summaryrefslogtreecommitdiffstats
path: root/repo-access.sh
blob: dbf1b58eff3984e3f52f8534b093987ec98e1b74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
##
# 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"
    elif [[ "$remote" == "" ]]; then
        (
            cd "$path"

            if [[ "$symref" == "HEAD" ]]; then
                cat "refs/HEAD"
            elif [ -f "refs/$symref" ]; then
                cat "refs/$symref"
            elif [ -f "revs/$symref/.commit.systr" ]; then
                echo "$symref"
            else
                echo "$symref not a revision" >&2
                exit 1
            fi
        )
    else
        ssh "$remote" "systrunk resv-ref \"$symref\" \"$path\""
    fi
}

##
# systrunk log [<commit>=BASE]
#
# View commit history.  Generates a dump of all commits reachable
# from the given commit, or BASE if no argument given.  Works for
# either local/remote repository.
##
function systr_repo_generate_log
{
    if [ $# -lt 1 ]; then
        commit="$BASE"
    else
        commit=$(systr_repo_resolve_reference "$1")
    fi

    if [[ "$remote" == "" ]]; then
        while [[ "$commit" != "NULL" ]]
        do
            read date <"$path/revs/$commit/.date.systr"
            read author <"$path/revs/$commit/.author.systr"
            read email  <"$path/revs/$commit/.email.systr"

            printf '%s %s\n' "$commit" "$date"
            printf '%s %s\n' "$author" "$email"
            echo ""
            cat "$path/revs/$commit/.mesg.systr"
            echo ""
            echo ""

            read commit <"$path/revs/$commit/.commit.systr"
        done
    else
        ssh "$remote" "systrunk log \"$commit\""
    fi
}