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 1eba321eed72044bc7bf444b9c7ac04ec7ba8417
parent 93f7b916ace0efd549b6ba338a54211e6ec08bc5
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Sun,  3 Mar 2024 09:41:16 +0100

Update subcommand options

Adds the '-1' option to almost all sub-commands, i.e. sub-commands
working on the working tree and not on individual commits. This option
limits the number of commits to be considered to one; in other words,
only the current HEAD is taken into account. This limits the data to be
transferred to the WAD objects of the current commit.

This option prevents the use of the --all option which, on the contrary,
takes into account all references, i.e. all commits in all branches.
This --all option has also been renamed to -a, not only to standardize
the synthax of the options, but also to respect the convention defined
by the syntax guidelines of POSIX utilities and thus enable use of the
getopt utility.

Diffstat:
Mgit-wad | 71+++++++++++++++++++++++++++++------------------------------------------
1 file changed, 29 insertions(+), 42 deletions(-)

diff --git a/git-wad b/git-wad @@ -38,12 +38,12 @@ fi synopsis() { >&2 printf "usage: git-wad checkout\n" - >&2 printf " git-wad fetch [--all]\n" + >&2 printf " git-wad fetch [-1a]\n" >&2 printf " git-wad init\n" - >&2 printf " git-wad prune [--all]\n" - >&2 printf " git-wad pull [--all]\n" - >&2 printf " git-wad push [--all]\n" - >&2 printf " git-wad status [--all]\n" + >&2 printf " git-wad prune [-1a]\n" + >&2 printf " git-wad pull [-1a]\n" + >&2 printf " git-wad push [-1a\n" + >&2 printf " git-wad status [-1a]\n" } is_init() @@ -70,24 +70,9 @@ encode() # digest, size printf "%s %s %d" "${GIT_WAD_HEADER}" "$1" "$2" } -# List hashes of WAD file from the current working tree -# shellcheck disable=SC2120 # $1 is optional -wad_hashes() # [--all] +# List hashes of WAD file from the current HEAD +wad_hashes() { - - rev="HEAD" - - if [ $# -ge 1 ]; then - case "$1" in - "--all") rev="--all" ;; - *) - # shellsheck disable=SC2120 - >&2 log "Invalid option %s\n" "$1" - return 1 - ;; - esac - fi - # Regular expression of a WAD wad_re="^${GIT_WAD_HEADER} [0-9a-z]\{64\} [0-9]\{1,\}$" @@ -98,7 +83,7 @@ wad_hashes() # [--all] # | Keep only objects that are blobs # | Get their hash # | Keep only the hash of blob objects that are WADs - git rev-list --objects "${rev}" \ + git rev-list --objects HEAD -1 \ | cut -d' ' -f1 \ | git cat-file --batch-check \ | sed -n "/[a-z0-9]\{40\} blob [0-9]\{1,\}/p" \ @@ -108,7 +93,7 @@ wad_hashes() # [--all] | sed -e '/${wad_re}/!d' -e 's/^.\{1,\}$/{}\n/'" } -# List paths of WAD file from the current working tree +# List paths of WAD file from the current commit wad_paths() { # Store the hash of WAD file @@ -126,19 +111,20 @@ wad_paths() } # List WAD objects from the current working tree -wad_objects() # [--all] +wad_objects() # [-1a] { - rev="HEAD" + rev="HEAD" # Revision - if [ $# -ge 1 ]; then - case "$1" in - "--all") rev="--all" ;; + while getopts a1 opt; do + case "${opt}" in + 1) rev="HEAD -1" ;; # Last commit only + a) rev="--all" ;; *) >&2 log "Invalid option %s\n" "$1" return 1 ;; esac - fi + done # The following command line can be translated as follows: # Print the IDs of all objects in "${rev}" (i.e. HEAD or --all) @@ -149,7 +135,8 @@ wad_objects() # [--all] # | 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}" \ + # shellsheck disable=SC2248 # ${rev} can have several arguments + git rev-list --objects ${rev} \ | cut -d' ' -f1 \ | git cat-file --batch-check \ | sed -n "/^[a-z0-9]\{40\} blob [0-9]\{1,\}$/p" \ @@ -159,8 +146,9 @@ wad_objects() # [--all] | sed "s/^${GIT_WAD_HEADER} \([0-9a-z]\{64\}\) [0-9]\{1,\}$/\1/" } -# List all locally stored WAD objects. These may be WAD objects from the -# current working tree, WAD objects to be cleaned up, or dummy files. +# List all stored WAD objects of the working tree. These may be WAD +# objects from the current HEAD, WAD objects to be cleaned up, or dummy +# files. all_objects() { find "${GIT_WAD_OBJDIR}" ! -path "${GIT_WAD_OBJDIR}" -prune -type f \ @@ -170,7 +158,7 @@ all_objects() # List of all locally stored WAD objects to be pruned, i.e. not # referenced in the current work tree. -unreferenced_objects() # [--all] +unreferenced_objects() # [-1a] { # Lists all locally stored WAD objects in tmpfile tmpfile="$(mktemp -p "${GIT_WAD_OBJDIR}")" @@ -185,13 +173,13 @@ unreferenced_objects() # [--all] rm -f "${tmpfile}" } -objects_to_push() # [--all] +objects_to_push() # [-1a] { wad_objects "$@" | xargs -I {} sh -c \ "if [ -f \"${GIT_WAD_OBJDIR}/{}\" ]; then echo \"{}\"; fi" } -objects_to_fetch() # [--all] +objects_to_fetch() # [-1a] { wad_objects "$@" | xargs -I {} sh -c \ "if [ ! -f \"${GIT_WAD_OBJDIR}/{}\" ]; then echo \"{}\"; fi" @@ -317,7 +305,7 @@ init() } # Transfert WAD objects to remote server -push() # [--all] +push() # [-1a] { if [ -z "${GIT_WAD_REMOTE_PUSH}" ]; then log "Remote undefined, i.e. variable GIT_WAD_REMOTE_PUSH is empty\n" @@ -330,7 +318,7 @@ push() # [--all] } # Download WAD objects from remote server -fetch() # [--all] +fetch() # [-1a] { if [ -z "${GIT_WAD_REMOTE_FETCH}" ]; then log "Remote undefined, i.e. variable GIT_WAD_REMOTE_FETCH is empty\n" @@ -354,7 +342,7 @@ checkout() # Download WAD objects from remote server and restore the content of # working WAD files. -pull() # [--all] +pull() # [-1a] { fetch "$@" checkout @@ -362,7 +350,7 @@ pull() # [--all] # Delete WAD objects not used in the current work tree from local # storage -prune() # [--all] +prune() # [-1a] { unreferenced_objects "$@" \ | xargs -I {} sh -c \ @@ -385,7 +373,6 @@ status() # [--all] resolved="$(mktemp -p "${GIT_WAD_OBJDIR}")" unrestored="$(mktemp -p "${GIT_WAD_OBJDIR}")" orphaned="$(mktemp -p "${GIT_WAD_OBJDIR}")" - wad_paths | while read -r wad; do # Read the WAD bytes corresponding to its header before it is restored header_size="$(sizeof_header)" @@ -444,7 +431,7 @@ status() # [--all] fi # Print number of WADs not referenced in current work tree - n="$(unreferenced_objects | wc -l)" + n="$(unreferenced_objects "$@" | wc -l)" if [ "${n}" -gt 0 ]; then printf "There are %d WADs not use in the current working tree\n" "${n}" printf " (use \"git wad prune\" to remove them)\n"