Эх сурвалжийг харах

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>
Gavin Mak 4 сар өмнө
parent
commit
74c5a68653
1 өөрчлөгдсөн 9 нэмэгдсэн , 4 устгасан
  1. 9 4
      gclient_scm.py

+ 9 - 4
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):