combine-diff: fix appending at the tail of a list.
... and use the established pattern of tail initialized to point at the head pointer for an empty list, and updated to point at the next pointer field of the item at the tail when appending. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 25, 2006 at 03:34 UTC
5290a0f8129cc5830390bad3cc6c8034cb23b41c
1 file changed
+6
-11
combine-diff.c
+6
-11
@@ -29,7 +29,7 @@ static struct path_list *intersect_paths(struct path_list *curr,
29
int i;
30
31
if (!n) {
32
- struct path_list *list = NULL, *tail = NULL;
32
+ struct path_list *list = NULL, **tail = &list;
33
for (i = 0; i < q->nr; i++) {
34
int len;
35
const char *path;
@@ -46,12 +46,8 @@ static struct path_list *intersect_paths(struct path_list *curr,
46
p->next = NULL;
47
memcpy(p->sha1, q->queue[i]->two->sha1, 20);
48
memcpy(p->parent_sha1[n], q->queue[i]->one->sha1, 20);
49
- if (!tail)
50
- list = tail = p;
51
- else {
52
- tail->next = p;
53
- p = tail;
54
- }
49
+ *tail = p;
50
+ tail = &p->next;
51
}
52
return list;
53
}
@@ -212,10 +208,7 @@ static void append_lost(struct sline *sline, int n, const char *line)
208
lline->parent_map = this_mask;
209
memcpy(lline->line, line, len);
210
lline->line[len] = 0;
215
- if (sline->lost_head)
216
- *(sline->lost_tail) = lline;
217
- else
218
- sline->lost_head = lline;
211
+ *sline->lost_tail = lline;
212
sline->lost_tail = &lline->next;
213
}
214
@@ -433,6 +426,7 @@ static void show_combined_diff(struct path_list *elem, int num_parent,
426
sline[0].bol = result;
427
for (lno = 0, cp = result; cp - result < size; cp++) {
428
if (*cp == '\n') {
429
+ sline[lno].lost_tail = &sline[lno].lost_head;
430
sline[lno].len = cp - sline[lno].bol;
431
sline[lno].flag = (1UL<<num_parent) - 1;
432
lno++;
@@ -441,6 +435,7 @@ static void show_combined_diff(struct path_list *elem, int num_parent,
435
}
436
}
437
if (result[size-1] != '\n') {
438
+ sline[cnt-1].lost_tail = &sline[cnt-1].lost_head;
439
sline[cnt-1].len = size - (sline[cnt-1].bol - result);
440
sline[cnt-1].flag = (1UL<<num_parent) - 1;
441
}