merge-recursive: Make use of provided bases
This makes some cases faster as we don't have to build the commit graph. Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se> Signed-off-by: Junio C Hamano <junkio@cox.net>
Fredrik Kuivinen committed
Feb 2, 2006 at 12:43 UTC
008bb6ea695e14740bfd14bec805cde6219b336e
1 file changed
+21
-10
git-merge-recursive.py
+21
-10
@@ -45,11 +45,10 @@ cacheOnly = False
45
# The entry point to the merge code
46
# ---------------------------------
47
48
-def merge(h1, h2, branch1Name, branch2Name, graph, callDepth=0):
48
+def merge(h1, h2, branch1Name, branch2Name, graph, callDepth=0, ancestor=None):
49
'''Merge the commits h1 and h2, return the resulting virtual
50
commit object and a flag indicating the cleaness of the merge.'''
51
assert(isinstance(h1, Commit) and isinstance(h2, Commit))
52
- assert(isinstance(graph, Graph))
52
53
global outputIndent
54
@@ -58,7 +57,11 @@ def merge(h1, h2, branch1Name, branch2Name, graph, callDepth=0):
57
output(h2)
58
sys.stdout.flush()
59
61
- ca = getCommonAncestors(graph, h1, h2)
60
+ if ancestor:
61
+ ca = [ancestor]
62
+ else:
63
+ assert(isinstance(graph, Graph))
64
+ ca = getCommonAncestors(graph, h1, h2)
65
output('found', len(ca), 'common ancestor(s):')
66
for x in ca:
67
output(x)
@@ -86,7 +89,7 @@ def merge(h1, h2, branch1Name, branch2Name, graph, callDepth=0):
89
[shaRes, clean] = mergeTrees(h1.tree(), h2.tree(), mergedCA.tree(),
90
branch1Name, branch2Name)
91
89
- if clean or cacheOnly:
92
+ if graph and (clean or cacheOnly):
93
res = Commit(None, [h1, h2], tree=shaRes)
94
graph.addNode(res)
95
else:
@@ -891,12 +894,11 @@ def usage():
894
895
# main entry point as merge strategy module
896
# The first parameters up to -- are merge bases, and the rest are heads.
894
-# This strategy module figures out merge bases itself, so we only
895
-# get heads.
897
898
if len(sys.argv) < 4:
899
usage()
900
901
+bases = []
902
for nextArg in xrange(1, len(sys.argv)):
903
if sys.argv[nextArg] == '--':
904
if len(sys.argv) != nextArg + 3:
@@ -907,6 +909,8 @@ for nextArg in xrange(1, len(sys.argv)):
909
except IndexError:
910
usage()
911
break
912
+ else:
913
+ bases.append(sys.argv[nextArg])
914
915
print 'Merging', h1, 'with', h2
916
@@ -914,10 +918,17 @@ try:
918
h1 = runProgram(['git-rev-parse', '--verify', h1 + '^0']).rstrip()
919
h2 = runProgram(['git-rev-parse', '--verify', h2 + '^0']).rstrip()
920
917
- graph = buildGraph([h1, h2])
918
-
919
- [dummy, clean] = merge(graph.shaMap[h1], graph.shaMap[h2],
920
- firstBranch, secondBranch, graph)
921
+ if len(bases) == 1:
922
+ base = runProgram(['git-rev-parse', '--verify',
923
+ bases[0] + '^0']).rstrip()
924
+ ancestor = Commit(base, None)
925
+ [dummy, clean] = merge(Commit(h1, None), Commit(h2, None),
926
+ firstBranch, secondBranch, None, 0,
927
+ ancestor)
928
+ else:
929
+ graph = buildGraph([h1, h2])
930
+ [dummy, clean] = merge(graph.shaMap[h1], graph.shaMap[h2],
931
+ firstBranch, secondBranch, graph)
932
933
print ''
934
except: