Thread (19 messages) flat view 19 messages, 7 authors, 2016-06-15
STALE3753d

[PATCH 2/4] fast-import: use pointer-to-pointer to keep list tail

From: Jeff King <hidden>
Date: 2016-06-15 22:56:28
Subsystem: the rest · Maintainer: Linus Torvalds

This is shorter, idiomatic, and it means the compiler does
not get confused about whether our "e" pointer is valid,
letting us drop the "e = e" hack.

Signed-off-by: Jeff King <redacted>
---
And it fixes an instance of Linus's "people do not understand pointers"
from here:

  http://meta.slashdot.org/story/12/10/11/0030249/linus-torvalds-answers-your-questions

 fast-import.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index c2a814e..583a439 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2613,7 +2613,7 @@ static struct hash_list *parse_merge(unsigned int *count)
 
 static struct hash_list *parse_merge(unsigned int *count)
 {
-	struct hash_list *list = NULL, *n, *e = e;
+	struct hash_list *list = NULL, **tail = &list, *n;
 	const char *from;
 	struct branch *s;
 
@@ -2641,11 +2641,9 @@ static struct hash_list *parse_merge(unsigned int *count)
 			die("Invalid ref name or SHA1 expression: %s", from);
 
 		n->next = NULL;
-		if (list)
-			e->next = n;
-		else
-			list = n;
-		e = n;
+		*tail = n;
+		tail = &n->next;
+
 		(*count)++;
 		read_next_command();
 	}
-- 
1.8.2.rc2.8.g2161951
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help