Skip to content

Commit 9460fd4

Browse files
Denton-Lgitster
authored andcommitted
Lib-ify prune-packed
In builtin.h, there exists the distinctly lib-ish function prune_packed_objects(). This function can currently only be called by built-in commands but, unlike all of the other functions in the header, it does not make sense to impose this restriction as the functionality can be logically reused in libgit. Extract this function into prune-packed.c so that related definitions can exist clearly in their own header file. While we're at it, clean up #includes that are unused. This patch is best viewed with --color-moved. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ce6521e commit 9460fd4

File tree

7 files changed

+56
-48
lines changed

7 files changed

+56
-48
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ LIB_OBJS += progress.o
952952
LIB_OBJS += promisor-remote.o
953953
LIB_OBJS += prompt.o
954954
LIB_OBJS += protocol.o
955+
LIB_OBJS += prune-packed.o
955956
LIB_OBJS += quote.o
956957
LIB_OBJS += range-diff.o
957958
LIB_OBJS += reachable.o

builtin.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,6 @@
9797
extern const char git_usage_string[];
9898
extern const char git_more_info_string[];
9999

100-
#define PRUNE_PACKED_DRY_RUN 01
101-
#define PRUNE_PACKED_VERBOSE 02
102-
103-
void prune_packed_objects(int);
104-
105100
/**
106101
* If a built-in has DELAY_PAGER_CONFIG set, the built-in should call this early
107102
* when it wishes to respect the `pager.foo`-config. The `cmd` is the name of

builtin/prune-packed.c

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,12 @@
11
#include "builtin.h"
2-
#include "cache.h"
3-
#include "progress.h"
42
#include "parse-options.h"
5-
#include "packfile.h"
6-
#include "object-store.h"
3+
#include "prune-packed.h"
74

85
static const char * const prune_packed_usage[] = {
96
N_("git prune-packed [-n | --dry-run] [-q | --quiet]"),
107
NULL
118
};
129

13-
static struct progress *progress;
14-
15-
static int prune_subdir(unsigned int nr, const char *path, void *data)
16-
{
17-
int *opts = data;
18-
display_progress(progress, nr + 1);
19-
if (!(*opts & PRUNE_PACKED_DRY_RUN))
20-
rmdir(path);
21-
return 0;
22-
}
23-
24-
static int prune_object(const struct object_id *oid, const char *path,
25-
void *data)
26-
{
27-
int *opts = data;
28-
29-
if (!has_object_pack(oid))
30-
return 0;
31-
32-
if (*opts & PRUNE_PACKED_DRY_RUN)
33-
printf("rm -f %s\n", path);
34-
else
35-
unlink_or_warn(path);
36-
return 0;
37-
}
38-
39-
void prune_packed_objects(int opts)
40-
{
41-
if (opts & PRUNE_PACKED_VERBOSE)
42-
progress = start_delayed_progress(_("Removing duplicate objects"), 256);
43-
44-
for_each_loose_file_in_objdir(get_object_directory(),
45-
prune_object, NULL, prune_subdir, &opts);
46-
47-
/* Ensure we show 100% before finishing progress */
48-
display_progress(progress, 256);
49-
stop_progress(&progress);
50-
}
51-
5210
int cmd_prune_packed(int argc, const char **argv, const char *prefix)
5311
{
5412
int opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0;

builtin/prune.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "reachable.h"
77
#include "parse-options.h"
88
#include "progress.h"
9+
#include "prune-packed.h"
910
#include "object-store.h"
1011

1112
static const char * const prune_usage[] = {

builtin/repack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "argv-array.h"
1111
#include "midx.h"
1212
#include "packfile.h"
13+
#include "prune-packed.h"
1314
#include "object-store.h"
1415
#include "promisor-remote.h"
1516

prune-packed.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "object-store.h"
2+
#include "packfile.h"
3+
#include "progress.h"
4+
#include "prune-packed.h"
5+
6+
static struct progress *progress;
7+
8+
static int prune_subdir(unsigned int nr, const char *path, void *data)
9+
{
10+
int *opts = data;
11+
display_progress(progress, nr + 1);
12+
if (!(*opts & PRUNE_PACKED_DRY_RUN))
13+
rmdir(path);
14+
return 0;
15+
}
16+
17+
static int prune_object(const struct object_id *oid, const char *path,
18+
void *data)
19+
{
20+
int *opts = data;
21+
22+
if (!has_object_pack(oid))
23+
return 0;
24+
25+
if (*opts & PRUNE_PACKED_DRY_RUN)
26+
printf("rm -f %s\n", path);
27+
else
28+
unlink_or_warn(path);
29+
return 0;
30+
}
31+
32+
void prune_packed_objects(int opts)
33+
{
34+
if (opts & PRUNE_PACKED_VERBOSE)
35+
progress = start_delayed_progress(_("Removing duplicate objects"), 256);
36+
37+
for_each_loose_file_in_objdir(get_object_directory(),
38+
prune_object, NULL, prune_subdir, &opts);
39+
40+
/* Ensure we show 100% before finishing progress */
41+
display_progress(progress, 256);
42+
stop_progress(&progress);
43+
}

prune-packed.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef PRUNE_PACKED_H
2+
#define PRUNE_PACKED_H
3+
4+
#define PRUNE_PACKED_DRY_RUN 01
5+
#define PRUNE_PACKED_VERBOSE 02
6+
7+
void prune_packed_objects(int);
8+
9+
#endif

0 commit comments

Comments
 (0)