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

Re: [PATCH v3 3/4] pathspec: add flag to indicate operation without repository

From
Jacob Keller <jacob.e.keller@intel.com>
Date
May 21, 2025, 23:05 UTC
Message-ID
<aa11a7ae-d7ba-445f-b3fa-a180843682c1@intel.com>
In-Reply-To
<xmqqwmabjoww.fsf@gitster.g>
On 5/20/2025 8:13 AM, Junio C Hamano wrote:
Show 48 quoted lines
> Jacob Keller <jacob.e.keller@intel.com> writes:
> 
>> From: Jacob Keller <jacob.keller@gmail.com>
>>
>> A following change will add support for pathspecs to the git diff
>> --no-index command. This mode of git diff does not load any repository.
>>
>> Add a new PATHSPEC_NO_REPOSITORY flag indicating that we're parsing
>> pathspecs without a repository.
>>
>> Both PATHSPEC_ATTR and PATHSPEC_FROMTOP require a repository to
>> function. Thus, verify that both of these are set in magic_mask to
>> ensure they won't be accepted when PATHSPEC_NO_REPOSITORY is set.
>>
>> Check PATHSPEC_NO_REPOSITORY when warning about paths outside the
>> directory tree. When the flag is set, do not look for a git repository
>> when generating the warning message.
>>
>> Finally, add a BUG in match_pathspec_item if the istate is NULL but the
>> pathspec has PATHSPEC_ATTR set. Callers which support PATHSPEC_ATTR
>> should always pass a valid istate, and callers which don't pass a valid
>> istate should have set PATHSPEC_ATTR in the magic_mask field to disable
>> support for attribute-based pathspecs.
> 
> All very sensible considerations.
> 
>> diff --git a/dir.c b/dir.c
>> index 2f2b654b0252..45aac0bfacab 100644
>> --- a/dir.c
>> +++ b/dir.c
>> @@ -396,9 +396,12 @@ static int match_pathspec_item(struct index_state *istate,
>>  	    strncmp(item->match, name - prefix, item->prefix))
>>  		return 0;
>>  
>> -	if (item->attr_match_nr &&
>> -	    !match_pathspec_attrs(istate, name - prefix, namelen + prefix, item))
>> -		return 0;
>> +	if (item->attr_match_nr) {
>> +		if (!istate)
>> +			BUG("magic PATHSPEC_ATTR requires an index");
>> +		if (!match_pathspec_attrs(istate, name - prefix, namelen + prefix, item))
>> +			return 0;
>> +	}
> 
> It is a bit curious why we do not check PATHSPEC_NO_REPOSITORY here,
> but it is OK, because it is a BUG for istate to be NULL when we have
> a repository anyway.
> 

match_pathspec doesn't take the same flags as parse_pathspec anyways, so we can't check it here :)

Previous: Jacob KellerNext: Jacob Keller
Message 11 of 15 in “diff: add pathspec support to --no-index”
  1. 0/4 diff: add pathspec support to --no-indexJacob Keller, May 20, 2025
  2. 1/4 prefix_path: support prefixes not ending in trailing slashJacob Keller, May 20, 2025
  3. Junio C HamanoMay 20, 2025
  4. Jacob KellerMay 20, 2025
  5. 2/4 pathspec: expose match_pathspec_with_flagsJacob Keller, May 20, 2025
  6. Junio C HamanoMay 20, 2025
  7. Jacob KellerMay 20, 2025
  8. 3/4 pathspec: add flag to indicate operation without repositoryJacob Keller, May 20, 2025
  9. Junio C HamanoMay 20, 2025
  10. Jacob KellerMay 20, 2025
  11. Jacob KellerMay 21, 2025
  12. 4/4 diff --no-index: support limiting by pathspecJacob Keller, May 20, 2025
  13. Junio C HamanoMay 20, 2025
  14. Jacob KellerMay 20, 2025
  15. Jacob KellerMay 20, 2025

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.