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