Giter Site home page Giter Site logo

com.zutubi.diff's Introduction

Zutubi Diff

Introduction

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.

Home Page

Zutubi diff has home on the web at:

http://zutubi.com/source/projects/com.zutubi.diff/

License

Zutubi diff is licensed under the Apache License, version 2.0. See the LICENSE file for details.

Quick Start

The best way to illustrate usage is with a simple example:

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. See below for build instructions.

Supported Formats

Currently full support is provided for unified diffs in the package com.zutubi.diff.unified. Limited support for git diffs, an extension of the unified format used by git, Mercurial and other tools, is provided in the com.zutubi.diff.git package. At present application of git diffs is not implemented.

Building

A simple Gradle (http://gradle.org/) build is included. To build the library as a jar run:

$ gradle jar

The jar will appear in build/libs. There are no dependencies - the jar stands alone. The build has only been tested with Gradle 1.2.

Example

After building the main jar, you can build the example in a similar way. You can then run it as a very-limited version of patch:

$ cd examples/patch
$ gradle jar
$ java -jar build/libs/patch.jar -p3 < my.patch

The patch can only be applied to the working directory.

Javadoc

You can generate full Javadoc for the library by running:

$ gradle javadoc

The documentation will appear in build/docs/javadoc.

Feedback

Feedback and contributions are welcome! Please contact:

[email protected]

or simply fork away!

com.zutubi.diff's People

Contributors

daichiueura avatar danielostermeier avatar jsankey avatar sebkur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

com.zutubi.diff's Issues

Add support for creating unified diff / patch files

Just wondering whether it would be in the scope of this project to also create the diff (after all, the project is called com.zutubi.diff, not com.zutubi.patch ;-)

The motivation is that there does not seem to be a good / maintained Java library to create diffs out there. However, maybe some code out of JGit's diff package could be used to create one.

@jsankey What do you think?

Building the example

Hello there, Thanks for sharing this!

I was able to build the main jar, but when trying to build the example following the instruction in the README it fails:

~/Downloads/com.zutubi.diff-master/examples/patch โฎ€ gradle jar

FAILURE: Build failed with an exception.

  • Where:
    Build file '~/Downloads/com.zutubi.diff-master/examples/patch/build.gradle' line: 7

  • What went wrong:
    A problem occurred evaluating root project 'patch'.

    Could not find property 'manifest' on root project 'patch'.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.573 secs

Thanks!
-Sal

Unix patching for removed files does not work.

Git typical patch when file is removed returns "/dev/null" as a new file and hunk size is set to [0,0].

Currently library adds the file path on top of base directory (/abc/dev/null).

Its quite an issue to use zutubi patch with diffs. Also patch does not recognize that diff as remove type.

Is it git specific? Any example showing to patch directory with diff --git ?

Parsing fails on certain patch files

I see the following Exception while parsing a simple Git-generated patch file:

Exception in thread "main" com.zutubi.diff.PatchParseException: 10: Hunk old length 1 is not consistent with hunk lines
at com.zutubi.diff.unified.UnifiedPatchParser.checkConsistency(UnifiedPatchParser.java:259)
at com.zutubi.diff.unified.UnifiedPatchParser.parse(UnifiedPatchParser.java:146)
at com.zutubi.diff.git.GitPatchParser.parse(GitPatchParser.java:131)
at com.zutubi.diff.git.GitPatchParser.parse(GitPatchParser.java:64)
at com.zutubi.diff.PatchFileParser.read(PatchFileParser.java:69)
at com.zutubi.diff.PatchFileParser.parse(PatchFileParser.java:45)
at internal.tryout.ChangeListParser.main(ChangeListParser.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Sample patch file:
(https://github.com/Zutubi/com.zutubi.diff/files/859422/0001-added-second-line-to-1.txt.patch.txt)

Code used for testing:
ChangeListParser.txt

`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.