-
Notifications
You must be signed in to change notification settings - Fork 70
Support binary diffs #887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Support binary diffs #887
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
485e759
Binary diffs
eseliger b8bf0f8
Fixup test
eseliger 4270708
Fixup
eseliger 907329c
Fixup
eseliger 3250037
Fixups
eseliger 068ddf3
Changelog entry
eseliger 459f02c
Use latest commit
eseliger 3e7415f
Merge branch 'main' into es/binary-diffs
eseliger 72489fc
CHANGELOG
eseliger e3f40f5
Linter
eseliger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| golang 1.18.1 | ||
| golang 1.19.3 | ||
| shfmt 3.2.0 | ||
| shellcheck 0.7.1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import ( | |
| "github.com/mattn/go-isatty" | ||
|
|
||
| "github.com/sourcegraph/sourcegraph/lib/errors" | ||
| "github.com/sourcegraph/sourcegraph/lib/output" | ||
|
|
||
| batcheslib "github.com/sourcegraph/sourcegraph/lib/batches" | ||
| "github.com/sourcegraph/sourcegraph/lib/batches/template" | ||
|
|
@@ -253,20 +254,38 @@ type executeBatchSpecOpts struct { | |
| // executeBatchSpec performs all the steps required to upload the batch spec to | ||
| // Sourcegraph, including execution as needed and applying the resulting batch | ||
| // spec if specified. | ||
| func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOpts) (err error) { | ||
| func executeBatchSpec(ctx context.Context, opts executeBatchSpecOpts) (err error) { | ||
| var execUI ui.ExecUI | ||
| if opts.flags.textOnly { | ||
| execUI = &ui.JSONLines{} | ||
| } else { | ||
| out := output.NewOutput(os.Stderr, output.OutputOpts{Verbose: *verbose}) | ||
| execUI = &ui.TUI{Out: out} | ||
| } | ||
|
|
||
| defer func() { | ||
| if err != nil { | ||
| ui.ExecutionError(err) | ||
| execUI.ExecutionError(err) | ||
| } | ||
| }() | ||
|
|
||
| svc := service.New(&service.Opts{ | ||
| Client: opts.client, | ||
| }) | ||
|
|
||
| ffs, err := svc.DetermineFeatureFlags(ctx) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Once we know about feature flags, reconfigure the UI if needed. | ||
| if opts.flags.textOnly && ffs.BinaryDiffs { | ||
| execUI = &ui.JSONLines{BinaryDiffs: true} | ||
| } | ||
|
|
||
| imageCache := docker.NewImageCache() | ||
|
|
||
| if err := validateSourcegraphVersionConstraint(ctx, svc); err != nil { | ||
| if err := validateSourcegraphVersionConstraint(ctx, ffs); err != nil { | ||
| return err | ||
| } | ||
|
|
||
|
|
@@ -309,45 +328,45 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp | |
| } | ||
|
|
||
| // Parse flags and build up our service and executor options. | ||
| ui.ParsingBatchSpec() | ||
| execUI.ParsingBatchSpec() | ||
| batchSpec, batchSpecDir, rawSpec, err := parseBatchSpec(ctx, opts.file, svc) | ||
| if err != nil { | ||
| var multiErr errors.MultiError | ||
| if errors.As(err, &multiErr) { | ||
| ui.ParsingBatchSpecFailure(multiErr) | ||
| execUI.ParsingBatchSpecFailure(multiErr) | ||
| return cmderrors.ExitCode(2, nil) | ||
| } else { | ||
| // This shouldn't happen; let's just punt and let the normal | ||
| // rendering occur. | ||
| return err | ||
| } | ||
| } | ||
| ui.ParsingBatchSpecSuccess() | ||
| execUI.ParsingBatchSpecSuccess() | ||
|
|
||
| ui.ResolvingNamespace() | ||
| execUI.ResolvingNamespace() | ||
| namespace, err := svc.ResolveNamespace(ctx, opts.flags.namespace) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| ui.ResolvingNamespaceSuccess(namespace.ID) | ||
| execUI.ResolvingNamespaceSuccess(namespace.ID) | ||
|
|
||
| var workspaceCreator workspace.Creator | ||
|
|
||
| if len(batchSpec.Steps) > 0 { | ||
| ui.PreparingContainerImages() | ||
| execUI.PreparingContainerImages() | ||
| images, err := svc.EnsureDockerImages( | ||
| ctx, | ||
| imageCache, | ||
| batchSpec.Steps, | ||
| parallelism, | ||
| ui.PreparingContainerImagesProgress, | ||
| execUI.PreparingContainerImagesProgress, | ||
| ) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| ui.PreparingContainerImagesSuccess() | ||
| execUI.PreparingContainerImagesSuccess() | ||
|
|
||
| ui.DeterminingWorkspaceCreatorType() | ||
| execUI.DeterminingWorkspaceCreatorType() | ||
| var typ workspace.CreatorType | ||
| workspaceCreator, typ = workspace.NewCreator(ctx, opts.flags.workspace, opts.flags.cacheDir, opts.flags.tempDir, images) | ||
| if typ == workspace.CreatorTypeVolume { | ||
|
|
@@ -357,21 +376,21 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp | |
| return err | ||
| } | ||
| } | ||
| ui.DeterminingWorkspaceCreatorTypeSuccess(typ) | ||
| execUI.DeterminingWorkspaceCreatorTypeSuccess(typ) | ||
| } | ||
|
|
||
| ui.DeterminingWorkspaces() | ||
| execUI.DeterminingWorkspaces() | ||
| workspaces, repos, err := svc.ResolveWorkspacesForBatchSpec(ctx, batchSpec, opts.flags.allowUnsupported, opts.flags.allowIgnored) | ||
| if err != nil { | ||
| if repoSet, ok := err.(batches.UnsupportedRepoSet); ok { | ||
| ui.DeterminingWorkspacesSuccess(len(workspaces), len(repos), repoSet, nil) | ||
| execUI.DeterminingWorkspacesSuccess(len(workspaces), len(repos), repoSet, nil) | ||
| } else if repoSet, ok := err.(batches.IgnoredRepoSet); ok { | ||
| ui.DeterminingWorkspacesSuccess(len(workspaces), len(repos), nil, repoSet) | ||
| execUI.DeterminingWorkspacesSuccess(len(workspaces), len(repos), nil, repoSet) | ||
| } else { | ||
| return errors.Wrap(err, "resolving repositories") | ||
| } | ||
| } else { | ||
| ui.DeterminingWorkspacesSuccess(len(workspaces), len(repos), nil, nil) | ||
| execUI.DeterminingWorkspacesSuccess(len(workspaces), len(repos), nil, nil) | ||
| } | ||
|
|
||
| archiveRegistry := repozip.NewArchiveRegistry(opts.client, opts.flags.cacheDir, opts.flags.cleanArchives) | ||
|
|
@@ -389,14 +408,16 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp | |
| TempDir: opts.flags.tempDir, | ||
| GlobalEnv: os.Environ(), | ||
| ForceRoot: opts.flags.runAsRoot, | ||
| BinaryDiffs: ffs.BinaryDiffs, | ||
| }, | ||
| Logger: logManager, | ||
| Cache: executor.NewDiskCache(opts.flags.cacheDir), | ||
| GlobalEnv: os.Environ(), | ||
| Logger: logManager, | ||
| Cache: executor.NewDiskCache(opts.flags.cacheDir), | ||
| BinaryDiffs: ffs.BinaryDiffs, | ||
| GlobalEnv: os.Environ(), | ||
| }, | ||
| ) | ||
|
|
||
| ui.CheckingCache() | ||
| execUI.CheckingCache() | ||
| tasks := svc.BuildTasks( | ||
| &template.BatchChangeAttributes{ | ||
| Name: batchSpec.Name, | ||
|
|
@@ -421,9 +442,9 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp | |
| return err | ||
| } | ||
| } | ||
| ui.CheckingCacheSuccess(len(specs), len(uncachedTasks)) | ||
| execUI.CheckingCacheSuccess(len(specs), len(uncachedTasks)) | ||
|
|
||
| taskExecUI := ui.ExecutingTasks(*verbose, parallelism) | ||
| taskExecUI := execUI.ExecutingTasks(*verbose, parallelism) | ||
| freshSpecs, logFiles, execErr := coord.ExecuteAndBuildSpecs(ctx, batchSpec, uncachedTasks, taskExecUI) | ||
| // Add external changeset specs. | ||
| importedSpecs, importErr := svc.CreateImportChangesetSpecs(ctx, batchSpec) | ||
|
|
@@ -440,7 +461,7 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp | |
| if err == nil { | ||
| taskExecUI.Success() | ||
| } else { | ||
| ui.ExecutingTasksSkippingErrors(err) | ||
| execUI.ExecutingTasksSkippingErrors(err) | ||
| } | ||
| } else { | ||
| if err != nil { | ||
|
|
@@ -450,7 +471,7 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp | |
| } | ||
|
|
||
| if len(logFiles) > 0 && opts.flags.keepLogs { | ||
| ui.LogFilesKept(logFiles) | ||
| execUI.LogFilesKept(logFiles) | ||
| } | ||
|
|
||
| specs = append(specs, freshSpecs...) | ||
|
|
@@ -464,29 +485,29 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp | |
| ids := make([]graphql.ChangesetSpecID, len(specs)) | ||
|
|
||
| if len(specs) > 0 { | ||
| ui.UploadingChangesetSpecs(len(specs)) | ||
| execUI.UploadingChangesetSpecs(len(specs)) | ||
|
|
||
| for i, spec := range specs { | ||
| id, err := svc.CreateChangesetSpec(ctx, spec) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| ids[i] = id | ||
| ui.UploadingChangesetSpecsProgress(i+1, len(specs)) | ||
| execUI.UploadingChangesetSpecsProgress(i+1, len(specs)) | ||
| } | ||
|
|
||
| ui.UploadingChangesetSpecsSuccess(ids) | ||
| execUI.UploadingChangesetSpecsSuccess(ids) | ||
| } else if len(repos) == 0 { | ||
| ui.NoChangesetSpecs() | ||
| execUI.NoChangesetSpecs() | ||
| } | ||
|
|
||
| ui.CreatingBatchSpec() | ||
| execUI.CreatingBatchSpec() | ||
| id, url, err := svc.CreateBatchSpec(ctx, namespace.ID, rawSpec, ids) | ||
| if err != nil { | ||
| return ui.CreatingBatchSpecError(err) | ||
| return execUI.CreatingBatchSpecError(err) | ||
| } | ||
| previewURL := cfg.Endpoint + url | ||
| ui.CreatingBatchSpecSuccess(previewURL) | ||
| execUI.CreatingBatchSpecSuccess(previewURL) | ||
|
|
||
| hasWorkspaceFiles := false | ||
| for _, step := range batchSpec.Steps { | ||
|
|
@@ -496,26 +517,26 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp | |
| } | ||
| } | ||
| if hasWorkspaceFiles { | ||
| ui.UploadingWorkspaceFiles() | ||
| execUI.UploadingWorkspaceFiles() | ||
| if err = svc.UploadBatchSpecWorkspaceFiles(ctx, batchSpecDir, string(id), batchSpec.Steps); err != nil { | ||
| // Since failing to upload workspace files should not stop processing, just warn | ||
| ui.UploadingWorkspaceFilesWarning(errors.Wrap(err, "uploading workspace files")) | ||
| execUI.UploadingWorkspaceFilesWarning(errors.Wrap(err, "uploading workspace files")) | ||
| } else { | ||
| ui.UploadingWorkspaceFilesSuccess() | ||
| execUI.UploadingWorkspaceFilesSuccess() | ||
| } | ||
| } | ||
|
|
||
| if !opts.applyBatchSpec { | ||
| ui.PreviewBatchSpec(previewURL) | ||
| execUI.PreviewBatchSpec(previewURL) | ||
| return | ||
| } | ||
|
|
||
| ui.ApplyingBatchSpec() | ||
| execUI.ApplyingBatchSpec() | ||
| batch, err := svc.ApplyBatchChange(ctx, id) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| ui.ApplyingBatchSpecSuccess(cfg.Endpoint + batch.URL) | ||
| execUI.ApplyingBatchSpecSuccess(cfg.Endpoint + batch.URL) | ||
|
|
||
| return nil | ||
| } | ||
|
|
@@ -617,11 +638,7 @@ func getBatchParallelism(ctx context.Context, flag int) (int, error) { | |
| return docker.NCPU(ctx) | ||
| } | ||
|
|
||
| func validateSourcegraphVersionConstraint(ctx context.Context, svc *service.Service) error { | ||
| ffs, err := svc.DetermineFeatureFlags(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| func validateSourcegraphVersionConstraint(ctx context.Context, ffs *batches.FeatureFlags) error { | ||
| if ffs.Sourcegraph40 { | ||
| return nil | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to upgrade, Sourcegraph now requires it.