Differences between revisions 2 and 3
Revision 2 as of 2007-02-19 10:56:54
Size: 5292
Editor: 193
Comment:
Revision 3 as of 2007-02-20 14:18:30
Size: 5804
Editor: host-85-118-226-179
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[:Printing Out File Contents:<< Previous Page] ["Main"]
 .+ ["What Is Subversion For"]
 .+ ["Setting Up A Subversion Repository"]
 .+ ["SVNKit Architecture"]
 .+ ["Getting Started With SVNKit"]
 .+ ["Authentication"]
 .+ ["Managing Repository With SVNKit"]
  .+ ["Printing Out A Subversion Repository Tree"]
  .+ ["Printing Out File Contents"]
  .- Printing Out Repository History
  .+ [:Committing To A Repository:Editing operation: committing to a repository]
  .+ [:Updating From A Repository:Editing Operation: receiving changes from a repository]
  .+ ["Replicating An Existing Repository"]
  .+ ["Managing A Working Copy"]
Line 3: Line 16:
[:Committing To A Repository:Next Page >>] ----

["Main"]

  • + ["What Is Subversion For"]
  • + ["Setting Up A Subversion Repository"]
  • + ["SVNKit Architecture"]
  • + ["Getting Started With SVNKit"]
  • + ["Authentication"]
  • + ["Managing Repository With SVNKit"]
    • + ["Printing Out A Subversion Repository Tree"]
    • + ["Printing Out File Contents"]
    • - Printing Out Repository History
    • + [:Committing To A Repository:Editing operation: committing to a repository]

    • + [:Updating From A Repository:Editing Operation: receiving changes from a repository]

    • + ["Replicating An Existing Repository"]
    • + ["Managing A Working Copy"]


Getting A Repository History

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.

   1 ...
   2 
   3 public class History {
   4 
   5     public static void main( String[] args ) {
   6         DAVRepositoryFactory.setup( );
   7 
   8         String url = "http://svn.svnkit.com/repos/svnkit/trunk/doc";
   9         String name = "anonymous";
  10         String password = "anonymous";
  11         long startRevision = 0;
  12         long endRevision = -1; //HEAD (the latest) revision
  13 
  14         SVNRepository repository = null;
  15         try {
  16             repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( url ) );
  17             ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( name, password );
  18             repository.setAuthenticationManager( authManager );
  19 
  20             ...
  21             Collection logEntries = null;
  22             
  23             logEntries = repository.log( new String[] { "" } , null , startRevision , endRevision , true , true );
  24             ...

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 [http://svnkit.com/kb/javadoc/org/tmatesoft/svn/core/SVNLogEntry.html 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 [http://svnkit.com/kb/javadoc/org/tmatesoft/svn/core/SVNLogEntryPath.html 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:

   1         ...      
   2         for ( Iterator entries = logEntries.iterator( ); entries.hasNext( ); ) {
   3             SVNLogEntry logEntry = ( SVNLogEntry ) entries.next( );
   4             System.out.println( "---------------------------------------------" );
   5             System.out.println ("revision: " + logEntry.getRevision( ) );
   6             System.out.println( "author: " + logEntry.getAuthor( ) );
   7             System.out.println( "date: " + logEntry.getDate( ) );
   8             System.out.println( "log message: " + logEntry.getMessage( ) );
   9 
  10             if ( logEntry.getChangedPaths( ).size( ) > 0 ) {
  11                 System.out.println( );
  12                 System.out.println( "changed paths:" );
  13                 Set changedPathsSet = logEntry.getChangedPaths( ).keySet( );
  14 
  15                 for ( Iterator changedPaths = changedPathsSet.iterator( ); changedPaths.hasNext( ); ) {
  16                     SVNLogEntryPath entryPath = ( SVNLogEntryPath ) logEntry.getChangedPaths( ).get( changedPaths.next( ) );
  17                     System.out.println( " "
  18                             + entryPath.getType( )
  19                             + " "
  20                             + entryPath.getPath( )
  21                             + ( ( entryPath.getCopyPath( ) != null ) ? " (from "
  22                                     + entryPath.getCopyPath( ) + " revision "
  23                                     + entryPath.getCopyRevision( ) + ")" : "" ) );
  24                 }
  25             }
  26         }
  27         ...
  28     }
  29 }

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


Download the [http://svn.svnkit.com/repos/svnkit/trunk/doc/examples/src/org/tmatesoft/svn/examples/repository/History.java example program source code].

Printing_Out_Repository_History (last edited 2012-01-03 18:04:25 by ip-109-80-120-205)