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;
}
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';
$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;
continue;
}
}
- $lineobj = new ContentProvider('commitdiff', 'patch_diffline');
- //if(preg_match('', $line))
+ $page->append('patch', $this->format_line($line));
+
}
if($is_header)
$page->set('patch', '');
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