Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6947085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:38:55+00:00 2026-05-27T13:38:55+00:00

%% Problem solved and the code below acts as expected %% I’m trying to

  • 0

%% Problem solved and the code below acts as expected %%

I’m trying to write a SVN pre-commit hook in Bash that tests incoming files for UTF-8 encoding. After a lot of string juggling to get the path of the incoming files and ignore dirs/pictures/deleted files and so on, I use ‘svnlook cat’ to read the incoming file and pipe it to ‘iconv -f UTF-8’. After this I read the exit status of the iconv operation with ${PIPESTATUS[1]}.

My code look like this:

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

The problem is, every time I try to commit a file with Scandinavian characters like “æøå” iconv returns an error (exit 1).

If I disable the script, commit the file with “æøå”, change the -t (transaction) in “svnlook -t” and “svnlook cat -t” to a -r (revision), and run the script manually with the revision number of the “æøå” file, then iconv (and therefor the script) returns exit 0. And everthing is dandy.

Why does svnlook cat -r work as expected (returning UTF-8 encoded “æøå” string), but not svnlook cat -t?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:38:56+00:00Added an answer on May 27, 2026 at 1:38 pm

    The problem was that iconv apparently behaves unexpectedly if no output encoding is selected.

    Changing

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

    to

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

    solved the problem, and made the script behave as expected 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PROBLEM SOLVED! STUPID TYPO IN MY CODE! That's my method of my UIScrollView delegate:
The problem mentioned below has been solved and code has been changed to reflect
I solved Problem 10 of Project Euler with the following code, which works through
I am trying to solve the problem Secret Code on SPOJ , and it's
I'm trying to solve the problem here but I don't know why my code
I'm trying to solve this problem, its not a homework question, its just code
PROBLEM SOLVED: I was overlooking a very simple issue, and that is that this
Problem solved: Thanks guys, see my answer below. I have a website running in
Is anyone trying to write their encoder code for the conversion of avi to
I have a problem with a piece of legacy c++/winsock code that is part

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.