简体   繁体   中英

Svnkit: getting the diffs between two commits revision remotely

I want to get the Diffs between two revisions using SvnKit. I have looked at the documentation and found this method in SVNRepository class but it checks only the diff between a local copy and a remote one.

diff(SVNURL url, long targetRevision, long revision, java.lang.String target, boolean ignoreAncestry, SVNDepth depth, boolean getContents, ISVNReporterBaton reporter, ISVNEditor editor)

is there anyway to get the diff for a certain repository for a range of revisions without downloading the repository ?

There're several APIs in SVNKit and SVNRepository-based API is the most low level, you need to have decent experience in working with Subversion internals to use it.

Instead it's better to use SvnOperationFactory-based API that works very similarly to "svn diff" command.

    final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
    try {
        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        final SvnDiffGenerator diffGenerator = new SvnDiffGenerator();
        diffGenerator.setBasePath(new File(""));

        final SvnDiff diff = svnOperationFactory.createDiff();
        diff.setSources(SvnTarget.fromURL(url, SVNRevision.create(revision1)), url, SVNRevision.create(revision2)));
        diff.setDiffGenerator(diffGenerator);
        diff.setOutput(byteArrayOutputStream);
        diff.run();
    } finally {
        svnOperationFactory.dispose();
    }

It calls SVNRepository#diff does a lot of work except that. If you need more control on the output, you can implement your own ISvnDiffGenerator and pass it to the operation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM