Skip to content

Commit 7ebf7fe

Browse files
authored
Remove old feature gates from pre-4.0 (#822)
1 parent 7143302 commit 7ebf7fe

File tree

20 files changed

+99
-365
lines changed

20 files changed

+99
-365
lines changed

cmd/src/batch_common.go

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -177,37 +177,17 @@ func batchDefaultCacheDir() string {
177177
if err != nil {
178178
return ""
179179
}
180-
181-
// Check if there's an old campaigns cache directory but not a new batch
182-
// directory: if so, we should rename the old directory and carry on.
183-
//
184-
// TODO(campaigns-deprecation): we can remove this migration shim after June
185-
// 2021.
186-
old := path.Join(uc, "sourcegraph", "campaigns")
187180
dir := path.Join(uc, "sourcegraph", "batch")
188-
if _, err := os.Stat(dir); os.IsNotExist(err) {
189-
if _, err := os.Stat(old); os.IsExist(err) {
190-
// We'll just try to do this without checking for an error: if it
191-
// fails, we'll carry on and let the normal cache directory handling
192-
// logic take care of it.
193-
os.Rename(old, dir)
194-
}
195-
}
196181

197182
return dir
198183
}
199184

200185
// batchDefaultTempDirPrefix returns the prefix to be passed to ioutil.TempFile.
201-
// If one of the environment variables SRC_BATCH_TMP_DIR or
202-
// SRC_CAMPAIGNS_TMP_DIR is set, that is used as the prefix. Otherwise we use
203-
// "/tmp".
186+
// If the environment variable SRC_BATCH_TMP_DIR is set, that is used as the prefix.
187+
// Otherwise we use "/tmp".
204188
func batchDefaultTempDirPrefix() string {
205-
// TODO(campaigns-deprecation): we can remove this migration shim in
206-
// Sourcegraph 4.0.
207-
for _, env := range []string{"SRC_BATCH_TMP_DIR", "SRC_CAMPAIGNS_TMP_DIR"} {
208-
if p := os.Getenv(env); p != "" {
209-
return p
210-
}
189+
if p := os.Getenv("SRC_BATCH_TMP_DIR"); p != "" {
190+
return p
211191
}
212192

213193
// On macOS, we use an explicit prefix for our temp directories, because
@@ -280,7 +260,7 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp
280260

281261
imageCache := docker.NewImageCache()
282262

283-
if err := svc.DetermineFeatureFlags(ctx); err != nil {
263+
if err := validateSourcegraphVersionConstraint(ctx, svc); err != nil {
284264
return err
285265
}
286266

@@ -399,7 +379,6 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp
399379
GlobalEnv: os.Environ(),
400380
IsRemote: false,
401381
},
402-
Features: svc.Features(),
403382
Logger: logManager,
404383
Cache: executor.NewDiskCache(opts.flags.cacheDir),
405384
GlobalEnv: os.Environ(),
@@ -604,3 +583,14 @@ func getBatchParallelism(ctx context.Context, flag int) (int, error) {
604583

605584
return docker.NCPU(ctx)
606585
}
586+
587+
func validateSourcegraphVersionConstraint(ctx context.Context, svc *service.Service) error {
588+
ffs, err := svc.DetermineFeatureFlags(ctx)
589+
if err != nil {
590+
return err
591+
}
592+
if ffs.Sourcegraph40 {
593+
return nil
594+
}
595+
return errors.Newf("\n\n * Warning:\n This version of src-cli requires Sourcegraph version 4.0 or newer. If you're not on Sourcegraph 4.0 or newer, please use the 3.x release of src-cli that corresponds to your Sourcegraph version.\n\n")
596+
}

cmd/src/batch_new.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Examples:
4848
Client: cfg.apiClient(apiFlags, flagSet.Output()),
4949
})
5050

51-
if err := svc.DetermineFeatureFlags(ctx); err != nil {
51+
if err := validateSourcegraphVersionConstraint(ctx, svc); err != nil {
5252
return err
5353
}
5454

cmd/src/batch_remote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Examples:
5252
Client: cfg.apiClient(flags.api, flagSet.Output()),
5353
})
5454

55-
if err := svc.DetermineFeatureFlags(ctx); err != nil {
55+
if err := validateSourcegraphVersionConstraint(ctx, svc); err != nil {
5656
return err
5757
}
5858

cmd/src/batch_repositories.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Examples:
6464
Client: client,
6565
})
6666

67-
if err := svc.DetermineFeatureFlags(ctx); err != nil {
67+
if err := validateSourcegraphVersionConstraint(ctx, svc); err != nil {
6868
return err
6969
}
7070

cmd/src/batch_validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Examples:
6363
Client: cfg.apiClient(apiFlags, flagSet.Output()),
6464
})
6565

66-
if err := svc.DetermineFeatureFlags(ctx); err != nil {
66+
if err := validateSourcegraphVersionConstraint(ctx, svc); err != nil {
6767
ui.ExecutionError(err)
6868
return err
6969
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/sourcegraph/go-diff v0.6.1
2222
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf
2323
github.com/sourcegraph/scip v0.2.0
24-
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220822143138-d621aac70d3d
24+
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220825181731-397a768a5290
2525
github.com/stretchr/testify v1.7.2
2626
golang.org/x/net v0.0.0-20220722155237-a158d28d115b
2727
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
@@ -103,7 +103,7 @@ require (
103103
go.uber.org/zap v1.21.0 // indirect
104104
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
105105
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
106-
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 // indirect
106+
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 // indirect
107107
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect
108108
golang.org/x/text v0.3.7 // indirect
109109
golang.org/x/tools v0.1.12 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ github.com/sourcegraph/log v0.0.0-20220707160925-6a936691c838 h1:8wknDSCUVYbaRT6
370370
github.com/sourcegraph/log v0.0.0-20220707160925-6a936691c838/go.mod h1:zWEPlKrWBUVpko/tOgDS+qrp7BmzaCcmUrh9+ver1iQ=
371371
github.com/sourcegraph/scip v0.2.0 h1:Z9rR9TNONtRhqcpm0JP/yEBUy0fBKaSVbWIZKih5v04=
372372
github.com/sourcegraph/scip v0.2.0/go.mod h1:EYyT39nXdZDNVmgbJAlyIVWbEb1txnAOKpJPSYpvgXk=
373-
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220822143138-d621aac70d3d h1:bUaXAbtXSWbcv8LjDwwYXo0grERhlOJDn2T8ROe/Mmc=
374-
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220822143138-d621aac70d3d/go.mod h1:9wnFUNfpORLAOJn4XAO7ZeWnYkf6/CxlWaTU1vlpuKc=
373+
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220825181731-397a768a5290 h1:SLCu3Rf1eLZ4sNKl0Bg1oURTgDxEutRCaTQt5dpVqH4=
374+
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220825181731-397a768a5290/go.mod h1:9wnFUNfpORLAOJn4XAO7ZeWnYkf6/CxlWaTU1vlpuKc=
375375
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152 h1:z/MpntplPaW6QW95pzcAR/72Z5TWDyDnSo0EOcyij9o=
376376
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
377377
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
@@ -535,8 +535,8 @@ golang.org/x/sys v0.0.0-20211102192858-4dd72447c267/go.mod h1:oPkhp1MJrh7nUepCBc
535535
golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
536536
golang.org/x/sys v0.0.0-20211213223007-03aa0b5f6827/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
537537
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
538-
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 h1:Sx/u41w+OwrInGdEckYmEuU5gHoGSL4QbDz3S9s6j4U=
539-
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
538+
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 h1:TyKJRhyo17yWxOMCTHKWrc5rddHORMlnZ/j57umaUd8=
539+
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
540540
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
541541
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 h1:EH1Deb8WZJ0xc0WK//leUHXcX9aLE5SymusoTmMZye8=
542542
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

internal/api/api.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
ioaux "github.com/jig/teereadcloser"
1717
"github.com/kballard/go-shellquote"
1818
"github.com/mattn/go-isatty"
19+
1920
"github.com/sourcegraph/src-cli/internal/version"
2021
)
2122

@@ -28,13 +29,6 @@ type Client interface {
2829
// NewRequest creates a GraphQL request.
2930
NewRequest(query string, vars map[string]interface{}) Request
3031

31-
// NewGzippedRequest creates a GraphQL request with gzip compression turned on.
32-
NewGzippedRequest(query string, vars map[string]interface{}) Request
33-
34-
// NewGzippedQuery is a convenience wrapper around NewQuery with gzip
35-
// compression turned on.
36-
NewGzippedQuery(query string) Request
37-
3832
// NewHTTPRequest creates an http.Request for the Sourcegraph API.
3933
//
4034
// path is joined against the API route. For example on Sourcegraph.com this
@@ -72,7 +66,6 @@ type request struct {
7266
client *client
7367
query string
7468
vars map[string]interface{}
75-
gzip bool
7669
}
7770

7871
// ClientOpts encapsulates the options given to NewClient.
@@ -132,19 +125,6 @@ func (c *client) NewRequest(query string, vars map[string]interface{}) Request {
132125
}
133126
}
134127

135-
func (c *client) NewGzippedRequest(query string, vars map[string]interface{}) Request {
136-
return &request{
137-
client: c,
138-
query: query,
139-
vars: vars,
140-
gzip: true,
141-
}
142-
}
143-
144-
func (c *client) NewGzippedQuery(query string) Request {
145-
return c.NewGzippedRequest(query, nil)
146-
}
147-
148128
func (c *client) Do(req *http.Request) (*http.Response, error) {
149129
return c.httpClient.Do(req)
150130
}
@@ -216,19 +196,16 @@ func (r *request) do(ctx context.Context, result interface{}) (bool, error) {
216196
}
217197

218198
var bufBody io.Reader = bytes.NewBuffer(reqBody)
219-
if r.gzip {
220-
bufBody = gzipReader(bufBody)
221-
}
199+
bufBody = gzipReader(bufBody)
222200

223201
// Create the HTTP request.
224202
req, err := r.client.NewHTTPRequest(ctx, "POST", ".api/graphql", bufBody)
225203
if err != nil {
226204
return false, err
227205
}
228206

229-
if r.gzip {
230-
req.Header.Set("Content-Encoding", "gzip")
231-
}
207+
// Use gzip compression.
208+
req.Header.Set("Content-Encoding", "gzip")
232209

233210
// Perform the request.
234211
resp, err := r.client.httpClient.Do(req)

internal/batches/executor/coordinator.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/sourcegraph/sourcegraph/lib/batches/execution"
1010
"github.com/sourcegraph/sourcegraph/lib/batches/execution/cache"
1111

12-
"github.com/sourcegraph/src-cli/internal/batches"
1312
"github.com/sourcegraph/src-cli/internal/batches/log"
1413
)
1514

@@ -34,8 +33,6 @@ type NewCoordinatorOpts struct {
3433
Logger log.LogManager
3534
GlobalEnv []string
3635

37-
// Used by batcheslib.BuildChangesetSpecs
38-
Features batches.FeatureFlags
3936
IsRemote bool
4037
}
4138

@@ -124,10 +121,7 @@ func (c Coordinator) buildChangesetSpecs(task *Task, batchSpec *batcheslib.Batch
124121
},
125122
}
126123

