git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1
@ 2020-05-15 10:04 Christian Couder
  2020-05-15 10:04 ` [PATCH 01/13] upload-pack: remove unused 'wants' from upload_pack_data Christian Couder
                   ` (16 more replies)
  0 siblings, 17 replies; 108+ messages in thread
From: Christian Couder @ 2020-05-15 10:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

In the thread started by:

https://lore.kernel.org/git/20200507095829.16894-1-chriscool@tuxfamily.org/

which led to the following bug fix commit:

08450ef791 (upload-pack: clear filter_options for each v2 fetch
command, 2020-05-08)

it was agreed that having many static variables in 'upload-pack.c',
while upload_pack_v2() is called more than once per process, is very
bug prone and messy, and that a good way forward would be to use
'struct upload_pack_data' thoroughly, especially in upload_pack()
where it isn't used yet.

This patch series is the first part of an effort in this direction.

While there are still a lot of static variables at the top of
'upload-pack.c' after this patch series, it does a lot of ground work
and a number of cleanups.

This patch series is based on master at 172e8ff696 (The ninth batch,
2020-05-13).

Christian Couder (13):
  upload-pack: remove unused 'wants' from upload_pack_data
  upload-pack: move {want,have}_obj to upload_pack_data
  upload-pack: move 'struct upload_pack_data' around
  upload-pack: use 'struct upload_pack_data' in upload_pack()
  upload-pack: pass upload_pack_data to get_common_commits()
  upload-pack: pass upload_pack_data to receive_needs()
  upload-pack: use upload_pack_data writer in receive_needs()
  upload-pack: move symref to upload_pack_data
  upload-pack: pass upload_pack_data to send_ref()
  upload-pack: pass upload_pack_data to check_non_tip()
  upload-pack: remove static variable 'stateless_rpc'
  upload-pack: pass upload_pack_data to create_pack_file()
  upload-pack: use upload_pack_data fields in receive_needs()

 upload-pack.c | 298 ++++++++++++++++++++++++--------------------------
 1 file changed, 145 insertions(+), 153 deletions(-)

-- 
2.26.2.638.gb2c16ea67b.dirty


^ permalink raw reply	[flat|nested] 108+ messages in thread

* [PATCH 01/13] upload-pack: remove unused 'wants' from upload_pack_data
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
@ 2020-05-15 10:04 ` Christian Couder
  2020-05-15 18:03   ` Jeff King
  2020-05-15 10:04 ` [PATCH 02/13] upload-pack: move {want,have}_obj to upload_pack_data Christian Couder
                   ` (15 subsequent siblings)
  16 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-15 10:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's remove 'struct object_array wants' from
'struct upload_pack_data', as it appears to be unused.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 0478bff3e7..9aaf886828 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1131,7 +1131,6 @@ void upload_pack(struct upload_pack_options *options)
 }
 
 struct upload_pack_data {
-	struct object_array wants;
 	struct string_list wanted_refs;
 	struct oid_array haves;
 
@@ -1157,14 +1156,12 @@ struct upload_pack_data {
 
 static void upload_pack_data_init(struct upload_pack_data *data)
 {
-	struct object_array wants = OBJECT_ARRAY_INIT;
 	struct string_list wanted_refs = STRING_LIST_INIT_DUP;
 	struct oid_array haves = OID_ARRAY_INIT;
 	struct object_array shallows = OBJECT_ARRAY_INIT;
 	struct string_list deepen_not = STRING_LIST_INIT_DUP;
 
 	memset(data, 0, sizeof(*data));
-	data->wants = wants;
 	data->wanted_refs = wanted_refs;
 	data->haves = haves;
 	data->shallows = shallows;
@@ -1174,7 +1171,6 @@ static void upload_pack_data_init(struct upload_pack_data *data)
 
 static void upload_pack_data_clear(struct upload_pack_data *data)
 {
-	object_array_clear(&data->wants);
 	string_list_clear(&data->wanted_refs, 1);
 	oid_array_clear(&data->haves);
 	object_array_clear(&data->shallows);
-- 
2.26.2.638.gb2c16ea67b.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 02/13] upload-pack: move {want,have}_obj to upload_pack_data
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
  2020-05-15 10:04 ` [PATCH 01/13] upload-pack: remove unused 'wants' from upload_pack_data Christian Couder
@ 2020-05-15 10:04 ` Christian Couder
  2020-05-15 18:05   ` Jeff King
  2020-05-15 10:04 ` [PATCH 03/13] upload-pack: move 'struct upload_pack_data' around Christian Couder
                   ` (14 subsequent siblings)
  16 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-15 10:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the want_obj and have_obj object
arrays into 'struct upload_pack_data'.

These object arrays are used by both upload_pack() and
upload_pack_v2(), for example when these functions call
create_pack_file(). We are going to use
'struct upload_pack_data' in upload_pack() in a followup
commit.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 48 +++++++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 23 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 9aaf886828..e1b10522f7 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1132,6 +1132,8 @@ void upload_pack(struct upload_pack_options *options)
 
 struct upload_pack_data {
 	struct string_list wanted_refs;
+	struct object_array want_obj;
+	struct object_array have_obj;
 	struct oid_array haves;
 
 	struct object_array shallows;
@@ -1157,12 +1159,16 @@ struct upload_pack_data {
 static void upload_pack_data_init(struct upload_pack_data *data)
 {
 	struct string_list wanted_refs = STRING_LIST_INIT_DUP;
+	struct object_array want_obj = OBJECT_ARRAY_INIT;
+	struct object_array have_obj = OBJECT_ARRAY_INIT;
 	struct oid_array haves = OID_ARRAY_INIT;
 	struct object_array shallows = OBJECT_ARRAY_INIT;
 	struct string_list deepen_not = STRING_LIST_INIT_DUP;
 
 	memset(data, 0, sizeof(*data));
 	data->wanted_refs = wanted_refs;
+	data->want_obj = want_obj;
+	data->have_obj = have_obj;
 	data->haves = haves;
 	data->shallows = shallows;
 	data->deepen_not = deepen_not;
@@ -1172,6 +1178,8 @@ static void upload_pack_data_init(struct upload_pack_data *data)
 static void upload_pack_data_clear(struct upload_pack_data *data)
 {
 	string_list_clear(&data->wanted_refs, 1);
+	object_array_clear(&data->want_obj);
+	object_array_clear(&data->have_obj);
 	oid_array_clear(&data->haves);
 	object_array_clear(&data->shallows);
 	string_list_clear(&data->deepen_not, 0);
@@ -1256,19 +1264,18 @@ static int parse_have(const char *line, struct oid_array *haves)
 }
 
 static void process_args(struct packet_reader *request,
-			 struct upload_pack_data *data,
-			 struct object_array *want_obj)
+			 struct upload_pack_data *data)
 {
 	while (packet_reader_read(request) == PACKET_READ_NORMAL) {
 		const char *arg = request->line;
 		const char *p;
 
 		/* process want */
-		if (parse_want(&data->writer, arg, want_obj))
+		if (parse_want(&data->writer, arg, &data->want_obj))
 			continue;
 		if (allow_ref_in_want &&
 		    parse_want_ref(&data->writer, arg, &data->wanted_refs,
-				   want_obj))
+				   &data->want_obj))
 			continue;
 		/* process have line */
 		if (parse_have(arg, &data->haves))
@@ -1399,17 +1406,16 @@ static int send_acks(struct packet_writer *writer, struct oid_array *acks,
 	return 0;
 }
 
-static int process_haves_and_send_acks(struct upload_pack_data *data,
-				       struct object_array *have_obj,
-				       struct object_array *want_obj)
+static int process_haves_and_send_acks(struct upload_pack_data *data)
 {
 	struct oid_array common = OID_ARRAY_INIT;
 	int ret = 0;
 
-	process_haves(&data->haves, &common, have_obj);
+	process_haves(&data->haves, &common, &data->have_obj);
 	if (data->done) {
 		ret = 1;
-	} else if (send_acks(&data->writer, &common, have_obj, want_obj)) {
+	} else if (send_acks(&data->writer, &common,
+			     &data->have_obj, &data->want_obj)) {
 		packet_writer_delim(&data->writer);
 		ret = 1;
 	} else {
@@ -1441,8 +1447,7 @@ static void send_wanted_ref_info(struct upload_pack_data *data)
 	packet_writer_delim(&data->writer);
 }
 
-static void send_shallow_info(struct upload_pack_data *data,
-			      struct object_array *want_obj)
+static void send_shallow_info(struct upload_pack_data *data)
 {
 	/* No shallow info needs to be sent */
 	if (!data->depth && !data->deepen_rev_list && !data->shallows.nr &&
@@ -1455,10 +1460,10 @@ static void send_shallow_info(struct upload_pack_data *data,
 			       data->deepen_rev_list,
 			       data->deepen_since, &data->deepen_not,
 			       data->deepen_relative,
-			       &data->shallows, want_obj) &&
+			       &data->shallows, &data->want_obj) &&
 	    is_repository_shallow(the_repository))
 		deepen(&data->writer, INFINITE_DEPTH, data->deepen_relative,
-		       &data->shallows, want_obj);
+		       &data->shallows, &data->want_obj);
 
 	packet_delim(1);
 }
@@ -1475,8 +1480,6 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
 {
 	enum fetch_state state = FETCH_PROCESS_ARGS;
 	struct upload_pack_data data;
-	struct object_array have_obj = OBJECT_ARRAY_INIT;
-	struct object_array want_obj = OBJECT_ARRAY_INIT;
 
 	clear_object_flags(ALL_FLAGS);
 
@@ -1488,9 +1491,9 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
 	while (state != FETCH_DONE) {
 		switch (state) {
 		case FETCH_PROCESS_ARGS:
-			process_args(request, &data, &want_obj);
+			process_args(request, &data);
 
-			if (!want_obj.nr) {
+			if (!data.want_obj.nr) {
 				/*
 				 * Request didn't contain any 'want' lines,
 				 * guess they didn't want anything.
@@ -1510,18 +1513,19 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
 			}
 			break;
 		case FETCH_SEND_ACKS:
-			if (process_haves_and_send_acks(&data, &have_obj,
-							&want_obj))
+			if (process_haves_and_send_acks(&data))
 				state = FETCH_SEND_PACK;
 			else
 				state = FETCH_DONE;
 			break;
 		case FETCH_SEND_PACK:
 			send_wanted_ref_info(&data);
-			send_shallow_info(&data, &want_obj);
+			send_shallow_info(&data);
 
 			packet_writer_write(&data.writer, "packfile\n");
-			create_pack_file(&have_obj, &want_obj, &data.filter_options);
+			create_pack_file(&data.have_obj,
+					 &data.want_obj,
+					 &data.filter_options);
 			state = FETCH_DONE;
 			break;
 		case FETCH_DONE:
@@ -1530,8 +1534,6 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
 	}
 
 	upload_pack_data_clear(&data);
-	object_array_clear(&have_obj);
-	object_array_clear(&want_obj);
 	return 0;
 }
 
-- 
2.26.2.638.gb2c16ea67b.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 03/13] upload-pack: move 'struct upload_pack_data' around
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
  2020-05-15 10:04 ` [PATCH 01/13] upload-pack: remove unused 'wants' from upload_pack_data Christian Couder
  2020-05-15 10:04 ` [PATCH 02/13] upload-pack: move {want,have}_obj to upload_pack_data Christian Couder
@ 2020-05-15 10:04 ` Christian Couder
  2020-05-15 18:05   ` Jeff King
  2020-05-15 10:04 ` [PATCH 04/13] upload-pack: use 'struct upload_pack_data' in upload_pack() Christian Couder
                   ` (13 subsequent siblings)
  16 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-15 10:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move 'struct upload_pack_data' and the
related upload_pack_data_init() and upload_pack_data_clear()
functions towards the beginning of the file, so that this struct
and its related functions can then be used by upload_pack() in a
followup commit.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 112 +++++++++++++++++++++++++-------------------------
 1 file changed, 56 insertions(+), 56 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index e1b10522f7..9aeb3477c9 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -72,6 +72,62 @@ static int allow_ref_in_want;
 
 static int allow_sideband_all;
 
+struct upload_pack_data {
+	struct string_list wanted_refs;
+	struct object_array want_obj;
+	struct object_array have_obj;
+	struct oid_array haves;
+
+	struct object_array shallows;
+	struct string_list deepen_not;
+	int depth;
+	timestamp_t deepen_since;
+	int deepen_rev_list;
+	int deepen_relative;
+
+	struct list_objects_filter_options filter_options;
+
+	struct packet_writer writer;
+
+	unsigned stateless_rpc : 1;
+
+	unsigned use_thin_pack : 1;
+	unsigned use_ofs_delta : 1;
+	unsigned no_progress : 1;
+	unsigned use_include_tag : 1;
+	unsigned done : 1;
+};
+
+static void upload_pack_data_init(struct upload_pack_data *data)
+{
+	struct string_list wanted_refs = STRING_LIST_INIT_DUP;
+	struct object_array want_obj = OBJECT_ARRAY_INIT;
+	struct object_array have_obj = OBJECT_ARRAY_INIT;
+	struct oid_array haves = OID_ARRAY_INIT;
+	struct object_array shallows = OBJECT_ARRAY_INIT;
+	struct string_list deepen_not = STRING_LIST_INIT_DUP;
+
+	memset(data, 0, sizeof(*data));
+	data->wanted_refs = wanted_refs;
+	data->want_obj = want_obj;
+	data->have_obj = have_obj;
+	data->haves = haves;
+	data->shallows = shallows;
+	data->deepen_not = deepen_not;
+	packet_writer_init(&data->writer, 1);
+}
+
+static void upload_pack_data_clear(struct upload_pack_data *data)
+{
+	string_list_clear(&data->wanted_refs, 1);
+	object_array_clear(&data->want_obj);
+	object_array_clear(&data->have_obj);
+	oid_array_clear(&data->haves);
+	object_array_clear(&data->shallows);
+	string_list_clear(&data->deepen_not, 0);
+	list_objects_filter_release(&data->filter_options);
+}
+
 static void reset_timeout(void)
 {
 	alarm(timeout);
@@ -1130,62 +1186,6 @@ void upload_pack(struct upload_pack_options *options)
 	list_objects_filter_release(&filter_options);
 }
 
-struct upload_pack_data {
-	struct string_list wanted_refs;
-	struct object_array want_obj;
-	struct object_array have_obj;
-	struct oid_array haves;
-
-	struct object_array shallows;
-	struct string_list deepen_not;
-	int depth;
-	timestamp_t deepen_since;
-	int deepen_rev_list;
-	int deepen_relative;
-
-	struct list_objects_filter_options filter_options;
-
-	struct packet_writer writer;
-
-	unsigned stateless_rpc : 1;
-
-	unsigned use_thin_pack : 1;
-	unsigned use_ofs_delta : 1;
-	unsigned no_progress : 1;
-	unsigned use_include_tag : 1;
-	unsigned done : 1;
-};
-
-static void upload_pack_data_init(struct upload_pack_data *data)
-{
-	struct string_list wanted_refs = STRING_LIST_INIT_DUP;
-	struct object_array want_obj = OBJECT_ARRAY_INIT;
-	struct object_array have_obj = OBJECT_ARRAY_INIT;
-	struct oid_array haves = OID_ARRAY_INIT;
-	struct object_array shallows = OBJECT_ARRAY_INIT;
-	struct string_list deepen_not = STRING_LIST_INIT_DUP;
-
-	memset(data, 0, sizeof(*data));
-	data->wanted_refs = wanted_refs;
-	data->want_obj = want_obj;
-	data->have_obj = have_obj;
-	data->haves = haves;
-	data->shallows = shallows;
-	data->deepen_not = deepen_not;
-	packet_writer_init(&data->writer, 1);
-}
-
-static void upload_pack_data_clear(struct upload_pack_data *data)
-{
-	string_list_clear(&data->wanted_refs, 1);
-	object_array_clear(&data->want_obj);
-	object_array_clear(&data->have_obj);
-	oid_array_clear(&data->haves);
-	object_array_clear(&data->shallows);
-	string_list_clear(&data->deepen_not, 0);
-	list_objects_filter_release(&data->filter_options);
-}
-
 static int parse_want(struct packet_writer *writer, const char *line,
 		      struct object_array *want_obj)
 {
-- 
2.26.2.638.gb2c16ea67b.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 04/13] upload-pack: use 'struct upload_pack_data' in upload_pack()
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
                   ` (2 preceding siblings ...)
  2020-05-15 10:04 ` [PATCH 03/13] upload-pack: move 'struct upload_pack_data' around Christian Couder
@ 2020-05-15 10:04 ` Christian Couder
  2020-05-15 10:30   ` Derrick Stolee
  2020-05-15 10:04 ` [PATCH 05/13] upload-pack: pass upload_pack_data to get_common_commits() Christian Couder
                   ` (12 subsequent siblings)
  16 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-15 10:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's use 'struct upload_pack_data' in
upload_pack().

This will make it possible in followup commits to remove a lot
of static variables and local variables that have the same name
and purpose as fields in 'struct upload_pack_data'. This will
also make upload_pack() work in a more similar way as
upload_pack_v2().

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 9aeb3477c9..cb336c5713 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1144,18 +1144,17 @@ static int upload_pack_config(const char *var, const char *value, void *unused)
 void upload_pack(struct upload_pack_options *options)
 {
 	struct string_list symref = STRING_LIST_INIT_DUP;
-	struct object_array want_obj = OBJECT_ARRAY_INIT;
 	struct packet_reader reader;
-	struct list_objects_filter_options filter_options;
+	struct upload_pack_data data;
 
 	stateless_rpc = options->stateless_rpc;
 	timeout = options->timeout;
 	daemon_mode = options->daemon_mode;
 
-	memset(&filter_options, 0, sizeof(filter_options));
-
 	git_config(upload_pack_config, NULL);
 
+	upload_pack_data_init(&data);
+
 	head_ref_namespaced(find_symref, &symref);
 
 	if (options->advertise_refs || !stateless_rpc) {
@@ -1169,21 +1168,24 @@ void upload_pack(struct upload_pack_options *options)
 		for_each_namespaced_ref(check_ref, NULL);
 	}
 	string_list_clear(&symref, 1);
-	if (options->advertise_refs)
-		return;
 
-	packet_reader_init(&reader, 0, NULL, 0,
-			   PACKET_READ_CHOMP_NEWLINE |
-			   PACKET_READ_DIE_ON_ERR_PACKET);
+	if (!options->advertise_refs) {
+		packet_reader_init(&reader, 0, NULL, 0,
+				   PACKET_READ_CHOMP_NEWLINE |
+				   PACKET_READ_DIE_ON_ERR_PACKET);
 
-	receive_needs(&reader, &want_obj, &filter_options);
-	if (want_obj.nr) {
-		struct object_array have_obj = OBJECT_ARRAY_INIT;
-		get_common_commits(&reader, &have_obj, &want_obj);
-		create_pack_file(&have_obj, &want_obj, &filter_options);
+		receive_needs(&reader, &data.want_obj, &data.filter_options);
+		if (data.want_obj.nr) {
+			get_common_commits(&reader,
+					   &data.have_obj,
+					   &data.want_obj);
+			create_pack_file(&data.have_obj,
+					 &data.want_obj,
+					 &data.filter_options);
+		}
 	}
 
-	list_objects_filter_release(&filter_options);
+	upload_pack_data_clear(&data);
 }
 
 static int parse_want(struct packet_writer *writer, const char *line,
-- 
2.26.2.638.gb2c16ea67b.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 05/13] upload-pack: pass upload_pack_data to get_common_commits()
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
                   ` (3 preceding siblings ...)
  2020-05-15 10:04 ` [PATCH 04/13] upload-pack: use 'struct upload_pack_data' in upload_pack() Christian Couder
@ 2020-05-15 10:04 ` Christian Couder
  2020-05-15 18:17   ` Jeff King
  2020-05-15 10:04 ` [PATCH 06/13] upload-pack: pass upload_pack_data to receive_needs() Christian Couder
                   ` (11 subsequent siblings)
  16 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-15 10:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass 'struct upload_pack_data' to
get_common_commits(), so that this function and the functions
it calls can use all the fields of that struct in followup
commits.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index cb336c5713..7953a33189 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -414,9 +414,8 @@ static int ok_to_give_up(const struct object_array *have_obj,
 					    min_generation);
 }
 
-static int get_common_commits(struct packet_reader *reader,
-			      struct object_array *have_obj,
-			      struct object_array *want_obj)
+static int get_common_commits(struct upload_pack_data *data,
+			      struct packet_reader *reader)
 {
 	struct object_id oid;
 	char last_hex[GIT_MAX_HEXSZ + 1];
@@ -432,12 +431,14 @@ static int get_common_commits(struct packet_reader *reader,
 		reset_timeout();
 
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
-			if (multi_ack == 2 && got_common
-			    && !got_other && ok_to_give_up(have_obj, want_obj)) {
+			if (multi_ack == 2
+			    && got_common
+			    && !got_other
+			    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
 				sent_ready = 1;
 				packet_write_fmt(1, "ACK %s ready\n", last_hex);
 			}
-			if (have_obj->nr == 0 || multi_ack)
+			if (data->have_obj.nr == 0 || multi_ack)
 				packet_write_fmt(1, "NAK\n");
 
 			if (no_done && sent_ready) {
@@ -451,10 +452,11 @@ static int get_common_commits(struct packet_reader *reader,
 			continue;
 		}
 		if (skip_prefix(reader->line, "have ", &arg)) {
-			switch (got_oid(arg, &oid, have_obj)) {
+			switch (got_oid(arg, &oid, &data->have_obj)) {
 			case -1: /* they have what we do not */
 				got_other = 1;
-				if (multi_ack && ok_to_give_up(have_obj, want_obj)) {
+				if (multi_ack
+				    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
 					const char *hex = oid_to_hex(&oid);
 					if (multi_ack == 2) {
 						sent_ready = 1;
@@ -470,14 +472,14 @@ static int get_common_commits(struct packet_reader *reader,
 					packet_write_fmt(1, "ACK %s common\n", last_hex);
 				else if (multi_ack)
 					packet_write_fmt(1, "ACK %s continue\n", last_hex);
-				else if (have_obj->nr == 1)
+				else if (data->have_obj.nr == 1)
 					packet_write_fmt(1, "ACK %s\n", last_hex);
 				break;
 			}
 			continue;
 		}
 		if (!strcmp(reader->line, "done")) {
-			if (have_obj->nr > 0) {
+			if (data->have_obj.nr > 0) {
 				if (multi_ack)
 					packet_write_fmt(1, "ACK %s\n", last_hex);
 				return 0;
@@ -1176,9 +1178,7 @@ void upload_pack(struct upload_pack_options *options)
 
 		receive_needs(&reader, &data.want_obj, &data.filter_options);
 		if (data.want_obj.nr) {
-			get_common_commits(&reader,
-					   &data.have_obj,
-					   &data.want_obj);
+			get_common_commits(&data, &reader);
 			create_pack_file(&data.have_obj,
 					 &data.want_obj,
 					 &data.filter_options);
-- 
2.26.2.638.gb2c16ea67b.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 06/13] upload-pack: pass upload_pack_data to receive_needs()
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
                   ` (4 preceding siblings ...)
  2020-05-15 10:04 ` [PATCH 05/13] upload-pack: pass upload_pack_data to get_common_commits() Christian Couder
@ 2020-05-15 10:04 ` Christian Couder
  2020-05-15 18:20   ` Jeff King
  2020-05-15 10:04 ` [PATCH 07/13] upload-pack: use upload_pack_data writer in receive_needs() Christian Couder
                   ` (10 subsequent siblings)
  16 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-15 10:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass 'struct upload_pack_data' to
receive_needs(), so that this function and the functions it
calls can use all the fields of that struct in followup commits.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 7953a33189..94bf9cd088 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -907,9 +907,8 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,
 	return 0;
 }
 
-static void receive_needs(struct packet_reader *reader,
-			  struct object_array *want_obj,
-			  struct list_objects_filter_options *filter_options)
+static void receive_needs(struct upload_pack_data *data,
+			  struct packet_reader *reader)
 {
 	struct object_array shallows = OBJECT_ARRAY_INIT;
 	struct string_list deepen_not = STRING_LIST_INIT_DUP;
@@ -944,8 +943,8 @@ static void receive_needs(struct packet_reader *reader,
 		if (skip_prefix(reader->line, "filter ", &arg)) {
 			if (!filter_capability_requested)
 				die("git upload-pack: filtering capability not negotiated");
-			list_objects_filter_die_if_populated(filter_options);
-			parse_list_objects_filter(filter_options, arg);
+			list_objects_filter_die_if_populated(&data->filter_options);
+			parse_list_objects_filter(&data->filter_options, arg);
 			continue;
 		}
 
@@ -990,7 +989,7 @@ static void receive_needs(struct packet_reader *reader,
 			if (!((allow_unadvertised_object_request & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1
 			      || is_our_ref(o)))
 				has_non_tip = 1;
-			add_object_array(o, NULL, want_obj);
+			add_object_array(o, NULL, &data->want_obj);
 		}
 	}
 
@@ -1002,7 +1001,7 @@ static void receive_needs(struct packet_reader *reader,
 	 * by another process that handled the initial request.
 	 */
 	if (has_non_tip)
-		check_non_tip(want_obj, &writer);
+		check_non_tip(&data->want_obj, &writer);
 
 	if (!use_sideband && daemon_mode)
 		no_progress = 1;
@@ -1012,7 +1011,7 @@ static void receive_needs(struct packet_reader *reader,
 
 	if (send_shallow_list(&writer, depth, deepen_rev_list, deepen_since,
 			      &deepen_not, deepen_relative, &shallows,
-			      want_obj))
+			      &data->want_obj))
 		packet_flush(1);
 	object_array_clear(&shallows);
 }
@@ -1176,7 +1175,7 @@ void upload_pack(struct upload_pack_options *options)
 				   PACKET_READ_CHOMP_NEWLINE |
 				   PACKET_READ_DIE_ON_ERR_PACKET);
 
-		receive_needs(&reader, &data.want_obj, &data.filter_options);
+		receive_needs(&data, &reader);
 		if (data.want_obj.nr) {
 			get_common_commits(&data, &reader);
 			create_pack_file(&data.have_obj,
-- 
2.26.2.638.gb2c16ea67b.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 07/13] upload-pack: use upload_pack_data writer in receive_needs()
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
                   ` (5 preceding siblings ...)
  2020-05-15 10:04 ` [PATCH 06/13] upload-pack: pass upload_pack_data to receive_needs() Christian Couder
@ 2020-05-15 10:04 ` Christian Couder
  2020-05-15 18:23   ` Jeff King
  2020-05-15 10:04 ` [PATCH 08/13] upload-pack: move symref to upload_pack_data Christian Couder
                   ` (9 subsequent siblings)
  16 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-15 10:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's use the 'struct packet_writer writer'
field from 'struct upload_pack_data' in receive_needs(),
instead of a local 'struct packet_writer writer' variable.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 94bf9cd088..399ec60ade 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -917,10 +917,8 @@ static void receive_needs(struct upload_pack_data *data,
 	timestamp_t deepen_since = 0;
 	int deepen_rev_list = 0;
 	int deepen_relative = 0;
-	struct packet_writer writer;
 
 	shallow_nr = 0;
-	packet_writer_init(&writer, 1);
 	for (;;) {
 		struct object *o;
 		const char *features;
@@ -978,7 +976,7 @@ static void receive_needs(struct upload_pack_data *data,
 
 		o = parse_object(the_repository, &oid_buf);
 		if (!o) {
-			packet_writer_error(&writer,
+			packet_writer_error(&data->writer,
 					    "upload-pack: not our ref %s",
 					    oid_to_hex(&oid_buf));
 			die("git upload-pack: not our ref %s",
@@ -1001,7 +999,7 @@ static void receive_needs(struct upload_pack_data *data,
 	 * by another process that handled the initial request.
 	 */
 	if (has_non_tip)
-		check_non_tip(&data->want_obj, &writer);
+		check_non_tip(&data->want_obj, &data->writer);
 
 	if (!use_sideband && daemon_mode)
 		no_progress = 1;
@@ -1009,7 +1007,7 @@ static void receive_needs(struct upload_pack_data *data,
 	if (depth == 0 && !deepen_rev_list && shallows.nr == 0)
 		return;
 
-	if (send_shallow_list(&writer, depth, deepen_rev_list, deepen_since,
+	if (send_shallow_list(&data->writer, depth, deepen_rev_list, deepen_since,
 			      &deepen_not, deepen_relative, &shallows,
 			      &data->want_obj))
 		packet_flush(1);
-- 
2.26.2.638.gb2c16ea67b.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 08/13] upload-pack: move symref to upload_pack_data
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
                   ` (6 preceding siblings ...)
  2020-05-15 10:04 ` [PATCH 07/13] upload-pack: use upload_pack_data writer in receive_needs() Christian Couder
@ 2020-05-15 10:04 ` Christian Couder
  2020-05-15 18:28   ` Jeff King
  2020-05-15 10:04 ` [PATCH 09/13] upload-pack: pass upload_pack_data to send_ref() Christian Couder
                   ` (8 subsequent siblings)
  16 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-15 10:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, we are passing around that struct to many
functions, so let's also pass 'struct string_list symref' around
at the same time by moving it from a local variable in
upload_pack() into a field of 'struct upload_pack_data'.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 399ec60ade..c7e35a7fc9 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -73,6 +73,7 @@ static int allow_ref_in_want;
 static int allow_sideband_all;
 
 struct upload_pack_data {
+	struct string_list symref;
 	struct string_list wanted_refs;
 	struct object_array want_obj;
 	struct object_array have_obj;
@@ -100,6 +101,7 @@ struct upload_pack_data {
 
 static void upload_pack_data_init(struct upload_pack_data *data)
 {
+	struct string_list symref = STRING_LIST_INIT_DUP;
 	struct string_list wanted_refs = STRING_LIST_INIT_DUP;
 	struct object_array want_obj = OBJECT_ARRAY_INIT;
 	struct object_array have_obj = OBJECT_ARRAY_INIT;
@@ -108,6 +110,7 @@ static void upload_pack_data_init(struct upload_pack_data *data)
 	struct string_list deepen_not = STRING_LIST_INIT_DUP;
 
 	memset(data, 0, sizeof(*data));
+	data->symref = symref;
 	data->wanted_refs = wanted_refs;
 	data->want_obj = want_obj;
 	data->have_obj = have_obj;
@@ -119,6 +122,7 @@ static void upload_pack_data_init(struct upload_pack_data *data)
 
 static void upload_pack_data_clear(struct upload_pack_data *data)
 {
+	string_list_clear(&data->symref, 1);
 	string_list_clear(&data->wanted_refs, 1);
 	object_array_clear(&data->want_obj);
 	object_array_clear(&data->have_obj);
@@ -1142,7 +1146,6 @@ static int upload_pack_config(const char *var, const char *value, void *unused)
 
 void upload_pack(struct upload_pack_options *options)
 {
-	struct string_list symref = STRING_LIST_INIT_DUP;
 	struct packet_reader reader;
 	struct upload_pack_data data;
 
@@ -1154,19 +1157,18 @@ void upload_pack(struct upload_pack_options *options)
 
 	upload_pack_data_init(&data);
 
-	head_ref_namespaced(find_symref, &symref);
+	head_ref_namespaced(find_symref, &data.symref);
 
 	if (options->advertise_refs || !stateless_rpc) {
 		reset_timeout();
-		head_ref_namespaced(send_ref, &symref);
-		for_each_namespaced_ref(send_ref, &symref);
+		head_ref_namespaced(send_ref, &data.symref);
+		for_each_namespaced_ref(send_ref, &data.symref);
 		advertise_shallow_grafts(1);
 		packet_flush(1);
 	} else {
 		head_ref_namespaced(check_ref, NULL);
 		for_each_namespaced_ref(check_ref, NULL);
 	}
-	string_list_clear(&symref, 1);
 
 	if (!options->advertise_refs) {
 		packet_reader_init(&reader, 0, NULL, 0,
-- 
2.26.2.638.gb2c16ea67b.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 09/13] upload-pack: pass upload_pack_data to send_ref()
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
                   ` (7 preceding siblings ...)
  2020-05-15 10:04 ` [PATCH 08/13] upload-pack: move symref to upload_pack_data Christian Couder
@ 2020-05-15 10:04 ` Christian Couder
  2020-05-15 18:33   ` Jeff King
  2020-05-15 10:04 ` [PATCH 10/13] upload-pack: pass upload_pack_data to check_non_tip() Christian Couder
                   ` (7 subsequent siblings)
  16 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-15 10:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass that struct to send_ref(), so that
this function, and the functions it calls, can use all the
fields of the struct in followup commits.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index c7e35a7fc9..bc259f1713 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1059,6 +1059,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
 		" deepen-relative no-progress include-tag multi_ack_detailed";
 	const char *refname_nons = strip_namespace(refname);
 	struct object_id peeled;
+	struct upload_pack_data *data = cb_data;
 
 	if (mark_our_ref(refname_nons, refname, oid))
 		return 0;
@@ -1066,7 +1067,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
 	if (capabilities) {
 		struct strbuf symref_info = STRBUF_INIT;
 
-		format_symref_info(&symref_info, cb_data);
+		format_symref_info(&symref_info, &data->symref);
 		packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s agent=%s\n",
 			     oid_to_hex(oid), refname_nons,
 			     0, capabilities,
@@ -1161,8 +1162,8 @@ void upload_pack(struct upload_pack_options *options)
 
 	if (options->advertise_refs || !stateless_rpc) {
 		reset_timeout();
-		head_ref_namespaced(send_ref, &data.symref);
-		for_each_namespaced_ref(send_ref, &data.symref);
+		head_ref_namespaced(send_ref, &data);
+		for_each_namespaced_ref(send_ref, &data);
 		advertise_shallow_grafts(1);
 		packet_flush(1);
 	} else {
-- 
2.26.2.638.gb2c16ea67b.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 10/13] upload-pack: pass upload_pack_data to check_non_tip()
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
                   ` (8 preceding siblings ...)
  2020-05-15 10:04 ` [PATCH 09/13] upload-pack: pass upload_pack_data to send_ref() Christian Couder
@ 2020-05-15 10:04 ` Christian Couder
  2020-05-15 10:04 ` [PATCH 11/13] upload-pack: remove static variable 'stateless_rpc' Christian Couder
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-05-15 10:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass that struct to check_non_tip(), so
that this function and the functions it calls, can use all the
fields of the struct in followup commits.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index bc259f1713..680c38cc13 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -654,8 +654,7 @@ static int has_unreachable(struct object_array *src)
 	return 1;
 }
 
-static void check_non_tip(struct object_array *want_obj,
-			  struct packet_writer *writer)
+static void check_non_tip(struct upload_pack_data *data)
 {
 	int i;
 
@@ -666,16 +665,16 @@ static void check_non_tip(struct object_array *want_obj,
 	 */
 	if (!stateless_rpc && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
 		goto error;
-	if (!has_unreachable(want_obj))
+	if (!has_unreachable(&data->want_obj))
 		/* All the non-tip ones are ancestors of what we advertised */
 		return;
 
 error:
 	/* Pick one of them (we know there at least is one) */
-	for (i = 0; i < want_obj->nr; i++) {
-		struct object *o = want_obj->objects[i].item;
+	for (i = 0; i < data->want_obj.nr; i++) {
+		struct object *o = data->want_obj.objects[i].item;
 		if (!is_our_ref(o)) {
-			packet_writer_error(writer,
+			packet_writer_error(&data->writer,
 					    "upload-pack: not our ref %s",
 					    oid_to_hex(&o->oid));
 			die("git upload-pack: not our ref %s",
@@ -1003,7 +1002,7 @@ static void receive_needs(struct upload_pack_data *data,
 	 * by another process that handled the initial request.
 	 */
 	if (has_non_tip)
-		check_non_tip(&data->want_obj, &data->writer);
+		check_non_tip(data);
 
 	if (!use_sideband && daemon_mode)
 		no_progress = 1;
-- 
2.26.2.638.gb2c16ea67b.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 11/13] upload-pack: remove static variable 'stateless_rpc'
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
                   ` (9 preceding siblings ...)
  2020-05-15 10:04 ` [PATCH 10/13] upload-pack: pass upload_pack_data to check_non_tip() Christian Couder
@ 2020-05-15 10:04 ` Christian Couder
  2020-05-15 18:38   ` Jeff King
  2020-05-15 10:04 ` [PATCH 12/13] upload-pack: pass upload_pack_data to create_pack_file() Christian Couder
                   ` (5 subsequent siblings)
  16 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-15 10:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's remove the 'stateless_rpc' static
variable, as we can now use the field of 'struct upload_pack_data'
with the same name instead.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 680c38cc13..4ac40c5b04 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -63,7 +63,6 @@ static int keepalive = 5;
  * otherwise maximum packet size (up to 65520 bytes).
  */
 static int use_sideband;
-static int stateless_rpc;
 static const char *pack_objects_hook;
 
 static int filter_capability_requested;
@@ -449,7 +448,7 @@ static int get_common_commits(struct upload_pack_data *data,
 				packet_write_fmt(1, "ACK %s\n", last_hex);
 				return 0;
 			}
-			if (stateless_rpc)
+			if (data->stateless_rpc)
 				exit(0);
 			got_common = 0;
 			got_other = 0;
@@ -663,7 +662,8 @@ static void check_non_tip(struct upload_pack_data *data)
 	 * uploadpack.allowReachableSHA1InWant,
 	 * non-tip requests can never happen.
 	 */
-	if (!stateless_rpc && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
+	if (!data->stateless_rpc
+	    && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
 		goto error;
 	if (!has_unreachable(&data->want_obj))
 		/* All the non-tip ones are ancestors of what we advertised */
@@ -1074,7 +1074,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
 				     " allow-tip-sha1-in-want" : "",
 			     (allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ?
 				     " allow-reachable-sha1-in-want" : "",
-			     stateless_rpc ? " no-done" : "",
+			     data->stateless_rpc ? " no-done" : "",
 			     symref_info.buf,
 			     allow_filter ? " filter" : "",
 			     git_user_agent_sanitized());
@@ -1149,7 +1149,6 @@ void upload_pack(struct upload_pack_options *options)
 	struct packet_reader reader;
 	struct upload_pack_data data;
 
-	stateless_rpc = options->stateless_rpc;
 	timeout = options->timeout;
 	daemon_mode = options->daemon_mode;
 
@@ -1157,9 +1156,11 @@ void upload_pack(struct upload_pack_options *options)
 
 	upload_pack_data_init(&data);
 
+	data.stateless_rpc = options->stateless_rpc;
+
 	head_ref_namespaced(find_symref, &data.symref);
 
-	if (options->advertise_refs || !stateless_rpc) {
+	if (options->advertise_refs || !data.stateless_rpc) {
 		reset_timeout();
 		head_ref_namespaced(send_ref, &data);
 		for_each_namespaced_ref(send_ref, &data);
-- 
2.26.2.638.gb2c16ea67b.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 12/13] upload-pack: pass upload_pack_data to create_pack_file()
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
                   ` (10 preceding siblings ...)
  2020-05-15 10:04 ` [PATCH 11/13] upload-pack: remove static variable 'stateless_rpc' Christian Couder
@ 2020-05-15 10:04 ` Christian Couder
  2020-05-15 10:04 ` [PATCH 13/13] upload-pack: use upload_pack_data fields in receive_needs() Christian Couder
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-05-15 10:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass that struct to create_pack_file(),
so that this function, and the function it calls, can use all
the fields of the struct.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 4ac40c5b04..93cf4b1fe5 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -161,9 +161,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
 	return 0;
 }
 
-static void create_pack_file(const struct object_array *have_obj,
-			     const struct object_array *want_obj,
-			     struct list_objects_filter_options *filter_options)
+static void create_pack_file(struct upload_pack_data *pack_data)
 {
 	struct child_process pack_objects = CHILD_PROCESS_INIT;
 	char data[8193], progress[128];
@@ -200,9 +198,9 @@ static void create_pack_file(const struct object_array *have_obj,
 		argv_array_push(&pack_objects.args, "--delta-base-offset");
 	if (use_include_tag)
 		argv_array_push(&pack_objects.args, "--include-tag");
-	if (filter_options->choice) {
+	if (pack_data->filter_options.choice) {
 		const char *spec =
-			expand_list_objects_filter_spec(filter_options);
+			expand_list_objects_filter_spec(&pack_data->filter_options);
 		if (pack_objects.use_shell) {
 			struct strbuf buf = STRBUF_INIT;
 			sq_quote_buf(&buf, spec);
@@ -226,13 +224,13 @@ static void create_pack_file(const struct object_array *have_obj,
 	if (shallow_nr)
 		for_each_commit_graft(write_one_shallow, pipe_fd);
 
-	for (i = 0; i < want_obj->nr; i++)
+	for (i = 0; i < pack_data->want_obj.nr; i++)
 		fprintf(pipe_fd, "%s\n",
-			oid_to_hex(&want_obj->objects[i].item->oid));
+			oid_to_hex(&pack_data->want_obj.objects[i].item->oid));
 	fprintf(pipe_fd, "--not\n");
-	for (i = 0; i < have_obj->nr; i++)
+	for (i = 0; i < pack_data->have_obj.nr; i++)
 		fprintf(pipe_fd, "%s\n",
-			oid_to_hex(&have_obj->objects[i].item->oid));
+			oid_to_hex(&pack_data->have_obj.objects[i].item->oid));
 	for (i = 0; i < extra_edge_obj.nr; i++)
 		fprintf(pipe_fd, "%s\n",
 			oid_to_hex(&extra_edge_obj.objects[i].item->oid));
@@ -1179,9 +1177,7 @@ void upload_pack(struct upload_pack_options *options)
 		receive_needs(&data, &reader);
 		if (data.want_obj.nr) {
 			get_common_commits(&data, &reader);
-			create_pack_file(&data.have_obj,
-					 &data.want_obj,
-					 &data.filter_options);
+			create_pack_file(&data);
 		}
 	}
 
@@ -1525,9 +1521,7 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
 			send_shallow_info(&data);
 
 			packet_writer_write(&data.writer, "packfile\n");
-			create_pack_file(&data.have_obj,
-					 &data.want_obj,
-					 &data.filter_options);
+			create_pack_file(&data);
 			state = FETCH_DONE;
 			break;
 		case FETCH_DONE:
-- 
2.26.2.638.gb2c16ea67b.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 13/13] upload-pack: use upload_pack_data fields in receive_needs()
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
                   ` (11 preceding siblings ...)
  2020-05-15 10:04 ` [PATCH 12/13] upload-pack: pass upload_pack_data to create_pack_file() Christian Couder
@ 2020-05-15 10:04 ` Christian Couder
  2020-05-15 18:42   ` Jeff King
  2020-05-15 10:43 ` [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Derrick Stolee
                   ` (3 subsequent siblings)
  16 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-15 10:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's use fields from this struct in
receive_needs(), instead of local variables with the same name
and purpose.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 93cf4b1fe5..401c9e6c4b 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -911,13 +911,7 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,
 static void receive_needs(struct upload_pack_data *data,
 			  struct packet_reader *reader)
 {
-	struct object_array shallows = OBJECT_ARRAY_INIT;
-	struct string_list deepen_not = STRING_LIST_INIT_DUP;
-	int depth = 0;
 	int has_non_tip = 0;
-	timestamp_t deepen_since = 0;
-	int deepen_rev_list = 0;
-	int deepen_relative = 0;
 
 	shallow_nr = 0;
 	for (;;) {
@@ -930,13 +924,13 @@ static void receive_needs(struct upload_pack_data *data,
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL)
 			break;
 
-		if (process_shallow(reader->line, &shallows))
+		if (process_shallow(reader->line, &data->shallows))
 			continue;
-		if (process_deepen(reader->line, &depth))
+		if (process_deepen(reader->line, &data->depth))
 			continue;
-		if (process_deepen_since(reader->line, &deepen_since, &deepen_rev_list))
+		if (process_deepen_since(reader->line, &data->deepen_since, &data->deepen_rev_list))
 			continue;
-		if (process_deepen_not(reader->line, &deepen_not, &deepen_rev_list))
+		if (process_deepen_not(reader->line, &data->deepen_not, &data->deepen_rev_list))
 			continue;
 
 		if (skip_prefix(reader->line, "filter ", &arg)) {
@@ -953,7 +947,7 @@ static void receive_needs(struct upload_pack_data *data,
 			    "expected to get object ID, not '%s'", reader->line);
 
 		if (parse_feature_request(features, "deepen-relative"))
-			deepen_relative = 1;
+			data->deepen_relative = 1;
 		if (parse_feature_request(features, "multi_ack_detailed"))
 			multi_ack = 2;
 		else if (parse_feature_request(features, "multi_ack"))
@@ -1005,14 +999,18 @@ static void receive_needs(struct upload_pack_data *data,
 	if (!use_sideband && daemon_mode)
 		no_progress = 1;
 
-	if (depth == 0 && !deepen_rev_list && shallows.nr == 0)
+	if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
 		return;
 
-	if (send_shallow_list(&data->writer, depth, deepen_rev_list, deepen_since,
-			      &deepen_not, deepen_relative, &shallows,
+	if (send_shallow_list(&data->writer,
+			      data->depth,
+			      data->deepen_rev_list,
+			      data->deepen_since,
+			      &data->deepen_not,
+			      data->deepen_relative,
+			      &data->shallows,
 			      &data->want_obj))
 		packet_flush(1);
-	object_array_clear(&shallows);
 }
 
 /* return non-zero if the ref is hidden, otherwise 0 */
-- 
2.26.2.638.gb2c16ea67b.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* Re: [PATCH 04/13] upload-pack: use 'struct upload_pack_data' in upload_pack()
  2020-05-15 10:04 ` [PATCH 04/13] upload-pack: use 'struct upload_pack_data' in upload_pack() Christian Couder
@ 2020-05-15 10:30   ` Derrick Stolee
  2020-05-15 18:13     ` Jeff King
  0 siblings, 1 reply; 108+ messages in thread
From: Derrick Stolee @ 2020-05-15 10:30 UTC (permalink / raw)
  To: Christian Couder, git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

On 5/15/2020 6:04 AM, Christian Couder wrote:
> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's use 'struct upload_pack_data' in
> upload_pack().
> 
> This will make it possible in followup commits to remove a lot
> of static variables and local variables that have the same name
> and purpose as fields in 'struct upload_pack_data'. This will
> also make upload_pack() work in a more similar way as
> upload_pack_v2().
> 
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
>  upload-pack.c | 32 +++++++++++++++++---------------
>  1 file changed, 17 insertions(+), 15 deletions(-)
> 
> diff --git a/upload-pack.c b/upload-pack.c
> index 9aeb3477c9..cb336c5713 100644
> --- a/upload-pack.c
> +++ b/upload-pack.c
> @@ -1144,18 +1144,17 @@ static int upload_pack_config(const char *var, const char *value, void *unused)
>  void upload_pack(struct upload_pack_options *options)
>  {
>  	struct string_list symref = STRING_LIST_INIT_DUP;
> -	struct object_array want_obj = OBJECT_ARRAY_INIT;
>  	struct packet_reader reader;
> -	struct list_objects_filter_options filter_options;
> +	struct upload_pack_data data;
>  
>  	stateless_rpc = options->stateless_rpc;
>  	timeout = options->timeout;
>  	daemon_mode = options->daemon_mode;
>  
> -	memset(&filter_options, 0, sizeof(filter_options));
> -

I checked that upload_pack_data_init() runs memset(), which
initializes the memory for data.filter_options. Thanks.

>  	git_config(upload_pack_config, NULL);
>  
> +	upload_pack_data_init(&data);
> +
>  	head_ref_namespaced(find_symref, &symref);
>  
>  	if (options->advertise_refs || !stateless_rpc) {
> @@ -1169,21 +1168,24 @@ void upload_pack(struct upload_pack_options *options)


The control flow below was hard to parse from the diff because
a whitespace line split up the "-" lines and the "+" lines.
I reorder them here:

Old code:

> -	if (options->advertise_refs)
> -		return;
>  
> -	packet_reader_init(&reader, 0, NULL, 0,
> -			   PACKET_READ_CHOMP_NEWLINE |
> -			   PACKET_READ_DIE_ON_ERR_PACKET);
>  
> -	receive_needs(&reader, &want_obj, &filter_options);
> -	if (want_obj.nr) {
> -		struct object_array have_obj = OBJECT_ARRAY_INIT;
> -		get_common_commits(&reader, &have_obj, &want_obj);
> -		create_pack_file(&have_obj, &want_obj, &filter_options);
>	}
> -	list_objects_filter_release(&filter_options);
>  }

New code:

> +	if (!options->advertise_refs) {
> +		packet_reader_init(&reader, 0, NULL, 0,
> +				   PACKET_READ_CHOMP_NEWLINE |
> +				   PACKET_READ_DIE_ON_ERR_PACKET);
>  
> +		receive_needs(&reader, &data.want_obj, &data.filter_options);
> +		if (data.want_obj.nr) {
> +			get_common_commits(&reader,
> +					   &data.have_obj,
> +					   &data.want_obj);
> +			create_pack_file(&data.have_obj,
> +					 &data.want_obj,
> +					 &data.filter_options);
> +		}
>  	}
>  
> +	upload_pack_data_clear(&data);
>  }

The major change is that the "options->advertise_refs" case
now clears the data when before it did not. This seems like
a good change to make.

Also, the code that has now been surrounded by an if block
isn't so large as to justify a "goto cleanup" case.

Thanks,
-Stolee


^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
                   ` (12 preceding siblings ...)
  2020-05-15 10:04 ` [PATCH 13/13] upload-pack: use upload_pack_data fields in receive_needs() Christian Couder
@ 2020-05-15 10:43 ` Derrick Stolee
  2020-05-19  9:49   ` Christian Couder
  2020-05-15 18:47 ` Jeff King
                   ` (2 subsequent siblings)
  16 siblings, 1 reply; 108+ messages in thread
From: Derrick Stolee @ 2020-05-15 10:43 UTC (permalink / raw)
  To: Christian Couder, git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

On 5/15/2020 6:04 AM, Christian Couder wrote:
> In the thread started by:
> 
> https://lore.kernel.org/git/20200507095829.16894-1-chriscool@tuxfamily.org/
> 
> which led to the following bug fix commit:
> 
> 08450ef791 (upload-pack: clear filter_options for each v2 fetch
> command, 2020-05-08)
> 
> it was agreed that having many static variables in 'upload-pack.c',
> while upload_pack_v2() is called more than once per process, is very
> bug prone and messy, and that a good way forward would be to use
> 'struct upload_pack_data' thoroughly, especially in upload_pack()
> where it isn't used yet.
> 
> This patch series is the first part of an effort in this direction.
> 
> While there are still a lot of static variables at the top of
> 'upload-pack.c' after this patch series, it does a lot of ground work
> and a number of cleanups.

The patches here are carefully organized to make review easy. Thanks!

I was surprised to see how many local or static variables you were able
to remove using members that already existed in 'struct upload_pack_data'.
That made the changes here particularly easy to trust.

Reviewed-by: Derrick Stolee <dstolee@microsoft.com>

Thanks,
-Stolee


^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 01/13] upload-pack: remove unused 'wants' from upload_pack_data
  2020-05-15 10:04 ` [PATCH 01/13] upload-pack: remove unused 'wants' from upload_pack_data Christian Couder
@ 2020-05-15 18:03   ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-15 18:03 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 12:04:42PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's remove 'struct object_array wants' from
> 'struct upload_pack_data', as it appears to be unused.

Yep, the diff shows this is clearly not used.

I was a bit curious how it came to be unused, but it was like this from
the very start of that struct being added in 3145ea957d (upload-pack:
introduce fetch server command, 2018-03-15). We don't need it because of
the local want_obj in upload_pack_v2(), but I see you deal with that in
the next commit. Looks good so far.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 02/13] upload-pack: move {want,have}_obj to upload_pack_data
  2020-05-15 10:04 ` [PATCH 02/13] upload-pack: move {want,have}_obj to upload_pack_data Christian Couder
@ 2020-05-15 18:05   ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-15 18:05 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 12:04:43PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's move the want_obj and have_obj object
> arrays into 'struct upload_pack_data'.
> 
> These object arrays are used by both upload_pack() and
> upload_pack_v2(), for example when these functions call
> create_pack_file(). We are going to use
> 'struct upload_pack_data' in upload_pack() in a followup
> commit.

Makes sense. The v2 code path is slightly messier now (having to
dereference "data" more), but this should all pay off later in the
series when we can get rid of v0 globals.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 03/13] upload-pack: move 'struct upload_pack_data' around
  2020-05-15 10:04 ` [PATCH 03/13] upload-pack: move 'struct upload_pack_data' around Christian Couder
@ 2020-05-15 18:05   ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-15 18:05 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 12:04:44PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's move 'struct upload_pack_data' and the
> related upload_pack_data_init() and upload_pack_data_clear()
> functions towards the beginning of the file, so that this struct
> and its related functions can then be used by upload_pack() in a
> followup commit.

Obviously a pure movement (hooray for --color-moved yet again). Looks
good.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 04/13] upload-pack: use 'struct upload_pack_data' in upload_pack()
  2020-05-15 10:30   ` Derrick Stolee
@ 2020-05-15 18:13     ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-15 18:13 UTC (permalink / raw)
  To: Derrick Stolee
  Cc: Christian Couder, git, Junio C Hamano, Derrick Stolee,
	Taylor Blau, Jonathan Tan, Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 06:30:23AM -0400, Derrick Stolee wrote:

> The control flow below was hard to parse from the diff because
> a whitespace line split up the "-" lines and the "+" lines.
> I reorder them here:

Using "-w" improves it a bit, because the packet_reader_init() becomes
an anchor. But sadly the rest is hard to follow because of adding
"data." to each variable reference.

I hoped --patience or --histogram might do better, but they don't. I
think breaking it into a block like you did is the simplest way to see
it.

> The major change is that the "options->advertise_refs" case
> now clears the data when before it did not. This seems like
> a good change to make.

Yeah, I think so, too. It looks like we were simply leaking the filter
options before. I think we still leak the symref list, but it looks like
that will get moved into upload_pack_data in a later patch, too.

So still looking good so far.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 05/13] upload-pack: pass upload_pack_data to get_common_commits()
  2020-05-15 10:04 ` [PATCH 05/13] upload-pack: pass upload_pack_data to get_common_commits() Christian Couder
@ 2020-05-15 18:17   ` Jeff King
  2020-05-15 18:36     ` Jeff King
  0 siblings, 1 reply; 108+ messages in thread
From: Jeff King @ 2020-05-15 18:17 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 12:04:46PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's pass 'struct upload_pack_data' to
> get_common_commits(), so that this function and the functions
> it calls can use all the fields of that struct in followup
> commits.

This one is optional, I think. We're not removing any globals nor moving
towards removing any (I don't think), because we're really just
replacing two object_array parameters with the big data struct:

> -static int get_common_commits(struct packet_reader *reader,
> -			      struct object_array *have_obj,
> -			      struct object_array *want_obj)
> +static int get_common_commits(struct upload_pack_data *data,
> +			      struct packet_reader *reader)

I say "I don't think" because it's possible that get_common_commits()
could use one of the other fields (or pass it to another function) in a
later patch. But I don't see it.

So I think one _could_ argue that it should continue to take the minimum
set of arguments it needs. I doubt it would ever be useful outside of the
context of upload_pack, so I think in practice it doesn't matter much
(beyond perhaps documenting which parts of the global data it needs). So
I don't feel strongly either way.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 06/13] upload-pack: pass upload_pack_data to receive_needs()
  2020-05-15 10:04 ` [PATCH 06/13] upload-pack: pass upload_pack_data to receive_needs() Christian Couder
@ 2020-05-15 18:20   ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-15 18:20 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 12:04:47PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's pass 'struct upload_pack_data' to
> receive_needs(), so that this function and the functions it
> calls can use all the fields of that struct in followup commits.

This is a similar case to the get_common_commits() one, where we replace
specific options with the big struct:

> -static void receive_needs(struct packet_reader *reader,
> -			  struct object_array *want_obj,
> -			  struct list_objects_filter_options *filter_options)
> +static void receive_needs(struct upload_pack_data *data,
> +			  struct packet_reader *reader)

...except that we _do_ later make more use of the big struct. So it
makes sense to me here (and perhaps that also argues that
get_common_commits() should take the big struct as you did, so that all
of these big helper functions have access to it).

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 07/13] upload-pack: use upload_pack_data writer in receive_needs()
  2020-05-15 10:04 ` [PATCH 07/13] upload-pack: use upload_pack_data writer in receive_needs() Christian Couder
@ 2020-05-15 18:23   ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-15 18:23 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 12:04:48PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's use the 'struct packet_writer writer'
> field from 'struct upload_pack_data' in receive_needs(),
> instead of a local 'struct packet_writer writer' variable.

Makes sense. I don't think the writer carries any packet state between
phases that would confuse us by using the same one.

I did wonder how its use_sideband flag works, but it looks like we only
set that in v2 when we see sideband-all. So for v0, it wouldn't affect
us either way.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 08/13] upload-pack: move symref to upload_pack_data
  2020-05-15 10:04 ` [PATCH 08/13] upload-pack: move symref to upload_pack_data Christian Couder
