dot

packages and services management
Log | Files | Refs | README

commit e2602766de4b1917acdebde3ebde098942a93898
parent 8f44f4c922d93db434c97746c82ea6949fedd400
Author: Josuah Demangeonā  ā µ <mail@josuah.net>
Date:   Wed,  5 Apr 2017 14:43:20 +0200

fixed and simplified version

Diffstat:
Mbin/version | 109++++++++++++++++++++++++++++---------------------------------------------------
Mman/version.1 | 21++++++++++++---------
2 files changed, 50 insertions(+), 80 deletions(-)

diff --git a/bin/version b/bin/version @@ -28,10 +28,10 @@ init() pwd="$PWD/" while pwd="${pwd%/*}" && [ "$pwd" ] || break do - [ -d "$pwd/.v" ] && die 'already in a version tree' + [ -d "$pwd/v" ] && die 'already in a version tree' done - mkdir -p .v/obj .v/rev + mkdir -p v/obj v/rev } @@ -39,17 +39,17 @@ new() { printf 'making a new revision\n' - find . -type f ! -name .v ! -path '*/.v/*' | sort | xargs $SUM | - tee .v/tmp | while read -r hash path + find . -type f ! -path './v/*' | sort | xargs $SUM | tee v/tmp | + while read -r hash path do - test -f ".v/obj/$hash" || cp "$path" ".v/obj/$hash" + test -f "v/obj/$hash" || cp "$path" "v/obj/$hash" done - mv -f .v/tmp ".v/rev/$($SUM .v/tmp | cut -d ' ' -f 1 >> .v/log)" - tail -n 2 .v/log - printf '%s\n' "$(uniq .v/log)" > .v/log + mv -f v/tmp "v/rev/$($SUM v/tmp | cut -d ' ' -f 1 | tee -a v/log)" + tail -n 2 v/log + printf '%s\n' "$(uniq v/log)" > v/log - chmod -w .v/obj/* .v/rev/* + chmod -w v/obj/* v/rev/* } @@ -58,22 +58,17 @@ new() difftree() { - IFS="$NL" - [ "$1" ] || set -- $(tail -n 2 ".v/log") - [ $# -ne 2 ] && die 'can not find the two revisions to diff' - unset IFS + printf -- '--- %s\n+++ %s\n\n' "$1" "$2" - printf '1 %s\n2 %s\n\n' "$1" "$2" - - sort -o .v/tmp1 ".v/rev/$1" - sort -o .v/tmp2 ".v/rev/$2" + sort -o v/tmp1 "v/rev/$1" + sort -o v/tmp2 "v/rev/$2" { - comm -32 .v/tmp1 .v/tmp2 | sed 's/^/- /' - comm -31 .v/tmp1 .v/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 .v/tmp1 .v/tmp2 + rm -f v/tmp1 v/tmp2 } @@ -85,21 +80,17 @@ revision() printf 'applying revision "%s" to tree\n' "$1" - difftree "$(tail -n 1 .v/log)" "$1" | - while read -r f hash path + difftree "$(tail -n 1 v/log)" "$1" | while read -r f hash path do case "$f" in - ( + ) - mkdir -p "${path%/*}" && cp ".v/obj/$hash" "$path" - chmod +w "$path" - ;; - ( - ) - rm "$path" - ;; + ( + ) mkdir -p "${path%/*}" && cp "v/obj/$hash" "$path" ;; + ( - ) rm "$path" ;; esac done - printf '%s\n' "$1" >> .v/log + chmod +w "$path" + + printf '%s\n' "$1" >> v/log } @@ -107,81 +98,57 @@ revision() pull() { - printf 'importing objects from "%s" to "%s"\n' "$1" "$PWD" + printf 'importing all objects from "%s" to "%s"\n' "$1" "$PWD" - find "$1/.v/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 - cp "$path" "${path#$1/}" || exit 1 - fi + [ -f "${path#$1/}" ] || cp "$path" "${path#$1/}" || exit 1 done - for revision in $(tac .v/log) + for revision in $(tac v/log) do - grep "$revision" "$1/.v/log" > /dev/null && break + grep "$revision" "$1/v/log" > /dev/null && break done || die "no revision common to \"$1\" and \"$PWD\"" - new="$(tail -n 1 "$1/.v/log")" - cp "$1/.v/rev/$new" ".v/rev/$new" + new="$(tail -n 1 "$1/v/log")" + cp "$1/v/rev/$new" "v/rev/$new" revision "$new" - - new } main() { - case "$1" in - ( d | diff | r | revision | m | merge | p | pull | n | new ) - [ -d .v ] || die "no \".v/\" in \"$PWD\"" + case "$1" in ( -d | -r | -m | -p | -n ) + [ -d v ] || die "no \"v/\" in \"$PWD\"" esac - case "$1" in - ( d | diff | r | revision | m | merge | p | pull ) - [ -f .v/log ] || die "no revision in \"$PWD\"" + case "$1" in ( -d | -r | -m | -p ) + [ -f v/log ] || die "no revision in \"$PWD\"" esac case "$1" in - ( i | init ) - [ $# -eq 1 ] || usage i - + ( -i ) [ $# = 1 ] || usage init ;; - ( n | new ) - [ $# -eq 1 ] || usage n - + ( -n ) [ $# = 1 ] || usage new ;; - ( d | diff ) - [ $# -eq 3 ] || [ $# -eq 1 ] || usage d - [ "$2" ] && [ ! -f ".v/rev/$2" ] && die "no revision $2" - [ "$3" ] && [ ! -f ".v/rev/$3" ] && die "no revision $3" - + ( -d ) [ $# = 3 ] && [ -f "v/rev/$2" ] && [ -f "v/rev/$3" ] || usage difftree "$2" "$3" ;; - ( r | revision ) - [ $# -eq 2 ] || usage r - [ -f ".v/rev/$2" ] || die "no revision $2" - + ( -r ) [ $# = 2 ] || [ -f "v/rev/$2" ] || usage revision "$2" ;; - ( p | pull ) - [ $# -eq 2 ] || usage m - [ -d "$2/.v" ] || die "no \".v/\" in \"$2\"" - [ -f "$2/.v/log" ] || die "no revision in \"$2\"" - + ( -p ) [ $# = 2 ] && [ -d "$2/v" ] && [ -f "$2/v/log" ] || usage pull "$(cd "$2" || exit 1; pwd)" ;; - ( * | '' ) - - usage + ( * | '' ) usage ;; esac } diff --git a/man/version.1 b/man/version.1 @@ -82,18 +82,18 @@ Revert the changes to and switch the state to . .Bl -tag -width indent . -.It Pa .v +.It Pa v Main version directory. The directory in which -.Pa .v +.Pa v is located is the root version directory. . -.It Pa .v/obj/ +.It Pa v/obj/ Directory containing the .Sy objects every named after the hash of its content. . -.It Pa .v/rev/ +.It Pa v/rev/ Directory containing the .Sy revisions which contains the list of files, along with their associated hashes, @@ -107,7 +107,7 @@ in the following format: . The revisions are also named after their content. . -.It Pa .v/log +.It Pa v/log A file containing an history of every revision as a list of name of revision files, with one revision per line. . @@ -144,8 +144,11 @@ ba49aa8aabb111af9d3837e4fc1a2c4edf91fb092f9093d09a6d7c5fc15e3888 Diffing last two revisions: . .Bd -literal -offset indent -$ version -d $(tail -n 2 .v/log) -\&... +$ version -d $(tail -n 2 v/log) +--- e68a60a444860ebf5e0ff8ef58cc59944ffea7e11e49e038339112940ea8223b ++++ a7e8968176118b7cb97511b3426aee66d577b5956282810fe28cc6dc8ff4872d + ++ e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 ./test .Ed . .Pp @@ -153,6 +156,6 @@ $ version -d $(tail -n 2 .v/log) Find the revision corresponding to a file: . .Bd -literal -offset indent -$ grep -rlF path/to/file.txt .v/rev/ -\&.v/rev/9e59e557dad5b2c8b66313a2836afd1970990b885d08e728e6cd5a2a7b7df584 +$ grep -rlF path/to/file.txt v/rev/ +v/rev/9e59e557dad5b2c8b66313a2836afd1970990b885d08e728e6cd5a2a7b7df584 .Ed