127-
return batcheslib.BuildChangesetSpecs(input, batcheslib.ChangesetSpecFeatureFlags{
128-
IncludeAutoAuthorDetails: c.opts.Features.IncludeAutoAuthorDetails,
129-
AllowOptionalPublished: c.opts.Features.AllowOptionalPublished,
130-
})
124+
return batcheslib.BuildChangesetSpecs(input)
131125
}
132126

133127
func (c *Coordinator) loadCachedStepResults(ctx context.Context, task *Task, globalEnv []string) error {

internal/batches/executor/coordinator_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestCoordinator_Execute(t *testing.T) {
8282
{task: sourcegraphTask, stepResults: []execution.AfterStepResult{{Diff: `dummydiff2`}}},
8383
},
8484
},
85-
opts: NewCoordinatorOpts{Features: featuresAllEnabled()},
85+
opts: NewCoordinatorOpts{},
8686

8787
wantCacheEntries: 2,
8888
wantSpecs: []*batcheslib.ChangesetSpec{
@@ -150,7 +150,7 @@ func TestCoordinator_Execute(t *testing.T) {
150150
},
151151
},
152152
},
153-
opts: NewCoordinatorOpts{Features: featuresAllEnabled()},
153+
opts: NewCoordinatorOpts{},
154154

155155
wantCacheEntries: 1,
156156
wantSpecs: []*batcheslib.ChangesetSpec{
@@ -201,7 +201,7 @@ func TestCoordinator_Execute(t *testing.T) {
201201
{task: sourcegraphTask, stepResults: []execution.AfterStepResult{{Diff: nestedChangesDiff}}},
202202
},
203203
},
204-
opts: NewCoordinatorOpts{Features: featuresAllEnabled()},
204+
opts: NewCoordinatorOpts{},
205205

206206
// TODO: Fix comment.
207207
// We have 4 ChangesetSpecs, but we only want 2 cache entries,
@@ -249,7 +249,7 @@ func TestCoordinator_Execute(t *testing.T) {
249249
{task: sourcegraphTask, stepResults: []execution.AfterStepResult{{Diff: `dummydiff2`, StepIndex: 0}}},
250250
},
251251
},
252-
opts: NewCoordinatorOpts{Features: featuresAllEnabled()},
252+
opts: NewCoordinatorOpts{},
253253

254254
wantCacheEntries: 2,
255255
wantSpecs: []*batcheslib.ChangesetSpec{

0 commit comments

Comments
 (0)