@@ -679,8 +679,8 @@ static int handle_one_ref(const char *path,
679679
680680/*
681681 * 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 .
684684 *
685685 * For future extension, ':/!' is reserved. If you want to match a message
686686 * 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)
692692 struct commit_list * list = NULL , * backup = NULL , * l ;
693693 int retval = -1 ;
694694 char * temp_commit_buffer = NULL ;
695+ regex_t regex ;
695696
696697 if (prefix [0 ] == '!' ) {
697698 if (prefix [1 ] != '!' )
698699 die ("Invalid search pattern: %s" , prefix );
699700 prefix ++ ;
700701 }
702+
703+ if (regcomp (& regex , prefix , REG_EXTENDED ))
704+ die ("Invalid search pattern: %s" , prefix );
705+
701706 for_each_ref (handle_one_ref , & list );
702707 for (l = list ; l ; l = l -> next )
703708 commit_list_insert (l -> item , & backup );
@@ -721,12 +726,13 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
721726 }
722727 if (!(p = strstr (p , "\n\n" )))
723728 continue ;
724- if (!prefixcmp ( p + 2 , prefix )) {
729+ if (!regexec ( & regex , p + 2 , 0 , NULL , 0 )) {
725730 hashcpy (sha1 , commit -> object .sha1 );
726731 retval = 0 ;
727732 break ;
728733 }
729734 }
735+ regfree (& regex );
730736 free (temp_commit_buffer );
731737 free_commit_list (list );
732738 for (l = backup ; l ; l = l -> next )
0 commit comments