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

Re: [PATCH] blame: allow --contents to work with non-HEAD commit

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 24, 2023, 04:41 UTC
Message-ID
<xmqqy1nm69se.fsf@gitster.g>
In-Reply-To
<20230324010457.275902-1-jacob.e.keller@intel.com>
Jacob Keller <jacob.e.keller@intel.com> writes:
Show 16 quoted lines
> From: Jacob Keller <jacob.keller@gmail.com>
>
> The --contents option can be used with git blame to blame the file as if
> it had the contents from the specified file. This is akin to copying the
> contents into the working tree and then running git blame. This option
> has been supported since 1cfe77333f27 ("git-blame: no rev means start
> from the working tree file.")
>
> The --contents option always blames the file as if it was based on the
> current HEAD commit. If you try to pass a revision while using
> --contents, you get the following error:
>
>   fatal: cannot use --contents with final commit object name
>
> This is because the blame process generates a fake working tree commit
> which always uses the HEAD object.
"the HEAD object as its sole parent."
> Fix fake_working_tree_commit to take the object ID to use for the
> parent instead of always using HEAD. If both a revision and --contents
> is provided, look up the object ID from the provided revision instead of
> using HEAD.
An obvious enhancement.

As the original author of 1cfe7733 (git-blame: no rev means start from the working tree file., 2007-01-30), I am not sure if the verb "fix" is fair to describe this change, though. If you update the working tree file with contents that is vastly different and totally unrelated to the version at HEAD, then with this new feature, your "blame" can start at the working tree file, and then some commit that is totally unrelated to HEAD, and down the history from it, and everything should make sense, but if you smudge your working tree files that way, it would be quite awkward to use the working tree to advance the history that leads to HEAD. That is the reason why I designed the "fake commit based on off-history contents" features to work only with HEAD. But unlike actually messing with the contents of the working tree files, feeding a temporary contents via the "--contents" option has much less chance of breaking the next commit, so I do not have any objection to this patch.

Thanks.
Previous: Jacob KellerNext: Jacob Keller
Message 2 of 3 in “blame: allow --contents to work with non-HEAD commit”
  1. blame: allow --contents to work with non-HEAD commitJacob Keller, Mar 24, 2023
  2. Junio C HamanoMar 24, 2023
  3. Jacob KellerMar 24, 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.