Skip to content

Commit 8592f15

Browse files
gitsterdscho
authored andcommitted
Merge branch 'sg/line-log-boundary-fixes'
A corner case bug in "git log -L..." has been corrected. * sg/line-log-boundary-fixes: line-log: show all line ranges touched by the same diff range line-log: fix assertion error
2 parents fb583dc + e310699 commit 8592f15

File tree

8 files changed

+218
-3
lines changed

8 files changed

+218
-3
lines changed

line-log.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static void range_set_difference(struct range_set *out,
201201
* b: ------|
202202
*/
203203
j++;
204-
if (j >= b->nr || end < b->ranges[j].start) {
204+
if (j >= b->nr || end <= b->ranges[j].start) {
205205
/*
206206
* b exhausted, or
207207
* a: ----|
@@ -408,7 +408,7 @@ static void diff_ranges_filter_touched(struct diff_ranges *out,
408408
assert(out->target.nr == 0);
409409

410410
for (i = 0; i < diff->target.nr; i++) {
411-
while (diff->target.ranges[i].start > rs->ranges[j].end) {
411+
while (diff->target.ranges[i].start >= rs->ranges[j].end) {
412412
j++;
413413
if (j == rs->nr)
414414
return;
@@ -939,9 +939,18 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang
939939
long t_cur = t_start;
940940
unsigned int j_last;
941941

942+
/*
943+
* If a diff range touches multiple line ranges, then all
944+
* those line ranges should be shown, so take a step back if
945+
* the current line range is still in the previous diff range
946+
* (even if only partially).
947+
*/
948+
if (j > 0 && diff->target.ranges[j-1].end > t_start)
949+
j--;
950+
942951
while (j < diff->target.nr && diff->target.ranges[j].end < t_start)
943952
j++;
944-
if (j == diff->target.nr || diff->target.ranges[j].start > t_end)
953+
if (j == diff->target.nr || diff->target.ranges[j].start >= t_end)
945954
continue;
946955

947956
/* Scan ahead to determine the last diff that falls in this range */

t/t4211-line-log.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ canned_test "-L :main:a.c -L 4,18:a.c simple" multiple-overlapping
7878
canned_test "-L 4:a.c -L 8,12:a.c simple" multiple-superset
7979
canned_test "-L 8,12:a.c -L 4:a.c simple" multiple-superset
8080

81+
canned_test "-L 10,16:b.c -L 18,26:b.c main" no-assertion-error
82+
8183
test_bad_opts "-L" "switch.*requires a value"
8284
test_bad_opts "-L b.c" "argument not .start,end:file"
8385
test_bad_opts "-L 1:" "argument not .start,end:file"

t/t4211/sha1/expect.multiple

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,9 @@ diff --git a/a.c b/a.c
102102
+ s++;
103103
+ }
104104
+}
105+
@@ -0,0 +16,5 @@
106+
+int main ()
107+
+{
108+
+ printf("%d\n", f(15));
109+
+ return 0;
110+
+}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
commit 0d8dcfc6b968e06a27d5215bad1fdde3de9d6235
2+
Author: Thomas Rast <[email protected]>
3+
Date: Thu Feb 28 10:50:24 2013 +0100
4+
5+
move within the file
6+
7+
diff --git a/b.c b/b.c
8+
--- a/b.c
9+
+++ b/b.c
10+
@@ -25,0 +18,9 @@
11+
+long f(long x)
12+
+{
13+
+ int s = 0;
14+
+ while (x) {
15+
+ x /= 2;
16+
+ s++;
17+
+ }
18+
+ return s;
19+
+}
20+
21+
commit 4659538844daa2849b1a9e7d6fadb96fcd26fc83
22+
Author: Thomas Rast <[email protected]>
23+
Date: Thu Feb 28 10:48:43 2013 +0100
24+
25+
change back to complete line
26+
27+
diff --git a/a.c b/a.c
28+
--- a/a.c
29+
+++ b/a.c
30+
@@ -18,5 +18,7 @@
31+
int main ()
32+
{
33+
printf("%ld\n", f(15));
34+
return 0;
35+
-}
36+
\ No newline at end of file
37+
+}
38+
+
39+
+/* incomplete lines are bad! */
40+
41+
commit 100b61a6f2f720f812620a9d10afb3a960ccb73c
42+
Author: Thomas Rast <[email protected]>
43+
Date: Thu Feb 28 10:48:10 2013 +0100
44+
45+
change to an incomplete line at end
46+
47+
diff --git a/a.c b/a.c
48+
--- a/a.c
49+
+++ b/a.c
50+
@@ -18,5 +18,5 @@
51+
int main ()
52+
{
53+
printf("%ld\n", f(15));
54+
return 0;
55+
-}
56+
+}
57+
\ No newline at end of file
58+
59+
commit a6eb82647d5d67f893da442f8f9375fd89a3b1e2
60+
Author: Thomas Rast <[email protected]>
61+
Date: Thu Feb 28 10:45:16 2013 +0100
62+
63+
touch both functions
64+
65+
diff --git a/a.c b/a.c
66+
--- a/a.c
67+
+++ b/a.c
68+
@@ -17,5 +17,5 @@
69+
int main ()
70+
{
71+
- printf("%d\n", f(15));
72+
+ printf("%ld\n", f(15));
73+
return 0;
74+
}
75+
76+
commit de4c48ae814792c02a49c4c3c0c757ae69c55f6a
77+
Author: Thomas Rast <[email protected]>
78+
Date: Thu Feb 28 10:44:48 2013 +0100
79+
80+
initial
81+
82+
diff --git a/a.c b/a.c
83+
--- /dev/null
84+
+++ b/a.c
85+
@@ -0,0 +16,5 @@
86+
+int main ()
87+
+{
88+
+ printf("%d\n", f(15));
89+
+ return 0;
90+
+}

