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 <peff@peff.net> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
Nov 16, 2020 at 13:41 UTC
704c4a5c0720825bf79db428bfcbd10b642a5b57
1 file changed
+30
-1
builtin/repack.c
+30
-1
@@ -212,6 +212,27 @@ static struct {
212
{".promisor", 1},
213
};
214
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
+
236
static void repack_promisor_objects(const struct pack_objects_args *args,
237
struct string_list *names)
238
{
@@ -240,11 +261,12 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
261
262
out = xfdopen(cmd.out, "r");
263
while (strbuf_getline_lf(&line, out) != EOF) {
264
+ struct string_list_item *item;
265
char *promisor_name;
266
int fd;
267
if (line.len != the_hash_algo->hexsz)
268
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);
270
271
/*
272
* 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,
285
if (fd < 0)
286
die_errno(_("unable to create '%s'"), promisor_name);
287
close(fd);
288
+
289
+ item->util = (void *)(uintptr_t)populate_pack_exts(item->string);
290
+
291
free(promisor_name);
292
}
293
fclose(out);
@@ -430,6 +455,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
455
if (!names.nr && !po_args.quiet)
456
printf_ln(_("Nothing new to pack."));
457
458
+ for_each_string_list_item(item, &names) {
459
+ item->util = (void *)(uintptr_t)populate_pack_exts(item->string);
460
+ }
461
+
462
close_object_store(the_repository->objects);
463
464
/*