[PATCH 0/5] More recursive merge updates
From: Fredrik Kuivinen <hidden>
Date: 2016-06-15 22:42:06
Here is another patch series with updates to the recursive merge algorithm. - Fredrik
6 messages, 1 author, 2016-06-15 · open the first message on its own page
From: Fredrik Kuivinen <hidden>
Date: 2016-06-15 22:42:06
Here is another patch series with updates to the recursive merge algorithm. - Fredrik
From: Fredrik Kuivinen <hidden>
Date: 2016-06-15 22:42:06
If there are non-mergeable changes leave the head contents in the cache and update the working directory with the output from merge(1). In the add/add and delete/modify conflict cases leave unmerged cache entries in the index. Signed-off-by: Fredrik Kuivinen <redacted> --- git-merge-recursive.py | 68 +++++++++++++++++++++++------------------------- 1 files changed, 33 insertions(+), 35 deletions(-) 11a6300badeb3b2a46d088877f2f264d18b2160d
diff --git a/git-merge-recursive.py b/git-merge-recursive.py
--- a/git-merge-recursive.py
+++ b/git-merge-recursive.py@@ -7,8 +7,6 @@ from sets import Set sys.path.append('@@GIT_PYTHON_PATH@@') from gitMergeCommon import * -alwaysWriteTree = False - # The actual merge code # ---------------------
@@ -46,19 +44,14 @@ def merge(h1, h2, branch1Name, branch2Na runProgram(['git-update-cache', '-q', '--refresh']) # Use the original index if we only have one common ancestor - updateWd = True - if alwaysWriteTree: - cleanCache = True - else: - cleanCache = False + cleanCache = False else: runProgram(['git-read-tree', h1.tree()]) - updateWd = False cleanCache = True [shaRes, clean] = mergeTrees(h1.tree(), h2.tree(), Ms.tree(), branch1Name, branch2Name, - cleanCache, updateWd) + cleanCache) if clean or cleanCache: res = Commit(None, [h1, h2], tree=shaRes)
@@ -125,7 +118,7 @@ def unmergedCacheEntries(): return res def mergeTrees(head, merge, common, branch1Name, branch2Name, - cleanCache, updateWd): + cleanCache): '''Merge the trees 'head' and 'merge' with the common ancestor 'common'. The name of the head branch is 'branch1Name' and the name of the merge branch is 'branch2Name'. Return a tuple (tree, cleanMerge)
@@ -138,10 +131,11 @@ def mergeTrees(head, merge, common, bran print 'Already uptodate!' return [head, True] - if updateWd: - updateArg = '-u' - else: + if cleanCache: updateArg = '-i' + else: + updateArg = '-u' + runProgram(['git-read-tree', updateArg, '-m', common, head, merge]) cleanMerge = True
@@ -157,7 +151,7 @@ def mergeTrees(head, merge, common, bran entries = unmergedCacheEntries() for name in entries: if not processEntry(entries[name], branch1Name, branch2Name, - files, dirs, cleanCache, updateWd): + files, dirs, cleanCache): cleanMerge = False if cleanMerge or cleanCache:
@@ -169,29 +163,25 @@ def mergeTrees(head, merge, common, bran return [tree, cleanMerge] -def processEntry(entry, branch1Name, branch2Name, files, dirs, - cleanCache, updateWd): +def processEntry(entry, branch1Name, branch2Name, files, dirs, cleanCache): '''Merge one cache entry. 'files' is a Set with the files in both of the heads that we are going to merge. 'dirs' contains the corresponding data for directories. If 'cleanCache' is True no non-zero stages will be left in the cache for the path corresponding to the entry 'entry'.''' -# cleanCache == True => Don't leave any non-stage 0 entries in the cache. -# False => Leave unmerged entries - -# updateWd == True => Update the working directory to correspond to the cache -# False => Leave the working directory unchanged +# cleanCache == True => Don't leave any non-stage 0 entries in the cache and +# don't update the working directory +# False => Leave unmerged entries and update the working directory # clean == True => non-conflict case # False => conflict case # If cleanCache == False then the cache shouldn't be updated if clean == False - def updateFile(clean, sha, mode, path): - if cleanCache or (not cleanCache and clean): - runProgram(['git-update-cache', '--add', '--cacheinfo', - '0%o' % mode, sha, path]) + def updateFile(clean, sha, mode, path, onlyWd=False): + updateCache = not onlyWd and (cleanCache or (not cleanCache and clean)) + updateWd = onlyWd or (not cleanCache and clean) if updateWd: prog = ['git-cat-file', 'blob', sha]
@@ -213,13 +203,18 @@ def processEntry(entry, branch1Name, bra os.symlink(linkTarget, path) else: assert(False) - runProgram(['git-update-cache', '--', path]) + + if updateWd and updateCache: + runProgram(['git-update-cache', '--add', '--', path]) + elif updateCache: + runProgram(['git-update-cache', '--add', '--cacheinfo', + '0%o' % mode, sha, path]) def removeFile(clean, path): if cleanCache or (not cleanCache and clean): runProgram(['git-update-cache', '--force-remove', '--', path]) - if updateWd: + if not cleanCache and clean: try: os.unlink(path) except OSError, e:
@@ -235,8 +230,7 @@ def processEntry(entry, branch1Name, bra files.add(newPath) return newPath - debug('processing', entry.path, 'clean cache:', cleanCache, - 'wd:', updateWd) + debug('processing', entry.path, 'clean cache:', cleanCache) cleanMerge = True
@@ -327,9 +321,9 @@ def processEntry(entry, branch1Name, bra if aMode != bMode: cleanMerge = False print 'CONFLICT: File "' + path + \ - '" added identically in both branches,' - print 'CONFLICT: but permissions conflict', '0%o' % aMode, \ - '->', '0%o' % bMode + '" added identically in both branches,', \ + 'but permissions conflict', '0%o' % aMode, '->', \ + '0%o' % bMode print 'CONFLICT: adding with permission:', '0%o' % aMode updateFile(False, aSha, aMode, path)
@@ -341,8 +335,7 @@ def processEntry(entry, branch1Name, bra newPath1 = uniquePath(path, branch1Name) newPath2 = uniquePath(path, branch2Name) print 'CONFLICT (add/add): File "' + path + \ - '" added non-identically in both branches.', \ - 'Adding "' + newPath1 + '" and "' + newPath2 + '" instead.' + '" added non-identically in both branches.' removeFile(False, path) updateFile(False, aSha, aMode, newPath1) updateFile(False, bSha, bMode, newPath2)
@@ -372,7 +365,12 @@ def processEntry(entry, branch1Name, bra if ret != 0: cleanMerge = False print 'CONFLICT (content): Merge conflict in "' + path + '".' - updateFile(False, sha, mode, path) + + if cleanCache: + updateFile(False, sha, mode, path) + else: + updateFile(True, aSha, aMode, path) + updateFile(False, sha, mode, path, True) else: updateFile(True, sha, mode, path)
From: Fredrik Kuivinen <hidden>
Date: 2016-06-15 22:42:06
With this change we can get rid of a call to 'git-update-index --refresh'. Signed-off-by: Fredrik Kuivinen <redacted> --- git-merge-recursive.py | 23 ++++++++++++++++++----- 1 files changed, 18 insertions(+), 5 deletions(-) 68a73c83a0ba2175cb366bddf3b851f824c6d598
diff --git a/git-merge-recursive.py b/git-merge-recursive.py
--- a/git-merge-recursive.py
+++ b/git-merge-recursive.py@@ -10,6 +10,22 @@ from gitMergeCommon import * # The actual merge code # --------------------- +originalIndexFile = os.environ.get('GIT_INDEX_FILE', + os.environ.get('GIT_DIR', '.git') + '/index') +temporaryIndexFile = os.environ.get('GIT_DIR', '.git') + \ + '/merge-recursive-tmp-index' +def setupIndex(temporary): + try: + os.unlink(temporaryIndexFile) + except OSError: + pass + if temporary: + newIndex = temporaryIndexFile + os.environ + else: + newIndex = originalIndexFile + os.environ['GIT_INDEX_FILE'] = newIndex + def merge(h1, h2, branch1Name, branch2Name, graph, callDepth=0): '''Merge the commits h1 and h2, return the resulting virtual commit object and a flag indicating the cleaness of the merge.'''
@@ -39,13 +55,10 @@ def merge(h1, h2, branch1Name, branch2Na assert(isinstance(Ms, Commit)) if callDepth == 0: - if len(ca) > 1: - runProgram(['git-read-tree', h1.tree()]) - runProgram(['git-update-index', '-q', '--refresh']) - # Use the original index if we only have one common ancestor - + setupIndex(False) cleanCache = False else: + setupIndex(True) runProgram(['git-read-tree', h1.tree()]) cleanCache = True
From: Fredrik Kuivinen <hidden>
Date: 2016-06-15 22:42:06
Signed-off-by: Fredrik Kuivinen <redacted> --- git-merge-recursive.py | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) c8d10db0a5380fc52681255b78433390b357c4d0
diff --git a/git-merge-recursive.py b/git-merge-recursive.py
--- a/git-merge-recursive.py
+++ b/git-merge-recursive.py@@ -41,7 +41,7 @@ def merge(h1, h2, branch1Name, branch2Na if callDepth == 0: if len(ca) > 1: runProgram(['git-read-tree', h1.tree()]) - runProgram(['git-update-cache', '-q', '--refresh']) + runProgram(['git-update-index', '-q', '--refresh']) # Use the original index if we only have one common ancestor cleanCache = False
@@ -205,14 +205,14 @@ def processEntry(entry, branch1Name, bra assert(False) if updateWd and updateCache: - runProgram(['git-update-cache', '--add', '--', path]) + runProgram(['git-update-index', '--add', '--', path]) elif updateCache: - runProgram(['git-update-cache', '--add', '--cacheinfo', + runProgram(['git-update-index', '--add', '--cacheinfo', '0%o' % mode, sha, path]) def removeFile(clean, path): if cleanCache or (not cleanCache and clean): - runProgram(['git-update-cache', '--force-remove', '--', path]) + runProgram(['git-update-index', '--force-remove', '--', path]) if not cleanCache and clean: try:
From: Fredrik Kuivinen <hidden>
Date: 2016-06-15 22:42:06
git-merge.sh does this for us. Signed-off-by: Fredrik Kuivinen <redacted> --- git-merge-recursive.py | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) e0e1a108a224b6bf202beb59c1514325205d3638
diff --git a/git-merge-recursive.py b/git-merge-recursive.py
--- a/git-merge-recursive.py
+++ b/git-merge-recursive.py@@ -423,5 +423,4 @@ except: if clean: sys.exit(0) else: - print 'Automatic merge failed, fix up by hand' sys.exit(1)
From: Fredrik Kuivinen <hidden>
Date: 2016-06-15 22:42:06
Signed-off-by: Fredrik Kuivinen <redacted> --- gitMergeCommon.py | 27 +++++++++++++-------------- 1 files changed, 13 insertions(+), 14 deletions(-) bd535d629be12d94648a40c2feb89cf14482f772
diff --git a/gitMergeCommon.py b/gitMergeCommon.py
--- a/gitMergeCommon.py
+++ b/gitMergeCommon.py@@ -1,19 +1,24 @@ import sys, re, os, traceback from sets import Set +def die(*args): + printList(args, sys.stderr) + sys.exit(2) + +def printList(list, file=sys.stdout): + for x in list: + file.write(str(x)) + file.write(' ') + file.write('\n') + if sys.version_info[0] < 2 or \ (sys.version_info[0] == 2 and sys.version_info[1] < 4): - print 'Python version 2.4 required, found', \ - str(sys.version_info[0])+'.'+str(sys.version_info[1])+'.'+ \ - str(sys.version_info[2]) - sys.exit(1) + die('Python version 2.4 required, found', \ + str(sys.version_info[0])+'.'+str(sys.version_info[1])+'.'+ \ + str(sys.version_info[2])) import subprocess -def die(*args): - printList(args, sys.stderr) - sys.exit(2) - # Debugging machinery # -------------------
@@ -32,12 +37,6 @@ def debug(*args): if funcName in functionsToDebug: printList(args) -def printList(list, file=sys.stdout): - for x in list: - file.write(str(x)) - file.write(' ') - file.write('\n') - # Program execution # -----------------