Merge branch 'lt/extended-sha1-match-commit-with-regexp'
* lt/extended-sha1-match-commit-with-regexp: Make :/ accept a regex rather than a fixed pattern
This commit is contained in:
commit
13cbf011a9
12
sha1_name.c
12
sha1_name.c
@ -679,8 +679,8 @@ static int handle_one_ref(const char *path,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* This interprets names like ':/Initial revision of "git"' by searching
|
* This interprets names like ':/Initial revision of "git"' by searching
|
||||||
* through history and returning the first commit whose message starts
|
* through history and returning the first commit whose message matches
|
||||||
* with the given string.
|
* the given regular expression.
|
||||||
*
|
*
|
||||||
* For future extension, ':/!' is reserved. If you want to match a message
|
* For future extension, ':/!' is reserved. If you want to match a message
|
||||||
* beginning with a '!', you have to repeat the exclamation mark.
|
* beginning with a '!', you have to repeat the exclamation mark.
|
||||||
@ -692,12 +692,17 @@ 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;
|
char *temp_commit_buffer = NULL;
|
||||||
|
regex_t regex;
|
||||||
|
|
||||||
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 (regcomp(®ex, prefix, REG_EXTENDED))
|
||||||
|
die("Invalid search pattern: %s", prefix);
|
||||||
|
|
||||||
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);
|
||||||
@ -721,12 +726,13 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
|
|||||||
}
|
}
|
||||||
if (!(p = strstr(p, "\n\n")))
|
if (!(p = strstr(p, "\n\n")))
|
||||||
continue;
|
continue;
|
||||||
if (!prefixcmp(p + 2, prefix)) {
|
if (!regexec(®ex, p + 2, 0, NULL, 0)) {
|
||||||
hashcpy(sha1, commit->object.sha1);
|
hashcpy(sha1, commit->object.sha1);
|
||||||
retval = 0;
|
retval = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
regfree(®ex);
|
||||||
free(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)
|
||||||
|
Loading…
Reference in New Issue
Block a user