git3html

git clone https://orangeshoelaces.net/git/git3html.git

bee23b327e40c86c3a318e91422e34aed88a163d

Author: Vasilii Kolobkov on 01/14/2019

Committer: Vasilii Kolobkov on 01/14/2019

Try not to output any superfluous line breaks within <pre>s

Stats

git3html | 43 +++-----
1 file changed, 14 insertions(+), 29 deletions(-)

Patch

diff --git a/git3html b/git3html
index fd38d0c..e5009a1 100755
--- a/git3html
+++ b/git3html
@@ -134,11 +134,11 @@ footer() {
 readme() (
 	header "${projname} readme" .
 	root=$(tmrc)
-	echo '<pre>'
+	printf '<pre>'
 	g ls-tree --name-only "$root" | grep '^README*' | while read -r readme; do
 		g cat-file --textconv "$root:$readme" | escape
 	done
-	echo '</pre>'
+	printf '</pre>'
 	footer
 )
 
@@ -150,45 +150,29 @@ commit() (
 		header "${projname} commit ${shortid}" ..
 		printf '<h2>%s<span class="id-suffix">%s</h2>\n' "$shortid" \
 			"$(echo "$id" | cut -c "$(expr ${#shortid} + 1)-")"
-		cat <<-END
-		<pre>
-		<code>
-		END
+		printf '<pre><code>'
 		for v in an ae ad cn ce cd; do
 			IFS= read -r "$v"
 		done
 		printf 'Author:    <a href="mailto:%s">%s</a> on %s\n' "$ae" "$an" "$ad"
-		printf 'Committer: <a href="mailto:%s">%s</a> on %s\n' "$ce" "$cn" "$cd"
-		cat <<-END
-		</code>
-		</pre>
-		END
+		printf 'Committer: <a href="mailto:%s">%s</a> on %s' "$ce" "$cn" "$cd"
+		printf '</code></pre>\n'
 	}
-	cat <<-END
-	<h3>Stats</h3>
-	<pre>
-	<code>
-	END
+	printf '<h3>Stats</h3>\n'
+	printf '<pre><code>'
 	g diff-tree --stat --stat-graph-width=8 "$id" | tail -n +2 | escape | sed \
 		's/^[[:space:]]*//;
 		s#\(+*\)\(-*\)$#<span class="add">\1</span><span class="delete">\2</span>#'
-	cat <<-END
-	</code>
-	</pre>
-	<h3>Patch</h3>
-	<pre>
-	<code>
-	END
+	printf '</code></pre>\n'
+	printf '<h3>Patch</h3>\n'
+	printf '<pre><code>'
 	g diff-tree -p "$id" | tail -n +2 | escape | sed "\
 		$(for p in diff old new deleted copy rename similarity dissimilarity index; do
 			echo "/^$p/ { s,^,<span class=\"hunk-header\">,; s,$,</span>,; }"
 		done;)
 		/^+/ { s,^,<span class=\"add\">,; s,$,</span>,; }
 		/^-/ { s,^,<span class=\"delete\">,; s,$,</span>,; }"
-	cat <<-END
-	</code>
-	</pre>
-	END
+	printf '</code></pre>\n'
 	footer
 )
 
@@ -270,13 +254,14 @@ textfile() (
 	relbaseoutdir="$3"
 
 	header "${reppath}:" "$relbaseoutdir"
-	printf '<code>%s:</code>\n<pre>\n<code>\n' "$(echo "$reppath" | escape)"
+	printf '<h2>%s</h2>\n' "$(echo "$reppath" | escape)"
+	printf '<pre><code>'
 	n=0
 	g cat-file blob "$blob" | escape | awk -F '' '{
 		++n
 		printf "<a href=\"#l%d\">%4d</a> %s\n", n, n, $0
 	}'
-	printf '</code>\n</pre>\n'
+	printf '</code></pre>\n'
 	footer
 )