`git blame` Line Number Off-by-one

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



What did you do before the bug happened? (Steps to reproduce your issue)

 * Clone https://github.com/apache/tomcat
* Run `git blame --root -leftw -L 21,21 -L 23,23 51844327d8613448bb0bf9667e1a61e462e2043c^ -- modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java`

What did you expect to happen? (Expected behavior)

`git blame` shows the last commit that modified lines 21 and 23 of `modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java` starting at the parent of `51844327d8613448bb0bf9667e1a61e462e2043c`.

```
$ git blame --root -leftw -L 21,21 -L 23,23 51844327d8613448bb0bf9667e1a61e462e2043c^ -- modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java c65a429f06f4e4a025a306e377211863d9ff2a0c modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java (<fhanik@xxxxxxxxxx> 1226896977 +0000 21) import java.util.ArrayList; c65a429f06f4e4a025a306e377211863d9ff2a0c modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java (<fhanik@xxxxxxxxxx> 1226896977 +0000 23) import java.util.List;
```

What happened instead? (Actual behavior)

Line 23 is not shown in the `git blame` output. Instead, line 22 is shown.

```
$ git blame --root -leftw -L 21,21 -L 23,23 51844327d8613448bb0bf9667e1a61e462e2043c^ -- modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java c65a429f06f4e4a025a306e377211863d9ff2a0c modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java (<fhanik@xxxxxxxxxx> 1226896977 +0000 21) import java.util.ArrayList; c65a429f06f4e4a025a306e377211863d9ff2a0c modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java (<fhanik@xxxxxxxxxx> 1226896977 +0000 22) import java.util.HashMap;
```

What's different between what you expected and what actually happened?

Line 23 is not shown in the `git blame` output. Instead line 22 is shown.

Anything else you want to add:

* The issue is reproducible on git versions 2.28.0 (on Ubuntu 18.04.4 LTS), 2.24.0 (on Ubuntu 18.04.3 LTS), 2.17.0 (on Ubuntu 18.04.4 LTS), and 2.27.0.windows.1 (on Microsoft Windows 10 Enterprise 10.0.19041 Build 19041).
 * The addition of `--porcelain` does not resolve the issue.
* The issue is not specific to a particular repository. For instance, the output from `git blame -L 1466,1466 -L 1468,1468 35e69fc7cf9421ab04ffc9d52cb36d07fa12984a^ -- c/dec/decode.c` in a clone of https://github.com/google/brotli shows last commit that modified lines 1466 and 1467 (instead 1468). * The issue seems to present itself only when there is exactly one line in between two specifications of `-L`. For instance, `-L 20,20 -L 23,23` correctly blames lines 20 and 23, `-L 20,20 -L 21,21 -L 22,22 -L 23,23` correctly blames lines 20, 21, 22, and 23, `-L 23,23` correctly blames line 23, but `-L 21,21 -L 23,23` blames lines 21 and 22 (instead of 23).

[System Info]
git version:
git version 2.28.0
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 4.15.0-88-generic #88-Ubuntu SMP Tue Feb 11 20:11:34 UTC 2020 x86_64
compiler info: gnuc: 7.5
libc info: glibc: 2.27
$SHELL (typically, interactive shell): <unset>

[Enabled Hooks]





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux