dot

packages and services management
Log | Files | Refs | README

commit 6ae84eff9cbc487b586e2368cb5876f59327dd23
parent cd8c4b1f2bf5d4362142dfa448649812e64bbeba
Author: josuah <mail@josuah.net>
Date:   Sat, 31 Dec 2016 02:31:37 +0100

Simplified version

Diffstat:
M.local/bin/version | 132++++++++++++++++++++++++++++++++++++-------------------------------------------
M.profile | 8++++----
2 files changed, 64 insertions(+), 76 deletions(-)

diff --git a/.local/bin/version b/.local/bin/version @@ -1,10 +1,11 @@ +#!/bin/sh # Simple version control system to store large datasets using hashs # dependencies: # mkdir find sort xargs md5sum rm test mv comm sed printf tac -TAB=' ' NL=' +NL=' ' @@ -35,161 +36,148 @@ die() } -# -# Generate exclude rules for find(1) for every arguments -# +# Generate exclude rules for find(1) for each arguments + exclude() { for path in "$@" - do - printf ' ! -name %s ! -path */%s/*' "$path" "$path" + do printf ' ! -name %s ! -path */%s/*' "$path" "$path" done } -# -# Find the root "./.version/" dir if any or return error. -# -root() +init() { - while [ ! -d ".version" ] - do - [ "$PWD" = '/' ] && return 1 || cd .. + pwd="$PWD/" + while pwd="${pwd%/*}" && [ "$pwd" ] + do [ -d "$pwd/.version" ] && die "already in a version tree" done - pwd && return 0 -} - -init() -{ - [ "$1" ] && die "existing ./.version/ dir in $1" mkdir -p .version/obj .version/rev - exit 0 } -# -# 1: root in which generate the new version -# new() { printf 'generating a new revision\n' - cd "$1" || die 'could not go to root of tree' find . -type f $(exclude .git .version) -print0 | sort -z | - xargs -0 md5sum > "$1/.version/tmp" + xargs -0 md5sum > .version/tmp - hash="$(md5sum "$1/.version/tmp")" || die 'could not generate md5sum' + hash="$(md5sum .version/tmp)" || die 'could not generate md5sum' hash="${hash%% *}" if - [ -f "$1/.version/history" ] && - [ "$hash" = "$(sed -n '$p' "$1/.version/history")" ] + [ -f .version/history ] && + [ "$hash" = "$(sed '$qd' .version/history)" ] then - rm "$1/.version/tmp" + rm .version/tmp die 'already at latest version' fi - printf '%s\n' "$hash" >> "$1/.version/history" - mv "$1/.version/tmp" "$1/.version/rev/$hash" + printf '%s\n' "$hash" >> .version/history + mv .version/tmp ".version/rev/$hash" printf 'saving content in ./.version/obj/\n' while read -r hash path - do - if [ ! -f "$1/.version/obj/$hash" ] - then - cp -f "$1/$path" "$1/.version/obj/$hash" - fi - done < "$1/.version/rev/$hash" + do [ ! -f ".version/obj/$hash" ] && cp -f "$path" ".version/obj/$hash" + done < ".version/rev/$hash" } -# -# 1: 2: root of tree in which look for common revision -# -merge() +# 1: root of foreign tree to import in local tree + +import() { + 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/}" + done + # find latest common revision for revision in $(tac "$1/.version/history") - do - common="$(grep "$revision" "$2/.version/history")" && break + do common="$(grep "$revision" "$2/.version/history")" && break done - [ "$common" ] || die "no revision common to $1 and $2" - # generate a diff for both trees - printf '%s\n\n' "$1" - makediff "$common" '' "$1" - printf '\n\n%s\n\n' "$2" - makediff "$common" '' "$2" + # TODO: start editor to edit diff, so that user can choose what to apply + makediff "$common" +} + + +# 1: 2: root of tree in which look for common revision + +merge() +{ + (cd "$1" && import "$2") + (cd "$2" && import "$1") } -# # 1: old revision to diff # 2: new revision to diff -# 3: root of the tree for which make a diff -# + makediff() { IFS="$NL" - [ "$1" ] || set -- $(sed '$!{xd} ${xpx}' "$3/.version/history") "$3" - [ $# -ne 3 ] && die 'can not find the two revisions to diff' + [ "$1" ] || set -- $(sed '$!{xd} ${xpx}' ".version/history") + [ $# -ne 2 ] && die 'can not find the two revisions to diff' + unset IFS printf ': %s -> %s\n\n' "$1" "$2" - sort -o "$3/.version/tmp1" "$3/.version/rev/$1" - sort -o "$3/.version/tmp2" "$3/.version/rev/$2" + sort -o .version/tmp1 ".version/rev/$1" + sort -o .version/tmp2 ".version/rev/$2" { # -: not present in the next revision - comm -32 "$3/.version/tmp1" "$3/.version/tmp2" | sed 's/^/- /' + comm -32 .version/tmp1 .version/tmp2 | sed 's/^/- /' # +: not present in the previous revision - comm -31 "$3/.version/tmp1" "$3/.version/tmp2" | sed 's/^/+ /' + comm -31 .version/tmp1 .version/tmp2 | sed 's/^/+ /' } | sort -t "$NL" -k 1.$((32 + 6)) - rm -f "$3/.version/tmp1" "$3/.version/tmp2" + rm -f .version/tmp[12] } main() { case "$1" in ( n | new | d | diff | l | list | m | merge ) - root="$(root)" || die "no ./.version/ dir in $PWD" + [ -d .version ] || die "no .version dir in $PWD" esac case "$1" in ( d | diff | l | list | m | merge ) - [ -f "$root/.version/history" ] || die "no revision in $root" + [ -f ".version/history" ] || die "no revision in $PWD" esac case "$1" in ( i | init ) [ $# -ne 1 ] && usage i - init "$(root)" + init ;; ( n | new ) [ $# -ne 1 ] && usage n - new "$root" + new ;; ( d | diff ) - [ $# -gt 1 ] && [ ! -f "$root/.version/rev/$2" ] && usage d - [ $# -gt 1 ] && [ ! -f "$root/.version/rev/$3" ] && usage d + [ $# -gt 1 ] && [ ! -f ".version/rev/$2" ] && usage d + [ $# -gt 1 ] && [ ! -f ".version/rev/$3" ] && usage d [ $# -gt 3 ] && usage d - makediff "$2" "$3" "$root" + makediff "$2" "$3" ;; ( l | list ) [ $# -gt 2 ] && usage l - [ $# -eq 1 ] && less -F "$root/.version/history" - [ $# -eq 2 ] && [ -f "$root/.version/rev/$2" ] && - less -F "$root/.version/rev/$2" + [ $# -eq 1 ] && less -F .version/history + [ $# -eq 2 ] && [ -f ".version/rev/$2" ] && + less -F ".version/rev/$2" ;; ( m | merge ) - [ $# -ne 2 ] && usage m - [ -d "$2/.version" ] || die "no ./.version/ dir in $2" + [ $# -lt 2 ] && [ $# -gt 3 ] && usage m + [ -d "$2/.version" ] || die "no .version dir in $2" [ -f "$2/.version/history" ] || die "no revision in $2" - merge "$(root)" "$(cd "$2"; pwd)" + merge "$(cd "$1" || exit 1; pwd)" "$(cd "$2" || exit 1; pwd)" ;; ( * | '' ) usage diff --git a/.profile b/.profile @@ -78,8 +78,7 @@ page() color() { for i in 1 2 3 4 5 6 7 - do - printf ' \033[3%sm___\033[1m___\033[0m' $i + do printf ' \033[3%sm___\033[1m___\033[0m' $i done printf '\n' } @@ -164,11 +163,12 @@ screencast() main() { if [ "$TERM" = 'linux' ] - then - setfont ~/.local/share/consolefonts/terminus-16n.psf + then setfont ~/.local/share/consolefonts/terminus-16n.psf fi [ "$ABDUCO" ] || TERM='screen' ABDUCO='dvtm' abduco -A dvtm dvtm-status + + export TERM='ansi' }