1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/**
* AltGit - altgit
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Paolo Lulli <kevwe.com>
* @copyright Paolo Lulli 2026
*/
package handler
import (
"altgit/internal/config"
"altgit/internal/gitrepo"
"altgit/internal/rendering"
"fmt"
"html/template"
"net/url"
"strings"
"github.com/gin-gonic/gin"
)
// HandleLog GET /:repo/log
func HandleLog(cfg config.AltGitConfiguration) gin.HandlerFunc {
return func(c *gin.Context) {
repoName, rp, ok := rendering.ResolveRepo(cfg, c.Param("repo"))
if !ok {
return
}
pd := rendering.BasePageData(c, repoName, rp, "log",
template.HTML(fmt.Sprintf(
`<a href="/">repos</a> <span class="sep">/</span> <a href="/%s/">%s</a> <span class="sep">/</span> log`,
url.PathEscape(repoName), template.HTMLEscapeString(repoName),
)))
commits, cmd, err := gitrepo.ListLog(rp, pd.Branch, 200)
var body strings.Builder
body.WriteString(fmt.Sprintf(
`<h1 class="page-title">Log</h1>`+
`<p class="page-sub">branch: <strong>%s</strong> · %d commits shown</p>`,
template.HTMLEscapeString(pd.Branch), len(commits),
))
if err != nil || len(commits) == 0 {
body.WriteString(`<div class="empty">No commits found.</div>`)
} else {
body.WriteString(`<div class="log-list">`)
for _, cm := range commits {
body.WriteString(fmt.Sprintf(
`<div class="log-item">`+
`<a class="log-hash" href="/%s/commit?hash=%s&branch=%s">%s</a>`+
`<span class="log-msg">%s</span>`+
`<span class="log-author">%s</span>`+
`<span class="log-date">%s</span>`+
`</div>`,
url.PathEscape(repoName),
url.QueryEscape(cm.Hash), url.QueryEscape(pd.Branch),
template.HTMLEscapeString(cm.Short),
template.HTMLEscapeString(cm.Message),
template.HTMLEscapeString(cm.Author),
template.HTMLEscapeString(cm.Date),
))
}
body.WriteString("</div>")
}
pd.Title = repoName + " — log"
pd.GitCmd = cmd
pd.Body = template.HTML(body.String())
rendering.RenderPage(cfg, c, pd)
}
}
|