t/t4211/sha1/expect.two-ranges

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,9 @@ diff --git a/a.c b/a.c
100100
+ s++;
101101
+ }
102102
+}
103+
@@ -0,0 +16,5 @@
104+
+int main ()
105+
+{
106+
+ printf("%d\n", f(15));
107+
+ return 0;
108+
+}

t/t4211/sha256/expect.multiple

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,9 @@ diff --git a/a.c b/a.c
102102
+ s++;
103103
+ }
104104
+}
105+
@@ -0,0 +16,5 @@
106+
+int main ()
107+
+{
108+
+ printf("%d\n", f(15));
109+
+ return 0;
110+
+}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
commit eb871b8aa9aff323e484723039c9a92ab0266e060bc0ef2afb08fadda25c5ace
2+
Author: Thomas Rast <[email protected]>
3+
Date: Thu Feb 28 10:50:24 2013 +0100
4+
5+
move within the file
6+
7+
diff --git a/b.c b/b.c
8+
--- a/b.c
9+
+++ b/b.c
10+
@@ -25,0 +18,9 @@
11+
+long f(long x)
12+
+{
13+
+ int s = 0;
14+
+ while (x) {
15+
+ x /= 2;
16+
+ s++;
17+
+ }
18+
+ return s;
19+
+}
20+
21+
commit 5526ed05c2476b56af8b7be499e8f78bd50f490740733a9ca7e1f55878fa90a9
22+
Author: Thomas Rast <[email protected]>
23+
Date: Thu Feb 28 10:48:43 2013 +0100
24+
25+
change back to complete line
26+
27+
diff --git a/a.c b/a.c
28+
--- a/a.c
29+
+++ b/a.c
30+
@@ -18,5 +18,7 @@
31+
int main ()
32+
{
33+
printf("%ld\n", f(15));
34+
return 0;
35+
-}
36+
\ No newline at end of file
37+
+}
38+
+
39+
+/* incomplete lines are bad! */
40+
41+
commit 29f32ac3141c48b22803e5c4127b719917b67d0f8ca8c5248bebfa2a19f7da10
42+
Author: Thomas Rast <[email protected]>
43+
Date: Thu Feb 28 10:48:10 2013 +0100
44+
45+
change to an incomplete line at end
46+
47+
diff --git a/a.c b/a.c
48+
--- a/a.c
49+
+++ b/a.c
50+
@@ -18,5 +18,5 @@
51+
int main ()
52+
{
53+
printf("%ld\n", f(15));
54+
return 0;
55+
-}
56+
+}
57+
\ No newline at end of file
58+
59+
commit ccf97b9878189c40a981da50b15713bb80a35755326320ec80900caf22ced46f
60+
Author: Thomas Rast <[email protected]>
61+
Date: Thu Feb 28 10:45:16 2013 +0100
62+
63+
touch both functions
64+
65+
diff --git a/a.c b/a.c
66+
--- a/a.c
67+
+++ b/a.c
68+
@@ -17,5 +17,5 @@
69+
int main ()
70+
{
71+
- printf("%d\n", f(15));
72+
+ printf("%ld\n", f(15));
73+
return 0;
74+
}
75+
76+
commit 1dd7e9b2b1699324b53b341e728653b913bc192a14dfea168c5b51f2b3d03592
77+
Author: Thomas Rast <[email protected]>
78+
Date: Thu Feb 28 10:44:48 2013 +0100
79+
80+
initial
81+
82+
diff --git a/a.c b/a.c
83+
--- /dev/null
84+
+++ b/a.c
85+
@@ -0,0 +16,5 @@
86+
+int main ()
87+
+{
88+
+ printf("%d\n", f(15));
89+
+ return 0;
90+
+}

t/t4211/sha256/expect.two-ranges

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,9 @@ diff --git a/a.c b/a.c
100100
+ s++;
101101
+ }
102102
+}
103+
@@ -0,0 +16,5 @@
104+
+int main ()
105+
+{
106+
+ printf("%d\n", f(15));
107+
+ return 0;
108+
+}

0 commit comments

Comments
 (0)