finished commitdiff page
[phpgitweb.git] / htdocs / lib / PageClasses.diff.class.php
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', '');