1

我正在尝试在 java 中创建一个方法,它将把以前的修订版放回我的存储库中。我尝试了几种选择,但直到现在都没有成功。我认为我尝试过的最佳选择是在以下测试类中:

package svntest;

import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.internal.wc.SVNSynchronizeEditor;
import org.tmatesoft.svn.core.io.ISVNReporter;
import org.tmatesoft.svn.core.io.ISVNReporterBaton;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

public class Test {

    static String url = "myhost:8080/svn/sonic76/branches/TEST/myproject";

    public static void main(String[] args) {
        try {
            DAVRepositoryFactory.setup();
            SVNRepositoryFactoryImpl.setup();
            FSRepositoryFactory.setup();
            ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(user, password);           
            SVNRepository srcRepos = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
            srcRepos.setAuthenticationManager(authManager);
            SVNRepository destRepos = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
            destRepos.setAuthenticationManager(authManager);
            SVNSynchronizeEditor syncher = new SVNSynchronizeEditor(destRepos, null, SVNRevision.BASE.getNumber(), null);
            srcRepos.update(SVNURL.parseURIEncoded(url), SVNRevision.BASE.getNumber()-1, null, SVNDepth.INFINITY, new MyReporterBaton(), syncher);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static class MyReporterBaton implements ISVNReporterBaton {
        @Override
        public void report(ISVNReporter reporter) throws SVNException {
            reporter.setPath("", null, 32981, false);
            reporter.finishReport();
        }
    }
}

我得到的错误是:

org.tmatesoft.svn.core.SVNException: svn: E160024: File or directory 'xml/myfile.xml' is out of date; try updating
svn: E160024: resource out of date; try updating

文件夹 xml 中的文件 myfile.xml 正是在当前版本和上一个版本之间发生更改的文件,我想放回以前的版本。有任何想法吗?

如您所见,我使用的是 svnkit,但任何其他 API 也可以。

4

0 回答 0