Add an optional no-auto-gc flag for the git fetch.

Bug: b/458222057
Recipe-Nontrivial-Roll: chromiumos
Change-Id: If00eb0639871b060bc5efc507e79620382c0dfe5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7153382
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Marc Jin <jmarc@google.com>
This commit is contained in:
Marc Jin
2025-11-13 20:36:03 -08:00
committed by LUCI CQ
parent 11b0e6b805
commit ccd4d2f345
5 changed files with 255 additions and 13 deletions

View File

@@ -447,7 +447,7 @@ Returns:
Returns a git command step.
&mdash; **def [bundle\_create](/recipes/recipe_modules/git/api.py#390)(self, bundle_path, rev_list_args=None, \*\*kwargs):**
&mdash; **def [bundle\_create](/recipes/recipe_modules/git/api.py#395)(self, bundle_path, rev_list_args=None, \*\*kwargs):**
Runs 'git bundle create' on a Git repository.
@@ -461,7 +461,7 @@ Args:
Outputs the contents of a file at a given revision.
&mdash; **def [checkout](/recipes/recipe_modules/git/api.py#106)(self, url, ref=None, dir_path=None, recursive=False, submodules=True, submodule_update_force=False, keep_paths=None, step_suffix=None, curl_trace_file=None, raise_on_failure=True, set_got_revision=False, remote_name=None, display_fetch_size=None, file_name=None, submodule_update_recursive=True, use_git_cache=False, progress=True, tags=False, depth=None):**
&mdash; **def [checkout](/recipes/recipe_modules/git/api.py#106)(self, url, ref=None, dir_path=None, recursive=False, submodules=True, submodule_update_force=False, keep_paths=None, step_suffix=None, curl_trace_file=None, raise_on_failure=True, set_got_revision=False, remote_name=None, display_fetch_size=None, file_name=None, submodule_update_recursive=True, use_git_cache=False, progress=True, tags=False, depth=None, no_auto_gc=False):**
Performs a full git checkout and returns sha1 of checked out revision.
@@ -498,11 +498,12 @@ Args:
* tags (bool): Also fetch tags.
* depth (int): if > 0, limit fetching to the given number of commits from
the tips of the remote tree.
* no_auto_gc: whether to turn off the automatic garbage collection.
Returns: If the checkout was successful, this returns the commit hash of
the checked-out-repo. Otherwise this returns None.
&mdash; **def [config\_get](/recipes/recipe_modules/git/api.py#359)(self, prop_name, \*\*kwargs):**
&mdash; **def [config\_get](/recipes/recipe_modules/git/api.py#364)(self, prop_name, \*\*kwargs):**
Returns git config output.
@@ -529,7 +530,7 @@ Returns:
Fetches all tags from the remote.
&mdash; **def [get\_remote\_url](/recipes/recipe_modules/git/api.py#378)(self, remote_name=None, \*\*kwargs):**
&mdash; **def [get\_remote\_url](/recipes/recipe_modules/git/api.py#383)(self, remote_name=None, \*\*kwargs):**
Returns the remote Git repository URL, or None.
@@ -539,11 +540,11 @@ Args:
Returns: (str) The URL of the remote Git repository, or None.
&mdash; **def [get\_timestamp](/recipes/recipe_modules/git/api.py#330)(self, commit='HEAD', test_data=None, \*\*kwargs):**
&mdash; **def [get\_timestamp](/recipes/recipe_modules/git/api.py#335)(self, commit='HEAD', test_data=None, \*\*kwargs):**
Find and return the timestamp of the given commit.
&mdash; **def [ls\_remote](/recipes/recipe_modules/git/api.py#471)(self, url, ref, name=None, \*\*kwargs):**
&mdash; **def [ls\_remote](/recipes/recipe_modules/git/api.py#476)(self, url, ref, name=None, \*\*kwargs):**
Request the head revision for a given ref using ls-remote. Raise a
StepFailure if the ref does not exist, or more than one ref was found.
@@ -555,7 +556,7 @@ Args:
Returns: A git revision.
&mdash; **def [new\_branch](/recipes/recipe_modules/git/api.py#403)(self, branch, name=None, upstream=None, upstream_current=False, \*\*kwargs):**
&mdash; **def [new\_branch](/recipes/recipe_modules/git/api.py#408)(self, branch, name=None, upstream=None, upstream_current=False, \*\*kwargs):**
Runs git new-branch on a Git repository, to be used before git cl
upload.
@@ -567,7 +568,7 @@ Args:
* upstream_current (bool): whether to use '--upstream_current'.
* kwargs: Forwarded to '__call__'.
&mdash; **def [number](/recipes/recipe_modules/git/api.py#434)(self, commitrefs=None, test_values=None):**
&mdash; **def [number](/recipes/recipe_modules/git/api.py#439)(self, commitrefs=None, test_values=None):**
Computes the generation number of some commits.
@@ -584,7 +585,7 @@ A list of strings containing the generation numbers of the commits.
If non-empty commitrefs was provided, the order of the returned
numbers will correspond to the order of the provided commitrefs.
&mdash; **def [rebase](/recipes/recipe_modules/git/api.py#339)(self, name_prefix, branch, dir_path, remote_name=None, \*\*kwargs):**
&mdash; **def [rebase](/recipes/recipe_modules/git/api.py#344)(self, name_prefix, branch, dir_path, remote_name=None, \*\*kwargs):**
Runs rebase HEAD onto branch

View File

@@ -122,7 +122,8 @@ class GitApi(recipe_api.RecipeApi):
use_git_cache=False,
progress=True,
tags=False,
depth=None):
depth=None,
no_auto_gc=False):
"""Performs a full git checkout and returns sha1 of checked out revision.
Args:
@@ -158,6 +159,7 @@ class GitApi(recipe_api.RecipeApi):
* tags (bool): Also fetch tags.
* depth (int): if > 0, limit fetching to the given number of commits from
the tips of the remote tree.
* no_auto_gc: whether to turn off the automatic garbage collection.
Returns: If the checkout was successful, this returns the commit hash of
the checked-out-repo. Otherwise this returns None.
@@ -263,6 +265,9 @@ class GitApi(recipe_api.RecipeApi):
assert isinstance(depth, int)
fetch_args += ['--depth', depth]
if no_auto_gc:
fetch_args.append('--no-auto-gc')
fetch_step_name = 'git fetch%s' % step_suffix
if display_fetch_size:
count_objects_before_fetch = self.count_objects(

View File

@@ -0,0 +1,232 @@
[
{
"cmd": [
"python3",
"-u",
"RECIPE_MODULE[depot_tools::git]/resources/git_setup.py",
"--path",
"[START_DIR]/src",
"--url",
"https://chromium.googlesource.com/chromium/src.git"
],
"name": "git setup"
},
{
"cmd": [
"git",
"fetch",
"origin",
"main",
"--recurse-submodules",
"--progress",
"--no-auto-gc"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git fetch"
},
{
"cmd": [
"git",
"checkout",
"-f",
"FETCH_HEAD"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "read revision",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
"clean",
"-f",
"-d",
"-x"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git clean"
},
{
"cmd": [
"git",
"submodule",
"sync"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "submodule sync"
},
{
"cmd": [
"git",
"submodule",
"update",
"--init",
"--recursive"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "submodule update"
},
{
"cmd": [
"git",
"-c",
"foo=bar",
"count-objects",
"-v"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "count-objects"
},
{
"cmd": [
"git",
"config",
"--get",
"remote.origin.url"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git config remote.origin.url",
"~followup_annotations": [
"@@@STEP_TEXT@foo@@@"
]
},
{
"cmd": [
"git",
"show",
"HEAD",
"--format=%at",
"-s"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git show"
},
{
"cmd": [
"git",
"fetch",
"origin",
"--tags"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git fetch tags"
},
{
"cmd": [
"git",
"status"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git status"
},
{
"cmd": [
"git",
"status"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git status can_fail_build"
},
{
"cmd": [
"git",
"status"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git status cannot_fail_build"
},
{
"cmd": [
"git",
"new-branch",
"refactor"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch refactor"
},
{
"cmd": [
"git",
"new-branch",
"feature",
"--upstream",
"refactor"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch feature"
},
{
"cmd": [
"git",
"new-branch",
"track_current",
"--upstream_current"
],
"cwd": "[START_DIR]/src",
"env": {
"PATH": "RECIPE_REPO[depot_tools]:<PATH>"
},
"infra_step": true,
"name": "git new-branch track_current"
},
{
"cmd": [
"git",
"rebase",
"origin/main"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "my repo rebase"
},
{
"cmd": [
"git",
"bundle",
"create",
"[START_DIR]/all.bundle",
"--all"
],
"cwd": "[START_DIR]/src",
"infra_step": true,
"name": "git bundle"
},
{
"name": "$result"
}
]

View File

@@ -194,10 +194,10 @@
" File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/property_invoker.py\", in _invoke_with_properties",
" return callable_obj(*props, **additional_args)",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
" File \"RECIPE_REPO[depot_tools]/recipes/recipe_modules/git/examples/full.py\", line 81, in RunSteps",
" File \"RECIPE_REPO[depot_tools]/recipes/recipe_modules/git/examples/full.py\", line 82, in RunSteps",
" api.git.new_branch('failed_new_branch', upstream='will_fail', upstream_current=True) #pylint: disable = line-too-long",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
" File \"RECIPE_REPO[depot_tools]/recipes/recipe_modules/git/api.py\", line 420, in new_branch",
" File \"RECIPE_REPO[depot_tools]/recipes/recipe_modules/git/api.py\", line 425, in new_branch",
" raise ValueError('Can not define both upstream and upstream_current')",
"ValueError: Can not define both upstream and upstream_current"
]

View File

@@ -45,7 +45,8 @@ def RunSteps(api):
submodule_update_recursive=submodule_update_recursive,
use_git_cache=api.properties.get('use_git_cache'),
tags=api.properties.get('tags'),
depth=api.properties.get('depth'))
depth=api.properties.get('depth'),
no_auto_gc=api.properties.get('no_auto_gc'))
assert retVal == "deadbeef", (
"expected retVal to be %r but was %r" % ("deadbeef", retVal))
@@ -174,3 +175,6 @@ def GenTests(api):
api.expect_exception('ValueError'))
yield (api.test('git-checkout-with-depth') + api.properties(depth=1))
yield (api.test('git-fetch-without-auto-gc') +
api.properties(no_auto_gc=True))