Skip to content

Commit 7f9778b

Browse files
g-papeJunio C Hamano
authored andcommitted
gitweb: choose appropriate view for file type if a= parameter missing
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7b6e0eb commit 7f9778b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

gitweb/gitweb.perl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,16 @@ sub evaluate_path_info {
458458
"project_index" => \&git_project_index,
459459
);
460460

461-
if (defined $project) {
462-
$action ||= 'summary';
463-
} else {
464-
$action ||= 'project_list';
461+
if (!defined $action) {
462+
if (defined $hash) {
463+
$action = git_get_type($hash);
464+
} elsif (defined $hash_base && defined $file_name) {
465+
$action = git_get_type("$hash_base:$file_name");
466+
} elsif (defined $project) {
467+
$action = 'summary';
468+
} else {
469+
$action = 'project_list';
470+
}
465471
}
466472
if (!defined($actions{$action})) {
467473
die_error(undef, "Unknown action");

0 commit comments

Comments
 (0)