[PATCH] GitWeb + TopGit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Petr,

I have changed gitweb to show topgit topics. log and shortlog shows
only the history for refs/top-bases/$topic..$topic.

You can see it in action here:

http://kgb2.thruhere.net/git/?p=bertw/topgit.git;a=summary

This patch is based on the debian package gitweb-1.6.3.1-1.  If you'r
interested I can rebase the patch on git.git.

Regards,
Bert

Signed-off-by: Bert Wesarg <bert.wesarg@xxxxxxxxxxxxxx>

---
diff --git a/gitweb.cgi b/gitweb.cgi
index 820f073..fd9e64b 100755
--- a/gitweb.cgi
+++ b/gitweb.cgi
@@ -536,6 +536,7 @@ our %actions = (
 	"summary" => \&git_summary,
 	"tag" => \&git_tag,
 	"tags" => \&git_tags,
+	"topics" => \&git_topics,
 	"tree" => \&git_tree,
 	"snapshot" => \&git_snapshot,
 	"object" => \&git_object,
@@ -2684,12 +2685,13 @@ sub parse_from_to_diffinfo {
 ## ......................................................................
 ## parse to array of hashes functions
 
-sub git_get_heads_list {
+sub _git_get_heads_list {
+	my $topics = shift;
 	my $limit = shift;
+	my $n = 0;
 	my @headslist;
 
-	open my $fd, '-|', git_cmd(), 'for-each-ref',
-		($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
+	open my $fd, '-|', git_cmd(), 'for-each-ref', '--sort=-committerdate',
 		'--format=%(objectname) %(refname) %(subject)%00%(committer)',
 		'refs/heads'
 		or return;
@@ -2704,6 +2706,22 @@ sub git_get_heads_list {
 		$ref_item{'fullname'}  = $name;
 		$name =~ s!^refs/heads/!!;
 
+		# filter TopGit topics out
+		open (my $dd, "-|", git_cmd(), 'rev-parse',  '--quiet',
+			'--verify', "refs/top-bases/$name")
+			or die_error(500, "Open rev-parse failed");
+		my $base_ref = <$dd>;
+		close $dd;
+		next if ($topics ? !defined $base_ref : defined $base_ref);
+
+		# limit list
+		last if ($limit and $n++ > ($limit + 1));
+
+		if ($topics) {
+			$ref_item{'base_name'}  = "refs/top-bases/$name";
+			$ref_item{'base_id'}    = $base_ref;
+		}
+
 		$ref_item{'name'}  = $name;
 		$ref_item{'id'}    = $hash;
 		$ref_item{'title'} = $title || '(no commit message)';
@@ -2721,6 +2739,14 @@ sub git_get_heads_list {
 	return wantarray ? @headslist : \@headslist;
 }
 
+sub git_get_heads_list {
+	return _git_get_heads_list(0, @_);
+}
+
+sub git_get_topics_list {
+	return _git_get_heads_list(1, @_);
+}
+
 sub git_get_tags_list {
 	my $limit = shift;
 	my @tagslist;
@@ -4335,6 +4361,53 @@ sub git_heads_body {
 	print "</table>\n";
 }
 
+sub git_topics_body {
+	# uses global variable $project
+	my ($topiclist, $head, $from, $to, $extra) = @_;
+	$from = 0 unless defined $from;
+	$to = $#{$topiclist} if (!defined $to || $#{$topiclist} < $to);
+
+	print "<table class=\"heads\">\n";
+	my $alternate = 1;
+	for (my $i = $from; $i <= $to; $i++) {
+		my $entry = $topiclist->[$i];
+		my %ref = %$entry;
+		my $curr = $ref{'id'} eq $head;
+		if ($alternate) {
+			print "<tr class=\"dark\">\n";
+		} else {
+			print "<tr class=\"light\">\n";
+		}
+		$alternate ^= 1;
+		print "<td><i>$ref{'age'}</i></td>\n" .
+		      ($curr ? "<td class=\"current_head\">" : "<td>") .
+		      $cgi->a({-href => href(action=>"shortlog",
+		                             hash_parent=>$ref{'base_name'},
+		                             hash=>$ref{'fullname'},
+		                             extra_options=>'--no-merges'),
+		               -class => "list name"},esc_html($ref{'name'})) .
+		      "</td>\n" .
+		      "<td class=\"link\">" .
+		      $cgi->a({-href => href(action=>"shortlog",
+		                             hash_parent=>$ref{'base_name'},
+		                             hash=>$ref{'fullname'},
+		                             extra_options=>'--no-merges')}, "shortlog") . " | " .
+		      $cgi->a({-href => href(action=>"log",
+		                             hash_parent=>$ref{'base_name'},
+		                             hash=>$ref{'fullname'},
+		                             extra_options=>'--no-merges')}, "log") . " | " .
+		      $cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})}, "tree") .
+		      "</td>\n" .
+		      "</tr>";
+	}
+	if (defined $extra) {
+		print "<tr>\n" .
+		      "<td colspan=\"3\">$extra</td>\n" .
+		      "</tr>\n";
+	}
+	print "</table>\n";
+}
+
 sub git_search_grep_body {
 	my ($commitlist, $from, $to, $extra) = @_;
 	$from = 0 unless defined $from;
@@ -4481,6 +4554,7 @@ sub git_summary {
 	# there are more ...
 	my @taglist  = git_get_tags_list(16);
 	my @headlist = git_get_heads_list(16);
+	my @topiclist = git_get_topics_list(16);
 	my @forklist;
 	my $check_forks = gitweb_check_feature('forks');
 
@@ -4558,6 +4632,13 @@ sub git_summary {
 		               $cgi->a({-href => href(action=>"heads")}, "..."));
 	}
 
+	if (@topiclist) {
+		git_print_header_div('topics');
+		git_topics_body(\@topiclist, $head, 0, 15,
+		               $#topiclist <= 15 ? undef :
+		               $cgi->a({-href => href(action=>"topics")}, "..."));
+	}
+
 	if (@forklist) {
 		git_print_header_div('forks');
 		git_project_list_body(\@forklist, 'age', 0, 15,
@@ -4757,6 +4838,19 @@ sub git_heads {
 	git_footer_html();
 }
 
+sub git_topics {
+	my $head = git_get_head_hash($project);
+	git_header_html();
+	git_print_page_nav('','', $head,undef,$head);
+	git_print_header_div('summary', $project);
+
+	my @topicslist = git_get_topics_list();
+	if (@topicslist) {
+		git_topics_body(\@topicslist, $head);
+	}
+	git_footer_html();
+}
+
 sub git_blob_plain {
 	my $type = shift;
 	my $expires;
@@ -5054,7 +5148,11 @@ sub git_log {
 	}
 	my $refs = git_get_references();
 
-	my @commitlist = parse_commits($hash, 101, (100 * $page));
+	my $commit_hash = $hash;
+	if (defined $hash_parent) {
+		$commit_hash = "$hash_parent..$hash";
+	}
+	my @commitlist = parse_commits($commit_hash, 101, (100 * $page));
 
 	my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100);
 
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]