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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
diff --git a/Makefile b/Makefile
index d44c3e0bb481f1543e6c732face81161bf9330ea..41eb273c916e1ac6f7b65f06eb69485b83f68ee4 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,8 @@ THEME_DIR=./themes REPO_PATH=./repos LOG_LEVEL=debug \
$(GO) run github.com/cosmtrek/air@latest \
-build.cmd="make gogit" \
-build.bin="./gogit" \
- -build.exclude_regex="(themes/|repos/|Makefile)" \
+ -build.exclude_regex="(repos/|Makefile)" \
+ -build.rerun_delay=500ms \
-screen.clear_on_rebuild=true
.PHONY: lint
diff --git a/internal/handler/repo.go b/internal/handler/repo.go
index 216445ed19d73642491c5fd433b44df5591974cf..882cf3ddc1faae267ffdd98d142bc2ddcc35e2fb 100644
--- a/internal/handler/repo.go
+++ b/internal/handler/repo.go
@@ -19,6 +19,8 @@ case "":
templates.Overview(repo)(ctx)
case "log":
logHandler(repo)(ctx)
+ case "tag":
+ tagHandler(repo)(ctx)
case "commit":
commitHandler(repo)(ctx)
default:
diff --git a/internal/handler/tag.go b/internal/handler/tag.go
new file mode 100644
index 0000000000000000000000000000000000000000..f73466757683da6d3f0ef3f4651ad944769689ec
--- /dev/null
+++ b/internal/handler/tag.go
@@ -0,0 +1,30 @@
+package handler
+
+import (
+ "path"
+ "strings"
+
+ "git.sr.ht/~mpldr/gogit/internal/conman"
+ "git.sr.ht/~mpldr/gogit/internal/handler/templates"
+ "git.sr.ht/~mpldr/gogit/internal/types"
+ "github.com/valyala/fasthttp"
+)
+
+func tagHandler(repo *types.Repo) fasthttp.RequestHandler {
+ return func(ctx *fasthttp.RequestCtx) {
+ tag := strings.TrimPrefix(string(ctx.Path()), path.Join(repo.Path, "tag"))
+ tag, _, _ = strings.Cut(strings.TrimPrefix(tag, "/"), "/")
+
+ log := conman.GetLogger(ctx)
+ log.Debug("rendering tag", "path", ctx.Path(), "tag", tag)
+
+ tagData := repo.Tag(tag)
+ if tagData == nil {
+ errorHandler(ctx, ErrNotFound)
+ return
+ }
+
+ ctx.SetContentType("text/html; charset=utf-8")
+ templates.Tag(tagData)(ctx)
+ }
+}
diff --git a/internal/handler/templates/parse.go b/internal/handler/templates/parse.go
index e20e75a1eeafe7d312ff5e15760c7caa439ce300..0edc2e67cb378307d4510ef3340ddf6c6890b23a 100644
--- a/internal/handler/templates/parse.go
+++ b/internal/handler/templates/parse.go
@@ -40,4 +40,5 @@ "index": &indexTmpl,
"overview": &overviewTmpl,
"commit": &commitTmpl,
"log": &logTmpl,
+ "tag": &tagTmpl,
}
diff --git a/internal/handler/templates/tag.go b/internal/handler/templates/tag.go
new file mode 100644
index 0000000000000000000000000000000000000000..ec9a405b89f048b8040562ddab469d1251475d57
--- /dev/null
+++ b/internal/handler/templates/tag.go
@@ -0,0 +1,21 @@
+package templates
+
+import (
+ "html/template"
+ "log/slog"
+
+ "git.sr.ht/~mpldr/gogit/internal/types"
+ "github.com/valyala/fasthttp"
+)
+
+var tagTmpl *template.Template
+
+func Tag(data *types.Tag) fasthttp.RequestHandler {
+ return func(ctx *fasthttp.RequestCtx) {
+ ctx.SetContentType("text/html; charset=utf-8")
+ err := tagTmpl.Execute(ctx, data)
+ if err != nil {
+ slog.Error("failed to execute template", "template", "tag", "error", err)
+ }
+ }
+}
diff --git a/internal/types/repo.go b/internal/types/repo.go
index 2e67222cf8a0db1fdb5a20d47aa9c971b342d71e..b8d9190b1f0d37355a8ccf847c3cb1229a37a26c 100644
--- a/internal/types/repo.go
+++ b/internal/types/repo.go
@@ -140,3 +140,11 @@ }
return results
}
+
+func (r *Repo) Tag(tag string) *Tag {
+ tagObj, err := r.repo.Tag(tag)
+ if err != nil {
+ return nil
+ }
+ return NewTag(tagObj, r)
+}
diff --git a/internal/types/tag.go b/internal/types/tag.go
new file mode 100644
index 0000000000000000000000000000000000000000..13b7b89f2fc793e3d9832fb9a049ff644357b381
--- /dev/null
+++ b/internal/types/tag.go
@@ -0,0 +1,34 @@
+package types
+
+import (
+ "github.com/go-git/go-git/v5/plumbing"
+ "github.com/go-git/go-git/v5/plumbing/object"
+)
+
+type Tag struct {
+ ref *plumbing.Reference
+ repo *Repo
+}
+
+func NewTag(ref *plumbing.Reference, repo *Repo) *Tag {
+ return &Tag{
+ ref: ref,
+ repo: repo,
+ }
+}
+
+func (t *Tag) Object() *object.Tag {
+ tag, err := t.repo.repo.TagObject(t.ref.Hash())
+ if err != nil {
+ return nil
+ }
+ return tag
+}
+
+func (t *Tag) Hash() string {
+ return t.ref.Hash().String()
+}
+
+func (t *Tag) Name() string {
+ return t.ref.Name().Short()
+}
diff --git a/themes/i-am-too-lazy-to-make-a-theme/overview.html b/themes/i-am-too-lazy-to-make-a-theme/overview.html
index 972361c77b03105fbbc40e55e56a91be30a36d2b..21f3b555a3c0be2eceac71eb6ef07f4c803aaa10 100644
--- a/themes/i-am-too-lazy-to-make-a-theme/overview.html
+++ b/themes/i-am-too-lazy-to-make-a-theme/overview.html
@@ -19,7 +19,7 @@ </ul>
<h2>Tags</h2>
<ul>
{{range .Tags}}
- <li><a href="{{$Path}}/ref/{{.Name.Short}}">{{.Name.Short}}</a></li>
+ <li><a href="{{$Path}}/tag/{{.Name.Short}}">{{.Name.Short}}</a></li>
{{end}}
</ul>
<h2>Commits</h2>
diff --git a/themes/i-am-too-lazy-to-make-a-theme/tag.html b/themes/i-am-too-lazy-to-make-a-theme/tag.html
new file mode 100644
index 0000000000000000000000000000000000000000..e4116f2fcb07ef1f397aad6b75cefc6323d1dad6
--- /dev/null
+++ b/themes/i-am-too-lazy-to-make-a-theme/tag.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>Log</title>
+ </head>
+ <body>
+ <h1 class="title">
+ Tag: {{.Name}}
+ </h1>
+ {{with .Object}}
+ Tagger: <code>{{.Tagger.Name}} <{{.Tagger.Email}}> at {{.Tagger.When}}</code><br>
+ On: <a href="../commit/{{.Target}}">{{.Target}}</a>
+ <pre>{{.Message}}</pre>
+ {{end}}
+ </body>
+</html>
|