5 files changed,
71 insertions(+),
79 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-02-10 01:39:54 +0200
Authored at:
2026-02-09 23:16:21 +0200
Change ID:
ssoxxkyolnpymuymqtoxxouokwmssyuk
Parent:
fb69639
M
internal/git/diff.go
路路路 25 25 } 26 26 27 27 type NiceDiff struct { 28 - Diff []Diff 29 - Commit *Commit 30 - Parent *Commit 31 - Stat struct { 28 + Diff []Diff 29 + Commit *Commit 30 + Parents []string // list of short hashes 31 + Stat struct { 32 32 FilesChanged int 33 33 Insertions int 34 34 Deletions int 路路路 41 41 return nil, fmt.Errorf("commit object: %w", err) 42 42 } 43 43 44 - patch, parent, err := g.getPatch(c) 44 + patch, parents, err := g.getPatch(c) 45 45 if err != nil { 46 46 return nil, err 47 47 } 路路路 53 53 54 54 nd := NiceDiff{} 55 55 nd.Commit = newCommit(c) 56 - nd.Parent = newCommit(parent) 56 + nd.Parents = parents 57 57 nd.Stat.FilesChanged = len(diffs) 58 58 nd.Diff = make([]Diff, len(diffs)) 59 59 for i, d := range diffs { 路路路 84 84 return &nd, nil 85 85 } 86 86 87 -func (g *Repo) getPatch(c *object.Commit) (*object.Patch, *object.Commit, error) { 87 +func (g *Repo) getPatch(c *object.Commit) (*object.Patch, []string, error) { 88 88 commitTree, err := c.Tree() 89 89 if err != nil { 90 90 return nil, nil, err 91 91 } 92 92 93 - var parentTree *object.Tree 94 - var parent *object.Commit 95 - 96 - if c.NumParents() != 0 { 97 - parent, err = c.Parents().Next() 98 - if err != nil { 99 - return nil, nil, err 93 + parentTree := &object.Tree{} 94 + if c.NumParents() > 0 { 95 + parent, perr := c.Parents().Next() 96 + if perr != nil { 97 + return nil, nil, perr 100 98 } 101 - parentTree, err = parent.Tree() 102 - if err != nil { 99 + if parentTree, err = parent.Tree(); err != nil { 103 100 return nil, nil, err 104 101 } 105 - } else { 106 - parentTree = &object.Tree{} 107 102 } 108 103 109 104 patch, err := parentTree.Patch(commitTree) 路路路 111 106 return nil, nil, fmt.Errorf("patch: %w", err) 112 107 } 113 108 114 - return patch, parent, nil 109 + parents := make([]string, len(c.ParentHashes)) 110 + for i, h := range c.ParentHashes { 111 + parents[i] = newShortHash(h) 112 + } 113 + 114 + return patch, parents, nil 115 115 }
M
internal/git/repo.go
路路路 79 79 Committed time.Time 80 80 } 81 81 82 +func newShortHash(h plumbing.Hash) string { return h.String()[:7] } 82 83 func newCommit(c *object.Commit) *Commit { 83 84 return &Commit{ 84 85 AuthorEmail: c.Author.Email, 85 86 AuthorName: c.Author.Name, 86 87 Committed: c.Committer.When, 87 88 Hash: c.Hash.String(), 88 - HashShort: c.Hash.String()[:8], 89 + HashShort: newShortHash(c.Hash), 89 90 Message: c.Message, 90 91 } 91 92 }
M
web/templates/repo_commit.html
路路路 8 8 {{ template "repo_header" . }} 9 9 <main> 10 10 <section class="commit"> 11 + <div class="commit-refs"> 12 + {{ .stat.FilesChanged }} files changed, 13 + {{ .stat.Insertions }} insertions(+), 14 + {{ .stat.Deletions }} deletions(-) 15 + </div> 16 + 11 17 <div class="box"> 12 - <div class="commit-info"> 13 - <span class="commit-date">{{ .commit.Committed }}</span> 14 - {{ .commit.AuthorName }} <a href="mailto:{{ .commit.AuthorEmail }}" class="commit-email">{{ .commit.AuthorEmail }}</a> 18 + <pre class="commit-message">{{ .commit.Message }}</pre> 19 + <div> 20 + <strong>Author:</strong> 21 + {{ .commit.AuthorName }} 22 + <a href="mailto:{{ .AuthorEmail }}" class="commit-email">{{ .commit.AuthorEmail }}</a> 23 + </div> 24 + <div> 25 + <strong>Committed at:</strong> 26 + {{ .commit.Committed }} 15 27 </div> 16 - <pre class="commit-message">{{- .commit.Message -}}</pre> 17 - </div> 18 - 19 - <table class="table commit-refs"> 20 - <tbody> 21 - <tr> 22 - <td class="label nowrap"><strong>commit</strong></td> 23 - <td> 24 - <span class="commit-hash">{{ .commit.HashShort }}</span> 25 - </td> 26 - </tr> 27 - {{ if .parent }} 28 - <tr> 29 - <td class="label nowrap"><strong>parent</strong></td> 30 - <td> 31 - <span class="commit-hash">{{ .parent.HashShort }}</span> 32 - </td> 33 - </tr> 34 - {{ end }} 35 - </tbody> 36 - </table> 37 - 38 - <div class="diff-stat"> 39 28 <div> 40 - {{ .stat.FilesChanged }} files changed, 41 - {{ .stat.Insertions }} insertions(+), 42 - {{ .stat.Deletions }} deletions(-) 29 + <strong>Parent:</strong> 30 + {{ range $i, $p := .parents -}} 31 + {{ if $i }}, {{ end -}} 32 + <a href="/{{ $.name }}/commit/{{ $p }}">{{ $p }}</a> 33 + {{- end }} 43 34 </div> 35 + </div> 44 36 45 - {{ if gt (len .diff) 1}} 46 - <div class="jump"> 47 - <strong>jump to</strong> 48 - <table class="table jump-table"> 49 - <tbody> 50 - {{ range .diff }} 51 - {{ $path := .Name.New }} 52 - {{ if not $path }}{{ $path = .Name.Old }}{{ end }} 53 - <tr> 54 - <td class="diff-type"> 55 - {{ if .IsNew }}<span class="diff-type diff-add">A</span>{{ end }} 56 - {{ if .IsDelete }}<span class="diff-type diff-del">D</span>{{ end }} 57 - {{ if not (or .IsNew .IsDelete) }}<span class="diff-type diff-mod">M</span>{{ end }} 58 - </td> 59 - <td class="fill"> 60 - <a href="#{{ $path }}"> 61 - {{ if and .Name.Old .Name.New }}{{ .Name.Old }} → {{ .Name.New }}{{ else }}{{ $path }}{{ end }} 62 - </a> 63 - </td> 64 - </tr> 65 - {{ end }} 66 - </tbody> 67 - </table> 68 - </div> 69 - {{ end }} 37 + {{ if gt (len .diff) 1 -}} 38 + <div class="jump"> 39 + <strong>jump to</strong> 40 + <table class="table jump-table"> 41 + <tbody> 42 + {{ range .diff }} 43 + {{ $path := .Name.New }} 44 + {{ if not $path }}{{ $path = .Name.Old }}{{ end }} 45 + <tr> 46 + <td class="diff-type"> 47 + {{ if .IsNew }}<span class="diff-type diff-add">A</span>{{ end }} 48 + {{ if .IsDelete }}<span class="diff-type diff-del">D</span>{{ end }} 49 + {{ if not (or .IsNew .IsDelete) }}<span class="diff-type diff-mod">M</span>{{ end }} 50 + </td> 51 + <td class="fill"> 52 + <a href="#{{ $path }}"> 53 + {{ if and .Name.Old .Name.New }}{{ .Name.Old }} → {{ .Name.New }}{{ else }}{{ $path }}{{ end }} 54 + </a> 55 + </td> 56 + </tr> 57 + {{ end }} 58 + </tbody> 59 + </table> 70 60 </div> 61 + {{ end }} 71 62 </section> 72 63 <section> 73 64 {{ $repo := .name }} 74 - {{ $this := .commit }} 75 - {{ $parent := .parent }} 65 + {{ $this := .commit.Hash }} 66 + {{ $parent := index .parents 0 }} 76 67 {{ range .diff }} 77 68 {{ $path := .Name.New }} 78 69 {{ if not $path }}{{ $path = .Name.Old }}{{ end }} 路路路 90 81 {{ if .Name.Old }} 91 82 <a href="/{{ $repo }}/blob/{{ $parent }}/{{ .Name.Old }}">{{ .Name.Old }}</a> 92 83 {{ if .Name.New }} 93 - → 84 + → 94 85 <a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}">{{ .Name.New }}</a> 95 86 {{ end }} 96 87 {{ else }}