Skip to content

Commit 364d3e6

Browse files
dschogitster
authored andcommitted
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>
1 parent 311db37 commit 364d3e6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

sha1_name.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,31 +610,44 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
610610
{
611611
struct commit_list *list = NULL, *backup = NULL, *l;
612612
int retval = -1;
613+
char *temp_commit_buffer = NULL;
613614

614615
if (prefix[0] == '!') {
615616
if (prefix[1] != '!')
616617
die ("Invalid search pattern: %s", prefix);
617618
prefix++;
618619
}
619-
if (!save_commit_buffer)
620-
return error("Could not expand oneline-name.");
621620
for_each_ref(handle_one_ref, &list);
622621
for (l = list; l; l = l->next)
623622
commit_list_insert(l->item, &backup);
624623
while (list) {
625624
char *p;
626625
struct commit *commit;
626+
enum object_type type;
627+
unsigned long size;
627628

628629
commit = pop_most_recent_commit(&list, ONELINE_SEEN);
629630
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")))
631642
continue;
632643
if (!prefixcmp(p + 2, prefix)) {
633644
hashcpy(sha1, commit->object.sha1);
634645
retval = 0;
635646
break;
636647
}
637648
}
649+
if (temp_commit_buffer)
650+
free(temp_commit_buffer);
638651
free_commit_list(list);
639652
for (l = backup; l; l = l->next)
640653
clear_commit_marks(l->item, ONELINE_SEEN);

0 commit comments

Comments
 (0)