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}) {
2334 if (ref($line) eq "HASH") {
2335 # pre-parsed (or generated by hand)
2338 $diff = parse_difftree_raw_line
($line);
2342 print "<tr class=\"dark\">\n";
2344 print "<tr class=\"light\">\n";
2348 if (exists $diff->{'nparents'}) { # combined diff
2350 fill_from_file_info
($diff, @parents)
2351 unless exists $diff->{'from_file'};
2353 if ($diff->{'to_id'} ne ('0' x
40)) {
2354 # file exists in the result (child) commit
2356 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2357 file_name
=>$diff->{'to_file'},
2359 -class => "list"}, esc_path
($diff->{'to_file'})) .
2363 esc_path
($diff->{'to_file'}) .
2367 if ($action eq 'commitdiff') {
2370 print "<td class=\"link\">" .
2371 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2376 my $has_history = 0;
2377 my $not_deleted = 0;
2378 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2379 my $hash_parent = $parents[$i];
2380 my $from_hash = $diff->{'from_id'}[$i];
2381 my $from_path = $diff->{'from_file'}[$i];
2382 my $status = $diff->{'status'}[$i];
2384 $has_history ||= ($status ne 'A');
2385 $not_deleted ||= ($status ne 'D');
2387 if ($status eq 'A') {
2388 print "<td class=\"link\" align=\"right\"> | </td>\n";
2389 } elsif ($status eq 'D') {
2390 print "<td class=\"link\">" .
2391 $cgi->a({-href
=> href
(action
=>"blob",
2394 file_name
=>$from_path)},
2398 if ($diff->{'to_id'} eq $from_hash) {
2399 print "<td class=\"link nochange\">";
2401 print "<td class=\"link\">";
2403 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2404 hash
=>$diff->{'to_id'},
2405 hash_parent
=>$from_hash,
2407 hash_parent_base
=>$hash_parent,
2408 file_name
=>$diff->{'to_file'},
2409 file_parent
=>$from_path)},
2415 print "<td class=\"link\">";
2417 print $cgi->a({-href
=> href
(action
=>"blob",
2418 hash
=>$diff->{'to_id'},
2419 file_name
=>$diff->{'to_file'},
2422 print " | " if ($has_history);
2425 print $cgi->a({-href
=> href
(action
=>"history",
2426 file_name
=>$diff->{'to_file'},
2433 next; # instead of 'else' clause, to avoid extra indent
2435 # else ordinary diff
2437 my ($to_mode_oct, $to_mode_str, $to_file_type);
2438 my ($from_mode_oct, $from_mode_str, $from_file_type);
2439 if ($diff->{'to_mode'} ne ('0' x
6)) {
2440 $to_mode_oct = oct $diff->{'to_mode'};
2441 if (S_ISREG
($to_mode_oct)) { # only for regular file
2442 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2444 $to_file_type = file_type
($diff->{'to_mode'});
2446 if ($diff->{'from_mode'} ne ('0' x
6)) {
2447 $from_mode_oct = oct $diff->{'from_mode'};
2448 if (S_ISREG
($to_mode_oct)) { # only for regular file
2449 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2451 $from_file_type = file_type
($diff->{'from_mode'});
2454 if ($diff->{'status'} eq "A") { # created
2455 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2456 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2457 $mode_chng .= "]</span>";
2459 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2460 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2461 -class => "list"}, esc_path
($diff->{'file'}));
2463 print "<td>$mode_chng</td>\n";
2464 print "<td class=\"link\">";
2465 if ($action eq 'commitdiff') {
2468 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2471 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2472 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2476 } elsif ($diff->{'status'} eq "D") { # deleted
2477 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2479 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2480 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2481 -class => "list"}, esc_path
($diff->{'file'}));
2483 print "<td>$mode_chng</td>\n";
2484 print "<td class=\"link\">";
2485 if ($action eq 'commitdiff') {
2488 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2491 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2492 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2495 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2496 file_name
=>$diff->{'file'})},
2499 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2500 file_name
=>$diff->{'file'})},
2504 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2505 my $mode_chnge = "";
2506 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2507 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2508 if ($from_file_type ne $to_file_type) {
2509 $mode_chnge .= " from $from_file_type to $to_file_type";
2511 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2512 if ($from_mode_str && $to_mode_str) {
2513 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2514 } elsif ($to_mode_str) {
2515 $mode_chnge .= " mode: $to_mode_str";
2518 $mode_chnge .= "]</span>\n";
2521 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2522 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2523 -class => "list"}, esc_path
($diff->{'file'}));
2525 print "<td>$mode_chnge</td>\n";
2526 print "<td class=\"link\">";
2527 if ($action eq 'commitdiff') {
2530 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2532 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2533 # "commit" view and modified file (not onlu mode changed)
2534 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2535 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2536 hash_base
=>$hash, hash_parent_base
=>$parent,
2537 file_name
=>$diff->{'file'})},
2541 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2542 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2545 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2546 file_name
=>$diff->{'file'})},
2549 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2550 file_name
=>$diff->{'file'})},
2554 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2555 my %status_name = ('R' => 'moved', 'C' => 'copied');
2556 my $nstatus = $status_name{$diff->{'status'}};
2558 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2559 # mode also for directories, so we cannot use $to_mode_str
2560 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2563 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2564 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2565 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2566 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2567 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2568 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2569 -class => "list"}, esc_path
($diff->{'from_file'})) .
2570 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2571 "<td class=\"link\">";
2572 if ($action eq 'commitdiff') {
2575 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2577 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2578 # "commit" view and modified file (not only pure rename or copy)
2579 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2580 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2581 hash_base
=>$hash, hash_parent_base
=>$parent,
2582 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2586 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2587 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2590 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2591 file_name
=>$diff->{'to_file'})},
2594 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2595 file_name
=>$diff->{'to_file'})},
2599 } # we should not encounter Unmerged (U) or Unknown (X) status
2605 sub git_patchset_body
{
2606 my ($fd, $difftree, $hash, @hash_parents) = @_;
2607 my ($hash_parent) = $hash_parents[0];
2610 my $patch_number = 0;
2615 print "<div class=\"patchset\">\n";
2617 # skip to first patch
2618 while ($patch_line = <$fd>) {
2621 last if ($patch_line =~ m/^diff /);
2625 while ($patch_line) {
2627 my ($from_id, $to_id);
2630 #assert($patch_line =~ m/^diff /) if DEBUG;
2631 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2633 push @diff_header, $patch_line;
2635 # extended diff header
2637 while ($patch_line = <$fd>) {
2640 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2642 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2645 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2646 $from_id = [ split(',', $1) ];
2650 push @diff_header, $patch_line;
2652 my $last_patch_line = $patch_line;
2654 # check if current patch belong to current raw line
2655 # and parse raw git-diff line if needed
2656 if (defined $diffinfo &&
2657 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2658 $diffinfo->{'to_id'} eq $to_id) {
2659 # this is split patch
2660 print "<div class=\"patch cont\">\n";
2662 # advance raw git-diff output if needed
2663 $patch_idx++ if defined $diffinfo;
2665 # read and prepare patch information
2666 if (ref($difftree->[$patch_idx]) eq "HASH") {
2667 # pre-parsed (or generated by hand)
2668 $diffinfo = $difftree->[$patch_idx];
2670 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2672 if ($diffinfo->{'nparents'}) {
2676 fill_from_file_info
($diffinfo, @hash_parents)
2677 unless exists $diffinfo->{'from_file'};
2678 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2679 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2680 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2681 $from{'href'}[$i] = href
(action
=>"blob",
2682 hash_base
=>$hash_parents[$i],
2683 hash
=>$diffinfo->{'from_id'}[$i],
2684 file_name
=>$from{'file'}[$i]);
2686 $from{'href'}[$i] = undef;
2690 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2691 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2692 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2693 hash
=>$diffinfo->{'from_id'},
2694 file_name
=>$from{'file'});
2696 delete $from{'href'};
2699 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2700 if ($diffinfo->{'status'} ne "D") { # not deleted file
2701 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2702 hash
=>$diffinfo->{'to_id'},
2703 file_name
=>$to{'file'});
2707 # this is first patch for raw difftree line with $patch_idx index
2708 # we index @$difftree array from 0, but number patches from 1
2709 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2712 # print "git diff" header
2713 $patch_line = shift @diff_header;
2714 if ($diffinfo->{'nparents'}) {
2717 $patch_line =~ s!^(diff (.*?) )"?.*$!$1!;
2719 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2720 esc_path
($to{'file'}));
2721 } else { # file was deleted
2722 $patch_line .= esc_path
($to{'file'});
2727 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2728 if ($from{'href'}) {
2729 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2730 'a/' . esc_path
($from{'file'}));
2731 } else { # file was added
2732 $patch_line .= 'a/' . esc_path
($from{'file'});
2736 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2737 'b/' . esc_path
($to{'file'}));
2738 } else { # file was deleted
2739 $patch_line .= 'b/' . esc_path
($to{'file'});
2743 print "<div class=\"diff header\">$patch_line</div>\n";
2745 # print extended diff header
2746 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2748 foreach $patch_line (@diff_header) {
2750 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2751 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2752 esc_path
($from{'file'}));
2754 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2755 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2756 esc_path
($to{'file'}));
2758 # match single <mode>
2759 if ($patch_line =~ m/\s(\d{6})$/) {
2760 $patch_line .= '<span class="info"> (' .
2761 file_type_long
($1) .
2765 if ($patch_line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2766 # can match only for combined diff
2767 $patch_line = 'index ';
2768 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2769 if ($from{'href'}[$i]) {
2770 $patch_line .= $cgi->a({-href
=>$from{'href'}[$i],
2772 substr($diffinfo->{'from_id'}[$i],0,7));
2774 $patch_line .= '0' x
7;
2777 $patch_line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2779 $patch_line .= '..';
2781 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2782 substr($diffinfo->{'to_id'},0,7));
2784 $patch_line .= '0' x
7;
2787 } elsif ($patch_line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2788 # can match only for ordinary diff
2789 my ($from_link, $to_link);
2790 if ($from{'href'}) {
2791 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2792 substr($diffinfo->{'from_id'},0,7));
2794 $from_link = '0' x
7;
2797 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2798 substr($diffinfo->{'to_id'},0,7));
2803 # my ($from_hash, $to_hash) =
2804 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2805 # my ($from_id, $to_id) =
2806 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2807 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2809 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2810 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2812 print $patch_line . "<br/>\n";
2814 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2816 # from-file/to-file diff header
2817 $patch_line = $last_patch_line;
2818 if (! $patch_line) {
2819 print "</div>\n"; # class="patch"
2822 next PATCH
if ($patch_line =~ m/^diff /);
2823 #assert($patch_line =~ m/^---/) if DEBUG;
2824 if (!$diffinfo->{'nparents'} && # not from-file line for combined diff
2825 $from{'href'} && $patch_line =~ m!^--- "?a/!) {
2826 $patch_line = '--- a/' .
2827 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2828 esc_path
($from{'file'}));
2830 print "<div class=\"diff from_file\">$patch_line</div>\n";
2832 $patch_line = <$fd>;
2835 #assert($patch_line =~ m/^+++/) if DEBUG;
2836 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2837 $patch_line = '+++ b/' .
2838 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2839 esc_path
($to{'file'}));
2841 print "<div class=\"diff to_file\">$patch_line</div>\n";
2845 while ($patch_line = <$fd>) {
2848 next PATCH
if ($patch_line =~ m/^diff /);
2850 print format_diff_line
($patch_line, \
%from, \
%to);
2854 print "</div>\n"; # class="patch"
2856 print "<div class=\"diff nodifferences\">No differences found</div>\n" if (!$patch_number);
2858 print "</div>\n"; # class="patchset"
2861 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2863 sub git_project_list_body
{
2864 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2866 my ($check_forks) = gitweb_check_feature
('forks');
2869 foreach my $pr (@
$projlist) {
2870 my (@aa) = git_get_last_activity
($pr->{'path'});
2874 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2875 if (!defined $pr->{'descr'}) {
2876 my $descr = git_get_project_description
($pr->{'path'}) || "";
2877 $pr->{'descr_long'} = decode_utf8
($descr);
2878 $pr->{'descr'} = chop_str
($descr, 25, 5);
2880 if (!defined $pr->{'owner'}) {
2881 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2884 my $pname = $pr->{'path'};
2885 if (($pname =~ s/\.git$//) &&
2886 ($pname !~ /\/$/) &&
2887 (-d
"$projectroot/$pname")) {
2888 $pr->{'forks'} = "-d $projectroot/$pname";
2894 push @projects, $pr;
2897 $order ||= $default_projects_order;
2898 $from = 0 unless defined $from;
2899 $to = $#projects if (!defined $to || $#projects < $to);
2901 print "<table class=\"project_list\">\n";
2902 unless ($no_header) {
2905 print "<th></th>\n";
2907 if ($order eq "project") {
2908 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2909 print "<th>Project</th>\n";
2912 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2913 -class => "header"}, "Project") .
2916 if ($order eq "descr") {
2917 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2918 print "<th>Description</th>\n";
2921 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2922 -class => "header"}, "Description") .
2925 if ($order eq "owner") {
2926 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2927 print "<th>Owner</th>\n";
2930 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2931 -class => "header"}, "Owner") .
2934 if ($order eq "age") {
2935 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2936 print "<th>Last Change</th>\n";
2939 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2940 -class => "header"}, "Last Change") .
2943 print "<th></th>\n" .
2947 for (my $i = $from; $i <= $to; $i++) {
2948 my $pr = $projects[$i];
2950 print "<tr class=\"dark\">\n";
2952 print "<tr class=\"light\">\n";
2957 if ($pr->{'forks'}) {
2958 print "<!-- $pr->{'forks'} -->\n";
2959 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2963 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2964 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2965 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2966 -class => "list", -title
=> $pr->{'descr_long'}},
2967 esc_html
($pr->{'descr'})) . "</td>\n" .
2968 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2969 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2970 $pr->{'age_string'} . "</td>\n" .
2971 "<td class=\"link\">" .
2972 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2973 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2974 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2975 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2976 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2980 if (defined $extra) {
2983 print "<td></td>\n";
2985 print "<td colspan=\"5\">$extra</td>\n" .
2991 sub git_shortlog_body
{
2992 # uses global variable $project
2993 my ($commitlist, $from, $to, $refs, $extra) = @_;
2995 my $have_snapshot = gitweb_have_snapshot
();
2997 $from = 0 unless defined $from;
2998 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3000 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3002 for (my $i = $from; $i <= $to; $i++) {
3003 my %co = %{$commitlist->[$i]};
3004 my $commit = $co{'id'};
3005 my $ref = format_ref_marker
($refs, $commit);
3007 print "<tr class=\"dark\">\n";
3009 print "<tr class=\"light\">\n";
3012 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3013 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3014 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3016 print format_subject_html
($co{'title'}, $co{'title_short'},
3017 href
(action
=>"commit", hash
=>$commit), $ref);
3019 "<td class=\"link\">" .
3020 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3021 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3022 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3023 if ($have_snapshot) {
3024 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3029 if (defined $extra) {
3031 "<td colspan=\"4\">$extra</td>\n" .
3037 sub git_history_body
{
3038 # Warning: assumes constant type (blob or tree) during history
3039 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3041 $from = 0 unless defined $from;
3042 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3044 print "<table class=\"history\" cellspacing=\"0\">\n";
3046 for (my $i = $from; $i <= $to; $i++) {
3047 my %co = %{$commitlist->[$i]};
3051 my $commit = $co{'id'};
3053 my $ref = format_ref_marker
($refs, $commit);
3056 print "<tr class=\"dark\">\n";
3058 print "<tr class=\"light\">\n";
3061 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3062 # shortlog uses chop_str($co{'author_name'}, 10)
3063 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3065 # originally git_history used chop_str($co{'title'}, 50)
3066 print format_subject_html
($co{'title'}, $co{'title_short'},
3067 href
(action
=>"commit", hash
=>$commit), $ref);
3069 "<td class=\"link\">" .
3070 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3071 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3073 if ($ftype eq 'blob') {
3074 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3075 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3076 if (defined $blob_current && defined $blob_parent &&
3077 $blob_current ne $blob_parent) {
3079 $cgi->a({-href
=> href
(action
=>"blobdiff",
3080 hash
=>$blob_current, hash_parent
=>$blob_parent,
3081 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3082 file_name
=>$file_name)},
3089 if (defined $extra) {
3091 "<td colspan=\"4\">$extra</td>\n" .
3098 # uses global variable $project
3099 my ($taglist, $from, $to, $extra) = @_;
3100 $from = 0 unless defined $from;
3101 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3103 print "<table class=\"tags\" cellspacing=\"0\">\n";
3105 for (my $i = $from; $i <= $to; $i++) {
3106 my $entry = $taglist->[$i];
3108 my $comment = $tag{'subject'};
3110 if (defined $comment) {
3111 $comment_short = chop_str
($comment, 30, 5);
3114 print "<tr class=\"dark\">\n";
3116 print "<tr class=\"light\">\n";
3119 if (defined $tag{'age'}) {
3120 print "<td><i>$tag{'age'}</i></td>\n";
3122 print "<td></td>\n";
3125 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3126 -class => "list name"}, esc_html
($tag{'name'})) .
3129 if (defined $comment) {
3130 print format_subject_html
($comment, $comment_short,
3131 href
(action
=>"tag", hash
=>$tag{'id'}));
3134 "<td class=\"selflink\">";
3135 if ($tag{'type'} eq "tag") {
3136 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3141 "<td class=\"link\">" . " | " .
3142 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3143 if ($tag{'reftype'} eq "commit") {
3144 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3145 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3146 } elsif ($tag{'reftype'} eq "blob") {
3147 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3152 if (defined $extra) {
3154 "<td colspan=\"5\">$extra</td>\n" .
3160 sub git_heads_body
{
3161 # uses global variable $project
3162 my ($headlist, $head, $from, $to, $extra) = @_;
3163 $from = 0 unless defined $from;
3164 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3166 print "<table class=\"heads\" cellspacing=\"0\">\n";
3168 for (my $i = $from; $i <= $to; $i++) {
3169 my $entry = $headlist->[$i];
3171 my $curr = $ref{'id'} eq $head;
3173 print "<tr class=\"dark\">\n";
3175 print "<tr class=\"light\">\n";
3178 print "<td><i>$ref{'age'}</i></td>\n" .
3179 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3180 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3181 -class => "list name"},esc_html
($ref{'name'})) .
3183 "<td class=\"link\">" .
3184 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3185 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3186 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3190 if (defined $extra) {
3192 "<td colspan=\"3\">$extra</td>\n" .
3198 sub git_search_grep_body
{
3199 my ($commitlist, $from, $to, $extra) = @_;
3200 $from = 0 unless defined $from;
3201 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3203 print "<table class=\"grep\" cellspacing=\"0\">\n";
3205 for (my $i = $from; $i <= $to; $i++) {
3206 my %co = %{$commitlist->[$i]};
3210 my $commit = $co{'id'};
3212 print "<tr class=\"dark\">\n";
3214 print "<tr class=\"light\">\n";
3217 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3218 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3220 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3221 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3222 my $comment = $co{'comment'};
3223 foreach my $line (@
$comment) {
3224 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3225 my $lead = esc_html
($1) || "";
3226 $lead = chop_str
($lead, 30, 10);
3227 my $match = esc_html
($2) || "";
3228 my $trail = esc_html
($3) || "";
3229 $trail = chop_str
($trail, 30, 10);
3230 my $text = "$lead<span class=\"match\">$match</span>$trail";
3231 print chop_str
($text, 80, 5) . "<br/>\n";
3235 "<td class=\"link\">" .
3236 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3238 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3242 if (defined $extra) {
3244 "<td colspan=\"3\">$extra</td>\n" .
3250 ## ======================================================================
3251 ## ======================================================================
3254 sub git_project_list
{
3255 my $order = $cgi->param('o');
3256 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3257 die_error
(undef, "Unknown order parameter");
3260 my @list = git_get_projects_list
();
3262 die_error
(undef, "No projects found");
3266 if (-f
$home_text) {
3267 print "<div class=\"index_include\">\n";
3268 open (my $fd, $home_text);
3273 git_project_list_body
(\
@list, $order);
3278 my $order = $cgi->param('o');
3279 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3280 die_error
(undef, "Unknown order parameter");
3283 my @list = git_get_projects_list
($project);
3285 die_error
(undef, "No forks found");
3289 git_print_page_nav
('','');
3290 git_print_header_div
('summary', "$project forks");
3291 git_project_list_body
(\
@list, $order);
3295 sub git_project_index
{
3296 my @projects = git_get_projects_list
($project);
3299 -type
=> 'text/plain',
3300 -charset
=> 'utf-8',
3301 -content_disposition
=> 'inline; filename="index.aux"');
3303 foreach my $pr (@projects) {
3304 if (!exists $pr->{'owner'}) {
3305 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3308 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3309 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3310 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3311 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3315 print "$path $owner\n";
3320 my $descr = git_get_project_description
($project) || "none";
3321 my %co = parse_commit
("HEAD");
3322 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3323 my $head = $co{'id'};
3325 my $owner = git_get_project_owner
($project);
3327 my $refs = git_get_references
();
3328 # These get_*_list functions return one more to allow us to see if
3329 # there are more ...
3330 my @taglist = git_get_tags_list
(16);
3331 my @headlist = git_get_heads_list
(16);
3333 my ($check_forks) = gitweb_check_feature
('forks');
3336 @forklist = git_get_projects_list
($project);
3340 git_print_page_nav
('summary','', $head);
3342 print "<div class=\"title\"> </div>\n";
3343 print "<table cellspacing=\"0\">\n" .
3344 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3345 "<tr><td>owner</td><td>$owner</td></tr>\n" .
3346 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3347 # use per project git URL list in $projectroot/$project/cloneurl
3348 # or make project git URL from git base URL and project name
3349 my $url_tag = "URL";
3350 my @url_list = git_get_project_url_list
($project);
3351 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3352 foreach my $git_url (@url_list) {
3353 next unless $git_url;
3354 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3359 if (-s
"$projectroot/$project/README.html") {
3360 if (open my $fd, "$projectroot/$project/README.html") {
3361 print "<div class=\"title\">readme</div>\n";
3362 print $_ while (<$fd>);
3367 # we need to request one more than 16 (0..15) to check if
3369 my @commitlist = parse_commits
($head, 17);
3370 git_print_header_div
('shortlog');
3371 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3372 $#commitlist <= 15 ?
undef :
3373 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3376 git_print_header_div
('tags');
3377 git_tags_body
(\
@taglist, 0, 15,
3378 $#taglist <= 15 ?
undef :
3379 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3383 git_print_header_div
('heads');
3384 git_heads_body
(\
@headlist, $head, 0, 15,
3385 $#headlist <= 15 ?
undef :
3386 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3390 git_print_header_div
('forks');
3391 git_project_list_body
(\
@forklist, undef, 0, 15,
3392 $#forklist <= 15 ?
undef :
3393 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3401 my $head = git_get_head_hash
($project);
3403 git_print_page_nav
('','', $head,undef,$head);
3404 my %tag = parse_tag
($hash);
3405 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3406 print "<div class=\"title_text\">\n" .
3407 "<table cellspacing=\"0\">\n" .
3409 "<td>object</td>\n" .
3410 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3411 $tag{'object'}) . "</td>\n" .
3412 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3413 $tag{'type'}) . "</td>\n" .
3415 if (defined($tag{'author'})) {
3416 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3417 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3418 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3419 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3422 print "</table>\n\n" .
3424 print "<div class=\"page_body\">";
3425 my $comment = $tag{'comment'};
3426 foreach my $line (@
$comment) {
3428 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3438 my ($have_blame) = gitweb_check_feature
('blame');
3440 die_error
('403 Permission denied', "Permission denied");
3442 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3443 $hash_base ||= git_get_head_hash
($project);
3444 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3445 my %co = parse_commit
($hash_base)
3446 or die_error
(undef, "Reading commit failed");
3447 if (!defined $hash) {
3448 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3449 or die_error
(undef, "Error looking up file");
3451 $ftype = git_get_type
($hash);
3452 if ($ftype !~ "blob") {
3453 die_error
('400 Bad Request', "Object is not a blob");
3455 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3456 $file_name, $hash_base)
3457 or die_error
(undef, "Open git-blame failed");
3460 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3463 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3466 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3468 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3469 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3470 git_print_page_path
($file_name, $ftype, $hash_base);
3471 my @rev_color = (qw(light2 dark2));
3472 my $num_colors = scalar(@rev_color);
3473 my $current_color = 0;
3476 <div class="page_body">
3477 <table class="blame">
3478 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3483 last unless defined $_;
3484 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3485 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3486 if (!exists $metainfo{$full_rev}) {
3487 $metainfo{$full_rev} = {};
3489 my $meta = $metainfo{$full_rev};
3492 if (/^(\S+) (.*)$/) {
3498 my $rev = substr($full_rev, 0, 8);
3499 my $author = $meta->{'author'};
3500 my %date = parse_date
($meta->{'author-time'},
3501 $meta->{'author-tz'});
3502 my $date = $date{'iso-tz'};
3504 $current_color = ++$current_color % $num_colors;
3506 print "<tr class=\"$rev_color[$current_color]\">\n";
3508 print "<td class=\"sha1\"";
3509 print " title=\"". esc_html
($author) . ", $date\"";
3510 print " rowspan=\"$group_size\"" if ($group_size > 1);
3512 print $cgi->a({-href
=> href
(action
=>"commit",
3514 file_name
=>$file_name)},
3518 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3519 or die_error
(undef, "Open git-rev-parse failed");
3520 my $parent_commit = <$dd>;
3522 chomp($parent_commit);
3523 my $blamed = href
(action
=> 'blame',
3524 file_name
=> $meta->{'filename'},
3525 hash_base
=> $parent_commit);
3526 print "<td class=\"linenr\">";
3527 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3529 -class => "linenr" },
3532 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3538 or print "Reading blob failed\n";
3545 my ($have_blame) = gitweb_check_feature
('blame');
3547 die_error
('403 Permission denied', "Permission denied");
3549 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3550 $hash_base ||= git_get_head_hash
($project);
3551 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3552 my %co = parse_commit
($hash_base)
3553 or die_error
(undef, "Reading commit failed");
3554 if (!defined $hash) {
3555 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3556 or die_error
(undef, "Error lookup file");
3558 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3559 or die_error
(undef, "Open git-annotate failed");
3562 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3565 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3568 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3570 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3571 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3572 git_print_page_path
($file_name, 'blob', $hash_base);
3573 print "<div class=\"page_body\">\n";
3575 <table class="blame">
3584 my @line_class = (qw(light dark));
3585 my $line_class_len = scalar (@line_class);
3586 my $line_class_num = $#line_class;
3587 while (my $line = <$fd>) {
3599 $line_class_num = ($line_class_num + 1) % $line_class_len;
3601 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3608 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
3611 $short_rev = substr ($long_rev, 0, 8);
3612 $age = time () - $time;
3613 $age_str = age_string
($age);
3614 $age_str =~ s/ / /g;
3615 $age_class = age_class
($age);
3616 $author = esc_html
($author);
3617 $author =~ s/ / /g;
3619 $data = untabify
($data);
3620 $data = esc_html
($data);
3623 <tr class="$line_class[$line_class_num]">
3624 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3625 <td class="$age_class">$age_str</td>
3627 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3628 <td class="pre">$data</td>
3631 } # while (my $line = <$fd>)
3632 print "</table>\n\n";
3634 or print "Reading blob failed.\n";
3640 my $head = git_get_head_hash
($project);
3642 git_print_page_nav
('','', $head,undef,$head);
3643 git_print_header_div
('summary', $project);
3645 my @tagslist = git_get_tags_list
();
3647 git_tags_body
(\
@tagslist);
3653 my $head = git_get_head_hash
($project);
3655 git_print_page_nav
('','', $head,undef,$head);
3656 git_print_header_div
('summary', $project);
3658 my @headslist = git_get_heads_list
();
3660 git_heads_body
(\
@headslist, $head);
3665 sub git_blob_plain
{
3668 if (!defined $hash) {
3669 if (defined $file_name) {
3670 my $base = $hash_base || git_get_head_hash
($project);
3671 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3672 or die_error
(undef, "Error lookup file");
3674 die_error
(undef, "No file name defined");
3676 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3677 # blobs defined by non-textual hash id's can be cached
3682 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3683 or die_error
(undef, "Couldn't cat $file_name, $hash");
3685 $type ||= blob_mimetype
($fd, $file_name);
3687 # save as filename, even when no $file_name is given
3688 my $save_as = "$hash";
3689 if (defined $file_name) {
3690 $save_as = $file_name;
3691 } elsif ($type =~ m/^text\//) {
3698 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3700 binmode STDOUT
, ':raw';
3702 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3710 if (!defined $hash) {
3711 if (defined $file_name) {
3712 my $base = $hash_base || git_get_head_hash
($project);
3713 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3714 or die_error
(undef, "Error lookup file");
3716 die_error
(undef, "No file name defined");
3718 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3719 # blobs defined by non-textual hash id's can be cached
3723 my ($have_blame) = gitweb_check_feature
('blame');
3724 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3725 or die_error
(undef, "Couldn't cat $file_name, $hash");
3726 my $mimetype = blob_mimetype
($fd, $file_name);
3727 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3729 return git_blob_plain
($mimetype);
3731 # we can have blame only for text/* mimetype
3732 $have_blame &&= ($mimetype =~ m!^text/!);
3734 git_header_html
(undef, $expires);
3735 my $formats_nav = '';
3736 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3737 if (defined $file_name) {
3740 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3741 hash
=>$hash, file_name
=>$file_name)},
3746 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3747 hash
=>$hash, file_name
=>$file_name)},
3750 $cgi->a({-href
=> href
(action
=>"blob_plain",
3751 hash
=>$hash, file_name
=>$file_name)},
3754 $cgi->a({-href
=> href
(action
=>"blob",
3755 hash_base
=>"HEAD", file_name
=>$file_name)},
3759 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3761 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3762 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3764 print "<div class=\"page_nav\">\n" .
3765 "<br/><br/></div>\n" .
3766 "<div class=\"title\">$hash</div>\n";
3768 git_print_page_path
($file_name, "blob", $hash_base);
3769 print "<div class=\"page_body\">\n";
3770 if ($mimetype =~ m!^text/!) {
3772 while (my $line = <$fd>) {
3775 $line = untabify
($line);
3776 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3777 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3779 } elsif ($mimetype =~ m!^image/!) {
3780 print qq!<img type
="$mimetype"!;
3782 print qq! alt
="$file_name" title
="$file_name"!;
3785 href(action=>"blob_plain
", hash=>$hash,
3786 hash_base=>$hash_base, file_name=>$file_name) .
3790 or print "Reading blob failed.\n";
3796 my $have_snapshot = gitweb_have_snapshot
();
3798 if (!defined $hash_base) {
3799 $hash_base = "HEAD";
3801 if (!defined $hash) {
3802 if (defined $file_name) {
3803 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3809 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3810 or die_error
(undef, "Open git-ls-tree failed");
3811 my @entries = map { chomp; $_ } <$fd>;
3812 close $fd or die_error
(undef, "Reading tree failed");
3815 my $refs = git_get_references
();
3816 my $ref = format_ref_marker
($refs, $hash_base);
3819 my ($have_blame) = gitweb_check_feature
('blame');
3820 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3822 if (defined $file_name) {
3824 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3825 hash
=>$hash, file_name
=>$file_name)},
3827 $cgi->a({-href
=> href
(action
=>"tree",
3828 hash_base
=>"HEAD", file_name
=>$file_name)},
3831 if ($have_snapshot) {
3832 # FIXME: Should be available when we have no hash base as well.
3834 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3837 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3838 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3841 print "<div class=\"page_nav\">\n";
3842 print "<br/><br/></div>\n";
3843 print "<div class=\"title\">$hash</div>\n";
3845 if (defined $file_name) {
3846 $basedir = $file_name;
3847 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3851 git_print_page_path
($file_name, 'tree', $hash_base);
3852 print "<div class=\"page_body\">\n";
3853 print "<table cellspacing=\"0\">\n";
3855 # '..' (top directory) link if possible
3856 if (defined $hash_base &&
3857 defined $file_name && $file_name =~ m![^/]+$!) {
3859 print "<tr class=\"dark\">\n";
3861 print "<tr class=\"light\">\n";
3865 my $up = $file_name;
3866 $up =~ s!/?[^/]+$!!;
3867 undef $up unless $up;
3868 # based on git_print_tree_entry
3869 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3870 print '<td class="list">';
3871 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3875 print "<td class=\"link\"></td>\n";
3879 foreach my $line (@entries) {
3880 my %t = parse_ls_tree_line
($line, -z
=> 1);
3883 print "<tr class=\"dark\">\n";
3885 print "<tr class=\"light\">\n";
3889 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3893 print "</table>\n" .
3899 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3900 my $have_snapshot = (defined $ctype && defined $suffix);
3901 if (!$have_snapshot) {
3902 die_error
('403 Permission denied', "Permission denied");
3905 if (!defined $hash) {
3906 $hash = git_get_head_hash
($project);
3909 my $filename = decode_utf8
(basename
($project)) . "-$hash.tar.$suffix";
3912 -type
=> "application/$ctype",
3913 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3914 -status
=> '200 OK');
3916 my $git = git_cmd_str
();
3917 my $name = $project;
3918 $name =~ s/\047/\047\\\047\047/g;
3920 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3921 or die_error
(undef, "Execute git-tar-tree failed");
3922 binmode STDOUT
, ':raw';
3924 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3930 my $head = git_get_head_hash
($project);
3931 if (!defined $hash) {
3934 if (!defined $page) {
3937 my $refs = git_get_references
();
3939 my @commitlist = parse_commits
($hash, 101, (100 * $page));
3941 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
3944 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3947 my %co = parse_commit
($hash);
3949 git_print_header_div
('summary', $project);
3950 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3952 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
3953 for (my $i = 0; $i <= $to; $i++) {
3954 my %co = %{$commitlist[$i]};
3956 my $commit = $co{'id'};
3957 my $ref = format_ref_marker
($refs, $commit);
3958 my %ad = parse_date
($co{'author_epoch'});
3959 git_print_header_div
('commit',
3960 "<span class=\"age\">$co{'age_string'}</span>" .
3961 esc_html
($co{'title'}) . $ref,
3963 print "<div class=\"title_text\">\n" .
3964 "<div class=\"log_link\">\n" .
3965 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3967 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3969 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3972 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3975 print "<div class=\"log_body\">\n";
3976 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3979 if ($#commitlist >= 100) {
3980 print "<div class=\"page_nav\">\n";
3981 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
3982 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3989 $hash ||= $hash_base || "HEAD";
3990 my %co = parse_commit
($hash);
3992 die_error
(undef, "Unknown commit object");
3994 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3995 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3997 my $parent = $co{'parent'};
3998 my $parents = $co{'parents'}; # listref
4000 # we need to prepare $formats_nav before any parameter munging
4002 if (!defined $parent) {
4004 $formats_nav .= '(initial)';
4005 } elsif (@
$parents == 1) {
4006 # single parent commit
4009 $cgi->a({-href
=> href
(action
=>"commit",
4011 esc_html
(substr($parent, 0, 7))) .
4018 $cgi->a({-href
=> href
(action
=>"commit",
4020 esc_html
(substr($_, 0, 7)));
4025 if (!defined $parent) {
4029 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4031 (@
$parents <= 1 ?
$parent : '-c'),
4033 or die_error
(undef, "Open git-diff-tree failed");
4034 @difftree = map { chomp; $_ } <$fd>;
4035 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4037 # non-textual hash id's can be cached
4039 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4042 my $refs = git_get_references
();
4043 my $ref = format_ref_marker
($refs, $co{'id'});
4045 my $have_snapshot = gitweb_have_snapshot
();
4047 git_header_html
(undef, $expires);
4048 git_print_page_nav
('commit', '',
4049 $hash, $co{'tree'}, $hash,
4052 if (defined $co{'parent'}) {
4053 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4055 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4057 print "<div class=\"title_text\">\n" .
4058 "<table cellspacing=\"0\">\n";
4059 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4061 "<td></td><td> $ad{'rfc2822'}";
4062 if ($ad{'hour_local'} < 6) {
4063 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4064 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4066 printf(" (%02d:%02d %s)",
4067 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4071 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4072 print "<tr><td></td><td> $cd{'rfc2822'}" .
4073 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4075 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4078 "<td class=\"sha1\">" .
4079 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4080 class => "list"}, $co{'tree'}) .
4082 "<td class=\"link\">" .
4083 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4085 if ($have_snapshot) {
4087 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4092 foreach my $par (@
$parents) {
4095 "<td class=\"sha1\">" .
4096 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4097 class => "list"}, $par) .
4099 "<td class=\"link\">" .
4100 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4102 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4109 print "<div class=\"page_body\">\n";
4110 git_print_log
($co{'comment'});
4113 git_difftree_body
(\
@difftree, $hash, @
$parents);
4119 # object is defined by:
4120 # - hash or hash_base alone
4121 # - hash_base and file_name
4124 # - hash or hash_base alone
4125 if ($hash || ($hash_base && !defined $file_name)) {
4126 my $object_id = $hash || $hash_base;
4128 my $git_command = git_cmd_str
();
4129 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4130 or die_error
('404 Not Found', "Object does not exist");
4134 or die_error
('404 Not Found', "Object does not exist");
4136 # - hash_base and file_name
4137 } elsif ($hash_base && defined $file_name) {
4138 $file_name =~ s
,/+$,,;
4140 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4141 or die_error
('404 Not Found', "Base object does not exist");
4143 # here errors should not hapen
4144 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4145 or die_error
(undef, "Open git-ls-tree failed");
4149 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4150 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4151 die_error
('404 Not Found', "File or directory for given base does not exist");
4156 die_error
('404 Not Found', "Not enough information to find object");
4159 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4160 hash
=>$hash, hash_base
=>$hash_base,
4161 file_name
=>$file_name),
4162 -status
=> '302 Found');
4166 my $format = shift || 'html';
4173 # preparing $fd and %diffinfo for git_patchset_body
4175 if (defined $hash_base && defined $hash_parent_base) {
4176 if (defined $file_name) {
4178 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4179 $hash_parent_base, $hash_base,
4180 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4181 or die_error
(undef, "Open git-diff-tree failed");
4182 @difftree = map { chomp; $_ } <$fd>;
4184 or die_error
(undef, "Reading git-diff-tree failed");
4186 or die_error
('404 Not Found', "Blob diff not found");
4188 } elsif (defined $hash &&
4189 $hash =~ /[0-9a-fA-F]{40}/) {
4190 # try to find filename from $hash
4192 # read filtered raw output
4193 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4194 $hash_parent_base, $hash_base, "--"
4195 or die_error
(undef, "Open git-diff-tree failed");
4197 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4199 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4200 map { chomp; $_ } <$fd>;
4202 or die_error
(undef, "Reading git-diff-tree failed");
4204 or die_error
('404 Not Found', "Blob diff not found");
4207 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4210 if (@difftree > 1) {
4211 die_error
('404 Not Found', "Ambiguous blob diff specification");
4214 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4215 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4216 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4218 $hash_parent ||= $diffinfo{'from_id'};
4219 $hash ||= $diffinfo{'to_id'};
4221 # non-textual hash id's can be cached
4222 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4223 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4228 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4229 '-p', ($format eq 'html' ?
"--full-index" : ()),
4230 $hash_parent_base, $hash_base,
4231 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4232 or die_error
(undef, "Open git-diff-tree failed");
4235 # old/legacy style URI
4236 if (!%diffinfo && # if new style URI failed
4237 defined $hash && defined $hash_parent) {
4238 # fake git-diff-tree raw output
4239 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4240 $diffinfo{'from_id'} = $hash_parent;
4241 $diffinfo{'to_id'} = $hash;
4242 if (defined $file_name) {
4243 if (defined $file_parent) {
4244 $diffinfo{'status'} = '2';
4245 $diffinfo{'from_file'} = $file_parent;
4246 $diffinfo{'to_file'} = $file_name;
4247 } else { # assume not renamed
4248 $diffinfo{'status'} = '1';
4249 $diffinfo{'from_file'} = $file_name;
4250 $diffinfo{'to_file'} = $file_name;
4252 } else { # no filename given
4253 $diffinfo{'status'} = '2';
4254 $diffinfo{'from_file'} = $hash_parent;
4255 $diffinfo{'to_file'} = $hash;
4258 # non-textual hash id's can be cached
4259 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4260 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4265 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4266 '-p', ($format eq 'html' ?
"--full-index" : ()),
4267 $hash_parent, $hash, "--"
4268 or die_error
(undef, "Open git-diff failed");
4270 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4275 if ($format eq 'html') {
4277 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4278 hash
=>$hash, hash_parent
=>$hash_parent,
4279 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4280 file_name
=>$file_name, file_parent
=>$file_parent)},
4282 git_header_html
(undef, $expires);
4283 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4284 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4285 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4287 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4288 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4290 if (defined $file_name) {
4291 git_print_page_path
($file_name, "blob", $hash_base);
4293 print "<div class=\"page_path\"></div>\n";
4296 } elsif ($format eq 'plain') {
4298 -type
=> 'text/plain',
4299 -charset
=> 'utf-8',
4300 -expires
=> $expires,
4301 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4303 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4306 die_error
(undef, "Unknown blobdiff format");
4310 if ($format eq 'html') {
4311 print "<div class=\"page_body\">\n";
4313 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4316 print "</div>\n"; # class="page_body"
4320 while (my $line = <$fd>) {
4321 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4322 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4326 last if $line =~ m!^\+\+\+!;
4334 sub git_blobdiff_plain
{
4335 git_blobdiff
('plain');
4338 sub git_commitdiff
{
4339 my $format = shift || 'html';
4340 $hash ||= $hash_base || "HEAD";
4341 my %co = parse_commit
($hash);
4343 die_error
(undef, "Unknown commit object");
4346 # we need to prepare $formats_nav before any parameter munging
4348 if ($format eq 'html') {
4350 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4351 hash
=>$hash, hash_parent
=>$hash_parent)},
4354 if (defined $hash_parent) {
4355 # commitdiff with two commits given
4356 my $hash_parent_short = $hash_parent;
4357 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4358 $hash_parent_short = substr($hash_parent, 0, 7);
4362 $cgi->a({-href
=> href
(action
=>"commitdiff",
4363 hash
=>$hash_parent)},
4364 esc_html
($hash_parent_short)) .
4366 } elsif (!$co{'parent'}) {
4368 $formats_nav .= ' (initial)';
4369 } elsif (scalar @
{$co{'parents'}} == 1) {
4370 # single parent commit
4373 $cgi->a({-href
=> href
(action
=>"commitdiff",
4374 hash
=>$co{'parent'})},
4375 esc_html
(substr($co{'parent'}, 0, 7))) .
4382 $cgi->a({-href
=> href
(action
=>"commitdiff",
4384 esc_html
(substr($_, 0, 7)));
4385 } @
{$co{'parents'}} ) .
4390 my $hash_parent_param = $hash_parent;
4391 if (!defined $hash_parent) {
4392 $hash_parent_param =
4393 @
{$co{'parents'}} > 1 ?
'-c' : $co{'parent'} || '--root';
4399 if ($format eq 'html') {
4400 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4401 "--no-commit-id", "--patch-with-raw", "--full-index",
4402 $hash_parent_param, $hash, "--"
4403 or die_error
(undef, "Open git-diff-tree failed");
4405 while (my $line = <$fd>) {
4407 # empty line ends raw part of diff-tree output
4409 push @difftree, scalar parse_difftree_raw_line
($line);
4412 } elsif ($format eq 'plain') {
4413 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4414 '-p', $hash_parent_param, $hash, "--"
4415 or die_error
(undef, "Open git-diff-tree failed");
4418 die_error
(undef, "Unknown commitdiff format");
4421 # non-textual hash id's can be cached
4423 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4427 # write commit message
4428 if ($format eq 'html') {
4429 my $refs = git_get_references
();
4430 my $ref = format_ref_marker
($refs, $co{'id'});
4432 git_header_html
(undef, $expires);
4433 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4434 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4435 git_print_authorship
(\
%co);
4436 print "<div class=\"page_body\">\n";
4437 if (@
{$co{'comment'}} > 1) {
4438 print "<div class=\"log\">\n";
4439 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4440 print "</div>\n"; # class="log"
4443 } elsif ($format eq 'plain') {
4444 my $refs = git_get_references
("tags");
4445 my $tagname = git_get_rev_name_tags
($hash);
4446 my $filename = basename
($project) . "-$hash.patch";
4449 -type
=> 'text/plain',
4450 -charset
=> 'utf-8',
4451 -expires
=> $expires,
4452 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4453 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4456 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4457 Subject: $co{'title'}
4459 print "X-Git-Tag: $tagname\n" if $tagname;
4460 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4462 foreach my $line (@
{$co{'comment'}}) {
4469 if ($format eq 'html') {
4470 git_difftree_body
(\
@difftree, $hash, $hash_parent || @
{$co{'parents'}});
4473 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @
{$co{'parents'}});
4475 print "</div>\n"; # class="page_body"
4478 } elsif ($format eq 'plain') {
4482 or print "Reading git-diff-tree failed\n";
4486 sub git_commitdiff_plain
{
4487 git_commitdiff
('plain');
4491 if (!defined $hash_base) {
4492 $hash_base = git_get_head_hash
($project);
4494 if (!defined $page) {
4498 my %co = parse_commit
($hash_base);
4500 die_error
(undef, "Unknown commit object");
4503 my $refs = git_get_references
();
4504 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4506 if (!defined $hash && defined $file_name) {
4507 $hash = git_get_hash_by_path
($hash_base, $file_name);
4509 if (defined $hash) {
4510 $ftype = git_get_type
($hash);
4513 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4515 my $paging_nav = '';
4518 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4519 file_name
=>$file_name)},
4521 $paging_nav .= " ⋅ " .
4522 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4523 file_name
=>$file_name, page
=>$page-1),
4524 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4526 $paging_nav .= "first";
4527 $paging_nav .= " ⋅ prev";
4529 if ($#commitlist >= 100) {
4530 $paging_nav .= " ⋅ " .
4531 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4532 file_name
=>$file_name, page
=>$page+1),
4533 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4535 $paging_nav .= " ⋅ next";
4538 if ($#commitlist >= 100) {
4540 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4541 file_name
=>$file_name, page
=>$page+1),
4542 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4546 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4547 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4548 git_print_page_path
($file_name, $ftype, $hash_base);
4550 git_history_body
(\
@commitlist, 0, 99,
4551 $refs, $hash_base, $ftype, $next_link);
4557 my ($have_search) = gitweb_check_feature
('search');
4558 if (!$have_search) {
4559 die_error
('403 Permission denied', "Permission denied");
4561 if (!defined $searchtext) {
4562 die_error
(undef, "Text field empty");
4564 if (!defined $hash) {
4565 $hash = git_get_head_hash
($project);
4567 my %co = parse_commit
($hash);
4569 die_error
(undef, "Unknown commit object");
4571 if (!defined $page) {
4575 $searchtype ||= 'commit';
4576 if ($searchtype eq 'pickaxe') {
4577 # pickaxe may take all resources of your box and run for several minutes
4578 # with every query - so decide by yourself how public you make this feature
4579 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4580 if (!$have_pickaxe) {
4581 die_error
('403 Permission denied', "Permission denied");
4587 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4589 if ($searchtype eq 'commit') {
4590 $greptype = "--grep=";
4591 } elsif ($searchtype eq 'author') {
4592 $greptype = "--author=";
4593 } elsif ($searchtype eq 'committer') {
4594 $greptype = "--committer=";
4596 $greptype .= $searchtext;
4597 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4599 my $paging_nav = '';
4602 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4603 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4605 $paging_nav .= " ⋅ " .
4606 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4607 searchtext
=>$searchtext, searchtype
=>$searchtype,
4609 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4611 $paging_nav .= "first";
4612 $paging_nav .= " ⋅ prev";
4614 if ($#commitlist >= 100) {
4615 $paging_nav .= " ⋅ " .
4616 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4617 searchtext
=>$searchtext, searchtype
=>$searchtype,
4619 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4621 $paging_nav .= " ⋅ next";
4624 if ($#commitlist >= 100) {
4626 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4627 searchtext
=>$searchtext, searchtype
=>$searchtype,
4629 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4632 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4633 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4634 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4637 if ($searchtype eq 'pickaxe') {
4638 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4639 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4641 print "<table cellspacing=\"0\">\n";
4644 my $git_command = git_cmd_str
();
4645 open my $fd, "-|", "$git_command rev-list $hash | " .
4646 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4649 while (my $line = <$fd>) {
4650 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4653 $set{'from_id'} = $3;
4655 $set{'id'} = $set{'to_id'};
4656 if ($set{'id'} =~ m/0{40}/) {
4657 $set{'id'} = $set{'from_id'};
4659 if ($set{'id'} =~ m/0{40}/) {
4663 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4666 print "<tr class=\"dark\">\n";
4668 print "<tr class=\"light\">\n";
4671 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4672 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4674 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4675 -class => "list subject"},
4676 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4677 while (my $setref = shift @files) {
4679 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4680 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4682 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4686 "<td class=\"link\">" .
4687 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4689 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4693 %co = parse_commit
($1);
4703 sub git_search_help
{
4705 git_print_page_nav
('','', $hash,$hash,$hash);
4708 <dt><b>commit</b></dt>
4709 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4710 <dt><b>author</b></dt>
4711 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4712 <dt><b>committer</b></dt>
4713 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4715 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4716 if ($have_pickaxe) {
4718 <dt><b>pickaxe</b></dt>
4719 <dd>All commits that caused the string to appear or disappear from any file (changes that
4720 added, removed or "modified" the string) will be listed. This search can take a while and
4721 takes a lot of strain on the server, so please use it wisely.</dd>
4729 my $head = git_get_head_hash
($project);
4730 if (!defined $hash) {
4733 if (!defined $page) {
4736 my $refs = git_get_references
();
4738 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4740 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4742 if ($#commitlist >= 100) {
4744 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4745 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4749 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4750 git_print_header_div
('summary', $project);
4752 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4757 ## ......................................................................
4758 ## feeds (RSS, Atom; OPML)
4761 my $format = shift || 'atom';
4762 my ($have_blame) = gitweb_check_feature
('blame');
4764 # Atom: http://www.atomenabled.org/developers/syndication/
4765 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4766 if ($format ne 'rss' && $format ne 'atom') {
4767 die_error
(undef, "Unknown web feed format");
4770 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4771 my $head = $hash || 'HEAD';
4772 my @commitlist = parse_commits
($head, 150);
4776 my $content_type = "application/$format+xml";
4777 if (defined $cgi->http('HTTP_ACCEPT') &&
4778 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4779 # browser (feed reader) prefers text/xml
4780 $content_type = 'text/xml';
4782 if (defined($commitlist[0])) {
4783 %latest_commit = %{$commitlist[0]};
4784 %latest_date = parse_date
($latest_commit{'author_epoch'});
4786 -type
=> $content_type,
4787 -charset
=> 'utf-8',
4788 -last_modified
=> $latest_date{'rfc2822'});
4791 -type
=> $content_type,
4792 -charset
=> 'utf-8');
4795 # Optimization: skip generating the body if client asks only
4796 # for Last-Modified date.
4797 return if ($cgi->request_method() eq 'HEAD');
4800 my $title = "$site_name - $project/$action";
4801 my $feed_type = 'log';
4802 if (defined $hash) {
4803 $title .= " - '$hash'";
4804 $feed_type = 'branch log';
4805 if (defined $file_name) {
4806 $title .= " :: $file_name";
4807 $feed_type = 'history';
4809 } elsif (defined $file_name) {
4810 $title .= " - $file_name";
4811 $feed_type = 'history';
4813 $title .= " $feed_type";
4814 my $descr = git_get_project_description
($project);
4815 if (defined $descr) {
4816 $descr = esc_html
($descr);
4818 $descr = "$project " .
4819 ($format eq 'rss' ?
'RSS' : 'Atom') .
4822 my $owner = git_get_project_owner
($project);
4823 $owner = esc_html
($owner);
4827 if (defined $file_name) {
4828 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4829 } elsif (defined $hash) {
4830 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4832 $alt_url = href
(-full
=>1, action
=>"summary");
4834 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
4835 if ($format eq 'rss') {
4837 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4840 print "<title>$title</title>\n" .
4841 "<link>$alt_url</link>\n" .
4842 "<description>$descr</description>\n" .
4843 "<language>en</language>\n";
4844 } elsif ($format eq 'atom') {
4846 <feed xmlns="http://www.w3.org/2005/Atom">
4848 print "<title>$title</title>\n" .
4849 "<subtitle>$descr</subtitle>\n" .
4850 '<link rel="alternate" type="text/html" href="' .
4851 $alt_url . '" />' . "\n" .
4852 '<link rel="self" type="' . $content_type . '" href="' .
4853 $cgi->self_url() . '" />' . "\n" .
4854 "<id>" . href
(-full
=>1) . "</id>\n" .
4855 # use project owner for feed author
4856 "<author><name>$owner</name></author>\n";
4857 if (defined $favicon) {
4858 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4860 if (defined $logo_url) {
4861 # not twice as wide as tall: 72 x 27 pixels
4862 print "<logo>" . esc_url
($logo) . "</logo>\n";
4864 if (! %latest_date) {
4865 # dummy date to keep the feed valid until commits trickle in:
4866 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4868 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4873 for (my $i = 0; $i <= $#commitlist; $i++) {
4874 my %co = %{$commitlist[$i]};
4875 my $commit = $co{'id'};
4876 # we read 150, we always show 30 and the ones more recent than 48 hours
4877 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4880 my %cd = parse_date
($co{'author_epoch'});
4882 # get list of changed files
4883 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4884 $co{'parent'}, $co{'id'}, "--", (defined $file_name ?
$file_name : ())
4886 my @difftree = map { chomp; $_ } <$fd>;
4890 # print element (entry, item)
4891 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4892 if ($format eq 'rss') {
4894 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4895 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4896 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4897 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4898 "<link>$co_url</link>\n" .
4899 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4900 "<content:encoded>" .
4902 } elsif ($format eq 'atom') {
4904 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4905 "<updated>$cd{'iso-8601'}</updated>\n" .
4907 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4908 if ($co{'author_email'}) {
4909 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4911 print "</author>\n" .
4912 # use committer for contributor
4914 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4915 if ($co{'committer_email'}) {
4916 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4918 print "</contributor>\n" .
4919 "<published>$cd{'iso-8601'}</published>\n" .
4920 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4921 "<id>$co_url</id>\n" .
4922 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4923 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4925 my $comment = $co{'comment'};
4927 foreach my $line (@
$comment) {
4928 $line = esc_html
($line);
4931 print "</pre><ul>\n";
4932 foreach my $difftree_line (@difftree) {
4933 my %difftree = parse_difftree_raw_line
($difftree_line);
4934 next if !$difftree{'from_id'};
4936 my $file = $difftree{'file'} || $difftree{'to_file'};
4940 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4941 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4942 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4943 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4944 -title
=> "diff"}, 'D');
4946 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4947 file_name
=>$file, hash_base
=>$commit),
4948 -title
=> "blame"}, 'B');
4950 # if this is not a feed of a file history
4951 if (!defined $file_name || $file_name ne $file) {
4952 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4953 file_name
=>$file, hash
=>$commit),
4954 -title
=> "history"}, 'H');
4956 $file = esc_path
($file);
4960 if ($format eq 'rss') {
4961 print "</ul>]]>\n" .
4962 "</content:encoded>\n" .
4964 } elsif ($format eq 'atom') {
4965 print "</ul>\n</div>\n" .
4972 if ($format eq 'rss') {
4973 print "</channel>\n</rss>\n";
4974 } elsif ($format eq 'atom') {
4988 my @list = git_get_projects_list
();
4990 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4992 <?xml version="1.0" encoding="utf-8"?>
4993 <opml version="1.0">
4995 <title>$site_name OPML Export</title>
4998 <outline text="git RSS feeds">
5001 foreach my $pr (@list) {
5003 my $head = git_get_head_hash
($proj{'path'});
5004 if (!defined $head) {
5007 $git_dir = "$projectroot/$proj{'path'}";
5008 my %co = parse_commit
($head);
5013 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5014 my $rss = "$my_url?p=$proj{'path'};a=rss";
5015 my $html = "$my_url?p=$proj{'path'};a=summary";
5016 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";