Skip to content

Commit 9f3ff59

Browse files
committed
prune-packed: remove USE_THE_REPOSITORY_VARIABLE
Right now, 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 (builtin/prune-packed.c, builtin/prune.c, and builtin/repack.c) to pass their local `repo` variables. Because we are now actually using the 'repo' parameter in these files, we can safely remove the UNUSED macro from them. finally, drop the USE_THE_REPOSITORY_VARIABLE macro from prune-packed.c. Signed-off-by: Shashank <shashu8660@gmail.com>
1 parent 6de20f6 commit 9f3ff59

5 files changed

Lines changed: 27 additions & 17 deletions

File tree

‎builtin/prune-packed.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ static const char * const prune_packed_usage[] = {
1111
int cmd_prune_packed(int argc,
1212
const char **argv,
1313
const char *prefix,
14-
struct repository *repo UNUSED)
14+
struct repository *repo)
1515
{
1616
int opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0;
1717
const struct option prune_packed_options[] = {
@@ -30,6 +30,6 @@ int cmd_prune_packed(int argc,
3030
prune_packed_usage,
3131
prune_packed_options);
3232

33-
prune_packed_objects(opts);
33+
prune_packed_objects(repo, opts);
3434
return 0;
3535
}

‎builtin/prune.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ int cmd_prune(int argc,
201201
for_each_loose_file_in_source(repo->objects->sources,
202202
prune_object, prune_cruft, prune_subdir, &revs);
203203

204-
prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);
204+
prune_packed_objects(repo, show_only ? PRUNE_PACKED_DRY_RUN : 0);
205205
remove_temporary_files(repo_get_object_directory(repo));
206206
s = mkpathdup("%s/pack", repo_get_object_directory(repo));
207207
remove_temporary_files(s);

‎builtin/repack.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ int cmd_repack(int argc,
757757
wrote_incremental_midx);
758758
if (show_progress)
759759
opts |= PRUNE_PACKED_VERBOSE;
760-
prune_packed_objects(opts);
760+
prune_packed_objects(repo, opts);
761761

762762
if (!keep_unreachable &&
763763
(!(pack_everything & LOOSEN_UNREACHABLE) ||

‎prune-packed.c‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
2-
31
#include "git-compat-util.h"
42
#include "gettext.h"
53
#include "object-file.h"
@@ -8,40 +6,50 @@
86
#include "prune-packed.h"
97
#include "repository.h"
108

9+
struct prune_data {
10+
struct repository *r;
11+
int opts;
12+
};
13+
1114
static struct progress *progress;
1215

1316
static int prune_subdir(unsigned int nr, const char *path, void *data)
1417
{
15-
int *opts = data;
18+
struct prune_data *d = data;
1619
display_progress(progress, nr + 1);
17-
if (!(*opts & PRUNE_PACKED_DRY_RUN))
20+
if (!(d->opts & PRUNE_PACKED_DRY_RUN))
1821
rmdir(path);
1922
return 0;
2023
}
2124

2225
static int prune_object(const struct object_id *oid, const char *path,
23-
void *data)
26+
void *data)
2427
{
25-
int *opts = data;
28+
struct prune_data *d = data;
2629

27-
if (!has_object_pack(the_repository, oid))
30+
if (!repo_has_object_pack(d->r, oid))
2831
return 0;
2932

30-
if (*opts & PRUNE_PACKED_DRY_RUN)
33+
if (d->opts & PRUNE_PACKED_DRY_RUN)
3134
printf("rm -f %s\n", path);
3235
else
3336
unlink_or_warn(path);
3437
return 0;
3538
}
3639

37-
void prune_packed_objects(int opts)
40+
void prune_packed_objects(struct repository *r, int opts)
3841
{
42+
struct prune_data cb_data = {
43+
.r = r,
44+
.opts = opts
45+
};
46+
3947
if (opts & PRUNE_PACKED_VERBOSE)
40-
progress = start_delayed_progress(the_repository,
48+
progress = start_delayed_progress(r,
4149
_("Removing duplicate objects"), 256);
4250

43-
for_each_loose_file_in_source(the_repository->objects->sources,
44-
prune_object, NULL, prune_subdir, &opts);
51+
for_each_loose_file_in_source(r->objects->sources,
52+
prune_object, NULL, prune_subdir, &cb_data);
4553

4654
/* Ensure we show 100% before finishing progress */
4755
display_progress(progress, 256);

‎prune-packed.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#ifndef PRUNE_PACKED_H
22
#define PRUNE_PACKED_H
33

4+
struct repository;
5+
46
#define PRUNE_PACKED_DRY_RUN 01
57
#define PRUNE_PACKED_VERBOSE 02
68

7-
void prune_packed_objects(int);
9+
void prune_packed_objects(struct repository *r, int opts);
810

911
#endif

0 commit comments

Comments
 (0)