1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

psvn.elで空白を含むユーザ名に対処する

Last updated at Posted at 2014-11-22

githubのおかげもあり、オープンソースの世界ではソフト開発のバージョン管理にはgitがメジャーになっていますが、会社などのクローズな環境での開発では、まだまだsubversionが使われていると思います。Emacsのsubversionフロントエンドと言えば、長年愛用しているのがpsvn.elですが、(個人的に) 一番困るのが空白を含むユーザ名 (svn:author) を正しく扱えないこと。psvn.elのFAQにも一番最初に書いてあるくらいなので、多分困っているのは私だけではないはず...

そのFAQの通り一応対処法は用意してあって、svn-user-names-including-blanks に空白を含むユーザ名を列挙して svn-pre-parse-status-hook に設定すれば回避できます。ただ、この方法だとユーザ名ごとにいちいち追加していかなければならず、メンバーが多い場合には非常に面倒です。そこで、ある程度は自動的に判断して回避できるように、psvn.elを弄ってみました。

psvn.elは svn status -v の出力を取り込んでいるので、そのフォーマットを確認してみました。

              1234     1234 alpha22jp    file1.txt
              1234     1212 Nanashino Gonbei file2.txt
              1234      689 Ai Ueo       file3.txt

のように、ユーザ名のcolumnは12文字分が確保されていて、その後空白1つを挟んでファイルパスのcolumnになります。ユーザ名が12文字より短い場合は空白で埋められ、長い場合はその分ファイルパスのcolumnが後ろにずらされます。つまり、ユーザ名のcolumnの先頭から12文字分の間に '文字' '空白' '文字' のパターンがあれば、それはユーザ名の中の空白と判断してよいと言えます。ということで svn status -v の結果を処理する svn-parse-status-result 関数に以下のようなコードを入れることで、うまく対応できました。

psvn.el
          (let (line limit)
            (setq limit (svn-point-at-eol))
            (setq line (buffer-substring-no-properties (point) limit))
            (when (> (length (split-string line)) 4)
              (save-excursion
                (when
                    (re-search-forward "\\([-?]\\|[0-9]+\\) +\\([-?]\\|[0-9]+\\)" limit t)
                  ;; length of author column is at least 12 chars
                  (setq limit (+ (point) 12))
                  (while (re-search-forward "\\(\\w\\) \\(\\w\\)" limit t)
                    (replace-match "\\1.\\2"))))))

もちろん、これで対処しきれないケースもありますが、名字と名前の間の空白という典型的なケースは殆ど大丈夫なので、それから漏れるものは個別に svn-user-names-including-blanks に登録するという運用で問題ないでしょう。

上記変更を入れたpsvn.elは、こちらに上げてあるのでご利用下さい。EmacsWikiにあるsubversion 1.7以降への対応パッチも当ててあります。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?