Don't generate git patches that rename a file to multiple destinations
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Mon, 20 Nov 2006 19:32:46 -0200
changeset 3702 70c3ee224c08
parent 3701 05c8704a3743
child 3703 e674cae8efee
Don't generate git patches that rename a file to multiple destinations With this patch, instead of generating N renames, we'll generate 1 rename and N-1 copies. Ideally the rename should come after the copies instead of before them, but that'd be harder to do.
mercurial/patch.py
tests/test-git-export
tests/test-git-export.out
--- a/mercurial/patch.py	Mon Nov 20 19:32:45 2006 -0200
+++ b/mercurial/patch.py	Mon Nov 20 19:32:46 2006 -0200
@@ -547,6 +547,7 @@
 
     all = modified + added + removed
     all.sort()
+    gone = {}
     for f in all:
         to = None
         tn = None
@@ -574,7 +575,11 @@
                     a, arev = copied[f]
                     omode = gitmode(mmap.execf(a))
                     addmodehdr(header, omode, mode)
-                    op = a in removed and 'rename' or 'copy'
+                    if a in removed and a not in gone:
+                        op = 'rename'
+                        gone[a] = 1
+                    else:
+                        op = 'copy'
                     header.append('%s from %s\n' % (op, a))
                     header.append('%s to %s\n' % (op, f))
                     to = getfile(a).read(arev)
--- a/tests/test-git-export	Mon Nov 20 19:32:45 2006 -0200
+++ b/tests/test-git-export	Mon Nov 20 19:32:46 2006 -0200
@@ -127,3 +127,11 @@
 echo
 echo '% created between r1 and parent of wd; renamed in the wd'
 hg diff --git -r -2
+hg ci -m 'mv brand-new brand-new2'
+
+echo '% one file is copied to many destinations and removed'
+hg cp brand-new2 brand-new3
+hg mv brand-new2 brand-new3-2
+hg ci -m 'multiple renames/copies'
+hg diff --git -r -2 -r -1
+
--- a/tests/test-git-export.out	Mon Nov 20 19:32:45 2006 -0200
+++ b/tests/test-git-export.out	Mon Nov 20 19:32:46 2006 -0200
@@ -133,3 +133,10 @@
 +++ b/brand-new2
 @@ -0,0 +1,1 @@
 +
+% one file is copied to many destinations and removed
+diff --git a/brand-new2 b/brand-new3
+rename from brand-new2
+rename to brand-new3
+diff --git a/brand-new2 b/brand-new3-2
+copy from brand-new2
+copy to brand-new3-2