Skip to content

Commit 90d397b

Browse files
committed
Remove the internal GitInfo type and make Page.GitInf() return a pointer
See #5693
1 parent 61e6c73 commit 90d397b

File tree

10 files changed

+16
-62
lines changed

10 files changed

+16
-62
lines changed

hugolib/gitinfo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ type gitInfo struct {
3030
repo *gitmap.GitRepo
3131
}
3232

33-
func (g *gitInfo) forPage(p page.Page) source.GitInfo {
33+
func (g *gitInfo) forPage(p page.Page) *source.GitInfo {
3434
name := strings.TrimPrefix(filepath.ToSlash(p.File().Filename()), g.contentDir)
3535
name = strings.TrimPrefix(name, "/")
3636
gi, found := g.repo.Files[name]
3737
if !found {
38-
return source.GitInfo{}
38+
return nil
3939
}
40-
return source.NewGitInfo(*gi)
40+
return gi
4141
}
4242

4343
func newGitInfo(d *deps.Deps) (*gitInfo, error) {

hugolib/hugo_sites.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,13 @@ func (h *HugoSites) RegularPages() page.Pages {
230230
return v
231231
}
232232

233-
func (h *HugoSites) gitInfoForPage(p page.Page) (source.GitInfo, error) {
233+
func (h *HugoSites) gitInfoForPage(p page.Page) (*source.GitInfo, error) {
234234
if _, err := h.init.gitInfo.Do(context.Background()); err != nil {
235-
return source.GitInfo{}, err
235+
return nil, err
236236
}
237237

238238
if h.gitInfo == nil {
239-
return source.GitInfo{}, nil
239+
return nil, nil
240240
}
241241

242242
return h.gitInfo.forPage(p), nil

hugolib/page.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func (p *pageState) ApplyFilterToHeadings(ctx context.Context, fn func(*tableofc
238238
}
239239
}
240240

241-
func (p *pageState) GitInfo() source.GitInfo {
241+
func (p *pageState) GitInfo() *source.GitInfo {
242242
return p.gitInfo
243243
}
244244

hugolib/page__common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type pageCommon struct {
8686
targetPathDescriptor page.TargetPathDescriptor
8787

8888
// Set if feature enabled and this is in a Git repo.
89-
gitInfo source.GitInfo
89+
gitInfo *source.GitInfo
9090
codeowners []string
9191

9292
// Positional navigation

hugolib/page__meta.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func (p *pageState) setMetaPostParams() error {
405405
}
406406

407407
var gitAuthorDate time.Time
408-
if !p.gitInfo.IsZero() {
408+
if p.gitInfo != nil {
409409
gitAuthorDate = p.gitInfo.AuthorDate
410410
}
411411

resources/page/page.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ type GetPageProvider interface {
135135
// GitInfoProvider provides Git info.
136136
type GitInfoProvider interface {
137137
// GitInfo returns the Git info for this object.
138-
GitInfo() source.GitInfo
138+
GitInfo() *source.GitInfo
139139
// CodeOwners returns the code owners for this object.
140140
CodeOwners() []string
141141
}

resources/page/page_nop.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ func (p *nopPage) GetTerms(taxonomy string) Pages {
178178
return nil
179179
}
180180

181-
func (p *nopPage) GitInfo() source.GitInfo {
182-
return source.GitInfo{}
181+
func (p *nopPage) GitInfo() *source.GitInfo {
182+
return nil
183183
}
184184

185185
func (p *nopPage) CodeOwners() []string {

resources/page/testhelpers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ func (p *testPage) GetInternalRelatedDocsHandler() *RelatedDocsHandler {
225225
return relatedDocsHandler
226226
}
227227

228-
func (p *testPage) GitInfo() source.GitInfo {
229-
return source.GitInfo{}
228+
func (p *testPage) GitInfo() *source.GitInfo {
229+
return nil
230230
}
231231

232232
func (p *testPage) CodeOwners() []string {

source/fileInfo.go

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package source
1616
import (
1717
"path/filepath"
1818
"sync"
19-
"time"
2019

2120
"github.com/bep/gitmap"
2221
"github.com/gohugoio/hugo/common/hashing"
@@ -154,50 +153,5 @@ func NewFileInfo(fi hugofs.FileMetaInfo) *File {
154153
}
155154
}
156155

157-
func NewGitInfo(info gitmap.GitInfo) GitInfo {
158-
gi := GitInfo{
159-
Hash: info.Hash,
160-
AbbreviatedHash: info.AbbreviatedHash,
161-
Subject: info.Subject,
162-
AuthorName: info.AuthorName,
163-
AuthorEmail: info.AuthorEmail,
164-
AuthorDate: info.AuthorDate,
165-
CommitDate: info.CommitDate,
166-
Body: info.Body,
167-
}
168-
169-
if info.Ancestor != nil {
170-
anc := NewGitInfo(*info.Ancestor)
171-
gi.Ancestor = &anc
172-
}
173-
174-
return gi
175-
}
176-
177156
// GitInfo provides information about a version controlled source file.
178-
type GitInfo struct {
179-
// Commit hash.
180-
Hash string `json:"hash"`
181-
// Abbreviated commit hash.
182-
AbbreviatedHash string `json:"abbreviatedHash"`
183-
// The commit message's subject/title line.
184-
Subject string `json:"subject"`
185-
// The author name, respecting .mailmap.
186-
AuthorName string `json:"authorName"`
187-
// The author email address, respecting .mailmap.
188-
AuthorEmail string `json:"authorEmail"`
189-
// The author date.
190-
AuthorDate time.Time `json:"authorDate"`
191-
// The commit date.
192-
CommitDate time.Time `json:"commitDate"`
193-
// The commit message's body.
194-
Body string `json:"body"`
195-
// The file-filtered ancestor commit, if any.
196-
Ancestor *GitInfo `json:"ancestor"`
197-
}
198-
199-
// IsZero returns true if the GitInfo is empty,
200-
// meaning it will also be falsy in the Go templates.
201-
func (g *GitInfo) IsZero() bool {
202-
return g == nil || g.Hash == ""
203-
}
157+
type GitInfo = gitmap.GitInfo

tpl/page/page_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ disableLiveReload = true
221221
b.AssertFileContent("public/index.html", "1\n2\n3")
222222
}
223223

224-
func TestThatPageGitInfoShouldBeZero(t *testing.T) {
224+
func TestThatPageGitInfoShouldBeNil(t *testing.T) {
225225
t.Parallel()
226226

227227
files := `

0 commit comments

Comments
 (0)