@matheusbsbs / matheus-bagliano / commits / 40a7ce64e1
Fork 0

tr portability fixes

Specifying character ranges in tr differs between System V and POSIX. In System V, brackets are required (e.g., '[A-Z]'), whereas in POSIX they are not. We can mostly get around this by just using the bracket form for both sets, as in: tr '[A-Z] '[a-z]' in which case POSIX interpets this as "'[' becomes '['", which is OK. However, this doesn't work with multiple sequences, like: # rot13 tr '[A-Z][a-z]' '[N-Z][A-M][n-z][a-m]' where the POSIX version does not behave the same as the System V version. In this case, we must simply enumerate the sequence. This patch fixes problematic uses of tr in git scripts and test scripts in one of three ways: - if a single sequence, make sure it uses brackets - if multiple sequences, enumerate - if extra brackets (e.g., tr '[A]' 'a'), eliminate brackets Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 12, 2008 at 17:29 UTC 40a7ce64e146c79a966a8494d3a7e85826d7f4e9
4 files changed +9 -6
git-bisect.sh
+2 -2
@@ -293,14 +293,14 @@ bisect_next() {
293 bisect_next_check good
294
295 skip=$(git for-each-ref --format='%(objectname)' \
296 - "refs/bisect/skip-*" | tr '[\012]' ' ') || exit
296 + "refs/bisect/skip-*" | tr '\012' ' ') || exit
297
298 BISECT_OPT=''
299 test -n "$skip" && BISECT_OPT='--bisect-all'
300
301 bad=$(git rev-parse --verify refs/bisect/bad) &&
302 good=$(git for-each-ref --format='^%(objectname)' \
303 - "refs/bisect/good-*" | tr '[\012]' ' ') &&
303 + "refs/bisect/good-*" | tr '\012' ' ') &&
304 eval="git rev-list --bisect-vars $BISECT_OPT $good $bad --" &&
305 eval="$eval $(cat "$GIT_DIR/BISECT_NAMES")" &&
306 eval=$(filter_skipped "$eval" "$skip") &&
git-filter-branch.sh
+2 -2
@@ -58,8 +58,8 @@ eval "$functions"
58 # "author" or "committer
59
60 set_ident () {
61 - lid="$(echo "$1" | tr "A-Z" "a-z")"
62 - uid="$(echo "$1" | tr "a-z" "A-Z")"
61 + lid="$(echo "$1" | tr "[A-Z]" "[a-z]")"
62 + uid="$(echo "$1" | tr "[a-z]" "[A-Z]")"
63 pick_id_script='
64 /^'$lid' /{
65 s/'\''/'\''\\'\'\''/g
t/t4022-diff-rewrite.sh
+4 -1
@@ -8,7 +8,10 @@ test_expect_success setup '
8
9 cat ../../COPYING >test &&
10 git add test &&
11 - tr 'a-zA-Z' 'n-za-mN-ZA-M' <../../COPYING >test
11 + tr \
12 + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \
13 + "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \
14 + <../../COPYING >test
15
16 '
17
t/t7003-filter-branch.sh
+1 -1
@@ -4,7 +4,7 @@ test_description='git-filter-branch'
4 . ./test-lib.sh
5
6 make_commit () {
7 - lower=$(echo $1 | tr A-Z a-z)
7 + lower=$(echo $1 | tr '[A-Z]' '[a-z]')
8 echo $lower > $lower
9 git add $lower
10 test_tick