How to Getting A Repository History With SVNKIt

來源:互聯網
上載者:User

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: 1240author: alexdate: Tue Aug 02 19:52:49 NOVST 2005log message: 0.9.0 is now trunkchanged paths: A      /trunk (from /branches/0.9.0 revision 1239)---------------------------------------------revision: 1263author: sadate: Wed Aug 03 21:19:55 NOVST 2005log 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: 1287author: sadate: Mon Aug 08 18:27:37 NOVST 2005log 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: 1294author: sadate: Tue Aug 09 02:46:29 NOVST 2005log message: corrected wc examples, modified javadoc files

 

 

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.