Svnkit:远程修改两个提交之间的差异

时间:2017-03-31 19:40:18

标签: java svn svnkit

我想使用SvnKit获得两个版本之间的差异。我查看了文档并在SVNRepository类中找到了这个方法,但它只检查本地副本和远程副本之间的差异。

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

无论如何都可以在不下载存储库的情况下为一系列修订获取某个存储库的差异?

1 个答案:

答案 0 :(得分:1)

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.