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 d3fbae6dd495d720a1505989b5430015f7f3940d
parent 69bc8857232cddda7bbae5926ccaff036d32d282
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Sun, 24 Mar 2024 21:45:37 +0100

WAD objects can be downloaded from https and gophers

Detect which protocol is used for the retrieval URI and choose to use
rsync or curl accordingly.

Change the default value of the GIT_WAD_REMOTE_FETCH and
GIT_WAD_REMOTE_PULL environment variables. If they are not defined, they
take the value of the origin repository url. This simplifies the
workflow when the user does not wish to store the data elsewhere than in
the git repository. This should be the most frequent behavior.

Diffstat:
Mgit-wad | 32+++++++++++++++++++++++++++-----
Mgit-wad.1 | 20+++++++++++++++++---
2 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/git-wad b/git-wad @@ -29,9 +29,17 @@ GIT_WAD_HEADER="#\$# git-wad" GIT_WAD_OBJDIR=".git/wad" GIT_WAD_VERBOSE=1 -# Default options -[ -z "${GIT_WAD_REMOTE_PUSH}" ] && GIT_WAD_REMOTE_PUSH="" -[ -z "${GIT_WAD_REMOTE_FETCH}" ] && GIT_WAD_REMOTE_FETCH="${GIT_WAD_REMOTE_PUSH}" +######################################################################## +# Helper functions +######################################################################## +if [ -z "${GIT_WAD_REMOTE_FETCH}" ] \ +&& git remote | grep -qe "^origin$"; then + GIT_WAD_REMOTE_FETCH="$(git remote get-url origin)" +fi +if [ -z "${GIT_WAD_REMOTE_PUSH}" ] \ +&& git remote | grep -qe "^origin$"; then + GIT_WAD_REMOTE_PUSH="$(git remote get-url --push origin)" +fi ######################################################################## # Helper functions @@ -323,6 +331,8 @@ push() # [-1a] fi log "Pushing to %s\n" "${GIT_WAD_REMOTE_PUSH}" + + remote="${GIT_WAD_REMOTE_FETCH#file://}" objects_to_push "$@" | rsync -av --progress --ignore-existing \ --files-from=- "${GIT_WAD_OBJDIR}" "${GIT_WAD_REMOTE_PUSH}" } @@ -336,8 +346,20 @@ fetch() # [-1a] fi log "Fetching from %s\n" "${GIT_WAD_REMOTE_FETCH}" - objects_to_fetch "$@" | rsync -av --progress --ignore-existing \ - --files-from=- "${GIT_WAD_REMOTE_FETCH}" "${GIT_WAD_OBJDIR}" + + # Use curl to download WAD objects via http[s] or gopher[s] protocol + if echo "${GIT_WAD_REMOTE_FETCH}" | grep -q \ + -e "^http[s]\{0,1\}://" \ + -e "^gopher[s]\{0,1\}://"; then + objects_to_fetch "$@" | xargs -I {} curl --remove-on-error -w "{}\n" \ + -o "${GIT_WAD_OBJDIR}/{}" "${GIT_WAD_REMOTE_FETCH}/{}" + + # By default transfert WAD objects by rsync + else + remote="${GIT_WAD_REMOTE_FETCH#file://}" + objects_to_fetch "$@" | rsync -av --progress --ignore-existing \ + --files-from=- "${remote}" "${GIT_WAD_OBJDIR}" + fi } # Restore the content of WAD files diff --git a/git-wad.1 b/git-wad.1 @@ -163,13 +163,16 @@ subcommand and affect the reported number of WAD file data to remove. URI of the remote repository .Em from which WAD file data is transfered. -By default it is set to the -.Ev GIT_WAD_REMOTE_PUSH -environment variable. +By default, this is the fetch URL of the +.Li origin +git repository. .It Ev GIT_WAD_REMOTE_PUSH URI of the remote repository .Em to which WAD file data is transfered. +By default, this is the push URL of the +.Li origin +git repository. .El .Sh FILES .Bl -tag -width Ds @@ -210,6 +213,17 @@ test.png filter=wad .El .Sh EXIT STATUS .Ex -std +.Sh EXAMPLES +Use git-wad to archive pdf files of a git repository: +.Bd -literal -offset Ds +cd /path/to/git/repository +git wad init +echo "*.pdf filter=wad" >> .gitattributes +git add document.pdf +git commit -m "Add a PDF document managed by git-wad" +git push origin +git wad push +.Ed .Sh SEE ALSO .Xr git 1 , .Xr gitattributes 5