summaryrefslogtreecommitdiff
path: root/fetch-pack.c
diff options
context:
space:
mode:
Diffstat (limited to 'fetch-pack.c')
-rw-r--r--fetch-pack.c179
1 files changed, 133 insertions, 46 deletions
diff --git a/fetch-pack.c b/fetch-pack.c
index cb6647d..091f9a8 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1,24 +1,28 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "repository.h"
#include "config.h"
+#include "date.h"
+#include "environment.h"
+#include "gettext.h"
+#include "hex.h"
#include "lockfile.h"
#include "refs.h"
#include "pkt-line.h"
#include "commit.h"
#include "tag.h"
-#include "exec-cmd.h"
#include "pack.h"
#include "sideband.h"
#include "fetch-pack.h"
#include "remote.h"
#include "run-command.h"
#include "connect.h"
-#include "transport.h"
+#include "trace2.h"
#include "version.h"
#include "oid-array.h"
#include "oidset.h"
#include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "path.h"
#include "connected.h"
#include "fetch-negotiator.h"
#include "fsck.h"
@@ -26,6 +30,7 @@
#include "commit-reach.h"
#include "commit-graph.h"
#include "sigchain.h"
+#include "mergesort.h"
static int transfer_unpack_limit = -1;
static int fetch_unpack_limit = -1;
@@ -175,8 +180,10 @@ static int rev_list_insert_ref(struct fetch_negotiator *negotiator,
return 0;
}
-static int rev_list_insert_ref_oid(const char *refname, const struct object_id *oid,
- int flag, void *cb_data)
+static int rev_list_insert_ref_oid(const char *refname UNUSED,
+ const struct object_id *oid,
+ int flag UNUSED,
+ void *cb_data)
{
return rev_list_insert_ref(cb_data, oid);
}
@@ -292,6 +299,29 @@ static void mark_tips(struct fetch_negotiator *negotiator,
return;
}
+static void send_filter(struct fetch_pack_args *args,
+ struct strbuf *req_buf,
+ int server_supports_filter)
+{
+ if (args->filter_options.choice) {
+ const char *spec =
+ expand_list_objects_filter_spec(&args->filter_options);
+ if (server_supports_filter) {
+ print_verbose(args, _("Server supports filter"));
+ packet_buf_write(req_buf, "filter %s", spec);
+ trace2_data_string("fetch", the_repository,
+ "filter/effective", spec);
+ } else {
+ warning("filtering not recognized by server, ignoring");
+ trace2_data_string("fetch", the_repository,
+ "filter/unsupported", spec);
+ }
+ } else {
+ trace2_data_string("fetch", the_repository,
+ "filter/none", "");
+ }
+}
+
static int find_common(struct fetch_negotiator *negotiator,
struct fetch_pack_args *args,
int fd[2], struct object_id *result_oid,
@@ -299,6 +329,7 @@ static int find_common(struct fetch_negotiator *negotiator,
{
int fetching;
int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval;
+ int negotiation_round = 0, haves = 0;
const struct object_id *oid;
unsigned in_vain = 0;
int got_continue = 0;
@@ -389,11 +420,7 @@ static int find_common(struct fetch_negotiator *negotiator,
packet_buf_write(&req_buf, "deepen-not %s", s->string);
}
}
- if (server_supports_filtering && args->filter_options.choice) {
- const char *spec =
- expand_list_objects_filter_spec(&args->filter_options);
- packet_buf_write(&req_buf, "filter %s", spec);
- }
+ send_filter(args, &req_buf, server_supports_filtering);
packet_buf_flush(&req_buf);
state_len = req_buf.len;
@@ -441,9 +468,19 @@ static int find_common(struct fetch_negotiator *negotiator,
packet_buf_write(&req_buf, "have %s\n", oid_to_hex(oid));
print_verbose(args, "have %s", oid_to_hex(oid));
in_vain++;
+ haves++;
if (flush_at <= ++count) {
int ack;
+ negotiation_round++;
+ trace2_region_enter_printf("negotiation_v0_v1", "round",
+ the_repository, "%d",
+ negotiation_round);
+ trace2_data_intmax("negotiation_v0_v1", the_repository,
+ "haves_added", haves);
+ trace2_data_intmax("negotiation_v0_v1", the_repository,
+ "in_vain", in_vain);
+ haves = 0;
packet_buf_flush(&req_buf);
send_request(args, fd[1], &req_buf);
strbuf_setlen(&req_buf, state_len);
@@ -465,6 +502,9 @@ static int find_common(struct fetch_negotiator *negotiator,
ack, oid_to_hex(result_oid));
switch (ack) {
case ACK:
+ trace2_region_leave_printf("negotiation_v0_v1", "round",
+ the_repository, "%d",
+ negotiation_round);
flushes = 0;
multi_ack = 0;
retval = 0;
@@ -490,6 +530,7 @@ static int find_common(struct fetch_negotiator *negotiator,
const char *hex = oid_to_hex(result_oid);
packet_buf_write(&req_buf, "have %s\n", hex);
state_len = req_buf.len;
+ haves++;
/*
* Reset in_vain because an ack
* for this commit has not been
@@ -508,6 +549,9 @@ static int find_common(struct fetch_negotiator *negotiator,
}
} while (ack);
flushes--;
+ trace2_region_leave_printf("negotiation_v0_v1", "round",
+ the_repository, "%d",
+ negotiation_round);
if (got_continue && MAX_IN_VAIN < in_vain) {
print_verbose(args, _("giving up"));
break; /* give up */
@@ -518,6 +562,8 @@ static int find_common(struct fetch_negotiator *negotiator,
}
done:
trace2_region_leave("fetch-pack", "negotiation_v0_v1", the_repository);
+ trace2_data_intmax("negotiation_v0_v1", the_repository, "total_rounds",
+ negotiation_round);
if (!got_ready || !no_done) {
packet_buf_write(&req_buf, "done\n");
send_request(args, fd[1], &req_buf);
@@ -560,8 +606,10 @@ static int mark_complete(const struct object_id *oid)
return 0;
}
-static int mark_complete_oid(const char *refname, const struct object_id *oid,
- int flag, void *cb_data)
+static int mark_complete_oid(const char *refname UNUSED,
+ const struct object_id *oid,
+ int flag UNUSED,
+ void *cb_data UNUSED)
{
return mark_complete(oid);
}
@@ -678,7 +726,7 @@ static void filter_refs(struct fetch_pack_args *args,
*refs = newlist;
}
-static void mark_alternate_complete(struct fetch_negotiator *unused,
+static void mark_alternate_complete(struct fetch_negotiator *negotiator UNUSED,
struct object *obj)
{
mark_complete(&obj->oid);
@@ -718,9 +766,9 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
if (!commit) {
struct object *o;
- if (!has_object_file_with_flags(&ref->old_oid,
- OBJECT_INFO_QUICK |
- OBJECT_INFO_SKIP_FETCH_OBJECT))
+ if (!repo_has_object_file_with_flags(the_repository, &ref->old_oid,
+ OBJECT_INFO_QUICK |
+ OBJECT_INFO_SKIP_FETCH_OBJECT))
continue;
o = parse_object(the_repository, &ref->old_oid);
if (!o || o->type != OBJ_COMMIT)
@@ -799,7 +847,7 @@ static int everything_local(struct fetch_pack_args *args,
return retval;
}
-static int sideband_demux(int in, int out, void *data)
+static int sideband_demux(int in UNUSED, int out, void *data)
{
int *xd = data;
int ret;
@@ -1025,6 +1073,13 @@ static int get_pack(struct fetch_pack_args *args,
return 0;
}
+static int ref_compare_name(const struct ref *a, const struct ref *b)
+{
+ return strcmp(a->name, b->name);
+}
+
+DEFINE_LIST_SORT(static, sort_ref_list, struct ref, next);
+
static int cmp_ref_by_name(const void *a_, const void *b_)
{
const struct ref *a = *((const struct ref **)a_);
@@ -1043,7 +1098,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
struct ref *ref = copy_ref_list(orig_ref);
struct object_id oid;
const char *agent_feature;
- int agent_len;
+ size_t agent_len;
struct fetch_negotiator negotiator_alloc;
struct fetch_negotiator *negotiator;
@@ -1061,7 +1116,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
agent_supported = 1;
if (agent_len)
print_verbose(args, _("Server version is %.*s"),
- agent_len, agent_feature);
+ (int)agent_len, agent_feature);
}
if (!server_supports("session-id"))
@@ -1266,15 +1321,15 @@ static void write_fetch_command_and_capabilities(struct strbuf *req_buf,
{
const char *hash_name;
- if (server_supports_v2("fetch", 1))
- packet_buf_write(req_buf, "command=fetch");
- if (server_supports_v2("agent", 0))
+ ensure_server_supports_v2("fetch");
+ packet_buf_write(req_buf, "command=fetch");
+ if (server_supports_v2("agent"))
packet_buf_write(req_buf, "agent=%s", git_user_agent_sanitized());
- if (advertise_sid && server_supports_v2("session-id", 0))
+ if (advertise_sid && server_supports_v2("session-id"))
packet_buf_write(req_buf, "session-id=%s", trace2_session_id());
- if (server_options && server_options->nr &&
- server_supports_v2("server-option", 1)) {
+ if (server_options && server_options->nr) {
int i;
+ ensure_server_supports_v2("server-option");
for (i = 0; i < server_options->nr; i++)
packet_buf_write(req_buf, "server-option=%s",
server_options->items[i].string);
@@ -1323,15 +1378,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
die(_("Server does not support shallow requests"));
/* Add filter */
- if (server_supports_feature("fetch", "filter", 0) &&
- args->filter_options.choice) {
- const char *spec =
- expand_list_objects_filter_spec(&args->filter_options);
- print_verbose(args, _("Server supports filter"));
- packet_buf_write(&req_buf, "filter %s", spec);
- } else if (args->filter_options.choice) {
- warning("filtering not recognized by server, ignoring");
- }
+ send_filter(args, &req_buf,
+ server_supports_feature("fetch", "filter", 0));
if (server_supports_feature("fetch", "packfile-uris", 0)) {
int i;
@@ -1361,6 +1409,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
haves_added = add_haves(negotiator, &req_buf, haves_to_send);
*in_vain += haves_added;
+ trace2_data_intmax("negotiation_v2", the_repository, "haves_added", haves_added);
+ trace2_data_intmax("negotiation_v2", the_repository, "in_vain", *in_vain);
if (!haves_added || (seen_ack && *in_vain >= MAX_IN_VAIN)) {
/* Send Done */
packet_buf_write(&req_buf, "done\n");
@@ -1603,6 +1653,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
struct oidset common = OIDSET_INIT;
struct packet_reader reader;
int in_vain = 0, negotiation_started = 0;
+ int negotiation_round = 0;
int haves_to_send = INITIAL_FLUSH;
struct fetch_negotiator negotiator_alloc;
struct fetch_negotiator *negotiator;
@@ -1659,12 +1710,20 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
"negotiation_v2",
the_repository);
}
+ negotiation_round++;
+ trace2_region_enter_printf("negotiation_v2", "round",
+ the_repository, "%d",
+ negotiation_round);
if (send_fetch_request(negotiator, fd[1], args, ref,
&common,
&haves_to_send, &in_vain,
reader.use_sideband,
- seen_ack))
+ seen_ack)) {
+ trace2_region_leave_printf("negotiation_v2", "round",
+ the_repository, "%d",
+ negotiation_round);
state = FETCH_GET_PACK;
+ }
else
state = FETCH_PROCESS_ACKS;
break;
@@ -1677,6 +1736,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
seen_ack = 1;
oidset_insert(&common, &common_oid);
}
+ trace2_region_leave_printf("negotiation_v2", "round",
+ the_repository, "%d",
+ negotiation_round);
if (received_ready) {
/*
* Don't check for response delimiter; get_pack() will
@@ -1692,6 +1754,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
trace2_region_leave("fetch-pack",
"negotiation_v2",
the_repository);
+ trace2_data_intmax("negotiation_v2", the_repository,
+ "total_rounds", negotiation_round);
/* Check for shallow-info section */
if (process_section_header(&reader, "shallow-info", 1))
receive_shallow_info(args, &reader, shallows, si);
@@ -1793,8 +1857,11 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
return ref;
}
-static int fetch_pack_config_cb(const char *var, const char *value, void *cb)
+static int fetch_pack_config_cb(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
+ const char *msg_id;
+
if (strcmp(var, "fetch.fsck.skiplist") == 0) {
const char *path;
@@ -1806,16 +1873,18 @@ static int fetch_pack_config_cb(const char *var, const char *value, void *cb)
return 0;
}
- if (skip_prefix(var, "fetch.fsck.", &var)) {
- if (is_valid_msg_type(var, value))
+ if (skip_prefix(var, "fetch.fsck.", &msg_id)) {
+ if (!value)
+ return config_error_nonbool(var);
+ if (is_valid_msg_type(msg_id, value))
strbuf_addf(&fsck_msg_types, "%c%s=%s",
- fsck_msg_types.len ? ',' : '=', var, value);
+ fsck_msg_types.len ? ',' : '=', msg_id, value);
else
- warning("Skipping unknown msg id '%s'", var);
+ warning("Skipping unknown msg id '%s'", msg_id);
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static void fetch_pack_config(void)
@@ -1844,10 +1913,10 @@ static void fetch_pack_setup(void)
if (did_setup)
return;
fetch_pack_config();
- if (0 <= transfer_unpack_limit)
- unpack_limit = transfer_unpack_limit;
- else if (0 <= fetch_unpack_limit)
+ if (0 <= fetch_unpack_limit)
unpack_limit = fetch_unpack_limit;
+ else if (0 <= transfer_unpack_limit)
+ unpack_limit = transfer_unpack_limit;
did_setup = 1;
}
@@ -1903,7 +1972,7 @@ static void update_shallow(struct fetch_pack_args *args,
struct oid_array extra = OID_ARRAY_INIT;
struct object_id *oid = si->shallow->oid;
for (i = 0; i < si->shallow->nr; i++)
- if (has_object_file(&oid[i]))
+ if (repo_has_object_file(the_repository, &oid[i]))
oid_array_append(&extra, &oid[i]);
if (extra.nr) {
setup_alternate_shallow(&shallow_lock,
@@ -2071,6 +2140,7 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips,
int in_vain = 0;
int seen_ack = 0;
int last_iteration = 0;
+ int negotiation_round = 0;
timestamp_t min_generation = GENERATION_NUMBER_INFINITY;
fetch_negotiator_init(the_repository, &negotiator);
@@ -2084,11 +2154,17 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips,
add_to_object_array,
&nt_object_array);
+ trace2_region_enter("fetch-pack", "negotiate_using_fetch", the_repository);
while (!last_iteration) {
int haves_added;
struct object_id common_oid;
int received_ready = 0;
+ negotiation_round++;
+
+ trace2_region_enter_printf("negotiate_using_fetch", "round",
+ the_repository, "%d",
+ negotiation_round);
strbuf_reset(&req_buf);
write_fetch_command_and_capabilities(&req_buf, server_options);
@@ -2099,6 +2175,11 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips,
if (!haves_added || (seen_ack && in_vain >= MAX_IN_VAIN))
last_iteration = 1;
+ trace2_data_intmax("negotiate_using_fetch", the_repository,
+ "haves_added", haves_added);
+ trace2_data_intmax("negotiate_using_fetch", the_repository,
+ "in_vain", in_vain);
+
/* Send request */
packet_buf_flush(&req_buf);
if (write_in_full(fd[1], req_buf.buf, req_buf.len) < 0)
@@ -2131,7 +2212,13 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips,
REACH_SCRATCH, 0,
min_generation))
last_iteration = 1;
+ trace2_region_leave_printf("negotiation", "round",
+ the_repository, "%d",
+ negotiation_round);
}
+ trace2_region_leave("fetch-pack", "negotiate_using_fetch", the_repository);
+ trace2_data_intmax("negotiate_using_fetch", the_repository,
+ "total_rounds", negotiation_round);
clear_common_flag(acked_commits);
strbuf_release(&req_buf);
}