@matheusbsbs / matheus-bagliano / commits / 57895105c4
Fork 0

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>

Linus Torvalds committed Apr 23, 2010 at 08:20 UTC 57895105c4ff083d7c9bc59b2b88b9b5176c1915
1 file changed +9 -3
sha1_name.c
+9 -3
@@ -679,8 +679,8 @@ static int handle_one_ref(const char *path,
679
680 /*
681 * This interprets names like ':/Initial revision of "git"' by searching
682 - * through history and returning the first commit whose message starts
683 - * with the given string.
682 + * through history and returning the first commit whose message matches
683 + * the given regular expression.
684 *
685 * For future extension, ':/!' is reserved. If you want to match a message
686 * 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)
692 struct commit_list *list = NULL, *backup = NULL, *l;
693 int retval = -1;
694 char *temp_commit_buffer = NULL;
695 + regex_t regex;
696
697 if (prefix[0] == '!') {
698 if (prefix[1] != '!')
699 die ("Invalid search pattern: %s", prefix);
700 prefix++;
701 }
702 +
703 + if (regcomp(&regex, prefix, REG_EXTENDED))
704 + die("Invalid search pattern: %s", prefix);
705 +
706 for_each_ref(handle_one_ref, &list);
707 for (l = list; l; l = l->next)
708 commit_list_insert(l->item, &backup);
@@ -721,12 +726,13 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
726 }
727 if (!(p = strstr(p, "\n\n")))
728 continue;
724 - if (!prefixcmp(p + 2, prefix)) {
729 + if (!regexec(&regex, p + 2, 0, NULL, 0)) {
730 hashcpy(sha1, commit->object.sha1);
731 retval = 0;
732 break;
733 }
734 }
735 + regfree(&regex);
736 free(temp_commit_buffer);
737 free_commit_list(list);
738 for (l = backup; l; l = l->next)