-
-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vinai/refactor docs #1210
Merged
Merged
Vinai/refactor docs #1210
Changes from 19 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
9f3913f
Prelimm methods of drw
VinaiRachakonda e121d06
Remove the some DocsReadWriter methods and move towards use of GetDoc…
VinaiRachakonda 6f30212
Fix bug with repos that have no docs initialized
VinaiRachakonda a0b4235
clean up method
VinaiRachakonda bf91136
Formatting, comments and remove method:
VinaiRachakonda cd85e71
Commit compiles and passes docs test. Factors out much of the root up…
VinaiRachakonda 3ef5011
Dump a bunch of methods environment.go
VinaiRachakonda a41b41d
Merge branch 'master' into vinai/refactor-docs
VinaiRachakonda efaa0bb
Final updates
VinaiRachakonda d380a2d
Remove a bunch of stuff from root_val
VinaiRachakonda 3598fc5
Move some more methods areound and create a docs table package. Focus…
VinaiRachakonda 3f2db74
Redo diffs.go to not use docs
VinaiRachakonda 4160af0
Redo doc diffs, still failing tests
VinaiRachakonda 28bd7db
Passing all docs tests...
VinaiRachakonda 5ac7392
First step in refactoring out doltdocs package...
VinaiRachakonda 4ad5617
type formatting and other things
VinaiRachakonda c4aa8f5
I think everything is passing
VinaiRachakonda ee97d12
Undo bats rewrite
VinaiRachakonda c9c684d
Small fixes
VinaiRachakonda e6f05fd
More changes
VinaiRachakonda ad439c8
repo fmt
VinaiRachakonda ccdfb0f
Pr review comments before large drw refactor
VinaiRachakonda 9443ca6
Iniital changes
VinaiRachakonda 531b88a
Method changes
VinaiRachakonda a345da2
additional changes
VinaiRachakonda 76e3f1f
some refactoring :)
VinaiRachakonda b4a329e
rewrite the diffs alg
VinaiRachakonda 288f01b
Make significant refacotring changes. Need to rewrite cli diff
VinaiRachakonda 5ecabe6
More changes
VinaiRachakonda 69356ca
Fix bc bug
VinaiRachakonda File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ import ( | |
eventsapi "github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1" | ||
"github.com/dolthub/dolt/go/libraries/doltcore/diff" | ||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb" | ||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs" | ||
"github.com/dolthub/dolt/go/libraries/doltcore/env" | ||
"github.com/dolthub/dolt/go/libraries/doltcore/env/actions" | ||
"github.com/dolthub/dolt/go/libraries/doltcore/row" | ||
|
@@ -282,7 +283,21 @@ func parseDiffArgs(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPar | |
|
||
func getDiffRoots(ctx context.Context, dEnv *env.DoltEnv, args []string) (from, to *doltdb.RootValue, leftover []string, err error) { | ||
headRoot, err := dEnv.StagedRoot(ctx) | ||
workingRoot, err := dEnv.WorkingRootWithDocs(ctx) | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
|
||
workingRoot, err := dEnv.WorkingRoot(ctx) | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
|
||
docs, err := dEnv.DocsReadWriter().GetDocsOnDisk() | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
|
||
workingRoot, err = env.UpdateRootWithDocs(ctx, dEnv.DbData(), workingRoot, env.Working, docs) | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
|
@@ -296,6 +311,7 @@ func getDiffRoots(ctx context.Context, dEnv *env.DoltEnv, args []string) (from, | |
|
||
from, ok := maybeResolve(ctx, dEnv, args[0]) | ||
|
||
// TODO: Remove this comment | ||
if !ok { | ||
// `dolt diff ...tables` | ||
from = headRoot | ||
|
@@ -874,7 +890,7 @@ func createSplitter(fromSch schema.Schema, toSch schema.Schema, joiner *rowconv. | |
} | ||
|
||
func diffDoltDocs(ctx context.Context, dEnv *env.DoltEnv, from, to *doltdb.RootValue, dArgs *diffArgs) error { | ||
_, docDetails, err := actions.GetTblsAndDocDetails(dEnv.DocsReadWriter(), dArgs.docSet.AsSlice()) | ||
_, docDetails, err := actions.GetTablesOrDocs(dEnv.DocsReadWriter(), dArgs.docSet.AsSlice()) | ||
|
||
if err != nil { | ||
return err | ||
|
@@ -892,39 +908,40 @@ func diffDoltDocs(ctx context.Context, dEnv *env.DoltEnv, from, to *doltdb.RootV | |
return err | ||
} | ||
|
||
printDocDiffs(ctx, dEnv, fromDocTable, toDocTable, docDetails) | ||
printDocDiffs(ctx, dEnv.DocsReadWriter(), fromDocTable, toDocTable, docDetails) | ||
return nil | ||
} | ||
|
||
func printDocDiffs(ctx context.Context, dEnv *env.DoltEnv, fromTbl, toTbl *doltdb.Table, docDetails []doltdb.DocDetails) { | ||
func printDocDiffs(ctx context.Context, drw env.DocsReadWriter, fromTbl, toTbl *doltdb.Table, currentDocDetails doltdocs.Docs) { | ||
bold := color.New(color.Bold) | ||
|
||
if docDetails == nil { | ||
docDetails, _ = dEnv.GetAllValidDocDetails() | ||
if currentDocDetails == nil { | ||
currentDocDetails, _ = drw.GetDocsOnDisk() | ||
} | ||
|
||
for _, doc := range docDetails { | ||
if toTbl != nil { | ||
sch1, _ := toTbl.GetSchema(ctx) | ||
doc, _ = doltdb.AddNewerTextToDocFromTbl(ctx, toTbl, &sch1, doc) | ||
for _, doc := range currentDocDetails { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error handling in this entire block is missing |
||
if doc.Text != nil && fromTbl == nil { | ||
printAddedDoc(bold, doc.DocPk) | ||
} else if fromTbl != nil { | ||
if toTbl != nil { | ||
sch1, _ := toTbl.GetSchema(ctx) | ||
doc, _ = doltdocs.GetDocTextFromTbl(ctx, toTbl, &sch1, doc) | ||
} | ||
|
||
} | ||
if fromTbl != nil { | ||
sch2, _ := fromTbl.GetSchema(ctx) | ||
doc, _ = doltdb.AddValueToDocFromTbl(ctx, fromTbl, &sch2, doc) | ||
} | ||
|
||
if doc.Value != nil { | ||
newer := string(doc.NewerText) | ||
older, _ := strconv.Unquote(doc.Value.HumanReadableString()) | ||
lines := textdiff.LineDiffAsLines(older, newer) | ||
if doc.NewerText == nil { | ||
printDeletedDoc(bold, doc.DocPk, lines) | ||
} else if len(lines) > 0 && newer != older { | ||
printModifiedDoc(bold, doc.DocPk, lines) | ||
docToCompareTo, _ := doltdocs.GetDocTextFromTbl(ctx, fromTbl, &sch2, doc) | ||
|
||
if docToCompareTo.Text != nil { | ||
newer := string(doc.Text) | ||
older := string(docToCompareTo.Text) | ||
lines := textdiff.LineDiffAsLines(older, newer) | ||
|
||
if doc.Text == nil { | ||
printDeletedDoc(bold, doc.DocPk, lines) | ||
} else if len(lines) > 0 && newer != older { | ||
printModifiedDoc(bold, doc.DocPk, lines) | ||
} | ||
} | ||
} else if doc.Value == nil && doc.NewerText != nil { | ||
printAddedDoc(bold, doc.DocPk) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
// Copyright 2020 Dolthub, Inc. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might as well update this now GoLand can automate for you |
||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package diff | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb" | ||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs" | ||
"github.com/dolthub/dolt/go/libraries/doltcore/row" | ||
"github.com/dolthub/dolt/go/libraries/doltcore/schema" | ||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding" | ||
"github.com/dolthub/dolt/go/store/types" | ||
) | ||
|
||
func TestDocDiff(t *testing.T) { | ||
ctx := context.Background() | ||
ddb, _ := doltdb.LoadDoltDB(ctx, types.Format_7_18, doltdb.InMemDoltDB) | ||
ddb.WriteEmptyRepo(ctx, "billy bob", "bigbillieb@fake.horse") | ||
|
||
cs, _ := doltdb.NewCommitSpec("master") | ||
cm, _ := ddb.Resolve(ctx, cs, nil) | ||
|
||
root, err := cm.GetRootValue() | ||
assert.NoError(t, err) | ||
|
||
docDetails := []doltdocs.DocDetails{ | ||
{DocPk: doltdb.LicensePk}, | ||
{DocPk: doltdb.ReadmePk}, | ||
} | ||
|
||
// DocDiff between a root and itself should return no added, modified or removed docs. | ||
added, modified, removed, err := DocDiff(ctx, root, root, docDetails) | ||
assert.NoError(t, err) | ||
|
||
if len(added)+len(modified)+len(removed) != 0 { | ||
t.Error("Bad doc diff when comparing two repos") | ||
} | ||
|
||
// Create tbl1 with one license row | ||
sch := createTestDocsSchema() | ||
licRow := makeDocRow(t, sch, doltdb.LicensePk, types.String("license row")) | ||
m, _ := createTestRows(t, ddb.ValueReadWriter(), sch, []row.Row{licRow}) | ||
tbl1, err := CreateTestTable(ddb.ValueReadWriter(), sch, m) | ||
assert.NoError(t, err) | ||
|
||
// Create root2 with tbl1 on it (one doc: license) | ||
root2, err := root.PutTable(ctx, doltdb.DocTableName, tbl1) | ||
assert.NoError(t, err) | ||
|
||
// DocDiff between root and root2 should return one added doc, LICENSE.md | ||
added, modified, removed, err = DocDiff(ctx, root, root2, docDetails) | ||
assert.NoError(t, err) | ||
|
||
if len(added) != 1 || added[0] != "LICENSE.md" || len(modified)+len(removed) != 0 { | ||
t.Error("Bad table diff after adding a single table") | ||
} | ||
|
||
// Create tbl2 with one readme row | ||
readmeRow := makeDocRow(t, sch, doltdb.ReadmePk, types.String("readme row")) | ||
m, _ = createTestRows(t, ddb.ValueReadWriter(), sch, []row.Row{readmeRow}) | ||
tbl2, err := CreateTestTable(ddb.ValueReadWriter(), sch, m) | ||
assert.NoError(t, err) | ||
|
||
// Create root3 with tbl2 on it (one doc: readme) | ||
root3, err := root.PutTable(ctx, doltdb.DocTableName, tbl2) | ||
assert.NoError(t, err) | ||
|
||
// DocDiff between root2 and root3 should return one removed doc (license) and one added doc (readme). | ||
added, modified, removed, err = DocDiff(ctx, root2, root3, docDetails) | ||
assert.NoError(t, err) | ||
|
||
if len(removed) != 1 || removed[0] != "LICENSE.md" || len(added) != 1 || added[0] != "README.md" || len(modified) != 0 { | ||
t.Error("Bad table diff after adding a single table") | ||
} | ||
|
||
// Create tbl3 with 2 doc rows (readme, license) | ||
readmeRowUpdated := makeDocRow(t, sch, doltdb.ReadmePk, types.String("a different readme")) | ||
m, _ = createTestRows(t, ddb.ValueReadWriter(), sch, []row.Row{readmeRowUpdated, licRow}) | ||
tbl3, err := CreateTestTable(ddb.ValueReadWriter(), sch, m) | ||
assert.NoError(t, err) | ||
|
||
// Create root4 with tbl3 on it (two docs: readme and license) | ||
root4, err := root3.PutTable(ctx, doltdb.DocTableName, tbl3) | ||
assert.NoError(t, err) | ||
|
||
// DocDiff between root3 and root4 should return one added doc (license) and one modified doc (readme). | ||
added, modified, removed, err = DocDiff(ctx, root3, root4, nil) | ||
assert.NoError(t, err) | ||
|
||
if len(added) != 1 || added[0] != "LICENSE.md" || len(modified) != 1 || modified[0] != "README.md" || len(removed) != 0 { | ||
t.Error("Bad table diff after adding a single table") | ||
} | ||
|
||
// DocDiff between root4 and root shows 2 remove docs (license, readme) | ||
added, modified, removed, err = DocDiff(ctx, root4, root, nil) | ||
assert.NoError(t, err) | ||
|
||
if len(removed) != 2 || len(modified) != 0 || len(added) != 0 { | ||
t.Error("Bad table diff after adding a single table") | ||
} | ||
} | ||
|
||
func CreateTestTable(vrw types.ValueReadWriter, tSchema schema.Schema, rowData types.Map) (*doltdb.Table, error) { | ||
schemaVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), vrw, tSchema) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
empty, _ := types.NewMap(context.Background(), vrw) | ||
tbl, err := doltdb.NewTable(context.Background(), vrw, schemaVal, rowData, empty) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return tbl, nil | ||
} | ||
|
||
func createTestDocsSchema() schema.Schema { | ||
typedColColl, _ := schema.NewColCollection( | ||
schema.NewColumn(doltdb.DocPkColumnName, schema.DocNameTag, types.StringKind, true, schema.NotNullConstraint{}), | ||
schema.NewColumn(doltdb.DocTextColumnName, schema.DocTextTag, types.StringKind, false), | ||
) | ||
sch, err := schema.SchemaFromCols(typedColColl) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return sch | ||
} | ||
|
||
func makeDocRow(t *testing.T, sch schema.Schema, pk string, rowVal types.Value) row.Row { | ||
row, err := row.New(types.Format_7_18, sch, row.TaggedValues{ | ||
schema.DocNameTag: types.String(pk), | ||
schema.DocTextTag: rowVal, | ||
}) | ||
assert.NoError(t, err) | ||
|
||
return row | ||
} | ||
|
||
func createTestRows(t *testing.T, vrw types.ValueReadWriter, sch schema.Schema, rows []row.Row) (types.Map, []row.Row) { | ||
ctx := context.Background() | ||
var err error | ||
|
||
m, err := types.NewMap(ctx, vrw) | ||
assert.NoError(t, err) | ||
ed := m.Edit() | ||
|
||
for _, r := range rows { | ||
ed = ed.Set(r.NomsMapKey(sch), r.NomsMapValue(sch)) | ||
} | ||
|
||
m, err = ed.Map(ctx) | ||
assert.NoError(t, err) | ||
|
||
return m, rows | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to inspect and handle error here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually why do we need this entire block? Can't we enforce that we get the current docs before calling this? Then we don't need to pass a drw at all