diff --git a/git_upstream/lib/pygitcompat.py b/git_upstream/lib/pygitcompat.py index 3a2d4f2..fb1ebc5 100644 --- a/git_upstream/lib/pygitcompat.py +++ b/git_upstream/lib/pygitcompat.py @@ -94,6 +94,10 @@ class GitUpstreamCompatCommit(Commit): def hexsha(self): return self.id + @property + def short(self): + return self.repo.git.rev_parse(self.hexsha, short=True) + @classmethod def iter_items(cls, repo, ref, path='', **kwargs): """ @@ -113,3 +117,5 @@ if not hasattr(Commit, 'iter_items'): Commit = GitUpstreamCompatCommit # monkey patch class so that Repo will use the patched class git.commit.Commit = GitUpstreamCompatCommit +else: + Commit.short = GitUpstreamCompatCommit.short diff --git a/git_upstream/lib/rebaseeditor.py b/git_upstream/lib/rebaseeditor.py index 1adb8d8..5925fdb 100644 --- a/git_upstream/lib/rebaseeditor.py +++ b/git_upstream/lib/rebaseeditor.py @@ -82,34 +82,27 @@ class RebaseEditor(GitMixin, LogDedentMixin): with codecs.open(todo_file, "w", "utf-8") as todo: for commit in commits: if not root: - root = commit.parents[0].hexsha + root = commit.parents[0] subject = commit.message.splitlines()[0] - todo.write("pick %s %s\n" % (commit.hexsha[:7], subject)) + todo.write("pick %s %s\n" % (self._shorten(commit), subject)) # if root isn't set at this point, then there were no commits if not root: todo.write("noop\n") todo.write(TODO_EPILOGUE % - {'shortrevisions': self._short_revisions(root, - commit.hexsha), - 'shortonto': self._short_onto(onto or root)}) + {'shortrevisions': "%s..%s" % (self._shorten(root), + self._shorten(commit)), + 'shortonto': self._shorten(onto or root)}) return todo_file - def _short_revisions(self, root, commit): + def _shorten(self, commit): - if not root: + if not commit: return "" - return "%s..%s" % (root[:7], commit[:7]) - - def _short_onto(self, onto): - - if not onto: - return "" - - return self.git.rev_parse(onto)[:7] + return self.git.rev_parse(commit, short=True) def _set_editor(self, editor): diff --git a/git_upstream/lib/searchers.py b/git_upstream/lib/searchers.py index dc800d0..091eae0 100644 --- a/git_upstream/lib/searchers.py +++ b/git_upstream/lib/searchers.py @@ -569,7 +569,7 @@ class SupersededCommitFilter(LogDedentMixin, GitMixin, CommitFilter): because the following superseding change-ids have not been found: %s - """, commit.hexsha[:7], commit.message.splitlines()[0], + """, commit.short, commit.message.splitlines()[0], '\n '.join(superseding_change_ids)) yield commit continue @@ -580,7 +580,7 @@ class SupersededCommitFilter(LogDedentMixin, GitMixin, CommitFilter): because it has been marked as superseded by the following note: %s - """, commit.hexsha[:7], commit.message.splitlines()[0], + """, commit.short, commit.message.splitlines()[0], commit_note) @@ -710,7 +710,7 @@ class DiscardDuplicateGerritChangeId(LogDedentMixin, GitMixin, CommitFilter): Including change missing 'Change-Id' Commit: %s %s Message: %s - """, commit.hexsha[:7], commit.message.splitlines()[0], + """, commit.short, commit.message.splitlines()[0], commit.message) yield commit continue @@ -735,7 +735,7 @@ class DiscardDuplicateGerritChangeId(LogDedentMixin, GitMixin, CommitFilter): Skipping duplicate Change-Id in search ref %s Commit: %s %s - """, change_id, commit.hexsha[:7], + """, change_id, commit.short, commit.message.splitlines()[0]) continue @@ -745,7 +745,7 @@ class DiscardDuplicateGerritChangeId(LogDedentMixin, GitMixin, CommitFilter): Including unmatched change %s Commit: %s %s - """, change_id, commit.hexsha[:7], + """, change_id, commit.short, commit.message.splitlines()[0]) yield commit