diff options
| author | Gavin Mak <gavinmak@google.com> | 2026-01-07 20:27:41 +0000 |
|---|---|---|
| committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2026-01-08 11:33:40 -0800 |
| commit | e71a8c6dd85026c8861e675ed7ff468fc611df44 (patch) | |
| tree | 0bc1ce1dddc3bd2777433aed3db28bcd9d7035e8 | |
| parent | c687b5df9e049f928c295e771fdebf593cffaed7 (diff) | |
| download | git-repo-e71a8c6dd85026c8861e675ed7ff468fc611df44.tar.gz | |
project: disable auto-gc for depth=1 in git configv2.61
During sync, `git checkout` can trigger fetch for missing objects in
partial clones. This internal fetch can trigger `git maintenance` or
`git gc` and cause delays during the local checkout phase. Set
maintenance.auto to false and gc.auto to 0 in during `_InitRemote` if
`depth=1` to ensure that implicit fetches spawned by git skip GC.
Bug: 379111283
Change-Id: I6b22a4867f29b6e9598746cb752820a84dc2aeb6
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/540681
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
| -rw-r--r-- | git_config.py | 6 | ||||
| -rw-r--r-- | project.py | 9 | ||||
| -rw-r--r-- | tests/test_git_config.py | 24 |
3 files changed, 39 insertions, 0 deletions
diff --git a/git_config.py b/git_config.py index 14c4c11a..5559657a 100644 --- a/git_config.py +++ b/git_config.py | |||
| @@ -222,6 +222,12 @@ class GitConfig: | |||
| 222 | value = "true" if value else "false" | 222 | value = "true" if value else "false" |
| 223 | self.SetString(name, value) | 223 | self.SetString(name, value) |
| 224 | 224 | ||
| 225 | def SetInt(self, name: str, value: int) -> None: | ||
| 226 | """Set an integer value for a key.""" | ||
| 227 | if value is not None: | ||
| 228 | value = str(value) | ||
| 229 | self.SetString(name, value) | ||
| 230 | |||
| 225 | def GetString(self, name: str, all_keys: bool = False) -> Union[str, None]: | 231 | def GetString(self, name: str, all_keys: bool = False) -> Union[str, None]: |
| 226 | """Get the first value for a key, or None if it is not defined. | 232 | """Get the first value for a key, or None if it is not defined. |
| 227 | 233 | ||
| @@ -3316,6 +3316,15 @@ class Project: | |||
| 3316 | remote.ResetFetch(mirror=True) | 3316 | remote.ResetFetch(mirror=True) |
| 3317 | remote.Save() | 3317 | remote.Save() |
| 3318 | 3318 | ||
| 3319 | # Disable auto-gc for depth=1 to prevent hangs during lazy fetches | ||
| 3320 | # inside git checkout for partial clones. | ||
| 3321 | effective_depth = ( | ||
| 3322 | self.clone_depth or self.manifest.manifestProject.depth | ||
| 3323 | ) | ||
| 3324 | if effective_depth == 1: | ||
| 3325 | self.config.SetBoolean("maintenance.auto", False) | ||
| 3326 | self.config.SetInt("gc.auto", 0) | ||
| 3327 | |||
| 3319 | def _InitMRef(self): | 3328 | def _InitMRef(self): |
| 3320 | """Initialize the pseudo m/<manifest branch> ref.""" | 3329 | """Initialize the pseudo m/<manifest branch> ref.""" |
| 3321 | if self.manifest.branch: | 3330 | if self.manifest.branch: |
diff --git a/tests/test_git_config.py b/tests/test_git_config.py index cf6e7793..e1604bd7 100644 --- a/tests/test_git_config.py +++ b/tests/test_git_config.py | |||
| @@ -166,6 +166,30 @@ class GitConfigReadWriteTests(unittest.TestCase): | |||
| 166 | config = self.get_config() | 166 | config = self.get_config() |
| 167 | self.assertIsNone(config.GetBoolean("foo.bar")) | 167 | self.assertIsNone(config.GetBoolean("foo.bar")) |
| 168 | 168 | ||
| 169 | def test_SetInt(self): | ||
| 170 | """Test SetInt behavior.""" | ||
| 171 | # Set a value. | ||
| 172 | self.assertIsNone(self.config.GetInt("foo.bar")) | ||
| 173 | self.config.SetInt("foo.bar", 10) | ||
| 174 | self.assertEqual(10, self.config.GetInt("foo.bar")) | ||
| 175 | |||
| 176 | # Make sure the value was actually written out. | ||
| 177 | config = self.get_config() | ||
| 178 | self.assertEqual(10, config.GetInt("foo.bar")) | ||
| 179 | self.assertEqual("10", config.GetString("foo.bar")) | ||
| 180 | |||
| 181 | # Update the value. | ||
| 182 | self.config.SetInt("foo.bar", 20) | ||
| 183 | self.assertEqual(20, self.config.GetInt("foo.bar")) | ||
| 184 | config = self.get_config() | ||
| 185 | self.assertEqual(20, config.GetInt("foo.bar")) | ||
| 186 | |||
| 187 | # Delete the value. | ||
| 188 | self.config.SetInt("foo.bar", None) | ||
| 189 | self.assertIsNone(self.config.GetInt("foo.bar")) | ||
| 190 | config = self.get_config() | ||
| 191 | self.assertIsNone(config.GetInt("foo.bar")) | ||
| 192 | |||
| 169 | def test_GetSyncAnalysisStateData(self): | 193 | def test_GetSyncAnalysisStateData(self): |
| 170 | """Test config entries with a sync state analysis data.""" | 194 | """Test config entries with a sync state analysis data.""" |
| 171 | superproject_logging_data = {} | 195 | superproject_logging_data = {} |
