fetch-pack: refactor writing promisor file

Let's replace the 2 different pieces of code that write a
promisor file in 'builtin/repack.c' and 'fetch-pack.c'
with a new function called 'write_promisor_file()' in
'pack-write.c' and 'pack.h'.

This might also help us in the future, if we want to put
back the ref names and associated hashes that were in
the promisor files we are repacking in 'builtin/repack.c'
as suggested by a NEEDSWORK comment just above the code
we are refactoring.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Christian Couder
2021-01-12 09:21:59 +01:00
committed by Junio C Hamano
parent 9d7fa3be31
commit 33add2ad7d
4 changed files with 20 additions and 12 deletions

View File

@ -777,8 +777,6 @@ static void create_promisor_file(const char *keep_name,
{
struct strbuf promisor_name = STRBUF_INIT;
int suffix_stripped;
FILE *output;
int i;
strbuf_addstr(&promisor_name, keep_name);
suffix_stripped = strbuf_strip_suffix(&promisor_name, ".keep");
@ -787,11 +785,7 @@ static void create_promisor_file(const char *keep_name,
keep_name);
strbuf_addstr(&promisor_name, ".promisor");
output = xfopen(promisor_name.buf, "w");
for (i = 0; i < nr_sought; i++)
fprintf(output, "%s %s\n", oid_to_hex(&sought[i]->old_oid),
sought[i]->name);
fclose(output);
write_promisor_file(promisor_name.buf, sought, nr_sought);
strbuf_release(&promisor_name);
}