开发者

Can I use PHP4 to interact with an SVN repository without a working copy?

开发者 https://www.devze.com 2022-12-15 17:06 出处:网络
I would like to perform SVN operations on an SVN repository (over HTTP, if it matters) without requiring a working copy. Basically, here are the things I want to do:

I would like to perform SVN operations on an SVN repository (over HTTP, if it matters) without requiring a working copy. Basically, here are the things I want to do:

  1. Check if a directory exists remotely.

    • If the directory does not exist, create it
  2. Check if a file exists in the repository

    1. if the file does not exist, create a new file in the repository with my content
      • This has to use an author name that I provide, not the authenticated WebDAV author (which is why the WebDAV approach doesn't work for me)
    2. If the file does exist, replace its contents with the contents of my specified file.

I have been trying to use the autoversioning approach, but that method requires me to set up authentication for the WebDAV server, which is less than ideal in my circumstance. I could use FS operations (the client is SVN 1.6, so shallow working copies + command line would work) but that's both slow and in开发者_Go百科elegant.

Is there a library (which MUST be useable from PHP 4.4!) that can do what I describe?


From what little experience I have dabbling with SVN from PHP: If you have command line access from your PHP script to the svn executable, go that way.

It's always faster than a PHP implementation of the protocol, and more reliable.

All PHP SVN clients I've tried had flaws, bugs, or were altogether shaky. (I don't know the PECL one, though.)


Find the svn commandline, or svn extension equivalents of:

check if a directory exists remotely.

svn info <URL>

If the directory does not exist, create it

svn mkdir <URL>

Check if a file exists in the repository

svn info <URL>

if the file does not exist, create a new file in the repository with my content

This one is harder without a working copy. You could create a tempfile and then:

svn import /tmp/mytempfile <URL>

If the file does exist, replace its contents with the contents of my specified file.

svn delete <URL>

followed by the above, you can't modify a file without a working copy. Note that this causes a very suboptimal use of Subversion. It's designed to store changes, not files. I wouldn't recommend a delete/import to change a few lines of text.

This has to use an author name that I provide, not the authenticated WebDAV author (which is why the WebDAV approach doesn't work for me)

You can't provide an arbitrary author name using webdav, you authenticate over HTTP(S) to the remote server, and that name is used as author. If you need another name, you need to create another user on the server, and give that user access to the repository.


You can try this class: http://www.phpclasses.org/browse/package/4270.html

It's supposedly working starting at PHP 3...


Maybe the PECL::svn extension (manual) would do ?

For the last version, the requirement is :

PHP Version: PHP 4.0.0 or newer


And it seems there are functions that could do what you want ; for instance :

  • svn_mkdir : Creates a directory in a working copy or repository.

But not sure the are functions for everything you want, though...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号