mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-18 09:40:59 -05:00
Experimenting with a session based repo state reader, not sure I like it
This commit is contained in:
@@ -236,7 +236,8 @@ func (db Database) GetTableInsensitive(ctx *sql.Context, tblName string) (sql.Ta
|
||||
func (db Database) GetTableInsensitiveWithRoot(ctx *sql.Context, root *doltdb.RootValue, tblName string) (dt sql.Table, found bool, err error) {
|
||||
lwrName := strings.ToLower(tblName)
|
||||
|
||||
head, _, err := DSessFromSess(ctx.Session).GetHeadCommit(ctx, db.name)
|
||||
sess := DSessFromSess(ctx.Session)
|
||||
head, _, err := sess.GetHeadCommit(ctx, db.name)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
@@ -280,7 +281,7 @@ func (db Database) GetTableInsensitiveWithRoot(ctx *sql.Context, root *doltdb.Ro
|
||||
case doltdb.CommitAncestorsTableName:
|
||||
dt, found = dtables.NewCommitAncestorsTable(ctx, db.ddb), true
|
||||
case doltdb.StatusTableName:
|
||||
dt, found = dtables.NewStatusTable(ctx, db.name, db.ddb, db.rsr, db.drw), true
|
||||
dt, found = dtables.NewStatusTable(ctx, db.name, db.ddb, NewSessionRepoStateReader(sess, db.name), db.drw), true
|
||||
}
|
||||
if found {
|
||||
return dt, found, nil
|
||||
|
||||
@@ -284,12 +284,15 @@ func (sess *DoltSession) CommitWorkingSetToDolt(ctx *sql.Context, dbData env.DbD
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = actions.StageAllTables(ctx, dbData)
|
||||
|
||||
workingRoot := sess.roots[dbName].root
|
||||
|
||||
err = actions.StageAllTables(ctx, workingRoot, dbData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
queryTime := ctx.QueryTime()
|
||||
_, err = actions.CommitStaged(ctx, dbData, actions.CommitStagedProps{
|
||||
_, err = actions.CommitStaged(ctx, workingRoot, dbData, actions.CommitStagedProps{
|
||||
Message: fmt.Sprintf("Transaction commit at %s", queryTime.UTC().Format("2006-01-02T15:04:05Z")),
|
||||
Date: queryTime,
|
||||
AllowEmpty: false,
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
dsqle "github.com/dolthub/dolt/go/libraries/doltcore/sqle"
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/diff"
|
||||
@@ -84,10 +83,10 @@ func newStatusItr(ctx *sql.Context, st *StatusTable) (*StatusItr, error) {
|
||||
rsr := st.rsr
|
||||
drw := st.drw
|
||||
|
||||
sess := dsqle.DSessFromSess(ctx.Session)
|
||||
workingRoot, ok := sess.GetRoot(st.dbName)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("No root found in session")
|
||||
workingHash := rsr.WorkingHash()
|
||||
workingRoot, err := ddb.ReadRootValue(ctx, workingHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
stagedTables, unstagedTables, err := diff.GetStagedUnstagedTableDeltas(ctx, ddb, workingRoot, rsr)
|
||||
|
||||
86
go/libraries/doltcore/sqle/session_repo_state.go
Executable file
86
go/libraries/doltcore/sqle/session_repo_state.go
Executable file
@@ -0,0 +1,86 @@
|
||||
// Copyright 2021 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 sqle
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
)
|
||||
|
||||
// SessionRepoStateReader is an adapter for env.RepoStateReader in SQL contexts, getting information about the repo state
|
||||
// from the session.
|
||||
type SessionRepoStateReader struct {
|
||||
session *DoltSession
|
||||
dbName string
|
||||
}
|
||||
|
||||
func NewSessionRepoStateReader(session *DoltSession, dbName string) SessionRepoStateReader {
|
||||
return SessionRepoStateReader{session: session, dbName: dbName}
|
||||
}
|
||||
|
||||
func (s SessionRepoStateReader) CWBHeadRef() ref.DoltRef {
|
||||
workingSet := s.session.workingSets[s.dbName]
|
||||
headRef, err := workingSet.ToHeadRef()
|
||||
// TODO: fix this interface
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return headRef
|
||||
}
|
||||
|
||||
func (s SessionRepoStateReader) CWBHeadSpec() *doltdb.CommitSpec {
|
||||
// TODO: get rid of this
|
||||
ref := s.CWBHeadRef()
|
||||
spec, err := doltdb.NewCommitSpec(ref.GetPath())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return spec
|
||||
}
|
||||
|
||||
func (s SessionRepoStateReader) CWBHeadHash(ctx context.Context) (hash.Hash, error) {
|
||||
// TODO: get rid of this
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s SessionRepoStateReader) WorkingHash() hash.Hash {
|
||||
hash, err := s.session.roots[s.dbName].root.HashOf()
|
||||
// TODO: fix this interface
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return hash
|
||||
}
|
||||
|
||||
func (s SessionRepoStateReader) StagedHash() hash.Hash {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s SessionRepoStateReader) IsMergeActive() bool {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s SessionRepoStateReader) GetMergeCommit() string {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s SessionRepoStateReader) GetPreMergeWorking() string {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user