git-wad

Manage files via git but not their content
git clone git://git.meso-star.fr/git-wad.git
Log | Files | Refs | README | LICENSE

commit a9dbcb373c61451ff85af5672bf4621f9cf461e8
parent f8d1a1a287194e97a95e4c8cd4feb475c67d4c0e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Sun, 12 Jan 2025 15:14:42 +0100

Force default character type when using sed

Avoid the illegal byte sequence problem reported by some sed
implementations when using system locale settings.

Diffstat:
Mgit-wad | 21+++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/git-wad b/git-wad @@ -30,6 +30,11 @@ if [ "${is_inside_git_dir}" = "true" ]; then die fi +# Force default locale when using sed, i.e. treat all characters as +# individual bytes. Otherwise, some sed implementations return +# multi-byte encoding errors. +alias sed__='LC_CTYPE=C sed' + # shellcheck disable=SC2310 working_tree="$(git rev-parse --show-toplevel)" || die "$?" git_wad_tmpdir="$(mktemp -d "${TMPDIR:-/tmp}/git_wad_XXXXXX")" || die "$?" @@ -104,9 +109,9 @@ wad_hashes() git rev-list --objects HEAD -1 \ | cut -d' ' -f1 \ | git cat-file --batch-check \ - | sed -n 's/\(^[a-z0-9]\{40\}\) blob [0-9]\{1,\}$/\1/p' \ + | sed__ -n 's/\(^[a-z0-9]\{40\}\) blob [0-9]\{1,\}$/\1/p' \ | git cat-file --batch='%(objectname)' \ - | sed -n "/^[0-9a-z]\{40\}$/{N;s/^\([0-9a-z]\{40\}\)\n${wad_re}$/\1/p}" + | sed__ -n "/^[0-9a-z]\{40\}$/{N;s/^\([0-9a-z]\{40\}\)\n${wad_re}$/\1/p}" } # List paths of WAD file from the current commit @@ -156,16 +161,16 @@ wad_objects() # [-1a] git rev-list --objects ${rev} \ | cut -d' ' -f1 \ | git cat-file --batch-check \ - | sed -n 's/\(^[a-z0-9]\{40\}\) blob [0-9]\{1,\}$/\1/p' \ + | sed__ -n 's/\(^[a-z0-9]\{40\}\) blob [0-9]\{1,\}$/\1/p' \ | git cat-file --batch \ - | sed -n "s/^${GIT_WAD_HEADER} \([0-9a-z]\{64\}\) [0-9]\{1,\}$/\1/p" + | sed__ -n "s/^${GIT_WAD_HEADER} \([0-9a-z]\{64\}\) [0-9]\{1,\}$/\1/p" } # List WAD objects staged for the next commit wad_objects_staged() { git diff --cached \ - | sed -n "s/^+${GIT_WAD_HEADER} \([0-9a-z]\{64\}\) [0-9]\{1,\}$/\1/p" + | sed__ -n "s/^+${GIT_WAD_HEADER} \([0-9a-z]\{64\}\) [0-9]\{1,\}$/\1/p" } # List all stored WAD objects of the working tree. These may be WAD @@ -230,7 +235,7 @@ next_timestamp() restore() # WAD file { wad="$1" - digest=$(sed "s/^${GIT_WAD_HEADER} \([0-9a-z]\{64\}\) [0-9]\{1,\}$/\1/" "${wad}") + digest=$(sed__ "s/^${GIT_WAD_HEADER} \([0-9a-z]\{64\}\) [0-9]\{1,\}$/\1/" "${wad}") if [ -z "${digest}" ]; then >&2 printf "Invalid WAD file %s\n" "$1" @@ -319,7 +324,7 @@ smudge() # stdin else # It is a WAD # The sed directive remove the space before the digest - digest_size="$(cat - | sed "1s/^ //")" + digest_size="$(cat - | sed__ "1s/^ //")" digest="$(echo "${digest_size}" | cut -d' ' -f1)" size="$(echo "${digest_size}" | cut -d' ' -f2)" @@ -496,7 +501,7 @@ status() # [-1a] else # Read the WAD digest from its header - digest=$(sed \ + digest=$(sed__ \ -e "1s/^${GIT_WAD_HEADER} \([0-9a-z]\{64\}\) [0-9]\{1,\}$/\1/" \ "${wad}")