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 CGI
->compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # target of the home link on top of all pages
39 our $home_link = $my_uri || "/";
41 # string of the home link on top of all pages
42 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
44 # name of your site or organization to appear in page titles
45 # replace this with something more descriptive for clearer bookmarks
46 our $site_name = "++GITWEB_SITENAME++"
47 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
49 # filename of html text to include at top of each page
50 our $site_header = "++GITWEB_SITE_HEADER++";
51 # html text to include at home page
52 our $home_text = "++GITWEB_HOMETEXT++";
53 # filename of html text to include at bottom of each page
54 our $site_footer = "++GITWEB_SITE_FOOTER++";
57 our @stylesheets = ("++GITWEB_CSS++");
58 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
59 our $stylesheet = undef;
60 # URI of GIT logo (72x27 size)
61 our $logo = "++GITWEB_LOGO++";
62 # URI of GIT favicon, assumed to be image/png type
63 our $favicon = "++GITWEB_FAVICON++";
65 # URI and label (title) of GIT logo link
66 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
67 #our $logo_label = "git documentation";
68 our $logo_url = "http://git.or.cz/";
69 our $logo_label = "git homepage";
71 # source of projects list
72 our $projects_list = "++GITWEB_LIST++";
74 # default order of projects list
75 # valid values are none, project, descr, owner, and age
76 our $default_projects_order = "project";
78 # show repository only if this file exists
79 # (only effective if this variable evaluates to true)
80 our $export_ok = "++GITWEB_EXPORT_OK++";
82 # only allow viewing of repositories also shown on the overview page
83 our $strict_export = "++GITWEB_STRICT_EXPORT++";
85 # list of git base URLs used for URL to where fetch project from,
86 # i.e. full URL is "$git_base_url/$project"
87 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
89 # default blob_plain mimetype and default charset for text/plain blob
90 our $default_blob_plain_mimetype = 'text/plain';
91 our $default_text_plain_charset = undef;
93 # file to use for guessing MIME types before trying /etc/mime.types
94 # (relative to the current git repository)
95 our $mimetypes_file = undef;
97 # assume this charset if line contains non-UTF-8 characters;
98 # it should be valid encoding (see Encoding::Supported(3pm) for list),
99 # for which encoding all byte sequences are valid, for example
100 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
101 # could be even 'utf-8' for the old behavior)
102 our $fallback_encoding = 'latin1';
104 # You define site-wide feature defaults here; override them with
105 # $GITWEB_CONFIG as necessary.
108 # 'sub' => feature-sub (subroutine),
109 # 'override' => allow-override (boolean),
110 # 'default' => [ default options...] (array reference)}
112 # if feature is overridable (it means that allow-override has true value),
113 # then feature-sub will be called with default options as parameters;
114 # return value of feature-sub indicates if to enable specified feature
116 # if there is no 'sub' key (no feature-sub), then feature cannot be
119 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
121 # Enable the 'blame' blob view, showing the last commit that modified
122 # each line in the file. This can be very CPU-intensive.
124 # To enable system wide have in $GITWEB_CONFIG
125 # $feature{'blame'}{'default'} = [1];
126 # To have project specific config enable override in $GITWEB_CONFIG
127 # $feature{'blame'}{'override'} = 1;
128 # and in project config gitweb.blame = 0|1;
130 'sub' => \
&feature_blame
,
134 # Enable the 'snapshot' link, providing a compressed tarball of any
135 # tree. This can potentially generate high traffic if you have large
138 # To disable system wide have in $GITWEB_CONFIG
139 # $feature{'snapshot'}{'default'} = [undef];
140 # To have project specific config enable override in $GITWEB_CONFIG
141 # $feature{'snapshot'}{'override'} = 1;
142 # and in project config gitweb.snapshot = none|gzip|bzip2|zip;
144 'sub' => \
&feature_snapshot
,
146 # => [content-encoding, suffix, program]
147 'default' => ['x-gzip', 'gz', 'gzip']},
149 # Enable text search, which will list the commits which match author,
150 # committer or commit text to a given string. Enabled by default.
151 # Project specific override is not supported.
156 # Enable grep search, which will list the files in currently selected
157 # tree containing the given string. Enabled by default. This can be
158 # potentially CPU-intensive, of course.
160 # To enable system wide have in $GITWEB_CONFIG
161 # $feature{'grep'}{'default'} = [1];
162 # To have project specific config enable override in $GITWEB_CONFIG
163 # $feature{'grep'}{'override'} = 1;
164 # and in project config gitweb.grep = 0|1;
169 # Enable the pickaxe search, which will list the commits that modified
170 # a given string in a file. This can be practical and quite faster
171 # alternative to 'blame', but still potentially CPU-intensive.
173 # To enable system wide have in $GITWEB_CONFIG
174 # $feature{'pickaxe'}{'default'} = [1];
175 # To have project specific config enable override in $GITWEB_CONFIG
176 # $feature{'pickaxe'}{'override'} = 1;
177 # and in project config gitweb.pickaxe = 0|1;
179 'sub' => \
&feature_pickaxe
,
183 # Make gitweb use an alternative format of the URLs which can be
184 # more readable and natural-looking: project name is embedded
185 # directly in the path and the query string contains other
186 # auxiliary information. All gitweb installations recognize
187 # URL in either format; this configures in which formats gitweb
190 # To enable system wide have in $GITWEB_CONFIG
191 # $feature{'pathinfo'}{'default'} = [1];
192 # Project specific override is not supported.
194 # Note that you will need to change the default location of CSS,
195 # favicon, logo and possibly other files to an absolute URL. Also,
196 # if gitweb.cgi serves as your indexfile, you will need to force
197 # $my_uri to contain the script name in your $GITWEB_CONFIG.
202 # Make gitweb consider projects in project root subdirectories
203 # to be forks of existing projects. Given project $projname.git,
204 # projects matching $projname/*.git will not be shown in the main
205 # projects list, instead a '+' mark will be added to $projname
206 # there and a 'forks' view will be enabled for the project, listing
207 # all the forks. If project list is taken from a file, forks have
208 # to be listed after the main project.
210 # To enable system wide have in $GITWEB_CONFIG
211 # $feature{'forks'}{'default'} = [1];
212 # Project specific override is not supported.
218 sub gitweb_check_feature
{
220 return unless exists $feature{$name};
221 my ($sub, $override, @defaults) = (
222 $feature{$name}{'sub'},
223 $feature{$name}{'override'},
224 @
{$feature{$name}{'default'}});
225 if (!$override) { return @defaults; }
227 warn "feature $name is not overrideable";
230 return $sub->(@defaults);
234 my ($val) = git_get_project_config
('blame', '--bool');
236 if ($val eq 'true') {
238 } elsif ($val eq 'false') {
245 sub feature_snapshot
{
246 my ($ctype, $suffix, $command) = @_;
248 my ($val) = git_get_project_config
('snapshot');
250 if ($val eq 'gzip') {
251 return ('x-gzip', 'gz', 'gzip');
252 } elsif ($val eq 'bzip2') {
253 return ('x-bzip2', 'bz2', 'bzip2');
254 } elsif ($val eq 'zip') {
255 return ('x-zip', 'zip', '');
256 } elsif ($val eq 'none') {
260 return ($ctype, $suffix, $command);
263 sub gitweb_have_snapshot
{
264 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
265 my $have_snapshot = (defined $ctype && defined $suffix);
267 return $have_snapshot;
271 my ($val) = git_get_project_config
('grep', '--bool');
273 if ($val eq 'true') {
275 } elsif ($val eq 'false') {
282 sub feature_pickaxe
{
283 my ($val) = git_get_project_config
('pickaxe', '--bool');
285 if ($val eq 'true') {
287 } elsif ($val eq 'false') {
294 # checking HEAD file with -e is fragile if the repository was
295 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
297 sub check_head_link
{
299 my $headfile = "$dir/HEAD";
300 return ((-e
$headfile) ||
301 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
304 sub check_export_ok
{
306 return (check_head_link
($dir) &&
307 (!$export_ok || -e
"$dir/$export_ok"));
310 # rename detection options for git-diff and git-diff-tree
311 # - default is '-M', with the cost proportional to
312 # (number of removed files) * (number of new files).
313 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
314 # (number of changed files + number of removed files) * (number of new files)
315 # - even more costly is '-C', '--find-copies-harder' with cost
316 # (number of files in the original tree) * (number of new files)
317 # - one might want to include '-B' option, e.g. '-B', '-M'
318 our @diff_opts = ('-M'); # taken from git_commit
320 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
321 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
323 # version of the core git binary
324 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
326 $projects_list ||= $projectroot;
328 # ======================================================================
329 # input validation and dispatch
330 our $action = $cgi->param('a');
331 if (defined $action) {
332 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
333 die_error
(undef, "Invalid action parameter");
337 # parameters which are pathnames
338 our $project = $cgi->param('p');
339 if (defined $project) {
340 if (!validate_pathname
($project) ||
341 !(-d
"$projectroot/$project") ||
342 !check_head_link
("$projectroot/$project") ||
343 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
344 ($strict_export && !project_in_list
($project))) {
346 die_error
(undef, "No such project");
350 our $file_name = $cgi->param('f');
351 if (defined $file_name) {
352 if (!validate_pathname
($file_name)) {
353 die_error
(undef, "Invalid file parameter");
357 our $file_parent = $cgi->param('fp');
358 if (defined $file_parent) {
359 if (!validate_pathname
($file_parent)) {
360 die_error
(undef, "Invalid file parent parameter");
364 # parameters which are refnames
365 our $hash = $cgi->param('h');
367 if (!validate_refname
($hash)) {
368 die_error
(undef, "Invalid hash parameter");
372 our $hash_parent = $cgi->param('hp');
373 if (defined $hash_parent) {
374 if (!validate_refname
($hash_parent)) {
375 die_error
(undef, "Invalid hash parent parameter");
379 our $hash_base = $cgi->param('hb');
380 if (defined $hash_base) {
381 if (!validate_refname
($hash_base)) {
382 die_error
(undef, "Invalid hash base parameter");
386 our $hash_parent_base = $cgi->param('hpb');
387 if (defined $hash_parent_base) {
388 if (!validate_refname
($hash_parent_base)) {
389 die_error
(undef, "Invalid hash parent base parameter");
394 our $page = $cgi->param('pg');
396 if ($page =~ m/[^0-9]/) {
397 die_error
(undef, "Invalid page parameter");
401 our $searchtype = $cgi->param('st');
402 if (defined $searchtype) {
403 if ($searchtype =~ m/[^a-z]/) {
404 die_error
(undef, "Invalid searchtype parameter");
408 our $searchtext = $cgi->param('s');
410 if (defined $searchtext) {
411 if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
412 die_error
(undef, "Invalid search parameter");
414 if (length($searchtext) < 2) {
415 die_error
(undef, "At least two characters are required for search parameter");
417 $search_regexp = quotemeta $searchtext;
420 # now read PATH_INFO and use it as alternative to parameters
421 sub evaluate_path_info
{
422 return if defined $project;
423 my $path_info = $ENV{"PATH_INFO"};
424 return if !$path_info;
425 $path_info =~ s
,^/+,,;
426 return if !$path_info;
427 # find which part of PATH_INFO is project
428 $project = $path_info;
430 while ($project && !check_head_link
("$projectroot/$project")) {
431 $project =~ s
,/*[^/]*$,,;
434 $project = validate_pathname
($project);
436 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
437 ($strict_export && !project_in_list
($project))) {
441 # do not change any parameters if an action is given using the query string
443 $path_info =~ s
,^$project/*,,;
444 my ($refname, $pathname) = split(/:/, $path_info, 2);
445 if (defined $pathname) {
446 # we got "project.git/branch:filename" or "project.git/branch:dir/"
447 # we could use git_get_type(branch:pathname), but it needs $git_dir
448 $pathname =~ s
,^/+,,;
449 if (!$pathname || substr($pathname, -1) eq "/") {
453 $action ||= "blob_plain";
455 $hash_base ||= validate_refname
($refname);
456 $file_name ||= validate_pathname
($pathname);
457 } elsif (defined $refname) {
458 # we got "project.git/branch"
459 $action ||= "shortlog";
460 $hash ||= validate_refname
($refname);
463 evaluate_path_info
();
465 # path to the current git repository
467 $git_dir = "$projectroot/$project" if $project;
471 "blame" => \
&git_blame2
,
472 "blobdiff" => \
&git_blobdiff
,
473 "blobdiff_plain" => \
&git_blobdiff_plain
,
474 "blob" => \
&git_blob
,
475 "blob_plain" => \
&git_blob_plain
,
476 "commitdiff" => \
&git_commitdiff
,
477 "commitdiff_plain" => \
&git_commitdiff_plain
,
478 "commit" => \
&git_commit
,
479 "forks" => \
&git_forks
,
480 "heads" => \
&git_heads
,
481 "history" => \
&git_history
,
484 "atom" => \
&git_atom
,
485 "search" => \
&git_search
,
486 "search_help" => \
&git_search_help
,
487 "shortlog" => \
&git_shortlog
,
488 "summary" => \
&git_summary
,
490 "tags" => \
&git_tags
,
491 "tree" => \
&git_tree
,
492 "snapshot" => \
&git_snapshot
,
493 "object" => \
&git_object
,
494 # those below don't need $project
495 "opml" => \
&git_opml
,
496 "project_list" => \
&git_project_list
,
497 "project_index" => \
&git_project_index
,
500 if (!defined $action) {
502 $action = git_get_type
($hash);
503 } elsif (defined $hash_base && defined $file_name) {
504 $action = git_get_type
("$hash_base:$file_name");
505 } elsif (defined $project) {
508 $action = 'project_list';
511 if (!defined($actions{$action})) {
512 die_error
(undef, "Unknown action");
514 if ($action !~ m/^(opml|project_list|project_index)$/ &&
516 die_error
(undef, "Project needed");
518 $actions{$action}->();
521 ## ======================================================================
526 # default is to use -absolute url() i.e. $my_uri
527 my $href = $params{-full
} ?
$my_url : $my_uri;
529 # XXX: Warning: If you touch this, check the search form for updating,
540 hash_parent_base
=> "hpb",
546 my %mapping = @mapping;
548 $params{'project'} = $project unless exists $params{'project'};
550 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
552 # use PATH_INFO for project name
553 $href .= "/$params{'project'}" if defined $params{'project'};
554 delete $params{'project'};
556 # Summary just uses the project path URL
557 if (defined $params{'action'} && $params{'action'} eq 'summary') {
558 delete $params{'action'};
562 # now encode the parameters explicitly
564 for (my $i = 0; $i < @mapping; $i += 2) {
565 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
566 if (defined $params{$name}) {
567 push @result, $symbol . "=" . esc_param
($params{$name});
570 $href .= "?" . join(';', @result) if scalar @result;
576 ## ======================================================================
577 ## validation, quoting/unquoting and escaping
579 sub validate_pathname
{
580 my $input = shift || return undef;
582 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
583 # at the beginning, at the end, and between slashes.
584 # also this catches doubled slashes
585 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
589 if ($input =~ m!\0!) {
595 sub validate_refname
{
596 my $input = shift || return undef;
598 # textual hashes are O.K.
599 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
602 # it must be correct pathname
603 $input = validate_pathname
($input)
605 # restrictions on ref name according to git-check-ref-format
606 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
612 # decode sequences of octets in utf8 into Perl's internal form,
613 # which is utf-8 with utf8 flag set if needed. gitweb writes out
614 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
618 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
622 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
626 # quote unsafe chars, but keep the slash, even when it's not
627 # correct, but quoted slashes look too horrible in bookmarks
630 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
636 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
639 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
645 # replace invalid utf8 character with SUBSTITUTION sequence
650 $str = to_utf8
($str);
651 $str = $cgi->escapeHTML($str);
652 if ($opts{'-nbsp'}) {
653 $str =~ s/ / /g;
655 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
659 # quote control characters and escape filename to HTML
664 $str = to_utf8
($str);
665 $str = $cgi->escapeHTML($str);
666 if ($opts{'-nbsp'}) {
667 $str =~ s/ / /g;
669 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
673 # Make control characters "printable", using character escape codes (CEC)
676 my %es = ( # character escape codes, aka escape sequences
677 "\t" => '\t', # tab (HT)
678 "\n" => '\n', # line feed (LF)
679 "\r" => '\r', # carrige return (CR)
680 "\f" => '\f', # form feed (FF)
681 "\b" => '\b', # backspace (BS)
682 "\a" => '\a', # alarm (bell) (BEL)
683 "\e" => '\e', # escape (ESC)
684 "\013" => '\v', # vertical tab (VT)
685 "\000" => '\0', # nul character (NUL)
687 my $chr = ( (exists $es{$cntrl})
689 : sprintf('\%03o', ord($cntrl)) );
690 return "<span class=\"cntrl\">$chr</span>";
693 # Alternatively use unicode control pictures codepoints,
694 # Unicode "printable representation" (PR)
697 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
698 return "<span class=\"cntrl\">$chr</span>";
701 # git may return quoted and escaped filenames
707 my %es = ( # character escape codes, aka escape sequences
708 't' => "\t", # tab (HT, TAB)
709 'n' => "\n", # newline (NL)
710 'r' => "\r", # return (CR)
711 'f' => "\f", # form feed (FF)
712 'b' => "\b", # backspace (BS)
713 'a' => "\a", # alarm (bell) (BEL)
714 'e' => "\e", # escape (ESC)
715 'v' => "\013", # vertical tab (VT)
718 if ($seq =~ m/^[0-7]{1,3}$/) {
719 # octal char sequence
720 return chr(oct($seq));
721 } elsif (exists $es{$seq}) {
722 # C escape sequence, aka character escape code
725 # quoted ordinary character
729 if ($str =~ m/^"(.*)"$/) {
732 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
737 # escape tabs (convert tabs to spaces)
741 while ((my $pos = index($line, "\t")) != -1) {
742 if (my $count = (8 - ($pos % 8))) {
743 my $spaces = ' ' x
$count;
744 $line =~ s/\t/$spaces/;
751 sub project_in_list
{
753 my @list = git_get_projects_list
();
754 return @list && scalar(grep { $_->{'path'} eq $project } @list);
757 ## ----------------------------------------------------------------------
758 ## HTML aware string manipulation
763 my $add_len = shift || 10;
765 # allow only $len chars, but don't cut a word if it would fit in $add_len
766 # if it doesn't fit, cut it if it's still longer than the dots we would add
767 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
770 if (length($tail) > 4) {
772 $body =~ s/&[^;]*$//; # remove chopped character entities
777 ## ----------------------------------------------------------------------
778 ## functions returning short strings
780 # CSS class for given age value (in seconds)
786 } elsif ($age < 60*60*2) {
788 } elsif ($age < 60*60*24*2) {
795 # convert age in seconds to "nn units ago" string
800 if ($age > 60*60*24*365*2) {
801 $age_str = (int $age/60/60/24/365);
802 $age_str .= " years ago";
803 } elsif ($age > 60*60*24*(365/12)*2) {
804 $age_str = int $age/60/60/24/(365/12);
805 $age_str .= " months ago";
806 } elsif ($age > 60*60*24*7*2) {
807 $age_str = int $age/60/60/24/7;
808 $age_str .= " weeks ago";
809 } elsif ($age > 60*60*24*2) {
810 $age_str = int $age/60/60/24;
811 $age_str .= " days ago";
812 } elsif ($age > 60*60*2) {
813 $age_str = int $age/60/60;
814 $age_str .= " hours ago";
815 } elsif ($age > 60*2) {
816 $age_str = int $age/60;
817 $age_str .= " min ago";
820 $age_str .= " sec ago";
822 $age_str .= " right now";
827 # convert file mode in octal to symbolic file mode string
829 my $mode = oct shift;
831 if (S_ISDIR
($mode & S_IFMT
)) {
833 } elsif (S_ISLNK
($mode)) {
835 } elsif (S_ISREG
($mode)) {
836 # git cares only about the executable bit
837 if ($mode & S_IXUSR
) {
847 # convert file mode in octal to file type string
851 if ($mode !~ m/^[0-7]+$/) {
857 if (S_ISDIR
($mode & S_IFMT
)) {
859 } elsif (S_ISLNK
($mode)) {
861 } elsif (S_ISREG
($mode)) {
868 # convert file mode in octal to file type description string
872 if ($mode !~ m/^[0-7]+$/) {
878 if (S_ISDIR
($mode & S_IFMT
)) {
880 } elsif (S_ISLNK
($mode)) {
882 } elsif (S_ISREG
($mode)) {
883 if ($mode & S_IXUSR
) {
894 ## ----------------------------------------------------------------------
895 ## functions returning short HTML fragments, or transforming HTML fragments
896 ## which don't belong to other sections
898 # format line of commit message.
899 sub format_log_line_html
{
902 $line = esc_html
($line, -nbsp
=>1);
903 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
906 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
907 -class => "text"}, $hash_text);
908 $line =~ s/$hash_text/$link/;
913 # format marker of refs pointing to given object
914 sub format_ref_marker
{
915 my ($refs, $id) = @_;
918 if (defined $refs->{$id}) {
919 foreach my $ref (@
{$refs->{$id}}) {
920 my ($type, $name) = qw();
921 # e.g. tags/v2.6.11 or heads/next
922 if ($ref =~ m!^(.*?)s?/(.*)$!) {
930 $markers .= " <span class=\"$type\" title=\"$ref\">" .
931 esc_html
($name) . "</span>";
936 return ' <span class="refs">'. $markers . '</span>';
942 # format, perhaps shortened and with markers, title line
943 sub format_subject_html
{
944 my ($long, $short, $href, $extra) = @_;
945 $extra = '' unless defined($extra);
947 if (length($short) < length($long)) {
948 return $cgi->a({-href
=> $href, -class => "list subject",
949 -title
=> to_utf8
($long)},
950 esc_html
($short) . $extra);
952 return $cgi->a({-href
=> $href, -class => "list subject"},
953 esc_html
($long) . $extra);
957 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
958 sub format_git_diff_header_line
{
960 my $diffinfo = shift;
961 my ($from, $to) = @_;
963 if ($diffinfo->{'nparents'}) {
965 $line =~ s!^(diff (.*?) )"?.*$!$1!;
967 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
968 esc_path
($to->{'file'}));
969 } else { # file was deleted (no href)
970 $line .= esc_path
($to->{'file'});
974 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
975 if ($from->{'href'}) {
976 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
977 'a/' . esc_path
($from->{'file'}));
978 } else { # file was added (no href)
979 $line .= 'a/' . esc_path
($from->{'file'});
983 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
984 'b/' . esc_path
($to->{'file'}));
985 } else { # file was deleted
986 $line .= 'b/' . esc_path
($to->{'file'});
990 return "<div class=\"diff header\">$line</div>\n";
993 # format extended diff header line, before patch itself
994 sub format_extended_diff_header_line
{
996 my $diffinfo = shift;
997 my ($from, $to) = @_;
1000 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1001 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1002 esc_path
($from->{'file'}));
1004 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1005 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1006 esc_path
($to->{'file'}));
1008 # match single <mode>
1009 if ($line =~ m/\s(\d{6})$/) {
1010 $line .= '<span class="info"> (' .
1011 file_type_long
($1) .
1015 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1016 # can match only for combined diff
1018 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1019 if ($from->{'href'}[$i]) {
1020 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1022 substr($diffinfo->{'from_id'}[$i],0,7));
1027 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1030 if ($to->{'href'}) {
1031 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1032 substr($diffinfo->{'to_id'},0,7));
1037 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1038 # can match only for ordinary diff
1039 my ($from_link, $to_link);
1040 if ($from->{'href'}) {
1041 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1042 substr($diffinfo->{'from_id'},0,7));
1044 $from_link = '0' x
7;
1046 if ($to->{'href'}) {
1047 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1048 substr($diffinfo->{'to_id'},0,7));
1052 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1053 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1056 return $line . "<br/>\n";
1059 # format from-file/to-file diff header
1060 sub format_diff_from_to_header
{
1061 my ($from_line, $to_line, $diffinfo, $from, $to) = @_;
1066 #assert($line =~ m/^---/) if DEBUG;
1067 # no extra formatting "^--- /dev/null"
1068 if ($line =~ m!^--- "?a/!) {
1069 if (!$diffinfo->{'nparents'} && # multiple 'from'
1072 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1073 esc_path
($from->{'file'}));
1076 esc_path
($from->{'file'});
1079 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1082 #assert($line =~ m/^\+\+\+/) if DEBUG;
1083 # no extra formatting for "^+++ /dev/null"
1084 if ($line =~ m!^\+\+\+ "?b/!) {
1085 if ($to->{'href'}) {
1087 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1088 esc_path
($to->{'file'}));
1091 esc_path
($to->{'file'});
1094 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1099 # format patch (diff) line (not to be used for diff headers)
1100 sub format_diff_line
{
1102 my ($from, $to) = @_;
1103 my $diff_class = "";
1107 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1109 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1110 if ($line =~ m/^\@{3}/) {
1111 $diff_class = " chunk_header";
1112 } elsif ($line =~ m/^\\/) {
1113 $diff_class = " incomplete";
1114 } elsif ($prefix =~ tr/+/+/) {
1115 $diff_class = " add";
1116 } elsif ($prefix =~ tr/-/-/) {
1117 $diff_class = " rem";
1120 # assume ordinary diff
1121 my $char = substr($line, 0, 1);
1123 $diff_class = " add";
1124 } elsif ($char eq '-') {
1125 $diff_class = " rem";
1126 } elsif ($char eq '@') {
1127 $diff_class = " chunk_header";
1128 } elsif ($char eq "\\") {
1129 $diff_class = " incomplete";
1132 $line = untabify
($line);
1133 if ($from && $to && $line =~ m/^\@{2} /) {
1134 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1135 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1137 $from_lines = 0 unless defined $from_lines;
1138 $to_lines = 0 unless defined $to_lines;
1140 if ($from->{'href'}) {
1141 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1142 -class=>"list"}, $from_text);
1144 if ($to->{'href'}) {
1145 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1146 -class=>"list"}, $to_text);
1148 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1149 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1150 return "<div class=\"diff$diff_class\">$line</div>\n";
1151 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1152 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1153 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1155 @from_text = split(' ', $ranges);
1156 for (my $i = 0; $i < @from_text; ++$i) {
1157 ($from_start[$i], $from_nlines[$i]) =
1158 (split(',', substr($from_text[$i], 1)), 0);
1161 $to_text = pop @from_text;
1162 $to_start = pop @from_start;
1163 $to_nlines = pop @from_nlines;
1165 $line = "<span class=\"chunk_info\">$prefix ";
1166 for (my $i = 0; $i < @from_text; ++$i) {
1167 if ($from->{'href'}[$i]) {
1168 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1169 -class=>"list"}, $from_text[$i]);
1171 $line .= $from_text[$i];
1175 if ($to->{'href'}) {
1176 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1177 -class=>"list"}, $to_text);
1181 $line .= " $prefix</span>" .
1182 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1183 return "<div class=\"diff$diff_class\">$line</div>\n";
1185 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1188 ## ----------------------------------------------------------------------
1189 ## git utility subroutines, invoking git commands
1191 # returns path to the core git executable and the --git-dir parameter as list
1193 return $GIT, '--git-dir='.$git_dir;
1196 # returns path to the core git executable and the --git-dir parameter as string
1198 return join(' ', git_cmd
());
1201 # get HEAD ref of given project as hash
1202 sub git_get_head_hash
{
1203 my $project = shift;
1204 my $o_git_dir = $git_dir;
1206 $git_dir = "$projectroot/$project";
1207 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1210 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1214 if (defined $o_git_dir) {
1215 $git_dir = $o_git_dir;
1220 # get type of given object
1224 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1226 close $fd or return;
1231 sub git_get_project_config
{
1232 my ($key, $type) = @_;
1234 return unless ($key);
1235 $key =~ s/^gitweb\.//;
1236 return if ($key =~ m/\W/);
1238 my @x = (git_cmd
(), 'config');
1239 if (defined $type) { push @x, $type; }
1241 push @x, "gitweb.$key";
1247 # get hash of given path at given ref
1248 sub git_get_hash_by_path
{
1250 my $path = shift || return undef;
1255 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1256 or die_error
(undef, "Open git-ls-tree failed");
1258 close $fd or return undef;
1260 if (!defined $line) {
1261 # there is no tree or hash given by $path at $base
1265 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1266 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1267 if (defined $type && $type ne $2) {
1268 # type doesn't match
1274 # get path of entry with given hash at given tree-ish (ref)
1275 # used to get 'from' filename for combined diff (merge commit) for renames
1276 sub git_get_path_by_hash
{
1277 my $base = shift || return;
1278 my $hash = shift || return;
1282 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1284 while (my $line = <$fd>) {
1287 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1288 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1289 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1298 ## ......................................................................
1299 ## git utility functions, directly accessing git repository
1301 sub git_get_project_description
{
1304 open my $fd, "$projectroot/$path/description" or return undef;
1307 if (defined $descr) {
1313 sub git_get_project_url_list
{
1316 open my $fd, "$projectroot/$path/cloneurl" or return;
1317 my @git_project_url_list = map { chomp; $_ } <$fd>;
1320 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1323 sub git_get_projects_list
{
1328 $filter =~ s/\.git$//;
1330 my ($check_forks) = gitweb_check_feature
('forks');
1332 if (-d
$projects_list) {
1333 # search in directory
1334 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1335 # remove the trailing "/"
1337 my $pfxlen = length("$dir");
1340 follow_fast
=> 1, # follow symbolic links
1341 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1343 # skip project-list toplevel, if we get it.
1344 return if (m!^[/.]$!);
1345 # only directories can be git repositories
1346 return unless (-d
$_);
1348 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1349 # we check related file in $projectroot
1350 if ($check_forks and $subdir =~ m
#/.#) {
1351 $File::Find
::prune
= 1;
1352 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1353 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1354 $File::Find
::prune
= 1;
1359 } elsif (-f
$projects_list) {
1360 # read from file(url-encoded):
1361 # 'git%2Fgit.git Linus+Torvalds'
1362 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1363 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1365 open my ($fd), $projects_list or return;
1367 while (my $line = <$fd>) {
1369 my ($path, $owner) = split ' ', $line;
1370 $path = unescape
($path);
1371 $owner = unescape
($owner);
1372 if (!defined $path) {
1375 if ($filter ne '') {
1376 # looking for forks;
1377 my $pfx = substr($path, 0, length($filter));
1378 if ($pfx ne $filter) {
1381 my $sfx = substr($path, length($filter));
1382 if ($sfx !~ /^\/.*\
.git
$/) {
1385 } elsif ($check_forks) {
1387 foreach my $filter (keys %paths) {
1388 # looking for forks;
1389 my $pfx = substr($path, 0, length($filter));
1390 if ($pfx ne $filter) {
1393 my $sfx = substr($path, length($filter));
1394 if ($sfx !~ /^\/.*\
.git
$/) {
1397 # is a fork, don't include it in
1402 if (check_export_ok
("$projectroot/$path")) {
1405 owner
=> to_utf8
($owner),
1408 (my $forks_path = $path) =~ s/\.git$//;
1409 $paths{$forks_path}++;
1417 sub git_get_project_owner
{
1418 my $project = shift;
1421 return undef unless $project;
1423 # read from file (url-encoded):
1424 # 'git%2Fgit.git Linus+Torvalds'
1425 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1426 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1427 if (-f
$projects_list) {
1428 open (my $fd , $projects_list);
1429 while (my $line = <$fd>) {
1431 my ($pr, $ow) = split ' ', $line;
1432 $pr = unescape
($pr);
1433 $ow = unescape
($ow);
1434 if ($pr eq $project) {
1435 $owner = to_utf8
($ow);
1441 if (!defined $owner) {
1442 $owner = get_file_owner
("$projectroot/$project");
1448 sub git_get_last_activity
{
1452 $git_dir = "$projectroot/$path";
1453 open($fd, "-|", git_cmd
(), 'for-each-ref',
1454 '--format=%(committer)',
1455 '--sort=-committerdate',
1457 'refs/heads') or return;
1458 my $most_recent = <$fd>;
1459 close $fd or return;
1460 if (defined $most_recent &&
1461 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1463 my $age = time - $timestamp;
1464 return ($age, age_string
($age));
1468 sub git_get_references
{
1469 my $type = shift || "";
1471 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1472 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1473 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1474 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1477 while (my $line = <$fd>) {
1479 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1480 if (defined $refs{$1}) {
1481 push @
{$refs{$1}}, $2;
1487 close $fd or return;
1491 sub git_get_rev_name_tags
{
1492 my $hash = shift || return undef;
1494 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1496 my $name_rev = <$fd>;
1499 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1502 # catches also '$hash undefined' output
1507 ## ----------------------------------------------------------------------
1508 ## parse to hash functions
1512 my $tz = shift || "-0000";
1515 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1516 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1517 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1518 $date{'hour'} = $hour;
1519 $date{'minute'} = $min;
1520 $date{'mday'} = $mday;
1521 $date{'day'} = $days[$wday];
1522 $date{'month'} = $months[$mon];
1523 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1524 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1525 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1526 $mday, $months[$mon], $hour ,$min;
1527 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1528 1900+$year, $mon, $mday, $hour ,$min, $sec;
1530 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1531 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1532 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1533 $date{'hour_local'} = $hour;
1534 $date{'minute_local'} = $min;
1535 $date{'tz_local'} = $tz;
1536 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1537 1900+$year, $mon+1, $mday,
1538 $hour, $min, $sec, $tz);
1547 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1548 $tag{'id'} = $tag_id;
1549 while (my $line = <$fd>) {
1551 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1552 $tag{'object'} = $1;
1553 } elsif ($line =~ m/^type (.+)$/) {
1555 } elsif ($line =~ m/^tag (.+)$/) {
1557 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1558 $tag{'author'} = $1;
1561 } elsif ($line =~ m/--BEGIN/) {
1562 push @comment, $line;
1564 } elsif ($line eq "") {
1568 push @comment, <$fd>;
1569 $tag{'comment'} = \
@comment;
1570 close $fd or return;
1571 if (!defined $tag{'name'}) {
1577 sub parse_commit_text
{
1578 my ($commit_text, $withparents) = @_;
1579 my @commit_lines = split '\n', $commit_text;
1582 pop @commit_lines; # Remove '\0'
1584 if (! @commit_lines) {
1588 my $header = shift @commit_lines;
1589 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1592 ($co{'id'}, my @parents) = split ' ', $header;
1593 while (my $line = shift @commit_lines) {
1594 last if $line eq "\n";
1595 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1597 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1599 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1601 $co{'author_epoch'} = $2;
1602 $co{'author_tz'} = $3;
1603 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1604 $co{'author_name'} = $1;
1605 $co{'author_email'} = $2;
1607 $co{'author_name'} = $co{'author'};
1609 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1610 $co{'committer'} = $1;
1611 $co{'committer_epoch'} = $2;
1612 $co{'committer_tz'} = $3;
1613 $co{'committer_name'} = $co{'committer'};
1614 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1615 $co{'committer_name'} = $1;
1616 $co{'committer_email'} = $2;
1618 $co{'committer_name'} = $co{'committer'};
1622 if (!defined $co{'tree'}) {
1625 $co{'parents'} = \
@parents;
1626 $co{'parent'} = $parents[0];
1628 foreach my $title (@commit_lines) {
1631 $co{'title'} = chop_str
($title, 80, 5);
1632 # remove leading stuff of merges to make the interesting part visible
1633 if (length($title) > 50) {
1634 $title =~ s/^Automatic //;
1635 $title =~ s/^merge (of|with) /Merge ... /i;
1636 if (length($title) > 50) {
1637 $title =~ s/(http|rsync):\/\///;
1639 if (length($title) > 50) {
1640 $title =~ s/(master|www|rsync)\.//;
1642 if (length($title) > 50) {
1643 $title =~ s/kernel.org:?//;
1645 if (length($title) > 50) {
1646 $title =~ s/\/pub\/scm//;
1649 $co{'title_short'} = chop_str
($title, 50, 5);
1653 if ($co{'title'} eq "") {
1654 $co{'title'} = $co{'title_short'} = '(no commit message)';
1656 # remove added spaces
1657 foreach my $line (@commit_lines) {
1660 $co{'comment'} = \
@commit_lines;
1662 my $age = time - $co{'committer_epoch'};
1664 $co{'age_string'} = age_string
($age);
1665 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1666 if ($age > 60*60*24*7*2) {
1667 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1668 $co{'age_string_age'} = $co{'age_string'};
1670 $co{'age_string_date'} = $co{'age_string'};
1671 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1677 my ($commit_id) = @_;
1682 open my $fd, "-|", git_cmd
(), "rev-list",
1688 or die_error
(undef, "Open git-rev-list failed");
1689 %co = parse_commit_text
(<$fd>, 1);
1696 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1704 open my $fd, "-|", git_cmd
(), "rev-list",
1706 ($arg ?
($arg) : ()),
1707 ("--max-count=" . $maxcount),
1708 ("--skip=" . $skip),
1711 ($filename ?
($filename) : ())
1712 or die_error
(undef, "Open git-rev-list failed");
1713 while (my $line = <$fd>) {
1714 my %co = parse_commit_text
($line);
1719 return wantarray ?
@cos : \
@cos;
1722 # parse ref from ref_file, given by ref_id, with given type
1724 my $ref_file = shift;
1726 my $type = shift || git_get_type
($ref_id);
1729 $ref_item{'type'} = $type;
1730 $ref_item{'id'} = $ref_id;
1731 $ref_item{'epoch'} = 0;
1732 $ref_item{'age'} = "unknown";
1733 if ($type eq "tag") {
1734 my %tag = parse_tag
($ref_id);
1735 $ref_item{'comment'} = $tag{'comment'};
1736 if ($tag{'type'} eq "commit") {
1737 my %co = parse_commit
($tag{'object'});
1738 $ref_item{'epoch'} = $co{'committer_epoch'};
1739 $ref_item{'age'} = $co{'age_string'};
1740 } elsif (defined($tag{'epoch'})) {
1741 my $age = time - $tag{'epoch'};
1742 $ref_item{'epoch'} = $tag{'epoch'};
1743 $ref_item{'age'} = age_string
($age);
1745 $ref_item{'reftype'} = $tag{'type'};
1746 $ref_item{'name'} = $tag{'name'};
1747 $ref_item{'refid'} = $tag{'object'};
1748 } elsif ($type eq "commit"){
1749 my %co = parse_commit
($ref_id);
1750 $ref_item{'reftype'} = "commit";
1751 $ref_item{'name'} = $ref_file;
1752 $ref_item{'title'} = $co{'title'};
1753 $ref_item{'refid'} = $ref_id;
1754 $ref_item{'epoch'} = $co{'committer_epoch'};
1755 $ref_item{'age'} = $co{'age_string'};
1757 $ref_item{'reftype'} = $type;
1758 $ref_item{'name'} = $ref_file;
1759 $ref_item{'refid'} = $ref_id;
1765 # parse line of git-diff-tree "raw" output
1766 sub parse_difftree_raw_line
{
1770 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1771 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1772 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1773 $res{'from_mode'} = $1;
1774 $res{'to_mode'} = $2;
1775 $res{'from_id'} = $3;
1777 $res{'status'} = $5;
1778 $res{'similarity'} = $6;
1779 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1780 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1782 $res{'file'} = unquote
($7);
1785 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1786 # combined diff (for merge commit)
1787 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1788 $res{'nparents'} = length($1);
1789 $res{'from_mode'} = [ split(' ', $2) ];
1790 $res{'to_mode'} = pop @
{$res{'from_mode'}};
1791 $res{'from_id'} = [ split(' ', $3) ];
1792 $res{'to_id'} = pop @
{$res{'from_id'}};
1793 $res{'status'} = [ split('', $4) ];
1794 $res{'to_file'} = unquote
($5);
1796 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1797 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1798 $res{'commit'} = $1;
1801 return wantarray ?
%res : \
%res;
1804 # parse line of git-ls-tree output
1805 sub parse_ls_tree_line
($;%) {
1810 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1811 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1819 $res{'name'} = unquote
($4);
1822 return wantarray ?
%res : \
%res;
1825 # generates _two_ hashes, references to which are passed as 2 and 3 argument
1826 sub parse_from_to_diffinfo
{
1827 my ($diffinfo, $from, $to, @parents) = @_;
1829 if ($diffinfo->{'nparents'}) {
1831 $from->{'file'} = [];
1832 $from->{'href'} = [];
1833 fill_from_file_info
($diffinfo, @parents)
1834 unless exists $diffinfo->{'from_file'};
1835 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1836 $from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
1837 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
1838 $from->{'href'}[$i] = href
(action
=>"blob",
1839 hash_base
=>$parents[$i],
1840 hash
=>$diffinfo->{'from_id'}[$i],
1841 file_name
=>$from->{'file'}[$i]);
1843 $from->{'href'}[$i] = undef;
1847 $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
1848 if ($diffinfo->{'status'} ne "A") { # not new (added) file
1849 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
1850 hash
=>$diffinfo->{'from_id'},
1851 file_name
=>$from->{'file'});
1853 delete $from->{'href'};
1857 $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
1858 if (!is_deleted
($diffinfo)) { # file exists in result
1859 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
1860 hash
=>$diffinfo->{'to_id'},
1861 file_name
=>$to->{'file'});
1863 delete $to->{'href'};
1867 ## ......................................................................
1868 ## parse to array of hashes functions
1870 sub git_get_heads_list
{
1874 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1875 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
1876 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1879 while (my $line = <$fd>) {
1883 my ($refinfo, $committerinfo) = split(/\0/, $line);
1884 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1885 my ($committer, $epoch, $tz) =
1886 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1887 $name =~ s!^refs/heads/!!;
1889 $ref_item{'name'} = $name;
1890 $ref_item{'id'} = $hash;
1891 $ref_item{'title'} = $title || '(no commit message)';
1892 $ref_item{'epoch'} = $epoch;
1894 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1896 $ref_item{'age'} = "unknown";
1899 push @headslist, \
%ref_item;
1903 return wantarray ?
@headslist : \
@headslist;
1906 sub git_get_tags_list
{
1910 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1911 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
1912 '--format=%(objectname) %(objecttype) %(refname) '.
1913 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1916 while (my $line = <$fd>) {
1920 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1921 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1922 my ($creator, $epoch, $tz) =
1923 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1924 $name =~ s!^refs/tags/!!;
1926 $ref_item{'type'} = $type;
1927 $ref_item{'id'} = $id;
1928 $ref_item{'name'} = $name;
1929 if ($type eq "tag") {
1930 $ref_item{'subject'} = $title;
1931 $ref_item{'reftype'} = $reftype;
1932 $ref_item{'refid'} = $refid;
1934 $ref_item{'reftype'} = $type;
1935 $ref_item{'refid'} = $id;
1938 if ($type eq "tag" || $type eq "commit") {
1939 $ref_item{'epoch'} = $epoch;
1941 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1943 $ref_item{'age'} = "unknown";
1947 push @tagslist, \
%ref_item;
1951 return wantarray ?
@tagslist : \
@tagslist;
1954 ## ----------------------------------------------------------------------
1955 ## filesystem-related functions
1957 sub get_file_owner
{
1960 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1961 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1962 if (!defined $gcos) {
1966 $owner =~ s/[,;].*$//;
1967 return to_utf8
($owner);
1970 ## ......................................................................
1971 ## mimetype related functions
1973 sub mimetype_guess_file
{
1974 my $filename = shift;
1975 my $mimemap = shift;
1976 -r
$mimemap or return undef;
1979 open(MIME
, $mimemap) or return undef;
1981 next if m/^#/; # skip comments
1982 my ($mime, $exts) = split(/\t+/);
1983 if (defined $exts) {
1984 my @exts = split(/\s+/, $exts);
1985 foreach my $ext (@exts) {
1986 $mimemap{$ext} = $mime;
1992 $filename =~ /\.([^.]*)$/;
1993 return $mimemap{$1};
1996 sub mimetype_guess
{
1997 my $filename = shift;
1999 $filename =~ /\./ or return undef;
2001 if ($mimetypes_file) {
2002 my $file = $mimetypes_file;
2003 if ($file !~ m!^/!) { # if it is relative path
2004 # it is relative to project
2005 $file = "$projectroot/$project/$file";
2007 $mime = mimetype_guess_file
($filename, $file);
2009 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2015 my $filename = shift;
2018 my $mime = mimetype_guess
($filename);
2019 $mime and return $mime;
2023 return $default_blob_plain_mimetype unless $fd;
2026 return 'text/plain' .
2027 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
2028 } elsif (! $filename) {
2029 return 'application/octet-stream';
2030 } elsif ($filename =~ m/\.png$/i) {
2032 } elsif ($filename =~ m/\.gif$/i) {
2034 } elsif ($filename =~ m/\.jpe?g$/i) {
2035 return 'image/jpeg';
2037 return 'application/octet-stream';
2041 ## ======================================================================
2042 ## functions printing HTML: header, footer, error page
2044 sub git_header_html
{
2045 my $status = shift || "200 OK";
2046 my $expires = shift;
2048 my $title = "$site_name";
2049 if (defined $project) {
2050 $title .= " - " . to_utf8
($project);
2051 if (defined $action) {
2052 $title .= "/$action";
2053 if (defined $file_name) {
2054 $title .= " - " . esc_path
($file_name);
2055 if ($action eq "tree" && $file_name !~ m
|/$|) {
2062 # require explicit support from the UA if we are to send the page as
2063 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2064 # we have to do this because MSIE sometimes globs '*/*', pretending to
2065 # support xhtml+xml but choking when it gets what it asked for.
2066 if (defined $cgi->http('HTTP_ACCEPT') &&
2067 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2068 $cgi->Accept('application/xhtml+xml') != 0) {
2069 $content_type = 'application/xhtml+xml';
2071 $content_type = 'text/html';
2073 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2074 -status
=> $status, -expires
=> $expires);
2075 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2077 <?xml version="1.0" encoding="utf-8"?>
2078 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2079 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2080 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2081 <!-- git core binaries version $git_version -->
2083 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2084 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2085 <meta name="robots" content="index, nofollow"/>
2086 <title>$title</title>
2088 # print out each stylesheet that exist
2089 if (defined $stylesheet) {
2090 #provides backwards capability for those people who define style sheet in a config file
2091 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2093 foreach my $stylesheet (@stylesheets) {
2094 next unless $stylesheet;
2095 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2098 if (defined $project) {
2099 printf('<link rel="alternate" title="%s log RSS feed" '.
2100 'href="%s" type="application/rss+xml" />'."\n",
2101 esc_param
($project), href
(action
=>"rss"));
2102 printf('<link rel="alternate" title="%s log Atom feed" '.
2103 'href="%s" type="application/atom+xml" />'."\n",
2104 esc_param
($project), href
(action
=>"atom"));
2106 printf('<link rel="alternate" title="%s projects list" '.
2107 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2108 $site_name, href
(project
=>undef, action
=>"project_index"));
2109 printf('<link rel="alternate" title="%s projects feeds" '.
2110 'href="%s" type="text/x-opml"/>'."\n",
2111 $site_name, href
(project
=>undef, action
=>"opml"));
2113 if (defined $favicon) {
2114 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
2120 if (-f
$site_header) {
2121 open (my $fd, $site_header);
2126 print "<div class=\"page_header\">\n" .
2127 $cgi->a({-href
=> esc_url
($logo_url),
2128 -title
=> $logo_label},
2129 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2130 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2131 if (defined $project) {
2132 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2133 if (defined $action) {
2140 my ($have_search) = gitweb_check_feature
('search');
2141 if ((defined $project) && ($have_search)) {
2142 if (!defined $searchtext) {
2146 if (defined $hash_base) {
2147 $search_hash = $hash_base;
2148 } elsif (defined $hash) {
2149 $search_hash = $hash;
2151 $search_hash = "HEAD";
2153 $cgi->param("a", "search");
2154 $cgi->param("h", $search_hash);
2155 $cgi->param("p", $project);
2156 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
2157 "<div class=\"search\">\n" .
2158 $cgi->hidden(-name
=> "p") . "\n" .
2159 $cgi->hidden(-name
=> "a") . "\n" .
2160 $cgi->hidden(-name
=> "h") . "\n" .
2161 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2162 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2163 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2165 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2167 $cgi->end_form() . "\n";
2171 sub git_footer_html
{
2172 print "<div class=\"page_footer\">\n";
2173 if (defined $project) {
2174 my $descr = git_get_project_description
($project);
2175 if (defined $descr) {
2176 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2178 print $cgi->a({-href
=> href
(action
=>"rss"),
2179 -class => "rss_logo"}, "RSS") . " ";
2180 print $cgi->a({-href
=> href
(action
=>"atom"),
2181 -class => "rss_logo"}, "Atom") . "\n";
2183 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2184 -class => "rss_logo"}, "OPML") . " ";
2185 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2186 -class => "rss_logo"}, "TXT") . "\n";
2190 if (-f
$site_footer) {
2191 open (my $fd, $site_footer);
2201 my $status = shift || "403 Forbidden";
2202 my $error = shift || "Malformed query, file missing or permission denied";
2204 git_header_html
($status);
2206 <div class="page_body">
2216 ## ----------------------------------------------------------------------
2217 ## functions printing or outputting HTML: navigation
2219 sub git_print_page_nav
{
2220 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2221 $extra = '' if !defined $extra; # pager or formats
2223 my @navs = qw(summary shortlog log commit commitdiff tree);
2225 @navs = grep { $_ ne $suppress } @navs;
2228 my %arg = map { $_ => {action
=>$_} } @navs;
2229 if (defined $head) {
2230 for (qw(commit commitdiff)) {
2231 $arg{$_}{'hash'} = $head;
2233 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2234 for (qw(shortlog log)) {
2235 $arg{$_}{'hash'} = $head;
2239 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2240 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2242 print "<div class=\"page_nav\">\n" .
2244 map { $_ eq $current ?
2245 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2247 print "<br/>\n$extra<br/>\n" .
2251 sub format_paging_nav
{
2252 my ($action, $hash, $head, $page, $nrevs) = @_;
2256 if ($hash ne $head || $page) {
2257 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2259 $paging_nav .= "HEAD";
2263 $paging_nav .= " ⋅ " .
2264 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2265 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2267 $paging_nav .= " ⋅ prev";
2270 if ($nrevs >= (100 * ($page+1)-1)) {
2271 $paging_nav .= " ⋅ " .
2272 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2273 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2275 $paging_nav .= " ⋅ next";
2281 ## ......................................................................
2282 ## functions printing or outputting HTML: div
2284 sub git_print_header_div
{
2285 my ($action, $title, $hash, $hash_base) = @_;
2288 $args{'action'} = $action;
2289 $args{'hash'} = $hash if $hash;
2290 $args{'hash_base'} = $hash_base if $hash_base;
2292 print "<div class=\"header\">\n" .
2293 $cgi->a({-href
=> href
(%args), -class => "title"},
2294 $title ?
$title : $action) .
2298 #sub git_print_authorship (\%) {
2299 sub git_print_authorship
{
2302 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2303 print "<div class=\"author_date\">" .
2304 esc_html
($co->{'author_name'}) .
2306 if ($ad{'hour_local'} < 6) {
2307 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2308 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2310 printf(" (%02d:%02d %s)",
2311 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2316 sub git_print_page_path
{
2322 print "<div class=\"page_path\">";
2323 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2324 -title
=> 'tree root'}, to_utf8
("[$project]"));
2326 if (defined $name) {
2327 my @dirname = split '/', $name;
2328 my $basename = pop @dirname;
2331 foreach my $dir (@dirname) {
2332 $fullname .= ($fullname ?
'/' : '') . $dir;
2333 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2335 -title
=> $fullname}, esc_path
($dir));
2338 if (defined $type && $type eq 'blob') {
2339 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2341 -title
=> $name}, esc_path
($basename));
2342 } elsif (defined $type && $type eq 'tree') {
2343 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2345 -title
=> $name}, esc_path
($basename));
2348 print esc_path
($basename);
2351 print "<br/></div>\n";
2354 # sub git_print_log (\@;%) {
2355 sub git_print_log
($;%) {
2359 if ($opts{'-remove_title'}) {
2360 # remove title, i.e. first line of log
2363 # remove leading empty lines
2364 while (defined $log->[0] && $log->[0] eq "") {
2371 foreach my $line (@
$log) {
2372 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2375 if (! $opts{'-remove_signoff'}) {
2376 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2379 # remove signoff lines
2386 # print only one empty line
2387 # do not print empty line after signoff
2389 next if ($empty || $signoff);
2395 print format_log_line_html
($line) . "<br/>\n";
2398 if ($opts{'-final_empty_line'}) {
2399 # end with single empty line
2400 print "<br/>\n" unless $empty;
2404 # return link target (what link points to)
2405 sub git_get_link_target
{
2410 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2414 $link_target = <$fd>;
2419 return $link_target;
2422 # given link target, and the directory (basedir) the link is in,
2423 # return target of link relative to top directory (top tree);
2424 # return undef if it is not possible (including absolute links).
2425 sub normalize_link_target
{
2426 my ($link_target, $basedir, $hash_base) = @_;
2428 # we can normalize symlink target only if $hash_base is provided
2429 return unless $hash_base;
2431 # absolute symlinks (beginning with '/') cannot be normalized
2432 return if (substr($link_target, 0, 1) eq '/');
2434 # normalize link target to path from top (root) tree (dir)
2437 $path = $basedir . '/' . $link_target;
2439 # we are in top (root) tree (dir)
2440 $path = $link_target;
2443 # remove //, /./, and /../
2445 foreach my $part (split('/', $path)) {
2446 # discard '.' and ''
2447 next if (!$part || $part eq '.');
2449 if ($part eq '..') {
2453 # link leads outside repository (outside top dir)
2457 push @path_parts, $part;
2460 $path = join('/', @path_parts);
2465 # print tree entry (row of git_tree), but without encompassing <tr> element
2466 sub git_print_tree_entry
{
2467 my ($t, $basedir, $hash_base, $have_blame) = @_;
2470 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2472 # The format of a table row is: mode list link. Where mode is
2473 # the mode of the entry, list is the name of the entry, an href,
2474 # and link is the action links of the entry.
2476 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2477 if ($t->{'type'} eq "blob") {
2478 print "<td class=\"list\">" .
2479 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2480 file_name
=>"$basedir$t->{'name'}", %base_key),
2481 -class => "list"}, esc_path
($t->{'name'}));
2482 if (S_ISLNK
(oct $t->{'mode'})) {
2483 my $link_target = git_get_link_target
($t->{'hash'});
2485 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2486 if (defined $norm_target) {
2488 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2489 file_name
=>$norm_target),
2490 -title
=> $norm_target}, esc_path
($link_target));
2492 print " -> " . esc_path
($link_target);
2497 print "<td class=\"link\">";
2498 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2499 file_name
=>"$basedir$t->{'name'}", %base_key)},
2503 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2504 file_name
=>"$basedir$t->{'name'}", %base_key)},
2507 if (defined $hash_base) {
2509 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2510 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2514 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2515 file_name
=>"$basedir$t->{'name'}")},
2519 } elsif ($t->{'type'} eq "tree") {
2520 print "<td class=\"list\">";
2521 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2522 file_name
=>"$basedir$t->{'name'}", %base_key)},
2523 esc_path
($t->{'name'}));
2525 print "<td class=\"link\">";
2526 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2527 file_name
=>"$basedir$t->{'name'}", %base_key)},
2529 if (defined $hash_base) {
2531 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2532 file_name
=>"$basedir$t->{'name'}")},
2539 ## ......................................................................
2540 ## functions printing large fragments of HTML
2542 sub fill_from_file_info
{
2543 my ($diff, @parents) = @_;
2545 $diff->{'from_file'} = [ ];
2546 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2547 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2548 if ($diff->{'status'}[$i] eq 'R' ||
2549 $diff->{'status'}[$i] eq 'C') {
2550 $diff->{'from_file'}[$i] =
2551 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2558 # parameters can be strings, or references to arrays of strings
2562 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @
$a == @
$b) {
2563 for (my $i = 0; $i < @
$a; ++$i) {
2564 return 0 unless ($a->[$i] eq $b->[$i]);
2567 } elsif (!ref($a) && !ref($b)) {
2575 my $diffinfo = shift;
2577 return $diffinfo->{'to_id'} eq ('0' x
40);
2580 sub git_difftree_body
{
2581 my ($difftree, $hash, @parents) = @_;
2582 my ($parent) = $parents[0];
2583 my ($have_blame) = gitweb_check_feature
('blame');
2584 print "<div class=\"list_head\">\n";
2585 if ($#{$difftree} > 10) {
2586 print(($#{$difftree} + 1) . " files changed:\n");
2590 print "<table class=\"" .
2591 (@parents > 1 ?
"combined " : "") .
2594 # header only for combined diff in 'commitdiff' view
2595 my $has_header = @parents > 1 && $action eq 'commitdiff';
2598 print "<thead><tr>\n" .
2599 "<th></th><th></th>\n"; # filename, patchN link
2600 for (my $i = 0; $i < @parents; $i++) {
2601 my $par = $parents[$i];
2603 $cgi->a({-href
=> href
(action
=>"commitdiff",
2604 hash
=>$hash, hash_parent
=>$par),
2605 -title
=> 'commitdiff to parent number ' .
2606 ($i+1) . ': ' . substr($par,0,7)},
2610 print "</tr></thead>\n<tbody>\n";
2615 foreach my $line (@
{$difftree}) {
2617 if (ref($line) eq "HASH") {
2618 # pre-parsed (or generated by hand)
2621 $diff = parse_difftree_raw_line
($line);
2625 print "<tr class=\"dark\">\n";
2627 print "<tr class=\"light\">\n";
2631 if (exists $diff->{'nparents'}) { # combined diff
2633 fill_from_file_info
($diff, @parents)
2634 unless exists $diff->{'from_file'};
2636 if (!is_deleted
($diff)) {
2637 # file exists in the result (child) commit
2639 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2640 file_name
=>$diff->{'to_file'},
2642 -class => "list"}, esc_path
($diff->{'to_file'})) .
2646 esc_path
($diff->{'to_file'}) .
2650 if ($action eq 'commitdiff') {
2653 print "<td class=\"link\">" .
2654 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2659 my $has_history = 0;
2660 my $not_deleted = 0;
2661 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2662 my $hash_parent = $parents[$i];
2663 my $from_hash = $diff->{'from_id'}[$i];
2664 my $from_path = $diff->{'from_file'}[$i];
2665 my $status = $diff->{'status'}[$i];
2667 $has_history ||= ($status ne 'A');
2668 $not_deleted ||= ($status ne 'D');
2670 if ($status eq 'A') {
2671 print "<td class=\"link\" align=\"right\"> | </td>\n";
2672 } elsif ($status eq 'D') {
2673 print "<td class=\"link\">" .
2674 $cgi->a({-href
=> href
(action
=>"blob",
2677 file_name
=>$from_path)},
2681 if ($diff->{'to_id'} eq $from_hash) {
2682 print "<td class=\"link nochange\">";
2684 print "<td class=\"link\">";
2686 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2687 hash
=>$diff->{'to_id'},
2688 hash_parent
=>$from_hash,
2690 hash_parent_base
=>$hash_parent,
2691 file_name
=>$diff->{'to_file'},
2692 file_parent
=>$from_path)},
2698 print "<td class=\"link\">";
2700 print $cgi->a({-href
=> href
(action
=>"blob",
2701 hash
=>$diff->{'to_id'},
2702 file_name
=>$diff->{'to_file'},
2705 print " | " if ($has_history);
2708 print $cgi->a({-href
=> href
(action
=>"history",
2709 file_name
=>$diff->{'to_file'},
2716 next; # instead of 'else' clause, to avoid extra indent
2718 # else ordinary diff
2720 my ($to_mode_oct, $to_mode_str, $to_file_type);
2721 my ($from_mode_oct, $from_mode_str, $from_file_type);
2722 if ($diff->{'to_mode'} ne ('0' x
6)) {
2723 $to_mode_oct = oct $diff->{'to_mode'};
2724 if (S_ISREG
($to_mode_oct)) { # only for regular file
2725 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2727 $to_file_type = file_type
($diff->{'to_mode'});
2729 if ($diff->{'from_mode'} ne ('0' x
6)) {
2730 $from_mode_oct = oct $diff->{'from_mode'};
2731 if (S_ISREG
($to_mode_oct)) { # only for regular file
2732 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2734 $from_file_type = file_type
($diff->{'from_mode'});
2737 if ($diff->{'status'} eq "A") { # created
2738 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2739 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2740 $mode_chng .= "]</span>";
2742 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2743 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2744 -class => "list"}, esc_path
($diff->{'file'}));
2746 print "<td>$mode_chng</td>\n";
2747 print "<td class=\"link\">";
2748 if ($action eq 'commitdiff') {
2751 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2754 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2755 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2759 } elsif ($diff->{'status'} eq "D") { # deleted
2760 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2762 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2763 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2764 -class => "list"}, esc_path
($diff->{'file'}));
2766 print "<td>$mode_chng</td>\n";
2767 print "<td class=\"link\">";
2768 if ($action eq 'commitdiff') {
2771 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2774 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2775 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2778 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2779 file_name
=>$diff->{'file'})},
2782 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2783 file_name
=>$diff->{'file'})},
2787 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2788 my $mode_chnge = "";
2789 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2790 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2791 if ($from_file_type ne $to_file_type) {
2792 $mode_chnge .= " from $from_file_type to $to_file_type";
2794 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2795 if ($from_mode_str && $to_mode_str) {
2796 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2797 } elsif ($to_mode_str) {
2798 $mode_chnge .= " mode: $to_mode_str";
2801 $mode_chnge .= "]</span>\n";
2804 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2805 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2806 -class => "list"}, esc_path
($diff->{'file'}));
2808 print "<td>$mode_chnge</td>\n";
2809 print "<td class=\"link\">";
2810 if ($action eq 'commitdiff') {
2813 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2815 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2816 # "commit" view and modified file (not onlu mode changed)
2817 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2818 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2819 hash_base
=>$hash, hash_parent_base
=>$parent,
2820 file_name
=>$diff->{'file'})},
2824 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2825 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2828 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2829 file_name
=>$diff->{'file'})},
2832 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2833 file_name
=>$diff->{'file'})},
2837 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2838 my %status_name = ('R' => 'moved', 'C' => 'copied');
2839 my $nstatus = $status_name{$diff->{'status'}};
2841 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2842 # mode also for directories, so we cannot use $to_mode_str
2843 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2846 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2847 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2848 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2849 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2850 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2851 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2852 -class => "list"}, esc_path
($diff->{'from_file'})) .
2853 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2854 "<td class=\"link\">";
2855 if ($action eq 'commitdiff') {
2858 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2860 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2861 # "commit" view and modified file (not only pure rename or copy)
2862 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2863 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2864 hash_base
=>$hash, hash_parent_base
=>$parent,
2865 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2869 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2870 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2873 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2874 file_name
=>$diff->{'to_file'})},
2877 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2878 file_name
=>$diff->{'to_file'})},
2882 } # we should not encounter Unmerged (U) or Unknown (X) status
2885 print "</tbody>" if $has_header;
2889 sub git_patchset_body
{
2890 my ($fd, $difftree, $hash, @hash_parents) = @_;
2891 my ($hash_parent) = $hash_parents[0];
2894 my $patch_number = 0;
2899 print "<div class=\"patchset\">\n";
2901 # skip to first patch
2902 while ($patch_line = <$fd>) {
2905 last if ($patch_line =~ m/^diff /);
2909 while ($patch_line) {
2911 my ($from_id, $to_id);
2914 #assert($patch_line =~ m/^diff /) if DEBUG;
2915 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2917 push @diff_header, $patch_line;
2919 # extended diff header
2921 while ($patch_line = <$fd>) {
2924 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2926 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2929 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2930 $from_id = [ split(',', $1) ];
2934 push @diff_header, $patch_line;
2936 my $last_patch_line = $patch_line;
2938 # check if current patch belong to current raw line
2939 # and parse raw git-diff line if needed
2940 if (defined $diffinfo &&
2941 defined $from_id && defined $to_id &&
2942 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2943 $diffinfo->{'to_id'} eq $to_id) {
2944 # this is continuation of a split patch
2945 print "<div class=\"patch cont\">\n";
2947 # advance raw git-diff output if needed
2948 $patch_idx++ if defined $diffinfo;
2950 # read and prepare patch information
2951 if (ref($difftree->[$patch_idx]) eq "HASH") {
2952 # pre-parsed (or generated by hand)
2953 $diffinfo = $difftree->[$patch_idx];
2955 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2957 # modifies %from, %to hashes
2958 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
2959 if ($diffinfo->{'nparents'}) {
2963 fill_from_file_info
($diffinfo, @hash_parents)
2964 unless exists $diffinfo->{'from_file'};
2965 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2966 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2967 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2968 $from{'href'}[$i] = href
(action
=>"blob",
2969 hash_base
=>$hash_parents[$i],
2970 hash
=>$diffinfo->{'from_id'}[$i],
2971 file_name
=>$from{'file'}[$i]);
2973 $from{'href'}[$i] = undef;
2977 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2978 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2979 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2980 hash
=>$diffinfo->{'from_id'},
2981 file_name
=>$from{'file'});
2983 delete $from{'href'};
2987 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2988 if (!is_deleted
($diffinfo)) { # file exists in result
2989 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2990 hash
=>$diffinfo->{'to_id'},
2991 file_name
=>$to{'file'});
2995 # this is first patch for raw difftree line with $patch_idx index
2996 # we index @$difftree array from 0, but number patches from 1
2997 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3000 # print "git diff" header
3001 $patch_line = shift @diff_header;
3002 print format_git_diff_header_line
($patch_line, $diffinfo,
3005 # print extended diff header
3006 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
3008 foreach $patch_line (@diff_header) {
3009 print format_extended_diff_header_line
($patch_line, $diffinfo,
3012 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
3014 # from-file/to-file diff header
3015 $patch_line = $last_patch_line;
3016 if (! $patch_line) {
3017 print "</div>\n"; # class="patch"
3020 next PATCH
if ($patch_line =~ m/^diff /);
3021 #assert($patch_line =~ m/^---/) if DEBUG;
3022 #assert($patch_line eq $last_patch_line) if DEBUG;
3024 $patch_line = <$fd>;
3026 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3028 print format_diff_from_to_header
($last_patch_line, $patch_line,
3029 $diffinfo, \
%from, \
%to);
3033 while ($patch_line = <$fd>) {
3036 next PATCH
if ($patch_line =~ m/^diff /);
3038 print format_diff_line
($patch_line, \
%from, \
%to);
3042 print "</div>\n"; # class="patch"
3045 if ($patch_number == 0) {
3046 if (@hash_parents > 1) {
3047 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3049 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3053 print "</div>\n"; # class="patchset"
3056 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3058 sub git_project_list_body
{
3059 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3061 my ($check_forks) = gitweb_check_feature
('forks');
3064 foreach my $pr (@
$projlist) {
3065 my (@aa) = git_get_last_activity
($pr->{'path'});
3069 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3070 if (!defined $pr->{'descr'}) {
3071 my $descr = git_get_project_description
($pr->{'path'}) || "";
3072 $pr->{'descr_long'} = to_utf8
($descr);
3073 $pr->{'descr'} = chop_str
($descr, 25, 5);
3075 if (!defined $pr->{'owner'}) {
3076 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
3079 my $pname = $pr->{'path'};
3080 if (($pname =~ s/\.git$//) &&
3081 ($pname !~ /\/$/) &&
3082 (-d
"$projectroot/$pname")) {
3083 $pr->{'forks'} = "-d $projectroot/$pname";
3089 push @projects, $pr;
3092 $order ||= $default_projects_order;
3093 $from = 0 unless defined $from;
3094 $to = $#projects if (!defined $to || $#projects < $to);
3096 print "<table class=\"project_list\">\n";
3097 unless ($no_header) {
3100 print "<th></th>\n";
3102 if ($order eq "project") {
3103 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3104 print "<th>Project</th>\n";
3107 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3108 -class => "header"}, "Project") .
3111 if ($order eq "descr") {
3112 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3113 print "<th>Description</th>\n";
3116 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3117 -class => "header"}, "Description") .
3120 if ($order eq "owner") {
3121 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3122 print "<th>Owner</th>\n";
3125 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3126 -class => "header"}, "Owner") .
3129 if ($order eq "age") {
3130 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3131 print "<th>Last Change</th>\n";
3134 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3135 -class => "header"}, "Last Change") .
3138 print "<th></th>\n" .
3142 for (my $i = $from; $i <= $to; $i++) {
3143 my $pr = $projects[$i];
3145 print "<tr class=\"dark\">\n";
3147 print "<tr class=\"light\">\n";
3152 if ($pr->{'forks'}) {
3153 print "<!-- $pr->{'forks'} -->\n";
3154 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3158 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3159 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3160 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3161 -class => "list", -title
=> $pr->{'descr_long'}},
3162 esc_html
($pr->{'descr'})) . "</td>\n" .
3163 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3164 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3165 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3166 "<td class=\"link\">" .
3167 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3168 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3169 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3170 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3171 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3175 if (defined $extra) {
3178 print "<td></td>\n";
3180 print "<td colspan=\"5\">$extra</td>\n" .
3186 sub git_shortlog_body
{
3187 # uses global variable $project
3188 my ($commitlist, $from, $to, $refs, $extra) = @_;
3190 my $have_snapshot = gitweb_have_snapshot
();
3192 $from = 0 unless defined $from;
3193 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3195 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3197 for (my $i = $from; $i <= $to; $i++) {
3198 my %co = %{$commitlist->[$i]};
3199 my $commit = $co{'id'};
3200 my $ref = format_ref_marker
($refs, $commit);
3202 print "<tr class=\"dark\">\n";
3204 print "<tr class=\"light\">\n";
3207 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3208 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3209 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3211 print format_subject_html
($co{'title'}, $co{'title_short'},
3212 href
(action
=>"commit", hash
=>$commit), $ref);
3214 "<td class=\"link\">" .
3215 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3216 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3217 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3218 if ($have_snapshot) {
3219 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3224 if (defined $extra) {
3226 "<td colspan=\"4\">$extra</td>\n" .
3232 sub git_history_body
{
3233 # Warning: assumes constant type (blob or tree) during history
3234 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3236 $from = 0 unless defined $from;
3237 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3239 print "<table class=\"history\" cellspacing=\"0\">\n";
3241 for (my $i = $from; $i <= $to; $i++) {
3242 my %co = %{$commitlist->[$i]};
3246 my $commit = $co{'id'};
3248 my $ref = format_ref_marker
($refs, $commit);
3251 print "<tr class=\"dark\">\n";
3253 print "<tr class=\"light\">\n";
3256 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3257 # shortlog uses chop_str($co{'author_name'}, 10)
3258 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3260 # originally git_history used chop_str($co{'title'}, 50)
3261 print format_subject_html
($co{'title'}, $co{'title_short'},
3262 href
(action
=>"commit", hash
=>$commit), $ref);
3264 "<td class=\"link\">" .
3265 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3266 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3268 if ($ftype eq 'blob') {
3269 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3270 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3271 if (defined $blob_current && defined $blob_parent &&
3272 $blob_current ne $blob_parent) {
3274 $cgi->a({-href
=> href
(action
=>"blobdiff",
3275 hash
=>$blob_current, hash_parent
=>$blob_parent,
3276 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3277 file_name
=>$file_name)},
3284 if (defined $extra) {
3286 "<td colspan=\"4\">$extra</td>\n" .
3293 # uses global variable $project
3294 my ($taglist, $from, $to, $extra) = @_;
3295 $from = 0 unless defined $from;
3296 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3298 print "<table class=\"tags\" cellspacing=\"0\">\n";
3300 for (my $i = $from; $i <= $to; $i++) {
3301 my $entry = $taglist->[$i];
3303 my $comment = $tag{'subject'};
3305 if (defined $comment) {
3306 $comment_short = chop_str
($comment, 30, 5);
3309 print "<tr class=\"dark\">\n";
3311 print "<tr class=\"light\">\n";
3314 if (defined $tag{'age'}) {
3315 print "<td><i>$tag{'age'}</i></td>\n";
3317 print "<td></td>\n";
3320 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3321 -class => "list name"}, esc_html
($tag{'name'})) .
3324 if (defined $comment) {
3325 print format_subject_html
($comment, $comment_short,
3326 href
(action
=>"tag", hash
=>$tag{'id'}));
3329 "<td class=\"selflink\">";
3330 if ($tag{'type'} eq "tag") {
3331 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3336 "<td class=\"link\">" . " | " .
3337 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3338 if ($tag{'reftype'} eq "commit") {
3339 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3340 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3341 } elsif ($tag{'reftype'} eq "blob") {
3342 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3347 if (defined $extra) {
3349 "<td colspan=\"5\">$extra</td>\n" .
3355 sub git_heads_body
{
3356 # uses global variable $project
3357 my ($headlist, $head, $from, $to, $extra) = @_;
3358 $from = 0 unless defined $from;
3359 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3361 print "<table class=\"heads\" cellspacing=\"0\">\n";
3363 for (my $i = $from; $i <= $to; $i++) {
3364 my $entry = $headlist->[$i];
3366 my $curr = $ref{'id'} eq $head;
3368 print "<tr class=\"dark\">\n";
3370 print "<tr class=\"light\">\n";
3373 print "<td><i>$ref{'age'}</i></td>\n" .
3374 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3375 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3376 -class => "list name"},esc_html
($ref{'name'})) .
3378 "<td class=\"link\">" .
3379 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3380 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3381 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3385 if (defined $extra) {
3387 "<td colspan=\"3\">$extra</td>\n" .
3393 sub git_search_grep_body
{
3394 my ($commitlist, $from, $to, $extra) = @_;
3395 $from = 0 unless defined $from;
3396 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3398 print "<table class=\"grep\" cellspacing=\"0\">\n";
3400 for (my $i = $from; $i <= $to; $i++) {
3401 my %co = %{$commitlist->[$i]};
3405 my $commit = $co{'id'};
3407 print "<tr class=\"dark\">\n";
3409 print "<tr class=\"light\">\n";
3412 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3413 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3415 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3416 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3417 my $comment = $co{'comment'};
3418 foreach my $line (@
$comment) {
3419 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3420 my $lead = esc_html
($1) || "";
3421 $lead = chop_str
($lead, 30, 10);
3422 my $match = esc_html
($2) || "";
3423 my $trail = esc_html
($3) || "";
3424 $trail = chop_str
($trail, 30, 10);
3425 my $text = "$lead<span class=\"match\">$match</span>$trail";
3426 print chop_str
($text, 80, 5) . "<br/>\n";
3430 "<td class=\"link\">" .
3431 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3433 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3437 if (defined $extra) {
3439 "<td colspan=\"3\">$extra</td>\n" .
3445 ## ======================================================================
3446 ## ======================================================================
3449 sub git_project_list
{
3450 my $order = $cgi->param('o');
3451 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3452 die_error
(undef, "Unknown order parameter");
3455 my @list = git_get_projects_list
();
3457 die_error
(undef, "No projects found");
3461 if (-f
$home_text) {
3462 print "<div class=\"index_include\">\n";
3463 open (my $fd, $home_text);
3468 git_project_list_body
(\
@list, $order);
3473 my $order = $cgi->param('o');
3474 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3475 die_error
(undef, "Unknown order parameter");
3478 my @list = git_get_projects_list
($project);
3480 die_error
(undef, "No forks found");
3484 git_print_page_nav
('','');
3485 git_print_header_div
('summary', "$project forks");
3486 git_project_list_body
(\
@list, $order);
3490 sub git_project_index
{
3491 my @projects = git_get_projects_list
($project);
3494 -type
=> 'text/plain',
3495 -charset
=> 'utf-8',
3496 -content_disposition
=> 'inline; filename="index.aux"');
3498 foreach my $pr (@projects) {
3499 if (!exists $pr->{'owner'}) {
3500 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3503 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3504 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3505 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3506 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3510 print "$path $owner\n";
3515 my $descr = git_get_project_description
($project) || "none";
3516 my %co = parse_commit
("HEAD");
3517 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3518 my $head = $co{'id'};
3520 my $owner = git_get_project_owner
($project);
3522 my $refs = git_get_references
();
3523 # These get_*_list functions return one more to allow us to see if
3524 # there are more ...
3525 my @taglist = git_get_tags_list
(16);
3526 my @headlist = git_get_heads_list
(16);
3528 my ($check_forks) = gitweb_check_feature
('forks');
3531 @forklist = git_get_projects_list
($project);
3535 git_print_page_nav
('summary','', $head);
3537 print "<div class=\"title\"> </div>\n";
3538 print "<table cellspacing=\"0\">\n" .
3539 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3540 "<tr><td>owner</td><td>$owner</td></tr>\n";
3541 if (defined $cd{'rfc2822'}) {
3542 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3545 # use per project git URL list in $projectroot/$project/cloneurl
3546 # or make project git URL from git base URL and project name
3547 my $url_tag = "URL";
3548 my @url_list = git_get_project_url_list
($project);
3549 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3550 foreach my $git_url (@url_list) {
3551 next unless $git_url;
3552 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3557 if (-s
"$projectroot/$project/README.html") {
3558 if (open my $fd, "$projectroot/$project/README.html") {
3559 print "<div class=\"title\">readme</div>\n";
3560 print $_ while (<$fd>);
3565 # we need to request one more than 16 (0..15) to check if
3567 my @commitlist = $head ? parse_commits
($head, 17) : ();
3569 git_print_header_div
('shortlog');
3570 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3571 $#commitlist <= 15 ?
undef :
3572 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3576 git_print_header_div
('tags');
3577 git_tags_body
(\
@taglist, 0, 15,
3578 $#taglist <= 15 ?
undef :
3579 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3583 git_print_header_div
('heads');
3584 git_heads_body
(\
@headlist, $head, 0, 15,
3585 $#headlist <= 15 ?
undef :
3586 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3590 git_print_header_div
('forks');
3591 git_project_list_body
(\
@forklist, undef, 0, 15,
3592 $#forklist <= 15 ?
undef :
3593 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3601 my $head = git_get_head_hash
($project);
3603 git_print_page_nav
('','', $head,undef,$head);
3604 my %tag = parse_tag
($hash);
3607 die_error
(undef, "Unknown tag object");
3610 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3611 print "<div class=\"title_text\">\n" .
3612 "<table cellspacing=\"0\">\n" .
3614 "<td>object</td>\n" .
3615 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3616 $tag{'object'}) . "</td>\n" .
3617 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3618 $tag{'type'}) . "</td>\n" .
3620 if (defined($tag{'author'})) {
3621 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3622 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3623 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3624 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3627 print "</table>\n\n" .
3629 print "<div class=\"page_body\">";
3630 my $comment = $tag{'comment'};
3631 foreach my $line (@
$comment) {
3633 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3643 my ($have_blame) = gitweb_check_feature
('blame');
3645 die_error
('403 Permission denied', "Permission denied");
3647 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3648 $hash_base ||= git_get_head_hash
($project);
3649 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3650 my %co = parse_commit
($hash_base)
3651 or die_error
(undef, "Reading commit failed");
3652 if (!defined $hash) {
3653 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3654 or die_error
(undef, "Error looking up file");
3656 $ftype = git_get_type
($hash);
3657 if ($ftype !~ "blob") {
3658 die_error
('400 Bad Request', "Object is not a blob");
3660 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3661 $file_name, $hash_base)
3662 or die_error
(undef, "Open git-blame failed");
3665 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3668 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3671 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3673 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3674 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3675 git_print_page_path
($file_name, $ftype, $hash_base);
3676 my @rev_color = (qw(light2 dark2));
3677 my $num_colors = scalar(@rev_color);
3678 my $current_color = 0;
3681 <div class="page_body">
3682 <table class="blame">
3683 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3688 last unless defined $_;
3689 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3690 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3691 if (!exists $metainfo{$full_rev}) {
3692 $metainfo{$full_rev} = {};
3694 my $meta = $metainfo{$full_rev};
3697 if (/^(\S+) (.*)$/) {
3703 my $rev = substr($full_rev, 0, 8);
3704 my $author = $meta->{'author'};
3705 my %date = parse_date
($meta->{'author-time'},
3706 $meta->{'author-tz'});
3707 my $date = $date{'iso-tz'};
3709 $current_color = ++$current_color % $num_colors;
3711 print "<tr class=\"$rev_color[$current_color]\">\n";
3713 print "<td class=\"sha1\"";
3714 print " title=\"". esc_html
($author) . ", $date\"";
3715 print " rowspan=\"$group_size\"" if ($group_size > 1);
3717 print $cgi->a({-href
=> href
(action
=>"commit",
3719 file_name
=>$file_name)},
3723 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3724 or die_error
(undef, "Open git-rev-parse failed");
3725 my $parent_commit = <$dd>;
3727 chomp($parent_commit);
3728 my $blamed = href
(action
=> 'blame',
3729 file_name
=> $meta->{'filename'},
3730 hash_base
=> $parent_commit);
3731 print "<td class=\"linenr\">";
3732 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3734 -class => "linenr" },
3737 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3743 or print "Reading blob failed\n";
3750 my ($have_blame) = gitweb_check_feature
('blame');
3752 die_error
('403 Permission denied', "Permission denied");
3754 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3755 $hash_base ||= git_get_head_hash
($project);
3756 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3757 my %co = parse_commit
($hash_base)
3758 or die_error
(undef, "Reading commit failed");
3759 if (!defined $hash) {
3760 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3761 or die_error
(undef, "Error lookup file");
3763 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3764 or die_error
(undef, "Open git-annotate failed");
3767 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3770 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3773 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3775 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3776 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3777 git_print_page_path
($file_name, 'blob', $hash_base);
3778 print "<div class=\"page_body\">\n";
3780 <table class="blame">
3789 my @line_class = (qw(light dark));
3790 my $line_class_len = scalar (@line_class);
3791 my $line_class_num = $#line_class;
3792 while (my $line = <$fd>) {
3804 $line_class_num = ($line_class_num + 1) % $line_class_len;
3806 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3813 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
3816 $short_rev = substr ($long_rev, 0, 8);
3817 $age = time () - $time;
3818 $age_str = age_string
($age);
3819 $age_str =~ s/ / /g;
3820 $age_class = age_class
($age);
3821 $author = esc_html
($author);
3822 $author =~ s/ / /g;
3824 $data = untabify
($data);
3825 $data = esc_html
($data);
3828 <tr class="$line_class[$line_class_num]">
3829 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3830 <td class="$age_class">$age_str</td>
3832 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3833 <td class="pre">$data</td>
3836 } # while (my $line = <$fd>)
3837 print "</table>\n\n";
3839 or print "Reading blob failed.\n";
3845 my $head = git_get_head_hash
($project);
3847 git_print_page_nav
('','', $head,undef,$head);
3848 git_print_header_div
('summary', $project);
3850 my @tagslist = git_get_tags_list
();
3852 git_tags_body
(\
@tagslist);
3858 my $head = git_get_head_hash
($project);
3860 git_print_page_nav
('','', $head,undef,$head);
3861 git_print_header_div
('summary', $project);
3863 my @headslist = git_get_heads_list
();
3865 git_heads_body
(\
@headslist, $head);
3870 sub git_blob_plain
{
3873 if (!defined $hash) {
3874 if (defined $file_name) {
3875 my $base = $hash_base || git_get_head_hash
($project);
3876 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3877 or die_error
(undef, "Error lookup file");
3879 die_error
(undef, "No file name defined");
3881 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3882 # blobs defined by non-textual hash id's can be cached
3887 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3888 or die_error
(undef, "Couldn't cat $file_name, $hash");
3890 $type ||= blob_mimetype
($fd, $file_name);
3892 # save as filename, even when no $file_name is given
3893 my $save_as = "$hash";
3894 if (defined $file_name) {
3895 $save_as = $file_name;
3896 } elsif ($type =~ m/^text\//) {
3903 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3905 binmode STDOUT
, ':raw';
3907 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3915 if (!defined $hash) {
3916 if (defined $file_name) {
3917 my $base = $hash_base || git_get_head_hash
($project);
3918 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3919 or die_error
(undef, "Error lookup file");
3921 die_error
(undef, "No file name defined");
3923 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3924 # blobs defined by non-textual hash id's can be cached
3928 my ($have_blame) = gitweb_check_feature
('blame');
3929 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3930 or die_error
(undef, "Couldn't cat $file_name, $hash");
3931 my $mimetype = blob_mimetype
($fd, $file_name);
3932 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3934 return git_blob_plain
($mimetype);
3936 # we can have blame only for text/* mimetype
3937 $have_blame &&= ($mimetype =~ m!^text/!);
3939 git_header_html
(undef, $expires);
3940 my $formats_nav = '';
3941 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3942 if (defined $file_name) {
3945 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3946 hash
=>$hash, file_name
=>$file_name)},
3951 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3952 hash
=>$hash, file_name
=>$file_name)},
3955 $cgi->a({-href
=> href
(action
=>"blob_plain",
3956 hash
=>$hash, file_name
=>$file_name)},
3959 $cgi->a({-href
=> href
(action
=>"blob",
3960 hash_base
=>"HEAD", file_name
=>$file_name)},
3964 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3966 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3967 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3969 print "<div class=\"page_nav\">\n" .
3970 "<br/><br/></div>\n" .
3971 "<div class=\"title\">$hash</div>\n";
3973 git_print_page_path
($file_name, "blob", $hash_base);
3974 print "<div class=\"page_body\">\n";
3975 if ($mimetype =~ m!^text/!) {
3977 while (my $line = <$fd>) {
3980 $line = untabify
($line);
3981 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3982 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3984 } elsif ($mimetype =~ m!^image/!) {
3985 print qq!<img type
="$mimetype"!;
3987 print qq! alt
="$file_name" title
="$file_name"!;
3990 href(action=>"blob_plain
", hash=>$hash,
3991 hash_base=>$hash_base, file_name=>$file_name) .
3995 or print "Reading blob failed.\n";
4001 my $have_snapshot = gitweb_have_snapshot
();
4003 if (!defined $hash_base) {
4004 $hash_base = "HEAD";
4006 if (!defined $hash) {
4007 if (defined $file_name) {
4008 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4014 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4015 or die_error
(undef, "Open git-ls-tree failed");
4016 my @entries = map { chomp; $_ } <$fd>;
4017 close $fd or die_error
(undef, "Reading tree failed");
4020 my $refs = git_get_references
();
4021 my $ref = format_ref_marker
($refs, $hash_base);
4024 my ($have_blame) = gitweb_check_feature
('blame');
4025 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4027 if (defined $file_name) {
4029 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4030 hash
=>$hash, file_name
=>$file_name)},
4032 $cgi->a({-href
=> href
(action
=>"tree",
4033 hash_base
=>"HEAD", file_name
=>$file_name)},
4036 if ($have_snapshot) {
4037 # FIXME: Should be available when we have no hash base as well.
4039 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
4042 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4043 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4046 print "<div class=\"page_nav\">\n";
4047 print "<br/><br/></div>\n";
4048 print "<div class=\"title\">$hash</div>\n";
4050 if (defined $file_name) {
4051 $basedir = $file_name;
4052 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4056 git_print_page_path
($file_name, 'tree', $hash_base);
4057 print "<div class=\"page_body\">\n";
4058 print "<table cellspacing=\"0\">\n";
4060 # '..' (top directory) link if possible
4061 if (defined $hash_base &&
4062 defined $file_name && $file_name =~ m![^/]+$!) {
4064 print "<tr class=\"dark\">\n";
4066 print "<tr class=\"light\">\n";
4070 my $up = $file_name;
4071 $up =~ s!/?[^/]+$!!;
4072 undef $up unless $up;
4073 # based on git_print_tree_entry
4074 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4075 print '<td class="list">';
4076 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4080 print "<td class=\"link\"></td>\n";
4084 foreach my $line (@entries) {
4085 my %t = parse_ls_tree_line
($line, -z
=> 1);
4088 print "<tr class=\"dark\">\n";
4090 print "<tr class=\"light\">\n";
4094 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4098 print "</table>\n" .
4104 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
4105 my $have_snapshot = (defined $ctype && defined $suffix);
4106 if (!$have_snapshot) {
4107 die_error
('403 Permission denied', "Permission denied");
4110 if (!defined $hash) {
4111 $hash = git_get_head_hash
($project);
4114 my $git = git_cmd_str
();
4115 my $name = $project;
4116 $name =~ s/\047/\047\\\047\047/g;
4117 my $filename = to_utf8
(basename
($project));
4119 if ($suffix eq 'zip') {
4120 $filename .= "-$hash.$suffix";
4121 $cmd = "$git archive --format=zip --prefix=\'$name\'/ $hash";
4123 $filename .= "-$hash.tar.$suffix";
4124 $cmd = "$git archive --format=tar --prefix=\'$name\'/ $hash | $command";
4128 -type
=> "application/$ctype",
4129 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4130 -status
=> '200 OK');
4132 open my $fd, "-|", $cmd
4133 or die_error
(undef, "Execute git-archive failed");
4134 binmode STDOUT
, ':raw';
4136 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4142 my $head = git_get_head_hash
($project);
4143 if (!defined $hash) {
4146 if (!defined $page) {
4149 my $refs = git_get_references
();
4151 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4153 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4156 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4159 my %co = parse_commit
($hash);
4161 git_print_header_div
('summary', $project);
4162 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4164 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4165 for (my $i = 0; $i <= $to; $i++) {
4166 my %co = %{$commitlist[$i]};
4168 my $commit = $co{'id'};
4169 my $ref = format_ref_marker
($refs, $commit);
4170 my %ad = parse_date
($co{'author_epoch'});
4171 git_print_header_div
('commit',
4172 "<span class=\"age\">$co{'age_string'}</span>" .
4173 esc_html
($co{'title'}) . $ref,
4175 print "<div class=\"title_text\">\n" .
4176 "<div class=\"log_link\">\n" .
4177 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4179 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4181 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4184 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4187 print "<div class=\"log_body\">\n";
4188 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4191 if ($#commitlist >= 100) {
4192 print "<div class=\"page_nav\">\n";
4193 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4194 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4201 $hash ||= $hash_base || "HEAD";
4202 my %co = parse_commit
($hash);
4204 die_error
(undef, "Unknown commit object");
4206 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4207 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4209 my $parent = $co{'parent'};
4210 my $parents = $co{'parents'}; # listref
4212 # we need to prepare $formats_nav before any parameter munging
4214 if (!defined $parent) {
4216 $formats_nav .= '(initial)';
4217 } elsif (@
$parents == 1) {
4218 # single parent commit
4221 $cgi->a({-href
=> href
(action
=>"commit",
4223 esc_html
(substr($parent, 0, 7))) .
4230 $cgi->a({-href
=> href
(action
=>"commit",
4232 esc_html
(substr($_, 0, 7)));
4237 if (!defined $parent) {
4241 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4243 (@
$parents <= 1 ?
$parent : '-c'),
4245 or die_error
(undef, "Open git-diff-tree failed");
4246 @difftree = map { chomp; $_ } <$fd>;
4247 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4249 # non-textual hash id's can be cached
4251 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4254 my $refs = git_get_references
();
4255 my $ref = format_ref_marker
($refs, $co{'id'});
4257 my $have_snapshot = gitweb_have_snapshot
();
4259 git_header_html
(undef, $expires);
4260 git_print_page_nav
('commit', '',
4261 $hash, $co{'tree'}, $hash,
4264 if (defined $co{'parent'}) {
4265 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4267 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4269 print "<div class=\"title_text\">\n" .
4270 "<table cellspacing=\"0\">\n";
4271 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4273 "<td></td><td> $ad{'rfc2822'}";
4274 if ($ad{'hour_local'} < 6) {
4275 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4276 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4278 printf(" (%02d:%02d %s)",
4279 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4283 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4284 print "<tr><td></td><td> $cd{'rfc2822'}" .
4285 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4287 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4290 "<td class=\"sha1\">" .
4291 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4292 class => "list"}, $co{'tree'}) .
4294 "<td class=\"link\">" .
4295 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4297 if ($have_snapshot) {
4299 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4304 foreach my $par (@
$parents) {
4307 "<td class=\"sha1\">" .
4308 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4309 class => "list"}, $par) .
4311 "<td class=\"link\">" .
4312 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4314 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4321 print "<div class=\"page_body\">\n";
4322 git_print_log
($co{'comment'});
4325 git_difftree_body
(\
@difftree, $hash, @
$parents);
4331 # object is defined by:
4332 # - hash or hash_base alone
4333 # - hash_base and file_name
4336 # - hash or hash_base alone
4337 if ($hash || ($hash_base && !defined $file_name)) {
4338 my $object_id = $hash || $hash_base;
4340 my $git_command = git_cmd_str
();
4341 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4342 or die_error
('404 Not Found', "Object does not exist");
4346 or die_error
('404 Not Found', "Object does not exist");
4348 # - hash_base and file_name
4349 } elsif ($hash_base && defined $file_name) {
4350 $file_name =~ s
,/+$,,;
4352 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4353 or die_error
('404 Not Found', "Base object does not exist");
4355 # here errors should not hapen
4356 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4357 or die_error
(undef, "Open git-ls-tree failed");
4361 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4362 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4363 die_error
('404 Not Found', "File or directory for given base does not exist");
4368 die_error
('404 Not Found', "Not enough information to find object");
4371 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4372 hash
=>$hash, hash_base
=>$hash_base,
4373 file_name
=>$file_name),
4374 -status
=> '302 Found');
4378 my $format = shift || 'html';
4385 # preparing $fd and %diffinfo for git_patchset_body
4387 if (defined $hash_base && defined $hash_parent_base) {
4388 if (defined $file_name) {
4390 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4391 $hash_parent_base, $hash_base,
4392 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4393 or die_error
(undef, "Open git-diff-tree failed");
4394 @difftree = map { chomp; $_ } <$fd>;
4396 or die_error
(undef, "Reading git-diff-tree failed");
4398 or die_error
('404 Not Found', "Blob diff not found");
4400 } elsif (defined $hash &&
4401 $hash =~ /[0-9a-fA-F]{40}/) {
4402 # try to find filename from $hash
4404 # read filtered raw output
4405 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4406 $hash_parent_base, $hash_base, "--"
4407 or die_error
(undef, "Open git-diff-tree failed");
4409 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4411 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4412 map { chomp; $_ } <$fd>;
4414 or die_error
(undef, "Reading git-diff-tree failed");
4416 or die_error
('404 Not Found', "Blob diff not found");
4419 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4422 if (@difftree > 1) {
4423 die_error
('404 Not Found', "Ambiguous blob diff specification");
4426 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4427 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4428 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4430 $hash_parent ||= $diffinfo{'from_id'};
4431 $hash ||= $diffinfo{'to_id'};
4433 # non-textual hash id's can be cached
4434 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4435 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4440 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4441 '-p', ($format eq 'html' ?
"--full-index" : ()),
4442 $hash_parent_base, $hash_base,
4443 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4444 or die_error
(undef, "Open git-diff-tree failed");
4447 # old/legacy style URI
4448 if (!%diffinfo && # if new style URI failed
4449 defined $hash && defined $hash_parent) {
4450 # fake git-diff-tree raw output
4451 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4452 $diffinfo{'from_id'} = $hash_parent;
4453 $diffinfo{'to_id'} = $hash;
4454 if (defined $file_name) {
4455 if (defined $file_parent) {
4456 $diffinfo{'status'} = '2';
4457 $diffinfo{'from_file'} = $file_parent;
4458 $diffinfo{'to_file'} = $file_name;
4459 } else { # assume not renamed
4460 $diffinfo{'status'} = '1';
4461 $diffinfo{'from_file'} = $file_name;
4462 $diffinfo{'to_file'} = $file_name;
4464 } else { # no filename given
4465 $diffinfo{'status'} = '2';
4466 $diffinfo{'from_file'} = $hash_parent;
4467 $diffinfo{'to_file'} = $hash;
4470 # non-textual hash id's can be cached
4471 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4472 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4477 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4478 '-p', ($format eq 'html' ?
"--full-index" : ()),
4479 $hash_parent, $hash, "--"
4480 or die_error
(undef, "Open git-diff failed");
4482 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4487 if ($format eq 'html') {
4489 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4490 hash
=>$hash, hash_parent
=>$hash_parent,
4491 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4492 file_name
=>$file_name, file_parent
=>$file_parent)},
4494 git_header_html
(undef, $expires);
4495 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4496 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4497 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4499 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4500 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4502 if (defined $file_name) {
4503 git_print_page_path
($file_name, "blob", $hash_base);
4505 print "<div class=\"page_path\"></div>\n";
4508 } elsif ($format eq 'plain') {
4510 -type
=> 'text/plain',
4511 -charset
=> 'utf-8',
4512 -expires
=> $expires,
4513 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4515 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4518 die_error
(undef, "Unknown blobdiff format");
4522 if ($format eq 'html') {
4523 print "<div class=\"page_body\">\n";
4525 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4528 print "</div>\n"; # class="page_body"
4532 while (my $line = <$fd>) {
4533 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4534 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4538 last if $line =~ m!^\+\+\+!;
4546 sub git_blobdiff_plain
{
4547 git_blobdiff
('plain');
4550 sub git_commitdiff
{
4551 my $format = shift || 'html';
4552 $hash ||= $hash_base || "HEAD";
4553 my %co = parse_commit
($hash);
4555 die_error
(undef, "Unknown commit object");
4558 # we need to prepare $formats_nav before any parameter munging
4560 if ($format eq 'html') {
4562 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4563 hash
=>$hash, hash_parent
=>$hash_parent)},
4566 if (defined $hash_parent) {
4567 # commitdiff with two commits given
4568 my $hash_parent_short = $hash_parent;
4569 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4570 $hash_parent_short = substr($hash_parent, 0, 7);
4574 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
4575 if ($co{'parents'}[$i] eq $hash_parent) {
4576 $formats_nav .= ' parent ' . ($i+1);
4580 $formats_nav .= ': ' .
4581 $cgi->a({-href
=> href
(action
=>"commitdiff",
4582 hash
=>$hash_parent)},
4583 esc_html
($hash_parent_short)) .
4585 } elsif (!$co{'parent'}) {
4587 $formats_nav .= ' (initial)';
4588 } elsif (scalar @
{$co{'parents'}} == 1) {
4589 # single parent commit
4592 $cgi->a({-href
=> href
(action
=>"commitdiff",
4593 hash
=>$co{'parent'})},
4594 esc_html
(substr($co{'parent'}, 0, 7))) .
4601 $cgi->a({-href
=> href
(action
=>"commitdiff",
4603 esc_html
(substr($_, 0, 7)));
4604 } @
{$co{'parents'}} ) .
4609 my $hash_parent_param = $hash_parent;
4610 if (!defined $hash_parent) {
4611 $hash_parent_param =
4612 @
{$co{'parents'}} > 1 ?
'-c' : $co{'parent'} || '--root';
4618 if ($format eq 'html') {
4619 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4620 "--no-commit-id", "--patch-with-raw", "--full-index",
4621 $hash_parent_param, $hash, "--"
4622 or die_error
(undef, "Open git-diff-tree failed");
4624 while (my $line = <$fd>) {
4626 # empty line ends raw part of diff-tree output
4628 push @difftree, scalar parse_difftree_raw_line
($line);
4631 } elsif ($format eq 'plain') {
4632 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4633 '-p', $hash_parent_param, $hash, "--"
4634 or die_error
(undef, "Open git-diff-tree failed");
4637 die_error
(undef, "Unknown commitdiff format");
4640 # non-textual hash id's can be cached
4642 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4646 # write commit message
4647 if ($format eq 'html') {
4648 my $refs = git_get_references
();
4649 my $ref = format_ref_marker
($refs, $co{'id'});
4651 git_header_html
(undef, $expires);
4652 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4653 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4654 git_print_authorship
(\
%co);
4655 print "<div class=\"page_body\">\n";
4656 if (@
{$co{'comment'}} > 1) {
4657 print "<div class=\"log\">\n";
4658 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4659 print "</div>\n"; # class="log"
4662 } elsif ($format eq 'plain') {
4663 my $refs = git_get_references
("tags");
4664 my $tagname = git_get_rev_name_tags
($hash);
4665 my $filename = basename
($project) . "-$hash.patch";
4668 -type
=> 'text/plain',
4669 -charset
=> 'utf-8',
4670 -expires
=> $expires,
4671 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4672 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4675 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4676 Subject: $co{'title'}
4678 print "X-Git-Tag: $tagname\n" if $tagname;
4679 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4681 foreach my $line (@
{$co{'comment'}}) {
4688 if ($format eq 'html') {
4689 git_difftree_body
(\
@difftree, $hash, $hash_parent || @
{$co{'parents'}});
4692 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @
{$co{'parents'}});
4694 print "</div>\n"; # class="page_body"
4697 } elsif ($format eq 'plain') {
4701 or print "Reading git-diff-tree failed\n";
4705 sub git_commitdiff_plain
{
4706 git_commitdiff
('plain');
4710 if (!defined $hash_base) {
4711 $hash_base = git_get_head_hash
($project);
4713 if (!defined $page) {
4717 my %co = parse_commit
($hash_base);
4719 die_error
(undef, "Unknown commit object");
4722 my $refs = git_get_references
();
4723 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4725 if (!defined $hash && defined $file_name) {
4726 $hash = git_get_hash_by_path
($hash_base, $file_name);
4728 if (defined $hash) {
4729 $ftype = git_get_type
($hash);
4732 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4734 my $paging_nav = '';
4737 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4738 file_name
=>$file_name)},
4740 $paging_nav .= " ⋅ " .
4741 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4742 file_name
=>$file_name, page
=>$page-1),
4743 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4745 $paging_nav .= "first";
4746 $paging_nav .= " ⋅ prev";
4748 if ($#commitlist >= 100) {
4749 $paging_nav .= " ⋅ " .
4750 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4751 file_name
=>$file_name, page
=>$page+1),
4752 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4754 $paging_nav .= " ⋅ next";
4757 if ($#commitlist >= 100) {
4759 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4760 file_name
=>$file_name, page
=>$page+1),
4761 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4765 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4766 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4767 git_print_page_path
($file_name, $ftype, $hash_base);
4769 git_history_body
(\
@commitlist, 0, 99,
4770 $refs, $hash_base, $ftype, $next_link);
4776 my ($have_search) = gitweb_check_feature
('search');
4777 if (!$have_search) {
4778 die_error
('403 Permission denied', "Permission denied");
4780 if (!defined $searchtext) {
4781 die_error
(undef, "Text field empty");
4783 if (!defined $hash) {
4784 $hash = git_get_head_hash
($project);
4786 my %co = parse_commit
($hash);
4788 die_error
(undef, "Unknown commit object");
4790 if (!defined $page) {
4794 $searchtype ||= 'commit';
4795 if ($searchtype eq 'pickaxe') {
4796 # pickaxe may take all resources of your box and run for several minutes
4797 # with every query - so decide by yourself how public you make this feature
4798 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4799 if (!$have_pickaxe) {
4800 die_error
('403 Permission denied', "Permission denied");
4803 if ($searchtype eq 'grep') {
4804 my ($have_grep) = gitweb_check_feature
('grep');
4806 die_error
('403 Permission denied', "Permission denied");
4812 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4814 if ($searchtype eq 'commit') {
4815 $greptype = "--grep=";
4816 } elsif ($searchtype eq 'author') {
4817 $greptype = "--author=";
4818 } elsif ($searchtype eq 'committer') {
4819 $greptype = "--committer=";
4821 $greptype .= $search_regexp;
4822 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4824 my $paging_nav = '';
4827 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4828 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4830 $paging_nav .= " ⋅ " .
4831 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4832 searchtext
=>$searchtext, searchtype
=>$searchtype,
4834 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4836 $paging_nav .= "first";
4837 $paging_nav .= " ⋅ prev";
4839 if ($#commitlist >= 100) {
4840 $paging_nav .= " ⋅ " .
4841 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4842 searchtext
=>$searchtext, searchtype
=>$searchtype,
4844 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4846 $paging_nav .= " ⋅ next";
4849 if ($#commitlist >= 100) {
4851 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4852 searchtext
=>$searchtext, searchtype
=>$searchtype,
4854 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4857 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4858 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4859 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4862 if ($searchtype eq 'pickaxe') {
4863 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4864 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4866 print "<table cellspacing=\"0\">\n";
4869 my $git_command = git_cmd_str
();
4870 my $searchqtext = $searchtext;
4871 $searchqtext =~ s/'/'\\''/;
4872 open my $fd, "-|", "$git_command rev-list $hash | " .
4873 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
4876 while (my $line = <$fd>) {
4877 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4880 $set{'from_id'} = $3;
4882 $set{'id'} = $set{'to_id'};
4883 if ($set{'id'} =~ m/0{40}/) {
4884 $set{'id'} = $set{'from_id'};
4886 if ($set{'id'} =~ m/0{40}/) {
4890 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4893 print "<tr class=\"dark\">\n";
4895 print "<tr class=\"light\">\n";
4898 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4899 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4901 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4902 -class => "list subject"},
4903 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4904 while (my $setref = shift @files) {
4906 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4907 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4909 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4913 "<td class=\"link\">" .
4914 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4916 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4920 %co = parse_commit
($1);
4928 if ($searchtype eq 'grep') {
4929 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4930 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4932 print "<table cellspacing=\"0\">\n";
4936 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
4938 while (my $line = <$fd>) {
4940 my ($file, $lno, $ltext, $binary);
4941 last if ($matches++ > 1000);
4942 if ($line =~ /^Binary file (.+) matches$/) {
4946 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
4948 if ($file ne $lastfile) {
4949 $lastfile and print "</td></tr>\n";
4951 print "<tr class=\"dark\">\n";
4953 print "<tr class=\"light\">\n";
4955 print "<td class=\"list\">".
4956 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4957 file_name
=>"$file"),
4958 -class => "list"}, esc_path
($file));
4959 print "</td><td>\n";
4963 print "<div class=\"binary\">Binary file</div>\n";
4965 $ltext = untabify
($ltext);
4966 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
4967 $ltext = esc_html
($1, -nbsp
=>1);
4968 $ltext .= '<span class="match">';
4969 $ltext .= esc_html
($2, -nbsp
=>1);
4970 $ltext .= '</span>';
4971 $ltext .= esc_html
($3, -nbsp
=>1);
4973 $ltext = esc_html
($ltext, -nbsp
=>1);
4975 print "<div class=\"pre\">" .
4976 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4977 file_name
=>"$file").'#l'.$lno,
4978 -class => "linenr"}, sprintf('%4i', $lno))
4979 . ' ' . $ltext . "</div>\n";
4983 print "</td></tr>\n";
4984 if ($matches > 1000) {
4985 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
4988 print "<div class=\"diff nodifferences\">No matches found</div>\n";
4997 sub git_search_help
{
4999 git_print_page_nav
('','', $hash,$hash,$hash);
5002 <dt><b>commit</b></dt>
5003 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5005 my ($have_grep) = gitweb_check_feature
('grep');
5008 <dt><b>grep</b></dt>
5009 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5010 a different one) are searched for the given
5011 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5012 (POSIX extended) and the matches are listed. On large
5013 trees, this search can take a while and put some strain on the server, so please use it with
5014 some consideration.</dd>
5018 <dt><b>author</b></dt>
5019 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5020 <dt><b>committer</b></dt>
5021 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5023 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5024 if ($have_pickaxe) {
5026 <dt><b>pickaxe</b></dt>
5027 <dd>All commits that caused the string to appear or disappear from any file (changes that
5028 added, removed or "modified" the string) will be listed. This search can take a while and
5029 takes a lot of strain on the server, so please use it wisely.</dd>
5037 my $head = git_get_head_hash
($project);
5038 if (!defined $hash) {
5041 if (!defined $page) {
5044 my $refs = git_get_references
();
5046 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5048 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5050 if ($#commitlist >= 100) {
5052 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5053 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5057 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5058 git_print_header_div
('summary', $project);
5060 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5065 ## ......................................................................
5066 ## feeds (RSS, Atom; OPML)
5069 my $format = shift || 'atom';
5070 my ($have_blame) = gitweb_check_feature
('blame');
5072 # Atom: http://www.atomenabled.org/developers/syndication/
5073 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5074 if ($format ne 'rss' && $format ne 'atom') {
5075 die_error
(undef, "Unknown web feed format");
5078 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5079 my $head = $hash || 'HEAD';
5080 my @commitlist = parse_commits
($head, 150);
5084 my $content_type = "application/$format+xml";
5085 if (defined $cgi->http('HTTP_ACCEPT') &&
5086 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5087 # browser (feed reader) prefers text/xml
5088 $content_type = 'text/xml';
5090 if (defined($commitlist[0])) {
5091 %latest_commit = %{$commitlist[0]};
5092 %latest_date = parse_date
($latest_commit{'author_epoch'});
5094 -type
=> $content_type,
5095 -charset
=> 'utf-8',
5096 -last_modified
=> $latest_date{'rfc2822'});
5099 -type
=> $content_type,
5100 -charset
=> 'utf-8');
5103 # Optimization: skip generating the body if client asks only
5104 # for Last-Modified date.
5105 return if ($cgi->request_method() eq 'HEAD');
5108 my $title = "$site_name - $project/$action";
5109 my $feed_type = 'log';
5110 if (defined $hash) {
5111 $title .= " - '$hash'";
5112 $feed_type = 'branch log';
5113 if (defined $file_name) {
5114 $title .= " :: $file_name";
5115 $feed_type = 'history';
5117 } elsif (defined $file_name) {
5118 $title .= " - $file_name";
5119 $feed_type = 'history';
5121 $title .= " $feed_type";
5122 my $descr = git_get_project_description
($project);
5123 if (defined $descr) {
5124 $descr = esc_html
($descr);
5126 $descr = "$project " .
5127 ($format eq 'rss' ?
'RSS' : 'Atom') .
5130 my $owner = git_get_project_owner
($project);
5131 $owner = esc_html
($owner);
5135 if (defined $file_name) {
5136 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5137 } elsif (defined $hash) {
5138 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5140 $alt_url = href
(-full
=>1, action
=>"summary");
5142 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5143 if ($format eq 'rss') {
5145 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5148 print "<title>$title</title>\n" .
5149 "<link>$alt_url</link>\n" .
5150 "<description>$descr</description>\n" .
5151 "<language>en</language>\n";
5152 } elsif ($format eq 'atom') {
5154 <feed xmlns="http://www.w3.org/2005/Atom">
5156 print "<title>$title</title>\n" .
5157 "<subtitle>$descr</subtitle>\n" .
5158 '<link rel="alternate" type="text/html" href="' .
5159 $alt_url . '" />' . "\n" .
5160 '<link rel="self" type="' . $content_type . '" href="' .
5161 $cgi->self_url() . '" />' . "\n" .
5162 "<id>" . href
(-full
=>1) . "</id>\n" .
5163 # use project owner for feed author
5164 "<author><name>$owner</name></author>\n";
5165 if (defined $favicon) {
5166 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5168 if (defined $logo_url) {
5169 # not twice as wide as tall: 72 x 27 pixels
5170 print "<logo>" . esc_url
($logo) . "</logo>\n";
5172 if (! %latest_date) {
5173 # dummy date to keep the feed valid until commits trickle in:
5174 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5176 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5181 for (my $i = 0; $i <= $#commitlist; $i++) {
5182 my %co = %{$commitlist[$i]};
5183 my $commit = $co{'id'};
5184 # we read 150, we always show 30 and the ones more recent than 48 hours
5185 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5188 my %cd = parse_date
($co{'author_epoch'});
5190 # get list of changed files
5191 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5192 $co{'parent'} || "--root",
5193 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5195 my @difftree = map { chomp; $_ } <$fd>;
5199 # print element (entry, item)
5200 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5201 if ($format eq 'rss') {
5203 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5204 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5205 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5206 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5207 "<link>$co_url</link>\n" .
5208 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5209 "<content:encoded>" .
5211 } elsif ($format eq 'atom') {
5213 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5214 "<updated>$cd{'iso-8601'}</updated>\n" .
5216 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5217 if ($co{'author_email'}) {
5218 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5220 print "</author>\n" .
5221 # use committer for contributor
5223 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5224 if ($co{'committer_email'}) {
5225 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5227 print "</contributor>\n" .
5228 "<published>$cd{'iso-8601'}</published>\n" .
5229 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5230 "<id>$co_url</id>\n" .
5231 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5232 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5234 my $comment = $co{'comment'};
5236 foreach my $line (@
$comment) {
5237 $line = esc_html
($line);
5240 print "</pre><ul>\n";
5241 foreach my $difftree_line (@difftree) {
5242 my %difftree = parse_difftree_raw_line
($difftree_line);
5243 next if !$difftree{'from_id'};
5245 my $file = $difftree{'file'} || $difftree{'to_file'};
5249 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5250 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5251 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5252 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5253 -title
=> "diff"}, 'D');
5255 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5256 file_name
=>$file, hash_base
=>$commit),
5257 -title
=> "blame"}, 'B');
5259 # if this is not a feed of a file history
5260 if (!defined $file_name || $file_name ne $file) {
5261 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5262 file_name
=>$file, hash
=>$commit),
5263 -title
=> "history"}, 'H');
5265 $file = esc_path
($file);
5269 if ($format eq 'rss') {
5270 print "</ul>]]>\n" .
5271 "</content:encoded>\n" .
5273 } elsif ($format eq 'atom') {
5274 print "</ul>\n</div>\n" .
5281 if ($format eq 'rss') {
5282 print "</channel>\n</rss>\n";
5283 } elsif ($format eq 'atom') {
5297 my @list = git_get_projects_list
();
5299 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5301 <?xml version="1.0" encoding="utf-8"?>
5302 <opml version="1.0">
5304 <title>$site_name OPML Export</title>
5307 <outline text="git RSS feeds">
5310 foreach my $pr (@list) {
5312 my $head = git_get_head_hash
($proj{'path'});
5313 if (!defined $head) {
5316 $git_dir = "$projectroot/$proj{'path'}";
5317 my %co = parse_commit
($head);
5322 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5323 my $rss = "$my_url?p=$proj{'path'};a=rss";
5324 my $html = "$my_url?p=$proj{'path'};a=summary";
5325 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";