summaryrefslogtreecommitdiffstats
path: root/subcmds/sync.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r--subcmds/sync.py31
1 files changed, 23 insertions, 8 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 85ead6c31..bfbe1937d 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -1244,14 +1244,15 @@ later is required to fix a server side protocol bug.
1244 1244
1245 return False 1245 return False
1246 1246
1247 def _SetPreciousObjectsState(self, project: Project, opt): 1247 @classmethod
1248 def _SetPreciousObjectsState(cls, project: Project, opt):
1248 """Correct the preciousObjects state for the project. 1249 """Correct the preciousObjects state for the project.
1249 1250
1250 Args: 1251 Args:
1251 project: the project to examine, and possibly correct. 1252 project: the project to examine, and possibly correct.
1252 opt: options given to sync. 1253 opt: options given to sync.
1253 """ 1254 """
1254 expected = self._GetPreciousObjectsState(project, opt) 1255 expected = cls._GetPreciousObjectsState(project, opt)
1255 actual = ( 1256 actual = (
1256 project.config.GetBoolean("extensions.preciousObjects") or False 1257 project.config.GetBoolean("extensions.preciousObjects") or False
1257 ) 1258 )
@@ -1285,7 +1286,22 @@ later is required to fix a server side protocol bug.
1285 project.config.SetString("extensions.preciousObjects", None) 1286 project.config.SetString("extensions.preciousObjects", None)
1286 project.config.SetString("gc.pruneExpire", None) 1287 project.config.SetString("gc.pruneExpire", None)
1287 1288
1288 def _GCProjects(self, projects, opt, err_event): 1289 @staticmethod
1290 def _RunOneGC(project: Project, config: Optional[dict] = None) -> None:
1291 """Run auto GC on a single project."""
1292 local_config = {}
1293 if config:
1294 local_config.update(config)
1295 local_config["gc.autoDetach"] = "false"
1296 project.bare_git.gc("--auto", config=local_config)
1297
1298 @classmethod
1299 def _GCProjects(
1300 cls,
1301 projects: List[Project],
1302 opt: optparse.Values,
1303 err_event: _threading.Event,
1304 ) -> None:
1289 """Perform garbage collection. 1305 """Perform garbage collection.
1290 1306
1291 If We are skipping garbage collection (opt.auto_gc not set), we still 1307 If We are skipping garbage collection (opt.auto_gc not set), we still
@@ -1295,7 +1311,7 @@ later is required to fix a server side protocol bug.
1295 if not opt.auto_gc: 1311 if not opt.auto_gc:
1296 # Just repair preciousObjects state, and return. 1312 # Just repair preciousObjects state, and return.
1297 for project in projects: 1313 for project in projects:
1298 self._SetPreciousObjectsState(project, opt) 1314 cls._SetPreciousObjectsState(project, opt)
1299 return 1315 return
1300 1316
1301 pm = Progress( 1317 pm = Progress(
@@ -1305,9 +1321,8 @@ later is required to fix a server side protocol bug.
1305 1321
1306 tidy_dirs = {} 1322 tidy_dirs = {}
1307 for project in projects: 1323 for project in projects:
1308 self._SetPreciousObjectsState(project, opt) 1324 cls._SetPreciousObjectsState(project, opt)
1309 1325
1310 project.config.SetString("gc.autoDetach", "false")
1311 # Only call git gc once per objdir, but call pack-refs for the 1326 # Only call git gc once per objdir, but call pack-refs for the
1312 # remainder. 1327 # remainder.
1313 if project.objdir not in tidy_dirs: 1328 if project.objdir not in tidy_dirs:
@@ -1328,7 +1343,7 @@ later is required to fix a server side protocol bug.
1328 pm.update(msg=bare_git._project.name) 1343 pm.update(msg=bare_git._project.name)
1329 1344
1330 if run_gc: 1345 if run_gc:
1331 bare_git.gc("--auto") 1346 cls._RunOneGC(bare_git._project)
1332 else: 1347 else:
1333 bare_git.pack_refs() 1348 bare_git.pack_refs()
1334 pm.end() 1349 pm.end()
@@ -1345,7 +1360,7 @@ later is required to fix a server side protocol bug.
1345 try: 1360 try:
1346 try: 1361 try:
1347 if run_gc: 1362 if run_gc:
1348 bare_git.gc("--auto", config=config) 1363 cls._RunOneGC(bare_git._project, config=config)
1349 else: 1364 else:
1350 bare_git.pack_refs(config=config) 1365 bare_git.pack_refs(config=config)
1351 except GitError: 1366 except GitError: