diff mbox series

[06/12] upload-pack: change multi_ack to an enum

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

Commit Message

Christian Couder May 27, 2020, 4:47 p.m. UTC
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(-)

Comments

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

Patch

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