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 50bf7e8ffed9da9d6fe51c3269623f5efb0835fc
parent faa5f7c7b7c37ffa8cc4e5b19c9afff868ddec4f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Sat, 13 Jan 2024 19:29:15 +0100

Add the prune subcommand

Clean up old WAD objects that are no longer part of the current work
tree.

Diffstat:
Mgit-wad | 35+++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+), 0 deletions(-)

diff --git a/git-wad b/git-wad @@ -40,6 +40,7 @@ synopsis() >&2 printf "usage: git-wad checkout\n" >&2 printf " git-wad fetch [--all]\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" } @@ -62,6 +63,16 @@ encode() # digest, size printf "%s %s %d" "${GIT_WAD_HEADER}" "$1" "$2" } +# List all locally stored WAD objects. These may be WAD objects from the +# current working tree, old WAD objects to be cleaned up, or dummy +# files. +list_objects() +{ + find "${GIT_WAD_OBJDIR}" ! -path "${GIT_WAD_OBJDIR}" -prune -type f \ + | grep -e "${GIT_WAD_OBJDIR}/[0-9a-z]\{64\}" \ + | xargs -I {} basename {} +} + # List WAD objects from the current working tree wad_objects() # [--all] { @@ -271,6 +282,29 @@ pull() # [--all] checkout } +# Delete old WAD objects from local storage +prune() # [--all] +{ + # Lists all locally stored WAD objects in tmpfile + tmpfile="$(mktemp -p "${GIT_WAD_OBJDIR}")" + list_objects | sort > "${tmpfile}" + + # The following command line is translated as follows: + # List of WAD objects in the current work tree + # | Sort them in ascending order + # | Subtract them from the list of locally stored WAD objects + # | Delete remaining WAD objects, + # i.e. old ones that are no longer referenced + wad_objects "$@" \ + | sort \ + | comm -3 "${tmpfile}" - \ + | xargs -I {} sh -c \ + "printf \"Removing %s\n\" \"${GIT_WAD_OBJDIR}/{}\"; \ + rm -f \"${GIT_WAD_OBJDIR}/{}\"" + + rm -f "${tmpfile}" +} + ######################################################################## # The command ######################################################################## @@ -284,6 +318,7 @@ case "${sub_cmd}" in "filter-clean") shift 1; clean "$@" ;; "filter-smudge") shift 1; smudge "$@" ;; "init") shift 1; init "$@" ;; + "prune") shift 1; prune "$@" ;; "push") shift 1; push "$@" ;; "pull") shift 1; pull "$@" ;; *) synopsis; exit 1 ;;