接觸Subversion

空間IDC提供Subversion功能.偶好奇查了查,
好像是一個項目開發與版本控制系統,CVS的替代產品.
雖然一般大型程序開發才會用這個東西,不過了解一下,應該不錯.

Subversion的一些資料(搜羅自網絡,與Subversion官方站點 http://subversion.tigris.org/)

Subversion快速入門教程(轉)
作者: Rock Sun
2005-10-20
如何快速建立Subversion服務器,並且在項目中使用起來,這是大家最關心的問題,與CVS相比,Subversion有更多的選擇,也更加的容易,幾個命令就可以建立一套服務器環境,可以使用起來,這裡配套有動畫教程。

本文是使用Subversion最快速的教程,在最短的時間裡幫助您建立起一套可用的服務器環境,只需略加調整就可以應用到實際項目當中。

本教程分為以下幾個部門,不僅僅是快速入門,最後我們還有一些高級功能的說明,為了說明簡單,教程是在windows下使用的方式,以方便資源有限的項目使用,對於UNIX環境下,區別並不大。

1. 軟件下載
2. 服務器和客戶端安裝
3. 建立版本庫(Repository)
4. 配置用戶和權限
5. 運行獨立服務器
6. 初始化導入
7. 基本客戶端操作

1,軟件下載

* 下載Subversion服務器程序。

到官方網站 的下載二進制安裝文件,來到二進制包下載部分 ,找到 Windows NT, 2000, XP and 2003部分,然後選擇”this directory”,這樣我們可以看到許多下載的內容,目前可以下栽 svn-1.2.3-setup.exe。

* 下載Subversion的Windows客戶端TortoiseSVN。

TortoiseSVN是擴展Windows Shell的一套工具,可以看作Windows資源管理器的插件,安裝之後Windows就可以識別Subversion的工作目錄。
官方網站是TortoiseSVN,下載方式和前面的svn服務器類似,在Download頁面的我們選擇Official version for Win2k/XP or higher的版本,然後在sourceforge的下載頁面選擇目前的最高穩定版本的安裝文件TortoiseSVN-1.2.4.4479-svn-1.2.3.msi。

2,服務器和客戶端安裝

* 服務器安裝,直接運行svn-1.2.3-setup.exe,根據提示安裝即可,這樣我們就有了一套服務器可以運行的環境。
* 安裝TortoiseSVN,同樣直接運行TortoiseSVN-1.2.4.4479-svn-1.2.3.msi按照提示安裝即可,不過最後完成後會提示是否重啟,其實重啟只是使svn工作拷貝在windows中的特殊樣式生效,與所有的實際功能無關,這裡為了立刻看到好的效果,還是重新啟動機器。

3,建立版本庫(Repository)

運行Subversion服務器需要首先要建立一個版本庫(Repository),可以看作服務器上存放數據的數據庫,在安裝了Subversion服務器之後,可以直接運行,如:

svnadmin create E:\svndemo\repository

就會在目錄E:\svndemo\repository下創建一個版本庫。

我們也可以使用TortoiseSVN圖形化的完成這一步:

在目錄E:\svndemo\repository下”右鍵->TortoiseSVN->Create Repository here…“, 然後可以選擇版本庫模式, 這裡使用默認即可, 然後就創建了一系列目錄和文件。

4,配置用戶和權限

來到E:\svndemo\repository\conf目錄,修改svnserve.conf:

# [general]
# password-db = passwd

改為:

[general]
password-db = passwd

然後修改同目錄的passwd文件,去掉下面三行的注釋:

# [users]
# harry = harryssecret
# sally = sallyssecret

最後變成:

[users]
harry = harryssecret
sally = sallyssecret

5,運行獨立服務器

在任意目錄下運行:

svnserve -d -r E:\svndemo\repository

我們的服務器程序就已經啟動了。

6,初始化導入

來到我們想要導入的項目根目錄,在這個例子里是E:\svndemo\initproject,目錄下有一個readme.txt文件:

1. 右鍵->TortoiseSVN->Import…
2. URL of repository輸入“svn://localhost/trunk”
3. ok

完成之後目錄沒有任何變化,如果沒有報錯,數據就已經全部導入到了我們剛才定義的版本庫中。

7,基本客戶端操作

取出版本庫到一個工作拷貝:

來到任意空目錄下,在本例中是E:\svndemo\wc1,運行右鍵->Checkout,在URL of repository中輸入svn://localhost/trunk,這樣我們就得到了一份工作拷貝。

在工作拷貝中作出修改並提交:

打開readme.txt,作出修改,然後右鍵->Commit…,這樣我們就把修改提交到了版本庫,我們可以運行。

察看所作的修改:

readme.txt上右鍵->TortoiseSVN->Show Log,這樣我們就可以看到我們對這個文件所有的提交。在版本1上右鍵->Compare with working copy,我們可以比較工作拷貝的文件和版本1的區別。

最後,所有的內容都已經錄製為動畫文件,大家可以參考。

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=537628

Subversion基本使用
客戶端組件供使用者使用,主要包括以下兩個組件:
svn 是命令行客戶端程序,用來管理數據.
Svnversion 用來查看工作拷貝的混合版本狀態.
服務器組件供管理員使用,包括以下幾個組件:
svnadmin 用來創建與調整Subversion的文件庫的工具.
svnlook 用來查看Subversion的文件庫的工具.
一,Subversion在項目中用到的操作
檔案庫的兩種配置方案:

方案1 方案2
個人意見:
如果projectA和projectB之間互相獨立,則使用方案1比較好管理.
如果projectA和projectB之間聯繫的比較緊密,則使用方案2比較好管理.
創建文件庫(新建一個項目),命令如下: (服務端操作)
mkdir /usr/local/svn
svnadmin create /usr/local/svn /java
將目錄doc的內容,直接導入至文件庫的fox目錄里,命令如下:
mkdir java
mkdir java/trunk //主線
mkdir java/branches //分支
mkdir java/tags //標記,用來存放不再變動的分支
svn import . http://localhost/svn/java -m “Initial repository layout” 或
svn import java http://localhost/svn/java -m “Initial repository layout”
checkout(可縮寫為co)服務器文件到本地機器上(/usr/local/svn/work)
cd /usr/local/work //先建立本地的工作路徑
svn co http://localhost/svn/java java –username afa –password guesswhat
網頁訪問方式http://myserver/svn/ 的方式
通過命令行執行例如checkout,update等各種操作(建議先切換到當前工作路徑).
TortoiseSVN訪問方式需要安裝TortoiseSVN,可代替命令行執行各種操作.
commit 提交
當本地工作目錄上修改或新建文件或文件夾時,服務器上得倉庫並不會自動修改,需要使用commit命令把本地做的修改保存到服務器上.每次修改後commit,服務器上得版本號會加1.
新增文件或文件夾(先進入到當前目錄)
svn add newfile/newdir
svn commit –m “message”
本地更新文件update(不帶參數則更新為最新版本)
svn update –r 3 test.java //本地的test.java更新為第三次提交的版本
注意幾個狀態:
A 新增
D 刪除
U 更新
C 衝突
G 合併
創建分支(branch)和標記(tag)
$ svn checkout http://serverip/svn/java java
$ cd java
$ svn copy trunk/calc branches/calc-branch-1.0
$ svn status
$ svn commit -m “Creating a private branch of /trunk/calc.”
合併分支
(1)合併從某個版本都某個版本
cd 到相應的目錄(如 /usr/local/work/java/trunk)
$ svn merge -r 343:344 http://serverip/svn/java/branches/java-branch-1.0
(2)合併整個分支(如從341版本產生了分支到現在要合併起來)
$ svn merge -r 341:HEAD http://serverip/svn/java/branches/java-branch-1.0
(3) 合併時產生衝突的處理主要是靠手動修改.
<<<<<<>>>>>> .merge-right.r14 //這兩行是分支上做的修改
修改完了之後,把svn產生的多餘的控制文件刪除(或用svn resolved命令)再commit就OK了.
“svn status”顯示本地更新,如果沒有任何更新(或剛剛commit)則沒有任何信息顯示.
“svn diff”顯示詳細的更新細節:
$ svn diff -r 343:344 http://serverip/svn/java/trunk/work.java
“svn revert”移除用戶的本地更新(本地做了更新,但沒有提交時有效).
“svn resolved”命令,當手工解決了版本衝突之後,在commit之前執行,用來告訴SVN”我已經解決了衝突,請讓我提交吧”
svn resolved work.java //當前目錄下的work.java
svn delete刪除命令
cd到某個需要被刪除的目錄
$ svn del –force branches
$ svn commit –m “Delete the java branches”
其他命令(對服務端進行操作)
(1)svnlook tree path/java –show-ids
(2)備份與恢復(特別是對於升級Subversion的情況)
完整式備份與恢復:
$ svnadmin dump java > dumpfile
$ svnadmin create dumpjava //可以修改倉庫(項目)的名字
$ svnadmin load dumpjava dumpfile1
$ svnadmin dump myrepos –revision 1001:2000 –incremental > dumpfile2
$ svnadmin dump myrepos –revision 2001:3000 –incremental > dumpfile3
$ svnadmin load newrepos < dumpfile1
$ svnadmin load newrepos < dumpfile2
$ svnadmin load newrepos < dumpfile3
二,倉庫的權限設置
創建口令文件(使用Apache的htpasswd)
$ cd /urs/local/Apache/bin //進入到apache的bin目錄
$ htpasswd -c /etc/svn-auth-file afa //第一次: 以 -c 建立口令文件
New password: *****
Re-type new password: *****
Adding password for user afa
$ htpasswd /etc/svn-auth-file test //第二次不用-C參數,但要指定口令文件(含路徑)
New password: *******
Re-type new password: *******
Adding password for user test
$
編輯httpd.conf文件,加入身份驗證
DAV svn
SVNParentPath /usr/local/svn
AuthType Basic
AuthName “Subversion repository”
AuthUserFile /etc/svn-auth-file
Require valid-user
更細緻的權限控制――分組管理
DAV svn
SVNParentPath /usr/local/svn
AuthzSVNAccessFile /etc/svn/authz.conf
AuthType Basic
AuthName “Subversion repository”
AuthUserFile /etc/svn-auth-file
Require valid-user
authz.conf的內容為:
[groups]
everyone = afa,test, tommy, songjy, zhengyong, orcus, zhangq
groupA = afa,robert, zhangq
groupB = test,orcus, tommy
[projectA:/]
@groupA = rw
@everyone = r
[projectB:/]
@everyone = r
@groupB = rw

下篇這篇,是Dreamhost Wiki關於Svn的文檔.非常詳細
不過偶看得頭疼很

Subversion
From DreamHost
Jump to: navigation, search
This article or section may require a cleanup.
We are hoping to create articles that meet certain standards. Please discuss this issue on the talk page. Editing help is available.

Subversion (official site) is a version-control system that keeps track of changes in your files on a server. Subversion helps to coordinate work among multiple people. For an introduction – read the book – it is really great.
Contents
[hide]

* 1 Subversion on Dreamhost
* 2 Quick Start
o 2.1 Gotchas
* 3 Connecting to Subversion Repository
o 3.1 Using svn+ssh
o 3.2 Using HTTP
* 4 How to use: quick reference
o 4.1 Creating Repository via Command-Line
+ 4.1.1 Gotchas
o 4.2 Importing Folders and Files
o 4.3 Loading a dumpfile
o 4.4 Using TortoiseSVN
+ 4.4.1 Create Session Key
+ 4.4.2 Setup New Session
+ 4.4.3 Other References
+ 4.4.4 Notes
o 4.5 Multiple User Access to Repository
o 4.6 Using Apache basic authentication
o 4.7 Using Subversion for Web development (automatic post-commit checkout)
* 5 Upgrading to Newest Subversion
* 6 Interfacing with Subversion from PHP
* 7 Setting up post commit emails
* 8 External Links
o 8.1 Books and tutorials
o 8.2 GUI Integration
o 8.3 Web-based repository browsers
* 9 See Also
* 10 Userbased Scripts

[edit] Subversion on Dreamhost

The current version of Subversion on Dreamhost is 1.4.2. If you want to install a newer version, please see Subversion_Installation. If your server is still running old 1.3.x version, let us know and we can upgrade it for you. Subversion 1.4.x features repository mirroring, more efficient transfer and storage of binary files in comparison with previous versions.

You can install and configure Subversion repositories from control panel.
[edit] Quick Start

To set up a Subversion repository at svn.yoursite.com for a project called “myproject”, follow these steps:

1. Create svn.yoursite.com:
1. Go to your DreamHost control panel and click Domains, then Manage Domains
2. Click Add New Domain / Sub-Domain
3. Enter “svn.yoursite.com” in the Domain To Host field, enter “svn.yoursite.com” in the Web Directory field, and select Remove www.
4. Click Fully Host This Domain Now!
2. Wait a few hours until the new DNS information propagates (that is, when visiting svn.yoursite.com in a web browser doesn’t give an error–the page will look like an empty directory listing once the DNS info has propagated).
3. Set up a Subversion repository:
1. Click Goodies, then Subversion
2. Enter “My Project” in the Project Name field, “myproject” in the Project ID field, and make sure that svn.yoursite.com is selected for the URL. Use “myproject” as the directory name.
3. Replace the dummy usernames and passwords with a username and password for yourself.
4. Click Create My New Project Repository Now!

As soon as the DreamHost Subversive Robot actually creates your repository, you can begin using it. For instance, to import a directory:

svn import some_directory http://svn.yoursite.com/myproject -m “Initial import”

[edit] Gotchas

Warning: If you create a new repository at an existing domain, the domain may be moved to a new Apache service and the DNS information will change. This will affect you if you have your DNS info hosted somewhere else than Dreamhost (you’ll have to get the new IP address and update your DNS info). This is only the case with domains that have been hosted with DreamHost for more than a year or so. Anything added more recently than that will probably not be affected.

Warning: Repositories don’t act like normal directories: You will not be able to use .htaccess files, cgi scripts, etc. in your repository directory. For instance, if you setup your repository at http://svn.example.com/, you will not be able to password protect that directory using .htaccess. You must use the Public/Private field in the Subversion panel page. Changes made in the Htaccess/WebDAV panel also do not apply to your SVN repository.

This also means you can’t install ViewVC in the main repository directory. To work around this, put your repository in http://svn.example.com/svn/ and the ViewVC cgi in http://svn.example.com/. Remember, you’ll need to use a .htaccess file to configure http://svn.example.com/, but the Public/Private field in the Subversion panel to protect http://svn.example.com/svn/.

Hastily-made repositories often don’t work: If you create your repository before its intended host is fully created (and resolved), you may have an inaccessible repository. Assuming it doesn’t yet contain any information (how could it?), just delete it and recreate it. (Alternatively, you may be experiencing a DNS propagation delay if you can access your repository via http within the DreamHost system, but see an empty directory from outside DreamHost [Apache 1.3x serving your empty domain]. If you can’t wait, try querying the DH DNS servers for your IP and using a local hosts file or NetInfo to temporarily resolve your svn host. Remember to undo this when DNS records have propagated.)

Some have reported success just submitting an edit (with no changes) to their repository in the Control Panel. This operation recreates your reponame.access and reponame.passwd files re-establishing dhapache as their group (and undoing any MD5 passwords you’ve made manually). Unfortunately, this does nothing to fix your repository if the owner has been changed from dhapache to your username.

It would be nice if the Subversion Control Panel had an explicit option to fix owner and group on a given repository, say, by running:

sudo chown -R dhapache ~/svn/reponame;
sudo chgrp dhapache ~/svn/reponame.access ~/svn/reponame.passwd;

… in the background. As it is, you have to dump, recreate and reload your repository.

Another nice feature would be a Control Panel switch to allow passwords to be created and maintained with MD5 encryption.

Some clients require MD5 passwords: If you get “access denied” warnings, you may need to use MD5 passwords instead of the standard variety created by the DreamHost Control Panel. Use htpasswd -nm username to generate the entry (ala username:passwd-hash) for your reponame.passwd file. And use an editor (ala nano reponame.passwd) to replace your standard password entry.

Don’t overwrite your reponame.access and reponame.passwd files with echo “username:passwd-hash” > reponame.passwd Overwriting the files will cause them to have your user’s group instead of dhapache, leaving your repository in a read-only or inaccessible state.

Removing repositories through the control panel doesn’t seem to remove the ~/svn/ directory. (as of Apr 12 2006) Workaround:

cd ~/svn;
mkdir old;
mv old

You have the proper permissions to do this. (You can also use WebFTP to delete or rename the repository directory.)
[edit] Connecting to Subversion Repository
[edit] Using svn+ssh

Allows for a svn client to connect directly with the repository via ssh.

You have to set up a ssh username and password. Subversion users defined in the panel will not be used for authentication.

svn+ssh://{user}@www.yourdomain.ext/home/{user}/svn/{project}

note: {project} is the ID of your subversion project, NOT the projectname.

You should also check SSH#Passwordless_Login to use this mode without being asked for the password repeated times

See also SVN book for SSH tricks
[edit] Using HTTP

1. Use the HTTP path that you used in the Subversion panel.
2. Sign in using username and password specified in the panel.

Is there any way for svn users to change their password in this mode? No. Only through panel.
Is there any way to use https instead of http? Probably, but first you will need a unique IP address and Secure Server installed on your domain.

[edit] How to use: quick reference
The instructions provided in this article or section require shell access unless otherwise stated.

You can use the PuTTY client on Windows, or SSH on UNIX.
Your account must be setup for shell access in the Control Panel if you haven’t done so already.
More information may be available on the article’s talk page.
[edit] Creating Repository via Command-Line

If you didn’t use the Dreamhost Subversion Panel, you can create the repository at a directory. If you used the Quick Start method then skip this step and go to the next one.

svnadmin create /home/user/path/to/repository

[edit] Gotchas

Handmade repos are read-only (via http): If you find that you have to tweak and reload your dumpfile a few times, it can be handy to use the CLI tools (e.g. rm -rf and svnadmin create) to wipe and recreate your repository until you get it right. But then you’ll want to use the Control Panel to delete and recreate your repository. Your test repositories will not function properly in production (they won’t permit any changes).

The Panel creates the repository with dhapache as the owner, and the reponame.access and reponame.passwd files with dhapache as the group. Trying to create your own production repo with svnadmin create is futile because you don’t have authorization to change those ownerships and group memberships (and you’re not a sudoer).

Don’t overwrite dhapache files: Don’t overwrite your reponame.access and reponame.passwd files with echo “username:passwd-hash” > reponame.passwd (e.g. if you’re trying to use MD5 passwords). Use an editor and paste in the new data. Overwriting the files will cause them to have your user’s group instead of dhapache. If your repository is relatively mature when you make this mistake, and you have no backup, you will be out of options.
[edit] Importing Folders and Files

Once the repository is created you can add folders and files that you have in another location. It is better to use this method to keep the revisions number down when first creating the repository.

svn import /home/USER/path/to/source file:///home/USER/path/to/repository –message=”Importing Project”

You have to put a message in and change the text inside to whatever you are doing at the time.
[edit] Loading a dumpfile

Sometimes, you would have an existing repository that you want to migrate to your Dreamhost svn repository. You will need to take a dump of your existing repository and load it into your Dreamhost repository.

* Dump your existing repository

svnadmin dump path-to-repo | gzip > dumpfile.gz

* Upload dumpfile.gz to your home directory.

* Load this into your repository.

If you set up using the Dreamhost Subversion Panel, then the repository will be under the $HOME/svn/{repo-id} where the repo-id is the id you used to setup the repository in the panel. Decompress the dumpfile first.

gunzip -c dumpfile.gz | svnadmin load /home/USER/path/to/repository

Command should show all files being imported, if not then check the instructions and try again.
[edit] Using TortoiseSVN

TortoiseSVN is a Windows GUI integration program for svn. Use at your own risk and is not officially supported.

This walkthrough assumes username is myname, with a website at www.mysite.com, and that the repositories are in ~/svn starting with a project named myproject. You can choose your own directory names.

Step 1: Create the repository following the Repository section of this guide. Step 2: Download and install SVN client
[edit] Create Session Key

If you don’t create the public session key, you will have to type your password in for every action in the browser and for every time TortoiseSVN connects to the server.

Start in your home directory

cd ~

Generate the key set using the passphrase of your choice and put the public key in a .ssh directory (note: the name “rsakey” isn’t required)

Write down your passphrase as you will need it later.

ssh-keygen -b 1024 -t rsa -N SomeLongTextForPassphrase -f rsakey

Create the .ssh folder

mkdir .ssh

Move the public key inside of the folder and rename it.

mv rsakey.pub .ssh/authorized_keys

Change permissions on both the folder and file for security.

chmod 700 .ssh
chmod 600 .ssh/authorized_keys

Download and install the Putty tools (scroll down to the Windows-style installer). This is an SSH client with authentication tools.

Download your “rsakey” file (your private key) from the server to your local machine (the rsakey should be in your home directory).

Use your Windows FTP client.

Load it into the PuTTYgen tool (puttygen.exe) and enter your passphrase when it asks for it.

Use SSH-2 (RSA) which will be the default.

Save it as a private key from PuTTYgen in a safe place as rsakey.ppk.
[edit] Setup New Session

1. Run PuTTY Pageant. Pageant will put an icon of a computer wearing a hat into the System tray.
2. Load a private key into it. Double click on the icon and then click on Private Key File.
3. Type in the Passphrase.

* Run Putty and make a new session:
o Hostname: www.mysite.com
o Protocol: SSH
o Saved Sessions: mysiteSSH
o Connection->Data->auto-login username: myuser
o Connection->SSH->preferred protocol: 2
o Connection->SSH->Auth->private key file: path\to\rsakey.ppk

* Click “Save” on the sessions panel to save this config.

* Open PuTTY if you want to test your session. PuTTY will notice that Pageant is running, retrieve the key automatically from Pageant, and use it to authenticate. You can now open as many PuTTY sessions as you like without having to type your passphrase again. You may get a message saying, “The server’s host key is not set in the registry.” (Insert what this means here.)

* Now find your local project directory, and copy what you want to add to Subversion into a temporary directory (let’s call it “ImportMe”), organizing it carefully — it’s smart to put your files in a “trunk” directory so that working with new branches and tags later is simple.

* Right-click on the ImportMe folder and select “Import…” from the TortoiseSVN submenu. You will be adding everything inside this folder into the root of the “myproject” repository.

* In the import dialog, enter the URL of Repository like this. Replace “mysiteSSH” with the name of your PuTTY stored session and “myusername” with your real username. If you just want a straight SSH tunnel, we’d use [email protected] here instead of mysiteSSH:

svn+ssh://mysiteSSH/home/myusername/svn/myproject

…and click “Okay”. This will load your project files into the repository.

* Next, check out the files you want to work with into your project directory (but make sure you aren’t overwriting files when you check out or you’ll get errors). This is the “SVN Checkout…” option in the folder context menu.

Everything should be pretty self-explanatory from there on.
[edit] Other References

[1] – For Windows XP

[2] – Guide from TortoiseSVN site (generate RSA key instead of DSA key).
[edit] Notes

* TortoiseSVN (1.1.3) – Go into Settings and enter TortoisePlink as the SSH client under the Network tab to connect to your repository. You can use svn+ssh://[email protected]/home/myusername/svn/myproject to specify your username directly in the URL. Along with Pageant for key-based authentication, using TortoiseSVN is very transparent and easy to use.

Also screen is getting over worked for overnight checkouts (yes overnight)

screen
svn co &> ~/log_co &
^ad

[edit] Multiple User Access to Repository

(I have only tried this in a bundy shell, not externally (with TortoiseSVN, for example)

* Create at least two users (mysvnadmin, mysvnuser)
* Create the repository and import the project with mysvnuser.
* Login (ssh) to mysvnuser’s account:

$ su mysvnuser
$ svn co file:///home/mysvnadmin/repos/project work
$ svn add file
$ svn commit -m “added file”
$ svn log
r1 | mysvnadmin | 2005-09-04 08:03:47 -0700 (04 Sep 2005) | 1 line
initial import
r2 | mysvnuser | 2005-09-04 23:34:13 -0700 (04 Oct 2005) | 1 line
added file

I had no trouble with svn+shh (on bundy):

$ svn co svn+ssh://[email protected]/home/mysvnadmin/repos/project work

[edit] Using Apache basic authentication

The Dreamhost panel provides a way to create user accounts only for Subversion- the above steps require each user to have a Unix account with shell access so they can log in via SSH.

If you want to do per-directory permissions in your repository using those accounts, you need to manually edit the .access file as described here:

Subversion manual

However, if you make changes to the user list using the Dreamhost control panel, it will overwrite any changes you make to the .access file.

You can manually add and administer the usernames and passwords for Subversion by using htpasswd to add/edit users to the .passwd file for your repository. This is not recommended though, because after manual editing either the .access or .passwd files, the group changes from dhapache to whatever the auto-generated group for your account is. This prevents the Apache module from being able to read the files. You then need to change the permissions so that they can be read by apache: chmod 644

Note that this is giving “world” read access to those files, which potentially is a security risk. Using control panel automatically resets group back to dbapache, but you will lose your per-directory settings. Using Apache and these passwords isn’t very secure anyway without https access, so this is all more for convenience. If you need security, create Unix accounts with SSH shell access as described above.
[edit] Using Subversion for Web development (automatic post-commit checkout)

Subversion can be a very useful tool for developing Web sites or Web-based applications. You may wonder, though, how that would work. After you commit your changes, how do they flow into the site?

Here’s how: you make your site into just another working copy, checked out from your Subversion repository into the appropriate publicly-accessible directory. Then, when you commit a change, you run svn update against that other working copy, and voila! All your updates are on the site.

Tortoise context menus only work in windows explorer. If you want to use the tortoise commands (checkout,update,…) on your dreamhost directories , you can map a network drive to your ftp location. You will need a tool like “novell netdrive” in order to do the mapping.

This, in fact, is the method recommended in the Subversion FAQ. The FAQ even mentions that you can go a step further and have your site update automatically whenever you commit, using Subversion’s cool “hook scripts” functionality to automatically run svn update upon commit.

A userbased script to this purpose can be found down the bottom Userbased Scripts

However, if you try that on Dreamhost, you’ll find that the post-commit hook script will never successfully execute svn update. Why? Here’s the explanation I got from DH:

The reason for why this doesn’t work is that since the [hook] script gets executed as the apache process, the script runs as user dhapache. If you try to have user dhapache (which is a normal unprivileged user) update a subversion repo in your home directory and owned by you, it will fail.

In other words, it’s a permissions issue. And due to the way Subversion is set up by DH, it’s one that you can’t fix — at least not directly.

There is a way around this, though: instead of having your hook script do the svn update directly, we’re going to put a C program in the middle. In other words, instead of the post-commit hook script calling svn update, it will now call a C program, which will execute a bash script that runs the svn update. This gets you around the “script runs as Web server user” issue.

Here’s the steps for doing this:

1. Move your non-working post-commit file to post-commit.bash.

2. Create a file named post-commit.c with the contents:

#define REAL_SCRIPT “/path/to/post-commit.bash”
#include
#include
main( ac, av )
char **av;
{
execv( REAL_SCRIPT, av );
}

(Note: CHANGE the value of the REAL_SCRIPT variable in the C program to be the full path to your newly created post-commit.bash file — something like “/home/YOURUSER/svn/YOURREPOSITORY/hooks/post-commit.bash”.)

3. Compile the C code:

gcc -o post-commit post-commit.c

4. Setuid the file:

chmod 4755 post-commit

(if the above doesn’t work, try)

chmod +s post-commit

Assuming that you have gave the right path to post-commit.bash in the C program, Subversion will now automatically execute it every time you make a commit to your repository, allowing you to do cool stuff like automatically updating a site with newly committed changes. Pretty nifty!

Why does this work? By setting the setuid/setgid bit, when dhapache calls the executable it will temporarily assume the permissions of the owner of the file (you) and perform the actions. For security reasons, this functionality is disabled on most operating systems for shell scripts, so we have to go with the C code.

You may also want to deny public access to the .svn folders that are checked out as part of a subversion repository by adding this to an .htaccess file in your web root:

RedirectMatch 403 /\.svn.*$

[edit] Upgrading to Newest Subversion

If you would like to install a newer version of subversion (e.g., for repository syncing), then you will need to go to this page

http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=260&expandFolder=74

and download both the subversion-x.x.x.tar.bz2 and the subversion-deps-x.x.x.tar.bz2. The “deps” file contains all the subversion dependencies.

The newest subversion as of 2007.03.12 is 1.4.3. To install locally, create a temporary work directory and do the following.

mkdir tmpwork
cd tmpwork
wget http://subversion.tigris.org/downloads/subversion-1.4.3.tar.bz2
wget http://subversion.tigris.org/downloads/subversion-deps-1.4.3.tar.bz2
tar -xjf subversion-1.4.3.tar.bz2
tar -xjf subversion-deps-1.4.3.tar.bz2
cd subversion-1.4.3
./configure –prefix=/home/{yourlogin} –with-ssl
make
make install

That will install the new subversion into your user directory. You’ll need to change the path to include your ~/bin directory to use the new binaries.
[edit] Interfacing with Subversion from PHP

You’ll need to install the PECL extension SVN. Detailed instructions are available here: http://hp.jpsband.org/xhtml-compiler/docs/compile-svn.txt
[edit] Setting up post commit emails

Simply edit your svn/(repository name)/hooks/post-commit.tmpl file. Change /usr/lib/subversion/hook-scripts/commit-email.pl “$REPOS” “$REV” [email protected] to your commit email list. Then reinitialize SVN.

The actual file should be post-commit, not post-commit.tmpl. If you use an editor that edits in place, as opposed to (for instance) emacs which moves the original aside and creates a fresh file, you should still have the right owner/group and not need any reinitializing.

The default settings for commit-email.pl may be to use a connection to localhost instead of firing up sendmail, in which case you need the –from parameter for bounce/envelope address.
[edit] External Links
[edit] Books and tutorials

Version Control with Subversion is the Online Subversion book freely available online in its entirety. If you have shared hosting, focus on the file:// and svn+ssh:// protocols (which do not involve any actual continually running “server” processes that might not be good in a shared environment). If you have a dedicated hosting, you can do whatever you want I imagine.

* Subversion on Dreamhost

[edit] GUI Integration

* SCPlugin is a Finder contextual menu plugin for Mac OS X for subversion operations. Windows users will recognize it as the Mac analogue to TortoiseSVN.
* SVN Client Requires payed registration after 60 day trial.
* SvnX is an excellent GUI for Mac OS X.
* TortoiseSVN is a subversion client implemented as a Windows shell extension.
* RapidSVN Multi-platform GUI for Mac OS X, Linux, Windows.
* Syncro SVN Client a cross platform Subversion client.

[edit] Web-based repository browsers

These provide a number of convenient features, including RSS feeds, integrated bug tracking, collaborative documentation:

* Trac (Difficult Installation)
* ViewVC formerly ViewCVS official site, old site
* WebSVN – auto-tarball of directories, syntax highlighting – official site
* SVN::Web – on CPAN

[edit] See Also

* Subversion Installation
* CVS
* TortoiseSVN using Putty sessions

[edit] Userbased Scripts

This script creates a post-commit hook that runs another post-commit (which actually performs updates). It disables both stdout and stderr to avoid problems with Apache and TortoiseSVN. The script will set up initial import directories (standard trunk, tag, branches folders) and create the necessary hook files to automatically update your http root from /trunk.

Simply copy and paste the following script, filling in the appropriate variables with your own information, into a file on your server. Then set execute permissions (chmod 775 scriptname) and run it (./scriptname). Once it’s done you can safely delete the script and try committing changes to your site.

#./bin/bash
pname=”REPNAME”
webpage=”WEBPAGEFOLDER/”
svnurl=”http://svn.YOURHOST.com”
homedir=”/home/YOURUSER”

mkdir svninit
mkdir svninit/trunk
mkdir svninit/branches
mkdir svninit/tags

svn import svninit $svnurl/$pname -m “Initial Import”

rm -r svninit

svn co $svnurl/$pname/trunk/ $homedir/$webpage

touch post-commit.c

echo ‘#include ‘ > post-commit.c
echo ‘#include ‘ >> post-commit.c
echo ‘#include ‘ >> post-commit.c
echo ‘int main(void)’ >> post-commit.c
echo ‘{‘ >> post-commit.c
echo ‘ close(1);’ >> post-commit.c
echo ‘ close(2);’ >> post-commit.c
echo ‘ execl(“/usr/bin/svn”, “svn”, “update”, “‘$homedir’/’$webpage'”, (const char *) NULL);’ >> post-commit.c
echo ‘ return(EXIT_SUCCESS);’ >> post-commit.c
echo ‘}’ >> post-commit.c

gcc -o post-commit.bash post-commit.c
rm post-commit.c
mv -f post-commit.bash $homedir/svn/$pname/hooks/
chmod 775 $homedir/svn/$pname/hooks/post-commit.bash
chmod +s $homedir/svn/$pname/hooks/post-commit.bash

touch post-commit.c

echo ‘#define REAL_SCRIPT “‘$homedir’/svn/’$pname’/hooks/post-commit.bash”‘ > post-commit.c
echo ‘#include ‘ >> post-commit.c
echo ‘#include ‘ >> post-commit.c
echo ‘#include ‘ >> post-commit.c
echo ‘#include ‘ >> post-commit.c
echo ‘int main( ac, av )’ >> post-commit.c
echo ‘ char **av;’ >> post-commit.c
echo ‘{‘ >> post-commit.c
echo ‘ close(1);’ >> post-commit.c
echo ‘ close(2);’ >> post-commit.c
echo ‘ execv( REAL_SCRIPT, av );’ >> post-commit.c
echo ‘ return(EXIT_SUCCESS);’ >> post-commit.c
echo ‘}’ >> post-commit.c

gcc -o post-commit post-commit.c
rm post-commit.c
mv -f post-commit $homedir/svn/$pname/hooks/
chmod 775 $homedir/svn/$pname/hooks/post-commit
chmod +s $homedir/svn/$pname/hooks/post-commit

One Reply to “接觸Subversion”

Comments are closed.