dot

packages and services management
Log | Files | Refs | README

commit 71486ebb86956cfb088f25abe1f72df676960ce1
parent ffcbb2218a498d890981da214e0ef5e336bb2b82
Author: Josuah Demangeonā  ā µ <mail@josuah.net>
Date:   Wed, 22 Mar 2017 20:54:22 +0100

Changed '.version' to '.v'.

Diffstat:
Mbin/version | 80+++++++++++++++++++++++++++++++++++--------------------------------------------
1 file changed, 35 insertions(+), 45 deletions(-)

diff --git a/bin/version b/bin/version @@ -10,7 +10,8 @@ NL=' die() { - printf "\033[1;31m%s\033[m\n" "$1" 1>&2; exit 1 + printf "\033[1;31m%s\033[m\n" "$1" 1>&2 + exit 1 } @@ -22,7 +23,7 @@ opt() usage() { - opt "$1" i 'i[nit]' "new \".version\" directory in \"$PWD\"" + opt "$1" i 'i[nit]' "new \".v\" directory in \"$PWD\"" opt "$1" n 'n[ew]' 'new revision saving all tree content' opt "$1" d 'd[diff] [1 2]' 'diff revisions 1 and 2 (or latests)' opt "$1" r 'r[evision] REV' 'switch tree to revision REV' @@ -31,26 +32,15 @@ usage() } -# Generate exclude rules for find(1), for each arguments. - -exclude() -{ - for path in "$@" - do - printf ' ! -name %s ! -path */%s/*' "$path" "$path" - done -} - - init() { pwd="$PWD/" - while pwd="${pwd%/*}" && [ "$pwd" ] + while pwd="${pwd%/*}" && [ "$pwd" ] || break do - [ -d "$pwd/.version" ] && die 'already in a version tree' + [ -d "$pwd/.v" ] && die 'already in a version tree' done - mkdir -p .version/obj .version/rev + mkdir -p .v/obj .v/rev } @@ -58,18 +48,18 @@ new() { printf 'making a new revision\n' - find . -type f $(exclude .git .version) | sort | xargs sha256sum | - tee .version/tmp | while read -r hash path + find . -type f ! -name .v ! -path '*/.v/*' | sort | xargs sha256sum | + tee .v/tmp | while read -r hash path do - test -f ".version/obj/$hash" || cp "$path" ".version/obj/$hash" + test -f ".v/obj/$hash" || cp "$path" ".v/obj/$hash" done - new="$(sha256sum .version/tmp | sed 's/ .*//' | tee -a .version/history)" - mv -f .version/tmp ".version/rev/$new" - tail -n 2 .version/history - printf '%s\n' "$(uniq .version/history)" > .version/history + new="$(sha256sum .v/tmp | sed 's/ .*//' | tee -a .v/history)" + mv -f .v/tmp ".v/rev/$new" + tail -n 2 .v/history + printf '%s\n' "$(uniq .v/history)" > .v/history - chmod -w .version/obj/* .version/rev/* + chmod -w .v/obj/* .v/rev/* } @@ -79,21 +69,21 @@ new() difftree() { IFS="$NL" - [ "$1" ] || set -- $(tail -n 2 ".version/history") + [ "$1" ] || set -- $(tail -n 2 ".v/history") [ $# -ne 2 ] && die 'can not find the two revisions to diff' unset IFS printf '1 %s\n2 %s\n\n' "$1" "$2" - sort -o .version/tmp1 ".version/rev/$1" - sort -o .version/tmp2 ".version/rev/$2" + sort -o .v/tmp1 ".v/rev/$1" + sort -o .v/tmp2 ".v/rev/$2" { - comm -32 .version/tmp1 .version/tmp2 | sed 's/^/- /' - comm -31 .version/tmp1 .version/tmp2 | sed 's/^/+ /' + comm -32 .v/tmp1 .v/tmp2 | sed 's/^/- /' + comm -31 .v/tmp1 .v/tmp2 | sed 's/^/+ /' } | sort -t "$NL" -k 1.$((32 + 6)) -k 1,1r - rm -f .version/tmp1 .version/tmp2 + rm -f .v/tmp1 .v/tmp2 } @@ -105,12 +95,12 @@ revision() printf 'applying revision "%s" to tree\n' "$1" - difftree "$(tail -n 1 .version/history)" "$1" | + difftree "$(tail -n 1 .v/history)" "$1" | while read -r f hash path do case "$f" in ( + ) - mkdir -p "${path%/*}" && cp ".version/obj/$hash" "$path" + mkdir -p "${path%/*}" && cp ".v/obj/$hash" "$path" chmod +w "$path" ;; ( - ) @@ -119,7 +109,7 @@ revision() esac done - printf '%s\n' "$1" >> .version/history + printf '%s\n' "$1" >> .v/history } @@ -129,7 +119,7 @@ pull() { printf 'importing objects from "%s" to "%s"\n' "$1" "$PWD" - find "$1/.version/obj" -type f | while IFS='' read -r path + find "$1/.v/obj" -type f | while IFS='' read -r path do if [ ! -f "${path#$1/}" ] then @@ -137,13 +127,13 @@ pull() fi done - for revision in $(tac .version/history) + for revision in $(tac .v/history) do - grep "$revision" "$1/.version/history" > /dev/null && break + grep "$revision" "$1/.v/history" > /dev/null && break done || die "no revision common to \"$1\" and \"$PWD\"" - new="$(tail -n 1 "$1/.version/history")" - cp "$1/.version/rev/$new" ".version/rev/$new" + new="$(tail -n 1 "$1/.v/history")" + cp "$1/.v/rev/$new" ".v/rev/$new" revision "$new" @@ -155,12 +145,12 @@ main() { case "$1" in ( d | diff | r | revision | m | merge | p | pull | n | new ) - [ -d .version ] || die "no \".version/\" in \"$PWD\"" + [ -d .v ] || die "no \".v/\" in \"$PWD\"" esac case "$1" in ( d | diff | r | revision | m | merge | p | pull ) - [ -f .version/history ] || die "no revision in \"$PWD\"" + [ -f .v/history ] || die "no revision in \"$PWD\"" esac case "$1" in @@ -178,23 +168,23 @@ main() ( d | diff ) [ $# -eq 3 ] || [ $# -eq 1 ] || usage d - [ "$2" ] && [ ! -f ".version/rev/$2" ] && die "no revision $2" - [ "$3" ] && [ ! -f ".version/rev/$3" ] && die "no revision $3" + [ "$2" ] && [ ! -f ".v/rev/$2" ] && die "no revision $2" + [ "$3" ] && [ ! -f ".v/rev/$3" ] && die "no revision $3" difftree "$2" "$3" ;; ( r | revision ) [ $# -eq 2 ] || usage r - [ -f ".version/rev/$2" ] || die "no revision $2" + [ -f ".v/rev/$2" ] || die "no revision $2" revision "$2" ;; ( p | pull ) [ $# -eq 2 ] || usage m - [ -d "$2/.version" ] || die "no \".version/\" in \"$2\"" - [ -f "$2/.version/history" ] || die "no revision in \"$2\"" + [ -d "$2/.v" ] || die "no \".v/\" in \"$2\"" + [ -f "$2/.v/history" ] || die "no revision in \"$2\"" pull "$(cd "$2" || exit 1; pwd)" ;;