commit
message
Rendering files that changed for a commit
author
Ben Vogt <[email protected]>
date
2023-04-04 20:32:00
stats
3 file(s) changed,
33 insertions(+),
6 deletions(-)
files
commit.go
gshr.css
templates/commit.html
1diff --git a/commit.go b/commit.go
2index c9a822b..45a6717 100644
3--- a/commit.go
4+++ b/commit.go
5@@ -27,6 +27,7 @@ type CommitPage struct {
6 FileChangeCount int
7 LinesAdded int
8 LinesDeleted int
9+ FilesChanged []string
10 DiffContent template.HTML
11 }
12
13@@ -54,6 +55,8 @@ func RenderAllCommitPages(r *git.Repository) {
14 checkErr(err)
15 }
16 diffContent := template.HTML("")
17+ filesChangedMap := make(map[string]bool)
18+ filesChanged := []string{}
19 if parent != nil {
20 lexer := lexers.Match("x.diff")
21 if lexer == nil {
22@@ -77,6 +80,23 @@ func RenderAllCommitPages(r *git.Repository) {
23 err = formatter.Format(buf, style, iterator)
24 checkErr(err)
25 diffContent = template.HTML(buf.String())
26+ for _, fp := range patch.FilePatches() {
27+ from, to := fp.Files()
28+ if from != nil {
29+ filePath := from.Path()
30+ if _, found := filesChangedMap[filePath]; !found {
31+ filesChangedMap[filePath] = true
32+ filesChanged = append(filesChanged, filePath)
33+ }
34+ }
35+ if to != nil {
36+ filePath := to.Path()
37+ if _, found := filesChangedMap[filePath]; !found {
38+ filesChangedMap[filePath] = true
39+ filesChanged = append(filesChanged, filePath)
40+ }
41+ }
42+ }
43 }
44 stats, err := c.Stats()
45 added := 0
46@@ -97,6 +117,7 @@ func RenderAllCommitPages(r *git.Repository) {
47 FileChangeCount: len(stats),
48 LinesAdded: added,
49 LinesDeleted: deleted,
50+ FilesChanged: filesChanged,
51 DiffContent: diffContent,
52 }).Render(t)
53 return nil
54diff --git a/gshr.css b/gshr.css
55index ff70099..edd175c 100644
56--- a/gshr.css
57+++ b/gshr.css
58@@ -267,6 +267,7 @@ div.content * tr:hover {
59 div.content * td {
60 padding: 0 0.4em;
61 max-width: 380px;
62+ vertical-align: top;
63 }
64
65 .chroma {
66diff --git a/templates/commit.html b/templates/commit.html
67index 8e7d723..2f27c1b 100644
68--- a/templates/commit.html
69+++ b/templates/commit.html
70@@ -31,17 +31,22 @@
71 <td><b>message: </b></td>
72 <td> {{ .Message }}</td>
73 </tr>
74- </tbody>
75- </table>
76- <table>
77- <tbody>
78 <tr>
79+ <td><b>stats: </b></td>
80 <td>
81 {{ .FileChangeCount }} file(s) changed,
82 {{ .LinesAdded }} insertions(+),
83 {{ .LinesDeleted }} deletions(-)
84 </td>
85 </tr>
86+ <tr>
87+ <td><b>files: </b></td>
88+ <td>
89+ {{ range .FilesChanged }}
90+ <div>{{ . }}</div>
91+ {{ end }}
92+ </td>
93+ </tr>
94 </tbody>
95 </table>
96 {{ .DiffContent }}