From 5692053379147dde8a8cabc226b73c2d5184f4c0 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Fri, 1 Sep 2017 06:28:44 -0400 Subject: Rewrite rsync mod to drop remote support Also added some helpers for the merge implementation. --- rsync.sh | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 84 insertions(+), 19 deletions(-) diff --git a/rsync.sh b/rsync.sh index 2a36053..5fc0c7d 100644 --- a/rsync.sh +++ b/rsync.sh @@ -2,14 +2,12 @@ # systr_rsync_normal [] # # Perform normal rsync operations to transfer files to or from the -# repository. If is set, it is used as the --link-dest value -# for rsync. This function is polymorphic for both local and remote -# repositories. +# repository. If is set, it is used as the --link-dest value. ## function systr_rsync_normal { if [ $# -lt 2 ]; then - echo "Fatal: too few arguments to systr_rsync_normal" + echo "Fatal: too few args to rsync_normal" >&2 exit 1 fi @@ -22,21 +20,88 @@ function systr_rsync_normal link="" fi - if [[ "$remote" == "" ]]; then - rsync -az --info=progress2 --info=stats2 \ - --delete --exclude='*.systr' \ - $link \ - "$src" "$dst" + rsync -az --info=progress2 --info=stats2 --delete \ + --exclude='*.systr' $link "$src" "$dst" +} + +## +# systr_rsync_diff +# +# Copy files from to , but only if they've changed +# since the state in . Empty directories are +# purged from afterward. +## +function systr_rsync_diff +{ + if [ $# -lt 3 ]; then + echo "Fatal: too few args to rsync_diff" >&2 + exit 1 + fi + + src="$1" + compare="--compare-dest=$2" + dst="$3" + + rsync -az --delete --exclude='*.systr' $compare \ + "$src" "$dst" + + find "$dst" -type d -empty -delete +} + +## +# systr_rsync_del +# +# Delete files in , only if they have been deleted from +# to . Deleted files in are 'backed up', +# in rsync lingo, meaning they are actually renamed with a +# suffix appended to the original filename. +# +# If is the worktree ("."), our file suffix will be +# '&' to signify files deleted by us. Otherwise, the suffix +# will be '~' to signify files deleted by 'them'. +## +function systr_rsync_del +{ + if [ $# -lt 3 ]; then + echo "Fatal: too few args to rsync_del" >&2 + exit 1 + fi + + src="$1" + compare="--compare-dest=$2" + dst="$3" + + if [[ "$src" == "." ]]; then + suffix="--suffix='&'" else - if [[ "$src" == "." ]]; then - dst="$remote:$dst" - else - src="$remote:$src" - fi - - rsync -az -e ssh --info=progress2 --info=stats2 \ - --delete --exclude='*.systr' \ - $link \ - "$src" "$dst" + suffix="--suffix='~'" fi + + rsync -azb $suffix --existing --ignore-existing \ + --delete --exclude='*.systr' $compare \ + "$src" "$dst" +} + +## +# systr_rsync_merge +# +# Finish setting up a merge, by copying files from the +# temporary directory to the merge staging directory. +# +# Files in overwritten by this operation will +# be suffixed with '*' to signify files modified by +# both of us. +## +function systr_rsync_merge +{ + if [ $# -lt 2 ]; then + echo "Fatal: too few args to rsync_merge" >&2 + exit 1 + fi + + src="$1" + dst="$2" + + rsync -azb --suffix='*' --exclude='*.systr' \ + "$src" "$dst" } -- cgit v1.2.3