Fix 'No newline...' annotation in rewrite diffs.
PATCH 1/1 Fix 'No newline...' annotation in rewrite diffs.
From 01730a741cc5fd7d0a5d8bd0d3df80d12c81fe48 Mon Sep 17 00:00:00 2001
From: Adam Butcher <[email protected]>
Date: Wed, 1 Aug 2012 22:25:09 +0100
Subject: [PATCH] Fix 'No newline...' annotation in rewrite diffs.
When operating in --break-rewrites (-B) mode on a file with no newline terminator (and assuming --break-rewrites determines that the diff _is_ a rewrite), git diff previously concatenated the indicator comment '\ No newline at end of file' directly to the terminating line rather than on a line of its own. The resulting diff is broken; claiming that the last line actually contains the indicator text. Without -B there is no problem with the same files.
This patch fixes the former case by inserting a newline into the output prior to emitting the indicator comment.
Potential issue: Currently this emits an ASCII 10 newline character only. I'm not sure whether this will be okay on all platforms; it seems to work fine on Windows and GNU at least.
A couple of tests have been added to the rewrite suite to confirm that the indicator comment is generated on its own line in both plain diff and rewrite mode. The latter test fails if the functional part of this patch (i.e. diff.c) is reverted.
--- diff.c | 1 + t/t4022-diff-rewrite.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+)
diff.c +1 -0
@@ -574,6 +574,7 @@ static void emit_rewrite_lines(struct emit_callback *ecb,if (!endp) {const char *plain =diff_get_color (ecb->color_diff,DIFF_PLAIN ); +putc ('\n' , ecb->opt->file);emit_line_0 (ecb->opt, plain, reset,'\\' , nneof,strlen (nneof)); }
t/t4022-diff-rewrite.sh +27 -0
@@ -66,5 +66,32 @@ test_expect_success 'suppress deletion diff with -B -D' ' grep -v "Linus Torvalds" actual ' +# create a file containing numbers with no newline at +# the end and modify it such that the starting 10 lines +# are unchanged, the next 101 are rewritten and the last +# line differs only in that in is terminated by a newline. +seq 1 10 > seq +seq 100 +1 200 >> seq +printf 201 >> seq +(git add seq; git commit seq -m seq) >/dev/null +seq 1 10 > seq +seq 300 -1 200 >> seq + +test_expect_success 'no newline at eof is on its own line without -B' ' + + (git diff seq; true) > res && + grep "^\\\\ No newline at end of file$" res && + grep -v "^.\\+\\\\ No newline at end of file" res && + grep -v "\\\\ No newline at end of file.\\+$" res +' + +test_expect_success 'no newline at eof is on its own line with -B' ' + + (git diff -B seq; true) > res && + grep "^\\\\ No newline at end of file$" res && + grep -v "^.\\+\\\\ No newline at end of file" res && + grep -v "\\\\ No newline at end of file.\\+$" res +' + test_done
Signature · 1 line
1.7.11.msysgit.0
Quoted 4 lines · Adam Butcher
From
01730a741cc5fd7d0a5d8bd0d3df80d12c81fe48Mon Sep 17 00:00:00 2001
From: Adam Butcher <[email protected]>
Date: Wed, 1 Aug 2012 22:25:09 +0100
Subject: [PATCH] Fix 'No newline...' annotation in rewrite diffs.
You can drop these lines from the email body; they are redundant with what's in your actual header.
Quoted 10 lines
When operating in --break-rewrites (-B) mode on a file with no newline terminator (and assuming --break-rewrites determines that the diff _is_ a rewrite), git diff previously concatenated the indicator comment '\ No newline at end of file' directly to the terminating line rather than on a line of its own. The resulting diff is broken; claiming that the last line actually contains the indicator text. Without -B there is no problem with the same files.
This patch fixes the former case by inserting a newline into the output prior to emitting the indicator comment.
Makes sense.
Quoted 3 lines
Potential issue: Currently this emits an ASCII 10 newline character only. I'm not sure whether this will be okay on all platforms; it seems to work fine on Windows and GNU at least.
This should not be a problem. Git always outputs newlines; it is stdio who might munge it into CRLF if need be (and your patch uses putc, so we should be fine).
Quoted 4 lines
A couple of tests have been added to the rewrite suite to confirm that the indicator comment is generated on its own line in both plain diff and rewrite mode. The latter test fails if the functional part of this patch (i.e.
diff.c) is reverted.
Yay, tests.
diff.c static void emit_rewrite_lines(struct · line 574
Quoted 11 lines
--- diff.c | 1 + t/t4022-diff-rewrite.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+)diff.c +0
-0@@ -574,6 +574,7 @@ static void emit_rewrite_lines(struct emit_callback *ecb,
Your patch is line-wrapped and cannot be applied as-is (try turning off "flowed text" in your MUA).
Quoted 7 lines
diff.c +1
-0if (!endp) {const char *plain =diff_get_color (ecb->color_diff,DIFF_PLAIN ); +putc ('\n' , ecb->opt->file);emit_line_0 (ecb->opt, plain, reset,'\\' , nneof,strlen (nneof));}
Looks correct. I was curious how the regular (non-rewrite) code path did this, and it just sticks the "\n" as part of the nneof string. However, we would not want that here, because each line should have its own color markers.
diff.c
Quoted 10 lines
diff.c +10
-0+# create a file containing numbers with no newline at +# the end and modify it such that the starting 10 lines +# are unchanged, the next 101 are rewritten and the last +# line differs only in that in is terminated by a newline. +seq 1 10 > seq +seq 100 +1 200 >> seq +printf 201 >> seq +(git add seq; git commit seq -m seq) >/dev/null +seq 1 10 > seq +seq 300 -1 200 >> seq
Seq is (unfortunately) not portable. I usually use a perl snippet instead, like:
perl -le 'print for (1..10)'
Though I think we are adjusting that to use $PERL_PATH these days.
-Peff
Quoted 10 lines · Jeff King
Quoted 4 lines · Adam Butcher
From
01730a741cc5fd7d0a5d8bd0d3df80d12c81fe48Mon Sep 17 00:00:00 2001
From: Adam Butcher <[email protected]>
Date: Wed, 1 Aug 2012 22:25:09 +0100
Subject: [PATCH] Fix 'No newline...' annotation in rewrite diffs.You can drop these lines from the email body; they are redundant with what's in your actual header.
I sent via a webmail interface and wasn't sure what format the resulting mail would have so decided to paste the entire formatted patch in. Seeing as the webmailer has corrupted my patch with word wrapping (which I noticed almost immediately when my post hit gmane and have since found out that it apparently cannot be disabled?!) it was a bad idea all round. I could attach as a file but this is cumbersome from a review and apply point of view so I think I'll hook up git to gmail's tls smtp server so that I can use git send-email direct rather than messing about with a GUI.
Quoted 13 lines
Quoted 10 lines
When operating in --break-rewrites (-B) mode on a file with no newline terminator (and assuming --break-rewrites determines that the diff _is_ a rewrite), git diff previously concatenated the indicator comment '\ No newline at end of file' directly to the terminating line rather than on a line of its own. The resulting diff is broken; claiming that the last line actually contains the indicator text. Without -B there is no problem with the same files.
This patch fixes the former case by inserting a newline into the output prior to emitting the indicator comment.
Makes sense.
Quoted 8 lines
Quoted 3 lines
Potential issue: Currently this emits an ASCII 10 newline character only. I'm not sure whether this will be okay on all platforms; it seems to work fine on Windows and GNU at least.
This should not be a problem. Git always outputs newlines; it is stdio who might munge it into CRLF if need be (and your patch uses putc, so we should be fine).
Great.
Quoted 12 lines
Quoted 4 lines
A couple of tests have been added to the rewrite suite to confirm that the indicator comment is generated on its own line in both plain diff and rewrite mode. The latter test fails if the functional part of this patch (i.e.
diff.c) is reverted.Yay, tests.
Quoted 5 lines
--- diff.c | 1 + t/t4022-diff-rewrite.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+)
Quoted 10 lines
diff.c static void emit_rewrite_lines(struct · line 574
Quoted 6 lines
diff.c +0
-0@@ -574,6 +574,7 @@ static void emit_rewrite_lines(struct emit_callback *ecb,Your patch is line-wrapped and cannot be applied as-is (try turning off "flowed text" in your MUA).
Indeed. Grr. If only I could. I'll test that whatever solution I come up with works before posting again with an update addressing yours and Junio's comments.
Quoted 27 lines
Quoted 7 lines
diff.c +1
-0if (!endp) {const char *plain =diff_get_color (ecb->color_diff,DIFF_PLAIN ); +putc ('\n' , ecb->opt->file);emit_line_0 (ecb->opt, plain, reset,'\\' , nneof,strlen (nneof));}
Looks correct. I was curious how the regular (non-rewrite) code path did this, and it just sticks the "\n" as part of the nneof string. However, we would not want that here, because each line should have its own color markers.
diff.c
Quoted 10 lines
diff.c +10
-0+# create a file containing numbers with no newline at +# the end and modify it such that the starting 10 lines +# are unchanged, the next 101 are rewritten and the last +# line differs only in that in is terminated by a newline. +seq 1 10 > seq +seq 100 +1 200 >> seq +printf 201 >> seq +(git add seq; git commit seq -m seq) >/dev/null +seq 1 10 > seq +seq 300 -1 200 >> seqSeq is (unfortunately) not portable. I usually use a perl snippet instead, like:
Quoted 4 lines
perl -le 'print for (1..10)'
Though I think we are adjusting that to use $PERL_PATH these days.
No probs. Will change.
Cheers
Adam
Quoted 9 lines · Jeff King
Quoted 4 lines · Adam Butcher
From
01730a741cc5fd7d0a5d8bd0d3df80d12c81fe48Mon Sep 17 00:00:00 2001
From: Adam Butcher <[email protected]>
Date: Wed, 1 Aug 2012 22:25:09 +0100
Subject: [PATCH] Fix 'No newline...' annotation in rewrite diffs.You can drop these lines from the email body; they are redundant with what's in your actual header.
s/can/should/ actually, for readability.
Quoted 21 lines
Quoted 10 lines
When operating in --break-rewrites (-B) mode on a file with no newline terminator (and assuming --break-rewrites determines that the diff _is_ a rewrite), git diff previously concatenated the indicator comment '\ No newline at end of file' directly to the terminating line rather than on a line of its own. The resulting diff is broken; claiming that the last line actually contains the indicator text. Without -B there is no problem with the same files.
This patch fixes the former case by inserting a newline into the output prior to emitting the indicator comment.
Makes sense.
Quoted 3 lines
Potential issue: Currently this emits an ASCII 10 newline character only. I'm not sure whether this will be okay on all platforms; it seems to work fine on Windows and GNU at least.
This should not be a problem. Git always outputs newlines; it is stdio who might munge it into CRLF if need be (and your patch uses putc, so we should be fine).
Quoted 8 lines
Quoted 4 lines
A couple of tests have been added to the rewrite suite to confirm that the indicator comment is generated on its own line in both plain diff and rewrite mode. The latter test fails if the functional part of this patch (i.e.
diff.c) is reverted.Yay, tests.
Quoted 1 line
---
Sign-off needed.
Quoted 41 lines
diff.c static void emit_rewrite_lines(struct · line 574
Quoted 10 lines
diff.c | 1 + t/t4022-diff-rewrite.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+)diff.c +0
-0@@ -574,6 +574,7 @@ static void emit_rewrite_lines(struct emit_callback *ecb,Your patch is line-wrapped and cannot be applied as-is (try turning off "flowed text" in your MUA).
Quoted 7 lines
diff.c +1
-0if (!endp) {const char *plain =diff_get_color (ecb->color_diff,DIFF_PLAIN ); +putc ('\n' , ecb->opt->file);emit_line_0 (ecb->opt, plain, reset,'\\' , nneof,strlen (nneof));}
Looks correct. I was curious how the regular (non-rewrite) code path did this, and it just sticks the "\n" as part of the nneof string. However, we would not want that here, because each line should have its own color markers.
diff.c
Quoted 10 lines
diff.c +10
-0+# create a file containing numbers with no newline at +# the end and modify it such that the starting 10 lines +# are unchanged, the next 101 are rewritten and the last +# line differs only in that in is terminated by a newline. +seq 1 10 > seq +seq 100 +1 200 >> seq +printf 201 >> seq +(git add seq; git commit seq -m seq) >/dev/null +seq 1 10 > seq +seq 300 -1 200 >> seqSeq is (unfortunately) not portable. I usually use a perl snippet instead, like:
Quoted 3 lines
perl -le 'print for (1..10)'
Though I think we are adjusting that to use $PERL_PATH these days.
t/perf/perf-lib.sh and t/t5551-http-fetch.sh seem to use "seq"; perhaps we should replace them, then.
Quoted 9 lines · Junio C Hamano
Quoted 6 lines
Seq is (unfortunately) not portable. I usually use a perl snippet instead, like:
perl -le 'print for (1..10)'
Though I think we are adjusting that to use $PERL_PATH these days.
t/perf/perf-lib.shandt/t5551-http-fetch.shseem to use "seq"; perhaps we should replace them, then.
Traditionally, BSD did not have seq (they have "jot" instead). However, my OS X 10.7 box does have seq, and its manpage claims that it appeared in FreeBSD 9.0. But we should be able to run the test suite on older versions of both (9.0 is barely 6 months old).
I suspect people on those platforms did not notice because t5551 does not run by default (not only due to the apache requirement, but you have to set GIT_TEST_LONG to trigger the particular test that uses it), and people don't typically run the perf code regularly to look for regressions.
-- >8 --
Subject: [PATCH] stop using 'seq' in test scripts
The seq command is GNU-ism, and is missing at least in older BSD releases and their derivatives, not to mention antique commercial Unixes.
We already purged it in b3431bc (Don't use seq in tests, not everyone has it, 2007-05-02), but a few new instances have crept in. They went unnoticed because they are in scripts that are not run by default.
Let's replace them with a perl snippet (which we already assume to be everywhere elsewhere in the test suite).
---
b3431bc used a while loop with increment to replace it, which we could also do. I think the perl script is a little easier to read. If we ever want to drop the perl dependency for the test suite, we could write a 5-liner test-seq.c replacement.
t/perf/perf-lib.sh | 2 +- t/t5551-http-fetch.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
t/perf/perf-lib.sh +1 -1
@@ -163,7 +163,7 @@ test_perf () { else echo "perf $test_count - $1:" fi - for i in $(seq 1 $GIT_PERF_REPEAT_COUNT); do + for i in $("$PERL_PATH" -le "print for 1..$GIT_PERF_REPEAT_COUNT"); do say >&3 "running: $2" if test_run_perf_ "$2" then
t/t5551-http-fetch.sh +1 -1
@@ -114,7 +114,7 @@ test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' ( cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - for i in `seq 50000` + for i in `"$PERL_PATH" -le "print for (1..50000)"` do echo "commit refs/heads/too-many-refs" echo "mark :$i"
t/perf/perf-lib.sh test_perf () { · line 166
Quoted 2 lines · Jeff King <peff <at> peff.net> writes:
t/perf/perf-lib.sh +1
-1- for i in $(seq 1 $GIT_PERF_REPEAT_COUNT); do + for i in $("$PERL_PATH" -le "print for 1..$GIT_PERF_REPEAT_COUNT"); do
Maybe you could introduce "test_seq" instead.
t/t4022-diff-rewrite.sh test_expect_success 'suppress deletion diff with -B -D' ' · line 78
Quoted 10 lines · Adam Butcher
t/t4022-diff-rewrite.sh +10
-0+# create a file containing numbers with no newline at +# the end and modify it such that the starting 10 lines +# are unchanged, the next 101 are rewritten and the last +# line differs only in that in is terminated by a newline. +seq 1 10 > seq +seq 100 +1 200 >> seq +printf 201 >> seq +(git add seq; git commit seq -m seq) >/dev/null +seq 1 10 > seq +seq 300 -1 200 >> seq
We would prefer to have these set-up steps in test_expect_success. That way, we will have more chance to catch potential and unintended breakage to "git add" and "git commit" when people attempt to update them.
Also, the redirect target sticks to redirect operator in our scripts, i.e. "cmd >seq" not "cmd > seq".
t/t4022-diff-rewrite.sh test_expect_success 'suppress deletion diff with -B -D' ' · line 82
Quoted 3 lines
t/t4022-diff-rewrite.sh +3
-0+test_expect_success 'no newline at eof is on its own line without -B' + + (git diff seq; true) > res &&
What is this subshell and true about? A git diff does not exit with non zero to signal differences, and even if it did, the right way to write it would be
test_might_fail git cmd >res &&
to allow us to make sure that the git command that may or may not exit with zero still does not die an uncontrolled death (e.g. segv).
t/t4022-diff-rewrite.sh test_expect_success 'suppress deletion diff with -B -D' ' · line 86
Quoted 4 lines
t/t4022-diff-rewrite.sh +4
-0+ grep "^\\\\ No newline at end of file$" res && + grep -v "^.\\+\\\\ No newline at end of file" res && + grep -v "\\\\ No newline at end of file.\\+$" res +'
It is preferrable not to spell "No newline at ..." part out, so that we won't have to worry about future rewords and i18n. There are older tests that predate i18n and they do spell these out, but that is not a good reason to make things worse than they already are.
"git apply" only looks at the backslash-space at the beginning of line anyway.
t/t4022-diff-rewrite.sh test_expect_success 'suppress deletion diff with -B -D' ' · line 94
Quoted 7 lines
t/t4022-diff-rewrite.sh +7
-0+test_expect_success 'no newline at eof is on its own line with -B' ' + + (git diff -B seq; true) > res && + grep "^\\\\ No newline at end of file$" res && + grep -v "^.\\+\\\\ No newline at end of file" res && + grep -v "\\\\ No newline at end of file.\\+$" res +'
Likewise.
Quoted 1 line
test_done
Thanks.
Quoted 18 lines · Junio C Hamano
t/t4022-diff-rewrite.sh test_expect_success 'suppress deletion diff with -B -D' ' · line 78
Quoted 10 lines · Adam Butcher
t/t4022-diff-rewrite.sh +10
-0+# create a file containing numbers with no newline at +# the end and modify it such that the starting 10 lines +# are unchanged, the next 101 are rewritten and the last +# line differs only in that in is terminated by a newline. +seq 1 10 > seq +seq 100 +1 200 >> seq +printf 201 >> seq +(git add seq; git commit seq -m seq) >/dev/null +seq 1 10 > seq +seq 300 -1 200 >> seqWe would prefer to have these set-up steps in
test_expect_success. That way, we will have more chance to catch potential and unintended breakage to "git add" and "git commit" when people attempt to update them.
Cool, no probs. I had originally put them at the start of the first test that I added but decided to pull them out as prep. I think that msysGit or something about my Windows shell session may have played a part in my not chaining them with && also (see below). I'll clean them up and wrap them in a test_expect_success.
Quoted 3 lines
Also, the redirect target sticks to redirect operator in our scripts, i.e. "cmd >seq" not "cmd > seq".
Okay, will change.
Quoted 8 lines
t/t4022-diff-rewrite.sh test_expect_success 'suppress deletion diff with -B -D' ' · line 82
Quoted 4 lines
t/t4022-diff-rewrite.sh +3
-1+test_expect_success 'no newline at eof is on its own line without -B' + + (git diff seq; true) > res &&What is this subshell and true about? A git diff does not exit with non zero to signal differences,
Hmm, (?confused?) yeah actually I didn't think it did -- I was surprised when git returned 1 for this line. I think it must have been an issue with the version msysGit I was using or something sticking errorlevel in my Windows shell. Git seemed to return 1 ALWAYS! I usually use gnu/linux but on this occasion I wrote the fix and tests blind on a Windows machine testing the logic manually with msysGit. I ran the tests on a linux machine at work and they did what I expected so I left them as was without rechecking this.
I'm glad that this can be simplified. It felt wrong -- similar lines elsewhere in the script didn't do it so I wasn't really happy with it. Turns out it looks to be a Windows/environment issue. I cannot reproduce it now.
Quoted 5 lines
and even if it did, the right way to
write it would betest_might_fail git cmd >res &&
Fair enough. Good to know that's available.
Quoted 11 lines
to allow us to make sure that the git command that may or may not exit with zero still does not die an uncontrolled death (e.g. segv).
t/t4022-diff-rewrite.sh test_expect_success 'suppress deletion diff with -B -D' ' · line 86
Quoted 4 lines
t/t4022-diff-rewrite.sh +4
-0+ grep "^\\\\ No newline at end of file$" res && + grep -v "^.\\+\\\\ No newline at end of file" res && + grep -v "\\\\ No newline at end of file.\\+$" res +'It is preferrable not to spell "No newline at ..." part out, so that we won't have to worry about future rewords and i18n.
Okay no probs. I was originally going to spell it out only once and use parameter expansion. However I understand the point of not spelling it out at all. The only reason I did so was to catch other potential errors where text may have been 'attached' to either side of the annotation string by some future (or other) bug.
Quoted 4 lines
There are older
tests that predate i18n and they do spell these out, but that is not a good reason to make things worse than they already are.
Agreed. Should I just test for this prefix case (i.e. the bug at hand) only and not preempt future potential issues? Or should I just stick the current string in a variable and keep the logic as is; at least then there would only be one place requiring a fix in the reword case (but still additional rework in the i18n case -- though I assume the test could force a particular locale to evade this).
Quoted 3 lines
"git apply" only looks at the backslash-space at the beginning of line anyway.
Okay.
Quoted 11 lines
t/t4022-diff-rewrite.sh test_expect_success 'suppress deletion diff with -B -D' ' · line 94
Quoted 8 lines
+test_expect_success 'no newline at eof is on its own line with -B' '
t/t4022-diff-rewrite.sh +6
-0+ + (git diff -B seq; true) > res && + grep "^\\\\ No newline at end of file$" res && + grep -v "^.\\+\\\\ No newline at end of file" res && + grep -v "\\\\ No newline at end of file.\\+$" res +'Likewise.
Quoted 3 lines
Quoted 1 line
test_doneThanks.
No probs. I will address both your and Jeff's comments sometime tomorrow and hopefully send a well formatted patch in next time.
Cheers,
Adam
Quoted 6 lines · Michał Kiedrowicz
t/perf/perf-lib.sh test_perf () { · line 166
Quoted 2 lines · Jeff King <peff <at> peff.net> writes:
t/perf/perf-lib.sh +1
-1- for i in $(seq 1 $GIT_PERF_REPEAT_COUNT); do + for i in $("$PERL_PATH" -le "print for 1..$GIT_PERF_REPEAT_COUNT"); doMaybe you could introduce "
test_seq" instead.
I don't have a strong preference, as there are only two callsites. Do you want to make a patch?
-Peff
PATCH 1/1 tests: Introduce test_seq
Jeff King wrote:
The seq command is GNU-ism, and is missing at least in older BSD releases and their derivatives, not to mention antique commercial Unixes.
We already purged it in b3431bc (Don't use seq in tests, not everyone has it, 2007-05-02), but a few new instances have crept in. They went unnoticed because they are in scripts that are not run by default.
This commit replaces them with test_seq that is implemented with a Perl snippet (proposed by Jeff). This is better than inlining this snippet everywhere it's needed because it's easier to read and it's easier to change the implementation (e.g. to C) if we ever decide to remove Perl from the test suite.
Note that test_seq is not a complete replacement for seq(1). It just has what we need now.
There are also many places that do for i in 1 2 3 ... but I'm not sure if it's worth converting them to test_seq. That would introduce running more processes of Perl during the tests and might increase the total time tests take.
---
Quoted 2 lines
I don't have a strong preference, as there are only two callsites. Do you want to make a patch?
Sure. Here it is.
t/perf/perf-lib.sh | 2 +- t/t5551-http-fetch.sh | 2 +- t/test-lib-functions.sh | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-)
t/perf/perf-lib.sh +1 -1
@@ -163,7 +163,7 @@ test_perf () { else echo "perf $test_count - $1:" fi - for i in $(seq 1 $GIT_PERF_REPEAT_COUNT); do + for i in $(test_seq 1 $GIT_PERF_REPEAT_COUNT); do say >&3 "running: $2" if test_run_perf_ "$2" then
t/t5551-http-fetch.sh +1 -1
@@ -114,7 +114,7 @@ test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' ( cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - for i in `seq 50000` + for i in `test_seq 50000` do echo "commit refs/heads/too-many-refs" echo "mark :$i"
t/test-lib-functions.sh +14 -0
@@ -530,6 +530,20 @@ test_cmp() { $GIT_TEST_CMP "$@" } +# test_seq is a portable replacement for seq(1). +# It may be used like: +# +# for i in `test_seq 100`; do +# echo $i +# done + +test_seq () { + test $# = 1 || + error "bug in the test script: not 1 parameter to test_seq" + last=$1 + "$PERL_PATH" -le "print for 1..$last" +} + # This function can be used to schedule some commands to be run # unconditionally at the end of the test to restore sanity: #
Signature · 1 line
1.7.11.rc0.212.g37218b0.dirty
Re: [PATCH] tests: Introduce test_seq
Quoted 20 lines · Michał Kiedrowicz
Jeff King wrote:
The seq command is GNU-ism, and is missing at least in older BSD releases and their derivatives, not to mention antique commercial Unixes.
We already purged it in b3431bc (Don't use seq in tests, not everyone has it, 2007-05-02), but a few new instances have crept in. They went unnoticed because they are in scripts that are not run by default.
This commit replaces them with
test_seqthat is implemented with a Perl snippet (proposed by Jeff). This is better than inlining this snippet everywhere it's needed because it's easier to read and it's easier to change the implementation (e.g. to C) if we ever decide to remove Perl from the test suite.Note that
test_seqis not a complete replacement for seq(1). It just has what we need now.
Quoted 6 lines
There are also many places that do
for i in 1 2 3 ...but I'm not sure if it's worth converting them totest_seq. That would introduce running more processes of Perl during the tests and might increase the total time tests take.Signed-off-by Michał Kiedrowicz <[email protected]>
Fine explanation, but...
t/perf/perf-lib.sh test_perf () { · line 166
Quoted 10 lines
t/perf/perf-lib.sh +1
-1@@ -163,7 +163,7 @@ test_perf () { else echo "perf $test_count - $1:" fi - for i in $(seq 1 $GIT_PERF_REPEAT_COUNT); do + for i in $(test_seq 1 $GIT_PERF_REPEAT_COUNT); do
Two args to test_seq, but...
t/perf/perf-lib.sh test_perf () {
Quoted 13 lines
t/perf/perf-lib.sh +13
-0+# test_seq is a portable replacement for seq(1). +# It may be used like: +# +# for i in `test_seq 100`; do +# echo $i +# done + +test_seq () { + test $# = 1 || + error "bug in the test script: not 1 parameter to test_seq" + last=$1 + "$PERL_PATH" -le "print for 1..$last" +}
it wants only one.
I think you would want:
test $# = 1 && set -- 1 "$@" "$PERL_PATH" -le "print for $1..$2"
It might also be worth quoting the parameters like this:
"$PERL_PATH" -le "print for '$1'..'$2'"
so that "test_seq a f" works, too.
-Peff
Re: [PATCH] tests: Introduce test_seq
Quoted 8 lines · Jeff King
Quoted 6 lines · Michał Kiedrowicz
Jeff King wrote:
The seq command is GNU-ism, and is missing at least in older BSD releases and their derivatives, not to mention antique commercial Unixes.
Quoted 7 lines
Quoted 7 lines
We already purged it in b3431bc (Don't use seq in tests, not everyone has it, 2007-05-02), but a few new instances have crept in. They went unnoticed because they are in scripts that are not run by default.
This commit replaces them with
test_seqthat is implemented with a Perl snippet (proposed by Jeff).
Just say "Replace them with test_seq...", without "This commit".
Quoted 33 lines
Fine explanation, but...
t/perf/perf-lib.sh test_perf () { · line 166
Quoted 10 lines
t/perf/perf-lib.sh +1
-1@@ -163,7 +163,7 @@ test_perf () { else echo "perf $test_count - $1:" fi - for i in $(seq 1 $GIT_PERF_REPEAT_COUNT); do + for i in $(test_seq 1 $GIT_PERF_REPEAT_COUNT); doTwo args to
test_seq, but...t/perf/perf-lib.sh test_perf () {
Quoted 13 lines
t/perf/perf-lib.sh +13
-0+# test_seq is a portable replacement for seq(1). +# It may be used like: +# +# for i in `test_seq 100`; do +# echo $i +# done + +test_seq () { + test $# = 1 || + error "bug in the test script: not 1 parameter to test_seq" + last=$1 + "$PERL_PATH" -le "print for 1..$last" +}it wants only one.
I think you would want:
Quoted 8 lines
test $# = 1 && set -- 1 "$@" "$PERL_PATH" -le "print for $1..$2"It might also be worth quoting the parameters like this:
"$PERL_PATH" -le "print for '$1'..'$2'"
so that "
test_seqa f" works, too.
Yeah, I like that last one, but then unlike the claim in the comment before the function definition, it is not "a portable replacement for seq(1)" at all, but something a lot more suited for our purpose. So at least the comment needs to be updated. I do not have strong opinion on calling this test_seq when it acts differently from seq; it is not confusing enough to make me push something longer that is different from "seq", e.g. test_sequence.
Wouldn't it be cleaner and readable to write it like this
"$PERL_PATH" -le 'print for $ARGV[0]..$ARGV[1]' "$1" "$2"
by the way?
PATCH 1/1 tests: Introduce test_seq
Jeff King wrote:
The seq command is GNU-ism, and is missing at least in older BSD releases and their derivatives, not to mention antique commercial Unixes.
We already purged it in b3431bc (Don't use seq in tests, not everyone has it, 2007-05-02), but a few new instances have crept in. They went unnoticed because they are in scripts that are not run by default.
Replace them with test_seq that is implemented with a Perl snippet (proposed by Jeff). This is better than inlining this snippet everywhere it's needed because it's easier to read and it's easier to change the implementation (e.g. to C) if we ever decide to remove Perl from the test suite.
Note that test_seq is not a complete replacement for seq(1). It just has what we need now.
There are also many places that do for i in 1 2 3 ... but I'm not sure if it's worth converting them to test_seq. That would introduce running more processes of Perl.
---
Changes since previous version:
* Removed "This commit replaces" from commit message
* Reworded test_seq description
* Now $first and $last are passed to Perl as arguments
t/perf/perf-lib.sh | 2 +- t/t5551-http-fetch.sh | 2 +- t/test-lib-functions.sh | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-)
t/perf/perf-lib.sh +1 -1
@@ -163,7 +163,7 @@ test_perf () { else echo "perf $test_count - $1:" fi - for i in $(seq 1 $GIT_PERF_REPEAT_COUNT); do + for i in $(test_seq 1 $GIT_PERF_REPEAT_COUNT); do say >&3 "running: $2" if test_run_perf_ "$2" then
t/t5551-http-fetch.sh +1 -1
@@ -114,7 +114,7 @@ test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' ( cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - for i in `seq 50000` + for i in `test_seq 50000` do echo "commit refs/heads/too-many-refs" echo "mark :$i"
t/test-lib-functions.sh +20 -0
@@ -530,6 +530,26 @@ test_cmp() { $GIT_TEST_CMP "$@" } +# Print a sequence of numbers or letters in increasing order. This is +# similar to GNU seq(1), but the latter might not be available +# everywhere. It may be used like: +# +# for i in `test_seq 100`; do +# for j in `test_seq 10 20`; do +# for k in `test_seq a z`; do +# echo $i-$j-$k +# done +# done +# done + +test_seq () { + test $# = 2 && { first=$1; shift; } || first=1 + test $# = 1 || + error "bug in the test script: not 1 or 2 parameters to test_seq" + last=$1 + "$PERL_PATH" -le 'print for "$ARGV[0]".."$ARGV[1]"' "$first" "$last" +} + # This function can be used to schedule some commands to be run # unconditionally at the end of the test to restore sanity: #
Signature · 1 line
1.7.11.rc0.212.g37218b0.dirty
Re: [PATCH] tests: Introduce test_seq
Tentatively I'll queue this one on top, but I am tempted to squash this in before merging the topic down.
-- >8 --
Subject: [PATCH] fixup! tests: Introduce test_seq
Complex chains of && and || are harder to read when used as replacement for if/else statements, but it is easy to rewrite it with a case/esac in this case.
Avoid using unnecessary variables $first and $last.
--- t/test-lib-functions.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
t/test-lib-functions.sh +7 -6
@@ -532,7 +532,7 @@ test_cmp() { # Print a sequence of numbers or letters in increasing order. This is # similar to GNU seq(1), but the latter might not be available -# everywhere. It may be used like: +# everywhere (and does not do letters). It may be used like: # # for i in `test_seq 100`; do # for j in `test_seq 10 20`; do
@@ -543,11 +543,12 @@ test_cmp() { # done test_seq () { - test $# = 2 && { first=$1; shift; } || first=1 - test $# = 1 || - error "bug in the test script: not 1 or 2 parameters to test_seq" - last=$1 - "$PERL_PATH" -le 'print for "$ARGV[0]".."$ARGV[1]"' "$first" "$last" + case $# in + 1) set 1 "$@" ;; + 2) ;; + *) error "bug in the test script: not 1 or 2 parameters to test_seq" ;; + esac + "$PERL_PATH" -le 'print for $ARGV[0]..$ARGV[1]' "$@" } # This function can be used to schedule some commands to be run
Signature · 1 line
1.7.12.rc1.50.g3df08cf
Re: [PATCH] tests: Introduce test_seq
Quoted 9 lines · Junio C Hamano
Tentatively I'll queue this one on top, but I am tempted to squash this in before merging the topic down.
-- >8 --
Subject: [PATCH] fixup! tests: Introducetest_seqComplex chains of && and || are harder to read when used as replacement for if/else statements, but it is easy to rewrite it with a case/esac in this case.
I just copied it from test_expect_success, but yeah, case/esac is clearer.
Quoted 39 lines
Avoid using unnecessary variables $first and $last.
Signed-off-by Junio C Hamano <[email protected]>--- t/test-lib-functions.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)t/test-lib-functions.sh +7
-6@@ -532,7 +532,7 @@ test_cmp() { # Print a sequence of numbers or letters in increasing order. This is # similar to GNU seq(1), but the latter might not be available -# everywhere. It may be used like: +# everywhere (and does not do letters). It may be used like: # # for i in `test_seq 100`; do # for j in `test_seq 10 20`; do@@ -543,11 +543,12 @@ test_cmp() { # done test_seq () { - test $# = 2 && { first=$1; shift; } || first=1 - test $# = 1 || - error "bug in the test script: not 1 or 2 parameters to test_seq" - last=$1 - "$PERL_PATH" -le 'print for "$ARGV[0]".."$ARGV[1]"' "$first" "$last" + case $# in + 1) set 1 "$@" ;; + 2) ;; + *) error "bug in the test script: not 1 or 2 parameters to test_seq" ;; + esac + "$PERL_PATH" -le 'print for $ARGV[0]..$ARGV[1]' "$@" } # This function can be used to schedule some commands to be run
Re: [PATCH] tests: Introduce test_seq
Quoted 8 lines · Michał Kiedrowicz <michal.kiedrowicz <at> gmail.com> writes:
Quoted 7 lines · Junio C Hamano <gitster <at> pobox.com> wrote:
t/test-lib-functions.sh +0
-0@@ -543,11 +543,12 @@ test_cmp() { # done
Quoted 10 lines
t/test-lib-functions.sh test_cmp() { · line 549
Quoted 10 lines
t/test-lib-functions.sh +4
-5test_seq () { - test $# = 2 && { first=$1; shift; } || first=1 - test $# = 1 || - error "bug in the test script: not 1 or 2 parameters to test_seq" - last=$1 - "$PERL_PATH" -le 'print for "$ARGV[0]".."$ARGV[1]"' "$first" "$last" + case $# in + 1) set 1 "$@" ;; + 2) ;; + *) error "bug in the test script: not 1 or 2 parameters to
test_seq" ;;
Quoted 5 lines
t/test-lib-functions.sh test_cmp() { · line 554
Quoted 5 lines
t/test-lib-functions.sh +2
-0+ esac + "$PERL_PATH" -le 'print for $ARGV[0]..$ARGV[1]' "$@" } # This function can be used to schedule some commands to be run
-- >8 --
Subject: [PATCH] Fixup test_seq: ensure arguments passed to script.
If the arguments passed to to test_seq start with '-' (e.g. negative integers) they are considered perl options and the program errors. By prefixing the user argument list with '--' when passing to perl, this is avoid and sequences involving negative numbers are possible.
--- t/test-lib-functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/test-lib-functions.sh +0 -0
@@ -539,7 +539,7 @@ test_seq () { 2) ;; *) error "bug in the test script: not 1 or 2 parameters to
test_seq" ;;
esac
- "$PERL_PATH" -le 'print for $ARGV[0]..$ARGV[1]' "$@"
+ "$PERL_PATH" -le 'print for $ARGV[0]..$ARGV[1]' -- "$@"
}
# This function can be used to schedule some commands to be run
Signature · 1 line
1.7.11.msysgit.1.1.gf0affa1
Re: [PATCH] tests: Introduce test_seq
In reply to Michał KiedrowiczQuoted 20 lines · Michał Kiedrowicz
Jeff King wrote:
The seq command is GNU-ism, and is missing at least in older BSD releases and their derivatives, not to mention antique commercial Unixes.
We already purged it in b3431bc (Don't use seq in tests, not everyone has it, 2007-05-02), but a few new instances have crept in. They went unnoticed because they are in scripts that are not run by default.
Replace them with
test_seqthat is implemented with a Perl snippet (proposed by Jeff). This is better than inlining this snippet everywhere it's needed because it's easier to read and it's easier to change the implementation (e.g. to C) if we ever decide to remove Perl from the test suite.Note that
test_seqis not a complete replacement for seq(1). It just has what we need now.
Quoted 6 lines
There are also many places that do
for i in 1 2 3 ...but I'm not sure if it's worth converting them totest_seq. That would introduce running more processes of Perl.Signed-off-by Michał Kiedrowicz <[email protected]>---
Thanks; Jeff, ack?
I have one minor nit that I am tempted to fix while queuing---see below.
Quoted 53 lines
Changes since previous version:
* Removed "This commit replaces" from commit message
* Rewordedtest_seqdescription
* Now $first and $last are passed to Perl as argumentst/perf/perf-lib.sh | 2 +- t/t5551-http-fetch.sh | 2 +- t/test-lib-functions.sh | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-)t/perf/perf-lib.sh +1
-1@@ -163,7 +163,7 @@ test_perf () { else echo "perf $test_count - $1:" fi - for i in $(seq 1 $GIT_PERF_REPEAT_COUNT); do + for i in $(test_seq 1 $GIT_PERF_REPEAT_COUNT); do say >&3 "running: $2" if test_run_perf_ "$2" thent/t5551-http-fetch.sh +1
-1@@ -114,7 +114,7 @@ test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' ( cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - for i in `seq 50000` + for i in `test_seq 50000` do echo "commit refs/heads/too-many-refs" echo "mark :$i"t/test-lib-functions.sh +8
-0@@ -530,6 +530,26 @@ test_cmp() { $GIT_TEST_CMP "$@" } +# Print a sequence of numbers or letters in increasing order. This is +# similar to GNU seq(1), but the latter might not be available +# everywhere. It may be used like: +# +# for i in `test_seq 100`; do +# for j in `test_seq 10 20`; do +# for k in `test_seq a z`; do +# echo $i-$j-$k
t/test-lib-functions.sh test_cmp() { · line 550
Quoted 10 lines
t/test-lib-functions.sh +10
-0+# done +# done +# done + +test_seq () { + test $# = 2 && { first=$1; shift; } || first=1 + test $# = 1 || + error "bug in the test script: not 1 or 2 parameters to test_seq" + last=$1 + "$PERL_PATH" -le 'print for "$ARGV[0]".."$ARGV[1]"' "$first" "$last"
I'd prefer not to have dq around $ARGV[]; is there a reason to have one around these?
Quoted 5 lines
t/test-lib-functions.sh +2
-0+} + # This function can be used to schedule some commands to be run # unconditionally at the end of the test to restore sanity: #
Jeff King
Acked-byRe: [PATCH] tests: Introduce test_seq
Quoted 22 lines · Junio C Hamano
Quoted 20 lines · Michał Kiedrowicz
Jeff King wrote:
The seq command is GNU-ism, and is missing at least in older BSD releases and their derivatives, not to mention antique commercial Unixes.
We already purged it in b3431bc (Don't use seq in tests, not everyone has it, 2007-05-02), but a few new instances have crept in. They went unnoticed because they are in scripts that are not run by default.
Replace them with
test_seqthat is implemented with a Perl snippet (proposed by Jeff). This is better than inlining this snippet everywhere it's needed because it's easier to read and it's easier to change the implementation (e.g. to C) if we ever decide to remove Perl from the test suite.Note that
test_seqis not a complete replacement for seq(1). It just has what we need now.
Quoted 8 lines
Quoted 6 lines
There are also many places that do
for i in 1 2 3 ...but I'm not sure if it's worth converting them totest_seq. That would introduce running more processes of Perl.Signed-off-by Michał Kiedrowicz <[email protected]>---
Thanks; Jeff, ack?
Yeah,
Quoted 4 lines
t/test-lib-functions.sh test_cmp() { · line 550
Quoted 1 line
t/test-lib-functions.sh +1
-0+ "$PERL_PATH" -le 'print for "$ARGV[0]".."$ARGV[1]"' "$first" "$last"I'd prefer not to have dq around $ARGV[]; is there a reason to have one around these?
I don't think they accomplish anything, and it is slightly easier to read without them. I'm fine either way.
-Peff
Re: [PATCH] tests: Introduce test_seq
In reply to Junio C HamanoQuoted 5 lines · Junio C Hamano
Wouldn't it be cleaner and readable to write it like this
"$PERL_PATH" -le 'print for $ARGV[0]..$ARGV[1]' "$1" "$2"by the way?
Yeah, that would be more robust (it's longer to type, which is why I avoided it in the inline replacement, but since we're factoring it out, that's not an issue).
-Peff
Re: [PATCH] tests: Introduce test_seq
In reply to Junio C HamanoQuoted 62 lines · Junio C Hamano
Quoted 8 lines · Jeff King
Quoted 6 lines · Michał Kiedrowicz
Jeff King wrote:
The seq command is GNU-ism, and is missing at least in older BSD releases and their derivatives, not to mention antique commercial Unixes.
Quoted 7 lines
Quoted 7 lines
We already purged it in b3431bc (Don't use seq in tests, not everyone has it, 2007-05-02), but a few new instances have crept in. They went unnoticed because they are in scripts that are not run by default.
This commit replaces them with
test_seqthat is implemented with a Perl snippet (proposed by Jeff).Just say "Replace them with
test_seq...", without "This commit".Quoted 33 lines
Fine explanation, but...
t/perf/perf-lib.sh test_perf () { · line 166
Quoted 10 lines
t/perf/perf-lib.sh +1
-1@@ -163,7 +163,7 @@ test_perf () { else echo "perf $test_count - $1:" fi - for i in $(seq 1 $GIT_PERF_REPEAT_COUNT); do + for i in $(test_seq 1 $GIT_PERF_REPEAT_COUNT); doTwo args to
test_seq, but...t/perf/perf-lib.sh test_perf () {
Quoted 13 lines
t/perf/perf-lib.sh +13
-0+# test_seq is a portable replacement for seq(1). +# It may be used like: +# +# for i in `test_seq 100`; do +# echo $i +# done + +test_seq () { + test $# = 1 || + error "bug in the test script: not 1 parameter to test_seq" + last=$1 + "$PERL_PATH" -le "print for 1..$last" +}it wants only one.
I think you would want:
Quoted 8 lines
test $# = 1 && set -- 1 "$@" "$PERL_PATH" -le "print for $1..$2"It might also be worth quoting the parameters like this:
"$PERL_PATH" -le "print for '$1'..'$2'"
so that "
test_seqa f" works, too.
Quoted 8 lines
Yeah, I like that last one, but then unlike the claim in the comment before the function definition, it is not "a portable replacement for seq(1)" at all, but something a lot more suited for our purpose. So at least the comment needs to be updated. I do not have strong opinion on calling this
test_seqwhen it acts differently from seq; it is not confusing enough to make me push something longer that is different from "seq", e.g.test_sequence.
I prefer "test_seq" because it reminds seq which helps learning how to use it. If some other seq feature is ever needed (e.g. increment value, decrementing), it may be added at any time (but I don't think so, there are only few usages after years of test suite existence).
Quoted 5 lines
Wouldn't it be cleaner and readable to write it like this
"$PERL_PATH" -le 'print for $ARGV[0]..$ARGV[1]' "$1" "$2"by the way?
Re: [PATCH] tests: Introduce test_seq
Am 04.08.2012 00:09, schrieb Michał Kiedrowicz:
Quoted 10 lines
Quoted 4 lines · Junio C Hamano
I do not have strong
opinion on calling thistest_seqwhen it acts differently from seq; it is not confusing enough to make me push something longer that is different from "seq", e.g.test_sequence.I prefer "
test_seq" because it reminds seq which helps learning how to use it. If some other seq feature is ever needed (e.g. increment value, decrementing), it may be added at any time (but I don't think so, there are only few usages after years of test suite existence).
And the reason for this is that we always told people "don't use seq" and they submitted an updated patch. What would we have to do now? We have to tell them "don't use seq, use test_seq". Therefore, the patch does not accomplish anything useful, IMO.
The function should really just be named 'seq'.
Or how about this strategy:
seq () {
unset -f seq
if ! seq 1 2 >/dev/null 2>&1
then
# don't have a working seq; provide it as a function
seq () {
insert your definition here
}
fi
seq "$@"
}but it is not my favorite.
-- Hannes
Re: [PATCH] tests: Introduce test_seq
Quoted 10 lines · Johannes Sixt
And the reason for this is that we always told people "don't use seq" and they submitted an updated patch. What would we have to do now? We have to tell them "don't use seq, use
test_seq". Therefore, the patch does not accomplish anything useful, IMO.The function should really just be named 'seq'.
Or how about this strategy:
...
but it is not my favorite.
Why not? That implementation looks like a logical and natural consequence of "should relly just be named 'seq'" suggestion.
Having said that, we already say "don't use cmp, use test_cmp", so it might not be such a big deal, even though I find the reasoning in the first paragraph I quoted above from your message quite sane and convincing to me.
PATCH 1/1 tests: Introduce test_seq
In reply to Jeff KingJeff King wrote:
The seq command is GNU-ism, and is missing at least in older BSD releases and their derivatives, not to mention antique commercial Unixes.
We already purged it in b3431bc (Don't use seq in tests, not everyone has it, 2007-05-02), but a few new instances have crept in. They went unnoticed because they are in scripts that are not run by default.
This commit replaces them with test_seq that is implemented with a Perl snippet (proposed by Jeff). This is better than inlining this snippet everywhere it's needed because it's easier to read and it's easier to change the implementation (e.g. to C) if we ever decide to remove Perl from the test suite.
Note that test_seq is not a complete replacement for seq(1). It just has what we need now.
There are also many places that do for i in 1 2 3 ... but I'm not sure if it's worth converting them to test_seq. That would introduce running more processes of Perl.
---
Previous patch didn't support test_seq 1 50 (I removed it accidentally).
t/perf/perf-lib.sh | 2 +- t/t5551-http-fetch.sh | 2 +- t/test-lib-functions.sh | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-)
t/perf/perf-lib.sh +1 -1
@@ -163,7 +163,7 @@ test_perf () { else echo "perf $test_count - $1:" fi - for i in $(seq 1 $GIT_PERF_REPEAT_COUNT); do + for i in $(test_seq 1 $GIT_PERF_REPEAT_COUNT); do say >&3 "running: $2" if test_run_perf_ "$2" then
t/t5551-http-fetch.sh +1 -1
@@ -114,7 +114,7 @@ test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' ( cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - for i in `seq 50000` + for i in `test_seq 50000` do echo "commit refs/heads/too-many-refs" echo "mark :$i"
t/test-lib-functions.sh +15 -0
@@ -530,6 +530,21 @@ test_cmp() { $GIT_TEST_CMP "$@" } +# test_seq is a portable replacement for seq(1). +# It may be used like: +# +# for i in `test_seq 100`; do +# echo $i +# done + +test_seq () { + test $# = 2 && { first=$1; shift; } || first=1 + test $# = 1 || + error "bug in the test script: not 1 or 2 parameters to test_seq" + last=$1 + "$PERL_PATH" -le "print for $first..$last" +} + # This function can be used to schedule some commands to be run # unconditionally at the end of the test to restore sanity: #
Signature · 1 line
1.7.11.rc0.212.g37218b0.dirty
Re: [PATCH] tests: Introduce test_seq
Quoted 1 line · Michał Kiedrowicz
Previous patch didn't support
test_seq 1 50(I removed it accidentally).
Our emails just crossed paths. :)
t/test-lib-functions.sh test_cmp() { · line 538
Quoted 6 lines
t/test-lib-functions.sh +6
-0+# test_seq is a portable replacement for seq(1). +# It may be used like: +# +# for i in `test_seq 100`; do +# echo $i +# done
This should probably note that it is a subset of seq's behavior. You talked about it in the commit message, but the in-code comment is a much more likely thing for a potential user to read.
-Peff
Re: [PATCH] tests: Introduce test_seq
Quoted 5 lines · Jeff King
Quoted 1 line · Michał Kiedrowicz
Previous patch didn't support
test_seq 1 50(I removed it accidentally).Our emails just crossed paths. :)
Yeah :)
Quoted 12 lines
t/test-lib-functions.sh test_cmp() { · line 538
Quoted 7 lines
t/test-lib-functions.sh +6
-0+# test_seq is a portable replacement for seq(1). +# It may be used like: +# +# for i in `test_seq 100`; do +# echo $i +# doneThis should probably note that it is a subset of seq's behavior. You talked about it in the commit message, but the in-code comment is a much more likely thing for a potential user to read.
Quoted 1 line
-Peff
OK, I'll quote parameters and add a note.
PATCH 1/1 tests: Introduce test_seq
Jeff King wrote:
The seq command is GNU-ism, and is missing at least in older BSD releases and their derivatives, not to mention antique commercial Unixes.
We already purged it in b3431bc (Don't use seq in tests, not everyone has it, 2007-05-02), but a few new instances have crept in. They went unnoticed because they are in scripts that are not run by default.
This commit replaces them with test_seq that is implemented with a Perl snippet (proposed by Jeff). This is better than inlining this snippet everywhere it's needed because it's easier to read and it's easier to change the implementation (e.g. to C) if we ever decide to remove Perl from the test suite.
Note that test_seq is not a complete replacement for seq(1). It just has what we need now.
There are also many places that do for i in 1 2 3 ... but I'm not sure if it's worth converting them to test_seq. That would introduce running more processes of Perl.
---
Changes since previous patch:
* Added quotes around arguments, allowing test_seq a z
* Improved test_seq comments
t/perf/perf-lib.sh | 2 +- t/t5551-http-fetch.sh | 2 +- t/test-lib-functions.sh | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-)
t/perf/perf-lib.sh +1 -1
@@ -163,7 +163,7 @@ test_perf () { else echo "perf $test_count - $1:" fi - for i in $(seq 1 $GIT_PERF_REPEAT_COUNT); do + for i in $(test_seq 1 $GIT_PERF_REPEAT_COUNT); do say >&3 "running: $2" if test_run_perf_ "$2" then
t/t5551-http-fetch.sh +1 -1
@@ -114,7 +114,7 @@ test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' ( cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - for i in `seq 50000` + for i in `test_seq 50000` do echo "commit refs/heads/too-many-refs" echo "mark :$i"
t/test-lib-functions.sh +19 -0
@@ -530,6 +530,25 @@ test_cmp() { $GIT_TEST_CMP "$@" } +# test_seq is a portable yet not complete replacement for seq(1). +# It may be used like: +# +# for i in `test_seq 100`; do +# for j in `test_seq 10 20`; do +# for k in `test_seq a z`; do +# echo $i-$j-$k +# done +# done +# done + +test_seq () { + test $# = 2 && { first=$1; shift; } || first=1 + test $# = 1 || + error "bug in the test script: not 1 or 2 parameters to test_seq" + last=$1 + "$PERL_PATH" -le "print for '$first'..'$last'" +} + # This function can be used to schedule some commands to be run # unconditionally at the end of the test to restore sanity: #
Signature · 1 line
1.7.11.rc0.212.g37218b0.dirty
Re: [PATCH] tests: Introduce test_seq
Quoted 9 lines · Michał Kiedrowicz
Changes since previous patch:
* Added quotes around arguments, allowing
test_seq a z
* Improvedtest_seqcommentst/perf/perf-lib.sh | 2 +- t/t5551-http-fetch.sh | 2 +- t/test-lib-functions.sh | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-)
I think this version looks OK.
-Peff
Quoted 11 lines · Jeff King
Quoted 6 lines · Michał Kiedrowicz
t/perf/perf-lib.sh test_perf () { · line 166
Quoted 2 lines · Jeff King <peff <at> peff.net> writes:
t/perf/perf-lib.sh +1
-1- for i in $(seq 1 $GIT_PERF_REPEAT_COUNT); do + for i in $("$PERL_PATH" -le "print for 1..$GIT_PERF_REPEAT_COUNT"); doMaybe you could introduce "
test_seq" instead.I don't have a strong preference, as there are only two callsites. Do you want to make a patch?
If you run "for . in . . ." in t/, we see quite a many hits, so "only two callsites" might be undercounting the candidates.
Quoted 7 lines · Junio C Hamano
Quoted 4 lines
Quoted 1 line
Maybe you could introduce "
test_seq" instead.I don't have a strong preference, as there are only two callsites. Do you want to make a patch?
If you run "for . in . . ." in t/, we see quite a many hits, so "only two callsites" might be undercounting the candidates.
True. Although a good number of them are not numeric sequences (however perl being perl, I think my one-liner would take "a" and "g" as end-points just as readily).
I have no problem with converting them all. I just didn't want to personally go to the work myself.
-Peff
When operating in --break-rewrites (-B) mode on a file with no newline terminator (and assuming --break-rewrites determines that the diff _is_ a rewrite), git diff previously concatenated the indicator comment '\ No newline at end of file' directly to the terminating line rather than on a line of its own. The resulting diff is broken; claiming that the last line actually contains the indicator text. Without -B there is no problem with the same files.
This patch fixes the former case by inserting a newline into the output prior to emitting the indicator comment.
A couple of tests have been added to the rewrite suite to confirm that the indicator comment is generated on its own line in both plain diff and rewrite mode. The latter test fails if the functional part of this patch (i.e. diff.c) is reverted.
---
Updates: Test only:
- removed redundant para from commit msg
- use test_seq shell function instead of seq
- pull prep statements into individual tests
- test expected success of git commands in prep
- confirm that rewrite is considered a rewrite by diff -B
- remove superfluous comments in favor of test descriptions
- use variable to spell 'no newline' annotation to support simpler maintenance whilst still allowing to check for unexpected leading or trailing characters.
diff.c | 1 + t/t4022-diff-rewrite.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)
diff.c +1 -0
@@ -574,6 +574,7 @@ static void emit_rewrite_lines(struct emit_callback *ecb,if (!endp) {const char *plain =diff_get_color (ecb->color_diff,DIFF_PLAIN ); +putc ('\n' , ecb->opt->file);emit_line_0 (ecb->opt, plain, reset,'\\' , nneof,strlen (nneof)); }
t/t4022-diff-rewrite.sh +1 -0
@@ -66,5 +66,47 @@ test_expect_success 'suppress deletion diff with -B -D' ' grep -v "Linus Torvalds" actual ' +test_expect_success 'generate initial "no newline at eof" sequence file and
commit' '
+
+ test_seq 1 99 >seq && + printf 100 >>seq && + git add seq && + git commit seq -m seq
+'
+
+test_expect_success 'rewrite the middle 90% of sequence file and terminate with newline' '
+
+ test_seq 1 5 >seq && + test_seq 9331 9420 >>seq && + test_seq 96 100 >>seq
+'
+
+test_expect_success 'confirm that sequence file is considered a rewrite' ' +
+ git diff -B seq >res &&
+ grep "dissimilarity index" res
+'
+
+# Full annotation string used to check for erroneous leading or +# trailing characters. Backslash is double escaped due to usage +# within dq argument to grep expansion below. +no_newline_anno='\\\\ No newline at end of file'
+
+test_expect_success 'no newline at eof is on its own line without -B' ' +
+ git diff seq >res &&
+ grep "^'"$no_newline_anno"'$" res &&
+ grep -v "^.\\+'"$no_newline_anno"'" res &&
+ grep -v "'"$no_newline_anno"'.\\+$" res
+'
+
+test_expect_success 'no newline at eof is on its own line with -B' ' +
+ git diff -B seq >res &&
+ grep "^'"$no_newline_anno"'$" res &&
+ grep -v "^.\\+'"$no_newline_anno"'" res &&
+ grep -v "'"$no_newline_anno"'.\\+$" res
+'
+
test_done
Signature · 1 line
1.7.11.msysgit.1.1.gf0affa1
Quoted 8 lines · Adam Butcher
When operating in --break-rewrites (-B) mode on a file with no newline terminator (and assuming --break-rewrites determines that the diff _is_ a rewrite), git diff previously concatenated the indicator comment '\ No newline at end of file' directly to the terminating line rather than on a line of its own. The resulting diff is broken; claiming that the last line actually contains the indicator text. Without -B there is no problem with the same files.
Quoted 8 lines
This patch fixes the former case by inserting a newline into the output prior to emitting the indicator comment.
A couple of tests have been added to the rewrite suite to confirm that the indicator comment is generated on its own line in both plain diff and rewrite mode. The latter test fails if the functional part of this patch (i.e.
diff.c) is reverted.
---
Thanks. You need your sign-off immediately before the "---" line.
When the problem description at the beginning of a log message is about the current status of the code (which is almost always the case), it generally does not need to be clarified with "previously".
A (POSIXy technical term) for the last line that does not end with the newline is "incomplete line", I think.
Cf. http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap03.html#tag_21_03_00_67
I'd describe this perhaps like so if I were doing this patch:
Fix '\ No newline...' annotation in rewrite diffs
When a file that ends with an incomplete line is expressed as a complete rewrite with the -B option, git diff incorrectly appends the incomplete line indicator "\ No newline at end of file" after such a line, rather than writing it on a line of its own (the output codepath for normal output without -B does not have this problem). Add a LF after the incomplete line before writing the "\ No newline ..." out to fix this.
Add a couple of tests to confirm that the indicator comment is generated on its own line in both plain diff and rewrite mode.
Quoted 10 lines
t/t4022-diff-rewrite.sh +1
-0@@ -66,5 +66,47 @@ test_expect_success 'suppress deletion diff with -B -D' ' grep -v "Linus Torvalds" actual ' +test_expect_success 'generate initial "no newline at eof" sequence file andcommit' '
Line-wrapped.
t/t4022-diff-rewrite.sh
Quoted 5 lines
t/t4022-diff-rewrite.sh +5
-0+test_expect_success 'confirm that sequence file is considered a rewrite' ' + + git diff -B seq >res && + grep "dissimilarity index" res +'
Good thinking to make sure the condition to trigger the issue still holds in the future.
t/t4022-diff-rewrite.sh
Quoted 9 lines
t/t4022-diff-rewrite.sh +9
-0+# Full annotation string used to check for erroneous leading or +# trailing characters. Backslash is double escaped due to usage +# within dq argument to grep expansion below. +no_newline_anno='\\\\ No newline at end of file' + +test_expect_success 'no newline at eof is on its own line without -B' ' + + git diff seq >res && + grep "^'"$no_newline_anno"'$" res &&
I think it is sufficient to write this line as:
grep "^$no_newline_anno$" res &&
The third parameter to test_expect_success function is inside a sq, so it will have the above string as-is, with $no_newline_anno not expanded, and then when the string is eval'ed, the variable is visible to the eval.
So the above should be more like:
# Full annotation string used to check for erroneous leading or # trailing characters.
no_newline_anno='\\ No newline at end of file'
test_expect_success 'no newline at eof is on its own line without -B' '
git diff seq >res &&
grep "^$no_newline_anno$" res &&
t/t4022-diff-rewrite.sh
Quoted 2 lines
t/t4022-diff-rewrite.sh +2
-0+ grep -v "^.\\+'"$no_newline_anno"'" res && + grep -v "'"$no_newline_anno"'.\\+$" res
Converting these two the same way, we would get
grep -v "^.\\+$no_newline_anno" res && grep -v "$no_newline_anno.\\+$" res
but isn't this doubly wrong?
(1) \+ to require "one-or-more", which is otherwise not supported in BRE, is a GNU extension. It is simple to fix it by writing "^..*$no_newline_anno" to say "what we try to find appears somewhere not at the beginning of line".
(2) The "grep -v" shows the lines that express all the additions and deletions prefixed with + and - as they do not match "the line has the marker misplaced in the middle of the line" criteria. Doesn't grep return true in that case, as it found some matching lines, even if you had "\ No newline" in the middle of some lines?
As I already said, I do not think hardcoding the whole "No newline at end of line" in this test is a good idea anyway, and because you know the text being compared does not have any backslash in it, it suffices to make sure that the only occurrence of a backslash is on a single line and at the beginning, I think.
In other words,
grep "^\\ " res && ! grep "^..*\\ " res
or something.
I'll tentatively queue a tweaked version on 'pu', but we would at least want a sign-off.
Thanks.
PATCH 1/1 Fix '\ No newline...' annotation in rewrite diffs
When a file that ends with an incomplete line is expressed as a complete rewrite with the -B option, git diff incorrectly appends the incomplete line indicator "\ No newline at end of file" after such a line, rather than writing it on a line of its own (the output codepath for normal output without -B does not have this problem). Add a LF after the incomplete line before writing the "\ No newline ..." out to fix this.
Add a couple of tests to confirm that the indicator comment is generated on its own line in both plain diff and rewrite mode.
---
Updates:
- replace commit msg with revised suggestion from Junio
- remove hardcoded 'No newline...' in tests and simplify
diff.c | 1 + t/t4022-diff-rewrite.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+)
diff.c +1 -0
@@ -574,6 +574,7 @@ static void emit_rewrite_lines(struct emit_callback *ecb,if (!endp) {const char *plain =diff_get_color (ecb->color_diff,DIFF_PLAIN ); +putc ('\n' , ecb->opt->file);emit_line_0 (ecb->opt, plain, reset,'\\' , nneof,strlen (nneof)); }
t/t4022-diff-rewrite.sh +33 -0
@@ -66,5 +66,38 @@ test_expect_success 'suppress deletion diff with -B -D' ' grep -v "Linus Torvalds" actual ' +test_expect_success 'generate initial "no newline at eof" sequence file and commit' ' + + test_seq 1 99 >seq && + printf 100 >>seq && + git add seq && + git commit seq -m seq +' + +test_expect_success 'rewrite the middle 90% of sequence file and terminate with newline' ' + + test_seq 1 5 >seq && + test_seq 9331 9420 >>seq && + test_seq 96 100 >>seq +' + +test_expect_success 'confirm that sequence file is considered a rewrite' ' + + git diff -B seq >res && + grep "dissimilarity index" res +' + +test_expect_success 'no newline at eof is on its own line without -B' ' + + git diff seq >res && + grep "^\\\\ " res && ! grep "^..*\\\\ " res +' + +test_expect_success 'no newline at eof is on its own line with -B' ' + + git diff -B seq >res && + grep "^\\\\ " res && ! grep "^..*\\\\ " res +' + test_done
Signature · 1 line
1.7.11.msysgit.1.1.gf0affa1
Re: [PATCH] tests: Introduce test_seq
In reply to Johannes SixtQuoted 12 lines · Johannes Sixt
Am 04.08.2012 00:09, schrieb Michał Kiedrowicz:
Quoted 10 lines
Quoted 4 lines · Junio C Hamano
I do not have strong
opinion on calling thistest_seqwhen it acts differently from seq; it is not confusing enough to make me push something longer that is different from "seq", e.g.test_sequence.I prefer "
test_seq" because it reminds seq which helps learning how to use it. If some other seq feature is ever needed (e.g. increment value, decrementing), it may be added at any time (but I don't think so, there are only few usages after years of test suite existence).
Quoted 6 lines
And the reason for this is that we always told people "don't use seq" and they submitted an updated patch. What would we have to do now? We have to tell them "don't use seq, use
test_seq". Therefore, the patch does not accomplish anything useful, IMO.The function should really just be named 'seq'.
My reasoning was that there is already test_cmp, so let's make test_seq, but I agree with you that it doesn't solve the issue completely. So my 2 cents is that it would be best to stay with not allowing seq in the test suite.
Quoted 18 lines
Or how about this strategy:
seq () { unset -f seq if ! seq 1 2 >/dev/null 2>&1 then # don't have a working seq; provide it as a function seq () { insert your definition here } fi seq "$@" }but it is not my favorite.
-- Hannes
Re: [PATCH] tests: Introduce test_seq
In reply to Johannes SixtQuoted 21 lines · Johannes Sixt
And the reason for this is that we always told people "don't use seq" and they submitted an updated patch. What would we have to do now? We have to tell them "don't use seq, use
test_seq". Therefore, the patch does not accomplish anything useful, IMO.The function should really just be named 'seq'.
Or how about this strategy:
seq () { unset -f seq if ! seq 1 2 >/dev/null 2>&1 then # don't have a working seq; provide it as a function seq () { insert your definition here } fi seq "$@" }
Quoted 1 line
but it is not my favorite.
No, falling back just makes that problem worse. Our test_seq is not fully compatible with seq. So anyone who uses an advanced feature of seq (like "seq 0 100 10" or "seq -f %02g 1 10") will have the test work on their system (with seq) and then break on some other random platform. So instead of saying "no, don't use seq, use test_seq", reviewers have to catch it and say "don't use some features of seq, because the fallback doesn't have them".
If you eliminate the fallback, then at least the reviewers do not have to catch it (the tests will never work for the patch writer, since they will always use our feature-less seq replacement). But I find it slightly confusion-inducing to call something that is not seq-compatible "seq".
-Peff