summaryrefslogtreecommitdiff
path: root/fetch-pack.c
diff options
context:
space:
mode:
Diffstat (limited to 'fetch-pack.c')
-rw-r--r--fetch-pack.c72
1 files changed, 61 insertions, 11 deletions
diff --git a/fetch-pack.c b/fetch-pack.c
index 6ccc629..f80e2d1 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -167,16 +167,16 @@ static enum ack_type get_ack(struct packet_reader *reader,
if (!strcmp(reader->line, "NAK"))
return NAK;
if (skip_prefix(reader->line, "ACK ", &arg)) {
- if (!get_oid_hex(arg, result_oid)) {
- arg += 40;
- len -= arg - reader->line;
+ const char *p;
+ if (!parse_oid_hex(arg, result_oid, &p)) {
+ len -= p - reader->line;
if (len < 1)
return ACK;
- if (strstr(arg, "continue"))
+ if (strstr(p, "continue"))
return ACK_continue;
- if (strstr(arg, "common"))
+ if (strstr(p, "common"))
return ACK_common;
- if (strstr(arg, "ready"))
+ if (strstr(p, "ready"))
return ACK_ready;
return ACK;
}
@@ -382,6 +382,7 @@ static int find_common(struct fetch_negotiator *negotiator,
state_len = 0;
}
+ trace2_region_enter("fetch-pack", "negotiation_v0_v1", the_repository);
flushes = 0;
retval = -1;
if (args->no_dependents)
@@ -466,6 +467,7 @@ static int find_common(struct fetch_negotiator *negotiator,
}
}
done:
+ trace2_region_leave("fetch-pack", "negotiation_v0_v1", the_repository);
if (!got_ready || !no_done) {
packet_buf_write(&req_buf, "done\n");
send_request(args, fd[1], &req_buf);
@@ -754,8 +756,33 @@ static int sideband_demux(int in, int out, void *data)
return ret;
}
+static void write_promisor_file(const char *keep_name,
+ struct ref **sought, int nr_sought)
+{
+ struct strbuf promisor_name = STRBUF_INIT;
+ int suffix_stripped;
+ FILE *output;
+ int i;
+
+ strbuf_addstr(&promisor_name, keep_name);
+ suffix_stripped = strbuf_strip_suffix(&promisor_name, ".keep");
+ if (!suffix_stripped)
+ BUG("name of pack lockfile should end with .keep (was '%s')",
+ keep_name);
+ strbuf_addstr(&promisor_name, ".promisor");
+
+ output = xfopen(promisor_name.buf, "w");
+ for (i = 0; i < nr_sought; i++)
+ fprintf(output, "%s %s\n", oid_to_hex(&sought[i]->old_oid),
+ sought[i]->name);
+ fclose(output);
+
+ strbuf_release(&promisor_name);
+}
+
static int get_pack(struct fetch_pack_args *args,
- int xd[2], char **pack_lockfile)
+ int xd[2], char **pack_lockfile,
+ struct ref **sought, int nr_sought)
{
struct async demux;
int do_keep = args->keep_pack;
@@ -817,7 +844,13 @@ static int get_pack(struct fetch_pack_args *args,
}
if (args->check_self_contained_and_connected)
argv_array_push(&cmd.args, "--check-self-contained-and-connected");
- if (args->from_promisor)
+ /*
+ * If we're obtaining the filename of a lockfile, we'll use
+ * that filename to write a .promisor file with more
+ * information below. If not, we need index-pack to do it for
+ * us.
+ */
+ if (!(do_keep && pack_lockfile) && args->from_promisor)
argv_array_push(&cmd.args, "--promisor");
}
else {
@@ -871,6 +904,14 @@ static int get_pack(struct fetch_pack_args *args,
die(_("%s failed"), cmd_name);
if (use_sideband && finish_async(&demux))
die(_("error in sideband demultiplexer"));
+
+ /*
+ * Now that index-pack has succeeded, write the promisor file using the
+ * obtained .keep filename if necessary
+ */
+ if (do_keep && pack_lockfile && args->from_promisor)
+ write_promisor_file(*pack_lockfile, sought, nr_sought);
+
return 0;
}
@@ -1006,7 +1047,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
alternate_shallow_file = setup_temporary_shallow(si->shallow);
else
alternate_shallow_file = NULL;
- if (get_pack(args, fd, pack_lockfile))
+ if (get_pack(args, fd, pack_lockfile, sought, nr_sought))
die(_("git fetch-pack: fetch failed."));
all_done:
@@ -1378,7 +1419,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
enum fetch_state state = FETCH_CHECK_LOCAL;
struct oidset common = OIDSET_INIT;
struct packet_reader reader;
- int in_vain = 0;
+ int in_vain = 0, negotiation_started = 0;
int haves_to_send = INITIAL_FLUSH;
struct fetch_negotiator negotiator;
fetch_negotiator_init(r, &negotiator);
@@ -1421,6 +1462,12 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
}
break;
case FETCH_SEND_REQUEST:
+ if (!negotiation_started) {
+ negotiation_started = 1;
+ trace2_region_enter("fetch-pack",
+ "negotiation_v2",
+ the_repository);
+ }
if (send_fetch_request(&negotiator, fd[1], args, ref,
&common,
&haves_to_send, &in_vain,
@@ -1444,6 +1491,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
}
break;
case FETCH_GET_PACK:
+ trace2_region_leave("fetch-pack",
+ "negotiation_v2",
+ the_repository);
/* Check for shallow-info section */
if (process_section_header(&reader, "shallow-info", 1))
receive_shallow_info(args, &reader, shallows, si);
@@ -1453,7 +1503,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
/* get the pack */
process_section_header(&reader, "packfile", 0);
- if (get_pack(args, fd, pack_lockfile))
+ if (get_pack(args, fd, pack_lockfile, sought, nr_sought))
die(_("git fetch-pack: fetch failed."));
state = FETCH_DONE;