* finish task #6859.
This commit is contained in:
@@ -390,6 +390,51 @@ class repo extends control
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Blame repo file.
|
||||
*
|
||||
* @param int $repoID
|
||||
* @param string $entry
|
||||
* @param string $revision
|
||||
* @param string $encoding
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function blame($repoID, $entry, $revision = 'HEAD', $encoding = '')
|
||||
{
|
||||
if($this->get->entry) $entry = $this->get->entry;
|
||||
$this->repo->setMenu($this->repos, $repoID);
|
||||
if($repoID == 0) $repoID = $this->session->repoID;
|
||||
$repo = $this->repo->getRepoByID($repoID);
|
||||
$file = $entry;
|
||||
$entry = $this->repo->decodePath($entry);
|
||||
|
||||
$this->scm->setEngine($repo);
|
||||
$encoding = empty($encoding) ? $repo->encoding : $encoding;
|
||||
$encoding = strtolower(str_replace('_', '-', $encoding));
|
||||
$blames = $this->scm->blame($entry, $revision);
|
||||
$revisions = array();
|
||||
foreach($blames as $i => $blame)
|
||||
{
|
||||
if(isset($blame['revision'])) $revisions[$blame['revision']] = $blame['revision'];
|
||||
if($encoding != 'utf-8') $blames[$i]['content'] = helper::convertEncoding($blame['content'], $encoding);
|
||||
}
|
||||
|
||||
$log = $repo->SCM == 'Git' ? $this->dao->select('revision,commit')->from(TABLE_REPOHISTORY)->where('revision')->eq($revision)->andWhere('repo')->eq($repo->id)->fetch() : '';
|
||||
|
||||
$this->view->title = $this->lang->repo->common;
|
||||
$this->view->repoID = $repoID;
|
||||
$this->view->repo = $repo;
|
||||
$this->view->revision = $revision;
|
||||
$this->view->entry = $entry;
|
||||
$this->view->file = $file;
|
||||
$this->view->encoding = str_replace('-', '_', $encoding);
|
||||
$this->view->historys = $repo->SCM == 'Git' ? $this->dao->select('revision,commit')->from(TABLE_REPOHISTORY)->where('revision')->in($revisions)->andWhere('repo')->eq($repo->id)->fetchPairs() : '';
|
||||
$this->view->revisionName = ($log and $repo->SCM == 'Git') ? $this->repo->getGitRevisionName($log->revision, $log->commit) : $revision;
|
||||
$this->view->blames = $blames;
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show diff.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* The create view file of repo module of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2012 青岛易软天创网络科技有限公司 (QingDao Nature Easy Soft Network Technology Co,LTD www.cnezsoft.com)
|
||||
* @author Wang Yidong, Zhu Jinyong
|
||||
* @package repo
|
||||
* @version $Id: blame.html.php $
|
||||
*/
|
||||
?>
|
||||
<?php
|
||||
include '../../common/view/header.html.php';
|
||||
js::import($jsRoot . 'misc/highlight/highlight.pack.js');
|
||||
css::import($jsRoot . 'misc/highlight/styles/github.css');
|
||||
?>
|
||||
<?php if(!isonlybody()):?>
|
||||
<div id='mainMenu' class='clearfix'>
|
||||
<div class="btn-toolbar pull-left">
|
||||
<?php
|
||||
$backURI = $this->session->repoView ? $this->session->repoView : $this->session->repoList;
|
||||
if($backURI)
|
||||
{
|
||||
echo html::a($backURI, "<i class='icon icon-back icon-sm'></i>" . $lang->goback, '', "class='btn btn-link'");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo html::backButton("<i class='icon icon-back icon-sm'></i>" . $lang->goback, '', 'btn btn-link');
|
||||
}
|
||||
?>
|
||||
<div class="divider"></div>
|
||||
<div class="page-title">
|
||||
<strong>
|
||||
<?php
|
||||
echo html::a($this->repo->createLink('browse', "repoID=$repoID"), $repo->name);
|
||||
$paths= explode('/', $entry);
|
||||
$fileName = array_pop($paths);
|
||||
$postPath = '';
|
||||
foreach($paths as $pathName)
|
||||
{
|
||||
$postPath .= $pathName . '/';
|
||||
echo '/' . ' ' . html::a($this->repo->createLink('browse', "repoID=$repoID", "path=" . $this->repo->encodePath($postPath)), trim($pathName, '/'));
|
||||
}
|
||||
echo '/' . ' ' . $fileName;
|
||||
echo " <span class='label label-info'>" . $revisionName . '</span>';
|
||||
?>
|
||||
</strong>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
|
||||
<div class="code panel">
|
||||
<div class='panel-heading'>
|
||||
<div class='panel-title'><?php echo $entry;?></div>
|
||||
<?php $encodePath = $this->repo->encodePath($entry);?>
|
||||
<div class='panel-actions'>
|
||||
<div class='btn-group'>
|
||||
<?php echo html::commonButton(zget($lang->repo->encodingList, $encoding, $lang->repo->encoding) . "<span class='caret'></span>", "id='encoding' data-toggle='dropdown'", 'btn dropdown-toggle')?>
|
||||
<ul class='dropdown-menu' role='menu' aria-labelledby='encoding'>
|
||||
<?php foreach($lang->repo->encodingList as $key => $val):?>
|
||||
<li><?php echo html::a($this->repo->createLink('blame', "repoID=$repoID&entry=&revision=$revision&encoding=$key", "entry=$encodePath"), $val)?></li>
|
||||
<?php endforeach;?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<table class="blame table table-form table-fixed">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class='w-70px'><?php echo $lang->repo->revision?></td>
|
||||
<?php if($repo->SCM == 'Git'):?>
|
||||
<td class='w-50px'><?php echo $lang->repo->commit?></td>
|
||||
<?php endif;?>
|
||||
<td class='w-100px'><?php echo $lang->repo->committer?></td>
|
||||
<td class="w-40px"><?php echo $lang->repo->line?></td>
|
||||
<td><?php echo $lang->repo->code?></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($blames as $blame):?>
|
||||
<tr<?php if(isset($blame['lines'])) echo " class='topLine'";?>>
|
||||
<?php
|
||||
if(isset($blame['lines']))
|
||||
{
|
||||
$rowspan = $blame['lines'];
|
||||
echo '<td rowspan="' . $rowspan . '" class="info" title="' . $blame['revision'] . '">';
|
||||
echo $repo->SCM == 'Git' ? substr($blame['revision'], 0, 10) : $blame['revision'];
|
||||
echo '</td>';
|
||||
if($repo->SCM == 'Git') echo '<td rowspan="' . $rowspan . '" class="info">' . zget($historys, $blame['revision'], '') . '</td>';
|
||||
echo '<td rowspan="' . $rowspan . '" class="info">' . $blame['committer'] . '</td>';
|
||||
}
|
||||
?>
|
||||
<td class="line"><?php echo $blame['line'];?></td>
|
||||
<td><pre><?php echo htmlspecialchars($blame['content']);?></pre></td>
|
||||
</tr>
|
||||
<?php endforeach?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<?php include '../../common/view/footer.html.php';?>
|
||||
Reference in New Issue
Block a user