summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-04-30 19:22:35 -0400
committerMalf Furious <m@lfurio.us>2017-04-30 19:22:35 -0400
commit151f754b5e87920c3fec9927f978549b2343a99b (patch)
treeab46120e38e07a48df65aed6755b3ee947660525
parent7210a46fda8537d59aa7421cc1b2989dc8085590 (diff)
downloadsystrunk-151f754b5e87920c3fec9927f978549b2343a99b.tar.gz
systrunk-151f754b5e87920c3fec9927f978549b2343a99b.zip
Add repo-access module
-rw-r--r--repo-access.sh48
1 files changed, 48 insertions, 0 deletions
diff --git a/repo-access.sh b/repo-access.sh
new file mode 100644
index 0000000..1e799a5
--- /dev/null
+++ b/repo-access.sh
@@ -0,0 +1,48 @@
+##
+# systr_repo_resolve_reference <symref> [<path>]
+#
+# Resolve a revision to a commit ID. This function is polymorphic
+# for both local and remote repositories. The result is printed to
+# stdout.
+##
+function systr_repo_resolve_reference
+{
+ if [ $# -lt 1 ]; then
+ echo "Fatal: too few arguments to systr_repo_resolve_reference"
+ exit 1
+ fi
+
+ symref="$1"
+
+ if [ $# -gt 1 ]; then
+ path="$2"
+ fi
+
+ if [[ "$symref" == "BASE" ]]; then
+ cat ".systr/BASE"
+ elif [[ "$symref" == "TRAC" ]]; then
+ read trac <.systr/TRAC
+ systr_repo_resolve_reference "$trac"
+ elif [[ "$symref" == "NULL" ]]; then
+ echo "NULL"
+ fi
+
+ if [[ "$remote" == "" ]]; then
+ (
+ cd "$path"
+
+ if [[ "$symref" == "HEAD" ]]; then
+ cat "HEAD"
+ elif [ -f "refs/$symref" ]; then
+ cat "refs/$symref"
+ elif [ -f "revs/$symref/.commit.systr" ]; then
+ echo "$symref"
+ else
+ echo "$symref not a revision"
+ exit 1
+ fi
+ )
+ else
+ ssh "$remote" "systrunk resv-ref \"$symref\" \"$path\""
+ fi
+}