added full view of code difference

This commit is contained in:
hyung-hwan 2015-01-25 17:09:28 +00:00
parent d5b787036f
commit 11e60639af
6 changed files with 69 additions and 21 deletions

View File

@ -336,7 +336,7 @@ class Code extends Controller
} }
} }
function diff ($projectid = '', $path = '', $rev1 = SVN_REVISION_HEAD, $rev2 = SVN_REVISION_HEAD) function _do_diff ($projectid = '', $path = '', $rev1 = SVN_REVISION_HEAD, $rev2 = SVN_REVISION_HEAD, $full = FALSE)
{ {
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');
$this->load->model ('SubversionModel', 'subversion'); $this->load->model ('SubversionModel', 'subversion');
@ -371,7 +371,7 @@ class Code extends Controller
redirect ("main/signin/" . $this->converter->AsciiTohex(current_url())); redirect ("main/signin/" . $this->converter->AsciiTohex(current_url()));
} }
$file = $this->subversion->getDiff ($projectid, $path, $rev1, $rev2); $file = $this->subversion->getDiff ($projectid, $path, $rev1, $rev2, $full);
if ($file === FALSE) if ($file === FALSE)
{ {
$data['project'] = $project; $data['project'] = $project;
@ -400,6 +400,16 @@ class Code extends Controller
} }
} }
function diff ($projectid = '', $path = '', $rev1 = SVN_REVISION_HEAD, $rev2 = SVN_REVISION_HEAD)
{
return $this->_do_diff ($projectid, $path, $rev1, $rev2, FALSE);
}
function fulldiff ($projectid = '', $path = '', $rev1 = SVN_REVISION_HEAD, $rev2 = SVN_REVISION_HEAD)
{
return $this->_do_diff ($projectid, $path, $rev1, $rev2, TRUE);
}
function fetch ($projectid = '', $path = '', $rev = SVN_REVISION_HEAD) function fetch ($projectid = '', $path = '', $rev = SVN_REVISION_HEAD)
{ {
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');

View File

@ -30,6 +30,7 @@ $lang['File'] = 'File';
$lang['Files'] = 'Files'; $lang['Files'] = 'Files';
$lang['First'] = 'First'; $lang['First'] = 'First';
$lang['Folder'] = 'Folder'; $lang['Folder'] = 'Folder';
$lang['Full Difference'] = 'FullDiff';
$lang['Head revision'] = 'Head revision'; $lang['Head revision'] = 'Head revision';
$lang['Hide details'] = 'Hide details'; $lang['Hide details'] = 'Hide details';
$lang['History'] = 'History'; $lang['History'] = 'History';

View File

@ -28,6 +28,7 @@ $lang['File'] = 'File';
$lang['Files'] = 'File'; $lang['Files'] = 'File';
$lang['First'] = 'Pertama'; $lang['First'] = 'Pertama';
$lang['Folder'] = 'Folder'; $lang['Folder'] = 'Folder';
$lang['Full Difference'] = 'FullDiff';
$lang['Head revision'] = 'Kepala revisi'; $lang['Head revision'] = 'Kepala revisi';
$lang['History'] = 'Sejarah'; $lang['History'] = 'Sejarah';
$lang['Home'] = 'Beranda'; $lang['Home'] = 'Beranda';

View File

@ -20,7 +20,7 @@ $lang['Delete'] = '삭제';
$lang['Description'] = '설명'; $lang['Description'] = '설명';
$lang['Destyle'] = '모양새제거'; $lang['Destyle'] = '모양새제거';
$lang['Details'] = '상세내역'; $lang['Details'] = '상세내역';
$lang['Difference'] = '차이'; $lang['Difference'] = '차이';
$lang['Directory'] = '디렉토리'; $lang['Directory'] = '디렉토리';
$lang['Download'] = '내려받음'; $lang['Download'] = '내려받음';
$lang['Edit'] = '수정'; $lang['Edit'] = '수정';
@ -30,6 +30,7 @@ $lang['File'] = '파일';
$lang['Files'] = '파일'; $lang['Files'] = '파일';
$lang['First'] = '처음'; $lang['First'] = '처음';
$lang['Folder'] = '폴더'; $lang['Folder'] = '폴더';
$lang['Full Difference'] = '전체차이';
$lang['Head revision'] = '최신리비전'; $lang['Head revision'] = '최신리비전';
$lang['Hide details'] = '상세내역숨김'; $lang['Hide details'] = '상세내역숨김';
$lang['History'] = '변경기록'; $lang['History'] = '변경기록';

View File

@ -278,14 +278,20 @@ class SubversionModel extends Model
return $fileinfo; return $fileinfo;
} }
function _get_diff ($diff, $all, $ent) function _get_diff ($diff, $src1, $src2, $all, $ent)
{ {
/* copied from websvn */ /* copied from websvn */
if ($all) if ($all)
{ {
$ofile = fopen ($oldtname, "r"); //$ofile = fopen ($oldtname, "r");
$nfile = fopen ($newtname, "r"); //$nfile = fopen ($newtname, "r");
$ofile = fopen("php://memory", 'r+');
$nfile = fopen("php://memory", 'r+');
fputs($ofile, $src1);
fputs($nfile, $src2);
rewind($ofile);
rewind($nfile);
} }
// Ignore the 4 header lines // Ignore the 4 header lines
@ -398,15 +404,15 @@ class SubversionModel extends Model
$listing[$index]["rev1diffclass"] = "diffdeleted"; $listing[$index]["rev1diffclass"] = "diffdeleted";
$listing[$index]["rev2diffclass"] = "diff"; $listing[$index]["rev2diffclass"] = "diff";
$listing[$index]["rev1line"] = $text;
//$listing[$index]["rev2line"] = " ";
$listing[$index]["rev2line"] = '';
if ($all) { if ($all) {
fgets($ofile); fgets($ofile);
$curoline++; $curoline++;
} }
$listing[$index]["rev1line"] = $text;
//$listing[$index]["rev2line"] = " ";
$listing[$index]["rev2line"] = '';
break; break;
case "+": case "+":
@ -429,23 +435,29 @@ class SubversionModel extends Model
$listing[$i]["rev2diffclass"] = "diffchanged"; $listing[$i]["rev2diffclass"] = "diffchanged";
$listing[$i]["rev2line"] = $text; $listing[$i]["rev2line"] = $text;
if ($all) { if ($all)
{
fgets($nfile); fgets($nfile);
$curnline++; $curnline++;
} }
// Don't increment the current index count // Don't increment the current index count
$index--; $index--;
} else { }
else
{
$listing[$index]["rev1diffclass"] = "diff"; $listing[$index]["rev1diffclass"] = "diff";
$listing[$index]["rev2diffclass"] = "diffadded"; $listing[$index]["rev2diffclass"] = "diffadded";
//$listing[$index]["rev1line"] = " "; //$listing[$index]["rev1line"] = " ";
$listing[$index]["rev1line"] = ''; $listing[$index]["rev1line"] = '';
$listing[$index]["rev2line"] = $text; $listing[$index]["rev2line"] = $text;
if ($all) { if ($all)
{
fgets($nfile); fgets($nfile);
$curnline++; $curnline++;
} }
@ -459,7 +471,8 @@ class SubversionModel extends Model
$listing[$index]["rev1line"] = $text; $listing[$index]["rev1line"] = $text;
$listing[$index]["rev2line"] = $text; $listing[$index]["rev2line"] = $text;
if ($all) { if ($all)
{
fgets($ofile); fgets($ofile);
fgets($nfile); fgets($nfile);
$curoline++; $curoline++;
@ -479,13 +492,18 @@ class SubversionModel extends Model
// Output the rest of the files // Output the rest of the files
if ($all) if ($all)
{ {
while (!feof($ofile) || !feof($nfile)) while (1)
{ {
if (feof($ofile) && feof($nfile)) break;
$listing[$index]["rev1diffclass"] = "diff"; $listing[$index]["rev1diffclass"] = "diff";
$listing[$index]["rev2diffclass"] = "diff"; $listing[$index]["rev2diffclass"] = "diff";
$line = rtrim(fgets($ofile)); if (!feof($ofile))
if ($ent) $line = replaceEntities($line, $rep); {
$line = rtrim(fgets($ofile));
if ($ent) $line = replaceEntities($line, $rep);
}
if (!feof($ofile)) { if (!feof($ofile)) {
//$listing[$index]["rev1line"] = hardspace($line); //$listing[$index]["rev1line"] = hardspace($line);
@ -495,9 +513,13 @@ class SubversionModel extends Model
//$listing[$index]["rev1line"] = " "; //$listing[$index]["rev1line"] = " ";
$listing[$index]["rev1line"] = ''; $listing[$index]["rev1line"] = '';
} }
$line = rtrim(fgets($nfile)); if (!feof($nfile))
if ($ent) $line = replaceEntities(rtrim(fgets($nfile)), $rep); {
$line = rtrim(fgets($nfile));
if ($ent) $line = replaceEntities(rtrim(fgets($nfile)), $rep);
}
if (!feof($nfile)) { if (!feof($nfile)) {
//$listing[$index]["rev2line"] = hardspace($line); //$listing[$index]["rev2line"] = hardspace($line);
@ -528,7 +550,7 @@ class SubversionModel extends Model
// $rev1 - new revision number // $rev1 - new revision number
// $rev2 - old revision number // $rev2 - old revision number
// //
function getDiff ($projectid, $path, $rev1, $rev2) function getDiff ($projectid, $path, $rev1, $rev2, $full = FALSE)
{ {
//$url = 'file:///'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"; //$url = 'file:///'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}";
$orgurl = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"); $orgurl = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}");
@ -621,7 +643,16 @@ class SubversionModel extends Model
fclose($errors); fclose($errors);
$fileinfo['content'] = $this->_get_diff ($diff, FALSE, FALSE); if ($full)
{
$src1 = @svn_cat ($info2[0]['url'], $info2[0]['revision']);
$src2 = @svn_cat ($info1[0]['url'], $info1[0]['revision']);
$fileinfo['content'] = $this->_get_diff ($diff, $src1, $src2, TRUE, FALSE);
}
else
{
$fileinfo['content'] = $this->_get_diff ($diff, '', '', FALSE, FALSE);
}
fclose ($diff); fclose ($diff);
return $fileinfo; return $fileinfo;

View File

@ -219,6 +219,10 @@ $history = $file['history'];
print anchor ("code/diff/{$project->id}/{$xpar}/{$history['rev']}", $this->lang->line('Difference')); print anchor ("code/diff/{$project->id}/{$xpar}/{$history['rev']}", $this->lang->line('Difference'));
print '</td>'; print '</td>';
print '<td>';
print anchor ("code/fulldiff/{$project->id}/{$xpar}/{$history['rev']}", $this->lang->line('Full Difference'));
print '</td>';
print '</tr>'; print '</tr>';
} }
?> ?>