summaryrefslogtreecommitdiffstats
path: root/subcmds/gc.py
diff options
context:
space:
mode:
authorJosip Sokcevic <sokcevic@chromium.org>2025-01-14 19:16:28 +0000
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2025-01-14 12:33:45 -0800
commit41a27eb854b011f1506cbf984645df5a0f67ad00 (patch)
tree68cc4df3764bf171a1689f471f1b7e7d9584cfe4 /subcmds/gc.py
parentd93fe60e893435d9eb3a08dd59d92def40798e95 (diff)
downloadgit-repo-41a27eb854b011f1506cbf984645df5a0f67ad00.tar.gz
gc: extract deletion from Execute method
Change-Id: Icef4f28fbdb9658892611def7589f5eba43c952c Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/447721 Reviewed-by: Scott Lee <ddoman@google.com> Commit-Queue: Josip Sokcevic <sokcevic@chromium.org> Tested-by: Josip Sokcevic <sokcevic@chromium.org>
Diffstat (limited to 'subcmds/gc.py')
-rw-r--r--subcmds/gc.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/subcmds/gc.py b/subcmds/gc.py
index f12f56f1..14d9675c 100644
--- a/subcmds/gc.py
+++ b/subcmds/gc.py
@@ -13,11 +13,12 @@
13# limitations under the License. 13# limitations under the License.
14 14
15import os 15import os
16from typing import Set 16from typing import List, Set
17 17
18from command import Command 18from command import Command
19import platform_utils 19import platform_utils
20from progress import Progress 20from progress import Progress
21from project import Project
21 22
22 23
23class Gc(Command): 24class Gc(Command):
@@ -64,10 +65,7 @@ class Gc(Command):
64 65
65 return to_delete 66 return to_delete
66 67
67 def Execute(self, opt, args): 68 def delete_unused_projects(self, projects: List[Project], opt):
68 projects = self.GetProjects(
69 args, all_manifests=not opt.this_manifest_only
70 )
71 print(f"Scanning filesystem under {self.repodir}...") 69 print(f"Scanning filesystem under {self.repodir}...")
72 70
73 project_paths = set() 71 project_paths = set()
@@ -90,11 +88,11 @@ class Gc(Command):
90 88
91 if not to_delete: 89 if not to_delete:
92 print("Nothing to clean up.") 90 print("Nothing to clean up.")
93 return 91 return 0
94 92
95 print("Identified the following projects are no longer used:") 93 print("Identified the following projects are no longer used:")
96 print("\n".join(to_delete)) 94 print("\n".join(to_delete))
97 print("\n") 95 print("")
98 if not opt.yes: 96 if not opt.yes:
99 print( 97 print(
100 "If you proceed, any local commits in those projects will be " 98 "If you proceed, any local commits in those projects will be "
@@ -125,3 +123,12 @@ class Gc(Command):
125 platform_utils.rmtree(tmp_path) 123 platform_utils.rmtree(tmp_path)
126 pm.update(msg=path) 124 pm.update(msg=path)
127 pm.end() 125 pm.end()
126
127 return 0
128
129 def Execute(self, opt, args):
130 projects: List[Project] = self.GetProjects(
131 args, all_manifests=not opt.this_manifest_only
132 )
133
134 return self.delete_unused_projects(projects, opt)