« Return to Thread: SVNKit behaves differently using file, svn and http protocols

Re: SVNKit behaves differently using file, svn and http protocols

by Alexander Kitaev-3 :: Rate this Message:

Reply to Author | View in Thread

Dear Ahsan,

 > Difference between file and svn protocols:
 > - When using the file protocol, any operation that fails within a
 > transaction (getCommitEditor() in SVNRepository class) will immediately
 > throw an exception (before the commit even), such as adding the same
 > file twice. The exception will be thrown right after the 2nd add.
 > - When using the svn protocol, any operation that fails within a
 > transaction will throw an exception only when commit is called
 > (closeEdit() in ISVNEditor class). So if you add the same file twice and
 > do a bunch of other operations it will not throw an exception until you
 > call closeEdit().
This is expected behavior - "svn" is network protocol and currently
implemented in such a way that client first sends requests and only then
reads server response. This is different from local repository access
when there is no separate client and server and exception could be
thrown back at any moment.

 > Difference between svn and http:
 > - When using  the svn protocol, you can add a file in any directory by
 > specifying the full path (addFile() method in the ISVNEditor class)
 > without having to call openDir on that directory. So for example, all I
 > had to do was call openRoot and then I could do
 > addFile("dirA/dirB/fileA") without having to call openDir("dirA/dirB")
 > and that would work fine.
 > - When using the http protocol, I cannot add a file using the full path
 > anymore. I have to call openDir("dirA/dirB") before calling
 > addFile(dirA/dirB/fileA). If I don't call openDir first, it will create
 > the file in the directory that is currently open. So for example, if I
 > call openRoot() and then call addFile(dirA/dirB/fileA), it will create
 > fileA in the root of the repo and not in dirA/dirB.
There are general rules on how to use ISVNEditor for commit operation.
In case you are not following those rules, then your code still may work
with some protocols and not work with others.

You may find an example on how to use ISVNEditor for commit operation at
https://wiki.svnkit.com/Committing_To_A_Repository

Shortly, the rule is that all parent directories should be "opened"
before working with child path.

Imagine, you have a repository with location at
http://host/repository/path and would like to delete file at
"/path/dir/subdir/file.txt" and change property of a directory
"/path/dir/subdir2" (paths relative to repository root). The code will
look like:

editor.openRoot(-1);
editor.openDir("dir");

editor.openDir("dir/subdir");
editor.deleteEntry("dir/subdir/file.txt");
editor.closeDir(); // dir/subdir

editor.openDir("dir/subdir2");
editor.changeDirProperty(...);
editor.closeDir(); // dir/subdir2

editor.closeDir(); // dir

editor.closeDir(); // root
editor.closeEdit();

So, first you have to use paths relative to SVNRepository location URL
(URL with which SVNRepository was created) and second you should
traverse the tree without any paths skipped. This way you'll make sure
that your code works with all protocols.

Alexander Kitaev,
TMate Software,
http://svnkit.com/ - Java [Sub]Versioning Library!

Ahsan Rabbani wrote:

> Hi all,
> I have noticed that certain SVNKit operations behave differently
> depending on the protocol I am using. Also, I am only referring to the
> low level API for directly manipulating a repository. I have not used or
> tried the higher level API for working copies so I can't say how it
> behaves with those. Has anyone else come across this? I can verify that
> these behavioural differences exist because I had a working code base
> that functioned as expected. I then switched the protocol from file to
> svn, and it broke. I then updated the code so it would work with the svn
> protocol, and then after some time I switched over to http and it broke
> again. The following are the differences I've encountered so far.
>
> Difference between file and svn protocols:
> - When using the file protocol, any operation that fails within a
> transaction (getCommitEditor() in SVNRepository class) will immediately
> throw an exception (before the commit even), such as adding the same
> file twice. The exception will be thrown right after the 2nd add.
> - When using the svn protocol, any operation that fails within a
> transaction will throw an exception only when commit is called
> (closeEdit() in ISVNEditor class). So if you add the same file twice and
> do a bunch of other operations it will not throw an exception until you
> call closeEdit().
>
> Difference between svn and http:
> - When using  the svn protocol, you can add a file in any directory by
> specifying the full path (addFile() method in the ISVNEditor class)
> without having to call openDir on that directory. So for example, all I
> had to do was call openRoot and then I could do
> addFile("dirA/dirB/fileA") without having to call openDir("dirA/dirB")
> and that would work fine.
> - When using the http protocol, I cannot add a file using the full path
> anymore. I have to call openDir("dirA/dirB") before calling
> addFile(dirA/dirB/fileA). If I don't call openDir first, it will create
> the file in the directory that is currently open. So for example, if I
> call openRoot() and then call addFile(dirA/dirB/fileA), it will create
> fileA in the root of the repo and not in dirA/dirB.
>
> Has anyone else come across any other differences like these? Is this
> normal behaviour that I just missed in the documentation?
>
> Thanks
> Ahsan

---------------------------------------------------------------------
To unsubscribe, e-mail: svnkit-users-unsubscribe@...
For additional commands, e-mail: svnkit-users-help@...

 « Return to Thread: SVNKit behaves differently using file, svn and http protocols