🢀︎ stagit :: 951717c


commit 951717ce3d91ece220af28d0cb413a9988e53927
Author: acidvegas <acid.vegas@acid.vegas>
Date:   Fri Jul 5 23:31:58 2019 -0400

    Added MAX_COMMIT_LINES option to truncate commit lines

diff --git a/stagit b/stagit
index f36477e..a8402e9 100755
--- a/stagit
+++ b/stagit
@@ -1,15 +1,16 @@
 #!/bin/sh
 set -e
 
-##### settings ######################################################################
-CLONE_URL='remote' # base url for cloning repositories ('remote' = remote.origin.url)
-CNAME=''           # create a CNAME file with a custom domain (empty = do not create)
-MAX_COMMITS=100    # maximum number of commits to show (0 = all)
-MAX_COMMIT_MSG=100 # maximum characters in a commit message to display (0 = all)
-REPO_DIR=$HOME/git # directory containing repositories
-THEME='light'      # default style used ('light' or 'dark')
-WWW_DIR=$HOME/www  # directory to output to
-#####################################################################################
+##### settings ########################################################################
+CLONE_URL='remote'   # base url for cloning repositories ('remote' = remote.origin.url)
+CNAME=''             # create a CNAME file with a custom domain (empty = do not create)
+MAX_COMMITS=100      # maximum number of commits to show (0 = all)
+MAX_COMMIT_MSG=100   # maximum characters in a commit message to display (0 = all)
+MAX_COMMIT_LINES=999 # maximum number of lines to show in a commit (0 = all)
+REPO_DIR=$HOME/git   # directory containing repositories
+THEME='light'        # default style used ('light' or 'dark')
+WWW_DIR=$HOME/www    # directory to output to
+#######################################################################################
 
 generate_css() {
 	if [ $THEME = 'light' ]; then
@@ -87,7 +88,8 @@ generate_commit_index() {
 			"<meta charset=\"UTF-8\">\n"\
 			"<title>$REPO_NAME :: $COMMIT_HASH</title>\n"\
 			"<h1><a href=\"../index.html\" title=\"Back to Repository\">&#x1F880;</a> $REPO_NAME :: $COMMIT_HASH</h1>\n"\
-			"<hr><pre>" >> $WWW_DIR/$REPO_NAME/commit/$COMMIT_HASH.html
+			"<hr>\n"\
+			"<pre>" >> $WWW_DIR/$REPO_NAME/commit/$COMMIT_HASH.html
 }
 
 [ ! -d $REPO_DIR ] && echo "'$REPO_DIR' directory does not exist" && exit 1
@@ -141,7 +143,11 @@ for d in $(find $REPO_DIR -name .git -type d -prune | sort); do # todo: sort by
 		COMMIT_DATE=$(echo $line | cut -d'|' -f7)
 		echo "<tr class=\"item\"><td>$COMMIT_SIGNED <a href=\"commit/$COMMIT_HASH.html\" title=\"View this commit\">$COMMIT_HASH</a></td><td>$COMMIT_MESSAGE</td><td>$COMMIT_AUTHOR</td><td>$COMMIT_DATE</td></tr>" >> $WWW_DIR/$REPO_NAME/index.html
 		generate_commit_index $REPO_NAME $COMMIT_HASH
-		COMMIT_DIFF=$(git --git-dir $d show $COMMIT_HASH | sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/"/\&quot;/g;')
+		COMMIT_DIFF=$(git --git-dir $d show $COMMIT_HASH) # todo: convert terminal colors to html
+		if [ $MAX_COMMIT_LINES -ne 0 -a $(echo "$COMMIT_DIFF" | wc -l) -gt $MAX_COMMIT_LINES ]; then
+			COMMIT_DIFF=$(echo "$COMMIT_DIFF" | head -n $MAX_COMMIT_LINES)
+		fi
+		COMMIT_DIFF=$(echo "$COMMIT_DIFF" | sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/"/\&quot;/g;' | tr -d '\r')
 		echo "$COMMIT_DIFF" | while IFS= read -r line; do
 			echo "<code>$line</code>" >> $WWW_DIR/$REPO_NAME/commit/$COMMIT_HASH.html
 		done