Re: [PATCHv9] pathspec: allow querying for attributes

2016-05-20 Thread Junio C Hamano
Thanks.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv9] pathspec: allow querying for attributes

2016-05-20 Thread Stefan Beller
The pathspec mechanism is extended via the new
":(attr:eol=input)pattern/to/match" syntax to filter paths so that it
requires paths to not just match the given pattern but also have the
specified attrs attached for them to be chosen.

Signed-off-by: Stefan Beller 
---

Junio, please replace the last patch of sb/pathspec-label with this one.

diff to last round:
#   diff --git a/Documentation/glossary-content.txt 
b/Documentation/glossary-content.txt
#   index e06520b..181f52e 100644
#   --- a/Documentation/glossary-content.txt
#   +++ b/Documentation/glossary-content.txt
#   @@ -389,7 +389,7 @@ After `attr:` comes a space separated list of 
"attribute
#requirements", all of which must be met in order for the
#path to be considered a match; this is in addition to the
#usual non-magic pathspec pattern matching.
#   -
#   ++
#Each of the attribute requirements for the path takes one of
#these forms:
#
#   diff --git a/pathspec.c b/pathspec.c
#   index 693a5e7..0a02255 100644
#   --- a/pathspec.c
#   +++ b/pathspec.c
#   @@ -115,19 +115,19 @@ static void parse_pathspec_attr_match(struct 
pathspec_item *item, const char *va
#   const char *attr = si->string;
#   struct attr_match *am = >attr_match[j];
#
#   -   attr_len = strcspn(attr, "=");
#   switch (*attr) {
#   case '!':
#   am->match_mode = MATCH_UNSPECIFIED;
#   attr++;
#   -   attr_len--;
#   +   attr_len = strlen(attr);
#   break;
#   case '-':
#   am->match_mode = MATCH_UNSET;
#   attr++;
#   -   attr_len--;
#   +   attr_len = strlen(attr);
#   break;
#   default:
#   +   attr_len = strcspn(attr, "=");
#   if (attr[attr_len] != '=')
#   am->match_mode = MATCH_SET;
#   else {
#   diff --git a/t/t6134-pathspec-with-labels.sh 
b/t/t6134-pathspec-with-labels.sh
#   index 5da1a63..a5c9632 100755
#   --- a/t/t6134-pathspec-with-labels.sh
#   +++ b/t/t6134-pathspec-with-labels.sh
#   @@ -40,8 +40,7 @@ test_expect_success 'setup a tree' '
#'
#
#test_expect_success 'pathspec with no attr' '
#   -   test_must_fail git ls-files ":(attr:)" 2>actual &&
#   -   test_i18ngrep fatal actual
#   +   test_must_fail git ls-files ":(attr:)"
#'
#
#test_expect_success 'pathspec with labels and non existent 
.gitattributes' '
#   @@ -156,8 +155,12 @@ test_expect_success 'check label excluding other 
labels' '
#'
#
#test_expect_success 'abort on giving invalid label on the command 
line' '
#   -   test_must_fail git ls-files . ":(attr:☺)" 2>actual &&
#   -   test_i18ngrep "fatal" actual
#   +   test_must_fail git ls-files . ":(attr:☺)"
#   +'
#   +
#   +test_expect_success 'abort on asking for wrong magic' '
#   +   test_must_fail git ls-files . ":(attr:-label=foo)" &&
#   +   test_must_fail git ls-files . ":(attr:!label=foo)"
#'
#
#test_done

 Documentation/glossary-content.txt |  20 +
 dir.c  |  35 
 pathspec.c | 101 +-
 pathspec.h |  16 
 t/t6134-pathspec-with-labels.sh| 166 +
 5 files changed, 334 insertions(+), 4 deletions(-)
 create mode 100755 t/t6134-pathspec-with-labels.sh

diff --git a/Documentation/glossary-content.txt 
b/Documentation/glossary-content.txt
index cafc284..181f52e 100644
--- a/Documentation/glossary-content.txt
+++ b/Documentation/glossary-content.txt
@@ -384,6 +384,26 @@ full pathname may have special meaning:
 +
 Glob magic is incompatible with literal magic.
 
+attr;;
+After `attr:` comes a space separated list of "attribute
+requirements", all of which must be met in order for the
+path to be considered a match; this is in addition to the
+usual non-magic pathspec pattern matching.
++
+Each of the attribute requirements for the path takes one of
+these forms:
+
+- "`ATTR`" requires that the attribute `ATTR` must be set.
+
+- "`-ATTR`" requires that the attribute `ATTR` must be unset.
+
+- "`ATTR=VALUE`" requires that the attribute `ATTR` must be
+  set to the string `VALUE`.
+
+- "`!ATTR`" requires that the attribute `ATTR` must be
+  unspecified.
++
+
 exclude;;
After a path matches any non-exclude pathspec, it will be run
through all exclude pathspec (magic