Skip to content

Commit 704c4a5

Browse files
ttaylorrpeff
authored andcommitted
builtin/repack.c: keep track of what pack-objects wrote
In the subsequent commit, it will become useful to keep track of which metadata files were written by pack-objects. We already do this to an extent with the 'exts' array, which only is used in the context of existing packs. Co-authored-by: Jeff King <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 63f4d5c commit 704c4a5

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

builtin/repack.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,27 @@ static struct {
212212
{".promisor", 1},
213213
};
214214

215+
static unsigned populate_pack_exts(char *name)
216+
{
217+
struct stat statbuf;
218+
struct strbuf path = STRBUF_INIT;
219+
unsigned ret = 0;
220+
int i;
221+
222+
for (i = 0; i < ARRAY_SIZE(exts); i++) {
223+
strbuf_reset(&path);
224+
strbuf_addf(&path, "%s-%s%s", packtmp, name, exts[i].name);
225+
226+
if (stat(path.buf, &statbuf))
227+
continue;
228+
229+
ret |= (1 << i);
230+
}
231+
232+
strbuf_release(&path);
233+
return ret;
234+
}
235+
215236
static void repack_promisor_objects(const struct pack_objects_args *args,
216237
struct string_list *names)
217238
{
@@ -240,11 +261,12 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
240261

241262
out = xfdopen(cmd.out, "r");
242263
while (strbuf_getline_lf(&line, out) != EOF) {
264+
struct string_list_item *item;
243265
char *promisor_name;
244266
int fd;
245267
if (line.len != the_hash_algo->hexsz)
246268
die(_("repack: Expecting full hex object ID lines only from pack-objects."));
247-
string_list_append(names, line.buf);
269+
item = string_list_append(names, line.buf);
248270

249271
/*
250272
* pack-objects creates the .pack and .idx files, but not the
@@ -263,6 +285,9 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
263285
if (fd < 0)
264286
die_errno(_("unable to create '%s'"), promisor_name);
265287
close(fd);
288+
289+
item->util = (void *)(uintptr_t)populate_pack_exts(item->string);
290+
266291
free(promisor_name);
267292
}
268293
fclose(out);
@@ -430,6 +455,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
430455
if (!names.nr && !po_args.quiet)
431456
printf_ln(_("Nothing new to pack."));
432457

458+
for_each_string_list_item(item, &names) {
459+
item->util = (void *)(uintptr_t)populate_pack_exts(item->string);
460+
}
461+
433462
close_object_store(the_repository->objects);
434463

435464
/*

0 commit comments

Comments
 (0)