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:27 UTC
Message-ID
<92BDE017-77A1-444A-A156-7CEC73456268@gmail.com>
In-Reply-To
<20230921214021.GB302338@coredump.intra.peff.net>
Hi Peff,	
On 21 Sep 2023, at 17:40, Jeff King wrote:
Show 78 quoted lines
> On Thu, Sep 21, 2023 at 01:52:52AM -0700, Junio C Hamano wrote:
>
>> 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.
>
> I think it's unlikely for a user to write that. But if you are running a
> server full of bare repositories that does diffs, you might end up with
> a script that sticks "--attr-source=HEAD" at the beginning of every
> command.
>
> It is true that HEAD may not be related. But that is what we use if you
> are in a non-bare repository and run "git diff foo^ foo".
>
> Arguably:
>
>   git --attr-source=$to diff $from $to
>
> is a better default for this command. But something like "git log -p" is
> trickier, as you have many commits to show. You can try to use the tip
> of the traversal, but there may be multiple. Using the attributes from
> the destination of each commit is the most likely to avoid divergence
> between the attributes and the code, but it may also not be what people
> want. Using the modern attributes from the working tree often makes
> showing historical commits much nicer.
>
> So I dunno. I could see arguments in both directions, but I think in
> general people have been OK with pulling attributes from the working
> tree. And --attr-source=HEAD is the bare equivalent.
>
>> 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.
>
> I don't know that it was my example. :) But yes, if you do
> "--attr-source=$to", you're overriding even the non-bare case. That may
> be what you want for some cases, but as above, I think it's hard to
> apply consistently (or even what you'd want for the general 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.
>
> True, yeah. We can't do that here because attributes are spread across
> the tree. So all my mentions of attr.blob would really be attr.tree.
>
>> 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.
>
> Yeah, that is basically what I am proposing. It sounds from the
> discussion here that there are two interesting cases:
>
>   1. You want to use --attr-source=HEAD because you are trying to make a
>      bare repo behave like a non-bare one. You probably want the "don't
>      complain if it is missing" behavior.
Yep, this is the primary use case for us.
Show 23 quoted lines
>
>   2. You are trying to use the attributes from one side of the diff to
>      override the worktree ones (because the two trees are unrelated).
>      In which case it does not really matter if --attr-source complains,
>      because the diff will likewise complain if the tree cannot be
>      resolved.
>
> Just trying to play devil's advocate, though, I guess you could run a
> non-diff operation like say:
>
>   git --attr-source=my-branch check-attr foo
>
> and then you probably _do_ want to know if that source was ignored or
> typo'd.
>
>> 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.
>
> I think folks mentioned mailmap.blob in the original discussion for
> --attr-source. I don't remember why the patch went with --attr-source
> there. Maybe John can speak to that.

Yeah I was looking for this, and I think I found it in [1], which was part of a separate patch having to do with gitattributes. If someone did mention it in the patch for --attr-source, then I can't remember why we decided to go with the comand line flag rather than the config.

1. https://lore.kernel.org/git/ZBMn5T6zfKK+PYUe@coredump.intra.peff.net/
>
> -Peff
Previous: Jeff KingNext: John Cai
Message 6 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.