How to create a storable patch?
EasyG0ing1 opened this issue · comments
Without loading this down with details, I'll just say that I read over the examples and it seems like this library will do what I need it to do, but I can't figure something out.
I'm going to use the example text that you have in the examples to explain.
If I use the file issue10_base.txt
, then I apply issue10_patch.txt
, I can get the original file just fine. However, When I try to extract the patch from that original file when compared against issue10_base.txt
, this is how I'm doing it:
List<String> original = Files.readAllLines(ORIGINAL.toPath());
List<String> revised = Files.readAllLines(REVISED.toPath());
Patch<String> patch = DiffUtils.diff(original, revised);
String finalPatch;
for (AbstractDelta<String> delta : patch.getDeltas()) {
finalPatch = delta.toString();
}
//Store finalPatch in database;
The patch ends up looking like this:
[InsertDelta, position: 43, lines: [ <orderEntry type="library" name="Python 2.6.6 (/usr/bin/python2.6) interpreter library" level="application" />]]
But your patch looks like this:
--- /bonobo/bonobo.iml
+++ /bonobo/bonobo.iml
@@ -41,6 +40,7 @@
<SOURCES />
</library>
</orderEntry>
+ <orderEntry type="library" name="Python 2.6.6 (/usr/bin/python2.6) interpreter library" level="application" />
</component>
</module>
And when I roll your patch back onto the source, it patches it properly, but obviously mine does not.
How can I generate the patch to look like yours?
Never mind, I figured it out. I needed to use the UnifiedDiffUtils method shown in the examples
Good to see you figured it out. Thx for using diff utils.