repo *gitmap.GitRepo
}
-func (g *gitInfo) forPage(p page.Page) source.GitInfo {
+func (g *gitInfo) forPage(p page.Page) *source.GitInfo {
name := strings.TrimPrefix(filepath.ToSlash(p.File().Filename()), g.contentDir)
name = strings.TrimPrefix(name, "/")
gi, found := g.repo.Files[name]
if !found {
- return source.GitInfo{}
+ return nil
}
- return source.NewGitInfo(*gi)
+ return gi
}
func newGitInfo(d *deps.Deps) (*gitInfo, error) {
return v
}
-func (h *HugoSites) gitInfoForPage(p page.Page) (source.GitInfo, error) {
+func (h *HugoSites) gitInfoForPage(p page.Page) (*source.GitInfo, error) {
if _, err := h.init.gitInfo.Do(context.Background()); err != nil {
- return source.GitInfo{}, err
+ return nil, err
}
if h.gitInfo == nil {
- return source.GitInfo{}, nil
+ return nil, nil
}
return h.gitInfo.forPage(p), nil
}
}
-func (p *pageState) GitInfo() source.GitInfo {
+func (p *pageState) GitInfo() *source.GitInfo {
return p.gitInfo
}
targetPathDescriptor page.TargetPathDescriptor
// Set if feature enabled and this is in a Git repo.
- gitInfo source.GitInfo
+ gitInfo *source.GitInfo
codeowners []string
// Positional navigation
}
var gitAuthorDate time.Time
- if !p.gitInfo.IsZero() {
+ if p.gitInfo != nil {
gitAuthorDate = p.gitInfo.AuthorDate
}
// GitInfoProvider provides Git info.
type GitInfoProvider interface {
// GitInfo returns the Git info for this object.
- GitInfo() source.GitInfo
+ GitInfo() *source.GitInfo
// CodeOwners returns the code owners for this object.
CodeOwners() []string
}
return nil
}
-func (p *nopPage) GitInfo() source.GitInfo {
- return source.GitInfo{}
+func (p *nopPage) GitInfo() *source.GitInfo {
+ return nil
}
func (p *nopPage) CodeOwners() []string {
return relatedDocsHandler
}
-func (p *testPage) GitInfo() source.GitInfo {
- return source.GitInfo{}
+func (p *testPage) GitInfo() *source.GitInfo {
+ return nil
}
func (p *testPage) CodeOwners() []string {
import (
"path/filepath"
"sync"
- "time"
"github.com/bep/gitmap"
"github.com/gohugoio/hugo/common/hashing"
}
}
-func NewGitInfo(info gitmap.GitInfo) GitInfo {
- gi := GitInfo{
- Hash: info.Hash,
- AbbreviatedHash: info.AbbreviatedHash,
- Subject: info.Subject,
- AuthorName: info.AuthorName,
- AuthorEmail: info.AuthorEmail,
- AuthorDate: info.AuthorDate,
- CommitDate: info.CommitDate,
- Body: info.Body,
- }
-
- if info.Ancestor != nil {
- anc := NewGitInfo(*info.Ancestor)
- gi.Ancestor = &anc
- }
-
- return gi
-}
-
// GitInfo provides information about a version controlled source file.
-type GitInfo struct {
- // Commit hash.
- Hash string `json:"hash"`
- // Abbreviated commit hash.
- AbbreviatedHash string `json:"abbreviatedHash"`
- // The commit message's subject/title line.
- Subject string `json:"subject"`
- // The author name, respecting .mailmap.
- AuthorName string `json:"authorName"`
- // The author email address, respecting .mailmap.
- AuthorEmail string `json:"authorEmail"`
- // The author date.
- AuthorDate time.Time `json:"authorDate"`
- // The commit date.
- CommitDate time.Time `json:"commitDate"`
- // The commit message's body.
- Body string `json:"body"`
- // The file-filtered ancestor commit, if any.
- Ancestor *GitInfo `json:"ancestor"`
-}
-
-// IsZero returns true if the GitInfo is empty,
-// meaning it will also be falsy in the Go templates.
-func (g *GitInfo) IsZero() bool {
- return g == nil || g.Hash == ""
-}
+type GitInfo = gitmap.GitInfo
b.AssertFileContent("public/index.html", "1\n2\n3")
}
-func TestThatPageGitInfoShouldBeZero(t *testing.T) {
+func TestThatPageGitInfoShouldBeNil(t *testing.T) {
t.Parallel()
files := `