7 files changed,
37 insertions(+),
53 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-02-10 01:39:41 +0200
Authored at:
2026-02-09 22:25:02 +0200
Change ID:
mwkktmtwmrlqnsvoynuotqkroskuvvrz
Parent:
447b2f5
M
internal/git/diff.go
路路路 26 26 27 27 type NiceDiff struct { 28 28 Diff []Diff 29 - Commit struct { 30 - Commit 31 - This string 32 - Parent string 33 - } 34 - Stat struct { 29 + Commit *Commit 30 + Parent *Commit 31 + Stat struct { 35 32 FilesChanged int 36 33 Insertions int 37 34 Deletions int 路路路 55 52 } 56 53 57 54 nd := NiceDiff{} 58 - nd.Commit.Message = c.Message 59 - nd.Commit.Hash = c.Hash.String() 60 - nd.Commit.HashShort = c.Hash.String()[:8] 61 - nd.Commit.AuthorEmail = c.Author.Email 62 - nd.Commit.AuthorName = c.Author.Name 63 - nd.Commit.This = c.Hash.String() 64 - nd.Commit.Parent = getParentHash(parent) 55 + nd.Commit = newCommit(c) 56 + nd.Parent = newCommit(parent) 65 57 nd.Stat.FilesChanged = len(diffs) 66 - 67 58 nd.Diff = make([]Diff, len(diffs)) 68 59 for i, d := range diffs { 69 60 diff := &nd.Diff[i] 路路路 122 113 123 114 return patch, parent, nil 124 115 } 125 - 126 -func getParentHash(parent *object.Commit) string { 127 - if parent == nil || parent.Hash.IsZero() { 128 - return "" 129 - } 130 - return parent.Hash.String() 131 -}
M
internal/git/repo.go
路路路 79 79 Committed time.Time 80 80 } 81 81 82 +func newCommit(c *object.Commit) *Commit { 83 + return &Commit{ 84 + AuthorEmail: c.Author.Email, 85 + AuthorName: c.Author.Name, 86 + Committed: c.Committer.When, 87 + Hash: c.Hash.String(), 88 + HashShort: c.Hash.String()[:8], 89 + Message: c.Message, 90 + } 91 +} 92 + 82 93 func (g *Repo) Commits() ([]*Commit, error) { 83 94 if g.IsEmpty() { 84 95 return []*Commit{}, nil 路路路 94 105 95 106 var commits []*Commit 96 107 ci.ForEach(func(c *object.Commit) error { 97 - commits = append(commits, &Commit{ 98 - AuthorEmail: c.Author.Email, 99 - AuthorName: c.Author.Name, 100 - Committed: c.Committer.When, 101 - Hash: c.Hash.String(), 102 - HashShort: c.Hash.String()[:8], 103 - Message: c.Message, 104 - }) 108 + commits = append(commits, newCommit(c)) 105 109 return nil 106 110 }) 107 111 路路路 118 122 return nil, fmt.Errorf("last commit: %w", err) 119 123 } 120 124 121 - return &Commit{ 122 - AuthorEmail: c.Author.Email, 123 - AuthorName: c.Author.Name, 124 - Committed: c.Committer.When, 125 - Hash: c.Hash.String(), 126 - HashShort: c.Hash.String()[:8], 127 - Message: c.Message, 128 - }, nil 125 + return newCommit(c), nil 129 126 } 130 127 131 128 func (g *Repo) FileContent(path string) (string, error) {
M
internal/handlers/repo.go
路路路 275 275 } 276 276 277 277 data := make(map[string]any) 278 - data["stat"] = diff.Stat 279 278 data["diff"] = diff.Diff 280 279 data["commit"] = diff.Commit 280 + data["parent"] = diff.Parent 281 + data["stat"] = diff.Stat 281 282 data["name"] = name 282 283 data["ref"] = ref 283 284 data["desc"] = desc
M
web/templates/index.html
路路路 5 5 {{ template "head" . }} 6 6 <title>{{ .meta.Title }}</title> 7 7 </head> 8 - <header> 9 - <h1>{{ .meta.Title }}</h1> 10 - <h2>{{ .meta.Description }}</h2> 11 - </header> 12 8 <body> 9 + <header> 10 + <h1>{{ .meta.Title }}</h1> 11 + <h2>{{ .meta.Description }}</h2> 12 + </header> 13 13 <main> 14 14 <table class="table index"> 15 15 <thead> 路路路 20 20 </tr> 21 21 </thead> 22 22 <tbody> 23 - {{ range .repos }} 23 + {{- range .repos }} 24 24 <tr> 25 25 <td class="nowrap"><a href="/{{ .Name }}">{{ .Name }}</a></td> 26 26 <td class="fill">{{- if .Desc }}{{ .Desc }}{{- else }}<span class="muted">No description set</span>{{- end }} 路路路 31 31 </span> 32 32 </td> 33 33 </tr> 34 - {{ end}} 34 + {{ end }} 35 35 </tbody> 36 36 </table> 37 37 </main>
M
web/templates/repo_commit.html
路路路 2 2 <html> 3 3 <head> 4 4 {{ template "head" . }} 5 - <title>{{ .name }}: {{ .commit.This }}</title> 5 + <title>{{ .name }}: {{ .commit.HashShort }}</title> 6 6 </head> 7 - {{ template "repo_header" . }} 8 7 <body> 8 + {{ template "repo_header" . }} 9 9 <main> 10 10 <section class="commit"> 11 11 <div class="box"> 路路路 21 21 <tr> 22 22 <td class="label nowrap"><strong>commit</strong></td> 23 23 <td> 24 - <span class="commit-hash">{{ .commit.This }}</span> 24 + <span class="commit-hash">{{ .commit.HashShort }}</span> 25 25 </td> 26 26 </tr> 27 - {{ if .commit.Parent }} 27 + {{ if .parent }} 28 28 <tr> 29 29 <td class="label nowrap"><strong>parent</strong></td> 30 30 <td> 31 - <span class="commit-hash">{{ .commit.Parent }}</span> 31 + <span class="commit-hash">{{ .parent.HashShort }}</span> 32 32 </td> 33 33 </tr> 34 34 {{ end }} 路路路 69 69 </section> 70 70 <section> 71 71 {{ $repo := .name }} 72 - {{ $this := .commit.This }} 73 - {{ $parent := .commit.Parent }} 72 + {{ $this := .commit }} 73 + {{ $parent := .parent }} 74 74 {{ range .diff }} 75 75 {{ $path := .Name.New }} 76 76 {{ if not $path }}{{ $path = .Name.Old }}{{ end }}