Skip to content

Commit 80db3cd

Browse files
ttaylorrgitster
authored andcommitted
builtin/repack.c: pass write_pack_opts to finish_pack_objects_cmd()
To prepare to move the `finish_pack_objects_cmd()` function out of the builtin and into the repack.h API, there are a couple of things we need to do first: - First, let's take advantage of `write_pack_opts_is_local()` function introduced in the previous commit instead of passing "local" explicitly. - Let's also avoid referring to the static 'packtmp' field within builtin/repack.c by instead accessing it through the write_pack_opts argument. There are three callers which need to adjust themselves in order to account for this change. The callers which reside in write_cruft_pack() and write_filtered_pack() both already have an "opts" in scope, so they can pass it through transparently. The other call (at the bottom of `cmd_repack()`) needs to initialize its own write_pack_opts to pass the necessary fields over to the direct call to `finish_pack_objects_cmd()`. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2f79c79 commit 80db3cd

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

builtin/repack.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,12 @@ static int repack_config(const char *var, const char *value,
108108
}
109109

110110
static int finish_pack_objects_cmd(const struct git_hash_algo *algop,
111+
const struct write_pack_opts *opts,
111112
struct child_process *cmd,
112-
struct string_list *names,
113-
int local)
113+
struct string_list *names)
114114
{
115115
FILE *out;
116+
bool local = write_pack_opts_is_local(opts);
116117
struct strbuf line = STRBUF_INIT;
117118

118119
out = xfdopen(cmd->out, "r");
@@ -128,7 +129,8 @@ static int finish_pack_objects_cmd(const struct git_hash_algo *algop,
128129
*/
129130
if (local) {
130131
item = string_list_append(names, line.buf);
131-
item->util = generated_pack_populate(line.buf, packtmp);
132+
item->util = generated_pack_populate(line.buf,
133+
opts->packtmp);
132134
}
133135
}
134136
fclose(out);
@@ -147,7 +149,6 @@ static int write_filtered_pack(const struct write_pack_opts *opts,
147149
FILE *in;
148150
int ret;
149151
const char *caret;
150-
bool local = write_pack_opts_is_local(opts);
151152
const char *pack_prefix = write_pack_opts_pack_prefix(opts);
152153

153154
prepare_pack_objects(&cmd, opts->po_args, opts->destination);
@@ -183,8 +184,8 @@ static int write_filtered_pack(const struct write_pack_opts *opts,
183184
fprintf(in, "%s%s.pack\n", caret, item->string);
184185
fclose(in);
185186

186-
return finish_pack_objects_cmd(existing->repo->hash_algo, &cmd, names,
187-
local);
187+
return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
188+
names);
188189
}
189190

190191
static void combine_small_cruft_packs(FILE *in, size_t combine_cruft_below_size,
@@ -231,7 +232,6 @@ static int write_cruft_pack(const struct write_pack_opts *opts,
231232
struct string_list_item *item;
232233
FILE *in;
233234
int ret;
234-
bool local = write_pack_opts_is_local(opts);
235235
const char *pack_prefix = write_pack_opts_pack_prefix(opts);
236236

237237
prepare_pack_objects(&cmd, opts->po_args, opts->destination);
@@ -279,8 +279,8 @@ static int write_cruft_pack(const struct write_pack_opts *opts,
279279
fprintf(in, "%s.pack\n", item->string);
280280
fclose(in);
281281

282-
return finish_pack_objects_cmd(existing->repo->hash_algo, &cmd, names,
283-
local);
282+
return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
283+
names);
284284
}
285285

286286
int cmd_repack(int argc,
@@ -560,9 +560,17 @@ int cmd_repack(int argc,
560560
fclose(in);
561561
}
562562

563-
ret = finish_pack_objects_cmd(repo->hash_algo, &cmd, &names, 1);
564-
if (ret)
565-
goto cleanup;
563+
{
564+
struct write_pack_opts opts = {
565+
.packdir = packdir,
566+
.destination = packdir,
567+
.packtmp = packtmp,
568+
};
569+
ret = finish_pack_objects_cmd(repo->hash_algo, &opts, &cmd,
570+
&names);
571+
if (ret)
572+
goto cleanup;
573+
}
566574

567575
if (!names.nr) {
568576
if (!po_args.quiet)

0 commit comments

Comments
 (0)