dot

packages and services management
Log | Files | Refs | README

commit 68f16559b9f10a147d091f37e1579a54d844a9c6
parent 261855ce54d2bb201058e5f791892f6670e59d10
Author: josuah <mail@josuah.net>
Date:   Tue,  3 Jan 2017 01:28:08 +0100

I think I finished it.  '_'

Diffstat:
M.local/bin/version | 98++++++++++++++++++++++++-------------------------------------------------------
1 file changed, 29 insertions(+), 69 deletions(-)

diff --git a/.local/bin/version b/.local/bin/version @@ -2,7 +2,7 @@ # Simple version control system to store large datasets using md5 hashs # dependencies: -# mkdir find sort xargs md5sum rm test mv chmod comm sed printf tac tail +# mkdir find sort xargs md5sum rm test mv chmod comm sed printf tac tail NL=' @@ -27,7 +27,7 @@ usage() 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' - opt "$1" m 'm[erge] 1 2' 'merge trees 1 and 2 together' + opt "$1" p 'p[ull] TREE' "import TREE's objects and latest revision" exit 1 } @@ -99,11 +99,13 @@ difftree() } -# i: diff to apply as generated by makediff +# 1: revision to apply to the current tree -applydiff() +revision() { - while read -r f md5 path + new + + difftree "$(tail -n 1 .version/history)" "$1" | while read -r f md5 path do case "$f" in ( + ) @@ -119,103 +121,61 @@ applydiff() } -# 1: tree to check version - -revision() -{ - new - difftree "$(tail -n 1 .version/history)" "$1" | applydiff -} - - # 1: root of foreign tree to import in local tree -import() +pull() { printf 'importing objects from "%s" to "%s"\n' "$1" "$PWD" find "$1/.version/obj" -type f | while IFS='' read -r path do [ -f "${path#$1/}" ] || { cp "$path" "${path#$1/}" || return 1; } done -} - -# 1: 2: root of trees to merge together + for revision in $(tac .version/history) + do grep "$revision" "$1/.version/history" > /dev/null && break + done || die "no revision common to \"$1\" and \"$PWD\"" -merge() -{ - (cd "$1" && import "$2") || die "could not import \"$2\" to \"$1\"" - (cd "$2" && import "$1") || die "could not import \"$1\" to \"$2\"" + new="$(tail -n 1 "$1/.version/history")" + cp "$1/.version/rev/$new" ".version/rev/$new" - for revision in $(tac "$1/.version/history") - do common="$(grep "$revision" "$2/.version/history")" && break - done || die "no revision common to \"$1\" and \"$2\"" - - lastf='' lastm='' lastp='' tmp="$(mktemp)" - { - (cd "$1" && difftree "$common" "$(tail -n 1 .version/history)") - (cd "$2" && difftree "$common" "$(tail -n 1 .version/history)") - printf '\n' - } | sed -r '/^.? *[^ ]*$/ d' | sort -t "$NL" -k 1.$((32 + 6)) -k 1,1r | - while read -r f md5 path - do - if [ "$f" = "$lastf" ] && [ "$path" = "$lastp" ] - then - printf '%s! %s %s\n' "$f" "$md5" "$path" - printf '%s! %s %s\n' "$lastf" "$lastm" "$lastp" - lastf='' lastm='' lastp='' - continue - elif [ "$lastp" ] - then - printf '%s %s %s\n' "$lastf" "$lastm" "$lastp" - fi - lastf="$f" lastm="$md5" lastp="$path" - done > "$tmp" - - "$EDITOR" "$tmp" - - grep '^.!' "$tmp" > /dev/null && die 'unsolved conflicts remains' - - (cd "$1" && applydiff < "$tmp") || die "patching \"$1\" failed" - (cd "$2" && applydiff < "$tmp") || die "patching \"$2\" failed" - - rm -f "$tmp" + revision "$new" } main() { + case "$1" in ( d | diff | r | revision | m | merge | n | new ) + [ -d .version ] || die "no \".version/\" in \"$PWD\"" + esac + + case "$1" in ( d | diff | r | revision | m | merge ) + [ -f .version/history ] || die "no revision in \"$PWD\"" + esac + case "$1" in ( i | init ) - [ $# -ne 1 ] && usage i + [ $# -ne 1 ] || usage i init ;; ( n | new ) - [ -d .version ] || die "no \".version/\" in \"$PWD\"" - [ $# -ne 1 ] && usage n + [ $# -eq 1 ] || usage n new ;; ( d | diff ) - [ $# -ne 3 ] && [ $# -ne 1 ] && usage d - [ -d .version ] || die "no \".version/\" in \"$PWD\"" - [ -f .version/history ] || die "no revision in \"$PWD\"" + [ $# -eq 3 ] || [ $# -eq 1 ] || usage d [ "$2" ] && [ ! -f ".version/rev/$2" ] && die "no revision $2" [ "$3" ] && [ ! -f ".version/rev/$3" ] && die "no revision $3" difftree "$2" "$3" ;; ( r | revision ) - [ $# -ne 2 ] && usage r - [ -d .version ] || die "no \".version/\" in \"$PWD\"" - [ -f .version/history ] || die "no revision in \"$PWD\"" + [ $# -eq 2 ] || usage r [ -f ".version/rev/$2" ] || die "no revision $2" revision "$2" ;; - ( m | merge ) - [ $# -lt 2 ] && [ $# -gt 3 ] && usage m + ( p | pull ) + [ $# -eq 2 ] || usage m [ -d "$2/.version" ] || die "no \".version/\" in \"$2\"" [ -f "$2/.version/history" ] || die "no revision in \"$2\"" - [ -d "$3/.version" ] || die "no \".version/\" in \"$3\"" - [ -f "$3/.version/history" ] || die "no revision in \"$3\"" - merge "$(cd "$2" || exit 1; pwd)" "$(cd "$3" || exit 1; pwd)" + pull "$(cd "$2" || exit 1; pwd)" ;; ( * | '' ) usage