diff --git a/lib/scm/scm.class.php b/lib/scm/scm.class.php index fa25c2d929..5e2c30782e 100644 --- a/lib/scm/scm.class.php +++ b/lib/scm/scm.class.php @@ -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) diff --git a/module/git/config.php b/module/git/config.php index 3939637730..a4abe2dafc 100644 --- a/module/git/config.php +++ b/module/git/config.php @@ -1,28 +1,2 @@ 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'] = ''; -*/ diff --git a/module/git/model.php b/module/git/model.php index 4c2819fdb5..fd45df8aa0 100644 --- a/module/git/model.php +++ b/module/git/model.php @@ -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); diff --git a/module/repo/lang/en.php b/module/repo/lang/en.php index 729ff8748a..bff2fce85c 100644 --- a/module/repo/lang/en.php +++ b/module/repo/lang/en.php @@ -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 = 'You may find the reference about how to set Git sync from here.'; +$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"; diff --git a/module/repo/lang/zh-cn.php b/module/repo/lang/zh-cn.php index c94c19d375..bd716d4af4 100644 --- a/module/repo/lang/zh-cn.php +++ b/module/repo/lang/zh-cn.php @@ -140,6 +140,7 @@ $lang->repo->error->clientVersion = "客户端版本过低,请升级或更换S $lang->repo->error->encoding = "编码可能错误,请更换编码重试。"; $lang->repo->tips = '请参照这里,设置版本库定时同步。'; +$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"; diff --git a/module/repo/view/create.html.php b/module/repo/view/create.html.php index fe063f55f2..0e1885a799 100644 --- a/module/repo/view/create.html.php +++ b/module/repo/view/create.html.php @@ -45,7 +45,7 @@