Skip to content

Commit 7eefa13

Browse files
committed
Merge branch 'cc/write-promisor-file'
A bit of code refactoring. * cc/write-promisor-file: pack-write: die on error in write_promisor_file() fetch-pack: refactor writing promisor file fetch-pack: rename helper to create_promisor_file()
2 parents 8b48981 + 7c99bc2 commit 7eefa13

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

builtin/repack.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "object-store.h"
1515
#include "promisor-remote.h"
1616
#include "shallow.h"
17+
#include "pack.h"
1718

1819
static int delta_base_offset = 1;
1920
static int pack_kept_objects = -1;
@@ -263,7 +264,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
263264
while (strbuf_getline_lf(&line, out) != EOF) {
264265
struct string_list_item *item;
265266
char *promisor_name;
266-
int fd;
267+
267268
if (line.len != the_hash_algo->hexsz)
268269
die(_("repack: Expecting full hex object ID lines only from pack-objects."));
269270
item = string_list_append(names, line.buf);
@@ -281,10 +282,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
281282
*/
282283
promisor_name = mkpathdup("%s-%s.promisor", packtmp,
283284
line.buf);
284-
fd = open(promisor_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
285-
if (fd < 0)
286-
die_errno(_("unable to create '%s'"), promisor_name);
287-
close(fd);
285+
write_promisor_file(promisor_name, NULL, 0);
288286

289287
item->util = (void *)(uintptr_t)populate_pack_exts(item->string);
290288

fetch-pack.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -772,13 +772,11 @@ static int sideband_demux(int in, int out, void *data)
772772
return ret;
773773
}
774774

775-
static void write_promisor_file(const char *keep_name,
776-
struct ref **sought, int nr_sought)
775+
static void create_promisor_file(const char *keep_name,
776+
struct ref **sought, int nr_sought)
777777
{
778778
struct strbuf promisor_name = STRBUF_INIT;
779779
int suffix_stripped;
780-
FILE *output;
781-
int i;
782780

783781
strbuf_addstr(&promisor_name, keep_name);
784782
suffix_stripped = strbuf_strip_suffix(&promisor_name, ".keep");
@@ -787,11 +785,7 @@ static void write_promisor_file(const char *keep_name,
787785
keep_name);
788786
strbuf_addstr(&promisor_name, ".promisor");
789787

790-
output = xfopen(promisor_name.buf, "w");
791-
for (i = 0; i < nr_sought; i++)
792-
fprintf(output, "%s %s\n", oid_to_hex(&sought[i]->old_oid),
793-
sought[i]->name);
794-
fclose(output);
788+
write_promisor_file(promisor_name.buf, sought, nr_sought);
795789

796790
strbuf_release(&promisor_name);
797791
}
@@ -875,7 +869,7 @@ static int get_pack(struct fetch_pack_args *args,
875869

876870
if (args->from_promisor)
877871
/*
878-
* write_promisor_file() may be called afterwards but
872+
* create_promisor_file() may be called afterwards but
879873
* we still need index-pack to know that this is a
880874
* promisor pack. For example, if transfer.fsckobjects
881875
* is true, index-pack needs to know that .gitmodules
@@ -943,7 +937,7 @@ static int get_pack(struct fetch_pack_args *args,
943937
* obtained .keep filename if necessary
944938
*/
945939
if (do_keep && pack_lockfiles && pack_lockfiles->nr && args->from_promisor)
946-
write_promisor_file(pack_lockfiles->items[0].string, sought, nr_sought);
940+
create_promisor_file(pack_lockfiles->items[0].string, sought, nr_sought);
947941

948942
return 0;
949943
}

pack-write.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "cache.h"
22
#include "pack.h"
33
#include "csum-file.h"
4+
#include "remote.h"
45

56
void reset_pack_idx_option(struct pack_idx_option *opts)
67
{
@@ -367,3 +368,18 @@ void finish_tmp_packfile(struct strbuf *name_buffer,
367368

368369
free((void *)idx_tmp_name);
369370
}
371+
372+
void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought)
373+
{
374+
int i, err;
375+
FILE *output = xfopen(promisor_name, "w");
376+
377+
for (i = 0; i < nr_sought; i++)
378+
fprintf(output, "%s %s\n", oid_to_hex(&sought[i]->old_oid),
379+
sought[i]->name);
380+
381+
err = ferror(output);
382+
err |= fclose(output);
383+
if (err)
384+
die(_("could not write '%s' promisor file"), promisor_name);
385+
}

pack.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ off_t write_pack_header(struct hashfile *f, uint32_t);
8787
void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);
8888
char *index_pack_lockfile(int fd);
8989

90+
struct ref;
91+
92+
void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought);
93+
9094
/*
9195
* The "hdr" output buffer should be at least this big, which will handle sizes
9296
* up to 2^67.

0 commit comments

Comments
 (0)