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

Support multiple diff hunks #60

Closed
piranna opened this issue Jun 3, 2015 · 7 comments
Closed

Support multiple diff hunks #60

piranna opened this issue Jun 3, 2015 · 7 comments
Milestone

Comments

@piranna
Copy link
Contributor

piranna commented Jun 3, 2015

The method applyPatch() seems only support the first diff hunks, that don't allow to use it when a patch file has several chunks or chunks for several files. First case would be easy to do, just only continue for the next one. For the several files case it would be harder, but how could it be done, specially when you don't know the exact files that need to be patched? Maybe a hash object with the string content of the files, being the paths the key?

@kpdecker
Copy link
Owner

kpdecker commented Aug 6, 2015

@piranna apply should work with multiple chunks. Can you provide an example of the input and output you are seeing?

It does not support multiple files but there perhaps could be a callback-based API that would allow for something like that without too much effort.

@piranna
Copy link
Contributor Author

piranna commented Aug 6, 2015

@piranna apply should work with multiple chunks. Can you provide an example of the input and output you are seeing?

I did it only by eye-sign, I've just reviewed it and maybe it wronged me that at

hunks[0].added.push(diffstr[i].substr(1));
} else if (diffstr[i][0] === '-') {
hunks[0].removed.push(diffstr[i].substr(1));
} else if (diffstr[i][0] === ' ') {
hunks[0].added.push(diffstr[i].substr(1));
hunks[0].removed.push(diffstr[i].substr(1));
only it's updated hunks[0], but now I've seen they are being unshifted first, so hunks[0] is new each time, sorry.

It does not support multiple files but there perhaps could be a callback-based API that would allow for something like that without too much effort.

JsDiff could have a streams of objects that emit a data event for each different file in the original diffStr with the path of the file to be patched and the diffStr fragment that should be applied to that file, so later the user can call to applyPath() with the original file content and the diffStr fragment for that file.

@kpdecker kpdecker modified the milestones: 2.0.0, 2.1.0 Aug 6, 2015
@kpdecker
Copy link
Owner

kpdecker commented Aug 7, 2015

I'm working on separating the patch apply and parse logic. Once this is done, callers will be able to parse and then iterate over this object if they have multiple files.

@kpdecker
Copy link
Owner

kpdecker commented Aug 8, 2015

Implemented applyPatches which provides a series of callbacks that allow the caller to provide the file data. They are also able to manually call the new parsePatch method and iterate over this and then call applyPatch directly with the content of each file.

@piranna
Copy link
Contributor Author

piranna commented Aug 8, 2015

Really cool, thank you! :-D

@kpdecker
Copy link
Owner

Released in 2.1.0

@piranna
Copy link
Contributor Author

piranna commented Aug 27, 2015

👍 :-)

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

2 participants