Migration This is my new public git source viewer. Source coming soon. Please contact with concerns/bugs. Contact me

internal/modules/commit.go

79436f09f5539aac9b6f836b5b9049bbbece48aa · 897 B · 38 lines raw

1 package modules
2
3 import (
4 "net/http"
5
6 "gsg/internal/core"
7 "gsg/internal/gitx"
8 )
9
10 func init() {
11 core.Register("commit", commitMod)
12 core.Register("diff", diffMod)
13 }
14
15 // commit: metadata for the single commit at Ctx.Commit.
16 func commitMod(c *core.Ctx, args ...string) (any, error) {
17 if c.Commit == "" {
18 return nil, core.Errorf(http.StatusNotFound, "no commit")
19 }
20 log, err := c.Repo.Log(c.Commit, 1, 0, false)
21 if err != nil {
22 return nil, err
23 }
24 if len(log) == 0 {
25 return nil, core.Errorf(http.StatusNotFound, "commit %s not found", c.Commit)
26 }
27 return log[0], nil
28 }
29
30 // diff: the patch for Ctx.Commit. This is the module that static
31 // generation made impractical -- here it is one git process, cached
32 // forever against an immutable SHA.
33 func diffMod(c *core.Ctx, args ...string) (any, error) {
34 if c.Commit == "" {
35 return gitx.Diff{}, nil
36 }
37 return c.Repo.DiffCommit(c.Commit)
38 }