Kay Sievers | 161332a | 2005-08-07 19:49:46 +0200 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 3 | # gitweb - simple web interface to track changes in git repositories |
Kay Sievers | 22fafb9 | 2005-08-07 19:56:59 +0200 | [diff] [blame] | 4 | # |
Kay Sievers | 00cd079 | 2006-05-22 14:30:47 +0200 | [diff] [blame] | 5 | # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org> |
| 6 | # (C) 2005, Christian Gierke |
Kay Sievers | 823d5dc | 2005-08-07 19:57:58 +0200 | [diff] [blame] | 7 | # |
Kay Sievers | d8f1c5c | 2005-10-04 01:12:47 +0200 | [diff] [blame] | 8 | # This program is licensed under the GPLv2 |
Kay Sievers | 161332a | 2005-08-07 19:49:46 +0200 | [diff] [blame] | 9 | |
Ævar Arnfjörð Bjarmason | d48b284 | 2010-09-24 20:00:52 +0000 | [diff] [blame] | 10 | use 5.008; |
Kay Sievers | 161332a | 2005-08-07 19:49:46 +0200 | [diff] [blame] | 11 | use strict; |
| 12 | use warnings; |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 13 | use CGI qw(:standard :escapeHTML -nosticky); |
Kay Sievers | 7403d50 | 2005-08-07 20:23:49 +0200 | [diff] [blame] | 14 | use CGI::Util qw(unescape); |
Jakub Narebski | 7a59745 | 2010-04-24 16:00:04 +0200 | [diff] [blame] | 15 | use CGI::Carp qw(fatalsToBrowser set_message); |
Kay Sievers | 40c1381 | 2005-11-19 17:41:29 +0100 | [diff] [blame] | 16 | use Encode; |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 17 | use Fcntl ':mode'; |
Junio C Hamano | 7a13b99 | 2006-07-31 19:18:34 -0700 | [diff] [blame] | 18 | use File::Find qw(); |
Aneesh Kumar K.V | cb9c6e5 | 2006-08-17 20:59:46 +0530 | [diff] [blame] | 19 | use File::Basename qw(basename); |
Kay Sievers | 10bb903 | 2005-11-23 04:26:40 +0100 | [diff] [blame] | 20 | binmode STDOUT, ':utf8'; |
Kay Sievers | 161332a | 2005-08-07 19:49:46 +0200 | [diff] [blame] | 21 | |
Jakub Narebski | aa7dd05 | 2009-09-01 13:39:16 +0200 | [diff] [blame] | 22 | our $t0; |
| 23 | if (eval { require Time::HiRes; 1; }) { |
| 24 | $t0 = [Time::HiRes::gettimeofday()]; |
| 25 | } |
| 26 | our $number_of_git_cmds = 0; |
| 27 | |
Jakub Narebski | b1f5f64 | 2006-12-28 00:00:52 +0100 | [diff] [blame] | 28 | BEGIN { |
Jakub Narebski | 3be8e72 | 2007-04-01 22:22:21 +0200 | [diff] [blame] | 29 | CGI->compile() if $ENV{'MOD_PERL'}; |
Jakub Narebski | b1f5f64 | 2006-12-28 00:00:52 +0100 | [diff] [blame] | 30 | } |
| 31 | |
Junio C Hamano | 06c084d | 2006-08-02 13:50:20 -0700 | [diff] [blame] | 32 | our $version = "++GIT_VERSION++"; |
Kay Sievers | 44ad297 | 2005-08-07 19:59:24 +0200 | [diff] [blame] | 33 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 34 | our ($my_url, $my_uri, $base_url, $path_info, $home_link); |
| 35 | sub evaluate_uri { |
| 36 | our $cgi; |
Giuseppe Bilotta | 81d3fe9 | 2009-02-15 10:18:36 +0100 | [diff] [blame] | 37 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 38 | our $my_url = $cgi->url(); |
| 39 | our $my_uri = $cgi->url(-absolute => 1); |
| 40 | |
| 41 | # Base URL for relative URLs in gitweb ($logo, $favicon, ...), |
| 42 | # needed and used only for URLs with nonempty PATH_INFO |
| 43 | our $base_url = $my_url; |
| 44 | |
| 45 | # When the script is used as DirectoryIndex, the URL does not contain the name |
| 46 | # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we |
| 47 | # have to do it ourselves. We make $path_info global because it's also used |
| 48 | # later on. |
| 49 | # |
| 50 | # Another issue with the script being the DirectoryIndex is that the resulting |
| 51 | # $my_url data is not the full script URL: this is good, because we want |
| 52 | # generated links to keep implying the script name if it wasn't explicitly |
| 53 | # indicated in the URL we're handling, but it means that $my_url cannot be used |
| 54 | # as base URL. |
| 55 | # Therefore, if we needed to strip PATH_INFO, then we know that we have |
| 56 | # to build the base URL ourselves: |
| 57 | our $path_info = $ENV{"PATH_INFO"}; |
| 58 | if ($path_info) { |
| 59 | if ($my_url =~ s,\Q$path_info\E$,, && |
| 60 | $my_uri =~ s,\Q$path_info\E$,, && |
| 61 | defined $ENV{'SCRIPT_NAME'}) { |
| 62 | $base_url = $cgi->url(-base => 1) . $ENV{'SCRIPT_NAME'}; |
| 63 | } |
Giuseppe Bilotta | 81d3fe9 | 2009-02-15 10:18:36 +0100 | [diff] [blame] | 64 | } |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 65 | |
| 66 | # target of the home link on top of all pages |
| 67 | our $home_link = $my_uri || "/"; |
Giuseppe Bilotta | b65910f | 2008-09-29 15:07:42 +0200 | [diff] [blame] | 68 | } |
| 69 | |
Alp Toker | e130dda | 2006-07-12 23:55:10 +0100 | [diff] [blame] | 70 | # core git executable to use |
| 71 | # this can just be "git" if your webserver has a sensible PATH |
Junio C Hamano | 06c084d | 2006-08-02 13:50:20 -0700 | [diff] [blame] | 72 | our $GIT = "++GIT_BINDIR++/git"; |
Jakub Narebski | 3f7f2710 | 2006-06-21 09:48:04 +0200 | [diff] [blame] | 73 | |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 74 | # absolute fs-path which will be prepended to the project path |
Dennis Stosberg | 4a87b43 | 2006-06-21 15:07:08 +0200 | [diff] [blame] | 75 | #our $projectroot = "/pub/scm"; |
Junio C Hamano | 06c084d | 2006-08-02 13:50:20 -0700 | [diff] [blame] | 76 | our $projectroot = "++GITWEB_PROJECTROOT++"; |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 77 | |
Luke Lu | ca5e949 | 2007-10-16 20:45:25 -0700 | [diff] [blame] | 78 | # fs traversing limit for getting project list |
| 79 | # the number is relative to the projectroot |
| 80 | our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++"; |
| 81 | |
Yasushi SHOJI | 2de21fa | 2006-08-15 07:50:49 +0900 | [diff] [blame] | 82 | # string of the home link on top of all pages |
| 83 | our $home_link_str = "++GITWEB_HOME_LINK_STR++"; |
| 84 | |
Alp Toker | 49da1da | 2006-07-11 21:10:26 +0100 | [diff] [blame] | 85 | # name of your site or organization to appear in page titles |
| 86 | # replace this with something more descriptive for clearer bookmarks |
Petr Baudis | 8be2890 | 2006-10-24 05:18:39 +0200 | [diff] [blame] | 87 | our $site_name = "++GITWEB_SITENAME++" |
| 88 | || ($ENV{'SERVER_NAME'} || "Untitled") . " Git"; |
Alp Toker | 49da1da | 2006-07-11 21:10:26 +0100 | [diff] [blame] | 89 | |
Alan Chandler | b2d3476 | 2006-10-03 13:49:03 +0100 | [diff] [blame] | 90 | # filename of html text to include at top of each page |
| 91 | our $site_header = "++GITWEB_SITE_HEADER++"; |
Kay Sievers | 8ab1da2 | 2005-08-07 20:22:53 +0200 | [diff] [blame] | 92 | # html text to include at home page |
Junio C Hamano | 06c084d | 2006-08-02 13:50:20 -0700 | [diff] [blame] | 93 | our $home_text = "++GITWEB_HOMETEXT++"; |
Alan Chandler | b2d3476 | 2006-10-03 13:49:03 +0100 | [diff] [blame] | 94 | # filename of html text to include at bottom of each page |
| 95 | our $site_footer = "++GITWEB_SITE_FOOTER++"; |
Kay Sievers | 8ab1da2 | 2005-08-07 20:22:53 +0200 | [diff] [blame] | 96 | |
Alan Chandler | b2d3476 | 2006-10-03 13:49:03 +0100 | [diff] [blame] | 97 | # URI of stylesheets |
| 98 | our @stylesheets = ("++GITWEB_CSS++"); |
Petr Baudis | 887a612 | 2006-10-26 14:41:25 +0200 | [diff] [blame] | 99 | # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. |
| 100 | our $stylesheet = undef; |
Jakub Narebski | 9a7a62f | 2006-10-06 12:31:05 +0200 | [diff] [blame] | 101 | # URI of GIT logo (72x27 size) |
Junio C Hamano | 06c084d | 2006-08-02 13:50:20 -0700 | [diff] [blame] | 102 | our $logo = "++GITWEB_LOGO++"; |
Jakub Narebski | 0b5deba | 2006-09-04 20:32:13 +0200 | [diff] [blame] | 103 | # URI of GIT favicon, assumed to be image/png type |
| 104 | our $favicon = "++GITWEB_FAVICON++"; |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 105 | # URI of gitweb.js (JavaScript code for gitweb) |
| 106 | our $javascript = "++GITWEB_JS++"; |
Jakub Narebski | aedd942 | 2006-06-17 11:23:56 +0200 | [diff] [blame] | 107 | |
Jakub Narebski | 9a7a62f | 2006-10-06 12:31:05 +0200 | [diff] [blame] | 108 | # URI and label (title) of GIT logo link |
| 109 | #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; |
| 110 | #our $logo_label = "git documentation"; |
Wincent Colaiuta | 69fb828 | 2009-07-12 14:31:28 +0200 | [diff] [blame] | 111 | our $logo_url = "http://git-scm.com/"; |
Jakub Narebski | 9a7a62f | 2006-10-06 12:31:05 +0200 | [diff] [blame] | 112 | our $logo_label = "git homepage"; |
Junio C Hamano | 51a7c66 | 2006-09-23 12:36:01 -0700 | [diff] [blame] | 113 | |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 114 | # source of projects list |
Junio C Hamano | 06c084d | 2006-08-02 13:50:20 -0700 | [diff] [blame] | 115 | our $projects_list = "++GITWEB_LIST++"; |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 116 | |
Michael Hendricks | 55feb12 | 2007-07-04 18:36:48 -0600 | [diff] [blame] | 117 | # the width (in characters) of the projects list "Description" column |
| 118 | our $projects_list_description_width = 25; |
| 119 | |
Frank Lichtenheld | b06dcf8 | 2007-04-06 23:58:24 +0200 | [diff] [blame] | 120 | # default order of projects list |
| 121 | # valid values are none, project, descr, owner, and age |
| 122 | our $default_projects_order = "project"; |
| 123 | |
Matthias Lederhofer | 32f4aac | 2006-09-17 00:31:01 +0200 | [diff] [blame] | 124 | # show repository only if this file exists |
| 125 | # (only effective if this variable evaluates to true) |
| 126 | our $export_ok = "++GITWEB_EXPORT_OK++"; |
| 127 | |
Alexander Gavrilov | dd7f5f1 | 2008-11-06 01:36:23 +0300 | [diff] [blame] | 128 | # show repository only if this subroutine returns true |
| 129 | # when given the path to the project, for example: |
| 130 | # sub { return -e "$_[0]/git-daemon-export-ok"; } |
| 131 | our $export_auth_hook = undef; |
| 132 | |
Matthias Lederhofer | 32f4aac | 2006-09-17 00:31:01 +0200 | [diff] [blame] | 133 | # only allow viewing of repositories also shown on the overview page |
| 134 | our $strict_export = "++GITWEB_STRICT_EXPORT++"; |
| 135 | |
Jakub Narebski | 19a8721 | 2006-08-15 23:03:17 +0200 | [diff] [blame] | 136 | # list of git base URLs used for URL to where fetch project from, |
| 137 | # i.e. full URL is "$git_base_url/$project" |
Jakub Narebski | d6b7e0b | 2006-10-26 12:26:44 +0200 | [diff] [blame] | 138 | our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++"); |
Jakub Narebski | 19a8721 | 2006-08-15 23:03:17 +0200 | [diff] [blame] | 139 | |
Jakub Narebski | f5aa79d | 2006-06-17 13:32:15 +0200 | [diff] [blame] | 140 | # default blob_plain mimetype and default charset for text/plain blob |
Dennis Stosberg | 4a87b43 | 2006-06-21 15:07:08 +0200 | [diff] [blame] | 141 | our $default_blob_plain_mimetype = 'text/plain'; |
| 142 | our $default_text_plain_charset = undef; |
Jakub Narebski | f5aa79d | 2006-06-17 13:32:15 +0200 | [diff] [blame] | 143 | |
Petr Baudis | 2d00737 | 2006-06-18 00:01:06 +0200 | [diff] [blame] | 144 | # file to use for guessing MIME types before trying /etc/mime.types |
| 145 | # (relative to the current git repository) |
Dennis Stosberg | 4a87b43 | 2006-06-21 15:07:08 +0200 | [diff] [blame] | 146 | our $mimetypes_file = undef; |
Petr Baudis | 2d00737 | 2006-06-18 00:01:06 +0200 | [diff] [blame] | 147 | |
Martin Koegler | 00f429a | 2007-06-03 17:42:44 +0200 | [diff] [blame] | 148 | # assume this charset if line contains non-UTF-8 characters; |
| 149 | # it should be valid encoding (see Encoding::Supported(3pm) for list), |
| 150 | # for which encoding all byte sequences are valid, for example |
| 151 | # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it |
| 152 | # could be even 'utf-8' for the old behavior) |
| 153 | our $fallback_encoding = 'latin1'; |
| 154 | |
Jakub Narebski | 69a9b41 | 2007-07-20 02:15:09 +0200 | [diff] [blame] | 155 | # rename detection options for git-diff and git-diff-tree |
| 156 | # - default is '-M', with the cost proportional to |
| 157 | # (number of removed files) * (number of new files). |
| 158 | # - more costly is '-C' (which implies '-M'), with the cost proportional to |
| 159 | # (number of changed files + number of removed files) * (number of new files) |
| 160 | # - even more costly is '-C', '--find-copies-harder' with cost |
| 161 | # (number of files in the original tree) * (number of new files) |
| 162 | # - one might want to include '-B' option, e.g. '-B', '-M' |
| 163 | our @diff_opts = ('-M'); # taken from git_commit |
| 164 | |
Matt McCutchen | 7e1100e | 2009-02-07 19:00:09 -0500 | [diff] [blame] | 165 | # Disables features that would allow repository owners to inject script into |
| 166 | # the gitweb domain. |
| 167 | our $prevent_xss = 0; |
| 168 | |
Christopher Wilson | 7ce896b | 2010-09-21 00:25:19 -0700 | [diff] [blame] | 169 | # Path to the highlight executable to use (must be the one from |
| 170 | # http://www.andre-simon.de due to assumptions about parameters and output). |
| 171 | # Useful if highlight is not installed on your webserver's PATH. |
| 172 | # [Default: highlight] |
| 173 | our $highlight_bin = "++HIGHLIGHT_BIN++"; |
| 174 | |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 175 | # information about snapshot formats that gitweb is capable of serving |
| 176 | our %known_snapshot_formats = ( |
| 177 | # name => { |
| 178 | # 'display' => display name, |
| 179 | # 'type' => mime type, |
| 180 | # 'suffix' => filename suffix, |
| 181 | # 'format' => --format for git-archive, |
| 182 | # 'compressor' => [compressor command and arguments] |
Mark A Rada | 1bfd363 | 2009-08-06 10:25:39 -0400 | [diff] [blame] | 183 | # (array reference, optional) |
| 184 | # 'disabled' => boolean (optional)} |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 185 | # |
| 186 | 'tgz' => { |
| 187 | 'display' => 'tar.gz', |
| 188 | 'type' => 'application/x-gzip', |
| 189 | 'suffix' => '.tar.gz', |
| 190 | 'format' => 'tar', |
| 191 | 'compressor' => ['gzip']}, |
| 192 | |
| 193 | 'tbz2' => { |
| 194 | 'display' => 'tar.bz2', |
| 195 | 'type' => 'application/x-bzip2', |
| 196 | 'suffix' => '.tar.bz2', |
| 197 | 'format' => 'tar', |
| 198 | 'compressor' => ['bzip2']}, |
| 199 | |
Mark A Rada | cbdefb5 | 2009-08-06 10:28:25 -0400 | [diff] [blame] | 200 | 'txz' => { |
| 201 | 'display' => 'tar.xz', |
| 202 | 'type' => 'application/x-xz', |
| 203 | 'suffix' => '.tar.xz', |
| 204 | 'format' => 'tar', |
| 205 | 'compressor' => ['xz'], |
| 206 | 'disabled' => 1}, |
| 207 | |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 208 | 'zip' => { |
| 209 | 'display' => 'zip', |
| 210 | 'type' => 'application/x-zip', |
| 211 | 'suffix' => '.zip', |
| 212 | 'format' => 'zip'}, |
| 213 | ); |
| 214 | |
| 215 | # Aliases so we understand old gitweb.snapshot values in repository |
| 216 | # configuration. |
| 217 | our %known_snapshot_format_aliases = ( |
| 218 | 'gzip' => 'tgz', |
| 219 | 'bzip2' => 'tbz2', |
Mark A Rada | cbdefb5 | 2009-08-06 10:28:25 -0400 | [diff] [blame] | 220 | 'xz' => 'txz', |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 221 | |
| 222 | # backward compatibility: legacy gitweb config support |
| 223 | 'x-gzip' => undef, 'gz' => undef, |
| 224 | 'x-bzip2' => undef, 'bz2' => undef, |
| 225 | 'x-zip' => undef, '' => undef, |
| 226 | ); |
| 227 | |
Giuseppe Bilotta | e9fdd74 | 2009-06-30 00:00:51 +0200 | [diff] [blame] | 228 | # Pixel sizes for icons and avatars. If the default font sizes or lineheights |
| 229 | # are changed, it may be appropriate to change these values too via |
| 230 | # $GITWEB_CONFIG. |
| 231 | our %avatar_size = ( |
| 232 | 'default' => 16, |
| 233 | 'double' => 32 |
| 234 | ); |
| 235 | |
John 'Warthog9' Hawley | b62a1a9 | 2010-01-30 23:30:39 +0100 | [diff] [blame] | 236 | # Used to set the maximum load that we will still respond to gitweb queries. |
| 237 | # If server load exceed this value then return "503 server busy" error. |
| 238 | # If gitweb cannot determined server load, it is taken to be 0. |
| 239 | # Leave it undefined (or set to 'undef') to turn off load checking. |
| 240 | our $maxload = 300; |
| 241 | |
Alejandro R. Sedeño | 61bf126 | 2010-07-28 14:40:53 -0400 | [diff] [blame] | 242 | # configuration for 'highlight' (http://www.andre-simon.de/) |
| 243 | # match by basename |
| 244 | our %highlight_basename = ( |
| 245 | #'Program' => 'py', |
| 246 | #'Library' => 'py', |
| 247 | 'SConstruct' => 'py', # SCons equivalent of Makefile |
| 248 | 'Makefile' => 'make', |
| 249 | ); |
| 250 | # match by extension |
| 251 | our %highlight_ext = ( |
| 252 | # main extensions, defining name of syntax; |
| 253 | # see files in /usr/share/highlight/langDefs/ directory |
| 254 | map { $_ => $_ } |
| 255 | qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl), |
| 256 | # alternate extensions, see /etc/highlight/filetypes.conf |
| 257 | 'h' => 'c', |
| 258 | map { $_ => 'cpp' } qw(cxx c++ cc), |
| 259 | map { $_ => 'php' } qw(php3 php4), |
| 260 | map { $_ => 'pl' } qw(perl pm), # perhaps also 'cgi' |
| 261 | 'mak' => 'make', |
| 262 | map { $_ => 'xml' } qw(xhtml html htm), |
| 263 | ); |
| 264 | |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 265 | # You define site-wide feature defaults here; override them with |
| 266 | # $GITWEB_CONFIG as necessary. |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 267 | our %feature = ( |
Jakub Narebski | 17848fc | 2006-08-26 19:14:22 +0200 | [diff] [blame] | 268 | # feature => { |
| 269 | # 'sub' => feature-sub (subroutine), |
| 270 | # 'override' => allow-override (boolean), |
| 271 | # 'default' => [ default options...] (array reference)} |
| 272 | # |
Jakub Narebski | b4b20b2 | 2007-05-15 01:55:44 +0200 | [diff] [blame] | 273 | # if feature is overridable (it means that allow-override has true value), |
Jakub Narebski | 17848fc | 2006-08-26 19:14:22 +0200 | [diff] [blame] | 274 | # then feature-sub will be called with default options as parameters; |
| 275 | # return value of feature-sub indicates if to enable specified feature |
| 276 | # |
Jakub Narebski | b4b20b2 | 2007-05-15 01:55:44 +0200 | [diff] [blame] | 277 | # if there is no 'sub' key (no feature-sub), then feature cannot be |
Ralf Wildenhues | 22e5e58 | 2010-08-22 13:12:12 +0200 | [diff] [blame] | 278 | # overridden |
Jakub Narebski | b4b20b2 | 2007-05-15 01:55:44 +0200 | [diff] [blame] | 279 | # |
Giuseppe Bilotta | ff3c0ff | 2008-12-02 14:57:28 -0800 | [diff] [blame] | 280 | # use gitweb_get_feature(<feature>) to retrieve the <feature> value |
| 281 | # (an array) or gitweb_check_feature(<feature>) to check if <feature> |
| 282 | # is enabled |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 283 | |
Petr Baudis | 45a3b12 | 2006-10-07 15:17:47 +0200 | [diff] [blame] | 284 | # Enable the 'blame' blob view, showing the last commit that modified |
| 285 | # each line in the file. This can be very CPU-intensive. |
| 286 | |
| 287 | # To enable system wide have in $GITWEB_CONFIG |
| 288 | # $feature{'blame'}{'default'} = [1]; |
| 289 | # To have project specific config enable override in $GITWEB_CONFIG |
| 290 | # $feature{'blame'}{'override'} = 1; |
| 291 | # and in project config gitweb.blame = 0|1; |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 292 | 'blame' => { |
Matt Kraai | cdad817 | 2008-12-15 22:16:19 -0800 | [diff] [blame] | 293 | 'sub' => sub { feature_bool('blame', @_) }, |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 294 | 'override' => 0, |
| 295 | 'default' => [0]}, |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 296 | |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 297 | # Enable the 'snapshot' link, providing a compressed archive of any |
Petr Baudis | 45a3b12 | 2006-10-07 15:17:47 +0200 | [diff] [blame] | 298 | # tree. This can potentially generate high traffic if you have large |
| 299 | # project. |
| 300 | |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 301 | # Value is a list of formats defined in %known_snapshot_formats that |
| 302 | # you wish to offer. |
Petr Baudis | 45a3b12 | 2006-10-07 15:17:47 +0200 | [diff] [blame] | 303 | # To disable system wide have in $GITWEB_CONFIG |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 304 | # $feature{'snapshot'}{'default'} = []; |
Petr Baudis | 45a3b12 | 2006-10-07 15:17:47 +0200 | [diff] [blame] | 305 | # To have project specific config enable override in $GITWEB_CONFIG |
Uwe Zeisberger | bbee1d9 | 2006-12-08 12:44:31 +0100 | [diff] [blame] | 306 | # $feature{'snapshot'}{'override'} = 1; |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 307 | # and in project config, a comma-separated list of formats or "none" |
| 308 | # to disable. Example: gitweb.snapshot = tbz2,zip; |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 309 | 'snapshot' => { |
| 310 | 'sub' => \&feature_snapshot, |
| 311 | 'override' => 0, |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 312 | 'default' => ['tgz']}, |
Jakub Narebski | 04f7a94 | 2006-09-11 00:29:27 +0200 | [diff] [blame] | 313 | |
Robert Fitzsimons | 6be9351 | 2006-12-23 03:35:16 +0000 | [diff] [blame] | 314 | # Enable text search, which will list the commits which match author, |
| 315 | # committer or commit text to a given string. Enabled by default. |
Jakub Narebski | b4b20b2 | 2007-05-15 01:55:44 +0200 | [diff] [blame] | 316 | # Project specific override is not supported. |
Robert Fitzsimons | 6be9351 | 2006-12-23 03:35:16 +0000 | [diff] [blame] | 317 | 'search' => { |
| 318 | 'override' => 0, |
| 319 | 'default' => [1]}, |
| 320 | |
Petr Baudis | e773855 | 2007-05-17 04:31:12 +0200 | [diff] [blame] | 321 | # Enable grep search, which will list the files in currently selected |
| 322 | # tree containing the given string. Enabled by default. This can be |
| 323 | # potentially CPU-intensive, of course. |
| 324 | |
| 325 | # To enable system wide have in $GITWEB_CONFIG |
| 326 | # $feature{'grep'}{'default'} = [1]; |
| 327 | # To have project specific config enable override in $GITWEB_CONFIG |
| 328 | # $feature{'grep'}{'override'} = 1; |
| 329 | # and in project config gitweb.grep = 0|1; |
| 330 | 'grep' => { |
Matt Kraai | cdad817 | 2008-12-15 22:16:19 -0800 | [diff] [blame] | 331 | 'sub' => sub { feature_bool('grep', @_) }, |
Petr Baudis | e773855 | 2007-05-17 04:31:12 +0200 | [diff] [blame] | 332 | 'override' => 0, |
| 333 | 'default' => [1]}, |
| 334 | |
Petr Baudis | 45a3b12 | 2006-10-07 15:17:47 +0200 | [diff] [blame] | 335 | # Enable the pickaxe search, which will list the commits that modified |
| 336 | # a given string in a file. This can be practical and quite faster |
| 337 | # alternative to 'blame', but still potentially CPU-intensive. |
| 338 | |
| 339 | # To enable system wide have in $GITWEB_CONFIG |
| 340 | # $feature{'pickaxe'}{'default'} = [1]; |
| 341 | # To have project specific config enable override in $GITWEB_CONFIG |
| 342 | # $feature{'pickaxe'}{'override'} = 1; |
| 343 | # and in project config gitweb.pickaxe = 0|1; |
Jakub Narebski | 04f7a94 | 2006-09-11 00:29:27 +0200 | [diff] [blame] | 344 | 'pickaxe' => { |
Matt Kraai | cdad817 | 2008-12-15 22:16:19 -0800 | [diff] [blame] | 345 | 'sub' => sub { feature_bool('pickaxe', @_) }, |
Jakub Narebski | 04f7a94 | 2006-09-11 00:29:27 +0200 | [diff] [blame] | 346 | 'override' => 0, |
| 347 | 'default' => [1]}, |
Martin Waitz | 9e75690 | 2006-10-01 23:57:48 +0200 | [diff] [blame] | 348 | |
Jakub Narebski | e4b48ea | 2009-09-07 14:40:00 +0200 | [diff] [blame] | 349 | # Enable showing size of blobs in a 'tree' view, in a separate |
| 350 | # column, similar to what 'ls -l' does. This cost a bit of IO. |
| 351 | |
| 352 | # To disable system wide have in $GITWEB_CONFIG |
| 353 | # $feature{'show-sizes'}{'default'} = [0]; |
| 354 | # To have project specific config enable override in $GITWEB_CONFIG |
| 355 | # $feature{'show-sizes'}{'override'} = 1; |
| 356 | # and in project config gitweb.showsizes = 0|1; |
| 357 | 'show-sizes' => { |
| 358 | 'sub' => sub { feature_bool('showsizes', @_) }, |
| 359 | 'override' => 0, |
| 360 | 'default' => [1]}, |
| 361 | |
Petr Baudis | 45a3b12 | 2006-10-07 15:17:47 +0200 | [diff] [blame] | 362 | # Make gitweb use an alternative format of the URLs which can be |
| 363 | # more readable and natural-looking: project name is embedded |
| 364 | # directly in the path and the query string contains other |
| 365 | # auxiliary information. All gitweb installations recognize |
| 366 | # URL in either format; this configures in which formats gitweb |
| 367 | # generates links. |
| 368 | |
| 369 | # To enable system wide have in $GITWEB_CONFIG |
| 370 | # $feature{'pathinfo'}{'default'} = [1]; |
| 371 | # Project specific override is not supported. |
| 372 | |
| 373 | # Note that you will need to change the default location of CSS, |
| 374 | # favicon, logo and possibly other files to an absolute URL. Also, |
| 375 | # if gitweb.cgi serves as your indexfile, you will need to force |
| 376 | # $my_uri to contain the script name in your $GITWEB_CONFIG. |
Martin Waitz | 9e75690 | 2006-10-01 23:57:48 +0200 | [diff] [blame] | 377 | 'pathinfo' => { |
| 378 | 'override' => 0, |
| 379 | 'default' => [0]}, |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 380 | |
| 381 | # Make gitweb consider projects in project root subdirectories |
| 382 | # to be forks of existing projects. Given project $projname.git, |
| 383 | # projects matching $projname/*.git will not be shown in the main |
| 384 | # projects list, instead a '+' mark will be added to $projname |
| 385 | # there and a 'forks' view will be enabled for the project, listing |
Frank Lichtenheld | c2b8b13 | 2007-04-06 23:58:11 +0200 | [diff] [blame] | 386 | # all the forks. If project list is taken from a file, forks have |
| 387 | # to be listed after the main project. |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 388 | |
| 389 | # To enable system wide have in $GITWEB_CONFIG |
| 390 | # $feature{'forks'}{'default'} = [1]; |
| 391 | # Project specific override is not supported. |
| 392 | 'forks' => { |
| 393 | 'override' => 0, |
| 394 | 'default' => [0]}, |
Petr Baudis | d627f68 | 2008-10-02 16:36:52 +0200 | [diff] [blame] | 395 | |
| 396 | # Insert custom links to the action bar of all project pages. |
| 397 | # This enables you mainly to link to third-party scripts integrating |
| 398 | # into gitweb; e.g. git-browser for graphical history representation |
| 399 | # or custom web-based repository administration interface. |
| 400 | |
| 401 | # The 'default' value consists of a list of triplets in the form |
| 402 | # (label, link, position) where position is the label after which |
Jakub Narebski | 2b11e05 | 2008-10-12 00:02:32 +0200 | [diff] [blame] | 403 | # to insert the link and link is a format string where %n expands |
Petr Baudis | d627f68 | 2008-10-02 16:36:52 +0200 | [diff] [blame] | 404 | # to the project name, %f to the project path within the filesystem, |
| 405 | # %h to the current hash (h gitweb parameter) and %b to the current |
Jakub Narebski | 2b11e05 | 2008-10-12 00:02:32 +0200 | [diff] [blame] | 406 | # hash base (hb gitweb parameter); %% expands to %. |
Petr Baudis | d627f68 | 2008-10-02 16:36:52 +0200 | [diff] [blame] | 407 | |
| 408 | # To enable system wide have in $GITWEB_CONFIG e.g. |
| 409 | # $feature{'actions'}{'default'} = [('graphiclog', |
| 410 | # '/git-browser/by-commit.html?r=%n', 'summary')]; |
| 411 | # Project specific override is not supported. |
| 412 | 'actions' => { |
| 413 | 'override' => 0, |
| 414 | 'default' => []}, |
Shawn O. Pearce | 3e3d4ee | 2008-10-03 07:41:25 -0700 | [diff] [blame] | 415 | |
Petr Baudis | aed93de | 2008-10-02 17:13:02 +0200 | [diff] [blame] | 416 | # Allow gitweb scan project content tags described in ctags/ |
| 417 | # of project repository, and display the popular Web 2.0-ish |
| 418 | # "tag cloud" near the project list. Note that this is something |
| 419 | # COMPLETELY different from the normal Git tags. |
| 420 | |
| 421 | # gitweb by itself can show existing tags, but it does not handle |
| 422 | # tagging itself; you need an external application for that. |
| 423 | # For an example script, check Girocco's cgi/tagproj.cgi. |
| 424 | # You may want to install the HTML::TagCloud Perl module to get |
| 425 | # a pretty tag cloud instead of just a list of tags. |
| 426 | |
| 427 | # To enable system wide have in $GITWEB_CONFIG |
| 428 | # $feature{'ctags'}{'default'} = ['path_to_tag_script']; |
| 429 | # Project specific override is not supported. |
| 430 | 'ctags' => { |
| 431 | 'override' => 0, |
| 432 | 'default' => [0]}, |
Giuseppe Bilotta | 9872cd6 | 2008-12-18 08:13:16 +0100 | [diff] [blame] | 433 | |
| 434 | # The maximum number of patches in a patchset generated in patch |
| 435 | # view. Set this to 0 or undef to disable patch view, or to a |
| 436 | # negative number to remove any limit. |
| 437 | |
| 438 | # To disable system wide have in $GITWEB_CONFIG |
| 439 | # $feature{'patches'}{'default'} = [0]; |
| 440 | # To have project specific config enable override in $GITWEB_CONFIG |
| 441 | # $feature{'patches'}{'override'} = 1; |
| 442 | # and in project config gitweb.patches = 0|n; |
| 443 | # where n is the maximum number of patches allowed in a patchset. |
| 444 | 'patches' => { |
| 445 | 'sub' => \&feature_patches, |
| 446 | 'override' => 0, |
| 447 | 'default' => [16]}, |
Giuseppe Bilotta | e9fdd74 | 2009-06-30 00:00:51 +0200 | [diff] [blame] | 448 | |
| 449 | # Avatar support. When this feature is enabled, views such as |
| 450 | # shortlog or commit will display an avatar associated with |
| 451 | # the email of the committer(s) and/or author(s). |
| 452 | |
Giuseppe Bilotta | 679a1a1 | 2009-06-30 00:00:53 +0200 | [diff] [blame] | 453 | # Currently available providers are gravatar and picon. |
| 454 | # If an unknown provider is specified, the feature is disabled. |
| 455 | |
| 456 | # Gravatar depends on Digest::MD5. |
| 457 | # Picon currently relies on the indiana.edu database. |
Giuseppe Bilotta | e9fdd74 | 2009-06-30 00:00:51 +0200 | [diff] [blame] | 458 | |
| 459 | # To enable system wide have in $GITWEB_CONFIG |
Giuseppe Bilotta | 679a1a1 | 2009-06-30 00:00:53 +0200 | [diff] [blame] | 460 | # $feature{'avatar'}{'default'} = ['<provider>']; |
| 461 | # where <provider> is either gravatar or picon. |
Giuseppe Bilotta | e9fdd74 | 2009-06-30 00:00:51 +0200 | [diff] [blame] | 462 | # To have project specific config enable override in $GITWEB_CONFIG |
| 463 | # $feature{'avatar'}{'override'} = 1; |
Giuseppe Bilotta | 679a1a1 | 2009-06-30 00:00:53 +0200 | [diff] [blame] | 464 | # and in project config gitweb.avatar = <provider>; |
Giuseppe Bilotta | e9fdd74 | 2009-06-30 00:00:51 +0200 | [diff] [blame] | 465 | 'avatar' => { |
| 466 | 'sub' => \&feature_avatar, |
| 467 | 'override' => 0, |
| 468 | 'default' => ['']}, |
Jakub Narebski | aa7dd05 | 2009-09-01 13:39:16 +0200 | [diff] [blame] | 469 | |
| 470 | # Enable displaying how much time and how many git commands |
| 471 | # it took to generate and display page. Disabled by default. |
| 472 | # Project specific override is not supported. |
| 473 | 'timed' => { |
| 474 | 'override' => 0, |
| 475 | 'default' => [0]}, |
Jakub Narebski | e627e50 | 2009-11-26 21:12:15 +0100 | [diff] [blame] | 476 | |
| 477 | # Enable turning some links into links to actions which require |
| 478 | # JavaScript to run (like 'blame_incremental'). Not enabled by |
| 479 | # default. Project specific override is currently not supported. |
| 480 | 'javascript-actions' => { |
| 481 | 'override' => 0, |
| 482 | 'default' => [0]}, |
Johannes Schindelin | b331fe5 | 2010-04-27 21:34:44 +0200 | [diff] [blame] | 483 | |
| 484 | # Syntax highlighting support. This is based on Daniel Svensson's |
| 485 | # and Sham Chukoury's work in gitweb-xmms2.git. |
Jakub Narebski | 592ea41 | 2010-04-27 21:34:45 +0200 | [diff] [blame] | 486 | # It requires the 'highlight' program present in $PATH, |
| 487 | # and therefore is disabled by default. |
Johannes Schindelin | b331fe5 | 2010-04-27 21:34:44 +0200 | [diff] [blame] | 488 | |
| 489 | # To enable system wide have in $GITWEB_CONFIG |
| 490 | # $feature{'highlight'}{'default'} = [1]; |
| 491 | |
| 492 | 'highlight' => { |
| 493 | 'sub' => sub { feature_bool('highlight', @_) }, |
| 494 | 'override' => 0, |
| 495 | 'default' => [0]}, |
Giuseppe Bilotta | 60efa24 | 2010-11-11 13:26:09 +0100 | [diff] [blame] | 496 | |
| 497 | # Enable displaying of remote heads in the heads list |
| 498 | |
| 499 | # To enable system wide have in $GITWEB_CONFIG |
| 500 | # $feature{'remote_heads'}{'default'} = [1]; |
| 501 | # To have project specific config enable override in $GITWEB_CONFIG |
| 502 | # $feature{'remote_heads'}{'override'} = 1; |
| 503 | # and in project config gitweb.remote_heads = 0|1; |
| 504 | 'remote_heads' => { |
| 505 | 'sub' => sub { feature_bool('remote_heads', @_) }, |
| 506 | 'override' => 0, |
| 507 | 'default' => [0]}, |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 508 | ); |
| 509 | |
Junio C Hamano | a7c5a28 | 2008-11-29 13:02:08 -0800 | [diff] [blame] | 510 | sub gitweb_get_feature { |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 511 | my ($name) = @_; |
Jakub Narebski | dd1ad5f | 2006-09-26 01:56:17 +0200 | [diff] [blame] | 512 | return unless exists $feature{$name}; |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 513 | my ($sub, $override, @defaults) = ( |
| 514 | $feature{$name}{'sub'}, |
| 515 | $feature{$name}{'override'}, |
| 516 | @{$feature{$name}{'default'}}); |
Jakub Narebski | 9be3614 | 2010-03-01 22:51:34 +0100 | [diff] [blame] | 517 | # project specific override is possible only if we have project |
| 518 | our $git_dir; # global variable, declared later |
| 519 | if (!$override || !defined $git_dir) { |
| 520 | return @defaults; |
| 521 | } |
Martin Waitz | a945591 | 2006-10-03 20:07:43 +0200 | [diff] [blame] | 522 | if (!defined $sub) { |
Nanako Shiraishi | 9319789 | 2009-08-28 12:18:49 +0900 | [diff] [blame] | 523 | warn "feature $name is not overridable"; |
Martin Waitz | a945591 | 2006-10-03 20:07:43 +0200 | [diff] [blame] | 524 | return @defaults; |
| 525 | } |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 526 | return $sub->(@defaults); |
| 527 | } |
| 528 | |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 529 | # A wrapper to check if a given feature is enabled. |
| 530 | # With this, you can say |
| 531 | # |
| 532 | # my $bool_feat = gitweb_check_feature('bool_feat'); |
| 533 | # gitweb_check_feature('bool_feat') or somecode; |
| 534 | # |
| 535 | # instead of |
| 536 | # |
| 537 | # my ($bool_feat) = gitweb_get_feature('bool_feat'); |
| 538 | # (gitweb_get_feature('bool_feat'))[0] or somecode; |
| 539 | # |
| 540 | sub gitweb_check_feature { |
| 541 | return (gitweb_get_feature(@_))[0]; |
| 542 | } |
| 543 | |
| 544 | |
Matt Kraai | cdad817 | 2008-12-15 22:16:19 -0800 | [diff] [blame] | 545 | sub feature_bool { |
| 546 | my $key = shift; |
| 547 | my ($val) = git_get_project_config($key, '--bool'); |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 548 | |
Marcel M. Cary | df5d10a | 2009-02-18 14:09:41 +0100 | [diff] [blame] | 549 | if (!defined $val) { |
| 550 | return ($_[0]); |
| 551 | } elsif ($val eq 'true') { |
Matt Kraai | cdad817 | 2008-12-15 22:16:19 -0800 | [diff] [blame] | 552 | return (1); |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 553 | } elsif ($val eq 'false') { |
Matt Kraai | cdad817 | 2008-12-15 22:16:19 -0800 | [diff] [blame] | 554 | return (0); |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 555 | } |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 556 | } |
| 557 | |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 558 | sub feature_snapshot { |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 559 | my (@fmts) = @_; |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 560 | |
| 561 | my ($val) = git_get_project_config('snapshot'); |
| 562 | |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 563 | if ($val) { |
| 564 | @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val); |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 565 | } |
| 566 | |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 567 | return @fmts; |
Luben Tuikov | de9272f | 2006-09-28 16:49:21 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Giuseppe Bilotta | 9872cd6 | 2008-12-18 08:13:16 +0100 | [diff] [blame] | 570 | sub feature_patches { |
| 571 | my @val = (git_get_project_config('patches', '--int')); |
| 572 | |
| 573 | if (@val) { |
| 574 | return @val; |
| 575 | } |
| 576 | |
| 577 | return ($_[0]); |
| 578 | } |
| 579 | |
Giuseppe Bilotta | e9fdd74 | 2009-06-30 00:00:51 +0200 | [diff] [blame] | 580 | sub feature_avatar { |
| 581 | my @val = (git_get_project_config('avatar')); |
| 582 | |
| 583 | return @val ? @val : @_; |
| 584 | } |
| 585 | |
Junio C Hamano | 2172ce4 | 2006-10-03 02:30:47 -0700 | [diff] [blame] | 586 | # checking HEAD file with -e is fragile if the repository was |
| 587 | # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed |
| 588 | # and then pruned. |
| 589 | sub check_head_link { |
| 590 | my ($dir) = @_; |
| 591 | my $headfile = "$dir/HEAD"; |
| 592 | return ((-e $headfile) || |
| 593 | (-l $headfile && readlink($headfile) =~ /^refs\/heads\//)); |
| 594 | } |
| 595 | |
| 596 | sub check_export_ok { |
| 597 | my ($dir) = @_; |
| 598 | return (check_head_link($dir) && |
Alexander Gavrilov | dd7f5f1 | 2008-11-06 01:36:23 +0300 | [diff] [blame] | 599 | (!$export_ok || -e "$dir/$export_ok") && |
| 600 | (!$export_auth_hook || $export_auth_hook->($dir))); |
Junio C Hamano | 2172ce4 | 2006-10-03 02:30:47 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Jakub Narebski | a781785 | 2007-07-22 23:41:20 +0200 | [diff] [blame] | 603 | # process alternate names for backward compatibility |
| 604 | # filter out unsupported (unknown) snapshot formats |
| 605 | sub filter_snapshot_fmts { |
| 606 | my @fmts = @_; |
| 607 | |
| 608 | @fmts = map { |
| 609 | exists $known_snapshot_format_aliases{$_} ? |
| 610 | $known_snapshot_format_aliases{$_} : $_} @fmts; |
Jakub Narebski | 68cedb1 | 2009-05-10 02:40:37 +0200 | [diff] [blame] | 611 | @fmts = grep { |
Mark A Rada | 1bfd363 | 2009-08-06 10:25:39 -0400 | [diff] [blame] | 612 | exists $known_snapshot_formats{$_} && |
| 613 | !$known_snapshot_formats{$_}{'disabled'}} @fmts; |
Jakub Narebski | a781785 | 2007-07-22 23:41:20 +0200 | [diff] [blame] | 614 | } |
| 615 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 616 | our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM); |
| 617 | sub evaluate_gitweb_config { |
| 618 | our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++"; |
| 619 | our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++"; |
| 620 | # die if there are errors parsing config file |
| 621 | if (-e $GITWEB_CONFIG) { |
| 622 | do $GITWEB_CONFIG; |
| 623 | die $@ if $@; |
| 624 | } elsif (-e $GITWEB_CONFIG_SYSTEM) { |
| 625 | do $GITWEB_CONFIG_SYSTEM; |
| 626 | die $@ if $@; |
| 627 | } |
Gerrit Pape | 17a8b25 | 2008-03-26 18:11:19 +0000 | [diff] [blame] | 628 | } |
Jeff King | c8d138a | 2006-08-02 15:23:34 -0400 | [diff] [blame] | 629 | |
John 'Warthog9' Hawley | b62a1a9 | 2010-01-30 23:30:39 +0100 | [diff] [blame] | 630 | # Get loadavg of system, to compare against $maxload. |
| 631 | # Currently it requires '/proc/loadavg' present to get loadavg; |
| 632 | # if it is not present it returns 0, which means no load checking. |
| 633 | sub get_loadavg { |
| 634 | if( -e '/proc/loadavg' ){ |
| 635 | open my $fd, '<', '/proc/loadavg' |
| 636 | or return 0; |
| 637 | my @load = split(/\s+/, scalar <$fd>); |
| 638 | close $fd; |
| 639 | |
| 640 | # The first three columns measure CPU and IO utilization of the last one, |
| 641 | # five, and 10 minute periods. The fourth column shows the number of |
| 642 | # currently running processes and the total number of processes in the m/n |
| 643 | # format. The last column displays the last process ID used. |
| 644 | return $load[0] || 0; |
| 645 | } |
| 646 | # additional checks for load average should go here for things that don't export |
| 647 | # /proc/loadavg |
| 648 | |
| 649 | return 0; |
| 650 | } |
| 651 | |
Jeff King | c8d138a | 2006-08-02 15:23:34 -0400 | [diff] [blame] | 652 | # version of the core git binary |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 653 | our $git_version; |
| 654 | sub evaluate_git_version { |
| 655 | our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown"; |
| 656 | $number_of_git_cmds++; |
| 657 | } |
Jeff King | c8d138a | 2006-08-02 15:23:34 -0400 | [diff] [blame] | 658 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 659 | sub check_loadavg { |
| 660 | if (defined $maxload && get_loadavg() > $maxload) { |
| 661 | die_error(503, "The load average on the server is too high"); |
| 662 | } |
John 'Warthog9' Hawley | b62a1a9 | 2010-01-30 23:30:39 +0100 | [diff] [blame] | 663 | } |
| 664 | |
Jakub Narebski | 154b4d7 | 2006-08-05 12:55:20 +0200 | [diff] [blame] | 665 | # ====================================================================== |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 666 | # input validation and dispatch |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 667 | |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 668 | # input parameters can be collected from a variety of sources (presently, CGI |
| 669 | # and PATH_INFO), so we define an %input_params hash that collects them all |
| 670 | # together during validation: this allows subsequent uses (e.g. href()) to be |
| 671 | # agnostic of the parameter origin |
Kay Sievers | 6191f8e | 2005-08-07 20:19:56 +0200 | [diff] [blame] | 672 | |
Alexander Gavrilov | dde80d9 | 2008-11-06 01:10:07 +0300 | [diff] [blame] | 673 | our %input_params = (); |
Martin Waitz | 5c95fab | 2006-08-17 00:28:38 +0200 | [diff] [blame] | 674 | |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 675 | # input parameters are stored with the long parameter name as key. This will |
| 676 | # also be used in the href subroutine to convert parameters to their CGI |
| 677 | # equivalent, and since the href() usage is the most frequent one, we store |
| 678 | # the name -> CGI key mapping here, instead of the reverse. |
| 679 | # |
| 680 | # XXX: Warning: If you touch this, check the search form for updating, |
| 681 | # too. |
Jakub Narebski | 24d0693 | 2006-09-26 01:57:02 +0200 | [diff] [blame] | 682 | |
Alexander Gavrilov | dde80d9 | 2008-11-06 01:10:07 +0300 | [diff] [blame] | 683 | our @cgi_param_mapping = ( |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 684 | project => "p", |
| 685 | action => "a", |
| 686 | file_name => "f", |
| 687 | file_parent => "fp", |
| 688 | hash => "h", |
| 689 | hash_parent => "hp", |
| 690 | hash_base => "hb", |
| 691 | hash_parent_base => "hpb", |
| 692 | page => "pg", |
| 693 | order => "o", |
| 694 | searchtext => "s", |
| 695 | searchtype => "st", |
| 696 | snapshot_format => "sf", |
| 697 | extra_options => "opt", |
| 698 | search_use_regexp => "sr", |
Jakub Narebski | c4ccf61 | 2009-09-01 13:39:19 +0200 | [diff] [blame] | 699 | # this must be last entry (for manipulation from JavaScript) |
| 700 | javascript => "js" |
Miklos Vajna | 868bc06 | 2007-07-12 20:39:27 +0200 | [diff] [blame] | 701 | ); |
Alexander Gavrilov | dde80d9 | 2008-11-06 01:10:07 +0300 | [diff] [blame] | 702 | our %cgi_param_mapping = @cgi_param_mapping; |
Miklos Vajna | 868bc06 | 2007-07-12 20:39:27 +0200 | [diff] [blame] | 703 | |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 704 | # we will also need to know the possible actions, for validation |
Alexander Gavrilov | dde80d9 | 2008-11-06 01:10:07 +0300 | [diff] [blame] | 705 | our %actions = ( |
Rafael Garcia-Suarez | 3a5b919 | 2008-06-06 09:53:32 +0200 | [diff] [blame] | 706 | "blame" => \&git_blame, |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 707 | "blame_incremental" => \&git_blame_incremental, |
| 708 | "blame_data" => \&git_blame_data, |
Matthias Lederhofer | 8e85cdc | 2006-07-31 23:46:25 +0200 | [diff] [blame] | 709 | "blobdiff" => \&git_blobdiff, |
| 710 | "blobdiff_plain" => \&git_blobdiff_plain, |
| 711 | "blob" => \&git_blob, |
| 712 | "blob_plain" => \&git_blob_plain, |
| 713 | "commitdiff" => \&git_commitdiff, |
| 714 | "commitdiff_plain" => \&git_commitdiff_plain, |
| 715 | "commit" => \&git_commit, |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 716 | "forks" => \&git_forks, |
Matthias Lederhofer | 8e85cdc | 2006-07-31 23:46:25 +0200 | [diff] [blame] | 717 | "heads" => \&git_heads, |
| 718 | "history" => \&git_history, |
| 719 | "log" => \&git_log, |
Giuseppe Bilotta | 9872cd6 | 2008-12-18 08:13:16 +0100 | [diff] [blame] | 720 | "patch" => \&git_patch, |
Giuseppe Bilotta | a3411f8 | 2008-12-18 08:13:18 +0100 | [diff] [blame] | 721 | "patches" => \&git_patches, |
Giuseppe Bilotta | 00fa6fe | 2010-11-11 13:26:11 +0100 | [diff] [blame^] | 722 | "remotes" => \&git_remotes, |
Matthias Lederhofer | 8e85cdc | 2006-07-31 23:46:25 +0200 | [diff] [blame] | 723 | "rss" => \&git_rss, |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 724 | "atom" => \&git_atom, |
Matthias Lederhofer | 8e85cdc | 2006-07-31 23:46:25 +0200 | [diff] [blame] | 725 | "search" => \&git_search, |
Petr Baudis | 88ad729 | 2006-10-24 05:15:46 +0200 | [diff] [blame] | 726 | "search_help" => \&git_search_help, |
Matthias Lederhofer | 8e85cdc | 2006-07-31 23:46:25 +0200 | [diff] [blame] | 727 | "shortlog" => \&git_shortlog, |
| 728 | "summary" => \&git_summary, |
| 729 | "tag" => \&git_tag, |
| 730 | "tags" => \&git_tags, |
| 731 | "tree" => \&git_tree, |
Aneesh Kumar K.V | cb9c6e5 | 2006-08-17 20:59:46 +0530 | [diff] [blame] | 732 | "snapshot" => \&git_snapshot, |
Jakub Narebski | ca94601 | 2006-12-10 13:25:47 +0100 | [diff] [blame] | 733 | "object" => \&git_object, |
Jakub Narebski | 77a153f | 2006-08-22 16:59:20 +0200 | [diff] [blame] | 734 | # those below don't need $project |
| 735 | "opml" => \&git_opml, |
| 736 | "project_list" => \&git_project_list, |
Jakub Narebski | fc2b2be | 2006-09-15 04:56:03 +0200 | [diff] [blame] | 737 | "project_index" => \&git_project_index, |
Matthias Lederhofer | 8e85cdc | 2006-07-31 23:46:25 +0200 | [diff] [blame] | 738 | ); |
| 739 | |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 740 | # finally, we have the hash of allowed extra_options for the commands that |
| 741 | # allow them |
Alexander Gavrilov | dde80d9 | 2008-11-06 01:10:07 +0300 | [diff] [blame] | 742 | our %allowed_options = ( |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 743 | "--no-merges" => [ qw(rss atom log shortlog history) ], |
| 744 | ); |
| 745 | |
| 746 | # fill %input_params with the CGI parameters. All values except for 'opt' |
| 747 | # should be single values, but opt can be an array. We should probably |
| 748 | # build an array of parameters that can be multi-valued, but since for the time |
| 749 | # being it's only this one, we just single it out |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 750 | sub evaluate_query_params { |
| 751 | our $cgi; |
| 752 | |
| 753 | while (my ($name, $symbol) = each %cgi_param_mapping) { |
| 754 | if ($symbol eq 'opt') { |
| 755 | $input_params{$name} = [ $cgi->param($symbol) ]; |
| 756 | } else { |
| 757 | $input_params{$name} = $cgi->param($symbol); |
| 758 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 759 | } |
| 760 | } |
| 761 | |
| 762 | # now read PATH_INFO and update the parameter list for missing parameters |
| 763 | sub evaluate_path_info { |
| 764 | return if defined $input_params{'project'}; |
| 765 | return if !$path_info; |
| 766 | $path_info =~ s,^/+,,; |
| 767 | return if !$path_info; |
| 768 | |
| 769 | # find which part of PATH_INFO is project |
| 770 | my $project = $path_info; |
| 771 | $project =~ s,/+$,,; |
| 772 | while ($project && !check_head_link("$projectroot/$project")) { |
| 773 | $project =~ s,/*[^/]*$,,; |
| 774 | } |
| 775 | return unless $project; |
| 776 | $input_params{'project'} = $project; |
| 777 | |
| 778 | # do not change any parameters if an action is given using the query string |
| 779 | return if $input_params{'action'}; |
| 780 | $path_info =~ s,^\Q$project\E/*,,; |
| 781 | |
Giuseppe Bilotta | d8c2882 | 2008-10-21 21:34:50 +0200 | [diff] [blame] | 782 | # next, check if we have an action |
| 783 | my $action = $path_info; |
| 784 | $action =~ s,/.*$,,; |
| 785 | if (exists $actions{$action}) { |
| 786 | $path_info =~ s,^$action/*,,; |
| 787 | $input_params{'action'} = $action; |
| 788 | } |
| 789 | |
| 790 | # list of actions that want hash_base instead of hash, but can have no |
| 791 | # pathname (f) parameter |
| 792 | my @wants_base = ( |
| 793 | 'tree', |
| 794 | 'history', |
| 795 | ); |
| 796 | |
Jakub Narebski | 7e00dc5 | 2010-10-13 13:33:48 +0200 | [diff] [blame] | 797 | # we want to catch, among others |
Giuseppe Bilotta | b0be383 | 2008-10-21 21:34:53 +0200 | [diff] [blame] | 798 | # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] |
| 799 | my ($parentrefname, $parentpathname, $refname, $pathname) = |
Jakub Narebski | 7e00dc5 | 2010-10-13 13:33:48 +0200 | [diff] [blame] | 800 | ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?([^:]+?)?(?::(.+))?$/); |
Giuseppe Bilotta | b0be383 | 2008-10-21 21:34:53 +0200 | [diff] [blame] | 801 | |
| 802 | # first, analyze the 'current' part |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 803 | if (defined $pathname) { |
Giuseppe Bilotta | d8c2882 | 2008-10-21 21:34:50 +0200 | [diff] [blame] | 804 | # we got "branch:filename" or "branch:dir/" |
| 805 | # we could use git_get_type(branch:pathname), but: |
| 806 | # - it needs $git_dir |
| 807 | # - it does a git() call |
| 808 | # - the convention of terminating directories with a slash |
| 809 | # makes it superfluous |
| 810 | # - embedding the action in the PATH_INFO would make it even |
| 811 | # more superfluous |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 812 | $pathname =~ s,^/+,,; |
| 813 | if (!$pathname || substr($pathname, -1) eq "/") { |
Giuseppe Bilotta | d8c2882 | 2008-10-21 21:34:50 +0200 | [diff] [blame] | 814 | $input_params{'action'} ||= "tree"; |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 815 | $pathname =~ s,/$,,; |
| 816 | } else { |
Giuseppe Bilotta | b0be383 | 2008-10-21 21:34:53 +0200 | [diff] [blame] | 817 | # the default action depends on whether we had parent info |
| 818 | # or not |
| 819 | if ($parentrefname) { |
| 820 | $input_params{'action'} ||= "blobdiff_plain"; |
| 821 | } else { |
| 822 | $input_params{'action'} ||= "blob_plain"; |
| 823 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 824 | } |
| 825 | $input_params{'hash_base'} ||= $refname; |
| 826 | $input_params{'file_name'} ||= $pathname; |
| 827 | } elsif (defined $refname) { |
Giuseppe Bilotta | d8c2882 | 2008-10-21 21:34:50 +0200 | [diff] [blame] | 828 | # we got "branch". In this case we have to choose if we have to |
| 829 | # set hash or hash_base. |
| 830 | # |
| 831 | # Most of the actions without a pathname only want hash to be |
| 832 | # set, except for the ones specified in @wants_base that want |
| 833 | # hash_base instead. It should also be noted that hand-crafted |
| 834 | # links having 'history' as an action and no pathname or hash |
| 835 | # set will fail, but that happens regardless of PATH_INFO. |
Jakub Narebski | d0af373 | 2010-10-13 13:35:20 +0200 | [diff] [blame] | 836 | if (defined $parentrefname) { |
| 837 | # if there is parent let the default be 'shortlog' action |
| 838 | # (for http://git.example.com/repo.git/A..B links); if there |
| 839 | # is no parent, dispatch will detect type of object and set |
| 840 | # action appropriately if required (if action is not set) |
| 841 | $input_params{'action'} ||= "shortlog"; |
| 842 | } |
| 843 | if ($input_params{'action'} && |
| 844 | grep { $_ eq $input_params{'action'} } @wants_base) { |
Giuseppe Bilotta | d8c2882 | 2008-10-21 21:34:50 +0200 | [diff] [blame] | 845 | $input_params{'hash_base'} ||= $refname; |
| 846 | } else { |
| 847 | $input_params{'hash'} ||= $refname; |
| 848 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 849 | } |
Giuseppe Bilotta | b0be383 | 2008-10-21 21:34:53 +0200 | [diff] [blame] | 850 | |
| 851 | # next, handle the 'parent' part, if present |
| 852 | if (defined $parentrefname) { |
| 853 | # a missing pathspec defaults to the 'current' filename, allowing e.g. |
| 854 | # someproject/blobdiff/oldrev..newrev:/filename |
| 855 | if ($parentpathname) { |
| 856 | $parentpathname =~ s,^/+,,; |
| 857 | $parentpathname =~ s,/$,,; |
| 858 | $input_params{'file_parent'} ||= $parentpathname; |
| 859 | } else { |
| 860 | $input_params{'file_parent'} ||= $input_params{'file_name'}; |
| 861 | } |
| 862 | # we assume that hash_parent_base is wanted if a path was specified, |
| 863 | # or if the action wants hash_base instead of hash |
| 864 | if (defined $input_params{'file_parent'} || |
| 865 | grep { $_ eq $input_params{'action'} } @wants_base) { |
| 866 | $input_params{'hash_parent_base'} ||= $parentrefname; |
| 867 | } else { |
| 868 | $input_params{'hash_parent'} ||= $parentrefname; |
| 869 | } |
| 870 | } |
Giuseppe Bilotta | 1ec2fb5 | 2008-11-02 10:21:38 +0100 | [diff] [blame] | 871 | |
| 872 | # for the snapshot action, we allow URLs in the form |
| 873 | # $project/snapshot/$hash.ext |
| 874 | # where .ext determines the snapshot and gets removed from the |
| 875 | # passed $refname to provide the $hash. |
| 876 | # |
| 877 | # To be able to tell that $refname includes the format extension, we |
| 878 | # require the following two conditions to be satisfied: |
| 879 | # - the hash input parameter MUST have been set from the $refname part |
| 880 | # of the URL (i.e. they must be equal) |
| 881 | # - the snapshot format MUST NOT have been defined already (e.g. from |
| 882 | # CGI parameter sf) |
| 883 | # It's also useless to try any matching unless $refname has a dot, |
| 884 | # so we check for that too |
| 885 | if (defined $input_params{'action'} && |
| 886 | $input_params{'action'} eq 'snapshot' && |
| 887 | defined $refname && index($refname, '.') != -1 && |
| 888 | $refname eq $input_params{'hash'} && |
| 889 | !defined $input_params{'snapshot_format'}) { |
| 890 | # We loop over the known snapshot formats, checking for |
| 891 | # extensions. Allowed extensions are both the defined suffix |
| 892 | # (which includes the initial dot already) and the snapshot |
| 893 | # format key itself, with a prepended dot |
Holger Weiß | ccb4b53 | 2009-03-31 18:16:36 +0200 | [diff] [blame] | 894 | while (my ($fmt, $opt) = each %known_snapshot_formats) { |
Giuseppe Bilotta | 1ec2fb5 | 2008-11-02 10:21:38 +0100 | [diff] [blame] | 895 | my $hash = $refname; |
Jakub Narebski | 095e914 | 2009-05-11 19:42:47 +0200 | [diff] [blame] | 896 | unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { |
| 897 | next; |
| 898 | } |
| 899 | my $sfx = $1; |
Giuseppe Bilotta | 1ec2fb5 | 2008-11-02 10:21:38 +0100 | [diff] [blame] | 900 | # a valid suffix was found, so set the snapshot format |
| 901 | # and reset the hash parameter |
| 902 | $input_params{'snapshot_format'} = $fmt; |
| 903 | $input_params{'hash'} = $hash; |
| 904 | # we also set the format suffix to the one requested |
| 905 | # in the URL: this way a request for e.g. .tgz returns |
| 906 | # a .tgz instead of a .tar.gz |
| 907 | $known_snapshot_formats{$fmt}{'suffix'} = $sfx; |
| 908 | last; |
| 909 | } |
| 910 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 911 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 912 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 913 | our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base, |
| 914 | $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp, |
| 915 | $searchtext, $search_regexp); |
| 916 | sub evaluate_and_validate_params { |
| 917 | our $action = $input_params{'action'}; |
| 918 | if (defined $action) { |
| 919 | if (!validate_action($action)) { |
| 920 | die_error(400, "Invalid action parameter"); |
| 921 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 922 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 923 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 924 | # parameters which are pathnames |
| 925 | our $project = $input_params{'project'}; |
| 926 | if (defined $project) { |
| 927 | if (!validate_project($project)) { |
| 928 | undef $project; |
| 929 | die_error(404, "No such project"); |
| 930 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 931 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 932 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 933 | our $file_name = $input_params{'file_name'}; |
| 934 | if (defined $file_name) { |
| 935 | if (!validate_pathname($file_name)) { |
| 936 | die_error(400, "Invalid file parameter"); |
| 937 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 938 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 939 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 940 | our $file_parent = $input_params{'file_parent'}; |
| 941 | if (defined $file_parent) { |
| 942 | if (!validate_pathname($file_parent)) { |
| 943 | die_error(400, "Invalid file parent parameter"); |
| 944 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 945 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 946 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 947 | # parameters which are refnames |
| 948 | our $hash = $input_params{'hash'}; |
| 949 | if (defined $hash) { |
| 950 | if (!validate_refname($hash)) { |
| 951 | die_error(400, "Invalid hash parameter"); |
| 952 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 953 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 954 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 955 | our $hash_parent = $input_params{'hash_parent'}; |
| 956 | if (defined $hash_parent) { |
| 957 | if (!validate_refname($hash_parent)) { |
| 958 | die_error(400, "Invalid hash parent parameter"); |
| 959 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 960 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 961 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 962 | our $hash_base = $input_params{'hash_base'}; |
| 963 | if (defined $hash_base) { |
| 964 | if (!validate_refname($hash_base)) { |
| 965 | die_error(400, "Invalid hash base parameter"); |
| 966 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 967 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 968 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 969 | our @extra_options = @{$input_params{'extra_options'}}; |
| 970 | # @extra_options is always defined, since it can only be (currently) set from |
| 971 | # CGI, and $cgi->param() returns the empty array in array context if the param |
| 972 | # is not set |
| 973 | foreach my $opt (@extra_options) { |
| 974 | if (not exists $allowed_options{$opt}) { |
| 975 | die_error(400, "Invalid option parameter"); |
| 976 | } |
| 977 | if (not grep(/^$action$/, @{$allowed_options{$opt}})) { |
| 978 | die_error(400, "Invalid option parameter for this action"); |
| 979 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 980 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 981 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 982 | our $hash_parent_base = $input_params{'hash_parent_base'}; |
| 983 | if (defined $hash_parent_base) { |
| 984 | if (!validate_refname($hash_parent_base)) { |
| 985 | die_error(400, "Invalid hash parent base parameter"); |
| 986 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 987 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 988 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 989 | # other parameters |
| 990 | our $page = $input_params{'page'}; |
| 991 | if (defined $page) { |
| 992 | if ($page =~ m/[^0-9]/) { |
| 993 | die_error(400, "Invalid page parameter"); |
| 994 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 995 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 996 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 997 | our $searchtype = $input_params{'searchtype'}; |
| 998 | if (defined $searchtype) { |
| 999 | if ($searchtype =~ m/[^a-z]/) { |
| 1000 | die_error(400, "Invalid searchtype parameter"); |
| 1001 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 1002 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 1003 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 1004 | our $search_use_regexp = $input_params{'search_use_regexp'}; |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 1005 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 1006 | our $searchtext = $input_params{'searchtext'}; |
| 1007 | our $search_regexp; |
| 1008 | if (defined $searchtext) { |
| 1009 | if (length($searchtext) < 2) { |
| 1010 | die_error(403, "At least two characters are required for search parameter"); |
| 1011 | } |
| 1012 | $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext; |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 1013 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | # path to the current git repository |
| 1017 | our $git_dir; |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 1018 | sub evaluate_git_dir { |
| 1019 | our $git_dir = "$projectroot/$project" if $project; |
| 1020 | } |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 1021 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 1022 | our (@snapshot_fmts, $git_avatar); |
| 1023 | sub configure_gitweb_features { |
| 1024 | # list of supported snapshot formats |
| 1025 | our @snapshot_fmts = gitweb_get_feature('snapshot'); |
| 1026 | @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts); |
Giuseppe Bilotta | 5e16684 | 2008-11-02 10:21:37 +0100 | [diff] [blame] | 1027 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 1028 | # check that the avatar feature is set to a known provider name, |
| 1029 | # and for each provider check if the dependencies are satisfied. |
| 1030 | # if the provider name is invalid or the dependencies are not met, |
| 1031 | # reset $git_avatar to the empty string. |
| 1032 | our ($git_avatar) = gitweb_get_feature('avatar'); |
| 1033 | if ($git_avatar eq 'gravatar') { |
| 1034 | $git_avatar = '' unless (eval { require Digest::MD5; 1; }); |
| 1035 | } elsif ($git_avatar eq 'picon') { |
| 1036 | # no dependencies |
| 1037 | } else { |
| 1038 | $git_avatar = ''; |
| 1039 | } |
Giuseppe Bilotta | e9fdd74 | 2009-06-30 00:00:51 +0200 | [diff] [blame] | 1040 | } |
| 1041 | |
Jakub Narebski | 7a59745 | 2010-04-24 16:00:04 +0200 | [diff] [blame] | 1042 | # custom error handler: 'die <message>' is Internal Server Error |
| 1043 | sub handle_errors_html { |
| 1044 | my $msg = shift; # it is already HTML escaped |
| 1045 | |
| 1046 | # to avoid infinite loop where error occurs in die_error, |
| 1047 | # change handler to default handler, disabling handle_errors_html |
| 1048 | set_message("Error occured when inside die_error:\n$msg"); |
| 1049 | |
| 1050 | # you cannot jump out of die_error when called as error handler; |
| 1051 | # the subroutine set via CGI::Carp::set_message is called _after_ |
| 1052 | # HTTP headers are already written, so it cannot write them itself |
| 1053 | die_error(undef, undef, $msg, -error_handler => 1, -no_http_header => 1); |
| 1054 | } |
| 1055 | set_message(\&handle_errors_html); |
| 1056 | |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 1057 | # dispatch |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 1058 | sub dispatch { |
| 1059 | if (!defined $action) { |
| 1060 | if (defined $hash) { |
| 1061 | $action = git_get_type($hash); |
| 1062 | } elsif (defined $hash_base && defined $file_name) { |
| 1063 | $action = git_get_type("$hash_base:$file_name"); |
| 1064 | } elsif (defined $project) { |
| 1065 | $action = 'summary'; |
| 1066 | } else { |
| 1067 | $action = 'project_list'; |
| 1068 | } |
Gerrit Pape | 7f9778b | 2007-05-10 07:32:07 +0000 | [diff] [blame] | 1069 | } |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 1070 | if (!defined($actions{$action})) { |
| 1071 | die_error(400, "Unknown action"); |
| 1072 | } |
| 1073 | if ($action !~ m/^(?:opml|project_list|project_index)$/ && |
| 1074 | !$project) { |
| 1075 | die_error(400, "Project needed"); |
| 1076 | } |
| 1077 | $actions{$action}->(); |
Jakub Narebski | 77a153f | 2006-08-22 16:59:20 +0200 | [diff] [blame] | 1078 | } |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 1079 | |
Jakub Narebski | 869d588 | 2010-07-05 20:52:43 +0200 | [diff] [blame] | 1080 | sub reset_timer { |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 1081 | our $t0 = [Time::HiRes::gettimeofday()] |
| 1082 | if defined $t0; |
Jakub Narebski | 869d588 | 2010-07-05 20:52:43 +0200 | [diff] [blame] | 1083 | our $number_of_git_cmds = 0; |
| 1084 | } |
| 1085 | |
| 1086 | sub run_request { |
| 1087 | reset_timer(); |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 1088 | |
| 1089 | evaluate_uri(); |
Jonathan Nieder | 7f425db | 2010-07-30 22:01:59 -0500 | [diff] [blame] | 1090 | evaluate_gitweb_config(); |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 1091 | check_loadavg(); |
| 1092 | |
Jonathan Nieder | 7f425db | 2010-07-30 22:01:59 -0500 | [diff] [blame] | 1093 | # $projectroot and $projects_list might be set in gitweb config file |
| 1094 | $projects_list ||= $projectroot; |
| 1095 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 1096 | evaluate_query_params(); |
| 1097 | evaluate_path_info(); |
| 1098 | evaluate_and_validate_params(); |
| 1099 | evaluate_git_dir(); |
| 1100 | |
| 1101 | configure_gitweb_features(); |
| 1102 | |
| 1103 | dispatch(); |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 1104 | } |
Sam Vilain | a0446e7 | 2010-05-07 14:54:05 +0200 | [diff] [blame] | 1105 | |
| 1106 | our $is_last_request = sub { 1 }; |
| 1107 | our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook); |
| 1108 | our $CGI = 'CGI'; |
| 1109 | our $cgi; |
Jakub Narebski | 45aa989 | 2010-06-05 23:11:18 +0200 | [diff] [blame] | 1110 | sub configure_as_fcgi { |
| 1111 | require CGI::Fast; |
| 1112 | our $CGI = 'CGI::Fast'; |
| 1113 | |
| 1114 | my $request_number = 0; |
| 1115 | # let each child service 100 requests |
| 1116 | our $is_last_request = sub { ++$request_number > 100 }; |
Jakub Narebski | d04d3d4 | 2006-09-19 21:53:22 +0200 | [diff] [blame] | 1117 | } |
Sam Vilain | a0446e7 | 2010-05-07 14:54:05 +0200 | [diff] [blame] | 1118 | sub evaluate_argv { |
Jakub Narebski | 45aa989 | 2010-06-05 23:11:18 +0200 | [diff] [blame] | 1119 | my $script_name = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || __FILE__; |
| 1120 | configure_as_fcgi() |
| 1121 | if $script_name =~ /\.fcgi$/; |
| 1122 | |
Sam Vilain | a0446e7 | 2010-05-07 14:54:05 +0200 | [diff] [blame] | 1123 | return unless (@ARGV); |
| 1124 | |
| 1125 | require Getopt::Long; |
| 1126 | Getopt::Long::GetOptions( |
Jakub Narebski | 45aa989 | 2010-06-05 23:11:18 +0200 | [diff] [blame] | 1127 | 'fastcgi|fcgi|f' => \&configure_as_fcgi, |
Sam Vilain | a0446e7 | 2010-05-07 14:54:05 +0200 | [diff] [blame] | 1128 | 'nproc|n=i' => sub { |
| 1129 | my ($arg, $val) = @_; |
| 1130 | return unless eval { require FCGI::ProcManager; 1; }; |
| 1131 | my $proc_manager = FCGI::ProcManager->new({ |
| 1132 | n_processes => $val, |
| 1133 | }); |
| 1134 | our $pre_listen_hook = sub { $proc_manager->pm_manage() }; |
| 1135 | our $pre_dispatch_hook = sub { $proc_manager->pm_pre_dispatch() }; |
| 1136 | our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() }; |
| 1137 | }, |
| 1138 | ); |
| 1139 | } |
| 1140 | |
| 1141 | sub run { |
| 1142 | evaluate_argv(); |
Jakub Narebski | 869d588 | 2010-07-05 20:52:43 +0200 | [diff] [blame] | 1143 | evaluate_git_version(); |
| 1144 | |
Sam Vilain | a0446e7 | 2010-05-07 14:54:05 +0200 | [diff] [blame] | 1145 | $pre_listen_hook->() |
| 1146 | if $pre_listen_hook; |
| 1147 | |
| 1148 | REQUEST: |
| 1149 | while ($cgi = $CGI->new()) { |
| 1150 | $pre_dispatch_hook->() |
| 1151 | if $pre_dispatch_hook; |
| 1152 | |
| 1153 | run_request(); |
| 1154 | |
Jakub Narebski | 0b45010 | 2010-08-02 22:21:47 +0200 | [diff] [blame] | 1155 | $post_dispatch_hook->() |
Sam Vilain | a0446e7 | 2010-05-07 14:54:05 +0200 | [diff] [blame] | 1156 | if $post_dispatch_hook; |
| 1157 | |
| 1158 | last REQUEST if ($is_last_request->()); |
| 1159 | } |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 1160 | |
| 1161 | DONE_GITWEB: |
| 1162 | 1; |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 1163 | } |
Sam Vilain | a0446e7 | 2010-05-07 14:54:05 +0200 | [diff] [blame] | 1164 | |
Jakub Narebski | c2394fe | 2010-05-07 14:54:04 +0200 | [diff] [blame] | 1165 | run(); |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 1166 | |
Jakub Narebski | 5ed2ec1 | 2010-06-13 12:09:32 +0200 | [diff] [blame] | 1167 | if (defined caller) { |
| 1168 | # wrapped in a subroutine processing requests, |
| 1169 | # e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI |
| 1170 | return; |
| 1171 | } else { |
| 1172 | # pure CGI script, serving single request |
| 1173 | exit; |
| 1174 | } |
Kay Sievers | 823d5dc | 2005-08-07 19:57:58 +0200 | [diff] [blame] | 1175 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1176 | ## ====================================================================== |
Martin Waitz | 06a9d86 | 2006-08-16 00:23:50 +0200 | [diff] [blame] | 1177 | ## action links |
| 1178 | |
Jakub Narebski | 377bee3 | 2010-04-24 15:53:19 +0200 | [diff] [blame] | 1179 | # possible values of extra options |
| 1180 | # -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base) |
| 1181 | # -replay => 1 - start from a current view (replay with modifications) |
| 1182 | # -path_info => 0|1 - don't use/use path_info URL (if possible) |
Jakub Narebski | 74fd872 | 2009-05-07 19:11:29 +0200 | [diff] [blame] | 1183 | sub href { |
Jakub Narebski | 498fe00 | 2006-08-22 19:05:25 +0200 | [diff] [blame] | 1184 | my %params = @_; |
Jakub Narebski | bd5d1e4 | 2006-11-19 15:05:21 +0100 | [diff] [blame] | 1185 | # default is to use -absolute url() i.e. $my_uri |
| 1186 | my $href = $params{-full} ? $my_url : $my_uri; |
Jakub Narebski | 498fe00 | 2006-08-22 19:05:25 +0200 | [diff] [blame] | 1187 | |
Jakub Narebski | afa9b62 | 2008-02-14 09:22:30 +0100 | [diff] [blame] | 1188 | $params{'project'} = $project unless exists $params{'project'}; |
| 1189 | |
Jakub Narebski | 1cad283 | 2007-11-01 13:06:27 +0100 | [diff] [blame] | 1190 | if ($params{-replay}) { |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 1191 | while (my ($name, $symbol) = each %cgi_param_mapping) { |
Jakub Narebski | 1cad283 | 2007-11-01 13:06:27 +0100 | [diff] [blame] | 1192 | if (!exists $params{$name}) { |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 1193 | $params{$name} = $input_params{$name}; |
Jakub Narebski | 1cad283 | 2007-11-01 13:06:27 +0100 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 1198 | my $use_pathinfo = gitweb_check_feature('pathinfo'); |
Jakub Narebski | 377bee3 | 2010-04-24 15:53:19 +0200 | [diff] [blame] | 1199 | if (defined $params{'project'} && |
| 1200 | (exists $params{-path_info} ? $params{-path_info} : $use_pathinfo)) { |
Giuseppe Bilotta | b02bd7a | 2008-10-21 21:34:51 +0200 | [diff] [blame] | 1201 | # try to put as many parameters as possible in PATH_INFO: |
| 1202 | # - project name |
| 1203 | # - action |
Giuseppe Bilotta | 8db49a7 | 2008-10-21 21:34:54 +0200 | [diff] [blame] | 1204 | # - hash_parent or hash_parent_base:/file_parent |
Giuseppe Bilotta | 3550ea7 | 2008-10-21 21:34:52 +0200 | [diff] [blame] | 1205 | # - hash or hash_base:/filename |
Giuseppe Bilotta | c752a0e | 2008-11-02 10:21:39 +0100 | [diff] [blame] | 1206 | # - the snapshot_format as an appropriate suffix |
Giuseppe Bilotta | b02bd7a | 2008-10-21 21:34:51 +0200 | [diff] [blame] | 1207 | |
| 1208 | # When the script is the root DirectoryIndex for the domain, |
| 1209 | # $href here would be something like http://gitweb.example.com/ |
| 1210 | # Thus, we strip any trailing / from $href, to spare us double |
| 1211 | # slashes in the final URL |
| 1212 | $href =~ s,/$,,; |
| 1213 | |
| 1214 | # Then add the project name, if present |
Giuseppe Bilotta | fb098a9 | 2009-01-02 12:34:40 +0100 | [diff] [blame] | 1215 | $href .= "/".esc_url($params{'project'}); |
Martin Waitz | 9e75690 | 2006-10-01 23:57:48 +0200 | [diff] [blame] | 1216 | delete $params{'project'}; |
| 1217 | |
Giuseppe Bilotta | c752a0e | 2008-11-02 10:21:39 +0100 | [diff] [blame] | 1218 | # since we destructively absorb parameters, we keep this |
| 1219 | # boolean that remembers if we're handling a snapshot |
| 1220 | my $is_snapshot = $params{'action'} eq 'snapshot'; |
| 1221 | |
Giuseppe Bilotta | b02bd7a | 2008-10-21 21:34:51 +0200 | [diff] [blame] | 1222 | # Summary just uses the project path URL, any other action is |
| 1223 | # added to the URL |
| 1224 | if (defined $params{'action'}) { |
| 1225 | $href .= "/".esc_url($params{'action'}) unless $params{'action'} eq 'summary'; |
Martin Waitz | 9e75690 | 2006-10-01 23:57:48 +0200 | [diff] [blame] | 1226 | delete $params{'action'}; |
| 1227 | } |
Giuseppe Bilotta | b02bd7a | 2008-10-21 21:34:51 +0200 | [diff] [blame] | 1228 | |
Giuseppe Bilotta | 8db49a7 | 2008-10-21 21:34:54 +0200 | [diff] [blame] | 1229 | # Next, we put hash_parent_base:/file_parent..hash_base:/file_name, |
| 1230 | # stripping nonexistent or useless pieces |
| 1231 | $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'} |
| 1232 | || $params{'hash_parent'} || $params{'hash'}); |
Giuseppe Bilotta | b02bd7a | 2008-10-21 21:34:51 +0200 | [diff] [blame] | 1233 | if (defined $params{'hash_base'}) { |
Giuseppe Bilotta | 8db49a7 | 2008-10-21 21:34:54 +0200 | [diff] [blame] | 1234 | if (defined $params{'hash_parent_base'}) { |
| 1235 | $href .= esc_url($params{'hash_parent_base'}); |
| 1236 | # skip the file_parent if it's the same as the file_name |
Giuseppe Bilotta | b7da721 | 2009-07-31 08:48:49 +0200 | [diff] [blame] | 1237 | if (defined $params{'file_parent'}) { |
| 1238 | if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) { |
| 1239 | delete $params{'file_parent'}; |
| 1240 | } elsif ($params{'file_parent'} !~ /\.\./) { |
| 1241 | $href .= ":/".esc_url($params{'file_parent'}); |
| 1242 | delete $params{'file_parent'}; |
| 1243 | } |
Giuseppe Bilotta | 8db49a7 | 2008-10-21 21:34:54 +0200 | [diff] [blame] | 1244 | } |
| 1245 | $href .= ".."; |
| 1246 | delete $params{'hash_parent'}; |
| 1247 | delete $params{'hash_parent_base'}; |
| 1248 | } elsif (defined $params{'hash_parent'}) { |
| 1249 | $href .= esc_url($params{'hash_parent'}). ".."; |
| 1250 | delete $params{'hash_parent'}; |
| 1251 | } |
| 1252 | |
| 1253 | $href .= esc_url($params{'hash_base'}); |
| 1254 | if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) { |
Giuseppe Bilotta | 3550ea7 | 2008-10-21 21:34:52 +0200 | [diff] [blame] | 1255 | $href .= ":/".esc_url($params{'file_name'}); |
Giuseppe Bilotta | b02bd7a | 2008-10-21 21:34:51 +0200 | [diff] [blame] | 1256 | delete $params{'file_name'}; |
| 1257 | } |
| 1258 | delete $params{'hash'}; |
| 1259 | delete $params{'hash_base'}; |
| 1260 | } elsif (defined $params{'hash'}) { |
Giuseppe Bilotta | 8db49a7 | 2008-10-21 21:34:54 +0200 | [diff] [blame] | 1261 | $href .= esc_url($params{'hash'}); |
Giuseppe Bilotta | b02bd7a | 2008-10-21 21:34:51 +0200 | [diff] [blame] | 1262 | delete $params{'hash'}; |
| 1263 | } |
Giuseppe Bilotta | c752a0e | 2008-11-02 10:21:39 +0100 | [diff] [blame] | 1264 | |
| 1265 | # If the action was a snapshot, we can absorb the |
| 1266 | # snapshot_format parameter too |
| 1267 | if ($is_snapshot) { |
| 1268 | my $fmt = $params{'snapshot_format'}; |
| 1269 | # snapshot_format should always be defined when href() |
| 1270 | # is called, but just in case some code forgets, we |
| 1271 | # fall back to the default |
| 1272 | $fmt ||= $snapshot_fmts[0]; |
| 1273 | $href .= $known_snapshot_formats{$fmt}{'suffix'}; |
| 1274 | delete $params{'snapshot_format'}; |
| 1275 | } |
Martin Waitz | 9e75690 | 2006-10-01 23:57:48 +0200 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | # now encode the parameters explicitly |
Jakub Narebski | 498fe00 | 2006-08-22 19:05:25 +0200 | [diff] [blame] | 1279 | my @result = (); |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 1280 | for (my $i = 0; $i < @cgi_param_mapping; $i += 2) { |
| 1281 | my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]); |
Jakub Narebski | 498fe00 | 2006-08-22 19:05:25 +0200 | [diff] [blame] | 1282 | if (defined $params{$name}) { |
Jakub Narebski | f22cca4 | 2007-07-29 01:04:09 +0200 | [diff] [blame] | 1283 | if (ref($params{$name}) eq "ARRAY") { |
| 1284 | foreach my $par (@{$params{$name}}) { |
| 1285 | push @result, $symbol . "=" . esc_param($par); |
| 1286 | } |
| 1287 | } else { |
| 1288 | push @result, $symbol . "=" . esc_param($params{$name}); |
| 1289 | } |
Jakub Narebski | 498fe00 | 2006-08-22 19:05:25 +0200 | [diff] [blame] | 1290 | } |
| 1291 | } |
Martin Waitz | 9e75690 | 2006-10-01 23:57:48 +0200 | [diff] [blame] | 1292 | $href .= "?" . join(';', @result) if scalar @result; |
| 1293 | |
| 1294 | return $href; |
Martin Waitz | 06a9d86 | 2006-08-16 00:23:50 +0200 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | |
| 1298 | ## ====================================================================== |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1299 | ## validation, quoting/unquoting and escaping |
| 1300 | |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 1301 | sub validate_action { |
| 1302 | my $input = shift || return undef; |
| 1303 | return undef unless exists $actions{$input}; |
| 1304 | return $input; |
| 1305 | } |
| 1306 | |
| 1307 | sub validate_project { |
| 1308 | my $input = shift || return undef; |
| 1309 | if (!validate_pathname($input) || |
| 1310 | !(-d "$projectroot/$input") || |
Alexander Gavrilov | ec26f09 | 2008-11-06 01:15:56 +0300 | [diff] [blame] | 1311 | !check_export_ok("$projectroot/$input") || |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 1312 | ($strict_export && !project_in_list($input))) { |
| 1313 | return undef; |
| 1314 | } else { |
| 1315 | return $input; |
| 1316 | } |
| 1317 | } |
| 1318 | |
Jakub Narebski | 24d0693 | 2006-09-26 01:57:02 +0200 | [diff] [blame] | 1319 | sub validate_pathname { |
| 1320 | my $input = shift || return undef; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1321 | |
Jakub Narebski | 24d0693 | 2006-09-26 01:57:02 +0200 | [diff] [blame] | 1322 | # no '.' or '..' as elements of path, i.e. no '.' nor '..' |
| 1323 | # at the beginning, at the end, and between slashes. |
| 1324 | # also this catches doubled slashes |
| 1325 | if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) { |
| 1326 | return undef; |
| 1327 | } |
| 1328 | # no null characters |
| 1329 | if ($input =~ m!\0!) { |
| 1330 | return undef; |
| 1331 | } |
| 1332 | return $input; |
| 1333 | } |
| 1334 | |
| 1335 | sub validate_refname { |
| 1336 | my $input = shift || return undef; |
| 1337 | |
| 1338 | # textual hashes are O.K. |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1339 | if ($input =~ m/^[0-9a-fA-F]{40}$/) { |
| 1340 | return $input; |
| 1341 | } |
Jakub Narebski | 24d0693 | 2006-09-26 01:57:02 +0200 | [diff] [blame] | 1342 | # it must be correct pathname |
| 1343 | $input = validate_pathname($input) |
| 1344 | or return undef; |
| 1345 | # restrictions on ref name according to git-check-ref-format |
| 1346 | if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1347 | return undef; |
| 1348 | } |
| 1349 | return $input; |
| 1350 | } |
| 1351 | |
Martin Koegler | 00f429a | 2007-06-03 17:42:44 +0200 | [diff] [blame] | 1352 | # decode sequences of octets in utf8 into Perl's internal form, |
| 1353 | # which is utf-8 with utf8 flag set if needed. gitweb writes out |
| 1354 | # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning |
| 1355 | sub to_utf8 { |
| 1356 | my $str = shift; |
Jakub Narebski | 1df4876 | 2010-02-07 21:52:25 +0100 | [diff] [blame] | 1357 | return undef unless defined $str; |
İsmail Dönmez | e5d3de5 | 2007-12-04 10:55:41 +0200 | [diff] [blame] | 1358 | if (utf8::valid($str)) { |
| 1359 | utf8::decode($str); |
| 1360 | return $str; |
Martin Koegler | 00f429a | 2007-06-03 17:42:44 +0200 | [diff] [blame] | 1361 | } else { |
| 1362 | return decode($fallback_encoding, $str, Encode::FB_DEFAULT); |
| 1363 | } |
| 1364 | } |
| 1365 | |
Kay Sievers | 232ff55 | 2005-11-24 16:56:55 +0100 | [diff] [blame] | 1366 | # quote unsafe chars, but keep the slash, even when it's not |
| 1367 | # correct, but quoted slashes look too horrible in bookmarks |
| 1368 | sub esc_param { |
Kay Sievers | 353347b | 2005-11-14 05:47:18 +0100 | [diff] [blame] | 1369 | my $str = shift; |
Jakub Narebski | 1df4876 | 2010-02-07 21:52:25 +0100 | [diff] [blame] | 1370 | return undef unless defined $str; |
Giuseppe Bilotta | 452e225 | 2009-10-13 21:51:36 +0200 | [diff] [blame] | 1371 | $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg; |
Kay Sievers | a9e60b7 | 2005-11-14 15:15:12 +0100 | [diff] [blame] | 1372 | $str =~ s/ /\+/g; |
Kay Sievers | 353347b | 2005-11-14 05:47:18 +0100 | [diff] [blame] | 1373 | return $str; |
| 1374 | } |
| 1375 | |
Ralf Wildenhues | 22e5e58 | 2010-08-22 13:12:12 +0200 | [diff] [blame] | 1376 | # quote unsafe chars in whole URL, so some characters cannot be quoted |
Jakub Narebski | f93bff8 | 2006-09-26 01:58:41 +0200 | [diff] [blame] | 1377 | sub esc_url { |
| 1378 | my $str = shift; |
Jakub Narebski | 1df4876 | 2010-02-07 21:52:25 +0100 | [diff] [blame] | 1379 | return undef unless defined $str; |
Pavan Kumar Sunkara | 109988f | 2010-07-15 12:59:01 +0530 | [diff] [blame] | 1380 | $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg; |
Jakub Narebski | f93bff8 | 2006-09-26 01:58:41 +0200 | [diff] [blame] | 1381 | $str =~ s/ /\+/g; |
| 1382 | return $str; |
| 1383 | } |
| 1384 | |
Kay Sievers | 232ff55 | 2005-11-24 16:56:55 +0100 | [diff] [blame] | 1385 | # replace invalid utf8 character with SUBSTITUTION sequence |
Jakub Narebski | 74fd872 | 2009-05-07 19:11:29 +0200 | [diff] [blame] | 1386 | sub esc_html { |
Kay Sievers | 40c1381 | 2005-11-19 17:41:29 +0100 | [diff] [blame] | 1387 | my $str = shift; |
Jakub Narebski | 6255ef0 | 2006-11-01 14:33:21 +0100 | [diff] [blame] | 1388 | my %opts = @_; |
| 1389 | |
Jakub Narebski | 1df4876 | 2010-02-07 21:52:25 +0100 | [diff] [blame] | 1390 | return undef unless defined $str; |
| 1391 | |
Martin Koegler | 00f429a | 2007-06-03 17:42:44 +0200 | [diff] [blame] | 1392 | $str = to_utf8($str); |
Li Yang | c390ae9 | 2007-03-06 11:58:56 +0800 | [diff] [blame] | 1393 | $str = $cgi->escapeHTML($str); |
Jakub Narebski | 6255ef0 | 2006-11-01 14:33:21 +0100 | [diff] [blame] | 1394 | if ($opts{'-nbsp'}) { |
| 1395 | $str =~ s/ / /g; |
| 1396 | } |
Junio C Hamano | 25ffbb2 | 2006-11-08 15:11:10 -0800 | [diff] [blame] | 1397 | $str =~ s|([[:cntrl:]])|(($1 ne "\t") ? quot_cec($1) : $1)|eg; |
Kay Sievers | 40c1381 | 2005-11-19 17:41:29 +0100 | [diff] [blame] | 1398 | return $str; |
| 1399 | } |
| 1400 | |
Jakub Narebski | 391862e | 2006-11-25 09:43:59 +0100 | [diff] [blame] | 1401 | # quote control characters and escape filename to HTML |
| 1402 | sub esc_path { |
| 1403 | my $str = shift; |
| 1404 | my %opts = @_; |
| 1405 | |
Jakub Narebski | 1df4876 | 2010-02-07 21:52:25 +0100 | [diff] [blame] | 1406 | return undef unless defined $str; |
| 1407 | |
Martin Koegler | 00f429a | 2007-06-03 17:42:44 +0200 | [diff] [blame] | 1408 | $str = to_utf8($str); |
Li Yang | c390ae9 | 2007-03-06 11:58:56 +0800 | [diff] [blame] | 1409 | $str = $cgi->escapeHTML($str); |
Jakub Narebski | 391862e | 2006-11-25 09:43:59 +0100 | [diff] [blame] | 1410 | if ($opts{'-nbsp'}) { |
| 1411 | $str =~ s/ / /g; |
| 1412 | } |
| 1413 | $str =~ s|([[:cntrl:]])|quot_cec($1)|eg; |
| 1414 | return $str; |
| 1415 | } |
| 1416 | |
| 1417 | # Make control characters "printable", using character escape codes (CEC) |
Jakub Narebski | 1d3bc0c | 2006-11-08 11:50:07 +0100 | [diff] [blame] | 1418 | sub quot_cec { |
| 1419 | my $cntrl = shift; |
Jakub Narebski | c84c483 | 2008-02-17 18:48:13 +0100 | [diff] [blame] | 1420 | my %opts = @_; |
Jakub Narebski | 1d3bc0c | 2006-11-08 11:50:07 +0100 | [diff] [blame] | 1421 | my %es = ( # character escape codes, aka escape sequences |
Jakub Narebski | c84c483 | 2008-02-17 18:48:13 +0100 | [diff] [blame] | 1422 | "\t" => '\t', # tab (HT) |
| 1423 | "\n" => '\n', # line feed (LF) |
| 1424 | "\r" => '\r', # carrige return (CR) |
| 1425 | "\f" => '\f', # form feed (FF) |
| 1426 | "\b" => '\b', # backspace (BS) |
| 1427 | "\a" => '\a', # alarm (bell) (BEL) |
| 1428 | "\e" => '\e', # escape (ESC) |
| 1429 | "\013" => '\v', # vertical tab (VT) |
| 1430 | "\000" => '\0', # nul character (NUL) |
| 1431 | ); |
Jakub Narebski | 1d3bc0c | 2006-11-08 11:50:07 +0100 | [diff] [blame] | 1432 | my $chr = ( (exists $es{$cntrl}) |
| 1433 | ? $es{$cntrl} |
Petr Baudis | 25dfd17 | 2008-10-01 22:11:54 +0200 | [diff] [blame] | 1434 | : sprintf('\%2x', ord($cntrl)) ); |
Jakub Narebski | c84c483 | 2008-02-17 18:48:13 +0100 | [diff] [blame] | 1435 | if ($opts{-nohtml}) { |
| 1436 | return $chr; |
| 1437 | } else { |
| 1438 | return "<span class=\"cntrl\">$chr</span>"; |
| 1439 | } |
Jakub Narebski | 1d3bc0c | 2006-11-08 11:50:07 +0100 | [diff] [blame] | 1440 | } |
| 1441 | |
Jakub Narebski | 391862e | 2006-11-25 09:43:59 +0100 | [diff] [blame] | 1442 | # Alternatively use unicode control pictures codepoints, |
| 1443 | # Unicode "printable representation" (PR) |
Jakub Narebski | 1d3bc0c | 2006-11-08 11:50:07 +0100 | [diff] [blame] | 1444 | sub quot_upr { |
| 1445 | my $cntrl = shift; |
Jakub Narebski | c84c483 | 2008-02-17 18:48:13 +0100 | [diff] [blame] | 1446 | my %opts = @_; |
| 1447 | |
Jakub Narebski | 1d3bc0c | 2006-11-08 11:50:07 +0100 | [diff] [blame] | 1448 | my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl)); |
Jakub Narebski | c84c483 | 2008-02-17 18:48:13 +0100 | [diff] [blame] | 1449 | if ($opts{-nohtml}) { |
| 1450 | return $chr; |
| 1451 | } else { |
| 1452 | return "<span class=\"cntrl\">$chr</span>"; |
| 1453 | } |
Jakub Narebski | 1d3bc0c | 2006-11-08 11:50:07 +0100 | [diff] [blame] | 1454 | } |
| 1455 | |
Kay Sievers | 232ff55 | 2005-11-24 16:56:55 +0100 | [diff] [blame] | 1456 | # git may return quoted and escaped filenames |
| 1457 | sub unquote { |
| 1458 | my $str = shift; |
Jakub Narebski | 403d090 | 2006-11-08 11:48:56 +0100 | [diff] [blame] | 1459 | |
| 1460 | sub unq { |
| 1461 | my $seq = shift; |
| 1462 | my %es = ( # character escape codes, aka escape sequences |
| 1463 | 't' => "\t", # tab (HT, TAB) |
| 1464 | 'n' => "\n", # newline (NL) |
| 1465 | 'r' => "\r", # return (CR) |
| 1466 | 'f' => "\f", # form feed (FF) |
| 1467 | 'b' => "\b", # backspace (BS) |
| 1468 | 'a' => "\a", # alarm (bell) (BEL) |
| 1469 | 'e' => "\e", # escape (ESC) |
| 1470 | 'v' => "\013", # vertical tab (VT) |
| 1471 | ); |
| 1472 | |
| 1473 | if ($seq =~ m/^[0-7]{1,3}$/) { |
| 1474 | # octal char sequence |
| 1475 | return chr(oct($seq)); |
| 1476 | } elsif (exists $es{$seq}) { |
| 1477 | # C escape sequence, aka character escape code |
Jakub Narebski | c84c483 | 2008-02-17 18:48:13 +0100 | [diff] [blame] | 1478 | return $es{$seq}; |
Jakub Narebski | 403d090 | 2006-11-08 11:48:56 +0100 | [diff] [blame] | 1479 | } |
| 1480 | # quoted ordinary character |
| 1481 | return $seq; |
| 1482 | } |
| 1483 | |
Kay Sievers | 232ff55 | 2005-11-24 16:56:55 +0100 | [diff] [blame] | 1484 | if ($str =~ m/^"(.*)"$/) { |
Jakub Narebski | 403d090 | 2006-11-08 11:48:56 +0100 | [diff] [blame] | 1485 | # needs unquoting |
Kay Sievers | 232ff55 | 2005-11-24 16:56:55 +0100 | [diff] [blame] | 1486 | $str = $1; |
Jakub Narebski | 403d090 | 2006-11-08 11:48:56 +0100 | [diff] [blame] | 1487 | $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg; |
Kay Sievers | 232ff55 | 2005-11-24 16:56:55 +0100 | [diff] [blame] | 1488 | } |
| 1489 | return $str; |
| 1490 | } |
| 1491 | |
Jakub Narebski | f16db17 | 2006-08-06 02:08:31 +0200 | [diff] [blame] | 1492 | # escape tabs (convert tabs to spaces) |
| 1493 | sub untabify { |
| 1494 | my $line = shift; |
| 1495 | |
| 1496 | while ((my $pos = index($line, "\t")) != -1) { |
| 1497 | if (my $count = (8 - ($pos % 8))) { |
| 1498 | my $spaces = ' ' x $count; |
| 1499 | $line =~ s/\t/$spaces/; |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | return $line; |
| 1504 | } |
| 1505 | |
Matthias Lederhofer | 32f4aac | 2006-09-17 00:31:01 +0200 | [diff] [blame] | 1506 | sub project_in_list { |
| 1507 | my $project = shift; |
| 1508 | my @list = git_get_projects_list(); |
| 1509 | return @list && scalar(grep { $_->{'path'} eq $project } @list); |
| 1510 | } |
| 1511 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1512 | ## ---------------------------------------------------------------------- |
| 1513 | ## HTML aware string manipulation |
| 1514 | |
Jakub Narebski | b8d97d0 | 2008-02-25 21:07:57 +0100 | [diff] [blame] | 1515 | # Try to chop given string on a word boundary between position |
| 1516 | # $len and $len+$add_len. If there is no word boundary there, |
| 1517 | # chop at $len+$add_len. Do not chop if chopped part plus ellipsis |
| 1518 | # (marking chopped part) would be longer than given string. |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1519 | sub chop_str { |
| 1520 | my $str = shift; |
| 1521 | my $len = shift; |
| 1522 | my $add_len = shift || 10; |
Jakub Narebski | b8d97d0 | 2008-02-25 21:07:57 +0100 | [diff] [blame] | 1523 | my $where = shift || 'right'; # 'left' | 'center' | 'right' |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1524 | |
Anders Waldenborg | dee2775 | 2008-05-21 13:44:43 +0200 | [diff] [blame] | 1525 | # Make sure perl knows it is utf8 encoded so we don't |
| 1526 | # cut in the middle of a utf8 multibyte char. |
| 1527 | $str = to_utf8($str); |
| 1528 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1529 | # allow only $len chars, but don't cut a word if it would fit in $add_len |
| 1530 | # if it doesn't fit, cut it if it's still longer than the dots we would add |
Jakub Narebski | b8d97d0 | 2008-02-25 21:07:57 +0100 | [diff] [blame] | 1531 | # remove chopped character entities entirely |
| 1532 | |
| 1533 | # when chopping in the middle, distribute $len into left and right part |
| 1534 | # return early if chopping wouldn't make string shorter |
| 1535 | if ($where eq 'center') { |
| 1536 | return $str if ($len + 5 >= length($str)); # filler is length 5 |
| 1537 | $len = int($len/2); |
| 1538 | } else { |
| 1539 | return $str if ($len + 4 >= length($str)); # filler is length 4 |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1540 | } |
Jakub Narebski | b8d97d0 | 2008-02-25 21:07:57 +0100 | [diff] [blame] | 1541 | |
| 1542 | # regexps: ending and beginning with word part up to $add_len |
| 1543 | my $endre = qr/.{$len}\w{0,$add_len}/; |
| 1544 | my $begre = qr/\w{0,$add_len}.{$len}/; |
| 1545 | |
| 1546 | if ($where eq 'left') { |
| 1547 | $str =~ m/^(.*?)($begre)$/; |
| 1548 | my ($lead, $body) = ($1, $2); |
| 1549 | if (length($lead) > 4) { |
Jakub Narebski | b8d97d0 | 2008-02-25 21:07:57 +0100 | [diff] [blame] | 1550 | $lead = " ..."; |
| 1551 | } |
| 1552 | return "$lead$body"; |
| 1553 | |
| 1554 | } elsif ($where eq 'center') { |
| 1555 | $str =~ m/^($endre)(.*)$/; |
| 1556 | my ($left, $str) = ($1, $2); |
| 1557 | $str =~ m/^(.*?)($begre)$/; |
| 1558 | my ($mid, $right) = ($1, $2); |
| 1559 | if (length($mid) > 5) { |
Jakub Narebski | b8d97d0 | 2008-02-25 21:07:57 +0100 | [diff] [blame] | 1560 | $mid = " ... "; |
| 1561 | } |
| 1562 | return "$left$mid$right"; |
| 1563 | |
| 1564 | } else { |
| 1565 | $str =~ m/^($endre)(.*)$/; |
| 1566 | my $body = $1; |
| 1567 | my $tail = $2; |
| 1568 | if (length($tail) > 4) { |
Jakub Narebski | b8d97d0 | 2008-02-25 21:07:57 +0100 | [diff] [blame] | 1569 | $tail = "... "; |
| 1570 | } |
| 1571 | return "$body$tail"; |
| 1572 | } |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1573 | } |
| 1574 | |
David Symonds | ce58ec9 | 2007-10-23 11:31:22 +1000 | [diff] [blame] | 1575 | # takes the same arguments as chop_str, but also wraps a <span> around the |
| 1576 | # result with a title attribute if it does get chopped. Additionally, the |
| 1577 | # string is HTML-escaped. |
| 1578 | sub chop_and_escape_str { |
Jakub Narebski | b8d97d0 | 2008-02-25 21:07:57 +0100 | [diff] [blame] | 1579 | my ($str) = @_; |
David Symonds | ce58ec9 | 2007-10-23 11:31:22 +1000 | [diff] [blame] | 1580 | |
Jakub Narebski | b8d97d0 | 2008-02-25 21:07:57 +0100 | [diff] [blame] | 1581 | my $chopped = chop_str(@_); |
David Symonds | ce58ec9 | 2007-10-23 11:31:22 +1000 | [diff] [blame] | 1582 | if ($chopped eq $str) { |
| 1583 | return esc_html($chopped); |
| 1584 | } else { |
Jakub Narebski | 14afe77 | 2009-05-22 17:35:46 +0200 | [diff] [blame] | 1585 | $str =~ s/[[:cntrl:]]/?/g; |
Jakub Narebski | 850b90a | 2008-02-16 23:07:46 +0100 | [diff] [blame] | 1586 | return $cgi->span({-title=>$str}, esc_html($chopped)); |
David Symonds | ce58ec9 | 2007-10-23 11:31:22 +1000 | [diff] [blame] | 1587 | } |
| 1588 | } |
| 1589 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1590 | ## ---------------------------------------------------------------------- |
| 1591 | ## functions returning short strings |
| 1592 | |
Jakub Narebski | 1f1ab5f | 2006-06-20 14:58:12 +0000 | [diff] [blame] | 1593 | # CSS class for given age value (in seconds) |
| 1594 | sub age_class { |
| 1595 | my $age = shift; |
| 1596 | |
Jakub Narebski | 785cdea | 2007-05-13 12:39:22 +0200 | [diff] [blame] | 1597 | if (!defined $age) { |
| 1598 | return "noage"; |
| 1599 | } elsif ($age < 60*60*2) { |
Jakub Narebski | 1f1ab5f | 2006-06-20 14:58:12 +0000 | [diff] [blame] | 1600 | return "age0"; |
| 1601 | } elsif ($age < 60*60*24*2) { |
| 1602 | return "age1"; |
| 1603 | } else { |
| 1604 | return "age2"; |
| 1605 | } |
| 1606 | } |
| 1607 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1608 | # convert age in seconds to "nn units ago" string |
| 1609 | sub age_string { |
| 1610 | my $age = shift; |
| 1611 | my $age_str; |
| 1612 | |
| 1613 | if ($age > 60*60*24*365*2) { |
| 1614 | $age_str = (int $age/60/60/24/365); |
| 1615 | $age_str .= " years ago"; |
| 1616 | } elsif ($age > 60*60*24*(365/12)*2) { |
| 1617 | $age_str = int $age/60/60/24/(365/12); |
| 1618 | $age_str .= " months ago"; |
| 1619 | } elsif ($age > 60*60*24*7*2) { |
| 1620 | $age_str = int $age/60/60/24/7; |
| 1621 | $age_str .= " weeks ago"; |
| 1622 | } elsif ($age > 60*60*24*2) { |
| 1623 | $age_str = int $age/60/60/24; |
| 1624 | $age_str .= " days ago"; |
| 1625 | } elsif ($age > 60*60*2) { |
| 1626 | $age_str = int $age/60/60; |
| 1627 | $age_str .= " hours ago"; |
| 1628 | } elsif ($age > 60*2) { |
| 1629 | $age_str = int $age/60; |
| 1630 | $age_str .= " min ago"; |
| 1631 | } elsif ($age > 2) { |
| 1632 | $age_str = int $age; |
| 1633 | $age_str .= " sec ago"; |
| 1634 | } else { |
| 1635 | $age_str .= " right now"; |
| 1636 | } |
| 1637 | return $age_str; |
| 1638 | } |
| 1639 | |
Jakub Narebski | 01ac1e3 | 2007-07-28 16:27:31 +0200 | [diff] [blame] | 1640 | use constant { |
| 1641 | S_IFINVALID => 0030000, |
| 1642 | S_IFGITLINK => 0160000, |
| 1643 | }; |
| 1644 | |
| 1645 | # submodule/subproject, a commit object reference |
Jakub Narebski | 74fd872 | 2009-05-07 19:11:29 +0200 | [diff] [blame] | 1646 | sub S_ISGITLINK { |
Jakub Narebski | 01ac1e3 | 2007-07-28 16:27:31 +0200 | [diff] [blame] | 1647 | my $mode = shift; |
| 1648 | |
| 1649 | return (($mode & S_IFMT) == S_IFGITLINK) |
| 1650 | } |
| 1651 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1652 | # convert file mode in octal to symbolic file mode string |
| 1653 | sub mode_str { |
| 1654 | my $mode = oct shift; |
| 1655 | |
Jakub Narebski | 01ac1e3 | 2007-07-28 16:27:31 +0200 | [diff] [blame] | 1656 | if (S_ISGITLINK($mode)) { |
| 1657 | return 'm---------'; |
| 1658 | } elsif (S_ISDIR($mode & S_IFMT)) { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1659 | return 'drwxr-xr-x'; |
| 1660 | } elsif (S_ISLNK($mode)) { |
| 1661 | return 'lrwxrwxrwx'; |
| 1662 | } elsif (S_ISREG($mode)) { |
| 1663 | # git cares only about the executable bit |
| 1664 | if ($mode & S_IXUSR) { |
| 1665 | return '-rwxr-xr-x'; |
| 1666 | } else { |
| 1667 | return '-rw-r--r--'; |
| 1668 | }; |
| 1669 | } else { |
| 1670 | return '----------'; |
| 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | # convert file mode in octal to file type string |
| 1675 | sub file_type { |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 1676 | my $mode = shift; |
| 1677 | |
| 1678 | if ($mode !~ m/^[0-7]+$/) { |
| 1679 | return $mode; |
| 1680 | } else { |
| 1681 | $mode = oct $mode; |
| 1682 | } |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1683 | |
Jakub Narebski | 01ac1e3 | 2007-07-28 16:27:31 +0200 | [diff] [blame] | 1684 | if (S_ISGITLINK($mode)) { |
| 1685 | return "submodule"; |
| 1686 | } elsif (S_ISDIR($mode & S_IFMT)) { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1687 | return "directory"; |
| 1688 | } elsif (S_ISLNK($mode)) { |
| 1689 | return "symlink"; |
| 1690 | } elsif (S_ISREG($mode)) { |
| 1691 | return "file"; |
| 1692 | } else { |
| 1693 | return "unknown"; |
| 1694 | } |
| 1695 | } |
| 1696 | |
Jakub Narebski | 744d0ac | 2006-11-08 17:59:41 +0100 | [diff] [blame] | 1697 | # convert file mode in octal to file type description string |
| 1698 | sub file_type_long { |
| 1699 | my $mode = shift; |
| 1700 | |
| 1701 | if ($mode !~ m/^[0-7]+$/) { |
| 1702 | return $mode; |
| 1703 | } else { |
| 1704 | $mode = oct $mode; |
| 1705 | } |
| 1706 | |
Jakub Narebski | 01ac1e3 | 2007-07-28 16:27:31 +0200 | [diff] [blame] | 1707 | if (S_ISGITLINK($mode)) { |
| 1708 | return "submodule"; |
| 1709 | } elsif (S_ISDIR($mode & S_IFMT)) { |
Jakub Narebski | 744d0ac | 2006-11-08 17:59:41 +0100 | [diff] [blame] | 1710 | return "directory"; |
| 1711 | } elsif (S_ISLNK($mode)) { |
| 1712 | return "symlink"; |
| 1713 | } elsif (S_ISREG($mode)) { |
| 1714 | if ($mode & S_IXUSR) { |
| 1715 | return "executable"; |
| 1716 | } else { |
| 1717 | return "file"; |
| 1718 | }; |
| 1719 | } else { |
| 1720 | return "unknown"; |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1725 | ## ---------------------------------------------------------------------- |
| 1726 | ## functions returning short HTML fragments, or transforming HTML fragments |
Pavel Roskin | 3dff537 | 2007-02-03 23:49:16 -0500 | [diff] [blame] | 1727 | ## which don't belong to other sections |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1728 | |
Junio C Hamano | 225932e | 2006-11-09 00:57:13 -0800 | [diff] [blame] | 1729 | # format line of commit message. |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1730 | sub format_log_line_html { |
| 1731 | my $line = shift; |
| 1732 | |
Junio C Hamano | 225932e | 2006-11-09 00:57:13 -0800 | [diff] [blame] | 1733 | $line = esc_html($line, -nbsp=>1); |
Marcel M. Cary | 7d233de | 2009-02-17 19:00:43 -0800 | [diff] [blame] | 1734 | $line =~ s{\b([0-9a-fA-F]{8,40})\b}{ |
| 1735 | $cgi->a({-href => href(action=>"object", hash=>$1), |
| 1736 | -class => "text"}, $1); |
| 1737 | }eg; |
| 1738 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1739 | return $line; |
| 1740 | } |
| 1741 | |
| 1742 | # format marker of refs pointing to given object |
Giuseppe Bilotta | 4afbaef | 2008-09-02 21:47:05 +0200 | [diff] [blame] | 1743 | |
| 1744 | # the destination action is chosen based on object type and current context: |
| 1745 | # - for annotated tags, we choose the tag view unless it's the current view |
| 1746 | # already, in which case we go to shortlog view |
| 1747 | # - for other refs, we keep the current view if we're in history, shortlog or |
| 1748 | # log view, and select shortlog otherwise |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 1749 | sub format_ref_marker { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1750 | my ($refs, $id) = @_; |
Jakub Narebski | d294e1c | 2006-08-14 02:14:20 +0200 | [diff] [blame] | 1751 | my $markers = ''; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1752 | |
| 1753 | if (defined $refs->{$id}) { |
Jakub Narebski | d294e1c | 2006-08-14 02:14:20 +0200 | [diff] [blame] | 1754 | foreach my $ref (@{$refs->{$id}}) { |
Giuseppe Bilotta | 4afbaef | 2008-09-02 21:47:05 +0200 | [diff] [blame] | 1755 | # this code exploits the fact that non-lightweight tags are the |
| 1756 | # only indirect objects, and that they are the only objects for which |
| 1757 | # we want to use tag instead of shortlog as action |
Jakub Narebski | d294e1c | 2006-08-14 02:14:20 +0200 | [diff] [blame] | 1758 | my ($type, $name) = qw(); |
Giuseppe Bilotta | 4afbaef | 2008-09-02 21:47:05 +0200 | [diff] [blame] | 1759 | my $indirect = ($ref =~ s/\^\{\}$//); |
Jakub Narebski | d294e1c | 2006-08-14 02:14:20 +0200 | [diff] [blame] | 1760 | # e.g. tags/v2.6.11 or heads/next |
| 1761 | if ($ref =~ m!^(.*?)s?/(.*)$!) { |
| 1762 | $type = $1; |
| 1763 | $name = $2; |
| 1764 | } else { |
| 1765 | $type = "ref"; |
| 1766 | $name = $ref; |
| 1767 | } |
| 1768 | |
Giuseppe Bilotta | 4afbaef | 2008-09-02 21:47:05 +0200 | [diff] [blame] | 1769 | my $class = $type; |
| 1770 | $class .= " indirect" if $indirect; |
| 1771 | |
| 1772 | my $dest_action = "shortlog"; |
| 1773 | |
| 1774 | if ($indirect) { |
| 1775 | $dest_action = "tag" unless $action eq "tag"; |
| 1776 | } elsif ($action =~ /^(history|(short)?log)$/) { |
| 1777 | $dest_action = $action; |
| 1778 | } |
| 1779 | |
| 1780 | my $dest = ""; |
| 1781 | $dest .= "refs/" unless $ref =~ m!^refs/!; |
| 1782 | $dest .= $ref; |
| 1783 | |
| 1784 | my $link = $cgi->a({ |
| 1785 | -href => href( |
| 1786 | action=>$dest_action, |
| 1787 | hash=>$dest |
| 1788 | )}, $name); |
| 1789 | |
| 1790 | $markers .= " <span class=\"$class\" title=\"$ref\">" . |
| 1791 | $link . "</span>"; |
Jakub Narebski | d294e1c | 2006-08-14 02:14:20 +0200 | [diff] [blame] | 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | if ($markers) { |
| 1796 | return ' <span class="refs">'. $markers . '</span>'; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 1797 | } else { |
| 1798 | return ""; |
| 1799 | } |
| 1800 | } |
| 1801 | |
Jakub Narebski | 17d0744 | 2006-08-14 02:08:27 +0200 | [diff] [blame] | 1802 | # format, perhaps shortened and with markers, title line |
| 1803 | sub format_subject_html { |
Martin Waitz | 1c2a4f5 | 2006-08-16 00:24:30 +0200 | [diff] [blame] | 1804 | my ($long, $short, $href, $extra) = @_; |
Jakub Narebski | 17d0744 | 2006-08-14 02:08:27 +0200 | [diff] [blame] | 1805 | $extra = '' unless defined($extra); |
| 1806 | |
| 1807 | if (length($short) < length($long)) { |
Jakub Narebski | 14afe77 | 2009-05-22 17:35:46 +0200 | [diff] [blame] | 1808 | $long =~ s/[[:cntrl:]]/?/g; |
Jakub Narebski | 7c27801 | 2006-08-22 12:02:48 +0200 | [diff] [blame] | 1809 | return $cgi->a({-href => $href, -class => "list subject", |
Martin Koegler | 00f429a | 2007-06-03 17:42:44 +0200 | [diff] [blame] | 1810 | -title => to_utf8($long)}, |
Giuseppe Bilotta | 01b89f0 | 2009-08-23 10:28:09 +0200 | [diff] [blame] | 1811 | esc_html($short)) . $extra; |
Jakub Narebski | 17d0744 | 2006-08-14 02:08:27 +0200 | [diff] [blame] | 1812 | } else { |
Jakub Narebski | 7c27801 | 2006-08-22 12:02:48 +0200 | [diff] [blame] | 1813 | return $cgi->a({-href => $href, -class => "list subject"}, |
Giuseppe Bilotta | 01b89f0 | 2009-08-23 10:28:09 +0200 | [diff] [blame] | 1814 | esc_html($long)) . $extra; |
Jakub Narebski | 17d0744 | 2006-08-14 02:08:27 +0200 | [diff] [blame] | 1815 | } |
| 1816 | } |
| 1817 | |
Giuseppe Bilotta | 5a371b7 | 2009-06-30 00:00:52 +0200 | [diff] [blame] | 1818 | # Rather than recomputing the url for an email multiple times, we cache it |
| 1819 | # after the first hit. This gives a visible benefit in views where the avatar |
| 1820 | # for the same email is used repeatedly (e.g. shortlog). |
| 1821 | # The cache is shared by all avatar engines (currently gravatar only), which |
| 1822 | # are free to use it as preferred. Since only one avatar engine is used for any |
| 1823 | # given page, there's no risk for cache conflicts. |
| 1824 | our %avatar_cache = (); |
| 1825 | |
Giuseppe Bilotta | 679a1a1 | 2009-06-30 00:00:53 +0200 | [diff] [blame] | 1826 | # Compute the picon url for a given email, by using the picon search service over at |
| 1827 | # http://www.cs.indiana.edu/picons/search.html |
| 1828 | sub picon_url { |
| 1829 | my $email = lc shift; |
| 1830 | if (!$avatar_cache{$email}) { |
| 1831 | my ($user, $domain) = split('@', $email); |
| 1832 | $avatar_cache{$email} = |
| 1833 | "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" . |
| 1834 | "$domain/$user/" . |
| 1835 | "users+domains+unknown/up/single"; |
| 1836 | } |
| 1837 | return $avatar_cache{$email}; |
| 1838 | } |
| 1839 | |
Giuseppe Bilotta | 5a371b7 | 2009-06-30 00:00:52 +0200 | [diff] [blame] | 1840 | # Compute the gravatar url for a given email, if it's not in the cache already. |
| 1841 | # Gravatar stores only the part of the URL before the size, since that's the |
| 1842 | # one computationally more expensive. This also allows reuse of the cache for |
| 1843 | # different sizes (for this particular engine). |
| 1844 | sub gravatar_url { |
| 1845 | my $email = lc shift; |
| 1846 | my $size = shift; |
| 1847 | $avatar_cache{$email} ||= |
| 1848 | "http://www.gravatar.com/avatar/" . |
| 1849 | Digest::MD5::md5_hex($email) . "?s="; |
| 1850 | return $avatar_cache{$email} . $size; |
| 1851 | } |
| 1852 | |
Giuseppe Bilotta | e9fdd74 | 2009-06-30 00:00:51 +0200 | [diff] [blame] | 1853 | # Insert an avatar for the given $email at the given $size if the feature |
| 1854 | # is enabled. |
| 1855 | sub git_get_avatar { |
| 1856 | my ($email, %opts) = @_; |
| 1857 | my $pre_white = ($opts{-pad_before} ? " " : ""); |
| 1858 | my $post_white = ($opts{-pad_after} ? " " : ""); |
| 1859 | $opts{-size} ||= 'default'; |
| 1860 | my $size = $avatar_size{$opts{-size}} || $avatar_size{'default'}; |
| 1861 | my $url = ""; |
| 1862 | if ($git_avatar eq 'gravatar') { |
Giuseppe Bilotta | 5a371b7 | 2009-06-30 00:00:52 +0200 | [diff] [blame] | 1863 | $url = gravatar_url($email, $size); |
Giuseppe Bilotta | 679a1a1 | 2009-06-30 00:00:53 +0200 | [diff] [blame] | 1864 | } elsif ($git_avatar eq 'picon') { |
| 1865 | $url = picon_url($email); |
Giuseppe Bilotta | e9fdd74 | 2009-06-30 00:00:51 +0200 | [diff] [blame] | 1866 | } |
Giuseppe Bilotta | 679a1a1 | 2009-06-30 00:00:53 +0200 | [diff] [blame] | 1867 | # Other providers can be added by extending the if chain, defining $url |
Giuseppe Bilotta | e9fdd74 | 2009-06-30 00:00:51 +0200 | [diff] [blame] | 1868 | # as needed. If no variant puts something in $url, we assume avatars |
| 1869 | # are completely disabled/unavailable. |
| 1870 | if ($url) { |
| 1871 | return $pre_white . |
| 1872 | "<img width=\"$size\" " . |
| 1873 | "class=\"avatar\" " . |
| 1874 | "src=\"$url\" " . |
Giuseppe Bilotta | 7d25ef4 | 2009-06-30 00:00:54 +0200 | [diff] [blame] | 1875 | "alt=\"\" " . |
Giuseppe Bilotta | e9fdd74 | 2009-06-30 00:00:51 +0200 | [diff] [blame] | 1876 | "/>" . $post_white; |
| 1877 | } else { |
| 1878 | return ""; |
| 1879 | } |
| 1880 | } |
| 1881 | |
Stephen Boyd | e133d65 | 2009-10-15 21:14:59 -0700 | [diff] [blame] | 1882 | sub format_search_author { |
| 1883 | my ($author, $searchtype, $displaytext) = @_; |
| 1884 | my $have_search = gitweb_check_feature('search'); |
| 1885 | |
| 1886 | if ($have_search) { |
| 1887 | my $performed = ""; |
| 1888 | if ($searchtype eq 'author') { |
| 1889 | $performed = "authored"; |
| 1890 | } elsif ($searchtype eq 'committer') { |
| 1891 | $performed = "committed"; |
| 1892 | } |
| 1893 | |
| 1894 | return $cgi->a({-href => href(action=>"search", hash=>$hash, |
| 1895 | searchtext=>$author, |
| 1896 | searchtype=>$searchtype), class=>"list", |
| 1897 | title=>"Search for commits $performed by $author"}, |
| 1898 | $displaytext); |
| 1899 | |
| 1900 | } else { |
| 1901 | return $displaytext; |
| 1902 | } |
| 1903 | } |
| 1904 | |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 1905 | # format the author name of the given commit with the given tag |
| 1906 | # the author name is chopped and escaped according to the other |
| 1907 | # optional parameters (see chop_str). |
| 1908 | sub format_author_html { |
| 1909 | my $tag = shift; |
| 1910 | my $co = shift; |
| 1911 | my $author = chop_and_escape_str($co->{'author_name'}, @_); |
Giuseppe Bilotta | e9fdd74 | 2009-06-30 00:00:51 +0200 | [diff] [blame] | 1912 | return "<$tag class=\"author\">" . |
Stephen Boyd | e133d65 | 2009-10-15 21:14:59 -0700 | [diff] [blame] | 1913 | format_search_author($co->{'author_name'}, "author", |
| 1914 | git_get_avatar($co->{'author_email'}, -pad_after => 1) . |
| 1915 | $author) . |
| 1916 | "</$tag>"; |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 1917 | } |
| 1918 | |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 1919 | # format git diff header line, i.e. "diff --(git|combined|cc) ..." |
| 1920 | sub format_git_diff_header_line { |
| 1921 | my $line = shift; |
| 1922 | my $diffinfo = shift; |
| 1923 | my ($from, $to) = @_; |
| 1924 | |
| 1925 | if ($diffinfo->{'nparents'}) { |
| 1926 | # combined diff |
| 1927 | $line =~ s!^(diff (.*?) )"?.*$!$1!; |
| 1928 | if ($to->{'href'}) { |
| 1929 | $line .= $cgi->a({-href => $to->{'href'}, -class => "path"}, |
| 1930 | esc_path($to->{'file'})); |
| 1931 | } else { # file was deleted (no href) |
| 1932 | $line .= esc_path($to->{'file'}); |
| 1933 | } |
| 1934 | } else { |
| 1935 | # "ordinary" diff |
| 1936 | $line =~ s!^(diff (.*?) )"?a/.*$!$1!; |
| 1937 | if ($from->{'href'}) { |
| 1938 | $line .= $cgi->a({-href => $from->{'href'}, -class => "path"}, |
| 1939 | 'a/' . esc_path($from->{'file'})); |
| 1940 | } else { # file was added (no href) |
| 1941 | $line .= 'a/' . esc_path($from->{'file'}); |
| 1942 | } |
| 1943 | $line .= ' '; |
| 1944 | if ($to->{'href'}) { |
| 1945 | $line .= $cgi->a({-href => $to->{'href'}, -class => "path"}, |
| 1946 | 'b/' . esc_path($to->{'file'})); |
| 1947 | } else { # file was deleted |
| 1948 | $line .= 'b/' . esc_path($to->{'file'}); |
| 1949 | } |
| 1950 | } |
| 1951 | |
| 1952 | return "<div class=\"diff header\">$line</div>\n"; |
| 1953 | } |
| 1954 | |
| 1955 | # format extended diff header line, before patch itself |
| 1956 | sub format_extended_diff_header_line { |
| 1957 | my $line = shift; |
| 1958 | my $diffinfo = shift; |
| 1959 | my ($from, $to) = @_; |
| 1960 | |
| 1961 | # match <path> |
| 1962 | if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) { |
| 1963 | $line .= $cgi->a({-href=>$from->{'href'}, -class=>"path"}, |
| 1964 | esc_path($from->{'file'})); |
| 1965 | } |
| 1966 | if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) { |
| 1967 | $line .= $cgi->a({-href=>$to->{'href'}, -class=>"path"}, |
| 1968 | esc_path($to->{'file'})); |
| 1969 | } |
| 1970 | # match single <mode> |
| 1971 | if ($line =~ m/\s(\d{6})$/) { |
| 1972 | $line .= '<span class="info"> (' . |
| 1973 | file_type_long($1) . |
| 1974 | ')</span>'; |
| 1975 | } |
| 1976 | # match <hash> |
| 1977 | if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) { |
| 1978 | # can match only for combined diff |
| 1979 | $line = 'index '; |
| 1980 | for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) { |
| 1981 | if ($from->{'href'}[$i]) { |
| 1982 | $line .= $cgi->a({-href=>$from->{'href'}[$i], |
| 1983 | -class=>"hash"}, |
| 1984 | substr($diffinfo->{'from_id'}[$i],0,7)); |
| 1985 | } else { |
| 1986 | $line .= '0' x 7; |
| 1987 | } |
| 1988 | # separator |
| 1989 | $line .= ',' if ($i < $diffinfo->{'nparents'} - 1); |
| 1990 | } |
| 1991 | $line .= '..'; |
| 1992 | if ($to->{'href'}) { |
| 1993 | $line .= $cgi->a({-href=>$to->{'href'}, -class=>"hash"}, |
| 1994 | substr($diffinfo->{'to_id'},0,7)); |
| 1995 | } else { |
| 1996 | $line .= '0' x 7; |
| 1997 | } |
| 1998 | |
| 1999 | } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) { |
| 2000 | # can match only for ordinary diff |
| 2001 | my ($from_link, $to_link); |
| 2002 | if ($from->{'href'}) { |
| 2003 | $from_link = $cgi->a({-href=>$from->{'href'}, -class=>"hash"}, |
| 2004 | substr($diffinfo->{'from_id'},0,7)); |
| 2005 | } else { |
| 2006 | $from_link = '0' x 7; |
| 2007 | } |
| 2008 | if ($to->{'href'}) { |
| 2009 | $to_link = $cgi->a({-href=>$to->{'href'}, -class=>"hash"}, |
| 2010 | substr($diffinfo->{'to_id'},0,7)); |
| 2011 | } else { |
| 2012 | $to_link = '0' x 7; |
| 2013 | } |
| 2014 | my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'}); |
| 2015 | $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!; |
| 2016 | } |
| 2017 | |
| 2018 | return $line . "<br/>\n"; |
| 2019 | } |
| 2020 | |
| 2021 | # format from-file/to-file diff header |
| 2022 | sub format_diff_from_to_header { |
Jakub Narebski | 91af4ce | 2007-06-08 13:32:44 +0200 | [diff] [blame] | 2023 | my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_; |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 2024 | my $line; |
| 2025 | my $result = ''; |
| 2026 | |
| 2027 | $line = $from_line; |
| 2028 | #assert($line =~ m/^---/) if DEBUG; |
Jakub Narebski | deaa01a | 2007-06-08 13:29:49 +0200 | [diff] [blame] | 2029 | # no extra formatting for "^--- /dev/null" |
| 2030 | if (! $diffinfo->{'nparents'}) { |
| 2031 | # ordinary (single parent) diff |
| 2032 | if ($line =~ m!^--- "?a/!) { |
| 2033 | if ($from->{'href'}) { |
| 2034 | $line = '--- a/' . |
| 2035 | $cgi->a({-href=>$from->{'href'}, -class=>"path"}, |
| 2036 | esc_path($from->{'file'})); |
| 2037 | } else { |
| 2038 | $line = '--- a/' . |
| 2039 | esc_path($from->{'file'}); |
| 2040 | } |
| 2041 | } |
| 2042 | $result .= qq!<div class="diff from_file">$line</div>\n!; |
| 2043 | |
| 2044 | } else { |
| 2045 | # combined diff (merge commit) |
| 2046 | for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) { |
| 2047 | if ($from->{'href'}[$i]) { |
| 2048 | $line = '--- ' . |
Jakub Narebski | 91af4ce | 2007-06-08 13:32:44 +0200 | [diff] [blame] | 2049 | $cgi->a({-href=>href(action=>"blobdiff", |
| 2050 | hash_parent=>$diffinfo->{'from_id'}[$i], |
| 2051 | hash_parent_base=>$parents[$i], |
| 2052 | file_parent=>$from->{'file'}[$i], |
| 2053 | hash=>$diffinfo->{'to_id'}, |
| 2054 | hash_base=>$hash, |
| 2055 | file_name=>$to->{'file'}), |
| 2056 | -class=>"path", |
| 2057 | -title=>"diff" . ($i+1)}, |
| 2058 | $i+1) . |
| 2059 | '/' . |
Jakub Narebski | deaa01a | 2007-06-08 13:29:49 +0200 | [diff] [blame] | 2060 | $cgi->a({-href=>$from->{'href'}[$i], -class=>"path"}, |
| 2061 | esc_path($from->{'file'}[$i])); |
| 2062 | } else { |
| 2063 | $line = '--- /dev/null'; |
| 2064 | } |
| 2065 | $result .= qq!<div class="diff from_file">$line</div>\n!; |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 2066 | } |
| 2067 | } |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 2068 | |
| 2069 | $line = $to_line; |
| 2070 | #assert($line =~ m/^\+\+\+/) if DEBUG; |
| 2071 | # no extra formatting for "^+++ /dev/null" |
| 2072 | if ($line =~ m!^\+\+\+ "?b/!) { |
| 2073 | if ($to->{'href'}) { |
| 2074 | $line = '+++ b/' . |
| 2075 | $cgi->a({-href=>$to->{'href'}, -class=>"path"}, |
| 2076 | esc_path($to->{'file'})); |
| 2077 | } else { |
| 2078 | $line = '+++ b/' . |
| 2079 | esc_path($to->{'file'}); |
| 2080 | } |
| 2081 | } |
| 2082 | $result .= qq!<div class="diff to_file">$line</div>\n!; |
| 2083 | |
| 2084 | return $result; |
| 2085 | } |
| 2086 | |
Jakub Narebski | cd030c3 | 2007-06-08 13:33:28 +0200 | [diff] [blame] | 2087 | # create note for patch simplified by combined diff |
| 2088 | sub format_diff_cc_simplified { |
| 2089 | my ($diffinfo, @parents) = @_; |
| 2090 | my $result = ''; |
| 2091 | |
| 2092 | $result .= "<div class=\"diff header\">" . |
| 2093 | "diff --cc "; |
| 2094 | if (!is_deleted($diffinfo)) { |
| 2095 | $result .= $cgi->a({-href => href(action=>"blob", |
| 2096 | hash_base=>$hash, |
| 2097 | hash=>$diffinfo->{'to_id'}, |
| 2098 | file_name=>$diffinfo->{'to_file'}), |
| 2099 | -class => "path"}, |
| 2100 | esc_path($diffinfo->{'to_file'})); |
| 2101 | } else { |
| 2102 | $result .= esc_path($diffinfo->{'to_file'}); |
| 2103 | } |
| 2104 | $result .= "</div>\n" . # class="diff header" |
| 2105 | "<div class=\"diff nodifferences\">" . |
| 2106 | "Simple merge" . |
| 2107 | "</div>\n"; # class="diff nodifferences" |
| 2108 | |
| 2109 | return $result; |
| 2110 | } |
| 2111 | |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 2112 | # format patch (diff) line (not to be used for diff headers) |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 2113 | sub format_diff_line { |
| 2114 | my $line = shift; |
Jakub Narebski | 59e3b14 | 2006-11-18 23:35:40 +0100 | [diff] [blame] | 2115 | my ($from, $to) = @_; |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 2116 | my $diff_class = ""; |
| 2117 | |
| 2118 | chomp $line; |
| 2119 | |
Jakub Narebski | e72c0ea | 2007-05-07 01:10:05 +0200 | [diff] [blame] | 2120 | if ($from && $to && ref($from->{'href'}) eq "ARRAY") { |
| 2121 | # combined diff |
| 2122 | my $prefix = substr($line, 0, scalar @{$from->{'href'}}); |
| 2123 | if ($line =~ m/^\@{3}/) { |
| 2124 | $diff_class = " chunk_header"; |
| 2125 | } elsif ($line =~ m/^\\/) { |
| 2126 | $diff_class = " incomplete"; |
| 2127 | } elsif ($prefix =~ tr/+/+/) { |
| 2128 | $diff_class = " add"; |
| 2129 | } elsif ($prefix =~ tr/-/-/) { |
| 2130 | $diff_class = " rem"; |
| 2131 | } |
| 2132 | } else { |
| 2133 | # assume ordinary diff |
| 2134 | my $char = substr($line, 0, 1); |
| 2135 | if ($char eq '+') { |
| 2136 | $diff_class = " add"; |
| 2137 | } elsif ($char eq '-') { |
| 2138 | $diff_class = " rem"; |
| 2139 | } elsif ($char eq '@') { |
| 2140 | $diff_class = " chunk_header"; |
| 2141 | } elsif ($char eq "\\") { |
| 2142 | $diff_class = " incomplete"; |
| 2143 | } |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 2144 | } |
| 2145 | $line = untabify($line); |
Jakub Narebski | 59e3b14 | 2006-11-18 23:35:40 +0100 | [diff] [blame] | 2146 | if ($from && $to && $line =~ m/^\@{2} /) { |
| 2147 | my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) = |
| 2148 | $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/; |
| 2149 | |
| 2150 | $from_lines = 0 unless defined $from_lines; |
| 2151 | $to_lines = 0 unless defined $to_lines; |
| 2152 | |
| 2153 | if ($from->{'href'}) { |
| 2154 | $from_text = $cgi->a({-href=>"$from->{'href'}#l$from_start", |
| 2155 | -class=>"list"}, $from_text); |
| 2156 | } |
| 2157 | if ($to->{'href'}) { |
| 2158 | $to_text = $cgi->a({-href=>"$to->{'href'}#l$to_start", |
| 2159 | -class=>"list"}, $to_text); |
| 2160 | } |
| 2161 | $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" . |
| 2162 | "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>"; |
| 2163 | return "<div class=\"diff$diff_class\">$line</div>\n"; |
Jakub Narebski | e72c0ea | 2007-05-07 01:10:05 +0200 | [diff] [blame] | 2164 | } elsif ($from && $to && $line =~ m/^\@{3}/) { |
| 2165 | my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/; |
| 2166 | my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines); |
| 2167 | |
| 2168 | @from_text = split(' ', $ranges); |
| 2169 | for (my $i = 0; $i < @from_text; ++$i) { |
| 2170 | ($from_start[$i], $from_nlines[$i]) = |
| 2171 | (split(',', substr($from_text[$i], 1)), 0); |
| 2172 | } |
| 2173 | |
| 2174 | $to_text = pop @from_text; |
| 2175 | $to_start = pop @from_start; |
| 2176 | $to_nlines = pop @from_nlines; |
| 2177 | |
| 2178 | $line = "<span class=\"chunk_info\">$prefix "; |
| 2179 | for (my $i = 0; $i < @from_text; ++$i) { |
| 2180 | if ($from->{'href'}[$i]) { |
| 2181 | $line .= $cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]", |
| 2182 | -class=>"list"}, $from_text[$i]); |
| 2183 | } else { |
| 2184 | $line .= $from_text[$i]; |
| 2185 | } |
| 2186 | $line .= " "; |
| 2187 | } |
| 2188 | if ($to->{'href'}) { |
| 2189 | $line .= $cgi->a({-href=>"$to->{'href'}#l$to_start", |
| 2190 | -class=>"list"}, $to_text); |
| 2191 | } else { |
| 2192 | $line .= $to_text; |
| 2193 | } |
| 2194 | $line .= " $prefix</span>" . |
| 2195 | "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>"; |
| 2196 | return "<div class=\"diff$diff_class\">$line</div>\n"; |
Jakub Narebski | 59e3b14 | 2006-11-18 23:35:40 +0100 | [diff] [blame] | 2197 | } |
Jakub Narebski | 6255ef0 | 2006-11-01 14:33:21 +0100 | [diff] [blame] | 2198 | return "<div class=\"diff$diff_class\">" . esc_html($line, -nbsp=>1) . "</div>\n"; |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 2199 | } |
| 2200 | |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 2201 | # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)", |
| 2202 | # linked. Pass the hash of the tree/commit to snapshot. |
| 2203 | sub format_snapshot_links { |
| 2204 | my ($hash) = @_; |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 2205 | my $num_fmts = @snapshot_fmts; |
| 2206 | if ($num_fmts > 1) { |
| 2207 | # A parenthesized list of links bearing format names. |
Jakub Narebski | a781785 | 2007-07-22 23:41:20 +0200 | [diff] [blame] | 2208 | # e.g. "snapshot (_tar.gz_ _zip_)" |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 2209 | return "snapshot (" . join(' ', map |
| 2210 | $cgi->a({ |
| 2211 | -href => href( |
| 2212 | action=>"snapshot", |
| 2213 | hash=>$hash, |
| 2214 | snapshot_format=>$_ |
| 2215 | ) |
| 2216 | }, $known_snapshot_formats{$_}{'display'}) |
| 2217 | , @snapshot_fmts) . ")"; |
| 2218 | } elsif ($num_fmts == 1) { |
| 2219 | # A single "snapshot" link whose tooltip bears the format name. |
Jakub Narebski | a781785 | 2007-07-22 23:41:20 +0200 | [diff] [blame] | 2220 | # i.e. "_snapshot_" |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 2221 | my ($fmt) = @snapshot_fmts; |
Jakub Narebski | a781785 | 2007-07-22 23:41:20 +0200 | [diff] [blame] | 2222 | return |
| 2223 | $cgi->a({ |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 2224 | -href => href( |
| 2225 | action=>"snapshot", |
| 2226 | hash=>$hash, |
| 2227 | snapshot_format=>$fmt |
| 2228 | ), |
| 2229 | -title => "in format: $known_snapshot_formats{$fmt}{'display'}" |
| 2230 | }, "snapshot"); |
| 2231 | } else { # $num_fmts == 0 |
| 2232 | return undef; |
| 2233 | } |
| 2234 | } |
| 2235 | |
Jakub Narebski | 3562198 | 2008-04-20 22:09:48 +0200 | [diff] [blame] | 2236 | ## ...................................................................... |
| 2237 | ## functions returning values to be passed, perhaps after some |
| 2238 | ## transformation, to other functions; e.g. returning arguments to href() |
| 2239 | |
| 2240 | # returns hash to be passed to href to generate gitweb URL |
| 2241 | # in -title key it returns description of link |
| 2242 | sub get_feed_info { |
| 2243 | my $format = shift || 'Atom'; |
| 2244 | my %res = (action => lc($format)); |
| 2245 | |
| 2246 | # feed links are possible only for project views |
| 2247 | return unless (defined $project); |
| 2248 | # some views should link to OPML, or to generic project feed, |
| 2249 | # or don't have specific feed yet (so they should use generic) |
| 2250 | return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x); |
| 2251 | |
| 2252 | my $branch; |
| 2253 | # branches refs uses 'refs/heads/' prefix (fullname) to differentiate |
| 2254 | # from tag links; this also makes possible to detect branch links |
| 2255 | if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) || |
| 2256 | (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) { |
| 2257 | $branch = $1; |
| 2258 | } |
| 2259 | # find log type for feed description (title) |
| 2260 | my $type = 'log'; |
| 2261 | if (defined $file_name) { |
| 2262 | $type = "history of $file_name"; |
| 2263 | $type .= "/" if ($action eq 'tree'); |
| 2264 | $type .= " on '$branch'" if (defined $branch); |
| 2265 | } else { |
| 2266 | $type = "log of $branch" if (defined $branch); |
| 2267 | } |
| 2268 | |
| 2269 | $res{-title} = $type; |
| 2270 | $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef); |
| 2271 | $res{'file_name'} = $file_name; |
| 2272 | |
| 2273 | return %res; |
| 2274 | } |
| 2275 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2276 | ## ---------------------------------------------------------------------- |
| 2277 | ## git utility subroutines, invoking git commands |
| 2278 | |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 2279 | # returns path to the core git executable and the --git-dir parameter as list |
| 2280 | sub git_cmd { |
Jakub Narebski | aa7dd05 | 2009-09-01 13:39:16 +0200 | [diff] [blame] | 2281 | $number_of_git_cmds++; |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 2282 | return $GIT, '--git-dir='.$git_dir; |
| 2283 | } |
| 2284 | |
Lea Wiemann | 516381d | 2008-06-17 23:46:35 +0200 | [diff] [blame] | 2285 | # quote the given arguments for passing them to the shell |
| 2286 | # quote_command("command", "arg 1", "arg with ' and ! characters") |
| 2287 | # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'" |
| 2288 | # Try to avoid using this function wherever possible. |
| 2289 | sub quote_command { |
| 2290 | return join(' ', |
Jakub Narebski | 68cedb1 | 2009-05-10 02:40:37 +0200 | [diff] [blame] | 2291 | map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ); |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 2292 | } |
| 2293 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2294 | # get HEAD ref of given project as hash |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 2295 | sub git_get_head_hash { |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 2296 | return git_get_full_hash(shift, 'HEAD'); |
| 2297 | } |
| 2298 | |
| 2299 | sub git_get_full_hash { |
| 2300 | return git_get_hash(@_); |
| 2301 | } |
| 2302 | |
| 2303 | sub git_get_short_hash { |
| 2304 | return git_get_hash(@_, '--short=7'); |
| 2305 | } |
| 2306 | |
| 2307 | sub git_get_hash { |
| 2308 | my ($project, $hash, @options) = @_; |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 2309 | my $o_git_dir = $git_dir; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2310 | my $retval = undef; |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 2311 | $git_dir = "$projectroot/$project"; |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 2312 | if (open my $fd, '-|', git_cmd(), 'rev-parse', |
| 2313 | '--verify', '-q', @options, $hash) { |
| 2314 | $retval = <$fd>; |
| 2315 | chomp $retval if defined $retval; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2316 | close $fd; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2317 | } |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 2318 | if (defined $o_git_dir) { |
| 2319 | $git_dir = $o_git_dir; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2320 | } |
| 2321 | return $retval; |
| 2322 | } |
| 2323 | |
| 2324 | # get type of given object |
| 2325 | sub git_get_type { |
| 2326 | my $hash = shift; |
| 2327 | |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 2328 | open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2329 | my $type = <$fd>; |
| 2330 | close $fd or return; |
| 2331 | chomp $type; |
| 2332 | return $type; |
| 2333 | } |
| 2334 | |
Jakub Narebski | b201927 | 2007-11-03 00:41:19 +0100 | [diff] [blame] | 2335 | # repository configuration |
| 2336 | our $config_file = ''; |
| 2337 | our %config; |
| 2338 | |
| 2339 | # store multiple values for single key as anonymous array reference |
| 2340 | # single values stored directly in the hash, not as [ <value> ] |
| 2341 | sub hash_set_multi { |
| 2342 | my ($hash, $key, $value) = @_; |
| 2343 | |
| 2344 | if (!exists $hash->{$key}) { |
| 2345 | $hash->{$key} = $value; |
| 2346 | } elsif (!ref $hash->{$key}) { |
| 2347 | $hash->{$key} = [ $hash->{$key}, $value ]; |
| 2348 | } else { |
| 2349 | push @{$hash->{$key}}, $value; |
| 2350 | } |
| 2351 | } |
| 2352 | |
| 2353 | # return hash of git project configuration |
| 2354 | # optionally limited to some section, e.g. 'gitweb' |
| 2355 | sub git_parse_project_config { |
| 2356 | my $section_regexp = shift; |
| 2357 | my %config; |
| 2358 | |
| 2359 | local $/ = "\0"; |
| 2360 | |
| 2361 | open my $fh, "-|", git_cmd(), "config", '-z', '-l', |
| 2362 | or return; |
| 2363 | |
| 2364 | while (my $keyval = <$fh>) { |
| 2365 | chomp $keyval; |
| 2366 | my ($key, $value) = split(/\n/, $keyval, 2); |
| 2367 | |
| 2368 | hash_set_multi(\%config, $key, $value) |
| 2369 | if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o); |
| 2370 | } |
| 2371 | close $fh; |
| 2372 | |
| 2373 | return %config; |
| 2374 | } |
| 2375 | |
Marcel M. Cary | df5d10a | 2009-02-18 14:09:41 +0100 | [diff] [blame] | 2376 | # convert config value to boolean: 'true' or 'false' |
Jakub Narebski | b201927 | 2007-11-03 00:41:19 +0100 | [diff] [blame] | 2377 | # no value, number > 0, 'true' and 'yes' values are true |
| 2378 | # rest of values are treated as false (never as error) |
| 2379 | sub config_to_bool { |
| 2380 | my $val = shift; |
| 2381 | |
Marcel M. Cary | df5d10a | 2009-02-18 14:09:41 +0100 | [diff] [blame] | 2382 | return 1 if !defined $val; # section.key |
| 2383 | |
Jakub Narebski | b201927 | 2007-11-03 00:41:19 +0100 | [diff] [blame] | 2384 | # strip leading and trailing whitespace |
| 2385 | $val =~ s/^\s+//; |
| 2386 | $val =~ s/\s+$//; |
| 2387 | |
Marcel M. Cary | df5d10a | 2009-02-18 14:09:41 +0100 | [diff] [blame] | 2388 | return (($val =~ /^\d+$/ && $val) || # section.key = 1 |
Jakub Narebski | b201927 | 2007-11-03 00:41:19 +0100 | [diff] [blame] | 2389 | ($val =~ /^(?:true|yes)$/i)); # section.key = true |
| 2390 | } |
| 2391 | |
| 2392 | # convert config value to simple decimal number |
| 2393 | # an optional value suffix of 'k', 'm', or 'g' will cause the value |
| 2394 | # to be multiplied by 1024, 1048576, or 1073741824 |
| 2395 | sub config_to_int { |
| 2396 | my $val = shift; |
| 2397 | |
| 2398 | # strip leading and trailing whitespace |
| 2399 | $val =~ s/^\s+//; |
| 2400 | $val =~ s/\s+$//; |
| 2401 | |
| 2402 | if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) { |
| 2403 | $unit = lc($unit); |
| 2404 | # unknown unit is treated as 1 |
| 2405 | return $num * ($unit eq 'g' ? 1073741824 : |
| 2406 | $unit eq 'm' ? 1048576 : |
| 2407 | $unit eq 'k' ? 1024 : 1); |
| 2408 | } |
| 2409 | return $val; |
| 2410 | } |
| 2411 | |
| 2412 | # convert config value to array reference, if needed |
| 2413 | sub config_to_multi { |
| 2414 | my $val = shift; |
| 2415 | |
Jakub Narebski | d76a585 | 2007-12-20 10:48:09 +0100 | [diff] [blame] | 2416 | return ref($val) ? $val : (defined($val) ? [ $val ] : []); |
Jakub Narebski | b201927 | 2007-11-03 00:41:19 +0100 | [diff] [blame] | 2417 | } |
| 2418 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2419 | sub git_get_project_config { |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 2420 | my ($key, $type) = @_; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2421 | |
Jakub Narebski | 7a49c25 | 2010-03-27 20:26:59 +0100 | [diff] [blame] | 2422 | return unless defined $git_dir; |
Jakub Narebski | 9be3614 | 2010-03-01 22:51:34 +0100 | [diff] [blame] | 2423 | |
Jakub Narebski | b201927 | 2007-11-03 00:41:19 +0100 | [diff] [blame] | 2424 | # key sanity check |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2425 | return unless ($key); |
| 2426 | $key =~ s/^gitweb\.//; |
| 2427 | return if ($key =~ m/\W/); |
| 2428 | |
Jakub Narebski | b201927 | 2007-11-03 00:41:19 +0100 | [diff] [blame] | 2429 | # type sanity check |
| 2430 | if (defined $type) { |
| 2431 | $type =~ s/^--//; |
| 2432 | $type = undef |
| 2433 | unless ($type eq 'bool' || $type eq 'int'); |
| 2434 | } |
| 2435 | |
| 2436 | # get config |
| 2437 | if (!defined $config_file || |
| 2438 | $config_file ne "$git_dir/config") { |
| 2439 | %config = git_parse_project_config('gitweb'); |
| 2440 | $config_file = "$git_dir/config"; |
| 2441 | } |
| 2442 | |
Marcel M. Cary | df5d10a | 2009-02-18 14:09:41 +0100 | [diff] [blame] | 2443 | # check if config variable (key) exists |
| 2444 | return unless exists $config{"gitweb.$key"}; |
| 2445 | |
Jakub Narebski | b201927 | 2007-11-03 00:41:19 +0100 | [diff] [blame] | 2446 | # ensure given type |
| 2447 | if (!defined $type) { |
| 2448 | return $config{"gitweb.$key"}; |
| 2449 | } elsif ($type eq 'bool') { |
| 2450 | # backward compatibility: 'git config --bool' returns true/false |
| 2451 | return config_to_bool($config{"gitweb.$key"}) ? 'true' : 'false'; |
| 2452 | } elsif ($type eq 'int') { |
| 2453 | return config_to_int($config{"gitweb.$key"}); |
| 2454 | } |
| 2455 | return $config{"gitweb.$key"}; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2456 | } |
| 2457 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2458 | # get hash of given path at given ref |
| 2459 | sub git_get_hash_by_path { |
| 2460 | my $base = shift; |
| 2461 | my $path = shift || return undef; |
Jakub Narebski | 1d782b0 | 2006-09-21 18:09:12 +0200 | [diff] [blame] | 2462 | my $type = shift; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2463 | |
Jakub Narebski | 4b02f48 | 2006-09-26 01:54:24 +0200 | [diff] [blame] | 2464 | $path =~ s,/+$,,; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2465 | |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 2466 | open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 2467 | or die_error(500, "Open git-ls-tree failed"); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2468 | my $line = <$fd>; |
| 2469 | close $fd or return undef; |
| 2470 | |
Jakub Narebski | 198a2a8 | 2007-05-12 21:16:34 +0200 | [diff] [blame] | 2471 | if (!defined $line) { |
| 2472 | # there is no tree or hash given by $path at $base |
| 2473 | return undef; |
| 2474 | } |
| 2475 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2476 | #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' |
Jakub Narebski | 8b4b94c | 2006-10-30 22:25:11 +0100 | [diff] [blame] | 2477 | $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/; |
Jakub Narebski | 1d782b0 | 2006-09-21 18:09:12 +0200 | [diff] [blame] | 2478 | if (defined $type && $type ne $2) { |
| 2479 | # type doesn't match |
| 2480 | return undef; |
| 2481 | } |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2482 | return $3; |
| 2483 | } |
| 2484 | |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 2485 | # get path of entry with given hash at given tree-ish (ref) |
| 2486 | # used to get 'from' filename for combined diff (merge commit) for renames |
| 2487 | sub git_get_path_by_hash { |
| 2488 | my $base = shift || return; |
| 2489 | my $hash = shift || return; |
| 2490 | |
| 2491 | local $/ = "\0"; |
| 2492 | |
| 2493 | open my $fd, "-|", git_cmd(), "ls-tree", '-r', '-t', '-z', $base |
| 2494 | or return undef; |
| 2495 | while (my $line = <$fd>) { |
| 2496 | chomp $line; |
| 2497 | |
| 2498 | #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb' |
| 2499 | #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README' |
| 2500 | if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) { |
| 2501 | close $fd; |
| 2502 | return $1; |
| 2503 | } |
| 2504 | } |
| 2505 | close $fd; |
| 2506 | return undef; |
| 2507 | } |
| 2508 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2509 | ## ...................................................................... |
| 2510 | ## git utility functions, directly accessing git repository |
| 2511 | |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 2512 | sub git_get_project_description { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2513 | my $path = shift; |
| 2514 | |
Jakub Narebski | 0e121a2 | 2007-11-03 00:41:20 +0100 | [diff] [blame] | 2515 | $git_dir = "$projectroot/$path"; |
Jakub Narebski | dff2b6d | 2009-05-10 02:38:34 +0200 | [diff] [blame] | 2516 | open my $fd, '<', "$git_dir/description" |
Jakub Narebski | 0e121a2 | 2007-11-03 00:41:20 +0100 | [diff] [blame] | 2517 | or return git_get_project_config('description'); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2518 | my $descr = <$fd>; |
| 2519 | close $fd; |
Junio C Hamano | 2eb54ef | 2007-05-16 21:04:16 -0700 | [diff] [blame] | 2520 | if (defined $descr) { |
| 2521 | chomp $descr; |
| 2522 | } |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2523 | return $descr; |
| 2524 | } |
| 2525 | |
Petr Baudis | aed93de | 2008-10-02 17:13:02 +0200 | [diff] [blame] | 2526 | sub git_get_project_ctags { |
| 2527 | my $path = shift; |
| 2528 | my $ctags = {}; |
| 2529 | |
| 2530 | $git_dir = "$projectroot/$path"; |
Jakub Narebski | ad87e4f | 2009-05-11 03:21:06 +0200 | [diff] [blame] | 2531 | opendir my $dh, "$git_dir/ctags" |
| 2532 | or return $ctags; |
| 2533 | foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir($dh)) { |
Jakub Narebski | dff2b6d | 2009-05-10 02:38:34 +0200 | [diff] [blame] | 2534 | open my $ct, '<', $_ or next; |
Jakub Narebski | ad87e4f | 2009-05-11 03:21:06 +0200 | [diff] [blame] | 2535 | my $val = <$ct>; |
Petr Baudis | aed93de | 2008-10-02 17:13:02 +0200 | [diff] [blame] | 2536 | chomp $val; |
Jakub Narebski | ad87e4f | 2009-05-11 03:21:06 +0200 | [diff] [blame] | 2537 | close $ct; |
Petr Baudis | aed93de | 2008-10-02 17:13:02 +0200 | [diff] [blame] | 2538 | my $ctag = $_; $ctag =~ s#.*/##; |
| 2539 | $ctags->{$ctag} = $val; |
| 2540 | } |
Jakub Narebski | ad87e4f | 2009-05-11 03:21:06 +0200 | [diff] [blame] | 2541 | closedir $dh; |
Petr Baudis | aed93de | 2008-10-02 17:13:02 +0200 | [diff] [blame] | 2542 | $ctags; |
| 2543 | } |
| 2544 | |
| 2545 | sub git_populate_project_tagcloud { |
| 2546 | my $ctags = shift; |
| 2547 | |
| 2548 | # First, merge different-cased tags; tags vote on casing |
| 2549 | my %ctags_lc; |
| 2550 | foreach (keys %$ctags) { |
| 2551 | $ctags_lc{lc $_}->{count} += $ctags->{$_}; |
| 2552 | if (not $ctags_lc{lc $_}->{topcount} |
| 2553 | or $ctags_lc{lc $_}->{topcount} < $ctags->{$_}) { |
| 2554 | $ctags_lc{lc $_}->{topcount} = $ctags->{$_}; |
| 2555 | $ctags_lc{lc $_}->{topname} = $_; |
| 2556 | } |
| 2557 | } |
| 2558 | |
| 2559 | my $cloud; |
| 2560 | if (eval { require HTML::TagCloud; 1; }) { |
| 2561 | $cloud = HTML::TagCloud->new; |
| 2562 | foreach (sort keys %ctags_lc) { |
| 2563 | # Pad the title with spaces so that the cloud looks |
| 2564 | # less crammed. |
| 2565 | my $title = $ctags_lc{$_}->{topname}; |
| 2566 | $title =~ s/ / /g; |
| 2567 | $title =~ s/^/ /g; |
| 2568 | $title =~ s/$/ /g; |
| 2569 | $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count}); |
| 2570 | } |
| 2571 | } else { |
| 2572 | $cloud = \%ctags_lc; |
| 2573 | } |
| 2574 | $cloud; |
| 2575 | } |
| 2576 | |
| 2577 | sub git_show_project_tagcloud { |
| 2578 | my ($cloud, $count) = @_; |
| 2579 | print STDERR ref($cloud)."..\n"; |
| 2580 | if (ref $cloud eq 'HTML::TagCloud') { |
| 2581 | return $cloud->html_and_css($count); |
| 2582 | } else { |
| 2583 | my @tags = sort { $cloud->{$a}->{count} <=> $cloud->{$b}->{count} } keys %$cloud; |
| 2584 | return '<p align="center">' . join (', ', map { |
| 2585 | "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>" |
| 2586 | } splice(@tags, 0, $count)) . '</p>'; |
| 2587 | } |
| 2588 | } |
| 2589 | |
Jakub Narebski | e79ca7c | 2006-08-16 14:50:34 +0200 | [diff] [blame] | 2590 | sub git_get_project_url_list { |
| 2591 | my $path = shift; |
| 2592 | |
Jakub Narebski | 0e121a2 | 2007-11-03 00:41:20 +0100 | [diff] [blame] | 2593 | $git_dir = "$projectroot/$path"; |
Jakub Narebski | dff2b6d | 2009-05-10 02:38:34 +0200 | [diff] [blame] | 2594 | open my $fd, '<', "$git_dir/cloneurl" |
Jakub Narebski | 0e121a2 | 2007-11-03 00:41:20 +0100 | [diff] [blame] | 2595 | or return wantarray ? |
| 2596 | @{ config_to_multi(git_get_project_config('url')) } : |
| 2597 | config_to_multi(git_get_project_config('url')); |
Jakub Narebski | e79ca7c | 2006-08-16 14:50:34 +0200 | [diff] [blame] | 2598 | my @git_project_url_list = map { chomp; $_ } <$fd>; |
| 2599 | close $fd; |
| 2600 | |
| 2601 | return wantarray ? @git_project_url_list : \@git_project_url_list; |
| 2602 | } |
| 2603 | |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 2604 | sub git_get_projects_list { |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 2605 | my ($filter) = @_; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2606 | my @list; |
| 2607 | |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 2608 | $filter ||= ''; |
| 2609 | $filter =~ s/\.git$//; |
| 2610 | |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 2611 | my $check_forks = gitweb_check_feature('forks'); |
Frank Lichtenheld | c2b8b13 | 2007-04-06 23:58:11 +0200 | [diff] [blame] | 2612 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2613 | if (-d $projects_list) { |
| 2614 | # search in directory |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 2615 | my $dir = $projects_list . ($filter ? "/$filter" : ''); |
Aneesh Kumar K.V | 6768d6b | 2006-11-03 10:41:45 +0530 | [diff] [blame] | 2616 | # remove the trailing "/" |
| 2617 | $dir =~ s!/+$!!; |
Jakub Narebski | c0011ff | 2006-09-14 22:18:59 +0200 | [diff] [blame] | 2618 | my $pfxlen = length("$dir"); |
Luke Lu | ca5e949 | 2007-10-16 20:45:25 -0700 | [diff] [blame] | 2619 | my $pfxdepth = ($dir =~ tr!/!!); |
Jakub Narebski | c0011ff | 2006-09-14 22:18:59 +0200 | [diff] [blame] | 2620 | |
| 2621 | File::Find::find({ |
| 2622 | follow_fast => 1, # follow symbolic links |
Junio C Hamano | d20602e | 2007-07-27 01:23:03 -0700 | [diff] [blame] | 2623 | follow_skip => 2, # ignore duplicates |
Jakub Narebski | c0011ff | 2006-09-14 22:18:59 +0200 | [diff] [blame] | 2624 | dangling_symlinks => 0, # ignore dangling symlinks, silently |
| 2625 | wanted => sub { |
Jakub Narebski | ee1d8ee | 2010-04-30 18:30:31 +0200 | [diff] [blame] | 2626 | # global variables |
| 2627 | our $project_maxdepth; |
| 2628 | our $projectroot; |
Jakub Narebski | c0011ff | 2006-09-14 22:18:59 +0200 | [diff] [blame] | 2629 | # skip project-list toplevel, if we get it. |
| 2630 | return if (m!^[/.]$!); |
| 2631 | # only directories can be git repositories |
| 2632 | return unless (-d $_); |
Luke Lu | ca5e949 | 2007-10-16 20:45:25 -0700 | [diff] [blame] | 2633 | # don't traverse too deep (Find is super slow on os x) |
| 2634 | if (($File::Find::name =~ tr!/!!) - $pfxdepth > $project_maxdepth) { |
| 2635 | $File::Find::prune = 1; |
| 2636 | return; |
| 2637 | } |
Jakub Narebski | c0011ff | 2006-09-14 22:18:59 +0200 | [diff] [blame] | 2638 | |
| 2639 | my $subdir = substr($File::Find::name, $pfxlen + 1); |
| 2640 | # we check related file in $projectroot |
Devin Doucette | fb3bb3d | 2008-12-27 02:39:31 -0700 | [diff] [blame] | 2641 | my $path = ($filter ? "$filter/" : '') . $subdir; |
| 2642 | if (check_export_ok("$projectroot/$path")) { |
| 2643 | push @list, { path => $path }; |
Jakub Narebski | c0011ff | 2006-09-14 22:18:59 +0200 | [diff] [blame] | 2644 | $File::Find::prune = 1; |
| 2645 | } |
| 2646 | }, |
| 2647 | }, "$dir"); |
| 2648 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2649 | } elsif (-f $projects_list) { |
| 2650 | # read from file(url-encoded): |
| 2651 | # 'git%2Fgit.git Linus+Torvalds' |
| 2652 | # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin' |
| 2653 | # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman' |
Frank Lichtenheld | c2b8b13 | 2007-04-06 23:58:11 +0200 | [diff] [blame] | 2654 | my %paths; |
Jakub Narebski | dff2b6d | 2009-05-10 02:38:34 +0200 | [diff] [blame] | 2655 | open my $fd, '<', $projects_list or return; |
Frank Lichtenheld | c2b8b13 | 2007-04-06 23:58:11 +0200 | [diff] [blame] | 2656 | PROJECT: |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2657 | while (my $line = <$fd>) { |
| 2658 | chomp $line; |
| 2659 | my ($path, $owner) = split ' ', $line; |
| 2660 | $path = unescape($path); |
| 2661 | $owner = unescape($owner); |
| 2662 | if (!defined $path) { |
| 2663 | next; |
| 2664 | } |
Junio C Hamano | 83ee94c | 2006-11-07 22:37:17 -0800 | [diff] [blame] | 2665 | if ($filter ne '') { |
| 2666 | # looking for forks; |
| 2667 | my $pfx = substr($path, 0, length($filter)); |
| 2668 | if ($pfx ne $filter) { |
Frank Lichtenheld | c2b8b13 | 2007-04-06 23:58:11 +0200 | [diff] [blame] | 2669 | next PROJECT; |
Junio C Hamano | 83ee94c | 2006-11-07 22:37:17 -0800 | [diff] [blame] | 2670 | } |
| 2671 | my $sfx = substr($path, length($filter)); |
| 2672 | if ($sfx !~ /^\/.*\.git$/) { |
Frank Lichtenheld | c2b8b13 | 2007-04-06 23:58:11 +0200 | [diff] [blame] | 2673 | next PROJECT; |
| 2674 | } |
| 2675 | } elsif ($check_forks) { |
| 2676 | PATH: |
| 2677 | foreach my $filter (keys %paths) { |
| 2678 | # looking for forks; |
| 2679 | my $pfx = substr($path, 0, length($filter)); |
| 2680 | if ($pfx ne $filter) { |
| 2681 | next PATH; |
| 2682 | } |
| 2683 | my $sfx = substr($path, length($filter)); |
| 2684 | if ($sfx !~ /^\/.*\.git$/) { |
| 2685 | next PATH; |
| 2686 | } |
| 2687 | # is a fork, don't include it in |
| 2688 | # the list |
| 2689 | next PROJECT; |
Junio C Hamano | 83ee94c | 2006-11-07 22:37:17 -0800 | [diff] [blame] | 2690 | } |
| 2691 | } |
Junio C Hamano | 2172ce4 | 2006-10-03 02:30:47 -0700 | [diff] [blame] | 2692 | if (check_export_ok("$projectroot/$path")) { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2693 | my $pr = { |
| 2694 | path => $path, |
Martin Koegler | 00f429a | 2007-06-03 17:42:44 +0200 | [diff] [blame] | 2695 | owner => to_utf8($owner), |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2696 | }; |
Frank Lichtenheld | c2b8b13 | 2007-04-06 23:58:11 +0200 | [diff] [blame] | 2697 | push @list, $pr; |
| 2698 | (my $forks_path = $path) =~ s/\.git$//; |
| 2699 | $paths{$forks_path}++; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2700 | } |
| 2701 | } |
| 2702 | close $fd; |
| 2703 | } |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2704 | return @list; |
| 2705 | } |
| 2706 | |
Junio C Hamano | 4785245 | 2007-07-03 22:10:42 -0700 | [diff] [blame] | 2707 | our $gitweb_project_owner = undef; |
| 2708 | sub git_get_project_list_from_file { |
Jakub Narebski | 1e0cf03 | 2006-08-14 02:10:06 +0200 | [diff] [blame] | 2709 | |
Junio C Hamano | 4785245 | 2007-07-03 22:10:42 -0700 | [diff] [blame] | 2710 | return if (defined $gitweb_project_owner); |
Jakub Narebski | 1e0cf03 | 2006-08-14 02:10:06 +0200 | [diff] [blame] | 2711 | |
Junio C Hamano | 4785245 | 2007-07-03 22:10:42 -0700 | [diff] [blame] | 2712 | $gitweb_project_owner = {}; |
Jakub Narebski | 1e0cf03 | 2006-08-14 02:10:06 +0200 | [diff] [blame] | 2713 | # read from file (url-encoded): |
| 2714 | # 'git%2Fgit.git Linus+Torvalds' |
| 2715 | # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin' |
| 2716 | # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman' |
| 2717 | if (-f $projects_list) { |
Jakub Narebski | dff2b6d | 2009-05-10 02:38:34 +0200 | [diff] [blame] | 2718 | open(my $fd, '<', $projects_list); |
Jakub Narebski | 1e0cf03 | 2006-08-14 02:10:06 +0200 | [diff] [blame] | 2719 | while (my $line = <$fd>) { |
| 2720 | chomp $line; |
| 2721 | my ($pr, $ow) = split ' ', $line; |
| 2722 | $pr = unescape($pr); |
| 2723 | $ow = unescape($ow); |
Junio C Hamano | 4785245 | 2007-07-03 22:10:42 -0700 | [diff] [blame] | 2724 | $gitweb_project_owner->{$pr} = to_utf8($ow); |
Jakub Narebski | 1e0cf03 | 2006-08-14 02:10:06 +0200 | [diff] [blame] | 2725 | } |
| 2726 | close $fd; |
| 2727 | } |
Junio C Hamano | 4785245 | 2007-07-03 22:10:42 -0700 | [diff] [blame] | 2728 | } |
| 2729 | |
| 2730 | sub git_get_project_owner { |
| 2731 | my $project = shift; |
| 2732 | my $owner; |
| 2733 | |
| 2734 | return undef unless $project; |
Bruno Ribas | b59012e | 2008-02-08 14:38:04 -0200 | [diff] [blame] | 2735 | $git_dir = "$projectroot/$project"; |
Junio C Hamano | 4785245 | 2007-07-03 22:10:42 -0700 | [diff] [blame] | 2736 | |
| 2737 | if (!defined $gitweb_project_owner) { |
| 2738 | git_get_project_list_from_file(); |
| 2739 | } |
| 2740 | |
| 2741 | if (exists $gitweb_project_owner->{$project}) { |
| 2742 | $owner = $gitweb_project_owner->{$project}; |
| 2743 | } |
Bruno Ribas | b59012e | 2008-02-08 14:38:04 -0200 | [diff] [blame] | 2744 | if (!defined $owner){ |
| 2745 | $owner = git_get_project_config('owner'); |
| 2746 | } |
Jakub Narebski | 1e0cf03 | 2006-08-14 02:10:06 +0200 | [diff] [blame] | 2747 | if (!defined $owner) { |
Bruno Ribas | b59012e | 2008-02-08 14:38:04 -0200 | [diff] [blame] | 2748 | $owner = get_file_owner("$git_dir"); |
Jakub Narebski | 1e0cf03 | 2006-08-14 02:10:06 +0200 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | return $owner; |
| 2752 | } |
| 2753 | |
Jakub Narebski | c60c56c | 2006-10-28 19:43:40 +0200 | [diff] [blame] | 2754 | sub git_get_last_activity { |
| 2755 | my ($path) = @_; |
| 2756 | my $fd; |
| 2757 | |
| 2758 | $git_dir = "$projectroot/$path"; |
| 2759 | open($fd, "-|", git_cmd(), 'for-each-ref', |
Robert Fitzsimons | 0ff5ec7 | 2006-12-22 19:38:13 +0000 | [diff] [blame] | 2760 | '--format=%(committer)', |
Jakub Narebski | c60c56c | 2006-10-28 19:43:40 +0200 | [diff] [blame] | 2761 | '--sort=-committerdate', |
Robert Fitzsimons | 0ff5ec7 | 2006-12-22 19:38:13 +0000 | [diff] [blame] | 2762 | '--count=1', |
Jakub Narebski | c60c56c | 2006-10-28 19:43:40 +0200 | [diff] [blame] | 2763 | 'refs/heads') or return; |
| 2764 | my $most_recent = <$fd>; |
| 2765 | close $fd or return; |
Jakub Narebski | 785cdea | 2007-05-13 12:39:22 +0200 | [diff] [blame] | 2766 | if (defined $most_recent && |
| 2767 | $most_recent =~ / (\d+) [-+][01]\d\d\d$/) { |
Jakub Narebski | c60c56c | 2006-10-28 19:43:40 +0200 | [diff] [blame] | 2768 | my $timestamp = $1; |
| 2769 | my $age = time - $timestamp; |
| 2770 | return ($age, age_string($age)); |
| 2771 | } |
Matt McCutchen | c956395 | 2007-06-28 18:15:22 -0400 | [diff] [blame] | 2772 | return (undef, undef); |
Jakub Narebski | c60c56c | 2006-10-28 19:43:40 +0200 | [diff] [blame] | 2773 | } |
| 2774 | |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 2775 | sub git_get_references { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2776 | my $type = shift || ""; |
| 2777 | my %refs; |
Jakub Narebski | 28b9d9f | 2006-11-25 11:32:08 +0100 | [diff] [blame] | 2778 | # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11 |
| 2779 | # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{} |
| 2780 | open my $fd, "-|", git_cmd(), "show-ref", "--dereference", |
| 2781 | ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type |
Jakub Narebski | 9704d75 | 2006-09-19 14:31:49 +0200 | [diff] [blame] | 2782 | or return; |
Jakub Narebski | d294e1c | 2006-08-14 02:14:20 +0200 | [diff] [blame] | 2783 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2784 | while (my $line = <$fd>) { |
| 2785 | chomp $line; |
Giuseppe Bilotta | 4afbaef | 2008-09-02 21:47:05 +0200 | [diff] [blame] | 2786 | if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2787 | if (defined $refs{$1}) { |
Jakub Narebski | d294e1c | 2006-08-14 02:14:20 +0200 | [diff] [blame] | 2788 | push @{$refs{$1}}, $2; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2789 | } else { |
Jakub Narebski | d294e1c | 2006-08-14 02:14:20 +0200 | [diff] [blame] | 2790 | $refs{$1} = [ $2 ]; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2791 | } |
| 2792 | } |
| 2793 | } |
| 2794 | close $fd or return; |
| 2795 | return \%refs; |
| 2796 | } |
| 2797 | |
Jakub Narebski | 56a322f | 2006-08-24 19:41:23 +0200 | [diff] [blame] | 2798 | sub git_get_rev_name_tags { |
| 2799 | my $hash = shift || return undef; |
| 2800 | |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 2801 | open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash |
Jakub Narebski | 56a322f | 2006-08-24 19:41:23 +0200 | [diff] [blame] | 2802 | or return; |
| 2803 | my $name_rev = <$fd>; |
| 2804 | close $fd; |
| 2805 | |
| 2806 | if ($name_rev =~ m|^$hash tags/(.*)$|) { |
| 2807 | return $1; |
| 2808 | } else { |
| 2809 | # catches also '$hash undefined' output |
| 2810 | return undef; |
| 2811 | } |
| 2812 | } |
| 2813 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2814 | ## ---------------------------------------------------------------------- |
| 2815 | ## parse to hash functions |
| 2816 | |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 2817 | sub parse_date { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2818 | my $epoch = shift; |
| 2819 | my $tz = shift || "-0000"; |
| 2820 | |
| 2821 | my %date; |
| 2822 | my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); |
| 2823 | my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); |
| 2824 | my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch); |
| 2825 | $date{'hour'} = $hour; |
| 2826 | $date{'minute'} = $min; |
| 2827 | $date{'mday'} = $mday; |
| 2828 | $date{'day'} = $days[$wday]; |
| 2829 | $date{'month'} = $months[$mon]; |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 2830 | $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", |
| 2831 | $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec; |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 2832 | $date{'mday-time'} = sprintf "%d %s %02d:%02d", |
| 2833 | $mday, $months[$mon], $hour ,$min; |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 2834 | $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ", |
Vincent Zanotti | a62d6d8 | 2007-11-10 19:55:27 +0100 | [diff] [blame] | 2835 | 1900+$year, 1+$mon, $mday, $hour ,$min, $sec; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2836 | |
| 2837 | $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/; |
| 2838 | my $local = $epoch + ((int $1 + ($2/60)) * 3600); |
| 2839 | ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local); |
| 2840 | $date{'hour_local'} = $hour; |
| 2841 | $date{'minute_local'} = $min; |
| 2842 | $date{'tz_local'} = $tz; |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 2843 | $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s", |
| 2844 | 1900+$year, $mon+1, $mday, |
| 2845 | $hour, $min, $sec, $tz); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2846 | return %date; |
| 2847 | } |
| 2848 | |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 2849 | sub parse_tag { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2850 | my $tag_id = shift; |
| 2851 | my %tag; |
| 2852 | my @comment; |
| 2853 | |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 2854 | open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2855 | $tag{'id'} = $tag_id; |
| 2856 | while (my $line = <$fd>) { |
| 2857 | chomp $line; |
| 2858 | if ($line =~ m/^object ([0-9a-fA-F]{40})$/) { |
| 2859 | $tag{'object'} = $1; |
| 2860 | } elsif ($line =~ m/^type (.+)$/) { |
| 2861 | $tag{'type'} = $1; |
| 2862 | } elsif ($line =~ m/^tag (.+)$/) { |
| 2863 | $tag{'name'} = $1; |
| 2864 | } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) { |
| 2865 | $tag{'author'} = $1; |
Giuseppe Bilotta | ba92473 | 2009-06-30 00:00:50 +0200 | [diff] [blame] | 2866 | $tag{'author_epoch'} = $2; |
| 2867 | $tag{'author_tz'} = $3; |
| 2868 | if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) { |
| 2869 | $tag{'author_name'} = $1; |
| 2870 | $tag{'author_email'} = $2; |
| 2871 | } else { |
| 2872 | $tag{'author_name'} = $tag{'author'}; |
| 2873 | } |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2874 | } elsif ($line =~ m/--BEGIN/) { |
| 2875 | push @comment, $line; |
| 2876 | last; |
| 2877 | } elsif ($line eq "") { |
| 2878 | last; |
| 2879 | } |
| 2880 | } |
| 2881 | push @comment, <$fd>; |
| 2882 | $tag{'comment'} = \@comment; |
| 2883 | close $fd or return; |
| 2884 | if (!defined $tag{'name'}) { |
| 2885 | return |
| 2886 | }; |
| 2887 | return %tag |
| 2888 | } |
| 2889 | |
Robert Fitzsimons | 756bbf5 | 2006-12-24 14:31:42 +0000 | [diff] [blame] | 2890 | sub parse_commit_text { |
Robert Fitzsimons | ccdfdea | 2006-12-27 14:22:21 +0000 | [diff] [blame] | 2891 | my ($commit_text, $withparents) = @_; |
Robert Fitzsimons | 756bbf5 | 2006-12-24 14:31:42 +0000 | [diff] [blame] | 2892 | my @commit_lines = split '\n', $commit_text; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2893 | my %co; |
| 2894 | |
Robert Fitzsimons | 756bbf5 | 2006-12-24 14:31:42 +0000 | [diff] [blame] | 2895 | pop @commit_lines; # Remove '\0' |
| 2896 | |
Jakub Narebski | 198a2a8 | 2007-05-12 21:16:34 +0200 | [diff] [blame] | 2897 | if (! @commit_lines) { |
| 2898 | return; |
| 2899 | } |
| 2900 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2901 | my $header = shift @commit_lines; |
Jakub Narebski | 198a2a8 | 2007-05-12 21:16:34 +0200 | [diff] [blame] | 2902 | if ($header !~ m/^[0-9a-fA-F]{40}/) { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2903 | return; |
| 2904 | } |
Robert Fitzsimons | ccdfdea | 2006-12-27 14:22:21 +0000 | [diff] [blame] | 2905 | ($co{'id'}, my @parents) = split ' ', $header; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2906 | while (my $line = shift @commit_lines) { |
| 2907 | last if $line eq "\n"; |
| 2908 | if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) { |
| 2909 | $co{'tree'} = $1; |
Robert Fitzsimons | ccdfdea | 2006-12-27 14:22:21 +0000 | [diff] [blame] | 2910 | } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) { |
Robert Fitzsimons | 208b2df | 2006-12-24 14:31:43 +0000 | [diff] [blame] | 2911 | push @parents, $1; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2912 | } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) { |
Zoltán Füzesi | 5ed5bbc | 2009-08-02 09:42:24 +0200 | [diff] [blame] | 2913 | $co{'author'} = to_utf8($1); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2914 | $co{'author_epoch'} = $2; |
| 2915 | $co{'author_tz'} = $3; |
Jakub Narebski | ba00b8c | 2006-11-25 15:54:32 +0100 | [diff] [blame] | 2916 | if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) { |
| 2917 | $co{'author_name'} = $1; |
| 2918 | $co{'author_email'} = $2; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2919 | } else { |
| 2920 | $co{'author_name'} = $co{'author'}; |
| 2921 | } |
| 2922 | } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) { |
Zoltán Füzesi | 5ed5bbc | 2009-08-02 09:42:24 +0200 | [diff] [blame] | 2923 | $co{'committer'} = to_utf8($1); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2924 | $co{'committer_epoch'} = $2; |
| 2925 | $co{'committer_tz'} = $3; |
Jakub Narebski | ba00b8c | 2006-11-25 15:54:32 +0100 | [diff] [blame] | 2926 | if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) { |
| 2927 | $co{'committer_name'} = $1; |
| 2928 | $co{'committer_email'} = $2; |
| 2929 | } else { |
| 2930 | $co{'committer_name'} = $co{'committer'}; |
| 2931 | } |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2932 | } |
| 2933 | } |
| 2934 | if (!defined $co{'tree'}) { |
| 2935 | return; |
| 2936 | }; |
Robert Fitzsimons | 208b2df | 2006-12-24 14:31:43 +0000 | [diff] [blame] | 2937 | $co{'parents'} = \@parents; |
| 2938 | $co{'parent'} = $parents[0]; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2939 | |
| 2940 | foreach my $title (@commit_lines) { |
| 2941 | $title =~ s/^ //; |
| 2942 | if ($title ne "") { |
| 2943 | $co{'title'} = chop_str($title, 80, 5); |
| 2944 | # remove leading stuff of merges to make the interesting part visible |
| 2945 | if (length($title) > 50) { |
| 2946 | $title =~ s/^Automatic //; |
| 2947 | $title =~ s/^merge (of|with) /Merge ... /i; |
| 2948 | if (length($title) > 50) { |
| 2949 | $title =~ s/(http|rsync):\/\///; |
| 2950 | } |
| 2951 | if (length($title) > 50) { |
| 2952 | $title =~ s/(master|www|rsync)\.//; |
| 2953 | } |
| 2954 | if (length($title) > 50) { |
| 2955 | $title =~ s/kernel.org:?//; |
| 2956 | } |
| 2957 | if (length($title) > 50) { |
| 2958 | $title =~ s/\/pub\/scm//; |
| 2959 | } |
| 2960 | } |
| 2961 | $co{'title_short'} = chop_str($title, 50, 5); |
| 2962 | last; |
| 2963 | } |
| 2964 | } |
Joey Hess | 53c3967 | 2008-09-05 14:26:29 -0400 | [diff] [blame] | 2965 | if (! defined $co{'title'} || $co{'title'} eq "") { |
Petr Baudis | 7e0fe5c | 2006-10-06 18:55:04 +0200 | [diff] [blame] | 2966 | $co{'title'} = $co{'title_short'} = '(no commit message)'; |
| 2967 | } |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 2968 | # remove added spaces |
| 2969 | foreach my $line (@commit_lines) { |
| 2970 | $line =~ s/^ //; |
| 2971 | } |
| 2972 | $co{'comment'} = \@commit_lines; |
| 2973 | |
| 2974 | my $age = time - $co{'committer_epoch'}; |
| 2975 | $co{'age'} = $age; |
| 2976 | $co{'age_string'} = age_string($age); |
| 2977 | my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'}); |
| 2978 | if ($age > 60*60*24*7*2) { |
| 2979 | $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday; |
| 2980 | $co{'age_string_age'} = $co{'age_string'}; |
| 2981 | } else { |
| 2982 | $co{'age_string_date'} = $co{'age_string'}; |
| 2983 | $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday; |
| 2984 | } |
| 2985 | return %co; |
| 2986 | } |
| 2987 | |
Robert Fitzsimons | 756bbf5 | 2006-12-24 14:31:42 +0000 | [diff] [blame] | 2988 | sub parse_commit { |
| 2989 | my ($commit_id) = @_; |
| 2990 | my %co; |
| 2991 | |
| 2992 | local $/ = "\0"; |
| 2993 | |
| 2994 | open my $fd, "-|", git_cmd(), "rev-list", |
Robert Fitzsimons | ccdfdea | 2006-12-27 14:22:21 +0000 | [diff] [blame] | 2995 | "--parents", |
Robert Fitzsimons | 756bbf5 | 2006-12-24 14:31:42 +0000 | [diff] [blame] | 2996 | "--header", |
Robert Fitzsimons | 756bbf5 | 2006-12-24 14:31:42 +0000 | [diff] [blame] | 2997 | "--max-count=1", |
| 2998 | $commit_id, |
| 2999 | "--", |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 3000 | or die_error(500, "Open git-rev-list failed"); |
Robert Fitzsimons | ccdfdea | 2006-12-27 14:22:21 +0000 | [diff] [blame] | 3001 | %co = parse_commit_text(<$fd>, 1); |
Robert Fitzsimons | 756bbf5 | 2006-12-24 14:31:42 +0000 | [diff] [blame] | 3002 | close $fd; |
| 3003 | |
| 3004 | return %co; |
| 3005 | } |
| 3006 | |
| 3007 | sub parse_commits { |
Jakub Narebski | 311e552 | 2008-02-26 13:22:06 +0100 | [diff] [blame] | 3008 | my ($commit_id, $maxcount, $skip, $filename, @args) = @_; |
Robert Fitzsimons | 756bbf5 | 2006-12-24 14:31:42 +0000 | [diff] [blame] | 3009 | my @cos; |
| 3010 | |
| 3011 | $maxcount ||= 1; |
| 3012 | $skip ||= 0; |
| 3013 | |
Robert Fitzsimons | 756bbf5 | 2006-12-24 14:31:42 +0000 | [diff] [blame] | 3014 | local $/ = "\0"; |
| 3015 | |
| 3016 | open my $fd, "-|", git_cmd(), "rev-list", |
| 3017 | "--header", |
Jakub Narebski | 311e552 | 2008-02-26 13:22:06 +0100 | [diff] [blame] | 3018 | @args, |
Robert Fitzsimons | 756bbf5 | 2006-12-24 14:31:42 +0000 | [diff] [blame] | 3019 | ("--max-count=" . $maxcount), |
Robert Fitzsimons | f47efbb | 2006-12-24 14:31:49 +0000 | [diff] [blame] | 3020 | ("--skip=" . $skip), |
Miklos Vajna | 868bc06 | 2007-07-12 20:39:27 +0200 | [diff] [blame] | 3021 | @extra_options, |
Robert Fitzsimons | 756bbf5 | 2006-12-24 14:31:42 +0000 | [diff] [blame] | 3022 | $commit_id, |
| 3023 | "--", |
| 3024 | ($filename ? ($filename) : ()) |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 3025 | or die_error(500, "Open git-rev-list failed"); |
Robert Fitzsimons | 756bbf5 | 2006-12-24 14:31:42 +0000 | [diff] [blame] | 3026 | while (my $line = <$fd>) { |
| 3027 | my %co = parse_commit_text($line); |
| 3028 | push @cos, \%co; |
| 3029 | } |
| 3030 | close $fd; |
| 3031 | |
| 3032 | return wantarray ? @cos : \@cos; |
| 3033 | } |
| 3034 | |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 3035 | # parse line of git-diff-tree "raw" output |
Jakub Narebski | 740e67f | 2006-08-21 23:07:00 +0200 | [diff] [blame] | 3036 | sub parse_difftree_raw_line { |
| 3037 | my $line = shift; |
| 3038 | my %res; |
| 3039 | |
| 3040 | # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c' |
| 3041 | # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c' |
| 3042 | if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) { |
| 3043 | $res{'from_mode'} = $1; |
| 3044 | $res{'to_mode'} = $2; |
| 3045 | $res{'from_id'} = $3; |
| 3046 | $res{'to_id'} = $4; |
Jakub Narebski | 4ed4a34 | 2008-04-05 21:13:24 +0100 | [diff] [blame] | 3047 | $res{'status'} = $5; |
Jakub Narebski | 740e67f | 2006-08-21 23:07:00 +0200 | [diff] [blame] | 3048 | $res{'similarity'} = $6; |
| 3049 | if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 3050 | ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7); |
Jakub Narebski | 740e67f | 2006-08-21 23:07:00 +0200 | [diff] [blame] | 3051 | } else { |
Jakub Narebski | 9d30145 | 2007-11-01 12:38:08 +0100 | [diff] [blame] | 3052 | $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote($7); |
Jakub Narebski | 740e67f | 2006-08-21 23:07:00 +0200 | [diff] [blame] | 3053 | } |
| 3054 | } |
Jakub Narebski | 78bc403 | 2007-05-07 01:10:03 +0200 | [diff] [blame] | 3055 | # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh' |
| 3056 | # combined diff (for merge commit) |
| 3057 | elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) { |
| 3058 | $res{'nparents'} = length($1); |
| 3059 | $res{'from_mode'} = [ split(' ', $2) ]; |
| 3060 | $res{'to_mode'} = pop @{$res{'from_mode'}}; |
| 3061 | $res{'from_id'} = [ split(' ', $3) ]; |
| 3062 | $res{'to_id'} = pop @{$res{'from_id'}}; |
| 3063 | $res{'status'} = [ split('', $4) ]; |
| 3064 | $res{'to_file'} = unquote($5); |
| 3065 | } |
Jakub Narebski | 740e67f | 2006-08-21 23:07:00 +0200 | [diff] [blame] | 3066 | # 'c512b523472485aef4fff9e57b229d9d243c967f' |
Jakub Narebski | 0edcb37 | 2006-08-31 00:36:04 +0200 | [diff] [blame] | 3067 | elsif ($line =~ m/^([0-9a-fA-F]{40})$/) { |
| 3068 | $res{'commit'} = $1; |
| 3069 | } |
Jakub Narebski | 740e67f | 2006-08-21 23:07:00 +0200 | [diff] [blame] | 3070 | |
| 3071 | return wantarray ? %res : \%res; |
| 3072 | } |
| 3073 | |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 3074 | # wrapper: return parsed line of git-diff-tree "raw" output |
| 3075 | # (the argument might be raw line, or parsed info) |
| 3076 | sub parsed_difftree_line { |
| 3077 | my $line_or_ref = shift; |
| 3078 | |
| 3079 | if (ref($line_or_ref) eq "HASH") { |
| 3080 | # pre-parsed (or generated by hand) |
| 3081 | return $line_or_ref; |
| 3082 | } else { |
| 3083 | return parse_difftree_raw_line($line_or_ref); |
| 3084 | } |
| 3085 | } |
| 3086 | |
Jakub Narebski | cb849b4 | 2006-08-31 00:32:15 +0200 | [diff] [blame] | 3087 | # parse line of git-ls-tree output |
Jakub Narebski | 74fd872 | 2009-05-07 19:11:29 +0200 | [diff] [blame] | 3088 | sub parse_ls_tree_line { |
Jakub Narebski | cb849b4 | 2006-08-31 00:32:15 +0200 | [diff] [blame] | 3089 | my $line = shift; |
| 3090 | my %opts = @_; |
| 3091 | my %res; |
| 3092 | |
Jakub Narebski | e4b48ea | 2009-09-07 14:40:00 +0200 | [diff] [blame] | 3093 | if ($opts{'-l'}) { |
| 3094 | #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c' |
| 3095 | $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s; |
Jakub Narebski | cb849b4 | 2006-08-31 00:32:15 +0200 | [diff] [blame] | 3096 | |
Jakub Narebski | e4b48ea | 2009-09-07 14:40:00 +0200 | [diff] [blame] | 3097 | $res{'mode'} = $1; |
| 3098 | $res{'type'} = $2; |
| 3099 | $res{'hash'} = $3; |
| 3100 | $res{'size'} = $4; |
| 3101 | if ($opts{'-z'}) { |
| 3102 | $res{'name'} = $5; |
| 3103 | } else { |
| 3104 | $res{'name'} = unquote($5); |
| 3105 | } |
Jakub Narebski | cb849b4 | 2006-08-31 00:32:15 +0200 | [diff] [blame] | 3106 | } else { |
Jakub Narebski | e4b48ea | 2009-09-07 14:40:00 +0200 | [diff] [blame] | 3107 | #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' |
| 3108 | $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s; |
| 3109 | |
| 3110 | $res{'mode'} = $1; |
| 3111 | $res{'type'} = $2; |
| 3112 | $res{'hash'} = $3; |
| 3113 | if ($opts{'-z'}) { |
| 3114 | $res{'name'} = $4; |
| 3115 | } else { |
| 3116 | $res{'name'} = unquote($4); |
| 3117 | } |
Jakub Narebski | cb849b4 | 2006-08-31 00:32:15 +0200 | [diff] [blame] | 3118 | } |
| 3119 | |
| 3120 | return wantarray ? %res : \%res; |
| 3121 | } |
| 3122 | |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 3123 | # generates _two_ hashes, references to which are passed as 2 and 3 argument |
| 3124 | sub parse_from_to_diffinfo { |
| 3125 | my ($diffinfo, $from, $to, @parents) = @_; |
| 3126 | |
| 3127 | if ($diffinfo->{'nparents'}) { |
| 3128 | # combined diff |
| 3129 | $from->{'file'} = []; |
| 3130 | $from->{'href'} = []; |
| 3131 | fill_from_file_info($diffinfo, @parents) |
| 3132 | unless exists $diffinfo->{'from_file'}; |
| 3133 | for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) { |
Jakub Narebski | 9d30145 | 2007-11-01 12:38:08 +0100 | [diff] [blame] | 3134 | $from->{'file'}[$i] = |
| 3135 | defined $diffinfo->{'from_file'}[$i] ? |
| 3136 | $diffinfo->{'from_file'}[$i] : |
| 3137 | $diffinfo->{'to_file'}; |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 3138 | if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file |
| 3139 | $from->{'href'}[$i] = href(action=>"blob", |
| 3140 | hash_base=>$parents[$i], |
| 3141 | hash=>$diffinfo->{'from_id'}[$i], |
| 3142 | file_name=>$from->{'file'}[$i]); |
| 3143 | } else { |
| 3144 | $from->{'href'}[$i] = undef; |
| 3145 | } |
| 3146 | } |
| 3147 | } else { |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 3148 | # ordinary (not combined) diff |
Jakub Narebski | 9d30145 | 2007-11-01 12:38:08 +0100 | [diff] [blame] | 3149 | $from->{'file'} = $diffinfo->{'from_file'}; |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 3150 | if ($diffinfo->{'status'} ne "A") { # not new (added) file |
| 3151 | $from->{'href'} = href(action=>"blob", hash_base=>$hash_parent, |
| 3152 | hash=>$diffinfo->{'from_id'}, |
| 3153 | file_name=>$from->{'file'}); |
| 3154 | } else { |
| 3155 | delete $from->{'href'}; |
| 3156 | } |
| 3157 | } |
| 3158 | |
Jakub Narebski | 9d30145 | 2007-11-01 12:38:08 +0100 | [diff] [blame] | 3159 | $to->{'file'} = $diffinfo->{'to_file'}; |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 3160 | if (!is_deleted($diffinfo)) { # file exists in result |
| 3161 | $to->{'href'} = href(action=>"blob", hash_base=>$hash, |
| 3162 | hash=>$diffinfo->{'to_id'}, |
| 3163 | file_name=>$to->{'file'}); |
| 3164 | } else { |
| 3165 | delete $to->{'href'}; |
| 3166 | } |
| 3167 | } |
| 3168 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3169 | ## ...................................................................... |
| 3170 | ## parse to array of hashes functions |
| 3171 | |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 3172 | sub git_get_heads_list { |
Giuseppe Bilotta | 9b3f3de | 2010-11-11 13:26:10 +0100 | [diff] [blame] | 3173 | my ($limit, @classes) = @_; |
Giuseppe Bilotta | 00fa6fe | 2010-11-11 13:26:11 +0100 | [diff] [blame^] | 3174 | @classes = ('heads') unless @classes; |
Giuseppe Bilotta | 9b3f3de | 2010-11-11 13:26:10 +0100 | [diff] [blame] | 3175 | my @patterns = map { "refs/$_" } @classes; |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 3176 | my @headslist; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3177 | |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 3178 | open my $fd, '-|', git_cmd(), 'for-each-ref', |
| 3179 | ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate', |
| 3180 | '--format=%(objectname) %(refname) %(subject)%00%(committer)', |
Giuseppe Bilotta | 9b3f3de | 2010-11-11 13:26:10 +0100 | [diff] [blame] | 3181 | @patterns |
Jakub Narebski | c83a77e | 2006-09-15 03:43:28 +0200 | [diff] [blame] | 3182 | or return; |
| 3183 | while (my $line = <$fd>) { |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 3184 | my %ref_item; |
Jakub Narebski | 120ddde | 2006-09-19 14:33:22 +0200 | [diff] [blame] | 3185 | |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 3186 | chomp $line; |
| 3187 | my ($refinfo, $committerinfo) = split(/\0/, $line); |
| 3188 | my ($hash, $name, $title) = split(' ', $refinfo, 3); |
| 3189 | my ($committer, $epoch, $tz) = |
| 3190 | ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/); |
Jakub Narebski | bf901f8 | 2007-12-15 15:40:28 +0100 | [diff] [blame] | 3191 | $ref_item{'fullname'} = $name; |
Giuseppe Bilotta | 60efa24 | 2010-11-11 13:26:09 +0100 | [diff] [blame] | 3192 | $name =~ s!^refs/(?:head|remote)s/!!; |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 3193 | |
| 3194 | $ref_item{'name'} = $name; |
| 3195 | $ref_item{'id'} = $hash; |
| 3196 | $ref_item{'title'} = $title || '(no commit message)'; |
| 3197 | $ref_item{'epoch'} = $epoch; |
| 3198 | if ($epoch) { |
| 3199 | $ref_item{'age'} = age_string(time - $ref_item{'epoch'}); |
| 3200 | } else { |
| 3201 | $ref_item{'age'} = "unknown"; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3202 | } |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 3203 | |
| 3204 | push @headslist, \%ref_item; |
Jakub Narebski | c83a77e | 2006-09-15 03:43:28 +0200 | [diff] [blame] | 3205 | } |
| 3206 | close $fd; |
Junio C Hamano | 7a13b99 | 2006-07-31 19:18:34 -0700 | [diff] [blame] | 3207 | |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 3208 | return wantarray ? @headslist : \@headslist; |
| 3209 | } |
Jakub Narebski | c83a77e | 2006-09-15 03:43:28 +0200 | [diff] [blame] | 3210 | |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 3211 | sub git_get_tags_list { |
| 3212 | my $limit = shift; |
| 3213 | my @tagslist; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3214 | |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 3215 | open my $fd, '-|', git_cmd(), 'for-each-ref', |
| 3216 | ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate', |
| 3217 | '--format=%(objectname) %(objecttype) %(refname) '. |
| 3218 | '%(*objectname) %(*objecttype) %(subject)%00%(creator)', |
| 3219 | 'refs/tags' |
| 3220 | or return; |
| 3221 | while (my $line = <$fd>) { |
| 3222 | my %ref_item; |
| 3223 | |
| 3224 | chomp $line; |
| 3225 | my ($refinfo, $creatorinfo) = split(/\0/, $line); |
| 3226 | my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6); |
| 3227 | my ($creator, $epoch, $tz) = |
| 3228 | ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/); |
Jakub Narebski | bf901f8 | 2007-12-15 15:40:28 +0100 | [diff] [blame] | 3229 | $ref_item{'fullname'} = $name; |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 3230 | $name =~ s!^refs/tags/!!; |
| 3231 | |
| 3232 | $ref_item{'type'} = $type; |
| 3233 | $ref_item{'id'} = $id; |
| 3234 | $ref_item{'name'} = $name; |
| 3235 | if ($type eq "tag") { |
| 3236 | $ref_item{'subject'} = $title; |
| 3237 | $ref_item{'reftype'} = $reftype; |
| 3238 | $ref_item{'refid'} = $refid; |
| 3239 | } else { |
| 3240 | $ref_item{'reftype'} = $type; |
| 3241 | $ref_item{'refid'} = $id; |
| 3242 | } |
| 3243 | |
| 3244 | if ($type eq "tag" || $type eq "commit") { |
| 3245 | $ref_item{'epoch'} = $epoch; |
| 3246 | if ($epoch) { |
| 3247 | $ref_item{'age'} = age_string(time - $ref_item{'epoch'}); |
| 3248 | } else { |
| 3249 | $ref_item{'age'} = "unknown"; |
| 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | push @tagslist, \%ref_item; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3254 | } |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 3255 | close $fd; |
| 3256 | |
| 3257 | return wantarray ? @tagslist : \@tagslist; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3258 | } |
| 3259 | |
| 3260 | ## ---------------------------------------------------------------------- |
| 3261 | ## filesystem-related functions |
| 3262 | |
| 3263 | sub get_file_owner { |
| 3264 | my $path = shift; |
| 3265 | |
| 3266 | my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path); |
| 3267 | my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid); |
| 3268 | if (!defined $gcos) { |
| 3269 | return undef; |
| 3270 | } |
| 3271 | my $owner = $gcos; |
| 3272 | $owner =~ s/[,;].*$//; |
Martin Koegler | 00f429a | 2007-06-03 17:42:44 +0200 | [diff] [blame] | 3273 | return to_utf8($owner); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3274 | } |
| 3275 | |
Jakub Narebski | 2dcb5e1 | 2008-12-01 19:01:42 +0100 | [diff] [blame] | 3276 | # assume that file exists |
| 3277 | sub insert_file { |
| 3278 | my $filename = shift; |
| 3279 | |
| 3280 | open my $fd, '<', $filename; |
Jakub Narebski | 4586864 | 2008-12-08 14:13:21 +0100 | [diff] [blame] | 3281 | print map { to_utf8($_) } <$fd>; |
Jakub Narebski | 2dcb5e1 | 2008-12-01 19:01:42 +0100 | [diff] [blame] | 3282 | close $fd; |
| 3283 | } |
| 3284 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3285 | ## ...................................................................... |
| 3286 | ## mimetype related functions |
| 3287 | |
| 3288 | sub mimetype_guess_file { |
| 3289 | my $filename = shift; |
| 3290 | my $mimemap = shift; |
| 3291 | -r $mimemap or return undef; |
| 3292 | |
| 3293 | my %mimemap; |
Jakub Narebski | dff2b6d | 2009-05-10 02:38:34 +0200 | [diff] [blame] | 3294 | open(my $mh, '<', $mimemap) or return undef; |
Jakub Narebski | ad87e4f | 2009-05-11 03:21:06 +0200 | [diff] [blame] | 3295 | while (<$mh>) { |
Jakub Narebski | 618918e | 2006-08-14 02:15:22 +0200 | [diff] [blame] | 3296 | next if m/^#/; # skip comments |
Jakub Narebski | ad87e4f | 2009-05-11 03:21:06 +0200 | [diff] [blame] | 3297 | my ($mimetype, $exts) = split(/\t+/); |
Junio C Hamano | 46b059d | 2006-07-31 19:24:37 -0700 | [diff] [blame] | 3298 | if (defined $exts) { |
| 3299 | my @exts = split(/\s+/, $exts); |
| 3300 | foreach my $ext (@exts) { |
Jakub Narebski | ad87e4f | 2009-05-11 03:21:06 +0200 | [diff] [blame] | 3301 | $mimemap{$ext} = $mimetype; |
Junio C Hamano | 46b059d | 2006-07-31 19:24:37 -0700 | [diff] [blame] | 3302 | } |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3303 | } |
| 3304 | } |
Jakub Narebski | ad87e4f | 2009-05-11 03:21:06 +0200 | [diff] [blame] | 3305 | close($mh); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3306 | |
Jakub Narebski | 8059319 | 2006-09-19 13:57:03 +0200 | [diff] [blame] | 3307 | $filename =~ /\.([^.]*)$/; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3308 | return $mimemap{$1}; |
| 3309 | } |
| 3310 | |
| 3311 | sub mimetype_guess { |
| 3312 | my $filename = shift; |
| 3313 | my $mime; |
| 3314 | $filename =~ /\./ or return undef; |
| 3315 | |
| 3316 | if ($mimetypes_file) { |
| 3317 | my $file = $mimetypes_file; |
Jakub Narebski | d5aa50d | 2006-08-14 02:16:33 +0200 | [diff] [blame] | 3318 | if ($file !~ m!^/!) { # if it is relative path |
| 3319 | # it is relative to project |
| 3320 | $file = "$projectroot/$project/$file"; |
| 3321 | } |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3322 | $mime = mimetype_guess_file($filename, $file); |
| 3323 | } |
| 3324 | $mime ||= mimetype_guess_file($filename, '/etc/mime.types'); |
| 3325 | return $mime; |
| 3326 | } |
| 3327 | |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 3328 | sub blob_mimetype { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3329 | my $fd = shift; |
| 3330 | my $filename = shift; |
| 3331 | |
| 3332 | if ($filename) { |
| 3333 | my $mime = mimetype_guess($filename); |
| 3334 | $mime and return $mime; |
| 3335 | } |
| 3336 | |
| 3337 | # just in case |
| 3338 | return $default_blob_plain_mimetype unless $fd; |
| 3339 | |
| 3340 | if (-T $fd) { |
Jakub Narebski | 7f718e8 | 2008-06-03 16:47:10 +0200 | [diff] [blame] | 3341 | return 'text/plain'; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3342 | } elsif (! $filename) { |
| 3343 | return 'application/octet-stream'; |
| 3344 | } elsif ($filename =~ m/\.png$/i) { |
| 3345 | return 'image/png'; |
| 3346 | } elsif ($filename =~ m/\.gif$/i) { |
| 3347 | return 'image/gif'; |
| 3348 | } elsif ($filename =~ m/\.jpe?g$/i) { |
| 3349 | return 'image/jpeg'; |
| 3350 | } else { |
| 3351 | return 'application/octet-stream'; |
| 3352 | } |
| 3353 | } |
| 3354 | |
Jakub Narebski | 7f718e8 | 2008-06-03 16:47:10 +0200 | [diff] [blame] | 3355 | sub blob_contenttype { |
| 3356 | my ($fd, $file_name, $type) = @_; |
| 3357 | |
| 3358 | $type ||= blob_mimetype($fd, $file_name); |
| 3359 | if ($type eq 'text/plain' && defined $default_text_plain_charset) { |
| 3360 | $type .= "; charset=$default_text_plain_charset"; |
| 3361 | } |
| 3362 | |
| 3363 | return $type; |
| 3364 | } |
| 3365 | |
Jakub Narebski | 592ea41 | 2010-04-27 21:34:45 +0200 | [diff] [blame] | 3366 | # guess file syntax for syntax highlighting; return undef if no highlighting |
| 3367 | # the name of syntax can (in the future) depend on syntax highlighter used |
| 3368 | sub guess_file_syntax { |
| 3369 | my ($highlight, $mimetype, $file_name) = @_; |
| 3370 | return undef unless ($highlight && defined $file_name); |
Jakub Narebski | 592ea41 | 2010-04-27 21:34:45 +0200 | [diff] [blame] | 3371 | my $basename = basename($file_name, '.in'); |
| 3372 | return $highlight_basename{$basename} |
| 3373 | if exists $highlight_basename{$basename}; |
| 3374 | |
| 3375 | $basename =~ /\.([^.]*)$/; |
| 3376 | my $ext = $1 or return undef; |
| 3377 | return $highlight_ext{$ext} |
| 3378 | if exists $highlight_ext{$ext}; |
| 3379 | |
| 3380 | return undef; |
| 3381 | } |
| 3382 | |
| 3383 | # run highlighter and return FD of its output, |
| 3384 | # or return original FD if no highlighting |
| 3385 | sub run_highlighter { |
| 3386 | my ($fd, $highlight, $syntax) = @_; |
| 3387 | return $fd unless ($highlight && defined $syntax); |
| 3388 | |
| 3389 | close $fd |
| 3390 | or die_error(404, "Reading blob failed"); |
| 3391 | open $fd, quote_command(git_cmd(), "cat-file", "blob", $hash)." | ". |
Christopher Wilson | 7ce896b | 2010-09-21 00:25:19 -0700 | [diff] [blame] | 3392 | quote_command($highlight_bin). |
| 3393 | " --xhtml --fragment --syntax $syntax |" |
Jakub Narebski | 592ea41 | 2010-04-27 21:34:45 +0200 | [diff] [blame] | 3394 | or die_error(500, "Couldn't open file or run syntax highlighter"); |
| 3395 | return $fd; |
| 3396 | } |
| 3397 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3398 | ## ====================================================================== |
| 3399 | ## functions printing HTML: header, footer, error page |
| 3400 | |
Jakub Narebski | efb2d0c | 2010-04-24 16:01:10 +0200 | [diff] [blame] | 3401 | sub get_page_title { |
| 3402 | my $title = to_utf8($site_name); |
| 3403 | |
| 3404 | return $title unless (defined $project); |
| 3405 | $title .= " - " . to_utf8($project); |
| 3406 | |
| 3407 | return $title unless (defined $action); |
| 3408 | $title .= "/$action"; # $action is US-ASCII (7bit ASCII) |
| 3409 | |
| 3410 | return $title unless (defined $file_name); |
| 3411 | $title .= " - " . esc_path($file_name); |
| 3412 | if ($action eq "tree" && $file_name !~ m|/$|) { |
| 3413 | $title .= "/"; |
| 3414 | } |
| 3415 | |
| 3416 | return $title; |
| 3417 | } |
| 3418 | |
Kay Sievers | 12a88f2 | 2005-08-07 20:02:47 +0200 | [diff] [blame] | 3419 | sub git_header_html { |
Kay Sievers | a59d4af | 2005-08-07 20:15:44 +0200 | [diff] [blame] | 3420 | my $status = shift || "200 OK"; |
Kay Sievers | 1104429 | 2005-10-19 03:18:45 +0200 | [diff] [blame] | 3421 | my $expires = shift; |
Jakub Narebski | 7a59745 | 2010-04-24 16:00:04 +0200 | [diff] [blame] | 3422 | my %opts = @_; |
Kay Sievers | a59d4af | 2005-08-07 20:15:44 +0200 | [diff] [blame] | 3423 | |
Jakub Narebski | efb2d0c | 2010-04-24 16:01:10 +0200 | [diff] [blame] | 3424 | my $title = get_page_title(); |
Alp Toker | f6801d6 | 2006-07-11 11:19:34 +0100 | [diff] [blame] | 3425 | my $content_type; |
| 3426 | # require explicit support from the UA if we are to send the page as |
| 3427 | # 'application/xhtml+xml', otherwise send it as plain old 'text/html'. |
| 3428 | # we have to do this because MSIE sometimes globs '*/*', pretending to |
| 3429 | # support xhtml+xml but choking when it gets what it asked for. |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 3430 | if (defined $cgi->http('HTTP_ACCEPT') && |
| 3431 | $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ && |
| 3432 | $cgi->Accept('application/xhtml+xml') != 0) { |
Alp Toker | f6801d6 | 2006-07-11 11:19:34 +0100 | [diff] [blame] | 3433 | $content_type = 'application/xhtml+xml'; |
| 3434 | } else { |
| 3435 | $content_type = 'text/html'; |
| 3436 | } |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 3437 | print $cgi->header(-type=>$content_type, -charset => 'utf-8', |
Jakub Narebski | 7a59745 | 2010-04-24 16:00:04 +0200 | [diff] [blame] | 3438 | -status=> $status, -expires => $expires) |
Jakub Narebski | ad709ea | 2010-06-13 00:35:59 +0200 | [diff] [blame] | 3439 | unless ($opts{'-no_http_header'}); |
Jakub Narebski | 45c9a75 | 2006-12-27 23:59:51 +0100 | [diff] [blame] | 3440 | my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : ''; |
Kay Sievers | a59d4af | 2005-08-07 20:15:44 +0200 | [diff] [blame] | 3441 | print <<EOF; |
Kay Sievers | 6191f8e | 2005-08-07 20:19:56 +0200 | [diff] [blame] | 3442 | <?xml version="1.0" encoding="utf-8"?> |
Kay Sievers | 161332a | 2005-08-07 19:49:46 +0200 | [diff] [blame] | 3443 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
Kay Sievers | 034df39 | 2005-08-07 20:20:07 +0200 | [diff] [blame] | 3444 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"> |
Jakub Narebski | d4baf9e | 2006-08-17 11:21:28 +0200 | [diff] [blame] | 3445 | <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke --> |
Jakub Narebski | ae20de5 | 2006-06-21 09:48:03 +0200 | [diff] [blame] | 3446 | <!-- git core binaries version $git_version --> |
Kay Sievers | 161332a | 2005-08-07 19:49:46 +0200 | [diff] [blame] | 3447 | <head> |
Alp Toker | f6801d6 | 2006-07-11 11:19:34 +0100 | [diff] [blame] | 3448 | <meta http-equiv="content-type" content="$content_type; charset=utf-8"/> |
Jakub Narebski | 45c9a75 | 2006-12-27 23:59:51 +0100 | [diff] [blame] | 3449 | <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/> |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 3450 | <meta name="robots" content="index, nofollow"/> |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 3451 | <title>$title</title> |
Kay Sievers | 161332a | 2005-08-07 19:49:46 +0200 | [diff] [blame] | 3452 | EOF |
Giuseppe Bilotta | 41a4d16 | 2009-01-31 02:31:52 +0100 | [diff] [blame] | 3453 | # the stylesheet, favicon etc urls won't work correctly with path_info |
| 3454 | # unless we set the appropriate base URL |
Giuseppe Bilotta | c3254ae | 2009-01-31 02:31:50 +0100 | [diff] [blame] | 3455 | if ($ENV{'PATH_INFO'}) { |
Giuseppe Bilotta | 81d3fe9 | 2009-02-15 10:18:36 +0100 | [diff] [blame] | 3456 | print "<base href=\"".esc_url($base_url)."\" />\n"; |
Giuseppe Bilotta | c3254ae | 2009-01-31 02:31:50 +0100 | [diff] [blame] | 3457 | } |
Giuseppe Bilotta | 41a4d16 | 2009-01-31 02:31:52 +0100 | [diff] [blame] | 3458 | # print out each stylesheet that exist, providing backwards capability |
| 3459 | # for those people who defined $stylesheet in a config file |
Alan Chandler | b2d3476 | 2006-10-03 13:49:03 +0100 | [diff] [blame] | 3460 | if (defined $stylesheet) { |
Alan Chandler | b2d3476 | 2006-10-03 13:49:03 +0100 | [diff] [blame] | 3461 | print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n"; |
| 3462 | } else { |
| 3463 | foreach my $stylesheet (@stylesheets) { |
| 3464 | next unless $stylesheet; |
| 3465 | print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n"; |
| 3466 | } |
| 3467 | } |
Matthias Lederhofer | dd04c42 | 2006-08-06 13:25:41 +0200 | [diff] [blame] | 3468 | if (defined $project) { |
Jakub Narebski | 3562198 | 2008-04-20 22:09:48 +0200 | [diff] [blame] | 3469 | my %href_params = get_feed_info(); |
| 3470 | if (!exists $href_params{'-title'}) { |
| 3471 | $href_params{'-title'} = 'log'; |
| 3472 | } |
| 3473 | |
| 3474 | foreach my $format qw(RSS Atom) { |
| 3475 | my $type = lc($format); |
| 3476 | my %link_attr = ( |
| 3477 | '-rel' => 'alternate', |
| 3478 | '-title' => "$project - $href_params{'-title'} - $format feed", |
| 3479 | '-type' => "application/$type+xml" |
| 3480 | ); |
| 3481 | |
| 3482 | $href_params{'action'} = $type; |
| 3483 | $link_attr{'-href'} = href(%href_params); |
| 3484 | print "<link ". |
| 3485 | "rel=\"$link_attr{'-rel'}\" ". |
| 3486 | "title=\"$link_attr{'-title'}\" ". |
| 3487 | "href=\"$link_attr{'-href'}\" ". |
| 3488 | "type=\"$link_attr{'-type'}\" ". |
| 3489 | "/>\n"; |
| 3490 | |
| 3491 | $href_params{'extra_options'} = '--no-merges'; |
| 3492 | $link_attr{'-href'} = href(%href_params); |
| 3493 | $link_attr{'-title'} .= ' (no merges)'; |
| 3494 | print "<link ". |
| 3495 | "rel=\"$link_attr{'-rel'}\" ". |
| 3496 | "title=\"$link_attr{'-title'}\" ". |
| 3497 | "href=\"$link_attr{'-href'}\" ". |
| 3498 | "type=\"$link_attr{'-type'}\" ". |
| 3499 | "/>\n"; |
| 3500 | } |
| 3501 | |
Jakub Narebski | 9d0734a | 2006-09-15 11:11:33 +0200 | [diff] [blame] | 3502 | } else { |
| 3503 | printf('<link rel="alternate" title="%s projects list" '. |
Jakub Narebski | 3562198 | 2008-04-20 22:09:48 +0200 | [diff] [blame] | 3504 | 'href="%s" type="text/plain; charset=utf-8" />'."\n", |
Jakub Narebski | 9d0734a | 2006-09-15 11:11:33 +0200 | [diff] [blame] | 3505 | $site_name, href(project=>undef, action=>"project_index")); |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 3506 | printf('<link rel="alternate" title="%s projects feeds" '. |
Jakub Narebski | 3562198 | 2008-04-20 22:09:48 +0200 | [diff] [blame] | 3507 | 'href="%s" type="text/x-opml" />'."\n", |
Jakub Narebski | 9d0734a | 2006-09-15 11:11:33 +0200 | [diff] [blame] | 3508 | $site_name, href(project=>undef, action=>"opml")); |
Matthias Lederhofer | dd04c42 | 2006-08-06 13:25:41 +0200 | [diff] [blame] | 3509 | } |
Jakub Narebski | 0b5deba | 2006-09-04 20:32:13 +0200 | [diff] [blame] | 3510 | if (defined $favicon) { |
Jakub Narebski | 3562198 | 2008-04-20 22:09:48 +0200 | [diff] [blame] | 3511 | print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n); |
Jakub Narebski | 0b5deba | 2006-09-04 20:32:13 +0200 | [diff] [blame] | 3512 | } |
Jakub Narebski | 1016135 | 2006-08-05 13:18:58 +0200 | [diff] [blame] | 3513 | |
Matthias Lederhofer | dd04c42 | 2006-08-06 13:25:41 +0200 | [diff] [blame] | 3514 | print "</head>\n" . |
Alan Chandler | b2d3476 | 2006-10-03 13:49:03 +0100 | [diff] [blame] | 3515 | "<body>\n"; |
| 3516 | |
John 'Warthog9' Hawley | 24d4afc | 2010-01-30 23:30:41 +0100 | [diff] [blame] | 3517 | if (defined $site_header && -f $site_header) { |
Jakub Narebski | 2dcb5e1 | 2008-12-01 19:01:42 +0100 | [diff] [blame] | 3518 | insert_file($site_header); |
Alan Chandler | b2d3476 | 2006-10-03 13:49:03 +0100 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | print "<div class=\"page_header\">\n" . |
Jakub Narebski | 9a7a62f | 2006-10-06 12:31:05 +0200 | [diff] [blame] | 3522 | $cgi->a({-href => esc_url($logo_url), |
| 3523 | -title => $logo_label}, |
| 3524 | qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>)); |
Jakub Narebski | f93bff8 | 2006-09-26 01:58:41 +0200 | [diff] [blame] | 3525 | print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / "; |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 3526 | if (defined $project) { |
Martin Waitz | 1c2a4f5 | 2006-08-16 00:24:30 +0200 | [diff] [blame] | 3527 | print $cgi->a({-href => href(action=>"summary")}, esc_html($project)); |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 3528 | if (defined $action) { |
| 3529 | print " / $action"; |
| 3530 | } |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 3531 | print "\n"; |
Robert Fitzsimons | 6be9351 | 2006-12-23 03:35:16 +0000 | [diff] [blame] | 3532 | } |
Petr Baudis | d77b567 | 2007-05-17 04:24:19 +0200 | [diff] [blame] | 3533 | print "</div>\n"; |
| 3534 | |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 3535 | my $have_search = gitweb_check_feature('search'); |
Jakub Narebski | f70dda2 | 2008-06-02 11:54:41 +0200 | [diff] [blame] | 3536 | if (defined $project && $have_search) { |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 3537 | if (!defined $searchtext) { |
| 3538 | $searchtext = ""; |
| 3539 | } |
Kay Sievers | c39e47d | 2005-09-17 03:00:21 +0200 | [diff] [blame] | 3540 | my $search_hash; |
Timo Hirvonen | 4c5c202 | 2006-06-20 16:41:05 +0300 | [diff] [blame] | 3541 | if (defined $hash_base) { |
| 3542 | $search_hash = $hash_base; |
| 3543 | } elsif (defined $hash) { |
Kay Sievers | c39e47d | 2005-09-17 03:00:21 +0200 | [diff] [blame] | 3544 | $search_hash = $hash; |
| 3545 | } else { |
Jakub Narebski | 8adc4bd | 2006-06-22 08:52:57 +0200 | [diff] [blame] | 3546 | $search_hash = "HEAD"; |
Kay Sievers | c39e47d | 2005-09-17 03:00:21 +0200 | [diff] [blame] | 3547 | } |
Matt McCutchen | 40375a8 | 2007-06-28 14:57:07 -0400 | [diff] [blame] | 3548 | my $action = $my_uri; |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 3549 | my $use_pathinfo = gitweb_check_feature('pathinfo'); |
Matt McCutchen | 40375a8 | 2007-06-28 14:57:07 -0400 | [diff] [blame] | 3550 | if ($use_pathinfo) { |
martin f. krafft | 85d17a1 | 2008-04-20 23:23:38 +0200 | [diff] [blame] | 3551 | $action .= "/".esc_url($project); |
Matt McCutchen | 40375a8 | 2007-06-28 14:57:07 -0400 | [diff] [blame] | 3552 | } |
Matt McCutchen | 40375a8 | 2007-06-28 14:57:07 -0400 | [diff] [blame] | 3553 | print $cgi->startform(-method => "get", -action => $action) . |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 3554 | "<div class=\"search\">\n" . |
Jakub Narebski | f70dda2 | 2008-06-02 11:54:41 +0200 | [diff] [blame] | 3555 | (!$use_pathinfo && |
| 3556 | $cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) . "\n") . |
| 3557 | $cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) . "\n" . |
| 3558 | $cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) . "\n" . |
Petr Baudis | 88ad729 | 2006-10-24 05:15:46 +0200 | [diff] [blame] | 3559 | $cgi->popup_menu(-name => 'st', -default => 'commit', |
Petr Baudis | e773855 | 2007-05-17 04:31:12 +0200 | [diff] [blame] | 3560 | -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) . |
Petr Baudis | 88ad729 | 2006-10-24 05:15:46 +0200 | [diff] [blame] | 3561 | $cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) . |
| 3562 | " search:\n", |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 3563 | $cgi->textfield(-name => "s", -value => $searchtext) . "\n" . |
Petr Baudis | 0e55991 | 2008-02-26 13:22:08 +0100 | [diff] [blame] | 3564 | "<span title=\"Extended regular expression\">" . |
| 3565 | $cgi->checkbox(-name => 'sr', -value => 1, -label => 're', |
| 3566 | -checked => $search_use_regexp) . |
| 3567 | "</span>" . |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 3568 | "</div>" . |
| 3569 | $cgi->end_form() . "\n"; |
Kay Sievers | 4c02e3c | 2005-08-07 19:52:52 +0200 | [diff] [blame] | 3570 | } |
Kay Sievers | 161332a | 2005-08-07 19:49:46 +0200 | [diff] [blame] | 3571 | } |
| 3572 | |
Kay Sievers | 12a88f2 | 2005-08-07 20:02:47 +0200 | [diff] [blame] | 3573 | sub git_footer_html { |
Jakub Narebski | 3562198 | 2008-04-20 22:09:48 +0200 | [diff] [blame] | 3574 | my $feed_class = 'rss_logo'; |
| 3575 | |
Kay Sievers | 6191f8e | 2005-08-07 20:19:56 +0200 | [diff] [blame] | 3576 | print "<div class=\"page_footer\">\n"; |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 3577 | if (defined $project) { |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 3578 | my $descr = git_get_project_description($project); |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 3579 | if (defined $descr) { |
Kay Sievers | 40c1381 | 2005-11-19 17:41:29 +0100 | [diff] [blame] | 3580 | print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n"; |
Kay Sievers | 6191f8e | 2005-08-07 20:19:56 +0200 | [diff] [blame] | 3581 | } |
Jakub Narebski | 3562198 | 2008-04-20 22:09:48 +0200 | [diff] [blame] | 3582 | |
| 3583 | my %href_params = get_feed_info(); |
| 3584 | if (!%href_params) { |
| 3585 | $feed_class .= ' generic'; |
| 3586 | } |
| 3587 | $href_params{'-title'} ||= 'log'; |
| 3588 | |
| 3589 | foreach my $format qw(RSS Atom) { |
| 3590 | $href_params{'action'} = lc($format); |
| 3591 | print $cgi->a({-href => href(%href_params), |
| 3592 | -title => "$href_params{'-title'} $format feed", |
| 3593 | -class => $feed_class}, $format)."\n"; |
| 3594 | } |
| 3595 | |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 3596 | } else { |
Jakub Narebski | a1565c4 | 2006-09-15 19:30:34 +0200 | [diff] [blame] | 3597 | print $cgi->a({-href => href(project=>undef, action=>"opml"), |
Jakub Narebski | 3562198 | 2008-04-20 22:09:48 +0200 | [diff] [blame] | 3598 | -class => $feed_class}, "OPML") . " "; |
Jakub Narebski | 9d0734a | 2006-09-15 11:11:33 +0200 | [diff] [blame] | 3599 | print $cgi->a({-href => href(project=>undef, action=>"project_index"), |
Jakub Narebski | 3562198 | 2008-04-20 22:09:48 +0200 | [diff] [blame] | 3600 | -class => $feed_class}, "TXT") . "\n"; |
Kay Sievers | ff7669a | 2005-08-07 20:13:02 +0200 | [diff] [blame] | 3601 | } |
Jakub Narebski | 3562198 | 2008-04-20 22:09:48 +0200 | [diff] [blame] | 3602 | print "</div>\n"; # class="page_footer" |
Alan Chandler | b2d3476 | 2006-10-03 13:49:03 +0100 | [diff] [blame] | 3603 | |
Jakub Narebski | aa7dd05 | 2009-09-01 13:39:16 +0200 | [diff] [blame] | 3604 | if (defined $t0 && gitweb_check_feature('timed')) { |
| 3605 | print "<div id=\"generating_info\">\n"; |
| 3606 | print 'This page took '. |
| 3607 | '<span id="generating_time" class="time_span">'. |
| 3608 | Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]). |
| 3609 | ' seconds </span>'. |
| 3610 | ' and '. |
| 3611 | '<span id="generating_cmd">'. |
| 3612 | $number_of_git_cmds. |
| 3613 | '</span> git commands '. |
| 3614 | " to generate.\n"; |
| 3615 | print "</div>\n"; # class="page_footer" |
| 3616 | } |
| 3617 | |
John 'Warthog9' Hawley | 24d4afc | 2010-01-30 23:30:41 +0100 | [diff] [blame] | 3618 | if (defined $site_footer && -f $site_footer) { |
Jakub Narebski | 2dcb5e1 | 2008-12-01 19:01:42 +0100 | [diff] [blame] | 3619 | insert_file($site_footer); |
Alan Chandler | b2d3476 | 2006-10-03 13:49:03 +0100 | [diff] [blame] | 3620 | } |
| 3621 | |
Jakub Narebski | c4ccf61 | 2009-09-01 13:39:19 +0200 | [diff] [blame] | 3622 | print qq!<script type="text/javascript" src="$javascript"></script>\n!; |
John 'Warthog9' Hawley | b62a1a9 | 2010-01-30 23:30:39 +0100 | [diff] [blame] | 3623 | if (defined $action && |
| 3624 | $action eq 'blame_incremental') { |
Jakub Narebski | c4ccf61 | 2009-09-01 13:39:19 +0200 | [diff] [blame] | 3625 | print qq!<script type="text/javascript">\n!. |
| 3626 | qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!. |
| 3627 | qq! "!. href() .qq!");\n!. |
| 3628 | qq!</script>\n!; |
Jakub Narebski | e627e50 | 2009-11-26 21:12:15 +0100 | [diff] [blame] | 3629 | } elsif (gitweb_check_feature('javascript-actions')) { |
Jakub Narebski | c4ccf61 | 2009-09-01 13:39:19 +0200 | [diff] [blame] | 3630 | print qq!<script type="text/javascript">\n!. |
| 3631 | qq!window.onload = fixLinks;\n!. |
| 3632 | qq!</script>\n!; |
| 3633 | } |
| 3634 | |
Alan Chandler | b2d3476 | 2006-10-03 13:49:03 +0100 | [diff] [blame] | 3635 | print "</body>\n" . |
Kay Sievers | 9cd3d98 | 2005-08-07 20:17:42 +0200 | [diff] [blame] | 3636 | "</html>"; |
Kay Sievers | 161332a | 2005-08-07 19:49:46 +0200 | [diff] [blame] | 3637 | } |
| 3638 | |
Jakub Narebski | 453541f | 2010-02-07 21:51:18 +0100 | [diff] [blame] | 3639 | # die_error(<http_status_code>, <error_message>[, <detailed_html_description>]) |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 3640 | # Example: die_error(404, 'Hash not found') |
| 3641 | # By convention, use the following status codes (as defined in RFC 2616): |
| 3642 | # 400: Invalid or missing CGI parameters, or |
| 3643 | # requested object exists but has wrong type. |
| 3644 | # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on |
| 3645 | # this server or project. |
| 3646 | # 404: Requested object/revision/project doesn't exist. |
| 3647 | # 500: The server isn't configured properly, or |
| 3648 | # an internal error occurred (e.g. failed assertions caused by bugs), or |
| 3649 | # an unknown error occurred (e.g. the git binary died unexpectedly). |
John 'Warthog9' Hawley | b62a1a9 | 2010-01-30 23:30:39 +0100 | [diff] [blame] | 3650 | # 503: The server is currently unavailable (because it is overloaded, |
| 3651 | # or down for maintenance). Generally, this is a temporary state. |
Kay Sievers | 061cc7c | 2005-08-07 20:15:57 +0200 | [diff] [blame] | 3652 | sub die_error { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 3653 | my $status = shift || 500; |
Jakub Narebski | 1df4876 | 2010-02-07 21:52:25 +0100 | [diff] [blame] | 3654 | my $error = esc_html(shift) || "Internal Server Error"; |
John 'Warthog9' Hawley | aa14013 | 2010-01-30 23:30:44 +0100 | [diff] [blame] | 3655 | my $extra = shift; |
Jakub Narebski | 7a59745 | 2010-04-24 16:00:04 +0200 | [diff] [blame] | 3656 | my %opts = @_; |
Kay Sievers | 664f4cc | 2005-08-07 20:17:19 +0200 | [diff] [blame] | 3657 | |
John 'Warthog9' Hawley | b62a1a9 | 2010-01-30 23:30:39 +0100 | [diff] [blame] | 3658 | my %http_responses = ( |
| 3659 | 400 => '400 Bad Request', |
| 3660 | 403 => '403 Forbidden', |
| 3661 | 404 => '404 Not Found', |
| 3662 | 500 => '500 Internal Server Error', |
| 3663 | 503 => '503 Service Unavailable', |
| 3664 | ); |
Jakub Narebski | 7a59745 | 2010-04-24 16:00:04 +0200 | [diff] [blame] | 3665 | git_header_html($http_responses{$status}, undef, %opts); |
Jakub Narebski | 59b9f61 | 2006-08-22 23:42:53 +0200 | [diff] [blame] | 3666 | print <<EOF; |
| 3667 | <div class="page_body"> |
| 3668 | <br /><br /> |
| 3669 | $status - $error |
| 3670 | <br /> |
Jakub Narebski | 59b9f61 | 2006-08-22 23:42:53 +0200 | [diff] [blame] | 3671 | EOF |
John 'Warthog9' Hawley | aa14013 | 2010-01-30 23:30:44 +0100 | [diff] [blame] | 3672 | if (defined $extra) { |
| 3673 | print "<hr />\n" . |
| 3674 | "$extra\n"; |
| 3675 | } |
| 3676 | print "</div>\n"; |
| 3677 | |
Kay Sievers | a59d4af | 2005-08-07 20:15:44 +0200 | [diff] [blame] | 3678 | git_footer_html(); |
Jakub Narebski | 7a59745 | 2010-04-24 16:00:04 +0200 | [diff] [blame] | 3679 | goto DONE_GITWEB |
| 3680 | unless ($opts{'-error_handler'}); |
Kay Sievers | a59d4af | 2005-08-07 20:15:44 +0200 | [diff] [blame] | 3681 | } |
| 3682 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3683 | ## ---------------------------------------------------------------------- |
| 3684 | ## functions printing or outputting HTML: navigation |
| 3685 | |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 3686 | sub git_print_page_nav { |
Jakub Narebski | b18f9bf | 2006-07-30 14:59:57 +0200 | [diff] [blame] | 3687 | my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_; |
| 3688 | $extra = '' if !defined $extra; # pager or formats |
| 3689 | |
| 3690 | my @navs = qw(summary shortlog log commit commitdiff tree); |
| 3691 | if ($suppress) { |
| 3692 | @navs = grep { $_ ne $suppress } @navs; |
| 3693 | } |
| 3694 | |
Martin Waitz | 1c2a4f5 | 2006-08-16 00:24:30 +0200 | [diff] [blame] | 3695 | my %arg = map { $_ => {action=>$_} } @navs; |
Jakub Narebski | b18f9bf | 2006-07-30 14:59:57 +0200 | [diff] [blame] | 3696 | if (defined $head) { |
| 3697 | for (qw(commit commitdiff)) { |
Jakub Narebski | 3be8e72 | 2007-04-01 22:22:21 +0200 | [diff] [blame] | 3698 | $arg{$_}{'hash'} = $head; |
Jakub Narebski | b18f9bf | 2006-07-30 14:59:57 +0200 | [diff] [blame] | 3699 | } |
| 3700 | if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) { |
| 3701 | for (qw(shortlog log)) { |
Jakub Narebski | 3be8e72 | 2007-04-01 22:22:21 +0200 | [diff] [blame] | 3702 | $arg{$_}{'hash'} = $head; |
Jakub Narebski | b18f9bf | 2006-07-30 14:59:57 +0200 | [diff] [blame] | 3703 | } |
| 3704 | } |
| 3705 | } |
Petr Baudis | d627f68 | 2008-10-02 16:36:52 +0200 | [diff] [blame] | 3706 | |
Jakub Narebski | 3be8e72 | 2007-04-01 22:22:21 +0200 | [diff] [blame] | 3707 | $arg{'tree'}{'hash'} = $treehead if defined $treehead; |
| 3708 | $arg{'tree'}{'hash_base'} = $treebase if defined $treebase; |
Jakub Narebski | b18f9bf | 2006-07-30 14:59:57 +0200 | [diff] [blame] | 3709 | |
Junio C Hamano | a7c5a28 | 2008-11-29 13:02:08 -0800 | [diff] [blame] | 3710 | my @actions = gitweb_get_feature('actions'); |
Jakub Narebski | 2b11e05 | 2008-10-12 00:02:32 +0200 | [diff] [blame] | 3711 | my %repl = ( |
| 3712 | '%' => '%', |
| 3713 | 'n' => $project, # project name |
| 3714 | 'f' => $git_dir, # project path within filesystem |
| 3715 | 'h' => $treehead || '', # current hash ('h' parameter) |
| 3716 | 'b' => $treebase || '', # hash base ('hb' parameter) |
| 3717 | ); |
Petr Baudis | d627f68 | 2008-10-02 16:36:52 +0200 | [diff] [blame] | 3718 | while (@actions) { |
Jakub Narebski | 2b11e05 | 2008-10-12 00:02:32 +0200 | [diff] [blame] | 3719 | my ($label, $link, $pos) = splice(@actions,0,3); |
| 3720 | # insert |
Petr Baudis | d627f68 | 2008-10-02 16:36:52 +0200 | [diff] [blame] | 3721 | @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs; |
| 3722 | # munch munch |
Jakub Narebski | 2b11e05 | 2008-10-12 00:02:32 +0200 | [diff] [blame] | 3723 | $link =~ s/%([%nfhb])/$repl{$1}/g; |
Petr Baudis | d627f68 | 2008-10-02 16:36:52 +0200 | [diff] [blame] | 3724 | $arg{$label}{'_href'} = $link; |
| 3725 | } |
| 3726 | |
Jakub Narebski | b18f9bf | 2006-07-30 14:59:57 +0200 | [diff] [blame] | 3727 | print "<div class=\"page_nav\">\n" . |
| 3728 | (join " | ", |
Martin Waitz | 1c2a4f5 | 2006-08-16 00:24:30 +0200 | [diff] [blame] | 3729 | map { $_ eq $current ? |
Petr Baudis | d627f68 | 2008-10-02 16:36:52 +0200 | [diff] [blame] | 3730 | $_ : $cgi->a({-href => ($arg{$_}{_href} ? $arg{$_}{_href} : href(%{$arg{$_}}))}, "$_") |
Martin Waitz | 1c2a4f5 | 2006-08-16 00:24:30 +0200 | [diff] [blame] | 3731 | } @navs); |
Jakub Narebski | 898a893 | 2006-07-30 16:14:43 +0200 | [diff] [blame] | 3732 | print "<br/>\n$extra<br/>\n" . |
Jakub Narebski | b18f9bf | 2006-07-30 14:59:57 +0200 | [diff] [blame] | 3733 | "</div>\n"; |
| 3734 | } |
| 3735 | |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 3736 | sub format_paging_nav { |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 3737 | my ($action, $page, $has_next_link) = @_; |
Jakub Narebski | 43ffc06 | 2006-07-30 17:49:00 +0200 | [diff] [blame] | 3738 | my $paging_nav; |
| 3739 | |
| 3740 | |
Jakub Narebski | 43ffc06 | 2006-07-30 17:49:00 +0200 | [diff] [blame] | 3741 | if ($page > 0) { |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 3742 | $paging_nav .= |
| 3743 | $cgi->a({-href => href(-replay=>1, page=>undef)}, "first") . |
| 3744 | " ⋅ " . |
Jakub Narebski | 7afd77b | 2007-11-01 13:06:28 +0100 | [diff] [blame] | 3745 | $cgi->a({-href => href(-replay=>1, page=>$page-1), |
Jakub Narebski | 26298b5 | 2006-08-10 12:38:47 +0200 | [diff] [blame] | 3746 | -accesskey => "p", -title => "Alt-p"}, "prev"); |
Jakub Narebski | 43ffc06 | 2006-07-30 17:49:00 +0200 | [diff] [blame] | 3747 | } else { |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 3748 | $paging_nav .= "first ⋅ prev"; |
Jakub Narebski | 43ffc06 | 2006-07-30 17:49:00 +0200 | [diff] [blame] | 3749 | } |
| 3750 | |
Lea Wiemann | 1f684dc | 2008-05-28 01:25:42 +0200 | [diff] [blame] | 3751 | if ($has_next_link) { |
Jakub Narebski | 43ffc06 | 2006-07-30 17:49:00 +0200 | [diff] [blame] | 3752 | $paging_nav .= " ⋅ " . |
Jakub Narebski | 7afd77b | 2007-11-01 13:06:28 +0100 | [diff] [blame] | 3753 | $cgi->a({-href => href(-replay=>1, page=>$page+1), |
Jakub Narebski | 26298b5 | 2006-08-10 12:38:47 +0200 | [diff] [blame] | 3754 | -accesskey => "n", -title => "Alt-n"}, "next"); |
Jakub Narebski | 43ffc06 | 2006-07-30 17:49:00 +0200 | [diff] [blame] | 3755 | } else { |
| 3756 | $paging_nav .= " ⋅ next"; |
| 3757 | } |
| 3758 | |
| 3759 | return $paging_nav; |
| 3760 | } |
| 3761 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3762 | ## ...................................................................... |
| 3763 | ## functions printing or outputting HTML: div |
Kay Sievers | 42f7eb9 | 2005-08-07 20:21:46 +0200 | [diff] [blame] | 3764 | |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 3765 | sub git_print_header_div { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3766 | my ($action, $title, $hash, $hash_base) = @_; |
Martin Waitz | 1c2a4f5 | 2006-08-16 00:24:30 +0200 | [diff] [blame] | 3767 | my %args = (); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3768 | |
Jakub Narebski | 3be8e72 | 2007-04-01 22:22:21 +0200 | [diff] [blame] | 3769 | $args{'action'} = $action; |
| 3770 | $args{'hash'} = $hash if $hash; |
| 3771 | $args{'hash_base'} = $hash_base if $hash_base; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3772 | |
| 3773 | print "<div class=\"header\">\n" . |
Martin Waitz | 1c2a4f5 | 2006-08-16 00:24:30 +0200 | [diff] [blame] | 3774 | $cgi->a({-href => href(%args), -class => "title"}, |
| 3775 | $title ? $title : $action) . |
| 3776 | "\n</div>\n"; |
Kay Sievers | 42f7eb9 | 2005-08-07 20:21:46 +0200 | [diff] [blame] | 3777 | } |
| 3778 | |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 3779 | sub print_local_time { |
John 'Warthog9' Hawley | 0cf207f | 2010-01-30 23:30:42 +0100 | [diff] [blame] | 3780 | print format_local_time(@_); |
| 3781 | } |
| 3782 | |
| 3783 | sub format_local_time { |
| 3784 | my $localtime = ''; |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 3785 | my %date = @_; |
| 3786 | if ($date{'hour_local'} < 6) { |
John 'Warthog9' Hawley | 0cf207f | 2010-01-30 23:30:42 +0100 | [diff] [blame] | 3787 | $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)", |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 3788 | $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'}); |
Jakub Narebski | a44465c | 2006-08-28 23:17:31 +0200 | [diff] [blame] | 3789 | } else { |
John 'Warthog9' Hawley | 0cf207f | 2010-01-30 23:30:42 +0100 | [diff] [blame] | 3790 | $localtime .= sprintf(" (%02d:%02d %s)", |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 3791 | $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'}); |
Jakub Narebski | a44465c | 2006-08-28 23:17:31 +0200 | [diff] [blame] | 3792 | } |
John 'Warthog9' Hawley | 0cf207f | 2010-01-30 23:30:42 +0100 | [diff] [blame] | 3793 | |
| 3794 | return $localtime; |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 3795 | } |
| 3796 | |
| 3797 | # Outputs the author name and date in long form |
| 3798 | sub git_print_authorship { |
| 3799 | my $co = shift; |
| 3800 | my %opts = @_; |
| 3801 | my $tag = $opts{-tag} || 'div'; |
Stephen Boyd | e133d65 | 2009-10-15 21:14:59 -0700 | [diff] [blame] | 3802 | my $author = $co->{'author_name'}; |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 3803 | |
| 3804 | my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'}); |
| 3805 | print "<$tag class=\"author_date\">" . |
Stephen Boyd | e133d65 | 2009-10-15 21:14:59 -0700 | [diff] [blame] | 3806 | format_search_author($author, "author", esc_html($author)) . |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 3807 | " [$ad{'rfc2822'}"; |
| 3808 | print_local_time(%ad) if ($opts{-localtime}); |
Giuseppe Bilotta | e9fdd74 | 2009-06-30 00:00:51 +0200 | [diff] [blame] | 3809 | print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1) |
| 3810 | . "</$tag>\n"; |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | # Outputs table rows containing the full author or committer information, |
Ralf Wildenhues | 22e5e58 | 2010-08-22 13:12:12 +0200 | [diff] [blame] | 3814 | # in the format expected for 'commit' view (& similar). |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 3815 | # Parameters are a commit hash reference, followed by the list of people |
Ralf Wildenhues | 22e5e58 | 2010-08-22 13:12:12 +0200 | [diff] [blame] | 3816 | # to output information for. If the list is empty it defaults to both |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 3817 | # author and committer. |
| 3818 | sub git_print_authorship_rows { |
| 3819 | my $co = shift; |
| 3820 | # too bad we can't use @people = @_ || ('author', 'committer') |
| 3821 | my @people = @_; |
| 3822 | @people = ('author', 'committer') unless @people; |
| 3823 | foreach my $who (@people) { |
| 3824 | my %wd = parse_date($co->{"${who}_epoch"}, $co->{"${who}_tz"}); |
Stephen Boyd | e133d65 | 2009-10-15 21:14:59 -0700 | [diff] [blame] | 3825 | print "<tr><td>$who</td><td>" . |
| 3826 | format_search_author($co->{"${who}_name"}, $who, |
| 3827 | esc_html($co->{"${who}_name"})) . " " . |
| 3828 | format_search_author($co->{"${who}_email"}, $who, |
| 3829 | esc_html("<" . $co->{"${who}_email"} . ">")) . |
| 3830 | "</td><td rowspan=\"2\">" . |
Giuseppe Bilotta | e9fdd74 | 2009-06-30 00:00:51 +0200 | [diff] [blame] | 3831 | git_get_avatar($co->{"${who}_email"}, -size => 'double') . |
| 3832 | "</td></tr>\n" . |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 3833 | "<tr>" . |
| 3834 | "<td></td><td> $wd{'rfc2822'}"; |
| 3835 | print_local_time(%wd); |
| 3836 | print "</td>" . |
| 3837 | "</tr>\n"; |
| 3838 | } |
Jakub Narebski | 6fd92a2 | 2006-08-28 14:48:12 +0200 | [diff] [blame] | 3839 | } |
| 3840 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 3841 | sub git_print_page_path { |
| 3842 | my $name = shift; |
| 3843 | my $type = shift; |
Luben Tuikov | 59fb1c9 | 2006-08-17 10:39:29 -0700 | [diff] [blame] | 3844 | my $hb = shift; |
Junio C Hamano | df2c37a | 2006-01-09 13:13:39 +0100 | [diff] [blame] | 3845 | |
Jakub Narebski | 4df118e | 2006-10-21 17:53:55 +0200 | [diff] [blame] | 3846 | |
| 3847 | print "<div class=\"page_path\">"; |
| 3848 | print $cgi->a({-href => href(action=>"tree", hash_base=>$hb), |
Martin Koegler | 00f429a | 2007-06-03 17:42:44 +0200 | [diff] [blame] | 3849 | -title => 'tree root'}, to_utf8("[$project]")); |
Jakub Narebski | 4df118e | 2006-10-21 17:53:55 +0200 | [diff] [blame] | 3850 | print " / "; |
| 3851 | if (defined $name) { |
Jakub Narebski | 762c720 | 2006-09-04 18:17:58 +0200 | [diff] [blame] | 3852 | my @dirname = split '/', $name; |
| 3853 | my $basename = pop @dirname; |
| 3854 | my $fullname = ''; |
| 3855 | |
Jakub Narebski | 762c720 | 2006-09-04 18:17:58 +0200 | [diff] [blame] | 3856 | foreach my $dir (@dirname) { |
Petr Baudis | 16fdb48 | 2006-09-21 02:05:50 +0200 | [diff] [blame] | 3857 | $fullname .= ($fullname ? '/' : '') . $dir; |
Jakub Narebski | 762c720 | 2006-09-04 18:17:58 +0200 | [diff] [blame] | 3858 | print $cgi->a({-href => href(action=>"tree", file_name=>$fullname, |
| 3859 | hash_base=>$hb), |
Jakub Narebski | edc04e9 | 2007-03-07 02:21:25 +0100 | [diff] [blame] | 3860 | -title => $fullname}, esc_path($dir)); |
Petr Baudis | 26d0a97 | 2006-09-23 01:00:12 +0200 | [diff] [blame] | 3861 | print " / "; |
Jakub Narebski | 762c720 | 2006-09-04 18:17:58 +0200 | [diff] [blame] | 3862 | } |
| 3863 | if (defined $type && $type eq 'blob') { |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 3864 | print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name, |
Jakub Narebski | 762c720 | 2006-09-04 18:17:58 +0200 | [diff] [blame] | 3865 | hash_base=>$hb), |
Jakub Narebski | edc04e9 | 2007-03-07 02:21:25 +0100 | [diff] [blame] | 3866 | -title => $name}, esc_path($basename)); |
Jakub Narebski | 762c720 | 2006-09-04 18:17:58 +0200 | [diff] [blame] | 3867 | } elsif (defined $type && $type eq 'tree') { |
| 3868 | print $cgi->a({-href => href(action=>"tree", file_name=>$file_name, |
| 3869 | hash_base=>$hb), |
Jakub Narebski | edc04e9 | 2007-03-07 02:21:25 +0100 | [diff] [blame] | 3870 | -title => $name}, esc_path($basename)); |
Jakub Narebski | 4df118e | 2006-10-21 17:53:55 +0200 | [diff] [blame] | 3871 | print " / "; |
Luben Tuikov | 59fb1c9 | 2006-08-17 10:39:29 -0700 | [diff] [blame] | 3872 | } else { |
Jakub Narebski | 403d090 | 2006-11-08 11:48:56 +0100 | [diff] [blame] | 3873 | print esc_path($basename); |
Luben Tuikov | 59fb1c9 | 2006-08-17 10:39:29 -0700 | [diff] [blame] | 3874 | } |
Kay Sievers | 8ed23e1 | 2005-08-07 20:05:44 +0200 | [diff] [blame] | 3875 | } |
Jakub Narebski | 4df118e | 2006-10-21 17:53:55 +0200 | [diff] [blame] | 3876 | print "<br/></div>\n"; |
Kay Sievers | 4c02e3c | 2005-08-07 19:52:52 +0200 | [diff] [blame] | 3877 | } |
| 3878 | |
Jakub Narebski | 74fd872 | 2009-05-07 19:11:29 +0200 | [diff] [blame] | 3879 | sub git_print_log { |
Jakub Narebski | d16d093 | 2006-08-17 11:21:23 +0200 | [diff] [blame] | 3880 | my $log = shift; |
Jakub Narebski | b7f9253 | 2006-08-28 14:48:10 +0200 | [diff] [blame] | 3881 | my %opts = @_; |
Jakub Narebski | d16d093 | 2006-08-17 11:21:23 +0200 | [diff] [blame] | 3882 | |
Jakub Narebski | b7f9253 | 2006-08-28 14:48:10 +0200 | [diff] [blame] | 3883 | if ($opts{'-remove_title'}) { |
| 3884 | # remove title, i.e. first line of log |
| 3885 | shift @$log; |
| 3886 | } |
Jakub Narebski | d16d093 | 2006-08-17 11:21:23 +0200 | [diff] [blame] | 3887 | # remove leading empty lines |
| 3888 | while (defined $log->[0] && $log->[0] eq "") { |
| 3889 | shift @$log; |
| 3890 | } |
| 3891 | |
| 3892 | # print log |
| 3893 | my $signoff = 0; |
| 3894 | my $empty = 0; |
| 3895 | foreach my $line (@$log) { |
Jakub Narebski | b7f9253 | 2006-08-28 14:48:10 +0200 | [diff] [blame] | 3896 | if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) { |
| 3897 | $signoff = 1; |
Jakub Narebski | fba20b4 | 2006-08-28 14:48:13 +0200 | [diff] [blame] | 3898 | $empty = 0; |
Jakub Narebski | b7f9253 | 2006-08-28 14:48:10 +0200 | [diff] [blame] | 3899 | if (! $opts{'-remove_signoff'}) { |
| 3900 | print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n"; |
| 3901 | next; |
| 3902 | } else { |
| 3903 | # remove signoff lines |
| 3904 | next; |
| 3905 | } |
| 3906 | } else { |
| 3907 | $signoff = 0; |
| 3908 | } |
| 3909 | |
Jakub Narebski | d16d093 | 2006-08-17 11:21:23 +0200 | [diff] [blame] | 3910 | # print only one empty line |
| 3911 | # do not print empty line after signoff |
| 3912 | if ($line eq "") { |
| 3913 | next if ($empty || $signoff); |
| 3914 | $empty = 1; |
| 3915 | } else { |
| 3916 | $empty = 0; |
| 3917 | } |
Jakub Narebski | b7f9253 | 2006-08-28 14:48:10 +0200 | [diff] [blame] | 3918 | |
| 3919 | print format_log_line_html($line) . "<br/>\n"; |
| 3920 | } |
| 3921 | |
| 3922 | if ($opts{'-final_empty_line'}) { |
| 3923 | # end with single empty line |
| 3924 | print "<br/>\n" unless $empty; |
Jakub Narebski | d16d093 | 2006-08-17 11:21:23 +0200 | [diff] [blame] | 3925 | } |
| 3926 | } |
| 3927 | |
Jakub Narebski | e33fba4 | 2006-12-10 13:25:46 +0100 | [diff] [blame] | 3928 | # return link target (what link points to) |
| 3929 | sub git_get_link_target { |
| 3930 | my $hash = shift; |
| 3931 | my $link_target; |
| 3932 | |
| 3933 | # read link |
| 3934 | open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash |
| 3935 | or return; |
| 3936 | { |
Jakub Narebski | 34122b5 | 2009-05-11 03:29:40 +0200 | [diff] [blame] | 3937 | local $/ = undef; |
Jakub Narebski | e33fba4 | 2006-12-10 13:25:46 +0100 | [diff] [blame] | 3938 | $link_target = <$fd>; |
| 3939 | } |
| 3940 | close $fd |
| 3941 | or return; |
| 3942 | |
| 3943 | return $link_target; |
| 3944 | } |
| 3945 | |
Jakub Narebski | 3bf9d57 | 2006-12-10 13:25:48 +0100 | [diff] [blame] | 3946 | # given link target, and the directory (basedir) the link is in, |
| 3947 | # return target of link relative to top directory (top tree); |
| 3948 | # return undef if it is not possible (including absolute links). |
| 3949 | sub normalize_link_target { |
Jakub Narebski | 15c54fe | 2009-05-11 19:45:11 +0200 | [diff] [blame] | 3950 | my ($link_target, $basedir) = @_; |
Jakub Narebski | 3bf9d57 | 2006-12-10 13:25:48 +0100 | [diff] [blame] | 3951 | |
| 3952 | # absolute symlinks (beginning with '/') cannot be normalized |
| 3953 | return if (substr($link_target, 0, 1) eq '/'); |
| 3954 | |
| 3955 | # normalize link target to path from top (root) tree (dir) |
| 3956 | my $path; |
| 3957 | if ($basedir) { |
| 3958 | $path = $basedir . '/' . $link_target; |
| 3959 | } else { |
| 3960 | # we are in top (root) tree (dir) |
| 3961 | $path = $link_target; |
| 3962 | } |
| 3963 | |
| 3964 | # remove //, /./, and /../ |
| 3965 | my @path_parts; |
| 3966 | foreach my $part (split('/', $path)) { |
| 3967 | # discard '.' and '' |
| 3968 | next if (!$part || $part eq '.'); |
| 3969 | # handle '..' |
| 3970 | if ($part eq '..') { |
| 3971 | if (@path_parts) { |
| 3972 | pop @path_parts; |
| 3973 | } else { |
| 3974 | # link leads outside repository (outside top dir) |
| 3975 | return; |
| 3976 | } |
| 3977 | } else { |
| 3978 | push @path_parts, $part; |
| 3979 | } |
| 3980 | } |
| 3981 | $path = join('/', @path_parts); |
| 3982 | |
| 3983 | return $path; |
| 3984 | } |
Jakub Narebski | e33fba4 | 2006-12-10 13:25:46 +0100 | [diff] [blame] | 3985 | |
Jakub Narebski | fa70200 | 2006-08-31 00:35:07 +0200 | [diff] [blame] | 3986 | # print tree entry (row of git_tree), but without encompassing <tr> element |
| 3987 | sub git_print_tree_entry { |
| 3988 | my ($t, $basedir, $hash_base, $have_blame) = @_; |
| 3989 | |
| 3990 | my %base_key = (); |
Jakub Narebski | e33fba4 | 2006-12-10 13:25:46 +0100 | [diff] [blame] | 3991 | $base_key{'hash_base'} = $hash_base if defined $hash_base; |
Jakub Narebski | fa70200 | 2006-08-31 00:35:07 +0200 | [diff] [blame] | 3992 | |
Luben Tuikov | 4de741b | 2006-09-25 22:38:16 -0700 | [diff] [blame] | 3993 | # The format of a table row is: mode list link. Where mode is |
| 3994 | # the mode of the entry, list is the name of the entry, an href, |
| 3995 | # and link is the action links of the entry. |
| 3996 | |
Jakub Narebski | fa70200 | 2006-08-31 00:35:07 +0200 | [diff] [blame] | 3997 | print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n"; |
Jakub Narebski | e4b48ea | 2009-09-07 14:40:00 +0200 | [diff] [blame] | 3998 | if (exists $t->{'size'}) { |
| 3999 | print "<td class=\"size\">$t->{'size'}</td>\n"; |
| 4000 | } |
Jakub Narebski | fa70200 | 2006-08-31 00:35:07 +0200 | [diff] [blame] | 4001 | if ($t->{'type'} eq "blob") { |
| 4002 | print "<td class=\"list\">" . |
Luben Tuikov | 4de741b | 2006-09-25 22:38:16 -0700 | [diff] [blame] | 4003 | $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'}, |
Jakub Narebski | e7fb022 | 2006-10-21 17:52:19 +0200 | [diff] [blame] | 4004 | file_name=>"$basedir$t->{'name'}", %base_key), |
Jakub Narebski | e33fba4 | 2006-12-10 13:25:46 +0100 | [diff] [blame] | 4005 | -class => "list"}, esc_path($t->{'name'})); |
| 4006 | if (S_ISLNK(oct $t->{'mode'})) { |
| 4007 | my $link_target = git_get_link_target($t->{'hash'}); |
| 4008 | if ($link_target) { |
Jakub Narebski | 15c54fe | 2009-05-11 19:45:11 +0200 | [diff] [blame] | 4009 | my $norm_target = normalize_link_target($link_target, $basedir); |
Jakub Narebski | 3bf9d57 | 2006-12-10 13:25:48 +0100 | [diff] [blame] | 4010 | if (defined $norm_target) { |
| 4011 | print " -> " . |
| 4012 | $cgi->a({-href => href(action=>"object", hash_base=>$hash_base, |
| 4013 | file_name=>$norm_target), |
| 4014 | -title => $norm_target}, esc_path($link_target)); |
| 4015 | } else { |
| 4016 | print " -> " . esc_path($link_target); |
| 4017 | } |
Jakub Narebski | e33fba4 | 2006-12-10 13:25:46 +0100 | [diff] [blame] | 4018 | } |
| 4019 | } |
| 4020 | print "</td>\n"; |
Luben Tuikov | 4de741b | 2006-09-25 22:38:16 -0700 | [diff] [blame] | 4021 | print "<td class=\"link\">"; |
Petr Baudis | 4777b01 | 2006-10-24 05:36:10 +0200 | [diff] [blame] | 4022 | print $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'}, |
Jakub Narebski | e33fba4 | 2006-12-10 13:25:46 +0100 | [diff] [blame] | 4023 | file_name=>"$basedir$t->{'name'}", %base_key)}, |
| 4024 | "blob"); |
Jakub Narebski | fa70200 | 2006-08-31 00:35:07 +0200 | [diff] [blame] | 4025 | if ($have_blame) { |
Petr Baudis | 4777b01 | 2006-10-24 05:36:10 +0200 | [diff] [blame] | 4026 | print " | " . |
| 4027 | $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'}, |
Jakub Narebski | e33fba4 | 2006-12-10 13:25:46 +0100 | [diff] [blame] | 4028 | file_name=>"$basedir$t->{'name'}", %base_key)}, |
| 4029 | "blame"); |
Jakub Narebski | fa70200 | 2006-08-31 00:35:07 +0200 | [diff] [blame] | 4030 | } |
| 4031 | if (defined $hash_base) { |
Petr Baudis | 4777b01 | 2006-10-24 05:36:10 +0200 | [diff] [blame] | 4032 | print " | " . |
| 4033 | $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, |
Jakub Narebski | fa70200 | 2006-08-31 00:35:07 +0200 | [diff] [blame] | 4034 | hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")}, |
| 4035 | "history"); |
| 4036 | } |
| 4037 | print " | " . |
Luben Tuikov | 6f7ea5f | 2006-09-29 09:57:43 -0700 | [diff] [blame] | 4038 | $cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base, |
Jakub Narebski | e7fb022 | 2006-10-21 17:52:19 +0200 | [diff] [blame] | 4039 | file_name=>"$basedir$t->{'name'}")}, |
| 4040 | "raw"); |
Luben Tuikov | 4de741b | 2006-09-25 22:38:16 -0700 | [diff] [blame] | 4041 | print "</td>\n"; |
Jakub Narebski | fa70200 | 2006-08-31 00:35:07 +0200 | [diff] [blame] | 4042 | |
| 4043 | } elsif ($t->{'type'} eq "tree") { |
Luben Tuikov | 0fa105e | 2006-09-26 12:45:37 -0700 | [diff] [blame] | 4044 | print "<td class=\"list\">"; |
| 4045 | print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'}, |
Jakub Narebski | e4b48ea | 2009-09-07 14:40:00 +0200 | [diff] [blame] | 4046 | file_name=>"$basedir$t->{'name'}", |
| 4047 | %base_key)}, |
Jakub Narebski | 403d090 | 2006-11-08 11:48:56 +0100 | [diff] [blame] | 4048 | esc_path($t->{'name'})); |
Luben Tuikov | 0fa105e | 2006-09-26 12:45:37 -0700 | [diff] [blame] | 4049 | print "</td>\n"; |
| 4050 | print "<td class=\"link\">"; |
Petr Baudis | 4777b01 | 2006-10-24 05:36:10 +0200 | [diff] [blame] | 4051 | print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'}, |
Jakub Narebski | e4b48ea | 2009-09-07 14:40:00 +0200 | [diff] [blame] | 4052 | file_name=>"$basedir$t->{'name'}", |
| 4053 | %base_key)}, |
Jakub Narebski | e33fba4 | 2006-12-10 13:25:46 +0100 | [diff] [blame] | 4054 | "tree"); |
Jakub Narebski | fa70200 | 2006-08-31 00:35:07 +0200 | [diff] [blame] | 4055 | if (defined $hash_base) { |
Petr Baudis | 4777b01 | 2006-10-24 05:36:10 +0200 | [diff] [blame] | 4056 | print " | " . |
| 4057 | $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, |
Jakub Narebski | fa70200 | 2006-08-31 00:35:07 +0200 | [diff] [blame] | 4058 | file_name=>"$basedir$t->{'name'}")}, |
| 4059 | "history"); |
| 4060 | } |
| 4061 | print "</td>\n"; |
Jakub Narebski | 01ac1e3 | 2007-07-28 16:27:31 +0200 | [diff] [blame] | 4062 | } else { |
| 4063 | # unknown object: we can only present history for it |
| 4064 | # (this includes 'commit' object, i.e. submodule support) |
| 4065 | print "<td class=\"list\">" . |
| 4066 | esc_path($t->{'name'}) . |
| 4067 | "</td>\n"; |
| 4068 | print "<td class=\"link\">"; |
| 4069 | if (defined $hash_base) { |
| 4070 | print $cgi->a({-href => href(action=>"history", |
| 4071 | hash_base=>$hash_base, |
| 4072 | file_name=>"$basedir$t->{'name'}")}, |
| 4073 | "history"); |
| 4074 | } |
| 4075 | print "</td>\n"; |
Jakub Narebski | fa70200 | 2006-08-31 00:35:07 +0200 | [diff] [blame] | 4076 | } |
| 4077 | } |
| 4078 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 4079 | ## ...................................................................... |
| 4080 | ## functions printing large fragments of HTML |
Kay Sievers | ede5e10 | 2005-08-07 20:23:12 +0200 | [diff] [blame] | 4081 | |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4082 | # get pre-image filenames for merge (combined) diff |
Jakub Narebski | e72c0ea | 2007-05-07 01:10:05 +0200 | [diff] [blame] | 4083 | sub fill_from_file_info { |
| 4084 | my ($diff, @parents) = @_; |
| 4085 | |
| 4086 | $diff->{'from_file'} = [ ]; |
| 4087 | $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef; |
| 4088 | for (my $i = 0; $i < $diff->{'nparents'}; $i++) { |
| 4089 | if ($diff->{'status'}[$i] eq 'R' || |
| 4090 | $diff->{'status'}[$i] eq 'C') { |
| 4091 | $diff->{'from_file'}[$i] = |
| 4092 | git_get_path_by_hash($parents[$i], $diff->{'from_id'}[$i]); |
| 4093 | } |
| 4094 | } |
| 4095 | |
| 4096 | return $diff; |
| 4097 | } |
| 4098 | |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4099 | # is current raw difftree line of file deletion |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 4100 | sub is_deleted { |
| 4101 | my $diffinfo = shift; |
| 4102 | |
Jakub Narebski | 4ed4a34 | 2008-04-05 21:13:24 +0100 | [diff] [blame] | 4103 | return $diffinfo->{'to_id'} eq ('0' x 40); |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 4104 | } |
Jakub Narebski | e72c0ea | 2007-05-07 01:10:05 +0200 | [diff] [blame] | 4105 | |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4106 | # does patch correspond to [previous] difftree raw line |
| 4107 | # $diffinfo - hashref of parsed raw diff format |
| 4108 | # $patchinfo - hashref of parsed patch diff format |
| 4109 | # (the same keys as in $diffinfo) |
| 4110 | sub is_patch_split { |
| 4111 | my ($diffinfo, $patchinfo) = @_; |
| 4112 | |
| 4113 | return defined $diffinfo && defined $patchinfo |
Jakub Narebski | 9d30145 | 2007-11-01 12:38:08 +0100 | [diff] [blame] | 4114 | && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'}; |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4115 | } |
| 4116 | |
| 4117 | |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4118 | sub git_difftree_body { |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4119 | my ($difftree, $hash, @parents) = @_; |
| 4120 | my ($parent) = $parents[0]; |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 4121 | my $have_blame = gitweb_check_feature('blame'); |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4122 | print "<div class=\"list_head\">\n"; |
| 4123 | if ($#{$difftree} > 10) { |
| 4124 | print(($#{$difftree} + 1) . " files changed:\n"); |
| 4125 | } |
| 4126 | print "</div>\n"; |
| 4127 | |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4128 | print "<table class=\"" . |
| 4129 | (@parents > 1 ? "combined " : "") . |
| 4130 | "diff_tree\">\n"; |
Jakub Narebski | 47598d7 | 2007-06-08 13:24:56 +0200 | [diff] [blame] | 4131 | |
| 4132 | # header only for combined diff in 'commitdiff' view |
Jakub Narebski | 3ef408a | 2007-09-08 21:54:28 +0200 | [diff] [blame] | 4133 | my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff'; |
Jakub Narebski | 47598d7 | 2007-06-08 13:24:56 +0200 | [diff] [blame] | 4134 | if ($has_header) { |
| 4135 | # table header |
| 4136 | print "<thead><tr>\n" . |
| 4137 | "<th></th><th></th>\n"; # filename, patchN link |
| 4138 | for (my $i = 0; $i < @parents; $i++) { |
| 4139 | my $par = $parents[$i]; |
| 4140 | print "<th>" . |
| 4141 | $cgi->a({-href => href(action=>"commitdiff", |
| 4142 | hash=>$hash, hash_parent=>$par), |
| 4143 | -title => 'commitdiff to parent number ' . |
| 4144 | ($i+1) . ': ' . substr($par,0,7)}, |
| 4145 | $i+1) . |
| 4146 | " </th>\n"; |
| 4147 | } |
| 4148 | print "</tr></thead>\n<tbody>\n"; |
| 4149 | } |
| 4150 | |
Luben Tuikov | 6dd36ac | 2006-09-28 16:47:50 -0700 | [diff] [blame] | 4151 | my $alternate = 1; |
Jakub Narebski | b4657e7 | 2006-08-28 14:48:14 +0200 | [diff] [blame] | 4152 | my $patchno = 0; |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4153 | foreach my $line (@{$difftree}) { |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4154 | my $diff = parsed_difftree_line($line); |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4155 | |
| 4156 | if ($alternate) { |
| 4157 | print "<tr class=\"dark\">\n"; |
| 4158 | } else { |
| 4159 | print "<tr class=\"light\">\n"; |
| 4160 | } |
| 4161 | $alternate ^= 1; |
| 4162 | |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4163 | if (exists $diff->{'nparents'}) { # combined diff |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4164 | |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4165 | fill_from_file_info($diff, @parents) |
| 4166 | unless exists $diff->{'from_file'}; |
Jakub Narebski | e72c0ea | 2007-05-07 01:10:05 +0200 | [diff] [blame] | 4167 | |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 4168 | if (!is_deleted($diff)) { |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4169 | # file exists in the result (child) commit |
| 4170 | print "<td>" . |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4171 | $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'}, |
| 4172 | file_name=>$diff->{'to_file'}, |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4173 | hash_base=>$hash), |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4174 | -class => "list"}, esc_path($diff->{'to_file'})) . |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4175 | "</td>\n"; |
| 4176 | } else { |
| 4177 | print "<td>" . |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4178 | esc_path($diff->{'to_file'}) . |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4179 | "</td>\n"; |
| 4180 | } |
| 4181 | |
| 4182 | if ($action eq 'commitdiff') { |
| 4183 | # link to patch |
| 4184 | $patchno++; |
| 4185 | print "<td class=\"link\">" . |
| 4186 | $cgi->a({-href => "#patch$patchno"}, "patch") . |
| 4187 | " | " . |
| 4188 | "</td>\n"; |
| 4189 | } |
| 4190 | |
| 4191 | my $has_history = 0; |
| 4192 | my $not_deleted = 0; |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4193 | for (my $i = 0; $i < $diff->{'nparents'}; $i++) { |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4194 | my $hash_parent = $parents[$i]; |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4195 | my $from_hash = $diff->{'from_id'}[$i]; |
| 4196 | my $from_path = $diff->{'from_file'}[$i]; |
| 4197 | my $status = $diff->{'status'}[$i]; |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4198 | |
| 4199 | $has_history ||= ($status ne 'A'); |
| 4200 | $not_deleted ||= ($status ne 'D'); |
| 4201 | |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4202 | if ($status eq 'A') { |
| 4203 | print "<td class=\"link\" align=\"right\"> | </td>\n"; |
| 4204 | } elsif ($status eq 'D') { |
| 4205 | print "<td class=\"link\">" . |
| 4206 | $cgi->a({-href => href(action=>"blob", |
| 4207 | hash_base=>$hash, |
| 4208 | hash=>$from_hash, |
| 4209 | file_name=>$from_path)}, |
| 4210 | "blob" . ($i+1)) . |
| 4211 | " | </td>\n"; |
| 4212 | } else { |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4213 | if ($diff->{'to_id'} eq $from_hash) { |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4214 | print "<td class=\"link nochange\">"; |
| 4215 | } else { |
| 4216 | print "<td class=\"link\">"; |
| 4217 | } |
| 4218 | print $cgi->a({-href => href(action=>"blobdiff", |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4219 | hash=>$diff->{'to_id'}, |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4220 | hash_parent=>$from_hash, |
| 4221 | hash_base=>$hash, |
| 4222 | hash_parent_base=>$hash_parent, |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4223 | file_name=>$diff->{'to_file'}, |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4224 | file_parent=>$from_path)}, |
| 4225 | "diff" . ($i+1)) . |
| 4226 | " | </td>\n"; |
| 4227 | } |
| 4228 | } |
| 4229 | |
| 4230 | print "<td class=\"link\">"; |
| 4231 | if ($not_deleted) { |
| 4232 | print $cgi->a({-href => href(action=>"blob", |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4233 | hash=>$diff->{'to_id'}, |
| 4234 | file_name=>$diff->{'to_file'}, |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4235 | hash_base=>$hash)}, |
| 4236 | "blob"); |
| 4237 | print " | " if ($has_history); |
| 4238 | } |
| 4239 | if ($has_history) { |
| 4240 | print $cgi->a({-href => href(action=>"history", |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4241 | file_name=>$diff->{'to_file'}, |
Jakub Narebski | ed224de | 2007-05-07 01:10:04 +0200 | [diff] [blame] | 4242 | hash_base=>$hash)}, |
| 4243 | "history"); |
| 4244 | } |
| 4245 | print "</td>\n"; |
| 4246 | |
| 4247 | print "</tr>\n"; |
| 4248 | next; # instead of 'else' clause, to avoid extra indent |
| 4249 | } |
| 4250 | # else ordinary diff |
| 4251 | |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 4252 | my ($to_mode_oct, $to_mode_str, $to_file_type); |
| 4253 | my ($from_mode_oct, $from_mode_str, $from_file_type); |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4254 | if ($diff->{'to_mode'} ne ('0' x 6)) { |
| 4255 | $to_mode_oct = oct $diff->{'to_mode'}; |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 4256 | if (S_ISREG($to_mode_oct)) { # only for regular file |
| 4257 | $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4258 | } |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4259 | $to_file_type = file_type($diff->{'to_mode'}); |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 4260 | } |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4261 | if ($diff->{'from_mode'} ne ('0' x 6)) { |
| 4262 | $from_mode_oct = oct $diff->{'from_mode'}; |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 4263 | if (S_ISREG($to_mode_oct)) { # only for regular file |
| 4264 | $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits |
| 4265 | } |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4266 | $from_file_type = file_type($diff->{'from_mode'}); |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 4267 | } |
| 4268 | |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4269 | if ($diff->{'status'} eq "A") { # created |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 4270 | my $mode_chng = "<span class=\"file_status new\">[new $to_file_type"; |
| 4271 | $mode_chng .= " with mode: $to_mode_str" if $to_mode_str; |
| 4272 | $mode_chng .= "]</span>"; |
Luben Tuikov | 499faed | 2006-09-27 17:23:25 -0700 | [diff] [blame] | 4273 | print "<td>"; |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4274 | print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'}, |
| 4275 | hash_base=>$hash, file_name=>$diff->{'file'}), |
| 4276 | -class => "list"}, esc_path($diff->{'file'})); |
Luben Tuikov | 499faed | 2006-09-27 17:23:25 -0700 | [diff] [blame] | 4277 | print "</td>\n"; |
| 4278 | print "<td>$mode_chng</td>\n"; |
| 4279 | print "<td class=\"link\">"; |
Jakub Narebski | 72dbafa | 2006-09-04 18:19:58 +0200 | [diff] [blame] | 4280 | if ($action eq 'commitdiff') { |
Jakub Narebski | b4657e7 | 2006-08-28 14:48:14 +0200 | [diff] [blame] | 4281 | # link to patch |
| 4282 | $patchno++; |
Luben Tuikov | 499faed | 2006-09-27 17:23:25 -0700 | [diff] [blame] | 4283 | print $cgi->a({-href => "#patch$patchno"}, "patch"); |
Jakub Narebski | 897d1d2 | 2006-11-19 22:51:39 +0100 | [diff] [blame] | 4284 | print " | "; |
Jakub Narebski | b4657e7 | 2006-08-28 14:48:14 +0200 | [diff] [blame] | 4285 | } |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4286 | print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'}, |
| 4287 | hash_base=>$hash, file_name=>$diff->{'file'})}, |
Jakub Narebski | 3faa541 | 2007-01-08 02:10:42 +0100 | [diff] [blame] | 4288 | "blob"); |
Jakub Narebski | b4657e7 | 2006-08-28 14:48:14 +0200 | [diff] [blame] | 4289 | print "</td>\n"; |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4290 | |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4291 | } elsif ($diff->{'status'} eq "D") { # deleted |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 4292 | my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>"; |
Luben Tuikov | 499faed | 2006-09-27 17:23:25 -0700 | [diff] [blame] | 4293 | print "<td>"; |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4294 | print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'}, |
| 4295 | hash_base=>$parent, file_name=>$diff->{'file'}), |
| 4296 | -class => "list"}, esc_path($diff->{'file'})); |
Luben Tuikov | 499faed | 2006-09-27 17:23:25 -0700 | [diff] [blame] | 4297 | print "</td>\n"; |
| 4298 | print "<td>$mode_chng</td>\n"; |
| 4299 | print "<td class=\"link\">"; |
Jakub Narebski | 72dbafa | 2006-09-04 18:19:58 +0200 | [diff] [blame] | 4300 | if ($action eq 'commitdiff') { |
Jakub Narebski | b4657e7 | 2006-08-28 14:48:14 +0200 | [diff] [blame] | 4301 | # link to patch |
| 4302 | $patchno++; |
Luben Tuikov | 499faed | 2006-09-27 17:23:25 -0700 | [diff] [blame] | 4303 | print $cgi->a({-href => "#patch$patchno"}, "patch"); |
| 4304 | print " | "; |
Jakub Narebski | b4657e7 | 2006-08-28 14:48:14 +0200 | [diff] [blame] | 4305 | } |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4306 | print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'}, |
| 4307 | hash_base=>$parent, file_name=>$diff->{'file'})}, |
Jakub Narebski | 897d1d2 | 2006-11-19 22:51:39 +0100 | [diff] [blame] | 4308 | "blob") . " | "; |
Junio C Hamano | 2b2a8c7 | 2006-11-08 12:22:04 -0800 | [diff] [blame] | 4309 | if ($have_blame) { |
Jakub Narebski | 897d1d2 | 2006-11-19 22:51:39 +0100 | [diff] [blame] | 4310 | print $cgi->a({-href => href(action=>"blame", hash_base=>$parent, |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4311 | file_name=>$diff->{'file'})}, |
Jakub Narebski | 897d1d2 | 2006-11-19 22:51:39 +0100 | [diff] [blame] | 4312 | "blame") . " | "; |
Junio C Hamano | 2b2a8c7 | 2006-11-08 12:22:04 -0800 | [diff] [blame] | 4313 | } |
Jakub Narebski | b4657e7 | 2006-08-28 14:48:14 +0200 | [diff] [blame] | 4314 | print $cgi->a({-href => href(action=>"history", hash_base=>$parent, |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4315 | file_name=>$diff->{'file'})}, |
Jakub Narebski | e7fb022 | 2006-10-21 17:52:19 +0200 | [diff] [blame] | 4316 | "history"); |
Luben Tuikov | 499faed | 2006-09-27 17:23:25 -0700 | [diff] [blame] | 4317 | print "</td>\n"; |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4318 | |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4319 | } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4320 | my $mode_chnge = ""; |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4321 | if ($diff->{'from_mode'} != $diff->{'to_mode'}) { |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 4322 | $mode_chnge = "<span class=\"file_status mode_chnge\">[changed"; |
Jakub Narebski | 6e72cf4 | 2007-01-03 20:47:24 +0100 | [diff] [blame] | 4323 | if ($from_file_type ne $to_file_type) { |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 4324 | $mode_chnge .= " from $from_file_type to $to_file_type"; |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4325 | } |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 4326 | if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) { |
| 4327 | if ($from_mode_str && $to_mode_str) { |
| 4328 | $mode_chnge .= " mode: $from_mode_str->$to_mode_str"; |
| 4329 | } elsif ($to_mode_str) { |
| 4330 | $mode_chnge .= " mode: $to_mode_str"; |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4331 | } |
| 4332 | } |
| 4333 | $mode_chnge .= "]</span>\n"; |
| 4334 | } |
| 4335 | print "<td>"; |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4336 | print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'}, |
| 4337 | hash_base=>$hash, file_name=>$diff->{'file'}), |
| 4338 | -class => "list"}, esc_path($diff->{'file'})); |
Luben Tuikov | 499faed | 2006-09-27 17:23:25 -0700 | [diff] [blame] | 4339 | print "</td>\n"; |
| 4340 | print "<td>$mode_chnge</td>\n"; |
| 4341 | print "<td class=\"link\">"; |
Jakub Narebski | 241cc59 | 2006-10-31 17:36:27 +0100 | [diff] [blame] | 4342 | if ($action eq 'commitdiff') { |
| 4343 | # link to patch |
| 4344 | $patchno++; |
| 4345 | print $cgi->a({-href => "#patch$patchno"}, "patch") . |
| 4346 | " | "; |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4347 | } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) { |
Jakub Narebski | 241cc59 | 2006-10-31 17:36:27 +0100 | [diff] [blame] | 4348 | # "commit" view and modified file (not onlu mode changed) |
| 4349 | print $cgi->a({-href => href(action=>"blobdiff", |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4350 | hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'}, |
Jakub Narebski | 241cc59 | 2006-10-31 17:36:27 +0100 | [diff] [blame] | 4351 | hash_base=>$hash, hash_parent_base=>$parent, |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4352 | file_name=>$diff->{'file'})}, |
Jakub Narebski | 241cc59 | 2006-10-31 17:36:27 +0100 | [diff] [blame] | 4353 | "diff") . |
| 4354 | " | "; |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4355 | } |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4356 | print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'}, |
| 4357 | hash_base=>$hash, file_name=>$diff->{'file'})}, |
Jakub Narebski | 897d1d2 | 2006-11-19 22:51:39 +0100 | [diff] [blame] | 4358 | "blob") . " | "; |
Junio C Hamano | 2b2a8c7 | 2006-11-08 12:22:04 -0800 | [diff] [blame] | 4359 | if ($have_blame) { |
Jakub Narebski | 897d1d2 | 2006-11-19 22:51:39 +0100 | [diff] [blame] | 4360 | print $cgi->a({-href => href(action=>"blame", hash_base=>$hash, |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4361 | file_name=>$diff->{'file'})}, |
Jakub Narebski | 897d1d2 | 2006-11-19 22:51:39 +0100 | [diff] [blame] | 4362 | "blame") . " | "; |
Junio C Hamano | 2b2a8c7 | 2006-11-08 12:22:04 -0800 | [diff] [blame] | 4363 | } |
Luben Tuikov | eb51ec9 | 2006-09-27 17:24:49 -0700 | [diff] [blame] | 4364 | print $cgi->a({-href => href(action=>"history", hash_base=>$hash, |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4365 | file_name=>$diff->{'file'})}, |
Jakub Narebski | e7fb022 | 2006-10-21 17:52:19 +0200 | [diff] [blame] | 4366 | "history"); |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4367 | print "</td>\n"; |
| 4368 | |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4369 | } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 4370 | my %status_name = ('R' => 'moved', 'C' => 'copied'); |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4371 | my $nstatus = $status_name{$diff->{'status'}}; |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4372 | my $mode_chng = ""; |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4373 | if ($diff->{'from_mode'} != $diff->{'to_mode'}) { |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 4374 | # mode also for directories, so we cannot use $to_mode_str |
| 4375 | $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777); |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4376 | } |
| 4377 | print "<td>" . |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 4378 | $cgi->a({-href => href(action=>"blob", hash_base=>$hash, |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4379 | hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}), |
| 4380 | -class => "list"}, esc_path($diff->{'to_file'})) . "</td>\n" . |
Jakub Narebski | e8e41a9 | 2006-08-21 23:08:52 +0200 | [diff] [blame] | 4381 | "<td><span class=\"file_status $nstatus\">[$nstatus from " . |
| 4382 | $cgi->a({-href => href(action=>"blob", hash_base=>$parent, |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4383 | hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}), |
| 4384 | -class => "list"}, esc_path($diff->{'from_file'})) . |
| 4385 | " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" . |
Luben Tuikov | 499faed | 2006-09-27 17:23:25 -0700 | [diff] [blame] | 4386 | "<td class=\"link\">"; |
Jakub Narebski | 241cc59 | 2006-10-31 17:36:27 +0100 | [diff] [blame] | 4387 | if ($action eq 'commitdiff') { |
| 4388 | # link to patch |
| 4389 | $patchno++; |
| 4390 | print $cgi->a({-href => "#patch$patchno"}, "patch") . |
| 4391 | " | "; |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4392 | } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) { |
Jakub Narebski | 241cc59 | 2006-10-31 17:36:27 +0100 | [diff] [blame] | 4393 | # "commit" view and modified file (not only pure rename or copy) |
| 4394 | print $cgi->a({-href => href(action=>"blobdiff", |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4395 | hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'}, |
Jakub Narebski | 241cc59 | 2006-10-31 17:36:27 +0100 | [diff] [blame] | 4396 | hash_base=>$hash, hash_parent_base=>$parent, |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4397 | file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})}, |
Jakub Narebski | 241cc59 | 2006-10-31 17:36:27 +0100 | [diff] [blame] | 4398 | "diff") . |
| 4399 | " | "; |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4400 | } |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4401 | print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'}, |
| 4402 | hash_base=>$parent, file_name=>$diff->{'to_file'})}, |
Jakub Narebski | 897d1d2 | 2006-11-19 22:51:39 +0100 | [diff] [blame] | 4403 | "blob") . " | "; |
Junio C Hamano | 2b2a8c7 | 2006-11-08 12:22:04 -0800 | [diff] [blame] | 4404 | if ($have_blame) { |
Jakub Narebski | 897d1d2 | 2006-11-19 22:51:39 +0100 | [diff] [blame] | 4405 | print $cgi->a({-href => href(action=>"blame", hash_base=>$hash, |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4406 | file_name=>$diff->{'to_file'})}, |
Jakub Narebski | 897d1d2 | 2006-11-19 22:51:39 +0100 | [diff] [blame] | 4407 | "blame") . " | "; |
Junio C Hamano | 2b2a8c7 | 2006-11-08 12:22:04 -0800 | [diff] [blame] | 4408 | } |
Jakub Narebski | 897d1d2 | 2006-11-19 22:51:39 +0100 | [diff] [blame] | 4409 | print $cgi->a({-href => href(action=>"history", hash_base=>$hash, |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 4410 | file_name=>$diff->{'to_file'})}, |
Jakub Narebski | e7fb022 | 2006-10-21 17:52:19 +0200 | [diff] [blame] | 4411 | "history"); |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4412 | print "</td>\n"; |
| 4413 | |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4414 | } # we should not encounter Unmerged (U) or Unknown (X) status |
| 4415 | print "</tr>\n"; |
| 4416 | } |
Jakub Narebski | 47598d7 | 2007-06-08 13:24:56 +0200 | [diff] [blame] | 4417 | print "</tbody>" if $has_header; |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 4418 | print "</table>\n"; |
| 4419 | } |
| 4420 | |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 4421 | sub git_patchset_body { |
Jakub Narebski | e72c0ea | 2007-05-07 01:10:05 +0200 | [diff] [blame] | 4422 | my ($fd, $difftree, $hash, @hash_parents) = @_; |
| 4423 | my ($hash_parent) = $hash_parents[0]; |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 4424 | |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4425 | my $is_combined = (@hash_parents > 1); |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 4426 | my $patch_idx = 0; |
Martin Koegler | 4280cde | 2007-04-22 22:49:25 -0700 | [diff] [blame] | 4427 | my $patch_number = 0; |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4428 | my $patch_line; |
Jakub Narebski | fe87585 | 2006-08-25 20:59:39 +0200 | [diff] [blame] | 4429 | my $diffinfo; |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4430 | my $to_name; |
Jakub Narebski | 744d0ac | 2006-11-08 17:59:41 +0100 | [diff] [blame] | 4431 | my (%from, %to); |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 4432 | |
| 4433 | print "<div class=\"patchset\">\n"; |
| 4434 | |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4435 | # skip to first patch |
| 4436 | while ($patch_line = <$fd>) { |
Jakub Narebski | 157e43b | 2006-08-24 19:34:36 +0200 | [diff] [blame] | 4437 | chomp $patch_line; |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 4438 | |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4439 | last if ($patch_line =~ m/^diff /); |
| 4440 | } |
| 4441 | |
| 4442 | PATCH: |
| 4443 | while ($patch_line) { |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4444 | |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4445 | # parse "git diff" header line |
| 4446 | if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) { |
| 4447 | # $1 is from_name, which we do not use |
| 4448 | $to_name = unquote($2); |
| 4449 | $to_name =~ s!^b/!!; |
| 4450 | } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) { |
| 4451 | # $1 is 'cc' or 'combined', which we do not use |
| 4452 | $to_name = unquote($2); |
| 4453 | } else { |
| 4454 | $to_name = undef; |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4455 | } |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4456 | |
| 4457 | # check if current patch belong to current raw line |
| 4458 | # and parse raw git-diff line if needed |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4459 | if (is_patch_split($diffinfo, { 'to_file' => $to_name })) { |
Jakub Narebski | 2206537 | 2007-05-12 12:42:32 +0200 | [diff] [blame] | 4460 | # this is continuation of a split patch |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4461 | print "<div class=\"patch cont\">\n"; |
| 4462 | } else { |
| 4463 | # advance raw git-diff output if needed |
| 4464 | $patch_idx++ if defined $diffinfo; |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 4465 | |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4466 | # read and prepare patch information |
| 4467 | $diffinfo = parsed_difftree_line($difftree->[$patch_idx]); |
| 4468 | |
Jakub Narebski | cd030c3 | 2007-06-08 13:33:28 +0200 | [diff] [blame] | 4469 | # compact combined diff output can have some patches skipped |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4470 | # find which patch (using pathname of result) we are at now; |
| 4471 | if ($is_combined) { |
| 4472 | while ($to_name ne $diffinfo->{'to_file'}) { |
Jakub Narebski | cd030c3 | 2007-06-08 13:33:28 +0200 | [diff] [blame] | 4473 | print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" . |
| 4474 | format_diff_cc_simplified($diffinfo, @hash_parents) . |
| 4475 | "</div>\n"; # class="patch" |
| 4476 | |
| 4477 | $patch_idx++; |
| 4478 | $patch_number++; |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4479 | |
| 4480 | last if $patch_idx > $#$difftree; |
| 4481 | $diffinfo = parsed_difftree_line($difftree->[$patch_idx]); |
Jakub Narebski | cd030c3 | 2007-06-08 13:33:28 +0200 | [diff] [blame] | 4482 | } |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4483 | } |
Jakub Narebski | 711fa74 | 2007-09-08 21:49:11 +0200 | [diff] [blame] | 4484 | |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 4485 | # modifies %from, %to hashes |
| 4486 | parse_from_to_diffinfo($diffinfo, \%from, \%to, @hash_parents); |
Jakub Narebski | 5f85505 | 2007-05-17 22:54:28 +0200 | [diff] [blame] | 4487 | |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4488 | # this is first patch for raw difftree line with $patch_idx index |
| 4489 | # we index @$difftree array from 0, but number patches from 1 |
| 4490 | print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n"; |
Jakub Narebski | 744d0ac | 2006-11-08 17:59:41 +0100 | [diff] [blame] | 4491 | } |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 4492 | |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4493 | # git diff header |
| 4494 | #assert($patch_line =~ m/^diff /) if DEBUG; |
| 4495 | #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed |
| 4496 | $patch_number++; |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4497 | # print "git diff" header |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 4498 | print format_git_diff_header_line($patch_line, $diffinfo, |
| 4499 | \%from, \%to); |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 4500 | |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4501 | # print extended diff header |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4502 | print "<div class=\"diff extended_header\">\n"; |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4503 | EXTENDED_HEADER: |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4504 | while ($patch_line = <$fd>) { |
| 4505 | chomp $patch_line; |
| 4506 | |
| 4507 | last EXTENDED_HEADER if ($patch_line =~ m/^--- |^diff /); |
| 4508 | |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 4509 | print format_extended_diff_header_line($patch_line, $diffinfo, |
| 4510 | \%from, \%to); |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4511 | } |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4512 | print "</div>\n"; # class="diff extended_header" |
Jakub Narebski | e4e4f82 | 2006-08-25 21:04:13 +0200 | [diff] [blame] | 4513 | |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4514 | # from-file/to-file diff header |
Jakub Narebski | 0bdb28c | 2007-01-10 00:07:43 +0100 | [diff] [blame] | 4515 | if (! $patch_line) { |
| 4516 | print "</div>\n"; # class="patch" |
| 4517 | last PATCH; |
| 4518 | } |
Jakub Narebski | 66399ef | 2007-01-07 02:52:25 +0100 | [diff] [blame] | 4519 | next PATCH if ($patch_line =~ m/^diff /); |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4520 | #assert($patch_line =~ m/^---/) if DEBUG; |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4521 | |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4522 | my $last_patch_line = $patch_line; |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4523 | $patch_line = <$fd>; |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4524 | chomp $patch_line; |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 4525 | #assert($patch_line =~ m/^\+\+\+/) if DEBUG; |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4526 | |
Jakub Narebski | 9092174 | 2007-06-08 13:27:42 +0200 | [diff] [blame] | 4527 | print format_diff_from_to_header($last_patch_line, $patch_line, |
Jakub Narebski | 91af4ce | 2007-06-08 13:32:44 +0200 | [diff] [blame] | 4528 | $diffinfo, \%from, \%to, |
| 4529 | @hash_parents); |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4530 | |
| 4531 | # the patch itself |
| 4532 | LINE: |
| 4533 | while ($patch_line = <$fd>) { |
| 4534 | chomp $patch_line; |
| 4535 | |
| 4536 | next PATCH if ($patch_line =~ m/^diff /); |
| 4537 | |
Jakub Narebski | 59e3b14 | 2006-11-18 23:35:40 +0100 | [diff] [blame] | 4538 | print format_diff_line($patch_line, \%from, \%to); |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 4539 | } |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 4540 | |
Jakub Narebski | 6d55f05 | 2006-11-18 23:35:39 +0100 | [diff] [blame] | 4541 | } continue { |
| 4542 | print "</div>\n"; # class="patch" |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 4543 | } |
Jakub Narebski | d26c426 | 2007-05-17 00:05:55 +0200 | [diff] [blame] | 4544 | |
Ralf Wildenhues | 22e5e58 | 2010-08-22 13:12:12 +0200 | [diff] [blame] | 4545 | # for compact combined (--cc) format, with chunk and patch simplification |
| 4546 | # the patchset might be empty, but there might be unprocessed raw lines |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4547 | for (++$patch_idx if $patch_number > 0; |
Jakub Narebski | cd030c3 | 2007-06-08 13:33:28 +0200 | [diff] [blame] | 4548 | $patch_idx < @$difftree; |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4549 | ++$patch_idx) { |
Jakub Narebski | cd030c3 | 2007-06-08 13:33:28 +0200 | [diff] [blame] | 4550 | # read and prepare patch information |
Jakub Narebski | 0cec6db | 2007-10-30 01:35:05 +0100 | [diff] [blame] | 4551 | $diffinfo = parsed_difftree_line($difftree->[$patch_idx]); |
Jakub Narebski | cd030c3 | 2007-06-08 13:33:28 +0200 | [diff] [blame] | 4552 | |
| 4553 | # generate anchor for "patch" links in difftree / whatchanged part |
| 4554 | print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" . |
| 4555 | format_diff_cc_simplified($diffinfo, @hash_parents) . |
| 4556 | "</div>\n"; # class="patch" |
| 4557 | |
| 4558 | $patch_number++; |
| 4559 | } |
| 4560 | |
Jakub Narebski | d26c426 | 2007-05-17 00:05:55 +0200 | [diff] [blame] | 4561 | if ($patch_number == 0) { |
| 4562 | if (@hash_parents > 1) { |
| 4563 | print "<div class=\"diff nodifferences\">Trivial merge</div>\n"; |
| 4564 | } else { |
| 4565 | print "<div class=\"diff nodifferences\">No differences found</div>\n"; |
| 4566 | } |
| 4567 | } |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 4568 | |
| 4569 | print "</div>\n"; # class="patchset" |
| 4570 | } |
| 4571 | |
| 4572 | # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
| 4573 | |
Jakub Narebski | 6991341 | 2008-06-10 19:21:01 +0200 | [diff] [blame] | 4574 | # fills project list info (age, description, owner, forks) for each |
| 4575 | # project in the list, removing invalid projects from returned list |
| 4576 | # NOTE: modifies $projlist, but does not remove entries from it |
| 4577 | sub fill_project_list_info { |
| 4578 | my ($projlist, $check_forks) = @_; |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4579 | my @projects; |
Jakub Narebski | 6991341 | 2008-06-10 19:21:01 +0200 | [diff] [blame] | 4580 | |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 4581 | my $show_ctags = gitweb_check_feature('ctags'); |
Jakub Narebski | 6991341 | 2008-06-10 19:21:01 +0200 | [diff] [blame] | 4582 | PROJECT: |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4583 | foreach my $pr (@$projlist) { |
Jakub Narebski | 6991341 | 2008-06-10 19:21:01 +0200 | [diff] [blame] | 4584 | my (@activity) = git_get_last_activity($pr->{'path'}); |
| 4585 | unless (@activity) { |
| 4586 | next PROJECT; |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4587 | } |
Jakub Narebski | 6991341 | 2008-06-10 19:21:01 +0200 | [diff] [blame] | 4588 | ($pr->{'age'}, $pr->{'age_string'}) = @activity; |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4589 | if (!defined $pr->{'descr'}) { |
| 4590 | my $descr = git_get_project_description($pr->{'path'}) || ""; |
Jakub Narebski | 6991341 | 2008-06-10 19:21:01 +0200 | [diff] [blame] | 4591 | $descr = to_utf8($descr); |
| 4592 | $pr->{'descr_long'} = $descr; |
Michael Hendricks | 55feb12 | 2007-07-04 18:36:48 -0600 | [diff] [blame] | 4593 | $pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5); |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4594 | } |
| 4595 | if (!defined $pr->{'owner'}) { |
Miklos Vajna | 76e4f5d | 2007-07-04 00:11:23 +0200 | [diff] [blame] | 4596 | $pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || ""; |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4597 | } |
| 4598 | if ($check_forks) { |
| 4599 | my $pname = $pr->{'path'}; |
Junio C Hamano | 83ee94c | 2006-11-07 22:37:17 -0800 | [diff] [blame] | 4600 | if (($pname =~ s/\.git$//) && |
| 4601 | ($pname !~ /\/$/) && |
| 4602 | (-d "$projectroot/$pname")) { |
| 4603 | $pr->{'forks'} = "-d $projectroot/$pname"; |
Jakub Narebski | 3278fbc | 2009-05-11 19:37:28 +0200 | [diff] [blame] | 4604 | } else { |
Junio C Hamano | 83ee94c | 2006-11-07 22:37:17 -0800 | [diff] [blame] | 4605 | $pr->{'forks'} = 0; |
| 4606 | } |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4607 | } |
Petr Baudis | aed93de | 2008-10-02 17:13:02 +0200 | [diff] [blame] | 4608 | $show_ctags and $pr->{'ctags'} = git_get_project_ctags($pr->{'path'}); |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4609 | push @projects, $pr; |
| 4610 | } |
| 4611 | |
Jakub Narebski | 6991341 | 2008-06-10 19:21:01 +0200 | [diff] [blame] | 4612 | return @projects; |
| 4613 | } |
| 4614 | |
Petr Baudis | 6b28da6 | 2008-09-25 18:48:37 +0200 | [diff] [blame] | 4615 | # print 'sort by' <th> element, generating 'sort by $name' replay link |
| 4616 | # if that order is not selected |
Jakub Narebski | 7da0f3a | 2008-06-10 19:21:44 +0200 | [diff] [blame] | 4617 | sub print_sort_th { |
John 'Warthog9' Hawley | 1ee4b4e | 2010-01-30 23:30:43 +0100 | [diff] [blame] | 4618 | print format_sort_th(@_); |
| 4619 | } |
| 4620 | |
| 4621 | sub format_sort_th { |
Petr Baudis | 6b28da6 | 2008-09-25 18:48:37 +0200 | [diff] [blame] | 4622 | my ($name, $order, $header) = @_; |
John 'Warthog9' Hawley | 1ee4b4e | 2010-01-30 23:30:43 +0100 | [diff] [blame] | 4623 | my $sort_th = ""; |
Jakub Narebski | 7da0f3a | 2008-06-10 19:21:44 +0200 | [diff] [blame] | 4624 | $header ||= ucfirst($name); |
| 4625 | |
| 4626 | if ($order eq $name) { |
John 'Warthog9' Hawley | 1ee4b4e | 2010-01-30 23:30:43 +0100 | [diff] [blame] | 4627 | $sort_th .= "<th>$header</th>\n"; |
Jakub Narebski | 7da0f3a | 2008-06-10 19:21:44 +0200 | [diff] [blame] | 4628 | } else { |
John 'Warthog9' Hawley | 1ee4b4e | 2010-01-30 23:30:43 +0100 | [diff] [blame] | 4629 | $sort_th .= "<th>" . |
| 4630 | $cgi->a({-href => href(-replay=>1, order=>$name), |
| 4631 | -class => "header"}, $header) . |
| 4632 | "</th>\n"; |
Jakub Narebski | 7da0f3a | 2008-06-10 19:21:44 +0200 | [diff] [blame] | 4633 | } |
John 'Warthog9' Hawley | 1ee4b4e | 2010-01-30 23:30:43 +0100 | [diff] [blame] | 4634 | |
| 4635 | return $sort_th; |
Jakub Narebski | 7da0f3a | 2008-06-10 19:21:44 +0200 | [diff] [blame] | 4636 | } |
| 4637 | |
Jakub Narebski | 6991341 | 2008-06-10 19:21:01 +0200 | [diff] [blame] | 4638 | sub git_project_list_body { |
Petr Baudis | 4232611 | 2008-10-02 17:17:01 +0200 | [diff] [blame] | 4639 | # actually uses global variable $project |
Jakub Narebski | 6991341 | 2008-06-10 19:21:01 +0200 | [diff] [blame] | 4640 | my ($projlist, $order, $from, $to, $extra, $no_header) = @_; |
| 4641 | |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 4642 | my $check_forks = gitweb_check_feature('forks'); |
Jakub Narebski | 6991341 | 2008-06-10 19:21:01 +0200 | [diff] [blame] | 4643 | my @projects = fill_project_list_info($projlist, $check_forks); |
| 4644 | |
Frank Lichtenheld | b06dcf8 | 2007-04-06 23:58:24 +0200 | [diff] [blame] | 4645 | $order ||= $default_projects_order; |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4646 | $from = 0 unless defined $from; |
| 4647 | $to = $#projects if (!defined $to || $#projects < $to); |
| 4648 | |
Petr Baudis | 6b28da6 | 2008-09-25 18:48:37 +0200 | [diff] [blame] | 4649 | my %order_info = ( |
| 4650 | project => { key => 'path', type => 'str' }, |
| 4651 | descr => { key => 'descr_long', type => 'str' }, |
| 4652 | owner => { key => 'owner', type => 'str' }, |
| 4653 | age => { key => 'age', type => 'num' } |
| 4654 | ); |
| 4655 | my $oi = $order_info{$order}; |
| 4656 | if ($oi->{'type'} eq 'str') { |
| 4657 | @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects; |
| 4658 | } else { |
| 4659 | @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects; |
| 4660 | } |
| 4661 | |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 4662 | my $show_ctags = gitweb_check_feature('ctags'); |
Petr Baudis | aed93de | 2008-10-02 17:13:02 +0200 | [diff] [blame] | 4663 | if ($show_ctags) { |
| 4664 | my %ctags; |
| 4665 | foreach my $p (@projects) { |
| 4666 | foreach my $ct (keys %{$p->{'ctags'}}) { |
| 4667 | $ctags{$ct} += $p->{'ctags'}->{$ct}; |
| 4668 | } |
| 4669 | } |
| 4670 | my $cloud = git_populate_project_tagcloud(\%ctags); |
| 4671 | print git_show_project_tagcloud($cloud, 64); |
| 4672 | } |
| 4673 | |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4674 | print "<table class=\"project_list\">\n"; |
| 4675 | unless ($no_header) { |
| 4676 | print "<tr>\n"; |
| 4677 | if ($check_forks) { |
| 4678 | print "<th></th>\n"; |
| 4679 | } |
Petr Baudis | 6b28da6 | 2008-09-25 18:48:37 +0200 | [diff] [blame] | 4680 | print_sort_th('project', $order, 'Project'); |
| 4681 | print_sort_th('descr', $order, 'Description'); |
| 4682 | print_sort_th('owner', $order, 'Owner'); |
| 4683 | print_sort_th('age', $order, 'Last Change'); |
Jakub Narebski | 7da0f3a | 2008-06-10 19:21:44 +0200 | [diff] [blame] | 4684 | print "<th></th>\n" . # for links |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4685 | "</tr>\n"; |
| 4686 | } |
| 4687 | my $alternate = 1; |
Petr Baudis | aed93de | 2008-10-02 17:13:02 +0200 | [diff] [blame] | 4688 | my $tagfilter = $cgi->param('by_tag'); |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4689 | for (my $i = $from; $i <= $to; $i++) { |
| 4690 | my $pr = $projects[$i]; |
Petr Baudis | 4232611 | 2008-10-02 17:17:01 +0200 | [diff] [blame] | 4691 | |
Petr Baudis | aed93de | 2008-10-02 17:13:02 +0200 | [diff] [blame] | 4692 | next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}}; |
Petr Baudis | 0d1d154 | 2008-10-03 09:29:45 +0200 | [diff] [blame] | 4693 | next if $searchtext and not $pr->{'path'} =~ /$searchtext/ |
| 4694 | and not $pr->{'descr_long'} =~ /$searchtext/; |
| 4695 | # Weed out forks or non-matching entries of search |
Petr Baudis | 4232611 | 2008-10-02 17:17:01 +0200 | [diff] [blame] | 4696 | if ($check_forks) { |
| 4697 | my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s#\.git$#/#; |
| 4698 | $forkbase="^$forkbase" if $forkbase; |
Petr Baudis | 0d1d154 | 2008-10-03 09:29:45 +0200 | [diff] [blame] | 4699 | next if not $searchtext and not $tagfilter and $show_ctags |
| 4700 | and $pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe |
Petr Baudis | 4232611 | 2008-10-02 17:17:01 +0200 | [diff] [blame] | 4701 | } |
| 4702 | |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4703 | if ($alternate) { |
| 4704 | print "<tr class=\"dark\">\n"; |
| 4705 | } else { |
| 4706 | print "<tr class=\"light\">\n"; |
| 4707 | } |
| 4708 | $alternate ^= 1; |
| 4709 | if ($check_forks) { |
| 4710 | print "<td>"; |
| 4711 | if ($pr->{'forks'}) { |
Junio C Hamano | 83ee94c | 2006-11-07 22:37:17 -0800 | [diff] [blame] | 4712 | print "<!-- $pr->{'forks'} -->\n"; |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4713 | print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "+"); |
| 4714 | } |
| 4715 | print "</td>\n"; |
| 4716 | } |
| 4717 | print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"), |
| 4718 | -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" . |
Jakub Narebski | e88ce8a | 2006-11-26 02:18:26 +0100 | [diff] [blame] | 4719 | "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"), |
| 4720 | -class => "list", -title => $pr->{'descr_long'}}, |
| 4721 | esc_html($pr->{'descr'})) . "</td>\n" . |
David Symonds | d3cd249 | 2007-10-23 11:31:23 +1000 | [diff] [blame] | 4722 | "<td><i>" . chop_and_escape_str($pr->{'owner'}, 15) . "</i></td>\n"; |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4723 | print "<td class=\"". age_class($pr->{'age'}) . "\">" . |
Jakub Narebski | 785cdea | 2007-05-13 12:39:22 +0200 | [diff] [blame] | 4724 | (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" . |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4725 | "<td class=\"link\">" . |
| 4726 | $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " . |
Alexandre Julliard | faa1bbf | 2006-11-15 21:37:50 +0100 | [diff] [blame] | 4727 | $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " . |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 4728 | $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " . |
| 4729 | $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") . |
| 4730 | ($pr->{'forks'} ? " | " . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "forks") : '') . |
| 4731 | "</td>\n" . |
| 4732 | "</tr>\n"; |
| 4733 | } |
| 4734 | if (defined $extra) { |
| 4735 | print "<tr>\n"; |
| 4736 | if ($check_forks) { |
| 4737 | print "<td></td>\n"; |
| 4738 | } |
| 4739 | print "<td colspan=\"5\">$extra</td>\n" . |
| 4740 | "</tr>\n"; |
| 4741 | } |
| 4742 | print "</table>\n"; |
| 4743 | } |
| 4744 | |
Jakub Narebski | 42671ca | 2009-11-13 02:02:12 +0100 | [diff] [blame] | 4745 | sub git_log_body { |
| 4746 | # uses global variable $project |
| 4747 | my ($commitlist, $from, $to, $refs, $extra) = @_; |
| 4748 | |
| 4749 | $from = 0 unless defined $from; |
| 4750 | $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to); |
| 4751 | |
| 4752 | for (my $i = 0; $i <= $to; $i++) { |
| 4753 | my %co = %{$commitlist->[$i]}; |
| 4754 | next if !%co; |
| 4755 | my $commit = $co{'id'}; |
| 4756 | my $ref = format_ref_marker($refs, $commit); |
| 4757 | my %ad = parse_date($co{'author_epoch'}); |
| 4758 | git_print_header_div('commit', |
| 4759 | "<span class=\"age\">$co{'age_string'}</span>" . |
| 4760 | esc_html($co{'title'}) . $ref, |
| 4761 | $commit); |
| 4762 | print "<div class=\"title_text\">\n" . |
| 4763 | "<div class=\"log_link\">\n" . |
| 4764 | $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . |
| 4765 | " | " . |
| 4766 | $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . |
| 4767 | " | " . |
| 4768 | $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") . |
| 4769 | "<br/>\n" . |
| 4770 | "</div>\n"; |
| 4771 | git_print_authorship(\%co, -tag => 'span'); |
| 4772 | print "<br/>\n</div>\n"; |
| 4773 | |
| 4774 | print "<div class=\"log_body\">\n"; |
| 4775 | git_print_log($co{'comment'}, -final_empty_line=> 1); |
| 4776 | print "</div>\n"; |
| 4777 | } |
| 4778 | if ($extra) { |
| 4779 | print "<div class=\"page_nav\">\n"; |
| 4780 | print "$extra\n"; |
| 4781 | print "</div>\n"; |
| 4782 | } |
| 4783 | } |
| 4784 | |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4785 | sub git_shortlog_body { |
| 4786 | # uses global variable $project |
Robert Fitzsimons | 190d7fd | 2006-12-24 14:31:44 +0000 | [diff] [blame] | 4787 | my ($commitlist, $from, $to, $refs, $extra) = @_; |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 4788 | |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4789 | $from = 0 unless defined $from; |
Robert Fitzsimons | 190d7fd | 2006-12-24 14:31:44 +0000 | [diff] [blame] | 4790 | $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to); |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4791 | |
Jakub Narebski | 591ebf6 | 2007-11-19 14:16:11 +0100 | [diff] [blame] | 4792 | print "<table class=\"shortlog\">\n"; |
Luben Tuikov | 6dd36ac | 2006-09-28 16:47:50 -0700 | [diff] [blame] | 4793 | my $alternate = 1; |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4794 | for (my $i = $from; $i <= $to; $i++) { |
Robert Fitzsimons | 190d7fd | 2006-12-24 14:31:44 +0000 | [diff] [blame] | 4795 | my %co = %{$commitlist->[$i]}; |
| 4796 | my $commit = $co{'id'}; |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 4797 | my $ref = format_ref_marker($refs, $commit); |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4798 | if ($alternate) { |
| 4799 | print "<tr class=\"dark\">\n"; |
| 4800 | } else { |
| 4801 | print "<tr class=\"light\">\n"; |
| 4802 | } |
| 4803 | $alternate ^= 1; |
| 4804 | # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" . |
| 4805 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 4806 | format_author_html('td', \%co, 10) . "<td>"; |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 4807 | print format_subject_html($co{'title'}, $co{'title_short'}, |
| 4808 | href(action=>"commit", hash=>$commit), $ref); |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4809 | print "</td>\n" . |
| 4810 | "<td class=\"link\">" . |
Petr Baudis | 4777b01 | 2006-10-24 05:36:10 +0200 | [diff] [blame] | 4811 | $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " . |
Petr Baudis | 35749ae | 2006-09-22 03:19:44 +0200 | [diff] [blame] | 4812 | $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " . |
Petr Baudis | 55ff35c | 2006-10-06 15:57:52 +0200 | [diff] [blame] | 4813 | $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree"); |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 4814 | my $snapshot_links = format_snapshot_links($commit); |
| 4815 | if (defined $snapshot_links) { |
| 4816 | print " | " . $snapshot_links; |
Petr Baudis | 55ff35c | 2006-10-06 15:57:52 +0200 | [diff] [blame] | 4817 | } |
Aneesh Kumar K.V | cb9c6e5 | 2006-08-17 20:59:46 +0530 | [diff] [blame] | 4818 | print "</td>\n" . |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4819 | "</tr>\n"; |
| 4820 | } |
| 4821 | if (defined $extra) { |
| 4822 | print "<tr>\n" . |
| 4823 | "<td colspan=\"4\">$extra</td>\n" . |
| 4824 | "</tr>\n"; |
| 4825 | } |
| 4826 | print "</table>\n"; |
| 4827 | } |
| 4828 | |
Jakub Narebski | 581860e | 2006-08-14 02:09:08 +0200 | [diff] [blame] | 4829 | sub git_history_body { |
| 4830 | # Warning: assumes constant type (blob or tree) during history |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 4831 | my ($commitlist, $from, $to, $refs, $extra, |
| 4832 | $file_name, $file_hash, $ftype) = @_; |
Jakub Narebski | 8be6835 | 2006-09-11 00:36:04 +0200 | [diff] [blame] | 4833 | |
| 4834 | $from = 0 unless defined $from; |
Robert Fitzsimons | a8b983b | 2006-12-24 14:31:48 +0000 | [diff] [blame] | 4835 | $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist}); |
Jakub Narebski | 581860e | 2006-08-14 02:09:08 +0200 | [diff] [blame] | 4836 | |
Jakub Narebski | 591ebf6 | 2007-11-19 14:16:11 +0100 | [diff] [blame] | 4837 | print "<table class=\"history\">\n"; |
Luben Tuikov | 6dd36ac | 2006-09-28 16:47:50 -0700 | [diff] [blame] | 4838 | my $alternate = 1; |
Jakub Narebski | 8be6835 | 2006-09-11 00:36:04 +0200 | [diff] [blame] | 4839 | for (my $i = $from; $i <= $to; $i++) { |
Robert Fitzsimons | a8b983b | 2006-12-24 14:31:48 +0000 | [diff] [blame] | 4840 | my %co = %{$commitlist->[$i]}; |
Jakub Narebski | 581860e | 2006-08-14 02:09:08 +0200 | [diff] [blame] | 4841 | if (!%co) { |
| 4842 | next; |
| 4843 | } |
Robert Fitzsimons | a8b983b | 2006-12-24 14:31:48 +0000 | [diff] [blame] | 4844 | my $commit = $co{'id'}; |
Jakub Narebski | 581860e | 2006-08-14 02:09:08 +0200 | [diff] [blame] | 4845 | |
| 4846 | my $ref = format_ref_marker($refs, $commit); |
| 4847 | |
| 4848 | if ($alternate) { |
| 4849 | print "<tr class=\"dark\">\n"; |
| 4850 | } else { |
| 4851 | print "<tr class=\"light\">\n"; |
| 4852 | } |
| 4853 | $alternate ^= 1; |
| 4854 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 4855 | # shortlog: format_author_html('td', \%co, 10) |
| 4856 | format_author_html('td', \%co, 15, 3) . "<td>"; |
Jakub Narebski | 581860e | 2006-08-14 02:09:08 +0200 | [diff] [blame] | 4857 | # originally git_history used chop_str($co{'title'}, 50) |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 4858 | print format_subject_html($co{'title'}, $co{'title_short'}, |
| 4859 | href(action=>"commit", hash=>$commit), $ref); |
Jakub Narebski | 581860e | 2006-08-14 02:09:08 +0200 | [diff] [blame] | 4860 | print "</td>\n" . |
| 4861 | "<td class=\"link\">" . |
Luben Tuikov | 6d81c5a | 2006-09-28 17:21:07 -0700 | [diff] [blame] | 4862 | $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype) . " | " . |
| 4863 | $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff"); |
Jakub Narebski | 581860e | 2006-08-14 02:09:08 +0200 | [diff] [blame] | 4864 | |
| 4865 | if ($ftype eq 'blob') { |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 4866 | my $blob_current = $file_hash; |
Jakub Narebski | 581860e | 2006-08-14 02:09:08 +0200 | [diff] [blame] | 4867 | my $blob_parent = git_get_hash_by_path($commit, $file_name); |
| 4868 | if (defined $blob_current && defined $blob_parent && |
| 4869 | $blob_current ne $blob_parent) { |
| 4870 | print " | " . |
Jakub Narebski | 420e92f | 2006-08-24 23:53:54 +0200 | [diff] [blame] | 4871 | $cgi->a({-href => href(action=>"blobdiff", |
| 4872 | hash=>$blob_current, hash_parent=>$blob_parent, |
| 4873 | hash_base=>$hash_base, hash_parent_base=>$commit, |
| 4874 | file_name=>$file_name)}, |
Jakub Narebski | 581860e | 2006-08-14 02:09:08 +0200 | [diff] [blame] | 4875 | "diff to current"); |
| 4876 | } |
| 4877 | } |
| 4878 | print "</td>\n" . |
| 4879 | "</tr>\n"; |
| 4880 | } |
| 4881 | if (defined $extra) { |
| 4882 | print "<tr>\n" . |
| 4883 | "<td colspan=\"4\">$extra</td>\n" . |
| 4884 | "</tr>\n"; |
| 4885 | } |
| 4886 | print "</table>\n"; |
| 4887 | } |
| 4888 | |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4889 | sub git_tags_body { |
| 4890 | # uses global variable $project |
| 4891 | my ($taglist, $from, $to, $extra) = @_; |
| 4892 | $from = 0 unless defined $from; |
| 4893 | $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to); |
| 4894 | |
Jakub Narebski | 591ebf6 | 2007-11-19 14:16:11 +0100 | [diff] [blame] | 4895 | print "<table class=\"tags\">\n"; |
Luben Tuikov | 6dd36ac | 2006-09-28 16:47:50 -0700 | [diff] [blame] | 4896 | my $alternate = 1; |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4897 | for (my $i = $from; $i <= $to; $i++) { |
| 4898 | my $entry = $taglist->[$i]; |
| 4899 | my %tag = %$entry; |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 4900 | my $comment = $tag{'subject'}; |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4901 | my $comment_short; |
| 4902 | if (defined $comment) { |
| 4903 | $comment_short = chop_str($comment, 30, 5); |
| 4904 | } |
| 4905 | if ($alternate) { |
| 4906 | print "<tr class=\"dark\">\n"; |
| 4907 | } else { |
| 4908 | print "<tr class=\"light\">\n"; |
| 4909 | } |
| 4910 | $alternate ^= 1; |
Jakub Narebski | 27dd1a8 | 2007-01-03 22:54:29 +0100 | [diff] [blame] | 4911 | if (defined $tag{'age'}) { |
| 4912 | print "<td><i>$tag{'age'}</i></td>\n"; |
| 4913 | } else { |
| 4914 | print "<td></td>\n"; |
| 4915 | } |
| 4916 | print "<td>" . |
Martin Waitz | 1c2a4f5 | 2006-08-16 00:24:30 +0200 | [diff] [blame] | 4917 | $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}), |
Jakub Narebski | 63e4220 | 2006-08-22 12:38:59 +0200 | [diff] [blame] | 4918 | -class => "list name"}, esc_html($tag{'name'})) . |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4919 | "</td>\n" . |
| 4920 | "<td>"; |
| 4921 | if (defined $comment) { |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 4922 | print format_subject_html($comment, $comment_short, |
| 4923 | href(action=>"tag", hash=>$tag{'id'})); |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4924 | } |
| 4925 | print "</td>\n" . |
| 4926 | "<td class=\"selflink\">"; |
| 4927 | if ($tag{'type'} eq "tag") { |
Martin Waitz | 1c2a4f5 | 2006-08-16 00:24:30 +0200 | [diff] [blame] | 4928 | print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag"); |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4929 | } else { |
| 4930 | print " "; |
| 4931 | } |
| 4932 | print "</td>\n" . |
| 4933 | "<td class=\"link\">" . " | " . |
Martin Waitz | 1c2a4f5 | 2006-08-16 00:24:30 +0200 | [diff] [blame] | 4934 | $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'}); |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4935 | if ($tag{'reftype'} eq "commit") { |
Jakub Narebski | bf901f8 | 2007-12-15 15:40:28 +0100 | [diff] [blame] | 4936 | print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})}, "shortlog") . |
| 4937 | " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})}, "log"); |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4938 | } elsif ($tag{'reftype'} eq "blob") { |
Martin Waitz | 1c2a4f5 | 2006-08-16 00:24:30 +0200 | [diff] [blame] | 4939 | print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw"); |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4940 | } |
| 4941 | print "</td>\n" . |
| 4942 | "</tr>"; |
| 4943 | } |
| 4944 | if (defined $extra) { |
| 4945 | print "<tr>\n" . |
| 4946 | "<td colspan=\"5\">$extra</td>\n" . |
| 4947 | "</tr>\n"; |
| 4948 | } |
| 4949 | print "</table>\n"; |
| 4950 | } |
| 4951 | |
| 4952 | sub git_heads_body { |
| 4953 | # uses global variable $project |
Jakub Narebski | 120ddde | 2006-09-19 14:33:22 +0200 | [diff] [blame] | 4954 | my ($headlist, $head, $from, $to, $extra) = @_; |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4955 | $from = 0 unless defined $from; |
Jakub Narebski | 120ddde | 2006-09-19 14:33:22 +0200 | [diff] [blame] | 4956 | $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to); |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4957 | |
Jakub Narebski | 591ebf6 | 2007-11-19 14:16:11 +0100 | [diff] [blame] | 4958 | print "<table class=\"heads\">\n"; |
Luben Tuikov | 6dd36ac | 2006-09-28 16:47:50 -0700 | [diff] [blame] | 4959 | my $alternate = 1; |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4960 | for (my $i = $from; $i <= $to; $i++) { |
Jakub Narebski | 120ddde | 2006-09-19 14:33:22 +0200 | [diff] [blame] | 4961 | my $entry = $headlist->[$i]; |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 4962 | my %ref = %$entry; |
| 4963 | my $curr = $ref{'id'} eq $head; |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4964 | if ($alternate) { |
| 4965 | print "<tr class=\"dark\">\n"; |
| 4966 | } else { |
| 4967 | print "<tr class=\"light\">\n"; |
| 4968 | } |
| 4969 | $alternate ^= 1; |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 4970 | print "<td><i>$ref{'age'}</i></td>\n" . |
| 4971 | ($curr ? "<td class=\"current_head\">" : "<td>") . |
Jakub Narebski | bf901f8 | 2007-12-15 15:40:28 +0100 | [diff] [blame] | 4972 | $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}), |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 4973 | -class => "list name"},esc_html($ref{'name'})) . |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4974 | "</td>\n" . |
| 4975 | "<td class=\"link\">" . |
Jakub Narebski | bf901f8 | 2007-12-15 15:40:28 +0100 | [diff] [blame] | 4976 | $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})}, "shortlog") . " | " . |
| 4977 | $cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})}, "log") . " | " . |
Giuseppe Bilotta | 9e70e15 | 2010-11-11 13:26:08 +0100 | [diff] [blame] | 4978 | $cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'fullname'})}, "tree") . |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 4979 | "</td>\n" . |
| 4980 | "</tr>"; |
| 4981 | } |
| 4982 | if (defined $extra) { |
| 4983 | print "<tr>\n" . |
| 4984 | "<td colspan=\"3\">$extra</td>\n" . |
| 4985 | "</tr>\n"; |
| 4986 | } |
| 4987 | print "</table>\n"; |
| 4988 | } |
| 4989 | |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 4990 | sub git_search_grep_body { |
Robert Fitzsimons | 5ad6608 | 2006-12-24 14:31:46 +0000 | [diff] [blame] | 4991 | my ($commitlist, $from, $to, $extra) = @_; |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 4992 | $from = 0 unless defined $from; |
Robert Fitzsimons | 5ad6608 | 2006-12-24 14:31:46 +0000 | [diff] [blame] | 4993 | $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to); |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 4994 | |
Jakub Narebski | 591ebf6 | 2007-11-19 14:16:11 +0100 | [diff] [blame] | 4995 | print "<table class=\"commit_search\">\n"; |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 4996 | my $alternate = 1; |
| 4997 | for (my $i = $from; $i <= $to; $i++) { |
Robert Fitzsimons | 5ad6608 | 2006-12-24 14:31:46 +0000 | [diff] [blame] | 4998 | my %co = %{$commitlist->[$i]}; |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 4999 | if (!%co) { |
| 5000 | next; |
| 5001 | } |
Robert Fitzsimons | 5ad6608 | 2006-12-24 14:31:46 +0000 | [diff] [blame] | 5002 | my $commit = $co{'id'}; |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 5003 | if ($alternate) { |
| 5004 | print "<tr class=\"dark\">\n"; |
| 5005 | } else { |
| 5006 | print "<tr class=\"light\">\n"; |
| 5007 | } |
| 5008 | $alternate ^= 1; |
| 5009 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 5010 | format_author_html('td', \%co, 15, 5) . |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 5011 | "<td>" . |
Junio C Hamano | be8b906 | 2008-02-22 17:33:47 +0100 | [diff] [blame] | 5012 | $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), |
| 5013 | -class => "list subject"}, |
| 5014 | chop_and_escape_str($co{'title'}, 50) . "<br/>"); |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 5015 | my $comment = $co{'comment'}; |
| 5016 | foreach my $line (@$comment) { |
Jakub Narebski | 6dfbb30 | 2008-03-02 16:57:14 +0100 | [diff] [blame] | 5017 | if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) { |
Junio C Hamano | be8b906 | 2008-02-22 17:33:47 +0100 | [diff] [blame] | 5018 | my ($lead, $match, $trail) = ($1, $2, $3); |
Jakub Narebski | b8d97d0 | 2008-02-25 21:07:57 +0100 | [diff] [blame] | 5019 | $match = chop_str($match, 70, 5, 'center'); |
| 5020 | my $contextlen = int((80 - length($match))/2); |
| 5021 | $contextlen = 30 if ($contextlen > 30); |
| 5022 | $lead = chop_str($lead, $contextlen, 10, 'left'); |
| 5023 | $trail = chop_str($trail, $contextlen, 10, 'right'); |
Junio C Hamano | be8b906 | 2008-02-22 17:33:47 +0100 | [diff] [blame] | 5024 | |
| 5025 | $lead = esc_html($lead); |
| 5026 | $match = esc_html($match); |
| 5027 | $trail = esc_html($trail); |
| 5028 | |
| 5029 | print "$lead<span class=\"match\">$match</span>$trail<br />"; |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 5030 | } |
| 5031 | } |
| 5032 | print "</td>\n" . |
| 5033 | "<td class=\"link\">" . |
| 5034 | $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") . |
| 5035 | " | " . |
Denis Cheng | f1fe8f5 | 2007-11-26 20:42:06 +0800 | [diff] [blame] | 5036 | $cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})}, "commitdiff") . |
| 5037 | " | " . |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 5038 | $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree"); |
| 5039 | print "</td>\n" . |
| 5040 | "</tr>\n"; |
| 5041 | } |
| 5042 | if (defined $extra) { |
| 5043 | print "<tr>\n" . |
| 5044 | "<td colspan=\"3\">$extra</td>\n" . |
| 5045 | "</tr>\n"; |
| 5046 | } |
| 5047 | print "</table>\n"; |
| 5048 | } |
| 5049 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 5050 | ## ====================================================================== |
| 5051 | ## ====================================================================== |
| 5052 | ## actions |
| 5053 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 5054 | sub git_project_list { |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 5055 | my $order = $input_params{'order'}; |
Frank Lichtenheld | b06dcf8 | 2007-04-06 23:58:24 +0200 | [diff] [blame] | 5056 | if (defined $order && $order !~ m/none|project|descr|owner|age/) { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5057 | die_error(400, "Unknown order parameter"); |
Jakub Narebski | 6326b60 | 2006-08-01 02:59:12 +0200 | [diff] [blame] | 5058 | } |
| 5059 | |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5060 | my @list = git_get_projects_list(); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 5061 | if (!@list) { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5062 | die_error(404, "No projects found"); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 5063 | } |
Jakub Narebski | 6326b60 | 2006-08-01 02:59:12 +0200 | [diff] [blame] | 5064 | |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 5065 | git_header_html(); |
John 'Warthog9' Hawley | 24d4afc | 2010-01-30 23:30:41 +0100 | [diff] [blame] | 5066 | if (defined $home_text && -f $home_text) { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 5067 | print "<div class=\"index_include\">\n"; |
Jakub Narebski | 2dcb5e1 | 2008-12-01 19:01:42 +0100 | [diff] [blame] | 5068 | insert_file($home_text); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 5069 | print "</div>\n"; |
| 5070 | } |
Petr Baudis | 0d1d154 | 2008-10-03 09:29:45 +0200 | [diff] [blame] | 5071 | print $cgi->startform(-method => "get") . |
| 5072 | "<p class=\"projsearch\">Search:\n" . |
| 5073 | $cgi->textfield(-name => "s", -value => $searchtext) . "\n" . |
| 5074 | "</p>" . |
| 5075 | $cgi->end_form() . "\n"; |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 5076 | git_project_list_body(\@list, $order); |
| 5077 | git_footer_html(); |
| 5078 | } |
| 5079 | |
| 5080 | sub git_forks { |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 5081 | my $order = $input_params{'order'}; |
Frank Lichtenheld | b06dcf8 | 2007-04-06 23:58:24 +0200 | [diff] [blame] | 5082 | if (defined $order && $order !~ m/none|project|descr|owner|age/) { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5083 | die_error(400, "Unknown order parameter"); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 5084 | } |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 5085 | |
| 5086 | my @list = git_get_projects_list($project); |
| 5087 | if (!@list) { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5088 | die_error(404, "No forks found"); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 5089 | } |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 5090 | |
| 5091 | git_header_html(); |
| 5092 | git_print_page_nav('',''); |
| 5093 | git_print_header_div('summary', "$project forks"); |
| 5094 | git_project_list_body(\@list, $order); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 5095 | git_footer_html(); |
| 5096 | } |
| 5097 | |
Jakub Narebski | fc2b2be | 2006-09-15 04:56:03 +0200 | [diff] [blame] | 5098 | sub git_project_index { |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 5099 | my @projects = git_get_projects_list($project); |
Jakub Narebski | fc2b2be | 2006-09-15 04:56:03 +0200 | [diff] [blame] | 5100 | |
| 5101 | print $cgi->header( |
| 5102 | -type => 'text/plain', |
| 5103 | -charset => 'utf-8', |
Jakub Narebski | ab41dfb | 2006-09-26 01:59:43 +0200 | [diff] [blame] | 5104 | -content_disposition => 'inline; filename="index.aux"'); |
Jakub Narebski | fc2b2be | 2006-09-15 04:56:03 +0200 | [diff] [blame] | 5105 | |
| 5106 | foreach my $pr (@projects) { |
| 5107 | if (!exists $pr->{'owner'}) { |
Miklos Vajna | 76e4f5d | 2007-07-04 00:11:23 +0200 | [diff] [blame] | 5108 | $pr->{'owner'} = git_get_project_owner("$pr->{'path'}"); |
Jakub Narebski | fc2b2be | 2006-09-15 04:56:03 +0200 | [diff] [blame] | 5109 | } |
| 5110 | |
| 5111 | my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'}); |
| 5112 | # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' ' |
| 5113 | $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg; |
| 5114 | $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg; |
| 5115 | $path =~ s/ /\+/g; |
| 5116 | $owner =~ s/ /\+/g; |
| 5117 | |
| 5118 | print "$path $owner\n"; |
| 5119 | } |
| 5120 | } |
| 5121 | |
Kay Sievers | ede5e10 | 2005-08-07 20:23:12 +0200 | [diff] [blame] | 5122 | sub git_summary { |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5123 | my $descr = git_get_project_description($project) || "none"; |
Robert Fitzsimons | a979d12 | 2006-12-22 19:38:15 +0000 | [diff] [blame] | 5124 | my %co = parse_commit("HEAD"); |
Jakub Narebski | 785cdea | 2007-05-13 12:39:22 +0200 | [diff] [blame] | 5125 | my %cd = %co ? parse_date($co{'committer_epoch'}, $co{'committer_tz'}) : (); |
Robert Fitzsimons | a979d12 | 2006-12-22 19:38:15 +0000 | [diff] [blame] | 5126 | my $head = $co{'id'}; |
Giuseppe Bilotta | 00fa6fe | 2010-11-11 13:26:11 +0100 | [diff] [blame^] | 5127 | my $remote_heads = gitweb_check_feature('remote_heads'); |
Kay Sievers | ede5e10 | 2005-08-07 20:23:12 +0200 | [diff] [blame] | 5128 | |
Jakub Narebski | 1e0cf03 | 2006-08-14 02:10:06 +0200 | [diff] [blame] | 5129 | my $owner = git_get_project_owner($project); |
Kay Sievers | ede5e10 | 2005-08-07 20:23:12 +0200 | [diff] [blame] | 5130 | |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 5131 | my $refs = git_get_references(); |
Robert Fitzsimons | 313ce8c | 2006-12-19 12:08:54 +0000 | [diff] [blame] | 5132 | # These get_*_list functions return one more to allow us to see if |
| 5133 | # there are more ... |
| 5134 | my @taglist = git_get_tags_list(16); |
| 5135 | my @headlist = git_get_heads_list(16); |
Giuseppe Bilotta | 00fa6fe | 2010-11-11 13:26:11 +0100 | [diff] [blame^] | 5136 | my @remotelist = $remote_heads ? git_get_heads_list(16, 'remotes') : (); |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 5137 | my @forklist; |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 5138 | my $check_forks = gitweb_check_feature('forks'); |
Junio C Hamano | 5dd5ed0 | 2006-11-07 22:00:45 -0800 | [diff] [blame] | 5139 | |
| 5140 | if ($check_forks) { |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 5141 | @forklist = git_get_projects_list($project); |
| 5142 | } |
Jakub Narebski | 120ddde | 2006-09-19 14:33:22 +0200 | [diff] [blame] | 5143 | |
Kay Sievers | ede5e10 | 2005-08-07 20:23:12 +0200 | [diff] [blame] | 5144 | git_header_html(); |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5145 | git_print_page_nav('summary','', $head); |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 5146 | |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 5147 | print "<div class=\"title\"> </div>\n"; |
Jakub Narebski | 591ebf6 | 2007-11-19 14:16:11 +0100 | [diff] [blame] | 5148 | print "<table class=\"projects_list\">\n" . |
Petr Baudis | a476142 | 2008-10-02 16:25:05 +0200 | [diff] [blame] | 5149 | "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" . |
| 5150 | "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n"; |
Jakub Narebski | 785cdea | 2007-05-13 12:39:22 +0200 | [diff] [blame] | 5151 | if (defined $cd{'rfc2822'}) { |
Petr Baudis | a476142 | 2008-10-02 16:25:05 +0200 | [diff] [blame] | 5152 | print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n"; |
Jakub Narebski | 785cdea | 2007-05-13 12:39:22 +0200 | [diff] [blame] | 5153 | } |
| 5154 | |
Jakub Narebski | e79ca7c | 2006-08-16 14:50:34 +0200 | [diff] [blame] | 5155 | # use per project git URL list in $projectroot/$project/cloneurl |
| 5156 | # or make project git URL from git base URL and project name |
Jakub Narebski | 19a8721 | 2006-08-15 23:03:17 +0200 | [diff] [blame] | 5157 | my $url_tag = "URL"; |
Jakub Narebski | e79ca7c | 2006-08-16 14:50:34 +0200 | [diff] [blame] | 5158 | my @url_list = git_get_project_url_list($project); |
| 5159 | @url_list = map { "$_/$project" } @git_base_url_list unless @url_list; |
| 5160 | foreach my $git_url (@url_list) { |
| 5161 | next unless $git_url; |
Petr Baudis | a476142 | 2008-10-02 16:25:05 +0200 | [diff] [blame] | 5162 | print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n"; |
Jakub Narebski | 19a8721 | 2006-08-15 23:03:17 +0200 | [diff] [blame] | 5163 | $url_tag = ""; |
| 5164 | } |
Petr Baudis | aed93de | 2008-10-02 17:13:02 +0200 | [diff] [blame] | 5165 | |
| 5166 | # Tag cloud |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 5167 | my $show_ctags = gitweb_check_feature('ctags'); |
Petr Baudis | aed93de | 2008-10-02 17:13:02 +0200 | [diff] [blame] | 5168 | if ($show_ctags) { |
| 5169 | my $ctags = git_get_project_ctags($project); |
| 5170 | my $cloud = git_populate_project_tagcloud($ctags); |
| 5171 | print "<tr id=\"metadata_ctags\"><td>Content tags:<br />"; |
| 5172 | print "</td>\n<td>" unless %$ctags; |
| 5173 | print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>"; |
| 5174 | print "</td>\n<td>" if %$ctags; |
| 5175 | print git_show_project_tagcloud($cloud, 48); |
| 5176 | print "</td></tr>"; |
| 5177 | } |
| 5178 | |
Jakub Narebski | 19a8721 | 2006-08-15 23:03:17 +0200 | [diff] [blame] | 5179 | print "</table>\n"; |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 5180 | |
Matt McCutchen | 7e1100e | 2009-02-07 19:00:09 -0500 | [diff] [blame] | 5181 | # If XSS prevention is on, we don't include README.html. |
| 5182 | # TODO: Allow a readme in some safe format. |
| 5183 | if (!$prevent_xss && -s "$projectroot/$project/README.html") { |
Jakub Narebski | 2dcb5e1 | 2008-12-01 19:01:42 +0100 | [diff] [blame] | 5184 | print "<div class=\"title\">readme</div>\n" . |
| 5185 | "<div class=\"readme\">\n"; |
| 5186 | insert_file("$projectroot/$project/README.html"); |
| 5187 | print "\n</div>\n"; # class="readme" |
Petr Baudis | 447ef09 | 2006-10-24 05:23:46 +0200 | [diff] [blame] | 5188 | } |
| 5189 | |
Robert Fitzsimons | 313ce8c | 2006-12-19 12:08:54 +0000 | [diff] [blame] | 5190 | # we need to request one more than 16 (0..15) to check if |
| 5191 | # those 16 are all |
Jakub Narebski | 785cdea | 2007-05-13 12:39:22 +0200 | [diff] [blame] | 5192 | my @commitlist = $head ? parse_commits($head, 17) : (); |
| 5193 | if (@commitlist) { |
| 5194 | git_print_header_div('shortlog'); |
| 5195 | git_shortlog_body(\@commitlist, 0, 15, $refs, |
| 5196 | $#commitlist <= 15 ? undef : |
| 5197 | $cgi->a({-href => href(action=>"shortlog")}, "...")); |
| 5198 | } |
Kay Sievers | ede5e10 | 2005-08-07 20:23:12 +0200 | [diff] [blame] | 5199 | |
Jakub Narebski | 120ddde | 2006-09-19 14:33:22 +0200 | [diff] [blame] | 5200 | if (@taglist) { |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5201 | git_print_header_div('tags'); |
Jakub Narebski | 120ddde | 2006-09-19 14:33:22 +0200 | [diff] [blame] | 5202 | git_tags_body(\@taglist, 0, 15, |
Robert Fitzsimons | 313ce8c | 2006-12-19 12:08:54 +0000 | [diff] [blame] | 5203 | $#taglist <= 15 ? undef : |
Martin Waitz | 1c2a4f5 | 2006-08-16 00:24:30 +0200 | [diff] [blame] | 5204 | $cgi->a({-href => href(action=>"tags")}, "...")); |
Kay Sievers | ede5e10 | 2005-08-07 20:23:12 +0200 | [diff] [blame] | 5205 | } |
Kay Sievers | 0db3797 | 2005-08-07 20:24:35 +0200 | [diff] [blame] | 5206 | |
Jakub Narebski | 120ddde | 2006-09-19 14:33:22 +0200 | [diff] [blame] | 5207 | if (@headlist) { |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5208 | git_print_header_div('heads'); |
Jakub Narebski | 120ddde | 2006-09-19 14:33:22 +0200 | [diff] [blame] | 5209 | git_heads_body(\@headlist, $head, 0, 15, |
Robert Fitzsimons | 313ce8c | 2006-12-19 12:08:54 +0000 | [diff] [blame] | 5210 | $#headlist <= 15 ? undef : |
Martin Waitz | 1c2a4f5 | 2006-08-16 00:24:30 +0200 | [diff] [blame] | 5211 | $cgi->a({-href => href(action=>"heads")}, "...")); |
Kay Sievers | 0db3797 | 2005-08-07 20:24:35 +0200 | [diff] [blame] | 5212 | } |
Jakub Narebski | 9f5dcb8 | 2006-07-31 11:22:13 +0200 | [diff] [blame] | 5213 | |
Giuseppe Bilotta | 00fa6fe | 2010-11-11 13:26:11 +0100 | [diff] [blame^] | 5214 | if (@remotelist) { |
| 5215 | git_print_header_div('remotes'); |
| 5216 | git_heads_body(\@remotelist, $head, 0, 15, |
| 5217 | $#remotelist <= 15 ? undef : |
| 5218 | $cgi->a({-href => href(action=>"remotes")}, "...")); |
| 5219 | } |
| 5220 | |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 5221 | if (@forklist) { |
| 5222 | git_print_header_div('forks'); |
Mike Ralphson | f04f27e | 2008-09-25 18:48:48 +0200 | [diff] [blame] | 5223 | git_project_list_body(\@forklist, 'age', 0, 15, |
Robert Fitzsimons | aaca967 | 2006-12-22 19:38:12 +0000 | [diff] [blame] | 5224 | $#forklist <= 15 ? undef : |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 5225 | $cgi->a({-href => href(action=>"forks")}, "..."), |
Mike Ralphson | f04f27e | 2008-09-25 18:48:48 +0200 | [diff] [blame] | 5226 | 'no_header'); |
Petr Baudis | e30496d | 2006-10-24 05:33:17 +0200 | [diff] [blame] | 5227 | } |
| 5228 | |
Kay Sievers | ede5e10 | 2005-08-07 20:23:12 +0200 | [diff] [blame] | 5229 | git_footer_html(); |
| 5230 | } |
| 5231 | |
Kay Sievers | d8a20ba | 2005-08-07 20:28:53 +0200 | [diff] [blame] | 5232 | sub git_tag { |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5233 | my %tag = parse_tag($hash); |
Jakub Narebski | 198a2a8 | 2007-05-12 21:16:34 +0200 | [diff] [blame] | 5234 | |
| 5235 | if (! %tag) { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5236 | die_error(404, "Unknown tag object"); |
Jakub Narebski | 198a2a8 | 2007-05-12 21:16:34 +0200 | [diff] [blame] | 5237 | } |
| 5238 | |
Anders Kaseorg | d8a9480 | 2010-08-27 13:38:16 -0400 | [diff] [blame] | 5239 | my $head = git_get_head_hash($project); |
| 5240 | git_header_html(); |
| 5241 | git_print_page_nav('','', $head,undef,$head); |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5242 | git_print_header_div('commit', esc_html($tag{'name'}), $hash); |
Kay Sievers | d8a20ba | 2005-08-07 20:28:53 +0200 | [diff] [blame] | 5243 | print "<div class=\"title_text\">\n" . |
Jakub Narebski | 591ebf6 | 2007-11-19 14:16:11 +0100 | [diff] [blame] | 5244 | "<table class=\"object_header\">\n" . |
Kay Sievers | e4669df | 2005-08-08 00:02:39 +0200 | [diff] [blame] | 5245 | "<tr>\n" . |
| 5246 | "<td>object</td>\n" . |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 5247 | "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})}, |
| 5248 | $tag{'object'}) . "</td>\n" . |
| 5249 | "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})}, |
| 5250 | $tag{'type'}) . "</td>\n" . |
Kay Sievers | e4669df | 2005-08-08 00:02:39 +0200 | [diff] [blame] | 5251 | "</tr>\n"; |
Kay Sievers | d8a20ba | 2005-08-07 20:28:53 +0200 | [diff] [blame] | 5252 | if (defined($tag{'author'})) { |
Giuseppe Bilotta | ba92473 | 2009-06-30 00:00:50 +0200 | [diff] [blame] | 5253 | git_print_authorship_rows(\%tag, 'author'); |
Kay Sievers | d8a20ba | 2005-08-07 20:28:53 +0200 | [diff] [blame] | 5254 | } |
| 5255 | print "</table>\n\n" . |
| 5256 | "</div>\n"; |
| 5257 | print "<div class=\"page_body\">"; |
| 5258 | my $comment = $tag{'comment'}; |
| 5259 | foreach my $line (@$comment) { |
Junio C Hamano | 7002243 | 2006-11-24 14:04:01 -0800 | [diff] [blame] | 5260 | chomp $line; |
Jakub Narebski | 793c400 | 2006-11-24 22:25:50 +0100 | [diff] [blame] | 5261 | print esc_html($line, -nbsp=>1) . "<br/>\n"; |
Kay Sievers | d8a20ba | 2005-08-07 20:28:53 +0200 | [diff] [blame] | 5262 | } |
| 5263 | print "</div>\n"; |
| 5264 | git_footer_html(); |
| 5265 | } |
| 5266 | |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 5267 | sub git_blame_common { |
| 5268 | my $format = shift || 'porcelain'; |
Jakub Narebski | c4ccf61 | 2009-09-01 13:39:19 +0200 | [diff] [blame] | 5269 | if ($format eq 'porcelain' && $cgi->param('js')) { |
| 5270 | $format = 'incremental'; |
| 5271 | $action = 'blame_incremental'; # for page title etc |
| 5272 | } |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 5273 | |
Jakub Narebski | d2ce10d | 2008-12-09 23:48:51 +0100 | [diff] [blame] | 5274 | # permissions |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 5275 | gitweb_check_feature('blame') |
Jakub Narebski | d2ce10d | 2008-12-09 23:48:51 +0100 | [diff] [blame] | 5276 | or die_error(403, "Blame view not allowed"); |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5277 | |
Jakub Narebski | d2ce10d | 2008-12-09 23:48:51 +0100 | [diff] [blame] | 5278 | # error checking |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5279 | die_error(400, "No file name given") unless $file_name; |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5280 | $hash_base ||= git_get_head_hash($project); |
Jakub Narebski | d2ce10d | 2008-12-09 23:48:51 +0100 | [diff] [blame] | 5281 | die_error(404, "Couldn't find base commit") unless $hash_base; |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5282 | my %co = parse_commit($hash_base) |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5283 | or die_error(404, "Commit not found"); |
Jakub Narebski | d2ce10d | 2008-12-09 23:48:51 +0100 | [diff] [blame] | 5284 | my $ftype = "blob"; |
Luben Tuikov | 1f2857e | 2006-07-23 13:34:55 -0700 | [diff] [blame] | 5285 | if (!defined $hash) { |
| 5286 | $hash = git_get_hash_by_path($hash_base, $file_name, "blob") |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5287 | or die_error(404, "Error looking up file"); |
Jakub Narebski | d2ce10d | 2008-12-09 23:48:51 +0100 | [diff] [blame] | 5288 | } else { |
| 5289 | $ftype = git_get_type($hash); |
| 5290 | if ($ftype !~ "blob") { |
| 5291 | die_error(400, "Object is not a blob"); |
| 5292 | } |
Luben Tuikov | 1f2857e | 2006-07-23 13:34:55 -0700 | [diff] [blame] | 5293 | } |
Jakub Narebski | d2ce10d | 2008-12-09 23:48:51 +0100 | [diff] [blame] | 5294 | |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 5295 | my $fd; |
| 5296 | if ($format eq 'incremental') { |
| 5297 | # get file contents (as base) |
| 5298 | open $fd, "-|", git_cmd(), 'cat-file', 'blob', $hash |
| 5299 | or die_error(500, "Open git-cat-file failed"); |
| 5300 | } elsif ($format eq 'data') { |
| 5301 | # run git-blame --incremental |
| 5302 | open $fd, "-|", git_cmd(), "blame", "--incremental", |
| 5303 | $hash_base, "--", $file_name |
| 5304 | or die_error(500, "Open git-blame --incremental failed"); |
| 5305 | } else { |
| 5306 | # run git-blame --porcelain |
| 5307 | open $fd, "-|", git_cmd(), "blame", '-p', |
| 5308 | $hash_base, '--', $file_name |
| 5309 | or die_error(500, "Open git-blame --porcelain failed"); |
| 5310 | } |
| 5311 | |
| 5312 | # incremental blame data returns early |
| 5313 | if ($format eq 'data') { |
| 5314 | print $cgi->header( |
| 5315 | -type=>"text/plain", -charset => "utf-8", |
| 5316 | -status=> "200 OK"); |
| 5317 | local $| = 1; # output autoflush |
| 5318 | print while <$fd>; |
| 5319 | close $fd |
| 5320 | or print "ERROR $!\n"; |
| 5321 | |
| 5322 | print 'END'; |
| 5323 | if (defined $t0 && gitweb_check_feature('timed')) { |
| 5324 | print ' '. |
| 5325 | Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]). |
| 5326 | ' '.$number_of_git_cmds; |
| 5327 | } |
| 5328 | print "\n"; |
| 5329 | |
| 5330 | return; |
| 5331 | } |
Jakub Narebski | d2ce10d | 2008-12-09 23:48:51 +0100 | [diff] [blame] | 5332 | |
| 5333 | # page header |
Luben Tuikov | 1f2857e | 2006-07-23 13:34:55 -0700 | [diff] [blame] | 5334 | git_header_html(); |
Jakub Narebski | 0d83ddc | 2006-07-30 15:01:07 +0200 | [diff] [blame] | 5335 | my $formats_nav = |
Jakub Narebski | a3823e5 | 2007-11-01 13:06:29 +0100 | [diff] [blame] | 5336 | $cgi->a({-href => href(action=>"blob", -replay=>1)}, |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 5337 | "blob") . |
Jakub Narebski | 87e573f | 2009-12-01 17:54:26 +0100 | [diff] [blame] | 5338 | " | "; |
| 5339 | if ($format eq 'incremental') { |
| 5340 | $formats_nav .= |
| 5341 | $cgi->a({-href => href(action=>"blame", javascript=>0, -replay=>1)}, |
| 5342 | "blame") . " (non-incremental)"; |
| 5343 | } else { |
| 5344 | $formats_nav .= |
| 5345 | $cgi->a({-href => href(action=>"blame_incremental", -replay=>1)}, |
| 5346 | "blame") . " (incremental)"; |
| 5347 | } |
| 5348 | $formats_nav .= |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 5349 | " | " . |
Jakub Narebski | a3823e5 | 2007-11-01 13:06:29 +0100 | [diff] [blame] | 5350 | $cgi->a({-href => href(action=>"history", -replay=>1)}, |
| 5351 | "history") . |
Petr Baudis | cae1862 | 2006-09-22 03:19:41 +0200 | [diff] [blame] | 5352 | " | " . |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 5353 | $cgi->a({-href => href(action=>$action, file_name=>$file_name)}, |
Petr Baudis | f35274d | 2006-09-22 03:19:53 +0200 | [diff] [blame] | 5354 | "HEAD"); |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5355 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); |
| 5356 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); |
Luben Tuikov | 59fb1c9 | 2006-08-17 10:39:29 -0700 | [diff] [blame] | 5357 | git_print_page_path($file_name, $ftype, $hash_base); |
Jakub Narebski | d2ce10d | 2008-12-09 23:48:51 +0100 | [diff] [blame] | 5358 | |
| 5359 | # page body |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 5360 | if ($format eq 'incremental') { |
| 5361 | print "<noscript>\n<div class=\"error\"><center><b>\n". |
| 5362 | "This page requires JavaScript to run.\n Use ". |
Jakub Narebski | c4ccf61 | 2009-09-01 13:39:19 +0200 | [diff] [blame] | 5363 | $cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)}, |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 5364 | 'this page'). |
| 5365 | " instead.\n". |
| 5366 | "</b></center></div>\n</noscript>\n"; |
| 5367 | |
| 5368 | print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!; |
| 5369 | } |
| 5370 | |
| 5371 | print qq!<div class="page_body">\n!; |
| 5372 | print qq!<div id="progress_info">... / ...</div>\n! |
| 5373 | if ($format eq 'incremental'); |
| 5374 | print qq!<table id="blame_table" class="blame" width="100%">\n!. |
| 5375 | #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!. |
| 5376 | qq!<thead>\n!. |
| 5377 | qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!. |
| 5378 | qq!</thead>\n!. |
| 5379 | qq!<tbody>\n!; |
| 5380 | |
Jakub Narebski | aef3768 | 2009-07-25 00:44:06 +0200 | [diff] [blame] | 5381 | my @rev_color = qw(light dark); |
Luben Tuikov | cc1bf97 | 2006-07-23 13:37:53 -0700 | [diff] [blame] | 5382 | my $num_colors = scalar(@rev_color); |
| 5383 | my $current_color = 0; |
Jakub Narebski | d2ce10d | 2008-12-09 23:48:51 +0100 | [diff] [blame] | 5384 | |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 5385 | if ($format eq 'incremental') { |
| 5386 | my $color_class = $rev_color[$current_color]; |
| 5387 | |
| 5388 | #contents of a file |
| 5389 | my $linenr = 0; |
| 5390 | LINE: |
| 5391 | while (my $line = <$fd>) { |
| 5392 | chomp $line; |
| 5393 | $linenr++; |
| 5394 | |
| 5395 | print qq!<tr id="l$linenr" class="$color_class">!. |
| 5396 | qq!<td class="sha1"><a href=""> </a></td>!. |
| 5397 | qq!<td class="linenr">!. |
| 5398 | qq!<a class="linenr" href="">$linenr</a></td>!; |
| 5399 | print qq!<td class="pre">! . esc_html($line) . "</td>\n"; |
| 5400 | print qq!</tr>\n!; |
Junio C Hamano | eeef88c | 2006-10-05 13:55:58 -0700 | [diff] [blame] | 5401 | } |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 5402 | |
| 5403 | } else { # porcelain, i.e. ordinary blame |
| 5404 | my %metainfo = (); # saves information about commits |
| 5405 | |
| 5406 | # blame data |
| 5407 | LINE: |
| 5408 | while (my $line = <$fd>) { |
| 5409 | chomp $line; |
| 5410 | # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>] |
| 5411 | # no <lines in group> for subsequent lines in group of lines |
| 5412 | my ($full_rev, $orig_lineno, $lineno, $group_size) = |
| 5413 | ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/); |
| 5414 | if (!exists $metainfo{$full_rev}) { |
| 5415 | $metainfo{$full_rev} = { 'nprevious' => 0 }; |
Junio C Hamano | eeef88c | 2006-10-05 13:55:58 -0700 | [diff] [blame] | 5416 | } |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 5417 | my $meta = $metainfo{$full_rev}; |
| 5418 | my $data; |
| 5419 | while ($data = <$fd>) { |
| 5420 | chomp $data; |
| 5421 | last if ($data =~ s/^\t//); # contents of line |
| 5422 | if ($data =~ /^(\S+)(?: (.*))?$/) { |
| 5423 | $meta->{$1} = $2 unless exists $meta->{$1}; |
| 5424 | } |
| 5425 | if ($data =~ /^previous /) { |
| 5426 | $meta->{'nprevious'}++; |
Jakub Narebski | a36817b | 2009-07-25 00:44:05 +0200 | [diff] [blame] | 5427 | } |
| 5428 | } |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 5429 | my $short_rev = substr($full_rev, 0, 8); |
| 5430 | my $author = $meta->{'author'}; |
| 5431 | my %date = |
| 5432 | parse_date($meta->{'author-time'}, $meta->{'author-tz'}); |
| 5433 | my $date = $date{'iso-tz'}; |
| 5434 | if ($group_size) { |
| 5435 | $current_color = ($current_color + 1) % $num_colors; |
| 5436 | } |
| 5437 | my $tr_class = $rev_color[$current_color]; |
| 5438 | $tr_class .= ' boundary' if (exists $meta->{'boundary'}); |
| 5439 | $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0); |
| 5440 | $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1); |
| 5441 | print "<tr id=\"l$lineno\" class=\"$tr_class\">\n"; |
| 5442 | if ($group_size) { |
| 5443 | print "<td class=\"sha1\""; |
| 5444 | print " title=\"". esc_html($author) . ", $date\""; |
| 5445 | print " rowspan=\"$group_size\"" if ($group_size > 1); |
| 5446 | print ">"; |
| 5447 | print $cgi->a({-href => href(action=>"commit", |
| 5448 | hash=>$full_rev, |
| 5449 | file_name=>$file_name)}, |
| 5450 | esc_html($short_rev)); |
| 5451 | if ($group_size >= 2) { |
| 5452 | my @author_initials = ($author =~ /\b([[:upper:]])\B/g); |
| 5453 | if (@author_initials) { |
| 5454 | print "<br />" . |
| 5455 | esc_html(join('', @author_initials)); |
| 5456 | # or join('.', ...) |
| 5457 | } |
| 5458 | } |
| 5459 | print "</td>\n"; |
| 5460 | } |
| 5461 | # 'previous' <sha1 of parent commit> <filename at commit> |
| 5462 | if (exists $meta->{'previous'} && |
| 5463 | $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) { |
| 5464 | $meta->{'parent'} = $1; |
| 5465 | $meta->{'file_parent'} = unquote($2); |
| 5466 | } |
| 5467 | my $linenr_commit = |
| 5468 | exists($meta->{'parent'}) ? |
| 5469 | $meta->{'parent'} : $full_rev; |
| 5470 | my $linenr_filename = |
| 5471 | exists($meta->{'file_parent'}) ? |
| 5472 | $meta->{'file_parent'} : unquote($meta->{'filename'}); |
| 5473 | my $blamed = href(action => 'blame', |
| 5474 | file_name => $linenr_filename, |
| 5475 | hash_base => $linenr_commit); |
| 5476 | print "<td class=\"linenr\">"; |
| 5477 | print $cgi->a({ -href => "$blamed#l$orig_lineno", |
| 5478 | -class => "linenr" }, |
| 5479 | esc_html($lineno)); |
| 5480 | print "</td>"; |
| 5481 | print "<td class=\"pre\">" . esc_html($data) . "</td>\n"; |
| 5482 | print "</tr>\n"; |
| 5483 | } # end while |
| 5484 | |
Luben Tuikov | 1f2857e | 2006-07-23 13:34:55 -0700 | [diff] [blame] | 5485 | } |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 5486 | |
| 5487 | # footer |
| 5488 | print "</tbody>\n". |
| 5489 | "</table>\n"; # class="blame" |
| 5490 | print "</div>\n"; # class="blame_body" |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 5491 | close $fd |
| 5492 | or print "Reading blob failed\n"; |
Jakub Narebski | d2ce10d | 2008-12-09 23:48:51 +0100 | [diff] [blame] | 5493 | |
Luben Tuikov | 1f2857e | 2006-07-23 13:34:55 -0700 | [diff] [blame] | 5494 | git_footer_html(); |
| 5495 | } |
| 5496 | |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 5497 | sub git_blame { |
| 5498 | git_blame_common(); |
| 5499 | } |
| 5500 | |
| 5501 | sub git_blame_incremental { |
| 5502 | git_blame_common('incremental'); |
| 5503 | } |
| 5504 | |
| 5505 | sub git_blame_data { |
| 5506 | git_blame_common('data'); |
| 5507 | } |
| 5508 | |
Kay Sievers | ede5e10 | 2005-08-07 20:23:12 +0200 | [diff] [blame] | 5509 | sub git_tags { |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5510 | my $head = git_get_head_hash($project); |
Kay Sievers | ede5e10 | 2005-08-07 20:23:12 +0200 | [diff] [blame] | 5511 | git_header_html(); |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5512 | git_print_page_nav('','', $head,undef,$head); |
| 5513 | git_print_header_div('summary', $project); |
Jakub Narebski | 27fb8c4 | 2006-07-30 20:32:01 +0200 | [diff] [blame] | 5514 | |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 5515 | my @tagslist = git_get_tags_list(); |
| 5516 | if (@tagslist) { |
| 5517 | git_tags_body(\@tagslist); |
Kay Sievers | ede5e10 | 2005-08-07 20:23:12 +0200 | [diff] [blame] | 5518 | } |
Kay Sievers | ede5e10 | 2005-08-07 20:23:12 +0200 | [diff] [blame] | 5519 | git_footer_html(); |
| 5520 | } |
| 5521 | |
Kay Sievers | d8f1c5c | 2005-10-04 01:12:47 +0200 | [diff] [blame] | 5522 | sub git_heads { |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5523 | my $head = git_get_head_hash($project); |
Kay Sievers | 0db3797 | 2005-08-07 20:24:35 +0200 | [diff] [blame] | 5524 | git_header_html(); |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5525 | git_print_page_nav('','', $head,undef,$head); |
| 5526 | git_print_header_div('summary', $project); |
Jakub Narebski | 27fb8c4 | 2006-07-30 20:32:01 +0200 | [diff] [blame] | 5527 | |
Jakub Narebski | cd14640 | 2006-11-02 20:23:11 +0100 | [diff] [blame] | 5528 | my @headslist = git_get_heads_list(); |
| 5529 | if (@headslist) { |
| 5530 | git_heads_body(\@headslist, $head); |
Kay Sievers | 0db3797 | 2005-08-07 20:24:35 +0200 | [diff] [blame] | 5531 | } |
Kay Sievers | 0db3797 | 2005-08-07 20:24:35 +0200 | [diff] [blame] | 5532 | git_footer_html(); |
| 5533 | } |
| 5534 | |
Giuseppe Bilotta | 00fa6fe | 2010-11-11 13:26:11 +0100 | [diff] [blame^] | 5535 | sub git_remotes { |
| 5536 | gitweb_check_feature('remote_heads') |
| 5537 | or die_error(403, "Remote heads view is disabled"); |
| 5538 | |
| 5539 | my $head = git_get_head_hash($project); |
| 5540 | git_header_html(); |
| 5541 | git_print_page_nav('','', $head,undef,$head); |
| 5542 | git_print_header_div('summary', $project); |
| 5543 | |
| 5544 | my @remotelist = git_get_heads_list(undef, 'remotes'); |
| 5545 | if (@remotelist) { |
| 5546 | git_heads_body(\@remotelist, $head); |
| 5547 | } |
| 5548 | git_footer_html(); |
| 5549 | } |
| 5550 | |
Luben Tuikov | 930cf7d | 2006-07-09 20:18:57 -0700 | [diff] [blame] | 5551 | sub git_blob_plain { |
Jakub Narebski | 7f718e8 | 2008-06-03 16:47:10 +0200 | [diff] [blame] | 5552 | my $type = shift; |
Jakub Narebski | f2e7330 | 2006-08-26 19:14:25 +0200 | [diff] [blame] | 5553 | my $expires; |
Jakub Narebski | f2e7330 | 2006-08-26 19:14:25 +0200 | [diff] [blame] | 5554 | |
Luben Tuikov | cff0771 | 2006-07-23 13:28:55 -0700 | [diff] [blame] | 5555 | if (!defined $hash) { |
Jakub Narebski | 5be01bc | 2006-07-29 22:43:40 +0200 | [diff] [blame] | 5556 | if (defined $file_name) { |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5557 | my $base = $hash_base || git_get_head_hash($project); |
Jakub Narebski | 5be01bc | 2006-07-29 22:43:40 +0200 | [diff] [blame] | 5558 | $hash = git_get_hash_by_path($base, $file_name, "blob") |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5559 | or die_error(404, "Cannot find file"); |
Jakub Narebski | 5be01bc | 2006-07-29 22:43:40 +0200 | [diff] [blame] | 5560 | } else { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5561 | die_error(400, "No file name defined"); |
Jakub Narebski | 5be01bc | 2006-07-29 22:43:40 +0200 | [diff] [blame] | 5562 | } |
Martin Waitz | 800764c | 2006-09-16 23:09:02 +0200 | [diff] [blame] | 5563 | } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) { |
| 5564 | # blobs defined by non-textual hash id's can be cached |
| 5565 | $expires = "+1d"; |
Jakub Narebski | 5be01bc | 2006-07-29 22:43:40 +0200 | [diff] [blame] | 5566 | } |
Martin Waitz | 800764c | 2006-09-16 23:09:02 +0200 | [diff] [blame] | 5567 | |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 5568 | open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5569 | or die_error(500, "Open git-cat-file blob '$hash' failed"); |
Luben Tuikov | 930cf7d | 2006-07-09 20:18:57 -0700 | [diff] [blame] | 5570 | |
Jakub Narebski | 7f718e8 | 2008-06-03 16:47:10 +0200 | [diff] [blame] | 5571 | # content-type (can include charset) |
| 5572 | $type = blob_contenttype($fd, $file_name, $type); |
Luben Tuikov | 930cf7d | 2006-07-09 20:18:57 -0700 | [diff] [blame] | 5573 | |
Jakub Narebski | 7f718e8 | 2008-06-03 16:47:10 +0200 | [diff] [blame] | 5574 | # "save as" filename, even when no $file_name is given |
Luben Tuikov | 930cf7d | 2006-07-09 20:18:57 -0700 | [diff] [blame] | 5575 | my $save_as = "$hash"; |
| 5576 | if (defined $file_name) { |
| 5577 | $save_as = $file_name; |
| 5578 | } elsif ($type =~ m/^text\//) { |
| 5579 | $save_as .= '.txt'; |
| 5580 | } |
| 5581 | |
Matt McCutchen | 7e1100e | 2009-02-07 19:00:09 -0500 | [diff] [blame] | 5582 | # With XSS prevention on, blobs of all types except a few known safe |
| 5583 | # ones are served with "Content-Disposition: attachment" to make sure |
| 5584 | # they don't run in our security domain. For certain image types, |
| 5585 | # blob view writes an <img> tag referring to blob_plain view, and we |
| 5586 | # want to be sure not to break that by serving the image as an |
| 5587 | # attachment (though Firefox 3 doesn't seem to care). |
| 5588 | my $sandbox = $prevent_xss && |
| 5589 | $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!; |
| 5590 | |
Jakub Narebski | f2e7330 | 2006-08-26 19:14:25 +0200 | [diff] [blame] | 5591 | print $cgi->header( |
Jakub Narebski | 7f718e8 | 2008-06-03 16:47:10 +0200 | [diff] [blame] | 5592 | -type => $type, |
| 5593 | -expires => $expires, |
Matt McCutchen | 7e1100e | 2009-02-07 19:00:09 -0500 | [diff] [blame] | 5594 | -content_disposition => |
| 5595 | ($sandbox ? 'attachment' : 'inline') |
| 5596 | . '; filename="' . $save_as . '"'); |
Jakub Narebski | 34122b5 | 2009-05-11 03:29:40 +0200 | [diff] [blame] | 5597 | local $/ = undef; |
Luben Tuikov | 930cf7d | 2006-07-09 20:18:57 -0700 | [diff] [blame] | 5598 | binmode STDOUT, ':raw'; |
| 5599 | print <$fd>; |
| 5600 | binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi |
Luben Tuikov | 930cf7d | 2006-07-09 20:18:57 -0700 | [diff] [blame] | 5601 | close $fd; |
| 5602 | } |
| 5603 | |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 5604 | sub git_blob { |
Jakub Narebski | f2e7330 | 2006-08-26 19:14:25 +0200 | [diff] [blame] | 5605 | my $expires; |
Jakub Narebski | f2e7330 | 2006-08-26 19:14:25 +0200 | [diff] [blame] | 5606 | |
Luben Tuikov | cff0771 | 2006-07-23 13:28:55 -0700 | [diff] [blame] | 5607 | if (!defined $hash) { |
Jakub Narebski | 5be01bc | 2006-07-29 22:43:40 +0200 | [diff] [blame] | 5608 | if (defined $file_name) { |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5609 | my $base = $hash_base || git_get_head_hash($project); |
Jakub Narebski | 5be01bc | 2006-07-29 22:43:40 +0200 | [diff] [blame] | 5610 | $hash = git_get_hash_by_path($base, $file_name, "blob") |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5611 | or die_error(404, "Cannot find file"); |
Jakub Narebski | 5be01bc | 2006-07-29 22:43:40 +0200 | [diff] [blame] | 5612 | } else { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5613 | die_error(400, "No file name defined"); |
Jakub Narebski | 5be01bc | 2006-07-29 22:43:40 +0200 | [diff] [blame] | 5614 | } |
Martin Waitz | 800764c | 2006-09-16 23:09:02 +0200 | [diff] [blame] | 5615 | } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) { |
| 5616 | # blobs defined by non-textual hash id's can be cached |
| 5617 | $expires = "+1d"; |
Jakub Narebski | 5be01bc | 2006-07-29 22:43:40 +0200 | [diff] [blame] | 5618 | } |
Martin Waitz | 800764c | 2006-09-16 23:09:02 +0200 | [diff] [blame] | 5619 | |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 5620 | my $have_blame = gitweb_check_feature('blame'); |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 5621 | open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5622 | or die_error(500, "Couldn't cat $file_name, $hash"); |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5623 | my $mimetype = blob_mimetype($fd, $file_name); |
Johannes Schindelin | b331fe5 | 2010-04-27 21:34:44 +0200 | [diff] [blame] | 5624 | # use 'blob_plain' (aka 'raw') view for files that cannot be displayed |
Jakub Narebski | dfa7c7d | 2007-12-15 15:41:49 +0100 | [diff] [blame] | 5625 | if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B $fd) { |
Luben Tuikov | 930cf7d | 2006-07-09 20:18:57 -0700 | [diff] [blame] | 5626 | close $fd; |
| 5627 | return git_blob_plain($mimetype); |
| 5628 | } |
Jakub Narebski | 5a4cf33 | 2006-12-04 23:47:22 +0100 | [diff] [blame] | 5629 | # we can have blame only for text/* mimetype |
| 5630 | $have_blame &&= ($mimetype =~ m!^text/!); |
| 5631 | |
Jakub Narebski | 592ea41 | 2010-04-27 21:34:45 +0200 | [diff] [blame] | 5632 | my $highlight = gitweb_check_feature('highlight'); |
| 5633 | my $syntax = guess_file_syntax($highlight, $mimetype, $file_name); |
| 5634 | $fd = run_highlighter($fd, $highlight, $syntax) |
| 5635 | if $syntax; |
Johannes Schindelin | b331fe5 | 2010-04-27 21:34:44 +0200 | [diff] [blame] | 5636 | |
Jakub Narebski | f2e7330 | 2006-08-26 19:14:25 +0200 | [diff] [blame] | 5637 | git_header_html(undef, $expires); |
Jakub Narebski | 0d83ddc | 2006-07-30 15:01:07 +0200 | [diff] [blame] | 5638 | my $formats_nav = ''; |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5639 | if (defined $hash_base && (my %co = parse_commit($hash_base))) { |
Kay Sievers | 9312944 | 2005-10-17 03:27:54 +0200 | [diff] [blame] | 5640 | if (defined $file_name) { |
Florian Forster | 5996ca0 | 2006-06-12 10:31:57 +0200 | [diff] [blame] | 5641 | if ($have_blame) { |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 5642 | $formats_nav .= |
Jakub Narebski | a3823e5 | 2007-11-01 13:06:29 +0100 | [diff] [blame] | 5643 | $cgi->a({-href => href(action=>"blame", -replay=>1)}, |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 5644 | "blame") . |
| 5645 | " | "; |
Florian Forster | 5996ca0 | 2006-06-12 10:31:57 +0200 | [diff] [blame] | 5646 | } |
Jakub Narebski | 0d83ddc | 2006-07-30 15:01:07 +0200 | [diff] [blame] | 5647 | $formats_nav .= |
Jakub Narebski | a3823e5 | 2007-11-01 13:06:29 +0100 | [diff] [blame] | 5648 | $cgi->a({-href => href(action=>"history", -replay=>1)}, |
Petr Baudis | cae1862 | 2006-09-22 03:19:41 +0200 | [diff] [blame] | 5649 | "history") . |
| 5650 | " | " . |
Jakub Narebski | a3823e5 | 2007-11-01 13:06:29 +0100 | [diff] [blame] | 5651 | $cgi->a({-href => href(action=>"blob_plain", -replay=>1)}, |
Petr Baudis | 35329cc | 2006-09-22 03:19:50 +0200 | [diff] [blame] | 5652 | "raw") . |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 5653 | " | " . |
| 5654 | $cgi->a({-href => href(action=>"blob", |
| 5655 | hash_base=>"HEAD", file_name=>$file_name)}, |
Petr Baudis | f35274d | 2006-09-22 03:19:53 +0200 | [diff] [blame] | 5656 | "HEAD"); |
Kay Sievers | 9312944 | 2005-10-17 03:27:54 +0200 | [diff] [blame] | 5657 | } else { |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 5658 | $formats_nav .= |
Jakub Narebski | a3823e5 | 2007-11-01 13:06:29 +0100 | [diff] [blame] | 5659 | $cgi->a({-href => href(action=>"blob_plain", -replay=>1)}, |
| 5660 | "raw"); |
Kay Sievers | 9312944 | 2005-10-17 03:27:54 +0200 | [diff] [blame] | 5661 | } |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5662 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); |
| 5663 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 5664 | } else { |
| 5665 | print "<div class=\"page_nav\">\n" . |
| 5666 | "<br/><br/></div>\n" . |
| 5667 | "<div class=\"title\">$hash</div>\n"; |
| 5668 | } |
Luben Tuikov | 59fb1c9 | 2006-08-17 10:39:29 -0700 | [diff] [blame] | 5669 | git_print_page_path($file_name, "blob", $hash_base); |
Kay Sievers | c07ad4b | 2005-08-07 20:22:44 +0200 | [diff] [blame] | 5670 | print "<div class=\"page_body\">\n"; |
Jakub Narebski | dfa7c7d | 2007-12-15 15:41:49 +0100 | [diff] [blame] | 5671 | if ($mimetype =~ m!^image/!) { |
Jakub Narebski | 5a4cf33 | 2006-12-04 23:47:22 +0100 | [diff] [blame] | 5672 | print qq!<img type="$mimetype"!; |
| 5673 | if ($file_name) { |
| 5674 | print qq! alt="$file_name" title="$file_name"!; |
| 5675 | } |
| 5676 | print qq! src="! . |
| 5677 | href(action=>"blob_plain", hash=>$hash, |
| 5678 | hash_base=>$hash_base, file_name=>$file_name) . |
| 5679 | qq!" />\n!; |
Jakub Narebski | dfa7c7d | 2007-12-15 15:41:49 +0100 | [diff] [blame] | 5680 | } else { |
| 5681 | my $nr; |
| 5682 | while (my $line = <$fd>) { |
| 5683 | chomp $line; |
| 5684 | $nr++; |
| 5685 | $line = untabify($line); |
Jakub Narebski | 592ea41 | 2010-04-27 21:34:45 +0200 | [diff] [blame] | 5686 | printf qq!<div class="pre"><a id="l%i" href="%s#l%i" class="linenr">%4i</a> %s</div>\n!, |
| 5687 | $nr, href(-replay => 1), $nr, $nr, $syntax ? $line : esc_html($line, -nbsp=>1); |
Jakub Narebski | dfa7c7d | 2007-12-15 15:41:49 +0100 | [diff] [blame] | 5688 | } |
Kay Sievers | 161332a | 2005-08-07 19:49:46 +0200 | [diff] [blame] | 5689 | } |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 5690 | close $fd |
| 5691 | or print "Reading blob failed.\n"; |
Kay Sievers | fbb592a | 2005-08-07 20:12:11 +0200 | [diff] [blame] | 5692 | print "</div>"; |
Kay Sievers | 12a88f2 | 2005-08-07 20:02:47 +0200 | [diff] [blame] | 5693 | git_footer_html(); |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 5694 | } |
| 5695 | |
| 5696 | sub git_tree { |
Luben Tuikov | 6f7ea5f | 2006-09-29 09:57:43 -0700 | [diff] [blame] | 5697 | if (!defined $hash_base) { |
| 5698 | $hash_base = "HEAD"; |
| 5699 | } |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 5700 | if (!defined $hash) { |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 5701 | if (defined $file_name) { |
Luben Tuikov | 6f7ea5f | 2006-09-29 09:57:43 -0700 | [diff] [blame] | 5702 | $hash = git_get_hash_by_path($hash_base, $file_name, "tree"); |
| 5703 | } else { |
| 5704 | $hash = $hash_base; |
Kay Sievers | 10dba28 | 2005-08-07 20:25:27 +0200 | [diff] [blame] | 5705 | } |
Kay Sievers | e925f38 | 2005-08-07 20:23:35 +0200 | [diff] [blame] | 5706 | } |
Jakub Narebski | 2d7a353 | 2008-10-02 16:50:04 +0200 | [diff] [blame] | 5707 | die_error(404, "No such tree") unless defined($hash); |
Jakub Narebski | 34122b5 | 2009-05-11 03:29:40 +0200 | [diff] [blame] | 5708 | |
Jakub Narebski | e4b48ea | 2009-09-07 14:40:00 +0200 | [diff] [blame] | 5709 | my $show_sizes = gitweb_check_feature('show-sizes'); |
| 5710 | my $have_blame = gitweb_check_feature('blame'); |
| 5711 | |
Jakub Narebski | 34122b5 | 2009-05-11 03:29:40 +0200 | [diff] [blame] | 5712 | my @entries = (); |
| 5713 | { |
| 5714 | local $/ = "\0"; |
Jakub Narebski | e4b48ea | 2009-09-07 14:40:00 +0200 | [diff] [blame] | 5715 | open my $fd, "-|", git_cmd(), "ls-tree", '-z', |
| 5716 | ($show_sizes ? '-l' : ()), @extra_options, $hash |
Jakub Narebski | 34122b5 | 2009-05-11 03:29:40 +0200 | [diff] [blame] | 5717 | or die_error(500, "Open git-ls-tree failed"); |
| 5718 | @entries = map { chomp; $_ } <$fd>; |
| 5719 | close $fd |
| 5720 | or die_error(404, "Reading tree failed"); |
| 5721 | } |
Kay Sievers | d63577d | 2005-08-07 20:18:13 +0200 | [diff] [blame] | 5722 | |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5723 | my $refs = git_get_references(); |
| 5724 | my $ref = format_ref_marker($refs, $hash_base); |
Kay Sievers | 12a88f2 | 2005-08-07 20:02:47 +0200 | [diff] [blame] | 5725 | git_header_html(); |
Jakub Narebski | 300454f | 2006-10-21 17:53:09 +0200 | [diff] [blame] | 5726 | my $basedir = ''; |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5727 | if (defined $hash_base && (my %co = parse_commit($hash_base))) { |
Petr Baudis | cae1862 | 2006-09-22 03:19:41 +0200 | [diff] [blame] | 5728 | my @views_nav = (); |
| 5729 | if (defined $file_name) { |
| 5730 | push @views_nav, |
Jakub Narebski | a3823e5 | 2007-11-01 13:06:29 +0100 | [diff] [blame] | 5731 | $cgi->a({-href => href(action=>"history", -replay=>1)}, |
Petr Baudis | cae1862 | 2006-09-22 03:19:41 +0200 | [diff] [blame] | 5732 | "history"), |
| 5733 | $cgi->a({-href => href(action=>"tree", |
| 5734 | hash_base=>"HEAD", file_name=>$file_name)}, |
Petr Baudis | f35274d | 2006-09-22 03:19:53 +0200 | [diff] [blame] | 5735 | "HEAD"), |
Petr Baudis | cae1862 | 2006-09-22 03:19:41 +0200 | [diff] [blame] | 5736 | } |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 5737 | my $snapshot_links = format_snapshot_links($hash); |
| 5738 | if (defined $snapshot_links) { |
Petr Baudis | cae1862 | 2006-09-22 03:19:41 +0200 | [diff] [blame] | 5739 | # FIXME: Should be available when we have no hash base as well. |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 5740 | push @views_nav, $snapshot_links; |
Petr Baudis | cae1862 | 2006-09-22 03:19:41 +0200 | [diff] [blame] | 5741 | } |
Jakub Narebski | e4b48ea | 2009-09-07 14:40:00 +0200 | [diff] [blame] | 5742 | git_print_page_nav('tree','', $hash_base, undef, undef, |
| 5743 | join(' | ', @views_nav)); |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5744 | git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base); |
Kay Sievers | d63577d | 2005-08-07 20:18:13 +0200 | [diff] [blame] | 5745 | } else { |
Jakub Narebski | fa70200 | 2006-08-31 00:35:07 +0200 | [diff] [blame] | 5746 | undef $hash_base; |
Kay Sievers | d63577d | 2005-08-07 20:18:13 +0200 | [diff] [blame] | 5747 | print "<div class=\"page_nav\">\n"; |
| 5748 | print "<br/><br/></div>\n"; |
| 5749 | print "<div class=\"title\">$hash</div>\n"; |
| 5750 | } |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 5751 | if (defined $file_name) { |
Jakub Narebski | 300454f | 2006-10-21 17:53:09 +0200 | [diff] [blame] | 5752 | $basedir = $file_name; |
| 5753 | if ($basedir ne '' && substr($basedir, -1) ne '/') { |
| 5754 | $basedir .= '/'; |
| 5755 | } |
Jakub Narebski | 2d7a353 | 2008-10-02 16:50:04 +0200 | [diff] [blame] | 5756 | git_print_page_path($file_name, 'tree', $hash_base); |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 5757 | } |
Kay Sievers | fbb592a | 2005-08-07 20:12:11 +0200 | [diff] [blame] | 5758 | print "<div class=\"page_body\">\n"; |
Jakub Narebski | 591ebf6 | 2007-11-19 14:16:11 +0100 | [diff] [blame] | 5759 | print "<table class=\"tree\">\n"; |
Luben Tuikov | 6dd36ac | 2006-09-28 16:47:50 -0700 | [diff] [blame] | 5760 | my $alternate = 1; |
Jakub Narebski | b6b7fc7 | 2006-10-21 17:54:44 +0200 | [diff] [blame] | 5761 | # '..' (top directory) link if possible |
| 5762 | if (defined $hash_base && |
| 5763 | defined $file_name && $file_name =~ m![^/]+$!) { |
| 5764 | if ($alternate) { |
| 5765 | print "<tr class=\"dark\">\n"; |
| 5766 | } else { |
| 5767 | print "<tr class=\"light\">\n"; |
| 5768 | } |
| 5769 | $alternate ^= 1; |
| 5770 | |
| 5771 | my $up = $file_name; |
| 5772 | $up =~ s!/?[^/]+$!!; |
| 5773 | undef $up unless $up; |
| 5774 | # based on git_print_tree_entry |
| 5775 | print '<td class="mode">' . mode_str('040000') . "</td>\n"; |
Jakub Narebski | e4b48ea | 2009-09-07 14:40:00 +0200 | [diff] [blame] | 5776 | print '<td class="size"> </td>'."\n" if $show_sizes; |
Jakub Narebski | b6b7fc7 | 2006-10-21 17:54:44 +0200 | [diff] [blame] | 5777 | print '<td class="list">'; |
Jakub Narebski | e4b48ea | 2009-09-07 14:40:00 +0200 | [diff] [blame] | 5778 | print $cgi->a({-href => href(action=>"tree", |
| 5779 | hash_base=>$hash_base, |
Jakub Narebski | b6b7fc7 | 2006-10-21 17:54:44 +0200 | [diff] [blame] | 5780 | file_name=>$up)}, |
| 5781 | ".."); |
| 5782 | print "</td>\n"; |
| 5783 | print "<td class=\"link\"></td>\n"; |
| 5784 | |
| 5785 | print "</tr>\n"; |
| 5786 | } |
Kay Sievers | 161332a | 2005-08-07 19:49:46 +0200 | [diff] [blame] | 5787 | foreach my $line (@entries) { |
Jakub Narebski | e4b48ea | 2009-09-07 14:40:00 +0200 | [diff] [blame] | 5788 | my %t = parse_ls_tree_line($line, -z => 1, -l => $show_sizes); |
Jakub Narebski | cb849b4 | 2006-08-31 00:32:15 +0200 | [diff] [blame] | 5789 | |
Kay Sievers | bddec01 | 2005-08-07 20:25:42 +0200 | [diff] [blame] | 5790 | if ($alternate) { |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 5791 | print "<tr class=\"dark\">\n"; |
Kay Sievers | bddec01 | 2005-08-07 20:25:42 +0200 | [diff] [blame] | 5792 | } else { |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 5793 | print "<tr class=\"light\">\n"; |
Kay Sievers | bddec01 | 2005-08-07 20:25:42 +0200 | [diff] [blame] | 5794 | } |
| 5795 | $alternate ^= 1; |
Jakub Narebski | cb849b4 | 2006-08-31 00:32:15 +0200 | [diff] [blame] | 5796 | |
Jakub Narebski | 300454f | 2006-10-21 17:53:09 +0200 | [diff] [blame] | 5797 | git_print_tree_entry(\%t, $basedir, $hash_base, $have_blame); |
Jakub Narebski | fa70200 | 2006-08-31 00:35:07 +0200 | [diff] [blame] | 5798 | |
Kay Sievers | 42f7eb9 | 2005-08-07 20:21:46 +0200 | [diff] [blame] | 5799 | print "</tr>\n"; |
Kay Sievers | 161332a | 2005-08-07 19:49:46 +0200 | [diff] [blame] | 5800 | } |
Kay Sievers | 42f7eb9 | 2005-08-07 20:21:46 +0200 | [diff] [blame] | 5801 | print "</table>\n" . |
| 5802 | "</div>"; |
Kay Sievers | 12a88f2 | 2005-08-07 20:02:47 +0200 | [diff] [blame] | 5803 | git_footer_html(); |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 5804 | } |
| 5805 | |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 5806 | sub snapshot_name { |
| 5807 | my ($project, $hash) = @_; |
| 5808 | |
| 5809 | # path/to/project.git -> project |
| 5810 | # path/to/project/.git -> project |
| 5811 | my $name = to_utf8($project); |
| 5812 | $name =~ s,([^/])/*\.git$,$1,; |
| 5813 | $name = basename($name); |
| 5814 | # sanitize name |
| 5815 | $name =~ s/[[:cntrl:]]/?/g; |
| 5816 | |
| 5817 | my $ver = $hash; |
| 5818 | if ($hash =~ /^[0-9a-fA-F]+$/) { |
| 5819 | # shorten SHA-1 hash |
| 5820 | my $full_hash = git_get_full_hash($project, $hash); |
| 5821 | if ($full_hash =~ /^$hash/ && length($hash) > 7) { |
| 5822 | $ver = git_get_short_hash($project, $hash); |
| 5823 | } |
| 5824 | } elsif ($hash =~ m!^refs/tags/(.*)$!) { |
| 5825 | # tags don't need shortened SHA-1 hash |
| 5826 | $ver = $1; |
| 5827 | } else { |
| 5828 | # branches and other need shortened SHA-1 hash |
| 5829 | if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) { |
| 5830 | $ver = $1; |
| 5831 | } |
| 5832 | $ver .= '-' . git_get_short_hash($project, $hash); |
| 5833 | } |
| 5834 | # in case of hierarchical branch names |
| 5835 | $ver =~ s!/!.!g; |
| 5836 | |
| 5837 | # name = project-version_string |
| 5838 | $name = "$name-$ver"; |
| 5839 | |
| 5840 | return wantarray ? ($name, $name) : $name; |
| 5841 | } |
| 5842 | |
Aneesh Kumar K.V | cb9c6e5 | 2006-08-17 20:59:46 +0530 | [diff] [blame] | 5843 | sub git_snapshot { |
Giuseppe Bilotta | 1b2d297 | 2008-10-10 20:42:26 +0200 | [diff] [blame] | 5844 | my $format = $input_params{'snapshot_format'}; |
Giuseppe Bilotta | 5e16684 | 2008-11-02 10:21:37 +0100 | [diff] [blame] | 5845 | if (!@snapshot_fmts) { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5846 | die_error(403, "Snapshots not allowed"); |
Jakub Narebski | 3473e7d | 2007-07-25 01:19:58 +0200 | [diff] [blame] | 5847 | } |
| 5848 | # default to first supported snapshot format |
Giuseppe Bilotta | 5e16684 | 2008-11-02 10:21:37 +0100 | [diff] [blame] | 5849 | $format ||= $snapshot_fmts[0]; |
Jakub Narebski | 3473e7d | 2007-07-25 01:19:58 +0200 | [diff] [blame] | 5850 | if ($format !~ m/^[a-z0-9]+$/) { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5851 | die_error(400, "Invalid snapshot format parameter"); |
Jakub Narebski | 3473e7d | 2007-07-25 01:19:58 +0200 | [diff] [blame] | 5852 | } elsif (!exists($known_snapshot_formats{$format})) { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5853 | die_error(400, "Unknown snapshot format"); |
Mark A Rada | 1bfd363 | 2009-08-06 10:25:39 -0400 | [diff] [blame] | 5854 | } elsif ($known_snapshot_formats{$format}{'disabled'}) { |
| 5855 | die_error(403, "Snapshot format not allowed"); |
Mark Rada | 34b31a8 | 2009-08-25 00:59:48 -0400 | [diff] [blame] | 5856 | } elsif (!grep($_ eq $format, @snapshot_fmts)) { |
| 5857 | die_error(403, "Unsupported snapshot format"); |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 5858 | } |
| 5859 | |
Mark Rada | fdb0c36 | 2009-09-26 13:46:08 -0400 | [diff] [blame] | 5860 | my $type = git_get_type("$hash^{}"); |
| 5861 | if (!$type) { |
| 5862 | die_error(404, 'Object does not exist'); |
| 5863 | } elsif ($type eq 'blob') { |
| 5864 | die_error(400, 'Object is not a tree-ish'); |
Aneesh Kumar K.V | cb9c6e5 | 2006-08-17 20:59:46 +0530 | [diff] [blame] | 5865 | } |
| 5866 | |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 5867 | my ($name, $prefix) = snapshot_name($project, $hash); |
| 5868 | my $filename = "$name$known_snapshot_formats{$format}{'suffix'}"; |
| 5869 | my $cmd = quote_command( |
Lea Wiemann | 516381d | 2008-06-17 23:46:35 +0200 | [diff] [blame] | 5870 | git_cmd(), 'archive', |
| 5871 | "--format=$known_snapshot_formats{$format}{'format'}", |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 5872 | "--prefix=$prefix/", $hash); |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 5873 | if (exists $known_snapshot_formats{$format}{'compressor'}) { |
Lea Wiemann | 516381d | 2008-06-17 23:46:35 +0200 | [diff] [blame] | 5874 | $cmd .= ' | ' . quote_command(@{$known_snapshot_formats{$format}{'compressor'}}); |
Mark Levedahl | 072570e | 2007-05-20 11:46:46 -0400 | [diff] [blame] | 5875 | } |
Aneesh Kumar K.V | cb9c6e5 | 2006-08-17 20:59:46 +0530 | [diff] [blame] | 5876 | |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 5877 | $filename =~ s/(["\\])/\\$1/g; |
Jakub Narebski | ab41dfb | 2006-09-26 01:59:43 +0200 | [diff] [blame] | 5878 | print $cgi->header( |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 5879 | -type => $known_snapshot_formats{$format}{'type'}, |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 5880 | -content_disposition => 'inline; filename="' . $filename . '"', |
Jakub Narebski | ab41dfb | 2006-09-26 01:59:43 +0200 | [diff] [blame] | 5881 | -status => '200 OK'); |
Aneesh Kumar K.V | cb9c6e5 | 2006-08-17 20:59:46 +0530 | [diff] [blame] | 5882 | |
Mark Levedahl | 072570e | 2007-05-20 11:46:46 -0400 | [diff] [blame] | 5883 | open my $fd, "-|", $cmd |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5884 | or die_error(500, "Execute git-archive failed"); |
Aneesh Kumar K.V | cb9c6e5 | 2006-08-17 20:59:46 +0530 | [diff] [blame] | 5885 | binmode STDOUT, ':raw'; |
| 5886 | print <$fd>; |
| 5887 | binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi |
| 5888 | close $fd; |
Aneesh Kumar K.V | cb9c6e5 | 2006-08-17 20:59:46 +0530 | [diff] [blame] | 5889 | } |
| 5890 | |
Jakub Narebski | 15f0b11 | 2009-11-13 02:02:13 +0100 | [diff] [blame] | 5891 | sub git_log_generic { |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 5892 | my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_; |
Jakub Narebski | 15f0b11 | 2009-11-13 02:02:13 +0100 | [diff] [blame] | 5893 | |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5894 | my $head = git_get_head_hash($project); |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 5895 | if (!defined $base) { |
| 5896 | $base = $head; |
Kay Sievers | 0db3797 | 2005-08-07 20:24:35 +0200 | [diff] [blame] | 5897 | } |
Kay Sievers | ea4a6df | 2005-08-07 20:26:49 +0200 | [diff] [blame] | 5898 | if (!defined $page) { |
| 5899 | $page = 0; |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 5900 | } |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 5901 | my $refs = git_get_references(); |
Kay Sievers | ea4a6df | 2005-08-07 20:26:49 +0200 | [diff] [blame] | 5902 | |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 5903 | my $commit_hash = $base; |
| 5904 | if (defined $parent) { |
| 5905 | $commit_hash = "$parent..$base"; |
Jakub Narebski | 15f0b11 | 2009-11-13 02:02:13 +0100 | [diff] [blame] | 5906 | } |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 5907 | my @commitlist = |
| 5908 | parse_commits($commit_hash, 101, (100 * $page), |
| 5909 | defined $file_name ? ($file_name, "--full-history") : ()); |
Kay Sievers | ea4a6df | 2005-08-07 20:26:49 +0200 | [diff] [blame] | 5910 | |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 5911 | my $ftype; |
| 5912 | if (!defined $file_hash && defined $file_name) { |
| 5913 | # some commits could have deleted file in question, |
| 5914 | # and not have it in tree, but one of them has to have it |
| 5915 | for (my $i = 0; $i < @commitlist; $i++) { |
| 5916 | $file_hash = git_get_hash_by_path($commitlist[$i]{'id'}, $file_name); |
| 5917 | last if defined $file_hash; |
| 5918 | } |
| 5919 | } |
| 5920 | if (defined $file_hash) { |
| 5921 | $ftype = git_get_type($file_hash); |
| 5922 | } |
| 5923 | if (defined $file_name && !defined $ftype) { |
| 5924 | die_error(500, "Unknown type of object"); |
| 5925 | } |
| 5926 | my %co; |
| 5927 | if (defined $file_name) { |
| 5928 | %co = parse_commit($base) |
| 5929 | or die_error(404, "Unknown commit object"); |
| 5930 | } |
| 5931 | |
| 5932 | |
| 5933 | my $paging_nav = format_paging_nav($fmt_name, $page, $#commitlist >= 100); |
Jakub Narebski | 15f0b11 | 2009-11-13 02:02:13 +0100 | [diff] [blame] | 5934 | my $next_link = ''; |
Jakub Narebski | 42671ca | 2009-11-13 02:02:12 +0100 | [diff] [blame] | 5935 | if ($#commitlist >= 100) { |
| 5936 | $next_link = |
| 5937 | $cgi->a({-href => href(-replay=>1, page=>$page+1), |
| 5938 | -accesskey => "n", -title => "Alt-n"}, "next"); |
| 5939 | } |
Jakub Narebski | 15f0b11 | 2009-11-13 02:02:13 +0100 | [diff] [blame] | 5940 | my $patch_max = gitweb_get_feature('patches'); |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 5941 | if ($patch_max && !defined $file_name) { |
Giuseppe Bilotta | 75bf2cb | 2008-12-18 08:13:19 +0100 | [diff] [blame] | 5942 | if ($patch_max < 0 || @commitlist <= $patch_max) { |
| 5943 | $paging_nav .= " ⋅ " . |
| 5944 | $cgi->a({-href => href(action=>"patches", -replay=>1)}, |
| 5945 | "patches"); |
| 5946 | } |
| 5947 | } |
| 5948 | |
Jakub Narebski | 0d83ddc | 2006-07-30 15:01:07 +0200 | [diff] [blame] | 5949 | git_header_html(); |
Jakub Narebski | 15f0b11 | 2009-11-13 02:02:13 +0100 | [diff] [blame] | 5950 | git_print_page_nav($fmt_name,'', $hash,$hash,$hash, $paging_nav); |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 5951 | if (defined $file_name) { |
| 5952 | git_print_header_div('commit', esc_html($co{'title'}), $base); |
| 5953 | } else { |
| 5954 | git_print_header_div('summary', $project) |
| 5955 | } |
| 5956 | git_print_page_path($file_name, $ftype, $hash_base) |
| 5957 | if (defined $file_name); |
Jakub Narebski | 0d83ddc | 2006-07-30 15:01:07 +0200 | [diff] [blame] | 5958 | |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 5959 | $body_subr->(\@commitlist, 0, 99, $refs, $next_link, |
| 5960 | $file_name, $file_hash, $ftype); |
Jakub Narebski | 42671ca | 2009-11-13 02:02:12 +0100 | [diff] [blame] | 5961 | |
Kay Sievers | 034df39 | 2005-08-07 20:20:07 +0200 | [diff] [blame] | 5962 | git_footer_html(); |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 5963 | } |
| 5964 | |
Jakub Narebski | 15f0b11 | 2009-11-13 02:02:13 +0100 | [diff] [blame] | 5965 | sub git_log { |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 5966 | git_log_generic('log', \&git_log_body, |
| 5967 | $hash, $hash_parent); |
Jakub Narebski | 15f0b11 | 2009-11-13 02:02:13 +0100 | [diff] [blame] | 5968 | } |
| 5969 | |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 5970 | sub git_commit { |
Jakub Narebski | 9954f77 | 2006-11-18 23:35:41 +0100 | [diff] [blame] | 5971 | $hash ||= $hash_base || "HEAD"; |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 5972 | my %co = parse_commit($hash) |
| 5973 | or die_error(404, "Unknown commit object"); |
Kay Sievers | 161332a | 2005-08-07 19:49:46 +0200 | [diff] [blame] | 5974 | |
Jakub Narebski | c9d193d | 2006-12-15 21:57:16 +0100 | [diff] [blame] | 5975 | my $parent = $co{'parent'}; |
| 5976 | my $parents = $co{'parents'}; # listref |
| 5977 | |
| 5978 | # we need to prepare $formats_nav before any parameter munging |
| 5979 | my $formats_nav; |
| 5980 | if (!defined $parent) { |
| 5981 | # --root commitdiff |
| 5982 | $formats_nav .= '(initial)'; |
| 5983 | } elsif (@$parents == 1) { |
| 5984 | # single parent commit |
| 5985 | $formats_nav .= |
| 5986 | '(parent: ' . |
| 5987 | $cgi->a({-href => href(action=>"commit", |
| 5988 | hash=>$parent)}, |
| 5989 | esc_html(substr($parent, 0, 7))) . |
| 5990 | ')'; |
| 5991 | } else { |
| 5992 | # merge commit |
| 5993 | $formats_nav .= |
| 5994 | '(merge: ' . |
| 5995 | join(' ', map { |
Jakub Narebski | f9308a1 | 2007-03-23 21:04:31 +0100 | [diff] [blame] | 5996 | $cgi->a({-href => href(action=>"commit", |
Jakub Narebski | c9d193d | 2006-12-15 21:57:16 +0100 | [diff] [blame] | 5997 | hash=>$_)}, |
| 5998 | esc_html(substr($_, 0, 7))); |
| 5999 | } @$parents ) . |
| 6000 | ')'; |
| 6001 | } |
Jakub Narebski | 1655c98 | 2009-10-09 14:26:44 +0200 | [diff] [blame] | 6002 | if (gitweb_check_feature('patches') && @$parents <= 1) { |
Giuseppe Bilotta | 75bf2cb | 2008-12-18 08:13:19 +0100 | [diff] [blame] | 6003 | $formats_nav .= " | " . |
| 6004 | $cgi->a({-href => href(action=>"patch", -replay=>1)}, |
| 6005 | "patch"); |
| 6006 | } |
Jakub Narebski | c9d193d | 2006-12-15 21:57:16 +0100 | [diff] [blame] | 6007 | |
Kay Sievers | d8a20ba | 2005-08-07 20:28:53 +0200 | [diff] [blame] | 6008 | if (!defined $parent) { |
Jakub Narebski | b918298 | 2006-07-30 18:28:34 -0700 | [diff] [blame] | 6009 | $parent = "--root"; |
Kay Sievers | 6191f8e | 2005-08-07 20:19:56 +0200 | [diff] [blame] | 6010 | } |
Jakub Narebski | 549ab4a | 2006-12-15 17:53:45 +0100 | [diff] [blame] | 6011 | my @difftree; |
Jakub Narebski | 208ecb2 | 2007-05-07 01:10:08 +0200 | [diff] [blame] | 6012 | open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id", |
| 6013 | @diff_opts, |
| 6014 | (@$parents <= 1 ? $parent : '-c'), |
| 6015 | $hash, "--" |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6016 | or die_error(500, "Open git-diff-tree failed"); |
Jakub Narebski | 208ecb2 | 2007-05-07 01:10:08 +0200 | [diff] [blame] | 6017 | @difftree = map { chomp; $_ } <$fd>; |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6018 | close $fd or die_error(404, "Reading git-diff-tree failed"); |
Kay Sievers | 1104429 | 2005-10-19 03:18:45 +0200 | [diff] [blame] | 6019 | |
| 6020 | # non-textual hash id's can be cached |
| 6021 | my $expires; |
| 6022 | if ($hash =~ m/^[0-9a-fA-F]{40}$/) { |
| 6023 | $expires = "+1d"; |
| 6024 | } |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 6025 | my $refs = git_get_references(); |
| 6026 | my $ref = format_ref_marker($refs, $co{'id'}); |
Aneesh Kumar K.V | ddb8d90 | 2006-08-20 11:53:04 +0530 | [diff] [blame] | 6027 | |
Jakub Narebski | 594e212 | 2006-07-31 02:21:52 +0200 | [diff] [blame] | 6028 | git_header_html(undef, $expires); |
Petr Baudis | a144154 | 2006-10-06 18:59:33 +0200 | [diff] [blame] | 6029 | git_print_page_nav('commit', '', |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 6030 | $hash, $co{'tree'}, $hash, |
Jakub Narebski | c9d193d | 2006-12-15 21:57:16 +0100 | [diff] [blame] | 6031 | $formats_nav); |
Luben Tuikov | 4f7b34c | 2006-07-23 13:36:32 -0700 | [diff] [blame] | 6032 | |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 6033 | if (defined $co{'parent'}) { |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 6034 | git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash); |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 6035 | } else { |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 6036 | git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash); |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 6037 | } |
Kay Sievers | 6191f8e | 2005-08-07 20:19:56 +0200 | [diff] [blame] | 6038 | print "<div class=\"title_text\">\n" . |
Jakub Narebski | 591ebf6 | 2007-11-19 14:16:11 +0100 | [diff] [blame] | 6039 | "<table class=\"object_header\">\n"; |
Giuseppe Bilotta | 1c49a4e | 2009-06-30 00:00:48 +0200 | [diff] [blame] | 6040 | git_print_authorship_rows(\%co); |
Jakub Narebski | 1f1ab5f | 2006-06-20 14:58:12 +0000 | [diff] [blame] | 6041 | print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n"; |
Kay Sievers | bddec01 | 2005-08-07 20:25:42 +0200 | [diff] [blame] | 6042 | print "<tr>" . |
| 6043 | "<td>tree</td>" . |
Jakub Narebski | 1f1ab5f | 2006-06-20 14:58:12 +0000 | [diff] [blame] | 6044 | "<td class=\"sha1\">" . |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 6045 | $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash), |
| 6046 | class => "list"}, $co{'tree'}) . |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6047 | "</td>" . |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 6048 | "<td class=\"link\">" . |
| 6049 | $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)}, |
| 6050 | "tree"); |
Matt McCutchen | a3c8ab3 | 2007-07-22 01:30:27 +0200 | [diff] [blame] | 6051 | my $snapshot_links = format_snapshot_links($hash); |
| 6052 | if (defined $snapshot_links) { |
| 6053 | print " | " . $snapshot_links; |
Aneesh Kumar K.V | cb9c6e5 | 2006-08-17 20:59:46 +0530 | [diff] [blame] | 6054 | } |
| 6055 | print "</td>" . |
Kay Sievers | bddec01 | 2005-08-07 20:25:42 +0200 | [diff] [blame] | 6056 | "</tr>\n"; |
Jakub Narebski | 549ab4a | 2006-12-15 17:53:45 +0100 | [diff] [blame] | 6057 | |
Kay Sievers | 3e02929 | 2005-08-07 20:05:15 +0200 | [diff] [blame] | 6058 | foreach my $par (@$parents) { |
Kay Sievers | bddec01 | 2005-08-07 20:25:42 +0200 | [diff] [blame] | 6059 | print "<tr>" . |
| 6060 | "<td>parent</td>" . |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 6061 | "<td class=\"sha1\">" . |
| 6062 | $cgi->a({-href => href(action=>"commit", hash=>$par), |
| 6063 | class => "list"}, $par) . |
| 6064 | "</td>" . |
Kay Sievers | bddec01 | 2005-08-07 20:25:42 +0200 | [diff] [blame] | 6065 | "<td class=\"link\">" . |
Martin Waitz | 1c2a4f5 | 2006-08-16 00:24:30 +0200 | [diff] [blame] | 6066 | $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") . |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 6067 | " | " . |
Jakub Narebski | f2e6094 | 2006-09-03 23:43:03 +0200 | [diff] [blame] | 6068 | $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") . |
Kay Sievers | bddec01 | 2005-08-07 20:25:42 +0200 | [diff] [blame] | 6069 | "</td>" . |
| 6070 | "</tr>\n"; |
Kay Sievers | 3e02929 | 2005-08-07 20:05:15 +0200 | [diff] [blame] | 6071 | } |
Jakub Narebski | 7a9b4c5 | 2006-06-21 09:48:02 +0200 | [diff] [blame] | 6072 | print "</table>". |
Kay Sievers | b87d78d | 2005-08-07 20:21:04 +0200 | [diff] [blame] | 6073 | "</div>\n"; |
Jakub Narebski | d16d093 | 2006-08-17 11:21:23 +0200 | [diff] [blame] | 6074 | |
Kay Sievers | fbb592a | 2005-08-07 20:12:11 +0200 | [diff] [blame] | 6075 | print "<div class=\"page_body\">\n"; |
Jakub Narebski | d16d093 | 2006-08-17 11:21:23 +0200 | [diff] [blame] | 6076 | git_print_log($co{'comment'}); |
Kay Sievers | 927dcec | 2005-08-07 20:18:44 +0200 | [diff] [blame] | 6077 | print "</div>\n"; |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 6078 | |
Jakub Narebski | 208ecb2 | 2007-05-07 01:10:08 +0200 | [diff] [blame] | 6079 | git_difftree_body(\@difftree, $hash, @$parents); |
Jakub Narebski | 4a4a1a5 | 2006-08-14 02:18:33 +0200 | [diff] [blame] | 6080 | |
Kay Sievers | 12a88f2 | 2005-08-07 20:02:47 +0200 | [diff] [blame] | 6081 | git_footer_html(); |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 6082 | } |
| 6083 | |
Jakub Narebski | ca94601 | 2006-12-10 13:25:47 +0100 | [diff] [blame] | 6084 | sub git_object { |
| 6085 | # object is defined by: |
| 6086 | # - hash or hash_base alone |
| 6087 | # - hash_base and file_name |
| 6088 | my $type; |
| 6089 | |
| 6090 | # - hash or hash_base alone |
| 6091 | if ($hash || ($hash_base && !defined $file_name)) { |
| 6092 | my $object_id = $hash || $hash_base; |
| 6093 | |
Lea Wiemann | 516381d | 2008-06-17 23:46:35 +0200 | [diff] [blame] | 6094 | open my $fd, "-|", quote_command( |
| 6095 | git_cmd(), 'cat-file', '-t', $object_id) . ' 2> /dev/null' |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6096 | or die_error(404, "Object does not exist"); |
Jakub Narebski | ca94601 | 2006-12-10 13:25:47 +0100 | [diff] [blame] | 6097 | $type = <$fd>; |
| 6098 | chomp $type; |
| 6099 | close $fd |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6100 | or die_error(404, "Object does not exist"); |
Jakub Narebski | ca94601 | 2006-12-10 13:25:47 +0100 | [diff] [blame] | 6101 | |
| 6102 | # - hash_base and file_name |
| 6103 | } elsif ($hash_base && defined $file_name) { |
| 6104 | $file_name =~ s,/+$,,; |
| 6105 | |
| 6106 | system(git_cmd(), "cat-file", '-e', $hash_base) == 0 |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6107 | or die_error(404, "Base object does not exist"); |
Jakub Narebski | ca94601 | 2006-12-10 13:25:47 +0100 | [diff] [blame] | 6108 | |
| 6109 | # here errors should not hapen |
| 6110 | open my $fd, "-|", git_cmd(), "ls-tree", $hash_base, "--", $file_name |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6111 | or die_error(500, "Open git-ls-tree failed"); |
Jakub Narebski | ca94601 | 2006-12-10 13:25:47 +0100 | [diff] [blame] | 6112 | my $line = <$fd>; |
| 6113 | close $fd; |
| 6114 | |
| 6115 | #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' |
| 6116 | unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6117 | die_error(404, "File or directory for given base does not exist"); |
Jakub Narebski | ca94601 | 2006-12-10 13:25:47 +0100 | [diff] [blame] | 6118 | } |
| 6119 | $type = $2; |
| 6120 | $hash = $3; |
| 6121 | } else { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6122 | die_error(400, "Not enough information to find object"); |
Jakub Narebski | ca94601 | 2006-12-10 13:25:47 +0100 | [diff] [blame] | 6123 | } |
| 6124 | |
| 6125 | print $cgi->redirect(-uri => href(action=>$type, -full=>1, |
| 6126 | hash=>$hash, hash_base=>$hash_base, |
| 6127 | file_name=>$file_name), |
| 6128 | -status => '302 Found'); |
| 6129 | } |
| 6130 | |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 6131 | sub git_blobdiff { |
Jakub Narebski | 9b71b1f | 2006-08-25 21:14:49 +0200 | [diff] [blame] | 6132 | my $format = shift || 'html'; |
| 6133 | |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6134 | my $fd; |
| 6135 | my @difftree; |
| 6136 | my %diffinfo; |
Jakub Narebski | 9b71b1f | 2006-08-25 21:14:49 +0200 | [diff] [blame] | 6137 | my $expires; |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6138 | |
| 6139 | # preparing $fd and %diffinfo for git_patchset_body |
| 6140 | # new style URI |
| 6141 | if (defined $hash_base && defined $hash_parent_base) { |
| 6142 | if (defined $file_name) { |
| 6143 | # read raw output |
Jakub Narebski | 45bd0c8 | 2006-10-30 22:29:06 +0100 | [diff] [blame] | 6144 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
| 6145 | $hash_parent_base, $hash_base, |
Jakub Narebski | 5ae917a | 2007-03-30 23:41:26 +0200 | [diff] [blame] | 6146 | "--", (defined $file_parent ? $file_parent : ()), $file_name |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6147 | or die_error(500, "Open git-diff-tree failed"); |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6148 | @difftree = map { chomp; $_ } <$fd>; |
| 6149 | close $fd |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6150 | or die_error(404, "Reading git-diff-tree failed"); |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6151 | @difftree |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6152 | or die_error(404, "Blob diff not found"); |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6153 | |
Jakub Narebski | 0aea337 | 2006-08-27 23:45:26 +0200 | [diff] [blame] | 6154 | } elsif (defined $hash && |
| 6155 | $hash =~ /[0-9a-fA-F]{40}/) { |
| 6156 | # try to find filename from $hash |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6157 | |
| 6158 | # read filtered raw output |
Jakub Narebski | 45bd0c8 | 2006-10-30 22:29:06 +0100 | [diff] [blame] | 6159 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
| 6160 | $hash_parent_base, $hash_base, "--" |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6161 | or die_error(500, "Open git-diff-tree failed"); |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6162 | @difftree = |
| 6163 | # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c' |
| 6164 | # $hash == to_id |
| 6165 | grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ } |
| 6166 | map { chomp; $_ } <$fd>; |
| 6167 | close $fd |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6168 | or die_error(404, "Reading git-diff-tree failed"); |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6169 | @difftree |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6170 | or die_error(404, "Blob diff not found"); |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6171 | |
| 6172 | } else { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6173 | die_error(400, "Missing one of the blob diff parameters"); |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6174 | } |
| 6175 | |
| 6176 | if (@difftree > 1) { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6177 | die_error(400, "Ambiguous blob diff specification"); |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6178 | } |
| 6179 | |
| 6180 | %diffinfo = parse_difftree_raw_line($difftree[0]); |
Jakub Narebski | 9d30145 | 2007-11-01 12:38:08 +0100 | [diff] [blame] | 6181 | $file_parent ||= $diffinfo{'from_file'} || $file_name; |
| 6182 | $file_name ||= $diffinfo{'to_file'}; |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6183 | |
| 6184 | $hash_parent ||= $diffinfo{'from_id'}; |
| 6185 | $hash ||= $diffinfo{'to_id'}; |
| 6186 | |
Jakub Narebski | 9b71b1f | 2006-08-25 21:14:49 +0200 | [diff] [blame] | 6187 | # non-textual hash id's can be cached |
| 6188 | if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ && |
| 6189 | $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) { |
| 6190 | $expires = '+1d'; |
| 6191 | } |
| 6192 | |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6193 | # open patch output |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 6194 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
Jakub Narebski | 957d6ea | 2007-04-05 13:45:41 +0200 | [diff] [blame] | 6195 | '-p', ($format eq 'html' ? "--full-index" : ()), |
| 6196 | $hash_parent_base, $hash_base, |
Jakub Narebski | 5ae917a | 2007-03-30 23:41:26 +0200 | [diff] [blame] | 6197 | "--", (defined $file_parent ? $file_parent : ()), $file_name |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6198 | or die_error(500, "Open git-diff-tree failed"); |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6199 | } |
| 6200 | |
Junio C Hamano | b54dc9f | 2008-12-16 19:42:02 -0800 | [diff] [blame] | 6201 | # old/legacy style URI -- not generated anymore since 1.4.3. |
| 6202 | if (!%diffinfo) { |
| 6203 | die_error('404 Not Found', "Missing one of the blob diff parameters") |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6204 | } |
| 6205 | |
| 6206 | # header |
Jakub Narebski | 9b71b1f | 2006-08-25 21:14:49 +0200 | [diff] [blame] | 6207 | if ($format eq 'html') { |
| 6208 | my $formats_nav = |
Jakub Narebski | a3823e5 | 2007-11-01 13:06:29 +0100 | [diff] [blame] | 6209 | $cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)}, |
Petr Baudis | 35329cc | 2006-09-22 03:19:50 +0200 | [diff] [blame] | 6210 | "raw"); |
Jakub Narebski | 9b71b1f | 2006-08-25 21:14:49 +0200 | [diff] [blame] | 6211 | git_header_html(undef, $expires); |
| 6212 | if (defined $hash_base && (my %co = parse_commit($hash_base))) { |
| 6213 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); |
| 6214 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); |
| 6215 | } else { |
| 6216 | print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n"; |
| 6217 | print "<div class=\"title\">$hash vs $hash_parent</div>\n"; |
| 6218 | } |
| 6219 | if (defined $file_name) { |
| 6220 | git_print_page_path($file_name, "blob", $hash_base); |
| 6221 | } else { |
| 6222 | print "<div class=\"page_path\"></div>\n"; |
| 6223 | } |
| 6224 | |
| 6225 | } elsif ($format eq 'plain') { |
| 6226 | print $cgi->header( |
| 6227 | -type => 'text/plain', |
| 6228 | -charset => 'utf-8', |
| 6229 | -expires => $expires, |
Luben Tuikov | a2a3bf7 | 2006-09-28 16:51:43 -0700 | [diff] [blame] | 6230 | -content_disposition => 'inline; filename="' . "$file_name" . '.patch"'); |
Jakub Narebski | 9b71b1f | 2006-08-25 21:14:49 +0200 | [diff] [blame] | 6231 | |
| 6232 | print "X-Git-Url: " . $cgi->self_url() . "\n\n"; |
| 6233 | |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 6234 | } else { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6235 | die_error(400, "Unknown blobdiff format"); |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6236 | } |
| 6237 | |
| 6238 | # patch |
Jakub Narebski | 9b71b1f | 2006-08-25 21:14:49 +0200 | [diff] [blame] | 6239 | if ($format eq 'html') { |
| 6240 | print "<div class=\"page_body\">\n"; |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6241 | |
Jakub Narebski | 9b71b1f | 2006-08-25 21:14:49 +0200 | [diff] [blame] | 6242 | git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base); |
| 6243 | close $fd; |
Jakub Narebski | 7c5e2eb | 2006-08-25 21:13:34 +0200 | [diff] [blame] | 6244 | |
Jakub Narebski | 9b71b1f | 2006-08-25 21:14:49 +0200 | [diff] [blame] | 6245 | print "</div>\n"; # class="page_body" |
| 6246 | git_footer_html(); |
| 6247 | |
| 6248 | } else { |
| 6249 | while (my $line = <$fd>) { |
Jakub Narebski | 403d090 | 2006-11-08 11:48:56 +0100 | [diff] [blame] | 6250 | $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg; |
| 6251 | $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg; |
Jakub Narebski | 9b71b1f | 2006-08-25 21:14:49 +0200 | [diff] [blame] | 6252 | |
| 6253 | print $line; |
| 6254 | |
| 6255 | last if $line =~ m!^\+\+\+!; |
| 6256 | } |
| 6257 | local $/ = undef; |
| 6258 | print <$fd>; |
| 6259 | close $fd; |
| 6260 | } |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 6261 | } |
| 6262 | |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6263 | sub git_blobdiff_plain { |
Jakub Narebski | 9b71b1f | 2006-08-25 21:14:49 +0200 | [diff] [blame] | 6264 | git_blobdiff('plain'); |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6265 | } |
| 6266 | |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 6267 | sub git_commitdiff { |
Giuseppe Bilotta | 2020985 | 2008-12-18 08:13:17 +0100 | [diff] [blame] | 6268 | my %params = @_; |
| 6269 | my $format = $params{-format} || 'html'; |
Giuseppe Bilotta | 9872cd6 | 2008-12-18 08:13:16 +0100 | [diff] [blame] | 6270 | |
Giuseppe Bilotta | 75bf2cb | 2008-12-18 08:13:19 +0100 | [diff] [blame] | 6271 | my ($patch_max) = gitweb_get_feature('patches'); |
Giuseppe Bilotta | 9872cd6 | 2008-12-18 08:13:16 +0100 | [diff] [blame] | 6272 | if ($format eq 'patch') { |
Giuseppe Bilotta | 9872cd6 | 2008-12-18 08:13:16 +0100 | [diff] [blame] | 6273 | die_error(403, "Patch view not allowed") unless $patch_max; |
| 6274 | } |
| 6275 | |
Jakub Narebski | 9954f77 | 2006-11-18 23:35:41 +0100 | [diff] [blame] | 6276 | $hash ||= $hash_base || "HEAD"; |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6277 | my %co = parse_commit($hash) |
| 6278 | or die_error(404, "Unknown commit object"); |
Jakub Narebski | 151602d | 2006-10-23 00:37:56 +0200 | [diff] [blame] | 6279 | |
Jakub Narebski | cd030c3 | 2007-06-08 13:33:28 +0200 | [diff] [blame] | 6280 | # choose format for commitdiff for merge |
| 6281 | if (! defined $hash_parent && @{$co{'parents'}} > 1) { |
| 6282 | $hash_parent = '--cc'; |
| 6283 | } |
| 6284 | # we need to prepare $formats_nav before almost any parameter munging |
Jakub Narebski | 151602d | 2006-10-23 00:37:56 +0200 | [diff] [blame] | 6285 | my $formats_nav; |
| 6286 | if ($format eq 'html') { |
| 6287 | $formats_nav = |
Jakub Narebski | a3823e5 | 2007-11-01 13:06:29 +0100 | [diff] [blame] | 6288 | $cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)}, |
Jakub Narebski | 151602d | 2006-10-23 00:37:56 +0200 | [diff] [blame] | 6289 | "raw"); |
Jakub Narebski | 1655c98 | 2009-10-09 14:26:44 +0200 | [diff] [blame] | 6290 | if ($patch_max && @{$co{'parents'}} <= 1) { |
Giuseppe Bilotta | 75bf2cb | 2008-12-18 08:13:19 +0100 | [diff] [blame] | 6291 | $formats_nav .= " | " . |
| 6292 | $cgi->a({-href => href(action=>"patch", -replay=>1)}, |
| 6293 | "patch"); |
| 6294 | } |
Jakub Narebski | 151602d | 2006-10-23 00:37:56 +0200 | [diff] [blame] | 6295 | |
Jakub Narebski | cd030c3 | 2007-06-08 13:33:28 +0200 | [diff] [blame] | 6296 | if (defined $hash_parent && |
| 6297 | $hash_parent ne '-c' && $hash_parent ne '--cc') { |
Jakub Narebski | 151602d | 2006-10-23 00:37:56 +0200 | [diff] [blame] | 6298 | # commitdiff with two commits given |
| 6299 | my $hash_parent_short = $hash_parent; |
| 6300 | if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) { |
| 6301 | $hash_parent_short = substr($hash_parent, 0, 7); |
| 6302 | } |
| 6303 | $formats_nav .= |
Jakub Narebski | ada3e1f | 2007-06-08 13:26:31 +0200 | [diff] [blame] | 6304 | ' (from'; |
| 6305 | for (my $i = 0; $i < @{$co{'parents'}}; $i++) { |
| 6306 | if ($co{'parents'}[$i] eq $hash_parent) { |
| 6307 | $formats_nav .= ' parent ' . ($i+1); |
| 6308 | last; |
| 6309 | } |
| 6310 | } |
| 6311 | $formats_nav .= ': ' . |
Jakub Narebski | 151602d | 2006-10-23 00:37:56 +0200 | [diff] [blame] | 6312 | $cgi->a({-href => href(action=>"commitdiff", |
| 6313 | hash=>$hash_parent)}, |
| 6314 | esc_html($hash_parent_short)) . |
| 6315 | ')'; |
| 6316 | } elsif (!$co{'parent'}) { |
| 6317 | # --root commitdiff |
| 6318 | $formats_nav .= ' (initial)'; |
| 6319 | } elsif (scalar @{$co{'parents'}} == 1) { |
| 6320 | # single parent commit |
| 6321 | $formats_nav .= |
| 6322 | ' (parent: ' . |
| 6323 | $cgi->a({-href => href(action=>"commitdiff", |
| 6324 | hash=>$co{'parent'})}, |
| 6325 | esc_html(substr($co{'parent'}, 0, 7))) . |
| 6326 | ')'; |
| 6327 | } else { |
| 6328 | # merge commit |
Jakub Narebski | cd030c3 | 2007-06-08 13:33:28 +0200 | [diff] [blame] | 6329 | if ($hash_parent eq '--cc') { |
| 6330 | $formats_nav .= ' | ' . |
| 6331 | $cgi->a({-href => href(action=>"commitdiff", |
| 6332 | hash=>$hash, hash_parent=>'-c')}, |
| 6333 | 'combined'); |
| 6334 | } else { # $hash_parent eq '-c' |
| 6335 | $formats_nav .= ' | ' . |
| 6336 | $cgi->a({-href => href(action=>"commitdiff", |
| 6337 | hash=>$hash, hash_parent=>'--cc')}, |
| 6338 | 'compact'); |
| 6339 | } |
Jakub Narebski | 151602d | 2006-10-23 00:37:56 +0200 | [diff] [blame] | 6340 | $formats_nav .= |
| 6341 | ' (merge: ' . |
| 6342 | join(' ', map { |
| 6343 | $cgi->a({-href => href(action=>"commitdiff", |
| 6344 | hash=>$_)}, |
| 6345 | esc_html(substr($_, 0, 7))); |
| 6346 | } @{$co{'parents'}} ) . |
| 6347 | ')'; |
| 6348 | } |
| 6349 | } |
| 6350 | |
Jakub Narebski | fb1dde4 | 2007-05-07 01:10:07 +0200 | [diff] [blame] | 6351 | my $hash_parent_param = $hash_parent; |
Jakub Narebski | cd030c3 | 2007-06-08 13:33:28 +0200 | [diff] [blame] | 6352 | if (!defined $hash_parent_param) { |
| 6353 | # --cc for multiple parents, --root for parentless |
Jakub Narebski | fb1dde4 | 2007-05-07 01:10:07 +0200 | [diff] [blame] | 6354 | $hash_parent_param = |
Jakub Narebski | cd030c3 | 2007-06-08 13:33:28 +0200 | [diff] [blame] | 6355 | @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root'; |
Kay Sievers | bddec01 | 2005-08-07 20:25:42 +0200 | [diff] [blame] | 6356 | } |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6357 | |
| 6358 | # read commitdiff |
| 6359 | my $fd; |
| 6360 | my @difftree; |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6361 | if ($format eq 'html') { |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 6362 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
Jakub Narebski | 45bd0c8 | 2006-10-30 22:29:06 +0100 | [diff] [blame] | 6363 | "--no-commit-id", "--patch-with-raw", "--full-index", |
Jakub Narebski | fb1dde4 | 2007-05-07 01:10:07 +0200 | [diff] [blame] | 6364 | $hash_parent_param, $hash, "--" |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6365 | or die_error(500, "Open git-diff-tree failed"); |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6366 | |
Jakub Narebski | 04408c3 | 2006-11-18 23:35:38 +0100 | [diff] [blame] | 6367 | while (my $line = <$fd>) { |
| 6368 | chomp $line; |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6369 | # empty line ends raw part of diff-tree output |
| 6370 | last unless $line; |
Jakub Narebski | 493e01d | 2007-05-07 01:10:06 +0200 | [diff] [blame] | 6371 | push @difftree, scalar parse_difftree_raw_line($line); |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6372 | } |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6373 | |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6374 | } elsif ($format eq 'plain') { |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 6375 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
Jakub Narebski | fb1dde4 | 2007-05-07 01:10:07 +0200 | [diff] [blame] | 6376 | '-p', $hash_parent_param, $hash, "--" |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6377 | or die_error(500, "Open git-diff-tree failed"); |
Giuseppe Bilotta | 9872cd6 | 2008-12-18 08:13:16 +0100 | [diff] [blame] | 6378 | } elsif ($format eq 'patch') { |
| 6379 | # For commit ranges, we limit the output to the number of |
| 6380 | # patches specified in the 'patches' feature. |
| 6381 | # For single commits, we limit the output to a single patch, |
| 6382 | # diverging from the git-format-patch default. |
| 6383 | my @commit_spec = (); |
| 6384 | if ($hash_parent) { |
| 6385 | if ($patch_max > 0) { |
| 6386 | push @commit_spec, "-$patch_max"; |
| 6387 | } |
| 6388 | push @commit_spec, '-n', "$hash_parent..$hash"; |
| 6389 | } else { |
Giuseppe Bilotta | a3411f8 | 2008-12-18 08:13:18 +0100 | [diff] [blame] | 6390 | if ($params{-single}) { |
| 6391 | push @commit_spec, '-1'; |
| 6392 | } else { |
| 6393 | if ($patch_max > 0) { |
| 6394 | push @commit_spec, "-$patch_max"; |
| 6395 | } |
| 6396 | push @commit_spec, "-n"; |
| 6397 | } |
| 6398 | push @commit_spec, '--root', $hash; |
Giuseppe Bilotta | 9872cd6 | 2008-12-18 08:13:16 +0100 | [diff] [blame] | 6399 | } |
Pavan Kumar Sunkara | 04794fd | 2010-05-10 18:41:35 +0200 | [diff] [blame] | 6400 | open $fd, "-|", git_cmd(), "format-patch", @diff_opts, |
| 6401 | '--encoding=utf8', '--stdout', @commit_spec |
Giuseppe Bilotta | 9872cd6 | 2008-12-18 08:13:16 +0100 | [diff] [blame] | 6402 | or die_error(500, "Open git-format-patch failed"); |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6403 | } else { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6404 | die_error(400, "Unknown commitdiff format"); |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6405 | } |
Kay Sievers | 4c02e3c | 2005-08-07 19:52:52 +0200 | [diff] [blame] | 6406 | |
Kay Sievers | 1104429 | 2005-10-19 03:18:45 +0200 | [diff] [blame] | 6407 | # non-textual hash id's can be cached |
| 6408 | my $expires; |
| 6409 | if ($hash =~ m/^[0-9a-fA-F]{40}$/) { |
| 6410 | $expires = "+1d"; |
| 6411 | } |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 6412 | |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6413 | # write commit message |
| 6414 | if ($format eq 'html') { |
| 6415 | my $refs = git_get_references(); |
| 6416 | my $ref = format_ref_marker($refs, $co{'id'}); |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6417 | |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6418 | git_header_html(undef, $expires); |
| 6419 | git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav); |
| 6420 | git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash); |
Giuseppe Bilotta | f88bafa | 2009-06-30 00:00:49 +0200 | [diff] [blame] | 6421 | print "<div class=\"title_text\">\n" . |
| 6422 | "<table class=\"object_header\">\n"; |
| 6423 | git_print_authorship_rows(\%co); |
| 6424 | print "</table>". |
| 6425 | "</div>\n"; |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6426 | print "<div class=\"page_body\">\n"; |
Jakub Narebski | 8256098 | 2006-10-24 13:55:33 +0200 | [diff] [blame] | 6427 | if (@{$co{'comment'}} > 1) { |
| 6428 | print "<div class=\"log\">\n"; |
| 6429 | git_print_log($co{'comment'}, -final_empty_line=> 1, -remove_title => 1); |
| 6430 | print "</div>\n"; # class="log" |
| 6431 | } |
Kay Sievers | 1b1cd42 | 2005-08-07 20:28:01 +0200 | [diff] [blame] | 6432 | |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6433 | } elsif ($format eq 'plain') { |
| 6434 | my $refs = git_get_references("tags"); |
Jakub Narebski | edf735a | 2006-08-24 19:45:30 +0200 | [diff] [blame] | 6435 | my $tagname = git_get_rev_name_tags($hash); |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6436 | my $filename = basename($project) . "-$hash.patch"; |
| 6437 | |
| 6438 | print $cgi->header( |
| 6439 | -type => 'text/plain', |
| 6440 | -charset => 'utf-8', |
| 6441 | -expires => $expires, |
Luben Tuikov | a2a3bf7 | 2006-09-28 16:51:43 -0700 | [diff] [blame] | 6442 | -content_disposition => 'inline; filename="' . "$filename" . '"'); |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6443 | my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'}); |
Yasushi SHOJI | 7720224 | 2008-01-29 21:16:02 +0900 | [diff] [blame] | 6444 | print "From: " . to_utf8($co{'author'}) . "\n"; |
| 6445 | print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n"; |
| 6446 | print "Subject: " . to_utf8($co{'title'}) . "\n"; |
| 6447 | |
Jakub Narebski | edf735a | 2006-08-24 19:45:30 +0200 | [diff] [blame] | 6448 | print "X-Git-Tag: $tagname\n" if $tagname; |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6449 | print "X-Git-Url: " . $cgi->self_url() . "\n\n"; |
Jakub Narebski | edf735a | 2006-08-24 19:45:30 +0200 | [diff] [blame] | 6450 | |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6451 | foreach my $line (@{$co{'comment'}}) { |
Yasushi SHOJI | 7720224 | 2008-01-29 21:16:02 +0900 | [diff] [blame] | 6452 | print to_utf8($line) . "\n"; |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6453 | } |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6454 | print "---\n\n"; |
Giuseppe Bilotta | 9872cd6 | 2008-12-18 08:13:16 +0100 | [diff] [blame] | 6455 | } elsif ($format eq 'patch') { |
| 6456 | my $filename = basename($project) . "-$hash.patch"; |
| 6457 | |
| 6458 | print $cgi->header( |
| 6459 | -type => 'text/plain', |
| 6460 | -charset => 'utf-8', |
| 6461 | -expires => $expires, |
| 6462 | -content_disposition => 'inline; filename="' . "$filename" . '"'); |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6463 | } |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6464 | |
| 6465 | # write patch |
| 6466 | if ($format eq 'html') { |
Jakub Narebski | cd030c3 | 2007-06-08 13:33:28 +0200 | [diff] [blame] | 6467 | my $use_parents = !defined $hash_parent || |
| 6468 | $hash_parent eq '-c' || $hash_parent eq '--cc'; |
| 6469 | git_difftree_body(\@difftree, $hash, |
| 6470 | $use_parents ? @{$co{'parents'}} : $hash_parent); |
Jakub Narebski | b4657e7 | 2006-08-28 14:48:14 +0200 | [diff] [blame] | 6471 | print "<br/>\n"; |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6472 | |
Jakub Narebski | cd030c3 | 2007-06-08 13:33:28 +0200 | [diff] [blame] | 6473 | git_patchset_body($fd, \@difftree, $hash, |
| 6474 | $use_parents ? @{$co{'parents'}} : $hash_parent); |
Jakub Narebski | 157e43b | 2006-08-24 19:34:36 +0200 | [diff] [blame] | 6475 | close $fd; |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6476 | print "</div>\n"; # class="page_body" |
| 6477 | git_footer_html(); |
| 6478 | |
| 6479 | } elsif ($format eq 'plain') { |
| 6480 | local $/ = undef; |
| 6481 | print <$fd>; |
| 6482 | close $fd |
| 6483 | or print "Reading git-diff-tree failed\n"; |
Giuseppe Bilotta | 9872cd6 | 2008-12-18 08:13:16 +0100 | [diff] [blame] | 6484 | } elsif ($format eq 'patch') { |
| 6485 | local $/ = undef; |
| 6486 | print <$fd>; |
| 6487 | close $fd |
| 6488 | or print "Reading git-format-patch failed\n"; |
Jakub Narebski | eee0890 | 2006-08-24 00:15:14 +0200 | [diff] [blame] | 6489 | } |
| 6490 | } |
| 6491 | |
| 6492 | sub git_commitdiff_plain { |
Giuseppe Bilotta | 2020985 | 2008-12-18 08:13:17 +0100 | [diff] [blame] | 6493 | git_commitdiff(-format => 'plain'); |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6494 | } |
| 6495 | |
Giuseppe Bilotta | 9872cd6 | 2008-12-18 08:13:16 +0100 | [diff] [blame] | 6496 | # format-patch-style patches |
| 6497 | sub git_patch { |
Jakub Narebski | 1655c98 | 2009-10-09 14:26:44 +0200 | [diff] [blame] | 6498 | git_commitdiff(-format => 'patch', -single => 1); |
Giuseppe Bilotta | a3411f8 | 2008-12-18 08:13:18 +0100 | [diff] [blame] | 6499 | } |
| 6500 | |
| 6501 | sub git_patches { |
Giuseppe Bilotta | 2020985 | 2008-12-18 08:13:17 +0100 | [diff] [blame] | 6502 | git_commitdiff(-format => 'patch'); |
Kay Sievers | 09bd789 | 2005-08-07 20:21:23 +0200 | [diff] [blame] | 6503 | } |
| 6504 | |
| 6505 | sub git_history { |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 6506 | git_log_generic('history', \&git_history_body, |
| 6507 | $hash_base, $hash_parent_base, |
| 6508 | $file_name, $hash); |
Kay Sievers | 161332a | 2005-08-07 19:49:46 +0200 | [diff] [blame] | 6509 | } |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6510 | |
| 6511 | sub git_search { |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 6512 | gitweb_check_feature('search') or die_error(403, "Search is disabled"); |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6513 | if (!defined $searchtext) { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6514 | die_error(400, "Text field is empty"); |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6515 | } |
| 6516 | if (!defined $hash) { |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 6517 | $hash = git_get_head_hash($project); |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6518 | } |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 6519 | my %co = parse_commit($hash); |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6520 | if (!%co) { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6521 | die_error(404, "Unknown commit object"); |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6522 | } |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 6523 | if (!defined $page) { |
| 6524 | $page = 0; |
| 6525 | } |
Jakub Narebski | 04f7a94 | 2006-09-11 00:29:27 +0200 | [diff] [blame] | 6526 | |
Petr Baudis | 88ad729 | 2006-10-24 05:15:46 +0200 | [diff] [blame] | 6527 | $searchtype ||= 'commit'; |
| 6528 | if ($searchtype eq 'pickaxe') { |
Jakub Narebski | 04f7a94 | 2006-09-11 00:29:27 +0200 | [diff] [blame] | 6529 | # pickaxe may take all resources of your box and run for several minutes |
| 6530 | # with every query - so decide by yourself how public you make this feature |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 6531 | gitweb_check_feature('pickaxe') |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6532 | or die_error(403, "Pickaxe is disabled"); |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 6533 | } |
Petr Baudis | e773855 | 2007-05-17 04:31:12 +0200 | [diff] [blame] | 6534 | if ($searchtype eq 'grep') { |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 6535 | gitweb_check_feature('grep') |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6536 | or die_error(403, "Grep is disabled"); |
Petr Baudis | e773855 | 2007-05-17 04:31:12 +0200 | [diff] [blame] | 6537 | } |
Petr Baudis | 88ad729 | 2006-10-24 05:15:46 +0200 | [diff] [blame] | 6538 | |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6539 | git_header_html(); |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6540 | |
Petr Baudis | 88ad729 | 2006-10-24 05:15:46 +0200 | [diff] [blame] | 6541 | if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') { |
Robert Fitzsimons | 8e574fb | 2006-12-23 03:35:14 +0000 | [diff] [blame] | 6542 | my $greptype; |
| 6543 | if ($searchtype eq 'commit') { |
| 6544 | $greptype = "--grep="; |
| 6545 | } elsif ($searchtype eq 'author') { |
| 6546 | $greptype = "--author="; |
| 6547 | } elsif ($searchtype eq 'committer') { |
| 6548 | $greptype = "--committer="; |
| 6549 | } |
Jakub Narebski | 0270cd0 | 2008-02-26 13:22:07 +0100 | [diff] [blame] | 6550 | $greptype .= $searchtext; |
| 6551 | my @commitlist = parse_commits($hash, 101, (100 * $page), undef, |
Petr Baudis | 0e55991 | 2008-02-26 13:22:08 +0100 | [diff] [blame] | 6552 | $greptype, '--regexp-ignore-case', |
| 6553 | $search_use_regexp ? '--extended-regexp' : '--fixed-strings'); |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 6554 | |
| 6555 | my $paging_nav = ''; |
| 6556 | if ($page > 0) { |
| 6557 | $paging_nav .= |
| 6558 | $cgi->a({-href => href(action=>"search", hash=>$hash, |
Jakub Narebski | 0270cd0 | 2008-02-26 13:22:07 +0100 | [diff] [blame] | 6559 | searchtext=>$searchtext, |
| 6560 | searchtype=>$searchtype)}, |
Jakub Narebski | a23f0a7 | 2007-04-01 22:21:38 +0200 | [diff] [blame] | 6561 | "first"); |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 6562 | $paging_nav .= " ⋅ " . |
Jakub Narebski | 7afd77b | 2007-11-01 13:06:28 +0100 | [diff] [blame] | 6563 | $cgi->a({-href => href(-replay=>1, page=>$page-1), |
Jakub Narebski | a23f0a7 | 2007-04-01 22:21:38 +0200 | [diff] [blame] | 6564 | -accesskey => "p", -title => "Alt-p"}, "prev"); |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 6565 | } else { |
| 6566 | $paging_nav .= "first"; |
| 6567 | $paging_nav .= " ⋅ prev"; |
| 6568 | } |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 6569 | my $next_link = ''; |
Robert Fitzsimons | 5ad6608 | 2006-12-24 14:31:46 +0000 | [diff] [blame] | 6570 | if ($#commitlist >= 100) { |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 6571 | $next_link = |
Jakub Narebski | 7afd77b | 2007-11-01 13:06:28 +0100 | [diff] [blame] | 6572 | $cgi->a({-href => href(-replay=>1, page=>$page+1), |
Jakub Narebski | a23f0a7 | 2007-04-01 22:21:38 +0200 | [diff] [blame] | 6573 | -accesskey => "n", -title => "Alt-n"}, "next"); |
Jakub Narebski | 7afd77b | 2007-11-01 13:06:28 +0100 | [diff] [blame] | 6574 | $paging_nav .= " ⋅ $next_link"; |
| 6575 | } else { |
| 6576 | $paging_nav .= " ⋅ next"; |
| 6577 | } |
| 6578 | |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 6579 | git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav); |
| 6580 | git_print_header_div('commit', esc_html($co{'title'}), $hash); |
Jonathan Nieder | 497d9c3 | 2010-08-07 16:56:47 -0500 | [diff] [blame] | 6581 | if ($page == 0 && !@commitlist) { |
| 6582 | print "<p>No match.</p>\n"; |
| 6583 | } else { |
| 6584 | git_search_grep_body(\@commitlist, 0, 99, $next_link); |
| 6585 | } |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 6586 | } |
| 6587 | |
Petr Baudis | 88ad729 | 2006-10-24 05:15:46 +0200 | [diff] [blame] | 6588 | if ($searchtype eq 'pickaxe') { |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 6589 | git_print_page_nav('','', $hash,$co{'tree'},$hash); |
| 6590 | git_print_header_div('commit', esc_html($co{'title'}), $hash); |
| 6591 | |
Jakub Narebski | 591ebf6 | 2007-11-19 14:16:11 +0100 | [diff] [blame] | 6592 | print "<table class=\"pickaxe search\">\n"; |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 6593 | my $alternate = 1; |
Jakub Narebski | 34122b5 | 2009-05-11 03:29:40 +0200 | [diff] [blame] | 6594 | local $/ = "\n"; |
Jakub Narebski | c582aba | 2008-03-05 09:31:55 +0100 | [diff] [blame] | 6595 | open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts, |
| 6596 | '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext", |
| 6597 | ($search_use_regexp ? '--pickaxe-regex' : ()); |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 6598 | undef %co; |
| 6599 | my @files; |
| 6600 | while (my $line = <$fd>) { |
Jakub Narebski | c582aba | 2008-03-05 09:31:55 +0100 | [diff] [blame] | 6601 | chomp $line; |
| 6602 | next unless $line; |
| 6603 | |
| 6604 | my %set = parse_difftree_raw_line($line); |
| 6605 | if (defined $set{'commit'}) { |
| 6606 | # finish previous commit |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 6607 | if (%co) { |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 6608 | print "</td>\n" . |
| 6609 | "<td class=\"link\">" . |
Martin Waitz | 756d2f0 | 2006-08-17 00:28:36 +0200 | [diff] [blame] | 6610 | $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") . |
Jakub Narebski | 952c65f | 2006-08-22 16:52:50 +0200 | [diff] [blame] | 6611 | " | " . |
| 6612 | $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree"); |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 6613 | print "</td>\n" . |
| 6614 | "</tr>\n"; |
| 6615 | } |
Jakub Narebski | c582aba | 2008-03-05 09:31:55 +0100 | [diff] [blame] | 6616 | |
| 6617 | if ($alternate) { |
| 6618 | print "<tr class=\"dark\">\n"; |
| 6619 | } else { |
| 6620 | print "<tr class=\"light\">\n"; |
| 6621 | } |
| 6622 | $alternate ^= 1; |
| 6623 | %co = parse_commit($set{'commit'}); |
| 6624 | my $author = chop_and_escape_str($co{'author_name'}, 15, 5); |
| 6625 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . |
| 6626 | "<td><i>$author</i></td>\n" . |
| 6627 | "<td>" . |
| 6628 | $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), |
| 6629 | -class => "list subject"}, |
| 6630 | chop_and_escape_str($co{'title'}, 50) . "<br/>"); |
| 6631 | } elsif (defined $set{'to_id'}) { |
| 6632 | next if ($set{'to_id'} =~ m/^0{40}$/); |
| 6633 | |
| 6634 | print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'}, |
| 6635 | hash=>$set{'to_id'}, file_name=>$set{'to_file'}), |
| 6636 | -class => "list"}, |
| 6637 | "<span class=\"match\">" . esc_path($set{'file'}) . "</span>") . |
| 6638 | "<br/>\n"; |
Kay Sievers | c994d62 | 2005-08-07 20:27:18 +0200 | [diff] [blame] | 6639 | } |
| 6640 | } |
| 6641 | close $fd; |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 6642 | |
Jakub Narebski | c582aba | 2008-03-05 09:31:55 +0100 | [diff] [blame] | 6643 | # finish last commit (warning: repetition!) |
| 6644 | if (%co) { |
| 6645 | print "</td>\n" . |
| 6646 | "<td class=\"link\">" . |
| 6647 | $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") . |
| 6648 | " | " . |
| 6649 | $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree"); |
| 6650 | print "</td>\n" . |
| 6651 | "</tr>\n"; |
| 6652 | } |
| 6653 | |
Robert Fitzsimons | 8dbc0fc | 2006-12-23 14:57:12 +0000 | [diff] [blame] | 6654 | print "</table>\n"; |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6655 | } |
Petr Baudis | e773855 | 2007-05-17 04:31:12 +0200 | [diff] [blame] | 6656 | |
| 6657 | if ($searchtype eq 'grep') { |
| 6658 | git_print_page_nav('','', $hash,$co{'tree'},$hash); |
| 6659 | git_print_header_div('commit', esc_html($co{'title'}), $hash); |
| 6660 | |
Jakub Narebski | 591ebf6 | 2007-11-19 14:16:11 +0100 | [diff] [blame] | 6661 | print "<table class=\"grep_search\">\n"; |
Petr Baudis | e773855 | 2007-05-17 04:31:12 +0200 | [diff] [blame] | 6662 | my $alternate = 1; |
| 6663 | my $matches = 0; |
Jakub Narebski | 34122b5 | 2009-05-11 03:29:40 +0200 | [diff] [blame] | 6664 | local $/ = "\n"; |
Petr Baudis | 0e55991 | 2008-02-26 13:22:08 +0100 | [diff] [blame] | 6665 | open my $fd, "-|", git_cmd(), 'grep', '-n', |
| 6666 | $search_use_regexp ? ('-E', '-i') : '-F', |
| 6667 | $searchtext, $co{'tree'}; |
Petr Baudis | e773855 | 2007-05-17 04:31:12 +0200 | [diff] [blame] | 6668 | my $lastfile = ''; |
| 6669 | while (my $line = <$fd>) { |
| 6670 | chomp $line; |
| 6671 | my ($file, $lno, $ltext, $binary); |
| 6672 | last if ($matches++ > 1000); |
| 6673 | if ($line =~ /^Binary file (.+) matches$/) { |
| 6674 | $file = $1; |
| 6675 | $binary = 1; |
| 6676 | } else { |
| 6677 | (undef, $file, $lno, $ltext) = split(/:/, $line, 4); |
| 6678 | } |
| 6679 | if ($file ne $lastfile) { |
| 6680 | $lastfile and print "</td></tr>\n"; |
| 6681 | if ($alternate++) { |
| 6682 | print "<tr class=\"dark\">\n"; |
| 6683 | } else { |
| 6684 | print "<tr class=\"light\">\n"; |
| 6685 | } |
| 6686 | print "<td class=\"list\">". |
| 6687 | $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'}, |
| 6688 | file_name=>"$file"), |
| 6689 | -class => "list"}, esc_path($file)); |
| 6690 | print "</td><td>\n"; |
| 6691 | $lastfile = $file; |
| 6692 | } |
| 6693 | if ($binary) { |
| 6694 | print "<div class=\"binary\">Binary file</div>\n"; |
| 6695 | } else { |
| 6696 | $ltext = untabify($ltext); |
Petr Baudis | 0e55991 | 2008-02-26 13:22:08 +0100 | [diff] [blame] | 6697 | if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) { |
Petr Baudis | e773855 | 2007-05-17 04:31:12 +0200 | [diff] [blame] | 6698 | $ltext = esc_html($1, -nbsp=>1); |
| 6699 | $ltext .= '<span class="match">'; |
| 6700 | $ltext .= esc_html($2, -nbsp=>1); |
| 6701 | $ltext .= '</span>'; |
| 6702 | $ltext .= esc_html($3, -nbsp=>1); |
| 6703 | } else { |
| 6704 | $ltext = esc_html($ltext, -nbsp=>1); |
| 6705 | } |
| 6706 | print "<div class=\"pre\">" . |
| 6707 | $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'}, |
| 6708 | file_name=>"$file").'#l'.$lno, |
| 6709 | -class => "linenr"}, sprintf('%4i', $lno)) |
| 6710 | . ' ' . $ltext . "</div>\n"; |
| 6711 | } |
| 6712 | } |
| 6713 | if ($lastfile) { |
| 6714 | print "</td></tr>\n"; |
| 6715 | if ($matches > 1000) { |
| 6716 | print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n"; |
| 6717 | } |
| 6718 | } else { |
| 6719 | print "<div class=\"diff nodifferences\">No matches found</div>\n"; |
| 6720 | } |
| 6721 | close $fd; |
| 6722 | |
| 6723 | print "</table>\n"; |
| 6724 | } |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6725 | git_footer_html(); |
| 6726 | } |
| 6727 | |
Petr Baudis | 88ad729 | 2006-10-24 05:15:46 +0200 | [diff] [blame] | 6728 | sub git_search_help { |
| 6729 | git_header_html(); |
| 6730 | git_print_page_nav('','', $hash,$hash,$hash); |
| 6731 | print <<EOT; |
Petr Baudis | 0e55991 | 2008-02-26 13:22:08 +0100 | [diff] [blame] | 6732 | <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without |
| 6733 | regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox, |
| 6734 | the pattern entered is recognized as the POSIX extended |
| 6735 | <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case |
| 6736 | insensitive).</p> |
Petr Baudis | 88ad729 | 2006-10-24 05:15:46 +0200 | [diff] [blame] | 6737 | <dl> |
| 6738 | <dt><b>commit</b></dt> |
Petr Baudis | 0e55991 | 2008-02-26 13:22:08 +0100 | [diff] [blame] | 6739 | <dd>The commit messages and authorship information will be scanned for the given pattern.</dd> |
Petr Baudis | e773855 | 2007-05-17 04:31:12 +0200 | [diff] [blame] | 6740 | EOT |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 6741 | my $have_grep = gitweb_check_feature('grep'); |
Petr Baudis | e773855 | 2007-05-17 04:31:12 +0200 | [diff] [blame] | 6742 | if ($have_grep) { |
| 6743 | print <<EOT; |
| 6744 | <dt><b>grep</b></dt> |
| 6745 | <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing |
Petr Baudis | 0e55991 | 2008-02-26 13:22:08 +0100 | [diff] [blame] | 6746 | a different one) are searched for the given pattern. On large trees, this search can take |
| 6747 | a while and put some strain on the server, so please use it with some consideration. Note that |
| 6748 | due to git-grep peculiarity, currently if regexp mode is turned off, the matches are |
| 6749 | case-sensitive.</dd> |
Petr Baudis | e773855 | 2007-05-17 04:31:12 +0200 | [diff] [blame] | 6750 | EOT |
| 6751 | } |
| 6752 | print <<EOT; |
Petr Baudis | 88ad729 | 2006-10-24 05:15:46 +0200 | [diff] [blame] | 6753 | <dt><b>author</b></dt> |
Petr Baudis | 0e55991 | 2008-02-26 13:22:08 +0100 | [diff] [blame] | 6754 | <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd> |
Petr Baudis | 88ad729 | 2006-10-24 05:15:46 +0200 | [diff] [blame] | 6755 | <dt><b>committer</b></dt> |
Petr Baudis | 0e55991 | 2008-02-26 13:22:08 +0100 | [diff] [blame] | 6756 | <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd> |
Petr Baudis | 88ad729 | 2006-10-24 05:15:46 +0200 | [diff] [blame] | 6757 | EOT |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 6758 | my $have_pickaxe = gitweb_check_feature('pickaxe'); |
Petr Baudis | 88ad729 | 2006-10-24 05:15:46 +0200 | [diff] [blame] | 6759 | if ($have_pickaxe) { |
| 6760 | print <<EOT; |
| 6761 | <dt><b>pickaxe</b></dt> |
| 6762 | <dd>All commits that caused the string to appear or disappear from any file (changes that |
| 6763 | added, removed or "modified" the string) will be listed. This search can take a while and |
Petr Baudis | 0e55991 | 2008-02-26 13:22:08 +0100 | [diff] [blame] | 6764 | takes a lot of strain on the server, so please use it wisely. Note that since you may be |
| 6765 | interested even in changes just changing the case as well, this search is case sensitive.</dd> |
Petr Baudis | 88ad729 | 2006-10-24 05:15:46 +0200 | [diff] [blame] | 6766 | EOT |
| 6767 | } |
| 6768 | print "</dl>\n"; |
| 6769 | git_footer_html(); |
| 6770 | } |
| 6771 | |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6772 | sub git_shortlog { |
Jakub Narebski | 69ca37d | 2009-11-13 02:02:14 +0100 | [diff] [blame] | 6773 | git_log_generic('shortlog', \&git_shortlog_body, |
| 6774 | $hash, $hash_parent); |
Kay Sievers | 1980669 | 2005-08-07 20:26:27 +0200 | [diff] [blame] | 6775 | } |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 6776 | |
| 6777 | ## ...................................................................... |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6778 | ## feeds (RSS, Atom; OPML) |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 6779 | |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6780 | sub git_feed { |
| 6781 | my $format = shift || 'atom'; |
Giuseppe Bilotta | 25b2790 | 2008-11-29 13:07:29 -0800 | [diff] [blame] | 6782 | my $have_blame = gitweb_check_feature('blame'); |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6783 | |
| 6784 | # Atom: http://www.atomenabled.org/developers/syndication/ |
| 6785 | # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ |
| 6786 | if ($format ne 'rss' && $format ne 'atom') { |
Lea Wiemann | 074afaa | 2008-06-19 22:03:21 +0200 | [diff] [blame] | 6787 | die_error(400, "Unknown web feed format"); |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6788 | } |
| 6789 | |
| 6790 | # log/feed of current (HEAD) branch, log of given branch, history of file/directory |
| 6791 | my $head = $hash || 'HEAD'; |
Jakub Narebski | 311e552 | 2008-02-26 13:22:06 +0100 | [diff] [blame] | 6792 | my @commitlist = parse_commits($head, 150, 0, $file_name); |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6793 | |
| 6794 | my %latest_commit; |
| 6795 | my %latest_date; |
| 6796 | my $content_type = "application/$format+xml"; |
| 6797 | if (defined $cgi->http('HTTP_ACCEPT') && |
| 6798 | $cgi->Accept('text/xml') > $cgi->Accept($content_type)) { |
| 6799 | # browser (feed reader) prefers text/xml |
| 6800 | $content_type = 'text/xml'; |
| 6801 | } |
Robert Fitzsimons | b6093a5 | 2006-12-24 14:31:47 +0000 | [diff] [blame] | 6802 | if (defined($commitlist[0])) { |
| 6803 | %latest_commit = %{$commitlist[0]}; |
Giuseppe Bilotta | cd956c7 | 2009-01-26 12:50:16 +0100 | [diff] [blame] | 6804 | my $latest_epoch = $latest_commit{'committer_epoch'}; |
| 6805 | %latest_date = parse_date($latest_epoch); |
| 6806 | my $if_modified = $cgi->http('IF_MODIFIED_SINCE'); |
| 6807 | if (defined $if_modified) { |
| 6808 | my $since; |
| 6809 | if (eval { require HTTP::Date; 1; }) { |
| 6810 | $since = HTTP::Date::str2time($if_modified); |
| 6811 | } elsif (eval { require Time::ParseDate; 1; }) { |
| 6812 | $since = Time::ParseDate::parsedate($if_modified, GMT => 1); |
| 6813 | } |
| 6814 | if (defined $since && $latest_epoch <= $since) { |
| 6815 | print $cgi->header( |
| 6816 | -type => $content_type, |
| 6817 | -charset => 'utf-8', |
| 6818 | -last_modified => $latest_date{'rfc2822'}, |
| 6819 | -status => '304 Not Modified'); |
| 6820 | return; |
| 6821 | } |
| 6822 | } |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6823 | print $cgi->header( |
| 6824 | -type => $content_type, |
| 6825 | -charset => 'utf-8', |
| 6826 | -last_modified => $latest_date{'rfc2822'}); |
| 6827 | } else { |
| 6828 | print $cgi->header( |
| 6829 | -type => $content_type, |
| 6830 | -charset => 'utf-8'); |
| 6831 | } |
| 6832 | |
| 6833 | # Optimization: skip generating the body if client asks only |
| 6834 | # for Last-Modified date. |
| 6835 | return if ($cgi->request_method() eq 'HEAD'); |
| 6836 | |
| 6837 | # header variables |
| 6838 | my $title = "$site_name - $project/$action"; |
| 6839 | my $feed_type = 'log'; |
| 6840 | if (defined $hash) { |
| 6841 | $title .= " - '$hash'"; |
| 6842 | $feed_type = 'branch log'; |
| 6843 | if (defined $file_name) { |
| 6844 | $title .= " :: $file_name"; |
| 6845 | $feed_type = 'history'; |
| 6846 | } |
| 6847 | } elsif (defined $file_name) { |
| 6848 | $title .= " - $file_name"; |
| 6849 | $feed_type = 'history'; |
| 6850 | } |
| 6851 | $title .= " $feed_type"; |
| 6852 | my $descr = git_get_project_description($project); |
| 6853 | if (defined $descr) { |
| 6854 | $descr = esc_html($descr); |
| 6855 | } else { |
| 6856 | $descr = "$project " . |
| 6857 | ($format eq 'rss' ? 'RSS' : 'Atom') . |
| 6858 | " feed"; |
| 6859 | } |
| 6860 | my $owner = git_get_project_owner($project); |
| 6861 | $owner = esc_html($owner); |
| 6862 | |
| 6863 | #header |
| 6864 | my $alt_url; |
| 6865 | if (defined $file_name) { |
| 6866 | $alt_url = href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name); |
| 6867 | } elsif (defined $hash) { |
| 6868 | $alt_url = href(-full=>1, action=>"log", hash=>$hash); |
| 6869 | } else { |
| 6870 | $alt_url = href(-full=>1, action=>"summary"); |
| 6871 | } |
| 6872 | print qq!<?xml version="1.0" encoding="utf-8"?>\n!; |
| 6873 | if ($format eq 'rss') { |
| 6874 | print <<XML; |
Jakub Narebski | 59b9f61 | 2006-08-22 23:42:53 +0200 | [diff] [blame] | 6875 | <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"> |
| 6876 | <channel> |
Jakub Narebski | 59b9f61 | 2006-08-22 23:42:53 +0200 | [diff] [blame] | 6877 | XML |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6878 | print "<title>$title</title>\n" . |
| 6879 | "<link>$alt_url</link>\n" . |
| 6880 | "<description>$descr</description>\n" . |
Giuseppe Bilotta | 3ac109a | 2009-01-26 12:50:13 +0100 | [diff] [blame] | 6881 | "<language>en</language>\n" . |
| 6882 | # project owner is responsible for 'editorial' content |
| 6883 | "<managingEditor>$owner</managingEditor>\n"; |
Giuseppe Bilotta | 1ba68ce | 2009-01-26 12:50:11 +0100 | [diff] [blame] | 6884 | if (defined $logo || defined $favicon) { |
| 6885 | # prefer the logo to the favicon, since RSS |
| 6886 | # doesn't allow both |
| 6887 | my $img = esc_url($logo || $favicon); |
| 6888 | print "<image>\n" . |
| 6889 | "<url>$img</url>\n" . |
| 6890 | "<title>$title</title>\n" . |
| 6891 | "<link>$alt_url</link>\n" . |
| 6892 | "</image>\n"; |
| 6893 | } |
Giuseppe Bilotta | 0cf3128 | 2009-01-26 12:50:14 +0100 | [diff] [blame] | 6894 | if (%latest_date) { |
| 6895 | print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n"; |
| 6896 | print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n"; |
| 6897 | } |
Giuseppe Bilotta | ad59a7a | 2009-01-26 12:50:12 +0100 | [diff] [blame] | 6898 | print "<generator>gitweb v.$version/$git_version</generator>\n"; |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6899 | } elsif ($format eq 'atom') { |
| 6900 | print <<XML; |
| 6901 | <feed xmlns="http://www.w3.org/2005/Atom"> |
| 6902 | XML |
| 6903 | print "<title>$title</title>\n" . |
| 6904 | "<subtitle>$descr</subtitle>\n" . |
| 6905 | '<link rel="alternate" type="text/html" href="' . |
| 6906 | $alt_url . '" />' . "\n" . |
| 6907 | '<link rel="self" type="' . $content_type . '" href="' . |
| 6908 | $cgi->self_url() . '" />' . "\n" . |
| 6909 | "<id>" . href(-full=>1) . "</id>\n" . |
| 6910 | # use project owner for feed author |
| 6911 | "<author><name>$owner</name></author>\n"; |
| 6912 | if (defined $favicon) { |
| 6913 | print "<icon>" . esc_url($favicon) . "</icon>\n"; |
| 6914 | } |
| 6915 | if (defined $logo_url) { |
| 6916 | # not twice as wide as tall: 72 x 27 pixels |
Jakub Narebski | e114726 | 2006-12-04 14:09:43 +0100 | [diff] [blame] | 6917 | print "<logo>" . esc_url($logo) . "</logo>\n"; |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6918 | } |
| 6919 | if (! %latest_date) { |
| 6920 | # dummy date to keep the feed valid until commits trickle in: |
| 6921 | print "<updated>1970-01-01T00:00:00Z</updated>\n"; |
| 6922 | } else { |
| 6923 | print "<updated>$latest_date{'iso-8601'}</updated>\n"; |
| 6924 | } |
Giuseppe Bilotta | ad59a7a | 2009-01-26 12:50:12 +0100 | [diff] [blame] | 6925 | print "<generator version='$version/$git_version'>gitweb</generator>\n"; |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6926 | } |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 6927 | |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6928 | # contents |
Robert Fitzsimons | b6093a5 | 2006-12-24 14:31:47 +0000 | [diff] [blame] | 6929 | for (my $i = 0; $i <= $#commitlist; $i++) { |
| 6930 | my %co = %{$commitlist[$i]}; |
| 6931 | my $commit = $co{'id'}; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 6932 | # we read 150, we always show 30 and the ones more recent than 48 hours |
Jakub Narebski | 91fd2bf | 2006-11-25 15:54:34 +0100 | [diff] [blame] | 6933 | if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) { |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 6934 | last; |
| 6935 | } |
Jakub Narebski | 91fd2bf | 2006-11-25 15:54:34 +0100 | [diff] [blame] | 6936 | my %cd = parse_date($co{'author_epoch'}); |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6937 | |
| 6938 | # get list of changed files |
Robert Fitzsimons | b6093a5 | 2006-12-24 14:31:47 +0000 | [diff] [blame] | 6939 | open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
Jakub Narebski | c906b18 | 2007-05-19 02:47:51 +0200 | [diff] [blame] | 6940 | $co{'parent'} || "--root", |
| 6941 | $co{'id'}, "--", (defined $file_name ? $file_name : ()) |
Jakub Narebski | 6bcf4b4 | 2006-08-27 23:49:36 +0200 | [diff] [blame] | 6942 | or next; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 6943 | my @difftree = map { chomp; $_ } <$fd>; |
Jakub Narebski | 6bcf4b4 | 2006-08-27 23:49:36 +0200 | [diff] [blame] | 6944 | close $fd |
| 6945 | or next; |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6946 | |
| 6947 | # print element (entry, item) |
Florian La Roche | e62a641 | 2008-02-03 12:38:46 +0100 | [diff] [blame] | 6948 | my $co_url = href(-full=>1, action=>"commitdiff", hash=>$commit); |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6949 | if ($format eq 'rss') { |
| 6950 | print "<item>\n" . |
| 6951 | "<title>" . esc_html($co{'title'}) . "</title>\n" . |
| 6952 | "<author>" . esc_html($co{'author'}) . "</author>\n" . |
| 6953 | "<pubDate>$cd{'rfc2822'}</pubDate>\n" . |
| 6954 | "<guid isPermaLink=\"true\">$co_url</guid>\n" . |
| 6955 | "<link>$co_url</link>\n" . |
| 6956 | "<description>" . esc_html($co{'title'}) . "</description>\n" . |
| 6957 | "<content:encoded>" . |
| 6958 | "<![CDATA[\n"; |
| 6959 | } elsif ($format eq 'atom') { |
| 6960 | print "<entry>\n" . |
| 6961 | "<title type=\"html\">" . esc_html($co{'title'}) . "</title>\n" . |
| 6962 | "<updated>$cd{'iso-8601'}</updated>\n" . |
Jakub Narebski | ab23c19 | 2006-11-25 15:54:33 +0100 | [diff] [blame] | 6963 | "<author>\n" . |
| 6964 | " <name>" . esc_html($co{'author_name'}) . "</name>\n"; |
| 6965 | if ($co{'author_email'}) { |
| 6966 | print " <email>" . esc_html($co{'author_email'}) . "</email>\n"; |
| 6967 | } |
| 6968 | print "</author>\n" . |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6969 | # use committer for contributor |
Jakub Narebski | ab23c19 | 2006-11-25 15:54:33 +0100 | [diff] [blame] | 6970 | "<contributor>\n" . |
| 6971 | " <name>" . esc_html($co{'committer_name'}) . "</name>\n"; |
| 6972 | if ($co{'committer_email'}) { |
| 6973 | print " <email>" . esc_html($co{'committer_email'}) . "</email>\n"; |
| 6974 | } |
| 6975 | print "</contributor>\n" . |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6976 | "<published>$cd{'iso-8601'}</published>\n" . |
| 6977 | "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" . |
| 6978 | "<id>$co_url</id>\n" . |
| 6979 | "<content type=\"xhtml\" xml:base=\"" . esc_url($my_url) . "\">\n" . |
| 6980 | "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n"; |
| 6981 | } |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 6982 | my $comment = $co{'comment'}; |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6983 | print "<pre>\n"; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 6984 | foreach my $line (@$comment) { |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6985 | $line = esc_html($line); |
| 6986 | print "$line\n"; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 6987 | } |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 6988 | print "</pre><ul>\n"; |
| 6989 | foreach my $difftree_line (@difftree) { |
| 6990 | my %difftree = parse_difftree_raw_line($difftree_line); |
| 6991 | next if !$difftree{'from_id'}; |
| 6992 | |
| 6993 | my $file = $difftree{'file'} || $difftree{'to_file'}; |
| 6994 | |
| 6995 | print "<li>" . |
| 6996 | "[" . |
| 6997 | $cgi->a({-href => href(-full=>1, action=>"blobdiff", |
| 6998 | hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'}, |
| 6999 | hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'}, |
| 7000 | file_name=>$file, file_parent=>$difftree{'from_file'}), |
| 7001 | -title => "diff"}, 'D'); |
| 7002 | if ($have_blame) { |
| 7003 | print $cgi->a({-href => href(-full=>1, action=>"blame", |
| 7004 | file_name=>$file, hash_base=>$commit), |
| 7005 | -title => "blame"}, 'B'); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 7006 | } |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 7007 | # if this is not a feed of a file history |
| 7008 | if (!defined $file_name || $file_name ne $file) { |
| 7009 | print $cgi->a({-href => href(-full=>1, action=>"history", |
| 7010 | file_name=>$file, hash=>$commit), |
| 7011 | -title => "history"}, 'H'); |
| 7012 | } |
| 7013 | $file = esc_path($file); |
| 7014 | print "] ". |
| 7015 | "$file</li>\n"; |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 7016 | } |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 7017 | if ($format eq 'rss') { |
| 7018 | print "</ul>]]>\n" . |
| 7019 | "</content:encoded>\n" . |
| 7020 | "</item>\n"; |
| 7021 | } elsif ($format eq 'atom') { |
| 7022 | print "</ul>\n</div>\n" . |
| 7023 | "</content>\n" . |
| 7024 | "</entry>\n"; |
| 7025 | } |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 7026 | } |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 7027 | |
| 7028 | # end of feed |
| 7029 | if ($format eq 'rss') { |
| 7030 | print "</channel>\n</rss>\n"; |
Jakub Narebski | 3278fbc | 2009-05-11 19:37:28 +0200 | [diff] [blame] | 7031 | } elsif ($format eq 'atom') { |
Jakub Narebski | af6feeb | 2006-11-19 15:05:22 +0100 | [diff] [blame] | 7032 | print "</feed>\n"; |
| 7033 | } |
| 7034 | } |
| 7035 | |
| 7036 | sub git_rss { |
| 7037 | git_feed('rss'); |
| 7038 | } |
| 7039 | |
| 7040 | sub git_atom { |
| 7041 | git_feed('atom'); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 7042 | } |
| 7043 | |
| 7044 | sub git_opml { |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 7045 | my @list = git_get_projects_list(); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 7046 | |
Giuseppe Bilotta | ae35785 | 2009-01-02 13:49:30 +0100 | [diff] [blame] | 7047 | print $cgi->header( |
| 7048 | -type => 'text/xml', |
| 7049 | -charset => 'utf-8', |
| 7050 | -content_disposition => 'inline; filename="opml.xml"'); |
| 7051 | |
Jakub Narebski | 59b9f61 | 2006-08-22 23:42:53 +0200 | [diff] [blame] | 7052 | print <<XML; |
| 7053 | <?xml version="1.0" encoding="utf-8"?> |
| 7054 | <opml version="1.0"> |
| 7055 | <head> |
Petr Baudis | 8be2890 | 2006-10-24 05:18:39 +0200 | [diff] [blame] | 7056 | <title>$site_name OPML Export</title> |
Jakub Narebski | 59b9f61 | 2006-08-22 23:42:53 +0200 | [diff] [blame] | 7057 | </head> |
| 7058 | <body> |
| 7059 | <outline text="git RSS feeds"> |
| 7060 | XML |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 7061 | |
| 7062 | foreach my $pr (@list) { |
| 7063 | my %proj = %$pr; |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 7064 | my $head = git_get_head_hash($proj{'path'}); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 7065 | if (!defined $head) { |
| 7066 | next; |
| 7067 | } |
Dennis Stosberg | 25691fb | 2006-08-28 17:49:58 +0200 | [diff] [blame] | 7068 | $git_dir = "$projectroot/$proj{'path'}"; |
Jakub Narebski | 847e01f | 2006-08-14 02:05:47 +0200 | [diff] [blame] | 7069 | my %co = parse_commit($head); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 7070 | if (!%co) { |
| 7071 | next; |
| 7072 | } |
| 7073 | |
| 7074 | my $path = esc_html(chop_str($proj{'path'}, 25, 5)); |
Giuseppe Bilotta | df63fbb | 2009-01-02 13:15:28 +0100 | [diff] [blame] | 7075 | my $rss = href('project' => $proj{'path'}, 'action' => 'rss', -full => 1); |
| 7076 | my $html = href('project' => $proj{'path'}, 'action' => 'summary', -full => 1); |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 7077 | print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n"; |
| 7078 | } |
Jakub Narebski | 59b9f61 | 2006-08-22 23:42:53 +0200 | [diff] [blame] | 7079 | print <<XML; |
| 7080 | </outline> |
| 7081 | </body> |
| 7082 | </opml> |
| 7083 | XML |
Jakub Narebski | 717b831 | 2006-07-31 21:22:15 +0200 | [diff] [blame] | 7084 | } |