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

From: Junio C Hamano <[email-masked]>
Date: Thu, 23 Mar 2023 21:41:21 -0700

Jacob Keller <[email-masked]> writes:

> From: Jacob Keller <[email-masked]>
>
> 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.