]>
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 | |
4a87b43e | 21 | our $cgi = new CGI; |
06c084d2 | 22 | our $version = "++GIT_VERSION++"; |
4a87b43e DS |
23 | our $my_url = $cgi->url(); |
24 | our $my_uri = $cgi->url(-absolute => 1); | |
3e029299 | 25 | |
e130ddaa AT |
26 | # core git executable to use |
27 | # this can just be "git" if your webserver has a sensible PATH | |
06c084d2 | 28 | our $GIT = "++GIT_BINDIR++/git"; |
3f7f2710 | 29 | |
b87d78d6 | 30 | # absolute fs-path which will be prepended to the project path |
4a87b43e | 31 | #our $projectroot = "/pub/scm"; |
06c084d2 | 32 | our $projectroot = "++GITWEB_PROJECTROOT++"; |
b87d78d6 | 33 | |
b87d78d6 | 34 | # target of the home link on top of all pages |
6132b7e4 | 35 | our $home_link = $my_uri || "/"; |
b87d78d6 | 36 | |
2de21fac YS |
37 | # string of the home link on top of all pages |
38 | our $home_link_str = "++GITWEB_HOME_LINK_STR++"; | |
39 | ||
49da1daf AT |
40 | # name of your site or organization to appear in page titles |
41 | # replace this with something more descriptive for clearer bookmarks | |
06c084d2 | 42 | our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled"; |
49da1daf | 43 | |
b2d3476e AC |
44 | # filename of html text to include at top of each page |
45 | our $site_header = "++GITWEB_SITE_HEADER++"; | |
8ab1da2c | 46 | # html text to include at home page |
06c084d2 | 47 | our $home_text = "++GITWEB_HOMETEXT++"; |
b2d3476e AC |
48 | # filename of html text to include at bottom of each page |
49 | our $site_footer = "++GITWEB_SITE_FOOTER++"; | |
50 | ||
51 | # URI of stylesheets | |
52 | our @stylesheets = ("++GITWEB_CSS++"); | |
53 | our $stylesheet; | |
54 | # default is not to define style sheet, but it can be overwritten later | |
55 | undef $stylesheet; | |
8ab1da2c | 56 | |
aedd9425 | 57 | # URI of default stylesheet |
06c084d2 | 58 | our $stylesheet = "++GITWEB_CSS++"; |
9a7a62ff | 59 | # URI of GIT logo (72x27 size) |
06c084d2 | 60 | our $logo = "++GITWEB_LOGO++"; |
0b5deba1 JN |
61 | # URI of GIT favicon, assumed to be image/png type |
62 | our $favicon = "++GITWEB_FAVICON++"; | |
aedd9425 | 63 | |
9a7a62ff JN |
64 | # URI and label (title) of GIT logo link |
65 | #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; | |
66 | #our $logo_label = "git documentation"; | |
67 | our $logo_url = "http://git.or.cz/"; | |
68 | our $logo_label = "git homepage"; | |
51a7c66a | 69 | |
09bd7898 | 70 | # source of projects list |
06c084d2 | 71 | our $projects_list = "++GITWEB_LIST++"; |
b87d78d6 | 72 | |
32f4aacc ML |
73 | # show repository only if this file exists |
74 | # (only effective if this variable evaluates to true) | |
75 | our $export_ok = "++GITWEB_EXPORT_OK++"; | |
76 | ||
77 | # only allow viewing of repositories also shown on the overview page | |
78 | our $strict_export = "++GITWEB_STRICT_EXPORT++"; | |
79 | ||
19a8721e JN |
80 | # list of git base URLs used for URL to where fetch project from, |
81 | # i.e. full URL is "$git_base_url/$project" | |
82 | our @git_base_url_list = ("++GITWEB_BASE_URL++"); | |
83 | ||
f5aa79d9 | 84 | # default blob_plain mimetype and default charset for text/plain blob |
4a87b43e DS |
85 | our $default_blob_plain_mimetype = 'text/plain'; |
86 | our $default_text_plain_charset = undef; | |
f5aa79d9 | 87 | |
2d007374 PB |
88 | # file to use for guessing MIME types before trying /etc/mime.types |
89 | # (relative to the current git repository) | |
4a87b43e | 90 | our $mimetypes_file = undef; |
2d007374 | 91 | |
ddb8d900 AK |
92 | # You define site-wide feature defaults here; override them with |
93 | # $GITWEB_CONFIG as necessary. | |
952c65fc | 94 | our %feature = ( |
17848fc6 JN |
95 | # feature => { |
96 | # 'sub' => feature-sub (subroutine), | |
97 | # 'override' => allow-override (boolean), | |
98 | # 'default' => [ default options...] (array reference)} | |
99 | # | |
100 | # if feature is overridable (it means that allow-override has true value, | |
101 | # then feature-sub will be called with default options as parameters; | |
102 | # return value of feature-sub indicates if to enable specified feature | |
103 | # | |
104 | # use gitweb_check_feature(<feature>) to check if <feature> is enabled | |
952c65fc | 105 | |
45a3b12c PB |
106 | # Enable the 'blame' blob view, showing the last commit that modified |
107 | # each line in the file. This can be very CPU-intensive. | |
108 | ||
109 | # To enable system wide have in $GITWEB_CONFIG | |
110 | # $feature{'blame'}{'default'} = [1]; | |
111 | # To have project specific config enable override in $GITWEB_CONFIG | |
112 | # $feature{'blame'}{'override'} = 1; | |
113 | # and in project config gitweb.blame = 0|1; | |
952c65fc JN |
114 | 'blame' => { |
115 | 'sub' => \&feature_blame, | |
116 | 'override' => 0, | |
117 | 'default' => [0]}, | |
118 | ||
45a3b12c PB |
119 | # Enable the 'snapshot' link, providing a compressed tarball of any |
120 | # tree. This can potentially generate high traffic if you have large | |
121 | # project. | |
122 | ||
123 | # To disable system wide have in $GITWEB_CONFIG | |
124 | # $feature{'snapshot'}{'default'} = [undef]; | |
125 | # To have project specific config enable override in $GITWEB_CONFIG | |
126 | # $feature{'blame'}{'override'} = 1; | |
127 | # and in project config gitweb.snapshot = none|gzip|bzip2; | |
952c65fc JN |
128 | 'snapshot' => { |
129 | 'sub' => \&feature_snapshot, | |
130 | 'override' => 0, | |
131 | # => [content-encoding, suffix, program] | |
132 | 'default' => ['x-gzip', 'gz', 'gzip']}, | |
04f7a94f | 133 | |
45a3b12c PB |
134 | # Enable the pickaxe search, which will list the commits that modified |
135 | # a given string in a file. This can be practical and quite faster | |
136 | # alternative to 'blame', but still potentially CPU-intensive. | |
137 | ||
138 | # To enable system wide have in $GITWEB_CONFIG | |
139 | # $feature{'pickaxe'}{'default'} = [1]; | |
140 | # To have project specific config enable override in $GITWEB_CONFIG | |
141 | # $feature{'pickaxe'}{'override'} = 1; | |
142 | # and in project config gitweb.pickaxe = 0|1; | |
04f7a94f JN |
143 | 'pickaxe' => { |
144 | 'sub' => \&feature_pickaxe, | |
145 | 'override' => 0, | |
146 | 'default' => [1]}, | |
9e756904 | 147 | |
45a3b12c PB |
148 | # Make gitweb use an alternative format of the URLs which can be |
149 | # more readable and natural-looking: project name is embedded | |
150 | # directly in the path and the query string contains other | |
151 | # auxiliary information. All gitweb installations recognize | |
152 | # URL in either format; this configures in which formats gitweb | |
153 | # generates links. | |
154 | ||
155 | # To enable system wide have in $GITWEB_CONFIG | |
156 | # $feature{'pathinfo'}{'default'} = [1]; | |
157 | # Project specific override is not supported. | |
158 | ||
159 | # Note that you will need to change the default location of CSS, | |
160 | # favicon, logo and possibly other files to an absolute URL. Also, | |
161 | # if gitweb.cgi serves as your indexfile, you will need to force | |
162 | # $my_uri to contain the script name in your $GITWEB_CONFIG. | |
9e756904 MW |
163 | 'pathinfo' => { |
164 | 'override' => 0, | |
165 | 'default' => [0]}, | |
ddb8d900 AK |
166 | ); |
167 | ||
168 | sub gitweb_check_feature { | |
169 | my ($name) = @_; | |
dd1ad5f1 | 170 | return unless exists $feature{$name}; |
952c65fc JN |
171 | my ($sub, $override, @defaults) = ( |
172 | $feature{$name}{'sub'}, | |
173 | $feature{$name}{'override'}, | |
174 | @{$feature{$name}{'default'}}); | |
ddb8d900 | 175 | if (!$override) { return @defaults; } |
a9455919 MW |
176 | if (!defined $sub) { |
177 | warn "feature $name is not overrideable"; | |
178 | return @defaults; | |
179 | } | |
ddb8d900 AK |
180 | return $sub->(@defaults); |
181 | } | |
182 | ||
ddb8d900 AK |
183 | sub feature_blame { |
184 | my ($val) = git_get_project_config('blame', '--bool'); | |
185 | ||
186 | if ($val eq 'true') { | |
187 | return 1; | |
188 | } elsif ($val eq 'false') { | |
189 | return 0; | |
190 | } | |
191 | ||
192 | return $_[0]; | |
193 | } | |
194 | ||
ddb8d900 AK |
195 | sub feature_snapshot { |
196 | my ($ctype, $suffix, $command) = @_; | |
197 | ||
198 | my ($val) = git_get_project_config('snapshot'); | |
199 | ||
200 | if ($val eq 'gzip') { | |
201 | return ('x-gzip', 'gz', 'gzip'); | |
202 | } elsif ($val eq 'bzip2') { | |
203 | return ('x-bzip2', 'bz2', 'bzip2'); | |
204 | } elsif ($val eq 'none') { | |
205 | return (); | |
206 | } | |
207 | ||
208 | return ($ctype, $suffix, $command); | |
209 | } | |
210 | ||
de9272f4 LT |
211 | sub gitweb_have_snapshot { |
212 | my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot'); | |
213 | my $have_snapshot = (defined $ctype && defined $suffix); | |
214 | ||
215 | return $have_snapshot; | |
216 | } | |
217 | ||
04f7a94f JN |
218 | sub feature_pickaxe { |
219 | my ($val) = git_get_project_config('pickaxe', '--bool'); | |
220 | ||
221 | if ($val eq 'true') { | |
222 | return (1); | |
223 | } elsif ($val eq 'false') { | |
224 | return (0); | |
225 | } | |
226 | ||
227 | return ($_[0]); | |
228 | } | |
229 | ||
2172ce4b JH |
230 | # checking HEAD file with -e is fragile if the repository was |
231 | # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed | |
232 | # and then pruned. | |
233 | sub check_head_link { | |
234 | my ($dir) = @_; | |
235 | my $headfile = "$dir/HEAD"; | |
236 | return ((-e $headfile) || | |
237 | (-l $headfile && readlink($headfile) =~ /^refs\/heads\//)); | |
238 | } | |
239 | ||
240 | sub check_export_ok { | |
241 | my ($dir) = @_; | |
242 | return (check_head_link($dir) && | |
243 | (!$export_ok || -e "$dir/$export_ok")); | |
244 | } | |
245 | ||
6bcf4b46 JN |
246 | # rename detection options for git-diff and git-diff-tree |
247 | # - default is '-M', with the cost proportional to | |
248 | # (number of removed files) * (number of new files). | |
249 | # - more costly is '-C' (or '-C', '-M'), with the cost proportional to | |
250 | # (number of changed files + number of removed files) * (number of new files) | |
251 | # - even more costly is '-C', '--find-copies-harder' with cost | |
252 | # (number of files in the original tree) * (number of new files) | |
253 | # - one might want to include '-B' option, e.g. '-B', '-M' | |
254 | our @diff_opts = ('-M'); # taken from git_commit | |
255 | ||
06c084d2 | 256 | our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++"; |
4b5dc988 | 257 | do $GITWEB_CONFIG if -e $GITWEB_CONFIG; |
c8d138a8 JK |
258 | |
259 | # version of the core git binary | |
260 | our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown"; | |
261 | ||
262 | $projects_list ||= $projectroot; | |
c8d138a8 | 263 | |
154b4d78 | 264 | # ====================================================================== |
09bd7898 | 265 | # input validation and dispatch |
4a87b43e | 266 | our $action = $cgi->param('a'); |
09bd7898 | 267 | if (defined $action) { |
c91da262 | 268 | if ($action =~ m/[^0-9a-zA-Z\.\-_]/) { |
cac4bd94 | 269 | die_error(undef, "Invalid action parameter"); |
b87d78d6 | 270 | } |
b87d78d6 | 271 | } |
44ad2978 | 272 | |
24d0693a | 273 | # parameters which are pathnames |
dd70235f | 274 | our $project = $cgi->param('p'); |
13d02165 | 275 | if (defined $project) { |
24d0693a | 276 | if (!validate_pathname($project) || |
7939fe44 | 277 | !(-d "$projectroot/$project") || |
2172ce4b | 278 | !check_head_link("$projectroot/$project") || |
32f4aacc ML |
279 | ($export_ok && !(-e "$projectroot/$project/$export_ok")) || |
280 | ($strict_export && !project_in_list($project))) { | |
7939fe44 | 281 | undef $project; |
cac4bd94 | 282 | die_error(undef, "No such project"); |
9cd3d988 | 283 | } |
a59d4afd | 284 | } |
6191f8e1 | 285 | |
4a87b43e | 286 | our $file_name = $cgi->param('f'); |
24d0693a JN |
287 | if (defined $file_name) { |
288 | if (!validate_pathname($file_name)) { | |
289 | die_error(undef, "Invalid file parameter"); | |
290 | } | |
291 | } | |
292 | ||
5c95fab0 | 293 | our $file_parent = $cgi->param('fp'); |
24d0693a JN |
294 | if (defined $file_parent) { |
295 | if (!validate_pathname($file_parent)) { | |
296 | die_error(undef, "Invalid file parent parameter"); | |
297 | } | |
298 | } | |
5c95fab0 | 299 | |
24d0693a | 300 | # parameters which are refnames |
4a87b43e | 301 | our $hash = $cgi->param('h'); |
4fac5294 | 302 | if (defined $hash) { |
24d0693a | 303 | if (!validate_refname($hash)) { |
cac4bd94 | 304 | die_error(undef, "Invalid hash parameter"); |
4fac5294 | 305 | } |
a59d4afd | 306 | } |
6191f8e1 | 307 | |
4a87b43e | 308 | our $hash_parent = $cgi->param('hp'); |
c91da262 | 309 | if (defined $hash_parent) { |
24d0693a | 310 | if (!validate_refname($hash_parent)) { |
cac4bd94 | 311 | die_error(undef, "Invalid hash parent parameter"); |
c91da262 | 312 | } |
09bd7898 KS |
313 | } |
314 | ||
4a87b43e | 315 | our $hash_base = $cgi->param('hb'); |
c91da262 | 316 | if (defined $hash_base) { |
24d0693a | 317 | if (!validate_refname($hash_base)) { |
cac4bd94 | 318 | die_error(undef, "Invalid hash base parameter"); |
c91da262 | 319 | } |
a59d4afd | 320 | } |
6191f8e1 | 321 | |
420e92f2 JN |
322 | our $hash_parent_base = $cgi->param('hpb'); |
323 | if (defined $hash_parent_base) { | |
24d0693a | 324 | if (!validate_refname($hash_parent_base)) { |
420e92f2 JN |
325 | die_error(undef, "Invalid hash parent base parameter"); |
326 | } | |
327 | } | |
328 | ||
24d0693a | 329 | # other parameters |
4a87b43e | 330 | our $page = $cgi->param('pg'); |
ea4a6df4 | 331 | if (defined $page) { |
ac8e3f2b | 332 | if ($page =~ m/[^0-9]/) { |
cac4bd94 | 333 | die_error(undef, "Invalid page parameter"); |
b87d78d6 | 334 | } |
2ad9331e | 335 | } |
823d5dc8 | 336 | |
4a87b43e | 337 | our $searchtext = $cgi->param('s'); |
19806691 KS |
338 | if (defined $searchtext) { |
339 | if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) { | |
cac4bd94 | 340 | die_error(undef, "Invalid search parameter"); |
19806691 KS |
341 | } |
342 | $searchtext = quotemeta $searchtext; | |
343 | } | |
344 | ||
dd70235f | 345 | # now read PATH_INFO and use it as alternative to parameters |
645927ce ML |
346 | sub evaluate_path_info { |
347 | return if defined $project; | |
348 | my $path_info = $ENV{"PATH_INFO"}; | |
349 | return if !$path_info; | |
cd90e75f | 350 | $path_info =~ s,^/+,,; |
645927ce | 351 | return if !$path_info; |
cd90e75f | 352 | # find which part of PATH_INFO is project |
dd70235f | 353 | $project = $path_info; |
cd90e75f | 354 | $project =~ s,/+$,,; |
2172ce4b | 355 | while ($project && !check_head_link("$projectroot/$project")) { |
dd70235f MW |
356 | $project =~ s,/*[^/]*$,,; |
357 | } | |
cd90e75f | 358 | # validate project |
24d0693a | 359 | $project = validate_pathname($project); |
645927ce ML |
360 | if (!$project || |
361 | ($export_ok && !-e "$projectroot/$project/$export_ok") || | |
362 | ($strict_export && !project_in_list($project))) { | |
363 | undef $project; | |
364 | return; | |
dd70235f | 365 | } |
645927ce ML |
366 | # do not change any parameters if an action is given using the query string |
367 | return if $action; | |
cd90e75f JN |
368 | $path_info =~ s,^$project/*,,; |
369 | my ($refname, $pathname) = split(/:/, $path_info, 2); | |
370 | if (defined $pathname) { | |
371 | # we got "project.git/branch:filename" or "project.git/branch:dir/" | |
372 | # we could use git_get_type(branch:pathname), but it needs $git_dir | |
373 | $pathname =~ s,^/+,,; | |
374 | if (!$pathname || substr($pathname, -1) eq "/") { | |
375 | $action ||= "tree"; | |
053d62bb | 376 | $pathname =~ s,/$,,; |
cd90e75f JN |
377 | } else { |
378 | $action ||= "blob_plain"; | |
379 | } | |
24d0693a JN |
380 | $hash_base ||= validate_refname($refname); |
381 | $file_name ||= validate_pathname($pathname); | |
cd90e75f | 382 | } elsif (defined $refname) { |
dd70235f MW |
383 | # we got "project.git/branch" |
384 | $action ||= "shortlog"; | |
24d0693a | 385 | $hash ||= validate_refname($refname); |
dd70235f MW |
386 | } |
387 | } | |
645927ce | 388 | evaluate_path_info(); |
dd70235f | 389 | |
645927ce ML |
390 | # path to the current git repository |
391 | our $git_dir; | |
392 | $git_dir = "$projectroot/$project" if $project; | |
dd70235f | 393 | |
717b8311 | 394 | # dispatch |
8e85cdc4 ML |
395 | my %actions = ( |
396 | "blame" => \&git_blame2, | |
397 | "blobdiff" => \&git_blobdiff, | |
398 | "blobdiff_plain" => \&git_blobdiff_plain, | |
399 | "blob" => \&git_blob, | |
400 | "blob_plain" => \&git_blob_plain, | |
401 | "commitdiff" => \&git_commitdiff, | |
402 | "commitdiff_plain" => \&git_commitdiff_plain, | |
403 | "commit" => \&git_commit, | |
404 | "heads" => \&git_heads, | |
405 | "history" => \&git_history, | |
406 | "log" => \&git_log, | |
407 | "rss" => \&git_rss, | |
408 | "search" => \&git_search, | |
409 | "shortlog" => \&git_shortlog, | |
410 | "summary" => \&git_summary, | |
411 | "tag" => \&git_tag, | |
412 | "tags" => \&git_tags, | |
413 | "tree" => \&git_tree, | |
cb9c6e5b | 414 | "snapshot" => \&git_snapshot, |
77a153fd JN |
415 | # those below don't need $project |
416 | "opml" => \&git_opml, | |
417 | "project_list" => \&git_project_list, | |
fc2b2be0 | 418 | "project_index" => \&git_project_index, |
8e85cdc4 ML |
419 | ); |
420 | ||
77a153fd JN |
421 | if (defined $project) { |
422 | $action ||= 'summary'; | |
423 | } else { | |
424 | $action ||= 'project_list'; | |
425 | } | |
8e85cdc4 | 426 | if (!defined($actions{$action})) { |
cac4bd94 | 427 | die_error(undef, "Unknown action"); |
09bd7898 | 428 | } |
d04d3d42 JN |
429 | if ($action !~ m/^(opml|project_list|project_index)$/ && |
430 | !$project) { | |
431 | die_error(undef, "Project needed"); | |
432 | } | |
8e85cdc4 ML |
433 | $actions{$action}->(); |
434 | exit; | |
09bd7898 | 435 | |
06a9d86b MW |
436 | ## ====================================================================== |
437 | ## action links | |
438 | ||
439 | sub href(%) { | |
498fe002 | 440 | my %params = @_; |
9e756904 | 441 | my $href = $my_uri; |
498fe002 | 442 | |
34c06118 PB |
443 | # XXX: Warning: If you touch this, check the search form for updating, |
444 | # too. | |
498fe002 JN |
445 | |
446 | my @mapping = ( | |
06a9d86b | 447 | project => "p", |
420e92f2 | 448 | action => "a", |
06a9d86b | 449 | file_name => "f", |
5c95fab0 | 450 | file_parent => "fp", |
06a9d86b MW |
451 | hash => "h", |
452 | hash_parent => "hp", | |
453 | hash_base => "hb", | |
420e92f2 | 454 | hash_parent_base => "hpb", |
06a9d86b | 455 | page => "pg", |
a1565c44 | 456 | order => "o", |
06a9d86b MW |
457 | searchtext => "s", |
458 | ); | |
498fe002 | 459 | my %mapping = @mapping; |
06a9d86b | 460 | |
a1565c44 | 461 | $params{'project'} = $project unless exists $params{'project'}; |
06a9d86b | 462 | |
9e756904 MW |
463 | my ($use_pathinfo) = gitweb_check_feature('pathinfo'); |
464 | if ($use_pathinfo) { | |
465 | # use PATH_INFO for project name | |
466 | $href .= "/$params{'project'}" if defined $params{'project'}; | |
467 | delete $params{'project'}; | |
468 | ||
469 | # Summary just uses the project path URL | |
470 | if (defined $params{'action'} && $params{'action'} eq 'summary') { | |
471 | delete $params{'action'}; | |
472 | } | |
473 | } | |
474 | ||
475 | # now encode the parameters explicitly | |
498fe002 JN |
476 | my @result = (); |
477 | for (my $i = 0; $i < @mapping; $i += 2) { | |
478 | my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]); | |
479 | if (defined $params{$name}) { | |
480 | push @result, $symbol . "=" . esc_param($params{$name}); | |
481 | } | |
482 | } | |
9e756904 MW |
483 | $href .= "?" . join(';', @result) if scalar @result; |
484 | ||
485 | return $href; | |
06a9d86b MW |
486 | } |
487 | ||
488 | ||
717b8311 JN |
489 | ## ====================================================================== |
490 | ## validation, quoting/unquoting and escaping | |
491 | ||
24d0693a JN |
492 | sub validate_pathname { |
493 | my $input = shift || return undef; | |
717b8311 | 494 | |
24d0693a JN |
495 | # no '.' or '..' as elements of path, i.e. no '.' nor '..' |
496 | # at the beginning, at the end, and between slashes. | |
497 | # also this catches doubled slashes | |
498 | if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) { | |
499 | return undef; | |
717b8311 | 500 | } |
24d0693a JN |
501 | # no null characters |
502 | if ($input =~ m!\0!) { | |
717b8311 JN |
503 | return undef; |
504 | } | |
24d0693a JN |
505 | return $input; |
506 | } | |
507 | ||
508 | sub validate_refname { | |
509 | my $input = shift || return undef; | |
510 | ||
511 | # textual hashes are O.K. | |
512 | if ($input =~ m/^[0-9a-fA-F]{40}$/) { | |
513 | return $input; | |
514 | } | |
515 | # it must be correct pathname | |
516 | $input = validate_pathname($input) | |
517 | or return undef; | |
518 | # restrictions on ref name according to git-check-ref-format | |
519 | if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) { | |
717b8311 JN |
520 | return undef; |
521 | } | |
522 | return $input; | |
523 | } | |
524 | ||
847abc0f YS |
525 | # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT); |
526 | sub to_utf8 { | |
527 | my $str = shift; | |
528 | return decode("utf8", $str, Encode::FB_DEFAULT); | |
529 | } | |
530 | ||
232ff553 KS |
531 | # quote unsafe chars, but keep the slash, even when it's not |
532 | # correct, but quoted slashes look too horrible in bookmarks | |
533 | sub esc_param { | |
353347b0 | 534 | my $str = shift; |
a2f3db2f | 535 | $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X", ord($1))/eg; |
18216710 | 536 | $str =~ s/\+/%2B/g; |
a9e60b7d | 537 | $str =~ s/ /\+/g; |
353347b0 KS |
538 | return $str; |
539 | } | |
540 | ||
f93bff8d JN |
541 | # quote unsafe chars in whole URL, so some charactrs cannot be quoted |
542 | sub esc_url { | |
543 | my $str = shift; | |
544 | $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg; | |
545 | $str =~ s/\+/%2B/g; | |
546 | $str =~ s/ /\+/g; | |
547 | return $str; | |
548 | } | |
549 | ||
232ff553 | 550 | # replace invalid utf8 character with SUBSTITUTION sequence |
40c13813 KS |
551 | sub esc_html { |
552 | my $str = shift; | |
847abc0f | 553 | $str = to_utf8($str); |
10bb9036 | 554 | $str = escapeHTML($str); |
3dc13832 | 555 | $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file) |
e70866f5 | 556 | $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1) |
40c13813 KS |
557 | return $str; |
558 | } | |
559 | ||
232ff553 KS |
560 | # git may return quoted and escaped filenames |
561 | sub unquote { | |
562 | my $str = shift; | |
563 | if ($str =~ m/^"(.*)"$/) { | |
564 | $str = $1; | |
565 | $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg; | |
566 | } | |
567 | return $str; | |
568 | } | |
569 | ||
f16db173 JN |
570 | # escape tabs (convert tabs to spaces) |
571 | sub untabify { | |
572 | my $line = shift; | |
573 | ||
574 | while ((my $pos = index($line, "\t")) != -1) { | |
575 | if (my $count = (8 - ($pos % 8))) { | |
576 | my $spaces = ' ' x $count; | |
577 | $line =~ s/\t/$spaces/; | |
578 | } | |
579 | } | |
580 | ||
581 | return $line; | |
582 | } | |
583 | ||
32f4aacc ML |
584 | sub project_in_list { |
585 | my $project = shift; | |
586 | my @list = git_get_projects_list(); | |
587 | return @list && scalar(grep { $_->{'path'} eq $project } @list); | |
588 | } | |
589 | ||
717b8311 JN |
590 | ## ---------------------------------------------------------------------- |
591 | ## HTML aware string manipulation | |
592 | ||
593 | sub chop_str { | |
594 | my $str = shift; | |
595 | my $len = shift; | |
596 | my $add_len = shift || 10; | |
597 | ||
598 | # allow only $len chars, but don't cut a word if it would fit in $add_len | |
599 | # if it doesn't fit, cut it if it's still longer than the dots we would add | |
600 | $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/; | |
601 | my $body = $1; | |
602 | my $tail = $2; | |
603 | if (length($tail) > 4) { | |
604 | $tail = " ..."; | |
605 | $body =~ s/&[^;]*$//; # remove chopped character entities | |
606 | } | |
607 | return "$body$tail"; | |
608 | } | |
609 | ||
610 | ## ---------------------------------------------------------------------- | |
611 | ## functions returning short strings | |
612 | ||
1f1ab5f0 JN |
613 | # CSS class for given age value (in seconds) |
614 | sub age_class { | |
615 | my $age = shift; | |
616 | ||
617 | if ($age < 60*60*2) { | |
618 | return "age0"; | |
619 | } elsif ($age < 60*60*24*2) { | |
620 | return "age1"; | |
621 | } else { | |
622 | return "age2"; | |
623 | } | |
624 | } | |
625 | ||
717b8311 JN |
626 | # convert age in seconds to "nn units ago" string |
627 | sub age_string { | |
628 | my $age = shift; | |
629 | my $age_str; | |
a59d4afd | 630 | |
717b8311 JN |
631 | if ($age > 60*60*24*365*2) { |
632 | $age_str = (int $age/60/60/24/365); | |
633 | $age_str .= " years ago"; | |
634 | } elsif ($age > 60*60*24*(365/12)*2) { | |
635 | $age_str = int $age/60/60/24/(365/12); | |
636 | $age_str .= " months ago"; | |
637 | } elsif ($age > 60*60*24*7*2) { | |
638 | $age_str = int $age/60/60/24/7; | |
639 | $age_str .= " weeks ago"; | |
640 | } elsif ($age > 60*60*24*2) { | |
641 | $age_str = int $age/60/60/24; | |
642 | $age_str .= " days ago"; | |
643 | } elsif ($age > 60*60*2) { | |
644 | $age_str = int $age/60/60; | |
645 | $age_str .= " hours ago"; | |
646 | } elsif ($age > 60*2) { | |
647 | $age_str = int $age/60; | |
648 | $age_str .= " min ago"; | |
649 | } elsif ($age > 2) { | |
650 | $age_str = int $age; | |
651 | $age_str .= " sec ago"; | |
f6801d66 | 652 | } else { |
717b8311 | 653 | $age_str .= " right now"; |
4c02e3c5 | 654 | } |
717b8311 | 655 | return $age_str; |
161332a5 KS |
656 | } |
657 | ||
717b8311 JN |
658 | # convert file mode in octal to symbolic file mode string |
659 | sub mode_str { | |
660 | my $mode = oct shift; | |
661 | ||
662 | if (S_ISDIR($mode & S_IFMT)) { | |
663 | return 'drwxr-xr-x'; | |
664 | } elsif (S_ISLNK($mode)) { | |
665 | return 'lrwxrwxrwx'; | |
666 | } elsif (S_ISREG($mode)) { | |
667 | # git cares only about the executable bit | |
668 | if ($mode & S_IXUSR) { | |
669 | return '-rwxr-xr-x'; | |
670 | } else { | |
671 | return '-rw-r--r--'; | |
672 | }; | |
c994d620 | 673 | } else { |
717b8311 | 674 | return '----------'; |
ff7669a5 | 675 | } |
161332a5 KS |
676 | } |
677 | ||
717b8311 JN |
678 | # convert file mode in octal to file type string |
679 | sub file_type { | |
7c5e2ebb JN |
680 | my $mode = shift; |
681 | ||
682 | if ($mode !~ m/^[0-7]+$/) { | |
683 | return $mode; | |
684 | } else { | |
685 | $mode = oct $mode; | |
686 | } | |
664f4cc5 | 687 | |
717b8311 JN |
688 | if (S_ISDIR($mode & S_IFMT)) { |
689 | return "directory"; | |
690 | } elsif (S_ISLNK($mode)) { | |
691 | return "symlink"; | |
692 | } elsif (S_ISREG($mode)) { | |
693 | return "file"; | |
694 | } else { | |
695 | return "unknown"; | |
696 | } | |
a59d4afd KS |
697 | } |
698 | ||
717b8311 JN |
699 | ## ---------------------------------------------------------------------- |
700 | ## functions returning short HTML fragments, or transforming HTML fragments | |
701 | ## which don't beling to other sections | |
b18f9bf4 | 702 | |
717b8311 JN |
703 | # format line of commit message or tag comment |
704 | sub format_log_line_html { | |
705 | my $line = shift; | |
b18f9bf4 | 706 | |
717b8311 JN |
707 | $line = esc_html($line); |
708 | $line =~ s/ / /g; | |
709 | if ($line =~ m/([0-9a-fA-F]{40})/) { | |
710 | my $hash_text = $1; | |
711 | if (git_get_type($hash_text) eq "commit") { | |
952c65fc JN |
712 | my $link = |
713 | $cgi->a({-href => href(action=>"commit", hash=>$hash_text), | |
714 | -class => "text"}, $hash_text); | |
717b8311 | 715 | $line =~ s/$hash_text/$link/; |
b18f9bf4 JN |
716 | } |
717 | } | |
717b8311 | 718 | return $line; |
b18f9bf4 JN |
719 | } |
720 | ||
717b8311 | 721 | # format marker of refs pointing to given object |
847e01fb | 722 | sub format_ref_marker { |
717b8311 | 723 | my ($refs, $id) = @_; |
d294e1ca | 724 | my $markers = ''; |
27fb8c40 | 725 | |
717b8311 | 726 | if (defined $refs->{$id}) { |
d294e1ca JN |
727 | foreach my $ref (@{$refs->{$id}}) { |
728 | my ($type, $name) = qw(); | |
729 | # e.g. tags/v2.6.11 or heads/next | |
730 | if ($ref =~ m!^(.*?)s?/(.*)$!) { | |
731 | $type = $1; | |
732 | $name = $2; | |
733 | } else { | |
734 | $type = "ref"; | |
735 | $name = $ref; | |
736 | } | |
737 | ||
738 | $markers .= " <span class=\"$type\">" . esc_html($name) . "</span>"; | |
739 | } | |
740 | } | |
741 | ||
742 | if ($markers) { | |
743 | return ' <span class="refs">'. $markers . '</span>'; | |
717b8311 JN |
744 | } else { |
745 | return ""; | |
746 | } | |
27fb8c40 JN |
747 | } |
748 | ||
17d07443 JN |
749 | # format, perhaps shortened and with markers, title line |
750 | sub format_subject_html { | |
1c2a4f5a | 751 | my ($long, $short, $href, $extra) = @_; |
17d07443 JN |
752 | $extra = '' unless defined($extra); |
753 | ||
754 | if (length($short) < length($long)) { | |
7c278014 | 755 | return $cgi->a({-href => $href, -class => "list subject", |
847abc0f | 756 | -title => to_utf8($long)}, |
17d07443 JN |
757 | esc_html($short) . $extra); |
758 | } else { | |
7c278014 | 759 | return $cgi->a({-href => $href, -class => "list subject"}, |
17d07443 JN |
760 | esc_html($long) . $extra); |
761 | } | |
762 | } | |
763 | ||
eee08903 JN |
764 | sub format_diff_line { |
765 | my $line = shift; | |
766 | my $char = substr($line, 0, 1); | |
767 | my $diff_class = ""; | |
768 | ||
769 | chomp $line; | |
770 | ||
771 | if ($char eq '+') { | |
772 | $diff_class = " add"; | |
773 | } elsif ($char eq "-") { | |
774 | $diff_class = " rem"; | |
775 | } elsif ($char eq "@") { | |
776 | $diff_class = " chunk_header"; | |
777 | } elsif ($char eq "\\") { | |
af33ef21 | 778 | $diff_class = " incomplete"; |
eee08903 JN |
779 | } |
780 | $line = untabify($line); | |
781 | return "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n"; | |
782 | } | |
783 | ||
717b8311 JN |
784 | ## ---------------------------------------------------------------------- |
785 | ## git utility subroutines, invoking git commands | |
42f7eb94 | 786 | |
25691fbe DS |
787 | # returns path to the core git executable and the --git-dir parameter as list |
788 | sub git_cmd { | |
789 | return $GIT, '--git-dir='.$git_dir; | |
790 | } | |
791 | ||
792 | # returns path to the core git executable and the --git-dir parameter as string | |
793 | sub git_cmd_str { | |
794 | return join(' ', git_cmd()); | |
795 | } | |
796 | ||
717b8311 | 797 | # get HEAD ref of given project as hash |
847e01fb | 798 | sub git_get_head_hash { |
df2c37a5 | 799 | my $project = shift; |
25691fbe | 800 | my $o_git_dir = $git_dir; |
df2c37a5 | 801 | my $retval = undef; |
25691fbe DS |
802 | $git_dir = "$projectroot/$project"; |
803 | if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") { | |
df2c37a5 JH |
804 | my $head = <$fd>; |
805 | close $fd; | |
2c5c008b KS |
806 | if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) { |
807 | $retval = $1; | |
df2c37a5 JH |
808 | } |
809 | } | |
25691fbe DS |
810 | if (defined $o_git_dir) { |
811 | $git_dir = $o_git_dir; | |
2c5c008b | 812 | } |
df2c37a5 JH |
813 | return $retval; |
814 | } | |
815 | ||
717b8311 JN |
816 | # get type of given object |
817 | sub git_get_type { | |
818 | my $hash = shift; | |
819 | ||
25691fbe | 820 | open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return; |
717b8311 JN |
821 | my $type = <$fd>; |
822 | close $fd or return; | |
823 | chomp $type; | |
824 | return $type; | |
825 | } | |
826 | ||
827 | sub git_get_project_config { | |
ddb8d900 | 828 | my ($key, $type) = @_; |
717b8311 JN |
829 | |
830 | return unless ($key); | |
831 | $key =~ s/^gitweb\.//; | |
832 | return if ($key =~ m/\W/); | |
833 | ||
25691fbe | 834 | my @x = (git_cmd(), 'repo-config'); |
ddb8d900 AK |
835 | if (defined $type) { push @x, $type; } |
836 | push @x, "--get"; | |
837 | push @x, "gitweb.$key"; | |
838 | my $val = qx(@x); | |
839 | chomp $val; | |
717b8311 JN |
840 | return ($val); |
841 | } | |
842 | ||
717b8311 JN |
843 | # get hash of given path at given ref |
844 | sub git_get_hash_by_path { | |
845 | my $base = shift; | |
846 | my $path = shift || return undef; | |
1d782b03 | 847 | my $type = shift; |
717b8311 | 848 | |
4b02f483 | 849 | $path =~ s,/+$,,; |
717b8311 | 850 | |
25691fbe | 851 | open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path |
cac4bd94 | 852 | or die_error(undef, "Open git-ls-tree failed"); |
717b8311 JN |
853 | my $line = <$fd>; |
854 | close $fd or return undef; | |
855 | ||
856 | #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' | |
857 | $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/; | |
1d782b03 JN |
858 | if (defined $type && $type ne $2) { |
859 | # type doesn't match | |
860 | return undef; | |
861 | } | |
717b8311 JN |
862 | return $3; |
863 | } | |
864 | ||
865 | ## ...................................................................... | |
866 | ## git utility functions, directly accessing git repository | |
867 | ||
847e01fb | 868 | sub git_get_project_description { |
b87d78d6 | 869 | my $path = shift; |
09bd7898 | 870 | |
19806691 | 871 | open my $fd, "$projectroot/$path/description" or return undef; |
b87d78d6 KS |
872 | my $descr = <$fd>; |
873 | close $fd; | |
874 | chomp $descr; | |
875 | return $descr; | |
12a88f2f KS |
876 | } |
877 | ||
e79ca7cc JN |
878 | sub git_get_project_url_list { |
879 | my $path = shift; | |
880 | ||
74d61667 | 881 | open my $fd, "$projectroot/$path/cloneurl" or return; |
e79ca7cc JN |
882 | my @git_project_url_list = map { chomp; $_ } <$fd>; |
883 | close $fd; | |
884 | ||
885 | return wantarray ? @git_project_url_list : \@git_project_url_list; | |
886 | } | |
887 | ||
847e01fb | 888 | sub git_get_projects_list { |
717b8311 JN |
889 | my @list; |
890 | ||
891 | if (-d $projects_list) { | |
892 | # search in directory | |
893 | my $dir = $projects_list; | |
c0011ff8 JN |
894 | my $pfxlen = length("$dir"); |
895 | ||
896 | File::Find::find({ | |
897 | follow_fast => 1, # follow symbolic links | |
898 | dangling_symlinks => 0, # ignore dangling symlinks, silently | |
899 | wanted => sub { | |
900 | # skip project-list toplevel, if we get it. | |
901 | return if (m!^[/.]$!); | |
902 | # only directories can be git repositories | |
903 | return unless (-d $_); | |
904 | ||
905 | my $subdir = substr($File::Find::name, $pfxlen + 1); | |
906 | # we check related file in $projectroot | |
2172ce4b | 907 | if (check_export_ok("$projectroot/$subdir")) { |
c0011ff8 JN |
908 | push @list, { path => $subdir }; |
909 | $File::Find::prune = 1; | |
910 | } | |
911 | }, | |
912 | }, "$dir"); | |
913 | ||
717b8311 JN |
914 | } elsif (-f $projects_list) { |
915 | # read from file(url-encoded): | |
916 | # 'git%2Fgit.git Linus+Torvalds' | |
917 | # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin' | |
918 | # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman' | |
dd1ad5f1 | 919 | open my ($fd), $projects_list or return; |
717b8311 JN |
920 | while (my $line = <$fd>) { |
921 | chomp $line; | |
922 | my ($path, $owner) = split ' ', $line; | |
923 | $path = unescape($path); | |
924 | $owner = unescape($owner); | |
925 | if (!defined $path) { | |
926 | next; | |
927 | } | |
2172ce4b | 928 | if (check_export_ok("$projectroot/$path")) { |
717b8311 JN |
929 | my $pr = { |
930 | path => $path, | |
847abc0f | 931 | owner => to_utf8($owner), |
717b8311 JN |
932 | }; |
933 | push @list, $pr | |
934 | } | |
935 | } | |
936 | close $fd; | |
937 | } | |
938 | @list = sort {$a->{'path'} cmp $b->{'path'}} @list; | |
939 | return @list; | |
940 | } | |
941 | ||
1e0cf030 JN |
942 | sub git_get_project_owner { |
943 | my $project = shift; | |
944 | my $owner; | |
945 | ||
946 | return undef unless $project; | |
947 | ||
948 | # read from file (url-encoded): | |
949 | # 'git%2Fgit.git Linus+Torvalds' | |
950 | # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin' | |
951 | # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman' | |
952 | if (-f $projects_list) { | |
953 | open (my $fd , $projects_list); | |
954 | while (my $line = <$fd>) { | |
955 | chomp $line; | |
956 | my ($pr, $ow) = split ' ', $line; | |
957 | $pr = unescape($pr); | |
958 | $ow = unescape($ow); | |
959 | if ($pr eq $project) { | |
847abc0f | 960 | $owner = to_utf8($ow); |
1e0cf030 JN |
961 | last; |
962 | } | |
963 | } | |
964 | close $fd; | |
965 | } | |
966 | if (!defined $owner) { | |
967 | $owner = get_file_owner("$projectroot/$project"); | |
968 | } | |
969 | ||
970 | return $owner; | |
971 | } | |
972 | ||
847e01fb | 973 | sub git_get_references { |
717b8311 JN |
974 | my $type = shift || ""; |
975 | my %refs; | |
976 | # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11 | |
977 | # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{} | |
9704d75d JN |
978 | open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/" |
979 | or return; | |
d294e1ca | 980 | |
717b8311 JN |
981 | while (my $line = <$fd>) { |
982 | chomp $line; | |
d294e1ca | 983 | if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) { |
717b8311 | 984 | if (defined $refs{$1}) { |
d294e1ca | 985 | push @{$refs{$1}}, $2; |
717b8311 | 986 | } else { |
d294e1ca | 987 | $refs{$1} = [ $2 ]; |
717b8311 JN |
988 | } |
989 | } | |
990 | } | |
991 | close $fd or return; | |
992 | return \%refs; | |
993 | } | |
994 | ||
56a322f1 JN |
995 | sub git_get_rev_name_tags { |
996 | my $hash = shift || return undef; | |
997 | ||
25691fbe | 998 | open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash |
56a322f1 JN |
999 | or return; |
1000 | my $name_rev = <$fd>; | |
1001 | close $fd; | |
1002 | ||
1003 | if ($name_rev =~ m|^$hash tags/(.*)$|) { | |
1004 | return $1; | |
1005 | } else { | |
1006 | # catches also '$hash undefined' output | |
1007 | return undef; | |
1008 | } | |
1009 | } | |
1010 | ||
717b8311 JN |
1011 | ## ---------------------------------------------------------------------- |
1012 | ## parse to hash functions | |
1013 | ||
847e01fb | 1014 | sub parse_date { |
717b8311 JN |
1015 | my $epoch = shift; |
1016 | my $tz = shift || "-0000"; | |
1017 | ||
1018 | my %date; | |
1019 | my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
1020 | my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
1021 | my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch); | |
1022 | $date{'hour'} = $hour; | |
1023 | $date{'minute'} = $min; | |
1024 | $date{'mday'} = $mday; | |
1025 | $date{'day'} = $days[$wday]; | |
1026 | $date{'month'} = $months[$mon]; | |
952c65fc JN |
1027 | $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", |
1028 | $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec; | |
1029 | $date{'mday-time'} = sprintf "%d %s %02d:%02d", | |
1030 | $mday, $months[$mon], $hour ,$min; | |
717b8311 JN |
1031 | |
1032 | $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/; | |
1033 | my $local = $epoch + ((int $1 + ($2/60)) * 3600); | |
1034 | ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local); | |
1035 | $date{'hour_local'} = $hour; | |
1036 | $date{'minute_local'} = $min; | |
1037 | $date{'tz_local'} = $tz; | |
1038 | return %date; | |
1039 | } | |
1040 | ||
847e01fb | 1041 | sub parse_tag { |
ede5e100 KS |
1042 | my $tag_id = shift; |
1043 | my %tag; | |
d8a20ba9 | 1044 | my @comment; |
ede5e100 | 1045 | |
25691fbe | 1046 | open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return; |
d8a20ba9 | 1047 | $tag{'id'} = $tag_id; |
ede5e100 KS |
1048 | while (my $line = <$fd>) { |
1049 | chomp $line; | |
1050 | if ($line =~ m/^object ([0-9a-fA-F]{40})$/) { | |
1051 | $tag{'object'} = $1; | |
7ab0d2b6 | 1052 | } elsif ($line =~ m/^type (.+)$/) { |
ede5e100 | 1053 | $tag{'type'} = $1; |
7ab0d2b6 | 1054 | } elsif ($line =~ m/^tag (.+)$/) { |
ede5e100 | 1055 | $tag{'name'} = $1; |
d8a20ba9 KS |
1056 | } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) { |
1057 | $tag{'author'} = $1; | |
1058 | $tag{'epoch'} = $2; | |
1059 | $tag{'tz'} = $3; | |
1060 | } elsif ($line =~ m/--BEGIN/) { | |
1061 | push @comment, $line; | |
1062 | last; | |
1063 | } elsif ($line eq "") { | |
1064 | last; | |
ede5e100 KS |
1065 | } |
1066 | } | |
d8a20ba9 KS |
1067 | push @comment, <$fd>; |
1068 | $tag{'comment'} = \@comment; | |
19806691 | 1069 | close $fd or return; |
ede5e100 KS |
1070 | if (!defined $tag{'name'}) { |
1071 | return | |
1072 | }; | |
1073 | return %tag | |
1074 | } | |
1075 | ||
63e02a1b JH |
1076 | sub git_get_last_activity { |
1077 | my ($path) = @_; | |
1078 | my $fd; | |
1079 | ||
1080 | $git_dir = "$projectroot/$path"; | |
1081 | open($fd, "-|", git_cmd(), 'for-each-ref', | |
1082 | '--format=%(refname) %(committer)', | |
1083 | '--sort=-committerdate', | |
1084 | 'refs/heads') or return; | |
1085 | my $most_recent = <$fd>; | |
1086 | close $fd or return; | |
1087 | if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) { | |
1088 | my $timestamp = $1; | |
1089 | my $age = time - $timestamp; | |
1090 | return ($age, age_string($age)); | |
1091 | } | |
1092 | } | |
1093 | ||
847e01fb | 1094 | sub parse_commit { |
19806691 KS |
1095 | my $commit_id = shift; |
1096 | my $commit_text = shift; | |
1097 | ||
1098 | my @commit_lines; | |
703ac710 | 1099 | my %co; |
703ac710 | 1100 | |
19806691 KS |
1101 | if (defined $commit_text) { |
1102 | @commit_lines = @$commit_text; | |
1103 | } else { | |
a153adf6 | 1104 | local $/ = "\0"; |
25691fbe | 1105 | open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id |
952c65fc | 1106 | or return; |
25f422fb | 1107 | @commit_lines = split '\n', <$fd>; |
19806691 | 1108 | close $fd or return; |
25f422fb | 1109 | pop @commit_lines; |
19806691 | 1110 | } |
25f422fb KS |
1111 | my $header = shift @commit_lines; |
1112 | if (!($header =~ m/^[0-9a-fA-F]{40}/)) { | |
1113 | return; | |
1114 | } | |
1115 | ($co{'id'}, my @parents) = split ' ', $header; | |
1116 | $co{'parents'} = \@parents; | |
1117 | $co{'parent'} = $parents[0]; | |
19806691 | 1118 | while (my $line = shift @commit_lines) { |
b87d78d6 | 1119 | last if $line eq "\n"; |
7ab0d2b6 | 1120 | if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) { |
703ac710 | 1121 | $co{'tree'} = $1; |
022be3d0 | 1122 | } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) { |
3f714537 | 1123 | $co{'author'} = $1; |
185f09e5 KS |
1124 | $co{'author_epoch'} = $2; |
1125 | $co{'author_tz'} = $3; | |
2bf7a52c KS |
1126 | if ($co{'author'} =~ m/^([^<]+) </) { |
1127 | $co{'author_name'} = $1; | |
1128 | } else { | |
1129 | $co{'author_name'} = $co{'author'}; | |
1130 | } | |
86eed32d KS |
1131 | } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) { |
1132 | $co{'committer'} = $1; | |
185f09e5 KS |
1133 | $co{'committer_epoch'} = $2; |
1134 | $co{'committer_tz'} = $3; | |
991910a9 KS |
1135 | $co{'committer_name'} = $co{'committer'}; |
1136 | $co{'committer_name'} =~ s/ <.*//; | |
703ac710 KS |
1137 | } |
1138 | } | |
ede5e100 | 1139 | if (!defined $co{'tree'}) { |
25f422fb | 1140 | return; |
ede5e100 | 1141 | }; |
25f422fb | 1142 | |
19806691 | 1143 | foreach my $title (@commit_lines) { |
c2488d06 | 1144 | $title =~ s/^ //; |
19806691 | 1145 | if ($title ne "") { |
48c771f4 | 1146 | $co{'title'} = chop_str($title, 80, 5); |
19806691 KS |
1147 | # remove leading stuff of merges to make the interesting part visible |
1148 | if (length($title) > 50) { | |
1149 | $title =~ s/^Automatic //; | |
1150 | $title =~ s/^merge (of|with) /Merge ... /i; | |
1151 | if (length($title) > 50) { | |
1152 | $title =~ s/(http|rsync):\/\///; | |
1153 | } | |
1154 | if (length($title) > 50) { | |
1155 | $title =~ s/(master|www|rsync)\.//; | |
1156 | } | |
1157 | if (length($title) > 50) { | |
1158 | $title =~ s/kernel.org:?//; | |
1159 | } | |
1160 | if (length($title) > 50) { | |
1161 | $title =~ s/\/pub\/scm//; | |
1162 | } | |
1163 | } | |
48c771f4 | 1164 | $co{'title_short'} = chop_str($title, 50, 5); |
19806691 KS |
1165 | last; |
1166 | } | |
1167 | } | |
7e0fe5c9 PB |
1168 | if ($co{'title'} eq "") { |
1169 | $co{'title'} = $co{'title_short'} = '(no commit message)'; | |
1170 | } | |
25f422fb KS |
1171 | # remove added spaces |
1172 | foreach my $line (@commit_lines) { | |
1173 | $line =~ s/^ //; | |
1174 | } | |
1175 | $co{'comment'} = \@commit_lines; | |
2ae100df KS |
1176 | |
1177 | my $age = time - $co{'committer_epoch'}; | |
1178 | $co{'age'} = $age; | |
d263a6bd | 1179 | $co{'age_string'} = age_string($age); |
71be1e79 KS |
1180 | my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'}); |
1181 | if ($age > 60*60*24*7*2) { | |
1b1cd421 | 1182 | $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday; |
71be1e79 KS |
1183 | $co{'age_string_age'} = $co{'age_string'}; |
1184 | } else { | |
1185 | $co{'age_string_date'} = $co{'age_string'}; | |
1b1cd421 | 1186 | $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday; |
71be1e79 | 1187 | } |
703ac710 KS |
1188 | return %co; |
1189 | } | |
1190 | ||
a446d6bb JN |
1191 | # parse ref from ref_file, given by ref_id, with given type |
1192 | sub parse_ref { | |
1193 | my $ref_file = shift; | |
1194 | my $ref_id = shift; | |
1195 | my $type = shift || git_get_type($ref_id); | |
1196 | my %ref_item; | |
1197 | ||
1198 | $ref_item{'type'} = $type; | |
1199 | $ref_item{'id'} = $ref_id; | |
1200 | $ref_item{'epoch'} = 0; | |
1201 | $ref_item{'age'} = "unknown"; | |
1202 | if ($type eq "tag") { | |
1203 | my %tag = parse_tag($ref_id); | |
1204 | $ref_item{'comment'} = $tag{'comment'}; | |
1205 | if ($tag{'type'} eq "commit") { | |
1206 | my %co = parse_commit($tag{'object'}); | |
1207 | $ref_item{'epoch'} = $co{'committer_epoch'}; | |
1208 | $ref_item{'age'} = $co{'age_string'}; | |
1209 | } elsif (defined($tag{'epoch'})) { | |
1210 | my $age = time - $tag{'epoch'}; | |
1211 | $ref_item{'epoch'} = $tag{'epoch'}; | |
1212 | $ref_item{'age'} = age_string($age); | |
1213 | } | |
1214 | $ref_item{'reftype'} = $tag{'type'}; | |
1215 | $ref_item{'name'} = $tag{'name'}; | |
1216 | $ref_item{'refid'} = $tag{'object'}; | |
1217 | } elsif ($type eq "commit"){ | |
1218 | my %co = parse_commit($ref_id); | |
1219 | $ref_item{'reftype'} = "commit"; | |
1220 | $ref_item{'name'} = $ref_file; | |
1221 | $ref_item{'title'} = $co{'title'}; | |
1222 | $ref_item{'refid'} = $ref_id; | |
1223 | $ref_item{'epoch'} = $co{'committer_epoch'}; | |
1224 | $ref_item{'age'} = $co{'age_string'}; | |
1225 | } else { | |
1226 | $ref_item{'reftype'} = $type; | |
1227 | $ref_item{'name'} = $ref_file; | |
1228 | $ref_item{'refid'} = $ref_id; | |
1229 | } | |
1230 | ||
1231 | return %ref_item; | |
1232 | } | |
1233 | ||
e8e41a93 | 1234 | # parse line of git-diff-tree "raw" output |
740e67f9 JN |
1235 | sub parse_difftree_raw_line { |
1236 | my $line = shift; | |
1237 | my %res; | |
1238 | ||
1239 | # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c' | |
1240 | # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c' | |
1241 | if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) { | |
1242 | $res{'from_mode'} = $1; | |
1243 | $res{'to_mode'} = $2; | |
1244 | $res{'from_id'} = $3; | |
1245 | $res{'to_id'} = $4; | |
1246 | $res{'status'} = $5; | |
1247 | $res{'similarity'} = $6; | |
1248 | if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied | |
e8e41a93 | 1249 | ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7); |
740e67f9 JN |
1250 | } else { |
1251 | $res{'file'} = unquote($7); | |
1252 | } | |
1253 | } | |
1254 | # 'c512b523472485aef4fff9e57b229d9d243c967f' | |
0edcb37d JN |
1255 | elsif ($line =~ m/^([0-9a-fA-F]{40})$/) { |
1256 | $res{'commit'} = $1; | |
1257 | } | |
740e67f9 JN |
1258 | |
1259 | return wantarray ? %res : \%res; | |
1260 | } | |
1261 | ||
cb849b46 JN |
1262 | # parse line of git-ls-tree output |
1263 | sub parse_ls_tree_line ($;%) { | |
1264 | my $line = shift; | |
1265 | my %opts = @_; | |
1266 | my %res; | |
1267 | ||
1268 | #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' | |
1269 | $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/; | |
1270 | ||
1271 | $res{'mode'} = $1; | |
1272 | $res{'type'} = $2; | |
1273 | $res{'hash'} = $3; | |
1274 | if ($opts{'-z'}) { | |
1275 | $res{'name'} = $4; | |
1276 | } else { | |
1277 | $res{'name'} = unquote($4); | |
1278 | } | |
1279 | ||
1280 | return wantarray ? %res : \%res; | |
1281 | } | |
1282 | ||
717b8311 JN |
1283 | ## ...................................................................... |
1284 | ## parse to array of hashes functions | |
4c02e3c5 | 1285 | |
847e01fb | 1286 | sub git_get_refs_list { |
120ddde2 JN |
1287 | my $type = shift || ""; |
1288 | my %refs; | |
717b8311 | 1289 | my @reflist; |
4c02e3c5 | 1290 | |
717b8311 | 1291 | my @refs; |
c83a77e4 JN |
1292 | open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/" |
1293 | or return; | |
1294 | while (my $line = <$fd>) { | |
1295 | chomp $line; | |
120ddde2 JN |
1296 | if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?([^\^]+))(\^\{\})?$/) { |
1297 | if (defined $refs{$1}) { | |
1298 | push @{$refs{$1}}, $2; | |
1299 | } else { | |
1300 | $refs{$1} = [ $2 ]; | |
1301 | } | |
1302 | ||
1303 | if (! $4) { # unpeeled, direct reference | |
1304 | push @refs, { hash => $1, name => $3 }; # without type | |
1305 | } elsif ($3 eq $refs[-1]{'name'}) { | |
1306 | # most likely a tag is followed by its peeled | |
1307 | # (deref) one, and when that happens we know the | |
1308 | # previous one was of type 'tag'. | |
1309 | $refs[-1]{'type'} = "tag"; | |
1310 | } | |
717b8311 | 1311 | } |
c83a77e4 JN |
1312 | } |
1313 | close $fd; | |
1314 | ||
1315 | foreach my $ref (@refs) { | |
1316 | my $ref_file = $ref->{'name'}; | |
1317 | my $ref_id = $ref->{'hash'}; | |
7a13b999 | 1318 | |
c83a77e4 | 1319 | my $type = $ref->{'type'} || git_get_type($ref_id) || next; |
a446d6bb | 1320 | my %ref_item = parse_ref($ref_file, $ref_id, $type); |
991910a9 | 1321 | |
717b8311 JN |
1322 | push @reflist, \%ref_item; |
1323 | } | |
a446d6bb | 1324 | # sort refs by age |
717b8311 | 1325 | @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist; |
120ddde2 | 1326 | return (\@reflist, \%refs); |
86eed32d KS |
1327 | } |
1328 | ||
717b8311 JN |
1329 | ## ---------------------------------------------------------------------- |
1330 | ## filesystem-related functions | |
022be3d0 | 1331 | |
c07ad4b9 KS |
1332 | sub get_file_owner { |
1333 | my $path = shift; | |
1334 | ||
1335 | my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path); | |
1336 | my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid); | |
1337 | if (!defined $gcos) { | |
1338 | return undef; | |
1339 | } | |
1340 | my $owner = $gcos; | |
1341 | $owner =~ s/[,;].*$//; | |
847abc0f | 1342 | return to_utf8($owner); |
c07ad4b9 KS |
1343 | } |
1344 | ||
717b8311 JN |
1345 | ## ...................................................................... |
1346 | ## mimetype related functions | |
09bd7898 | 1347 | |
717b8311 JN |
1348 | sub mimetype_guess_file { |
1349 | my $filename = shift; | |
1350 | my $mimemap = shift; | |
1351 | -r $mimemap or return undef; | |
1352 | ||
1353 | my %mimemap; | |
1354 | open(MIME, $mimemap) or return undef; | |
1355 | while (<MIME>) { | |
618918e5 | 1356 | next if m/^#/; # skip comments |
717b8311 | 1357 | my ($mime, $exts) = split(/\t+/); |
46b059d7 JH |
1358 | if (defined $exts) { |
1359 | my @exts = split(/\s+/, $exts); | |
1360 | foreach my $ext (@exts) { | |
1361 | $mimemap{$ext} = $mime; | |
1362 | } | |
09bd7898 | 1363 | } |
09bd7898 | 1364 | } |
717b8311 | 1365 | close(MIME); |
09bd7898 | 1366 | |
8059319a | 1367 | $filename =~ /\.([^.]*)$/; |
717b8311 JN |
1368 | return $mimemap{$1}; |
1369 | } | |
5996ca08 | 1370 | |
717b8311 JN |
1371 | sub mimetype_guess { |
1372 | my $filename = shift; | |
1373 | my $mime; | |
1374 | $filename =~ /\./ or return undef; | |
5996ca08 | 1375 | |
717b8311 JN |
1376 | if ($mimetypes_file) { |
1377 | my $file = $mimetypes_file; | |
d5aa50de JN |
1378 | if ($file !~ m!^/!) { # if it is relative path |
1379 | # it is relative to project | |
1380 | $file = "$projectroot/$project/$file"; | |
1381 | } | |
717b8311 JN |
1382 | $mime = mimetype_guess_file($filename, $file); |
1383 | } | |
1384 | $mime ||= mimetype_guess_file($filename, '/etc/mime.types'); | |
1385 | return $mime; | |
5996ca08 FF |
1386 | } |
1387 | ||
847e01fb | 1388 | sub blob_mimetype { |
717b8311 JN |
1389 | my $fd = shift; |
1390 | my $filename = shift; | |
5996ca08 | 1391 | |
717b8311 JN |
1392 | if ($filename) { |
1393 | my $mime = mimetype_guess($filename); | |
1394 | $mime and return $mime; | |
d8d17b5d | 1395 | } |
717b8311 JN |
1396 | |
1397 | # just in case | |
1398 | return $default_blob_plain_mimetype unless $fd; | |
1399 | ||
1400 | if (-T $fd) { | |
1401 | return 'text/plain' . | |
1402 | ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : ''); | |
1403 | } elsif (! $filename) { | |
1404 | return 'application/octet-stream'; | |
1405 | } elsif ($filename =~ m/\.png$/i) { | |
1406 | return 'image/png'; | |
1407 | } elsif ($filename =~ m/\.gif$/i) { | |
1408 | return 'image/gif'; | |
1409 | } elsif ($filename =~ m/\.jpe?g$/i) { | |
1410 | return 'image/jpeg'; | |
d8d17b5d | 1411 | } else { |
717b8311 | 1412 | return 'application/octet-stream'; |
f7ab660c | 1413 | } |
717b8311 JN |
1414 | } |
1415 | ||
1416 | ## ====================================================================== | |
1417 | ## functions printing HTML: header, footer, error page | |
1418 | ||
1419 | sub git_header_html { | |
1420 | my $status = shift || "200 OK"; | |
1421 | my $expires = shift; | |
1422 | ||
1423 | my $title = "$site_name git"; | |
1424 | if (defined $project) { | |
1425 | $title .= " - $project"; | |
1426 | if (defined $action) { | |
1427 | $title .= "/$action"; | |
1428 | if (defined $file_name) { | |
a2f3db2f | 1429 | $title .= " - " . esc_html($file_name); |
717b8311 JN |
1430 | if ($action eq "tree" && $file_name !~ m|/$|) { |
1431 | $title .= "/"; | |
1432 | } | |
1433 | } | |
1434 | } | |
f7ab660c | 1435 | } |
717b8311 JN |
1436 | my $content_type; |
1437 | # require explicit support from the UA if we are to send the page as | |
1438 | # 'application/xhtml+xml', otherwise send it as plain old 'text/html'. | |
1439 | # we have to do this because MSIE sometimes globs '*/*', pretending to | |
1440 | # support xhtml+xml but choking when it gets what it asked for. | |
952c65fc JN |
1441 | if (defined $cgi->http('HTTP_ACCEPT') && |
1442 | $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ && | |
1443 | $cgi->Accept('application/xhtml+xml') != 0) { | |
717b8311 | 1444 | $content_type = 'application/xhtml+xml'; |
f7ab660c | 1445 | } else { |
717b8311 | 1446 | $content_type = 'text/html'; |
f7ab660c | 1447 | } |
952c65fc JN |
1448 | print $cgi->header(-type=>$content_type, -charset => 'utf-8', |
1449 | -status=> $status, -expires => $expires); | |
717b8311 JN |
1450 | print <<EOF; |
1451 | <?xml version="1.0" encoding="utf-8"?> | |
1452 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
1453 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"> | |
d4baf9ea | 1454 | <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke --> |
717b8311 JN |
1455 | <!-- git core binaries version $git_version --> |
1456 | <head> | |
1457 | <meta http-equiv="content-type" content="$content_type; charset=utf-8"/> | |
d4baf9ea | 1458 | <meta name="generator" content="gitweb/$version git/$git_version"/> |
717b8311 JN |
1459 | <meta name="robots" content="index, nofollow"/> |
1460 | <title>$title</title> | |
717b8311 | 1461 | EOF |
b2d3476e AC |
1462 | # print out each stylesheet that exist |
1463 | if (defined $stylesheet) { | |
1464 | #provides backwards capability for those people who define style sheet in a config file | |
1465 | print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n"; | |
1466 | } else { | |
1467 | foreach my $stylesheet (@stylesheets) { | |
1468 | next unless $stylesheet; | |
1469 | print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n"; | |
1470 | } | |
1471 | } | |
dd04c428 ML |
1472 | if (defined $project) { |
1473 | printf('<link rel="alternate" title="%s log" '. | |
1474 | 'href="%s" type="application/rss+xml"/>'."\n", | |
1c2a4f5a | 1475 | esc_param($project), href(action=>"rss")); |
9d0734ae JN |
1476 | } else { |
1477 | printf('<link rel="alternate" title="%s projects list" '. | |
1478 | 'href="%s" type="text/plain; charset=utf-8"/>'."\n", | |
1479 | $site_name, href(project=>undef, action=>"project_index")); | |
1480 | printf('<link rel="alternate" title="%s projects logs" '. | |
1481 | 'href="%s" type="text/x-opml"/>'."\n", | |
1482 | $site_name, href(project=>undef, action=>"opml")); | |
dd04c428 | 1483 | } |
0b5deba1 JN |
1484 | if (defined $favicon) { |
1485 | print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n); | |
1486 | } | |
10161355 | 1487 | |
dd04c428 | 1488 | print "</head>\n" . |
b2d3476e AC |
1489 | "<body>\n"; |
1490 | ||
1491 | if (-f $site_header) { | |
1492 | open (my $fd, $site_header); | |
1493 | print <$fd>; | |
1494 | close $fd; | |
1495 | } | |
1496 | ||
1497 | print "<div class=\"page_header\">\n" . | |
9a7a62ff JN |
1498 | $cgi->a({-href => esc_url($logo_url), |
1499 | -title => $logo_label}, | |
1500 | qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>)); | |
f93bff8d | 1501 | print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / "; |
717b8311 | 1502 | if (defined $project) { |
1c2a4f5a | 1503 | print $cgi->a({-href => href(action=>"summary")}, esc_html($project)); |
717b8311 JN |
1504 | if (defined $action) { |
1505 | print " / $action"; | |
1506 | } | |
1507 | print "\n"; | |
1508 | if (!defined $searchtext) { | |
1509 | $searchtext = ""; | |
1510 | } | |
1511 | my $search_hash; | |
1512 | if (defined $hash_base) { | |
1513 | $search_hash = $hash_base; | |
1514 | } elsif (defined $hash) { | |
1515 | $search_hash = $hash; | |
bddec01d | 1516 | } else { |
717b8311 | 1517 | $search_hash = "HEAD"; |
bddec01d | 1518 | } |
717b8311 JN |
1519 | $cgi->param("a", "search"); |
1520 | $cgi->param("h", $search_hash); | |
34c06118 | 1521 | $cgi->param("p", $project); |
717b8311 JN |
1522 | print $cgi->startform(-method => "get", -action => $my_uri) . |
1523 | "<div class=\"search\">\n" . | |
1524 | $cgi->hidden(-name => "p") . "\n" . | |
1525 | $cgi->hidden(-name => "a") . "\n" . | |
1526 | $cgi->hidden(-name => "h") . "\n" . | |
1527 | $cgi->textfield(-name => "s", -value => $searchtext) . "\n" . | |
1528 | "</div>" . | |
1529 | $cgi->end_form() . "\n"; | |
b87d78d6 | 1530 | } |
717b8311 JN |
1531 | print "</div>\n"; |
1532 | } | |
1533 | ||
1534 | sub git_footer_html { | |
1535 | print "<div class=\"page_footer\">\n"; | |
1536 | if (defined $project) { | |
847e01fb | 1537 | my $descr = git_get_project_description($project); |
717b8311 JN |
1538 | if (defined $descr) { |
1539 | print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n"; | |
1540 | } | |
a1565c44 JN |
1541 | print $cgi->a({-href => href(action=>"rss"), |
1542 | -class => "rss_logo"}, "RSS") . "\n"; | |
717b8311 | 1543 | } else { |
a1565c44 | 1544 | print $cgi->a({-href => href(project=>undef, action=>"opml"), |
9d0734ae JN |
1545 | -class => "rss_logo"}, "OPML") . " "; |
1546 | print $cgi->a({-href => href(project=>undef, action=>"project_index"), | |
1547 | -class => "rss_logo"}, "TXT") . "\n"; | |
717b8311 | 1548 | } |
b2d3476e AC |
1549 | print "</div>\n" ; |
1550 | ||
1551 | if (-f $site_footer) { | |
1552 | open (my $fd, $site_footer); | |
1553 | print <$fd>; | |
1554 | close $fd; | |
1555 | } | |
1556 | ||
1557 | print "</body>\n" . | |
717b8311 JN |
1558 | "</html>"; |
1559 | } | |
1560 | ||
1561 | sub die_error { | |
1562 | my $status = shift || "403 Forbidden"; | |
1563 | my $error = shift || "Malformed query, file missing or permission denied"; | |
1564 | ||
1565 | git_header_html($status); | |
59b9f61a JN |
1566 | print <<EOF; |
1567 | <div class="page_body"> | |
1568 | <br /><br /> | |
1569 | $status - $error | |
1570 | <br /> | |
1571 | </div> | |
1572 | EOF | |
b87d78d6 | 1573 | git_footer_html(); |
717b8311 | 1574 | exit; |
161332a5 KS |
1575 | } |
1576 | ||
717b8311 JN |
1577 | ## ---------------------------------------------------------------------- |
1578 | ## functions printing or outputting HTML: navigation | |
1579 | ||
847e01fb | 1580 | sub git_print_page_nav { |
717b8311 JN |
1581 | my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_; |
1582 | $extra = '' if !defined $extra; # pager or formats | |
1583 | ||
1584 | my @navs = qw(summary shortlog log commit commitdiff tree); | |
1585 | if ($suppress) { | |
1586 | @navs = grep { $_ ne $suppress } @navs; | |
1587 | } | |
1588 | ||
1c2a4f5a | 1589 | my %arg = map { $_ => {action=>$_} } @navs; |
717b8311 JN |
1590 | if (defined $head) { |
1591 | for (qw(commit commitdiff)) { | |
1c2a4f5a | 1592 | $arg{$_}{hash} = $head; |
717b8311 JN |
1593 | } |
1594 | if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) { | |
1595 | for (qw(shortlog log)) { | |
1c2a4f5a | 1596 | $arg{$_}{hash} = $head; |
045e531a | 1597 | } |
6a928415 KS |
1598 | } |
1599 | } | |
1c2a4f5a MW |
1600 | $arg{tree}{hash} = $treehead if defined $treehead; |
1601 | $arg{tree}{hash_base} = $treebase if defined $treebase; | |
717b8311 JN |
1602 | |
1603 | print "<div class=\"page_nav\">\n" . | |
1604 | (join " | ", | |
1c2a4f5a MW |
1605 | map { $_ eq $current ? |
1606 | $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_") | |
1607 | } @navs); | |
717b8311 JN |
1608 | print "<br/>\n$extra<br/>\n" . |
1609 | "</div>\n"; | |
6a928415 KS |
1610 | } |
1611 | ||
847e01fb | 1612 | sub format_paging_nav { |
717b8311 JN |
1613 | my ($action, $hash, $head, $page, $nrevs) = @_; |
1614 | my $paging_nav; | |
594e212b | 1615 | |
717b8311 JN |
1616 | |
1617 | if ($hash ne $head || $page) { | |
1c2a4f5a | 1618 | $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD"); |
594e212b | 1619 | } else { |
717b8311 JN |
1620 | $paging_nav .= "HEAD"; |
1621 | } | |
1622 | ||
1623 | if ($page > 0) { | |
1624 | $paging_nav .= " ⋅ " . | |
1c2a4f5a | 1625 | $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1), |
26298b5f | 1626 | -accesskey => "p", -title => "Alt-p"}, "prev"); |
717b8311 JN |
1627 | } else { |
1628 | $paging_nav .= " ⋅ prev"; | |
1629 | } | |
1630 | ||
1631 | if ($nrevs >= (100 * ($page+1)-1)) { | |
1632 | $paging_nav .= " ⋅ " . | |
1c2a4f5a | 1633 | $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1), |
26298b5f | 1634 | -accesskey => "n", -title => "Alt-n"}, "next"); |
717b8311 JN |
1635 | } else { |
1636 | $paging_nav .= " ⋅ next"; | |
594e212b | 1637 | } |
717b8311 JN |
1638 | |
1639 | return $paging_nav; | |
594e212b JN |
1640 | } |
1641 | ||
717b8311 JN |
1642 | ## ...................................................................... |
1643 | ## functions printing or outputting HTML: div | |
1644 | ||
847e01fb | 1645 | sub git_print_header_div { |
717b8311 | 1646 | my ($action, $title, $hash, $hash_base) = @_; |
1c2a4f5a | 1647 | my %args = (); |
717b8311 | 1648 | |
1c2a4f5a MW |
1649 | $args{action} = $action; |
1650 | $args{hash} = $hash if $hash; | |
1651 | $args{hash_base} = $hash_base if $hash_base; | |
717b8311 JN |
1652 | |
1653 | print "<div class=\"header\">\n" . | |
1c2a4f5a MW |
1654 | $cgi->a({-href => href(%args), -class => "title"}, |
1655 | $title ? $title : $action) . | |
1656 | "\n</div>\n"; | |
717b8311 | 1657 | } |
ede5e100 | 1658 | |
6fd92a28 JN |
1659 | #sub git_print_authorship (\%) { |
1660 | sub git_print_authorship { | |
1661 | my $co = shift; | |
1662 | ||
a44465cc | 1663 | my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'}); |
6fd92a28 JN |
1664 | print "<div class=\"author_date\">" . |
1665 | esc_html($co->{'author_name'}) . | |
a44465cc JN |
1666 | " [$ad{'rfc2822'}"; |
1667 | if ($ad{'hour_local'} < 6) { | |
1668 | printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", | |
1669 | $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); | |
1670 | } else { | |
1671 | printf(" (%02d:%02d %s)", | |
1672 | $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); | |
1673 | } | |
1674 | print "]</div>\n"; | |
6fd92a28 JN |
1675 | } |
1676 | ||
717b8311 JN |
1677 | sub git_print_page_path { |
1678 | my $name = shift; | |
1679 | my $type = shift; | |
59fb1c94 | 1680 | my $hb = shift; |
ede5e100 | 1681 | |
4df118ed JN |
1682 | |
1683 | print "<div class=\"page_path\">"; | |
1684 | print $cgi->a({-href => href(action=>"tree", hash_base=>$hb), | |
1685 | -title => 'tree root'}, "[$project]"); | |
1686 | print " / "; | |
1687 | if (defined $name) { | |
762c7205 JN |
1688 | my @dirname = split '/', $name; |
1689 | my $basename = pop @dirname; | |
1690 | my $fullname = ''; | |
1691 | ||
762c7205 | 1692 | foreach my $dir (@dirname) { |
16fdb488 | 1693 | $fullname .= ($fullname ? '/' : '') . $dir; |
762c7205 JN |
1694 | print $cgi->a({-href => href(action=>"tree", file_name=>$fullname, |
1695 | hash_base=>$hb), | |
26d0a976 PB |
1696 | -title => $fullname}, esc_html($dir)); |
1697 | print " / "; | |
762c7205 JN |
1698 | } |
1699 | if (defined $type && $type eq 'blob') { | |
952c65fc | 1700 | print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name, |
762c7205 JN |
1701 | hash_base=>$hb), |
1702 | -title => $name}, esc_html($basename)); | |
1703 | } elsif (defined $type && $type eq 'tree') { | |
1704 | print $cgi->a({-href => href(action=>"tree", file_name=>$file_name, | |
1705 | hash_base=>$hb), | |
26d0a976 | 1706 | -title => $name}, esc_html($basename)); |
4df118ed | 1707 | print " / "; |
59fb1c94 | 1708 | } else { |
762c7205 | 1709 | print esc_html($basename); |
59fb1c94 | 1710 | } |
ede5e100 | 1711 | } |
4df118ed | 1712 | print "<br/></div>\n"; |
ede5e100 KS |
1713 | } |
1714 | ||
b7f9253d JN |
1715 | # sub git_print_log (\@;%) { |
1716 | sub git_print_log ($;%) { | |
d16d093c | 1717 | my $log = shift; |
b7f9253d | 1718 | my %opts = @_; |
d16d093c | 1719 | |
b7f9253d JN |
1720 | if ($opts{'-remove_title'}) { |
1721 | # remove title, i.e. first line of log | |
1722 | shift @$log; | |
1723 | } | |
d16d093c JN |
1724 | # remove leading empty lines |
1725 | while (defined $log->[0] && $log->[0] eq "") { | |
1726 | shift @$log; | |
1727 | } | |
1728 | ||
1729 | # print log | |
1730 | my $signoff = 0; | |
1731 | my $empty = 0; | |
1732 | foreach my $line (@$log) { | |
b7f9253d JN |
1733 | if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) { |
1734 | $signoff = 1; | |
fba20b42 | 1735 | $empty = 0; |
b7f9253d JN |
1736 | if (! $opts{'-remove_signoff'}) { |
1737 | print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n"; | |
1738 | next; | |
1739 | } else { | |
1740 | # remove signoff lines | |
1741 | next; | |
1742 | } | |
1743 | } else { | |
1744 | $signoff = 0; | |
1745 | } | |
1746 | ||
d16d093c JN |
1747 | # print only one empty line |
1748 | # do not print empty line after signoff | |
1749 | if ($line eq "") { | |
1750 | next if ($empty || $signoff); | |
1751 | $empty = 1; | |
1752 | } else { | |
1753 | $empty = 0; | |
1754 | } | |
b7f9253d JN |
1755 | |
1756 | print format_log_line_html($line) . "<br/>\n"; | |
1757 | } | |
1758 | ||
1759 | if ($opts{'-final_empty_line'}) { | |
1760 | # end with single empty line | |
1761 | print "<br/>\n" unless $empty; | |
d16d093c JN |
1762 | } |
1763 | } | |
1764 | ||
1765 | sub git_print_simplified_log { | |
1766 | my $log = shift; | |
1767 | my $remove_title = shift; | |
1768 | ||
b7f9253d JN |
1769 | git_print_log($log, |
1770 | -final_empty_line=> 1, | |
b7f9253d | 1771 | -remove_title => $remove_title); |
d16d093c JN |
1772 | } |
1773 | ||
fa702003 JN |
1774 | # print tree entry (row of git_tree), but without encompassing <tr> element |
1775 | sub git_print_tree_entry { | |
1776 | my ($t, $basedir, $hash_base, $have_blame) = @_; | |
1777 | ||
1778 | my %base_key = (); | |
1779 | $base_key{hash_base} = $hash_base if defined $hash_base; | |
1780 | ||
4de741b3 LT |
1781 | # The format of a table row is: mode list link. Where mode is |
1782 | # the mode of the entry, list is the name of the entry, an href, | |
1783 | # and link is the action links of the entry. | |
1784 | ||
fa702003 JN |
1785 | print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n"; |
1786 | if ($t->{'type'} eq "blob") { | |
1787 | print "<td class=\"list\">" . | |
4de741b3 | 1788 | $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'}, |
e7fb022a JN |
1789 | file_name=>"$basedir$t->{'name'}", %base_key), |
1790 | -class => "list"}, esc_html($t->{'name'})) . "</td>\n"; | |
4de741b3 | 1791 | print "<td class=\"link\">"; |
fa702003 | 1792 | if ($have_blame) { |
4de741b3 | 1793 | print $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'}, |
e7fb022a JN |
1794 | file_name=>"$basedir$t->{'name'}", %base_key)}, |
1795 | "blame"); | |
fa702003 JN |
1796 | } |
1797 | if (defined $hash_base) { | |
4de741b3 LT |
1798 | if ($have_blame) { |
1799 | print " | "; | |
1800 | } | |
1801 | print $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, | |
fa702003 JN |
1802 | hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")}, |
1803 | "history"); | |
1804 | } | |
1805 | print " | " . | |
6f7ea5fb | 1806 | $cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base, |
e7fb022a JN |
1807 | file_name=>"$basedir$t->{'name'}")}, |
1808 | "raw"); | |
4de741b3 | 1809 | print "</td>\n"; |
fa702003 JN |
1810 | |
1811 | } elsif ($t->{'type'} eq "tree") { | |
0fa105e7 LT |
1812 | print "<td class=\"list\">"; |
1813 | print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'}, | |
fa702003 | 1814 | file_name=>"$basedir$t->{'name'}", %base_key)}, |
0fa105e7 LT |
1815 | esc_html($t->{'name'})); |
1816 | print "</td>\n"; | |
1817 | print "<td class=\"link\">"; | |
fa702003 | 1818 | if (defined $hash_base) { |
0fa105e7 | 1819 | print $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, |
fa702003 JN |
1820 | file_name=>"$basedir$t->{'name'}")}, |
1821 | "history"); | |
1822 | } | |
1823 | print "</td>\n"; | |
1824 | } | |
1825 | } | |
1826 | ||
717b8311 JN |
1827 | ## ...................................................................... |
1828 | ## functions printing large fragments of HTML | |
1829 | ||
4a4a1a53 | 1830 | sub git_difftree_body { |
eee08903 | 1831 | my ($difftree, $hash, $parent) = @_; |
4a4a1a53 JN |
1832 | |
1833 | print "<div class=\"list_head\">\n"; | |
1834 | if ($#{$difftree} > 10) { | |
1835 | print(($#{$difftree} + 1) . " files changed:\n"); | |
1836 | } | |
1837 | print "</div>\n"; | |
1838 | ||
1839 | print "<table class=\"diff_tree\">\n"; | |
6dd36acd | 1840 | my $alternate = 1; |
b4657e77 | 1841 | my $patchno = 0; |
4a4a1a53 | 1842 | foreach my $line (@{$difftree}) { |
e8e41a93 | 1843 | my %diff = parse_difftree_raw_line($line); |
4a4a1a53 JN |
1844 | |
1845 | if ($alternate) { | |
1846 | print "<tr class=\"dark\">\n"; | |
1847 | } else { | |
1848 | print "<tr class=\"light\">\n"; | |
1849 | } | |
1850 | $alternate ^= 1; | |
1851 | ||
e8e41a93 JN |
1852 | my ($to_mode_oct, $to_mode_str, $to_file_type); |
1853 | my ($from_mode_oct, $from_mode_str, $from_file_type); | |
1854 | if ($diff{'to_mode'} ne ('0' x 6)) { | |
1855 | $to_mode_oct = oct $diff{'to_mode'}; | |
1856 | if (S_ISREG($to_mode_oct)) { # only for regular file | |
1857 | $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits | |
1858 | } | |
1859 | $to_file_type = file_type($diff{'to_mode'}); | |
1860 | } | |
1861 | if ($diff{'from_mode'} ne ('0' x 6)) { | |
1862 | $from_mode_oct = oct $diff{'from_mode'}; | |
1863 | if (S_ISREG($to_mode_oct)) { # only for regular file | |
1864 | $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits | |
4a4a1a53 | 1865 | } |
e8e41a93 JN |
1866 | $from_file_type = file_type($diff{'from_mode'}); |
1867 | } | |
1868 | ||
1869 | if ($diff{'status'} eq "A") { # created | |
1870 | my $mode_chng = "<span class=\"file_status new\">[new $to_file_type"; | |
1871 | $mode_chng .= " with mode: $to_mode_str" if $to_mode_str; | |
1872 | $mode_chng .= "]</span>"; | |
499faeda LT |
1873 | print "<td>"; |
1874 | print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'}, | |
e8e41a93 | 1875 | hash_base=>$hash, file_name=>$diff{'file'}), |
e7fb022a | 1876 | -class => "list"}, esc_html($diff{'file'})); |
499faeda LT |
1877 | print "</td>\n"; |
1878 | print "<td>$mode_chng</td>\n"; | |
1879 | print "<td class=\"link\">"; | |
72dbafa1 | 1880 | if ($action eq 'commitdiff') { |
b4657e77 JN |
1881 | # link to patch |
1882 | $patchno++; | |
499faeda | 1883 | print $cgi->a({-href => "#patch$patchno"}, "patch"); |
b4657e77 JN |
1884 | } |
1885 | print "</td>\n"; | |
4a4a1a53 | 1886 | |
e8e41a93 JN |
1887 | } elsif ($diff{'status'} eq "D") { # deleted |
1888 | my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>"; | |
499faeda LT |
1889 | print "<td>"; |
1890 | print $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'}, | |
e8e41a93 | 1891 | hash_base=>$parent, file_name=>$diff{'file'}), |
499faeda LT |
1892 | -class => "list"}, esc_html($diff{'file'})); |
1893 | print "</td>\n"; | |
1894 | print "<td>$mode_chng</td>\n"; | |
1895 | print "<td class=\"link\">"; | |
72dbafa1 | 1896 | if ($action eq 'commitdiff') { |
b4657e77 JN |
1897 | # link to patch |
1898 | $patchno++; | |
499faeda LT |
1899 | print $cgi->a({-href => "#patch$patchno"}, "patch"); |
1900 | print " | "; | |
b4657e77 | 1901 | } |
eb51ec9c | 1902 | print $cgi->a({-href => href(action=>"blame", hash_base=>$parent, |
e7fb022a JN |
1903 | file_name=>$diff{'file'})}, |
1904 | "blame") . " | "; | |
b4657e77 | 1905 | print $cgi->a({-href => href(action=>"history", hash_base=>$parent, |
e7fb022a JN |
1906 | file_name=>$diff{'file'})}, |
1907 | "history"); | |
499faeda | 1908 | print "</td>\n"; |
4a4a1a53 | 1909 | |
e8e41a93 | 1910 | } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed |
4a4a1a53 | 1911 | my $mode_chnge = ""; |
e8e41a93 JN |
1912 | if ($diff{'from_mode'} != $diff{'to_mode'}) { |
1913 | $mode_chnge = "<span class=\"file_status mode_chnge\">[changed"; | |
1914 | if ($from_file_type != $to_file_type) { | |
1915 | $mode_chnge .= " from $from_file_type to $to_file_type"; | |
4a4a1a53 | 1916 | } |
e8e41a93 JN |
1917 | if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) { |
1918 | if ($from_mode_str && $to_mode_str) { | |
1919 | $mode_chnge .= " mode: $from_mode_str->$to_mode_str"; | |
1920 | } elsif ($to_mode_str) { | |
1921 | $mode_chnge .= " mode: $to_mode_str"; | |
4a4a1a53 JN |
1922 | } |
1923 | } | |
1924 | $mode_chnge .= "]</span>\n"; | |
1925 | } | |
1926 | print "<td>"; | |
499faeda | 1927 | print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'}, |
e7fb022a JN |
1928 | hash_base=>$hash, file_name=>$diff{'file'}), |
1929 | -class => "list"}, esc_html($diff{'file'})); | |
499faeda LT |
1930 | print "</td>\n"; |
1931 | print "<td>$mode_chnge</td>\n"; | |
1932 | print "<td class=\"link\">"; | |
e8e41a93 | 1933 | if ($diff{'to_id'} ne $diff{'from_id'}) { # modified |
72dbafa1 | 1934 | if ($action eq 'commitdiff') { |
b4657e77 JN |
1935 | # link to patch |
1936 | $patchno++; | |
499faeda | 1937 | print $cgi->a({-href => "#patch$patchno"}, "patch"); |
b4657e77 | 1938 | } else { |
499faeda | 1939 | print $cgi->a({-href => href(action=>"blobdiff", |
e7fb022a JN |
1940 | hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'}, |
1941 | hash_base=>$hash, hash_parent_base=>$parent, | |
1942 | file_name=>$diff{'file'})}, | |
1943 | "diff"); | |
b4657e77 | 1944 | } |
499faeda | 1945 | print " | "; |
4a4a1a53 | 1946 | } |
eb51ec9c | 1947 | print $cgi->a({-href => href(action=>"blame", hash_base=>$hash, |
e7fb022a JN |
1948 | file_name=>$diff{'file'})}, |
1949 | "blame") . " | "; | |
eb51ec9c | 1950 | print $cgi->a({-href => href(action=>"history", hash_base=>$hash, |
e7fb022a JN |
1951 | file_name=>$diff{'file'})}, |
1952 | "history"); | |
4a4a1a53 JN |
1953 | print "</td>\n"; |
1954 | ||
e8e41a93 JN |
1955 | } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied |
1956 | my %status_name = ('R' => 'moved', 'C' => 'copied'); | |
1957 | my $nstatus = $status_name{$diff{'status'}}; | |
4a4a1a53 | 1958 | my $mode_chng = ""; |
e8e41a93 JN |
1959 | if ($diff{'from_mode'} != $diff{'to_mode'}) { |
1960 | # mode also for directories, so we cannot use $to_mode_str | |
1961 | $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777); | |
4a4a1a53 JN |
1962 | } |
1963 | print "<td>" . | |
e8e41a93 JN |
1964 | $cgi->a({-href => href(action=>"blob", hash_base=>$hash, |
1965 | hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}), | |
1966 | -class => "list"}, esc_html($diff{'to_file'})) . "</td>\n" . | |
1967 | "<td><span class=\"file_status $nstatus\">[$nstatus from " . | |
1968 | $cgi->a({-href => href(action=>"blob", hash_base=>$parent, | |
1969 | hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}), | |
1970 | -class => "list"}, esc_html($diff{'from_file'})) . | |
1971 | " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" . | |
499faeda | 1972 | "<td class=\"link\">"; |
e8e41a93 | 1973 | if ($diff{'to_id'} ne $diff{'from_id'}) { |
72dbafa1 | 1974 | if ($action eq 'commitdiff') { |
b4657e77 JN |
1975 | # link to patch |
1976 | $patchno++; | |
eb51ec9c | 1977 | print $cgi->a({-href => "#patch$patchno"}, "patch"); |
b4657e77 | 1978 | } else { |
eb51ec9c | 1979 | print $cgi->a({-href => href(action=>"blobdiff", |
e7fb022a JN |
1980 | hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'}, |
1981 | hash_base=>$hash, hash_parent_base=>$parent, | |
1982 | file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})}, | |
1983 | "diff"); | |
b4657e77 | 1984 | } |
eb51ec9c | 1985 | print " | "; |
4a4a1a53 | 1986 | } |
eb51ec9c | 1987 | print $cgi->a({-href => href(action=>"blame", hash_base=>$parent, |
e7fb022a JN |
1988 | file_name=>$diff{'from_file'})}, |
1989 | "blame") . " | "; | |
eb51ec9c | 1990 | print $cgi->a({-href => href(action=>"history", hash_base=>$parent, |
e7fb022a JN |
1991 | file_name=>$diff{'from_file'})}, |
1992 | "history"); | |
4a4a1a53 | 1993 | print "</td>\n"; |
e8e41a93 | 1994 | |
4a4a1a53 JN |
1995 | } # we should not encounter Unmerged (U) or Unknown (X) status |
1996 | print "</tr>\n"; | |
1997 | } | |
1998 | print "</table>\n"; | |
1999 | } | |
2000 | ||
eee08903 | 2001 | sub git_patchset_body { |
157e43b4 | 2002 | my ($fd, $difftree, $hash, $hash_parent) = @_; |
eee08903 JN |
2003 | |
2004 | my $patch_idx = 0; | |
2005 | my $in_header = 0; | |
2006 | my $patch_found = 0; | |
fe87585e | 2007 | my $diffinfo; |
eee08903 JN |
2008 | |
2009 | print "<div class=\"patchset\">\n"; | |
2010 | ||
157e43b4 | 2011 | LINE: |
c8a99d76 | 2012 | while (my $patch_line = <$fd>) { |
157e43b4 | 2013 | chomp $patch_line; |
eee08903 JN |
2014 | |
2015 | if ($patch_line =~ m/^diff /) { # "git diff" header | |
2016 | # beginning of patch (in patchset) | |
2017 | if ($patch_found) { | |
2018 | # close previous patch | |
2019 | print "</div>\n"; # class="patch" | |
2020 | } else { | |
2021 | # first patch in patchset | |
2022 | $patch_found = 1; | |
2023 | } | |
b4657e77 | 2024 | print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n"; |
eee08903 | 2025 | |
fe87585e JN |
2026 | if (ref($difftree->[$patch_idx]) eq "HASH") { |
2027 | $diffinfo = $difftree->[$patch_idx]; | |
2028 | } else { | |
2029 | $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]); | |
2030 | } | |
2031 | $patch_idx++; | |
eee08903 JN |
2032 | |
2033 | # for now, no extended header, hence we skip empty patches | |
2034 | # companion to next LINE if $in_header; | |
fe87585e | 2035 | if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change |
eee08903 JN |
2036 | $in_header = 1; |
2037 | next LINE; | |
2038 | } | |
2039 | ||
fe87585e JN |
2040 | if ($diffinfo->{'status'} eq "A") { # added |
2041 | print "<div class=\"diff_info\">" . file_type($diffinfo->{'to_mode'}) . ":" . | |
eee08903 | 2042 | $cgi->a({-href => href(action=>"blob", hash_base=>$hash, |
fe87585e | 2043 | hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})}, |
689b7f5c | 2044 | $diffinfo->{'to_id'}) . " (new)" . |
eee08903 JN |
2045 | "</div>\n"; # class="diff_info" |
2046 | ||
fe87585e JN |
2047 | } elsif ($diffinfo->{'status'} eq "D") { # deleted |
2048 | print "<div class=\"diff_info\">" . file_type($diffinfo->{'from_mode'}) . ":" . | |
eee08903 | 2049 | $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent, |
fe87585e | 2050 | hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})}, |
689b7f5c | 2051 | $diffinfo->{'from_id'}) . " (deleted)" . |
eee08903 JN |
2052 | "</div>\n"; # class="diff_info" |
2053 | ||
fe87585e | 2054 | } elsif ($diffinfo->{'status'} eq "R" || # renamed |
7c5e2ebb JN |
2055 | $diffinfo->{'status'} eq "C" || # copied |
2056 | $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff) | |
eee08903 | 2057 | print "<div class=\"diff_info\">" . |
fe87585e | 2058 | file_type($diffinfo->{'from_mode'}) . ":" . |
eee08903 | 2059 | $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent, |
fe87585e JN |
2060 | hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'from_file'})}, |
2061 | $diffinfo->{'from_id'}) . | |
eee08903 | 2062 | " -> " . |
fe87585e | 2063 | file_type($diffinfo->{'to_mode'}) . ":" . |
eee08903 | 2064 | $cgi->a({-href => href(action=>"blob", hash_base=>$hash, |
fe87585e JN |
2065 | hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'to_file'})}, |
2066 | $diffinfo->{'to_id'}); | |
eee08903 JN |
2067 | print "</div>\n"; # class="diff_info" |
2068 | ||
2069 | } else { # modified, mode changed, ... | |
2070 | print "<div class=\"diff_info\">" . | |
fe87585e | 2071 | file_type($diffinfo->{'from_mode'}) . ":" . |
eee08903 | 2072 | $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent, |
fe87585e JN |
2073 | hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})}, |
2074 | $diffinfo->{'from_id'}) . | |
eee08903 | 2075 | " -> " . |
fe87585e | 2076 | file_type($diffinfo->{'to_mode'}) . ":" . |
eee08903 | 2077 | $cgi->a({-href => href(action=>"blob", hash_base=>$hash, |
fe87585e JN |
2078 | hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})}, |
2079 | $diffinfo->{'to_id'}); | |
eee08903 JN |
2080 | print "</div>\n"; # class="diff_info" |
2081 | } | |
2082 | ||
2083 | #print "<div class=\"diff extended_header\">\n"; | |
2084 | $in_header = 1; | |
2085 | next LINE; | |
2086 | } # start of patch in patchset | |
2087 | ||
2088 | ||
2089 | if ($in_header && $patch_line =~ m/^---/) { | |
e4e4f825 | 2090 | #print "</div>\n"; # class="diff extended_header" |
eee08903 | 2091 | $in_header = 0; |
e4e4f825 JN |
2092 | |
2093 | my $file = $diffinfo->{'from_file'}; | |
2094 | $file ||= $diffinfo->{'file'}; | |
ef10ee87 JN |
2095 | $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent, |
2096 | hash=>$diffinfo->{'from_id'}, file_name=>$file), | |
2097 | -class => "list"}, esc_html($file)); | |
2098 | $patch_line =~ s|a/.*$|a/$file|g; | |
2099 | print "<div class=\"diff from_file\">$patch_line</div>\n"; | |
e4e4f825 JN |
2100 | |
2101 | $patch_line = <$fd>; | |
2102 | chomp $patch_line; | |
2103 | ||
2104 | #$patch_line =~ m/^+++/; | |
2105 | $file = $diffinfo->{'to_file'}; | |
2106 | $file ||= $diffinfo->{'file'}; | |
ef10ee87 JN |
2107 | $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash, |
2108 | hash=>$diffinfo->{'to_id'}, file_name=>$file), | |
2109 | -class => "list"}, esc_html($file)); | |
2110 | $patch_line =~ s|b/.*|b/$file|g; | |
2111 | print "<div class=\"diff to_file\">$patch_line</div>\n"; | |
e4e4f825 JN |
2112 | |
2113 | next LINE; | |
eee08903 JN |
2114 | } |
2115 | next LINE if $in_header; | |
2116 | ||
2117 | print format_diff_line($patch_line); | |
2118 | } | |
2119 | print "</div>\n" if $patch_found; # class="patch" | |
2120 | ||
2121 | print "</div>\n"; # class="patchset" | |
2122 | } | |
2123 | ||
2124 | # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | |
2125 | ||
9f5dcb81 JN |
2126 | sub git_shortlog_body { |
2127 | # uses global variable $project | |
2128 | my ($revlist, $from, $to, $refs, $extra) = @_; | |
ddb8d900 | 2129 | |
9f5dcb81 JN |
2130 | $from = 0 unless defined $from; |
2131 | $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to); | |
2132 | ||
2133 | print "<table class=\"shortlog\" cellspacing=\"0\">\n"; | |
6dd36acd | 2134 | my $alternate = 1; |
9f5dcb81 JN |
2135 | for (my $i = $from; $i <= $to; $i++) { |
2136 | my $commit = $revlist->[$i]; | |
847e01fb JN |
2137 | #my $ref = defined $refs ? format_ref_marker($refs, $commit) : ''; |
2138 | my $ref = format_ref_marker($refs, $commit); | |
2139 | my %co = parse_commit($commit); | |
9f5dcb81 JN |
2140 | if ($alternate) { |
2141 | print "<tr class=\"dark\">\n"; | |
2142 | } else { | |
2143 | print "<tr class=\"light\">\n"; | |
2144 | } | |
2145 | $alternate ^= 1; | |
2146 | # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" . | |
2147 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . | |
2148 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" . | |
2149 | "<td>"; | |
952c65fc JN |
2150 | print format_subject_html($co{'title'}, $co{'title_short'}, |
2151 | href(action=>"commit", hash=>$commit), $ref); | |
9f5dcb81 JN |
2152 | print "</td>\n" . |
2153 | "<td class=\"link\">" . | |
35749ae5 | 2154 | $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " . |
55ff35cb PB |
2155 | $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree"); |
2156 | if (gitweb_have_snapshot()) { | |
2157 | print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot"); | |
2158 | } | |
cb9c6e5b | 2159 | print "</td>\n" . |
9f5dcb81 JN |
2160 | "</tr>\n"; |
2161 | } | |
2162 | if (defined $extra) { | |
2163 | print "<tr>\n" . | |
2164 | "<td colspan=\"4\">$extra</td>\n" . | |
2165 | "</tr>\n"; | |
2166 | } | |
2167 | print "</table>\n"; | |
2168 | } | |
2169 | ||
581860e1 JN |
2170 | sub git_history_body { |
2171 | # Warning: assumes constant type (blob or tree) during history | |
8be68352 JN |
2172 | my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_; |
2173 | ||
2174 | $from = 0 unless defined $from; | |
2175 | $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist}); | |
581860e1 JN |
2176 | |
2177 | print "<table class=\"history\" cellspacing=\"0\">\n"; | |
6dd36acd | 2178 | my $alternate = 1; |
8be68352 JN |
2179 | for (my $i = $from; $i <= $to; $i++) { |
2180 | if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) { | |
581860e1 JN |
2181 | next; |
2182 | } | |
2183 | ||
2184 | my $commit = $1; | |
2185 | my %co = parse_commit($commit); | |
2186 | if (!%co) { | |
2187 | next; | |
2188 | } | |
2189 | ||
2190 | my $ref = format_ref_marker($refs, $commit); | |
2191 | ||
2192 | if ($alternate) { | |
2193 | print "<tr class=\"dark\">\n"; | |
2194 | } else { | |
2195 | print "<tr class=\"light\">\n"; | |
2196 | } | |
2197 | $alternate ^= 1; | |
2198 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . | |
2199 | # shortlog uses chop_str($co{'author_name'}, 10) | |
2200 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" . | |
2201 | "<td>"; | |
2202 | # originally git_history used chop_str($co{'title'}, 50) | |
952c65fc JN |
2203 | print format_subject_html($co{'title'}, $co{'title_short'}, |
2204 | href(action=>"commit", hash=>$commit), $ref); | |
581860e1 JN |
2205 | print "</td>\n" . |
2206 | "<td class=\"link\">" . | |
6d81c5a2 LT |
2207 | $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype) . " | " . |
2208 | $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff"); | |
581860e1 JN |
2209 | |
2210 | if ($ftype eq 'blob') { | |
2211 | my $blob_current = git_get_hash_by_path($hash_base, $file_name); | |
2212 | my $blob_parent = git_get_hash_by_path($commit, $file_name); | |
2213 | if (defined $blob_current && defined $blob_parent && | |
2214 | $blob_current ne $blob_parent) { | |
2215 | print " | " . | |
420e92f2 JN |
2216 | $cgi->a({-href => href(action=>"blobdiff", |
2217 | hash=>$blob_current, hash_parent=>$blob_parent, | |
2218 | hash_base=>$hash_base, hash_parent_base=>$commit, | |
2219 | file_name=>$file_name)}, | |
581860e1 JN |
2220 | "diff to current"); |
2221 | } | |
2222 | } | |
2223 | print "</td>\n" . | |
2224 | "</tr>\n"; | |
2225 | } | |
2226 | if (defined $extra) { | |
2227 | print "<tr>\n" . | |
2228 | "<td colspan=\"4\">$extra</td>\n" . | |
2229 | "</tr>\n"; | |
2230 | } | |
2231 | print "</table>\n"; | |
2232 | } | |
2233 | ||
717b8311 JN |
2234 | sub git_tags_body { |
2235 | # uses global variable $project | |
2236 | my ($taglist, $from, $to, $extra) = @_; | |
2237 | $from = 0 unless defined $from; | |
2238 | $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to); | |
2239 | ||
2240 | print "<table class=\"tags\" cellspacing=\"0\">\n"; | |
6dd36acd | 2241 | my $alternate = 1; |
717b8311 JN |
2242 | for (my $i = $from; $i <= $to; $i++) { |
2243 | my $entry = $taglist->[$i]; | |
2244 | my %tag = %$entry; | |
2245 | my $comment_lines = $tag{'comment'}; | |
2246 | my $comment = shift @$comment_lines; | |
2247 | my $comment_short; | |
2248 | if (defined $comment) { | |
2249 | $comment_short = chop_str($comment, 30, 5); | |
2250 | } | |
2251 | if ($alternate) { | |
2252 | print "<tr class=\"dark\">\n"; | |
2253 | } else { | |
2254 | print "<tr class=\"light\">\n"; | |
2255 | } | |
2256 | $alternate ^= 1; | |
2257 | print "<td><i>$tag{'age'}</i></td>\n" . | |
2258 | "<td>" . | |
1c2a4f5a | 2259 | $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}), |
63e4220b | 2260 | -class => "list name"}, esc_html($tag{'name'})) . |
717b8311 JN |
2261 | "</td>\n" . |
2262 | "<td>"; | |
2263 | if (defined $comment) { | |
952c65fc JN |
2264 | print format_subject_html($comment, $comment_short, |
2265 | href(action=>"tag", hash=>$tag{'id'})); | |
717b8311 JN |
2266 | } |
2267 | print "</td>\n" . | |
2268 | "<td class=\"selflink\">"; | |
2269 | if ($tag{'type'} eq "tag") { | |
1c2a4f5a | 2270 | print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag"); |
717b8311 JN |
2271 | } else { |
2272 | print " "; | |
2273 | } | |
2274 | print "</td>\n" . | |
2275 | "<td class=\"link\">" . " | " . | |
1c2a4f5a | 2276 | $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'}); |
717b8311 | 2277 | if ($tag{'reftype'} eq "commit") { |
1c2a4f5a MW |
2278 | print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . |
2279 | " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'refid'})}, "log"); | |
717b8311 | 2280 | } elsif ($tag{'reftype'} eq "blob") { |
1c2a4f5a | 2281 | print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw"); |
717b8311 JN |
2282 | } |
2283 | print "</td>\n" . | |
2284 | "</tr>"; | |
2285 | } | |
2286 | if (defined $extra) { | |
2287 | print "<tr>\n" . | |
2288 | "<td colspan=\"5\">$extra</td>\n" . | |
2289 | "</tr>\n"; | |
2290 | } | |
2291 | print "</table>\n"; | |
2292 | } | |
2293 | ||
2294 | sub git_heads_body { | |
2295 | # uses global variable $project | |
120ddde2 | 2296 | my ($headlist, $head, $from, $to, $extra) = @_; |
717b8311 | 2297 | $from = 0 unless defined $from; |
120ddde2 | 2298 | $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to); |
717b8311 JN |
2299 | |
2300 | print "<table class=\"heads\" cellspacing=\"0\">\n"; | |
6dd36acd | 2301 | my $alternate = 1; |
717b8311 | 2302 | for (my $i = $from; $i <= $to; $i++) { |
120ddde2 | 2303 | my $entry = $headlist->[$i]; |
717b8311 JN |
2304 | my %tag = %$entry; |
2305 | my $curr = $tag{'id'} eq $head; | |
2306 | if ($alternate) { | |
2307 | print "<tr class=\"dark\">\n"; | |
2308 | } else { | |
2309 | print "<tr class=\"light\">\n"; | |
2310 | } | |
2311 | $alternate ^= 1; | |
2312 | print "<td><i>$tag{'age'}</i></td>\n" . | |
2313 | ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") . | |
1c2a4f5a | 2314 | $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'}), |
63e4220b | 2315 | -class => "list name"},esc_html($tag{'name'})) . |
717b8311 JN |
2316 | "</td>\n" . |
2317 | "<td class=\"link\">" . | |
1c2a4f5a | 2318 | $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " . |
1d62be25 PB |
2319 | $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") . " | " . |
2320 | $cgi->a({-href => href(action=>"tree", hash=>$tag{'name'}, hash_base=>$tag{'name'})}, "tree") . | |
717b8311 JN |
2321 | "</td>\n" . |
2322 | "</tr>"; | |
2323 | } | |
2324 | if (defined $extra) { | |
2325 | print "<tr>\n" . | |
2326 | "<td colspan=\"3\">$extra</td>\n" . | |
2327 | "</tr>\n"; | |
2328 | } | |
2329 | print "</table>\n"; | |
2330 | } | |
2331 | ||
717b8311 JN |
2332 | ## ====================================================================== |
2333 | ## ====================================================================== | |
2334 | ## actions | |
2335 | ||
717b8311 | 2336 | sub git_project_list { |
6326b60c JN |
2337 | my $order = $cgi->param('o'); |
2338 | if (defined $order && $order !~ m/project|descr|owner|age/) { | |
e2860ead | 2339 | die_error(undef, "Unknown order parameter"); |
6326b60c JN |
2340 | } |
2341 | ||
847e01fb | 2342 | my @list = git_get_projects_list(); |
717b8311 JN |
2343 | my @projects; |
2344 | if (!@list) { | |
cac4bd94 | 2345 | die_error(undef, "No projects found"); |
717b8311 JN |
2346 | } |
2347 | foreach my $pr (@list) { | |
63e02a1b JH |
2348 | my (@aa) = git_get_last_activity($pr->{'path'}); |
2349 | unless (@aa) { | |
717b8311 | 2350 | next; |
9f5dcb81 | 2351 | } |
63e02a1b | 2352 | ($pr->{'age'}, $pr->{'age_string'}) = @aa; |
717b8311 | 2353 | if (!defined $pr->{'descr'}) { |
847e01fb | 2354 | my $descr = git_get_project_description($pr->{'path'}) || ""; |
717b8311 | 2355 | $pr->{'descr'} = chop_str($descr, 25, 5); |
9f5dcb81 | 2356 | } |
717b8311 JN |
2357 | if (!defined $pr->{'owner'}) { |
2358 | $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || ""; | |
9f5dcb81 | 2359 | } |
717b8311 | 2360 | push @projects, $pr; |
9f5dcb81 | 2361 | } |
6326b60c | 2362 | |
717b8311 JN |
2363 | git_header_html(); |
2364 | if (-f $home_text) { | |
2365 | print "<div class=\"index_include\">\n"; | |
2366 | open (my $fd, $home_text); | |
2367 | print <$fd>; | |
2368 | close $fd; | |
2369 | print "</div>\n"; | |
9f5dcb81 | 2370 | } |
717b8311 JN |
2371 | print "<table class=\"project_list\">\n" . |
2372 | "<tr>\n"; | |
6326b60c JN |
2373 | $order ||= "project"; |
2374 | if ($order eq "project") { | |
717b8311 JN |
2375 | @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects; |
2376 | print "<th>Project</th>\n"; | |
2377 | } else { | |
6326b60c | 2378 | print "<th>" . |
a1565c44 | 2379 | $cgi->a({-href => href(project=>undef, order=>'project'), |
6326b60c JN |
2380 | -class => "header"}, "Project") . |
2381 | "</th>\n"; | |
717b8311 | 2382 | } |
6326b60c | 2383 | if ($order eq "descr") { |
717b8311 JN |
2384 | @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects; |
2385 | print "<th>Description</th>\n"; | |
2386 | } else { | |
6326b60c | 2387 | print "<th>" . |
a1565c44 | 2388 | $cgi->a({-href => href(project=>undef, order=>'descr'), |
6326b60c JN |
2389 | -class => "header"}, "Description") . |
2390 | "</th>\n"; | |
717b8311 | 2391 | } |
6326b60c | 2392 | if ($order eq "owner") { |
717b8311 JN |
2393 | @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects; |
2394 | print "<th>Owner</th>\n"; | |
2395 | } else { | |
6326b60c | 2396 | print "<th>" . |
a1565c44 | 2397 | $cgi->a({-href => href(project=>undef, order=>'owner'), |
6326b60c JN |
2398 | -class => "header"}, "Owner") . |
2399 | "</th>\n"; | |
717b8311 | 2400 | } |
6326b60c | 2401 | if ($order eq "age") { |
63e02a1b | 2402 | @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects; |
717b8311 JN |
2403 | print "<th>Last Change</th>\n"; |
2404 | } else { | |
6326b60c | 2405 | print "<th>" . |
a1565c44 | 2406 | $cgi->a({-href => href(project=>undef, order=>'age'), |
6326b60c JN |
2407 | -class => "header"}, "Last Change") . |
2408 | "</th>\n"; | |
717b8311 JN |
2409 | } |
2410 | print "<th></th>\n" . | |
2411 | "</tr>\n"; | |
6dd36acd | 2412 | my $alternate = 1; |
717b8311 | 2413 | foreach my $pr (@projects) { |
9f5dcb81 JN |
2414 | if ($alternate) { |
2415 | print "<tr class=\"dark\">\n"; | |
2416 | } else { | |
2417 | print "<tr class=\"light\">\n"; | |
2418 | } | |
2419 | $alternate ^= 1; | |
756d2f06 | 2420 | print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"), |
6326b60c | 2421 | -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" . |
717b8311 JN |
2422 | "<td>" . esc_html($pr->{'descr'}) . "</td>\n" . |
2423 | "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n"; | |
63e02a1b JH |
2424 | print "<td class=\"". age_class($pr->{'age'}) . "\">" . |
2425 | $pr->{'age_string'} . "</td>\n" . | |
9f5dcb81 | 2426 | "<td class=\"link\">" . |
756d2f06 MW |
2427 | $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " . |
2428 | $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " . | |
609ff267 PB |
2429 | $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " . |
2430 | $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") . | |
9f5dcb81 | 2431 | "</td>\n" . |
9f5dcb81 JN |
2432 | "</tr>\n"; |
2433 | } | |
2434 | print "</table>\n"; | |
717b8311 | 2435 | git_footer_html(); |
9f5dcb81 JN |
2436 | } |
2437 | ||
fc2b2be0 JN |
2438 | sub git_project_index { |
2439 | my @projects = git_get_projects_list(); | |
2440 | ||
2441 | print $cgi->header( | |
2442 | -type => 'text/plain', | |
2443 | -charset => 'utf-8', | |
ab41dfbf | 2444 | -content_disposition => 'inline; filename="index.aux"'); |
fc2b2be0 JN |
2445 | |
2446 | foreach my $pr (@projects) { | |
2447 | if (!exists $pr->{'owner'}) { | |
2448 | $pr->{'owner'} = get_file_owner("$projectroot/$project"); | |
2449 | } | |
2450 | ||
2451 | my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'}); | |
2452 | # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' ' | |
2453 | $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg; | |
2454 | $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg; | |
2455 | $path =~ s/ /\+/g; | |
2456 | $owner =~ s/ /\+/g; | |
2457 | ||
2458 | print "$path $owner\n"; | |
2459 | } | |
2460 | } | |
2461 | ||
ede5e100 | 2462 | sub git_summary { |
847e01fb JN |
2463 | my $descr = git_get_project_description($project) || "none"; |
2464 | my $head = git_get_head_hash($project); | |
2465 | my %co = parse_commit($head); | |
2466 | my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'}); | |
ede5e100 | 2467 | |
1e0cf030 | 2468 | my $owner = git_get_project_owner($project); |
ede5e100 | 2469 | |
120ddde2 JN |
2470 | my ($reflist, $refs) = git_get_refs_list(); |
2471 | ||
2472 | my @taglist; | |
2473 | my @headlist; | |
2474 | foreach my $ref (@$reflist) { | |
2475 | if ($ref->{'name'} =~ s!^heads/!!) { | |
2476 | push @headlist, $ref; | |
2477 | } else { | |
2478 | $ref->{'name'} =~ s!^tags/!!; | |
2479 | push @taglist, $ref; | |
2480 | } | |
2481 | } | |
2482 | ||
ede5e100 | 2483 | git_header_html(); |
847e01fb | 2484 | git_print_page_nav('summary','', $head); |
9f5dcb81 | 2485 | |
19806691 | 2486 | print "<div class=\"title\"> </div>\n"; |
bddec01d | 2487 | print "<table cellspacing=\"0\">\n" . |
40c13813 | 2488 | "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" . |
ede5e100 | 2489 | "<tr><td>owner</td><td>$owner</td></tr>\n" . |
19a8721e | 2490 | "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n"; |
e79ca7cc JN |
2491 | # use per project git URL list in $projectroot/$project/cloneurl |
2492 | # or make project git URL from git base URL and project name | |
19a8721e | 2493 | my $url_tag = "URL"; |
e79ca7cc JN |
2494 | my @url_list = git_get_project_url_list($project); |
2495 | @url_list = map { "$_/$project" } @git_base_url_list unless @url_list; | |
2496 | foreach my $git_url (@url_list) { | |
2497 | next unless $git_url; | |
2498 | print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n"; | |
19a8721e JN |
2499 | $url_tag = ""; |
2500 | } | |
2501 | print "</table>\n"; | |
9f5dcb81 | 2502 | |
25691fbe DS |
2503 | open my $fd, "-|", git_cmd(), "rev-list", "--max-count=17", |
2504 | git_get_head_hash($project) | |
cac4bd94 | 2505 | or die_error(undef, "Open git-rev-list failed"); |
0881d2d1 | 2506 | my @revlist = map { chomp; $_ } <$fd>; |
ede5e100 | 2507 | close $fd; |
847e01fb | 2508 | git_print_header_div('shortlog'); |
9f5dcb81 | 2509 | git_shortlog_body(\@revlist, 0, 15, $refs, |
1c2a4f5a | 2510 | $cgi->a({-href => href(action=>"shortlog")}, "...")); |
ede5e100 | 2511 | |
120ddde2 | 2512 | if (@taglist) { |
847e01fb | 2513 | git_print_header_div('tags'); |
120ddde2 | 2514 | git_tags_body(\@taglist, 0, 15, |
1c2a4f5a | 2515 | $cgi->a({-href => href(action=>"tags")}, "...")); |
ede5e100 | 2516 | } |
0db37973 | 2517 | |
120ddde2 | 2518 | if (@headlist) { |
847e01fb | 2519 | git_print_header_div('heads'); |
120ddde2 | 2520 | git_heads_body(\@headlist, $head, 0, 15, |
1c2a4f5a | 2521 | $cgi->a({-href => href(action=>"heads")}, "...")); |
0db37973 | 2522 | } |
9f5dcb81 | 2523 | |
ede5e100 KS |
2524 | git_footer_html(); |
2525 | } | |
2526 | ||
d8a20ba9 | 2527 | sub git_tag { |
847e01fb | 2528 | my $head = git_get_head_hash($project); |
d8a20ba9 | 2529 | git_header_html(); |
847e01fb JN |
2530 | git_print_page_nav('','', $head,undef,$head); |
2531 | my %tag = parse_tag($hash); | |
2532 | git_print_header_div('commit', esc_html($tag{'name'}), $hash); | |
d8a20ba9 KS |
2533 | print "<div class=\"title_text\">\n" . |
2534 | "<table cellspacing=\"0\">\n" . | |
e4669df9 KS |
2535 | "<tr>\n" . |
2536 | "<td>object</td>\n" . | |
952c65fc JN |
2537 | "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})}, |
2538 | $tag{'object'}) . "</td>\n" . | |
2539 | "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})}, | |
2540 | $tag{'type'}) . "</td>\n" . | |
e4669df9 | 2541 | "</tr>\n"; |
d8a20ba9 | 2542 | if (defined($tag{'author'})) { |
847e01fb | 2543 | my %ad = parse_date($tag{'epoch'}, $tag{'tz'}); |
40c13813 | 2544 | print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n"; |
952c65fc JN |
2545 | print "<tr><td></td><td>" . $ad{'rfc2822'} . |
2546 | sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . | |
2547 | "</td></tr>\n"; | |
d8a20ba9 KS |
2548 | } |
2549 | print "</table>\n\n" . | |
2550 | "</div>\n"; | |
2551 | print "<div class=\"page_body\">"; | |
2552 | my $comment = $tag{'comment'}; | |
2553 | foreach my $line (@$comment) { | |
40c13813 | 2554 | print esc_html($line) . "<br/>\n"; |
d8a20ba9 KS |
2555 | } |
2556 | print "</div>\n"; | |
2557 | git_footer_html(); | |
2558 | } | |
2559 | ||
1f2857ea LT |
2560 | sub git_blame2 { |
2561 | my $fd; | |
2562 | my $ftype; | |
ddb8d900 | 2563 | |
1d3fc68a AK |
2564 | my ($have_blame) = gitweb_check_feature('blame'); |
2565 | if (!$have_blame) { | |
ddb8d900 AK |
2566 | die_error('403 Permission denied', "Permission denied"); |
2567 | } | |
1f2857ea | 2568 | die_error('404 Not Found', "File name not defined") if (!$file_name); |
847e01fb | 2569 | $hash_base ||= git_get_head_hash($project); |
cac4bd94 | 2570 | die_error(undef, "Couldn't find base commit") unless ($hash_base); |
847e01fb | 2571 | my %co = parse_commit($hash_base) |
1f2857ea LT |
2572 | or die_error(undef, "Reading commit failed"); |
2573 | if (!defined $hash) { | |
2574 | $hash = git_get_hash_by_path($hash_base, $file_name, "blob") | |
2575 | or die_error(undef, "Error looking up file"); | |
2576 | } | |
2577 | $ftype = git_get_type($hash); | |
2578 | if ($ftype !~ "blob") { | |
e484a2d6 | 2579 | die_error("400 Bad Request", "Object is not a blob"); |
1f2857ea | 2580 | } |
a2f3db2f | 2581 | open ($fd, "-|", git_cmd(), "blame", '-l', '--', $file_name, $hash_base) |
cac4bd94 | 2582 | or die_error(undef, "Open git-blame failed"); |
1f2857ea | 2583 | git_header_html(); |
0d83ddc4 | 2584 | my $formats_nav = |
952c65fc JN |
2585 | $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, |
2586 | "blob") . | |
2587 | " | " . | |
cae1862a PB |
2588 | $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, |
2589 | "history") . | |
2590 | " | " . | |
952c65fc | 2591 | $cgi->a({-href => href(action=>"blame", file_name=>$file_name)}, |
f35274da | 2592 | "HEAD"); |
847e01fb JN |
2593 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); |
2594 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
59fb1c94 | 2595 | git_print_page_path($file_name, $ftype, $hash_base); |
82f930de | 2596 | my @rev_color = (qw(light2 dark2)); |
cc1bf97e LT |
2597 | my $num_colors = scalar(@rev_color); |
2598 | my $current_color = 0; | |
2599 | my $last_rev; | |
59b9f61a JN |
2600 | print <<HTML; |
2601 | <div class="page_body"> | |
2602 | <table class="blame"> | |
2603 | <tr><th>Commit</th><th>Line</th><th>Data</th></tr> | |
2604 | HTML | |
acb0f6f3 | 2605 | while (<$fd>) { |
c8aeaaf7 LT |
2606 | my ($full_rev, $author, $date, $lineno, $data) = |
2607 | /^([0-9a-f]{40}).*?\s\((.*?)\s+([-\d]+ [:\d]+ [-+\d]+)\s+(\d+)\)\s(.*)/; | |
9074484a | 2608 | my $rev = substr($full_rev, 0, 8); |
9dc5f8c9 | 2609 | my $print_c8 = 0; |
9074484a | 2610 | |
cc1bf97e LT |
2611 | if (!defined $last_rev) { |
2612 | $last_rev = $full_rev; | |
9dc5f8c9 | 2613 | $print_c8 = 1; |
cc1bf97e LT |
2614 | } elsif ($last_rev ne $full_rev) { |
2615 | $last_rev = $full_rev; | |
2616 | $current_color = ++$current_color % $num_colors; | |
9dc5f8c9 | 2617 | $print_c8 = 1; |
cc1bf97e | 2618 | } |
9074484a | 2619 | print "<tr class=\"$rev_color[$current_color]\">\n"; |
c8aeaaf7 LT |
2620 | print "<td class=\"sha1\""; |
2621 | if ($print_c8 == 1) { | |
2622 | print " title=\"$author, $date\""; | |
2623 | } | |
2624 | print ">"; | |
9dc5f8c9 LT |
2625 | if ($print_c8 == 1) { |
2626 | print $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)}, | |
2627 | esc_html($rev)); | |
2628 | } | |
2629 | print "</td>\n"; | |
9074484a JH |
2630 | print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . |
2631 | esc_html($lineno) . "</a></td>\n"; | |
2632 | print "<td class=\"pre\">" . esc_html($data) . "</td>\n"; | |
2633 | print "</tr>\n"; | |
1f2857ea LT |
2634 | } |
2635 | print "</table>\n"; | |
2636 | print "</div>"; | |
952c65fc JN |
2637 | close $fd |
2638 | or print "Reading blob failed\n"; | |
1f2857ea LT |
2639 | git_footer_html(); |
2640 | } | |
2641 | ||
e34ef621 FF |
2642 | sub git_blame { |
2643 | my $fd; | |
ddb8d900 | 2644 | |
1d3fc68a AK |
2645 | my ($have_blame) = gitweb_check_feature('blame'); |
2646 | if (!$have_blame) { | |
ddb8d900 AK |
2647 | die_error('403 Permission denied', "Permission denied"); |
2648 | } | |
cac4bd94 | 2649 | die_error('404 Not Found', "File name not defined") if (!$file_name); |
847e01fb | 2650 | $hash_base ||= git_get_head_hash($project); |
cac4bd94 | 2651 | die_error(undef, "Couldn't find base commit") unless ($hash_base); |
847e01fb | 2652 | my %co = parse_commit($hash_base) |
cac4bd94 | 2653 | or die_error(undef, "Reading commit failed"); |
e34ef621 FF |
2654 | if (!defined $hash) { |
2655 | $hash = git_get_hash_by_path($hash_base, $file_name, "blob") | |
cac4bd94 | 2656 | or die_error(undef, "Error lookup file"); |
e34ef621 | 2657 | } |
25691fbe | 2658 | open ($fd, "-|", git_cmd(), "annotate", '-l', '-t', '-r', $file_name, $hash_base) |
cac4bd94 | 2659 | or die_error(undef, "Open git-annotate failed"); |
e34ef621 | 2660 | git_header_html(); |
0d83ddc4 | 2661 | my $formats_nav = |
952c65fc JN |
2662 | $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, |
2663 | "blob") . | |
2664 | " | " . | |
cae1862a PB |
2665 | $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, |
2666 | "history") . | |
2667 | " | " . | |
952c65fc | 2668 | $cgi->a({-href => href(action=>"blame", file_name=>$file_name)}, |
f35274da | 2669 | "HEAD"); |
847e01fb JN |
2670 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); |
2671 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
59fb1c94 | 2672 | git_print_page_path($file_name, 'blob', $hash_base); |
e34ef621 FF |
2673 | print "<div class=\"page_body\">\n"; |
2674 | print <<HTML; | |
1f1ab5f0 | 2675 | <table class="blame"> |
e34ef621 FF |
2676 | <tr> |
2677 | <th>Commit</th> | |
2678 | <th>Age</th> | |
2679 | <th>Author</th> | |
2680 | <th>Line</th> | |
2681 | <th>Data</th> | |
2682 | </tr> | |
2683 | HTML | |
2684 | my @line_class = (qw(light dark)); | |
2685 | my $line_class_len = scalar (@line_class); | |
2686 | my $line_class_num = $#line_class; | |
2687 | while (my $line = <$fd>) { | |
2688 | my $long_rev; | |
2689 | my $short_rev; | |
2690 | my $author; | |
2691 | my $time; | |
2692 | my $lineno; | |
2693 | my $data; | |
2694 | my $age; | |
2695 | my $age_str; | |
1f1ab5f0 | 2696 | my $age_class; |
e34ef621 FF |
2697 | |
2698 | chomp $line; | |
2699 | $line_class_num = ($line_class_num + 1) % $line_class_len; | |
2700 | ||
030b5208 | 2701 | if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) { |
e34ef621 FF |
2702 | $long_rev = $1; |
2703 | $author = $2; | |
2704 | $time = $3; | |
2705 | $lineno = $4; | |
2706 | $data = $5; | |
2707 | } else { | |
1f1ab5f0 | 2708 | print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n); |
e34ef621 FF |
2709 | next; |
2710 | } | |
2711 | $short_rev = substr ($long_rev, 0, 8); | |
2712 | $age = time () - $time; | |
2713 | $age_str = age_string ($age); | |
2714 | $age_str =~ s/ / /g; | |
1f1ab5f0 | 2715 | $age_class = age_class($age); |
e34ef621 FF |
2716 | $author = esc_html ($author); |
2717 | $author =~ s/ / /g; | |
f16db173 JN |
2718 | |
2719 | $data = untabify($data); | |
717b8311 | 2720 | $data = esc_html ($data); |
2d007374 | 2721 | |
717b8311 JN |
2722 | print <<HTML; |
2723 | <tr class="$line_class[$line_class_num]"> | |
1c2a4f5a | 2724 | <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td> |
717b8311 JN |
2725 | <td class="$age_class">$age_str</td> |
2726 | <td>$author</td> | |
2727 | <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td> | |
2728 | <td class="pre">$data</td> | |
2729 | </tr> | |
2730 | HTML | |
2731 | } # while (my $line = <$fd>) | |
2732 | print "</table>\n\n"; | |
952c65fc JN |
2733 | close $fd |
2734 | or print "Reading blob failed.\n"; | |
717b8311 JN |
2735 | print "</div>"; |
2736 | git_footer_html(); | |
2d007374 PB |
2737 | } |
2738 | ||
717b8311 | 2739 | sub git_tags { |
847e01fb | 2740 | my $head = git_get_head_hash($project); |
717b8311 | 2741 | git_header_html(); |
847e01fb JN |
2742 | git_print_page_nav('','', $head,undef,$head); |
2743 | git_print_header_div('summary', $project); | |
2d007374 | 2744 | |
120ddde2 | 2745 | my ($taglist) = git_get_refs_list("tags"); |
62e27f27 | 2746 | if (@$taglist) { |
717b8311 | 2747 | git_tags_body($taglist); |
2d007374 | 2748 | } |
717b8311 | 2749 | git_footer_html(); |
2d007374 PB |
2750 | } |
2751 | ||
717b8311 | 2752 | sub git_heads { |
847e01fb | 2753 | my $head = git_get_head_hash($project); |
717b8311 | 2754 | git_header_html(); |
847e01fb JN |
2755 | git_print_page_nav('','', $head,undef,$head); |
2756 | git_print_header_div('summary', $project); | |
930cf7dd | 2757 | |
120ddde2 | 2758 | my ($headlist) = git_get_refs_list("heads"); |
62e27f27 | 2759 | if (@$headlist) { |
120ddde2 | 2760 | git_heads_body($headlist, $head); |
f5aa79d9 | 2761 | } |
717b8311 | 2762 | git_footer_html(); |
f5aa79d9 JN |
2763 | } |
2764 | ||
19806691 | 2765 | sub git_blob_plain { |
f2e73302 | 2766 | my $expires; |
f2e73302 | 2767 | |
cff0771b | 2768 | if (!defined $hash) { |
5be01bc8 | 2769 | if (defined $file_name) { |
847e01fb | 2770 | my $base = $hash_base || git_get_head_hash($project); |
5be01bc8 | 2771 | $hash = git_get_hash_by_path($base, $file_name, "blob") |
cac4bd94 | 2772 | or die_error(undef, "Error lookup file"); |
5be01bc8 | 2773 | } else { |
cac4bd94 | 2774 | die_error(undef, "No file name defined"); |
5be01bc8 | 2775 | } |
800764cf MW |
2776 | } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) { |
2777 | # blobs defined by non-textual hash id's can be cached | |
2778 | $expires = "+1d"; | |
5be01bc8 | 2779 | } |
800764cf | 2780 | |
930cf7dd | 2781 | my $type = shift; |
25691fbe | 2782 | open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash |
cfd82669 | 2783 | or die_error(undef, "Couldn't cat $file_name, $hash"); |
930cf7dd | 2784 | |
847e01fb | 2785 | $type ||= blob_mimetype($fd, $file_name); |
f5aa79d9 JN |
2786 | |
2787 | # save as filename, even when no $file_name is given | |
2788 | my $save_as = "$hash"; | |
9312944d KS |
2789 | if (defined $file_name) { |
2790 | $save_as = $file_name; | |
f5aa79d9 JN |
2791 | } elsif ($type =~ m/^text\//) { |
2792 | $save_as .= '.txt'; | |
9312944d | 2793 | } |
f5aa79d9 | 2794 | |
f2e73302 JN |
2795 | print $cgi->header( |
2796 | -type => "$type", | |
2797 | -expires=>$expires, | |
a2a3bf7b | 2798 | -content_disposition => 'inline; filename="' . "$save_as" . '"'); |
19806691 | 2799 | undef $/; |
ad14e931 | 2800 | binmode STDOUT, ':raw'; |
19806691 | 2801 | print <$fd>; |
ad14e931 | 2802 | binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi |
19806691 KS |
2803 | $/ = "\n"; |
2804 | close $fd; | |
2805 | } | |
2806 | ||
930cf7dd | 2807 | sub git_blob { |
f2e73302 | 2808 | my $expires; |
f2e73302 | 2809 | |
cff0771b | 2810 | if (!defined $hash) { |
5be01bc8 | 2811 | if (defined $file_name) { |
847e01fb | 2812 | my $base = $hash_base || git_get_head_hash($project); |
5be01bc8 | 2813 | $hash = git_get_hash_by_path($base, $file_name, "blob") |
cac4bd94 | 2814 | or die_error(undef, "Error lookup file"); |
5be01bc8 | 2815 | } else { |
cac4bd94 | 2816 | die_error(undef, "No file name defined"); |
5be01bc8 | 2817 | } |
800764cf MW |
2818 | } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) { |
2819 | # blobs defined by non-textual hash id's can be cached | |
2820 | $expires = "+1d"; | |
5be01bc8 | 2821 | } |
800764cf | 2822 | |
1d3fc68a | 2823 | my ($have_blame) = gitweb_check_feature('blame'); |
25691fbe | 2824 | open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash |
cac4bd94 | 2825 | or die_error(undef, "Couldn't cat $file_name, $hash"); |
847e01fb | 2826 | my $mimetype = blob_mimetype($fd, $file_name); |
930cf7dd LT |
2827 | if ($mimetype !~ m/^text\//) { |
2828 | close $fd; | |
2829 | return git_blob_plain($mimetype); | |
2830 | } | |
f2e73302 | 2831 | git_header_html(undef, $expires); |
0d83ddc4 | 2832 | my $formats_nav = ''; |
847e01fb | 2833 | if (defined $hash_base && (my %co = parse_commit($hash_base))) { |
930cf7dd LT |
2834 | if (defined $file_name) { |
2835 | if ($have_blame) { | |
952c65fc JN |
2836 | $formats_nav .= |
2837 | $cgi->a({-href => href(action=>"blame", hash_base=>$hash_base, | |
2838 | hash=>$hash, file_name=>$file_name)}, | |
2839 | "blame") . | |
2840 | " | "; | |
930cf7dd | 2841 | } |
0d83ddc4 | 2842 | $formats_nav .= |
cae1862a PB |
2843 | $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, |
2844 | hash=>$hash, file_name=>$file_name)}, | |
2845 | "history") . | |
2846 | " | " . | |
952c65fc JN |
2847 | $cgi->a({-href => href(action=>"blob_plain", |
2848 | hash=>$hash, file_name=>$file_name)}, | |
35329cc1 | 2849 | "raw") . |
952c65fc JN |
2850 | " | " . |
2851 | $cgi->a({-href => href(action=>"blob", | |
2852 | hash_base=>"HEAD", file_name=>$file_name)}, | |
f35274da | 2853 | "HEAD"); |
930cf7dd | 2854 | } else { |
952c65fc | 2855 | $formats_nav .= |
35329cc1 | 2856 | $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "raw"); |
930cf7dd | 2857 | } |
847e01fb JN |
2858 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); |
2859 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
930cf7dd LT |
2860 | } else { |
2861 | print "<div class=\"page_nav\">\n" . | |
2862 | "<br/><br/></div>\n" . | |
2863 | "<div class=\"title\">$hash</div>\n"; | |
2864 | } | |
59fb1c94 | 2865 | git_print_page_path($file_name, "blob", $hash_base); |
930cf7dd LT |
2866 | print "<div class=\"page_body\">\n"; |
2867 | my $nr; | |
2868 | while (my $line = <$fd>) { | |
2869 | chomp $line; | |
2870 | $nr++; | |
f16db173 | 2871 | $line = untabify($line); |
952c65fc JN |
2872 | printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", |
2873 | $nr, $nr, $nr, esc_html($line); | |
930cf7dd | 2874 | } |
952c65fc JN |
2875 | close $fd |
2876 | or print "Reading blob failed.\n"; | |
930cf7dd LT |
2877 | print "</div>"; |
2878 | git_footer_html(); | |
2879 | } | |
2880 | ||
09bd7898 | 2881 | sub git_tree { |
de9272f4 | 2882 | my $have_snapshot = gitweb_have_snapshot(); |
cae1862a | 2883 | |
6f7ea5fb LT |
2884 | if (!defined $hash_base) { |
2885 | $hash_base = "HEAD"; | |
2886 | } | |
b87d78d6 | 2887 | if (!defined $hash) { |
09bd7898 | 2888 | if (defined $file_name) { |
6f7ea5fb LT |
2889 | $hash = git_get_hash_by_path($hash_base, $file_name, "tree"); |
2890 | } else { | |
2891 | $hash = $hash_base; | |
10dba28d | 2892 | } |
e925f38c | 2893 | } |
232ff553 | 2894 | $/ = "\0"; |
25691fbe | 2895 | open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash |
cac4bd94 | 2896 | or die_error(undef, "Open git-ls-tree failed"); |
0881d2d1 | 2897 | my @entries = map { chomp; $_ } <$fd>; |
cac4bd94 | 2898 | close $fd or die_error(undef, "Reading tree failed"); |
232ff553 | 2899 | $/ = "\n"; |
d63577da | 2900 | |
847e01fb JN |
2901 | my $refs = git_get_references(); |
2902 | my $ref = format_ref_marker($refs, $hash_base); | |
12a88f2f | 2903 | git_header_html(); |
300454fe | 2904 | my $basedir = ''; |
1d3fc68a | 2905 | my ($have_blame) = gitweb_check_feature('blame'); |
847e01fb | 2906 | if (defined $hash_base && (my %co = parse_commit($hash_base))) { |
cae1862a PB |
2907 | my @views_nav = (); |
2908 | if (defined $file_name) { | |
2909 | push @views_nav, | |
2910 | $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, | |
2911 | hash=>$hash, file_name=>$file_name)}, | |
2912 | "history"), | |
2913 | $cgi->a({-href => href(action=>"tree", | |
2914 | hash_base=>"HEAD", file_name=>$file_name)}, | |
f35274da | 2915 | "HEAD"), |
cae1862a PB |
2916 | } |
2917 | if ($have_snapshot) { | |
2918 | # FIXME: Should be available when we have no hash base as well. | |
2919 | push @views_nav, | |
5c7d2cf3 | 2920 | $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, |
e7fb022a | 2921 | "snapshot"); |
cae1862a PB |
2922 | } |
2923 | git_print_page_nav('tree','', $hash_base, undef, undef, join(' | ', @views_nav)); | |
847e01fb | 2924 | git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base); |
d63577da | 2925 | } else { |
fa702003 | 2926 | undef $hash_base; |
d63577da KS |
2927 | print "<div class=\"page_nav\">\n"; |
2928 | print "<br/><br/></div>\n"; | |
2929 | print "<div class=\"title\">$hash</div>\n"; | |
2930 | } | |
09bd7898 | 2931 | if (defined $file_name) { |
300454fe JN |
2932 | $basedir = $file_name; |
2933 | if ($basedir ne '' && substr($basedir, -1) ne '/') { | |
2934 | $basedir .= '/'; | |
2935 | } | |
09bd7898 | 2936 | } |
59fb1c94 | 2937 | git_print_page_path($file_name, 'tree', $hash_base); |
fbb592a9 | 2938 | print "<div class=\"page_body\">\n"; |
42f7eb94 | 2939 | print "<table cellspacing=\"0\">\n"; |
6dd36acd | 2940 | my $alternate = 1; |
b6b7fc72 JN |
2941 | # '..' (top directory) link if possible |
2942 | if (defined $hash_base && | |
2943 | defined $file_name && $file_name =~ m![^/]+$!) { | |
2944 | if ($alternate) { | |
2945 | print "<tr class=\"dark\">\n"; | |
2946 | } else { | |
2947 | print "<tr class=\"light\">\n"; | |
2948 | } | |
2949 | $alternate ^= 1; | |
2950 | ||
2951 | my $up = $file_name; | |
2952 | $up =~ s!/?[^/]+$!!; | |
2953 | undef $up unless $up; | |
2954 | # based on git_print_tree_entry | |
2955 | print '<td class="mode">' . mode_str('040000') . "</td>\n"; | |
2956 | print '<td class="list">'; | |
2957 | print $cgi->a({-href => href(action=>"tree", hash_base=>$hash_base, | |
2958 | file_name=>$up)}, | |
2959 | ".."); | |
2960 | print "</td>\n"; | |
2961 | print "<td class=\"link\"></td>\n"; | |
2962 | ||
2963 | print "</tr>\n"; | |
2964 | } | |
161332a5 | 2965 | foreach my $line (@entries) { |
cb849b46 JN |
2966 | my %t = parse_ls_tree_line($line, -z => 1); |
2967 | ||
bddec01d | 2968 | if ($alternate) { |
c994d620 | 2969 | print "<tr class=\"dark\">\n"; |
bddec01d | 2970 | } else { |
c994d620 | 2971 | print "<tr class=\"light\">\n"; |
bddec01d KS |
2972 | } |
2973 | $alternate ^= 1; | |
cb849b46 | 2974 | |
300454fe | 2975 | git_print_tree_entry(\%t, $basedir, $hash_base, $have_blame); |
fa702003 | 2976 | |
42f7eb94 | 2977 | print "</tr>\n"; |
161332a5 | 2978 | } |
42f7eb94 KS |
2979 | print "</table>\n" . |
2980 | "</div>"; | |
12a88f2f | 2981 | git_footer_html(); |
09bd7898 KS |
2982 | } |
2983 | ||
cb9c6e5b | 2984 | sub git_snapshot { |
ddb8d900 AK |
2985 | my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot'); |
2986 | my $have_snapshot = (defined $ctype && defined $suffix); | |
2987 | if (!$have_snapshot) { | |
2988 | die_error('403 Permission denied', "Permission denied"); | |
2989 | } | |
2990 | ||
cb9c6e5b AK |
2991 | if (!defined $hash) { |
2992 | $hash = git_get_head_hash($project); | |
2993 | } | |
2994 | ||
ddb8d900 | 2995 | my $filename = basename($project) . "-$hash.tar.$suffix"; |
cb9c6e5b | 2996 | |
ab41dfbf JN |
2997 | print $cgi->header( |
2998 | -type => 'application/x-tar', | |
2999 | -content_encoding => $ctype, | |
a2a3bf7b | 3000 | -content_disposition => 'inline; filename="' . "$filename" . '"', |
ab41dfbf | 3001 | -status => '200 OK'); |
cb9c6e5b | 3002 | |
9ccb64c8 JH |
3003 | my $git = git_cmd_str(); |
3004 | my $name = $project; | |
3005 | $name =~ s/\047/\047\\\047\047/g; | |
3006 | open my $fd, "-|", | |
3007 | "$git archive --format=tar --prefix=\'$name\'/ $hash | $command" | |
3008 | or die_error(undef, "Execute git-tar-tree failed."); | |
cb9c6e5b AK |
3009 | binmode STDOUT, ':raw'; |
3010 | print <$fd>; | |
3011 | binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi | |
3012 | close $fd; | |
3013 | ||
cb9c6e5b AK |
3014 | } |
3015 | ||
09bd7898 | 3016 | sub git_log { |
847e01fb | 3017 | my $head = git_get_head_hash($project); |
0db37973 | 3018 | if (!defined $hash) { |
19806691 | 3019 | $hash = $head; |
0db37973 | 3020 | } |
ea4a6df4 KS |
3021 | if (!defined $page) { |
3022 | $page = 0; | |
b87d78d6 | 3023 | } |
847e01fb | 3024 | my $refs = git_get_references(); |
ea4a6df4 KS |
3025 | |
3026 | my $limit = sprintf("--max-count=%i", (100 * ($page+1))); | |
25691fbe | 3027 | open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash |
cac4bd94 | 3028 | or die_error(undef, "Open git-rev-list failed"); |
0881d2d1 | 3029 | my @revlist = map { chomp; $_ } <$fd>; |
ea4a6df4 KS |
3030 | close $fd; |
3031 | ||
847e01fb | 3032 | my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist); |
0d83ddc4 JN |
3033 | |
3034 | git_header_html(); | |
847e01fb | 3035 | git_print_page_nav('log','', $hash,undef,undef, $paging_nav); |
0d83ddc4 | 3036 | |
b87d78d6 | 3037 | if (!@revlist) { |
847e01fb | 3038 | my %co = parse_commit($hash); |
27fb8c40 | 3039 | |
847e01fb | 3040 | git_print_header_div('summary', $project); |
e925f38c | 3041 | print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n"; |
161332a5 | 3042 | } |
c994d620 KS |
3043 | for (my $i = ($page * 100); $i <= $#revlist; $i++) { |
3044 | my $commit = $revlist[$i]; | |
847e01fb JN |
3045 | my $ref = format_ref_marker($refs, $commit); |
3046 | my %co = parse_commit($commit); | |
b87d78d6 | 3047 | next if !%co; |
847e01fb JN |
3048 | my %ad = parse_date($co{'author_epoch'}); |
3049 | git_print_header_div('commit', | |
26298b5f JN |
3050 | "<span class=\"age\">$co{'age_string'}</span>" . |
3051 | esc_html($co{'title'}) . $ref, | |
3052 | $commit); | |
034df39e KS |
3053 | print "<div class=\"title_text\">\n" . |
3054 | "<div class=\"log_link\">\n" . | |
1c2a4f5a | 3055 | $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . |
952c65fc JN |
3056 | " | " . |
3057 | $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . | |
6ef4cb2e | 3058 | " | " . |
d7267207 | 3059 | $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") . |
eb28240b | 3060 | "<br/>\n" . |
034df39e | 3061 | "</div>\n" . |
40c13813 | 3062 | "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" . |
d16d093c JN |
3063 | "</div>\n"; |
3064 | ||
3065 | print "<div class=\"log_body\">\n"; | |
3066 | git_print_simplified_log($co{'comment'}); | |
09bd7898 | 3067 | print "</div>\n"; |
e334d18c | 3068 | } |
034df39e | 3069 | git_footer_html(); |
09bd7898 KS |
3070 | } |
3071 | ||
3072 | sub git_commit { | |
847e01fb | 3073 | my %co = parse_commit($hash); |
034df39e | 3074 | if (!%co) { |
cac4bd94 | 3075 | die_error(undef, "Unknown commit object"); |
d63577da | 3076 | } |
847e01fb JN |
3077 | my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'}); |
3078 | my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'}); | |
161332a5 | 3079 | |
d8a20ba9 KS |
3080 | my $parent = $co{'parent'}; |
3081 | if (!defined $parent) { | |
b9182987 | 3082 | $parent = "--root"; |
6191f8e1 | 3083 | } |
25691fbe | 3084 | open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $parent, $hash |
cac4bd94 | 3085 | or die_error(undef, "Open git-diff-tree failed"); |
0881d2d1 | 3086 | my @difftree = map { chomp; $_ } <$fd>; |
cac4bd94 | 3087 | close $fd or die_error(undef, "Reading git-diff-tree failed"); |
11044297 KS |
3088 | |
3089 | # non-textual hash id's can be cached | |
3090 | my $expires; | |
3091 | if ($hash =~ m/^[0-9a-fA-F]{40}$/) { | |
3092 | $expires = "+1d"; | |
3093 | } | |
847e01fb JN |
3094 | my $refs = git_get_references(); |
3095 | my $ref = format_ref_marker($refs, $co{'id'}); | |
ddb8d900 | 3096 | |
de9272f4 | 3097 | my $have_snapshot = gitweb_have_snapshot(); |
ddb8d900 | 3098 | |
cae1862a | 3099 | my @views_nav = (); |
4f7b34c9 | 3100 | if (defined $file_name && defined $co{'parent'}) { |
cae1862a | 3101 | push @views_nav, |
952c65fc JN |
3102 | $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)}, |
3103 | "blame"); | |
4f7b34c9 | 3104 | } |
594e212b | 3105 | git_header_html(undef, $expires); |
a144154f | 3106 | git_print_page_nav('commit', '', |
952c65fc | 3107 | $hash, $co{'tree'}, $hash, |
cae1862a | 3108 | join (' | ', @views_nav)); |
4f7b34c9 | 3109 | |
b87d78d6 | 3110 | if (defined $co{'parent'}) { |
847e01fb | 3111 | git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash); |
b87d78d6 | 3112 | } else { |
847e01fb | 3113 | git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash); |
b87d78d6 | 3114 | } |
6191f8e1 | 3115 | print "<div class=\"title_text\">\n" . |
b87d78d6 | 3116 | "<table cellspacing=\"0\">\n"; |
40c13813 | 3117 | print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n". |
bddec01d KS |
3118 | "<tr>" . |
3119 | "<td></td><td> $ad{'rfc2822'}"; | |
927dcec4 | 3120 | if ($ad{'hour_local'} < 6) { |
952c65fc JN |
3121 | printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", |
3122 | $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); | |
b87d78d6 | 3123 | } else { |
952c65fc JN |
3124 | printf(" (%02d:%02d %s)", |
3125 | $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); | |
b87d78d6 | 3126 | } |
bddec01d KS |
3127 | print "</td>" . |
3128 | "</tr>\n"; | |
40c13813 | 3129 | print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n"; |
952c65fc JN |
3130 | print "<tr><td></td><td> $cd{'rfc2822'}" . |
3131 | sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . | |
3132 | "</td></tr>\n"; | |
1f1ab5f0 | 3133 | print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n"; |
bddec01d KS |
3134 | print "<tr>" . |
3135 | "<td>tree</td>" . | |
1f1ab5f0 | 3136 | "<td class=\"sha1\">" . |
952c65fc JN |
3137 | $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash), |
3138 | class => "list"}, $co{'tree'}) . | |
19806691 | 3139 | "</td>" . |
952c65fc JN |
3140 | "<td class=\"link\">" . |
3141 | $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)}, | |
3142 | "tree"); | |
cb9c6e5b | 3143 | if ($have_snapshot) { |
952c65fc JN |
3144 | print " | " . |
3145 | $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot"); | |
cb9c6e5b AK |
3146 | } |
3147 | print "</td>" . | |
bddec01d | 3148 | "</tr>\n"; |
8adc4bd4 | 3149 | my $parents = $co{'parents'}; |
3e029299 | 3150 | foreach my $par (@$parents) { |
bddec01d KS |
3151 | print "<tr>" . |
3152 | "<td>parent</td>" . | |
952c65fc JN |
3153 | "<td class=\"sha1\">" . |
3154 | $cgi->a({-href => href(action=>"commit", hash=>$par), | |
3155 | class => "list"}, $par) . | |
3156 | "</td>" . | |
bddec01d | 3157 | "<td class=\"link\">" . |
1c2a4f5a | 3158 | $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") . |
952c65fc | 3159 | " | " . |
f2e60947 | 3160 | $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") . |
bddec01d KS |
3161 | "</td>" . |
3162 | "</tr>\n"; | |
3e029299 | 3163 | } |
7a9b4c5f | 3164 | print "</table>". |
b87d78d6 | 3165 | "</div>\n"; |
d16d093c | 3166 | |
fbb592a9 | 3167 | print "<div class=\"page_body\">\n"; |
d16d093c | 3168 | git_print_log($co{'comment'}); |
927dcec4 | 3169 | print "</div>\n"; |
4a4a1a53 | 3170 | |
eee08903 | 3171 | git_difftree_body(\@difftree, $hash, $parent); |
4a4a1a53 | 3172 | |
12a88f2f | 3173 | git_footer_html(); |
09bd7898 KS |
3174 | } |
3175 | ||
3176 | sub git_blobdiff { | |
9b71b1f6 JN |
3177 | my $format = shift || 'html'; |
3178 | ||
7c5e2ebb JN |
3179 | my $fd; |
3180 | my @difftree; | |
3181 | my %diffinfo; | |
9b71b1f6 | 3182 | my $expires; |
7c5e2ebb JN |
3183 | |
3184 | # preparing $fd and %diffinfo for git_patchset_body | |
3185 | # new style URI | |
3186 | if (defined $hash_base && defined $hash_parent_base) { | |
3187 | if (defined $file_name) { | |
3188 | # read raw output | |
25691fbe | 3189 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base, |
7c5e2ebb JN |
3190 | "--", $file_name |
3191 | or die_error(undef, "Open git-diff-tree failed"); | |
3192 | @difftree = map { chomp; $_ } <$fd>; | |
3193 | close $fd | |
3194 | or die_error(undef, "Reading git-diff-tree failed"); | |
3195 | @difftree | |
3196 | or die_error('404 Not Found', "Blob diff not found"); | |
3197 | ||
0aea3376 JN |
3198 | } elsif (defined $hash && |
3199 | $hash =~ /[0-9a-fA-F]{40}/) { | |
3200 | # try to find filename from $hash | |
7c5e2ebb JN |
3201 | |
3202 | # read filtered raw output | |
25691fbe | 3203 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base |
7c5e2ebb JN |
3204 | or die_error(undef, "Open git-diff-tree failed"); |
3205 | @difftree = | |
3206 | # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c' | |
3207 | # $hash == to_id | |
3208 | grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ } | |
3209 | map { chomp; $_ } <$fd>; | |
3210 | close $fd | |
3211 | or die_error(undef, "Reading git-diff-tree failed"); | |
3212 | @difftree | |
3213 | or die_error('404 Not Found', "Blob diff not found"); | |
3214 | ||
3215 | } else { | |
3216 | die_error('404 Not Found', "Missing one of the blob diff parameters"); | |
3217 | } | |
3218 | ||
3219 | if (@difftree > 1) { | |
3220 | die_error('404 Not Found', "Ambiguous blob diff specification"); | |
3221 | } | |
3222 | ||
3223 | %diffinfo = parse_difftree_raw_line($difftree[0]); | |
3224 | $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'}; | |
3225 | $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'}; | |
3226 | ||
3227 | $hash_parent ||= $diffinfo{'from_id'}; | |
3228 | $hash ||= $diffinfo{'to_id'}; | |
3229 | ||
9b71b1f6 JN |
3230 | # non-textual hash id's can be cached |
3231 | if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ && | |
3232 | $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) { | |
3233 | $expires = '+1d'; | |
3234 | } | |
3235 | ||
7c5e2ebb | 3236 | # open patch output |
25691fbe | 3237 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
6bcf4b46 | 3238 | '-p', $hash_parent_base, $hash_base, |
7c5e2ebb JN |
3239 | "--", $file_name |
3240 | or die_error(undef, "Open git-diff-tree failed"); | |
3241 | } | |
3242 | ||
3243 | # old/legacy style URI | |
3244 | if (!%diffinfo && # if new style URI failed | |
3245 | defined $hash && defined $hash_parent) { | |
3246 | # fake git-diff-tree raw output | |
3247 | $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob"; | |
3248 | $diffinfo{'from_id'} = $hash_parent; | |
3249 | $diffinfo{'to_id'} = $hash; | |
3250 | if (defined $file_name) { | |
3251 | if (defined $file_parent) { | |
3252 | $diffinfo{'status'} = '2'; | |
8391548e PB |
3253 | $diffinfo{'from_file'} = $file_parent; |
3254 | $diffinfo{'to_file'} = $file_name; | |
7c5e2ebb JN |
3255 | } else { # assume not renamed |
3256 | $diffinfo{'status'} = '1'; | |
8391548e PB |
3257 | $diffinfo{'from_file'} = $file_name; |
3258 | $diffinfo{'to_file'} = $file_name; | |
7c5e2ebb JN |
3259 | } |
3260 | } else { # no filename given | |
3261 | $diffinfo{'status'} = '2'; | |
3262 | $diffinfo{'from_file'} = $hash_parent; | |
3263 | $diffinfo{'to_file'} = $hash; | |
3264 | } | |
3265 | ||
9b71b1f6 JN |
3266 | # non-textual hash id's can be cached |
3267 | if ($hash =~ m/^[0-9a-fA-F]{40}$/ && | |
3268 | $hash_parent =~ m/^[0-9a-fA-F]{40}$/) { | |
3269 | $expires = '+1d'; | |
3270 | } | |
3271 | ||
3272 | # open patch output | |
25691fbe | 3273 | open $fd, "-|", git_cmd(), "diff", '-p', @diff_opts, $hash_parent, $hash |
7c5e2ebb JN |
3274 | or die_error(undef, "Open git-diff failed"); |
3275 | } else { | |
3276 | die_error('404 Not Found', "Missing one of the blob diff parameters") | |
3277 | unless %diffinfo; | |
3278 | } | |
3279 | ||
3280 | # header | |
9b71b1f6 JN |
3281 | if ($format eq 'html') { |
3282 | my $formats_nav = | |
3283 | $cgi->a({-href => href(action=>"blobdiff_plain", | |
3284 | hash=>$hash, hash_parent=>$hash_parent, | |
3285 | hash_base=>$hash_base, hash_parent_base=>$hash_parent_base, | |
3286 | file_name=>$file_name, file_parent=>$file_parent)}, | |
35329cc1 | 3287 | "raw"); |
9b71b1f6 JN |
3288 | git_header_html(undef, $expires); |
3289 | if (defined $hash_base && (my %co = parse_commit($hash_base))) { | |
3290 | git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); | |
3291 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
3292 | } else { | |
3293 | print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n"; | |
3294 | print "<div class=\"title\">$hash vs $hash_parent</div>\n"; | |
3295 | } | |
3296 | if (defined $file_name) { | |
3297 | git_print_page_path($file_name, "blob", $hash_base); | |
3298 | } else { | |
3299 | print "<div class=\"page_path\"></div>\n"; | |
3300 | } | |
3301 | ||
3302 | } elsif ($format eq 'plain') { | |
3303 | print $cgi->header( | |
3304 | -type => 'text/plain', | |
3305 | -charset => 'utf-8', | |
3306 | -expires => $expires, | |
a2a3bf7b | 3307 | -content_disposition => 'inline; filename="' . "$file_name" . '.patch"'); |
9b71b1f6 JN |
3308 | |
3309 | print "X-Git-Url: " . $cgi->self_url() . "\n\n"; | |
3310 | ||
7c5e2ebb | 3311 | } else { |
9b71b1f6 | 3312 | die_error(undef, "Unknown blobdiff format"); |
7c5e2ebb JN |
3313 | } |
3314 | ||
3315 | # patch | |
9b71b1f6 JN |
3316 | if ($format eq 'html') { |
3317 | print "<div class=\"page_body\">\n"; | |
7c5e2ebb | 3318 | |
9b71b1f6 JN |
3319 | git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base); |
3320 | close $fd; | |
7c5e2ebb | 3321 | |
9b71b1f6 JN |
3322 | print "</div>\n"; # class="page_body" |
3323 | git_footer_html(); | |
3324 | ||
3325 | } else { | |
3326 | while (my $line = <$fd>) { | |
8391548e PB |
3327 | $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg; |
3328 | $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg; | |
9b71b1f6 JN |
3329 | |
3330 | print $line; | |
3331 | ||
3332 | last if $line =~ m!^\+\+\+!; | |
3333 | } | |
3334 | local $/ = undef; | |
3335 | print <$fd>; | |
3336 | close $fd; | |
3337 | } | |
09bd7898 KS |
3338 | } |
3339 | ||
19806691 | 3340 | sub git_blobdiff_plain { |
9b71b1f6 | 3341 | git_blobdiff('plain'); |
19806691 KS |
3342 | } |
3343 | ||
09bd7898 | 3344 | sub git_commitdiff { |
eee08903 | 3345 | my $format = shift || 'html'; |
847e01fb | 3346 | my %co = parse_commit($hash); |
034df39e | 3347 | if (!%co) { |
cac4bd94 | 3348 | die_error(undef, "Unknown commit object"); |
d63577da | 3349 | } |
bddec01d | 3350 | if (!defined $hash_parent) { |
b5ff2cf9 | 3351 | $hash_parent = $co{'parent'} || '--root'; |
bddec01d | 3352 | } |
eee08903 JN |
3353 | |
3354 | # read commitdiff | |
3355 | my $fd; | |
3356 | my @difftree; | |
eee08903 | 3357 | if ($format eq 'html') { |
25691fbe | 3358 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
eee08903 JN |
3359 | "--patch-with-raw", "--full-index", $hash_parent, $hash |
3360 | or die_error(undef, "Open git-diff-tree failed"); | |
3361 | ||
3362 | while (chomp(my $line = <$fd>)) { | |
3363 | # empty line ends raw part of diff-tree output | |
3364 | last unless $line; | |
3365 | push @difftree, $line; | |
3366 | } | |
eee08903 | 3367 | |
eee08903 | 3368 | } elsif ($format eq 'plain') { |
25691fbe | 3369 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
6bcf4b46 | 3370 | '-p', $hash_parent, $hash |
eee08903 | 3371 | or die_error(undef, "Open git-diff-tree failed"); |
157e43b4 | 3372 | |
eee08903 JN |
3373 | } else { |
3374 | die_error(undef, "Unknown commitdiff format"); | |
3375 | } | |
161332a5 | 3376 | |
11044297 KS |
3377 | # non-textual hash id's can be cached |
3378 | my $expires; | |
3379 | if ($hash =~ m/^[0-9a-fA-F]{40}$/) { | |
3380 | $expires = "+1d"; | |
3381 | } | |
09bd7898 | 3382 | |
eee08903 JN |
3383 | # write commit message |
3384 | if ($format eq 'html') { | |
3385 | my $refs = git_get_references(); | |
3386 | my $ref = format_ref_marker($refs, $co{'id'}); | |
3387 | my $formats_nav = | |
3388 | $cgi->a({-href => href(action=>"commitdiff_plain", | |
3389 | hash=>$hash, hash_parent=>$hash_parent)}, | |
35329cc1 | 3390 | "raw"); |
1b1cd421 | 3391 | |
eee08903 JN |
3392 | git_header_html(undef, $expires); |
3393 | git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav); | |
3394 | git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash); | |
6fd92a28 | 3395 | git_print_authorship(\%co); |
eee08903 JN |
3396 | print "<div class=\"page_body\">\n"; |
3397 | print "<div class=\"log\">\n"; | |
3398 | git_print_simplified_log($co{'comment'}, 1); # skip title | |
3399 | print "</div>\n"; # class="log" | |
3400 | ||
3401 | } elsif ($format eq 'plain') { | |
3402 | my $refs = git_get_references("tags"); | |
edf735ab | 3403 | my $tagname = git_get_rev_name_tags($hash); |
eee08903 JN |
3404 | my $filename = basename($project) . "-$hash.patch"; |
3405 | ||
3406 | print $cgi->header( | |
3407 | -type => 'text/plain', | |
3408 | -charset => 'utf-8', | |
3409 | -expires => $expires, | |
a2a3bf7b | 3410 | -content_disposition => 'inline; filename="' . "$filename" . '"'); |
eee08903 JN |
3411 | my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'}); |
3412 | print <<TEXT; | |
59b9f61a JN |
3413 | From: $co{'author'} |
3414 | Date: $ad{'rfc2822'} ($ad{'tz_local'}) | |
3415 | Subject: $co{'title'} | |
3416 | TEXT | |
edf735ab | 3417 | print "X-Git-Tag: $tagname\n" if $tagname; |
eee08903 | 3418 | print "X-Git-Url: " . $cgi->self_url() . "\n\n"; |
edf735ab | 3419 | |
eee08903 JN |
3420 | foreach my $line (@{$co{'comment'}}) { |
3421 | print "$line\n"; | |
3422 | } | |
3423 | print "---\n\n"; | |
1b1cd421 | 3424 | } |
1b1cd421 | 3425 | |
eee08903 JN |
3426 | # write patch |
3427 | if ($format eq 'html') { | |
b4657e77 JN |
3428 | git_difftree_body(\@difftree, $hash, $hash_parent); |
3429 | print "<br/>\n"; | |
1b1cd421 | 3430 | |
157e43b4 JN |
3431 | git_patchset_body($fd, \@difftree, $hash, $hash_parent); |
3432 | close $fd; | |
eee08903 JN |
3433 | print "</div>\n"; # class="page_body" |
3434 | git_footer_html(); | |
3435 | ||
3436 | } elsif ($format eq 'plain') { | |
3437 | local $/ = undef; | |
3438 | print <$fd>; | |
3439 | close $fd | |
3440 | or print "Reading git-diff-tree failed\n"; | |
19806691 KS |
3441 | } |
3442 | } | |
3443 | ||
eee08903 JN |
3444 | sub git_commitdiff_plain { |
3445 | git_commitdiff('plain'); | |
3446 | } | |
3447 | ||
09bd7898 | 3448 | sub git_history { |
c6e1d9ed | 3449 | if (!defined $hash_base) { |
847e01fb | 3450 | $hash_base = git_get_head_hash($project); |
09bd7898 | 3451 | } |
8be68352 JN |
3452 | if (!defined $page) { |
3453 | $page = 0; | |
3454 | } | |
63433106 | 3455 | my $ftype; |
847e01fb | 3456 | my %co = parse_commit($hash_base); |
09bd7898 | 3457 | if (!%co) { |
cac4bd94 | 3458 | die_error(undef, "Unknown commit object"); |
2ae100df | 3459 | } |
8be68352 | 3460 | |
847e01fb | 3461 | my $refs = git_get_references(); |
8be68352 JN |
3462 | my $limit = sprintf("--max-count=%i", (100 * ($page+1))); |
3463 | ||
93d5f061 LT |
3464 | if (!defined $hash && defined $file_name) { |
3465 | $hash = git_get_hash_by_path($hash_base, $file_name); | |
3466 | } | |
cff0771b | 3467 | if (defined $hash) { |
63433106 | 3468 | $ftype = git_get_type($hash); |
cff0771b | 3469 | } |
10dba28d | 3470 | |
cdd4037d | 3471 | open my $fd, "-|", |
8be68352 JN |
3472 | git_cmd(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name |
3473 | or die_error(undef, "Open git-rev-list-failed"); | |
3474 | my @revlist = map { chomp; $_ } <$fd>; | |
3475 | close $fd | |
3476 | or die_error(undef, "Reading git-rev-list failed"); | |
25691fbe | 3477 | |
8be68352 JN |
3478 | my $paging_nav = ''; |
3479 | if ($page > 0) { | |
3480 | $paging_nav .= | |
3481 | $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, | |
3482 | file_name=>$file_name)}, | |
3483 | "first"); | |
3484 | $paging_nav .= " ⋅ " . | |
3485 | $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, | |
3486 | file_name=>$file_name, page=>$page-1), | |
3487 | -accesskey => "p", -title => "Alt-p"}, "prev"); | |
3488 | } else { | |
3489 | $paging_nav .= "first"; | |
3490 | $paging_nav .= " ⋅ prev"; | |
3491 | } | |
3492 | if ($#revlist >= (100 * ($page+1)-1)) { | |
3493 | $paging_nav .= " ⋅ " . | |
3494 | $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, | |
3495 | file_name=>$file_name, page=>$page+1), | |
3496 | -accesskey => "n", -title => "Alt-n"}, "next"); | |
3497 | } else { | |
3498 | $paging_nav .= " ⋅ next"; | |
3499 | } | |
3500 | my $next_link = ''; | |
3501 | if ($#revlist >= (100 * ($page+1)-1)) { | |
3502 | $next_link = | |
3503 | $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, | |
3504 | file_name=>$file_name, page=>$page+1), | |
3505 | -title => "Alt-n"}, "next"); | |
3506 | } | |
3507 | ||
3508 | git_header_html(); | |
3509 | git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav); | |
3510 | git_print_header_div('commit', esc_html($co{'title'}), $hash_base); | |
3511 | git_print_page_path($file_name, $ftype, $hash_base); | |
3512 | ||
3513 | git_history_body(\@revlist, ($page * 100), $#revlist, | |
3514 | $refs, $hash_base, $ftype, $next_link); | |
581860e1 | 3515 | |
d51e902a | 3516 | git_footer_html(); |
161332a5 | 3517 | } |
19806691 KS |
3518 | |
3519 | sub git_search { | |
3520 | if (!defined $searchtext) { | |
cac4bd94 | 3521 | die_error(undef, "Text field empty"); |
19806691 KS |
3522 | } |
3523 | if (!defined $hash) { | |
847e01fb | 3524 | $hash = git_get_head_hash($project); |
19806691 | 3525 | } |
847e01fb | 3526 | my %co = parse_commit($hash); |
19806691 | 3527 | if (!%co) { |
cac4bd94 | 3528 | die_error(undef, "Unknown commit object"); |
19806691 | 3529 | } |
04f7a94f | 3530 | |
c994d620 KS |
3531 | my $commit_search = 1; |
3532 | my $author_search = 0; | |
3533 | my $committer_search = 0; | |
3534 | my $pickaxe_search = 0; | |
3535 | if ($searchtext =~ s/^author\\://i) { | |
3536 | $author_search = 1; | |
3537 | } elsif ($searchtext =~ s/^committer\\://i) { | |
3538 | $committer_search = 1; | |
3539 | } elsif ($searchtext =~ s/^pickaxe\\://i) { | |
3540 | $commit_search = 0; | |
3541 | $pickaxe_search = 1; | |
04f7a94f JN |
3542 | |
3543 | # pickaxe may take all resources of your box and run for several minutes | |
3544 | # with every query - so decide by yourself how public you make this feature | |
3545 | my ($have_pickaxe) = gitweb_check_feature('pickaxe'); | |
3546 | if (!$have_pickaxe) { | |
3547 | die_error('403 Permission denied', "Permission denied"); | |
3548 | } | |
c994d620 | 3549 | } |
19806691 | 3550 | git_header_html(); |
847e01fb JN |
3551 | git_print_page_nav('','', $hash,$co{'tree'},$hash); |
3552 | git_print_header_div('commit', esc_html($co{'title'}), $hash); | |
19806691 | 3553 | |
19806691 | 3554 | print "<table cellspacing=\"0\">\n"; |
6dd36acd | 3555 | my $alternate = 1; |
c994d620 KS |
3556 | if ($commit_search) { |
3557 | $/ = "\0"; | |
25691fbe | 3558 | open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", $hash or next; |
c994d620 KS |
3559 | while (my $commit_text = <$fd>) { |
3560 | if (!grep m/$searchtext/i, $commit_text) { | |
3561 | next; | |
19806691 | 3562 | } |
c994d620 KS |
3563 | if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) { |
3564 | next; | |
19806691 | 3565 | } |
c994d620 | 3566 | if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) { |
19806691 KS |
3567 | next; |
3568 | } | |
c994d620 | 3569 | my @commit_lines = split "\n", $commit_text; |
847e01fb | 3570 | my %co = parse_commit(undef, \@commit_lines); |
c994d620 KS |
3571 | if (!%co) { |
3572 | next; | |
3573 | } | |
3574 | if ($alternate) { | |
3575 | print "<tr class=\"dark\">\n"; | |
3576 | } else { | |
3577 | print "<tr class=\"light\">\n"; | |
3578 | } | |
3579 | $alternate ^= 1; | |
71be1e79 | 3580 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . |
40c13813 | 3581 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" . |
c994d620 | 3582 | "<td>" . |
63e4220b JN |
3583 | $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"}, |
3584 | esc_html(chop_str($co{'title'}, 50)) . "<br/>"); | |
c994d620 KS |
3585 | my $comment = $co{'comment'}; |
3586 | foreach my $line (@$comment) { | |
3587 | if ($line =~ m/^(.*)($searchtext)(.*)$/i) { | |
40c13813 | 3588 | my $lead = esc_html($1) || ""; |
c994d620 | 3589 | $lead = chop_str($lead, 30, 10); |
40c13813 KS |
3590 | my $match = esc_html($2) || ""; |
3591 | my $trail = esc_html($3) || ""; | |
c994d620 | 3592 | $trail = chop_str($trail, 30, 10); |
1f1ab5f0 | 3593 | my $text = "$lead<span class=\"match\">$match</span>$trail"; |
c994d620 | 3594 | print chop_str($text, 80, 5) . "<br/>\n"; |
19806691 | 3595 | } |
c994d620 KS |
3596 | } |
3597 | print "</td>\n" . | |
3598 | "<td class=\"link\">" . | |
756d2f06 | 3599 | $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") . |
952c65fc JN |
3600 | " | " . |
3601 | $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree"); | |
c994d620 KS |
3602 | print "</td>\n" . |
3603 | "</tr>\n"; | |
3604 | } | |
3605 | close $fd; | |
3606 | } | |
3607 | ||
3608 | if ($pickaxe_search) { | |
3609 | $/ = "\n"; | |
25691fbe DS |
3610 | my $git_command = git_cmd_str(); |
3611 | open my $fd, "-|", "$git_command rev-list $hash | " . | |
3612 | "$git_command diff-tree -r --stdin -S\'$searchtext\'"; | |
c994d620 KS |
3613 | undef %co; |
3614 | my @files; | |
3615 | while (my $line = <$fd>) { | |
3616 | if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) { | |
3617 | my %set; | |
3618 | $set{'file'} = $6; | |
3619 | $set{'from_id'} = $3; | |
3620 | $set{'to_id'} = $4; | |
3621 | $set{'id'} = $set{'to_id'}; | |
3622 | if ($set{'id'} =~ m/0{40}/) { | |
3623 | $set{'id'} = $set{'from_id'}; | |
19806691 | 3624 | } |
c994d620 KS |
3625 | if ($set{'id'} =~ m/0{40}/) { |
3626 | next; | |
3627 | } | |
3628 | push @files, \%set; | |
53b89d8d | 3629 | } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){ |
c994d620 KS |
3630 | if (%co) { |
3631 | if ($alternate) { | |
3632 | print "<tr class=\"dark\">\n"; | |
3633 | } else { | |
3634 | print "<tr class=\"light\">\n"; | |
3635 | } | |
3636 | $alternate ^= 1; | |
71be1e79 | 3637 | print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . |
40c13813 | 3638 | "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" . |
c994d620 | 3639 | "<td>" . |
952c65fc JN |
3640 | $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), |
3641 | -class => "list subject"}, | |
63e4220b | 3642 | esc_html(chop_str($co{'title'}, 50)) . "<br/>"); |
c994d620 KS |
3643 | while (my $setref = shift @files) { |
3644 | my %set = %$setref; | |
952c65fc JN |
3645 | print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'}, |
3646 | hash=>$set{'id'}, file_name=>$set{'file'}), | |
3647 | -class => "list"}, | |
3648 | "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") . | |
c994d620 KS |
3649 | "<br/>\n"; |
3650 | } | |
3651 | print "</td>\n" . | |
3652 | "<td class=\"link\">" . | |
756d2f06 | 3653 | $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") . |
952c65fc JN |
3654 | " | " . |
3655 | $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree"); | |
c994d620 KS |
3656 | print "</td>\n" . |
3657 | "</tr>\n"; | |
3658 | } | |
847e01fb | 3659 | %co = parse_commit($1); |
19806691 | 3660 | } |
19806691 | 3661 | } |
c994d620 | 3662 | close $fd; |
19806691 KS |
3663 | } |
3664 | print "</table>\n"; | |
19806691 KS |
3665 | git_footer_html(); |
3666 | } | |
3667 | ||
3668 | sub git_shortlog { | |
847e01fb | 3669 | my $head = git_get_head_hash($project); |
19806691 KS |
3670 | if (!defined $hash) { |
3671 | $hash = $head; | |
3672 | } | |
ea4a6df4 KS |
3673 | if (!defined $page) { |
3674 | $page = 0; | |
3675 | } | |
847e01fb | 3676 | my $refs = git_get_references(); |
ea4a6df4 KS |
3677 | |
3678 | my $limit = sprintf("--max-count=%i", (100 * ($page+1))); | |
25691fbe | 3679 | open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash |
cac4bd94 | 3680 | or die_error(undef, "Open git-rev-list failed"); |
0881d2d1 | 3681 | my @revlist = map { chomp; $_ } <$fd>; |
19806691 | 3682 | close $fd; |
ea4a6df4 | 3683 | |
847e01fb | 3684 | my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#revlist); |
9f5dcb81 JN |
3685 | my $next_link = ''; |
3686 | if ($#revlist >= (100 * ($page+1)-1)) { | |
3687 | $next_link = | |
756d2f06 | 3688 | $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1), |
9f5dcb81 JN |
3689 | -title => "Alt-n"}, "next"); |
3690 | } | |
3691 | ||
0d83ddc4 JN |
3692 | |
3693 | git_header_html(); | |
847e01fb JN |
3694 | git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav); |
3695 | git_print_header_div('summary', $project); | |
0d83ddc4 | 3696 | |
9f5dcb81 JN |
3697 | git_shortlog_body(\@revlist, ($page * 100), $#revlist, $refs, $next_link); |
3698 | ||
19806691 KS |
3699 | git_footer_html(); |
3700 | } | |
717b8311 JN |
3701 | |
3702 | ## ...................................................................... | |
3703 | ## feeds (RSS, OPML) | |
3704 | ||
3705 | sub git_rss { | |
3706 | # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ | |
25691fbe | 3707 | open my $fd, "-|", git_cmd(), "rev-list", "--max-count=150", git_get_head_hash($project) |
cac4bd94 | 3708 | or die_error(undef, "Open git-rev-list failed"); |
717b8311 | 3709 | my @revlist = map { chomp; $_ } <$fd>; |
cac4bd94 | 3710 | close $fd or die_error(undef, "Reading git-rev-list failed"); |
717b8311 | 3711 | print $cgi->header(-type => 'text/xml', -charset => 'utf-8'); |
59b9f61a JN |
3712 | print <<XML; |
3713 | <?xml version="1.0" encoding="utf-8"?> | |
3714 | <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"> | |
3715 | <channel> | |
3716 | <title>$project $my_uri $my_url</title> | |
3717 | <link>${\esc_html("$my_url?p=$project;a=summary")}</link> | |
3718 | <description>$project log</description> | |
3719 | <language>en</language> | |
3720 | XML | |
717b8311 JN |
3721 | |
3722 | for (my $i = 0; $i <= $#revlist; $i++) { | |
3723 | my $commit = $revlist[$i]; | |
847e01fb | 3724 | my %co = parse_commit($commit); |
717b8311 JN |
3725 | # we read 150, we always show 30 and the ones more recent than 48 hours |
3726 | if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) { | |
3727 | last; | |
3728 | } | |
847e01fb | 3729 | my %cd = parse_date($co{'committer_epoch'}); |
25691fbe | 3730 | open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, |
6bcf4b46 JN |
3731 | $co{'parent'}, $co{'id'} |
3732 | or next; | |
717b8311 | 3733 | my @difftree = map { chomp; $_ } <$fd>; |
6bcf4b46 JN |
3734 | close $fd |
3735 | or next; | |
717b8311 JN |
3736 | print "<item>\n" . |
3737 | "<title>" . | |
3738 | sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) . | |
3739 | "</title>\n" . | |
3740 | "<author>" . esc_html($co{'author'}) . "</author>\n" . | |
3741 | "<pubDate>$cd{'rfc2822'}</pubDate>\n" . | |
3742 | "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" . | |
3743 | "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" . | |
3744 | "<description>" . esc_html($co{'title'}) . "</description>\n" . | |
3745 | "<content:encoded>" . | |
3746 | "<![CDATA[\n"; | |
3747 | my $comment = $co{'comment'}; | |
3748 | foreach my $line (@$comment) { | |
847abc0f | 3749 | $line = to_utf8($line); |
717b8311 JN |
3750 | print "$line<br/>\n"; |
3751 | } | |
3752 | print "<br/>\n"; | |
3753 | foreach my $line (@difftree) { | |
3754 | if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) { | |
3755 | next; | |
3756 | } | |
a2f3db2f | 3757 | my $file = esc_html(unquote($7)); |
847abc0f | 3758 | $file = to_utf8($file); |
717b8311 JN |
3759 | print "$file<br/>\n"; |
3760 | } | |
3761 | print "]]>\n" . | |
3762 | "</content:encoded>\n" . | |
3763 | "</item>\n"; | |
3764 | } | |
3765 | print "</channel></rss>"; | |
3766 | } | |
3767 | ||
3768 | sub git_opml { | |
847e01fb | 3769 | my @list = git_get_projects_list(); |
717b8311 JN |
3770 | |
3771 | print $cgi->header(-type => 'text/xml', -charset => 'utf-8'); | |
59b9f61a JN |
3772 | print <<XML; |
3773 | <?xml version="1.0" encoding="utf-8"?> | |
3774 | <opml version="1.0"> | |
3775 | <head> | |
3776 | <title>$site_name Git OPML Export</title> | |
3777 | </head> | |
3778 | <body> | |
3779 | <outline text="git RSS feeds"> | |
3780 | XML | |
717b8311 JN |
3781 | |
3782 | foreach my $pr (@list) { | |
3783 | my %proj = %$pr; | |
847e01fb | 3784 | my $head = git_get_head_hash($proj{'path'}); |
717b8311 JN |
3785 | if (!defined $head) { |
3786 | next; | |
3787 | } | |
25691fbe | 3788 | $git_dir = "$projectroot/$proj{'path'}"; |
847e01fb | 3789 | my %co = parse_commit($head); |
717b8311 JN |
3790 | if (!%co) { |
3791 | next; | |
3792 | } | |
3793 | ||
3794 | my $path = esc_html(chop_str($proj{'path'}, 25, 5)); | |
3795 | my $rss = "$my_url?p=$proj{'path'};a=rss"; | |
3796 | my $html = "$my_url?p=$proj{'path'};a=summary"; | |
3797 | print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n"; | |
3798 | } | |
59b9f61a JN |
3799 | print <<XML; |
3800 | </outline> | |
3801 | </body> | |
3802 | </opml> | |
3803 | XML | |
717b8311 | 3804 | } |