commit 0e64d3696e7b202ecca1c766a1183daac1145849
parent 443324e078a2319afbaef6151e7d3463a5ca2dd2
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 5 Feb 2025 14:50:17 +0100
Force default character type when using tr
Avoid the illegal byte sequence problem reported by some tr
implementations when using system locale settings.
Diffstat:
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/git-wad b/git-wad
@@ -33,10 +33,11 @@ if [ "${is_inside_git_dir}" = "true" ]; then
exit 1
fi
-# Force default locale when using sed, i.e. treat all characters as
-# individual bytes. Otherwise, some sed implementations return
-# multi-byte encoding errors.
+# Force default locale when using sed and tr, i.e. treat all characters
+# as individual bytes. Otherwise, some implementations return multi-byte
+# encoding errors.
alias sed__='LC_CTYPE=C sed'
+alias tr__='LC_CTYPE=C tr'
# Check checksum command support
if ! command -v sha256sum 1> /dev/null 2>&1 \
@@ -151,7 +152,7 @@ wad_paths()
# | Sort the result in ascending order
# | Print path for WAD files only
git ls-tree -r HEAD "${working_tree}" \
- | tr ' ' ' ' \
+ | tr__ ' ' ' ' \
| cut -d' ' -f3,4 \
| sort -b \
| join -o 2.2 "${hashes}" -
@@ -381,7 +382,7 @@ clean() # stdin
# in the following.
header_size="$(sizeof_header)"
header="$(dd ibs=1 count="${header_size}" if="${tmpclean}" 2>/dev/null\
- | tr '\0' '0')"
+ | tr__ '\0' '0')"
# Do not clean input stream if it is an un-smudged WAD
if [ "${header}" = "${GIT_WAD_HEADER}" ]; then
@@ -408,7 +409,7 @@ clean() # stdin
smudge() # stdin
{
header_size="$(sizeof_header)"
- header="$(dd ibs=1 count="${header_size}" 2> /dev/null | tr '\0' '0')"
+ header="$(dd ibs=1 count="${header_size}" 2> /dev/null | tr__ '\0' '0')"
if [ "${header}" != "${GIT_WAD_HEADER}" ]; then # It is not a WAD
log "git-wad:filter-smudge: not a managed file"
@@ -612,7 +613,7 @@ status() # [-1a]
# Read the WAD bytes corresponding to its header before it is restored
header_size="$(sizeof_header)"
header="$(dd if="${wad}" ibs=1 count="${header_size}" 2> /dev/null \
- | tr '\0' '0')"
+ | tr__ '\0' '0')"
# The header read is not a valid WAD header, i.e. the WAD has
# already been restored