mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-07-16 21:57:00 +00:00
project: fix sync of shallow projects sharing objdir
Repo sync fails when the following conditions are met: * There are several checkouts of the same project in different paths. * The checkouts are using git hashes as revisions (not branches). * There is a clone-depth set on these projects. * sync-c="true" is set in the manifest. * The revision specified in the manifest has moved forward since the first repo init. The sync fails because only the first gitdir gets the "shallow" file, and subsequent dirs can't be synced. Do not optimize away the fetch when the conditions above happen. Simplified the boolean check in Sync_NetworkHalf and _RemoteFetch using has_shallow, renamed loop variable to avoid shadowing. Test: create a manifest matching conditions above, repo init, forward the hash, and repo sync. Test: added tests in test_project.py Bug: 505072873 Originally-by: Elvira Khabirova <elvira.khabirova@volvocars.com> Change-Id: I37c533c382e34fc5ddab489c5593b9e5d3875be2 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/601441 Tested-by: Sainath Varanasi <varanasisai@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com> Commit-Queue: Sainath Varanasi <varanasisai@google.com>
This commit is contained in:
committed by
gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
d32b70275c
commit
3af9e2f146
+25
-4
@@ -1538,6 +1538,7 @@ class Project:
|
||||
|
||||
# See if we can skip the network fetch entirely.
|
||||
remote_fetched = False
|
||||
has_shallow = os.path.exists(os.path.join(self.gitdir, "shallow"))
|
||||
if not (
|
||||
optimized_fetch
|
||||
and IsId(self.revisionExpr)
|
||||
@@ -1545,8 +1546,8 @@ class Project:
|
||||
use_superproject=use_superproject
|
||||
)
|
||||
and (
|
||||
not depth
|
||||
or os.path.exists(os.path.join(self.gitdir, "shallow"))
|
||||
has_shallow
|
||||
or (not depth and not self._SharingProjectHasShallow())
|
||||
)
|
||||
):
|
||||
remote_fetched = True
|
||||
@@ -2643,6 +2644,23 @@ class Project:
|
||||
# There is no such persistent revision. We have to fetch it.
|
||||
return False
|
||||
|
||||
def _SharingProjectHasShallow(self) -> bool:
|
||||
"""Check if another project sharing this objdir has a "shallow" file.
|
||||
|
||||
If any project sharing this objdir has a shallow file in its gitdir,
|
||||
then the shared objdir may be depth-limited, and every other project
|
||||
sharing this objdir needs its own shallow file so that git knows
|
||||
where history is truncated.
|
||||
"""
|
||||
other_projects = self.manifest.GetProjectsWithName(
|
||||
self.name, all_manifests=True
|
||||
)
|
||||
for proj in other_projects:
|
||||
if proj.objdir == self.objdir and proj.gitdir != self.gitdir:
|
||||
if os.path.exists(os.path.join(proj.gitdir, "shallow")):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _FetchArchive(self, tarpath, cwd=None):
|
||||
cmd = ["archive", "-v", "-o", tarpath]
|
||||
cmd.append("--remote=%s" % self.remote.url)
|
||||
@@ -2702,11 +2720,14 @@ class Project:
|
||||
tag_name = self.upstream[len(R_TAGS) :]
|
||||
|
||||
if is_sha1 or tag_name is not None:
|
||||
has_shallow = os.path.exists(
|
||||
os.path.join(self.gitdir, "shallow")
|
||||
)
|
||||
if self._CheckForImmutableRevision(
|
||||
use_superproject=use_superproject
|
||||
) and (
|
||||
not depth
|
||||
or os.path.exists(os.path.join(self.gitdir, "shallow"))
|
||||
has_shallow
|
||||
or (not depth and not self._SharingProjectHasShallow())
|
||||
):
|
||||
if verbose:
|
||||
print(
|
||||
|
||||
Reference in New Issue
Block a user