pre-commit hook in svn: could not be translated from the native locale to UTF-8

Posted by Alexandre Moraes on Stack Overflow See other posts from Stack Overflow or by Alexandre Moraes
Published on 2010-02-08T18:38:41Z Indexed on 2011/01/14 2:53 UTC
Read the original article Hit count: 524

Filed under:
|
|

Hi everybody,

I have a problem with my pre-commit hook.

This hook test if a file is locked when the user commits. When a bad condition happens, it should output that the another user is locking this file or if nobody is locking, it should show "you are not locking this file message (file´s name)". The error happens when the file´s name has some latin character like "ç" and tortoise show me this in the output.

Commit failed (details follow): Commit blocked by pre-commit hook (exit code 1) with output: [Erro output could not be translated from the native locale to UTF-8.]

Do you know how can I solve this?

Thanks,

Alexandre

My shell script is here:

#!/bin/sh
REPOS="$1"
TXN="$2"
export LANG="en_US.UTF-8"
/app/svn/hooks/ensure-has-need-lock.pl "$REPOS" "$TXN"
if [ $? -ne 0 ]; then exit 1; fi
exit 0

And my perl is here:

!/usr/bin/env perl  

#Turn on warnings the best way depending on the Perl version.   
BEGIN {   
  if ( $] >= 5.006_000)   
    { require warnings; import warnings; }                         
  else     
    { $^W = 1; }                  
}              

use strict;   
use Carp;   

&usage unless @ARGV == 2;   

my $repos        = shift;   
my $txn          = shift;    

my $svnlook = "/usr/local/bin/svnlook";   
my $user;   

my $ok = 1;   
  foreach my $program ($svnlook)   
    {   
      if (-e $program)   
        {   
          unless (-x $program)   
            {   
              warn "$0: required program $program' is not executable, ",   
                   "edit $0.\n";   
              $ok = 0;   
            }   
        }   
      else   
        {   
          warn "$0: required program $program' does not exist, edit $0.\n";   
          $ok = 0;   
        }   
    }   
  exit 1 unless $ok;   

  unless (-e $repos){   
      &usage("$0: repository directory $repos' does not exist.");   
  }   
  unless (-d $repos){   
      &usage("$0: repository directory $repos' is not a directory.");   
  }   

  foreach my $user_tmp (&read_from_process($svnlook, 'author', $repos, '-t', $txn))   
  {   
      $user = $user_tmp;   
  }   
  my @errors;           

  foreach my $transaction (&read_from_process($svnlook, 'changed', $repos, '-t', $txn)){  
    if ($transaction =~ /^U.  (.*[^\/])$/){   
      my $file = $1;   
      my $err = 0;   
      foreach my $locks (&read_from_process($svnlook, 'lock', $repos, $file)){   
        $err = 1;   
        if($locks=~ /Owner: (.*)/){   
          if($1 != $user){   
           push @errors, "$file : You are not locking this file!";    
          }   
        }   
      }   
      if($err==0){   
        push @errors, "$file : You are not locking this file!";   
      }   
    }   
    elsif($transaction =~ /^D.  (.*[^\/])$/){   
      my $file = $1;   
      my $tchan = &read_from_process($svnlook, 'lock', $repos, $file);   
      foreach my $locks (&read_from_process($svnlook, 'lock', $repos, $file)){   
        push @errors, "$1 : cannot delete locked Files";   
      }   
    }   
    elsif($transaction =~ /^A.  (.*[^\/])$/){   
      my $needs_lock;   
      my $path = $1;   
      foreach my $prop (&read_from_process($svnlook, 'proplist', $repos, '-t', $txn, '--verbose', $path)){   
          if ($prop =~ /^\s*svn:needs-lock : (\S+)/){   
            $needs_lock = $1;   
          }   
      }   
      if (not $needs_lock){   
        push @errors, "$path : svn:needs-lock is not set. Pleas ask TCC for support.";   
      }   
    }   
  }   
if (@errors)   
  {   
    warn "$0:\n\n",   
         join("\n", @errors), "\n\n";   
    exit 1;   
  }   
else   
  {   
    exit 0;   
  }   

sub usage   
{   
  warn "@_\n" if @_;   
  die "usage: $0 REPOS TXN-NAME\n";   
}   

sub safe_read_from_pipe   
{   
  unless (@_)   
    {   
      croak "$0: safe_read_from_pipe passed no arguments.\n";   
    }   
  print "Running @_\n";   
  my $pid = open(SAFE_READ, '-|');   
  unless (defined $pid)   
    {   
      die "$0: cannot fork: $!\n";   
    }   
  unless ($pid)   
    {   
      open(STDERR, ">&STDOUT")   
        or die "$0: cannot dup STDOUT: $!\n";   
      exec(@_)   
        or die "$0: cannot exec @_': $!\n";   
    }   
  my @output;   
  while (<SAFE_READ>)   
    {   
      chomp;   
      push(@output, $_);   
    }   
  close(SAFE_READ);   
  my $result = $?;   
  my $exit   = $result >> 8;   
  my $signal = $result & 127;   
  my $cd     = $result & 128 ? "with core dump" : "";   
  if ($signal or $cd)   
    {   
      warn "$0: pipe from @_' failed $cd: exit=$exit signal=$signal\n";   
    }   
  if (wantarray)   
    {   
      return ($result, @output);   
    }   
  else   
    {   
      return $result;   
    }   
}   

sub read_from_process   
  {   
  unless (@_)   
    {   
      croak "$0: read_from_process passed no arguments.\n";   
    }   
  my ($status, @output) = &safe_read_from_pipe(@_);   
  if ($status)   
    {   
      if (@output)   
        {   
          die "$0: @_' failed with this output:\n", join("\n", @output), "\n";   
        }   
      else   
        {   
          die "$0: @_' failed with no output.\n";   
        }   
    }   
  else   
    {   
      return @output;   
    }   
}

© Stack Overflow or respective owner

Related posts about svn

Related posts about utf-8