Add committer tag only when needed in git conversion
authorRichard Quirk <richard.quirk@gmail.com>
Fri, 01 May 2009 11:32:19 +0200
changeset 8271 e3d3dad805f9
parent 8270 3477ad0b1f2c
child 8272 79983cfa7efe
Add committer tag only when needed in git conversion Convert from a git repo added a committer: tag in the log message even if the committer and the author were the same person.
hgext/convert/git.py
tests/test-convert-git
tests/test-convert-git.out
--- a/hgext/convert/git.py	Fri May 01 12:35:13 2009 +0200
+++ b/hgext/convert/git.py	Fri May 01 11:32:19 2009 +0200
@@ -90,6 +90,7 @@
         message = self.recode(message)
         l = c[:end].splitlines()
         parents = []
+        author = committer = None
         for e in l[1:]:
             n, v = e.split(" ", 1)
             if n == "author":
@@ -104,9 +105,10 @@
                 committer = " ".join(p[:-2])
                 if committer[0] == "<": committer = committer[1:-1]
                 committer = self.recode(committer)
-                message += "\ncommitter: %s\n" % committer
             if n == "parent": parents.append(v)
 
+        if committer and committer != author:
+            message += "\ncommitter: %s\n" % committer
         tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:]
         tz = -int(tzs) * (int(tzh) * 3600 + int(tzm))
         date = tm + " " + str(tz)
--- a/tests/test-convert-git	Fri May 01 12:35:13 2009 +0200
+++ b/tests/test-convert-git	Fri May 01 11:32:19 2009 +0200
@@ -148,4 +148,22 @@
 cd git-repo3-hg
 hg up -C
 python -c 'print len(file("b", "rb").read())'
+cd ..
 
+echo
+echo '% test author vs committer'
+mkdir git-repo4
+cd git-repo4
+git init-db >/dev/null 2>/dev/null
+echo >> foo
+git add foo
+commit -a -m addfoo
+echo >> foo
+GIT_AUTHOR_NAME="nottest"
+commit -a -m addfoo2
+cd ..
+
+echo '% convert author committer'
+hg convert git-repo4 git-repo4-hg
+cd git-repo4-hg
+hg log -v
--- a/tests/test-convert-git.out	Fri May 01 12:35:13 2009 +0200
+++ b/tests/test-convert-git.out	Fri May 01 11:32:19 2009 +0200
@@ -10,18 +10,16 @@
 2 t4.1
 1 t4.2
 0 Merge branch other
-changeset:   5:4ab1af49a271
+changeset:   5:c78094926be2
 tag:         tip
-parent:      3:0222ab0998d7
-parent:      4:5333c870e3c2
+parent:      3:f5f5cb45432b
+parent:      4:4e174f80c67c
 user:        test <test@example.org>
 date:        Mon Jan 01 00:00:15 2007 +0000
 files:       a
 description:
 Merge branch other
 
-committer: test <test@example.org>
-
 
 % full conversion
 @    9 "Discard change to foo" files: foo
@@ -98,3 +96,31 @@
 0 addbinary
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 4096
+
+% test author vs committer
+% convert author committer
+initializing destination git-repo4-hg repository
+scanning source...
+sorting...
+converting...
+1 addfoo
+0 addfoo2
+changeset:   1:d63e967f93da
+tag:         tip
+user:        nottest <test@example.org>
+date:        Mon Jan 01 00:00:21 2007 +0000
+files:       foo
+description:
+addfoo2
+
+committer: test <test@example.org>
+
+
+changeset:   0:0735477b0224
+user:        test <test@example.org>
+date:        Mon Jan 01 00:00:20 2007 +0000
+files:       foo
+description:
+addfoo
+
+