[PATCH 4/6] rsync transport: clarify insert_packed_refs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



gcc -Wuninitialized warns us that it might be confusing.

Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
 transport.c |   35 +++++++++++++++++++----------------
 1 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/transport.c b/transport.c
index 718605f..0f06720 100644
--- a/transport.c
+++ b/transport.c
@@ -104,7 +104,8 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
 		return;
 
 	for (;;) {
-		int cmp, len;
+		int cmp = 1, len;
+		struct ref *next;
 
 		if (!fgets(buffer, sizeof(buffer), f)) {
 			fclose(f);
@@ -118,22 +119,24 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
 			buffer[--len] = '\0';
 		if (len < 41)
 			continue;
-		while ((*list)->next &&
-				(cmp = strcmp(buffer + 41,
-				      (*list)->next->name)) > 0)
-			list = &(*list)->next;
-		if (!(*list)->next || cmp < 0) {
-			struct ref *next = alloc_ref(buffer + 41);
-			buffer[40] = '\0';
-			if (get_sha1_hex(buffer, next->old_sha1)) {
-				warning ("invalid SHA-1: %s", buffer);
-				free(next);
-				continue;
-			}
-			next->next = (*list)->next;
-			(*list)->next = next;
-			list = &(*list)->next;
+		for (; (*list)->next; list = &(*list)->next) {
+			cmp = strcmp(buffer + 41, (*list)->next->name);
+			if (cmp <= 0)
+				break;
+		}
+		if (!cmp)	/* already inserted. */
+			continue;
+
+		next = alloc_ref(buffer + 41);
+		buffer[40] = '\0';
+		if (get_sha1_hex(buffer, next->old_sha1)) {
+			warning ("invalid SHA-1: %s", buffer);
+			free(next);
+			continue;
 		}
+		next->next = (*list)->next;
+		(*list)->next = next;
+		list = &(*list)->next;
 	}
 }
 
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]