dot

packages and services management
Log | Files | Refs | README

commit 549bf36734169a403d20d6b1d819bb5762a1ac83
parent 3abfc04a257dc5a83fbcffa7c51d837b39e50ab4
Author: josuah <mail@josuah.net>
Date:   Sat, 31 Dec 2016 14:21:28 +0100

Udpated and added a few bits

Diffstat:
M.local/bin/version | 99+++++++++++++++++++++++++++++++++++++++++--------------------------------------
1 file changed, 52 insertions(+), 47 deletions(-)

diff --git a/.local/bin/version b/.local/bin/version @@ -17,20 +17,17 @@ die() opt() { - [ -z "${1#$2}" ] && if [ "$1" ] - then printf '%s %s %s\n' "${0##*/}" "$3" "$4" - else printf '%s %-20s %s\n' "${0##*/}" "$3" "$4" - fi + [ -z "${1#$2}" ] && printf '%s %-20s %s\n' "${0##*/}" "$3" "$4" } usage() { - opt "$1" i 'i[nit]' 'new .version directory in working directory' - opt "$1" n 'n[ew]' 'new version entry saving all tree content' - opt "$1" l 'l[ist] [REV]' 'display full history of revisions or REV' - opt "$1" d 'd[diff] [OLD NEW]' 'diff revisions OLD and NEW (or latests)' - opt "$1" m 'm[erge] TREE' 'merge current tree with foreign TREE' + opt "$1" i 'i[nit]' "make new ".version" directory in \"$PWD\"" + opt "$1" n 'n[ew]' 'make 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' + opt "$1" m 'm[erge] TREE' 'merge current tree with foreign TREE' exit 1 } @@ -72,23 +69,54 @@ new() [ -f .version/history ] && [ "$hash" = "$old" ] || printf '%s\n' "$hash" >> .version/history + e=0 while read -r hash path - do [ ! -f ".version/obj/$hash" ] && cp -f "$path" ".version/obj/$hash" + do [ -f ".version/obj/$hash" ] || cp -f "$path" ".version/obj/$hash" done < ".version/rev/$hash" chmod -w .version/obj/* .version/rev/* } +# 1: old revision to diff +# 2: new revision to diff + +difftree() +{ + IFS="$NL" + [ "$1" ] || set -- $(sed '$!{xd} ${xpx}' ".version/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" + + { + comm -32 .version/tmp1 .version/tmp2 | sed 's/^/- /' + comm -31 .version/tmp1 .version/tmp2 | sed 's/^/+ /' + } | sort -t "$NL" -k 1.$((32 + 6)) + + rm -f .version/tmp1 .version/tmp2 +} + + +revision() +{ + new + # TODO: apply difftree to current tree +} + + # 1: root of foreign tree to import in local tree import() { - :: "importing objects from \"$1\" to \"$PWD\"" + printf 'importing objects from "%s" to "%s"' "$1" "$PWD" find "$1/.version/obj" -type f | while IFS='' read -r path do [ -f "${path#$1/}" ] || cp "$path" "${path#$1/}" done - chmod -w "$1/.version/obj/"* "$1/.version/obj/"* for revision in $(tac "$1/.version/history") do common="$(grep "$revision" "$2/.version/history")" && break @@ -96,7 +124,9 @@ import() [ "$common" ] || die "no revision common to \"$1\" and \"$2\"" # TODO: start editor to edit diff, so that user can choose what to apply - difftree "$common" + # difftree "$common" "$(sed 'lastest')" + # cd "$2" || exit 1 + difftree "$common" "$(sed 'lastest')" } @@ -109,37 +139,13 @@ merge() } -# 1: old revision to diff -# 2: new revision to diff - -difftree() -{ - IFS="$NL" - [ "$1" ] || set -- $(sed '$!{xd} ${xpx}' ".version/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" - - { - comm -32 .version/tmp1 .version/tmp2 | sed 's/^/- /' - comm -31 .version/tmp1 .version/tmp2 | sed 's/^/+ /' - } | sort -t "$NL" -k 1.$((32 + 6)) - - rm -f .version/tmp1 .version/tmp2 -} - - main() { - case "$1" in ( n | new | d | diff | l | list | m | merge ) + case "$1" in ( n | new | d | diff | r | rev | m | merge ) [ -d .version ] || die "no .version dir in \"$PWD\"" esac - case "$1" in ( d | diff | l | list | m | merge ) + case "$1" in ( d | diff | r | rev | m | merge ) [ -f ".version/history" ] || die "no revision in \"$PWD\"" esac @@ -153,16 +159,15 @@ main() new ;; ( d | diff ) - [ $# -gt 1 ] && [ ! -f ".version/rev/$2" ] && usage d - [ $# -gt 1 ] && [ ! -f ".version/rev/$3" ] && usage d - [ $# -gt 3 ] && usage d + [ $# -ne 3 ] && [ $# -ne 1 ] && usage d + [ "$2" ] && [ ! -f ".version/rev/$2" ] && die "no revision $2" + [ "$3" ] && [ ! -f ".version/rev/$3" ] && die "no revision $3" difftree "$2" "$3" ;; - ( l | list ) - [ $# -gt 2 ] && usage l - [ $# -eq 1 ] && less -F .version/history - [ $# -eq 2 ] && [ -f ".version/rev/$2" ] && - less -F ".version/rev/$2" + ( r | revision ) + [ $# -ne 2 ] && usage r + [ -f ".version/rev/$2" ] || die "no revision $2" + revision ;; ( m | merge ) [ $# -lt 2 ] && [ $# -gt 3 ] && usage m