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>
58 lines
1.2 KiB
C
58 lines
1.2 KiB
C
#include "git-compat-util.h"
|
|
#include "gettext.h"
|
|
#include "object-file.h"
|
|
#include "packfile.h"
|
|
#include "progress.h"
|
|
#include "prune-packed.h"
|
|
#include "repository.h"
|
|
|
|
struct prune_data {
|
|
struct repository *r;
|
|
int opts;
|
|
};
|
|
|
|
static struct progress *progress;
|
|
|
|
static int prune_subdir(unsigned int nr, const char *path, void *data)
|
|
{
|
|
struct prune_data *d = data;
|
|
display_progress(progress, nr + 1);
|
|
if (!(d->opts & PRUNE_PACKED_DRY_RUN))
|
|
rmdir(path);
|
|
return 0;
|
|
}
|
|
|
|
static int prune_object(const struct object_id *oid, const char *path,
|
|
void *data)
|
|
{
|
|
struct prune_data *d = data;
|
|
|
|
if (!has_object_pack(d->r, oid))
|
|
return 0;
|
|
|
|
if (d->opts & PRUNE_PACKED_DRY_RUN)
|
|
printf("rm -f %s\n", path);
|
|
else
|
|
unlink_or_warn(path);
|
|
return 0;
|
|
}
|
|
|
|
void prune_packed_objects(struct repository *r, int opts)
|
|
{
|
|
struct prune_data cb_data = {
|
|
.r = r,
|
|
.opts = opts
|
|
};
|
|
|
|
if (opts & PRUNE_PACKED_VERBOSE)
|
|
progress = start_delayed_progress(r,
|
|
_("Removing duplicate objects"), 256);
|
|
|
|
for_each_loose_file_in_source(r->objects->source,
|
|
prune_object, NULL, prune_subdir, &cb_data);
|
|
|
|
/* Ensure we show 100% before finishing progress */
|
|
display_progress(progress, 256);
|
|
stop_progress(&progress);
|
|
}
|