diff mbox series

[13/13] upload-pack: use upload_pack_data fields in receive_needs()

Message ID 20200515100454.14486-14-chriscool@tuxfamily.org (mailing list archive)
State New, archived
Headers show
Series upload-pack: use 'struct upload_pack_data' thoroughly, part 1 | expand

Commit Message

Christian Couder May 15, 2020, 10:04 a.m. UTC
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(-)

Comments

Jeff King May 15, 2020, 6:42 p.m. UTC | #1
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
diff mbox series

Patch

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 */