Merge branch 'ab/portable-more'
authorJunio C Hamano <gitster@pobox.com>
Tue, 4 Sep 2018 21:31:40 +0000 (14:31 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 4 Sep 2018 21:31:40 +0000 (14:31 -0700)
Portability fix.

* ab/portable-more:
tests: fix non-portable iconv invocation
tests: fix non-portable "${var:-"str"}" construct
tests: fix and add lint for non-portable grep --file
tests: fix version-specific portability issue in Perl JSON
tests: use shorter labels in chainlint.sed for AIX sed
tests: fix comment syntax in chainlint.sed for AIX sed
tests: fix and add lint for non-portable seq
tests: fix and add lint for non-portable head -c N

t/chainlint.sed
t/check-non-portable-shell.pl
t/t0019/parse_json.perl
t/t0028-working-tree-encoding.sh
t/t4013-diff-various.sh
t/t5310-pack-bitmaps.sh
t/t5318-commit-graph.sh
t/t5552-skipping-fetch-negotiator.sh
t/t5703-upload-pack-ref-in-want.sh
t/test-lib.sh
index 8544df38dfc0c557120a8a250529147edbc3d2a4..c80d2fad7a85e2bf6f59b5a5acd80be5f688cb90 100644 (file)
 /<<[   ]*[-\\']*[A-Za-z0-9_]/ {
        s/^\(.*\)<<[    ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
        s/[     ]*<<//
-       :hereslurp
+       :hered
        N
        /^<\([^>]*\)>.*\n[      ]*\1[   ]*$/!{
                s/\n.*$//
-               bhereslurp
+               bhered
        }
        s/^<[^>]*>//
        s/\n.*$//
@@ -131,9 +131,8 @@ b
 b
 
 :subshell
-# bare "(" line?
+# bare "(" line? -- stash for later printing
 /^[    ]*([    ]*$/ {
-       # stash for later printing
        h
        bnextline
 }
@@ -150,7 +149,7 @@ s/.*\n//
 
 :slurp
 # incomplete line "...\"
-/\\$/bincomplete
+/\\$/bicmplte
 # multi-line quoted string "...\n..."?
 /"/bdqstring
 # multi-line quoted string '...\n...'? (but not contraction in string "it's")
@@ -172,7 +171,7 @@ s/.*\n//
        /"[^"]*#[^"]*"/!s/[     ]#.*$//
 }
 # one-liner "case ... esac"
-/^[    ]*case[         ]*..*esac/bcheckchain
+/^[    ]*case[         ]*..*esac/bchkchn
 # multi-line "case ... esac"
 /^[    ]*case[         ]..*[   ]in/bcase
 # multi-line "for ... done" or "while ... done"
@@ -201,32 +200,32 @@ s/.*\n//
 /^[    ]*fi[   ]*[<>|]/bdone
 /^[    ]*fi[   ]*)/bdone
 # nested one-liner "(...) &&"
-/^[    ]*(.*)[         ]*&&[   ]*$/bcheckchain
+/^[    ]*(.*)[         ]*&&[   ]*$/bchkchn
 # nested one-liner "(...)"
-/^[    ]*(.*)[         ]*$/bcheckchain
+/^[    ]*(.*)[         ]*$/bchkchn
 # nested one-liner "(...) >x" (or "2>x" or "<x" or "|x")
-/^[    ]*(.*)[         ]*[0-9]*[<>|]/bcheckchain
+/^[    ]*(.*)[         ]*[0-9]*[<>|]/bchkchn
 # nested multi-line "(...\n...)"
 /^[    ]*(/bnest
 # multi-line "{...\n...}"
 /^[    ]*{/bblock
 # closing ")" on own line -- exit subshell
-/^[    ]*)/bclosesolo
+/^[    ]*)/bclssolo
 # "$((...))" -- arithmetic expansion; not closing ")"
-/\$(([^)][^)]*))[^)]*$/bcheckchain
+/\$(([^)][^)]*))[^)]*$/bchkchn
 # "$(...)" -- command substitution; not closing ")"
-/\$([^)][^)]*)[^)]*$/bcheckchain
+/\$([^)][^)]*)[^)]*$/bchkchn
 # multi-line "$(...\n...)" -- command substitution; treat as nested subshell
 /\$([^)]*$/bnest
 # "=(...)" -- Bash array assignment; not closing ")"
-/=(/bcheckchain
+/=(/bchkchn
 # closing "...) &&"
 /)[    ]*&&[   ]*$/bclose
 # closing "...)"
 /)[    ]*$/bclose
 # closing "...) >x" (or "2>x" or "<x" or "|x")
 /)[    ]*[<>|]/bclose
