summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-02-10 14:20:10 -0800
committerJunio C Hamano <gitster@pobox.com>2016-02-10 14:20:10 -0800
commitfb795323ce3ce5a358f8e55641777b9cdbeab846 (patch)
tree886f5c1eaef8861f19bbd8b3d7a364444d9ba9ca /sha1_name.c
parent722c9244452c1853f0592b22c331382c282768c7 (diff)
parent0769854f3db2c09c8b5993ea023ea07ddc1eb6eb (diff)
downloadgit-fb795323ce3ce5a358f8e55641777b9cdbeab846.tar.gz
Merge branch 'wp/sha1-name-negative-match'
A new "<branch>^{/!-<pattern>}" notation can be used to name a commit that is reachable from <branch> that does not match the given <pattern>. * wp/sha1-name-negative-match: object name: introduce '^{/!-<negative pattern>}' notation test for '!' handling in rev-parse's named commits
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 892db21813..89918ca158 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -848,8 +848,12 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l
* through history and returning the first commit whose message starts
* 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.
+ * For negative-matching, prefix the pattern-part with '!-', like: ':/!-WIP'.
+ *
+ * For a literal '!' character at the beginning of a pattern, you have to repeat
+ * that, like: ':/!!foo'
+ *
+ * For future extension, all other sequences beginning with ':/!' are reserved.
*/
/* Remember to update object flag allocation in object.h */
@@ -878,12 +882,18 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
{
struct commit_list *backup = NULL, *l;
int found = 0;
+ int negative = 0;
regex_t regex;
if (prefix[0] == '!') {
- if (prefix[1] != '!')
- die ("Invalid search pattern: %s", prefix);
prefix++;
+
+ if (prefix[0] == '-') {
+ prefix++;
+ negative = 1;
+ } else if (prefix[0] != '!') {
+ die ("Invalid search pattern: %s", prefix);
+ }
}
if (regcomp(&regex, prefix, REG_EXTENDED))
@@ -903,7 +913,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
continue;
buf = get_commit_buffer(commit, NULL);
p = strstr(buf, "\n\n");
- matches = p && !regexec(&regex, p + 2, 0, NULL, 0);
+ matches = negative ^ (p && !regexec(&regex, p + 2, 0, NULL, 0));
unuse_commit_buffer(commit, buf);
if (matches) {