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

Re: git blame --reverse doesn't find line in HEAD

From
Nick Snyder <nick@sourcegraph.com>
Date
Dec 6, 2017, 15:40 UTC
Message-ID
<CA+SQVf24rcQ1iKAQBW0Ky7Qm8zuF3Esw8qMKvG+KCbCA-mCcfA@mail.gmail.com>
In-Reply-To
<CA+SQVf1W6BhNyB6bGxh7WfCwb6+E3pNjHLeS4xDYPJ6BLT8cng@mail.gmail.com>
This can be reproduced on Linux and Mac. This behavior seems to be a bug.
On Wed, Nov 29, 2017 at 12:06 AM, Nick Snyder <nick@sourcegraph.com> wrote:
Show 78 quoted lines
> I have a repo that reproduces a behavior with `git blame --reverse`
> that surprises me. https://github.com/nicksnyder/git-blame-bug
>
> The readme explains the observed behavior and what I expected to
> happen. I will inline the readme at the bottom of this message for
> convenience.
>
> Am I misunderstanding --reverse or is this a bug?
>
> Thanks!
> Nick
>
> $ git --version
> git version 2.15.0
>
> Blame of L465 in Tree.tsx at HEAD (ca0fb5) points to L463 at 199ee7
>
> $ git blame -p -L465,465 Tree.tsx
> 199ee75d1240ae72cd965f62aceeb301ab64e1bd 463 465 1
> filename Tree.tsx
>             public shouldComponentUpdate(nextProps: TileProps): boolean {
>
> EXPECTED: Reverse blame of L463 at 199ee7 points to L465 at the
> lastest commit in the repo (at least ca0fb5).
> ACTUAL: Reverse blame of L463 at 199ee7 points to L463 at 199ee7.
>
> $ git blame -p -L463,463 --reverse 199ee7.. Tree.tsx
> 199ee75d1240ae72cd965f62aceeb301ab64e1bd 463 463 1
> boundary
> previous ca0fb5a2d61cb16909bcb06f49dd5448a26f32b1 Tree.tsx
> filename Tree.tsx
>             public shouldComponentUpdate(nextProps: TileProps): boolean {
>
> The line in question is in the diff (git diff 199ee7..ca0fb5), but
> that particular line is neither added nor deleted, so I don't know why
> blame would think it is deleted.
>
> Relevant hunk in diff:
>
> @@ -452,28 +462,17 @@ export class LayerTile extends
> React.Component<TileProps, {}> {
>          }
>      }
>
> -    public validTokenRange(props: TileProps): boolean {
> -        if (props.selectedPath === '') {
> -            return true
> -        }
> -        const token = props.selectedPath.split('/').pop()!
> -        return token >= this.first && token <= this.last
> -    }
> -
>      public shouldComponentUpdate(nextProps: TileProps): boolean {
> -        const lastValid = this.validTokenRange(this.props)
> -        const nextValid = this.validTokenRange(nextProps)
> -        if (!lastValid && !nextValid) {
> -            // short circuit
> -            return false
> +        if (isEqualOrAncestor(this.props.selectedDir,
> this.props.currSubpath)) {
> +            return true
>          }
> -        if (isEqualOrAncestor(this.props.selectedDir,
> this.props.currSubpath) && lastValid) {
> +        if (nextProps.selectedDir === nextProps.currSubpath) {
>              return true
>          }
> -        if (nextProps.selectedDir === nextProps.currSubpath &&
> this.validTokenRange(nextProps)) {
> +        if (getParentDir(nextProps.selectedDir) === nextProps.currSubpath) {
>              return true
>          }
> -        if (getParentDir(nextProps.selectedDir) ===
> nextProps.currSubpath && this.validTokenRange(nextProps)) {
> +        if (!isEqual(nextProps.pathSplits, this.props.pathSplits)) {
>              return true
>          }
>          return false
Previous: Nick SnyderNext: Junio C Hamano
Message 2 of 5 in “git blame --reverse doesn't find line in HEAD”
  1. Nick SnyderNov 29, 2017
  2. Nick SnyderDec 6, 2017
  3. Junio C HamanoDec 6, 2017
  4. Nick SnyderDec 6, 2017
  5. Nick SnyderDec 7, 2017

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.