From 17833322d9e0c650310e55f806d5e3545c265c2a Mon Sep 17 00:00:00 2001 From: Jason Chang Date: Tue, 23 May 2023 13:06:55 -0700 Subject: 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 Tested-by: Jason Chang --- subcmds/sync.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'subcmds/sync.py') 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 _REPO_AUTO_GC = "REPO_AUTO_GC" _AUTO_GC = os.environ.get(_REPO_AUTO_GC) == "1" +_REPO_ALLOW_SHALLOW = os.environ.get("REPO_ALLOW_SHALLOW") + class _FetchOneResult(NamedTuple): """_FetchOne return value. @@ -638,6 +640,7 @@ later is required to fix a server side protocol bug. ssh_proxy=self.ssh_proxy, clone_filter=project.manifest.CloneFilter, partial_clone_exclude=project.manifest.PartialCloneExclude, + clone_filter_for_depth=project.manifest.CloneFilterForDepth, ) success = sync_result.success remote_fetched = sync_result.remote_fetched @@ -1440,6 +1443,7 @@ later is required to fix a server side protocol bug. submodules=mp.manifest.HasSubmodules, clone_filter=mp.manifest.CloneFilter, partial_clone_exclude=mp.manifest.PartialCloneExclude, + clone_filter_for_depth=mp.manifest.CloneFilterForDepth, ) finish = time.time() self.event_log.AddSync( @@ -1589,6 +1593,15 @@ later is required to fix a server side protocol bug. _PostRepoUpgrade(manifest, quiet=opt.quiet) mp = manifest.manifestProject + + if _REPO_ALLOW_SHALLOW is not None: + if _REPO_ALLOW_SHALLOW == "1": + mp.ConfigureCloneFilterForDepth(None) + elif ( + _REPO_ALLOW_SHALLOW == "0" and mp.clone_filter_for_depth is None + ): + mp.ConfigureCloneFilterForDepth("blob:none") + if opt.mp_update: self._UpdateAllManifestProjects(opt, mp, manifest_name) else: -- cgit v1.2.3-54-g00ecf