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
+17
View File
@@ -151,6 +151,23 @@ class scm
$jobToBuild = array_keys(array_flip($taskToBuild) + array_flip($newArr));
}
}
public function iconvComment($comment, $encodings)
{
/* Get encodings. */
if($encodings == '') return $comment;
$encodings = explode(',', $encodings);
/* Try convert. */
foreach($encodings as $encoding)
{
if($encoding == 'utf-8') continue;
$result = helper::convertEncoding($comment, $encoding);
if($result) return $result;
}
return $comment;
}
}
function escapeCmd($cmd)
-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);
+1
View File
@@ -140,6 +140,7 @@ $lang->repo->error->clientVersion = "Client version is too low, please upgrade o
$lang->repo->error->encoding = "The encoding maybe wrong. Please change the encoding and try again.";
$lang->repo->tips = '<strong>You may find the reference about how to set Git sync from <a target="_blank" href="https://www.zentao.net/book/zentaopmshelp/207.html">here</a>.</strong>';
$lang->repo->encodingsTips = "The encodings of commit comments, can be comma separated values,e.g. utf-8";
$lang->repo->example = new stdclass();
$lang->repo->example->client = "For example, /usr/bin/svn, C:\subversion\svn.exe, /usr/bin/git";
$lang->repo->example->path = "For example, SVN: http://example.googlecode.com/svn/, GIT: /home/test";
+1
View File
@@ -140,6 +140,7 @@ $lang->repo->error->clientVersion = "客户端版本过低,请升级或更换S
$lang->repo->error->encoding = "编码可能错误,请更换编码重试。";
$lang->repo->tips = '<strong>请参照<a target="_blank" href="https://www.zentao.net/book/zentaopmshelp/207.html">这里</a>,设置版本库定时同步。</strong>';
$lang->repo->encodingsTips = "提交日志的编码,可以用逗号连接起来的多个,比如utf-8。";
$lang->repo->example = new stdclass();
$lang->repo->example->client = "例如:/usr/bin/svn, C:\subversion\svn.exe, /usr/bin/git";
$lang->repo->example->path = "例如:SVN: http://example.googlecode.com/svn/, GIT: /homt/test";
+1 -1
View File
@@ -45,7 +45,7 @@
<tr>
<th><?php echo $lang->repo->encoding; ?></th>
<td class='required'><?php echo html::input('encoding', 'utf-8', "class='form-control'"); ?></td>
<td></td>
<td class='muted'><?php echo $lang->repo->encodingsTips; ?></td>
</tr>
<tr>
<th><?php echo $lang->repo->client;?></th>
+1 -1
View File
@@ -45,7 +45,7 @@
<tr>
<th><?php echo $lang->repo->encoding; ?></th>
<td class='required'><?php echo html::input('encoding', $repo->encoding, "class='form-control'"); ?></td>
<td></td>
<td class='muted'><?php echo $lang->repo->encodingsTips; ?></td>
</tr>
<tr>
<th><?php echo $lang->repo->client;?></th>
+6 -29
View File
@@ -119,7 +119,7 @@ class svnModel extends model
' task:' . join(' ', $objects['tasks']) .
' bug:' . join(',', $objects['bugs']));
$this->saveAction2PMS($objects, $log);
$this->saveAction2PMS($objects, $log, $repo->encoding);
}
else
{
@@ -223,7 +223,7 @@ class svnModel extends model
{
if(strtolower($repoInDb->SCM) === 'subversion' && !in_array($repoInDb->path, $svnRepos)) {
$svnRepos[] = (object)array('id'=>$repoInDb->id, 'path' => $repoInDb->path,
'encoding' => 'utf-8', 'client' => $repoInDb->client, 'account' => $repoInDb->account, 'password' => $repoInDb->password);
'encoding' => $repoInDb->encoding, 'client' => $repoInDb->client, 'account' => $repoInDb->account, 'password' => $repoInDb->password);
$paths[] = $repoInDb->path;
}
}
@@ -429,31 +429,6 @@ class svnModel 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->svn->encodings) ? $this->config->svn->encodings : '');
if($encodings == '') return $comment;
$encodings = explode(',', $encodings);
/* Try convert. */
foreach($encodings as $encoding)
{
if($encoding == 'utf-8') continue;
$result = helper::convertEncoding($comment, $encoding);
if($result) return $result;
}
return $comment;
}
/**
* Diff a url.
*
@@ -541,13 +516,15 @@ class svnModel 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 = 'svncommited';
$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 = $log->revision;
$changes = $this->createActionChanges($log, $repoRoot);