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 # html text to include at home page
45 our $home_text = "++GITWEB_HOMETEXT++";
47 # URI of default stylesheet
48 our $stylesheet = "++GITWEB_CSS++";
50 our $logo = "++GITWEB_LOGO++";
51 # URI of GIT favicon, assumed to be image/png type
52 our $favicon = "++GITWEB_FAVICON++";
54 # source of projects list
55 our $projects_list = "++GITWEB_LIST++";
57 # show repository only if this file exists
58 # (only effective if this variable evaluates to true)
59 our $export_ok = "++GITWEB_EXPORT_OK++";
61 # only allow viewing of repositories also shown on the overview page
62 our $strict_export = "++GITWEB_STRICT_EXPORT++";
64 # list of git base URLs used for URL to where fetch project from,
65 # i.e. full URL is "$git_base_url/$project"
66 our @git_base_url_list = ("++GITWEB_BASE_URL++");
68 # default blob_plain mimetype and default charset for text/plain blob
69 our $default_blob_plain_mimetype = 'text/plain';
70 our $default_text_plain_charset = undef;
72 # file to use for guessing MIME types before trying /etc/mime.types
73 # (relative to the current git repository)
74 our $mimetypes_file = undef;
76 # You define site-wide feature defaults here; override them with
77 # $GITWEB_CONFIG as necessary.
80 # 'sub' => feature-sub (subroutine),
81 # 'override' => allow-override (boolean),
82 # 'default' => [ default options...] (array reference)}
84 # if feature is overridable (it means that allow-override has true value,
85 # then feature-sub will be called with default options as parameters;
86 # return value of feature-sub indicates if to enable specified feature
88 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
90 # Enable the 'blame' blob view, showing the last commit that modified
91 # each line in the file. This can be very CPU-intensive.
93 # To enable system wide have in $GITWEB_CONFIG
94 # $feature{'blame'}{'default'} = [1];
95 # To have project specific config enable override in $GITWEB_CONFIG
96 # $feature{'blame'}{'override'} = 1;
97 # and in project config gitweb.blame = 0|1;
99 'sub' => \
&feature_blame
,
103 # Enable the 'snapshot' link, providing a compressed tarball of any
104 # tree. This can potentially generate high traffic if you have large
107 # To disable system wide have in $GITWEB_CONFIG
108 # $feature{'snapshot'}{'default'} = [undef];
109 # To have project specific config enable override in $GITWEB_CONFIG
110 # $feature{'blame'}{'override'} = 1;
111 # and in project config gitweb.snapshot = none|gzip|bzip2;
113 'sub' => \
&feature_snapshot
,
115 # => [content-encoding, suffix, program]
116 'default' => ['x-gzip', 'gz', 'gzip']},
118 # Enable the pickaxe search, which will list the commits that modified
119 # a given string in a file. This can be practical and quite faster
120 # alternative to 'blame', but still potentially CPU-intensive.
122 # To enable system wide have in $GITWEB_CONFIG
123 # $feature{'pickaxe'}{'default'} = [1];
124 # To have project specific config enable override in $GITWEB_CONFIG
125 # $feature{'pickaxe'}{'override'} = 1;
126 # and in project config gitweb.pickaxe = 0|1;
128 'sub' => \
&feature_pickaxe
,
132 # Make gitweb use an alternative format of the URLs which can be
133 # more readable and natural-looking: project name is embedded
134 # directly in the path and the query string contains other
135 # auxiliary information. All gitweb installations recognize
136 # URL in either format; this configures in which formats gitweb
139 # To enable system wide have in $GITWEB_CONFIG
140 # $feature{'pathinfo'}{'default'} = [1];
141 # Project specific override is not supported.
143 # Note that you will need to change the default location of CSS,
144 # favicon, logo and possibly other files to an absolute URL. Also,
145 # if gitweb.cgi serves as your indexfile, you will need to force
146 # $my_uri to contain the script name in your $GITWEB_CONFIG.
152 sub gitweb_check_feature
{
154 return unless exists $feature{$name};
155 my ($sub, $override, @defaults) = (
156 $feature{$name}{'sub'},
157 $feature{$name}{'override'},
158 @
{$feature{$name}{'default'}});
159 if (!$override) { return @defaults; }
161 warn "feature $name is not overrideable";
164 return $sub->(@defaults);
168 my ($val) = git_get_project_config
('blame', '--bool');
170 if ($val eq 'true') {
172 } elsif ($val eq 'false') {
179 sub feature_snapshot
{
180 my ($ctype, $suffix, $command) = @_;
182 my ($val) = git_get_project_config
('snapshot');
184 if ($val eq 'gzip') {
185 return ('x-gzip', 'gz', 'gzip');
186 } elsif ($val eq 'bzip2') {
187 return ('x-bzip2', 'bz2', 'bzip2');
188 } elsif ($val eq 'none') {
192 return ($ctype, $suffix, $command);
195 sub gitweb_have_snapshot
{
196 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
197 my $have_snapshot = (defined $ctype && defined $suffix);
199 return $have_snapshot;
202 sub feature_pickaxe
{
203 my ($val) = git_get_project_config
('pickaxe', '--bool');
205 if ($val eq 'true') {
207 } elsif ($val eq 'false') {
214 # rename detection options for git-diff and git-diff-tree
215 # - default is '-M', with the cost proportional to
216 # (number of removed files) * (number of new files).
217 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
218 # (number of changed files + number of removed files) * (number of new files)
219 # - even more costly is '-C', '--find-copies-harder' with cost
220 # (number of files in the original tree) * (number of new files)
221 # - one might want to include '-B' option, e.g. '-B', '-M'
222 our @diff_opts = ('-M'); # taken from git_commit
224 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
225 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
227 # version of the core git binary
228 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
230 $projects_list ||= $projectroot;
232 # ======================================================================
233 # input validation and dispatch
234 our $action = $cgi->param('a');
235 if (defined $action) {
236 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
237 die_error
(undef, "Invalid action parameter");
241 # parameters which are pathnames
242 our $project = $cgi->param('p');
243 if (defined $project) {
244 if (!validate_pathname
($project) ||
245 !(-d
"$projectroot/$project") ||
246 !(-e
"$projectroot/$project/HEAD") ||
247 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
248 ($strict_export && !project_in_list
($project))) {
250 die_error
(undef, "No such project");
254 our $file_name = $cgi->param('f');
255 if (defined $file_name) {
256 if (!validate_pathname
($file_name)) {
257 die_error
(undef, "Invalid file parameter");
261 our $file_parent = $cgi->param('fp');
262 if (defined $file_parent) {
263 if (!validate_pathname
($file_parent)) {
264 die_error
(undef, "Invalid file parent parameter");
268 # parameters which are refnames
269 our $hash = $cgi->param('h');
271 if (!validate_refname
($hash)) {
272 die_error
(undef, "Invalid hash parameter");
276 our $hash_parent = $cgi->param('hp');
277 if (defined $hash_parent) {
278 if (!validate_refname
($hash_parent)) {
279 die_error
(undef, "Invalid hash parent parameter");
283 our $hash_base = $cgi->param('hb');
284 if (defined $hash_base) {
285 if (!validate_refname
($hash_base)) {
286 die_error
(undef, "Invalid hash base parameter");
290 our $hash_parent_base = $cgi->param('hpb');
291 if (defined $hash_parent_base) {
292 if (!validate_refname
($hash_parent_base)) {
293 die_error
(undef, "Invalid hash parent base parameter");
298 our $page = $cgi->param('pg');
300 if ($page =~ m/[^0-9]/) {
301 die_error
(undef, "Invalid page parameter");
305 our $searchtext = $cgi->param('s');
306 if (defined $searchtext) {
307 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
308 die_error
(undef, "Invalid search parameter");
310 $searchtext = quotemeta $searchtext;
313 # now read PATH_INFO and use it as alternative to parameters
314 sub evaluate_path_info
{
315 return if defined $project;
316 my $path_info = $ENV{"PATH_INFO"};
317 return if !$path_info;
318 $path_info =~ s
,^/+,,;
319 return if !$path_info;
320 # find which part of PATH_INFO is project
321 $project = $path_info;
323 while ($project && !-e
"$projectroot/$project/HEAD") {
324 $project =~ s
,/*[^/]*$,,;
327 $project = validate_pathname
($project);
329 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
330 ($strict_export && !project_in_list
($project))) {
334 # do not change any parameters if an action is given using the query string
336 $path_info =~ s
,^$project/*,,;
337 my ($refname, $pathname) = split(/:/, $path_info, 2);
338 if (defined $pathname) {
339 # we got "project.git/branch:filename" or "project.git/branch:dir/"
340 # we could use git_get_type(branch:pathname), but it needs $git_dir
341 $pathname =~ s
,^/+,,;
342 if (!$pathname || substr($pathname, -1) eq "/") {
346 $action ||= "blob_plain";
348 $hash_base ||= validate_refname
($refname);
349 $file_name ||= validate_pathname
($pathname);
350 } elsif (defined $refname) {
351 # we got "project.git/branch"
352 $action ||= "shortlog";
353 $hash ||= validate_refname
($refname);
356 evaluate_path_info
();
358 # path to the current git repository
360 $git_dir = "$projectroot/$project" if $project;
364 "blame" => \
&git_blame2
,
365 "blobdiff" => \
&git_blobdiff
,
366 "blobdiff_plain" => \
&git_blobdiff_plain
,
367 "blob" => \
&git_blob
,
368 "blob_plain" => \
&git_blob_plain
,
369 "commitdiff" => \
&git_commitdiff
,
370 "commitdiff_plain" => \
&git_commitdiff_plain
,
371 "commit" => \
&git_commit
,
372 "heads" => \
&git_heads
,
373 "history" => \
&git_history
,
376 "search" => \
&git_search
,
377 "shortlog" => \
&git_shortlog
,
378 "summary" => \
&git_summary
,
380 "tags" => \
&git_tags
,
381 "tree" => \
&git_tree
,
382 "snapshot" => \
&git_snapshot
,
383 # those below don't need $project
384 "opml" => \
&git_opml
,
385 "project_list" => \
&git_project_list
,
386 "project_index" => \
&git_project_index
,
389 if (defined $project) {
390 $action ||= 'summary';
392 $action ||= 'project_list';
394 if (!defined($actions{$action})) {
395 die_error
(undef, "Unknown action");
397 if ($action !~ m/^(opml|project_list|project_index)$/ &&
399 die_error
(undef, "Project needed");
401 $actions{$action}->();
404 ## ======================================================================
419 hash_parent_base
=> "hpb",
424 my %mapping = @mapping;
426 $params{'project'} = $project unless exists $params{'project'};
428 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
430 # use PATH_INFO for project name
431 $href .= "/$params{'project'}" if defined $params{'project'};
432 delete $params{'project'};
434 # Summary just uses the project path URL
435 if (defined $params{'action'} && $params{'action'} eq 'summary') {
436 delete $params{'action'};
440 # now encode the parameters explicitly
442 for (my $i = 0; $i < @mapping; $i += 2) {
443 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
444 if (defined $params{$name}) {
445 push @result, $symbol . "=" . esc_param
($params{$name});
448 $href .= "?" . join(';', @result) if scalar @result;
454 ## ======================================================================
455 ## validation, quoting/unquoting and escaping
457 sub validate_pathname
{
458 my $input = shift || return undef;
460 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
461 # at the beginning, at the end, and between slashes.
462 # also this catches doubled slashes
463 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
467 if ($input =~ m!\0!) {
473 sub validate_refname
{
474 my $input = shift || return undef;
476 # textual hashes are O.K.
477 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
480 # it must be correct pathname
481 $input = validate_pathname
($input)
483 # restrictions on ref name according to git-check-ref-format
484 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
490 # quote unsafe chars, but keep the slash, even when it's not
491 # correct, but quoted slashes look too horrible in bookmarks
494 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
500 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
503 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
509 # replace invalid utf8 character with SUBSTITUTION sequence
512 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
513 $str = escapeHTML
($str);
514 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
518 # git may return quoted and escaped filenames
521 if ($str =~ m/^"(.*)"$/) {
523 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
528 # escape tabs (convert tabs to spaces)
532 while ((my $pos = index($line, "\t")) != -1) {
533 if (my $count = (8 - ($pos % 8))) {
534 my $spaces = ' ' x
$count;
535 $line =~ s/\t/$spaces/;
542 sub project_in_list
{
544 my @list = git_get_projects_list
();
545 return @list && scalar(grep { $_->{'path'} eq $project } @list);
548 ## ----------------------------------------------------------------------
549 ## HTML aware string manipulation
554 my $add_len = shift || 10;
556 # allow only $len chars, but don't cut a word if it would fit in $add_len
557 # if it doesn't fit, cut it if it's still longer than the dots we would add
558 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
561 if (length($tail) > 4) {
563 $body =~ s/&[^;]*$//; # remove chopped character entities
568 ## ----------------------------------------------------------------------
569 ## functions returning short strings
571 # CSS class for given age value (in seconds)
575 if ($age < 60*60*2) {
577 } elsif ($age < 60*60*24*2) {
584 # convert age in seconds to "nn units ago" string
589 if ($age > 60*60*24*365*2) {
590 $age_str = (int $age/60/60/24/365);
591 $age_str .= " years ago";
592 } elsif ($age > 60*60*24*(365/12)*2) {
593 $age_str = int $age/60/60/24/(365/12);
594 $age_str .= " months ago";
595 } elsif ($age > 60*60*24*7*2) {
596 $age_str = int $age/60/60/24/7;
597 $age_str .= " weeks ago";
598 } elsif ($age > 60*60*24*2) {
599 $age_str = int $age/60/60/24;
600 $age_str .= " days ago";
601 } elsif ($age > 60*60*2) {
602 $age_str = int $age/60/60;
603 $age_str .= " hours ago";
604 } elsif ($age > 60*2) {
605 $age_str = int $age/60;
606 $age_str .= " min ago";
609 $age_str .= " sec ago";
611 $age_str .= " right now";
616 # convert file mode in octal to symbolic file mode string
618 my $mode = oct shift;
620 if (S_ISDIR
($mode & S_IFMT
)) {
622 } elsif (S_ISLNK
($mode)) {
624 } elsif (S_ISREG
($mode)) {
625 # git cares only about the executable bit
626 if ($mode & S_IXUSR
) {
636 # convert file mode in octal to file type string
640 if ($mode !~ m/^[0-7]+$/) {
646 if (S_ISDIR
($mode & S_IFMT
)) {
648 } elsif (S_ISLNK
($mode)) {
650 } elsif (S_ISREG
($mode)) {
657 ## ----------------------------------------------------------------------
658 ## functions returning short HTML fragments, or transforming HTML fragments
659 ## which don't beling to other sections
661 # format line of commit message or tag comment
662 sub format_log_line_html
{
665 $line = esc_html
($line);
666 $line =~ s/ / /g;
667 if ($line =~ m/([0-9a-fA-F]{40})/) {
669 if (git_get_type
($hash_text) eq "commit") {
671 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
672 -class => "text"}, $hash_text);
673 $line =~ s/$hash_text/$link/;
679 # format marker of refs pointing to given object
680 sub format_ref_marker
{
681 my ($refs, $id) = @_;
684 if (defined $refs->{$id}) {
685 foreach my $ref (@
{$refs->{$id}}) {
686 my ($type, $name) = qw();
687 # e.g. tags/v2.6.11 or heads/next
688 if ($ref =~ m!^(.*?)s?/(.*)$!) {
696 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
701 return ' <span class="refs">'. $markers . '</span>';
707 # format, perhaps shortened and with markers, title line
708 sub format_subject_html
{
709 my ($long, $short, $href, $extra) = @_;
710 $extra = '' unless defined($extra);
712 if (length($short) < length($long)) {
713 return $cgi->a({-href
=> $href, -class => "list subject",
714 -title
=> decode
("utf8", $long, Encode
::FB_DEFAULT
)},
715 esc_html
($short) . $extra);
717 return $cgi->a({-href
=> $href, -class => "list subject"},
718 esc_html
($long) . $extra);
722 sub format_diff_line
{
724 my $char = substr($line, 0, 1);
730 $diff_class = " add";
731 } elsif ($char eq "-") {
732 $diff_class = " rem";
733 } elsif ($char eq "@") {
734 $diff_class = " chunk_header";
735 } elsif ($char eq "\\") {
736 $diff_class = " incomplete";
738 $line = untabify
($line);
739 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
742 ## ----------------------------------------------------------------------
743 ## git utility subroutines, invoking git commands
745 # returns path to the core git executable and the --git-dir parameter as list
747 return $GIT, '--git-dir='.$git_dir;
750 # returns path to the core git executable and the --git-dir parameter as string
752 return join(' ', git_cmd
());
755 # get HEAD ref of given project as hash
756 sub git_get_head_hash
{
758 my $o_git_dir = $git_dir;
760 $git_dir = "$projectroot/$project";
761 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
764 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
768 if (defined $o_git_dir) {
769 $git_dir = $o_git_dir;
774 # get type of given object
778 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
785 sub git_get_project_config
{
786 my ($key, $type) = @_;
788 return unless ($key);
789 $key =~ s/^gitweb\.//;
790 return if ($key =~ m/\W/);
792 my @x = (git_cmd
(), 'repo-config');
793 if (defined $type) { push @x, $type; }
795 push @x, "gitweb.$key";
801 # get hash of given path at given ref
802 sub git_get_hash_by_path
{
804 my $path = shift || return undef;
809 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
810 or die_error
(undef, "Open git-ls-tree failed");
812 close $fd or return undef;
814 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
815 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
816 if (defined $type && $type ne $2) {
823 ## ......................................................................
824 ## git utility functions, directly accessing git repository
826 sub git_get_project_description
{
829 open my $fd, "$projectroot/$path/description" or return undef;
836 sub git_get_project_url_list
{
839 open my $fd, "$projectroot/$path/cloneurl" or return;
840 my @git_project_url_list = map { chomp; $_ } <$fd>;
843 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
846 sub git_get_projects_list
{
849 if (-d
$projects_list) {
850 # search in directory
851 my $dir = $projects_list;
852 my $pfxlen = length("$dir");
855 follow_fast
=> 1, # follow symbolic links
856 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
858 # skip project-list toplevel, if we get it.
859 return if (m!^[/.]$!);
860 # only directories can be git repositories
861 return unless (-d
$_);
863 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
864 # we check related file in $projectroot
865 if (-e
"$projectroot/$subdir/HEAD" && (!$export_ok ||
866 -e
"$projectroot/$subdir/$export_ok")) {
867 push @list, { path
=> $subdir };
868 $File::Find
::prune
= 1;
873 } elsif (-f
$projects_list) {
874 # read from file(url-encoded):
875 # 'git%2Fgit.git Linus+Torvalds'
876 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
877 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
878 open my ($fd), $projects_list or return;
879 while (my $line = <$fd>) {
881 my ($path, $owner) = split ' ', $line;
882 $path = unescape
($path);
883 $owner = unescape
($owner);
884 if (!defined $path) {
887 if (-e
"$projectroot/$path/HEAD" && (!$export_ok ||
888 -e
"$projectroot/$path/$export_ok")) {
891 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
898 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
902 sub git_get_project_owner
{
906 return undef unless $project;
908 # read from file (url-encoded):
909 # 'git%2Fgit.git Linus+Torvalds'
910 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
911 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
912 if (-f
$projects_list) {
913 open (my $fd , $projects_list);
914 while (my $line = <$fd>) {
916 my ($pr, $ow) = split ' ', $line;
919 if ($pr eq $project) {
920 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
926 if (!defined $owner) {
927 $owner = get_file_owner
("$projectroot/$project");
933 sub git_get_references
{
934 my $type = shift || "";
936 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
937 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
938 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
941 while (my $line = <$fd>) {
943 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
944 if (defined $refs{$1}) {
945 push @
{$refs{$1}}, $2;
955 sub git_get_rev_name_tags
{
956 my $hash = shift || return undef;
958 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
960 my $name_rev = <$fd>;
963 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
966 # catches also '$hash undefined' output
971 ## ----------------------------------------------------------------------
972 ## parse to hash functions
976 my $tz = shift || "-0000";
979 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
980 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
981 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
982 $date{'hour'} = $hour;
983 $date{'minute'} = $min;
984 $date{'mday'} = $mday;
985 $date{'day'} = $days[$wday];
986 $date{'month'} = $months[$mon];
987 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
988 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
989 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
990 $mday, $months[$mon], $hour ,$min;
992 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
993 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
994 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
995 $date{'hour_local'} = $hour;
996 $date{'minute_local'} = $min;
997 $date{'tz_local'} = $tz;
1006 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1007 $tag{'id'} = $tag_id;
1008 while (my $line = <$fd>) {
1010 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1011 $tag{'object'} = $1;
1012 } elsif ($line =~ m/^type (.+)$/) {
1014 } elsif ($line =~ m/^tag (.+)$/) {
1016 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1017 $tag{'author'} = $1;
1020 } elsif ($line =~ m/--BEGIN/) {
1021 push @comment, $line;
1023 } elsif ($line eq "") {
1027 push @comment, <$fd>;
1028 $tag{'comment'} = \
@comment;
1029 close $fd or return;
1030 if (!defined $tag{'name'}) {
1037 my $commit_id = shift;
1038 my $commit_text = shift;
1043 if (defined $commit_text) {
1044 @commit_lines = @
$commit_text;
1047 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1049 @commit_lines = split '\n', <$fd>;
1050 close $fd or return;
1054 my $header = shift @commit_lines;
1055 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1058 ($co{'id'}, my @parents) = split ' ', $header;
1059 $co{'parents'} = \
@parents;
1060 $co{'parent'} = $parents[0];
1061 while (my $line = shift @commit_lines) {
1062 last if $line eq "\n";
1063 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1065 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1067 $co{'author_epoch'} = $2;
1068 $co{'author_tz'} = $3;
1069 if ($co{'author'} =~ m/^([^<]+) </) {
1070 $co{'author_name'} = $1;
1072 $co{'author_name'} = $co{'author'};
1074 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1075 $co{'committer'} = $1;
1076 $co{'committer_epoch'} = $2;
1077 $co{'committer_tz'} = $3;
1078 $co{'committer_name'} = $co{'committer'};
1079 $co{'committer_name'} =~ s/ <.*//;
1082 if (!defined $co{'tree'}) {
1086 foreach my $title (@commit_lines) {
1089 $co{'title'} = chop_str
($title, 80, 5);
1090 # remove leading stuff of merges to make the interesting part visible
1091 if (length($title) > 50) {
1092 $title =~ s/^Automatic //;
1093 $title =~ s/^merge (of|with) /Merge ... /i;
1094 if (length($title) > 50) {
1095 $title =~ s/(http|rsync):\/\///;
1097 if (length($title) > 50) {
1098 $title =~ s/(master|www|rsync)\.//;
1100 if (length($title) > 50) {
1101 $title =~ s/kernel.org:?//;
1103 if (length($title) > 50) {
1104 $title =~ s/\/pub\/scm//;
1107 $co{'title_short'} = chop_str
($title, 50, 5);
1111 # remove added spaces
1112 foreach my $line (@commit_lines) {
1115 $co{'comment'} = \
@commit_lines;
1117 my $age = time - $co{'committer_epoch'};
1119 $co{'age_string'} = age_string
($age);
1120 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1121 if ($age > 60*60*24*7*2) {
1122 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1123 $co{'age_string_age'} = $co{'age_string'};
1125 $co{'age_string_date'} = $co{'age_string'};
1126 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1131 # parse ref from ref_file, given by ref_id, with given type
1133 my $ref_file = shift;
1135 my $type = shift || git_get_type
($ref_id);
1138 $ref_item{'type'} = $type;
1139 $ref_item{'id'} = $ref_id;
1140 $ref_item{'epoch'} = 0;
1141 $ref_item{'age'} = "unknown";
1142 if ($type eq "tag") {
1143 my %tag = parse_tag
($ref_id);
1144 $ref_item{'comment'} = $tag{'comment'};
1145 if ($tag{'type'} eq "commit") {
1146 my %co = parse_commit
($tag{'object'});
1147 $ref_item{'epoch'} = $co{'committer_epoch'};
1148 $ref_item{'age'} = $co{'age_string'};
1149 } elsif (defined($tag{'epoch'})) {
1150 my $age = time - $tag{'epoch'};
1151 $ref_item{'epoch'} = $tag{'epoch'};
1152 $ref_item{'age'} = age_string
($age);
1154 $ref_item{'reftype'} = $tag{'type'};
1155 $ref_item{'name'} = $tag{'name'};
1156 $ref_item{'refid'} = $tag{'object'};
1157 } elsif ($type eq "commit"){
1158 my %co = parse_commit
($ref_id);
1159 $ref_item{'reftype'} = "commit";
1160 $ref_item{'name'} = $ref_file;
1161 $ref_item{'title'} = $co{'title'};
1162 $ref_item{'refid'} = $ref_id;
1163 $ref_item{'epoch'} = $co{'committer_epoch'};
1164 $ref_item{'age'} = $co{'age_string'};
1166 $ref_item{'reftype'} = $type;
1167 $ref_item{'name'} = $ref_file;
1168 $ref_item{'refid'} = $ref_id;
1174 # parse line of git-diff-tree "raw" output
1175 sub parse_difftree_raw_line
{
1179 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1180 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1181 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1182 $res{'from_mode'} = $1;
1183 $res{'to_mode'} = $2;
1184 $res{'from_id'} = $3;
1186 $res{'status'} = $5;
1187 $res{'similarity'} = $6;
1188 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1189 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1191 $res{'file'} = unquote
($7);
1194 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1195 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1196 $res{'commit'} = $1;
1199 return wantarray ?
%res : \
%res;
1202 # parse line of git-ls-tree output
1203 sub parse_ls_tree_line
($;%) {
1208 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1209 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1217 $res{'name'} = unquote
($4);
1220 return wantarray ?
%res : \
%res;
1223 ## ......................................................................
1224 ## parse to array of hashes functions
1226 sub git_get_refs_list
{
1227 my $type = shift || "";
1232 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1234 while (my $line = <$fd>) {
1236 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1237 if (defined $refs{$1}) {
1238 push @
{$refs{$1}}, $2;
1243 if (! $4) { # unpeeled, direct reference
1244 push @refs, { hash
=> $1, name
=> $3 }; # without type
1245 } elsif ($3 eq $refs[-1]{'name'}) {
1246 # most likely a tag is followed by its peeled
1247 # (deref) one, and when that happens we know the
1248 # previous one was of type 'tag'.
1249 $refs[-1]{'type'} = "tag";
1255 foreach my $ref (@refs) {
1256 my $ref_file = $ref->{'name'};
1257 my $ref_id = $ref->{'hash'};
1259 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1260 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1262 push @reflist, \
%ref_item;
1265 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1266 return (\
@reflist, \
%refs);
1269 ## ----------------------------------------------------------------------
1270 ## filesystem-related functions
1272 sub get_file_owner
{
1275 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1276 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1277 if (!defined $gcos) {
1281 $owner =~ s/[,;].*$//;
1282 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1285 ## ......................................................................
1286 ## mimetype related functions
1288 sub mimetype_guess_file
{
1289 my $filename = shift;
1290 my $mimemap = shift;
1291 -r
$mimemap or return undef;
1294 open(MIME
, $mimemap) or return undef;
1296 next if m/^#/; # skip comments
1297 my ($mime, $exts) = split(/\t+/);
1298 if (defined $exts) {
1299 my @exts = split(/\s+/, $exts);
1300 foreach my $ext (@exts) {
1301 $mimemap{$ext} = $mime;
1307 $filename =~ /\.([^.]*)$/;
1308 return $mimemap{$1};
1311 sub mimetype_guess
{
1312 my $filename = shift;
1314 $filename =~ /\./ or return undef;
1316 if ($mimetypes_file) {
1317 my $file = $mimetypes_file;
1318 if ($file !~ m!^/!) { # if it is relative path
1319 # it is relative to project
1320 $file = "$projectroot/$project/$file";
1322 $mime = mimetype_guess_file
($filename, $file);
1324 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1330 my $filename = shift;
1333 my $mime = mimetype_guess
($filename);
1334 $mime and return $mime;
1338 return $default_blob_plain_mimetype unless $fd;
1341 return 'text/plain' .
1342 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1343 } elsif (! $filename) {
1344 return 'application/octet-stream';
1345 } elsif ($filename =~ m/\.png$/i) {
1347 } elsif ($filename =~ m/\.gif$/i) {
1349 } elsif ($filename =~ m/\.jpe?g$/i) {
1350 return 'image/jpeg';
1352 return 'application/octet-stream';
1356 ## ======================================================================
1357 ## functions printing HTML: header, footer, error page
1359 sub git_header_html
{
1360 my $status = shift || "200 OK";
1361 my $expires = shift;
1363 my $title = "$site_name git";
1364 if (defined $project) {
1365 $title .= " - $project";
1366 if (defined $action) {
1367 $title .= "/$action";
1368 if (defined $file_name) {
1369 $title .= " - " . esc_html
($file_name);
1370 if ($action eq "tree" && $file_name !~ m
|/$|) {
1377 # require explicit support from the UA if we are to send the page as
1378 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1379 # we have to do this because MSIE sometimes globs '*/*', pretending to
1380 # support xhtml+xml but choking when it gets what it asked for.
1381 if (defined $cgi->http('HTTP_ACCEPT') &&
1382 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1383 $cgi->Accept('application/xhtml+xml') != 0) {
1384 $content_type = 'application/xhtml+xml';
1386 $content_type = 'text/html';
1388 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1389 -status
=> $status, -expires
=> $expires);
1391 <?xml version="1.0" encoding="utf-8"?>
1392 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1393 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1394 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1395 <!-- git core binaries version $git_version -->
1397 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1398 <meta name="generator" content="gitweb/$version git/$git_version"/>
1399 <meta name="robots" content="index, nofollow"/>
1400 <title>$title</title>
1401 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1403 if (defined $project) {
1404 printf('<link rel="alternate" title="%s log" '.
1405 'href="%s" type="application/rss+xml"/>'."\n",
1406 esc_param
($project), href
(action
=>"rss"));
1408 printf('<link rel="alternate" title="%s projects list" '.
1409 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1410 $site_name, href
(project
=>undef, action
=>"project_index"));
1411 printf('<link rel="alternate" title="%s projects logs" '.
1412 'href="%s" type="text/x-opml"/>'."\n",
1413 $site_name, href
(project
=>undef, action
=>"opml"));
1415 if (defined $favicon) {
1416 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1421 "<div class=\"page_header\">\n" .
1422 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1423 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1425 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1426 if (defined $project) {
1427 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1428 if (defined $action) {
1432 if (!defined $searchtext) {
1436 if (defined $hash_base) {
1437 $search_hash = $hash_base;
1438 } elsif (defined $hash) {
1439 $search_hash = $hash;
1441 $search_hash = "HEAD";
1443 $cgi->param("a", "search");
1444 $cgi->param("h", $search_hash);
1445 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1446 "<div class=\"search\">\n" .
1447 $cgi->hidden(-name
=> "p") . "\n" .
1448 $cgi->hidden(-name
=> "a") . "\n" .
1449 $cgi->hidden(-name
=> "h") . "\n" .
1450 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1452 $cgi->end_form() . "\n";
1457 sub git_footer_html
{
1458 print "<div class=\"page_footer\">\n";
1459 if (defined $project) {
1460 my $descr = git_get_project_description
($project);
1461 if (defined $descr) {
1462 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1464 print $cgi->a({-href
=> href
(action
=>"rss"),
1465 -class => "rss_logo"}, "RSS") . "\n";
1467 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1468 -class => "rss_logo"}, "OPML") . " ";
1469 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1470 -class => "rss_logo"}, "TXT") . "\n";
1478 my $status = shift || "403 Forbidden";
1479 my $error = shift || "Malformed query, file missing or permission denied";
1481 git_header_html
($status);
1483 <div class="page_body">
1493 ## ----------------------------------------------------------------------
1494 ## functions printing or outputting HTML: navigation
1496 sub git_print_page_nav
{
1497 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1498 $extra = '' if !defined $extra; # pager or formats
1500 my @navs = qw(summary shortlog log commit commitdiff tree);
1502 @navs = grep { $_ ne $suppress } @navs;
1505 my %arg = map { $_ => {action
=>$_} } @navs;
1506 if (defined $head) {
1507 for (qw(commit commitdiff)) {
1508 $arg{$_}{hash
} = $head;
1510 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1511 for (qw(shortlog log)) {
1512 $arg{$_}{hash
} = $head;
1516 $arg{tree
}{hash
} = $treehead if defined $treehead;
1517 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1519 print "<div class=\"page_nav\">\n" .
1521 map { $_ eq $current ?
1522 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1524 print "<br/>\n$extra<br/>\n" .
1528 sub format_paging_nav
{
1529 my ($action, $hash, $head, $page, $nrevs) = @_;
1533 if ($hash ne $head || $page) {
1534 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1536 $paging_nav .= "HEAD";
1540 $paging_nav .= " ⋅ " .
1541 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1542 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1544 $paging_nav .= " ⋅ prev";
1547 if ($nrevs >= (100 * ($page+1)-1)) {
1548 $paging_nav .= " ⋅ " .
1549 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1550 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1552 $paging_nav .= " ⋅ next";
1558 ## ......................................................................
1559 ## functions printing or outputting HTML: div
1561 sub git_print_header_div
{
1562 my ($action, $title, $hash, $hash_base) = @_;
1565 $args{action
} = $action;
1566 $args{hash
} = $hash if $hash;
1567 $args{hash_base
} = $hash_base if $hash_base;
1569 print "<div class=\"header\">\n" .
1570 $cgi->a({-href
=> href
(%args), -class => "title"},
1571 $title ?
$title : $action) .
1575 #sub git_print_authorship (\%) {
1576 sub git_print_authorship
{
1579 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1580 print "<div class=\"author_date\">" .
1581 esc_html
($co->{'author_name'}) .
1583 if ($ad{'hour_local'} < 6) {
1584 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1585 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1587 printf(" (%02d:%02d %s)",
1588 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1593 sub git_print_page_path
{
1598 if (!defined $name) {
1599 print "<div class=\"page_path\">/</div>\n";
1601 my @dirname = split '/', $name;
1602 my $basename = pop @dirname;
1605 print "<div class=\"page_path\">";
1606 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1607 -title
=> 'tree root'}, "[$project]");
1609 foreach my $dir (@dirname) {
1610 $fullname .= ($fullname ?
'/' : '') . $dir;
1611 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1613 -title
=> $fullname}, esc_html
($dir));
1616 if (defined $type && $type eq 'blob') {
1617 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1619 -title
=> $name}, esc_html
($basename));
1620 } elsif (defined $type && $type eq 'tree') {
1621 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1623 -title
=> $name}, esc_html
($basename));
1625 print esc_html
($basename);
1627 print "<br/></div>\n";
1631 # sub git_print_log (\@;%) {
1632 sub git_print_log
($;%) {
1636 if ($opts{'-remove_title'}) {
1637 # remove title, i.e. first line of log
1640 # remove leading empty lines
1641 while (defined $log->[0] && $log->[0] eq "") {
1648 foreach my $line (@
$log) {
1649 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1652 if (! $opts{'-remove_signoff'}) {
1653 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1656 # remove signoff lines
1663 # print only one empty line
1664 # do not print empty line after signoff
1666 next if ($empty || $signoff);
1672 print format_log_line_html
($line) . "<br/>\n";
1675 if ($opts{'-final_empty_line'}) {
1676 # end with single empty line
1677 print "<br/>\n" unless $empty;
1681 sub git_print_simplified_log
{
1683 my $remove_title = shift;
1686 -final_empty_line
=> 1,
1687 -remove_title
=> $remove_title);
1690 # print tree entry (row of git_tree), but without encompassing <tr> element
1691 sub git_print_tree_entry
{
1692 my ($t, $basedir, $hash_base, $have_blame) = @_;
1695 $base_key{hash_base
} = $hash_base if defined $hash_base;
1697 # The format of a table row is: mode list link. Where mode is
1698 # the mode of the entry, list is the name of the entry, an href,
1699 # and link is the action links of the entry.
1701 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1702 if ($t->{'type'} eq "blob") {
1703 print "<td class=\"list\">" .
1704 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1705 file_name
=>"$basedir$t->{'name'}", %base_key),
1706 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1707 print "<td class=\"link\">";
1709 print $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1710 file_name
=>"$basedir$t->{'name'}", %base_key)},
1713 if (defined $hash_base) {
1717 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1718 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1722 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1723 file_name
=>"$basedir$t->{'name'}")},
1727 } elsif ($t->{'type'} eq "tree") {
1728 print "<td class=\"list\">";
1729 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1730 file_name
=>"$basedir$t->{'name'}", %base_key)},
1731 esc_html
($t->{'name'}));
1733 print "<td class=\"link\">";
1734 if (defined $hash_base) {
1735 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1736 file_name
=>"$basedir$t->{'name'}")},
1743 ## ......................................................................
1744 ## functions printing large fragments of HTML
1746 sub git_difftree_body
{
1747 my ($difftree, $hash, $parent) = @_;
1749 print "<div class=\"list_head\">\n";
1750 if ($#{$difftree} > 10) {
1751 print(($#{$difftree} + 1) . " files changed:\n");
1755 print "<table class=\"diff_tree\">\n";
1758 foreach my $line (@
{$difftree}) {
1759 my %diff = parse_difftree_raw_line
($line);
1762 print "<tr class=\"dark\">\n";
1764 print "<tr class=\"light\">\n";
1768 my ($to_mode_oct, $to_mode_str, $to_file_type);
1769 my ($from_mode_oct, $from_mode_str, $from_file_type);
1770 if ($diff{'to_mode'} ne ('0' x
6)) {
1771 $to_mode_oct = oct $diff{'to_mode'};
1772 if (S_ISREG
($to_mode_oct)) { # only for regular file
1773 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1775 $to_file_type = file_type
($diff{'to_mode'});
1777 if ($diff{'from_mode'} ne ('0' x
6)) {
1778 $from_mode_oct = oct $diff{'from_mode'};
1779 if (S_ISREG
($to_mode_oct)) { # only for regular file
1780 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1782 $from_file_type = file_type
($diff{'from_mode'});
1785 if ($diff{'status'} eq "A") { # created
1786 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1787 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1788 $mode_chng .= "]</span>";
1790 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1791 hash_base
=>$hash, file_name
=>$diff{'file'}),
1792 -class => "list"}, esc_html
($diff{'file'}));
1794 print "<td>$mode_chng</td>\n";
1795 print "<td class=\"link\">";
1796 if ($action eq 'commitdiff') {
1799 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1803 } elsif ($diff{'status'} eq "D") { # deleted
1804 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1806 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1807 hash_base
=>$parent, file_name
=>$diff{'file'}),
1808 -class => "list"}, esc_html
($diff{'file'}));
1810 print "<td>$mode_chng</td>\n";
1811 print "<td class=\"link\">";
1812 if ($action eq 'commitdiff') {
1815 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1818 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1819 file_name
=>$diff{'file'})},
1821 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1822 file_name
=>$diff{'file'})},
1826 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1827 my $mode_chnge = "";
1828 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1829 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1830 if ($from_file_type != $to_file_type) {
1831 $mode_chnge .= " from $from_file_type to $to_file_type";
1833 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1834 if ($from_mode_str && $to_mode_str) {
1835 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1836 } elsif ($to_mode_str) {
1837 $mode_chnge .= " mode: $to_mode_str";
1840 $mode_chnge .= "]</span>\n";
1843 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1844 hash_base
=>$hash, file_name
=>$diff{'file'}),
1845 -class => "list"}, esc_html
($diff{'file'}));
1847 print "<td>$mode_chnge</td>\n";
1848 print "<td class=\"link\">";
1849 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1850 if ($action eq 'commitdiff') {
1853 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1855 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1856 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1857 hash_base
=>$hash, hash_parent_base
=>$parent,
1858 file_name
=>$diff{'file'})},
1863 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1864 file_name
=>$diff{'file'})},
1866 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1867 file_name
=>$diff{'file'})},
1871 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1872 my %status_name = ('R' => 'moved', 'C' => 'copied');
1873 my $nstatus = $status_name{$diff{'status'}};
1875 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1876 # mode also for directories, so we cannot use $to_mode_str
1877 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1880 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1881 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1882 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1883 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1884 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1885 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1886 -class => "list"}, esc_html
($diff{'from_file'})) .
1887 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1888 "<td class=\"link\">";
1889 if ($diff{'to_id'} ne $diff{'from_id'}) {
1890 if ($action eq 'commitdiff') {
1893 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1895 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1896 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1897 hash_base
=>$hash, hash_parent_base
=>$parent,
1898 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1903 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1904 file_name
=>$diff{'from_file'})},
1906 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1907 file_name
=>$diff{'from_file'})},
1911 } # we should not encounter Unmerged (U) or Unknown (X) status
1917 sub git_patchset_body
{
1918 my ($fd, $difftree, $hash, $hash_parent) = @_;
1922 my $patch_found = 0;
1925 print "<div class=\"patchset\">\n";
1928 while (my $patch_line = <$fd>) {
1931 if ($patch_line =~ m/^diff /) { # "git diff" header
1932 # beginning of patch (in patchset)
1934 # close previous patch
1935 print "</div>\n"; # class="patch"
1937 # first patch in patchset
1940 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1942 if (ref($difftree->[$patch_idx]) eq "HASH") {
1943 $diffinfo = $difftree->[$patch_idx];
1945 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1949 # for now, no extended header, hence we skip empty patches
1950 # companion to next LINE if $in_header;
1951 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1956 if ($diffinfo->{'status'} eq "A") { # added
1957 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1958 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1959 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1960 $diffinfo->{'to_id'}) . "(new)" .
1961 "</div>\n"; # class="diff_info"
1963 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1964 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1965 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1966 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1967 $diffinfo->{'from_id'}) . "(deleted)" .
1968 "</div>\n"; # class="diff_info"
1970 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1971 $diffinfo->{'status'} eq "C" || # copied
1972 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1973 print "<div class=\"diff_info\">" .
1974 file_type
($diffinfo->{'from_mode'}) . ":" .
1975 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1976 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1977 $diffinfo->{'from_id'}) .
1979 file_type
($diffinfo->{'to_mode'}) . ":" .
1980 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1981 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1982 $diffinfo->{'to_id'});
1983 print "</div>\n"; # class="diff_info"
1985 } else { # modified, mode changed, ...
1986 print "<div class=\"diff_info\">" .
1987 file_type
($diffinfo->{'from_mode'}) . ":" .
1988 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1989 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1990 $diffinfo->{'from_id'}) .
1992 file_type
($diffinfo->{'to_mode'}) . ":" .
1993 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1994 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1995 $diffinfo->{'to_id'});
1996 print "</div>\n"; # class="diff_info"
1999 #print "<div class=\"diff extended_header\">\n";
2002 } # start of patch in patchset
2005 if ($in_header && $patch_line =~ m/^---/) {
2006 #print "</div>\n"; # class="diff extended_header"
2009 my $file = $diffinfo->{'from_file'};
2010 $file ||= $diffinfo->{'file'};
2011 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2012 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2013 -class => "list"}, esc_html
($file));
2014 $patch_line =~ s
|a
/.*$|a/$file|g
;
2015 print "<div class=\"diff from_file\">$patch_line</div>\n";
2017 $patch_line = <$fd>;
2020 #$patch_line =~ m/^+++/;
2021 $file = $diffinfo->{'to_file'};
2022 $file ||= $diffinfo->{'file'};
2023 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2024 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2025 -class => "list"}, esc_html
($file));
2026 $patch_line =~ s
|b
/.*|b/$file|g
;
2027 print "<div class=\"diff to_file\">$patch_line</div>\n";
2031 next LINE
if $in_header;
2033 print format_diff_line
($patch_line);
2035 print "</div>\n" if $patch_found; # class="patch"
2037 print "</div>\n"; # class="patchset"
2040 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2042 sub git_shortlog_body
{
2043 # uses global variable $project
2044 my ($revlist, $from, $to, $refs, $extra) = @_;
2046 $from = 0 unless defined $from;
2047 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2049 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2051 for (my $i = $from; $i <= $to; $i++) {
2052 my $commit = $revlist->[$i];
2053 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2054 my $ref = format_ref_marker
($refs, $commit);
2055 my %co = parse_commit
($commit);
2057 print "<tr class=\"dark\">\n";
2059 print "<tr class=\"light\">\n";
2062 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2063 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2064 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2066 print format_subject_html
($co{'title'}, $co{'title_short'},
2067 href
(action
=>"commit", hash
=>$commit), $ref);
2069 "<td class=\"link\">" .
2070 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2071 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") . " | " .
2072 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2076 if (defined $extra) {
2078 "<td colspan=\"4\">$extra</td>\n" .
2084 sub git_history_body
{
2085 # Warning: assumes constant type (blob or tree) during history
2086 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2088 $from = 0 unless defined $from;
2089 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2091 print "<table class=\"history\" cellspacing=\"0\">\n";
2093 for (my $i = $from; $i <= $to; $i++) {
2094 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2099 my %co = parse_commit
($commit);
2104 my $ref = format_ref_marker
($refs, $commit);
2107 print "<tr class=\"dark\">\n";
2109 print "<tr class=\"light\">\n";
2112 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2113 # shortlog uses chop_str($co{'author_name'}, 10)
2114 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2116 # originally git_history used chop_str($co{'title'}, 50)
2117 print format_subject_html
($co{'title'}, $co{'title_short'},
2118 href
(action
=>"commit", hash
=>$commit), $ref);
2120 "<td class=\"link\">" .
2121 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2122 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2124 if ($ftype eq 'blob') {
2125 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2126 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2127 if (defined $blob_current && defined $blob_parent &&
2128 $blob_current ne $blob_parent) {
2130 $cgi->a({-href
=> href
(action
=>"blobdiff",
2131 hash
=>$blob_current, hash_parent
=>$blob_parent,
2132 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2133 file_name
=>$file_name)},
2140 if (defined $extra) {
2142 "<td colspan=\"4\">$extra</td>\n" .
2149 # uses global variable $project
2150 my ($taglist, $from, $to, $extra) = @_;
2151 $from = 0 unless defined $from;
2152 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2154 print "<table class=\"tags\" cellspacing=\"0\">\n";
2156 for (my $i = $from; $i <= $to; $i++) {
2157 my $entry = $taglist->[$i];
2159 my $comment_lines = $tag{'comment'};
2160 my $comment = shift @
$comment_lines;
2162 if (defined $comment) {
2163 $comment_short = chop_str
($comment, 30, 5);
2166 print "<tr class=\"dark\">\n";
2168 print "<tr class=\"light\">\n";
2171 print "<td><i>$tag{'age'}</i></td>\n" .
2173 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2174 -class => "list name"}, esc_html
($tag{'name'})) .
2177 if (defined $comment) {
2178 print format_subject_html
($comment, $comment_short,
2179 href
(action
=>"tag", hash
=>$tag{'id'}));
2182 "<td class=\"selflink\">";
2183 if ($tag{'type'} eq "tag") {
2184 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2189 "<td class=\"link\">" . " | " .
2190 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2191 if ($tag{'reftype'} eq "commit") {
2192 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2193 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2194 } elsif ($tag{'reftype'} eq "blob") {
2195 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2200 if (defined $extra) {
2202 "<td colspan=\"5\">$extra</td>\n" .
2208 sub git_heads_body
{
2209 # uses global variable $project
2210 my ($headlist, $head, $from, $to, $extra) = @_;
2211 $from = 0 unless defined $from;
2212 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2214 print "<table class=\"heads\" cellspacing=\"0\">\n";
2216 for (my $i = $from; $i <= $to; $i++) {
2217 my $entry = $headlist->[$i];
2219 my $curr = $tag{'id'} eq $head;
2221 print "<tr class=\"dark\">\n";
2223 print "<tr class=\"light\">\n";
2226 print "<td><i>$tag{'age'}</i></td>\n" .
2227 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
2228 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2229 -class => "list name"},esc_html
($tag{'name'})) .
2231 "<td class=\"link\">" .
2232 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2233 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2234 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2238 if (defined $extra) {
2240 "<td colspan=\"3\">$extra</td>\n" .
2246 ## ======================================================================
2247 ## ======================================================================
2250 sub git_project_list
{
2251 my $order = $cgi->param('o');
2252 if (defined $order && $order !~ m/project|descr|owner|age/) {
2253 die_error
(undef, "Unknown order parameter");
2256 my @list = git_get_projects_list
();
2259 die_error
(undef, "No projects found");
2261 foreach my $pr (@list) {
2262 my $head = git_get_head_hash
($pr->{'path'});
2263 if (!defined $head) {
2266 $git_dir = "$projectroot/$pr->{'path'}";
2267 my %co = parse_commit
($head);
2271 $pr->{'commit'} = \
%co;
2272 if (!defined $pr->{'descr'}) {
2273 my $descr = git_get_project_description
($pr->{'path'}) || "";
2274 $pr->{'descr'} = chop_str
($descr, 25, 5);
2276 if (!defined $pr->{'owner'}) {
2277 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2279 push @projects, $pr;
2283 if (-f
$home_text) {
2284 print "<div class=\"index_include\">\n";
2285 open (my $fd, $home_text);
2290 print "<table class=\"project_list\">\n" .
2292 $order ||= "project";
2293 if ($order eq "project") {
2294 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2295 print "<th>Project</th>\n";
2298 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2299 -class => "header"}, "Project") .
2302 if ($order eq "descr") {
2303 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2304 print "<th>Description</th>\n";
2307 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2308 -class => "header"}, "Description") .
2311 if ($order eq "owner") {
2312 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2313 print "<th>Owner</th>\n";
2316 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2317 -class => "header"}, "Owner") .
2320 if ($order eq "age") {
2321 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2322 print "<th>Last Change</th>\n";
2325 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2326 -class => "header"}, "Last Change") .
2329 print "<th></th>\n" .
2332 foreach my $pr (@projects) {
2334 print "<tr class=\"dark\">\n";
2336 print "<tr class=\"light\">\n";
2339 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2340 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2341 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2342 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2343 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2344 $pr->{'commit'}{'age_string'} . "</td>\n" .
2345 "<td class=\"link\">" .
2346 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2347 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2348 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2349 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2357 sub git_project_index
{
2358 my @projects = git_get_projects_list
();
2361 -type
=> 'text/plain',
2362 -charset
=> 'utf-8',
2363 -content_disposition
=> 'inline; filename="index.aux"');
2365 foreach my $pr (@projects) {
2366 if (!exists $pr->{'owner'}) {
2367 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2370 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2371 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2372 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2373 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2377 print "$path $owner\n";
2382 my $descr = git_get_project_description
($project) || "none";
2383 my $head = git_get_head_hash
($project);
2384 my %co = parse_commit
($head);
2385 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2387 my $owner = git_get_project_owner
($project);
2389 my ($reflist, $refs) = git_get_refs_list
();
2393 foreach my $ref (@
$reflist) {
2394 if ($ref->{'name'} =~ s!^heads/!!) {
2395 push @headlist, $ref;
2397 $ref->{'name'} =~ s!^tags/!!;
2398 push @taglist, $ref;
2403 git_print_page_nav
('summary','', $head);
2405 print "<div class=\"title\"> </div>\n";
2406 print "<table cellspacing=\"0\">\n" .
2407 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2408 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2409 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2410 # use per project git URL list in $projectroot/$project/cloneurl
2411 # or make project git URL from git base URL and project name
2412 my $url_tag = "URL";
2413 my @url_list = git_get_project_url_list
($project);
2414 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2415 foreach my $git_url (@url_list) {
2416 next unless $git_url;
2417 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2422 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2423 git_get_head_hash
($project)
2424 or die_error
(undef, "Open git-rev-list failed");
2425 my @revlist = map { chomp; $_ } <$fd>;
2427 git_print_header_div
('shortlog');
2428 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2429 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2432 git_print_header_div
('tags');
2433 git_tags_body
(\
@taglist, 0, 15,
2434 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2438 git_print_header_div
('heads');
2439 git_heads_body
(\
@headlist, $head, 0, 15,
2440 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2447 my $head = git_get_head_hash
($project);
2449 git_print_page_nav
('','', $head,undef,$head);
2450 my %tag = parse_tag
($hash);
2451 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2452 print "<div class=\"title_text\">\n" .
2453 "<table cellspacing=\"0\">\n" .
2455 "<td>object</td>\n" .
2456 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2457 $tag{'object'}) . "</td>\n" .
2458 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2459 $tag{'type'}) . "</td>\n" .
2461 if (defined($tag{'author'})) {
2462 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2463 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2464 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2465 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2468 print "</table>\n\n" .
2470 print "<div class=\"page_body\">";
2471 my $comment = $tag{'comment'};
2472 foreach my $line (@
$comment) {
2473 print esc_html
($line) . "<br/>\n";
2483 my ($have_blame) = gitweb_check_feature
('blame');
2485 die_error
('403 Permission denied', "Permission denied");
2487 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2488 $hash_base ||= git_get_head_hash
($project);
2489 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2490 my %co = parse_commit
($hash_base)
2491 or die_error
(undef, "Reading commit failed");
2492 if (!defined $hash) {
2493 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2494 or die_error
(undef, "Error looking up file");
2496 $ftype = git_get_type
($hash);
2497 if ($ftype !~ "blob") {
2498 die_error
("400 Bad Request", "Object is not a blob");
2500 open ($fd, "-|", git_cmd
(), "blame", '-l', '--', $file_name, $hash_base)
2501 or die_error
(undef, "Open git-blame failed");
2504 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2507 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2510 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2512 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2513 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2514 git_print_page_path
($file_name, $ftype, $hash_base);
2515 my @rev_color = (qw(light2 dark2));
2516 my $num_colors = scalar(@rev_color);
2517 my $current_color = 0;
2520 <div class="page_body">
2521 <table class="blame">
2522 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2525 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2527 my $rev = substr($full_rev, 0, 8);
2531 if (!defined $last_rev) {
2532 $last_rev = $full_rev;
2533 } elsif ($last_rev ne $full_rev) {
2534 $last_rev = $full_rev;
2535 $current_color = ++$current_color % $num_colors;
2537 print "<tr class=\"$rev_color[$current_color]\">\n";
2538 print "<td class=\"sha1\">" .
2539 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2540 esc_html
($rev)) . "</td>\n";
2541 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2542 esc_html
($lineno) . "</a></td>\n";
2543 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2549 or print "Reading blob failed\n";
2556 my ($have_blame) = gitweb_check_feature
('blame');
2558 die_error
('403 Permission denied', "Permission denied");
2560 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2561 $hash_base ||= git_get_head_hash
($project);
2562 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2563 my %co = parse_commit
($hash_base)
2564 or die_error
(undef, "Reading commit failed");
2565 if (!defined $hash) {
2566 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2567 or die_error
(undef, "Error lookup file");
2569 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2570 or die_error
(undef, "Open git-annotate failed");
2573 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2576 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2579 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2581 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2582 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2583 git_print_page_path
($file_name, 'blob', $hash_base);
2584 print "<div class=\"page_body\">\n";
2586 <table class="blame">
2595 my @line_class = (qw(light dark));
2596 my $line_class_len = scalar (@line_class);
2597 my $line_class_num = $#line_class;
2598 while (my $line = <$fd>) {
2610 $line_class_num = ($line_class_num + 1) % $line_class_len;
2612 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2619 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2622 $short_rev = substr ($long_rev, 0, 8);
2623 $age = time () - $time;
2624 $age_str = age_string
($age);
2625 $age_str =~ s/ / /g;
2626 $age_class = age_class
($age);
2627 $author = esc_html
($author);
2628 $author =~ s/ / /g;
2630 $data = untabify
($data);
2631 $data = esc_html
($data);
2634 <tr class="$line_class[$line_class_num]">
2635 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2636 <td class="$age_class">$age_str</td>
2638 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2639 <td class="pre">$data</td>
2642 } # while (my $line = <$fd>)
2643 print "</table>\n\n";
2645 or print "Reading blob failed.\n";
2651 my $head = git_get_head_hash
($project);
2653 git_print_page_nav
('','', $head,undef,$head);
2654 git_print_header_div
('summary', $project);
2656 my ($taglist) = git_get_refs_list
("tags");
2658 git_tags_body
($taglist);
2664 my $head = git_get_head_hash
($project);
2666 git_print_page_nav
('','', $head,undef,$head);
2667 git_print_header_div
('summary', $project);
2669 my ($headlist) = git_get_refs_list
("heads");
2671 git_heads_body
($headlist, $head);
2676 sub git_blob_plain
{
2679 if (!defined $hash) {
2680 if (defined $file_name) {
2681 my $base = $hash_base || git_get_head_hash
($project);
2682 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2683 or die_error
(undef, "Error lookup file");
2685 die_error
(undef, "No file name defined");
2687 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2688 # blobs defined by non-textual hash id's can be cached
2693 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2694 or die_error
(undef, "Couldn't cat $file_name, $hash");
2696 $type ||= blob_mimetype
($fd, $file_name);
2698 # save as filename, even when no $file_name is given
2699 my $save_as = "$hash";
2700 if (defined $file_name) {
2701 $save_as = $file_name;
2702 } elsif ($type =~ m/^text\//) {
2709 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2711 binmode STDOUT
, ':raw';
2713 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2721 if (!defined $hash) {
2722 if (defined $file_name) {
2723 my $base = $hash_base || git_get_head_hash
($project);
2724 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2725 or die_error
(undef, "Error lookup file");
2727 die_error
(undef, "No file name defined");
2729 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2730 # blobs defined by non-textual hash id's can be cached
2734 my ($have_blame) = gitweb_check_feature
('blame');
2735 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2736 or die_error
(undef, "Couldn't cat $file_name, $hash");
2737 my $mimetype = blob_mimetype
($fd, $file_name);
2738 if ($mimetype !~ m/^text\//) {
2740 return git_blob_plain
($mimetype);
2742 git_header_html
(undef, $expires);
2743 my $formats_nav = '';
2744 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2745 if (defined $file_name) {
2748 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2749 hash
=>$hash, file_name
=>$file_name)},
2754 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2755 hash
=>$hash, file_name
=>$file_name)},
2758 $cgi->a({-href
=> href
(action
=>"blob_plain",
2759 hash
=>$hash, file_name
=>$file_name)},
2762 $cgi->a({-href
=> href
(action
=>"blob",
2763 hash_base
=>"HEAD", file_name
=>$file_name)},
2767 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2769 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2770 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2772 print "<div class=\"page_nav\">\n" .
2773 "<br/><br/></div>\n" .
2774 "<div class=\"title\">$hash</div>\n";
2776 git_print_page_path
($file_name, "blob", $hash_base);
2777 print "<div class=\"page_body\">\n";
2779 while (my $line = <$fd>) {
2782 $line = untabify
($line);
2783 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2784 $nr, $nr, $nr, esc_html
($line);
2787 or print "Reading blob failed.\n";
2793 my $have_snapshot = gitweb_have_snapshot
();
2795 if (!defined $hash_base) {
2796 $hash_base = "HEAD";
2798 if (!defined $hash) {
2799 if (defined $file_name) {
2800 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
2806 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2807 or die_error
(undef, "Open git-ls-tree failed");
2808 my @entries = map { chomp; $_ } <$fd>;
2809 close $fd or die_error
(undef, "Reading tree failed");
2812 my $refs = git_get_references
();
2813 my $ref = format_ref_marker
($refs, $hash_base);
2816 my ($have_blame) = gitweb_check_feature
('blame');
2817 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2819 if (defined $file_name) {
2821 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2822 hash
=>$hash, file_name
=>$file_name)},
2824 $cgi->a({-href
=> href
(action
=>"tree",
2825 hash_base
=>"HEAD", file_name
=>$file_name)},
2828 if ($have_snapshot) {
2829 # FIXME: Should be available when we have no hash base as well.
2831 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2834 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2835 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2838 print "<div class=\"page_nav\">\n";
2839 print "<br/><br/></div>\n";
2840 print "<div class=\"title\">$hash</div>\n";
2842 if (defined $file_name) {
2843 $base = esc_html
("$file_name/");
2845 git_print_page_path
($file_name, 'tree', $hash_base);
2846 print "<div class=\"page_body\">\n";
2847 print "<table cellspacing=\"0\">\n";
2849 foreach my $line (@entries) {
2850 my %t = parse_ls_tree_line
($line, -z
=> 1);
2853 print "<tr class=\"dark\">\n";
2855 print "<tr class=\"light\">\n";
2859 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2863 print "</table>\n" .
2869 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2870 my $have_snapshot = (defined $ctype && defined $suffix);
2871 if (!$have_snapshot) {
2872 die_error
('403 Permission denied', "Permission denied");
2875 if (!defined $hash) {
2876 $hash = git_get_head_hash
($project);
2879 my $filename = basename
($project) . "-$hash.tar.$suffix";
2882 -type
=> 'application/x-tar',
2883 -content_encoding
=> $ctype,
2884 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
2885 -status
=> '200 OK');
2887 my $git_command = git_cmd_str
();
2888 open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
2889 die_error
(undef, "Execute git-tar-tree failed.");
2890 binmode STDOUT
, ':raw';
2892 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2898 my $head = git_get_head_hash
($project);
2899 if (!defined $hash) {
2902 if (!defined $page) {
2905 my $refs = git_get_references
();
2907 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2908 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2909 or die_error
(undef, "Open git-rev-list failed");
2910 my @revlist = map { chomp; $_ } <$fd>;
2913 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2916 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2919 my %co = parse_commit
($hash);
2921 git_print_header_div
('summary', $project);
2922 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2924 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2925 my $commit = $revlist[$i];
2926 my $ref = format_ref_marker
($refs, $commit);
2927 my %co = parse_commit
($commit);
2929 my %ad = parse_date
($co{'author_epoch'});
2930 git_print_header_div
('commit',
2931 "<span class=\"age\">$co{'age_string'}</span>" .
2932 esc_html
($co{'title'}) . $ref,
2934 print "<div class=\"title_text\">\n" .
2935 "<div class=\"log_link\">\n" .
2936 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2938 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2940 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
2943 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2946 print "<div class=\"log_body\">\n";
2947 git_print_simplified_log
($co{'comment'});
2954 my %co = parse_commit
($hash);
2956 die_error
(undef, "Unknown commit object");
2958 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2959 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2961 my $parent = $co{'parent'};
2962 if (!defined $parent) {
2965 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
2966 or die_error
(undef, "Open git-diff-tree failed");
2967 my @difftree = map { chomp; $_ } <$fd>;
2968 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2970 # non-textual hash id's can be cached
2972 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2975 my $refs = git_get_references
();
2976 my $ref = format_ref_marker
($refs, $co{'id'});
2978 my $have_snapshot = gitweb_have_snapshot
();
2981 if (defined $file_name && defined $co{'parent'}) {
2983 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2986 if (defined $co{'parent'}) {
2988 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash)}, "shortlog"),
2989 $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash)}, "log");
2991 git_header_html
(undef, $expires);
2992 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2993 $hash, $co{'tree'}, $hash,
2994 join (' | ', @views_nav));
2996 if (defined $co{'parent'}) {
2997 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2999 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3001 print "<div class=\"title_text\">\n" .
3002 "<table cellspacing=\"0\">\n";
3003 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3005 "<td></td><td> $ad{'rfc2822'}";
3006 if ($ad{'hour_local'} < 6) {
3007 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3008 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3010 printf(" (%02d:%02d %s)",
3011 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3015 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3016 print "<tr><td></td><td> $cd{'rfc2822'}" .
3017 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3019 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3022 "<td class=\"sha1\">" .
3023 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3024 class => "list"}, $co{'tree'}) .
3026 "<td class=\"link\">" .
3027 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3029 if ($have_snapshot) {
3031 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3035 my $parents = $co{'parents'};
3036 foreach my $par (@
$parents) {
3039 "<td class=\"sha1\">" .
3040 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3041 class => "list"}, $par) .
3043 "<td class=\"link\">" .
3044 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3046 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3053 print "<div class=\"page_body\">\n";
3054 git_print_log
($co{'comment'});
3057 git_difftree_body
(\
@difftree, $hash, $parent);
3063 my $format = shift || 'html';
3070 # preparing $fd and %diffinfo for git_patchset_body
3072 if (defined $hash_base && defined $hash_parent_base) {
3073 if (defined $file_name) {
3075 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3077 or die_error
(undef, "Open git-diff-tree failed");
3078 @difftree = map { chomp; $_ } <$fd>;
3080 or die_error
(undef, "Reading git-diff-tree failed");
3082 or die_error
('404 Not Found', "Blob diff not found");
3084 } elsif (defined $hash &&
3085 $hash =~ /[0-9a-fA-F]{40}/) {
3086 # try to find filename from $hash
3088 # read filtered raw output
3089 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3090 or die_error
(undef, "Open git-diff-tree failed");
3092 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3094 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3095 map { chomp; $_ } <$fd>;
3097 or die_error
(undef, "Reading git-diff-tree failed");
3099 or die_error
('404 Not Found', "Blob diff not found");
3102 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3105 if (@difftree > 1) {
3106 die_error
('404 Not Found', "Ambiguous blob diff specification");
3109 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3110 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3111 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3113 $hash_parent ||= $diffinfo{'from_id'};
3114 $hash ||= $diffinfo{'to_id'};
3116 # non-textual hash id's can be cached
3117 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3118 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3123 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3124 '-p', $hash_parent_base, $hash_base,
3126 or die_error
(undef, "Open git-diff-tree failed");
3129 # old/legacy style URI
3130 if (!%diffinfo && # if new style URI failed
3131 defined $hash && defined $hash_parent) {
3132 # fake git-diff-tree raw output
3133 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3134 $diffinfo{'from_id'} = $hash_parent;
3135 $diffinfo{'to_id'} = $hash;
3136 if (defined $file_name) {
3137 if (defined $file_parent) {
3138 $diffinfo{'status'} = '2';
3139 $diffinfo{'from_file'} = $file_parent;
3140 $diffinfo{'to_file'} = $file_name;
3141 } else { # assume not renamed
3142 $diffinfo{'status'} = '1';
3143 $diffinfo{'from_file'} = $file_name;
3144 $diffinfo{'to_file'} = $file_name;
3146 } else { # no filename given
3147 $diffinfo{'status'} = '2';
3148 $diffinfo{'from_file'} = $hash_parent;
3149 $diffinfo{'to_file'} = $hash;
3152 # non-textual hash id's can be cached
3153 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3154 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3159 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3160 or die_error
(undef, "Open git-diff failed");
3162 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3167 if ($format eq 'html') {
3169 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3170 hash
=>$hash, hash_parent
=>$hash_parent,
3171 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3172 file_name
=>$file_name, file_parent
=>$file_parent)},
3174 git_header_html
(undef, $expires);
3175 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3176 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3177 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3179 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3180 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3182 if (defined $file_name) {
3183 git_print_page_path
($file_name, "blob", $hash_base);
3185 print "<div class=\"page_path\"></div>\n";
3188 } elsif ($format eq 'plain') {
3190 -type
=> 'text/plain',
3191 -charset
=> 'utf-8',
3192 -expires
=> $expires,
3193 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3195 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3198 die_error
(undef, "Unknown blobdiff format");
3202 if ($format eq 'html') {
3203 print "<div class=\"page_body\">\n";
3205 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3208 print "</div>\n"; # class="page_body"
3212 while (my $line = <$fd>) {
3213 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3214 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3218 last if $line =~ m!^\+\+\+!;
3226 sub git_blobdiff_plain
{
3227 git_blobdiff
('plain');
3230 sub git_commitdiff
{
3231 my $format = shift || 'html';
3232 my %co = parse_commit
($hash);
3234 die_error
(undef, "Unknown commit object");
3236 if (!defined $hash_parent) {
3237 $hash_parent = $co{'parent'} || '--root';
3243 if ($format eq 'html') {
3244 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3245 "--patch-with-raw", "--full-index", $hash_parent, $hash
3246 or die_error
(undef, "Open git-diff-tree failed");
3248 while (chomp(my $line = <$fd>)) {
3249 # empty line ends raw part of diff-tree output
3251 push @difftree, $line;
3254 } elsif ($format eq 'plain') {
3255 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3256 '-p', $hash_parent, $hash
3257 or die_error
(undef, "Open git-diff-tree failed");
3260 die_error
(undef, "Unknown commitdiff format");
3263 # non-textual hash id's can be cached
3265 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3269 # write commit message
3270 if ($format eq 'html') {
3271 my $refs = git_get_references
();
3272 my $ref = format_ref_marker
($refs, $co{'id'});
3274 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3275 hash
=>$hash, hash_parent
=>$hash_parent)},
3278 git_header_html
(undef, $expires);
3279 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3280 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3281 git_print_authorship
(\
%co);
3282 print "<div class=\"page_body\">\n";
3283 print "<div class=\"log\">\n";
3284 git_print_simplified_log
($co{'comment'}, 1); # skip title
3285 print "</div>\n"; # class="log"
3287 } elsif ($format eq 'plain') {
3288 my $refs = git_get_references
("tags");
3289 my $tagname = git_get_rev_name_tags
($hash);
3290 my $filename = basename
($project) . "-$hash.patch";
3293 -type
=> 'text/plain',
3294 -charset
=> 'utf-8',
3295 -expires
=> $expires,
3296 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3297 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3300 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3301 Subject: $co{'title'}
3303 print "X-Git-Tag: $tagname\n" if $tagname;
3304 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3306 foreach my $line (@
{$co{'comment'}}) {
3313 if ($format eq 'html') {
3314 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3317 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3319 print "</div>\n"; # class="page_body"
3322 } elsif ($format eq 'plain') {
3326 or print "Reading git-diff-tree failed\n";
3330 sub git_commitdiff_plain
{
3331 git_commitdiff
('plain');
3335 if (!defined $hash_base) {
3336 $hash_base = git_get_head_hash
($project);
3338 if (!defined $page) {
3342 my %co = parse_commit
($hash_base);
3344 die_error
(undef, "Unknown commit object");
3347 my $refs = git_get_references
();
3348 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3350 if (!defined $hash && defined $file_name) {
3351 $hash = git_get_hash_by_path
($hash_base, $file_name);
3353 if (defined $hash) {
3354 $ftype = git_get_type
($hash);
3358 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3359 or die_error
(undef, "Open git-rev-list-failed");
3360 my @revlist = map { chomp; $_ } <$fd>;
3362 or die_error
(undef, "Reading git-rev-list failed");
3364 my $paging_nav = '';
3367 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3368 file_name
=>$file_name)},
3370 $paging_nav .= " ⋅ " .
3371 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3372 file_name
=>$file_name, page
=>$page-1),
3373 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3375 $paging_nav .= "first";
3376 $paging_nav .= " ⋅ prev";
3378 if ($#revlist >= (100 * ($page+1)-1)) {
3379 $paging_nav .= " ⋅ " .
3380 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3381 file_name
=>$file_name, page
=>$page+1),
3382 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3384 $paging_nav .= " ⋅ next";
3387 if ($#revlist >= (100 * ($page+1)-1)) {
3389 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3390 file_name
=>$file_name, page
=>$page+1),
3391 -title
=> "Alt-n"}, "next");
3395 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3396 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3397 git_print_page_path
($file_name, $ftype, $hash_base);
3399 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3400 $refs, $hash_base, $ftype, $next_link);
3406 if (!defined $searchtext) {
3407 die_error
(undef, "Text field empty");
3409 if (!defined $hash) {
3410 $hash = git_get_head_hash
($project);
3412 my %co = parse_commit
($hash);
3414 die_error
(undef, "Unknown commit object");
3417 my $commit_search = 1;
3418 my $author_search = 0;
3419 my $committer_search = 0;
3420 my $pickaxe_search = 0;
3421 if ($searchtext =~ s/^author\\://i) {
3423 } elsif ($searchtext =~ s/^committer\\://i) {
3424 $committer_search = 1;
3425 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3427 $pickaxe_search = 1;
3429 # pickaxe may take all resources of your box and run for several minutes
3430 # with every query - so decide by yourself how public you make this feature
3431 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3432 if (!$have_pickaxe) {
3433 die_error
('403 Permission denied', "Permission denied");
3437 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3438 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3440 print "<table cellspacing=\"0\">\n";
3442 if ($commit_search) {
3444 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3445 while (my $commit_text = <$fd>) {
3446 if (!grep m/$searchtext/i, $commit_text) {
3449 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3452 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3455 my @commit_lines = split "\n", $commit_text;
3456 my %co = parse_commit
(undef, \
@commit_lines);
3461 print "<tr class=\"dark\">\n";
3463 print "<tr class=\"light\">\n";
3466 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3467 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3469 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3470 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3471 my $comment = $co{'comment'};
3472 foreach my $line (@
$comment) {
3473 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3474 my $lead = esc_html
($1) || "";
3475 $lead = chop_str
($lead, 30, 10);
3476 my $match = esc_html
($2) || "";
3477 my $trail = esc_html
($3) || "";
3478 $trail = chop_str
($trail, 30, 10);
3479 my $text = "$lead<span class=\"match\">$match</span>$trail";
3480 print chop_str
($text, 80, 5) . "<br/>\n";
3484 "<td class=\"link\">" .
3485 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3487 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3494 if ($pickaxe_search) {
3496 my $git_command = git_cmd_str
();
3497 open my $fd, "-|", "$git_command rev-list $hash | " .
3498 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3501 while (my $line = <$fd>) {
3502 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3505 $set{'from_id'} = $3;
3507 $set{'id'} = $set{'to_id'};
3508 if ($set{'id'} =~ m/0{40}/) {
3509 $set{'id'} = $set{'from_id'};
3511 if ($set{'id'} =~ m/0{40}/) {
3515 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3518 print "<tr class=\"dark\">\n";
3520 print "<tr class=\"light\">\n";
3523 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3524 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3526 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3527 -class => "list subject"},
3528 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3529 while (my $setref = shift @files) {
3531 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3532 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3534 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3538 "<td class=\"link\">" .
3539 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3541 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3545 %co = parse_commit
($1);
3555 my $head = git_get_head_hash
($project);
3556 if (!defined $hash) {
3559 if (!defined $page) {
3562 my $refs = git_get_references
();
3564 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3565 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3566 or die_error
(undef, "Open git-rev-list failed");
3567 my @revlist = map { chomp; $_ } <$fd>;
3570 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3572 if ($#revlist >= (100 * ($page+1)-1)) {
3574 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3575 -title
=> "Alt-n"}, "next");
3580 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3581 git_print_header_div
('summary', $project);
3583 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3588 ## ......................................................................
3589 ## feeds (RSS, OPML)
3592 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3593 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3594 or die_error
(undef, "Open git-rev-list failed");
3595 my @revlist = map { chomp; $_ } <$fd>;
3596 close $fd or die_error
(undef, "Reading git-rev-list failed");
3597 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3599 <?xml version="1.0" encoding="utf-8"?>
3600 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3602 <title>$project $my_uri $my_url</title>
3603 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3604 <description>$project log</description>
3605 <language>en</language>
3608 for (my $i = 0; $i <= $#revlist; $i++) {
3609 my $commit = $revlist[$i];
3610 my %co = parse_commit
($commit);
3611 # we read 150, we always show 30 and the ones more recent than 48 hours
3612 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3615 my %cd = parse_date
($co{'committer_epoch'});
3616 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3617 $co{'parent'}, $co{'id'}
3619 my @difftree = map { chomp; $_ } <$fd>;
3624 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3626 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3627 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3628 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3629 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3630 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3631 "<content:encoded>" .
3633 my $comment = $co{'comment'};
3634 foreach my $line (@
$comment) {
3635 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3636 print "$line<br/>\n";
3639 foreach my $line (@difftree) {
3640 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3643 my $file = esc_html
(unquote
($7));
3644 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3645 print "$file<br/>\n";
3648 "</content:encoded>\n" .
3651 print "</channel></rss>";
3655 my @list = git_get_projects_list
();
3657 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3659 <?xml version="1.0" encoding="utf-8"?>
3660 <opml version="1.0">
3662 <title>$site_name Git OPML Export</title>
3665 <outline text="git RSS feeds">
3668 foreach my $pr (@list) {
3670 my $head = git_get_head_hash
($proj{'path'});
3671 if (!defined $head) {
3674 $git_dir = "$projectroot/$proj{'path'}";
3675 my %co = parse_commit
($head);
3680 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3681 my $rss = "$my_url?p=$proj{'path'};a=rss";
3682 my $html = "$my_url?p=$proj{'path'};a=summary";
3683 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";