tools/cl: Identify cl's by Change-Id

Otherwise we won't be able to find the corresponding gerrit change
if the commit has been ammended.

BUG=b:239840337
TEST=./tools/cl status

Change-Id: I5a9673414145a0dcc0547c1de6422992478a3094
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3885076
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
This commit is contained in:
Dennis Kempin 2022-09-08 19:36:57 +00:00 committed by crosvm LUCI
parent 644251cec0
commit a91002bb46

View file

@ -4,10 +4,12 @@
# found in the LICENSE file. # found in the LICENSE file.
import functools import functools
import re
import sys
from os import chdir from os import chdir
from pathlib import Path from pathlib import Path
from impl.common import CROSVM_ROOT, GerritChange, confirm, run_commands, cmd
import sys from impl.common import CROSVM_ROOT, GerritChange, cmd, confirm, run_commands
USAGE = """\ USAGE = """\
./tools/cl [upload|rebase|status|prune] ./tools/cl [upload|rebase|status|prune]
@ -65,9 +67,19 @@ class LocalChange(object):
sha_title = line.split(" ", 1) sha_title = line.split(" ", 1)
yield cls(sha_title[0], sha_title[1]) yield cls(sha_title[0], sha_title[1])
@functools.cached_property
def change_id(self):
msg = git("log -1 --format=email", self.sha).stdout()
match = re.search("^Change-Id: (I[a-f0-9]+)", msg, re.MULTILINE)
if not match:
return None
return match.group(1)
@functools.cached_property @functools.cached_property
def gerrit(self): def gerrit(self):
results = GerritChange.query("project:crosvm/crosvm", self.sha) if not self.change_id:
return None
results = GerritChange.query("project:crosvm/crosvm", self.change_id)
if len(results) > 1: if len(results) > 1:
raise Exception(f"Multiple gerrit changes found for commit {self.sha}: {self.title}.") raise Exception(f"Multiple gerrit changes found for commit {self.sha}: {self.title}.")
return results[0] if results else None return results[0] if results else None
@ -127,7 +139,12 @@ def prerequisites():
def print_branch_summary(branch: str): def print_branch_summary(branch: str):
print("Branch", branch, "tracking", get_upstream(branch)) upstream = get_upstream(branch)
if not upstream:
print("Branch", branch, "is not tracking an upstream branch")
print()
return
print("Branch", branch, "tracking", upstream)
changes = [*LocalChange.list_changes(branch)] changes = [*LocalChange.list_changes(branch)]
for change in changes: for change in changes:
if change.gerrit: if change.gerrit: