From 0919ae7e03ab40813f2da91838a6fd2e1de52899 Mon Sep 17 00:00:00 2001 From: haneul Date: Tue, 24 Mar 2009 10:05:41 +0000 Subject: [PATCH] source_compare git-svn-id: http://xe-core.googlecode.com/svn/sandbox@5956 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- modules/issuetracker/classes/svn.class.php | 117 +++++++++++------- .../skins/xe_issuetracker/css/common.css | 3 + .../skins/xe_issuetracker/source_compare.html | 42 ++++--- 3 files changed, 100 insertions(+), 62 deletions(-) diff --git a/modules/issuetracker/classes/svn.class.php b/modules/issuetracker/classes/svn.class.php index 4952f74de..59df8b2d6 100644 --- a/modules/issuetracker/classes/svn.class.php +++ b/modules/issuetracker/classes/svn.class.php @@ -195,6 +195,75 @@ 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) { 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); @@ -216,52 +285,10 @@ $erev ); $output = $this->execCmd($command, $error); - + debugPrint($output); $list = explode("\n",$output); - $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($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; + $output = $this->parseComp($list); + return $output; } diff --git a/modules/issuetracker/skins/xe_issuetracker/css/common.css b/modules/issuetracker/skins/xe_issuetracker/css/common.css index 49e646fa0..09e972f26 100644 --- a/modules/issuetracker/skins/xe_issuetracker/css/common.css +++ b/modules/issuetracker/skins/xe_issuetracker/css/common.css @@ -296,3 +296,6 @@ dt span.closed { text-decoration: line-through; } .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 .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; } diff --git a/modules/issuetracker/skins/xe_issuetracker/source_compare.html b/modules/issuetracker/skins/xe_issuetracker/source_compare.html index 45fb273b7..cc909740c 100644 --- a/modules/issuetracker/skins/xe_issuetracker/source_compare.html +++ b/modules/issuetracker/skins/xe_issuetracker/source_compare.html @@ -10,30 +10,38 @@ -++ - + - + - - + + + - - - - - - - - - - - - +{@ $bStart = true } + + + + + + + + + + + + + + + + {@ $bStart = false } +
{$item->filename}{$item->filename}
Rev. {$item->before_revision}Rev. {$item->after_revision}{$item->before_revision}{$item->after_revision}
line {$change->before_line}line {$change->after_line}
{nl2br(str_replace(' ','  ',htmlspecialchars($change->before_code[$i])))}{nl2br(str_replace(' ','  ',htmlspecialchars($change->after_code[$i])))}
......
{$line->before_line_number}{$line->after_line_number}type)-->class="{$line->type}" >{nl2br(str_replace("\t","    ",str_replace(' ',' ',htmlspecialchars($line->data))))}