diff options
author | Malf Furious <m@lfurio.us> | 2017-09-01 06:35:08 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2017-09-01 06:35:08 -0400 |
commit | 2f69a3efcef8df278fb37e42153124e2a5858604 (patch) | |
tree | b9af9a195097df4b82d7efe91fbb579b48d80804 /repo-access.sh | |
parent | 5692053379147dde8a8cabc226b73c2d5184f4c0 (diff) | |
download | systrunk-2f69a3efcef8df278fb37e42153124e2a5858604.tar.gz systrunk-2f69a3efcef8df278fb37e42153124e2a5858604.zip |
Add functions to support the merge implementation
Including commit distance, shortlog, and merge-base locator.
Diffstat (limited to 'repo-access.sh')
-rw-r--r-- | repo-access.sh | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/repo-access.sh b/repo-access.sh index 6f6bf74..2b6a5cc 100644 --- a/repo-access.sh +++ b/repo-access.sh @@ -36,6 +36,90 @@ function systr_repo_resolve_reference } ## +# systr_repo_commit_dist <a> <b> +# +# Determine how many commits have occurred between <a> and <b>. +# IE: How far behind <b> is <a>? If <a> and <b> 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 [<commit>=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 <a> <b> +# +# Find the merge base between <a> and <b>. That is, determine +# which other commit is the closest common ancestor of both +# <a> and <b>. 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 [<commit>=BASE] # # View commit history. Generate a dump of all commits reachable |