このタイトルはどうかと思うけど、つらつらと書く。

最近FreeBSDのサーバの調子が悪くて、結構固まったり勝手に再起動したりする。
そんなときは /var/log/messages を見るんだけど、qpopper とか postgres のログで埋まっていて見づらくてしょうがない。
そう言えば、昔 syslog.conf を修正して popper のログとかは別のファイルに分けたはずなんだけどな~?と思って /etc/syslog.conf を見るとそう言う記述が何にもない。
/var/log を見ると、popper 用のログファイルとかは残っていて、どうも今年の3月末くらいに make world して mergemaster したときにsyslog.conf をデフォルトのもので上書いてしまったらしい。
昔の syslog.conf がマシン移行のときのバックアップに残っていたので、syslog.conf に以下を追加する。
!imapd
*.*                                             /var/log/imapd.log
!qpopper
*.*                                             /var/log/popper.log
!upnpd
*.*                                             /var/log/upnp.log
!postgres
*.*                                             /var/log/postgres.log
upnpdとか今は使ってないけど。
ついでに /etc/newsyslog.conf もみなおして、ちゃんとファイルが rotate されるようにしておく。

こう言う事故は気をつけても起きるので、対策をしよう。/etc/のファイルをバージョンコントロール配下に置いてやることにする。
バージョンコントロールと言えば昔CVS今Subversionを愛用しているのだが、/etc/のファイルのために別の場所にリポジトリを作りたくない。
となれば今流行り(ちょっと今と言うのはつらいかも知れないけど)の git を使うことにする。
# cd /etc
# git init
# chmod go-rx .git
# git add syslog.conf newsyslog.conf (その他自分で変更しているファイル。全部でもかまわないけど)
# git commit -m "add"
みたいな感じで、/etc/.git が作られてここにバージョン管理に必要な情報が書き込まれる。
実際に何か起きたときにはまたそのときに git の使い方を勉強しよう。

このようにして git に追加したファイルを emacs で開くと、mode line に Git-master とか表示される。
M-x vc-print-log とかも使えるし、最近の emacs の vc-mode は git を理解してくれるようだ。
で、ファイルを変更して commit しようと思って C-x C-q と打つと、
File is under version-control; use C-x v v to check in/out
と表示される。
cvs使ってたころは C-x C-q で commit されたんだけどな~と思って自分が使っているいろいろな環境を調べてみたら、 .emacs に以下の行を含んでいるものがあった。
(global-set-key "\C-x\C-q" 'vc-toggle-read-only)
お~、これだこれだ、と思って .emacs に書いて試してみたところ、
Toggling the readability of a version controlled file is likely to wreak havoc 
と言われる。wreak havocって何?
どうなってるんだろーと思ってvc-toggle-read-only が定義されている vc-hooks.el を見てみる。
(defun vc-toggle-read-only (&optional verbose)
  "Change read-only status of current buffer, perhaps via version control.

If the buffer is visiting a file registered with version control,
throw an error, because this is not a safe or really meaningful operation
on any version-control system newer than RCS.

Otherwise, just change the read-only flag of the buffer.

If you bind this function to \\[toggle-read-only], then Emacs
will properly intercept all attempts to toggle the read-only flag
on version-controlled buffer."
  (interactive "P")
  (if (vc-backend buffer-file-name)
      (error "Toggling the readability of a version controlled file is likely to wreak havoc")
    (toggle-read-only)))
うん、エラーが出るようになってる。RCSより新しいバージョン管理システムでは安全じゃないから駄目なんだと。
いや、でも、しかし、昔は確かにこれで行けたよ、RCSじゃなくてCVSとかSubversionだったよ、と思ってemacs22のvc-hooks.elを見てみると、
(defun vc-toggle-read-only (&optional verbose)
  "Change read-only status of current buffer, perhaps via version control.

If the buffer is visiting a file registered with version control,
then check the file in or out.  Otherwise, just change the read-only flag
of the buffer.
With prefix argument, ask for version number to check in or check out.
Check-out of a specified version number does not lock the file;
to do that, use this command a second time with no argument.

If you bind this function to \\[toggle-read-only], then Emacs checks files
in or out whenever you toggle the read-only flag."
  (interactive "P")
  (if (or (and (boundp 'vc-dired-mode) vc-dired-mode)
          ;; use boundp because vc.el might not be loaded
          (vc-backend buffer-file-name))
      (vc-next-action verbose)
    (toggle-read-only)))
うん、vc-next-action呼んでるじゃん。
これで良いんだよ、これで。
昔話をすると、CVS使ってたころは環境変数 CVSREAD ってのを設定しておいて、CVS管理下のファイルは全て read only ファイルを編集するときは C-x C-q 打って明示的に cvs edit して、編集が終わったら再度 C-x C-q 打って commiteしてたのよ。
今はそう言う使い方しないんだろうねえ。gitの場合は pushとかpullとかしなければ伝わらないしねえ。だったら余計にローカルコミットは C-x C-q で良くない?C-x v v って長いし。

と、言うわけで何が危険なんだかちゃんと理解しないままに、~/.emacs に以下を追加したのでした。
(defun my-toggle-read-only (&optional verbose)
  "Change read-only status of current buffer, perhaps via version control."
  (interactive "P")
  (if (or (and (boundp 'vc-dired-mode) vc-dired-mode)
          ;; use boundp because vc.el might not be loaded
          (vc-backend buffer-file-name))
      (vc-next-action verbose)
    (toggle-read-only)))
(global-set-key "\C-x\C-q" 'my-toggle-read-only)

カテゴリ

トラックバック(0)

このブログ記事を参照しているブログ一覧: git と emacs23

このブログ記事に対するトラックバックURL: https://www.wizard-limit.net/cgi-bin/mt/mt-tb.cgi/2425

コメントする

このブログ記事について

このページは、falseが2010年8月20日 15:45に書いたブログ記事です。

ひとつ前のブログ記事は「クライアント認証ができるようになった」です。

次のブログ記事は「ゲーム用PCその2」です。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。

広告

Powered by Movable Type 6.1.1