blob: 2b6a5cce9333cbe0b82728a262f2f5d2623646d1 (
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
##
# systr_repo_resolve_reference <ref>
#
# Resolve a revision name to a commit ID. The result is printed to
# stdout.
##
function systr_repo_resolve_reference
{
if [ $# -lt 1 ]; then
echo "Fatal: too few args to repo_resolve_reference" >&2
exit 1
fi
ref="$1"
if [[ "$ref" == "BASE" ]]; then
cat .systr/BASE
elif [[ "$ref" == "TRAC" ]]; then
systr_repo_resolve_reference "$TRAC"
elif [[ "$ref" == "NULL" ]]; then
echo "NULL"
else
(
cd "$path"
if [ -f "refs/$ref" ]; then
cat "refs/$ref"
elif [ -f "revs/$ref/.commit.systr" ]; then
echo "$ref"
else
echo "$ref is not a revision" >&2
exit 1
fi
)
fi
}
##
# 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
# from the given commit, or BASE if no argument is given.
##
function systr_log
{
if [ $# -lt 1 ]; then
commit="$BASE"
else
commit=$(systr_repo_resolve_reference "$1")
fi
while [[ "$commit" != "NULL" ]]
do
(
cd "$path/revs/$commit/"
read date <.date.systr
read author <.author.systr
read email <.email.systr
printf '%s %s\n' "$commit" "$date"
printf '%s <%s>\n\n' "$author" "$email"
cat .mesg.systr
echo ""
echo ""
)
read commit <"$path/revs/$commit/.commit.systr"
done
}
##
# systrunk init <name>
#
# Initialize a repository called "<name>.systr" in the current
# directory.
##
function systr_init
{
if [ $# -lt 1 ]; then
echo "Fatal: too few args to init" >&2
exit 1
fi
name="$1"
mkdir "$name.systr"
cd "$name.systr"
mkdir refs revs
echo "NULL" >refs/HEAD
}
|