Differences between revisions 19 and 20
Revision 19 as of 2008-08-14 14:40:13
Size: 7337
Editor: gw
Comment:
Revision 20 as of 2008-08-19 15:15:25
Size: 9366
Editor: 194
Comment:
Deletions are marked like this. Additions are marked like this.
Line 128: Line 128:

----

'''
Q:
Hi,

Is there any way to distinguish svn moves from svn copies using the low
level API?
'''

A:
Yes, there is. Here is a short example demonstrating how to do that:

{{{#!java
public class Tests {

    public static void main(String[] args) {
        try {
            DAVRepositoryFactory.setup();
            SVNRepositoryFactoryImpl.setup();
            FSRepositoryFactory.setup();
            String url = args[0];
            SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
            
            repository.log(null, 0, -1, true, false, -1, false, null, new ISVNLogEntryHandler() {

                public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
                    Map changedPaths = logEntry.getChangedPaths();
                    for (Iterator changedPathsIter = changedPaths.keySet().iterator(); changedPathsIter.hasNext();) {
                        String changedPath = (String) changedPathsIter.next();
                        SVNLogEntryPath logEntryPath = (SVNLogEntryPath) changedPaths.get(changedPath);
                        
                        if (logEntryPath.getType() == SVNLogEntryPath.TYPE_ADDED && logEntryPath.getCopyPath() != null) {
                            SVNLogEntryPath copySourcePath = (SVNLogEntryPath) changedPaths.get(logEntryPath.getCopyPath());
                            if (copySourcePath != null && copySourcePath.getType() == SVNLogEntryPath.TYPE_DELETED) {
                                System.out.println("Path " + changedPath + " was moved from " +
                                        logEntryPath.getCopyPath() + " in revision " + logEntry.getRevision());
                                
                            }
                        }
                    }
                }
            });
            
            System.exit(0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

}}}

Main

Here on this page we will publish different user qeustions and answers to them that a visitor may find interesting for himself.

Q: I'm encountering performance issues refreshing a working copy accessed through a symbolic link.

For example I have a symbolic link named 'myProjects' in my home directory which links to /media/projects. When I use the command 'svn status myProjects/projectName' the operation is a lot slower than when I use 'svn status /media/projects/projectName'. Is this a known issue, can it be resolved?

A: Yes, this is a known problem. SVNKit supports versioned symbolic links and in order to resolve them uses expensive native program calls (ls). In case some of the working copy directory parents is a symbolic link, such calls are performed for every file in the working copy (because their absolute and canonical path differs and there is no way to say whether a file is a symbolic link or not, but calling ls command for it).

There are two workarounds for this problem:

1. Put your working copy or refer to it by it's "real" path, not by the one that includes symbolic link, that is what you already doing.

2. Disable versioned symbolic links support in SVNKit. To do that set the following System property:

-Dsvnkit.symlinks=false

(above is an option that you should add to the command line you're using to start your application)

at runtime you may call:

   1 SVNFileType.setSymlinkSupportEnabled(false);


Q: Can the current SVNKit version be forced to create pre-1.5 format working copies? My problem is I need to support the older working copy format (pre svn 1.5.0) and I assumed the new SVNKit automatically generates (and upgrades) working copies to this latest format. I thought the most recent 1.2.x release would do the trick.

A: Yes, you can configure SVNKit to use the pre-1.5 WC format by putting the following code somewhere in the startup function:

   1     SVNAdminAreaFactory.setSelector(new ISVNAdminAreaFactorySelector() {
   2         public Collection getEnabledFactories(File path, Collection factories, boolean writeAccess) throws                
   3                                                                                            SVNException  {
   4             Collection enabledFactories = new TreeSet();
   5             for (Iterator factoriesIter = factories.iterator(); factoriesIter.hasNext(); ) {
   6                 SVNAdminAreaFactory factory = (SVNAdminAreaFactory)factoriesIter.next();
   7                 int version = factory.getSupportedVersion();
   8                 if (version == SVNAdminAreaFactory.WC_FORMAT_13 || version == SVNAdminAreaFactory.WC_FORMAT_14) {
   9                     enabledFactories.add(factory);
  10                 }
  11              }
  12              return enabledFactories;
  13          }
  14     });

As you can see in this code snippet ISVNAdminAreaFactorySelector gives you an ability to switch off the 1.5 fromat admin area factory.

There is also a system property svnkit.upgradeWC, when set to false it will disable upgrade of existing working copies to the new format, but it still will be used for new directories, so first option (providing custom interface implementation) is preferable.

Since 1.2.0 version SVNKit provides an ability to downgrade working copy format. The following code snippet shows a way to achieve that:

   1     SVNClientManager clientManager = SVNClientManager.newInstance();
   2     SVNWCClient wcClient = clientManager.getWCClient();
   3     File wc = new File("/path/to/working/copy");
   4     wcClient.doSetWCFormat(wc, SVNAdminAreaFactory.WC_FORMAT_14);


Q: I wonder if the methods of SVNRepository (like .checkout an .update) are atomic: Is it possible (not probable) that another SVN client commit changes just while (not before or after) I am checking out or updating through these methods ?

A: SVNKit commit operations are atomic. That means that if you have two or more different clients committing (no matter whether they are all SVNKit clients or only one of them), they will be synchronized on the back end. In case of svn:// and http:// protocols commit finalizations are handled by the server itself (svnserve or mod_dav_svn), SVNKit client only sends necessary data and commands to the server, but the final step - writing to the repository - is undertaken by the server as you call ISVNEditor.closeEdit(). In case of the file:/// protocol SVNKit behaves like Subversion - it gets a write lock on a repository before making a transaction immutable the same way Subversion does it.

When updating via svn:// or http://: on the back end it is handled by the server itself, SVNKit receives data and commands to update, but what is happening on the back end, SVNKit doesn't matter (if something is wrong it's up to the server to deal with it). file:/// protocol update is implemented in a similar manner as in Subversion - it's a read operation and does not need any locks. Once it got the revision to update against it doesn't matter whether any commits are being performed: commits can create new repository files, but can not modify or delete existing ones, - you know each revision creates a new rev file in an FSFS repository. So your update will be absolutely consistent, although it doesn't mean that you will always get the latest revision when updating to HEAD revision - it may occur that after you started an update against a HEAD revision, someone started a new commit. But I believe it's true for Subversion, too.

So, the answer to your question is yes, it's possible and it's ok.


Q: I am also concerned about the use of the SVNCommitEditor object: In case of heavy editing through calls of the editor's methods it is possible, that another SVN client took a commit meanwhile. Does this cause trouble for the editor itself? I think a final (and atomic) commit is done by the editor through the call of its .closeEdit() method, not during the editing, or isn't it? To which revision does this refer, the HEAD revision at initialization of the editor or the HEAD revision at the .closeEdit() call?

A: No, it doesn't cause any trouble for the editor itself. Until a call to ISVNEditor.closeEdit() is made each transaction lives in it's own directory on the back end. And even if someone committed a new revision after you started your transaction but before you finished it, when you call ISVNEditor.closeEdit() SVNKit (in file:///) tries to merge all changes committed ever since. And if it sees that someone has changed the same files it aborts, notifying a user with an exception. However if it succeeds to merge all changes committed since the transaction was started a new revision it results to will also contain all previous modifications. It means it "refers" to the real HEAD revision, which may be equal or greater than transaction start point revision. That is a new transaction will be absolutely consistent. In other protocols the picture is the same but this work is handled by the server itself.


Q: Hi,

Is there any way to distinguish svn moves from svn copies using the low level API?

A: Yes, there is. Here is a short example demonstrating how to do that:

   1 public class Tests {
   2 
   3     public static void main(String[] args) {
   4         try {
   5             DAVRepositoryFactory.setup();
   6             SVNRepositoryFactoryImpl.setup();
   7             FSRepositoryFactory.setup();
   8             String url = args[0];
   9             SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
  10             
  11             repository.log(null, 0, -1, true, false, -1, false, null, new ISVNLogEntryHandler() {
  12 
  13                 public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
  14                     Map changedPaths = logEntry.getChangedPaths();
  15                     for (Iterator changedPathsIter = changedPaths.keySet().iterator(); changedPathsIter.hasNext();) {
  16                         String changedPath = (String) changedPathsIter.next();
  17                         SVNLogEntryPath logEntryPath = (SVNLogEntryPath) changedPaths.get(changedPath);
  18                         
  19                         if (logEntryPath.getType() == SVNLogEntryPath.TYPE_ADDED && logEntryPath.getCopyPath() != null) {
  20                             SVNLogEntryPath copySourcePath = (SVNLogEntryPath) changedPaths.get(logEntryPath.getCopyPath());
  21                             if (copySourcePath != null && copySourcePath.getType() == SVNLogEntryPath.TYPE_DELETED) {
  22                                 System.out.println("Path " + changedPath + " was moved from " + 
  23                                         logEntryPath.getCopyPath() + " in revision " + logEntry.getRevision());
  24                                 
  25                             }
  26                         }
  27                     }
  28                 }
  29             });
  30             
  31             System.exit(0);
  32         } catch (Exception e) {
  33             e.printStackTrace();
  34         }
  35     }
  36 }    

SVNKit_FAQ (last edited 2012-01-03 18:09:05 by ip-109-80-120-205)