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 7e6d4172a68c3e02af6772be46933cdc6215ac4d
parent 343d353a3713b48bd56eaa382ab96b1be309a265
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  2 Oct 2024 12:02:21 +0200

Improving portability

Do not use git subcommand options that are too recent. Ensure that all
git commands used are available at least on git 2.1.4, i.e. the version
of git under which this commit was tested.

Do not use the strftime function in an awk program, which is not a POSIX
awk function but a GNU awk extension.

Diffstat:
Mgit-wad | 50++++++++++++++++++++++++++++++++++----------------
1 file changed, 34 insertions(+), 16 deletions(-)

diff --git a/git-wad b/git-wad @@ -40,11 +40,14 @@ GIT_WAD_VERBOSE="${GIT_WAD_VERBOSE:-0}" if [ -z "${GIT_WAD_REMOTE_FETCH}" ] \ && git remote | grep -qe "^origin$"; then - GIT_WAD_REMOTE_FETCH="$(git remote get-url origin)" + GIT_WAD_REMOTE_FETCH="$(git config remote.origin.url || true)" fi if [ -z "${GIT_WAD_REMOTE_PUSH}" ] \ && git remote | grep -qe "^origin$"; then - GIT_WAD_REMOTE_PUSH="$(git remote get-url --push origin)" + GIT_WAD_REMOTE_PUSH="$(git config remote.origin.pushurl || true)" + if [ -z "${GIT_WAD_REMOTE_PUSH}" ]; then + GIT_WAD_REMOTE_PUSH="${GIT_WAD_REMOTE_FETCH}" + fi fi ######################################################################## @@ -84,12 +87,18 @@ wad_hashes() wad_re="${GIT_WAD_HEADER} [0-9a-z]\{64\} [0-9]\{1,\}" # The following command line can be translated as follows: - # Print the hash (aka objectname) of all blobs in HEAD + # Print the IDs of all objects in HEAD + # | Get their hash + # | Print object information of these hashes + # | Keep only the hash of objects that are blobs # | Print blob content preceeded by its hash # | Print the blob hash if the following line indicates a WAD - git rev-list --objects --no-object-names --filter=object:type=blob HEAD -1 \ - | git cat-file --batch='%(objectname)' \ - | sed -n "/^[0-9a-z]\{40\}$/{N;s/^\([0-9a-z]\{40\}\)\n${wad_re}$/\1/p}" + 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' \ + | git cat-file --batch='%(objectname)' \ + | 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 @@ -99,10 +108,14 @@ wad_paths() hashes="${git_wad_tmpdir}/hashes" wad_hashes | sort -b > "${hashes}" - # Lists the current tree, printing the hash and path of its files + # Lists the current tree + # | Replace tabs by spaces (see git-ls-tree(1) for output format) + # | Print only the hash and path of listed files # | Sort the result in ascending order # | Print path for WAD files only - git ls-tree -r --format="%(objectname) %(path)" HEAD "${working_tree}" \ + git ls-tree -r HEAD "${working_tree}" \ + | tr ' ' ' ' \ + | cut -d' ' -f3,4 \ | sort -b \ | join -o 2.2 "${hashes}" - } @@ -125,13 +138,19 @@ wad_objects() # [-1a] done # The following command line can be translated as follows: - # Print the hash (aka objectname) of all blobs in HEAD - # | Print blob content - # | Extract and print only the digest of WAD objects + # Print the IDs of all objects in "${rev}" (i.e. HEAD or --all) + # | Get their hash + # | Print object information of these hashes + # | Keep only the hash of objects that are blobs + # | Print information _and_ contents of these hashes + # | Finally print digest of WAD object # shellcheck disable=SC2086 # ${rev} can have several arguments - git rev-list --objects --no-object-names --filter=object:type=blob ${rev} \ - | git cat-file --batch \ - | sed -n "s/^${GIT_WAD_HEADER} \([0-9a-z]\{64\}\) [0-9]\{1,\}$/\1/p" + 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' \ + | git cat-file --batch \ + | sed -n "s/^${GIT_WAD_HEADER} \([0-9a-z]\{64\}\) [0-9]\{1,\}$/\1/p" } # List WAD objects staged for the next commit @@ -197,8 +216,7 @@ next_timestamp() awk 'BEGIN { srand(); # Use the current epoch as seed epoch = srand() + 1; # Return the current seed + 1, i.e. "epoch + 1" - print strftime("%Y-%m-%dT%H:%M:%S", epoch); - }' + }' | date +%Y-%m-%dT%H:%M:%S } restore() # WAD file