Files
git/builtin/prune-packed.c
Shashank S Mogaveera b36143daa1 prune-packed: remove USE_THE_REPOSITORY_VARIABLE
The prune_packed_objects() function uses the global
the_repository variable. To help with the libification effort,
change this function so it takes a 'struct repository' pointer
as an argument instead.

The function for_each_loose_file_in_source() uses a callback
that only takes a single 'void *data' pointer. This means we
cannot pass both the repository pointer and the 'opts' integer
at the same time. To fix this, create a new 'struct prune_data'
to hold both of them together, and update the prune_subdir() and
prune_object() callbacks to read from this new struct.

Update the builtins that call this function to pass their local
`repo` parameters. As all of those builtins are declared with
`RUN_SETUP` we know that they won't execute outside a repository
and thus the repository parameter will be set. Unless the command
was invoked with "-h" to print help, but all new uses of the `repo`
variable are after a call to `parse_options()` which knows to exit
early in case it sees "-h"

Finally, drop the USE_THE_REPOSITORY_VARIABLE macro from
prune-packed.c.

Signed-off-by: Shashank S Mogaveera <shashu8660@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-10-27 14:41:39 -07:00

36 lines
859 B
C

#include "builtin.h"
#include "gettext.h"
#include "parse-options.h"
#include "prune-packed.h"
static const char * const prune_packed_usage[] = {
"git prune-packed [-n | --dry-run] [-q | --quiet]",
NULL
};
int cmd_prune_packed(int argc,
const char **argv,
const char *prefix,
struct repository *repo)
{
int opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0;
const struct option prune_packed_options[] = {
OPT_BIT('n', "dry-run", &opts, N_("dry run"),
PRUNE_PACKED_DRY_RUN),
OPT_NEGBIT('q', "quiet", &opts, N_("be quiet"),
PRUNE_PACKED_VERBOSE),
OPT_END()
};
argc = parse_options(argc, argv, prefix, prune_packed_options,
prune_packed_usage, 0);
if (argc > 0)
usage_msg_opt(_("too many arguments"),
prune_packed_usage,
prune_packed_options);
prune_packed_objects(repo, opts);
return 0;
}