標籤:clob tin create patch ide web str and from
在前文中,基於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 ducertroot# svnadmin create venus
1.2 設定項目venus
root# tree venus/confvenus/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 9veli = 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 svnserveroot# svnserve -d -r venusroot# ps -ef | grep venus | grep -v greproot 6960 2233 0 11:29 ? 00:00:00 svnserve -d -r venusroot# netstat -an | grep 3690tcp 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.0veli$ svn co svn://192.168.228.128 --username=veli --password=veliChecked out revision 0.veli$ ls -A.svn
1.4.2 add some files
veli$ cd /tmp && mkdir sandbox && cd sandboxveli$ svn mkdir demoA demoveli$ cd demoveli$ svn add foo.cA foo.cveli$ svn add bar.pyA bar.pyveli$ svn add MakefileA Makefileveli$ svn statusA .A MakefileA bar.pyA foo.c
1.4.3 commit
veli$ svn commit -m "05/15/2017: init demo"Adding .Adding MakefileAdding bar.pyAdding foo.cTransmitting file data ...Committed revision 1.
到此為止,一個svn server就搭建好了,並且可以很流暢地工作了。接下來,使用webrev工具建立代碼比對網頁。因為在前一節已經介紹了如何下載webrev工具,這裡就不再多說了,直接使用就好。
2. 使用webrev建立代碼比對網頁
2.1 checkout svn庫裡的demo代碼
veli$ rm -rf /tmp/sandbox && mkdir /tmp/sandboxveli$ cd /tmp/sandboxveli$ svn co svn://192.168.228.128 --username=veli --password=veliA demoA demo/bar.pyA demo/MakefileA demo/foo.cChecked out revision 1.
2.2 修改檔案
veli$ cd /tmp/sandbox/demoveli$ vi foo.cveli$ svn diff foo.cIndex: 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.pyveli$ svn diff bar.pyIndex: 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 Makefileveli$ svn diff MakefileIndex: 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 [email protected] $<@@ -9,7 +9,12 @@ foo.o: foo.c $(CC) $(CFLAGS) -c $<+bar: bar.py+ cp $< [email protected]+ chmod +x [email protected]+ 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:$PATHveli$ webrevWARNING: codereview(1) not found. SCM detected: subversion File list from: svn status ... Done. Workspace: /tmp/sandboxCompare 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]