* [PATCH] GitWeb + TopGit
@ 2009-06-03 11:09 Bert Wesarg
2009-11-03 20:39 ` Petr Baudis
0 siblings, 1 reply; 2+ messages in thread
From: Bert Wesarg @ 2009-06-03 11:09 UTC (permalink / raw)
To: Petr Baudis; +Cc: Bert Wesarg, git
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@googlemail.com>
---
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);
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] GitWeb + TopGit
2009-06-03 11:09 [PATCH] GitWeb + TopGit Bert Wesarg
@ 2009-11-03 20:39 ` Petr Baudis
0 siblings, 0 replies; 2+ messages in thread
From: Petr Baudis @ 2009-11-03 20:39 UTC (permalink / raw)
To: Bert Wesarg; +Cc: git
Hi!
On Wed, Jun 03, 2009 at 01:09:12PM +0200, Bert Wesarg wrote:
> 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.
I'm very sorry I never got around to replying to this patch; I'd like
to add it to repo.or.cz now, would you still be interested in improving
it a little?
Specifically, it would be necessary to show the topics section only if
the repository actually is topgit-controlled, that is it has the
refs/top-bases/ tree. If you could add that, I'm wondering if it would
be also suitable for gitweb upstream inclusion? Anyone...?
Your gitweb above also has an extra 'patches' link in the shortlog
view - this would indeed be much useful to actually get the patch
introduced by the topic branch, however:
(i) It is not included in this patch?
(ii) It doesn't seem to work, giving a 400 error.
(iii) It would be cool if it could also be added to the links in the
topic list.
Thanks!
> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
>
> ---
> diff --git a/gitweb.cgi b/gitweb.cgi
> index 820f073..fd9e64b 100755
> --- a/gitweb.cgi
> +++ b/gitweb.cgi
> @@ -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);
>
And this seems like overally useful gitweb addition.
--
Petr "Pasky" Baudis
A lot of people have my books on their bookshelves.
That's the problem, they need to read them. -- Don Knuth
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-11-03 20:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-03 11:09 [PATCH] GitWeb + TopGit Bert Wesarg
2009-11-03 20:39 ` Petr Baudis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).