threads / patch / 43825

patchgitweb: Add support for extending the action bar with custom links

Subject: [PATCH] gitweb: Add support for extending the action bar with custom links

## tl;dr

2 messages between Oct 2, 2008 and Oct 3, 2008. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Petr Baudis· Oct 2, 2008, 14:36 UTC · lore

This makes it possible to easily extend gitweb with custom functionality, e.g. git-browser or web-based repository administration system like the repo.or.cz/Girocco duct tape.

Signed-off-by: Petr Baudis <pasky@suse.cz>
---
 gitweb/gitweb.perl |   35 ++++++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 deletions(-)
Show changes to gitweb/gitweb.perl +34 −1
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index da474d0..9fbc9f8 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -275,6 +275,26 @@ our %feature = (
 	'forks' => {
 		'override' => 0,
 		'default' => [0]},
+
+	# Insert custom links to the action bar of all project pages.
+	# This enables you mainly to link to third-party scripts integrating
+	# into gitweb; e.g. git-browser for graphical history representation
+	# or custom web-based repository administration interface.
+
+	# The 'default' value consists of a list of triplets in the form
+	# (label, link, position) where position is the label after which
+	# to inster the link and link is a format string where %n expands
+	# to the project name, %f to the project path within the filesystem,
+	# %h to the current hash (h gitweb parameter) and %b to the current
+	# hash base (hb gitweb parameter).
+
+	# To enable system wide have in $GITWEB_CONFIG e.g.
+	# $feature{'actions'}{'default'} = [('graphiclog',
+	# 	'/git-browser/by-commit.html?r=%n', 'summary')];
+	# Project specific override is not supported.
+	'actions' => {
+		'override' => 0,
+		'default' => []},
 );
 
 sub gitweb_check_feature {
@@ -2757,13 +2777,26 @@ sub git_print_page_nav {
 			}
 		}
 	}
+
 	$arg{'tree'}{'hash'} = $treehead if defined $treehead;
 	$arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
 
+	my @actions = gitweb_check_feature('actions');
+	while (@actions) {
+		my ($label, $link, $pos) = (shift(@actions), shift(@actions), shift(@actions));
+		@navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
+		# munch munch
+		$link =~ s#%n#$project#g;
+		$link =~ s#%f#$git_dir#g;
+		$treehead ? $link =~ s#%h#$treehead#g : $link =~ s#%h##g;
+		$treebase ? $link =~ s#%b#$treebase#g : $link =~ s#%b##g;
+		$arg{$label}{'_href'} = $link;
+	}
+
 	print "<div class=\"page_nav\">\n" .
 		(join " | ",
 		 map { $_ eq $current ?
-		       $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
+		       $_ : $cgi->a({-href => ($arg{$_}{_href} ? $arg{$_}{_href} : href(%{$arg{$_}}))}, "$_")
 		 } @navs);
 	print "<br/>\n$extra<br/>\n" .
 	      "</div>\n";
-- 
tg: (c427559..) t/extra-actions/extra-actions (depends on: vanilla/master)
Petr Baudis· Oct 3, 2008, 13:45 UTC · re: Petr Baudis · lore

[PATCH] gitweb: Unify shortlog/log links

Instead of 'shortlog | log', we use only 'log' now, pointing to the shortlog action, since that is what most people are usually interested in first. In the action-specific navbar, you can then choose between short and full log view.

The aim of this patch is to reduce the overwhelming number of links by including only orthogonal links to most popular views.

Signed-off-by: Petr Baudis <petr.baudis@novartis.com>
---
 gitweb/gitweb.perl |   46 +++++++++++++++++++++++++++++++++-------------
 1 files changed, 33 insertions(+), 13 deletions(-)
