From fa707a14649d5c21fde35fb5eba56992432b328d Mon Sep 17 00:00:00 2001 From: wangyidong Date: Mon, 21 Aug 2017 16:00:42 +0800 Subject: [PATCH] * code for task #3100. --- module/git/config.php | 3 ++- module/git/model.php | 32 ++++++++++++++++++++++++++------ module/svn/config.php | 1 + module/svn/model.php | 14 +++++++------- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/module/git/config.php b/module/git/config.php index c5c8b2e310..8033ef700f 100644 --- a/module/git/config.php +++ b/module/git/config.php @@ -18,7 +18,8 @@ $config->git->encodings = 'utf-8'; $config->git->client = ''; $i = 1; -$config->git->repos[$i]['path'] = ''; +$config->git->repos[$i]['path'] = ''; +$config->git->repos[$i]['encoding'] = 'utf-8'; /* $i ++; diff --git a/module/git/model.php b/module/git/model.php index e377f375c2..ee564f1356 100644 --- a/module/git/model.php +++ b/module/git/model.php @@ -426,13 +426,23 @@ class gitModel extends model exec("{$this->client} config core.quotepath false"); $subPath = substr($path, strlen($repo->path)); if($subPath{0} == '/' or $subPath{0} == '\\') $subPath = substr($subPath, 1); + + $encodings = explode(',', $this->config->git->encodings); + foreach($encodings as $encoding) + { + $encoding = trim($encoding); + if($encoding == 'utf-8') continue; + $subPath = helper::convertEncoding($subPath, 'utf-8', $encoding); + if($subPath) break; + } + exec("$this->client rev-list -n 2 $revision -- $subPath", $lists); if(count($lists) == 2) list($nowRevision, $preRevision) = $lists; - $cmd = "$this->client diff $preRevision $nowRevision -- $subPath"; + $cmd = "$this->client diff $preRevision $nowRevision -- $subPath 2>&1"; $diff = `$cmd`; - $encodings = isset($repo->encodings) ? $repo->encodings : $this->config->svn->encodings; - if($encodings or $encodings != 'utf-8') $diff = helper::convertEncoding($diff, $encodings); + $encoding = isset($repo->encoding) ? $repo->encoding : 'utf-8'; + if($encoding and $encoding != 'utf-8') $diff = helper::convertEncoding($diff, $encoding); return $diff; } @@ -457,13 +467,23 @@ class gitModel extends model $subPath = substr($path, strlen($repo->path)); if($subPath{0} == '/' or $subPath{0} == '\\') $subPath = substr($subPath, 1); + + $encodings = explode(',', $this->config->git->encodings); + foreach($encodings as $encoding) + { + $encoding = trim($encoding); + if($encoding == 'utf-8') continue; + $subPath = helper::convertEncoding($subPath, 'utf-8', $encoding); + if($subPath) break; + } + chdir($repo->path); exec("{$this->client} config core.quotepath false"); - $cmd = "$this->client show $revision:$subPath"; + $cmd = "$this->client show $revision:$subPath 2>&1"; $code = `$cmd`; - $encodings = isset($repo->encodings) ? $repo->encodings : $this->config->git->encodings; - if($encodings or $encodings != 'utf-8') $code = helper::convertEncoding($code, $encodings); + $encoding = isset($repo->encoding) ? $repo->encoding : 'utf-8'; + if($encoding and $encoding != 'utf-8') $code = helper::convertEncoding($code, $encoding); return $code; } diff --git a/module/svn/config.php b/module/svn/config.php index dc4fcd29b9..6f6cded6a5 100644 --- a/module/svn/config.php +++ b/module/svn/config.php @@ -21,6 +21,7 @@ $config->svn->client = ''; $i = 1; $config->svn->repos[$i]['path'] = ''; +$config->svn->repos[$i]['encoding'] = 'utf-8'; $config->svn->repos[$i]['username'] = ''; $config->svn->repos[$i]['password'] = ''; diff --git a/module/svn/model.php b/module/svn/model.php index 9d7d15a3f9..2848f83c30 100644 --- a/module/svn/model.php +++ b/module/svn/model.php @@ -388,7 +388,7 @@ class svnModel extends model foreach($encodings as $encoding) { if($encoding == 'utf-8') continue; - $result = @iconv($encoding, 'utf-8', $comment); + $result = helper::convertEncoding($comment, $encoding) if($result) return $result; } @@ -417,11 +417,11 @@ class svnModel extends model $url = str_replace('%2F', '/', urlencode($url)); $url = str_replace('%3A', ':', $url); - $cmd = $this->client . " diff -r $oldRevision:$revision $url"; + $cmd = $this->client . " diff -r $oldRevision:$revision $url 2>&1"; $diff = `$cmd`; - $encodings = isset($repo->encodings) ? $repo->encodings : $this->config->svn->encodings; - if($encodings or $encodings != 'utf-8') $diff = helper::convertEncoding($diff, $encodings); + $encoding = isset($repo->encoding) ? $repo->encoding : 'utf-8'; + if($encoding and $encoding != 'utf-8') $diff = helper::convertEncoding($diff, $encoding); return $diff; } @@ -447,11 +447,11 @@ class svnModel extends model $url = str_replace('%2F', '/', urlencode($url)); $url = str_replace('%3A', ':', $url); - $cmd = $this->client . " cat $url@$revision"; + $cmd = $this->client . " cat $url@$revision 2>&1"; $code = `$cmd`; - $encodings = isset($repo->encodings) ? $repo->encodings : $this->config->svn->encodings; - if($encodings or $encodings != 'utf-8') $code = helper::convertEncoding($code, $encodings); + $encoding = isset($repo->encoding) ? $repo->encoding : 'utf-8'; + if($encoding and $encoding != 'utf-8') $code = helper::convertEncoding($code, $encoding); return $code; }