pathspec: allow escaped query values
commitc5af19f9ab4cd8582689ca9d9c84f188f4442d10
authorBrandon Williams <bmwill@google.com>
Mon, 13 Mar 2017 18:23:22 +0000 (13 11:23 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Mar 2017 22:28:56 +0000 (13 15:28 -0700)
treef148fdc5c2b8d223227a6328dc3cb53c8c06dd7e
parentb0db70465246bb8309d3d12c9bc34ac3f0c1e203
pathspec: allow escaped query values

In our own .gitattributes file we have attributes such as:

    *.[ch] whitespace=indent,trail,space

When querying for attributes we want to be able to ask for the exact
value, i.e.

    git ls-files :(attr:whitespace=indent,trail,space)

should work, but the commas are used in the attr magic to introduce
the next attr, such that this query currently fails with

fatal: Invalid pathspec magic 'trail' in ':(attr:whitespace=indent,trail,space)'

This change allows escaping characters by a backslash, such that the query

    git ls-files :(attr:whitespace=indent\,trail\,space)

will match all path that have the value "indent,trail,space" for the
whitespace attribute. To accomplish this, we need to modify two places.
First `parse_long_magic` needs to not stop early upon seeing a comma or
closing paren that is escaped. As a second step we need to remove any
escaping from the attr value.

Based on a patch by Stefan Beller <sbeller@google.com>

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pathspec.c
t/t6135-pathspec-with-attrs.sh