@ 2020-05-15 18:28   ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-15 18:28 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 12:04:49PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, we are passing around that struct to many
> functions, so let's also pass 'struct string_list symref' around
> at the same time by moving it from a local variable in
> upload_pack() into a field of 'struct upload_pack_data'.

Hmm, do we really benefit here at all? The symref list is a local
implementation detail of upload_pack(), and v2 would not use it at all.
Nor does it ever survive past the function in which it's declared.

Perhaps it would help if we were able to send upload_pack_data along to
for_each_ref(), as you do in the next patch, and that let us make use of
upload_pack_data to access other variables. But it doesn't look like we
ever do.

In light of that, is it worth it?

I think we _could_ switch send_ref() (the callback for for_each_ref())
to use the packet-writer struct. Perhaps that would make it worth doing.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 09/13] upload-pack: pass upload_pack_data to send_ref()
  2020-05-15 10:04 ` [PATCH 09/13] upload-pack: pass upload_pack_data to send_ref() Christian Couder
@ 2020-05-15 18:33   ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-15 18:33 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 12:04:50PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's pass that struct to send_ref(), so that
> this function, and the functions it calls, can use all the
> fields of the struct in followup commits.

OK, this is the natural consequence of the previous patch. We could make
use of data->writer, as below, but I don't think it buys us much.

I went looking for other things we could use from upload_pack_data, too.
It looks like some bits like stateless_rpc could be re-used.

-Peff

diff --git a/upload-pack.c b/upload-pack.c
index bc259f1713..7be81c479c 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1068,7 +1068,8 @@ static int send_ref(const char *refname, const struct object_id *oid,
 		struct strbuf symref_info = STRBUF_INIT;
 
 		format_symref_info(&symref_info, &data->symref);
-		packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s agent=%s\n",
+		packet_writer_write(&data->writer,
+			     "%s %s%c%s%s%s%s%s%s agent=%s\n",
 			     oid_to_hex(oid), refname_nons,
 			     0, capabilities,
 			     (allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
@@ -1081,11 +1082,13 @@ static int send_ref(const char *refname, const struct object_id *oid,
 			     git_user_agent_sanitized());
 		strbuf_release(&symref_info);
 	} else {
-		packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), refname_nons);
+		packet_writer_write(&data->writer, "%s %s\n",
+				    oid_to_hex(oid), refname_nons);
 	}
 	capabilities = NULL;
 	if (!peel_ref(refname, &peeled))
-		packet_write_fmt(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
+		packet_writer_write(&data->writer, "%s %s^{}\n",
+				    oid_to_hex(&peeled), refname_nons);
 	return 0;
 }
 

^ permalink raw reply related	[flat|nested] 108+ messages in thread

* Re: [PATCH 05/13] upload-pack: pass upload_pack_data to get_common_commits()
  2020-05-15 18:17   ` Jeff King
@ 2020-05-15 18:36     ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-15 18:36 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 02:17:54PM -0400, Jeff King wrote:

> On Fri, May 15, 2020 at 12:04:46PM +0200, Christian Couder wrote:
> 
> > As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> > more thoroughly, let's pass 'struct upload_pack_data' to
> > get_common_commits(), so that this function and the functions
> > it calls can use all the fields of that struct in followup
> > commits.
> 
> This one is optional, I think. We're not removing any globals nor moving
> towards removing any (I don't think), because we're really just
> replacing two object_array parameters with the big data struct:
> 
> > -static int get_common_commits(struct packet_reader *reader,
> > -			      struct object_array *have_obj,
> > -			      struct object_array *want_obj)
> > +static int get_common_commits(struct upload_pack_data *data,
> > +			      struct packet_reader *reader)
> 
> I say "I don't think" because it's possible that get_common_commits()
> could use one of the other fields (or pass it to another function) in a
> later patch. But I don't see it.
> 
> So I think one _could_ argue that it should continue to take the minimum
> set of arguments it needs. I doubt it would ever be useful outside of the
> context of upload_pack, so I think in practice it doesn't matter much
> (beyond perhaps documenting which parts of the global data it needs). So
> I don't feel strongly either way.

OK, I take it back. I finally go to the spot later in the series where
you use data->stateless_rpc, etc. So I think this is a positive
movement.

I think it might have been easier to review if the changes were made in
the opposite order: globals removed and passed down the call stack, and
then the big struct used to simplify passing the data around. But that
would have been a lot more tedious to write (and perhaps to review, as
I'd have made the opposite complaint ;) ). And definitely not worth
doing now.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 11/13] upload-pack: remove static variable 'stateless_rpc'
  2020-05-15 10:04 ` [PATCH 11/13] upload-pack: remove static variable 'stateless_rpc' Christian Couder
@ 2020-05-15 18:38   ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-15 18:38 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 12:04:52PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's remove the 'stateless_rpc' static
> variable, as we can now use the field of 'struct upload_pack_data'
> with the same name instead.

OK, here's where all of the struct passing in the previous commits
begins to pay off, as we get to start deleting globals:

>  static int use_sideband;
> -static int stateless_rpc;
>  static const char *pack_objects_hook;

Definitely a positive direction, and it should be obvious that all of
the appropriate spots have been converted because the old variable goes
away.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 13/13] upload-pack: use upload_pack_data fields in receive_needs()
  2020-05-15 10:04 ` [PATCH 13/13] upload-pack: use upload_pack_data fields in receive_needs() Christian Couder
@ 2020-05-15 18:42   ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-15 18:42 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 12:04:54PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's use fields from this struct in
> receive_needs(), instead of local variables with the same name
> and purpose.

OK, makes sense. These are purely local in v0, but it's nice for us to
match v2 better (rather than somebody looking at v0 wondering why
data.shallows is never used).

> -	if (send_shallow_list(&data->writer, depth, deepen_rev_list, deepen_since,
> -			      &deepen_not, deepen_relative, &shallows,
> +	if (send_shallow_list(&data->writer,
> +			      data->depth,
> +			      data->deepen_rev_list,
> +			      data->deepen_since,
> +			      &data->deepen_not,
> +			      data->deepen_relative,
> +			      &data->shallows,
>  			      &data->want_obj))
>  		packet_flush(1);
> -	object_array_clear(&shallows);
>  }

We can drop this final cleanup step because it's now covered by
upload_pack_data_clear(). I wondered if any callers would care that we
don't clear it until later, but I guess it couldn't possibly matter:
they would not have had access to this "shallows" variable in the first
place, since it was local.

So this is obviously correct.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
                   ` (13 preceding siblings ...)
  2020-05-15 10:43 ` [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Derrick Stolee
@ 2020-05-15 18:47 ` Jeff King
  2020-05-15 18:55   ` Jeff King
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
  16 siblings, 1 reply; 108+ messages in thread
From: Jeff King @ 2020-05-15 18:47 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 12:04:41PM +0200, Christian Couder wrote:

> In the thread started by:
> 
> https://lore.kernel.org/git/20200507095829.16894-1-chriscool@tuxfamily.org/
> 
> which led to the following bug fix commit:
> 
> 08450ef791 (upload-pack: clear filter_options for each v2 fetch
> command, 2020-05-08)
> 
> it was agreed that having many static variables in 'upload-pack.c',
> while upload_pack_v2() is called more than once per process, is very
> bug prone and messy, and that a good way forward would be to use
> 'struct upload_pack_data' thoroughly, especially in upload_pack()
> where it isn't used yet.
> 
> This patch series is the first part of an effort in this direction.

Thanks for following up on this! I think all of the patches here are
moving in a good direction. I think there's a philosophical question
about whether some of the functions should be taking the minimum set of
fields from upload_pack_data, or just the whole struct. But seeing the
opportunities for cleanup near the end, especially around little flags,
I think passing the big struct around (like you've done here) is
probably the best choice.

> While there are still a lot of static variables at the top of
> 'upload-pack.c' after this patch series, it does a lot of ground work
> and a number of cleanups.

Yeah, I think all of use_thin_pack, use_ofs_delta, etc, should be easy
conversions on top (and will really give us the payoff).

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1
  2020-05-15 18:47 ` Jeff King
@ 2020-05-15 18:55   ` Jeff King
  2020-05-19  9:44     ` Christian Couder
  0 siblings, 1 reply; 108+ messages in thread
From: Jeff King @ 2020-05-15 18:55 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 02:47:16PM -0400, Jeff King wrote:

> > While there are still a lot of static variables at the top of
> > 'upload-pack.c' after this patch series, it does a lot of ground work
> > and a number of cleanups.
> 
> Yeah, I think all of use_thin_pack, use_ofs_delta, etc, should be easy
> conversions on top (and will really give us the payoff).

Hmm, none of those fields in upload_pack_data are used, even for v2!
I.e., if I apply this patch:

    diff --git a/upload-pack.c b/upload-pack.c
    index 401c9e6c4b..522ae3ff6e 100644
    --- a/upload-pack.c
    +++ b/upload-pack.c
    @@ -91,10 +91,6 @@ struct upload_pack_data {
     
     	unsigned stateless_rpc : 1;
     
    -	unsigned use_thin_pack : 1;
    -	unsigned use_ofs_delta : 1;
    -	unsigned no_progress : 1;
    -	unsigned use_include_tag : 1;
     	unsigned done : 1;
     };
     

it still compiles. So starting to use those would be a behavior change,
as we accidentally let use_ofs_delta, etc, propagate from one v2 "fetch"
command to another for ssh/git/file connections (but not for http). I
think that's fixing a bug (but one nobody is likely to see, because it
would imply the client sending different capabilities for each request).

I think we'd want something like the patch below.

Some of the other globals, like multi_ack, are really v0 only (since v2
assumes certain baseline capabilities). We could either leave them
as-is, or roll them into upload_pack_data and just let v2 code ignore
them as it does now.

diff --git a/upload-pack.c b/upload-pack.c
index 401c9e6c4b..2fa645834a 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -46,8 +46,7 @@ static timestamp_t oldest_have;
 
 static int multi_ack;
 static int no_done;
-static int use_thin_pack, use_ofs_delta, use_include_tag;
-static int no_progress, daemon_mode;
+static int daemon_mode;
 /* Allow specifying sha1 if it is a ref tip. */
 #define ALLOW_TIP_SHA1	01
 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
@@ -186,17 +185,17 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 	}
 	argv_array_push(&pack_objects.args, "pack-objects");
 	argv_array_push(&pack_objects.args, "--revs");
-	if (use_thin_pack)
+	if (pack_data->use_thin_pack)
 		argv_array_push(&pack_objects.args, "--thin");
 
 	argv_array_push(&pack_objects.args, "--stdout");
 	if (shallow_nr)
 		argv_array_push(&pack_objects.args, "--shallow");
-	if (!no_progress)
+	if (!pack_data->no_progress)
 		argv_array_push(&pack_objects.args, "--progress");
-	if (use_ofs_delta)
+	if (pack_data->use_ofs_delta)
 		argv_array_push(&pack_objects.args, "--delta-base-offset");
-	if (use_include_tag)
+	if (pack_data->use_include_tag)
 		argv_array_push(&pack_objects.args, "--include-tag");
 	if (pack_data->filter_options.choice) {
 		const char *spec =
@@ -955,17 +954,17 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "no-done"))
 			no_done = 1;
 		if (parse_feature_request(features, "thin-pack"))
-			use_thin_pack = 1;
+			data->use_thin_pack = 1;
 		if (parse_feature_request(features, "ofs-delta"))
-			use_ofs_delta = 1;
+			data->use_ofs_delta = 1;
 		if (parse_feature_request(features, "side-band-64k"))
 			use_sideband = LARGE_PACKET_MAX;
 		else if (parse_feature_request(features, "side-band"))
 			use_sideband = DEFAULT_PACKET_MAX;
 		if (parse_feature_request(features, "no-progress"))
-			no_progress = 1;
+			data->no_progress = 1;
 		if (parse_feature_request(features, "include-tag"))
-			use_include_tag = 1;
+			data->use_include_tag = 1;
 		if (allow_filter && parse_feature_request(features, "filter"))
 			filter_capability_requested = 1;
 
@@ -997,7 +996,7 @@ static void receive_needs(struct upload_pack_data *data,
 		check_non_tip(data);
 
 	if (!use_sideband && daemon_mode)
-		no_progress = 1;
+		data->no_progress = 1;
 
 	if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
 		return;
@@ -1279,19 +1278,19 @@ static void process_args(struct packet_reader *request,
 
 		/* process args like thin-pack */
 		if (!strcmp(arg, "thin-pack")) {
-			use_thin_pack = 1;
+			data->use_thin_pack = 1;
 			continue;
 		}
 		if (!strcmp(arg, "ofs-delta")) {
-			use_ofs_delta = 1;
+			data->use_ofs_delta = 1;
 			continue;
 		}
 		if (!strcmp(arg, "no-progress")) {
-			no_progress = 1;
+			data->no_progress = 1;
 			continue;
 		}
 		if (!strcmp(arg, "include-tag")) {
-			use_include_tag = 1;
+			data->use_include_tag = 1;
 			continue;
 		}
 		if (!strcmp(arg, "done")) {

^ permalink raw reply related	[flat|nested] 108+ messages in thread

* Re: [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1
  2020-05-15 18:55   ` Jeff King
@ 2020-05-19  9:44     ` Christian Couder
  0 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-05-19  9:44 UTC (permalink / raw)
  To: Jeff King
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 8:55 PM Jeff King <peff@peff.net> wrote:
>
> On Fri, May 15, 2020 at 02:47:16PM -0400, Jeff King wrote:
>
> > > While there are still a lot of static variables at the top of
> > > 'upload-pack.c' after this patch series, it does a lot of ground work
> > > and a number of cleanups.
> >
> > Yeah, I think all of use_thin_pack, use_ofs_delta, etc, should be easy
> > conversions on top (and will really give us the payoff).
>
> Hmm, none of those fields in upload_pack_data are used, even for v2!
> I.e., if I apply this patch:

[...]

> it still compiles. So starting to use those would be a behavior change,
> as we accidentally let use_ofs_delta, etc, propagate from one v2 "fetch"
> command to another for ssh/git/file connections (but not for http). I
> think that's fixing a bug (but one nobody is likely to see, because it
> would imply the client sending different capabilities for each request).

I agree.

> I think we'd want something like the patch below.

Thanks for your patch! I have included it as the first patch in the
"part 2" patch series I am planning to send once this "part 1" will be
merged to pu or next:

- the commit with your patch:
https://gitlab.com/gitlab-org/gitlab-git/-/commit/458b79f0f563226bf50924553fc3889cb0942864
- the whole branch with "part 1" and "part 2":
https://gitlab.com/gitlab-org/gitlab-git/-/commits/fix-upload-pack-variable-scope5/

> Some of the other globals, like multi_ack, are really v0 only (since v2
> assumes certain baseline capabilities). We could either leave them
> as-is, or roll them into upload_pack_data and just let v2 code ignore
> them as it does now.

I am in favor of rolling them into upload_pack_data. That's what I
started doing in "part 1" and continued doing in "part 2". I think it
makes the code more coherent and cleaner.

Thanks for your review,
Christian.

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1
  2020-05-15 10:43 ` [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Derrick Stolee
@ 2020-05-19  9:49   ` Christian Couder
  0 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-05-19  9:49 UTC (permalink / raw)
  To: Derrick Stolee, Junio C Hamano
  Cc: git, Derrick Stolee, Jeff King, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Fri, May 15, 2020 at 12:43 PM Derrick Stolee <stolee@gmail.com> wrote:
>
> On 5/15/2020 6:04 AM, Christian Couder wrote:

> > While there are still a lot of static variables at the top of
> > 'upload-pack.c' after this patch series, it does a lot of ground work
> > and a number of cleanups.
>
> The patches here are carefully organized to make review easy. Thanks!
>
> I was surprised to see how many local or static variables you were able
> to remove using members that already existed in 'struct upload_pack_data'.
> That made the changes here particularly easy to trust.
>
> Reviewed-by: Derrick Stolee <dstolee@microsoft.com>

Thanks for your review and kind words! I would very much like to add
your "Reviewed-by:" to this patch series, but as no suggestion has
been made to improve it, I am a bit reluctant to resend with only your
"Reviewed-by:" added.

Junio, what would you prefer?

Thanks,
Christian.

^ permalink raw reply	[flat|nested] 108+ messages in thread

* [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
                   ` (14 preceding siblings ...)
  2020-05-15 18:47 ` Jeff King
@ 2020-05-27 16:47 ` Christian Couder
  2020-05-27 16:47   ` [PATCH 01/12] upload-pack: actually use some upload_pack_data bitfields Christian Couder
                     ` (13 more replies)
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
  16 siblings, 14 replies; 108+ messages in thread
From: Christian Couder @ 2020-05-27 16:47 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

This patch series is the second part of an effort to move all static
variables in 'upload-pack.c' into 'struct upload_pack_data'.

It is based on 'cc/upload-pack-data' which contains "part 1" of this
effort. (See also: https://lore.kernel.org/git/20200515100454.14486-1-chriscool@tuxfamily.org/)

A part 3 will follow with the rest of the patches needed to get rid of
the static variables left after this patch series.

Thanks to Peff and Stolee for their review and help.

Christian Couder (11):
  upload-pack: move static vars to upload_pack_data
  upload-pack: move use_sideband to upload_pack_data
  upload-pack: move filter_capability_requested to upload_pack_data
  upload-pack: move multi_ack to upload_pack_data
  upload-pack: change multi_ack to an enum
  upload-pack: pass upload_pack_data to upload_pack_config()
  upload-pack: move keepalive to upload_pack_data
  upload-pack: move allow_filter to upload_pack_data
  upload-pack: move allow_ref_in_want to upload_pack_data
  upload-pack: move allow_sideband_all to upload_pack_data
  upload-pack: move pack_objects_hook to upload_pack_data

Jeff King (1):
  upload-pack: actually use some upload_pack_data bitfields

 upload-pack.c | 185 +++++++++++++++++++++++++++-----------------------
 1 file changed, 101 insertions(+), 84 deletions(-)

-- 
2.27.0.rc2.38.gc6b4ed14d2.dirty


^ permalink raw reply	[flat|nested] 108+ messages in thread

* [PATCH 01/12] upload-pack: actually use some upload_pack_data bitfields
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
@ 2020-05-27 16:47   ` Christian Couder
  2020-05-27 16:47   ` [PATCH 02/12] upload-pack: move static vars to upload_pack_data Christian Couder
                     ` (12 subsequent siblings)
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-05-27 16:47 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

From: Jeff King <peff@peff.net>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's actually start using some bitfields of
that struct, which were previously unused.

We could instead have just removed the following bitfields
from the struct:

unsigned use_thin_pack : 1;
unsigned use_ofs_delta : 1;
unsigned no_progress : 1;
unsigned use_include_tag : 1;

but using them makes it possible to remove a number of static
variables with the same name and purpose from 'upload-pack.c'.

This is a behavior change, as we accidentally used to let values
in those bitfields propagate from one v2 "fetch" command to
another for ssh/git/file connections (but not for http). That's
fixing a bug, but one nobody is likely to see, because it would
imply the client sending different capabilities for each request.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 401c9e6c4b..2fa645834a 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -46,8 +46,7 @@ static timestamp_t oldest_have;
 
 static int multi_ack;
 static int no_done;
-static int use_thin_pack, use_ofs_delta, use_include_tag;
-static int no_progress, daemon_mode;
+static int daemon_mode;
 /* Allow specifying sha1 if it is a ref tip. */
 #define ALLOW_TIP_SHA1	01
 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
@@ -186,17 +185,17 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 	}
 	argv_array_push(&pack_objects.args, "pack-objects");
 	argv_array_push(&pack_objects.args, "--revs");
-	if (use_thin_pack)
+	if (pack_data->use_thin_pack)
 		argv_array_push(&pack_objects.args, "--thin");
 
 	argv_array_push(&pack_objects.args, "--stdout");
 	if (shallow_nr)
 		argv_array_push(&pack_objects.args, "--shallow");
-	if (!no_progress)
+	if (!pack_data->no_progress)
 		argv_array_push(&pack_objects.args, "--progress");
-	if (use_ofs_delta)
+	if (pack_data->use_ofs_delta)
 		argv_array_push(&pack_objects.args, "--delta-base-offset");
-	if (use_include_tag)
+	if (pack_data->use_include_tag)
 		argv_array_push(&pack_objects.args, "--include-tag");
 	if (pack_data->filter_options.choice) {
 		const char *spec =
@@ -955,17 +954,17 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "no-done"))
 			no_done = 1;
 		if (parse_feature_request(features, "thin-pack"))
-			use_thin_pack = 1;
+			data->use_thin_pack = 1;
 		if (parse_feature_request(features, "ofs-delta"))
-			use_ofs_delta = 1;
+			data->use_ofs_delta = 1;
 		if (parse_feature_request(features, "side-band-64k"))
 			use_sideband = LARGE_PACKET_MAX;
 		else if (parse_feature_request(features, "side-band"))
 			use_sideband = DEFAULT_PACKET_MAX;
 		if (parse_feature_request(features, "no-progress"))
-			no_progress = 1;
+			data->no_progress = 1;
 		if (parse_feature_request(features, "include-tag"))
-			use_include_tag = 1;
+			data->use_include_tag = 1;
 		if (allow_filter && parse_feature_request(features, "filter"))
 			filter_capability_requested = 1;
 
@@ -997,7 +996,7 @@ static void receive_needs(struct upload_pack_data *data,
 		check_non_tip(data);
 
 	if (!use_sideband && daemon_mode)
-		no_progress = 1;
+		data->no_progress = 1;
 
 	if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
 		return;
@@ -1279,19 +1278,19 @@ static void process_args(struct packet_reader *request,
 
 		/* process args like thin-pack */
 		if (!strcmp(arg, "thin-pack")) {
-			use_thin_pack = 1;
+			data->use_thin_pack = 1;
 			continue;
 		}
 		if (!strcmp(arg, "ofs-delta")) {
-			use_ofs_delta = 1;
+			data->use_ofs_delta = 1;
 			continue;
 		}
 		if (!strcmp(arg, "no-progress")) {
-			no_progress = 1;
+			data->no_progress = 1;
 			continue;
 		}
 		if (!strcmp(arg, "include-tag")) {
-			use_include_tag = 1;
+			data->use_include_tag = 1;
 			continue;
 		}
 		if (!strcmp(arg, "done")) {
-- 
2.27.0.rc2.38.gc6b4ed14d2.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 02/12] upload-pack: move static vars to upload_pack_data
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
  2020-05-27 16:47   ` [PATCH 01/12] upload-pack: actually use some upload_pack_data bitfields Christian Couder
@ 2020-05-27 16:47   ` Christian Couder
  2020-05-27 18:06     ` Jeff King
  2020-05-27 16:47   ` [PATCH 03/12] upload-pack: move use_sideband " Christian Couder
                     ` (11 subsequent siblings)
  13 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-27 16:47 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'no_done', 'daemon_mode' and
'timeout' variables into this struct.

They are only used by protocol v0 code since protocol v2 assumes
certain baseline capabilities, but rolling them into
upload_pack_data and just letting v2 code ignore them as it does
now is more coherent and cleaner.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 2fa645834a..c83c5a619b 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -45,8 +45,6 @@
 static timestamp_t oldest_have;
 
 static int multi_ack;
-static int no_done;
-static int daemon_mode;
 /* Allow specifying sha1 if it is a ref tip. */
 #define ALLOW_TIP_SHA1	01
 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
@@ -56,7 +54,6 @@ static int daemon_mode;
 static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
-static unsigned int timeout;
 static int keepalive = 5;
 /* 0 for no sideband,
  * otherwise maximum packet size (up to 65520 bytes).
@@ -83,18 +80,21 @@ struct upload_pack_data {
 	timestamp_t deepen_since;
 	int deepen_rev_list;
 	int deepen_relative;
+	int timeout;
 
 	struct list_objects_filter_options filter_options;
 
 	struct packet_writer writer;
 
 	unsigned stateless_rpc : 1;
+	unsigned daemon_mode : 1;
 
 	unsigned use_thin_pack : 1;
 	unsigned use_ofs_delta : 1;
 	unsigned no_progress : 1;
 	unsigned use_include_tag : 1;
 	unsigned done : 1;
+	unsigned no_done : 1;
 };
 
 static void upload_pack_data_init(struct upload_pack_data *data)
@@ -130,7 +130,7 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
 	list_objects_filter_release(&data->filter_options);
 }
 
-static void reset_timeout(void)
+static void reset_timeout(int timeout)
 {
 	alarm(timeout);
 }
@@ -246,7 +246,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 		int pe, pu, pollsize;
 		int ret;
 
-		reset_timeout();
+		reset_timeout(pack_data->timeout);
 
 		pollsize = 0;
 		pe = pu = -1;
@@ -428,7 +428,7 @@ static int get_common_commits(struct upload_pack_data *data,
 	for (;;) {
 		const char *arg;
 
-		reset_timeout();
+		reset_timeout(data->timeout);
 
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
 			if (multi_ack == 2
@@ -441,7 +441,7 @@ static int get_common_commits(struct upload_pack_data *data,
 			if (data->have_obj.nr == 0 || multi_ack)
 				packet_write_fmt(1, "NAK\n");
 
-			if (no_done && sent_ready) {
+			if (data->no_done && sent_ready) {
 				packet_write_fmt(1, "ACK %s\n", last_hex);
 				return 0;
 			}
@@ -919,7 +919,7 @@ static void receive_needs(struct upload_pack_data *data,
 		struct object_id oid_buf;
 		const char *arg;
 
-		reset_timeout();
+		reset_timeout(data->timeout);
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL)
 			break;
 
@@ -952,7 +952,7 @@ static void receive_needs(struct upload_pack_data *data,
 		else if (parse_feature_request(features, "multi_ack"))
 			multi_ack = 1;
 		if (parse_feature_request(features, "no-done"))
-			no_done = 1;
+			data->no_done = 1;
 		if (parse_feature_request(features, "thin-pack"))
 			data->use_thin_pack = 1;
 		if (parse_feature_request(features, "ofs-delta"))
@@ -995,7 +995,7 @@ static void receive_needs(struct upload_pack_data *data,
 	if (has_non_tip)
 		check_non_tip(data);
 
-	if (!use_sideband && daemon_mode)
+	if (!use_sideband && data->daemon_mode)
 		data->no_progress = 1;
 
 	if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
@@ -1144,19 +1144,18 @@ void upload_pack(struct upload_pack_options *options)
 	struct packet_reader reader;
 	struct upload_pack_data data;
 
-	timeout = options->timeout;
-	daemon_mode = options->daemon_mode;
-
 	git_config(upload_pack_config, NULL);
 
 	upload_pack_data_init(&data);
 
 	data.stateless_rpc = options->stateless_rpc;
+	data.daemon_mode = options->daemon_mode;
+	data.timeout = options->timeout;
 
 	head_ref_namespaced(find_symref, &data.symref);
 
 	if (options->advertise_refs || !data.stateless_rpc) {
-		reset_timeout();
+		reset_timeout(data.timeout);
 		head_ref_namespaced(send_ref, &data);
 		for_each_namespaced_ref(send_ref, &data);
 		advertise_shallow_grafts(1);
-- 
2.27.0.rc2.38.gc6b4ed14d2.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 03/12] upload-pack: move use_sideband to upload_pack_data
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
  2020-05-27 16:47   ` [PATCH 01/12] upload-pack: actually use some upload_pack_data bitfields Christian Couder
  2020-05-27 16:47   ` [PATCH 02/12] upload-pack: move static vars to upload_pack_data Christian Couder
@ 2020-05-27 16:47   ` Christian Couder
  2020-05-27 18:07     ` Jeff King
  2020-05-27 16:47   ` [PATCH 04/12] upload-pack: move filter_capability_requested " Christian Couder
                     ` (10 subsequent siblings)
  13 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-27 16:47 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'use_sideband' static variable
into this struct.

This variable is used by both v0 and v2 protocols.

While at it, let's update the comment near the variable
definition.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index c83c5a619b..a5a9750890 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -55,10 +55,6 @@ static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
 static int keepalive = 5;
-/* 0 for no sideband,
- * otherwise maximum packet size (up to 65520 bytes).
- */
-static int use_sideband;
 static const char *pack_objects_hook;
 
 static int filter_capability_requested;
@@ -82,6 +78,9 @@ struct upload_pack_data {
 	int deepen_relative;
 	int timeout;
 
+	/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
+	int use_sideband;
+
 	struct list_objects_filter_options filter_options;
 
 	struct packet_writer writer;
@@ -135,7 +134,8 @@ static void reset_timeout(int timeout)
 	alarm(timeout);
 }
 
-static void send_client_data(int fd, const char *data, ssize_t sz)
+static void send_client_data(int fd, const char *data, ssize_t sz,
+			     int use_sideband)
 {
 	if (use_sideband) {
 		send_sideband(1, fd, data, sz, use_sideband);
@@ -284,7 +284,8 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 			sz = xread(pack_objects.err, progress,
 				  sizeof(progress));
 			if (0 < sz)
-				send_client_data(2, progress, sz);
+				send_client_data(2, progress, sz,
+						 pack_data->use_sideband);
 			else if (sz == 0) {
 				close(pack_objects.err);
 				pack_objects.err = -1;
@@ -327,7 +328,8 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 			}
 			else
 				buffered = -1;
-			send_client_data(1, data, sz);
+			send_client_data(1, data, sz,
+					 pack_data->use_sideband);
 		}
 
 		/*
@@ -340,7 +342,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 		 * protocol to say anything, so those clients are just out of
 		 * luck.
 		 */
-		if (!ret && use_sideband) {
+		if (!ret && pack_data->use_sideband) {
 			static const char buf[] = "0005\1";
 			write_or_die(1, buf, 5);
 		}
@@ -354,15 +356,17 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 	/* flush the data */
 	if (0 <= buffered) {
 		data[0] = buffered;
-		send_client_data(1, data, 1);
+		send_client_data(1, data, 1,
+				 pack_data->use_sideband);
 		fprintf(stderr, "flushed.\n");
 	}
-	if (use_sideband)
+	if (pack_data->use_sideband)
 		packet_flush(1);
 	return;
 
  fail:
-	send_client_data(3, abort_msg, sizeof(abort_msg));
+	send_client_data(3, abort_msg, sizeof(abort_msg),
+			 pack_data->use_sideband);
 	die("git upload-pack: %s", abort_msg);
 }
 
@@ -958,9 +962,9 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "ofs-delta"))
 			data->use_ofs_delta = 1;
 		if (parse_feature_request(features, "side-band-64k"))
-			use_sideband = LARGE_PACKET_MAX;
+			data->use_sideband = LARGE_PACKET_MAX;
 		else if (parse_feature_request(features, "side-band"))
-			use_sideband = DEFAULT_PACKET_MAX;
+			data->use_sideband = DEFAULT_PACKET_MAX;
 		if (parse_feature_request(features, "no-progress"))
 			data->no_progress = 1;
 		if (parse_feature_request(features, "include-tag"))
@@ -995,7 +999,7 @@ static void receive_needs(struct upload_pack_data *data,
 	if (has_non_tip)
 		check_non_tip(data);
 
-	if (!use_sideband && data->daemon_mode)
+	if (!data->use_sideband && data->daemon_mode)
 		data->no_progress = 1;
 
 	if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
@@ -1480,7 +1484,7 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
 	git_config(upload_pack_config, NULL);
 
 	upload_pack_data_init(&data);
-	use_sideband = LARGE_PACKET_MAX;
+	data.use_sideband = LARGE_PACKET_MAX;
 
 	while (state != FETCH_DONE) {
 		switch (state) {
-- 
2.27.0.rc2.38.gc6b4ed14d2.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 04/12] upload-pack: move filter_capability_requested to upload_pack_data
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                     ` (2 preceding siblings ...)
  2020-05-27 16:47   ` [PATCH 03/12] upload-pack: move use_sideband " Christian Couder
@ 2020-05-27 16:47   ` Christian Couder
  2020-05-27 18:08     ` Jeff King
  2020-05-27 16:47   ` [PATCH 05/12] upload-pack: move multi_ack " Christian Couder
                     ` (9 subsequent siblings)
  13 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-27 16:47 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the filter_capability_requested
static variable into this struct.

It is only used by protocol v0 code since protocol v2 assumes
certain baseline capabilities, but rolling it into
upload_pack_data and just letting v2 code ignore it as it does
now is more coherent and cleaner.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index a5a9750890..e81b326690 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -57,7 +57,6 @@ static struct object_array extra_edge_obj;
 static int keepalive = 5;
 static const char *pack_objects_hook;
 
-static int filter_capability_requested;
 static int allow_filter;
 static int allow_ref_in_want;
 
@@ -94,6 +93,7 @@ struct upload_pack_data {
 	unsigned use_include_tag : 1;
 	unsigned done : 1;
 	unsigned no_done : 1;
+	unsigned filter_capability_requested : 1;
 };
 
 static void upload_pack_data_init(struct upload_pack_data *data)
@@ -937,7 +937,7 @@ static void receive_needs(struct upload_pack_data *data,
 			continue;
 
 		if (skip_prefix(reader->line, "filter ", &arg)) {
-			if (!filter_capability_requested)
+			if (!data->filter_capability_requested)
 				die("git upload-pack: filtering capability not negotiated");
 			list_objects_filter_die_if_populated(&data->filter_options);
 			parse_list_objects_filter(&data->filter_options, arg);
@@ -970,7 +970,7 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "include-tag"))
 			data->use_include_tag = 1;
 		if (allow_filter && parse_feature_request(features, "filter"))
-			filter_capability_requested = 1;
+			data->filter_capability_requested = 1;
 
 		o = parse_object(the_repository, &oid_buf);
 		if (!o) {
-- 
2.27.0.rc2.38.gc6b4ed14d2.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 05/12] upload-pack: move multi_ack to upload_pack_data
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                     ` (3 preceding siblings ...)
  2020-05-27 16:47   ` [PATCH 04/12] upload-pack: move filter_capability_requested " Christian Couder
@ 2020-05-27 16:47   ` Christian Couder
  2020-05-27 16:47   ` [PATCH 06/12] upload-pack: change multi_ack to an enum Christian Couder
                     ` (8 subsequent siblings)
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-05-27 16:47 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the multi_ack static variable into
this struct.

It is only used by protocol v0 code since protocol v2 assumes
certain baseline capabilities, but rolling it into
upload_pack_data and just letting v2 code ignore it as it does
now is more coherent and cleaner.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index e81b326690..385b165bec 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -44,7 +44,6 @@
 
 static timestamp_t oldest_have;
 
-static int multi_ack;
 /* Allow specifying sha1 if it is a ref tip. */
 #define ALLOW_TIP_SHA1	01
 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
@@ -76,6 +75,7 @@ struct upload_pack_data {
 	int deepen_rev_list;
 	int deepen_relative;
 	int timeout;
+	int multi_ack;
 
 	/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
 	int use_sideband;
@@ -435,14 +435,14 @@ static int get_common_commits(struct upload_pack_data *data,
 		reset_timeout(data->timeout);
 
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
-			if (multi_ack == 2
+			if (data->multi_ack == 2
 			    && got_common
 			    && !got_other
 			    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
 				sent_ready = 1;
 				packet_write_fmt(1, "ACK %s ready\n", last_hex);
 			}
-			if (data->have_obj.nr == 0 || multi_ack)
+			if (data->have_obj.nr == 0 || data->multi_ack)
 				packet_write_fmt(1, "NAK\n");
 
 			if (data->no_done && sent_ready) {
@@ -459,10 +459,10 @@ static int get_common_commits(struct upload_pack_data *data,
 			switch (got_oid(arg, &oid, &data->have_obj)) {
 			case -1: /* they have what we do not */
 				got_other = 1;
-				if (multi_ack
+				if (data->multi_ack
 				    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
 					const char *hex = oid_to_hex(&oid);
-					if (multi_ack == 2) {
+					if (data->multi_ack == 2) {
 						sent_ready = 1;
 						packet_write_fmt(1, "ACK %s ready\n", hex);
 					} else
@@ -472,9 +472,9 @@ static int get_common_commits(struct upload_pack_data *data,
 			default:
 				got_common = 1;
 				oid_to_hex_r(last_hex, &oid);
-				if (multi_ack == 2)
+				if (data->multi_ack == 2)
 					packet_write_fmt(1, "ACK %s common\n", last_hex);
-				else if (multi_ack)
+				else if (data->multi_ack)
 					packet_write_fmt(1, "ACK %s continue\n", last_hex);
 				else if (data->have_obj.nr == 1)
 					packet_write_fmt(1, "ACK %s\n", last_hex);
@@ -484,7 +484,7 @@ static int get_common_commits(struct upload_pack_data *data,
 		}
 		if (!strcmp(reader->line, "done")) {
 			if (data->have_obj.nr > 0) {
-				if (multi_ack)
+				if (data->multi_ack)
 					packet_write_fmt(1, "ACK %s\n", last_hex);
 				return 0;
 			}
@@ -952,9 +952,9 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "deepen-relative"))
 			data->deepen_relative = 1;
 		if (parse_feature_request(features, "multi_ack_detailed"))
-			multi_ack = 2;
+			data->multi_ack = 2;
 		else if (parse_feature_request(features, "multi_ack"))
-			multi_ack = 1;
+			data->multi_ack = 1;
 		if (parse_feature_request(features, "no-done"))
 			data->no_done = 1;
 		if (parse_feature_request(features, "thin-pack"))
-- 
2.27.0.rc2.38.gc6b4ed14d2.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 06/12] upload-pack: change multi_ack to an enum
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                     ` (4 preceding siblings ...)
  2020-05-27 16:47   ` [PATCH 05/12] upload-pack: move multi_ack " Christian Couder
@ 2020-05-27 16:47   ` Christian Couder
  2020-05-27 18:10     ` Jeff King
  2020-05-27 16:47   ` [PATCH 07/12] upload-pack: pass upload_pack_data to upload_pack_config() Christian Couder
                     ` (7 subsequent siblings)
  13 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-27 16:47 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's take this opportunity to change the
'multi_ack' variable, which is now part of 'upload_pack_data',
to an enum.

This will make it clear which values this variable can take.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 385b165bec..d211bebc0e 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -75,7 +75,12 @@ struct upload_pack_data {
 	int deepen_rev_list;
 	int deepen_relative;
 	int timeout;
-	int multi_ack;
+
+	enum  {
+		no_multi_ack = 0,
+		multi_ack = 1,
+		multi_ack_detailed = 2
+	} multi_ack;
 
 	/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
 	int use_sideband;
@@ -435,7 +440,7 @@ static int get_common_commits(struct upload_pack_data *data,
 		reset_timeout(data->timeout);
 
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
-			if (data->multi_ack == 2
+			if (data->multi_ack == multi_ack_detailed
 			    && got_common
 			    && !got_other
 			    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
@@ -462,7 +467,7 @@ static int get_common_commits(struct upload_pack_data *data,
 				if (data->multi_ack
 				    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
 					const char *hex = oid_to_hex(&oid);
-					if (data->multi_ack == 2) {
+					if (data->multi_ack == multi_ack_detailed) {
 						sent_ready = 1;
 						packet_write_fmt(1, "ACK %s ready\n", hex);
 					} else
@@ -472,7 +477,7 @@ static int get_common_commits(struct upload_pack_data *data,
 			default:
 				got_common = 1;
 				oid_to_hex_r(last_hex, &oid);
-				if (data->multi_ack == 2)
+				if (data->multi_ack == multi_ack_detailed)
 					packet_write_fmt(1, "ACK %s common\n", last_hex);
 				else if (data->multi_ack)
 					packet_write_fmt(1, "ACK %s continue\n", last_hex);
@@ -952,9 +957,9 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "deepen-relative"))
 			data->deepen_relative = 1;
 		if (parse_feature_request(features, "multi_ack_detailed"))
-			data->multi_ack = 2;
+			data->multi_ack = multi_ack_detailed;
 		else if (parse_feature_request(features, "multi_ack"))
-			data->multi_ack = 1;
+			data->multi_ack = multi_ack;
 		if (parse_feature_request(features, "no-done"))
 			data->no_done = 1;
 		if (parse_feature_request(features, "thin-pack"))
-- 
2.27.0.rc2.38.gc6b4ed14d2.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 07/12] upload-pack: pass upload_pack_data to upload_pack_config()
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                     ` (5 preceding siblings ...)
  2020-05-27 16:47   ` [PATCH 06/12] upload-pack: change multi_ack to an enum Christian Couder
@ 2020-05-27 16:47   ` Christian Couder
  2020-05-27 18:36     ` Jeff King
  2020-05-27 16:47   ` [PATCH 08/12] upload-pack: move keepalive to upload_pack_data Christian Couder
                     ` (6 subsequent siblings)
  13 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-27 16:47 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass that struct to upload_pack_config(),
so that this function can use all the fields of the struct.

This will be used in followup commits to move static variables
that are set in upload_pack_config() into 'upload_pack_data'.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index d211bebc0e..101e28f478 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1108,7 +1108,7 @@ static int find_symref(const char *refname, const struct object_id *oid,
 	return 0;
 }
 
-static int upload_pack_config(const char *var, const char *value, void *unused)
+static int upload_pack_config(const char *var, const char *value, void *cb_data)
 {
 	if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
 		if (git_config_bool(var, value))
@@ -1153,10 +1153,10 @@ void upload_pack(struct upload_pack_options *options)
 	struct packet_reader reader;
 	struct upload_pack_data data;
 
-	git_config(upload_pack_config, NULL);
-
 	upload_pack_data_init(&data);
 
+	git_config(upload_pack_config, &data);
+
 	data.stateless_rpc = options->stateless_rpc;
 	data.daemon_mode = options->daemon_mode;
 	data.timeout = options->timeout;
@@ -1486,11 +1486,11 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
 
 	clear_object_flags(ALL_FLAGS);
 
-	git_config(upload_pack_config, NULL);
-
 	upload_pack_data_init(&data);
 	data.use_sideband = LARGE_PACKET_MAX;
 
+	git_config(upload_pack_config, &data);
+
 	while (state != FETCH_DONE) {
 		switch (state) {
 		case FETCH_PROCESS_ARGS:
-- 
2.27.0.rc2.38.gc6b4ed14d2.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 08/12] upload-pack: move keepalive to upload_pack_data
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                     ` (6 preceding siblings ...)
  2020-05-27 16:47   ` [PATCH 07/12] upload-pack: pass upload_pack_data to upload_pack_config() Christian Couder
@ 2020-05-27 16:47   ` Christian Couder
  2020-05-27 18:38     ` Jeff King
  2020-05-27 16:47   ` [PATCH 09/12] upload-pack: move allow_filter " Christian Couder
                     ` (5 subsequent siblings)
  13 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-27 16:47 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'keepalive' static variable
into this struct.

It is used by code common to protocol v0 and protocol v2.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 101e28f478..e00631a703 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -53,7 +53,6 @@ static timestamp_t oldest_have;
 static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
-static int keepalive = 5;
 static const char *pack_objects_hook;
 
 static int allow_filter;
@@ -75,6 +74,7 @@ struct upload_pack_data {
 	int deepen_rev_list;
 	int deepen_relative;
 	int timeout;
+	int keepalive;
 
 	enum  {
 		no_multi_ack = 0,
@@ -120,6 +120,8 @@ static void upload_pack_data_init(struct upload_pack_data *data)
 	data->shallows = shallows;
 	data->deepen_not = deepen_not;
 	packet_writer_init(&data->writer, 1);
+
+	data->keepalive = 5;
 }
 
 static void upload_pack_data_clear(struct upload_pack_data *data)
@@ -248,7 +250,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 
 	while (1) {
 		struct pollfd pfd[2];
-		int pe, pu, pollsize;
+		int pe, pu, pollsize, polltimeout;
 		int ret;
 
 		reset_timeout(pack_data->timeout);
@@ -272,8 +274,11 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 		if (!pollsize)
 			break;
 
-		ret = poll(pfd, pollsize,
-			keepalive < 0 ? -1 : 1000 * keepalive);
+		polltimeout = pack_data->keepalive < 0
+			? -1
+			: 1000 * pack_data->keepalive;
+
+		ret = poll(pfd, pollsize, polltimeout);
 
 		if (ret < 0) {
 			if (errno != EINTR) {
@@ -1110,6 +1115,8 @@ static int find_symref(const char *refname, const struct object_id *oid,
 
 static int upload_pack_config(const char *var, const char *value, void *cb_data)
 {
+	struct upload_pack_data *data = cb_data;
+
 	if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
 		if (git_config_bool(var, value))
 			allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
@@ -1126,9 +1133,9 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 		else
 			allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
 	} else if (!strcmp("uploadpack.keepalive", var)) {
-		keepalive = git_config_int(var, value);
-		if (!keepalive)
-			keepalive = -1;
+		data->keepalive = git_config_int(var, value);
+		if (!data->keepalive)
+			data->keepalive = -1;
 	} else if (!strcmp("uploadpack.allowfilter", var)) {
 		allow_filter = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowrefinwant", var)) {
-- 
2.27.0.rc2.38.gc6b4ed14d2.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 09/12] upload-pack: move allow_filter to upload_pack_data
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                     ` (7 preceding siblings ...)
  2020-05-27 16:47   ` [PATCH 08/12] upload-pack: move keepalive to upload_pack_data Christian Couder
@ 2020-05-27 16:47   ` Christian Couder
  2020-05-27 18:39     ` Jeff King
  2020-05-27 16:47   ` [PATCH 10/12] upload-pack: move allow_ref_in_want " Christian Couder
                     ` (4 subsequent siblings)
  13 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-27 16:47 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'allow_filter' static variable
into this struct.

It is only used by protocol v0 code since protocol v2 assumes
certain baseline capabilities, but rolling it into
upload_pack_data and just letting v2 code ignore it as it does
now is more coherent and cleaner.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index e00631a703..10bafeb8b6 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -55,7 +55,6 @@ static int shallow_nr;
 static struct object_array extra_edge_obj;
 static const char *pack_objects_hook;
 
-static int allow_filter;
 static int allow_ref_in_want;
 
 static int allow_sideband_all;
@@ -99,6 +98,8 @@ struct upload_pack_data {
 	unsigned done : 1;
 	unsigned no_done : 1;
 	unsigned filter_capability_requested : 1;
+
+	unsigned allow_filter : 1;
 };
 
 static void upload_pack_data_init(struct upload_pack_data *data)
@@ -979,7 +980,8 @@ static void receive_needs(struct upload_pack_data *data,
 			data->no_progress = 1;
 		if (parse_feature_request(features, "include-tag"))
 			data->use_include_tag = 1;
-		if (allow_filter && parse_feature_request(features, "filter"))
+		if (data->allow_filter &&
+		    parse_feature_request(features, "filter"))
 			data->filter_capability_requested = 1;
 
 		o = parse_object(the_repository, &oid_buf);
@@ -1085,7 +1087,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
 				     " allow-reachable-sha1-in-want" : "",
 			     data->stateless_rpc ? " no-done" : "",
 			     symref_info.buf,
-			     allow_filter ? " filter" : "",
+			     data->allow_filter ? " filter" : "",
 			     git_user_agent_sanitized());
 		strbuf_release(&symref_info);
 	} else {
@@ -1137,7 +1139,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 		if (!data->keepalive)
 			data->keepalive = -1;
 	} else if (!strcmp("uploadpack.allowfilter", var)) {
-		allow_filter = git_config_bool(var, value);
+		data->allow_filter = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowrefinwant", var)) {
 		allow_ref_in_want = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowsidebandall", var)) {
@@ -1329,7 +1331,7 @@ static void process_args(struct packet_reader *request,
 			continue;
 		}
 
-		if (allow_filter && skip_prefix(arg, "filter ", &p)) {
+		if (data->allow_filter && skip_prefix(arg, "filter ", &p)) {
 			list_objects_filter_die_if_populated(&data->filter_options);
 			parse_list_objects_filter(&data->filter_options, p);
 			continue;
-- 
2.27.0.rc2.38.gc6b4ed14d2.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 10/12] upload-pack: move allow_ref_in_want to upload_pack_data
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                     ` (8 preceding siblings ...)
  2020-05-27 16:47   ` [PATCH 09/12] upload-pack: move allow_filter " Christian Couder
@ 2020-05-27 16:47   ` Christian Couder
  2020-05-27 18:41     ` Jeff King
  2020-05-27 16:47   ` [PATCH 11/12] upload-pack: move allow_sideband_all " Christian Couder
                     ` (3 subsequent siblings)
  13 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-27 16:47 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'allow_ref_in_want' static
variable into this struct.

It is only used by protocol v0 code since protocol v2 assumes
certain baseline capabilities, but rolling it into
upload_pack_data and just letting v2 code ignore it as it does
now is more coherent and cleaner.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 10bafeb8b6..b5647eb47c 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -55,8 +55,6 @@ static int shallow_nr;
 static struct object_array extra_edge_obj;
 static const char *pack_objects_hook;
 
-static int allow_ref_in_want;
-
 static int allow_sideband_all;
 
 struct upload_pack_data {
@@ -100,6 +98,7 @@ struct upload_pack_data {
 	unsigned filter_capability_requested : 1;
 
 	unsigned allow_filter : 1;
+	unsigned allow_ref_in_want : 1;
 };
 
 static void upload_pack_data_init(struct upload_pack_data *data)
@@ -1141,7 +1140,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 	} else if (!strcmp("uploadpack.allowfilter", var)) {
 		data->allow_filter = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowrefinwant", var)) {
-		allow_ref_in_want = git_config_bool(var, value);
+		data->allow_ref_in_want = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowsidebandall", var)) {
 		allow_sideband_all = git_config_bool(var, value);
 	} else if (!strcmp("core.precomposeunicode", var)) {
@@ -1285,7 +1284,7 @@ static void process_args(struct packet_reader *request,
 		/* process want */
 		if (parse_want(&data->writer, arg, &data->want_obj))
 			continue;
-		if (allow_ref_in_want &&
+		if (data->allow_ref_in_want &&
 		    parse_want_ref(&data->writer, arg, &data->wanted_refs,
 				   &data->want_obj))
 			continue;
-- 
2.27.0.rc2.38.gc6b4ed14d2.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 11/12] upload-pack: move allow_sideband_all to upload_pack_data
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                     ` (9 preceding siblings ...)
  2020-05-27 16:47   ` [PATCH 10/12] upload-pack: move allow_ref_in_want " Christian Couder
@ 2020-05-27 16:47   ` Christian Couder
  2020-05-27 16:47   ` [PATCH 12/12] upload-pack: move pack_objects_hook " Christian Couder
                     ` (2 subsequent siblings)
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-05-27 16:47 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'allow_sideband_all' static
variable into this struct.

It is used only by protocol v2 code.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index b5647eb47c..becefd5bdc 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -55,8 +55,6 @@ static int shallow_nr;
 static struct object_array extra_edge_obj;
 static const char *pack_objects_hook;
 
-static int allow_sideband_all;
-
 struct upload_pack_data {
 	struct string_list symref;
 	struct string_list wanted_refs;
@@ -99,6 +97,7 @@ struct upload_pack_data {
 
 	unsigned allow_filter : 1;
 	unsigned allow_ref_in_want : 1;
+	unsigned allow_sideband_all : 1;
 };
 
 static void upload_pack_data_init(struct upload_pack_data *data)
@@ -1142,7 +1141,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 	} else if (!strcmp("uploadpack.allowrefinwant", var)) {
 		data->allow_ref_in_want = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowsidebandall", var)) {
-		allow_sideband_all = git_config_bool(var, value);
+		data->allow_sideband_all = git_config_bool(var, value);
 	} else if (!strcmp("core.precomposeunicode", var)) {
 		precomposed_unicode = git_config_bool(var, value);
 	}
@@ -1337,7 +1336,7 @@ static void process_args(struct packet_reader *request,
 		}
 
 		if ((git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) ||
-		     allow_sideband_all) &&
+		     data->allow_sideband_all) &&
 		    !strcmp(arg, "sideband-all")) {
 			data->writer.use_sideband = 1;
 			continue;
-- 
2.27.0.rc2.38.gc6b4ed14d2.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 12/12] upload-pack: move pack_objects_hook to upload_pack_data
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                     ` (10 preceding siblings ...)
  2020-05-27 16:47   ` [PATCH 11/12] upload-pack: move allow_sideband_all " Christian Couder
@ 2020-05-27 16:47   ` Christian Couder
  2020-05-27 18:55     ` Jeff King
  2020-05-27 18:57   ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Jeff King
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
  13 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-05-27 16:47 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'pack_objects_hook' static
variable into this struct.

It is used by code common to protocol v0 and protocol v2.

While at it let's also free() it in upload_pack_data_clear().

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index becefd5bdc..3e9ae53e6c 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -53,7 +53,6 @@ static timestamp_t oldest_have;
 static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
-static const char *pack_objects_hook;
 
 struct upload_pack_data {
 	struct string_list symref;
@@ -84,6 +83,8 @@ struct upload_pack_data {
 
 	struct packet_writer writer;
 
+	const char *pack_objects_hook;
+
 	unsigned stateless_rpc : 1;
 	unsigned daemon_mode : 1;
 
@@ -133,6 +134,8 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
 	object_array_clear(&data->shallows);
 	string_list_clear(&data->deepen_not, 0);
 	list_objects_filter_release(&data->filter_options);
+
+	free((char *)data->pack_objects_hook);
 }
 
 static void reset_timeout(int timeout)
@@ -177,10 +180,10 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 	int i;
 	FILE *pipe_fd;
 
-	if (!pack_objects_hook)
+	if (!pack_data->pack_objects_hook)
 		pack_objects.git_cmd = 1;
 	else {
-		argv_array_push(&pack_objects.args, pack_objects_hook);
+		argv_array_push(&pack_objects.args, pack_data->pack_objects_hook);
 		argv_array_push(&pack_objects.args, "git");
 		pack_objects.use_shell = 1;
 	}
@@ -1149,7 +1152,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 	if (current_config_scope() != CONFIG_SCOPE_LOCAL &&
 	current_config_scope() != CONFIG_SCOPE_WORKTREE) {
 		if (!strcmp("uploadpack.packobjectshook", var))
-			return git_config_string(&pack_objects_hook, var, value);
+			return git_config_string(&data->pack_objects_hook, var, value);
 	}
 
 	return parse_hide_refs_config(var, value, "uploadpack");
-- 
2.27.0.rc2.38.gc6b4ed14d2.dirty


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* Re: [PATCH 02/12] upload-pack: move static vars to upload_pack_data
  2020-05-27 16:47   ` [PATCH 02/12] upload-pack: move static vars to upload_pack_data Christian Couder
@ 2020-05-27 18:06     ` Jeff King
  2020-06-02  4:19       ` Christian Couder
  0 siblings, 1 reply; 108+ messages in thread
From: Jeff King @ 2020-05-27 18:06 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Wed, May 27, 2020 at 06:47:32PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's move the 'no_done', 'daemon_mode' and
> 'timeout' variables into this struct.

Makes sense.

> They are only used by protocol v0 code since protocol v2 assumes
> certain baseline capabilities, but rolling them into
> upload_pack_data and just letting v2 code ignore them as it does
> now is more coherent and cleaner.

Is it perhaps worth keeping these v0-only fields grouped together within
the struct, along with a comment? That way nobody has to repeat your
research later into which ones are used and which ones are not.

> -static unsigned int timeout;

This was unsigned, but gets moved as...

> @@ -83,18 +80,21 @@ struct upload_pack_data {
>  	timestamp_t deepen_since;
>  	int deepen_rev_list;
>  	int deepen_relative;
> +	int timeout;

...a signed int.

It probably doesn't matter much in practice for the values we'd give it,
but the alarm() to which it's ultimately fed takes an unsigned int.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 03/12] upload-pack: move use_sideband to upload_pack_data
  2020-05-27 16:47   ` [PATCH 03/12] upload-pack: move use_sideband " Christian Couder
@ 2020-05-27 18:07     ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-27 18:07 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Wed, May 27, 2020 at 06:47:33PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's move the 'use_sideband' static variable
> into this struct.
> 
> This variable is used by both v0 and v2 protocols.
> 
> While at it, let's update the comment near the variable
> definition.

Yep, looks good. I was surprised for a moment by "used by v2", which
always does sideband. But of course we still _use_ the variable, we just
set it unconditionally in the v2 code-path.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 04/12] upload-pack: move filter_capability_requested to upload_pack_data
  2020-05-27 16:47   ` [PATCH 04/12] upload-pack: move filter_capability_requested " Christian Couder
@ 2020-05-27 18:08     ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-27 18:08 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Wed, May 27, 2020 at 06:47:34PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's move the filter_capability_requested
> static variable into this struct.
> 
> It is only used by protocol v0 code since protocol v2 assumes
> certain baseline capabilities, but rolling it into
> upload_pack_data and just letting v2 code ignore it as it does
> now is more coherent and cleaner.

Looks good, though this is another candidate for grouping/commenting in
the struct that it's v0-only.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 06/12] upload-pack: change multi_ack to an enum
  2020-05-27 16:47   ` [PATCH 06/12] upload-pack: change multi_ack to an enum Christian Couder
@ 2020-05-27 18:10     ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-27 18:10 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Wed, May 27, 2020 at 06:47:36PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's take this opportunity to change the
> 'multi_ack' variable, which is now part of 'upload_pack_data',
> to an enum.
> 
> This will make it clear which values this variable can take.

Much nicer, thanks for doing this cleanup.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 07/12] upload-pack: pass upload_pack_data to upload_pack_config()
  2020-05-27 16:47   ` [PATCH 07/12] upload-pack: pass upload_pack_data to upload_pack_config() Christian Couder
@ 2020-05-27 18:36     ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-27 18:36 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Wed, May 27, 2020 at 06:47:37PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's pass that struct to upload_pack_config(),
> so that this function can use all the fields of the struct.
> 
> This will be used in followup commits to move static variables
> that are set in upload_pack_config() into 'upload_pack_data'.

Makes sense...

> @@ -1153,10 +1153,10 @@ void upload_pack(struct upload_pack_options *options)
>  	struct packet_reader reader;
>  	struct upload_pack_data data;
>  
> -	git_config(upload_pack_config, NULL);
> -
>  	upload_pack_data_init(&data);
>  
> +	git_config(upload_pack_config, &data);
> +

...and we know there can't be any init-time dependency issues with this
reordering, because the original could not have accessed &data at all.

Looks good.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 08/12] upload-pack: move keepalive to upload_pack_data
  2020-05-27 16:47   ` [PATCH 08/12] upload-pack: move keepalive to upload_pack_data Christian Couder
@ 2020-05-27 18:38     ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-27 18:38 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Wed, May 27, 2020 at 06:47:38PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's move the 'keepalive' static variable
> into this struct.
> 
> It is used by code common to protocol v0 and protocol v2.

Sounds good.

> @@ -248,7 +250,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
>  
>  	while (1) {
>  		struct pollfd pfd[2];
> -		int pe, pu, pollsize;
> +		int pe, pu, pollsize, polltimeout;
>  		int ret;
>  
>  		reset_timeout(pack_data->timeout);
> @@ -272,8 +274,11 @@ static void create_pack_file(struct upload_pack_data *pack_data)
>  		if (!pollsize)
>  			break;
>  
> -		ret = poll(pfd, pollsize,
> -			keepalive < 0 ? -1 : 1000 * keepalive);
> +		polltimeout = pack_data->keepalive < 0
> +			? -1
> +			: 1000 * pack_data->keepalive;
> +
> +		ret = poll(pfd, pollsize, polltimeout);

The new variable isn't strictly necessary, but it keeps the line-length
down now that the variable name is much longer. Looks reasonable.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 09/12] upload-pack: move allow_filter to upload_pack_data
  2020-05-27 16:47   ` [PATCH 09/12] upload-pack: move allow_filter " Christian Couder
@ 2020-05-27 18:39     ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-27 18:39 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Wed, May 27, 2020 at 06:47:39PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's move the 'allow_filter' static variable
> into this struct.
> 
> It is only used by protocol v0 code since protocol v2 assumes
> certain baseline capabilities, but rolling it into
> upload_pack_data and just letting v2 code ignore it as it does
> now is more coherent and cleaner.

I'm not sure that's true. It should be reflecting the
uploadpack.allowfilter config in both cases. This final hunk:

> @@ -1329,7 +1331,7 @@ static void process_args(struct packet_reader *request,
>  			continue;
>  		}
>  
> -		if (allow_filter && skip_prefix(arg, "filter ", &p)) {
> +		if (data->allow_filter && skip_prefix(arg, "filter ", &p)) {
>  			list_objects_filter_die_if_populated(&data->filter_options);
>  			parse_list_objects_filter(&data->filter_options, p);
>  			continue;

is v2 respecting it.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 10/12] upload-pack: move allow_ref_in_want to upload_pack_data
  2020-05-27 16:47   ` [PATCH 10/12] upload-pack: move allow_ref_in_want " Christian Couder
@ 2020-05-27 18:41     ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-27 18:41 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Wed, May 27, 2020 at 06:47:40PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's move the 'allow_ref_in_want' static
> variable into this struct.
> 
> It is only used by protocol v0 code since protocol v2 assumes
> certain baseline capabilities, but rolling it into
> upload_pack_data and just letting v2 code ignore it as it does
> now is more coherent and cleaner.

I think this is opposite, isn't it? Ref-in-want is a v2-only feature,
and v0 does not support it at all (though it could).

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 12/12] upload-pack: move pack_objects_hook to upload_pack_data
  2020-05-27 16:47   ` [PATCH 12/12] upload-pack: move pack_objects_hook " Christian Couder
@ 2020-05-27 18:55     ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-05-27 18:55 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Wed, May 27, 2020 at 06:47:42PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's move the 'pack_objects_hook' static
> variable into this struct.
> 
> It is used by code common to protocol v0 and protocol v2.
> 
> While at it let's also free() it in upload_pack_data_clear().

Makes sense.

> @@ -133,6 +134,8 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
>  	object_array_clear(&data->shallows);
>  	string_list_clear(&data->deepen_not, 0);
>  	list_objects_filter_release(&data->filter_options);
> +
> +	free((char *)data->pack_objects_hook);

This cast is ugly, but unavoidable because git_config_string() takes a
pointer-to-const.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                     ` (11 preceding siblings ...)
  2020-05-27 16:47   ` [PATCH 12/12] upload-pack: move pack_objects_hook " Christian Couder
@ 2020-05-27 18:57   ` Jeff King
  2020-05-27 20:41     ` Junio C Hamano
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
  13 siblings, 1 reply; 108+ messages in thread
From: Jeff King @ 2020-05-27 18:57 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Wed, May 27, 2020 at 06:47:30PM +0200, Christian Couder wrote:

> This patch series is the second part of an effort to move all static
> variables in 'upload-pack.c' into 'struct upload_pack_data'.
> 
> It is based on 'cc/upload-pack-data' which contains "part 1" of this
> effort. (See also: https://lore.kernel.org/git/20200515100454.14486-1-chriscool@tuxfamily.org/)
> 
> A part 3 will follow with the rest of the patches needed to get rid of
> the static variables left after this patch series.

Thanks again for working on this. It mostly looks good, but I left a few
comments, mostly about commit messages or comments. :)

One thing I think we _could_ do is to switch v2 to only reading the
config once, instead of once per request. And then all of those config
values could remain where they are, as they wouldn't need to be cleared
or reset. But I doubt the cost of parsing config per-request is
noticeable in practice, so I'm happy with it either way.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2
  2020-05-27 18:57   ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Jeff King
@ 2020-05-27 20:41     ` Junio C Hamano
  0 siblings, 0 replies; 108+ messages in thread
From: Junio C Hamano @ 2020-05-27 20:41 UTC (permalink / raw)
  To: Jeff King
  Cc: Christian Couder, git, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

Jeff King <peff@peff.net> writes:

> One thing I think we _could_ do is to switch v2 to only reading the
> config once, instead of once per request. And then all of those config
> values could remain where they are, as they wouldn't need to be cleared
> or reset. But I doubt the cost of parsing config per-request is
> noticeable in practice, so I'm happy with it either way.

Yeah, I agree that that would not be an optimization for
performance, but the value of doing it primarily lies in
gaining the conceptual clarity in the resulting code.

Thanks, both.

^ permalink raw reply	[flat|nested] 108+ messages in thread

* [PATCH v2 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                     ` (12 preceding siblings ...)
  2020-05-27 18:57   ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Jeff King
@ 2020-06-02  4:16   ` Christian Couder
  2020-06-02  4:16     ` [PATCH v2 01/13] upload-pack: actually use some upload_pack_data bitfields Christian Couder
                       ` (15 more replies)
  13 siblings, 16 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:16 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

This patch series is the second part of an effort to move all static
variables in 'upload-pack.c' into 'struct upload_pack_data'.

It is based on 'cc/upload-pack-data' which contains "part 1" of this
effort. (See also: https://lore.kernel.org/git/20200515100454.14486-1-chriscool@tuxfamily.org/)

A part 3 will follow with the rest of the patches needed to get rid of
the static variables left after this patch series.

Thanks to Peff for his review of the first version (V1:
https://lore.kernel.org/git/20200527164742.23067-1-chriscool@tuxfamily.org/)
of this part 2.

Compared to V1 the changes are the following:

  - added patch 2/13 "upload-pack: annotate upload_pack_data fields"
    to add 'v0 only' or 'v2 only' comments to the 'upload_pack_data'
    fields, and to better group 'v0 only' and 'v2 only' fields
    together

  - added similar comments in all the other patches when necessary

  - in patch 3/13 'timeout' is still an 'unsigned int' after being
    moved into 'upload_pack_data'

  - in patch 10/13 commit message has been corrected to say that
    'allow_filter' is used by both protocol v0 and v2

  - in patch 11/13 commit message has been corrected to say that
    'allow_ref_in_want' is used only by protocol v2

Here is the range-diff with V1:

 1:  e5c31f30ec =  1:  e5c31f30ec upload-pack: actually use some upload_pack_data bitfields
 -:  ---------- >  2:  225be644f4 upload-pack: annotate upload_pack_data fields
 2:  5f2da66cfd !  3:  5adca8d70c upload-pack: move static vars to upload_pack_data
    @@ upload-pack.c: static int daemon_mode;
      /* 0 for no sideband,
       * otherwise maximum packet size (up to 65520 bytes).
     @@ upload-pack.c: struct upload_pack_data {
    -   timestamp_t deepen_since;
        int deepen_rev_list;
        int deepen_relative;
    -+  int timeout;
      
    ++  unsigned int timeout;                                   /* v0 only */
    ++
        struct list_objects_filter_options filter_options;
      
        struct packet_writer writer;
      
    -   unsigned stateless_rpc : 1;
    -+  unsigned daemon_mode : 1;
    +   unsigned stateless_rpc : 1;                             /* v0 only */
    ++  unsigned no_done : 1;                                   /* v0 only */
    ++  unsigned daemon_mode : 1;                               /* v0 only */
      
        unsigned use_thin_pack : 1;
        unsigned use_ofs_delta : 1;
    -   unsigned no_progress : 1;
    -   unsigned use_include_tag : 1;
    -   unsigned done : 1;
    -+  unsigned no_done : 1;
    - };
    - 
    - static void upload_pack_data_init(struct upload_pack_data *data)
     @@ upload-pack.c: static void upload_pack_data_clear(struct upload_pack_data *data)
        list_objects_filter_release(&data->filter_options);
      }
      
     -static void reset_timeout(void)
    -+static void reset_timeout(int timeout)
    ++static void reset_timeout(unsigned int timeout)
      {
        alarm(timeout);
      }
 3:  56b90f8b5d !  4:  1507a8134a upload-pack: move use_sideband to upload_pack_data
    @@ upload-pack.c: static unsigned int allow_unadvertised_object_request;
      
      static int filter_capability_requested;
     @@ upload-pack.c: struct upload_pack_data {
    -   int deepen_relative;
    -   int timeout;
    + 
    +   unsigned int timeout;                                   /* v0 only */
      
     +  /* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
     +  int use_sideband;
    @@ upload-pack.c: struct upload_pack_data {
        struct list_objects_filter_options filter_options;
      
        struct packet_writer writer;
    -@@ upload-pack.c: static void reset_timeout(int timeout)
    +@@ upload-pack.c: static void reset_timeout(unsigned int timeout)
        alarm(timeout);
      }
      
 4:  a49469bc06 !  5:  0ef8d28958 upload-pack: move filter_capability_requested to upload_pack_data
    @@ upload-pack.c: static struct object_array extra_edge_obj;
      static int allow_ref_in_want;
      
     @@ upload-pack.c: struct upload_pack_data {
    -   unsigned use_include_tag : 1;
    -   unsigned done : 1;
    -   unsigned no_done : 1;
    -+  unsigned filter_capability_requested : 1;
    - };
    +   unsigned stateless_rpc : 1;                             /* v0 only */
    +   unsigned no_done : 1;                                   /* v0 only */
    +   unsigned daemon_mode : 1;                               /* v0 only */
    ++  unsigned filter_capability_requested : 1;               /* v0 only */
      
    - static void upload_pack_data_init(struct upload_pack_data *data)
    +   unsigned use_thin_pack : 1;
    +   unsigned use_ofs_delta : 1;
     @@ upload-pack.c: static void receive_needs(struct upload_pack_data *data,
                        continue;
      
 5:  e0d720aa97 !  6:  319c09ce02 upload-pack: move multi_ack to upload_pack_data
    @@ upload-pack.c
      #define ALLOW_TIP_SHA1    01
      /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
     @@ upload-pack.c: struct upload_pack_data {
    -   int deepen_rev_list;
        int deepen_relative;
    -   int timeout;
    -+  int multi_ack;
    + 
    +   unsigned int timeout;                                   /* v0 only */
    ++  int multi_ack;                                          /* v0 only */
      
        /* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
        int use_sideband;
 6:  076f4ad903 !  7:  cd3a0a1e5c upload-pack: change multi_ack to an enum
    @@ Commit message
     
      ## upload-pack.c ##
     @@ upload-pack.c: struct upload_pack_data {
    -   int deepen_rev_list;
        int deepen_relative;
    -   int timeout;
    --  int multi_ack;
    -+
    + 
    +   unsigned int timeout;                                   /* v0 only */
    +-  int multi_ack;                                          /* v0 only */
     +  enum  {
     +          no_multi_ack = 0,
     +          multi_ack = 1,
     +          multi_ack_detailed = 2
    -+  } multi_ack;
    ++  } multi_ack;                                            /* v0 only */
      
        /* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
        int use_sideband;
 7:  c0b051f344 =  8:  c23e37a8da upload-pack: pass upload_pack_data to upload_pack_config()
 8:  5daacc6670 !  9:  26893a4098 upload-pack: move keepalive to upload_pack_data
    @@ upload-pack.c: static timestamp_t oldest_have;
      
      static int allow_filter;
     @@ upload-pack.c: struct upload_pack_data {
    +   timestamp_t deepen_since;
        int deepen_rev_list;
        int deepen_relative;
    -   int timeout;
     +  int keepalive;
      
    +   unsigned int timeout;                                   /* v0 only */
        enum  {
    -           no_multi_ack = 0,
     @@ upload-pack.c: static void upload_pack_data_init(struct upload_pack_data *data)
        data->shallows = shallows;
        data->deepen_not = deepen_not;
 9:  d04f78999b ! 10:  2fa59d6c89 upload-pack: move allow_filter to upload_pack_data
    @@ Commit message
         more thoroughly, let's move the 'allow_filter' static variable
         into this struct.
     
    -    It is only used by protocol v0 code since protocol v2 assumes
    -    certain baseline capabilities, but rolling it into
    -    upload_pack_data and just letting v2 code ignore it as it does
    -    now is more coherent and cleaner.
    +    It is used by both protocol v0 and protocol v2 code.
     
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
     
    @@ upload-pack.c: static int shallow_nr;
      
      static int allow_sideband_all;
     @@ upload-pack.c: struct upload_pack_data {
    -   unsigned done : 1;
    -   unsigned no_done : 1;
    -   unsigned filter_capability_requested : 1;
    -+
    +   unsigned use_ofs_delta : 1;
    +   unsigned no_progress : 1;
    +   unsigned use_include_tag : 1;
     +  unsigned allow_filter : 1;
    - };
      
    - static void upload_pack_data_init(struct upload_pack_data *data)
    +   unsigned done : 1;                                      /* v2 only */
    + };
     @@ upload-pack.c: static void receive_needs(struct upload_pack_data *data,
                        data->no_progress = 1;
                if (parse_feature_request(features, "include-tag"))
10:  9e99d94c33 ! 11:  d501b0f694 upload-pack: move allow_ref_in_want to upload_pack_data
    @@ Commit message
         more thoroughly, let's move the 'allow_ref_in_want' static
         variable into this struct.
     
    -    It is only used by protocol v0 code since protocol v2 assumes
    -    certain baseline capabilities, but rolling it into
    -    upload_pack_data and just letting v2 code ignore it as it does
    -    now is more coherent and cleaner.
    +    It is used only by protocol v2 code.
     
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
     
    @@ upload-pack.c: static int shallow_nr;
     -
      static int allow_sideband_all;
      
    - struct upload_pack_data {
    + /*
     @@ upload-pack.c: struct upload_pack_data {
    -   unsigned filter_capability_requested : 1;
    - 
        unsigned allow_filter : 1;
    -+  unsigned allow_ref_in_want : 1;
    + 
    +   unsigned done : 1;                                      /* v2 only */
    ++  unsigned allow_ref_in_want : 1;                         /* v2 only */
      };
      
      static void upload_pack_data_init(struct upload_pack_data *data)
11:  64928f291d ! 12:  90513f0543 upload-pack: move allow_sideband_all to upload_pack_data
    @@ upload-pack.c: static int shallow_nr;
      
     -static int allow_sideband_all;
     -
    - struct upload_pack_data {
    -   struct string_list symref;
    -   struct string_list wanted_refs;
    + /*
    +  * Please annotate, and if possible group together, fields used only
    +  * for protocol v0 or only for protocol v2.
     @@ upload-pack.c: struct upload_pack_data {
      
    -   unsigned allow_filter : 1;
    -   unsigned allow_ref_in_want : 1;
    -+  unsigned allow_sideband_all : 1;
    +   unsigned done : 1;                                      /* v2 only */
    +   unsigned allow_ref_in_want : 1;                         /* v2 only */
    ++  unsigned allow_sideband_all : 1;                        /* v2 only */
      };
      
      static void upload_pack_data_init(struct upload_pack_data *data)
12:  07c5ed9528 ! 13:  f2851482f5 upload-pack: move pack_objects_hook to upload_pack_data
    @@ upload-pack.c: static timestamp_t oldest_have;
      static struct object_array extra_edge_obj;
     -static const char *pack_objects_hook;
      
    - struct upload_pack_data {
    -   struct string_list symref;
    + /*
    +  * Please annotate, and if possible group together, fields used only
     @@ upload-pack.c: struct upload_pack_data {
      
        struct packet_writer writer;
      
     +  const char *pack_objects_hook;
     +
    -   unsigned stateless_rpc : 1;
    -   unsigned daemon_mode : 1;
    - 
    +   unsigned stateless_rpc : 1;                             /* v0 only */
    +   unsigned no_done : 1;                                   /* v0 only */
    +   unsigned daemon_mode : 1;                               /* v0 only */
     @@ upload-pack.c: static void upload_pack_data_clear(struct upload_pack_data *data)
        object_array_clear(&data->shallows);
        string_list_clear(&data->deepen_not, 0);
    @@ upload-pack.c: static void upload_pack_data_clear(struct upload_pack_data *data)
     +  free((char *)data->pack_objects_hook);
      }
      
    - static void reset_timeout(int timeout)
    + static void reset_timeout(unsigned int timeout)
     @@ upload-pack.c: static void create_pack_file(struct upload_pack_data *pack_data)
        int i;
        FILE *pipe_fd;


Christian Couder (12):
  upload-pack: annotate upload_pack_data fields
  upload-pack: move static vars to upload_pack_data
  upload-pack: move use_sideband to upload_pack_data
  upload-pack: move filter_capability_requested to upload_pack_data
  upload-pack: move multi_ack to upload_pack_data
  upload-pack: change multi_ack to an enum
  upload-pack: pass upload_pack_data to upload_pack_config()
  upload-pack: move keepalive to upload_pack_data
  upload-pack: move allow_filter to upload_pack_data
  upload-pack: move allow_ref_in_want to upload_pack_data
  upload-pack: move allow_sideband_all to upload_pack_data
  upload-pack: move pack_objects_hook to upload_pack_data

Jeff King (1):
  upload-pack: actually use some upload_pack_data bitfields

 upload-pack.c | 199 ++++++++++++++++++++++++++++----------------------
 1 file changed, 110 insertions(+), 89 deletions(-)

-- 
2.27.0.rc0.26.g636377a2c4


^ permalink raw reply	[flat|nested] 108+ messages in thread

* [PATCH v2 01/13] upload-pack: actually use some upload_pack_data bitfields
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
@ 2020-06-02  4:16     ` Christian Couder
  2020-06-02  4:16     ` [PATCH v2 02/13] upload-pack: annotate upload_pack_data fields Christian Couder
                       ` (14 subsequent siblings)
  15 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:16 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

From: Jeff King <peff@peff.net>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's actually start using some bitfields of
that struct, which were previously unused.

We could instead have just removed the following bitfields
from the struct:

unsigned use_thin_pack : 1;
unsigned use_ofs_delta : 1;
unsigned no_progress : 1;
unsigned use_include_tag : 1;

but using them makes it possible to remove a number of static
variables with the same name and purpose from 'upload-pack.c'.

This is a behavior change, as we accidentally used to let values
in those bitfields propagate from one v2 "fetch" command to
another for ssh/git/file connections (but not for http). That's
fixing a bug, but one nobody is likely to see, because it would
imply the client sending different capabilities for each request.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 401c9e6c4b..2fa645834a 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -46,8 +46,7 @@ static timestamp_t oldest_have;
 
 static int multi_ack;
 static int no_done;
-static int use_thin_pack, use_ofs_delta, use_include_tag;
-static int no_progress, daemon_mode;
+static int daemon_mode;
 /* Allow specifying sha1 if it is a ref tip. */
 #define ALLOW_TIP_SHA1	01
 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
@@ -186,17 +185,17 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 	}
 	argv_array_push(&pack_objects.args, "pack-objects");
 	argv_array_push(&pack_objects.args, "--revs");
-	if (use_thin_pack)
+	if (pack_data->use_thin_pack)
 		argv_array_push(&pack_objects.args, "--thin");
 
 	argv_array_push(&pack_objects.args, "--stdout");
 	if (shallow_nr)
 		argv_array_push(&pack_objects.args, "--shallow");
-	if (!no_progress)
+	if (!pack_data->no_progress)
 		argv_array_push(&pack_objects.args, "--progress");
-	if (use_ofs_delta)
+	if (pack_data->use_ofs_delta)
 		argv_array_push(&pack_objects.args, "--delta-base-offset");
-	if (use_include_tag)
+	if (pack_data->use_include_tag)
 		argv_array_push(&pack_objects.args, "--include-tag");
 	if (pack_data->filter_options.choice) {
 		const char *spec =
@@ -955,17 +954,17 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "no-done"))
 			no_done = 1;
 		if (parse_feature_request(features, "thin-pack"))
-			use_thin_pack = 1;
+			data->use_thin_pack = 1;
 		if (parse_feature_request(features, "ofs-delta"))
-			use_ofs_delta = 1;
+			data->use_ofs_delta = 1;
 		if (parse_feature_request(features, "side-band-64k"))
 			use_sideband = LARGE_PACKET_MAX;
 		else if (parse_feature_request(features, "side-band"))
 			use_sideband = DEFAULT_PACKET_MAX;
 		if (parse_feature_request(features, "no-progress"))
-			no_progress = 1;
+			data->no_progress = 1;
 		if (parse_feature_request(features, "include-tag"))
-			use_include_tag = 1;
+			data->use_include_tag = 1;
 		if (allow_filter && parse_feature_request(features, "filter"))
 			filter_capability_requested = 1;
 
@@ -997,7 +996,7 @@ static void receive_needs(struct upload_pack_data *data,
 		check_non_tip(data);
 
 	if (!use_sideband && daemon_mode)
-		no_progress = 1;
+		data->no_progress = 1;
 
 	if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
 		return;
@@ -1279,19 +1278,19 @@ static void process_args(struct packet_reader *request,
 
 		/* process args like thin-pack */
 		if (!strcmp(arg, "thin-pack")) {
-			use_thin_pack = 1;
+			data->use_thin_pack = 1;
 			continue;
 		}
 		if (!strcmp(arg, "ofs-delta")) {
-			use_ofs_delta = 1;
+			data->use_ofs_delta = 1;
 			continue;
 		}
 		if (!strcmp(arg, "no-progress")) {
-			no_progress = 1;
+			data->no_progress = 1;
 			continue;
 		}
 		if (!strcmp(arg, "include-tag")) {
-			use_include_tag = 1;
+			data->use_include_tag = 1;
 			continue;
 		}
 		if (!strcmp(arg, "done")) {
-- 
2.27.0.rc0.26.g636377a2c4


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v2 02/13] upload-pack: annotate upload_pack_data fields
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
  2020-06-02  4:16     ` [PATCH v2 01/13] upload-pack: actually use some upload_pack_data bitfields Christian Couder
@ 2020-06-02  4:16     ` Christian Couder
  2020-06-02  4:16     ` [PATCH v2 03/13] upload-pack: move static vars to upload_pack_data Christian Couder
                       ` (13 subsequent siblings)
  15 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:16 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's annotate fields from this struct to let
people know which ones are used only for protocol v0 and which
ones only for protocol v2.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 2fa645834a..3963a3805e 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -70,12 +70,16 @@ static int allow_ref_in_want;
 
 static int allow_sideband_all;
 
+/*
+ * Please annotate, and if possible group together, fields used only
+ * for protocol v0 or only for protocol v2.
+ */
 struct upload_pack_data {
-	struct string_list symref;
-	struct string_list wanted_refs;
+	struct string_list symref;				/* v0 only */
 	struct object_array want_obj;
 	struct object_array have_obj;
-	struct oid_array haves;
+	struct oid_array haves;					/* v2 only */
+	struct string_list wanted_refs;				/* v2 only */
 
 	struct object_array shallows;
 	struct string_list deepen_not;
@@ -88,13 +92,14 @@ struct upload_pack_data {
 
 	struct packet_writer writer;
 
-	unsigned stateless_rpc : 1;
+	unsigned stateless_rpc : 1;				/* v0 only */
 
 	unsigned use_thin_pack : 1;
 	unsigned use_ofs_delta : 1;
 	unsigned no_progress : 1;
 	unsigned use_include_tag : 1;
-	unsigned done : 1;
+
+	unsigned done : 1;					/* v2 only */
 };
 
 static void upload_pack_data_init(struct upload_pack_data *data)
-- 
2.27.0.rc0.26.g636377a2c4


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v2 03/13] upload-pack: move static vars to upload_pack_data
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
  2020-06-02  4:16     ` [PATCH v2 01/13] upload-pack: actually use some upload_pack_data bitfields Christian Couder
  2020-06-02  4:16     ` [PATCH v2 02/13] upload-pack: annotate upload_pack_data fields Christian Couder
@ 2020-06-02  4:16     ` Christian Couder
  2020-06-02  6:59       ` Jeff King
  2020-06-02  4:16     ` [PATCH v2 04/13] upload-pack: move use_sideband " Christian Couder
                       ` (12 subsequent siblings)
  15 siblings, 1 reply; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:16 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'no_done', 'daemon_mode' and
'timeout' variables into this struct.

They are only used by protocol v0 code since protocol v2 assumes
certain baseline capabilities, but rolling them into
upload_pack_data and just letting v2 code ignore them as it does
now is more coherent and cleaner.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 3963a3805e..21a27b2d2c 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -45,8 +45,6 @@
 static timestamp_t oldest_have;
 
 static int multi_ack;
-static int no_done;
-static int daemon_mode;
 /* Allow specifying sha1 if it is a ref tip. */
 #define ALLOW_TIP_SHA1	01
 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
@@ -56,7 +54,6 @@ static int daemon_mode;
 static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
-static unsigned int timeout;
 static int keepalive = 5;
 /* 0 for no sideband,
  * otherwise maximum packet size (up to 65520 bytes).
@@ -88,11 +85,15 @@ struct upload_pack_data {
 	int deepen_rev_list;
 	int deepen_relative;
 
+	unsigned int timeout;					/* v0 only */
+
 	struct list_objects_filter_options filter_options;
 
 	struct packet_writer writer;
 
 	unsigned stateless_rpc : 1;				/* v0 only */
+	unsigned no_done : 1;					/* v0 only */
+	unsigned daemon_mode : 1;				/* v0 only */
 
 	unsigned use_thin_pack : 1;
 	unsigned use_ofs_delta : 1;
@@ -135,7 +136,7 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
 	list_objects_filter_release(&data->filter_options);
 }
 
-static void reset_timeout(void)
+static void reset_timeout(unsigned int timeout)
 {
 	alarm(timeout);
 }
@@ -251,7 +252,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 		int pe, pu, pollsize;
 		int ret;
 
-		reset_timeout();
+		reset_timeout(pack_data->timeout);
 
 		pollsize = 0;
 		pe = pu = -1;
@@ -433,7 +434,7 @@ static int get_common_commits(struct upload_pack_data *data,
 	for (;;) {
 		const char *arg;
 
-		reset_timeout();
+		reset_timeout(data->timeout);
 
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
 			if (multi_ack == 2
@@ -446,7 +447,7 @@ static int get_common_commits(struct upload_pack_data *data,
 			if (data->have_obj.nr == 0 || multi_ack)
 				packet_write_fmt(1, "NAK\n");
 
-			if (no_done && sent_ready) {
+			if (data->no_done && sent_ready) {
 				packet_write_fmt(1, "ACK %s\n", last_hex);
 				return 0;
 			}
@@ -924,7 +925,7 @@ static void receive_needs(struct upload_pack_data *data,
 		struct object_id oid_buf;
 		const char *arg;
 
-		reset_timeout();
+		reset_timeout(data->timeout);
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL)
 			break;
 
@@ -957,7 +958,7 @@ static void receive_needs(struct upload_pack_data *data,
 		else if (parse_feature_request(features, "multi_ack"))
 			multi_ack = 1;
 		if (parse_feature_request(features, "no-done"))
-			no_done = 1;
+			data->no_done = 1;
 		if (parse_feature_request(features, "thin-pack"))
 			data->use_thin_pack = 1;
 		if (parse_feature_request(features, "ofs-delta"))
@@ -1000,7 +1001,7 @@ static void receive_needs(struct upload_pack_data *data,
 	if (has_non_tip)
 		check_non_tip(data);
 
-	if (!use_sideband && daemon_mode)
+	if (!use_sideband && data->daemon_mode)
 		data->no_progress = 1;
 
 	if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
@@ -1149,19 +1150,18 @@ void upload_pack(struct upload_pack_options *options)
 	struct packet_reader reader;
 	struct upload_pack_data data;
 
-	timeout = options->timeout;
-	daemon_mode = options->daemon_mode;
-
 	git_config(upload_pack_config, NULL);
 
 	upload_pack_data_init(&data);
 
 	data.stateless_rpc = options->stateless_rpc;
+	data.daemon_mode = options->daemon_mode;
+	data.timeout = options->timeout;
 
 	head_ref_namespaced(find_symref, &data.symref);
 
 	if (options->advertise_refs || !data.stateless_rpc) {
-		reset_timeout();
+		reset_timeout(data.timeout);
 		head_ref_namespaced(send_ref, &data);
 		for_each_namespaced_ref(send_ref, &data);
 		advertise_shallow_grafts(1);
-- 
2.27.0.rc0.26.g636377a2c4


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v2 04/13] upload-pack: move use_sideband to upload_pack_data
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
                       ` (2 preceding siblings ...)
  2020-06-02  4:16     ` [PATCH v2 03/13] upload-pack: move static vars to upload_pack_data Christian Couder
@ 2020-06-02  4:16     ` Christian Couder
  2020-06-02  4:16     ` [PATCH v2 05/13] upload-pack: move filter_capability_requested " Christian Couder
                       ` (11 subsequent siblings)
  15 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:16 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'use_sideband' static variable
into this struct.

This variable is used by both v0 and v2 protocols.

While at it, let's update the comment near the variable
definition.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 21a27b2d2c..07798fdc75 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -55,10 +55,6 @@ static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
 static int keepalive = 5;
-/* 0 for no sideband,
- * otherwise maximum packet size (up to 65520 bytes).
- */
-static int use_sideband;
 static const char *pack_objects_hook;
 
 static int filter_capability_requested;
@@ -87,6 +83,9 @@ struct upload_pack_data {
 
 	unsigned int timeout;					/* v0 only */
 
+	/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
+	int use_sideband;
+
 	struct list_objects_filter_options filter_options;
 
 	struct packet_writer writer;
@@ -141,7 +140,8 @@ static void reset_timeout(unsigned int timeout)
 	alarm(timeout);
 }
 
-static void send_client_data(int fd, const char *data, ssize_t sz)
+static void send_client_data(int fd, const char *data, ssize_t sz,
+			     int use_sideband)
 {
 	if (use_sideband) {
 		send_sideband(1, fd, data, sz, use_sideband);
@@ -290,7 +290,8 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 			sz = xread(pack_objects.err, progress,
 				  sizeof(progress));
 			if (0 < sz)
-				send_client_data(2, progress, sz);
+				send_client_data(2, progress, sz,
+						 pack_data->use_sideband);
 			else if (sz == 0) {
 				close(pack_objects.err);
 				pack_objects.err = -1;
@@ -333,7 +334,8 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 			}
 			else
 				buffered = -1;
-			send_client_data(1, data, sz);
+			send_client_data(1, data, sz,
+					 pack_data->use_sideband);
 		}
 
 		/*
@@ -346,7 +348,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 		 * protocol to say anything, so those clients are just out of
 		 * luck.
 		 */
-		if (!ret && use_sideband) {
+		if (!ret && pack_data->use_sideband) {
 			static const char buf[] = "0005\1";
 			write_or_die(1, buf, 5);
 		}
@@ -360,15 +362,17 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 	/* flush the data */
 	if (0 <= buffered) {
 		data[0] = buffered;
-		send_client_data(1, data, 1);
+		send_client_data(1, data, 1,
+				 pack_data->use_sideband);
 		fprintf(stderr, "flushed.\n");
 	}
-	if (use_sideband)
+	if (pack_data->use_sideband)
 		packet_flush(1);
 	return;
 
  fail:
-	send_client_data(3, abort_msg, sizeof(abort_msg));
+	send_client_data(3, abort_msg, sizeof(abort_msg),
+			 pack_data->use_sideband);
 	die("git upload-pack: %s", abort_msg);
 }
 
@@ -964,9 +968,9 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "ofs-delta"))
 			data->use_ofs_delta = 1;
 		if (parse_feature_request(features, "side-band-64k"))
-			use_sideband = LARGE_PACKET_MAX;
+			data->use_sideband = LARGE_PACKET_MAX;
 		else if (parse_feature_request(features, "side-band"))
-			use_sideband = DEFAULT_PACKET_MAX;
+			data->use_sideband = DEFAULT_PACKET_MAX;
 		if (parse_feature_request(features, "no-progress"))
 			data->no_progress = 1;
 		if (parse_feature_request(features, "include-tag"))
@@ -1001,7 +1005,7 @@ static void receive_needs(struct upload_pack_data *data,
 	if (has_non_tip)
 		check_non_tip(data);
 
-	if (!use_sideband && data->daemon_mode)
+	if (!data->use_sideband && data->daemon_mode)
 		data->no_progress = 1;
 
 	if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
@@ -1486,7 +1490,7 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
 	git_config(upload_pack_config, NULL);
 
 	upload_pack_data_init(&data);
-	use_sideband = LARGE_PACKET_MAX;
+	data.use_sideband = LARGE_PACKET_MAX;
 
 	while (state != FETCH_DONE) {
 		switch (state) {
-- 
2.27.0.rc0.26.g636377a2c4


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v2 05/13] upload-pack: move filter_capability_requested to upload_pack_data
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
                       ` (3 preceding siblings ...)
  2020-06-02  4:16     ` [PATCH v2 04/13] upload-pack: move use_sideband " Christian Couder
@ 2020-06-02  4:16     ` Christian Couder
  2020-06-02  4:16     ` [PATCH v2 06/13] upload-pack: move multi_ack " Christian Couder
                       ` (10 subsequent siblings)
  15 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:16 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the filter_capability_requested
static variable into this struct.

It is only used by protocol v0 code since protocol v2 assumes
certain baseline capabilities, but rolling it into
upload_pack_data and just letting v2 code ignore it as it does
now is more coherent and cleaner.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 07798fdc75..6226387a84 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -57,7 +57,6 @@ static struct object_array extra_edge_obj;
 static int keepalive = 5;
 static const char *pack_objects_hook;
 
-static int filter_capability_requested;
 static int allow_filter;
 static int allow_ref_in_want;
 
@@ -93,6 +92,7 @@ struct upload_pack_data {
 	unsigned stateless_rpc : 1;				/* v0 only */
 	unsigned no_done : 1;					/* v0 only */
 	unsigned daemon_mode : 1;				/* v0 only */
+	unsigned filter_capability_requested : 1;		/* v0 only */
 
 	unsigned use_thin_pack : 1;
 	unsigned use_ofs_delta : 1;
@@ -943,7 +943,7 @@ static void receive_needs(struct upload_pack_data *data,
 			continue;
 
 		if (skip_prefix(reader->line, "filter ", &arg)) {
-			if (!filter_capability_requested)
+			if (!data->filter_capability_requested)
 				die("git upload-pack: filtering capability not negotiated");
 			list_objects_filter_die_if_populated(&data->filter_options);
 			parse_list_objects_filter(&data->filter_options, arg);
@@ -976,7 +976,7 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "include-tag"))
 			data->use_include_tag = 1;
 		if (allow_filter && parse_feature_request(features, "filter"))
-			filter_capability_requested = 1;
+			data->filter_capability_requested = 1;
 
 		o = parse_object(the_repository, &oid_buf);
 		if (!o) {
-- 
2.27.0.rc0.26.g636377a2c4


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v2 06/13] upload-pack: move multi_ack to upload_pack_data
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
                       ` (4 preceding siblings ...)
  2020-06-02  4:16     ` [PATCH v2 05/13] upload-pack: move filter_capability_requested " Christian Couder
@ 2020-06-02  4:16     ` Christian Couder
  2020-06-02  4:16     ` [PATCH v2 07/13] upload-pack: change multi_ack to an enum Christian Couder
                       ` (9 subsequent siblings)
  15 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:16 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the multi_ack static variable into
this struct.

It is only used by protocol v0 code since protocol v2 assumes
certain baseline capabilities, but rolling it into
upload_pack_data and just letting v2 code ignore it as it does
now is more coherent and cleaner.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 6226387a84..f8611a5d53 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -44,7 +44,6 @@
 
 static timestamp_t oldest_have;
 
-static int multi_ack;
 /* Allow specifying sha1 if it is a ref tip. */
 #define ALLOW_TIP_SHA1	01
 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
@@ -81,6 +80,7 @@ struct upload_pack_data {
 	int deepen_relative;
 
 	unsigned int timeout;					/* v0 only */
+	int multi_ack;						/* v0 only */
 
 	/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
 	int use_sideband;
@@ -441,14 +441,14 @@ static int get_common_commits(struct upload_pack_data *data,
 		reset_timeout(data->timeout);
 
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
-			if (multi_ack == 2
+			if (data->multi_ack == 2
 			    && got_common
 			    && !got_other
 			    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
 				sent_ready = 1;
 				packet_write_fmt(1, "ACK %s ready\n", last_hex);
 			}
-			if (data->have_obj.nr == 0 || multi_ack)
+			if (data->have_obj.nr == 0 || data->multi_ack)
 				packet_write_fmt(1, "NAK\n");
 
 			if (data->no_done && sent_ready) {
@@ -465,10 +465,10 @@ static int get_common_commits(struct upload_pack_data *data,
 			switch (got_oid(arg, &oid, &data->have_obj)) {
 			case -1: /* they have what we do not */
 				got_other = 1;
-				if (multi_ack
+				if (data->multi_ack
 				    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
 					const char *hex = oid_to_hex(&oid);
-					if (multi_ack == 2) {
+					if (data->multi_ack == 2) {
 						sent_ready = 1;
 						packet_write_fmt(1, "ACK %s ready\n", hex);
 					} else
@@ -478,9 +478,9 @@ static int get_common_commits(struct upload_pack_data *data,
 			default:
 				got_common = 1;
 				oid_to_hex_r(last_hex, &oid);
-				if (multi_ack == 2)
+				if (data->multi_ack == 2)
 					packet_write_fmt(1, "ACK %s common\n", last_hex);
-				else if (multi_ack)
+				else if (data->multi_ack)
 					packet_write_fmt(1, "ACK %s continue\n", last_hex);
 				else if (data->have_obj.nr == 1)
 					packet_write_fmt(1, "ACK %s\n", last_hex);
@@ -490,7 +490,7 @@ static int get_common_commits(struct upload_pack_data *data,
 		}
 		if (!strcmp(reader->line, "done")) {
 			if (data->have_obj.nr > 0) {
-				if (multi_ack)
+				if (data->multi_ack)
 					packet_write_fmt(1, "ACK %s\n", last_hex);
 				return 0;
 			}
@@ -958,9 +958,9 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "deepen-relative"))
 			data->deepen_relative = 1;
 		if (parse_feature_request(features, "multi_ack_detailed"))
-			multi_ack = 2;
+			data->multi_ack = 2;
 		else if (parse_feature_request(features, "multi_ack"))
-			multi_ack = 1;
+			data->multi_ack = 1;
 		if (parse_feature_request(features, "no-done"))
 			data->no_done = 1;
 		if (parse_feature_request(features, "thin-pack"))
-- 
2.27.0.rc0.26.g636377a2c4


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v2 07/13] upload-pack: change multi_ack to an enum
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
                       ` (5 preceding siblings ...)
  2020-06-02  4:16     ` [PATCH v2 06/13] upload-pack: move multi_ack " Christian Couder
@ 2020-06-02  4:16     ` Christian Couder
  2020-06-02  4:16     ` [PATCH v2 08/13] upload-pack: pass upload_pack_data to upload_pack_config() Christian Couder
                       ` (8 subsequent siblings)
  15 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:16 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's take this opportunity to change the
'multi_ack' variable, which is now part of 'upload_pack_data',
to an enum.

This will make it clear which values this variable can take.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index f8611a5d53..83270452d4 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -80,7 +80,11 @@ struct upload_pack_data {
 	int deepen_relative;
 
 	unsigned int timeout;					/* v0 only */
-	int multi_ack;						/* v0 only */
+	enum  {
+		no_multi_ack = 0,
+		multi_ack = 1,
+		multi_ack_detailed = 2
+	} multi_ack;						/* v0 only */
 
 	/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
 	int use_sideband;
@@ -441,7 +445,7 @@ static int get_common_commits(struct upload_pack_data *data,
 		reset_timeout(data->timeout);
 
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
-			if (data->multi_ack == 2
+			if (data->multi_ack == multi_ack_detailed
 			    && got_common
 			    && !got_other
 			    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
@@ -468,7 +472,7 @@ static int get_common_commits(struct upload_pack_data *data,
 				if (data->multi_ack
 				    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
 					const char *hex = oid_to_hex(&oid);
-					if (data->multi_ack == 2) {
+					if (data->multi_ack == multi_ack_detailed) {
 						sent_ready = 1;
 						packet_write_fmt(1, "ACK %s ready\n", hex);
 					} else
@@ -478,7 +482,7 @@ static int get_common_commits(struct upload_pack_data *data,
 			default:
 				got_common = 1;
 				oid_to_hex_r(last_hex, &oid);
-				if (data->multi_ack == 2)
+				if (data->multi_ack == multi_ack_detailed)
 					packet_write_fmt(1, "ACK %s common\n", last_hex);
 				else if (data->multi_ack)
 					packet_write_fmt(1, "ACK %s continue\n", last_hex);
@@ -958,9 +962,9 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "deepen-relative"))
 			data->deepen_relative = 1;
 		if (parse_feature_request(features, "multi_ack_detailed"))
-			data->multi_ack = 2;
+			data->multi_ack = multi_ack_detailed;
 		else if (parse_feature_request(features, "multi_ack"))
-			data->multi_ack = 1;
+			data->multi_ack = multi_ack;
 		if (parse_feature_request(features, "no-done"))
 			data->no_done = 1;
 		if (parse_feature_request(features, "thin-pack"))
-- 
2.27.0.rc0.26.g636377a2c4


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v2 08/13] upload-pack: pass upload_pack_data to upload_pack_config()
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
                       ` (6 preceding siblings ...)
  2020-06-02  4:16     ` [PATCH v2 07/13] upload-pack: change multi_ack to an enum Christian Couder
@ 2020-06-02  4:16     ` Christian Couder
  2020-06-02  4:16     ` [PATCH v2 09/13] upload-pack: move keepalive to upload_pack_data Christian Couder
                       ` (7 subsequent siblings)
  15 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:16 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass that struct to upload_pack_config(),
so that this function can use all the fields of the struct.

This will be used in followup commits to move static variables
that are set in upload_pack_config() into 'upload_pack_data'.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 83270452d4..7b0954794a 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1113,7 +1113,7 @@ static int find_symref(const char *refname, const struct object_id *oid,
 	return 0;
 }
 
-static int upload_pack_config(const char *var, const char *value, void *unused)
+static int upload_pack_config(const char *var, const char *value, void *cb_data)
 {
 	if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
 		if (git_config_bool(var, value))
@@ -1158,10 +1158,10 @@ void upload_pack(struct upload_pack_options *options)
 	struct packet_reader reader;
 	struct upload_pack_data data;
 
-	git_config(upload_pack_config, NULL);
-
 	upload_pack_data_init(&data);
 
+	git_config(upload_pack_config, &data);
+
 	data.stateless_rpc = options->stateless_rpc;
 	data.daemon_mode = options->daemon_mode;
 	data.timeout = options->timeout;
@@ -1491,11 +1491,11 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
 
 	clear_object_flags(ALL_FLAGS);
 
-	git_config(upload_pack_config, NULL);
-
 	upload_pack_data_init(&data);
 	data.use_sideband = LARGE_PACKET_MAX;
 
+	git_config(upload_pack_config, &data);
+
 	while (state != FETCH_DONE) {
 		switch (state) {
 		case FETCH_PROCESS_ARGS:
-- 
2.27.0.rc0.26.g636377a2c4


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v2 09/13] upload-pack: move keepalive to upload_pack_data
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
                       ` (7 preceding siblings ...)
  2020-06-02  4:16     ` [PATCH v2 08/13] upload-pack: pass upload_pack_data to upload_pack_config() Christian Couder
@ 2020-06-02  4:16     ` Christian Couder
  2020-06-02  4:16     ` [PATCH v2 10/13] upload-pack: move allow_filter " Christian Couder
                       ` (6 subsequent siblings)
  15 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:16 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'keepalive' static variable
into this struct.

It is used by code common to protocol v0 and protocol v2.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 7b0954794a..2695b52147 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -53,7 +53,6 @@ static timestamp_t oldest_have;
 static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
-static int keepalive = 5;
 static const char *pack_objects_hook;
 
 static int allow_filter;
@@ -78,6 +77,7 @@ struct upload_pack_data {
 	timestamp_t deepen_since;
 	int deepen_rev_list;
 	int deepen_relative;
+	int keepalive;
 
 	unsigned int timeout;					/* v0 only */
 	enum  {
@@ -125,6 +125,8 @@ static void upload_pack_data_init(struct upload_pack_data *data)
 	data->shallows = shallows;
 	data->deepen_not = deepen_not;
 	packet_writer_init(&data->writer, 1);
+
+	data->keepalive = 5;
 }
 
 static void upload_pack_data_clear(struct upload_pack_data *data)
@@ -253,7 +255,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 
 	while (1) {
 		struct pollfd pfd[2];
-		int pe, pu, pollsize;
+		int pe, pu, pollsize, polltimeout;
 		int ret;
 
 		reset_timeout(pack_data->timeout);
@@ -277,8 +279,11 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 		if (!pollsize)
 			break;
 
-		ret = poll(pfd, pollsize,
-			keepalive < 0 ? -1 : 1000 * keepalive);
+		polltimeout = pack_data->keepalive < 0
+			? -1
+			: 1000 * pack_data->keepalive;
+
+		ret = poll(pfd, pollsize, polltimeout);
 
 		if (ret < 0) {
 			if (errno != EINTR) {
@@ -1115,6 +1120,8 @@ static int find_symref(const char *refname, const struct object_id *oid,
 
 static int upload_pack_config(const char *var, const char *value, void *cb_data)
 {
+	struct upload_pack_data *data = cb_data;
+
 	if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
 		if (git_config_bool(var, value))
 			allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
@@ -1131,9 +1138,9 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 		else
 			allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
 	} else if (!strcmp("uploadpack.keepalive", var)) {
-		keepalive = git_config_int(var, value);
-		if (!keepalive)
-			keepalive = -1;
+		data->keepalive = git_config_int(var, value);
+		if (!data->keepalive)
+			data->keepalive = -1;
 	} else if (!strcmp("uploadpack.allowfilter", var)) {
 		allow_filter = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowrefinwant", var)) {
-- 
2.27.0.rc0.26.g636377a2c4


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v2 10/13] upload-pack: move allow_filter to upload_pack_data
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
                       ` (8 preceding siblings ...)
  2020-06-02  4:16     ` [PATCH v2 09/13] upload-pack: move keepalive to upload_pack_data Christian Couder
@ 2020-06-02  4:16     ` Christian Couder
  2020-06-02  4:16     ` [PATCH v2 11/13] upload-pack: move allow_ref_in_want " Christian Couder
                       ` (5 subsequent siblings)
  15 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:16 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'allow_filter' static variable
into this struct.

It is used by both protocol v0 and protocol v2 code.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 2695b52147..538160801d 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -55,7 +55,6 @@ static int shallow_nr;
 static struct object_array extra_edge_obj;
 static const char *pack_objects_hook;
 
-static int allow_filter;
 static int allow_ref_in_want;
 
 static int allow_sideband_all;
@@ -102,6 +101,7 @@ struct upload_pack_data {
 	unsigned use_ofs_delta : 1;
 	unsigned no_progress : 1;
 	unsigned use_include_tag : 1;
+	unsigned allow_filter : 1;
 
 	unsigned done : 1;					/* v2 only */
 };
@@ -984,7 +984,8 @@ static void receive_needs(struct upload_pack_data *data,
 			data->no_progress = 1;
 		if (parse_feature_request(features, "include-tag"))
 			data->use_include_tag = 1;
-		if (allow_filter && parse_feature_request(features, "filter"))
+		if (data->allow_filter &&
+		    parse_feature_request(features, "filter"))
 			data->filter_capability_requested = 1;
 
 		o = parse_object(the_repository, &oid_buf);
@@ -1090,7 +1091,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
 				     " allow-reachable-sha1-in-want" : "",
 			     data->stateless_rpc ? " no-done" : "",
 			     symref_info.buf,
-			     allow_filter ? " filter" : "",
+			     data->allow_filter ? " filter" : "",
 			     git_user_agent_sanitized());
 		strbuf_release(&symref_info);
 	} else {
@@ -1142,7 +1143,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 		if (!data->keepalive)
 			data->keepalive = -1;
 	} else if (!strcmp("uploadpack.allowfilter", var)) {
-		allow_filter = git_config_bool(var, value);
+		data->allow_filter = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowrefinwant", var)) {
 		allow_ref_in_want = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowsidebandall", var)) {
@@ -1334,7 +1335,7 @@ static void process_args(struct packet_reader *request,
 			continue;
 		}
 
-		if (allow_filter && skip_prefix(arg, "filter ", &p)) {
+		if (data->allow_filter && skip_prefix(arg, "filter ", &p)) {
 			list_objects_filter_die_if_populated(&data->filter_options);
 			parse_list_objects_filter(&data->filter_options, p);
 			continue;
-- 
2.27.0.rc0.26.g636377a2c4


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v2 11/13] upload-pack: move allow_ref_in_want to upload_pack_data
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
                       ` (9 preceding siblings ...)
  2020-06-02  4:16     ` [PATCH v2 10/13] upload-pack: move allow_filter " Christian Couder
@ 2020-06-02  4:16     ` Christian Couder
  2020-06-02  4:16     ` [PATCH v2 12/13] upload-pack: move allow_sideband_all " Christian Couder
                       ` (4 subsequent siblings)
  15 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:16 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'allow_ref_in_want' static
variable into this struct.

It is used only by protocol v2 code.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 538160801d..3c00d79443 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -55,8 +55,6 @@ static int shallow_nr;
 static struct object_array extra_edge_obj;
 static const char *pack_objects_hook;
 
-static int allow_ref_in_want;
-
 static int allow_sideband_all;
 
 /*
@@ -104,6 +102,7 @@ struct upload_pack_data {
 	unsigned allow_filter : 1;
 
 	unsigned done : 1;					/* v2 only */
+	unsigned allow_ref_in_want : 1;				/* v2 only */
 };
 
 static void upload_pack_data_init(struct upload_pack_data *data)
@@ -1145,7 +1144,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 	} else if (!strcmp("uploadpack.allowfilter", var)) {
 		data->allow_filter = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowrefinwant", var)) {
-		allow_ref_in_want = git_config_bool(var, value);
+		data->allow_ref_in_want = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowsidebandall", var)) {
 		allow_sideband_all = git_config_bool(var, value);
 	} else if (!strcmp("core.precomposeunicode", var)) {
@@ -1289,7 +1288,7 @@ static void process_args(struct packet_reader *request,
 		/* process want */
 		if (parse_want(&data->writer, arg, &data->want_obj))
 			continue;
-		if (allow_ref_in_want &&
+		if (data->allow_ref_in_want &&
 		    parse_want_ref(&data->writer, arg, &data->wanted_refs,
 				   &data->want_obj))
 			continue;
-- 
2.27.0.rc0.26.g636377a2c4


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v2 12/13] upload-pack: move allow_sideband_all to upload_pack_data
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
                       ` (10 preceding siblings ...)
  2020-06-02  4:16     ` [PATCH v2 11/13] upload-pack: move allow_ref_in_want " Christian Couder
@ 2020-06-02  4:16     ` Christian Couder
  2020-06-02  4:16     ` [PATCH v2 13/13] upload-pack: move pack_objects_hook " Christian Couder
                       ` (3 subsequent siblings)
  15 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:16 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'allow_sideband_all' static
variable into this struct.

It is used only by protocol v2 code.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 3c00d79443..0887410791 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -55,8 +55,6 @@ static int shallow_nr;
 static struct object_array extra_edge_obj;
 static const char *pack_objects_hook;
 
-static int allow_sideband_all;
-
 /*
  * Please annotate, and if possible group together, fields used only
  * for protocol v0 or only for protocol v2.
@@ -103,6 +101,7 @@ struct upload_pack_data {
 
 	unsigned done : 1;					/* v2 only */
 	unsigned allow_ref_in_want : 1;				/* v2 only */
+	unsigned allow_sideband_all : 1;			/* v2 only */
 };
 
 static void upload_pack_data_init(struct upload_pack_data *data)
@@ -1146,7 +1145,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 	} else if (!strcmp("uploadpack.allowrefinwant", var)) {
 		data->allow_ref_in_want = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowsidebandall", var)) {
-		allow_sideband_all = git_config_bool(var, value);
+		data->allow_sideband_all = git_config_bool(var, value);
 	} else if (!strcmp("core.precomposeunicode", var)) {
 		precomposed_unicode = git_config_bool(var, value);
 	}
@@ -1341,7 +1340,7 @@ static void process_args(struct packet_reader *request,
 		}
 
 		if ((git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) ||
-		     allow_sideband_all) &&
+		     data->allow_sideband_all) &&
 		    !strcmp(arg, "sideband-all")) {
 			data->writer.use_sideband = 1;
 			continue;
-- 
2.27.0.rc0.26.g636377a2c4


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v2 13/13] upload-pack: move pack_objects_hook to upload_pack_data
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
                       ` (11 preceding siblings ...)
  2020-06-02  4:16     ` [PATCH v2 12/13] upload-pack: move allow_sideband_all " Christian Couder
@ 2020-06-02  4:16     ` Christian Couder
  2020-06-02  7:08     ` [PATCH v2 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Jeff King
                       ` (2 subsequent siblings)
  15 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:16 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'pack_objects_hook' static
variable into this struct.

It is used by code common to protocol v0 and protocol v2.

While at it let's also free() it in upload_pack_data_clear().

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 0887410791..30e8c54060 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -53,7 +53,6 @@ static timestamp_t oldest_have;
 static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
-static const char *pack_objects_hook;
 
 /*
  * Please annotate, and if possible group together, fields used only
@@ -88,6 +87,8 @@ struct upload_pack_data {
 
 	struct packet_writer writer;
 
+	const char *pack_objects_hook;
+
 	unsigned stateless_rpc : 1;				/* v0 only */
 	unsigned no_done : 1;					/* v0 only */
 	unsigned daemon_mode : 1;				/* v0 only */
@@ -137,6 +138,8 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
 	object_array_clear(&data->shallows);
 	string_list_clear(&data->deepen_not, 0);
 	list_objects_filter_release(&data->filter_options);
+
+	free((char *)data->pack_objects_hook);
 }
 
 static void reset_timeout(unsigned int timeout)
@@ -181,10 +184,10 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 	int i;
 	FILE *pipe_fd;
 
-	if (!pack_objects_hook)
+	if (!pack_data->pack_objects_hook)
 		pack_objects.git_cmd = 1;
 	else {
-		argv_array_push(&pack_objects.args, pack_objects_hook);
+		argv_array_push(&pack_objects.args, pack_data->pack_objects_hook);
 		argv_array_push(&pack_objects.args, "git");
 		pack_objects.use_shell = 1;
 	}
@@ -1153,7 +1156,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 	if (current_config_scope() != CONFIG_SCOPE_LOCAL &&
 	current_config_scope() != CONFIG_SCOPE_WORKTREE) {
 		if (!strcmp("uploadpack.packobjectshook", var))
-			return git_config_string(&pack_objects_hook, var, value);
+			return git_config_string(&data->pack_objects_hook, var, value);
 	}
 
 	return parse_hide_refs_config(var, value, "uploadpack");
-- 
2.27.0.rc0.26.g636377a2c4


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* Re: [PATCH 02/12] upload-pack: move static vars to upload_pack_data
  2020-05-27 18:06     ` Jeff King
@ 2020-06-02  4:19       ` Christian Couder
  0 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02  4:19 UTC (permalink / raw)
  To: Jeff King
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Wed, May 27, 2020 at 8:06 PM Jeff King <peff@peff.net> wrote:
>
> On Wed, May 27, 2020 at 06:47:32PM +0200, Christian Couder wrote:

> > They are only used by protocol v0 code since protocol v2 assumes
> > certain baseline capabilities, but rolling them into
> > upload_pack_data and just letting v2 code ignore them as it does
> > now is more coherent and cleaner.
>
> Is it perhaps worth keeping these v0-only fields grouped together within
> the struct, along with a comment?

Ok, I will try to do that in part 2 and part 3.

> That way nobody has to repeat your
> research later into which ones are used and which ones are not.
>
> > -static unsigned int timeout;
>
> This was unsigned, but gets moved as...
>
> > @@ -83,18 +80,21 @@ struct upload_pack_data {
> >       timestamp_t deepen_since;
> >       int deepen_rev_list;
> >       int deepen_relative;
> > +     int timeout;
>
> ...a signed int.

Yeah, not sure what happened. Maybe I needed some coffee when I did that.

It's fixed in my current version.

Thanks,
Christian.

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH v2 03/13] upload-pack: move static vars to upload_pack_data
  2020-06-02  4:16     ` [PATCH v2 03/13] upload-pack: move static vars to upload_pack_data Christian Couder
@ 2020-06-02  6:59       ` Jeff King
  0 siblings, 0 replies; 108+ messages in thread
From: Jeff King @ 2020-06-02  6:59 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Tue, Jun 02, 2020 at 06:16:47AM +0200, Christian Couder wrote:

> -static int no_done;
> -static int daemon_mode;
> [...]
> +	unsigned no_done : 1;					/* v0 only */
> +	unsigned daemon_mode : 1;				/* v0 only */

These ones go from int to bitfield. It looks like we only ever assign
0/1 to them. Looks good.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH v2 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
                       ` (12 preceding siblings ...)
  2020-06-02  4:16     ` [PATCH v2 13/13] upload-pack: move pack_objects_hook " Christian Couder
@ 2020-06-02  7:08     ` Jeff King
  2020-06-02 17:24       ` Junio C Hamano
  2020-06-02 19:05     ` [PATCH] fixup! upload-pack: change multi_ack to an enum Jonathan Tan
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
  15 siblings, 1 reply; 108+ messages in thread
From: Jeff King @ 2020-06-02  7:08 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Tue, Jun 02, 2020 at 06:16:44AM +0200, Christian Couder wrote:

> Compared to V1 the changes are the following:
> [...]

Thanks, this version looks good to me.

-Peff

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH v2 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2
  2020-06-02  7:08     ` [PATCH v2 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Jeff King
@ 2020-06-02 17:24       ` Junio C Hamano
  0 siblings, 0 replies; 108+ messages in thread
From: Junio C Hamano @ 2020-06-02 17:24 UTC (permalink / raw)
  To: Jeff King
  Cc: Christian Couder, git, Derrick Stolee, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

Jeff King <peff@peff.net> writes:

> On Tue, Jun 02, 2020 at 06:16:44AM +0200, Christian Couder wrote:
>
>> Compared to V1 the changes are the following:
>> [...]
>
> Thanks, this version looks good to me.

Thanks, both.


^ permalink raw reply	[flat|nested] 108+ messages in thread

* [PATCH] fixup! upload-pack: change multi_ack to an enum
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
                       ` (13 preceding siblings ...)
  2020-06-02  7:08     ` [PATCH v2 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Jeff King
@ 2020-06-02 19:05     ` Jonathan Tan
  2020-06-02 19:28       ` Christian Couder
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
  15 siblings, 1 reply; 108+ messages in thread
From: Jonathan Tan @ 2020-06-02 19:05 UTC (permalink / raw)
  To: git; +Cc: Jonathan Tan, christian.couder, peff, gitster

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
I think enum values should be all-caps, so here is a fixup for that. I
also fixed a spacing issue (2 spaces between "enum" and "{").

Also, maybe replace the first paragraph of the 1st patch:

  As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
  more thoroughly, let's actually start using some bitfields of
  that struct, which were previously unused.

with:

  As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
  more thoroughly, let's actually start using some bitfields of
  that struct. These bitfields were introduced in 3145ea957d
  ("upload-pack: introduce fetch server command", 2018-03-15) but were
  never used.

Other than that, this patch set looks good to me.

 upload-pack.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 30e8c54060..bc7e3ca19d 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -74,10 +74,10 @@ struct upload_pack_data {
 	int keepalive;
 
 	unsigned int timeout;					/* v0 only */
-	enum  {
-		no_multi_ack = 0,
-		multi_ack = 1,
-		multi_ack_detailed = 2
+	enum {
+		NO_MULTI_ACK = 0,
+		MULTI_ACK = 1,
+		MULTI_ACK_DETAILED = 2
 	} multi_ack;						/* v0 only */
 
 	/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
@@ -451,7 +451,7 @@ static int get_common_commits(struct upload_pack_data *data,
 		reset_timeout(data->timeout);
 
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
-			if (data->multi_ack == multi_ack_detailed
+			if (data->multi_ack == MULTI_ACK_DETAILED
 			    && got_common
 			    && !got_other
 			    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
@@ -478,7 +478,7 @@ static int get_common_commits(struct upload_pack_data *data,
 				if (data->multi_ack
 				    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
 					const char *hex = oid_to_hex(&oid);
-					if (data->multi_ack == multi_ack_detailed) {
+					if (data->multi_ack == MULTI_ACK_DETAILED) {
 						sent_ready = 1;
 						packet_write_fmt(1, "ACK %s ready\n", hex);
 					} else
@@ -488,7 +488,7 @@ static int get_common_commits(struct upload_pack_data *data,
 			default:
 				got_common = 1;
 				oid_to_hex_r(last_hex, &oid);
-				if (data->multi_ack == multi_ack_detailed)
+				if (data->multi_ack == MULTI_ACK_DETAILED)
 					packet_write_fmt(1, "ACK %s common\n", last_hex);
 				else if (data->multi_ack)
 					packet_write_fmt(1, "ACK %s continue\n", last_hex);
@@ -968,9 +968,9 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "deepen-relative"))
 			data->deepen_relative = 1;
 		if (parse_feature_request(features, "multi_ack_detailed"))
-			data->multi_ack = multi_ack_detailed;
+			data->multi_ack = MULTI_ACK_DETAILED;
 		else if (parse_feature_request(features, "multi_ack"))
-			data->multi_ack = multi_ack;
+			data->multi_ack = MULTI_ACK;
 		if (parse_feature_request(features, "no-done"))
 			data->no_done = 1;
 		if (parse_feature_request(features, "thin-pack"))
-- 
2.27.0.rc2.251.g90737beb825-goog


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* Re: [PATCH] fixup! upload-pack: change multi_ack to an enum
  2020-06-02 19:05     ` [PATCH] fixup! upload-pack: change multi_ack to an enum Jonathan Tan
@ 2020-06-02 19:28       ` Christian Couder
  0 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-02 19:28 UTC (permalink / raw)
  To: Jonathan Tan; +Cc: git, Jeff King, Junio C Hamano

On Tue, Jun 2, 2020 at 9:05 PM Jonathan Tan <jonathantanmy@google.com> wrote:
>
> Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
> ---

Thanks for the patch!

> I think enum values should be all-caps, so here is a fixup for that.

It's true that they are often all-caps, but there are a number of
places where some enum values are lower case like:

- apply.h
- dir.c
- pretty.c
...

> I also fixed a spacing issue (2 spaces between "enum" and "{").

Thanks for that.

> Also, maybe replace the first paragraph of the 1st patch:
>
>   As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
>   more thoroughly, let's actually start using some bitfields of
>   that struct, which were previously unused.
>
> with:
>
>   As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
>   more thoroughly, let's actually start using some bitfields of
>   that struct. These bitfields were introduced in 3145ea957d
>   ("upload-pack: introduce fetch server command", 2018-03-15) but were
>   never used.

Yeah, it seems better.

> Other than that, this patch set looks good to me.

Thank you for your review. I am ok to resend a V3 of the part 2 patch
series with all these changes. If having all-caps enum values is not
required though, I wonder if it's worth resending everything.

^ permalink raw reply	[flat|nested] 108+ messages in thread

* [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2
  2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
                       ` (14 preceding siblings ...)
  2020-06-02 19:05     ` [PATCH] fixup! upload-pack: change multi_ack to an enum Jonathan Tan
@ 2020-06-04 17:54     ` Christian Couder
  2020-06-04 17:54       ` [PATCH v3 01/13] upload-pack: actually use some upload_pack_data bitfields Christian Couder
                         ` (13 more replies)
  15 siblings, 14 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-04 17:54 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

This patch series is the second part of an effort to move all static
variables in 'upload-pack.c' into 'struct upload_pack_data'.

It is based on 'cc/upload-pack-data' which contains "part 1" of this
effort. (See also: https://lore.kernel.org/git/20200515100454.14486-1-chriscool@tuxfamily.org/)

A part 3 will follow with the rest of the patches needed to get rid of
the static variables left after this patch series.

Thanks to Peff for his review of the first and second versions of this
part 2:

V1: https://lore.kernel.org/git/20200527164742.23067-1-chriscool@tuxfamily.org/
V2: https://lore.kernel.org/git/20200602041657.7132-1-chriscool@tuxfamily.org/

Thanks to Jonathan Tan for his review of V2 too.

Compared to V2 the changes are the following:

  - patch 01/13 integrates Jonathan's commit message improvement

  - patch 07/13 integrates Jonathan's fixup patch which makes
    multi_ack enum values all-caps and fixes a spacing issue (2 spaces
    between "enum" and "{")

There is a lot of noise in the range-diff with V2, because V3 contains
Peff's 'Acked-by:' and Junio's 'Signed-off-by', but here it is:

 1:  e5c31f30ec !  1:  12f8a9c953 upload-pack: actually use some upload_pack_data bitfields
    @@ Commit message
     
         As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
         more thoroughly, let's actually start using some bitfields of
    -    that struct, which were previously unused.
    +    that struct. These bitfields were introduced in 3145ea957d
    +    ("upload-pack: introduce fetch server command", 2018-03-15), but
    +    were never used.
     
         We could instead have just removed the following bitfields
         from the struct:
    @@ Commit message
         fixing a bug, but one nobody is likely to see, because it would
         imply the client sending different capabilities for each request.
     
    +    Helped-by: Jonathan Tan <jonathantanmy@google.com>
         Signed-off-by: Jeff King <peff@peff.net>
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
    +    Acked-by: Jeff King <peff@peff.net>
    +    Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
      ## upload-pack.c ##
     @@ upload-pack.c: static timestamp_t oldest_have;
 2:  225be644f4 !  2:  b74c2f4d64 upload-pack: annotate upload_pack_data fields
    @@ Commit message
         ones only for protocol v2.
     
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
    +    Acked-by: Jeff King <peff@peff.net>
    +    Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
      ## upload-pack.c ##
     @@ upload-pack.c: static int allow_ref_in_want;
 3:  5adca8d70c !  3:  05cb66320a upload-pack: move static vars to upload_pack_data
    @@ Commit message
         now is more coherent and cleaner.
     
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
    +    Acked-by: Jeff King <peff@peff.net>
    +    Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
      ## upload-pack.c ##
     @@
 4:  1507a8134a !  4:  be32b64b0a upload-pack: move use_sideband to upload_pack_data
    @@ Commit message
         definition.
     
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
    +    Acked-by: Jeff King <peff@peff.net>
    +    Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
      ## upload-pack.c ##
     @@ upload-pack.c: static unsigned int allow_unadvertised_object_request;
 5:  0ef8d28958 !  5:  154651241d upload-pack: move filter_capability_requested to upload_pack_data
    @@ Commit message
         now is more coherent and cleaner.
     
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
    +    Acked-by: Jeff King <peff@peff.net>
    +    Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
      ## upload-pack.c ##
     @@ upload-pack.c: static struct object_array extra_edge_obj;
 6:  319c09ce02 !  6:  ba6999dc74 upload-pack: move multi_ack to upload_pack_data
    @@ Commit message
         now is more coherent and cleaner.
     
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
    +    Acked-by: Jeff King <peff@peff.net>
    +    Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
      ## upload-pack.c ##
     @@
 7:  cd3a0a1e5c !  7:  988e2e1d9a upload-pack: change multi_ack to an enum
    @@ Commit message
     
         This will make it clear which values this variable can take.
     
    +    Helped-by: Jonathan Tan <jonathantanmy@google.com>
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
    +    Acked-by: Jeff King <peff@peff.net>
    +    Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
      ## upload-pack.c ##
     @@ upload-pack.c: struct upload_pack_data {
    @@ upload-pack.c: struct upload_pack_data {
      
        unsigned int timeout;                                   /* v0 only */
     -  int multi_ack;                                          /* v0 only */
    -+  enum  {
    -+          no_multi_ack = 0,
    -+          multi_ack = 1,
    -+          multi_ack_detailed = 2
    ++  enum {
    ++          NO_MULTI_ACK = 0,
    ++          MULTI_ACK = 1,
    ++          MULTI_ACK_DETAILED = 2
     +  } multi_ack;                                            /* v0 only */
      
        /* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
    @@ upload-pack.c: static int get_common_commits(struct upload_pack_data *data,
      
                if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
     -                  if (data->multi_ack == 2
    -+                  if (data->multi_ack == multi_ack_detailed
    ++                  if (data->multi_ack == MULTI_ACK_DETAILED
                            && got_common
                            && !got_other
                            && ok_to_give_up(&data->have_obj, &data->want_obj)) {
    @@ upload-pack.c: static int get_common_commits(struct upload_pack_data *data,
                                    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
                                        const char *hex = oid_to_hex(&oid);
     -                                  if (data->multi_ack == 2) {
    -+                                  if (data->multi_ack == multi_ack_detailed) {
    ++                                  if (data->multi_ack == MULTI_ACK_DETAILED) {
                                                sent_ready = 1;
                                                packet_write_fmt(1, "ACK %s ready\n", hex);
                                        } else
    @@ upload-pack.c: static int get_common_commits(struct upload_pack_data *data,
                                got_common = 1;
                                oid_to_hex_r(last_hex, &oid);
     -                          if (data->multi_ack == 2)
    -+                          if (data->multi_ack == multi_ack_detailed)
    ++                          if (data->multi_ack == MULTI_ACK_DETAILED)
                                        packet_write_fmt(1, "ACK %s common\n", last_hex);
                                else if (data->multi_ack)
                                        packet_write_fmt(1, "ACK %s continue\n", last_hex);
    @@ upload-pack.c: static void receive_needs(struct upload_pack_data *data,
                        data->deepen_relative = 1;
                if (parse_feature_request(features, "multi_ack_detailed"))
     -                  data->multi_ack = 2;
    -+                  data->multi_ack = multi_ack_detailed;
    ++                  data->multi_ack = MULTI_ACK_DETAILED;
                else if (parse_feature_request(features, "multi_ack"))
     -                  data->multi_ack = 1;
    -+                  data->multi_ack = multi_ack;
    ++                  data->multi_ack = MULTI_ACK;
                if (parse_feature_request(features, "no-done"))
                        data->no_done = 1;
                if (parse_feature_request(features, "thin-pack"))
 8:  c23e37a8da !  8:  8dcd7dddc2 upload-pack: pass upload_pack_data to upload_pack_config()
    @@ Commit message
         that are set in upload_pack_config() into 'upload_pack_data'.
     
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
    +    Acked-by: Jeff King <peff@peff.net>
    +    Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
      ## upload-pack.c ##
     @@ upload-pack.c: static int find_symref(const char *refname, const struct object_id *oid,
 9:  26893a4098 !  9:  8c165eef8f upload-pack: move keepalive to upload_pack_data
    @@ Commit message
         It is used by code common to protocol v0 and protocol v2.
     
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
    +    Acked-by: Jeff King <peff@peff.net>
    +    Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
      ## upload-pack.c ##
     @@ upload-pack.c: static timestamp_t oldest_have;
    @@ upload-pack.c: struct upload_pack_data {
     +  int keepalive;
      
        unsigned int timeout;                                   /* v0 only */
    -   enum  {
    +   enum {
     @@ upload-pack.c: static void upload_pack_data_init(struct upload_pack_data *data)
        data->shallows = shallows;
        data->deepen_not = deepen_not;
10:  2fa59d6c89 ! 10:  17ac2a015a upload-pack: move allow_filter to upload_pack_data
    @@ Commit message
         It is used by both protocol v0 and protocol v2 code.
     
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
    +    Acked-by: Jeff King <peff@peff.net>
    +    Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
      ## upload-pack.c ##
     @@ upload-pack.c: static int shallow_nr;
11:  d501b0f694 ! 11:  74245639d8 upload-pack: move allow_ref_in_want to upload_pack_data
    @@ Commit message
         It is used only by protocol v2 code.
     
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
    +    Acked-by: Jeff King <peff@peff.net>
    +    Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
      ## upload-pack.c ##
     @@ upload-pack.c: static int shallow_nr;
12:  90513f0543 ! 12:  d866ea2741 upload-pack: move allow_sideband_all to upload_pack_data
    @@ Commit message
         It is used only by protocol v2 code.
     
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
    +    Acked-by: Jeff King <peff@peff.net>
    +    Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
      ## upload-pack.c ##
     @@ upload-pack.c: static int shallow_nr;
13:  f2851482f5 ! 13:  fce53edae4 upload-pack: move pack_objects_hook to upload_pack_data
    @@ Commit message
         While at it let's also free() it in upload_pack_data_clear().
     
         Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
    +    Acked-by: Jeff King <peff@peff.net>
    +    Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
      ## upload-pack.c ##
     @@ upload-pack.c: static timestamp_t oldest_have;

Christian Couder (12):
  upload-pack: annotate upload_pack_data fields
  upload-pack: move static vars to upload_pack_data
  upload-pack: move use_sideband to upload_pack_data
  upload-pack: move filter_capability_requested to upload_pack_data
  upload-pack: move multi_ack to upload_pack_data
  upload-pack: change multi_ack to an enum
  upload-pack: pass upload_pack_data to upload_pack_config()
  upload-pack: move keepalive to upload_pack_data
  upload-pack: move allow_filter to upload_pack_data
  upload-pack: move allow_ref_in_want to upload_pack_data
  upload-pack: move allow_sideband_all to upload_pack_data
  upload-pack: move pack_objects_hook to upload_pack_data

Jeff King (1):
  upload-pack: actually use some upload_pack_data bitfields

 upload-pack.c | 199 ++++++++++++++++++++++++++++----------------------
 1 file changed, 110 insertions(+), 89 deletions(-)

-- 
2.27.0.rc0.26.gf2851482f5


^ permalink raw reply	[flat|nested] 108+ messages in thread

* [PATCH v3 01/13] upload-pack: actually use some upload_pack_data bitfields
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
@ 2020-06-04 17:54       ` Christian Couder
  2020-06-04 17:54       ` [PATCH v3 02/13] upload-pack: annotate upload_pack_data fields Christian Couder
                         ` (12 subsequent siblings)
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-04 17:54 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

From: Jeff King <peff@peff.net>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's actually start using some bitfields of
that struct. These bitfields were introduced in 3145ea957d
("upload-pack: introduce fetch server command", 2018-03-15), but
were never used.

We could instead have just removed the following bitfields
from the struct:

unsigned use_thin_pack : 1;
unsigned use_ofs_delta : 1;
unsigned no_progress : 1;
unsigned use_include_tag : 1;

but using them makes it possible to remove a number of static
variables with the same name and purpose from 'upload-pack.c'.

This is a behavior change, as we accidentally used to let values
in those bitfields propagate from one v2 "fetch" command to
another for ssh/git/file connections (but not for http). That's
fixing a bug, but one nobody is likely to see, because it would
imply the client sending different capabilities for each request.

Helped-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 upload-pack.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 401c9e6c4b..2fa645834a 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -46,8 +46,7 @@ static timestamp_t oldest_have;
 
 static int multi_ack;
 static int no_done;
-static int use_thin_pack, use_ofs_delta, use_include_tag;
-static int no_progress, daemon_mode;
+static int daemon_mode;
 /* Allow specifying sha1 if it is a ref tip. */
 #define ALLOW_TIP_SHA1	01
 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
@@ -186,17 +185,17 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 	}
 	argv_array_push(&pack_objects.args, "pack-objects");
 	argv_array_push(&pack_objects.args, "--revs");
-	if (use_thin_pack)
+	if (pack_data->use_thin_pack)
 		argv_array_push(&pack_objects.args, "--thin");
 
 	argv_array_push(&pack_objects.args, "--stdout");
 	if (shallow_nr)
 		argv_array_push(&pack_objects.args, "--shallow");
-	if (!no_progress)
+	if (!pack_data->no_progress)
 		argv_array_push(&pack_objects.args, "--progress");
-	if (use_ofs_delta)
+	if (pack_data->use_ofs_delta)
 		argv_array_push(&pack_objects.args, "--delta-base-offset");
-	if (use_include_tag)
+	if (pack_data->use_include_tag)
 		argv_array_push(&pack_objects.args, "--include-tag");
 	if (pack_data->filter_options.choice) {
 		const char *spec =
@@ -955,17 +954,17 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "no-done"))
 			no_done = 1;
 		if (parse_feature_request(features, "thin-pack"))
-			use_thin_pack = 1;
+			data->use_thin_pack = 1;
 		if (parse_feature_request(features, "ofs-delta"))
-			use_ofs_delta = 1;
+			data->use_ofs_delta = 1;
 		if (parse_feature_request(features, "side-band-64k"))
 			use_sideband = LARGE_PACKET_MAX;
 		else if (parse_feature_request(features, "side-band"))
 			use_sideband = DEFAULT_PACKET_MAX;
 		if (parse_feature_request(features, "no-progress"))
-			no_progress = 1;
+			data->no_progress = 1;
 		if (parse_feature_request(features, "include-tag"))
-			use_include_tag = 1;
+			data->use_include_tag = 1;
 		if (allow_filter && parse_feature_request(features, "filter"))
 			filter_capability_requested = 1;
 
@@ -997,7 +996,7 @@ static void receive_needs(struct upload_pack_data *data,
 		check_non_tip(data);
 
 	if (!use_sideband && daemon_mode)
-		no_progress = 1;
+		data->no_progress = 1;
 
 	if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
 		return;
@@ -1279,19 +1278,19 @@ static void process_args(struct packet_reader *request,
 
 		/* process args like thin-pack */
 		if (!strcmp(arg, "thin-pack")) {
-			use_thin_pack = 1;
+			data->use_thin_pack = 1;
 			continue;
 		}
 		if (!strcmp(arg, "ofs-delta")) {
-			use_ofs_delta = 1;
+			data->use_ofs_delta = 1;
 			continue;
 		}
 		if (!strcmp(arg, "no-progress")) {
-			no_progress = 1;
+			data->no_progress = 1;
 			continue;
 		}
 		if (!strcmp(arg, "include-tag")) {
-			use_include_tag = 1;
+			data->use_include_tag = 1;
 			continue;
 		}
 		if (!strcmp(arg, "done")) {
-- 
2.27.0.rc0.26.gf2851482f5


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v3 02/13] upload-pack: annotate upload_pack_data fields
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
  2020-06-04 17:54       ` [PATCH v3 01/13] upload-pack: actually use some upload_pack_data bitfields Christian Couder
@ 2020-06-04 17:54       ` Christian Couder
  2020-06-04 17:54       ` [PATCH v3 03/13] upload-pack: move static vars to upload_pack_data Christian Couder
                         ` (11 subsequent siblings)
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-04 17:54 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder,
	Christian Couder

From: Christian Couder <christian.couder@gmail.com>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's annotate fields from this struct to let
people know which ones are used only for protocol v0 and which
ones only for protocol v2.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 upload-pack.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 2fa645834a..3963a3805e 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -70,12 +70,16 @@ static int allow_ref_in_want;
 
 static int allow_sideband_all;
 
+/*
+ * Please annotate, and if possible group together, fields used only
+ * for protocol v0 or only for protocol v2.
+ */
 struct upload_pack_data {
-	struct string_list symref;
-	struct string_list wanted_refs;
+	struct string_list symref;				/* v0 only */
 	struct object_array want_obj;
 	struct object_array have_obj;
-	struct oid_array haves;
+	struct oid_array haves;					/* v2 only */
+	struct string_list wanted_refs;				/* v2 only */
 
 	struct object_array shallows;
 	struct string_list deepen_not;
@@ -88,13 +92,14 @@ struct upload_pack_data {
 
 	struct packet_writer writer;
 
-	unsigned stateless_rpc : 1;
+	unsigned stateless_rpc : 1;				/* v0 only */
 
 	unsigned use_thin_pack : 1;
 	unsigned use_ofs_delta : 1;
 	unsigned no_progress : 1;
 	unsigned use_include_tag : 1;
-	unsigned done : 1;
+
+	unsigned done : 1;					/* v2 only */
 };
 
 static void upload_pack_data_init(struct upload_pack_data *data)
-- 
2.27.0.rc0.26.gf2851482f5


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v3 03/13] upload-pack: move static vars to upload_pack_data
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
  2020-06-04 17:54       ` [PATCH v3 01/13] upload-pack: actually use some upload_pack_data bitfields Christian Couder
  2020-06-04 17:54       ` [PATCH v3 02/13] upload-pack: annotate upload_pack_data fields Christian Couder
@ 2020-06-04 17:54       ` Christian Couder
  2020-06-04 17:54       ` [PATCH v3 04/13] upload-pack: move use_sideband " Christian Couder
                         ` (10 subsequent siblings)
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-04 17:54 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder,
	Christian Couder

From: Christian Couder <christian.couder@gmail.com>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'no_done', 'daemon_mode' and
'timeout' variables into this struct.

They are only used by protocol v0 code since protocol v2 assumes
certain baseline capabilities, but rolling them into
upload_pack_data and just letting v2 code ignore them as it does
now is more coherent and cleaner.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 upload-pack.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 3963a3805e..21a27b2d2c 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -45,8 +45,6 @@
 static timestamp_t oldest_have;
 
 static int multi_ack;
-static int no_done;
-static int daemon_mode;
 /* Allow specifying sha1 if it is a ref tip. */
 #define ALLOW_TIP_SHA1	01
 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
@@ -56,7 +54,6 @@ static int daemon_mode;
 static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
-static unsigned int timeout;
 static int keepalive = 5;
 /* 0 for no sideband,
  * otherwise maximum packet size (up to 65520 bytes).
@@ -88,11 +85,15 @@ struct upload_pack_data {
 	int deepen_rev_list;
 	int deepen_relative;
 
+	unsigned int timeout;					/* v0 only */
+
 	struct list_objects_filter_options filter_options;
 
 	struct packet_writer writer;
 
 	unsigned stateless_rpc : 1;				/* v0 only */
+	unsigned no_done : 1;					/* v0 only */
+	unsigned daemon_mode : 1;				/* v0 only */
 
 	unsigned use_thin_pack : 1;
 	unsigned use_ofs_delta : 1;
@@ -135,7 +136,7 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
 	list_objects_filter_release(&data->filter_options);
 }
 
-static void reset_timeout(void)
+static void reset_timeout(unsigned int timeout)
 {
 	alarm(timeout);
 }
@@ -251,7 +252,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 		int pe, pu, pollsize;
 		int ret;
 
-		reset_timeout();
+		reset_timeout(pack_data->timeout);
 
 		pollsize = 0;
 		pe = pu = -1;
@@ -433,7 +434,7 @@ static int get_common_commits(struct upload_pack_data *data,
 	for (;;) {
 		const char *arg;
 
-		reset_timeout();
+		reset_timeout(data->timeout);
 
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
 			if (multi_ack == 2
@@ -446,7 +447,7 @@ static int get_common_commits(struct upload_pack_data *data,
 			if (data->have_obj.nr == 0 || multi_ack)
 				packet_write_fmt(1, "NAK\n");
 
-			if (no_done && sent_ready) {
+			if (data->no_done && sent_ready) {
 				packet_write_fmt(1, "ACK %s\n", last_hex);
 				return 0;
 			}
@@ -924,7 +925,7 @@ static void receive_needs(struct upload_pack_data *data,
 		struct object_id oid_buf;
 		const char *arg;
 
-		reset_timeout();
+		reset_timeout(data->timeout);
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL)
 			break;
 
@@ -957,7 +958,7 @@ static void receive_needs(struct upload_pack_data *data,
 		else if (parse_feature_request(features, "multi_ack"))
 			multi_ack = 1;
 		if (parse_feature_request(features, "no-done"))
-			no_done = 1;
+			data->no_done = 1;
 		if (parse_feature_request(features, "thin-pack"))
 			data->use_thin_pack = 1;
 		if (parse_feature_request(features, "ofs-delta"))
@@ -1000,7 +1001,7 @@ static void receive_needs(struct upload_pack_data *data,
 	if (has_non_tip)
 		check_non_tip(data);
 
-	if (!use_sideband && daemon_mode)
+	if (!use_sideband && data->daemon_mode)
 		data->no_progress = 1;
 
 	if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
@@ -1149,19 +1150,18 @@ void upload_pack(struct upload_pack_options *options)
 	struct packet_reader reader;
 	struct upload_pack_data data;
 
-	timeout = options->timeout;
-	daemon_mode = options->daemon_mode;
-
 	git_config(upload_pack_config, NULL);
 
 	upload_pack_data_init(&data);
 
 	data.stateless_rpc = options->stateless_rpc;
+	data.daemon_mode = options->daemon_mode;
+	data.timeout = options->timeout;
 
 	head_ref_namespaced(find_symref, &data.symref);
 
 	if (options->advertise_refs || !data.stateless_rpc) {
-		reset_timeout();
+		reset_timeout(data.timeout);
 		head_ref_namespaced(send_ref, &data);
 		for_each_namespaced_ref(send_ref, &data);
 		advertise_shallow_grafts(1);
-- 
2.27.0.rc0.26.gf2851482f5


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v3 04/13] upload-pack: move use_sideband to upload_pack_data
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                         ` (2 preceding siblings ...)
  2020-06-04 17:54       ` [PATCH v3 03/13] upload-pack: move static vars to upload_pack_data Christian Couder
@ 2020-06-04 17:54       ` Christian Couder
  2020-06-04 17:54       ` [PATCH v3 05/13] upload-pack: move filter_capability_requested " Christian Couder
                         ` (9 subsequent siblings)
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-04 17:54 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder,
	Christian Couder

From: Christian Couder <christian.couder@gmail.com>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'use_sideband' static variable
into this struct.

This variable is used by both v0 and v2 protocols.

While at it, let's update the comment near the variable
definition.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 upload-pack.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 21a27b2d2c..07798fdc75 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -55,10 +55,6 @@ static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
 static int keepalive = 5;
-/* 0 for no sideband,
- * otherwise maximum packet size (up to 65520 bytes).
- */
-static int use_sideband;
 static const char *pack_objects_hook;
 
 static int filter_capability_requested;
@@ -87,6 +83,9 @@ struct upload_pack_data {
 
 	unsigned int timeout;					/* v0 only */
 
+	/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
+	int use_sideband;
+
 	struct list_objects_filter_options filter_options;
 
 	struct packet_writer writer;
@@ -141,7 +140,8 @@ static void reset_timeout(unsigned int timeout)
 	alarm(timeout);
 }
 
-static void send_client_data(int fd, const char *data, ssize_t sz)
+static void send_client_data(int fd, const char *data, ssize_t sz,
+			     int use_sideband)
 {
 	if (use_sideband) {
 		send_sideband(1, fd, data, sz, use_sideband);
@@ -290,7 +290,8 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 			sz = xread(pack_objects.err, progress,
 				  sizeof(progress));
 			if (0 < sz)
-				send_client_data(2, progress, sz);
+				send_client_data(2, progress, sz,
+						 pack_data->use_sideband);
 			else if (sz == 0) {
 				close(pack_objects.err);
 				pack_objects.err = -1;
@@ -333,7 +334,8 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 			}
 			else
 				buffered = -1;
-			send_client_data(1, data, sz);
+			send_client_data(1, data, sz,
+					 pack_data->use_sideband);
 		}
 
 		/*
@@ -346,7 +348,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 		 * protocol to say anything, so those clients are just out of
 		 * luck.
 		 */
-		if (!ret && use_sideband) {
+		if (!ret && pack_data->use_sideband) {
 			static const char buf[] = "0005\1";
 			write_or_die(1, buf, 5);
 		}
@@ -360,15 +362,17 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 	/* flush the data */
 	if (0 <= buffered) {
 		data[0] = buffered;
-		send_client_data(1, data, 1);
+		send_client_data(1, data, 1,
+				 pack_data->use_sideband);
 		fprintf(stderr, "flushed.\n");
 	}
-	if (use_sideband)
+	if (pack_data->use_sideband)
 		packet_flush(1);
 	return;
 
  fail:
-	send_client_data(3, abort_msg, sizeof(abort_msg));
+	send_client_data(3, abort_msg, sizeof(abort_msg),
+			 pack_data->use_sideband);
 	die("git upload-pack: %s", abort_msg);
 }
 
@@ -964,9 +968,9 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "ofs-delta"))
 			data->use_ofs_delta = 1;
 		if (parse_feature_request(features, "side-band-64k"))
-			use_sideband = LARGE_PACKET_MAX;
+			data->use_sideband = LARGE_PACKET_MAX;
 		else if (parse_feature_request(features, "side-band"))
-			use_sideband = DEFAULT_PACKET_MAX;
+			data->use_sideband = DEFAULT_PACKET_MAX;
 		if (parse_feature_request(features, "no-progress"))
 			data->no_progress = 1;
 		if (parse_feature_request(features, "include-tag"))
@@ -1001,7 +1005,7 @@ static void receive_needs(struct upload_pack_data *data,
 	if (has_non_tip)
 		check_non_tip(data);
 
-	if (!use_sideband && data->daemon_mode)
+	if (!data->use_sideband && data->daemon_mode)
 		data->no_progress = 1;
 
 	if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
@@ -1486,7 +1490,7 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
 	git_config(upload_pack_config, NULL);
 
 	upload_pack_data_init(&data);
-	use_sideband = LARGE_PACKET_MAX;
+	data.use_sideband = LARGE_PACKET_MAX;
 
 	while (state != FETCH_DONE) {
 		switch (state) {
-- 
2.27.0.rc0.26.gf2851482f5


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v3 05/13] upload-pack: move filter_capability_requested to upload_pack_data
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                         ` (3 preceding siblings ...)
  2020-06-04 17:54       ` [PATCH v3 04/13] upload-pack: move use_sideband " Christian Couder
@ 2020-06-04 17:54       ` Christian Couder
  2020-06-04 17:54       ` [PATCH v3 06/13] upload-pack: move multi_ack " Christian Couder
                         ` (8 subsequent siblings)
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-04 17:54 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder,
	Christian Couder

From: Christian Couder <christian.couder@gmail.com>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the filter_capability_requested
static variable into this struct.

It is only used by protocol v0 code since protocol v2 assumes
certain baseline capabilities, but rolling it into
upload_pack_data and just letting v2 code ignore it as it does
now is more coherent and cleaner.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 upload-pack.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 07798fdc75..6226387a84 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -57,7 +57,6 @@ static struct object_array extra_edge_obj;
 static int keepalive = 5;
 static const char *pack_objects_hook;
 
-static int filter_capability_requested;
 static int allow_filter;
 static int allow_ref_in_want;
 
@@ -93,6 +92,7 @@ struct upload_pack_data {
 	unsigned stateless_rpc : 1;				/* v0 only */
 	unsigned no_done : 1;					/* v0 only */
 	unsigned daemon_mode : 1;				/* v0 only */
+	unsigned filter_capability_requested : 1;		/* v0 only */
 
 	unsigned use_thin_pack : 1;
 	unsigned use_ofs_delta : 1;
@@ -943,7 +943,7 @@ static void receive_needs(struct upload_pack_data *data,
 			continue;
 
 		if (skip_prefix(reader->line, "filter ", &arg)) {
-			if (!filter_capability_requested)
+			if (!data->filter_capability_requested)
 				die("git upload-pack: filtering capability not negotiated");
 			list_objects_filter_die_if_populated(&data->filter_options);
 			parse_list_objects_filter(&data->filter_options, arg);
@@ -976,7 +976,7 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "include-tag"))
 			data->use_include_tag = 1;
 		if (allow_filter && parse_feature_request(features, "filter"))
-			filter_capability_requested = 1;
+			data->filter_capability_requested = 1;
 
 		o = parse_object(the_repository, &oid_buf);
 		if (!o) {
-- 
2.27.0.rc0.26.gf2851482f5


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v3 06/13] upload-pack: move multi_ack to upload_pack_data
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                         ` (4 preceding siblings ...)
  2020-06-04 17:54       ` [PATCH v3 05/13] upload-pack: move filter_capability_requested " Christian Couder
@ 2020-06-04 17:54       ` Christian Couder
  2020-06-04 17:54       ` [PATCH v3 07/13] upload-pack: change multi_ack to an enum Christian Couder
                         ` (7 subsequent siblings)
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-04 17:54 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder,
	Christian Couder

From: Christian Couder <christian.couder@gmail.com>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the multi_ack static variable into
this struct.

It is only used by protocol v0 code since protocol v2 assumes
certain baseline capabilities, but rolling it into
upload_pack_data and just letting v2 code ignore it as it does
now is more coherent and cleaner.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 upload-pack.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 6226387a84..f8611a5d53 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -44,7 +44,6 @@
 
 static timestamp_t oldest_have;
 
-static int multi_ack;
 /* Allow specifying sha1 if it is a ref tip. */
 #define ALLOW_TIP_SHA1	01
 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
@@ -81,6 +80,7 @@ struct upload_pack_data {
 	int deepen_relative;
 
 	unsigned int timeout;					/* v0 only */
+	int multi_ack;						/* v0 only */
 
 	/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
 	int use_sideband;
@@ -441,14 +441,14 @@ static int get_common_commits(struct upload_pack_data *data,
 		reset_timeout(data->timeout);
 
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
-			if (multi_ack == 2
+			if (data->multi_ack == 2
 			    && got_common
 			    && !got_other
 			    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
 				sent_ready = 1;
 				packet_write_fmt(1, "ACK %s ready\n", last_hex);
 			}
-			if (data->have_obj.nr == 0 || multi_ack)
+			if (data->have_obj.nr == 0 || data->multi_ack)
 				packet_write_fmt(1, "NAK\n");
 
 			if (data->no_done && sent_ready) {
@@ -465,10 +465,10 @@ static int get_common_commits(struct upload_pack_data *data,
 			switch (got_oid(arg, &oid, &data->have_obj)) {
 			case -1: /* they have what we do not */
 				got_other = 1;
-				if (multi_ack
+				if (data->multi_ack
 				    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
 					const char *hex = oid_to_hex(&oid);
-					if (multi_ack == 2) {
+					if (data->multi_ack == 2) {
 						sent_ready = 1;
 						packet_write_fmt(1, "ACK %s ready\n", hex);
 					} else
@@ -478,9 +478,9 @@ static int get_common_commits(struct upload_pack_data *data,
 			default:
 				got_common = 1;
 				oid_to_hex_r(last_hex, &oid);
-				if (multi_ack == 2)
+				if (data->multi_ack == 2)
 					packet_write_fmt(1, "ACK %s common\n", last_hex);
-				else if (multi_ack)
+				else if (data->multi_ack)
 					packet_write_fmt(1, "ACK %s continue\n", last_hex);
 				else if (data->have_obj.nr == 1)
 					packet_write_fmt(1, "ACK %s\n", last_hex);
@@ -490,7 +490,7 @@ static int get_common_commits(struct upload_pack_data *data,
 		}
 		if (!strcmp(reader->line, "done")) {
 			if (data->have_obj.nr > 0) {
-				if (multi_ack)
+				if (data->multi_ack)
 					packet_write_fmt(1, "ACK %s\n", last_hex);
 				return 0;
 			}
@@ -958,9 +958,9 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "deepen-relative"))
 			data->deepen_relative = 1;
 		if (parse_feature_request(features, "multi_ack_detailed"))
-			multi_ack = 2;
+			data->multi_ack = 2;
 		else if (parse_feature_request(features, "multi_ack"))
-			multi_ack = 1;
+			data->multi_ack = 1;
 		if (parse_feature_request(features, "no-done"))
 			data->no_done = 1;
 		if (parse_feature_request(features, "thin-pack"))
-- 
2.27.0.rc0.26.gf2851482f5


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v3 07/13] upload-pack: change multi_ack to an enum
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                         ` (5 preceding siblings ...)
  2020-06-04 17:54       ` [PATCH v3 06/13] upload-pack: move multi_ack " Christian Couder
@ 2020-06-04 17:54       ` Christian Couder
  2020-06-04 17:54       ` [PATCH v3 08/13] upload-pack: pass upload_pack_data to upload_pack_config() Christian Couder
                         ` (6 subsequent siblings)
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-04 17:54 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder,
	Christian Couder

From: Christian Couder <christian.couder@gmail.com>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's take this opportunity to change the
'multi_ack' variable, which is now part of 'upload_pack_data',
to an enum.

This will make it clear which values this variable can take.

Helped-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 upload-pack.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index f8611a5d53..e7b8140e55 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -80,7 +80,11 @@ struct upload_pack_data {
 	int deepen_relative;
 
 	unsigned int timeout;					/* v0 only */
-	int multi_ack;						/* v0 only */
+	enum {
+		NO_MULTI_ACK = 0,
+		MULTI_ACK = 1,
+		MULTI_ACK_DETAILED = 2
+	} multi_ack;						/* v0 only */
 
 	/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
 	int use_sideband;
@@ -441,7 +445,7 @@ static int get_common_commits(struct upload_pack_data *data,
 		reset_timeout(data->timeout);
 
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
-			if (data->multi_ack == 2
+			if (data->multi_ack == MULTI_ACK_DETAILED
 			    && got_common
 			    && !got_other
 			    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
@@ -468,7 +472,7 @@ static int get_common_commits(struct upload_pack_data *data,
 				if (data->multi_ack
 				    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
 					const char *hex = oid_to_hex(&oid);
-					if (data->multi_ack == 2) {
+					if (data->multi_ack == MULTI_ACK_DETAILED) {
 						sent_ready = 1;
 						packet_write_fmt(1, "ACK %s ready\n", hex);
 					} else
@@ -478,7 +482,7 @@ static int get_common_commits(struct upload_pack_data *data,
 			default:
 				got_common = 1;
 				oid_to_hex_r(last_hex, &oid);
-				if (data->multi_ack == 2)
+				if (data->multi_ack == MULTI_ACK_DETAILED)
 					packet_write_fmt(1, "ACK %s common\n", last_hex);
 				else if (data->multi_ack)
 					packet_write_fmt(1, "ACK %s continue\n", last_hex);
@@ -958,9 +962,9 @@ static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "deepen-relative"))
 			data->deepen_relative = 1;
 		if (parse_feature_request(features, "multi_ack_detailed"))
-			data->multi_ack = 2;
+			data->multi_ack = MULTI_ACK_DETAILED;
 		else if (parse_feature_request(features, "multi_ack"))
-			data->multi_ack = 1;
+			data->multi_ack = MULTI_ACK;
 		if (parse_feature_request(features, "no-done"))
 			data->no_done = 1;
 		if (parse_feature_request(features, "thin-pack"))
-- 
2.27.0.rc0.26.gf2851482f5


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v3 08/13] upload-pack: pass upload_pack_data to upload_pack_config()
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                         ` (6 preceding siblings ...)
  2020-06-04 17:54       ` [PATCH v3 07/13] upload-pack: change multi_ack to an enum Christian Couder
@ 2020-06-04 17:54       ` Christian Couder
  2020-06-04 17:54       ` [PATCH v3 09/13] upload-pack: move keepalive to upload_pack_data Christian Couder
                         ` (5 subsequent siblings)
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-04 17:54 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder,
	Christian Couder

From: Christian Couder <christian.couder@gmail.com>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass that struct to upload_pack_config(),
so that this function can use all the fields of the struct.

This will be used in followup commits to move static variables
that are set in upload_pack_config() into 'upload_pack_data'.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 upload-pack.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index e7b8140e55..b846aa4728 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1113,7 +1113,7 @@ static int find_symref(const char *refname, const struct object_id *oid,
 	return 0;
 }
 
-static int upload_pack_config(const char *var, const char *value, void *unused)
+static int upload_pack_config(const char *var, const char *value, void *cb_data)
 {
 	if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
 		if (git_config_bool(var, value))
@@ -1158,10 +1158,10 @@ void upload_pack(struct upload_pack_options *options)
 	struct packet_reader reader;
 	struct upload_pack_data data;
 
-	git_config(upload_pack_config, NULL);
-
 	upload_pack_data_init(&data);
 
+	git_config(upload_pack_config, &data);
+
 	data.stateless_rpc = options->stateless_rpc;
 	data.daemon_mode = options->daemon_mode;
 	data.timeout = options->timeout;
@@ -1491,11 +1491,11 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
 
 	clear_object_flags(ALL_FLAGS);
 
-	git_config(upload_pack_config, NULL);
-
 	upload_pack_data_init(&data);
 	data.use_sideband = LARGE_PACKET_MAX;
 
+	git_config(upload_pack_config, &data);
+
 	while (state != FETCH_DONE) {
 		switch (state) {
 		case FETCH_PROCESS_ARGS:
-- 
2.27.0.rc0.26.gf2851482f5


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v3 09/13] upload-pack: move keepalive to upload_pack_data
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                         ` (7 preceding siblings ...)
  2020-06-04 17:54       ` [PATCH v3 08/13] upload-pack: pass upload_pack_data to upload_pack_config() Christian Couder
@ 2020-06-04 17:54       ` Christian Couder
  2020-06-04 17:54       ` [PATCH v3 10/13] upload-pack: move allow_filter " Christian Couder
                         ` (4 subsequent siblings)
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-04 17:54 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder,
	Christian Couder

From: Christian Couder <christian.couder@gmail.com>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'keepalive' static variable
into this struct.

It is used by code common to protocol v0 and protocol v2.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 upload-pack.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index b846aa4728..0eb4c32552 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -53,7 +53,6 @@ static timestamp_t oldest_have;
 static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
-static int keepalive = 5;
 static const char *pack_objects_hook;
 
 static int allow_filter;
@@ -78,6 +77,7 @@ struct upload_pack_data {
 	timestamp_t deepen_since;
 	int deepen_rev_list;
 	int deepen_relative;
+	int keepalive;
 
 	unsigned int timeout;					/* v0 only */
 	enum {
@@ -125,6 +125,8 @@ static void upload_pack_data_init(struct upload_pack_data *data)
 	data->shallows = shallows;
 	data->deepen_not = deepen_not;
 	packet_writer_init(&data->writer, 1);
+
+	data->keepalive = 5;
 }
 
 static void upload_pack_data_clear(struct upload_pack_data *data)
@@ -253,7 +255,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 
 	while (1) {
 		struct pollfd pfd[2];
-		int pe, pu, pollsize;
+		int pe, pu, pollsize, polltimeout;
 		int ret;
 
 		reset_timeout(pack_data->timeout);
@@ -277,8 +279,11 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 		if (!pollsize)
 			break;
 
-		ret = poll(pfd, pollsize,
-			keepalive < 0 ? -1 : 1000 * keepalive);
+		polltimeout = pack_data->keepalive < 0
+			? -1
+			: 1000 * pack_data->keepalive;
+
+		ret = poll(pfd, pollsize, polltimeout);
 
 		if (ret < 0) {
 			if (errno != EINTR) {
@@ -1115,6 +1120,8 @@ static int find_symref(const char *refname, const struct object_id *oid,
 
 static int upload_pack_config(const char *var, const char *value, void *cb_data)
 {
+	struct upload_pack_data *data = cb_data;
+
 	if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
 		if (git_config_bool(var, value))
 			allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
@@ -1131,9 +1138,9 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 		else
 			allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
 	} else if (!strcmp("uploadpack.keepalive", var)) {
-		keepalive = git_config_int(var, value);
-		if (!keepalive)
-			keepalive = -1;
+		data->keepalive = git_config_int(var, value);
+		if (!data->keepalive)
+			data->keepalive = -1;
 	} else if (!strcmp("uploadpack.allowfilter", var)) {
 		allow_filter = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowrefinwant", var)) {
-- 
2.27.0.rc0.26.gf2851482f5


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v3 10/13] upload-pack: move allow_filter to upload_pack_data
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                         ` (8 preceding siblings ...)
  2020-06-04 17:54       ` [PATCH v3 09/13] upload-pack: move keepalive to upload_pack_data Christian Couder
@ 2020-06-04 17:54       ` Christian Couder
  2020-06-04 17:54       ` [PATCH v3 11/13] upload-pack: move allow_ref_in_want " Christian Couder
                         ` (3 subsequent siblings)
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-04 17:54 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder,
	Christian Couder

From: Christian Couder <christian.couder@gmail.com>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'allow_filter' static variable
into this struct.

It is used by both protocol v0 and protocol v2 code.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 upload-pack.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 0eb4c32552..19b342d4b0 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -55,7 +55,6 @@ static int shallow_nr;
 static struct object_array extra_edge_obj;
 static const char *pack_objects_hook;
 
-static int allow_filter;
 static int allow_ref_in_want;
 
 static int allow_sideband_all;
@@ -102,6 +101,7 @@ struct upload_pack_data {
 	unsigned use_ofs_delta : 1;
 	unsigned no_progress : 1;
 	unsigned use_include_tag : 1;
+	unsigned allow_filter : 1;
 
 	unsigned done : 1;					/* v2 only */
 };
@@ -984,7 +984,8 @@ static void receive_needs(struct upload_pack_data *data,
 			data->no_progress = 1;
 		if (parse_feature_request(features, "include-tag"))
 			data->use_include_tag = 1;
-		if (allow_filter && parse_feature_request(features, "filter"))
+		if (data->allow_filter &&
+		    parse_feature_request(features, "filter"))
 			data->filter_capability_requested = 1;
 
 		o = parse_object(the_repository, &oid_buf);
@@ -1090,7 +1091,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
 				     " allow-reachable-sha1-in-want" : "",
 			     data->stateless_rpc ? " no-done" : "",
 			     symref_info.buf,
-			     allow_filter ? " filter" : "",
+			     data->allow_filter ? " filter" : "",
 			     git_user_agent_sanitized());
 		strbuf_release(&symref_info);
 	} else {
@@ -1142,7 +1143,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 		if (!data->keepalive)
 			data->keepalive = -1;
 	} else if (!strcmp("uploadpack.allowfilter", var)) {
-		allow_filter = git_config_bool(var, value);
+		data->allow_filter = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowrefinwant", var)) {
 		allow_ref_in_want = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowsidebandall", var)) {
@@ -1334,7 +1335,7 @@ static void process_args(struct packet_reader *request,
 			continue;
 		}
 
-		if (allow_filter && skip_prefix(arg, "filter ", &p)) {
+		if (data->allow_filter && skip_prefix(arg, "filter ", &p)) {
 			list_objects_filter_die_if_populated(&data->filter_options);
 			parse_list_objects_filter(&data->filter_options, p);
 			continue;
-- 
2.27.0.rc0.26.gf2851482f5


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v3 11/13] upload-pack: move allow_ref_in_want to upload_pack_data
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                         ` (9 preceding siblings ...)
  2020-06-04 17:54       ` [PATCH v3 10/13] upload-pack: move allow_filter " Christian Couder
@ 2020-06-04 17:54       ` Christian Couder
  2020-06-04 17:54       ` [PATCH v3 12/13] upload-pack: move allow_sideband_all " Christian Couder
                         ` (2 subsequent siblings)
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-04 17:54 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder,
	Christian Couder

From: Christian Couder <christian.couder@gmail.com>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'allow_ref_in_want' static
variable into this struct.

It is used only by protocol v2 code.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 upload-pack.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 19b342d4b0..0d75745d8d 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -55,8 +55,6 @@ static int shallow_nr;
 static struct object_array extra_edge_obj;
 static const char *pack_objects_hook;
 
-static int allow_ref_in_want;
-
 static int allow_sideband_all;
 
 /*
@@ -104,6 +102,7 @@ struct upload_pack_data {
 	unsigned allow_filter : 1;
 
 	unsigned done : 1;					/* v2 only */
+	unsigned allow_ref_in_want : 1;				/* v2 only */
 };
 
 static void upload_pack_data_init(struct upload_pack_data *data)
@@ -1145,7 +1144,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 	} else if (!strcmp("uploadpack.allowfilter", var)) {
 		data->allow_filter = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowrefinwant", var)) {
-		allow_ref_in_want = git_config_bool(var, value);
+		data->allow_ref_in_want = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowsidebandall", var)) {
 		allow_sideband_all = git_config_bool(var, value);
 	} else if (!strcmp("core.precomposeunicode", var)) {
@@ -1289,7 +1288,7 @@ static void process_args(struct packet_reader *request,
 		/* process want */
 		if (parse_want(&data->writer, arg, &data->want_obj))
 			continue;
-		if (allow_ref_in_want &&
+		if (data->allow_ref_in_want &&
 		    parse_want_ref(&data->writer, arg, &data->wanted_refs,
 				   &data->want_obj))
 			continue;
-- 
2.27.0.rc0.26.gf2851482f5


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v3 12/13] upload-pack: move allow_sideband_all to upload_pack_data
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                         ` (10 preceding siblings ...)
  2020-06-04 17:54       ` [PATCH v3 11/13] upload-pack: move allow_ref_in_want " Christian Couder
@ 2020-06-04 17:54       ` Christian Couder
  2020-06-04 17:54       ` [PATCH v3 13/13] upload-pack: move pack_objects_hook " Christian Couder
  2020-06-04 18:07       ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Junio C Hamano
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-04 17:54 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder,
	Christian Couder

From: Christian Couder <christian.couder@gmail.com>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'allow_sideband_all' static
variable into this struct.

It is used only by protocol v2 code.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 upload-pack.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 0d75745d8d..78b10a89ea 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -55,8 +55,6 @@ static int shallow_nr;
 static struct object_array extra_edge_obj;
 static const char *pack_objects_hook;
 
-static int allow_sideband_all;
-
 /*
  * Please annotate, and if possible group together, fields used only
  * for protocol v0 or only for protocol v2.
@@ -103,6 +101,7 @@ struct upload_pack_data {
 
 	unsigned done : 1;					/* v2 only */
 	unsigned allow_ref_in_want : 1;				/* v2 only */
+	unsigned allow_sideband_all : 1;			/* v2 only */
 };
 
 static void upload_pack_data_init(struct upload_pack_data *data)
@@ -1146,7 +1145,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 	} else if (!strcmp("uploadpack.allowrefinwant", var)) {
 		data->allow_ref_in_want = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowsidebandall", var)) {
-		allow_sideband_all = git_config_bool(var, value);
+		data->allow_sideband_all = git_config_bool(var, value);
 	} else if (!strcmp("core.precomposeunicode", var)) {
 		precomposed_unicode = git_config_bool(var, value);
 	}
@@ -1341,7 +1340,7 @@ static void process_args(struct packet_reader *request,
 		}
 
 		if ((git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) ||
-		     allow_sideband_all) &&
+		     data->allow_sideband_all) &&
 		    !strcmp(arg, "sideband-all")) {
 			data->writer.use_sideband = 1;
 			continue;
-- 
2.27.0.rc0.26.gf2851482f5


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH v3 13/13] upload-pack: move pack_objects_hook to upload_pack_data
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                         ` (11 preceding siblings ...)
  2020-06-04 17:54       ` [PATCH v3 12/13] upload-pack: move allow_sideband_all " Christian Couder
@ 2020-06-04 17:54       ` Christian Couder
  2020-06-04 18:07       ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Junio C Hamano
  13 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-04 17:54 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder,
	Christian Couder

From: Christian Couder <christian.couder@gmail.com>

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'pack_objects_hook' static
variable into this struct.

It is used by code common to protocol v0 and protocol v2.

While at it let's also free() it in upload_pack_data_clear().

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 upload-pack.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 78b10a89ea..bc7e3ca19d 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -53,7 +53,6 @@ static timestamp_t oldest_have;
 static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
-static const char *pack_objects_hook;
 
 /*
  * Please annotate, and if possible group together, fields used only
@@ -88,6 +87,8 @@ struct upload_pack_data {
 
 	struct packet_writer writer;
 
+	const char *pack_objects_hook;
+
 	unsigned stateless_rpc : 1;				/* v0 only */
 	unsigned no_done : 1;					/* v0 only */
 	unsigned daemon_mode : 1;				/* v0 only */
@@ -137,6 +138,8 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
 	object_array_clear(&data->shallows);
 	string_list_clear(&data->deepen_not, 0);
 	list_objects_filter_release(&data->filter_options);
+
+	free((char *)data->pack_objects_hook);
 }
 
 static void reset_timeout(unsigned int timeout)
@@ -181,10 +184,10 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 	int i;
 	FILE *pipe_fd;
 
-	if (!pack_objects_hook)
+	if (!pack_data->pack_objects_hook)
 		pack_objects.git_cmd = 1;
 	else {
-		argv_array_push(&pack_objects.args, pack_objects_hook);
+		argv_array_push(&pack_objects.args, pack_data->pack_objects_hook);
 		argv_array_push(&pack_objects.args, "git");
 		pack_objects.use_shell = 1;
 	}
@@ -1153,7 +1156,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 	if (current_config_scope() != CONFIG_SCOPE_LOCAL &&
 	current_config_scope() != CONFIG_SCOPE_WORKTREE) {
 		if (!strcmp("uploadpack.packobjectshook", var))
-			return git_config_string(&pack_objects_hook, var, value);
+			return git_config_string(&data->pack_objects_hook, var, value);
 	}
 
 	return parse_hide_refs_config(var, value, "uploadpack");
-- 
2.27.0.rc0.26.gf2851482f5


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* Re: [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2
  2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
                         ` (12 preceding siblings ...)
  2020-06-04 17:54       ` [PATCH v3 13/13] upload-pack: move pack_objects_hook " Christian Couder
@ 2020-06-04 18:07       ` Junio C Hamano
  2020-06-05 10:38         ` Christian Couder
  13 siblings, 1 reply; 108+ messages in thread
From: Junio C Hamano @ 2020-06-04 18:07 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Derrick Stolee, Jeff King, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

Christian Couder <christian.couder@gmail.com> writes:

> This patch series is the second part of an effort to move all static
> variables in 'upload-pack.c' into 'struct upload_pack_data'.
>
> It is based on 'cc/upload-pack-data' which contains "part 1" of this
> effort. (See also: https://lore.kernel.org/git/20200515100454.14486-1-chriscool@tuxfamily.org/)
>
> A part 3 will follow with the rest of the patches needed to get rid of
> the static variables left after this patch series.
>
> Thanks to Peff for his review of the first and second versions of this
> part 2:
>
> V1: https://lore.kernel.org/git/20200527164742.23067-1-chriscool@tuxfamily.org/
> V2: https://lore.kernel.org/git/20200602041657.7132-1-chriscool@tuxfamily.org/
>
> Thanks to Jonathan Tan for his review of V2 too.
>
> Compared to V2 the changes are the following:
>
>   - patch 01/13 integrates Jonathan's commit message improvement
>
>   - patch 07/13 integrates Jonathan's fixup patch which makes
>     multi_ack enum values all-caps and fixes a spacing issue (2 spaces
>     between "enum" and "{")

Thanks, all.

I notice that enumeration constants for "enum multi_ack" have been
upcased; I do not think it matters too much either way.  A situation
that strongly favours upper case is when the enum is the result of
converting from C preprocessor macros that were spelled with upper
case, but this is not one of those.

> There is a lot of noise in the range-diff with V2, because V3 contains
> Peff's 'Acked-by:' and Junio's 'Signed-off-by', but here it is:

Would it work as a "trick" to fetch what has been queued in 'pu' and
compare against that lets you avoid such a "noise", I wonder?  If it
works well, it would have an added benefit of having the
publically-known commit object names on the left hand side
(e.g. instead of e5c31f30ec, you'd see d293806610 as the patch 1
from the second iteration) of the range-diff.

>  1:  e5c31f30ec !  1:  12f8a9c953 upload-pack: actually use some upload_pack_data bitfields

^ permalink raw reply	[flat|nested] 108+ messages in thread

* Re: [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2
  2020-06-04 18:07       ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Junio C Hamano
@ 2020-06-05 10:38         ` Christian Couder
  0 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-05 10:38 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Derrick Stolee, Jeff King, Taylor Blau, Jonathan Tan,
	Jonathan Nieder, Christian Couder

On Thu, Jun 4, 2020 at 8:07 PM Junio C Hamano <gitster@pobox.com> wrote:

>
> Christian Couder <christian.couder@gmail.com> writes:

> > There is a lot of noise in the range-diff with V2, because V3 contains
> > Peff's 'Acked-by:' and Junio's 'Signed-off-by', but here it is:
>
> Would it work as a "trick" to fetch what has been queued in 'pu' and
> compare against that lets you avoid such a "noise", I wonder?

Yeah, probably. I will try it next time.

> If it
> works well, it would have an added benefit of having the
> publically-known commit object names on the left hand side
> (e.g. instead of e5c31f30ec, you'd see d293806610 as the patch 1
> from the second iteration) of the range-diff.

Yeah, thanks for the suggestion!

By the way another issue I had was that for some reason send-email
inserted a "From: Christian Couder <christian.couder@gmail.com>" line
at the beginning of each patch. Sorry about that.

^ permalink raw reply	[flat|nested] 108+ messages in thread

* [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3
  2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
                   ` (15 preceding siblings ...)
  2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
@ 2020-06-11 12:05 ` Christian Couder
  2020-06-11 12:05   ` [PATCH 01/14] upload-pack: pass upload_pack_data to send_shallow_list() Christian Couder
                     ` (14 more replies)
  16 siblings, 15 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

This patch series is the third and last part of an effort to move all
static variables in 'upload-pack.c' into 'struct upload_pack_data'.

It is based on 'cc/upload-pack-data-2' which contains "part 2" of this
effort.

There are no static variables left in 'upload-pack.c' after this patch
series. Patch 14/14 is a small refactoring on top which can be left
out.

Thanks to Peff, Jonathan Tan and Stolee who reviewed previous parts of
this.

Christian Couder (14):
  upload-pack: pass upload_pack_data to send_shallow_list()
  upload-pack: pass upload_pack_data to deepen()
  upload-pack: pass upload_pack_data to deepen_by_rev_list()
  upload-pack: pass upload_pack_data to send_unshallow()
  upload-pack: move shallow_nr to upload_pack_data
  upload-pack: move extra_edge_obj to upload_pack_data
  upload-pack: move allow_unadvertised_object_request to
    upload_pack_data
  upload-pack: change allow_unadvertised_object_request to an enum
  upload-pack: pass upload_pack_data to process_haves()
  upload-pack: pass upload_pack_data to send_acks()
  upload-pack: pass upload_pack_data to ok_to_give_up()
  upload-pack: pass upload_pack_data to got_oid()
  upload-pack: move oldest_have to upload_pack_data
  upload-pack: refactor common code into do_got_oid()

 upload-pack.c | 287 ++++++++++++++++++++++----------------------------
 1 file changed, 125 insertions(+), 162 deletions(-)

-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply	[flat|nested] 108+ messages in thread

* [PATCH 01/14] upload-pack: pass upload_pack_data to send_shallow_list()
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
@ 2020-06-11 12:05   ` Christian Couder
  2020-06-11 12:05   ` [PATCH 02/14] upload-pack: pass upload_pack_data to deepen() Christian Couder
                     ` (13 subsequent siblings)
  14 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass that struct to send_shallow_list(),
so that this function can use all the fields of the struct.

This will be used in followup commits to move static variables
into 'upload_pack_data'.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 57 +++++++++++++++++++--------------------------------
 1 file changed, 21 insertions(+), 36 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index bc7e3ca19d..ada9082b06 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -808,53 +808,49 @@ static void deepen_by_rev_list(struct packet_writer *writer, int ac,
 }
 
 /* Returns 1 if a shallow list is sent or 0 otherwise */
-static int send_shallow_list(struct packet_writer *writer,
-			     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)
+static int send_shallow_list(struct upload_pack_data *data)
 {
 	int ret = 0;
 
-	if (depth > 0 && deepen_rev_list)
+	if (data->depth > 0 && data->deepen_rev_list)
 		die("git upload-pack: deepen and deepen-since (or deepen-not) cannot be used together");
-	if (depth > 0) {
-		deepen(writer, depth, deepen_relative, shallows, want_obj);
+	if (data->depth > 0) {
+		deepen(&data->writer, data->depth, data->deepen_relative,
+		       &data->shallows, &data->want_obj);
 		ret = 1;
-	} else if (deepen_rev_list) {
+	} else if (data->deepen_rev_list) {
 		struct argv_array av = ARGV_ARRAY_INIT;
 		int i;
 
 		argv_array_push(&av, "rev-list");
-		if (deepen_since)
-			argv_array_pushf(&av, "--max-age=%"PRItime, deepen_since);
-		if (deepen_not->nr) {
+		if (data->deepen_since)
+			argv_array_pushf(&av, "--max-age=%"PRItime, data->deepen_since);
+		if (data->deepen_not.nr) {
 			argv_array_push(&av, "--not");
-			for (i = 0; i < deepen_not->nr; i++) {
-				struct string_list_item *s = deepen_not->items + i;
+			for (i = 0; i < data->deepen_not.nr; i++) {
+				struct string_list_item *s = data->deepen_not.items + i;
 				argv_array_push(&av, s->string);
 			}
 			argv_array_push(&av, "--not");
 		}
-		for (i = 0; i < want_obj->nr; i++) {
-			struct object *o = want_obj->objects[i].item;
+		for (i = 0; i < data->want_obj.nr; i++) {
+			struct object *o = data->want_obj.objects[i].item;
 			argv_array_push(&av, oid_to_hex(&o->oid));
 		}
-		deepen_by_rev_list(writer, av.argc, av.argv, shallows, want_obj);
+		deepen_by_rev_list(&data->writer, av.argc, av.argv,
+				   &data->shallows, &data->want_obj);
 		argv_array_clear(&av);
 		ret = 1;
 	} else {
-		if (shallows->nr > 0) {
+		if (data->shallows.nr > 0) {
 			int i;
-			for (i = 0; i < shallows->nr; i++)
+			for (i = 0; i < data->shallows.nr; i++)
 				register_shallow(the_repository,
-						 &shallows->objects[i].item->oid);
+						 &data->shallows.objects[i].item->oid);
 		}
 	}
 
-	shallow_nr += shallows->nr;
+	shallow_nr += data->shallows.nr;
 	return ret;
 }
 
@@ -1022,14 +1018,7 @@ static void receive_needs(struct upload_pack_data *data,
 	if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
 		return;
 
-	if (send_shallow_list(&data->writer,
-			      data->depth,
-			      data->deepen_rev_list,
-			      data->deepen_since,
-			      &data->deepen_not,
-			      data->deepen_relative,
-			      &data->shallows,
-			      &data->want_obj))
+	if (send_shallow_list(data))
 		packet_flush(1);
 }
 
@@ -1473,11 +1462,7 @@ static void send_shallow_info(struct upload_pack_data *data)
 
 	packet_writer_write(&data->writer, "shallow-info\n");
 
-	if (!send_shallow_list(&data->writer, data->depth,
-			       data->deepen_rev_list,
-			       data->deepen_since, &data->deepen_not,
-			       data->deepen_relative,
-			       &data->shallows, &data->want_obj) &&
+	if (!send_shallow_list(data) &&
 	    is_repository_shallow(the_repository))
 		deepen(&data->writer, INFINITE_DEPTH, data->deepen_relative,
 		       &data->shallows, &data->want_obj);
-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 02/14] upload-pack: pass upload_pack_data to deepen()
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
  2020-06-11 12:05   ` [PATCH 01/14] upload-pack: pass upload_pack_data to send_shallow_list() Christian Couder
@ 2020-06-11 12:05   ` Christian Couder
  2020-06-11 12:05   ` [PATCH 03/14] upload-pack: pass upload_pack_data to deepen_by_rev_list() Christian Couder
                     ` (12 subsequent siblings)
  14 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass that struct to deepen(), so that
this function can use all the fields of the struct.

This will be used in followup commits to move static variables
into 'upload_pack_data'.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index ada9082b06..3f15828fd2 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -753,17 +753,16 @@ static void send_unshallow(struct packet_writer *writer,
 
 static int check_ref(const char *refname_full, const struct object_id *oid,
 		     int flag, void *cb_data);
-static void deepen(struct packet_writer *writer, int depth, int deepen_relative,
-		   struct object_array *shallows, struct object_array *want_obj)
+static void deepen(struct upload_pack_data *data, int depth)
 {
 	if (depth == INFINITE_DEPTH && !is_repository_shallow(the_repository)) {
 		int i;
 
-		for (i = 0; i < shallows->nr; i++) {
-			struct object *object = shallows->objects[i].item;
+		for (i = 0; i < data->shallows.nr; i++) {
+			struct object *object = data->shallows.objects[i].item;
 			object->flags |= NOT_SHALLOW;
 		}
-	} else if (deepen_relative) {
+	} else if (data->deepen_relative) {
 		struct object_array reachable_shallows = OBJECT_ARRAY_INIT;
 		struct commit_list *result;
 
@@ -774,23 +773,23 @@ static void deepen(struct packet_writer *writer, int depth, int deepen_relative,
 		head_ref_namespaced(check_ref, NULL);
 		for_each_namespaced_ref(check_ref, NULL);
 
-		get_reachable_list(shallows, &reachable_shallows);
+		get_reachable_list(&data->shallows, &reachable_shallows);
 		result = get_shallow_commits(&reachable_shallows,
 					     depth + 1,
 					     SHALLOW, NOT_SHALLOW);
-		send_shallow(writer, result);
+		send_shallow(&data->writer, result);
 		free_commit_list(result);
 		object_array_clear(&reachable_shallows);
 	} else {
 		struct commit_list *result;
 
-		result = get_shallow_commits(want_obj, depth,
+		result = get_shallow_commits(&data->want_obj, depth,
 					     SHALLOW, NOT_SHALLOW);
-		send_shallow(writer, result);
+		send_shallow(&data->writer, result);
 		free_commit_list(result);
 	}
 
-	send_unshallow(writer, shallows, want_obj);
+	send_unshallow(&data->writer, &data->shallows, &data->want_obj);
 }
 
 static void deepen_by_rev_list(struct packet_writer *writer, int ac,
@@ -815,8 +814,7 @@ static int send_shallow_list(struct upload_pack_data *data)
 	if (data->depth > 0 && data->deepen_rev_list)
 		die("git upload-pack: deepen and deepen-since (or deepen-not) cannot be used together");
 	if (data->depth > 0) {
-		deepen(&data->writer, data->depth, data->deepen_relative,
-		       &data->shallows, &data->want_obj);
+		deepen(data, data->depth);
 		ret = 1;
 	} else if (data->deepen_rev_list) {
 		struct argv_array av = ARGV_ARRAY_INIT;
@@ -1464,8 +1462,7 @@ static void send_shallow_info(struct upload_pack_data *data)
 
 	if (!send_shallow_list(data) &&
 	    is_repository_shallow(the_repository))
-		deepen(&data->writer, INFINITE_DEPTH, data->deepen_relative,
-		       &data->shallows, &data->want_obj);
+		deepen(data, INFINITE_DEPTH);
 
 	packet_delim(1);
 }
-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 03/14] upload-pack: pass upload_pack_data to deepen_by_rev_list()
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
  2020-06-11 12:05   ` [PATCH 01/14] upload-pack: pass upload_pack_data to send_shallow_list() Christian Couder
  2020-06-11 12:05   ` [PATCH 02/14] upload-pack: pass upload_pack_data to deepen() Christian Couder
@ 2020-06-11 12:05   ` Christian Couder
  2020-06-11 12:05   ` [PATCH 04/14] upload-pack: pass upload_pack_data to send_unshallow() Christian Couder
                     ` (11 subsequent siblings)
  14 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass that struct to deepen_by_rev_list(),
so that this function can use all the fields of the struct.

This will be used in followup commits to move static variables
into 'upload_pack_data'.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 3f15828fd2..aa8cde6dbf 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -792,18 +792,17 @@ static void deepen(struct upload_pack_data *data, int depth)
 	send_unshallow(&data->writer, &data->shallows, &data->want_obj);
 }
 
-static void deepen_by_rev_list(struct packet_writer *writer, int ac,
-			       const char **av,
-			       struct object_array *shallows,
-			       struct object_array *want_obj)
+static void deepen_by_rev_list(struct upload_pack_data *data,
+			       int ac,
+			       const char **av)
 {
 	struct commit_list *result;
 
 	disable_commit_graph(the_repository);
 	result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW);
-	send_shallow(writer, result);
+	send_shallow(&data->writer, result);
 	free_commit_list(result);
-	send_unshallow(writer, shallows, want_obj);
+	send_unshallow(&data->writer, &data->shallows, &data->want_obj);
 }
 
 /* Returns 1 if a shallow list is sent or 0 otherwise */
@@ -835,8 +834,7 @@ static int send_shallow_list(struct upload_pack_data *data)
 			struct object *o = data->want_obj.objects[i].item;
 			argv_array_push(&av, oid_to_hex(&o->oid));
 		}
-		deepen_by_rev_list(&data->writer, av.argc, av.argv,
-				   &data->shallows, &data->want_obj);
+		deepen_by_rev_list(data, av.argc, av.argv);
 		argv_array_clear(&av);
 		ret = 1;
 	} else {
-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 04/14] upload-pack: pass upload_pack_data to send_unshallow()
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
                     ` (2 preceding siblings ...)
  2020-06-11 12:05   ` [PATCH 03/14] upload-pack: pass upload_pack_data to deepen_by_rev_list() Christian Couder
@ 2020-06-11 12:05   ` Christian Couder
  2020-06-11 12:05   ` [PATCH 05/14] upload-pack: move shallow_nr to upload_pack_data Christian Couder
                     ` (10 subsequent siblings)
  14 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass that struct to send_unshallow(), so
that this function can use all the fields of the struct.

This will be used in followup commits to move static variables
into 'upload_pack_data'.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index aa8cde6dbf..3b4749d120 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -715,17 +715,15 @@ static void send_shallow(struct packet_writer *writer,
 	}
 }
 
-static void send_unshallow(struct packet_writer *writer,
-			   const struct object_array *shallows,
-			   struct object_array *want_obj)
+static void send_unshallow(struct upload_pack_data *data)
 {
 	int i;
 
-	for (i = 0; i < shallows->nr; i++) {
-		struct object *object = shallows->objects[i].item;
+	for (i = 0; i < data->shallows.nr; i++) {
+		struct object *object = data->shallows.objects[i].item;
 		if (object->flags & NOT_SHALLOW) {
 			struct commit_list *parents;
-			packet_writer_write(writer, "unshallow %s",
+			packet_writer_write(&data->writer, "unshallow %s",
 					    oid_to_hex(&object->oid));
 			object->flags &= ~CLIENT_SHALLOW;
 			/*
@@ -741,7 +739,7 @@ static void send_unshallow(struct packet_writer *writer,
 			parents = ((struct commit *)object)->parents;
 			while (parents) {
 				add_object_array(&parents->item->object,
-						 NULL, want_obj);
+						 NULL, &data->want_obj);
 				parents = parents->next;
 			}
 			add_object_array(object, NULL, &extra_edge_obj);
@@ -789,7 +787,7 @@ static void deepen(struct upload_pack_data *data, int depth)
 		free_commit_list(result);
 	}
 
-	send_unshallow(&data->writer, &data->shallows, &data->want_obj);
+	send_unshallow(data);
 }
 
 static void deepen_by_rev_list(struct upload_pack_data *data,
@@ -802,7 +800,7 @@ static void deepen_by_rev_list(struct upload_pack_data *data,
 	result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW);
 	send_shallow(&data->writer, result);
 	free_commit_list(result);
-	send_unshallow(&data->writer, &data->shallows, &data->want_obj);
+	send_unshallow(data);
 }
 
 /* Returns 1 if a shallow list is sent or 0 otherwise */
-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 05/14] upload-pack: move shallow_nr to upload_pack_data
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
                     ` (3 preceding siblings ...)
  2020-06-11 12:05   ` [PATCH 04/14] upload-pack: pass upload_pack_data to send_unshallow() Christian Couder
@ 2020-06-11 12:05   ` Christian Couder
  2020-06-11 12:05   ` [PATCH 06/14] upload-pack: move extra_edge_obj " Christian Couder
                     ` (9 subsequent siblings)
  14 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'shallow_nr' static variable
into this struct.

It is used by code common to protocol v0 and protocol v2.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 3b4749d120..d00a8d6b77 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -51,7 +51,6 @@ static timestamp_t oldest_have;
 /* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */
 #define ALLOW_ANY_SHA1	07
 static unsigned int allow_unadvertised_object_request;
-static int shallow_nr;
 static struct object_array extra_edge_obj;
 
 /*
@@ -72,6 +71,7 @@ struct upload_pack_data {
 	int deepen_rev_list;
 	int deepen_relative;
 	int keepalive;
+	int shallow_nr;
 
 	unsigned int timeout;					/* v0 only */
 	enum {
@@ -192,7 +192,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 		pack_objects.use_shell = 1;
 	}
 
-	if (shallow_nr) {
+	if (pack_data->shallow_nr) {
 		argv_array_push(&pack_objects.args, "--shallow-file");
 		argv_array_push(&pack_objects.args, "");
 	}
@@ -202,7 +202,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 		argv_array_push(&pack_objects.args, "--thin");
 
 	argv_array_push(&pack_objects.args, "--stdout");
-	if (shallow_nr)
+	if (pack_data->shallow_nr)
 		argv_array_push(&pack_objects.args, "--shallow");
 	if (!pack_data->no_progress)
 		argv_array_push(&pack_objects.args, "--progress");
@@ -233,7 +233,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 
 	pipe_fd = xfdopen(pack_objects.in, "w");
 
-	if (shallow_nr)
+	if (pack_data->shallow_nr)
 		for_each_commit_graft(write_one_shallow, pipe_fd);
 
 	for (i = 0; i < pack_data->want_obj.nr; i++)
@@ -700,16 +700,16 @@ static void check_non_tip(struct upload_pack_data *data)
 	}
 }
 
-static void send_shallow(struct packet_writer *writer,
+static void send_shallow(struct upload_pack_data *data,
 			 struct commit_list *result)
 {
 	while (result) {
 		struct object *object = &result->item->object;
 		if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
-			packet_writer_write(writer, "shallow %s",
+			packet_writer_write(&data->writer, "shallow %s",
 					    oid_to_hex(&object->oid));
 			register_shallow(the_repository, &object->oid);
-			shallow_nr++;
+			data->shallow_nr++;
 		}
 		result = result->next;
 	}
@@ -775,7 +775,7 @@ static void deepen(struct upload_pack_data *data, int depth)
 		result = get_shallow_commits(&reachable_shallows,
 					     depth + 1,
 					     SHALLOW, NOT_SHALLOW);
-		send_shallow(&data->writer, result);
+		send_shallow(data, result);
 		free_commit_list(result);
 		object_array_clear(&reachable_shallows);
 	} else {
@@ -783,7 +783,7 @@ static void deepen(struct upload_pack_data *data, int depth)
 
 		result = get_shallow_commits(&data->want_obj, depth,
 					     SHALLOW, NOT_SHALLOW);
-		send_shallow(&data->writer, result);
+		send_shallow(data, result);
 		free_commit_list(result);
 	}
 
@@ -798,7 +798,7 @@ static void deepen_by_rev_list(struct upload_pack_data *data,
 
 	disable_commit_graph(the_repository);
 	result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW);
-	send_shallow(&data->writer, result);
+	send_shallow(data, result);
 	free_commit_list(result);
 	send_unshallow(data);
 }
@@ -844,7 +844,7 @@ static int send_shallow_list(struct upload_pack_data *data)
 		}
 	}
 
-	shallow_nr += data->shallows.nr;
+	data->shallow_nr += data->shallows.nr;
 	return ret;
 }
 
@@ -922,7 +922,7 @@ static void receive_needs(struct upload_pack_data *data,
 {
 	int has_non_tip = 0;
 
-	shallow_nr = 0;
+	data->shallow_nr = 0;
 	for (;;) {
 		struct object *o;
 		const char *features;
-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 06/14] upload-pack: move extra_edge_obj to upload_pack_data
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
                     ` (4 preceding siblings ...)
  2020-06-11 12:05   ` [PATCH 05/14] upload-pack: move shallow_nr to upload_pack_data Christian Couder
@ 2020-06-11 12:05   ` Christian Couder
  2020-06-11 12:05   ` [PATCH 07/14] upload-pack: move allow_unadvertised_object_request " Christian Couder
                     ` (8 subsequent siblings)
  14 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'extra_edge_obj' static variable
into this struct.

It is used by code common to protocol v0 and protocol v2.

While at it let's properly initialize and clear 'extra_edge_obj'
in the appropriate 'upload_pack_data' initialization and
clearing functions.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index d00a8d6b77..acddfe28d6 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -51,7 +51,6 @@ static timestamp_t oldest_have;
 /* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */
 #define ALLOW_ANY_SHA1	07
 static unsigned int allow_unadvertised_object_request;
-static struct object_array extra_edge_obj;
 
 /*
  * Please annotate, and if possible group together, fields used only
@@ -66,6 +65,7 @@ struct upload_pack_data {
 
 	struct object_array shallows;
 	struct string_list deepen_not;
+	struct object_array extra_edge_obj;
 	int depth;
 	timestamp_t deepen_since;
 	int deepen_rev_list;
@@ -114,6 +114,7 @@ static void upload_pack_data_init(struct upload_pack_data *data)
 	struct oid_array haves = OID_ARRAY_INIT;
 	struct object_array shallows = OBJECT_ARRAY_INIT;
 	struct string_list deepen_not = STRING_LIST_INIT_DUP;
+	struct object_array extra_edge_obj = OBJECT_ARRAY_INIT;
 
 	memset(data, 0, sizeof(*data));
 	data->symref = symref;
@@ -123,6 +124,7 @@ static void upload_pack_data_init(struct upload_pack_data *data)
 	data->haves = haves;
 	data->shallows = shallows;
 	data->deepen_not = deepen_not;
+	data->extra_edge_obj = extra_edge_obj;
 	packet_writer_init(&data->writer, 1);
 
 	data->keepalive = 5;
@@ -137,6 +139,7 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
 	oid_array_clear(&data->haves);
 	object_array_clear(&data->shallows);
 	string_list_clear(&data->deepen_not, 0);
+	object_array_clear(&data->extra_edge_obj);
 	list_objects_filter_release(&data->filter_options);
 
 	free((char *)data->pack_objects_hook);
@@ -243,9 +246,9 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 	for (i = 0; i < pack_data->have_obj.nr; i++)
 		fprintf(pipe_fd, "%s\n",
 			oid_to_hex(&pack_data->have_obj.objects[i].item->oid));
-	for (i = 0; i < extra_edge_obj.nr; i++)
+	for (i = 0; i < pack_data->extra_edge_obj.nr; i++)
 		fprintf(pipe_fd, "%s\n",
-			oid_to_hex(&extra_edge_obj.objects[i].item->oid));
+			oid_to_hex(&pack_data->extra_edge_obj.objects[i].item->oid));
 	fprintf(pipe_fd, "\n");
 	fflush(pipe_fd);
 	fclose(pipe_fd);
@@ -742,7 +745,7 @@ static void send_unshallow(struct upload_pack_data *data)
 						 NULL, &data->want_obj);
 				parents = parents->next;
 			}
-			add_object_array(object, NULL, &extra_edge_obj);
+			add_object_array(object, NULL, &data->extra_edge_obj);
 		}
 		/* make sure commit traversal conforms to client */
 		register_shallow(the_repository, &object->oid);
-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 07/14] upload-pack: move allow_unadvertised_object_request to upload_pack_data
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
                     ` (5 preceding siblings ...)
  2020-06-11 12:05   ` [PATCH 06/14] upload-pack: move extra_edge_obj " Christian Couder
@ 2020-06-11 12:05   ` Christian Couder
  2020-06-11 12:05   ` [PATCH 08/14] upload-pack: change allow_unadvertised_object_request to an enum Christian Couder
                     ` (7 subsequent siblings)
  14 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'allow_unadvertised_object_request'
static variable into this struct.

It is used by code common to protocol v0 and protocol v2.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 55 ++++++++++++++++++++++++++++++---------------------
 1 file changed, 32 insertions(+), 23 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index acddfe28d6..5cd1342f62 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -44,13 +44,13 @@
 
 static timestamp_t oldest_have;
 
+/* Values for allow_unadvertised_object_request flags */
 /* Allow specifying sha1 if it is a ref tip. */
 #define ALLOW_TIP_SHA1	01
 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
 #define ALLOW_REACHABLE_SHA1	02
 /* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */
 #define ALLOW_ANY_SHA1	07
-static unsigned int allow_unadvertised_object_request;
 
 /*
  * Please annotate, and if possible group together, fields used only
@@ -83,6 +83,9 @@ struct upload_pack_data {
 	/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
 	int use_sideband;
 
+	/* See ALLOW_* values defined above */
+	unsigned int allow_unadvertised_object_request;
+
 	struct list_objects_filter_options filter_options;
 
 	struct packet_writer writer;
@@ -514,7 +517,8 @@ static int get_common_commits(struct upload_pack_data *data,
 	}
 }
 
-static int is_our_ref(struct object *o)
+static int is_our_ref(struct object *o,
+		      unsigned int allow_unadvertised_object_request)
 {
 	int allow_hidden_ref = (allow_unadvertised_object_request &
 			(ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));
@@ -526,7 +530,8 @@ static int is_our_ref(struct object *o)
  */
 static int do_reachable_revlist(struct child_process *cmd,
 				struct object_array *src,
-				struct object_array *reachable)
+				struct object_array *reachable,
+				unsigned int allow_unadvertised_object_request)
 {
 	static const char *argv[] = {
 		"rev-list", "--stdin", NULL,
@@ -560,7 +565,7 @@ static int do_reachable_revlist(struct child_process *cmd,
 			continue;
 		if (reachable && o->type == OBJ_COMMIT)
 			o->flags &= ~TMP_MARK;
-		if (!is_our_ref(o))
+		if (!is_our_ref(o, allow_unadvertised_object_request))
 			continue;
 		memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz);
 		if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0)
@@ -569,7 +574,7 @@ static int do_reachable_revlist(struct child_process *cmd,
 	namebuf[hexsz] = '\n';
 	for (i = 0; i < src->nr; i++) {
 		o = src->objects[i].item;
-		if (is_our_ref(o)) {
+		if (is_our_ref(o, allow_unadvertised_object_request)) {
 			if (reachable)
 				add_object_array(o, NULL, reachable);
 			continue;
@@ -596,7 +601,7 @@ static int do_reachable_revlist(struct child_process *cmd,
 	return -1;
 }
 
-static int get_reachable_list(struct object_array *src,
+static int get_reachable_list(struct upload_pack_data *data,
 			      struct object_array *reachable)
 {
 	struct child_process cmd = CHILD_PROCESS_INIT;
@@ -605,7 +610,8 @@ static int get_reachable_list(struct object_array *src,
 	char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
 	const unsigned hexsz = the_hash_algo->hexsz;
 
-	if (do_reachable_revlist(&cmd, src, reachable) < 0)
+	if (do_reachable_revlist(&cmd, &data->shallows, reachable,
+				 data->allow_unadvertised_object_request) < 0)
 		return -1;
 
 	while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) {
@@ -636,13 +642,15 @@ static int get_reachable_list(struct object_array *src,
 	return 0;
 }
 
-static int has_unreachable(struct object_array *src)
+static int has_unreachable(struct object_array *src,
+			   unsigned int allow_unadvertised_object_request)
 {
 	struct child_process cmd = CHILD_PROCESS_INIT;
 	char buf[1];
 	int i;
 
-	if (do_reachable_revlist(&cmd, src, NULL) < 0)
+	if (do_reachable_revlist(&cmd, src, NULL,
+				 allow_unadvertised_object_request) < 0)
 		return 1;
 
 	/*
@@ -683,9 +691,10 @@ static void check_non_tip(struct upload_pack_data *data)
 	 * non-tip requests can never happen.
 	 */
 	if (!data->stateless_rpc
-	    && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
+	    && !(data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
 		goto error;
-	if (!has_unreachable(&data->want_obj))
+	if (!has_unreachable(&data->want_obj,
+			     data->allow_unadvertised_object_request))
 		/* All the non-tip ones are ancestors of what we advertised */
 		return;
 
@@ -693,7 +702,7 @@ static void check_non_tip(struct upload_pack_data *data)
 	/* Pick one of them (we know there at least is one) */
 	for (i = 0; i < data->want_obj.nr; i++) {
 		struct object *o = data->want_obj.objects[i].item;
-		if (!is_our_ref(o)) {
+		if (!is_our_ref(o, data->allow_unadvertised_object_request)) {
 			packet_writer_error(&data->writer,
 					    "upload-pack: not our ref %s",
 					    oid_to_hex(&o->oid));
@@ -774,7 +783,7 @@ static void deepen(struct upload_pack_data *data, int depth)
 		head_ref_namespaced(check_ref, NULL);
 		for_each_namespaced_ref(check_ref, NULL);
 
-		get_reachable_list(&data->shallows, &reachable_shallows);
+		get_reachable_list(data, &reachable_shallows);
 		result = get_shallow_commits(&reachable_shallows,
 					     depth + 1,
 					     SHALLOW, NOT_SHALLOW);
@@ -992,8 +1001,8 @@ static void receive_needs(struct upload_pack_data *data,
 		}
 		if (!(o->flags & WANTED)) {
 			o->flags |= WANTED;
-			if (!((allow_unadvertised_object_request & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1
-			      || is_our_ref(o)))
+			if (!((data->allow_unadvertised_object_request & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1
+			      || is_our_ref(o, data->allow_unadvertised_object_request)))
 				has_non_tip = 1;
 			add_object_array(o, NULL, &data->want_obj);
 		}
@@ -1072,9 +1081,9 @@ static int send_ref(const char *refname, const struct object_id *oid,
 		packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s agent=%s\n",
 			     oid_to_hex(oid), refname_nons,
 			     0, capabilities,
-			     (allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
+			     (data->allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
 				     " allow-tip-sha1-in-want" : "",
-			     (allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ?
+			     (data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ?
 				     " allow-reachable-sha1-in-want" : "",
 			     data->stateless_rpc ? " no-done" : "",
 			     symref_info.buf,
@@ -1112,19 +1121,19 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 
 	if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
 		if (git_config_bool(var, value))
-			allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
+			data->allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
 		else
-			allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1;
+			data->allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1;
 	} else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) {
 		if (git_config_bool(var, value))
-			allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
+			data->allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
 		else
-			allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1;
+			data->allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1;
 	} else if (!strcmp("uploadpack.allowanysha1inwant", var)) {
 		if (git_config_bool(var, value))
-			allow_unadvertised_object_request |= ALLOW_ANY_SHA1;
+			data->allow_unadvertised_object_request |= ALLOW_ANY_SHA1;
 		else
-			allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
+			data->allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
 	} else if (!strcmp("uploadpack.keepalive", var)) {
 		data->keepalive = git_config_int(var, value);
 		if (!data->keepalive)
-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 08/14] upload-pack: change allow_unadvertised_object_request to an enum
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
                     ` (6 preceding siblings ...)
  2020-06-11 12:05   ` [PATCH 07/14] upload-pack: move allow_unadvertised_object_request " Christian Couder
@ 2020-06-11 12:05   ` Christian Couder
  2020-06-11 12:05   ` [PATCH 09/14] upload-pack: pass upload_pack_data to process_haves() Christian Couder
                     ` (6 subsequent siblings)
  14 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's change allow_unadvertised_object_request,
which is now part of 'upload_pack_data', from an 'unsigned int'
to an enum.

This will make it clear which values this variable can take.

While at it let's change this variable name to 'allow_uor' to
make it shorter.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 68 ++++++++++++++++++++++++---------------------------
 1 file changed, 32 insertions(+), 36 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 5cd1342f62..0b30794d91 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -44,13 +44,15 @@
 
 static timestamp_t oldest_have;
 
-/* Values for allow_unadvertised_object_request flags */
-/* Allow specifying sha1 if it is a ref tip. */
-#define ALLOW_TIP_SHA1	01
-/* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
-#define ALLOW_REACHABLE_SHA1	02
-/* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */
-#define ALLOW_ANY_SHA1	07
+/* Enum for allowed unadvertised object request (UOR) */
+enum allow_uor {
+	/* Allow specifying sha1 if it is a ref tip. */
+	ALLOW_TIP_SHA1 = 0x01,
+	/* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
+	ALLOW_REACHABLE_SHA1 = 0x02,
+	/* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */
+	ALLOW_ANY_SHA1 = 0x07
+};
 
 /*
  * Please annotate, and if possible group together, fields used only
@@ -83,8 +85,7 @@ struct upload_pack_data {
 	/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
 	int use_sideband;
 
-	/* See ALLOW_* values defined above */
-	unsigned int allow_unadvertised_object_request;
+	enum allow_uor allow_uor;
 
 	struct list_objects_filter_options filter_options;
 
@@ -517,11 +518,10 @@ static int get_common_commits(struct upload_pack_data *data,
 	}
 }
 
-static int is_our_ref(struct object *o,
-		      unsigned int allow_unadvertised_object_request)
+static int is_our_ref(struct object *o, enum allow_uor allow_uor)
 {
-	int allow_hidden_ref = (allow_unadvertised_object_request &
-			(ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));
+	int allow_hidden_ref = (allow_uor &
+				(ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));
 	return o->flags & ((allow_hidden_ref ? HIDDEN_REF : 0) | OUR_REF);
 }
 
@@ -531,7 +531,7 @@ static int is_our_ref(struct object *o,
 static int do_reachable_revlist(struct child_process *cmd,
 				struct object_array *src,
 				struct object_array *reachable,
-				unsigned int allow_unadvertised_object_request)
+				enum allow_uor allow_uor)
 {
 	static const char *argv[] = {
 		"rev-list", "--stdin", NULL,
@@ -565,7 +565,7 @@ static int do_reachable_revlist(struct child_process *cmd,
 			continue;
 		if (reachable && o->type == OBJ_COMMIT)
 			o->flags &= ~TMP_MARK;
-		if (!is_our_ref(o, allow_unadvertised_object_request))
+		if (!is_our_ref(o, allow_uor))
 			continue;
 		memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz);
 		if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0)
@@ -574,7 +574,7 @@ static int do_reachable_revlist(struct child_process *cmd,
 	namebuf[hexsz] = '\n';
 	for (i = 0; i < src->nr; i++) {
 		o = src->objects[i].item;
-		if (is_our_ref(o, allow_unadvertised_object_request)) {
+		if (is_our_ref(o, allow_uor)) {
 			if (reachable)
 				add_object_array(o, NULL, reachable);
 			continue;
@@ -611,7 +611,7 @@ static int get_reachable_list(struct upload_pack_data *data,
 	const unsigned hexsz = the_hash_algo->hexsz;
 
 	if (do_reachable_revlist(&cmd, &data->shallows, reachable,
-				 data->allow_unadvertised_object_request) < 0)
+				 data->allow_uor) < 0)
 		return -1;
 
 	while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) {
@@ -642,15 +642,13 @@ static int get_reachable_list(struct upload_pack_data *data,
 	return 0;
 }
 
-static int has_unreachable(struct object_array *src,
-			   unsigned int allow_unadvertised_object_request)
+static int has_unreachable(struct object_array *src, enum allow_uor allow_uor)
 {
 	struct child_process cmd = CHILD_PROCESS_INIT;
 	char buf[1];
 	int i;
 
-	if (do_reachable_revlist(&cmd, src, NULL,
-				 allow_unadvertised_object_request) < 0)
+	if (do_reachable_revlist(&cmd, src, NULL, allow_uor) < 0)
 		return 1;
 
 	/*
@@ -690,11 +688,9 @@ static void check_non_tip(struct upload_pack_data *data)
 	 * uploadpack.allowReachableSHA1InWant,
 	 * non-tip requests can never happen.
 	 */
-	if (!data->stateless_rpc
-	    && !(data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
+	if (!data->stateless_rpc && !(data->allow_uor & ALLOW_REACHABLE_SHA1))
 		goto error;
-	if (!has_unreachable(&data->want_obj,
-			     data->allow_unadvertised_object_request))
+	if (!has_unreachable(&data->want_obj, data->allow_uor))
 		/* All the non-tip ones are ancestors of what we advertised */
 		return;
 
@@ -702,7 +698,7 @@ static void check_non_tip(struct upload_pack_data *data)
 	/* Pick one of them (we know there at least is one) */
 	for (i = 0; i < data->want_obj.nr; i++) {
 		struct object *o = data->want_obj.objects[i].item;
-		if (!is_our_ref(o, data->allow_unadvertised_object_request)) {
+		if (!is_our_ref(o, data->allow_uor)) {
 			packet_writer_error(&data->writer,
 					    "upload-pack: not our ref %s",
 					    oid_to_hex(&o->oid));
@@ -1001,8 +997,8 @@ static void receive_needs(struct upload_pack_data *data,
 		}
 		if (!(o->flags & WANTED)) {
 			o->flags |= WANTED;
-			if (!((data->allow_unadvertised_object_request & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1
-			      || is_our_ref(o, data->allow_unadvertised_object_request)))
+			if (!((data->allow_uor & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1
+			      || is_our_ref(o, data->allow_uor)))
 				has_non_tip = 1;
 			add_object_array(o, NULL, &data->want_obj);
 		}
@@ -1081,9 +1077,9 @@ static int send_ref(const char *refname, const struct object_id *oid,
 		packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s agent=%s\n",
 			     oid_to_hex(oid), refname_nons,
 			     0, capabilities,
-			     (data->allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
+			     (data->allow_uor & ALLOW_TIP_SHA1) ?
 				     " allow-tip-sha1-in-want" : "",
-			     (data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ?
+			     (data->allow_uor & ALLOW_REACHABLE_SHA1) ?
 				     " allow-reachable-sha1-in-want" : "",
 			     data->stateless_rpc ? " no-done" : "",
 			     symref_info.buf,
@@ -1121,19 +1117,19 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
 
 	if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
 		if (git_config_bool(var, value))
-			data->allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
+			data->allow_uor |= ALLOW_TIP_SHA1;
 		else
-			data->allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1;
+			data->allow_uor &= ~ALLOW_TIP_SHA1;
 	} else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) {
 		if (git_config_bool(var, value))
-			data->allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
+			data->allow_uor |= ALLOW_REACHABLE_SHA1;
 		else
-			data->allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1;
+			data->allow_uor &= ~ALLOW_REACHABLE_SHA1;
 	} else if (!strcmp("uploadpack.allowanysha1inwant", var)) {
 		if (git_config_bool(var, value))
-			data->allow_unadvertised_object_request |= ALLOW_ANY_SHA1;
+			data->allow_uor |= ALLOW_ANY_SHA1;
 		else
-			data->allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
+			data->allow_uor &= ~ALLOW_ANY_SHA1;
 	} else if (!strcmp("uploadpack.keepalive", var)) {
 		data->keepalive = git_config_int(var, value);
 		if (!data->keepalive)
-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 09/14] upload-pack: pass upload_pack_data to process_haves()
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
                     ` (7 preceding siblings ...)
  2020-06-11 12:05   ` [PATCH 08/14] upload-pack: change allow_unadvertised_object_request to an enum Christian Couder
@ 2020-06-11 12:05   ` Christian Couder
  2020-06-11 12:05   ` [PATCH 10/14] upload-pack: pass upload_pack_data to send_acks() Christian Couder
                     ` (5 subsequent siblings)
  14 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass that struct to process_haves(), so
that this function can use all the fields of the struct.

This will be used in followup commits to move a static variable
into 'upload_pack_data'.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 0b30794d91..b20600fceb 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1348,14 +1348,13 @@ static void process_args(struct packet_reader *request,
 		die(_("expected flush after fetch arguments"));
 }
 
-static int process_haves(struct oid_array *haves, struct oid_array *common,
-			 struct object_array *have_obj)
+static int process_haves(struct upload_pack_data *data, struct oid_array *common)
 {
 	int i;
 
 	/* Process haves */
-	for (i = 0; i < haves->nr; i++) {
-		const struct object_id *oid = &haves->oid[i];
+	for (i = 0; i < data->haves.nr; i++) {
+		const struct object_id *oid = &data->haves.oid[i];
 		struct object *o;
 		int we_knew_they_have = 0;
 
@@ -1382,7 +1381,7 @@ static int process_haves(struct oid_array *haves, struct oid_array *common,
 				parents->item->object.flags |= THEY_HAVE;
 		}
 		if (!we_knew_they_have)
-			add_object_array(o, NULL, have_obj);
+			add_object_array(o, NULL, &data->have_obj);
 	}
 
 	return 0;
@@ -1419,7 +1418,7 @@ static int process_haves_and_send_acks(struct upload_pack_data *data)
 	struct oid_array common = OID_ARRAY_INIT;
 	int ret = 0;
 
-	process_haves(&data->haves, &common, &data->have_obj);
+	process_haves(data, &common);
 	if (data->done) {
 		ret = 1;
 	} else if (send_acks(&data->writer, &common,
-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 10/14] upload-pack: pass upload_pack_data to send_acks()
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
                     ` (8 preceding siblings ...)
  2020-06-11 12:05   ` [PATCH 09/14] upload-pack: pass upload_pack_data to process_haves() Christian Couder
@ 2020-06-11 12:05   ` Christian Couder
  2020-06-11 12:05   ` [PATCH 11/14] upload-pack: pass upload_pack_data to ok_to_give_up() Christian Couder
                     ` (4 subsequent siblings)
  14 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass that struct to send_acks(), so
that this function can use all the fields of the struct.

This will be used in followup commits to move a static variable
into 'upload_pack_data'.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index b20600fceb..0523feaac2 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1387,26 +1387,24 @@ static int process_haves(struct upload_pack_data *data, struct oid_array *common
 	return 0;
 }
 
-static int send_acks(struct packet_writer *writer, struct oid_array *acks,
-		     const struct object_array *have_obj,
-		     struct object_array *want_obj)
+static int send_acks(struct upload_pack_data *data, struct oid_array *acks)
 {
 	int i;
 
-	packet_writer_write(writer, "acknowledgments\n");
+	packet_writer_write(&data->writer, "acknowledgments\n");
 
 	/* Send Acks */
 	if (!acks->nr)
-		packet_writer_write(writer, "NAK\n");
+		packet_writer_write(&data->writer, "NAK\n");
 
 	for (i = 0; i < acks->nr; i++) {
-		packet_writer_write(writer, "ACK %s\n",
+		packet_writer_write(&data->writer, "ACK %s\n",
 				    oid_to_hex(&acks->oid[i]));
 	}
 
-	if (ok_to_give_up(have_obj, want_obj)) {
+	if (ok_to_give_up(&data->have_obj, &data->want_obj)) {
 		/* Send Ready */
-		packet_writer_write(writer, "ready\n");
+		packet_writer_write(&data->writer, "ready\n");
 		return 1;
 	}
 
@@ -1421,8 +1419,7 @@ static int process_haves_and_send_acks(struct upload_pack_data *data)
 	process_haves(data, &common);
 	if (data->done) {
 		ret = 1;
-	} else if (send_acks(&data->writer, &common,
-			     &data->have_obj, &data->want_obj)) {
+	} else if (send_acks(data, &common)) {
 		packet_writer_delim(&data->writer);
 		ret = 1;
 	} else {
-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 11/14] upload-pack: pass upload_pack_data to ok_to_give_up()
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
                     ` (9 preceding siblings ...)
  2020-06-11 12:05   ` [PATCH 10/14] upload-pack: pass upload_pack_data to send_acks() Christian Couder
@ 2020-06-11 12:05   ` Christian Couder
  2020-06-11 12:05   ` [PATCH 12/14] upload-pack: pass upload_pack_data to got_oid() Christian Couder
                     ` (3 subsequent siblings)
  14 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass that struct to ok_to_give_up(), so
that this function can use all the fields of the struct.

This will be used in followup commits to move a static variable
into 'upload_pack_data'.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 0523feaac2..245eda8ba1 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -428,15 +428,14 @@ static int got_oid(const char *hex, struct object_id *oid,
 	return 0;
 }
 
-static int ok_to_give_up(const struct object_array *have_obj,
-			 struct object_array *want_obj)
+static int ok_to_give_up(struct upload_pack_data *data)
 {
 	uint32_t min_generation = GENERATION_NUMBER_ZERO;
 
-	if (!have_obj->nr)
+	if (!data->have_obj.nr)
 		return 0;
 
-	return can_all_from_reach_with_flag(want_obj, THEY_HAVE,
+	return can_all_from_reach_with_flag(&data->want_obj, THEY_HAVE,
 					    COMMON_KNOWN, oldest_have,
 					    min_generation);
 }
@@ -461,7 +460,7 @@ static int get_common_commits(struct upload_pack_data *data,
 			if (data->multi_ack == MULTI_ACK_DETAILED
 			    && got_common
 			    && !got_other
-			    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
+			    && ok_to_give_up(data)) {
 				sent_ready = 1;
 				packet_write_fmt(1, "ACK %s ready\n", last_hex);
 			}
@@ -483,7 +482,7 @@ static int get_common_commits(struct upload_pack_data *data,
 			case -1: /* they have what we do not */
 				got_other = 1;
 				if (data->multi_ack
-				    && ok_to_give_up(&data->have_obj, &data->want_obj)) {
+				    && ok_to_give_up(data)) {
 					const char *hex = oid_to_hex(&oid);
 					if (data->multi_ack == MULTI_ACK_DETAILED) {
 						sent_ready = 1;
@@ -1402,7 +1401,7 @@ static int send_acks(struct upload_pack_data *data, struct oid_array *acks)
 				    oid_to_hex(&acks->oid[i]));
 	}
 
-	if (ok_to_give_up(&data->have_obj, &data->want_obj)) {
+	if (ok_to_give_up(data)) {
 		/* Send Ready */
 		packet_writer_write(&data->writer, "ready\n");
 		return 1;
-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 12/14] upload-pack: pass upload_pack_data to got_oid()
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
                     ` (10 preceding siblings ...)
  2020-06-11 12:05   ` [PATCH 11/14] upload-pack: pass upload_pack_data to ok_to_give_up() Christian Couder
@ 2020-06-11 12:05   ` Christian Couder
  2020-06-11 12:05   ` [PATCH 13/14] upload-pack: move oldest_have to upload_pack_data Christian Couder
                     ` (2 subsequent siblings)
  14 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's pass that struct to got_oid(), so that
this function can use all the fields of the struct.

This will be used in followup commits to move a static variable
into 'upload_pack_data'.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 245eda8ba1..6729c17cf4 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -393,8 +393,8 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 	die("git upload-pack: %s", abort_msg);
 }
 
-static int got_oid(const char *hex, struct object_id *oid,
-		   struct object_array *have_obj)
+static int got_oid(struct upload_pack_data *data,
+		   const char *hex, struct object_id *oid)
 {
 	struct object *o;
 	int we_knew_they_have = 0;
@@ -422,7 +422,7 @@ static int got_oid(const char *hex, struct object_id *oid,
 			parents->item->object.flags |= THEY_HAVE;
 	}
 	if (!we_knew_they_have) {
-		add_object_array(o, NULL, have_obj);
+		add_object_array(o, NULL, &data->have_obj);
 		return 1;
 	}
 	return 0;
@@ -478,7 +478,7 @@ static int get_common_commits(struct upload_pack_data *data,
 			continue;
 		}
 		if (skip_prefix(reader->line, "have ", &arg)) {
-			switch (got_oid(arg, &oid, &data->have_obj)) {
+			switch (got_oid(data, arg, &oid)) {
 			case -1: /* they have what we do not */
 				got_other = 1;
 				if (data->multi_ack
-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 13/14] upload-pack: move oldest_have to upload_pack_data
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
                     ` (11 preceding siblings ...)
  2020-06-11 12:05   ` [PATCH 12/14] upload-pack: pass upload_pack_data to got_oid() Christian Couder
@ 2020-06-11 12:05   ` Christian Couder
  2020-06-11 12:05   ` [PATCH 14/14] upload-pack: refactor common code into do_got_oid() Christian Couder
  2020-06-11 20:04   ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Jonathan Tan
  14 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'oldest_have' static variable
into this struct.

It is used by both protocol v0 and protocol v2 code.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 6729c17cf4..3d331bedfa 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -42,8 +42,6 @@
 #define ALL_FLAGS (THEY_HAVE | OUR_REF | WANTED | COMMON_KNOWN | SHALLOW | \
 		NOT_SHALLOW | CLIENT_SHALLOW | HIDDEN_REF)
 
-static timestamp_t oldest_have;
-
 /* Enum for allowed unadvertised object request (UOR) */
 enum allow_uor {
 	/* Allow specifying sha1 if it is a ref tip. */
@@ -74,6 +72,7 @@ struct upload_pack_data {
 	int deepen_relative;
 	int keepalive;
 	int shallow_nr;
+	timestamp_t oldest_have;
 
 	unsigned int timeout;					/* v0 only */
 	enum {
@@ -414,8 +413,8 @@ static int got_oid(struct upload_pack_data *data,
 			we_knew_they_have = 1;
 		else
 			o->flags |= THEY_HAVE;
-		if (!oldest_have || (commit->date < oldest_have))
-			oldest_have = commit->date;
+		if (!data->oldest_have || (commit->date < data->oldest_have))
+			data->oldest_have = commit->date;
 		for (parents = commit->parents;
 		     parents;
 		     parents = parents->next)
@@ -436,7 +435,7 @@ static int ok_to_give_up(struct upload_pack_data *data)
 		return 0;
 
 	return can_all_from_reach_with_flag(&data->want_obj, THEY_HAVE,
-					    COMMON_KNOWN, oldest_have,
+					    COMMON_KNOWN, data->oldest_have,
 					    min_generation);
 }
 
@@ -1372,8 +1371,8 @@ static int process_haves(struct upload_pack_data *data, struct oid_array *common
 				we_knew_they_have = 1;
 			else
 				o->flags |= THEY_HAVE;
-			if (!oldest_have || (commit->date < oldest_have))
-				oldest_have = commit->date;
+			if (!data->oldest_have || (commit->date < data->oldest_have))
+				data->oldest_have = commit->date;
 			for (parents = commit->parents;
 			     parents;
 			     parents = parents->next)
-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* [PATCH 14/14] upload-pack: refactor common code into do_got_oid()
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
                     ` (12 preceding siblings ...)
  2020-06-11 12:05   ` [PATCH 13/14] upload-pack: move oldest_have to upload_pack_data Christian Couder
@ 2020-06-11 12:05   ` Christian Couder
  2020-06-11 20:04   ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Jonathan Tan
  14 siblings, 0 replies; 108+ messages in thread
From: Christian Couder @ 2020-06-11 12:05 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Jeff King, Taylor Blau,
	Jonathan Tan, Jonathan Nieder, Christian Couder

As 'upload-pack.c' is now using 'struct upload_pack_data'
thoroughly, let's refactor some common code into a new
do_got_oid() function.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 43 +++++++++++++------------------------------
 1 file changed, 13 insertions(+), 30 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 3d331bedfa..f899fdf46a 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -392,18 +392,11 @@ static void create_pack_file(struct upload_pack_data *pack_data)
 	die("git upload-pack: %s", abort_msg);
 }
 
-static int got_oid(struct upload_pack_data *data,
-		   const char *hex, struct object_id *oid)
+static int do_got_oid(struct upload_pack_data *data, const struct object_id *oid)
 {
-	struct object *o;
 	int we_knew_they_have = 0;
+	struct object *o = parse_object(the_repository, oid);
 
-	if (get_oid_hex(hex, oid))
-		die("git upload-pack: expected SHA1 object, got '%s'", hex);
-	if (!has_object_file(oid))
-		return -1;
-
-	o = parse_object(the_repository, oid);
 	if (!o)
 		die("oops (%s)", oid_to_hex(oid));
 	if (o->type == OBJ_COMMIT) {
@@ -427,6 +420,16 @@ static int got_oid(struct upload_pack_data *data,
 	return 0;
 }
 
+static int got_oid(struct upload_pack_data *data,
+		   const char *hex, struct object_id *oid)
+{
+	if (get_oid_hex(hex, oid))
+		die("git upload-pack: expected SHA1 object, got '%s'", hex);
+	if (!has_object_file(oid))
+		return -1;
+	return do_got_oid(data, oid);
+}
+
 static int ok_to_give_up(struct upload_pack_data *data)
 {
 	uint32_t min_generation = GENERATION_NUMBER_ZERO;
@@ -1353,33 +1356,13 @@ static int process_haves(struct upload_pack_data *data, struct oid_array *common
 	/* Process haves */
 	for (i = 0; i < data->haves.nr; i++) {
 		const struct object_id *oid = &data->haves.oid[i];
-		struct object *o;
-		int we_knew_they_have = 0;
 
 		if (!has_object_file(oid))
 			continue;
 
 		oid_array_append(common, oid);
 
-		o = parse_object(the_repository, oid);
-		if (!o)
-			die("oops (%s)", oid_to_hex(oid));
-		if (o->type == OBJ_COMMIT) {
-			struct commit_list *parents;
-			struct commit *commit = (struct commit *)o;
-			if (o->flags & THEY_HAVE)
-				we_knew_they_have = 1;
-			else
-				o->flags |= THEY_HAVE;
-			if (!data->oldest_have || (commit->date < data->oldest_have))
-				data->oldest_have = commit->date;
-			for (parents = commit->parents;
-			     parents;
-			     parents = parents->next)
-				parents->item->object.flags |= THEY_HAVE;
-		}
-		if (!we_knew_they_have)
-			add_object_array(o, NULL, &data->have_obj);
+		do_got_oid(data, oid);
 	}
 
 	return 0;
-- 
2.27.0.90.gabb59f83a2


^ permalink raw reply related	[flat|nested] 108+ messages in thread

* Re: [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3
  2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
                     ` (13 preceding siblings ...)
  2020-06-11 12:05   ` [PATCH 14/14] upload-pack: refactor common code into do_got_oid() Christian Couder
@ 2020-06-11 20:04   ` Jonathan Tan
  14 siblings, 0 replies; 108+ messages in thread
From: Jonathan Tan @ 2020-06-11 20:04 UTC (permalink / raw)
  To: christian.couder
  Cc: git, gitster, dstolee, peff, me, jonathantanmy, jrnieder, chriscool

> This patch series is the third and last part of an effort to move all
> static variables in 'upload-pack.c' into 'struct upload_pack_data'.
> 
> It is based on 'cc/upload-pack-data-2' which contains "part 2" of this
> effort.
> 
> There are no static variables left in 'upload-pack.c' after this patch
> series. Patch 14/14 is a small refactoring on top which can be left
> out.

Thanks. Overall, I see that this patch set gives "struct
upload_pack_data" to functions that use global variables (and in doing
so, shrinks their parameter list), enabling global variables to be moved
into that struct with a small diff. The changes are generally
mechanical, and this patch set looks good to me.

As an aside, I have attempted rebasing my CDN offloading patches [1]
from cc/upload-pack-data-2 onto this series, and the rebase succeeds
with trivial work needed.

[1] https://lore.kernel.org/git/cover.1591821067.git.jonathantanmy@google.com/

^ permalink raw reply	[flat|nested] 108+ messages in thread

end of thread, other threads:[~2020-06-11 20:05 UTC | newest]

Thread overview: 108+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15 10:04 [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Christian Couder
2020-05-15 10:04 ` [PATCH 01/13] upload-pack: remove unused 'wants' from upload_pack_data Christian Couder
2020-05-15 18:03   ` Jeff King
2020-05-15 10:04 ` [PATCH 02/13] upload-pack: move {want,have}_obj to upload_pack_data Christian Couder
2020-05-15 18:05   ` Jeff King
2020-05-15 10:04 ` [PATCH 03/13] upload-pack: move 'struct upload_pack_data' around Christian Couder
2020-05-15 18:05   ` Jeff King
2020-05-15 10:04 ` [PATCH 04/13] upload-pack: use 'struct upload_pack_data' in upload_pack() Christian Couder
2020-05-15 10:30   ` Derrick Stolee
2020-05-15 18:13     ` Jeff King
2020-05-15 10:04 ` [PATCH 05/13] upload-pack: pass upload_pack_data to get_common_commits() Christian Couder
2020-05-15 18:17   ` Jeff King
2020-05-15 18:36     ` Jeff King
2020-05-15 10:04 ` [PATCH 06/13] upload-pack: pass upload_pack_data to receive_needs() Christian Couder
2020-05-15 18:20   ` Jeff King
2020-05-15 10:04 ` [PATCH 07/13] upload-pack: use upload_pack_data writer in receive_needs() Christian Couder
2020-05-15 18:23   ` Jeff King
2020-05-15 10:04 ` [PATCH 08/13] upload-pack: move symref to upload_pack_data Christian Couder
2020-05-15 18:28   ` Jeff King
2020-05-15 10:04 ` [PATCH 09/13] upload-pack: pass upload_pack_data to send_ref() Christian Couder
2020-05-15 18:33   ` Jeff King
2020-05-15 10:04 ` [PATCH 10/13] upload-pack: pass upload_pack_data to check_non_tip() Christian Couder
2020-05-15 10:04 ` [PATCH 11/13] upload-pack: remove static variable 'stateless_rpc' Christian Couder
2020-05-15 18:38   ` Jeff King
2020-05-15 10:04 ` [PATCH 12/13] upload-pack: pass upload_pack_data to create_pack_file() Christian Couder
2020-05-15 10:04 ` [PATCH 13/13] upload-pack: use upload_pack_data fields in receive_needs() Christian Couder
2020-05-15 18:42   ` Jeff King
2020-05-15 10:43 ` [PATCH 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 1 Derrick Stolee
2020-05-19  9:49   ` Christian Couder
2020-05-15 18:47 ` Jeff King
2020-05-15 18:55   ` Jeff King
2020-05-19  9:44     ` Christian Couder
2020-05-27 16:47 ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
2020-05-27 16:47   ` [PATCH 01/12] upload-pack: actually use some upload_pack_data bitfields Christian Couder
2020-05-27 16:47   ` [PATCH 02/12] upload-pack: move static vars to upload_pack_data Christian Couder
2020-05-27 18:06     ` Jeff King
2020-06-02  4:19       ` Christian Couder
2020-05-27 16:47   ` [PATCH 03/12] upload-pack: move use_sideband " Christian Couder
2020-05-27 18:07     ` Jeff King
2020-05-27 16:47   ` [PATCH 04/12] upload-pack: move filter_capability_requested " Christian Couder
2020-05-27 18:08     ` Jeff King
2020-05-27 16:47   ` [PATCH 05/12] upload-pack: move multi_ack " Christian Couder
2020-05-27 16:47   ` [PATCH 06/12] upload-pack: change multi_ack to an enum Christian Couder
2020-05-27 18:10     ` Jeff King
2020-05-27 16:47   ` [PATCH 07/12] upload-pack: pass upload_pack_data to upload_pack_config() Christian Couder
2020-05-27 18:36     ` Jeff King
2020-05-27 16:47   ` [PATCH 08/12] upload-pack: move keepalive to upload_pack_data Christian Couder
2020-05-27 18:38     ` Jeff King
2020-05-27 16:47   ` [PATCH 09/12] upload-pack: move allow_filter " Christian Couder
2020-05-27 18:39     ` Jeff King
2020-05-27 16:47   ` [PATCH 10/12] upload-pack: move allow_ref_in_want " Christian Couder
2020-05-27 18:41     ` Jeff King
2020-05-27 16:47   ` [PATCH 11/12] upload-pack: move allow_sideband_all " Christian Couder
2020-05-27 16:47   ` [PATCH 12/12] upload-pack: move pack_objects_hook " Christian Couder
2020-05-27 18:55     ` Jeff King
2020-05-27 18:57   ` [PATCH 00/12] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Jeff King
2020-05-27 20:41     ` Junio C Hamano
2020-06-02  4:16   ` [PATCH v2 00/13] " Christian Couder
2020-06-02  4:16     ` [PATCH v2 01/13] upload-pack: actually use some upload_pack_data bitfields Christian Couder
2020-06-02  4:16     ` [PATCH v2 02/13] upload-pack: annotate upload_pack_data fields Christian Couder
2020-06-02  4:16     ` [PATCH v2 03/13] upload-pack: move static vars to upload_pack_data Christian Couder
2020-06-02  6:59       ` Jeff King
2020-06-02  4:16     ` [PATCH v2 04/13] upload-pack: move use_sideband " Christian Couder
2020-06-02  4:16     ` [PATCH v2 05/13] upload-pack: move filter_capability_requested " Christian Couder
2020-06-02  4:16     ` [PATCH v2 06/13] upload-pack: move multi_ack " Christian Couder
2020-06-02  4:16     ` [PATCH v2 07/13] upload-pack: change multi_ack to an enum Christian Couder
2020-06-02  4:16     ` [PATCH v2 08/13] upload-pack: pass upload_pack_data to upload_pack_config() Christian Couder
2020-06-02  4:16     ` [PATCH v2 09/13] upload-pack: move keepalive to upload_pack_data Christian Couder
2020-06-02  4:16     ` [PATCH v2 10/13] upload-pack: move allow_filter " Christian Couder
2020-06-02  4:16     ` [PATCH v2 11/13] upload-pack: move allow_ref_in_want " Christian Couder
2020-06-02  4:16     ` [PATCH v2 12/13] upload-pack: move allow_sideband_all " Christian Couder
2020-06-02  4:16     ` [PATCH v2 13/13] upload-pack: move pack_objects_hook " Christian Couder
2020-06-02  7:08     ` [PATCH v2 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Jeff King
2020-06-02 17:24       ` Junio C Hamano
2020-06-02 19:05     ` [PATCH] fixup! upload-pack: change multi_ack to an enum Jonathan Tan
2020-06-02 19:28       ` Christian Couder
2020-06-04 17:54     ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Christian Couder
2020-06-04 17:54       ` [PATCH v3 01/13] upload-pack: actually use some upload_pack_data bitfields Christian Couder
2020-06-04 17:54       ` [PATCH v3 02/13] upload-pack: annotate upload_pack_data fields Christian Couder
2020-06-04 17:54       ` [PATCH v3 03/13] upload-pack: move static vars to upload_pack_data Christian Couder
2020-06-04 17:54       ` [PATCH v3 04/13] upload-pack: move use_sideband " Christian Couder
2020-06-04 17:54       ` [PATCH v3 05/13] upload-pack: move filter_capability_requested " Christian Couder
2020-06-04 17:54       ` [PATCH v3 06/13] upload-pack: move multi_ack " Christian Couder
2020-06-04 17:54       ` [PATCH v3 07/13] upload-pack: change multi_ack to an enum Christian Couder
2020-06-04 17:54       ` [PATCH v3 08/13] upload-pack: pass upload_pack_data to upload_pack_config() Christian Couder
2020-06-04 17:54       ` [PATCH v3 09/13] upload-pack: move keepalive to upload_pack_data Christian Couder
2020-06-04 17:54       ` [PATCH v3 10/13] upload-pack: move allow_filter " Christian Couder
2020-06-04 17:54       ` [PATCH v3 11/13] upload-pack: move allow_ref_in_want " Christian Couder
2020-06-04 17:54       ` [PATCH v3 12/13] upload-pack: move allow_sideband_all " Christian Couder
2020-06-04 17:54       ` [PATCH v3 13/13] upload-pack: move pack_objects_hook " Christian Couder
2020-06-04 18:07       ` [PATCH v3 00/13] upload-pack: use 'struct upload_pack_data' thoroughly, part 2 Junio C Hamano
2020-06-05 10:38         ` Christian Couder
2020-06-11 12:05 ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Christian Couder
2020-06-11 12:05   ` [PATCH 01/14] upload-pack: pass upload_pack_data to send_shallow_list() Christian Couder
2020-06-11 12:05   ` [PATCH 02/14] upload-pack: pass upload_pack_data to deepen() Christian Couder
2020-06-11 12:05   ` [PATCH 03/14] upload-pack: pass upload_pack_data to deepen_by_rev_list() Christian Couder
2020-06-11 12:05   ` [PATCH 04/14] upload-pack: pass upload_pack_data to send_unshallow() Christian Couder
2020-06-11 12:05   ` [PATCH 05/14] upload-pack: move shallow_nr to upload_pack_data Christian Couder
2020-06-11 12:05   ` [PATCH 06/14] upload-pack: move extra_edge_obj " Christian Couder
2020-06-11 12:05   ` [PATCH 07/14] upload-pack: move allow_unadvertised_object_request " Christian Couder
2020-06-11 12:05   ` [PATCH 08/14] upload-pack: change allow_unadvertised_object_request to an enum Christian Couder
2020-06-11 12:05   ` [PATCH 09/14] upload-pack: pass upload_pack_data to process_haves() Christian Couder
2020-06-11 12:05   ` [PATCH 10/14] upload-pack: pass upload_pack_data to send_acks() Christian Couder
2020-06-11 12:05   ` [PATCH 11/14] upload-pack: pass upload_pack_data to ok_to_give_up() Christian Couder
2020-06-11 12:05   ` [PATCH 12/14] upload-pack: pass upload_pack_data to got_oid() Christian Couder
2020-06-11 12:05   ` [PATCH 13/14] upload-pack: move oldest_have to upload_pack_data Christian Couder
2020-06-11 12:05   ` [PATCH 14/14] upload-pack: refactor common code into do_got_oid() Christian Couder
2020-06-11 20:04   ` [PATCH 00/14] upload-pack: use 'struct upload_pack_data' thoroughly, part 3 Jonathan Tan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).