Skip to content

Commit 7a9c81a

Browse files
ttaylorrgitster
authored andcommitted
builtin/repack.c: introduce struct write_pack_opts
There are various functions within the 'repack' builtin which are responsible for writing different kinds of packs. They include: - `static int write_filtered_pack(...)` - `static int write_cruft_pack(...)` as well as the function `finish_pack_objects_cmd()`, which is responsible for finalizing a new pack write, and recording the checksum of its contents in the 'names' list. Both of these `write_` functions have a few things in common. They both take a pointer to the 'pack_objects_args' struct, as well as a pair of character pointers for `destination` and `pack_prefix`. Instead of repeating those arguments for each function, let's extract an options struct called "write_pack_opts" which has these three parameters as member fields. While we're at it, add fields for "packdir," and "packtmp", both of which are static variables within the builtin, and need to be read from within these two functions. This will shorten the list of parameters that callers have to provide to `write_filtered_pack()`, avoid ambiguity when passing multiple variables of the same type, and provide a unified interface for the two functions mentioned earlier. (Note that "pack_prefix" can be derived on the fly as a function of "packdir" and "packtmp", making it unnecessary to store "pack_prefix" explicitly. This commit ignores that potential cleanup in the name of doing as few things as possible, but a later commit will make that change.) Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6d05eb1 commit 7a9c81a

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

builtin/repack.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ static int finish_pack_objects_cmd(const struct git_hash_algo *algop,
138138
return finish_command(cmd);
139139
}
140140

141-
static int write_filtered_pack(const struct pack_objects_args *args,
142-
const char *destination,
143-
const char *pack_prefix,
141+
static int write_filtered_pack(const struct write_pack_opts *opts,
144142
struct existing_packs *existing,
145143
struct string_list *names)
146144
{
@@ -150,9 +148,9 @@ static int write_filtered_pack(const struct pack_objects_args *args,
150148
int ret;
151149
const char *caret;
152150
const char *scratch;
153-
int local = skip_prefix(destination, packdir, &scratch);
151+
int local = skip_prefix(opts->destination, opts->packdir, &scratch);
154152

155-
prepare_pack_objects(&cmd, args, destination);
153+
prepare_pack_objects(&cmd, opts->po_args, opts->destination);
156154

157155
strvec_push(&cmd.args, "--stdin-packs");
158156

@@ -175,7 +173,7 @@ static int write_filtered_pack(const struct pack_objects_args *args,
175173
*/
176174
in = xfdopen(cmd.in, "w");
177175
for_each_string_list_item(item, names)
178-
fprintf(in, "^%s-%s.pack\n", pack_prefix, item->string);
176+
fprintf(in, "^%s-%s.pack\n", opts->pack_prefix, item->string);
179177
for_each_string_list_item(item, &existing->non_kept_packs)
180178
fprintf(in, "%s.pack\n", item->string);
181179
for_each_string_list_item(item, &existing->cruft_packs)
@@ -665,14 +663,18 @@ int cmd_repack(int argc,
665663
}
666664

667665
if (po_args.filter_options.choice) {
668-
if (!filter_to)
669-
filter_to = packtmp;
670-
671-
ret = write_filtered_pack(&po_args,
672-
filter_to,
673-
find_pack_prefix(packdir, packtmp),
674-
&existing,
675-
&names);
666+
struct write_pack_opts opts = {
667+
.po_args = &po_args,
668+
.destination = filter_to,
669+
.pack_prefix = find_pack_prefix(packdir, packtmp),
670+
.packdir = packdir,
671+
.packtmp = packtmp,
672+
};
673+
674+
if (!opts.destination)
675+
opts.destination = packtmp;
676+
677+
ret = write_filtered_pack(&opts, &existing, &names);
676678
if (ret)
677679
goto cleanup;
678680
}

repack.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ void pack_objects_args_release(struct pack_objects_args *args);
3232
void repack_remove_redundant_pack(struct repository *repo, const char *dir_name,
3333
const char *base_name);
3434

35+
struct write_pack_opts {
36+
struct pack_objects_args *po_args;
37+
const char *destination;
38+
const char *pack_prefix;
39+
const char *packdir;
40+
const char *packtmp;
41+
};
42+
3543
struct repository;
3644
struct packed_git;
3745

0 commit comments

Comments
 (0)