zoukankan      html  css  js  c++  java
  • How to Getting A Repository History With SVNKIt

    In this example we'll demonstarte how you may get the history of changes made to a repository (i.e perform a log operation) starting with the very first revision and up to the very last one.

    public class History {
    
        public static void main( String[] args ) {
            DAVRepositoryFactory.setup( );
    
            String url = "http://svn.svnkit.com/repos/svnkit/trunk/doc";
            String name = "anonymous";
            String password = "anonymous";
            long startRevision = 0;
            long endRevision = -1; //HEAD (the latest) revision
    
            SVNRepository repository = null;
            try {
                repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( url ) );
                ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( name, password );
                repository.setAuthenticationManager( authManager );
    
                ...
                Collection logEntries = null;
                
                logEntries = repository.log( new String[] { "" } , null , startRevision , endRevision , true , true );
                ...

    We don't use paths to get only those revisions where paths were changed, so we pass an empty array new String[] { "" } to the log(...) method of the repository access driver.

    The second parameter is a Collection to receive history objects. Information about each revision is represented by a single SVNLogEntry object. We pass null since we don't need to fill an existing collection with history objects.

    Then we pass a range of revisions for which the history of changes to be fetched out.

    The fifth parameter controls whether information of all changed paths per revision should be included into histroy objects. Such information is represented by an SVNLogEntryPath object for each revision. We are going to print out all changed paths, so setting it to true.

    And the last parameter stricts node's history only to the node itself, what means that history of the node's ancestor (if the node has been copied) won't be included.

    Now let's print the collected information:

    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( ) + ")" : "" ) );
                    }
                }
            }

    And finally we run the program and have the following output in our console:

    ---------------------------------------------
    revision: 1240
    author: alex
    date: Tue Aug 02 19:52:49 NOVST 2005
    log message: 0.9.0 is now trunk
    
    changed paths:
     A      /trunk (from /branches/0.9.0 revision 1239)
    ---------------------------------------------
    revision: 1263
    author: sa
    date: Wed Aug 03 21:19:55 NOVST 2005
    log message: updated examples, javadoc files
     
    changed paths:
     M      /trunk/doc/javadoc-files/javadoc.css
     M      /trunk/doc/javadoc-files/overview.html
     M      /trunk/doc/examples/src/org/tmatesoft/svn/examples/wc/StatusHandler.java
    ---------------------------------------------
    revision: 1287
    author: sa
    date: Mon Aug 08 18:27:37 NOVST 2005
    log message: modified javadoc.css, packages overview
     
    changed paths:
     M      /trunk/doc/javadoc-files/javadoc.css
     M      /trunk/doc/javadoc-files/overview.html
     D      /trunk/doc/javadoc-files/subversion.png
     A      /trunk/doc/javadoc-files/info.png
    ---------------------------------------------
    revision: 1294
    author: sa
    date: Tue Aug 09 02:46:29 NOVST 2005
    log message: corrected wc examples, modified javadoc files

     

     

  • 相关阅读:
    品尝阿里云容器服务:负载均衡与容器的关系
    基于微服务架构、运行于容器中的.NET Core示例应用eShopOnContainers
    基于VS2017的Docker Support体检ASP.NET Core站点的Docker部署
    用工厂模式解决ASP.NET Core中依赖注入的一个烦恼
    终于知道什么情况下需要实现.NET Core中的IOptions接口
    ASP.NET Core Web API处理HttpResponseMessage类型返回值的问题
    ASP.NET Core奇遇记:无用户访问,CPU却一直100%
    省一行是一行:在if语句中使用C# 7.0的模式匹配
    ASP.NET Core 2.0 Preview 1 中贴心的新特性
    .NET Core类库项目中如何读取appsettings.json中的配置
  • 原文地址:https://www.cnblogs.com/malaikuangren/p/2776607.html
Copyright © 2011-2022 走看看