Make CommitMetaGenerator implementations private

And make their fields private too.
This commit is contained in:
Solipsis
2023-03-20 17:03:29 -07:00
parent ebcb0e2101
commit 060be7e0b2
3 changed files with 24 additions and 20 deletions

View File

@@ -159,7 +159,7 @@ func (cmd InitCmd) Exec(ctx context.Context, commandStr string, args []string, d
if requiresFunHash {
return doltdb.MakeCommitMetaGenerator(name, email, t)
} else {
return doltdb.FunHashCommitMetaGenerator{Name: name, Email: email, Timestamp: t}
return doltdb.MakeFunCommitMetaGenerator(name, email, t)
}
}()

View File

@@ -153,25 +153,25 @@ func (ddb *DoltDB) WriteEmptyRepoWithCommitMeta(ctx context.Context, initBranch
}
type CommitMetaGenerator interface {
Next() (*datas.CommitMeta, error)
IsGoodHash(hash.Hash) bool
next() (*datas.CommitMeta, error)
isGoodHash(hash.Hash) bool
}
func MakeCommitMetaGenerator(name, email string, timestamp time.Time) CommitMetaGenerator {
return SimpleCommitMetaGenerator{Name: name, Email: email, Timestamp: timestamp, Message: defaultInitialCommitMessage}
return simpleCommitMetaGenerator{name: name, email: email, timestamp: timestamp, message: defaultInitialCommitMessage}
}
type SimpleCommitMetaGenerator struct {
Name, Email string
Timestamp time.Time
Message string
type simpleCommitMetaGenerator struct {
name, email string
timestamp time.Time
message string
}
func (g SimpleCommitMetaGenerator) Next() (*datas.CommitMeta, error) {
return datas.NewCommitMetaWithUserTS(g.Name, g.Email, g.Message, g.Timestamp)
func (g simpleCommitMetaGenerator) next() (*datas.CommitMeta, error) {
return datas.NewCommitMetaWithUserTS(g.name, g.email, g.message, g.timestamp)
}
func (SimpleCommitMetaGenerator) IsGoodHash(hash.Hash) bool {
func (simpleCommitMetaGenerator) isGoodHash(hash.Hash) bool {
return true
}
@@ -217,7 +217,7 @@ func (ddb *DoltDB) WriteEmptyRepoWithCommitMetaAndDefaultBranch(
// the timestamp.
var firstCommit *datas.Commit
for {
cm, err := commitMetaGenerator.Next()
cm, err := commitMetaGenerator.next()
if err != nil {
return err
}
@@ -235,7 +235,7 @@ func (ddb *DoltDB) WriteEmptyRepoWithCommitMetaAndDefaultBranch(
return err
}
if !commitMetaGenerator.IsGoodHash(firstCommit.Addr()) {
if !commitMetaGenerator.isGoodHash(firstCommit.Addr()) {
break
}
}

View File

@@ -23,12 +23,16 @@ import (
"github.com/dolthub/dolt/go/store/hash"
)
type FunHashCommitMetaGenerator struct {
Name, Email string
Timestamp time.Time
type funHashCommitMetaGenerator struct {
name, email string
timestamp time.Time
attempt int
}
func MakeFunCommitMetaGenerator(name, email string, timestamp time.Time) CommitMetaGenerator {
return funHashCommitMetaGenerator{name: name, email: email, timestamp: timestamp, attempt: 0}
}
var descriptionReplacementCandidates = [][]rune{
{'I', '\u0406'},
{'i', '\u0456'},
@@ -44,11 +48,11 @@ var descriptionReplacementCandidates = [][]rune{
{'o', '\u043e'},
}
func (g FunHashCommitMetaGenerator) Next() (*datas.CommitMeta, error) {
func (g funHashCommitMetaGenerator) next() (*datas.CommitMeta, error) {
if g.attempt >= 1<<len(descriptionReplacementCandidates) {
g.attempt = 0
// The Time type uses nanosecond precision. Subtract one million nanoseconds (one ms)
g.Timestamp = g.Timestamp.Add(-1_000_000)
g.timestamp = g.timestamp.Add(-1_000_000)
}
// "Initialize data repository", with characters that could be Cyrillic replaced.
@@ -61,10 +65,10 @@ func (g FunHashCommitMetaGenerator) Next() (*datas.CommitMeta, error) {
g.attempt += 1
return datas.NewCommitMetaWithUserTS(g.Name, g.Email, description, g.Timestamp)
return datas.NewCommitMetaWithUserTS(g.name, g.email, description, g.timestamp)
}
func (g FunHashCommitMetaGenerator) IsGoodHash(h hash.Hash) bool {
func (g funHashCommitMetaGenerator) isGoodHash(h hash.Hash) bool {
var funRegExp = regexp.MustCompile("^d[o0][1l]t")
hashString := h.String()