svnkit:通过java操作svn

官方文档:http://wiki.svnkit.com/Getting_Started_With_SVNKit

demo: 获取提交历史

public static List<String> getLogs() throws SVNException{
        /*
         * 对版本库进行初始化操作,使用https或http访问svn时,执行DAVRepositoryFactory.setup(); 对于通过使用svn:// 和 svn+xxx://
         * 访问svn时,执行SVNRepositoryFactoryImpl.setup(); 对于通过file:/// 访问svn的情况,执行 FSRepositoryFactory.setup();
         */
        String url = "http://10.27.164.97/svn/imp/branches/imp_V1.0.5";
        String name = "15050886";
        String password = "sn9988&";
        long startRevision = 0;
        long endRevision = -1; // HEAD (the latest) revision

        SVNURL svnurl = SVNURL.parseURIEncoded(url); // 某目录在svn的位置,获取目录对应的URL。即版本库对应的URL地址
        DAVRepositoryFactory.setup(); // 初始化
        ISVNOptions options = SVNWCUtil.createDefaultOptions(true); // 驱动选项
        ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password); // 提供认证

        SVNRepository repos = SVNRepositoryFactory.create(svnurl);
        repos.setAuthenticationManager(authManager); // 设置认证

        Collection logEntries = null;
        List<String> result = new ArrayList<String>();
        logEntries = repos.log(new String[] { "" }, null, startRevision, endRevision, true, true);
        
        for (Iterator entries = logEntries.iterator(); entries.hasNext();) {
            SVNLogEntry logEntry = (SVNLogEntry) entries.next();
            System.out.println("---------------------------------------------");
            System.out.println("revision: " + logEntry.getRevision());
            System.out.println("author: " + logEntry.getAuthor());
            System.out.println("date: " + logEntry.getDate());
            System.out.println("log message: " + logEntry.getMessage());

            if (logEntry.getChangedPaths().size() > 0) {
                System.out.println();
                System.out.println("changed paths:");
                Set changedPathsSet = logEntry.getChangedPaths().keySet();

                for (Iterator changedPaths = changedPathsSet.iterator(); changedPaths.hasNext();) {
                    SVNLogEntryPath entryPath = (SVNLogEntryPath) logEntry.getChangedPaths().get(changedPaths.next());
                    System.out.println(" "
                            + entryPath.getType()
                            + " "
                            + entryPath.getPath()
                            + ((entryPath.getCopyPath() != null) ? " (from " + entryPath.getCopyPath() + " revision "
                                    + entryPath.getCopyRevision() + ")" : ""));
                    result.add(entryPath.getPath());
                }
            }
        }
        // 倒序
        Collections.reverse(result);
        return result;
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值