manifest: Add sync-strategy attribute to project elements

The only supported sync-strategy is "stateless". The intent is to keep
the local workspace as small as possible by not keeping history during
syncs. This prevents disk space waste for projects with large binaries
where we only care about the current version.

A follow up change will implement the logic.

Bug: 498730431
Change-Id: I84a436a9ca2492893163c6cfda6c28dc62a568f0
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/568462
Tested-by: Gavin Mak <gavinmak@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
This commit is contained in:
Gavin Mak
2026-04-01 23:03:03 +00:00
committed by LUCI
parent e8338b54bd
commit 00991bfb42
5 changed files with 101 additions and 21 deletions
+29 -12
View File
@@ -73,18 +73,19 @@ following DTD:
project*, project*,
copyfile*, copyfile*,
linkfile*)> linkfile*)>
<!ATTLIST project name CDATA #REQUIRED> <!ATTLIST project name CDATA #REQUIRED>
<!ATTLIST project path CDATA #IMPLIED> <!ATTLIST project path CDATA #IMPLIED>
<!ATTLIST project remote IDREF #IMPLIED> <!ATTLIST project remote IDREF #IMPLIED>
<!ATTLIST project revision CDATA #IMPLIED> <!ATTLIST project revision CDATA #IMPLIED>
<!ATTLIST project dest-branch CDATA #IMPLIED> <!ATTLIST project dest-branch CDATA #IMPLIED>
<!ATTLIST project groups CDATA #IMPLIED> <!ATTLIST project groups CDATA #IMPLIED>
<!ATTLIST project sync-c CDATA #IMPLIED> <!ATTLIST project sync-c CDATA #IMPLIED>
<!ATTLIST project sync-s CDATA #IMPLIED> <!ATTLIST project sync-s CDATA #IMPLIED>
<!ATTLIST project sync-tags CDATA #IMPLIED> <!ATTLIST project sync-tags CDATA #IMPLIED>
<!ATTLIST project upstream CDATA #IMPLIED> <!ATTLIST project upstream CDATA #IMPLIED>
<!ATTLIST project clone-depth CDATA #IMPLIED> <!ATTLIST project clone-depth CDATA #IMPLIED>
<!ATTLIST project force-path CDATA #IMPLIED> <!ATTLIST project force-path CDATA #IMPLIED>
<!ATTLIST project sync-strategy CDATA #IMPLIED>
<!ELEMENT annotation EMPTY> <!ELEMENT annotation EMPTY>
<!ATTLIST annotation name CDATA #REQUIRED> <!ATTLIST annotation name CDATA #REQUIRED>
@@ -389,6 +390,22 @@ rather than the `name` attribute. This attribute only applies to the
local mirrors syncing, it will be ignored when syncing the projects in a local mirrors syncing, it will be ignored when syncing the projects in a
client working directory. client working directory.
Attribute `sync-strategy`: Set the sync strategy used when fetching this
project. Currently the only supported value is `stateless`. When set to
`stateless`, repo will run a reflog expiration and aggressive garbage collection
at the end of the sync process. This is useful for projects that contain
large binary files and use `clone-depth="1"`, where garbage can accumulate
as binaries are added, deleted, or modified across successive syncs.
During a stateless sync, repo checks the following before cleaning up:
1. The project does not share an object directory with other projects.
2. The working tree is clean (no uncommitted changes, no untracked files).
3. There are no unpushed local commits.
4. There is no Git stash.
If any of these conditions are not met, repo falls back to a standard
sync without garbage collection.
### Element extend-project ### Element extend-project
Modify the attributes of the named project. Modify the attributes of the named project.
+41 -9
View File
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man. .\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH REPO "1" "March 2026" "repo manifest" "Repo Manual" .TH REPO "1" "April 2026" "repo manifest" "Repo Manual"
.SH NAME .SH NAME
repo \- repo manifest - manual page for repo manifest repo \- repo manifest - manual page for repo manifest
.SH SYNOPSIS .SH SYNOPSIS
@@ -165,15 +165,32 @@ IDREF #IMPLIED>
.TP .TP
<!ATTLIST project revision <!ATTLIST project revision
CDATA #IMPLIED> CDATA #IMPLIED>
.TP
<!ATTLIST project dest\-branch
CDATA #IMPLIED>
.TP
<!ATTLIST project groups
CDATA #IMPLIED>
.TP
<!ATTLIST project sync\-c
CDATA #IMPLIED>
.TP
<!ATTLIST project sync\-s
CDATA #IMPLIED>
.TP
<!ATTLIST project sync\-tags
CDATA #IMPLIED>
.TP
<!ATTLIST project upstream
CDATA #IMPLIED>
.TP
<!ATTLIST project clone\-depth
CDATA #IMPLIED>
.TP
<!ATTLIST project force\-path
CDATA #IMPLIED>
.IP .IP
<!ATTLIST project dest\-branch CDATA #IMPLIED> <!ATTLIST project sync\-strategy CDATA #IMPLIED>
<!ATTLIST project groups CDATA #IMPLIED>
<!ATTLIST project sync\-c CDATA #IMPLIED>
<!ATTLIST project sync\-s CDATA #IMPLIED>
<!ATTLIST project sync\-tags CDATA #IMPLIED>
<!ATTLIST project upstream CDATA #IMPLIED>
<!ATTLIST project clone\-depth CDATA #IMPLIED>
<!ATTLIST project force\-path CDATA #IMPLIED>
.IP .IP
<!ELEMENT annotation EMPTY> <!ELEMENT annotation EMPTY>
<!ATTLIST annotation name CDATA #REQUIRED> <!ATTLIST annotation name CDATA #REQUIRED>
@@ -469,6 +486,21 @@ mirror repository according to its `path` attribute (if supplied) rather than
the `name` attribute. This attribute only applies to the local mirrors syncing, the `name` attribute. This attribute only applies to the local mirrors syncing,
it will be ignored when syncing the projects in a client working directory. it will be ignored when syncing the projects in a client working directory.
.PP .PP
Attribute `sync\-strategy`: Set the sync strategy used when fetching this
project. Currently the only supported value is `stateless`. When set to
`stateless`, repo will run a reflog expiration and aggressive garbage collection
at the end of the sync process. This is useful for projects that contain large
binary files and use `clone\-depth="1"`, where garbage can accumulate as binaries
are added, deleted, or modified across successive syncs.
.PP
During a stateless sync, repo checks the following before cleaning up: 1. The
project does not share an object directory with other projects. 2. The working
tree is clean (no uncommitted changes, no untracked files). 3. There are no
unpushed local commits. 4. There is no Git stash.
.PP
If any of these conditions are not met, repo falls back to a standard sync
without garbage collection.
.PP
Element extend\-project Element extend\-project
.PP .PP
Modify the attributes of the named project. Modify the attributes of the named project.
+6
View File
@@ -759,6 +759,9 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
if p.clone_depth: if p.clone_depth:
e.setAttribute("clone-depth", str(p.clone_depth)) e.setAttribute("clone-depth", str(p.clone_depth))
if p.sync_strategy:
e.setAttribute("sync-strategy", str(p.sync_strategy))
self._output_manifest_project_extras(p, e) self._output_manifest_project_extras(p, e)
if p.subprojects: if p.subprojects:
@@ -1938,6 +1941,8 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
% (self.manifestFile, clone_depth) % (self.manifestFile, clone_depth)
) )
sync_strategy = node.getAttribute("sync-strategy") or None
dest_branch = ( dest_branch = (
node.getAttribute("dest-branch") or self._default.destBranchExpr node.getAttribute("dest-branch") or self._default.destBranchExpr
) )
@@ -1984,6 +1989,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
sync_s=sync_s, sync_s=sync_s,
sync_tags=sync_tags, sync_tags=sync_tags,
clone_depth=clone_depth, clone_depth=clone_depth,
sync_strategy=sync_strategy,
upstream=upstream, upstream=upstream,
parent=parent, parent=parent,
dest_branch=dest_branch, dest_branch=dest_branch,
+2
View File
@@ -558,6 +558,7 @@ class Project:
sync_s=False, sync_s=False,
sync_tags=True, sync_tags=True,
clone_depth=None, clone_depth=None,
sync_strategy=None,
upstream=None, upstream=None,
parent=None, parent=None,
use_git_worktrees=False, use_git_worktrees=False,
@@ -610,6 +611,7 @@ class Project:
self.sync_s = sync_s self.sync_s = sync_s
self.sync_tags = sync_tags self.sync_tags = sync_tags
self.clone_depth = clone_depth self.clone_depth = clone_depth
self.sync_strategy = sync_strategy
self.upstream = upstream self.upstream = upstream
self.parent = parent self.parent = parent
# NB: Do not use this setting in __init__ to change behavior so that the # NB: Do not use this setting in __init__ to change behavior so that the
+23
View File
@@ -732,6 +732,29 @@ class TestProjectElement:
"</manifest>" "</manifest>"
) )
def test_sync_strategy(self, repo_client: RepoClient) -> None:
"""Check setting of project's sync_strategy."""
manifest = repo_client.get_xml_manifest(
"""
<manifest>
<remote name="default-remote" fetch="http://localhost" />
<default remote="default-remote" revision="refs/heads/main" />
<project name="test-name" sync-strategy="stateless"/>
</manifest>
"""
)
assert len(manifest.projects) == 1
project = manifest.projects[0]
assert project.sync_strategy == "stateless"
assert (
sort_attributes(manifest.ToXml().toxml())
== '<?xml version="1.0" ?><manifest>'
'<remote fetch="http://localhost" name="default-remote"/>'
'<default remote="default-remote" revision="refs/heads/main"/>'
'<project name="test-name" sync-strategy="stateless"/>'
"</manifest>"
)
def test_trailing_slash(self, repo_client: RepoClient) -> None: def test_trailing_slash(self, repo_client: RepoClient) -> None:
"""Check handling of trailing slashes in attributes.""" """Check handling of trailing slashes in attributes."""