参考
- svn.apache.org/repos/asf/subversion/trunk/notes/unicode-composition-for-filenames
- subversion: 課題 2464
このスクリプトはSubversion で ASCII 以外のファイル名を追加させない方法 - 酒日記 はてな支店を参考にさせて頂きました。ありがとうございます。
検証環境は、Scientific Linux 6.1, Subversion 1.7.2 (ソースからビルド)です。
以下のファイルをレポジトリのhooksディレクトリにpre-commitというファイル名で配置して実行パーミションをつけます。
#!/usr/bin/env perl
use strict;
use utf8;
use open ":utf8";
use Encode;
use Unicode::Normalize;
$ENV{LANG} = 'ja_JP.utf8';
my $SVNLOOK='/usr/bin/svnlook';
sub main {
my ($repos, $txn) = @_;
my @cmd = ($SVNLOOK, 'changed', "-t$txn", $repos);
open my $pipe, '-|', @cmd or die $!;
my $error = 0;
while (my $line = <$pipe>) {
chomp $line;
if ($line =~ /^A\s+(.*)$/) {
my $path = $1;
if (contains_composition_characters($path)) {
warn "Cannot use filename containing composition characters (ex. dakuten): $path\n";
$error = 1;
}
}
}
close $pipe;
exit $error;
}
sub contains_composition_characters {
my $path = shift;
return NFC($path) ne $path || NFD($path) ne $path;
}
if (@ARGV != 2) {
die "Usage: $0 REPOS TXN\n";
}
main(@ARGV);上記のスクリプト利用時にはApache実行時のLANGをja_JP.utf8にする必要があります。Scientific Linux 6.1の場合は、/etc/sysconfig/httpdにて以下のように設定します。
HTTPD_LANG=ja_JP.utf8
LANGがデフォルトのCだとコミット時にエラーメッセージが表示できず、以下のようになってしまいます。
$ svn ci -m '' Adding d4です.txt Transmitting file data .svn: Commit failed (details follow): svn: Commit blocked by pre-commit hook (exit code 1) with output: [Error output could not be translated from the native locale to UTF-8.]