changeset 5335:88e931f74e8b

convert_git: avoid returning two entries for the same file in getchanges This could happen in merge changesets if the merged file was different from both parents.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Mon, 24 Sep 2007 19:00:11 -0300
parents 448eb46d4d84
children 24de027551c1 26692d08c2f9
files hgext/convert/git.py tests/test-convert-git tests/test-convert-git.out
diffstat 3 files changed, 53 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/git.py
+++ b/hgext/convert/git.py
@@ -61,9 +61,14 @@ class convert_git(converter_source):
         self.modecache = {}
         fh = self.gitcmd("git-diff-tree --root -m -r %s" % version)
         changes = []
+        seen = {}
         for l in fh:
-            if "\t" not in l: continue
+            if "\t" not in l:
+                continue
             m, f = l[:-1].split("\t")
+            if f in seen:
+                continue
+            seen[f] = 1
             m = m.split()
             h = m[3]
             p = (m[1] == "100755")
--- a/tests/test-convert-git
+++ b/tests/test-convert-git
@@ -5,15 +5,42 @@
 echo "[extensions]" >> $HGRCPATH
 echo "convert=" >> $HGRCPATH
 
+GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME
+GIT_AUTHOR_EMAIL='test@example.org'; export GIT_AUTHOR_EMAIL
+GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0000"; export GIT_AUTHOR_DATE
+GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_NAME
+GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL
+GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE
+
+count=10
+commit()
+{
+    GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000"
+    GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
+    git commit "$@" >/dev/null 2>/dev/null || echo "git commit error"
+    count=`expr $count + 1`
+}
+
 mkdir git-repo
 cd git-repo
 git init-db >/dev/null 2>/dev/null
 echo a > a
 git add a
-git commit -m t1 >/dev/null 2>/dev/null || echo "git commit error"
+commit -m t1
+
 echo b >> a
-git commit -a -m t2 >/dev/null || echo "git commit error"
+commit -a -m t2.1
+
+git checkout -b other HEAD^ >/dev/null 2>/dev/null
+echo c > a
+echo a >> a
+commit -a -m t2.2
+
+git checkout master >/dev/null 2>/dev/null
+git pull --no-commit . other > /dev/null 2>/dev/null
+commit -m 'Merge branch other'
 cd ..
 
-hg convert git-repo
+hg convert --datesort git-repo
 
+hg -R git-repo-hg tip -v
--- a/tests/test-convert-git.out
+++ b/tests/test-convert-git.out
@@ -3,5 +3,20 @@ initializing destination git-repo-hg rep
 scanning source...
 sorting...
 converting...
-1 t1
-0 t2
+3 t1
+2 t2.1
+1 t2.2
+0 Merge branch other
+changeset:   3:f0873470732d
+tag:         tip
+parent:      1:cb991dbbb06b
+parent:      2:600bef931ca4
+user:        test <test@example.org>
+date:        Mon Jan 01 00:00:13 2007 +0000
+files:       a
+description:
+Merge branch other
+
+committer: test <test@example.org>
+
+