builtin/repack.c: write cruft packs to arbitrary locations

In the following commit, a new write_cruft_pack() caller will be added which wants to write a cruft pack to an arbitrary location. Prepare for this by adding a parameter which controls the destination of the cruft pack. For now, provide "packtmp" so that this commit does not change any behavior. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Oct 24, 2022 at 14:43 UTC c12cda479eb103bc364e299a2e5654a7165df3cd
1 file changed +11 -3
builtin/repack.c
+11 -3
@@ -662,6 +662,7 @@ static int write_midx_included_packs(struct string_list *include,
662 }
663
664 static int write_cruft_pack(const struct pack_objects_args *args,
665 + const char *destination,
666 const char *pack_prefix,
667 const char *cruft_expiration,
668 struct string_list *names,
@@ -673,8 +674,10 @@ static int write_cruft_pack(const struct pack_objects_args *args,
674 struct string_list_item *item;
675 FILE *in, *out;
676 int ret;
677 + const char *scratch;
678 + int local = skip_prefix(destination, packdir, &scratch);
679
677 - prepare_pack_objects(&cmd, args, packtmp);
680 + prepare_pack_objects(&cmd, args, destination);
681
682 strvec_push(&cmd.args, "--cruft");
683 if (cruft_expiration)
@@ -714,7 +717,12 @@ static int write_cruft_pack(const struct pack_objects_args *args,
717 if (line.len != the_hash_algo->hexsz)
718 die(_("repack: Expecting full hex object ID lines only "
719 "from pack-objects."));
717 - string_list_append(names, line.buf);
720 + /*
721 + * avoid putting packs written outside of the repository in the
722 + * list of names
723 + */
724 + if (local)
725 + string_list_append(names, line.buf);
726 }
727 fclose(out);
728
@@ -986,7 +994,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
994 cruft_po_args.local = po_args.local;
995 cruft_po_args.quiet = po_args.quiet;
996
989 - ret = write_cruft_pack(&cruft_po_args, pack_prefix,
997 + ret = write_cruft_pack(&cruft_po_args, packtmp, pack_prefix,
998 cruft_expiration, &names,
999 &existing_nonkept_packs,
1000 &existing_kept_packs);