Re-fix get_sha1_oneline()
What the function wants to return is not if we saw any return from pop_most_recent_commit(), but if we found what was asked for. Signed-off-by: Junio C Hamano <junkio@cox.net>
Linus Torvalds committed
Mar 12, 2007 at 11:30 UTC
1358e7d670306a9fe8a612f1ebd1f058474d20af
1 file changed
+5
-5
sha1_name.c
+5
-5
@@ -602,10 +602,10 @@ static int handle_one_ref(const char *path,
602
*/
603
604
#define ONELINE_SEEN (1u<<20)
605
-int get_sha1_oneline(const char *prefix, unsigned char *sha1)
605
+static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
606
{
607
struct commit_list *list = NULL, *backup = NULL, *l;
608
- struct commit *commit = NULL;
608
+ int retval = -1;
609
610
if (prefix[0] == '!') {
611
if (prefix[1] != '!')
@@ -619,22 +619,22 @@ int get_sha1_oneline(const char *prefix, unsigned char *sha1)
619
commit_list_insert(l->item, &backup);
620
while (list) {
621
char *p;
622
+ struct commit *commit;
623
624
commit = pop_most_recent_commit(&list, ONELINE_SEEN);
624
- if (!commit)
625
- break;
625
parse_object(commit->object.sha1);
626
if (!commit->buffer || !(p = strstr(commit->buffer, "\n\n")))
627
continue;
628
if (!prefixcmp(p + 2, prefix)) {
629
hashcpy(sha1, commit->object.sha1);
630
+ retval = 0;
631
break;
632
}
633
}
634
free_commit_list(list);
635
for (l = backup; l; l = l->next)
636
clear_commit_marks(l->item, ONELINE_SEEN);
637
- return commit == NULL;
637
+ return retval;
638
}
639
640
/*