changeset 66:ae32828c68d7

Merge in Jelmer Vernooij's switch to python-fastimport over pyfastimport. Better to use his maintained library than my dusty old forgotten one. Incidentally, this merge deliberately leaves out efc96910ddf2 and descendants: that change broke the tests.
author Greg Ward <greg@gerg.ca>
date Sun, 26 Jul 2015 14:32:32 -0400
parents b3faf593a471 (diff) beea83224890 (current diff)
children d88ce26e0946
files hgfastimport/__init__.py hgfastimport/hgimport.py
diffstat 4 files changed, 31 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/hgfastimport/__init__.py	Sun Jul 26 14:25:46 2015 -0400
+++ b/hgfastimport/__init__.py	Sun Jul 26 14:32:32 2015 -0400
@@ -1,8 +1,8 @@
-from mercurial import encoding, util
+from mercurial import encoding
 from mercurial.i18n import _
 from hgext.convert import convcmd, hg
 
-from hgfastimport.hgimport import fastimport_source
+from hgimport import fastimport_source
 
 def fastimport(ui, repo, *sources, **opts):
     """Convert a git fastimport dump into Mercurial changesets.
--- a/hgfastimport/hgimport.py	Sun Jul 26 14:25:46 2015 -0400
+++ b/hgfastimport/hgimport.py	Sun Jul 26 14:32:32 2015 -0400
@@ -141,6 +141,8 @@
 
 class HgImportProcessor(processor.ImportProcessor):
     
+    tagprefix = "refs/tags/"
+
     def __init__(self, ui, repo):
         super(HgImportProcessor, self).__init__()
         self.ui = ui
@@ -213,19 +215,21 @@
         # This command means nothing to us
         pass
 
-    def _getcommit(self, committish):
+    def _getcommit(self, commitref):
         """Given a mark reference or a branch name, return the
-        appropriate commit object.  Return None if committish is a
-        branch with no commits.  Raises KeyError if anything else is out
-        of whack.
+        appropriate commit object.  Return None if commitref is a tag
+        or a branch with no commits.  Raises KeyError if anything else
+        is out of whack.
         """
-        if committish.startswith(":"):
+        if commitref.startswith(":"):
             # KeyError here indicates the input stream is broken.
-            return self.commitmap[committish]
+            return self.commitmap[commitref]
+        elif commitref.startswith(self.tagprefix):
+            return None
         else:
-            branch = self._getbranch(committish)
+            branch = self._getbranch(commitref)
             if branch is None:
-                raise ValueError("invalid committish: %r" % committish)
+                raise ValueError("invalid commit ref: %r" % commitref)
 
             heads = self.branchmap.get(branch)
             if heads is None:
@@ -258,6 +262,10 @@
         # of the fixup branch should be configurable!
         fixup = (cmd.ref == "refs/heads/TAG.FIXUP")
 
+        if cmd.ref.startswith(self.tagprefix) and cmd.mark:
+            tag = cmd.ref[len(self.tagprefix):]
+            self.tags.append((tag, ':' + cmd.mark))
+
         if cmd.from_:
             first_parent = cmd.from_
         else:
@@ -337,7 +345,7 @@
         self.ui.debug("processed commit %s\n" % cmd)
 
     def convert_date(self, c):
-        res = (int(c[2]), int(c[3]))
+        res = (int(c[2]), -int(c[3]))
         #print c, res
         #print type((0, 0)), type(res), len(res), type(res) is type((0, 0))
         #if type(res) is type((0, 0)) and len(res) == 2:
@@ -346,7 +354,6 @@
         return "%d %d" % res
         
     def reset_handler(self, cmd):
-        tagprefix = "refs/tags/"
         branch = self._getbranch(cmd.ref)
         if branch:
             # The usual case for 'reset': (re)create the named branch.
@@ -362,15 +369,16 @@
             #else:
             #    # XXX filename? line number?
             #    self.ui.warn("ignoring branch reset with no 'from'\n")
-        elif cmd.ref.startswith(tagprefix):
+        elif cmd.ref.startswith(self.tagprefix):
             # Create a "lightweight tag" in Git terms.  As I understand
             # it, that's a tag with no description and no history --
             # rather like CVS tags.  cvs2git turns CVS tags into Git
             # lightweight tags, so we should make sure they become
             # Mercurial tags.  But we don't have to fake a history for
             # them; save them up for the end.
-            tag = cmd.ref[len(tagprefix):]
-            self.tags.append((tag, cmd.from_))
+            if cmd.from_ is not None:
+                tag = cmd.ref[len(self.tagprefix):]
+                self.tags.append((tag, cmd.from_))
 
     def tag_handler(self, cmd):
         pass
--- a/tests/test-fastimport-git.out	Sun Jul 26 14:25:46 2015 -0400
+++ b/tests/test-fastimport-git.out	Sun Jul 26 14:32:32 2015 -0400
@@ -6,18 +6,18 @@
 0 modify
 Removing blob dir 'HGTMP/test-fastimport-git/simplegit/.hg/blobs' ...
 % hg log
-o  changeset:   1:0a3befda043d
+o  changeset:   1:3ba674918e3f
 |  tag:         tip
 |  user:        Joe Contributor <joe@example.com>
-|  date:        Fri Jan 11 01:20:00 2008 +0400
+|  date:        Thu Jan 10 17:20:00 2008 -0400
 |  files:       ooga
 |  description:
 |  modify
 |
 |
-o  changeset:   0:9a4b81675bd1
+o  changeset:   0:339e2fa74ac1
    user:        Example <example@example.org>
-   date:        Fri Jan 11 01:21:00 2008 +0400
+   date:        Thu Jan 10 17:21:00 2008 -0400
    files:       foo.txt ooga
    description:
    initial revision
--- a/tests/test-fastimport-nonascii.out	Sun Jul 26 14:25:46 2015 -0400
+++ b/tests/test-fastimport-nonascii.out	Sun Jul 26 14:32:32 2015 -0400
@@ -16,10 +16,10 @@
 converting...
 0 blah
 % log with non-ASCII author
-changeset:   0:e10eff2ea202
+changeset:   0:1988a11c4df7
 tag:         tip
 user:        Jürgen <juergen@example.org>
-date:        Tue Aug 11 10:13:20 2009 -0400
+date:        Tue Aug 11 18:13:20 2009 +0400
 summary:     blah
 
 % import dump with non-ASCII message
@@ -29,10 +29,10 @@
 0 fix na?ve implementation that ?le threw together for ?5
 Removing blob dir 'HGTMP/test-fastimport-nonascii/message/.hg/blobs' ...
 % log with non-ASCII message
-changeset:   0:cfd47dca9906
+changeset:   0:52b3afdff0e7
 tag:         tip
 user:        Dave <dave@example.org>
-date:        Tue Aug 11 10:13:50 2009 -0400
+date:        Tue Aug 11 18:13:50 2009 +0400
 summary:     fix naïve implementation that Øle threw together for €5
 
 % manifest