all repos

mugit @ 2fc36fc

🐮 git server that your cow will love
5 files changed, 71 insertions(+), 79 deletions(-)
ui: redesign commit page
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-02-10 01:39:54 +0200
Change ID: ssoxxkyolnpymuymqtoxxouokwmssyuk
Parent: fb69639
M internal/git/diff.go

@@ -25,10 +25,10 @@ IsDelete bool

} type NiceDiff struct { - Diff []Diff - Commit *Commit - Parent *Commit - Stat struct { + Diff []Diff + Commit *Commit + Parents []string // list of short hashes + Stat struct { FilesChanged int Insertions int Deletions int

@@ -41,7 +41,7 @@ if err != nil {

return nil, fmt.Errorf("commit object: %w", err) } - patch, parent, err := g.getPatch(c) + patch, parents, err := g.getPatch(c) if err != nil { return nil, err }

@@ -53,7 +53,7 @@ }

nd := NiceDiff{} nd.Commit = newCommit(c) - nd.Parent = newCommit(parent) + nd.Parents = parents nd.Stat.FilesChanged = len(diffs) nd.Diff = make([]Diff, len(diffs)) for i, d := range diffs {

@@ -84,26 +84,21 @@ }

return &nd, nil } -func (g *Repo) getPatch(c *object.Commit) (*object.Patch, *object.Commit, error) { +func (g *Repo) getPatch(c *object.Commit) (*object.Patch, []string, error) { commitTree, err := c.Tree() if err != nil { return nil, nil, err } - var parentTree *object.Tree - var parent *object.Commit - - if c.NumParents() != 0 { - parent, err = c.Parents().Next() - if err != nil { - return nil, nil, err + parentTree := &object.Tree{} + if c.NumParents() > 0 { + parent, perr := c.Parents().Next() + if perr != nil { + return nil, nil, perr } - parentTree, err = parent.Tree() - if err != nil { + if parentTree, err = parent.Tree(); err != nil { return nil, nil, err } - } else { - parentTree = &object.Tree{} } patch, err := parentTree.Patch(commitTree)

@@ -111,5 +106,10 @@ if err != nil {

return nil, nil, fmt.Errorf("patch: %w", err) } - return patch, parent, nil + parents := make([]string, len(c.ParentHashes)) + for i, h := range c.ParentHashes { + parents[i] = newShortHash(h) + } + + return patch, parents, nil }
M internal/git/repo.go

@@ -79,13 +79,14 @@ AuthorEmail string

Committed time.Time } +func newShortHash(h plumbing.Hash) string { return h.String()[:7] } 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], + HashShort: newShortHash(c.Hash), Message: c.Message, } }
M internal/handlers/repo.go

@@ -277,7 +277,7 @@

data := make(map[string]any) data["diff"] = diff.Diff data["commit"] = diff.Commit - data["parent"] = diff.Parent + data["parents"] = diff.Parents data["stat"] = diff.Stat data["name"] = name data["ref"] = ref
M web/static/style.css

@@ -288,7 +288,7 @@ .commit-message {

margin-top: 0.25rem; font-size: 1rem; line-height: 1.35; - margin-bottom: 0; + margin-bottom: 1rem; } .commit-info {
M web/templates/repo_commit.html

@@ -8,71 +8,62 @@ <body>

{{ template "repo_header" . }} <main> <section class="commit"> + <div class="commit-refs"> + {{ .stat.FilesChanged }} files changed, + {{ .stat.Insertions }} insertions(+), + {{ .stat.Deletions }} deletions(-) + </div> + <div class="box"> - <div class="commit-info"> - <span class="commit-date">{{ .commit.Committed }}</span> - {{ .commit.AuthorName }} <a href="mailto:{{ .commit.AuthorEmail }}" class="commit-email">{{ .commit.AuthorEmail }}</a> + <pre class="commit-message">{{ .commit.Message }}</pre> + <div> + <strong>Author:</strong> + {{ .commit.AuthorName }} + <a href="mailto:{{ .AuthorEmail }}" class="commit-email">{{ .commit.AuthorEmail }}</a> + </div> + <div> + <strong>Committed at:</strong> + {{ .commit.Committed }} </div> - <pre class="commit-message">{{- .commit.Message -}}</pre> - </div> - - <table class="table commit-refs"> - <tbody> - <tr> - <td class="label nowrap"><strong>commit</strong></td> - <td> - <span class="commit-hash">{{ .commit.HashShort }}</span> - </td> - </tr> - {{ if .parent }} - <tr> - <td class="label nowrap"><strong>parent</strong></td> - <td> - <span class="commit-hash">{{ .parent.HashShort }}</span> - </td> - </tr> - {{ end }} - </tbody> - </table> - - <div class="diff-stat"> <div> - {{ .stat.FilesChanged }} files changed, - {{ .stat.Insertions }} insertions(+), - {{ .stat.Deletions }} deletions(-) + <strong>Parent:</strong> + {{ range $i, $p := .parents -}} + {{ if $i }}, {{ end -}} + <a href="/{{ $.name }}/commit/{{ $p }}">{{ $p }}</a> + {{- end }} </div> + </div> - {{ if gt (len .diff) 1}} - <div class="jump"> - <strong>jump to</strong> - <table class="table jump-table"> - <tbody> - {{ range .diff }} - {{ $path := .Name.New }} - {{ if not $path }}{{ $path = .Name.Old }}{{ end }} - <tr> - <td class="diff-type"> - {{ if .IsNew }}<span class="diff-type diff-add">A</span>{{ end }} - {{ if .IsDelete }}<span class="diff-type diff-del">D</span>{{ end }} - {{ if not (or .IsNew .IsDelete) }}<span class="diff-type diff-mod">M</span>{{ end }} - </td> - <td class="fill"> - <a href="#{{ $path }}"> - {{ if and .Name.Old .Name.New }}{{ .Name.Old }} &#8594; {{ .Name.New }}{{ else }}{{ $path }}{{ end }} - </a> - </td> - </tr> - {{ end }} - </tbody> - </table> - </div> - {{ end }} + {{ if gt (len .diff) 1 -}} + <div class="jump"> + <strong>jump to</strong> + <table class="table jump-table"> + <tbody> + {{ range .diff }} + {{ $path := .Name.New }} + {{ if not $path }}{{ $path = .Name.Old }}{{ end }} + <tr> + <td class="diff-type"> + {{ if .IsNew }}<span class="diff-type diff-add">A</span>{{ end }} + {{ if .IsDelete }}<span class="diff-type diff-del">D</span>{{ end }} + {{ if not (or .IsNew .IsDelete) }}<span class="diff-type diff-mod">M</span>{{ end }} + </td> + <td class="fill"> + <a href="#{{ $path }}"> + {{ if and .Name.Old .Name.New }}{{ .Name.Old }} &#8594; {{ .Name.New }}{{ else }}{{ $path }}{{ end }} + </a> + </td> + </tr> + {{ end }} + </tbody> + </table> </div> + {{ end }} </section> <section> {{ $repo := .name }} - {{ $this := .commit }} - {{ $parent := .parent }} + {{ $this := .commit.Hash }} + {{ $parent := index .parents 0 }} {{ range .diff }} {{ $path := .Name.New }} {{ if not $path }}{{ $path = .Name.Old }}{{ end }}

@@ -90,7 +81,7 @@ {{ end }}

{{ if .Name.Old }} <a href="/{{ $repo }}/blob/{{ $parent }}/{{ .Name.Old }}">{{ .Name.Old }}</a> {{ if .Name.New }} - &#8594; + &#8594; <a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}">{{ .Name.New }}</a> {{ end }} {{ else }}