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 0c8a1c5701be1a9d1f7cea90e82b271169c9b9a8
parent 50bf7e8ffed9da9d6fe51c3269623f5efb0835fc
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Sun, 14 Jan 2024 18:21:24 +0100

Update on how WADs are listed

The list_objects function has been renamed to all_objects to make it
clearer that it lists all WAD objects stored locally, used or not.

Add the unreferenced_objects function, which lists WAD objects that are
not used in the current work tree, i.e. WAD objects to be pruned.  The
pruning function has been updated to take advantage of this new feature.

Diffstat:
Mgit-wad | 56++++++++++++++++++++++++++++++--------------------------
1 file changed, 30 insertions(+), 26 deletions(-)

diff --git a/git-wad b/git-wad @@ -63,16 +63,6 @@ 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] { @@ -107,6 +97,32 @@ 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. +all_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 of all locally stored WAD objects to be pruned, i.e. not +# referenced in the current work tree. +unreferenced_objects() # [--all] +{ + # Lists all locally stored WAD objects in tmpfile + tmpfile="$(mktemp -p "${GIT_WAD_OBJDIR}")" + all_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 + wad_objects "$@" | sort | comm -23 "${tmpfile}" - + + rm -f "${tmpfile}" +} + objects_to_push() # [--all] { wad_objects "$@" | xargs -I {} sh -c \ @@ -282,29 +298,17 @@ pull() # [--all] checkout } -# Delete old WAD objects from local storage +# Delete WAD objects not used in the current work tree 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}" - \ + unreferenced_objects "$@" \ | xargs -I {} sh -c \ "printf \"Removing %s\n\" \"${GIT_WAD_OBJDIR}/{}\"; \ rm -f \"${GIT_WAD_OBJDIR}/{}\"" - - rm -f "${tmpfile}" } + ######################################################################## # The command ########################################################################