source_compare

git-svn-id: http://xe-core.googlecode.com/svn/sandbox@5956 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
haneul 2009-03-24 10:05:41 +00:00
parent 9b4a5489d0
commit 0919ae7e03
3 changed files with 100 additions and 62 deletions

View file

@ -195,6 +195,75 @@
return $output; return $output;
} }
function parseComp(&$list)
{
$cnt = count($list);
$output = array();
$obj = null;
$idx = 0;
for($i=0;$i<$cnt;$i++) {
$str = $list[$i];
if(preg_match('/^Index: (.*)$/', $str, $m)) {
if($blockobj != null)
{
$obj->blocks[$blockobj->before_line_start] = $blockobj;
ksort($obj->blocks);
}
if($obj!==null) $output[] = $obj;
$obj = null;
$obj->filename = $m[1];
$idx = 0;
$obj->blocks = array();
continue;
}
if(preg_match('/^(\=+)$/',$str)) continue;
if(preg_match('/^--- ([^\(]+)\(revision ([0-9]+)\)$/i',$str,$m)) {
$obj->before_revision = $m[2];
continue;
}
if(preg_match('/^\+\+\+ ([^\(]+)\(revision ([0-9]+)\)$/i',$str,$m)) {
$obj->after_revision = $m[2];
continue;
}
if(preg_match('/^@@ \-([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@$/', $str, $m)) {
if($blockobj != null) $obj->blocks[$blockobj->before_line_start] = $blockobj;
$blockobj = null;
$blockobj->before_line_start = (int) $m[1];
$blockobj->after_line_start = (int) $m[3];
$cur_before_line = $blockobj->before_line_start;
$cur_after_line = $blockobj->after_line_start;
$blockobj->lines = array();
continue;
}
$line = null;
if(preg_match('/^\-(.*)$/i',$str)) {
$line->data = ' '.substr($str,1);
$line->type = "deleted";
$line->before_line_number = $cur_before_line ++;
}
else if(preg_match('/^\+(.*)$/i',$str)) {
$line->data = ' '.substr($str,1);
$line->type = "added";
$line->after_line_number = $cur_after_line ++;
}
else
{
$line->data = $str;
$line->before_line_number = $cur_before_line ++;
$line->after_line_number = $cur_after_line ++;
}
$blockobj->lines[] = $line;
}
if($obj!==null)
{
if($blockobj != null) $obj->blocks[$blockobj->before_line_start] = $blockobj;
ksort($obj->blocks);
$output[] = $obj;
}
return $output;
}
function getComp($path, $brev, $erev) { function getComp($path, $brev, $erev) {
if(!$brev) { if(!$brev) {
$command = sprintf('%s --non-interactive %s --config-dir %s log --xml --limit 2 %s%s@%d', $this->svn_cmd, $this->_getAuthInfo(), $this->tmp_dir, $this->url, $path, $erev); $command = sprintf('%s --non-interactive %s --config-dir %s log --xml --limit 2 %s%s@%d', $this->svn_cmd, $this->_getAuthInfo(), $this->tmp_dir, $this->url, $path, $erev);
@ -216,52 +285,10 @@
$erev $erev
); );
$output = $this->execCmd($command, $error); $output = $this->execCmd($command, $error);
debugPrint($output);
$list = explode("\n",$output); $list = explode("\n",$output);
$cnt = count($list); $output = $this->parseComp($list);
$output = array();
$obj = null;
$idx = 0;
for($i=0;$i<$cnt;$i++) {
$str = $list[$i];
if(preg_match('/^Index: (.*)$/', $str, $m)) {
if($obj!==null) $output[] = $obj;
$obj = null;
$obj->filename = $m[1];
$idx = 0;
$code_idx = -1;
$code_changed = false;
continue;
}
if(preg_match('/^(\=+)$/',$str)) continue;
if(preg_match('/^--- ([^\(]+)\(revision ([0-9]+)\)$/i',$str,$m)) {
$obj->before_revision = $m[2];
continue;
}
if(preg_match('/^\+\+\+ ([^\(]+)\(revision ([0-9]+)\)$/i',$str,$m)) {
$obj->after_revision = $m[2];
continue;
}
if(preg_match('/^@@ \-([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@$/', $str, $m)) {
$obj->changed[$idx]->before_line = sprintf('%d ~ %d', $m[1], $m[2]);
$obj->changed[$idx]->after_line = sprintf('%d ~ %d', $m[3], $m[4]);
continue;
}
if(preg_match('/^\-(.*)$/i',$str)) {
if(!$code_changed) {
$code_changed = true;
$code_idx++;
}
$obj->changed[$idx]->before_code[$code_idx] .= substr($str,1)."\n";
continue;
}
if(preg_match('/^\+(.*)$/i',$str)) {
$obj->changed[$idx]->after_code[$code_idx] .= substr($str,1)."\n";
$code_changed = false;
continue;
}
}
if($obj!==null) $output[] = $obj;
return $output; return $output;
} }

