Skip to content
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

Add option to specify context size #14

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

gcanat
Copy link

@gcanat gcanat commented Oct 1, 2024

similar to diff -U NUM

Copy link
Collaborator

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for contributing this!

When I looked at the code last time, I had the same intuition, but didn't get around to it.

Something that's gravely missing, but should be easy to add, is a test - there are already some that could be used as template.

Thanks again!

src/unified_diff.rs Outdated Show resolved Hide resolved
src/unified_diff.rs Outdated Show resolved Hide resolved
@@ -116,11 +119,11 @@ where
type Out = W;

fn process_change(&mut self, before: Range<u32>, after: Range<u32>) {
if before.start - self.pos > 6 {
if before.start - self.pos > self.ctx_size {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this 2 * self.ctx_size?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not understand why it would have to be 2 * self.ctx_size. For me, we want to move self.pos to before.start - self.ctx_size if it's not already inside that range. But maybe I'm missing something, that will be clearer once I write some tests (or @pascalkuthe chimes in).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd start at fixing CI before pinging people.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

Copy link
Author

@gcanat gcanat Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK so indeed 2 * self.ctx_size works well when we are between 2 hunks. But for the first hunk it can be incorrect. For example, say you have ctx_size=5. First hunk starts at line 9, self.pos is currently at 0. Since 9 - 0 < 2 * 5, you wont move self.pos and will print 8 lines of context before the first hunk.

Copy link
Collaborator

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for getting back to you so late - I wasn't aware that all of the issues have been addressed.

There is one more shortcoming regarding the documentation which I think could be fixed in a way that also allows extension in the future. It's something I'd implement myself, but then I can't merge myself anymore.

Thanks again for your help!

src/unified_diff.rs Outdated Show resolved Hide resolved
@Byron Byron force-pushed the context_size_option branch from c3b8fc3 to ba2fa5e Compare December 9, 2024 15:02
Byron
Byron previously approved these changes Dec 9, 2024
Copy link
Collaborator

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

I have rewritten the last commit to keep the option open to merge it myself I suppose, but I think this breaking change is now made so that other types of context could be added in the future without additional breaking changes.

The diff is best viewed by hiding whitespace, as I moved code a round a bit.

I will leave the merging to @pascalkuthe though just to be sure this works for him.

That way it's possible to update it in future, for instance to add assymetric context options.

Co-authored-by: Sebastian Thiel <[email protected]> 1733756156 +0100
@Byron Byron force-pushed the context_size_option branch from 0832791 to 8517f10 Compare January 20, 2025 08:58
Copy link
Collaborator

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have rebased it against master and fixed the merge conflicts due to trait bounds. Further, I ran cargo fmt, so it's now pretty much the same as before.

Byron added a commit to Byron/gitbutler that referenced this pull request Jan 20, 2025
This is the initial state as pulled from

pascalkuthe/imara-diff#14 at state
pascalkuthe/imara-diff@8517f10

The idea is that once it stabilized for us we can hopefully contribute it back.
We'd also want to eventually use the released version of `imara-diff`.
Byron added a commit to Byron/gitbutler that referenced this pull request Jan 21, 2025
This is the initial state as pulled from

pascalkuthe/imara-diff#14 at state
pascalkuthe/imara-diff@8517f10

The idea is that once it stabilized for us we can hopefully contribute it back.
We'd also want to eventually use the released version of `imara-diff`.
Byron added a commit to Byron/gitbutler that referenced this pull request Jan 21, 2025
This is the initial state as pulled from

pascalkuthe/imara-diff#14 at state
pascalkuthe/imara-diff@8517f10

The idea is that once it stabilized for us we can hopefully contribute it back.
We'd also want to eventually use the released version of `imara-diff`.
Byron added a commit to Byron/gitbutler that referenced this pull request Jan 21, 2025
This is the initial state as pulled from

pascalkuthe/imara-diff#14 at state
pascalkuthe/imara-diff@8517f10

The idea is that once it stabilized for us we can hopefully contribute it back.
We'd also want to eventually use the released version of `imara-diff`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants