dot

packages and services management
Log | Files | Refs | README

commit 3782f95a96300727548cd7a01fb6436806f7a1ba
parent 20fe081d8aee6acbb1a573812e48135b3e74c69f
Author: josuah <mail@josuah.net>
Date:   Tue,  3 Jan 2017 16:45:13 +0100

Much more space so that we can breath

Diffstat:
M.local/bin/version | 55++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 38 insertions(+), 17 deletions(-)

diff --git a/.local/bin/version b/.local/bin/version @@ -1,5 +1,5 @@ #!/bin/sh -# Simple version control system to store large datasets using md5 hashs +# version - Simple version control system to store data using hashs # dependencies: # mkdir find sort xargs md5sum rm test mv chmod comm sed printf tac tail @@ -37,7 +37,8 @@ usage() exclude() { for path in "$@" - do printf ' ! -name %s ! -path */%s/*' "$path" "$path" + do + printf ' ! -name %s ! -path */%s/*' "$path" "$path" done } @@ -46,7 +47,8 @@ init() { pwd="$PWD/" while pwd="${pwd%/*}" && [ "$pwd" ] - do [ -d "$pwd/.version" ] && die 'already in a version tree' + do + [ -d "$pwd/.version" ] && die 'already in a version tree' done mkdir -p .version/obj .version/rev @@ -58,20 +60,22 @@ new() printf 'making a new revision\n' find . -type f $(exclude .git .version) -print0 | sort -z | - xargs -0 md5sum > .version/tmp || die 'hashing error' + xargs -0 md5sum > .version/tmp || die 'hashing error' - md5="$(md5sum .version/tmp)" && md5="${md5%% *}" || die 'hashing error' - [ -f .version/history ] && old="$(tail -n 1 .version/history)" - printf '1 %s\n2 %s\n' "$old" "$md5" + hash="$(md5sum .version/tmp)" && hash="${hash%% *}" || exit 1 + [ -f .version/history ] && old="$(tail -n 1 .version/history)" || old='' + printf '1 %s\n2 %s\n' "$old" "$hash" - mv -f .version/tmp ".version/rev/$md5" + mv -f .version/tmp ".version/rev/$hash" - [ -f .version/history ] && [ "$md5" = "$old" ] || - printf '%s\n' "$md5" >> .version/history + [ -f .version/history ] && [ "$hash" = "$old" ] || + printf '%s\n' "$hash" >> .version/history - while read -r md5 path - do [ -f ".version/obj/$md5" ] || cp -f "$path" ".version/obj/$md5" - done < ".version/rev/$md5" + while read -r hash path + do + [ -f ".version/obj/$hash" ] || + cp -f "$path" ".version/obj/$hash" + done < ".version/rev/$hash" chmod -w .version/obj/* .version/rev/* } @@ -109,12 +113,13 @@ revision() printf 'applying revision "%s" to tree\n' "$1" - difftree "$(tail -n 1 .version/history)" "$1" | while read -r f md5 path + difftree "$(tail -n 1 .version/history)" "$1" | + while read -r f hash path do case "$f" in ( + ) mkdir -p "${path%/*}" - cp ".version/obj/$md5" "$path" + cp ".version/obj/$hash" "$path" chmod +w "$path" ;; ( - ) @@ -134,11 +139,16 @@ 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; } + do + if [ -f "${path#$1/}" ] + then + cp "$path" "${path#$1/}" || exit 1 + fi done for revision in $(tac .version/history) - do grep "$revision" "$1/.version/history" > /dev/null && break + do + grep "$revision" "$1/.version/history" > /dev/null && break done || die "no revision common to \"$1\" and \"$PWD\"" new="$(tail -n 1 "$1/.version/history")" @@ -163,30 +173,41 @@ main() case "$1" in ( i | init ) [ $# -ne 1 ] || usage i + init ;; + ( n | new ) [ $# -eq 1 ] || usage n + new ;; + ( 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" + difftree "$2" "$3" ;; + ( r | revision ) [ $# -eq 2 ] || usage r [ -f ".version/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\"" + pull "$(cd "$2" || exit 1; pwd)" ;; + ( * | '' ) + usage ;; esac