05 - Merge Management

93
MERGE MANAGEMENT

Transcript of 05 - Merge Management

Page 1: 05 - Merge Management

MERGE MANAGEMENT

Page 2: 05 - 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

Page 3: 05 - Merge Management

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

Page 4: 05 - Merge Management

4

INTRODUCTION TO MERGE MANAGEMENT Basic ideas and principles

Page 5: 05 - Merge Management

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

Page 6: 05 - Merge Management

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

Page 7: 05 - Merge Management

7

LET’S DIVE INTO THE MERGING MACHINERY

Page 8: 05 - Merge Management

8

COMMON BUZZWORDS OF MERGING MACHINERY

diff patch

branch merge

conflict cherrypicking

Page 9: 05 - Merge Management

9

COMMON BUZZWORDS OF MERGING MACHINERY

diff patch

branch merge

conflict cherrypicking

There are two diffs:diff and diff3

Page 10: 05 - Merge Management

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

Page 11: 05 - Merge Management

11

DIFF (TWO-WAY MERGE)

Page 12: 05 - Merge Management

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:

Page 13: 05 - Merge Management

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 …

Page 14: 05 - Merge Management

14

DIFF3 (THREE-WAY MERGE)

Page 15: 05 - Merge Management

15

COMMON BUZZWORDS OF MERGING MACHINERY

diff patch

branch merge

conflict cherrypicking

patch is often complementary to

the diff

Page 16: 05 - Merge Management

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:

Page 17: 05 - Merge Management

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:

Page 18: 05 - Merge Management

18

PATCH

WC (working copy)

patch

create patch

apply patch

svn diff > patchfile.patch

patch -p0 < patchfile.patch

Page 19: 05 - Merge Management

19

COMMON BUZZWORDS OF MERGING MACHINERY

diff patch

branch merge

conflict cherrypicking

merge has no sense without branches

Page 20: 05 - Merge Management

20

BRANCH

No merge without branch

No branch without merge

Page 21: 05 - Merge Management

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:

Page 22: 05 - Merge Management

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

Page 23: 05 - Merge Management

BRANCH TYPES

23

Purpose

Maturity

Codebase disparity

Independence

Duration Branch types

features

Page 24: 05 - Merge Management

24

BRANCH TYPES

Branch types

Experimental

SupportRelease

Trunk

Page 25: 05 - Merge Management

25

COMMON BUZZWORDS OF MERGING MACHINERY

diff patch

branch merge

conflict cherrypicking

merge is the most advanced operation

VCSs have

Page 26: 05 - Merge Management

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:

Page 27: 05 - Merge Management

27

MERGE. USE CASE

Page 28: 05 - Merge Management

28

MERGE. USE CASE

Page 29: 05 - Merge Management

29

COMMON BUZZWORDS OF MERGING MACHINERY

diff patch

branch merge

conflict cherrypicking

conflicts happen when there are difficulties with

merging

Page 30: 05 - Merge Management

30

CONFLICT

It is difficult to avoid conflict situation during team work

Page 31: 05 - Merge Management

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

Page 32: 05 - Merge Management

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

Page 33: 05 - Merge Management

33

CONFLICT RESOLUTION OPTIONS

• postponep• diff-fulldf• edite• resolvedr• mine-conflictmc• theirs-conflicttc• show all optionss

Page 34: 05 - Merge Management

34

diff patch

branch merge

conflict cherrypicking

COMMON BUZZWORDS OF MERGING MACHINERY

cherrypicking means replication of single

change

Page 35: 05 - Merge Management

35

MERGING IN ACTIONPractical example of merging

Page 36: 05 - Merge Management

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)

Page 37: 05 - Merge Management

37

REVISIONS HISTORY>: svn log

svn://localhost/ParseCmdLine/branches/experimental/experimentalOptions --stop-on-copy

>: svn log svn://localhost/ParseCmdLine/trunk

Page 38: 05 - Merge Management

38

MERGING RANGE OF REVISIONS

>: svn merge svn://localhost/ParseCmdLine/trunk svn://localhost/ParseCmdLine/branches/experimental/experimentalOptions –r 39:43

Page 39: 05 - Merge Management

39

REINTEGRATING A BRANCH

>: svn merge svn://localhost/ParseCmdLine/branches/experimental/experimentalOptions svn://localhost/ParseCmdLine/trunk --reintegrate

Page 40: 05 - Merge Management

40

MERGING TWO TREES

