From 653e97553f58d2b9bc9503524465c388f3cefc5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Klitzing?= Date: Fri, 31 Jan 2025 11:42:47 +0100 Subject: [PATCH] Fix review request for already known commitID If someone pushed a commit to a tag only instead to a branch it was not recognized as "already known commit" it the hooks tried to create another review request for the same commit. So let's check tag for already known commits, too. --- contrib/mercurial_git_push.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/contrib/mercurial_git_push.py b/contrib/mercurial_git_push.py index 7f2bb9b..f1c32ba 100755 --- a/contrib/mercurial_git_push.py +++ b/contrib/mercurial_git_push.py @@ -1433,12 +1433,17 @@ class GitRevision(BaseRevision): """Class to represent information of changeset.""" @staticmethod - def fetch_known_branches(rev): - output = execute(['git', 'branch', '--contains', rev]) - branches = [] - for branch in output.splitlines(): - branches.append(branch.replace('*', '').strip()) - return branches + def fetch_known_refs(rev): + output = execute(['git', 'for-each-ref', '--contains', rev]) + refs = [] + for line in output.splitlines(): + values = line.split() + if values[1] in ('commit', 'tag') and ( + 'refs/heads/' in values[2] or + 'refs/tags/' in values[2] + ): + refs.append(values[2]) + return refs @staticmethod def fetch_raw(node, base, skipKnown=True): @@ -1454,7 +1459,7 @@ def fetch_raw(node, base, skipKnown=True): if skipKnown: def isKnown(rev): - return len(GitRevision.fetch_known_branches(rev)) > 0 + return len(GitRevision.fetch_known_refs(rev)) > 0 changes[:] = [x for x in changes if not isKnown(x)] return changes @@ -1545,7 +1550,7 @@ def hasDangling(self): if self._has_dangling is None: self._has_dangling = ( self.isMerge() and - len(GitRevision.fetch_known_branches(self.parent(1))) == 0 + len(GitRevision.fetch_known_refs(self.parent(1))) == 0 ) return self._has_dangling