mirror of
https://github.com/Dev-Wiki/git-repo.git
synced 2025-12-13 16:14:02 +08:00
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>
This commit is contained in:
30
project.py
30
project.py
@@ -1186,6 +1186,7 @@ class Project(object):
|
||||
ssh_proxy=None,
|
||||
clone_filter=None,
|
||||
partial_clone_exclude=set(),
|
||||
clone_filter_for_depth=None,
|
||||
):
|
||||
"""Perform only the network IO portion of the sync process.
|
||||
Local working directory/branch state is not affected.
|
||||
@@ -1295,6 +1296,10 @@ class Project(object):
|
||||
else:
|
||||
depth = self.manifest.manifestProject.depth
|
||||
|
||||
if depth and clone_filter_for_depth:
|
||||
depth = None
|
||||
clone_filter = clone_filter_for_depth
|
||||
|
||||
# See if we can skip the network fetch entirely.
|
||||
remote_fetched = False
|
||||
if not (
|
||||
@@ -3884,6 +3889,11 @@ class ManifestProject(MetaProject):
|
||||
"""Partial clone exclude string"""
|
||||
return self.config.GetString("repo.partialcloneexclude")
|
||||
|
||||
@property
|
||||
def clone_filter_for_depth(self):
|
||||
"""Replace shallow clone with partial clone."""
|
||||
return self.config.GetString("repo.clonefilterfordepth")
|
||||
|
||||
@property
|
||||
def manifest_platform(self):
|
||||
"""The --platform argument from `repo init`."""
|
||||
@@ -3961,6 +3971,7 @@ class ManifestProject(MetaProject):
|
||||
manifest_name=spec.manifestName,
|
||||
this_manifest_only=True,
|
||||
outer_manifest=False,
|
||||
clone_filter_for_depth=mp.clone_filter_for_depth,
|
||||
)
|
||||
|
||||
def Sync(
|
||||
@@ -3991,6 +4002,7 @@ class ManifestProject(MetaProject):
|
||||
tags="",
|
||||
this_manifest_only=False,
|
||||
outer_manifest=True,
|
||||
clone_filter_for_depth=None,
|
||||
):
|
||||
"""Sync the manifest and all submanifests.
|
||||
|
||||
@@ -4035,6 +4047,8 @@ class ManifestProject(MetaProject):
|
||||
current sub manifest.
|
||||
outer_manifest: a boolean, whether to start at the outermost
|
||||
manifest.
|
||||
clone_filter_for_depth: a string, when specified replaces shallow
|
||||
clones with partial.
|
||||
|
||||
Returns:
|
||||
a boolean, whether the sync was successful.
|
||||
@@ -4297,6 +4311,9 @@ class ManifestProject(MetaProject):
|
||||
file=sys.stderr,
|
||||
)
|
||||
|
||||
if clone_filter_for_depth is not None:
|
||||
self.ConfigureCloneFilterForDepth(clone_filter_for_depth)
|
||||
|
||||
if use_superproject is not None:
|
||||
self.config.SetBoolean("repo.superproject", use_superproject)
|
||||
|
||||
@@ -4311,6 +4328,7 @@ class ManifestProject(MetaProject):
|
||||
submodules=submodules,
|
||||
clone_filter=clone_filter,
|
||||
partial_clone_exclude=self.manifest.PartialCloneExclude,
|
||||
clone_filter_for_depth=self.manifest.CloneFilterForDepth,
|
||||
).success
|
||||
if not success:
|
||||
r = self.GetRemote()
|
||||
@@ -4415,6 +4433,18 @@ class ManifestProject(MetaProject):
|
||||
|
||||
return True
|
||||
|
||||
def ConfigureCloneFilterForDepth(self, clone_filter_for_depth):
|
||||
"""Configure clone filter to replace shallow clones.
|
||||
|
||||
Args:
|
||||
clone_filter_for_depth: a string or None, e.g. 'blob:none' will
|
||||
disable shallow clones and replace with partial clone. None will
|
||||
enable shallow clones.
|
||||
"""
|
||||
self.config.SetString(
|
||||
"repo.clonefilterfordepth", clone_filter_for_depth
|
||||
)
|
||||
|
||||
def _ConfigureDepth(self, depth):
|
||||
"""Configure the depth we'll sync down.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user