Code

Merge branch 'rg/gitweb'
authorJunio C Hamano <gitster@pobox.com>
Sun, 22 Jun 2008 21:31:44 +0000 (14:31 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 22 Jun 2008 21:31:44 +0000 (14:31 -0700)
* rg/gitweb:
  gitweb: remove git_blame and rename git_blame2 to git_blame

1  2 
gitweb/gitweb.perl

diff --combined gitweb/gitweb.perl
index 49b01d8c25b7a7d9c850b5484414bfcfa9bbf85b,8d1f3e0547dd675d7d0fe3788f76e49efc701222..3a7adaee23868985613e70c83440d2cf99b6e9f2
@@@ -377,7 -377,7 +377,7 @@@ if (-e $GITWEB_CONFIG) 
  }
  
  # version of the core git binary
 -our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
 +our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
  
  $projects_list ||= $projectroot;
  
@@@ -539,7 -539,7 +539,7 @@@ $git_dir = "$projectroot/$project" if $
  
  # dispatch
  my %actions = (
-       "blame" => \&git_blame2,
+       "blame" => \&git_blame,
        "blobdiff" => \&git_blobdiff,
        "blobdiff_plain" => \&git_blobdiff_plain,
        "blob" => \&git_blob,
@@@ -1500,13 -1500,9 +1500,13 @@@ sub git_cmd 
        return $GIT, '--git-dir='.$git_dir;
  }
  
 -# returns path to the core git executable and the --git-dir parameter as string
 -sub git_cmd_str {
 -      return join(' ', git_cmd());
 +# quote the given arguments for passing them to the shell
 +# quote_command("command", "arg 1", "arg with ' and ! characters")
 +# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
 +# Try to avoid using this function wherever possible.
 +sub quote_command {
 +      return join(' ',
 +                  map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
  }
  
  # get HEAD ref of given project as hash
@@@ -2162,6 -2158,49 +2162,6 @@@ sub parse_commits 
        return wantarray ? @cos : \@cos;
  }
  
 -# parse ref from ref_file, given by ref_id, with given type
 -sub parse_ref {
 -      my $ref_file = shift;
 -      my $ref_id = shift;
 -      my $type = shift || git_get_type($ref_id);
 -      my %ref_item;
 -
 -      $ref_item{'type'} = $type;
 -      $ref_item{'id'} = $ref_id;
 -      $ref_item{'epoch'} = 0;
 -      $ref_item{'age'} = "unknown";
 -      if ($type eq "tag") {
 -              my %tag = parse_tag($ref_id);
 -              $ref_item{'comment'} = $tag{'comment'};
 -              if ($tag{'type'} eq "commit") {
 -                      my %co = parse_commit($tag{'object'});
 -                      $ref_item{'epoch'} = $co{'committer_epoch'};
 -                      $ref_item{'age'} = $co{'age_string'};
 -              } elsif (defined($tag{'epoch'})) {
 -                      my $age = time - $tag{'epoch'};
 -                      $ref_item{'epoch'} = $tag{'epoch'};
 -                      $ref_item{'age'} = age_string($age);
 -              }
 -              $ref_item{'reftype'} = $tag{'type'};
 -              $ref_item{'name'} = $tag{'name'};
 -              $ref_item{'refid'} = $tag{'object'};
 -      } elsif ($type eq "commit"){
 -              my %co = parse_commit($ref_id);
 -              $ref_item{'reftype'} = "commit";
 -              $ref_item{'name'} = $ref_file;
 -              $ref_item{'title'} = $co{'title'};
 -              $ref_item{'refid'} = $ref_id;
 -              $ref_item{'epoch'} = $co{'committer_epoch'};
 -              $ref_item{'age'} = $co{'age_string'};
 -      } else {
 -              $ref_item{'reftype'} = $type;
 -              $ref_item{'name'} = $ref_file;
 -              $ref_item{'refid'} = $ref_id;
 -      }
 -
 -      return %ref_item;
 -}
 -
  # parse line of git-diff-tree "raw" output
  sub parse_difftree_raw_line {
        my $line = shift;
@@@ -4113,7 -4152,7 +4113,7 @@@ sub git_tag 
        git_footer_html();
  }
  
- sub git_blame2 {
+ sub git_blame {
        my $fd;
        my $ftype;
  
        git_footer_html();
  }
  
- sub git_blame {
-       my $fd;
-       my ($have_blame) = gitweb_check_feature('blame');
-       if (!$have_blame) {
-               die_error('403 Permission denied', "Permission denied");
-       }
-       die_error('404 Not Found', "File name not defined") if (!$file_name);
-       $hash_base ||= git_get_head_hash($project);
-       die_error(undef, "Couldn't find base commit") unless ($hash_base);
-       my %co = parse_commit($hash_base)
-               or die_error(undef, "Reading commit failed");
-       if (!defined $hash) {
-               $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
-                       or die_error(undef, "Error lookup file");
-       }
-       open ($fd, "-|", git_cmd(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
-               or die_error(undef, "Open git-annotate failed");
-       git_header_html();
-       my $formats_nav =
-               $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
-                       "blob") .
-               " | " .
-               $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
-                       "history") .
-               " | " .
-               $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
-                       "HEAD");
-       git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
-       git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
-       git_print_page_path($file_name, 'blob', $hash_base);
-       print "<div class=\"page_body\">\n";
-       print <<HTML;
- <table class="blame">
-   <tr>
-     <th>Commit</th>
-     <th>Age</th>
-     <th>Author</th>
-     <th>Line</th>
-     <th>Data</th>
-   </tr>
- HTML
-       my @line_class = (qw(light dark));
-       my $line_class_len = scalar (@line_class);
-       my $line_class_num = $#line_class;
-       while (my $line = <$fd>) {
-               my $long_rev;
-               my $short_rev;
-               my $author;
-               my $time;
-               my $lineno;
-               my $data;
-               my $age;
-               my $age_str;
-               my $age_class;
-               chomp $line;
-               $line_class_num = ($line_class_num + 1) % $line_class_len;
-               if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
-                       $long_rev = $1;
-                       $author   = $2;
-                       $time     = $3;
-                       $lineno   = $4;
-                       $data     = $5;
-               } else {
-                       print qq(  <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
-                       next;
-               }
-               $short_rev  = substr ($long_rev, 0, 8);
-               $age        = time () - $time;
-               $age_str    = age_string ($age);
-               $age_str    =~ s/ /&nbsp;/g;
-               $age_class  = age_class($age);
-               $author     = esc_html ($author);
-               $author     =~ s/ /&nbsp;/g;
-               $data = untabify($data);
-               $data = esc_html ($data);
-               print <<HTML;
-   <tr class="$line_class[$line_class_num]">
-     <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
-     <td class="$age_class">$age_str</td>
-     <td>$author</td>
-     <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
-     <td class="pre">$data</td>
-   </tr>
- HTML
-       } # while (my $line = <$fd>)
-       print "</table>\n\n";
-       close $fd
-               or print "Reading blob failed.\n";
-       print "</div>";
-       git_footer_html();
- }
  sub git_tags {
        my $head = git_get_head_hash($project);
        git_header_html();
@@@ -4594,6 -4536,7 +4497,6 @@@ sub git_snapshot 
                $hash = git_get_head_hash($project);
        }
  
 -      my $git_command = git_cmd_str();
        my $name = $project;
        $name =~ s,([^/])/*\.git$,$1,;
        $name = basename($name);
        $name =~ s/\047/\047\\\047\047/g;
        my $cmd;
        $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
 -      $cmd = "$git_command archive " .
 -              "--format=$known_snapshot_formats{$format}{'format'} " .
 -              "--prefix=\'$name\'/ $hash";
 +      $cmd = quote_command(
 +              git_cmd(), 'archive',
 +              "--format=$known_snapshot_formats{$format}{'format'}",
 +              "--prefix=$name/", $hash);
        if (exists $known_snapshot_formats{$format}{'compressor'}) {
 -              $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
 +              $cmd .= ' | ' . quote_command(@{$known_snapshot_formats{$format}{'compressor'}});
        }
  
        print $cgi->header(
@@@ -4819,8 -4761,8 +4722,8 @@@ sub git_object 
        if ($hash || ($hash_base && !defined $file_name)) {
                my $object_id = $hash || $hash_base;
  
 -              my $git_command = git_cmd_str();
 -              open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
 +              open my $fd, "-|", quote_command(
 +                      git_cmd(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
                        or die_error('404 Not Found', "Object does not exist");
                $type = <$fd>;
                chomp $type;