blob: cbbd75c2c7dfd0d9a5294bdb8496e66233c18e55 [file] [log] [blame]
Kay Sievers161332a2005-08-07 19:49:46 +02001#!/usr/bin/perl
2
Kay Sieversc994d622005-08-07 20:27:18 +02003# gitweb - simple web interface to track changes in git repositories
Kay Sievers22fafb92005-08-07 19:56:59 +02004#
Kay Sievers00cd0792006-05-22 14:30:47 +02005# (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6# (C) 2005, Christian Gierke
Kay Sievers823d5dc2005-08-07 19:57:58 +02007#
Kay Sieversd8f1c5c2005-10-04 01:12:47 +02008# This program is licensed under the GPLv2
Kay Sievers161332a2005-08-07 19:49:46 +02009
10use strict;
11use warnings;
Kay Sievers19806692005-08-07 20:26:27 +020012use CGI qw(:standard :escapeHTML -nosticky);
Kay Sievers7403d502005-08-07 20:23:49 +020013use CGI::Util qw(unescape);
Kay Sievers161332a2005-08-07 19:49:46 +020014use CGI::Carp qw(fatalsToBrowser);
Kay Sievers40c13812005-11-19 17:41:29 +010015use Encode;
Kay Sieversb87d78d2005-08-07 20:21:04 +020016use Fcntl ':mode';
Junio C Hamano7a13b992006-07-31 19:18:34 -070017use File::Find qw();
Aneesh Kumar K.Vcb9c6e52006-08-17 20:59:46 +053018use File::Basename qw(basename);
Kay Sievers10bb9032005-11-23 04:26:40 +010019binmode STDOUT, ':utf8';
Kay Sievers161332a2005-08-07 19:49:46 +020020
Dennis Stosberg4a87b432006-06-21 15:07:08 +020021our $cgi = new CGI;
Junio C Hamano06c084d2006-08-02 13:50:20 -070022our $version = "++GIT_VERSION++";
Dennis Stosberg4a87b432006-06-21 15:07:08 +020023our $my_url = $cgi->url();
24our $my_uri = $cgi->url(-absolute => 1);
Kay Sievers44ad2972005-08-07 19:59:24 +020025
Alp Tokere130dda2006-07-12 23:55:10 +010026# core git executable to use
27# this can just be "git" if your webserver has a sensible PATH
Junio C Hamano06c084d2006-08-02 13:50:20 -070028our $GIT = "++GIT_BINDIR++/git";
Jakub Narebski3f7f27102006-06-21 09:48:04 +020029
Kay Sieversb87d78d2005-08-07 20:21:04 +020030# absolute fs-path which will be prepended to the project path
Dennis Stosberg4a87b432006-06-21 15:07:08 +020031#our $projectroot = "/pub/scm";
Junio C Hamano06c084d2006-08-02 13:50:20 -070032our $projectroot = "++GITWEB_PROJECTROOT++";
Kay Sieversb87d78d2005-08-07 20:21:04 +020033
Kay Sieversb87d78d2005-08-07 20:21:04 +020034# target of the home link on top of all pages
Martin Waitz6132b7e2006-08-17 00:28:39 +020035our $home_link = $my_uri || "/";
Kay Sieversb87d78d2005-08-07 20:21:04 +020036
Yasushi SHOJI2de21fa2006-08-15 07:50:49 +090037# string of the home link on top of all pages
38our $home_link_str = "++GITWEB_HOME_LINK_STR++";
39
Alp Toker49da1da2006-07-11 21:10:26 +010040# name of your site or organization to appear in page titles
41# replace this with something more descriptive for clearer bookmarks
Junio C Hamano06c084d2006-08-02 13:50:20 -070042our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
Alp Toker49da1da2006-07-11 21:10:26 +010043
Kay Sievers8ab1da22005-08-07 20:22:53 +020044# html text to include at home page
Junio C Hamano06c084d2006-08-02 13:50:20 -070045our $home_text = "++GITWEB_HOMETEXT++";
Kay Sievers8ab1da22005-08-07 20:22:53 +020046
Jakub Narebskiaedd9422006-06-17 11:23:56 +020047# URI of default stylesheet
Junio C Hamano06c084d2006-08-02 13:50:20 -070048our $stylesheet = "++GITWEB_CSS++";
Martin Waitz281f2f62006-07-31 00:38:39 +020049# URI of GIT logo
Junio C Hamano06c084d2006-08-02 13:50:20 -070050our $logo = "++GITWEB_LOGO++";
Jakub Narebski0b5deba2006-09-04 20:32:13 +020051# URI of GIT favicon, assumed to be image/png type
52our $favicon = "++GITWEB_FAVICON++";
Jakub Narebskiaedd9422006-06-17 11:23:56 +020053
Kay Sievers09bd7892005-08-07 20:21:23 +020054# source of projects list
Junio C Hamano06c084d2006-08-02 13:50:20 -070055our $projects_list = "++GITWEB_LIST++";
Kay Sieversb87d78d2005-08-07 20:21:04 +020056
Matthias Lederhofer32f4aac2006-09-17 00:31:01 +020057# show repository only if this file exists
58# (only effective if this variable evaluates to true)
59our $export_ok = "++GITWEB_EXPORT_OK++";
60
61# only allow viewing of repositories also shown on the overview page
62our $strict_export = "++GITWEB_STRICT_EXPORT++";
63
Jakub Narebski19a87212006-08-15 23:03:17 +020064# list of git base URLs used for URL to where fetch project from,
65# i.e. full URL is "$git_base_url/$project"
66our @git_base_url_list = ("++GITWEB_BASE_URL++");
67
Jakub Narebskif5aa79d2006-06-17 13:32:15 +020068# default blob_plain mimetype and default charset for text/plain blob
Dennis Stosberg4a87b432006-06-21 15:07:08 +020069our $default_blob_plain_mimetype = 'text/plain';
70our $default_text_plain_charset = undef;
Jakub Narebskif5aa79d2006-06-17 13:32:15 +020071
Petr Baudis2d007372006-06-18 00:01:06 +020072# file to use for guessing MIME types before trying /etc/mime.types
73# (relative to the current git repository)
Dennis Stosberg4a87b432006-06-21 15:07:08 +020074our $mimetypes_file = undef;
Petr Baudis2d007372006-06-18 00:01:06 +020075
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +053076# You define site-wide feature defaults here; override them with
77# $GITWEB_CONFIG as necessary.
Jakub Narebski952c65f2006-08-22 16:52:50 +020078our %feature = (
Jakub Narebski17848fc2006-08-26 19:14:22 +020079 # feature => {
80 # 'sub' => feature-sub (subroutine),
81 # 'override' => allow-override (boolean),
82 # 'default' => [ default options...] (array reference)}
83 #
84 # if feature is overridable (it means that allow-override has true value,
85 # then feature-sub will be called with default options as parameters;
86 # return value of feature-sub indicates if to enable specified feature
87 #
88 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +053089
Jakub Narebski952c65f2006-08-22 16:52:50 +020090 'blame' => {
91 'sub' => \&feature_blame,
92 'override' => 0,
93 'default' => [0]},
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +053094
Jakub Narebski952c65f2006-08-22 16:52:50 +020095 'snapshot' => {
96 'sub' => \&feature_snapshot,
97 'override' => 0,
98 # => [content-encoding, suffix, program]
99 'default' => ['x-gzip', 'gz', 'gzip']},
Jakub Narebski04f7a942006-09-11 00:29:27 +0200100
101 'pickaxe' => {
102 'sub' => \&feature_pickaxe,
103 'override' => 0,
104 'default' => [1]},
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +0530105);
106
107sub gitweb_check_feature {
108 my ($name) = @_;
109 return undef unless exists $feature{$name};
Jakub Narebski952c65f2006-08-22 16:52:50 +0200110 my ($sub, $override, @defaults) = (
111 $feature{$name}{'sub'},
112 $feature{$name}{'override'},
113 @{$feature{$name}{'default'}});
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +0530114 if (!$override) { return @defaults; }
115 return $sub->(@defaults);
116}
117
118# To enable system wide have in $GITWEB_CONFIG
Jakub Narebski17848fc2006-08-26 19:14:22 +0200119# $feature{'blame'}{'default'} = [1];
120# To have project specific config enable override in $GITWEB_CONFIG
121# $feature{'blame'}{'override'} = 1;
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +0530122# and in project config gitweb.blame = 0|1;
123
124sub feature_blame {
125 my ($val) = git_get_project_config('blame', '--bool');
126
127 if ($val eq 'true') {
128 return 1;
129 } elsif ($val eq 'false') {
130 return 0;
131 }
132
133 return $_[0];
134}
135
136# To disable system wide have in $GITWEB_CONFIG
Jakub Narebski17848fc2006-08-26 19:14:22 +0200137# $feature{'snapshot'}{'default'} = [undef];
138# To have project specific config enable override in $GITWEB_CONFIG
139# $feature{'blame'}{'override'} = 1;
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +0530140# and in project config gitweb.snapshot = none|gzip|bzip2
141
142sub feature_snapshot {
143 my ($ctype, $suffix, $command) = @_;
144
145 my ($val) = git_get_project_config('snapshot');
146
147 if ($val eq 'gzip') {
148 return ('x-gzip', 'gz', 'gzip');
149 } elsif ($val eq 'bzip2') {
150 return ('x-bzip2', 'bz2', 'bzip2');
151 } elsif ($val eq 'none') {
152 return ();
153 }
154
155 return ($ctype, $suffix, $command);
156}
157
Jakub Narebski04f7a942006-09-11 00:29:27 +0200158# To enable system wide have in $GITWEB_CONFIG
159# $feature{'pickaxe'}{'default'} = [1];
160# To have project specific config enable override in $GITWEB_CONFIG
161# $feature{'pickaxe'}{'override'} = 1;
162# and in project config gitweb.pickaxe = 0|1;
163
164sub feature_pickaxe {
165 my ($val) = git_get_project_config('pickaxe', '--bool');
166
167 if ($val eq 'true') {
168 return (1);
169 } elsif ($val eq 'false') {
170 return (0);
171 }
172
173 return ($_[0]);
174}
175
Jakub Narebski6bcf4b42006-08-27 23:49:36 +0200176# rename detection options for git-diff and git-diff-tree
177# - default is '-M', with the cost proportional to
178# (number of removed files) * (number of new files).
179# - more costly is '-C' (or '-C', '-M'), with the cost proportional to
180# (number of changed files + number of removed files) * (number of new files)
181# - even more costly is '-C', '--find-copies-harder' with cost
182# (number of files in the original tree) * (number of new files)
183# - one might want to include '-B' option, e.g. '-B', '-M'
184our @diff_opts = ('-M'); # taken from git_commit
185
Junio C Hamano06c084d2006-08-02 13:50:20 -0700186our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
Dennis Stosberg4b5dc982006-08-29 09:19:02 +0200187do $GITWEB_CONFIG if -e $GITWEB_CONFIG;
Jeff Kingc8d138a2006-08-02 15:23:34 -0400188
189# version of the core git binary
190our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
191
192$projects_list ||= $projectroot;
Jeff Kingc8d138a2006-08-02 15:23:34 -0400193
Jakub Narebski154b4d72006-08-05 12:55:20 +0200194# ======================================================================
Kay Sievers09bd7892005-08-07 20:21:23 +0200195# input validation and dispatch
Dennis Stosberg4a87b432006-06-21 15:07:08 +0200196our $action = $cgi->param('a');
Kay Sievers09bd7892005-08-07 20:21:23 +0200197if (defined $action) {
Kay Sieversc91da262005-09-03 14:50:33 +0200198 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
Jakub Narebskicac4bd92006-08-05 13:13:53 +0200199 die_error(undef, "Invalid action parameter");
Kay Sieversb87d78d2005-08-07 20:21:04 +0200200 }
Kay Sieversb87d78d2005-08-07 20:21:04 +0200201}
202
Martin Waitzdd702352006-09-16 23:08:32 +0200203our $project = $cgi->param('p');
Martin Waitz13d02162006-08-17 00:28:40 +0200204if (defined $project) {
Matthias Lederhofer7939fe42006-09-17 00:30:27 +0200205 if (!validate_input($project) ||
206 !(-d "$projectroot/$project") ||
Matthias Lederhofer32f4aac2006-09-17 00:31:01 +0200207 !(-e "$projectroot/$project/HEAD") ||
208 ($export_ok && !(-e "$projectroot/$project/$export_ok")) ||
209 ($strict_export && !project_in_list($project))) {
Matthias Lederhofer7939fe42006-09-17 00:30:27 +0200210 undef $project;
Jakub Narebskicac4bd92006-08-05 13:13:53 +0200211 die_error(undef, "No such project");
Kay Sievers9cd3d982005-08-07 20:17:42 +0200212 }
Kay Sievers2ad93312005-08-07 20:14:48 +0200213}
Kay Sievers6191f8e2005-08-07 20:19:56 +0200214
Dennis Stosberg4a87b432006-06-21 15:07:08 +0200215our $file_name = $cgi->param('f');
Kay Sieversb87d78d2005-08-07 20:21:04 +0200216if (defined $file_name) {
Jakub Narebskidbd954a2006-08-05 12:58:06 +0200217 if (!validate_input($file_name)) {
Jakub Narebskicac4bd92006-08-05 13:13:53 +0200218 die_error(undef, "Invalid file parameter");
Kay Sieversb87d78d2005-08-07 20:21:04 +0200219 }
Kay Sieversd51e9022005-08-07 20:16:07 +0200220}
Kay Sievers6191f8e2005-08-07 20:19:56 +0200221
Martin Waitz5c95fab2006-08-17 00:28:38 +0200222our $file_parent = $cgi->param('fp');
223if (defined $file_parent) {
224 if (!validate_input($file_parent)) {
225 die_error(undef, "Invalid file parent parameter");
226 }
227}
228
Dennis Stosberg4a87b432006-06-21 15:07:08 +0200229our $hash = $cgi->param('h');
Kay Sievers4fac5292005-08-07 20:27:38 +0200230if (defined $hash) {
Jakub Narebskidbd954a2006-08-05 12:58:06 +0200231 if (!validate_input($hash)) {
Jakub Narebskicac4bd92006-08-05 13:13:53 +0200232 die_error(undef, "Invalid hash parameter");
Kay Sievers4fac5292005-08-07 20:27:38 +0200233 }
Kay Sieversa59d4af2005-08-07 20:15:44 +0200234}
Kay Sievers6191f8e2005-08-07 20:19:56 +0200235
Dennis Stosberg4a87b432006-06-21 15:07:08 +0200236our $hash_parent = $cgi->param('hp');
Kay Sieversc91da262005-09-03 14:50:33 +0200237if (defined $hash_parent) {
Jakub Narebskidbd954a2006-08-05 12:58:06 +0200238 if (!validate_input($hash_parent)) {
Jakub Narebskicac4bd92006-08-05 13:13:53 +0200239 die_error(undef, "Invalid hash parent parameter");
Kay Sieversc91da262005-09-03 14:50:33 +0200240 }
Kay Sievers09bd7892005-08-07 20:21:23 +0200241}
242
Dennis Stosberg4a87b432006-06-21 15:07:08 +0200243our $hash_base = $cgi->param('hb');
Kay Sieversc91da262005-09-03 14:50:33 +0200244if (defined $hash_base) {
Jakub Narebskidbd954a2006-08-05 12:58:06 +0200245 if (!validate_input($hash_base)) {
Jakub Narebskicac4bd92006-08-05 13:13:53 +0200246 die_error(undef, "Invalid hash base parameter");
Kay Sieversc91da262005-09-03 14:50:33 +0200247 }
Kay Sieversa59d4af2005-08-07 20:15:44 +0200248}
Kay Sievers6191f8e2005-08-07 20:19:56 +0200249
Jakub Narebski420e92f2006-08-24 23:53:54 +0200250our $hash_parent_base = $cgi->param('hpb');
251if (defined $hash_parent_base) {
252 if (!validate_input($hash_parent_base)) {
253 die_error(undef, "Invalid hash parent base parameter");
254 }
255}
256
Dennis Stosberg4a87b432006-06-21 15:07:08 +0200257our $page = $cgi->param('pg');
Kay Sieversea4a6df2005-08-07 20:26:49 +0200258if (defined $page) {
Matthias Lederhoferac8e3f22006-09-17 13:52:45 +0200259 if ($page =~ m/[^0-9]/) {
Jakub Narebskicac4bd92006-08-05 13:13:53 +0200260 die_error(undef, "Invalid page parameter");
Kay Sieversb87d78d2005-08-07 20:21:04 +0200261 }
Kay Sieversa59d4af2005-08-07 20:15:44 +0200262}
Kay Sievers823d5dc2005-08-07 19:57:58 +0200263
Dennis Stosberg4a87b432006-06-21 15:07:08 +0200264our $searchtext = $cgi->param('s');
Kay Sievers19806692005-08-07 20:26:27 +0200265if (defined $searchtext) {
266 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
Jakub Narebskicac4bd92006-08-05 13:13:53 +0200267 die_error(undef, "Invalid search parameter");
Kay Sievers19806692005-08-07 20:26:27 +0200268 }
269 $searchtext = quotemeta $searchtext;
270}
271
Martin Waitzdd702352006-09-16 23:08:32 +0200272# now read PATH_INFO and use it as alternative to parameters
Matthias Lederhofer645927c2006-09-17 15:29:48 +0200273sub evaluate_path_info {
274 return if defined $project;
275 my $path_info = $ENV{"PATH_INFO"};
276 return if !$path_info;
Jakub Narebskicd90e752006-09-20 00:49:51 +0200277 $path_info =~ s,^/+,,;
Matthias Lederhofer645927c2006-09-17 15:29:48 +0200278 return if !$path_info;
Jakub Narebskicd90e752006-09-20 00:49:51 +0200279 # find which part of PATH_INFO is project
Martin Waitzdd702352006-09-16 23:08:32 +0200280 $project = $path_info;
Jakub Narebskicd90e752006-09-20 00:49:51 +0200281 $project =~ s,/+$,,;
Martin Waitzdd702352006-09-16 23:08:32 +0200282 while ($project && !-e "$projectroot/$project/HEAD") {
283 $project =~ s,/*[^/]*$,,;
284 }
Jakub Narebskicd90e752006-09-20 00:49:51 +0200285 # validate project
286 $project = validate_input($project);
Matthias Lederhofer645927c2006-09-17 15:29:48 +0200287 if (!$project ||
288 ($export_ok && !-e "$projectroot/$project/$export_ok") ||
289 ($strict_export && !project_in_list($project))) {
290 undef $project;
291 return;
Martin Waitzdd702352006-09-16 23:08:32 +0200292 }
Matthias Lederhofer645927c2006-09-17 15:29:48 +0200293 # do not change any parameters if an action is given using the query string
294 return if $action;
Jakub Narebskicd90e752006-09-20 00:49:51 +0200295 $path_info =~ s,^$project/*,,;
296 my ($refname, $pathname) = split(/:/, $path_info, 2);
297 if (defined $pathname) {
298 # we got "project.git/branch:filename" or "project.git/branch:dir/"
299 # we could use git_get_type(branch:pathname), but it needs $git_dir
300 $pathname =~ s,^/+,,;
301 if (!$pathname || substr($pathname, -1) eq "/") {
302 $action ||= "tree";
Martin Waitz053d62b2006-09-21 09:48:21 +0200303 $pathname =~ s,/$,,;
Jakub Narebskicd90e752006-09-20 00:49:51 +0200304 } else {
305 $action ||= "blob_plain";
306 }
307 $hash_base ||= validate_input($refname);
308 $file_name ||= validate_input($pathname);
309 } elsif (defined $refname) {
Martin Waitzdd702352006-09-16 23:08:32 +0200310 # we got "project.git/branch"
311 $action ||= "shortlog";
Jakub Narebskicd90e752006-09-20 00:49:51 +0200312 $hash ||= validate_input($refname);
Martin Waitzdd702352006-09-16 23:08:32 +0200313 }
314}
Matthias Lederhofer645927c2006-09-17 15:29:48 +0200315evaluate_path_info();
Martin Waitzdd702352006-09-16 23:08:32 +0200316
Matthias Lederhofer645927c2006-09-17 15:29:48 +0200317# path to the current git repository
318our $git_dir;
319$git_dir = "$projectroot/$project" if $project;
Martin Waitzdd702352006-09-16 23:08:32 +0200320
Jakub Narebski717b8312006-07-31 21:22:15 +0200321# dispatch
Matthias Lederhofer8e85cdc2006-07-31 23:46:25 +0200322my %actions = (
323 "blame" => \&git_blame2,
324 "blobdiff" => \&git_blobdiff,
325 "blobdiff_plain" => \&git_blobdiff_plain,
326 "blob" => \&git_blob,
327 "blob_plain" => \&git_blob_plain,
328 "commitdiff" => \&git_commitdiff,
329 "commitdiff_plain" => \&git_commitdiff_plain,
330 "commit" => \&git_commit,
331 "heads" => \&git_heads,
332 "history" => \&git_history,
333 "log" => \&git_log,
334 "rss" => \&git_rss,
335 "search" => \&git_search,
336 "shortlog" => \&git_shortlog,
337 "summary" => \&git_summary,
338 "tag" => \&git_tag,
339 "tags" => \&git_tags,
340 "tree" => \&git_tree,
Aneesh Kumar K.Vcb9c6e52006-08-17 20:59:46 +0530341 "snapshot" => \&git_snapshot,
Jakub Narebski77a153f2006-08-22 16:59:20 +0200342 # those below don't need $project
343 "opml" => \&git_opml,
344 "project_list" => \&git_project_list,
Jakub Narebskifc2b2be2006-09-15 04:56:03 +0200345 "project_index" => \&git_project_index,
Matthias Lederhofer8e85cdc2006-07-31 23:46:25 +0200346);
347
Jakub Narebski77a153f2006-08-22 16:59:20 +0200348if (defined $project) {
349 $action ||= 'summary';
350} else {
351 $action ||= 'project_list';
352}
Matthias Lederhofer8e85cdc2006-07-31 23:46:25 +0200353if (!defined($actions{$action})) {
Jakub Narebskicac4bd92006-08-05 13:13:53 +0200354 die_error(undef, "Unknown action");
Kay Sievers09bd7892005-08-07 20:21:23 +0200355}
Jakub Narebskid04d3d42006-09-19 21:53:22 +0200356if ($action !~ m/^(opml|project_list|project_index)$/ &&
357 !$project) {
358 die_error(undef, "Project needed");
359}
Matthias Lederhofer8e85cdc2006-07-31 23:46:25 +0200360$actions{$action}->();
361exit;
Kay Sievers09bd7892005-08-07 20:21:23 +0200362
Jakub Narebski717b8312006-07-31 21:22:15 +0200363## ======================================================================
Martin Waitz06a9d862006-08-16 00:23:50 +0200364## action links
365
366sub href(%) {
Jakub Narebski498fe002006-08-22 19:05:25 +0200367 my %params = @_;
368
369 my @mapping = (
Martin Waitz06a9d862006-08-16 00:23:50 +0200370 project => "p",
Jakub Narebski420e92f2006-08-24 23:53:54 +0200371 action => "a",
Martin Waitz06a9d862006-08-16 00:23:50 +0200372 file_name => "f",
Martin Waitz5c95fab2006-08-17 00:28:38 +0200373 file_parent => "fp",
Martin Waitz06a9d862006-08-16 00:23:50 +0200374 hash => "h",
375 hash_parent => "hp",
376 hash_base => "hb",
Jakub Narebski420e92f2006-08-24 23:53:54 +0200377 hash_parent_base => "hpb",
Martin Waitz06a9d862006-08-16 00:23:50 +0200378 page => "pg",
Jakub Narebskia1565c42006-09-15 19:30:34 +0200379 order => "o",
Martin Waitz06a9d862006-08-16 00:23:50 +0200380 searchtext => "s",
381 );
Jakub Narebski498fe002006-08-22 19:05:25 +0200382 my %mapping = @mapping;
Martin Waitz06a9d862006-08-16 00:23:50 +0200383
Jakub Narebskia1565c42006-09-15 19:30:34 +0200384 $params{'project'} = $project unless exists $params{'project'};
Martin Waitz06a9d862006-08-16 00:23:50 +0200385
Jakub Narebski498fe002006-08-22 19:05:25 +0200386 my @result = ();
387 for (my $i = 0; $i < @mapping; $i += 2) {
388 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
389 if (defined $params{$name}) {
390 push @result, $symbol . "=" . esc_param($params{$name});
391 }
392 }
393 return "$my_uri?" . join(';', @result);
Martin Waitz06a9d862006-08-16 00:23:50 +0200394}
395
396
397## ======================================================================
Jakub Narebski717b8312006-07-31 21:22:15 +0200398## validation, quoting/unquoting and escaping
399
400sub validate_input {
401 my $input = shift;
402
403 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
404 return $input;
405 }
406 if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
407 return undef;
408 }
409 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) {
410 return undef;
411 }
412 return $input;
413}
414
Kay Sievers232ff552005-11-24 16:56:55 +0100415# quote unsafe chars, but keep the slash, even when it's not
416# correct, but quoted slashes look too horrible in bookmarks
417sub esc_param {
Kay Sievers353347b2005-11-14 05:47:18 +0100418 my $str = shift;
Kay Sievers232ff552005-11-24 16:56:55 +0100419 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
Kay Sievers18216712005-11-14 06:10:07 +0100420 $str =~ s/\+/%2B/g;
Kay Sieversa9e60b72005-11-14 15:15:12 +0100421 $str =~ s/ /\+/g;
Kay Sievers353347b2005-11-14 05:47:18 +0100422 return $str;
423}
424
Kay Sievers232ff552005-11-24 16:56:55 +0100425# replace invalid utf8 character with SUBSTITUTION sequence
Kay Sievers40c13812005-11-19 17:41:29 +0100426sub esc_html {
427 my $str = shift;
Kay Sievers40c13812005-11-19 17:41:29 +0100428 $str = decode("utf8", $str, Encode::FB_DEFAULT);
Kay Sievers10bb9032005-11-23 04:26:40 +0100429 $str = escapeHTML($str);
Jakub Narebski3dc13832006-07-30 15:02:27 +0200430 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
Kay Sievers40c13812005-11-19 17:41:29 +0100431 return $str;
432}
433
Kay Sievers232ff552005-11-24 16:56:55 +0100434# git may return quoted and escaped filenames
435sub unquote {
436 my $str = shift;
437 if ($str =~ m/^"(.*)"$/) {
438 $str = $1;
439 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
440 }
441 return $str;
442}
443
Jakub Narebskif16db172006-08-06 02:08:31 +0200444# escape tabs (convert tabs to spaces)
445sub untabify {
446 my $line = shift;
447
448 while ((my $pos = index($line, "\t")) != -1) {
449 if (my $count = (8 - ($pos % 8))) {
450 my $spaces = ' ' x $count;
451 $line =~ s/\t/$spaces/;
452 }
453 }
454
455 return $line;
456}
457
Matthias Lederhofer32f4aac2006-09-17 00:31:01 +0200458sub project_in_list {
459 my $project = shift;
460 my @list = git_get_projects_list();
461 return @list && scalar(grep { $_->{'path'} eq $project } @list);
462}
463
Jakub Narebski717b8312006-07-31 21:22:15 +0200464## ----------------------------------------------------------------------
465## HTML aware string manipulation
466
467sub chop_str {
468 my $str = shift;
469 my $len = shift;
470 my $add_len = shift || 10;
471
472 # allow only $len chars, but don't cut a word if it would fit in $add_len
473 # if it doesn't fit, cut it if it's still longer than the dots we would add
474 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
475 my $body = $1;
476 my $tail = $2;
477 if (length($tail) > 4) {
478 $tail = " ...";
479 $body =~ s/&[^;]*$//; # remove chopped character entities
480 }
481 return "$body$tail";
482}
483
484## ----------------------------------------------------------------------
485## functions returning short strings
486
Jakub Narebski1f1ab5f2006-06-20 14:58:12 +0000487# CSS class for given age value (in seconds)
488sub age_class {
489 my $age = shift;
490
491 if ($age < 60*60*2) {
492 return "age0";
493 } elsif ($age < 60*60*24*2) {
494 return "age1";
495 } else {
496 return "age2";
497 }
498}
499
Jakub Narebski717b8312006-07-31 21:22:15 +0200500# convert age in seconds to "nn units ago" string
501sub age_string {
502 my $age = shift;
503 my $age_str;
504
505 if ($age > 60*60*24*365*2) {
506 $age_str = (int $age/60/60/24/365);
507 $age_str .= " years ago";
508 } elsif ($age > 60*60*24*(365/12)*2) {
509 $age_str = int $age/60/60/24/(365/12);
510 $age_str .= " months ago";
511 } elsif ($age > 60*60*24*7*2) {
512 $age_str = int $age/60/60/24/7;
513 $age_str .= " weeks ago";
514 } elsif ($age > 60*60*24*2) {
515 $age_str = int $age/60/60/24;
516 $age_str .= " days ago";
517 } elsif ($age > 60*60*2) {
518 $age_str = int $age/60/60;
519 $age_str .= " hours ago";
520 } elsif ($age > 60*2) {
521 $age_str = int $age/60;
522 $age_str .= " min ago";
523 } elsif ($age > 2) {
524 $age_str = int $age;
525 $age_str .= " sec ago";
526 } else {
527 $age_str .= " right now";
528 }
529 return $age_str;
530}
531
532# convert file mode in octal to symbolic file mode string
533sub mode_str {
534 my $mode = oct shift;
535
536 if (S_ISDIR($mode & S_IFMT)) {
537 return 'drwxr-xr-x';
538 } elsif (S_ISLNK($mode)) {
539 return 'lrwxrwxrwx';
540 } elsif (S_ISREG($mode)) {
541 # git cares only about the executable bit
542 if ($mode & S_IXUSR) {
543 return '-rwxr-xr-x';
544 } else {
545 return '-rw-r--r--';
546 };
547 } else {
548 return '----------';
549 }
550}
551
552# convert file mode in octal to file type string
553sub file_type {
Jakub Narebski7c5e2eb2006-08-25 21:13:34 +0200554 my $mode = shift;
555
556 if ($mode !~ m/^[0-7]+$/) {
557 return $mode;
558 } else {
559 $mode = oct $mode;
560 }
Jakub Narebski717b8312006-07-31 21:22:15 +0200561
562 if (S_ISDIR($mode & S_IFMT)) {
563 return "directory";
564 } elsif (S_ISLNK($mode)) {
565 return "symlink";
566 } elsif (S_ISREG($mode)) {
567 return "file";
568 } else {
569 return "unknown";
570 }
571}
572
573## ----------------------------------------------------------------------
574## functions returning short HTML fragments, or transforming HTML fragments
575## which don't beling to other sections
576
577# format line of commit message or tag comment
578sub format_log_line_html {
579 my $line = shift;
580
581 $line = esc_html($line);
582 $line =~ s/ /&nbsp;/g;
583 if ($line =~ m/([0-9a-fA-F]{40})/) {
584 my $hash_text = $1;
585 if (git_get_type($hash_text) eq "commit") {
Jakub Narebski952c65f2006-08-22 16:52:50 +0200586 my $link =
587 $cgi->a({-href => href(action=>"commit", hash=>$hash_text),
588 -class => "text"}, $hash_text);
Jakub Narebski717b8312006-07-31 21:22:15 +0200589 $line =~ s/$hash_text/$link/;
590 }
591 }
592 return $line;
593}
594
595# format marker of refs pointing to given object
Jakub Narebski847e01f2006-08-14 02:05:47 +0200596sub format_ref_marker {
Jakub Narebski717b8312006-07-31 21:22:15 +0200597 my ($refs, $id) = @_;
Jakub Narebskid294e1c2006-08-14 02:14:20 +0200598 my $markers = '';
Jakub Narebski717b8312006-07-31 21:22:15 +0200599
600 if (defined $refs->{$id}) {
Jakub Narebskid294e1c2006-08-14 02:14:20 +0200601 foreach my $ref (@{$refs->{$id}}) {
602 my ($type, $name) = qw();
603 # e.g. tags/v2.6.11 or heads/next
604 if ($ref =~ m!^(.*?)s?/(.*)$!) {
605 $type = $1;
606 $name = $2;
607 } else {
608 $type = "ref";
609 $name = $ref;
610 }
611
612 $markers .= " <span class=\"$type\">" . esc_html($name) . "</span>";
613 }
614 }
615
616 if ($markers) {
617 return ' <span class="refs">'. $markers . '</span>';
Jakub Narebski717b8312006-07-31 21:22:15 +0200618 } else {
619 return "";
620 }
621}
622
Jakub Narebski17d07442006-08-14 02:08:27 +0200623# format, perhaps shortened and with markers, title line
624sub format_subject_html {
Martin Waitz1c2a4f52006-08-16 00:24:30 +0200625 my ($long, $short, $href, $extra) = @_;
Jakub Narebski17d07442006-08-14 02:08:27 +0200626 $extra = '' unless defined($extra);
627
628 if (length($short) < length($long)) {
Jakub Narebski7c278012006-08-22 12:02:48 +0200629 return $cgi->a({-href => $href, -class => "list subject",
Martin Waitz1c2a4f52006-08-16 00:24:30 +0200630 -title => $long},
Jakub Narebski17d07442006-08-14 02:08:27 +0200631 esc_html($short) . $extra);
632 } else {
Jakub Narebski7c278012006-08-22 12:02:48 +0200633 return $cgi->a({-href => $href, -class => "list subject"},
Jakub Narebski17d07442006-08-14 02:08:27 +0200634 esc_html($long) . $extra);
635 }
636}
637
Jakub Narebskieee08902006-08-24 00:15:14 +0200638sub format_diff_line {
639 my $line = shift;
640 my $char = substr($line, 0, 1);
641 my $diff_class = "";
642
643 chomp $line;
644
645 if ($char eq '+') {
646 $diff_class = " add";
647 } elsif ($char eq "-") {
648 $diff_class = " rem";
649 } elsif ($char eq "@") {
650 $diff_class = " chunk_header";
651 } elsif ($char eq "\\") {
Jakub Narebskiaf33ef22006-08-24 01:58:49 +0200652 $diff_class = " incomplete";
Jakub Narebskieee08902006-08-24 00:15:14 +0200653 }
654 $line = untabify($line);
655 return "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
656}
657
Jakub Narebski717b8312006-07-31 21:22:15 +0200658## ----------------------------------------------------------------------
659## git utility subroutines, invoking git commands
660
Dennis Stosberg25691fb2006-08-28 17:49:58 +0200661# returns path to the core git executable and the --git-dir parameter as list
662sub git_cmd {
663 return $GIT, '--git-dir='.$git_dir;
664}
665
666# returns path to the core git executable and the --git-dir parameter as string
667sub git_cmd_str {
668 return join(' ', git_cmd());
669}
670
Jakub Narebski717b8312006-07-31 21:22:15 +0200671# get HEAD ref of given project as hash
Jakub Narebski847e01f2006-08-14 02:05:47 +0200672sub git_get_head_hash {
Jakub Narebski717b8312006-07-31 21:22:15 +0200673 my $project = shift;
Dennis Stosberg25691fb2006-08-28 17:49:58 +0200674 my $o_git_dir = $git_dir;
Jakub Narebski717b8312006-07-31 21:22:15 +0200675 my $retval = undef;
Dennis Stosberg25691fb2006-08-28 17:49:58 +0200676 $git_dir = "$projectroot/$project";
677 if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
Jakub Narebski717b8312006-07-31 21:22:15 +0200678 my $head = <$fd>;
679 close $fd;
680 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
681 $retval = $1;
682 }
683 }
Dennis Stosberg25691fb2006-08-28 17:49:58 +0200684 if (defined $o_git_dir) {
685 $git_dir = $o_git_dir;
Jakub Narebski717b8312006-07-31 21:22:15 +0200686 }
687 return $retval;
688}
689
690# get type of given object
691sub git_get_type {
692 my $hash = shift;
693
Dennis Stosberg25691fb2006-08-28 17:49:58 +0200694 open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
Jakub Narebski717b8312006-07-31 21:22:15 +0200695 my $type = <$fd>;
696 close $fd or return;
697 chomp $type;
698 return $type;
699}
700
701sub git_get_project_config {
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +0530702 my ($key, $type) = @_;
Jakub Narebski717b8312006-07-31 21:22:15 +0200703
704 return unless ($key);
705 $key =~ s/^gitweb\.//;
706 return if ($key =~ m/\W/);
707
Dennis Stosberg25691fb2006-08-28 17:49:58 +0200708 my @x = (git_cmd(), 'repo-config');
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +0530709 if (defined $type) { push @x, $type; }
710 push @x, "--get";
711 push @x, "gitweb.$key";
712 my $val = qx(@x);
713 chomp $val;
Jakub Narebski717b8312006-07-31 21:22:15 +0200714 return ($val);
715}
716
Jakub Narebski717b8312006-07-31 21:22:15 +0200717# get hash of given path at given ref
718sub git_get_hash_by_path {
719 my $base = shift;
720 my $path = shift || return undef;
Jakub Narebski1d782b02006-09-21 18:09:12 +0200721 my $type = shift;
Jakub Narebski717b8312006-07-31 21:22:15 +0200722
723 my $tree = $base;
724
Dennis Stosberg25691fb2006-08-28 17:49:58 +0200725 open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
Jakub Narebskicac4bd92006-08-05 13:13:53 +0200726 or die_error(undef, "Open git-ls-tree failed");
Jakub Narebski717b8312006-07-31 21:22:15 +0200727 my $line = <$fd>;
728 close $fd or return undef;
729
730 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
731 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
Jakub Narebski1d782b02006-09-21 18:09:12 +0200732 if (defined $type && $type ne $2) {
733 # type doesn't match
734 return undef;
735 }
Jakub Narebski717b8312006-07-31 21:22:15 +0200736 return $3;
737}
738
739## ......................................................................
740## git utility functions, directly accessing git repository
741
Jakub Narebski847e01f2006-08-14 02:05:47 +0200742sub git_get_project_description {
Jakub Narebski717b8312006-07-31 21:22:15 +0200743 my $path = shift;
744
745 open my $fd, "$projectroot/$path/description" or return undef;
746 my $descr = <$fd>;
747 close $fd;
748 chomp $descr;
749 return $descr;
750}
751
Jakub Narebskie79ca7c2006-08-16 14:50:34 +0200752sub git_get_project_url_list {
753 my $path = shift;
754
755 open my $fd, "$projectroot/$path/cloneurl" or return undef;
756 my @git_project_url_list = map { chomp; $_ } <$fd>;
757 close $fd;
758
759 return wantarray ? @git_project_url_list : \@git_project_url_list;
760}
761
Jakub Narebski847e01f2006-08-14 02:05:47 +0200762sub git_get_projects_list {
Jakub Narebski717b8312006-07-31 21:22:15 +0200763 my @list;
764
765 if (-d $projects_list) {
766 # search in directory
767 my $dir = $projects_list;
Jakub Narebskic0011ff2006-09-14 22:18:59 +0200768 my $pfxlen = length("$dir");
769
770 File::Find::find({
771 follow_fast => 1, # follow symbolic links
772 dangling_symlinks => 0, # ignore dangling symlinks, silently
773 wanted => sub {
774 # skip project-list toplevel, if we get it.
775 return if (m!^[/.]$!);
776 # only directories can be git repositories
777 return unless (-d $_);
778
779 my $subdir = substr($File::Find::name, $pfxlen + 1);
780 # we check related file in $projectroot
Matthias Lederhofer32f4aac2006-09-17 00:31:01 +0200781 if (-e "$projectroot/$subdir/HEAD" && (!$export_ok ||
782 -e "$projectroot/$subdir/$export_ok")) {
Jakub Narebskic0011ff2006-09-14 22:18:59 +0200783 push @list, { path => $subdir };
784 $File::Find::prune = 1;
785 }
786 },
787 }, "$dir");
788
Jakub Narebski717b8312006-07-31 21:22:15 +0200789 } elsif (-f $projects_list) {
790 # read from file(url-encoded):
791 # 'git%2Fgit.git Linus+Torvalds'
792 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
793 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
794 open my ($fd), $projects_list or return undef;
795 while (my $line = <$fd>) {
796 chomp $line;
797 my ($path, $owner) = split ' ', $line;
798 $path = unescape($path);
799 $owner = unescape($owner);
800 if (!defined $path) {
801 next;
802 }
Matthias Lederhofer32f4aac2006-09-17 00:31:01 +0200803 if (-e "$projectroot/$path/HEAD" && (!$export_ok ||
804 -e "$projectroot/$path/$export_ok")) {
Jakub Narebski717b8312006-07-31 21:22:15 +0200805 my $pr = {
806 path => $path,
807 owner => decode("utf8", $owner, Encode::FB_DEFAULT),
808 };
809 push @list, $pr
810 }
811 }
812 close $fd;
813 }
814 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
815 return @list;
816}
817
Jakub Narebski1e0cf032006-08-14 02:10:06 +0200818sub git_get_project_owner {
819 my $project = shift;
820 my $owner;
821
822 return undef unless $project;
823
824 # read from file (url-encoded):
825 # 'git%2Fgit.git Linus+Torvalds'
826 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
827 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
828 if (-f $projects_list) {
829 open (my $fd , $projects_list);
830 while (my $line = <$fd>) {
831 chomp $line;
832 my ($pr, $ow) = split ' ', $line;
833 $pr = unescape($pr);
834 $ow = unescape($ow);
835 if ($pr eq $project) {
836 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
837 last;
838 }
839 }
840 close $fd;
841 }
842 if (!defined $owner) {
843 $owner = get_file_owner("$projectroot/$project");
844 }
845
846 return $owner;
847}
848
Jakub Narebski847e01f2006-08-14 02:05:47 +0200849sub git_get_references {
Jakub Narebski717b8312006-07-31 21:22:15 +0200850 my $type = shift || "";
851 my %refs;
852 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
853 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
Jakub Narebski9704d752006-09-19 14:31:49 +0200854 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
855 or return;
Jakub Narebskid294e1c2006-08-14 02:14:20 +0200856
Jakub Narebski717b8312006-07-31 21:22:15 +0200857 while (my $line = <$fd>) {
858 chomp $line;
Jakub Narebskid294e1c2006-08-14 02:14:20 +0200859 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
Jakub Narebski717b8312006-07-31 21:22:15 +0200860 if (defined $refs{$1}) {
Jakub Narebskid294e1c2006-08-14 02:14:20 +0200861 push @{$refs{$1}}, $2;
Jakub Narebski717b8312006-07-31 21:22:15 +0200862 } else {
Jakub Narebskid294e1c2006-08-14 02:14:20 +0200863 $refs{$1} = [ $2 ];
Jakub Narebski717b8312006-07-31 21:22:15 +0200864 }
865 }
866 }
867 close $fd or return;
868 return \%refs;
869}
870
Jakub Narebski56a322f2006-08-24 19:41:23 +0200871sub git_get_rev_name_tags {
872 my $hash = shift || return undef;
873
Dennis Stosberg25691fb2006-08-28 17:49:58 +0200874 open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
Jakub Narebski56a322f2006-08-24 19:41:23 +0200875 or return;
876 my $name_rev = <$fd>;
877 close $fd;
878
879 if ($name_rev =~ m|^$hash tags/(.*)$|) {
880 return $1;
881 } else {
882 # catches also '$hash undefined' output
883 return undef;
884 }
885}
886
Jakub Narebski717b8312006-07-31 21:22:15 +0200887## ----------------------------------------------------------------------
888## parse to hash functions
889
Jakub Narebski847e01f2006-08-14 02:05:47 +0200890sub parse_date {
Jakub Narebski717b8312006-07-31 21:22:15 +0200891 my $epoch = shift;
892 my $tz = shift || "-0000";
893
894 my %date;
895 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
896 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
897 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
898 $date{'hour'} = $hour;
899 $date{'minute'} = $min;
900 $date{'mday'} = $mday;
901 $date{'day'} = $days[$wday];
902 $date{'month'} = $months[$mon];
Jakub Narebski952c65f2006-08-22 16:52:50 +0200903 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
904 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
905 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
906 $mday, $months[$mon], $hour ,$min;
Jakub Narebski717b8312006-07-31 21:22:15 +0200907
908 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
909 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
910 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
911 $date{'hour_local'} = $hour;
912 $date{'minute_local'} = $min;
913 $date{'tz_local'} = $tz;
914 return %date;
915}
916
Jakub Narebski847e01f2006-08-14 02:05:47 +0200917sub parse_tag {
Jakub Narebski717b8312006-07-31 21:22:15 +0200918 my $tag_id = shift;
919 my %tag;
920 my @comment;
921
Dennis Stosberg25691fb2006-08-28 17:49:58 +0200922 open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
Jakub Narebski717b8312006-07-31 21:22:15 +0200923 $tag{'id'} = $tag_id;
924 while (my $line = <$fd>) {
925 chomp $line;
926 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
927 $tag{'object'} = $1;
928 } elsif ($line =~ m/^type (.+)$/) {
929 $tag{'type'} = $1;
930 } elsif ($line =~ m/^tag (.+)$/) {
931 $tag{'name'} = $1;
932 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
933 $tag{'author'} = $1;
934 $tag{'epoch'} = $2;
935 $tag{'tz'} = $3;
936 } elsif ($line =~ m/--BEGIN/) {
937 push @comment, $line;
938 last;
939 } elsif ($line eq "") {
940 last;
941 }
942 }
943 push @comment, <$fd>;
944 $tag{'comment'} = \@comment;
945 close $fd or return;
946 if (!defined $tag{'name'}) {
947 return
948 };
949 return %tag
950}
951
Jakub Narebski847e01f2006-08-14 02:05:47 +0200952sub parse_commit {
Jakub Narebski717b8312006-07-31 21:22:15 +0200953 my $commit_id = shift;
954 my $commit_text = shift;
955
956 my @commit_lines;
957 my %co;
958
959 if (defined $commit_text) {
960 @commit_lines = @$commit_text;
961 } else {
962 $/ = "\0";
Dennis Stosberg25691fb2006-08-28 17:49:58 +0200963 open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
Jakub Narebski952c65f2006-08-22 16:52:50 +0200964 or return;
Jakub Narebski717b8312006-07-31 21:22:15 +0200965 @commit_lines = split '\n', <$fd>;
966 close $fd or return;
967 $/ = "\n";
968 pop @commit_lines;
969 }
970 my $header = shift @commit_lines;
971 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
972 return;
973 }
974 ($co{'id'}, my @parents) = split ' ', $header;
975 $co{'parents'} = \@parents;
976 $co{'parent'} = $parents[0];
977 while (my $line = shift @commit_lines) {
978 last if $line eq "\n";
979 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
980 $co{'tree'} = $1;
981 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
982 $co{'author'} = $1;
983 $co{'author_epoch'} = $2;
984 $co{'author_tz'} = $3;
985 if ($co{'author'} =~ m/^([^<]+) </) {
986 $co{'author_name'} = $1;
987 } else {
988 $co{'author_name'} = $co{'author'};
989 }
990 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
991 $co{'committer'} = $1;
992 $co{'committer_epoch'} = $2;
993 $co{'committer_tz'} = $3;
994 $co{'committer_name'} = $co{'committer'};
995 $co{'committer_name'} =~ s/ <.*//;
996 }
997 }
998 if (!defined $co{'tree'}) {
999 return;
1000 };
1001
1002 foreach my $title (@commit_lines) {
1003 $title =~ s/^ //;
1004 if ($title ne "") {
1005 $co{'title'} = chop_str($title, 80, 5);
1006 # remove leading stuff of merges to make the interesting part visible
1007 if (length($title) > 50) {
1008 $title =~ s/^Automatic //;
1009 $title =~ s/^merge (of|with) /Merge ... /i;
1010 if (length($title) > 50) {
1011 $title =~ s/(http|rsync):\/\///;
1012 }
1013 if (length($title) > 50) {
1014 $title =~ s/(master|www|rsync)\.//;
1015 }
1016 if (length($title) > 50) {
1017 $title =~ s/kernel.org:?//;
1018 }
1019 if (length($title) > 50) {
1020 $title =~ s/\/pub\/scm//;
1021 }
1022 }
1023 $co{'title_short'} = chop_str($title, 50, 5);
1024 last;
1025 }
1026 }
1027 # remove added spaces
1028 foreach my $line (@commit_lines) {
1029 $line =~ s/^ //;
1030 }
1031 $co{'comment'} = \@commit_lines;
1032
1033 my $age = time - $co{'committer_epoch'};
1034 $co{'age'} = $age;
1035 $co{'age_string'} = age_string($age);
1036 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1037 if ($age > 60*60*24*7*2) {
1038 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1039 $co{'age_string_age'} = $co{'age_string'};
1040 } else {
1041 $co{'age_string_date'} = $co{'age_string'};
1042 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1043 }
1044 return %co;
1045}
1046
Jakub Narebskia446d6b2006-08-14 02:07:00 +02001047# parse ref from ref_file, given by ref_id, with given type
1048sub parse_ref {
1049 my $ref_file = shift;
1050 my $ref_id = shift;
1051 my $type = shift || git_get_type($ref_id);
1052 my %ref_item;
1053
1054 $ref_item{'type'} = $type;
1055 $ref_item{'id'} = $ref_id;
1056 $ref_item{'epoch'} = 0;
1057 $ref_item{'age'} = "unknown";
1058 if ($type eq "tag") {
1059 my %tag = parse_tag($ref_id);
1060 $ref_item{'comment'} = $tag{'comment'};
1061 if ($tag{'type'} eq "commit") {
1062 my %co = parse_commit($tag{'object'});
1063 $ref_item{'epoch'} = $co{'committer_epoch'};
1064 $ref_item{'age'} = $co{'age_string'};
1065 } elsif (defined($tag{'epoch'})) {
1066 my $age = time - $tag{'epoch'};
1067 $ref_item{'epoch'} = $tag{'epoch'};
1068 $ref_item{'age'} = age_string($age);
1069 }
1070 $ref_item{'reftype'} = $tag{'type'};
1071 $ref_item{'name'} = $tag{'name'};
1072 $ref_item{'refid'} = $tag{'object'};
1073 } elsif ($type eq "commit"){
1074 my %co = parse_commit($ref_id);
1075 $ref_item{'reftype'} = "commit";
1076 $ref_item{'name'} = $ref_file;
1077 $ref_item{'title'} = $co{'title'};
1078 $ref_item{'refid'} = $ref_id;
1079 $ref_item{'epoch'} = $co{'committer_epoch'};
1080 $ref_item{'age'} = $co{'age_string'};
1081 } else {
1082 $ref_item{'reftype'} = $type;
1083 $ref_item{'name'} = $ref_file;
1084 $ref_item{'refid'} = $ref_id;
1085 }
1086
1087 return %ref_item;
1088}
1089
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001090# parse line of git-diff-tree "raw" output
Jakub Narebski740e67f2006-08-21 23:07:00 +02001091sub parse_difftree_raw_line {
1092 my $line = shift;
1093 my %res;
1094
1095 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1096 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1097 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1098 $res{'from_mode'} = $1;
1099 $res{'to_mode'} = $2;
1100 $res{'from_id'} = $3;
1101 $res{'to_id'} = $4;
1102 $res{'status'} = $5;
1103 $res{'similarity'} = $6;
1104 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001105 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
Jakub Narebski740e67f2006-08-21 23:07:00 +02001106 } else {
1107 $res{'file'} = unquote($7);
1108 }
1109 }
1110 # 'c512b523472485aef4fff9e57b229d9d243c967f'
Jakub Narebski0edcb372006-08-31 00:36:04 +02001111 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1112 $res{'commit'} = $1;
1113 }
Jakub Narebski740e67f2006-08-21 23:07:00 +02001114
1115 return wantarray ? %res : \%res;
1116}
1117
Jakub Narebskicb849b42006-08-31 00:32:15 +02001118# parse line of git-ls-tree output
1119sub parse_ls_tree_line ($;%) {
1120 my $line = shift;
1121 my %opts = @_;
1122 my %res;
1123
1124 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1125 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1126
1127 $res{'mode'} = $1;
1128 $res{'type'} = $2;
1129 $res{'hash'} = $3;
1130 if ($opts{'-z'}) {
1131 $res{'name'} = $4;
1132 } else {
1133 $res{'name'} = unquote($4);
1134 }
1135
1136 return wantarray ? %res : \%res;
1137}
1138
Jakub Narebski717b8312006-07-31 21:22:15 +02001139## ......................................................................
1140## parse to array of hashes functions
1141
Jakub Narebski847e01f2006-08-14 02:05:47 +02001142sub git_get_refs_list {
Jakub Narebski120ddde2006-09-19 14:33:22 +02001143 my $type = shift || "";
1144 my %refs;
Jakub Narebski717b8312006-07-31 21:22:15 +02001145 my @reflist;
1146
1147 my @refs;
Jakub Narebskic83a77e2006-09-15 03:43:28 +02001148 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1149 or return;
1150 while (my $line = <$fd>) {
1151 chomp $line;
Jakub Narebski120ddde2006-09-19 14:33:22 +02001152 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?([^\^]+))(\^\{\})?$/) {
1153 if (defined $refs{$1}) {
1154 push @{$refs{$1}}, $2;
1155 } else {
1156 $refs{$1} = [ $2 ];
1157 }
1158
1159 if (! $4) { # unpeeled, direct reference
1160 push @refs, { hash => $1, name => $3 }; # without type
1161 } elsif ($3 eq $refs[-1]{'name'}) {
1162 # most likely a tag is followed by its peeled
1163 # (deref) one, and when that happens we know the
1164 # previous one was of type 'tag'.
1165 $refs[-1]{'type'} = "tag";
1166 }
Jakub Narebski717b8312006-07-31 21:22:15 +02001167 }
Jakub Narebskic83a77e2006-09-15 03:43:28 +02001168 }
1169 close $fd;
Junio C Hamano7a13b992006-07-31 19:18:34 -07001170
Jakub Narebskic83a77e2006-09-15 03:43:28 +02001171 foreach my $ref (@refs) {
1172 my $ref_file = $ref->{'name'};
1173 my $ref_id = $ref->{'hash'};
1174
1175 my $type = $ref->{'type'} || git_get_type($ref_id) || next;
Jakub Narebskia446d6b2006-08-14 02:07:00 +02001176 my %ref_item = parse_ref($ref_file, $ref_id, $type);
Jakub Narebski717b8312006-07-31 21:22:15 +02001177
1178 push @reflist, \%ref_item;
1179 }
Jakub Narebskia446d6b2006-08-14 02:07:00 +02001180 # sort refs by age
Jakub Narebski717b8312006-07-31 21:22:15 +02001181 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
Jakub Narebski120ddde2006-09-19 14:33:22 +02001182 return (\@reflist, \%refs);
Jakub Narebski717b8312006-07-31 21:22:15 +02001183}
1184
1185## ----------------------------------------------------------------------
1186## filesystem-related functions
1187
1188sub get_file_owner {
1189 my $path = shift;
1190
1191 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1192 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1193 if (!defined $gcos) {
1194 return undef;
1195 }
1196 my $owner = $gcos;
1197 $owner =~ s/[,;].*$//;
1198 return decode("utf8", $owner, Encode::FB_DEFAULT);
1199}
1200
1201## ......................................................................
1202## mimetype related functions
1203
1204sub mimetype_guess_file {
1205 my $filename = shift;
1206 my $mimemap = shift;
1207 -r $mimemap or return undef;
1208
1209 my %mimemap;
1210 open(MIME, $mimemap) or return undef;
1211 while (<MIME>) {
Jakub Narebski618918e2006-08-14 02:15:22 +02001212 next if m/^#/; # skip comments
Jakub Narebski717b8312006-07-31 21:22:15 +02001213 my ($mime, $exts) = split(/\t+/);
Junio C Hamano46b059d2006-07-31 19:24:37 -07001214 if (defined $exts) {
1215 my @exts = split(/\s+/, $exts);
1216 foreach my $ext (@exts) {
1217 $mimemap{$ext} = $mime;
1218 }
Jakub Narebski717b8312006-07-31 21:22:15 +02001219 }
1220 }
1221 close(MIME);
1222
Jakub Narebski80593192006-09-19 13:57:03 +02001223 $filename =~ /\.([^.]*)$/;
Jakub Narebski717b8312006-07-31 21:22:15 +02001224 return $mimemap{$1};
1225}
1226
1227sub mimetype_guess {
1228 my $filename = shift;
1229 my $mime;
1230 $filename =~ /\./ or return undef;
1231
1232 if ($mimetypes_file) {
1233 my $file = $mimetypes_file;
Jakub Narebskid5aa50d2006-08-14 02:16:33 +02001234 if ($file !~ m!^/!) { # if it is relative path
1235 # it is relative to project
1236 $file = "$projectroot/$project/$file";
1237 }
Jakub Narebski717b8312006-07-31 21:22:15 +02001238 $mime = mimetype_guess_file($filename, $file);
1239 }
1240 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1241 return $mime;
1242}
1243
Jakub Narebski847e01f2006-08-14 02:05:47 +02001244sub blob_mimetype {
Jakub Narebski717b8312006-07-31 21:22:15 +02001245 my $fd = shift;
1246 my $filename = shift;
1247
1248 if ($filename) {
1249 my $mime = mimetype_guess($filename);
1250 $mime and return $mime;
1251 }
1252
1253 # just in case
1254 return $default_blob_plain_mimetype unless $fd;
1255
1256 if (-T $fd) {
1257 return 'text/plain' .
1258 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1259 } elsif (! $filename) {
1260 return 'application/octet-stream';
1261 } elsif ($filename =~ m/\.png$/i) {
1262 return 'image/png';
1263 } elsif ($filename =~ m/\.gif$/i) {
1264 return 'image/gif';
1265 } elsif ($filename =~ m/\.jpe?g$/i) {
1266 return 'image/jpeg';
1267 } else {
1268 return 'application/octet-stream';
1269 }
1270}
1271
1272## ======================================================================
1273## functions printing HTML: header, footer, error page
1274
Kay Sievers12a88f22005-08-07 20:02:47 +02001275sub git_header_html {
Kay Sieversa59d4af2005-08-07 20:15:44 +02001276 my $status = shift || "200 OK";
Kay Sievers11044292005-10-19 03:18:45 +02001277 my $expires = shift;
Kay Sieversa59d4af2005-08-07 20:15:44 +02001278
Alp Toker49da1da2006-07-11 21:10:26 +01001279 my $title = "$site_name git";
Kay Sieversb87d78d2005-08-07 20:21:04 +02001280 if (defined $project) {
1281 $title .= " - $project";
1282 if (defined $action) {
1283 $title .= "/$action";
Jakub Narebski7bedd9f2006-06-20 06:17:03 +00001284 if (defined $file_name) {
1285 $title .= " - $file_name";
1286 if ($action eq "tree" && $file_name !~ m|/$|) {
1287 $title .= "/";
1288 }
1289 }
Kay Sieversb87d78d2005-08-07 20:21:04 +02001290 }
1291 }
Alp Tokerf6801d62006-07-11 11:19:34 +01001292 my $content_type;
1293 # require explicit support from the UA if we are to send the page as
1294 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1295 # we have to do this because MSIE sometimes globs '*/*', pretending to
1296 # support xhtml+xml but choking when it gets what it asked for.
Jakub Narebski952c65f2006-08-22 16:52:50 +02001297 if (defined $cgi->http('HTTP_ACCEPT') &&
1298 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
1299 $cgi->Accept('application/xhtml+xml') != 0) {
Alp Tokerf6801d62006-07-11 11:19:34 +01001300 $content_type = 'application/xhtml+xml';
1301 } else {
1302 $content_type = 'text/html';
1303 }
Jakub Narebski952c65f2006-08-22 16:52:50 +02001304 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
1305 -status=> $status, -expires => $expires);
Kay Sieversa59d4af2005-08-07 20:15:44 +02001306 print <<EOF;
Kay Sievers6191f8e2005-08-07 20:19:56 +02001307<?xml version="1.0" encoding="utf-8"?>
Kay Sievers161332a2005-08-07 19:49:46 +02001308<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Kay Sievers034df392005-08-07 20:20:07 +02001309<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
Jakub Narebskid4baf9e2006-08-17 11:21:28 +02001310<!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
Jakub Narebskiae20de52006-06-21 09:48:03 +02001311<!-- git core binaries version $git_version -->
Kay Sievers161332a2005-08-07 19:49:46 +02001312<head>
Alp Tokerf6801d62006-07-11 11:19:34 +01001313<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
Jakub Narebskid4baf9e2006-08-17 11:21:28 +02001314<meta name="generator" content="gitweb/$version git/$git_version"/>
Kay Sieversc994d622005-08-07 20:27:18 +02001315<meta name="robots" content="index, nofollow"/>
Kay Sieversb87d78d2005-08-07 20:21:04 +02001316<title>$title</title>
Jakub Narebskiae20de52006-06-21 09:48:03 +02001317<link rel="stylesheet" type="text/css" href="$stylesheet"/>
Kay Sievers161332a2005-08-07 19:49:46 +02001318EOF
Matthias Lederhoferdd04c422006-08-06 13:25:41 +02001319 if (defined $project) {
1320 printf('<link rel="alternate" title="%s log" '.
1321 'href="%s" type="application/rss+xml"/>'."\n",
Martin Waitz1c2a4f52006-08-16 00:24:30 +02001322 esc_param($project), href(action=>"rss"));
Jakub Narebski9d0734a2006-09-15 11:11:33 +02001323 } else {
1324 printf('<link rel="alternate" title="%s projects list" '.
1325 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1326 $site_name, href(project=>undef, action=>"project_index"));
1327 printf('<link rel="alternate" title="%s projects logs" '.
1328 'href="%s" type="text/x-opml"/>'."\n",
1329 $site_name, href(project=>undef, action=>"opml"));
Matthias Lederhoferdd04c422006-08-06 13:25:41 +02001330 }
Jakub Narebski0b5deba2006-09-04 20:32:13 +02001331 if (defined $favicon) {
1332 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1333 }
Jakub Narebski10161352006-08-05 13:18:58 +02001334
Matthias Lederhoferdd04c422006-08-06 13:25:41 +02001335 print "</head>\n" .
1336 "<body>\n" .
Jakub Narebski10161352006-08-05 13:18:58 +02001337 "<div class=\"page_header\">\n" .
Kay Sieversc994d622005-08-07 20:27:18 +02001338 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
Martin Waitz281f2f62006-07-31 00:38:39 +02001339 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
Kay Sievers19806692005-08-07 20:26:27 +02001340 "</a>\n";
Yasushi SHOJI2de21fa2006-08-15 07:50:49 +09001341 print $cgi->a({-href => esc_param($home_link)}, $home_link_str) . " / ";
Kay Sieversb87d78d2005-08-07 20:21:04 +02001342 if (defined $project) {
Martin Waitz1c2a4f52006-08-16 00:24:30 +02001343 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
Kay Sieversb87d78d2005-08-07 20:21:04 +02001344 if (defined $action) {
1345 print " / $action";
1346 }
Kay Sievers19806692005-08-07 20:26:27 +02001347 print "\n";
1348 if (!defined $searchtext) {
1349 $searchtext = "";
1350 }
Kay Sieversc39e47d2005-09-17 03:00:21 +02001351 my $search_hash;
Timo Hirvonen4c5c2022006-06-20 16:41:05 +03001352 if (defined $hash_base) {
1353 $search_hash = $hash_base;
1354 } elsif (defined $hash) {
Kay Sieversc39e47d2005-09-17 03:00:21 +02001355 $search_hash = $hash;
1356 } else {
Jakub Narebski8adc4bd2006-06-22 08:52:57 +02001357 $search_hash = "HEAD";
Kay Sieversc39e47d2005-09-17 03:00:21 +02001358 }
Kay Sievers19806692005-08-07 20:26:27 +02001359 $cgi->param("a", "search");
Kay Sieversc39e47d2005-09-17 03:00:21 +02001360 $cgi->param("h", $search_hash);
Kay Sievers353347b2005-11-14 05:47:18 +01001361 print $cgi->startform(-method => "get", -action => $my_uri) .
Kay Sieversc994d622005-08-07 20:27:18 +02001362 "<div class=\"search\">\n" .
1363 $cgi->hidden(-name => "p") . "\n" .
1364 $cgi->hidden(-name => "a") . "\n" .
Kay Sieversc39e47d2005-09-17 03:00:21 +02001365 $cgi->hidden(-name => "h") . "\n" .
Kay Sieversc994d622005-08-07 20:27:18 +02001366 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
1367 "</div>" .
1368 $cgi->end_form() . "\n";
Kay Sievers4c02e3c2005-08-07 19:52:52 +02001369 }
1370 print "</div>\n";
Kay Sievers161332a2005-08-07 19:49:46 +02001371}
1372
Kay Sievers12a88f22005-08-07 20:02:47 +02001373sub git_footer_html {
Kay Sievers6191f8e2005-08-07 20:19:56 +02001374 print "<div class=\"page_footer\">\n";
Kay Sieversb87d78d2005-08-07 20:21:04 +02001375 if (defined $project) {
Jakub Narebski847e01f2006-08-14 02:05:47 +02001376 my $descr = git_get_project_description($project);
Kay Sieversb87d78d2005-08-07 20:21:04 +02001377 if (defined $descr) {
Kay Sievers40c13812005-11-19 17:41:29 +01001378 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
Kay Sievers6191f8e2005-08-07 20:19:56 +02001379 }
Jakub Narebskia1565c42006-09-15 19:30:34 +02001380 print $cgi->a({-href => href(action=>"rss"),
1381 -class => "rss_logo"}, "RSS") . "\n";
Kay Sieversc994d622005-08-07 20:27:18 +02001382 } else {
Jakub Narebskia1565c42006-09-15 19:30:34 +02001383 print $cgi->a({-href => href(project=>undef, action=>"opml"),
Jakub Narebski9d0734a2006-09-15 11:11:33 +02001384 -class => "rss_logo"}, "OPML") . " ";
1385 print $cgi->a({-href => href(project=>undef, action=>"project_index"),
1386 -class => "rss_logo"}, "TXT") . "\n";
Kay Sieversff7669a2005-08-07 20:13:02 +02001387 }
Kay Sievers6191f8e2005-08-07 20:19:56 +02001388 print "</div>\n" .
1389 "</body>\n" .
Kay Sievers9cd3d982005-08-07 20:17:42 +02001390 "</html>";
Kay Sievers161332a2005-08-07 19:49:46 +02001391}
1392
Kay Sievers061cc7c2005-08-07 20:15:57 +02001393sub die_error {
1394 my $status = shift || "403 Forbidden";
Jakub Narebski7a9b4c52006-06-21 09:48:02 +02001395 my $error = shift || "Malformed query, file missing or permission denied";
Kay Sievers664f4cc2005-08-07 20:17:19 +02001396
Kay Sieversa59d4af2005-08-07 20:15:44 +02001397 git_header_html($status);
Jakub Narebski59b9f612006-08-22 23:42:53 +02001398 print <<EOF;
1399<div class="page_body">
1400<br /><br />
1401$status - $error
1402<br />
1403</div>
1404EOF
Kay Sieversa59d4af2005-08-07 20:15:44 +02001405 git_footer_html();
Kay Sievers09bd7892005-08-07 20:21:23 +02001406 exit;
Kay Sieversa59d4af2005-08-07 20:15:44 +02001407}
1408
Jakub Narebski717b8312006-07-31 21:22:15 +02001409## ----------------------------------------------------------------------
1410## functions printing or outputting HTML: navigation
1411
Jakub Narebski847e01f2006-08-14 02:05:47 +02001412sub git_print_page_nav {
Jakub Narebskib18f9bf2006-07-30 14:59:57 +02001413 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1414 $extra = '' if !defined $extra; # pager or formats
1415
1416 my @navs = qw(summary shortlog log commit commitdiff tree);
1417 if ($suppress) {
1418 @navs = grep { $_ ne $suppress } @navs;
1419 }
1420
Martin Waitz1c2a4f52006-08-16 00:24:30 +02001421 my %arg = map { $_ => {action=>$_} } @navs;
Jakub Narebskib18f9bf2006-07-30 14:59:57 +02001422 if (defined $head) {
1423 for (qw(commit commitdiff)) {
Martin Waitz1c2a4f52006-08-16 00:24:30 +02001424 $arg{$_}{hash} = $head;
Jakub Narebskib18f9bf2006-07-30 14:59:57 +02001425 }
1426 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1427 for (qw(shortlog log)) {
Martin Waitz1c2a4f52006-08-16 00:24:30 +02001428 $arg{$_}{hash} = $head;
Jakub Narebskib18f9bf2006-07-30 14:59:57 +02001429 }
1430 }
1431 }
Martin Waitz1c2a4f52006-08-16 00:24:30 +02001432 $arg{tree}{hash} = $treehead if defined $treehead;
1433 $arg{tree}{hash_base} = $treebase if defined $treebase;
Jakub Narebskib18f9bf2006-07-30 14:59:57 +02001434
1435 print "<div class=\"page_nav\">\n" .
1436 (join " | ",
Martin Waitz1c2a4f52006-08-16 00:24:30 +02001437 map { $_ eq $current ?
1438 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
1439 } @navs);
Jakub Narebski898a8932006-07-30 16:14:43 +02001440 print "<br/>\n$extra<br/>\n" .
Jakub Narebskib18f9bf2006-07-30 14:59:57 +02001441 "</div>\n";
1442}
1443
Jakub Narebski847e01f2006-08-14 02:05:47 +02001444sub format_paging_nav {
Jakub Narebski6855f422006-07-30 20:31:00 +02001445 my ($action, $hash, $head, $page, $nrevs) = @_;
Jakub Narebski43ffc062006-07-30 17:49:00 +02001446 my $paging_nav;
1447
1448
1449 if ($hash ne $head || $page) {
Martin Waitz1c2a4f52006-08-16 00:24:30 +02001450 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
Jakub Narebski43ffc062006-07-30 17:49:00 +02001451 } else {
1452 $paging_nav .= "HEAD";
1453 }
1454
1455 if ($page > 0) {
1456 $paging_nav .= " &sdot; " .
Martin Waitz1c2a4f52006-08-16 00:24:30 +02001457 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1),
Jakub Narebski26298b52006-08-10 12:38:47 +02001458 -accesskey => "p", -title => "Alt-p"}, "prev");
Jakub Narebski43ffc062006-07-30 17:49:00 +02001459 } else {
1460 $paging_nav .= " &sdot; prev";
1461 }
1462
1463 if ($nrevs >= (100 * ($page+1)-1)) {
1464 $paging_nav .= " &sdot; " .
Martin Waitz1c2a4f52006-08-16 00:24:30 +02001465 $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1),
Jakub Narebski26298b52006-08-10 12:38:47 +02001466 -accesskey => "n", -title => "Alt-n"}, "next");
Jakub Narebski43ffc062006-07-30 17:49:00 +02001467 } else {
1468 $paging_nav .= " &sdot; next";
1469 }
1470
1471 return $paging_nav;
1472}
1473
Jakub Narebski717b8312006-07-31 21:22:15 +02001474## ......................................................................
1475## functions printing or outputting HTML: div
Kay Sievers42f7eb92005-08-07 20:21:46 +02001476
Jakub Narebski847e01f2006-08-14 02:05:47 +02001477sub git_print_header_div {
Jakub Narebski717b8312006-07-31 21:22:15 +02001478 my ($action, $title, $hash, $hash_base) = @_;
Martin Waitz1c2a4f52006-08-16 00:24:30 +02001479 my %args = ();
Jakub Narebski717b8312006-07-31 21:22:15 +02001480
Martin Waitz1c2a4f52006-08-16 00:24:30 +02001481 $args{action} = $action;
1482 $args{hash} = $hash if $hash;
1483 $args{hash_base} = $hash_base if $hash_base;
Jakub Narebski717b8312006-07-31 21:22:15 +02001484
1485 print "<div class=\"header\">\n" .
Martin Waitz1c2a4f52006-08-16 00:24:30 +02001486 $cgi->a({-href => href(%args), -class => "title"},
1487 $title ? $title : $action) .
1488 "\n</div>\n";
Kay Sievers42f7eb92005-08-07 20:21:46 +02001489}
1490
Jakub Narebski6fd92a22006-08-28 14:48:12 +02001491#sub git_print_authorship (\%) {
1492sub git_print_authorship {
1493 my $co = shift;
1494
Jakub Narebskia44465c2006-08-28 23:17:31 +02001495 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
Jakub Narebski6fd92a22006-08-28 14:48:12 +02001496 print "<div class=\"author_date\">" .
1497 esc_html($co->{'author_name'}) .
Jakub Narebskia44465c2006-08-28 23:17:31 +02001498 " [$ad{'rfc2822'}";
1499 if ($ad{'hour_local'} < 6) {
1500 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1501 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1502 } else {
1503 printf(" (%02d:%02d %s)",
1504 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1505 }
1506 print "]</div>\n";
Jakub Narebski6fd92a22006-08-28 14:48:12 +02001507}
1508
Jakub Narebski717b8312006-07-31 21:22:15 +02001509sub git_print_page_path {
1510 my $name = shift;
1511 my $type = shift;
Luben Tuikov59fb1c92006-08-17 10:39:29 -07001512 my $hb = shift;
Junio C Hamanodf2c37a2006-01-09 13:13:39 +01001513
Jakub Narebski717b8312006-07-31 21:22:15 +02001514 if (!defined $name) {
Jakub Narebski63e42202006-08-22 12:38:59 +02001515 print "<div class=\"page_path\">/</div>\n";
Jakub Narebski762c7202006-09-04 18:17:58 +02001516 } else {
1517 my @dirname = split '/', $name;
1518 my $basename = pop @dirname;
1519 my $fullname = '';
1520
Jakub Narebski63e42202006-08-22 12:38:59 +02001521 print "<div class=\"page_path\">";
Petr Baudis16fdb482006-09-21 02:05:50 +02001522 print $cgi->a({-href => href(action=>"tree", hash_base=>$hb),
1523 -title => '/'}, '/');
1524 print " ";
Jakub Narebski762c7202006-09-04 18:17:58 +02001525 foreach my $dir (@dirname) {
Petr Baudis16fdb482006-09-21 02:05:50 +02001526 $fullname .= ($fullname ? '/' : '') . $dir;
Jakub Narebski762c7202006-09-04 18:17:58 +02001527 print $cgi->a({-href => href(action=>"tree", file_name=>$fullname,
1528 hash_base=>$hb),
Petr Baudis16fdb482006-09-21 02:05:50 +02001529 -title => $fullname}, esc_html($dir . '/'));
1530 print " ";
Jakub Narebski762c7202006-09-04 18:17:58 +02001531 }
1532 if (defined $type && $type eq 'blob') {
Jakub Narebski952c65f2006-08-22 16:52:50 +02001533 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
Jakub Narebski762c7202006-09-04 18:17:58 +02001534 hash_base=>$hb),
1535 -title => $name}, esc_html($basename));
1536 } elsif (defined $type && $type eq 'tree') {
1537 print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
1538 hash_base=>$hb),
Petr Baudis16fdb482006-09-21 02:05:50 +02001539 -title => $name}, esc_html($basename . '/'));
Luben Tuikov59fb1c92006-08-17 10:39:29 -07001540 } else {
Jakub Narebski762c7202006-09-04 18:17:58 +02001541 print esc_html($basename);
Luben Tuikov59fb1c92006-08-17 10:39:29 -07001542 }
Jakub Narebski63e42202006-08-22 12:38:59 +02001543 print "<br/></div>\n";
Kay Sievers8ed23e12005-08-07 20:05:44 +02001544 }
Kay Sievers4c02e3c2005-08-07 19:52:52 +02001545}
1546
Jakub Narebskib7f92532006-08-28 14:48:10 +02001547# sub git_print_log (\@;%) {
1548sub git_print_log ($;%) {
Jakub Narebskid16d0932006-08-17 11:21:23 +02001549 my $log = shift;
Jakub Narebskib7f92532006-08-28 14:48:10 +02001550 my %opts = @_;
Jakub Narebskid16d0932006-08-17 11:21:23 +02001551
Jakub Narebskib7f92532006-08-28 14:48:10 +02001552 if ($opts{'-remove_title'}) {
1553 # remove title, i.e. first line of log
1554 shift @$log;
1555 }
Jakub Narebskid16d0932006-08-17 11:21:23 +02001556 # remove leading empty lines
1557 while (defined $log->[0] && $log->[0] eq "") {
1558 shift @$log;
1559 }
1560
1561 # print log
1562 my $signoff = 0;
1563 my $empty = 0;
1564 foreach my $line (@$log) {
Jakub Narebskib7f92532006-08-28 14:48:10 +02001565 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1566 $signoff = 1;
Jakub Narebskifba20b42006-08-28 14:48:13 +02001567 $empty = 0;
Jakub Narebskib7f92532006-08-28 14:48:10 +02001568 if (! $opts{'-remove_signoff'}) {
1569 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
1570 next;
1571 } else {
1572 # remove signoff lines
1573 next;
1574 }
1575 } else {
1576 $signoff = 0;
1577 }
1578
Jakub Narebskid16d0932006-08-17 11:21:23 +02001579 # print only one empty line
1580 # do not print empty line after signoff
1581 if ($line eq "") {
1582 next if ($empty || $signoff);
1583 $empty = 1;
1584 } else {
1585 $empty = 0;
1586 }
Jakub Narebskib7f92532006-08-28 14:48:10 +02001587
1588 print format_log_line_html($line) . "<br/>\n";
1589 }
1590
1591 if ($opts{'-final_empty_line'}) {
1592 # end with single empty line
1593 print "<br/>\n" unless $empty;
Jakub Narebskid16d0932006-08-17 11:21:23 +02001594 }
1595}
1596
1597sub git_print_simplified_log {
1598 my $log = shift;
1599 my $remove_title = shift;
1600
Jakub Narebskib7f92532006-08-28 14:48:10 +02001601 git_print_log($log,
1602 -final_empty_line=> 1,
Jakub Narebskib7f92532006-08-28 14:48:10 +02001603 -remove_title => $remove_title);
Jakub Narebskid16d0932006-08-17 11:21:23 +02001604}
1605
Jakub Narebskifa702002006-08-31 00:35:07 +02001606# print tree entry (row of git_tree), but without encompassing <tr> element
1607sub git_print_tree_entry {
1608 my ($t, $basedir, $hash_base, $have_blame) = @_;
1609
1610 my %base_key = ();
1611 $base_key{hash_base} = $hash_base if defined $hash_base;
1612
1613 print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n";
1614 if ($t->{'type'} eq "blob") {
1615 print "<td class=\"list\">" .
1616 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
1617 file_name=>"$basedir$t->{'name'}", %base_key),
1618 -class => "list"}, esc_html($t->{'name'})) .
1619 "</td>\n" .
1620 "<td class=\"link\">" .
1621 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
1622 file_name=>"$basedir$t->{'name'}", %base_key)},
1623 "blob");
1624 if ($have_blame) {
1625 print " | " .
1626 $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},
1627 file_name=>"$basedir$t->{'name'}", %base_key)},
1628 "blame");
1629 }
1630 if (defined $hash_base) {
1631 print " | " .
1632 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
1633 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
1634 "history");
1635 }
1636 print " | " .
1637 $cgi->a({-href => href(action=>"blob_plain",
1638 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
1639 "raw") .
1640 "</td>\n";
1641
1642 } elsif ($t->{'type'} eq "tree") {
1643 print "<td class=\"list\">" .
1644 $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
1645 file_name=>"$basedir$t->{'name'}", %base_key)},
1646 esc_html($t->{'name'})) .
1647 "</td>\n" .
1648 "<td class=\"link\">" .
1649 $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
1650 file_name=>"$basedir$t->{'name'}", %base_key)},
1651 "tree");
1652 if (defined $hash_base) {
1653 print " | " .
1654 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
1655 file_name=>"$basedir$t->{'name'}")},
1656 "history");
1657 }
1658 print "</td>\n";
1659 }
1660}
1661
Jakub Narebski717b8312006-07-31 21:22:15 +02001662## ......................................................................
1663## functions printing large fragments of HTML
Kay Sieversede5e102005-08-07 20:23:12 +02001664
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001665sub git_difftree_body {
Jakub Narebskieee08902006-08-24 00:15:14 +02001666 my ($difftree, $hash, $parent) = @_;
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001667
1668 print "<div class=\"list_head\">\n";
1669 if ($#{$difftree} > 10) {
1670 print(($#{$difftree} + 1) . " files changed:\n");
1671 }
1672 print "</div>\n";
1673
1674 print "<table class=\"diff_tree\">\n";
1675 my $alternate = 0;
Jakub Narebskib4657e72006-08-28 14:48:14 +02001676 my $patchno = 0;
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001677 foreach my $line (@{$difftree}) {
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001678 my %diff = parse_difftree_raw_line($line);
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001679
1680 if ($alternate) {
1681 print "<tr class=\"dark\">\n";
1682 } else {
1683 print "<tr class=\"light\">\n";
1684 }
1685 $alternate ^= 1;
1686
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001687 my ($to_mode_oct, $to_mode_str, $to_file_type);
1688 my ($from_mode_oct, $from_mode_str, $from_file_type);
1689 if ($diff{'to_mode'} ne ('0' x 6)) {
1690 $to_mode_oct = oct $diff{'to_mode'};
1691 if (S_ISREG($to_mode_oct)) { # only for regular file
1692 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001693 }
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001694 $to_file_type = file_type($diff{'to_mode'});
1695 }
1696 if ($diff{'from_mode'} ne ('0' x 6)) {
1697 $from_mode_oct = oct $diff{'from_mode'};
1698 if (S_ISREG($to_mode_oct)) { # only for regular file
1699 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1700 }
1701 $from_file_type = file_type($diff{'from_mode'});
1702 }
1703
1704 if ($diff{'status'} eq "A") { # created
1705 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1706 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1707 $mode_chng .= "]</span>";
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001708 print "<td>" .
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001709 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1710 hash_base=>$hash, file_name=>$diff{'file'}),
1711 -class => "list"}, esc_html($diff{'file'})) .
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001712 "</td>\n" .
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001713 "<td>$mode_chng</td>\n" .
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001714 "<td class=\"link\">" .
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001715 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1716 hash_base=>$hash, file_name=>$diff{'file'})},
Jakub Narebskib4657e72006-08-28 14:48:14 +02001717 "blob");
Jakub Narebski72dbafa2006-09-04 18:19:58 +02001718 if ($action eq 'commitdiff') {
Jakub Narebskib4657e72006-08-28 14:48:14 +02001719 # link to patch
1720 $patchno++;
1721 print " | " .
1722 $cgi->a({-href => "#patch$patchno"}, "patch");
1723 }
1724 print "</td>\n";
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001725
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001726 } elsif ($diff{'status'} eq "D") { # deleted
1727 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001728 print "<td>" .
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001729 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1730 hash_base=>$parent, file_name=>$diff{'file'}),
1731 -class => "list"}, esc_html($diff{'file'})) .
1732 "</td>\n" .
1733 "<td>$mode_chng</td>\n" .
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001734 "<td class=\"link\">" .
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001735 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1736 hash_base=>$parent, file_name=>$diff{'file'})},
1737 "blob") .
Jakub Narebskib4657e72006-08-28 14:48:14 +02001738 " | ";
Jakub Narebski72dbafa2006-09-04 18:19:58 +02001739 if ($action eq 'commitdiff') {
Jakub Narebskib4657e72006-08-28 14:48:14 +02001740 # link to patch
1741 $patchno++;
1742 print " | " .
1743 $cgi->a({-href => "#patch$patchno"}, "patch");
1744 }
1745 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
Jakub Narebski09052552006-08-26 23:33:58 +02001746 file_name=>$diff{'file'})},
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001747 "history") .
1748 "</td>\n";
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001749
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001750 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001751 my $mode_chnge = "";
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001752 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1753 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1754 if ($from_file_type != $to_file_type) {
1755 $mode_chnge .= " from $from_file_type to $to_file_type";
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001756 }
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001757 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1758 if ($from_mode_str && $to_mode_str) {
1759 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1760 } elsif ($to_mode_str) {
1761 $mode_chnge .= " mode: $to_mode_str";
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001762 }
1763 }
1764 $mode_chnge .= "]</span>\n";
1765 }
1766 print "<td>";
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001767 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
Jakub Narebski420e92f2006-08-24 23:53:54 +02001768 print $cgi->a({-href => href(action=>"blobdiff",
1769 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1770 hash_base=>$hash, hash_parent_base=>$parent,
1771 file_name=>$diff{'file'}),
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001772 -class => "list"}, esc_html($diff{'file'}));
1773 } else { # only mode changed
1774 print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1775 hash_base=>$hash, file_name=>$diff{'file'}),
1776 -class => "list"}, esc_html($diff{'file'}));
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001777 }
1778 print "</td>\n" .
1779 "<td>$mode_chnge</td>\n" .
1780 "<td class=\"link\">" .
Jakub Narebskib4657e72006-08-28 14:48:14 +02001781 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1782 hash_base=>$hash, file_name=>$diff{'file'})},
1783 "blob");
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001784 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
Jakub Narebski72dbafa2006-09-04 18:19:58 +02001785 if ($action eq 'commitdiff') {
Jakub Narebskib4657e72006-08-28 14:48:14 +02001786 # link to patch
1787 $patchno++;
1788 print " | " .
1789 $cgi->a({-href => "#patch$patchno"}, "patch");
1790 } else {
1791 print " | " .
1792 $cgi->a({-href => href(action=>"blobdiff",
1793 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1794 hash_base=>$hash, hash_parent_base=>$parent,
1795 file_name=>$diff{'file'})},
1796 "diff");
1797 }
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001798 }
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001799 print " | " .
1800 $cgi->a({-href => href(action=>"history",
1801 hash_base=>$hash, file_name=>$diff{'file'})},
1802 "history");
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001803 print "</td>\n";
1804
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001805 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1806 my %status_name = ('R' => 'moved', 'C' => 'copied');
1807 my $nstatus = $status_name{$diff{'status'}};
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001808 my $mode_chng = "";
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001809 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1810 # mode also for directories, so we cannot use $to_mode_str
1811 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001812 }
1813 print "<td>" .
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001814 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1815 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}),
1816 -class => "list"}, esc_html($diff{'to_file'})) . "</td>\n" .
1817 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1818 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
1819 hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}),
1820 -class => "list"}, esc_html($diff{'from_file'})) .
1821 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001822 "<td class=\"link\">" .
Jakub Narebskie8e41a92006-08-21 23:08:52 +02001823 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1824 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'})},
1825 "blob");
1826 if ($diff{'to_id'} ne $diff{'from_id'}) {
Jakub Narebski72dbafa2006-09-04 18:19:58 +02001827 if ($action eq 'commitdiff') {
Jakub Narebskib4657e72006-08-28 14:48:14 +02001828 # link to patch
1829 $patchno++;
1830 print " | " .
1831 $cgi->a({-href => "#patch$patchno"}, "patch");
1832 } else {
1833 print " | " .
1834 $cgi->a({-href => href(action=>"blobdiff",
1835 hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1836 hash_base=>$hash, hash_parent_base=>$parent,
1837 file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
1838 "diff");
1839 }
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001840 }
1841 print "</td>\n";
1842
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02001843 } # we should not encounter Unmerged (U) or Unknown (X) status
1844 print "</tr>\n";
1845 }
1846 print "</table>\n";
1847}
1848
Jakub Narebskieee08902006-08-24 00:15:14 +02001849sub git_patchset_body {
Jakub Narebski157e43b2006-08-24 19:34:36 +02001850 my ($fd, $difftree, $hash, $hash_parent) = @_;
Jakub Narebskieee08902006-08-24 00:15:14 +02001851
1852 my $patch_idx = 0;
1853 my $in_header = 0;
1854 my $patch_found = 0;
Jakub Narebskife875852006-08-25 20:59:39 +02001855 my $diffinfo;
Jakub Narebskieee08902006-08-24 00:15:14 +02001856
1857 print "<div class=\"patchset\">\n";
1858
Jakub Narebski157e43b2006-08-24 19:34:36 +02001859 LINE:
Jakub Narebskic8a99d72006-08-26 19:14:23 +02001860 while (my $patch_line = <$fd>) {
Jakub Narebski157e43b2006-08-24 19:34:36 +02001861 chomp $patch_line;
Jakub Narebskieee08902006-08-24 00:15:14 +02001862
1863 if ($patch_line =~ m/^diff /) { # "git diff" header
1864 # beginning of patch (in patchset)
1865 if ($patch_found) {
1866 # close previous patch
1867 print "</div>\n"; # class="patch"
1868 } else {
1869 # first patch in patchset
1870 $patch_found = 1;
1871 }
Jakub Narebskib4657e72006-08-28 14:48:14 +02001872 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
Jakub Narebskieee08902006-08-24 00:15:14 +02001873
Jakub Narebskife875852006-08-25 20:59:39 +02001874 if (ref($difftree->[$patch_idx]) eq "HASH") {
1875 $diffinfo = $difftree->[$patch_idx];
1876 } else {
1877 $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]);
1878 }
1879 $patch_idx++;
Jakub Narebskieee08902006-08-24 00:15:14 +02001880
1881 # for now, no extended header, hence we skip empty patches
1882 # companion to next LINE if $in_header;
Jakub Narebskife875852006-08-25 20:59:39 +02001883 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
Jakub Narebskieee08902006-08-24 00:15:14 +02001884 $in_header = 1;
1885 next LINE;
1886 }
1887
Jakub Narebskife875852006-08-25 20:59:39 +02001888 if ($diffinfo->{'status'} eq "A") { # added
1889 print "<div class=\"diff_info\">" . file_type($diffinfo->{'to_mode'}) . ":" .
Jakub Narebskieee08902006-08-24 00:15:14 +02001890 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
Jakub Narebskife875852006-08-25 20:59:39 +02001891 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
1892 $diffinfo->{'to_id'}) . "(new)" .
Jakub Narebskieee08902006-08-24 00:15:14 +02001893 "</div>\n"; # class="diff_info"
1894
Jakub Narebskife875852006-08-25 20:59:39 +02001895 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1896 print "<div class=\"diff_info\">" . file_type($diffinfo->{'from_mode'}) . ":" .
Jakub Narebskieee08902006-08-24 00:15:14 +02001897 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
Jakub Narebskife875852006-08-25 20:59:39 +02001898 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
1899 $diffinfo->{'from_id'}) . "(deleted)" .
Jakub Narebskieee08902006-08-24 00:15:14 +02001900 "</div>\n"; # class="diff_info"
1901
Jakub Narebskife875852006-08-25 20:59:39 +02001902 } elsif ($diffinfo->{'status'} eq "R" || # renamed
Jakub Narebski7c5e2eb2006-08-25 21:13:34 +02001903 $diffinfo->{'status'} eq "C" || # copied
1904 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
Jakub Narebskieee08902006-08-24 00:15:14 +02001905 print "<div class=\"diff_info\">" .
Jakub Narebskife875852006-08-25 20:59:39 +02001906 file_type($diffinfo->{'from_mode'}) . ":" .
Jakub Narebskieee08902006-08-24 00:15:14 +02001907 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
Jakub Narebskife875852006-08-25 20:59:39 +02001908 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'from_file'})},
1909 $diffinfo->{'from_id'}) .
Jakub Narebskieee08902006-08-24 00:15:14 +02001910 " -> " .
Jakub Narebskife875852006-08-25 20:59:39 +02001911 file_type($diffinfo->{'to_mode'}) . ":" .
Jakub Narebskieee08902006-08-24 00:15:14 +02001912 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
Jakub Narebskife875852006-08-25 20:59:39 +02001913 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'to_file'})},
1914 $diffinfo->{'to_id'});
Jakub Narebskieee08902006-08-24 00:15:14 +02001915 print "</div>\n"; # class="diff_info"
1916
1917 } else { # modified, mode changed, ...
1918 print "<div class=\"diff_info\">" .
Jakub Narebskife875852006-08-25 20:59:39 +02001919 file_type($diffinfo->{'from_mode'}) . ":" .
Jakub Narebskieee08902006-08-24 00:15:14 +02001920 $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
Jakub Narebskife875852006-08-25 20:59:39 +02001921 hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
1922 $diffinfo->{'from_id'}) .
Jakub Narebskieee08902006-08-24 00:15:14 +02001923 " -> " .
Jakub Narebskife875852006-08-25 20:59:39 +02001924 file_type($diffinfo->{'to_mode'}) . ":" .
Jakub Narebskieee08902006-08-24 00:15:14 +02001925 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
Jakub Narebskife875852006-08-25 20:59:39 +02001926 hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
1927 $diffinfo->{'to_id'});
Jakub Narebskieee08902006-08-24 00:15:14 +02001928 print "</div>\n"; # class="diff_info"
1929 }
1930
1931 #print "<div class=\"diff extended_header\">\n";
1932 $in_header = 1;
1933 next LINE;
1934 } # start of patch in patchset
1935
1936
1937 if ($in_header && $patch_line =~ m/^---/) {
Jakub Narebskie4e4f822006-08-25 21:04:13 +02001938 #print "</div>\n"; # class="diff extended_header"
Jakub Narebskieee08902006-08-24 00:15:14 +02001939 $in_header = 0;
Jakub Narebskie4e4f822006-08-25 21:04:13 +02001940
1941 my $file = $diffinfo->{'from_file'};
1942 $file ||= $diffinfo->{'file'};
Jakub Narebskief10ee82006-08-25 21:05:07 +02001943 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
1944 hash=>$diffinfo->{'from_id'}, file_name=>$file),
1945 -class => "list"}, esc_html($file));
1946 $patch_line =~ s|a/.*$|a/$file|g;
1947 print "<div class=\"diff from_file\">$patch_line</div>\n";
Jakub Narebskie4e4f822006-08-25 21:04:13 +02001948
1949 $patch_line = <$fd>;
1950 chomp $patch_line;
1951
1952 #$patch_line =~ m/^+++/;
1953 $file = $diffinfo->{'to_file'};
1954 $file ||= $diffinfo->{'file'};
Jakub Narebskief10ee82006-08-25 21:05:07 +02001955 $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
1956 hash=>$diffinfo->{'to_id'}, file_name=>$file),
1957 -class => "list"}, esc_html($file));
1958 $patch_line =~ s|b/.*|b/$file|g;
1959 print "<div class=\"diff to_file\">$patch_line</div>\n";
Jakub Narebskie4e4f822006-08-25 21:04:13 +02001960
1961 next LINE;
Jakub Narebskieee08902006-08-24 00:15:14 +02001962 }
1963 next LINE if $in_header;
1964
1965 print format_diff_line($patch_line);
1966 }
1967 print "</div>\n" if $patch_found; # class="patch"
1968
1969 print "</div>\n"; # class="patchset"
1970}
1971
1972# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1973
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02001974sub git_shortlog_body {
1975 # uses global variable $project
1976 my ($revlist, $from, $to, $refs, $extra) = @_;
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +05301977
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02001978 $from = 0 unless defined $from;
1979 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1980
1981 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1982 my $alternate = 0;
1983 for (my $i = $from; $i <= $to; $i++) {
1984 my $commit = $revlist->[$i];
Jakub Narebski847e01f2006-08-14 02:05:47 +02001985 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1986 my $ref = format_ref_marker($refs, $commit);
1987 my %co = parse_commit($commit);
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02001988 if ($alternate) {
1989 print "<tr class=\"dark\">\n";
1990 } else {
1991 print "<tr class=\"light\">\n";
1992 }
1993 $alternate ^= 1;
1994 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1995 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1996 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1997 "<td>";
Jakub Narebski952c65f2006-08-22 16:52:50 +02001998 print format_subject_html($co{'title'}, $co{'title_short'},
1999 href(action=>"commit", hash=>$commit), $ref);
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002000 print "</td>\n" .
2001 "<td class=\"link\">" .
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002002 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
Petr Baudis35749ae2006-09-22 03:19:44 +02002003 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
2004 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree");
Aneesh Kumar K.Vcb9c6e52006-08-17 20:59:46 +05302005 print "</td>\n" .
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002006 "</tr>\n";
2007 }
2008 if (defined $extra) {
2009 print "<tr>\n" .
2010 "<td colspan=\"4\">$extra</td>\n" .
2011 "</tr>\n";
2012 }
2013 print "</table>\n";
2014}
2015
Jakub Narebski581860e2006-08-14 02:09:08 +02002016sub git_history_body {
2017 # Warning: assumes constant type (blob or tree) during history
Jakub Narebski8be68352006-09-11 00:36:04 +02002018 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2019
2020 $from = 0 unless defined $from;
2021 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
Jakub Narebski581860e2006-08-14 02:09:08 +02002022
2023 print "<table class=\"history\" cellspacing=\"0\">\n";
2024 my $alternate = 0;
Jakub Narebski8be68352006-09-11 00:36:04 +02002025 for (my $i = $from; $i <= $to; $i++) {
2026 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
Jakub Narebski581860e2006-08-14 02:09:08 +02002027 next;
2028 }
2029
2030 my $commit = $1;
2031 my %co = parse_commit($commit);
2032 if (!%co) {
2033 next;
2034 }
2035
2036 my $ref = format_ref_marker($refs, $commit);
2037
2038 if ($alternate) {
2039 print "<tr class=\"dark\">\n";
2040 } else {
2041 print "<tr class=\"light\">\n";
2042 }
2043 $alternate ^= 1;
2044 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2045 # shortlog uses chop_str($co{'author_name'}, 10)
2046 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2047 "<td>";
2048 # originally git_history used chop_str($co{'title'}, 50)
Jakub Narebski952c65f2006-08-22 16:52:50 +02002049 print format_subject_html($co{'title'}, $co{'title_short'},
2050 href(action=>"commit", hash=>$commit), $ref);
Jakub Narebski581860e2006-08-14 02:09:08 +02002051 print "</td>\n" .
2052 "<td class=\"link\">" .
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002053 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
2054 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
2055 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype);
Jakub Narebski581860e2006-08-14 02:09:08 +02002056
2057 if ($ftype eq 'blob') {
2058 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
2059 my $blob_parent = git_get_hash_by_path($commit, $file_name);
2060 if (defined $blob_current && defined $blob_parent &&
2061 $blob_current ne $blob_parent) {
2062 print " | " .
Jakub Narebski420e92f2006-08-24 23:53:54 +02002063 $cgi->a({-href => href(action=>"blobdiff",
2064 hash=>$blob_current, hash_parent=>$blob_parent,
2065 hash_base=>$hash_base, hash_parent_base=>$commit,
2066 file_name=>$file_name)},
Jakub Narebski581860e2006-08-14 02:09:08 +02002067 "diff to current");
2068 }
2069 }
2070 print "</td>\n" .
2071 "</tr>\n";
2072 }
2073 if (defined $extra) {
2074 print "<tr>\n" .
2075 "<td colspan=\"4\">$extra</td>\n" .
2076 "</tr>\n";
2077 }
2078 print "</table>\n";
2079}
2080
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002081sub git_tags_body {
2082 # uses global variable $project
2083 my ($taglist, $from, $to, $extra) = @_;
2084 $from = 0 unless defined $from;
2085 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2086
2087 print "<table class=\"tags\" cellspacing=\"0\">\n";
2088 my $alternate = 0;
2089 for (my $i = $from; $i <= $to; $i++) {
2090 my $entry = $taglist->[$i];
2091 my %tag = %$entry;
2092 my $comment_lines = $tag{'comment'};
2093 my $comment = shift @$comment_lines;
2094 my $comment_short;
2095 if (defined $comment) {
2096 $comment_short = chop_str($comment, 30, 5);
2097 }
2098 if ($alternate) {
2099 print "<tr class=\"dark\">\n";
2100 } else {
2101 print "<tr class=\"light\">\n";
2102 }
2103 $alternate ^= 1;
2104 print "<td><i>$tag{'age'}</i></td>\n" .
2105 "<td>" .
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002106 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
Jakub Narebski63e42202006-08-22 12:38:59 +02002107 -class => "list name"}, esc_html($tag{'name'})) .
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002108 "</td>\n" .
2109 "<td>";
2110 if (defined $comment) {
Jakub Narebski952c65f2006-08-22 16:52:50 +02002111 print format_subject_html($comment, $comment_short,
2112 href(action=>"tag", hash=>$tag{'id'}));
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002113 }
2114 print "</td>\n" .
2115 "<td class=\"selflink\">";
2116 if ($tag{'type'} eq "tag") {
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002117 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002118 } else {
2119 print "&nbsp;";
2120 }
2121 print "</td>\n" .
2122 "<td class=\"link\">" . " | " .
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002123 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002124 if ($tag{'reftype'} eq "commit") {
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002125 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
2126 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'refid'})}, "log");
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002127 } elsif ($tag{'reftype'} eq "blob") {
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002128 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002129 }
2130 print "</td>\n" .
2131 "</tr>";
2132 }
2133 if (defined $extra) {
2134 print "<tr>\n" .
2135 "<td colspan=\"5\">$extra</td>\n" .
2136 "</tr>\n";
2137 }
2138 print "</table>\n";
2139}
2140
2141sub git_heads_body {
2142 # uses global variable $project
Jakub Narebski120ddde2006-09-19 14:33:22 +02002143 my ($headlist, $head, $from, $to, $extra) = @_;
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002144 $from = 0 unless defined $from;
Jakub Narebski120ddde2006-09-19 14:33:22 +02002145 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002146
2147 print "<table class=\"heads\" cellspacing=\"0\">\n";
2148 my $alternate = 0;
2149 for (my $i = $from; $i <= $to; $i++) {
Jakub Narebski120ddde2006-09-19 14:33:22 +02002150 my $entry = $headlist->[$i];
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002151 my %tag = %$entry;
2152 my $curr = $tag{'id'} eq $head;
2153 if ($alternate) {
2154 print "<tr class=\"dark\">\n";
2155 } else {
2156 print "<tr class=\"light\">\n";
2157 }
2158 $alternate ^= 1;
2159 print "<td><i>$tag{'age'}</i></td>\n" .
2160 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002161 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'}),
Jakub Narebski63e42202006-08-22 12:38:59 +02002162 -class => "list name"},esc_html($tag{'name'})) .
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002163 "</td>\n" .
2164 "<td class=\"link\">" .
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002165 $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " .
2166 $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") .
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002167 "</td>\n" .
2168 "</tr>";
2169 }
2170 if (defined $extra) {
2171 print "<tr>\n" .
2172 "<td colspan=\"3\">$extra</td>\n" .
2173 "</tr>\n";
2174 }
2175 print "</table>\n";
2176}
2177
Jakub Narebski717b8312006-07-31 21:22:15 +02002178## ======================================================================
2179## ======================================================================
2180## actions
2181
Jakub Narebski717b8312006-07-31 21:22:15 +02002182sub git_project_list {
Jakub Narebski6326b602006-08-01 02:59:12 +02002183 my $order = $cgi->param('o');
2184 if (defined $order && $order !~ m/project|descr|owner|age/) {
Jakub Narebskie2860ea2006-08-05 13:15:24 +02002185 die_error(undef, "Unknown order parameter");
Jakub Narebski6326b602006-08-01 02:59:12 +02002186 }
2187
Jakub Narebski847e01f2006-08-14 02:05:47 +02002188 my @list = git_get_projects_list();
Jakub Narebski717b8312006-07-31 21:22:15 +02002189 my @projects;
2190 if (!@list) {
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002191 die_error(undef, "No projects found");
Jakub Narebski717b8312006-07-31 21:22:15 +02002192 }
2193 foreach my $pr (@list) {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002194 my $head = git_get_head_hash($pr->{'path'});
Jakub Narebski717b8312006-07-31 21:22:15 +02002195 if (!defined $head) {
2196 next;
2197 }
Dennis Stosberg25691fb2006-08-28 17:49:58 +02002198 $git_dir = "$projectroot/$pr->{'path'}";
Jakub Narebski847e01f2006-08-14 02:05:47 +02002199 my %co = parse_commit($head);
Jakub Narebski717b8312006-07-31 21:22:15 +02002200 if (!%co) {
2201 next;
2202 }
2203 $pr->{'commit'} = \%co;
2204 if (!defined $pr->{'descr'}) {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002205 my $descr = git_get_project_description($pr->{'path'}) || "";
Jakub Narebski717b8312006-07-31 21:22:15 +02002206 $pr->{'descr'} = chop_str($descr, 25, 5);
2207 }
2208 if (!defined $pr->{'owner'}) {
2209 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
2210 }
2211 push @projects, $pr;
2212 }
Jakub Narebski6326b602006-08-01 02:59:12 +02002213
Jakub Narebski717b8312006-07-31 21:22:15 +02002214 git_header_html();
2215 if (-f $home_text) {
2216 print "<div class=\"index_include\">\n";
2217 open (my $fd, $home_text);
2218 print <$fd>;
2219 close $fd;
2220 print "</div>\n";
2221 }
2222 print "<table class=\"project_list\">\n" .
2223 "<tr>\n";
Jakub Narebski6326b602006-08-01 02:59:12 +02002224 $order ||= "project";
2225 if ($order eq "project") {
Jakub Narebski717b8312006-07-31 21:22:15 +02002226 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2227 print "<th>Project</th>\n";
2228 } else {
Jakub Narebski6326b602006-08-01 02:59:12 +02002229 print "<th>" .
Jakub Narebskia1565c42006-09-15 19:30:34 +02002230 $cgi->a({-href => href(project=>undef, order=>'project'),
Jakub Narebski6326b602006-08-01 02:59:12 +02002231 -class => "header"}, "Project") .
2232 "</th>\n";
Jakub Narebski717b8312006-07-31 21:22:15 +02002233 }
Jakub Narebski6326b602006-08-01 02:59:12 +02002234 if ($order eq "descr") {
Jakub Narebski717b8312006-07-31 21:22:15 +02002235 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2236 print "<th>Description</th>\n";
2237 } else {
Jakub Narebski6326b602006-08-01 02:59:12 +02002238 print "<th>" .
Jakub Narebskia1565c42006-09-15 19:30:34 +02002239 $cgi->a({-href => href(project=>undef, order=>'descr'),
Jakub Narebski6326b602006-08-01 02:59:12 +02002240 -class => "header"}, "Description") .
2241 "</th>\n";
Jakub Narebski717b8312006-07-31 21:22:15 +02002242 }
Jakub Narebski6326b602006-08-01 02:59:12 +02002243 if ($order eq "owner") {
Jakub Narebski717b8312006-07-31 21:22:15 +02002244 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2245 print "<th>Owner</th>\n";
2246 } else {
Jakub Narebski6326b602006-08-01 02:59:12 +02002247 print "<th>" .
Jakub Narebskia1565c42006-09-15 19:30:34 +02002248 $cgi->a({-href => href(project=>undef, order=>'owner'),
Jakub Narebski6326b602006-08-01 02:59:12 +02002249 -class => "header"}, "Owner") .
2250 "</th>\n";
Jakub Narebski717b8312006-07-31 21:22:15 +02002251 }
Jakub Narebski6326b602006-08-01 02:59:12 +02002252 if ($order eq "age") {
Jakub Narebski717b8312006-07-31 21:22:15 +02002253 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2254 print "<th>Last Change</th>\n";
2255 } else {
Jakub Narebski6326b602006-08-01 02:59:12 +02002256 print "<th>" .
Jakub Narebskia1565c42006-09-15 19:30:34 +02002257 $cgi->a({-href => href(project=>undef, order=>'age'),
Jakub Narebski6326b602006-08-01 02:59:12 +02002258 -class => "header"}, "Last Change") .
2259 "</th>\n";
Jakub Narebski717b8312006-07-31 21:22:15 +02002260 }
2261 print "<th></th>\n" .
2262 "</tr>\n";
2263 my $alternate = 0;
2264 foreach my $pr (@projects) {
2265 if ($alternate) {
2266 print "<tr class=\"dark\">\n";
2267 } else {
2268 print "<tr class=\"light\">\n";
2269 }
2270 $alternate ^= 1;
Martin Waitz756d2f02006-08-17 00:28:36 +02002271 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
Jakub Narebski6326b602006-08-01 02:59:12 +02002272 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
Jakub Narebski717b8312006-07-31 21:22:15 +02002273 "<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
2274 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
Jakub Narebski6326b602006-08-01 02:59:12 +02002275 print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
2276 $pr->{'commit'}{'age_string'} . "</td>\n" .
Jakub Narebski717b8312006-07-31 21:22:15 +02002277 "<td class=\"link\">" .
Martin Waitz756d2f02006-08-17 00:28:36 +02002278 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
2279 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
Petr Baudis609ff262006-09-22 01:58:40 +02002280 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " .
2281 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") .
Jakub Narebski717b8312006-07-31 21:22:15 +02002282 "</td>\n" .
2283 "</tr>\n";
2284 }
2285 print "</table>\n";
2286 git_footer_html();
2287}
2288
Jakub Narebskifc2b2be2006-09-15 04:56:03 +02002289sub git_project_index {
2290 my @projects = git_get_projects_list();
2291
2292 print $cgi->header(
2293 -type => 'text/plain',
2294 -charset => 'utf-8',
2295 -content_disposition => qq(inline; filename="index.aux"));
2296
2297 foreach my $pr (@projects) {
2298 if (!exists $pr->{'owner'}) {
2299 $pr->{'owner'} = get_file_owner("$projectroot/$project");
2300 }
2301
2302 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2303 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2304 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
2305 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
2306 $path =~ s/ /\+/g;
2307 $owner =~ s/ /\+/g;
2308
2309 print "$path $owner\n";
2310 }
2311}
2312
Kay Sieversede5e102005-08-07 20:23:12 +02002313sub git_summary {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002314 my $descr = git_get_project_description($project) || "none";
2315 my $head = git_get_head_hash($project);
2316 my %co = parse_commit($head);
2317 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
Kay Sieversede5e102005-08-07 20:23:12 +02002318
Jakub Narebski1e0cf032006-08-14 02:10:06 +02002319 my $owner = git_get_project_owner($project);
Kay Sieversede5e102005-08-07 20:23:12 +02002320
Jakub Narebski120ddde2006-09-19 14:33:22 +02002321 my ($reflist, $refs) = git_get_refs_list();
2322
2323 my @taglist;
2324 my @headlist;
2325 foreach my $ref (@$reflist) {
2326 if ($ref->{'name'} =~ s!^heads/!!) {
2327 push @headlist, $ref;
2328 } else {
2329 $ref->{'name'} =~ s!^tags/!!;
2330 push @taglist, $ref;
2331 }
2332 }
2333
Kay Sieversede5e102005-08-07 20:23:12 +02002334 git_header_html();
Jakub Narebski847e01f2006-08-14 02:05:47 +02002335 git_print_page_nav('summary','', $head);
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002336
Kay Sievers19806692005-08-07 20:26:27 +02002337 print "<div class=\"title\">&nbsp;</div>\n";
Kay Sieversbddec012005-08-07 20:25:42 +02002338 print "<table cellspacing=\"0\">\n" .
Kay Sievers40c13812005-11-19 17:41:29 +01002339 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
Kay Sieversede5e102005-08-07 20:23:12 +02002340 "<tr><td>owner</td><td>$owner</td></tr>\n" .
Jakub Narebski19a87212006-08-15 23:03:17 +02002341 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
Jakub Narebskie79ca7c2006-08-16 14:50:34 +02002342 # use per project git URL list in $projectroot/$project/cloneurl
2343 # or make project git URL from git base URL and project name
Jakub Narebski19a87212006-08-15 23:03:17 +02002344 my $url_tag = "URL";
Jakub Narebskie79ca7c2006-08-16 14:50:34 +02002345 my @url_list = git_get_project_url_list($project);
2346 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2347 foreach my $git_url (@url_list) {
2348 next unless $git_url;
2349 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
Jakub Narebski19a87212006-08-15 23:03:17 +02002350 $url_tag = "";
2351 }
2352 print "</table>\n";
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002353
Dennis Stosberg25691fb2006-08-28 17:49:58 +02002354 open my $fd, "-|", git_cmd(), "rev-list", "--max-count=17",
2355 git_get_head_hash($project)
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002356 or die_error(undef, "Open git-rev-list failed");
Jakub Narebski0881d2d2006-07-30 14:58:11 +02002357 my @revlist = map { chomp; $_ } <$fd>;
Kay Sieversede5e102005-08-07 20:23:12 +02002358 close $fd;
Jakub Narebski847e01f2006-08-14 02:05:47 +02002359 git_print_header_div('shortlog');
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002360 git_shortlog_body(\@revlist, 0, 15, $refs,
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002361 $cgi->a({-href => href(action=>"shortlog")}, "..."));
Kay Sieversede5e102005-08-07 20:23:12 +02002362
Jakub Narebski120ddde2006-09-19 14:33:22 +02002363 if (@taglist) {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002364 git_print_header_div('tags');
Jakub Narebski120ddde2006-09-19 14:33:22 +02002365 git_tags_body(\@taglist, 0, 15,
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002366 $cgi->a({-href => href(action=>"tags")}, "..."));
Kay Sieversede5e102005-08-07 20:23:12 +02002367 }
Kay Sievers0db37972005-08-07 20:24:35 +02002368
Jakub Narebski120ddde2006-09-19 14:33:22 +02002369 if (@headlist) {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002370 git_print_header_div('heads');
Jakub Narebski120ddde2006-09-19 14:33:22 +02002371 git_heads_body(\@headlist, $head, 0, 15,
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002372 $cgi->a({-href => href(action=>"heads")}, "..."));
Kay Sievers0db37972005-08-07 20:24:35 +02002373 }
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002374
Kay Sieversede5e102005-08-07 20:23:12 +02002375 git_footer_html();
2376}
2377
Kay Sieversd8a20ba2005-08-07 20:28:53 +02002378sub git_tag {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002379 my $head = git_get_head_hash($project);
Kay Sieversd8a20ba2005-08-07 20:28:53 +02002380 git_header_html();
Jakub Narebski847e01f2006-08-14 02:05:47 +02002381 git_print_page_nav('','', $head,undef,$head);
2382 my %tag = parse_tag($hash);
2383 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
Kay Sieversd8a20ba2005-08-07 20:28:53 +02002384 print "<div class=\"title_text\">\n" .
2385 "<table cellspacing=\"0\">\n" .
Kay Sieverse4669df2005-08-08 00:02:39 +02002386 "<tr>\n" .
2387 "<td>object</td>\n" .
Jakub Narebski952c65f2006-08-22 16:52:50 +02002388 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2389 $tag{'object'}) . "</td>\n" .
2390 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
2391 $tag{'type'}) . "</td>\n" .
Kay Sieverse4669df2005-08-08 00:02:39 +02002392 "</tr>\n";
Kay Sieversd8a20ba2005-08-07 20:28:53 +02002393 if (defined($tag{'author'})) {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002394 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
Kay Sievers40c13812005-11-19 17:41:29 +01002395 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
Jakub Narebski952c65f2006-08-22 16:52:50 +02002396 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2397 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2398 "</td></tr>\n";
Kay Sieversd8a20ba2005-08-07 20:28:53 +02002399 }
2400 print "</table>\n\n" .
2401 "</div>\n";
2402 print "<div class=\"page_body\">";
2403 my $comment = $tag{'comment'};
2404 foreach my $line (@$comment) {
Kay Sievers40c13812005-11-19 17:41:29 +01002405 print esc_html($line) . "<br/>\n";
Kay Sieversd8a20ba2005-08-07 20:28:53 +02002406 }
2407 print "</div>\n";
2408 git_footer_html();
2409}
2410
Luben Tuikov1f2857e2006-07-23 13:34:55 -07002411sub git_blame2 {
2412 my $fd;
2413 my $ftype;
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +05302414
Aneesh Kumar K.V1d3fc682006-09-01 09:13:32 +05302415 my ($have_blame) = gitweb_check_feature('blame');
2416 if (!$have_blame) {
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +05302417 die_error('403 Permission denied', "Permission denied");
2418 }
Luben Tuikov1f2857e2006-07-23 13:34:55 -07002419 die_error('404 Not Found', "File name not defined") if (!$file_name);
Jakub Narebski847e01f2006-08-14 02:05:47 +02002420 $hash_base ||= git_get_head_hash($project);
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002421 die_error(undef, "Couldn't find base commit") unless ($hash_base);
Jakub Narebski847e01f2006-08-14 02:05:47 +02002422 my %co = parse_commit($hash_base)
Luben Tuikov1f2857e2006-07-23 13:34:55 -07002423 or die_error(undef, "Reading commit failed");
2424 if (!defined $hash) {
2425 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
2426 or die_error(undef, "Error looking up file");
2427 }
2428 $ftype = git_get_type($hash);
2429 if ($ftype !~ "blob") {
Jakub Narebskie484a2d2006-08-05 13:12:51 +02002430 die_error("400 Bad Request", "Object is not a blob");
Luben Tuikov1f2857e2006-07-23 13:34:55 -07002431 }
Dennis Stosberg25691fb2006-08-28 17:49:58 +02002432 open ($fd, "-|", git_cmd(), "blame", '-l', $file_name, $hash_base)
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002433 or die_error(undef, "Open git-blame failed");
Luben Tuikov1f2857e2006-07-23 13:34:55 -07002434 git_header_html();
Jakub Narebski0d83ddc2006-07-30 15:01:07 +02002435 my $formats_nav =
Jakub Narebski952c65f2006-08-22 16:52:50 +02002436 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2437 "blob") .
2438 " | " .
Petr Baudiscae18622006-09-22 03:19:41 +02002439 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2440 "history") .
2441 " | " .
Jakub Narebski952c65f2006-08-22 16:52:50 +02002442 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2443 "head");
Jakub Narebski847e01f2006-08-14 02:05:47 +02002444 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2445 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
Luben Tuikov59fb1c92006-08-17 10:39:29 -07002446 git_print_page_path($file_name, $ftype, $hash_base);
Luben Tuikov82f930d2006-08-04 15:09:59 -07002447 my @rev_color = (qw(light2 dark2));
Luben Tuikovcc1bf972006-07-23 13:37:53 -07002448 my $num_colors = scalar(@rev_color);
2449 my $current_color = 0;
2450 my $last_rev;
Jakub Narebski59b9f612006-08-22 23:42:53 +02002451 print <<HTML;
2452<div class="page_body">
2453<table class="blame">
2454<tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2455HTML
Luben Tuikovacb0f6f2006-07-23 14:17:48 -07002456 while (<$fd>) {
2457 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2458 my $full_rev = $1;
Luben Tuikov1f2857e2006-07-23 13:34:55 -07002459 my $rev = substr($full_rev, 0, 8);
Luben Tuikovacb0f6f2006-07-23 14:17:48 -07002460 my $lineno = $2;
2461 my $data = $3;
Luben Tuikov1f2857e2006-07-23 13:34:55 -07002462
Luben Tuikovcc1bf972006-07-23 13:37:53 -07002463 if (!defined $last_rev) {
2464 $last_rev = $full_rev;
2465 } elsif ($last_rev ne $full_rev) {
2466 $last_rev = $full_rev;
2467 $current_color = ++$current_color % $num_colors;
2468 }
2469 print "<tr class=\"$rev_color[$current_color]\">\n";
Luben Tuikov1f2857e2006-07-23 13:34:55 -07002470 print "<td class=\"sha1\">" .
Jakub Narebski952c65f2006-08-22 16:52:50 +02002471 $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
2472 esc_html($rev)) . "</td>\n";
2473 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2474 esc_html($lineno) . "</a></td>\n";
Luben Tuikov1f2857e2006-07-23 13:34:55 -07002475 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
2476 print "</tr>\n";
2477 }
2478 print "</table>\n";
2479 print "</div>";
Jakub Narebski952c65f2006-08-22 16:52:50 +02002480 close $fd
2481 or print "Reading blob failed\n";
Luben Tuikov1f2857e2006-07-23 13:34:55 -07002482 git_footer_html();
2483}
2484
Florian Forstere34ef622006-06-11 17:45:19 +02002485sub git_blame {
2486 my $fd;
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +05302487
Aneesh Kumar K.V1d3fc682006-09-01 09:13:32 +05302488 my ($have_blame) = gitweb_check_feature('blame');
2489 if (!$have_blame) {
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +05302490 die_error('403 Permission denied', "Permission denied");
2491 }
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002492 die_error('404 Not Found', "File name not defined") if (!$file_name);
Jakub Narebski847e01f2006-08-14 02:05:47 +02002493 $hash_base ||= git_get_head_hash($project);
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002494 die_error(undef, "Couldn't find base commit") unless ($hash_base);
Jakub Narebski847e01f2006-08-14 02:05:47 +02002495 my %co = parse_commit($hash_base)
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002496 or die_error(undef, "Reading commit failed");
Florian Forstere34ef622006-06-11 17:45:19 +02002497 if (!defined $hash) {
2498 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002499 or die_error(undef, "Error lookup file");
Florian Forstere34ef622006-06-11 17:45:19 +02002500 }
Dennis Stosberg25691fb2006-08-28 17:49:58 +02002501 open ($fd, "-|", git_cmd(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002502 or die_error(undef, "Open git-annotate failed");
Florian Forstere34ef622006-06-11 17:45:19 +02002503 git_header_html();
Jakub Narebski0d83ddc2006-07-30 15:01:07 +02002504 my $formats_nav =
Jakub Narebski952c65f2006-08-22 16:52:50 +02002505 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2506 "blob") .
2507 " | " .
Petr Baudiscae18622006-09-22 03:19:41 +02002508 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
2509 "history") .
2510 " | " .
Jakub Narebski952c65f2006-08-22 16:52:50 +02002511 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
2512 "head");
Jakub Narebski847e01f2006-08-14 02:05:47 +02002513 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2514 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
Luben Tuikov59fb1c92006-08-17 10:39:29 -07002515 git_print_page_path($file_name, 'blob', $hash_base);
Florian Forstere34ef622006-06-11 17:45:19 +02002516 print "<div class=\"page_body\">\n";
2517 print <<HTML;
Jakub Narebski1f1ab5f2006-06-20 14:58:12 +00002518<table class="blame">
Florian Forstere34ef622006-06-11 17:45:19 +02002519 <tr>
2520 <th>Commit</th>
2521 <th>Age</th>
2522 <th>Author</th>
2523 <th>Line</th>
2524 <th>Data</th>
2525 </tr>
2526HTML
2527 my @line_class = (qw(light dark));
2528 my $line_class_len = scalar (@line_class);
2529 my $line_class_num = $#line_class;
2530 while (my $line = <$fd>) {
2531 my $long_rev;
2532 my $short_rev;
2533 my $author;
2534 my $time;
2535 my $lineno;
2536 my $data;
2537 my $age;
2538 my $age_str;
Jakub Narebski1f1ab5f2006-06-20 14:58:12 +00002539 my $age_class;
Florian Forstere34ef622006-06-11 17:45:19 +02002540
2541 chomp $line;
2542 $line_class_num = ($line_class_num + 1) % $line_class_len;
2543
Jakub Narebski030b5202006-08-26 02:13:05 +02002544 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
Florian Forstere34ef622006-06-11 17:45:19 +02002545 $long_rev = $1;
2546 $author = $2;
2547 $time = $3;
2548 $lineno = $4;
2549 $data = $5;
2550 } else {
Jakub Narebski1f1ab5f2006-06-20 14:58:12 +00002551 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
Florian Forstere34ef622006-06-11 17:45:19 +02002552 next;
2553 }
2554 $short_rev = substr ($long_rev, 0, 8);
2555 $age = time () - $time;
2556 $age_str = age_string ($age);
2557 $age_str =~ s/ /&nbsp;/g;
Jakub Narebski1f1ab5f2006-06-20 14:58:12 +00002558 $age_class = age_class($age);
Florian Forstere34ef622006-06-11 17:45:19 +02002559 $author = esc_html ($author);
2560 $author =~ s/ /&nbsp;/g;
Jakub Narebskif16db172006-08-06 02:08:31 +02002561
2562 $data = untabify($data);
Florian Forstere34ef622006-06-11 17:45:19 +02002563 $data = esc_html ($data);
Florian Forstere34ef622006-06-11 17:45:19 +02002564
2565 print <<HTML;
2566 <tr class="$line_class[$line_class_num]">
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002567 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
Jakub Narebski1f1ab5f2006-06-20 14:58:12 +00002568 <td class="$age_class">$age_str</td>
Florian Forstere34ef622006-06-11 17:45:19 +02002569 <td>$author</td>
Jakub Narebski1f1ab5f2006-06-20 14:58:12 +00002570 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2571 <td class="pre">$data</td>
Florian Forstere34ef622006-06-11 17:45:19 +02002572 </tr>
2573HTML
2574 } # while (my $line = <$fd>)
2575 print "</table>\n\n";
Jakub Narebski952c65f2006-08-22 16:52:50 +02002576 close $fd
2577 or print "Reading blob failed.\n";
Florian Forstere34ef622006-06-11 17:45:19 +02002578 print "</div>";
2579 git_footer_html();
2580}
2581
Kay Sieversede5e102005-08-07 20:23:12 +02002582sub git_tags {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002583 my $head = git_get_head_hash($project);
Kay Sieversede5e102005-08-07 20:23:12 +02002584 git_header_html();
Jakub Narebski847e01f2006-08-14 02:05:47 +02002585 git_print_page_nav('','', $head,undef,$head);
2586 git_print_header_div('summary', $project);
Jakub Narebski27fb8c42006-07-30 20:32:01 +02002587
Jakub Narebski120ddde2006-09-19 14:33:22 +02002588 my ($taglist) = git_get_refs_list("tags");
Jakub Narebski62e27f22006-09-19 20:47:27 +02002589 if (@$taglist) {
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02002590 git_tags_body($taglist);
Kay Sieversede5e102005-08-07 20:23:12 +02002591 }
Kay Sieversede5e102005-08-07 20:23:12 +02002592 git_footer_html();
2593}
2594
Kay Sieversd8f1c5c2005-10-04 01:12:47 +02002595sub git_heads {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002596 my $head = git_get_head_hash($project);
Kay Sievers0db37972005-08-07 20:24:35 +02002597 git_header_html();
Jakub Narebski847e01f2006-08-14 02:05:47 +02002598 git_print_page_nav('','', $head,undef,$head);
2599 git_print_header_div('summary', $project);
Jakub Narebski27fb8c42006-07-30 20:32:01 +02002600
Jakub Narebski120ddde2006-09-19 14:33:22 +02002601 my ($headlist) = git_get_refs_list("heads");
Jakub Narebski62e27f22006-09-19 20:47:27 +02002602 if (@$headlist) {
Jakub Narebski120ddde2006-09-19 14:33:22 +02002603 git_heads_body($headlist, $head);
Kay Sievers0db37972005-08-07 20:24:35 +02002604 }
Kay Sievers0db37972005-08-07 20:24:35 +02002605 git_footer_html();
2606}
2607
Luben Tuikov930cf7d2006-07-09 20:18:57 -07002608sub git_blob_plain {
Jakub Narebskif2e73302006-08-26 19:14:25 +02002609 my $expires;
Jakub Narebskif2e73302006-08-26 19:14:25 +02002610
Luben Tuikovcff07712006-07-23 13:28:55 -07002611 if (!defined $hash) {
Jakub Narebski5be01bc2006-07-29 22:43:40 +02002612 if (defined $file_name) {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002613 my $base = $hash_base || git_get_head_hash($project);
Jakub Narebski5be01bc2006-07-29 22:43:40 +02002614 $hash = git_get_hash_by_path($base, $file_name, "blob")
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002615 or die_error(undef, "Error lookup file");
Jakub Narebski5be01bc2006-07-29 22:43:40 +02002616 } else {
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002617 die_error(undef, "No file name defined");
Jakub Narebski5be01bc2006-07-29 22:43:40 +02002618 }
Martin Waitz800764c2006-09-16 23:09:02 +02002619 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2620 # blobs defined by non-textual hash id's can be cached
2621 $expires = "+1d";
Jakub Narebski5be01bc2006-07-29 22:43:40 +02002622 }
Martin Waitz800764c2006-09-16 23:09:02 +02002623
Luben Tuikov930cf7d2006-07-09 20:18:57 -07002624 my $type = shift;
Dennis Stosberg25691fb2006-08-28 17:49:58 +02002625 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
Jakub Narebskicfd82662006-08-05 12:56:04 +02002626 or die_error(undef, "Couldn't cat $file_name, $hash");
Luben Tuikov930cf7d2006-07-09 20:18:57 -07002627
Jakub Narebski847e01f2006-08-14 02:05:47 +02002628 $type ||= blob_mimetype($fd, $file_name);
Luben Tuikov930cf7d2006-07-09 20:18:57 -07002629
2630 # save as filename, even when no $file_name is given
2631 my $save_as = "$hash";
2632 if (defined $file_name) {
2633 $save_as = $file_name;
2634 } elsif ($type =~ m/^text\//) {
2635 $save_as .= '.txt';
2636 }
2637
Jakub Narebskif2e73302006-08-26 19:14:25 +02002638 print $cgi->header(
2639 -type => "$type",
2640 -expires=>$expires,
2641 -content_disposition => "inline; filename=\"$save_as\"");
Luben Tuikov930cf7d2006-07-09 20:18:57 -07002642 undef $/;
2643 binmode STDOUT, ':raw';
2644 print <$fd>;
2645 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2646 $/ = "\n";
2647 close $fd;
2648}
2649
Kay Sievers09bd7892005-08-07 20:21:23 +02002650sub git_blob {
Jakub Narebskif2e73302006-08-26 19:14:25 +02002651 my $expires;
Jakub Narebskif2e73302006-08-26 19:14:25 +02002652
Luben Tuikovcff07712006-07-23 13:28:55 -07002653 if (!defined $hash) {
Jakub Narebski5be01bc2006-07-29 22:43:40 +02002654 if (defined $file_name) {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002655 my $base = $hash_base || git_get_head_hash($project);
Jakub Narebski5be01bc2006-07-29 22:43:40 +02002656 $hash = git_get_hash_by_path($base, $file_name, "blob")
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002657 or die_error(undef, "Error lookup file");
Jakub Narebski5be01bc2006-07-29 22:43:40 +02002658 } else {
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002659 die_error(undef, "No file name defined");
Jakub Narebski5be01bc2006-07-29 22:43:40 +02002660 }
Martin Waitz800764c2006-09-16 23:09:02 +02002661 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2662 # blobs defined by non-textual hash id's can be cached
2663 $expires = "+1d";
Jakub Narebski5be01bc2006-07-29 22:43:40 +02002664 }
Martin Waitz800764c2006-09-16 23:09:02 +02002665
Aneesh Kumar K.V1d3fc682006-09-01 09:13:32 +05302666 my ($have_blame) = gitweb_check_feature('blame');
Dennis Stosberg25691fb2006-08-28 17:49:58 +02002667 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002668 or die_error(undef, "Couldn't cat $file_name, $hash");
Jakub Narebski847e01f2006-08-14 02:05:47 +02002669 my $mimetype = blob_mimetype($fd, $file_name);
Luben Tuikov930cf7d2006-07-09 20:18:57 -07002670 if ($mimetype !~ m/^text\//) {
2671 close $fd;
2672 return git_blob_plain($mimetype);
2673 }
Jakub Narebskif2e73302006-08-26 19:14:25 +02002674 git_header_html(undef, $expires);
Jakub Narebski0d83ddc2006-07-30 15:01:07 +02002675 my $formats_nav = '';
Jakub Narebski847e01f2006-08-14 02:05:47 +02002676 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
Kay Sievers93129442005-10-17 03:27:54 +02002677 if (defined $file_name) {
Florian Forster5996ca02006-06-12 10:31:57 +02002678 if ($have_blame) {
Jakub Narebski952c65f2006-08-22 16:52:50 +02002679 $formats_nav .=
2680 $cgi->a({-href => href(action=>"blame", hash_base=>$hash_base,
2681 hash=>$hash, file_name=>$file_name)},
2682 "blame") .
2683 " | ";
Florian Forster5996ca02006-06-12 10:31:57 +02002684 }
Jakub Narebski0d83ddc2006-07-30 15:01:07 +02002685 $formats_nav .=
Petr Baudiscae18622006-09-22 03:19:41 +02002686 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2687 hash=>$hash, file_name=>$file_name)},
2688 "history") .
2689 " | " .
Jakub Narebski952c65f2006-08-22 16:52:50 +02002690 $cgi->a({-href => href(action=>"blob_plain",
2691 hash=>$hash, file_name=>$file_name)},
2692 "plain") .
2693 " | " .
2694 $cgi->a({-href => href(action=>"blob",
2695 hash_base=>"HEAD", file_name=>$file_name)},
2696 "head");
Kay Sievers93129442005-10-17 03:27:54 +02002697 } else {
Jakub Narebski952c65f2006-08-22 16:52:50 +02002698 $formats_nav .=
2699 $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "plain");
Kay Sievers93129442005-10-17 03:27:54 +02002700 }
Jakub Narebski847e01f2006-08-14 02:05:47 +02002701 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2702 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
Kay Sievers09bd7892005-08-07 20:21:23 +02002703 } else {
2704 print "<div class=\"page_nav\">\n" .
2705 "<br/><br/></div>\n" .
2706 "<div class=\"title\">$hash</div>\n";
2707 }
Luben Tuikov59fb1c92006-08-17 10:39:29 -07002708 git_print_page_path($file_name, "blob", $hash_base);
Kay Sieversc07ad4b2005-08-07 20:22:44 +02002709 print "<div class=\"page_body\">\n";
Kay Sievers161332a2005-08-07 19:49:46 +02002710 my $nr;
2711 while (my $line = <$fd>) {
Kay Sieversc07ad4b2005-08-07 20:22:44 +02002712 chomp $line;
Kay Sievers161332a2005-08-07 19:49:46 +02002713 $nr++;
Jakub Narebskif16db172006-08-06 02:08:31 +02002714 $line = untabify($line);
Jakub Narebski952c65f2006-08-22 16:52:50 +02002715 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2716 $nr, $nr, $nr, esc_html($line);
Kay Sievers161332a2005-08-07 19:49:46 +02002717 }
Jakub Narebski952c65f2006-08-22 16:52:50 +02002718 close $fd
2719 or print "Reading blob failed.\n";
Kay Sieversfbb592a2005-08-07 20:12:11 +02002720 print "</div>";
Kay Sievers12a88f22005-08-07 20:02:47 +02002721 git_footer_html();
Kay Sievers09bd7892005-08-07 20:21:23 +02002722}
2723
2724sub git_tree {
Petr Baudiscae18622006-09-22 03:19:41 +02002725 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2726 my $have_snapshot = (defined $ctype && defined $suffix);
2727
Kay Sieversb87d78d2005-08-07 20:21:04 +02002728 if (!defined $hash) {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002729 $hash = git_get_head_hash($project);
Kay Sievers09bd7892005-08-07 20:21:23 +02002730 if (defined $file_name) {
Junio C Hamanodf2c37a2006-01-09 13:13:39 +01002731 my $base = $hash_base || $hash;
Kay Sievers09bd7892005-08-07 20:21:23 +02002732 $hash = git_get_hash_by_path($base, $file_name, "tree");
2733 }
Kay Sievers10dba282005-08-07 20:25:27 +02002734 if (!defined $hash_base) {
Junio C Hamanodf2c37a2006-01-09 13:13:39 +01002735 $hash_base = $hash;
Kay Sievers10dba282005-08-07 20:25:27 +02002736 }
Kay Sieverse925f382005-08-07 20:23:35 +02002737 }
Kay Sievers232ff552005-11-24 16:56:55 +01002738 $/ = "\0";
Dennis Stosberg25691fb2006-08-28 17:49:58 +02002739 open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002740 or die_error(undef, "Open git-ls-tree failed");
Jakub Narebski0881d2d2006-07-30 14:58:11 +02002741 my @entries = map { chomp; $_ } <$fd>;
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002742 close $fd or die_error(undef, "Reading tree failed");
Kay Sievers232ff552005-11-24 16:56:55 +01002743 $/ = "\n";
Kay Sieversd63577d2005-08-07 20:18:13 +02002744
Jakub Narebski847e01f2006-08-14 02:05:47 +02002745 my $refs = git_get_references();
2746 my $ref = format_ref_marker($refs, $hash_base);
Kay Sievers12a88f22005-08-07 20:02:47 +02002747 git_header_html();
Kay Sievers09bd7892005-08-07 20:21:23 +02002748 my $base = "";
Aneesh Kumar K.V1d3fc682006-09-01 09:13:32 +05302749 my ($have_blame) = gitweb_check_feature('blame');
Jakub Narebski847e01f2006-08-14 02:05:47 +02002750 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
Petr Baudiscae18622006-09-22 03:19:41 +02002751 my @views_nav = ();
2752 if (defined $file_name) {
2753 push @views_nav,
2754 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2755 hash=>$hash, file_name=>$file_name)},
2756 "history"),
2757 $cgi->a({-href => href(action=>"tree",
2758 hash_base=>"HEAD", file_name=>$file_name)},
2759 "head");
2760 }
2761 if ($have_snapshot) {
2762 # FIXME: Should be available when we have no hash base as well.
2763 push @views_nav,
2764 $cgi->a({-href => href(action=>"snapshot")},
2765 "snapshot");
2766 }
2767 git_print_page_nav('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
Jakub Narebski847e01f2006-08-14 02:05:47 +02002768 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
Kay Sieversd63577d2005-08-07 20:18:13 +02002769 } else {
Jakub Narebskifa702002006-08-31 00:35:07 +02002770 undef $hash_base;
Kay Sieversd63577d2005-08-07 20:18:13 +02002771 print "<div class=\"page_nav\">\n";
2772 print "<br/><br/></div>\n";
2773 print "<div class=\"title\">$hash</div>\n";
2774 }
Kay Sievers09bd7892005-08-07 20:21:23 +02002775 if (defined $file_name) {
Kay Sievers232ff552005-11-24 16:56:55 +01002776 $base = esc_html("$file_name/");
Kay Sievers09bd7892005-08-07 20:21:23 +02002777 }
Luben Tuikov59fb1c92006-08-17 10:39:29 -07002778 git_print_page_path($file_name, 'tree', $hash_base);
Kay Sieversfbb592a2005-08-07 20:12:11 +02002779 print "<div class=\"page_body\">\n";
Kay Sievers42f7eb92005-08-07 20:21:46 +02002780 print "<table cellspacing=\"0\">\n";
Kay Sieversbddec012005-08-07 20:25:42 +02002781 my $alternate = 0;
Kay Sievers161332a2005-08-07 19:49:46 +02002782 foreach my $line (@entries) {
Jakub Narebskicb849b42006-08-31 00:32:15 +02002783 my %t = parse_ls_tree_line($line, -z => 1);
2784
Kay Sieversbddec012005-08-07 20:25:42 +02002785 if ($alternate) {
Kay Sieversc994d622005-08-07 20:27:18 +02002786 print "<tr class=\"dark\">\n";
Kay Sieversbddec012005-08-07 20:25:42 +02002787 } else {
Kay Sieversc994d622005-08-07 20:27:18 +02002788 print "<tr class=\"light\">\n";
Kay Sieversbddec012005-08-07 20:25:42 +02002789 }
2790 $alternate ^= 1;
Jakub Narebskicb849b42006-08-31 00:32:15 +02002791
Jakub Narebskifa702002006-08-31 00:35:07 +02002792 git_print_tree_entry(\%t, $base, $hash_base, $have_blame);
2793
Kay Sievers42f7eb92005-08-07 20:21:46 +02002794 print "</tr>\n";
Kay Sievers161332a2005-08-07 19:49:46 +02002795 }
Kay Sievers42f7eb92005-08-07 20:21:46 +02002796 print "</table>\n" .
2797 "</div>";
Kay Sievers12a88f22005-08-07 20:02:47 +02002798 git_footer_html();
Kay Sievers09bd7892005-08-07 20:21:23 +02002799}
2800
Aneesh Kumar K.Vcb9c6e52006-08-17 20:59:46 +05302801sub git_snapshot {
2802
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +05302803 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2804 my $have_snapshot = (defined $ctype && defined $suffix);
2805 if (!$have_snapshot) {
2806 die_error('403 Permission denied', "Permission denied");
2807 }
2808
Aneesh Kumar K.Vcb9c6e52006-08-17 20:59:46 +05302809 if (!defined $hash) {
2810 $hash = git_get_head_hash($project);
2811 }
2812
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +05302813 my $filename = basename($project) . "-$hash.tar.$suffix";
Aneesh Kumar K.Vcb9c6e52006-08-17 20:59:46 +05302814
2815 print $cgi->header(-type => 'application/x-tar',
Jakub Narebski134a69412006-08-22 16:55:34 +02002816 -content_encoding => $ctype,
2817 -content_disposition => "inline; filename=\"$filename\"",
Jakub Narebski952c65f2006-08-22 16:52:50 +02002818 -status => '200 OK');
Aneesh Kumar K.Vcb9c6e52006-08-17 20:59:46 +05302819
Dennis Stosberg25691fb2006-08-28 17:49:58 +02002820 my $git_command = git_cmd_str();
2821 open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +05302822 die_error(undef, "Execute git-tar-tree failed.");
Aneesh Kumar K.Vcb9c6e52006-08-17 20:59:46 +05302823 binmode STDOUT, ':raw';
2824 print <$fd>;
2825 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2826 close $fd;
2827
Aneesh Kumar K.Vcb9c6e52006-08-17 20:59:46 +05302828}
2829
Kay Sievers09bd7892005-08-07 20:21:23 +02002830sub git_log {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002831 my $head = git_get_head_hash($project);
Kay Sievers0db37972005-08-07 20:24:35 +02002832 if (!defined $hash) {
Kay Sievers19806692005-08-07 20:26:27 +02002833 $hash = $head;
Kay Sievers0db37972005-08-07 20:24:35 +02002834 }
Kay Sieversea4a6df2005-08-07 20:26:49 +02002835 if (!defined $page) {
2836 $page = 0;
Kay Sieversb87d78d2005-08-07 20:21:04 +02002837 }
Jakub Narebski847e01f2006-08-14 02:05:47 +02002838 my $refs = git_get_references();
Kay Sieversea4a6df2005-08-07 20:26:49 +02002839
2840 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
Dennis Stosberg25691fb2006-08-28 17:49:58 +02002841 open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002842 or die_error(undef, "Open git-rev-list failed");
Jakub Narebski0881d2d2006-07-30 14:58:11 +02002843 my @revlist = map { chomp; $_ } <$fd>;
Kay Sieversea4a6df2005-08-07 20:26:49 +02002844 close $fd;
2845
Jakub Narebski847e01f2006-08-14 02:05:47 +02002846 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist);
Jakub Narebski0d83ddc2006-07-30 15:01:07 +02002847
2848 git_header_html();
Jakub Narebski847e01f2006-08-14 02:05:47 +02002849 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
Jakub Narebski0d83ddc2006-07-30 15:01:07 +02002850
Kay Sieversb87d78d2005-08-07 20:21:04 +02002851 if (!@revlist) {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002852 my %co = parse_commit($hash);
Jakub Narebski27fb8c42006-07-30 20:32:01 +02002853
Jakub Narebski847e01f2006-08-14 02:05:47 +02002854 git_print_header_div('summary', $project);
Kay Sieverse925f382005-08-07 20:23:35 +02002855 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
Kay Sievers034df392005-08-07 20:20:07 +02002856 }
Kay Sieversc994d622005-08-07 20:27:18 +02002857 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2858 my $commit = $revlist[$i];
Jakub Narebski847e01f2006-08-14 02:05:47 +02002859 my $ref = format_ref_marker($refs, $commit);
2860 my %co = parse_commit($commit);
Kay Sieversb87d78d2005-08-07 20:21:04 +02002861 next if !%co;
Jakub Narebski847e01f2006-08-14 02:05:47 +02002862 my %ad = parse_date($co{'author_epoch'});
2863 git_print_header_div('commit',
Jakub Narebski26298b52006-08-10 12:38:47 +02002864 "<span class=\"age\">$co{'age_string'}</span>" .
2865 esc_html($co{'title'}) . $ref,
2866 $commit);
Kay Sievers034df392005-08-07 20:20:07 +02002867 print "<div class=\"title_text\">\n" .
2868 "<div class=\"log_link\">\n" .
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002869 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
Jakub Narebski952c65f2006-08-22 16:52:50 +02002870 " | " .
2871 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
Kay Sieverseb282402005-08-07 20:21:34 +02002872 "<br/>\n" .
Kay Sievers034df392005-08-07 20:20:07 +02002873 "</div>\n" .
Kay Sievers40c13812005-11-19 17:41:29 +01002874 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
Jakub Narebskid16d0932006-08-17 11:21:23 +02002875 "</div>\n";
2876
2877 print "<div class=\"log_body\">\n";
2878 git_print_simplified_log($co{'comment'});
Kay Sievers09bd7892005-08-07 20:21:23 +02002879 print "</div>\n";
Kay Sievers034df392005-08-07 20:20:07 +02002880 }
2881 git_footer_html();
Kay Sievers09bd7892005-08-07 20:21:23 +02002882}
2883
2884sub git_commit {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002885 my %co = parse_commit($hash);
Kay Sievers034df392005-08-07 20:20:07 +02002886 if (!%co) {
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002887 die_error(undef, "Unknown commit object");
Kay Sieversd63577d2005-08-07 20:18:13 +02002888 }
Jakub Narebski847e01f2006-08-14 02:05:47 +02002889 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
2890 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
Kay Sievers161332a2005-08-07 19:49:46 +02002891
Kay Sieversd8a20ba2005-08-07 20:28:53 +02002892 my $parent = $co{'parent'};
2893 if (!defined $parent) {
Jakub Narebskib9182982006-07-30 18:28:34 -07002894 $parent = "--root";
Kay Sievers6191f8e2005-08-07 20:19:56 +02002895 }
Dennis Stosberg25691fb2006-08-28 17:49:58 +02002896 open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $parent, $hash
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002897 or die_error(undef, "Open git-diff-tree failed");
Jakub Narebski0881d2d2006-07-30 14:58:11 +02002898 my @difftree = map { chomp; $_ } <$fd>;
Jakub Narebskicac4bd92006-08-05 13:13:53 +02002899 close $fd or die_error(undef, "Reading git-diff-tree failed");
Kay Sievers11044292005-10-19 03:18:45 +02002900
2901 # non-textual hash id's can be cached
2902 my $expires;
2903 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2904 $expires = "+1d";
2905 }
Jakub Narebski847e01f2006-08-14 02:05:47 +02002906 my $refs = git_get_references();
2907 my $ref = format_ref_marker($refs, $co{'id'});
Aneesh Kumar K.Vddb8d902006-08-20 11:53:04 +05302908
2909 my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
2910 my $have_snapshot = (defined $ctype && defined $suffix);
2911
Petr Baudiscae18622006-09-22 03:19:41 +02002912 my @views_nav = ();
Luben Tuikov4f7b34c2006-07-23 13:36:32 -07002913 if (defined $file_name && defined $co{'parent'}) {
2914 my $parent = $co{'parent'};
Petr Baudiscae18622006-09-22 03:19:41 +02002915 push @views_nav,
Jakub Narebski952c65f2006-08-22 16:52:50 +02002916 $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)},
2917 "blame");
Luben Tuikov4f7b34c2006-07-23 13:36:32 -07002918 }
Petr Baudiscae18622006-09-22 03:19:41 +02002919 if (defined $co{'parent'}) {
2920 push @views_nav,
2921 $cgi->a({-href => href(action=>"shortlog", hash=>$hash)}, "shortlog"),
2922 $cgi->a({-href => href(action=>"log", hash=>$hash)}, "log");
2923 }
Jakub Narebski594e2122006-07-31 02:21:52 +02002924 git_header_html(undef, $expires);
Jakub Narebski847e01f2006-08-14 02:05:47 +02002925 git_print_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
Jakub Narebski952c65f2006-08-22 16:52:50 +02002926 $hash, $co{'tree'}, $hash,
Petr Baudiscae18622006-09-22 03:19:41 +02002927 join (' | ', @views_nav));
Luben Tuikov4f7b34c2006-07-23 13:36:32 -07002928
Kay Sieversb87d78d2005-08-07 20:21:04 +02002929 if (defined $co{'parent'}) {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002930 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
Kay Sieversb87d78d2005-08-07 20:21:04 +02002931 } else {
Jakub Narebski847e01f2006-08-14 02:05:47 +02002932 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
Kay Sieversb87d78d2005-08-07 20:21:04 +02002933 }
Kay Sievers6191f8e2005-08-07 20:19:56 +02002934 print "<div class=\"title_text\">\n" .
Kay Sieversb87d78d2005-08-07 20:21:04 +02002935 "<table cellspacing=\"0\">\n";
Kay Sievers40c13812005-11-19 17:41:29 +01002936 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
Kay Sieversbddec012005-08-07 20:25:42 +02002937 "<tr>" .
2938 "<td></td><td> $ad{'rfc2822'}";
Kay Sievers927dcec2005-08-07 20:18:44 +02002939 if ($ad{'hour_local'} < 6) {
Jakub Narebski952c65f2006-08-22 16:52:50 +02002940 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2941 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
Kay Sieversb87d78d2005-08-07 20:21:04 +02002942 } else {
Jakub Narebski952c65f2006-08-22 16:52:50 +02002943 printf(" (%02d:%02d %s)",
2944 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
Kay Sievers927dcec2005-08-07 20:18:44 +02002945 }
Kay Sieversbddec012005-08-07 20:25:42 +02002946 print "</td>" .
2947 "</tr>\n";
Kay Sievers40c13812005-11-19 17:41:29 +01002948 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
Jakub Narebski952c65f2006-08-22 16:52:50 +02002949 print "<tr><td></td><td> $cd{'rfc2822'}" .
2950 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2951 "</td></tr>\n";
Jakub Narebski1f1ab5f2006-06-20 14:58:12 +00002952 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
Kay Sieversbddec012005-08-07 20:25:42 +02002953 print "<tr>" .
2954 "<td>tree</td>" .
Jakub Narebski1f1ab5f2006-06-20 14:58:12 +00002955 "<td class=\"sha1\">" .
Jakub Narebski952c65f2006-08-22 16:52:50 +02002956 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
2957 class => "list"}, $co{'tree'}) .
Kay Sievers19806692005-08-07 20:26:27 +02002958 "</td>" .
Jakub Narebski952c65f2006-08-22 16:52:50 +02002959 "<td class=\"link\">" .
2960 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
2961 "tree");
Aneesh Kumar K.Vcb9c6e52006-08-17 20:59:46 +05302962 if ($have_snapshot) {
Jakub Narebski952c65f2006-08-22 16:52:50 +02002963 print " | " .
2964 $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot");
Aneesh Kumar K.Vcb9c6e52006-08-17 20:59:46 +05302965 }
2966 print "</td>" .
Kay Sieversbddec012005-08-07 20:25:42 +02002967 "</tr>\n";
Jakub Narebski8adc4bd2006-06-22 08:52:57 +02002968 my $parents = $co{'parents'};
Kay Sievers3e029292005-08-07 20:05:15 +02002969 foreach my $par (@$parents) {
Kay Sieversbddec012005-08-07 20:25:42 +02002970 print "<tr>" .
2971 "<td>parent</td>" .
Jakub Narebski952c65f2006-08-22 16:52:50 +02002972 "<td class=\"sha1\">" .
2973 $cgi->a({-href => href(action=>"commit", hash=>$par),
2974 class => "list"}, $par) .
2975 "</td>" .
Kay Sieversbddec012005-08-07 20:25:42 +02002976 "<td class=\"link\">" .
Martin Waitz1c2a4f52006-08-16 00:24:30 +02002977 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
Jakub Narebski952c65f2006-08-22 16:52:50 +02002978 " | " .
Jakub Narebskif2e60942006-09-03 23:43:03 +02002979 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") .
Kay Sieversbddec012005-08-07 20:25:42 +02002980 "</td>" .
2981 "</tr>\n";
Kay Sievers3e029292005-08-07 20:05:15 +02002982 }
Jakub Narebski7a9b4c52006-06-21 09:48:02 +02002983 print "</table>".
Kay Sieversb87d78d2005-08-07 20:21:04 +02002984 "</div>\n";
Jakub Narebskid16d0932006-08-17 11:21:23 +02002985
Kay Sieversfbb592a2005-08-07 20:12:11 +02002986 print "<div class=\"page_body\">\n";
Jakub Narebskid16d0932006-08-17 11:21:23 +02002987 git_print_log($co{'comment'});
Kay Sievers927dcec2005-08-07 20:18:44 +02002988 print "</div>\n";
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02002989
Jakub Narebskieee08902006-08-24 00:15:14 +02002990 git_difftree_body(\@difftree, $hash, $parent);
Jakub Narebski4a4a1a52006-08-14 02:18:33 +02002991
Kay Sievers12a88f22005-08-07 20:02:47 +02002992 git_footer_html();
Kay Sievers09bd7892005-08-07 20:21:23 +02002993}
2994
2995sub git_blobdiff {
Jakub Narebski9b71b1f2006-08-25 21:14:49 +02002996 my $format = shift || 'html';
2997
Jakub Narebski7c5e2eb2006-08-25 21:13:34 +02002998 my $fd;
2999 my @difftree;
3000 my %diffinfo;
Jakub Narebski9b71b1f2006-08-25 21:14:49 +02003001 my $expires;
Jakub Narebski7c5e2eb2006-08-25 21:13:34 +02003002
3003 # preparing $fd and %diffinfo for git_patchset_body
3004 # new style URI
3005 if (defined $hash_base && defined $hash_parent_base) {
3006 if (defined $file_name) {
3007 # read raw output
Dennis Stosberg25691fb2006-08-28 17:49:58 +02003008 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
Jakub Narebski7c5e2eb2006-08-25 21:13:34 +02003009 "--", $file_name
3010 or die_error(undef, "Open git-diff-tree failed");
3011 @difftree = map { chomp; $_ } <$fd>;
3012 close $fd
3013 or die_error(undef, "Reading git-diff-tree failed");
3014 @difftree
3015 or die_error('404 Not Found', "Blob diff not found");
3016
Jakub Narebski0aea3372006-08-27 23:45:26 +02003017 } elsif (defined $hash &&
3018 $hash =~ /[0-9a-fA-F]{40}/) {
3019 # try to find filename from $hash
Jakub Narebski7c5e2eb2006-08-25 21:13:34 +02003020
3021 # read filtered raw output
Dennis Stosberg25691fb2006-08-28 17:49:58 +02003022 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
Jakub Narebski7c5e2eb2006-08-25 21:13:34 +02003023 or die_error(undef, "Open git-diff-tree failed");
3024 @difftree =
3025 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3026 # $hash == to_id
3027 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3028 map { chomp; $_ } <$fd>;
3029 close $fd
3030 or die_error(undef, "Reading git-diff-tree failed");
3031 @difftree
3032 or die_error('404 Not Found', "Blob diff not found");
3033
3034 } else {
3035 die_error('404 Not Found', "Missing one of the blob diff parameters");
3036 }
3037
3038 if (@difftree > 1) {
3039 die_error('404 Not Found', "Ambiguous blob diff specification");
3040 }
3041
3042 %diffinfo = parse_difftree_raw_line($difftree[0]);
3043 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3044 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3045
3046 $hash_parent ||= $diffinfo{'from_id'};
3047 $hash ||= $diffinfo{'to_id'};
3048
Jakub Narebski9b71b1f2006-08-25 21:14:49 +02003049 # non-textual hash id's can be cached
3050 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3051 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3052 $expires = '+1d';
3053 }
3054
Jakub Narebski7c5e2eb2006-08-25 21:13:34 +02003055 # open patch output
Dennis Stosberg25691fb2006-08-28 17:49:58 +02003056 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
Jakub Narebski6bcf4b42006-08-27 23:49:36 +02003057 '-p', $hash_parent_base, $hash_base,
Jakub Narebski7c5e2eb2006-08-25 21:13:34 +02003058 "--", $file_name
3059 or die_error(undef, "Open git-diff-tree failed");
3060 }
3061
3062 # old/legacy style URI
3063 if (!%diffinfo && # if new style URI failed
3064 defined $hash && defined $hash_parent) {
3065 # fake git-diff-tree raw output
3066 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3067 $diffinfo{'from_id'} = $hash_parent;
3068 $diffinfo{'to_id'} = $hash;
3069 if (defined $file_name) {
3070 if (defined $file_parent) {
3071 $diffinfo{'status'} = '2';
3072 $diffinfo{'from_file'} = $file_parent;
3073 $diffinfo{'to_file'} = $file_name;
3074 } else { # assume not renamed
3075 $diffinfo{'status'} = '1';
3076 $diffinfo{'from_file'} = $file_name;
3077 $diffinfo{'to_file'} = $file_name;
3078 }
3079 } else { # no filename given
3080 $diffinfo{'status'} = '2';
3081 $diffinfo{'from_file'} = $hash_parent;
3082 $diffinfo{'to_file'} = $hash;
3083 }
3084
Jakub Narebski9b71b1f2006-08-25 21:14:49 +02003085 # non-textual hash id's can be cached
3086 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3087 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3088 $expires = '+1d';
3089 }
3090
3091 # open patch output
Dennis Stosberg25691fb2006-08-28 17:49:58 +02003092 open $fd, "-|", git_cmd(), "diff", '-p', @diff_opts, $hash_parent, $hash
Jakub Narebski7c5e2eb2006-08-25 21:13:34 +02003093 or die_error(undef, "Open git-diff failed");
3094 } else {
3095 die_error('404 Not Found', "Missing one of the blob diff parameters")
3096 unless %diffinfo;
3097 }
3098
3099 # header
Jakub Narebski9b71b1f2006-08-25 21:14:49 +02003100 if ($format eq 'html') {
3101 my $formats_nav =
3102 $cgi->a({-href => href(action=>"blobdiff_plain",
3103 hash=>$hash, hash_parent=>$hash_parent,
3104 hash_base=>$hash_base, hash_parent_base=>$hash_parent_base,
3105 file_name=>$file_name, file_parent=>$file_parent)},
3106 "plain");
3107 git_header_html(undef, $expires);
3108 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
3109 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3110 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3111 } else {
3112 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3113 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3114 }
3115 if (defined $file_name) {
3116 git_print_page_path($file_name, "blob", $hash_base);
3117 } else {
3118 print "<div class=\"page_path\"></div>\n";
3119 }
3120
3121 } elsif ($format eq 'plain') {
3122 print $cgi->header(
3123 -type => 'text/plain',
3124 -charset => 'utf-8',
3125 -expires => $expires,
3126 -content_disposition => qq(inline; filename="${file_name}.patch"));
3127
3128 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3129
Kay Sievers09bd7892005-08-07 20:21:23 +02003130 } else {
Jakub Narebski9b71b1f2006-08-25 21:14:49 +02003131 die_error(undef, "Unknown blobdiff format");
Jakub Narebski7c5e2eb2006-08-25 21:13:34 +02003132 }
3133
3134 # patch
Jakub Narebski9b71b1f2006-08-25 21:14:49 +02003135 if ($format eq 'html') {
3136 print "<div class=\"page_body\">\n";
Jakub Narebski7c5e2eb2006-08-25 21:13:34 +02003137
Jakub Narebski9b71b1f2006-08-25 21:14:49 +02003138 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
3139 close $fd;
Jakub Narebski7c5e2eb2006-08-25 21:13:34 +02003140
Jakub Narebski9b71b1f2006-08-25 21:14:49 +02003141 print "</div>\n"; # class="page_body"
3142 git_footer_html();
3143
3144 } else {
3145 while (my $line = <$fd>) {
3146 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
3147 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
3148
3149 print $line;
3150
3151 last if $line =~ m!^\+\+\+!;
3152 }
3153 local $/ = undef;
3154 print <$fd>;
3155 close $fd;
3156 }
Kay Sievers09bd7892005-08-07 20:21:23 +02003157}
3158
Kay Sievers19806692005-08-07 20:26:27 +02003159sub git_blobdiff_plain {
Jakub Narebski9b71b1f2006-08-25 21:14:49 +02003160 git_blobdiff('plain');
Kay Sievers19806692005-08-07 20:26:27 +02003161}
3162
Kay Sievers09bd7892005-08-07 20:21:23 +02003163sub git_commitdiff {
Jakub Narebskieee08902006-08-24 00:15:14 +02003164 my $format = shift || 'html';
Jakub Narebski847e01f2006-08-14 02:05:47 +02003165 my %co = parse_commit($hash);
Kay Sievers034df392005-08-07 20:20:07 +02003166 if (!%co) {
Jakub Narebskicac4bd92006-08-05 13:13:53 +02003167 die_error(undef, "Unknown commit object");
Kay Sieversd63577d2005-08-07 20:18:13 +02003168 }
Kay Sieversbddec012005-08-07 20:25:42 +02003169 if (!defined $hash_parent) {
Jakub Narebskib5ff2cf2006-08-06 16:14:25 +02003170 $hash_parent = $co{'parent'} || '--root';
Kay Sieversbddec012005-08-07 20:25:42 +02003171 }
Jakub Narebskieee08902006-08-24 00:15:14 +02003172
3173 # read commitdiff
3174 my $fd;
3175 my @difftree;
Jakub Narebskieee08902006-08-24 00:15:14 +02003176 if ($format eq 'html') {
Dennis Stosberg25691fb2006-08-28 17:49:58 +02003177 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
Jakub Narebskieee08902006-08-24 00:15:14 +02003178 "--patch-with-raw", "--full-index", $hash_parent, $hash
3179 or die_error(undef, "Open git-diff-tree failed");
3180
3181 while (chomp(my $line = <$fd>)) {
3182 # empty line ends raw part of diff-tree output
3183 last unless $line;
3184 push @difftree, $line;
3185 }
Jakub Narebskieee08902006-08-24 00:15:14 +02003186
Jakub Narebskieee08902006-08-24 00:15:14 +02003187 } elsif ($format eq 'plain') {
Dennis Stosberg25691fb2006-08-28 17:49:58 +02003188 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
Jakub Narebski6bcf4b42006-08-27 23:49:36 +02003189 '-p', $hash_parent, $hash
Jakub Narebskieee08902006-08-24 00:15:14 +02003190 or die_error(undef, "Open git-diff-tree failed");
Jakub Narebski157e43b2006-08-24 19:34:36 +02003191
Jakub Narebskieee08902006-08-24 00:15:14 +02003192 } else {
3193 die_error(undef, "Unknown commitdiff format");
3194 }
Kay Sievers4c02e3c2005-08-07 19:52:52 +02003195
Kay Sievers11044292005-10-19 03:18:45 +02003196 # non-textual hash id's can be cached
3197 my $expires;
3198 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3199 $expires = "+1d";
3200 }
Kay Sievers09bd7892005-08-07 20:21:23 +02003201
Jakub Narebskieee08902006-08-24 00:15:14 +02003202 # write commit message
3203 if ($format eq 'html') {
3204 my $refs = git_get_references();
3205 my $ref = format_ref_marker($refs, $co{'id'});
3206 my $formats_nav =
3207 $cgi->a({-href => href(action=>"commitdiff_plain",
3208 hash=>$hash, hash_parent=>$hash_parent)},
3209 "plain");
Kay Sievers19806692005-08-07 20:26:27 +02003210
Jakub Narebskieee08902006-08-24 00:15:14 +02003211 git_header_html(undef, $expires);
3212 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3213 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
Jakub Narebski6fd92a22006-08-28 14:48:12 +02003214 git_print_authorship(\%co);
Jakub Narebskieee08902006-08-24 00:15:14 +02003215 print "<div class=\"page_body\">\n";
3216 print "<div class=\"log\">\n";
3217 git_print_simplified_log($co{'comment'}, 1); # skip title
3218 print "</div>\n"; # class="log"
Kay Sievers1b1cd422005-08-07 20:28:01 +02003219
Jakub Narebskieee08902006-08-24 00:15:14 +02003220 } elsif ($format eq 'plain') {
3221 my $refs = git_get_references("tags");
Jakub Narebskiedf735a2006-08-24 19:45:30 +02003222 my $tagname = git_get_rev_name_tags($hash);
Jakub Narebskieee08902006-08-24 00:15:14 +02003223 my $filename = basename($project) . "-$hash.patch";
3224
3225 print $cgi->header(
3226 -type => 'text/plain',
3227 -charset => 'utf-8',
3228 -expires => $expires,
3229 -content_disposition => qq(inline; filename="$filename"));
3230 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
3231 print <<TEXT;
Jakub Narebski59b9f612006-08-22 23:42:53 +02003232From: $co{'author'}
3233Date: $ad{'rfc2822'} ($ad{'tz_local'})
3234Subject: $co{'title'}
3235TEXT
Jakub Narebskiedf735a2006-08-24 19:45:30 +02003236 print "X-Git-Tag: $tagname\n" if $tagname;
Jakub Narebskieee08902006-08-24 00:15:14 +02003237 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
Jakub Narebskiedf735a2006-08-24 19:45:30 +02003238
Jakub Narebskieee08902006-08-24 00:15:14 +02003239 foreach my $line (@{$co{'comment'}}) {
3240 print "$line\n";
Kay Sievers19806692005-08-07 20:26:27 +02003241 }
Jakub Narebskieee08902006-08-24 00:15:14 +02003242 print "---\n\n";
Kay Sievers19806692005-08-07 20:26:27 +02003243 }
Jakub Narebskieee08902006-08-24 00:15:14 +02003244
3245 # write patch
3246 if ($format eq 'html') {
Jakub Narebskib4657e72006-08-28 14:48:14 +02003247 git_difftree_body(\@difftree, $hash, $hash_parent);
3248 print "<br/>\n";
Jakub Narebskieee08902006-08-24 00:15:14 +02003249
Jakub Narebski157e43b2006-08-24 19:34:36 +02003250 git_patchset_body($fd, \@difftree, $hash, $hash_parent);
3251 close $fd;
Jakub Narebskieee08902006-08-24 00:15:14 +02003252 print "</div>\n"; # class="page_body"
3253 git_footer_html();
3254
3255 } elsif ($format eq 'plain') {
3256 local $/ = undef;
3257 print <$fd>;
3258 close $fd
3259 or print "Reading git-diff-tree failed\n";
3260 }
3261}
3262
3263sub git_commitdiff_plain {
3264 git_commitdiff('plain');
Kay Sievers19806692005-08-07 20:26:27 +02003265}
3266
Kay Sievers09bd7892005-08-07 20:21:23 +02003267sub git_history {
Luben Tuikovc6e1d9e2006-07-23 13:26:30 -07003268 if (!defined $hash_base) {
Jakub Narebski847e01f2006-08-14 02:05:47 +02003269 $hash_base = git_get_head_hash($project);
Kay Sievers09bd7892005-08-07 20:21:23 +02003270 }
Jakub Narebski8be68352006-09-11 00:36:04 +02003271 if (!defined $page) {
3272 $page = 0;
3273 }
Luben Tuikov63433102006-07-23 13:31:15 -07003274 my $ftype;
Jakub Narebski847e01f2006-08-14 02:05:47 +02003275 my %co = parse_commit($hash_base);
Kay Sievers09bd7892005-08-07 20:21:23 +02003276 if (!%co) {
Jakub Narebskicac4bd92006-08-05 13:13:53 +02003277 die_error(undef, "Unknown commit object");
Kay Sievers2ae100d2005-08-07 20:17:00 +02003278 }
Jakub Narebski8be68352006-09-11 00:36:04 +02003279
Jakub Narebski847e01f2006-08-14 02:05:47 +02003280 my $refs = git_get_references();
Jakub Narebski8be68352006-09-11 00:36:04 +02003281 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3282
Luben Tuikov93d5f062006-07-23 13:30:08 -07003283 if (!defined $hash && defined $file_name) {
3284 $hash = git_get_hash_by_path($hash_base, $file_name);
3285 }
Luben Tuikovcff07712006-07-23 13:28:55 -07003286 if (defined $hash) {
Luben Tuikov63433102006-07-23 13:31:15 -07003287 $ftype = git_get_type($hash);
Luben Tuikovcff07712006-07-23 13:28:55 -07003288 }
Kay Sievers10dba282005-08-07 20:25:27 +02003289
Junio C Hamanocdd40372006-06-30 18:54:32 -07003290 open my $fd, "-|",
Jakub Narebski8be68352006-09-11 00:36:04 +02003291 git_cmd(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3292 or die_error(undef, "Open git-rev-list-failed");
3293 my @revlist = map { chomp; $_ } <$fd>;
3294 close $fd
3295 or die_error(undef, "Reading git-rev-list failed");
Dennis Stosberg25691fb2006-08-28 17:49:58 +02003296
Jakub Narebski8be68352006-09-11 00:36:04 +02003297 my $paging_nav = '';
3298 if ($page > 0) {
3299 $paging_nav .=
3300 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3301 file_name=>$file_name)},
3302 "first");
3303 $paging_nav .= " &sdot; " .
3304 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3305 file_name=>$file_name, page=>$page-1),
3306 -accesskey => "p", -title => "Alt-p"}, "prev");
3307 } else {
3308 $paging_nav .= "first";
3309 $paging_nav .= " &sdot; prev";
3310 }
3311 if ($#revlist >= (100 * ($page+1)-1)) {
3312 $paging_nav .= " &sdot; " .
3313 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3314 file_name=>$file_name, page=>$page+1),
3315 -accesskey => "n", -title => "Alt-n"}, "next");
3316 } else {
3317 $paging_nav .= " &sdot; next";
3318 }
3319 my $next_link = '';
3320 if ($#revlist >= (100 * ($page+1)-1)) {
3321 $next_link =
3322 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3323 file_name=>$file_name, page=>$page+1),
3324 -title => "Alt-n"}, "next");
3325 }
Jakub Narebski581860e2006-08-14 02:09:08 +02003326
Jakub Narebski8be68352006-09-11 00:36:04 +02003327 git_header_html();
3328 git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3329 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3330 git_print_page_path($file_name, $ftype, $hash_base);
3331
3332 git_history_body(\@revlist, ($page * 100), $#revlist,
3333 $refs, $hash_base, $ftype, $next_link);
3334
Kay Sieversd51e9022005-08-07 20:16:07 +02003335 git_footer_html();
Kay Sievers161332a2005-08-07 19:49:46 +02003336}
Kay Sievers19806692005-08-07 20:26:27 +02003337
3338sub git_search {
3339 if (!defined $searchtext) {
Jakub Narebskicac4bd92006-08-05 13:13:53 +02003340 die_error(undef, "Text field empty");
Kay Sievers19806692005-08-07 20:26:27 +02003341 }
3342 if (!defined $hash) {
Jakub Narebski847e01f2006-08-14 02:05:47 +02003343 $hash = git_get_head_hash($project);
Kay Sievers19806692005-08-07 20:26:27 +02003344 }
Jakub Narebski847e01f2006-08-14 02:05:47 +02003345 my %co = parse_commit($hash);
Kay Sievers19806692005-08-07 20:26:27 +02003346 if (!%co) {
Jakub Narebskicac4bd92006-08-05 13:13:53 +02003347 die_error(undef, "Unknown commit object");
Kay Sievers19806692005-08-07 20:26:27 +02003348 }
Jakub Narebski04f7a942006-09-11 00:29:27 +02003349
Kay Sieversc994d622005-08-07 20:27:18 +02003350 my $commit_search = 1;
3351 my $author_search = 0;
3352 my $committer_search = 0;
3353 my $pickaxe_search = 0;
3354 if ($searchtext =~ s/^author\\://i) {
3355 $author_search = 1;
3356 } elsif ($searchtext =~ s/^committer\\://i) {
3357 $committer_search = 1;
3358 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3359 $commit_search = 0;
3360 $pickaxe_search = 1;
Jakub Narebski04f7a942006-09-11 00:29:27 +02003361
3362 # pickaxe may take all resources of your box and run for several minutes
3363 # with every query - so decide by yourself how public you make this feature
3364 my ($have_pickaxe) = gitweb_check_feature('pickaxe');
3365 if (!$have_pickaxe) {
3366 die_error('403 Permission denied', "Permission denied");
3367 }
Kay Sieversc994d622005-08-07 20:27:18 +02003368 }
Kay Sievers19806692005-08-07 20:26:27 +02003369 git_header_html();
Jakub Narebski847e01f2006-08-14 02:05:47 +02003370 git_print_page_nav('','', $hash,$co{'tree'},$hash);
3371 git_print_header_div('commit', esc_html($co{'title'}), $hash);
Kay Sievers19806692005-08-07 20:26:27 +02003372
Kay Sievers19806692005-08-07 20:26:27 +02003373 print "<table cellspacing=\"0\">\n";
Kay Sievers19806692005-08-07 20:26:27 +02003374 my $alternate = 0;
Kay Sieversc994d622005-08-07 20:27:18 +02003375 if ($commit_search) {
3376 $/ = "\0";
Dennis Stosberg25691fb2006-08-28 17:49:58 +02003377 open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", $hash or next;
Kay Sieversc994d622005-08-07 20:27:18 +02003378 while (my $commit_text = <$fd>) {
3379 if (!grep m/$searchtext/i, $commit_text) {
Kay Sievers19806692005-08-07 20:26:27 +02003380 next;
3381 }
Kay Sieversc994d622005-08-07 20:27:18 +02003382 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3383 next;
Kay Sievers19806692005-08-07 20:26:27 +02003384 }
Kay Sieversc994d622005-08-07 20:27:18 +02003385 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3386 next;
3387 }
3388 my @commit_lines = split "\n", $commit_text;
Jakub Narebski847e01f2006-08-14 02:05:47 +02003389 my %co = parse_commit(undef, \@commit_lines);
Kay Sieversc994d622005-08-07 20:27:18 +02003390 if (!%co) {
3391 next;
3392 }
3393 if ($alternate) {
3394 print "<tr class=\"dark\">\n";
3395 } else {
3396 print "<tr class=\"light\">\n";
3397 }
3398 $alternate ^= 1;
Kay Sievers71be1e72005-08-07 20:27:27 +02003399 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
Kay Sievers40c13812005-11-19 17:41:29 +01003400 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
Kay Sieversc994d622005-08-07 20:27:18 +02003401 "<td>" .
Jakub Narebski63e42202006-08-22 12:38:59 +02003402 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
3403 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
Kay Sieversc994d622005-08-07 20:27:18 +02003404 my $comment = $co{'comment'};
3405 foreach my $line (@$comment) {
3406 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
Kay Sievers40c13812005-11-19 17:41:29 +01003407 my $lead = esc_html($1) || "";
Kay Sieversc994d622005-08-07 20:27:18 +02003408 $lead = chop_str($lead, 30, 10);
Kay Sievers40c13812005-11-19 17:41:29 +01003409 my $match = esc_html($2) || "";
3410 my $trail = esc_html($3) || "";
Kay Sieversc994d622005-08-07 20:27:18 +02003411 $trail = chop_str($trail, 30, 10);
Jakub Narebski1f1ab5f2006-06-20 14:58:12 +00003412 my $text = "$lead<span class=\"match\">$match</span>$trail";
Kay Sieversc994d622005-08-07 20:27:18 +02003413 print chop_str($text, 80, 5) . "<br/>\n";
3414 }
3415 }
3416 print "</td>\n" .
3417 "<td class=\"link\">" .
Martin Waitz756d2f02006-08-17 00:28:36 +02003418 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
Jakub Narebski952c65f2006-08-22 16:52:50 +02003419 " | " .
3420 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
Kay Sieversc994d622005-08-07 20:27:18 +02003421 print "</td>\n" .
3422 "</tr>\n";
Kay Sievers19806692005-08-07 20:26:27 +02003423 }
Kay Sieversc994d622005-08-07 20:27:18 +02003424 close $fd;
3425 }
3426
3427 if ($pickaxe_search) {
3428 $/ = "\n";
Dennis Stosberg25691fb2006-08-28 17:49:58 +02003429 my $git_command = git_cmd_str();
3430 open my $fd, "-|", "$git_command rev-list $hash | " .
3431 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
Kay Sieversc994d622005-08-07 20:27:18 +02003432 undef %co;
3433 my @files;
3434 while (my $line = <$fd>) {
3435 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3436 my %set;
3437 $set{'file'} = $6;
3438 $set{'from_id'} = $3;
3439 $set{'to_id'} = $4;
3440 $set{'id'} = $set{'to_id'};
3441 if ($set{'id'} =~ m/0{40}/) {
3442 $set{'id'} = $set{'from_id'};
3443 }
3444 if ($set{'id'} =~ m/0{40}/) {
3445 next;
3446 }
3447 push @files, \%set;
Kay Sievers53b89d82005-08-12 22:12:58 +02003448 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
Kay Sieversc994d622005-08-07 20:27:18 +02003449 if (%co) {
3450 if ($alternate) {
3451 print "<tr class=\"dark\">\n";
3452 } else {
3453 print "<tr class=\"light\">\n";
3454 }
3455 $alternate ^= 1;
Kay Sievers71be1e72005-08-07 20:27:27 +02003456 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
Kay Sievers40c13812005-11-19 17:41:29 +01003457 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
Kay Sieversc994d622005-08-07 20:27:18 +02003458 "<td>" .
Jakub Narebski952c65f2006-08-22 16:52:50 +02003459 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
3460 -class => "list subject"},
Jakub Narebski63e42202006-08-22 12:38:59 +02003461 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
Kay Sieversc994d622005-08-07 20:27:18 +02003462 while (my $setref = shift @files) {
3463 my %set = %$setref;
Jakub Narebski952c65f2006-08-22 16:52:50 +02003464 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
3465 hash=>$set{'id'}, file_name=>$set{'file'}),
3466 -class => "list"},
3467 "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") .
Kay Sieversc994d622005-08-07 20:27:18 +02003468 "<br/>\n";
3469 }
3470 print "</td>\n" .
3471 "<td class=\"link\">" .
Martin Waitz756d2f02006-08-17 00:28:36 +02003472 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
Jakub Narebski952c65f2006-08-22 16:52:50 +02003473 " | " .
3474 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
Kay Sieversc994d622005-08-07 20:27:18 +02003475 print "</td>\n" .
3476 "</tr>\n";
3477 }
Jakub Narebski847e01f2006-08-14 02:05:47 +02003478 %co = parse_commit($1);
Kay Sieversc994d622005-08-07 20:27:18 +02003479 }
3480 }
3481 close $fd;
Kay Sievers19806692005-08-07 20:26:27 +02003482 }
3483 print "</table>\n";
Kay Sievers19806692005-08-07 20:26:27 +02003484 git_footer_html();
3485}
3486
3487sub git_shortlog {
Jakub Narebski847e01f2006-08-14 02:05:47 +02003488 my $head = git_get_head_hash($project);
Kay Sievers19806692005-08-07 20:26:27 +02003489 if (!defined $hash) {
3490 $hash = $head;
3491 }
Kay Sieversea4a6df2005-08-07 20:26:49 +02003492 if (!defined $page) {
3493 $page = 0;
3494 }
Jakub Narebski847e01f2006-08-14 02:05:47 +02003495 my $refs = git_get_references();
Kay Sieversea4a6df2005-08-07 20:26:49 +02003496
3497 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
Dennis Stosberg25691fb2006-08-28 17:49:58 +02003498 open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
Jakub Narebskicac4bd92006-08-05 13:13:53 +02003499 or die_error(undef, "Open git-rev-list failed");
Jakub Narebski0881d2d2006-07-30 14:58:11 +02003500 my @revlist = map { chomp; $_ } <$fd>;
Kay Sievers19806692005-08-07 20:26:27 +02003501 close $fd;
Kay Sieversea4a6df2005-08-07 20:26:49 +02003502
Jakub Narebski847e01f2006-08-14 02:05:47 +02003503 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#revlist);
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02003504 my $next_link = '';
3505 if ($#revlist >= (100 * ($page+1)-1)) {
3506 $next_link =
Martin Waitz756d2f02006-08-17 00:28:36 +02003507 $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1),
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02003508 -title => "Alt-n"}, "next");
3509 }
3510
Jakub Narebski0d83ddc2006-07-30 15:01:07 +02003511
3512 git_header_html();
Jakub Narebski847e01f2006-08-14 02:05:47 +02003513 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
3514 git_print_header_div('summary', $project);
Jakub Narebski0d83ddc2006-07-30 15:01:07 +02003515
Jakub Narebski9f5dcb82006-07-31 11:22:13 +02003516 git_shortlog_body(\@revlist, ($page * 100), $#revlist, $refs, $next_link);
3517
Kay Sievers19806692005-08-07 20:26:27 +02003518 git_footer_html();
3519}
Jakub Narebski717b8312006-07-31 21:22:15 +02003520
3521## ......................................................................
3522## feeds (RSS, OPML)
3523
3524sub git_rss {
3525 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
Dennis Stosberg25691fb2006-08-28 17:49:58 +02003526 open my $fd, "-|", git_cmd(), "rev-list", "--max-count=150", git_get_head_hash($project)
Jakub Narebskicac4bd92006-08-05 13:13:53 +02003527 or die_error(undef, "Open git-rev-list failed");
Jakub Narebski717b8312006-07-31 21:22:15 +02003528 my @revlist = map { chomp; $_ } <$fd>;
Jakub Narebskicac4bd92006-08-05 13:13:53 +02003529 close $fd or die_error(undef, "Reading git-rev-list failed");
Jakub Narebski717b8312006-07-31 21:22:15 +02003530 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
Jakub Narebski59b9f612006-08-22 23:42:53 +02003531 print <<XML;
3532<?xml version="1.0" encoding="utf-8"?>
3533<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3534<channel>
3535<title>$project $my_uri $my_url</title>
3536<link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3537<description>$project log</description>
3538<language>en</language>
3539XML
Jakub Narebski717b8312006-07-31 21:22:15 +02003540
3541 for (my $i = 0; $i <= $#revlist; $i++) {
3542 my $commit = $revlist[$i];
Jakub Narebski847e01f2006-08-14 02:05:47 +02003543 my %co = parse_commit($commit);
Jakub Narebski717b8312006-07-31 21:22:15 +02003544 # we read 150, we always show 30 and the ones more recent than 48 hours
3545 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3546 last;
3547 }
Jakub Narebski847e01f2006-08-14 02:05:47 +02003548 my %cd = parse_date($co{'committer_epoch'});
Dennis Stosberg25691fb2006-08-28 17:49:58 +02003549 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
Jakub Narebski6bcf4b42006-08-27 23:49:36 +02003550 $co{'parent'}, $co{'id'}
3551 or next;
Jakub Narebski717b8312006-07-31 21:22:15 +02003552 my @difftree = map { chomp; $_ } <$fd>;
Jakub Narebski6bcf4b42006-08-27 23:49:36 +02003553 close $fd
3554 or next;
Jakub Narebski717b8312006-07-31 21:22:15 +02003555 print "<item>\n" .
3556 "<title>" .
3557 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
3558 "</title>\n" .
3559 "<author>" . esc_html($co{'author'}) . "</author>\n" .
3560 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3561 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3562 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3563 "<description>" . esc_html($co{'title'}) . "</description>\n" .
3564 "<content:encoded>" .
3565 "<![CDATA[\n";
3566 my $comment = $co{'comment'};
3567 foreach my $line (@$comment) {
3568 $line = decode("utf8", $line, Encode::FB_DEFAULT);
3569 print "$line<br/>\n";
3570 }
3571 print "<br/>\n";
3572 foreach my $line (@difftree) {
3573 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3574 next;
3575 }
3576 my $file = validate_input(unquote($7));
3577 $file = decode("utf8", $file, Encode::FB_DEFAULT);
3578 print "$file<br/>\n";
3579 }
3580 print "]]>\n" .
3581 "</content:encoded>\n" .
3582 "</item>\n";
3583 }
3584 print "</channel></rss>";
3585}
3586
3587sub git_opml {
Jakub Narebski847e01f2006-08-14 02:05:47 +02003588 my @list = git_get_projects_list();
Jakub Narebski717b8312006-07-31 21:22:15 +02003589
3590 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
Jakub Narebski59b9f612006-08-22 23:42:53 +02003591 print <<XML;
3592<?xml version="1.0" encoding="utf-8"?>
3593<opml version="1.0">
3594<head>
3595 <title>$site_name Git OPML Export</title>
3596</head>
3597<body>
3598<outline text="git RSS feeds">
3599XML
Jakub Narebski717b8312006-07-31 21:22:15 +02003600
3601 foreach my $pr (@list) {
3602 my %proj = %$pr;
Jakub Narebski847e01f2006-08-14 02:05:47 +02003603 my $head = git_get_head_hash($proj{'path'});
Jakub Narebski717b8312006-07-31 21:22:15 +02003604 if (!defined $head) {
3605 next;
3606 }
Dennis Stosberg25691fb2006-08-28 17:49:58 +02003607 $git_dir = "$projectroot/$proj{'path'}";
Jakub Narebski847e01f2006-08-14 02:05:47 +02003608 my %co = parse_commit($head);
Jakub Narebski717b8312006-07-31 21:22:15 +02003609 if (!%co) {
3610 next;
3611 }
3612
3613 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
3614 my $rss = "$my_url?p=$proj{'path'};a=rss";
3615 my $html = "$my_url?p=$proj{'path'};a=summary";
3616 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
3617 }
Jakub Narebski59b9f612006-08-22 23:42:53 +02003618 print <<XML;
3619</outline>
3620</body>
3621</opml>
3622XML
Jakub Narebski717b8312006-07-31 21:22:15 +02003623}