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

Re: [PATCH 2/2] dir: do not feed path suffix to pathspec match

From
René Scharfe <l.s.r@web.de>
Date
Jul 8, 2023, 07:16 UTC
Message-ID
<f592e7c9-2a73-41f3-02a5-d77b7be574f1@web.de>
In-Reply-To
<20230707220457.3655121-3-gitster@pobox.com>
Am 08.07.23 um 00:04 schrieb Junio C Hamano:
Show 22 quoted lines
> diff --git a/dir.c b/dir.c
> index 3acac7beb1..6116022ae6 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -488,9 +476,6 @@ static int do_match_pathspec(struct index_state *istate,
>  			return 0;
>  	}
>
> -	name += prefix;
> -	namelen -= prefix;
> -
>  	for (i = ps->nr - 1; i >= 0; i--) {
>  		int how;
>
> @@ -506,8 +491,8 @@ static int do_match_pathspec(struct index_state *istate,
>  		 */
>  		if (seen && ps->items[i].magic & PATHSPEC_EXCLUDE)
>  			seen[i] = MATCHED_FNMATCH;
> -		how = match_pathspec_item(istate, ps->items+i, prefix, name,
> -					  namelen, flags);
> +		how = match_pathspec_item(istate, ps->items+i,
> +					  name, namelen, flags);

With that, the parameter "prefix" of do_match_pathspec() becomes unused and can be removed. This cascades to match_pathspec_with_flags(), match_pathspec(), dir_path_match() and builtin/add.c::prune_directory(), and fill_directory() can lose its return value.

The code continues here like this, though:
                if (ps->recursive &&
                    (ps->magic & PATHSPEC_MAXDEPTH) &&
                    ps->max_depth != -1 &&
                    how && how != MATCHED_FNMATCH) {
                        int len = ps->items[i].len;
                        if (name[len] == '/')
                                len++;
                        if (within_depth(name+len, namelen-len, 0, ps->max_depth))
                                how = MATCHED_EXACTLY;
                        else
                                how = 0;
                }

And "name" here would be affected by "prefix" no longer being added. Does it fix or break --max-depth? I think neither: builtin/grep.c -- the only user of PATHSPEC_MAXDEPTH AFAICS -- passes a prefix of 0.

René
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 9 in “Fix attr magic combined with pathspec prefix”
  1. 0/2 Fix attr magic combined with pathspec prefixJunio C Hamano, Jul 7, 2023
  2. 2/2 dir: do not feed path suffix to pathspec matchJunio C Hamano, Jul 7, 2023
  3. dir: do not feed path suffix to pathspec matchJunio C Hamano, Jul 7, 2023
  4. René ScharfeJul 8, 2023
  5. dir: match "attr" pathspec magic with correct pathsJunio C Hamano, Jul 8, 2023
  6. René ScharfeJul 9, 2023
  7. Junio C HamanoJul 9, 2023
  8. René ScharfeJul 8, 2023
  9. 1/2 t6135: attr magic with path patternJunio C Hamano, Jul 7, 2023

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.