开发者

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

开发者 https://www.devze.com 2022-12-19 07:42 出处:网络
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 no

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;   
    }   
}


This is a known subversion bug, I just hit as well. http://subversion.tigris.org/issues/show_bug.cgi?id=2487

To solve my problem I used vi and did the following

I usually do a :set hls (highlight search results) followed by /[^ -~] (search for any character that is not between space and tilde, ie. that is not a printable character from the ASCII set.) You can add the tab character (with Ctrl-V Tab) inside the square brackets if you use it in your documents. It will show as /[^ -~^I] with a blue ^I.

found a u in Cancun that had an accent but was actually not a legal latin-1 character.


I solved this (on debian) by editing the /etc/apache2/envvars and set the apache to run with the machine locale (the default is C):

## The locale used by some modules like mod_dav
export LANG=C
## Uncomment the following line to use the system default locale instead:
#. /etc/default/locale  

^---- uncomment this line to set the system locale in apache.

if you are not using a UTF-8 locale, manually set a UTF-8 locale just for apache:

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8


I also faced this issue and it was happening because I was using some special characters in my commit message. I just removed those characters and it worked like charm.

Specially look for apostrophe characters (when u have text copied from word document or so).


You need to add the following line in your httpd.conf file.

SVNUseUTF8 on

are you using CentOS? this maybe some OS issue, since it is almost impossible to find this tip only with Google.


In the post commit script or the commit message look for " or ' and check them if they are in UTF-8 format. If not change them and run it worked for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号