Skip to content

Commit a012588

Browse files
committed
Merge branch 'cc/upload-pack-v2-fetch-fix'
Serving a "git fetch" client over "git://" and "ssh://" protocols using the on-wire protocol version 2 was buggy on the server end when the client needs to make a follow-up request to e.g. auto-follow tags. * cc/upload-pack-v2-fetch-fix: upload-pack: clear filter_options for each v2 fetch command
2 parents ce1adb1 + 08450ef commit a012588

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

t/t5616-partial-clone.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,11 @@ test_expect_success 'fetch lazy-fetches only to resolve deltas, protocol v2' '
384384
grep "want $(cat hash)" trace
385385
'
386386

387-
# The following two tests must be in this order, or else
388-
# the first will not fail. It is important that the srv.bare
389-
# repository did not have tags during clone, but has tags
387+
# The following two tests must be in this order. It is important that
388+
# the srv.bare repository did not have tags during clone, but has tags
390389
# in the fetch.
391390

392-
test_expect_failure 'verify fetch succeeds when asking for new tags' '
391+
test_expect_success 'verify fetch succeeds when asking for new tags' '
393392
git clone --filter=blob:none "file://$(pwd)/srv.bare" tag-test &&
394393
for i in I J K
395394
do

upload-pack.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ static const char *pack_objects_hook;
6969
static int filter_capability_requested;
7070
static int allow_filter;
7171
static int allow_ref_in_want;
72-
static struct list_objects_filter_options filter_options;
7372

7473
static int allow_sideband_all;
7574

@@ -104,7 +103,8 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
104103
}
105104

106105
static void create_pack_file(const struct object_array *have_obj,
107-
const struct object_array *want_obj)
106+
const struct object_array *want_obj,
107+
struct list_objects_filter_options *filter_options)
108108
{
109109
struct child_process pack_objects = CHILD_PROCESS_INIT;
110110
char data[8193], progress[128];
@@ -141,9 +141,9 @@ static void create_pack_file(const struct object_array *have_obj,
141141
argv_array_push(&pack_objects.args, "--delta-base-offset");
142142
if (use_include_tag)
143143
argv_array_push(&pack_objects.args, "--include-tag");
144-
if (filter_options.choice) {
144+
if (filter_options->choice) {
145145
const char *spec =
146-
expand_list_objects_filter_spec(&filter_options);
146+
expand_list_objects_filter_spec(filter_options);
147147
if (pack_objects.use_shell) {
148148
struct strbuf buf = STRBUF_INIT;
149149
sq_quote_buf(&buf, spec);
@@ -849,7 +849,9 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,
849849
return 0;
850850
}
851851

852-
static void receive_needs(struct packet_reader *reader, struct object_array *want_obj)
852+
static void receive_needs(struct packet_reader *reader,
853+
struct object_array *want_obj,
854+
struct list_objects_filter_options *filter_options)
853855
{
854856
struct object_array shallows = OBJECT_ARRAY_INIT;
855857
struct string_list deepen_not = STRING_LIST_INIT_DUP;
@@ -884,8 +886,8 @@ static void receive_needs(struct packet_reader *reader, struct object_array *wan
884886
if (skip_prefix(reader->line, "filter ", &arg)) {
885887
if (!filter_capability_requested)
886888
die("git upload-pack: filtering capability not negotiated");
887-
list_objects_filter_die_if_populated(&filter_options);
888-
parse_list_objects_filter(&filter_options, arg);
889+
list_objects_filter_die_if_populated(filter_options);
890+
parse_list_objects_filter(filter_options, arg);
889891
continue;
890892
}
891893

@@ -1088,11 +1090,14 @@ void upload_pack(struct upload_pack_options *options)
10881090
struct string_list symref = STRING_LIST_INIT_DUP;
10891091
struct object_array want_obj = OBJECT_ARRAY_INIT;
10901092
struct packet_reader reader;
1093+
struct list_objects_filter_options filter_options;
10911094

10921095
stateless_rpc = options->stateless_rpc;
10931096
timeout = options->timeout;
10941097
daemon_mode = options->daemon_mode;
10951098

1099+
memset(&filter_options, 0, sizeof(filter_options));
1100+
10961101
git_config(upload_pack_config, NULL);
10971102

10981103
head_ref_namespaced(find_symref, &symref);
@@ -1115,12 +1120,14 @@ void upload_pack(struct upload_pack_options *options)
11151120
PACKET_READ_CHOMP_NEWLINE |
11161121
PACKET_READ_DIE_ON_ERR_PACKET);
11171122

1118-
receive_needs(&reader, &want_obj);
1123+
receive_needs(&reader, &want_obj, &filter_options);
11191124
if (want_obj.nr) {
11201125
struct object_array have_obj = OBJECT_ARRAY_INIT;
11211126
get_common_commits(&reader, &have_obj, &want_obj);
1122-
create_pack_file(&have_obj, &want_obj);
1127+
create_pack_file(&have_obj, &want_obj, &filter_options);
11231128
}
1129+
1130+
list_objects_filter_release(&filter_options);
11241131
}
11251132

11261133
struct upload_pack_data {
@@ -1135,6 +1142,8 @@ struct upload_pack_data {
11351142
int deepen_rev_list;
11361143
int deepen_relative;
11371144

1145+
struct list_objects_filter_options filter_options;
1146+
11381147
struct packet_writer writer;
11391148

11401149
unsigned stateless_rpc : 1;
@@ -1170,6 +1179,7 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
11701179
oid_array_clear(&data->haves);
11711180
object_array_clear(&data->shallows);
11721181
string_list_clear(&data->deepen_not, 0);
1182+
list_objects_filter_release(&data->filter_options);
11731183
}
11741184

11751185
static int parse_want(struct packet_writer *writer, const char *line,
@@ -1307,8 +1317,8 @@ static void process_args(struct packet_reader *request,
13071317
}
13081318

13091319
if (allow_filter && skip_prefix(arg, "filter ", &p)) {
1310-
list_objects_filter_die_if_populated(&filter_options);
1311-
parse_list_objects_filter(&filter_options, p);
1320+
list_objects_filter_die_if_populated(&data->filter_options);
1321+
parse_list_objects_filter(&data->filter_options, p);
13121322
continue;
13131323
}
13141324

@@ -1515,7 +1525,7 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
15151525
send_shallow_info(&data, &want_obj);
15161526

15171527
packet_writer_write(&data.writer, "packfile\n");
1518-
create_pack_file(&have_obj, &want_obj);
1528+
create_pack_file(&have_obj, &want_obj, &data.filter_options);
15191529
state = FETCH_DONE;
15201530
break;
15211531
case FETCH_DONE:

0 commit comments

Comments
 (0)