t5500, t5539: tests for shallow depth excluding a ref
[gitweb.git] / sha1_name.c
index 37ba126d9b0887a05aaa00373dfe6687e1f79038..89918ca158379a02368b0604b14465fa14855c8e 100644 (file)
@@ -616,13 +616,13 @@ static int get_parent(const char *name, int len,
        if (parse_commit(commit))
                return -1;
        if (!idx) {
-               hashcpy(result, get_object_hash(commit->object));
+               hashcpy(result, commit->object.oid.hash);
                return 0;
        }
        p = commit->parents;
        while (p) {
                if (!--idx) {
-                       hashcpy(result, get_object_hash(p->item->object));
+                       hashcpy(result, p->item->object.oid.hash);
                        return 0;
                }
                p = p->next;
@@ -649,7 +649,7 @@ static int get_nth_ancestor(const char *name, int len,
                        return -1;
                commit = commit->parents->item;
        }
-       hashcpy(result, get_object_hash(commit->object));
+       hashcpy(result, commit->object.oid.hash);
        return 0;
 }
 
@@ -659,7 +659,7 @@ struct object *peel_to_type(const char *name, int namelen,
        if (name && !namelen)
                namelen = strlen(name);
        while (1) {
-               if (!o || (!o->parsed && !parse_object(get_object_hash(*o))))
+               if (!o || (!o->parsed && !parse_object(o->oid.hash)))
                        return NULL;
                if (expected_type == OBJ_ANY || o->type == expected_type)
                        return o;
@@ -736,7 +736,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
                return -1;
        if (!expected_type) {
                o = deref_tag(o, name, sp - name - 2);
-               if (!o || (!o->parsed && !parse_object(get_object_hash(*o))))
+               if (!o || (!o->parsed && !parse_object(o->oid.hash)))
                        return -1;
                hashcpy(sha1, o->oid.hash);
                return 0;
@@ -751,7 +751,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
        if (!o)
                return -1;
 
-       hashcpy(sha1, get_object_hash(*o));
+       hashcpy(sha1, o->oid.hash);
        if (sp[0] == '/') {
                /* "$commit^{/foo}" */
                char *prefix;
@@ -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))
@@ -899,15 +909,15 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
                int matches;
 
                commit = pop_most_recent_commit(&list, ONELINE_SEEN);
-               if (!parse_object(get_object_hash(commit->object)))
+               if (!parse_object(commit->object.oid.hash))
                        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) {
-                       hashcpy(sha1, get_object_hash(commit->object));
+                       hashcpy(sha1, commit->object.oid.hash);
                        found = 1;
                        break;
                }