View file

@ -296,3 +296,6 @@ dt span.closed { text-decoration: line-through; }
.extraVarForm ul { margin:0; padding:0; list-style:none; } .extraVarForm ul { margin:0; padding:0; list-style:none; }
.extraVarForm .date { border:1px solid; border-color:#a6a6a6 #d8d8d8 #d8d8d8 #a6a6a6; padding:3px; margin-right:10px; width:100px; } .extraVarForm .date { border:1px solid; border-color:#a6a6a6 #d8d8d8 #d8d8d8 #a6a6a6; padding:3px; margin-right:10px; width:100px; }
.extraVarForm .address { border:1px solid; border-color:#a6a6a6 #d8d8d8 #d8d8d8 #a6a6a6; padding:3px; margin-right:10px; width:300px; } .extraVarForm .address { border:1px solid; border-color:#a6a6a6 #d8d8d8 #d8d8d8 #a6a6a6; padding:3px; margin-right:10px; width:300px; }
.diff .deleted { background: #FFDDDD none; }
.diff .added { background: #DDFFDD none; }

View file

@ -10,30 +10,38 @@
<!--@if($comp)--> <!--@if($comp)-->
<!--@foreach($comp as $item)--> <!--@foreach($comp as $item)-->
<table> <table>
<col width="*" /> <col width="20" />
<col width="20" />
<col width="*" /> <col width="*" />
<thead> <thead>
<tr> <tr>
<th colspan="2" class="filename">{$item->filename}</th> <th colspan="3" class="filename">{$item->filename}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody class="diff">
<tr class="revision"> <tr class="revision">
<td class="before">Rev. {$item->before_revision}</td> <td class="before">{$item->before_revision}</td>
<td class="after">Rev. {$item->after_revision}</td> <td class="after">{$item->after_revision}</td>
<td></td>
</tr> </tr>
<!--@foreach($item->changed as $change)--> {@ $bStart = true }
<tr class="line"> <!--@foreach($item->blocks as $block)-->
<td class="before">line {$change->before_line}</td> <!--@if(!$bStart)-->
<td class="after">line {$change->after_line}</td> <tr>
</tr> <td>...</td>
<!--@for($i=0;$i<count($change->before_code);$i++)--> <td>...</td>
<tr class="code"> <td></td>
<td>{nl2br(str_replace(' ','&nbsp;&nbsp;',htmlspecialchars($change->before_code[$i])))}</td> </tr>
<td>{nl2br(str_replace(' ','&nbsp;&nbsp;',htmlspecialchars($change->after_code[$i])))}</td> <!--@endif-->
</tr> <!--@foreach($block->lines as $line)-->
<!--@end--> <tr>
<!--@end--> <td>{$line->before_line_number}</td>
<td>{$line->after_line_number}</td>
<td <!--@if($line->type)-->class="{$line->type}"<!--@endif--> >{nl2br(str_replace("\t","&nbsp;&nbsp;&nbsp;&nbsp;",str_replace(' ','&nbsp;',htmlspecialchars($line->data))))}</td>
</tr>
<!--@endforeach-->
{@ $bStart = false }
<!--@endforeach-->
</tbody> </tbody>
</table> </table>
<!--@end--> <!--@end-->