]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.perl
gitweb: Show submodule entries in the 'tree' view
[Gitweb] / gitweb.perl
index 9c5dfc500f558ba149407baccc2975e8f94364624fefe40aca71a5b8edd4d342..2f2e52fe63c5b13f24061496ba881aaabd1576a702b3fbf3499e2800a4ca2be1 100755 (executable)
@@ -308,10 +308,6 @@ sub feature_snapshot {
 
        if ($val) {
                @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
-               @fmts = grep { defined } map {
-                       exists $known_snapshot_format_aliases{$_} ?
-                               $known_snapshot_format_aliases{$_} : $_ } @fmts;
-               @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
        }
 
        return @fmts;
@@ -357,6 +353,18 @@ sub check_export_ok {
                (!$export_ok || -e "$dir/$export_ok"));
 }
 
+# process alternate names for backward compatibility
+# filter out unsupported (unknown) snapshot formats
+sub filter_snapshot_fmts {
+       my @fmts = @_;
+
+       @fmts = map {
+               exists $known_snapshot_format_aliases{$_} ?
+                      $known_snapshot_format_aliases{$_} : $_} @fmts;
+       @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
+
+}
+
 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
 do $GITWEB_CONFIG if -e $GITWEB_CONFIG;
 
@@ -883,11 +891,25 @@ sub age_string {
        return $age_str;
 }
 
+use constant {
+       S_IFINVALID => 0030000,
+       S_IFGITLINK => 0160000,
+};
+
+# submodule/subproject, a commit object reference
+sub S_ISGITLINK($) {
+       my $mode = shift;
+
+       return (($mode & S_IFMT) == S_IFGITLINK)
+}
+
 # convert file mode in octal to symbolic file mode string
 sub mode_str {
        my $mode = oct shift;
 
-       if (S_ISDIR($mode & S_IFMT)) {
+       if (S_ISGITLINK($mode)) {
+               return 'm---------';
+       } elsif (S_ISDIR($mode & S_IFMT)) {
                return 'drwxr-xr-x';
        } elsif (S_ISLNK($mode)) {
                return 'lrwxrwxrwx';
@@ -913,7 +935,9 @@ sub file_type {
                $mode = oct $mode;
        }
 
-       if (S_ISDIR($mode & S_IFMT)) {
+       if (S_ISGITLINK($mode)) {
+               return "submodule";
+       } elsif (S_ISDIR($mode & S_IFMT)) {
                return "directory";
        } elsif (S_ISLNK($mode)) {
                return "symlink";
@@ -934,7 +958,9 @@ sub file_type_long {
                $mode = oct $mode;
        }
 
-       if (S_ISDIR($mode & S_IFMT)) {
+       if (S_ISGITLINK($mode)) {
+               return "submodule";
+       } elsif (S_ISDIR($mode & S_IFMT)) {
                return "directory";
        } elsif (S_ISLNK($mode)) {
                return "symlink";
@@ -1300,9 +1326,11 @@ sub format_diff_line {
 sub format_snapshot_links {
        my ($hash) = @_;
        my @snapshot_fmts = gitweb_check_feature('snapshot');
+       @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
        my $num_fmts = @snapshot_fmts;
        if ($num_fmts > 1) {
                # A parenthesized list of links bearing format names.
+               # e.g. "snapshot (_tar.gz_ _zip_)"
                return "snapshot (" . join(' ', map
                        $cgi->a({
                                -href => href(
@@ -1314,8 +1342,10 @@ sub format_snapshot_links {
                , @snapshot_fmts) . ")";
        } elsif ($num_fmts == 1) {
                # A single "snapshot" link whose tooltip bears the format name.
+               # i.e. "_snapshot_"
                my ($fmt) = @snapshot_fmts;
-               return $cgi->a({
+               return
+                       $cgi->a({
                                -href => href(
                                        action=>"snapshot",
                                        hash=>$hash,
@@ -2696,6 +2726,20 @@ sub git_print_tree_entry {
                                      "history");
                }
                print "</td>\n";
+       } else {
+               # unknown object: we can only present history for it
+               # (this includes 'commit' object, i.e. submodule support)
+               print "<td class=\"list\">" .
+                     esc_path($t->{'name'}) .
+                     "</td>\n";
+               print "<td class=\"link\">";
+               if (defined $hash_base) {
+                       print $cgi->a({-href => href(action=>"history",
+                                                    hash_base=>$hash_base,
+                                                    file_name=>"$basedir$t->{'name'}")},
+                                     "history");
+               }
+               print "</td>\n";
        }
 }
 
@@ -4303,11 +4347,19 @@ sub git_tree {
 
 sub git_snapshot {
        my @supported_fmts = gitweb_check_feature('snapshot');
+       @supported_fmts = filter_snapshot_fmts(@supported_fmts);
 
        my $format = $cgi->param('sf');
-       unless ($format =~ m/[a-z0-9]+/
-               && exists($known_snapshot_formats{$format})
-               && grep($_ eq $format, @supported_fmts)) {
+       if (!@supported_fmts) {
+               die_error('403 Permission denied', "Permission denied");
+       }
+       # default to first supported snapshot format
+       $format ||= $supported_fmts[0];
+       if ($format !~ m/^[a-z0-9]+$/) {
+               die_error(undef, "Invalid snapshot format parameter");
+       } elsif (!exists($known_snapshot_formats{$format})) {
+               die_error(undef, "Unknown snapshot format");
+       } elsif (!grep($_ eq $format, @supported_fmts)) {
                die_error(undef, "Unsupported snapshot format");
        }
 
@@ -4324,7 +4376,7 @@ sub git_snapshot {
        my $cmd;
        $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
        $cmd = "$git_command archive " .
-               "--format=$known_snapshot_formats{$format}{'format'}" .
+               "--format=$known_snapshot_formats{$format}{'format'} " .
                "--prefix=\'$name\'/ $hash";
        if (exists $known_snapshot_formats{$format}{'compressor'}) {
                $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
This page took 0.222574 seconds and 4 git commands to generate.