Only check mirror existence for actual SHA-1 commit hashes

Refine the post-mirror-update check in `_UpdateMirrorIfNotContains` to
verify only when the hash revision is a SHA-1 hash. This fixes a
regression where syncing refs under refs/changes/* fails because the
check was incorrectly applied to non-hash revision strings.

Bug: 407864212, 341208163
Change-Id: I07dfe29fa7f27f6c69fa281762779e305e83b91f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6469936
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
This commit is contained in:
Gavin Mak
2025-04-17 13:51:19 -07:00
committed by LUCI CQ
parent a4b9f2a0c1
commit 74c5a68653

View File

@@ -1332,10 +1332,13 @@ class GitWrapper(SCMWrapper):
def _UpdateMirrorIfNotContains(self, mirror, options, rev_type, revision): def _UpdateMirrorIfNotContains(self, mirror, options, rev_type, revision):
"""Update a git mirror unless it already contains a hash revision. """Update a git mirror unless it already contains a hash revision.
This raises an error if a hash revision isn't present even after This raises an error if a SHA-1 revision isn't present even after
fetching from the remote. fetching from the remote.
""" """
if rev_type == 'hash' and mirror.contains_revision(revision): # 'hash' is overloaded and can refer to a SHA-1 hash or refs/changes/*.
is_sha = gclient_utils.IsFullGitSha(revision)
if rev_type == 'hash' and is_sha and mirror.contains_revision(revision):
if options.verbose: if options.verbose:
self.Print('skipping mirror update, it has rev=%s already' % self.Print('skipping mirror update, it has rev=%s already' %
revision, revision,
@@ -1351,8 +1354,10 @@ class GitWrapper(SCMWrapper):
depth=depth, depth=depth,
lock_timeout=getattr(options, 'lock_timeout', 0)) lock_timeout=getattr(options, 'lock_timeout', 0))
# Make sure we've actually fetched the revision we want. # Make sure we've actually fetched the revision we want, but only if it
if rev_type == 'hash' and not mirror.contains_revision(revision): # was specified as an explicit commit hash.
if rev_type == 'hash' and is_sha and not mirror.contains_revision(
revision):
raise gclient_utils.Error(f'Failed to fetch {revision}.') raise gclient_utils.Error(f'Failed to fetch {revision}.')
def _Clone(self, revision, url, options): def _Clone(self, revision, url, options):