05 - Merge Management

2,233 views

Published on

Published in: Technology
  • Be the first to comment

05 - Merge Management

  1. 1. MERGE MANAGEMENT
  2. 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 2
  3. 3. TRAINING PLAN1. 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 3
  4. 4. INTRODUCTION TO MERGE MANAGEMENT4 Basic ideas and principles
  5. 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 5
  6. 6. WHY DO WE NEED TO MANAGEMERGING?1. Result of merging often might be unpredictable2. Nobody can guarantee that result of merging is the one you really wanted to achieve3. Few people know the machinery of merging process4. 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 6
  7. 7. LET’S DIVE INTO THE MERGING MACHINERY 7
  8. 8. COMMON BUZZWORDS OFMERGING MACHINERY diff patch branch merge conflict cherrypicking 8
  9. 9. COMMON BUZZWORDS OFMERGING MACHINERY diff patch branch merge There are two diffs: diff and diff3 conflict cherrypicking 9
  10. 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 10
  11. 11. DIFF (TWO-WAY MERGE) 11
  12. 12. DIFF3 (THREE-WAY MERGE)Diff3 utility is the basis for: Manual comparison of three files Automatic merging Generation of conflict situations Textual representation of the conflicts 12
  13. 13. DIFF3 (THREE-WAY MERGE) You can think of diff3 as subtracting older from theirs and adding the result to mine … or … as merging into mine the changes that would turn older into theirs 13
  14. 14. DIFF3 (THREE-WAY MERGE) 14
  15. 15. COMMON BUZZWORDS OFMERGING MACHINERY diff patch branch merge patch is often complementary to the diff conflict cherrypicking 15
  16. 16. PATCHYou can think about patch – as a: Useful utility for applying specific source code change set to the working copy Reversed diff Imitation of distributed version control in centralized VCSs 16
  17. 17. PATCHInteresting facts about 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 17
  18. 18. PATCH svn diff > patchfile.patch create patch patch apply patch WC (working copy) patch -p0 < patchfile.patch 18
  19. 19. COMMON BUZZWORDS OFMERGING MACHINERY diff merge has no sense patch without branches branch merge conflict cherrypicking 19
  20. 20. BRANCH No merge without branch No branch without merge 20
  21. 21. BRANCHYou can think about branch as: 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 21 VCS
  22. 22. BRANCH TYPESsvn merge sourceURL1[@N] sourceURL2[@M] [WCPATH]svn merge -r N:M SOURCE [PATH] Merging operation is highly dependent on source and target branches Purpose of the branches, their contents and types directly affect the merging operation workflow and its results 22
  23. 23. BRANCH TYPES Purpose Duration Maturity Branch types features Codebase Independence 23 disparity
  24. 24. BRANCH TYPES Trunk Experimental Branch types Release Support 24
  25. 25. COMMON BUZZWORDS OFMERGING MACHINERY diff patch branch merge merge is the most advanced operation conflict VCSs have cherrypicking 25
  26. 26. MERGEYou can think about merge as: 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: 26 automerge
  27. 27. MERGE. USE CASE 27
  28. 28. MERGE. USE CASE 28
  29. 29. COMMON BUZZWORDS OFMERGING MACHINERY diff patch conflicts happen when there are difficulties branch with merging merge conflict cherrypicking 29
  30. 30. CONFLICT It is difficult to avoid conflict situation during team work 30
  31. 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 31
  32. 32. GENERAL CONFLICT RESOLUTION WORKFLOW Or edit files Update manually savingworking copy final version and with running svn conflicting resolved changes command Use one of Commit the conflict resolved resolution changes options suggested by VCS (svn 32 resolve)
  33. 33. CONFLICT RESOLUTIONOPTIONS p • postpone df • diff-full e • edit r • resolved mc • mine-conflict tc • theirs-conflict 33 s • show all options
  34. 34. COMMON BUZZWORDS OFMERGING MACHINERY diff patchcherrypicking means replication of single change branch merge conflict cherrypicking 34
  35. 35. MERGING IN ACTION35 Practical example of merging
  36. 36. REVISIONS HISTORY>: svn log svn://localhost/ParseCmdLine/branches/experi mental/experimentalOptions --stop-on-copy ------------------------------------------------------------------------ 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) ------------------------------------------------------------------------>: svn log svn://localhost/ParseCmdLine/trunk 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) 36 ------------------------------------------------------------------------ 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. 37. REVISIONS HISTORY>: svn log svn://localhost/ParseCmdLine/branches/experi mental/experimentalOptions --stop-on-copy>: svn log svn://localhost/ParseCmdLine/trunk 37
  38. 38. MERGING RANGE OF REVISIONS>: svn merge svn://localhost/ParseCmdLine/trunk svn://localhost/ParseCmdLine/branches/experimental/experim entalOptions –r 39:43 38
  39. 39. REINTEGRATING A BRANCH>: svn merge svn://localhost/ParseCmdLine/branches/experimental/experimentalOptions svn://localhost/ParseCmdLine/trunk --reintegrate 39
  40. 40. MERGING TWO TREES>: svn merge svn://localhost/ParseCmdLine/branches/experimental/experimentalOptions svn://localhost/ParseCmdLine/trunk --ignore-ancestry 40
  41. 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 41
  42. 42. MERGE TRACKINGReduces the bookkeeping overhead for branch maintenanceAllows to avoid common cases of the "repeated merge" problemAllows cherry-picking of changesAllows outputting list of revisions available for mergingSupport of bidirectional mergesSupport of blocking changesSupport of merge rollbacks 42
  43. 43. CHERRYPICKING  svn merge -c REV SOURCE WC  svn merge svn://localhost/ParseCmdLine/trunk svn://localhost/ParseCmdLine/branches/experim ental/experimentalOptions –c 43 /trunk -c 43 /experimentalRevisionnumber 22 23 24 25 … 39 40 41 42 43 43
  44. 44. END OF SECTION 44
  45. 45. MERGE. MATURITY TESTING45 Proving that nothing is so simple as someone says
  46. 46. MERGE. MATURITY TESTING There are several cases proving that… you cannot fully trust automerge 46
  47. 47. MERGE. MATURITY TESTINGMerging operation maturity test cases:Standard conflict handlingBOF/EOF StingersIdentical TwinsX-TupletsHungry BlobsUnique anchors 47
  48. 48. MERGE. MATURITY TESTINGMerging operation maturity test cases:Standard conflict handlingBOF/EOF StingersIdentical Twins sure same source code Making lines have been modified byX-Tuplets different usersHungry BlobsUnique Diff3 anchors Subversion Git Works as expected Works as expected Works as expected 48
  49. 49. MERGE. MATURITY TESTINGMerging operation maturity test cases:Standard conflict handlingBOF/EOF StingersIdentical Twins Sometimes problems emergeX-Tuplets at the beginning and ending of the fileHungry BlobsUnique Diff3 anchors Subversion Git Works as expected Works as expected Works as expected 49
  50. 50. MERGE. MATURITY TESTINGMerging operation maturity test cases:Standard conflict handlingBOF/EOF StingersIdentical TwinsX-Tuplets handling identical files fromHungry Blobsdifferent working copiesUnique Diff3 anchors Subversion Git Fails Works as expected Works as expected 50
  51. 51. MERGE. MATURITY TESTINGMerging operation maturity test cases: Diff3 Subversion GitStandard conflict Works as expected Fails handling FailsBOF/EOF Stingers handling identical files from different workingIdentical Twins with minor adjacent changes copies, butX-TupletsHungry BlobsUnique anchors 51
  52. 52. MERGE. MATURITY TESTINGMerging operation maturity test cases: Diff3 Subversion GitStandard expected handling Works as conflict Fails Works as expectedBOF/EOF Stingers adjacent changes fromIdentical Twins different working copiesX-TupletsHungry BlobsUnique anchors 52
  53. 53. MERGE. MATURITY TESTINGMerging operation maturity test cases: Diff3 Subversion GitStandard conflict handling Fails Fails FailsBOF/EOF StingersIdentical Twins additional heuristics using during diff for covering specialX-Tuplets cases of mergingHungry BlobsUnique anchors 53
  54. 54. MERGE. MATURITY TESTINGOne more example of faulty automerging: 54
  55. 55. ADVANCED MERGE MANAGEMENT56 More complex issues related to merging
  56. 56. BRANCHES INHERITANCE There are certain branch creation and inheritance restrictions which will be described by filling in table shown belowRELATION child BRANCH TYPE trunk support release experimental trunk parent support release experimental 57
  57. 57. BRANCHES INHERITANCE Trunk cannot be the child of any other branchRELATION child BRANCH TYPE trunk support release experimental trunk parent support release experimental 58
  58. 58. BRANCHES INHERITANCE Support branch can be inherited only from trunkRELATION child BRANCH TYPE trunk support release experimental trunk + parent support - release - experimental - 59
  59. 59. BRANCHES INHERITANCE Release branches can be inherited both from trunk and support branchesRELATION child BRANCH TYPE trunk support release experimental trunk + + parent support - + release - - experimental - - 60
  60. 60. BRANCHES INHERITANCE Experimental branches can be inherited from any type of branch except release branchRELATION child BRANCH TYPE trunk support release experimental trunk + + + parent support - + + release - - - experimental - - + 61
  61. 61. SUPPORT AND RELEASEBRANCHES /1.1.x /2.0.x /trunk /1.2.x /1.0.x /1.x.x release branch 62 support branch
  62. 62. EXPERIMENTAL BRANCHES /trunk /1.x.x /db_refactoring /l18n_embedding /UI_lazy_loading /UI_integration /Layout_rework 63 support branch /3-column experimental branch
  63. 63. TO MERGE OR NOT TO MERGE? 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.DESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent parent support from child parent release child 64 parent experimental child
  64. 64. TO MERGE OR NOT TO MERGE? 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 operationDESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent - - + parent - + support from child - - - parent release child + + - - 65 parent + experimental child + + - - + +
  65. 65. TO MERGE OR NOT TO MERGE? Trunk can be only parent branchRELATION child BRANCH TYPE trunk support release experimental trunk + + + parent support - + + release - - - experimental - - +DESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent parent support from child parent release child 66 parent experimental child
  66. 66. TO MERGE OR NOT TO MERGE? 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 were consideringDESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent parent support from child parent release child 67 parent experimental child
  67. 67. TO MERGE OR NOT TO MERGE? Branch cannot be parent to itselfDESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent parent support from child parent release child 68 parent experimental child
  68. 68. TO MERGE OR NOT TO MERGE? There are cases automatically excluded by branch creation and inheritance rulesRELATION child BRANCH TYPE trunk support release experimental trunk + + + parent support - + + release - - - experimental - - +DESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent parent - support from child - - parent - release child - - 69 parent + experimental child + +
  69. 69. TO MERGE OR NOT TO MERGE? There are cases automatically excluded by branch creation and inheritance rulesRELATION child BRANCH TYPE trunk support release experimental trunk + + + parent support - + + release - - - experimental - - +DESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent parent support from child - - parent - - release child - 70 parent - - experimental child -
  70. 70. TO MERGE OR NOT TO MERGE? This is the result of exclusion merging cases by logic and branches creation and inheritance rules. We will be filling in empty cellsDESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent parent support from child parent release child 71 parent experimental child
  71. 71. TO MERGE OR NOT TO MERGE? Support branches are fully independent, they are not assumed to be merged with trunk or other support branches /trunk /1.x.xDESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent - parent support from child - parent release child 72 parent experimental child
  72. 72. TO MERGE OR NOT TO MERGE?Purpose of release branch is maturing the releaseIt is expected that only bugfixes will be merged toparent branch and no changes will be merged fromparent branchDESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent - - parent - support from child - parent release child + + 73 parent experimental child
  73. 73. TO MERGE OR NOT TO MERGE?Purpose of release branch is maturing the release /0.2.x /1.0.x /trunk /1.x.xDESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent - - parent - support from child - parent release child + + 74 parent experimental child
  74. 74. TO MERGE OR NOT TO MERGE?Child to child relation represents sibling branchesNo merge between sibling release and supportbranches is allowedDESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent - - parent - support from child - - parent release child + + - 75 parent experimental child
  75. 75. TO MERGE OR NOT TO MERGE?Child to child relation represents sibling branches /trunk /1.0.x /1.x.xDESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent - - parent - support from child - - parent release child + + - 76 parent experimental child
  76. 76. TO MERGE OR NOT TO MERGE?It is allowed to merge experimental branches withany type of parent branch /trunk /UI_integration /Layout_rework /3-columnDESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent - - + parent - + support from child - - parent release child + + - 77 parent + experimental child + + +
  77. 77. TO MERGE OR NOT TO MERGE?No merge allowed between sibling experimental andany type of other branch (except experimental) /trunk /Layout_rework /1.x.x /UI_integration /1.0.x /3-column /UI_integrationDESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent - - + parent - + support from child - - - parent release child + + - - 78 parent + experimental child + + - - + +
  78. 78. TO MERGE OR NOT TO MERGE? Final picture 49  Total number of cells 33  Number of cells with logically excluded cases 20  Number of cells with cases excluded logically and using branch inheritance rules 9  Allowed case of merging 73%  Disallowed cases introduced by merging rulesDESTINATION to BRANCH TYPE trunk support release experimental RELATION parent parent child parent child parent child trunk parent - - + parent - + support from child - - - parent release child + + - - 79 parent + experimental child + + - - + +
  79. 79. SUPPORT AND RELEASEBRANCHES /1.1.x /2.0.x /trunk /1.2.x /1.0.x /1.x.x release branch allowed merge operation 80 support branch disallowed merge operation
  80. 80. EXPERIMENTAL BRANCHES /trunk /1.x.x /db_refactoring /l18n_embedding /UI_lazy_loading /UI_integration allowed merge /Layout_rework disallowed merge 82 support branch /3-column experimental branch
  81. 81. CONCLUSION83
  82. 82. HOW WOULD YOU KNOW THE MERGE ISAPPROPRIATE? 84
  83. 83. HOW WOULD YOU KNOW THE MERGE ISAPPROPRIATE? Make sure source and target branches are compatible for merging 85
  84. 84. HOW WOULD YOU KNOW THE MERGE ISSUCCESSFUL? 86
  85. 85. HOW WOULD YOU KNOW THE MERGE ISSUCCESSFUL? Don’t leave merges unfinished 87
  86. 86. HOW WOULD YOU KNOW THE MERGE ISSUCCESSFUL? Run unit-tests and inspections afterwards 88
  87. 87. HOW WOULD YOU KNOW THE MERGE ISSUCCESSFUL? 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 89
  88. 88. 90
  89. 89. AFTERWORD91
  90. 90. RECOMMENDED READING1. Version control with Subversion By Ben Collins-Sussman, Brian W. Fitzpatrick, C. Michael Pilato 92
  91. 91. RECOMMENDED READING2. Version Control with Git by Jon Loeliger 93
  92. 92. RECOMMENDED READING3. Mercurial: The Definitive Guide by Bryan OSullivan 94
  93. 93. 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- 95 info.html - detailed description of merge tracking features

×