dot

packages and services management
Log | Files | Refs | README

commit 60468de5d9102460e9f22fbacccfcd1af1d23a8e
parent e136729cead6f11ad146b4760f2e4481cb660072
Author: josuah <mail@josuah.net>
Date:   Mon,  2 Jan 2017 15:32:15 +0100

Correctly generating diff for merging

Diffstat:
M.local/bin/version | 56+++++++++++++++++++-------------------------------------
1 file changed, 19 insertions(+), 37 deletions(-)

diff --git a/.local/bin/version b/.local/bin/version @@ -132,28 +132,6 @@ import() } -# 1: 2: root of trees for which check for conflicts -# 3: revision common to 1 and 2 from which look for conflicts - -conflicts() -{ - 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" -} - - # 1: 2: root of trees to merge together merge() @@ -161,26 +139,30 @@ merge() (cd "$1" && import "$2") || die "could not import \"$2\" to \"$1\"" (cd "$2" && import "$1") || die "could not import \"$1\" to \"$2\"" - for common in $(tac "$1/.version/history") - do grep "$revision" "$2/.version/history" > /dev/null && break + for revision in $(tac "$1/.version/history") + do common="$(grep "$revision" "$2/.version/history")" && break done || die "no revision common to \"$1\" and \"$2\"" - conflicts="$(conflicts "$1" "$2" "$common")" - - 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 + lastf='' lastm='' lastp='' + { + (cd "$1" && difftree "$common" "$(tail -n 1 .version/history)") + (cd "$2" && difftree "$common" "$(tail -n 1 .version/history)") + printf '\n' + } | sed -r '/^.? *[^ ]*$/ d' | sort -t "$NL" -k 1.$((32 + 6)) -k 1,1r | + while read -r f md5 path do - if printf '%s\n' "$conflicts" | grep "$file" > /dev/null + if [ "$path" = "$lastp" ] && [ "$f" = "$lastf" ] + then + printf '%s! %s %s\n' "$f" "$md5" "$path" + printf '%s! %s %s\n' "$lastf" "$lastm" "$lastp" + lastf='' lastm='' lastp='' + continue + elif [ "$lastp" ] then - printf '%s %s %s\n' "$f" "$md5" "$file" - else - + printf '%s %s %s\n' "$lastf" "$lastm" "$lastp" + fi + lastf="$f" lastm="$md5" lastp="$path" done - done }