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

Apply patch on current state #20

Open
DavidGamba opened this issue Sep 21, 2015 · 5 comments
Open

Apply patch on current state #20

DavidGamba opened this issue Sep 21, 2015 · 5 comments
Labels

Comments

@DavidGamba
Copy link

I would really like to be able to apply a patch from a previous undo onto my current state, not just having to revert completely to that state.

For example, in the image below, apply the patch made on 3 onto my current state 6, leaving me in a new state 7 with the patch from 3 applied.

gundo-tree

Thanks for picking up the development of this plugin :-)

@dsummersl
Copy link
Collaborator

Thanks for the suggestion!

I foresee problems with conflicts if we implemented this feature...although I guess we could simply apply the patch, conflict markers and all, and let the user figure out how to resolve them.

One thing you can do now is navigate to '3' and press 'd' to diff 3 with 6. You can then pull over the changes you want to get to 7 - not quite automatic, but possble at the moment...

@DavidGamba
Copy link
Author

Thanks for the quick reply and for pointing out the temporary workaround. I think having this feature will speed workflow quite a bit.

we could simply apply the patch, conflict markers and all, and let the user figure out how to resolve them.

That behaviour sounds correct to me. If the user doesn't like the conflict patch they can always undo ;-)
In most cases patches will apply cleanly though.

@wsdjeg
Copy link
Contributor

wsdjeg commented Jan 10, 2016

I think it is just like the git tree,if you want to merged 3 into 6 ,I think it is not git fast forward,so there maybe some issues.I think it is better do it manully

@simnalamburt simnalamburt changed the title feature: Apply patch on current state Apply patch on current state Mar 7, 2017
@TamaMcGlinn
Copy link

Certainly, it is a non-trivial feature. But, (along with undo'ing just that change) if possible, it would be a very useful feature. Quite often the changes would not conflict.

I think the best way would be to construct a git repository in-memory of the current file, and apply the 3 changes required (the state before the selected change, the state at that change, and the current state) as three commits, and then do the cherry-pick or revert respectively and make a new change in the buffer which sets the state to whatever git output; which would often be non-conflicted, and would otherwise have conflict markers in the file.

@dsummersl
Copy link
Collaborator

We do use difflib under the covers to generate the unified diff format; we could simply implement 'apply patch' two a set of strings. This provides some options: https://stackoverflow.com/questions/2307472/generating-and-applying-diffs-in-python

My best guess of a heuristic:

  • Generate the unified diff of the two versions of the buffers (already being done in mundo). Suppose the diff is from version n in the undo history, and version z for the revision of our current buffer.
  • Apply each hunk of the unified diff into the current buffer.
  • If all hunks applied successfully, we're done.
  • If any hunk does not apply we need to communicate this to the user in some way:
    • maybe show the diff of the n + 1 undo with the current buffer (it'll contain whatever hunks that failed to apply - but also all changes from n+1..z).
    • keep track of the hunks that ailed to apply and show them in a scratch buffer, maybe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants