commit 8c023307369cfaf937a6dbf0fdfca145366cfe72
Author: David Voznyarskiy <davidv@no-reply@disroot.org>
Date: Sun Apr 12 20:54:44 2026 -0700
lot of optimizations by removing the unnessecary amount of exec.Commands
Signed-off-by: David Voznyarskiy <davidv@no-reply@disroot.org>
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..fdddb29
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <https://unlicense.org>
diff --git a/README.md b/README.md
index b746c28..72c2bbb 100644
--- a/README.md
+++ b/README.md
@@ -48,10 +48,9 @@ generate pages for a repository
shgit repo output_dir
shgit repo
-Still very much a work in progress. Shgit takes a repository as an
-argument and outputs multiple HTML files and directories into either a
-specified directory or, if no output directory is given, into the
-working directory.
+Shgit takes a repository as an argument and outputs multiple HTML files
+and directories into either a specified directory or, if no output
+directory is given, into the working directory.
Within shgit/config.go configuration of the logo and favicon as well
as some HTML elements can be set.
diff --git a/shgit/logs.go b/shgit/logs.go
index 839d9c9..157b5c4 100644
--- a/shgit/logs.go
+++ b/shgit/logs.go
@@ -31,11 +31,11 @@ func logTest(repo string, path string) {
panic(err)
}
- hashes := strings.Split(strings.TrimSpace(string(cmd)), "\n")
+ hashes := strings.SplitSeq(strings.TrimSpace(string(cmd)), "\n")
// TODO fix formatting
// TODO add coloring and links
- for _, hash := range hashes {
+ for hash := range hashes {
cmd, err := exec.Command(
"git",
"-C",
@@ -105,95 +105,58 @@ func logPage(topPart string, repo string, path string, numofCommits int) {
for i := range numofCommits {
file.WriteString("<tr>")
- cmd, _ := exec.Command(
+ cmd, err := exec.Command(
"git",
"-C", repo,
"log", "-1",
fmt.Sprintf("--skip=%d", i),
- "--pretty=format:%cd",
- "--date=format:%Y-%m-%d",
- ).Output()
- date := strings.TrimSpace(string(cmd))
- file.WriteString("<td valign=\"top\">")
- file.WriteString(date)
-
- file.WriteString("</td>\n")
-
- cmd, _ = exec.Command(
- "git",
- "-C", repo,
- "show",
- fmt.Sprintf("HEAD~%d", i),
+ "--shortstat",
+ "--pretty=format:%ai%n%an%n%s%n%H",
).Output()
+ if err != nil {
+ panic(err)
+ }
- // commit := strings.TrimSpace(string(cmd))
+ commitInfo := strings.Split(string(cmd), "\n")
+ timeofCommit := commitInfo[0]
+ authorofCommit := commitInfo[1]
+ commitMessageTest := commitInfo[2]
+ commitHash := commitInfo[3]
+ shortStatInfo := commitInfo[4]
- lines := strings.Split(string(cmd), "\n")
- var firstLine string
- var hash string
- if lines[0] != "" {
- firstLine = lines[0]
- } else {
- return
- }
+ file.WriteString("<td valign=\"top\">")
- fields := strings.Fields(firstLine)
- hash = fields[1]
+ dateofCommit := strings.SplitN(timeofCommit, " ", 2)[0]
+ file.WriteString(dateofCommit) // YYYY-MM-DD
- cmd, _ = exec.Command(
- "git",
- "-C", repo,
- "log", "-1",
- fmt.Sprintf("--skip=%d", i),
- "--pretty=format:%s",
- ).Output()
- commit := strings.TrimSpace(string(cmd))
- file.WriteString("<td>")
- file.WriteString("\n<a href=\"logs/")
- file.WriteString(hash)
- file.WriteString(".html\">" + commit + "</a>\n")
+ file.WriteString("</td>\n<td>\n<a href=\"logs/")
+ file.WriteString(commitHash)
+ file.WriteString(".html\">" + commitMessageTest + "</a>\n")
file.WriteString("</td>\n")
- cmd, _ = exec.Command(
- "git",
- "-C", repo,
- "log", "-1",
- fmt.Sprintf("--skip=%d", i),
- "--pretty=format:%an",
- ).Output()
- author := strings.TrimSpace(string(cmd))
file.WriteString("<td style=\"white-space:nowrap\" valign=\"top\">")
- file.WriteString(author)
+ file.WriteString(authorofCommit)
file.WriteString("</td>\n")
- cmd, _ = exec.Command(
- "git",
- "-C", repo,
- "log", "-1",
- fmt.Sprintf("--skip=%d", i),
- "--shortstat",
- "--pretty=format:",
- ).Output()
- cmdOutput := strings.TrimSpace(string(cmd))
+ cmdOutput := strings.TrimSpace(string(shortStatInfo))
arr := strings.Fields(cmdOutput)
if len(arr) == 0 {
continue
}
file.WriteString("<td style=\"padding-left: 1em\" valign=\"top\" align=\"right\">")
- file.WriteString(arr[0])
+ file.WriteString(arr[0]) // files edited
file.WriteString("</td>\n")
file.WriteString("<td style=\"color:ForestGreen\" valign=\"top\" align=\"right\">+")
- file.WriteString(arr[3])
+ file.WriteString(arr[3]) // lines added
file.WriteString("</td>\n")
if len(arr) > 5 {
file.WriteString("<td style=\"color:Crimson\" valign=\"top\" align=\"right\">-")
- file.WriteString(arr[5])
+ file.WriteString(arr[5]) // lines removed
file.WriteString("</td>\n")
}
file.WriteString("\n</tr>")
}
- file.WriteString("\n</table>")
- file.WriteString("\n</body>")
+ file.WriteString("\n</table>\n</body>")
}
diff --git a/shgit/shared.go b/shgit/shared.go
index 0297e90..228d9d6 100644
--- a/shgit/shared.go
+++ b/shgit/shared.go
@@ -69,7 +69,7 @@ var genTopPart = func(repo string, depth int) string {
b.WriteString("<style>")
b.WriteString(styles["codeline"])
- b.WriteString("</style>\n")
+ b.WriteString("\n</style>\n")
b.WriteString("</head>\n")
diff --git a/shgit/shgit.go b/shgit/shgit.go
index 2a99f6b..3b48283 100644
--- a/shgit/shgit.go
+++ b/shgit/shgit.go
@@ -119,72 +119,37 @@ func indexPageCommitTable(numofCommits int, file *os.File, repo string, path str
"-C", repo,
"log", "-1",
fmt.Sprintf("--skip=%d", i),
- "--pretty=format:%cd",
- "--date=format:%Y-%m-%d",
+ "--pretty=format:%ai%n%an%n%s%n%H",
).Output()
if err != nil {
panic(err)
}
- commit := strings.TrimSpace(string(cmd))
+ commitInfo := strings.Split(string(cmd), "\n")
+ timeofCommit := commitInfo[0]
+ authorofCommit := commitInfo[1]
+ commitMessage := commitInfo[2]
+ commitHash := commitInfo[3]
+
file.WriteString("<td valign=\"top\">")
- file.WriteString(commit)
+ dateofCommit := strings.SplitN(timeofCommit, " ", 2)[0]
+ file.WriteString(dateofCommit)
file.WriteString("</td>\n")
- cmd, _ = exec.Command(
- "git",
- "-C",
- repo,
- "show",
- fmt.Sprintf("HEAD~%d", i),
- ).Output()
-
- // commit := strings.TrimSpace(string(cmd))
-
- lines := strings.Split(string(cmd), "\n")
- var firstLine string
- var hash string
- if lines[0] != "" {
- firstLine = lines[0]
- } else {
- return
- }
-
- fields := strings.Fields(firstLine)
- hash = fields[1]
-
- cmd, _ = exec.Command(
- "git",
- "-C", repo,
- "log", "-1",
- fmt.Sprintf("--skip=%d", i),
- "--pretty=format:%s",
- ).Output()
- commit = strings.TrimSpace(string(cmd))
maxLen := 45
- if len(commit) > maxLen {
- commit = commit[:maxLen] + "..."
+ if len(commitMessage) > maxLen {
+ commitMessage = commitMessage[:maxLen] + "..."
}
file.WriteString("<td valign=\"top\">")
file.WriteString("<a href=\"logs/")
- file.WriteString(hash)
- file.WriteString(".html\">" + commit + "</a>")
+ file.WriteString(commitHash)
+ file.WriteString(".html\">" + commitMessage + "</a>")
file.WriteString("</td>\n")
- cmd, _ = exec.Command(
- "git",
- "-C", repo,
- "log", "-1",
- fmt.Sprintf("--skip=%d", i),
- "--pretty=format:%an",
- ).Output()
- commit = strings.TrimSpace(string(cmd))
file.WriteString("<td valign=\"top\">")
- file.WriteString(commit)
- file.WriteString("</td>\n")
-
- file.WriteString("</tr>")
+ file.WriteString(authorofCommit)
+ file.WriteString("</td>\n</tr>")
// index.html will only be showing the 5 latest or less commits
if i == 4 {
@@ -193,5 +158,4 @@ func indexPageCommitTable(numofCommits int, file *os.File, repo string, path str
}
file.WriteString("</table>")
- file.WriteString("</body>")
}