SVN

1、SVN服务器和客户端的安装及配置

参考http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407610.html
需注意的是:安装TortoiseSVN时最好把Command Line Client Tools也安装,否则不能在命令行里使用svn命令。


2、SVNKit

SVNKit是一个纯java的subversion客户端库,使用SVNKit无需安装任何subversion客户端,支持各种操作系统。可以编程实现TortoiseSVN的功能。

http://wiki.svnkit.com/Printing_Out_Repository_History 有很多DEMO,可参考。

2.1、使用SVNKit按照时间段来获取SVN资源库的历史操作记录
// 版本库初始化
        DAVRepositoryFactory.setup();

        // 资源库相关登录配置信息
        String url = "SVN资源库地址";
        String username = "stypace";
        String password = "123456";
        long startRevision = 0;// 最初版本
        long endRevision = -1;//最近版本

        // 资源库
        SVNRepository repository = null;

        try {
            // 时间参数
            final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            //			final Date begin = format.parse(args[0]);
            //			final Date end = format.parse(args[1]);

            final Date begin = format.parse("2015-01-27 10:30:00");
            final Date end = format.parse("2015-01-27 20:00:00");

            // 建立一个新的资源库
            repository = DAVRepositoryFactory.create(SVNURL.parseURIEncoded(url));
            // 登录确认信息
            ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(
                username, password);
            repository.setAuthenticationManager(authManager);
            // 存放结果
            final Collection logEntries = new ArrayList<SVNLogEntry>();
            // 执行log函数,根据时间参数获取历史记录
            repository.log(new String[] { "" }, startRevision, endRevision, true, true,
                new ISVNLogEntryHandler() {
                    public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
                        // 依据提交时间进行过滤
                        if (logEntry.getDate().after(begin) && logEntry.getDate().before(end)) {
                            addLogEntry(logEntry);
                        }
                    }

                    public void addLogEntry(SVNLogEntry logEntry) {
                        logEntries.add(logEntry);
                    }
                });
            // 遍历
            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 = logEntry.getChangedPaths().get(
                            changedPaths.next());
                        System.out
                            .println(" "
                                     + entryPath.getType()
                                     + " "
                                     + entryPath.getPath()
                                     + ((entryPath.getCopyPath() != null) ? " (from "
                                                                            + entryPath
                                                                                .getCopyPath()
                                                                            + " revision "
                                                                            + entryPath
                                                                                .getCopyRevision()
                                                                            + ")" : ""));
                    }
                }
            }

        } catch (Exception ex) {
            System.out.println(ex.toString());
        }

        System.exit(1);
    }


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值