-:checkchain
+:chkchn
 # mark suspect if line uses ";" internally rather than "&&" (but not ";" in a
 # string and not ";;" in one-liner "case...esac")
 /;/{
@@ -245,7 +244,7 @@ n
 bslurp
 
 # found incomplete line "...\" -- slurp up next line
-:incomplete
+:icmplte
 N
 s/\\\n//
 bslurp
@@ -283,11 +282,11 @@ bfolded
 :heredoc
 s/^\(.*\)<<[   ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
 s/[    ]*<<//
-:hereslurpsub
+:heredsub
 N
 /^<\([^>]*\)>.*\n[     ]*\1[   ]*$/!{
        s/\n.*$//
-       bhereslurpsub
+       bheredsub
 }
 s/^<[^>]*>//
 s/\n.*$//
@@ -317,43 +316,43 @@ x
 # is 'done' or 'fi' cuddled with ")" to close subshell?
 /done.*)/bclose
 /fi.*)/bclose
-bcheckchain
+bchkchn
 
 # found nested multi-line "(...\n...)" -- pass through untouched
 :nest
 x
-:nestslurp
+:nstslurp
 n
 # closing ")" on own line -- stop nested slurp
-/^[    ]*)/bnestclose
+/^[    ]*)/bnstclose
 # comment -- not closing ")" if in comment
-/^[    ]*#/bnestcontinue
+/^[    ]*#/bnstcnt
 # "$((...))" -- arithmetic expansion; not closing ")"
-/\$(([^)][^)]*))[^)]*$/bnestcontinue
+/\$(([^)][^)]*))[^)]*$/bnstcnt
 # "$(...)" -- command substitution; not closing ")"
-/\$([^)][^)]*)[^)]*$/bnestcontinue
+/\$([^)][^)]*)[^)]*$/bnstcnt
 # closing "...)" -- stop nested slurp
-/)/bnestclose
-:nestcontinue
+/)/bnstclose
+:nstcnt
 x
-bnestslurp
-:nestclose
+bnstslurp
+:nstclose
 s/^/>>/
 # is it "))" which closes nested and parent subshells?
 /)[    ]*)/bslurp
-bcheckchain
+bchkchn
 
 # found multi-line "{...\n...}" block -- pass through untouched
 :block
 x
 n
 # closing "}" -- stop block slurp
-/}/bcheckchain
+/}/bchkchn
 bblock
 
 # found closing ")" on own line -- drop "suspect" from final line of subshell
 # since that line legitimately lacks "&&" and exit subshell loop
-:closesolo
+:clssolo
 x
 s/?!AMP?!//
 p
