]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'es/blame-L-more'
authorJunio C Hamano <gitster@pobox.com>
Mon, 9 Sep 2013 21:32:45 +0000 (14:32 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Sep 2013 21:32:45 +0000 (14:32 -0700)
More fixes to the code to parse the "-L" option in "log" and "blame".

* es/blame-L-more:
  blame: reject empty ranges -L,+0 and -L,-0
  t8001/t8002: blame: demonstrate acceptance of bogus -L,+0 and -L,-0
  blame: reject empty ranges -LX,+0 and -LX,-0
  t8001/t8002: blame: demonstrate acceptance of bogus -LX,+0 and -LX,-0
  log: fix -L bounds checking bug
  t4211: retire soon-to-be unimplementable tests
  t4211: log: demonstrate -L bounds checking bug
  blame: fix -L bounds checking bug
  t8001/t8002: blame: add empty file & partial-line tests
  t8001/t8002: blame: demonstrate -L bounds checking bug
  t8001/t8002: blame: decompose overly-large test

builtin/blame.c
line-log.c
line-range.c
t/annotate-tests.sh
t/t4211-line-log.sh

index f932112e72f42fcfcb418109ecd7c08c3522d4f5..aa1abb6d5e19ed60197a477a8b4bafa6fbd20c76 100644 (file)
@@ -2495,13 +2495,13 @@ parse_done:
        bottom = top = 0;
        if (bottomtop)
                prepare_blame_range(&sb, bottomtop, lno, &bottom, &top);
+       if (lno < top || ((lno || bottom) && lno < bottom))
+               die("file %s has only %lu lines", path, lno);
        if (bottom < 1)
                bottom = 1;
        if (top < 1)
                top = lno;
        bottom--;
-       if (lno < top || lno < bottom)
-               die("file %s has only %lu lines", path, lno);
 
        ent = xcalloc(1, sizeof(*ent));
        ent->lno = bottom;
index c2d01dccc2a12a767c442de58ed78df130699d74..1c3ac8dccd1dd7c1c15aaa82e80d6dbdf129bb56 100644 (file)
@@ -594,13 +594,13 @@ parse_lines(struct commit *commit, const char *prefix, struct string_list *args)
                                    lines, &begin, &end,
                                    full_name))
                        die("malformed -L argument '%s'", range_part);
+               if (lines < end || ((lines || begin) && lines < begin))
+                       die("file %s has only %lu lines", name_part, lines);
                if (begin < 1)
                        begin = 1;
                if (end < 1)
                        end = lines;
                begin--;
-               if (lines < end || lines < begin)
-                       die("file %s has only %ld lines", name_part, lines);
                line_log_data_insert(&ranges, full_name, begin, end);
 
                free_filespec(spec);
index 3942475c2fc8e48c7f0a2d7808f77a4f71a1cde6..69e8d6b6c02101b4243e1850aa52c377ccaa0a2b 100644 (file)
@@ -21,11 +21,13 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,
         * for 20 lines, or "-L <something>,-5" for 5 lines ending at
         * <something>.
         */
