gitweb: more support for PATH_INFO based URLs
Now three types of path based URLs are supported: gitweb.cgi/project.git gitweb.cgi/project.git/branch gitweb.cgi/project.git/branch/filename The first one (show project summary) was already supported for a long time now. The other two are new: they show the shortlog of a branch or the plain file contents of some file contained in the repository. This is especially useful to support project web pages for small projects: just create an html branch and then use an URL like gitweb.cgi/project.git/html/index.html. Signed-off-by: Martin Waitz <tali@admingilde.org> Acked-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Martin Waitz committed
Sep 16, 2006 at 23:08 UTC
dd70235f5a81e52725365365a554cf7c8cfa37e6
1 file changed
+27
-7
gitweb/gitweb.perl
+27
-7
@@ -196,12 +196,7 @@ if (defined $action) {
196
}
197
}
198
199
-our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
200
-if (defined $project) {
201
- $project =~ s|^/||;
202
- $project =~ s|/$||;
203
- $project = undef unless $project;
204
-}
199
+our $project = $cgi->param('p');
200
if (defined $project) {
201
if (!validate_input($project)) {
202
die_error(undef, "Invalid project parameter");
@@ -212,7 +207,6 @@ if (defined $project) {
207
if (!(-e "$projectroot/$project/HEAD")) {
208
die_error(undef, "No such project");
209
}
215
- $git_dir = "$projectroot/$project";
210
}
211
212
our $file_name = $cgi->param('f');
@@ -272,6 +266,32 @@ if (defined $searchtext) {
266
$searchtext = quotemeta $searchtext;
267
}
268
269
+# now read PATH_INFO and use it as alternative to parameters
270
+our $path_info = $ENV{"PATH_INFO"};
271
+$path_info =~ s|^/||;
272
+$path_info =~ s|/$||;
273
+if (validate_input($path_info) && !defined $project) {
274
+ $project = $path_info;
275
+ while ($project && !-e "$projectroot/$project/HEAD") {
276
+ $project =~ s,/*[^/]*$,,;
277
+ }
278
+ if (defined $project) {
279
+ $project = undef unless $project;
280
+ }
281
+ if ($path_info =~ m,^$project/([^/]+)/(.+)$,) {
282
+ # we got "project.git/branch/filename"
283
+ $action ||= "blob_plain";
284
+ $hash_base ||= $1;
285
+ $file_name ||= $2;
286
+ } elsif ($path_info =~ m,^$project/([^/]+)$,) {
287
+ # we got "project.git/branch"
288
+ $action ||= "shortlog";
289
+ $hash ||= $1;
290
+ }
291
+}
292
+
293
+$git_dir = "$projectroot/$project";
294
+
295
# dispatch
296
my %actions = (
297
"blame" => \&git_blame2,