Skip to content

Commit fa0787a

Browse files
ttaylorrgitster
authored andcommitted
repack: move finish_pack_objects_cmd() out of the builtin
In a similar spirit as the previous commit(s), now that the function `finish_pack_objects_cmd()` has no explicit dependencies within the repack builtin, let's extract it. This prepares us to extract the remaining two functions within the repack builtin that explicitly write packfiles, which are `write_cruft_pack()` and `write_filtered_pack()`, which will be done in the future commits. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80db3cd commit fa0787a

File tree

3 files changed

+38
-33
lines changed

3 files changed

+38
-33
lines changed

builtin/repack.c

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

110-
static int finish_pack_objects_cmd(const struct git_hash_algo *algop,
111-
const struct write_pack_opts *opts,
112-
struct child_process *cmd,
113-
struct string_list *names)
114-
{
115-
FILE *out;
116-
bool local = write_pack_opts_is_local(opts);
117-
struct strbuf line = STRBUF_INIT;
118-
119-
out = xfdopen(cmd->out, "r");
120-
while (strbuf_getline_lf(&line, out) != EOF) {
121-
struct string_list_item *item;
122-
123-
if (line.len != algop->hexsz)
124-
die(_("repack: Expecting full hex object ID lines only "
125-
"from pack-objects."));
126-
/*
127-
* Avoid putting packs written outside of the repository in the
128-
* list of names.
129-
*/
130-
if (local) {
131-
item = string_list_append(names, line.buf);
132-
item->util = generated_pack_populate(line.buf,
133-
opts->packtmp);
134-
}
135-
}
136-
fclose(out);
137-
138-
strbuf_release(&line);
139-
140-
return finish_command(cmd);
141-
}
142-
143110
static int write_filtered_pack(const struct write_pack_opts *opts,
144111
struct existing_packs *existing,
145112
struct string_list *names)

repack.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,39 @@ bool write_pack_opts_is_local(const struct write_pack_opts *opts)
8282
return starts_with(opts->destination, opts->packdir);
8383
}
8484

85+
int finish_pack_objects_cmd(const struct git_hash_algo *algop,
86+
const struct write_pack_opts *opts,
87+
struct child_process *cmd,
88+
struct string_list *names)
89+
{
90+
FILE *out;
91+
bool local = write_pack_opts_is_local(opts);
92+
struct strbuf line = STRBUF_INIT;
93+
94+
out = xfdopen(cmd->out, "r");
95+
while (strbuf_getline_lf(&line, out) != EOF) {
96+
struct string_list_item *item;
97+
98+
if (line.len != algop->hexsz)
99+
die(_("repack: Expecting full hex object ID lines only "
100+
"from pack-objects."));
101+
/*
102+
* Avoid putting packs written outside of the repository in the
103+
* list of names.
104+
*/
105+
if (local) {
106+
item = string_list_append(names, line.buf);
107+
item->util = generated_pack_populate(line.buf,
108+
opts->packtmp);
109+
}
110+
}
111+
fclose(out);
112+
113+
strbuf_release(&line);
114+
115+
return finish_command(cmd);
116+
}
117+
85118
#define DELETE_PACK 1
86119
#define RETAIN_PACK 2
87120

repack.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ struct write_pack_opts {
4242
const char *write_pack_opts_pack_prefix(const struct write_pack_opts *opts);
4343
bool write_pack_opts_is_local(const struct write_pack_opts *opts);
4444

45+
int finish_pack_objects_cmd(const struct git_hash_algo *algop,
46+
const struct write_pack_opts *opts,
47+
struct child_process *cmd,
48+
struct string_list *names);
49+
4550
struct repository;
4651
struct packed_git;
4752

0 commit comments

Comments
 (0)