UML软件工程组织

 

 

用 Subversion 來維護程式
 
2008-09-28 来源:sanwangx.info
 

最近在實驗室寫 project 和幫朋友改 bbs 的聊天室,都是用 Subversion 來維護產出的程式碼。

簡單來講,Subversion 採用 Global Revision Numbers,不像其它版本控制系統 (ex: CVS) 是針對每個個別的檔案做版本控制,檔案的版本只會在有修改 commit (提交) 時才會遞增。對 Subversion 來說,在你每次 commit (新增、修改或刪除任何檔案或任何資料夾) 時,Subversion 會遞增 Global Revision Number,而每個檔案和資料夾只會記住它在哪幾個 global revision 裡也有被修改到。所以,你日後要 checkout 時所指定的版本編號所代表的意義是:「整個 repository 在第 N 次 commit 後的狀態」。當然,你 checkout 時所指定的 repository URL 除了可以指定整個 repository 的根目錄,也可以只指定一個檔案或 repository 裡的目錄。

我想這對一般人來講才是比較直覺的,而不像 CVS 是對每個 repository 裡的檔案分別做版本編號,如果要推出一個 release 版本時,需要對所有檔案做 tag 標記,如此一來,CVS 才知道每個檔案要使用第幾版。

我在 Windows 平台上使用的 Subversion Client 是 TortoiseSVN,這是免費的,它把 Subversion client 應有的功能都整合在 Windows 檔案總管的右鍵選單裡,相當的便利。

安裝 Subversion

Subversion 我安裝在 Fedora Core 2,用 Fedora 內附的 up2date 即可馬上安裝完成,只要打

up2date --install subversion

就可以了,注意要使用 root 來執行這個命令。

設定原始碼的維護成員

一開始先確定哪些系統上的 user 需要參與同一個專案的原始碼維護工作,在這裡假設有 user_a、user_b 和 user_c,把這些帳號加到新成立的 project_a group (/etc/group 檔案):

lteamster:x:30055:user_a,user_b,user_c

設定 Subversion repository
在這裡我們建立 /home/project_a 這個目錄,並把初始化這個目錄為 Subversion repository:

svnadmin create /home/project_a

Subversion 會在指定目錄下建立一些 Subversion 系統使用的檔案。接下來就是設定這個 repository 的存取權限,把 repository 目錄和裡面的檔案設定只有其 owner 和 project_a group 成員可以存取 (rw)。

chown -R user_a.project_a /home/project_a
chmod 770 /home/project_a
chmod -R g+w /home/project_a

設定這個 repository 的存取權限,把下面三行加進去 /home/project_a/conf/svnserve.conf:

[general]
anon-access = none
auth-access = write

anon-access 是限制匿名登入 (使用 svn:// 連線) 的存取權限,我們設為 none,也就是不能讀寫 (checkout 和 commit)。而 auth-access 是限制有援權的使用者 (使用 svn+ssh:// 來登入) 的存取權限,我們設為 write,也就是可以讀寫。

使用 Subversion

最後就可以在 Windows 上用 TortoiseSVN 來 import 資料到 repository,Repository’s URL 輸入:

svn+ssh://username@svn-server-ip-address/home/project_a

username 改成你在 svn-server-ip-address 這台電腦使用的帳號名稱,svn-server-ip-address 是 Subversion server 的主機 IP 位址,緊接在IP 後面的是 repository 在系統的路徑。接下來就可以開始使用 Subversion 來維謢程式碼了。Enjoy It!

備份 Subversion repository

dump: usage: svnadmin dump REPOS_PATH [-r LOWER[:UPPER]] [--incremental]

Dump the contents of filesystem to stdout in a ‘dumpfile’ portable format, sending feedback to stderr. Dump revisions LOWER rev through UPPER rev. If no revisions are given, dump all
revision trees. If only LOWER is given, dump that one revision tree. If –incremental is passed, then the first revision dumped will be a diff against the previous revision, instead of the usual fulltext.

Valid options:
-r [--revision] arg : specify revision number ARG (or X:Y range)
–incremental : dump incrementally
-q [--quiet] : no progress (only errors) to stderr

回復 Subversion repository

load: usage: svnadmin load REPOS_PATH

Read a ‘dumpfile’-formatted stream from stdin, committing
new revisions into the repository’s filesystem. If the repository
was previously empty, its UUID will, by default, be changed to the
one specified in the stream. Progress feedback is sent to stdout.

Valid options:
-q [--quiet] : no progress (only errors) to stderr
–ignore-uuid : ignore any repos UUID found in the stream
–force-uuid : set repos UUID to that found in stream, if any
–parent-dir arg : load at specified directory in repository

後來因為常常得直接在 Linux command line 下改程式,所以 commit 程式到 Subversion 也直接在 command line 下完成,svn ci 可以 commit 程式碼, svn co 是 checkout 程式碼,svn st 可以看目前 working copy 的修改狀態,要回復程式碼到上一個版本用 svn revert,回復時不需要再連到 Subversion 就可以完成。其它詳細內容請見 manual。

相關連結

Subversion revision 10061 (Manual) --> http://svnbook.red-bean.com/svnbook/book.html

Subversion Draft Revision 1411M (中文化 manual)--> http://twpug.net/docs/Subversion/

TortoiseSVN --> http://tortoisesvn.tigris.org/

 

组织简介 | 联系我们 |   Copyright 2002 ®  UML软件工程组织 京ICP备10020922号

京公海网安备110108001071号