Mercurial > hg > hg-fastimport
comparison hgfastimport/hgimport.py @ 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 | c82b6a84884f 76bd0ea8add3 |
| children | 47bc97e1c46f |
comparison
equal
deleted
inserted
replaced
| 65:b3faf593a471 | 66:ae32828c68d7 |
|---|---|
| 20 for basing real processors on. See the processors package for examples. | 20 for basing real processors on. See the processors package for examples. |
| 21 """ | 21 """ |
| 22 | 22 |
| 23 import os | 23 import os |
| 24 import shutil | 24 import shutil |
| 25 import stat | |
| 26 import sys | |
| 25 | 27 |
| 26 from hgext.convert import common, hg as converthg | 28 from hgext.convert import common, hg as converthg |
| 27 | 29 |
| 28 from fastimport import processor, parser | 30 from fastimport import processor, parser |
| 29 | 31 |
| 121 # private worker methods | 123 # private worker methods |
| 122 | 124 |
| 123 def _parse(self): | 125 def _parse(self): |
| 124 if self.parsed: | 126 if self.parsed: |
| 125 return | 127 return |
| 126 processor.parseMany(self.sources, parser.ImportParser, self.processor) | 128 for source in self.sources: |
| 129 if source == "-": | |
| 130 infile = sys.stdin | |
| 131 else: | |
| 132 infile = open(source, 'rb') | |
| 133 try: | |
| 134 p = parser.ImportParser(infile) | |
| 135 self.processor.process(p.iter_commands) | |
| 136 finally: | |
| 137 if infile is not sys.stdin: | |
| 138 infile.close() | |
| 127 self.parsed = True | 139 self.parsed = True |
| 140 | |
| 128 | 141 |
| 129 class HgImportProcessor(processor.ImportProcessor): | 142 class HgImportProcessor(processor.ImportProcessor): |
| 130 | 143 |
| 131 tagprefix = "refs/tags/" | 144 tagprefix = "refs/tags/" |
| 132 | 145 |
| 309 # we see that, revert to plain old "jsmith". | 322 # we see that, revert to plain old "jsmith". |
| 310 user = userinfo[0] | 323 user = userinfo[0] |
| 311 else: | 324 else: |
| 312 user = "%s <%s>" % (userinfo[0], userinfo[1]) | 325 user = "%s <%s>" % (userinfo[0], userinfo[1]) |
| 313 | 326 |
| 314 assert type(cmd.message) is unicode | 327 text = cmd.message |
| 315 text = cmd.message.encode("utf-8") | |
| 316 date = self.convert_date(userinfo) | 328 date = self.convert_date(userinfo) |
| 317 | 329 |
| 318 parents = filter(None, [first_parent, second_parent]) | 330 parents = filter(None, [first_parent, second_parent]) |
| 319 commit = common.commit(user, date, text, parents, branch, rev=cmd.id) | 331 commit = common.commit(user, date, text, parents, branch, rev=cmd.id) |
| 320 | 332 |
| 406 self.inlinecount += 1 | 418 self.inlinecount += 1 |
| 407 | 419 |
| 408 fileid = (self.command.id, blobid) | 420 fileid = (self.command.id, blobid) |
| 409 | 421 |
| 410 self.modified.append((filecmd.path, fileid)) | 422 self.modified.append((filecmd.path, fileid)) |
| 411 if filecmd.mode.endswith("644"): # normal file | 423 if stat.S_ISLNK(filecmd.mode): # link |
| 424 mode = 'l' | |
| 425 elif filecmd.mode & 0111: # executable | |
| 426 mode = 'x' | |
| 427 elif stat.S_ISREG(filecmd.mode): # regular file | |
| 412 mode = '' | 428 mode = '' |
| 413 elif filecmd.mode.endswith("755"): # executable | |
| 414 mode = 'x' | |
| 415 elif filecmd.mode == "120000": # symlink | |
| 416 mode = 'l' | |
| 417 else: | 429 else: |
| 418 raise RuntimeError("mode %r unsupported" % filecmd.mode) | 430 raise RuntimeError("mode %r unsupported" % filecmd.mode) |
| 419 | 431 |
| 420 self.mode[filecmd.path] = mode | 432 self.mode[filecmd.path] = mode |
| 421 | 433 |
