From 74c5a6865394f15b427c517b7dcfbe33730b9d0e Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Thu, 17 Apr 2025 13:51:19 -0700 Subject: [PATCH] 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 Commit-Queue: Gavin Mak --- gclient_scm.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gclient_scm.py b/gclient_scm.py index d6f1442117..1948090763 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -1332,10 +1332,13 @@ class GitWrapper(SCMWrapper): def _UpdateMirrorIfNotContains(self, mirror, options, rev_type, 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. """ - 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: self.Print('skipping mirror update, it has rev=%s already' % revision, @@ -1351,8 +1354,10 @@ class GitWrapper(SCMWrapper): depth=depth, lock_timeout=getattr(options, 'lock_timeout', 0)) - # Make sure we've actually fetched the revision we want. - if rev_type == 'hash' and not mirror.contains_revision(revision): + # Make sure we've actually fetched the revision we want, but only if it + # 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}.') def _Clone(self, revision, url, options):