Mercurial > hg-git
comparison hggit/git_handler.py @ 996:eb01d99111b6
stop dying if extras is malformed
A commit's extras field should be considered user-supplied input that can take
any form. Trusting it to be properly formatted is dangerous and can prevent
forward progress. Instead, swallow errors due to malformed extras and carry on.
author | Ryan McElroy <rmcelroy@fb.com> |
---|---|
date | Mon, 05 Sep 2016 03:04:24 -0700 |
parents | c4a2ef796c19 |
children | d0ce6eaebe7b |
comparison
equal
deleted
inserted
replaced
995:c4a2ef796c19 | 996:eb01d99111b6 |
---|---|
462 for i, ctx in enumerate(export): | 462 for i, ctx in enumerate(export): |
463 self.ui.progress('exporting', i, total=total) | 463 self.ui.progress('exporting', i, total=total) |
464 self.export_hg_commit(ctx.node(), exporter) | 464 self.export_hg_commit(ctx.node(), exporter) |
465 self.ui.progress('exporting', None, total=total) | 465 self.ui.progress('exporting', None, total=total) |
466 | 466 |
467 def set_commiter_from_author(self, commit): | |
468 commit.committer = commit.author | |
469 commit.commit_time = commit.author_time | |
470 commit.commit_timezone = commit.author_timezone | |
471 | |
467 # convert this commit into git objects | 472 # convert this commit into git objects |
468 # go through the manifest, convert all blobs/trees we don't have | 473 # go through the manifest, convert all blobs/trees we don't have |
469 # write the commit object (with metadata info) | 474 # write the commit object (with metadata info) |
470 def export_hg_commit(self, rev, exporter): | 475 def export_hg_commit(self, rev, exporter): |
471 self.ui.note(_("converting revision %s\n") % hex(rev)) | 476 self.ui.note(_("converting revision %s\n") % hex(rev)) |
487 commit.author = self.get_git_author(ctx) | 492 commit.author = self.get_git_author(ctx) |
488 commit.author_time = int(time) | 493 commit.author_time = int(time) |
489 commit.author_timezone = -timezone | 494 commit.author_timezone = -timezone |
490 | 495 |
491 if 'committer' in extra: | 496 if 'committer' in extra: |
492 # fixup timezone | 497 try: |
493 (name, timestamp, timezone) = extra['committer'].rsplit(' ', 2) | 498 # fixup timezone |
494 commit.committer = name | 499 (name, timestamp, timezone) = extra['committer'].rsplit(' ', 2) |
495 commit.commit_time = timestamp | 500 commit.committer = name |
496 | 501 commit.commit_time = timestamp |
497 # work around a timezone format change | 502 |
498 if int(timezone) % 60 != 0: # pragma: no cover | 503 # work around a timezone format change |
499 timezone = parse_timezone(timezone) | 504 if int(timezone) % 60 != 0: # pragma: no cover |
500 # Newer versions of Dulwich return a tuple here | 505 timezone = parse_timezone(timezone) |
501 if isinstance(timezone, tuple): | 506 # Newer versions of Dulwich return a tuple here |
502 timezone, neg_utc = timezone | 507 if isinstance(timezone, tuple): |
503 commit._commit_timezone_neg_utc = neg_utc | 508 timezone, neg_utc = timezone |
504 else: | 509 commit._commit_timezone_neg_utc = neg_utc |
505 timezone = -int(timezone) | 510 else: |
506 commit.commit_timezone = timezone | 511 timezone = -int(timezone) |
512 commit.commit_timezone = timezone | |
513 except: # extra is essentially user-supplied, we must be careful | |
514 self.set_commiter_from_author(commit) | |
507 else: | 515 else: |
508 commit.committer = commit.author | 516 self.set_commiter_from_author(commit) |
509 commit.commit_time = commit.author_time | |
510 commit.commit_timezone = commit.author_timezone | |
511 | 517 |
512 commit.parents = [] | 518 commit.parents = [] |
513 for parent in self.get_git_parents(ctx): | 519 for parent in self.get_git_parents(ctx): |
514 hgsha = hex(parent.node()) | 520 hgsha = hex(parent.node()) |
515 git_sha = self.map_git_get(hgsha) | 521 git_sha = self.map_git_get(hgsha) |