svn - svn 中的预提交钩子(Hook) : could not be translated from the native locale to UTF-8

标签 svn utf-8 hook

我的预提交 Hook 有问题。

此 Hook 测试用户提交时文件是否被锁定。当发生不良情况时,它应该输出另一个用户正在锁定该文件,或者如果没有人锁定,它应该显示“您没有锁定该文件消息(文件名)”。当文件名包含一些拉丁字符(如“ç”)并且乌龟在输出中显示此错误时,就会发生错误。

提交失败(详细信息如下): 提交被预提交 Hook (退出代码 1)阻止,输出为: [错误输出无法从 native 语言环境转换为 UTF-8。]

你知道我该如何解决这个问题吗?

谢谢

亚历山大

我的 shell 脚本在这里:

#!/bin/sh
REPOS="$1"
TXN="$2"
导出 LANG="en_US.UTF-8"
/app/svn/hooks/ensure-has-need-lock.pl "$REPOS""$TXN"
如果 [ $? -ne 0];然后退出1; fi
退出 0

我的 Perl 在这里:

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

最佳答案

这是一个已知的颠覆错误,我也刚刚遇到过。 http://subversion.tigris.org/issues/show_bug.cgi?id=2487

为了解决我的问题,我使用 vi 并执行了以下操作

我通常会执行 :set hls (突出显示搜索结果),然后是/[^ -~] (搜索不在空格和波形符之间的任何字符,即 不是 ASCII 集中的可打印字符。)您可以添加制表符 如果您在方括号内使用字符(使用 Ctrl-V Tab) 你的文件。它将显示为/[^ -~^I] 并带有蓝色 ^I。

在坎昆发现了一个带口音的 u,但实际上不是合法的 latin-1 字符。

关于svn - svn 中的预提交钩子(Hook) : could not be translated from the native locale to UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2223958/

相关文章:

linux - Redmine中的SVN URL如何修改?

MongoDB SpiderMonkey 不理解 UTF-8

encoding - 如何停止 Server.HtmlEncode 编码 UTF8 字符?

C++ 重定向传出连接

javascript - Ember.Route - 模型钩子(Hook)被调用两次而不是一次

svn - 在更新之前,我可以像在 Eclipse 中一样在 TortoiseSVN 中查看传入的更改吗?

svn - SourceSafe 用户的颠覆

java - 在 Netbeans 中 react 包后,我无法再提交

encoding - 如何在 Aptana Studio 3 中设置 UTF-8?

c++ - 从另一个应用程序访问 lua_State