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
Efficient hunking of multiple hunks #1118
Conversation
core/commands/diff.py
Outdated
|
||
def apply_diffs_for_pts(self, cursor_pts, reset): | ||
in_cached_mode = self.view.settings().get("git_savvy.diff_view.in_cached_mode") | ||
patches = unique(flatten(filter_(self.head_and_hunk_for_pt(pt) for pt in cursor_pts))) |
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.
Correct me if I'm wrong but I believe we can simply use a set (or set comprehension), as head_and_hunk_for_pt
returns either None or substr (which is guaranteed to be a string). What do you say?
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.
Hm, which parts of this line sould be replaceable? btw: head_and_hunk_for_pt -> Optional[Tuple[str, str]]
So we go:
List[Optional[Tuple[str, str]]]
- filter -> List[Tuple[str, str]]
- flat -> List[str]
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.
Yea tuples of strings are usable in set just fine. I'm suggesting:
patches = ''.join(set(flatten(filter_(self.head_and_hunk_for_pt(pt) for pt in cursor_pts))))
But now that I think of it, it might not be good to jumble up the order of the strings; at the very least the head and hunk should come together ? I think we can scrape my suggestion in that case.
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.
Yes for the outer unique, we must keep everything ordered.
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.
Basically
HEAD_A, HUNK_B, HEAD_A, HUNK_C, ...
->
HEAD_A, HUNK_B, HUNK_C
54518a6
to
b60c4c3
Compare
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.
Nice, love the mypy stubs for sublime! Are these sourced from somewhere? And if so, can we mention it (link to it) in the comment?
If you will I have the ©️ on the stubs. You start with |
I should put them on GitHub and link them to here and SublimeLinter etc of course. Not sure how to do that easily. |
If the user selected multiple hunks, we merge them to a single patch and apply it.
@kaste this only applies to standard diff, not inline-diff right? I'm not certain, but it feels to me like we should be allowing multi-line / multi-hunk staging in inline diff as well, maybe in a separate PR Anyway, this works fine for me, so let's merge |
Hooray |
Fixes #1105
Multiple hunks can be combined into a patch which then can applied at once.