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 # You define site-wide feature defaults here; override them with
98 # $GITWEB_CONFIG as necessary.
101 # 'sub' => feature-sub (subroutine),
102 # 'override' => allow-override (boolean),
103 # 'default' => [ default options...] (array reference)}
105 # if feature is overridable (it means that allow-override has true value,
106 # then feature-sub will be called with default options as parameters;
107 # return value of feature-sub indicates if to enable specified feature
109 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
111 # Enable the 'blame' blob view, showing the last commit that modified
112 # each line in the file. This can be very CPU-intensive.
114 # To enable system wide have in $GITWEB_CONFIG
115 # $feature{'blame'}{'default'} = [1];
116 # To have project specific config enable override in $GITWEB_CONFIG
117 # $feature{'blame'}{'override'} = 1;
118 # and in project config gitweb.blame = 0|1;
120 'sub' => \
&feature_blame
,
124 # Enable the 'snapshot' link, providing a compressed tarball of any
125 # tree. This can potentially generate high traffic if you have large
128 # To disable system wide have in $GITWEB_CONFIG
129 # $feature{'snapshot'}{'default'} = [undef];
130 # To have project specific config enable override in $GITWEB_CONFIG
131 # $feature{'snapshot'}{'override'} = 1;
132 # and in project config gitweb.snapshot = none|gzip|bzip2;
134 'sub' => \
&feature_snapshot
,
136 # => [content-encoding, suffix, program]
137 'default' => ['x-gzip', 'gz', 'gzip']},
139 # Enable text search, which will list the commits which match author,
140 # committer or commit text to a given string. Enabled by default.
145 # Enable the pickaxe search, which will list the commits that modified
146 # a given string in a file. This can be practical and quite faster
147 # alternative to 'blame', but still potentially CPU-intensive.
149 # To enable system wide have in $GITWEB_CONFIG
150 # $feature{'pickaxe'}{'default'} = [1];
151 # To have project specific config enable override in $GITWEB_CONFIG
152 # $feature{'pickaxe'}{'override'} = 1;
153 # and in project config gitweb.pickaxe = 0|1;
155 'sub' => \
&feature_pickaxe
,
159 # Make gitweb use an alternative format of the URLs which can be
160 # more readable and natural-looking: project name is embedded
161 # directly in the path and the query string contains other
162 # auxiliary information. All gitweb installations recognize
163 # URL in either format; this configures in which formats gitweb
166 # To enable system wide have in $GITWEB_CONFIG
167 # $feature{'pathinfo'}{'default'} = [1];
168 # Project specific override is not supported.
170 # Note that you will need to change the default location of CSS,
171 # favicon, logo and possibly other files to an absolute URL. Also,
172 # if gitweb.cgi serves as your indexfile, you will need to force
173 # $my_uri to contain the script name in your $GITWEB_CONFIG.
178 # Make gitweb consider projects in project root subdirectories
179 # to be forks of existing projects. Given project $projname.git,
180 # projects matching $projname/*.git will not be shown in the main
181 # projects list, instead a '+' mark will be added to $projname
182 # there and a 'forks' view will be enabled for the project, listing
183 # all the forks. If project list is taken from a file, forks have
184 # to be listed after the main project.
186 # To enable system wide have in $GITWEB_CONFIG
187 # $feature{'forks'}{'default'} = [1];
188 # Project specific override is not supported.
194 sub gitweb_check_feature
{
196 return unless exists $feature{$name};
197 my ($sub, $override, @defaults) = (
198 $feature{$name}{'sub'},
199 $feature{$name}{'override'},
200 @
{$feature{$name}{'default'}});
201 if (!$override) { return @defaults; }
203 warn "feature $name is not overrideable";
206 return $sub->(@defaults);
210 my ($val) = git_get_project_config
('blame', '--bool');
212 if ($val eq 'true') {
214 } elsif ($val eq 'false') {
221 sub feature_snapshot
{
222 my ($ctype, $suffix, $command) = @_;
224 my ($val) = git_get_project_config
('snapshot');
226 if ($val eq 'gzip') {
227 return ('x-gzip', 'gz', 'gzip');
228 } elsif ($val eq 'bzip2') {
229 return ('x-bzip2', 'bz2', 'bzip2');
230 } elsif ($val eq 'none') {
234 return ($ctype, $suffix, $command);
237 sub gitweb_have_snapshot
{
238 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
239 my $have_snapshot = (defined $ctype && defined $suffix);
241 return $have_snapshot;
244 sub feature_pickaxe
{
245 my ($val) = git_get_project_config
('pickaxe', '--bool');
247 if ($val eq 'true') {
249 } elsif ($val eq 'false') {
256 # checking HEAD file with -e is fragile if the repository was
257 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
259 sub check_head_link
{
261 my $headfile = "$dir/HEAD";
262 return ((-e
$headfile) ||
263 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
266 sub check_export_ok
{
268 return (check_head_link
($dir) &&
269 (!$export_ok || -e
"$dir/$export_ok"));
272 # rename detection options for git-diff and git-diff-tree
273 # - default is '-M', with the cost proportional to
274 # (number of removed files) * (number of new files).
275 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
276 # (number of changed files + number of removed files) * (number of new files)
277 # - even more costly is '-C', '--find-copies-harder' with cost
278 # (number of files in the original tree) * (number of new files)
279 # - one might want to include '-B' option, e.g. '-B', '-M'
280 our @diff_opts = ('-M'); # taken from git_commit
282 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
283 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
285 # version of the core git binary
286 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
288 $projects_list ||= $projectroot;
290 # ======================================================================
291 # input validation and dispatch
292 our $action = $cgi->param('a');
293 if (defined $action) {
294 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
295 die_error
(undef, "Invalid action parameter");
299 # parameters which are pathnames
300 our $project = $cgi->param('p');
301 if (defined $project) {
302 if (!validate_pathname
($project) ||
303 !(-d
"$projectroot/$project") ||
304 !check_head_link
("$projectroot/$project") ||
305 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
306 ($strict_export && !project_in_list
($project))) {
308 die_error
(undef, "No such project");
312 our $file_name = $cgi->param('f');
313 if (defined $file_name) {
314 if (!validate_pathname
($file_name)) {
315 die_error
(undef, "Invalid file parameter");
319 our $file_parent = $cgi->param('fp');
320 if (defined $file_parent) {
321 if (!validate_pathname
($file_parent)) {
322 die_error
(undef, "Invalid file parent parameter");
326 # parameters which are refnames
327 our $hash = $cgi->param('h');
329 if (!validate_refname
($hash)) {
330 die_error
(undef, "Invalid hash parameter");
334 our $hash_parent = $cgi->param('hp');
335 if (defined $hash_parent) {
336 if (!validate_refname
($hash_parent)) {
337 die_error
(undef, "Invalid hash parent parameter");
341 our $hash_base = $cgi->param('hb');
342 if (defined $hash_base) {
343 if (!validate_refname
($hash_base)) {
344 die_error
(undef, "Invalid hash base parameter");
348 our $hash_parent_base = $cgi->param('hpb');
349 if (defined $hash_parent_base) {
350 if (!validate_refname
($hash_parent_base)) {
351 die_error
(undef, "Invalid hash parent base parameter");
356 our $page = $cgi->param('pg');
358 if ($page =~ m/[^0-9]/) {
359 die_error
(undef, "Invalid page parameter");
363 our $searchtext = $cgi->param('s');
364 if (defined $searchtext) {
365 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
366 die_error
(undef, "Invalid search parameter");
368 if (length($searchtext) < 2) {
369 die_error
(undef, "At least two characters are required for search parameter");
371 $searchtext = quotemeta $searchtext;
374 our $searchtype = $cgi->param('st');
375 if (defined $searchtype) {
376 if ($searchtype =~ m/[^a-z]/) {
377 die_error
(undef, "Invalid searchtype parameter");
381 # now read PATH_INFO and use it as alternative to parameters
382 sub evaluate_path_info
{
383 return if defined $project;
384 my $path_info = $ENV{"PATH_INFO"};
385 return if !$path_info;
386 $path_info =~ s
,^/+,,;
387 return if !$path_info;
388 # find which part of PATH_INFO is project
389 $project = $path_info;
391 while ($project && !check_head_link
("$projectroot/$project")) {
392 $project =~ s
,/*[^/]*$,,;
395 $project = validate_pathname
($project);
397 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
398 ($strict_export && !project_in_list
($project))) {
402 # do not change any parameters if an action is given using the query string
404 $path_info =~ s
,^$project/*,,;
405 my ($refname, $pathname) = split(/:/, $path_info, 2);
406 if (defined $pathname) {
407 # we got "project.git/branch:filename" or "project.git/branch:dir/"
408 # we could use git_get_type(branch:pathname), but it needs $git_dir
409 $pathname =~ s
,^/+,,;
410 if (!$pathname || substr($pathname, -1) eq "/") {
414 $action ||= "blob_plain";
416 $hash_base ||= validate_refname
($refname);
417 $file_name ||= validate_pathname
($pathname);
418 } elsif (defined $refname) {
419 # we got "project.git/branch"
420 $action ||= "shortlog";
421 $hash ||= validate_refname
($refname);
424 evaluate_path_info
();
426 # path to the current git repository
428 $git_dir = "$projectroot/$project" if $project;
432 "blame" => \
&git_blame2
,
433 "blobdiff" => \
&git_blobdiff
,
434 "blobdiff_plain" => \
&git_blobdiff_plain
,
435 "blob" => \
&git_blob
,
436 "blob_plain" => \
&git_blob_plain
,
437 "commitdiff" => \
&git_commitdiff
,
438 "commitdiff_plain" => \
&git_commitdiff_plain
,
439 "commit" => \
&git_commit
,
440 "forks" => \
&git_forks
,
441 "heads" => \
&git_heads
,
442 "history" => \
&git_history
,
445 "atom" => \
&git_atom
,
446 "search" => \
&git_search
,
447 "search_help" => \
&git_search_help
,
448 "shortlog" => \
&git_shortlog
,
449 "summary" => \
&git_summary
,
451 "tags" => \
&git_tags
,
452 "tree" => \
&git_tree
,
453 "snapshot" => \
&git_snapshot
,
454 "object" => \
&git_object
,
455 # those below don't need $project
456 "opml" => \
&git_opml
,
457 "project_list" => \
&git_project_list
,
458 "project_index" => \
&git_project_index
,
461 if (defined $project) {
462 $action ||= 'summary';
464 $action ||= 'project_list';
466 if (!defined($actions{$action})) {
467 die_error
(undef, "Unknown action");
469 if ($action !~ m/^(opml|project_list|project_index)$/ &&
471 die_error
(undef, "Project needed");
473 $actions{$action}->();
476 ## ======================================================================
481 # default is to use -absolute url() i.e. $my_uri
482 my $href = $params{-full
} ?
$my_url : $my_uri;
484 # XXX: Warning: If you touch this, check the search form for updating,
495 hash_parent_base
=> "hpb",
501 my %mapping = @mapping;
503 $params{'project'} = $project unless exists $params{'project'};
505 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
507 # use PATH_INFO for project name
508 $href .= "/$params{'project'}" if defined $params{'project'};
509 delete $params{'project'};
511 # Summary just uses the project path URL
512 if (defined $params{'action'} && $params{'action'} eq 'summary') {
513 delete $params{'action'};
517 # now encode the parameters explicitly
519 for (my $i = 0; $i < @mapping; $i += 2) {
520 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
521 if (defined $params{$name}) {
522 push @result, $symbol . "=" . esc_param
($params{$name});
525 $href .= "?" . join(';', @result) if scalar @result;
531 ## ======================================================================
532 ## validation, quoting/unquoting and escaping
534 sub validate_pathname
{
535 my $input = shift || return undef;
537 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
538 # at the beginning, at the end, and between slashes.
539 # also this catches doubled slashes
540 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
544 if ($input =~ m!\0!) {
550 sub validate_refname
{
551 my $input = shift || return undef;
553 # textual hashes are O.K.
554 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
557 # it must be correct pathname
558 $input = validate_pathname
($input)
560 # restrictions on ref name according to git-check-ref-format
561 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
567 # quote unsafe chars, but keep the slash, even when it's not
568 # correct, but quoted slashes look too horrible in bookmarks
571 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
577 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
580 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
586 # replace invalid utf8 character with SUBSTITUTION sequence
591 $str = decode_utf8
($str);
592 $str = $cgi->escapeHTML($str);
593 if ($opts{'-nbsp'}) {
594 $str =~ s/ / /g;
596 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
600 # quote control characters and escape filename to HTML
605 $str = decode_utf8
($str);
606 $str = $cgi->escapeHTML($str);
607 if ($opts{'-nbsp'}) {
608 $str =~ s/ / /g;
610 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
614 # Make control characters "printable", using character escape codes (CEC)
617 my %es = ( # character escape codes, aka escape sequences
618 "\t" => '\t', # tab (HT)
619 "\n" => '\n', # line feed (LF)
620 "\r" => '\r', # carrige return (CR)
621 "\f" => '\f', # form feed (FF)
622 "\b" => '\b', # backspace (BS)
623 "\a" => '\a', # alarm (bell) (BEL)
624 "\e" => '\e', # escape (ESC)
625 "\013" => '\v', # vertical tab (VT)
626 "\000" => '\0', # nul character (NUL)
628 my $chr = ( (exists $es{$cntrl})
630 : sprintf('\%03o', ord($cntrl)) );
631 return "<span class=\"cntrl\">$chr</span>";
634 # Alternatively use unicode control pictures codepoints,
635 # Unicode "printable representation" (PR)
638 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
639 return "<span class=\"cntrl\">$chr</span>";
642 # git may return quoted and escaped filenames
648 my %es = ( # character escape codes, aka escape sequences
649 't' => "\t", # tab (HT, TAB)
650 'n' => "\n", # newline (NL)
651 'r' => "\r", # return (CR)
652 'f' => "\f", # form feed (FF)
653 'b' => "\b", # backspace (BS)
654 'a' => "\a", # alarm (bell) (BEL)
655 'e' => "\e", # escape (ESC)
656 'v' => "\013", # vertical tab (VT)
659 if ($seq =~ m/^[0-7]{1,3}$/) {
660 # octal char sequence
661 return chr(oct($seq));
662 } elsif (exists $es{$seq}) {
663 # C escape sequence, aka character escape code
666 # quoted ordinary character
670 if ($str =~ m/^"(.*)"$/) {
673 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
678 # escape tabs (convert tabs to spaces)
682 while ((my $pos = index($line, "\t")) != -1) {
683 if (my $count = (8 - ($pos % 8))) {
684 my $spaces = ' ' x
$count;
685 $line =~ s/\t/$spaces/;
692 sub project_in_list
{
694 my @list = git_get_projects_list
();
695 return @list && scalar(grep { $_->{'path'} eq $project } @list);
698 ## ----------------------------------------------------------------------
699 ## HTML aware string manipulation
704 my $add_len = shift || 10;
706 # allow only $len chars, but don't cut a word if it would fit in $add_len
707 # if it doesn't fit, cut it if it's still longer than the dots we would add
708 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
711 if (length($tail) > 4) {
713 $body =~ s/&[^;]*$//; # remove chopped character entities
718 ## ----------------------------------------------------------------------
719 ## functions returning short strings
721 # CSS class for given age value (in seconds)
725 if ($age < 60*60*2) {
727 } elsif ($age < 60*60*24*2) {
734 # convert age in seconds to "nn units ago" string
739 if ($age > 60*60*24*365*2) {
740 $age_str = (int $age/60/60/24/365);
741 $age_str .= " years ago";
742 } elsif ($age > 60*60*24*(365/12)*2) {
743 $age_str = int $age/60/60/24/(365/12);
744 $age_str .= " months ago";
745 } elsif ($age > 60*60*24*7*2) {
746 $age_str = int $age/60/60/24/7;
747 $age_str .= " weeks ago";
748 } elsif ($age > 60*60*24*2) {
749 $age_str = int $age/60/60/24;
750 $age_str .= " days ago";
751 } elsif ($age > 60*60*2) {
752 $age_str = int $age/60/60;
753 $age_str .= " hours ago";
754 } elsif ($age > 60*2) {
755 $age_str = int $age/60;
756 $age_str .= " min ago";
759 $age_str .= " sec ago";
761 $age_str .= " right now";
766 # convert file mode in octal to symbolic file mode string
768 my $mode = oct shift;
770 if (S_ISDIR
($mode & S_IFMT
)) {
772 } elsif (S_ISLNK
($mode)) {
774 } elsif (S_ISREG
($mode)) {
775 # git cares only about the executable bit
776 if ($mode & S_IXUSR
) {
786 # convert file mode in octal to file type string
790 if ($mode !~ m/^[0-7]+$/) {
796 if (S_ISDIR
($mode & S_IFMT
)) {
798 } elsif (S_ISLNK
($mode)) {
800 } elsif (S_ISREG
($mode)) {
807 # convert file mode in octal to file type description string
811 if ($mode !~ m/^[0-7]+$/) {
817 if (S_ISDIR
($mode & S_IFMT
)) {
819 } elsif (S_ISLNK
($mode)) {
821 } elsif (S_ISREG
($mode)) {
822 if ($mode & S_IXUSR
) {
833 ## ----------------------------------------------------------------------
834 ## functions returning short HTML fragments, or transforming HTML fragments
835 ## which don't belong to other sections
837 # format line of commit message.
838 sub format_log_line_html
{
841 $line = esc_html
($line, -nbsp
=>1);
842 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
845 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
846 -class => "text"}, $hash_text);
847 $line =~ s/$hash_text/$link/;
852 # format marker of refs pointing to given object
853 sub format_ref_marker
{
854 my ($refs, $id) = @_;
857 if (defined $refs->{$id}) {
858 foreach my $ref (@
{$refs->{$id}}) {
859 my ($type, $name) = qw();
860 # e.g. tags/v2.6.11 or heads/next
861 if ($ref =~ m!^(.*?)s?/(.*)$!) {
869 $markers .= " <span class=\"$type\" title=\"$ref\">" .
870 esc_html
($name) . "</span>";
875 return ' <span class="refs">'. $markers . '</span>';
881 # format, perhaps shortened and with markers, title line
882 sub format_subject_html
{
883 my ($long, $short, $href, $extra) = @_;
884 $extra = '' unless defined($extra);
886 if (length($short) < length($long)) {
887 return $cgi->a({-href
=> $href, -class => "list subject",
888 -title
=> decode_utf8
($long)},
889 esc_html
($short) . $extra);
891 return $cgi->a({-href
=> $href, -class => "list subject"},
892 esc_html
($long) . $extra);
896 # format patch (diff) line (rather not to be used for diff headers)
897 sub format_diff_line
{
899 my ($from, $to) = @_;
904 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
906 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
907 if ($line =~ m/^\@{3}/) {
908 $diff_class = " chunk_header";
909 } elsif ($line =~ m/^\\/) {
910 $diff_class = " incomplete";
911 } elsif ($prefix =~ tr/+/+/) {
912 $diff_class = " add";
913 } elsif ($prefix =~ tr/-/-/) {
914 $diff_class = " rem";
917 # assume ordinary diff
918 my $char = substr($line, 0, 1);
920 $diff_class = " add";
921 } elsif ($char eq '-') {
922 $diff_class = " rem";
923 } elsif ($char eq '@') {
924 $diff_class = " chunk_header";
925 } elsif ($char eq "\\") {
926 $diff_class = " incomplete";
929 $line = untabify
($line);
930 if ($from && $to && $line =~ m/^\@{2} /) {
931 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
932 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
934 $from_lines = 0 unless defined $from_lines;
935 $to_lines = 0 unless defined $to_lines;
937 if ($from->{'href'}) {
938 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
939 -class=>"list"}, $from_text);
942 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
943 -class=>"list"}, $to_text);
945 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
946 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
947 return "<div class=\"diff$diff_class\">$line</div>\n";
948 } elsif ($from && $to && $line =~ m/^\@{3}/) {
949 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
950 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
952 @from_text = split(' ', $ranges);
953 for (my $i = 0; $i < @from_text; ++$i) {
954 ($from_start[$i], $from_nlines[$i]) =
955 (split(',', substr($from_text[$i], 1)), 0);
958 $to_text = pop @from_text;
959 $to_start = pop @from_start;
960 $to_nlines = pop @from_nlines;
962 $line = "<span class=\"chunk_info\">$prefix ";
963 for (my $i = 0; $i < @from_text; ++$i) {
964 if ($from->{'href'}[$i]) {
965 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
966 -class=>"list"}, $from_text[$i]);
968 $line .= $from_text[$i];
973 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
974 -class=>"list"}, $to_text);
978 $line .= " $prefix</span>" .
979 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
980 return "<div class=\"diff$diff_class\">$line</div>\n";
982 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
985 ## ----------------------------------------------------------------------
986 ## git utility subroutines, invoking git commands
988 # returns path to the core git executable and the --git-dir parameter as list
990 return $GIT, '--git-dir='.$git_dir;
993 # returns path to the core git executable and the --git-dir parameter as string
995 return join(' ', git_cmd
());
998 # get HEAD ref of given project as hash
999 sub git_get_head_hash
{
1000 my $project = shift;
1001 my $o_git_dir = $git_dir;
1003 $git_dir = "$projectroot/$project";
1004 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1007 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1011 if (defined $o_git_dir) {
1012 $git_dir = $o_git_dir;
1017 # get type of given object
1021 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1023 close $fd or return;
1028 sub git_get_project_config
{
1029 my ($key, $type) = @_;
1031 return unless ($key);
1032 $key =~ s/^gitweb\.//;
1033 return if ($key =~ m/\W/);
1035 my @x = (git_cmd
(), 'config');
1036 if (defined $type) { push @x, $type; }
1038 push @x, "gitweb.$key";
1044 # get hash of given path at given ref
1045 sub git_get_hash_by_path
{
1047 my $path = shift || return undef;
1052 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1053 or die_error
(undef, "Open git-ls-tree failed");
1055 close $fd or return undef;
1057 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1058 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1059 if (defined $type && $type ne $2) {
1060 # type doesn't match
1066 # get path of entry with given hash at given tree-ish (ref)
1067 # used to get 'from' filename for combined diff (merge commit) for renames
1068 sub git_get_path_by_hash
{
1069 my $base = shift || return;
1070 my $hash = shift || return;
1074 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1076 while (my $line = <$fd>) {
1079 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1080 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1081 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1090 ## ......................................................................
1091 ## git utility functions, directly accessing git repository
1093 sub git_get_project_description
{
1096 open my $fd, "$projectroot/$path/description" or return undef;
1103 sub git_get_project_url_list
{
1106 open my $fd, "$projectroot/$path/cloneurl" or return;
1107 my @git_project_url_list = map { chomp; $_ } <$fd>;
1110 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1113 sub git_get_projects_list
{
1118 $filter =~ s/\.git$//;
1120 my ($check_forks) = gitweb_check_feature
('forks');
1122 if (-d
$projects_list) {
1123 # search in directory
1124 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1125 # remove the trailing "/"
1127 my $pfxlen = length("$dir");
1130 follow_fast
=> 1, # follow symbolic links
1131 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1133 # skip project-list toplevel, if we get it.
1134 return if (m!^[/.]$!);
1135 # only directories can be git repositories
1136 return unless (-d
$_);
1138 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1139 # we check related file in $projectroot
1140 if ($check_forks and $subdir =~ m
#/.#) {
1141 $File::Find
::prune
= 1;
1142 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1143 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1144 $File::Find
::prune
= 1;
1149 } elsif (-f
$projects_list) {
1150 # read from file(url-encoded):
1151 # 'git%2Fgit.git Linus+Torvalds'
1152 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1153 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1155 open my ($fd), $projects_list or return;
1157 while (my $line = <$fd>) {
1159 my ($path, $owner) = split ' ', $line;
1160 $path = unescape
($path);
1161 $owner = unescape
($owner);
1162 if (!defined $path) {
1165 if ($filter ne '') {
1166 # looking for forks;
1167 my $pfx = substr($path, 0, length($filter));
1168 if ($pfx ne $filter) {
1171 my $sfx = substr($path, length($filter));
1172 if ($sfx !~ /^\/.*\
.git
$/) {
1175 } elsif ($check_forks) {
1177 foreach my $filter (keys %paths) {
1178 # looking for forks;
1179 my $pfx = substr($path, 0, length($filter));
1180 if ($pfx ne $filter) {
1183 my $sfx = substr($path, length($filter));
1184 if ($sfx !~ /^\/.*\
.git
$/) {
1187 # is a fork, don't include it in
1192 if (check_export_ok
("$projectroot/$path")) {
1195 owner
=> decode_utf8
($owner),
1198 (my $forks_path = $path) =~ s/\.git$//;
1199 $paths{$forks_path}++;
1207 sub git_get_project_owner
{
1208 my $project = shift;
1211 return undef unless $project;
1213 # read from file (url-encoded):
1214 # 'git%2Fgit.git Linus+Torvalds'
1215 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1216 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1217 if (-f
$projects_list) {
1218 open (my $fd , $projects_list);
1219 while (my $line = <$fd>) {
1221 my ($pr, $ow) = split ' ', $line;
1222 $pr = unescape
($pr);
1223 $ow = unescape
($ow);
1224 if ($pr eq $project) {
1225 $owner = decode_utf8
($ow);
1231 if (!defined $owner) {
1232 $owner = get_file_owner
("$projectroot/$project");
1238 sub git_get_last_activity
{
1242 $git_dir = "$projectroot/$path";
1243 open($fd, "-|", git_cmd
(), 'for-each-ref',
1244 '--format=%(committer)',
1245 '--sort=-committerdate',
1247 'refs/heads') or return;
1248 my $most_recent = <$fd>;
1249 close $fd or return;
1250 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1252 my $age = time - $timestamp;
1253 return ($age, age_string
($age));
1257 sub git_get_references
{
1258 my $type = shift || "";
1260 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1261 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1262 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1263 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1266 while (my $line = <$fd>) {
1268 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1269 if (defined $refs{$1}) {
1270 push @
{$refs{$1}}, $2;
1276 close $fd or return;
1280 sub git_get_rev_name_tags
{
1281 my $hash = shift || return undef;
1283 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1285 my $name_rev = <$fd>;
1288 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1291 # catches also '$hash undefined' output
1296 ## ----------------------------------------------------------------------
1297 ## parse to hash functions
1301 my $tz = shift || "-0000";
1304 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1305 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1306 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1307 $date{'hour'} = $hour;
1308 $date{'minute'} = $min;
1309 $date{'mday'} = $mday;
1310 $date{'day'} = $days[$wday];
1311 $date{'month'} = $months[$mon];
1312 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1313 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1314 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1315 $mday, $months[$mon], $hour ,$min;
1316 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1317 1900+$year, $mon, $mday, $hour ,$min, $sec;
1319 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1320 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1321 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1322 $date{'hour_local'} = $hour;
1323 $date{'minute_local'} = $min;
1324 $date{'tz_local'} = $tz;
1325 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1326 1900+$year, $mon+1, $mday,
1327 $hour, $min, $sec, $tz);
1336 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1337 $tag{'id'} = $tag_id;
1338 while (my $line = <$fd>) {
1340 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1341 $tag{'object'} = $1;
1342 } elsif ($line =~ m/^type (.+)$/) {
1344 } elsif ($line =~ m/^tag (.+)$/) {
1346 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1347 $tag{'author'} = $1;
1350 } elsif ($line =~ m/--BEGIN/) {
1351 push @comment, $line;
1353 } elsif ($line eq "") {
1357 push @comment, <$fd>;
1358 $tag{'comment'} = \
@comment;
1359 close $fd or return;
1360 if (!defined $tag{'name'}) {
1366 sub parse_commit_text
{
1367 my ($commit_text, $withparents) = @_;
1368 my @commit_lines = split '\n', $commit_text;
1371 pop @commit_lines; # Remove '\0'
1373 my $header = shift @commit_lines;
1374 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1377 ($co{'id'}, my @parents) = split ' ', $header;
1378 while (my $line = shift @commit_lines) {
1379 last if $line eq "\n";
1380 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1382 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1384 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1386 $co{'author_epoch'} = $2;
1387 $co{'author_tz'} = $3;
1388 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1389 $co{'author_name'} = $1;
1390 $co{'author_email'} = $2;
1392 $co{'author_name'} = $co{'author'};
1394 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1395 $co{'committer'} = $1;
1396 $co{'committer_epoch'} = $2;
1397 $co{'committer_tz'} = $3;
1398 $co{'committer_name'} = $co{'committer'};
1399 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1400 $co{'committer_name'} = $1;
1401 $co{'committer_email'} = $2;
1403 $co{'committer_name'} = $co{'committer'};
1407 if (!defined $co{'tree'}) {
1410 $co{'parents'} = \
@parents;
1411 $co{'parent'} = $parents[0];
1413 foreach my $title (@commit_lines) {
1416 $co{'title'} = chop_str
($title, 80, 5);
1417 # remove leading stuff of merges to make the interesting part visible
1418 if (length($title) > 50) {
1419 $title =~ s/^Automatic //;
1420 $title =~ s/^merge (of|with) /Merge ... /i;
1421 if (length($title) > 50) {
1422 $title =~ s/(http|rsync):\/\///;
1424 if (length($title) > 50) {
1425 $title =~ s/(master|www|rsync)\.//;
1427 if (length($title) > 50) {
1428 $title =~ s/kernel.org:?//;
1430 if (length($title) > 50) {
1431 $title =~ s/\/pub\/scm//;
1434 $co{'title_short'} = chop_str
($title, 50, 5);
1438 if ($co{'title'} eq "") {
1439 $co{'title'} = $co{'title_short'} = '(no commit message)';
1441 # remove added spaces
1442 foreach my $line (@commit_lines) {
1445 $co{'comment'} = \
@commit_lines;
1447 my $age = time - $co{'committer_epoch'};
1449 $co{'age_string'} = age_string
($age);
1450 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1451 if ($age > 60*60*24*7*2) {
1452 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1453 $co{'age_string_age'} = $co{'age_string'};
1455 $co{'age_string_date'} = $co{'age_string'};
1456 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1462 my ($commit_id) = @_;
1467 open my $fd, "-|", git_cmd
(), "rev-list",
1473 or die_error
(undef, "Open git-rev-list failed");
1474 %co = parse_commit_text
(<$fd>, 1);
1481 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1489 open my $fd, "-|", git_cmd
(), "rev-list",
1491 ($arg ?
($arg) : ()),
1492 ("--max-count=" . $maxcount),
1493 ("--skip=" . $skip),
1496 ($filename ?
($filename) : ())
1497 or die_error
(undef, "Open git-rev-list failed");
1498 while (my $line = <$fd>) {
1499 my %co = parse_commit_text
($line);
1504 return wantarray ?
@cos : \
@cos;
1507 # parse ref from ref_file, given by ref_id, with given type
1509 my $ref_file = shift;
1511 my $type = shift || git_get_type
($ref_id);
1514 $ref_item{'type'} = $type;
1515 $ref_item{'id'} = $ref_id;
1516 $ref_item{'epoch'} = 0;
1517 $ref_item{'age'} = "unknown";
1518 if ($type eq "tag") {
1519 my %tag = parse_tag
($ref_id);
1520 $ref_item{'comment'} = $tag{'comment'};
1521 if ($tag{'type'} eq "commit") {
1522 my %co = parse_commit
($tag{'object'});
1523 $ref_item{'epoch'} = $co{'committer_epoch'};
1524 $ref_item{'age'} = $co{'age_string'};
1525 } elsif (defined($tag{'epoch'})) {
1526 my $age = time - $tag{'epoch'};
1527 $ref_item{'epoch'} = $tag{'epoch'};
1528 $ref_item{'age'} = age_string
($age);
1530 $ref_item{'reftype'} = $tag{'type'};
1531 $ref_item{'name'} = $tag{'name'};
1532 $ref_item{'refid'} = $tag{'object'};
1533 } elsif ($type eq "commit"){
1534 my %co = parse_commit
($ref_id);
1535 $ref_item{'reftype'} = "commit";
1536 $ref_item{'name'} = $ref_file;
1537 $ref_item{'title'} = $co{'title'};
1538 $ref_item{'refid'} = $ref_id;
1539 $ref_item{'epoch'} = $co{'committer_epoch'};
1540 $ref_item{'age'} = $co{'age_string'};
1542 $ref_item{'reftype'} = $type;
1543 $ref_item{'name'} = $ref_file;
1544 $ref_item{'refid'} = $ref_id;
1550 # parse line of git-diff-tree "raw" output
1551 sub parse_difftree_raw_line
{
1555 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1556 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1557 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1558 $res{'from_mode'} = $1;
1559 $res{'to_mode'} = $2;
1560 $res{'from_id'} = $3;
1562 $res{'status'} = $5;
1563 $res{'similarity'} = $6;
1564 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1565 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1567 $res{'file'} = unquote
($7);
1570 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1571 # combined diff (for merge commit)
1572 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1573 $res{'nparents'} = length($1);
1574 $res{'from_mode'} = [ split(' ', $2) ];
1575 $res{'to_mode'} = pop @
{$res{'from_mode'}};
1576 $res{'from_id'} = [ split(' ', $3) ];
1577 $res{'to_id'} = pop @
{$res{'from_id'}};
1578 $res{'status'} = [ split('', $4) ];
1579 $res{'to_file'} = unquote
($5);
1581 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1582 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1583 $res{'commit'} = $1;
1586 return wantarray ?
%res : \
%res;
1589 # parse line of git-ls-tree output
1590 sub parse_ls_tree_line
($;%) {
1595 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1596 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1604 $res{'name'} = unquote
($4);
1607 return wantarray ?
%res : \
%res;
1610 ## ......................................................................
1611 ## parse to array of hashes functions
1613 sub git_get_heads_list
{
1617 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1618 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
1619 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1622 while (my $line = <$fd>) {
1626 my ($refinfo, $committerinfo) = split(/\0/, $line);
1627 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1628 my ($committer, $epoch, $tz) =
1629 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1630 $name =~ s!^refs/heads/!!;
1632 $ref_item{'name'} = $name;
1633 $ref_item{'id'} = $hash;
1634 $ref_item{'title'} = $title || '(no commit message)';
1635 $ref_item{'epoch'} = $epoch;
1637 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1639 $ref_item{'age'} = "unknown";
1642 push @headslist, \
%ref_item;
1646 return wantarray ?
@headslist : \
@headslist;
1649 sub git_get_tags_list
{
1653 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1654 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
1655 '--format=%(objectname) %(objecttype) %(refname) '.
1656 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1659 while (my $line = <$fd>) {
1663 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1664 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1665 my ($creator, $epoch, $tz) =
1666 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1667 $name =~ s!^refs/tags/!!;
1669 $ref_item{'type'} = $type;
1670 $ref_item{'id'} = $id;
1671 $ref_item{'name'} = $name;
1672 if ($type eq "tag") {
1673 $ref_item{'subject'} = $title;
1674 $ref_item{'reftype'} = $reftype;
1675 $ref_item{'refid'} = $refid;
1677 $ref_item{'reftype'} = $type;
1678 $ref_item{'refid'} = $id;
1681 if ($type eq "tag" || $type eq "commit") {
1682 $ref_item{'epoch'} = $epoch;
1684 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1686 $ref_item{'age'} = "unknown";
1690 push @tagslist, \
%ref_item;
1694 return wantarray ?
@tagslist : \
@tagslist;
1697 ## ----------------------------------------------------------------------
1698 ## filesystem-related functions
1700 sub get_file_owner
{
1703 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1704 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1705 if (!defined $gcos) {
1709 $owner =~ s/[,;].*$//;
1710 return decode_utf8
($owner);
1713 ## ......................................................................
1714 ## mimetype related functions
1716 sub mimetype_guess_file
{
1717 my $filename = shift;
1718 my $mimemap = shift;
1719 -r
$mimemap or return undef;
1722 open(MIME
, $mimemap) or return undef;
1724 next if m/^#/; # skip comments
1725 my ($mime, $exts) = split(/\t+/);
1726 if (defined $exts) {
1727 my @exts = split(/\s+/, $exts);
1728 foreach my $ext (@exts) {
1729 $mimemap{$ext} = $mime;
1735 $filename =~ /\.([^.]*)$/;
1736 return $mimemap{$1};
1739 sub mimetype_guess
{
1740 my $filename = shift;
1742 $filename =~ /\./ or return undef;
1744 if ($mimetypes_file) {
1745 my $file = $mimetypes_file;
1746 if ($file !~ m!^/!) { # if it is relative path
1747 # it is relative to project
1748 $file = "$projectroot/$project/$file";
1750 $mime = mimetype_guess_file
($filename, $file);
1752 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1758 my $filename = shift;
1761 my $mime = mimetype_guess
($filename);
1762 $mime and return $mime;
1766 return $default_blob_plain_mimetype unless $fd;
1769 return 'text/plain' .
1770 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1771 } elsif (! $filename) {
1772 return 'application/octet-stream';
1773 } elsif ($filename =~ m/\.png$/i) {
1775 } elsif ($filename =~ m/\.gif$/i) {
1777 } elsif ($filename =~ m/\.jpe?g$/i) {
1778 return 'image/jpeg';
1780 return 'application/octet-stream';
1784 ## ======================================================================
1785 ## functions printing HTML: header, footer, error page
1787 sub git_header_html
{
1788 my $status = shift || "200 OK";
1789 my $expires = shift;
1791 my $title = "$site_name";
1792 if (defined $project) {
1793 $title .= " - " . decode_utf8
($project);
1794 if (defined $action) {
1795 $title .= "/$action";
1796 if (defined $file_name) {
1797 $title .= " - " . esc_path
($file_name);
1798 if ($action eq "tree" && $file_name !~ m
|/$|) {
1805 # require explicit support from the UA if we are to send the page as
1806 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1807 # we have to do this because MSIE sometimes globs '*/*', pretending to
1808 # support xhtml+xml but choking when it gets what it asked for.
1809 if (defined $cgi->http('HTTP_ACCEPT') &&
1810 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1811 $cgi->Accept('application/xhtml+xml') != 0) {
1812 $content_type = 'application/xhtml+xml';
1814 $content_type = 'text/html';
1816 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1817 -status
=> $status, -expires
=> $expires);
1818 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
1820 <?xml version="1.0" encoding="utf-8"?>
1821 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1822 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1823 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1824 <!-- git core binaries version $git_version -->
1826 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1827 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1828 <meta name="robots" content="index, nofollow"/>
1829 <title>$title</title>
1831 # print out each stylesheet that exist
1832 if (defined $stylesheet) {
1833 #provides backwards capability for those people who define style sheet in a config file
1834 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1836 foreach my $stylesheet (@stylesheets) {
1837 next unless $stylesheet;
1838 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1841 if (defined $project) {
1842 printf('<link rel="alternate" title="%s log RSS feed" '.
1843 'href="%s" type="application/rss+xml" />'."\n",
1844 esc_param
($project), href
(action
=>"rss"));
1845 printf('<link rel="alternate" title="%s log Atom feed" '.
1846 'href="%s" type="application/atom+xml" />'."\n",
1847 esc_param
($project), href
(action
=>"atom"));
1849 printf('<link rel="alternate" title="%s projects list" '.
1850 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1851 $site_name, href
(project
=>undef, action
=>"project_index"));
1852 printf('<link rel="alternate" title="%s projects feeds" '.
1853 'href="%s" type="text/x-opml"/>'."\n",
1854 $site_name, href
(project
=>undef, action
=>"opml"));
1856 if (defined $favicon) {
1857 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1863 if (-f
$site_header) {
1864 open (my $fd, $site_header);
1869 print "<div class=\"page_header\">\n" .
1870 $cgi->a({-href
=> esc_url
($logo_url),
1871 -title
=> $logo_label},
1872 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
1873 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1874 if (defined $project) {
1875 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1876 if (defined $action) {
1881 my ($have_search) = gitweb_check_feature
('search');
1882 if ((defined $project) && ($have_search)) {
1883 if (!defined $searchtext) {
1887 if (defined $hash_base) {
1888 $search_hash = $hash_base;
1889 } elsif (defined $hash) {
1890 $search_hash = $hash;
1892 $search_hash = "HEAD";
1894 $cgi->param("a", "search");
1895 $cgi->param("h", $search_hash);
1896 $cgi->param("p", $project);
1897 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1898 "<div class=\"search\">\n" .
1899 $cgi->hidden(-name
=> "p") . "\n" .
1900 $cgi->hidden(-name
=> "a") . "\n" .
1901 $cgi->hidden(-name
=> "h") . "\n" .
1902 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1903 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1904 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1906 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1908 $cgi->end_form() . "\n";
1913 sub git_footer_html
{
1914 print "<div class=\"page_footer\">\n";
1915 if (defined $project) {
1916 my $descr = git_get_project_description
($project);
1917 if (defined $descr) {
1918 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1920 print $cgi->a({-href
=> href
(action
=>"rss"),
1921 -class => "rss_logo"}, "RSS") . " ";
1922 print $cgi->a({-href
=> href
(action
=>"atom"),
1923 -class => "rss_logo"}, "Atom") . "\n";
1925 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1926 -class => "rss_logo"}, "OPML") . " ";
1927 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1928 -class => "rss_logo"}, "TXT") . "\n";
1932 if (-f
$site_footer) {
1933 open (my $fd, $site_footer);
1943 my $status = shift || "403 Forbidden";
1944 my $error = shift || "Malformed query, file missing or permission denied";
1946 git_header_html
($status);
1948 <div class="page_body">
1958 ## ----------------------------------------------------------------------
1959 ## functions printing or outputting HTML: navigation
1961 sub git_print_page_nav
{
1962 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1963 $extra = '' if !defined $extra; # pager or formats
1965 my @navs = qw(summary shortlog log commit commitdiff tree);
1967 @navs = grep { $_ ne $suppress } @navs;
1970 my %arg = map { $_ => {action
=>$_} } @navs;
1971 if (defined $head) {
1972 for (qw(commit commitdiff)) {
1973 $arg{$_}{'hash'} = $head;
1975 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1976 for (qw(shortlog log)) {
1977 $arg{$_}{'hash'} = $head;
1981 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
1982 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
1984 print "<div class=\"page_nav\">\n" .
1986 map { $_ eq $current ?
1987 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1989 print "<br/>\n$extra<br/>\n" .
1993 sub format_paging_nav
{
1994 my ($action, $hash, $head, $page, $nrevs) = @_;
1998 if ($hash ne $head || $page) {
1999 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2001 $paging_nav .= "HEAD";
2005 $paging_nav .= " ⋅ " .
2006 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2007 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2009 $paging_nav .= " ⋅ prev";
2012 if ($nrevs >= (100 * ($page+1)-1)) {
2013 $paging_nav .= " ⋅ " .
2014 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2015 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2017 $paging_nav .= " ⋅ next";
2023 ## ......................................................................
2024 ## functions printing or outputting HTML: div
2026 sub git_print_header_div
{
2027 my ($action, $title, $hash, $hash_base) = @_;
2030 $args{'action'} = $action;
2031 $args{'hash'} = $hash if $hash;
2032 $args{'hash_base'} = $hash_base if $hash_base;
2034 print "<div class=\"header\">\n" .
2035 $cgi->a({-href
=> href
(%args), -class => "title"},
2036 $title ?
$title : $action) .
2040 #sub git_print_authorship (\%) {
2041 sub git_print_authorship
{
2044 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2045 print "<div class=\"author_date\">" .
2046 esc_html
($co->{'author_name'}) .
2048 if ($ad{'hour_local'} < 6) {
2049 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2050 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2052 printf(" (%02d:%02d %s)",
2053 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2058 sub git_print_page_path
{
2064 print "<div class=\"page_path\">";
2065 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2066 -title
=> 'tree root'}, decode_utf8
("[$project]"));
2068 if (defined $name) {
2069 my @dirname = split '/', $name;
2070 my $basename = pop @dirname;
2073 foreach my $dir (@dirname) {
2074 $fullname .= ($fullname ?
'/' : '') . $dir;
2075 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2077 -title
=> $fullname}, esc_path
($dir));
2080 if (defined $type && $type eq 'blob') {
2081 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2083 -title
=> $name}, esc_path
($basename));
2084 } elsif (defined $type && $type eq 'tree') {
2085 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2087 -title
=> $name}, esc_path
($basename));
2090 print esc_path
($basename);
2093 print "<br/></div>\n";
2096 # sub git_print_log (\@;%) {
2097 sub git_print_log
($;%) {
2101 if ($opts{'-remove_title'}) {
2102 # remove title, i.e. first line of log
2105 # remove leading empty lines
2106 while (defined $log->[0] && $log->[0] eq "") {
2113 foreach my $line (@
$log) {
2114 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2117 if (! $opts{'-remove_signoff'}) {
2118 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2121 # remove signoff lines
2128 # print only one empty line
2129 # do not print empty line after signoff
2131 next if ($empty || $signoff);
2137 print format_log_line_html
($line) . "<br/>\n";
2140 if ($opts{'-final_empty_line'}) {
2141 # end with single empty line
2142 print "<br/>\n" unless $empty;
2146 # return link target (what link points to)
2147 sub git_get_link_target
{
2152 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2156 $link_target = <$fd>;
2161 return $link_target;
2164 # given link target, and the directory (basedir) the link is in,
2165 # return target of link relative to top directory (top tree);
2166 # return undef if it is not possible (including absolute links).
2167 sub normalize_link_target
{
2168 my ($link_target, $basedir, $hash_base) = @_;
2170 # we can normalize symlink target only if $hash_base is provided
2171 return unless $hash_base;
2173 # absolute symlinks (beginning with '/') cannot be normalized
2174 return if (substr($link_target, 0, 1) eq '/');
2176 # normalize link target to path from top (root) tree (dir)
2179 $path = $basedir . '/' . $link_target;
2181 # we are in top (root) tree (dir)
2182 $path = $link_target;
2185 # remove //, /./, and /../
2187 foreach my $part (split('/', $path)) {
2188 # discard '.' and ''
2189 next if (!$part || $part eq '.');
2191 if ($part eq '..') {
2195 # link leads outside repository (outside top dir)
2199 push @path_parts, $part;
2202 $path = join('/', @path_parts);
2207 # print tree entry (row of git_tree), but without encompassing <tr> element
2208 sub git_print_tree_entry
{
2209 my ($t, $basedir, $hash_base, $have_blame) = @_;
2212 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2214 # The format of a table row is: mode list link. Where mode is
2215 # the mode of the entry, list is the name of the entry, an href,
2216 # and link is the action links of the entry.
2218 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2219 if ($t->{'type'} eq "blob") {
2220 print "<td class=\"list\">" .
2221 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2222 file_name
=>"$basedir$t->{'name'}", %base_key),
2223 -class => "list"}, esc_path
($t->{'name'}));
2224 if (S_ISLNK
(oct $t->{'mode'})) {
2225 my $link_target = git_get_link_target
($t->{'hash'});
2227 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2228 if (defined $norm_target) {
2230 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2231 file_name
=>$norm_target),
2232 -title
=> $norm_target}, esc_path
($link_target));
2234 print " -> " . esc_path
($link_target);
2239 print "<td class=\"link\">";
2240 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2241 file_name
=>"$basedir$t->{'name'}", %base_key)},
2245 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2246 file_name
=>"$basedir$t->{'name'}", %base_key)},
2249 if (defined $hash_base) {
2251 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2252 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2256 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2257 file_name
=>"$basedir$t->{'name'}")},
2261 } elsif ($t->{'type'} eq "tree") {
2262 print "<td class=\"list\">";
2263 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2264 file_name
=>"$basedir$t->{'name'}", %base_key)},
2265 esc_path
($t->{'name'}));
2267 print "<td class=\"link\">";
2268 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2269 file_name
=>"$basedir$t->{'name'}", %base_key)},
2271 if (defined $hash_base) {
2273 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2274 file_name
=>"$basedir$t->{'name'}")},
2281 ## ......................................................................
2282 ## functions printing large fragments of HTML
2284 sub fill_from_file_info
{
2285 my ($diff, @parents) = @_;
2287 $diff->{'from_file'} = [ ];
2288 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2289 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2290 if ($diff->{'status'}[$i] eq 'R' ||
2291 $diff->{'status'}[$i] eq 'C') {
2292 $diff->{'from_file'}[$i] =
2293 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2300 # parameters can be strings, or references to arrays of strings
2304 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @
$a == @
$b) {
2305 for (my $i = 0; $i < @
$a; ++$i) {
2306 return 0 unless ($a->[$i] eq $b->[$i]);
2309 } elsif (!ref($a) && !ref($b)) {
2317 sub git_difftree_body
{
2318 my ($difftree, $hash, @parents) = @_;
2319 my ($parent) = $parents[0];
2320 my ($have_blame) = gitweb_check_feature
('blame');
2321 print "<div class=\"list_head\">\n";
2322 if ($#{$difftree} > 10) {
2323 print(($#{$difftree} + 1) . " files changed:\n");
2327 print "<table class=\"" .
2328 (@parents > 1 ?
"combined " : "") .
2332 foreach my $line (@
{$difftree}) {
2333 my %diff = parse_difftree_raw_line
($line);
2336 print "<tr class=\"dark\">\n";
2338 print "<tr class=\"light\">\n";
2342 if (exists $diff{'nparents'}) { # combined diff
2344 fill_from_file_info
(\
%diff, @parents);
2346 if ($diff{'to_id'} ne ('0' x
40)) {
2347 # file exists in the result (child) commit
2349 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2350 file_name
=>$diff{'to_file'},
2352 -class => "list"}, esc_path
($diff{'to_file'})) .
2356 esc_path
($diff{'to_file'}) .
2360 if ($action eq 'commitdiff') {
2363 print "<td class=\"link\">" .
2364 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2369 my $has_history = 0;
2370 my $not_deleted = 0;
2371 for (my $i = 0; $i < $diff{'nparents'}; $i++) {
2372 my $hash_parent = $parents[$i];
2373 my $from_hash = $diff{'from_id'}[$i];
2374 my $from_path = $diff{'from_file'}[$i];
2375 my $status = $diff{'status'}[$i];
2377 $has_history ||= ($status ne 'A');
2378 $not_deleted ||= ($status ne 'D');
2380 if ($status eq 'A') {
2381 print "<td class=\"link\" align=\"right\"> | </td>\n";
2382 } elsif ($status eq 'D') {
2383 print "<td class=\"link\">" .
2384 $cgi->a({-href
=> href
(action
=>"blob",
2387 file_name
=>$from_path)},
2391 if ($diff{'to_id'} eq $from_hash) {
2392 print "<td class=\"link nochange\">";
2394 print "<td class=\"link\">";
2396 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2397 hash
=>$diff{'to_id'},
2398 hash_parent
=>$from_hash,
2400 hash_parent_base
=>$hash_parent,
2401 file_name
=>$diff{'to_file'},
2402 file_parent
=>$from_path)},
2408 print "<td class=\"link\">";
2410 print $cgi->a({-href
=> href
(action
=>"blob",
2411 hash
=>$diff{'to_id'},
2412 file_name
=>$diff{'to_file'},
2415 print " | " if ($has_history);
2418 print $cgi->a({-href
=> href
(action
=>"history",
2419 file_name
=>$diff{'to_file'},
2426 next; # instead of 'else' clause, to avoid extra indent
2428 # else ordinary diff
2430 my ($to_mode_oct, $to_mode_str, $to_file_type);
2431 my ($from_mode_oct, $from_mode_str, $from_file_type);
2432 if ($diff{'to_mode'} ne ('0' x
6)) {
2433 $to_mode_oct = oct $diff{'to_mode'};
2434 if (S_ISREG
($to_mode_oct)) { # only for regular file
2435 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2437 $to_file_type = file_type
($diff{'to_mode'});
2439 if ($diff{'from_mode'} ne ('0' x
6)) {
2440 $from_mode_oct = oct $diff{'from_mode'};
2441 if (S_ISREG
($to_mode_oct)) { # only for regular file
2442 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2444 $from_file_type = file_type
($diff{'from_mode'});
2447 if ($diff{'status'} eq "A") { # created
2448 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2449 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2450 $mode_chng .= "]</span>";
2452 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2453 hash_base
=>$hash, file_name
=>$diff{'file'}),
2454 -class => "list"}, esc_path
($diff{'file'}));
2456 print "<td>$mode_chng</td>\n";
2457 print "<td class=\"link\">";
2458 if ($action eq 'commitdiff') {
2461 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2464 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2465 hash_base
=>$hash, file_name
=>$diff{'file'})},
2469 } elsif ($diff{'status'} eq "D") { # deleted
2470 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2472 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2473 hash_base
=>$parent, file_name
=>$diff{'file'}),
2474 -class => "list"}, esc_path
($diff{'file'}));
2476 print "<td>$mode_chng</td>\n";
2477 print "<td class=\"link\">";
2478 if ($action eq 'commitdiff') {
2481 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2484 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2485 hash_base
=>$parent, file_name
=>$diff{'file'})},
2488 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2489 file_name
=>$diff{'file'})},
2492 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2493 file_name
=>$diff{'file'})},
2497 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2498 my $mode_chnge = "";
2499 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2500 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2501 if ($from_file_type ne $to_file_type) {
2502 $mode_chnge .= " from $from_file_type to $to_file_type";
2504 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2505 if ($from_mode_str && $to_mode_str) {
2506 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2507 } elsif ($to_mode_str) {
2508 $mode_chnge .= " mode: $to_mode_str";
2511 $mode_chnge .= "]</span>\n";
2514 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2515 hash_base
=>$hash, file_name
=>$diff{'file'}),
2516 -class => "list"}, esc_path
($diff{'file'}));
2518 print "<td>$mode_chnge</td>\n";
2519 print "<td class=\"link\">";
2520 if ($action eq 'commitdiff') {
2523 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2525 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2526 # "commit" view and modified file (not onlu mode changed)
2527 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2528 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2529 hash_base
=>$hash, hash_parent_base
=>$parent,
2530 file_name
=>$diff{'file'})},
2534 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2535 hash_base
=>$hash, file_name
=>$diff{'file'})},
2538 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2539 file_name
=>$diff{'file'})},
2542 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2543 file_name
=>$diff{'file'})},
2547 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2548 my %status_name = ('R' => 'moved', 'C' => 'copied');
2549 my $nstatus = $status_name{$diff{'status'}};
2551 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2552 # mode also for directories, so we cannot use $to_mode_str
2553 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2556 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2557 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2558 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2559 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2560 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2561 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2562 -class => "list"}, esc_path
($diff{'from_file'})) .
2563 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2564 "<td class=\"link\">";
2565 if ($action eq 'commitdiff') {
2568 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2570 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2571 # "commit" view and modified file (not only pure rename or copy)
2572 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2573 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2574 hash_base
=>$hash, hash_parent_base
=>$parent,
2575 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2579 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2580 hash_base
=>$parent, file_name
=>$diff{'to_file'})},
2583 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2584 file_name
=>$diff{'to_file'})},
2587 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2588 file_name
=>$diff{'to_file'})},
2592 } # we should not encounter Unmerged (U) or Unknown (X) status
2598 sub git_patchset_body
{
2599 my ($fd, $difftree, $hash, @hash_parents) = @_;
2600 my ($hash_parent) = $hash_parents[0];
2603 my $patch_number = 0;
2608 print "<div class=\"patchset\">\n";
2610 # skip to first patch
2611 while ($patch_line = <$fd>) {
2614 last if ($patch_line =~ m/^diff /);
2618 while ($patch_line) {
2620 my ($from_id, $to_id);
2623 #assert($patch_line =~ m/^diff /) if DEBUG;
2624 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2626 push @diff_header, $patch_line;
2628 # extended diff header
2630 while ($patch_line = <$fd>) {
2633 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2635 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2638 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2639 $from_id = [ split(',', $1) ];
2643 push @diff_header, $patch_line;
2645 my $last_patch_line = $patch_line;
2647 # check if current patch belong to current raw line
2648 # and parse raw git-diff line if needed
2649 if (defined $diffinfo &&
2650 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2651 $diffinfo->{'to_id'} eq $to_id) {
2652 # this is split patch
2653 print "<div class=\"patch cont\">\n";
2655 # advance raw git-diff output if needed
2656 $patch_idx++ if defined $diffinfo;
2658 # read and prepare patch information
2659 if (ref($difftree->[$patch_idx]) eq "HASH") {
2660 # pre-parsed (or generated by hand)
2661 $diffinfo = $difftree->[$patch_idx];
2663 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2665 if ($diffinfo->{'nparents'}) {
2669 fill_from_file_info
($diffinfo, @hash_parents)
2670 unless exists $diffinfo->{'from_file'};
2671 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2672 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2673 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2674 $from{'href'}[$i] = href
(action
=>"blob",
2675 hash_base
=>$hash_parents[$i],
2676 hash
=>$diffinfo->{'from_id'}[$i],
2677 file_name
=>$from{'file'}[$i]);
2679 $from{'href'}[$i] = undef;
2683 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2684 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2685 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2686 hash
=>$diffinfo->{'from_id'},
2687 file_name
=>$from{'file'});
2689 delete $from{'href'};
2692 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2693 if ($diffinfo->{'status'} ne "D") { # not deleted file
2694 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2695 hash
=>$diffinfo->{'to_id'},
2696 file_name
=>$to{'file'});
2700 # this is first patch for raw difftree line with $patch_idx index
2701 # we index @$difftree array from 0, but number patches from 1
2702 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2705 # print "git diff" header
2706 $patch_line = shift @diff_header;
2707 if ($diffinfo->{'nparents'}) {
2710 $patch_line =~ s!^(diff (.*?) )"?.*$!$1!;
2712 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2713 esc_path
($to{'file'}));
2714 } else { # file was deleted
2715 $patch_line .= esc_path
($to{'file'});
2720 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2721 if ($from{'href'}) {
2722 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2723 'a/' . esc_path
($from{'file'}));
2724 } else { # file was added
2725 $patch_line .= 'a/' . esc_path
($from{'file'});
2729 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2730 'b/' . esc_path
($to{'file'}));
2731 } else { # file was deleted
2732 $patch_line .= 'b/' . esc_path
($to{'file'});
2736 print "<div class=\"diff header\">$patch_line</div>\n";
2738 # print extended diff header
2739 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2741 foreach $patch_line (@diff_header) {
2743 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2744 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2745 esc_path
($from{'file'}));
2747 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2748 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2749 esc_path
($to{'file'}));
2751 # match single <mode>
2752 if ($patch_line =~ m/\s(\d{6})$/) {
2753 $patch_line .= '<span class="info"> (' .
2754 file_type_long
($1) .
2758 if ($patch_line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2759 # can match only for combined diff
2760 $patch_line = 'index ';
2761 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2762 if ($from{'href'}[$i]) {
2763 $patch_line .= $cgi->a({-href
=>$from{'href'}[$i],
2765 substr($diffinfo->{'from_id'}[$i],0,7));
2767 $patch_line .= '0' x
7;
2770 $patch_line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2772 $patch_line .= '..';
2774 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2775 substr($diffinfo->{'to_id'},0,7));
2777 $patch_line .= '0' x
7;
2780 } elsif ($patch_line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2781 # can match only for ordinary diff
2782 my ($from_link, $to_link);
2783 if ($from{'href'}) {
2784 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2785 substr($diffinfo->{'from_id'},0,7));
2787 $from_link = '0' x
7;
2790 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2791 substr($diffinfo->{'to_id'},0,7));
2796 # my ($from_hash, $to_hash) =
2797 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2798 # my ($from_id, $to_id) =
2799 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2800 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2802 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2803 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2805 print $patch_line . "<br/>\n";
2807 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2809 # from-file/to-file diff header
2810 $patch_line = $last_patch_line;
2811 if (! $patch_line) {
2812 print "</div>\n"; # class="patch"
2815 next PATCH
if ($patch_line =~ m/^diff /);
2816 #assert($patch_line =~ m/^---/) if DEBUG;
2817 if (!$diffinfo->{'nparents'} && # not from-file line for combined diff
2818 $from{'href'} && $patch_line =~ m!^--- "?a/!) {
2819 $patch_line = '--- a/' .
2820 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2821 esc_path
($from{'file'}));
2823 print "<div class=\"diff from_file\">$patch_line</div>\n";
2825 $patch_line = <$fd>;
2828 #assert($patch_line =~ m/^+++/) if DEBUG;
2829 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2830 $patch_line = '+++ b/' .
2831 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2832 esc_path
($to{'file'}));
2834 print "<div class=\"diff to_file\">$patch_line</div>\n";
2838 while ($patch_line = <$fd>) {
2841 next PATCH
if ($patch_line =~ m/^diff /);
2843 print format_diff_line
($patch_line, \
%from, \
%to);
2847 print "</div>\n"; # class="patch"
2849 print "<div class=\"diff nodifferences\">No differences found</div>\n" if (!$patch_number);
2851 print "</div>\n"; # class="patchset"
2854 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2856 sub git_project_list_body
{
2857 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2859 my ($check_forks) = gitweb_check_feature
('forks');
2862 foreach my $pr (@
$projlist) {
2863 my (@aa) = git_get_last_activity
($pr->{'path'});
2867 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2868 if (!defined $pr->{'descr'}) {
2869 my $descr = git_get_project_description
($pr->{'path'}) || "";
2870 $pr->{'descr_long'} = decode_utf8
($descr);
2871 $pr->{'descr'} = chop_str
($descr, 25, 5);
2873 if (!defined $pr->{'owner'}) {
2874 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2877 my $pname = $pr->{'path'};
2878 if (($pname =~ s/\.git$//) &&
2879 ($pname !~ /\/$/) &&
2880 (-d
"$projectroot/$pname")) {
2881 $pr->{'forks'} = "-d $projectroot/$pname";
2887 push @projects, $pr;
2890 $order ||= $default_projects_order;
2891 $from = 0 unless defined $from;
2892 $to = $#projects if (!defined $to || $#projects < $to);
2894 print "<table class=\"project_list\">\n";
2895 unless ($no_header) {
2898 print "<th></th>\n";
2900 if ($order eq "project") {
2901 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2902 print "<th>Project</th>\n";
2905 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2906 -class => "header"}, "Project") .
2909 if ($order eq "descr") {
2910 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2911 print "<th>Description</th>\n";
2914 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2915 -class => "header"}, "Description") .
2918 if ($order eq "owner") {
2919 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2920 print "<th>Owner</th>\n";
2923 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2924 -class => "header"}, "Owner") .
2927 if ($order eq "age") {
2928 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2929 print "<th>Last Change</th>\n";
2932 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2933 -class => "header"}, "Last Change") .
2936 print "<th></th>\n" .
2940 for (my $i = $from; $i <= $to; $i++) {
2941 my $pr = $projects[$i];
2943 print "<tr class=\"dark\">\n";
2945 print "<tr class=\"light\">\n";
2950 if ($pr->{'forks'}) {
2951 print "<!-- $pr->{'forks'} -->\n";
2952 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2956 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2957 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2958 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2959 -class => "list", -title
=> $pr->{'descr_long'}},
2960 esc_html
($pr->{'descr'})) . "</td>\n" .
2961 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2962 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2963 $pr->{'age_string'} . "</td>\n" .
2964 "<td class=\"link\">" .
2965 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2966 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2967 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2968 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2969 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2973 if (defined $extra) {
2976 print "<td></td>\n";
2978 print "<td colspan=\"5\">$extra</td>\n" .
2984 sub git_shortlog_body
{
2985 # uses global variable $project
2986 my ($commitlist, $from, $to, $refs, $extra) = @_;
2988 my $have_snapshot = gitweb_have_snapshot
();
2990 $from = 0 unless defined $from;
2991 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
2993 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2995 for (my $i = $from; $i <= $to; $i++) {
2996 my %co = %{$commitlist->[$i]};
2997 my $commit = $co{'id'};
2998 my $ref = format_ref_marker
($refs, $commit);
3000 print "<tr class=\"dark\">\n";
3002 print "<tr class=\"light\">\n";
3005 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3006 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3007 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3009 print format_subject_html
($co{'title'}, $co{'title_short'},
3010 href
(action
=>"commit", hash
=>$commit), $ref);
3012 "<td class=\"link\">" .
3013 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3014 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3015 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3016 if ($have_snapshot) {
3017 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3022 if (defined $extra) {
3024 "<td colspan=\"4\">$extra</td>\n" .
3030 sub git_history_body
{
3031 # Warning: assumes constant type (blob or tree) during history
3032 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3034 $from = 0 unless defined $from;
3035 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3037 print "<table class=\"history\" cellspacing=\"0\">\n";
3039 for (my $i = $from; $i <= $to; $i++) {
3040 my %co = %{$commitlist->[$i]};
3044 my $commit = $co{'id'};
3046 my $ref = format_ref_marker
($refs, $commit);
3049 print "<tr class=\"dark\">\n";
3051 print "<tr class=\"light\">\n";
3054 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3055 # shortlog uses chop_str($co{'author_name'}, 10)
3056 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3058 # originally git_history used chop_str($co{'title'}, 50)
3059 print format_subject_html
($co{'title'}, $co{'title_short'},
3060 href
(action
=>"commit", hash
=>$commit), $ref);
3062 "<td class=\"link\">" .
3063 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3064 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3066 if ($ftype eq 'blob') {
3067 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3068 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3069 if (defined $blob_current && defined $blob_parent &&
3070 $blob_current ne $blob_parent) {
3072 $cgi->a({-href
=> href
(action
=>"blobdiff",
3073 hash
=>$blob_current, hash_parent
=>$blob_parent,
3074 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3075 file_name
=>$file_name)},
3082 if (defined $extra) {
3084 "<td colspan=\"4\">$extra</td>\n" .
3091 # uses global variable $project
3092 my ($taglist, $from, $to, $extra) = @_;
3093 $from = 0 unless defined $from;
3094 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3096 print "<table class=\"tags\" cellspacing=\"0\">\n";
3098 for (my $i = $from; $i <= $to; $i++) {
3099 my $entry = $taglist->[$i];
3101 my $comment = $tag{'subject'};
3103 if (defined $comment) {
3104 $comment_short = chop_str
($comment, 30, 5);
3107 print "<tr class=\"dark\">\n";
3109 print "<tr class=\"light\">\n";
3112 if (defined $tag{'age'}) {
3113 print "<td><i>$tag{'age'}</i></td>\n";
3115 print "<td></td>\n";
3118 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3119 -class => "list name"}, esc_html
($tag{'name'})) .
3122 if (defined $comment) {
3123 print format_subject_html
($comment, $comment_short,
3124 href
(action
=>"tag", hash
=>$tag{'id'}));
3127 "<td class=\"selflink\">";
3128 if ($tag{'type'} eq "tag") {
3129 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3134 "<td class=\"link\">" . " | " .
3135 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3136 if ($tag{'reftype'} eq "commit") {
3137 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3138 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3139 } elsif ($tag{'reftype'} eq "blob") {
3140 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3145 if (defined $extra) {
3147 "<td colspan=\"5\">$extra</td>\n" .
3153 sub git_heads_body
{
3154 # uses global variable $project
3155 my ($headlist, $head, $from, $to, $extra) = @_;
3156 $from = 0 unless defined $from;
3157 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3159 print "<table class=\"heads\" cellspacing=\"0\">\n";
3161 for (my $i = $from; $i <= $to; $i++) {
3162 my $entry = $headlist->[$i];
3164 my $curr = $ref{'id'} eq $head;
3166 print "<tr class=\"dark\">\n";
3168 print "<tr class=\"light\">\n";
3171 print "<td><i>$ref{'age'}</i></td>\n" .
3172 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3173 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3174 -class => "list name"},esc_html
($ref{'name'})) .
3176 "<td class=\"link\">" .
3177 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3178 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3179 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3183 if (defined $extra) {
3185 "<td colspan=\"3\">$extra</td>\n" .
3191 sub git_search_grep_body
{
3192 my ($commitlist, $from, $to, $extra) = @_;
3193 $from = 0 unless defined $from;
3194 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3196 print "<table class=\"grep\" cellspacing=\"0\">\n";
3198 for (my $i = $from; $i <= $to; $i++) {
3199 my %co = %{$commitlist->[$i]};
3203 my $commit = $co{'id'};
3205 print "<tr class=\"dark\">\n";
3207 print "<tr class=\"light\">\n";
3210 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3211 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3213 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3214 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3215 my $comment = $co{'comment'};
3216 foreach my $line (@
$comment) {
3217 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3218 my $lead = esc_html
($1) || "";
3219 $lead = chop_str
($lead, 30, 10);
3220 my $match = esc_html
($2) || "";
3221 my $trail = esc_html
($3) || "";
3222 $trail = chop_str
($trail, 30, 10);
3223 my $text = "$lead<span class=\"match\">$match</span>$trail";
3224 print chop_str
($text, 80, 5) . "<br/>\n";
3228 "<td class=\"link\">" .
3229 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3231 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3235 if (defined $extra) {
3237 "<td colspan=\"3\">$extra</td>\n" .
3243 ## ======================================================================
3244 ## ======================================================================
3247 sub git_project_list
{
3248 my $order = $cgi->param('o');
3249 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3250 die_error
(undef, "Unknown order parameter");
3253 my @list = git_get_projects_list
();
3255 die_error
(undef, "No projects found");
3259 if (-f
$home_text) {
3260 print "<div class=\"index_include\">\n";
3261 open (my $fd, $home_text);
3266 git_project_list_body
(\
@list, $order);
3271 my $order = $cgi->param('o');
3272 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3273 die_error
(undef, "Unknown order parameter");
3276 my @list = git_get_projects_list
($project);
3278 die_error
(undef, "No forks found");
3282 git_print_page_nav
('','');
3283 git_print_header_div
('summary', "$project forks");
3284 git_project_list_body
(\
@list, $order);
3288 sub git_project_index
{
3289 my @projects = git_get_projects_list
($project);
3292 -type
=> 'text/plain',
3293 -charset
=> 'utf-8',
3294 -content_disposition
=> 'inline; filename="index.aux"');
3296 foreach my $pr (@projects) {
3297 if (!exists $pr->{'owner'}) {
3298 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3301 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3302 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3303 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3304 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3308 print "$path $owner\n";
3313 my $descr = git_get_project_description
($project) || "none";
3314 my %co = parse_commit
("HEAD");
3315 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3316 my $head = $co{'id'};
3318 my $owner = git_get_project_owner
($project);
3320 my $refs = git_get_references
();
3321 # These get_*_list functions return one more to allow us to see if
3322 # there are more ...
3323 my @taglist = git_get_tags_list
(16);
3324 my @headlist = git_get_heads_list
(16);
3326 my ($check_forks) = gitweb_check_feature
('forks');
3329 @forklist = git_get_projects_list
($project);
3333 git_print_page_nav
('summary','', $head);
3335 print "<div class=\"title\"> </div>\n";
3336 print "<table cellspacing=\"0\">\n" .
3337 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3338 "<tr><td>owner</td><td>$owner</td></tr>\n" .
3339 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3340 # use per project git URL list in $projectroot/$project/cloneurl
3341 # or make project git URL from git base URL and project name
3342 my $url_tag = "URL";
3343 my @url_list = git_get_project_url_list
($project);
3344 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3345 foreach my $git_url (@url_list) {
3346 next unless $git_url;
3347 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3352 if (-s
"$projectroot/$project/README.html") {
3353 if (open my $fd, "$projectroot/$project/README.html") {
3354 print "<div class=\"title\">readme</div>\n";
3355 print $_ while (<$fd>);
3360 # we need to request one more than 16 (0..15) to check if
3362 my @commitlist = parse_commits
($head, 17);
3363 git_print_header_div
('shortlog');
3364 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3365 $#commitlist <= 15 ?
undef :
3366 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3369 git_print_header_div
('tags');
3370 git_tags_body
(\
@taglist, 0, 15,
3371 $#taglist <= 15 ?
undef :
3372 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3376 git_print_header_div
('heads');
3377 git_heads_body
(\
@headlist, $head, 0, 15,
3378 $#headlist <= 15 ?
undef :
3379 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3383 git_print_header_div
('forks');
3384 git_project_list_body
(\
@forklist, undef, 0, 15,
3385 $#forklist <= 15 ?
undef :
3386 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3394 my $head = git_get_head_hash
($project);
3396 git_print_page_nav
('','', $head,undef,$head);
3397 my %tag = parse_tag
($hash);
3398 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3399 print "<div class=\"title_text\">\n" .
3400 "<table cellspacing=\"0\">\n" .
3402 "<td>object</td>\n" .
3403 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3404 $tag{'object'}) . "</td>\n" .
3405 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3406 $tag{'type'}) . "</td>\n" .
3408 if (defined($tag{'author'})) {
3409 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3410 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3411 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3412 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3415 print "</table>\n\n" .
3417 print "<div class=\"page_body\">";
3418 my $comment = $tag{'comment'};
3419 foreach my $line (@
$comment) {
3421 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3431 my ($have_blame) = gitweb_check_feature
('blame');
3433 die_error
('403 Permission denied', "Permission denied");
3435 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3436 $hash_base ||= git_get_head_hash
($project);
3437 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3438 my %co = parse_commit
($hash_base)
3439 or die_error
(undef, "Reading commit failed");
3440 if (!defined $hash) {
3441 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3442 or die_error
(undef, "Error looking up file");
3444 $ftype = git_get_type
($hash);
3445 if ($ftype !~ "blob") {
3446 die_error
('400 Bad Request', "Object is not a blob");
3448 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3449 $file_name, $hash_base)
3450 or die_error
(undef, "Open git-blame failed");
3453 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3456 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3459 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3461 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3462 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3463 git_print_page_path
($file_name, $ftype, $hash_base);
3464 my @rev_color = (qw(light2 dark2));
3465 my $num_colors = scalar(@rev_color);
3466 my $current_color = 0;
3469 <div class="page_body">
3470 <table class="blame">
3471 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3476 last unless defined $_;
3477 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3478 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3479 if (!exists $metainfo{$full_rev}) {
3480 $metainfo{$full_rev} = {};
3482 my $meta = $metainfo{$full_rev};
3485 if (/^(\S+) (.*)$/) {
3491 my $rev = substr($full_rev, 0, 8);
3492 my $author = $meta->{'author'};
3493 my %date = parse_date
($meta->{'author-time'},
3494 $meta->{'author-tz'});
3495 my $date = $date{'iso-tz'};
3497 $current_color = ++$current_color % $num_colors;
3499 print "<tr class=\"$rev_color[$current_color]\">\n";
3501 print "<td class=\"sha1\"";
3502 print " title=\"". esc_html
($author) . ", $date\"";
3503 print " rowspan=\"$group_size\"" if ($group_size > 1);
3505 print $cgi->a({-href
=> href
(action
=>"commit",
3507 file_name
=>$file_name)},
3511 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3512 or die_error
(undef, "Open git-rev-parse failed");
3513 my $parent_commit = <$dd>;
3515 chomp($parent_commit);
3516 my $blamed = href
(action
=> 'blame',
3517 file_name
=> $meta->{'filename'},
3518 hash_base
=> $parent_commit);
3519 print "<td class=\"linenr\">";
3520 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3522 -class => "linenr" },
3525 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3531 or print "Reading blob failed\n";
3538 my ($have_blame) = gitweb_check_feature
('blame');
3540 die_error
('403 Permission denied', "Permission denied");
3542 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3543 $hash_base ||= git_get_head_hash
($project);
3544 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3545 my %co = parse_commit
($hash_base)
3546 or die_error
(undef, "Reading commit failed");
3547 if (!defined $hash) {
3548 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3549 or die_error
(undef, "Error lookup file");
3551 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3552 or die_error
(undef, "Open git-annotate failed");
3555 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3558 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3561 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3563 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3564 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3565 git_print_page_path
($file_name, 'blob', $hash_base);
3566 print "<div class=\"page_body\">\n";
3568 <table class="blame">
3577 my @line_class = (qw(light dark));
3578 my $line_class_len = scalar (@line_class);
3579 my $line_class_num = $#line_class;
3580 while (my $line = <$fd>) {
3592 $line_class_num = ($line_class_num + 1) % $line_class_len;
3594 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3601 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
3604 $short_rev = substr ($long_rev, 0, 8);
3605 $age = time () - $time;
3606 $age_str = age_string
($age);
3607 $age_str =~ s/ / /g;
3608 $age_class = age_class
($age);
3609 $author = esc_html
($author);
3610 $author =~ s/ / /g;
3612 $data = untabify
($data);
3613 $data = esc_html
($data);
3616 <tr class="$line_class[$line_class_num]">
3617 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3618 <td class="$age_class">$age_str</td>
3620 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3621 <td class="pre">$data</td>
3624 } # while (my $line = <$fd>)
3625 print "</table>\n\n";
3627 or print "Reading blob failed.\n";
3633 my $head = git_get_head_hash
($project);
3635 git_print_page_nav
('','', $head,undef,$head);
3636 git_print_header_div
('summary', $project);
3638 my @tagslist = git_get_tags_list
();
3640 git_tags_body
(\
@tagslist);
3646 my $head = git_get_head_hash
($project);
3648 git_print_page_nav
('','', $head,undef,$head);
3649 git_print_header_div
('summary', $project);
3651 my @headslist = git_get_heads_list
();
3653 git_heads_body
(\
@headslist, $head);
3658 sub git_blob_plain
{
3661 if (!defined $hash) {
3662 if (defined $file_name) {
3663 my $base = $hash_base || git_get_head_hash
($project);
3664 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3665 or die_error
(undef, "Error lookup file");
3667 die_error
(undef, "No file name defined");
3669 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3670 # blobs defined by non-textual hash id's can be cached
3675 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3676 or die_error
(undef, "Couldn't cat $file_name, $hash");
3678 $type ||= blob_mimetype
($fd, $file_name);
3680 # save as filename, even when no $file_name is given
3681 my $save_as = "$hash";
3682 if (defined $file_name) {
3683 $save_as = $file_name;
3684 } elsif ($type =~ m/^text\//) {
3691 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3693 binmode STDOUT
, ':raw';
3695 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3703 if (!defined $hash) {
3704 if (defined $file_name) {
3705 my $base = $hash_base || git_get_head_hash
($project);
3706 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3707 or die_error
(undef, "Error lookup file");
3709 die_error
(undef, "No file name defined");
3711 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3712 # blobs defined by non-textual hash id's can be cached
3716 my ($have_blame) = gitweb_check_feature
('blame');
3717 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3718 or die_error
(undef, "Couldn't cat $file_name, $hash");
3719 my $mimetype = blob_mimetype
($fd, $file_name);
3720 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3722 return git_blob_plain
($mimetype);
3724 # we can have blame only for text/* mimetype
3725 $have_blame &&= ($mimetype =~ m!^text/!);
3727 git_header_html
(undef, $expires);
3728 my $formats_nav = '';
3729 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3730 if (defined $file_name) {
3733 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3734 hash
=>$hash, file_name
=>$file_name)},
3739 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3740 hash
=>$hash, file_name
=>$file_name)},
3743 $cgi->a({-href
=> href
(action
=>"blob_plain",
3744 hash
=>$hash, file_name
=>$file_name)},
3747 $cgi->a({-href
=> href
(action
=>"blob",
3748 hash_base
=>"HEAD", file_name
=>$file_name)},
3752 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3754 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3755 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3757 print "<div class=\"page_nav\">\n" .
3758 "<br/><br/></div>\n" .
3759 "<div class=\"title\">$hash</div>\n";
3761 git_print_page_path
($file_name, "blob", $hash_base);
3762 print "<div class=\"page_body\">\n";
3763 if ($mimetype =~ m!^text/!) {
3765 while (my $line = <$fd>) {
3768 $line = untabify
($line);
3769 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3770 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3772 } elsif ($mimetype =~ m!^image/!) {
3773 print qq!<img type
="$mimetype"!;
3775 print qq! alt
="$file_name" title
="$file_name"!;
3778 href(action=>"blob_plain
", hash=>$hash,
3779 hash_base=>$hash_base, file_name=>$file_name) .
3783 or print "Reading blob failed.\n";
3789 my $have_snapshot = gitweb_have_snapshot
();
3791 if (!defined $hash_base) {
3792 $hash_base = "HEAD";
3794 if (!defined $hash) {
3795 if (defined $file_name) {
3796 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3802 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3803 or die_error
(undef, "Open git-ls-tree failed");
3804 my @entries = map { chomp; $_ } <$fd>;
3805 close $fd or die_error
(undef, "Reading tree failed");
3808 my $refs = git_get_references
();
3809 my $ref = format_ref_marker
($refs, $hash_base);
3812 my ($have_blame) = gitweb_check_feature
('blame');
3813 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3815 if (defined $file_name) {
3817 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3818 hash
=>$hash, file_name
=>$file_name)},
3820 $cgi->a({-href
=> href
(action
=>"tree",
3821 hash_base
=>"HEAD", file_name
=>$file_name)},
3824 if ($have_snapshot) {
3825 # FIXME: Should be available when we have no hash base as well.
3827 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3830 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3831 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3834 print "<div class=\"page_nav\">\n";
3835 print "<br/><br/></div>\n";
3836 print "<div class=\"title\">$hash</div>\n";
3838 if (defined $file_name) {
3839 $basedir = $file_name;
3840 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3844 git_print_page_path
($file_name, 'tree', $hash_base);
3845 print "<div class=\"page_body\">\n";
3846 print "<table cellspacing=\"0\">\n";
3848 # '..' (top directory) link if possible
3849 if (defined $hash_base &&
3850 defined $file_name && $file_name =~ m![^/]+$!) {
3852 print "<tr class=\"dark\">\n";
3854 print "<tr class=\"light\">\n";
3858 my $up = $file_name;
3859 $up =~ s!/?[^/]+$!!;
3860 undef $up unless $up;
3861 # based on git_print_tree_entry
3862 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3863 print '<td class="list">';
3864 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3868 print "<td class=\"link\"></td>\n";
3872 foreach my $line (@entries) {
3873 my %t = parse_ls_tree_line
($line, -z
=> 1);
3876 print "<tr class=\"dark\">\n";
3878 print "<tr class=\"light\">\n";
3882 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3886 print "</table>\n" .
3892 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3893 my $have_snapshot = (defined $ctype && defined $suffix);
3894 if (!$have_snapshot) {
3895 die_error
('403 Permission denied', "Permission denied");
3898 if (!defined $hash) {
3899 $hash = git_get_head_hash
($project);
3902 my $filename = decode_utf8
(basename
($project)) . "-$hash.tar.$suffix";
3905 -type
=> "application/$ctype",
3906 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3907 -status
=> '200 OK');
3909 my $git = git_cmd_str
();
3910 my $name = $project;
3911 $name =~ s/\047/\047\\\047\047/g;
3913 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3914 or die_error
(undef, "Execute git-tar-tree failed");
3915 binmode STDOUT
, ':raw';
3917 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3923 my $head = git_get_head_hash
($project);
3924 if (!defined $hash) {
3927 if (!defined $page) {
3930 my $refs = git_get_references
();
3932 my @commitlist = parse_commits
($hash, 101, (100 * $page));
3934 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
3937 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3940 my %co = parse_commit
($hash);
3942 git_print_header_div
('summary', $project);
3943 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3945 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
3946 for (my $i = 0; $i <= $to; $i++) {
3947 my %co = %{$commitlist[$i]};
3949 my $commit = $co{'id'};
3950 my $ref = format_ref_marker
($refs, $commit);
3951 my %ad = parse_date
($co{'author_epoch'});
3952 git_print_header_div
('commit',
3953 "<span class=\"age\">$co{'age_string'}</span>" .
3954 esc_html
($co{'title'}) . $ref,
3956 print "<div class=\"title_text\">\n" .
3957 "<div class=\"log_link\">\n" .
3958 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3960 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3962 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3965 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3968 print "<div class=\"log_body\">\n";
3969 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3972 if ($#commitlist >= 100) {
3973 print "<div class=\"page_nav\">\n";
3974 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
3975 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3982 $hash ||= $hash_base || "HEAD";
3983 my %co = parse_commit
($hash);
3985 die_error
(undef, "Unknown commit object");
3987 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3988 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3990 my $parent = $co{'parent'};
3991 my $parents = $co{'parents'}; # listref
3993 # we need to prepare $formats_nav before any parameter munging
3995 if (!defined $parent) {
3997 $formats_nav .= '(initial)';
3998 } elsif (@
$parents == 1) {
3999 # single parent commit
4002 $cgi->a({-href
=> href
(action
=>"commit",
4004 esc_html
(substr($parent, 0, 7))) .
4011 $cgi->a({-href
=> href
(action
=>"commit",
4013 esc_html
(substr($_, 0, 7)));
4018 if (!defined $parent) {
4022 if (@
$parents <= 1) {
4023 # difftree output is not printed for merges
4024 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4025 @diff_opts, $parent, $hash, "--"
4026 or die_error
(undef, "Open git-diff-tree failed");
4027 @difftree = map { chomp; $_ } <$fd>;
4028 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4031 # non-textual hash id's can be cached
4033 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4036 my $refs = git_get_references
();
4037 my $ref = format_ref_marker
($refs, $co{'id'});
4039 my $have_snapshot = gitweb_have_snapshot
();
4041 git_header_html
(undef, $expires);
4042 git_print_page_nav
('commit', '',
4043 $hash, $co{'tree'}, $hash,
4046 if (defined $co{'parent'}) {
4047 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4049 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4051 print "<div class=\"title_text\">\n" .
4052 "<table cellspacing=\"0\">\n";
4053 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4055 "<td></td><td> $ad{'rfc2822'}";
4056 if ($ad{'hour_local'} < 6) {
4057 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4058 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4060 printf(" (%02d:%02d %s)",
4061 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4065 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4066 print "<tr><td></td><td> $cd{'rfc2822'}" .
4067 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4069 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4072 "<td class=\"sha1\">" .
4073 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4074 class => "list"}, $co{'tree'}) .
4076 "<td class=\"link\">" .
4077 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4079 if ($have_snapshot) {
4081 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4086 foreach my $par (@
$parents) {
4089 "<td class=\"sha1\">" .
4090 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4091 class => "list"}, $par) .
4093 "<td class=\"link\">" .
4094 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4096 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4103 print "<div class=\"page_body\">\n";
4104 git_print_log
($co{'comment'});
4107 if (@
$parents <= 1) {
4108 # do not output difftree/whatchanged for merges
4109 git_difftree_body
(\
@difftree, $hash, $parent);
4116 # object is defined by:
4117 # - hash or hash_base alone
4118 # - hash_base and file_name
4121 # - hash or hash_base alone
4122 if ($hash || ($hash_base && !defined $file_name)) {
4123 my $object_id = $hash || $hash_base;
4125 my $git_command = git_cmd_str
();
4126 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4127 or die_error
('404 Not Found', "Object does not exist");
4131 or die_error
('404 Not Found', "Object does not exist");
4133 # - hash_base and file_name
4134 } elsif ($hash_base && defined $file_name) {
4135 $file_name =~ s
,/+$,,;
4137 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4138 or die_error
('404 Not Found', "Base object does not exist");
4140 # here errors should not hapen
4141 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4142 or die_error
(undef, "Open git-ls-tree failed");
4146 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4147 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4148 die_error
('404 Not Found', "File or directory for given base does not exist");
4153 die_error
('404 Not Found', "Not enough information to find object");
4156 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4157 hash
=>$hash, hash_base
=>$hash_base,
4158 file_name
=>$file_name),
4159 -status
=> '302 Found');
4163 my $format = shift || 'html';
4170 # preparing $fd and %diffinfo for git_patchset_body
4172 if (defined $hash_base && defined $hash_parent_base) {
4173 if (defined $file_name) {
4175 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4176 $hash_parent_base, $hash_base,
4177 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4178 or die_error
(undef, "Open git-diff-tree failed");
4179 @difftree = map { chomp; $_ } <$fd>;
4181 or die_error
(undef, "Reading git-diff-tree failed");
4183 or die_error
('404 Not Found', "Blob diff not found");
4185 } elsif (defined $hash &&
4186 $hash =~ /[0-9a-fA-F]{40}/) {
4187 # try to find filename from $hash
4189 # read filtered raw output
4190 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4191 $hash_parent_base, $hash_base, "--"
4192 or die_error
(undef, "Open git-diff-tree failed");
4194 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4196 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4197 map { chomp; $_ } <$fd>;
4199 or die_error
(undef, "Reading git-diff-tree failed");
4201 or die_error
('404 Not Found', "Blob diff not found");
4204 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4207 if (@difftree > 1) {
4208 die_error
('404 Not Found', "Ambiguous blob diff specification");
4211 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4212 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4213 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4215 $hash_parent ||= $diffinfo{'from_id'};
4216 $hash ||= $diffinfo{'to_id'};
4218 # non-textual hash id's can be cached
4219 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4220 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4225 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4226 '-p', ($format eq 'html' ?
"--full-index" : ()),
4227 $hash_parent_base, $hash_base,
4228 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4229 or die_error
(undef, "Open git-diff-tree failed");
4232 # old/legacy style URI
4233 if (!%diffinfo && # if new style URI failed
4234 defined $hash && defined $hash_parent) {
4235 # fake git-diff-tree raw output
4236 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4237 $diffinfo{'from_id'} = $hash_parent;
4238 $diffinfo{'to_id'} = $hash;
4239 if (defined $file_name) {
4240 if (defined $file_parent) {
4241 $diffinfo{'status'} = '2';
4242 $diffinfo{'from_file'} = $file_parent;
4243 $diffinfo{'to_file'} = $file_name;
4244 } else { # assume not renamed
4245 $diffinfo{'status'} = '1';
4246 $diffinfo{'from_file'} = $file_name;
4247 $diffinfo{'to_file'} = $file_name;
4249 } else { # no filename given
4250 $diffinfo{'status'} = '2';
4251 $diffinfo{'from_file'} = $hash_parent;
4252 $diffinfo{'to_file'} = $hash;
4255 # non-textual hash id's can be cached
4256 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4257 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4262 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4263 '-p', ($format eq 'html' ?
"--full-index" : ()),
4264 $hash_parent, $hash, "--"
4265 or die_error
(undef, "Open git-diff failed");
4267 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4272 if ($format eq 'html') {
4274 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4275 hash
=>$hash, hash_parent
=>$hash_parent,
4276 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4277 file_name
=>$file_name, file_parent
=>$file_parent)},
4279 git_header_html
(undef, $expires);
4280 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4281 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4282 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4284 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4285 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4287 if (defined $file_name) {
4288 git_print_page_path
($file_name, "blob", $hash_base);
4290 print "<div class=\"page_path\"></div>\n";
4293 } elsif ($format eq 'plain') {
4295 -type
=> 'text/plain',
4296 -charset
=> 'utf-8',
4297 -expires
=> $expires,
4298 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4300 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4303 die_error
(undef, "Unknown blobdiff format");
4307 if ($format eq 'html') {
4308 print "<div class=\"page_body\">\n";
4310 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4313 print "</div>\n"; # class="page_body"
4317 while (my $line = <$fd>) {
4318 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4319 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4323 last if $line =~ m!^\+\+\+!;
4331 sub git_blobdiff_plain
{
4332 git_blobdiff
('plain');
4335 sub git_commitdiff
{
4336 my $format = shift || 'html';
4337 $hash ||= $hash_base || "HEAD";
4338 my %co = parse_commit
($hash);
4340 die_error
(undef, "Unknown commit object");
4343 # we need to prepare $formats_nav before any parameter munging
4345 if ($format eq 'html') {
4347 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4348 hash
=>$hash, hash_parent
=>$hash_parent)},
4351 if (defined $hash_parent) {
4352 # commitdiff with two commits given
4353 my $hash_parent_short = $hash_parent;
4354 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4355 $hash_parent_short = substr($hash_parent, 0, 7);
4359 $cgi->a({-href
=> href
(action
=>"commitdiff",
4360 hash
=>$hash_parent)},
4361 esc_html
($hash_parent_short)) .
4363 } elsif (!$co{'parent'}) {
4365 $formats_nav .= ' (initial)';
4366 } elsif (scalar @
{$co{'parents'}} == 1) {
4367 # single parent commit
4370 $cgi->a({-href
=> href
(action
=>"commitdiff",
4371 hash
=>$co{'parent'})},
4372 esc_html
(substr($co{'parent'}, 0, 7))) .
4379 $cgi->a({-href
=> href
(action
=>"commitdiff",
4381 esc_html
(substr($_, 0, 7)));
4382 } @
{$co{'parents'}} ) .
4387 if (!defined $hash_parent) {
4388 $hash_parent = $co{'parent'} || '--root';
4394 if ($format eq 'html') {
4395 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4396 "--no-commit-id", "--patch-with-raw", "--full-index",
4397 $hash_parent, $hash, "--"
4398 or die_error
(undef, "Open git-diff-tree failed");
4400 while (my $line = <$fd>) {
4402 # empty line ends raw part of diff-tree output
4404 push @difftree, $line;
4407 } elsif ($format eq 'plain') {
4408 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4409 '-p', $hash_parent, $hash, "--"
4410 or die_error
(undef, "Open git-diff-tree failed");
4413 die_error
(undef, "Unknown commitdiff format");
4416 # non-textual hash id's can be cached
4418 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4422 # write commit message
4423 if ($format eq 'html') {
4424 my $refs = git_get_references
();
4425 my $ref = format_ref_marker
($refs, $co{'id'});
4427 git_header_html
(undef, $expires);
4428 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4429 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4430 git_print_authorship
(\
%co);
4431 print "<div class=\"page_body\">\n";
4432 if (@
{$co{'comment'}} > 1) {
4433 print "<div class=\"log\">\n";
4434 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4435 print "</div>\n"; # class="log"
4438 } elsif ($format eq 'plain') {
4439 my $refs = git_get_references
("tags");
4440 my $tagname = git_get_rev_name_tags
($hash);
4441 my $filename = basename
($project) . "-$hash.patch";
4444 -type
=> 'text/plain',
4445 -charset
=> 'utf-8',
4446 -expires
=> $expires,
4447 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4448 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4451 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4452 Subject: $co{'title'}
4454 print "X-Git-Tag: $tagname\n" if $tagname;
4455 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4457 foreach my $line (@
{$co{'comment'}}) {
4464 if ($format eq 'html') {
4465 git_difftree_body
(\
@difftree, $hash, $hash_parent);
4468 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
4470 print "</div>\n"; # class="page_body"
4473 } elsif ($format eq 'plain') {
4477 or print "Reading git-diff-tree failed\n";
4481 sub git_commitdiff_plain
{
4482 git_commitdiff
('plain');
4486 if (!defined $hash_base) {
4487 $hash_base = git_get_head_hash
($project);
4489 if (!defined $page) {
4493 my %co = parse_commit
($hash_base);
4495 die_error
(undef, "Unknown commit object");
4498 my $refs = git_get_references
();
4499 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4501 if (!defined $hash && defined $file_name) {
4502 $hash = git_get_hash_by_path
($hash_base, $file_name);
4504 if (defined $hash) {
4505 $ftype = git_get_type
($hash);
4508 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4510 my $paging_nav = '';
4513 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4514 file_name
=>$file_name)},
4516 $paging_nav .= " ⋅ " .
4517 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4518 file_name
=>$file_name, page
=>$page-1),
4519 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4521 $paging_nav .= "first";
4522 $paging_nav .= " ⋅ prev";
4524 if ($#commitlist >= 100) {
4525 $paging_nav .= " ⋅ " .
4526 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4527 file_name
=>$file_name, page
=>$page+1),
4528 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4530 $paging_nav .= " ⋅ next";
4533 if ($#commitlist >= 100) {
4535 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4536 file_name
=>$file_name, page
=>$page+1),
4537 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4541 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4542 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4543 git_print_page_path
($file_name, $ftype, $hash_base);
4545 git_history_body
(\
@commitlist, 0, 99,
4546 $refs, $hash_base, $ftype, $next_link);
4552 my ($have_search) = gitweb_check_feature
('search');
4553 if (!$have_search) {
4554 die_error
('403 Permission denied', "Permission denied");
4556 if (!defined $searchtext) {
4557 die_error
(undef, "Text field empty");
4559 if (!defined $hash) {
4560 $hash = git_get_head_hash
($project);
4562 my %co = parse_commit
($hash);
4564 die_error
(undef, "Unknown commit object");
4566 if (!defined $page) {
4570 $searchtype ||= 'commit';
4571 if ($searchtype eq 'pickaxe') {
4572 # pickaxe may take all resources of your box and run for several minutes
4573 # with every query - so decide by yourself how public you make this feature
4574 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4575 if (!$have_pickaxe) {
4576 die_error
('403 Permission denied', "Permission denied");
4582 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4584 if ($searchtype eq 'commit') {
4585 $greptype = "--grep=";
4586 } elsif ($searchtype eq 'author') {
4587 $greptype = "--author=";
4588 } elsif ($searchtype eq 'committer') {
4589 $greptype = "--committer=";
4591 $greptype .= $searchtext;
4592 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4594 my $paging_nav = '';
4597 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4598 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4600 $paging_nav .= " ⋅ " .
4601 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4602 searchtext
=>$searchtext, searchtype
=>$searchtype,
4604 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4606 $paging_nav .= "first";
4607 $paging_nav .= " ⋅ prev";
4609 if ($#commitlist >= 100) {
4610 $paging_nav .= " ⋅ " .
4611 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4612 searchtext
=>$searchtext, searchtype
=>$searchtype,
4614 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4616 $paging_nav .= " ⋅ next";
4619 if ($#commitlist >= 100) {
4621 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4622 searchtext
=>$searchtext, searchtype
=>$searchtype,
4624 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4627 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4628 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4629 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4632 if ($searchtype eq 'pickaxe') {
4633 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4634 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4636 print "<table cellspacing=\"0\">\n";
4639 my $git_command = git_cmd_str
();
4640 open my $fd, "-|", "$git_command rev-list $hash | " .
4641 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4644 while (my $line = <$fd>) {
4645 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4648 $set{'from_id'} = $3;
4650 $set{'id'} = $set{'to_id'};
4651 if ($set{'id'} =~ m/0{40}/) {
4652 $set{'id'} = $set{'from_id'};
4654 if ($set{'id'} =~ m/0{40}/) {
4658 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4661 print "<tr class=\"dark\">\n";
4663 print "<tr class=\"light\">\n";
4666 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4667 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4669 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4670 -class => "list subject"},
4671 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4672 while (my $setref = shift @files) {
4674 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4675 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4677 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4681 "<td class=\"link\">" .
4682 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4684 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4688 %co = parse_commit
($1);
4698 sub git_search_help
{
4700 git_print_page_nav
('','', $hash,$hash,$hash);
4703 <dt><b>commit</b></dt>
4704 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4705 <dt><b>author</b></dt>
4706 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4707 <dt><b>committer</b></dt>
4708 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4710 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4711 if ($have_pickaxe) {
4713 <dt><b>pickaxe</b></dt>
4714 <dd>All commits that caused the string to appear or disappear from any file (changes that
4715 added, removed or "modified" the string) will be listed. This search can take a while and
4716 takes a lot of strain on the server, so please use it wisely.</dd>
4724 my $head = git_get_head_hash
($project);
4725 if (!defined $hash) {
4728 if (!defined $page) {
4731 my $refs = git_get_references
();
4733 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4735 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4737 if ($#commitlist >= 100) {
4739 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4740 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4744 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4745 git_print_header_div
('summary', $project);
4747 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4752 ## ......................................................................
4753 ## feeds (RSS, Atom; OPML)
4756 my $format = shift || 'atom';
4757 my ($have_blame) = gitweb_check_feature
('blame');
4759 # Atom: http://www.atomenabled.org/developers/syndication/
4760 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4761 if ($format ne 'rss' && $format ne 'atom') {
4762 die_error
(undef, "Unknown web feed format");
4765 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4766 my $head = $hash || 'HEAD';
4767 my @commitlist = parse_commits
($head, 150);
4771 my $content_type = "application/$format+xml";
4772 if (defined $cgi->http('HTTP_ACCEPT') &&
4773 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4774 # browser (feed reader) prefers text/xml
4775 $content_type = 'text/xml';
4777 if (defined($commitlist[0])) {
4778 %latest_commit = %{$commitlist[0]};
4779 %latest_date = parse_date
($latest_commit{'author_epoch'});
4781 -type
=> $content_type,
4782 -charset
=> 'utf-8',
4783 -last_modified
=> $latest_date{'rfc2822'});
4786 -type
=> $content_type,
4787 -charset
=> 'utf-8');
4790 # Optimization: skip generating the body if client asks only
4791 # for Last-Modified date.
4792 return if ($cgi->request_method() eq 'HEAD');
4795 my $title = "$site_name - $project/$action";
4796 my $feed_type = 'log';
4797 if (defined $hash) {
4798 $title .= " - '$hash'";
4799 $feed_type = 'branch log';
4800 if (defined $file_name) {
4801 $title .= " :: $file_name";
4802 $feed_type = 'history';
4804 } elsif (defined $file_name) {
4805 $title .= " - $file_name";
4806 $feed_type = 'history';
4808 $title .= " $feed_type";
4809 my $descr = git_get_project_description
($project);
4810 if (defined $descr) {
4811 $descr = esc_html
($descr);
4813 $descr = "$project " .
4814 ($format eq 'rss' ?
'RSS' : 'Atom') .
4817 my $owner = git_get_project_owner
($project);
4818 $owner = esc_html
($owner);
4822 if (defined $file_name) {
4823 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4824 } elsif (defined $hash) {
4825 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4827 $alt_url = href
(-full
=>1, action
=>"summary");
4829 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
4830 if ($format eq 'rss') {
4832 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4835 print "<title>$title</title>\n" .
4836 "<link>$alt_url</link>\n" .
4837 "<description>$descr</description>\n" .
4838 "<language>en</language>\n";
4839 } elsif ($format eq 'atom') {
4841 <feed xmlns="http://www.w3.org/2005/Atom">
4843 print "<title>$title</title>\n" .
4844 "<subtitle>$descr</subtitle>\n" .
4845 '<link rel="alternate" type="text/html" href="' .
4846 $alt_url . '" />' . "\n" .
4847 '<link rel="self" type="' . $content_type . '" href="' .
4848 $cgi->self_url() . '" />' . "\n" .
4849 "<id>" . href
(-full
=>1) . "</id>\n" .
4850 # use project owner for feed author
4851 "<author><name>$owner</name></author>\n";
4852 if (defined $favicon) {
4853 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4855 if (defined $logo_url) {
4856 # not twice as wide as tall: 72 x 27 pixels
4857 print "<logo>" . esc_url
($logo) . "</logo>\n";
4859 if (! %latest_date) {
4860 # dummy date to keep the feed valid until commits trickle in:
4861 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4863 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4868 for (my $i = 0; $i <= $#commitlist; $i++) {
4869 my %co = %{$commitlist[$i]};
4870 my $commit = $co{'id'};
4871 # we read 150, we always show 30 and the ones more recent than 48 hours
4872 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4875 my %cd = parse_date
($co{'author_epoch'});
4877 # get list of changed files
4878 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4879 $co{'parent'}, $co{'id'}, "--", (defined $file_name ?
$file_name : ())
4881 my @difftree = map { chomp; $_ } <$fd>;
4885 # print element (entry, item)
4886 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4887 if ($format eq 'rss') {
4889 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4890 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4891 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4892 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4893 "<link>$co_url</link>\n" .
4894 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4895 "<content:encoded>" .
4897 } elsif ($format eq 'atom') {
4899 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4900 "<updated>$cd{'iso-8601'}</updated>\n" .
4902 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4903 if ($co{'author_email'}) {
4904 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4906 print "</author>\n" .
4907 # use committer for contributor
4909 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4910 if ($co{'committer_email'}) {
4911 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4913 print "</contributor>\n" .
4914 "<published>$cd{'iso-8601'}</published>\n" .
4915 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4916 "<id>$co_url</id>\n" .
4917 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4918 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4920 my $comment = $co{'comment'};
4922 foreach my $line (@
$comment) {
4923 $line = esc_html
($line);
4926 print "</pre><ul>\n";
4927 foreach my $difftree_line (@difftree) {
4928 my %difftree = parse_difftree_raw_line
($difftree_line);
4929 next if !$difftree{'from_id'};
4931 my $file = $difftree{'file'} || $difftree{'to_file'};
4935 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4936 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4937 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4938 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4939 -title
=> "diff"}, 'D');
4941 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4942 file_name
=>$file, hash_base
=>$commit),
4943 -title
=> "blame"}, 'B');
4945 # if this is not a feed of a file history
4946 if (!defined $file_name || $file_name ne $file) {
4947 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4948 file_name
=>$file, hash
=>$commit),
4949 -title
=> "history"}, 'H');
4951 $file = esc_path
($file);
4955 if ($format eq 'rss') {
4956 print "</ul>]]>\n" .
4957 "</content:encoded>\n" .
4959 } elsif ($format eq 'atom') {
4960 print "</ul>\n</div>\n" .
4967 if ($format eq 'rss') {
4968 print "</channel>\n</rss>\n";
4969 } elsif ($format eq 'atom') {
4983 my @list = git_get_projects_list
();
4985 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4987 <?xml version="1.0" encoding="utf-8"?>
4988 <opml version="1.0">
4990 <title>$site_name OPML Export</title>
4993 <outline text="git RSS feeds">
4996 foreach my $pr (@list) {
4998 my $head = git_get_head_hash
($proj{'path'});
4999 if (!defined $head) {
5002 $git_dir = "$projectroot/$proj{'path'}";
5003 my %co = parse_commit
($head);
5008 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5009 my $rss = "$my_url?p=$proj{'path'};a=rss";
5010 my $html = "$my_url?p=$proj{'path'};a=summary";
5011 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";