]> Pileus Git - ~andy/git/commitdiff
pathspec: catch prepending :(prefix) on pathspec with short magic
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Thu, 5 Sep 2013 03:40:38 +0000 (10:40 +0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Sep 2013 19:25:19 +0000 (12:25 -0700)
:(prefix) is in the long form. Suppose people pass :!foo with '!'
being the short form of magic 'bar', the code will happily turn it to
:(prefix..)!foo, which makes '!' part of the path and no longer a magic.

The correct form must be ':(prefix..,bar)foo', but as so far we
haven't had any magic in short form yet (*), the code to convert from
short form to long one will be inactive anyway. Let's postpone it
until a real short form magic appears.

(*) The short form magic '/' is a special case and won't be caught by
this die(), which is correct. When '/' magic is detected, prefixlen is
set back to 0 and the whole "if (prefixlen..)" block is skipped.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pathspec.c

index d9f41432221ab5f886aaf0a6e306cb263892ab33..62fde5060f064388387059d55e18f4ca5c36ad00 100644 (file)
@@ -231,7 +231,9 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
                const char *start = elt;
                if (prefixlen && !literal_global) {
                        /* Preserve the actual prefix length of each pattern */
-                       if (long_magic_end) {
+                       if (short_magic)
+                               die("BUG: prefixing on short magic is not supported");
+                       else if (long_magic_end) {
                                strbuf_add(&sb, start, long_magic_end - start);
                                strbuf_addf(&sb, ",prefix:%d", prefixlen);
                                start = long_magic_end;