private $max_branches, $brach_id = 1, $branch_id = 1;
public function __construct() {
- $this->max_branches = 10;
+ $this->max_branches = GitConfig::GITGRAPH_MAX_BRANCHES;
$this->data['branches'] = array();
$this->data['ubranches'] = array();
}
}
public function parse($commits) {
+ if(!GitConfig::GITGRAPH_ENABLE)
+ return;
$brach_id = $this->brach_id;
$branch_uid = $this->branch_id;
$first_commit = (count($this->data['branches']) == 0 ? true : false);
for($j = 1; $j < count($commit['parent']); $j++) {
$add = true;
foreach($this->data['branches'] as $cbranch) {
- if($cbranch['next'] == $commit['parent'][$j]) {
+ if(array_key_exists('next', $cbranch) && $cbranch['next'] == $commit['parent'][$j]) {
$add = false;
break;
}
}
public function get_graph($id) {
+ if(!GitConfig::GITGRAPH_ENABLE)
+ return;
$graph = $this->graph[$id];
$data = $graph['d']['p'].$graph['d']['type'].count($this->data['branches']).'('.implode(',', $graph['l']).')';
$first_merge = true;
}
$graph['cs'] = array();
foreach($graph['br'] as $buid) {
+ if(!$buid) continue;
$branch = $this->data['ubranches'][$buid];
- if($branch['pre_merge'] && $branch['pre_merge_start'])
+ if($branch['pre_merge'] && array_key_exists('pre_merge_start', $branch) && $branch['pre_merge_start'])
$graph['cs'][] = $branch['id']."=".$branch['pre_merge_id'];
}
if(count($graph['cs'])) {
$data .= '('.implode(',', $graph['cs']).')';
}
+ if(GitConfig::GITGRAPH_BASE64)
+ $data = base64_encode($data);
return $data;
}
+ public function get_header_graph() {
+ $data = "head:";
+ $branchcount = 0;
+ $dataadd = "";
+ foreach($this->data['branches'] as $branch) {
+ if(array_key_exists('sticky', $branch) && $branch['sticky']) {
+ $name = explode('/', $branch['name'][0], 3);
+ $dataadd .= "\n".$branch['id'].":".$name[2];
+ $branchcount++;
+ }
+ }
+ $data.=$branchcount.$dataadd;
+ if(GitConfig::GITGRAPH_BASE64)
+ $data = base64_encode($data);
+ return $data;
+ }
}
class graph_image_generator {
- private $max_branches = 10;
+ private $max_branches;
private $image;
- private $size = 20;
- private $tile_size = 20;
+ private $size;
+ private $tile_size;
+ private $header_height = false;
private $colors, $color_swap = array();
- public function generate($data) {
- $data = $this->parse_data($data);
- if(!$data)
- return;
+ public function __construct() {
+ $this->max_branches = GitConfig::GITGRAPH_MAX_BRANCHES;
+ $this->size = GitConfig::GITGRAPH_END_SIZE;
+ $this->tile_size = GitConfig::GITGRAPH_TILE_SIZE;
$this->colors = array(
NULL,
array(0, 128, 128),
array(128, 0, 128)
);
+ }
+
+ public function generate($data) {
+ if(!GitConfig::GITGRAPH_ENABLE)
+ return;
+ $data = $this->parse_data($data);
+ if(!$data)
+ return;
$count = $data['count'];
if($count > $this->max_branches)
imagedestroy($this->image);
}
+ private function display_header($header) {
+ $header = explode("\n",$header);
+ $count = $header[0];
+ $header = array_slice($header, 1);
+ if($count > $this->max_branches)
+ $count = $this->max_branches;
+ if(!$this->header_height) {
+ $maxlen = 0;
+ foreach($header as $head) {
+ $head = explode(":", $head, 2);
+ $name = $head[1];
+ if(strlen($name) > $maxlen)
+ $maxlen = strlen($name);
+ }
+ $this->header_height = $maxlen * 2 + 15;
+ }
+ $image = imagecreatetruecolor($count * $this->size + 60, $this->header_height);
+ $transparentIndex = imagecolorallocate($image, 217, 216, 209);
+ imagefill($image, 0, 0, $transparentIndex);
+ $branches = 0;
+ foreach($header as $head) {
+ $head = explode(":", $head, 2);
+ $color = $this->get_color($head[0], true);
+ $name = $head[1];
+ $branches++;
+ $color = imagecolorallocatealpha($image, $color[0], $color[1], $color[2], 0);
+ imagettftext($image, 8, 28, ($head[0]-1) * $this->size + 10, $this->header_height-2, $color, realpath(dirname(__FILE__)."/../")."/res/arial.ttf", $name);
+ }
+ if(!$branches) die();
+ imagecolortransparent($image, $transparentIndex);
+ header('Content-Type: image/png');
+ imagepng($image);
+ imagedestroy($image);
+ }
+
private function parse_data($data) {
- //$data = array();
- if(!preg_match("/^([0-9]+)([abc]{1})([0-9]+)\(([^\)]*)\)([a-z0-9,\|]*)(\(([^\)]*)\)|)/i", $data, $matches))
+ if(GitConfig::GITGRAPH_BASE64)
+ $data = base64_decode($data);
+ if(!preg_match("/^([0-9]+)([abc]{1})([0-9]+)\(([^\)]*)\)([a-z0-9,\|]*)(\(([^\)]*)\)|)/i", $data, $matches)) {
+ if(preg_match("/head:(.*)/i", $data, $matches)) {
+ $this->display_header(substr($data, strlen("head:")));
+ }
return null;
+ }
$data = array();
$data['dot'] = array();
private function apply_data($data) {
foreach($data['l'] as $l)
- $this->overlay_image("img/line.png", ($l-1) * $this->size, $this->get_color($l));
+ $this->overlay_image("res/line.png", ($l-1) * $this->size, $this->get_color($l));
foreach($data['m'] as $m) {
if($m['dd'] == 'r')
- $this->overlay_image("img/dot_merge_right.png", ($data['dot']['pos'] - 1) * $this->size, $this->get_color($m['pos']));
+ $this->overlay_image("res/dot_merge_right.png", ($data['dot']['pos'] - 1) * $this->size, $this->get_color($m['pos']));
else if($m['dd'] == 'l')
- $this->overlay_image("img/dot_merge_left.png", ($data['dot']['pos'] - 1) * $this->size, $this->get_color($m['pos']));
+ $this->overlay_image("res/dot_merge_left.png", ($data['dot']['pos'] - 1) * $this->size, $this->get_color($m['pos']));
if($m['md'] == 'r')
- $this->overlay_image("img/".(($m['ml'] & 1) ? "branch" : "merge")."_right.png", ($m['pos'] - 1) * $this->size, $this->get_color($m['pos']));
+ $this->overlay_image("res/".(($m['ml'] & 1) ? "branch" : "merge")."_right.png", ($m['pos'] - 1) * $this->size, $this->get_color($m['pos']));
else if($m['md'] == 'l')
- $this->overlay_image("img/".(($m['ml'] & 1) ? "branch" : "merge")."_left.png", ($m['pos'] - 1) * $this->size, $this->get_color($m['pos']));
+ $this->overlay_image("res/".(($m['ml'] & 1) ? "branch" : "merge")."_left.png", ($m['pos'] - 1) * $this->size, $this->get_color($m['pos']));
if($m['ml'] == 0)
- $this->overlay_image("img/line.png", ($m['pos'] - 1) * $this->size, $this->get_color($m['pos']));
+ $this->overlay_image("res/line.png", ($m['pos'] - 1) * $this->size, $this->get_color($m['pos']));
foreach($m['hl'] as $hl) {
- $this->overlay_image("img/line_h.png", ($hl - 1) * $this->size, $this->get_color($m['pos']));
+ $this->overlay_image("res/line_h.png", ($hl - 1) * $this->size, $this->get_color($m['pos']));
}
}
if($data['dot']['type'] == 'a')
- $this->overlay_image("img/dot.png", ($data['dot']['pos'] - 1) * $this->size, $this->get_color($data['dot']['pos']));
+ $this->overlay_image("res/dot.png", ($data['dot']['pos'] - 1) * $this->size, $this->get_color($data['dot']['pos']));
else if($data['dot']['type'] == 'b')
- $this->overlay_image("img/dot_merge.png", ($data['dot']['pos'] - 1) * $this->size, $this->get_color($data['dot']['pos']));
+ $this->overlay_image("res/dot_merge.png", ($data['dot']['pos'] - 1) * $this->size, $this->get_color($data['dot']['pos']));
else if($data['dot']['type'] == 'c')
- $this->overlay_image("img/dot_init.png", ($data['dot']['pos'] - 1) * $this->size, $this->get_color($data['dot']['pos']));
+ $this->overlay_image("res/dot_init.png", ($data['dot']['pos'] - 1) * $this->size, $this->get_color($data['dot']['pos']));
}
class shortlog {
private $project;
private $graph_data;
+ private $first_commit;
public function generate_shortlog($project, $head, $max, $skip, $file = null, $pages = true, $next_page = 0) {
$this->project = $project;
$content = new ContentProvider('shortlog', 'shortlog');
- $commits = GitCommand::get_commits($project['path'], $head, $max+$skip+1, 0, $file);
- $this->graph_data = new graph_data_generator();
- if($head == null) {
- //add all refs to the graph
- foreach($this->project['refs'] as $ref => $rhash) {
- if(preg_match('#^refs/heads/#i', $ref) && preg_match('/^[a-f0-9]*$/i', $rhash)) {
- $this->graph_data->add_branch($rhash, $ref);
+ if(GitConfig::GITGRAPH_ENABLE) {
+ if($max+$skip >= 2000) { //only load the last 2k commits
+ $real_skip = ($max+$skip) - 2000;
+ $skip -= $real_skip;
+ } else
+ $real_skip = 0;
+ } else {
+ $real_skip = $skip;
+ $skip = 0;
+ }
+
+ $commits = GitCommand::get_commits($project['path'], $head, $max+$skip+1, $real_skip, $file);
+
+ if(GitConfig::GITGRAPH_ENABLE) {
+ $this->graph_data = new graph_data_generator();
+ if($head == null) {
+ //add all refs to the graph
+ foreach($this->project['refs'] as $ref => $rhash) {
+ if(preg_match('#^refs/heads/#i', $ref) && preg_match('/^[a-f0-9]*$/i', $rhash)) {
+ $this->graph_data->add_branch($rhash, $ref);
+ }
}
- }
- foreach($this->project['refs'] as $ref => $rhash) {
- if(preg_match('#^refs/remotes/#i', $ref) && preg_match('/^[a-f0-9]*$/i', $rhash)) {
- $this->graph_data->add_branch($rhash, $ref);
+ foreach($this->project['refs'] as $ref => $rhash) {
+ if(preg_match('#^refs/remotes/#i', $ref) && preg_match('/^[a-f0-9]*$/i', $rhash)) {
+ $this->graph_data->add_branch($rhash, $ref);
+ }
}
}
+ $this->graph_data->parse($commits);
+ $content->set('graph_data', $this->graph_data->get_header_graph());
}
- $this->graph_data->parse($commits);
$commit_counter = 0;
+ $this->first_commit = $commits[0];
foreach($commits as $commit) {
$commit_counter++;
if($commit_counter < $skip)
return $content;
}
+ public function get_first_commit() {
+ return $this->first_commit;
+ }
+
private function shortlog_entry($class, $commit) {
$entry = new ContentProvider('shortlog', 'shortlog_entry');
$entry->set('class', $class);
$entry->set('date', $date_str);
$entry->set('age', $age_str);
}
- $entry->set('graph_data', $this->graph_data->get_graph($commit['id']));
+ if(GitConfig::GITGRAPH_ENABLE)
+ $entry->set('graph_data', $this->graph_data->get_graph($commit['id']));
$entry->set('refs', $this->shortlog_commit_refs($commit['id']));
if(!$this->project)
return;
$project['refs'] = $phpgitweb->get_project_loader()->getProjectRefs($project);
+ $phpgitweb->append_header_nav("shortlog", null, true);
+
$this->page = new ContentProvider('shortlog', 'main');
//pages