Thursday, September 22, 2011

vim edited files, then use utf-8 encoding as default when svn commit

Move the original svn binary to svn.orig:
# mv /usr/local/bin/svn /usr/local/bin/svn.orig

Create a svn binary wrapper script:
# vi /usr/local/bin/svn
#!/bin/sh

### initialize
svnarg=""

### use encoding utf-8 as default if run "svn ci" or "svn commit".
if [ "$1" != "help" ]; then
  for myarg in "$@"; do
    if [ "${myarg}" = "commit" ] || [ "${myarg}" = "ci" ]; then
      svnarg="--encoding utf-8"
      break
    fi
  done
fi

### wrapper script to set umask to 027 on subversion binaries
### Note: the meaning of each umask:
### umask 002 // File permission 644. Owner can read/write. Group and Others can only read.
### umask 007 // File permission 660. Owner and Group can read/write. Others can not read or write.
### umask 027 // File permission 640. Owner can read/write. Group can read. Others can not read or write.
umask 027

### svn command
/usr/local/bin/svn.orig ${svnarg} "$@"

Try to "svn commit" a file:
# svn commit --message "svn log message: Hello World!"

or shortcut
# svn ci --message "svn log message: Hello World!"

My ~/.vimrc setting:
# cat ~/.vimrc
" let vim correctly load these ecnoding files
set fileencodings=utf-8,big5,euc-jp,gbk,euc-kr,utf-bom,iso8859-1
" file default encoding utf-8
set encoding=utf-8

For ~/.cshrc setting:
# cat ~/.cshrc
setenv LC_ALL en_US.UTF-8
setenv LANG en_US.UTF-8

setenv TERM screen-256color

For ~/.bashrc setting:
### utf-8 mode
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

To see a list of the available locales:
# locale -a

To see current locale setting:
# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_ALL=en_US.UTF-8

2 comments:

Gláucio said...

Really nice post!

Have you ever found a SVN variable to set instead of using the shell script?

Gláucio said...

I just figured it out.

SVN probably uses LANG unix variable when --encoding is not used on svn commit.

I've tried and it sets utf-8 successfully, just using a ordinary commit line command: "svn ci ."