]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.perl
gitweb: Move git-ls-tree output parsing to parse_ls_tree_line
[Gitweb] / gitweb.perl
index 09942030e1d5b12737d636e3f35007d5cbb52438b61b40f1fb1ae46241257da6..67f3d91d66699cfe71b11e939da31c2dd2f1f60fae025229f9b2bad70d909182 100755 (executable)
@@ -152,7 +152,7 @@ sub feature_snapshot {
 our @diff_opts = ('-M'); # taken from git_commit
 
 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
-require $GITWEB_CONFIG if -e $GITWEB_CONFIG;
+do $GITWEB_CONFIG if -e $GITWEB_CONFIG;
 
 # version of the core git binary
 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
@@ -1034,6 +1034,27 @@ sub parse_difftree_raw_line {
        return wantarray ? %res : \%res;
 }
 
+# parse line of git-ls-tree output
+sub parse_ls_tree_line ($;%) {
+       my $line = shift;
+       my %opts = @_;
+       my %res;
+
+       #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa  panic.c'
+       $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
+
+       $res{'mode'} = $1;
+       $res{'type'} = $2;
+       $res{'hash'} = $3;
+       if ($opts{'-z'}) {
+               $res{'name'} = $4;
+       } else {
+               $res{'name'} = unquote($4);
+       }
+
+       return wantarray ? %res : \%res;
+}
+
 ## ......................................................................
 ## parse to array of hashes functions
 
@@ -1358,10 +1379,18 @@ sub git_print_header_div {
 sub git_print_authorship {
        my $co = shift;
 
-       my %ad = parse_date($co->{'author_epoch'});
+       my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
        print "<div class=\"author_date\">" .
              esc_html($co->{'author_name'}) .
-             " [$ad{'rfc2822'}]</div>\n";
+             " [$ad{'rfc2822'}";
+       if ($ad{'hour_local'} < 6) {
+               printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
+                      $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
+       } else {
+               printf(" (%02d:%02d %s)",
+                      $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
+       }
+       print "]</div>\n";
 }
 
 sub git_print_page_path {
@@ -2504,51 +2533,54 @@ sub git_tree {
        print "<table cellspacing=\"0\">\n";
        my $alternate = 0;
        foreach my $line (@entries) {
-               #'100644        blob    0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa        panic.c'
-               $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
-               my $t_mode = $1;
-               my $t_type = $2;
-               my $t_hash = $3;
-               my $t_name = validate_input($4);
+               my %t = parse_ls_tree_line($line, -z => 1);
+
                if ($alternate) {
                        print "<tr class=\"dark\">\n";
                } else {
                        print "<tr class=\"light\">\n";
                }
                $alternate ^= 1;
-               print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n";
-               if ($t_type eq "blob") {
+
+               print "<td class=\"mode\">" . mode_str($t{'mode'}) . "</td>\n";
+               if ($t{'type'} eq "blob") {
                        print "<td class=\"list\">" .
-                             $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key),
-                                     -class => "list"}, esc_html($t_name)) .
+                             $cgi->a({-href => href(action=>"blob", hash=>$t{'hash'},
+                                                    file_name=>"$base$t{'name'}", %base_key),
+                                     -class => "list"}, esc_html($t{'name'})) .
                              "</td>\n" .
                              "<td class=\"link\">" .
-                             $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
+                             $cgi->a({-href => href(action=>"blob", hash=>$t{'hash'},
+                                                    file_name=>"$base$t{'name'}", %base_key)},
                                      "blob");
                        if ($have_blame) {
                                print " | " .
-                                       $cgi->a({-href => href(action=>"blame", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
+                                       $cgi->a({-href => href(action=>"blame", hash=>$t{'hash'},
+                                                              file_name=>"$base$t{'name'}", %base_key)},
                                                "blame");
                        }
                        print " | " .
                              $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
-                                                    hash=>$t_hash, file_name=>"$base$t_name")},
+                                                    hash=>$t{'hash'}, file_name=>"$base$t{'name'}")},
                                      "history") .
                              " | " .
                              $cgi->a({-href => href(action=>"blob_plain",
-                                                    hash=>$t_hash, file_name=>"$base$t_name")},
+                                                    hash=>$t{'hash'}, file_name=>"$base$t{'name'}")},
                                      "raw") .
                              "</td>\n";
-               } elsif ($t_type eq "tree") {
+               } elsif ($t{'type'} eq "tree") {
                        print "<td class=\"list\">" .
-                             $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
-                                     esc_html($t_name)) .
+                             $cgi->a({-href => href(action=>"tree", hash=>$t{'hash'},
+                                                    file_name=>"$base$t{'name'}", %base_key)},
+                                     esc_html($t{'name'})) .
                              "</td>\n" .
                              "<td class=\"link\">" .
-                             $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
+                             $cgi->a({-href => href(action=>"tree", hash=>$t{'hash'},
+                                                    file_name=>"$base$t{'name'}", %base_key)},
                                      "tree") .
                              " | " .
-                             $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, file_name=>"$base$t_name")},
+                             $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
+                                                    file_name=>"$base$t{'name'}")},
                                      "history") .
                              "</td>\n";
                }
@@ -2770,10 +2802,6 @@ sub git_blobdiff {
                        @difftree
                                or die_error('404 Not Found', "Blob diff not found");
 
-               } elsif (defined $hash) { # try to find filename from $hash
-                       if ($hash !~ /[0-9a-fA-F]{40}/) {
-                               $hash = git_to_hash($hash);
-                       }
                } elsif (defined $hash &&
                         $hash =~ /[0-9a-fA-F]{40}/) {
                        # try to find filename from $hash
This page took 0.175435 seconds and 4 git commands to generate.