# HG changeset patch # User Greg Ward # Date 1437935552 14400 # Node ID ae32828c68d7a926d184fb10cde3c4e4ed3200bc # Parent b3faf593a4712f694b90fd7c3170d7bafdab29f3# Parent beea8322489001f538bffda1b76d64d6fb9c9399 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. diff -r b3faf593a471 -r ae32828c68d7 README.txt --- a/README.txt Sun Jul 26 14:09:40 2015 -0400 +++ b/README.txt Sun Jul 26 14:32:32 2015 -0400 @@ -27,26 +27,22 @@ hg-fastimport requires Mercurial 1.3. -hg-fastimport depends on the pyfastimport library (which was extracted -from bzr-fastimport). pyfastimport lives on launchpad.net at - - https://code.launchpad.net/~gward/bzr-fastimport/reusable +hg-fastimport depends on the python-fastimport library (which was extracted +from bzr-fastimport). python-fastimport lives on launchpad.net at -Alternately, I maintain a Mercurial mirror of pyfastimport, so you can -just use Mercurial to get the code: + https://code.launchpad.net/python-fastimport - hg clone http://vc.gerg.ca/hg/pyfastimport/ - -To make the 'fastimport' package provided by pyfastimport available -to hg-fastimport, you need to add the pyfastimport directory to +To make the 'fastimport' package provided by python-fastimport available +to hg-fastimport, you need to add the python-fastimport directory to PYTHONPATH, e.g. PYTHONPATH=$HOME/src/pyfastimport -(Yes, this should get simpler in future: right now, both pyfastimport -and hg-fastimport are under active development, so things are a bit -messy. Bear with me.) +It should also be possible to install python-fastimport from cheeshop: + $ easy_install install python-fastimport + +And most Linux distributions have it packaged. USAGE ----- @@ -117,6 +113,7 @@ contributors: Paul Aurich + Jelmer Vernooij COPYRIGHT diff -r b3faf593a471 -r ae32828c68d7 hgfastimport/__init__.py --- a/hgfastimport/__init__.py Sun Jul 26 14:09:40 2015 -0400 +++ b/hgfastimport/__init__.py Sun Jul 26 14:32:32 2015 -0400 @@ -2,7 +2,6 @@ from mercurial.i18n import _ from hgext.convert import convcmd, hg -from fastimport import parser from hgimport import fastimport_source def fastimport(ui, repo, *sources, **opts): diff -r b3faf593a471 -r ae32828c68d7 hgfastimport/hgimport.py --- a/hgfastimport/hgimport.py Sun Jul 26 14:09:40 2015 -0400 +++ b/hgfastimport/hgimport.py Sun Jul 26 14:32:32 2015 -0400 @@ -22,6 +22,8 @@ import os import shutil +import stat +import sys from hgext.convert import common, hg as converthg @@ -123,9 +125,20 @@ def _parse(self): if self.parsed: return - processor.parseMany(self.sources, parser.ImportParser, self.processor) + for source in self.sources: + if source == "-": + infile = sys.stdin + else: + infile = open(source, 'rb') + try: + p = parser.ImportParser(infile) + self.processor.process(p.iter_commands) + finally: + if infile is not sys.stdin: + infile.close() self.parsed = True + class HgImportProcessor(processor.ImportProcessor): tagprefix = "refs/tags/" @@ -311,8 +324,7 @@ else: user = "%s <%s>" % (userinfo[0], userinfo[1]) - assert type(cmd.message) is unicode - text = cmd.message.encode("utf-8") + text = cmd.message date = self.convert_date(userinfo) parents = filter(None, [first_parent, second_parent]) @@ -408,12 +420,12 @@ fileid = (self.command.id, blobid) self.modified.append((filecmd.path, fileid)) - if filecmd.mode.endswith("644"): # normal file + if stat.S_ISLNK(filecmd.mode): # link + mode = 'l' + elif filecmd.mode & 0111: # executable + mode = 'x' + elif stat.S_ISREG(filecmd.mode): # regular file mode = '' - elif filecmd.mode.endswith("755"): # executable - mode = 'x' - elif filecmd.mode == "120000": # symlink - mode = 'l' else: raise RuntimeError("mode %r unsupported" % filecmd.mode) diff -r b3faf593a471 -r ae32828c68d7 tests/test-fastimport-anonbranch.out --- a/tests/test-fastimport-anonbranch.out Sun Jul 26 14:09:40 2015 -0400 +++ b/tests/test-fastimport-anonbranch.out Sun Jul 26 14:32:32 2015 -0400 @@ -11,25 +11,25 @@ 0 merge Removing blob dir 'HGTMP/test-fastimport-anonbranch/anonbranch/.hg/blobs' ... % log -o 6:0d34157f0c2f +o 6:ca2d9acb975f |\ merge | | -| o 5:b1437926634f +| o 5:426c5bd79694 | | modify foo | | -o | 4:3f6a069667a2 +o | 4:32f018ede0f8 | | remove oog | | -| o 3:6c4eac9a38c2 +| o 3:7c78b201cf49 | | modify bla | | -o | 2:26171fc4359c +o | 2:b4dd3ea3dee1 |/ add oog | -o 1:eda61aa1eb80 +o 1:60da203876bc | modify foo, add bla | -o 0:984734388051 +o 0:2eab317db71a initial revision % manifest at rev 0 @@ -52,14 +52,14 @@ % contents of bla at rev 6 blah blah % diff merge with first parent (rev 4:6) -diff -r 3f6a069667a2 -r 0d34157f0c2f bla +diff -r 32f018ede0f8 -r ca2d9acb975f bla --- a/bla Thu Jan 10 21:23:00 2008 +0000 +++ b/bla Thu Jan 10 21:24:00 2008 +0000 @@ -1,1 +1,1 @@ -bla +blah blah % diff merge with second parent (rev 5:6) -diff -r b1437926634f -r 0d34157f0c2f foo +diff -r 426c5bd79694 -r ca2d9acb975f foo --- a/foo Thu Jan 10 21:23:30 2008 +0000 +++ b/foo Thu Jan 10 21:24:00 2008 +0000 @@ -1,1 +1,1 @@ diff -r b3faf593a471 -r ae32828c68d7 tests/test-fastimport-simple.out --- a/tests/test-fastimport-simple.out Sun Jul 26 14:09:40 2015 -0400 +++ b/tests/test-fastimport-simple.out Sun Jul 26 14:32:32 2015 -0400 @@ -6,13 +6,13 @@ 0 add a line Removing blob dir 'HGTMP/test-fastimport-simple/simple/.hg/blobs' ... % hg log -changeset: 1:ec2bd7ac5b27 +changeset: 1:777dd8cf7297 tag: tip user: Example date: Thu Jan 10 21:20:01 2008 +0000 summary: add a line -changeset: 0:b7a8255f9622 +changeset: 0:1e4114af38f1 user: Example date: Thu Jan 10 21:20:00 2008 +0000 summary: initial revision