| 151 | } |
| 152 | |
| 153 | int cmd_prune(int argc, |
| 154 | const char **argv, |
| 155 | const char *prefix, |
| 156 | struct repository *repo) |
| 157 | { |
| 158 | struct rev_info revs; |
| 159 | int exclude_promisor_objects = 0; |
| 160 | const struct option options[] = { |
| 161 | OPT__DRY_RUN(&show_only, N_("do not remove, show only")), |
| 162 | OPT__VERBOSE(&verbose, N_("report pruned objects")), |
| 163 | OPT_BOOL(0, "progress", &show_progress, N_("show progress")), |
| 164 | OPT_EXPIRY_DATE(0, "expire", &expire, |
| 165 | N_("expire objects older than <time>")), |
| 166 | OPT_BOOL(0, "exclude-promisor-objects", &exclude_promisor_objects, |
| 167 | N_("limit traversal to objects outside promisor packfiles")), |
| 168 | OPT_END() |
| 169 | }; |
| 170 | char *s; |
| 171 | |
| 172 | expire = TIME_MAX; |
| 173 | save_commit_buffer = 0; |
| 174 | disable_replace_refs(); |
| 175 | |
| 176 | argc = parse_options(argc, argv, prefix, options, prune_usage, 0); |
| 177 | |
| 178 | repo_init_revisions(repo, &revs, prefix); |
| 179 | if (repo->repository_format_precious_objects) |
| 180 | die(_("cannot prune in a precious-objects repo")); |
| 181 | |
| 182 | while (argc--) { |
| 183 | struct object_id oid; |
| 184 | const char *name = *argv++; |
| 185 | |
| 186 | if (!repo_get_oid(repo, name, &oid)) { |
| 187 | struct object *object = parse_object_or_die(repo, &oid, name); |
| 188 | add_pending_object(&revs, object, ""); |
| 189 | } |
| 190 | else |
| 191 | die("unrecognized argument: %s", name); |
| 192 | } |
| 193 | |
| 194 | if (show_progress == -1) |
| 195 | show_progress = isatty(2); |
| 196 | if (exclude_promisor_objects) { |
| 197 | fetch_if_missing = 0; |
| 198 | revs.exclude_promisor_objects = 1; |
| 199 | } |
| 200 | |
| 201 | for_each_loose_file_in_source(repo->objects->sources, |
| 202 | prune_object, prune_cruft, prune_subdir, &revs); |
| 203 | |
| 204 | prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0); |
| 205 | remove_temporary_files(repo_get_object_directory(repo)); |
| 206 | s = mkpathdup("%s/pack", repo_get_object_directory(repo)); |
| 207 | remove_temporary_files(s); |
| 208 | free(s); |
| 209 | |
| 210 | if (is_repository_shallow(repo)) { |
nothing calls this directly
no test coverage detected