Skip to content

Commit d131154

Browse files
ttaylorrgitster
authored andcommitted
repack: move write_filtered_pack() out of the builtin
In a similar fashion as in previous commits, move the function `write_filtered_pack()` out of the builtin and into its own compilation unit. This function is now part of the repack.h API, but implemented in its own "repack-filtered.c" unit as it is a separate component from other kinds of repacking operations. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7db1053 commit d131154

File tree

5 files changed

+57
-46
lines changed

5 files changed

+57
-46
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,7 @@ LIB_OBJS += refs/ref-cache.o
11371137
LIB_OBJS += refspec.o
11381138
LIB_OBJS += remote.o
11391139
LIB_OBJS += repack.o
1140+
LIB_OBJS += repack-filtered.o
11401141
LIB_OBJS += repack-geometry.o
11411142
LIB_OBJS += repack-midx.o
11421143
LIB_OBJS += repack-promisor.o

builtin/repack.c

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -106,52 +106,6 @@ static int repack_config(const char *var, const char *value,
106106
return git_default_config(var, value, ctx, cb);
107107
}
108108

109-
static int write_filtered_pack(struct write_pack_opts *opts,
110-
struct existing_packs *existing,
111-
struct string_list *names)
112-
{
113-
struct child_process cmd = CHILD_PROCESS_INIT;
114-
struct string_list_item *item;
115-
FILE *in;
116-
int ret;
117-
const char *caret;
118-
const char *pack_prefix = write_pack_opts_pack_prefix(opts);
119-
120-
prepare_pack_objects(&cmd, opts->po_args, opts->destination);
121-
122-
strvec_push(&cmd.args, "--stdin-packs");
123-
124-
for_each_string_list_item(item, &existing->kept_packs)
125-
strvec_pushf(&cmd.args, "--keep-pack=%s", item->string);
126-
127-
cmd.in = -1;
128-
129-
ret = start_command(&cmd);
130-
if (ret)
131-
return ret;
132-
133-
/*
134-
* Here 'names' contains only the pack(s) that were just
135-
* written, which is exactly the packs we want to keep. Also
136-
* 'existing_kept_packs' already contains the packs in
137-
* 'keep_pack_list'.
138-
*/
139-
in = xfdopen(cmd.in, "w");
140-
for_each_string_list_item(item, names)
141-
fprintf(in, "^%s-%s.pack\n", pack_prefix, item->string);
142-
for_each_string_list_item(item, &existing->non_kept_packs)
143-
fprintf(in, "%s.pack\n", item->string);
144-
for_each_string_list_item(item, &existing->cruft_packs)
145-
fprintf(in, "%s.pack\n", item->string);
146-
caret = opts->po_args->pack_kept_objects ? "" : "^";
147-
for_each_string_list_item(item, &existing->kept_packs)
148-
fprintf(in, "%s%s.pack\n", caret, item->string);
149-
fclose(in);
150-
151-
return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
152-
names);
153-
}
154-
155109
static void combine_small_cruft_packs(FILE *in, size_t combine_cruft_below_size,
156110
struct existing_packs *existing)
157111
{

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ libgit_sources = [
463463
'reftable/writer.c',
464464
'remote.c',
465465
'repack.c',
466+
'repack-filtered.c',
466467
'repack-geometry.c',
467468
'repack-midx.c',
468469
'repack-promisor.c',

repack-filtered.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "git-compat-util.h"
2+
#include "repack.h"
3+
#include "repository.h"
4+
#include "run-command.h"
5+
#include "string-list.h"
6+
7+
int write_filtered_pack(struct write_pack_opts *opts,
8+
struct existing_packs *existing,
9+
struct string_list *names)
10+
{
11+
struct child_process cmd = CHILD_PROCESS_INIT;
12+
struct string_list_item *item;
13+
FILE *in;
14+
int ret;
15+
const char *caret;
16+
const char *pack_prefix = write_pack_opts_pack_prefix(opts);
17+
18+
prepare_pack_objects(&cmd, opts->po_args, opts->destination);
19+
20+
strvec_push(&cmd.args, "--stdin-packs");
21+
22+
for_each_string_list_item(item, &existing->kept_packs)
23+
strvec_pushf(&cmd.args, "--keep-pack=%s", item->string);
24+
25+
cmd.in = -1;
26+
27+
ret = start_command(&cmd);
28+
if (ret)
29+
return ret;
30+
31+
/*
32+
* Here 'names' contains only the pack(s) that were just
33+
* written, which is exactly the packs we want to keep. Also
34+
* 'existing_kept_packs' already contains the packs in
35+
* 'keep_pack_list'.
36+
*/
37+
in = xfdopen(cmd.in, "w");
38+
for_each_string_list_item(item, names)
39+
fprintf(in, "^%s-%s.pack\n", pack_prefix, item->string);
40+
for_each_string_list_item(item, &existing->non_kept_packs)
41+
fprintf(in, "%s.pack\n", item->string);
42+
for_each_string_list_item(item, &existing->cruft_packs)
43+
fprintf(in, "%s.pack\n", item->string);
44+
caret = opts->po_args->pack_kept_objects ? "" : "^";
45+
for_each_string_list_item(item, &existing->kept_packs)
46+
fprintf(in, "%s%s.pack\n", caret, item->string);
47+
fclose(in);
48+
49+
return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
50+
names);
51+
}

repack.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,8 @@ struct repack_write_midx_opts {
133133
void midx_snapshot_refs(struct repository *repo, struct tempfile *f);
134134
int write_midx_included_packs(struct repack_write_midx_opts *opts);
135135

136+
int write_filtered_pack(struct write_pack_opts *opts,
137+
struct existing_packs *existing,
138+
struct string_list *names);
139+
136140
#endif /* REPACK_H */

0 commit comments

Comments
 (0)