aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/git/git.go47
-rw-r--r--pkg/handler/git/handler.go2
-rw-r--r--scss/main.scss19
-rw-r--r--templates/commit.qtpl24
-rw-r--r--templates/commit.qtpl.go160
-rw-r--r--templates/gititemcommit.qtpl4
-rw-r--r--templates/gititemcommit.qtpl.go4
-rw-r--r--templates/gititemlog.qtpl2
-rw-r--r--templates/gititemlog.qtpl.go2
-rw-r--r--templates/gititemsummary.qtpl2
-rw-r--r--templates/gititemsummary.qtpl.go2
11 files changed, 199 insertions, 69 deletions
diff --git a/pkg/git/git.go b/pkg/git/git.go
index 9e7f9c9..d72e561 100644
--- a/pkg/git/git.go
+++ b/pkg/git/git.go
@@ -34,7 +34,7 @@ type (
}
CommitReference struct {
commit *object.Commit
- ref *plumbing.Reference
+ refs []*plumbing.Reference
}
infoWrapper struct {
name string
@@ -103,10 +103,20 @@ func (g *GitRepository) LastCommit() (*CommitReference, error) {
commitRef := &CommitReference{commit: c}
if err := iter.ForEach(func(ref *plumbing.Reference) error {
- if ref.Hash() != c.Hash {
- return nil
+ obj, err := g.repository.TagObject(ref.Hash())
+ switch err {
+ case nil:
+ if obj.Target == commitRef.commit.Hash {
+ commitRef.AddReference(ref)
+ }
+ case plumbing.ErrObjectNotFound:
+ if commitRef.commit.Hash == ref.Hash() {
+ commitRef.AddReference(ref)
+ }
+ default:
+ return err
}
- commitRef.ref = ref
+
return nil
}); err != nil {
return nil, err
@@ -155,17 +165,26 @@ func (g *GitRepository) Commits(count int, from string) ([]*CommitReference, *ob
}
// new we fetch for possible tags for each commit
- iter, err := g.repository.Tags()
+ iter, err := g.repository.References()
if err != nil {
return nil, nil, err
}
if err := iter.ForEach(func(ref *plumbing.Reference) error {
for _, c := range commitRefs {
- if c.commit.Hash != ref.Hash() {
- continue
+ obj, err := g.repository.TagObject(ref.Hash())
+ switch err {
+ case nil:
+ if obj.Target == c.commit.Hash {
+ c.AddReference(ref)
+ }
+ case plumbing.ErrObjectNotFound:
+ if c.commit.Hash == ref.Hash() {
+ c.AddReference(ref)
+ }
+ default:
+ return err
}
- c.ref = ref
}
return nil
}); err != nil {
@@ -497,6 +516,18 @@ func (c *CommitReference) Commit() *object.Commit {
return c.commit
}
+func (c *CommitReference) HasReference() bool {
+ return len(c.refs) > 0
+}
+
+func (c *CommitReference) References() []*plumbing.Reference {
+ return c.refs
+}
+
+func (c *CommitReference) AddReference(ref *plumbing.Reference) {
+ c.refs = append(c.refs, ref)
+}
+
func (self *tagList) Len() int {
return len(self.refs)
}
diff --git a/pkg/handler/git/handler.go b/pkg/handler/git/handler.go
index 33adc8d..b825ea4 100644
--- a/pkg/handler/git/handler.go
+++ b/pkg/handler/git/handler.go
@@ -384,7 +384,7 @@ func (g *GitHandler) Commit(w http.ResponseWriter, r *http.Request) error {
Name: name,
Ref: ref,
GitItemBase: &templates.GitItemCommitPage{
- Commit: commit.Commit(),
+ Commit: commit,
Diff: code.Bytes(),
},
}
diff --git a/scss/main.scss b/scss/main.scss
index 7a1fff2..51b7df7 100644
--- a/scss/main.scss
+++ b/scss/main.scss
@@ -183,3 +183,22 @@ pre {
max-width: calc(100% - calc(2 * #{$spacer}));
}
}
+
+.ref {
+ padding: 2px;
+ margin: 2px;
+ color: white;
+ text-decoration: none;
+
+ &:hover {
+ background: #70dc70;
+ }
+
+ &.branch {
+ background: #25a525;
+ }
+
+ &.tag {
+ background: #5874e2;
+ }
+}
diff --git a/templates/commit.qtpl b/templates/commit.qtpl
index b5699f4..adc6f2a 100644
--- a/templates/commit.qtpl
+++ b/templates/commit.qtpl
@@ -1,24 +1,34 @@
+{% import "git.gabrielgio.me/cerrado/pkg/git" %}
{% import "git.gabrielgio.me/cerrado/pkg/humanize" %}
-{% import "github.com/go-git/go-git/v5/plumbing/object" %}
-{% func Commit(name string, c *object.Commit, showTar bool) %}
+{% func Commit(name string, c *git.CommitReference, showTar bool) %}
<div class="row event">
<div class="row">
<div class="col-md">
- <a title="{%s c.Hash.String() %}" href="/{%s name %}/commit/{%s c.Hash.String() %}/">{%s c.Hash.String()[0:8] %}</a> —
- <a title="{%s c.Committer.Email %}" href="mailto:{%s c.Author.Email %}">{%s c.Author.Name %}</a>
+ <a title="{%s c.Commit().Hash.String() %}" href="/{%s name %}/commit/{%s c.Commit().Hash.String() %}/">{%s c.Commit().Hash.String()[0:8] %}</a> —
+ <a title="{%s c.Commit().Committer.Email %}" href="mailto:{%s c.Commit().Author.Email %}">{%s c.Commit().Author.Name %}</a>
+ —
+ {% if c.HasReference() %}
+ {% for _, r := range c.References() %}
+ {% if r.Name().IsBranch() %}
+ <a class="ref branch" title="{%s c.Commit().Hash.String() %}" href="/{%s name %}/tree/{%s r.Name().Short() %}/">{%s r.Name().Short() %}</a>
+ {% else %}
+ <a class="ref tag" title="{%s c.Commit().Hash.String() %}" href="/{%s name %}/commit/{%s c.Commit().Hash.String() %}/">{%s r.Name().Short() %}</a>
+ {% endif %}
+ {% endfor %}
+ {%endif%}
</div>
{% if showTar %}
<div class="col-md text-md-center">
- <a title="tar.gz for {%s c.Hash.String() %}" href="/{%s name %}/archive/{%s c.Hash.String() %}.tar.gz">tar.gz</a>
+ <a title="tar.gz for {%s c.Commit().Hash.String() %}" href="/{%s name %}/archive/{%s c.Commit().Hash.String() %}.tar.gz">tar.gz</a>
</div>
{% endif %}
<div class="col-md text-md-end">
- <a title="{%s c.Author.When.UTC().Format("2006-01-02 15:04:05")%} UTC">{%s humanize.Time(c.Author.When) %}</a>
+ <a title="{%s c.Commit().Author.When.UTC().Format("2006-01-02 15:04:05")%} UTC">{%s humanize.Time(c.Commit().Author.When) %}</a>
</div>
</div>
<div class="code-view">
- <pre>{%s c.Message %}</pre>
+ <pre>{%s c.Commit().Message %}</pre>
</div>
</div>
{% endfunc %}
diff --git a/templates/commit.qtpl.go b/templates/commit.qtpl.go
index 75ae899..fda993d 100644
--- a/templates/commit.qtpl.go
+++ b/templates/commit.qtpl.go
@@ -5,10 +5,10 @@
package templates
//line templates/commit.qtpl:1
-import "git.gabrielgio.me/cerrado/pkg/humanize"
+import "git.gabrielgio.me/cerrado/pkg/git"
//line templates/commit.qtpl:2
-import "github.com/go-git/go-git/v5/plumbing/object"
+import "git.gabrielgio.me/cerrado/pkg/humanize"
//line templates/commit.qtpl:4
import (
@@ -24,7 +24,7 @@ var (
)
//line templates/commit.qtpl:4
-func StreamCommit(qw422016 *qt422016.Writer, name string, c *object.Commit, showTar bool) {
+func StreamCommit(qw422016 *qt422016.Writer, name string, c *git.CommitReference, showTar bool) {
//line templates/commit.qtpl:4
qw422016.N().S(`
<div class="row event">
@@ -32,7 +32,7 @@ func StreamCommit(qw422016 *qt422016.Writer, name string, c *object.Commit, show
<div class="col-md">
<a title="`)
//line templates/commit.qtpl:8
- qw422016.E().S(c.Hash.String())
+ qw422016.E().S(c.Commit().Hash.String())
//line templates/commit.qtpl:8
qw422016.N().S(`" href="/`)
//line templates/commit.qtpl:8
@@ -40,98 +40,168 @@ func StreamCommit(qw422016 *qt422016.Writer, name string, c *object.Commit, show
//line templates/commit.qtpl:8
qw422016.N().S(`/commit/`)
//line templates/commit.qtpl:8
- qw422016.E().S(c.Hash.String())
+ qw422016.E().S(c.Commit().Hash.String())
//line templates/commit.qtpl:8
qw422016.N().S(`/">`)
//line templates/commit.qtpl:8
- qw422016.E().S(c.Hash.String()[0:8])
+ qw422016.E().S(c.Commit().Hash.String()[0:8])
//line templates/commit.qtpl:8
qw422016.N().S(`</a> —
<a title="`)
//line templates/commit.qtpl:9
- qw422016.E().S(c.Committer.Email)
+ qw422016.E().S(c.Commit().Committer.Email)
//line templates/commit.qtpl:9
qw422016.N().S(`" href="mailto:`)
//line templates/commit.qtpl:9
- qw422016.E().S(c.Author.Email)
+ qw422016.E().S(c.Commit().Author.Email)
//line templates/commit.qtpl:9
qw422016.N().S(`">`)
//line templates/commit.qtpl:9
- qw422016.E().S(c.Author.Name)
+ qw422016.E().S(c.Commit().Author.Name)
//line templates/commit.qtpl:9
qw422016.N().S(`</a>
+ —
+ `)
+//line templates/commit.qtpl:11
+ if c.HasReference() {
+//line templates/commit.qtpl:11
+ qw422016.N().S(`
+ `)
+//line templates/commit.qtpl:12
+ for _, r := range c.References() {
+//line templates/commit.qtpl:12
+ qw422016.N().S(`
+ `)
+//line templates/commit.qtpl:13
+ if r.Name().IsBranch() {
+//line templates/commit.qtpl:13
+ qw422016.N().S(`
+ <a class="ref branch" title="`)
+//line templates/commit.qtpl:14
+ qw422016.E().S(c.Commit().Hash.String())
+//line templates/commit.qtpl:14
+ qw422016.N().S(`" href="/`)
+//line templates/commit.qtpl:14
+ qw422016.E().S(name)
+//line templates/commit.qtpl:14
+ qw422016.N().S(`/tree/`)
+//line templates/commit.qtpl:14
+ qw422016.E().S(r.Name().Short())
+//line templates/commit.qtpl:14
+ qw422016.N().S(`/">`)
+//line templates/commit.qtpl:14
+ qw422016.E().S(r.Name().Short())
+//line templates/commit.qtpl:14
+ qw422016.N().S(`</a>
+ `)
+//line templates/commit.qtpl:15
+ } else {
+//line templates/commit.qtpl:15
+ qw422016.N().S(`
+ <a class="ref tag" title="`)
+//line templates/commit.qtpl:16
+ qw422016.E().S(c.Commit().Hash.String())
+//line templates/commit.qtpl:16
+ qw422016.N().S(`" href="/`)
+//line templates/commit.qtpl:16
+ qw422016.E().S(name)
+//line templates/commit.qtpl:16
+ qw422016.N().S(`/commit/`)
+//line templates/commit.qtpl:16
+ qw422016.E().S(c.Commit().Hash.String())
+//line templates/commit.qtpl:16
+ qw422016.N().S(`/">`)
+//line templates/commit.qtpl:16
+ qw422016.E().S(r.Name().Short())
+//line templates/commit.qtpl:16
+ qw422016.N().S(`</a>
+ `)
+//line templates/commit.qtpl:17
+ }
+//line templates/commit.qtpl:17
+ qw422016.N().S(`
+ `)
+//line templates/commit.qtpl:18
+ }
+//line templates/commit.qtpl:18
+ qw422016.N().S(`
+ `)
+//line templates/commit.qtpl:19
+ }
+//line templates/commit.qtpl:19
+ qw422016.N().S(`
</div>
`)
-//line templates/commit.qtpl:11
+//line templates/commit.qtpl:21
if showTar {
-//line templates/commit.qtpl:11
+//line templates/commit.qtpl:21
qw422016.N().S(`
<div class="col-md text-md-center">
<a title="tar.gz for `)
-//line templates/commit.qtpl:13
- qw422016.E().S(c.Hash.String())
-//line templates/commit.qtpl:13
+//line templates/commit.qtpl:23
+ qw422016.E().S(c.Commit().Hash.String())
+//line templates/commit.qtpl:23
qw422016.N().S(`" href="/`)
-//line templates/commit.qtpl:13
+//line templates/commit.qtpl:23
qw422016.E().S(name)
-//line templates/commit.qtpl:13
+//line templates/commit.qtpl:23
qw422016.N().S(`/archive/`)
-//line templates/commit.qtpl:13
- qw422016.E().S(c.Hash.String())
-//line templates/commit.qtpl:13
+//line templates/commit.qtpl:23
+ qw422016.E().S(c.Commit().Hash.String())
+//line templates/commit.qtpl:23
qw422016.N().S(`.tar.gz">tar.gz</a>
</div>
`)
-//line templates/commit.qtpl:15
+//line templates/commit.qtpl:25
}
-//line templates/commit.qtpl:15
+//line templates/commit.qtpl:25
qw422016.N().S(`
<div class="col-md text-md-end">
<a title="`)
-//line templates/commit.qtpl:17
- qw422016.E().S(c.Author.When.UTC().Format("2006-01-02 15:04:05"))
-//line templates/commit.qtpl:17
+//line templates/commit.qtpl:27
+ qw422016.E().S(c.Commit().Author.When.UTC().Format("2006-01-02 15:04:05"))
+//line templates/commit.qtpl:27
qw422016.N().S(` UTC">`)
-//line templates/commit.qtpl:17
- qw422016.E().S(humanize.Time(c.Author.When))
-//line templates/commit.qtpl:17
+//line templates/commit.qtpl:27
+ qw422016.E().S(humanize.Time(c.Commit().Author.When))
+//line templates/commit.qtpl:27
qw422016.N().S(`</a>
</div>
</div>
<div class="code-view">
<pre>`)
-//line templates/commit.qtpl:21
- qw422016.E().S(c.Message)
-//line templates/commit.qtpl:21
+//line templates/commit.qtpl:31
+ qw422016.E().S(c.Commit().Message)
+//line templates/commit.qtpl:31
qw422016.N().S(`</pre>
</div>
</div>
`)
-//line templates/commit.qtpl:24
+//line templates/commit.qtpl:34
}
-//line templates/commit.qtpl:24
-func WriteCommit(qq422016 qtio422016.Writer, name string, c *object.Commit, showTar bool) {
-//line templates/commit.qtpl:24
+//line templates/commit.qtpl:34
+func WriteCommit(qq422016 qtio422016.Writer, name string, c *git.CommitReference, showTar bool) {
+//line templates/commit.qtpl:34
qw422016 := qt422016.AcquireWriter(qq422016)
-//line templates/commit.qtpl:24
+//line templates/commit.qtpl:34
StreamCommit(qw422016, name, c, showTar)
-//line templates/commit.qtpl:24
+//line templates/commit.qtpl:34
qt422016.ReleaseWriter(qw422016)
-//line templates/commit.qtpl:24
+//line templates/commit.qtpl:34
}
-//line templates/commit.qtpl:24
-func Commit(name string, c *object.Commit, showTar bool) string {
-//line templates/commit.qtpl:24
+//line templates/commit.qtpl:34
+func Commit(name string, c *git.CommitReference, showTar bool) string {
+//line templates/commit.qtpl:34
qb422016 := qt422016.AcquireByteBuffer()
-//line templates/commit.qtpl:24
+//line templates/commit.qtpl:34
WriteCommit(qb422016, name, c, showTar)
-//line templates/commit.qtpl:24
+//line templates/commit.qtpl:34
qs422016 := string(qb422016.B)
-//line templates/commit.qtpl:24
+//line templates/commit.qtpl:34
qt422016.ReleaseByteBuffer(qb422016)
-//line templates/commit.qtpl:24
+//line templates/commit.qtpl:34
return qs422016
-//line templates/commit.qtpl:24
+//line templates/commit.qtpl:34
}
diff --git a/templates/gititemcommit.qtpl b/templates/gititemcommit.qtpl
index ec67757..7de1bdb 100644
--- a/templates/gititemcommit.qtpl
+++ b/templates/gititemcommit.qtpl
@@ -1,8 +1,8 @@
-{% import "github.com/go-git/go-git/v5/plumbing/object" %}
+{% import "git.gabrielgio.me/cerrado/pkg/git" %}
{% code
type GitItemCommitPage struct {
- Commit *object.Commit
+ Commit *git.CommitReference
Diff []byte
}
%}
diff --git a/templates/gititemcommit.qtpl.go b/templates/gititemcommit.qtpl.go
index 7e458f3..b790220 100644
--- a/templates/gititemcommit.qtpl.go
+++ b/templates/gititemcommit.qtpl.go
@@ -5,7 +5,7 @@
package templates
//line templates/gititemcommit.qtpl:1
-import "github.com/go-git/go-git/v5/plumbing/object"
+import "git.gabrielgio.me/cerrado/pkg/git"
//line templates/gititemcommit.qtpl:3
import (
@@ -22,7 +22,7 @@ var (
//line templates/gititemcommit.qtpl:4
type GitItemCommitPage struct {
- Commit *object.Commit
+ Commit *git.CommitReference
Diff []byte
}
diff --git a/templates/gititemlog.qtpl b/templates/gititemlog.qtpl
index 93efb24..391de53 100644
--- a/templates/gititemlog.qtpl
+++ b/templates/gititemlog.qtpl
@@ -13,7 +13,7 @@ type GitItemLogPage struct {
{% func (g *GitItemLogPage) GitContent(name, ref string) %}
<div class="event-list">
{% for _, c := range g.Commits %}
- {%= Commit(name, c.Commit(), false) %}
+ {%= Commit(name, c, false) %}
{% endfor %}
{% if g.Next != nil %}
<a href="/{%s name %}/log/{%s ref %}/?from={%s g.Next.Hash.String() %}" class="btn btn-primary">Next</a>
diff --git a/templates/gititemlog.qtpl.go b/templates/gititemlog.qtpl.go
index 05950ed..2c9ce93 100644
--- a/templates/gititemlog.qtpl.go
+++ b/templates/gititemlog.qtpl.go
@@ -74,7 +74,7 @@ func (g *GitItemLogPage) StreamGitContent(qw422016 *qt422016.Writer, name, ref s
qw422016.N().S(`
`)
//line templates/gititemlog.qtpl:16
- StreamCommit(qw422016, name, c.Commit(), false)
+ StreamCommit(qw422016, name, c, false)
//line templates/gititemlog.qtpl:16
qw422016.N().S(`
`)
diff --git a/templates/gititemsummary.qtpl b/templates/gititemsummary.qtpl
index 5d07680..e00c37d 100644
--- a/templates/gititemsummary.qtpl
+++ b/templates/gititemsummary.qtpl
@@ -38,7 +38,7 @@ type GitItemSummaryPage struct {
<div class="row">
<div class="event-list">
{% for _, c := range g.Commits %}
- {%= Commit(name, c.Commit(), false) %}
+ {%= Commit(name, c, false) %}
{% endfor %}
</div>
</div>
diff --git a/templates/gititemsummary.qtpl.go b/templates/gititemsummary.qtpl.go
index e17ec7c..0a78258 100644
--- a/templates/gititemsummary.qtpl.go
+++ b/templates/gititemsummary.qtpl.go
@@ -139,7 +139,7 @@ func (g *GitItemSummaryPage) StreamGitContent(qw422016 *qt422016.Writer, name, r
qw422016.N().S(`
`)
//line templates/gititemsummary.qtpl:41
- StreamCommit(qw422016, name, c.Commit(), false)
+ StreamCommit(qw422016, name, c, false)
//line templates/gititemsummary.qtpl:41
qw422016.N().S(`
`)