Skip to content

Commit

Permalink
Make :/ accept a regex rather than a fixed pattern
Browse files Browse the repository at this point in the history
This also makes it trigger anywhere in the commit message, rather than
just at the beginning. Which tends to be a lot more useful.

Signed-off-by: Linus Torvalds <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
torvalds authored and gitster committed Jun 14, 2010
1 parent 6339f67 commit 5789510
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions sha1_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ static int handle_one_ref(const char *path,

/*
* This interprets names like ':/Initial revision of "git"' by searching
* through history and returning the first commit whose message starts
* with the given string.
* through history and returning the first commit whose message matches
* the given regular expression.
*
* For future extension, ':/!' is reserved. If you want to match a message
* beginning with a '!', you have to repeat the exclamation mark.
Expand All @@ -692,12 +692,17 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
struct commit_list *list = NULL, *backup = NULL, *l;
int retval = -1;
char *temp_commit_buffer = NULL;
regex_t regex;

if (prefix[0] == '!') {
if (prefix[1] != '!')
die ("Invalid search pattern: %s", prefix);
prefix++;
}

if (regcomp(&regex, prefix, REG_EXTENDED))
die("Invalid search pattern: %s", prefix);

for_each_ref(handle_one_ref, &list);
for (l = list; l; l = l->next)
commit_list_insert(l->item, &backup);
Expand All @@ -721,12 +726,13 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
}
if (!(p = strstr(p, "\n\n")))
continue;
if (!prefixcmp(p + 2, prefix)) {
if (!regexec(&regex, p + 2, 0, NULL, 0)) {
hashcpy(sha1, commit->object.sha1);
retval = 0;
break;
}
}
regfree(&regex);
free(temp_commit_buffer);
free_commit_list(list);
for (l = backup; l; l = l->next)
Expand Down

0 comments on commit 5789510

Please sign in to comment.