mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-20 18:19:15 -06:00
Make CommitMetaGenerator implementations private
And make their fields private too.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user