Skip to content

Commit 026587c

Browse files
committed
Merge branch 'jt/fetch-pack-record-refs-in-the-dot-promisor'
Debugging support for lazy cloning has been a bit improved. * jt/fetch-pack-record-refs-in-the-dot-promisor: fetch-pack: write fetched refs to .promisor
2 parents da72936 + 5374a29 commit 026587c

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

builtin/repack.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
233233
/*
234234
* pack-objects creates the .pack and .idx files, but not the
235235
* .promisor file. Create the .promisor file, which is empty.
236+
*
237+
* NEEDSWORK: fetch-pack sometimes generates non-empty
238+
* .promisor files containing the ref names and associated
239+
* hashes at the point of generation of the corresponding
240+
* packfile, but this would not preserve their contents. Maybe
241+
* concatenate the contents of all .promisor files instead of
242+
* just creating a new empty file.
236243
*/
237244
promisor_name = mkpathdup("%s-%s.promisor", packtmp,
238245
line.buf);

fetch-pack.c

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,33 @@ static int sideband_demux(int in, int out, void *data)
756756
return ret;
757757
}
758758

759+
static void write_promisor_file(const char *keep_name,
760+
struct ref **sought, int nr_sought)
761+
{
762+
struct strbuf promisor_name = STRBUF_INIT;
763+
int suffix_stripped;
764+
FILE *output;
765+
int i;
766+
767+
strbuf_addstr(&promisor_name, keep_name);
768+
suffix_stripped = strbuf_strip_suffix(&promisor_name, ".keep");
769+
if (!suffix_stripped)
770+
BUG("name of pack lockfile should end with .keep (was '%s')",
771+
keep_name);
772+
strbuf_addstr(&promisor_name, ".promisor");
773+
774+
output = xfopen(promisor_name.buf, "w");
775+
for (i = 0; i < nr_sought; i++)
776+
fprintf(output, "%s %s\n", oid_to_hex(&sought[i]->old_oid),
777+
sought[i]->name);
778+
fclose(output);
779+
780+
strbuf_release(&promisor_name);
781+
}
782+
759783
static int get_pack(struct fetch_pack_args *args,
760-
int xd[2], char **pack_lockfile)
784+
int xd[2], char **pack_lockfile,
785+
struct ref **sought, int nr_sought)
761786
{
762787
struct async demux;
763788
int do_keep = args->keep_pack;
@@ -819,7 +844,13 @@ static int get_pack(struct fetch_pack_args *args,
819844
}
820845
if (args->check_self_contained_and_connected)
821846
argv_array_push(&cmd.args, "--check-self-contained-and-connected");
822-
if (args->from_promisor)
847+
/*
848+
* If we're obtaining the filename of a lockfile, we'll use
849+
* that filename to write a .promisor file with more
850+
* information below. If not, we need index-pack to do it for
851+
* us.
852+
*/
853+
if (!(do_keep && pack_lockfile) && args->from_promisor)
823854
argv_array_push(&cmd.args, "--promisor");
824855
}
825856
else {
@@ -873,6 +904,14 @@ static int get_pack(struct fetch_pack_args *args,
873904
die(_("%s failed"), cmd_name);
874905
if (use_sideband && finish_async(&demux))
875906
die(_("error in sideband demultiplexer"));
907+
908+
/*
909+
* Now that index-pack has succeeded, write the promisor file using the
910+
* obtained .keep filename if necessary
911+
*/
912+
if (do_keep && pack_lockfile && args->from_promisor)
913+
write_promisor_file(*pack_lockfile, sought, nr_sought);
914+
876915
return 0;
877916
}
878917

@@ -1008,7 +1047,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
10081047
alternate_shallow_file = setup_temporary_shallow(si->shallow);
10091048
else
10101049
alternate_shallow_file = NULL;
1011-
if (get_pack(args, fd, pack_lockfile))
1050+
if (get_pack(args, fd, pack_lockfile, sought, nr_sought))
10121051
die(_("git fetch-pack: fetch failed."));
10131052

10141053
all_done:
@@ -1464,7 +1503,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
14641503

14651504
/* get the pack */
14661505
process_section_header(&reader, "packfile", 0);
1467-
if (get_pack(args, fd, pack_lockfile))
1506+
if (get_pack(args, fd, pack_lockfile, sought, nr_sought))
14681507
die(_("git fetch-pack: fetch failed."));
14691508

14701509
state = FETCH_DONE;

t/t5616-partial-clone.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ test_expect_success 'do partial clone 1' '
4646
test "$(git -C pc1 config --local remote.origin.partialclonefilter)" = "blob:none"
4747
'
4848

49+
test_expect_success 'verify that .promisor file contains refs fetched' '
50+
ls pc1/.git/objects/pack/pack-*.promisor >promisorlist &&
51+
test_line_count = 1 promisorlist &&
52+
git -C srv.bare rev-list HEAD >headhash &&
53+
grep "$(cat headhash) HEAD" $(cat promisorlist) &&
54+
grep "$(cat headhash) refs/heads/master" $(cat promisorlist)
55+
'
56+
4957
# checkout master to force dynamic object fetch of blobs at HEAD.
5058
test_expect_success 'verify checkout with dynamic object fetch' '
5159
git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed &&

0 commit comments

Comments
 (0)