From 168205aced8d53adb8c5dbe6c5de32499056d9e2 Mon Sep 17 00:00:00 2001 From: pk910 Date: Thu, 6 Sep 2012 13:11:27 +0200 Subject: [PATCH] show all refs in shortlog if no ref is defined --- git_graph.php | 81 +++++++++++++++++++++++++++---------------- patch/gitweb.cgi.diff | 64 +++++++++++++++++++++++++++++++--- 2 files changed, 112 insertions(+), 33 deletions(-) diff --git a/git_graph.php b/git_graph.php index fa8d1bd..006b8a3 100644 --- a/git_graph.php +++ b/git_graph.php @@ -76,37 +76,41 @@ if($_SESSION['git_graph']) { $data = $old_data; } +function parse_commit($commit_data) { + $commit = array(); + $rev_lines = explode("\n", str_replace("\r", "", $commit_data)); + $commit['id'] = $rev_lines[0]; + foreach($rev_lines as $rev_line) { + if(substr($rev_line, 0, 4) == " ") { + if($commit['text']) + $commit['text'] .= "\n"; + $commit['text'] .= substr($rev_line, 4); + } else { + $opt = explode(" ", $rev_line); + if($opt[0] == "tree") + $commit['tree'] = $opt[1]; + else if($opt[0] == "parent") + $commit['parent'][] = $opt[1]; + else if($opt[0] == "author") { + $commit['author'] = $opt[1]; + $commit['author_mail'] = $opt[2]; + $commit['author_time'] = $opt[3]; + } else if($opt[0] == "committer") { + $commit['committer'] = $opt[1]; + $commit['committer_mail'] = $opt[2]; + $commit['committer_time'] = $opt[3]; + } + } + } + return $commit; +} + //load rev-list if(!$data['commits']) { - $cmd = "git --git-dir=".$repo_path.$project." rev-list --header --max-count=".($_GET['to'] + 1)." ".$_GET['h']; + $cmd = "git --git-dir=".$repo_path.$project." rev-list --header --max-count=".($_GET['to'] + 1)." ".($_GET['h'] =="all" ? "--all" : $_GET['h']); $rev_list = shell_exec($cmd); foreach(explode("\000", $rev_list) as $rev) { - $commit = array(); - $rev_lines = explode("\n", str_replace("\r", "", $rev)); - $commit['id'] = $rev_lines[0]; - foreach($rev_lines as $rev_line) { - if(substr($rev_line, 0, 4) == " ") { - if($commit['text']) - $commit['text'] .= "\n"; - $commit['text'] .= substr($rev_line, 4); - } else { - $opt = explode(" ", $rev_line); - if($opt[0] == "tree") - $commit['tree'] = $opt[1]; - else if($opt[0] == "parent") - $commit['parent'][] = $opt[1]; - else if($opt[0] == "author") { - $commit['author'] = $opt[1]; - $commit['author_mail'] = $opt[2]; - $commit['author_time'] = $opt[3]; - } else if($opt[0] == "committer") { - $commit['committer'] = $opt[1]; - $commit['committer_mail'] = $opt[2]; - $commit['committer_time'] = $opt[3]; - } - } - } - $data['commits'][] = $commit; + $data['commits'][] = parse_commit($rev); } } @@ -121,6 +125,20 @@ $brach_uid = 1; $graph_commit = NULL; $first_commit = true; +if($_GET['h'] == "all") { + //set master branch as first branch + $cmd = "git --git-dir=".$repo_path.$project." rev-list --header --max-count=1 HEAD"; + $head_list = shell_exec($cmd); + $head = parse_commit($head_list); + $first_commit = false; + $data['branches'][0] = array(); + $branch = &$data['branches'][0]; + $branch['id'] = $brach_id++; + $branch['uid'] = $branch_uid++; + $branch['active'] = true; + $branch['next'] = $head['id']; +} + for($i = 0; $i <= intval($_GET['to']); $i++) { //for($i = 0; $i < count($data['commits']); $i++) { $commit = &$data['commits'][$i]; @@ -160,8 +178,13 @@ for($i = 0; $i <= intval($_GET['to']); $i++) { } } unset($cbranch); - if($first) - continue; + if($first) { + $data['branches'][count($data['branches'])] = array(); + $branch = &$data['branches'][count($data['branches'])-1]; + $branch['id'] = $brach_id++; + $branch['uid'] = $branch_uid++; + $branch['active'] = true; + } } if(count($commit['parent']) > 1) { diff --git a/patch/gitweb.cgi.diff b/patch/gitweb.cgi.diff index deff0c6..dc69c37 100644 --- a/patch/gitweb.cgi.diff +++ b/patch/gitweb.cgi.diff @@ -1,6 +1,12 @@ ---- index.cgi Wed Aug 29 01:30:10 2012 -+++ index-graph.cgi Wed Aug 29 00:35:09 2012 -@@ -4769,8 +4772,18 @@ +--- index.cgi 2012-08-29 01:30:10 +0000 ++++ index-graph.cgi 2012-09-06 11:08:23 +0000 +@@ -4764,13 +4768,26 @@ + + sub git_shortlog_body { + # uses global variable $project +- my ($commitlist, $from, $to, $refs, $extra) = @_; ++ my ($commitlist, $from, $to, $refs, $extra, $file_name, $file_hash, $ftype, $allrefs) = @_; + $from = 0 unless defined $from; $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to); @@ -10,6 +16,9 @@ + my $graph_rand = int(rand(99999)); + + my $head = git_get_head_hash($project); ++ if (defined $allrefs && $allrefs == 1) { ++ $hash = "all"; ++ } + if (!defined $hash) { + $hash = $head; + } @@ -20,7 +29,7 @@ for (my $i = $from; $i <= $to; $i++) { my %co = %{$commitlist->[$i]}; my $commit = $co{'id'}; -@@ -4781,6 +4794,7 @@ +@@ -4781,6 +4798,7 @@ print "\n"; } $alternate ^= 1; @@ -28,3 +37,50 @@ # git_summary() used print "$co{'age_string'}\n" . print "$co{'age_string_date'}\n" . format_author_html('td', \%co, 10) . ""; +@@ -5167,12 +5187,12 @@ + + # we need to request one more than 16 (0..15) to check if + # those 16 are all +- my @commitlist = $head ? parse_commits($head, 17) : (); ++ my @commitlist = $head ? parse_commits("--all", 17) : (); + if (@commitlist) { + git_print_header_div('shortlog'); + git_shortlog_body(\@commitlist, 0, 15, $refs, + $#commitlist <= 15 ? undef : +- $cgi->a({-href => href(action=>"shortlog")}, "...")); ++ $cgi->a({-href => href(action=>"shortlog")}, "..."), 0, 0, 0, 1); + } + + if (@taglist) { +@@ -5847,8 +5867,10 @@ + my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_; + + my $head = git_get_head_hash($project); ++ my $allrefs; + if (!defined $base) { + $base = $head; ++ $allrefs = 1; + } + if (!defined $page) { + $page = 0; +@@ -5856,7 +5878,10 @@ + my $refs = git_get_references(); + + my $commit_hash = $base; +- if (defined $parent) { ++ if (defined $allrefs) { ++ $commit_hash = "--all"; ++ } ++ if (defined $parent) { + $commit_hash = "$parent..$base"; + } + my @commitlist = +@@ -5912,7 +5937,7 @@ + if (defined $file_name); + + $body_subr->(\@commitlist, 0, 99, $refs, $next_link, +- $file_name, $file_hash, $ftype); ++ $file_name, $file_hash, $ftype, $allrefs); + + git_footer_html(); + } -- 2.20.1