summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-04-23 15:20:20 (GMT)
committerJunio C Hamano <gitster@pobox.com>2010-06-14 17:31:11 (GMT)
commit57895105c4ff083d7c9bc59b2b88b9b5176c1915 (patch)
treef8ac0c8533c76be194a859ba5c74c34d395c657a /sha1_name.c
parent6339f67fedfec454294dc33ebc3dcec6eeb70e02 (diff)
downloadgit-57895105c4ff083d7c9bc59b2b88b9b5176c1915.zip
git-57895105c4ff083d7c9bc59b2b88b9b5176c1915.tar.gz
git-57895105c4ff083d7c9bc59b2b88b9b5176c1915.tar.bz2
Make :/ accept a regex rather than a fixed pattern
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 <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/sha1_name.c b/sha1_name.c
index bf92417..8cf635a 100644
--- a/sha1_name.c
+++ b/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
- * 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.
@@ -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);
@@ -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)