@matheusbsbs / matheus-bagliano / commits / 28e77a8164
Fork 0

merge-recursive: leave unmerged entries in the index.

This does two things. - When one branch renamed and the other branch did not, the resulting half-merged file in the working tree used to swap branches around and showed as if renaming side was "ours". This was confusing and inconsistent (even though the conflict markers were marked with branch names, it was not a good enough excuse). This changes the order of arguments to mergeFile in such a case to make sure we always see "our" change between <<< and ===, and "their" change between === and >>>. - When both branches renamed to the same path, and when one branch renamed and the other branch did not, we attempt mergeFile. When this automerge conflicted, we used to collapse the index. Now we use update-index --index-info to inject higher stage entries to leave the index in unmerged state for these two cases. What this still does _not_ do is to inject unmerged state into the index when the structural changes conflict. I have not thought things through what to do in each case yet, but the cases this commit cover are the most common ones, so this would be a good start. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Dec 10, 2005 at 22:05 UTC 28e77a81647584bfbe112f19e12e9952ab0b2fab
1 file changed +46 -8
git-merge-recursive.py
+46 -8
@@ -280,6 +280,22 @@ def updateFileExt(sha, mode, path, updateCache, updateWd):
280 runProgram(['git-update-index', '--add', '--cacheinfo',
281 '0%o' % mode, sha, path])
282
283 +def setIndexStages(path,
284 + oSHA1, oMode,
285 + aSHA1, aMode,
286 + bSHA1, bMode):
287 + prog = ['git-update-index', '-z', '--index-info']
288 + proc = subprocess.Popen(prog, stdin=subprocess.PIPE)
289 + pipe = proc.stdin
290 + # Clear stages first.
291 + pipe.write("0 " + ("0" * 40) + "\t" + path + "\0")
292 + # Set stages
293 + pipe.write("%o %s %d\t%s\0" % (oMode, oSHA1, 1, path))
294 + pipe.write("%o %s %d\t%s\0" % (aMode, aSHA1, 2, path))
295 + pipe.write("%o %s %d\t%s\0" % (bMode, bSHA1, 3, path))
296 + pipe.close()
297 + proc.wait()
298 +
299 def removeFile(clean, path):
300 updateCache = cacheOnly or clean
301 updateWd = not cacheOnly
@@ -590,6 +606,8 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
606 else:
607 dstName2 = ren1.dstName
608
609 + # NEEDSWORK: place dstNameA at stage 2 and dstNameB at stage 3
610 + # What about other stages???
611 updateFile(False, ren1.dstSha, ren1.dstMode, dstName1)
612 updateFile(False, ren2.dstSha, ren2.dstMode, dstName2)
613 else:
@@ -611,8 +629,11 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
629 cleanMerge = False
630
631 if not cacheOnly:
614 - updateFileExt(ren1.dstSha, ren1.dstMode, ren1.dstName,
615 - updateCache=True, updateWd=False)
632 + setIndexStages(ren1.dstName,
633 + ren1.srcSha, ren1.srcMode,
634 + ren1.dstSha, ren1.dstMode,
635 + ren2.dstSha, ren2.dstMode)
636 +
637 updateFile(clean, resSha, resMode, ren1.dstName)
638 else:
639 # Renamed in 1, maybe changed in 2
@@ -672,11 +693,24 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
693 tryMerge = True
694
695 if tryMerge:
696 +
697 + oName, oSHA1, oMode = ren1.srcName, ren1.srcSha, ren1.srcMode
698 + aName, bName = ren1.dstName, ren1.srcName
699 + aSHA1, bSHA1 = ren1.dstSha, srcShaOtherBranch
700 + aMode, bMode = ren1.dstMode, srcModeOtherBranch
701 + aBranch, bBranch = branchName1, branchName2
702 +
703 + if renamesA != renames1:
704 + aName, bName = bName, aName
705 + aSHA1, bSHA1 = bSHA1, aSHA1
706 + aMode, bMode = bMode, aMode
707 + aBranch, bBranch = bBranch, aBranch
708 +
709 [resSha, resMode, clean, merge] = \
676 - mergeFile(ren1.srcName, ren1.srcSha, ren1.srcMode,
677 - ren1.dstName, ren1.dstSha, ren1.dstMode,
678 - ren1.srcName, srcShaOtherBranch, srcModeOtherBranch,
679 - branchName1, branchName2)
710 + mergeFile(oName, oSHA1, oMode,
711 + aName, aSHA1, aMode,
712 + bName, bSHA1, bMode,
713 + aBranch, bBranch);
714
715 if merge or not clean:
716 output('Renaming', fmtRename(ren1.srcName, ren1.dstName))
@@ -690,8 +724,12 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
724 cleanMerge = False
725
726 if not cacheOnly:
693 - updateFileExt(ren1.dstSha, ren1.dstMode, ren1.dstName,
694 - updateCache=True, updateWd=False)
727 + # Stuff stage1/2/3
728 + setIndexStages(ren1.dstName,
729 + oSHA1, oMode,
730 + aSHA1, aMode,
731 + bSHA1, bMode)
732 +
733 updateFile(clean, resSha, resMode, ren1.dstName)
734
735 return cleanMerge