3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute
=> 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
44 # filename of html text to include at top of each page
45 our $site_header = "++GITWEB_SITE_HEADER++";
46 # html text to include at home page
47 our $home_text = "++GITWEB_HOMETEXT++";
48 # filename of html text to include at bottom of each page
49 our $site_footer = "++GITWEB_SITE_FOOTER++";
52 our @stylesheets = ("++GITWEB_CSS++");
54 # default is not to define style sheet, but it can be overwritten later
58 our $logo = "++GITWEB_LOGO++";
59 # URI of GIT favicon, assumed to be image/png type
60 our $favicon = "++GITWEB_FAVICON++";
62 # source of projects list
63 our $projects_list = "++GITWEB_LIST++";
65 # show repository only if this file exists
66 # (only effective if this variable evaluates to true)
67 our $export_ok = "++GITWEB_EXPORT_OK++";
69 # only allow viewing of repositories also shown on the overview page
70 our $strict_export = "++GITWEB_STRICT_EXPORT++";
72 # list of git base URLs used for URL to where fetch project from,
73 # i.e. full URL is "$git_base_url/$project"
74 our @git_base_url_list = ("++GITWEB_BASE_URL++");
76 # default blob_plain mimetype and default charset for text/plain blob
77 our $default_blob_plain_mimetype = 'text/plain';
78 our $default_text_plain_charset = undef;
80 # file to use for guessing MIME types before trying /etc/mime.types
81 # (relative to the current git repository)
82 our $mimetypes_file = undef;
84 # You define site-wide feature defaults here; override them with
85 # $GITWEB_CONFIG as necessary.
88 # 'sub' => feature-sub (subroutine),
89 # 'override' => allow-override (boolean),
90 # 'default' => [ default options...] (array reference)}
92 # if feature is overridable (it means that allow-override has true value,
93 # then feature-sub will be called with default options as parameters;
94 # return value of feature-sub indicates if to enable specified feature
96 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
99 'sub' => \
&feature_blame
,
104 'sub' => \
&feature_snapshot
,
106 # => [content-encoding, suffix, program]
107 'default' => ['x-gzip', 'gz', 'gzip']},
110 'sub' => \
&feature_pickaxe
,
115 sub gitweb_check_feature
{
117 return unless exists $feature{$name};
118 my ($sub, $override, @defaults) = (
119 $feature{$name}{'sub'},
120 $feature{$name}{'override'},
121 @
{$feature{$name}{'default'}});
122 if (!$override) { return @defaults; }
123 return $sub->(@defaults);
126 # To enable system wide have in $GITWEB_CONFIG
127 # $feature{'blame'}{'default'} = [1];
128 # To have project specific config enable override in $GITWEB_CONFIG
129 # $feature{'blame'}{'override'} = 1;
130 # and in project config gitweb.blame = 0|1;
133 my ($val) = git_get_project_config
('blame', '--bool');
135 if ($val eq 'true') {
137 } elsif ($val eq 'false') {
144 # To disable system wide have in $GITWEB_CONFIG
145 # $feature{'snapshot'}{'default'} = [undef];
146 # To have project specific config enable override in $GITWEB_CONFIG
147 # $feature{'blame'}{'override'} = 1;
148 # and in project config gitweb.snapshot = none|gzip|bzip2
150 sub feature_snapshot
{
151 my ($ctype, $suffix, $command) = @_;
153 my ($val) = git_get_project_config
('snapshot');
155 if ($val eq 'gzip') {
156 return ('x-gzip', 'gz', 'gzip');
157 } elsif ($val eq 'bzip2') {
158 return ('x-bzip2', 'bz2', 'bzip2');
159 } elsif ($val eq 'none') {
163 return ($ctype, $suffix, $command);
166 sub gitweb_have_snapshot
{
167 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
168 my $have_snapshot = (defined $ctype && defined $suffix);
170 return $have_snapshot;
173 # To enable system wide have in $GITWEB_CONFIG
174 # $feature{'pickaxe'}{'default'} = [1];
175 # To have project specific config enable override in $GITWEB_CONFIG
176 # $feature{'pickaxe'}{'override'} = 1;
177 # and in project config gitweb.pickaxe = 0|1;
179 sub feature_pickaxe
{
180 my ($val) = git_get_project_config
('pickaxe', '--bool');
182 if ($val eq 'true') {
184 } elsif ($val eq 'false') {
191 # checking HEAD file with -e is fragile if the repository was
192 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
194 sub check_head_link
{
196 my $headfile = "$dir/HEAD";
197 return ((-e
$headfile) ||
198 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
201 sub check_export_ok
{
203 return (check_head_link
($dir) &&
204 (!$export_ok || -e
"$dir/$export_ok"));
207 # rename detection options for git-diff and git-diff-tree
208 # - default is '-M', with the cost proportional to
209 # (number of removed files) * (number of new files).
210 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
211 # (number of changed files + number of removed files) * (number of new files)
212 # - even more costly is '-C', '--find-copies-harder' with cost
213 # (number of files in the original tree) * (number of new files)
214 # - one might want to include '-B' option, e.g. '-B', '-M'
215 our @diff_opts = ('-M'); # taken from git_commit
217 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
218 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
220 # version of the core git binary
221 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
223 $projects_list ||= $projectroot;
225 # ======================================================================
226 # input validation and dispatch
227 our $action = $cgi->param('a');
228 if (defined $action) {
229 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
230 die_error
(undef, "Invalid action parameter");
234 # parameters which are pathnames
235 our $project = $cgi->param('p');
236 if (defined $project) {
237 if (!validate_pathname
($project) ||
238 !(-d
"$projectroot/$project") ||
239 !check_head_link
("$projectroot/$project") ||
240 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
241 ($strict_export && !project_in_list
($project))) {
243 die_error
(undef, "No such project");
247 our $file_name = $cgi->param('f');
248 if (defined $file_name) {
249 if (!validate_pathname
($file_name)) {
250 die_error
(undef, "Invalid file parameter");
254 our $file_parent = $cgi->param('fp');
255 if (defined $file_parent) {
256 if (!validate_pathname
($file_parent)) {
257 die_error
(undef, "Invalid file parent parameter");
261 # parameters which are refnames
262 our $hash = $cgi->param('h');
264 if (!validate_refname
($hash)) {
265 die_error
(undef, "Invalid hash parameter");
269 our $hash_parent = $cgi->param('hp');
270 if (defined $hash_parent) {
271 if (!validate_refname
($hash_parent)) {
272 die_error
(undef, "Invalid hash parent parameter");
276 our $hash_base = $cgi->param('hb');
277 if (defined $hash_base) {
278 if (!validate_refname
($hash_base)) {
279 die_error
(undef, "Invalid hash base parameter");
283 our $hash_parent_base = $cgi->param('hpb');
284 if (defined $hash_parent_base) {
285 if (!validate_refname
($hash_parent_base)) {
286 die_error
(undef, "Invalid hash parent base parameter");
291 our $page = $cgi->param('pg');
293 if ($page =~ m/[^0-9]/) {
294 die_error
(undef, "Invalid page parameter");
298 our $searchtext = $cgi->param('s');
299 if (defined $searchtext) {
300 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
301 die_error
(undef, "Invalid search parameter");
303 $searchtext = quotemeta $searchtext;
306 # now read PATH_INFO and use it as alternative to parameters
307 sub evaluate_path_info
{
308 return if defined $project;
309 my $path_info = $ENV{"PATH_INFO"};
310 return if !$path_info;
311 $path_info =~ s
,^/+,,;
312 return if !$path_info;
313 # find which part of PATH_INFO is project
314 $project = $path_info;
316 while ($project && !check_head_link
("$projectroot/$project")) {
317 $project =~ s
,/*[^/]*$,,;
320 $project = validate_pathname
($project);
322 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
323 ($strict_export && !project_in_list
($project))) {
327 # do not change any parameters if an action is given using the query string
329 $path_info =~ s
,^$project/*,,;
330 my ($refname, $pathname) = split(/:/, $path_info, 2);
331 if (defined $pathname) {
332 # we got "project.git/branch:filename" or "project.git/branch:dir/"
333 # we could use git_get_type(branch:pathname), but it needs $git_dir
334 $pathname =~ s
,^/+,,;
335 if (!$pathname || substr($pathname, -1) eq "/") {
339 $action ||= "blob_plain";
341 $hash_base ||= validate_refname
($refname);
342 $file_name ||= validate_pathname
($pathname);
343 } elsif (defined $refname) {
344 # we got "project.git/branch"
345 $action ||= "shortlog";
346 $hash ||= validate_refname
($refname);
349 evaluate_path_info
();
351 # path to the current git repository
353 $git_dir = "$projectroot/$project" if $project;
357 "blame" => \
&git_blame2
,
358 "blobdiff" => \
&git_blobdiff
,
359 "blobdiff_plain" => \
&git_blobdiff_plain
,
360 "blob" => \
&git_blob
,
361 "blob_plain" => \
&git_blob_plain
,
362 "commitdiff" => \
&git_commitdiff
,
363 "commitdiff_plain" => \
&git_commitdiff_plain
,
364 "commit" => \
&git_commit
,
365 "heads" => \
&git_heads
,
366 "history" => \
&git_history
,
369 "search" => \
&git_search
,
370 "shortlog" => \
&git_shortlog
,
371 "summary" => \
&git_summary
,
373 "tags" => \
&git_tags
,
374 "tree" => \
&git_tree
,
375 "snapshot" => \
&git_snapshot
,
376 # those below don't need $project
377 "opml" => \
&git_opml
,
378 "project_list" => \
&git_project_list
,
379 "project_index" => \
&git_project_index
,
382 if (defined $project) {
383 $action ||= 'summary';
385 $action ||= 'project_list';
387 if (!defined($actions{$action})) {
388 die_error
(undef, "Unknown action");
390 if ($action !~ m/^(opml|project_list|project_index)$/ &&
392 die_error
(undef, "Project needed");
394 $actions{$action}->();
397 ## ======================================================================
411 hash_parent_base
=> "hpb",
416 my %mapping = @mapping;
418 $params{'project'} = $project unless exists $params{'project'};
421 for (my $i = 0; $i < @mapping; $i += 2) {
422 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
423 if (defined $params{$name}) {
424 push @result, $symbol . "=" . esc_param
($params{$name});
427 return "$my_uri?" . join(';', @result);
431 ## ======================================================================
432 ## validation, quoting/unquoting and escaping
434 sub validate_pathname
{
435 my $input = shift || return undef;
437 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
438 # at the beginning, at the end, and between slashes.
439 # also this catches doubled slashes
440 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
444 if ($input =~ m!\0!) {
450 sub validate_refname
{
451 my $input = shift || return undef;
453 # textual hashes are O.K.
454 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
457 # it must be correct pathname
458 $input = validate_pathname
($input)
460 # restrictions on ref name according to git-check-ref-format
461 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
467 # quote unsafe chars, but keep the slash, even when it's not
468 # correct, but quoted slashes look too horrible in bookmarks
471 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
477 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
480 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
486 # replace invalid utf8 character with SUBSTITUTION sequence
489 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
490 $str = escapeHTML
($str);
491 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
492 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
496 # git may return quoted and escaped filenames
499 if ($str =~ m/^"(.*)"$/) {
501 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
506 # escape tabs (convert tabs to spaces)
510 while ((my $pos = index($line, "\t")) != -1) {
511 if (my $count = (8 - ($pos % 8))) {
512 my $spaces = ' ' x
$count;
513 $line =~ s/\t/$spaces/;
520 sub project_in_list
{
522 my @list = git_get_projects_list
();
523 return @list && scalar(grep { $_->{'path'} eq $project } @list);
526 ## ----------------------------------------------------------------------
527 ## HTML aware string manipulation
532 my $add_len = shift || 10;
534 # allow only $len chars, but don't cut a word if it would fit in $add_len
535 # if it doesn't fit, cut it if it's still longer than the dots we would add
536 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
539 if (length($tail) > 4) {
541 $body =~ s/&[^;]*$//; # remove chopped character entities
546 ## ----------------------------------------------------------------------
547 ## functions returning short strings
549 # CSS class for given age value (in seconds)
553 if ($age < 60*60*2) {
555 } elsif ($age < 60*60*24*2) {
562 # convert age in seconds to "nn units ago" string
567 if ($age > 60*60*24*365*2) {
568 $age_str = (int $age/60/60/24/365);
569 $age_str .= " years ago";
570 } elsif ($age > 60*60*24*(365/12)*2) {
571 $age_str = int $age/60/60/24/(365/12);
572 $age_str .= " months ago";
573 } elsif ($age > 60*60*24*7*2) {
574 $age_str = int $age/60/60/24/7;
575 $age_str .= " weeks ago";
576 } elsif ($age > 60*60*24*2) {
577 $age_str = int $age/60/60/24;
578 $age_str .= " days ago";
579 } elsif ($age > 60*60*2) {
580 $age_str = int $age/60/60;
581 $age_str .= " hours ago";
582 } elsif ($age > 60*2) {
583 $age_str = int $age/60;
584 $age_str .= " min ago";
587 $age_str .= " sec ago";
589 $age_str .= " right now";
594 # convert file mode in octal to symbolic file mode string
596 my $mode = oct shift;
598 if (S_ISDIR
($mode & S_IFMT
)) {
600 } elsif (S_ISLNK
($mode)) {
602 } elsif (S_ISREG
($mode)) {
603 # git cares only about the executable bit
604 if ($mode & S_IXUSR
) {
614 # convert file mode in octal to file type string
618 if ($mode !~ m/^[0-7]+$/) {
624 if (S_ISDIR
($mode & S_IFMT
)) {
626 } elsif (S_ISLNK
($mode)) {
628 } elsif (S_ISREG
($mode)) {
635 ## ----------------------------------------------------------------------
636 ## functions returning short HTML fragments, or transforming HTML fragments
637 ## which don't beling to other sections
639 # format line of commit message or tag comment
640 sub format_log_line_html
{
643 $line = esc_html
($line);
644 $line =~ s/ / /g;
645 if ($line =~ m/([0-9a-fA-F]{40})/) {
647 if (git_get_type
($hash_text) eq "commit") {
649 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
650 -class => "text"}, $hash_text);
651 $line =~ s/$hash_text/$link/;
657 # format marker of refs pointing to given object
658 sub format_ref_marker
{
659 my ($refs, $id) = @_;
662 if (defined $refs->{$id}) {
663 foreach my $ref (@
{$refs->{$id}}) {
664 my ($type, $name) = qw();
665 # e.g. tags/v2.6.11 or heads/next
666 if ($ref =~ m!^(.*?)s?/(.*)$!) {
674 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
679 return ' <span class="refs">'. $markers . '</span>';
685 # format, perhaps shortened and with markers, title line
686 sub format_subject_html
{
687 my ($long, $short, $href, $extra) = @_;
688 $extra = '' unless defined($extra);
690 if (length($short) < length($long)) {
691 return $cgi->a({-href
=> $href, -class => "list subject",
692 -title
=> decode
("utf8", $long, Encode
::FB_DEFAULT
)},
693 esc_html
($short) . $extra);
695 return $cgi->a({-href
=> $href, -class => "list subject"},
696 esc_html
($long) . $extra);
700 sub format_diff_line
{
702 my $char = substr($line, 0, 1);
708 $diff_class = " add";
709 } elsif ($char eq "-") {
710 $diff_class = " rem";
711 } elsif ($char eq "@") {
712 $diff_class = " chunk_header";
713 } elsif ($char eq "\\") {
714 $diff_class = " incomplete";
716 $line = untabify
($line);
717 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
720 ## ----------------------------------------------------------------------
721 ## git utility subroutines, invoking git commands
723 # returns path to the core git executable and the --git-dir parameter as list
725 return $GIT, '--git-dir='.$git_dir;
728 # returns path to the core git executable and the --git-dir parameter as string
730 return join(' ', git_cmd
());
733 # get HEAD ref of given project as hash
734 sub git_get_head_hash
{
736 my $o_git_dir = $git_dir;
738 $git_dir = "$projectroot/$project";
739 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
742 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
746 if (defined $o_git_dir) {
747 $git_dir = $o_git_dir;
752 # get type of given object
756 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
763 sub git_get_project_config
{
764 my ($key, $type) = @_;
766 return unless ($key);
767 $key =~ s/^gitweb\.//;
768 return if ($key =~ m/\W/);
770 my @x = (git_cmd
(), 'repo-config');
771 if (defined $type) { push @x, $type; }
773 push @x, "gitweb.$key";
779 # get hash of given path at given ref
780 sub git_get_hash_by_path
{
782 my $path = shift || return undef;
787 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
788 or die_error
(undef, "Open git-ls-tree failed");
790 close $fd or return undef;
792 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
793 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
794 if (defined $type && $type ne $2) {
801 ## ......................................................................
802 ## git utility functions, directly accessing git repository
804 sub git_get_project_description
{
807 open my $fd, "$projectroot/$path/description" or return undef;
814 sub git_get_project_url_list
{
817 open my $fd, "$projectroot/$path/cloneurl" or return;
818 my @git_project_url_list = map { chomp; $_ } <$fd>;
821 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
824 sub git_get_projects_list
{
827 if (-d
$projects_list) {
828 # search in directory
829 my $dir = $projects_list;
830 my $pfxlen = length("$dir");
833 follow_fast
=> 1, # follow symbolic links
834 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
836 # skip project-list toplevel, if we get it.
837 return if (m!^[/.]$!);
838 # only directories can be git repositories
839 return unless (-d
$_);
841 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
842 # we check related file in $projectroot
843 if (check_export_ok
("$projectroot/$subdir")) {
844 push @list, { path
=> $subdir };
845 $File::Find
::prune
= 1;
850 } elsif (-f
$projects_list) {
851 # read from file(url-encoded):
852 # 'git%2Fgit.git Linus+Torvalds'
853 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
854 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
855 open my ($fd), $projects_list or return;
856 while (my $line = <$fd>) {
858 my ($path, $owner) = split ' ', $line;
859 $path = unescape
($path);
860 $owner = unescape
($owner);
861 if (!defined $path) {
864 if (check_export_ok
("$projectroot/$path")) {
867 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
874 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
878 sub git_get_project_owner
{
882 return undef unless $project;
884 # read from file (url-encoded):
885 # 'git%2Fgit.git Linus+Torvalds'
886 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
887 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
888 if (-f
$projects_list) {
889 open (my $fd , $projects_list);
890 while (my $line = <$fd>) {
892 my ($pr, $ow) = split ' ', $line;
895 if ($pr eq $project) {
896 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
902 if (!defined $owner) {
903 $owner = get_file_owner
("$projectroot/$project");
909 sub git_get_references
{
910 my $type = shift || "";
912 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
913 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
914 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
917 while (my $line = <$fd>) {
919 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
920 if (defined $refs{$1}) {
921 push @
{$refs{$1}}, $2;
931 sub git_get_rev_name_tags
{
932 my $hash = shift || return undef;
934 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
936 my $name_rev = <$fd>;
939 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
942 # catches also '$hash undefined' output
947 ## ----------------------------------------------------------------------
948 ## parse to hash functions
952 my $tz = shift || "-0000";
955 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
956 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
957 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
958 $date{'hour'} = $hour;
959 $date{'minute'} = $min;
960 $date{'mday'} = $mday;
961 $date{'day'} = $days[$wday];
962 $date{'month'} = $months[$mon];
963 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
964 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
965 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
966 $mday, $months[$mon], $hour ,$min;
968 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
969 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
970 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
971 $date{'hour_local'} = $hour;
972 $date{'minute_local'} = $min;
973 $date{'tz_local'} = $tz;
982 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
983 $tag{'id'} = $tag_id;
984 while (my $line = <$fd>) {
986 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
988 } elsif ($line =~ m/^type (.+)$/) {
990 } elsif ($line =~ m/^tag (.+)$/) {
992 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
996 } elsif ($line =~ m/--BEGIN/) {
997 push @comment, $line;
999 } elsif ($line eq "") {
1003 push @comment, <$fd>;
1004 $tag{'comment'} = \
@comment;
1005 close $fd or return;
1006 if (!defined $tag{'name'}) {
1013 my $commit_id = shift;
1014 my $commit_text = shift;
1019 if (defined $commit_text) {
1020 @commit_lines = @
$commit_text;
1023 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1025 @commit_lines = split '\n', <$fd>;
1026 close $fd or return;
1030 my $header = shift @commit_lines;
1031 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1034 ($co{'id'}, my @parents) = split ' ', $header;
1035 $co{'parents'} = \
@parents;
1036 $co{'parent'} = $parents[0];
1037 while (my $line = shift @commit_lines) {
1038 last if $line eq "\n";
1039 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1041 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1043 $co{'author_epoch'} = $2;
1044 $co{'author_tz'} = $3;
1045 if ($co{'author'} =~ m/^([^<]+) </) {
1046 $co{'author_name'} = $1;
1048 $co{'author_name'} = $co{'author'};
1050 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1051 $co{'committer'} = $1;
1052 $co{'committer_epoch'} = $2;
1053 $co{'committer_tz'} = $3;
1054 $co{'committer_name'} = $co{'committer'};
1055 $co{'committer_name'} =~ s/ <.*//;
1058 if (!defined $co{'tree'}) {
1062 foreach my $title (@commit_lines) {
1065 $co{'title'} = chop_str
($title, 80, 5);
1066 # remove leading stuff of merges to make the interesting part visible
1067 if (length($title) > 50) {
1068 $title =~ s/^Automatic //;
1069 $title =~ s/^merge (of|with) /Merge ... /i;
1070 if (length($title) > 50) {
1071 $title =~ s/(http|rsync):\/\///;
1073 if (length($title) > 50) {
1074 $title =~ s/(master|www|rsync)\.//;
1076 if (length($title) > 50) {
1077 $title =~ s/kernel.org:?//;
1079 if (length($title) > 50) {
1080 $title =~ s/\/pub\/scm//;
1083 $co{'title_short'} = chop_str
($title, 50, 5);
1087 # remove added spaces
1088 foreach my $line (@commit_lines) {
1091 $co{'comment'} = \
@commit_lines;
1093 my $age = time - $co{'committer_epoch'};
1095 $co{'age_string'} = age_string
($age);
1096 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1097 if ($age > 60*60*24*7*2) {
1098 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1099 $co{'age_string_age'} = $co{'age_string'};
1101 $co{'age_string_date'} = $co{'age_string'};
1102 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1107 # parse ref from ref_file, given by ref_id, with given type
1109 my $ref_file = shift;
1111 my $type = shift || git_get_type
($ref_id);
1114 $ref_item{'type'} = $type;
1115 $ref_item{'id'} = $ref_id;
1116 $ref_item{'epoch'} = 0;
1117 $ref_item{'age'} = "unknown";
1118 if ($type eq "tag") {
1119 my %tag = parse_tag
($ref_id);
1120 $ref_item{'comment'} = $tag{'comment'};
1121 if ($tag{'type'} eq "commit") {
1122 my %co = parse_commit
($tag{'object'});
1123 $ref_item{'epoch'} = $co{'committer_epoch'};
1124 $ref_item{'age'} = $co{'age_string'};
1125 } elsif (defined($tag{'epoch'})) {
1126 my $age = time - $tag{'epoch'};
1127 $ref_item{'epoch'} = $tag{'epoch'};
1128 $ref_item{'age'} = age_string
($age);
1130 $ref_item{'reftype'} = $tag{'type'};
1131 $ref_item{'name'} = $tag{'name'};
1132 $ref_item{'refid'} = $tag{'object'};
1133 } elsif ($type eq "commit"){
1134 my %co = parse_commit
($ref_id);
1135 $ref_item{'reftype'} = "commit";
1136 $ref_item{'name'} = $ref_file;
1137 $ref_item{'title'} = $co{'title'};
1138 $ref_item{'refid'} = $ref_id;
1139 $ref_item{'epoch'} = $co{'committer_epoch'};
1140 $ref_item{'age'} = $co{'age_string'};
1142 $ref_item{'reftype'} = $type;
1143 $ref_item{'name'} = $ref_file;
1144 $ref_item{'refid'} = $ref_id;
1150 # parse line of git-diff-tree "raw" output
1151 sub parse_difftree_raw_line
{
1155 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1156 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1157 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1158 $res{'from_mode'} = $1;
1159 $res{'to_mode'} = $2;
1160 $res{'from_id'} = $3;
1162 $res{'status'} = $5;
1163 $res{'similarity'} = $6;
1164 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1165 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1167 $res{'file'} = unquote
($7);
1170 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1171 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1172 $res{'commit'} = $1;
1175 return wantarray ?
%res : \
%res;
1178 # parse line of git-ls-tree output
1179 sub parse_ls_tree_line
($;%) {
1184 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1185 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1193 $res{'name'} = unquote
($4);
1196 return wantarray ?
%res : \
%res;
1199 ## ......................................................................
1200 ## parse to array of hashes functions
1202 sub git_get_refs_list
{
1203 my $type = shift || "";
1208 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1210 while (my $line = <$fd>) {
1212 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1213 if (defined $refs{$1}) {
1214 push @
{$refs{$1}}, $2;
1219 if (! $4) { # unpeeled, direct reference
1220 push @refs, { hash
=> $1, name
=> $3 }; # without type
1221 } elsif ($3 eq $refs[-1]{'name'}) {
1222 # most likely a tag is followed by its peeled
1223 # (deref) one, and when that happens we know the
1224 # previous one was of type 'tag'.
1225 $refs[-1]{'type'} = "tag";
1231 foreach my $ref (@refs) {
1232 my $ref_file = $ref->{'name'};
1233 my $ref_id = $ref->{'hash'};
1235 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1236 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1238 push @reflist, \
%ref_item;
1241 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1242 return (\
@reflist, \
%refs);
1245 ## ----------------------------------------------------------------------
1246 ## filesystem-related functions
1248 sub get_file_owner
{
1251 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1252 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1253 if (!defined $gcos) {
1257 $owner =~ s/[,;].*$//;
1258 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1261 ## ......................................................................
1262 ## mimetype related functions
1264 sub mimetype_guess_file
{
1265 my $filename = shift;
1266 my $mimemap = shift;
1267 -r
$mimemap or return undef;
1270 open(MIME
, $mimemap) or return undef;
1272 next if m/^#/; # skip comments
1273 my ($mime, $exts) = split(/\t+/);
1274 if (defined $exts) {
1275 my @exts = split(/\s+/, $exts);
1276 foreach my $ext (@exts) {
1277 $mimemap{$ext} = $mime;
1283 $filename =~ /\.([^.]*)$/;
1284 return $mimemap{$1};
1287 sub mimetype_guess
{
1288 my $filename = shift;
1290 $filename =~ /\./ or return undef;
1292 if ($mimetypes_file) {
1293 my $file = $mimetypes_file;
1294 if ($file !~ m!^/!) { # if it is relative path
1295 # it is relative to project
1296 $file = "$projectroot/$project/$file";
1298 $mime = mimetype_guess_file
($filename, $file);
1300 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1306 my $filename = shift;
1309 my $mime = mimetype_guess
($filename);
1310 $mime and return $mime;
1314 return $default_blob_plain_mimetype unless $fd;
1317 return 'text/plain' .
1318 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1319 } elsif (! $filename) {
1320 return 'application/octet-stream';
1321 } elsif ($filename =~ m/\.png$/i) {
1323 } elsif ($filename =~ m/\.gif$/i) {
1325 } elsif ($filename =~ m/\.jpe?g$/i) {
1326 return 'image/jpeg';
1328 return 'application/octet-stream';
1332 ## ======================================================================
1333 ## functions printing HTML: header, footer, error page
1335 sub git_header_html
{
1336 my $status = shift || "200 OK";
1337 my $expires = shift;
1339 my $title = "$site_name git";
1340 if (defined $project) {
1341 $title .= " - $project";
1342 if (defined $action) {
1343 $title .= "/$action";
1344 if (defined $file_name) {
1345 $title .= " - " . esc_html
($file_name);
1346 if ($action eq "tree" && $file_name !~ m
|/$|) {
1353 # require explicit support from the UA if we are to send the page as
1354 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1355 # we have to do this because MSIE sometimes globs '*/*', pretending to
1356 # support xhtml+xml but choking when it gets what it asked for.
1357 if (defined $cgi->http('HTTP_ACCEPT') &&
1358 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1359 $cgi->Accept('application/xhtml+xml') != 0) {
1360 $content_type = 'application/xhtml+xml';
1362 $content_type = 'text/html';
1364 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1365 -status
=> $status, -expires
=> $expires);
1367 <?xml version="1.0" encoding="utf-8"?>
1368 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1369 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1370 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1371 <!-- git core binaries version $git_version -->
1373 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1374 <meta name="generator" content="gitweb/$version git/$git_version"/>
1375 <meta name="robots" content="index, nofollow"/>
1376 <title>$title</title>
1378 # print out each stylesheet that exist
1379 if (defined $stylesheet) {
1380 #provides backwards capability for those people who define style sheet in a config file
1381 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1383 foreach my $stylesheet (@stylesheets) {
1384 next unless $stylesheet;
1385 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1388 if (defined $project) {
1389 printf('<link rel="alternate" title="%s log" '.
1390 'href="%s" type="application/rss+xml"/>'."\n",
1391 esc_param
($project), href
(action
=>"rss"));
1393 printf('<link rel="alternate" title="%s projects list" '.
1394 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1395 $site_name, href
(project
=>undef, action
=>"project_index"));
1396 printf('<link rel="alternate" title="%s projects logs" '.
1397 'href="%s" type="text/x-opml"/>'."\n",
1398 $site_name, href
(project
=>undef, action
=>"opml"));
1400 if (defined $favicon) {
1401 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1407 if (-f
$site_header) {
1408 open (my $fd, $site_header);
1413 print "<div class=\"page_header\">\n" .
1414 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1415 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1417 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1418 if (defined $project) {
1419 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1420 if (defined $action) {
1424 if (!defined $searchtext) {
1428 if (defined $hash_base) {
1429 $search_hash = $hash_base;
1430 } elsif (defined $hash) {
1431 $search_hash = $hash;
1433 $search_hash = "HEAD";
1435 $cgi->param("a", "search");
1436 $cgi->param("h", $search_hash);
1437 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1438 "<div class=\"search\">\n" .
1439 $cgi->hidden(-name
=> "p") . "\n" .
1440 $cgi->hidden(-name
=> "a") . "\n" .
1441 $cgi->hidden(-name
=> "h") . "\n" .
1442 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1444 $cgi->end_form() . "\n";
1449 sub git_footer_html
{
1450 print "<div class=\"page_footer\">\n";
1451 if (defined $project) {
1452 my $descr = git_get_project_description
($project);
1453 if (defined $descr) {
1454 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1456 print $cgi->a({-href
=> href
(action
=>"rss"),
1457 -class => "rss_logo"}, "RSS") . "\n";
1459 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1460 -class => "rss_logo"}, "OPML") . " ";
1461 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1462 -class => "rss_logo"}, "TXT") . "\n";
1466 if (-f
$site_footer) {
1467 open (my $fd, $site_footer);
1477 my $status = shift || "403 Forbidden";
1478 my $error = shift || "Malformed query, file missing or permission denied";
1480 git_header_html
($status);
1482 <div class="page_body">
1492 ## ----------------------------------------------------------------------
1493 ## functions printing or outputting HTML: navigation
1495 sub git_print_page_nav
{
1496 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1497 $extra = '' if !defined $extra; # pager or formats
1499 my @navs = qw(summary shortlog log commit commitdiff tree);
1501 @navs = grep { $_ ne $suppress } @navs;
1504 my %arg = map { $_ => {action
=>$_} } @navs;
1505 if (defined $head) {
1506 for (qw(commit commitdiff)) {
1507 $arg{$_}{hash
} = $head;
1509 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1510 for (qw(shortlog log)) {
1511 $arg{$_}{hash
} = $head;
1515 $arg{tree
}{hash
} = $treehead if defined $treehead;
1516 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1518 print "<div class=\"page_nav\">\n" .
1520 map { $_ eq $current ?
1521 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1523 print "<br/>\n$extra<br/>\n" .
1527 sub format_paging_nav
{
1528 my ($action, $hash, $head, $page, $nrevs) = @_;
1532 if ($hash ne $head || $page) {
1533 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1535 $paging_nav .= "HEAD";
1539 $paging_nav .= " ⋅ " .
1540 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1541 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1543 $paging_nav .= " ⋅ prev";
1546 if ($nrevs >= (100 * ($page+1)-1)) {
1547 $paging_nav .= " ⋅ " .
1548 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1549 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1551 $paging_nav .= " ⋅ next";
1557 ## ......................................................................
1558 ## functions printing or outputting HTML: div
1560 sub git_print_header_div
{
1561 my ($action, $title, $hash, $hash_base) = @_;
1564 $args{action
} = $action;
1565 $args{hash
} = $hash if $hash;
1566 $args{hash_base
} = $hash_base if $hash_base;
1568 print "<div class=\"header\">\n" .
1569 $cgi->a({-href
=> href
(%args), -class => "title"},
1570 $title ?
$title : $action) .
1574 #sub git_print_authorship (\%) {
1575 sub git_print_authorship
{
1578 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1579 print "<div class=\"author_date\">" .
1580 esc_html
($co->{'author_name'}) .
1582 if ($ad{'hour_local'} < 6) {
1583 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1584 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1586 printf(" (%02d:%02d %s)",
1587 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1592 sub git_print_page_path
{
1597 if (!defined $name) {
1598 print "<div class=\"page_path\">/</div>\n";
1600 my @dirname = split '/', $name;
1601 my $basename = pop @dirname;
1604 print "<div class=\"page_path\">";
1605 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1606 -title
=> 'tree root'}, "[$project]");
1608 foreach my $dir (@dirname) {
1609 $fullname .= ($fullname ?
'/' : '') . $dir;
1610 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1612 -title
=> $fullname}, esc_html
($dir));
1615 if (defined $type && $type eq 'blob') {
1616 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1618 -title
=> $name}, esc_html
($basename));
1619 } elsif (defined $type && $type eq 'tree') {
1620 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1622 -title
=> $name}, esc_html
($basename));
1624 print esc_html
($basename);
1626 print "<br/></div>\n";
1630 # sub git_print_log (\@;%) {
1631 sub git_print_log
($;%) {
1635 if ($opts{'-remove_title'}) {
1636 # remove title, i.e. first line of log
1639 # remove leading empty lines
1640 while (defined $log->[0] && $log->[0] eq "") {
1647 foreach my $line (@
$log) {
1648 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1651 if (! $opts{'-remove_signoff'}) {
1652 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1655 # remove signoff lines
1662 # print only one empty line
1663 # do not print empty line after signoff
1665 next if ($empty || $signoff);
1671 print format_log_line_html
($line) . "<br/>\n";
1674 if ($opts{'-final_empty_line'}) {
1675 # end with single empty line
1676 print "<br/>\n" unless $empty;
1680 sub git_print_simplified_log
{
1682 my $remove_title = shift;
1685 -final_empty_line
=> 1,
1686 -remove_title
=> $remove_title);
1689 # print tree entry (row of git_tree), but without encompassing <tr> element
1690 sub git_print_tree_entry
{
1691 my ($t, $basedir, $hash_base, $have_blame) = @_;
1694 $base_key{hash_base
} = $hash_base if defined $hash_base;
1696 # The format of a table row is: mode list link. Where mode is
1697 # the mode of the entry, list is the name of the entry, an href,
1698 # and link is the action links of the entry.
1700 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1701 if ($t->{'type'} eq "blob") {
1702 print "<td class=\"list\">" .
1703 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1704 file_name
=>"$basedir$t->{'name'}", %base_key),
1705 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1706 print "<td class=\"link\">";
1708 print $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1709 file_name
=>"$basedir$t->{'name'}", %base_key)},
1712 if (defined $hash_base) {
1716 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1717 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1721 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1722 file_name
=>"$basedir$t->{'name'}")},
1726 } elsif ($t->{'type'} eq "tree") {
1727 print "<td class=\"list\">";
1728 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1729 file_name
=>"$basedir$t->{'name'}", %base_key)},
1730 esc_html
($t->{'name'}));
1732 print "<td class=\"link\">";
1733 if (defined $hash_base) {
1734 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1735 file_name
=>"$basedir$t->{'name'}")},
1742 ## ......................................................................
1743 ## functions printing large fragments of HTML
1745 sub git_difftree_body
{
1746 my ($difftree, $hash, $parent) = @_;
1748 print "<div class=\"list_head\">\n";
1749 if ($#{$difftree} > 10) {
1750 print(($#{$difftree} + 1) . " files changed:\n");
1754 print "<table class=\"diff_tree\">\n";
1757 foreach my $line (@
{$difftree}) {
1758 my %diff = parse_difftree_raw_line
($line);
1761 print "<tr class=\"dark\">\n";
1763 print "<tr class=\"light\">\n";
1767 my ($to_mode_oct, $to_mode_str, $to_file_type);
1768 my ($from_mode_oct, $from_mode_str, $from_file_type);
1769 if ($diff{'to_mode'} ne ('0' x
6)) {
1770 $to_mode_oct = oct $diff{'to_mode'};
1771 if (S_ISREG
($to_mode_oct)) { # only for regular file
1772 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1774 $to_file_type = file_type
($diff{'to_mode'});
1776 if ($diff{'from_mode'} ne ('0' x
6)) {
1777 $from_mode_oct = oct $diff{'from_mode'};
1778 if (S_ISREG
($to_mode_oct)) { # only for regular file
1779 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1781 $from_file_type = file_type
($diff{'from_mode'});
1784 if ($diff{'status'} eq "A") { # created
1785 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1786 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1787 $mode_chng .= "]</span>";
1789 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1790 hash_base
=>$hash, file_name
=>$diff{'file'}),
1791 -class => "list"}, esc_html
($diff{'file'}));
1793 print "<td>$mode_chng</td>\n";
1794 print "<td class=\"link\">";
1795 if ($action eq 'commitdiff') {
1798 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1802 } elsif ($diff{'status'} eq "D") { # deleted
1803 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1805 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1806 hash_base
=>$parent, file_name
=>$diff{'file'}),
1807 -class => "list"}, esc_html
($diff{'file'}));
1809 print "<td>$mode_chng</td>\n";
1810 print "<td class=\"link\">";
1811 if ($action eq 'commitdiff') {
1814 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1817 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1818 file_name
=>$diff{'file'})},
1820 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1821 file_name
=>$diff{'file'})},
1825 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1826 my $mode_chnge = "";
1827 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1828 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1829 if ($from_file_type != $to_file_type) {
1830 $mode_chnge .= " from $from_file_type to $to_file_type";
1832 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1833 if ($from_mode_str && $to_mode_str) {
1834 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1835 } elsif ($to_mode_str) {
1836 $mode_chnge .= " mode: $to_mode_str";
1839 $mode_chnge .= "]</span>\n";
1842 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1843 hash_base
=>$hash, file_name
=>$diff{'file'}),
1844 -class => "list"}, esc_html
($diff{'file'}));
1846 print "<td>$mode_chnge</td>\n";
1847 print "<td class=\"link\">";
1848 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1849 if ($action eq 'commitdiff') {
1852 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1854 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1855 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1856 hash_base
=>$hash, hash_parent_base
=>$parent,
1857 file_name
=>$diff{'file'})},
1862 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1863 file_name
=>$diff{'file'})},
1865 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1866 file_name
=>$diff{'file'})},
1870 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1871 my %status_name = ('R' => 'moved', 'C' => 'copied');
1872 my $nstatus = $status_name{$diff{'status'}};
1874 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1875 # mode also for directories, so we cannot use $to_mode_str
1876 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1879 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1880 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1881 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1882 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1883 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1884 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1885 -class => "list"}, esc_html
($diff{'from_file'})) .
1886 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1887 "<td class=\"link\">";
1888 if ($diff{'to_id'} ne $diff{'from_id'}) {
1889 if ($action eq 'commitdiff') {
1892 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1894 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1895 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1896 hash_base
=>$hash, hash_parent_base
=>$parent,
1897 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1902 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1903 file_name
=>$diff{'from_file'})},
1905 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1906 file_name
=>$diff{'from_file'})},
1910 } # we should not encounter Unmerged (U) or Unknown (X) status
1916 sub git_patchset_body
{
1917 my ($fd, $difftree, $hash, $hash_parent) = @_;
1921 my $patch_found = 0;
1924 print "<div class=\"patchset\">\n";
1927 while (my $patch_line = <$fd>) {
1930 if ($patch_line =~ m/^diff /) { # "git diff" header
1931 # beginning of patch (in patchset)
1933 # close previous patch
1934 print "</div>\n"; # class="patch"
1936 # first patch in patchset
1939 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1941 if (ref($difftree->[$patch_idx]) eq "HASH") {
1942 $diffinfo = $difftree->[$patch_idx];
1944 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1948 # for now, no extended header, hence we skip empty patches
1949 # companion to next LINE if $in_header;
1950 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1955 if ($diffinfo->{'status'} eq "A") { # added
1956 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1957 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1958 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1959 $diffinfo->{'to_id'}) . "(new)" .
1960 "</div>\n"; # class="diff_info"
1962 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1963 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1964 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1965 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1966 $diffinfo->{'from_id'}) . "(deleted)" .
1967 "</div>\n"; # class="diff_info"
1969 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1970 $diffinfo->{'status'} eq "C" || # copied
1971 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1972 print "<div class=\"diff_info\">" .
1973 file_type
($diffinfo->{'from_mode'}) . ":" .
1974 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1975 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1976 $diffinfo->{'from_id'}) .
1978 file_type
($diffinfo->{'to_mode'}) . ":" .
1979 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1980 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1981 $diffinfo->{'to_id'});
1982 print "</div>\n"; # class="diff_info"
1984 } else { # modified, mode changed, ...
1985 print "<div class=\"diff_info\">" .
1986 file_type
($diffinfo->{'from_mode'}) . ":" .
1987 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1988 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1989 $diffinfo->{'from_id'}) .
1991 file_type
($diffinfo->{'to_mode'}) . ":" .
1992 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1993 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1994 $diffinfo->{'to_id'});
1995 print "</div>\n"; # class="diff_info"
1998 #print "<div class=\"diff extended_header\">\n";
2001 } # start of patch in patchset
2004 if ($in_header && $patch_line =~ m/^---/) {
2005 #print "</div>\n"; # class="diff extended_header"
2008 my $file = $diffinfo->{'from_file'};
2009 $file ||= $diffinfo->{'file'};
2010 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2011 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2012 -class => "list"}, esc_html
($file));
2013 $patch_line =~ s
|a
/.*$|a/$file|g
;
2014 print "<div class=\"diff from_file\">$patch_line</div>\n";
2016 $patch_line = <$fd>;
2019 #$patch_line =~ m/^+++/;
2020 $file = $diffinfo->{'to_file'};
2021 $file ||= $diffinfo->{'file'};
2022 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2023 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2024 -class => "list"}, esc_html
($file));
2025 $patch_line =~ s
|b
/.*|b/$file|g
;
2026 print "<div class=\"diff to_file\">$patch_line</div>\n";
2030 next LINE
if $in_header;
2032 print format_diff_line
($patch_line);
2034 print "</div>\n" if $patch_found; # class="patch"
2036 print "</div>\n"; # class="patchset"
2039 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2041 sub git_shortlog_body
{
2042 # uses global variable $project
2043 my ($revlist, $from, $to, $refs, $extra) = @_;
2045 $from = 0 unless defined $from;
2046 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2048 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2050 for (my $i = $from; $i <= $to; $i++) {
2051 my $commit = $revlist->[$i];
2052 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2053 my $ref = format_ref_marker
($refs, $commit);
2054 my %co = parse_commit
($commit);
2056 print "<tr class=\"dark\">\n";
2058 print "<tr class=\"light\">\n";
2061 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2062 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2063 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2065 print format_subject_html
($co{'title'}, $co{'title_short'},
2066 href
(action
=>"commit", hash
=>$commit), $ref);
2068 "<td class=\"link\">" .
2069 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2070 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") . " | " .
2071 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2075 if (defined $extra) {
2077 "<td colspan=\"4\">$extra</td>\n" .
2083 sub git_history_body
{
2084 # Warning: assumes constant type (blob or tree) during history
2085 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2087 $from = 0 unless defined $from;
2088 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2090 print "<table class=\"history\" cellspacing=\"0\">\n";
2092 for (my $i = $from; $i <= $to; $i++) {
2093 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2098 my %co = parse_commit
($commit);
2103 my $ref = format_ref_marker
($refs, $commit);
2106 print "<tr class=\"dark\">\n";
2108 print "<tr class=\"light\">\n";
2111 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2112 # shortlog uses chop_str($co{'author_name'}, 10)
2113 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2115 # originally git_history used chop_str($co{'title'}, 50)
2116 print format_subject_html
($co{'title'}, $co{'title_short'},
2117 href
(action
=>"commit", hash
=>$commit), $ref);
2119 "<td class=\"link\">" .
2120 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2121 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2123 if ($ftype eq 'blob') {
2124 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2125 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2126 if (defined $blob_current && defined $blob_parent &&
2127 $blob_current ne $blob_parent) {
2129 $cgi->a({-href
=> href
(action
=>"blobdiff",
2130 hash
=>$blob_current, hash_parent
=>$blob_parent,
2131 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2132 file_name
=>$file_name)},
2139 if (defined $extra) {
2141 "<td colspan=\"4\">$extra</td>\n" .
2148 # uses global variable $project
2149 my ($taglist, $from, $to, $extra) = @_;
2150 $from = 0 unless defined $from;
2151 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2153 print "<table class=\"tags\" cellspacing=\"0\">\n";
2155 for (my $i = $from; $i <= $to; $i++) {
2156 my $entry = $taglist->[$i];
2158 my $comment_lines = $tag{'comment'};
2159 my $comment = shift @
$comment_lines;
2161 if (defined $comment) {
2162 $comment_short = chop_str
($comment, 30, 5);
2165 print "<tr class=\"dark\">\n";
2167 print "<tr class=\"light\">\n";
2170 print "<td><i>$tag{'age'}</i></td>\n" .
2172 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2173 -class => "list name"}, esc_html
($tag{'name'})) .
2176 if (defined $comment) {
2177 print format_subject_html
($comment, $comment_short,
2178 href
(action
=>"tag", hash
=>$tag{'id'}));
2181 "<td class=\"selflink\">";
2182 if ($tag{'type'} eq "tag") {
2183 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2188 "<td class=\"link\">" . " | " .
2189 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2190 if ($tag{'reftype'} eq "commit") {
2191 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2192 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2193 } elsif ($tag{'reftype'} eq "blob") {
2194 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2199 if (defined $extra) {
2201 "<td colspan=\"5\">$extra</td>\n" .
2207 sub git_heads_body
{
2208 # uses global variable $project
2209 my ($headlist, $head, $from, $to, $extra) = @_;
2210 $from = 0 unless defined $from;
2211 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2213 print "<table class=\"heads\" cellspacing=\"0\">\n";
2215 for (my $i = $from; $i <= $to; $i++) {
2216 my $entry = $headlist->[$i];
2218 my $curr = $tag{'id'} eq $head;
2220 print "<tr class=\"dark\">\n";
2222 print "<tr class=\"light\">\n";
2225 print "<td><i>$tag{'age'}</i></td>\n" .
2226 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
2227 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2228 -class => "list name"},esc_html
($tag{'name'})) .
2230 "<td class=\"link\">" .
2231 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2232 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2233 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2237 if (defined $extra) {
2239 "<td colspan=\"3\">$extra</td>\n" .
2245 ## ======================================================================
2246 ## ======================================================================
2249 sub git_project_list
{
2250 my $order = $cgi->param('o');
2251 if (defined $order && $order !~ m/project|descr|owner|age/) {
2252 die_error
(undef, "Unknown order parameter");
2255 my @list = git_get_projects_list
();
2258 die_error
(undef, "No projects found");
2260 foreach my $pr (@list) {
2261 my $head = git_get_head_hash
($pr->{'path'});
2262 if (!defined $head) {
2265 $git_dir = "$projectroot/$pr->{'path'}";
2266 my %co = parse_commit
($head);
2270 $pr->{'commit'} = \
%co;
2271 if (!defined $pr->{'descr'}) {
2272 my $descr = git_get_project_description
($pr->{'path'}) || "";
2273 $pr->{'descr'} = chop_str
($descr, 25, 5);
2275 if (!defined $pr->{'owner'}) {
2276 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2278 push @projects, $pr;
2282 if (-f
$home_text) {
2283 print "<div class=\"index_include\">\n";
2284 open (my $fd, $home_text);
2289 print "<table class=\"project_list\">\n" .
2291 $order ||= "project";
2292 if ($order eq "project") {
2293 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2294 print "<th>Project</th>\n";
2297 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2298 -class => "header"}, "Project") .
2301 if ($order eq "descr") {
2302 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2303 print "<th>Description</th>\n";
2306 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2307 -class => "header"}, "Description") .
2310 if ($order eq "owner") {
2311 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2312 print "<th>Owner</th>\n";
2315 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2316 -class => "header"}, "Owner") .
2319 if ($order eq "age") {
2320 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2321 print "<th>Last Change</th>\n";
2324 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2325 -class => "header"}, "Last Change") .
2328 print "<th></th>\n" .
2331 foreach my $pr (@projects) {
2333 print "<tr class=\"dark\">\n";
2335 print "<tr class=\"light\">\n";
2338 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2339 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2340 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2341 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2342 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2343 $pr->{'commit'}{'age_string'} . "</td>\n" .
2344 "<td class=\"link\">" .
2345 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2346 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2347 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2348 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2356 sub git_project_index
{
2357 my @projects = git_get_projects_list
();
2360 -type
=> 'text/plain',
2361 -charset
=> 'utf-8',
2362 -content_disposition
=> 'inline; filename="index.aux"');
2364 foreach my $pr (@projects) {
2365 if (!exists $pr->{'owner'}) {
2366 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2369 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2370 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2371 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2372 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2376 print "$path $owner\n";
2381 my $descr = git_get_project_description
($project) || "none";
2382 my $head = git_get_head_hash
($project);
2383 my %co = parse_commit
($head);
2384 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2386 my $owner = git_get_project_owner
($project);
2388 my ($reflist, $refs) = git_get_refs_list
();
2392 foreach my $ref (@
$reflist) {
2393 if ($ref->{'name'} =~ s!^heads/!!) {
2394 push @headlist, $ref;
2396 $ref->{'name'} =~ s!^tags/!!;
2397 push @taglist, $ref;
2402 git_print_page_nav
('summary','', $head);
2404 print "<div class=\"title\"> </div>\n";
2405 print "<table cellspacing=\"0\">\n" .
2406 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2407 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2408 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2409 # use per project git URL list in $projectroot/$project/cloneurl
2410 # or make project git URL from git base URL and project name
2411 my $url_tag = "URL";
2412 my @url_list = git_get_project_url_list
($project);
2413 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2414 foreach my $git_url (@url_list) {
2415 next unless $git_url;
2416 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2421 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2422 git_get_head_hash
($project)
2423 or die_error
(undef, "Open git-rev-list failed");
2424 my @revlist = map { chomp; $_ } <$fd>;
2426 git_print_header_div
('shortlog');
2427 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2428 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2431 git_print_header_div
('tags');
2432 git_tags_body
(\
@taglist, 0, 15,
2433 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2437 git_print_header_div
('heads');
2438 git_heads_body
(\
@headlist, $head, 0, 15,
2439 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2446 my $head = git_get_head_hash
($project);
2448 git_print_page_nav
('','', $head,undef,$head);
2449 my %tag = parse_tag
($hash);
2450 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2451 print "<div class=\"title_text\">\n" .
2452 "<table cellspacing=\"0\">\n" .
2454 "<td>object</td>\n" .
2455 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2456 $tag{'object'}) . "</td>\n" .
2457 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2458 $tag{'type'}) . "</td>\n" .
2460 if (defined($tag{'author'})) {
2461 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2462 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2463 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2464 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2467 print "</table>\n\n" .
2469 print "<div class=\"page_body\">";
2470 my $comment = $tag{'comment'};
2471 foreach my $line (@
$comment) {
2472 print esc_html
($line) . "<br/>\n";
2482 my ($have_blame) = gitweb_check_feature
('blame');
2484 die_error
('403 Permission denied', "Permission denied");
2486 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2487 $hash_base ||= git_get_head_hash
($project);
2488 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2489 my %co = parse_commit
($hash_base)
2490 or die_error
(undef, "Reading commit failed");
2491 if (!defined $hash) {
2492 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2493 or die_error
(undef, "Error looking up file");
2495 $ftype = git_get_type
($hash);
2496 if ($ftype !~ "blob") {
2497 die_error
("400 Bad Request", "Object is not a blob");
2499 open ($fd, "-|", git_cmd
(), "blame", '-l', '--', $file_name, $hash_base)
2500 or die_error
(undef, "Open git-blame failed");
2503 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2506 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2509 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2511 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2512 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2513 git_print_page_path
($file_name, $ftype, $hash_base);
2514 my @rev_color = (qw(light2 dark2));
2515 my $num_colors = scalar(@rev_color);
2516 my $current_color = 0;
2519 <div class="page_body">
2520 <table class="blame">
2521 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2524 my ($full_rev, $author, $date, $lineno, $data) =
2525 /^([0-9a-f]{40}).*?\s\((.*?)\s+([-\d]+ [:\d]+ [-+\d]+)\s+(\d+)\)\s(.*)/;
2526 my $rev = substr($full_rev, 0, 8);
2529 if (!defined $last_rev) {
2530 $last_rev = $full_rev;
2532 } elsif ($last_rev ne $full_rev) {
2533 $last_rev = $full_rev;
2534 $current_color = ++$current_color % $num_colors;
2537 print "<tr class=\"$rev_color[$current_color]\">\n";
2538 print "<td class=\"sha1\"";
2539 if ($print_c8 == 1) {
2540 print " title=\"$author, $date\"";
2543 if ($print_c8 == 1) {
2544 print $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2548 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2549 esc_html
($lineno) . "</a></td>\n";
2550 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2556 or print "Reading blob failed\n";
2563 my ($have_blame) = gitweb_check_feature
('blame');
2565 die_error
('403 Permission denied', "Permission denied");
2567 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2568 $hash_base ||= git_get_head_hash
($project);
2569 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2570 my %co = parse_commit
($hash_base)
2571 or die_error
(undef, "Reading commit failed");
2572 if (!defined $hash) {
2573 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2574 or die_error
(undef, "Error lookup file");
2576 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2577 or die_error
(undef, "Open git-annotate failed");
2580 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2583 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2586 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2588 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2589 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2590 git_print_page_path
($file_name, 'blob', $hash_base);
2591 print "<div class=\"page_body\">\n";
2593 <table class="blame">
2602 my @line_class = (qw(light dark));
2603 my $line_class_len = scalar (@line_class);
2604 my $line_class_num = $#line_class;
2605 while (my $line = <$fd>) {
2617 $line_class_num = ($line_class_num + 1) % $line_class_len;
2619 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2626 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2629 $short_rev = substr ($long_rev, 0, 8);
2630 $age = time () - $time;
2631 $age_str = age_string
($age);
2632 $age_str =~ s/ / /g;
2633 $age_class = age_class
($age);
2634 $author = esc_html
($author);
2635 $author =~ s/ / /g;
2637 $data = untabify
($data);
2638 $data = esc_html
($data);
2641 <tr class="$line_class[$line_class_num]">
2642 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2643 <td class="$age_class">$age_str</td>
2645 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2646 <td class="pre">$data</td>
2649 } # while (my $line = <$fd>)
2650 print "</table>\n\n";
2652 or print "Reading blob failed.\n";
2658 my $head = git_get_head_hash
($project);
2660 git_print_page_nav
('','', $head,undef,$head);
2661 git_print_header_div
('summary', $project);
2663 my ($taglist) = git_get_refs_list
("tags");
2665 git_tags_body
($taglist);
2671 my $head = git_get_head_hash
($project);
2673 git_print_page_nav
('','', $head,undef,$head);
2674 git_print_header_div
('summary', $project);
2676 my ($headlist) = git_get_refs_list
("heads");
2678 git_heads_body
($headlist, $head);
2683 sub git_blob_plain
{
2686 if (!defined $hash) {
2687 if (defined $file_name) {
2688 my $base = $hash_base || git_get_head_hash
($project);
2689 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2690 or die_error
(undef, "Error lookup file");
2692 die_error
(undef, "No file name defined");
2694 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2695 # blobs defined by non-textual hash id's can be cached
2700 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2701 or die_error
(undef, "Couldn't cat $file_name, $hash");
2703 $type ||= blob_mimetype
($fd, $file_name);
2705 # save as filename, even when no $file_name is given
2706 my $save_as = "$hash";
2707 if (defined $file_name) {
2708 $save_as = $file_name;
2709 } elsif ($type =~ m/^text\//) {
2716 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2718 binmode STDOUT
, ':raw';
2720 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2728 if (!defined $hash) {
2729 if (defined $file_name) {
2730 my $base = $hash_base || git_get_head_hash
($project);
2731 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2732 or die_error
(undef, "Error lookup file");
2734 die_error
(undef, "No file name defined");
2736 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2737 # blobs defined by non-textual hash id's can be cached
2741 my ($have_blame) = gitweb_check_feature
('blame');
2742 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2743 or die_error
(undef, "Couldn't cat $file_name, $hash");
2744 my $mimetype = blob_mimetype
($fd, $file_name);
2745 if ($mimetype !~ m/^text\//) {
2747 return git_blob_plain
($mimetype);
2749 git_header_html
(undef, $expires);
2750 my $formats_nav = '';
2751 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2752 if (defined $file_name) {
2755 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2756 hash
=>$hash, file_name
=>$file_name)},
2761 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2762 hash
=>$hash, file_name
=>$file_name)},
2765 $cgi->a({-href
=> href
(action
=>"blob_plain",
2766 hash
=>$hash, file_name
=>$file_name)},
2769 $cgi->a({-href
=> href
(action
=>"blob",
2770 hash_base
=>"HEAD", file_name
=>$file_name)},
2774 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2776 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2777 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2779 print "<div class=\"page_nav\">\n" .
2780 "<br/><br/></div>\n" .
2781 "<div class=\"title\">$hash</div>\n";
2783 git_print_page_path
($file_name, "blob", $hash_base);
2784 print "<div class=\"page_body\">\n";
2786 while (my $line = <$fd>) {
2789 $line = untabify
($line);
2790 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2791 $nr, $nr, $nr, esc_html
($line);
2794 or print "Reading blob failed.\n";
2800 my $have_snapshot = gitweb_have_snapshot
();
2802 if (!defined $hash_base) {
2803 $hash_base = "HEAD";
2805 if (!defined $hash) {
2806 if (defined $file_name) {
2807 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
2813 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2814 or die_error
(undef, "Open git-ls-tree failed");
2815 my @entries = map { chomp; $_ } <$fd>;
2816 close $fd or die_error
(undef, "Reading tree failed");
2819 my $refs = git_get_references
();
2820 my $ref = format_ref_marker
($refs, $hash_base);
2823 my ($have_blame) = gitweb_check_feature
('blame');
2824 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2826 if (defined $file_name) {
2828 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2829 hash
=>$hash, file_name
=>$file_name)},
2831 $cgi->a({-href
=> href
(action
=>"tree",
2832 hash_base
=>"HEAD", file_name
=>$file_name)},
2835 if ($have_snapshot) {
2836 # FIXME: Should be available when we have no hash base as well.
2838 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2841 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2842 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2845 print "<div class=\"page_nav\">\n";
2846 print "<br/><br/></div>\n";
2847 print "<div class=\"title\">$hash</div>\n";
2849 if (defined $file_name) {
2850 $base = esc_html
("$file_name/");
2852 git_print_page_path
($file_name, 'tree', $hash_base);
2853 print "<div class=\"page_body\">\n";
2854 print "<table cellspacing=\"0\">\n";
2856 foreach my $line (@entries) {
2857 my %t = parse_ls_tree_line
($line, -z
=> 1);
2860 print "<tr class=\"dark\">\n";
2862 print "<tr class=\"light\">\n";
2866 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2870 print "</table>\n" .
2876 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2877 my $have_snapshot = (defined $ctype && defined $suffix);
2878 if (!$have_snapshot) {
2879 die_error
('403 Permission denied', "Permission denied");
2882 if (!defined $hash) {
2883 $hash = git_get_head_hash
($project);
2886 my $filename = basename
($project) . "-$hash.tar.$suffix";
2889 -type
=> 'application/x-tar',
2890 -content_encoding
=> $ctype,
2891 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
2892 -status
=> '200 OK');
2894 my $git_command = git_cmd_str
();
2895 open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
2896 die_error
(undef, "Execute git-tar-tree failed.");
2897 binmode STDOUT
, ':raw';
2899 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2905 my $head = git_get_head_hash
($project);
2906 if (!defined $hash) {
2909 if (!defined $page) {
2912 my $refs = git_get_references
();
2914 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2915 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2916 or die_error
(undef, "Open git-rev-list failed");
2917 my @revlist = map { chomp; $_ } <$fd>;
2920 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2923 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2926 my %co = parse_commit
($hash);
2928 git_print_header_div
('summary', $project);
2929 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2931 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2932 my $commit = $revlist[$i];
2933 my $ref = format_ref_marker
($refs, $commit);
2934 my %co = parse_commit
($commit);
2936 my %ad = parse_date
($co{'author_epoch'});
2937 git_print_header_div
('commit',
2938 "<span class=\"age\">$co{'age_string'}</span>" .
2939 esc_html
($co{'title'}) . $ref,
2941 print "<div class=\"title_text\">\n" .
2942 "<div class=\"log_link\">\n" .
2943 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2945 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2947 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
2950 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2953 print "<div class=\"log_body\">\n";
2954 git_print_simplified_log
($co{'comment'});
2961 my %co = parse_commit
($hash);
2963 die_error
(undef, "Unknown commit object");
2965 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2966 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2968 my $parent = $co{'parent'};
2969 if (!defined $parent) {
2972 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
2973 or die_error
(undef, "Open git-diff-tree failed");
2974 my @difftree = map { chomp; $_ } <$fd>;
2975 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2977 # non-textual hash id's can be cached
2979 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2982 my $refs = git_get_references
();
2983 my $ref = format_ref_marker
($refs, $co{'id'});
2985 my $have_snapshot = gitweb_have_snapshot
();
2988 if (defined $file_name && defined $co{'parent'}) {
2990 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2993 if (defined $co{'parent'}) {
2995 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash)}, "shortlog"),
2996 $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash)}, "log");
2998 git_header_html
(undef, $expires);
2999 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
3000 $hash, $co{'tree'}, $hash,
3001 join (' | ', @views_nav));
3003 if (defined $co{'parent'}) {
3004 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3006 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3008 print "<div class=\"title_text\">\n" .
3009 "<table cellspacing=\"0\">\n";
3010 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3012 "<td></td><td> $ad{'rfc2822'}";
3013 if ($ad{'hour_local'} < 6) {
3014 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3015 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3017 printf(" (%02d:%02d %s)",
3018 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3022 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3023 print "<tr><td></td><td> $cd{'rfc2822'}" .
3024 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3026 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3029 "<td class=\"sha1\">" .
3030 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3031 class => "list"}, $co{'tree'}) .
3033 "<td class=\"link\">" .
3034 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3036 if ($have_snapshot) {
3038 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3042 my $parents = $co{'parents'};
3043 foreach my $par (@
$parents) {
3046 "<td class=\"sha1\">" .
3047 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3048 class => "list"}, $par) .
3050 "<td class=\"link\">" .
3051 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3053 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3060 print "<div class=\"page_body\">\n";
3061 git_print_log
($co{'comment'});
3064 git_difftree_body
(\
@difftree, $hash, $parent);
3070 my $format = shift || 'html';
3077 # preparing $fd and %diffinfo for git_patchset_body
3079 if (defined $hash_base && defined $hash_parent_base) {
3080 if (defined $file_name) {
3082 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3084 or die_error
(undef, "Open git-diff-tree failed");
3085 @difftree = map { chomp; $_ } <$fd>;
3087 or die_error
(undef, "Reading git-diff-tree failed");
3089 or die_error
('404 Not Found', "Blob diff not found");
3091 } elsif (defined $hash &&
3092 $hash =~ /[0-9a-fA-F]{40}/) {
3093 # try to find filename from $hash
3095 # read filtered raw output
3096 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3097 or die_error
(undef, "Open git-diff-tree failed");
3099 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3101 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3102 map { chomp; $_ } <$fd>;
3104 or die_error
(undef, "Reading git-diff-tree failed");
3106 or die_error
('404 Not Found', "Blob diff not found");
3109 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3112 if (@difftree > 1) {
3113 die_error
('404 Not Found', "Ambiguous blob diff specification");
3116 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3117 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3118 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3120 $hash_parent ||= $diffinfo{'from_id'};
3121 $hash ||= $diffinfo{'to_id'};
3123 # non-textual hash id's can be cached
3124 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3125 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3130 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3131 '-p', $hash_parent_base, $hash_base,
3133 or die_error
(undef, "Open git-diff-tree failed");
3136 # old/legacy style URI
3137 if (!%diffinfo && # if new style URI failed
3138 defined $hash && defined $hash_parent) {
3139 # fake git-diff-tree raw output
3140 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3141 $diffinfo{'from_id'} = $hash_parent;
3142 $diffinfo{'to_id'} = $hash;
3143 if (defined $file_name) {
3144 if (defined $file_parent) {
3145 $diffinfo{'status'} = '2';
3146 $diffinfo{'from_file'} = $file_parent;
3147 $diffinfo{'to_file'} = $file_name;
3148 } else { # assume not renamed
3149 $diffinfo{'status'} = '1';
3150 $diffinfo{'from_file'} = $file_name;
3151 $diffinfo{'to_file'} = $file_name;
3153 } else { # no filename given
3154 $diffinfo{'status'} = '2';
3155 $diffinfo{'from_file'} = $hash_parent;
3156 $diffinfo{'to_file'} = $hash;
3159 # non-textual hash id's can be cached
3160 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3161 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3166 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3167 or die_error
(undef, "Open git-diff failed");
3169 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3174 if ($format eq 'html') {
3176 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3177 hash
=>$hash, hash_parent
=>$hash_parent,
3178 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3179 file_name
=>$file_name, file_parent
=>$file_parent)},
3181 git_header_html
(undef, $expires);
3182 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3183 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3184 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3186 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3187 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3189 if (defined $file_name) {
3190 git_print_page_path
($file_name, "blob", $hash_base);
3192 print "<div class=\"page_path\"></div>\n";
3195 } elsif ($format eq 'plain') {
3197 -type
=> 'text/plain',
3198 -charset
=> 'utf-8',
3199 -expires
=> $expires,
3200 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3202 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3205 die_error
(undef, "Unknown blobdiff format");
3209 if ($format eq 'html') {
3210 print "<div class=\"page_body\">\n";
3212 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3215 print "</div>\n"; # class="page_body"
3219 while (my $line = <$fd>) {
3220 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3221 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3225 last if $line =~ m!^\+\+\+!;
3233 sub git_blobdiff_plain
{
3234 git_blobdiff
('plain');
3237 sub git_commitdiff
{
3238 my $format = shift || 'html';
3239 my %co = parse_commit
($hash);
3241 die_error
(undef, "Unknown commit object");
3243 if (!defined $hash_parent) {
3244 $hash_parent = $co{'parent'} || '--root';
3250 if ($format eq 'html') {
3251 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3252 "--patch-with-raw", "--full-index", $hash_parent, $hash
3253 or die_error
(undef, "Open git-diff-tree failed");
3255 while (chomp(my $line = <$fd>)) {
3256 # empty line ends raw part of diff-tree output
3258 push @difftree, $line;
3261 } elsif ($format eq 'plain') {
3262 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3263 '-p', $hash_parent, $hash
3264 or die_error
(undef, "Open git-diff-tree failed");
3267 die_error
(undef, "Unknown commitdiff format");
3270 # non-textual hash id's can be cached
3272 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3276 # write commit message
3277 if ($format eq 'html') {
3278 my $refs = git_get_references
();
3279 my $ref = format_ref_marker
($refs, $co{'id'});
3281 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3282 hash
=>$hash, hash_parent
=>$hash_parent)},
3285 git_header_html
(undef, $expires);
3286 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3287 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3288 git_print_authorship
(\
%co);
3289 print "<div class=\"page_body\">\n";
3290 print "<div class=\"log\">\n";
3291 git_print_simplified_log
($co{'comment'}, 1); # skip title
3292 print "</div>\n"; # class="log"
3294 } elsif ($format eq 'plain') {
3295 my $refs = git_get_references
("tags");
3296 my $tagname = git_get_rev_name_tags
($hash);
3297 my $filename = basename
($project) . "-$hash.patch";
3300 -type
=> 'text/plain',
3301 -charset
=> 'utf-8',
3302 -expires
=> $expires,
3303 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3304 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3307 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3308 Subject: $co{'title'}
3310 print "X-Git-Tag: $tagname\n" if $tagname;
3311 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3313 foreach my $line (@
{$co{'comment'}}) {
3320 if ($format eq 'html') {
3321 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3324 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3326 print "</div>\n"; # class="page_body"
3329 } elsif ($format eq 'plain') {
3333 or print "Reading git-diff-tree failed\n";
3337 sub git_commitdiff_plain
{
3338 git_commitdiff
('plain');
3342 if (!defined $hash_base) {
3343 $hash_base = git_get_head_hash
($project);
3345 if (!defined $page) {
3349 my %co = parse_commit
($hash_base);
3351 die_error
(undef, "Unknown commit object");
3354 my $refs = git_get_references
();
3355 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3357 if (!defined $hash && defined $file_name) {
3358 $hash = git_get_hash_by_path
($hash_base, $file_name);
3360 if (defined $hash) {
3361 $ftype = git_get_type
($hash);
3365 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3366 or die_error
(undef, "Open git-rev-list-failed");
3367 my @revlist = map { chomp; $_ } <$fd>;
3369 or die_error
(undef, "Reading git-rev-list failed");
3371 my $paging_nav = '';
3374 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3375 file_name
=>$file_name)},
3377 $paging_nav .= " ⋅ " .
3378 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3379 file_name
=>$file_name, page
=>$page-1),
3380 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3382 $paging_nav .= "first";
3383 $paging_nav .= " ⋅ prev";
3385 if ($#revlist >= (100 * ($page+1)-1)) {
3386 $paging_nav .= " ⋅ " .
3387 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3388 file_name
=>$file_name, page
=>$page+1),
3389 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3391 $paging_nav .= " ⋅ next";
3394 if ($#revlist >= (100 * ($page+1)-1)) {
3396 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3397 file_name
=>$file_name, page
=>$page+1),
3398 -title
=> "Alt-n"}, "next");
3402 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3403 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3404 git_print_page_path
($file_name, $ftype, $hash_base);
3406 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3407 $refs, $hash_base, $ftype, $next_link);
3413 if (!defined $searchtext) {
3414 die_error
(undef, "Text field empty");
3416 if (!defined $hash) {
3417 $hash = git_get_head_hash
($project);
3419 my %co = parse_commit
($hash);
3421 die_error
(undef, "Unknown commit object");
3424 my $commit_search = 1;
3425 my $author_search = 0;
3426 my $committer_search = 0;
3427 my $pickaxe_search = 0;
3428 if ($searchtext =~ s/^author\\://i) {
3430 } elsif ($searchtext =~ s/^committer\\://i) {
3431 $committer_search = 1;
3432 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3434 $pickaxe_search = 1;
3436 # pickaxe may take all resources of your box and run for several minutes
3437 # with every query - so decide by yourself how public you make this feature
3438 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3439 if (!$have_pickaxe) {
3440 die_error
('403 Permission denied', "Permission denied");
3444 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3445 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3447 print "<table cellspacing=\"0\">\n";
3449 if ($commit_search) {
3451 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3452 while (my $commit_text = <$fd>) {
3453 if (!grep m/$searchtext/i, $commit_text) {
3456 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3459 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3462 my @commit_lines = split "\n", $commit_text;
3463 my %co = parse_commit
(undef, \
@commit_lines);
3468 print "<tr class=\"dark\">\n";
3470 print "<tr class=\"light\">\n";
3473 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3474 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3476 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3477 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3478 my $comment = $co{'comment'};
3479 foreach my $line (@
$comment) {
3480 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3481 my $lead = esc_html
($1) || "";
3482 $lead = chop_str
($lead, 30, 10);
3483 my $match = esc_html
($2) || "";
3484 my $trail = esc_html
($3) || "";
3485 $trail = chop_str
($trail, 30, 10);
3486 my $text = "$lead<span class=\"match\">$match</span>$trail";
3487 print chop_str
($text, 80, 5) . "<br/>\n";
3491 "<td class=\"link\">" .
3492 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3494 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3501 if ($pickaxe_search) {
3503 my $git_command = git_cmd_str
();
3504 open my $fd, "-|", "$git_command rev-list $hash | " .
3505 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3508 while (my $line = <$fd>) {
3509 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3512 $set{'from_id'} = $3;
3514 $set{'id'} = $set{'to_id'};
3515 if ($set{'id'} =~ m/0{40}/) {
3516 $set{'id'} = $set{'from_id'};
3518 if ($set{'id'} =~ m/0{40}/) {
3522 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3525 print "<tr class=\"dark\">\n";
3527 print "<tr class=\"light\">\n";
3530 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3531 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3533 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3534 -class => "list subject"},
3535 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3536 while (my $setref = shift @files) {
3538 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3539 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3541 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3545 "<td class=\"link\">" .
3546 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3548 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3552 %co = parse_commit
($1);
3562 my $head = git_get_head_hash
($project);
3563 if (!defined $hash) {
3566 if (!defined $page) {
3569 my $refs = git_get_references
();
3571 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3572 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3573 or die_error
(undef, "Open git-rev-list failed");
3574 my @revlist = map { chomp; $_ } <$fd>;
3577 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3579 if ($#revlist >= (100 * ($page+1)-1)) {
3581 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3582 -title
=> "Alt-n"}, "next");
3587 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3588 git_print_header_div
('summary', $project);
3590 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3595 ## ......................................................................
3596 ## feeds (RSS, OPML)
3599 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3600 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3601 or die_error
(undef, "Open git-rev-list failed");
3602 my @revlist = map { chomp; $_ } <$fd>;
3603 close $fd or die_error
(undef, "Reading git-rev-list failed");
3604 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3606 <?xml version="1.0" encoding="utf-8"?>
3607 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3609 <title>$project $my_uri $my_url</title>
3610 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3611 <description>$project log</description>
3612 <language>en</language>
3615 for (my $i = 0; $i <= $#revlist; $i++) {
3616 my $commit = $revlist[$i];
3617 my %co = parse_commit
($commit);
3618 # we read 150, we always show 30 and the ones more recent than 48 hours
3619 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3622 my %cd = parse_date
($co{'committer_epoch'});
3623 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3624 $co{'parent'}, $co{'id'}
3626 my @difftree = map { chomp; $_ } <$fd>;
3631 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3633 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3634 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3635 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3636 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3637 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3638 "<content:encoded>" .
3640 my $comment = $co{'comment'};
3641 foreach my $line (@
$comment) {
3642 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3643 print "$line<br/>\n";
3646 foreach my $line (@difftree) {
3647 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3650 my $file = esc_html
(unquote
($7));
3651 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3652 print "$file<br/>\n";
3655 "</content:encoded>\n" .
3658 print "</channel></rss>";
3662 my @list = git_get_projects_list
();
3664 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3666 <?xml version="1.0" encoding="utf-8"?>
3667 <opml version="1.0">
3669 <title>$site_name Git OPML Export</title>
3672 <outline text="git RSS feeds">
3675 foreach my $pr (@list) {
3677 my $head = git_get_head_hash
($proj{'path'});
3678 if (!defined $head) {
3681 $git_dir = "$projectroot/$proj{'path'}";
3682 my %co = parse_commit
($head);
3687 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3688 my $rss = "$my_url?p=$proj{'path'};a=rss";
3689 my $html = "$my_url?p=$proj{'path'};a=summary";
3690 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";