!!! svn memo [http://ukai.jp/|http://ukai.jp/] の [svn概要|http://ukai.jp/Slides/2003/0521-lw2003/html/mgp00001.html] のまとめ !! Subversion SubversionはCVSの利用形態をひきつぎつつ問題点を克服した新しいバージョン管理システム * はじめからネットワーク対応が考えられている ** WebDAV, svn, svn+ssh * 差分をやりとり * リビジョンはリポジトリ単位 * アトミックなコミット ** 複数のファイルの変更も同時にコミットできる * ブランチ/タグの扱いが違う ** コピーする ** コンテンツをコピーしていないので軽いオペレーション !! Subversion リポジトリ svnのリポジトリはプロジェクトごとに作る リポジトリを越えてファイルの移動がない 参照は svn:externals コミッターが同じ範囲 リポジトリの中身(コンベンション) 8< trunk/ >8 トランク (CVS HEADのブランチ) 8< branches/ >8 ブランチ (cvs tag -b) 8< tags/ >8 タグ (cvs tag) !! svnコマンド 8< % svn コマンド 引数 % svn help % svn helpコマンド >8 URL リポジトリ リポジトリ + パス 8< file:/svn/repos http://host/svn/repos svn://host/svn/repos >8 リビジョン X, X:Y 8< {DATE} HEAD リポジトリの最新 BASE ワーキングコピー COMMITTED 最後のコミット PREV 最後のコミットの前 >8 !! svn mkdir - リポジトリにディレクトリを作る 8< % svn mkdir file:///svn/repos/trunk --This line, and those below, will be ignored-- A file:///svn/repos/trunk Committed revision 1. % svn ls file:///svn/repos trunk/ % svn mkdir -m 'mkdir branches' file:///svn/repos/branches Committed revision 2. % svn mkdir -m 'mkdir tags' file:///svn/repos/tags Committed revision 3. >8 ** svn import directory の中味をリポジトリにいれる srcディレクトリをtrunkのsrcディレクトリに 8< % ls src foo.c % svn import src file:///svn/repos/trunk --This line, and those below, will be ignored-- A src Adding src/foo.c Committed revision 4. % svn ls file:///svn/repos/trunk hello/ % svn ls file:///svn/repos/trunk/src foo.c % svn ls -R file:///svn/repos/trunk src/ src/foo.c >8 !! svn checkout - リポジトリからワーキングコピーに trunkのsrcディレクトリを手元に 8< % svn checkout file:///svn/repos/trunk/src A src/foo.c Checked out revision 4. % ls hello total 20 drwxr-xr-x 3 ukai ukai 4096 May 11 23:58 ./ drwxrwxrwt 10 root root 8192 May 11 23:58 ../ drwxr-xr-x 7 ukai ukai 4096 May 11 23:58 .svn/ -rw-r--r-- 1 ukai ukai 94 May 11 23:58 foo.c % svn info Path: Url: file:///svn/repos/trunk/src Revision: 4 Node Kind: directory Schedule: normal Last Changed Author: ukai Last Changed Rev: 4 Last Changed Date: 2003-05-11 23:55:06 +0900 (Sun, 11 May 2003) >8 !! svn status, svn diff - 状態、リポジトリとワーキングコピーの違い ワーキングコピーで修正 8< % cd src % vi foo.c % svn status M foo.c % svn diff Index: foo.c =================================================================== --- foo.c (revision 4) +++ foo.c (working copy) .... >8 !! svn commit - ワーキングコピーからリポジトリにコミット 8< % svn commit --This line, and those below, will be ignored-- M foo.c Sending foo.c Transmitting file data . Committed revision 5. % svn status % svn diff >8 !! svn update - ワーキングコピーを最新に リポジトリからワーキングコピーに 8< % svn update At revision 5. >8 リポジトリからワーキングコピーにとりだしたリビジョンから、ワーキングコピーで修正されたものがあるか 8< svn status >8 !! コピー -修正- マージ コピー * svn checkout * svn update 修正 * エディタ マージ * svn commit !! svn log 8< % svn log ------------------------------------------------------------------------ rev 5: ukai | 2003-05-12 00:03:56 +0900 (Mon, 12 May 2003) | 2 lines add . ------------------------------------------------------------------------ rev 4: ukai | 2003-05-11 23:55:06 +0900 (Sun, 11 May 2003) | 2 lines import hello ------------------------------------------------------------------------ >8 !! svn add - リポジトリにファイルを追加 8< % vi Makefile % svn add Makefile A Makefile % svn status A Makefile % svn commit --This line, and those below, will be ignored-- A Makefile Adding Makefile Transmitting file data . Committed revision 6. % svn status -u -v 6 6 ukai . 6 6 ukai Makefile 6 5 ukai foo.c Head revision: 6 >8 !! svn delete - リポジトリからファイルを削除 8< % svn delete Makefile D Makefile --This line, and those below, will be ignored-- D Makefile Deleting Makefile Committed revision 7. % svn status -u -v 6 6 ukai . 6 5 ukai foo.c Head revision: 7 >8 !! svn move - ファイルを移動 working copy 内 8< % svn move foo.c hello.c A hello.c D foo.c % svn status A + hello.c D foo.c % svn commit --This line, and those below, will be ignored-- D foo.c A hello.c Adding hello.c Deleting foo.c Committed revision 8. >8 移動前のログがちゃんと見られる 8< % svn log hello.c ------------------------------------------------------------------------ rev 8: ukai | 2003-05-12 00:24:23 +0900 (Mon, 12 May 2003) | 2 lines move foo.c -> hello.c ------------------------------------------------------------------------ rev 5: ukai | 2003-05-12 00:03:56 +0900 (Mon, 12 May 2003) | 2 lines add . ------------------------------------------------------------------------ rev 4: ukai | 2003-05-11 23:55:06 +0900 (Sun, 11 May 2003) | 2 lines import hello ------------------------------------------------------------------------ >8 !! プロパティ プロパティ (svn help propset) * svn:ignore ** 各行に無視するファイルのパターン (.cvsignore) * svn:keywords ** キーワード置換: URL, Author, Date, Rev, Id * svn:executable ** chmod +x * svn:eol-style ** native, LF, CR, CRLF * svn:mime-type * svn:externals !! svn prop* 8< % svn propset svn:keywords Id hello.c property `svn:keywords' set on 'hello.c' % svn commit --This line, and those below, will be ignored-- MM hello.c Sending hello.c Transmitting file data . Committed revision 9. static char rcsid[] = "$Id$"; ↓ static char rcsid[] = "$Id: hello.c 9 2003-05-11 15:36:18Z ukai $"; % svn proplist -v hello.c Properties on 'hello.c': svn:keywords : Id svn propdel 削除 svn propedit 変更 svn propget 取得 >8 !! svn revert - ワーキングコピーの編集をなかったことにする 8< % svn status M hello.c % svn revert hello.c Reverted hello.c % svn status >8 !! 複数人で使う時は リポジトリのパーミッション 8< % svn ls file:///svn/repos svn: Couldn't open a repository. svn: Unable to open an ra_local session to URL svn: Unable to open repository 'file:///svn/repos' svn: Berkeley DB error svn: Berkeley DB error while opening environment for filesystem /svn/repos/db: Permission denied >8 group writableにしておく 8< umask 002 >8 他の人が修正を既にコミットしていて自分はなにもしてない場合 8< % svn status % svn update U hello.c Updated to revision 11. >8 修正がかぶらない場合 8< % svn status M hello.c % svn update G hello.c Updated to revision 13. >8 → マージされる コンフリクトする場合 8< % svn status M hello.c % svn update C hello.c Updated to revision 14. % ls hello.c* hello.c hello.c.mine hello.c.r13 hello.c.r14 >8 * hello.c ** マージしたもの ** コンフリクトマークいり * hello.c.mine ** マージする前 * hello.c.r13 ** ワーキングコピー修正前 * hello.c.r14 ** リビジョン最新 コンフリクトの解消 コンフリクトマーク 8< <<<<<<< .mine ワーキングコピーで修正していたもの ======= リポジトリの内容 >>>>>>> .r14 % svn update At revision 14. % svn status C hello.c ? hello.c.mine ? hello.c.r13 ? hello.c.r14 % svn resolve hello.c Resolved conflicted state of hello.c % ls hello.c* hello.c % svn status % svn update At revision 14. >8 !! タグ/ブランチ * Subversionにおいてはコピー操作。 * タグ/ブランチにあまり区別はない。 * バージョン管理システムを使っていなかった時に近い。 8< % svn copy file://svn/repos/trunk/hello file:///svn/repos/tags/hello-1.0 --This line, and those below, will be ignored-- A file:///svn/repos/tags/hello-1.0 Committed revision 15. % svn ls -R file:///svn/repos/ branches/ tags/ tags/hello-1.0/ tags/hello-1.0/hello.c trunk/ trunk/hello/ trunk/hello/hello.c >8 !! hooksの使い方 リポジトリのhooksディレクトリに.tmpl 拡張子がない実行ファイルを置く。 CVSROOT/管理用ディレクトリと違ってバージョン管理下にはない。 8< % ls hooks/ post-commit.tmpl pre-commit.tmpl start-commit.tmpl post-revprop-change.tmpl pre-revprop-change.tmpl >8 例 8< % cat post-commit #!/bin/sh -e REPOS="$1" cd /path/to/check/out/dir umask 002 svn update `svnlook dirs-changed $REPOS | sed -e 's,trunk/,,'` >8 !! リポジトリのバックアップ/リストア バックアップ 8< % svnadmin dump /svn/repos rev1 rev2 > dumpfile1 % svnadmin dump /svn/repos rev2+1 rev3 --incremental > dumpfile2 % svnadmin dump /svn/repos rev3+1 rev4 --incremental > dumpfile3 >8 リストア 8< % svnadmin create /svn/newrepos % svnadmin load /svn/newrepos < dumpfile1 % svnadmin load /svn/newrepos < dumpfile2 % svnadmin load /svn/newrepos < dumpfile3 >8 別の方法 8< % /usr/lib/subversion/hot-backup.py /svn/repos /var/backups/subversion/ >8 /var/backups/subversion/repos-n-m にリポジトリがバックアップされる !! 既知の問題点 * アクセスコントロールが貧弱 * ファイル単位で制御できない * hooksを使う? * 仕様なども含めて検討中 * どのレイヤにいれるべきか? * 日本語ファイル名の扱い * annotate * svn 1.0以降の予定 svn blame * symlink/hardlink * svn 1.0以降 * 仕様が枯れていない * 認証情報 .svn/ から ~/.subversion * svn-tunnel-agent=ssh から svn+ssh: !! よくあるトラブル * パーミッション ** 読み書きできないとdbがオープンできない ** 複数人で使う時は group writable で umask 002 * WebDAVのみに限定して www-data の所有にする * アップグレードした後 ** svnadmin recover /svn/repos する必要がある場合がある * コミット途中にとめた ** ロックが残っている ** svn cleanup でロックを消す !! まとめ * よりよいCVSをめざしたバージョン管理システム ** ファイルの移動 ** コミットがアトミック * 美しい設計、コーディングスタイル ** HACKING ** 言語バインディング: python, javaなど * しかしながらまだまだ開発途上 (<< 1.0) 実用に使えるがCVSほど枯れてはいない !! 参考URL Project Home Page 8< http://subversion.tigris.org/ >8 Subversion: The Definitive Guide 8< http://svnbook.red-bean.com/ 日本語: http://subversion.bluegate.org/doc/book.html >8 Subversion repository 8< http://svn.collab.net/repos/svn/ >8 SVN Quick Reference 8< http://subversion.tigris.org/files/documents/15/177/foo.ps >8