dot

packages and services management
Log | Files | Refs | README

commit 1b9a5127071d6a4b9b62df3e7041316cbcee9574
parent 093a15de2d3690f80b4d31e3a695ffb5e87f02b3
Author: Josuah Demangeon <mail@josuah.net>
Date:   Tue, 25 Apr 2017 15:55:26 +0200

removing even more lines

Diffstat:
Mbin/version | 33+++++++++++----------------------
1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/bin/version b/bin/version @@ -1,9 +1,5 @@ #!/bin/sh - -# simple version control system to store data using hashs - -# dependencies: -# mkdir find sort xargs sha256sum rm test mv chmod comm sed printf tac tail +# version control storing files using their hashes as name NL=' @@ -32,6 +28,7 @@ init() done mkdir -p v/obj v/rev + touch v/log } @@ -47,11 +44,12 @@ new() [ -f "v/obj/$hash" ] || cp "$path" "v/obj/$hash" done - new="$(md5sum v/tmp | cut -d ' ' -f 1)" + old="$(tail -n 1 v/log | cut -d ' ' -f 1)" + new="$(md5sum v/tmp | cut -d ' ' -f 1)" + mv -f v/tmp "v/rev/$new" - [ ! -f v/log ] || [ "$(tail -n 1 v/log | cut -d ' ' -f 1)" = "$new" ] && - printf '%s %s\n' "$new" "$1" | tee -a v/log + [ "$old" = "$new" ] || printf '%s %s\n' "$new" "$1" | tee -a v/log chmod -w v/obj/* v/rev/* } @@ -67,10 +65,7 @@ difftree() 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/^/+ /' - } | sort -t "$NL" -k 1.$((32 + 6)) -k 1,1r + comm -3 v/tmp1 v/tmp2 | sed 's/^[^\t]/- &/; s/^\t/+ /' rm -f v/tmp1 v/tmp2 } @@ -82,7 +77,7 @@ revision() { new - printf 'applying revision "%s" to tree\n' "$1" + printf 'applying revision %s\n' "$1" difftree "$(tail -n 1 v/log | cut -d ' ' -f 1)" "$1" | while read -r f hash path @@ -97,7 +92,7 @@ revision() } -#1 - root of foreign tree to import in local tree +#1 - foreign tree to import in local tree pull() { @@ -108,12 +103,6 @@ pull() [ -f "${path#$1/}" ] || cp "$path" "${path#$1/}" || exit 1 done - for revision in $(tac v/log | cut -d ' ' -f 1) - do - cut -d ' ' -f 1 "$1/v/log" | grep "$revision" > /dev/null && - break - done || die "no revision common to \"$1\" and \"$PWD\"" - new="$(tail -n 1 "$1/v/log" | cut -d ' ' -f 1)" cp "$1/v/rev/$new" "v/rev/$new" @@ -124,11 +113,11 @@ pull() main() { case "$1" in ( -d | -r | -m | -p | -n ) - [ -d v ] || die "no \"v/\" in \"$PWD\"" + [ -d v ] || die "no v/ in $PWD" esac case "$1" in ( -d | -r | -m | -p ) - [ -f v/log ] || die "no revision in \"$PWD\"" + [ "$(wc -l < v/log)" = 0 ] && die "no revision in $PWD" esac case "$1" in