mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-29 03:08:47 -06:00
go: doltcore: sqle,env: Make RepoStateReader take a generic Context parameter for some parameters so that we can get rid of some unprincipled sql.NewContext uses.
This commit is contained in:
@@ -258,7 +258,7 @@ func getNerf(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgParseResu
|
||||
return nil, err
|
||||
}
|
||||
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ func doltCommitUpdatedTags(ctx context.Context, dEnv *env.DoltEnv, workingRoot d
|
||||
return err
|
||||
}
|
||||
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ func getValueFromRefSpec(ctx context.Context, dEnv *env.DoltEnv, specRef string)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
|
||||
optionalCommit, err := dEnv.DoltDB(ctx).Resolve(ctx, commitSpec, headRef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -138,7 +138,7 @@ func applyStashAtIdx(ctx *sql.Context, dEnv *env.DoltEnv, curWorkingRoot doltdb.
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ func stashChanges(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPars
|
||||
}
|
||||
}
|
||||
|
||||
curHeadRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
curHeadRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ func cherryPick(ctx *sql.Context, dSess *dsess.DoltSession, roots doltdb.Roots,
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
headRef, err := dbData.Rsr.CWBHeadRef()
|
||||
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ func (mr *MultiRepoTestSetup) CommitWithWorkingSet(dbName string) *doltdb.Commit
|
||||
panic("pending commit error: " + err.Error())
|
||||
}
|
||||
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
panic("couldn't get working set: " + err.Error())
|
||||
}
|
||||
@@ -369,7 +369,7 @@ func (mr *MultiRepoTestSetup) PushToRemote(dbName, remoteName, branchName string
|
||||
mr.Errhand(fmt.Sprintf("Failed to access .dolt directory: %s", err.Error()))
|
||||
}
|
||||
|
||||
pushOptions := &env.PushOptions{
|
||||
pushOptions := &env.PushOptions[context.Context]{
|
||||
Targets: targets,
|
||||
Remote: remote,
|
||||
Rsr: dEnv.RepoStateReader(),
|
||||
|
||||
22
go/libraries/doltcore/env/actions/branch.go
vendored
22
go/libraries/doltcore/env/actions/branch.go
vendored
@@ -33,7 +33,7 @@ var ErrCOBranchDelete = errorKinds.NewKind("Cannot delete checked out branch '%s
|
||||
var ErrUnmergedBranch = errorKinds.NewKind("branch '%s' is not fully merged")
|
||||
var ErrWorkingSetsOnBothBranches = errors.New("checkout would overwrite uncommitted changes on target branch")
|
||||
|
||||
func RenameBranch(ctx context.Context, dbData env.DbData, oldBranch, newBranch string, remoteDbPro env.RemoteDbProvider, force bool, rsc *doltdb.ReplicationStatusController) error {
|
||||
func RenameBranch[C doltdb.Context](ctx C, dbData env.DbData[C], oldBranch, newBranch string, remoteDbPro env.RemoteDbProvider, force bool, rsc *doltdb.ReplicationStatusController) error {
|
||||
oldRef := ref.NewBranchRef(oldBranch)
|
||||
newRef := ref.NewBranchRef(newBranch)
|
||||
|
||||
@@ -115,7 +115,7 @@ type DeleteOptions struct {
|
||||
AllowDeletingCurrentBranch bool
|
||||
}
|
||||
|
||||
func DeleteBranch(ctx context.Context, dbData env.DbData, brName string, opts DeleteOptions, remoteDbPro env.RemoteDbProvider, rsc *doltdb.ReplicationStatusController) error {
|
||||
func DeleteBranch[C doltdb.Context](ctx C, dbData env.DbData[C], brName string, opts DeleteOptions, remoteDbPro env.RemoteDbProvider, rsc *doltdb.ReplicationStatusController) error {
|
||||
var branchRef ref.DoltRef
|
||||
if opts.Remote {
|
||||
var err error
|
||||
@@ -125,7 +125,7 @@ func DeleteBranch(ctx context.Context, dbData env.DbData, brName string, opts De
|
||||
}
|
||||
} else {
|
||||
branchRef = ref.NewBranchRef(brName)
|
||||
headRef, err := dbData.Rsr.CWBHeadRef()
|
||||
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func DeleteBranch(ctx context.Context, dbData env.DbData, brName string, opts De
|
||||
return DeleteBranchOnDB(ctx, dbData, branchRef, opts, remoteDbPro, rsc)
|
||||
}
|
||||
|
||||
func DeleteBranchOnDB(ctx context.Context, dbdata env.DbData, branchRef ref.DoltRef, opts DeleteOptions, pro env.RemoteDbProvider, rsc *doltdb.ReplicationStatusController) error {
|
||||
func DeleteBranchOnDB[C doltdb.Context](ctx C, dbdata env.DbData[C], branchRef ref.DoltRef, opts DeleteOptions, pro env.RemoteDbProvider, rsc *doltdb.ReplicationStatusController) error {
|
||||
ddb := dbdata.Ddb
|
||||
hasRef, err := ddb.HasRef(ctx, branchRef)
|
||||
|
||||
@@ -184,7 +184,7 @@ func DeleteBranchOnDB(ctx context.Context, dbdata env.DbData, branchRef ref.Dolt
|
||||
}
|
||||
|
||||
// validateBranchMergedIntoCurrentWorkingBranch returns an error if the given branch is not fully merged into the HEAD of the current branch.
|
||||
func validateBranchMergedIntoCurrentWorkingBranch(ctx context.Context, dbdata env.DbData, branch ref.DoltRef) error {
|
||||
func validateBranchMergedIntoCurrentWorkingBranch[C doltdb.Context](ctx C, dbdata env.DbData[C], branch ref.DoltRef) error {
|
||||
branchSpec, err := doltdb.NewCommitSpec(branch.GetPath())
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -204,7 +204,7 @@ func validateBranchMergedIntoCurrentWorkingBranch(ctx context.Context, dbdata en
|
||||
return err
|
||||
}
|
||||
|
||||
headRef, err := dbdata.Rsr.CWBHeadRef()
|
||||
headRef, err := dbdata.Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -237,7 +237,7 @@ func validateBranchMergedIntoCurrentWorkingBranch(ctx context.Context, dbdata en
|
||||
}
|
||||
|
||||
// validateBranchMergedIntoUpstream returns an error if the branch provided is not fully merged into its upstream
|
||||
func validateBranchMergedIntoUpstream(ctx context.Context, dbdata env.DbData, branch ref.DoltRef, remoteName string, pro env.RemoteDbProvider) error {
|
||||
func validateBranchMergedIntoUpstream[C doltdb.Context](ctx context.Context, dbdata env.DbData[C], branch ref.DoltRef, remoteName string, pro env.RemoteDbProvider) error {
|
||||
remotes, err := dbdata.Rsr.GetRemotes()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -294,7 +294,7 @@ func validateBranchMergedIntoUpstream(ctx context.Context, dbdata env.DbData, br
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateBranchWithStartPt(ctx context.Context, dbData env.DbData, newBranch, startPt string, force bool, rsc *doltdb.ReplicationStatusController) error {
|
||||
func CreateBranchWithStartPt[C doltdb.Context](ctx C, dbData env.DbData[C], newBranch, startPt string, force bool, rsc *doltdb.ReplicationStatusController) error {
|
||||
err := createBranch(ctx, dbData, newBranch, startPt, force, rsc)
|
||||
|
||||
if err != nil {
|
||||
@@ -354,8 +354,8 @@ func CreateBranchOnDB(ctx context.Context, ddb *doltdb.DoltDB, newBranch, starti
|
||||
return nil
|
||||
}
|
||||
|
||||
func createBranch(ctx context.Context, dbData env.DbData, newBranch, startingPoint string, force bool, rsc *doltdb.ReplicationStatusController) error {
|
||||
headRef, err := dbData.Rsr.CWBHeadRef()
|
||||
func createBranch[C doltdb.Context](ctx C, dbData env.DbData[C], newBranch, startingPoint string, force bool, rsc *doltdb.ReplicationStatusController) error {
|
||||
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -378,7 +378,7 @@ func MaybeGetCommit(ctx context.Context, dEnv *env.DoltEnv, str string) (*doltdb
|
||||
cs, err := doltdb.NewCommitSpec(str)
|
||||
|
||||
if err == nil {
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ func RootsForBranch(ctx context.Context, roots doltdb.Roots, branchRoot doltdb.R
|
||||
// CleanOldWorkingSet resets the source branch's working set to the branch head, leaving the source branch unchanged
|
||||
func CleanOldWorkingSet(
|
||||
ctx *sql.Context,
|
||||
dbData env.DbData,
|
||||
dbData env.DbData[*sql.Context],
|
||||
doltDb *doltdb.DoltDB,
|
||||
username, email string,
|
||||
initialRoots doltdb.Roots,
|
||||
|
||||
2
go/libraries/doltcore/env/actions/clone.go
vendored
2
go/libraries/doltcore/env/actions/clone.go
vendored
@@ -320,7 +320,7 @@ func fullClone(ctx context.Context, srcDB *doltdb.DoltDB, dEnv *env.DoltEnv, src
|
||||
|
||||
// shallowCloneDataPull is a shallow clone specific helper function to pull only the data required to show the given branch
|
||||
// at the depth given.
|
||||
func shallowCloneDataPull(ctx context.Context, destData env.DbData, srcDB *doltdb.DoltDB, remoteName, branch string, depth int) (*doltdb.Commit, error) {
|
||||
func shallowCloneDataPull[C doltdb.Context](ctx C, destData env.DbData[C], srcDB *doltdb.DoltDB, remoteName, branch string, depth int) (*doltdb.Commit, error) {
|
||||
remotes, err := destData.Rsr.GetRemotes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
22
go/libraries/doltcore/env/actions/remotes.go
vendored
22
go/libraries/doltcore/env/actions/remotes.go
vendored
@@ -102,7 +102,7 @@ func Push(ctx context.Context, tempTableDir string, mode ref.UpdateMode, destRef
|
||||
|
||||
// DoPush returns a message about whether the push was successful for each branch or a tag.
|
||||
// This includes if there is a new remote branch created, upstream is set or push was rejected for a branch.
|
||||
func DoPush(ctx context.Context, pushMeta *env.PushOptions, progStarter ProgStarter, progStopper ProgStopper) (returnMsg string, err error) {
|
||||
func DoPush[C doltdb.Context](ctx C, pushMeta *env.PushOptions[C], progStarter ProgStarter, progStopper ProgStopper) (returnMsg string, err error) {
|
||||
var successPush, setUpstreamPush, failedPush []string
|
||||
for _, targets := range pushMeta.Targets {
|
||||
err = push(ctx, pushMeta.Rsr, pushMeta.TmpDir, pushMeta.SrcDb, pushMeta.DestDb, pushMeta.Remote, targets, progStarter, progStopper)
|
||||
@@ -143,7 +143,7 @@ func DoPush(ctx context.Context, pushMeta *env.PushOptions, progStarter ProgStar
|
||||
}
|
||||
|
||||
// push performs push on a branch or a tag.
|
||||
func push(ctx context.Context, rsr env.RepoStateReader, tmpDir string, src, dest *doltdb.DoltDB, remote *env.Remote, opts *env.PushTarget, progStarter ProgStarter, progStopper ProgStopper) error {
|
||||
func push[C doltdb.Context](ctx C, rsr env.RepoStateReader[C], tmpDir string, src, dest *doltdb.DoltDB, remote *env.Remote, opts *env.PushTarget, progStarter ProgStarter, progStopper ProgStopper) error {
|
||||
switch opts.SrcRef.GetType() {
|
||||
case ref.BranchRefType:
|
||||
if opts.SrcRef == ref.EmptyBranchRef {
|
||||
@@ -212,7 +212,7 @@ func deleteRemoteBranch(ctx context.Context, toDelete, remoteRef ref.DoltRef, lo
|
||||
return nil
|
||||
}
|
||||
|
||||
func PushToRemoteBranch(ctx context.Context, rsr env.RepoStateReader, tempTableDir string, mode ref.UpdateMode, srcRef, destRef, remoteRef ref.DoltRef, localDB, remoteDB *doltdb.DoltDB, remote env.Remote, progStarter ProgStarter, progStopper ProgStopper) error {
|
||||
func PushToRemoteBranch[C doltdb.Context](ctx C, rsr env.RepoStateReader[C], tempTableDir string, mode ref.UpdateMode, srcRef, destRef, remoteRef ref.DoltRef, localDB, remoteDB *doltdb.DoltDB, remote env.Remote, progStarter ProgStarter, progStopper ProgStopper) error {
|
||||
evt := events.GetEventFromContext(ctx)
|
||||
|
||||
u, err := earl.Parse(remote.Url)
|
||||
@@ -225,7 +225,7 @@ func PushToRemoteBranch(ctx context.Context, rsr env.RepoStateReader, tempTableD
|
||||
}
|
||||
|
||||
cs, _ := doltdb.NewCommitSpec(srcRef.GetPath())
|
||||
headRef, err := rsr.CWBHeadRef()
|
||||
headRef, err := rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -471,9 +471,9 @@ func FetchRemoteBranch(
|
||||
|
||||
// ShallowFetchRefSpec fetches the remote refSpec from the source database to the destination database. Currently it is only
|
||||
// used for shallow clones.
|
||||
func ShallowFetchRefSpec(
|
||||
func ShallowFetchRefSpec[C doltdb.Context](
|
||||
ctx context.Context,
|
||||
dbData env.DbData,
|
||||
dbData env.DbData[C],
|
||||
srcDB *doltdb.DoltDB,
|
||||
refSpecs ref.RemoteRefSpec,
|
||||
remote *env.Remote,
|
||||
@@ -490,9 +490,9 @@ func ShallowFetchRefSpec(
|
||||
// FetchRefSpecs is the common SQL and CLI entrypoint for fetching branches, tags, and heads from a remote.
|
||||
// This function takes dbData which is a env.DbData object for handling repoState read and write, and srcDB is
|
||||
// a remote *doltdb.DoltDB object that is used to fetch remote branches from.
|
||||
func FetchRefSpecs(
|
||||
func FetchRefSpecs[C doltdb.Context](
|
||||
ctx context.Context,
|
||||
dbData env.DbData,
|
||||
dbData env.DbData[C],
|
||||
srcDB *doltdb.DoltDB,
|
||||
refSpecs []ref.RemoteRefSpec,
|
||||
defaultRefSpec bool,
|
||||
@@ -517,9 +517,9 @@ func FetchRefSpecs(
|
||||
// - depth: the depth of the fetch. If depth is greater than 0, it is a shallow clone.
|
||||
// - progStarter: function that starts the progress reporting
|
||||
// - progStopper: function that stops the progress reporting
|
||||
func fetchRefSpecsWithDepth(
|
||||
func fetchRefSpecsWithDepth[C doltdb.Context](
|
||||
ctx context.Context,
|
||||
dbData env.DbData,
|
||||
dbData env.DbData[C],
|
||||
srcDB *doltdb.DoltDB,
|
||||
refSpecs []ref.RemoteRefSpec,
|
||||
defaultRefSpecs bool,
|
||||
@@ -740,7 +740,7 @@ func updateSkipList(ctx context.Context, srcDB *doltdb.DoltDB, toFetch []hash.Ha
|
||||
return newFetchList, newSkipList, nil
|
||||
}
|
||||
|
||||
func pruneBranches(ctx context.Context, dbData env.DbData, remote env.Remote, remoteRefs []doltdb.RefWithHash) error {
|
||||
func pruneBranches[C doltdb.Context](ctx context.Context, dbData env.DbData[C], remote env.Remote, remoteRefs []doltdb.RefWithHash) error {
|
||||
remoteRefTypes := map[ref.RefType]struct{}{
|
||||
ref.RemoteRefType: {},
|
||||
}
|
||||
|
||||
16
go/libraries/doltcore/env/actions/reset.go
vendored
16
go/libraries/doltcore/env/actions/reset.go
vendored
@@ -32,7 +32,7 @@ import (
|
||||
// resetHardTables resolves a new HEAD commit from a refSpec and updates working set roots by
|
||||
// resetting the table contexts for tracked tables. New tables are ignored. Returns new HEAD
|
||||
// Commit and Roots.
|
||||
func resetHardTables(ctx *sql.Context, dbData env.DbData, cSpecStr string, roots doltdb.Roots) (*doltdb.Commit, doltdb.Roots, error) {
|
||||
func resetHardTables[C doltdb.Context](ctx C, dbData env.DbData[C], cSpecStr string, roots doltdb.Roots) (*doltdb.Commit, doltdb.Roots, error) {
|
||||
ddb := dbData.Ddb
|
||||
rsr := dbData.Rsr
|
||||
|
||||
@@ -43,7 +43,7 @@ func resetHardTables(ctx *sql.Context, dbData env.DbData, cSpecStr string, roots
|
||||
return nil, doltdb.Roots{}, err
|
||||
}
|
||||
|
||||
headRef, err := rsr.CWBHeadRef()
|
||||
headRef, err := rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, doltdb.Roots{}, err
|
||||
}
|
||||
@@ -147,16 +147,16 @@ func GetAllTableNames(ctx context.Context, root doltdb.RootValue) []doltdb.Table
|
||||
|
||||
// ResetHardTables resets the tables in working, staged, and head based on the given parameters. Returns the new
|
||||
// head commit and resulting roots
|
||||
func ResetHardTables(ctx *sql.Context, dbData env.DbData, cSpecStr string, roots doltdb.Roots) (*doltdb.Commit, doltdb.Roots, error) {
|
||||
func ResetHardTables[C doltdb.Context](ctx C, dbData env.DbData[C], cSpecStr string, roots doltdb.Roots) (*doltdb.Commit, doltdb.Roots, error) {
|
||||
return resetHardTables(ctx, dbData, cSpecStr, roots)
|
||||
}
|
||||
|
||||
// ResetHard resets the working, staged, and head to the ones in the provided roots and head ref.
|
||||
// The reset can be performed on a non-current branch and working set.
|
||||
// Returns an error if the reset fails.
|
||||
func ResetHard(
|
||||
ctx *sql.Context,
|
||||
dbData env.DbData,
|
||||
func ResetHard[C doltdb.Context](
|
||||
ctx C,
|
||||
dbData env.DbData[C],
|
||||
doltDb *doltdb.DoltDB,
|
||||
username, email string,
|
||||
cSpecStr string,
|
||||
@@ -222,13 +222,13 @@ func ResetSoftTables(ctx context.Context, tableNames []doltdb.TableName, roots d
|
||||
|
||||
// ResetSoftToRef matches the `git reset --soft <REF>` pattern. It returns a new Roots with the Staged and Head values
|
||||
// set to the commit specified by the spec string. The Working root is not set
|
||||
func ResetSoftToRef(ctx context.Context, dbData env.DbData, cSpecStr string) (doltdb.Roots, error) {
|
||||
func ResetSoftToRef[C doltdb.Context](ctx C, dbData env.DbData[C], cSpecStr string) (doltdb.Roots, error) {
|
||||
cs, err := doltdb.NewCommitSpec(cSpecStr)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
|
||||
headRef, err := dbData.Rsr.CWBHeadRef()
|
||||
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
|
||||
2
go/libraries/doltcore/env/actions/tag.go
vendored
2
go/libraries/doltcore/env/actions/tag.go
vendored
@@ -34,7 +34,7 @@ type TagProps struct {
|
||||
}
|
||||
|
||||
func CreateTag(ctx context.Context, dEnv *env.DoltEnv, tagName, startPoint string, props TagProps) error {
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ var ErrCOWorkspaceDelete = errors.New("attempted to delete checked out workspace
|
||||
var ErrBranchNameExists = errors.New("workspace name must not be existing branch name")
|
||||
|
||||
func CreateWorkspace(ctx context.Context, dEnv *env.DoltEnv, name, startPoint string) error {
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -94,7 +94,7 @@ func DeleteWorkspace(ctx context.Context, dEnv *env.DoltEnv, workspaceName strin
|
||||
}
|
||||
} else {
|
||||
dref = ref.NewWorkspaceRef(workspaceName)
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
24
go/libraries/doltcore/env/environment.go
vendored
24
go/libraries/doltcore/env/environment.go
vendored
@@ -271,7 +271,7 @@ func (dEnv *DoltEnv) Valid() bool {
|
||||
// initWorkingSetFromRepoState sets the working set for the env's head to mirror the contents of the repo state file.
|
||||
// This is only necessary to migrate repos written before this method was introduced, and can be removed after 1.0
|
||||
func (dEnv *DoltEnv) initWorkingSetFromRepoState(ctx context.Context) error {
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -610,8 +610,8 @@ func (dEnv *DoltEnv) InitializeRepoState(ctx context.Context, branchName string)
|
||||
return nil
|
||||
}
|
||||
|
||||
type RootsProvider interface {
|
||||
GetRoots(ctx context.Context) (doltdb.Roots, error)
|
||||
type RootsProvider[C doltdb.Context] interface {
|
||||
GetRoots(ctx C) (doltdb.Roots, error)
|
||||
}
|
||||
|
||||
// Roots returns the roots for this environment
|
||||
@@ -691,8 +691,8 @@ func (dEnv *DoltEnv) WorkingSet(ctx context.Context) (*doltdb.WorkingSet, error)
|
||||
return WorkingSet(ctx, dEnv.DoltDB(ctx), dEnv.RepoStateReader())
|
||||
}
|
||||
|
||||
func WorkingSet(ctx context.Context, ddb *doltdb.DoltDB, rsr RepoStateReader) (*doltdb.WorkingSet, error) {
|
||||
headRef, err := rsr.CWBHeadRef()
|
||||
func WorkingSet[C doltdb.Context](ctx C, ddb *doltdb.DoltDB, rsr RepoStateReader[C]) (*doltdb.WorkingSet, error) {
|
||||
headRef, err := rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -760,21 +760,21 @@ type repoStateReader struct {
|
||||
*DoltEnv
|
||||
}
|
||||
|
||||
func (r *repoStateReader) CWBHeadRef() (ref.DoltRef, error) {
|
||||
func (r *repoStateReader) CWBHeadRef(context.Context) (ref.DoltRef, error) {
|
||||
if r.RepoState == nil && r.RSLoadErr != nil {
|
||||
return nil, r.RSLoadErr
|
||||
}
|
||||
return r.RepoState.CWBHeadRef(), nil
|
||||
}
|
||||
|
||||
func (r *repoStateReader) CWBHeadSpec() (*doltdb.CommitSpec, error) {
|
||||
func (r *repoStateReader) CWBHeadSpec(context.Context) (*doltdb.CommitSpec, error) {
|
||||
if r.RepoState == nil && r.RSLoadErr != nil {
|
||||
return nil, r.RSLoadErr
|
||||
}
|
||||
return r.RepoState.CWBHeadSpec(), nil
|
||||
}
|
||||
|
||||
func (dEnv *DoltEnv) RepoStateReader() RepoStateReader {
|
||||
func (dEnv *DoltEnv) RepoStateReader() RepoStateReader[context.Context] {
|
||||
return &repoStateReader{dEnv}
|
||||
}
|
||||
|
||||
@@ -830,8 +830,8 @@ func (dEnv *DoltEnv) HeadCommit(ctx context.Context) (*doltdb.Commit, error) {
|
||||
return dEnv.DoltDB(ctx).ResolveCommitRef(ctx, dEnv.RepoState.CWBHeadRef())
|
||||
}
|
||||
|
||||
func (dEnv *DoltEnv) DbData(ctx context.Context) DbData {
|
||||
return DbData{
|
||||
func (dEnv *DoltEnv) DbData(ctx context.Context) DbData[context.Context] {
|
||||
return DbData[context.Context]{
|
||||
Ddb: dEnv.DoltDB(ctx),
|
||||
Rsw: dEnv.RepoStateWriter(),
|
||||
Rsr: dEnv.RepoStateReader(),
|
||||
@@ -1160,7 +1160,7 @@ func (dEnv *DoltEnv) FindRef(ctx context.Context, refStr string) (ref.DoltRef, e
|
||||
|
||||
// GetRefSpecs takes an optional remoteName and returns all refspecs associated with that remote. If "" is passed as
|
||||
// the remoteName then the default remote is used.
|
||||
func GetRefSpecs(rsr RepoStateReader, remoteName string) ([]ref.RemoteRefSpec, error) {
|
||||
func GetRefSpecs[C doltdb.Context](rsr RepoStateReader[C], remoteName string) ([]ref.RemoteRefSpec, error) {
|
||||
var remote Remote
|
||||
var err error
|
||||
|
||||
@@ -1207,7 +1207,7 @@ var ErrCantDetermineDefault = errors.New("unable to determine the default remote
|
||||
|
||||
// GetDefaultRemote gets the default remote for the environment. Not fully implemented yet. Needs to support multiple
|
||||
// repos and a configurable default.
|
||||
func GetDefaultRemote(rsr RepoStateReader) (Remote, error) {
|
||||
func GetDefaultRemote[C doltdb.Context](rsr RepoStateReader[C]) (Remote, error) {
|
||||
remotes, err := rsr.GetRemotes()
|
||||
if err != nil {
|
||||
return NoRemote, err
|
||||
|
||||
22
go/libraries/doltcore/env/memory.go
vendored
22
go/libraries/doltcore/env/memory.go
vendored
@@ -29,20 +29,20 @@ import (
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
)
|
||||
|
||||
func NewMemoryDbData(ctx context.Context, cfg config.ReadableConfig) (DbData, error) {
|
||||
func NewMemoryDbData(ctx context.Context, cfg config.ReadableConfig) (DbData[context.Context], error) {
|
||||
branchName := GetDefaultInitBranch(cfg)
|
||||
|
||||
ddb, err := NewMemoryDoltDB(ctx, branchName)
|
||||
if err != nil {
|
||||
return DbData{}, err
|
||||
return DbData[context.Context]{}, err
|
||||
}
|
||||
|
||||
rs, err := NewMemoryRepoState(ctx, ddb, branchName)
|
||||
if err != nil {
|
||||
return DbData{}, err
|
||||
return DbData[context.Context]{}, err
|
||||
}
|
||||
|
||||
return DbData{
|
||||
return DbData[context.Context]{
|
||||
Ddb: ddb,
|
||||
Rsw: rs,
|
||||
Rsr: rs,
|
||||
@@ -99,15 +99,15 @@ type MemoryRepoState struct {
|
||||
Head ref.DoltRef
|
||||
}
|
||||
|
||||
var _ RepoStateReader = MemoryRepoState{}
|
||||
var _ RepoStateReader[context.Context] = MemoryRepoState{}
|
||||
var _ RepoStateWriter = MemoryRepoState{}
|
||||
|
||||
func (m MemoryRepoState) CWBHeadRef() (ref.DoltRef, error) {
|
||||
func (m MemoryRepoState) CWBHeadRef(context.Context) (ref.DoltRef, error) {
|
||||
return m.Head, nil
|
||||
}
|
||||
|
||||
func (m MemoryRepoState) CWBHeadSpec() (*doltdb.CommitSpec, error) {
|
||||
headRef, err := m.CWBHeadRef()
|
||||
func (m MemoryRepoState) CWBHeadSpec(ctx context.Context) (*doltdb.CommitSpec, error) {
|
||||
headRef, err := m.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -125,7 +125,7 @@ func (m MemoryRepoState) UpdateStagedRoot(ctx context.Context, newRoot doltdb.Ro
|
||||
ws, err := m.WorkingSet(ctx)
|
||||
if err == doltdb.ErrWorkingSetNotFound {
|
||||
// first time updating root
|
||||
headRef, err := m.CWBHeadRef()
|
||||
headRef, err := m.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -155,7 +155,7 @@ func (m MemoryRepoState) UpdateWorkingRoot(ctx context.Context, newRoot doltdb.R
|
||||
ws, err := m.WorkingSet(ctx)
|
||||
if err == doltdb.ErrWorkingSetNotFound {
|
||||
// first time updating root
|
||||
headRef, err := m.CWBHeadRef()
|
||||
headRef, err := m.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func (m MemoryRepoState) UpdateWorkingRoot(ctx context.Context, newRoot doltdb.R
|
||||
}
|
||||
|
||||
func (m MemoryRepoState) WorkingSet(ctx context.Context) (*doltdb.WorkingSet, error) {
|
||||
headRef, err := m.CWBHeadRef()
|
||||
headRef, err := m.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
30
go/libraries/doltcore/env/remotes.go
vendored
30
go/libraries/doltcore/env/remotes.go
vendored
@@ -144,9 +144,9 @@ func (r Remote) WithParams(params map[string]string) Remote {
|
||||
|
||||
// PushOptions contains information needed for push for
|
||||
// one or more branches or a tag for a specific remote database.
|
||||
type PushOptions struct {
|
||||
type PushOptions[C doltdb.Context] struct {
|
||||
Targets []*PushTarget
|
||||
Rsr RepoStateReader
|
||||
Rsr RepoStateReader[C]
|
||||
Rsw RepoStateWriter
|
||||
Remote *Remote
|
||||
SrcDb *doltdb.DoltDB
|
||||
@@ -164,7 +164,7 @@ type PushTarget struct {
|
||||
HasUpstream bool
|
||||
}
|
||||
|
||||
func NewPushOpts(ctx context.Context, apr *argparser.ArgParseResults, rsr RepoStateReader, ddb *doltdb.DoltDB, force, setUpstream, pushAutoSetupRemote, all bool) ([]*PushTarget, *Remote, error) {
|
||||
func NewPushOpts[C doltdb.Context](ctx C, apr *argparser.ArgParseResults, rsr RepoStateReader[C], ddb *doltdb.DoltDB, force, setUpstream, pushAutoSetupRemote, all bool) ([]*PushTarget, *Remote, error) {
|
||||
if apr.NArg() == 0 {
|
||||
return getPushTargetsAndRemoteFromNoArg(ctx, rsr, ddb, force, setUpstream, pushAutoSetupRemote, all)
|
||||
}
|
||||
@@ -174,7 +174,7 @@ func NewPushOpts(ctx context.Context, apr *argparser.ArgParseResults, rsr RepoSt
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
currentBranch, err := rsr.CWBHeadRef()
|
||||
currentBranch, err := rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -227,7 +227,7 @@ func NewPushOpts(ctx context.Context, apr *argparser.ArgParseResults, rsr RepoSt
|
||||
}
|
||||
}
|
||||
|
||||
func getRemote(rsr RepoStateReader, name string) (Remote, error) {
|
||||
func getRemote[C doltdb.Context](rsr RepoStateReader[C], name string) (Remote, error) {
|
||||
remotes, err := rsr.GetRemotes()
|
||||
if err != nil {
|
||||
return NoRemote, err
|
||||
@@ -242,13 +242,13 @@ func getRemote(rsr RepoStateReader, name string) (Remote, error) {
|
||||
|
||||
// getPushTargetsAndRemoteFromNoArg pushes the current branch on default remote if upstream is set or `-u` is defined;
|
||||
// otherwise, all branches of default remote if `--all` flag is used.
|
||||
func getPushTargetsAndRemoteFromNoArg(ctx context.Context, rsr RepoStateReader, ddb *doltdb.DoltDB, force, setUpstream, pushAutoSetupRemote, all bool) ([]*PushTarget, *Remote, error) {
|
||||
func getPushTargetsAndRemoteFromNoArg[C doltdb.Context](ctx C, rsr RepoStateReader[C], ddb *doltdb.DoltDB, force, setUpstream, pushAutoSetupRemote, all bool) ([]*PushTarget, *Remote, error) {
|
||||
rsrBranches, err := rsr.GetBranches()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
currentBranch, err := rsr.CWBHeadRef()
|
||||
currentBranch, err := rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -355,9 +355,9 @@ func getPushTargetFromRefSpec(refSpec ref.RefSpec, currentBranch ref.DoltRef, re
|
||||
// If there is no remote specified, the current branch needs to have upstream set to push; otherwise, returns error.
|
||||
// This function returns |refSpec| for current branch, name of the remote the branch is associated with and
|
||||
// whether the current branch has upstream set.
|
||||
func getCurrentBranchRefSpec(ctx context.Context, branches *concurrentmap.Map[string, BranchConfig], rsr RepoStateReader, ddb *doltdb.DoltDB, remoteName string, isDefaultRemote, remoteSpecified, setUpstream, pushAutoSetupRemote bool) (ref.RefSpec, string, bool, error) {
|
||||
func getCurrentBranchRefSpec[C doltdb.Context](ctx C, branches *concurrentmap.Map[string, BranchConfig], rsr RepoStateReader[C], ddb *doltdb.DoltDB, remoteName string, isDefaultRemote, remoteSpecified, setUpstream, pushAutoSetupRemote bool) (ref.RefSpec, string, bool, error) {
|
||||
var refSpec ref.RefSpec
|
||||
currentBranch, err := rsr.CWBHeadRef()
|
||||
currentBranch, err := rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, "", false, err
|
||||
}
|
||||
@@ -387,7 +387,7 @@ func getCurrentBranchRefSpec(ctx context.Context, branches *concurrentmap.Map[st
|
||||
}
|
||||
|
||||
// RemoteForFetchArgs returns the remote and remaining arg strings for a fetch command
|
||||
func RemoteForFetchArgs(args []string, rsr RepoStateReader) (Remote, []string, error) {
|
||||
func RemoteForFetchArgs[C doltdb.Context](args []string, rsr RepoStateReader[C]) (Remote, []string, error) {
|
||||
var err error
|
||||
remotes, err := rsr.GetRemotes()
|
||||
if err != nil {
|
||||
@@ -418,7 +418,7 @@ func RemoteForFetchArgs(args []string, rsr RepoStateReader) (Remote, []string, e
|
||||
// ParseRefSpecs returns the ref specs for the string arguments given for the remote provided, or the default ref
|
||||
// specs for that remote if no arguments are provided. In the event that the default ref specs are returned, the
|
||||
// returned boolean value will be true.
|
||||
func ParseRefSpecs(args []string, rsr RepoStateReader, remote Remote) ([]ref.RemoteRefSpec, bool, error) {
|
||||
func ParseRefSpecs[C doltdb.Context](args []string, rsr RepoStateReader[C], remote Remote) ([]ref.RemoteRefSpec, bool, error) {
|
||||
if len(args) != 0 {
|
||||
specs, err := ParseRSFromArgs(remote.Name, args)
|
||||
return specs, false, err
|
||||
@@ -579,9 +579,9 @@ func WithForce(force bool) PullSpecOpt {
|
||||
|
||||
// NewPullSpec returns a PullSpec for the arguments given. This function validates remote and gets remoteRef
|
||||
// for given remoteRefName; if it's not defined, it uses current branch to get its upstream branch if it exists.
|
||||
func NewPullSpec(
|
||||
_ context.Context,
|
||||
rsr RepoStateReader,
|
||||
func NewPullSpec[C doltdb.Context](
|
||||
ctx C,
|
||||
rsr RepoStateReader[C],
|
||||
remoteName, remoteRefName string,
|
||||
remoteOnly bool,
|
||||
opts ...PullSpecOpt,
|
||||
@@ -605,7 +605,7 @@ func NewPullSpec(
|
||||
|
||||
var remoteRef ref.DoltRef
|
||||
if remoteRefName == "" {
|
||||
branch, err := rsr.CWBHeadRef()
|
||||
branch, err := rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
14
go/libraries/doltcore/env/repo_state.go
vendored
14
go/libraries/doltcore/env/repo_state.go
vendored
@@ -28,9 +28,9 @@ import (
|
||||
)
|
||||
|
||||
// TODO: change name to ClientStateReader, move out of env package
|
||||
type RepoStateReader interface {
|
||||
CWBHeadRef() (ref.DoltRef, error)
|
||||
CWBHeadSpec() (*doltdb.CommitSpec, error)
|
||||
type RepoStateReader[C doltdb.Context] interface {
|
||||
CWBHeadRef(C) (ref.DoltRef, error)
|
||||
CWBHeadSpec(C) (*doltdb.CommitSpec, error)
|
||||
GetRemotes() (*concurrentmap.Map[string, Remote], error)
|
||||
GetBackups() (*concurrentmap.Map[string, Remote], error)
|
||||
GetBranches() (*concurrentmap.Map[string, BranchConfig], error)
|
||||
@@ -47,8 +47,8 @@ type RepoStateWriter interface {
|
||||
UpdateBranch(name string, new BranchConfig) error
|
||||
}
|
||||
|
||||
type RepoStateReadWriter interface {
|
||||
RepoStateReader
|
||||
type RepoStateReadWriter[C doltdb.Context] interface {
|
||||
RepoStateReader[C]
|
||||
RepoStateWriter
|
||||
}
|
||||
|
||||
@@ -56,10 +56,10 @@ type RepoStateReadWriter interface {
|
||||
type RemoteDbProvider interface {
|
||||
GetRemoteDB(ctx context.Context, format *types.NomsBinFormat, r Remote, withCaching bool) (*doltdb.DoltDB, error)
|
||||
}
|
||||
type DbData struct {
|
||||
type DbData[C doltdb.Context] struct {
|
||||
Ddb *doltdb.DoltDB
|
||||
Rsw RepoStateWriter
|
||||
Rsr RepoStateReader
|
||||
Rsr RepoStateReader[C]
|
||||
}
|
||||
|
||||
type BranchConfig struct {
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package merge
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
@@ -81,9 +80,9 @@ func WithSquash(squash bool) MergeSpecOpt {
|
||||
}
|
||||
|
||||
// NewMergeSpec returns a MergeSpec with the arguments provided.
|
||||
func NewMergeSpec(
|
||||
ctx context.Context,
|
||||
rsr env.RepoStateReader,
|
||||
func NewMergeSpec[C doltdb.Context](
|
||||
ctx C,
|
||||
rsr env.RepoStateReader[C],
|
||||
ddb *doltdb.DoltDB,
|
||||
roots doltdb.Roots,
|
||||
name, email, commitSpecStr string,
|
||||
@@ -95,7 +94,7 @@ func NewMergeSpec(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
headRef, err := rsr.CWBHeadRef()
|
||||
headRef, err := rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -95,14 +95,14 @@ func AllBranches(ctx context.Context, dEnv *env.DoltEnv, applyUncommitted bool,
|
||||
|
||||
// CurrentBranch rewrites the history of the current branch using the |replay| function.
|
||||
func CurrentBranch(ctx context.Context, dEnv *env.DoltEnv, applyUncommitted bool, commitReplayer CommitReplayer, rootReplayer RootReplayer, nerf NeedsRebaseFn) error {
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return rebaseRefs(ctx, dEnv.DbData(ctx), applyUncommitted, commitReplayer, rootReplayer, nerf, headRef)
|
||||
}
|
||||
|
||||
func rebaseRefs(ctx context.Context, dbData env.DbData, applyUncommitted bool, commitReplayer CommitReplayer, rootReplayer RootReplayer, nerf NeedsRebaseFn, refs ...ref.DoltRef) error {
|
||||
func rebaseRefs(ctx context.Context, dbData env.DbData[context.Context], applyUncommitted bool, commitReplayer CommitReplayer, rootReplayer RootReplayer, nerf NeedsRebaseFn, refs ...ref.DoltRef) error {
|
||||
ddb := dbData.Ddb
|
||||
heads := make([]*doltdb.Commit, len(refs))
|
||||
for i, dRef := range refs {
|
||||
|
||||
@@ -113,7 +113,7 @@ func (db database) InitialDBState(ctx *sql.Context) (dsess.InitialDbState, error
|
||||
// repo state writer
|
||||
return dsess.InitialDbState{
|
||||
Db: db,
|
||||
DbData: env.DbData{
|
||||
DbData: env.DbData[*sql.Context]{
|
||||
Rsw: noopRepoStateWriter{},
|
||||
},
|
||||
ReadOnly: true,
|
||||
@@ -134,8 +134,8 @@ func (db database) GetRoot(context *sql.Context) (doltdb.RootValue, error) {
|
||||
return nil, errors.New("unimplemented")
|
||||
}
|
||||
|
||||
func (db database) DbData() env.DbData {
|
||||
return env.DbData{}
|
||||
func (db database) DbData() env.DbData[*sql.Context] {
|
||||
return env.DbData[*sql.Context]{}
|
||||
}
|
||||
|
||||
func (db database) EditOptions() editor.Options {
|
||||
|
||||
@@ -66,7 +66,7 @@ type Database struct {
|
||||
requestedName string
|
||||
schemaName string
|
||||
ddb *doltdb.DoltDB
|
||||
rsr env.RepoStateReader
|
||||
rsr env.RepoStateReader[*sql.Context]
|
||||
rsw env.RepoStateWriter
|
||||
gs dsess.GlobalStateImpl
|
||||
editOpts editor.Options
|
||||
@@ -162,7 +162,7 @@ func (db Database) DoltDatabases() []*doltdb.DoltDB {
|
||||
}
|
||||
|
||||
// NewDatabase returns a new dolt database to use in queries.
|
||||
func NewDatabase(ctx context.Context, name string, dbData env.DbData, editOpts editor.Options) (Database, error) {
|
||||
func NewDatabase(ctx context.Context, name string, dbData env.DbData[context.Context], editOpts editor.Options) (Database, error) {
|
||||
globalState, err := dsess.NewGlobalStateStoreForDb(ctx, name, dbData.Ddb)
|
||||
if err != nil {
|
||||
return Database{}, err
|
||||
@@ -172,13 +172,25 @@ func NewDatabase(ctx context.Context, name string, dbData env.DbData, editOpts e
|
||||
baseName: name,
|
||||
requestedName: name,
|
||||
ddb: dbData.Ddb,
|
||||
rsr: dbData.Rsr,
|
||||
rsr: forwardCtxDbData{dbData.Rsr},
|
||||
rsw: dbData.Rsw,
|
||||
gs: globalState,
|
||||
editOpts: editOpts,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type forwardCtxDbData struct {
|
||||
env.RepoStateReader[context.Context]
|
||||
}
|
||||
|
||||
func (d forwardCtxDbData) CWBHeadSpec(ctx *sql.Context) (*doltdb.CommitSpec, error) {
|
||||
return d.RepoStateReader.CWBHeadSpec(ctx)
|
||||
}
|
||||
|
||||
func (d forwardCtxDbData) CWBHeadRef(ctx *sql.Context) (ref.DoltRef, error) {
|
||||
return d.RepoStateReader.CWBHeadRef(ctx)
|
||||
}
|
||||
|
||||
// initialDBState returns the InitialDbState for |db|. Other implementations of SqlDatabase outside this file should
|
||||
// implement their own method for an initial db state and not rely on this method.
|
||||
func initialDBState(ctx *sql.Context, db dsess.SqlDatabase, branch string) (dsess.InitialDbState, error) {
|
||||
@@ -228,7 +240,7 @@ func (db Database) GetDoltDB() *doltdb.DoltDB {
|
||||
}
|
||||
|
||||
// GetStateReader gets the RepoStateReader for a Database
|
||||
func (db Database) GetStateReader() env.RepoStateReader {
|
||||
func (db Database) GetStateReader() env.RepoStateReader[*sql.Context] {
|
||||
return db.rsr
|
||||
}
|
||||
|
||||
@@ -237,8 +249,8 @@ func (db Database) GetStateWriter() env.RepoStateWriter {
|
||||
return db.rsw
|
||||
}
|
||||
|
||||
func (db Database) DbData() env.DbData {
|
||||
return env.DbData{
|
||||
func (db Database) DbData() env.DbData[*sql.Context] {
|
||||
return env.DbData[*sql.Context]{
|
||||
Ddb: db.ddb,
|
||||
Rsw: db.rsw,
|
||||
Rsr: db.rsr,
|
||||
@@ -773,7 +785,7 @@ func workingSetStagedRoot(ctx *sql.Context, dbName string) (doltdb.RootValue, er
|
||||
|
||||
// resolveAsOf resolves given expression to a commit, if one exists.
|
||||
func resolveAsOf(ctx *sql.Context, db Database, asOf interface{}) (*doltdb.Commit, doltdb.RootValue, error) {
|
||||
head, err := db.rsr.CWBHeadRef()
|
||||
head, err := db.rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -1107,7 +1107,7 @@ func isValidCommitHash(ctx *sql.Context, db dsess.SqlDatabase, commitHash string
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func initialDbState(ctx context.Context, db dsess.SqlDatabase, branch string) (dsess.InitialDbState, error) {
|
||||
func initialDbState(ctx *sql.Context, db dsess.SqlDatabase, branch string) (dsess.InitialDbState, error) {
|
||||
rsr := db.DbData().Rsr
|
||||
ddb := db.DbData().Ddb
|
||||
|
||||
@@ -1116,7 +1116,7 @@ func initialDbState(ctx context.Context, db dsess.SqlDatabase, branch string) (d
|
||||
r = ref.NewBranchRef(branch)
|
||||
} else {
|
||||
var err error
|
||||
r, err = rsr.CWBHeadRef()
|
||||
r, err = rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return dsess.InitialDbState{}, err
|
||||
}
|
||||
@@ -1393,7 +1393,7 @@ func (p *DoltDatabaseProvider) SessionDatabase(ctx *sql.Context, name string) (d
|
||||
if !ok {
|
||||
usingDefaultBranch = true
|
||||
|
||||
head, err = dsess.DefaultHead(baseName, db)
|
||||
head, err = dsess.DefaultHead(ctx, baseName, db)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
@@ -1596,7 +1596,7 @@ func initialStateForBranchDb(ctx *sql.Context, srcDb dsess.SqlDatabase) (dsess.I
|
||||
Db: srcDb,
|
||||
HeadCommit: cm,
|
||||
WorkingSet: ws,
|
||||
DbData: env.DbData{
|
||||
DbData: env.DbData[*sql.Context]{
|
||||
Ddb: srcDb.DbData().Ddb,
|
||||
Rsw: static,
|
||||
Rsr: static,
|
||||
@@ -1636,7 +1636,7 @@ func initialStateForTagDb(ctx context.Context, srcDb ReadOnlyDatabase) (dsess.In
|
||||
Db: srcDb,
|
||||
HeadCommit: cm,
|
||||
ReadOnly: true,
|
||||
DbData: env.DbData{
|
||||
DbData: env.DbData[*sql.Context]{
|
||||
Ddb: srcDb.DbData().Ddb,
|
||||
Rsw: srcDb.DbData().Rsw,
|
||||
Rsr: srcDb.DbData().Rsr,
|
||||
@@ -1666,7 +1666,7 @@ func revisionDbForCommit(ctx context.Context, srcDb Database, revSpec string, re
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func initialStateForCommit(ctx context.Context, srcDb ReadOnlyDatabase) (dsess.InitialDbState, error) {
|
||||
func initialStateForCommit(ctx *sql.Context, srcDb ReadOnlyDatabase) (dsess.InitialDbState, error) {
|
||||
revSpec := srcDb.Revision()
|
||||
|
||||
spec, err := doltdb.NewCommitSpec(revSpec)
|
||||
@@ -1674,7 +1674,7 @@ func initialStateForCommit(ctx context.Context, srcDb ReadOnlyDatabase) (dsess.I
|
||||
return dsess.InitialDbState{}, err
|
||||
}
|
||||
|
||||
headRef, err := srcDb.DbData().Rsr.CWBHeadRef()
|
||||
headRef, err := srcDb.DbData().Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return dsess.InitialDbState{}, err
|
||||
}
|
||||
@@ -1691,7 +1691,7 @@ func initialStateForCommit(ctx context.Context, srcDb ReadOnlyDatabase) (dsess.I
|
||||
Db: srcDb,
|
||||
HeadCommit: cm,
|
||||
ReadOnly: true,
|
||||
DbData: env.DbData{
|
||||
DbData: env.DbData[*sql.Context]{
|
||||
Ddb: srcDb.DbData().Ddb,
|
||||
Rsw: srcDb.DbData().Rsw,
|
||||
Rsr: srcDb.DbData().Rsr,
|
||||
@@ -1710,10 +1710,10 @@ func initialStateForCommit(ctx context.Context, srcDb ReadOnlyDatabase) (dsess.I
|
||||
type staticRepoState struct {
|
||||
branch ref.DoltRef
|
||||
env.RepoStateWriter
|
||||
env.RepoStateReader
|
||||
env.RepoStateReader[*sql.Context]
|
||||
}
|
||||
|
||||
func (s staticRepoState) CWBHeadRef() (ref.DoltRef, error) {
|
||||
func (s staticRepoState) CWBHeadRef(*sql.Context) (ref.DoltRef, error) {
|
||||
return s.branch, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ func resolveRefSpecs(ctx *sql.Context, leftSpec, rightSpec string) (left, right
|
||||
return nil, nil, sql.ErrDatabaseNotFound.New(dbName)
|
||||
}
|
||||
|
||||
headRef, err := dbData.Rsr.CWBHeadRef()
|
||||
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/errhand"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/branch_control"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dbfactory"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env/actions"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
@@ -113,7 +114,7 @@ func doDoltBackup(ctx *sql.Context, args []string) (int, error) {
|
||||
return statusOk, nil
|
||||
}
|
||||
|
||||
func addBackup(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResults) error {
|
||||
func addBackup(ctx *sql.Context, dbData env.DbData[*sql.Context], apr *argparser.ArgParseResults) error {
|
||||
if apr.NArg() != 3 {
|
||||
return fmt.Errorf("usage: dolt_backup('add', 'backup_name', 'backup-url')")
|
||||
}
|
||||
@@ -152,7 +153,7 @@ func addBackup(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResul
|
||||
}
|
||||
}
|
||||
|
||||
func restoreBackup(ctx *sql.Context, _ env.DbData, apr *argparser.ArgParseResults) error {
|
||||
func restoreBackup(ctx *sql.Context, _ env.DbData[*sql.Context], apr *argparser.ArgParseResults) error {
|
||||
if apr.NArg() != 3 {
|
||||
return fmt.Errorf("usage: dolt_backup('restore', 'backup_url', 'database_name')")
|
||||
}
|
||||
@@ -217,7 +218,7 @@ func restoreBackup(ctx *sql.Context, _ env.DbData, apr *argparser.ArgParseResult
|
||||
}
|
||||
}
|
||||
|
||||
func removeBackup(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResults) error {
|
||||
func removeBackup(ctx *sql.Context, dbData env.DbData[*sql.Context], apr *argparser.ArgParseResults) error {
|
||||
if apr.NArg() != 2 {
|
||||
return fmt.Errorf("usage: dolt_backup('remove', 'backup_name')")
|
||||
}
|
||||
@@ -276,7 +277,7 @@ func loadAwsParams(ctx *sql.Context, sess *dsess.DoltSession, apr *argparser.Arg
|
||||
return params, nil
|
||||
}
|
||||
|
||||
func syncBackupViaUrl(ctx *sql.Context, dbData env.DbData, sess *dsess.DoltSession, apr *argparser.ArgParseResults) error {
|
||||
func syncBackupViaUrl(ctx *sql.Context, dbData env.DbData[*sql.Context], sess *dsess.DoltSession, apr *argparser.ArgParseResults) error {
|
||||
if apr.NArg() != 2 {
|
||||
return fmt.Errorf("usage: dolt_backup('sync-url', BACKUP_URL)")
|
||||
}
|
||||
@@ -292,7 +293,7 @@ func syncBackupViaUrl(ctx *sql.Context, dbData env.DbData, sess *dsess.DoltSessi
|
||||
return syncRootsToBackup(ctx, dbData, sess, b)
|
||||
}
|
||||
|
||||
func syncBackupViaName(ctx *sql.Context, dbData env.DbData, sess *dsess.DoltSession, apr *argparser.ArgParseResults) error {
|
||||
func syncBackupViaName(ctx *sql.Context, dbData env.DbData[*sql.Context], sess *dsess.DoltSession, apr *argparser.ArgParseResults) error {
|
||||
if apr.NArg() != 2 {
|
||||
return fmt.Errorf("usage: dolt_backup('sync', BACKUP_NAME)")
|
||||
}
|
||||
@@ -312,7 +313,7 @@ func syncBackupViaName(ctx *sql.Context, dbData env.DbData, sess *dsess.DoltSess
|
||||
}
|
||||
|
||||
// syncRootsToBackup syncs the roots from |dbData| to the backup specified by |backup|.
|
||||
func syncRootsToBackup(ctx *sql.Context, dbData env.DbData, sess *dsess.DoltSession, backup env.Remote) error {
|
||||
func syncRootsToBackup(ctx *sql.Context, dbData env.DbData[*sql.Context], sess *dsess.DoltSession, backup env.Remote) error {
|
||||
destDb, err := sess.Provider().GetRemoteDB(ctx, dbData.Ddb.ValueReadWriter().Format(), backup, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading backup destination: %w", err)
|
||||
@@ -332,7 +333,7 @@ func syncRootsToBackup(ctx *sql.Context, dbData env.DbData, sess *dsess.DoltSess
|
||||
}
|
||||
|
||||
// syncRootsFromBackup syncs the roots from the backup specified by |backup| to |dbData|.
|
||||
func syncRootsFromBackup(ctx *sql.Context, dbData env.DbData, sess *dsess.DoltSession, backup env.Remote) error {
|
||||
func syncRootsFromBackup[C doltdb.Context](ctx *sql.Context, dbData env.DbData[C], sess *dsess.DoltSession, backup env.Remote) error {
|
||||
destDb, err := sess.Provider().GetRemoteDB(ctx, dbData.Ddb.ValueReadWriter().Format(), backup, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading backup destination: %w", err)
|
||||
|
||||
@@ -111,7 +111,7 @@ func commitTransaction(ctx *sql.Context, dSess *dsess.DoltSession, rsc *doltdb.R
|
||||
|
||||
// renameBranch takes DoltSession and database name to try accessing file system for dolt database.
|
||||
// If the oldBranch being renamed is the current branch on CLI, then RepoState head will be updated with the newBranch ref.
|
||||
func renameBranch(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResults, sess *dsess.DoltSession, dbName string, rsc *doltdb.ReplicationStatusController) error {
|
||||
func renameBranch(ctx *sql.Context, dbData env.DbData[*sql.Context], apr *argparser.ArgParseResults, sess *dsess.DoltSession, dbName string, rsc *doltdb.ReplicationStatusController) error {
|
||||
if apr.NArg() != 2 {
|
||||
return InvalidArgErr
|
||||
}
|
||||
@@ -151,7 +151,7 @@ func renameBranch(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseRe
|
||||
return err
|
||||
}
|
||||
|
||||
headRef, err := dbData.Rsr.CWBHeadRef()
|
||||
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -201,7 +201,7 @@ func renameBranch(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseRe
|
||||
// deleteBranches takes DoltSession and database name to try accessing file system for dolt database.
|
||||
// If the database is not session state db and the branch being deleted is the current branch on CLI, it will update
|
||||
// the RepoState to set head as empty branchRef.
|
||||
func deleteBranches(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResults, sess *dsess.DoltSession, dbName string, rsc *doltdb.ReplicationStatusController) error {
|
||||
func deleteBranches(ctx *sql.Context, dbData env.DbData[*sql.Context], apr *argparser.ArgParseResults, sess *dsess.DoltSession, dbName string, rsc *doltdb.ReplicationStatusController) error {
|
||||
if apr.NArg() == 0 {
|
||||
return InvalidArgErr
|
||||
}
|
||||
@@ -348,7 +348,7 @@ func loadConfig(ctx *sql.Context) *env.DoltCliConfig {
|
||||
return dEnv.Config
|
||||
}
|
||||
|
||||
func createNewBranch(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResults, rsc *doltdb.ReplicationStatusController) error {
|
||||
func createNewBranch(ctx *sql.Context, dbData env.DbData[*sql.Context], apr *argparser.ArgParseResults, rsc *doltdb.ReplicationStatusController) error {
|
||||
if apr.NArg() == 0 || apr.NArg() > 2 {
|
||||
return InvalidArgErr
|
||||
}
|
||||
@@ -422,7 +422,7 @@ func createNewBranch(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgPars
|
||||
return nil
|
||||
}
|
||||
|
||||
func copyBranch(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResults, rsc *doltdb.ReplicationStatusController) error {
|
||||
func copyBranch(ctx *sql.Context, dbData env.DbData[*sql.Context], apr *argparser.ArgParseResults, rsc *doltdb.ReplicationStatusController) error {
|
||||
if apr.NArg() != 2 {
|
||||
return InvalidArgErr
|
||||
}
|
||||
@@ -441,7 +441,7 @@ func copyBranch(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResu
|
||||
return copyABranch(ctx, dbData, srcBr, destBr, force, rsc)
|
||||
}
|
||||
|
||||
func copyABranch(ctx *sql.Context, dbData env.DbData, srcBr string, destBr string, force bool, rsc *doltdb.ReplicationStatusController) error {
|
||||
func copyABranch(ctx *sql.Context, dbData env.DbData[*sql.Context], srcBr string, destBr string, force bool, rsc *doltdb.ReplicationStatusController) error {
|
||||
if err := branch_control.CanCreateBranch(ctx, destBr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ func doDoltCheckout(ctx *sql.Context, args []string) (statusCode int, successMes
|
||||
return 1, "", ErrEmptyBranchName
|
||||
}
|
||||
|
||||
isModification, err := willModifyDb(dSess, dbData, currentDbName, branchName, updateHead)
|
||||
isModification, err := willModifyDb(ctx, dSess, dbData, currentDbName, branchName, updateHead)
|
||||
if err != nil {
|
||||
return 1, "", err
|
||||
}
|
||||
@@ -188,7 +188,7 @@ func doDoltCheckout(ctx *sql.Context, args []string) (statusCode int, successMes
|
||||
|
||||
// Check if the user executed `dolt checkout .`
|
||||
if apr.NArg() == 1 && apr.Arg(0) == "." {
|
||||
headRef, err := dbData.Rsr.CWBHeadRef()
|
||||
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return 1, "", err
|
||||
}
|
||||
@@ -301,7 +301,7 @@ func createWorkingSetForLocalBranch(ctx *sql.Context, ddb *doltdb.DoltDB, branch
|
||||
|
||||
// checkoutRemoteBranch checks out a remote branch creating a new local branch with the same name as the remote branch
|
||||
// and set its upstream. The upstream persists out of sql session. Returns the name of the upstream remote and branch.
|
||||
func checkoutRemoteBranch(ctx *sql.Context, dSess *dsess.DoltSession, dbName string, dbData env.DbData, branchName string, apr *argparser.ArgParseResults, rsc *doltdb.ReplicationStatusController) (upstream string, err error) {
|
||||
func checkoutRemoteBranch(ctx *sql.Context, dSess *dsess.DoltSession, dbName string, dbData env.DbData[*sql.Context], branchName string, apr *argparser.ArgParseResults, rsc *doltdb.ReplicationStatusController) (upstream string, err error) {
|
||||
remoteRefs, err := actions.GetRemoteBranchRef(ctx, dbData.Ddb, branchName)
|
||||
if err != nil {
|
||||
return "", errors.New("fatal: unable to read from data repository")
|
||||
@@ -365,7 +365,7 @@ func checkoutRemoteBranch(ctx *sql.Context, dSess *dsess.DoltSession, dbName str
|
||||
return "", errhand.BuildDError("%s: '%s'", err.Error(), remoteRef.GetRemote()).Build()
|
||||
}
|
||||
|
||||
headRef, err := dbData.Rsr.CWBHeadRef()
|
||||
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -384,7 +384,7 @@ func checkoutRemoteBranch(ctx *sql.Context, dSess *dsess.DoltSession, dbName str
|
||||
// checkoutNewBranch creates a new branch and makes it the active branch for the session.
|
||||
// If isMove is true, this function also moves the working set from the current branch into the new branch.
|
||||
// Returns the name of the new branch and the remote upstream branch (empty string if not applicable.)
|
||||
func checkoutNewBranch(ctx *sql.Context, dbName string, dbData env.DbData, apr *argparser.ArgParseResults, rsc *doltdb.ReplicationStatusController, isMove bool) (newBranchName string, remoteAndBranch string, err error) {
|
||||
func checkoutNewBranch(ctx *sql.Context, dbName string, dbData env.DbData[*sql.Context], apr *argparser.ArgParseResults, rsc *doltdb.ReplicationStatusController, isMove bool) (newBranchName string, remoteAndBranch string, err error) {
|
||||
var remoteName, remoteBranchName string
|
||||
var startPt = "head"
|
||||
var refSpec ref.RefSpec
|
||||
|
||||
@@ -192,8 +192,8 @@ func transferWorkingChanges(
|
||||
}
|
||||
|
||||
// willModifyDb determines whether or not this operation is a no-op and can return early with a helpful message.
|
||||
func willModifyDb(dSess *dsess.DoltSession, data env.DbData, dbName, branchName string, updateHead bool) (bool, error) {
|
||||
headRef, err := data.Rsr.CWBHeadRef()
|
||||
func willModifyDb(ctx *sql.Context, dSess *dsess.DoltSession, data env.DbData[*sql.Context], dbName, branchName string, updateHead bool) (bool, error) {
|
||||
headRef, err := data.Rsr.CWBHeadRef(ctx)
|
||||
// If we're in a detached head state, allow checking out a new branch.
|
||||
if err == doltdb.ErrOperationNotSupportedInDetachedHead {
|
||||
return true, nil
|
||||
|
||||
@@ -73,7 +73,7 @@ func countCommits(ctx *sql.Context, args ...string) (ahead uint64, behind uint64
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
headRef, err := rsr.CWBHeadRef()
|
||||
headRef, err := rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ func doDoltMerge(ctx *sql.Context, args []string) (string, int, int, string, err
|
||||
return "", noConflictsOrViolations, threeWayMerge, "", fmt.Errorf("Could not load database %s", dbName)
|
||||
}
|
||||
|
||||
headRef, err := dbData.Rsr.CWBHeadRef()
|
||||
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return "", noConflictsOrViolations, threeWayMerge, "", err
|
||||
}
|
||||
@@ -333,7 +333,7 @@ func executeMerge(
|
||||
return mergeRootToWorking(ctx, sess, dbName, squash, force, ws, result, workingDiffs, cm, cmSpec)
|
||||
}
|
||||
|
||||
func executeFFMerge(ctx *sql.Context, dbName string, squash bool, ws *doltdb.WorkingSet, dbData env.DbData, cm2 *doltdb.Commit, spec *merge.MergeSpec) (*doltdb.WorkingSet, error) {
|
||||
func executeFFMerge(ctx *sql.Context, dbName string, squash bool, ws *doltdb.WorkingSet, dbData env.DbData[*sql.Context], cm2 *doltdb.Commit, spec *merge.MergeSpec) (*doltdb.WorkingSet, error) {
|
||||
stagedRoot, err := cm2.GetRootValue(ctx)
|
||||
if err != nil {
|
||||
return ws, err
|
||||
@@ -349,7 +349,7 @@ func executeFFMerge(ctx *sql.Context, dbName string, squash bool, ws *doltdb.Wor
|
||||
// TODO: This is all incredibly suspect, needs to be replaced with library code that is functional instead of
|
||||
// altering global state
|
||||
if !squash {
|
||||
headRef, err := dbData.Rsr.CWBHeadRef()
|
||||
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ func doDoltPull(ctx *sql.Context, args []string) (int, int, string, error) {
|
||||
|
||||
rsSeen = true
|
||||
|
||||
headRef, err := dbData.Rsr.CWBHeadRef()
|
||||
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return noConflictsOrViolations, threeWayMerge, "", err
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ func doDoltPush(ctx *sql.Context, args []string) (int, string, error) {
|
||||
}
|
||||
|
||||
var returnMsg string
|
||||
po := &env.PushOptions{
|
||||
po := &env.PushOptions[*sql.Context]{
|
||||
Targets: targets,
|
||||
Remote: remote,
|
||||
Rsr: dbData.Rsr,
|
||||
|
||||
@@ -84,7 +84,7 @@ func doDoltRemote(ctx *sql.Context, args []string) (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func addRemote(_ *sql.Context, dbName string, dbd env.DbData, apr *argparser.ArgParseResults, sess *dsess.DoltSession) error {
|
||||
func addRemote(_ *sql.Context, dbName string, dbd env.DbData[*sql.Context], apr *argparser.ArgParseResults, sess *dsess.DoltSession) error {
|
||||
if apr.NArg() != 3 {
|
||||
return fmt.Errorf("error: invalid argument")
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func addRemote(_ *sql.Context, dbName string, dbd env.DbData, apr *argparser.Arg
|
||||
return dbd.Rsw.AddRemote(r)
|
||||
}
|
||||
|
||||
func removeRemote(ctx *sql.Context, dbd env.DbData, apr *argparser.ArgParseResults, rsc *doltdb.ReplicationStatusController) error {
|
||||
func removeRemote(ctx *sql.Context, dbd env.DbData[*sql.Context], apr *argparser.ArgParseResults, rsc *doltdb.ReplicationStatusController) error {
|
||||
if apr.NArg() != 2 {
|
||||
return fmt.Errorf("error: invalid argument")
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ func doDoltReset(ctx *sql.Context, args []string) (int, error) {
|
||||
// resetSoftToRef resets the session HEAD to the commit ref given
|
||||
func resetSoftToRef(
|
||||
ctx *sql.Context,
|
||||
dbData env.DbData,
|
||||
dbData env.DbData[*sql.Context],
|
||||
firstArg string,
|
||||
dSess *dsess.DoltSession,
|
||||
dbName string,
|
||||
@@ -202,7 +202,7 @@ func resetSoftTables(
|
||||
func resetSoft(
|
||||
ctx *sql.Context,
|
||||
apr *argparser.ArgParseResults,
|
||||
dbData env.DbData,
|
||||
dbData env.DbData[*sql.Context],
|
||||
dSess *dsess.DoltSession,
|
||||
dbName string,
|
||||
) error {
|
||||
@@ -237,7 +237,7 @@ func resetHard(
|
||||
ctx *sql.Context,
|
||||
apr *argparser.ArgParseResults,
|
||||
roots doltdb.Roots,
|
||||
dbData env.DbData,
|
||||
dbData env.DbData[*sql.Context],
|
||||
dSess *dsess.DoltSession,
|
||||
dbName string,
|
||||
) error {
|
||||
@@ -258,7 +258,7 @@ func resetHard(
|
||||
|
||||
// TODO: this overrides the transaction setting, needs to happen at commit, not here
|
||||
if newHead != nil {
|
||||
headRef, err := dbData.Rsr.CWBHeadRef()
|
||||
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ func doDoltTag(ctx *sql.Context, args []string) (int, error) {
|
||||
if len(apr.Args) > 1 {
|
||||
startPoint = apr.Arg(1)
|
||||
}
|
||||
headRef, err := dbData.Rsr.CWBHeadRef()
|
||||
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ type InitialDbState struct {
|
||||
// HeadRoot is the root value for databases without a HeadCommit. Nil for databases with a HeadCommit.
|
||||
HeadRoot doltdb.RootValue
|
||||
ReadOnly bool
|
||||
DbData env.DbData
|
||||
DbData env.DbData[*sql.Context]
|
||||
Remotes *concurrentmap.Map[string, env.Remote]
|
||||
Branches *concurrentmap.Map[string, env.BranchConfig]
|
||||
Backups *concurrentmap.Map[string, env.Remote]
|
||||
@@ -117,7 +117,7 @@ type branchState struct {
|
||||
// case headCommit must be set
|
||||
workingSet *doltdb.WorkingSet
|
||||
// dbData is an accessor for the underlying doltDb
|
||||
dbData env.DbData
|
||||
dbData env.DbData[*sql.Context]
|
||||
// writeSession is this head's write session
|
||||
writeSession WriteSession
|
||||
// readOnly is true if this database is read only
|
||||
|
||||
@@ -268,7 +268,7 @@ func (d *DoltSession) RemoveBranchState(ctx *sql.Context, dbName string, branchN
|
||||
return sql.ErrDatabaseNotFound.New(baseName)
|
||||
}
|
||||
|
||||
defaultHead, err := DefaultHead(baseName, db)
|
||||
defaultHead, err := DefaultHead(ctx, baseName, db)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -961,13 +961,13 @@ func (d *DoltSession) GetDoltDB(ctx *sql.Context, dbName string) (*doltdb.DoltDB
|
||||
return branchState.dbData.Ddb, true
|
||||
}
|
||||
|
||||
func (d *DoltSession) GetDbData(ctx *sql.Context, dbName string) (env.DbData, bool) {
|
||||
func (d *DoltSession) GetDbData(ctx *sql.Context, dbName string) (env.DbData[*sql.Context], bool) {
|
||||
branchState, ok, err := d.lookupDbState(ctx, dbName)
|
||||
if err != nil {
|
||||
return env.DbData{}, false
|
||||
return env.DbData[*sql.Context]{}, false
|
||||
}
|
||||
if !ok {
|
||||
return env.DbData{}, false
|
||||
return env.DbData[*sql.Context]{}, false
|
||||
}
|
||||
|
||||
return branchState.dbData, true
|
||||
@@ -1375,7 +1375,7 @@ func (d *DoltSession) addDB(ctx *sql.Context, db SqlDatabase) error {
|
||||
|
||||
// The checkedOutRevSpec should be the checked out branch of the database if available, or the revision
|
||||
// string otherwise
|
||||
sessionState.checkedOutRevSpec, err = DefaultHead(baseName, baseDb)
|
||||
sessionState.checkedOutRevSpec, err = DefaultHead(ctx, baseName, baseDb)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -2018,7 +2018,7 @@ func TransactionRoot(ctx *sql.Context, db SqlDatabase) (hash.Hash, error) {
|
||||
}
|
||||
|
||||
// DefaultHead returns the head for the database given when one isn't specified
|
||||
func DefaultHead(baseName string, db SqlDatabase) (string, error) {
|
||||
func DefaultHead(ctx *sql.Context, baseName string, db SqlDatabase) (string, error) {
|
||||
head := ""
|
||||
|
||||
// First check the global variable for the default branch
|
||||
@@ -2038,7 +2038,7 @@ func DefaultHead(baseName string, db SqlDatabase) (string, error) {
|
||||
if head == "" {
|
||||
rsr := db.DbData().Rsr
|
||||
if rsr != nil {
|
||||
headRef, err := rsr.CWBHeadRef()
|
||||
headRef, err := rsr.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ type DoltDatabaseProvider interface {
|
||||
}
|
||||
|
||||
type SessionDatabaseBranchSpec struct {
|
||||
RepoState env.RepoStateReadWriter
|
||||
RepoState env.RepoStateReadWriter[*sql.Context]
|
||||
Branch string
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ type SqlDatabase interface {
|
||||
// TODO: get rid of this, it's managed by the session, not the DB
|
||||
GetRoot(*sql.Context) (doltdb.RootValue, error)
|
||||
// TODO: remove ddb from the below, it's separable and is 95% of the uses of this method
|
||||
DbData() env.DbData
|
||||
DbData() env.DbData[*sql.Context]
|
||||
// DoltDatabases returns all underlying DoltDBs for this database.
|
||||
DoltDatabases() []*doltdb.DoltDB
|
||||
// Schema returns the schema of the database.
|
||||
|
||||
@@ -41,9 +41,9 @@ func (s SessionStateAdapter) SetCWBHeadRef(ctx context.Context, newRef ref.Marsh
|
||||
return fmt.Errorf("Cannot set cwb head ref with a SessionStateAdapter")
|
||||
}
|
||||
|
||||
var _ env.RepoStateReader = SessionStateAdapter{}
|
||||
var _ env.RepoStateReader[*sql.Context] = SessionStateAdapter{}
|
||||
var _ env.RepoStateWriter = SessionStateAdapter{}
|
||||
var _ env.RootsProvider = SessionStateAdapter{}
|
||||
var _ env.RootsProvider[*sql.Context] = SessionStateAdapter{}
|
||||
|
||||
func NewSessionStateAdapter(session *DoltSession, dbName string, remotes *concurrentmap.Map[string, env.Remote], branches *concurrentmap.Map[string, env.BranchConfig], backups *concurrentmap.Map[string, env.Remote]) SessionStateAdapter {
|
||||
if branches == nil {
|
||||
@@ -52,9 +52,8 @@ func NewSessionStateAdapter(session *DoltSession, dbName string, remotes *concur
|
||||
return SessionStateAdapter{session: session, dbName: dbName, remotes: remotes, branches: branches, backups: backups}
|
||||
}
|
||||
|
||||
func (s SessionStateAdapter) GetRoots(ctx context.Context) (doltdb.Roots, error) {
|
||||
sqlCtx := sql.NewContext(ctx)
|
||||
state, _, err := s.session.lookupDbState(sqlCtx, s.dbName)
|
||||
func (s SessionStateAdapter) GetRoots(ctx *sql.Context) (doltdb.Roots, error) {
|
||||
state, _, err := s.session.lookupDbState(ctx, s.dbName)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
@@ -62,8 +61,8 @@ func (s SessionStateAdapter) GetRoots(ctx context.Context) (doltdb.Roots, error)
|
||||
return state.roots(), nil
|
||||
}
|
||||
|
||||
func (s SessionStateAdapter) CWBHeadRef() (ref.DoltRef, error) {
|
||||
workingSet, err := s.session.WorkingSet(sql.NewContext(context.Background()), s.dbName)
|
||||
func (s SessionStateAdapter) CWBHeadRef(ctx *sql.Context) (ref.DoltRef, error) {
|
||||
workingSet, err := s.session.WorkingSet(ctx, s.dbName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -75,9 +74,9 @@ func (s SessionStateAdapter) CWBHeadRef() (ref.DoltRef, error) {
|
||||
return headRef, nil
|
||||
}
|
||||
|
||||
func (s SessionStateAdapter) CWBHeadSpec() (*doltdb.CommitSpec, error) {
|
||||
func (s SessionStateAdapter) CWBHeadSpec(ctx *sql.Context) (*doltdb.CommitSpec, error) {
|
||||
// TODO: get rid of this
|
||||
ref, err := s.CWBHeadRef()
|
||||
ref, err := s.CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -484,7 +484,7 @@ type patchNode struct {
|
||||
dataPatchStmts []string
|
||||
}
|
||||
|
||||
func getPatchNodes(ctx *sql.Context, dbData env.DbData, tableDeltas []diff.TableDelta, fromRefDetails, toRefDetails *refDetails, includeSchemaDiff, includeDataDiff bool) (patches []*patchNode, err error) {
|
||||
func getPatchNodes(ctx *sql.Context, dbData env.DbData[*sql.Context], tableDeltas []diff.TableDelta, fromRefDetails, toRefDetails *refDetails, includeSchemaDiff, includeDataDiff bool) (patches []*patchNode, err error) {
|
||||
for _, td := range tableDeltas {
|
||||
if td.FromTable == nil && td.ToTable == nil {
|
||||
// no diff
|
||||
@@ -557,7 +557,7 @@ func canGetDataDiff(ctx *sql.Context, td diff.TableDelta) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func getUserTableDataSqlPatch(ctx *sql.Context, dbData env.DbData, td diff.TableDelta, fromRefDetails, toRefDetails *refDetails) ([]string, error) {
|
||||
func getUserTableDataSqlPatch(ctx *sql.Context, dbData env.DbData[*sql.Context], td diff.TableDelta, fromRefDetails, toRefDetails *refDetails) ([]string, error) {
|
||||
// ToTable is used as target table as it cannot be nil at this point
|
||||
diffSch, projections, ri, err := getDiffQuery(ctx, dbData, td, fromRefDetails, toRefDetails)
|
||||
if err != nil {
|
||||
@@ -622,7 +622,7 @@ func getDataSqlPatchResults(ctx *sql.Context, diffQuerySch, targetSch sql.Schema
|
||||
// on diff table function row iter. This function attempts to imitate running a query
|
||||
// fmt.Sprintf("select %s, %s from dolt_diff('%s', '%s', '%s')", columnsWithDiff, "diff_type", fromRef, toRef, tableName)
|
||||
// on sql engine, which returns the schema and rowIter of the final data diff result.
|
||||
func getDiffQuery(ctx *sql.Context, dbData env.DbData, td diff.TableDelta, fromRefDetails, toRefDetails *refDetails) (sql.Schema, []sql.Expression, sql.RowIter, error) {
|
||||
func getDiffQuery(ctx *sql.Context, dbData env.DbData[*sql.Context], td diff.TableDelta, fromRefDetails, toRefDetails *refDetails) (sql.Schema, []sql.Expression, sql.RowIter, error) {
|
||||
diffTableSchema, j, err := dtables.GetDiffTableSchemaAndJoiner(td.ToTable.Format(), td.FromSch, td.ToSch)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
|
||||
@@ -35,7 +35,7 @@ type StatusTable struct {
|
||||
tableName string
|
||||
ddb *doltdb.DoltDB
|
||||
workingSet *doltdb.WorkingSet
|
||||
rootsProvider env.RootsProvider
|
||||
rootsProvider env.RootsProvider[*sql.Context]
|
||||
}
|
||||
|
||||
var _ sql.StatisticsTable = (*StatusTable)(nil)
|
||||
@@ -90,7 +90,7 @@ func (st StatusTable) PartitionRows(context *sql.Context, _ sql.Partition) (sql.
|
||||
}
|
||||
|
||||
// NewStatusTable creates a StatusTable
|
||||
func NewStatusTable(_ *sql.Context, tableName string, ddb *doltdb.DoltDB, ws *doltdb.WorkingSet, rp env.RootsProvider) sql.Table {
|
||||
func NewStatusTable(_ *sql.Context, tableName string, ddb *doltdb.DoltDB, ws *doltdb.WorkingSet, rp env.RootsProvider[*sql.Context]) sql.Table {
|
||||
return &StatusTable{
|
||||
tableName: tableName,
|
||||
ddb: ddb,
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
dsqle "github.com/dolthub/dolt/go/libraries/doltcore/sqle"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
@@ -173,11 +174,11 @@ func drainIter(ctx *sql.Context, iter sql.RowIter) error {
|
||||
func getDbState(t *testing.T, db sql.Database, dEnv *env.DoltEnv) (dsess.InitialDbState, error) {
|
||||
ctx := context.Background()
|
||||
|
||||
headSpec, err := dEnv.RepoStateReader().CWBHeadSpec()
|
||||
headSpec, err := dEnv.RepoStateReader().CWBHeadSpec(ctx)
|
||||
if err != nil {
|
||||
return dsess.InitialDbState{}, err
|
||||
}
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
|
||||
if err != nil {
|
||||
return dsess.InitialDbState{}, err
|
||||
}
|
||||
@@ -194,7 +195,23 @@ func getDbState(t *testing.T, db sql.Database, dEnv *env.DoltEnv) (dsess.Initial
|
||||
Db: db,
|
||||
HeadCommit: headCommit,
|
||||
WorkingSet: ws,
|
||||
DbData: dEnv.DbData(ctx),
|
||||
Remotes: dEnv.RepoState.Remotes,
|
||||
DbData: env.DbData[*sql.Context]{
|
||||
Ddb: dEnv.DoltDB(ctx),
|
||||
Rsr: forwardCtxDbData{dEnv.DbData(ctx).Rsr},
|
||||
Rsw: dEnv.DbData(ctx).Rsw,
|
||||
},
|
||||
Remotes: dEnv.RepoState.Remotes,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type forwardCtxDbData struct {
|
||||
env.RepoStateReader[context.Context]
|
||||
}
|
||||
|
||||
func (d forwardCtxDbData) CWBHeadSpec(ctx *sql.Context) (*doltdb.CommitSpec, error) {
|
||||
return d.RepoStateReader.CWBHeadSpec(ctx)
|
||||
}
|
||||
|
||||
func (d forwardCtxDbData) CWBHeadRef(ctx *sql.Context) (ref.DoltRef, error) {
|
||||
return d.RepoStateReader.CWBHeadRef(ctx)
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ func NewTestEngine(dEnv *env.DoltEnv, ctx context.Context, db dsess.SqlDatabase)
|
||||
|
||||
// ExecuteSelect executes the select statement given and returns the resulting rows, or an error if one is encountered.
|
||||
func ExecuteSelect(ctx context.Context, dEnv *env.DoltEnv, root doltdb.RootValue, query string) ([]sql.Row, error) {
|
||||
dbData := env.DbData{
|
||||
dbData := env.DbData[context.Context]{
|
||||
Ddb: dEnv.DoltDB(ctx),
|
||||
Rsw: dEnv.RepoStateWriter(),
|
||||
Rsr: dEnv.RepoStateReader(),
|
||||
|
||||
@@ -89,7 +89,7 @@ func (db *UserSpaceDatabase) InitialDBState(ctx *sql.Context) (dsess.InitialDbSt
|
||||
Db: db,
|
||||
ReadOnly: true,
|
||||
HeadRoot: db.RootValue,
|
||||
DbData: env.DbData{
|
||||
DbData: env.DbData[*sql.Context]{
|
||||
Rsw: noopRepoStateWriter{},
|
||||
},
|
||||
Remotes: concurrentmap.New[string, env.Remote](),
|
||||
@@ -113,8 +113,8 @@ func (db *UserSpaceDatabase) GetTemporaryTablesRoot(*sql.Context) (doltdb.RootVa
|
||||
panic("UserSpaceDatabase should not contain any temporary tables")
|
||||
}
|
||||
|
||||
func (db *UserSpaceDatabase) DbData() env.DbData {
|
||||
return env.DbData{}
|
||||
func (db *UserSpaceDatabase) DbData() env.DbData[*sql.Context] {
|
||||
return env.DbData[*sql.Context]{}
|
||||
}
|
||||
|
||||
func (db *UserSpaceDatabase) EditOptions() editor.Options {
|
||||
|
||||
Reference in New Issue
Block a user