Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions builtin/prune-packed.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static const char * const prune_packed_usage[] = {
int cmd_prune_packed(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
struct repository *repo)
{
int opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0;
const struct option prune_packed_options[] = {
Expand All @@ -30,6 +30,6 @@ int cmd_prune_packed(int argc,
prune_packed_usage,
prune_packed_options);

prune_packed_objects(opts);
prune_packed_objects(repo, opts);
return 0;
}
2 changes: 1 addition & 1 deletion builtin/prune.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ int cmd_prune(int argc,
for_each_loose_file_in_source(repo->objects->sources,
prune_object, prune_cruft, prune_subdir, &revs);

prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);
prune_packed_objects(repo, show_only ? PRUNE_PACKED_DRY_RUN : 0);
remove_temporary_files(repo_get_object_directory(repo));
s = mkpathdup("%s/pack", repo_get_object_directory(repo));
remove_temporary_files(s);
Expand Down
2 changes: 1 addition & 1 deletion builtin/repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ int cmd_repack(int argc,
wrote_incremental_midx);
if (show_progress)
opts |= PRUNE_PACKED_VERBOSE;
prune_packed_objects(opts);
prune_packed_objects(repo, opts);

if (!keep_unreachable &&
(!(pack_everything & LOOSEN_UNREACHABLE) ||
Expand Down
32 changes: 20 additions & 12 deletions prune-packed.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "gettext.h"
#include "object-file.h"
Expand All @@ -8,40 +6,50 @@
#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)
{
int *opts = data;
struct prune_data *d = data;
display_progress(progress, nr + 1);
if (!(*opts & PRUNE_PACKED_DRY_RUN))
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)
void *data)
{
int *opts = data;
struct prune_data *d = data;

if (!has_object_pack(the_repository, oid))
if (!has_object_pack(d->r, oid))
return 0;

if (*opts & PRUNE_PACKED_DRY_RUN)
if (d->opts & PRUNE_PACKED_DRY_RUN)
printf("rm -f %s\n", path);
else
unlink_or_warn(path);
return 0;
}

void prune_packed_objects(int opts)
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(the_repository,
progress = start_delayed_progress(r,
_("Removing duplicate objects"), 256);

for_each_loose_file_in_source(the_repository->objects->sources,
prune_object, NULL, prune_subdir, &opts);
for_each_loose_file_in_source(r->objects->sources,
prune_object, NULL, prune_subdir, &cb_data);

/* Ensure we show 100% before finishing progress */
display_progress(progress, 256);
Expand Down
4 changes: 3 additions & 1 deletion prune-packed.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#ifndef PRUNE_PACKED_H
#define PRUNE_PACKED_H

struct repository;

#define PRUNE_PACKED_DRY_RUN 01
#define PRUNE_PACKED_VERBOSE 02

void prune_packed_objects(int);
void prune_packed_objects(struct repository *r, int opts);

#endif
Loading