在Linux上創建webrev(cont)[基於svn]
在前文中,基於git介紹了webrev工具。實際上,webrev工具還支持hg和svn。最近的工作中不可避免地要使用svn,故在此總結一下如何基於svn在Linux上創建webrev。順便吐個槽,沒有網頁版的代碼比對,用svn diff簡直就是刀耕火種茹毛飲血啊!技術再嫻熟的老司機,也架不住讓你在高速公路上開拖來機Orz!
以前工作上一直用版本管理工具Mercurial (命令為hg), 個人學習的話用Git, 但從來沒用過Subversion (命令為svn等) 。所以,下面的先簡單介紹一下如何搭建一個svn的server然後初始化一個代碼倉庫。相比之下,基於Mercurial的代碼倉庫初始化實在是太容易了,只需要一條命令(hg init .)搞定。
1. 搭建一個svn的server
1.1 創建一個項目venus
root# cd /var/tmp && mkdir ducert root# svnadmin create venus
1.2 配置項目venus
root# tree venus/conf venus/conf ├── authz #<-- 權限相關的配置 ├── hooks-env.tmpl ├── passwd #<-- 帳號相關的配置 └── svnserve.conf #<-- 資源庫相關配置 0 directories, 4 files
1.2.1 配置賬號 e.g. 添加用戶veli, 密碼為veli (見第9行)
root# cat -n passwd 1 ### This file is an example password file for svnserve. 2 ### Its format is similar to that of svnserve.conf. As shown in the 3 ### example below it contains one section labelled [users]. 4 ### The name and password for each user follow, one account per line. 5 6 [users] 7 # harry = harryssecret 8 # sally = sallyssecret 9 veli = veli
1.2.2 配置權限 e.g. 給用戶veli的是可以在/下面進行讀寫 (見第34和35行)
root# cat -n authz
1 ### This file is an example authorization file for svnserve.
2 ### Its format is identical to that of mod_authz_svn authorization
3 ### files.
...
33
34 [/]
35 veli=rw
1.2.3 配置資源庫 e.g. 設置代碼庫的根目錄(見第48行) (第19,20,27,36行只需要把對應的註釋符號去掉即可)
root# cat -n svnserve.conf 1 ### This file controls the configuration of the svnserve daemon, if you 2 ### use it to allow access to this repository. (If you only allow 3 ### access through http: and/or file: URLs, then this file is ... 19 anon-access = read 20 auth-access = write ... 27 password-db = passwd ... 36 authz-db = authz ... 48 realm = /var/tmp/ducert/venus ...
1.3 啟動svnserver (e.g. svnserve -d -r venus)
root# cd /var/tmp/ducert && pkill svnserve root# svnserve -d -r venus root# ps -ef | grep venus | grep -v grep root 6960 2233 0 11:29 ? 00:00:00 svnserve -d -r venus root# netstat -an | grep 3690 tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN
1.4 測試svn server "venus" 可以正常工作
1.4.1 checkout
veli$ ifconfig -a | egrep "inet addr:.*255.255.255.0" inet addr:192.168.228.128 Bcast:192.168.228.255 Mask:255.255.255.0 veli$ svn co svn://192.168.228.128 --username=veli --password=veli Checked out revision 0. veli$ ls -A .svn
1.4.2 add some files
veli$ cd /tmp && mkdir sandbox && cd sandbox veli$ svn mkdir demo A demo veli$ cd demo veli$ svn add foo.c A foo.c veli$ svn add bar.py A bar.py veli$ svn add Makefile A Makefile veli$ svn status A . A Makefile A bar.py A foo.c
1.4.3 commit
veli$ svn commit -m "05/15/2017: init demo" Adding . Adding Makefile Adding bar.py Adding foo.c Transmitting file data ... Committed revision 1.
到此為止,一個svn server就搭建好了,並且可以很流暢地工作了。接下來,使用webrev工具創建代碼比對網頁。因為在前一節已經介紹了如何下載webrev工具,這裏就不再多說了,直接使用就好。
2. 使用webrev創建代碼比對網頁
2.1 checkout svn庫裏的demo代碼
veli$ rm -rf /tmp/sandbox && mkdir /tmp/sandbox veli$ cd /tmp/sandbox veli$ svn co svn://192.168.228.128 --username=veli --password=veli A demo A demo/bar.py A demo/Makefile A demo/foo.c Checked out revision 1.
2.2 修改文件
veli$ cd /tmp/sandbox/demo veli$ vi foo.c veli$ svn diff foo.c Index: foo.c =================================================================== --- foo.c (revision 1) +++ foo.c (working copy) @@ -3,7 +3,7 @@ int main(int argc, char *argv[]) { - (void) printf("Hello World!\n"); + printf("Hello World!\n"); return 0; } veli$ vi bar.py veli$ svn diff bar.py Index: bar.py =================================================================== --- bar.py (revision 1) +++ bar.py (working copy) @@ -4,9 +4,9 @@ def main(argc, argv): print "Hello World!" + return 0 if __name__ == ‘__main__‘: - argv = sys.argv - argc = len(sys.argv) + argc, argv = len(sys.argv), sys.argv sys.exit(main(argc, argv)) veli$ vi Makefile veli$ svn diff Makefile Index: Makefile =================================================================== --- Makefile (revision 1) +++ Makefile (working copy) @@ -1,7 +1,7 @@ CC = gcc CFLAGS = -g -Wall -m32 -all: foo +all: foo bar foo: foo.o $(CC) $(CFLAGS) -o $@ $< @@ -9,7 +9,12 @@ foo.o: foo.c $(CC) $(CFLAGS) -c $< +bar: bar.py + cp $< $@ + chmod +x $@ + clean: rm -f *.o clobber: clean - rm -f foo + rm -f foo bar +cl: clobber
2.3 創建webrev
veli$ export PATH=/var/tmp/webrev/bin:$PATH veli$ webrev WARNING: codereview(1) not found. SCM detected: subversion File list from: svn status ... Done. Workspace: /tmp/sandbox Compare against: Output to: /tmp/sandbox/webrev Output Files: demo/Makefile patch cdiffs udiffs wdiffs sdiffs frames old new demo/bar.py patch cdiffs udiffs wdiffs sdiffs frames old new demo/foo.c patch cdiffs udiffs wdiffs sdiffs frames old new Generating PDF: Skipped: no output available index.html: Done.
2.4 通過瀏覽器查看
o
o foo.c.frames.html
o bar.py
o Makefile
在Linux上創建webrev(cont)[基於svn]