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

Re: [PATCH] attr: attr.allowInvalidSource config to allow invalid revision

From
John Cai <johncai86@gmail.com>
Date
Sep 26, 2023, 18:30 UTC
Message-ID
<000AEFB0-0694-415D-94CB-9BB437E1A9FA@gmail.com>
In-Reply-To
<xmqq1qer7vrv.fsf@gitster.g>
Hi Junio,
On 21 Sep 2023, at 4:52, Junio C Hamano wrote:
Show 63 quoted lines
> Jeff King <peff@peff.net> writes:
>
>> In an empty repository, "git log" will die anyway. So I think the more
>> interesting case is "I have a repository with stuff in it, but HEAD
>> points to an unborn branch". So:
>>
>>   git --attr-source=HEAD diff foo^ foo
>
> This still looks like a made-up example.  Who in the right mind
> would specify HEAD when both of the revs involved in the operation
> are from branch 'foo'?  The history of HEAD may not have anything
> common with the operand of the operation 'foo' (or its parent), or
> worse, it may not even exist.
>
> But your "in this repository we never trust attributes from working
> tree, take it instead from this file or from this blob" example does
> make a lot more sense as a use case.
>
>> And there you really are saying "if there are attributes in HEAD, use
>> them; otherwise, don't worry about it". This is exactly what we do with
>> mailmap.blob: in a bare repository it is set to HEAD by default, but if
>> HEAD does not resolve, we just ignore it (just like a HEAD that does not
>> contain a .mailmap file). And those match the non-bare cases, where we'd
>> read those files from the working tree instead.
>
> "HEAD" -> "HEAD:.mailmap" if I recall correctly.
>
> And if HEAD does not resolve, we pretend as if HEAD is an empty
> tree-ish (hence HEAD:.mailmap is missing).  It becomes very tempting
> to do the same for the attribute sources and treat unborn HEAD as if
> it specifies an empty tree-ish, without any configuration or an
> extra option.
>
> Such a change would be an end-user observable behaviour change, but
> nobody sane would be running "git --attr-source=HEAD diff HEAD^ HEAD"
> to check and detect an unborn HEAD for its error exit code, so I do
> not think it is a horribly wrong thing to do.
>
> But again, as you said, --attr-source=<tree-ish> does not sound like
> a good fit for bare-repository hosted environment and a tentative
> hack waiting for a proper attr.blob support, or something like that,
> to appear.
>
>> But what is weird about this patch is that we are using a config option
>> to change how a command-line option is interpreted. If the idea is that
>> some invocations care about the validity of the source and some do not,
>> then the config option is much too blunt. It is set once long ago, but
>> it can't distinguish between times you care about invalid sources and
>> times you don't.
>>
>> It would make much more sense to me to have another command-line option,
>> like:
>>
>>   git --attr-source=HEAD --allow-invalid-attr-source
>
> Yeah, if we were to make it configurable without changing the
> default behaviour, I agree that would be more correct approach.  A
> configuration does not sound like a good fit.
>
>> ... And I really think attr.blob is a better match for what GitLab
>> is trying to do here, because it is set once and applies to all
>> commands, rather than having to teach every invocation to pass it
>> (though I guess maybe they use it as an environment variable).

Between adding an --allow-invalid-attr-source, and adding attr.blob and attr.allowInvalidSource I think I like adding the attr.blob config more.

>
> True, too.
>
> Thanks.

thanks John

Previous: John CaiNext: John Cai
Message 7 of 34 in “attr: attr.allowInvalidSource config to allow invalid revision”
  1. attr: attr.allowInvalidSource config to allow invalid revisionJohn Cai via GitGitGadget, Sep 20, 2023
  2. Junio C HamanoSep 20, 2023
  3. Jeff KingSep 21, 2023
  4. Junio C HamanoSep 21, 2023
  5. Jeff KingSep 21, 2023
  6. John CaiSep 26, 2023
  7. John CaiSep 26, 2023
  8. John CaiSep 26, 2023
  9. 0/2 attr: add attr.tree and attr.allowInvalidSource configsJohn Cai via GitGitGadget, Oct 4, 2023
  10. 1/2 attr: add attr.tree for setting the treeish to read attributes fromJohn Cai via GitGitGadget, Oct 4, 2023
  11. Junio C HamanoOct 4, 2023
  12. Jeff KingOct 5, 2023
  13. John CaiOct 5, 2023
  14. Junio C HamanoOct 4, 2023
  15. Jonathan TanOct 6, 2023
  16. 2/2 attr: add attr.allowInvalidSource config to allow invalid revisionJohn Cai via GitGitGadget, Oct 4, 2023
  17. 0/2 attr: add attr.tree configJohn Cai via GitGitGadget, Oct 10, 2023
  18. 1/2 attr: read attributes from HEAD when bare repoJohn Cai via GitGitGadget, Oct 10, 2023
  19. Eric SunshineOct 10, 2023
  20. 2/2 attr: add attr.tree for setting the treeish to read attributes fromJohn Cai via GitGitGadget, Oct 10, 2023
  21. Junio C HamanoOct 10, 2023
  22. John CaiOct 11, 2023
  23. 0/2 attr: add attr.tree configJohn Cai via GitGitGadget, Oct 11, 2023
  24. 1/2 attr: read attributes from HEAD when bare repoJohn Cai via GitGitGadget, Oct 11, 2023
  25. 2/2 attr: add attr.tree for setting the treeish to read attributes fromJohn Cai via GitGitGadget, Oct 11, 2023
  26. Junio C HamanoOct 11, 2023
  27. John CaiOct 13, 2023
  28. 0/2 attr: add attr.tree configJohn Cai via GitGitGadget, Oct 13, 2023
  29. 1/2 attr: read attributes from HEAD when bare repoJohn Cai via GitGitGadget, Oct 13, 2023
  30. 2/2 attr: add attr.tree for setting the treeish to read attributes fromJohn Cai via GitGitGadget, Oct 13, 2023
  31. Junio C HamanoOct 13, 2023
  32. Junio C HamanoOct 13, 2023
  33. Junio C HamanoOct 13, 2023
  34. John CaiOct 19, 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.