mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-22 02:50:04 -05:00
rip out docs
This commit is contained in:
@@ -87,17 +87,12 @@ func (cmd AddCmd) Exec(ctx context.Context, commandStr string, args []string, dE
|
||||
if apr.NArg() == 0 && !allFlag {
|
||||
cli.Println("Nothing specified, nothing added.\n Maybe you wanted to say 'dolt add .'?")
|
||||
} else if allFlag || apr.NArg() == 1 && apr.Arg(0) == "." {
|
||||
roots, err = actions.StageAllTables(ctx, roots, dEnv.Docs)
|
||||
roots, err = actions.StageAllTables(ctx, roots)
|
||||
if err != nil {
|
||||
return handleStageError(err)
|
||||
}
|
||||
} else {
|
||||
tables, docs, err := actions.GetTablesOrDocs(dEnv.DocsReadWriter(), apr.Args)
|
||||
if err != nil {
|
||||
return handleStageError(err)
|
||||
}
|
||||
|
||||
roots, err = actions.StageTables(ctx, roots, docs, tables)
|
||||
roots, err = actions.StageTables(ctx, roots, apr.Args)
|
||||
if err != nil {
|
||||
return handleStageError(err)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"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/utils/argparser"
|
||||
@@ -132,14 +131,7 @@ func (cmd CheckoutCmd) Exec(ctx context.Context, commandStr string, args []strin
|
||||
return handleResetError(verr, usagePrt)
|
||||
}
|
||||
|
||||
tbls, docs, err := actions.GetTablesOrDocs(dEnv.DocsReadWriter(), args)
|
||||
if err != nil {
|
||||
verr := errhand.BuildDError("error: unable to parse arguments.").AddCause(err).Build()
|
||||
return HandleVErrAndExitCode(verr, usagePrt)
|
||||
}
|
||||
|
||||
verr := checkoutTablesAndDocs(ctx, dEnv, tbls, docs)
|
||||
|
||||
verr := checkoutTables(ctx, dEnv, args)
|
||||
if verr != nil && apr.NArg() == 1 {
|
||||
verr = checkoutRemoteBranchOrSuggestNew(ctx, dEnv, name)
|
||||
}
|
||||
@@ -205,13 +197,13 @@ func checkoutNewBranch(ctx context.Context, dEnv *env.DoltEnv, newBranch string,
|
||||
return checkoutBranch(ctx, dEnv, newBranch, false)
|
||||
}
|
||||
|
||||
func checkoutTablesAndDocs(ctx context.Context, dEnv *env.DoltEnv, tables []string, docs doltdocs.Docs) errhand.VerboseError {
|
||||
func checkoutTables(ctx context.Context, dEnv *env.DoltEnv, tables []string) errhand.VerboseError {
|
||||
roots, err := dEnv.Roots(ctx)
|
||||
if err != nil {
|
||||
return errhand.VerboseErrorFromError(err)
|
||||
}
|
||||
|
||||
err = actions.CheckoutTablesAndDocs(ctx, roots, dEnv.DbData(), tables, docs)
|
||||
err = actions.CheckoutTables(ctx, roots, dEnv.DbData(), tables)
|
||||
|
||||
if err != nil {
|
||||
if doltdb.IsRootValUnreachable(err) {
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/commands"
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/errhand"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env/actions"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/merge"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/argparser"
|
||||
)
|
||||
@@ -141,12 +140,10 @@ func autoResolve(ctx context.Context, apr *argparser.ArgParseResults, dEnv *env.
|
||||
} else {
|
||||
err = merge.AutoResolveTables(ctx, dEnv, autoResolveFunc, tbls)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return errhand.BuildDError("error: failed to resolve").AddCause(err).Build()
|
||||
}
|
||||
|
||||
return saveDocsOnResolve(ctx, dEnv)
|
||||
return nil
|
||||
}
|
||||
|
||||
func manualResolve(ctx context.Context, apr *argparser.ArgParseResults, dEnv *env.DoltEnv) errhand.VerboseError {
|
||||
@@ -225,14 +222,5 @@ func manualResolve(ctx context.Context, apr *argparser.ArgParseResults, dEnv *en
|
||||
|
||||
valid := len(keysToResolve) - len(invalid) - len(notFound)
|
||||
cli.Println(valid, "rows resolved successfully")
|
||||
|
||||
return saveDocsOnResolve(ctx, dEnv)
|
||||
}
|
||||
|
||||
func saveDocsOnResolve(ctx context.Context, dEnv *env.DoltEnv) errhand.VerboseError {
|
||||
err := actions.SaveTrackedDocsFromWorking(ctx, dEnv)
|
||||
if err != nil {
|
||||
return errhand.BuildDError("error: failed to update docs on the filesystem").AddCause(err).Build()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ func (cmd CommitCmd) Exec(ctx context.Context, commandStr string, args []string,
|
||||
}
|
||||
|
||||
if allFlag {
|
||||
roots, err = actions.StageAllTables(ctx, roots, dEnv.Docs)
|
||||
roots, err = actions.StageAllTables(ctx, roots)
|
||||
if err != nil {
|
||||
return handleCommitErr(ctx, dEnv, err, help)
|
||||
}
|
||||
@@ -204,8 +204,7 @@ func handleCommitErr(ctx context.Context, dEnv *env.DoltEnv, err error, usage cl
|
||||
|
||||
if actions.IsNothingStaged(err) {
|
||||
notStagedTbls := actions.NothingStagedTblDiffs(err)
|
||||
notStagedDocs := actions.NothingStagedDocsDiffs(err)
|
||||
n := PrintDiffsNotStaged(ctx, dEnv, cli.CliOut, notStagedTbls, notStagedDocs, false, 0, nil, nil)
|
||||
n := PrintDiffsNotStaged(ctx, dEnv, cli.CliOut, notStagedTbls, false, 0, nil, nil)
|
||||
|
||||
if n == 0 {
|
||||
bdr := errhand.BuildDError(`no changes added to commit (use "dolt add")`)
|
||||
@@ -262,18 +261,9 @@ func buildInitalCommitMsg(ctx context.Context, dEnv *env.DoltEnv) (string, error
|
||||
workingTblsWithViolations = []string{}
|
||||
}
|
||||
|
||||
docsOnDisk, err := dEnv.DocsReadWriter().GetDocsOnDisk()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
stagedDocDiffs, notStagedDocDiffs, err := diff.GetDocDiffs(ctx, roots, docsOnDisk)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
n := printStagedDiffs(buf, stagedTblDiffs, stagedDocDiffs, true)
|
||||
n = PrintDiffsNotStaged(ctx, dEnv, buf, notStagedTblDiffs, notStagedDocDiffs, true, n, workingTblsInConflict, workingTblsWithViolations)
|
||||
n := printStagedDiffs(buf, stagedTblDiffs, true)
|
||||
n = PrintDiffsNotStaged(ctx, dEnv, buf, notStagedTblDiffs, true, n, workingTblsInConflict, workingTblsWithViolations)
|
||||
|
||||
currBranch := dEnv.RepoStateReader().CWBHeadRef()
|
||||
initialCommitMessage := "\n" + "# Please enter the commit message for your changes. Lines starting" + "\n" +
|
||||
@@ -323,7 +313,6 @@ func PrintDiffsNotStaged(
|
||||
dEnv *env.DoltEnv,
|
||||
wr io.Writer,
|
||||
notStagedTbls []diff.TableDelta,
|
||||
notStagedDocs *diff.DocDiffs,
|
||||
printHelp bool,
|
||||
linesPrinted int,
|
||||
workingTblsInConflict, workingTblsWithViolations []string,
|
||||
@@ -373,7 +362,7 @@ func PrintDiffsNotStaged(
|
||||
}
|
||||
}
|
||||
|
||||
numRemovedOrModified := removeModified + notStagedDocs.NumRemoved + notStagedDocs.NumModified
|
||||
numRemovedOrModified := removeModified
|
||||
docsInCnf, _ := docCnfsOnWorkingRoot(ctx, dEnv)
|
||||
|
||||
if numRemovedOrModified-inCnfSet.Size()-violationSet.Size() > 0 {
|
||||
@@ -390,7 +379,7 @@ func PrintDiffsNotStaged(
|
||||
iohelp.WriteLine(wr, workingHeaderHelp)
|
||||
}
|
||||
|
||||
lines := getModifiedAndRemovedNotStaged(notStagedTbls, notStagedDocs, inCnfSet, violationSet)
|
||||
lines := getModifiedAndRemovedNotStaged(notStagedTbls, inCnfSet, violationSet)
|
||||
|
||||
iohelp.WriteLine(wr, color.RedString(strings.Join(lines, "\n")))
|
||||
linesPrinted += len(lines)
|
||||
@@ -398,7 +387,7 @@ func PrintDiffsNotStaged(
|
||||
|
||||
}
|
||||
|
||||
if added > 0 || notStagedDocs.NumAdded > 0 {
|
||||
if added > 0 {
|
||||
if linesPrinted > 0 {
|
||||
cli.Println()
|
||||
}
|
||||
@@ -412,7 +401,7 @@ func PrintDiffsNotStaged(
|
||||
iohelp.WriteLine(wr, untrackedHeaderHelp)
|
||||
}
|
||||
|
||||
lines := getAddedNotStaged(notStagedTbls, notStagedDocs)
|
||||
lines := getAddedNotStaged(notStagedTbls)
|
||||
|
||||
iohelp.WriteLine(wr, color.RedString(strings.Join(lines, "\n")))
|
||||
linesPrinted += len(lines)
|
||||
@@ -424,8 +413,8 @@ func PrintDiffsNotStaged(
|
||||
return linesPrinted
|
||||
}
|
||||
|
||||
func getModifiedAndRemovedNotStaged(notStagedTbls []diff.TableDelta, notStagedDocs *diff.DocDiffs, inCnfSet, violationSet *set.StrSet) (lines []string) {
|
||||
lines = make([]string, 0, len(notStagedTbls)+notStagedDocs.Len())
|
||||
func getModifiedAndRemovedNotStaged(notStagedTbls []diff.TableDelta, inCnfSet, violationSet *set.StrSet) (lines []string) {
|
||||
lines = make([]string, 0, len(notStagedTbls))
|
||||
for _, td := range notStagedTbls {
|
||||
if td.IsAdd() || inCnfSet.Contains(td.CurName()) || violationSet.Contains(td.CurName()) || td.CurName() == doltdb.DocTableName {
|
||||
continue
|
||||
@@ -439,36 +428,17 @@ func getModifiedAndRemovedNotStaged(notStagedTbls []diff.TableDelta, notStagedDo
|
||||
lines = append(lines, fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.ModifiedTable], td.CurName()))
|
||||
}
|
||||
}
|
||||
|
||||
if notStagedDocs.NumRemoved+notStagedDocs.NumModified > 0 {
|
||||
for _, docName := range notStagedDocs.Docs {
|
||||
dtt := notStagedDocs.DocToType[docName]
|
||||
|
||||
if dtt != diff.AddedDoc {
|
||||
lines = append(lines, fmt.Sprintf(statusFmt, docDiffTypeToLabel[dtt], docName))
|
||||
}
|
||||
}
|
||||
}
|
||||
return lines
|
||||
}
|
||||
|
||||
func getAddedNotStaged(notStagedTbls []diff.TableDelta, notStagedDocs *diff.DocDiffs) (lines []string) {
|
||||
lines = make([]string, 0, len(notStagedTbls)+notStagedDocs.Len())
|
||||
func getAddedNotStaged(notStagedTbls []diff.TableDelta) (lines []string) {
|
||||
lines = make([]string, 0, len(notStagedTbls))
|
||||
for _, td := range notStagedTbls {
|
||||
if td.IsAdd() || td.IsRename() {
|
||||
// per Git, unstaged renames are shown as drop + add
|
||||
lines = append(lines, fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.AddedTable], td.CurName()))
|
||||
}
|
||||
}
|
||||
|
||||
for _, docName := range notStagedDocs.Docs {
|
||||
doct := notStagedDocs.DocToType[docName]
|
||||
|
||||
if doct == diff.AddedDoc {
|
||||
lines = append(lines, fmt.Sprintf(statusFmt, docDiffTypeToLabel[doct], docName))
|
||||
}
|
||||
}
|
||||
|
||||
return lines
|
||||
}
|
||||
|
||||
@@ -507,21 +477,15 @@ var tblDiffTypeToLabel = map[diff.TableDiffType]string{
|
||||
diff.AddedTable: "new table:",
|
||||
}
|
||||
|
||||
var docDiffTypeToLabel = map[diff.DocDiffType]string{
|
||||
diff.ModifiedDoc: "modified:",
|
||||
diff.RemovedDoc: "deleted:",
|
||||
diff.AddedDoc: "new doc:",
|
||||
}
|
||||
|
||||
func printStagedDiffs(wr io.Writer, stagedTbls []diff.TableDelta, stagedDocs *diff.DocDiffs, printHelp bool) int {
|
||||
if len(stagedTbls)+stagedDocs.Len() > 0 {
|
||||
func printStagedDiffs(wr io.Writer, stagedTbls []diff.TableDelta, printHelp bool) int {
|
||||
if len(stagedTbls) > 0 {
|
||||
iohelp.WriteLine(wr, stagedHeader)
|
||||
|
||||
if printHelp {
|
||||
iohelp.WriteLine(wr, stagedHeaderHelp)
|
||||
}
|
||||
|
||||
lines := make([]string, 0, len(stagedTbls)+stagedDocs.Len())
|
||||
lines := make([]string, 0, len(stagedTbls))
|
||||
for _, td := range stagedTbls {
|
||||
if !doltdb.IsReadOnlySystemTable(td.CurName()) {
|
||||
if td.IsAdd() {
|
||||
@@ -536,14 +500,8 @@ func printStagedDiffs(wr io.Writer, stagedTbls []diff.TableDelta, stagedDocs *di
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for _, docName := range stagedDocs.Docs {
|
||||
dtt := stagedDocs.DocToType[docName]
|
||||
lines = append(lines, fmt.Sprintf(statusFmt, docDiffTypeToLabel[dtt], docName))
|
||||
}
|
||||
|
||||
iohelp.WriteLine(wr, color.GreenString(strings.Join(lines, "\n")))
|
||||
return len(stagedTbls) + stagedDocs.Len()
|
||||
return len(stagedTbls)
|
||||
}
|
||||
|
||||
return 0
|
||||
|
||||
@@ -32,9 +32,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"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle"
|
||||
@@ -109,7 +107,6 @@ type diffArgs struct {
|
||||
fromRef string
|
||||
toRef string
|
||||
tableSet *set.StrSet
|
||||
docSet *set.StrSet
|
||||
limit int
|
||||
where string
|
||||
}
|
||||
@@ -168,12 +165,6 @@ func (cmd DiffCmd) Exec(ctx context.Context, commandStr string, args []string, d
|
||||
if verr != nil {
|
||||
return HandleVErrAndExitCode(verr, usage)
|
||||
}
|
||||
|
||||
err = diffDoltDocs(ctx, dEnv, dArgs)
|
||||
if err != nil {
|
||||
verr = errhand.BuildDError("error diffing dolt docs").AddCause(err).Build()
|
||||
}
|
||||
|
||||
return HandleVErrAndExitCode(verr, usage)
|
||||
}
|
||||
|
||||
@@ -223,14 +214,8 @@ func parseDiffArgs(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPar
|
||||
}
|
||||
|
||||
dArgs.tableSet = set.NewStrSet(nil)
|
||||
dArgs.docSet = set.NewStrSet(nil)
|
||||
|
||||
for _, tableName := range tableNames {
|
||||
if tableName == doltdocs.ReadmeDoc || tableName == doltdocs.LicenseDoc {
|
||||
dArgs.docSet.Add(tableName)
|
||||
continue
|
||||
}
|
||||
|
||||
// verify table args exist in at least one root
|
||||
_, ok, err := dArgs.fromRoot.GetTable(ctx, tableName)
|
||||
if err != nil {
|
||||
@@ -257,7 +242,6 @@ func parseDiffArgs(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPar
|
||||
return nil, err
|
||||
}
|
||||
dArgs.tableSet.Add(utn...)
|
||||
dArgs.docSet.Add(doltdocs.ReadmeDoc, doltdocs.LicenseDoc)
|
||||
}
|
||||
|
||||
return dArgs, nil
|
||||
@@ -281,16 +265,6 @@ func (dArgs *diffArgs) applyDiffRoots(ctx context.Context, dEnv *env.DoltEnv, ar
|
||||
return nil, err
|
||||
}
|
||||
|
||||
docs, err := dEnv.DocsReadWriter().GetDocsOnDisk()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
workingRoot, err = doltdocs.UpdateRootWithDocs(ctx, workingRoot, docs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dArgs.fromRoot = stagedRoot
|
||||
dArgs.fromRef = "STAGED"
|
||||
dArgs.toRoot = workingRoot
|
||||
@@ -724,48 +698,6 @@ func getColumnNamesString(fromSch, toSch schema.Schema, args *diffArgs) string {
|
||||
return strings.Join(cols, ",")
|
||||
}
|
||||
|
||||
func diffDoltDocs(ctx context.Context, dEnv *env.DoltEnv, dArgs *diffArgs) error {
|
||||
_, docs, err := actions.GetTablesOrDocs(dEnv.DocsReadWriter(), dArgs.docSet.AsSlice())
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return printDocDiffs(ctx, dArgs.fromRoot, dArgs.toRoot, docs)
|
||||
}
|
||||
|
||||
func printDocDiffs(ctx context.Context, from, to *doltdb.RootValue, docsFilter doltdocs.Docs) error {
|
||||
bold := color.New(color.Bold)
|
||||
|
||||
comparisons, err := diff.DocsDiffToComparisons(ctx, from, to, docsFilter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, doc := range docsFilter {
|
||||
for _, comparison := range comparisons {
|
||||
if doc.DocPk == comparison.DocName {
|
||||
if comparison.OldText == nil && comparison.CurrentText != nil {
|
||||
printAddedDoc(bold, comparison.DocName)
|
||||
} else if comparison.OldText != nil {
|
||||
older := string(comparison.OldText)
|
||||
newer := string(comparison.CurrentText)
|
||||
|
||||
lines := textdiff.LineDiffAsLines(older, newer)
|
||||
|
||||
if comparison.CurrentText == nil {
|
||||
printDeletedDoc(bold, comparison.DocName, lines)
|
||||
} else if len(lines) > 0 && newer != older {
|
||||
printModifiedDoc(bold, comparison.DocName, lines)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func printDiffLines(bold *color.Color, lines []string) {
|
||||
for _, line := range lines {
|
||||
if string(line[0]) == string("+") {
|
||||
@@ -778,26 +710,6 @@ func printDiffLines(bold *color.Color, lines []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func printModifiedDoc(bold *color.Color, pk string, lines []string) {
|
||||
_, _ = bold.Printf("diff --dolt a/%[1]s b/%[1]s\n", pk)
|
||||
_, _ = bold.Printf("--- a/%s\n", pk)
|
||||
_, _ = bold.Printf("+++ b/%s\n", pk)
|
||||
|
||||
printDiffLines(bold, lines)
|
||||
}
|
||||
|
||||
func printAddedDoc(bold *color.Color, pk string) {
|
||||
_, _ = bold.Printf("diff --dolt a/%[1]s b/%[1]s\n", pk)
|
||||
_, _ = bold.Println("added doc")
|
||||
}
|
||||
|
||||
func printDeletedDoc(bold *color.Color, pk string, lines []string) {
|
||||
_, _ = bold.Printf("diff --dolt a/%[1]s b/%[1]s\n", pk)
|
||||
_, _ = bold.Println("deleted doc")
|
||||
|
||||
printDiffLines(bold, lines)
|
||||
}
|
||||
|
||||
func printTableDiffSummary(td diff.TableDelta) {
|
||||
bold := color.New(color.Bold)
|
||||
if td.IsDrop() {
|
||||
|
||||
@@ -17,6 +17,8 @@ package docscmds
|
||||
import (
|
||||
"context"
|
||||
|
||||
textdiff "github.com/andreyvit/diff"
|
||||
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/cli"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/argparser"
|
||||
@@ -59,5 +61,68 @@ func (cmd DiffCmd) ArgParser() *argparser.ArgParser {
|
||||
|
||||
// Exec implements cli.Command.
|
||||
func (cmd DiffCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
textdiff.LineDiff("abc", "xyz")
|
||||
panic("dolt docs diff")
|
||||
}
|
||||
|
||||
//func diffDoltDocs(ctx context.Context, dEnv *env.DoltEnv, dArgs *diffArgs) error {
|
||||
// _, docs, err := actions.GetTables(dArgs.docSet.AsSlice())
|
||||
//
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// return printDocDiffs(ctx, dArgs.fromRoot, dArgs.toRoot, docs)
|
||||
//}
|
||||
//
|
||||
//func printDocDiffs(ctx context.Context, from, to *doltdb.RootValue, docsFilter doltdocs.Docs) error {
|
||||
// bold := color.New(color.Bold)
|
||||
//
|
||||
// comparisons, err := diff.DocsDiffToComparisons(ctx, from, to, docsFilter)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// for _, doc := range docsFilter {
|
||||
// for _, comparison := range comparisons {
|
||||
// if doc.DocPk == comparison.DocName {
|
||||
// if comparison.OldText == nil && comparison.CurrentText != nil {
|
||||
// printAddedDoc(bold, comparison.DocName)
|
||||
// } else if comparison.OldText != nil {
|
||||
// older := string(comparison.OldText)
|
||||
// newer := string(comparison.CurrentText)
|
||||
//
|
||||
// lines := textdiff.LineDiffAsLines(older, newer)
|
||||
//
|
||||
// if comparison.CurrentText == nil {
|
||||
// printDeletedDoc(bold, comparison.DocName, lines)
|
||||
// } else if len(lines) > 0 && newer != older {
|
||||
// printModifiedDoc(bold, comparison.DocName, lines)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//func printModifiedDoc(bold *color.Color, pk string, lines []string) {
|
||||
// _, _ = bold.Printf("diff --dolt a/%[1]s b/%[1]s\n", pk)
|
||||
// _, _ = bold.Printf("--- a/%s\n", pk)
|
||||
// _, _ = bold.Printf("+++ b/%s\n", pk)
|
||||
//
|
||||
// printDiffLines(bold, lines)
|
||||
//}
|
||||
//
|
||||
//func printAddedDoc(bold *color.Color, pk string) {
|
||||
// _, _ = bold.Printf("diff --dolt a/%[1]s b/%[1]s\n", pk)
|
||||
// _, _ = bold.Println("added doc")
|
||||
//}
|
||||
//
|
||||
//func printDeletedDoc(bold *color.Color, pk string, lines []string) {
|
||||
// _, _ = bold.Printf("diff --dolt a/%[1]s b/%[1]s\n", pk)
|
||||
// _, _ = bold.Println("deleted doc")
|
||||
//
|
||||
// printDiffLines(bold, lines)
|
||||
//}
|
||||
|
||||
@@ -159,9 +159,6 @@ func MaybeMigrateEnv(ctx context.Context, dEnv *env.DoltEnv) (*env.DoltEnv, erro
|
||||
if tmp.RSLoadErr != nil {
|
||||
return nil, tmp.RSLoadErr
|
||||
}
|
||||
if tmp.DocsLoadErr != nil {
|
||||
return nil, tmp.DocsLoadErr
|
||||
}
|
||||
if tmp.DBLoadError != nil {
|
||||
return nil, tmp.DBLoadError
|
||||
}
|
||||
|
||||
@@ -149,12 +149,6 @@ var tblDiffTypeToShortLabel = map[diff.TableDiffType]string{
|
||||
diff.AddedTable: "N",
|
||||
}
|
||||
|
||||
var docDiffTypeToShortLabel = map[diff.DocDiffType]string{
|
||||
diff.ModifiedDoc: "M",
|
||||
diff.RemovedDoc: "D",
|
||||
diff.AddedDoc: "N",
|
||||
}
|
||||
|
||||
func printNotStaged(ctx context.Context, dEnv *env.DoltEnv, staged *doltdb.RootValue) {
|
||||
// Printing here is best effort. Fail silently
|
||||
working, err := dEnv.WorkingRoot(ctx)
|
||||
@@ -168,11 +162,6 @@ func printNotStaged(ctx context.Context, dEnv *env.DoltEnv, staged *doltdb.RootV
|
||||
return
|
||||
}
|
||||
|
||||
notStagedDocs, err := diff.NewDocDiffs(ctx, working, nil, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
removeModified := 0
|
||||
for _, td := range notStagedTbls {
|
||||
if !td.IsAdd() {
|
||||
@@ -180,7 +169,7 @@ func printNotStaged(ctx context.Context, dEnv *env.DoltEnv, staged *doltdb.RootV
|
||||
}
|
||||
}
|
||||
|
||||
if removeModified+notStagedDocs.NumRemoved+notStagedDocs.NumModified > 0 {
|
||||
if removeModified > 0 {
|
||||
cli.Println("Unstaged changes after reset:")
|
||||
|
||||
var lines []string
|
||||
@@ -197,14 +186,6 @@ func printNotStaged(ctx context.Context, dEnv *env.DoltEnv, staged *doltdb.RootV
|
||||
lines = append(lines, fmt.Sprintf("%s\t%s", tblDiffTypeToShortLabel[diff.ModifiedTable], td.CurName()))
|
||||
}
|
||||
}
|
||||
|
||||
for _, docName := range notStagedDocs.Docs {
|
||||
ddt := notStagedDocs.DocToType[docName]
|
||||
if ddt != diff.AddedDoc {
|
||||
lines = append(lines, fmt.Sprintf("%s\t%s", docDiffTypeToShortLabel[ddt], docName))
|
||||
}
|
||||
}
|
||||
|
||||
cli.Println(strings.Join(lines, "\n"))
|
||||
}
|
||||
}
|
||||
@@ -233,25 +214,3 @@ func handleResetError(err error, usage cli.UsagePrinter) int {
|
||||
|
||||
return HandleVErrAndExitCode(verr, usage)
|
||||
}
|
||||
|
||||
func getAllRoots(ctx context.Context, dEnv *env.DoltEnv) (*doltdb.RootValue, *doltdb.RootValue, *doltdb.RootValue, errhand.VerboseError) {
|
||||
workingRoot, err := dEnv.WorkingRoot(ctx)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, nil, errhand.BuildDError("Unable to get staged.").AddCause(err).Build()
|
||||
}
|
||||
|
||||
stagedRoot, err := dEnv.StagedRoot(ctx)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, nil, errhand.BuildDError("Unable to get staged.").AddCause(err).Build()
|
||||
}
|
||||
|
||||
headRoot, err := dEnv.HeadRoot(ctx)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, nil, errhand.BuildDError("Unable to get at HEAD.").AddCause(err).Build()
|
||||
}
|
||||
|
||||
return workingRoot, stagedRoot, headRoot, nil
|
||||
}
|
||||
|
||||
@@ -86,17 +86,7 @@ func (cmd StatusCmd) Exec(ctx context.Context, commandStr string, args []string,
|
||||
return handleStatusVErr(err)
|
||||
}
|
||||
|
||||
docsOnDisk, err := dEnv.DocsReadWriter().GetDocsOnDisk()
|
||||
if err != nil {
|
||||
return handleStatusVErr(err)
|
||||
}
|
||||
|
||||
stagedDocDiffs, notStagedDocDiffs, err := diff.GetDocDiffs(ctx, roots, docsOnDisk)
|
||||
if err != nil {
|
||||
return handleStatusVErr(err)
|
||||
}
|
||||
|
||||
err = PrintStatus(ctx, dEnv, staged, notStaged, workingTblsInConflict, workingTblsWithViolations, stagedDocDiffs, notStagedDocDiffs)
|
||||
err = PrintStatus(ctx, dEnv, staged, notStaged, workingTblsInConflict, workingTblsWithViolations)
|
||||
if err != nil {
|
||||
return handleStatusVErr(err)
|
||||
}
|
||||
@@ -105,7 +95,7 @@ func (cmd StatusCmd) Exec(ctx context.Context, commandStr string, args []string,
|
||||
}
|
||||
|
||||
// TODO: working docs in conflict param not used here
|
||||
func PrintStatus(ctx context.Context, dEnv *env.DoltEnv, stagedTbls, notStagedTbls []diff.TableDelta, workingTblsInConflict, workingTblsWithViolations []string, stagedDocs, notStagedDocs *diff.DocDiffs) error {
|
||||
func PrintStatus(ctx context.Context, dEnv *env.DoltEnv, stagedTbls, notStagedTbls []diff.TableDelta, workingTblsInConflict, workingTblsWithViolations []string) error {
|
||||
cli.Printf(branchHeader, dEnv.RepoStateReader().CWBHeadRef().GetPath())
|
||||
|
||||
err := printRemoteRefTrackingInfo(ctx, dEnv)
|
||||
@@ -130,8 +120,8 @@ func PrintStatus(ctx context.Context, dEnv *env.DoltEnv, stagedTbls, notStagedTb
|
||||
}
|
||||
}
|
||||
|
||||
n := printStagedDiffs(cli.CliOut, stagedTbls, stagedDocs, true)
|
||||
n = PrintDiffsNotStaged(ctx, dEnv, cli.CliOut, notStagedTbls, notStagedDocs, true, n, workingTblsInConflict, workingTblsWithViolations)
|
||||
n := printStagedDiffs(cli.CliOut, stagedTbls, true)
|
||||
n = PrintDiffsNotStaged(ctx, dEnv, cli.CliOut, notStagedTbls, true, n, workingTblsInConflict, workingTblsWithViolations)
|
||||
|
||||
if !mergeActive && n == 0 {
|
||||
cli.Println("nothing to commit, working tree clean")
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
// Copyright 2020 Dolthub, Inc.
|
||||
//
|
||||
// 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/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
filesys2 "github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
func TestDocDiff(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ddb, _ := doltdb.LoadDoltDB(ctx, types.Format_Default, doltdb.InMemDoltDB, filesys2.LocalFS)
|
||||
ddb.WriteEmptyRepo(ctx, env.DefaultInitBranch, "billy bob", "bigbillieb@fake.horse")
|
||||
|
||||
cs, _ := doltdb.NewCommitSpec(env.DefaultInitBranch)
|
||||
cm, _ := ddb.Resolve(ctx, cs, nil)
|
||||
|
||||
root, err := cm.GetRootValue(ctx)
|
||||
assert.NoError(t, err)
|
||||
|
||||
docs := doltdocs.Docs{
|
||||
{DocPk: doltdocs.LicenseDoc},
|
||||
{DocPk: doltdocs.ReadmeDoc},
|
||||
}
|
||||
|
||||
// DocsDiff between a root and itself should return no added, modified or removed docs.
|
||||
added, modified, removed, err := DocsDiff(ctx, root, root, docs)
|
||||
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, doltdocs.LicenseDoc, 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)
|
||||
|
||||
// DocsDiff between root and root2 should return one added doc, LICENSE.md
|
||||
added, modified, removed, err = DocsDiff(ctx, root, root2, docs)
|
||||
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, doltdocs.ReadmeDoc, 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)
|
||||
|
||||
// DocsDiff between root2 and root3 should return one removed doc (license) and one added doc (readme).
|
||||
added, modified, removed, err = DocsDiff(ctx, root2, root3, docs)
|
||||
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, doltdocs.ReadmeDoc, 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)
|
||||
|
||||
// DocsDiff between root3 and root4 should return one added doc (license) and one modified doc (readme).
|
||||
added, modified, removed, err = DocsDiff(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")
|
||||
}
|
||||
|
||||
// DocsDiff between root4 and root shows 2 remove docs (license, readme)
|
||||
added, modified, removed, err = DocsDiff(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) {
|
||||
tbl, err := doltdb.NewNomsTable(context.Background(), vrw, tSchema, rowData, nil, nil)
|
||||
|
||||
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_Default, 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
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
// Copyright 2020 Dolthub, Inc.
|
||||
//
|
||||
// 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"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
|
||||
)
|
||||
|
||||
type TableDiffType int
|
||||
|
||||
const (
|
||||
AddedTable TableDiffType = iota
|
||||
ModifiedTable
|
||||
RenamedTable
|
||||
RemovedTable
|
||||
)
|
||||
|
||||
type DocDiffType int
|
||||
|
||||
const (
|
||||
AddedDoc DocDiffType = iota
|
||||
ModifiedDoc
|
||||
RemovedDoc
|
||||
)
|
||||
|
||||
type DocDiffs struct {
|
||||
NumAdded int
|
||||
NumModified int
|
||||
NumRemoved int
|
||||
DocToType map[string]DocDiffType
|
||||
Docs []string
|
||||
}
|
||||
|
||||
// NewDocDiffs returns DocDiffs for Dolt Docs between two roots.
|
||||
func NewDocDiffs(ctx context.Context, older *doltdb.RootValue, newer *doltdb.RootValue, docs doltdocs.Docs) (*DocDiffs, error) {
|
||||
var added []string
|
||||
var modified []string
|
||||
var removed []string
|
||||
if older != nil {
|
||||
if newer == nil {
|
||||
a, m, r, err := DocsDiff(ctx, older, nil, docs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
added = a
|
||||
modified = m
|
||||
removed = r
|
||||
} else {
|
||||
a, m, r, err := DocsDiff(ctx, older, newer, docs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
added = a
|
||||
modified = m
|
||||
removed = r
|
||||
}
|
||||
}
|
||||
var docNames []string
|
||||
docNames = append(docNames, added...)
|
||||
docNames = append(docNames, modified...)
|
||||
docNames = append(docNames, removed...)
|
||||
sort.Strings(docNames)
|
||||
|
||||
docsToType := make(map[string]DocDiffType)
|
||||
for _, nt := range added {
|
||||
docsToType[nt] = AddedDoc
|
||||
}
|
||||
|
||||
for _, nt := range modified {
|
||||
docsToType[nt] = ModifiedDoc
|
||||
}
|
||||
|
||||
for _, nt := range removed {
|
||||
docsToType[nt] = RemovedDoc
|
||||
}
|
||||
|
||||
return &DocDiffs{len(added), len(modified), len(removed), docsToType, docNames}, nil
|
||||
}
|
||||
|
||||
// Len returns the number of docs in a DocDiffs
|
||||
func (nd *DocDiffs) Len() int {
|
||||
return len(nd.Docs)
|
||||
}
|
||||
|
||||
// GetDocDiffs retrieves staged and unstaged DocDiffs.
|
||||
func GetDocDiffs(
|
||||
ctx context.Context,
|
||||
roots doltdb.Roots,
|
||||
docsOnDisk doltdocs.Docs,
|
||||
) (*DocDiffs, *DocDiffs, error) {
|
||||
notStagedDocDiffs, err := NewDocDiffs(ctx, roots.Working, nil, docsOnDisk)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
stagedDocDiffs, err := NewDocDiffs(ctx, roots.Head, roots.Staged, docsOnDisk)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return stagedDocDiffs, notStagedDocDiffs, nil
|
||||
}
|
||||
|
||||
type docComparison struct {
|
||||
DocName string
|
||||
CurrentText []byte
|
||||
OldText []byte
|
||||
}
|
||||
|
||||
// DocsDiff returns the added, modified and removed docs when comparing a root value with an other (newer) value. If the other value,
|
||||
// is not provided, then we compare the docs on the root value to the docs provided.
|
||||
func DocsDiff(ctx context.Context, root *doltdb.RootValue, other *doltdb.RootValue, docs doltdocs.Docs) (added, modified, removed []string, err error) {
|
||||
docComparisons, err := DocsDiffToComparisons(ctx, root, other, docs)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
a, m, r := computeDiffsFromDocComparisons(docComparisons)
|
||||
return a, m, r, nil
|
||||
}
|
||||
|
||||
// DocsDiffToComparisons returns the docComparisons between an old root, a new root, and a set of docs. It is exported
|
||||
// due to the cli usage of doc diffs.
|
||||
func DocsDiffToComparisons(ctx context.Context, root *doltdb.RootValue, other *doltdb.RootValue, docs doltdocs.Docs) ([]docComparison, error) {
|
||||
if other == nil {
|
||||
return compareRootWithDocs(ctx, root, docs)
|
||||
} else {
|
||||
return compareDocsBtwnRoots(ctx, root, other)
|
||||
}
|
||||
}
|
||||
|
||||
// compareRootWithDocs compares a root and set of new docs.
|
||||
func compareRootWithDocs(ctx context.Context, root *doltdb.RootValue, docs doltdocs.Docs) ([]docComparison, error) {
|
||||
oldDocs, found, err := doltdocs.GetAllDocs(ctx, root)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
oldDocs = make(doltdocs.Docs, 0)
|
||||
}
|
||||
|
||||
return getDocComparisons(oldDocs, docs), nil
|
||||
}
|
||||
|
||||
// compareDocsBtwnRoots takes an oldRoot and a newRoot and compares the docs tables between the two.
|
||||
func compareDocsBtwnRoots(ctx context.Context, oldRoot *doltdb.RootValue, newRoot *doltdb.RootValue) ([]docComparison, error) {
|
||||
oldDocs, found, err := doltdocs.GetAllDocs(ctx, oldRoot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
oldDocs = make(doltdocs.Docs, 0)
|
||||
}
|
||||
|
||||
newDocs, found, err := doltdocs.GetAllDocs(ctx, newRoot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
newDocs = make(doltdocs.Docs, 0)
|
||||
}
|
||||
|
||||
return getDocComparisons(oldDocs, newDocs), nil
|
||||
}
|
||||
|
||||
// getDocComparisons compares two sets of docs looking for modifications, removals, and additions as docComparisons
|
||||
func getDocComparisons(oldDocs doltdocs.Docs, newDocs doltdocs.Docs) []docComparison {
|
||||
docComparisons := make([]docComparison, 0)
|
||||
|
||||
// First case is looking at the old docs and seeing what was modified or removed
|
||||
for _, oldDoc := range oldDocs {
|
||||
dc := docComparison{DocName: oldDoc.DocPk, OldText: oldDoc.Text, CurrentText: getMatchingText(oldDoc, newDocs)}
|
||||
docComparisons = append(docComparisons, dc)
|
||||
}
|
||||
|
||||
// Second case is looking back at the old docs and seeing what was added
|
||||
for _, newDoc := range newDocs {
|
||||
oldText := getMatchingText(newDoc, oldDocs)
|
||||
if oldText == nil {
|
||||
dc := docComparison{DocName: newDoc.DocPk, OldText: nil, CurrentText: newDoc.Text}
|
||||
docComparisons = append(docComparisons, dc)
|
||||
}
|
||||
}
|
||||
|
||||
return docComparisons
|
||||
}
|
||||
|
||||
// getMatchingText matches a doc in a set of other docs and returns the relevant text.
|
||||
func getMatchingText(doc doltdocs.Doc, docs doltdocs.Docs) []byte {
|
||||
for _, toCompare := range docs {
|
||||
if doc.DocPk == toCompare.DocPk {
|
||||
return toCompare.Text
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// computeDiffsFromDocComparisons takes the docComparisons and returns the final add, modified, removed count.
|
||||
func computeDiffsFromDocComparisons(docComparisons []docComparison) (added, modified, removed []string) {
|
||||
added = []string{}
|
||||
modified = []string{}
|
||||
removed = []string{}
|
||||
for _, doc := range docComparisons {
|
||||
added, modified, removed = appendDocDiffs(added, modified, removed, doc.OldText, doc.CurrentText, doc.DocName)
|
||||
}
|
||||
return added, modified, removed
|
||||
}
|
||||
|
||||
func appendDocDiffs(added, modified, removed []string, olderVal []byte, newerVal []byte, docPk string) (add, mod, rem []string) {
|
||||
if olderVal == nil && newerVal != nil {
|
||||
added = append(added, docPk)
|
||||
} else if olderVal != nil {
|
||||
if newerVal == nil {
|
||||
removed = append(removed, docPk)
|
||||
} else if strconv.Quote(string(olderVal)) != strconv.Quote(string(newerVal)) {
|
||||
modified = append(modified, docPk)
|
||||
}
|
||||
}
|
||||
return added, modified, removed
|
||||
}
|
||||
@@ -27,6 +27,15 @@ import (
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
type TableDiffType int
|
||||
|
||||
const (
|
||||
AddedTable TableDiffType = iota
|
||||
ModifiedTable
|
||||
RenamedTable
|
||||
RemovedTable
|
||||
)
|
||||
|
||||
// TableDelta represents the change of a single table between two roots.
|
||||
// FromFKs and ToFKs contain Foreign Keys that constrain columns in this table,
|
||||
// they do not contain Foreign Keys that reference this table.
|
||||
|
||||
@@ -20,9 +20,10 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/funcitr"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/utils/set"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -153,6 +154,20 @@ var generatedSystemTablePrefixes = []string{
|
||||
DoltConstViolTablePrefix,
|
||||
}
|
||||
|
||||
const (
|
||||
// LicenseDoc is the key for accessing the license within the docs table
|
||||
LicenseDoc = "LICENSE.md"
|
||||
// ReadmeDoc is the key for accessing the readme within the docs table
|
||||
ReadmeDoc = "README.md"
|
||||
)
|
||||
|
||||
// todo(andy)
|
||||
var doltDocsColumns = schema.NewColCollection(
|
||||
schema.NewColumn(DocPkColumnName, schema.DocNameTag, types.StringKind, true, schema.NotNullConstraint{}),
|
||||
schema.NewColumn(DocTextColumnName, schema.DocTextTag, types.StringKind, false),
|
||||
)
|
||||
var DocsSchema = schema.MustSchemaFromCols(doltDocsColumns)
|
||||
|
||||
const (
|
||||
// DocTableName is the name of the dolt table containing documents such as the license and readme
|
||||
DocTableName = "dolt_docs"
|
||||
|
||||
@@ -1,256 +0,0 @@
|
||||
// Copyright 2020 Dolthub, Inc.
|
||||
//
|
||||
// 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 doltdocs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dbfactory"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
var ErrDocsUpdate = errors.New("error updating local docs")
|
||||
var ErrEmptyDocsTable = errors.New("error: All docs removed. Removing Docs Table")
|
||||
var ErrMarshallingSchema = errors.New("error marshalling schema")
|
||||
|
||||
var doltDocsColumns = schema.NewColCollection(
|
||||
schema.NewColumn(doltdb.DocPkColumnName, schema.DocNameTag, types.StringKind, true, schema.NotNullConstraint{}),
|
||||
schema.NewColumn(doltdb.DocTextColumnName, schema.DocTextTag, types.StringKind, false),
|
||||
)
|
||||
var DocsSchema = schema.MustSchemaFromCols(doltDocsColumns)
|
||||
|
||||
type Doc struct {
|
||||
Text []byte
|
||||
DocPk string
|
||||
File string
|
||||
}
|
||||
|
||||
type Docs []Doc
|
||||
|
||||
const (
|
||||
ReadmeFile = "../README.md"
|
||||
LicenseFile = "../LICENSE.md"
|
||||
|
||||
// LicenseDoc is the key for accessing the license within the docs table
|
||||
LicenseDoc = "LICENSE.md"
|
||||
// ReadmeDoc is the key for accessing the readme within the docs table
|
||||
ReadmeDoc = "README.md"
|
||||
)
|
||||
|
||||
var SupportedDocs = Docs{
|
||||
{DocPk: ReadmeDoc, File: ReadmeFile},
|
||||
{DocPk: LicenseDoc, File: LicenseFile},
|
||||
}
|
||||
|
||||
// GetLocalFileText returns a byte slice representing the contents of the provided file, if it exists
|
||||
func GetLocalFileText(fs filesys.Filesys, file string) ([]byte, error) {
|
||||
path := ""
|
||||
if DocFileExists(fs, file) {
|
||||
path = GetDocFilePath(file)
|
||||
}
|
||||
|
||||
if path != "" {
|
||||
return fs.ReadFile(path)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// GetSupportedDocs takes in a filesystem and returns the contents of all docs on disk.
|
||||
func GetSupportedDocs(fs filesys.Filesys) (docs Docs, err error) {
|
||||
docs = Docs{}
|
||||
for _, doc := range SupportedDocs {
|
||||
newerText, err := GetLocalFileText(fs, doc.File)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
doc.Text = newerText
|
||||
docs = append(docs, doc)
|
||||
}
|
||||
return docs, nil
|
||||
}
|
||||
|
||||
// GetDoc takes in a filesystem and a docName and returns the doc's contents.
|
||||
func GetDoc(fs filesys.Filesys, docName string) (doc Doc, err error) {
|
||||
for _, doc := range SupportedDocs {
|
||||
if doc.DocPk == docName {
|
||||
newerText, err := GetLocalFileText(fs, doc.File)
|
||||
if err != nil {
|
||||
return Doc{}, err
|
||||
}
|
||||
doc.Text = newerText
|
||||
return doc, nil
|
||||
}
|
||||
}
|
||||
return Doc{}, err
|
||||
}
|
||||
|
||||
func GetDocNamesFromDocs(docs Docs) []string {
|
||||
if docs == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
ret := make([]string, len(docs))
|
||||
|
||||
for i, doc := range docs {
|
||||
ret[i] = doc.DocPk
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
// GetDocsFromRoot takes in a root value and returns the docs stored in its dolt_docs table.
|
||||
func GetDocsFromRoot(ctx context.Context, root *doltdb.RootValue, docNames ...string) (Docs, error) {
|
||||
docTbl, docTblFound, err := root.GetTable(ctx, doltdb.DocTableName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var sch schema.Schema
|
||||
if docTblFound {
|
||||
docSch, err := docTbl.GetSchema(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sch = docSch
|
||||
}
|
||||
|
||||
if docNames == nil {
|
||||
docNames = GetDocNamesFromDocs(SupportedDocs)
|
||||
}
|
||||
|
||||
docs := make(Docs, len(docNames))
|
||||
for i, name := range docNames {
|
||||
doc, isSupported := IsSupportedDoc(name)
|
||||
if !isSupported {
|
||||
return nil, fmt.Errorf("%s is not a supported doc", name)
|
||||
}
|
||||
|
||||
docText, err := getDocTextFromTbl(ctx, docTbl, &sch, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
doc.Text = docText
|
||||
docs[i] = doc
|
||||
}
|
||||
|
||||
return docs, nil
|
||||
}
|
||||
|
||||
// Save takes in a fs object and saves all the docs to the filesystem, overwriting any existing files.
|
||||
func (docs Docs) Save(fs filesys.ReadWriteFS) error {
|
||||
for _, doc := range docs {
|
||||
if _, ok := IsSupportedDoc(doc.DocPk); !ok {
|
||||
continue
|
||||
}
|
||||
filePath := GetDocFilePath(doc.File)
|
||||
if doc.Text != nil {
|
||||
err := fs.WriteFile(filePath, doc.Text)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err := DeleteDoc(fs, doc.DocPk)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetDocFilePath takes in a filename and appends it to the DoltDir filepath.
|
||||
func GetDocFilePath(filename string) string {
|
||||
return filepath.Join(dbfactory.DoltDir, filename)
|
||||
}
|
||||
|
||||
// LoadDocs takes in a fs object and reads all the docs (ex. README.md) defined in SupportedDocs.
|
||||
func LoadDocs(fs filesys.ReadWriteFS) (Docs, error) {
|
||||
docsWithCurrentText := SupportedDocs
|
||||
for i, val := range docsWithCurrentText {
|
||||
path := GetDocFilePath(val.File)
|
||||
exists, isDir := fs.Exists(path)
|
||||
if exists && !isDir {
|
||||
data, err := fs.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
val.Text = data
|
||||
docsWithCurrentText[i] = val
|
||||
}
|
||||
}
|
||||
return docsWithCurrentText, nil
|
||||
}
|
||||
|
||||
func IsSupportedDoc(docName string) (Doc, bool) {
|
||||
for _, doc := range SupportedDocs {
|
||||
if doc.DocPk == docName {
|
||||
return doc, true
|
||||
}
|
||||
}
|
||||
return Doc{}, false
|
||||
}
|
||||
|
||||
func DocFileExists(fs filesys.ReadWriteFS, file string) bool {
|
||||
exists, isDir := fs.Exists(GetDocFilePath(file))
|
||||
return exists && !isDir
|
||||
}
|
||||
|
||||
// DeleteDoc takes in a filesytem object and deletes the file with docName, if it's a SupportedDoc.
|
||||
func DeleteDoc(fs filesys.ReadWriteFS, docName string) error {
|
||||
if doc, ok := IsSupportedDoc(docName); ok {
|
||||
if doc.DocPk == docName {
|
||||
path := GetDocFilePath(doc.File)
|
||||
exists, isDir := fs.Exists(path)
|
||||
if exists && !isDir {
|
||||
return fs.DeleteFile(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateRootWithDocs takes in a root value, and some docs and writes those docs to the dolt_docs table
|
||||
// (perhaps creating it in the process). The table might not necessarily need to be created if there are no docs in the
|
||||
// repo yet.
|
||||
func UpdateRootWithDocs(ctx context.Context, root *doltdb.RootValue, docs Docs) (*doltdb.RootValue, error) {
|
||||
docTbl, err := CreateOrUpdateDocsTable(ctx, root, docs)
|
||||
|
||||
if errors.Is(ErrEmptyDocsTable, err) {
|
||||
root, err = root.RemoveTables(ctx, false, false, doltdb.DocTableName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// There might not need be a need to create docs table if not docs have been created yet so check if docTbl != nil.
|
||||
if docTbl != nil {
|
||||
root, err = root.PutTable(ctx, doltdb.DocTableName, docTbl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return root, nil
|
||||
}
|
||||
@@ -1,281 +0,0 @@
|
||||
// Copyright 2020 Dolthub, Inc.
|
||||
//
|
||||
// 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 doltdocs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
// updateDocsTable takes in docTbl param and updates it with the value in docs. It returns the updated table.
|
||||
func updateDocsTable(ctx context.Context, docTbl *doltdb.Table, docs Docs) (*doltdb.Table, error) {
|
||||
m, err := docTbl.GetNomsRowData(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sch, err := docTbl.GetSchema(context.Background())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nbf := m.Format()
|
||||
|
||||
me := m.Edit()
|
||||
for _, doc := range docs {
|
||||
key, err := docTblKeyFromName(docTbl.Format(), doc.DocPk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
docRow, exists, err := table.GetRow(ctx, docTbl, sch, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if exists && doc.Text == nil {
|
||||
me = me.Remove(docRow.NomsMapKey(sch))
|
||||
} else if doc.Text != nil {
|
||||
docTaggedVals := row.TaggedValues{
|
||||
schema.DocNameTag: types.String(doc.DocPk),
|
||||
schema.DocTextTag: types.String(doc.Text),
|
||||
}
|
||||
docRow, err = row.New(nbf, sch, docTaggedVals)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
me = me.Set(docRow.NomsMapKey(sch), docRow.NomsMapValue(sch))
|
||||
}
|
||||
}
|
||||
updatedMap, err := me.Map(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if updatedMap.Len() == 0 {
|
||||
return nil, ErrEmptyDocsTable
|
||||
}
|
||||
|
||||
docTbl, err = docTbl.UpdateNomsRows(ctx, updatedMap)
|
||||
|
||||
return docTbl, err
|
||||
}
|
||||
|
||||
// createDocsTable creates a new in memory table that stores the given doc details.
|
||||
func createDocsTable(ctx context.Context, vrw types.ValueReadWriter, docs Docs) (*doltdb.Table, error) {
|
||||
|
||||
rows := make([]row.Row, 0, len(docs))
|
||||
|
||||
// Determines if the table needs to be created at all and initializes a schema if it does.
|
||||
for _, doc := range docs {
|
||||
|
||||
if doc.Text != nil {
|
||||
docTaggedVals := row.TaggedValues{
|
||||
schema.DocNameTag: types.String(doc.DocPk),
|
||||
schema.DocTextTag: types.String(doc.Text),
|
||||
}
|
||||
|
||||
r, err := row.New(vrw.Format(), DocsSchema, docTaggedVals)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows = append(rows, r)
|
||||
}
|
||||
}
|
||||
|
||||
if len(rows) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
empty, err := types.NewMap(ctx, vrw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
me := empty.Edit()
|
||||
for _, r := range rows {
|
||||
k, v := r.NomsMapKey(DocsSchema), r.NomsMapValue(DocsSchema)
|
||||
me.Set(k, v)
|
||||
}
|
||||
|
||||
rowMap, err := me.Map(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
newDocsTbl, err := doltdb.NewNomsTable(ctx, vrw, DocsSchema, rowMap, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newDocsTbl, nil
|
||||
}
|
||||
|
||||
// CreateOrUpdateDocsTable takes a root value and a set of docs and either creates the docs table or updates it with docs.
|
||||
func CreateOrUpdateDocsTable(ctx context.Context, root *doltdb.RootValue, docs Docs) (*doltdb.Table, error) {
|
||||
docsTbl, found, err := root.GetTable(ctx, doltdb.DocTableName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if found {
|
||||
return updateDocsTable(ctx, docsTbl, docs)
|
||||
} else {
|
||||
return createDocsTable(ctx, root.VRW(), docs)
|
||||
}
|
||||
}
|
||||
|
||||
func docTblKeyFromName(fmt *types.NomsBinFormat, name string) (types.Tuple, error) {
|
||||
return types.NewTuple(fmt, types.Uint(schema.DocNameTag), types.String(name))
|
||||
}
|
||||
|
||||
// getDocTextFromTbl returns the Text field of a doc using the provided table and schema and primary key.
|
||||
func getDocTextFromTbl(ctx context.Context, tbl *doltdb.Table, sch *schema.Schema, docPk string) ([]byte, error) {
|
||||
if tbl != nil && sch != nil {
|
||||
key, err := docTblKeyFromName(tbl.Format(), docPk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
docRow, ok, err := getDocRow(ctx, tbl, *sch, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ok {
|
||||
docValue, _ := docRow.GetColVal(schema.DocTextTag)
|
||||
return []byte(docValue.(types.String)), nil
|
||||
} else {
|
||||
return nil, nil
|
||||
}
|
||||
} else {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
// getDocRow returns the associated row of a particular doc from the docTbl given.
|
||||
func getDocRow(ctx context.Context, docTbl *doltdb.Table, sch schema.Schema, key types.Tuple) (r row.Row, ok bool, err error) {
|
||||
rowMap, err := docTbl.GetNomsRowData(ctx)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
var fields types.Value
|
||||
fields, ok, err = rowMap.MaybeGet(ctx, key)
|
||||
if err != nil || !ok {
|
||||
return nil, ok, err
|
||||
}
|
||||
|
||||
r, err = row.FromNoms(sch, key, fields.(types.Tuple))
|
||||
return r, ok, err
|
||||
}
|
||||
|
||||
// getDocTextFromRow updates return the text field of a provided row.
|
||||
func getDocTextFromRow(r row.Row) ([]byte, error) {
|
||||
docValue, ok := r.GetColVal(schema.DocTextTag)
|
||||
if !ok {
|
||||
return nil, nil
|
||||
} else {
|
||||
docValStr, err := strconv.Unquote(docValue.HumanReadableString())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []byte(docValStr), nil
|
||||
}
|
||||
}
|
||||
|
||||
// getDocPKFromRow updates returns the docPk field of a given row.
|
||||
func getDocPKFromRow(r row.Row) (string, error) {
|
||||
colVal, _ := r.GetColVal(schema.DocNameTag)
|
||||
if colVal == nil {
|
||||
return "", nil
|
||||
} else {
|
||||
docName, err := strconv.Unquote(colVal.HumanReadableString())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return docName, nil
|
||||
}
|
||||
}
|
||||
|
||||
// GetAllDocs takes a root value and returns all the docs available in the root.
|
||||
func GetAllDocs(ctx context.Context, root *doltdb.RootValue) (Docs, bool, error) {
|
||||
if root == nil {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
docsTbl, found, err := root.GetTable(ctx, doltdb.DocTableName)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
if !found {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
docs, err := getDocsFromTable(ctx, docsTbl)
|
||||
return docs, true, err
|
||||
}
|
||||
|
||||
// getDocsFromTable takes the doltdocs table and a schema and return all docs in the dolt_docs table.
|
||||
func getDocsFromTable(ctx context.Context, table *doltdb.Table) (Docs, error) {
|
||||
ret := make(Docs, 0)
|
||||
|
||||
sch, err := table.GetSchema(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rows, err := table.GetNomsRowData(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = rows.IterAll(ctx, func(key, val types.Value) error {
|
||||
newRow, err := row.FromNoms(sch, key.(types.Tuple), val.(types.Tuple))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cols := sch.GetAllCols().GetColumns()
|
||||
colVals := make([]types.Value, len(cols))
|
||||
for i, col := range cols {
|
||||
colval, ok := newRow.GetColVal(col.Tag)
|
||||
if !ok {
|
||||
return errors.New("error: could not get doc column value")
|
||||
}
|
||||
colVals[i] = colval
|
||||
}
|
||||
|
||||
if len(colVals) < 2 {
|
||||
return errors.New("error: not enough values read from the table")
|
||||
}
|
||||
|
||||
doc := Doc{}
|
||||
doc.DocPk = string(colVals[0].(types.String))
|
||||
doc.Text = []byte(colVals[1].(types.String))
|
||||
ret = append(ret, doc)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return ret, err
|
||||
}
|
||||
@@ -1,194 +0,0 @@
|
||||
// Copyright 2020 Dolthub, Inc.
|
||||
//
|
||||
// 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 doltdocs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
filesys2 "github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
const defaultBranch = "main"
|
||||
|
||||
func TestAddNewerTextAndValueFromTable(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ddb, _ := doltdb.LoadDoltDB(ctx, types.Format_Default, doltdb.InMemDoltDB, filesys2.LocalFS)
|
||||
ddb.WriteEmptyRepo(ctx, defaultBranch, "billy bob", "bigbillieb@fake.horse")
|
||||
|
||||
// If no tbl/schema is provided, doc Text and Value should be nil.
|
||||
doc1 := Doc{DocPk: LicenseDoc}
|
||||
doc1Text, err := getDocTextFromTbl(ctx, nil, nil, doc1.DocPk)
|
||||
require.NoError(t, err)
|
||||
doc1.Text = doc1Text
|
||||
assert.Nil(t, doc1.Text)
|
||||
|
||||
// Create table with no rows
|
||||
sch := createTestDocsSchema()
|
||||
rows := []row.Row{}
|
||||
m, _ := createTestRows(t, ddb.ValueReadWriter(), sch, rows)
|
||||
tbl, err := CreateTestTable(ddb.ValueReadWriter(), sch, m)
|
||||
require.NoError(t, err)
|
||||
|
||||
// If a table doesn't have doc row, doc Text and Value should remain nil
|
||||
doc2 := Doc{DocPk: LicenseDoc}
|
||||
doc2Text, err := getDocTextFromTbl(ctx, tbl, &sch, doc2.DocPk)
|
||||
require.NoError(t, err)
|
||||
doc2.Text = doc2Text
|
||||
assert.Nil(t, doc2.Text)
|
||||
|
||||
// If a table doesn't have doc row, and Text and Value are originally non-nil, they should be updated to nil.
|
||||
doc3 := Doc{DocPk: LicenseDoc, Text: []byte("Something in newer text field")}
|
||||
doc3Text, err := getDocTextFromTbl(ctx, tbl, &sch, doc3.DocPk)
|
||||
require.NoError(t, err)
|
||||
doc3.Text = doc3Text
|
||||
assert.Nil(t, doc3.Text)
|
||||
|
||||
// Update tbl to have 2 doc rows, readme and license
|
||||
rows = getDocRows(t, sch, types.String("text in doc_text"))
|
||||
m, _ = createTestRows(t, ddb.ValueReadWriter(), sch, rows)
|
||||
tbl, err = CreateTestTable(ddb.ValueReadWriter(), sch, m)
|
||||
require.NoError(t, err)
|
||||
|
||||
// If a table has a doc row, Text and Value and should be updated to the `doc_text` value in that row.
|
||||
doc4 := Doc{DocPk: LicenseDoc, Text: []byte("Something in newer text field")}
|
||||
doc4Text, err := getDocTextFromTbl(ctx, tbl, &sch, doc4.DocPk)
|
||||
require.NoError(t, err)
|
||||
doc4.Text = doc4Text
|
||||
assert.Equal(t, "text in doc_text", string(doc4.Text))
|
||||
|
||||
// If a table has a doc row, and Text and Value are originally non-nil, they should be updated to the `doc_text` value.
|
||||
doc5 := Doc{DocPk: LicenseDoc}
|
||||
doc5Text, err := getDocTextFromTbl(ctx, tbl, &sch, doc5.DocPk)
|
||||
require.NoError(t, err)
|
||||
doc5.Text = doc5Text
|
||||
assert.Equal(t, "text in doc_text", string(doc5.Text))
|
||||
}
|
||||
|
||||
func TestAddNewerTextAndDocPkFromRow(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ddb, _ := doltdb.LoadDoltDB(ctx, types.Format_Default, doltdb.InMemDoltDB, filesys2.LocalFS)
|
||||
ddb.WriteEmptyRepo(ctx, defaultBranch, "billy bob", "bigbillieb@fake.horse")
|
||||
|
||||
sch := createTestDocsSchema()
|
||||
|
||||
emptyRow, err := row.New(types.Format_Default, sch, row.TaggedValues{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Text and DocName should be nil from an empty row
|
||||
doc1 := Doc{}
|
||||
text, err := getDocTextFromRow(emptyRow)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, text)
|
||||
docPk, err := getDocPKFromRow(emptyRow)
|
||||
require.NoError(t, err)
|
||||
doc1.DocPk = docPk
|
||||
assert.Equal(t, "", doc1.DocPk)
|
||||
|
||||
licenseRow, err := row.New(types.Format_Default, sch, row.TaggedValues{
|
||||
schema.DocNameTag: types.String(LicenseDoc),
|
||||
schema.DocTextTag: types.String("license!"),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Text and DocName should be added to doc from row
|
||||
doc2 := Doc{}
|
||||
text, err = getDocTextFromRow(licenseRow)
|
||||
require.NoError(t, err)
|
||||
doc2.Text = text
|
||||
assert.Equal(t, "license!", string(doc2.Text))
|
||||
docPk, err = getDocPKFromRow(licenseRow)
|
||||
require.NoError(t, err)
|
||||
doc2.DocPk = docPk
|
||||
assert.Equal(t, LicenseDoc, doc2.DocPk)
|
||||
|
||||
// When Text and DocName are non-nil, they should be updated from the row provided.
|
||||
doc3 := Doc{DocPk: "invalid", Text: []byte("something")}
|
||||
text, err = getDocTextFromRow(licenseRow)
|
||||
require.NoError(t, err)
|
||||
doc3.Text = text
|
||||
assert.Equal(t, "license!", string(doc3.Text))
|
||||
docPk, err = getDocPKFromRow(licenseRow)
|
||||
require.NoError(t, err)
|
||||
doc3.DocPk = docPk
|
||||
assert.Equal(t, LicenseDoc, doc3.DocPk)
|
||||
}
|
||||
|
||||
func CreateTestTable(vrw types.ValueReadWriter, tSchema schema.Schema, rowData types.Map) (*doltdb.Table, error) {
|
||||
tbl, err := doltdb.NewNomsTable(context.Background(), vrw, tSchema, rowData, nil, nil)
|
||||
|
||||
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 getDocRows(t *testing.T, sch schema.Schema, rowVal types.Value) []row.Row {
|
||||
rows := make([]row.Row, 2)
|
||||
row1 := makeDocRow(t, sch, LicenseDoc, rowVal)
|
||||
rows[0] = row1
|
||||
row2 := makeDocRow(t, sch, ReadmeDoc, rowVal)
|
||||
rows[1] = row2
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
func makeDocRow(t *testing.T, sch schema.Schema, pk string, rowVal types.Value) row.Row {
|
||||
row, err := row.New(types.Format_Default, sch, row.TaggedValues{
|
||||
schema.DocNameTag: types.String(pk),
|
||||
schema.DocTextTag: rowVal,
|
||||
})
|
||||
require.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)
|
||||
require.NoError(t, err)
|
||||
ed := m.Edit()
|
||||
|
||||
for _, r := range rows {
|
||||
ed = ed.Set(r.NomsMapKey(sch), r.NomsMapValue(sch))
|
||||
}
|
||||
|
||||
m, err = ed.Map(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
return m, rows
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func (a StageAll) Exec(t *testing.T, dEnv *env.DoltEnv) error {
|
||||
roots, err := dEnv.Roots(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
roots, err = actions.StageAllTables(context.Background(), roots, dEnv.Docs)
|
||||
roots, err = actions.StageAllTables(context.Background(), roots)
|
||||
require.NoError(t, err)
|
||||
|
||||
return dEnv.UpdateRoots(context.Background(), roots)
|
||||
@@ -115,7 +115,7 @@ func (c CommitAll) Exec(t *testing.T, dEnv *env.DoltEnv) error {
|
||||
roots, err := dEnv.Roots(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
roots, err = actions.StageAllTables(context.Background(), roots, dEnv.Docs)
|
||||
roots, err = actions.StageAllTables(context.Background(), roots)
|
||||
require.NoError(t, err)
|
||||
|
||||
name, email, err := env.GetNameAndEmail(dEnv.Config)
|
||||
@@ -167,13 +167,7 @@ func (r ResetHard) Exec(t *testing.T, dEnv *env.DoltEnv) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = dEnv.UpdateStagedRoot(context.Background(), headRoot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = actions.SaveTrackedDocsFromWorking(context.Background(), dEnv)
|
||||
return err
|
||||
return dEnv.UpdateStagedRoot(context.Background(), headRoot)
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
@@ -298,10 +292,6 @@ func (m Merge) Exec(t *testing.T, dEnv *env.DoltEnv) error {
|
||||
|
||||
err = dEnv.UpdateWorkingSet(context.Background(), workingSet.WithWorkingRoot(rv))
|
||||
require.NoError(t, err)
|
||||
|
||||
err = actions.SaveTrackedDocsFromWorking(context.Background(), dEnv)
|
||||
assert.NoError(t, err)
|
||||
|
||||
} else {
|
||||
opts := editor.Options{Deaf: dEnv.DbEaFactory(), Tempdir: dEnv.TempTableFilesDir()}
|
||||
mergedRoot, tblToStats, err := merge.MergeCommits(context.Background(), cm1, cm2, opts)
|
||||
@@ -320,11 +310,6 @@ func (m Merge) Exec(t *testing.T, dEnv *env.DoltEnv) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = actions.SaveTrackedDocsFromWorking(context.Background(), dEnv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = dEnv.UpdateStagedRoot(context.Background(), mergedRoot)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -297,7 +297,7 @@ func (mr *MultiRepoTestSetup) StageAll(dbName string) {
|
||||
mr.Errhand(fmt.Sprintf("Failed to get roots: %s", dbName))
|
||||
}
|
||||
|
||||
roots, err = actions.StageAllTables(ctx, roots, dEnv.Docs)
|
||||
roots, err = actions.StageAllTables(ctx, roots)
|
||||
if err != nil {
|
||||
mr.Errhand(fmt.Sprintf("Failed to stage tables: %s", dbName))
|
||||
}
|
||||
|
||||
+2
-12
@@ -272,7 +272,7 @@ func UpdateRootsForBranch(ctx context.Context, roots doltdb.Roots, branchRoot *d
|
||||
return roots, nil
|
||||
}
|
||||
|
||||
func CheckoutBranchNoDocs(ctx context.Context, roots doltdb.Roots, branchRoot *doltdb.RootValue, rsw env.RepoStateWriter, branchRef ref.BranchRef, force bool) error {
|
||||
func checkoutBranchNoDocs(ctx context.Context, roots doltdb.Roots, branchRoot *doltdb.RootValue, rsw env.RepoStateWriter, branchRef ref.BranchRef, force bool) error {
|
||||
roots, err := UpdateRootsForBranch(ctx, roots, branchRoot, force)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -321,17 +321,7 @@ func CheckoutBranch(ctx context.Context, dEnv *env.DoltEnv, brName string, force
|
||||
return err
|
||||
}
|
||||
|
||||
unstagedDocs, err := GetUnstagedDocsFromRoots(ctx, dEnv, roots)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = CheckoutBranchNoDocs(ctx, roots, branchRoot, dEnv.RepoStateWriter(), branchRef, force)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return SaveDocsFromWorkingExcludingFSChanges(ctx, dEnv, unstagedDocs)
|
||||
return checkoutBranchNoDocs(ctx, roots, branchRoot, dEnv.RepoStateWriter(), branchRef, force)
|
||||
}
|
||||
|
||||
// BranchRoot returns the root value at the branch with the name given
|
||||
|
||||
+7
-42
@@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
)
|
||||
|
||||
@@ -28,27 +27,20 @@ func CheckoutAllTables(ctx context.Context, roots doltdb.Roots, dbData env.DbDat
|
||||
return err
|
||||
}
|
||||
|
||||
docs := doltdocs.SupportedDocs
|
||||
return checkoutTablesAndDocs(ctx, dbData, roots, tbls, docs)
|
||||
return checkoutTables(ctx, dbData, roots, tbls)
|
||||
}
|
||||
|
||||
// CheckoutTablesAndDocs takes in a set of tables and docs and checks them out to another branch.
|
||||
func CheckoutTablesAndDocs(ctx context.Context, roots doltdb.Roots, dbData env.DbData, tables []string, docs doltdocs.Docs) error {
|
||||
return checkoutTablesAndDocs(ctx, dbData, roots, tables, docs)
|
||||
// CheckoutTables takes in a set of tables and docs and checks them out to another branch.
|
||||
func CheckoutTables(ctx context.Context, roots doltdb.Roots, dbData env.DbData, tables []string) error {
|
||||
return checkoutTables(ctx, dbData, roots, tables)
|
||||
}
|
||||
|
||||
func checkoutTables(ctx context.Context, dbData env.DbData, roots doltdb.Roots, tbls []string) (doltdb.Roots, error) {
|
||||
func checkoutTables(ctx context.Context, dbData env.DbData, roots doltdb.Roots, tbls []string) error {
|
||||
roots, err := MoveTablesFromHeadToWorking(ctx, roots, tbls)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
return err
|
||||
}
|
||||
|
||||
err = dbData.Rsw.UpdateWorkingRoot(ctx, roots.Working)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
|
||||
return roots, nil
|
||||
return dbData.Rsw.UpdateWorkingRoot(ctx, roots.Working)
|
||||
}
|
||||
|
||||
// MoveTablesFromHeadToWorking replaces the tables named from the given head to the given working root, overwriting any
|
||||
@@ -102,30 +94,3 @@ func MoveTablesFromHeadToWorking(ctx context.Context, roots doltdb.Roots, tbls [
|
||||
|
||||
return roots, nil
|
||||
}
|
||||
|
||||
func checkoutDocs(ctx context.Context, dbData env.DbData, roots doltdb.Roots, docs doltdocs.Docs) error {
|
||||
if len(docs) > 0 {
|
||||
var err error
|
||||
roots, docs, err = getUpdatedWorkingAndStagedWithDocs(ctx, roots, docs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err := dbData.Rsw.UpdateWorkingRoot(ctx, roots.Working)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return dbData.Drw.WriteDocsToDisk(docs)
|
||||
}
|
||||
|
||||
func checkoutTablesAndDocs(ctx context.Context, dbData env.DbData, roots doltdb.Roots, tbls []string, docs doltdocs.Docs) error {
|
||||
var err error
|
||||
roots, err = checkoutTables(ctx, dbData, roots, tbls)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return checkoutDocs(ctx, dbData, roots, docs)
|
||||
}
|
||||
|
||||
+1
-12
@@ -194,15 +194,11 @@ func CloneRemote(ctx context.Context, srcDB *doltdb.DoltDB, remoteName, branch s
|
||||
|
||||
// If we couldn't find a branch but the repo cloned successfully, it's empty. Initialize it instead of pulling from
|
||||
// the remote.
|
||||
performPull := true
|
||||
if branch == "" {
|
||||
err = InitEmptyClonedRepo(ctx, dEnv)
|
||||
if err != nil {
|
||||
if err = InitEmptyClonedRepo(ctx, dEnv); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
branch = env.GetDefaultInitBranch(dEnv.Config)
|
||||
performPull = false
|
||||
}
|
||||
|
||||
cs, _ := doltdb.NewCommitSpec(branch)
|
||||
@@ -246,13 +242,6 @@ func CloneRemote(ctx context.Context, srcDB *doltdb.DoltDB, remoteName, branch s
|
||||
}
|
||||
}
|
||||
|
||||
if performPull {
|
||||
err = SaveDocsFromRoot(ctx, rootVal, dEnv)
|
||||
if err != nil {
|
||||
return ErrFailedToUpdateDocs
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: make this interface take a DoltRef and marshal it automatically
|
||||
err = dEnv.RepoStateWriter().SetCWBHeadRef(ctx, ref.MarshalableRef{Ref: ref.NewBranchRef(branch)})
|
||||
if err != nil {
|
||||
|
||||
+2
-23
@@ -38,7 +38,6 @@ func CommitStaged(ctx context.Context, roots doltdb.Roots, mergeActive bool, mer
|
||||
ddb := dbData.Ddb
|
||||
rsr := dbData.Rsr
|
||||
rsw := dbData.Rsw
|
||||
drw := dbData.Drw
|
||||
|
||||
if props.Message == "" {
|
||||
return nil, datas.ErrEmptyCommitMessage
|
||||
@@ -59,16 +58,7 @@ func CommitStaged(ctx context.Context, roots doltdb.Roots, mergeActive bool, mer
|
||||
}
|
||||
|
||||
if len(staged) == 0 && !mergeActive && !props.AllowEmpty {
|
||||
docsOnDisk, err := drw.GetDocsOnDisk()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, notStagedDocs, err := diff.GetDocDiffs(ctx, roots, docsOnDisk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, NothingStaged{notStaged, notStagedDocs}
|
||||
return nil, NothingStaged{notStaged}
|
||||
}
|
||||
|
||||
if !props.Force {
|
||||
@@ -152,7 +142,6 @@ func GetCommitStaged(
|
||||
) (*doltdb.PendingCommit, error) {
|
||||
ddb := dbData.Ddb
|
||||
rsr := dbData.Rsr
|
||||
drw := dbData.Drw
|
||||
|
||||
if props.Message == "" {
|
||||
return nil, datas.ErrEmptyCommitMessage
|
||||
@@ -172,18 +161,8 @@ func GetCommitStaged(
|
||||
stagedTblNames = append(stagedTblNames, n)
|
||||
}
|
||||
|
||||
// TODO: kill off drw here, return an appropriate error type and make clients build this error as appropriate
|
||||
if len(staged) == 0 && !mergeActive && !props.AllowEmpty {
|
||||
docsOnDisk, err := drw.GetDocsOnDisk()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, notStagedDocs, err := diff.GetDocDiffs(ctx, roots, docsOnDisk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, NothingStaged{notStaged, notStagedDocs}
|
||||
return nil, NothingStaged{notStaged}
|
||||
}
|
||||
|
||||
if !props.Force {
|
||||
|
||||
-225
@@ -1,225 +0,0 @@
|
||||
// Copyright 2020 Dolthub, Inc.
|
||||
//
|
||||
// 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 actions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/diff"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
)
|
||||
|
||||
// SaveTrackedDocsFromWorking saves docs from the working root to the filesystem, and doesn't modify untracked docs.
|
||||
func SaveTrackedDocsFromWorking(ctx context.Context, dEnv *env.DoltEnv) error {
|
||||
localDocs := dEnv.Docs
|
||||
workingRoot, err := dEnv.WorkingRoot(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return SaveTrackedDocs(ctx, dEnv.DocsReadWriter(), workingRoot, workingRoot, localDocs)
|
||||
}
|
||||
|
||||
// SaveDocsFromRoot saves docs from the root given to the filesystem, and could overwrite untracked docs.
|
||||
func SaveDocsFromRoot(ctx context.Context, root *doltdb.RootValue, dEnv *env.DoltEnv) error {
|
||||
localDocs := dEnv.Docs
|
||||
drw := dEnv.DocsReadWriter()
|
||||
|
||||
docs, err := doltdocs.GetDocsFromRoot(ctx, root, doltdocs.GetDocNamesFromDocs(doltdocs.SupportedDocs)...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = drw.WriteDocsToDisk(docs)
|
||||
if err != nil {
|
||||
// If we can't update docs on disk, attempt to revert the change
|
||||
drw.WriteDocsToDisk(localDocs)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SaveTrackedDocs writes the docs from the targetRoot to the filesystem. The working root is used to identify untracked docs, which are left unchanged.
|
||||
func SaveTrackedDocs(ctx context.Context, drw env.DocsReadWriter, workRoot, targetRoot *doltdb.RootValue, localDocs doltdocs.Docs) error {
|
||||
docDiffs, err := diff.NewDocDiffs(ctx, workRoot, nil, localDocs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
docs := removeUntrackedDocs(localDocs, docDiffs)
|
||||
|
||||
docs, err = doltdocs.GetDocsFromRoot(ctx, targetRoot, doltdocs.GetDocNamesFromDocs(docs)...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = drw.WriteDocsToDisk(docs)
|
||||
|
||||
if err != nil {
|
||||
// If we can't update docs on disk, attempt to revert the change
|
||||
_ = drw.WriteDocsToDisk(localDocs)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func docIsUntracked(doc string, untracked []string) bool {
|
||||
for _, val := range untracked {
|
||||
if doc == val {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func removeUntrackedDocs(docs doltdocs.Docs, docDiffs *diff.DocDiffs) doltdocs.Docs {
|
||||
result := doltdocs.Docs{}
|
||||
untracked := getUntrackedDocs(docs, docDiffs)
|
||||
|
||||
for _, doc := range docs {
|
||||
if !docIsUntracked(doc.DocPk, untracked) {
|
||||
result = append(result, doc)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func getUntrackedDocs(docs doltdocs.Docs, docDiffs *diff.DocDiffs) []string {
|
||||
untracked := []string{}
|
||||
for _, docName := range docDiffs.Docs {
|
||||
dt := docDiffs.DocToType[docName]
|
||||
if dt == diff.AddedDoc {
|
||||
untracked = append(untracked, docName)
|
||||
}
|
||||
}
|
||||
|
||||
return untracked
|
||||
}
|
||||
|
||||
func getUpdatedWorkingAndStagedWithDocs(ctx context.Context, roots doltdb.Roots, docs doltdocs.Docs) (doltdb.Roots, doltdocs.Docs, error) {
|
||||
docsRoot := roots.Head
|
||||
_, ok, err := roots.Staged.GetTable(ctx, doltdb.DocTableName)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, nil, err
|
||||
} else if ok {
|
||||
docsRoot = roots.Staged
|
||||
}
|
||||
|
||||
docs, err = doltdocs.GetDocsFromRoot(ctx, docsRoot, doltdocs.GetDocNamesFromDocs(docs)...)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, nil, err
|
||||
}
|
||||
|
||||
roots.Working, err = doltdocs.UpdateRootWithDocs(ctx, roots.Working, docs)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, nil, err
|
||||
}
|
||||
|
||||
roots.Staged, err = doltdocs.UpdateRootWithDocs(ctx, roots.Staged, docs)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, nil, err
|
||||
}
|
||||
|
||||
return roots, docs, nil
|
||||
}
|
||||
|
||||
// GetUnstagedDocs retrieves the unstaged docs (docs from the filesystem).
|
||||
func GetUnstagedDocs(ctx context.Context, dEnv *env.DoltEnv) (doltdocs.Docs, error) {
|
||||
roots, err := dEnv.Roots(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return GetUnstagedDocsFromRoots(ctx, dEnv, roots)
|
||||
}
|
||||
|
||||
func GetUnstagedDocsFromRoots(ctx context.Context, dEnv *env.DoltEnv, roots doltdb.Roots) (doltdocs.Docs, error) {
|
||||
docsOnDisk, err := dEnv.DocsReadWriter().GetDocsOnDisk()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, unstagedDocDiffs, err := diff.GetDocDiffs(ctx, roots, docsOnDisk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
unstagedDocs := doltdocs.Docs{}
|
||||
for _, docName := range unstagedDocDiffs.Docs {
|
||||
docAr, err := dEnv.DocsReadWriter().GetDocsOnDisk(docName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(docAr) < 1 {
|
||||
return nil, errors.New("error: Failed getting unstaged docs")
|
||||
}
|
||||
|
||||
unstagedDocs = append(unstagedDocs, docAr[0])
|
||||
}
|
||||
return unstagedDocs, nil
|
||||
}
|
||||
|
||||
// SaveDocsFromWorkingExcludingFSChanges saves docs from the working root to the filesystem, and does not overwrite changes to docs on the FS.
|
||||
// Intended to be called after checking that no conflicts exist (during a checkout or merge, i.e.).
|
||||
func SaveDocsFromWorkingExcludingFSChanges(ctx context.Context, dEnv *env.DoltEnv, docsToExclude doltdocs.Docs) error {
|
||||
workingRoot, err := dEnv.WorkingRoot(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var docsToSave doltdocs.Docs
|
||||
if len(docsToExclude) > 0 {
|
||||
for _, doc := range dEnv.Docs {
|
||||
for _, excludedDoc := range docsToExclude {
|
||||
if doc.DocPk != excludedDoc.DocPk {
|
||||
docsToSave = append(docsToSave, doc)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
docsToSave = dEnv.Docs
|
||||
}
|
||||
|
||||
return SaveTrackedDocs(ctx, dEnv.DocsReadWriter(), workingRoot, workingRoot, docsToSave)
|
||||
}
|
||||
|
||||
// GetTablesOrDocs takes a slice of table or file names. Table names are returned as given. Supported doc names are
|
||||
// read from disk and their name replace with the names of the dolt_docs system table in the input slice. Supported docs
|
||||
// are returned in the second return param.
|
||||
func GetTablesOrDocs(drw env.DocsReadWriter, tablesOrFiles []string) (tables []string, docs doltdocs.Docs, err error) {
|
||||
for i, tbl := range tablesOrFiles {
|
||||
if _, ok := doltdocs.IsSupportedDoc(tbl); ok {
|
||||
docAr, err := drw.GetDocsOnDisk(tbl)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if len(docAr) < 1 {
|
||||
return nil, nil, errors.New("error: Failed getting docs")
|
||||
}
|
||||
|
||||
doc := docAr[0]
|
||||
if doc.DocPk == "" {
|
||||
return nil, nil, errors.New("Supported doc not found on disk.")
|
||||
}
|
||||
docs = append(docs, doc)
|
||||
tablesOrFiles[i] = doltdb.DocTableName
|
||||
}
|
||||
}
|
||||
return tablesOrFiles, docs, nil
|
||||
}
|
||||
-11
@@ -111,7 +111,6 @@ func CheckoutWouldOverwriteTables(err error) []string {
|
||||
|
||||
type NothingStaged struct {
|
||||
NotStagedTbls []diff.TableDelta
|
||||
NotStagedDocs *diff.DocDiffs
|
||||
}
|
||||
|
||||
func (ns NothingStaged) Error() string {
|
||||
@@ -132,13 +131,3 @@ func NothingStagedTblDiffs(err error) []diff.TableDelta {
|
||||
|
||||
return ns.NotStagedTbls
|
||||
}
|
||||
|
||||
func NothingStagedDocsDiffs(err error) *diff.DocDiffs {
|
||||
ns, ok := err.(NothingStaged)
|
||||
|
||||
if !ok {
|
||||
panic("Must validate with IsCheckoutWouldOverwrite before calling CheckoutWouldOverwriteTables")
|
||||
}
|
||||
|
||||
return ns.NotStagedDocs
|
||||
}
|
||||
|
||||
+1
-49
@@ -20,7 +20,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"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/utils/argparser"
|
||||
)
|
||||
@@ -116,11 +115,6 @@ func ResetHard(ctx context.Context, dEnv *env.DoltEnv, cSpecStr string, roots do
|
||||
return err
|
||||
}
|
||||
|
||||
err = SaveTrackedDocsFromWorking(ctx, dEnv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if newHead != nil {
|
||||
err = dEnv.DoltDB.SetHeadToCommit(ctx, dEnv.RepoStateReader().CWBHeadRef(), newHead)
|
||||
if err != nil {
|
||||
@@ -154,37 +148,15 @@ func ResetSoftTables(ctx context.Context, dbData env.DbData, apr *argparser.ArgP
|
||||
// ResetSoft resets the staged value from HEAD for the tables given and returns the updated roots.
|
||||
func ResetSoft(ctx context.Context, dbData env.DbData, tables []string, roots doltdb.Roots) (doltdb.Roots, error) {
|
||||
tables, err := getUnionedTables(ctx, tables, roots.Staged, roots.Head)
|
||||
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
|
||||
tables, docs, err := GetTablesOrDocs(dbData.Drw, tables)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
|
||||
if len(docs) > 0 {
|
||||
tables = RemoveDocsTable(tables)
|
||||
}
|
||||
|
||||
err = ValidateTables(context.TODO(), tables, roots.Staged, roots.Head)
|
||||
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
|
||||
roots, err = resetDocs(ctx, roots, docs)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
|
||||
roots, err = resetStaged(ctx, roots, tables)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
|
||||
return roots, nil
|
||||
return resetStaged(ctx, roots, tables)
|
||||
}
|
||||
|
||||
// ResetSoftToRef matches the `git reset --soft <REF>` pattern. It resets both staged and head to the previous ref
|
||||
@@ -232,26 +204,6 @@ func getUnionedTables(ctx context.Context, tables []string, stagedRoot, headRoot
|
||||
return tables, nil
|
||||
}
|
||||
|
||||
// resetDocs resets the working and staged docs with docs from head.
|
||||
func resetDocs(ctx context.Context, roots doltdb.Roots, docs doltdocs.Docs) (doltdb.Roots, error) {
|
||||
docs, err := doltdocs.GetDocsFromRoot(ctx, roots.Head, doltdocs.GetDocNamesFromDocs(docs)...)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
|
||||
roots.Working, err = doltdocs.UpdateRootWithDocs(ctx, roots.Working, docs)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
|
||||
roots.Staged, err = doltdocs.UpdateRootWithDocs(ctx, roots.Staged, docs)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
|
||||
return roots, nil
|
||||
}
|
||||
|
||||
func resetStaged(ctx context.Context, roots doltdb.Roots, tbls []string) (doltdb.Roots, error) {
|
||||
newStaged, err := MoveTablesBetweenRoots(ctx, tbls, roots.Head, roots.Staged)
|
||||
if err != nil {
|
||||
|
||||
+2
-34
@@ -18,45 +18,13 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
|
||||
)
|
||||
|
||||
func StageTables(ctx context.Context, roots doltdb.Roots, docs doltdocs.Docs, tbls []string) (doltdb.Roots, error) {
|
||||
if len(docs) > 0 {
|
||||
var err error
|
||||
roots.Working, err = doltdocs.UpdateRootWithDocs(ctx, roots.Working, docs)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
}
|
||||
|
||||
func StageTables(ctx context.Context, roots doltdb.Roots, tbls []string) (doltdb.Roots, error) {
|
||||
return stageTables(ctx, roots, tbls)
|
||||
}
|
||||
|
||||
func StageTablesNoDocs(ctx context.Context, roots doltdb.Roots, tbls []string) (doltdb.Roots, error) {
|
||||
return stageTables(ctx, roots, tbls)
|
||||
}
|
||||
|
||||
func StageAllTables(ctx context.Context, roots doltdb.Roots, docs doltdocs.Docs) (doltdb.Roots, error) {
|
||||
var err error
|
||||
|
||||
// To stage all docs for removal, use an empty slice instead of nil
|
||||
if docs != nil {
|
||||
roots.Working, err = doltdocs.UpdateRootWithDocs(ctx, roots.Working, docs)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
}
|
||||
|
||||
tbls, err := doltdb.UnionTableNames(ctx, roots.Staged, roots.Working)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
|
||||
return stageTables(ctx, roots, tbls)
|
||||
}
|
||||
|
||||
func StageAllTablesNoDocs(ctx context.Context, roots doltdb.Roots) (doltdb.Roots, error) {
|
||||
func StageAllTables(ctx context.Context, roots doltdb.Roots) (doltdb.Roots, error) {
|
||||
tbls, err := doltdb.UnionTableNames(ctx, roots.Staged, roots.Working)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
|
||||
-40
@@ -32,7 +32,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/creds"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dbfactory"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/grpcendpoint"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor"
|
||||
@@ -89,9 +88,6 @@ type DoltEnv struct {
|
||||
RepoState *RepoState
|
||||
RSLoadErr error
|
||||
|
||||
Docs doltdocs.Docs
|
||||
DocsLoadErr error
|
||||
|
||||
DoltDB *doltdb.DoltDB
|
||||
DBLoadError error
|
||||
|
||||
@@ -105,7 +101,6 @@ func Load(ctx context.Context, hdp HomeDirProvider, fs filesys.Filesys, urlStr,
|
||||
config, cfgErr := LoadDoltCliConfig(hdp, fs)
|
||||
repoState, rsErr := LoadRepoState(fs)
|
||||
|
||||
docs, docsErr := doltdocs.LoadDocs(fs)
|
||||
ddb, dbLoadErr := doltdb.LoadDoltDB(ctx, types.Format_Default, urlStr, fs)
|
||||
|
||||
dEnv := &DoltEnv{
|
||||
@@ -114,8 +109,6 @@ func Load(ctx context.Context, hdp HomeDirProvider, fs filesys.Filesys, urlStr,
|
||||
CfgLoadErr: cfgErr,
|
||||
RepoState: repoState,
|
||||
RSLoadErr: rsErr,
|
||||
Docs: docs,
|
||||
DocsLoadErr: docsErr,
|
||||
DoltDB: ddb,
|
||||
DBLoadError: dbLoadErr,
|
||||
FS: fs,
|
||||
@@ -666,38 +659,6 @@ func (dEnv *DoltEnv) RepoStateWriter() RepoStateWriter {
|
||||
return &repoStateWriter{dEnv}
|
||||
}
|
||||
|
||||
type docsReadWriter struct {
|
||||
FS filesys.Filesys
|
||||
}
|
||||
|
||||
// GetDocsOnDisk reads the filesystem and returns all docs.
|
||||
func (d *docsReadWriter) GetDocsOnDisk(docNames ...string) (doltdocs.Docs, error) {
|
||||
if docNames != nil {
|
||||
ret := make(doltdocs.Docs, len(docNames))
|
||||
|
||||
for i, name := range docNames {
|
||||
doc, err := doltdocs.GetDoc(d.FS, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret[i] = doc
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
return doltdocs.GetSupportedDocs(d.FS)
|
||||
}
|
||||
|
||||
// WriteDocsToDisk creates or updates the dolt_docs table with docs.
|
||||
func (d *docsReadWriter) WriteDocsToDisk(docs doltdocs.Docs) error {
|
||||
return docs.Save(d.FS)
|
||||
}
|
||||
|
||||
func (dEnv *DoltEnv) DocsReadWriter() DocsReadWriter {
|
||||
return &docsReadWriter{dEnv.FS}
|
||||
}
|
||||
|
||||
func (dEnv *DoltEnv) HeadRoot(ctx context.Context) (*doltdb.RootValue, error) {
|
||||
commit, err := dEnv.HeadCommit(ctx)
|
||||
if err != nil {
|
||||
@@ -716,7 +677,6 @@ func (dEnv *DoltEnv) DbData() DbData {
|
||||
Ddb: dEnv.DoltDB,
|
||||
Rsw: dEnv.RepoStateWriter(),
|
||||
Rsr: dEnv.RepoStateReader(),
|
||||
Drw: dEnv.DocsReadWriter(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-17
@@ -19,7 +19,6 @@ import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -27,7 +26,6 @@ import (
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dbfactory"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
@@ -103,10 +101,6 @@ func TestNonRepoDir(t *testing.T) {
|
||||
if dEnv.RSLoadErr == nil {
|
||||
t.Error("File doesn't exist. There should be an error if the directory doesn't exist.")
|
||||
}
|
||||
|
||||
if dEnv.DocsLoadErr != nil {
|
||||
t.Error("There shouldn't be an error if the directory doesn't exist.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoDir(t *testing.T) {
|
||||
@@ -119,7 +113,6 @@ func TestRepoDir(t *testing.T) {
|
||||
assert.Equal(t, "bheni", userName)
|
||||
|
||||
assert.NoError(t, dEnv.CfgLoadErr)
|
||||
assert.NoError(t, dEnv.DocsLoadErr)
|
||||
// RSLoadErr will be set because the above method of creating the repo doesn't initialize a valid working or staged
|
||||
}
|
||||
|
||||
@@ -133,7 +126,6 @@ func TestRepoDirNoLocal(t *testing.T) {
|
||||
}
|
||||
|
||||
require.NoError(t, dEnv.CfgLoadErr)
|
||||
require.NoError(t, dEnv.DocsLoadErr)
|
||||
// RSLoadErr will be set because the above method of creating the repo doesn't initialize a valid working or staged
|
||||
|
||||
err := dEnv.Config.CreateLocalConfig(map[string]string{"user.name": "bheni"})
|
||||
@@ -158,13 +150,6 @@ func TestInitRepo(t *testing.T) {
|
||||
|
||||
_, err = dEnv.StagedRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, doc := range doltdocs.SupportedDocs {
|
||||
docPath := doltdocs.GetDocFilePath(doc.File)
|
||||
if len(docPath) > 0 && !strings.Contains(doc.File, docPath) {
|
||||
t.Error("Doc file path should exist: ", doc.File)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestMigrateWorkingSet tests migrating a repo with the old RepoState fields to a new one
|
||||
@@ -172,7 +157,6 @@ func TestMigrateWorkingSet(t *testing.T) {
|
||||
t.Skip("This fails under race on ubuntu / mac")
|
||||
|
||||
// TODO: t.TempDir breaks on windows because of automatic cleanup (files still in use)
|
||||
// dir := t.TempDir()
|
||||
working, err := os.MkdirTemp("", "TestMigrateWorkingSet*")
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -229,7 +213,6 @@ func TestMigrateWorkingSet(t *testing.T) {
|
||||
dEnv = Load(context.Background(), testHomeDirFunc, dEnv.FS, doltdb.LocalDirDoltDB, "test")
|
||||
assert.NoError(t, dEnv.RSLoadErr)
|
||||
assert.NoError(t, dEnv.CfgLoadErr)
|
||||
assert.NoError(t, dEnv.DocsLoadErr)
|
||||
|
||||
ws, err = dEnv.WorkingSet(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
Vendored
-11
@@ -21,7 +21,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/config"
|
||||
"github.com/dolthub/dolt/go/store/chunks"
|
||||
@@ -46,7 +45,6 @@ func NewMemoryDbData(ctx context.Context, cfg config.ReadableConfig) (DbData, er
|
||||
Ddb: ddb,
|
||||
Rsw: rs,
|
||||
Rsr: rs,
|
||||
Drw: rs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -102,7 +100,6 @@ type MemoryRepoState struct {
|
||||
|
||||
var _ RepoStateReader = MemoryRepoState{}
|
||||
var _ RepoStateWriter = MemoryRepoState{}
|
||||
var _ DocsReadWriter = MemoryRepoState{}
|
||||
|
||||
func (m MemoryRepoState) CWBHeadRef() ref.DoltRef {
|
||||
return m.Head
|
||||
@@ -218,14 +215,6 @@ func (m MemoryRepoState) TempTableFilesDir() string {
|
||||
return os.TempDir()
|
||||
}
|
||||
|
||||
func (m MemoryRepoState) GetDocsOnDisk(docNames ...string) (doltdocs.Docs, error) {
|
||||
return nil, fmt.Errorf("cannot get docs from a memory database")
|
||||
}
|
||||
|
||||
func (m MemoryRepoState) WriteDocsToDisk(docs doltdocs.Docs) error {
|
||||
return fmt.Errorf("cannot write docs to a memory database")
|
||||
}
|
||||
|
||||
func (m MemoryRepoState) GetBackups() (map[string]Remote, error) {
|
||||
panic("cannot get backups on in memory database")
|
||||
}
|
||||
|
||||
-9
@@ -19,7 +19,6 @@ import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
@@ -47,18 +46,10 @@ type RepoStateWriter interface {
|
||||
UpdateBranch(name string, new BranchConfig) error
|
||||
}
|
||||
|
||||
type DocsReadWriter interface {
|
||||
// GetDocsOnDisk returns the docs in the filesytem optionally filtered by docNames.
|
||||
GetDocsOnDisk(docNames ...string) (doltdocs.Docs, error)
|
||||
// WriteDocsToDisk updates the documents stored in the filesystem with the contents in docs.
|
||||
WriteDocsToDisk(docs doltdocs.Docs) error
|
||||
}
|
||||
|
||||
type DbData struct {
|
||||
Ddb *doltdb.DoltDB
|
||||
Rsw RepoStateWriter
|
||||
Rsr RepoStateReader
|
||||
Drw DocsReadWriter
|
||||
}
|
||||
|
||||
type BranchConfig struct {
|
||||
|
||||
@@ -204,11 +204,6 @@ func ExecuteFFMerge(
|
||||
}
|
||||
}
|
||||
|
||||
unstagedDocs, err := actions.GetUnstagedDocs(ctx, dEnv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !spec.Squash {
|
||||
err = dEnv.DoltDB.FastForward(ctx, dEnv.RepoStateReader().CWBHeadRef(), spec.MergeC)
|
||||
|
||||
@@ -222,17 +217,7 @@ func ExecuteFFMerge(
|
||||
return err
|
||||
}
|
||||
|
||||
err = dEnv.UpdateWorkingSet(ctx, workingSet.WithWorkingRoot(workingRoot).WithStagedRoot(stagedRoot))
|
||||
if err != nil {
|
||||
return ErrMergeFailedToUpdateRepoState
|
||||
}
|
||||
|
||||
err = actions.SaveDocsFromWorkingExcludingFSChanges(ctx, dEnv, unstagedDocs)
|
||||
if err != nil {
|
||||
return ErrMergeFailedToUpdateDocs
|
||||
}
|
||||
|
||||
return nil
|
||||
return dEnv.UpdateWorkingSet(ctx, workingSet.WithWorkingRoot(workingRoot).WithStagedRoot(stagedRoot))
|
||||
}
|
||||
|
||||
func ExecuteMerge(ctx context.Context, dEnv *env.DoltEnv, spec *MergeSpec) (map[string]*MergeStats, error) {
|
||||
@@ -280,11 +265,6 @@ func mergedRootToWorking(
|
||||
}
|
||||
}
|
||||
|
||||
unstagedDocs, err := actions.GetUnstagedDocs(ctx, dEnv)
|
||||
if err != nil {
|
||||
return ErrFailedToDetermineUnstagedDocs
|
||||
}
|
||||
|
||||
err = dEnv.UpdateWorkingRoot(context.Background(), workingRoot)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -295,15 +275,7 @@ func mergedRootToWorking(
|
||||
return err
|
||||
}
|
||||
|
||||
if err = actions.SaveDocsFromWorkingExcludingFSChanges(ctx, dEnv, unstagedDocs); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = dEnv.UpdateStagedRoot(context.Background(), mergedRoot); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return dEnv.UpdateStagedRoot(context.Background(), mergedRoot)
|
||||
}
|
||||
|
||||
func conflictsAndViolations(tblToStats map[string]*MergeStats) (conflicts []string, constraintViolations []string) {
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/diff"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb/durable"
|
||||
"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/table/editor"
|
||||
@@ -1232,10 +1231,6 @@ func GetTablesWithConstraintViolations(ctx context.Context, roots doltdb.Roots)
|
||||
return workingViolations, stagedViolations, headViolations, err
|
||||
}
|
||||
|
||||
func GetDocsInConflict(ctx context.Context, workingRoot *doltdb.RootValue, docs doltdocs.Docs) (*diff.DocDiffs, error) {
|
||||
return diff.NewDocDiffs(ctx, workingRoot, nil, docs)
|
||||
}
|
||||
|
||||
func MergeWouldStompChanges(ctx context.Context, roots doltdb.Roots, mergeCommit *doltdb.Commit) ([]string, map[string]hash.Hash, error) {
|
||||
mergeRoot, err := mergeCommit.GetRootValue(ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"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/ref"
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
@@ -129,16 +128,12 @@ func rebaseRefs(ctx context.Context, dbData env.DbData, replay ReplayCommitFn, n
|
||||
ddb := dbData.Ddb
|
||||
rsr := dbData.Rsr
|
||||
rsw := dbData.Rsw
|
||||
drw := dbData.Drw
|
||||
|
||||
cwbRef := rsr.CWBHeadRef()
|
||||
dd, err := drw.GetDocsOnDisk()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
heads := make([]*doltdb.Commit, len(refs))
|
||||
for i, dRef := range refs {
|
||||
var err error
|
||||
heads[i], err = ddb.ResolveCommitRef(ctx, dRef)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -178,11 +173,6 @@ func rebaseRefs(ctx context.Context, dbData env.DbData, replay ReplayCommitFn, n
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = doltdocs.UpdateRootWithDocs(ctx, r, dd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: this should be a single update to repo state, not two
|
||||
err = rsw.UpdateStagedRoot(ctx, r)
|
||||
if err != nil {
|
||||
|
||||
@@ -86,7 +86,6 @@ type Database struct {
|
||||
ddb *doltdb.DoltDB
|
||||
rsr env.RepoStateReader
|
||||
rsw env.RepoStateWriter
|
||||
drw env.DocsReadWriter
|
||||
gs globalstate.GlobalState
|
||||
editOpts editor.Options
|
||||
}
|
||||
@@ -173,7 +172,6 @@ func NewDatabase(name string, dbData env.DbData, editOpts editor.Options) Databa
|
||||
ddb: dbData.Ddb,
|
||||
rsr: dbData.Rsr,
|
||||
rsw: dbData.Rsw,
|
||||
drw: dbData.Drw,
|
||||
gs: globalstate.NewGlobalStateStore(),
|
||||
editOpts: editOpts,
|
||||
}
|
||||
@@ -250,16 +248,11 @@ func (db Database) GetStateWriter() env.RepoStateWriter {
|
||||
return db.rsw
|
||||
}
|
||||
|
||||
func (db Database) GetDocsReadWriter() env.DocsReadWriter {
|
||||
return db.drw
|
||||
}
|
||||
|
||||
func (db Database) DbData() env.DbData {
|
||||
return env.DbData{
|
||||
Ddb: db.ddb,
|
||||
Rsw: db.rsw,
|
||||
Rsr: db.rsr,
|
||||
Drw: db.drw,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,7 +406,7 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ro
|
||||
map[string]env.Remote{},
|
||||
map[string]env.BranchConfig{},
|
||||
map[string]env.Remote{})
|
||||
dt, found = dtables.NewStatusTable(ctx, db.name, db.ddb, adapter, db.drw), true
|
||||
dt, found = dtables.NewStatusTable(ctx, db.name, db.ddb, adapter), true
|
||||
}
|
||||
if found {
|
||||
return dt, found, nil
|
||||
|
||||
@@ -454,7 +454,6 @@ func dbRevisionForBranch(ctx context.Context, srcDb SqlDatabase, revSpec string)
|
||||
branch: branch,
|
||||
RepoStateWriter: srcDb.DbData().Rsw,
|
||||
RepoStateReader: srcDb.DbData().Rsr,
|
||||
DocsReadWriter: srcDb.DbData().Drw,
|
||||
}
|
||||
|
||||
var db SqlDatabase
|
||||
@@ -466,7 +465,6 @@ func dbRevisionForBranch(ctx context.Context, srcDb SqlDatabase, revSpec string)
|
||||
ddb: v.ddb,
|
||||
rsw: static,
|
||||
rsr: static,
|
||||
drw: static,
|
||||
gs: v.gs,
|
||||
editOpts: v.editOpts,
|
||||
}
|
||||
@@ -477,7 +475,6 @@ func dbRevisionForBranch(ctx context.Context, srcDb SqlDatabase, revSpec string)
|
||||
ddb: v.ddb,
|
||||
rsw: static,
|
||||
rsr: static,
|
||||
drw: static,
|
||||
gs: v.gs,
|
||||
editOpts: v.editOpts,
|
||||
},
|
||||
@@ -495,7 +492,6 @@ func dbRevisionForBranch(ctx context.Context, srcDb SqlDatabase, revSpec string)
|
||||
Ddb: srcDb.DbData().Ddb,
|
||||
Rsw: static,
|
||||
Rsr: static,
|
||||
Drw: static,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -519,7 +515,6 @@ func dbRevisionForCommit(ctx context.Context, srcDb Database, revSpec string) (R
|
||||
ddb: srcDb.DbData().Ddb,
|
||||
rsw: srcDb.DbData().Rsw,
|
||||
rsr: srcDb.DbData().Rsr,
|
||||
drw: srcDb.DbData().Drw,
|
||||
editOpts: srcDb.editOpts,
|
||||
}}
|
||||
init := dsess.InitialDbState{
|
||||
@@ -530,7 +525,6 @@ func dbRevisionForCommit(ctx context.Context, srcDb Database, revSpec string) (R
|
||||
Ddb: srcDb.DbData().Ddb,
|
||||
Rsw: srcDb.DbData().Rsw,
|
||||
Rsr: srcDb.DbData().Rsr,
|
||||
Drw: srcDb.DbData().Drw,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -541,7 +535,6 @@ type staticRepoState struct {
|
||||
branch ref.DoltRef
|
||||
env.RepoStateWriter
|
||||
env.RepoStateReader
|
||||
env.DocsReadWriter
|
||||
}
|
||||
|
||||
func (s staticRepoState) CWBHeadRef() ref.DoltRef {
|
||||
|
||||
@@ -63,7 +63,7 @@ func DoDoltAdd(ctx *sql.Context, args []string) (int, error) {
|
||||
return 1, fmt.Errorf("db session not found")
|
||||
}
|
||||
|
||||
roots, err = actions.StageAllTablesNoDocs(ctx, roots)
|
||||
roots, err = actions.StageAllTables(ctx, roots)
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func DoDoltAdd(ctx *sql.Context, args []string) (int, error) {
|
||||
return 1, err
|
||||
}
|
||||
} else {
|
||||
roots, err = actions.StageTablesNoDocs(ctx, roots, apr.Args)
|
||||
roots, err = actions.StageTables(ctx, roots, apr.Args)
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ func DoDoltCommit(ctx *sql.Context, args []string) (string, error) {
|
||||
}
|
||||
|
||||
if apr.Contains(cli.AllFlag) {
|
||||
roots, err = actions.StageAllTablesNoDocs(ctx, roots)
|
||||
roots, err = actions.StageAllTables(ctx, roots)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf(err.Error())
|
||||
}
|
||||
|
||||
@@ -408,7 +408,7 @@ func (sess *Session) PendingCommitAllStaged(ctx *sql.Context, dbName string, pro
|
||||
}
|
||||
|
||||
var err error
|
||||
roots, err = actions.StageAllTablesNoDocs(ctx, roots)
|
||||
roots, err = actions.StageAllTables(ctx, roots)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import (
|
||||
type StatusTable struct {
|
||||
ddb *doltdb.DoltDB
|
||||
rootsProvider env.RootsProvider
|
||||
drw env.DocsReadWriter
|
||||
dbName string
|
||||
}
|
||||
|
||||
@@ -60,12 +59,11 @@ func (s StatusTable) PartitionRows(context *sql.Context, _ sql.Partition) (sql.R
|
||||
}
|
||||
|
||||
// NewStatusTable creates a StatusTable
|
||||
func NewStatusTable(_ *sql.Context, dbName string, ddb *doltdb.DoltDB, rp env.RootsProvider, drw env.DocsReadWriter) sql.Table {
|
||||
func NewStatusTable(_ *sql.Context, dbName string, ddb *doltdb.DoltDB, rp env.RootsProvider) sql.Table {
|
||||
return &StatusTable{
|
||||
ddb: ddb,
|
||||
dbName: dbName,
|
||||
rootsProvider: rp,
|
||||
drw: drw,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +77,6 @@ type StatusItr struct {
|
||||
|
||||
func newStatusItr(ctx *sql.Context, st *StatusTable) (*StatusItr, error) {
|
||||
rp := st.rootsProvider
|
||||
drw := st.drw
|
||||
|
||||
roots, err := rp.GetRoots(ctx)
|
||||
if err != nil {
|
||||
@@ -91,30 +88,12 @@ func newStatusItr(ctx *sql.Context, st *StatusTable) (*StatusItr, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
docsOnDisk, err := drw.GetDocsOnDisk()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
stagedDocDiffs, unStagedDocDiffs, err := diff.GetDocDiffs(ctx, roots, docsOnDisk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
workingTblsInConflict, _, _, err := merge.GetTablesInConflict(ctx, roots)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
docs, err := drw.GetDocsOnDisk()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
workingDocsInConflict, err := merge.GetDocsInConflict(ctx, roots.Working, docs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tLength := len(stagedTables) + len(unstagedTables) + len(stagedDocDiffs.Docs) + len(unStagedDocDiffs.Docs) + len(workingTblsInConflict) + len(workingDocsInConflict.Docs)
|
||||
tLength := len(stagedTables) + len(unstagedTables) + len(workingTblsInConflict)
|
||||
|
||||
tables := make([]string, tLength)
|
||||
isStaged := make([]bool, tLength)
|
||||
@@ -123,10 +102,7 @@ func newStatusItr(ctx *sql.Context, st *StatusTable) (*StatusItr, error) {
|
||||
itr := &StatusItr{tables: tables, isStaged: isStaged, statuses: statuses, idx: 0}
|
||||
|
||||
idx := handleStagedUnstagedTables(stagedTables, unstagedTables, itr, 0)
|
||||
idx = handleStagedUnstagedDocDiffs(stagedDocDiffs, unStagedDocDiffs, itr, idx)
|
||||
idx = handleWorkingTablesInConflict(workingTblsInConflict, itr, idx)
|
||||
idx = handleWorkingDocConflicts(workingDocsInConflict, itr, idx)
|
||||
|
||||
return itr, nil
|
||||
}
|
||||
|
||||
@@ -161,27 +137,6 @@ func handleStagedUnstagedTables(staged, unstaged []diff.TableDelta, itr *StatusI
|
||||
return idx
|
||||
}
|
||||
|
||||
var docDiffTypeToLabel = map[diff.DocDiffType]string{
|
||||
diff.ModifiedDoc: "modified",
|
||||
diff.RemovedDoc: "deleted",
|
||||
diff.AddedDoc: "new doc",
|
||||
}
|
||||
|
||||
func handleStagedUnstagedDocDiffs(staged *diff.DocDiffs, unstaged *diff.DocDiffs, itr *StatusItr, idx int) int {
|
||||
combined := append(staged.Docs, unstaged.Docs...)
|
||||
for i, docName := range combined {
|
||||
dType := staged.DocToType[docName]
|
||||
|
||||
itr.tables[idx] = docName
|
||||
itr.isStaged[idx] = i < len(staged.Docs)
|
||||
itr.statuses[idx] = docDiffTypeToLabel[dType]
|
||||
|
||||
idx += 1
|
||||
}
|
||||
|
||||
return idx
|
||||
}
|
||||
|
||||
const mergeConflictStatus = "conflict"
|
||||
|
||||
func handleWorkingTablesInConflict(workingTables []string, itr *StatusItr, idx int) int {
|
||||
@@ -196,18 +151,6 @@ func handleWorkingTablesInConflict(workingTables []string, itr *StatusItr, idx i
|
||||
return idx
|
||||
}
|
||||
|
||||
func handleWorkingDocConflicts(workingDocs *diff.DocDiffs, itr *StatusItr, idx int) int {
|
||||
for _, docName := range workingDocs.Docs {
|
||||
itr.tables[idx] = docName
|
||||
itr.isStaged[idx] = false
|
||||
itr.statuses[idx] = mergeConflictStatus
|
||||
|
||||
idx += 1
|
||||
}
|
||||
|
||||
return idx
|
||||
}
|
||||
|
||||
// Next retrieves the next row. It will return io.EOF if it's the last row.
|
||||
// After retrieving the last row, Close will be automatically closed.
|
||||
func (itr *StatusItr) Next(*sql.Context) (sql.Row, error) {
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
@@ -783,7 +782,7 @@ func TestAlterSystemTables(t *testing.T) {
|
||||
CreateTestDatabase(dEnv, t)
|
||||
|
||||
dtestutils.CreateTestTable(t, dEnv, "dolt_docs",
|
||||
doltdocs.DocsSchema,
|
||||
doltdb.DocsSchema,
|
||||
NewRow(types.String("LICENSE.md"), types.String("A license")))
|
||||
dtestutils.CreateTestTable(t, dEnv, doltdb.DoltQueryCatalogTableName,
|
||||
dtables.DoltQueryCatalogSchema,
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
|
||||
@@ -190,14 +189,6 @@ func TestExecuteDeleteSystemTables(t *testing.T) {
|
||||
}
|
||||
|
||||
var systemTableDeleteTests = []DeleteTest{
|
||||
{
|
||||
Name: "delete dolt_docs",
|
||||
AdditionalSetup: CreateTableFn("dolt_docs",
|
||||
doltdocs.DocsSchema,
|
||||
NewRow(types.String("LICENSE.md"), types.String("A license"))),
|
||||
DeleteQuery: "delete from dolt_docs",
|
||||
ExpectedErr: "cannot delete from table",
|
||||
},
|
||||
{
|
||||
Name: "delete dolt_query_catalog",
|
||||
AdditionalSetup: CreateTableFn(doltdb.DoltQueryCatalogTableName,
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
|
||||
@@ -377,14 +376,6 @@ func TestExecuteInsert(t *testing.T) {
|
||||
}
|
||||
|
||||
var systemTableInsertTests = []InsertTest{
|
||||
{
|
||||
Name: "insert into dolt_docs",
|
||||
AdditionalSetup: CreateTableFn("dolt_docs",
|
||||
doltdocs.DocsSchema,
|
||||
NewRow(types.String("LICENSE.md"), types.String("A license"))),
|
||||
InsertQuery: "insert into dolt_docs (doc_name, doc_text) values ('README.md', 'Some text')",
|
||||
ExpectedErr: "cannot insert into table",
|
||||
},
|
||||
{
|
||||
Name: "insert into dolt_query_catalog",
|
||||
AdditionalSetup: CreateTableFn(doltdb.DoltQueryCatalogTableName,
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
|
||||
@@ -252,14 +251,6 @@ func TestExecuteReplace(t *testing.T) {
|
||||
}
|
||||
|
||||
var systemTableReplaceTests = []ReplaceTest{
|
||||
{
|
||||
Name: "replace into dolt_docs",
|
||||
AdditionalSetup: CreateTableFn("dolt_docs",
|
||||
doltdocs.DocsSchema,
|
||||
NewRow(types.String("LICENSE.md"), types.String("A license"))),
|
||||
ReplaceQuery: "replace into dolt_docs (doc_name, doc_text) values ('README.md', 'Some text')",
|
||||
ExpectedErr: "cannot insert into table",
|
||||
},
|
||||
{
|
||||
Name: "replace into dolt_query_catalog",
|
||||
AdditionalSetup: CreateTableFn(doltdb.DoltQueryCatalogTableName,
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
@@ -1489,19 +1488,19 @@ func TestCaseSensitivity(t *testing.T) {
|
||||
}
|
||||
|
||||
var systemTableSelectTests = []SelectTest{
|
||||
{
|
||||
Name: "select from dolt_docs",
|
||||
AdditionalSetup: CreateTableFn("dolt_docs",
|
||||
doltdocs.DocsSchema,
|
||||
NewRowWithSchema(doltdocs.DocsSchema,
|
||||
types.String("LICENSE.md"),
|
||||
types.String("A license")),
|
||||
),
|
||||
Query: "select * from dolt_docs",
|
||||
ExpectedRows: ToSqlRows(CompressSchema(doltdocs.DocsSchema),
|
||||
NewRow(types.String("LICENSE.md"), types.String("A license"))),
|
||||
ExpectedSchema: CompressSchema(doltdocs.DocsSchema),
|
||||
},
|
||||
//{
|
||||
// Name: "select from dolt_docs",
|
||||
// AdditionalSetup: CreateTableFn("dolt_docs",
|
||||
// doltdocs.DocsSchema,
|
||||
// NewRowWithSchema(doltdocs.DocsSchema,
|
||||
// types.String("LICENSE.md"),
|
||||
// types.String("A license")),
|
||||
// ),
|
||||
// Query: "select * from dolt_docs",
|
||||
// ExpectedRows: ToSqlRows(CompressSchema(doltdocs.DocsSchema),
|
||||
// NewRow(types.String("LICENSE.md"), types.String("A license"))),
|
||||
// ExpectedSchema: CompressSchema(doltdocs.DocsSchema),
|
||||
//},
|
||||
{
|
||||
Name: "select from dolt_query_catalog",
|
||||
AdditionalSetup: CreateTableFn(doltdb.DoltQueryCatalogTableName,
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
|
||||
@@ -360,14 +359,6 @@ func TestExecuteUpdateSystemTables(t *testing.T) {
|
||||
}
|
||||
|
||||
var systemTableUpdateTests = []UpdateTest{
|
||||
{
|
||||
Name: "update dolt_docs",
|
||||
AdditionalSetup: CreateTableFn("dolt_docs",
|
||||
doltdocs.DocsSchema,
|
||||
NewRow(types.String("LICENSE.md"), types.String("A license"))),
|
||||
UpdateQuery: "update dolt_docs set doc_text = 'Some text')",
|
||||
ExpectedErr: "cannot insert into table",
|
||||
},
|
||||
{
|
||||
Name: "update dolt_query_catalog",
|
||||
AdditionalSetup: CreateTableFn(doltdb.DoltQueryCatalogTableName,
|
||||
|
||||
@@ -168,7 +168,6 @@ func ExecuteSelect(t *testing.T, dEnv *env.DoltEnv, ddb *doltdb.DoltDB, root *do
|
||||
Ddb: ddb,
|
||||
Rsw: dEnv.RepoStateWriter(),
|
||||
Rsr: dEnv.RepoStateReader(),
|
||||
Drw: dEnv.DocsReadWriter(),
|
||||
}
|
||||
|
||||
opts := editor.Options{Deaf: dEnv.DbEaFactory(), Tempdir: dEnv.TempTableFilesDir()}
|
||||
|
||||
Reference in New Issue
Block a user