git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCHv9 4/4] pathspec: allow querying for attributes

From
Junio C Hamano <gitster@pobox.com>
Date
May 20, 2016, 18:15 UTC
Message-ID
<xmqqd1ogegtn.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<xmqqbn41hbeq.fsf@gitster.mtv.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 8 quoted lines
> Stefan Beller <sbeller@google.com> writes:
>
>> +attr;;
>> +After `attr:` comes a space separated list of "attribute
>> +...
>> ++
>
> The text looks OK, but does it format well?

I didn't check this, but the remainder would look like this squashable patch.

You seem to i18ngrep for "fatal" but we are using test_must_fail for the exit status, so I am not sure if that adds much value, so the additional tests here do nto use that pattern.

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 = &item->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..060047a 100755
--- a/t/t6134-pathspec-with-labels.sh
+++ b/t/t6134-pathspec-with-labels.sh
@@ -160,4 +160,9 @@ test_expect_success 'abort on giving invalid label on the command line' '
 	test_i18ngrep "fatal" actual
 '
 
+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
Previous: Junio C HamanoNext: Stefan Beller
Message 7 of 9 in “[PATCHv9 0/4] pathspec magic extension to search for attributes”
  1. Stefan BellerMay 19, 2016
  2. 1/4 Documentation: fix a typoStefan Beller, May 19, 2016
  3. 2/4 pathspec: move long magic parsing out of prefix_pathspecStefan Beller, May 19, 2016
  4. 3/4 pathspec: move prefix check out of the inner loopStefan Beller, May 19, 2016
  5. 4/4 pathspec: allow querying for attributesStefan Beller, May 19, 2016
  6. Junio C HamanoMay 19, 2016
  7. Junio C HamanoMay 20, 2016
  8. Stefan BellerMay 20, 2016
  9. Junio C HamanoMay 20, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.