Merge branch 'jt/upload-pack-deepen-relative-proto-v2'
"git fetch --deepen=<more>" has been corrected to work over v2 protocol. * jt/upload-pack-deepen-relative-proto-v2: upload-pack: teach deepen-relative in protocol v2 fetch-pack: do not take shallow lock unnecessarily
This commit is contained in:
commit
a6e3839976
13
fetch-pack.c
13
fetch-pack.c
@ -1007,6 +1007,8 @@ static void add_shallow_requests(struct strbuf *req_buf,
|
||||
packet_buf_write(req_buf, "deepen-not %s", s->string);
|
||||
}
|
||||
}
|
||||
if (args->deepen_relative)
|
||||
packet_buf_write(req_buf, "deepen-relative\n");
|
||||
}
|
||||
|
||||
static void add_wants(int no_dependents, const struct ref *wants, struct strbuf *req_buf)
|
||||
@ -1232,6 +1234,8 @@ static int process_acks(struct fetch_negotiator *negotiator,
|
||||
static void receive_shallow_info(struct fetch_pack_args *args,
|
||||
struct packet_reader *reader)
|
||||
{
|
||||
int line_received = 0;
|
||||
|
||||
process_section_header(reader, "shallow-info", 0);
|
||||
while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
|
||||
const char *arg;
|
||||
@ -1241,6 +1245,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
|
||||
if (get_oid_hex(arg, &oid))
|
||||
die(_("invalid shallow line: %s"), reader->line);
|
||||
register_shallow(the_repository, &oid);
|
||||
line_received = 1;
|
||||
continue;
|
||||
}
|
||||
if (skip_prefix(reader->line, "unshallow ", &arg)) {
|
||||
@ -1253,6 +1258,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
|
||||
die(_("error in object: %s"), reader->line);
|
||||
if (unregister_shallow(&oid))
|
||||
die(_("no shallow found: %s"), reader->line);
|
||||
line_received = 1;
|
||||
continue;
|
||||
}
|
||||
die(_("expected shallow/unshallow, got %s"), reader->line);
|
||||
@ -1262,8 +1268,11 @@ static void receive_shallow_info(struct fetch_pack_args *args,
|
||||
reader->status != PACKET_READ_DELIM)
|
||||
die(_("error processing shallow info: %d"), reader->status);
|
||||
|
||||
setup_alternate_shallow(&shallow_lock, &alternate_shallow_file, NULL);
|
||||
args->deepen = 1;
|
||||
if (line_received) {
|
||||
setup_alternate_shallow(&shallow_lock, &alternate_shallow_file,
|
||||
NULL);
|
||||
args->deepen = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void receive_wanted_refs(struct packet_reader *reader,
|
||||
|
@ -43,6 +43,13 @@ int register_shallow(struct repository *r, const struct object_id *oid)
|
||||
|
||||
int is_repository_shallow(struct repository *r)
|
||||
{
|
||||
/*
|
||||
* NEEDSWORK: This function updates
|
||||
* r->parsed_objects->{is_shallow,shallow_stat} as a side effect but
|
||||
* there is no corresponding function to clear them when the shallow
|
||||
* file is updated.
|
||||
*/
|
||||
|
||||
FILE *fp;
|
||||
char buf[1024];
|
||||
const char *path = r->parsed_objects->alternate_shallow_file;
|
||||
|
@ -471,6 +471,53 @@ test_expect_success 'upload-pack respects client shallows' '
|
||||
grep "fetch< version 2" trace
|
||||
'
|
||||
|
||||
test_expect_success 'ensure that multiple fetches in same process from a shallow repo works' '
|
||||
rm -rf server client trace &&
|
||||
|
||||
test_create_repo server &&
|
||||
test_commit -C server one &&
|
||||
test_commit -C server two &&
|
||||
test_commit -C server three &&
|
||||
git clone --shallow-exclude two "file://$(pwd)/server" client &&
|
||||
|
||||
git -C server tag -a -m "an annotated tag" twotag two &&
|
||||
|
||||
# Triggers tag following (thus, 2 fetches in one process)
|
||||
GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
|
||||
fetch --shallow-exclude one origin &&
|
||||
# Ensure that protocol v2 is used
|
||||
grep "fetch< version 2" trace
|
||||
'
|
||||
|
||||
test_expect_success 'deepen-relative' '
|
||||
rm -rf server client trace &&
|
||||
|
||||
test_create_repo server &&
|
||||
test_commit -C server one &&
|
||||
test_commit -C server two &&
|
||||
test_commit -C server three &&
|
||||
git clone --depth 1 "file://$(pwd)/server" client &&
|
||||
test_commit -C server four &&
|
||||
|
||||
# Sanity check that only "three" is downloaded
|
||||
git -C client log --pretty=tformat:%s master >actual &&
|
||||
echo three >expected &&
|
||||
test_cmp expected actual &&
|
||||
|
||||
GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
|
||||
fetch --deepen=1 origin &&
|
||||
# Ensure that protocol v2 is used
|
||||
grep "fetch< version 2" trace &&
|
||||
|
||||
git -C client log --pretty=tformat:%s origin/master >actual &&
|
||||
cat >expected <<-\EOF &&
|
||||
four
|
||||
three
|
||||
two
|
||||
EOF
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
# Test protocol v2 with 'http://' transport
|
||||
#
|
||||
. "$TEST_DIRECTORY"/lib-httpd.sh
|
||||
|
@ -43,7 +43,6 @@
|
||||
|
||||
static timestamp_t oldest_have;
|
||||
|
||||
static int deepen_relative;
|
||||
static int multi_ack;
|
||||
static int no_done;
|
||||
static int use_thin_pack, use_ofs_delta, use_include_tag;
|
||||
@ -662,6 +661,9 @@ static void send_unshallow(const struct object_array *shallows,
|
||||
}
|
||||
}
|
||||
|
||||
static int check_ref(const char *refname_full, const struct object_id *oid,
|
||||
int flag, void *cb_data);
|
||||
|
||||
static void deepen(int depth, int deepen_relative,
|
||||
struct object_array *shallows, struct object_array *want_obj)
|
||||
{
|
||||
@ -676,6 +678,13 @@ static void deepen(int depth, int deepen_relative,
|
||||
struct object_array reachable_shallows = OBJECT_ARRAY_INIT;
|
||||
struct commit_list *result;
|
||||
|
||||
/*
|
||||
* Checking for reachable shallows requires that our refs be
|
||||
* marked with OUR_REF.
|
||||
*/
|
||||
head_ref_namespaced(check_ref, NULL);
|
||||
for_each_namespaced_ref(check_ref, NULL);
|
||||
|
||||
get_reachable_list(shallows, &reachable_shallows);
|
||||
result = get_shallow_commits(&reachable_shallows,
|
||||
depth + 1,
|
||||
@ -712,6 +721,7 @@ static void deepen_by_rev_list(int ac, const char **av,
|
||||
static int send_shallow_list(int depth, int deepen_rev_list,
|
||||
timestamp_t deepen_since,
|
||||
struct string_list *deepen_not,
|
||||
int deepen_relative,
|
||||
struct object_array *shallows,
|
||||
struct object_array *want_obj)
|
||||
{
|
||||
@ -834,6 +844,7 @@ static void receive_needs(struct object_array *want_obj)
|
||||
int has_non_tip = 0;
|
||||
timestamp_t deepen_since = 0;
|
||||
int deepen_rev_list = 0;
|
||||
int deepen_relative = 0;
|
||||
|
||||
shallow_nr = 0;
|
||||
for (;;) {
|
||||
@ -925,7 +936,8 @@ static void receive_needs(struct object_array *want_obj)
|
||||
return;
|
||||
|
||||
if (send_shallow_list(depth, deepen_rev_list, deepen_since,
|
||||
&deepen_not, &shallows, want_obj))
|
||||
&deepen_not, deepen_relative, &shallows,
|
||||
want_obj))
|
||||
packet_flush(1);
|
||||
object_array_clear(&shallows);
|
||||
}
|
||||
@ -1398,6 +1410,7 @@ static void send_shallow_info(struct upload_pack_data *data,
|
||||
|
||||
if (!send_shallow_list(data->depth, data->deepen_rev_list,
|
||||
data->deepen_since, &data->deepen_not,
|
||||
data->deepen_relative,
|
||||
&data->shallows, want_obj) &&
|
||||
is_repository_shallow(the_repository))
|
||||
deepen(INFINITE_DEPTH, data->deepen_relative, &data->shallows,
|
||||
|
Loading…
Reference in New Issue
Block a user