mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-12 02:58:53 -06:00
Simplify basic commit type for validation check
This commit is contained in:
@@ -116,10 +116,12 @@ func runLog(args []string) int {
|
||||
func printCommit(node LogNode, w io.Writer, db datas.Database) (err error) {
|
||||
maxMetaFieldNameLength := func(commit types.Struct) int {
|
||||
maxLen := 0
|
||||
meta := commit.Get(datas.MetaField).(types.Struct)
|
||||
meta.Type().Desc.(types.StructDesc).IterFields(func(name string, t *types.Type) {
|
||||
maxLen = max(maxLen, len(name))
|
||||
})
|
||||
if m, ok := commit.MaybeGet(datas.MetaField); ok {
|
||||
meta := m.(types.Struct)
|
||||
meta.Type().Desc.(types.StructDesc).IterFields(func(name string, t *types.Type) {
|
||||
maxLen = max(maxLen, len(name))
|
||||
})
|
||||
}
|
||||
return maxLen
|
||||
}
|
||||
|
||||
@@ -226,17 +228,20 @@ func genGraph(node LogNode, lineno int) string {
|
||||
}
|
||||
|
||||
func writeMetaLines(node LogNode, maxLines, lineno, maxLabelLen int, w io.Writer) (int, error) {
|
||||
meta := node.commit.Get(datas.MetaField).(types.Struct)
|
||||
mlw := &maxLineWriter{numLines: lineno, maxLines: maxLines, node: node, dest: w, needsPrefix: true, showGraph: showGraph}
|
||||
err := d.Try(func() {
|
||||
meta.Type().Desc.(types.StructDesc).IterFields(func(fieldName string, t *types.Type) {
|
||||
v := meta.Get(fieldName)
|
||||
fmt.Fprintf(mlw, "%-*s", maxLabelLen+2, strings.Title(fieldName)+":")
|
||||
types.WriteEncodedValue(mlw, v)
|
||||
fmt.Fprintf(mlw, "\n")
|
||||
if m, ok := node.commit.MaybeGet(datas.MetaField); ok {
|
||||
meta := m.(types.Struct)
|
||||
mlw := &maxLineWriter{numLines: lineno, maxLines: maxLines, node: node, dest: w, needsPrefix: true, showGraph: showGraph}
|
||||
err := d.Try(func() {
|
||||
meta.Type().Desc.(types.StructDesc).IterFields(func(fieldName string, t *types.Type) {
|
||||
v := meta.Get(fieldName)
|
||||
fmt.Fprintf(mlw, "%-*s", maxLabelLen+2, strings.Title(fieldName)+":")
|
||||
types.WriteEncodedValue(mlw, v)
|
||||
fmt.Fprintf(mlw, "\n")
|
||||
})
|
||||
})
|
||||
})
|
||||
return mlw.numLines, err
|
||||
return mlw.numLines, err
|
||||
}
|
||||
return lineno, nil
|
||||
}
|
||||
|
||||
func writeCommitLines(node LogNode, maxLines, lineno int, w io.Writer) (lineCnt int, err error) {
|
||||
|
||||
@@ -202,6 +202,32 @@ func (s *nomsLogTestSuite) TestNomsGraph2() {
|
||||
s.Equal(diffRes2, res)
|
||||
}
|
||||
|
||||
func (s *nomsLogTestSuite) TestNoMetaCommit() {
|
||||
str := spec.CreateDatabaseSpecString("ldb", s.LdbDir)
|
||||
db, err := spec.GetDatabase(str)
|
||||
s.NoError(err)
|
||||
|
||||
ds := dataset.NewDataset(db, "ds1")
|
||||
|
||||
meta := types.NewStruct("Meta", map[string]types.Value{
|
||||
"test1": types.String("Yoo"),
|
||||
"test2": types.String("Hoo"),
|
||||
})
|
||||
ds, err = ds.Commit(types.String("1"), dataset.CommitOptions{Meta: meta})
|
||||
s.NoError(err)
|
||||
r1 := ds.HeadRef()
|
||||
|
||||
noMetaCommit := types.NewStruct("Commit", map[string]types.Value{
|
||||
"value": types.String("2"),
|
||||
"parents": types.NewSet(r1),
|
||||
})
|
||||
ds.Database().Commit("ds1", noMetaCommit)
|
||||
db.Close()
|
||||
|
||||
res, _ := s.Run(main, []string{"log", "-show-value=false", spec.CreateValueSpecString("ldb", s.LdbDir, "ds1")})
|
||||
s.Equal(metaRes1, res)
|
||||
}
|
||||
|
||||
func (s *nomsLogTestSuite) TestNomsGraph3() {
|
||||
str := spec.CreateDatabaseSpecString("ldb", s.LdbDir)
|
||||
db, err := spec.GetDatabase(str)
|
||||
@@ -324,4 +350,6 @@ const (
|
||||
|
||||
truncRes3 = "* p1442asfqnhgv1ebg6rijhl3kb9n4vt3\n| Parent: 4tq9si4tk8n0pead7hovehcbuued45sa\n* 4tq9si4tk8n0pead7hovehcbuued45sa\n| Parent: None\n"
|
||||
diffTrunc3 = "* p1442asfqnhgv1ebg6rijhl3kb9n4vt3\n| Parent: 4tq9si4tk8n0pead7hovehcbuued45sa\n* 4tq9si4tk8n0pead7hovehcbuued45sa\n| Parent: None\n"
|
||||
|
||||
metaRes1 = "82pdg48mjv5noo1bn0k6mhbqe2daunt8\nParent: pv77djqjgu33b5lko9l3f7s3i15me2k2\n- \"1\"\n+ \"2\"\n\npv77djqjgu33b5lko9l3f7s3i15me2k2\nParent: None\nTest1: \"Yoo\"\nTest2: \"Hoo\"\n\n"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user