index d5823f71d8d57ec92404d5cceabd86d5ab86af53..b45bdac688c40104dd42ef68a07690420d96c142 100755 (executable)
@@ -41,6 +41,9 @@ sub err {
        /^\s*[^#]\s*which\s/ and err 'which is not portable (use type)';
        /\btest\s+[^=]*==/ and err '"test a == b" is not portable (use =)';
        /\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable (use test_line_count)';
+       /\bhead\s+-c\b/ and err 'head -c is not portable (use test_copy_bytes BYTES <file >out)';
+       /(?:\$\(seq|^\s*seq\b)/ and err 'seq is not portable (use test_seq)';
+       /\bgrep\b.*--file\b/ and err 'grep --file FILE is not portable (use grep -f FILE)';
        /\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (use FOO=bar && export FOO)';
        /^\s*([A-Z0-9_]+=(\w+|(["']).*?\3)\s+)+(\w+)/ and exists($func{$4}) and
                err '"FOO=bar shell_func" assignment extends beyond "shell_func"';
index ca4e5bfa7850ee5bc783cec7c0d18b8d76d66883..fea87fb81b62d4f1e9612094c60ee8dceebc07be 100644 (file)
@@ -34,6 +34,9 @@ sub dump_item {
     } elsif (ref($value) eq 'HASH') {
        print "$label_in hash\n";
        dump_hash($label_in, $value);
+    } elsif (ref $value) {
+       my $bool = $value ? 1 : 0;
+       print "$label_in $bool\n";
     } elsif (defined $value) {
        print "$label_in $value\n";
     } else {
index 12b8eb963a525e4083f96b7d9edc28858d90a1e7..7e87b5a200a3f6483ea2e243fa0c497205ce4e61 100755 (executable)
@@ -203,7 +203,11 @@ test_expect_success 'error if encoding garbage is already in Git' '
        test_i18ngrep "error: BOM is required" err.out
 '
 
-test_expect_success 'check roundtrip encoding' '
+test_lazy_prereq ICONV_SHIFT_JIS '
+       iconv -f UTF-8 -t SHIFT-JIS </dev/null
+'
+
+test_expect_success ICONV_SHIFT_JIS 'check roundtrip encoding' '
        test_when_finished "rm -f roundtrip.shift roundtrip.utf16" &&
        test_when_finished "git reset --hard HEAD" &&
 
index f8d853595b99bfff64521a502ee062b7e5f35e5f..73f7038253d6429f9d05c38f36c226107b5251ff 100755 (executable)
@@ -140,7 +140,7 @@ do
        expect="$TEST_DIRECTORY/t4013/diff.$test"
        actual="$pfx-diff.$test"
 
-       test_expect_success "git $cmd # magic is ${magic:-"(not used)"}" '
+       test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
                {
                        echo "$ git $cmd"
                        case "$magic" in
index 557bd0d0c09e370515acb7fc75391f0a7d62d73e..7bff7923f2a91165b5a0b5251351798519d63270 100755 (executable)
@@ -335,7 +335,7 @@ test_expect_success 'truncated bitmap fails gracefully' '
        git rev-list --use-bitmap-index --count --all >expect &&
        bitmap=$(ls .git/objects/pack/*.bitmap) &&
        test_when_finished "rm -f $bitmap" &&
-       head -c 512 <$bitmap >$bitmap.tmp &&
+       test_copy_bytes 512 <$bitmap >$bitmap.tmp &&
        mv -f $bitmap.tmp $bitmap &&
        git rev-list --use-bitmap-index --count --all >actual 2>stderr &&
        test_cmp expect actual &&
index 3c1ffad49144d177a56f2f6a0b26612899e25adb..0c500f7ca2641a2752f5d4819bb11efcf5f588bf 100755 (executable)
@@ -134,7 +134,7 @@ test_expect_success 'Add one more commit' '
        git branch commits/8 &&
        ls $objdir/pack | grep idx >existing-idx &&
        git repack &&
-       ls $objdir/pack| grep idx | grep -v --file=existing-idx >new-idx
+       ls $objdir/pack| grep idx | grep -v -existing-idx >new-idx
 '
 
 # Current graph structure:
index 5ad5bece55620138ce76579abb6e76c0710d126d..30857b84a8d5b5fdec59f775ab97293a7da4f2df 100755 (executable)
@@ -46,7 +46,7 @@ test_expect_success 'commits with no parents are sent regardless of skip distanc
        test_commit -C server to_fetch &&
 
        git init client &&
-       for i in $(seq 7)
+       for i in $(test_seq 7)
        do
                test_commit -C client c$i
        done &&
@@ -89,7 +89,7 @@ test_expect_success 'when two skips collide, favor the larger one' '
        test_commit -C server to_fetch &&
 
        git init client &&
-       for i in $(seq 11)
+       for i in $(test_seq 11)
        do
                test_commit -C client c$i
        done &&
@@ -168,14 +168,14 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC
        test_commit -C server to_fetch &&
 
        git init client &&
-       for i in $(seq 8)
+       for i in $(test_seq 8)
        do
                git -C client checkout --orphan b$i &&
                test_commit -C client b$i.c0
        done &&
-       for j in $(seq 19)
+       for j in $(test_seq 19)
        do
-               for i in $(seq 8)
+               for i in $(test_seq 8)
                do
                        git -C client checkout b$i &&
                        test_commit -C client b$i.c$j
@@ -205,7 +205,7 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC
 
        # fetch-pack should thus not send any more commits in the b1 branch, but
        # should still send the others (in this test, just check b2).
-       for i in $(seq 0 8)
+       for i in $(test_seq 0 8)
        do
                have_not_sent b1.c$i
        done &&
index a73c55a47eeedd82a1ac1201348a02a9bd3b43fd..d1ccc22331338b016646de6af5f15387b3119665 100755 (executable)
@@ -176,7 +176,7 @@ test_expect_success 'setup repos for change-while-negotiating test' '
                git clone "http://127.0.0.1:$LIB_HTTPD_PORT/smart/repo" "$LOCAL_PRISTINE" &&
                cd "$LOCAL_PRISTINE" &&
                git checkout -b side &&
-               for i in $(seq 1 33); do test_commit s$i; done &&
+               for i in $(test_seq 1 33); do test_commit s$i; done &&
 
                # Add novel commits to upstream
                git checkout master &&
@@ -289,7 +289,7 @@ test_expect_success 'setup repos for fetching with ref-in-want tests' '
                git clone "file://$REPO" "$LOCAL_PRISTINE" &&
                cd "$LOCAL_PRISTINE" &&
                git checkout -b side &&
-               for i in $(seq 1 33); do test_commit s$i; done &&
+               for i in $(test_seq 1 33); do test_commit s$i; done &&
 
                # Add novel commits to upstream
                git checkout master &&
index 8bb0f4348e94037ab8877fdb0389bde5a11a86e3..44288cbb598435a5dfff05e8e895cca85e53e804 100644 (file)
@@ -867,7 +867,7 @@ then
                # handle only executables, unless they are shell libraries that
                # need to be in the exec-path.
                test -x "$1" ||
-               test "# " = "$(head -c 2 <"$1")" ||
+               test "# " = "$(test_copy_bytes 2 <"$1")" ||
                return;
 
                base=$(basename "$1")
@@ -882,7 +882,7 @@ then
                # do not override scripts
                if test -x "$symlink_target" &&
                    test ! -d "$symlink_target" &&
-                   test "#!" != "$(head -c 2 < "$symlink_target")"
+                   test "#!" != "$(test_copy_bytes 2 <"$symlink_target")"
                then
                        symlink_target=../valgrind.sh
                fi