This patch series contains a few smaller updates to the merge-common-ancestors merge algorithm.
- Fredrik
threads / patch / 1787
Subject: [PATCH 0/5] git-merge-fredrik updates
This patch series contains a few smaller updates to the merge-common-ancestors merge algorithm.
- Fredrik
[PATCH 1/5] Fix assertion failure when merging common ancestors.
Bug reported by Junio.
Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
git-merge-fredrik.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
95251fce0dd6366478e8d51d4f187cb07d662d7a
diff --git a/git-merge-fredrik.py b/git-merge-fredrik.py --- a/git-merge-fredrik.py +++ b/git-merge-fredrik.py @@ -60,7 +60,7 @@ def merge(h1, h2, branch1Name, branch2Na branch1Name, branch2Name, cleanCache, updateWd) - if clean or alwaysWriteTree: + if clean or cleanCache: res = Commit(None, [h1, h2], tree=shaRes) graph.addNode(res) else:
[PATCH 2/5] Exit with status code 2 if we get an exception.
Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
git-merge-fredrik.py | 23 ++++++++++++++--------- 1 files changed, 14 insertions(+), 9 deletions(-)
f814a54ac034f4455363582b2c2f3d386bf8f0be
diff --git a/git-merge-fredrik.py b/git-merge-fredrik.py --- a/git-merge-fredrik.py +++ b/git-merge-fredrik.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import sys, math, random, os, re, signal, tempfile, stat, errno +import sys, math, random, os, re, signal, tempfile, stat, errno, traceback from heapq import heappush, heappop from sets import Set @@ -409,15 +409,20 @@ for nextArg in xrange(1, len(sys.argv)): break print 'Merging', h1, 'with', h2 -h1 = runProgram(['git-rev-parse', '--verify', h1 + '^0']).rstrip() -h2 = runProgram(['git-rev-parse', '--verify', h2 + '^0']).rstrip() -graph = buildGraph([h1, h2]) - -[res, clean] = merge(graph.shaMap[h1], graph.shaMap[h2], - firstBranch, secondBranch, graph) - -print '' +try: + h1 = runProgram(['git-rev-parse', '--verify', h1 + '^0']).rstrip() + h2 = runProgram(['git-rev-parse', '--verify', h2 + '^0']).rstrip() + + graph = buildGraph([h1, h2]) + + [res, clean] = merge(graph.shaMap[h1], graph.shaMap[h2], + firstBranch, secondBranch, graph) + + print '' +except: + traceback.print_exc(None, sys.stderr) + sys.exit(2) if clean: sys.exit(0)
[PATCH 3/5] Introduce a 'die' function.
Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
git-merge-fredrik.py | 15 +++++---------- gitMergeCommon.py | 12 ++++++++---- 2 files changed, 13 insertions(+), 14 deletions(-)
8ca382168d366c68c567c1f85fb6d2cb02b40f37
git-merge-fredrik.py, gitMergeCommon.py
diff --git a/git-merge-fredrik.py b/git-merge-fredrik.py --- a/git-merge-fredrik.py +++ b/git-merge-fredrik.py @@ -120,9 +120,8 @@ def unmergedCacheEntries(): e.stages[stage].mode = mode e.stages[stage].sha1 = sha1 else: - print 'Error: Merge program failed: Unexpected output from', \ - 'git-ls-files:', l - sys.exit(2) + die('Error: Merge program failed: Unexpected output from', \ + 'git-ls-files:', l) return res def mergeTrees(head, merge, common, branch1Name, branch2Name, @@ -381,15 +380,12 @@ def processEntry(entry, branch1Name, bra os.unlink(src1) os.unlink(src2) else: - print 'ERROR: Fatal merge failure.' - print "ERROR: Shouldn't happen" - sys.exit(2) + die("ERROR: Fatal merge failure, shouldn't happen.") return cleanMerge def usage(): - print 'Usage:', sys.argv[0], ' <base>... -- <head> <remote>..' - sys.exit(2) + die('Usage:', sys.argv[0], ' <base>... -- <head> <remote>..') # main entry point as merge strategy module # The first parameters up to -- are merge bases, and the rest are heads. @@ -399,8 +395,7 @@ def usage(): for nextArg in xrange(1, len(sys.argv)): if sys.argv[nextArg] == '--': if len(sys.argv) != nextArg + 3: - print 'Not handling anything other than two heads merge.' - sys.exit(2) + die('Not handling anything other than two heads merge.') try: h1 = firstBranch = sys.argv[nextArg + 1] h2 = secondBranch = sys.argv[nextArg + 2] diff --git a/gitMergeCommon.py b/gitMergeCommon.py --- a/gitMergeCommon.py +++ b/gitMergeCommon.py @@ -10,6 +10,10 @@ if sys.version_info[0] < 2 or \ import subprocess +def die(*args): + printList(args, sys.stderr) + sys.exit(2) + # Debugging machinery # ------------------- @@ -28,11 +32,11 @@ def debug(*args): if funcName in functionsToDebug: printList(args) -def printList(list): +def printList(list, file=sys.stdout): for x in list: - sys.stdout.write(str(x)) - sys.stdout.write(' ') - sys.stdout.write('\n') + file.write(str(x)) + file.write(' ') + file.write('\n') # Program execution # -----------------
[PATCH 4/5] Make sure we die if we don't get enough arguments.
Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
git-merge-fredrik.py | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
573c3e6f61eb2cb27b5d67f7a24f01a74980c769
diff --git a/git-merge-fredrik.py b/git-merge-fredrik.py --- a/git-merge-fredrik.py +++ b/git-merge-fredrik.py @@ -392,6 +392,9 @@ def usage(): # This strategy module figures out merge bases itself, so we only # get heads. +if len(sys.argv) < 4: + usage() + for nextArg in xrange(1, len(sys.argv)): if sys.argv[nextArg] == '--': if len(sys.argv) != nextArg + 3:
[PATCH 5/5] Make the ProgramError class printable.
Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
gitMergeCommon.py | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
30c12b2a8d3df83b15952f786327ccd0c3c04554
diff --git a/gitMergeCommon.py b/gitMergeCommon.py --- a/gitMergeCommon.py +++ b/gitMergeCommon.py @@ -46,6 +46,9 @@ class ProgramError(Exception): self.progStr = progStr self.error = error + def __str__(self): + return self.progStr + ': ' + self.error + addDebug('runProgram') def runProgram(prog, input=None, returnCode=False, env=None, pipeOutput=True): debug('runProgram prog:', str(prog), 'input:', str(input))
Re: [PATCH 0/5] git-merge-fredrik updates
Thanks. Will apply.
One request before we hit 0.99.7 (this Saturday) when the name will be cast in stone is to christen it better than 'fredrik' which was what I did as a tentative measure. Otherwise we would regret when you come up with another merge algorithm with different pros-and-cons with the current one.
[PATCH] Rename the 'fredrik' merge strategy to 'recursive'.
On Mon, Sep 12, 2005 at 02:58:31PM -0700, Junio C Hamano wrote:
> Thanks. Will apply. > > One request before we hit 0.99.7 (this Saturday) when the name > will be cast in stone is to christen it better than 'fredrik' > which was what I did as a tentative measure. Otherwise we would > regret when you come up with another merge algorithm with > different pros-and-cons with the current one.
I have thought about that too. Is 'git-merge-recursive.py' a good enough name?
- Fredrik
Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
.gitignore | 2 +- Makefile | 2 +- git-merge-recursive.py | 0 git-merge.sh | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) rename git-merge-fredrik.py => git-merge-recursive.py (100%)
7d5637d2df86406b4f8f3f96cbea57d977231470
.gitignore, Makefile, git-merge-fredrik.py, git-merge.sh
diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -43,10 +43,10 @@ git-mailinfo git-mailsplit git-merge git-merge-base -git-merge-fredrik git-merge-index git-merge-octopus git-merge-one-file +git-merge-recursive git-merge-resolve git-merge-stupid git-mktag diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -83,7 +83,7 @@ SCRIPT_PERL = \ git-rename.perl git-shortlog.perl SCRIPT_PYTHON = \ - git-merge-fredrik.py + git-merge-recursive.py # The ones that do not have to link with lcrypto nor lz. SIMPLE_PROGRAMS = \ diff --git a/git-merge-fredrik.py b/git-merge-recursive.py similarity index 100% rename from git-merge-fredrik.py rename to git-merge-recursive.py diff --git a/git-merge.sh b/git-merge.sh --- a/git-merge.sh +++ b/git-merge.sh @@ -12,9 +12,9 @@ usage () { die "git-merge [-n] [-s <strategy>]... <merge-message> <head> <remote>+" } -# all_strategies='resolve fredrik stupid octopus' +# all_strategies='resolve recursive stupid octopus' -all_strategies='fredrik octopus resolve stupid' +all_strategies='recursive octopus resolve stupid' default_strategies='resolve octopus' use_strategies=