现在的位置: 首页 > 综合 > 正文

Managing_A_Working_Copy

2013年08月04日 ⁄ 综合 ⁄ 共 4472字 ⁄ 字号 评论关闭

Main


Managing A Working Copy

Finally we came to discussing the SVNKit high-level
API
 - the one for manipulating Working Copies. All Working Copy operations are logically organized in different SVN*Client classes. At the same time there's SVNClientManager class
which composes all SVN*Client classes and, thus, simplifies work on creating and keeping various client classes:

So, you may instantiate different SVN*Client classes separately or keep a single SVNClientManager for the same purposes. In fact, SVNClientManager instantiates each SVN*Client object
at the first time you request it, but not earlier.

Methods of each SVN*Client class are similar to commands of the Subversion
command line client
We will show several simple operations you can perform upon Working Copies using SVNKit. We write a class WorkingCopy which
utilizes an SVNClientManager object:

切换行号显示

   1 ...
   2 
   3 public class WorkingCopy {
   4 
   5     private static SVNClientManager ourClientManager;
   6     ...
   7 

Then go several demonstration functions that will be used in the main program. The following one creates a new directory immediately in a repository:

切换行号显示

   1     private static SVNCommitInfo makeDirectory( SVNURL url , String commitMessage ) throws SVNException {
   2         return ourClientManager.getCommitClient( ).doMkDir( new SVNURL[] { url } , commitMessage );
   3     }
   4 

This one imports a local directory to a repository:

切换行号显示

   1     private static SVNCommitInfo importDirectory( File localPath , SVNURL dstURL , String commitMessage , boolean isRecursive ) throws SVNException {
   2         return ourClientManager.getCommitClient( ).doImport( localPath , dstURL , commitMessage , isRecursive );
   3     }
   4 

This one recursively commits Working Copy modifications to a repository:

切换行号显示

   1     private static SVNCommitInfo commit( File wcPath , boolean keepLocks , String commitMessage ) throws SVNException {
   2         return ourClientManager.getCommitClient().doCommit( new File[] { wcPath } , keepLocks , commitMessage , false , true );
   3     }
   4 

This one checks out a Working Copy given a repository url:

切换行号显示

   1     private static long checkout( SVNURL url , SVNRevision revision , File destPath , boolean isRecursive ) throws SVNException {
   2 
   3         SVNUpdateClient updateClient = ourClientManager.getUpdateClient( );
   4         /*
   5          * sets externals not to be ignored during the checkout
   6          */
   7         updateClient.setIgnoreExternals( false );
   8         /*
   9          * returns the number of the revision at which the working copy is 
  10          */
  11         return updateClient.doCheckout( url , destPath , revision , revision , isRecursive );
  12     }
  13 

This one updates a Working Copy to a particular revision:

切换行号显示

   1     private static long update( File wcPath , SVNRevision updateToRevision , boolean isRecursive ) throws SVNException {
   2 
   3         SVNUpdateClient updateClient = ourClientManager.getUpdateClient( );
   4         /*
   5          * sets externals not to be ignored during the update
   6          */
   7         updateClient.setIgnoreExternals( false );
   8         /*
   9          * returns the number of the revision wcPath was updated to
  10          */
  11         return updateClient.doUpdate( wcPath , updateToRevision , isRecursive );
  12     }
  13 

This one switches a Working Copy to another url:

切换行号显示

   1     private static long switchToURL( File wcPath , SVNURL url , SVNRevision updateToRevision , boolean isRecursive ) throws SVNException {
   2         SVNUpdateClient updateClient = ourClientManager.getUpdateClient( );
   3         /*
   4          * sets externals not to be ignored during the switch
   5          */
   6         updateClient.setIgnoreExternals( false );
   7         /*
   8          * returns the number of the revision wcPath was updated to
   9          */
  10         return updateClient.doSwitch( wcPath , url , updateToRevision , isRecursive );
  11     }
  12 

This one recursively adds an existing local item under version control (schedules for addition):

切换行号显示

   1     private static void addEntry( File wcPath ) throws SVNException {
   2         ourClientManager.getWCClient( ).doAdd( wcPath , false , false , false , true );
   3     }
   4 

This one locks a versioned item:

切换行号显示

   1     private static void lock( File wcPath , boolean isStealLock , String lockComment ) throws SVNException {
   2         ourClientManager.getWCClient( ).doLock( new File[] { wcPath } , isStealLock , lockComment );
   3     }
   4 

This one deletes a versioned item from version control (schedules for deletion):

切换行号显示

   1     private static void delete( File wcPath , boolean force ) throws SVNException {
   2         ourClientManager.getWCClient( ).doDelete( wcPath , force , false );
   3     }
   4 

This function copies or moves one location to another one within the same repository:

切换行号显示

   1     private static SVNCommitInfo copy( SVNURL srcURL , SVNURL dstURL , boolean isMove , String commitMessage ) throws SVNException {
   2         return ourClientManager.getCopyClient().doCopy( srcURL , SVNRevision.HEAD , dstURL , isMove , commitMessage );
   3     }
   4 

We also need a function which will report us status (including remote status) of our Working Copy. The high-level API 

抱歉!评论已关闭.