From 215e76c7ff8be46b8206c45aed3b6ec29069d4fc Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Tue, 6 Aug 2013 09:59:47 -0400 Subject: [PATCH] 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 Signed-off-by: Junio C Hamano --- Documentation/line-range-format.txt | 1 + line-range.c | 9 +++++++-- t/annotate-tests.sh | 17 +++++++++++++++++ t/t4211-line-log.sh | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Documentation/line-range-format.txt b/Documentation/line-range-format.txt index 469d80b242..d7f26039ca 100644 --- a/Documentation/line-range-format.txt +++ b/Documentation/line-range-format.txt @@ -26,3 +26,4 @@ If ``:'' is given in place of and , it denotes the range from the first funcname line that matches , up to the next funcname line. ``:'' searches from the end of the previous `-L` range, if any, otherwise from the start of file. +``^:'' searches from the start of file. diff --git a/line-range.c b/line-range.c index 4bae4bff21..ede0c6c98f 100644 --- a/line-range.c +++ b/line-range.c @@ -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); diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh index 4f7d6baef5..dabe89d91a 100644 --- a/t/annotate-tests.sh +++ b/t/annotate-tests.sh @@ -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