• SVN Java 客户端 svnkit 查询两个日期或版本之间的文件差异,类似 svn diff 命令


    /*
     * Copyleft                      
     */
    import java.io.ByteArrayOutputStream;
    import java.nio.charset.Charset;
    import java.nio.charset.StandardCharsets;
    import java.util.Arrays;
    import java.util.Date;
    import java.util.List;
    
    import org.tmatesoft.svn.core.SVNDepth;
    import org.tmatesoft.svn.core.SVNException;
    import org.tmatesoft.svn.core.SVNURL;
    import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
    import org.tmatesoft.svn.core.internal.wc.SVNFileUtil;
    import org.tmatesoft.svn.core.wc.SVNClientManager;
    import org.tmatesoft.svn.core.wc.SVNRevision;
    
    /**
     * 
     * @author wongtp
     * @date 2023-09-12
     */
    public final class SvnUtils {
        
        private SvnUtils() { }
        
        /**
         * @param url  需要查询变更日志的根路径
         * @param username  SVN 用户名,注意需要对 url 有访问权限
         * @param password  SVN 密码
         * @param oldRevisionDate  变更日志开始时间
         * @param newRevisionDate  变更日志结束时间
         * @return  返回变更日志列表,逐行输出
         * @throws SVNException
         */
        public static List<String> getChangeLog(String url, String username, String password, Date oldRevisionDate, Date newRevisionDate) throws SVNException, IOException {
            DefaultSVNOptions svnOption = new DefaultSVNOptions();
            // 关掉认证信息缓存到磁盘
            svnOption.setAuthStorageEnabled(false);
            // 关闭自动查找配置
            svnOption.setUseAutoProperties(false);
            // 貌似没啥用,关掉关掉
            svnOption.setKeepLocks(false);
            
            SVNClientManager clientManager = SVNClientManager.newInstance(svnOption, username, password);
            try (ByteArrayOutputStream result = new ByteArrayOutputStream()) {
                SVNURL svnUrl = SVNURL.parseURIEncoded(url);
                SVNRevision oldVersion = SVNRevision.create(oldRevisionDate);
                SVNRevision newVersion = SVNRevision.create(newRevisionDate);
                
                clientManager.getDiffClient().doDiff(svnUrl, newVersion, oldVersion, newVersion, SVNDepth.INFINITY, false, result);
                
                Charset charset = SVNFileUtil.isWindows ? Charset.forName("gbk") : StandardCharsets.UTF_8;
                return Arrays.asList(new String(result.toByteArray(), charset).split(System.lineSeparator()));
            } finally {
                clientManager.dispose();
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
  • 相关阅读:
    密码学中的RSA算法与椭圆曲线算法
    数据类型【MySQL】
    猿创征文|Python基础——Visual Studio版本——Web开发
    awtk-ftpd 发布
    选座位吧(10)
    多张图片转为pdf怎么弄?
    nacos使用达梦数据库
    c++day5
    C语言--一个球从100m高度自由落下,每次落地后反弹回原高度的一半,再落下,再反弹。求它在第10次落地时共经过多少米,第10次反弹多高
    数据分析之Numpy、Pandas和Sklearn
  • 原文地址:https://blog.csdn.net/ocp114/article/details/132842040