This repository was archived by the owner on Sep 30, 2024. It is now read-only.
gitserver: Add option to allow setting custom context line count#63840
Merged
eseliger merged 1 commit intoJul 19, 2024
Merged
Conversation
Member
Author
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
eseliger
commented
Jul 16, 2024
Comment on lines
103
to
111
Member
Author
There was a problem hiding this comment.
This is what you want, right?
de4ffc1 to
8c77e31
Compare
eseliger
commented
Jul 16, 2024
Comment on lines
831
to
850
Member
Author
There was a problem hiding this comment.
Here's example go-diff output for the hunk (which we need to work with because sub repo perms enforcement)
8c77e31 to
90bf1d2
Compare
This PR adds support for two new arguments in the gitserver API: InterHunkContext and ContextLines. See the inline docstring for the two, but basically this allows to request diffs with a custom amount of context lines and hunk merging. The defaults should be unchanged at `3` for both, according to https://sourcegraph.com/github.com/git/git/-/blob/diff.c?L60. Test plan: Added unit tests.
90bf1d2 to
f5757d3
Compare
kritzcreek
approved these changes
Jul 16, 2024
Comment on lines
103
to
111
Contributor
|
Fun, when trying to use this I came across this totally not brittle mock that'll need updating as well. Unless there's a better gitClient fake I could use for testing? |
Member
Author
|
Meh that thing should be gone by now. Instead, create a mock client like this: diff := []byte(`yourmockdiffhere`)
gs := gitserver.NewMockClient()
gs.DiffFunc.SetDefaultHook(func(ctx context.Context, rn api.RepoName, do gitserver.DiffOptions) (*gitserver.DiffFileIterator, error) {
return gitserver.NewDiffFileIterator(io.NopCloser(bytes.NewReader(diff))), nil
})and pass that gitserver client to the function you're testing |
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.

This PR adds support for two new arguments in the gitserver API: InterHunkContext and ContextLines.
See the inline docstring for the two, but basically this allows to request diffs with a custom amount of context lines and hunk merging.
The defaults should be unchanged at
3for both, according to https://sourcegraph.com/github.com/git/git/-/blob/diff.c?L60.Closes SRC-467
Test plan:
Added unit tests.