change git and svn to use the encoding defined in repo table

This commit is contained in:
aaronchen2k
2020-02-03 17:42:48 +08:00
parent a3a7b04531
commit dda120936d
8 changed files with 32 additions and 85 deletions
-26
View File
@@ -1,28 +1,2 @@
<?php
/**
* encodings: 提交日志的编码,比如GBK,可以用逗号连接起来的多个。
* client: Git客户端执行文件的路径,windows下面是git.exe的路径,linux下面比如/usr/bin/git
* repos可以是多个,需要设定某一个库的访问路径。
*
* encodeings: the encoding of the comment,can be a list.
* client: the git client binary path. Unser windows, find the path of git.exe. Under linux, try /usr/bin/git
* Can set multi repos, ervery one should set the path.
*
* 例子:
* $config->git->client = '/usr/bin/git'; // c:\git\git.exe
* $config->git->repos['pms']['path'] = '/home/user/repo/pms'; // c:\repo\pms
*
*/
/* will use the config of repo records in db
$config->git = new stdClass();
$config->git->encodings = 'utf-8';
$config->git->client = '/usr/bin/git';
$i = 1;
$config->git->repos[$i]['path'] = '/Users/aaron/devops/project/devops_test';
$config->git->repos[$i]['encoding'] = 'utf-8';
$i ++;
$config->git->repos[$i]['path'] = '';
*/
+5 -28
View File
@@ -120,7 +120,7 @@ class gitModel extends model
' task:' . join(' ', $objects['tasks']) .
' bug:' . join(',', $objects['bugs']));
$this->saveAction2PMS($objects, $log);
$this->saveAction2PMS($objects, $log, $repo->encoding);
}
else
{
@@ -444,31 +444,6 @@ class gitModel extends model
return $parsedLog;
}
/**
* Convert the comment to uft-8.
*
* @param string $comment
* @access public
* @return string
*/
public function iconvComment($comment)
{
/* Get encodings. */
$encodings = str_replace(' ', '', isset($this->config->git->encodings) ? $this->config->git->encodings : '');
if($encodings == '') return $comment;
$encodings = explode(',', $encodings);
/* Try convert. */
foreach($encodings as $encoding)
{
if($encoding == 'utf-8') continue;
$result = helper::convertEncoding($comment, $encoding, 'utf-8');
if($result) return $result;
}
return $comment;
}
/**
* Diff a url.
*
@@ -578,13 +553,15 @@ class gitModel extends model
* @access public
* @return void
*/
public function saveAction2PMS($objects, $log, $repoRoot = '')
public function saveAction2PMS($objects, $log, $repoRoot = '', $encodings = 'utf-8')
{
$action = new stdclass();
$action->actor = $log->author;
$action->action = 'gitcommited';
$action->date = $log->date;
$action->comment = htmlspecialchars($this->iconvComment($log->msg));
$scm = $this->app->loadClass('scm');
$action->comment = htmlspecialchars($scm->iconvComment($log->msg, $encodings));
$action->extra = substr($log->revision, 0, 10);
$changes = $this->createActionChanges($log, $repoRoot);