blame: teach -L/RE/ to search from end of previous -L range

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Aug 6, 2013 at 09:59 UTC 52f4d1264854485bfd50afeeed1933a3f9e05c96
2 files changed +24 -1
builtin/blame.c
+4 -1
@@ -2280,6 +2280,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2280 int cmd_is_annotate = !strcmp(argv[0], "annotate");
2281 struct range_set ranges;
2282 unsigned int range_i;
2283 + long anchor;
2284
2285 git_config(git_blame_config, NULL);
2286 init_revisions(&revs, NULL);
@@ -2475,11 +2476,12 @@ parse_done:
2476 if (lno && !range_list.nr)
2477 string_list_append(&range_list, xstrdup("1"));
2478
2479 + anchor = 1;
2480 range_set_init(&ranges, range_list.nr);
2481 for (range_i = 0; range_i < range_list.nr; ++range_i) {
2482 long bottom, top;
2483 if (parse_range_arg(range_list.items[range_i].string,
2482 - nth_line_cb, &sb, lno, 1,
2484 + nth_line_cb, &sb, lno, anchor,
2485 &bottom, &top, sb.path))
2486 usage(blame_usage);
2487 if (lno < top || ((lno || bottom) && lno < bottom))
@@ -2490,6 +2492,7 @@ parse_done:
2492 top = lno;
2493 bottom--;
2494 range_set_append_unsafe(&ranges, bottom, top);
2495 + anchor = top + 1;
2496 }
2497 sort_and_merge_range_set(&ranges);
2498
t/annotate-tests.sh
+20
@@ -303,6 +303,26 @@ test_expect_success 'blame -L multiple (superset/subset: unordered)' '
303 check_count -L3,5 -L2,8 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
304 '
305
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 +
326 test_expect_success 'setup -L :regex' '
327 tr Q "\\t" >hello.c <<-\EOF &&
328 int main(int argc, const char *argv[])