diff options
author | Josip Sokcevic <sokcevic@chromium.org> | 2025-01-14 19:16:28 +0000 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2025-01-14 12:33:45 -0800 |
commit | 41a27eb854b011f1506cbf984645df5a0f67ad00 (patch) | |
tree | 68cc4df3764bf171a1689f471f1b7e7d9584cfe4 | |
parent | d93fe60e893435d9eb3a08dd59d92def40798e95 (diff) | |
download | git-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>
-rw-r--r-- | subcmds/gc.py | 21 |
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 | ||
15 | import os | 15 | import os |
16 | from typing import Set | 16 | from typing import List, Set |
17 | 17 | ||
18 | from command import Command | 18 | from command import Command |
19 | import platform_utils | 19 | import platform_utils |
20 | from progress import Progress | 20 | from progress import Progress |
21 | from project import Project | ||
21 | 22 | ||
22 | 23 | ||
23 | class Gc(Command): | 24 | class 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) | ||