diff options
author | Jeff King <peff@peff.net> | 2008-03-12 17:29:57 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-03-12 21:10:00 -0700 |
commit | 40a7ce64e146c79a966a8494d3a7e85826d7f4e9 (patch) | |
tree | 3349632b86ba74d796700a57a8bae16386ebbfc2 /t | |
parent | Merge git://repo.or.cz/git-gui (diff) | |
download | tgif-40a7ce64e146c79a966a8494d3a7e85826d7f4e9.tar.xz |
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>
Diffstat (limited to 't')
-rwxr-xr-x | t/t4022-diff-rewrite.sh | 5 | ||||
-rwxr-xr-x | t/t7003-filter-branch.sh | 2 |
2 files changed, 5 insertions, 2 deletions
diff --git a/t/t4022-diff-rewrite.sh b/t/t4022-diff-rewrite.sh index 6de4acbd44..bf996fc414 100755 --- a/t/t4022-diff-rewrite.sh +++ b/t/t4022-diff-rewrite.sh @@ -8,7 +8,10 @@ test_expect_success setup ' cat ../../COPYING >test && git add test && - tr 'a-zA-Z' 'n-za-mN-ZA-M' <../../COPYING >test + tr \ + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \ + "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \ + <../../COPYING >test ' diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh index 6e14bf1c7f..553131fcf4 100755 --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@ -4,7 +4,7 @@ test_description='git-filter-branch' . ./test-lib.sh make_commit () { - lower=$(echo $1 | tr A-Z a-z) + lower=$(echo $1 | tr '[A-Z]' '[a-z]') echo $lower > $lower git add $lower test_tick |