dot

packages and services management
Log | Files | Refs | README

commit e136729cead6f11ad146b4760f2e4481cb660072
parent 1d9085c849b744f5e6bcc1d673b7e464fb57126d
Author: josuah <mail@josuah.net>
Date:   Mon,  2 Jan 2017 14:48:05 +0100

Starting to implement merging

Diffstat:
M.local/bin/build | 5++---
M.local/bin/version | 86+++++++++++++++++++++++++++++++++++++++++--------------------------------------
2 files changed, 47 insertions(+), 44 deletions(-)

diff --git a/.local/bin/build b/.local/bin/build @@ -43,14 +43,13 @@ view() error() { - printf '\033[31merror: \033[1m%-12s \033[m%s\n' "$1" "$2" 1>&2 - exit 1 + printf '\033[31m%-12s \033[1m%s\033[m\n' "$1" "$2" 1>&2; exit 1 } info() { - printf '\033[36minfo: \033[1m%-12s \033[m%s\n' "$1" "$2" 1>&2 + printf '\033[36m%-12s \033[1m%s\033[m\n' "$1" "$2" 1>&2 } diff --git a/.local/bin/version b/.local/bin/version @@ -11,7 +11,7 @@ NL=' die() { - printf "\033[1;31m%s\033[m\n" "$1"; exit 1 + printf "\033[1;31m%s\033[m\n" "$1" 1>&2; exit 1 } @@ -32,8 +32,6 @@ usage() } - - # Generate exclude rules for find(1) for each arguments exclude() @@ -134,12 +132,25 @@ import() } -# 1: revision from which list the file changes +# 1: 2: root of trees for which check for conflicts +# 3: revision common to 1 and 2 from which look for conflicts -filechanges() +conflicts() { - difftree "$1" "$(tail -n 1 .version/history)" | - cut -c $((32 + 6)) | sed '/^ *$/ d' | sort -u + for root in "$1" "$2" + do + ( + cd "$root" || exit 1 + difftree "$3" "$(tail -n 1 .version/history)" | + cut -c $((32 + 6))- | sed '/^ *$/ d' | sort -u + ) > "$root/.version/tmp" || die "could not diff \"$root\"" + done + + diff1="$(cd "$1" && difftree "$common" "$(tail -n 1 .version/history)")" + diff2="$(cd "$2" && difftree "$common" "$(tail -n 1 .version/history)")" + comm -12 "$1/.version/tmp" "$2/.version/tmp" + + rm -f "$1/.version/tmp" "$2/.version/tmp" } @@ -147,72 +158,65 @@ filechanges() merge() { - (cd "$2" && import "$1") || die "could not import \"$1\" to \"$2\"" (cd "$1" && import "$2") || die "could not import \"$2\" to \"$1\"" + (cd "$2" && import "$1") || die "could not import \"$1\" to \"$2\"" - for revision in $(tac "$1/.version/history") - do common="$(grep "$revision" "$2/.version/history")" && break - done - [ "$common" ] || die "no revision common to \"$1\" and \"$2\"" - - (cd "$1" && filechanges "$common") > "$1/.version/tmp" && - (cd "$2" && filechanges "$common") > "$2/.version/tmp" || - die "could not generate diff for \"$1\" and \"$2\"" - - clash="$(comm -12 "$1/.version/tmp" "$2/.version/tmp")" - if [ "$clash" ] - then - tmp="$(mktemp)" - printf 'Trees 1 and 2 conflicts\n\n1: %s\n2: %s\n\n' "$1" "$2" - printf 'Replace the '!' with number of files to keep.\n\n' - printf '%s\n' "$conflicts" | sed 's/^/! /')" > "$tmp" - ${EDITOR:-vi} "$tmp" - fi - # TODO FIXME: I'm getting tired. - while read -r f file - do - [ "$f" = ! ] && die "\"$1\" and \"$2\" have unsolved conflicts" - done < "$tmp" + for common in $(tac "$1/.version/history") + do grep "$revision" "$2/.version/history" > /dev/null && break + done || die "no revision common to \"$1\" and \"$2\"" + conflicts="$(conflicts "$1" "$2" "$common")" - rm -f tmp + for root in "$1" "$2" + do + ( + cd "$root" || exit 1 + difftree "$common" "$(tail -n 1 .version/history)" + ) || die "could not go to \"$1\"" | while read -r f md5 file + do + if printf '%s\n' "$conflicts" | grep "$file" > /dev/null + then + printf '%s %s %s\n' "$f" "$md5" "$file" + else + + done + done } main() { - case "$1" in ( n | new | d | diff | r | revision) - [ -d .version ] || die "no .version dir in \"$PWD\"" - esac - - case "$1" in ( d | diff | r | revision) - [ -f ".version/history" ] || die "no revision in \"$PWD\"" - esac - case "$1" in ( i | init ) [ $# -ne 1 ] && usage i init ;; ( n | new ) + [ -d .version ] || die "no \".version/\" in \"$PWD\"" [ $# -ne 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\"" [ "$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\"" [ -f ".version/rev/$2" ] || die "no revision $2" revision "$2" ;; ( m | merge ) [ $# -lt 2 ] && [ $# -gt 3 ] && usage m - [ -d "$2/.version" ] || die "no .version dir in \"$2\"" + [ -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)" ;; ( * | '' )