added possibility to show "official branches" up to the first commit
authorpk910 <philipp@zoelle1.de>
Fri, 7 Sep 2012 05:55:51 +0000 (07:55 +0200)
committerpk910 <philipp@zoelle1.de>
Fri, 7 Sep 2012 05:55:51 +0000 (07:55 +0200)
git_graph.php

index 006b8a3226661597597ff17ef21cee43822906cf..ce55b1e7789f3f44f7605a388d3a1f34d6430961 100644 (file)
@@ -8,6 +8,8 @@ $size = 20;
 $tile_size = 20; /* do not edit */
 
 $max_branches = 30;
+$use_local_branches = true;
+$use_remote_branches = true;
 
 $colors = array(
     NULL,
@@ -131,12 +133,61 @@ if($_GET['h'] == "all") {
     $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['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);
+            if(!$head[0])
+                continue;
+            $existing = false;
+            foreach($data['branches'] as $branch) {
+                if($branch['next'] == $head[0]) {
+                    $existing = true;
+                    break;
+                }
+            }
+            if($existing)
+                continue;
+            $data['branches'][count($data['branches'])] = array(
+                "id" => $brach_id++,
+                "uid" => $brach_uid++,
+                "active" => true,
+                "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);
+            if(!$head[0])
+                continue;
+            $existing = false;
+            foreach($data['branches'] as $branch) {
+                if($branch['next'] == $head[0]) {
+                    $existing = true;
+                    break;
+                }
+            }
+            if($existing)
+                continue;
+            $data['branches'][count($data['branches'])] = array(
+                "id" => $brach_id++,
+                "uid" => $brach_uid++,
+                "active" => true,
+                "next" => $head[0]
+            );
+        }
+    }
 }
 
 for($i = 0; $i <= intval($_GET['to']); $i++) {