line-range: teach -L^:RE to search from start of file
The -L:RE option of blame/log searches from the end of the previous -L range, if any. Add new notation -L^:RE to override this behavior and search from start of file. 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
215e76c7ff8be46b8206c45aed3b6ec29069d4fc
4 files changed
+26
-2
Documentation/line-range-format.txt
+1
@@ -26,3 +26,4 @@ If ``:<regex>'' is given in place of <start> and <end>, it denotes the range
26
from the first funcname line that matches <regex>, up to the next
27
funcname line. ``:<regex>'' searches from the end of the previous `-L` range,
28
if any, otherwise from the start of file.
29
+``^:<regex>'' searches from the start of file.
line-range.c
+7
-2
@@ -173,6 +173,11 @@ static const char *parse_range_funcname(const char *arg, nth_line_fn_t nth_line_
173
int reg_error;
174
regex_t regexp;
175
176
+ if (*arg == '^') {
177
+ anchor = 1;
178
+ arg++;
179
+ }
180
+
181
assert(*arg == ':');
182
term = arg+1;
183
while (*term && *term != ':') {
@@ -245,7 +250,7 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
250
if (anchor > lines)
251
anchor = lines + 1;
252
248
- if (*arg == ':') {
253
+ if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':')) {
254
arg = parse_range_funcname(arg, nth_line_cb, cb_data, lines, anchor, begin, end, path);
255
if (!arg || *arg)
256
return -1;
@@ -270,7 +275,7 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
275
276
const char *skip_range_arg(const char *arg)
277
{
273
- if (*arg == ':')
278
+ if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':'))
279
return parse_range_funcname(arg, NULL, NULL, 0, 0, NULL, NULL, NULL);
280
281
arg = parse_loc(arg, NULL, NULL, 0, -1, NULL);
t/annotate-tests.sh
+17
@@ -398,6 +398,23 @@ test_expect_success 'blame -L :RE (relative: end-of-file)' '
398
test_must_fail $PROG -L, -L:main hello.c
399
'
400
401
+test_expect_success 'blame -L ^:RE (absolute)' '
402
+ check_count -f hello.c -L3,3 -L^:ma.. F 4 G 1
403
+'
404
+
405
+test_expect_success 'blame -L ^:RE (absolute: no preceding range)' '
406
+ check_count -f hello.c -L^:ma.. F 4 G 1
407
+'
408
+
409
+test_expect_success 'blame -L ^:RE (absolute: not found)' '
410
+ test_must_fail $PROG -L4,4 -L^:tambourine hello.c
411
+'
412
+
413
+test_expect_success 'blame -L ^:RE (absolute: end-of-file)' '
414
+ n=$(printf "%d" $(wc -l <hello.c)) &&
415
+ check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1
416
+'
417
+
418
test_expect_success 'setup incremental' '
419
(
420
GIT_AUTHOR_NAME=I &&
t/t4211-line-log.sh
+1
@@ -48,6 +48,7 @@ canned_test "-M -L '/long f/,/^}/:b.c' move-support" move-support-f
48
canned_test "-M -L ':f:b.c' parallel-change" parallel-change-f-to-main
49
50
canned_test "-L 4,12:a.c -L :main:a.c simple" multiple
51
+canned_test "-L 4,18:a.c -L ^:main:a.c simple" multiple-overlapping
52
canned_test "-L :main:a.c -L 4,18:a.c simple" multiple-overlapping
53
canned_test "-L 4:a.c -L 8,12:a.c simple" multiple-superset
54
canned_test "-L 8,12:a.c -L 4:a.c simple" multiple-superset