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

Re: [PATCH v2 2/2] attr: more matching optimizations from .gitignore

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 10, 2012, 20:03 UTC
Message-ID
<7vpq4qaycn.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1349864466-28289-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
Show 11 quoted lines
> .gitattributes and .gitignore share the same pattern syntax but has
> separate matching implementation. Over the years, ignore's
> implementation accumulates more optimizations while attr's stays the
> same.
>
> This patch adds those optimizations to attr. Basically it tries to
> avoid fnmatch as much as possible in favor of strncmp.
>
> A few notes from this work is put in the documentation:
>
> * "!pattern" syntax is not supported in .gitattributes as it's not
s/not supported/forbidden/;

A reader can take "not supported" as "silently ignored", which is not the case. An explicit "forbidden" does not have such a misinterpretation.

It would save time from both of us if you can check what is queued on 'pu'. I do not think I touched the code for off-by-one bugs there, though.

Show 32 quoted lines
>   clear what it means (e.g. "!path attr" is about unsetting attr, or
>   undefining it..)
>
> * patterns applying to directories
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  How about this? Diff from the previous version:
>
>    diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
>    index cc2ff1d..9a0ed19 100644
>    --- a/Documentation/gitattributes.txt
>    +++ b/Documentation/gitattributes.txt
>    @@ -23,7 +23,7 @@ Each line in `gitattributes` file is of form:
>     That is, a pattern followed by an attributes list,
>     separated by whitespaces.  When the pattern matches the
>     path in question, the attributes listed on the line are given to
>    -the path. Only files can be attached attributes to.
>    +the path.
>     
>     Each attribute can be in one of these states for a given path:
>     
>    @@ -58,6 +58,13 @@ attribute.  The rules how the pattern matches paths are the
>     same as in `.gitignore` files; see linkgit:gitignore[5].
>     Unlike `.gitignore`, negative patterns are not supported.
>     
>    +Note that if a .gitignore rule matches a directory, the directory
>    +is ignored, which may be seen as assigning "ignore" attribute the
>    +directory and all files and directories inside. However, if a
>    +.gitattributes rule matches a directory, it manipulates
>    +attributes on that directory only, not files and directories
>    +inside.

Why do you even need to mention .gitignore in gitattributes manual where it is irrelevant from the reader's point of view?

Besides, the interpretation the "may be seen as" suggests is actively wrong. It is assigning "ignore-this-and-below" attribute to the directory, and there is no inconsistency between the two.

Again, I'd suggest dropping this addition.
Show 34 quoted lines
>    diff --git a/attr.c b/attr.c
>    index 7e85f82..4faf1ff 100644
>    --- a/attr.c
>    +++ b/attr.c
>    @@ -250,7 +250,6 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
>     	else {
>     		char *p = (char *)&(res->state[num_attr]);
>     		memcpy(p, name, namelen);
>    -		p[namelen] = 0;
>     		res->u.pat.pattern = p;
>     		parse_exclude_pattern(&res->u.pat.pattern,
>     				      &res->u.pat.patternlen,
>    @@ -690,16 +689,18 @@ static int path_matches(const char *pathname, int pathlen,
>     	 * contain the trailing slash
>     	 */
>     
>    -	if (pathlen < baselen ||
>    +	if (pathlen < baselen + 1 ||
>     	    (baselen && pathname[baselen] != '/') ||
>    -	    strncmp(pathname, base, baselen))
>    +	    strncmp_icase(pathname, base, baselen))
>     		return 0;
>     
>     	namelen = baselen ? pathlen - baselen - 1 : pathlen;
>     	name = pathname + pathlen - namelen;
>     
>    -	/* if the non-wildcard part is longer than the remaining
>    -	   pathname, surely it cannot match */
>    +	/*
>    +	 * if the non-wildcard part is longer than the remaining
>    +	 * pathname, surely it cannot match
>    +	 */
>     	if (!namelen || prefix > namelen)
>     		return 0;
Previous: Nguyễn Thái Ngọc DuyNext: Nguyen Thai Ngoc Duy
Message 8 of 14 in “gitignore: make pattern parsing code a separate function”
  1. 1/2 gitignore: make pattern parsing code a separate functionNguyễn Thái Ngọc Duy, Oct 9, 2012
  2. 2/2 attr: more matching optimizations from .gitignoreNguyễn Thái Ngọc Duy, Oct 9, 2012
  3. Junio C HamanoOct 9, 2012
  4. Johannes SixtOct 9, 2012
  5. Junio C HamanoOct 9, 2012
  6. Junio C HamanoOct 9, 2012
  7. 2/2 attr: more matching optimizations from .gitignoreNguyễn Thái Ngọc Duy, Oct 10, 2012
  8. Junio C HamanoOct 10, 2012
  9. Nguyen Thai Ngoc DuyOct 12, 2012
  10. Junio C HamanoOct 10, 2012
  11. Junio C HamanoOct 10, 2012
  12. Nguyen Thai Ngoc DuyOct 11, 2012
  13. Junio C HamanoOct 12, 2012
  14. Nguyen Thai Ngoc DuyOct 13, 2012

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.