diff mbox series

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

Message ID 20200515100454.14486-8-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 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(-)

Comments

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

Patch

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);