summaryrefslogtreecommitdiffstats
path: root/subcmds/sync.py
diff options
context:
space:
mode:
authorJason Chang <jasonnc@google.com>2023-05-23 13:06:55 -0700
committerJason Chang <jasonnc@google.com>2023-05-25 22:37:04 +0000
commit17833322d9e0c650310e55f806d5e3545c265c2a (patch)
tree67cd339bede0227bd43bd1e6fb9cc66fcb83d6b4 /subcmds/sync.py
parent04cba4add52b11a27d09d73c2cbfebcd67a1f2cc (diff)
downloadgit-repo-17833322d9e0c650310e55f806d5e3545c265c2a.tar.gz
Add envar to replace shallow clones with partial
An investigation go/git-repo-shallow shows a number of problems when doing a shallow git fetch/clone. This change introduces an environment variable REPO_ALLOW_SHALLOW. When this environment variable is set to 1 during a repo init or repo sync all shallow git fetch commands are replaced with partial fetch commands. Any shallow repository needing update is unshallowed. This behavior continues until a subsequent repo sync command is run with REPO_ALLOW_SHALLOW set to 1. Bug: b/274340522 Change-Id: I1c3188270629359e52449788897d9d4988ebf280 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/374754 Reviewed-by: Josip Sokcevic <sokcevic@google.com> Tested-by: Jason Chang <jasonnc@google.com>
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r--subcmds/sync.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index a44ed5b4..9ae8a4ce 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -79,6 +79,8 @@ _ONE_DAY_S = 24 * 60 * 60
79_REPO_AUTO_GC = "REPO_AUTO_GC" 79_REPO_AUTO_GC = "REPO_AUTO_GC"
80_AUTO_GC = os.environ.get(_REPO_AUTO_GC) == "1" 80_AUTO_GC = os.environ.get(_REPO_AUTO_GC) == "1"
81 81
82_REPO_ALLOW_SHALLOW = os.environ.get("REPO_ALLOW_SHALLOW")
83
82 84
83class _FetchOneResult(NamedTuple): 85class _FetchOneResult(NamedTuple):
84 """_FetchOne return value. 86 """_FetchOne return value.
@@ -638,6 +640,7 @@ later is required to fix a server side protocol bug.
638 ssh_proxy=self.ssh_proxy, 640 ssh_proxy=self.ssh_proxy,
639 clone_filter=project.manifest.CloneFilter, 641 clone_filter=project.manifest.CloneFilter,
640 partial_clone_exclude=project.manifest.PartialCloneExclude, 642 partial_clone_exclude=project.manifest.PartialCloneExclude,
643 clone_filter_for_depth=project.manifest.CloneFilterForDepth,
641 ) 644 )
642 success = sync_result.success 645 success = sync_result.success
643 remote_fetched = sync_result.remote_fetched 646 remote_fetched = sync_result.remote_fetched
@@ -1440,6 +1443,7 @@ later is required to fix a server side protocol bug.
1440 submodules=mp.manifest.HasSubmodules, 1443 submodules=mp.manifest.HasSubmodules,
1441 clone_filter=mp.manifest.CloneFilter, 1444 clone_filter=mp.manifest.CloneFilter,
1442 partial_clone_exclude=mp.manifest.PartialCloneExclude, 1445 partial_clone_exclude=mp.manifest.PartialCloneExclude,
1446 clone_filter_for_depth=mp.manifest.CloneFilterForDepth,
1443 ) 1447 )
1444 finish = time.time() 1448 finish = time.time()
1445 self.event_log.AddSync( 1449 self.event_log.AddSync(
@@ -1589,6 +1593,15 @@ later is required to fix a server side protocol bug.
1589 _PostRepoUpgrade(manifest, quiet=opt.quiet) 1593 _PostRepoUpgrade(manifest, quiet=opt.quiet)
1590 1594
1591 mp = manifest.manifestProject 1595 mp = manifest.manifestProject
1596
1597 if _REPO_ALLOW_SHALLOW is not None:
1598 if _REPO_ALLOW_SHALLOW == "1":
1599 mp.ConfigureCloneFilterForDepth(None)
1600 elif (
1601 _REPO_ALLOW_SHALLOW == "0" and mp.clone_filter_for_depth is None
1602 ):
1603 mp.ConfigureCloneFilterForDepth("blob:none")
1604
1592 if opt.mp_update: 1605 if opt.mp_update:
1593 self._UpdateAllManifestProjects(opt, mp, manifest_name) 1606 self._UpdateAllManifestProjects(opt, mp, manifest_name)
1594 else: 1607 else: