gshr
git static host repo -- generates static html for repos
git clone https://git.vogt.world/gshr.git
Log | Files | README.md | LICENSE
← Commit log
commit
message
Stats for lines added/deleted per commit
author
Ben Vogt <[email protected]>
date
2023-04-03 23:25:28
stats
2 file(s) changed, 13 insertions(+), 2 deletions(-)
files
log.template.html
main.go
 1diff --git a/log.template.html b/log.template.html
 2index b77ecae..fc325d5 100644
 3--- a/log.template.html
 4+++ b/log.template.html
 5@@ -64,8 +64,8 @@
 6             <td class="commit"><a href="commit/{{ .Hash }}">{{ .Message }}</a></td>
 7             <td>{{ .Author }}</td>
 8             <td align="right">{{ .FileChangeCount }}</td>
 9-            <td align="right">+2</td>
10-            <td align="right">-0</td>
11+            <td align="right">+{{ .LinesAdded }}</td>
12+            <td align="right">-{{ .LinesDeleted }}</td>
13           </tr>
14           {{ end }}
15         </tbody>
16diff --git a/main.go b/main.go
17index 58b1ad0..71c387e 100644
18--- a/main.go
19+++ b/main.go
20@@ -176,6 +176,8 @@ type Commit struct {
21 	Hash            string
22 	Message         string
23 	FileChangeCount int
24+	LinesAdded      int
25+	LinesDeleted    int
26 }
27 
28 type LogPage struct {
29@@ -228,6 +230,13 @@ func RenderLogPage(r *git.Repository) {
30 
31 	err = cIter.ForEach(func(c *object.Commit) error {
32 		stats, err := c.Stats()
33+		added := 0
34+		deleted := 0
35+		for i := 0; i < len(stats); i++ {
36+			stat := stats[i]
37+			added += stat.Addition
38+			deleted += stat.Deletion
39+		}
40 		checkErr(err)
41 		commits = append(commits, Commit{
42 			Author:          c.Author.Name,
43@@ -235,6 +244,8 @@ func RenderLogPage(r *git.Repository) {
44 			Date:            c.Author.When.UTC().Format("2006-01-02 15:04:05"),
45 			Hash:            c.Hash.String(),
46 			FileChangeCount: len(stats),
47+			LinesAdded:      added,
48+			LinesDeleted:    deleted,
49 		})
50 		return nil
51 	})