<?php
/* CONFIG */
-$repo_path = "/srv/gitosis/repositories/";
-$project_list = "/srv/gitosis/gitosis/projects.list";
+$repo_path = "/home/git/";
+$project_list = null;
$size = 20;
+$header_height = false; //false = dynamic
$tile_size = 20; /* do not edit */
$max_branches = 30;
+$use_local_branches = true;
+$use_remote_branches = true;
$colors = array(
NULL,
array(255, 0, 0),
- array(0, 255, 0),
+ array(array(0, 255, 0), array(0, 192, 0)),
array(0, 0, 255),
array(128, 128, 128),
array(128, 128, 0),
$data['branches'] = array();
$data['ubranches'] = array();
$brach_id = 1;
-$brach_uid = 1;
+$branch_uid = 1;
$graph_commit = NULL;
$first_commit = true;
$head_list = shell_exec($cmd);
$head = parse_commit($head_list);
$first_commit = false;
- $data['branches'][0] = array();
- $branch = &$data['branches'][0];
+ $data['branches'][count($data['branches'])] = array();
+ $branch = &$data['branches'][count($data['branches'])-1];
$branch['id'] = $brach_id++;
$branch['uid'] = $branch_uid++;
$branch['active'] = true;
+ $branch['sticky'] = true;
$branch['next'] = $head['id'];
+ unset($branch);
+ if($use_local_branches) {
+ $cmd = "git --git-dir=".$repo_path.$project." for-each-ref --sort=-committerdate refs/heads/";
+ $head_list = shell_exec($cmd);
+ foreach(explode("\n", str_replace("\r", "", $head_list)) as $head) {
+ $head = explode(" ", $head);
+ $name = explode("/", $head[1]);
+ $name = $name[count($name)-1];
+ if(!$head[0])
+ continue;
+ $existing = false;
+ foreach($data['branches'] as &$branch) {
+ if($branch['next'] == $head[0]) {
+ $existing = true;
+ $branch['name'][] = $name;
+ break;
+ }
+ }
+ unset($branch);
+ if($existing)
+ continue;
+ $data['branches'][count($data['branches'])] = array(
+ "id" => $brach_id++,
+ "uid" => $branch_uid++,
+ "active" => true,
+ "sticky" => true,
+ "name" => array($name),
+ "next" => $head[0]
+ );
+ }
+ }
+ if($use_remote_branches) {
+ $cmd = "git --git-dir=".$repo_path.$project." for-each-ref --sort=-committerdate refs/remotes/";
+ $head_list = shell_exec($cmd);
+ foreach(explode("\n", str_replace("\r", "", $head_list)) as $head) {
+ $head = explode(" ", $head);
+ $name = explode("/", $head[1]);
+ $name = $name[count($name)-2];
+ if(!$head[0])
+ continue;
+ $existing = false;
+ foreach($data['branches'] as &$branch) {
+ if($branch['next'] == $head[0]) {
+ $existing = true;
+ $branch['name'][] = $name;
+ break;
+ }
+ }
+ unset($branch);
+ if($existing)
+ continue;
+ $data['branches'][count($data['branches'])] = array(
+ "id" => $brach_id++,
+ "uid" => $branch_uid++,
+ "active" => true,
+ "sticky" => true,
+ "name" => array($name),
+ "next" => $head[0]
+ );
+ }
+ }
+}
+
+if($_GET['c'] == "header") {
+ $count = count($data['branches']);
+ if($count > $max_branches)
+ $count = $max_branches;
+ if(!$header_height) {
+ $maxlen = 0;
+ foreach($data['branches'] as $branch) {
+ if($branch['sticky'] && count($branch['name'])) {
+ if(strlen($branch['name'][0]) > $maxlen)
+ $maxlen = strlen($branch['name'][0]);
+ }
+ }
+ $header_height = $maxlen * 2 + 15;
+ }
+ $image = imagecreatetruecolor($count * $size + 60, $header_height);
+ $transparentIndex = imagecolorallocate($image, 217, 216, 209);
+ imagefill($image, 0, 0, $transparentIndex);
+ $branches = 0;
+ foreach($data['branches'] as $branch) {
+ if($branch['sticky'] && count($branch['name'])) {
+ $branches++;
+ $color = get_color($branch['id'], true);
+ $color = imagecolorallocatealpha($image, $color[0], $color[1], $color[2], 0);
+ imagettftext($image, 8, 28, ($branch['id']-1) * $size + 10, $header_height-2, $color, $_SERVER['DOCUMENT_ROOT']."/arial.ttf", $branch['name'][0]);
+ }
+ }
+ if(!$branches) die();
+ imagecolortransparent($image, $transparentIndex);
+ header('Content-Type: image/png');
+ imagepng($image);
+ imagedestroy($image);
+ die();
}
for($i = 0; $i <= intval($_GET['to']); $i++) {
}
}
-if($graph_commit == NULL)
- die("ERROR 0x07");
-
//DEV Breakpoint
//print_r($data);
//die();
//generate image
+
+if($graph_commit == NULL)
+ die("ERROR 0x07");
+
$count = count($data['branches']);
if($count > $max_branches)
$count = $max_branches;
imagecopyresampled($image, $image2, $left, 0, 0, 0, $size, $size, $tile_size, $tile_size);
}
-function get_color($id) {
+function get_color($id, $text = false) {
global $colors, $graph_commit, $data;
if($graph_commit['branches'][($id-1)]['pre_merge']) {
$branch = $data['ubranches'][$graph_commit['branches'][($id-1)]['uid']];
if($branch['pre_merge'] && $branch['pre_merge_start'])
$id = $branch['pre_merge_id'];
}
- return $colors[($id - 1) % count($colors)];
+ $color_array = $colors[($id - 1) % count($colors)];
+ if($text && is_array($color_array[0]) && $color_array[1])
+ return $color_array[1];
+ return (is_array($color_array[0]) ? $color_array[0] : $color_array);
}
foreach($graph_commit['branches'] as $branch) {