From 2f69a3efcef8df278fb37e42153124e2a5858604 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Fri, 1 Sep 2017 06:35:08 -0400 Subject: Add functions to support the merge implementation Including commit distance, shortlog, and merge-base locator. --- repo-access.sh | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'repo-access.sh') diff --git a/repo-access.sh b/repo-access.sh index 6f6bf74..2b6a5cc 100644 --- a/repo-access.sh +++ b/repo-access.sh @@ -35,6 +35,90 @@ function systr_repo_resolve_reference fi } +## +# systr_repo_commit_dist +# +# Determine how many commits have occurred between and . +# IE: How far behind is ? If and are (or +# reference) the same commit, the result it zero. Result +# written to stdout. +## +function systr_repo_commit_dist +{ + if [ $# -lt 2 ]; then + echo "Fatal: too few args to repo_commit_dist" >&2 + exit 1 + fi + + a=$(systr_repo_resolve_reference "$1") + b=$(systr_repo_resolve_reference "$2") + d=$((0)) + + while [[ "$b" != "NULL" ]] + do + if [[ "$b" == "$a" ]]; then + echo "$d" + exit + fi + + d=$(($d+1)) + read b <"$path/revs/$b/.commit.systr" + done + + echo "Inf" +} + +## +# systrunk shortlog [=BASE] +# +# View commit history. Generate list of commit IDs only, each +# one a newline. Written to stdout. +## +function systr_short_log +{ + if [ $# -lt 1 ]; then + commit="$BASE" + else + commit=$(systr_repo_resolve_reference "$1") + fi + + while [[ "$commit" != "NULL" ]] + do + echo "$commit" + read commit <"$path/revs/$commit/.commit.systr" + done +} + +## +# systr_repo_merge_base +# +# Find the merge base between and . That is, determine +# which other commit is the closest common ancestor of both +# and . Result or "NULL" written to stdout. +## +function systr_repo_merge_base +{ + if [ $# -lt 2 ]; then + echo "Fatal: too few args to repo_merge_base" >&2 + exit 1 + fi + + a=$(systr_repo_resolve_reference "$1") + b=$(systr_repo_resolve_reference "$2") + + while [[ "$a" != "NULL" ]] + do + check=$(systr_short_log "$b" | grep "$a") + + if [[ "$check" == "$a" ]]; then + echo "$a" + exit + fi + + read a <"$path/revs/$a/.commit.systr" + done +} + ## # systrunk log [=BASE] # -- cgit v1.2.3