finished commitdiff page
authorpk910 <philipp@zoelle1.de>
Sat, 16 Feb 2013 09:09:20 +0000 (10:09 +0100)
committerpk910 <philipp@zoelle1.de>
Sat, 16 Feb 2013 09:09:20 +0000 (10:09 +0100)
htdocs/lib/PageClasses.diff.class.php
htdocs/lib/Tools.class.php
htdocs/templates/default/commitdiff.tpl

index ff53a204309974653e8bc4927f7359564c68556d..f02fb4607dcd2314be163ddddd97bae5a5628261 100644 (file)
@@ -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', '');
index c0b01b0cd15b406e931145b479073f44b3b0589b..7e02c68e90406d60be7dabbd829e66de8a17ec59 100644 (file)
@@ -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
index 398aa0c304ace115b6ddacd1f7d5dc71656cd153..ec42c02d3a646ee6eddb4732f62b4c44fbedf541 100644 (file)
@@ -73,3 +73,9 @@
 
 # [patch_diffline]
 <div class="diff%class%">%line%</div>
+
+# [patch_nopatch_merge]
+<div class="diff nodifferences">Trivial merge</div>
+
+# [patch_nopatch_simple]
+<div class="diff nodifferences">No differences found</div>