dot

packages and services management
Log | Files | Refs | README

commit d3a42d94cb94f7ab5af1715335f5ebb07f8bf868
parent 668d231cb901536917062aceaf9d6d891cf28879
Author: josuah <mail@josuah.net>
Date:   Sun,  1 Jan 2017 22:20:50 +0100

Improved diff sorting for easier patching

Diffstat:
M.local/bin/version | 44+++++++++++++++++++++-----------------------
1 file changed, 21 insertions(+), 23 deletions(-)

diff --git a/.local/bin/version b/.local/bin/version @@ -1,8 +1,8 @@ #!/bin/sh -# Simple version control system to store large datasets using hashs +# 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 +# mkdir find sort xargs md5sum rm test mv chmod comm sed printf tac tail NL=' @@ -23,8 +23,8 @@ opt() usage() { - 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" i 'i[nit]' "new \".version\" 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' opt "$1" m 'm[erge] TREE' 'merge current tree with foreign TREE' @@ -60,19 +60,18 @@ new() find . -type f $(exclude .git .version) -print0 | sort -z | xargs -0 md5sum > .version/tmp - hash="$(md5sum .version/tmp)" || die 'could not generate hash' - hash="${hash%% *}" old="$(sed '$qd' .version/history)" - printf '1 %s\n2 %s\n' "$old" "$hash" + md5="$(md5sum .version/tmp)" && md5="${md5%% *}" || die 'md5sum failed' + [ -f .version/history ] && old="$(tail -n 1 .version/history)" + printf '1 %s\n2 %s\n' "$old" "$md5" - mv -f .version/tmp ".version/rev/$hash" + mv -f .version/tmp ".version/rev/$md5" - [ -f .version/history ] && [ "$hash" = "$old" ] || - printf '%s\n' "$hash" >> .version/history + [ -f .version/history ] && [ "$md5" = "$old" ] || + printf '%s\n' "$md5" >> .version/history - e=0 - while read -r hash path - do [ -f ".version/obj/$hash" ] || cp -f "$path" ".version/obj/$hash" - done < ".version/rev/$hash" + while read -r md5 path + do [ -f ".version/obj/$md5" ] || cp -f "$path" ".version/obj/$md5" + done < ".version/rev/$md5" chmod -w .version/obj/* .version/rev/* } @@ -84,7 +83,7 @@ new() difftree() { IFS="$NL" - [ "$1" ] || set -- $(sed '$!{xd} ${xpx}' ".version/history") + [ "$1" ] || set -- $(tail -n 2 ".version/history") [ $# -ne 2 ] && die 'can not find the two revisions to diff' unset IFS @@ -96,7 +95,7 @@ difftree() { comm -32 .version/tmp1 .version/tmp2 | sed 's/^/- /' comm -31 .version/tmp1 .version/tmp2 | sed 's/^/+ /' - } | sort -t "$NL" -k 1.$((32 + 6)) + } | sort -t "$NL" -k 1.$((32 + 6)) -k 1,1r rm -f .version/tmp1 .version/tmp2 } @@ -108,13 +107,12 @@ revision() { new - difftree "$(sed '$qd' .version/history)" "$1" | sort -r | - while read -r f hash path + difftree "$(tail -n 1 .version/history)" "$1" | while read -r f md5 path do case "$f" in ( + ) mkdir -p "${path%/*}" - cp ".version/obj/$hash" "$path" + cp ".version/obj/$md5" "$path" chmod +w "$path" ;; ( - ) @@ -140,9 +138,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" "$(sed 'lastest')" # cd "$2" || exit 1 - difftree "$common" "$(sed 'lastest')" + difftree "$common" "$(tail -n 1 "$1/.version/history")" | + cut -c $((32 + 6)) | uniq } @@ -157,11 +155,11 @@ merge() main() { - case "$1" in ( n | new | d | diff | r | rev | m | merge ) + case "$1" in ( n | new | d | diff | r | revision | m | merge ) [ -d .version ] || die "no .version dir in \"$PWD\"" esac - case "$1" in ( d | diff | r | rev | m | merge ) + case "$1" in ( d | diff | r | revision | m | merge ) [ -f ".version/history" ] || die "no revision in \"$PWD\"" esac