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

Making split hunks addable #1

Open
mtsgrd opened this issue Apr 24, 2024 · 0 comments
Open

Making split hunks addable #1

mtsgrd opened this issue Apr 24, 2024 · 0 comments

Comments

@mtsgrd
Copy link

mtsgrd commented Apr 24, 2024

Since we are actually starting with the merge conflict resolution in our
directory and creating the conflicting versions manually, we should be able
to record what the resolution is, detect it and apply the recorded resolution
automatically.

The problem as I understand it is that it's easy to separate a diff into two the way github desktop does it, but putting them back together doesn't work.. But what if we only needed to store and cascade the original line number when splitting diffs to make them addable again?

As an example, if we split this:

@@ -1,4 +1,7 @@
 a
 b
+c
+d
+e
 f
 g

into these two:

@@ -1,4 +1,5 @@
 a
 b
+d // original line 4
 f
 g
@@ -1,4 +1,6 @@
 a
 b
+c  // original line 3
+e  // original line 5
 f
 g

Then we have enough information to reverse the split? It works even if we split the second diff into two again.

Note: One issue at this stage would be if we paste some function up higher and it
shifts all the lines and then we run the status call again, will we match the
hunk ranges properly? I don't really know enough about exactly how we handle
this scenario now, but if it's difficult, we could keep a cache of what "splits"
we have by content and try to match based on that. But let's tackle this later,
it should be doable one way or another.

Also, about matching up the hunk ranges properly. I don't think we do a good enough job right now, but with a bit of effort we could have something quite solid that matches based on both line range intersection as well as the similarity score @Qix- coded up a while back.

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

No branches or pull requests

1 participant