stagit

improvements:

- nicer file list.
- relative urls, dont use base href.
- add link to plain files, files should be checked out in "file" dir.
- strip .git from bare repos.
- simplify part of commit per file, just link to commit + file anchor (WIP).

Hiltjo Posthuma contact@arjunchoudhary.com

commit: 0db9ba6 parent: bc0118b
1 files changed, 32 insertions(+), 42 deletions(-)
Murmoms+32-42
M · urmoms +32, -42
  1@@ -16,18 +16,17 @@ header() {
  2 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  3 <meta http-equiv="Content-Language" content="en" />
  4 <title>${name} - ${description}</title>
  5-<base href="${baseurl}" />
  6 <link rel="stylesheet" type="text/css" href="style.css" />
  7 </head>
  8 <body>
  9 <center>
 10-<h1><img src="logo.png" alt="" /> ${name}</h1>
 11+<h1><img src="${relpath}logo.png" alt="" /> ${name}</h1>
 12 <span class="desc">${description}</span><br/>
 13-<a href="log.html">Log</a> |
 14-<a href="files.html">Files</a> |
 15-<a href="stats.html">Stats</a> |
 16-<a href="readme.html">README</a> |
 17-<a href="license.html">LICENSE</a>
 18+<a href="${relpath}log.html">Log</a> |
 19+<a href="${relpath}files.html">Files</a> |
 20+<a href="${relpath}stats.html">Stats</a> |
 21+<a href="${relpath}readme.html">README</a> |
 22+<a href="${relpath}license.html">LICENSE</a>
 23 </center>
 24 <hr/>
 25 <pre>
 26@@ -37,8 +36,6 @@ header() {
 27 footer() {
 28 	cat <<!__EOF__
 29 </pre>
 30-<hr/>
 31-<i><center>Powered by urmoms vibrator</center></i>
 32 </body>
 33 </html>
 34 !__EOF__
 35@@ -56,58 +53,49 @@ mkdir -p "${htmldir}"
 36 # repodir must be a directory to go to.
 37 cd "$1" || usage
 38 
 39-# project name
 40-# TODO: if bare repo just remove .git suffix?
 41-name=$(basename "$(pwd)")
 42+# default index page (symlink).
 43+indexpage="log.html"
 44+
 45+# project name, if bare repo remove .git suffix.
 46+name=$(basename "$(pwd)" ".git")
 47 
 48 # read .git/description.
 49 description=""
 50 test -f ".git/description" && description="$(cat '.git/description')"
 51 
 52-# TODO: make configurable.
 53-baseurl="http://cow.codemadness.org/gitlog/"
 54-
 55-indexpage="log.html"
 56-
 57-firstcommit=$(git log | grep '^commit ' | tail -n 1 | cut -f 2 -d ' ')
 58-
 59-# make log per file.
 60-# TODO: just link to commit/commit? save some space and time?
 61-git ls-tree -r --name-only master | while read -r file; do
 62-	test -e "${htmldir}/file/${file}.html" && continue
 63-
 64-	d=$(dirname "${file}")
 65-	mkdir -p "${htmldir}/file/${d}"
 66-
 67-	header > "${htmldir}/file/${file}.html"
 68-	git show "${firstcommit}"...master "${file}" | \
 69-		sed -E 's@^commit (.*)$@commit <a href="commit/\1.html">\1</a>@g' >> "${htmldir}/file/${file}.html"
 70-	footer >> "${htmldir}/file/${file}.html"
 71-done
 72-
 73-# make log with all commits.
 74-header > "${htmldir}/log.html"
 75-printf '<table border="0">' >> "${htmldir}/log.html"
 76-git log --pretty='<tr><td align="right">%cD</td><td><a href="commit/%H.html">%H</a></td><td>%an</td><td>%s</td></tr>' >> "${htmldir}/log.html"
 77-printf '</table>' >> "${htmldir}/log.html"
 78-footer >> "${htmldir}/log.html"
 79-
 80 # make diff for each commit (all files).
 81+relpath="../"
 82 mkdir -p "${htmldir}/commit"
 83 git log --pretty='%H' | while read -r commit; do
 84 	test -e "${htmldir}/commit/${commit}.html" && continue
 85+
 86 	header > "${htmldir}/commit/${commit}.html"
 87-	git show "${commit}" >> "${htmldir}/commit/${commit}.html"
 88+	git show --pretty=full "${commit}" | \
 89+		sed -E 's@^commit (.*)$@commit <a href="'${relpath}'commit/\1.html">\1</a>@g' >> "${htmldir}/commit/${commit}.html"
 90 	footer >> "${htmldir}/commit/${commit}.html"
 91 done 
 92 
 93+# make log with all commits.
 94+relpath=""
 95+header > "${htmldir}/log.html"
 96+printf '<table border="0">' >> "${htmldir}/log.html"
 97+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"
 98+printf '</table>' >> "${htmldir}/log.html"
 99+footer >> "${htmldir}/log.html"
100+
101 # make index with file links.
102+relpath=""
103 header >> "${htmldir}/files.html"
104-git ls-tree -r master | sed -E 's@	(.*)$@	<a href="file/\1.html">\1</a>@g' >> "${htmldir}/files.html"
105+printf '<table><tr><td><b>Mode</b></td><td><b>Name</b></td><td><b>Size</b></td><td></td></tr>' >> "${htmldir}/files.html"
106+git ls-tree -r -l master | while read -r mode type object size file; do
107+	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}"
108+done >> "${htmldir}/files.html"
109+printf '</table>' >> "${htmldir}/files.html"
110 footer >> "${htmldir}/files.html"
111 
112 # readme page
113 # find README file.
114+relpath=""
115 readme=""
116 for f in README README.md readme.md; do
117 	test -e "${f}" && readme="${f}"
118@@ -123,6 +111,7 @@ footer >> "${htmldir}/readme.html"
119 
120 # license page
121 # find LICENSE file.
122+relpath=""
123 license=""
124 for f in LICENSE LICENSE.md; do
125 	test -e "${f}" && license="${f}"
126@@ -137,6 +126,7 @@ fi
127 footer >> "${htmldir}/license.html"
128 
129 # stats (authors).
130+relpath=""
131 header > "${htmldir}/stats.html"
132 git shortlog -n -s >> "${htmldir}/stats.html"
133 footer >> "${htmldir}/stats.html"