@matheusbsbs / matheus-bagliano / commits / 364d3e65a5
Fork 0

Allow ':/<oneline-prefix>' syntax to work with save_commit_buffer == 0

Earlier, ':/<oneline-prefix>' would not work (i.e. die) with commands that set save_commit_buffer = 0, such as blame, describe, pack-objects, reflog and bundle. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Dec 3, 2007 at 18:42 UTC 364d3e65a5da76ac51217e68b55504cd2cd154aa
1 file changed +16 -3
sha1_name.c
+16 -3
@@ -610,24 +610,35 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
610 {
611 struct commit_list *list = NULL, *backup = NULL, *l;
612 int retval = -1;
613 + char *temp_commit_buffer = NULL;
614
615 if (prefix[0] == '!') {
616 if (prefix[1] != '!')
617 die ("Invalid search pattern: %s", prefix);
618 prefix++;
619 }
619 - if (!save_commit_buffer)
620 - return error("Could not expand oneline-name.");
620 for_each_ref(handle_one_ref, &list);
621 for (l = list; l; l = l->next)
622 commit_list_insert(l->item, &backup);
623 while (list) {
624 char *p;
625 struct commit *commit;
626 + enum object_type type;
627 + unsigned long size;
628
629 commit = pop_most_recent_commit(&list, ONELINE_SEEN);
630 parse_object(commit->object.sha1);
630 - if (!commit->buffer || !(p = strstr(commit->buffer, "\n\n")))
631 + if (temp_commit_buffer)
632 + free(temp_commit_buffer);
633 + if (commit->buffer)
634 + p = commit->buffer;
635 + else {
636 + p = read_sha1_file(commit->object.sha1, &type, &size);
637 + if (!p)
638 + continue;
639 + temp_commit_buffer = p;
640 + }
641 + if (!(p = strstr(p, "\n\n")))
642 continue;
643 if (!prefixcmp(p + 2, prefix)) {
644 hashcpy(sha1, commit->object.sha1);
@@ -635,6 +646,8 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
646 break;
647 }
648 }
649 + if (temp_commit_buffer)
650 + free(temp_commit_buffer);
651 free_commit_list(list);
652 for (l = backup; l; l = l->next)
653 clear_commit_marks(l->item, ONELINE_SEEN);