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

[PATCH] gitweb: choose appropriate view for file type if a= parameter missing

From
Gerrit Pape <pape@smarden.org>
Date
May 10, 2007, 07:32 UTC
Message-ID
<20070510073207.21562.qmail@25d0c789693af2.315fe32.mid.smarden.org>
In-Reply-To
<7vvef1o2ni.fsf@assigned-by-dhcp.cox.net>

gitweb URLs use the a= parameter for the view to use on the given path, such as "blob" or "tree". Currently, if a gitweb URL omits the a= parameter, gitweb just shows the top-level repository summary, regardless of the path given. gitweb could instead choose an appropriate view based on the file type: blob for blobs (files), tree for trees (directories), and summary if no path given (the URL included no f= parameter, or an empty f= parameter).

Apart from making gitweb more robust and supporting URL editing more easily, this change would aid the creation of shortcuts to git repositories using simple substitution, such as: http://example.org/git/?p=path/to/repo.git;hb=HEAD;f=%s

With this patch, if given the hash through the h= parameter, or the hash base (hb=) and a filename (f=), gitweb uses cat-file -t to automatically set the a= parameter.

This feature was requested by Josh Triplett through
 http://bugs.debian.org/410465
Signed-off-by: Gerrit Pape <pape@smarden.org>
---
On Wed, May 09, 2007 at 07:04:01PM -0700, Junio C Hamano wrote:
Show 6 quoted lines
> I'd however request a few changes to the proposed commit log
> message:
>
>  * "See http://..." is not the primary information, but "see
>    ... for further details"; please have it at the end, not at
>    the beginning.
Okay.
>  * Was the patch authored by you, or Josh?  If the former,
>    what's his name doing here?  Perhaps you wanted to say
>    "Reported by Josh Triplett"?

Sometimes I'm lazy, it was just a copy&paste from the Debian bug report submitted by Josh.

Regards, Gerrit.
 gitweb/gitweb.perl |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 90243fd..21864c6 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -458,10 +458,16 @@ my %actions = (
 	"project_index" => \&git_project_index,
 );
 
-if (defined $project) {
-	$action ||= 'summary';
-} else {
-	$action ||= 'project_list';
+if (!defined $action) {
+	if (defined $hash) {
+		$action = git_get_type($hash);
+	} elsif (defined $hash_base && defined $file_name) {
+		$action = git_get_type("$hash_base:$file_name");
+	} elsif (defined $project) {
+		$action = 'summary';
+	} else {
+		$action = 'project_list';
+	}
 }
 if (!defined($actions{$action})) {
 	die_error(undef, "Unknown action");
-- 
1.5.1.3
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 5 in “gitweb: choose appropriate view for file type if a= parameter missing.”
  1. gitweb: choose appropriate view for file type if a= parameter missing.Gerrit Pape, May 9, 2007
  2. Junio C HamanoMay 10, 2007
  3. gitweb: choose appropriate view for file type if a= parameter missingGerrit Pape, May 10, 2007
  4. Junio C HamanoMay 10, 2007
  5. Jakub NarebskiMay 13, 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.