754
return ret;
755
}
756
757
+static void write_promisor_file(const char *keep_name,
758
+ struct ref **sought, int nr_sought)
759
+{
760
+ struct strbuf promisor_name = STRBUF_INIT;
761
+ int suffix_stripped;
762
+ FILE *output;
763
+ int i;
764
+
765
+ strbuf_addstr(&promisor_name, keep_name);
766
+ suffix_stripped = strbuf_strip_suffix(&promisor_name, ".keep");
767
+ if (!suffix_stripped)
768
+ BUG("name of pack lockfile should end with .keep (was '%s')",
769
+ keep_name);
770
+ strbuf_addstr(&promisor_name, ".promisor");
771
+
772
+ output = xfopen(promisor_name.buf, "w");
773
+ for (i = 0; i < nr_sought; i++)
774
+ fprintf(output, "%s %s\n", oid_to_hex(&sought[i]->old_oid),
775
+ sought[i]->name);
776
+ fclose(output);
777
+
778
+ strbuf_release(&promisor_name);
779
+}
780
+
781
static int get_pack(struct fetch_pack_args *args,
758
- int xd[2], char **pack_lockfile)
782
+ int xd[2], char **pack_lockfile,
783
+ struct ref **sought, int nr_sought)
784
{
785
struct async demux;
786
int do_keep = args->keep_pack;
842
}
843
if (args->check_self_contained_and_connected)
844
argv_array_push(&cmd.args, "--check-self-contained-and-connected");
820
- if (args->from_promisor)
845
+ /*
846
+ * If we're obtaining the filename of a lockfile, we'll use
847
+ * that filename to write a .promisor file with more
848
+ * information below. If not, we need index-pack to do it for
849
+ * us.
850
+ */
851
+ if (!(do_keep && pack_lockfile) && args->from_promisor)
852
argv_array_push(&cmd.args, "--promisor");
853
}
854
else {
902
die(_("%s failed"), cmd_name);
903
if (use_sideband && finish_async(&demux))
904
die(_("error in sideband demultiplexer"));
905
+
906
+ /*
907
+ * Now that index-pack has succeeded, write the promisor file using the
908
+ * obtained .keep filename if necessary
909
+ */
910
+ if (do_keep && pack_lockfile && args->from_promisor)
911
+ write_promisor_file(*pack_lockfile, sought, nr_sought);
912
+
913
return 0;
914
}
915
1045
alternate_shallow_file = setup_temporary_shallow(si->shallow);
1046
else
1047
alternate_shallow_file = NULL;
1009
- if (get_pack(args, fd, pack_lockfile))
1048
+ if (get_pack(args, fd, pack_lockfile, sought, nr_sought))
1049
die(_("git fetch-pack: fetch failed."));
1050
1051
all_done:
1492
1493
/* get the pack */
1494
process_section_header(&reader, "packfile", 0);
1456
- if (get_pack(args, fd, pack_lockfile))
1495
+ if (get_pack(args, fd, pack_lockfile, sought, nr_sought))
1496
die(_("git fetch-pack: fetch failed."));
1497
1498
state = FETCH_DONE;