-       if (1 < begin && (spec[0] == '+' || spec[0] == '-')) {
+       if (1 <= begin && (spec[0] == '+' || spec[0] == '-')) {
                num = strtol(spec + 1, &term, 10);
                if (term != spec + 1) {
                        if (!ret)
                                return term;
+                       if (num == 0)
+                               die("-L invalid empty range");
                        if (spec[0] == '-')
                                num = 0 - num;
                        if (0 < num)
index d4e7f4736f74e58da504a04be3898b0a4078fedb..ce5b8ed304d1c1374589fc96152eb4f0244e65b9 100644 (file)
@@ -185,6 +185,14 @@ test_expect_success 'blame -L Y,X (undocumented)' '
        check_count -L6,3 B 1 B1 1 B2 1 D 1
 '
 
+test_expect_success 'blame -L ,+0' '
+       test_must_fail $PROG -L,+0 file
+'
+
+test_expect_success 'blame -L X,+0' '
+       test_must_fail $PROG -L1,+0 file
+'
+
 test_expect_success 'blame -L X,+1' '
        check_count -L3,+1 B2 1
 '
@@ -193,6 +201,14 @@ test_expect_success 'blame -L X,+N' '
        check_count -L3,+4 B 1 B1 1 B2 1 D 1
 '
 
+test_expect_success 'blame -L ,-0' '
+       test_must_fail $PROG -L,-0 file
+'
+
+test_expect_success 'blame -L X,-0' '
+       test_must_fail $PROG -L1,-0 file
+'
+
 test_expect_success 'blame -L X,-1' '
        check_count -L3,-1 B2 1
 '
@@ -225,10 +241,32 @@ test_expect_success 'blame -L /RE/,-N' '
        check_count -L/99/,-3 B 1 B2 1 D 1
 '
 
+# 'file' ends with an incomplete line, so 'wc' reports one fewer lines than
+# git-blame sees, hence the last line is actually $(wc...)+1.
+test_expect_success 'blame -L X (X == nlines)' '
+       n=$(expr $(wc -l <file) + 1) &&
+       check_count -L$n C 1
+'
+
+test_expect_success 'blame -L X (X == nlines + 1)' '
+       n=$(expr $(wc -l <file) + 2) &&
+       test_must_fail $PROG -L$n file
+'
+
 test_expect_success 'blame -L X (X > nlines)' '
        test_must_fail $PROG -L12345 file
 '
 
+test_expect_success 'blame -L ,Y (Y == nlines)' '
+       n=$(expr $(wc -l <file) + 1) &&
+       check_count -L,$n A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
+'
+
+test_expect_success 'blame -L ,Y (Y == nlines + 1)' '
+       n=$(expr $(wc -l <file) + 2) &&
+       test_must_fail $PROG -L,$n file
+'
+
 test_expect_success 'blame -L ,Y (Y > nlines)' '
        test_must_fail $PROG -L,12345 file
 '
@@ -275,12 +313,102 @@ test_expect_success 'blame -L :nomatch' '
        test_must_fail $PROG -L:nomatch hello.c
 '
 
-test_expect_success 'blame -L bogus' '
-       test_must_fail $PROG -L file &&
-       test_must_fail $PROG -L1,+ file &&
-       test_must_fail $PROG -L1,- file &&
-       test_must_fail $PROG -LX file &&
-       test_must_fail $PROG -L1,X file &&
-       test_must_fail $PROG -L1,+N file &&
+test_expect_success 'setup incremental' '
+       (
+       GIT_AUTHOR_NAME=I &&
+       export GIT_AUTHOR_NAME &&
+       GIT_AUTHOR_EMAIL=I@test.git &&
+       export GIT_AUTHOR_EMAIL &&
+       >incremental &&
+       git add incremental &&
+       git commit -m "step 0" &&
+       printf "partial" >>incremental &&
+       git commit -a -m "step 0.5" &&
+       echo >>incremental &&
+       git commit -a -m "step 1"
+       )
+'
+
+test_expect_success 'blame empty' '
+       check_count -h HEAD^^ -f incremental
+'
+
+test_expect_success 'blame -L 0 empty (undocumented)' '
+       check_count -h HEAD^^ -f incremental -L0
+'
+
+test_expect_success 'blame -L 1 empty' '
+       test_must_fail $PROG -L1 incremental HEAD^^
+'
+
+test_expect_success 'blame -L 2 empty' '
+       test_must_fail $PROG -L2 incremental HEAD^^
+'
+
+test_expect_success 'blame half' '
+       check_count -h HEAD^ -f incremental I 1
+'
+
+test_expect_success 'blame -L 0 half (undocumented)' '
+       check_count -h HEAD^ -f incremental -L0 I 1
+'
+
+test_expect_success 'blame -L 1 half' '
+       check_count -h HEAD^ -f incremental -L1 I 1
+'
+
+test_expect_success 'blame -L 2 half' '
+       test_must_fail $PROG -L2 incremental HEAD^
+'
+
+test_expect_success 'blame -L 3 half' '
+       test_must_fail $PROG -L3 incremental HEAD^
+'
+
+test_expect_success 'blame full' '
+       check_count -f incremental I 1
+'
+
+test_expect_success 'blame -L 0 full (undocumented)' '
+       check_count -f incremental -L0 I 1
+'
+
+test_expect_success 'blame -L 1 full' '
+       check_count -f incremental -L1 I 1
+'
+
+test_expect_success 'blame -L 2 full' '
+       test_must_fail $PROG -L2 incremental
+'
+
+test_expect_success 'blame -L 3 full' '
+       test_must_fail $PROG -L3 incremental
+'
+
+test_expect_success 'blame -L' '
+       test_must_fail $PROG -L file
+'
+
+test_expect_success 'blame -L X,+' '
+       test_must_fail $PROG -L1,+ file
+'
+
+test_expect_success 'blame -L X,-' '
+       test_must_fail $PROG -L1,- file
+'
+
+test_expect_success 'blame -L X (non-numeric X)' '
+       test_must_fail $PROG -LX file
+'
+
+test_expect_success 'blame -L X,Y (non-numeric Y)' '
+       test_must_fail $PROG -L1,Y file
+'
+
+test_expect_success 'blame -L X,+N (non-numeric N)' '
+       test_must_fail $PROG -L1,+N file
+'
+
+test_expect_success 'blame -L X,-N (non-numeric N)' '
        test_must_fail $PROG -L1,-N file
 '
index 7665d6785c1a91ed0171e8cac61174ebee9b9a37..b01b3ddebb568e0fe74843d29933b5f0cda1a7d3 100755 (executable)
@@ -64,17 +64,34 @@ test_bad_opts "-L 1,1000:b.c" "has only.*lines"
 test_bad_opts "-L :b.c" "argument.*not of the form"
 test_bad_opts "-L :foo:b.c" "no match"
 
-# There is a separate bug when an empty -L range is the first -L encountered,
-# thus to demonstrate this particular bug, the empty -L range must follow a
-# non-empty -L range.
-test_expect_success '-L {empty-range} (any -L)' '
+test_expect_success '-L X (X == nlines)' '
+       n=$(wc -l <b.c) &&
+       git log -L $n:b.c
+'
+
+test_expect_success '-L X (X == nlines + 1)' '
        n=$(expr $(wc -l <b.c) + 1) &&
-       git log -L1,1:b.c -L$n:b.c
+       test_must_fail git log -L $n:b.c
+'
+
+test_expect_success '-L X (X == nlines + 2)' '
+       n=$(expr $(wc -l <b.c) + 2) &&
+       test_must_fail git log -L $n:b.c
 '
 
-test_expect_success '-L {empty-range} (first -L)' '
+test_expect_success '-L ,Y (Y == nlines)' '
+       n=$(printf "%d" $(wc -l <b.c)) &&
+       git log -L ,$n:b.c
+'
+
+test_expect_success '-L ,Y (Y == nlines + 1)' '
        n=$(expr $(wc -l <b.c) + 1) &&
-       git log -L$n:b.c
+       test_must_fail git log -L ,$n:b.c
+'
+
+test_expect_success '-L ,Y (Y == nlines + 2)' '
+       n=$(expr $(wc -l <b.c) + 2) &&
+       test_must_fail git log -L ,$n:b.c
 '
 
 test_done