Skip to content

Commit 5f03823

Browse files
authored
Merge pull request #9151 from dolthub/aaron/sql-ctx-cleanup
go: Thread Context a bit. Cleanup some uses of sql.NewContext.
2 parents 94a11de + abe1522 commit 5f03823

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+310
-289
lines changed

go/cmd/dolt/commands/archive.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func historicalFuzzyMatching(ctx context.Context, heads hash.HashSet, groupings
228228
hs = append(hs, h)
229229
}
230230

231-
iterator, err := commitwalk.GetTopologicalOrderIterator(ctx, db, hs, func(cmt *doltdb.OptionalCommit) (bool, error) {
231+
iterator, err := commitwalk.GetTopologicalOrderIterator[context.Context](ctx, db, hs, func(cmt *doltdb.OptionalCommit) (bool, error) {
232232
return true, nil
233233
})
234234
if err != nil {

go/cmd/dolt/commands/filter-branch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func getNerf(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgParseResu
258258
return nil, err
259259
}
260260

261-
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
261+
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
262262
if err != nil {
263263
return nil, err
264264
}

go/cmd/dolt/commands/schcmds/copy-tags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func doltCommitUpdatedTags(ctx context.Context, dEnv *env.DoltEnv, workingRoot d
280280
return err
281281
}
282282

283-
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
283+
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
284284
if err != nil {
285285
return err
286286
}

go/cmd/dolt/commands/show.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func getValueFromRefSpec(ctx context.Context, dEnv *env.DoltEnv, specRef string)
256256
if err != nil {
257257
return nil, err
258258
}
259-
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
259+
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
260260
optionalCommit, err := dEnv.DoltDB(ctx).Resolve(ctx, commitSpec, headRef)
261261
if err != nil {
262262
return nil, err

go/cmd/dolt/commands/stashcmds/pop.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func applyStashAtIdx(ctx *sql.Context, dEnv *env.DoltEnv, curWorkingRoot doltdb.
138138
if err != nil {
139139
return false, err
140140
}
141-
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
141+
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
142142
if err != nil {
143143
return false, err
144144
}

go/cmd/dolt/commands/stashcmds/stash.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func stashChanges(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPars
219219
}
220220
}
221221

222-
curHeadRef, err := dEnv.RepoStateReader().CWBHeadRef()
222+
curHeadRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
223223
if err != nil {
224224
return err
225225
}

go/libraries/doltcore/cherry_pick/cherry_pick.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func cherryPick(ctx *sql.Context, dSess *dsess.DoltSession, roots doltdb.Roots,
258258
if err != nil {
259259
return nil, "", err
260260
}
261-
headRef, err := dbData.Rsr.CWBHeadRef()
261+
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
262262
if err != nil {
263263
return nil, "", err
264264
}

go/libraries/doltcore/doltdb/commit_itr.go

+33-29
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ import (
2727
)
2828

2929
// CommitItr is an interface for iterating over a set of unique commits
30-
type CommitItr interface {
30+
type CommitItr[C Context] interface {
3131
// Next returns the hash of the next commit, and a pointer to that commit. Implementations of Next must handle
3232
// making sure the list of commits returned are unique. When complete Next will return hash.Hash{}, nil, io.EOF
33-
Next(ctx context.Context) (hash.Hash, *OptionalCommit, error)
33+
Next(ctx C) (hash.Hash, *OptionalCommit, error)
3434

3535
// Reset the commit iterator back to the start
3636
Reset(ctx context.Context) error
3737
}
3838

39-
type commitItr struct {
39+
type commitItr[C Context] struct {
4040
ddb *DoltDB
4141
rootCommits []*Commit
4242
currentRoot int
@@ -47,7 +47,7 @@ type commitItr struct {
4747
}
4848

4949
// CommitItrForAllBranches returns a CommitItr which will iterate over all commits in all branches in a DoltDB
50-
func CommitItrForAllBranches(ctx context.Context, ddb *DoltDB) (CommitItr, error) {
50+
func CommitItrForAllBranches[C Context](ctx context.Context, ddb *DoltDB) (CommitItr[C], error) {
5151
branchRefs, err := ddb.GetBranches(ctx)
5252

5353
if err != nil {
@@ -65,21 +65,21 @@ func CommitItrForAllBranches(ctx context.Context, ddb *DoltDB) (CommitItr, error
6565
rootCommits = append(rootCommits, cm)
6666
}
6767

68-
cmItr := CommitItrForRoots(ddb, rootCommits...)
68+
cmItr := CommitItrForRoots[C](ddb, rootCommits...)
6969
return cmItr, nil
7070
}
7171

7272
// CommitItrForRoots will return a CommitItr which will iterate over all ancestor commits of the provided rootCommits.
73-
func CommitItrForRoots(ddb *DoltDB, rootCommits ...*Commit) CommitItr {
74-
return &commitItr{
73+
func CommitItrForRoots[C Context](ddb *DoltDB, rootCommits ...*Commit) CommitItr[C] {
74+
return &commitItr[C]{
7575
ddb: ddb,
7676
rootCommits: rootCommits,
7777
added: make(map[hash.Hash]bool, 4096),
7878
unprocessed: make([]hash.Hash, 0, 4096),
7979
}
8080
}
8181

82-
func (cmItr *commitItr) Reset(ctx context.Context) error {
82+
func (cmItr *commitItr[C]) Reset(ctx context.Context) error {
8383
cmItr.curr = nil
8484
cmItr.currentRoot = 0
8585
cmItr.added = make(map[hash.Hash]bool, 4096)
@@ -90,7 +90,7 @@ func (cmItr *commitItr) Reset(ctx context.Context) error {
9090

9191
// Next returns the hash of the next commit, and a pointer to that commit. It handles making sure the list of commits
9292
// returned are unique. When complete Next will return hash.Hash{}, nil, io.EOF
93-
func (cmItr *commitItr) Next(ctx context.Context) (hash.Hash, *OptionalCommit, error) {
93+
func (cmItr *commitItr[C]) Next(ctx C) (hash.Hash, *OptionalCommit, error) {
9494
for cmItr.curr == nil {
9595
if cmItr.currentRoot >= len(cmItr.rootCommits) {
9696
return hash.Hash{}, nil, io.EOF
@@ -159,27 +159,31 @@ func HashToCommit(ctx context.Context, vrw types.ValueReadWriter, ns tree.NodeSt
159159
return NewCommit(ctx, vrw, ns, dc)
160160
}
161161

162+
type Context interface {
163+
context.Context
164+
}
165+
162166
// CommitFilter is a function that returns true if a commit should be filtered out, and false if it should be kept
163-
type CommitFilter func(context.Context, hash.Hash, *OptionalCommit) (filterOut bool, err error)
167+
type CommitFilter[C Context] func(C, hash.Hash, *OptionalCommit) (filterOut bool, err error)
164168

165169
// FilteringCommitItr is a CommitItr implementation that applies a filtering function to limit the commits returned
166-
type FilteringCommitItr struct {
167-
itr CommitItr
168-
filter CommitFilter
170+
type FilteringCommitItr[C Context] struct {
171+
itr CommitItr[C]
172+
filter CommitFilter[C]
169173
}
170174

171175
// AllCommits is a CommitFilter that matches all commits
172176
func AllCommits(_ context.Context, _ hash.Hash, _ *Commit) (filterOut bool, err error) {
173177
return false, nil
174178
}
175179

176-
func NewFilteringCommitItr(itr CommitItr, filter CommitFilter) FilteringCommitItr {
177-
return FilteringCommitItr{itr, filter}
180+
func NewFilteringCommitItr[C Context](itr CommitItr[C], filter CommitFilter[C]) FilteringCommitItr[C] {
181+
return FilteringCommitItr[C]{itr, filter}
178182
}
179183

180184
// Next returns the hash of the next commit, and a pointer to that commit. Implementations of Next must handle
181185
// making sure the list of commits returned are unique. When complete Next will return hash.Hash{}, nil, io.EOF
182-
func (itr FilteringCommitItr) Next(ctx context.Context) (hash.Hash, *OptionalCommit, error) {
186+
func (itr FilteringCommitItr[C]) Next(ctx C) (hash.Hash, *OptionalCommit, error) {
183187
// iteration will terminate on io.EOF or a commit that is !filteredOut
184188
for {
185189
h, cm, err := itr.itr.Next(ctx)
@@ -197,23 +201,23 @@ func (itr FilteringCommitItr) Next(ctx context.Context) (hash.Hash, *OptionalCom
197201
}
198202

199203
// Reset the commit iterator back to the
200-
func (itr FilteringCommitItr) Reset(ctx context.Context) error {
204+
func (itr FilteringCommitItr[C]) Reset(ctx context.Context) error {
201205
return itr.itr.Reset(ctx)
202206
}
203207

204-
func NewCommitSliceIter(cm []*Commit, h []hash.Hash) *CommitSliceIter {
205-
return &CommitSliceIter{cm: cm, h: h}
208+
func NewCommitSliceIter[C Context](cm []*Commit, h []hash.Hash) *CommitSliceIter[C] {
209+
return &CommitSliceIter[C]{cm: cm, h: h}
206210
}
207211

208-
type CommitSliceIter struct {
212+
type CommitSliceIter[C Context] struct {
209213
h []hash.Hash
210214
cm []*Commit
211215
i int
212216
}
213217

214-
var _ CommitItr = (*CommitSliceIter)(nil)
218+
var _ CommitItr[context.Context] = (*CommitSliceIter[context.Context])(nil)
215219

216-
func (i *CommitSliceIter) Next(ctx context.Context) (hash.Hash, *OptionalCommit, error) {
220+
func (i *CommitSliceIter[C]) Next(ctx C) (hash.Hash, *OptionalCommit, error) {
217221
if i.i >= len(i.h) {
218222
return hash.Hash{}, nil, io.EOF
219223
}
@@ -222,25 +226,25 @@ func (i *CommitSliceIter) Next(ctx context.Context) (hash.Hash, *OptionalCommit,
222226

223227
}
224228

225-
func (i *CommitSliceIter) Reset(ctx context.Context) error {
229+
func (i *CommitSliceIter[C]) Reset(ctx context.Context) error {
226230
i.i = 0
227231
return nil
228232
}
229233

230-
func NewOneCommitIter(cm *Commit, h hash.Hash, meta *datas.CommitMeta) *OneCommitIter {
231-
return &OneCommitIter{cm: &OptionalCommit{cm, h}, h: h}
234+
func NewOneCommitIter[C Context](cm *Commit, h hash.Hash, meta *datas.CommitMeta) *OneCommitIter[C] {
235+
return &OneCommitIter[C]{cm: &OptionalCommit{cm, h}, h: h}
232236
}
233237

234-
type OneCommitIter struct {
238+
type OneCommitIter[C Context] struct {
235239
h hash.Hash
236240
cm *OptionalCommit
237241
m *datas.CommitMeta
238242
done bool
239243
}
240244

241-
var _ CommitItr = (*OneCommitIter)(nil)
245+
var _ CommitItr[context.Context] = (*OneCommitIter[context.Context])(nil)
242246

243-
func (i *OneCommitIter) Next(_ context.Context) (hash.Hash, *OptionalCommit, error) {
247+
func (i *OneCommitIter[C]) Next(_ C) (hash.Hash, *OptionalCommit, error) {
244248
if i.done {
245249
return hash.Hash{}, nil, io.EOF
246250
}
@@ -249,7 +253,7 @@ func (i *OneCommitIter) Next(_ context.Context) (hash.Hash, *OptionalCommit, err
249253

250254
}
251255

252-
func (i *OneCommitIter) Reset(_ context.Context) error {
256+
func (i *OneCommitIter[C]) Reset(_ context.Context) error {
253257
i.done = false
254258
return nil
255259
}

go/libraries/doltcore/dtestutils/testcommands/multienv.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func (mr *MultiRepoTestSetup) CommitWithWorkingSet(dbName string) *doltdb.Commit
270270
panic("pending commit error: " + err.Error())
271271
}
272272

273-
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
273+
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
274274
if err != nil {
275275
panic("couldn't get working set: " + err.Error())
276276
}
@@ -369,7 +369,7 @@ func (mr *MultiRepoTestSetup) PushToRemote(dbName, remoteName, branchName string
369369
mr.Errhand(fmt.Sprintf("Failed to access .dolt directory: %s", err.Error()))
370370
}
371371

372-
pushOptions := &env.PushOptions{
372+
pushOptions := &env.PushOptions[context.Context]{
373373
Targets: targets,
374374
Remote: remote,
375375
Rsr: dEnv.RepoStateReader(),

go/libraries/doltcore/env/actions/branch.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var ErrCOBranchDelete = errorKinds.NewKind("Cannot delete checked out branch '%s
3333
var ErrUnmergedBranch = errorKinds.NewKind("branch '%s' is not fully merged")
3434
var ErrWorkingSetsOnBothBranches = errors.New("checkout would overwrite uncommitted changes on target branch")
3535

36-
func RenameBranch(ctx context.Context, dbData env.DbData, oldBranch, newBranch string, remoteDbPro env.RemoteDbProvider, force bool, rsc *doltdb.ReplicationStatusController) error {
36+
func RenameBranch[C doltdb.Context](ctx C, dbData env.DbData[C], oldBranch, newBranch string, remoteDbPro env.RemoteDbProvider, force bool, rsc *doltdb.ReplicationStatusController) error {
3737
oldRef := ref.NewBranchRef(oldBranch)
3838
newRef := ref.NewBranchRef(newBranch)
3939

@@ -115,7 +115,7 @@ type DeleteOptions struct {
115115
AllowDeletingCurrentBranch bool
116116
}
117117

118-
func DeleteBranch(ctx context.Context, dbData env.DbData, brName string, opts DeleteOptions, remoteDbPro env.RemoteDbProvider, rsc *doltdb.ReplicationStatusController) error {
118+
func DeleteBranch[C doltdb.Context](ctx C, dbData env.DbData[C], brName string, opts DeleteOptions, remoteDbPro env.RemoteDbProvider, rsc *doltdb.ReplicationStatusController) error {
119119
var branchRef ref.DoltRef
120120
if opts.Remote {
121121
var err error
@@ -125,7 +125,7 @@ func DeleteBranch(ctx context.Context, dbData env.DbData, brName string, opts De
125125
}
126126
} else {
127127
branchRef = ref.NewBranchRef(brName)
128-
headRef, err := dbData.Rsr.CWBHeadRef()
128+
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
129129
if err != nil {
130130
return err
131131
}
@@ -137,7 +137,7 @@ func DeleteBranch(ctx context.Context, dbData env.DbData, brName string, opts De
137137
return DeleteBranchOnDB(ctx, dbData, branchRef, opts, remoteDbPro, rsc)
138138
}
139139

140-
func DeleteBranchOnDB(ctx context.Context, dbdata env.DbData, branchRef ref.DoltRef, opts DeleteOptions, pro env.RemoteDbProvider, rsc *doltdb.ReplicationStatusController) error {
140+
func DeleteBranchOnDB[C doltdb.Context](ctx C, dbdata env.DbData[C], branchRef ref.DoltRef, opts DeleteOptions, pro env.RemoteDbProvider, rsc *doltdb.ReplicationStatusController) error {
141141
ddb := dbdata.Ddb
142142
hasRef, err := ddb.HasRef(ctx, branchRef)
143143

@@ -184,7 +184,7 @@ func DeleteBranchOnDB(ctx context.Context, dbdata env.DbData, branchRef ref.Dolt
184184
}
185185

186186
// validateBranchMergedIntoCurrentWorkingBranch returns an error if the given branch is not fully merged into the HEAD of the current branch.
187-
func validateBranchMergedIntoCurrentWorkingBranch(ctx context.Context, dbdata env.DbData, branch ref.DoltRef) error {
187+
func validateBranchMergedIntoCurrentWorkingBranch[C doltdb.Context](ctx C, dbdata env.DbData[C], branch ref.DoltRef) error {
188188
branchSpec, err := doltdb.NewCommitSpec(branch.GetPath())
189189
if err != nil {
190190
return err
@@ -204,7 +204,7 @@ func validateBranchMergedIntoCurrentWorkingBranch(ctx context.Context, dbdata en
204204
return err
205205
}
206206

207-
headRef, err := dbdata.Rsr.CWBHeadRef()
207+
headRef, err := dbdata.Rsr.CWBHeadRef(ctx)
208208
if err != nil {
209209
return err
210210
}
@@ -237,7 +237,7 @@ func validateBranchMergedIntoCurrentWorkingBranch(ctx context.Context, dbdata en
237237
}
238238

239239
// validateBranchMergedIntoUpstream returns an error if the branch provided is not fully merged into its upstream
240-
func validateBranchMergedIntoUpstream(ctx context.Context, dbdata env.DbData, branch ref.DoltRef, remoteName string, pro env.RemoteDbProvider) error {
240+
func validateBranchMergedIntoUpstream[C doltdb.Context](ctx context.Context, dbdata env.DbData[C], branch ref.DoltRef, remoteName string, pro env.RemoteDbProvider) error {
241241
remotes, err := dbdata.Rsr.GetRemotes()
242242
if err != nil {
243243
return err
@@ -294,7 +294,7 @@ func validateBranchMergedIntoUpstream(ctx context.Context, dbdata env.DbData, br
294294
return nil
295295
}
296296

297-
func CreateBranchWithStartPt(ctx context.Context, dbData env.DbData, newBranch, startPt string, force bool, rsc *doltdb.ReplicationStatusController) error {
297+
func CreateBranchWithStartPt[C doltdb.Context](ctx C, dbData env.DbData[C], newBranch, startPt string, force bool, rsc *doltdb.ReplicationStatusController) error {
298298
err := createBranch(ctx, dbData, newBranch, startPt, force, rsc)
299299

300300
if err != nil {
@@ -354,8 +354,8 @@ func CreateBranchOnDB(ctx context.Context, ddb *doltdb.DoltDB, newBranch, starti
354354
return nil
355355
}
356356

357-
func createBranch(ctx context.Context, dbData env.DbData, newBranch, startingPoint string, force bool, rsc *doltdb.ReplicationStatusController) error {
358-
headRef, err := dbData.Rsr.CWBHeadRef()
357+
func createBranch[C doltdb.Context](ctx C, dbData env.DbData[C], newBranch, startingPoint string, force bool, rsc *doltdb.ReplicationStatusController) error {
358+
headRef, err := dbData.Rsr.CWBHeadRef(ctx)
359359
if err != nil {
360360
return err
361361
}
@@ -378,7 +378,7 @@ func MaybeGetCommit(ctx context.Context, dEnv *env.DoltEnv, str string) (*doltdb
378378
cs, err := doltdb.NewCommitSpec(str)
379379

380380
if err == nil {
381-
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
381+
headRef, err := dEnv.RepoStateReader().CWBHeadRef(ctx)
382382
if err != nil {
383383
return nil, err
384384
}

go/libraries/doltcore/env/actions/checkout.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func RootsForBranch(ctx context.Context, roots doltdb.Roots, branchRoot doltdb.R
180180
// CleanOldWorkingSet resets the source branch's working set to the branch head, leaving the source branch unchanged
181181
func CleanOldWorkingSet(
182182
ctx *sql.Context,
183-
dbData env.DbData,
183+
dbData env.DbData[*sql.Context],
184184
doltDb *doltdb.DoltDB,
185185
username, email string,
186186
initialRoots doltdb.Roots,

go/libraries/doltcore/env/actions/clone.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func fullClone(ctx context.Context, srcDB *doltdb.DoltDB, dEnv *env.DoltEnv, src
320320

321321
// shallowCloneDataPull is a shallow clone specific helper function to pull only the data required to show the given branch
322322
// at the depth given.
323-
func shallowCloneDataPull(ctx context.Context, destData env.DbData, srcDB *doltdb.DoltDB, remoteName, branch string, depth int) (*doltdb.Commit, error) {
323+
func shallowCloneDataPull[C doltdb.Context](ctx C, destData env.DbData[C], srcDB *doltdb.DoltDB, remoteName, branch string, depth int) (*doltdb.Commit, error) {
324324
remotes, err := destData.Rsr.GetRemotes()
325325
if err != nil {
326326
return nil, err

0 commit comments

Comments
 (0)