summaryrefslogtreecommitdiff
path: root/urmoms
blob: 4243687e32b065b9381c06e64635bfdc346100dc (plain)
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
#!/bin/sh

# DEBUG
#set -e -x

usage() {
	printf '%s <repodir> <htmldir>\n' "$0"
	exit 1
}

header() {
	cat <<!__EOF__
<!DOCTYPE HTML>
<html dir="ltr" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="en" />
<title>${name} - ${description}</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<center>
<h1><img src="${relpath}logo.png" alt="" /> ${name}</h1>
<span class="desc">${description}</span><br/>
<a href="${relpath}log.html">Log</a> |
<a href="${relpath}files.html">Files</a> |
<a href="${relpath}stats.html">Stats</a> |
<a href="${relpath}readme.html">README</a> |
<a href="${relpath}license.html">LICENSE</a>
</center>
<hr/>
<pre>
!__EOF__
}

footer() {
	cat <<!__EOF__
</pre>
</body>
</html>
!__EOF__
}

# usage: repodir and htmldir must be set.
if test x"$1" = x"" || test x"$2" = x""; then
	usage
fi

# make absolute path to htmldir.
htmldir="$(readlink -f $2)"
mkdir -p "${htmldir}"

# repodir must be a directory to go to.
cd "$1" || usage

# default index page (symlink).
indexpage="log.html"

# project name, if bare repo remove .git suffix.
name=$(basename "$(pwd)" ".git")

# read .git/description.
description=""
test -f ".git/description" && description="$(cat '.git/description')"

# make diff for each commit (all files).
relpath="../"
mkdir -p "${htmldir}/commit"
git log --pretty='%H' | while read -r commit; do
	test -e "${htmldir}/commit/${commit}.html" && continue

	header > "${htmldir}/commit/${commit}.html"
	git show --pretty=full "${commit}" | \
		sed -E 's@^commit (.*)$@commit <a href="'${relpath}'commit/\1.html">\1</a>@g' >> "${htmldir}/commit/${commit}.html"
	footer >> "${htmldir}/commit/${commit}.html"
done 

# make log with all commits.
relpath=""
header > "${htmldir}/log.html"
printf '<table border="0">' >> "${htmldir}/log.html"
git log --pretty='<tr><td align="right">%cr</td><td><a href="'${relpath}'commit/%H.html">%H</a></td><td>%an</td><td>%s</td></tr>' >> "${htmldir}/log.html"
printf '</table>' >> "${htmldir}/log.html"
footer >> "${htmldir}/log.html"

# make index with file links.
relpath=""
header >> "${htmldir}/files.html"
printf '<table><tr><td><b>Mode</b></td><td><b>Name</b></td><td><b>Size</b></td><td></td></tr>' >> "${htmldir}/files.html"
git ls-tree -r -l master | while read -r mode type object size file; do
	git log -1 --pretty='<tr><td>'${mode}'</td><td><a href="'${relpath}'commit/%H.html#file-'${file}'">'${file}'</a></td><td>'${size}'</td><td><a href="file/'${file}'">[plain]</a></td></tr>' "${file}"
done >> "${htmldir}/files.html"
printf '</table>' >> "${htmldir}/files.html"
footer >> "${htmldir}/files.html"

# readme page
# find README file.
relpath=""
readme=""
for f in README README.md readme.md; do
	test -e "${f}" && readme="${f}"
done
# make page.
header > "${htmldir}/readme.html"
if test x"${readme}" != x""; then
	cat "${readme}" >> "${htmldir}/readme.html"
else
	echo "no README file found" >> "${htmldir}/readme.html"
fi
footer >> "${htmldir}/readme.html"

# license page
# find LICENSE file.
relpath=""
license=""
for f in LICENSE LICENSE.md; do
	test -e "${f}" && license="${f}"
done
# make page.
header > "${htmldir}/license.html"
if test x"${readme}" != x""; then
	cat "${license}" >> "${htmldir}/license.html"
else
	echo "unknown license" >> "${htmldir}/license.html"
fi
footer >> "${htmldir}/license.html"

# stats (authors).
relpath=""
header > "${htmldir}/stats.html"
git shortlog -n -s >> "${htmldir}/stats.html"
footer >> "${htmldir}/stats.html"

# symlink to index page.
ln -sf "$indexpage" "${htmldir}/index.html"