mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-05 16:15:41 -06:00
libraries/doltcore/env/actions: Move GetUnstagedDocs and SaveDocsFromWOrkingExcludingFSChanges to actions/docs.go
This commit is contained in:
46
go/libraries/doltcore/env/actions/branch.go
vendored
46
go/libraries/doltcore/env/actions/branch.go
vendored
@@ -19,7 +19,6 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/diff"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/set"
|
||||
@@ -246,7 +245,10 @@ func CheckoutBranch(ctx context.Context, dEnv *env.DoltEnv, brName string) error
|
||||
return err
|
||||
}
|
||||
|
||||
unstagedDocs, err := getUnstagedDocs(ctx, dEnv)
|
||||
unstagedDocs, err := GetUnstagedDocs(ctx, dEnv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dEnv.RepoState.Head = ref.MarshalableRef{Ref: dref}
|
||||
dEnv.RepoState.Working = wrkHash.String()
|
||||
@@ -258,47 +260,9 @@ func CheckoutBranch(ctx context.Context, dEnv *env.DoltEnv, brName string) error
|
||||
return err
|
||||
}
|
||||
|
||||
return saveDocsOnCheckout(ctx, dEnv, unstagedDocs)
|
||||
return SaveDocsFromWorkingExcludingFSChanges(ctx, dEnv, unstagedDocs)
|
||||
}
|
||||
|
||||
func getUnstagedDocs(ctx context.Context, dEnv *env.DoltEnv) (env.Docs, error) {
|
||||
_, unstagedDocDiffs, err := diff.GetDocDiffs(ctx, dEnv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
unstagedDocs := env.Docs{}
|
||||
for _, docName := range unstagedDocDiffs.Docs {
|
||||
docDetail, err := dEnv.GetOneDocDetail(docName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
unstagedDocs = append(unstagedDocs, docDetail)
|
||||
}
|
||||
return unstagedDocs, nil
|
||||
}
|
||||
|
||||
func saveDocsOnCheckout(ctx context.Context, dEnv *env.DoltEnv, docsToExclude env.Docs) error {
|
||||
workingRoot, err := dEnv.WorkingRoot(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var docsToSave env.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, workingRoot, workingRoot, docsToSave)
|
||||
}
|
||||
|
||||
var emptyHash = hash.Hash{}
|
||||
|
||||
func tblHashesForCO(ctx context.Context, oldRoot, newRoot, changedRoot *doltdb.RootValue, conflicts *set.StrSet) (map[string]hash.Hash, error) {
|
||||
|
||||
41
go/libraries/doltcore/env/actions/docs.go
vendored
41
go/libraries/doltcore/env/actions/docs.go
vendored
@@ -140,3 +140,44 @@ func getUpdatedWorkingAndStagedWithDocs(ctx context.Context, dEnv *env.DoltEnv,
|
||||
|
||||
return currRoot, stgRoot, nil
|
||||
}
|
||||
|
||||
// GetUnstagedDocs retrieves the unstaged docs (docs from the filesystem).
|
||||
func GetUnstagedDocs(ctx context.Context, dEnv *env.DoltEnv) (env.Docs, error) {
|
||||
_, unstagedDocDiffs, err := diff.GetDocDiffs(ctx, dEnv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
unstagedDocs := env.Docs{}
|
||||
for _, docName := range unstagedDocDiffs.Docs {
|
||||
docDetail, err := dEnv.GetOneDocDetail(docName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
unstagedDocs = append(unstagedDocs, docDetail)
|
||||
}
|
||||
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 env.Docs) error {
|
||||
workingRoot, err := dEnv.WorkingRoot(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var docsToSave env.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, workingRoot, workingRoot, docsToSave)
|
||||
}
|
||||
Reference in New Issue
Block a user