Browse Source

fetch-pack: with packfile URIs, use index-pack arg

Unify the index-pack arguments used when processing the inline pack and
when downloading packfiles referenced by URIs. This is done by teaching
get_pack() to also store the index-pack arguments whenever at least one
packfile URI is given, and then when processing the packfile URI(s),
using the stored arguments.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Jonathan Tan 4 years ago committed by Junio C Hamano
parent
commit
b664e9ffa1
  1. 34
      fetch-pack.c

34
fetch-pack.c

@ -797,12 +797,13 @@ static void write_promisor_file(const char *keep_name,
} }


/* /*
* Pass 1 as "only_packfile" if the pack received is the only pack in this * If packfile URIs were provided, pass a non-NULL pointer to index_pack_args.
* fetch request (that is, if there were no packfile URIs provided). * The strings to pass as the --index-pack-arg arguments to http-fetch will be
* stored there. (It must be freed by the caller.)
*/ */
static int get_pack(struct fetch_pack_args *args, static int get_pack(struct fetch_pack_args *args,
int xd[2], struct string_list *pack_lockfiles, int xd[2], struct string_list *pack_lockfiles,
int only_packfile, struct strvec *index_pack_args,
struct ref **sought, int nr_sought) struct ref **sought, int nr_sought)
{ {
struct async demux; struct async demux;
@ -845,7 +846,7 @@ static int get_pack(struct fetch_pack_args *args,
strvec_push(&cmd.args, alternate_shallow_file); strvec_push(&cmd.args, alternate_shallow_file);
} }


if (do_keep || args->from_promisor) { if (do_keep || args->from_promisor || index_pack_args) {
if (pack_lockfiles) if (pack_lockfiles)
cmd.out = -1; cmd.out = -1;
cmd_name = "index-pack"; cmd_name = "index-pack";
@ -863,7 +864,7 @@ static int get_pack(struct fetch_pack_args *args,
"--keep=fetch-pack %"PRIuMAX " on %s", "--keep=fetch-pack %"PRIuMAX " on %s",
(uintmax_t)getpid(), hostname); (uintmax_t)getpid(), hostname);
} }
if (only_packfile && args->check_self_contained_and_connected) if (!index_pack_args && args->check_self_contained_and_connected)
strvec_push(&cmd.args, "--check-self-contained-and-connected"); strvec_push(&cmd.args, "--check-self-contained-and-connected");
else else
/* /*
@ -901,7 +902,7 @@ static int get_pack(struct fetch_pack_args *args,
: transfer_fsck_objects >= 0 : transfer_fsck_objects >= 0
? transfer_fsck_objects ? transfer_fsck_objects
: 0) { : 0) {
if (args->from_promisor || !only_packfile) if (args->from_promisor || index_pack_args)
/* /*
* We cannot use --strict in index-pack because it * We cannot use --strict in index-pack because it
* checks both broken objects and links, but we only * checks both broken objects and links, but we only
@ -913,6 +914,13 @@ static int get_pack(struct fetch_pack_args *args,
fsck_msg_types.buf); fsck_msg_types.buf);
} }


if (index_pack_args) {
int i;

for (i = 0; i < cmd.args.nr; i++)
strvec_push(index_pack_args, cmd.args.v[i]);
}

cmd.in = demux.out; cmd.in = demux.out;
cmd.git_cmd = 1; cmd.git_cmd = 1;
if (start_command(&cmd)) if (start_command(&cmd))
@ -1084,7 +1092,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
alternate_shallow_file = setup_temporary_shallow(si->shallow); alternate_shallow_file = setup_temporary_shallow(si->shallow);
else else
alternate_shallow_file = NULL; alternate_shallow_file = NULL;
if (get_pack(args, fd, pack_lockfiles, 1, sought, nr_sought)) if (get_pack(args, fd, pack_lockfiles, NULL, sought, nr_sought))
die(_("git fetch-pack: fetch failed.")); die(_("git fetch-pack: fetch failed."));


all_done: all_done:
@ -1535,6 +1543,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
int seen_ack = 0; int seen_ack = 0;
struct string_list packfile_uris = STRING_LIST_INIT_DUP; struct string_list packfile_uris = STRING_LIST_INIT_DUP;
int i; int i;
struct strvec index_pack_args = STRVEC_INIT;


negotiator = &negotiator_alloc; negotiator = &negotiator_alloc;
fetch_negotiator_init(r, negotiator); fetch_negotiator_init(r, negotiator);
@ -1624,7 +1633,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
receive_packfile_uris(&reader, &packfile_uris); receive_packfile_uris(&reader, &packfile_uris);
process_section_header(&reader, "packfile", 0); process_section_header(&reader, "packfile", 0);
if (get_pack(args, fd, pack_lockfiles, if (get_pack(args, fd, pack_lockfiles,
!packfile_uris.nr, sought, nr_sought)) packfile_uris.nr ? &index_pack_args : NULL,
sought, nr_sought))
die(_("git fetch-pack: fetch failed.")); die(_("git fetch-pack: fetch failed."));
do_check_stateless_delimiter(args, &reader); do_check_stateless_delimiter(args, &reader);


@ -1636,6 +1646,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
} }


for (i = 0; i < packfile_uris.nr; i++) { for (i = 0; i < packfile_uris.nr; i++) {
int j;
struct child_process cmd = CHILD_PROCESS_INIT; struct child_process cmd = CHILD_PROCESS_INIT;
char packname[GIT_MAX_HEXSZ + 1]; char packname[GIT_MAX_HEXSZ + 1];
const char *uri = packfile_uris.items[i].string + const char *uri = packfile_uris.items[i].string +
@ -1645,9 +1656,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
strvec_pushf(&cmd.args, "--packfile=%.*s", strvec_pushf(&cmd.args, "--packfile=%.*s",
(int) the_hash_algo->hexsz, (int) the_hash_algo->hexsz,
packfile_uris.items[i].string); packfile_uris.items[i].string);
strvec_push(&cmd.args, "--index-pack-arg=index-pack"); for (j = 0; j < index_pack_args.nr; j++)
strvec_push(&cmd.args, "--index-pack-arg=--stdin"); strvec_pushf(&cmd.args, "--index-pack-arg=%s",
strvec_push(&cmd.args, "--index-pack-arg=--keep"); index_pack_args.v[j]);
strvec_push(&cmd.args, uri); strvec_push(&cmd.args, uri);
cmd.git_cmd = 1; cmd.git_cmd = 1;
cmd.no_stdin = 1; cmd.no_stdin = 1;
@ -1683,6 +1694,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
packname)); packname));
} }
string_list_clear(&packfile_uris, 0); string_list_clear(&packfile_uris, 0);
strvec_clear(&index_pack_args);


if (negotiator) if (negotiator)
negotiator->release(negotiator); negotiator->release(negotiator);

Loading…
Cancel
Save