]>
Commit | Line | Data |
---|---|---|
161332a5 KS |
1 | #!/usr/bin/perl |
2 | ||
c994d620 | 3 | # gitweb - simple web interface to track changes in git repositories |
22fafb99 | 4 | # |
00cd0794 KS |
5 | # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org> |
6 | # (C) 2005, Christian Gierke | |
823d5dc8 | 7 | # |
d8f1c5c2 | 8 | # This program is licensed under the GPLv2 |
161332a5 KS |
9 | |
10 | use strict; | |
11 | use warnings; | |
19806691 | 12 | use CGI qw(:standard :escapeHTML -nosticky); |
7403d50b | 13 | use CGI::Util qw(unescape); |
161332a5 | 14 | use CGI::Carp qw(fatalsToBrowser); |
40c13813 | 15 | use Encode; |
b87d78d6 | 16 | use Fcntl ':mode'; |
7a13b999 | 17 | use File::Find qw(); |
cb9c6e5b | 18 | use File::Basename qw(basename); |
10bb9036 | 19 | binmode STDOUT, ':utf8'; |
161332a5 | 20 | |
b1f5f64f | 21 | BEGIN { |
3be8e720 | 22 | CGI->compile() if $ENV{'MOD_PERL'}; |
b1f5f64f JN |
23 | } |
24 | ||
4a87b43e | 25 | our $cgi = new CGI; |
06c084d2 | 26 | our $version = "++GIT_VERSION++"; |
4a87b43e DS |
27 | our $my_url = $cgi->url(); |
28 | our $my_uri = $cgi->url(-absolute => 1); | |
3e029299 | 29 | |
e130ddaa AT |
30 | # core git executable to use |
31 | # this can just be "git" if your webserver has a sensible PATH | |
06c084d2 | 32 | our $GIT = "++GIT_BINDIR++/git"; |
3f7f2710 | 33 | |
b87d78d6 | 34 | # absolute fs-path which will be prepended to the project path |
4a87b43e | 35 | #our $projectroot = "/pub/scm"; |
06c084d2 | 36 | our $projectroot = "++GITWEB_PROJECTROOT++"; |
b87d78d6 | 37 | |
b87d78d6 | 38 | # target of the home link on top of all pages |
6132b7e4 | 39 | our $home_link = $my_uri || "/"; |
b87d78d6 | 40 | |
2de21fac YS |
41 | # string of the home link on top of all pages |
42 | our $home_link_str = "++GITWEB_HOME_LINK_STR++"; | |
43 | ||
49da1daf AT |
44 | # name of your site or organization to appear in page titles |
45 | # replace this with something more descriptive for clearer bookmarks | |
8be2890c PB |
46 | our $site_name = "++GITWEB_SITENAME++" |
47 | || ($ENV{'SERVER_NAME'} || "Untitled") . " Git"; | |
49da1daf | 48 | |
b2d3476e AC |
49 | # filename of html text to include at top of each page |
50 | our $site_header = "++GITWEB_SITE_HEADER++"; | |
8ab1da2c | 51 | # html text to include at home page |
06c084d2 | 52 | our $home_text = "++GITWEB_HOMETEXT++"; |
b2d3476e AC |
53 | # filename of html text to include at bottom of each page |
54 | our $site_footer = "++GITWEB_SITE_FOOTER++"; | |
55 | ||
56 | # URI of stylesheets | |
57 | our @stylesheets = ("++GITWEB_CSS++"); | |
887a612f PB |
58 | # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. |
59 | our $stylesheet = undef; | |
9a7a62ff | 60 | # URI of GIT logo (72x27 size) |
06c084d2 | 61 | our $logo = "++GITWEB_LOGO++"; |
0b5deba1 JN |
62 | # URI of GIT favicon, assumed to be image/png type |
63 | our $favicon = "++GITWEB_FAVICON++"; | |
aedd9425 | 64 | |
9a7a62ff JN |
65 | # URI and label (title) of GIT logo link |
66 | #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; | |
67 | #our $logo_label = "git documentation"; | |
68 | our $logo_url = "http://git.or.cz/"; | |
69 | our $logo_label = "git homepage"; | |
51a7c66a | 70 | |
09bd7898 | 71 | # source of projects list |
06c084d2 | 72 | our $projects_list = "++GITWEB_LIST++"; |
b87d78d6 | 73 | |
55feb120 MH |
74 | # the width (in characters) of the projects list "Description" column |
75 | our $projects_list_description_width = 25; | |
76 | ||
b06dcf8c FL |
77 | # default order of projects list |
78 | # valid values are none, project, descr, owner, and age | |
79 | our $default_projects_order = "project"; | |
80 | ||
32f4aacc ML |
81 | # show repository only if this file exists |
82 | # (only effective if this variable evaluates to true) | |
83 | our $export_ok = "++GITWEB_EXPORT_OK++"; | |
84 | ||
85 | # only allow viewing of repositories also shown on the overview page | |
86 | our $strict_export = "++GITWEB_STRICT_EXPORT++"; | |
87 | ||
19a8721e JN |
88 | # list of git base URLs used for URL to where fetch project from, |
89 | # i.e. full URL is "$git_base_url/$project" | |
d6b7e0b9 | 90 | our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++"); |
19a8721e | 91 | |
f5aa79d9 | 92 | # default blob_plain mimetype and default charset for text/plain blob |
4a87b43e DS |
93 | our $default_blob_plain_mimetype = 'text/plain'; |
94 | our $default_text_plain_charset = undef; | |
f5aa79d9 | 95 | |
2d007374 PB |
96 | # file to use for guessing MIME types before trying /etc/mime.types |
97 | # (relative to the current git repository) | |
4a87b43e | 98 | our $mimetypes_file = undef; |
2d007374 | 99 | |
00f429af MK |
100 | # assume this charset if line contains non-UTF-8 characters; |
101 | # it should be valid encoding (see Encoding::Supported(3pm) for list), | |
102 | # for which encoding all byte sequences are valid, for example | |
103 | # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it | |
104 | # could be even 'utf-8' for the old behavior) | |
105 | our $fallback_encoding = 'latin1'; | |
106 | ||
69a9b41c JN |
107 | # rename detection options for git-diff and git-diff-tree |
108 | # - default is '-M', with the cost proportional to | |
109 | # (number of removed files) * (number of new files). | |
110 | # - more costly is '-C' (which implies '-M'), with the cost proportional to | |
111 | # (number of changed files + number of removed files) * (number of new files) | |
112 | # - even more costly is '-C', '--find-copies-harder' with cost | |
113 | # (number of files in the original tree) * (number of new files) | |
114 | # - one might want to include '-B' option, e.g. '-B', '-M' | |
115 | our @diff_opts = ('-M'); # taken from git_commit | |
116 | ||
a3c8ab30 MM |
117 | # information about snapshot formats that gitweb is capable of serving |
118 | our %known_snapshot_formats = ( | |
119 | # name => { | |
120 | # 'display' => display name, | |
121 | # 'type' => mime type, | |
122 | # 'suffix' => filename suffix, | |
123 | # 'format' => --format for git-archive, | |
124 | # 'compressor' => [compressor command and arguments] | |
125 | # (array reference, optional)} | |
126 | # | |
127 | 'tgz' => { | |
128 | 'display' => 'tar.gz', | |
129 | 'type' => 'application/x-gzip', | |
130 | 'suffix' => '.tar.gz', | |
131 | 'format' => 'tar', | |
132 | 'compressor' => ['gzip']}, | |
133 | ||
134 | 'tbz2' => { | |
135 | 'display' => 'tar.bz2', | |
136 | 'type' => 'application/x-bzip2', | |
137 | 'suffix' => '.tar.bz2', | |
138 | 'format' => 'tar', | |
139 | 'compressor' => ['bzip2']}, | |
140 | ||
141 | 'zip' => { | |
142 | 'display' => 'zip', | |
143 | 'type' => 'application/x-zip', | |
144 | 'suffix' => '.zip', | |
145 | 'format' => 'zip'}, | |
146 | ); | |
147 | ||
148 | # Aliases so we understand old gitweb.snapshot values in repository | |
149 | # configuration. | |
150 | our %known_snapshot_format_aliases = ( | |
151 | 'gzip' => 'tgz', | |
152 | 'bzip2' => 'tbz2', | |
153 | ||
154 | # backward compatibility: legacy gitweb config support | |
155 | 'x-gzip' => undef, 'gz' => undef, | |
156 | 'x-bzip2' => undef, 'bz2' => undef, | |
157 | 'x-zip' => undef, '' => undef, | |
158 | ); | |
159 | ||
ddb8d900 AK |
160 | # You define site-wide feature defaults here; override them with |
161 | # $GITWEB_CONFIG as necessary. | |
952c65fc | 162 | our %feature = ( |
17848fc6 JN |
163 | # feature => { |
164 | # 'sub' => feature-sub (subroutine), | |
165 | # 'override' => allow-override (boolean), | |
166 | # 'default' => [ default options...] (array reference)} | |
167 | # | |
b4b20b21 | 168 | # if feature is overridable (it means that allow-override has true value), |
17848fc6 JN |
169 | # then feature-sub will be called with default options as parameters; |
170 | # return value of feature-sub indicates if to enable specified feature | |
171 | # | |
b4b20b21 JN |
172 | # if there is no 'sub' key (no feature-sub), then feature cannot be |
173 | # overriden | |
174 | # | |
17848fc6 | 175 | # use gitweb_check_feature(<feature>) to check if <feature> is enabled |
952c65fc | 176 | |
45a3b12c PB |
177 | # Enable the 'blame' blob view, showing the last commit that modified |
178 | # each line in the file. This can be very CPU-intensive. | |
179 | ||
180 | # To enable system wide have in $GITWEB_CONFIG | |
181 | # $feature{'blame'}{'default'} = [1]; | |
182 | # To have project specific config enable override in $GITWEB_CONFIG | |
183 | # $feature{'blame'}{'override'} = 1; | |
184 | # and in project config gitweb.blame = 0|1; | |
952c65fc JN |
185 | 'blame' => { |
186 | 'sub' => \&feature_blame, | |
187 | 'override' => 0, | |
188 | 'default' => [0]}, | |
189 | ||
a3c8ab30 | 190 | # Enable the 'snapshot' link, providing a compressed archive of any |
45a3b12c PB |
191 | # tree. This can potentially generate high traffic if you have large |
192 | # project. | |
193 | ||
a3c8ab30 MM |
194 | # Value is a list of formats defined in %known_snapshot_formats that |
195 | # you wish to offer. | |
45a3b12c | 196 | # To disable system wide have in $GITWEB_CONFIG |
a3c8ab30 | 197 | # $feature{'snapshot'}{'default'} = []; |
45a3b12c | 198 | # To have project specific config enable override in $GITWEB_CONFIG |
bbee1d97 | 199 | # $feature{'snapshot'}{'override'} = 1; |
a3c8ab30 MM |
200 | # and in project config, a comma-separated list of formats or "none" |
201 | # to disable. Example: gitweb.snapshot = tbz2,zip; | |
952c65fc JN |
202 | 'snapshot' => { |
203 | 'sub' => \&feature_snapshot, | |
204 | 'override' => 0, | |
a3c8ab30 | 205 | 'default' => ['tgz']}, |
04f7a94f | 206 | |
6be93511 RF |
207 | # Enable text search, which will list the commits which match author, |
208 | # committer or commit text to a given string. Enabled by default. | |
b4b20b21 | 209 | # Project specific override is not supported. |
6be93511 RF |
210 | 'search' => { |
211 | 'override' => 0, | |
212 | 'default' => [1]}, | |
213 | ||
e7738553 PB |
214 | # Enable grep search, which will list the files in currently selected |
215 | # tree containing the given string. Enabled by default. This can be | |
216 | # potentially CPU-intensive, of course. | |
217 | ||
218 | # To enable system wide have in $GITWEB_CONFIG | |
219 | # $feature{'grep'}{'default'} = [1]; | |
220 | # To have project specific config enable override in $GITWEB_CONFIG | |
221 | # $feature{'grep'}{'override'} = 1; | |
222 | # and in project config gitweb.grep = 0|1; | |
223 | 'grep' => { | |
224 | 'override' => 0, | |
225 | 'default' => [1]}, | |
226 | ||
45a3b12c PB |
227 | # Enable the pickaxe search, which will list the commits that modified |
228 | # a given string in a file. This can be practical and quite faster | |
229 | # alternative to 'blame', but still potentially CPU-intensive. | |
230 | ||
231 | # To enable system wide have in $GITWEB_CONFIG | |
232 | # $feature{'pickaxe'}{'default'} = [1]; | |
233 | # To have project specific config enable override in $GITWEB_CONFIG | |
234 | # $feature{'pickaxe'}{'override'} = 1; | |
235 | # and in project config gitweb.pickaxe = 0|1; | |
04f7a94f JN |
236 | 'pickaxe' => { |
237 | 'sub' => \&feature_pickaxe, | |
238 | 'override' => 0, | |
239 | 'default' => [1]}, | |
9e756904 | 240 | |
45a3b12c PB |
241 | # Make gitweb use an alternative format of the URLs which can be |
242 | # more readable and natural-looking: project name is embedded | |
243 | # directly in the path and the query string contains other | |
244 | # auxiliary information. All gitweb installations recognize | |
245 | # URL in either format; this configures in which formats gitweb | |
246 | # generates links. | |
247 | ||
248 | # To enable system wide have in $GITWEB_CONFIG | |
249 | # $feature{'pathinfo'}{'default'} = [1]; | |
250 | # Project specific override is not supported. | |
251 | ||
252 | # Note that you will need to change the default location of CSS, | |
253 | # favicon, logo and possibly other files to an absolute URL. Also, | |
254 | # if gitweb.cgi serves as your indexfile, you will need to force | |
255 | # $my_uri to contain the script name in your $GITWEB_CONFIG. | |
9e756904 MW |
256 | 'pathinfo' => { |
257 | 'override' => 0, | |
258 | 'default' => [0]}, | |
e30496df PB |
259 | |
260 | # Make gitweb consider projects in project root subdirectories | |
261 | # to be forks of existing projects. Given project $projname.git, | |
262 | # projects matching $projname/*.git will not be shown in the main | |
263 | # projects list, instead a '+' mark will be added to $projname | |
264 | # there and a 'forks' view will be enabled for the project, listing | |
c2b8b134 FL |
265 | # all the forks. If project list is taken from a file, forks have |
266 | # to be listed after the main project. | |
e30496df PB |
267 | |
268 | # To enable system wide have in $GITWEB_CONFIG | |
269 | # $feature{'forks'}{'default'} = [1]; | |
270 | # Project specific override is not supported. | |
271 | 'forks' => { | |
272 | 'override' => 0, | |
273 | 'default' => [0]}, | |
ddb8d900 AK |
274 | ); |
275 | ||
276 | sub gitweb_check_feature { | |
277 | my ($name) = @_; | |
dd1ad5f1 | 278 | return unless exists $feature{$name}; |
952c65fc JN |
279 | my ($sub, $override, @defaults) = ( |
280 | $feature{$name}{'sub'}, | |
281 | $feature{$name}{'override'}, | |
282 | @{$feature{$name}{'default'}}); | |
ddb8d900 | 283 | if (!$override) { return @defaults; } |
a9455919 MW |
284 | if (!defined $sub) { |
285 | warn "feature $name is not overrideable"; | |
286 | return @defaults; | |
287 | } | |
ddb8d900 AK |
288 | return $sub->(@defaults); |
289 | } | |
290 | ||
ddb8d900 AK |
291 | sub feature_blame { |
292 | my ($val) = git_get_project_config('blame', '--bool'); | |
293 | ||
294 | if ($val eq 'true') { | |
295 | return 1; | |
296 | } elsif ($val eq 'false') { | |
297 | return 0; | |
298 | } | |
299 | ||
300 | return $_[0]; | |
301 | } | |
302 | ||
ddb8d900 | 303 | sub feature_snapshot { |
a3c8ab30 | 304 | my (@fmts) = @_; |
ddb8d900 AK |
305 | |
306 | my ($val) = git_get_project_config('snapshot'); | |
307 | ||
a3c8ab30 MM |
308 | if ($val) { |
309 | @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val); | |
ddb8d900 AK |
310 | } |
311 | ||
a3c8ab30 | 312 | return @fmts; |
de9272f4 LT |
313 | } |
314 | ||
e7738553 PB |
315 | sub feature_grep { |
316 | my ($val) = git_get_project_config('grep', '--bool'); | |
317 | ||
318 | if ($val eq 'true') { | |
319 | return (1); | |
320 | } elsif ($val eq 'false') { | |
321 | return (0); | |
322 | } | |
323 | ||
324 | return ($_[0]); | |
325 | } | |
326 | ||
04f7a94f JN |
327 | sub feature_pickaxe { |
328 | my ($val) = git_get_project_config('pickaxe', '--bool'); | |
329 | ||
330 | if ($val eq 'true') { | |
331 | return (1); | |
332 | } elsif ($val eq 'false') { | |
333 | return (0); | |
334 | } | |
335 | ||
336 | return ($_[0]); | |
337 | } | |
338 | ||
2172ce4b JH |
339 | # checking HEAD file with -e is fragile if the repository was |
340 | # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed | |
341 | # and then pruned. | |
342 | sub check_head_link { | |
343 | my ($dir) = @_; | |
344 | my $headfile = "$dir/HEAD"; | |
345 | return ((-e $headfile) || | |
346 | (-l $headfile && readlink($headfile) =~ /^refs\/heads\//)); | |
347 | } | |
348 | ||
349 | sub check_export_ok { | |
350 | my ($dir) = @_; | |
351 | return (check_head_link($dir) && | |
352 | (!$export_ok || -e "$dir/$export_ok")); | |
353 | } | |
354 | ||
a781785d JN |
355 | # process alternate names for backward compatibility |
356 | # filter out unsupported (unknown) snapshot formats | |
357 | sub filter_snapshot_fmts { | |
358 | my @fmts = @_; | |
359 | ||
360 | @fmts = map { | |
361 | exists $known_snapshot_format_aliases{$_} ? | |
362 | $known_snapshot_format_aliases{$_} : $_} @fmts; | |
363 | @fmts = grep(exists $known_snapshot_formats{$_}, @fmts); | |
364 | ||
365 | } | |
366 | ||
06c084d2 | 367 | our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++"; |
4b5dc988 | 368 | do $GITWEB_CONFIG if -e $GITWEB_CONFIG; |
c8d138a8 JK |
369 | |
370 | # version of the core git binary | |
371 | our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown"; | |
372 | ||
373 | $projects_list ||= $projectroot; | |
c8d138a8 | 374 | |
154b4d78 | 375 | # ====================================================================== |
09bd7898 | 376 | # input validation and dispatch |
4a87b43e | 377 | our $action = $cgi->param('a'); |
09bd7898 | 378 | if (defined $action) { |
c91da262 | 379 | if ($action =~ m/[^0-9a-zA-Z\.\-_]/) { |
cac4bd94 | 380 | die_error(undef, "Invalid action parameter"); |
b87d78d6 | 381 | } |
b87d78d6 | 382 | } |
44ad2978 | 383 | |
24d0693a | 384 | # parameters which are pathnames |
dd70235f | 385 | our $project = $cgi->param('p'); |
13d02165 | 386 | if (defined $project) { |
24d0693a | 387 | if (!validate_pathname($project) || |
7939fe44 | 388 | !(-d "$projectroot/$project") || |
2172ce4b | 389 | !check_head_link("$projectroot/$project") || |
32f4aacc ML |
390 | ($export_ok && !(-e "$projectroot/$project/$export_ok")) || |
391 | ($strict_export && !project_in_list($project))) { | |
7939fe44 | 392 | undef $project; |
cac4bd94 | 393 | die_error(undef, "No such project"); |
9cd3d988 | 394 | } |
a59d4afd | 395 | } |
6191f8e1 | 396 | |
4a87b43e | 397 | our $file_name = $cgi->param('f'); |
24d0693a JN |
398 | if (defined $file_name) { |
399 | if (!validate_pathname($file_name)) { | |
400 | die_error(undef, "Invalid file parameter"); | |
401 | } | |
402 | } | |
403 | ||
5c95fab0 | 404 | our $file_parent = $cgi->param('fp'); |
24d0693a JN |
405 | if (defined $file_parent) { |
406 | if (!validate_pathname($file_parent)) { | |
407 | die_error(undef, "Invalid file parent parameter"); | |
408 | } | |
409 | } | |
5c95fab0 | 410 | |
24d0693a | 411 | # parameters which are refnames |
4a87b43e | 412 | our $hash = $cgi->param('h'); |
4fac5294 | 413 | if (defined $hash) { |
24d0693a | 414 | if (!validate_refname($hash)) { |
cac4bd94 | 415 | die_error(undef, "Invalid hash parameter"); |
4fac5294 | 416 | } |
a59d4afd | 417 | } |
6191f8e1 | 418 | |
4a87b43e | 419 | our $hash_parent = $cgi->param('hp'); |
c91da262 | 420 | if (defined $hash_parent) { |
24d0693a | 421 | if (!validate_refname($hash_parent)) { |
cac4bd94 | 422 | die_error(undef, "Invalid hash parent parameter"); |
c91da262 | 423 | } |
09bd7898 KS |
424 | } |
425 | ||
4a87b43e | 426 | our $hash_base = $cgi->param('hb'); |
c91da262 | 427 | if (defined $hash_base) { |
24d0693a | 428 | if (!validate_refname($hash_base)) { |
cac4bd94 | 429 | die_error(undef, "Invalid hash base parameter"); |
c91da262 | 430 | } |
a59d4afd | 431 | } |
6191f8e1 | 432 | |
868bc068 MV |
433 | my %allowed_options = ( |
434 | "--no-merges" => [ qw(rss atom log shortlog history) ], | |
435 | ); | |
436 | ||
437 | our @extra_options = $cgi->param('opt'); | |
438 | if (defined @extra_options) { | |
12075103 JN |
439 | foreach my $opt (@extra_options) { |
440 | if (not exists $allowed_options{$opt}) { | |
868bc068 MV |
441 | die_error(undef, "Invalid option parameter"); |
442 | } | |
12075103 | 443 | if (not grep(/^$action$/, @{$allowed_options{$opt}})) { |
868bc068 MV |
444 | die_error(undef, "Invalid option parameter for this action"); |
445 | } | |
446 | } | |
447 | } | |
448 | ||
420e92f2 JN |
449 | our $hash_parent_base = $cgi->param('hpb'); |
450 | if (defined $hash_parent_base) { | |
24d0693a | 451 | if (!validate_refname($hash_parent_base)) { |
420e92f2 JN |
452 | die_error(undef, "Invalid hash parent base parameter"); |
453 | } | |
454 | } | |
455 | ||
24d0693a | 456 | # other parameters |
4a87b43e | 457 | our $page = $cgi->param('pg'); |
ea4a6df4 | 458 | if (defined $page) { |
ac8e3f2b | 459 | if ($page =~ m/[^0-9]/) { |
cac4bd94 | 460 | die_error(undef, "Invalid page parameter"); |
b87d78d6 | 461 | } |
2ad9331e | 462 | } |
823d5dc8 | 463 | |
e7738553 PB |
464 | our $searchtype = $cgi->param('st'); |
465 | if (defined $searchtype) { | |
466 | if ($searchtype =~ m/[^a-z]/) { | |
467 | die_error(undef, "Invalid searchtype parameter"); | |
468 | } | |
469 | } | |
470 | ||
4a87b43e | 471 | our $searchtext = $cgi->param('s'); |
7e431ef9 | 472 | our $search_regexp; |
19806691 | 473 | if (defined $searchtext) { |
9d032c72 RF |
474 | if (length($searchtext) < 2) { |
475 | die_error(undef, "At least two characters are required for search parameter"); | |
476 | } | |
7e431ef9 | 477 | $search_regexp = quotemeta $searchtext; |
19806691 KS |
478 | } |
479 | ||
dd70235f | 480 | # now read PATH_INFO and use it as alternative to parameters |
645927ce ML |
481 | sub evaluate_path_info { |
482 | return if defined $project; | |
483 | my $path_info = $ENV{"PATH_INFO"}; | |
484 | return if !$path_info; | |
cd90e75f | 485 | $path_info =~ s,^/+,,; |
645927ce | 486 | return if !$path_info; |
cd90e75f | 487 | # find which part of PATH_INFO is project |
dd70235f | 488 | $project = $path_info; |
cd90e75f | 489 | $project =~ s,/+$,,; |
2172ce4b | 490 | while ($project && !check_head_link("$projectroot/$project")) { |
dd70235f MW |
491 | $project =~ s,/*[^/]*$,,; |
492 | } | |
cd90e75f | 493 | # validate project |
24d0693a | 494 | $project = validate_pathname($project); |
645927ce ML |
495 | if (!$project || |
496 | ($export_ok && !-e "$projectroot/$project/$export_ok") || | |
497 | ($strict_export && !project_in_list($project))) { | |
498 | undef $project; | |
499 | return; | |
dd70235f | 500 | } |
645927ce ML |
501 | # do not change any parameters if an action is given using the query string |
502 | return if $action; | |
cd90e75f JN |
503 | $path_info =~ s,^$project/*,,; |
504 | my ($refname, $pathname) = split(/:/, $path_info, 2); | |
505 | if (defined $pathname) { | |
506 | # we got "project.git/branch:filename" or "project.git/branch:dir/" | |
507 | # we could use git_get_type(branch:pathname), but it needs $git_dir | |
508 | $pathname =~ s,^/+,,; | |
509 | if (!$pathname || substr($pathname, -1) eq "/") { | |
510 | $action ||= "tree"; | |
053d62bb | 511 | $pathname =~ s,/$,,; |
cd90e75f JN |
512 | } else { |
513 | $action ||= "blob_plain"; | |
514 | } | |
24d0693a JN |
515 | $hash_base ||= validate_refname($refname); |
516 | $file_name ||= validate_pathname($pathname); | |
cd90e75f | 517 | } elsif (defined $refname) { |
dd70235f MW |
518 | # we got "project.git/branch" |
519 | $action ||= "shortlog"; | |
24d0693a | 520 | $hash ||= validate_refname($refname); |
dd70235f MW |
521 | } |
522 | } | |
645927ce | 523 | evaluate_path_info(); |
dd70235f | 524 | |
645927ce ML |
525 | # path to the current git repository |
526 | our $git_dir; | |
527 | $git_dir = "$projectroot/$project" if $project; | |
dd70235f | 528 | |
717b8311 | 529 | # dispatch |
8e85cdc4 ML |
530 | my %actions = ( |
531 | "blame" => \&git_blame2, | |
532 | "blobdiff" => \&git_blobdiff, | |
533 | "blobdiff_plain" => \&git_blobdiff_plain, | |
534 | "blob" => \&git_blob, | |
535 | "blob_plain" => \&git_blob_plain, | |
536 | "commitdiff" => \&git_commitdiff, | |
537 | "commitdiff_plain" => \&git_commitdiff_plain, | |
538 | "commit" => \&git_commit, | |
e30496df | 539 | "forks" => \&git_forks, |
8e85cdc4 ML |
540 | "heads" => \&git_heads, |
541 | "history" => \&git_history, | |
542 | "log" => \&git_log, | |
543 | "rss" => \&git_rss, | |
af6feeb2 | 544 | "atom" => \&git_atom, |
8e85cdc4 | 545 | "search" => \&git_search, |
88ad729b | 546 | "search_help" => \&git_search_help, |
8e85cdc4 ML |
547 | "shortlog" => \&git_shortlog, |
548 | "summary" => \&git_summary, | |
549 | "tag" => \&git_tag, | |
550 | "tags" => \&git_tags, | |
551 | "tree" => \&git_tree, | |
cb9c6e5b | 552 | "snapshot" => \&git_snapshot, |
ca94601c | 553 | "object" => \&git_object, |
77a153fd JN |
554 | # those below don't need $project |
555 | "opml" => \&git_opml, | |
556 | "project_list" => \&git_project_list, | |
fc2b2be0 | 557 | "project_index" => \&git_project_index, |
8e85cdc4 ML |
558 | ); |
559 | ||
7f9778b1 GP |
560 | if (!defined $action) { |
561 | if (defined $hash) { | |
562 | $action = git_get_type($hash); | |
563 | } elsif (defined $hash_base && defined $file_name) { | |
564 | $action = git_get_type("$hash_base:$file_name"); | |
565 | } elsif (defined $project) { | |
566 | $action = 'summary'; | |
567 | } else { | |
568 | $action = 'project_list'; | |
569 | } | |
77a153fd | 570 | } |
8e85cdc4 | 571 | if (!defined($actions{$action})) { |
cac4bd94 | 572 | die_error(undef, "Unknown action"); |
09bd7898 | 573 | } |
d04d3d42 JN |
574 | if ($action !~ m/^(opml|project_list|project_index)$/ && |
575 | !$project) { | |
576 | die_error(undef, "Project needed"); | |
577 | } | |
8e85cdc4 ML |
578 | $actions{$action}->(); |
579 | exit; | |
09bd7898 | 580 | |
06a9d86b MW |
581 | ## ====================================================================== |
582 | ## action links | |
583 | ||
584 | sub href(%) { | |
498fe002 | 585 | my %params = @_; |
bd5d1e42 JN |
586 | # default is to use -absolute url() i.e. $my_uri |
587 | my $href = $params{-full} ? $my_url : $my_uri; | |
498fe002 | 588 | |
34c06118 PB |
589 | # XXX: Warning: If you touch this, check the search form for updating, |
590 | # too. | |
498fe002 JN |
591 | |
592 | my @mapping = ( | |
06a9d86b | 593 | project => "p", |
420e92f2 | 594 | action => "a", |
06a9d86b | 595 | file_name => "f", |
5c95fab0 | 596 | file_parent => "fp", |
06a9d86b MW |
597 | hash => "h", |
598 | hash_parent => "hp", | |
599 | hash_base => "hb", | |
420e92f2 | 600 | hash_parent_base => "hpb", |
06a9d86b | 601 | page => "pg", |
a1565c44 | 602 | order => "o", |
06a9d86b | 603 | searchtext => "s", |
88ad729b | 604 | searchtype => "st", |
a3c8ab30 | 605 | snapshot_format => "sf", |
12075103 | 606 | extra_options => "opt", |
06a9d86b | 607 | ); |
498fe002 | 608 | my %mapping = @mapping; |
06a9d86b | 609 | |
a1565c44 | 610 | $params{'project'} = $project unless exists $params{'project'}; |
06a9d86b | 611 | |
9e756904 MW |
612 | my ($use_pathinfo) = gitweb_check_feature('pathinfo'); |
613 | if ($use_pathinfo) { | |
614 | # use PATH_INFO for project name | |
615 | $href .= "/$params{'project'}" if defined $params{'project'}; | |
616 | delete $params{'project'}; | |
617 | ||
618 | # Summary just uses the project path URL | |
619 | if (defined $params{'action'} && $params{'action'} eq 'summary') { | |
620 | delete $params{'action'}; | |
621 | } | |
622 | } | |
623 | ||
624 | # now encode the parameters explicitly | |
498fe002 JN |
625 | my @result = (); |
626 | for (my $i = 0; $i < @mapping; $i += 2) { | |
627 | my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]); | |
628 | if (defined $params{$name}) { | |
f22cca44 JN |
629 | if (ref($params{$name}) eq "ARRAY") { |
630 | foreach my $par (@{$params{$name}}) { | |
631 | push @result, $symbol . "=" . esc_param($par); | |
632 | } | |
633 | } else { | |
634 | push @result, $symbol . "=" . esc_param($params{$name}); | |
635 | } | |
498fe002 JN |
636 | } |
637 | } | |
9e756904 MW |
638 | $href .= "?" . join(';', @result) if scalar @result; |
639 | ||
640 | return $href; | |
06a9d86b MW |
641 | } |
642 | ||
643 | ||
717b8311 JN |
644 | ## ====================================================================== |
645 | ## validation, quoting/unquoting and escaping | |
646 | ||
24d0693a JN |
647 | sub validate_pathname { |
648 | my $input = shift || return undef; | |
717b8311 | 649 | |
24d0693a JN |
650 | # no '.' or '..' as elements of path, i.e. no '.' nor '..' |
651 | # at the beginning, at the end, and between slashes. | |
652 | # also this catches doubled slashes | |
653 | if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) { | |
654 | return undef; | |
717b8311 | 655 | } |
24d0693a JN |
656 | # no null characters |
657 | if ($input =~ m!\0!) { | |
717b8311 JN |
658 | return undef; |
659 | } | |
24d0693a JN |
660 | return $input; |
661 | } | |
662 | ||
663 | sub validate_refname { | |
664 | my $input = shift || return undef; | |
665 | ||
666 | # textual hashes are O.K. | |
667 | if ($input =~ m/^[0-9a-fA-F]{40}$/) { | |
668 | return $input; | |
669 | } | |
670 | # it must be correct pathname | |
671 | $input = validate_pathname($input) | |
672 | or return undef; | |
673 | # restrictions on ref name according to git-check-ref-format | |
674 | if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) { | |
717b8311 JN |
675 | return undef; |
676 | } | |
677 | return $input; | |
678 | } | |
679 | ||
00f429af MK |
680 | # decode sequences of octets in utf8 into Perl's internal form, |
681 | # which is utf-8 with utf8 flag set if needed. gitweb writes out | |
682 | # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning | |
683 | sub to_utf8 { | |
684 | my $str = shift; | |
685 | my $res; | |
686 | eval { $res = decode_utf8($str, Encode::FB_CROAK); }; | |
687 | if (defined $res) { | |
688 | return $res; | |
689 | } else { | |
690 | return decode($fallback_encoding, $str, Encode::FB_DEFAULT); | |
691 | } | |
692 | } | |
693 | ||
232ff553 KS |
694 | # quote unsafe chars, but keep the slash, even when it's not |
695 | # correct, but quoted slashes look too horrible in bookmarks | |
696 | sub esc_param { | |
353347b0 | 697 | my $str = shift; |
a2f3db2f | 698 | $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X", ord($1))/eg; |
18216710 | 699 | $str =~ s/\+/%2B/g; |
a9e60b7d | 700 | $str =~ s/ /\+/g; |
353347b0 KS |
701 | return $str; |
702 | } | |
703 | ||
f93bff8d JN |
704 | # quote unsafe chars in whole URL, so some charactrs cannot be quoted |
705 | sub esc_url { | |
706 | my $str = shift; | |
707 | $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg; | |
708 | $str =~ s/\+/%2B/g; | |
709 | $str =~ s/ /\+/g; | |
710 | return $str; | |
711 | } | |
712 | ||
232ff553 | 713 | # replace invalid utf8 character with SUBSTITUTION sequence |
6255ef08 | 714 | sub esc_html ($;%) { |
40c13813 | 715 | my $str = shift; |
6255ef08 JN |
716 | my %opts = @_; |
717 | ||
00f429af | 718 | $str = to_utf8($str); |
c390ae97 | 719 | $str = $cgi->escapeHTML($str); |
6255ef08 JN |
720 | if ($opts{'-nbsp'}) { |
721 | $str =~ s/ / /g; | |
722 | } | |
25ffbb27 | 723 | $str =~ s|([[:cntrl:]])|(($1 ne "\t") ? quot_cec($1) : $1)|eg; |
40c13813 KS |
724 | return $str; |
725 | } | |
726 | ||
391862e3 JN |
727 | # quote control characters and escape filename to HTML |
728 | sub esc_path { | |
729 | my $str = shift; | |
730 | my %opts = @_; | |
731 | ||
00f429af | 732 | $str = to_utf8($str); |
c390ae97 | 733 | $str = $cgi->escapeHTML($str); |
391862e3 JN |
734 | if ($opts{'-nbsp'}) { |
735 | $str =~ s/ / /g; | |
736 | } | |
737 | $str =~ s|([[:cntrl:]])|quot_cec($1)|eg; | |
738 | return $str; | |
739 | } | |
740 | ||
741 | # Make control characters "printable", using character escape codes (CEC) | |
1d3bc0cc JN |
742 | sub quot_cec { |
743 | my $cntrl = shift; | |
744 | my %es = ( # character escape codes, aka escape sequences | |
745 | "\t" => '\t', # tab (HT) | |
746 | "\n" => '\n', # line feed (LF) | |
747 | "\r" => '\r', # carrige return (CR) | |
748 | "\f" => '\f', # form feed (FF) | |
749 | "\b" => '\b', # backspace (BS) | |
750 | "\a" => '\a', # alarm (bell) (BEL) | |
751 | "\e" => '\e', # escape (ESC) | |
752 | "\013" => '\v', # vertical tab (VT) | |
753 | "\000" => '\0', # nul character (NUL) | |
754 | ); | |
755 | my $chr = ( (exists $es{$cntrl}) | |
756 | ? $es{$cntrl} | |
757 | : sprintf('\%03o', ord($cntrl)) ); | |
758 | return "<span class=\"cntrl\">$chr</span>"; | |
759 | } | |
760 | ||
391862e3 JN |
761 | # Alternatively use unicode control pictures codepoints, |
762 | # Unicode "printable representation" (PR) | |
1d3bc0cc JN |
763 | sub quot_upr { |
764 | my $cntrl = shift; | |
765 | my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl)); | |
766 | return "<span class=\"cntrl\">$chr</span>"; | |
767 | } | |
768 | ||
232ff553 KS |
769 | # git may return quoted and escaped filenames |
770 | sub unquote { | |
771 | my $str = shift; | |
403d0906 JN |
772 | |
773 | sub unq { | |
774 | my $seq = shift; | |
775 | my %es = ( # character escape codes, aka escape sequences | |
776 | 't' => "\t", # tab (HT, TAB) | |
777 | 'n' => "\n", # newline (NL) | |
778 | 'r' => "\r", # return (CR) | |
779 | 'f' => "\f", # form feed (FF) | |
780 | 'b' => "\b", # backspace (BS) | |
781 | 'a' => "\a", # alarm (bell) (BEL) | |
782 | 'e' => "\e", # escape (ESC) | |
783 | 'v' => "\013", # vertical tab (VT) | |
784 | ); | |
785 | ||
786 | if ($seq =~ m/^[0-7]{1,3}$/) { | |
787 | # octal char sequence | |
788 | return chr(oct($seq)); | |
789 | } elsif (exists $es{$seq}) { | |
790 | # C escape sequence, aka character escape code | |
791 | return $es{$seq} | |
792 | } | |
793 | # quoted ordinary character | |
794 | return $seq; | |
795 | } | |
796 | ||
232ff553 | 797 | if ($str =~ m/^"(.*)"$/) { |
403d0906 | 798 | # needs unquoting |
232ff553 | 799 | $str = $1; |
403d0906 | 800 | $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg; |
232ff553 KS |
801 | } |
802 | return $str; | |
803 | } | |
804 | ||
f16db173 JN |
805 | # escape tabs (convert tabs to spaces) |
806 | sub untabify { | |
807 | my $line = shift; | |
808 | ||
809 | while ((my $pos = index($line, "\t")) != -1) { | |
810 | if (my $count = (8 - ($pos % 8))) { | |
811 | my $spaces = ' ' x $count; | |
812 | $line =~ s/\t/$spaces/; | |
813 | } | |
814 | } | |
815 | ||
816 | return $line; | |
817 | } | |
818 | ||
32f4aacc ML |
819 | sub project_in_list { |
820 | my $project = shift; | |
821 | my @list = git_get_projects_list(); | |
822 | return @list && scalar(grep { $_->{'path'} eq $project } @list); | |
823 | } | |
824 | ||
717b8311 JN |
825 | ## ---------------------------------------------------------------------- |
826 | ## HTML aware string manipulation | |
827 | ||
828 | sub chop_str { | |
829 | my $str = shift; | |
830 | my $len = shift; | |
831 | my $add_len = shift || 10; | |
832 | ||
833 | # allow only $len chars, but don't cut a word if it would fit in $add_len | |
834 | # if it doesn't fit, cut it if it's still longer than the dots we would add | |
835 | $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/; | |
836 | my $body = $1; | |
837 | my $tail = $2; | |
838 | if (length($tail) > 4) { | |
839 | $tail = " ..."; | |
840 | $body =~ s/&[^;]*$//; # remove chopped character entities | |
841 | } | |
842 | return "$body$tail"; | |
843 | } | |
844 | ||
845 | ## ---------------------------------------------------------------------- | |
846 | ## functions returning short strings | |
847 | ||
1f1ab5f0 JN |
848 | # CSS class for given age value (in seconds) |
849 | sub age_class { | |
850 | my $age = shift; | |
851 | ||
785cdea9 JN |
852 | if (!defined $age) { |
853 | return "noage"; | |
854 | } elsif ($age < 60*60*2) { | |
1f1ab5f0 JN |
855 | return "age0"; |
856 | } elsif ($age < 60*60*24*2) { | |
857 | return "age1"; | |
858 | } else { | |
859 | return "age2"; | |
860 | } | |
861 | } | |
862 | ||
717b8311 JN |
863 | # convert age in seconds to "nn units ago" string |
864 | sub age_string { | |
865 | my $age = shift; | |
866 | my $age_str; | |
a59d4afd | 867 | |
717b8311 JN |
868 | if ($age > 60*60*24*365*2) { |
869 | $age_str = (int $age/60/60/24/365); | |
870 | $age_str .= " years ago"; | |
871 | } elsif ($age > 60*60*24*(365/12)*2) { | |
872 | $age_str = int $age/60/60/24/(365/12); | |
873 | $age_str .= " months ago"; | |
874 | } elsif ($age > 60*60*24*7*2) { | |
875 | $age_str = int $age/60/60/24/7; | |
876 | $age_str .= " weeks ago"; | |
877 | } elsif ($age > 60*60*24*2) { | |
878 | $age_str = int $age/60/60/24; | |
879 | $age_str .= " days ago"; | |
880 | } elsif ($age > 60*60*2) { | |
881 | $age_str = int $age/60/60; | |
882 | $age_str .= " hours ago"; | |
883 | } elsif ($age > 60*2) { | |
884 | $age_str = int $age/60; | |
885 | $age_str .= " min ago"; | |
886 | } elsif ($age > 2) { | |
887 | $age_str = int $age; | |
888 | $age_str .= " sec ago"; | |
f6801d66 | 889 | } else { |
717b8311 | 890 | $age_str .= " right now"; |
4c02e3c5 | 891 | } |
717b8311 | 892 | return $age_str; |
161332a5 KS |
893 | } |
894 | ||
01ac1e38 JN |
895 | use constant { |
896 | S_IFINVALID => 0030000, | |
897 | S_IFGITLINK => 0160000, | |
898 | }; | |
899 | ||
900 | # submodule/subproject, a commit object reference | |
901 | sub S_ISGITLINK($) { | |
902 | my $mode = shift; | |
903 | ||
904 | return (($mode & S_IFMT) == S_IFGITLINK) | |
905 | } | |
906 | ||
717b8311 JN |
907 | # convert file mode in octal to symbolic file mode string |
908 | sub mode_str { | |
909 | my $mode = oct shift; | |
910 | ||
01ac1e38 JN |
911 | if (S_ISGITLINK($mode)) { |
912 | return 'm---------'; | |
913 | } elsif (S_ISDIR($mode & S_IFMT)) { | |
717b8311 JN |
914 | return 'drwxr-xr-x'; |
915 | } elsif (S_ISLNK($mode)) { | |
916 | return 'lrwxrwxrwx'; | |
917 | } elsif (S_ISREG($mode)) { | |
918 | # git cares only about the executable bit | |
919 | if ($mode & S_IXUSR) { | |
920 | return '-rwxr-xr-x'; | |
921 | } else { | |
922 | return '-rw-r--r--'; | |
923 | }; | |
c994d620 | 924 | } else { |
717b8311 | 925 | return '----------'; |
ff7669a5 | 926 | } |
161332a5 KS |
927 | } |
928 | ||
717b8311 JN |
929 | # convert file mode in octal to file type string |
930 | sub file_type { | |
7c5e2ebb JN |
931 | my $mode = shift; |
932 | ||
933 | if ($mode !~ m/^[0-7]+$/) { | |
934 | return $mode; | |
935 | } else { | |
936 | $mode = oct $mode; | |
937 | } | |
664f4cc5 | 938 | |
01ac1e38 JN |
939 | if (S_ISGITLINK($mode)) { |
940 | return "submodule"; | |
941 | } elsif (S_ISDIR($mode & S_IFMT)) { | |
717b8311 JN |
942 | return "directory"; |
943 | } elsif (S_ISLNK($mode)) { | |
944 | return "symlink"; | |
945 | } elsif (S_ISREG($mode)) { | |
946 | return "file"; | |
947 | } else { | |
948 | return "unknown"; | |
949 | } | |
a59d4afd KS |
950 | } |
951 | ||
744d0ac3 JN |
952 | # convert file mode in octal to file type description string |
953 | sub file_type_long { | |
954 | my $mode = shift; | |
955 | ||
956 | if ($mode !~ m/^[0-7]+$/) { | |
957 | return $mode; | |
958 | } else { | |
959 | $mode = oct $mode; | |
960 | } | |
961 | ||
01ac1e38 JN |
962 | if (S_ISGITLINK($mode)) { |
963 | return "submodule"; | |
964 | } elsif (S_ISDIR($mode & S_IFMT)) { | |
744d0ac3 JN |
965 | return "directory"; |
966 | } elsif (S_ISLNK($mode)) { | |
967 | return "symlink"; | |
968 | } elsif (S_ISREG($mode)) { | |
969 | if ($mode & S_IXUSR) { | |
970 | return "executable"; | |
971 | } else { | |
972 | return "file"; | |
973 | }; | |
974 | } else { | |
975 | return "unknown"; | |
976 | } | |
977 | } | |
978 | ||
979 | ||
717b8311 JN |
980 | ## ---------------------------------------------------------------------- |
981 | ## functions returning short HTML fragments, or transforming HTML fragments | |
3dff5379 | 982 | ## which don't belong to other sections |
b18f9bf4 | 983 | |
225932ed | 984 | # format line of commit message. |
717b8311 JN |
985 | sub format_log_line_html { |
986 | my $line = shift; | |
b18f9bf4 | 987 | |
225932ed | 988 | $line = esc_html($line, -nbsp=>1); |
bfe2191f | 989 | if ($line =~ m/([0-9a-fA-F]{8,40})/) { |
717b8311 | 990 | my $hash_text = $1; |
bfe2191f JN |
991 | my $link = |
992 | $cgi->a({-href => href(action=>"object", hash=>$hash_text), | |
993 | -class => "text"}, $hash_text); | |
994 | $line =~ s/$hash_text/$link/; | |
b18f9bf4 | 995 | } |
717b8311 | 996 | return $line; |
b18f9bf4 JN |
997 | } |
998 | ||
717b8311 | 999 | # format marker of refs pointing to given object |
847e01fb | 1000 | sub format_ref_marker { |
717b8311 | 1001 | my ($refs, $id) = @_; |
d294e1ca | 1002 | my $markers = ''; |
27fb8c40 | 1003 | |
717b8311 | 1004 | if (defined $refs->{$id}) { |
d294e1ca JN |
1005 | foreach my $ref (@{$refs->{$id}}) { |
1006 | my ($type, $name) = qw(); | |
1007 | # e.g. tags/v2.6.11 or heads/next | |
1008 | if ($ref =~ m!^(.*?)s?/(.*)$!) { | |
1009 | $type = $1; | |
1010 | $name = $2; | |
1011 | } else { | |
1012 | $type = "ref"; | |
1013 | $name = $ref; | |
1014 | } | |
1015 | ||
5fce278e JN |
1016 | $markers .= " <span class=\"$type\" title=\"$ref\">" . |
1017 | esc_html($name) . "</span>"; | |
d294e1ca JN |
1018 | } |
1019 | } | |
1020 | ||
1021 | if ($markers) { | |
1022 | return ' <span class="refs">'. $markers . '</span>'; | |
717b8311 JN |
1023 | } else { |
1024 | return ""; | |
1025 | } | |
27fb8c40 JN |
1026 | } |
1027 | ||
17d07443 JN |
1028 | # format, perhaps shortened and with markers, title line |
1029 | sub format_subject_html { | |
1c2a4f5a | 1030 | my ($long, $short, $href, $extra) = @_; |
17d07443 JN |
1031 | $extra = '' unless defined($extra); |
1032 | ||
1033 | if (length($short) < length($long)) { | |
7c278014 | 1034 | return $cgi->a({-href => $href, -class => "list subject", |
00f429af | 1035 | -title => to_utf8($long)}, |
17d07443 JN |
1036 | esc_html($short) . $extra); |
1037 | } else { | |
7c278014 | 1038 | return $cgi->a({-href => $href, -class => "list subject"}, |
17d07443 JN |
1039 | esc_html($long) . $extra); |
1040 | } | |
1041 | } | |
1042 | ||
90921740 JN |
1043 | # format git diff header line, i.e. "diff --(git|combined|cc) ..." |
1044 | sub format_git_diff_header_line { | |
1045 | my $line = shift; | |
1046 | my $diffinfo = shift; | |
1047 | my ($from, $to) = @_; | |
1048 | ||
1049 | if ($diffinfo->{'nparents'}) { | |
1050 | # combined diff | |
1051 | $line =~ s!^(diff (.*?) )"?.*$!$1!; | |
1052 | if ($to->{'href'}) { | |
1053 | $line .= $cgi->a({-href => $to->{'href'}, -class => "path"}, | |
1054 | esc_path($to->{'file'})); | |
1055 | } else { # file was deleted (no href) | |
1056 | $line .= esc_path($to->{'file'}); | |
1057 | } | |
1058 | } else { | |
1059 | # "ordinary" diff | |
1060 | $line =~ s!^(diff (.*?) )"?a/.*$!$1!; | |
1061 | if ($from->{'href'}) { | |
1062 | $line .= $cgi->a({-href => $from->{'href'}, -class => "path"}, | |
1063 | 'a/' . esc_path($from->{'file'})); | |
1064 | } else { # file was added (no href) | |
1065 | $line .= 'a/' . esc_path($from->{'file'}); | |
1066 | } | |
1067 | $line .= ' '; | |
1068 | if ($to->{'href'}) { | |
1069 | $line .= $cgi->a({-href => $to->{'href'}, -class => "path"}, | |
1070 | 'b/' . esc_path($to->{'file'})); | |
1071 | } else { # file was deleted | |
1072 | $line .= 'b/' . esc_path($to->{'file'}); | |
1073 | } | |
1074 | } | |
1075 | ||
1076 | return "<div class=\"diff header\">$line</div>\n"; | |
1077 | } | |
1078 | ||
1079 | # format extended diff header line, before patch itself | |
1080 | sub format_extended_diff_header_line { | |
1081 | my $line = shift; | |
1082 | my $diffinfo = shift; | |
1083 | my ($from, $to) = @_; | |
1084 | ||
1085 | # match <path> | |
1086 | if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) { | |
1087 | $line .= $cgi->a({-href=>$from->{'href'}, -class=>"path"}, | |
1088 | esc_path($from->{'file'})); | |
1089 | } | |
1090 | if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) { | |
1091 | $line .= $cgi->a({-href=>$to->{'href'}, -class=>"path"}, | |
1092 | esc_path($to->{'file'})); | |
1093 | } | |
1094 | # match single <mode> | |
1095 | if ($line =~ m/\s(\d{6})$/) { | |
1096 | $line .= '<span class="info"> (' . | |
1097 | file_type_long($1) . | |
1098 | ')</span>'; | |
1099 | } | |
1100 | # match <hash> | |
1101 | if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) { | |
1102 | # can match only for combined diff | |
1103 | $line = 'index '; | |
1104 | for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) { | |
1105 | if ($from->{'href'}[$i]) { | |
1106 | $line .= $cgi->a({-href=>$from->{'href'}[$i], | |
1107 | -class=>"hash"}, | |
1108 | substr($diffinfo->{'from_id'}[$i],0,7)); | |
1109 | } else { | |
1110 | $line .= '0' x 7; | |
1111 | } | |
1112 | # separator | |
1113 | $line .= ',' if ($i < $diffinfo->{'nparents'} - 1); | |
1114 | } | |
1115 | $line .= '..'; | |
1116 | if ($to->{'href'}) { | |
1117 | $line .= $cgi->a({-href=>$to->{'href'}, -class=>"hash"}, | |
1118 | substr($diffinfo->{'to_id'},0,7)); | |
1119 | } else { | |
1120 | $line .= '0' x 7; | |
1121 | } | |
1122 | ||
1123 | } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) { | |
1124 | # can match only for ordinary diff | |
1125 | my ($from_link, $to_link); | |
1126 | if ($from->{'href'}) { | |
1127 | $from_link = $cgi->a({-href=>$from->{'href'}, -class=>"hash"}, | |
1128 | substr($diffinfo->{'from_id'},0,7)); | |
1129 | } else { | |
1130 | $from_link = '0' x 7; | |
1131 | } | |
1132 | if ($to->{'href'}) { | |
1133 | $to_link = $cgi->a({-href=>$to->{'href'}, -class=>"hash"}, | |
1134 | substr($diffinfo->{'to_id'},0,7)); | |
1135 | } else { | |
1136 | $to_link = '0' x 7; | |
1137 | } | |
1138 | my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'}); | |
1139 | $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!; | |
1140 | } | |
1141 | ||
1142 | return $line . "<br/>\n"; | |
1143 | } | |
1144 | ||
1145 | # format from-file/to-file diff header | |
1146 | sub format_diff_from_to_header { | |
91af4ce4 | 1147 | my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_; |
90921740 JN |
1148 | my $line; |
1149 | my $result = ''; | |
1150 | ||
1151 | $line = $from_line; | |
1152 | #assert($line =~ m/^---/) if DEBUG; | |
deaa01a9 JN |
1153 | # no extra formatting for "^--- /dev/null" |
1154 | if (! $diffinfo->{'nparents'}) { | |
1155 | # ordinary (single parent) diff | |
1156 | if ($line =~ m!^--- "?a/!) { | |
1157 | if ($from->{'href'}) { | |
1158 | $line = '--- a/' . | |
1159 | $cgi->a({-href=>$from->{'href'}, -class=>"path"}, | |
1160 | esc_path($from->{'file'})); | |
1161 | } else { | |
1162 | $line = '--- a/' . | |
1163 | esc_path($from->{'file'}); | |
1164 | } | |
1165 | } | |
1166 | $result .= qq!<div class="diff from_file">$line</div>\n!; | |
1167 | ||
1168 | } else { | |
1169 | # combined diff (merge commit) | |
1170 | for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) { | |
1171 | if ($from->{'href'}[$i]) { | |
1172 | $line = '--- ' . | |
91af4ce4 JN |
1173 | $cgi->a({-href=>href(action=>"blobdiff", |
1174 | hash_parent=>$diffinfo->{'from_id'}[$i], | |
1175 | hash_parent_base=>$parents[$i], | |
1176 | file_parent=>$from->{'file'}[$i], | |
1177 | hash=>$diffinfo->{'to_id'}, | |
1178 | hash_base=>$hash, | |
1179 | file_name=>$to->{'file'}), | |
1180 | -class=>"path", | |
1181 | -title=>"diff" . ($i+1)}, | |
1182 | $i+1) . | |
1183 | '/' . | |
deaa01a9 JN |
1184 | $cgi->a({-href=>$from->{'href'}[$i], -class=>"path"}, |
1185 | esc_path($from->{'file'}[$i])); | |
1186 | } else { | |
1187 | $line = '--- /dev/null'; | |
1188 | } | |
1189 | $result .= qq!<div class="diff from_file">$line</div>\n!; | |
90921740 JN |
1190 | } |
1191 | } | |
90921740 JN |
1192 | |
1193 | $line = $to_line; | |
1194 | #assert($line =~ m/^\+\+\+/) if DEBUG; | |
1195 | # no extra formatting for "^+++ /dev/null" | |
1196 | if ($line =~ m!^\+\+\+ "?b/!) { | |
1197 | if ($to->{'href'}) { | |
1198 | $line = '+++ b/' . | |
1199 | $cgi->a({-href=>$to->{'href'}, -class=>"path"}, | |
1200 | esc_path($to->{'file'})); | |
1201 | } else { | |
1202 | $line = '+++ b/' . | |
1203 | esc_path($to->{'file'}); | |
1204 | } | |
1205 | } | |
1206 | $result .= qq!<div class="diff to_file">$line</div>\n!; | |
1207 | ||
1208 | return $result; | |
1209 | } | |
1210 | ||
cd030c3a JN |
1211 | # create note for patch simplified by combined diff |
1212 | sub format_diff_cc_simplified { | |
1213 | my ($diffinfo, @parents) = @_; | |
1214 | my $result = ''; | |
1215 | ||
1216 | $result .= "<div class=\"diff header\">" . | |
1217 | "diff --cc "; | |
1218 | if (!is_deleted($diffinfo)) { | |
1219 | $result .= $cgi->a({-href => href(action=>"blob", | |
1220 | hash_base=>$hash, | |
1221 | hash=>$diffinfo->{'to_id'}, | |
1222 | file_name=>$diffinfo->{'to_file'}), | |
1223 | -class => "path"}, | |
1224 | esc_path($diffinfo->{'to_file'})); | |
1225 | } else { | |
1226 | $result .= esc_path($diffinfo->{'to_file'}); | |
1227 | } | |
1228 | $result .= "</div>\n" . # class="diff header" | |
1229 | "<div class=\"diff nodifferences\">" . | |
1230 | "Simple merge" . | |
1231 | "</div>\n"; # class="diff nodifferences" | |
1232 | ||
1233 | return $result; | |
1234 | } | |
1235 | ||
90921740 | 1236 | # format patch (diff) line (not to be used for diff headers) |
eee08903 JN |
1237 | sub format_diff_line { |
1238 | my $line = shift; | |
59e3b14e | 1239 | my ($from, $to) = @_; |
eee08903 JN |
1240 | my $diff_class = ""; |
1241 | ||
1242 | chomp $line; | |
1243 | ||
e72c0eaf JN |
1244 | if ($from && $to && ref($from->{'href'}) eq "ARRAY") { |
1245 | # combined diff | |
1246 | my $prefix = substr($line, 0, scalar @{$from->{'href'}}); | |
1247 | if ($line =~ m/^\@{3}/) { | |
1248 | $diff_class = " chunk_header"; | |
1249 | } elsif ($line =~ m/^\\/) { | |
1250 | $diff_class = " incomplete"; | |
1251 | } elsif ($prefix =~ tr/+/+/) { | |
1252 | $diff_class = " add"; | |
1253 | } elsif ($prefix =~ tr/-/-/) { | |
1254 | $diff_class = " rem"; | |
1255 | } | |
1256 | } else { | |
1257 | # assume ordinary diff | |
1258 | my $char = substr($line, 0, 1); | |
1259 | if ($char eq '+') { | |
1260 | $diff_class = " add"; | |
1261 | } elsif ($char eq '-') { | |
1262 | $diff_class = " rem"; | |
1263 | } elsif ($char eq '@') { | |
1264 | $diff_class = " chunk_header"; | |
1265 | } elsif ($char eq "\\") { | |
1266 | $diff_class = " incomplete"; | |
1267 | } | |
eee08903 JN |
1268 | } |
1269 | $line = untabify($line); | |
59e3b14e JN |
1270 | if ($from && $to && $line =~ m/^\@{2} /) { |
1271 | my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) = | |
1272 | $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/; | |
1273 | ||
1274 | $from_lines = 0 unless defined $from_lines; | |
1275 | $to_lines = 0 unless defined $to_lines; | |
1276 | ||
1277 | if ($from->{'href'}) { | |
1278 | $from_text = $cgi->a({-href=>"$from->{'href'}#l$from_start", | |
1279 | -class=>"list"}, $from_text); | |
1280 | } | |
1281 | if ($to->{'href'}) { | |
1282 | $to_text = $cgi->a({-href=>"$to->{'href'}#l$to_start", | |
1283 | -class=>"list"}, $to_text); | |
1284 | } | |
1285 | $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" . | |
1286 | "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>"; | |
1287 | return "<div class=\"diff$diff_class\">$line</div>\n"; | |
e72c0eaf JN |
1288 | } elsif ($from && $to && $line =~ m/^\@{3}/) { |
1289 | my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/; | |
1290 | my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines); | |
1291 | ||
1292 | @from_text = split(' ', $ranges); | |
1293 | for (my $i = 0; $i < @from_text; ++$i) { | |
1294 | ($from_start[$i], $from_nlines[$i]) = | |
1295 | (split(',', substr($from_text[$i], 1)), 0); | |
1296 | } | |
1297 | ||
1298 | $to_text = pop @from_text; | |
1299 | $to_start = pop @from_start; | |
1300 | $to_nlines = pop @from_nlines; | |
1301 | ||
1302 | $line = "<span class=\"chunk_info\">$prefix "; | |
1303 | for (my $i = 0; $i < @from_text; ++$i) { | |
1304 | if ($from->{'href'}[$i]) { | |
1305 | $line .= $cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]", | |
1306 | -class=>"list"}, $from_text[$i]); | |
1307 | } else { | |
1308 | $line .= $from_text[$i]; | |
1309 | } | |
1310 | $line .= " "; | |
1311 | } | |
1312 | if ($to->{'href'}) { | |
1313 | $line .= $cgi->a({-href=>"$to->{'href'}#l$to_start", | |
1314 | -class=>"list"}, $to_text); | |
1315 | } else { | |
1316 | $line .= $to_text; | |
1317 | } | |
1318 | $line .= " $prefix</span>" . | |
1319 | "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>"; | |
1320 | return "<div class=\"diff$diff_class\">$line</div>\n"; | |
59e3b14e | 1321 | } |
6255ef08 | 1322 | return "<div class=\"diff$diff_class\">" . esc_html($line, -nbsp=>1) . "</div>\n"; |
eee08903 JN |
1323 | } |
1324 | ||
a3c8ab30 MM |
1325 | # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)", |
1326 | # linked. Pass the hash of the tree/commit to snapshot. | |
1327 | sub format_snapshot_links { | |
1328 | my ($hash) = @_; | |
1329 | my @snapshot_fmts = gitweb_check_feature('snapshot'); | |
a781785d | 1330 | @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts); |
a3c8ab30 MM |
1331 | my $num_fmts = @snapshot_fmts; |
1332 | if ($num_fmts > 1) { | |
1333 | # A parenthesized list of links bearing format names. | |
a781785d | 1334 | # e.g. "snapshot (_tar.gz_ _zip_)" |
a3c8ab30 MM |
1335 | return "snapshot (" . join(' ', map |
1336 | $cgi->a({ | |
1337 | -href => href( | |
1338 | action=>"snapshot", | |
1339 | hash=>$hash, | |
1340 | snapshot_format=>$_ | |
1341 | ) | |
1342 | }, $known_snapshot_formats{$_}{'display'}) | |
1343 | , @snapshot_fmts) . ")"; | |
1344 | } elsif ($num_fmts == 1) { | |
1345 | # A single "snapshot" link whose tooltip bears the format name. | |
a781785d | 1346 | # i.e. "_snapshot_" |
a3c8ab30 | 1347 | my ($fmt) = @snapshot_fmts; |
a781785d JN |
1348 | return |
1349 | $cgi->a({ | |
a3c8ab30 MM |
1350 | -href => href( |
1351 | action=>"snapshot", | |
1352 | hash=>$hash, | |
1353 | snapshot_format=>$fmt | |
1354 | ), | |
1355 | -title => "in format: $known_snapshot_formats{$fmt}{'display'}" | |
1356 | }, "snapshot"); | |
1357 | } else { # $num_fmts == 0 | |
1358 | return undef; | |
1359 | } | |
1360 | } | |
1361 | ||
717b8311 JN |
1362 | ## ---------------------------------------------------------------------- |
1363 | ## git utility subroutines, invoking git commands | |
42f7eb94 | 1364 | |
25691fbe DS |
1365 | # returns path to the core git executable and the --git-dir parameter as list |
1366 | sub git_cmd { | |
1367 | return $GIT, '--git-dir='.$git_dir; | |
1368 | } | |
1369 | ||
1370 | # returns path to the core git executable and the --git-dir parameter as string | |
1371 | sub git_cmd_str { | |
1372 | return join(' ', git_cmd()); | |
1373 | } | |
1374 | ||
717b8311 | 1375 | # get HEAD ref of given project as hash |
847e01fb | 1376 | sub git_get_head_hash { |
df2c37a5 | 1377 | my $project = shift; |
25691fbe | 1378 | my $o_git_dir = $git_dir; |
df2c37a5 | 1379 | my $retval = undef; |
25691fbe DS |
1380 | $git_dir = "$projectroot/$project"; |
1381 | if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") { | |
df2c37a5 JH |
1382 | my $head = <$fd>; |
1383 | close $fd; | |
2c5c008b KS |
1384 | if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) { |
1385 | $retval = $1; | |
df2c37a5 JH |
1386 | } |
1387 | } | |
25691fbe DS |
1388 | if (defined $o_git_dir) { |
1389 | $git_dir = $o_git_dir; | |
2c5c008b | 1390 | } |
df2c37a5 JH |
1391 | return $retval; |
1392 | } | |
1393 | ||
717b8311 JN |
1394 | # get type of given object |
1395 | sub git_get_type { | |
1396 | my $hash = shift; | |
1397 | ||
25691fbe | 1398 | open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return; |
717b8311 JN |
1399 | my $type = <$fd>; |
1400 | close $fd or return; | |
1401 | chomp $type; | |
1402 | return $type; | |
1403 | } | |
1404 | ||
1405 | sub git_get_project_config { | |
ddb8d900 | 1406 | my ($key, $type) = @_; |
717b8311 JN |
1407 | |
1408 | return unless ($key); | |
1409 | $key =~ s/^gitweb\.//; | |
1410 | return if ($key =~ m/\W/); | |
1411 | ||
e0d10e1c | 1412 | my @x = (git_cmd(), 'config'); |
ddb8d900 AK |
1413 | if (defined $type) { push @x, $type; } |
1414 | push @x, "--get"; | |
1415 | push @x, "gitweb.$key"; | |
1416 | my $val = qx(@x); | |
1417 | chomp $val; | |
717b8311 JN |
1418 | return ($val); |
1419 | } | |
1420 | ||
717b8311 JN |
1421 | # get hash of given path at given ref |
1422 | sub git_get_hash_by_path { | |
1423 | my $base = shift; | |
1424 | my $path = shift || return undef; | |
1d782b03 | 1425 | my $type = shift; |
717b8311 | 1426 | |
4b02f483 | 1427 | $path =~ s,/+$,,; |
717b8311 | 1428 | |
25691fbe | 1429 | open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path |
cac4bd94 | 1430 | or die_error(undef, "Open git-ls-tree failed"); |
717b8311 JN |
1431 | my $line = <$fd>; |
1432 | close $fd or return undef; | |
1433 | ||
198a2a8a JN |
1434 | if (!defined $line) { |
1435 | # there is no tree or hash given by $path at $base | |
1436 | return undef; | |
1437 | } | |
1438 | ||
717b8311 | 1439 | #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' |
8b4b94cc | 1440 | $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/; |
1d782b03 JN |
1441 | if (defined $type && $type ne $2) { |
1442 | # type doesn't match | |
1443 | return undef; | |
1444 | } | |
717b8311 JN |
1445 | return $3; |
1446 | } | |
1447 | ||
ed224dea JN |
1448 | # get path of entry with given hash at given tree-ish (ref) |
1449 | # used to get 'from' filename for combined diff (merge commit) for renames | |
1450 | sub git_get_path_by_hash { | |
1451 | my $base = shift || return; | |
1452 | my $hash = shift || return; | |
1453 | ||
1454 | local $/ = "\0"; | |
1455 | ||
1456 | open my $fd, "-|", git_cmd(), "ls-tree", '-r', '-t', '-z', $base | |
1457 | or return undef; | |
1458 | while (my $line = <$fd>) { | |
1459 | chomp $line; | |
1460 | ||
1461 | #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb' | |
1462 | #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README' | |
1463 | if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) { | |
1464 | close $fd; | |
1465 | return $1; | |
1466 | } | |
1467 | } | |
1468 | close $fd; | |
1469 | return undef; | |
1470 | } | |
1471 | ||
717b8311 JN |
1472 | ## ...................................................................... |
1473 | ## git utility functions, directly accessing git repository | |
1474 | ||
847e01fb | 1475 | sub git_get_project_description { |
b87d78d6 | 1476 | my $path = shift; |
09bd7898 | 1477 | |
19806691 | 1478 | open my $fd, "$projectroot/$path/description" or return undef; |
b87d78d6 KS |
1479 | my $descr = <$fd>; |
1480 | close $fd; | |
2eb54efc JH |
1481 | if (defined $descr) { |
1482 | chomp $descr; | |
1483 | } | |
b87d78d6 | 1484 | return $descr; |
12a88f2f KS |
1485 | } |
1486 | ||
e79ca7cc JN |
1487 | sub git_get_project_url_list { |
1488 | my $path = shift; | |
1489 | ||
74d61667 | 1490 | open my $fd, "$projectroot/$path/cloneurl" or return; |
e79ca7cc JN |
1491 | my @git_project_url_list = map { chomp; $_ } <$fd>; |
1492 | close $fd; | |
1493 | ||
1494 | return wantarray ? @git_project_url_list : \@git_project_url_list; | |
1495 | } | |
1496 | ||
847e01fb | 1497 | sub git_get_projects_list { |
e30496df | 1498 | my ($filter) = @_; |
717b8311 JN |
1499 | my @list; |
1500 | ||
e30496df PB |
1501 | $filter ||= ''; |
1502 | $filter =~ s/\.git$//; | |
1503 | ||
c2b8b134 FL |
1504 | my ($check_forks) = gitweb_check_feature('forks'); |
1505 | ||
717b8311 JN |
1506 | if (-d $projects_list) { |
1507 | # search in directory | |
e30496df | 1508 | my $dir = $projects_list . ($filter ? "/$filter" : ''); |
6768d6b8 AK |
1509 | # remove the trailing "/" |
1510 | $dir =~ s!/+$!!; | |
c0011ff8 JN |
1511 | my $pfxlen = length("$dir"); |
1512 | ||
1513 | File::Find::find({ | |
1514 | follow_fast => 1, # follow symbolic links | |
d20602ee | 1515 | follow_skip => 2, # ignore duplicates |
c0011ff8 JN |
1516 | dangling_symlinks => 0, # ignore dangling symlinks, silently |
1517 | wanted => sub { | |
1518 | # skip project-list toplevel, if we get it. | |
1519 | return if (m!^[/.]$!); | |
1520 | # only directories can be git repositories | |
1521 | return unless (-d $_); | |
1522 | ||
1523 | my $subdir = substr($File::Find::name, $pfxlen + 1); | |
1524 | # we check related file in $projectroot | |
e30496df PB |
1525 | if ($check_forks and $subdir =~ m#/.#) { |
1526 | $File::Find::prune = 1; | |
1527 | } elsif (check_export_ok("$projectroot/$filter/$subdir")) { | |
1528 | push @list, { path => ($filter ? "$filter/" : '') . $subdir }; | |
c0011ff8 JN |
1529 | $File::Find::prune = 1; |
1530 | } | |
1531 | }, | |
1532 | }, "$dir"); | |
1533 | ||
717b8311 JN |
1534 | } elsif (-f $projects_list) { |
1535 | # read from file(url-encoded): | |
1536 | # 'git%2Fgit.git Linus+Torvalds' | |
1537 | # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin' | |
1538 | # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman' | |
c2b8b134 | 1539 | my %paths; |
dd1ad5f1 | 1540 | open my ($fd), $projects_list or return; |
c2b8b134 | 1541 | PROJECT: |
717b8311 JN |
1542 | while (my $line = <$fd>) { |
1543 | chomp $line; | |
1544 | my ($path, $owner) = split ' ', $line; | |
1545 | $path = unescape($path); | |
1546 | $owner = unescape($owner); | |
1547 | if (!defined $path) { | |
1548 | next; | |
1549 | } | |
83ee94c1 JH |
1550 | if ($filter ne '') { |
1551 | # looking for forks; | |
1552 | my $pfx = substr($path, 0, length($filter)); | |
1553 | if ($pfx ne $filter) { | |
c2b8b134 | 1554 | next PROJECT; |
83ee94c1 JH |
1555 | } |
1556 | my $sfx = substr($path, length($filter)); | |
1557 | if ($sfx !~ /^\/.*\.git$/) { | |
c2b8b134 FL |
1558 | next PROJECT; |
1559 | } | |
1560 | } elsif ($check_forks) { | |
1561 | PATH: | |
1562 | foreach my $filter (keys %paths) { | |
1563 | # looking for forks; | |
1564 | my $pfx = substr($path, 0, length($filter)); | |
1565 | if ($pfx ne $filter) { | |
1566 | next PATH; | |
1567 | } | |
1568 | my $sfx = substr($path, length($filter)); | |
1569 | if ($sfx !~ /^\/.*\.git$/) { | |
1570 | next PATH; | |
1571 | } | |
1572 | # is a fork, don't include it in | |
1573 | # the list | |
1574 | next PROJECT; | |
83ee94c1 JH |
1575 | } |
1576 | } | |
2172ce4b | 1577 | if (check_export_ok("$projectroot/$path")) { |
717b8311 JN |
1578 | my $pr = { |
1579 | path => $path, | |
00f429af | 1580 | owner => to_utf8($owner), |
717b8311 | 1581 | }; |
c2b8b134 FL |
1582 | push @list, $pr; |
1583 | (my $forks_path = $path) =~ s/\.git$//; | |
1584 | $paths{$forks_path}++; | |
717b8311 JN |
1585 | } |
1586 | } | |
1587 | close $fd; | |
1588 | } | |
717b8311 JN |
1589 | return @list; |
1590 | } | |
1591 | ||
47852450 JH |
1592 | our $gitweb_project_owner = undef; |
1593 | sub git_get_project_list_from_file { | |
1e0cf030 | 1594 | |
47852450 | 1595 | return if (defined $gitweb_project_owner); |
1e0cf030 | 1596 | |
47852450 | 1597 | $gitweb_project_owner = {}; |
1e0cf030 JN |
1598 | # read from file (url-encoded): |
1599 | # 'git%2Fgit.git Linus+Torvalds' | |
1600 | # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin' | |
1601 | # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman' | |
1602 | if (-f $projects_list) { | |
1603 | open (my $fd , $projects_list); | |
1604 | while (my $line = <$fd>) { | |
1605 | chomp $line; | |
1606 | my ($pr, $ow) = split ' ', $line; | |
1607 | $pr = unescape($pr); | |
1608 | $ow = unescape($ow); | |
47852450 | 1609 | $gitweb_project_owner->{$pr} = to_utf8($ow); |
1e0cf030 JN |
1610 | } |
1611 | close $fd; | |
1612 | } | |
47852450 JH |
1613 | } |
1614 | ||
1615 | sub git_get_project_owner { | |
1616 | my $project = shift; | |
1617 | my $owner; | |
1618 | ||
1619 | return undef unless $project; | |
1620 | ||
1621 | if (!defined $gitweb_project_owner) { | |
1622 | git_get_project_list_from_file(); | |
1623 | } | |
1624 | ||
1625 | if (exists $gitweb_project_owner->{$project}) { | |
1626 | $owner = $gitweb_project_owner->{$project}; | |
1627 | } | |
1e0cf030 JN |
1628 | if (!defined $owner) { |
1629 | $owner = get_file_owner("$projectroot/$project"); | |
1630 | } | |
1631 | ||
1632 | return $owner; | |
1633 | } | |
1634 | ||
c60c56cc JN |
1635 | sub git_get_last_activity { |
1636 | my ($path) = @_; | |
1637 | my $fd; | |
1638 | ||
1639 | $git_dir = "$projectroot/$path"; | |
1640 | open($fd, "-|", git_cmd(), 'for-each-ref', | |
0ff5ec70 | 1641 | '--format=%(committer)', |
c60c56cc | 1642 | '--sort=-committerdate', |
0ff5ec70 | 1643 | '--count=1', |
c60c56cc JN |
1644 | 'refs/heads') or return; |
1645 | my $most_recent = <$fd>; | |
1646 | close $fd or return; | |
785cdea9 JN |
1647 | if (defined $most_recent && |
1648 | $most_recent =~ / (\d+) [-+][01]\d\d\d$/) { | |
c60c56cc JN |
1649 | my $timestamp = $1; |
1650 | my $age = time - $timestamp; | |
1651 | return ($age, age_string($age)); | |
1652 | } | |
c956395e | 1653 | return (undef, undef); |
c60c56cc JN |
1654 | } |
1655 | ||
847e01fb | 1656 | sub git_get_references { |
717b8311 JN |
1657 | my $type = shift || ""; |
1658 | my %refs; | |
28b9d9f7 JN |
1659 | # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11 |
1660 | # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{} | |
1661 | open my $fd, "-|", git_cmd(), "show-ref", "--dereference", | |
1662 | ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type | |
9704d75d | 1663 | or return; |
d294e1ca | 1664 | |
717b8311 JN |
1665 | while (my $line = <$fd>) { |
1666 | chomp $line; | |
28b9d9f7 | 1667 | if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) { |
717b8311 | 1668 | if (defined $refs{$1}) { |
d294e1ca | 1669 | push @{$refs{$1}}, $2; |
717b8311 | 1670 | } else { |
d294e1ca | 1671 | $refs{$1} = [ $2 ]; |
717b8311 JN |
1672 | } |
1673 | } | |
1674 | } | |
1675 | close $fd or return; | |
1676 | return \%refs; | |
1677 | } | |
1678 | ||
56a322f1 JN |
1679 | sub git_get_rev_name_tags { |
1680 | my $hash = shift || return undef; | |
1681 | ||
25691fbe | 1682 | open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash |
56a322f1 JN |
1683 | or return; |
1684 | my $name_rev = <$fd>; | |
1685 | close $fd; | |
1686 | ||
1687 | if ($name_rev =~ m|^$hash tags/(.*)$|) { | |
1688 | return $1; | |
1689 | } else { | |
1690 | # catches also '$hash undefined' output | |
1691 | return undef; | |
1692 | } | |
1693 | } | |
1694 | ||
717b8311 JN |
1695 | ## ---------------------------------------------------------------------- |
1696 | ## parse to hash functions | |
1697 | ||
847e01fb | 1698 | sub parse_date { |
717b8311 JN |
1699 | my $epoch = shift; |
1700 | my $tz = shift || "-0000"; | |
1701 | ||
1702 | my %date; | |
1703 | my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
1704 | my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
1705 | my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch); | |
1706 | $date{'hour'} = $hour; | |
1707 | $date{'minute'} = $min; | |
1708 | $date{'mday'} = $mday; | |
1709 | $date{'day'} = $days[$wday]; | |
1710 | $date{'month'} = $months[$mon]; | |
af6feeb2 JN |
1711 | $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", |
1712 | $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec; | |
952c65fc JN |
1713 | $date{'mday-time'} = sprintf "%d %s %02d:%02d", |
1714 | $mday, $months[$mon], $hour ,$min; | |
af6feeb2 JN |
1715 | $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ", |
1716 | 1900+$year, $mon, $mday, $hour ,$min, $sec; | |
717b8311 JN |
1717 | |
1718 | $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/; | |
1719 | my $local = $epoch + ((int $1 + ($2/60)) * 3600); | |
1720 | ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local); | |
1721 | $date{'hour_local'} = $hour; | |
1722 | $date{'minute_local'} = $min; | |
1723 | $date{'tz_local'} = $tz; | |
af6feeb2 JN |
1724 | $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s", |
1725 | 1900+$year, $mon+1, $mday, | |
1726 | $hour, $min, $sec, $tz); | |
717b8311 JN |
1727 | return %date; |
1728 | } | |
1729 | ||
847e01fb | 1730 | sub parse_tag { |
ede5e100 KS |
1731 | my $tag_id = shift; |
1732 | my %tag; | |
d8a20ba9 | 1733 | my @comment; |
ede5e100 | 1734 | |
25691fbe | 1735 | open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return; |
d8a20ba9 | 1736 | $tag{'id'} = $tag_id; |
ede5e100 KS |
1737 | while (my $line = <$fd>) { |
1738 | chomp $line; | |
1739 | if ($line =~ m/^object ([0-9a-fA-F]{40})$/) { | |
1740 | $tag{'object'} = $1; | |
7ab0d2b6 | 1741 | } elsif ($line =~ m/^type (.+)$/) { |
ede5e100 | 1742 | $tag{'type'} = $1; |
7ab0d2b6 | 1743 | } elsif ($line =~ m/^tag (.+)$/) { |
ede5e100 | 1744 | $tag{'name'} = $1; |
d8a20ba9 KS |
1745 | } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) { |
1746 | $tag{'author'} = $1; | |
1747 | $tag{'epoch'} = $2; | |
1748 | $tag{'tz'} = $3; | |
1749 | } elsif ($line =~ m/--BEGIN/) { | |
1750 | push @comment, $line; | |
1751 | last; | |
1752 | } elsif ($line eq "") { | |
1753 | last; | |
ede5e100 KS |
1754 | } |
1755 | } | |
d8a20ba9 KS |
1756 | push @comment, <$fd>; |
1757 | $tag{'comment'} = \@comment; | |
19806691 | 1758 | close $fd or return; |
ede5e100 KS |
1759 | if (!defined $tag{'name'}) { |
1760 | return | |
1761 | }; | |
1762 | return %tag | |
1763 | } | |
1764 | ||
756bbf54 | 1765 | sub parse_commit_text { |
ccdfdea0 | 1766 | my ($commit_text, $withparents) = @_; |
756bbf54 | 1767 | my @commit_lines = split '\n', $commit_text; |
703ac710 | 1768 | my %co; |
703ac710 | 1769 | |
756bbf54 RF |
1770 | pop @commit_lines; # Remove '\0' |
1771 | ||
198a2a8a JN |
1772 | if (! @commit_lines) { |
1773 | return; | |
1774 | } | |
1775 | ||
25f422fb | 1776 | my $header = shift @commit_lines; |
198a2a8a | 1777 | if ($header !~ m/^[0-9a-fA-F]{40}/) { |
25f422fb KS |
1778 | return; |
1779 | } | |
ccdfdea0 | 1780 | ($co{'id'}, my @parents) = split ' ', $header; |
19806691 | 1781 | while (my $line = shift @commit_lines) { |
b87d78d6 | 1782 | last if $line eq "\n"; |
7ab0d2b6 | 1783 | if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) { |
703ac710 | 1784 | $co{'tree'} = $1; |
ccdfdea0 | 1785 | } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) { |
208b2dff | 1786 | push @parents, $1; |
022be3d0 | 1787 | } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) { |
3f714537 | 1788 | $co{'author'} = $1; |
185f09e5 KS |
1789 | $co{'author_epoch'} = $2; |
1790 | $co{'author_tz'} = $3; | |
ba00b8c1 JN |
1791 | if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) { |
1792 | $co{'author_name'} = $1; | |
1793 | $co{'author_email'} = $2; | |
2bf7a52c KS |
1794 | } else { |
1795 | $co{'author_name'} = $co{'author'}; | |
1796 | } | |
86eed32d KS |
1797 | } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) { |
1798 | $co{'committer'} = $1; | |
185f09e5 KS |
1799 | $co{'committer_epoch'} = $2; |
1800 | $co{'committer_tz'} = $3; | |
991910a9 | 1801 | $co{'committer_name'} = $co{'committer'}; |
ba00b8c1 JN |
1802 | if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) { |
1803 | $co{'committer_name'} = $1; | |
1804 | $co{'committer_email'} = $2; | |
1805 | } else { | |
1806 | $co{'committer_name'} = $co{'committer'}; | |
1807 | } | |
703ac710 KS |
1808 | } |
1809 | } | |
ede5e100 | 1810 | if (!defined $co{'tree'}) { |
25f422fb | 1811 | return; |
ede5e100 | 1812 | }; |
208b2dff RF |
1813 | $co{'parents'} = \@parents; |
1814 | $co{'parent'} = $parents[0]; | |
25f422fb | 1815 | |
19806691 | 1816 | foreach my $title (@commit_lines) { |
c2488d06 | 1817 | $title =~ s/^ //; |
19806691 | 1818 | if ($title ne "") { |
48c771f4 | 1819 | $co{'title'} = chop_str($title, 80, 5); |
19806691 KS |
1820 | # remove leading stuff of merges to make the interesting part visible |
1821 | if (length($title) > 50) { | |
1822 | $title =~ s/^Automatic //; | |
1823 | $title =~ s/^merge (of|with) /Merge ... /i; | |
1824 | if (length($title) > 50) { | |
1825 | $title =~ s/(http|rsync):\/\///; | |
1826 | } | |
1827 | if (length($title) > 50) { | |
1828 | $title =~ s/(master|www|rsync)\.//; | |
1829 | } | |
1830 | if (length($title) > 50) { | |
1831 | $title =~ s/kernel.org:?//; | |
1832 | } | |
1833 | if (length($title) > 50) { | |
1834 | $title =~ s/\/pub\/scm//; | |
1835 | } | |
1836 | } | |
48c771f4 | 1837 | $co{'title_short'} = chop_str($title, 50, 5); |
19806691 KS |
1838 | last; |
1839 | } | |
1840 | } | |
7e0fe5c9 PB |
1841 | if ($co{'title'} eq "") { |
1842 | $co{'title'} = $co{'title_short'} = '(no commit message)'; | |
1843 | } | |
25f422fb KS |
1844 | # remove added spaces |
1845 | foreach my $line (@commit_lines) { | |
1846 | $line =~ s/^ //; | |
1847 | } | |
1848 | $co{'comment'} = \@commit_lines; | |
2ae100df KS |
1849 | |
1850 | my $age = time - $co{'committer_epoch'}; | |
1851 | $co{'age'} = $age; | |
d263a6bd | 1852 | $co{'age_string'} = age_string($age); |
71be1e79 KS |
1853 | my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'}); |
1854 | if ($age > 60*60*24*7*2) { | |
1b1cd421 | 1855 | $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday; |
71be1e79 KS |
1856 | $co{'age_string_age'} = $co{'age_string'}; |
1857 | } else { | |
1858 | $co{'age_string_date'} = $co{'age_string'}; | |
1b1cd421 | 1859 | $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday; |
71be1e79 | 1860 | } |
703ac710 KS |
1861 | return %co; |
1862 | } | |
1863 | ||
756bbf54 RF |
1864 | sub parse_commit { |
1865 | my ($commit_id) = @_; | |
1866 | my %co; | |
1867 | ||
1868 | local $/ = "\0"; | |
1869 | ||
1870 | open my $fd, "-|", git_cmd(), "rev-list", | |
ccdfdea0 | 1871 | "--parents", |
756bbf54 | 1872 | "--header", |
756bbf54 RF |
1873 | "--max-count=1", |
1874 | $commit_id, | |
1875 | "--", | |
1876 | or die_error(undef, "Open git-rev-list failed"); | |
ccdfdea0 | 1877 | %co = parse_commit_text(<$fd>, 1); |
756bbf54 RF |
1878 | close $fd; |
1879 | ||
1880 | return %co; | |
1881 | } | |
1882 | ||
1883 | sub parse_commits { | |
1884 | my ($commit_id, $maxcount, $skip, $arg, $filename) = @_; | |
1885 | my @cos; | |
1886 | ||
1887 | $maxcount ||= 1; | |
1888 | $skip ||= 0; | |
1889 | ||
756bbf54 RF |
1890 | local $/ = "\0"; |
1891 | ||
1892 | open my $fd, "-|", git_cmd(), "rev-list", | |
1893 | "--header", | |
756bbf54 RF |
1894 | ($arg ? ($arg) : ()), |
1895 | ("--max-count=" . $maxcount), | |
f47efbb7 | 1896 | ("--skip=" . $skip), |
868bc068 | 1897 | @extra_options, |
756bbf54 RF |
1898 | $commit_id, |
1899 | "--", | |
1900 | ($filename ? ($filename) : ()) | |
1901 | or die_error(undef, "Open git-rev-list failed"); | |
1902 | while (my $line = <$fd>) { | |
1903 | my %co = parse_commit_text($line); | |
1904 | push @cos, \%co; | |
1905 | } | |
1906 | close $fd; | |
1907 | ||
1908 | return wantarray ? @cos : \@cos; | |
1909 | } | |
1910 | ||
a446d6bb JN |
1911 | # parse ref from ref_file, given by ref_id, with given type |
1912 | sub parse_ref { | |
1913 | my $ref_file = shift; | |
1914 | my $ref_id = shift; | |
1915 | my $type = shift || git_get_type($ref_id); | |
1916 | my %ref_item; | |
1917 | ||
1918 | $ref_item{'type'} = $type; | |
1919 | $ref_item{'id'} = $ref_id; | |
1920 | $ref_item{'epoch'} = 0; | |
1921 | $ref_item{'age'} = "unknown"; | |
1922 | if ($type eq "tag") { | |
1923 | my %tag = parse_tag($ref_id); | |
1924 | $ref_item{'comment'} = $tag{'comment'}; | |
1925 | if ($tag{'type'} eq "commit") { | |
1926 | my %co = parse_commit($tag{'object'}); | |
1927 | $ref_item{'epoch'} = $co{'committer_epoch'}; | |
1928 | $ref_item{'age'} = $co{'age_string'}; | |
1929 | } elsif (defined($tag{'epoch'})) { | |
1930 | my $age = time - $tag{'epoch'}; | |
1931 | $ref_item{'epoch'} = $tag{'epoch'}; | |
1932 | $ref_item{'age'} = age_string($age); | |
1933 | } | |
1934 | $ref_item{'reftype'} = $tag{'type'}; | |
1935 | $ref_item{'name'} = $tag{'name'}; | |
1936 | $ref_item{'refid'} = $tag{'object'}; | |
1937 | } elsif ($type eq "commit"){ | |
1938 | my %co = parse_commit($ref_id); | |
1939 | $ref_item{'reftype'} = "commit"; | |
1940 | $ref_item{'name'} = $ref_file; | |
1941 | $ref_item{'title'} = $co{'title'}; | |
1942 | $ref_item{'refid'} = $ref_id; | |
1943 | $ref_item{'epoch'} = $co{'committer_epoch'}; | |
1944 | $ref_item{'age'} = $co{'age_string'}; | |
1945 | } else { | |
1946 | $ref_item{'reftype'} = $type; | |
1947 | $ref_item{'name'} = $ref_file; | |
1948 | $ref_item{'refid'} = $ref_id; | |
1949 | } | |
1950 | ||
1951 | return %ref_item; | |
1952 | } | |
1953 | ||
e8e41a93 | 1954 | # parse line of git-diff-tree "raw" output |
740e67f9 JN |
1955 | sub parse_difftree_raw_line { |
1956 | my $line = shift; | |
1957 | my %res; | |
1958 | ||
1959 | # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c' | |
1960 | # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c' | |
1961 | if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) { | |
1962 | $res{'from_mode'} = $1; | |
1963 | $res{'to_mode'} = $2; | |
1964 | $res{'from_id'} = $3; | |
1965 | $res{'to_id'} = $4; | |
1966 | $res{'status'} = $5; | |
1967 | $res{'similarity'} = $6; | |
1968 | if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied | |
e8e41a93 | 1969 | ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7); |
740e67f9 JN |
1970 | } else { |
1971 | $res{'file'} = unquote($7); | |
1972 | } | |
1973 | } | |
78bc403a JN |
1974 | # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh' |
1975 | # combined diff (for merge commit) | |
1976 | elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) { | |
1977 | $res{'nparents'} = length($1); | |
1978 | $res{'from_mode'} = [ split(' ', $2) ]; | |
1979 | $res{'to_mode'} = pop @{$res{'from_mode'}}; | |
1980 | $res{'from_id'} = [ split(' ', $3) ]; | |
1981 | $res{'to_id'} = pop @{$res{'from_id'}}; | |
1982 | $res{'status'} = [ split('', $4) ]; | |
1983 | $res{'to_file'} = unquote($5); | |
1984 | } | |
740e67f9 | 1985 | # 'c512b523472485aef4fff9e57b229d9d243c967f' |
0edcb37d JN |
1986 | elsif ($line =~ m/^([0-9a-fA-F]{40})$/) { |
1987 | $res{'commit'} = $1; | |
1988 | } | |
740e67f9 JN |
1989 | |
1990 | return wantarray ? %res : \%res; | |
1991 | } | |
1992 | ||
cb849b46 JN |
1993 | # parse line of git-ls-tree output |
1994 | sub parse_ls_tree_line ($;%) { | |
1995 | my $line = shift; | |
1996 | my %opts = @_; | |
1997 | my %res; | |
1998 | ||
1999 | #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' | |
8b4b94cc | 2000 | $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s; |
cb849b46 JN |
2001 | |
2002 | $res{'mode'} = $1; | |
2003 | $res{'type'} = $2; | |
2004 | $res{'hash'} = $3; | |
2005 | if ($opts{'-z'}) { | |
2006 | $res{'name'} = $4; | |
2007 | } else { | |
2008 | $res{'name'} = unquote($4); | |
2009 | } | |
2010 | ||
2011 | return wantarray ? %res : \%res; | |
2012 | } | |
2013 | ||
90921740 JN |
2014 | # generates _two_ hashes, references to which are passed as 2 and 3 argument |
2015 | sub parse_from_to_diffinfo { | |
2016 | my ($diffinfo, $from, $to, @parents) = @_; | |
2017 | ||
2018 | if ($diffinfo->{'nparents'}) { | |
2019 | # combined diff | |
2020 | $from->{'file'} = []; | |
2021 | $from->{'href'} = []; | |
2022 | fill_from_file_info($diffinfo, @parents) | |
2023 | unless exists $diffinfo->{'from_file'}; | |
2024 | for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) { | |
2025 | $from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'}; | |
2026 | if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file | |
2027 | $from->{'href'}[$i] = href(action=>"blob", | |
2028 | hash_base=>$parents[$i], | |
2029 | hash=>$diffinfo->{'from_id'}[$i], | |
2030 | file_name=>$from->{'file'}[$i]); | |
2031 | } else { | |
2032 | $from->{'href'}[$i] = undef; | |
2033 | } | |
2034 | } | |
2035 | } else { | |
2036 | $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'}; | |
2037 | if ($diffinfo->{'status'} ne "A") { # not new (added) file | |
2038 | $from->{'href'} = href(action=>"blob", hash_base=>$hash_parent, | |
2039 | hash=>$diffinfo->{'from_id'}, | |
2040 | file_name=>$from->{'file'}); | |
2041 | } else { | |
2042 | delete $from->{'href'}; | |
2043 | } | |
2044 | } | |
2045 | ||
2046 | $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'}; | |
2047 | if (!is_deleted($diffinfo)) { # file exists in result | |
2048 | $to->{'href'} = href(action=>"blob", hash_base=>$hash, | |
2049 | hash=>$diffinfo->{'to_id'}, | |
2050 | file_name=>$to->{'file'}); | |
2051 | } else { | |
2052 | delete $to->{'href'}; | |
2053 | } | |
2054 | } | |
2055 | ||
717b8311 JN |
2056 | ## ...................................................................... |
2057 | ## parse to array of hashes functions | |
4c02e3c5 | 2058 | |
cd146408 JN |
2059 | sub git_get_heads_list { |
2060 | my $limit = shift; | |
2061 | my @headslist; | |
2062 | ||
2063 | open my $fd, '-|', git_cmd(), 'for-each-ref', | |
2064 | ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate', | |
2065 | '--format=%(objectname) %(refname) %(subject)%00%(committer)', | |
2066 | 'refs/heads' | |
c83a77e4 JN |
2067 | or return; |
2068 | while (my $line = <$fd>) { | |
cd146408 | 2069 | my %ref_item; |
120ddde2 | 2070 | |
cd146408 JN |
2071 | chomp $line; |
2072 | my ($refinfo, $committerinfo) = split(/\0/, $line); | |
2073 | my ($hash, $name, $title) = split(' ', $refinfo, 3); | |
2074 | my ($committer, $epoch, $tz) = | |
2075 | ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/); | |
2076 | $name =~ s!^refs/heads/!!; | |
2077 | ||
2078 | $ref_item{'name'} = $name; | |
2079 | $ref_item{'id'} = $hash; | |
2080 | $ref_item{'title'} = $title || '(no commit message)'; | |
2081 | $ref_item{'epoch'} = $epoch; | |
2082 | if ($epoch) { | |
2083 | $ref_item{'age'} = age_string(time - $ref_item{'epoch'}); | |
2084 | } else { | |
2085 | $ref_item{'age'} = "unknown"; | |
717b8311 | 2086 | } |
cd146408 JN |
2087 | |
2088 | push @headslist, \%ref_item; | |
c83a77e4 JN |
2089 | } |
2090 | close $fd; | |
2091 | ||
cd146408 JN |
2092 | return wantarray ? @headslist : \@headslist; |
2093 | } | |
2094 | ||
2095 | sub git_get_tags_list { | |
2096 | my $limit = shift; | |
2097 | my @tagslist; | |
2098 | ||
2099 | open my $fd, '-|', git_cmd(), 'for-each-ref', | |
2100 | ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate', | |
2101 | '--format=%(objectname) %(objecttype) %(refname) '. | |
2102 | '%(*objectname) %(*objecttype) %(subject)%00%(creator)', | |
2103 | 'refs/tags' | |
2104 | or return; | |
2105 | while (my $line = <$fd>) { | |
2106 | my %ref_item; | |
7a13b999 | 2107 | |
cd146408 JN |
2108 | chomp $line; |
2109 | my ($refinfo, $creatorinfo) = split(/\0/, $line); | |
2110 | my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6); | |
2111 | my ($creator, $epoch, $tz) = | |
2112 | ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/); | |
2113 | $name =~ s!^refs/tags/!!; | |
2114 | ||
2115 | $ref_item{'type'} = $type; | |
2116 | $ref_item{'id'} = $id; | |
2117 | $ref_item{'name'} = $name; | |
2118 | if ($type eq "tag") { | |
2119 | $ref_item{'subject'} = $title; | |
2120 | $ref_item{'reftype'} = $reftype; | |
2121 | $ref_item{'refid'} = $refid; | |
2122 | } else { | |
2123 | $ref_item{'reftype'} = $type; | |
2124 | $ref_item{'refid'} = $id; | |
2125 | } | |
2126 | ||
2127 | if ($type eq "tag" || $type eq "commit") { | |
2128 | $ref_item{'epoch'} = $epoch; | |
2129 | if ($epoch) { | |
2130 | $ref_item{'age'} = age_string(time - $ref_item{'epoch'}); | |
2131 | } else { | |
2132 | $ref_item{'age'} = "unknown"; | |
2133 | } | |
2134 | } | |
991910a9 | 2135 | |
cd146408 | 2136 | push @tagslist, \%ref_item; |
717b8311 | 2137 | } |
cd146408 JN |
2138 | close $fd; |
2139 | ||
2140 | return wantarray ? @tagslist : \@tagslist; | |
86eed32d KS |
2141 | } |
2142 | ||
717b8311 JN |
2143 | ## ---------------------------------------------------------------------- |
2144 | ## filesystem-related functions | |
022be3d0 | 2145 | |
c07ad4b9 KS |
2146 | sub get_file_owner { |
2147 | my $path = shift; | |
2148 | ||
2149 | my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path); | |
2150 | my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid); | |
2151 | if (!defined $gcos) { | |
2152 | return undef; | |
2153 | } | |
2154 | my $owner = $gcos; | |
2155 | $owner =~ s/[,;].*$//; | |
00f429af | 2156 | return to_utf8($owner); |
c07ad4b9 KS |
2157 | } |
2158 | ||
717b8311 JN |
2159 | ## ...................................................................... |
2160 | ## mimetype related functions | |
09bd7898 | 2161 | |
717b8311 JN |
2162 | sub mimetype_guess_file { |
2163 | my $filename = shift; | |
2164 | my $mimemap = shift; | |
2165 | -r $mimemap or return undef; | |
2166 | ||
2167 | my %mimemap; | |
2168 | open(MIME, $mimemap) or return undef; | |
2169 | while (<MIME>) { | |
618918e5 | 2170 | next if m/^#/; # skip comments |
717b8311 | 2171 | my ($mime, $exts) = split(/\t+/); |
46b059d7 JH |
2172 | if (defined $exts) { |
2173 | my @exts = split(/\s+/, $exts); | |
2174 | foreach my $ext (@exts) { | |
2175 | $mimemap{$ext} = $mime; | |
2176 | } | |
09bd7898 | 2177 | } |
09bd7898 | 2178 | } |
717b8311 | 2179 | close(MIME); |
09bd7898 | 2180 | |
8059319a | 2181 | $filename =~ /\.([^.]*)$/; |
717b8311 JN |
2182 | return $mimemap{$1}; |
2183 | } | |
5996ca08 | 2184 | |
717b8311 JN |
2185 | sub mimetype_guess { |
2186 | my $filename = shift; | |
2187 | my $mime; | |
2188 | $filename =~ /\./ or return undef; | |
5996ca08 | 2189 | |
717b8311 JN |
2190 | if ($mimetypes_file) { |
2191 | my $file = $mimetypes_file; | |
d5aa50de JN |
2192 | if ($file !~ m!^/!) { # if it is relative path |
2193 | # it is relative to project | |
2194 | $file = "$projectroot/$project/$file"; | |
2195 | } | |
717b8311 JN |
2196 | $mime = mimetype_guess_file($filename, $file); |
2197 | } | |
2198 | $mime ||= mimetype_guess_file($filename, '/etc/mime.types'); | |
2199 | return $mime; | |
5996ca08 FF |
2200 | } |
2201 | ||
847e01fb | 2202 | sub blob_mimetype { |
717b8311 JN |
2203 | my $fd = shift; |
2204 | my $filename = shift; | |
5996ca08 | 2205 | |
717b8311 JN |
2206 | if ($filename) { |
2207 | my $mime = mimetype_guess($filename); | |
2208 | $mime and return $mime; | |
d8d17b5d | 2209 | } |
717b8311 JN |
2210 | |
2211 | # just in case | |
2212 | return $default_blob_plain_mimetype unless $fd; | |
2213 | ||
2214 | if (-T $fd) { | |
2215 | return 'text/plain' . | |
2216 | ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : ''); | |
2217 | } elsif (! $filename) { | |
2218 | return 'application/octet-stream'; | |
2219 | } elsif ($filename =~ m/\.png$/i) { | |
2220 | return 'image/png'; | |
2221 | } elsif ($filename =~ m/\.gif$/i) { | |
2222 | return 'image/gif'; | |
2223 | } elsif ($filename =~ m/\.jpe?g$/i) { | |
2224 | return 'image/jpeg'; | |
d8d17b5d | 2225 | } else { |
717b8311 | 2226 | return 'application/octet-stream'; |
f7ab660c | 2227 | } |
717b8311 JN |
2228 | } |
2229 | ||
2230 | ## ====================================================================== | |
2231 | ## functions printing HTML: header, footer, error page | |
2232 | ||
2233 | sub git_header_html { | |
2234 | my $status = shift || "200 OK"; | |
2235 | my $expires = shift; | |
2236 | ||
8be2890c | 2237 | my $title = "$site_name"; |
717b8311 | 2238 | if (defined $project) { |
00f429af | 2239 | $title .= " - " . to_utf8($project); |
717b8311 JN |
2240 | if (defined $action) { |
2241 | $title .= "/$action"; | |
2242 | if (defined $file_name) { | |
403d0906 | 2243 | $title .= " - " . esc_path($file_name); |
717b8311 JN |
2244 | if ($action eq "tree" && $file_name !~ m|/$|) { |
2245 | $title .= "/"; | |
2246 | } | |
2247 | } | |
2248 | } | |
f7ab660c | 2249 | } |
717b8311 JN |
2250 | my $content_type; |
2251 | # require explicit support from the UA if we are to send the page as | |
2252 | # 'application/xhtml+xml', otherwise send it as plain old 'text/html'. | |
2253 | # we have to do this because MSIE sometimes globs '*/*', pretending to | |
2254 | # support xhtml+xml but choking when it gets what it asked for. | |
952c65fc JN |
2255 | if (defined $cgi->http('HTTP_ACCEPT') && |
2256 | $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ && | |
2257 | $cgi->Accept('application/xhtml+xml') != 0) { | |
717b8311 | 2258 | $content_type = 'application/xhtml+xml'; |
f7ab660c | 2259 | } else { |
717b8311 | 2260 | $content_type = 'text/html'; |
f7ab660c | 2261 | } |
952c65fc JN |
2262 | print $cgi->header(-type=>$content_type, -charset => 'utf-8', |
2263 | -status=> $status, -expires => $expires); | |
45c9a758 | 2264 | my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : ''; |
717b8311 JN |
2265 | print <<EOF; |
2266 | <?xml version="1.0" encoding="utf-8"?> | |
2267 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
2268 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"> | |
d4baf9ea | 2269 | <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke --> |
717b8311 JN |
2270 | <!-- git core binaries version $git_version --> |
2271 | <head> | |
2272 | <meta http-equiv="content-type" content="$content_type; charset=utf-8"/> | |
45c9a758 | 2273 | <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/> |
717b8311 JN |
2274 | <meta name="robots" content="index, nofollow"/> |
2275 | <title>$title</title> | |
717b8311 | 2276 | EOF |
b2d3476e AC |
2277 | # print out each stylesheet that exist |
2278 | if (defined $stylesheet) { | |
2279 | #provides backwards capability for those people who define style sheet in a config file | |
2280 | print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n"; | |
2281 | } else { | |
2282 | foreach my $stylesheet (@stylesheets) { | |
2283 | next unless $stylesheet; | |
2284 | print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n"; | |
2285 | } | |
2286 | } | |
dd04c428 | 2287 | if (defined $project) { |
af6feeb2 JN |
2288 | printf('<link rel="alternate" title="%s log RSS feed" '. |
2289 | 'href="%s" type="application/rss+xml" />'."\n", | |
1c2a4f5a | 2290 | esc_param($project), href(action=>"rss")); |
12075103 JN |
2291 | printf('<link rel="alternate" title="%s log RSS feed (no merges)" '. |
2292 | 'href="%s" type="application/rss+xml" />'."\n", | |
2293 | esc_param($project), href(action=>"rss", | |
2294 | extra_options=>"--no-merges")); | |
af6feeb2 JN |
2295 | printf('<link rel="alternate" title="%s log Atom feed" '. |
2296 | 'href="%s" type="application/atom+xml" />'."\n", | |
2297 | esc_param($project), href(action=>"atom")); | |
12075103 JN |
2298 | printf('<link rel="alternate" title="%s log Atom feed (no merges)" '. |
2299 | 'href="%s" type="application/atom+xml" />'."\n", | |
2300 | esc_param($project), href(action=>"atom", | |
2301 | extra_options=>"--no-merges")); | |
9d0734ae JN |
2302 | } else { |
2303 | printf('<link rel="alternate" title="%s projects list" '. | |
2304 | 'href="%s" type="text/plain; charset=utf-8"/>'."\n", | |
2305 | $site_name, href(project=>undef, action=>"project_index")); | |
af6feeb2 | 2306 | printf('<link rel="alternate" title="%s projects feeds" '. |
9d0734ae JN |
2307 | 'href="%s" type="text/x-opml"/>'."\n", |
2308 | $site_name, href(project=>undef, action=>"opml")); | |
dd04c428 | 2309 | } |
0b5deba1 JN |
2310 | if (defined $favicon) { |
2311 | print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n); | |
2312 | } | |
10161355 | 2313 | |
dd04c428 | 2314 | print "</head>\n" . |
b2d3476e AC |
2315 | "<body>\n"; |
2316 | ||
2317 | if (-f $site_header) { | |
2318 | open (my $fd, $site_header); | |
2319 | print <$fd>; | |
2320 | close $fd; | |
2321 | } | |
2322 | ||
2323 | print "<div class=\"page_header\">\n" . | |
9a7a62ff JN |
2324 | $cgi->a({-href => esc_url($logo_url), |
2325 | -title => $logo_label}, | |
2326 | qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>)); | |
f93bff8d | 2327 | print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / "; |
717b8311 | 2328 | if (defined $project) { |
1c2a4f5a | 2329 | print $cgi->a({-href => href(action=>"summary")}, esc_html($project)); |
717b8311 JN |
2330 | if (defined $action) { |
2331 | print " / $action"; | |
2332 | } | |
2333 | print "\n"; | |
6be93511 | 2334 | } |
d77b5673 PB |
2335 | print "</div>\n"; |
2336 | ||
6be93511 RF |
2337 | my ($have_search) = gitweb_check_feature('search'); |
2338 | if ((defined $project) && ($have_search)) { | |
717b8311 JN |
2339 | if (!defined $searchtext) { |
2340 | $searchtext = ""; | |
2341 | } | |
2342 | my $search_hash; | |
2343 | if (defined $hash_base) { | |
2344 | $search_hash = $hash_base; | |
2345 | } elsif (defined $hash) { | |
2346 | $search_hash = $hash; | |
bddec01d | 2347 | } else { |
717b8311 | 2348 | $search_hash = "HEAD"; |
bddec01d | 2349 | } |
40375a83 MM |
2350 | my $action = $my_uri; |
2351 | my ($use_pathinfo) = gitweb_check_feature('pathinfo'); | |
2352 | if ($use_pathinfo) { | |
2353 | $action .= "/$project"; | |
2354 | } else { | |
2355 | $cgi->param("p", $project); | |
2356 | } | |
717b8311 JN |
2357 | $cgi->param("a", "search"); |
2358 | $cgi->param("h", $search_hash); | |
40375a83 | 2359 | print $cgi->startform(-method => "get", -action => $action) . |
717b8311 | 2360 | "<div class=\"search\">\n" . |
40375a83 | 2361 | (!$use_pathinfo && $cgi->hidden(-name => "p") . "\n") . |
717b8311 JN |
2362 | $cgi->hidden(-name => "a") . "\n" . |
2363 | $cgi->hidden(-name => "h") . "\n" . | |
88ad729b | 2364 | $cgi->popup_menu(-name => 'st', -default => 'commit', |
e7738553 | 2365 | -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) . |
88ad729b PB |
2366 | $cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) . |
2367 | " search:\n", | |
717b8311 JN |
2368 | $cgi->textfield(-name => "s", -value => $searchtext) . "\n" . |
2369 | "</div>" . | |
2370 | $cgi->end_form() . "\n"; | |
b87d78d6 | 2371 | } |
717b8311 JN |
2372 | } |
2373 | ||
2374 | sub git_footer_html { | |
2375 | print "<div class=\"page_footer\">\n"; | |
2376 | if (defined $project) { | |
847e01fb | 2377 | my $descr = git_get_project_description($project); |
717b8311 JN |
2378 | if (defined $descr) { |
2379 | print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n"; | |
2380 | } | |
a1565c44 | 2381 | print $cgi->a({-href => href(action=>"rss"), |
af6feeb2 JN |
2382 | -class => "rss_logo"}, "RSS") . " "; |
2383 | print $cgi->a({-href => href(action=>"atom"), | |
2384 | -class => "rss_logo"}, "Atom") . "\n"; | |
717b8311 | 2385 | } else { |
a1565c44 | 2386 | print $cgi->a({-href => href(project=>undef, action=>"opml"), |
9d0734ae JN |
2387 | -class => "rss_logo"}, "OPML") . " "; |
2388 | print $cgi->a({-href => href(project=>undef, action=>"project_index"), | |
2389 | -class => "rss_logo"}, "TXT") . "\n"; | |
717b8311 | 2390 | } |
b2d3476e AC |
2391 | print "</div>\n" ; |
2392 | ||
2393 | if (-f $site_footer) { | |
2394 | open (my $fd, $site_footer); | |
2395 | print <$fd>; | |
2396 | close $fd; | |
2397 | } | |
2398 | ||
2399 | print "</body>\n" . | |
717b8311 JN |
2400 | "</html>"; |
2401 | } | |
2402 | ||
2403 | sub die_error { | |
2404 | my $status = shift || "403 Forbidden"; | |
2405 | my $error = shift || "Malformed query, file missing or permission denied"; | |
2406 | ||
2407 | git_header_html($status); | |
59b9f61a JN |
2408 | print <<EOF; |
2409 | <div class="page_body"> | |
2410 | <br /><br /> | |
2411 | $status - $error | |
2412 | <br /> | |
2413 | </div> | |
2414 | EOF | |
b87d78d6 | 2415 | git_footer_html(); |
717b8311 | 2416 | exit; |
161332a5 KS |
2417 | } |
2418 | ||
717b8311 JN |
2419 | ## ---------------------------------------------------------------------- |
2420 | ## functions printing or outputting HTML: navigation | |
2421 | ||
847e01fb | 2422 | sub git_print_page_nav { |
717b8311 JN |
2423 | my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_; |
2424 | $extra = '' if !defined $extra; # pager or formats | |
2425 | ||
2426 | my @navs = qw(summary shortlog log commit commitdiff tree); | |
2427 | if ($suppress) { | |
2428 | @navs = grep { $_ ne $suppress } @navs; | |
2429 | } | |
2430 | ||
1c2a4f5a | 2431 | my %arg = map { $_ => {action=>$_} } @navs; |
717b8311 JN |
2432 | if (defined $head) { |
2433 | for (qw(commit commitdiff)) { | |
3be8e720 | 2434 | $arg{$_}{'hash'} = $head; |
717b8311 JN |
2435 | } |
2436 | if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) { | |
2437 | for (qw(shortlog log)) { | |
3be8e720 | 2438 | $arg{$_}{'hash'} = $head; |
045e531a | 2439 | } |
6a928415 KS |
2440 | } |
2441 | } | |
3be8e720 JN |
2442 | $arg{'tree'}{'hash'} = $treehead if defined $treehead; |
2443 | $arg{'tree'}{'hash_base'} = $treebase if defined $treebase; | |
717b8311 JN |
2444 | |
2445 | print "<div class=\"page_nav\">\n" . | |
2446 | (join " | ", | |
1c2a4f5a MW |
2447 | map { $_ eq $current ? |
2448 | $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_") | |
2449 | } @navs); | |
717b8311 JN |
2450 | print "<br/>\n$extra<br/>\n" . |
2451 | "</div>\n"; | |
6a928415 KS |
2452 | } |
2453 | ||
847e01fb | 2454 | sub format_paging_nav { |
717b8311 JN |
2455 | my ($action, $hash, $head, $page, $nrevs) = @_; |
2456 | my $paging_nav; | |
594e212b | 2457 | |
717b8311 JN |
2458 | |
2459 | if ($hash ne $head || $page) { | |
1c2a4f5a | 2460 | $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD"); |
594e212b | 2461 | } else { |
717b8311 JN |
2462 | $paging_nav .= "HEAD"; |
2463 | } | |
2464 | ||
2465 | if ($page > 0) { | |
2466 | $paging_nav .= " ⋅ " . | |
1c2a4f5a | 2467 | $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1), |
26298b5f | 2468 | -accesskey => "p", -title => "Alt-p"}, "prev"); |
717b8311 JN |
2469 | } else { |
2470 | $paging_nav .= " ⋅ prev"; | |
2471 | } | |
2472 | ||
2473 | if ($nrevs >= (100 * ($page+1)-1)) { | |
2474 | $paging_nav .= " ⋅ " . | |
1c2a4f5a | 2475 | $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1), |
26298b5f | 2476 | -accesskey => "n", -title => "Alt-n"}, "next"); |
717b8311 JN |
2477 | } else { |
2478 | $paging_nav .= " ⋅ next"; | |
594e212b | 2479 | } |
717b8311 JN |
2480 | |
2481 | return $paging_nav; | |
594e212b JN |
2482 | } |
2483 | ||
717b8311 JN |
2484 | ## ...................................................................... |
2485 | ## functions printing or outputting HTML: div | |
2486 | ||
847e01fb | 2487 | sub git_print_header_div { |
717b8311 | 2488 | my ($action, $title, $hash, $hash_base) = @_; |
1c2a4f5a | 2489 | my %args = (); |
717b8311 | 2490 | |
3be8e720 JN |
2491 | $args{'action'} = $action; |
2492 | $args{'hash'} = $hash if $hash; | |
2493 | $args{'hash_base'} = $hash_base if $hash_base; | |
717b8311 JN |
2494 | |
2495 | print "<div class=\"header\">\n" . | |
1c2a4f5a MW |
2496 | $cgi->a({-href => href(%args), -class => "title"}, |
2497 | $title ? $title : $action) . | |
2498 | "\n</div>\n"; | |
717b8311 | 2499 | } |
ede5e100 | 2500 | |
6fd92a28 JN |
2501 | #sub git_print_authorship (\%) { |
2502 | sub git_print_authorship { | |
2503 | my $co = shift; | |
2504 | ||
a44465cc | 2505 | my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'}); |
6fd92a28 JN |
2506 | print "<div class=\"author_date\">" . |
2507 | esc_html($co->{'author_name'}) . | |
a44465cc JN |
2508 | " [$ad{'rfc2822'}"; |
2509 | if ($ad{'hour_local'} < 6) { | |
2510 | printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", | |
2511 | $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); | |
2512 | } else { | |
2513 | printf(" (%02d:%02d %s)", | |
2514 | $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); | |
2515 | } | |
2516 | print "]</div>\n"; | |
6fd92a28 JN |
2517 | } |
2518 | ||
717b8311 JN |
2519 | sub git_print_page_path { |
2520 | my $name = shift; | |
2521 | my $type = shift; | |
59fb1c94 | 2522 | my $hb = shift; |
ede5e100 | 2523 | |
4df118ed JN |
2524 | |
2525 | print "<div class=\"page_path\">"; | |
2526 | print $cgi->a({-href => href(action=>"tree", hash_base=>$hb), | |
00f429af | 2527 | -title => 'tree root'}, to_utf8("[$project]")); |
4df118ed JN |
2528 | print " / "; |
2529 | if (defined $name) { | |
762c7205 JN |
2530 | my @dirname = split '/', $name; |
2531 | my $basename = pop @dirname; | |
2532 | my $fullname = ''; | |
2533 | ||
762c7205 | 2534 | foreach my $dir (@dirname) { |
16fdb488 | 2535 | $fullname .= ($fullname ? '/' : '') . $dir; |
762c7205 JN |
2536 | print $cgi->a({-href => href(action=>"tree", file_name=>$fullname, |
2537 | hash_base=>$hb), | |
edc04e90 | 2538 | -title => $fullname}, esc_path($dir)); |
26d0a976 | 2539 | print " / "; |
762c7205 JN |
2540 | } |
2541 | if (defined $type && $type eq 'blob') { | |
952c65fc | 2542 | print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name, |
762c7205 | 2543 | hash_base=>$hb), |
edc04e90 | 2544 | -title => $name}, esc_path($basename)); |
762c7205 JN |
2545 | } elsif (defined $type && $type eq 'tree') { |
2546 | print $cgi->a({-href => href(action=>"tree", file_name=>$file_name, | |
2547 | hash_base=>$hb), | |
edc04e90 | 2548 | -title => $name}, esc_path($basename)); |
4df118ed | 2549 | print " / "; |
59fb1c94 | 2550 | } else { |
403d0906 | 2551 | print esc_path($basename); |
59fb1c94 | 2552 | } |
ede5e100 | 2553 | } |
4df118ed | 2554 | print "<br/></div>\n"; |
ede5e100 KS |
2555 | } |
2556 | ||
b7f9253d JN |
2557 | # sub git_print_log (\@;%) { |
2558 | sub git_print_log ($;%) { | |
d16d093c | 2559 | my $log = shift; |
b7f9253d | 2560 | my %opts = @_; |
d16d093c | 2561 | |
b7f9253d JN |
2562 | if ($opts{'-remove_title'}) { |
2563 | # remove title, i.e. first line of log | |
2564 | shift @$log; | |
2565 | } | |
d16d093c JN |
2566 | # remove leading empty lines |
2567 | while (defined $log->[0] && $log->[0] eq "") { | |
2568 | shift @$log; | |
2569 | } | |
2570 | ||
2571 | # print log | |
2572 | my $signoff = 0; | |
2573 | my $empty = 0; | |
2574 | foreach my $line (@$log) { | |
b7f9253d JN |
2575 | if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) { |
2576 | $signoff = 1; | |
fba20b42 | 2577 | $empty = 0; |
b7f9253d JN |
2578 | if (! $opts{'-remove_signoff'}) { |
2579 | print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n"; | |
2580 | next; | |
2581 | } else { | |
2582 | # remove signoff lines | |
2583 | next; | |
2584 | } | |
2585 | } else { | |
2586 | $signoff = 0; | |
2587 | } | |
2588 | ||
d16d093c JN |
2589 | # print only one empty line |
2590 | # do not print empty line after signoff | |
2591 | if ($line eq "") { | |
2592 | next if ($empty || $signoff); | |
2593 | $empty = 1; | |
2594 | } else { | |
2595 | $empty = 0; | |
2596 | } | |
b7f9253d JN |
2597 | |
2598 | print format_log_line_html($line) . "<br/>\n"; | |
2599 | } | |
2600 | ||
2601 | if ($opts{'-final_empty_line'}) { | |
2602 | # end with single empty line | |
2603 | print "<br/>\n" unless $empty; | |
d16d093c JN |
2604 | } |
2605 | } | |
2606 | ||
e33fba4c JN |
2607 | # return link target (what link points to) |
2608 | sub git_get_link_target { | |
2609 | my $hash = shift; | |
2610 | my $link_target; | |
2611 | ||
2612 | # read link | |
2613 | open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash | |
2614 | or return; | |
2615 | { | |
2616 | local $/; | |
2617 | $link_target = <$fd>; | |
2618 | } | |
2619 | close $fd | |
2620 | or return; | |
2621 | ||
2622 | return $link_target; | |
2623 | } | |
2624 | ||
3bf9d570 JN |
2625 | # given link target, and the directory (basedir) the link is in, |
2626 | # return target of link relative to top directory (top tree); | |
2627 | # return undef if it is not possible (including absolute links). | |
2628 | sub normalize_link_target { | |
2629 | my ($link_target, $basedir, $hash_base) = @_; | |
2630 | ||
2631 | # we can normalize symlink target only if $hash_base is provided | |
2632 | return unless $hash_base; | |
2633 | ||
2634 | # absolute symlinks (beginning with '/') cannot be normalized | |
2635 | return if (substr($link_target, 0, 1) eq '/'); | |
2636 | ||
2637 | # normalize link target to path from top (root) tree (dir) | |
2638 | my $path; | |
2639 | if ($basedir) { | |
2640 | $path = $basedir . '/' . $link_target; | |
2641 | } else { | |
2642 | # we are in top (root) tree (dir) | |
2643 | $path = $link_target; | |
2644 | } | |
2645 | ||
2646 | # remove //, /./, and /../ | |
2647 | my @path_parts; | |
2648 | foreach my $part (split('/', $path)) { | |
2649 | # discard '.' and '' | |
2650 | next if (!$part || $part eq '.'); | |
2651 | # handle '..' | |
2652 | if ($part eq '..') { | |
2653 | if (@path_parts) { | |
2654 | pop @path_parts; | |
2655 | } else { | |
2656 | # link leads outside repository (outside top dir) | |
2657 | return; | |
2658 | } | |
2659 | } else { | |
2660 | push @path_parts, $part; | |
2661 | } | |
2662 | } | |
2663 | $path = join('/', @path_parts); | |
2664 | ||
2665 | return $path; | |
2666 | } | |
e33fba4c | 2667 | |
fa702003 JN |
2668 | # print tree entry (row of git_tree), but without encompassing <tr> element |
2669 | sub git_print_tree_entry { | |
2670 | my ($t, $basedir, $hash_base, $have_blame) = @_; | |
2671 | ||
2672 | my %base_key = (); | |
e33fba4c | 2673 | $base_key{'hash_base'} = $hash_base if defined $hash_base; |
fa702003 | 2674 | |
4de741b3 LT |
2675 | # The format of a table row is: mode list link. Where mode is |
2676 | # the mode of the entry, list is the name of the entry, an href, | |
2677 | # and link is the action links of the entry. | |
2678 | ||
fa702003 JN |
2679 | print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n"; |
2680 | if ($t->{'type'} eq "blob") { | |
2681 | print "<td class=\"list\">" . | |
4de741b3 | 2682 | $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'}, |
e7fb022a | 2683 | file_name=>"$basedir$t->{'name'}", %base_key), |
e33fba4c JN |
2684 | -class => "list"}, esc_path($t->{'name'})); |
2685 | if (S_ISLNK(oct $t->{'mode'})) { | |
2686 | my $link_target = git_get_link_target($t->{'hash'}); | |
2687 | if ($link_target) { | |
3bf9d570 JN |
2688 | my $norm_target = normalize_link_target($link_target, $basedir, $hash_base); |
2689 | if (defined $norm_target) { | |
2690 | print " -> " . | |
2691 | $cgi->a({-href => href(action=>"object", hash_base=>$hash_base, | |
2692 | file_name=>$norm_target), | |
2693 | -title => $norm_target}, esc_path($link_target)); | |
2694 | } else { | |
2695 | print " -> " . esc_path($link_target); | |
2696 | } | |
e33fba4c JN |
2697 | } |
2698 | } | |
2699 | print "</td>\n"; | |
4de741b3 | 2700 | print "<td class=\"link\">"; |
4777b014 | 2701 | print $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'}, |
e33fba4c JN |
2702 | file_name=>"$basedir$t->{'name'}", %base_key)}, |
2703 | "blob"); | |
fa702003 | 2704 | if ($have_blame) { |
4777b014 PB |
2705 | print " | " . |
2706 | $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'}, | |
e33fba4c JN |
2707 | file_name=>"$basedir$t->{'name'}", %base_key)}, |
2708 | "blame"); | |
fa702003 JN |
2709 | } |
2710 | if (defined $hash_base) { | |
4777b014 PB |
2711 | print " | " . |
2712 | $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, | |
fa702003 JN |
2713 | hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")}, |
2714 | "history"); | |
2715 | } | |
2716 | print " | " . | |
6f7ea5fb | 2717 | $cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base, |
e7fb022a JN |
2718 | file_name=>"$basedir$t->{'name'}")}, |
2719 | "raw"); | |
4de741b3 | 2720 | print "</td>\n"; |
fa702003 JN |
2721 | |
2722 | } elsif ($t->{'type'} eq "tree") { | |
0fa105e7 LT |
2723 | print "<td class=\"list\">"; |
2724 | print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'}, | |
fa702003 | 2725 | file_name=>"$basedir$t->{'name'}", %base_key)}, |
403d0906 | 2726 | esc_path($t->{'name'})); |
0fa105e7 LT |
2727 | print "</td>\n"; |
2728 | print "<td class=\"link\">"; | |
4777b014 | 2729 | print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'}, |
e33fba4c JN |
2730 | file_name=>"$basedir$t->{'name'}", %base_key)}, |
2731 | "tree"); | |
fa702003 | 2732 | if (defined $hash_base) { |
4777b014 PB |
2733 | print " | " . |
2734 | $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, | |
fa702003 | 2735 | file_name=>"$basedir$t->{'name'}")}, |
01ac1e38 JN |
2736 | "history"); |
2737 | } | |
2738 | print "</td>\n"; | |
2739 | } else { | |
2740 | # unknown object: we can only present history for it | |
2741 | # (this includes 'commit' object, i.e. submodule support) | |
2742 | print "<td class=\"list\">" . | |
2743 | esc_path($t->{'name'}) . | |
2744 | "</td>\n"; | |
2745 | print "<td class=\"link\">"; | |
2746 | if (defined $hash_base) { | |
2747 | print $cgi->a({-href => href(action=>"history", | |
2748 | hash_base=>$hash_base, | |
2749 | file_name=>"$basedir$t->{'name'}")}, | |
fa702003 JN |
2750 | "history"); |
2751 | } | |
2752 | print "</td>\n"; | |
2753 | } | |
2754 | } | |
2755 | ||
717b8311 JN |
2756 | ## ...................................................................... |
2757 | ## functions printing large fragments of HTML | |
2758 | ||
e72c0eaf JN |
2759 | sub fill_from_file_info { |
2760 | my ($diff, @parents) = @_; | |
2761 | ||
2762 | $diff->{'from_file'} = [ ]; | |
2763 | $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef; | |
2764 | for (my $i = 0; $i < $diff->{'nparents'}; $i++) { | |
2765 | if ($diff->{'status'}[$i] eq 'R' || | |
2766 | $diff->{'status'}[$i] eq 'C') { | |
2767 | $diff->{'from_file'}[$i] = | |
2768 | git_get_path_by_hash($parents[$i], $diff->{'from_id'}[$i]); | |
2769 | } | |
2770 | } | |
2771 | ||
2772 | return $diff; | |
2773 | } | |
2774 | ||
2775 | # parameters can be strings, or references to arrays of strings | |
2776 | sub from_ids_eq { | |
2777 | my ($a, $b) = @_; | |
2778 | ||
2779 | if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) { | |
2780 | for (my $i = 0; $i < @$a; ++$i) { | |
2781 | return 0 unless ($a->[$i] eq $b->[$i]); | |
2782 | } | |
2783 | return 1; | |
2784 | } elsif (!ref($a) && !ref($b)) { | |
2785 | return $a eq $b; | |
2786 | } else { | |
2787 | return 0; | |
2788 | } | |
2789 | } | |
2790 | ||
90921740 JN |
2791 | sub is_deleted { |
2792 | my $diffinfo = shift; | |
2793 | ||
2794 | return $diffinfo->{'to_id'} eq ('0' x 40); | |
2795 | } | |
e72c0eaf | 2796 | |
4a4a1a53 | 2797 | sub git_difftree_body { |
ed224dea JN |
2798 | my ($difftree, $hash, @parents) = @_; |
2799 | my ($parent) = $parents[0]; | |
2b2a8c78 | 2800 | my ($have_blame) = gitweb_check_feature('blame'); |
4a4a1a53 JN |
2801 | print "<div class=\"list_head\">\n"; |
2802 | if ($#{$difftree} > 10) { | |
2803 | print(($#{$difftree} + 1) . " files changed:\n"); | |
2804 | } | |
2805 | print "</div>\n"; | |
2806 | ||
ed224dea JN |
2807 | print "<table class=\"" . |
2808 | (@parents > 1 ? "combined " : "") . | |
2809 | "diff_tree\">\n"; | |
47598d7a JN |
2810 | |
2811 | # header only for combined diff in 'commitdiff' view | |
2812 | my $has_header = @parents > 1 && $action eq 'commitdiff'; | |
2813 | if ($has_header) { | |
2814 | # table header | |
2815 | print "<thead><tr>\n" . | |
2816 | "<th></th><th></th>\n"; # filename, patchN link | |
2817 | for (my $i = 0; $i < @parents; $i++) { | |
2818 | my $par = $parents[$i]; | |
2819 | print "<th>" . | |
2820 | $cgi->a({-href => href(action=>"commitdiff", | |
2821 | hash=>$hash, hash_parent=>$par), | |
2822 | -title => 'commitdiff to parent number ' . | |
2823 | ($i+1) . ': ' . substr($par,0,7)}, | |
2824 | $i+1) . | |
2825 | " </th>\n"; | |
2826 | } | |
2827 | print "</tr></thead>\n<tbody>\n"; | |
2828 | } | |
2829 | ||
6dd36acd | 2830 | my $alternate = 1; |
b4657e77 | 2831 | my $patchno = 0; |
4a4a1a53 | 2832 | foreach my $line (@{$difftree}) { |
493e01db JN |
2833 | my $diff; |
2834 | if (ref($line) eq "HASH") { | |
2835 | # pre-parsed (or generated by hand) | |
2836 | $diff = $line; | |
2837 | } else { | |
2838 | $diff = parse_difftree_raw_line($line); | |
2839 | } | |
4a4a1a53 JN |
2840 | |
2841 | if ($alternate) { | |
2842 | print "<tr class=\"dark\">\n"; | |
2843 | } else { | |
2844 | print "<tr class=\"light\">\n"; | |
2845 | } | |
2846 | $alternate ^= 1; | |
2847 | ||
493e01db | 2848 | if (exists $diff->{'nparents'}) { # combined diff |
ed224dea | 2849 | |
493e01db JN |
2850 | fill_from_file_info($diff, @parents) |
2851 | unless exists $diff->{'from_file'}; | |
e72c0eaf | 2852 | |
90921740 | 2853 | if (!is_deleted($diff)) { |
ed224dea JN |
2854 | # file exists in the result (child) commit |
2855 | print "<td>" . | |
493e01db JN |
2856 | $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'}, |
2857 | file_name=>$diff->{'to_file'}, | |
ed224dea | 2858 | hash_base=>$hash), |
493e01db | 2859 | -class => "list"}, esc_path($diff->{'to_file'})) . |
ed224dea JN |
2860 | "</td>\n"; |
2861 | } else { | |
2862 | print "<td>" . | |
493e01db | 2863 | esc_path($diff->{'to_file'}) . |
ed224dea JN |
2864 | "</td>\n"; |
2865 | } | |
2866 | ||
2867 | if ($action eq 'commitdiff') { | |
2868 | # link to patch | |
2869 | $patchno++; | |
2870 | print "<td class=\"link\">" . | |
2871 | $cgi->a({-href => "#patch$patchno"}, "patch") . | |
2872 | " | " . | |
2873 | "</td>\n"; | |
2874 | } | |
2875 | ||
2876 | my $has_history = 0; | |
2877 | my $not_deleted = 0; | |
493e01db | 2878 | for (my $i = 0; $i < $diff->{'nparents'}; $i++) { |
ed224dea | 2879 | my $hash_parent = $parents[$i]; |
493e01db JN |
2880 | my $from_hash = $diff->{'from_id'}[$i]; |
2881 | my $from_path = $diff->{'from_file'}[$i]; | |
2882 | my $status = $diff->{'status'}[$i]; | |
ed224dea JN |
2883 | |
2884 | $has_history ||= ($status ne 'A'); | |
2885 | $not_deleted ||= ($status ne 'D'); | |
2886 | ||
ed224dea JN |
2887 | if ($status eq 'A') { |
2888 | print "<td class=\"link\" align=\"right\"> | </td>\n"; | |
2889 | } elsif ($status eq 'D') { | |
2890 | print "<td class=\"link\">" . | |
2891 | $cgi->a({-href => href(action=>"blob", | |
2892 | hash_base=>$hash, | |
2893 | hash=>$from_hash, | |
2894 | file_name=>$from_path)}, | |
2895 | "blob" . ($i+1)) . | |
2896 | " | </td>\n"; | |
2897 | } else { | |
493e01db | 2898 | if ($diff->{'to_id'} eq $from_hash) { |
ed224dea JN |
2899 | print "<td class=\"link nochange\">"; |
2900 | } else { | |
2901 | print "<td class=\"link\">"; | |
2902 | } | |
2903 | print $cgi->a({-href => href(action=>"blobdiff", | |
493e01db | 2904 | hash=>$diff->{'to_id'}, |
ed224dea JN |
2905 | hash_parent=>$from_hash, |
2906 | hash_base=>$hash, | |
2907 | hash_parent_base=>$hash_parent, | |
493e01db | 2908 | file_name=>$diff->{'to_file'}, |
ed224dea JN |
2909 | file_parent=>$from_path)}, |
2910 | "diff" . ($i+1)) . | |
2911 | " | </td>\n"; | |
2912 | } | |
2913 | } | |
2914 | ||
2915 | print "<td class=\"link\">"; | |
2916 | if ($not_deleted) { | |
2917 | print $cgi->a({-href => href(action=>"blob", | |
493e01db JN |
2918 | hash=>$diff->{'to_id'}, |
2919 | file_name=>$diff->{'to_file'}, | |
ed224dea JN |
2920 | hash_base=>$hash)}, |
2921 | "blob"); | |
2922 | print " | " if ($has_history); | |
2923 | } | |
2924 | if ($has_history) { | |
2925 | print $cgi->a({-href => href(action=>"history", | |
493e01db | 2926 | file_name=>$diff->{'to_file'}, |
ed224dea JN |
2927 | hash_base=>$hash)}, |
2928 | "history"); | |
2929 | } | |
2930 | print "</td>\n"; | |
2931 | ||
2932 | print "</tr>\n"; | |
2933 | next; # instead of 'else' clause, to avoid extra indent | |
2934 | } | |
2935 | # else ordinary diff | |
2936 | ||
e8e41a93 JN |
2937 | my ($to_mode_oct, $to_mode_str, $to_file_type); |
2938 | my ($from_mode_oct, $from_mode_str, $from_file_type); | |
493e01db JN |
2939 | if ($diff->{'to_mode'} ne ('0' x 6)) { |
2940 | $to_mode_oct = oct $diff->{'to_mode'}; | |
e8e41a93 JN |
2941 | if (S_ISREG($to_mode_oct)) { # only for regular file |
2942 | $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits | |
2943 | } | |
493e01db | 2944 | $to_file_type = file_type($diff->{'to_mode'}); |
e8e41a93 | 2945 | } |
493e01db JN |
2946 | if ($diff->{'from_mode'} ne ('0' x 6)) { |
2947 | $from_mode_oct = oct $diff->{'from_mode'}; | |
e8e41a93 JN |
2948 | if (S_ISREG($to_mode_oct)) { # only for regular file |
2949 | $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits | |
4a4a1a53 | 2950 | } |
493e01db | 2951 | $from_file_type = file_type($diff->{'from_mode'}); |
e8e41a93 JN |
2952 | } |
2953 | ||
493e01db | 2954 | if ($diff->{'status'} eq "A") { # created |
e8e41a93 JN |
2955 | my $mode_chng = "<span class=\"file_status new\">[new $to_file_type"; |
2956 | $mode_chng .= " with mode: $to_mode_str" if $to_mode_str; | |
2957 | $mode_chng .= "]</span>"; | |
499faeda | 2958 | print "<td>"; |
493e01db JN |
2959 | print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'}, |
2960 | hash_base=>$hash, file_name=>$diff->{'file'}), | |
2961 | -class => "list"}, esc_path($diff->{'file'})); | |
499faeda LT |
2962 | print "</td>\n"; |
2963 | print "<td>$mode_chng</td>\n"; | |
2964 | print "<td class=\"link\">"; | |
72dbafa1 | 2965 | if ($action eq 'commitdiff') { |
b4657e77 JN |
2966 | # link to patch |
2967 | $patchno++; | |
499faeda | 2968 | print $cgi->a({-href => "#patch$patchno"}, "patch"); |
897d1d2e | 2969 | print " | "; |
b4657e77 | 2970 | } |
493e01db JN |
2971 | print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'}, |
2972 | hash_base=>$hash, file_name=>$diff->{'file'})}, | |
3faa541f | 2973 | "blob"); |
b4657e77 | 2974 | print "</td>\n"; |
4a4a1a53 | 2975 | |
493e01db | 2976 | } elsif ($diff->{'status'} eq "D") { # deleted |
e8e41a93 | 2977 | my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>"; |
499faeda | 2978 | print "<td>"; |
493e01db JN |
2979 | print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'}, |
2980 | hash_base=>$parent, file_name=>$diff->{'file'}), | |
2981 | -class => "list"}, esc_path($diff->{'file'})); | |
499faeda LT |
2982 | print "</td>\n"; |
2983 | print "<td>$mode_chng</td>\n"; | |
2984 | print "<td class=\"link\">"; | |
72dbafa1 | 2985 | if ($action eq 'commitdiff') { |
b4657e77 JN |
2986 | # link to patch |
2987 | $patchno++; | |
499faeda LT |
2988 | print $cgi->a({-href => "#patch$patchno"}, "patch"); |
2989 | print " | "; | |
b4657e77 | 2990 | } |
493e01db JN |
2991 | print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'}, |
2992 | hash_base=>$parent, file_name=>$diff->{'file'})}, | |
897d1d2e | 2993 | "blob") . " | "; |
2b2a8c78 | 2994 | if ($have_blame) { |
897d1d2e | 2995 | print $cgi->a({-href => href(action=>"blame", hash_base=>$parent, |
493e01db | 2996 | file_name=>$diff->{'file'})}, |
897d1d2e | 2997 | "blame") . " | "; |
2b2a8c78 | 2998 | } |
b4657e77 | 2999 | print $cgi->a({-href => href(action=>"history", hash_base=>$parent, |
493e01db | 3000 | file_name=>$diff->{'file'})}, |
e7fb022a | 3001 | "history"); |
499faeda | 3002 | print "</td>\n"; |
4a4a1a53 | 3003 | |
493e01db | 3004 | } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed |
4a4a1a53 | 3005 | my $mode_chnge = ""; |
493e01db | 3006 | if ($diff->{'from_mode'} != $diff->{'to_mode'}) { |
e8e41a93 | 3007 | $mode_chnge = "<span class=\"file_status mode_chnge\">[changed"; |
6e72cf43 | 3008 | if ($from_file_type ne $to_file_type) { |
e8e41a93 | 3009 | $mode_chnge .= " from $from_file_type to $to_file_type"; |
4a4a1a53 | 3010 | } |
e8e41a93 JN |
3011 | if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) { |
3012 | if ($from_mode_str && $to_mode_str) { | |
3013 | $mode_chnge .= " mode: $from_mode_str->$to_mode_str"; | |
3014 | } elsif ($to_mode_str) { | |
3015 | $mode_chnge .= " mode: $to_mode_str"; | |
4a4a1a53 JN |
3016 | } |
3017 | } | |
3018 | $mode_chnge .= "]</span>\n"; | |
3019 | } | |
3020 | print "<td>"; | |
493e01db JN |
3021 | print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'}, |
3022 | hash_base=>$hash, file_name=>$diff->{'file'}), | |
3023 | -class => "list"}, esc_path($diff->{'file'})); | |
499faeda LT |
3024 | print "</td>\n"; |
3025 | print "<td>$mode_chnge</td>\n"; | |
3026 | print "<td class=\"link\">"; | |
241cc599 JN |
3027 | if ($action eq 'commitdiff') { |
3028 | # link to patch | |
3029 | $patchno++; | |
3030 | print $cgi->a({-href => "#patch$patchno"}, "patch") . | |
3031 | " | "; | |
493e01db | 3032 | } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) { |
241cc599 JN |
3033 | # "commit" view and modified file (not onlu mode changed) |
3034 | print $cgi->a({-href => href(action=>"blobdiff", | |
493e01db | 3035 | hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'}, |
241cc599 | 3036 | hash_base=>$hash, hash_parent_base=>$parent, |
493e01db | 3037 | file_name=>$diff->{'file'})}, |
241cc599 JN |
3038 | "diff") . |
3039 | " | "; | |
4a4a1a53 | 3040 | } |
493e01db JN |
3041 | print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'}, |
3042 | hash_base=>$hash, file_name=>$diff->{'file'})}, | |
897d1d2e | 3043 | "blob") . " | "; |
2b2a8c78 | 3044 | if ($have_blame) { |
897d1d2e | 3045 | print $cgi->a({-href => href(action=>"blame", hash_base=>$hash, |
493e01db | 3046 | file_name=>$diff->{'file'})}, |
897d1d2e | 3047 | "blame") . " | "; |
2b2a8c78 | 3048 | } |
eb51ec9c | 3049 | print $cgi->a({-href => href(action=>"history", hash_base=>$hash, |
493e01db | 3050 | file_name=>$diff->{'file'})}, |
e7fb022a | 3051 | "history"); |
4a4a1a53 JN |
3052 | print "</td>\n"; |
3053 | ||
493e01db | 3054 | } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied |
e8e41a93 | 3055 | my %status_name = ('R' => 'moved', 'C' => 'copied'); |
493e01db | 3056 | my $nstatus = $status_name{$diff->{'status'}}; |
4a4a1a53 | 3057 | my $mode_chng = ""; |
493e01db | 3058 | if ($diff->{'from_mode'} != $diff->{'to_mode'}) { |
e8e41a93 JN |
3059 | # mode also for directories, so we cannot use $to_mode_str |
3060 | $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777); | |
4a4a1a53 JN |
3061 | } |
3062 | print "<td>" . | |
e8e41a93 | 3063 | $cgi->a({-href => href(action=>"blob", hash_base=>$hash, |
493e01db JN |
3064 | hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}), |
3065 | -class => "list"}, esc_path($diff->{'to_file'})) . "</td>\n" . | |
e8e41a93 JN |
3066 | "<td><span class=\"file_status $nstatus\">[$nstatus from " . |
3067 | $cgi->a({-href => href(action=>"blob", hash_base=>$parent, | |
493e01db JN |
3068 | hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}), |
3069 | -class => "list"}, esc_path($diff->{'from_file'})) . | |
3070 | " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" . | |
499faeda | 3071 | "<td class=\"link\">"; |
241cc599 JN |
3072 | if ($action eq 'commitdiff') { |
3073 | # link to patch | |
3074 | $patchno++; | |
3075 | print $cgi->a({-href => "#patch$patchno"}, "patch") . | |
3076 | " | "; | |
493e01db | 3077 | } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) { |
241cc599 JN |
3078 | # "commit" view and modified file (not only pure rename or copy) |
3079 | print $cgi->a({-href => href(action=>"blobdiff", | |
493e01db | 3080 | hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'}, |
241cc599 | 3081 | hash_base=>$hash, hash_parent_base=>$parent, |
493e01db | 3082 | file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})}, |
241cc599 JN |
3083 | "diff") . |
3084 | " | "; | |
4a4a1a53 | 3085 | } |
493e01db JN |
3086 | print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'}, |
3087 | hash_base=>$parent, file_name=>$diff->{'to_file'})}, | |
897d1d2e | 3088 | "blob") . " | "; |
2b2a8c78 | 3089 | if ($have_blame) { |
897d1d2e | 3090 | print $cgi->a({-href => href(action=>"blame", hash_base=>$hash, |
493e01db | 3091 | file_name=>$diff->{'to_file'})}, |
897d1d2e | 3092 | "blame") . " | "; |
2b2a8c78 | 3093 | } |
897d1d2e | 3094 | print $cgi->a({-href => href(action=>"history", hash_base=>$hash, |
493e01db | 3095 | file_name=>$diff->{'to_file'})}, |
e7fb022a | 3096 | "history"); |
4a4a1a53 | 3097 | print "</td>\n"; |
e8e41a93 | 3098 | |
4a4a1a53 JN |
3099 | } # we should not encounter Unmerged (U) or Unknown (X) status |
3100 | print "</tr>\n"; | |
3101 | } | |
47598d7a | 3102 | print "</tbody>" if $has_header; |
4a4a1a53 JN |
3103 | print "</table>\n"; |
3104 | } | |
3105 | ||
eee08903 | 3106 | sub git_patchset_body { |
e72c0eaf JN |
3107 | my ($fd, $difftree, $hash, @hash_parents) = @_; |
3108 | my ($hash_parent) = $hash_parents[0]; | |
eee08903 JN |
3109 | |
3110 | my $patch_idx = 0; | |
4280cde9 | 3111 | my $patch_number = 0; |
6d55f055 | 3112 | my $patch_line; |
fe87585e | 3113 | my $diffinfo; |
744d0ac3 | 3114 | my (%from, %to); |
eee08903 JN |
3115 | |
3116 | print "<div class=\"patchset\">\n"; | |
3117 | ||
6d55f055 JN |
3118 | # skip to first patch |
3119 | while ($patch_line = <$fd>) { | |
157e43b4 | 3120 | chomp $patch_line; |
eee08903 | 3121 | |
6d55f055 JN |
3122 | last if ($patch_line =~ m/^diff /); |
3123 | } | |
3124 | ||
3125 | PATCH: | |
3126 | while ($patch_line) { | |
3127 | my @diff_header; | |
62e4f26f | 3128 | my ($from_id, $to_id); |
6d55f055 JN |
3129 | |
3130 | # git diff header | |
3131 | #assert($patch_line =~ m/^diff /) if DEBUG; | |
3132 | #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed | |
4280cde9 | 3133 | $patch_number++; |
6d55f055 JN |
3134 | push @diff_header, $patch_line; |
3135 | ||
3136 | # extended diff header | |
3137 | EXTENDED_HEADER: | |
3138 | while ($patch_line = <$fd>) { | |
3139 | chomp $patch_line; | |
3140 | ||
66399eff | 3141 | last EXTENDED_HEADER if ($patch_line =~ m/^--- |^diff /); |
6d55f055 JN |
3142 | |
3143 | if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) { | |
3144 | $from_id = $1; | |
3145 | $to_id = $2; | |
e72c0eaf JN |
3146 | } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) { |
3147 | $from_id = [ split(',', $1) ]; | |
3148 | $to_id = $2; | |
eee08903 | 3149 | } |
6d55f055 JN |
3150 | |
3151 | push @diff_header, $patch_line; | |
3152 | } | |
6d55f055 JN |
3153 | my $last_patch_line = $patch_line; |
3154 | ||
3155 | # check if current patch belong to current raw line | |
3156 | # and parse raw git-diff line if needed | |
3157 | if (defined $diffinfo && | |
2206537c | 3158 | defined $from_id && defined $to_id && |
e72c0eaf JN |
3159 | from_ids_eq($diffinfo->{'from_id'}, $from_id) && |
3160 | $diffinfo->{'to_id'} eq $to_id) { | |
2206537c | 3161 | # this is continuation of a split patch |
6d55f055 JN |
3162 | print "<div class=\"patch cont\">\n"; |
3163 | } else { | |
3164 | # advance raw git-diff output if needed | |
3165 | $patch_idx++ if defined $diffinfo; | |
eee08903 | 3166 | |
cd030c3a JN |
3167 | # compact combined diff output can have some patches skipped |
3168 | # find which patch (using pathname of result) we are at now | |
3169 | my $to_name; | |
3170 | if ($diff_header[0] =~ m!^diff --cc "?(.*)"?$!) { | |
3171 | $to_name = $1; | |
fe87585e | 3172 | } |
cd030c3a JN |
3173 | |
3174 | do { | |
3175 | # read and prepare patch information | |
3176 | if (ref($difftree->[$patch_idx]) eq "HASH") { | |
3177 | # pre-parsed (or generated by hand) | |
3178 | $diffinfo = $difftree->[$patch_idx]; | |
3179 | } else { | |
3180 | $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]); | |
3181 | } | |
3182 | ||
3183 | # check if current raw line has no patch (it got simplified) | |
3184 | if (defined $to_name && $to_name ne $diffinfo->{'to_file'}) { | |
3185 | print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" . | |
3186 | format_diff_cc_simplified($diffinfo, @hash_parents) . | |
3187 | "</div>\n"; # class="patch" | |
3188 | ||
3189 | $patch_idx++; | |
3190 | $patch_number++; | |
3191 | } | |
3192 | } until (!defined $to_name || $to_name eq $diffinfo->{'to_file'} || | |
3193 | $patch_idx > $#$difftree); | |
711fa742 | 3194 | |
90921740 JN |
3195 | # modifies %from, %to hashes |
3196 | parse_from_to_diffinfo($diffinfo, \%from, \%to, @hash_parents); | |
5f855052 | 3197 | |
6d55f055 JN |
3198 | # this is first patch for raw difftree line with $patch_idx index |
3199 | # we index @$difftree array from 0, but number patches from 1 | |
3200 | print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n"; | |
744d0ac3 | 3201 | } |
eee08903 | 3202 | |
6d55f055 JN |
3203 | # print "git diff" header |
3204 | $patch_line = shift @diff_header; | |
90921740 JN |
3205 | print format_git_diff_header_line($patch_line, $diffinfo, |
3206 | \%from, \%to); | |
6d55f055 JN |
3207 | |
3208 | # print extended diff header | |
3209 | print "<div class=\"diff extended_header\">\n" if (@diff_header > 0); | |
3210 | EXTENDED_HEADER: | |
3211 | foreach $patch_line (@diff_header) { | |
90921740 JN |
3212 | print format_extended_diff_header_line($patch_line, $diffinfo, |
3213 | \%from, \%to); | |
6d55f055 JN |
3214 | } |
3215 | print "</div>\n" if (@diff_header > 0); # class="diff extended_header" | |
3216 | ||
3217 | # from-file/to-file diff header | |
3218 | $patch_line = $last_patch_line; | |
0bdb28c9 JN |
3219 | if (! $patch_line) { |
3220 | print "</div>\n"; # class="patch" | |
3221 | last PATCH; | |
3222 | } | |
66399eff | 3223 | next PATCH if ($patch_line =~ m/^diff /); |
6d55f055 | 3224 | #assert($patch_line =~ m/^---/) if DEBUG; |
90921740 | 3225 | #assert($patch_line eq $last_patch_line) if DEBUG; |
744d0ac3 | 3226 | |
6d55f055 | 3227 | $patch_line = <$fd>; |
6d55f055 | 3228 | chomp $patch_line; |
90921740 | 3229 | #assert($patch_line =~ m/^\+\+\+/) if DEBUG; |
e4e4f825 | 3230 | |
90921740 | 3231 | print format_diff_from_to_header($last_patch_line, $patch_line, |
91af4ce4 JN |
3232 | $diffinfo, \%from, \%to, |
3233 | @hash_parents); | |
e4e4f825 | 3234 | |
6d55f055 JN |
3235 | # the patch itself |
3236 | LINE: | |
3237 | while ($patch_line = <$fd>) { | |
3238 | chomp $patch_line; | |
e4e4f825 | 3239 | |
6d55f055 | 3240 | next PATCH if ($patch_line =~ m/^diff /); |
e4e4f825 | 3241 | |
59e3b14e | 3242 | print format_diff_line($patch_line, \%from, \%to); |
eee08903 | 3243 | } |
eee08903 | 3244 | |
6d55f055 JN |
3245 | } continue { |
3246 | print "</div>\n"; # class="patch" | |
eee08903 | 3247 | } |
d26c4264 | 3248 | |
cd030c3a JN |
3249 | # for compact combined (--cc) format, with chunk and patch simpliciaction |
3250 | # patchset might be empty, but there might be unprocessed raw lines | |
3251 | for ($patch_idx++ if $patch_number > 0; | |
3252 | $patch_idx < @$difftree; | |
3253 | $patch_idx++) { | |
3254 | # read and prepare patch information | |
3255 | if (ref($difftree->[$patch_idx]) eq "HASH") { | |
3256 | # pre-parsed (or generated by hand) | |
3257 | $diffinfo = $difftree->[$patch_idx]; | |
3258 | } else { | |
3259 | $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]); | |
3260 | } | |
3261 | ||
3262 | # generate anchor for "patch" links in difftree / whatchanged part | |
3263 | print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" . | |
3264 | format_diff_cc_simplified($diffinfo, @hash_parents) . | |
3265 | "</div>\n"; # class="patch" | |
3266 | ||
3267 | $patch_number++; | |
3268 | } | |
3269 | ||
d26c4264 JN |
3270 | if ($patch_number == 0) { |
3271 | if (@hash_parents > 1) { | |
3272 | print "<div class=\"diff nodifferences\">Trivial merge</div>\n"; | |
3273 | } else { | |
3274 | print "<div class=\"diff nodifferences\">No differences found</div>\n"; | |
3275 | } | |
3276 | } | |
eee08903 JN |
3277 | |
3278 | print "</div>\n"; # class="patchset" | |
3279 | } | |
3280 | ||
3281 | # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | |
3282 | ||
e30496df PB |
3283 | sub git_project_list_body { |
3284 | my ($projlist, $order, $from, $to, $extra, $no_header) = @_; | |
3285 | ||
5dd5ed09 | 3286 | my ($check_forks) = gitweb_check_feature('forks'); |
e30496df PB |
3287 | |
3288 | my @projects; | |
3289 | foreach my $pr (@$projlist) { | |
3290 | my (@aa) = git_get_last_activity($pr->{'path'}); | |
3291 | unless (@aa) { | |
3292 | next; | |
3293 | } | |
3294 | ($pr->{'age'}, $pr->{'age_string'}) = @aa; | |
3295 | if (!defined $pr->{'descr'}) { | |
3296 | my $descr = git_get_project_description($pr->{'path'}) || ""; | |
00f429af | 3297 | $pr->{'descr_long'} = to_utf8($descr); |
55feb120 | 3298 | $pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5); |
e30496df PB |
3299 | } |
3300 | if (!defined $pr->{'owner'}) { | |
76e4f5d0 | 3301 | $pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || ""; |
e30496df PB |
3302 | } |
3303 | if ($check_forks) { | |
3304 | my $pname = $pr->{'path'}; | |
83ee94c1 JH |
3305 | if (($pname =~ s/\.git$//) && |
3306 | ($pname !~ /\/$/) && | |
3307 | (-d "$projectroot/$pname")) { | |
3308 | $pr->{'forks'} = "-d $projectroot/$pname"; | |
3309 | } | |
3310 | else { | |
3311 | $pr->{'forks'} = 0; | |
3312 | } | |
e30496df PB |
3313 | } |
3314 | push @projects, $pr; | |
3315 | } | |
3316 | ||
b06dcf8c | 3317 | $order ||= $default_projects_order; |
e30496df PB |
3318 | $from = 0 unless defined $from; |
3319 | $to = $#projects if (!defined $to || $#projects < $to); | |
3320 | ||
3321 | print "<table class=\"project_list\">\n"; | |
3322 | unless ($no_header) { | |
3323 | print "<tr>\n"; | |
3324 | if ($check_forks) { | |
3325 | print "<th></th>\n"; | |
3326 | } | |
3327 | if ($order eq "project") { | |
3328 | @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects; | |
3329 | print "<th>Project</th>\n"; | |
3330 | } else { | |
3331 | print "<th>" . | |
3332 | $cgi->a({-href => href(project=>undef, order=>'project'), | |
e88ce8a4 | 3333 | -class => "header"}, "Project") . |
e30496df PB |
3334 | "</th>\n"; |
3335 | } | |
3336 | if ($order eq "descr") { | |
3337 | @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects; | |
3338 | print "<th>Description</th>\n"; | |
3339 | } else { | |
3340 | print "<th>" . | |
3341 | $cgi->a({-href => href(project=>undef, order=>'descr'), | |
e88ce8a4 | 3342 | -class => "header"}, "Description") . |
e30496df PB |
3343 | "</th>\n"; |
3344 | } | |
3345 | if ($order eq "owner") { | |
3346 | @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects; | |
3347 | print "<th>Owner</th>\n"; | |
3348 | } else { | |
3349 | print "<th>" . | |
3350 | $cgi->a({-href => href(project=>undef, order=>'owner'), | |
e88ce8a4 | 3351 | -class => "header"}, "Owner") . |
e30496df PB |
3352 | "</th>\n"; |
3353 | } | |
3354 | if ($order eq "age") { | |
3355 | @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects; | |
3356 | print "<th>Last Change</th>\n"; | |
3357 | } else { | |
3358 | print "<th>" . | |
3359 | $cgi->a({-href => href(project=>undef, order=>'age'), | |
e88ce8a4 | 3360 | -class => "header"}, "Last Change") . |
e30496df PB |
3361 | "</th>\n"; |
3362 | } | |
3363 | print "<th></th>\n" . | |
3364 | "</tr>\n"; | |
3365 | } | |
3366 | my $alternate = 1; | |
3367 | for (my $i = $from; $i <= $to; $i++) { | |
3368 | my $pr = $projects[$i]; | |
3369 | if ($alternate) { | |
3370 | print "<tr class=\"dark\">\n"; | |
3371 | } else { | |
3372 | print "<tr class=\"light\">\n"; | |
3373 | } | |
3374 | $alternate ^= 1; | |
3375 | if ($check_forks) { | |
3376 | print "<td>"; | |
3377 | if ($pr->{'forks'}) { | |
83ee94c1 | 3378 | print "<!-- $pr->{'forks'} -->\n"; |
e30496df PB |
3379 | print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "+"); |
3380 | } | |
3381 | print "</td>\n"; | |
3382 | } | |
3383 | print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"), | |
3384 | -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" . | |
e88ce8a4 JN |
3385 | "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"), |
3386 | -class => "list", -title => $pr->{'descr_long'}}, | |
3387 | esc_html($pr->{'descr'})) . "</td>\n" . | |
ce312aff | 3388 | "<td><i>" . esc_html(chop_str($pr->{'owner'}, 15)) . "</i></td>\n"; |
e30496df | 3389 | print "<td class=\"". age_class($pr->{'age'}) . "\">" . |
785cdea9 | 3390 | (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" . |
e30496df PB |
3391 | "<td class=\"link\">" . |
3392 | $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " . | |
faa1bbfd | 3393 | $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " . |
e30496df PB |
3394 | $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " . |
3395 | $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") . | |
3396 | ($pr->{'forks'} ? " | " . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "forks") : '') . | |
3397 | "</td>\n" . | |
3398 | "</tr>\n"; | |
3399 | } | |
3400 | if (defined $extra) { | |
3401 | print "<tr>\n"; | |
3402 | if ($check_forks) { | |
3403 | print "<td></td>\n"; | |
3404 | } | |
3405 | print "<td colspan=\"5\">$extra</td>\n" . | |
3406 | "</tr>\n"; | |
3407 | } | |
3408 | print "</table>\n"; | |
3409 | } | |
3410 | ||
9f5dcb81 JN |
3411 | sub git_shortlog_body { |
3412 | # uses global variable $project | |
190d7fdc | 3413 | my ($commitlist, $from, $to, $refs, $extra) = @_; |
ddb8d900 | 3414 | |
9f5dcb81 | 3415 | $from = 0 unless defined $from; |
190d7fdc | 3416 | $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to); |
9f5dcb81 JN |
3417 | |
3418 | print "<table class=\"shortlog\" cellspacing=\"0\">\n"; | |
6dd36acd | 3419 | my $alternate = 1; |
9f5dcb81 | 3420 | for (my $i = $from; $i <= $to; $i++) { |
190d7fdc RF |
3421 | my %co = %{$commitlist->[$i]}; |
3422 | my $commit = $co{'id'}; | |
847e01fb | 3423 | my $ref = format_ref_marker($refs, $commit); |
9f5dcb81 JN |
3424 | if ($alternate) { |
3425 | print "<tr class=\"dark\">\n"; | |
3426 | } else { | |
3427 | print "<tr class=\"light\">\n"; | |
3428 | } | |
3429 | $alternate ^= 1; | |
3430 | # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" . | |
3431 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . | |
3432 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" . | |
3433 | "<td>"; | |
952c65fc JN |
3434 | print format_subject_html($co{'title'}, $co{'title_short'}, |
3435 | href(action=>"commit", hash=>$commit), $ref); | |
9f5dcb81 JN |
3436 | print "</td>\n" . |
3437 | "<td class=\"link\">" . | |
4777b014 | 3438 | $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " . |
35749ae5 | 3439 | $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " . |
55ff35cb | 3440 | $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree"); |
a3c8ab30 MM |
3441 | my $snapshot_links = format_snapshot_links($commit); |
3442 | if (defined $snapshot_links) { | |
3443 | print " | " . $snapshot_links; | |
55ff35cb | 3444 | } |
cb9c6e5b | 3445 | print "</td>\n" . |
9f5dcb81 JN |
3446 | "</tr>\n"; |
3447 | } | |
3448 | if (defined $extra) { | |
3449 | print "<tr>\n" . | |
3450 | "<td colspan=\"4\">$extra</td>\n" . | |
3451 | "</tr>\n"; | |
3452 | } | |
3453 | print "</table>\n"; | |
3454 | } | |
3455 | ||
581860e1 JN |
3456 | sub git_history_body { |
3457 | # Warning: assumes constant type (blob or tree) during history | |
a8b983bf | 3458 | my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_; |
8be68352 JN |
3459 | |
3460 | $from = 0 unless defined $from; | |
a8b983bf | 3461 | $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist}); |
581860e1 JN |
3462 | |
3463 | print "<table class=\"history\" cellspacing=\"0\">\n"; | |
6dd36acd | 3464 | my $alternate = 1; |
8be68352 | 3465 | for (my $i = $from; $i <= $to; $i++) { |
a8b983bf | 3466 | my %co = %{$commitlist->[$i]}; |
581860e1 JN |
3467 | if (!%co) { |
3468 | next; | |
3469 | } | |
a8b983bf | 3470 | my $commit = $co{'id'}; |
581860e1 JN |
3471 | |
3472 | my $ref = format_ref_marker($refs, $commit); | |
3473 | ||
3474 | if ($alternate) { | |
3475 | print "<tr class=\"dark\">\n"; | |
3476 | } else { | |
3477 | print "<tr class=\"light\">\n"; | |
3478 | } | |
3479 | $alternate ^= 1; | |
3480 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . | |
3481 | # shortlog uses chop_str($co{'author_name'}, 10) | |
3482 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" . | |
3483 | "<td>"; | |
3484 | # originally git_history used chop_str($co{'title'}, 50) | |
952c65fc JN |
3485 | print format_subject_html($co{'title'}, $co{'title_short'}, |
3486 | href(action=>"commit", hash=>$commit), $ref); | |
581860e1 JN |
3487 | print "</td>\n" . |
3488 | "<td class=\"link\">" . | |
6d81c5a2 LT |
3489 | $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype) . " | " . |
3490 | $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff"); | |
581860e1 JN |
3491 | |
3492 | if ($ftype eq 'blob') { | |
3493 | my $blob_current = git_get_hash_by_path($hash_base, $file_name); | |
3494 | my $blob_parent = git_get_hash_by_path($commit, $file_name); | |
3495 | if (defined $blob_current && defined $blob_parent && | |
3496 | $blob_current ne $blob_parent) { | |
3497 | print " | " . | |
420e92f2 JN |
3498 | $cgi->a({-href => href(action=>"blobdiff", |
3499 | hash=>$blob_current, hash_parent=>$blob_parent, | |
3500 | hash_base=>$hash_base, hash_parent_base=>$commit, | |
3501 | file_name=>$file_name)}, | |
581860e1 JN |
3502 | "diff to current"); |
3503 | } | |
3504 | } | |
3505 | print "</td>\n" . | |
3506 | "</tr>\n"; | |
3507 | } | |
3508 | if (defined $extra) { | |
3509 | print "<tr>\n" . | |
3510 | "<td colspan=\"4\">$extra</td>\n" . | |
3511 | "</tr>\n"; | |
3512 | } | |
3513 | print "</table>\n"; | |
3514 | } | |
3515 | ||
717b8311 JN |
3516 | sub git_tags_body { |
3517 | # uses global variable $project | |
3518 | my ($taglist, $from, $to, $extra) = @_; | |
3519 | $from = 0 unless defined $from; | |
3520 | $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to); | |
3521 | ||
3522 | print "<table class=\"tags\" cellspacing=\"0\">\n"; | |
6dd36acd | 3523 | my $alternate = 1; |
717b8311 JN |
3524 | for (my $i = $from; $i <= $to; $i++) { |
3525 | my $entry = $taglist->[$i]; | |
3526 | my %tag = %$entry; | |
cd146408 | 3527 | my $comment = $tag{'subject'}; |
717b8311 JN |
3528 | my $comment_short; |
3529 | if (defined $comment) { | |
3530 | $comment_short = chop_str($comment, 30, 5); | |
3531 | } | |
3532 | if ($alternate) { | |
3533 | print "<tr class=\"dark\">\n"; | |
3534 | } else { | |
3535 | print "<tr class=\"light\">\n"; | |
3536 | } | |
3537 | $alternate ^= 1; | |
27dd1a83 JN |
3538 | if (defined $tag{'age'}) { |
3539 | print "<td><i>$tag{'age'}</i></td>\n"; | |
3540 | } else { | |
3541 | print "<td></td>\n"; | |
3542 | } | |
3543 | print "<td>" . | |
1c2a4f5a | 3544 | $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}), |
63e4220b | 3545 | -class => "list name"}, esc_html($tag{'name'})) . |
717b8311 JN |
3546 | "</td>\n" . |
3547 | "<td>"; | |
3548 | if (defined $comment) { | |
952c65fc JN |
3549 | print format_subject_html($comment, $comment_short, |
3550 | href(action=>"tag", hash=>$tag{'id'})); | |
717b8311 JN |
3551 | } |
3552 | print "</td>\n" . | |
3553 | "<td class=\"selflink\">"; | |
3554 | if ($tag{'type'} eq "tag") { | |
1c2a4f5a | 3555 | print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag"); |
717b8311 JN |
3556 | } else { |
3557 | print " "; | |
3558 | } | |
3559 | print "</td>\n" . | |
3560 | "<td class=\"link\">" . " | " . | |
1c2a4f5a | 3561 | $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'}); |
717b8311 | 3562 | if ($tag{'reftype'} eq "commit") { |
1c2a4f5a | 3563 | print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . |
cd146408 | 3564 | " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log"); |
717b8311 | 3565 | } elsif ($tag{'reftype'} eq "blob") { |
1c2a4f5a | 3566 | print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw"); |
717b8311 JN |
3567 | } |
3568 | print "</td>\n" . | |
3569 | "</tr>"; | |
3570 | } | |
3571 | if (defined $extra) { | |
3572 | print "<tr>\n" . | |
3573 | "<td colspan=\"5\">$extra</td>\n" . | |
3574 | "</tr>\n"; | |
3575 | } | |
3576 | print "</table>\n"; | |
3577 | } | |
3578 | ||
3579 | sub git_heads_body { | |
3580 | # uses global variable $project | |
120ddde2 | 3581 | my ($headlist, $head, $from, $to, $extra) = @_; |
717b8311 | 3582 | $from = 0 unless defined $from; |
120ddde2 | 3583 | $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to); |
717b8311 JN |
3584 | |
3585 | print "<table class=\"heads\" cellspacing=\"0\">\n"; | |
6dd36acd | 3586 | my $alternate = 1; |
717b8311 | 3587 | for (my $i = $from; $i <= $to; $i++) { |
120ddde2 | 3588 | my $entry = $headlist->[$i]; |
cd146408 JN |
3589 | my %ref = %$entry; |
3590 | my $curr = $ref{'id'} eq $head; | |
717b8311 JN |
3591 | if ($alternate) { |
3592 | print "<tr class=\"dark\">\n"; | |
3593 | } else { | |
3594 | print "<tr class=\"light\">\n"; | |
3595 | } | |
3596 | $alternate ^= 1; | |
cd146408 JN |
3597 | print "<td><i>$ref{'age'}</i></td>\n" . |
3598 | ($curr ? "<td class=\"current_head\">" : "<td>") . | |
3599 | $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'name'}), | |
3600 | -class => "list name"},esc_html($ref{'name'})) . | |
717b8311 JN |
3601 | "</td>\n" . |
3602 | "<td class=\"link\">" . | |
cd146408 JN |
3603 | $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'name'})}, "shortlog") . " | " . |
3604 | $cgi->a({-href => href(action=>"log", hash=>$ref{'name'})}, "log") . " | " . | |
3605 | $cgi->a({-href => href(action=>"tree", hash=>$ref{'name'}, hash_base=>$ref{'name'})}, "tree") . | |
717b8311 JN |
3606 | "</td>\n" . |
3607 | "</tr>"; | |
3608 | } | |
3609 | if (defined $extra) { | |
3610 | print "<tr>\n" . | |
3611 | "<td colspan=\"3\">$extra</td>\n" . | |
3612 | "</tr>\n"; | |
3613 | } | |
3614 | print "</table>\n"; | |
3615 | } | |
3616 | ||
8dbc0fce | 3617 | sub git_search_grep_body { |
5ad66088 | 3618 | my ($commitlist, $from, $to, $extra) = @_; |
8dbc0fce | 3619 | $from = 0 unless defined $from; |
5ad66088 | 3620 | $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to); |
8dbc0fce RF |
3621 | |
3622 | print "<table class=\"grep\" cellspacing=\"0\">\n"; | |
3623 | my $alternate = 1; | |
3624 | for (my $i = $from; $i <= $to; $i++) { | |
5ad66088 | 3625 | my %co = %{$commitlist->[$i]}; |
8dbc0fce RF |
3626 | if (!%co) { |
3627 | next; | |
3628 | } | |
5ad66088 | 3629 | my $commit = $co{'id'}; |
8dbc0fce RF |
3630 | if ($alternate) { |
3631 | print "<tr class=\"dark\">\n"; | |
3632 | } else { | |
3633 | print "<tr class=\"light\">\n"; | |
3634 | } | |
3635 | $alternate ^= 1; | |
3636 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . | |
3637 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" . | |
3638 | "<td>" . | |
3639 | $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"}, | |
3640 | esc_html(chop_str($co{'title'}, 50)) . "<br/>"); | |
3641 | my $comment = $co{'comment'}; | |
3642 | foreach my $line (@$comment) { | |
7e431ef9 | 3643 | if ($line =~ m/^(.*)($search_regexp)(.*)$/i) { |
8dbc0fce RF |
3644 | my $lead = esc_html($1) || ""; |
3645 | $lead = chop_str($lead, 30, 10); | |
3646 | my $match = esc_html($2) || ""; | |
3647 | my $trail = esc_html($3) || ""; | |
3648 | $trail = chop_str($trail, 30, 10); | |
3649 | my $text = "$lead<span class=\"match\">$match</span>$trail"; | |
3650 | print chop_str($text, 80, 5) . "<br/>\n"; | |
3651 | } | |
3652 | } | |
3653 | print "</td>\n" . | |
3654 | "<td class=\"link\">" . | |
3655 | $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") . | |
3656 | " | " . | |
3657 | $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree"); | |
3658 | print "</td>\n" . | |
3659 | "</tr>\n"; | |
3660 | } | |
3661 | if (defined $extra) { | |
3662 | print "<tr>\n" . | |
3663 | "<td colspan=\"3\">$extra</td>\n" . | |
3664 | "</tr>\n"; | |
3665 | } | |
3666 | print "</table>\n"; | |
3667 | } | |
3668 | ||
717b8311 JN |
3669 | ## ====================================================================== |
3670 | ## ====================================================================== | |
3671 | ## actions | |
3672 | ||
717b8311 | 3673 | sub git_project_list { |
6326b60c | 3674 | my $order = $cgi->param('o'); |
b06dcf8c | 3675 | if (defined $order && $order !~ m/none|project|descr|owner|age/) { |
e2860ead | 3676 | die_error(undef, "Unknown order parameter"); |
6326b60c JN |
3677 | } |
3678 | ||
847e01fb | 3679 | my @list = git_get_projects_list(); |
717b8311 | 3680 | if (!@list) { |
cac4bd94 | 3681 | die_error(undef, "No projects found"); |
717b8311 | 3682 | } |
6326b60c | 3683 | |
717b8311 JN |
3684 | git_header_html(); |
3685 | if (-f $home_text) { | |
3686 | print "<div class=\"index_include\">\n"; | |
3687 | open (my $fd, $home_text); | |
3688 | print <$fd>; | |
3689 | close $fd; | |
3690 | print "</div>\n"; | |
9f5dcb81 | 3691 | } |
e30496df PB |
3692 | git_project_list_body(\@list, $order); |
3693 | git_footer_html(); | |
3694 | } | |
3695 | ||
3696 | sub git_forks { | |
3697 | my $order = $cgi->param('o'); | |
b06dcf8c | 3698 | if (defined $order && $order !~ m/none|project|descr|owner|age/) { |
e30496df | 3699 | die_error(undef, "Unknown order parameter"); |
717b8311 | 3700 | } |
e30496df PB |
3701 | |
3702 | my @list = git_get_projects_list($project); | |
3703 | if (!@list) { | |
3704 | die_error(undef, "No forks found"); | |
9f5dcb81 | 3705 | } |
e30496df PB |
3706 | |
3707 | git_header_html(); | |
3708 | git_print_page_nav('',''); | |
3709 | git_print_header_div('summary', "$project forks"); | |
3710 | git_project_list_body(\@list, $order); | |
717b8311 | 3711 | git_footer_html(); |
9f5dcb81 JN |
3712 | } |
3713 | ||
fc2b2be0 | 3714 | sub git_project_index { |
e30496df | 3715 | my @projects = git_get_projects_list($project); |
fc2b2be0 JN |
3716 | |
3717 | print $cgi->header( | |
3718 | -type => 'text/plain', | |
3719 | -charset => 'utf-8', | |
ab41dfbf | 3720 | -content_disposition => 'inline; filename="index.aux"'); |
fc2b2be0 JN |
3721 | |
3722 | foreach my $pr (@projects) { | |
3723 | if (!exists $pr->{'owner'}) { | |
76e4f5d0 | 3724 | $pr->{'owner'} = git_get_project_owner("$pr->{'path'}"); |
fc2b2be0 JN |
3725 | } |
3726 | ||
3727 | my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'}); | |
3728 | # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' ' | |
3729 | $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg; | |
3730 | $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg; | |
3731 | $path =~ s/ /\+/g; | |
3732 | $owner =~ s/ /\+/g; | |
3733 | ||
3734 | print "$path $owner\n"; | |
3735 | } | |
3736 | } | |
3737 | ||
ede5e100 | 3738 | sub git_summary { |
847e01fb | 3739 | my $descr = git_get_project_description($project) || "none"; |
a979d128 | 3740 | my %co = parse_commit("HEAD"); |
785cdea9 | 3741 | my %cd = %co ? parse_date($co{'committer_epoch'}, $co{'committer_tz'}) : (); |
a979d128 | 3742 | my $head = $co{'id'}; |
ede5e100 | 3743 | |
1e0cf030 | 3744 | my $owner = git_get_project_owner($project); |
ede5e100 | 3745 | |
cd146408 | 3746 | my $refs = git_get_references(); |
313ce8ce RF |
3747 | # These get_*_list functions return one more to allow us to see if |
3748 | # there are more ... | |
3749 | my @taglist = git_get_tags_list(16); | |
3750 | my @headlist = git_get_heads_list(16); | |
e30496df | 3751 | my @forklist; |
5dd5ed09 JH |
3752 | my ($check_forks) = gitweb_check_feature('forks'); |
3753 | ||
3754 | if ($check_forks) { | |
e30496df PB |
3755 | @forklist = git_get_projects_list($project); |
3756 | } | |
120ddde2 | 3757 | |
ede5e100 | 3758 | git_header_html(); |
847e01fb | 3759 | git_print_page_nav('summary','', $head); |
9f5dcb81 | 3760 | |
19806691 | 3761 | print "<div class=\"title\"> </div>\n"; |
bddec01d | 3762 | print "<table cellspacing=\"0\">\n" . |
40c13813 | 3763 | "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" . |
ce312aff | 3764 | "<tr><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n"; |
785cdea9 JN |
3765 | if (defined $cd{'rfc2822'}) { |
3766 | print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n"; | |
3767 | } | |
3768 | ||
e79ca7cc JN |
3769 | # use per project git URL list in $projectroot/$project/cloneurl |
3770 | # or make project git URL from git base URL and project name | |
19a8721e | 3771 | my $url_tag = "URL"; |
e79ca7cc JN |
3772 | my @url_list = git_get_project_url_list($project); |
3773 | @url_list = map { "$_/$project" } @git_base_url_list unless @url_list; | |
3774 | foreach my $git_url (@url_list) { | |
3775 | next unless $git_url; | |
3776 | print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n"; | |
19a8721e JN |
3777 | $url_tag = ""; |
3778 | } | |
3779 | print "</table>\n"; | |
9f5dcb81 | 3780 | |
447ef09a PB |
3781 | if (-s "$projectroot/$project/README.html") { |
3782 | if (open my $fd, "$projectroot/$project/README.html") { | |
3783 | print "<div class=\"title\">readme</div>\n"; | |
3784 | print $_ while (<$fd>); | |
3785 | close $fd; | |
3786 | } | |
3787 | } | |
3788 | ||
313ce8ce RF |
3789 | # we need to request one more than 16 (0..15) to check if |
3790 | # those 16 are all | |
785cdea9 JN |
3791 | my @commitlist = $head ? parse_commits($head, 17) : (); |
3792 | if (@commitlist) { | |
3793 | git_print_header_div('shortlog'); | |
3794 | git_shortlog_body(\@commitlist, 0, 15, $refs, | |
3795 | $#commitlist <= 15 ? undef : | |
3796 | $cgi->a({-href => href(action=>"shortlog")}, "...")); | |
3797 | } | |
ede5e100 | 3798 | |
120ddde2 | 3799 | if (@taglist) { |
847e01fb | 3800 | git_print_header_div('tags'); |
120ddde2 | 3801 | git_tags_body(\@taglist, 0, 15, |
313ce8ce | 3802 | $#taglist <= 15 ? undef : |
1c2a4f5a | 3803 | $cgi->a({-href => href(action=>"tags")}, "...")); |
ede5e100 | 3804 | } |
0db37973 | 3805 | |
120ddde2 | 3806 | if (@headlist) { |
847e01fb | 3807 | git_print_header_div('heads'); |
120ddde2 | 3808 | git_heads_body(\@headlist, $head, 0, 15, |
313ce8ce | 3809 | $#headlist <= 15 ? undef : |
1c2a4f5a | 3810 | $cgi->a({-href => href(action=>"heads")}, "...")); |
0db37973 | 3811 | } |
9f5dcb81 | 3812 | |
e30496df PB |
3813 | if (@forklist) { |
3814 | git_print_header_div('forks'); | |
3815 | git_project_list_body(\@forklist, undef, 0, 15, | |
aaca9675 | 3816 | $#forklist <= 15 ? undef : |
e30496df | 3817 | $cgi->a({-href => href(action=>"forks")}, "..."), |
a23f0a73 | 3818 | 'noheader'); |
e30496df PB |
3819 | } |
3820 | ||
ede5e100 KS |
3821 | git_footer_html(); |
3822 | } | |
3823 | ||
d8a20ba9 | 3824 | sub git_tag { |
847e01fb | 3825 | my $head = git_get_head_hash($project); |
d8a20ba9 | 3826 | git_header_html(); |
847e01fb JN |
3827 | git_print_page_nav('','', $head,undef,$head); |
3828 | my %tag = parse_tag($hash); | |
198a2a8a JN |
3829 | |
3830 | if (! %tag) { | |
3831 | die_error(undef, "Unknown tag object"); | |
3832 | } | |
3833 | ||
847e01fb | 3834 | git_print_header_div('commit', esc_html($tag{'name'}), $hash); |
d8a20ba9 KS |
3835 | print "<div class=\"title_text\">\n" . |
3836 | "<table cellspacing=\"0\">\n" . | |
e4669df9 KS |
3837 | "<tr>\n" . |
3838 | "<td>object</td>\n" . | |
952c65fc JN |
3839 | "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})}, |
3840 | $tag{'object'}) . "</td>\n" . | |
3841 | "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})}, | |
3842 | $tag{'type'}) . "</td>\n" . | |
e4669df9 | 3843 | "</tr>\n"; |
d8a20ba9 | 3844 | if (defined($tag{'author'})) { |
847e01fb | 3845 | my %ad = parse_date($tag{'epoch'}, $tag{'tz'}); |
40c13813 | 3846 | print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n"; |
952c65fc JN |
3847 | print "<tr><td></td><td>" . $ad{'rfc2822'} . |
3848 | sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . | |
3849 | "</td></tr>\n"; | |
d8a20ba9 KS |
3850 | } |
3851 | print "</table>\n\n" . | |
3852 | "</div>\n"; | |
3853 | print "<div class=\"page_body\">"; | |
3854 | my $comment = $tag{'comment'}; | |
3855 | foreach my $line (@$comment) { | |
7002243f | 3856 | chomp $line; |
793c400c | 3857 | print esc_html($line, -nbsp=>1) . "<br/>\n"; |
d8a20ba9 KS |
3858 | } |
3859 | print "</div>\n"; | |
3860 | git_footer_html(); | |
3861 | } | |
3862 | ||
1f2857ea LT |
3863 | sub git_blame2 { |
3864 | my $fd; | |
3865 | my $ftype; | |
ddb8d900 | 3866 | |
1d3fc68a AK |
3867 | my ($have_blame) = gitweb_check_feature('blame'); |
3868 | if (!$have_blame) { | |
ddb8d900 AK |
3869 | die_error('403 Permission denied', "Permission denied"); |
3870 | } | |
1f2857ea | 3871 | die_error('404 Not Found', "File name not defined") if (!$file_name); |
847e01fb | 3872 | $hash_base ||= git_get_head_hash($project); |
cac4bd94 | 3873 | die_error(undef, "Couldn't find base commit") unless ($hash_base); |
847e01fb | 3874 | my %co = parse_commit($hash_base) |
1f2857ea LT |
3875 | or die_error(undef, "Reading commit failed"); |
3876 | if (!defined $hash) { | |
3877 | $hash = git_get_hash_by_path($hash_base, $file_name, "blob") | |
3878 | or die_error(undef, "Error looking up file"); | |
3879 | } | |
3880 | $ftype = git_get_type($hash); | |
3881 | if ($ftype !~ "blob") { | |
f73bbb2d | 3882 | die_error('400 Bad Request', "Object is not a blob"); |
1f2857ea | 3883 | } |
48fd688a | 3884 | open ($fd, "-|", git_cmd(), "blame", '-p', '--', |
eeef88cd | 3885 | $file_name, $hash_base) |
cac4bd94 | 3886 | or die_error(undef, "Open git-blame failed"); |
1f2857ea | 3887 | git_header_html(); |
0d83ddc4 | 3888 | my $formats_nav = |
952c65fc JN |
3889 | $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, |
3890 | "blob") . | |
3891 | " | " . | |
cae1862a PB |
3892 | $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, |
3893 | "history") . | |
3894 | " | " . | |
952c65fc | 3895 | $cgi->a({-href => href(action=>"blame", file_name=>$file_name)}, |
f35274da | 3896 | "HEAD"); |
847e01fb JN |
3897 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); |
3898 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
59fb1c94 | 3899 | git_print_page_path($file_name, $ftype, $hash_base); |
82f930de | 3900 | my @rev_color = (qw(light2 dark2)); |
cc1bf97e LT |
3901 | my $num_colors = scalar(@rev_color); |
3902 | my $current_color = 0; | |
3903 | my $last_rev; | |
59b9f61a JN |
3904 | print <<HTML; |
3905 | <div class="page_body"> | |
3906 | <table class="blame"> | |
3907 | <tr><th>Commit</th><th>Line</th><th>Data</th></tr> | |
3908 | HTML | |
eeef88cd JH |
3909 | my %metainfo = (); |
3910 | while (1) { | |
3911 | $_ = <$fd>; | |
3912 | last unless defined $_; | |
d15c55aa | 3913 | my ($full_rev, $orig_lineno, $lineno, $group_size) = |
eeef88cd JH |
3914 | /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/; |
3915 | if (!exists $metainfo{$full_rev}) { | |
3916 | $metainfo{$full_rev} = {}; | |
3917 | } | |
3918 | my $meta = $metainfo{$full_rev}; | |
3919 | while (<$fd>) { | |
3920 | last if (s/^\t//); | |
3921 | if (/^(\S+) (.*)$/) { | |
3922 | $meta->{$1} = $2; | |
3923 | } | |
3924 | } | |
3925 | my $data = $_; | |
7002243f | 3926 | chomp $data; |
1f2857ea | 3927 | my $rev = substr($full_rev, 0, 8); |
eeef88cd JH |
3928 | my $author = $meta->{'author'}; |
3929 | my %date = parse_date($meta->{'author-time'}, | |
a23f0a73 | 3930 | $meta->{'author-tz'}); |
eeef88cd JH |
3931 | my $date = $date{'iso-tz'}; |
3932 | if ($group_size) { | |
cc1bf97e LT |
3933 | $current_color = ++$current_color % $num_colors; |
3934 | } | |
3935 | print "<tr class=\"$rev_color[$current_color]\">\n"; | |
eeef88cd JH |
3936 | if ($group_size) { |
3937 | print "<td class=\"sha1\""; | |
5ad0828c | 3938 | print " title=\"". esc_html($author) . ", $date\""; |
eeef88cd JH |
3939 | print " rowspan=\"$group_size\"" if ($group_size > 1); |
3940 | print ">"; | |
3941 | print $cgi->a({-href => href(action=>"commit", | |
a23f0a73 JN |
3942 | hash=>$full_rev, |
3943 | file_name=>$file_name)}, | |
3944 | esc_html($rev)); | |
eeef88cd | 3945 | print "</td>\n"; |
9dc5f8c9 | 3946 | } |
244a70e6 | 3947 | open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^") |
f73bbb2d | 3948 | or die_error(undef, "Open git-rev-parse failed"); |
244a70e6 LT |
3949 | my $parent_commit = <$dd>; |
3950 | close $dd; | |
3951 | chomp($parent_commit); | |
eeef88cd | 3952 | my $blamed = href(action => 'blame', |
a23f0a73 JN |
3953 | file_name => $meta->{'filename'}, |
3954 | hash_base => $parent_commit); | |
eeef88cd JH |
3955 | print "<td class=\"linenr\">"; |
3956 | print $cgi->a({ -href => "$blamed#l$orig_lineno", | |
a23f0a73 JN |
3957 | -id => "l$lineno", |
3958 | -class => "linenr" }, | |
3959 | esc_html($lineno)); | |
eeef88cd | 3960 | print "</td>"; |
1f2857ea LT |
3961 | print "<td class=\"pre\">" . esc_html($data) . "</td>\n"; |
3962 | print "</tr>\n"; | |
3963 | } | |
3964 | print "</table>\n"; | |
3965 | print "</div>"; | |
952c65fc JN |
3966 | close $fd |
3967 | or print "Reading blob failed\n"; | |
1f2857ea LT |
3968 | git_footer_html(); |
3969 | } | |
3970 | ||
e34ef621 FF |
3971 | sub git_blame { |
3972 | my $fd; | |
ddb8d900 | 3973 | |
1d3fc68a AK |
3974 | my ($have_blame) = gitweb_check_feature('blame'); |
3975 | if (!$have_blame) { | |
ddb8d900 AK |
3976 | die_error('403 Permission denied', "Permission denied"); |
3977 | } | |
cac4bd94 | 3978 | die_error('404 Not Found', "File name not defined") if (!$file_name); |
847e01fb | 3979 | $hash_base ||= git_get_head_hash($project); |
cac4bd94 | 3980 | die_error(undef, "Couldn't find base commit") unless ($hash_base); |
847e01fb | 3981 | my %co = parse_commit($hash_base) |
cac4bd94 | 3982 | or die_error(undef, "Reading commit failed"); |
e34ef621 FF |
3983 | if (!defined $hash) { |
3984 | $hash = git_get_hash_by_path($hash_base, $file_name, "blob") | |
cac4bd94 | 3985 | or die_error(undef, "Error lookup file"); |
e34ef621 | 3986 | } |
25691fbe | 3987 | open ($fd, "-|", git_cmd(), "annotate", '-l', '-t', '-r', $file_name, $hash_base) |
cac4bd94 | 3988 | or die_error(undef, "Open git-annotate failed"); |
e34ef621 | 3989 | git_header_html(); |
0d83ddc4 | 3990 | my $formats_nav = |
952c65fc JN |
3991 | $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, |
3992 | "blob") . | |
3993 | " | " . | |
cae1862a PB |
3994 | $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, |
3995 | "history") . | |
3996 | " | " . | |
952c65fc | 3997 | $cgi->a({-href => href(action=>"blame", file_name=>$file_name)}, |
f35274da | 3998 | "HEAD"); |
847e01fb JN |
3999 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); |
4000 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
59fb1c94 | 4001 | git_print_page_path($file_name, 'blob', $hash_base); |
e34ef621 FF |
4002 | print "<div class=\"page_body\">\n"; |
4003 | print <<HTML; | |
1f1ab5f0 | 4004 | <table class="blame"> |
e34ef621 FF |
4005 | <tr> |
4006 | <th>Commit</th> | |
4007 | <th>Age</th> | |
4008 | <th>Author</th> | |
4009 | <th>Line</th> | |
4010 | <th>Data</th> | |
4011 | </tr> | |
4012 | HTML | |
4013 | my @line_class = (qw(light dark)); | |
4014 | my $line_class_len = scalar (@line_class); | |
4015 | my $line_class_num = $#line_class; | |
4016 | while (my $line = <$fd>) { | |
4017 | my $long_rev; | |
4018 | my $short_rev; | |
4019 | my $author; | |
4020 | my $time; | |
4021 | my $lineno; | |
4022 | my $data; | |
4023 | my $age; | |
4024 | my $age_str; | |
1f1ab5f0 | 4025 | my $age_class; |
e34ef621 FF |
4026 | |
4027 | chomp $line; | |
4028 | $line_class_num = ($line_class_num + 1) % $line_class_len; | |
4029 | ||
030b5208 | 4030 | if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) { |
e34ef621 FF |
4031 | $long_rev = $1; |
4032 | $author = $2; | |
4033 | $time = $3; | |
4034 | $lineno = $4; | |
4035 | $data = $5; | |
4036 | } else { | |
1f1ab5f0 | 4037 | print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n); |
e34ef621 FF |
4038 | next; |
4039 | } | |
4040 | $short_rev = substr ($long_rev, 0, 8); | |
4041 | $age = time () - $time; | |
4042 | $age_str = age_string ($age); | |
4043 | $age_str =~ s/ / /g; | |
1f1ab5f0 | 4044 | $age_class = age_class($age); |
e34ef621 FF |
4045 | $author = esc_html ($author); |
4046 | $author =~ s/ / /g; | |
f16db173 JN |
4047 | |
4048 | $data = untabify($data); | |
717b8311 | 4049 | $data = esc_html ($data); |
2d007374 | 4050 | |
717b8311 JN |
4051 | print <<HTML; |
4052 | <tr class="$line_class[$line_class_num]"> | |
1c2a4f5a | 4053 | <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td> |
717b8311 JN |
4054 | <td class="$age_class">$age_str</td> |
4055 | <td>$author</td> | |
4056 | <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td> | |
4057 | <td class="pre">$data</td> | |
4058 | </tr> | |
4059 | HTML | |
4060 | } # while (my $line = <$fd>) | |
4061 | print "</table>\n\n"; | |
952c65fc JN |
4062 | close $fd |
4063 | or print "Reading blob failed.\n"; | |
717b8311 JN |
4064 | print "</div>"; |
4065 | git_footer_html(); | |
2d007374 PB |
4066 | } |
4067 | ||
717b8311 | 4068 | sub git_tags { |
847e01fb | 4069 | my $head = git_get_head_hash($project); |
717b8311 | 4070 | git_header_html(); |
847e01fb JN |
4071 | git_print_page_nav('','', $head,undef,$head); |
4072 | git_print_header_div('summary', $project); | |
2d007374 | 4073 | |
cd146408 JN |
4074 | my @tagslist = git_get_tags_list(); |
4075 | if (@tagslist) { | |
4076 | git_tags_body(\@tagslist); | |
2d007374 | 4077 | } |
717b8311 | 4078 | git_footer_html(); |
2d007374 PB |
4079 | } |
4080 | ||
717b8311 | 4081 | sub git_heads { |
847e01fb | 4082 | my $head = git_get_head_hash($project); |
717b8311 | 4083 | git_header_html(); |
847e01fb JN |
4084 | git_print_page_nav('','', $head,undef,$head); |
4085 | git_print_header_div('summary', $project); | |
930cf7dd | 4086 | |
cd146408 JN |
4087 | my @headslist = git_get_heads_list(); |
4088 | if (@headslist) { | |
4089 | git_heads_body(\@headslist, $head); | |
f5aa79d9 | 4090 | } |
717b8311 | 4091 | git_footer_html(); |
f5aa79d9 JN |
4092 | } |
4093 | ||
19806691 | 4094 | sub git_blob_plain { |
f2e73302 | 4095 | my $expires; |
f2e73302 | 4096 | |
cff0771b | 4097 | if (!defined $hash) { |
5be01bc8 | 4098 | if (defined $file_name) { |
847e01fb | 4099 | my $base = $hash_base || git_get_head_hash($project); |
5be01bc8 | 4100 | $hash = git_get_hash_by_path($base, $file_name, "blob") |
cac4bd94 | 4101 | or die_error(undef, "Error lookup file"); |
5be01bc8 | 4102 | } else { |
cac4bd94 | 4103 | die_error(undef, "No file name defined"); |
5be01bc8 | 4104 | } |
800764cf MW |
4105 | } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) { |
4106 | # blobs defined by non-textual hash id's can be cached | |
4107 | $expires = "+1d"; | |
5be01bc8 | 4108 | } |
800764cf | 4109 | |
930cf7dd | 4110 | my $type = shift; |
25691fbe | 4111 | open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash |
cfd82669 | 4112 | or die_error(undef, "Couldn't cat $file_name, $hash"); |
930cf7dd | 4113 | |
847e01fb | 4114 | $type ||= blob_mimetype($fd, $file_name); |
f5aa79d9 JN |
4115 | |
4116 | # save as filename, even when no $file_name is given | |
4117 | my $save_as = "$hash"; | |
9312944d KS |
4118 | if (defined $file_name) { |
4119 | $save_as = $file_name; | |
f5aa79d9 JN |
4120 | } elsif ($type =~ m/^text\//) { |
4121 | $save_as .= '.txt'; | |
9312944d | 4122 | } |
f5aa79d9 | 4123 | |
f2e73302 JN |
4124 | print $cgi->header( |
4125 | -type => "$type", | |
4126 | -expires=>$expires, | |
a2a3bf7b | 4127 | -content_disposition => 'inline; filename="' . "$save_as" . '"'); |
19806691 | 4128 | undef $/; |
ad14e931 | 4129 | binmode STDOUT, ':raw'; |
19806691 | 4130 | print <$fd>; |
ad14e931 | 4131 | binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi |
19806691 KS |
4132 | $/ = "\n"; |
4133 | close $fd; | |
4134 | } | |
4135 | ||
930cf7dd | 4136 | sub git_blob { |
f2e73302 | 4137 | my $expires; |
f2e73302 | 4138 | |
cff0771b | 4139 | if (!defined $hash) { |
5be01bc8 | 4140 | if (defined $file_name) { |
847e01fb | 4141 | my $base = $hash_base || git_get_head_hash($project); |
5be01bc8 | 4142 | $hash = git_get_hash_by_path($base, $file_name, "blob") |
cac4bd94 | 4143 | or die_error(undef, "Error lookup file"); |
5be01bc8 | 4144 | } else { |
cac4bd94 | 4145 | die_error(undef, "No file name defined"); |
5be01bc8 | 4146 | } |
800764cf MW |
4147 | } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) { |
4148 | # blobs defined by non-textual hash id's can be cached | |
4149 | $expires = "+1d"; | |
5be01bc8 | 4150 | } |
800764cf | 4151 | |
1d3fc68a | 4152 | my ($have_blame) = gitweb_check_feature('blame'); |
25691fbe | 4153 | open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash |
cac4bd94 | 4154 | or die_error(undef, "Couldn't cat $file_name, $hash"); |
847e01fb | 4155 | my $mimetype = blob_mimetype($fd, $file_name); |
5a4cf334 | 4156 | if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) { |
930cf7dd LT |
4157 | close $fd; |
4158 | return git_blob_plain($mimetype); | |
4159 | } | |
5a4cf334 JN |
4160 | # we can have blame only for text/* mimetype |
4161 | $have_blame &&= ($mimetype =~ m!^text/!); | |
4162 | ||
f2e73302 | 4163 | git_header_html(undef, $expires); |
0d83ddc4 | 4164 | my $formats_nav = ''; |
847e01fb | 4165 | if (defined $hash_base && (my %co = parse_commit($hash_base))) { |
930cf7dd LT |
4166 | if (defined $file_name) { |
4167 | if ($have_blame) { | |
952c65fc JN |
4168 | $formats_nav .= |
4169 | $cgi->a({-href => href(action=>"blame", hash_base=>$hash_base, | |
4170 | hash=>$hash, file_name=>$file_name)}, | |
4171 | "blame") . | |
4172 | " | "; | |
930cf7dd | 4173 | } |
0d83ddc4 | 4174 | $formats_nav .= |
cae1862a PB |
4175 | $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, |
4176 | hash=>$hash, file_name=>$file_name)}, | |
4177 | "history") . | |
4178 | " | " . | |
952c65fc JN |
4179 | $cgi->a({-href => href(action=>"blob_plain", |
4180 | hash=>$hash, file_name=>$file_name)}, | |
35329cc1 | 4181 | "raw") . |
952c65fc JN |
4182 | " | " . |
4183 | $cgi->a({-href => href(action=>"blob", | |
4184 | hash_base=>"HEAD", file_name=>$file_name)}, | |
f35274da | 4185 | "HEAD"); |
930cf7dd | 4186 | } else { |
952c65fc | 4187 | $formats_nav .= |
35329cc1 | 4188 | $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "raw"); |
930cf7dd | 4189 | } |
847e01fb JN |
4190 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); |
4191 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
930cf7dd LT |
4192 | } else { |
4193 | print "<div class=\"page_nav\">\n" . | |
4194 | "<br/><br/></div>\n" . | |
4195 | "<div class=\"title\">$hash</div>\n"; | |
4196 | } | |
59fb1c94 | 4197 | git_print_page_path($file_name, "blob", $hash_base); |
930cf7dd | 4198 | print "<div class=\"page_body\">\n"; |
5a4cf334 JN |
4199 | if ($mimetype =~ m!^text/!) { |
4200 | my $nr; | |
4201 | while (my $line = <$fd>) { | |
4202 | chomp $line; | |
4203 | $nr++; | |
4204 | $line = untabify($line); | |
4205 | printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", | |
4206 | $nr, $nr, $nr, esc_html($line, -nbsp=>1); | |
4207 | } | |
4208 | } elsif ($mimetype =~ m!^image/!) { | |
4209 | print qq!<img type="$mimetype"!; | |
4210 | if ($file_name) { | |
4211 | print qq! alt="$file_name" title="$file_name"!; | |
4212 | } | |
4213 | print qq! src="! . | |
4214 | href(action=>"blob_plain", hash=>$hash, | |
4215 | hash_base=>$hash_base, file_name=>$file_name) . | |
4216 | qq!" />\n!; | |
930cf7dd | 4217 | } |
952c65fc JN |
4218 | close $fd |
4219 | or print "Reading blob failed.\n"; | |
930cf7dd LT |
4220 | print "</div>"; |
4221 | git_footer_html(); | |
4222 | } | |
4223 | ||
09bd7898 | 4224 | sub git_tree { |
6f7ea5fb LT |
4225 | if (!defined $hash_base) { |
4226 | $hash_base = "HEAD"; | |
4227 | } | |
b87d78d6 | 4228 | if (!defined $hash) { |
09bd7898 | 4229 | if (defined $file_name) { |
6f7ea5fb LT |
4230 | $hash = git_get_hash_by_path($hash_base, $file_name, "tree"); |
4231 | } else { | |
4232 | $hash = $hash_base; | |
10dba28d | 4233 | } |
e925f38c | 4234 | } |
232ff553 | 4235 | $/ = "\0"; |
25691fbe | 4236 | open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash |
cac4bd94 | 4237 | or die_error(undef, "Open git-ls-tree failed"); |
0881d2d1 | 4238 | my @entries = map { chomp; $_ } <$fd>; |
cac4bd94 | 4239 | close $fd or die_error(undef, "Reading tree failed"); |
232ff553 | 4240 | $/ = "\n"; |
d63577da | 4241 | |
847e01fb JN |
4242 | my $refs = git_get_references(); |
4243 | my $ref = format_ref_marker($refs, $hash_base); | |
12a88f2f | 4244 | git_header_html(); |
300454fe | 4245 | my $basedir = ''; |
1d3fc68a | 4246 | my ($have_blame) = gitweb_check_feature('blame'); |
847e01fb | 4247 | if (defined $hash_base && (my %co = parse_commit($hash_base))) { |
cae1862a PB |
4248 | my @views_nav = (); |
4249 | if (defined $file_name) { | |
4250 | push @views_nav, | |
4251 | $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, | |
4252 | hash=>$hash, file_name=>$file_name)}, | |
4253 | "history"), | |
4254 | $cgi->a({-href => href(action=>"tree", | |
4255 | hash_base=>"HEAD", file_name=>$file_name)}, | |
f35274da | 4256 | "HEAD"), |
cae1862a | 4257 | } |
a3c8ab30 MM |
4258 | my $snapshot_links = format_snapshot_links($hash); |
4259 | if (defined $snapshot_links) { | |
cae1862a | 4260 | # FIXME: Should be available when we have no hash base as well. |
a3c8ab30 | 4261 | push @views_nav, $snapshot_links; |
cae1862a PB |
4262 | } |
4263 | git_print_page_nav('tree','', $hash_base, undef, undef, join(' | ', @views_nav)); | |
847e01fb | 4264 | git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base); |
d63577da | 4265 | } else { |
fa702003 | 4266 | undef $hash_base; |
d63577da KS |
4267 | print "<div class=\"page_nav\">\n"; |
4268 | print "<br/><br/></div>\n"; | |
4269 | print "<div class=\"title\">$hash</div>\n"; | |
4270 | } | |
09bd7898 | 4271 | if (defined $file_name) { |
300454fe JN |
4272 | $basedir = $file_name; |
4273 | if ($basedir ne '' && substr($basedir, -1) ne '/') { | |
4274 | $basedir .= '/'; | |
4275 | } | |
09bd7898 | 4276 | } |
59fb1c94 | 4277 | git_print_page_path($file_name, 'tree', $hash_base); |
fbb592a9 | 4278 | print "<div class=\"page_body\">\n"; |
42f7eb94 | 4279 | print "<table cellspacing=\"0\">\n"; |
6dd36acd | 4280 | my $alternate = 1; |
b6b7fc72 JN |
4281 | # '..' (top directory) link if possible |
4282 | if (defined $hash_base && | |
4283 | defined $file_name && $file_name =~ m![^/]+$!) { | |
4284 | if ($alternate) { | |
4285 | print "<tr class=\"dark\">\n"; | |
4286 | } else { | |
4287 | print "<tr class=\"light\">\n"; | |
4288 | } | |
4289 | $alternate ^= 1; | |
4290 | ||
4291 | my $up = $file_name; | |
4292 | $up =~ s!/?[^/]+$!!; | |
4293 | undef $up unless $up; | |
4294 | # based on git_print_tree_entry | |
4295 | print '<td class="mode">' . mode_str('040000') . "</td>\n"; | |
4296 | print '<td class="list">'; | |
4297 | print $cgi->a({-href => href(action=>"tree", hash_base=>$hash_base, | |
4298 | file_name=>$up)}, | |
4299 | ".."); | |
4300 | print "</td>\n"; | |
4301 | print "<td class=\"link\"></td>\n"; | |
4302 | ||
4303 | print "</tr>\n"; | |
4304 | } | |
161332a5 | 4305 | foreach my $line (@entries) { |
cb849b46 JN |
4306 | my %t = parse_ls_tree_line($line, -z => 1); |
4307 | ||
bddec01d | 4308 | if ($alternate) { |
c994d620 | 4309 | print "<tr class=\"dark\">\n"; |
bddec01d | 4310 | } else { |
c994d620 | 4311 | print "<tr class=\"light\">\n"; |
bddec01d KS |
4312 | } |
4313 | $alternate ^= 1; | |
cb849b46 | 4314 | |
300454fe | 4315 | git_print_tree_entry(\%t, $basedir, $hash_base, $have_blame); |
fa702003 | 4316 | |
42f7eb94 | 4317 | print "</tr>\n"; |
161332a5 | 4318 | } |
42f7eb94 KS |
4319 | print "</table>\n" . |
4320 | "</div>"; | |
12a88f2f | 4321 | git_footer_html(); |
09bd7898 KS |
4322 | } |
4323 | ||
cb9c6e5b | 4324 | sub git_snapshot { |
a3c8ab30 | 4325 | my @supported_fmts = gitweb_check_feature('snapshot'); |
a781785d | 4326 | @supported_fmts = filter_snapshot_fmts(@supported_fmts); |
a3c8ab30 MM |
4327 | |
4328 | my $format = $cgi->param('sf'); | |
3473e7df JN |
4329 | if (!@supported_fmts) { |
4330 | die_error('403 Permission denied', "Permission denied"); | |
4331 | } | |
4332 | # default to first supported snapshot format | |
4333 | $format ||= $supported_fmts[0]; | |
4334 | if ($format !~ m/^[a-z0-9]+$/) { | |
4335 | die_error(undef, "Invalid snapshot format parameter"); | |
4336 | } elsif (!exists($known_snapshot_formats{$format})) { | |
4337 | die_error(undef, "Unknown snapshot format"); | |
4338 | } elsif (!grep($_ eq $format, @supported_fmts)) { | |
a3c8ab30 | 4339 | die_error(undef, "Unsupported snapshot format"); |
ddb8d900 AK |
4340 | } |
4341 | ||
cb9c6e5b AK |
4342 | if (!defined $hash) { |
4343 | $hash = git_get_head_hash($project); | |
4344 | } | |
4345 | ||
a3c8ab30 | 4346 | my $git_command = git_cmd_str(); |
072570ee | 4347 | my $name = $project; |
9a7d9410 ML |
4348 | $name =~ s,([^/])/*\.git$,$1,; |
4349 | $name = basename($name); | |
4350 | my $filename = to_utf8($name); | |
072570ee | 4351 | $name =~ s/\047/\047\\\047\047/g; |
072570ee | 4352 | my $cmd; |
a3c8ab30 MM |
4353 | $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}"; |
4354 | $cmd = "$git_command archive " . | |
887c5266 | 4355 | "--format=$known_snapshot_formats{$format}{'format'} " . |
a3c8ab30 MM |
4356 | "--prefix=\'$name\'/ $hash"; |
4357 | if (exists $known_snapshot_formats{$format}{'compressor'}) { | |
4358 | $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}}; | |
072570ee | 4359 | } |
cb9c6e5b | 4360 | |
ab41dfbf | 4361 | print $cgi->header( |
a3c8ab30 | 4362 | -type => $known_snapshot_formats{$format}{'type'}, |
a2a3bf7b | 4363 | -content_disposition => 'inline; filename="' . "$filename" . '"', |
ab41dfbf | 4364 | -status => '200 OK'); |
cb9c6e5b | 4365 | |
072570ee ML |
4366 | open my $fd, "-|", $cmd |
4367 | or die_error(undef, "Execute git-archive failed"); | |
cb9c6e5b AK |
4368 | binmode STDOUT, ':raw'; |
4369 | print <$fd>; | |
4370 | binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi | |
4371 | close $fd; | |
cb9c6e5b AK |
4372 | } |
4373 | ||
09bd7898 | 4374 | sub git_log { |
847e01fb | 4375 | my $head = git_get_head_hash($project); |
0db37973 | 4376 | if (!defined $hash) { |
19806691 | 4377 | $hash = $head; |
0db37973 | 4378 | } |
ea4a6df4 KS |
4379 | if (!defined $page) { |
4380 | $page = 0; | |
b87d78d6 | 4381 | } |
847e01fb | 4382 | my $refs = git_get_references(); |
ea4a6df4 | 4383 | |
719dad28 | 4384 | my @commitlist = parse_commits($hash, 101, (100 * $page)); |
ea4a6df4 | 4385 | |
719dad28 | 4386 | my $paging_nav = format_paging_nav('log', $hash, $head, $page, (100 * ($page+1))); |
0d83ddc4 JN |
4387 | |
4388 | git_header_html(); | |
847e01fb | 4389 | git_print_page_nav('log','', $hash,undef,undef, $paging_nav); |
0d83ddc4 | 4390 | |
719dad28 | 4391 | if (!@commitlist) { |
847e01fb | 4392 | my %co = parse_commit($hash); |
27fb8c40 | 4393 | |
847e01fb | 4394 | git_print_header_div('summary', $project); |
e925f38c | 4395 | print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n"; |
161332a5 | 4396 | } |
719dad28 RF |
4397 | my $to = ($#commitlist >= 99) ? (99) : ($#commitlist); |
4398 | for (my $i = 0; $i <= $to; $i++) { | |
4399 | my %co = %{$commitlist[$i]}; | |
b87d78d6 | 4400 | next if !%co; |
719dad28 RF |
4401 | my $commit = $co{'id'}; |
4402 | my $ref = format_ref_marker($refs, $commit); | |
847e01fb JN |
4403 | my %ad = parse_date($co{'author_epoch'}); |
4404 | git_print_header_div('commit', | |
26298b5f JN |
4405 | "<span class=\"age\">$co{'age_string'}</span>" . |
4406 | esc_html($co{'title'}) . $ref, | |
4407 | $commit); | |
034df39e KS |
4408 | print "<div class=\"title_text\">\n" . |
4409 | "<div class=\"log_link\">\n" . | |
1c2a4f5a | 4410 | $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . |
952c65fc JN |
4411 | " | " . |
4412 | $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . | |
6ef4cb2e | 4413 | " | " . |
d7267207 | 4414 | $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") . |
eb28240b | 4415 | "<br/>\n" . |
034df39e | 4416 | "</div>\n" . |
40c13813 | 4417 | "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" . |
d16d093c JN |
4418 | "</div>\n"; |
4419 | ||
4420 | print "<div class=\"log_body\">\n"; | |
f2069411 | 4421 | git_print_log($co{'comment'}, -final_empty_line=> 1); |
09bd7898 | 4422 | print "</div>\n"; |
719dad28 RF |
4423 | } |
4424 | if ($#commitlist >= 100) { | |
4425 | print "<div class=\"page_nav\">\n"; | |
4426 | print $cgi->a({-href => href(action=>"log", hash=>$hash, page=>$page+1), | |
4427 | -accesskey => "n", -title => "Alt-n"}, "next"); | |
4428 | print "</div>\n"; | |
e334d18c | 4429 | } |
034df39e | 4430 | git_footer_html(); |
09bd7898 KS |
4431 | } |
4432 | ||
4433 | sub git_commit { | |
9954f772 | 4434 | $hash ||= $hash_base || "HEAD"; |
847e01fb | 4435 | my %co = parse_commit($hash); |
034df39e | 4436 | if (!%co) { |
cac4bd94 | 4437 | die_error(undef, "Unknown commit object"); |
d63577da | 4438 | } |
847e01fb JN |
4439 | my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'}); |
4440 | my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'}); | |
161332a5 | 4441 | |
c9d193df JN |
4442 | my $parent = $co{'parent'}; |
4443 | my $parents = $co{'parents'}; # listref | |
4444 | ||
4445 | # we need to prepare $formats_nav before any parameter munging | |
4446 | my $formats_nav; | |
4447 | if (!defined $parent) { | |
4448 | # --root commitdiff | |
4449 | $formats_nav .= '(initial)'; | |
4450 | } elsif (@$parents == 1) { | |
4451 | # single parent commit | |
4452 | $formats_nav .= | |
4453 | '(parent: ' . | |
4454 | $cgi->a({-href => href(action=>"commit", | |
4455 | hash=>$parent)}, | |
4456 | esc_html(substr($parent, 0, 7))) . | |
4457 | ')'; | |
4458 | } else { | |
4459 | # merge commit | |
4460 | $formats_nav .= | |
4461 | '(merge: ' . | |
4462 | join(' ', map { | |
f9308a18 | 4463 | $cgi->a({-href => href(action=>"commit", |
c9d193df JN |
4464 | hash=>$_)}, |
4465 | esc_html(substr($_, 0, 7))); | |
4466 | } @$parents ) . | |
4467 | ')'; | |
4468 | } | |
4469 | ||
d8a20ba9 | 4470 | if (!defined $parent) { |
b9182987 | 4471 | $parent = "--root"; |
6191f8e1 | 4472 | } |
549ab4a3 | 4473 | my @difftree; |
208ecb2e JN |
4474 | open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id", |
4475 | @diff_opts, | |
4476 | (@$parents <= 1 ? $parent : '-c'), | |
4477 | $hash, "--" | |
4478 | or die_error(undef, "Open git-diff-tree failed"); | |
4479 | @difftree = map { chomp; $_ } <$fd>; | |
4480 | close $fd or die_error(undef, "Reading git-diff-tree failed"); | |
11044297 KS |
4481 | |
4482 | # non-textual hash id's can be cached | |
4483 | my $expires; | |
4484 | if ($hash =~ m/^[0-9a-fA-F]{40}$/) { | |
4485 | $expires = "+1d"; | |
4486 | } | |
847e01fb JN |
4487 | my $refs = git_get_references(); |
4488 | my $ref = format_ref_marker($refs, $co{'id'}); | |
ddb8d900 | 4489 | |
594e212b | 4490 | git_header_html(undef, $expires); |
a144154f | 4491 | git_print_page_nav('commit', '', |
952c65fc | 4492 | $hash, $co{'tree'}, $hash, |
c9d193df | 4493 | $formats_nav); |
4f7b34c9 | 4494 | |
b87d78d6 | 4495 | if (defined $co{'parent'}) { |
847e01fb | 4496 | git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash); |
b87d78d6 | 4497 | } else { |
847e01fb | 4498 | git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash); |
b87d78d6 | 4499 | } |
6191f8e1 | 4500 | print "<div class=\"title_text\">\n" . |
b87d78d6 | 4501 | "<table cellspacing=\"0\">\n"; |
40c13813 | 4502 | print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n". |
bddec01d KS |
4503 | "<tr>" . |
4504 | "<td></td><td> $ad{'rfc2822'}"; | |
927dcec4 | 4505 | if ($ad{'hour_local'} < 6) { |
952c65fc JN |
4506 | printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", |
4507 | $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); | |
b87d78d6 | 4508 | } else { |
952c65fc JN |
4509 | printf(" (%02d:%02d %s)", |
4510 | $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); | |
b87d78d6 | 4511 | } |
bddec01d KS |
4512 | print "</td>" . |
4513 | "</tr>\n"; | |
40c13813 | 4514 | print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n"; |
952c65fc JN |
4515 | print "<tr><td></td><td> $cd{'rfc2822'}" . |
4516 | sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . | |
4517 | "</td></tr>\n"; | |
1f1ab5f0 | 4518 | print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n"; |
bddec01d KS |
4519 | print "<tr>" . |
4520 | "<td>tree</td>" . | |
1f1ab5f0 | 4521 | "<td class=\"sha1\">" . |
952c65fc JN |
4522 | $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash), |
4523 | class => "list"}, $co{'tree'}) . | |
19806691 | 4524 | "</td>" . |
952c65fc JN |
4525 | "<td class=\"link\">" . |
4526 | $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)}, | |
4527 | "tree"); | |
a3c8ab30 MM |
4528 | my $snapshot_links = format_snapshot_links($hash); |
4529 | if (defined $snapshot_links) { | |
4530 | print " | " . $snapshot_links; | |
cb9c6e5b AK |
4531 | } |
4532 | print "</td>" . | |
bddec01d | 4533 | "</tr>\n"; |
549ab4a3 | 4534 | |
3e029299 | 4535 | foreach my $par (@$parents) { |
bddec01d KS |
4536 | print "<tr>" . |
4537 | "<td>parent</td>" . | |
952c65fc JN |
4538 | "<td class=\"sha1\">" . |
4539 | $cgi->a({-href => href(action=>"commit", hash=>$par), | |
4540 | class => "list"}, $par) . | |
4541 | "</td>" . | |
bddec01d | 4542 | "<td class=\"link\">" . |
1c2a4f5a | 4543 | $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") . |
952c65fc | 4544 | " | " . |
f2e60947 | 4545 | $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") . |
bddec01d KS |
4546 | "</td>" . |
4547 | "</tr>\n"; | |
3e029299 | 4548 | } |
7a9b4c5f | 4549 | print "</table>". |
b87d78d6 | 4550 | "</div>\n"; |
d16d093c | 4551 | |
fbb592a9 | 4552 | print "<div class=\"page_body\">\n"; |
d16d093c | 4553 | git_print_log($co{'comment'}); |
927dcec4 | 4554 | print "</div>\n"; |
4a4a1a53 | 4555 | |
208ecb2e | 4556 | git_difftree_body(\@difftree, $hash, @$parents); |
4a4a1a53 | 4557 | |
12a88f2f | 4558 | git_footer_html(); |
09bd7898 KS |
4559 | } |
4560 | ||
ca94601c JN |
4561 | sub git_object { |
4562 | # object is defined by: | |
4563 | # - hash or hash_base alone | |
4564 | # - hash_base and file_name | |
4565 | my $type; | |
4566 | ||
4567 | # - hash or hash_base alone | |
4568 | if ($hash || ($hash_base && !defined $file_name)) { | |
4569 | my $object_id = $hash || $hash_base; | |
4570 | ||
4571 | my $git_command = git_cmd_str(); | |
4572 | open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null" | |
4573 | or die_error('404 Not Found', "Object does not exist"); | |
4574 | $type = <$fd>; | |
4575 | chomp $type; | |
4576 | close $fd | |
4577 | or die_error('404 Not Found', "Object does not exist"); | |
4578 | ||
4579 | # - hash_base and file_name | |
4580 | } elsif ($hash_base && defined $file_name) { | |
4581 | $file_name =~ s,/+$,,; | |
4582 | ||
4583 | system(git_cmd(), "cat-file", '-e', $hash_base) == 0 | |
4584 | or die_error('404 Not Found', "Base object does not exist"); | |
4585 | ||
4586 | # here errors should not hapen | |
4587 | open my $fd, "-|", git_cmd(), "ls-tree", $hash_base, "--", $file_name | |
4588 | or die_error(undef, "Open git-ls-tree failed"); | |
4589 | my $line = <$fd>; | |
4590 | close $fd; | |
4591 | ||
4592 | #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' | |
4593 | unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) { | |
4594 | die_error('404 Not Found', "File or directory for given base does not exist"); | |
4595 | } | |
4596 | $type = $2; | |
4597 | $hash = $3; | |
4598 | } else { | |
4599 | die_error('404 Not Found', "Not enough information to find object"); | |
4600 | } | |
4601 | ||
4602 | print $cgi->redirect(-uri => href(action=>$type, -full=>1, | |
4603 | hash=>$hash, hash_base=>$hash_base, | |
4604 | file_name=>$file_name), | |
4605 | -status => '302 Found'); | |
4606 | } | |
4607 | ||
09bd7898 | 4608 | sub git_blobdiff { |
9b71b1f6 JN |
4609 | my $format = shift || 'html'; |
4610 | ||
7c5e2ebb JN |
4611 | my $fd; |
4612 | my @difftree; | |
4613 | my %diffinfo; | |
9b71b1f6 | 4614 | my $expires; |
7c5e2ebb JN |
4615 | |
4616 | # preparing $fd and %diffinfo for git_patchset_body | |
4617 | # new style URI | |
4618 | if (defined $hash_base && defined $hash_parent_base) { | |
4619 | if (defined $file_name) { | |
4620 | # read raw output | |
45bd0c80 JN |
4621 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
4622 | $hash_parent_base, $hash_base, | |
5ae917ac | 4623 | "--", (defined $file_parent ? $file_parent : ()), $file_name |
7c5e2ebb JN |
4624 | or die_error(undef, "Open git-diff-tree failed"); |
4625 | @difftree = map { chomp; $_ } <$fd>; | |
4626 | close $fd | |
4627 | or die_error(undef, "Reading git-diff-tree failed"); | |
4628 | @difftree | |
4629 | or die_error('404 Not Found', "Blob diff not found"); | |
4630 | ||
0aea3376 JN |
4631 | } elsif (defined $hash && |
4632 | $hash =~ /[0-9a-fA-F]{40}/) { | |
4633 | # try to find filename from $hash | |
7c5e2ebb JN |
4634 | |
4635 | # read filtered raw output | |
45bd0c80 JN |
4636 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
4637 | $hash_parent_base, $hash_base, "--" | |
7c5e2ebb JN |
4638 | or die_error(undef, "Open git-diff-tree failed"); |
4639 | @difftree = | |
4640 | # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c' | |
4641 | # $hash == to_id | |
4642 | grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ } | |
4643 | map { chomp; $_ } <$fd>; | |
4644 | close $fd | |
4645 | or die_error(undef, "Reading git-diff-tree failed"); | |
4646 | @difftree | |
4647 | or die_error('404 Not Found', "Blob diff not found"); | |
4648 | ||
4649 | } else { | |
4650 | die_error('404 Not Found', "Missing one of the blob diff parameters"); | |
4651 | } | |
4652 | ||
4653 | if (@difftree > 1) { | |
4654 | die_error('404 Not Found', "Ambiguous blob diff specification"); | |
4655 | } | |
4656 | ||
4657 | %diffinfo = parse_difftree_raw_line($difftree[0]); | |
4658 | $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'}; | |
4659 | $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'}; | |
4660 | ||
4661 | $hash_parent ||= $diffinfo{'from_id'}; | |
4662 | $hash ||= $diffinfo{'to_id'}; | |
4663 | ||
9b71b1f6 JN |
4664 | # non-textual hash id's can be cached |
4665 | if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ && | |
4666 | $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) { | |
4667 | $expires = '+1d'; | |
4668 | } | |
4669 | ||
7c5e2ebb | 4670 | # open patch output |
25691fbe | 4671 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
957d6ea7 JN |
4672 | '-p', ($format eq 'html' ? "--full-index" : ()), |
4673 | $hash_parent_base, $hash_base, | |
5ae917ac | 4674 | "--", (defined $file_parent ? $file_parent : ()), $file_name |
7c5e2ebb JN |
4675 | or die_error(undef, "Open git-diff-tree failed"); |
4676 | } | |
4677 | ||
4678 | # old/legacy style URI | |
4679 | if (!%diffinfo && # if new style URI failed | |
4680 | defined $hash && defined $hash_parent) { | |
4681 | # fake git-diff-tree raw output | |
4682 | $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob"; | |
4683 | $diffinfo{'from_id'} = $hash_parent; | |
4684 | $diffinfo{'to_id'} = $hash; | |
4685 | if (defined $file_name) { | |
4686 | if (defined $file_parent) { | |
4687 | $diffinfo{'status'} = '2'; | |
8391548e PB |
4688 | $diffinfo{'from_file'} = $file_parent; |
4689 | $diffinfo{'to_file'} = $file_name; | |
7c5e2ebb JN |
4690 | } else { # assume not renamed |
4691 | $diffinfo{'status'} = '1'; | |
8391548e PB |
4692 | $diffinfo{'from_file'} = $file_name; |
4693 | $diffinfo{'to_file'} = $file_name; | |
7c5e2ebb JN |
4694 | } |
4695 | } else { # no filename given | |
4696 | $diffinfo{'status'} = '2'; | |
4697 | $diffinfo{'from_file'} = $hash_parent; | |
4698 | $diffinfo{'to_file'} = $hash; | |
4699 | } | |
4700 | ||
9b71b1f6 JN |
4701 | # non-textual hash id's can be cached |
4702 | if ($hash =~ m/^[0-9a-fA-F]{40}$/ && | |
4703 | $hash_parent =~ m/^[0-9a-fA-F]{40}$/) { | |
4704 | $expires = '+1d'; | |
4705 | } | |
4706 | ||
4707 | # open patch output | |
957d6ea7 JN |
4708 | open $fd, "-|", git_cmd(), "diff", @diff_opts, |
4709 | '-p', ($format eq 'html' ? "--full-index" : ()), | |
45bd0c80 | 4710 | $hash_parent, $hash, "--" |
7c5e2ebb JN |
4711 | or die_error(undef, "Open git-diff failed"); |
4712 | } else { | |
4713 | die_error('404 Not Found', "Missing one of the blob diff parameters") | |
4714 | unless %diffinfo; | |
4715 | } | |
4716 | ||
4717 | # header | |
9b71b1f6 JN |
4718 | if ($format eq 'html') { |
4719 | my $formats_nav = | |
4720 | $cgi->a({-href => href(action=>"blobdiff_plain", | |
4721 | hash=>$hash, hash_parent=>$hash_parent, | |
4722 | hash_base=>$hash_base, hash_parent_base=>$hash_parent_base, | |
4723 | file_name=>$file_name, file_parent=>$file_parent)}, | |
35329cc1 | 4724 | "raw"); |
9b71b1f6 JN |
4725 | git_header_html(undef, $expires); |
4726 | if (defined $hash_base && (my %co = parse_commit($hash_base))) { | |
4727 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); | |
4728 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
4729 | } else { | |
4730 | print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n"; | |
4731 | print "<div class=\"title\">$hash vs $hash_parent</div>\n"; | |
4732 | } | |
4733 | if (defined $file_name) { | |
4734 | git_print_page_path($file_name, "blob", $hash_base); | |
4735 | } else { | |
4736 | print "<div class=\"page_path\"></div>\n"; | |
4737 | } | |
4738 | ||
4739 | } elsif ($format eq 'plain') { | |
4740 | print $cgi->header( | |
4741 | -type => 'text/plain', | |
4742 | -charset => 'utf-8', | |
4743 | -expires => $expires, | |
a2a3bf7b | 4744 | -content_disposition => 'inline; filename="' . "$file_name" . '.patch"'); |
9b71b1f6 JN |
4745 | |
4746 | print "X-Git-Url: " . $cgi->self_url() . "\n\n"; | |
4747 | ||
7c5e2ebb | 4748 | } else { |
9b71b1f6 | 4749 | die_error(undef, "Unknown blobdiff format"); |
7c5e2ebb JN |
4750 | } |
4751 | ||
4752 | # patch | |
9b71b1f6 JN |
4753 | if ($format eq 'html') { |
4754 | print "<div class=\"page_body\">\n"; | |
7c5e2ebb | 4755 | |
9b71b1f6 JN |
4756 | git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base); |
4757 | close $fd; | |
7c5e2ebb | 4758 | |
9b71b1f6 JN |
4759 | print "</div>\n"; # class="page_body" |
4760 | git_footer_html(); | |
4761 | ||
4762 | } else { | |
4763 | while (my $line = <$fd>) { | |
403d0906 JN |
4764 | $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg; |
4765 | $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg; | |
9b71b1f6 JN |
4766 | |
4767 | print $line; | |
4768 | ||
4769 | last if $line =~ m!^\+\+\+!; | |
4770 | } | |
4771 | local $/ = undef; | |
4772 | print <$fd>; | |
4773 | close $fd; | |
4774 | } | |
09bd7898 KS |
4775 | } |
4776 | ||
19806691 | 4777 | sub git_blobdiff_plain { |
9b71b1f6 | 4778 | git_blobdiff('plain'); |
19806691 KS |
4779 | } |
4780 | ||
09bd7898 | 4781 | sub git_commitdiff { |
eee08903 | 4782 | my $format = shift || 'html'; |
9954f772 | 4783 | $hash ||= $hash_base || "HEAD"; |
847e01fb | 4784 | my %co = parse_commit($hash); |
034df39e | 4785 | if (!%co) { |
cac4bd94 | 4786 | die_error(undef, "Unknown commit object"); |
d63577da | 4787 | } |
151602df | 4788 | |
cd030c3a JN |
4789 | # choose format for commitdiff for merge |
4790 | if (! defined $hash_parent && @{$co{'parents'}} > 1) { | |
4791 | $hash_parent = '--cc'; | |
4792 | } | |
4793 | # we need to prepare $formats_nav before almost any parameter munging | |
151602df JN |
4794 | my $formats_nav; |
4795 | if ($format eq 'html') { | |
4796 | $formats_nav = | |
4797 | $cgi->a({-href => href(action=>"commitdiff_plain", | |
4798 | hash=>$hash, hash_parent=>$hash_parent)}, | |
4799 | "raw"); | |
4800 | ||
cd030c3a JN |
4801 | if (defined $hash_parent && |
4802 | $hash_parent ne '-c' && $hash_parent ne '--cc') { | |
151602df JN |
4803 | # commitdiff with two commits given |
4804 | my $hash_parent_short = $hash_parent; | |
4805 | if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) { | |
4806 | $hash_parent_short = substr($hash_parent, 0, 7); | |
4807 | } | |
4808 | $formats_nav .= | |
ada3e1f7 JN |
4809 | ' (from'; |
4810 | for (my $i = 0; $i < @{$co{'parents'}}; $i++) { | |
4811 | if ($co{'parents'}[$i] eq $hash_parent) { | |
4812 | $formats_nav .= ' parent ' . ($i+1); | |
4813 | last; | |
4814 | } | |
4815 | } | |
4816 | $formats_nav .= ': ' . | |
151602df JN |
4817 | $cgi->a({-href => href(action=>"commitdiff", |
4818 | hash=>$hash_parent)}, | |
4819 | esc_html($hash_parent_short)) . | |
4820 | ')'; | |
4821 | } elsif (!$co{'parent'}) { | |
4822 | # --root commitdiff | |
4823 | $formats_nav .= ' (initial)'; | |
4824 | } elsif (scalar @{$co{'parents'}} == 1) { | |
4825 | # single parent commit | |
4826 | $formats_nav .= | |
4827 | ' (parent: ' . | |
4828 | $cgi->a({-href => href(action=>"commitdiff", | |
4829 | hash=>$co{'parent'})}, | |
4830 | esc_html(substr($co{'parent'}, 0, 7))) . | |
4831 | ')'; | |
4832 | } else { | |
4833 | # merge commit | |
cd030c3a JN |
4834 | if ($hash_parent eq '--cc') { |
4835 | $formats_nav .= ' | ' . | |
4836 | $cgi->a({-href => href(action=>"commitdiff", | |
4837 | hash=>$hash, hash_parent=>'-c')}, | |
4838 | 'combined'); | |
4839 | } else { # $hash_parent eq '-c' | |
4840 | $formats_nav .= ' | ' . | |
4841 | $cgi->a({-href => href(action=>"commitdiff", | |
4842 | hash=>$hash, hash_parent=>'--cc')}, | |
4843 | 'compact'); | |
4844 | } | |
151602df JN |
4845 | $formats_nav .= |
4846 | ' (merge: ' . | |
4847 | join(' ', map { | |
4848 | $cgi->a({-href => href(action=>"commitdiff", | |
4849 | hash=>$_)}, | |
4850 | esc_html(substr($_, 0, 7))); | |
4851 | } @{$co{'parents'}} ) . | |
4852 | ')'; | |
4853 | } | |
4854 | } | |
4855 | ||
fb1dde4a | 4856 | my $hash_parent_param = $hash_parent; |
cd030c3a JN |
4857 | if (!defined $hash_parent_param) { |
4858 | # --cc for multiple parents, --root for parentless | |
fb1dde4a | 4859 | $hash_parent_param = |
cd030c3a | 4860 | @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root'; |
bddec01d | 4861 | } |
eee08903 JN |
4862 | |
4863 | # read commitdiff | |
4864 | my $fd; | |
4865 | my @difftree; | |
eee08903 | 4866 | if ($format eq 'html') { |
25691fbe | 4867 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
45bd0c80 | 4868 | "--no-commit-id", "--patch-with-raw", "--full-index", |
fb1dde4a | 4869 | $hash_parent_param, $hash, "--" |
eee08903 JN |
4870 | or die_error(undef, "Open git-diff-tree failed"); |
4871 | ||
04408c35 JN |
4872 | while (my $line = <$fd>) { |
4873 | chomp $line; | |
eee08903 JN |
4874 | # empty line ends raw part of diff-tree output |
4875 | last unless $line; | |
493e01db | 4876 | push @difftree, scalar parse_difftree_raw_line($line); |
eee08903 | 4877 | } |
eee08903 | 4878 | |
eee08903 | 4879 | } elsif ($format eq 'plain') { |
25691fbe | 4880 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
fb1dde4a | 4881 | '-p', $hash_parent_param, $hash, "--" |
eee08903 | 4882 | or die_error(undef, "Open git-diff-tree failed"); |
157e43b4 | 4883 | |
eee08903 JN |
4884 | } else { |
4885 | die_error(undef, "Unknown commitdiff format"); | |
4886 | } | |
161332a5 | 4887 | |
11044297 KS |
4888 | # non-textual hash id's can be cached |
4889 | my $expires; | |
4890 | if ($hash =~ m/^[0-9a-fA-F]{40}$/) { | |
4891 | $expires = "+1d"; | |
4892 | } | |
09bd7898 | 4893 | |
eee08903 JN |
4894 | # write commit message |
4895 | if ($format eq 'html') { | |
4896 | my $refs = git_get_references(); | |
4897 | my $ref = format_ref_marker($refs, $co{'id'}); | |
1b1cd421 | 4898 | |
eee08903 JN |
4899 | git_header_html(undef, $expires); |
4900 | git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav); | |
4901 | git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash); | |
6fd92a28 | 4902 | git_print_authorship(\%co); |
eee08903 | 4903 | print "<div class=\"page_body\">\n"; |
82560983 JN |
4904 | if (@{$co{'comment'}} > 1) { |
4905 | print "<div class=\"log\">\n"; | |
4906 | git_print_log($co{'comment'}, -final_empty_line=> 1, -remove_title => 1); | |
4907 | print "</div>\n"; # class="log" | |
4908 | } | |
eee08903 JN |
4909 | |
4910 | } elsif ($format eq 'plain') { | |
4911 | my $refs = git_get_references("tags"); | |
edf735ab | 4912 | my $tagname = git_get_rev_name_tags($hash); |
eee08903 JN |
4913 | my $filename = basename($project) . "-$hash.patch"; |
4914 | ||
4915 | print $cgi->header( | |
4916 | -type => 'text/plain', | |
4917 | -charset => 'utf-8', | |
4918 | -expires => $expires, | |
a2a3bf7b | 4919 | -content_disposition => 'inline; filename="' . "$filename" . '"'); |
eee08903 JN |
4920 | my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'}); |
4921 | print <<TEXT; | |
59b9f61a JN |
4922 | From: $co{'author'} |
4923 | Date: $ad{'rfc2822'} ($ad{'tz_local'}) | |
4924 | Subject: $co{'title'} | |
4925 | TEXT | |
edf735ab | 4926 | print "X-Git-Tag: $tagname\n" if $tagname; |
eee08903 | 4927 | print "X-Git-Url: " . $cgi->self_url() . "\n\n"; |
edf735ab | 4928 | |
eee08903 JN |
4929 | foreach my $line (@{$co{'comment'}}) { |
4930 | print "$line\n"; | |
4931 | } | |
4932 | print "---\n\n"; | |
1b1cd421 | 4933 | } |
1b1cd421 | 4934 | |
eee08903 JN |
4935 | # write patch |
4936 | if ($format eq 'html') { | |
cd030c3a JN |
4937 | my $use_parents = !defined $hash_parent || |
4938 | $hash_parent eq '-c' || $hash_parent eq '--cc'; | |
4939 | git_difftree_body(\@difftree, $hash, | |
4940 | $use_parents ? @{$co{'parents'}} : $hash_parent); | |
b4657e77 | 4941 | print "<br/>\n"; |
1b1cd421 | 4942 | |
cd030c3a JN |
4943 | git_patchset_body($fd, \@difftree, $hash, |
4944 | $use_parents ? @{$co{'parents'}} : $hash_parent); | |
157e43b4 | 4945 | close $fd; |
eee08903 JN |
4946 | print "</div>\n"; # class="page_body" |
4947 | git_footer_html(); | |
4948 | ||
4949 | } elsif ($format eq 'plain') { | |
4950 | local $/ = undef; | |
4951 | print <$fd>; | |
4952 | close $fd | |
4953 | or print "Reading git-diff-tree failed\n"; | |
19806691 KS |
4954 | } |
4955 | } | |
4956 | ||
eee08903 JN |
4957 | sub git_commitdiff_plain { |
4958 | git_commitdiff('plain'); | |
4959 | } | |
4960 | ||
09bd7898 | 4961 | sub git_history { |
c6e1d9ed | 4962 | if (!defined $hash_base) { |
847e01fb | 4963 | $hash_base = git_get_head_hash($project); |
09bd7898 | 4964 | } |
8be68352 JN |
4965 | if (!defined $page) { |
4966 | $page = 0; | |
4967 | } | |
63433106 | 4968 | my $ftype; |
847e01fb | 4969 | my %co = parse_commit($hash_base); |
09bd7898 | 4970 | if (!%co) { |
cac4bd94 | 4971 | die_error(undef, "Unknown commit object"); |
2ae100df | 4972 | } |
8be68352 | 4973 | |
847e01fb | 4974 | my $refs = git_get_references(); |
8be68352 JN |
4975 | my $limit = sprintf("--max-count=%i", (100 * ($page+1))); |
4976 | ||
93d5f061 LT |
4977 | if (!defined $hash && defined $file_name) { |
4978 | $hash = git_get_hash_by_path($hash_base, $file_name); | |
4979 | } | |
cff0771b | 4980 | if (defined $hash) { |
63433106 | 4981 | $ftype = git_get_type($hash); |
cff0771b | 4982 | } |
10dba28d | 4983 | |
a8b983bf | 4984 | my @commitlist = parse_commits($hash_base, 101, (100 * $page), "--full-history", $file_name); |
25691fbe | 4985 | |
8be68352 JN |
4986 | my $paging_nav = ''; |
4987 | if ($page > 0) { | |
4988 | $paging_nav .= | |
4989 | $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, | |
4990 | file_name=>$file_name)}, | |
4991 | "first"); | |
4992 | $paging_nav .= " ⋅ " . | |
4993 | $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, | |
4994 | file_name=>$file_name, page=>$page-1), | |
4995 | -accesskey => "p", -title => "Alt-p"}, "prev"); | |
4996 | } else { | |
4997 | $paging_nav .= "first"; | |
4998 | $paging_nav .= " ⋅ prev"; | |
4999 | } | |
a8b983bf | 5000 | if ($#commitlist >= 100) { |
8be68352 JN |
5001 | $paging_nav .= " ⋅ " . |
5002 | $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, | |
5003 | file_name=>$file_name, page=>$page+1), | |
5004 | -accesskey => "n", -title => "Alt-n"}, "next"); | |
5005 | } else { | |
5006 | $paging_nav .= " ⋅ next"; | |
5007 | } | |
5008 | my $next_link = ''; | |
a8b983bf | 5009 | if ($#commitlist >= 100) { |
8be68352 JN |
5010 | $next_link = |
5011 | $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, | |
5012 | file_name=>$file_name, page=>$page+1), | |
a8b983bf | 5013 | -accesskey => "n", -title => "Alt-n"}, "next"); |
8be68352 JN |
5014 | } |
5015 | ||
5016 | git_header_html(); | |
5017 | git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav); | |
5018 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
5019 | git_print_page_path($file_name, $ftype, $hash_base); | |
5020 | ||
a8b983bf | 5021 | git_history_body(\@commitlist, 0, 99, |
8be68352 | 5022 | $refs, $hash_base, $ftype, $next_link); |
581860e1 | 5023 | |
d51e902a | 5024 | git_footer_html(); |
161332a5 | 5025 | } |
19806691 KS |
5026 | |
5027 | sub git_search { | |
6be93511 RF |
5028 | my ($have_search) = gitweb_check_feature('search'); |
5029 | if (!$have_search) { | |
5030 | die_error('403 Permission denied', "Permission denied"); | |
5031 | } | |
19806691 | 5032 | if (!defined $searchtext) { |
cac4bd94 | 5033 | die_error(undef, "Text field empty"); |
19806691 KS |
5034 | } |
5035 | if (!defined $hash) { | |
847e01fb | 5036 | $hash = git_get_head_hash($project); |
19806691 | 5037 | } |
847e01fb | 5038 | my %co = parse_commit($hash); |
19806691 | 5039 | if (!%co) { |
cac4bd94 | 5040 | die_error(undef, "Unknown commit object"); |
19806691 | 5041 | } |
8dbc0fce RF |
5042 | if (!defined $page) { |
5043 | $page = 0; | |
5044 | } | |
04f7a94f | 5045 | |
88ad729b PB |
5046 | $searchtype ||= 'commit'; |
5047 | if ($searchtype eq 'pickaxe') { | |
04f7a94f JN |
5048 | # pickaxe may take all resources of your box and run for several minutes |
5049 | # with every query - so decide by yourself how public you make this feature | |
5050 | my ($have_pickaxe) = gitweb_check_feature('pickaxe'); | |
5051 | if (!$have_pickaxe) { | |
5052 | die_error('403 Permission denied', "Permission denied"); | |
5053 | } | |
c994d620 | 5054 | } |
e7738553 PB |
5055 | if ($searchtype eq 'grep') { |
5056 | my ($have_grep) = gitweb_check_feature('grep'); | |
5057 | if (!$have_grep) { | |
5058 | die_error('403 Permission denied', "Permission denied"); | |
5059 | } | |
5060 | } | |
88ad729b | 5061 | |
19806691 | 5062 | git_header_html(); |
19806691 | 5063 | |
88ad729b | 5064 | if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') { |
8e574fb5 RF |
5065 | my $greptype; |
5066 | if ($searchtype eq 'commit') { | |
5067 | $greptype = "--grep="; | |
5068 | } elsif ($searchtype eq 'author') { | |
5069 | $greptype = "--author="; | |
5070 | } elsif ($searchtype eq 'committer') { | |
5071 | $greptype = "--committer="; | |
5072 | } | |
7e431ef9 | 5073 | $greptype .= $search_regexp; |
5ad66088 | 5074 | my @commitlist = parse_commits($hash, 101, (100 * $page), $greptype); |
8dbc0fce RF |
5075 | |
5076 | my $paging_nav = ''; | |
5077 | if ($page > 0) { | |
5078 | $paging_nav .= | |
5079 | $cgi->a({-href => href(action=>"search", hash=>$hash, | |
a23f0a73 JN |
5080 | searchtext=>$searchtext, searchtype=>$searchtype)}, |
5081 | "first"); | |
8dbc0fce RF |
5082 | $paging_nav .= " ⋅ " . |
5083 | $cgi->a({-href => href(action=>"search", hash=>$hash, | |
a23f0a73 JN |
5084 | searchtext=>$searchtext, searchtype=>$searchtype, |
5085 | page=>$page-1), | |
5086 | -accesskey => "p", -title => "Alt-p"}, "prev"); | |
8dbc0fce RF |
5087 | } else { |
5088 | $paging_nav .= "first"; | |
5089 | $paging_nav .= " ⋅ prev"; | |
5090 | } | |
5ad66088 | 5091 | if ($#commitlist >= 100) { |
8dbc0fce RF |
5092 | $paging_nav .= " ⋅ " . |
5093 | $cgi->a({-href => href(action=>"search", hash=>$hash, | |
a23f0a73 JN |
5094 | searchtext=>$searchtext, searchtype=>$searchtype, |
5095 | page=>$page+1), | |
5096 | -accesskey => "n", -title => "Alt-n"}, "next"); | |
8dbc0fce RF |
5097 | } else { |
5098 | $paging_nav .= " ⋅ next"; | |
5099 | } | |
5100 | my $next_link = ''; | |
5ad66088 | 5101 | if ($#commitlist >= 100) { |
8dbc0fce RF |
5102 | $next_link = |
5103 | $cgi->a({-href => href(action=>"search", hash=>$hash, | |
a23f0a73 JN |
5104 | searchtext=>$searchtext, searchtype=>$searchtype, |
5105 | page=>$page+1), | |
5106 | -accesskey => "n", -title => "Alt-n"}, "next"); | |
8dbc0fce RF |
5107 | } |
5108 | ||
5109 | git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav); | |
5110 | git_print_header_div('commit', esc_html($co{'title'}), $hash); | |
5ad66088 | 5111 | git_search_grep_body(\@commitlist, 0, 99, $next_link); |
c994d620 KS |
5112 | } |
5113 | ||
88ad729b | 5114 | if ($searchtype eq 'pickaxe') { |
8dbc0fce RF |
5115 | git_print_page_nav('','', $hash,$co{'tree'},$hash); |
5116 | git_print_header_div('commit', esc_html($co{'title'}), $hash); | |
5117 | ||
5118 | print "<table cellspacing=\"0\">\n"; | |
5119 | my $alternate = 1; | |
c994d620 | 5120 | $/ = "\n"; |
25691fbe | 5121 | my $git_command = git_cmd_str(); |
4229aa51 PB |
5122 | my $searchqtext = $searchtext; |
5123 | $searchqtext =~ s/'/'\\''/; | |
25691fbe | 5124 | open my $fd, "-|", "$git_command rev-list $hash | " . |
4229aa51 | 5125 | "$git_command diff-tree -r --stdin -S\'$searchqtext\'"; |
c994d620 KS |
5126 | undef %co; |
5127 | my @files; | |
5128 | while (my $line = <$fd>) { | |
5129 | if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) { | |
5130 | my %set; | |
5131 | $set{'file'} = $6; | |
5132 | $set{'from_id'} = $3; | |
5133 | $set{'to_id'} = $4; | |
5134 | $set{'id'} = $set{'to_id'}; | |
5135 | if ($set{'id'} =~ m/0{40}/) { | |
5136 | $set{'id'} = $set{'from_id'}; | |
19806691 | 5137 | } |
c994d620 KS |
5138 | if ($set{'id'} =~ m/0{40}/) { |
5139 | next; | |
5140 | } | |
5141 | push @files, \%set; | |
53b89d8d | 5142 | } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){ |
c994d620 KS |
5143 | if (%co) { |
5144 | if ($alternate) { | |
5145 | print "<tr class=\"dark\">\n"; | |
5146 | } else { | |
5147 | print "<tr class=\"light\">\n"; | |
5148 | } | |
5149 | $alternate ^= 1; | |
71be1e79 | 5150 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . |
40c13813 | 5151 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" . |
c994d620 | 5152 | "<td>" . |
952c65fc JN |
5153 | $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), |
5154 | -class => "list subject"}, | |
63e4220b | 5155 | esc_html(chop_str($co{'title'}, 50)) . "<br/>"); |
c994d620 KS |
5156 | while (my $setref = shift @files) { |
5157 | my %set = %$setref; | |
952c65fc JN |
5158 | print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'}, |
5159 | hash=>$set{'id'}, file_name=>$set{'file'}), | |
5160 | -class => "list"}, | |
403d0906 | 5161 | "<span class=\"match\">" . esc_path($set{'file'}) . "</span>") . |
c994d620 KS |
5162 | "<br/>\n"; |
5163 | } | |
5164 | print "</td>\n" . | |
5165 | "<td class=\"link\">" . | |
756d2f06 | 5166 | $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") . |
952c65fc JN |
5167 | " | " . |
5168 | $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree"); | |
c994d620 KS |
5169 | print "</td>\n" . |
5170 | "</tr>\n"; | |
5171 | } | |
847e01fb | 5172 | %co = parse_commit($1); |
19806691 | 5173 | } |
19806691 | 5174 | } |
c994d620 | 5175 | close $fd; |
8dbc0fce RF |
5176 | |
5177 | print "</table>\n"; | |
19806691 | 5178 | } |
e7738553 PB |
5179 | |
5180 | if ($searchtype eq 'grep') { | |
5181 | git_print_page_nav('','', $hash,$co{'tree'},$hash); | |
5182 | git_print_header_div('commit', esc_html($co{'title'}), $hash); | |
5183 | ||
5184 | print "<table cellspacing=\"0\">\n"; | |
5185 | my $alternate = 1; | |
5186 | my $matches = 0; | |
5187 | $/ = "\n"; | |
5188 | open my $fd, "-|", git_cmd(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'}; | |
5189 | my $lastfile = ''; | |
5190 | while (my $line = <$fd>) { | |
5191 | chomp $line; | |
5192 | my ($file, $lno, $ltext, $binary); | |
5193 | last if ($matches++ > 1000); | |
5194 | if ($line =~ /^Binary file (.+) matches$/) { | |
5195 | $file = $1; | |
5196 | $binary = 1; | |
5197 | } else { | |
5198 | (undef, $file, $lno, $ltext) = split(/:/, $line, 4); | |
5199 | } | |
5200 | if ($file ne $lastfile) { | |
5201 | $lastfile and print "</td></tr>\n"; | |
5202 | if ($alternate++) { | |
5203 | print "<tr class=\"dark\">\n"; | |
5204 | } else { | |
5205 | print "<tr class=\"light\">\n"; | |
5206 | } | |
5207 | print "<td class=\"list\">". | |
5208 | $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'}, | |
5209 | file_name=>"$file"), | |
5210 | -class => "list"}, esc_path($file)); | |
5211 | print "</td><td>\n"; | |
5212 | $lastfile = $file; | |
5213 | } | |
5214 | if ($binary) { | |
5215 | print "<div class=\"binary\">Binary file</div>\n"; | |
5216 | } else { | |
5217 | $ltext = untabify($ltext); | |
5218 | if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) { | |
5219 | $ltext = esc_html($1, -nbsp=>1); | |
5220 | $ltext .= '<span class="match">'; | |
5221 | $ltext .= esc_html($2, -nbsp=>1); | |
5222 | $ltext .= '</span>'; | |
5223 | $ltext .= esc_html($3, -nbsp=>1); | |
5224 | } else { | |
5225 | $ltext = esc_html($ltext, -nbsp=>1); | |
5226 | } | |
5227 | print "<div class=\"pre\">" . | |
5228 | $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'}, | |
5229 | file_name=>"$file").'#l'.$lno, | |
5230 | -class => "linenr"}, sprintf('%4i', $lno)) | |
5231 | . ' ' . $ltext . "</div>\n"; | |
5232 | } | |
5233 | } | |
5234 | if ($lastfile) { | |
5235 | print "</td></tr>\n"; | |
5236 | if ($matches > 1000) { | |
5237 | print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n"; | |
5238 | } | |
5239 | } else { | |
5240 | print "<div class=\"diff nodifferences\">No matches found</div>\n"; | |
5241 | } | |
5242 | close $fd; | |
5243 | ||
5244 | print "</table>\n"; | |
5245 | } | |
19806691 KS |
5246 | git_footer_html(); |
5247 | } | |
5248 | ||
88ad729b PB |
5249 | sub git_search_help { |
5250 | git_header_html(); | |
5251 | git_print_page_nav('','', $hash,$hash,$hash); | |
5252 | print <<EOT; | |
5253 | <dl> | |
5254 | <dt><b>commit</b></dt> | |
5255 | <dd>The commit messages and authorship information will be scanned for the given string.</dd> | |
e7738553 PB |
5256 | EOT |
5257 | my ($have_grep) = gitweb_check_feature('grep'); | |
5258 | if ($have_grep) { | |
5259 | print <<EOT; | |
5260 | <dt><b>grep</b></dt> | |
5261 | <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing | |
5262 | a different one) are searched for the given | |
5263 | <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> | |
5264 | (POSIX extended) and the matches are listed. On large | |
5265 | trees, this search can take a while and put some strain on the server, so please use it with | |
5266 | some consideration.</dd> | |
5267 | EOT | |
5268 | } | |
5269 | print <<EOT; | |
88ad729b PB |
5270 | <dt><b>author</b></dt> |
5271 | <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd> | |
5272 | <dt><b>committer</b></dt> | |
5273 | <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd> | |
5274 | EOT | |
5275 | my ($have_pickaxe) = gitweb_check_feature('pickaxe'); | |
5276 | if ($have_pickaxe) { | |
5277 | print <<EOT; | |
5278 | <dt><b>pickaxe</b></dt> | |
5279 | <dd>All commits that caused the string to appear or disappear from any file (changes that | |
5280 | added, removed or "modified" the string) will be listed. This search can take a while and | |
5281 | takes a lot of strain on the server, so please use it wisely.</dd> | |
5282 | EOT | |
5283 | } | |
5284 | print "</dl>\n"; | |
5285 | git_footer_html(); | |
5286 | } | |
5287 | ||
19806691 | 5288 | sub git_shortlog { |
847e01fb | 5289 | my $head = git_get_head_hash($project); |
19806691 KS |
5290 | if (!defined $hash) { |
5291 | $hash = $head; | |
5292 | } | |
ea4a6df4 KS |
5293 | if (!defined $page) { |
5294 | $page = 0; | |
5295 | } | |
847e01fb | 5296 | my $refs = git_get_references(); |
ea4a6df4 | 5297 | |
d222984e | 5298 | my @commitlist = parse_commits($hash, 101, (100 * $page)); |
ea4a6df4 | 5299 | |
190d7fdc | 5300 | my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, (100 * ($page+1))); |
9f5dcb81 | 5301 | my $next_link = ''; |
190d7fdc | 5302 | if ($#commitlist >= 100) { |
9f5dcb81 | 5303 | $next_link = |
756d2f06 | 5304 | $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1), |
190d7fdc | 5305 | -accesskey => "n", -title => "Alt-n"}, "next"); |
9f5dcb81 JN |
5306 | } |
5307 | ||
0d83ddc4 | 5308 | git_header_html(); |
847e01fb JN |
5309 | git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav); |
5310 | git_print_header_div('summary', $project); | |
0d83ddc4 | 5311 | |
190d7fdc | 5312 | git_shortlog_body(\@commitlist, 0, 99, $refs, $next_link); |
9f5dcb81 | 5313 | |
19806691 KS |
5314 | git_footer_html(); |
5315 | } | |
717b8311 JN |
5316 | |
5317 | ## ...................................................................... | |
af6feeb2 | 5318 | ## feeds (RSS, Atom; OPML) |
717b8311 | 5319 | |
af6feeb2 JN |
5320 | sub git_feed { |
5321 | my $format = shift || 'atom'; | |
5322 | my ($have_blame) = gitweb_check_feature('blame'); | |
5323 | ||
5324 | # Atom: http://www.atomenabled.org/developers/syndication/ | |
5325 | # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ | |
5326 | if ($format ne 'rss' && $format ne 'atom') { | |
5327 | die_error(undef, "Unknown web feed format"); | |
5328 | } | |
5329 | ||
5330 | # log/feed of current (HEAD) branch, log of given branch, history of file/directory | |
5331 | my $head = $hash || 'HEAD'; | |
33f24330 | 5332 | my @commitlist = parse_commits($head, 150, 0, undef, $file_name); |
af6feeb2 JN |
5333 | |
5334 | my %latest_commit; | |
5335 | my %latest_date; | |
5336 | my $content_type = "application/$format+xml"; | |
5337 | if (defined $cgi->http('HTTP_ACCEPT') && | |
5338 | $cgi->Accept('text/xml') > $cgi->Accept($content_type)) { | |
5339 | # browser (feed reader) prefers text/xml | |
5340 | $content_type = 'text/xml'; | |
5341 | } | |
b6093a5c RF |
5342 | if (defined($commitlist[0])) { |
5343 | %latest_commit = %{$commitlist[0]}; | |
91fd2bf3 | 5344 | %latest_date = parse_date($latest_commit{'author_epoch'}); |
af6feeb2 JN |
5345 | print $cgi->header( |
5346 | -type => $content_type, | |
5347 | -charset => 'utf-8', | |
5348 | -last_modified => $latest_date{'rfc2822'}); | |
5349 | } else { | |
5350 | print $cgi->header( | |
5351 | -type => $content_type, | |
5352 | -charset => 'utf-8'); | |
5353 | } | |
5354 | ||
5355 | # Optimization: skip generating the body if client asks only | |
5356 | # for Last-Modified date. | |
5357 | return if ($cgi->request_method() eq 'HEAD'); | |
5358 | ||
5359 | # header variables | |
5360 | my $title = "$site_name - $project/$action"; | |
5361 | my $feed_type = 'log'; | |
5362 | if (defined $hash) { | |
5363 | $title .= " - '$hash'"; | |
5364 | $feed_type = 'branch log'; | |
5365 | if (defined $file_name) { | |
5366 | $title .= " :: $file_name"; | |
5367 | $feed_type = 'history'; | |
5368 | } | |
5369 | } elsif (defined $file_name) { | |
5370 | $title .= " - $file_name"; | |
5371 | $feed_type = 'history'; | |
5372 | } | |
5373 | $title .= " $feed_type"; | |
5374 | my $descr = git_get_project_description($project); | |
5375 | if (defined $descr) { | |
5376 | $descr = esc_html($descr); | |
5377 | } else { | |
5378 | $descr = "$project " . | |
5379 | ($format eq 'rss' ? 'RSS' : 'Atom') . | |
5380 | " feed"; | |
5381 | } | |
5382 | my $owner = git_get_project_owner($project); | |
5383 | $owner = esc_html($owner); | |
5384 | ||
5385 | #header | |
5386 | my $alt_url; | |
5387 | if (defined $file_name) { | |
5388 | $alt_url = href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name); | |
5389 | } elsif (defined $hash) { | |
5390 | $alt_url = href(-full=>1, action=>"log", hash=>$hash); | |
5391 | } else { | |
5392 | $alt_url = href(-full=>1, action=>"summary"); | |
5393 | } | |
5394 | print qq!<?xml version="1.0" encoding="utf-8"?>\n!; | |
5395 | if ($format eq 'rss') { | |
5396 | print <<XML; | |
59b9f61a JN |
5397 | <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"> |
5398 | <channel> | |
59b9f61a | 5399 | XML |
af6feeb2 JN |
5400 | print "<title>$title</title>\n" . |
5401 | "<link>$alt_url</link>\n" . | |
5402 | "<description>$descr</description>\n" . | |
5403 | "<language>en</language>\n"; | |
5404 | } elsif ($format eq 'atom') { | |
5405 | print <<XML; | |
5406 | <feed xmlns="http://www.w3.org/2005/Atom"> | |
5407 | XML | |
5408 | print "<title>$title</title>\n" . | |
5409 | "<subtitle>$descr</subtitle>\n" . | |
5410 | '<link rel="alternate" type="text/html" href="' . | |
5411 | $alt_url . '" />' . "\n" . | |
5412 | '<link rel="self" type="' . $content_type . '" href="' . | |
5413 | $cgi->self_url() . '" />' . "\n" . | |
5414 | "<id>" . href(-full=>1) . "</id>\n" . | |
5415 | # use project owner for feed author | |
5416 | "<author><name>$owner</name></author>\n"; | |
5417 | if (defined $favicon) { | |
5418 | print "<icon>" . esc_url($favicon) . "</icon>\n"; | |
5419 | } | |
5420 | if (defined $logo_url) { | |
5421 | # not twice as wide as tall: 72 x 27 pixels | |
e1147267 | 5422 | print "<logo>" . esc_url($logo) . "</logo>\n"; |
af6feeb2 JN |
5423 | } |
5424 | if (! %latest_date) { | |
5425 | # dummy date to keep the feed valid until commits trickle in: | |
5426 | print "<updated>1970-01-01T00:00:00Z</updated>\n"; | |
5427 | } else { | |
5428 | print "<updated>$latest_date{'iso-8601'}</updated>\n"; | |
5429 | } | |
5430 | } | |
717b8311 | 5431 | |
af6feeb2 | 5432 | # contents |
b6093a5c RF |
5433 | for (my $i = 0; $i <= $#commitlist; $i++) { |
5434 | my %co = %{$commitlist[$i]}; | |
5435 | my $commit = $co{'id'}; | |
717b8311 | 5436 | # we read 150, we always show 30 and the ones more recent than 48 hours |
91fd2bf3 | 5437 | if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) { |
717b8311 JN |
5438 | last; |
5439 | } | |
91fd2bf3 | 5440 | my %cd = parse_date($co{'author_epoch'}); |
af6feeb2 JN |
5441 | |
5442 | # get list of changed files | |
b6093a5c | 5443 | open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
c906b181 JN |
5444 | $co{'parent'} || "--root", |
5445 | $co{'id'}, "--", (defined $file_name ? $file_name : ()) | |
6bcf4b46 | 5446 | or next; |
717b8311 | 5447 | my @difftree = map { chomp; $_ } <$fd>; |
6bcf4b46 JN |
5448 | close $fd |
5449 | or next; | |
af6feeb2 JN |
5450 | |
5451 | # print element (entry, item) | |
5452 | my $co_url = href(-full=>1, action=>"commit", hash=>$commit); | |
5453 | if ($format eq 'rss') { | |
5454 | print "<item>\n" . | |
5455 | "<title>" . esc_html($co{'title'}) . "</title>\n" . | |
5456 | "<author>" . esc_html($co{'author'}) . "</author>\n" . | |
5457 | "<pubDate>$cd{'rfc2822'}</pubDate>\n" . | |
5458 | "<guid isPermaLink=\"true\">$co_url</guid>\n" . | |
5459 | "<link>$co_url</link>\n" . | |
5460 | "<description>" . esc_html($co{'title'}) . "</description>\n" . | |
5461 | "<content:encoded>" . | |
5462 | "<![CDATA[\n"; | |
5463 | } elsif ($format eq 'atom') { | |
5464 | print "<entry>\n" . | |
5465 | "<title type=\"html\">" . esc_html($co{'title'}) . "</title>\n" . | |
5466 | "<updated>$cd{'iso-8601'}</updated>\n" . | |
ab23c19d JN |
5467 | "<author>\n" . |
5468 | " <name>" . esc_html($co{'author_name'}) . "</name>\n"; | |
5469 | if ($co{'author_email'}) { | |
5470 | print " <email>" . esc_html($co{'author_email'}) . "</email>\n"; | |
5471 | } | |
5472 | print "</author>\n" . | |
af6feeb2 | 5473 | # use committer for contributor |
ab23c19d JN |
5474 | "<contributor>\n" . |
5475 | " <name>" . esc_html($co{'committer_name'}) . "</name>\n"; | |
5476 | if ($co{'committer_email'}) { | |
5477 | print " <email>" . esc_html($co{'committer_email'}) . "</email>\n"; | |
5478 | } | |
5479 | print "</contributor>\n" . | |
af6feeb2 JN |
5480 | "<published>$cd{'iso-8601'}</published>\n" . |
5481 | "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" . | |
5482 | "<id>$co_url</id>\n" . | |
5483 | "<content type=\"xhtml\" xml:base=\"" . esc_url($my_url) . "\">\n" . | |
5484 | "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n"; | |
5485 | } | |
717b8311 | 5486 | my $comment = $co{'comment'}; |
af6feeb2 | 5487 | print "<pre>\n"; |
717b8311 | 5488 | foreach my $line (@$comment) { |
af6feeb2 JN |
5489 | $line = esc_html($line); |
5490 | print "$line\n"; | |
717b8311 | 5491 | } |
af6feeb2 JN |
5492 | print "</pre><ul>\n"; |
5493 | foreach my $difftree_line (@difftree) { | |
5494 | my %difftree = parse_difftree_raw_line($difftree_line); | |
5495 | next if !$difftree{'from_id'}; | |
5496 | ||
5497 | my $file = $difftree{'file'} || $difftree{'to_file'}; | |
5498 | ||
5499 | print "<li>" . | |
5500 | "[" . | |
5501 | $cgi->a({-href => href(-full=>1, action=>"blobdiff", | |
5502 | hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'}, | |
5503 | hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'}, | |
5504 | file_name=>$file, file_parent=>$difftree{'from_file'}), | |
5505 | -title => "diff"}, 'D'); | |
5506 | if ($have_blame) { | |
5507 | print $cgi->a({-href => href(-full=>1, action=>"blame", | |
5508 | file_name=>$file, hash_base=>$commit), | |
5509 | -title => "blame"}, 'B'); | |
717b8311 | 5510 | } |
af6feeb2 JN |
5511 | # if this is not a feed of a file history |
5512 | if (!defined $file_name || $file_name ne $file) { | |
5513 | print $cgi->a({-href => href(-full=>1, action=>"history", | |
5514 | file_name=>$file, hash=>$commit), | |
5515 | -title => "history"}, 'H'); | |
5516 | } | |
5517 | $file = esc_path($file); | |
5518 | print "] ". | |
5519 | "$file</li>\n"; | |
5520 | } | |
5521 | if ($format eq 'rss') { | |
5522 | print "</ul>]]>\n" . | |
5523 | "</content:encoded>\n" . | |
5524 | "</item>\n"; | |
5525 | } elsif ($format eq 'atom') { | |
5526 | print "</ul>\n</div>\n" . | |
5527 | "</content>\n" . | |
5528 | "</entry>\n"; | |
717b8311 | 5529 | } |
717b8311 | 5530 | } |
af6feeb2 JN |
5531 | |
5532 | # end of feed | |
5533 | if ($format eq 'rss') { | |
5534 | print "</channel>\n</rss>\n"; | |
5535 | } elsif ($format eq 'atom') { | |
5536 | print "</feed>\n"; | |
5537 | } | |
5538 | } | |
5539 | ||
5540 | sub git_rss { | |
5541 | git_feed('rss'); | |
5542 | } | |
5543 | ||
5544 | sub git_atom { | |
5545 | git_feed('atom'); | |
717b8311 JN |
5546 | } |
5547 | ||
5548 | sub git_opml { | |
847e01fb | 5549 | my @list = git_get_projects_list(); |
717b8311 JN |
5550 | |
5551 | print $cgi->header(-type => 'text/xml', -charset => 'utf-8'); | |
59b9f61a JN |
5552 | print <<XML; |
5553 | <?xml version="1.0" encoding="utf-8"?> | |
5554 | <opml version="1.0"> | |
5555 | <head> | |
8be2890c | 5556 | <title>$site_name OPML Export</title> |
59b9f61a JN |
5557 | </head> |
5558 | <body> | |
5559 | <outline text="git RSS feeds"> | |
5560 | XML | |
717b8311 JN |
5561 | |
5562 | foreach my $pr (@list) { | |
5563 | my %proj = %$pr; | |
847e01fb | 5564 | my $head = git_get_head_hash($proj{'path'}); |
717b8311 JN |
5565 | if (!defined $head) { |
5566 | next; | |
5567 | } | |
25691fbe | 5568 | $git_dir = "$projectroot/$proj{'path'}"; |
847e01fb | 5569 | my %co = parse_commit($head); |
717b8311 JN |
5570 | if (!%co) { |
5571 | next; | |
5572 | } | |
5573 | ||
5574 | my $path = esc_html(chop_str($proj{'path'}, 25, 5)); | |
5575 | my $rss = "$my_url?p=$proj{'path'};a=rss"; | |
5576 | my $html = "$my_url?p=$proj{'path'};a=summary"; | |
5577 | print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n"; | |
5578 | } | |
59b9f61a JN |
5579 | print <<XML; |
5580 | </outline> | |
5581 | </body> | |
5582 | </opml> | |
5583 | XML | |
717b8311 | 5584 | } |