]> git.ipfire.org Git - thirdparty/git.git/commitdiff
line-range: teach -L^:RE to search from start of file
authorEric Sunshine <sunshine@sunshineco.com>
Tue, 6 Aug 2013 13:59:47 +0000 (09:59 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 6 Aug 2013 21:48:02 +0000 (14:48 -0700)
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>
Documentation/line-range-format.txt
line-range.c
t/annotate-tests.sh
t/t4211-line-log.sh

index 469d80b242cfd43d9bc191ae2bfd72a2a2cabf80..d7f26039cac500ff922dd3fb9470912b03718335 100644 (file)
@@ -26,3 +26,4 @@ If ``:<regex>'' is given in place of <start> and <end>, it denotes the range
 from the first funcname line that matches <regex>, up to the next
 funcname line. ``:<regex>'' searches from the end of the previous `-L` range,
 if any, otherwise from the start of file.
+``^:<regex>'' searches from the start of file.
index 4bae4bff212817a443f1cc6c0b124fb1bcd263b1..ede0c6c98f7b6fc1f4e85a3956f7824a81dff743 100644 (file)
@@ -173,6 +173,11 @@ static const char *parse_range_funcname(const char *arg, nth_line_fn_t nth_line_
        int reg_error;
        regex_t regexp;
 
+       if (*arg == '^') {
+               anchor = 1;
+               arg++;
+       }
+
        assert(*arg == ':');
        term = arg+1;
        while (*term && *term != ':') {
@@ -245,7 +250,7 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
        if (anchor > lines)
                anchor = lines + 1;
 
-       if (*arg == ':') {
+       if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':')) {
                arg = parse_range_funcname(arg, nth_line_cb, cb_data, lines, anchor, begin, end, path);
                if (!arg || *arg)
                        return -1;
@@ -270,7 +275,7 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
 
 const char *skip_range_arg(const char *arg)
 {
-       if (*arg == ':')
+       if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':'))
                return parse_range_funcname(arg, NULL, NULL, 0, 0, NULL, NULL, NULL);
 
        arg = parse_loc(arg, NULL, NULL, 0, -1, NULL);
index 4f7d6baef5aff829e35495a586009feee8708d90..dabe89d91a2198f8c8f0c3d42eb5d2cc480b5a14 100644 (file)
@@ -398,6 +398,23 @@ test_expect_success 'blame -L :RE (relative: end-of-file)' '
        test_must_fail $PROG -L, -L:main hello.c
 '
 
+test_expect_success 'blame -L ^:RE (absolute)' '
+       check_count -f hello.c -L3,3 -L^:ma.. F 4 G 1
+'
+
+test_expect_success 'blame -L ^:RE (absolute: no preceding range)' '
+       check_count -f hello.c -L^:ma.. F 4 G 1
+'
+
+test_expect_success 'blame -L ^:RE (absolute: not found)' '
+       test_must_fail $PROG -L4,4 -L^:tambourine hello.c
+'
+
+test_expect_success 'blame -L ^:RE (absolute: end-of-file)' '
+       n=$(printf "%d" $(wc -l <hello.c)) &&
+       check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1
+'
+
 test_expect_success 'setup incremental' '
        (
        GIT_AUTHOR_NAME=I &&
index 8ba2d511e598a148d781c21ee358a266b0f5b16b..7369d3c517294feda894eba85f7b02ac9a57ccae 100755 (executable)
@@ -48,6 +48,7 @@ canned_test "-M -L '/long f/,/^}/:b.c' move-support" move-support-f
 canned_test "-M -L ':f:b.c' parallel-change" parallel-change-f-to-main
 
 canned_test "-L 4,12:a.c -L :main:a.c simple" multiple
+canned_test "-L 4,18:a.c -L ^:main:a.c simple" multiple-overlapping
 canned_test "-L :main:a.c -L 4,18:a.c simple" multiple-overlapping
 canned_test "-L 4:a.c -L 8,12:a.c simple" multiple-superset
 canned_test "-L 8,12:a.c -L 4:a.c simple" multiple-superset