Skip to content

Commit

Permalink
gitweb: choose appropriate view for file type if a= parameter missing
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Gerrit Pape authored and Junio C Hamano committed May 10, 2007
1 parent 7b6e0eb commit 7f9778b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions gitweb/gitweb.perl
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,16 @@ sub evaluate_path_info {
"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");
Expand Down

0 comments on commit 7f9778b

Please sign in to comment.