From 07f0862d6ef4a14a812381a30931a46a51dbc87d Mon Sep 17 00:00:00 2001 From: pk910 Date: Sat, 16 Feb 2013 10:09:20 +0100 Subject: [PATCH] finished commitdiff page --- htdocs/lib/PageClasses.diff.class.php | 42 +++++++++++++++++++++++-- htdocs/lib/Tools.class.php | 13 ++++++++ htdocs/templates/default/commitdiff.tpl | 6 ++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/htdocs/lib/PageClasses.diff.class.php b/htdocs/lib/PageClasses.diff.class.php index ff53a20..f02fb46 100644 --- a/htdocs/lib/PageClasses.diff.class.php +++ b/htdocs/lib/PageClasses.diff.class.php @@ -77,6 +77,12 @@ class diff { break; } while(true); } + if($patch_id == 1) { + if(count($commit['parent']) > 1) + $html[] = new ContentProvider('commitdiff', 'patch_nopatch_merge'); + else + $html[] = new ContentProvider('commitdiff', 'patch_nopatch_simple'); + } return $html; } @@ -152,6 +158,37 @@ class diff { return $header; } + private function format_line($line) { + $lineobj = new ContentProvider('commitdiff', 'patch_diffline'); + $class = ""; + if($this->tree['parents'] > 1) { + $prefix = substr($line, 0, $this->tree['parents']); + if(preg_match('/@/', $prefix)) + $class = " chunk_header"; + else if(preg_match('/\\/', $prefix)) + $class = " incomplete"; + else if(preg_match('/+/', $prefix)) + $class = " add"; + else if(preg_match('/-/', $prefix)) + $class = " rem"; + } else { + $prefix = substr($line, 0, 1); + if($prefix == '@') + $class = " chunk_header"; + else if($prefix == '\\') + $class = " incomplete"; + else if($prefix == '+') + $class = " add"; + else if($prefix == '-') + $class = " rem"; + } + $lineobj->set('class', $class); + $line = Tools::replaceTabs($line); + $lineobj->set('line', htmlentities($line)); + + return $lineobj; + } + private function gen_contentprovider($patch_id) { if(!$this->diff) $pageclass = 'patch_nodiff'; @@ -161,6 +198,7 @@ class diff { $pageclass = 'patch_normal'; $page = new ContentProvider('commitdiff', $pageclass); $page->set('diffcmd', $this->gen_diffcmd_header()); + $page->set('patch_id', $patch_id); if(!$this->diff) return $page; $is_header = true; @@ -178,8 +216,8 @@ class diff { continue; } } - $lineobj = new ContentProvider('commitdiff', 'patch_diffline'); - //if(preg_match('', $line)) + $page->append('patch', $this->format_line($line)); + } if($is_header) $page->set('patch', ''); diff --git a/htdocs/lib/Tools.class.php b/htdocs/lib/Tools.class.php index c0b01b0..7e02c68 100644 --- a/htdocs/lib/Tools.class.php +++ b/htdocs/lib/Tools.class.php @@ -128,6 +128,19 @@ class Tools { return $offset; } + public static function replaceTabs($line) { + while(($pos = strpos($line, "\t")) !== false) { + $spacecount = 8 - ($pos % 8); + $i = 1; + while($line[$pos + $i] == "\t") { //maybe a little bit faster ;) + $i++; + $spacecount += 8; + } + $line = substr($line, 0, $pos).str_repeat(' ', $spacecount).substr($line, $pos + $i); + } + return $line; + } + } ?> \ No newline at end of file diff --git a/htdocs/templates/default/commitdiff.tpl b/htdocs/templates/default/commitdiff.tpl index 398aa0c..ec42c02 100644 --- a/htdocs/templates/default/commitdiff.tpl +++ b/htdocs/templates/default/commitdiff.tpl @@ -73,3 +73,9 @@ # [patch_diffline]
%line%
+ +# [patch_nopatch_merge] +
Trivial merge
+ +# [patch_nopatch_simple] +
No differences found
-- 2.20.1