Mercurial > hg > hg-fastimport
comparison hgfastimport/hgimport.py @ 62:76bd0ea8add3
Update to cope with API differences.
| author | Jelmer Vernooij <jelmer@samba.org> |
|---|---|
| date | Thu, 10 Nov 2011 23:09:10 +0100 |
| parents | a88f0dd05e92 |
| children | ae32828c68d7 |
comparison
equal
deleted
inserted
replaced
| 61:a1558739bd5e | 62:76bd0ea8add3 |
|---|---|
| 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 def __init__(self, ui, repo): | 144 def __init__(self, ui, repo): |
| 132 super(HgImportProcessor, self).__init__() | 145 super(HgImportProcessor, self).__init__() |
| 301 # we see that, revert to plain old "jsmith". | 314 # we see that, revert to plain old "jsmith". |
| 302 user = userinfo[0] | 315 user = userinfo[0] |
| 303 else: | 316 else: |
| 304 user = "%s <%s>" % (userinfo[0], userinfo[1]) | 317 user = "%s <%s>" % (userinfo[0], userinfo[1]) |
| 305 | 318 |
| 306 assert type(cmd.message) is unicode | 319 text = cmd.message |
| 307 text = cmd.message.encode("utf-8") | |
| 308 date = self.convert_date(userinfo) | 320 date = self.convert_date(userinfo) |
| 309 | 321 |
| 310 parents = filter(None, [first_parent, second_parent]) | 322 parents = filter(None, [first_parent, second_parent]) |
| 311 commit = common.commit(user, date, text, parents, branch, rev=cmd.id) | 323 commit = common.commit(user, date, text, parents, branch, rev=cmd.id) |
| 312 | 324 |
| 398 self.inlinecount += 1 | 410 self.inlinecount += 1 |
| 399 | 411 |
| 400 fileid = (self.command.id, blobid) | 412 fileid = (self.command.id, blobid) |
| 401 | 413 |
| 402 self.modified.append((filecmd.path, fileid)) | 414 self.modified.append((filecmd.path, fileid)) |
| 403 if filecmd.mode.endswith("644"): # normal file | 415 if stat.S_ISLNK(filecmd.mode): # link |
| 416 mode = 'l' | |
| 417 elif filecmd.mode & 0111: # executable | |
| 418 mode = 'x' | |
| 419 elif stat.S_ISREG(filecmd.mode): # regular file | |
| 404 mode = '' | 420 mode = '' |
| 405 elif filecmd.mode.endswith("755"): # executable | |
| 406 mode = 'x' | |
| 407 elif filecmd.mode == "120000": # symlink | |
| 408 mode = 'l' | |
| 409 else: | 421 else: |
| 410 raise RuntimeError("mode %r unsupported" % filecmd.mode) | 422 raise RuntimeError("mode %r unsupported" % filecmd.mode) |
| 411 | 423 |
| 412 self.mode[filecmd.path] = mode | 424 self.mode[filecmd.path] = mode |
| 413 | 425 |