>: svn merge svn://localhost/ParseCmdLine/branches/experimental/experimentalOptions svn://localhost/ParseCmdLine/trunk --ignore-ancestry

Page 41: 05 - Merge Management

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

Page 42: 05 - Merge Management

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

Page 43: 05 - Merge Management

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

Page 44: 05 - Merge Management

44

END OF SECTION

Page 45: 05 - Merge Management

45

MERGE. MATURITY TESTINGProving that nothing is so simple as someone says

Page 46: 05 - Merge Management

46

MERGE. MATURITY TESTING

There are several cases proving that…you cannot fully trust automerge

Page 47: 05 - Merge Management

47

MERGE. MATURITY TESTING

Standard conflict handling

BOF/EOF Stingers

Identical Twins

X-Tuplets

Hungry Blobs

Unique anchors

Merging operation maturity test cases:

Page 48: 05 - Merge Management

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

Page 49: 05 - Merge Management

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

Page 50: 05 - Merge Management

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

Page 51: 05 - Merge Management

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

Page 52: 05 - Merge Management

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

Page 53: 05 - Merge Management

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

Page 54: 05 - Merge Management

54

MERGE. MATURITY TESTING

One more example of faulty automerging:

Page 55: 05 - Merge Management

56

ADVANCED MERGE MANAGEMENTMore complex issues related to merging

Page 56: 05 - Merge Management

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

Page 57: 05 - Merge Management

58

BRANCHES INHERITANCE

RELATIONBRANCH TYPE trunk support release experimental

trunksupportrelease

experimental

child

parent

Trunk cannot be the child of any other branch

Page 58: 05 - Merge Management

59

BRANCHES INHERITANCE

RELATIONBRANCH TYPE trunk support release experimental

trunk +support -release -

experimental -

child

parent

Support branch can be inherited only from trunk

Page 59: 05 - Merge Management

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

Page 60: 05 - Merge Management

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

Page 61: 05 - Merge Management

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

Page 62: 05 - Merge Management

63

EXPERIMENTAL BRANCHES

/trunk

experimental branch

/db_refactoring

/UI_integration

/UI_lazy_loading

/Layout_rework

/3-column

/1.x.x

/l18n_embedding

support branch

Page 63: 05 - Merge Management

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.

Page 64: 05 - 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

+-

Page 65: 05 - Merge Management

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

Page 66: 05 - Merge Management

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

Page 67: 05 - Merge Management

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

Page 68: 05 - Merge Management

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

Page 69: 05 - Merge Management

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

Page 70: 05 - Merge Management

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

Page 71: 05 - Merge Management

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

Page 72: 05 - Merge Management

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

Page 73: 05 - Merge Management

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

Page 74: 05 - Merge Management

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

Page 75: 05 - Merge Management

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

Page 76: 05 - Merge Management

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

Page 77: 05 - Merge Management

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

Page 78: 05 - Merge Management

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

Page 79: 05 - Merge Management

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

Page 80: 05 - Merge Management

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

Page 81: 05 - Merge Management

83

CONCLUSION

Page 82: 05 - Merge Management

84

HOW WOULD YOU KNOW THE MERGE IS APPROPRIATE?

Page 83: 05 - Merge Management

85

HOW WOULD YOU KNOW THE MERGE IS APPROPRIATE?

Make sure source and target branches are compatible for merging

Page 84: 05 - Merge Management

86

HOW WOULD YOU KNOW THE MERGE IS SUCCESSFUL?

Page 85: 05 - Merge Management

87

HOW WOULD YOU KNOW THE MERGE IS SUCCESSFUL?

Don’t leave merges unfinished

Page 86: 05 - Merge Management

88

HOW WOULD YOU KNOW THE MERGE IS SUCCESSFUL?

Run unit-tests and inspections afterwards

Page 87: 05 - Merge Management

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

Page 88: 05 - Merge Management

90

Page 89: 05 - Merge Management

91

AFTERWORD

Page 90: 05 - Merge Management

92

RECOMMENDED READING

1. Version control with Subversion By Ben Collins-Sussman, Brian W. Fitzpatrick, C. Michael Pilato

Page 91: 05 - Merge Management

93

RECOMMENDED READING

2. Version Control with Git by Jon Loeliger

Page 92: 05 - Merge Management

94

RECOMMENDED READING

3. Mercurial: The Definitive Guide by Bryan O'Sullivan

Page 93: 05 - Merge Management

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