builtin/blame.c: struct blame_entry does not need a prev link
[gitweb.git] / pathspec.c
index 4e6a727570a3d9c7511009bcc71f8ae0ed2d5fa1..6cb9fd3014a424d11647e48de3b841012ccc2ffe 100644 (file)
@@ -74,6 +74,20 @@ static struct pathspec_magic {
        { PATHSPEC_EXCLUDE, '!', "exclude" },
 };
 
+static void prefix_short_magic(struct strbuf *sb, int prefixlen,
+                              unsigned short_magic)
+{
+       int i;
+       strbuf_addstr(sb, ":(");
+       for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++)
+               if (short_magic & pathspec_magic[i].bit) {
+                       if (sb->buf[sb->len - 1] != '(')
+                               strbuf_addch(sb, ',');
+                       strbuf_addstr(sb, pathspec_magic[i].name);
+               }
+       strbuf_addf(sb, ",prefix:%d)", prefixlen);
+}
+
 /*
  * Take an element of a pathspec and check for magic signatures.
  * Append the result to the prefix. Return the magic bitmap.
@@ -155,7 +169,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
                                        magic |= pathspec_magic[i].bit;
                                        break;
                                }
-                               if (!prefixcmp(copyfrom, "prefix:")) {
+                               if (starts_with(copyfrom, "prefix:")) {
                                        char *endptr;
                                        pathspec_prefix = strtol(copyfrom + 7,
                                                                 &endptr, 10);
@@ -233,22 +247,16 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
         */
        if (flags & PATHSPEC_PREFIX_ORIGIN) {
                struct strbuf sb = STRBUF_INIT;
-               const char *start = elt;
                if (prefixlen && !literal_global) {
                        /* Preserve the actual prefix length of each pattern */
                        if (short_magic)
-                               die("BUG: prefixing on short magic is not supported");
+                               prefix_short_magic(&sb, prefixlen, short_magic);
                        else if (long_magic_end) {
-                               strbuf_add(&sb, start, long_magic_end - start);
-                               strbuf_addf(&sb, ",prefix:%d", prefixlen);
-                               start = long_magic_end;
-                       } else {
-                               if (*start == ':')
-                                       start++;
+                               strbuf_add(&sb, elt, long_magic_end - elt);
+                               strbuf_addf(&sb, ",prefix:%d)", prefixlen);
+                       } else
                                strbuf_addf(&sb, ":(prefix:%d)", prefixlen);
-                       }
                }
-               strbuf_add(&sb, start, copyfrom - start);
                strbuf_addstr(&sb, match);
                item->original = strbuf_detach(&sb, NULL);
        } else