-
-
Notifications
You must be signed in to change notification settings - Fork 196
Support for File Creation #47
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
Comments
Could you give me some example diff file, which I could include as a testcase for this behaviour? |
My scenario: I need a patch file that covers file creation. The provided method com.github.difflib.Diffutils#diff(List original, List revised) can not handle null input for original. Still you can use this method to get a valid set of patches. You just have to use an empty list as input parameter, because the changes per line are exactly the same for both cases (Meaning in both cases is something like "There was nothing before, but now there is."). So this works fine. But when you call com.github.difflib.UnifiedDiffUtils#processDeltas, you can not build the unified diff, because you can not tell the method if it should include the file creation, or not, because it always tries to "overcome the 0-offset Position", even if the 0-offset is exactly, what you need. Example: 1. Current result
2. Expected (additional) result
|
I will look into it for both versions of the unified diff processor. Do you use the Multifile variant? |
generateUnifiedDiff was changed in that way, that originalFileName == null switches to newfile mode. |
Nice. Thanks a lot! 👍 |
You are welcome. Did you check the new Unified diff implementation? |
Yes. It works as expected. :) |
Argh, I actually found a problem. :) You should extend your test case to check the first lines of the result as well:
You will see, that "null" is printed as the files originalName now. :) |
Hi there, I ran into a problem when I tried to create a unified diff for the creation of a new file, which seams not to be supported by your library right now.
As far as I can see, this feature is very easy to implement and could help others as well.
It requires just a small change in the UnifiedDiffUtils.processDeltas() method, some changes in the method signatures to get the info about the new File creation into the methods and maybe another method to keep calls to old method signature running with default values.
Actually it just those few lines in the main logic that could cover file creation:
Cheers, Eva
The text was updated successfully, but these errors were encountered: