{"thread":{"id":"19650","subject":"[PATCH] GitWeb + TopGit","startedAt":"2009-06-03T11:09:12Z","lastAt":"2009-11-03T20:39:30Z","messageCount":2,"participants":["Bert Wesarg","Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"115335","messageId":"1244027352-24055-1-git-send-email-bert.wesarg@googlemail.com","threadId":"19650","inReplyTo":null,"subject":"[PATCH] GitWeb + TopGit","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2009-06-03T11:09:12Z","receivedAt":"2009-06-03T11:09:12Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"Hello Petr,\n\nI have changed gitweb to show topgit topics. log and shortlog shows\nonly the history for refs/top-bases/$topic..$topic.\n\nYou can see it in action here:\n\nhttp://kgb2.thruhere.net/git/?p=bertw/topgit.git;a=summary\n\nThis patch is based on the debian package gitweb-1.6.3.1-1.  If you'r\ninterested I can rebase the patch on git.git.\n\nRegards,\nBert\n\nSigned-off-by: Bert Wesarg <bert.wesarg@googlemail.com>\n\n---\ndiff --git a/gitweb.cgi b/gitweb.cgi\nindex 820f073..fd9e64b 100755\n--- a/gitweb.cgi\n+++ b/gitweb.cgi\n@@ -536,6 +536,7 @@ our %actions = (\n \t\"summary\" => \\&git_summary,\n \t\"tag\" => \\&git_tag,\n \t\"tags\" => \\&git_tags,\n+\t\"topics\" => \\&git_topics,\n \t\"tree\" => \\&git_tree,\n \t\"snapshot\" => \\&git_snapshot,\n \t\"object\" => \\&git_object,\n@@ -2684,12 +2685,13 @@ sub parse_from_to_diffinfo {\n ## ......................................................................\n ## parse to array of hashes functions\n \n-sub git_get_heads_list {\n+sub _git_get_heads_list {\n+\tmy $topics = shift;\n \tmy $limit = shift;\n+\tmy $n = 0;\n \tmy @headslist;\n \n-\topen my $fd, '-|', git_cmd(), 'for-each-ref',\n-\t\t($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',\n+\topen my $fd, '-|', git_cmd(), 'for-each-ref', '--sort=-committerdate',\n \t\t'--format=%(objectname) %(refname) %(subject)%00%(committer)',\n \t\t'refs/heads'\n \t\tor return;\n@@ -2704,6 +2706,22 @@ sub git_get_heads_list {\n \t\t$ref_item{'fullname'}  = $name;\n \t\t$name =~ s!^refs/heads/!!;\n \n+\t\t# filter TopGit topics out\n+\t\topen (my $dd, \"-|\", git_cmd(), 'rev-parse',  '--quiet',\n+\t\t\t'--verify', \"refs/top-bases/$name\")\n+\t\t\tor die_error(500, \"Open rev-parse failed\");\n+\t\tmy $base_ref = <$dd>;\n+\t\tclose $dd;\n+\t\tnext if ($topics ? !defined $base_ref : defined $base_ref);\n+\n+\t\t# limit list\n+\t\tlast if ($limit and $n++ > ($limit + 1));\n+\n+\t\tif ($topics) {\n+\t\t\t$ref_item{'base_name'}  = \"refs/top-bases/$name\";\n+\t\t\t$ref_item{'base_id'}    = $base_ref;\n+\t\t}\n+\n \t\t$ref_item{'name'}  = $name;\n \t\t$ref_item{'id'}    = $hash;\n \t\t$ref_item{'title'} = $title || '(no commit message)';\n@@ -2721,6 +2739,14 @@ sub git_get_heads_list {\n \treturn wantarray ? @headslist : \\@headslist;\n }\n \n+sub git_get_heads_list {\n+\treturn _git_get_heads_list(0, @_);\n+}\n+\n+sub git_get_topics_list {\n+\treturn _git_get_heads_list(1, @_);\n+}\n+\n sub git_get_tags_list {\n \tmy $limit = shift;\n \tmy @tagslist;\n@@ -4335,6 +4361,53 @@ sub git_heads_body {\n \tprint \"</table>\\n\";\n }\n \n+sub git_topics_body {\n+\t# uses global variable $project\n+\tmy ($topiclist, $head, $from, $to, $extra) = @_;\n+\t$from = 0 unless defined $from;\n+\t$to = $#{$topiclist} if (!defined $to || $#{$topiclist} < $to);\n+\n+\tprint \"<table class=\\\"heads\\\">\\n\";\n+\tmy $alternate = 1;\n+\tfor (my $i = $from; $i <= $to; $i++) {\n+\t\tmy $entry = $topiclist->[$i];\n+\t\tmy %ref = %$entry;\n+\t\tmy $curr = $ref{'id'} eq $head;\n+\t\tif ($alternate) {\n+\t\t\tprint \"<tr class=\\\"dark\\\">\\n\";\n+\t\t} else {\n+\t\t\tprint \"<tr class=\\\"light\\\">\\n\";\n+\t\t}\n+\t\t$alternate ^= 1;\n+\t\tprint \"<td><i>$ref{'age'}</i></td>\\n\" .\n+\t\t      ($curr ? \"<td class=\\\"current_head\\\">\" : \"<td>\") .\n+\t\t      $cgi->a({-href => href(action=>\"shortlog\",\n+\t\t                             hash_parent=>$ref{'base_name'},\n+\t\t                             hash=>$ref{'fullname'},\n+\t\t                             extra_options=>'--no-merges'),\n+\t\t               -class => \"list name\"},esc_html($ref{'name'})) .\n+\t\t      \"</td>\\n\" .\n+\t\t      \"<td class=\\\"link\\\">\" .\n+\t\t      $cgi->a({-href => href(action=>\"shortlog\",\n+\t\t                             hash_parent=>$ref{'base_name'},\n+\t\t                             hash=>$ref{'fullname'},\n+\t\t                             extra_options=>'--no-merges')}, \"shortlog\") . \" | \" .\n+\t\t      $cgi->a({-href => href(action=>\"log\",\n+\t\t                             hash_parent=>$ref{'base_name'},\n+\t\t                             hash=>$ref{'fullname'},\n+\t\t                             extra_options=>'--no-merges')}, \"log\") . \" | \" .\n+\t\t      $cgi->a({-href => href(action=>\"tree\", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})}, \"tree\") .\n+\t\t      \"</td>\\n\" .\n+\t\t      \"</tr>\";\n+\t}\n+\tif (defined $extra) {\n+\t\tprint \"<tr>\\n\" .\n+\t\t      \"<td colspan=\\\"3\\\">$extra</td>\\n\" .\n+\t\t      \"</tr>\\n\";\n+\t}\n+\tprint \"</table>\\n\";\n+}\n+\n sub git_search_grep_body {\n \tmy ($commitlist, $from, $to, $extra) = @_;\n \t$from = 0 unless defined $from;\n@@ -4481,6 +4554,7 @@ sub git_summary {\n \t# there are more ...\n \tmy @taglist  = git_get_tags_list(16);\n \tmy @headlist = git_get_heads_list(16);\n+\tmy @topiclist = git_get_topics_list(16);\n \tmy @forklist;\n \tmy $check_forks = gitweb_check_feature('forks');\n \n@@ -4558,6 +4632,13 @@ sub git_summary {\n \t\t               $cgi->a({-href => href(action=>\"heads\")}, \"...\"));\n \t}\n \n+\tif (@topiclist) {\n+\t\tgit_print_header_div('topics');\n+\t\tgit_topics_body(\\@topiclist, $head, 0, 15,\n+\t\t               $#topiclist <= 15 ? undef :\n+\t\t               $cgi->a({-href => href(action=>\"topics\")}, \"...\"));\n+\t}\n+\n \tif (@forklist) {\n \t\tgit_print_header_div('forks');\n \t\tgit_project_list_body(\\@forklist, 'age', 0, 15,\n@@ -4757,6 +4838,19 @@ sub git_heads {\n \tgit_footer_html();\n }\n \n+sub git_topics {\n+\tmy $head = git_get_head_hash($project);\n+\tgit_header_html();\n+\tgit_print_page_nav('','', $head,undef,$head);\n+\tgit_print_header_div('summary', $project);\n+\n+\tmy @topicslist = git_get_topics_list();\n+\tif (@topicslist) {\n+\t\tgit_topics_body(\\@topicslist, $head);\n+\t}\n+\tgit_footer_html();\n+}\n+\n sub git_blob_plain {\n \tmy $type = shift;\n \tmy $expires;\n@@ -5054,7 +5148,11 @@ sub git_log {\n \t}\n \tmy $refs = git_get_references();\n \n-\tmy @commitlist = parse_commits($hash, 101, (100 * $page));\n+\tmy $commit_hash = $hash;\n+\tif (defined $hash_parent) {\n+\t\t$commit_hash = \"$hash_parent..$hash\";\n+\t}\n+\tmy @commitlist = parse_commits($commit_hash, 101, (100 * $page));\n \n \tmy $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100);\n \n"},{"id":"126671","messageId":"20091103203930.GB17748@machine.or.cz","threadId":"19650","inReplyTo":"1244027352-24055-1-git-send-email-bert.wesarg@googlemail.com","subject":"Re: [PATCH] GitWeb + TopGit","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2009-11-03T20:39:30Z","receivedAt":"2009-11-03T20:39:30Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"  Hi!\n\nOn Wed, Jun 03, 2009 at 01:09:12PM +0200, Bert Wesarg wrote:\n> I have changed gitweb to show topgit topics. log and shortlog shows\n> only the history for refs/top-bases/$topic..$topic.\n> \n> You can see it in action here:\n> \n> http://kgb2.thruhere.net/git/?p=bertw/topgit.git;a=summary\n> \n> This patch is based on the debian package gitweb-1.6.3.1-1.  If you'r\n> interested I can rebase the patch on git.git.\n\n  I'm very sorry I never got around to replying to this patch; I'd like\nto add it to repo.or.cz now, would you still be interested in improving\nit a little?\n\n  Specifically, it would be necessary to show the topics section only if\nthe repository actually is topgit-controlled, that is it has the\nrefs/top-bases/ tree. If you could add that, I'm wondering if it would\nbe also suitable for gitweb upstream inclusion? Anyone...?\n\n  Your gitweb above also has an extra 'patches' link in the shortlog\nview - this would indeed be much useful to actually get the patch\nintroduced by the topic branch, however:\n\n  (i) It is not included in this patch?\n  (ii) It doesn't seem to work, giving a 400 error.\n  (iii) It would be cool if it could also be added to the links in the\ntopic list.\n\n  Thanks!\n\n> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>\n> \n> ---\n> diff --git a/gitweb.cgi b/gitweb.cgi\n> index 820f073..fd9e64b 100755\n> --- a/gitweb.cgi\n> +++ b/gitweb.cgi\n> @@ -5054,7 +5148,11 @@ sub git_log {\n>  \t}\n>  \tmy $refs = git_get_references();\n>  \n> -\tmy @commitlist = parse_commits($hash, 101, (100 * $page));\n> +\tmy $commit_hash = $hash;\n> +\tif (defined $hash_parent) {\n> +\t\t$commit_hash = \"$hash_parent..$hash\";\n> +\t}\n> +\tmy @commitlist = parse_commits($commit_hash, 101, (100 * $page));\n>  \n>  \tmy $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100);\n>  \n\n  And this seems like overally useful gitweb addition.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nA lot of people have my books on their bookshelves.\nThat's the problem, they need to read them. -- Don Knuth\n"}]}