Skip to content

Commit 52f4d12

Browse files
sunshinecogitster
authored andcommitted
blame: teach -L/RE/ to search from end of previous -L range
Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 815834e commit 52f4d12

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

builtin/blame.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
22802280
int cmd_is_annotate = !strcmp(argv[0], "annotate");
22812281
struct range_set ranges;
22822282
unsigned int range_i;
2283+
long anchor;
22832284

22842285
git_config(git_blame_config, NULL);
22852286
init_revisions(&revs, NULL);
@@ -2475,11 +2476,12 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
24752476
if (lno && !range_list.nr)
24762477
string_list_append(&range_list, xstrdup("1"));
24772478

2479+
anchor = 1;
24782480
range_set_init(&ranges, range_list.nr);
24792481
for (range_i = 0; range_i < range_list.nr; ++range_i) {
24802482
long bottom, top;
24812483
if (parse_range_arg(range_list.items[range_i].string,
2482-
nth_line_cb, &sb, lno, 1,
2484+
nth_line_cb, &sb, lno, anchor,
24832485
&bottom, &top, sb.path))
24842486
usage(blame_usage);
24852487
if (lno < top || ((lno || bottom) && lno < bottom))
@@ -2490,6 +2492,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
24902492
top = lno;
24912493
bottom--;
24922494
range_set_append_unsafe(&ranges, bottom, top);
2495+
anchor = top + 1;
24932496
}
24942497
sort_and_merge_range_set(&ranges);
24952498

t/annotate-tests.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,26 @@ test_expect_success 'blame -L multiple (superset/subset: unordered)' '
303303
check_count -L3,5 -L2,8 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
304304
'
305305

306+
test_expect_success 'blame -L /RE/ (relative)' '
307+
check_count -L3,3 -L/fox/ B1 1 B2 1 C 1 D 1 "A U Thor" 1
308+
'
309+
310+
test_expect_success 'blame -L /RE/ (relative: no preceding range)' '
311+
check_count -L/dog/ A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
312+
'
313+
314+
test_expect_success 'blame -L /RE/ (relative: adjacent)' '
315+
check_count -L1,1 -L/dog/,+1 A 1 E 1
316+
'
317+
318+
test_expect_success 'blame -L /RE/ (relative: not found)' '
319+
test_must_fail $PROG -L4,4 -L/dog/ file
320+
'
321+
322+
test_expect_success 'blame -L /RE/ (relative: end-of-file)' '
323+
test_must_fail $PROG -L, -L/$/ file
324+
'
325+
306326
test_expect_success 'setup -L :regex' '
307327
tr Q "\\t" >hello.c <<-\EOF &&
308328
int main(int argc, const char *argv[])

0 commit comments

Comments
 (0)