pathspec magic extension to search for attributes
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v9 Latest4 patches 4 repliesIn review
- v85 patches 16 repliesSuperseded
- v75 patches 6 repliesSuperseded
Patches in v9 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/4 | Documentation: fix a typoDocumentation/ | +1 | 0 replies | |
| 2/4 | pathspec: move long magic parsing out of prefix_pathspecpathspec.c | +47 | 0 replies | |
| 3/4 | pathspec: move prefix check out of the inner looppathspec.c | +10 | 0 replies | |
| 4/4 | pathspec: allow querying for attributesDocumentation/ dir.c pathspec.c +2 more | +331 | 4 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v9 yet.
Cover letter [PATCHv9 0/4] pathspec magic extension to search for attributes
This goes on top of origin/jc/attr, (396bf756f95, attr: expose validity check for attribute names)
Patches 1 is a small fix, which could go independently as well. I dropped the patch "string list: improve comment" Patches 3 and 4 are refactoring pathspec.c a little. These did not change since v7
Patch 5 contains all of Junios suggestions.
Thanks,
Stefan
diff to v8:
Documentation/glossary-content.txt +17 -14
@@ -385,20 +385,23 @@ full pathname may have special meaning: Glob magic is incompatible with literal magic. attr;; - Additionally to matching the pathspec, the path must have the - attribute as specified. The syntax for specifying the required - attributes is "`attr: [mode] <attribute name> [=value]`" -+ -Attributes can have 4 states (Set, Unset, Set to a value, unspecified) and -you can query each attribute for certain states. The "`[mode]`" is a special -character to indicate which attribute states are looked for. The following -modes are available: - - - an empty "`[mode]`" matches if the attribute is set - - "`-`" the attribute must be unset - - "`!`" the attribute must be unspecified - - an empty "`[mode]`" combined with "`[=value]`" matches if the attribute has - the given value. +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;;
dir.c +3 -3
@@ -231,11 +231,11 @@ static int match_attrs(const char *name, int namelen, match_mode = item->attr_match[i].match_mode;if (ATTR_TRUE (value)) - matched = match_mode ==MATCH_SET ; + matched = (match_mode ==MATCH_SET );else if (ATTR_FALSE (value)) - matched = match_mode ==MATCH_UNSET ; + matched = (match_mode ==MATCH_UNSET );else if (ATTR_UNSET (value)) - matched = match_mode ==MATCH_UNSPECIFIED ; + matched = (match_mode ==MATCH_UNSPECIFIED );else matched = (match_mode ==MATCH_VALUE && !strcmp (item->attr_match[i].value, value));
pathspec.c +22 -18
@@ -115,34 +115,38 @@ static void parse_pathspec_attr_match(struct pathspec_item *item, const char *vaconst char *attr = si->string;struct attr_match *am = &item->attr_match[j]; -if (attr[0 ] =='!' ) + attr_len =strcspn (attr,"=" ); +switch (*attr) { +case '!' : am->match_mode =MATCH_UNSPECIFIED ; -else if (attr[0 ] =='-' ) + attr++; + attr_len--; +break ; +case '-' : am->match_mode =MATCH_UNSET ; -else - am->match_mode =MATCH_SET ; - -if (am->match_mode !=MATCH_SET ) -/* skip first character */ attr++; + attr_len--; +break ; +default : +if (attr[attr_len] !='=' ) + am->match_mode =MATCH_SET ; +else { + am->match_mode =MATCH_VALUE ; + am->value =xstrdup (&attr[attr_len +1 ]); +if (strchr (am->value,'\\' )) +die (_ ("attr spec values must not contain backslashes" )); + } +break ; + } - attr_len =strcspn (attr,"=" ); -if (attr[attr_len] =='=' ) { - am->match_mode =MATCH_VALUE ; - am->value =xstrdup (&attr[attr_len +1 ]); -if (strchr (am->value,'\\' )) -die (_ ("attr spec values must not contain backslashes" )); - }else - am->value =NULL ; - -if (!attr_name_valid (attr, attr_len)) { + am->attr =git_attr_counted (attr, attr_len); +if (!am->attr) {struct strbuf sb =STRBUF_INIT ; am->match_mode =INVALID_ATTR ;invalid_attr_name_message (&sb, attr, attr_len);die (_ ("invalid attribute in '%s': '%s'" ), value, sb.buf); } - am->attr =git_attr_counted (attr, attr_len);git_attr_check_append (item->attr_check, am->attr); }
string-list.h +1 -1
@@ -106,7 +106,7 @@ void unsorted_string_list_delete_item(struct string_list *list, int i, int free_* list->strdup_strings must be set, as new memory needs to be * allocated to hold the substrings. If maxsplit is non-negative, * then split at most maxsplit times. Return the number of substrings -* appended to list. The list may be non-empty already. +* appended to list. * * Examples: * string_list_split(l, "foo:bar:baz", ':', -1) -> ["foo", "bar", "baz"]
t/t6134-pathspec-with-labels.sh +96 -99
243 lines not on this page · raw message