Search code examples
javasvnsvnkit

How to use SVNKit to get the list of all revisions merged from one branch to another?


Purpose:

As a quality check, we need to make sure that all qualified revisions are merged up to all higher revisions.

Example:

Release_10 --> Release_11

In TortoiseSVN, it is very easy to figure out which revisions have been merged by clicking the "Show Log" button. Merged revisions are clearly distinguished by formatting and a merge icon.

You can also list all merged revisions through pure SVN:

C:\Release_11>svn mergeinfo --show-revs merged https://svn_repo/project/branches/releases/Release_10
r32894
r32897
r32901
r32903
r32929
r32987
r32994
r32996
r33006
r33017
r33020
r33021
r33041
r33045
r33077

Currently, I have the code that lists all revision info:

SVNURL svnURL = SVNURL.parseURIEncoded(url);
SVNRepository repository = SVNRepositoryFactory.create(svnURL);
BasicAuthenticationManager authManager = BasicAuthenticationManager.newInstance("username", "password".toCharArray());
authManager.setProxy("00.00.00.00", 8080, null, (char[])null);
repository.setAuthenticationManager(authManager);
@SuppressWarnings("unchecked")
Collection<SVNLogEntry> logEntries = repository.log(new String[] { "" }, null, 0, -1, true, true);

Now I just need to figure out which ones have been merged.

Preferences:

  1. A single call to the repo to get all merged revisions. (Or better yet: A single call to get all the revisions and whether or not they were merged.)
  2. Would prefer not to have a local checkout of the SVN repo.

Notes:

  • Using SVNKIT v1.8.14, but am not locked into a specific revision.

Solution

  • If you run svn mergeinfo with absolute URLs for both source and target, you won't need a local checkout of the repository:

    svn mergeinfo --show-revs merged https://svn_repo/project/branches/releases/Release_10 https://svn_repo/project/branches/releases/Release_11
    

    To run this command, on SVNKit 1.7 or later, you can use SvnLogMergeInfo:

    SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
    try {
        String repo = "https://svn_repo/project/branches/releases/";
        String srcBranch = repo + "Release_10";
        String dstBranch = repo + "Release_11";
    
        // svnOperationFactory.setAuthenticationManager(null);
    
        SvnLogMergeInfo op = svnOperationFactory.createLogMergeInfo();
        op.setFindMerged(true); // --show-revs merged
        op.setSource(SvnTarget.fromURL(SVNURL.parseURIEncoded(srcBranch)));
        op.setSingleTarget(SvnTarget.fromURL(SVNURL.parseURIEncoded(dstBranch)));
        op.setReceiver(new ISvnObjectReceiver<SVNLogEntry>() {
    
            @Override
            public void receive(SvnTarget target, SVNLogEntry logEntry) throws SVNException {
                System.out.println("------\n" + logEntry);
            }
    
        });
        op.run();
    } finally {
        svnOperationFactory.dispose();
    }
    

    For older versions, you can use SVNDiffClient.doGetLogMergedMergeInfo.