зеркало из https://github.com/microsoft/git.git
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>
This commit is contained in:
Родитель
311db37e70
Коммит
364d3e65a5
19
sha1_name.c
19
sha1_name.c
|
@ -610,24 +610,35 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
|
||||||
{
|
{
|
||||||
struct commit_list *list = NULL, *backup = NULL, *l;
|
struct commit_list *list = NULL, *backup = NULL, *l;
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
char *temp_commit_buffer = NULL;
|
||||||
|
|
||||||
if (prefix[0] == '!') {
|
if (prefix[0] == '!') {
|
||||||
if (prefix[1] != '!')
|
if (prefix[1] != '!')
|
||||||
die ("Invalid search pattern: %s", prefix);
|
die ("Invalid search pattern: %s", prefix);
|
||||||
prefix++;
|
prefix++;
|
||||||
}
|
}
|
||||||
if (!save_commit_buffer)
|
|
||||||
return error("Could not expand oneline-name.");
|
|
||||||
for_each_ref(handle_one_ref, &list);
|
for_each_ref(handle_one_ref, &list);
|
||||||
for (l = list; l; l = l->next)
|
for (l = list; l; l = l->next)
|
||||||
commit_list_insert(l->item, &backup);
|
commit_list_insert(l->item, &backup);
|
||||||
while (list) {
|
while (list) {
|
||||||
char *p;
|
char *p;
|
||||||
struct commit *commit;
|
struct commit *commit;
|
||||||
|
enum object_type type;
|
||||||
|
unsigned long size;
|
||||||
|
|
||||||
commit = pop_most_recent_commit(&list, ONELINE_SEEN);
|
commit = pop_most_recent_commit(&list, ONELINE_SEEN);
|
||||||
parse_object(commit->object.sha1);
|
parse_object(commit->object.sha1);
|
||||||
if (!commit->buffer || !(p = strstr(commit->buffer, "\n\n")))
|
if (temp_commit_buffer)
|
||||||
|
free(temp_commit_buffer);
|
||||||
|
if (commit->buffer)
|
||||||
|
p = commit->buffer;
|
||||||
|
else {
|
||||||
|
p = read_sha1_file(commit->object.sha1, &type, &size);
|
||||||
|
if (!p)
|
||||||
|
continue;
|
||||||
|
temp_commit_buffer = p;
|
||||||
|
}
|
||||||
|
if (!(p = strstr(p, "\n\n")))
|
||||||
continue;
|
continue;
|
||||||
if (!prefixcmp(p + 2, prefix)) {
|
if (!prefixcmp(p + 2, prefix)) {
|
||||||
hashcpy(sha1, commit->object.sha1);
|
hashcpy(sha1, commit->object.sha1);
|
||||||
|
@ -635,6 +646,8 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (temp_commit_buffer)
|
||||||
|
free(temp_commit_buffer);
|
||||||
free_commit_list(list);
|
free_commit_list(list);
|
||||||
for (l = backup; l; l = l->next)
|
for (l = backup; l; l = l->next)
|
||||||
clear_commit_marks(l->item, ONELINE_SEEN);
|
clear_commit_marks(l->item, ONELINE_SEEN);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче