05 - Merge Management
-
Upload
sergii-shmarkatiuk -
Category
Technology
-
view
1.842 -
download
1
Transcript of 05 - Merge Management
MERGE MANAGEMENT
2
TRAINING GOALS
Describe problems and risks emerging during merge operations in
VCSs
Show how to mitigate those risks and avoid problems related to
merging
3
TRAINING PLAN
1. What is merging?2. Why do we need to manage merging?3. Merging machinery4. Branch types5. Merging operation – maturity testing6. Merging in action7. Advanced merge management8. Criteria of successful merge
4
INTRODUCTION TO MERGE MANAGEMENT Basic ideas and principles
5
WHAT IS MERGING?
• In general sense:combination of two (or more) different objects into the whole in the form of new object with unified properties
• Applicably to Version Control Systems:fundamental operation that reconciles multiple changes made to a revision-controlled collection of files
6
WHY DO WE NEED TO MANAGE MERGING?
1. Result of merging often might be unpredictable
2. Nobody can guarantee that result of merging is the one you really wanted to achieve
3. Few people know the machinery of merging process
4. If something unpredictable happened during merging, almost nobody can explain why.
5. This is all because merging is the one of the most non-trivial operations of version control systems
7
LET’S DIVE INTO THE MERGING MACHINERY
8
COMMON BUZZWORDS OF MERGING MACHINERY
diff patch
branch merge
conflict cherrypicking
9
COMMON BUZZWORDS OF MERGING MACHINERY
diff patch
branch merge
conflict cherrypicking
There are two diffs:diff and diff3
10
DIFF (TWO-WAY MERGE)
Based on the longest common subsequence (LCS) algorithm
Not to confuse with longest common substring algorithm
Complexity of LCS algorithm is O(mn); m, n – lengths of the strings
Therefore, diff works using line by line comparison
Uses four formats: normal, context, unified, ed Can compare directories and their content
recursively But does not track directories move/rename
11
DIFF (TWO-WAY MERGE)
12
DIFF3 (THREE-WAY MERGE)
Manual comparison of three files
Automatic merging
Generation of conflict situations
Textual representation of the conflicts
Diff3 utility is the basis for:
13
DIFF3 (THREE-WAY MERGE)
or
… as merging into mine the changes that would turn older into theirs
You can think of diff3 as subtracting older from theirs and adding the result to mine …
14
DIFF3 (THREE-WAY MERGE)
15
COMMON BUZZWORDS OF MERGING MACHINERY
diff patch
branch merge
conflict cherrypicking
patch is often complementary to
the diff
16
PATCH
Useful utility for applying specific source code change set to the working copy
Reversed diff Imitation of distributed version control in
centralized VCSs
You can think about patch – as a:
17
PATCH
Merging functionality in DVCSs is implemented via series of subsequent patches applied.
There is no patch format extension for directories structure modification. Beware about move, rename and delete operations
svn merge command is like patch, but with additional special abilities such as: tree structure changes tracking and mergeinfo tracking
Result of svn diff command is the fully functioning patch file, but with little bit more limited representation abilities (subset of patch format)
Patch is also often called changeset
Interesting facts about patch:
18
PATCH
WC (working copy)
patch
create patch
apply patch
svn diff > patchfile.patch
patch -p0 < patchfile.patch
19
COMMON BUZZWORDS OF MERGING MACHINERY
diff patch
branch merge
conflict cherrypicking
merge has no sense without branches
20
BRANCH
No merge without branch
No branch without merge
21
BRANCH
Separate isolated parallel development line (codebase)
Operation of separate development line creation (branching)
Set of files having common ancestor with another set of files
Another folder in repository (usually in /branches parent directory) of centralized VCS
Dedicated private place in distributed VCS
You can think about branch as:
22
BRANCH TYPES
svn merge sourceURL1[@N] sourceURL2[@M] [WCPATH]svn merge -r N:M SOURCE [PATH]
Purpose of the branches, their contents and types directly affect the merging operation workflow and its
results
Merging operation is highly dependent on source and target branches
BRANCH TYPES
23
Purpose
Maturity
Codebase disparity
Independence
Duration Branch types
features
24
BRANCH TYPES
Branch types
Experimental
SupportRelease
Trunk
25
COMMON BUZZWORDS OF MERGING MACHINERY
diff patch
branch merge
conflict cherrypicking
merge is the most advanced operation
VCSs have
26
MERGE
Reconciliation of multiple changes made to a revision-controlled collection of files
Application of the differences between two sources to a working copy path (svn merge, svn update)
Operation of joining two or more development histories together (git merge)
Reintegration of the whole branch (or its part) into another branch
Process of two or three files comparison: 2-way merge and 3-way merge
Automatically generated result of 3-way merge: automerge
You can think about merge as:
27
MERGE. USE CASE
28
MERGE. USE CASE
29
COMMON BUZZWORDS OF MERGING MACHINERY
diff patch
branch merge
conflict cherrypicking
conflicts happen when there are difficulties with
merging
30
CONFLICT
It is difficult to avoid conflict situation during team work
31
CONFLICT
Conflict – is a state of one or more working copy artifacts assuming that: The same source code lines have been modified by
different users Artifact properties have been modified by different
users VCS cannot resolve modifications of directory
structure have been made by different users
Conflict situations are potentially produced by: svn update svn merge
32
GENERAL CONFLICT RESOLUTION WORKFLOW
Update working
copy with conflicting changes
Use one of the conflict resolution
options suggested
by VCS (svn
resolve)
Or edit files manually
saving final version and running svn resolved command
Commit resolved changes
33
CONFLICT RESOLUTION OPTIONS
• postponep• diff-fulldf• edite• resolvedr• mine-conflictmc• theirs-conflicttc• show all optionss
34
diff patch
branch merge
conflict cherrypicking
COMMON BUZZWORDS OF MERGING MACHINERY
cherrypicking means replication of single
change
35
MERGING IN ACTIONPractical example of merging
36
REVISIONS HISTORY>: svn log
svn://localhost/ParseCmdLine/branches/experimental/experimentalOptions --stop-on-copy
>: svn log svn://localhost/ParseCmdLine/trunk
------------------------------------------------------------------------r42 | svn | 2011-02-26 20:29:59 +0200 (Sat, 26 Feb 2011)------------------------------------------------------------------------r41 | svn | 2011-02-25 20:49:10 +0200 (Fri, 25 Feb 2011)------------------------------------------------------------------------r40 | svn | 2011-02-25 20:44:40 +0200 (Fri, 25 Feb 2011)------------------------------------------------------------------------r38 | svn | 2011-02-25 00:39:06 +0200 (Fri, 25 Feb 2011)------------------------------------------------------------------------r37 | svn | 2011-02-25 00:24:47 +0200 (Fri, 25 Feb 2011)------------------------------------------------------------------------r36 | svn | 2011-02-25 00:20:28 +0200 (Fri, 25 Feb 2011)------------------------------------------------------------------------
r43 | svn | 2011-02-28 16:26:44 +0200 (Mon, 28 Feb 2011)------------------------------------------------------------------------r39 | svn | 2011-02-25 20:41:01 +0200 (Fri, 25 Feb 2011)------------------------------------------------------------------------r33 | svn | 2011-02-24 13:24:31 +0200 (Thu, 24 Feb 2011)------------------------------------------------------------------------r32 | svn | 2011-02-24 13:21:44 +0200 (Thu, 24 Feb 2011)------------------------------------------------------------------------r31 | svn | 2011-02-24 13:16:34 +0200 (Thu, 24 Feb 2011)------------------------------------------------------------------------r30 | svn | 2011-02-24 12:25:47 +0200 (Thu, 24 Feb 2011)------------------------------------------------------------------------r28 | svn | 2011-02-24 12:14:14 +0200 (Thu, 24 Feb 2011)
37
REVISIONS HISTORY>: svn log
svn://localhost/ParseCmdLine/branches/experimental/experimentalOptions --stop-on-copy
>: svn log svn://localhost/ParseCmdLine/trunk
38
MERGING RANGE OF REVISIONS
>: svn merge svn://localhost/ParseCmdLine/trunk svn://localhost/ParseCmdLine/branches/experimental/experimentalOptions –r 39:43
39
REINTEGRATING A BRANCH
>: svn merge svn://localhost/ParseCmdLine/branches/experimental/experimentalOptions svn://localhost/ParseCmdLine/trunk --reintegrate
40
MERGING TWO TREES
>: svn merge svn://localhost/ParseCmdLine/branches/experimental/experimentalOptions svn://localhost/ParseCmdLine/trunk --ignore-ancestry
41
DIFF3 VS MERGE
diff3 always ignores ancestry merge takes into account ancestry by default Therefore, repository should store information
about: Branching (svn copy operations) Merging (svn merge operations, revisions, baselines,
etc) Tree modifications (files copying, deletion, movement,
etc) Operations sequence
Before the release of Subversion 1.5 this functionality was implemented in svnmerge.py
In Subversion 1.5 it is called merge tracking
42
MERGE TRACKING
Reduces the bookkeeping overhead for branch maintenance
Allows to avoid common cases of the "repeated merge" problem
Allows cherry-picking of changes
Allows outputting list of revisions available for merging
Support of bidirectional merges
Support of blocking changes
Support of merge rollbacks
43
svn merge -c REV SOURCE WC svn merge svn://localhost/ParseCmdLine/trunk svn://localhost/ParseCmdLine/branches/experimental/experimentalOptions –c 43
CHERRYPICKING
/experimental
22 23 24 25 … 39 40 41 42 43
-c 43
/trunk
Revision number
44
END OF SECTION
45
MERGE. MATURITY TESTINGProving that nothing is so simple as someone says
46
MERGE. MATURITY TESTING
There are several cases proving that…you cannot fully trust automerge
47
MERGE. MATURITY TESTING
Standard conflict handling
BOF/EOF Stingers
Identical Twins
X-Tuplets
Hungry Blobs
Unique anchors
Merging operation maturity test cases:
48
MERGE. MATURITY TESTING
Standard conflict handling
BOF/EOF Stingers
Identical Twins
X-Tuplets
Hungry Blobs
Unique anchors
Merging operation maturity test cases:
Making sure same source code lines have been
modified by different users
Diff3 Subversion Git
Works as expected
Works as expected
Works as expected
49
MERGE. MATURITY TESTING
Standard conflict handling
BOF/EOF Stingers
Identical Twins
X-Tuplets
Hungry Blobs
Unique anchors
Merging operation maturity test cases:
Diff3 Subversion Git
Works as expected
Works as expected
Works as expected
Sometimes problems emerge at the beginning
and ending of the file
50
MERGE. MATURITY TESTING
Standard conflict handling
BOF/EOF Stingers
Identical Twins
X-Tuplets
Hungry Blobs
Unique anchors
Merging operation maturity test cases:
Diff3 Subversion Git
Fails Works as expected
Works as expected
handling identical files from
different working copies
51
MERGE. MATURITY TESTING
Standard conflict handling
BOF/EOF Stingers
Identical Twins
X-Tuplets
Hungry Blobs
Unique anchors
Merging operation maturity test cases:Diff3 Subversion Git
Fails Works as expected
Fails
handling identical files from different working copies, but with minor adjacent
changes
52
MERGE. MATURITY TESTING
Standard conflict handling
BOF/EOF Stingers
Identical Twins
X-Tuplets
Hungry Blobs
Unique anchors
Merging operation maturity test cases:Diff3 Subversion Git
Works as expected
Fails Works as expected
adjacent changes from different working copies
53
MERGE. MATURITY TESTING
Standard conflict handling
BOF/EOF Stingers
Identical Twins
X-Tuplets
Hungry Blobs
Unique anchors
Merging operation maturity test cases:
using additional heuristics during diff for covering
special cases of merging
Diff3 Subversion Git
Fails Fails Fails
54
MERGE. MATURITY TESTING
One more example of faulty automerging:
56
ADVANCED MERGE MANAGEMENTMore complex issues related to merging
57
BRANCHES INHERITANCE
RELATIONBRANCH TYPE trunk support release experimental
trunksupportrelease
experimental
child
parent
There are certain branch creation and inheritance restrictions which will be described
by filling in table shown below
58
BRANCHES INHERITANCE
RELATIONBRANCH TYPE trunk support release experimental
trunksupportrelease
experimental
child
parent
Trunk cannot be the child of any other branch
59
BRANCHES INHERITANCE
RELATIONBRANCH TYPE trunk support release experimental
trunk +support -release -
experimental -
child
parent
Support branch can be inherited only from trunk
60
BRANCHES INHERITANCE
RELATIONBRANCH TYPE trunk support release experimental
trunk + +support - +release - -
experimental - -
child
parent
Release branches can be inherited both from trunk and support branches
61
BRANCHES INHERITANCE
RELATIONBRANCH TYPE trunk support release experimental
trunk + + +support - + +release - - -
experimental - - +
child
parent
Experimental branches can be inherited from any type of branch except release branch
62
SUPPORT AND RELEASE BRANCHES
/trunk
/1.0.x
/1.1.x
/1.x.x
/2.0.x
/1.2.x
support branch
release branch
63
EXPERIMENTAL BRANCHES
/trunk
experimental branch
/db_refactoring
/UI_integration
/UI_lazy_loading
/Layout_rework
/3-column
/1.x.x
/l18n_embedding
support branch
64
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent
parent
child
parent
child
parent
child
to
from
support release experimental
support
release
experimental
There are certain merging restrictions which will be described by filling in table shown
below
We will fill in it step by step in order to understand all aspects of the advanced merge
management.
65
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent - - +
parent - +child - - -
parent
child + + - -parent +
child + + - - + +
to
from
support release experimental
support
release
experimental
Final result will look as follows
Logically excluded cases of merging Cases excluded by branch inheritance and creation rules Allowed case of merging Disallowed case of merging operation
+-
66
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent
parent
child
parent
child
parent
child
to
from
support release experimental
support
release
experimental
Trunk can be only parent branch
RELATIONBRANCH TYPE trunk support release experimental
trunk + + +support - + +release - - -
experimental - - +
child
parent
67
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent
parent
child
parent
child
parent
child
to
from
support release experimental
support
release
experimental
Merging from parent to parent of the same branch seems to be merged into itself. It
makes sense only as a conflict which is not the case of merge we're considering
68
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent
parent
child
parent
child
parent
child
to
from
support release experimental
support
release
experimental
Branch cannot be parent to itself
69
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent child
trunk parent
parent -child - -
parent -child - -
parent +child + +
to
from
support release experimental
support
release
experimental
There are cases automatically excluded by branch creation and inheritance rules
RELATIONBRANCH TYPE trunk support release experimental
trunk + + +support - + +release - - -
experimental - - +
child
parent
70
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent
parent
child - -parent - -
child -parent - -
child -
to
from
support release experimental
support
release
experimental
There are cases automatically excluded by branch creation and inheritance rules
RELATIONBRANCH TYPE trunk support release experimental
trunk + + +support - + +release - - -
experimental - - +
child
parent
71
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent
parent
child
parent
child
parent
child
to
from
support release experimental
support
release
experimental
This is the result of exclusion merging cases by logic and branches creation and
inheritance rules.
We will be filling in empty cells
72
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent -
parent
child -parent
child
parent
child
to
from
support release experimental
support
release
experimental
Support branches are fully independent, they are not assumed to be merged with trunk or
other support branches
/trunk
/1.x.x
73
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent - -
parent -child -
parent
child + +parent
child
to
from
support release experimental
support
release
experimental
Purpose of release branch is maturing the release
It is expected that only bugfixes will be merged to parent branch and no changes will be merged from parent branch
74
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent - -
parent -child -
parent
child + +parent
child
to
from
support release experimental
support
release
experimental
Purpose of release branch is maturing the release
/trunk
/0.2.x
/1.x.x
/1.0.x
75
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent - -
parent -child - -
parent
child + + -parent
child
to
from
support release experimental
support
release
experimental
Child to child relation represents sibling branchesNo merge between sibling release and support branches is allowed
76
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent - -
parent -child - -
parent
child + + -parent
child
to
from
support release experimental
support
release
experimental
Child to child relation represents sibling branches
/trunk
/1.x.x
/1.0.x
77
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent - - +
parent - +child - -
parent
child + + -parent +
child + + +
to
from
support release experimental
support
release
experimental
It is allowed to merge experimental branches with any type of parent branch
/trunk
/UI_integration
/Layout_rework
/3-column
78
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent - - +
parent - +child - - -
parent
child + + - -parent +
child + + - - + +
to
from
support release experimental
support
release
experimental
No merge allowed between sibling experimental and any type of other branch (except experimental)
/trunk
/UI_integration
/1.x.x/1.0.x
/UI_integration
/Layout_rework
/3-column
79
TO MERGE OR NOT TO MERGE?
DESTINATIONBRANCH TYPE trunk
RELATION parent parent child parent child parent childtrunk parent - - +
parent - +child - - -
parent
child + + - -parent +
child + + - - + +
to
from
support release experimental
support
release
experimental
Final picture
Total number of cells Number of cells with logically excluded cases Number of cells with cases excluded logically and using
branch inheritance rules Allowed case of merging Disallowed cases introduced by merging rules
33
20
973%
49
80
SUPPORT AND RELEASE BRANCHES
/trunk
/1.0.x
/1.1.x
/1.x.x
/2.0.x
/1.2.x
support branch
release branch
disallowed merge operation
allowed merge operation
82
EXPERIMENTAL BRANCHES
/trunk
/db_refactoring
/UI_integration
/UI_lazy_loading
/Layout_rework
/3-column
/1.x.x
/l18n_embedding
experimental branch
support branch
disallowed merge
allowed merge
83
CONCLUSION
84
HOW WOULD YOU KNOW THE MERGE IS APPROPRIATE?
85
HOW WOULD YOU KNOW THE MERGE IS APPROPRIATE?
Make sure source and target branches are compatible for merging
86
HOW WOULD YOU KNOW THE MERGE IS SUCCESSFUL?
87
HOW WOULD YOU KNOW THE MERGE IS SUCCESSFUL?
Don’t leave merges unfinished
88
HOW WOULD YOU KNOW THE MERGE IS SUCCESSFUL?
Run unit-tests and inspections afterwards
89
HOW WOULD YOU KNOW THE MERGE IS SUCCESSFUL?
Formal criteria: There are no conflicts Code compiles Unit-tests run successfully
Conceptual criteria: Implemented features do not have logical and
architectural contradictions Whole codebase correspond to the introduced
concepts In case of intersection between merged features
functionality it should lead to additional development
90
91
AFTERWORD
92
RECOMMENDED READING
1. Version control with Subversion By Ben Collins-Sussman, Brian W. Fitzpatrick, C. Michael Pilato
93
RECOMMENDED READING
2. Version Control with Git by Jon Loeliger
94
RECOMMENDED READING
3. Mercurial: The Definitive Guide by Bryan O'Sullivan
95
USEFUL LINKS http://www.misuse.org/science/2007/02/24/3-way-merging/ -
three way merging http://
svnbook.red-bean.com/en/1.5/svn.branchmerge.advanced.html - advanced merging in subversion
http://codereflect.com/2010/09/21/versioning-systems-and-3-way-merge-process/ - simple way to understand 3 way merge process
http://book.git-scm.com/3_basic_branching_and_merging.html - basic branching and merging
http://book.git-scm.com/5_advanced_branching_and_merging.html - advanced branching and merging
http://hgbook.red-bean.com/read/a-tour-of-mercurial-merging-work.html - how mercurial merging works
http://www.collab.net/community/subversion/articles/merge-info.html - detailed description of merge tracking features