2011-12-08 1 views
0

%% 해결 문제와 나는 SVN 쓰기 위해 노력하고있어 기대 %%SVN 트랜잭션이 아닌 SVN 트랜잭션에서 읽을 때 iconv가 종료되는 이유는 무엇입니까?

역할을 아래의 코드 UTF-8 인코딩에 들어오는 파일을 테스트 배쉬 후크 사전은 커밋. 들어오는 파일의 경로를 얻고 dirs/그림/삭제 된 파일 등을 무시하기 위해 많은 문자열을 저글링 한 후에 'svnlook cat'을 사용하여 들어오는 파일을 읽고 'iconv -f UTF-8'로 파이프합니다. 이 후에 $ {PIPESTATUS [1]}로 iconv 조작의 종료 상태를 읽습니다. 이 같은

내 코드 조회 :

REPOS="$1" 
TXN="$2" 

SVNLOOK=/usr/bin/svnlook 
ICONV=/usr/bin/iconv 

# The file endings to ignore when checking for UTF-8: 
IGNORED_ENDINGS=(png jar) 

# Prepairing to set the IFS (Internal Field Separator) so "for CHANGE in ..." will iterate 
# over lines instead of words 
OIFS="${IFS}" 
NIFS=$'\n' 

# Make sure that all files to be committed are encoded in UTF-8 
IFS="${NIFS}" 

for CHANGE in $($SVNLOOK changed -t "$TXN" "$REPOS"); do 
    IFS="${OIFS}" 
    # Skip change if first character is "D" (we dont care about checking deleted files) 
    if [ "${CHANGE:0:1}" == "D" ]; then 
     continue 
    fi 

    # Skip change if it is a directory (directories don't have encoding) 
    if [ "${CHANGE:(-1)}" == "/" ]; then 
     continue 
    fi 

    # Extract file repository path (remove first 4 characters) 
    FILEPATH=${CHANGE:4:(${#CHANGE}-4)} 

    # Ignore files that starts with "." like ".classpath" 
    IFS="//" # Change seperator to "/" so we can find the file in the file path 
    for SPLIT in $FILEPATH 
    do 
     FILE=$SPLIT 
    done 
    if [ "${FILE:0:1}" == "." ]; then 
     continue 
    fi 
    IFS="${OIFS}" # Reset Internal Field Seperator 

    # Ignore files that are not supposed to be checked, like images. (list defined in IGNORED_ENDINGS field above) 
    IFS="." # Change seperator to "." so we can find the file ending 
    for SPLIT in $FILE 
    do 
     ENDING=$SPLIT 
    done 
    IFS="${OIFS}" # Reset Internal Field Seperator 
    IGNORE="0" 
    for IGNORED_ENDING in ${IGNORED_ENDINGS[@]} 
    do 
     if [ `echo $IGNORED_ENDING | tr [:upper:] [:lower:]` == `echo $ENDING | tr [:upper:] [:lower:]` ] # case insensitive compare of strings 
     then 
      IGNORE="1" 
     fi 
    done 
    if [ "$IGNORE" == "1" ]; then 
     continue 
    fi 

    # Read changed file and pipe it to iconv to parse it as UTF-8 
    $SVNLOOK cat -t "$TXN" "$REPOS" "$FILEPATH" | $ICONV -f UTF-8 -t UTF-16 -o /dev/null 

    # If iconv exited with a non-zero value (error) then return error text and reject commit 
    if [ "${PIPESTATUS[1]}" != "0" ]; then 
     echo "Only UTF-8 files can be committed (violated in $FILEPATH)" 1>&2 
     exit 1 
    fi 
    IFS="${NIFS}" 
done 

IFS="${OIFS}" 

# All checks passed, so allow the commit. 
exit 0 

문제는, 내가 오류 (1 번 출구)를 반환의 iconv "æøå"와 같은 스칸디나비아 문자로 파일을 커밋하려고 할 때마다.

"æøå"로 파일을 커밋하고 "svnlook -t"및 "svnlook cat -t"에서 -t (트랜잭션)를 -r (개정)으로 변경하고 스크립트를 실행하십시오 수동으로 "æøå"파일의 개정 번호로 누른 다음 iconv (그리고 그에 대한 스크립트)는 0 번을 반환합니다. 그리고 모든 것이 멋쟁이입니다.

svnlook cat -r이 (UTF-8로 인코딩 된 "æøå"문자열을 반환하는) 예상대로 작동하지만 svnlook cat -t가 아닌 이유는 무엇입니까?

답변

0

출력 인코딩을 선택하지 않으면 iconv가 예기치 않게 작동합니다.

$SVNLOOK cat -t "$TXN" "$REPOS" "$FILEPATH" | $ICONV -f UTF-8 -o /dev/null 

$SVNLOOK cat -t "$TXN" "$REPOS" "$FILEPATH" | $ICONV -f UTF-8 -t UTF-16 -o /dev/null 

에 변경

문제를 해결하고, 예상대로 작동 스크립트 :

했다