Add new constants for last-upload-hash and gerritsquashhash
Also add comments.
Bug: 1382528
Change-Id: If4311f36e7d1f591be48a6d0de772701290d69db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4015279
Auto-Submit: Gavin Mak <gavinmak@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
diff --git a/git_cl.py b/git_cl.py
index fceee9f..a93f7db 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -125,6 +125,13 @@
ISSUE_CONFIG_KEY = 'gerritissue'
PATCHSET_CONFIG_KEY = 'gerritpatchset'
CODEREVIEW_SERVER_CONFIG_KEY = 'gerritserver'
+# When using squash workflow, _CMDUploadChange doesn't simply push the commit(s)
+# you make to Gerrit. Instead, it creates a new commit object that contains all
+# changes you've made, diffed against a parent/merge base.
+# This is the hash of the new squashed commit and you can find this on Gerrit.
+GERRIT_SQUASH_HASH_CONFIG_KEY = 'gerritsquashhash'
+# This is the latest uploaded local commit hash.
+LAST_UPLOAD_HASH_CONFIG_KEY = 'last-upload-hash'
# Shortcut since it quickly becomes repetitive.
Fore = colorama.Fore
@@ -1289,11 +1296,11 @@
else:
# Reset all of these just to be clean.
reset_suffixes = [
- 'last-upload-hash',
+ LAST_UPLOAD_HASH_CONFIG_KEY,
ISSUE_CONFIG_KEY,
PATCHSET_CONFIG_KEY,
CODEREVIEW_SERVER_CONFIG_KEY,
- 'gerritsquashhash',
+ GERRIT_SQUASH_HASH_CONFIG_KEY,
]
for prop in reset_suffixes:
try:
@@ -1598,7 +1605,8 @@
options, git_diff_args, custom_cl_base, change_desc)
if not ret:
self._GitSetBranchConfigValue(
- 'last-upload-hash', scm.GIT.ResolveCommit(settings.GetRoot(), 'HEAD'))
+ LAST_UPLOAD_HASH_CONFIG_KEY,
+ scm.GIT.ResolveCommit(settings.GetRoot(), 'HEAD'))
# Run post upload hooks, if specified.
if settings.GetRunPostUploadHook():
self.RunPostUploadHook(options.verbose, base_branch,
@@ -2108,7 +2116,7 @@
'Are you sure you wish to bypass it?\n',
action='bypass CQ')
differs = True
- last_upload = self._GitGetBranchConfigValue('gerritsquashhash')
+ last_upload = self._GitGetBranchConfigValue(GERRIT_SQUASH_HASH_CONFIG_KEY)
# Note: git diff outputs nothing if there is no diff.
if not last_upload or RunGit(['diff', last_upload]).strip():
print('WARNING: Some changes from local branch haven\'t been uploaded.')
@@ -2217,8 +2225,8 @@
self.SetIssue(parsed_issue_arg.issue)
self.SetPatchset(patchset)
fetched_hash = scm.GIT.ResolveCommit(settings.GetRoot(), 'FETCH_HEAD')
- self._GitSetBranchConfigValue('last-upload-hash', fetched_hash)
- self._GitSetBranchConfigValue('gerritsquashhash', fetched_hash)
+ self._GitSetBranchConfigValue(LAST_UPLOAD_HASH_CONFIG_KEY, fetched_hash)
+ self._GitSetBranchConfigValue(GERRIT_SQUASH_HASH_CONFIG_KEY, fetched_hash)
else:
print('WARNING: You are in detached HEAD state.\n'
'The patch has been applied to your checkout, but you will not be '
@@ -2631,7 +2639,7 @@
('Created|Updated %d issues on Gerrit, but only 1 expected.\n'
'Change-Id: %s') % (len(change_numbers), change_id), change_desc)
self.SetIssue(change_numbers[0])
- self._GitSetBranchConfigValue('gerritsquashhash', ref_to_push)
+ self._GitSetBranchConfigValue(GERRIT_SQUASH_HASH_CONFIG_KEY, ref_to_push)
if self.GetIssue() and (reviewers or cc):
# GetIssue() is not set in case of non-squash uploads according to tests.
@@ -2689,8 +2697,8 @@
# the tree hash of the parent branch. The upside is less likely bogus
# requests to reupload parent change just because it's uploadhash is
# missing, yet the downside likely exists, too (albeit unknown to me yet).
- parent = scm.GIT.GetBranchConfig(
- settings.GetRoot(), upstream_branch_name, 'gerritsquashhash')
+ parent = scm.GIT.GetBranchConfig(settings.GetRoot(), upstream_branch_name,
+ GERRIT_SQUASH_HASH_CONFIG_KEY)
# Verify that the upstream branch has been uploaded too, otherwise
# Gerrit will create additional CLs when uploading.
if not parent or (RunGitSilent(['rev-parse', upstream_branch + ':']) !=
@@ -5008,9 +5016,9 @@
if not issue:
DieWithError('No issue found for current branch (%s)' % branch)
- base = cl._GitGetBranchConfigValue('last-upload-hash')
+ base = cl._GitGetBranchConfigValue(LAST_UPLOAD_HASH_CONFIG_KEY)
if not base:
- base = cl._GitGetBranchConfigValue('gerritsquashhash')
+ base = cl._GitGetBranchConfigValue(GERRIT_SQUASH_HASH_CONFIG_KEY)
if not base:
detail = cl._GetChangeDetail(['CURRENT_REVISION', 'CURRENT_COMMIT'])
revision_info = detail['revisions'][detail['current_revision']]