Show changes to gitweb/gitweb.perl +33 −13
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 9fbc9f8..58fc137 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2761,7 +2761,7 @@ sub git_print_page_nav {
 	my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
 	$extra = '' if !defined $extra; # pager or formats
 
-	my @navs = qw(summary shortlog log commit commitdiff tree);
+	my @navs = qw(summary log commit commitdiff tree);
 	if ($suppress) {
 		@navs = grep { $_ ne $suppress } @navs;
 	}
@@ -2772,12 +2772,11 @@ sub git_print_page_nav {
 			$arg{$_}{'hash'} = $head;
 		}
 		if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
-			for (qw(shortlog log)) {
-				$arg{$_}{'hash'} = $head;
-			}
+			$arg{'log'}{'hash'} = $head;
 		}
 	}
 
+	$arg{'log'}{'action'} = 'shortlog';
 	$arg{'tree'}{'hash'} = $treehead if defined $treehead;
 	$arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
 
@@ -2832,6 +2831,26 @@ sub format_paging_nav {
 	return $paging_nav;
 }
 
+sub format_log_nav {
+	my ($action, $hash, $head, $page, $has_next_link) = @_;
+	my $paging_nav;
+
+	if ($action eq 'shortlog') {
+		$paging_nav .= 'shortlog';
+	} else {
+		$paging_nav .= $cgi->a({-href => href(action=>'shortlog', -replay=>1)}, 'shortlog');
+	}
+	$paging_nav .= ' | ';
+	if ($action eq 'log') {
+		$paging_nav .= 'fulllog';
+	} else {
+		$paging_nav .= $cgi->a({-href => href(action=>'log', -replay=>1)}, 'fulllog');
+	}
+
+	$paging_nav .= " | " . format_paging_nav($action, $hash, $head, $page, $has_next_link);
+	return $paging_nav;
+}
+
 ## ......................................................................
 ## functions printing or outputting HTML: div
 
@@ -3722,8 +3741,7 @@ sub git_project_list_body {
 		      (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
 		      "<td class=\"link\">" .
 		      $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary")   . " | " .
-		      $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
-		      $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " .
+		      $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "log") . " | " .
 		      $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") .
 		      ($pr->{'forks'} ? " | " . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "forks") : '') .
 		      "</td>\n" .
@@ -3894,8 +3912,7 @@ sub git_tags_body {
 		      "<td class=\"link\">" . " | " .
 		      $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
 		if ($tag{'reftype'} eq "commit") {
-			print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})}, "shortlog") .
-			      " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})}, "log");
+			print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})}, "log");
 		} elsif ($tag{'reftype'} eq "blob") {
 			print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
 		}
@@ -3934,8 +3951,7 @@ sub git_heads_body {
 		               -class => "list name"},esc_html($ref{'name'})) .
 		      "</td>\n" .
 		      "<td class=\"link\">" .
-		      $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})}, "shortlog") . " | " .
-		      $cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})}, "log") . " | " .
+		      $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})}, "log") . " | " .
 		      $cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})}, "tree") .
 		      "</td>\n" .
 		      "</tr>";
@@ -4628,9 +4644,12 @@ sub git_log {
 
 	my @commitlist = parse_commits($hash, 101, (100 * $page));
 
-	my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100);
+	my $paging_nav = format_log_nav('log', $hash, $head, $page, $#commitlist >= 100);
 
-	git_header_html();
+	{
+		local $action = 'fulllog';
+		git_header_html();
+	}
 	git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
 
 	if (!@commitlist) {
@@ -5533,7 +5552,8 @@ sub git_shortlog {
 
 	my @commitlist = parse_commits($hash, 101, (100 * $page));
 
-	my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#commitlist >= 100);
+	my $paging_nav = format_log_nav('shortlog', $hash, $head, $page, $#commitlist >= 100);
+
 	my $next_link = '';
 	if ($#commitlist >= 100) {
 		$next_link =
-- 
tg: (7fac06d..) t/extra-actions/log-consolidate (depends on: t/extra-actions/extra-actions)

← back to recent threads