pr feedback

This commit is contained in:
Andy Arthur
2021-07-21 10:01:26 -07:00
parent 66961cf567
commit fdc91d7cf4
8 changed files with 26 additions and 23 deletions

View File

@@ -164,9 +164,9 @@ func (p DoltDatabaseProvider) databaseForRevision(ctx context.Context, revDB str
}
func (p DoltDatabaseProvider) RevisionDbState(ctx context.Context, revDB string) (dsess.InitialDbState, error) {
err := sql.ErrDatabaseNotFound.New(revDB)
errNotFound := sql.ErrDatabaseNotFound.New(revDB)
if !strings.Contains(revDB, dbRevisionDelimiter) {
return dsess.InitialDbState{}, err
return dsess.InitialDbState{}, errNotFound
}
parts := strings.SplitN(revDB, dbRevisionDelimiter, 2)
@@ -174,11 +174,11 @@ func (p DoltDatabaseProvider) RevisionDbState(ctx context.Context, revDB string)
candidate, ok := p.databases[dbName]
if !ok {
return dsess.InitialDbState{}, err
return dsess.InitialDbState{}, errNotFound
}
srcDb, ok := candidate.(Database)
if !ok {
return dsess.InitialDbState{}, err
return dsess.InitialDbState{}, errNotFound
}
if isBranch(ctx, srcDb.ddb, revSpec) {
@@ -196,14 +196,14 @@ func (p DoltDatabaseProvider) RevisionDbState(ctx context.Context, revDB string)
// a WorkingSet to reference, but Commits in the history don't
// have corresponding WorkingSets.
//if doltdb.IsValidCommitHash(revSpec) {
// _, init, err := dbRevisionForCommit(ctx, srcDb, revSpec)
// if err != nil {
// return dsess.InitialDbState{}, err
// _, init, errNotFound := dbRevisionForCommit(ctx, srcDb, revSpec)
// if errNotFound != nil {
// return dsess.InitialDbState{}, errNotFound
// }
// return init, nil
//}
return dsess.InitialDbState{}, sql.ErrDatabaseNotFound.New(revDB)
return dsess.InitialDbState{}, errNotFound
}
func isBranch(ctx context.Context, ddb *doltdb.DoltDB, revSpec string) bool {

View File

@@ -60,7 +60,7 @@ func (d DoltCommitFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)
}
dSess := dsess.DSessFromSess(ctx.Session)
roots, ok := dSess.GetRoots(nil, dbName)
roots, ok := dSess.GetRoots(ctx, dbName)
if !ok {
return nil, fmt.Errorf("Could not load database %s", dbName)
}

View File

@@ -45,7 +45,7 @@ func (d DoltMergeFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)
}
sess := dsess.DSessFromSess(ctx.Session)
dbData, ok := sess.GetDbData(nil, dbName)
dbData, ok := sess.GetDbData(ctx, dbName)
if !ok {
return 1, fmt.Errorf("Could not load database %s", dbName)
@@ -71,7 +71,7 @@ func (d DoltMergeFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)
if err != nil {
return nil, err
}
roots, ok := sess.GetRoots(nil, dbName)
roots, ok := sess.GetRoots(ctx, dbName)
// logrus.Errorf("heads are working: %s\nhead: %s", roots.Working.DebugString(ctx, true), roots.Head.DebugString(ctx, true))
@@ -97,7 +97,7 @@ func (d DoltMergeFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)
return "Merge aborted", nil
}
ddb, ok := sess.GetDoltDB(nil, dbName)
ddb, ok := sess.GetDoltDB(ctx, dbName)
if !ok {
return nil, sql.ErrDatabaseNotFound.New(dbName)
}

View File

@@ -64,7 +64,7 @@ func (d DoltResetFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)
}
// Get all the needed roots.
roots, ok := dSess.GetRoots(nil, dbName)
roots, ok := dSess.GetRoots(ctx, dbName)
if !ok {
return 1, fmt.Errorf("Could not load database %s", dbName)
}

View File

@@ -71,7 +71,7 @@ func (cf *MergeFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
}
dbName := sess.GetCurrentDatabase()
ddb, ok := sess.GetDoltDB(nil, dbName)
ddb, ok := sess.GetDoltDB(ctx, dbName)
if !ok {
return nil, sql.ErrDatabaseNotFound.New(dbName)
}

View File

@@ -21,7 +21,7 @@ import (
)
// RevisionDatabaseProvider provides revision databases.
// In Dolt, commits and branches can be accessed as discreet databases
// In Dolt, commits and branches can be accessed as discrete databases
// using a Dolt-specific syntax: `my_database/my_branch`. Revision databases
// corresponding to historical commits in the repository will be read-only
// databases. Revision databases for branches will be read/write.

View File

@@ -297,7 +297,7 @@ func (sess *Session) CommitTransaction(ctx *sql.Context, dbName string, tx sql.T
}
}
dbState, _, err := sess.LookupDbState(ctx, dbName)
dbState, ok, err := sess.LookupDbState(ctx, dbName)
if err != nil {
return err
}
@@ -316,11 +316,6 @@ func (sess *Session) CommitTransaction(ctx *sql.Context, dbName string, tx sql.T
return nil
}
dbState, ok, err := sess.LookupDbState(ctx, dbName)
if err != nil {
return err
}
// It's possible that this returns false if the user has created an in-Memory database. Moreover,
// the analyzer will check for us whether a db exists or not.
// TODO: fix this

View File

@@ -33,13 +33,21 @@ type SessionStateAdapter struct {
}
func (s SessionStateAdapter) UpdateStagedRoot(ctx context.Context, newRoot *doltdb.RootValue) error {
roots, _ := s.session.GetRoots(nil, s.dbName)
sqlCtx, ok := ctx.(*sql.Context)
if ok {
return fmt.Errorf("non-sql context passed to SessionStateAdapter")
}
roots, _ := s.session.GetRoots(sqlCtx, s.dbName)
roots.Staged = newRoot
return s.session.SetRoots(ctx.(*sql.Context), s.dbName, roots)
}
func (s SessionStateAdapter) UpdateWorkingRoot(ctx context.Context, newRoot *doltdb.RootValue) error {
roots, _ := s.session.GetRoots(nil, s.dbName)
sqlCtx, ok := ctx.(*sql.Context)
if ok {
return fmt.Errorf("non-sql context passed to SessionStateAdapter")
}
roots, _ := s.session.GetRoots(sqlCtx, s.dbName)
roots.Working = newRoot
return s.session.SetRoots(ctx.(*sql.Context), s.dbName, roots)
}