7 files changed,
37 insertions(+),
53 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-02-10 01:39:41 +0200
Change ID:
mwkktmtwmrlqnsvoynuotqkroskuvvrz
Parent:
447b2f5
M
internal/git/diff.go
@@ -26,12 +26,9 @@ }
type NiceDiff struct { Diff []Diff - Commit struct { - Commit - This string - Parent string - } - Stat struct { + Commit *Commit + Parent *Commit + Stat struct { FilesChanged int Insertions int Deletions int@@ -55,15 +52,9 @@ return nil, fmt.Errorf("parsing diff: %w", err)
} nd := NiceDiff{} - nd.Commit.Message = c.Message - nd.Commit.Hash = c.Hash.String() - nd.Commit.HashShort = c.Hash.String()[:8] - nd.Commit.AuthorEmail = c.Author.Email - nd.Commit.AuthorName = c.Author.Name - nd.Commit.This = c.Hash.String() - nd.Commit.Parent = getParentHash(parent) + nd.Commit = newCommit(c) + nd.Parent = newCommit(parent) nd.Stat.FilesChanged = len(diffs) - nd.Diff = make([]Diff, len(diffs)) for i, d := range diffs { diff := &nd.Diff[i]@@ -122,10 +113,3 @@ }
return patch, parent, nil } - -func getParentHash(parent *object.Commit) string { - if parent == nil || parent.Hash.IsZero() { - return "" - } - return parent.Hash.String() -}
M
internal/git/repo.go
@@ -79,6 +79,17 @@ AuthorEmail string
Committed time.Time } +func newCommit(c *object.Commit) *Commit { + return &Commit{ + AuthorEmail: c.Author.Email, + AuthorName: c.Author.Name, + Committed: c.Committer.When, + Hash: c.Hash.String(), + HashShort: c.Hash.String()[:8], + Message: c.Message, + } +} + func (g *Repo) Commits() ([]*Commit, error) { if g.IsEmpty() { return []*Commit{}, nil@@ -94,14 +105,7 @@ }
var commits []*Commit ci.ForEach(func(c *object.Commit) error { - commits = append(commits, &Commit{ - AuthorEmail: c.Author.Email, - AuthorName: c.Author.Name, - Committed: c.Committer.When, - Hash: c.Hash.String(), - HashShort: c.Hash.String()[:8], - Message: c.Message, - }) + commits = append(commits, newCommit(c)) return nil })@@ -118,14 +122,7 @@ if err != nil {
return nil, fmt.Errorf("last commit: %w", err) } - return &Commit{ - AuthorEmail: c.Author.Email, - AuthorName: c.Author.Name, - Committed: c.Committer.When, - Hash: c.Hash.String(), - HashShort: c.Hash.String()[:8], - Message: c.Message, - }, nil + return newCommit(c), nil } func (g *Repo) FileContent(path string) (string, error) {
M
internal/handlers/repo.go
@@ -275,9 +275,10 @@ return
} data := make(map[string]any) - data["stat"] = diff.Stat data["diff"] = diff.Diff data["commit"] = diff.Commit + data["parent"] = diff.Parent + data["stat"] = diff.Stat data["name"] = name data["ref"] = ref data["desc"] = desc
M
web/templates/404.html
@@ -1,8 +1,9 @@
{{ define "404" }} +<!DOCTYPE html> <html> <head> + {{ template "head" . }} <title>404</title> -{{ template "head" . }} </head> <body> <main>
M
web/templates/500.html
@@ -1,8 +1,9 @@
{{ define "500" }} +<!DOCTYPE html> <html> <head> + {{ template "head" . }} <title>500</title> -{{ template "head" . }} </head> <body> <main>
M
web/templates/index.html
@@ -5,11 +5,11 @@ <head>
{{ template "head" . }} <title>{{ .meta.Title }}</title> </head> - <header> - <h1>{{ .meta.Title }}</h1> - <h2>{{ .meta.Description }}</h2> - </header> <body> + <header> + <h1>{{ .meta.Title }}</h1> + <h2>{{ .meta.Description }}</h2> + </header> <main> <table class="table index"> <thead>@@ -20,7 +20,7 @@ <th class="nowrap">Last update</th>
</tr> </thead> <tbody> - {{ range .repos }} + {{- range .repos }} <tr> <td class="nowrap"><a href="/{{ .Name }}">{{ .Name }}</a></td> <td class="fill">{{- if .Desc }}{{ .Desc }}{{- else }}<span class="muted">No description set</span>{{- end }}@@ -31,7 +31,7 @@ <span class="tooltip" role="tooltip">{{- .LastCommit -}}</span>
</span> </td> </tr> - {{ end}} + {{ end }} </tbody> </table> </main>
M
web/templates/repo_commit.html
@@ -2,10 +2,10 @@ {{ define "repo_commit" }}
<html> <head> {{ template "head" . }} - <title>{{ .name }}: {{ .commit.This }}</title> + <title>{{ .name }}: {{ .commit.HashShort }}</title> </head> - {{ template "repo_header" . }} <body> + {{ template "repo_header" . }} <main> <section class="commit"> <div class="box">@@ -21,14 +21,14 @@ <tbody>
<tr> <td class="label nowrap"><strong>commit</strong></td> <td> - <span class="commit-hash">{{ .commit.This }}</span> + <span class="commit-hash">{{ .commit.HashShort }}</span> </td> </tr> - {{ if .commit.Parent }} + {{ if .parent }} <tr> <td class="label nowrap"><strong>parent</strong></td> <td> - <span class="commit-hash">{{ .commit.Parent }}</span> + <span class="commit-hash">{{ .parent.HashShort }}</span> </td> </tr> {{ end }}@@ -69,8 +69,8 @@ </div>
</section> <section> {{ $repo := .name }} - {{ $this := .commit.This }} - {{ $parent := .commit.Parent }} + {{ $this := .commit }} + {{ $parent := .parent }} {{ range .diff }} {{ $path := .Name.New }} {{ if not $path }}{{ $path = .Name.Old }}{{ end }}