zutubi diff

Zutubi Diff is a Java library for parsing and applying patch files in unified diff and other formats. You can think of it as the library equivalent of the patch(1) utility, with the beginnings of support for more than just unified diffs.

quick start

The best way to start is to grab the latest jar from the downloads page and add it to your project. There are no additional dependencies. Here is a taste of code to parse and apply a diff:

PatchFileParser parser = new PatchFileParser(new UnifiedPatchParser());
PatchFile patchFile = parser.parse(new FileReader("/path/to/my.patch"));
patchFile.apply(toDirectory, 3);

This code parses a patch from the file my.patch and applies it to the directory toDirectory, stripping 3 slashes from the paths. It is analogous to running:

$ cd toDirectory
$ patch -p3 < /path/to/my.patch

Full code for this example can be found in the examples/patch directory. Javadoc may be generated by running:

$ gradle javadoc

in the source tree (requires a recent Gradle, docs appear in build/docs/javadoc).

supported formats

Currently full support is provided for unified diffs (the default for patches). Limited support for git diffs, an extension of the unified format used by git, Mercurial and other tools, is also provided. At present application of git diffs is not implemented.

license

Zutubi Diff is available under the Apache License, version 2.0. The license is quite liberal, even for commercial applications. See the LICENSE file for details.

more information

Want to learn more? Check out the following resources:

feedback

If you have any thoughts, questions etc about the tasks, you can contact me at:

jason@zutubi.com

Or you can submit an issue or pull request via GitHub. All feedback is welcome.