简体   繁体   English

如何以编程方式“即时”设置 SVN 存储库?

[英]How can I set up an SVN repository “on the fly” programmatically?

I'm setting up a system (PHP-based) that will let users instantly provision an SVN environment for use.我正在设置一个系统(基于 PHP),它可以让用户立即配置 SVN 环境以供使用。 It's an internal project so the users will mostly be internal users.这是一个内部项目,因此用户将主要是内部用户。

I haven't the foggiest idea where to even start.我什至不知道从哪里开始。 Are there SVN bindings for PHP, or am I going to have to use the svn console command?是否有用于 PHP 的 SVN 绑定,还是我必须使用svn控制台命令?

Here's one possibility.这是一种可能性。 You'll have a couple steps here.您将在这里执行几个步骤。 First, you need to create the svn repo in your PHP action script, maybe something like:首先,您需要在 PHP 操作脚本中创建 svn 存储库,可能类似于:

$name = $_REQUEST['name'];
// gonna need some sanity checking on $name here. no '..', no '/'s, etc
$cmd = 'svnadmin create ' . escapeshellarg('/var/svn/' . $name) . ' --fs-type fsfs';
exec('sudo ' . $cmd, $output, $exitValue);
if ($exitValue != 0) {
    // put the error message on the session, redirect out
}
$cmd = 'chown -R apache:apache ' . escapeshellarg('/var/svn/' . $name);
exec('sudo ' . $cmd, $output, $exitValue);
// error handling again

You'll need to set up sudo to allow your web server to run that svnadmin command.您需要设置 sudo 以允许您的 web 服务器运行该 svnadmin 命令。 Then you'll need to drop in a new apache.conf snippet in /etc/httpd/conf.d:然后你需要在 /etc/httpd/conf.d 中加入一个新的 apache.conf 片段:

<Location /$name>
   DAV svn
   SVNPath /var/svn/newproj
   #AuthType Basic
   #AuthName "SVN Repository"
   #AuthUserFile /var/svn/${name}.passwd
   #Require valid-user
</Location>

and restart Apache.并重新启动 Apache。 Maybe create that newproj htpasswd file too for security.为了安全起见,也许也创建那个 newproj htpasswd 文件。 Be sure to check and sanitize all passed form values ($_REQUEST).请务必检查并清理所有传递的表单值 ($_REQUEST)。 Hope this gets you started.希望这能让你开始。

Make it execute svnadmin create reponame to create the repo.让它执行svnadmin create reponame来创建 repo。 I don't think there are any libraries for this because you generally only find client side SVN libraries.我认为没有任何库可以解决这个问题,因为您通常只能找到客户端 SVN 库。

Just to make a suggestion "provisioning" Git repos is much simpler.只是提出“配置” Git 存储库的建议要简单得多。 And since there is no difference between client and server, your handling through git libraries ( http://code.google.com/p/git-php/ ) etc is very straightforward.而且由于客户端和服务器之间没有区别,因此您通过 git 库( http://code.google.com/p/git-php/ )等进行处理非常简单。 Of course you may only want SVN repos, but if you have the choice, go for git.当然,您可能只想要 SVN 存储库,但如果您有选择,go 用于 git。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM