/*
* 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.
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(®ex, 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);
}
if (!(p = strstr(p, "\n\n")))
continue;
- if (!prefixcmp(p + 2, prefix)) {
+ if (!regexec(®ex, p + 2, 0, NULL, 0)) {
hashcpy(sha1, commit->object.sha1);
retval = 0;
break;
}
}
+ regfree(®ex);
free(temp_commit_buffer);
free_commit_list(list);
for (l = backup; l; l = l->next)