git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] gitweb: Easier adding/changing parameters to current URL

From
Jakub Narebski <jnareb@gmail.com>
Date
Nov 1, 2007, 12:06 UTC
Message-ID
<1193918789-16421-3-git-send-email-jnareb@gmail.com>
In-Reply-To
<1193918789-16421-1-git-send-email-jnareb@gmail.com>

Add boolean option '-replay' to href() subroutine, which is used to generate links in gitweb. This option "replays" current URL, overriding it with provided parameters. It means that current value of each CGI parameter is used unless otherwise provided.

This change is meant to make it easier to generate links which differ
from current page URL only by one parameter, for example the same view
but sorted by different column:
  href(-replay=>1, order=>"age")
or view which differs by some option, e.g. in log views
  href(-replay=>1, extra_options=>"--no-merges")
or alternate view of the same object, e.g. in the 'blob' view
  href(-replay=>1, action=>"blob_plain")
Actual use of this functionality is left for later.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index e36dec1..eaab895 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -611,6 +611,15 @@ sub href(%) {
 	);
 	my %mapping = @mapping;
 
+	if ($params{-replay}) {
+		while (my ($name, $symbol) = each %mapping) {
+			if (!exists $params{$name}) {
+				# to allow for multivalued params we use arrayref form
+				$params{$name} = [ $cgi->param($symbol) ];
+			}
+		}
+	}
+
 	$params{'project'} = $project unless exists $params{'project'};
 
 	my ($use_pathinfo) = gitweb_check_feature('pathinfo');
-- 
1.5.3.4
Previous: Jakub NarebskiNext: Jakub Narebski
Message 3 of 7 in “gitweb: Simplify some gitweb URLs generation”
  1. 0/3 gitweb: Simplify some gitweb URLs generationJakub Narebski, Nov 1, 2007
  2. 0/3 gitweb: Simplify some gitweb URLs generationJakub Narebski, Nov 1, 2007
  3. 1/3 gitweb: Easier adding/changing parameters to current URLJakub Narebski, Nov 1, 2007
  4. 2/3 gitweb: Use href(-replay=>1, page=>...) to generate pagination linksJakub Narebski, Nov 1, 2007
  5. 3/3 gitweb: Use href(-replay=>1, action=>...) to generate alternate viewsJakub Narebski, Nov 1, 2007
  6. Junio C HamanoNov 1, 2007
  7. Jakub NarebskiNov 2, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.