summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvain <sylvain.desodt@gmail.com>2023-09-11 13:38:00 +0200
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-09-11 12:35:19 +0000
commit56a5a01c659ab005d9a0820f16e927e6253ab80c (patch)
treec5566e156369f783b82f5e6261ed7607ae4c56cb
parente9cb3911178669cb16a65ab5741eea44b79fea03 (diff)
downloadgit-repo-56a5a01c659ab005d9a0820f16e927e6253ab80c.tar.gz
project: Use IsId instead of ID_RE.match
Change-Id: I8ca83a034400da0cb97cba41415bfc50858a898b Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/385857 Tested-by: Sylvain Desodt <sylvain.desodt@gmail.com> Commit-Queue: Sylvain Desodt <sylvain.desodt@gmail.com> Reviewed-by: Mike Frysinger <vapier@google.com>
-rw-r--r--project.py21
1 files changed, 7 insertions, 14 deletions
diff --git a/project.py b/project.py
index f2f81d7a..84c66867 100644
--- a/project.py
+++ b/project.py
@@ -44,7 +44,6 @@ from git_command import GitCommand
44from git_config import GetSchemeFromUrl 44from git_config import GetSchemeFromUrl
45from git_config import GetUrlCookieFile 45from git_config import GetUrlCookieFile
46from git_config import GitConfig 46from git_config import GitConfig
47from git_config import ID_RE
48from git_config import IsId 47from git_config import IsId
49from git_refs import GitRefs 48from git_refs import GitRefs
50from git_refs import HEAD 49from git_refs import HEAD
@@ -1354,10 +1353,8 @@ class Project(object):
1354 remote_fetched = False 1353 remote_fetched = False
1355 if not ( 1354 if not (
1356 optimized_fetch 1355 optimized_fetch
1357 and ( 1356 and IsId(self.revisionExpr)
1358 ID_RE.match(self.revisionExpr) 1357 and self._CheckForImmutableRevision()
1359 and self._CheckForImmutableRevision()
1360 )
1361 ): 1358 ):
1362 remote_fetched = True 1359 remote_fetched = True
1363 try: 1360 try:
@@ -1674,7 +1671,7 @@ class Project(object):
1674 ) 1671 )
1675 1672
1676 branch.remote = self.GetRemote() 1673 branch.remote = self.GetRemote()
1677 if not ID_RE.match(self.revisionExpr): 1674 if not IsId(self.revisionExpr):
1678 # In case of manifest sync the revisionExpr might be a SHA1. 1675 # In case of manifest sync the revisionExpr might be a SHA1.
1679 branch.merge = self.revisionExpr 1676 branch.merge = self.revisionExpr
1680 if not branch.merge.startswith("refs/"): 1677 if not branch.merge.startswith("refs/"):
@@ -1924,9 +1921,7 @@ class Project(object):
1924 branch = self.GetBranch(name) 1921 branch = self.GetBranch(name)
1925 branch.remote = self.GetRemote() 1922 branch.remote = self.GetRemote()
1926 branch.merge = branch_merge 1923 branch.merge = branch_merge
1927 if not branch.merge.startswith("refs/") and not ID_RE.match( 1924 if not branch.merge.startswith("refs/") and not IsId(branch_merge):
1928 branch_merge
1929 ):
1930 branch.merge = R_HEADS + branch_merge 1925 branch.merge = R_HEADS + branch_merge
1931 1926
1932 if revision is None: 1927 if revision is None:
@@ -2077,7 +2072,7 @@ class Project(object):
2077 ) 2072 )
2078 b.Wait() 2073 b.Wait()
2079 finally: 2074 finally:
2080 if ID_RE.match(old): 2075 if IsId(old):
2081 self.bare_git.DetachHead(old) 2076 self.bare_git.DetachHead(old)
2082 else: 2077 else:
2083 self.bare_git.SetHead(old) 2078 self.bare_git.SetHead(old)
@@ -2379,7 +2374,6 @@ class Project(object):
2379 retry_sleep_initial_sec=4.0, 2374 retry_sleep_initial_sec=4.0,
2380 retry_exp_factor=2.0, 2375 retry_exp_factor=2.0,
2381 ) -> bool: 2376 ) -> bool:
2382 is_sha1 = False
2383 tag_name = None 2377 tag_name = None
2384 # The depth should not be used when fetching to a mirror because 2378 # The depth should not be used when fetching to a mirror because
2385 # it will result in a shallow repository that cannot be cloned or 2379 # it will result in a shallow repository that cannot be cloned or
@@ -2391,8 +2385,7 @@ class Project(object):
2391 if depth: 2385 if depth:
2392 current_branch_only = True 2386 current_branch_only = True
2393 2387
2394 if ID_RE.match(self.revisionExpr) is not None: 2388 is_sha1 = bool(IsId(self.revisionExpr))
2395 is_sha1 = True
2396 2389
2397 if current_branch_only: 2390 if current_branch_only:
2398 if self.revisionExpr.startswith(R_TAGS): 2391 if self.revisionExpr.startswith(R_TAGS):
@@ -2419,7 +2412,7 @@ class Project(object):
2419 # * otherwise, fetch all branches to make sure we end up with 2412 # * otherwise, fetch all branches to make sure we end up with
2420 # the specific commit. 2413 # the specific commit.
2421 if self.upstream: 2414 if self.upstream:
2422 current_branch_only = not ID_RE.match(self.upstream) 2415 current_branch_only = not IsId(self.upstream)
2423 else: 2416 else:
2424 current_branch_only = False 2417 current_branch_only = False
2425 2418