dot

packages and services management
Log | Files | Refs | README

commit 26021686285d06fc585a74d58bd7a721fe37214d
parent 642173bded3f96732f71c3395350b2a74e2afb4c
Author: josuah <mail@josuah.net>
Date:   Wed, 16 Nov 2016 23:54:04 -0500

Draft for version

Diffstat:
Mbin/version | 127+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 102 insertions(+), 25 deletions(-)

diff --git a/bin/version b/bin/version @@ -108,21 +108,82 @@ init() # history() { - local tree="$1" md5sum="$2" - - local revisions="$(ls "$tree/$DIR")" + local md5="$1" # sort revisions by date - printf %s "$revisions" | sort -r | while IFS='-' read -r y m d H M S md5 + ls "$DIR" | sort -r | while IFS='-' read -r y m d H M S sum do - [ "$md5sum" = "$md5" ] && return 0 + [ "$md5" = "$sum" ] && return # rebuild the name - printf '%s-' "y" "$m" "$d" "$H" "$M" "$S" "$md5" - printf '%s\n' "$md5" + printf '%s-' "$y" "$m" "$d" "$H" "$M" "$S" + printf '%s\n' "$sum" done | tac +} - die 'revision not found' + +# +# Follows every change a file had since a revision and print the history. +# +# The changes can be either: +# +# - c, creation +# +# - d, deletion +# +# - m, modification +# +# - r, rename +# +# - x, did not exist +# +# - e, equal to some version in "$destination" +# +# It look at every changes of the file described from "$md5" and "$path" +# backward in history from "$revision", until either: +# +# - the md5 and path match any revision of a file in the other tree, +# +# - a creation of this file +# +trace() +{ + local md5="$1" path="$2" revision="$3" destination="$4" + + : +} + + +# +# Take decision and perform actions according to an input feed from trace +# +action() +{ + # source: c > m? > . + # destination: + # + # If the file is created in source and never existed in + # destination, create it as well, create it on the other side as + # well + + # source: e > m + # destination: e > d + # + # If the file was deleted on source, but modified since in + # destination, prompt the user if he wants to copy the modified + # file from the destination branch. + + # source: e > m + # destination: e + # + # If the file has been modified on source but not in dest, prompt + # the user which version he wants to keep. + + # source: c > m? + # destination: + # + # If the file has only been created in source, and never existed in + # destination, just copy it to dest } @@ -135,30 +196,38 @@ merge() local tree1="$(go_to_root; pwd)" local tree2="$(cd "$1"; go_to_root; pwd)" - local revision1="$(find "$tree1/$DIR" | tail -n 1)" - local revision2="$(find "$tree2/$DIR" | tail -n 1)" + local revision1="$tree1/$DIR/$(ls "$tree1/$DIR" | tail -n 1)" + local revision2="$tree2/$DIR/$(ls "$tree2/$DIR" | tail -n 1)" - # all the differences between trees at latest version + # all the files that differ across the two trees at their latest version { sed 's/^/1 /' "$revision1" sed 's/^/2 /' "$revision2" - } | sort -k 2 | uniq -w 2 -u | while read -r revision hash path + } | sort -k 2 | uniq -w 2 -u | while read -r revision md5 path do - # with the file from one tree, get the other tree - case "$revision" in - 1 ) local revision="$revision2" tree="$tree2" ;; - 2 ) local revision="$revision1" tree="$tree1" ;; + # we will want to get the file from source into destination + 1 ) local source="$tree1" destination="$tree2" ;; + 2 ) local source="$tree2" destination="$tree1" ;; esac - # for this entry, look for any similar version in the other tree - origin="$( - cd "$tree/$DIR" - grep -r "$hash $path" - )" - - # for this common origin, look at what happen since then - - # first, get every commit since then + # get the history of change of the source file + trace "$source/$DIR/$revision" "$md5" "$path" | action + + # for this entry, look the similar version in the other tree + #IFS='- :' read -r sum path + ls "$tree/$DIR" | # for all revisions + sort -r | + xargs grep -h "$sum $path" "$tree/$DIR" | + head -n 1 | + { + read -r sum file + } + + # since this revision look for what happen in history + ( + cd "$tree" + history "${revision##*-}" + ) done } @@ -228,6 +297,14 @@ main() die "\"$2\" not a directory" fi ;; + h | history ) + if go_to_root + then + history "$2" + else + die "no \"$DIR\" found in tree" + fi + ;; '' | * ) usage ;;