Skip to content

Commit efc5e5e

Browse files
committed
Merge branch 'es/line-log-further-fixes' into tr/line-log
* es/line-log-further-fixes: line-log: fix "log -LN" crash when N is last line of file range-set: satisfy non-empty ranges invariant t4211: demonstrate crash when first -L encountered is empty range t4211: demonstrate empty -L range crash range-set: fix sort_and_merge_range_set() corner case bug range_set: fix coalescing bug when range is a subset of another t4211: fix broken test when one -L range is subset of another
2 parents 4999266 + df6308e commit efc5e5e

File tree

3 files changed

+153
-7
lines changed

3 files changed

+153
-7
lines changed

line-log.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,16 @@ static void range_set_check_invariants(struct range_set *rs)
110110
static void sort_and_merge_range_set(struct range_set *rs)
111111
{
112112
int i;
113-
int o = 1; /* output cursor */
113+
int o = 0; /* output cursor */
114114

115115
qsort(rs->ranges, rs->nr, sizeof(struct range), range_cmp);
116116

117-
for (i = 1; i < rs->nr; i++) {
118-
if (rs->ranges[i].start <= rs->ranges[o-1].end) {
119-
rs->ranges[o-1].end = rs->ranges[i].end;
117+
for (i = 0; i < rs->nr; i++) {
118+
if (rs->ranges[i].start == rs->ranges[i].end)
119+
continue;
120+
if (o > 0 && rs->ranges[i].start <= rs->ranges[o-1].end) {
121+
if (rs->ranges[o-1].end < rs->ranges[i].end)
122+
rs->ranges[o-1].end = rs->ranges[i].end;
120123
} else {
121124
rs->ranges[o].start = rs->ranges[i].start;
122125
rs->ranges[o].end = rs->ranges[i].end;
@@ -296,6 +299,7 @@ static void line_log_data_insert(struct line_log_data **list,
296299
p = xcalloc(1, sizeof(struct line_log_data));
297300
p->path = path;
298301
range_set_append(&p->ranges, begin, end);
302+
sort_and_merge_range_set(&p->ranges);
299303
if (ip) {
300304
p->next = ip->next;
301305
ip->next = p;

t/t4211-line-log.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,18 @@ test_bad_opts "-L 1,1000:b.c" "has only.*lines"
6464
test_bad_opts "-L :b.c" "argument.*not of the form"
6565
test_bad_opts "-L :foo:b.c" "no match"
6666

67+
# There is a separate bug when an empty -L range is the first -L encountered,
68+
# thus to demonstrate this particular bug, the empty -L range must follow a
69+
# non-empty -L range.
70+
test_expect_success '-L {empty-range} (any -L)' '
71+
n=$(expr $(cat b.c | wc -l) + 1) &&
72+
n=$(expr $(wc -l <b.c) + 1) &&
73+
git log -L1,1:b.c -L$n:b.c
74+
'
75+
76+
test_expect_success '-L {empty-range} (first -L)' '
77+
n=$(expr $(wc -l <b.c) + 1) &&
78+
git log -L$n:b.c
79+
'
80+
6781
test_done

t/t4211/expect.multiple-superset

Lines changed: 131 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,100 @@
1+
commit 4659538844daa2849b1a9e7d6fadb96fcd26fc83
2+
Author: Thomas Rast <[email protected]>
3+
Date: Thu Feb 28 10:48:43 2013 +0100
4+
5+
change back to complete line
6+
7+
diff --git a/a.c b/a.c
8+
--- a/a.c
9+
+++ b/a.c
10+
@@ -4,19 +4,21 @@
11+
long f(long x)
12+
{
13+
int s = 0;
14+
while (x) {
15+
x >>= 1;
16+
s++;
17+
}
18+
return s;
19+
}
20+
21+
/*
22+
* This is only an example!
23+
*/
24+
25+
int main ()
26+
{
27+
printf("%ld\n", f(15));
28+
return 0;
29+
-}
30+
\ No newline at end of file
31+
+}
32+
+
33+
+/* incomplete lines are bad! */
34+
35+
commit 100b61a6f2f720f812620a9d10afb3a960ccb73c
36+
Author: Thomas Rast <[email protected]>
37+
Date: Thu Feb 28 10:48:10 2013 +0100
38+
39+
change to an incomplete line at end
40+
41+
diff --git a/a.c b/a.c
42+
--- a/a.c
43+
+++ b/a.c
44+
@@ -4,19 +4,19 @@
45+
long f(long x)
46+
{
47+
int s = 0;
48+
while (x) {
49+
x >>= 1;
50+
s++;
51+
}
52+
return s;
53+
}
54+
55+
/*
56+
* This is only an example!
57+
*/
58+
59+
int main ()
60+
{
61+
printf("%ld\n", f(15));
62+
return 0;
63+
-}
64+
+}
65+
\ No newline at end of file
66+
67+
commit 39b6eb2d5b706d3322184a169f666f25ed3fbd00
68+
Author: Thomas Rast <[email protected]>
69+
Date: Thu Feb 28 10:45:41 2013 +0100
70+
71+
touch comment
72+
73+
diff --git a/a.c b/a.c
74+
--- a/a.c
75+
+++ b/a.c
76+
@@ -3,19 +3,19 @@
77+
long f(long x)
78+
{
79+
int s = 0;
80+
while (x) {
81+
x >>= 1;
82+
s++;
83+
}
84+
return s;
85+
}
86+
87+
/*
88+
- * A comment.
89+
+ * This is only an example!
90+
*/
91+
92+
int main ()
93+
{
94+
printf("%ld\n", f(15));
95+
return 0;
96+
}
97+
198
commit a6eb82647d5d67f893da442f8f9375fd89a3b1e2
299
Author: Thomas Rast <[email protected]>
3100
Date: Thu Feb 28 10:45:16 2013 +0100
@@ -7,7 +104,7 @@ Date: Thu Feb 28 10:45:16 2013 +0100
7104
diff --git a/a.c b/a.c
8105
--- a/a.c
9106
+++ b/a.c
10-
@@ -3,9 +3,9 @@
107+
@@ -3,19 +3,19 @@
11108
-int f(int x)
12109
+long f(long x)
13110
{
@@ -18,6 +115,17 @@ diff --git a/a.c b/a.c
18115
}
19116
return s;
20117
}
118+
119+
/*
120+
* A comment.
121+
*/
122+
123+
int main ()
124+
{
125+
- printf("%d\n", f(15));
126+
+ printf("%ld\n", f(15));
127+
return 0;
128+
}
21129

22130
commit f04fb20f2c77850996cba739709acc6faecc58f7
23131
Author: Thomas Rast <[email protected]>
@@ -28,7 +136,7 @@ Date: Thu Feb 28 10:44:55 2013 +0100
28136
diff --git a/a.c b/a.c
29137
--- a/a.c
30138
+++ b/a.c
31-
@@ -3,8 +3,9 @@
139+
@@ -3,18 +3,19 @@
32140
int f(int x)
33141
{
34142
int s = 0;
@@ -38,6 +146,16 @@ diff --git a/a.c b/a.c
38146
}
39147
+ return s;
40148
}
149+
150+
/*
151+
* A comment.
152+
*/
153+
154+
int main ()
155+
{
156+
printf("%d\n", f(15));
157+
return 0;
158+
}
41159

42160
commit de4c48ae814792c02a49c4c3c0c757ae69c55f6a
43161
Author: Thomas Rast <[email protected]>
@@ -48,7 +166,7 @@ Date: Thu Feb 28 10:44:48 2013 +0100
48166
diff --git a/a.c b/a.c
49167
--- /dev/null
50168
+++ b/a.c
51-
@@ -0,0 +3,8 @@
169+
@@ -0,0 +3,18 @@
52170
+int f(int x)
53171
+{
54172
+ int s = 0;
@@ -57,3 +175,13 @@ diff --git a/a.c b/a.c
57175
+ s++;
58176
+ }
59177
+}
178+
+
179+
+/*
180+
+ * A comment.
181+
+ */
182+
+
183+
+int main ()
184+
+{
185+
+ printf("%d\n", f(15));
186+
+ return 0;
187+
+}

0 commit comments

Comments
 (0)