]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.perl
gitweb: Always use git-peek-remote in git_get_references
[Gitweb] / gitweb.perl
index 8c0e4731921c5df05292aec634ca0efcc093e0f8c52009d5e5bd9117b4406905..64af897516cfcb8c88aedd350aba0e411bca12a7d6b3f408e2ad6d1a1868f349 100755 (executable)
@@ -274,13 +274,16 @@ sub evaluate_path_info {
        return if defined $project;
        my $path_info = $ENV{"PATH_INFO"};
        return if !$path_info;
-       $path_info =~ s,(^/|/$),,gs;
-       $path_info = validate_input($path_info);
+       $path_info =~ s,^/+,,;
        return if !$path_info;
+       # find which part of PATH_INFO is project
        $project = $path_info;
+       $project =~ s,/+$,,;
        while ($project && !-e "$projectroot/$project/HEAD") {
                $project =~ s,/*[^/]*$,,;
        }
+       # validate project
+       $project = validate_input($project);
        if (!$project ||
            ($export_ok && !-e "$projectroot/$project/$export_ok") ||
            ($strict_export && !project_in_list($project))) {
@@ -289,15 +292,23 @@ sub evaluate_path_info {
        }
        # do not change any parameters if an action is given using the query string
        return if $action;
-       if ($path_info =~ m,^$project/([^/]+)/(.+)$,) {
-               # we got "project.git/branch/filename"
-               $action    ||= "blob_plain";
-               $hash_base ||= validate_input($1);
-               $file_name ||= validate_input($2);
-       } elsif ($path_info =~ m,^$project/([^/]+)$,) {
+       $path_info =~ s,^$project/*,,;
+       my ($refname, $pathname) = split(/:/, $path_info, 2);
+       if (defined $pathname) {
+               # we got "project.git/branch:filename" or "project.git/branch:dir/"
+               # we could use git_get_type(branch:pathname), but it needs $git_dir
+               $pathname =~ s,^/+,,;
+               if (!$pathname || substr($pathname, -1) eq "/") {
+                       $action  ||= "tree";
+               } else {
+                       $action  ||= "blob_plain";
+               }
+               $hash_base ||= validate_input($refname);
+               $file_name ||= validate_input($pathname);
+       } elsif (defined $refname) {
                # we got "project.git/branch"
                $action ||= "shortlog";
-               $hash   ||= validate_input($1);
+               $hash   ||= validate_input($refname);
        }
 }
 evaluate_path_info();
@@ -341,6 +352,10 @@ if (defined $project) {
 if (!defined($actions{$action})) {
        die_error(undef, "Unknown action");
 }
+if ($action !~ m/^(opml|project_list|project_index)$/ &&
+    !$project) {
+       die_error(undef, "Project needed");
+}
 $actions{$action}->();
 exit;
 
@@ -828,16 +843,10 @@ sub git_get_project_owner {
 sub git_get_references {
        my $type = shift || "";
        my %refs;
-       my $fd;
        # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c      refs/tags/v2.6.11
        # c39ae07f393806ccf406ef966e9a15afc43cc36a      refs/tags/v2.6.11^{}
-       if (-f "$projectroot/$project/info/refs") {
-               open $fd, "$projectroot/$project/info/refs"
-                       or return;
-       } else {
-               open $fd, "-|", git_cmd(), "ls-remote", "."
-                       or return;
-       }
+       open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
+               or return;
 
        while (my $line = <$fd>) {
                chomp $line;
@@ -1197,7 +1206,7 @@ sub mimetype_guess_file {
        }
        close(MIME);
 
-       $filename =~ /\.(.*?)$/;
+       $filename =~ /\.([^.]*)$/;
        return $mimemap{$1};
 }
 
This page took 0.191124 seconds and 4 git commands to generate.