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 789aed8ff47be1ca34918b31d9693bbe94e83428
parent 6e9c787537b3a4859e460c3e753fa47305d2e1e1
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Sun, 26 Nov 2023 17:42:22 +0100

Add the push subcommand

It uses rsync to transfer data to the remote server defined in a
configuration variable. Note that this commit adds a way to override
configuration variables by defining a .git_wad.cfg file at the root of
the git working tree in which git-wad is invoked.

Diffstat:
Mgit-wad | 72+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 67 insertions(+), 5 deletions(-)

diff --git a/git-wad b/git-wad @@ -17,10 +17,20 @@ set -e -# Options -GIT_WAD_HEADER="#\$# git-wad" -GIT_WAD_OBJDIR=".git/wad" -GIT_WAD_VERBOSE=1 +# Load local config file +working_tree="$(git rev-parse --show-toplevel)" +config_file="${working_tree}/.git_wad.cfg" +if [ -f "${config_file}" ]; then + # shellcheck disable=SC1090 + . "${config_file}" +fi + +# Default options +[ -z "${GIT_WAD_HEADER}" ] && GIT_WAD_HEADER="#\$# git-wad" +[ -z "${GIT_WAD_OBJDIR}" ] && GIT_WAD_OBJDIR=".git/wad" +[ -z "${GIT_WAD_VERBOSE}" ] && GIT_WAD_VERBOSE=1 +[ -z "${GIT_WAD_REMOTE_PUSH}" ] && GIT_WAD_REMOTE_PUSH="" +[ -z "${GIT_WAD_REMOTE_FETCH}" ] && GIT_WAD_REMOTE_FETCH="${GIT_WAD_REMOTE_PUSH}" ######################################################################## # Helper functions @@ -28,6 +38,7 @@ GIT_WAD_VERBOSE=1 synopsis() { >&2 printf "usage: git-wad init\n" + >&2 printf " git-wad push [--all]\n" } log() # str [, arg...] @@ -111,6 +122,39 @@ smudge() # stdin fi } +wad_objects() # [--all] +{ + rev="HEAD" + + if [ $# -ge 1 ]; then + case "$1" in + "--all") rev="--all" ;; + *) + >&2 log "Invalid option %s\n" "$1" + return 1 + ;; + esac + fi + + # The following command line can be translated as follows: + # Print the IDs of all objects in "${rev}" (i.e. HEAD or --all) + # | Get their hash + # | Print object information of these hashes + # | Keep only objects that are blobs + # | Get their hash + # | Print information _and_ contents of these hashes + # | Keep only the contents of objects corresponding to WAD files + # | And finally, extract the corresponding WAD object digest + git rev-list --objects "${rev}" \ + | cut -d' ' -f1 \ + | git cat-file --batch-check \ + | grep -e "[a-z0-9]\{40\} blob [0-9]\{1,\}" \ + | cut -d' ' -f1 \ + | git cat-file --batch \ + | grep -e "^${GIT_WAD_HEADER} [0-9a-z]\{64\} [0-9]\{1,\}$" \ + | sed "s/^${GIT_WAD_HEADER} \([0-9a-z]\{64\}\) [0-9]\{1,\}$/\1/" +} + ######################################################################## # Sub commands ######################################################################## @@ -126,6 +170,23 @@ init() fi } +push() # [--all] +{ + if [ -z "${GIT_WAD_REMOTE_PUSH}" ]; then + log "Remote undefined, i.e. variable GIT_WAD_REMOTE_PUSH is empty\n" + return 1 + fi + + wad_objects "$@" | while read -r i; do + object="${GIT_WAD_OBJDIR}/${i}" + if [ -f "${object}" ]; then + rsync -av --progress --ignore-existing "${object}" \ + "${GIT_WAD_REMOTE_PUSH}" + fi + done + log "Pushed to %s\n" "${GIT_WAD_REMOTE_PUSH}" +} + ######################################################################## # The command ######################################################################## @@ -138,6 +199,7 @@ fi case "${sub_cmd}" in "filter-clean") shift 1; clean "$@" ;; "filter-smudge") shift 1; smudge "$@" ;; - "init") shift 1; init ;; + "init") shift 1; init "$@" ;; + "push") shift 1; push "$@" ;; *) synopsis; exit 1 ;; esac