@matheusbsbs / matheus-bagliano / commits / ed8ad7e2e2
Fork 0

I like the idea of the new ':/<oneline prefix>' notation, and gave it a try, but all I could get was a segfault. It was dereferencing a NULL commit list. Fix below. With it, this example now works:

I like the idea of the new ':/<oneline prefix>' notation, and gave it a try, but all I could get was a segfault. It was dereferencing a NULL commit list. Fix below. With it, this example now works: $ mkdir .j; cd .j; touch f $ git-init; git-add f; git-commit -mc f; echo x >f; git-commit -md f $ git-diff -p :/c :/d diff --git a/f b/f index e69de29..587be6b 100644 --- a/f +++ b/f @@ -0,0 +1 @@ +x Signed-off-by: Jim Meyering <jim@meyering.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jim Meyering committed Mar 11, 2007 at 19:49 UTC ed8ad7e2e29d4adf342964f6cc15d6b84f62c700
1 file changed +6 -2
sha1_name.c
+6 -2
@@ -605,7 +605,7 @@ static int handle_one_ref(const char *path,
605 int get_sha1_oneline(const char *prefix, unsigned char *sha1)
606 {
607 struct commit_list *list = NULL, *backup = NULL, *l;
608 - struct commit *commit;
608 + struct commit *commit = NULL;
609
610 if (prefix[0] == '!') {
611 if (prefix[1] != '!')
@@ -617,8 +617,12 @@ int get_sha1_oneline(const char *prefix, unsigned char *sha1)
617 for_each_ref(handle_one_ref, &list);
618 for (l = list; l; l = l->next)
619 commit_list_insert(l->item, &backup);
620 - while ((commit = pop_most_recent_commit(&list, ONELINE_SEEN))) {
620 + while (list) {
621 char *p;
622 +
623 + commit = pop_most_recent_commit(&list, ONELINE_SEEN);
624 + if (!commit)
625 + break;
626 parse_object(commit->object.sha1);
627 if (!commit->buffer || !(p = strstr(commit->buffer, "\n\n")))
628 continue;