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;
61 # URI of GIT logo (72x27 size)
62 our $logo = "++GITWEB_LOGO++";
63 # URI of GIT favicon, assumed to be image/png type
64 our $favicon = "++GITWEB_FAVICON++";
66 # URI and label (title) of GIT logo link
67 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
68 #our $logo_label = "git documentation";
69 our $logo_url = "http://git.or.cz/";
70 our $logo_label = "git homepage";
72 # source of projects list
73 our $projects_list = "++GITWEB_LIST++";
75 # default order of projects list
76 # valid values are none, project, descr, owner, and age
77 our $default_projects_order = "project";
79 # show repository only if this file exists
80 # (only effective if this variable evaluates to true)
81 our $export_ok = "++GITWEB_EXPORT_OK++";
83 # only allow viewing of repositories also shown on the overview page
84 our $strict_export = "++GITWEB_STRICT_EXPORT++";
86 # list of git base URLs used for URL to where fetch project from,
87 # i.e. full URL is "$git_base_url/$project"
88 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
90 # default blob_plain mimetype and default charset for text/plain blob
91 our $default_blob_plain_mimetype = 'text/plain';
92 our $default_text_plain_charset = undef;
94 # file to use for guessing MIME types before trying /etc/mime.types
95 # (relative to the current git repository)
96 our $mimetypes_file = undef;
98 # You define site-wide feature defaults here; override them with
99 # $GITWEB_CONFIG as necessary.
102 # 'sub' => feature-sub (subroutine),
103 # 'override' => allow-override (boolean),
104 # 'default' => [ default options...] (array reference)}
106 # if feature is overridable (it means that allow-override has true value),
107 # then feature-sub will be called with default options as parameters;
108 # return value of feature-sub indicates if to enable specified feature
110 # if there is no 'sub' key (no feature-sub), then feature cannot be
113 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
115 # Enable the 'blame' blob view, showing the last commit that modified
116 # each line in the file. This can be very CPU-intensive.
118 # To enable system wide have in $GITWEB_CONFIG
119 # $feature{'blame'}{'default'} = [1];
120 # To have project specific config enable override in $GITWEB_CONFIG
121 # $feature{'blame'}{'override'} = 1;
122 # and in project config gitweb.blame = 0|1;
124 'sub' => \
&feature_blame
,
128 # Enable the 'snapshot' link, providing a compressed tarball of any
129 # tree. This can potentially generate high traffic if you have large
132 # To disable system wide have in $GITWEB_CONFIG
133 # $feature{'snapshot'}{'default'} = [undef];
134 # To have project specific config enable override in $GITWEB_CONFIG
135 # $feature{'snapshot'}{'override'} = 1;
136 # and in project config gitweb.snapshot = none|gzip|bzip2;
138 'sub' => \
&feature_snapshot
,
140 # => [content-encoding, suffix, program]
141 'default' => ['x-gzip', 'gz', 'gzip']},
143 # Enable text search, which will list the commits which match author,
144 # committer or commit text to a given string. Enabled by default.
145 # Project specific override is not supported.
150 # Enable grep search, which will list the files in currently selected
151 # tree containing the given string. Enabled by default. This can be
152 # potentially CPU-intensive, of course.
154 # To enable system wide have in $GITWEB_CONFIG
155 # $feature{'grep'}{'default'} = [1];
156 # To have project specific config enable override in $GITWEB_CONFIG
157 # $feature{'grep'}{'override'} = 1;
158 # and in project config gitweb.grep = 0|1;
163 # Enable the pickaxe search, which will list the commits that modified
164 # a given string in a file. This can be practical and quite faster
165 # alternative to 'blame', but still potentially CPU-intensive.
167 # To enable system wide have in $GITWEB_CONFIG
168 # $feature{'pickaxe'}{'default'} = [1];
169 # To have project specific config enable override in $GITWEB_CONFIG
170 # $feature{'pickaxe'}{'override'} = 1;
171 # and in project config gitweb.pickaxe = 0|1;
173 'sub' => \
&feature_pickaxe
,
177 # Make gitweb use an alternative format of the URLs which can be
178 # more readable and natural-looking: project name is embedded
179 # directly in the path and the query string contains other
180 # auxiliary information. All gitweb installations recognize
181 # URL in either format; this configures in which formats gitweb
184 # To enable system wide have in $GITWEB_CONFIG
185 # $feature{'pathinfo'}{'default'} = [1];
186 # Project specific override is not supported.
188 # Note that you will need to change the default location of CSS,
189 # favicon, logo and possibly other files to an absolute URL. Also,
190 # if gitweb.cgi serves as your indexfile, you will need to force
191 # $my_uri to contain the script name in your $GITWEB_CONFIG.
196 # Make gitweb consider projects in project root subdirectories
197 # to be forks of existing projects. Given project $projname.git,
198 # projects matching $projname/*.git will not be shown in the main
199 # projects list, instead a '+' mark will be added to $projname
200 # there and a 'forks' view will be enabled for the project, listing
201 # all the forks. If project list is taken from a file, forks have
202 # to be listed after the main project.
204 # To enable system wide have in $GITWEB_CONFIG
205 # $feature{'forks'}{'default'} = [1];
206 # Project specific override is not supported.
212 sub gitweb_check_feature
{
214 return unless exists $feature{$name};
215 my ($sub, $override, @defaults) = (
216 $feature{$name}{'sub'},
217 $feature{$name}{'override'},
218 @{$feature{$name}{'default'}});
219 if (!$override) { return @defaults; }
221 warn "feature $name is not overrideable";
224 return $sub->(@defaults);
228 my ($val) = git_get_project_config
('blame', '--bool');
230 if ($val eq 'true') {
232 } elsif ($val eq 'false') {
239 sub feature_snapshot
{
240 my ($ctype, $suffix, $command) = @_;
242 my ($val) = git_get_project_config
('snapshot');
244 if ($val eq 'gzip') {
245 return ('x-gzip', 'gz', 'gzip');
246 } elsif ($val eq 'bzip2') {
247 return ('x-bzip2', 'bz2', 'bzip2');
248 } elsif ($val eq 'none') {
252 return ($ctype, $suffix, $command);
255 sub gitweb_have_snapshot
{
256 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
257 my $have_snapshot = (defined $ctype && defined $suffix);
259 return $have_snapshot;
263 my ($val) = git_get_project_config
('grep', '--bool');
265 if ($val eq 'true') {
267 } elsif ($val eq 'false') {
274 sub feature_pickaxe
{
275 my ($val) = git_get_project_config
('pickaxe', '--bool');
277 if ($val eq 'true') {
279 } elsif ($val eq 'false') {
286 # checking HEAD file with -e is fragile if the repository was
287 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
289 sub check_head_link
{
291 my $headfile = "$dir/HEAD";
292 return ((-e
$headfile) ||
293 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
296 sub check_export_ok
{
298 return (check_head_link
($dir) &&
299 (!$export_ok || -e
"$dir/$export_ok"));
302 # rename detection options for git-diff and git-diff-tree
303 # - default is '-M', with the cost proportional to
304 # (number of removed files) * (number of new files).
305 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
306 # (number of changed files + number of removed files) * (number of new files)
307 # - even more costly is '-C', '--find-copies-harder' with cost
308 # (number of files in the original tree) * (number of new files)
309 # - one might want to include '-B' option, e.g. '-B', '-M'
310 our @diff_opts = ('-M'); # taken from git_commit
312 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
313 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
315 # version of the core git binary
316 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
318 $projects_list ||= $projectroot;
320 # ======================================================================
321 # input validation and dispatch
322 our $action = $cgi->param('a');
323 if (defined $action) {
324 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
325 die_error
(undef, "Invalid action parameter");
329 # parameters which are pathnames
330 our $project = $cgi->param('p');
331 if (defined $project) {
332 if (!validate_pathname
($project) ||
333 !(-d
"$projectroot/$project") ||
334 !check_head_link
("$projectroot/$project") ||
335 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
336 ($strict_export && !project_in_list
($project))) {
338 die_error
(undef, "No such project");
342 our $file_name = $cgi->param('f');
343 if (defined $file_name) {
344 if (!validate_pathname
($file_name)) {
345 die_error
(undef, "Invalid file parameter");
349 our $file_parent = $cgi->param('fp');
350 if (defined $file_parent) {
351 if (!validate_pathname
($file_parent)) {
352 die_error
(undef, "Invalid file parent parameter");
356 # parameters which are refnames
357 our $hash = $cgi->param('h');
359 if (!validate_refname
($hash)) {
360 die_error
(undef, "Invalid hash parameter");
364 our $hash_parent = $cgi->param('hp');
365 if (defined $hash_parent) {
366 if (!validate_refname
($hash_parent)) {
367 die_error
(undef, "Invalid hash parent parameter");
371 our $hash_base = $cgi->param('hb');
372 if (defined $hash_base) {
373 if (!validate_refname
($hash_base)) {
374 die_error
(undef, "Invalid hash base parameter");
378 our $hash_parent_base = $cgi->param('hpb');
379 if (defined $hash_parent_base) {
380 if (!validate_refname
($hash_parent_base)) {
381 die_error
(undef, "Invalid hash parent base parameter");
386 our $page = $cgi->param('pg');
388 if ($page =~ m/[^0-9]/) {
389 die_error
(undef, "Invalid page parameter");
393 our $searchtype = $cgi->param('st');
394 if (defined $searchtype) {
395 if ($searchtype =~ m/[^a-z]/) {
396 die_error
(undef, "Invalid searchtype parameter");
400 our $searchtext = $cgi->param('s');
402 if (defined $searchtext) {
403 if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
404 die_error
(undef, "Invalid search parameter");
406 if (length($searchtext) < 2) {
407 die_error
(undef, "At least two characters are required for search parameter");
409 $search_regexp = quotemeta $searchtext;
412 our $searchtype = $cgi->param('st');
413 if (defined $searchtype) {
414 if ($searchtype =~ m/[^a-z]/) {
415 die_error
(undef, "Invalid searchtype parameter");
419 # now read PATH_INFO and use it as alternative to parameters
420 sub evaluate_path_info
{
421 return if defined $project;
422 my $path_info = $ENV{"PATH_INFO"};
423 return if !$path_info;
424 $path_info =~ s
,^/+,,;
425 return if !$path_info;
426 # find which part of PATH_INFO is project
427 $project = $path_info;
429 while ($project && !check_head_link
("$projectroot/$project")) {
430 $project =~ s
,/*[^/]*$,,;
433 $project = validate_pathname
($project);
435 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
436 ($strict_export && !project_in_list
($project))) {
440 # do not change any parameters if an action is given using the query string
442 $path_info =~ s
,^$project/*,,;
443 my ($refname, $pathname) = split(/:/, $path_info, 2);
444 if (defined $pathname) {
445 # we got "project.git/branch:filename" or "project.git/branch:dir/"
446 # we could use git_get_type(branch:pathname), but it needs $git_dir
447 $pathname =~ s
,^/+,,;
448 if (!$pathname || substr($pathname, -1) eq "/") {
452 $action ||= "blob_plain";
454 $hash_base ||= validate_refname
($refname);
455 $file_name ||= validate_pathname
($pathname);
456 } elsif (defined $refname) {
457 # we got "project.git/branch"
458 $action ||= "shortlog";
459 $hash ||= validate_refname
($refname);
462 evaluate_path_info
();
464 # path to the current git repository
466 $git_dir = "$projectroot/$project" if $project;
470 "blame" => \
&git_blame2
,
471 "blobdiff" => \
&git_blobdiff
,
472 "blobdiff_plain" => \
&git_blobdiff_plain
,
473 "blob" => \
&git_blob
,
474 "blob_plain" => \
&git_blob_plain
,
475 "commitdiff" => \
&git_commitdiff
,
476 "commitdiff_plain" => \
&git_commitdiff_plain
,
477 "commit" => \
&git_commit
,
478 "forks" => \
&git_forks
,
479 "heads" => \
&git_heads
,
480 "history" => \
&git_history
,
483 "atom" => \
&git_atom
,
484 "search" => \
&git_search
,
485 "search_help" => \
&git_search_help
,
486 "shortlog" => \
&git_shortlog
,
487 "summary" => \
&git_summary
,
489 "tags" => \
&git_tags
,
490 "tree" => \
&git_tree
,
491 "snapshot" => \
&git_snapshot
,
492 "object" => \
&git_object
,
493 # those below don't need $project
494 "opml" => \
&git_opml
,
495 "project_list" => \
&git_project_list
,
496 "project_index" => \
&git_project_index
,
499 if (!defined $action) {
501 $action = git_get_type
($hash);
502 } elsif (defined $hash_base && defined $file_name) {
503 $action = git_get_type
("$hash_base:$file_name");
504 } elsif (defined $project) {
507 $action = 'project_list';
510 if (!defined($actions{$action})) {
511 die_error
(undef, "Unknown action");
513 if ($action !~ m/^(opml|project_list|project_index)$/ &&
515 die_error
(undef, "Project needed");
517 $actions{$action}->();
520 ## ======================================================================
525 # default is to use -absolute url() i.e. $my_uri
526 my $href = $params{-full
} ? $my_url : $my_uri;
528 # XXX: Warning: If you touch this, check the search form for updating,
539 hash_parent_base
=> "hpb",
545 my %mapping = @mapping;
547 $params{'project'} = $project unless exists $params{'project'};
549 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
551 # use PATH_INFO for project name
552 $href .= "/$params{'project'}" if defined $params{'project'};
553 delete $params{'project'};
555 # Summary just uses the project path URL
556 if (defined $params{'action'} && $params{'action'} eq 'summary') {
557 delete $params{'action'};
561 # now encode the parameters explicitly
563 for (my $i = 0; $i < @mapping; $i += 2) {
564 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
565 if (defined $params{$name}) {
566 push @result, $symbol . "=" . esc_param
($params{$name});
569 $href .= "?" . join(';', @result) if scalar @result;
575 ## ======================================================================
576 ## validation, quoting/unquoting and escaping
578 sub validate_pathname
{
579 my $input = shift || return undef;
581 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
582 # at the beginning, at the end, and between slashes.
583 # also this catches doubled slashes
584 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
588 if ($input =~ m!\0!) {
594 sub validate_refname
{
595 my $input = shift || return undef;
597 # textual hashes are O.K.
598 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
601 # it must be correct pathname
602 $input = validate_pathname
($input)
604 # restrictions on ref name according to git-check-ref-format
605 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
611 # quote unsafe chars, but keep the slash, even when it's not
612 # correct, but quoted slashes look too horrible in bookmarks
615 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
621 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
624 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
630 # replace invalid utf8 character with SUBSTITUTION sequence
635 $str = decode_utf8
($str);
636 $str = $cgi->escapeHTML($str);
637 if ($opts{'-nbsp'}) {
638 $str =~ s/ / /g;
640 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
644 # quote control characters and escape filename to HTML
649 $str = decode_utf8
($str);
650 $str = $cgi->escapeHTML($str);
651 if ($opts{'-nbsp'}) {
652 $str =~ s/ / /g;
654 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
658 # Make control characters "printable", using character escape codes (CEC)
661 my %es = ( # character escape codes, aka escape sequences
662 "\t" => '\t', # tab (HT)
663 "\n" => '\n', # line feed (LF)
664 "\r" => '\r', # carrige return (CR)
665 "\f" => '\f', # form feed (FF)
666 "\b" => '\b', # backspace (BS)
667 "\a" => '\a', # alarm (bell) (BEL)
668 "\e" => '\e', # escape (ESC)
669 "\013" => '\v', # vertical tab (VT)
670 "\000" => '\0', # nul character (NUL)
672 my $chr = ( (exists $es{$cntrl})
674 : sprintf('\%03o', ord($cntrl)) );
675 return "<span class=\"cntrl\">$chr</span>";
678 # Alternatively use unicode control pictures codepoints,
679 # Unicode "printable representation" (PR)
682 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
683 return "<span class=\"cntrl\">$chr</span>";
686 # git may return quoted and escaped filenames
692 my %es = ( # character escape codes, aka escape sequences
693 't' => "\t", # tab (HT, TAB)
694 'n' => "\n", # newline (NL)
695 'r' => "\r", # return (CR)
696 'f' => "\f", # form feed (FF)
697 'b' => "\b", # backspace (BS)
698 'a' => "\a", # alarm (bell) (BEL)
699 'e' => "\e", # escape (ESC)
700 'v' => "\013", # vertical tab (VT)
703 if ($seq =~ m/^[0-7]{1,3}$/) {
704 # octal char sequence
705 return chr(oct($seq));
706 } elsif (exists $es{$seq}) {
707 # C escape sequence, aka character escape code
710 # quoted ordinary character
714 if ($str =~ m/^"(.*)"$/) {
717 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
722 # escape tabs (convert tabs to spaces)
726 while ((my $pos = index($line, "\t")) != -1) {
727 if (my $count = (8 - ($pos % 8))) {
728 my $spaces = ' ' x
$count;
729 $line =~ s/\t/$spaces/;
736 sub project_in_list
{
738 my @list = git_get_projects_list
();
739 return @list && scalar(grep { $_->{'path'} eq $project } @list);
742 ## ----------------------------------------------------------------------
743 ## HTML aware string manipulation
748 my $add_len = shift || 10;
750 # allow only $len chars, but don't cut a word if it would fit in $add_len
751 # if it doesn't fit, cut it if it's still longer than the dots we would add
752 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
755 if (length($tail) > 4) {
757 $body =~ s/&[^;]*$//; # remove chopped character entities
762 ## ----------------------------------------------------------------------
763 ## functions returning short strings
765 # CSS class for given age value (in seconds)
771 } elsif ($age < 60*60*2) {
773 } elsif ($age < 60*60*24*2) {
780 # convert age in seconds to "nn units ago" string
785 if ($age > 60*60*24*365*2) {
786 $age_str = (int $age/60/60/24/365);
787 $age_str .= " years ago";
788 } elsif ($age > 60*60*24*(365/12)*2) {
789 $age_str = int $age/60/60/24/(365/12);
790 $age_str .= " months ago";
791 } elsif ($age > 60*60*24*7*2) {
792 $age_str = int $age/60/60/24/7;
793 $age_str .= " weeks ago";
794 } elsif ($age > 60*60*24*2) {
795 $age_str = int $age/60/60/24;
796 $age_str .= " days ago";
797 } elsif ($age > 60*60*2) {
798 $age_str = int $age/60/60;
799 $age_str .= " hours ago";
800 } elsif ($age > 60*2) {
801 $age_str = int $age/60;
802 $age_str .= " min ago";
805 $age_str .= " sec ago";
807 $age_str .= " right now";
812 # convert file mode in octal to symbolic file mode string
814 my $mode = oct shift;
816 if (S_ISDIR
($mode & S_IFMT
)) {
818 } elsif (S_ISLNK
($mode)) {
820 } elsif (S_ISREG
($mode)) {
821 # git cares only about the executable bit
822 if ($mode & S_IXUSR
) {
832 # convert file mode in octal to file type string
836 if ($mode !~ m/^[0-7]+$/) {
842 if (S_ISDIR
($mode & S_IFMT
)) {
844 } elsif (S_ISLNK
($mode)) {
846 } elsif (S_ISREG
($mode)) {
853 # convert file mode in octal to file type description string
857 if ($mode !~ m/^[0-7]+$/) {
863 if (S_ISDIR
($mode & S_IFMT
)) {
865 } elsif (S_ISLNK
($mode)) {
867 } elsif (S_ISREG
($mode)) {
868 if ($mode & S_IXUSR
) {
879 ## ----------------------------------------------------------------------
880 ## functions returning short HTML fragments, or transforming HTML fragments
881 ## which don't belong to other sections
883 # format line of commit message.
884 sub format_log_line_html
{
887 $line = esc_html
($line, -nbsp
=>1);
888 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
891 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
892 -class => "text"}, $hash_text);
893 $line =~ s/$hash_text/$link/;
898 # format marker of refs pointing to given object
899 sub format_ref_marker
{
900 my ($refs, $id) = @_;
903 if (defined $refs->{$id}) {
904 foreach my $ref (@{$refs->{$id}}) {
905 my ($type, $name) = qw();
906 # e.g. tags/v2.6.11 or heads/next
907 if ($ref =~ m!^(.*?)s?/(.*)$!) {
915 $markers .= " <span class=\"$type\" title=\"$ref\">" .
916 esc_html
($name) . "</span>";
921 return ' <span class="refs">'. $markers . '</span>';
927 # format, perhaps shortened and with markers, title line
928 sub format_subject_html
{
929 my ($long, $short, $href, $extra) = @_;
930 $extra = '' unless defined($extra);
932 if (length($short) < length($long)) {
933 return $cgi->a({-href
=> $href, -class => "list subject",
934 -title
=> decode_utf8
($long)},
935 esc_html
($short) . $extra);
937 return $cgi->a({-href
=> $href, -class => "list subject"},
938 esc_html
($long) . $extra);
942 # format patch (diff) line (rather not to be used for diff headers)
943 sub format_diff_line
{
945 my ($from, $to) = @_;
950 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
952 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
953 if ($line =~ m/^\@{3}/) {
954 $diff_class = " chunk_header";
955 } elsif ($line =~ m/^\\/) {
956 $diff_class = " incomplete";
957 } elsif ($prefix =~ tr/+/+/) {
958 $diff_class = " add";
959 } elsif ($prefix =~ tr/-/-/) {
960 $diff_class = " rem";
963 # assume ordinary diff
964 my $char = substr($line, 0, 1);
966 $diff_class = " add";
967 } elsif ($char eq '-') {
968 $diff_class = " rem";
969 } elsif ($char eq '@') {
970 $diff_class = " chunk_header";
971 } elsif ($char eq "\\") {
972 $diff_class = " incomplete";
975 $line = untabify
($line);
976 if ($from && $to && $line =~ m/^\@{2} /) {
977 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
978 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
980 $from_lines = 0 unless defined $from_lines;
981 $to_lines = 0 unless defined $to_lines;
983 if ($from->{'href'}) {
984 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
985 -class=>"list"}, $from_text);
988 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
989 -class=>"list"}, $to_text);
991 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
992 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
993 return "<div class=\"diff$diff_class\">$line</div>\n";
994 } elsif ($from && $to && $line =~ m/^\@{3}/) {
995 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
996 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
998 @from_text = split(' ', $ranges);
999 for (my $i = 0; $i < @from_text; ++$i) {
1000 ($from_start[$i], $from_nlines[$i]) =
1001 (split(',', substr($from_text[$i], 1)), 0);
1004 $to_text = pop @from_text;
1005 $to_start = pop @from_start;
1006 $to_nlines = pop @from_nlines;
1008 $line = "<span class=\"chunk_info\">$prefix ";
1009 for (my $i = 0; $i < @from_text; ++$i) {
1010 if ($from->{'href'}[$i]) {
1011 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1012 -class=>"list"}, $from_text[$i]);
1014 $line .= $from_text[$i];
1018 if ($to->{'href'}) {
1019 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1020 -class=>"list"}, $to_text);
1024 $line .= " $prefix</span>" .
1025 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1026 return "<div class=\"diff$diff_class\">$line</div>\n";
1028 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1031 ## ----------------------------------------------------------------------
1032 ## git utility subroutines, invoking git commands
1034 # returns path to the core git executable and the --git-dir parameter as list
1036 return $GIT, '--git-dir='.$git_dir;
1039 # returns path to the core git executable and the --git-dir parameter as string
1041 return join(' ', git_cmd
());
1044 # get HEAD ref of given project as hash
1045 sub git_get_head_hash
{
1046 my $project = shift;
1047 my $o_git_dir = $git_dir;
1049 $git_dir = "$projectroot/$project";
1050 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1053 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1057 if (defined $o_git_dir) {
1058 $git_dir = $o_git_dir;
1063 # get type of given object
1067 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1069 close $fd or return;
1074 sub git_get_project_config
{
1075 my ($key, $type) = @_;
1077 return unless ($key);
1078 $key =~ s/^gitweb\.//;
1079 return if ($key =~ m/\W/);
1081 my @x = (git_cmd
(), 'config');
1082 if (defined $type) { push @x, $type; }
1084 push @x, "gitweb.$key";
1090 # get hash of given path at given ref
1091 sub git_get_hash_by_path
{
1093 my $path = shift || return undef;
1098 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1099 or die_error
(undef, "Open git-ls-tree failed");
1101 close $fd or return undef;
1103 if (!defined $line) {
1104 # there is no tree or hash given by $path at $base
1108 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1109 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1110 if (defined $type && $type ne $2) {
1111 # type doesn't match
1117 # get path of entry with given hash at given tree-ish (ref)
1118 # used to get 'from' filename for combined diff (merge commit) for renames
1119 sub git_get_path_by_hash
{
1120 my $base = shift || return;
1121 my $hash = shift || return;
1125 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1127 while (my $line = <$fd>) {
1130 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1131 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1132 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1141 ## ......................................................................
1142 ## git utility functions, directly accessing git repository
1144 sub git_get_project_description
{
1147 open my $fd, "$projectroot/$path/description" or return undef;
1150 if (defined $descr) {
1156 sub git_get_project_url_list
{
1159 open my $fd, "$projectroot/$path/cloneurl" or return;
1160 my @git_project_url_list = map { chomp; $_ } <$fd>;
1163 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1166 sub git_get_projects_list
{
1171 $filter =~ s/\.git$//;
1173 my ($check_forks) = gitweb_check_feature
('forks');
1175 if (-d
$projects_list) {
1176 # search in directory
1177 my $dir = $projects_list . ($filter ? "/$filter" : '');
1178 # remove the trailing "/"
1180 my $pfxlen = length("$dir");
1183 follow_fast
=> 1, # follow symbolic links
1184 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1186 # skip project-list toplevel, if we get it.
1187 return if (m!^[/.]$!);
1188 # only directories can be git repositories
1189 return unless (-d
$_);
1191 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1192 # we check related file in $projectroot
1193 if ($check_forks and $subdir =~ m
#/.#) {
1194 $File::Find
::prune
= 1;
1195 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1196 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1197 $File::Find
::prune
= 1;
1202 } elsif (-f
$projects_list) {
1203 # read from file(url-encoded):
1204 # 'git%2Fgit.git Linus+Torvalds'
1205 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1206 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1208 open my ($fd), $projects_list or return;
1210 while (my $line = <$fd>) {
1212 my ($path, $owner) = split ' ', $line;
1213 $path = unescape
($path);
1214 $owner = unescape
($owner);
1215 if (!defined $path) {
1218 if ($filter ne '') {
1219 # looking for forks;
1220 my $pfx = substr($path, 0, length($filter));
1221 if ($pfx ne $filter) {
1224 my $sfx = substr($path, length($filter));
1225 if ($sfx !~ /^\/.*\
.git
$/) {
1228 } elsif ($check_forks) {
1230 foreach my $filter (keys %paths) {
1231 # looking for forks;
1232 my $pfx = substr($path, 0, length($filter));
1233 if ($pfx ne $filter) {
1236 my $sfx = substr($path, length($filter));
1237 if ($sfx !~ /^\/.*\
.git
$/) {
1240 # is a fork, don't include it in
1245 if (check_export_ok
("$projectroot/$path")) {
1248 owner
=> decode_utf8
($owner),
1251 (my $forks_path = $path) =~ s/\.git$//;
1252 $paths{$forks_path}++;
1260 sub git_get_project_owner
{
1261 my $project = shift;
1264 return undef unless $project;
1266 # read from file (url-encoded):
1267 # 'git%2Fgit.git Linus+Torvalds'
1268 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1269 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1270 if (-f
$projects_list) {
1271 open (my $fd , $projects_list);
1272 while (my $line = <$fd>) {
1274 my ($pr, $ow) = split ' ', $line;
1275 $pr = unescape
($pr);
1276 $ow = unescape
($ow);
1277 if ($pr eq $project) {
1278 $owner = decode_utf8
($ow);
1284 if (!defined $owner) {
1285 $owner = get_file_owner
("$projectroot/$project");
1291 sub git_get_last_activity
{
1295 $git_dir = "$projectroot/$path";
1296 open($fd, "-|", git_cmd
(), 'for-each-ref',
1297 '--format=%(committer)',
1298 '--sort=-committerdate',
1300 'refs/heads') or return;
1301 my $most_recent = <$fd>;
1302 close $fd or return;
1303 if (defined $most_recent &&
1304 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1306 my $age = time - $timestamp;
1307 return ($age, age_string
($age));
1311 sub git_get_references
{
1312 my $type = shift || "";
1314 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1315 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1316 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1317 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1320 while (my $line = <$fd>) {
1322 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1323 if (defined $refs{$1}) {
1324 push @{$refs{$1}}, $2;
1330 close $fd or return;
1334 sub git_get_rev_name_tags
{
1335 my $hash = shift || return undef;
1337 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1339 my $name_rev = <$fd>;
1342 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1345 # catches also '$hash undefined' output
1350 ## ----------------------------------------------------------------------
1351 ## parse to hash functions
1355 my $tz = shift || "-0000";
1358 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1359 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1360 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1361 $date{'hour'} = $hour;
1362 $date{'minute'} = $min;
1363 $date{'mday'} = $mday;
1364 $date{'day'} = $days[$wday];
1365 $date{'month'} = $months[$mon];
1366 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1367 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1368 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1369 $mday, $months[$mon], $hour ,$min;
1370 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1371 1900+$year, $mon, $mday, $hour ,$min, $sec;
1373 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1374 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1375 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1376 $date{'hour_local'} = $hour;
1377 $date{'minute_local'} = $min;
1378 $date{'tz_local'} = $tz;
1379 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1380 1900+$year, $mon+1, $mday,
1381 $hour, $min, $sec, $tz);
1390 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1391 $tag{'id'} = $tag_id;
1392 while (my $line = <$fd>) {
1394 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1395 $tag{'object'} = $1;
1396 } elsif ($line =~ m/^type (.+)$/) {
1398 } elsif ($line =~ m/^tag (.+)$/) {
1400 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1401 $tag{'author'} = $1;
1404 } elsif ($line =~ m/--BEGIN/) {
1405 push @comment, $line;
1407 } elsif ($line eq "") {
1411 push @comment, <$fd>;
1412 $tag{'comment'} = \
@comment;
1413 close $fd or return;
1414 if (!defined $tag{'name'}) {
1420 sub parse_commit_text
{
1421 my ($commit_text, $withparents) = @_;
1422 my @commit_lines = split '\n', $commit_text;
1425 pop @commit_lines; # Remove '\0'
1427 if (! @commit_lines) {
1431 my $header = shift @commit_lines;
1432 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1435 ($co{'id'}, my @parents) = split ' ', $header;
1436 while (my $line = shift @commit_lines) {
1437 last if $line eq "\n";
1438 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1440 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1442 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1444 $co{'author_epoch'} = $2;
1445 $co{'author_tz'} = $3;
1446 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1447 $co{'author_name'} = $1;
1448 $co{'author_email'} = $2;
1450 $co{'author_name'} = $co{'author'};
1452 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1453 $co{'committer'} = $1;
1454 $co{'committer_epoch'} = $2;
1455 $co{'committer_tz'} = $3;
1456 $co{'committer_name'} = $co{'committer'};
1457 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1458 $co{'committer_name'} = $1;
1459 $co{'committer_email'} = $2;
1461 $co{'committer_name'} = $co{'committer'};
1465 if (!defined $co{'tree'}) {
1468 $co{'parents'} = \
@parents;
1469 $co{'parent'} = $parents[0];
1471 foreach my $title (@commit_lines) {
1474 $co{'title'} = chop_str
($title, 80, 5);
1475 # remove leading stuff of merges to make the interesting part visible
1476 if (length($title) > 50) {
1477 $title =~ s/^Automatic //;
1478 $title =~ s/^merge (of|with) /Merge ... /i;
1479 if (length($title) > 50) {
1480 $title =~ s/(http|rsync):\/\///;
1482 if (length($title) > 50) {
1483 $title =~ s/(master|www|rsync)\.//;
1485 if (length($title) > 50) {
1486 $title =~ s/kernel.org:?//;
1488 if (length($title) > 50) {
1489 $title =~ s/\/pub\/scm//;
1492 $co{'title_short'} = chop_str
($title, 50, 5);
1496 if ($co{'title'} eq "") {
1497 $co{'title'} = $co{'title_short'} = '(no commit message)';
1499 # remove added spaces
1500 foreach my $line (@commit_lines) {
1503 $co{'comment'} = \
@commit_lines;
1505 my $age = time - $co{'committer_epoch'};
1507 $co{'age_string'} = age_string
($age);
1508 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1509 if ($age > 60*60*24*7*2) {
1510 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1511 $co{'age_string_age'} = $co{'age_string'};
1513 $co{'age_string_date'} = $co{'age_string'};
1514 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1520 my ($commit_id) = @_;
1525 open my $fd, "-|", git_cmd
(), "rev-list",
1531 or die_error
(undef, "Open git-rev-list failed");
1532 %co = parse_commit_text
(<$fd>, 1);
1539 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1547 open my $fd, "-|", git_cmd
(), "rev-list",
1549 ($arg ? ($arg) : ()),
1550 ("--max-count=" . $maxcount),
1551 ("--skip=" . $skip),
1554 ($filename ? ($filename) : ())
1555 or die_error
(undef, "Open git-rev-list failed");
1556 while (my $line = <$fd>) {
1557 my %co = parse_commit_text
($line);
1562 return wantarray ? @cos : \
@cos;
1565 # parse ref from ref_file, given by ref_id, with given type
1567 my $ref_file = shift;
1569 my $type = shift || git_get_type
($ref_id);
1572 $ref_item{'type'} = $type;
1573 $ref_item{'id'} = $ref_id;
1574 $ref_item{'epoch'} = 0;
1575 $ref_item{'age'} = "unknown";
1576 if ($type eq "tag") {
1577 my %tag = parse_tag
($ref_id);
1578 $ref_item{'comment'} = $tag{'comment'};
1579 if ($tag{'type'} eq "commit") {
1580 my %co = parse_commit
($tag{'object'});
1581 $ref_item{'epoch'} = $co{'committer_epoch'};
1582 $ref_item{'age'} = $co{'age_string'};
1583 } elsif (defined($tag{'epoch'})) {
1584 my $age = time - $tag{'epoch'};
1585 $ref_item{'epoch'} = $tag{'epoch'};
1586 $ref_item{'age'} = age_string
($age);
1588 $ref_item{'reftype'} = $tag{'type'};
1589 $ref_item{'name'} = $tag{'name'};
1590 $ref_item{'refid'} = $tag{'object'};
1591 } elsif ($type eq "commit"){
1592 my %co = parse_commit
($ref_id);
1593 $ref_item{'reftype'} = "commit";
1594 $ref_item{'name'} = $ref_file;
1595 $ref_item{'title'} = $co{'title'};
1596 $ref_item{'refid'} = $ref_id;
1597 $ref_item{'epoch'} = $co{'committer_epoch'};
1598 $ref_item{'age'} = $co{'age_string'};
1600 $ref_item{'reftype'} = $type;
1601 $ref_item{'name'} = $ref_file;
1602 $ref_item{'refid'} = $ref_id;
1608 # parse line of git-diff-tree "raw" output
1609 sub parse_difftree_raw_line
{
1613 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1614 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1615 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1616 $res{'from_mode'} = $1;
1617 $res{'to_mode'} = $2;
1618 $res{'from_id'} = $3;
1620 $res{'status'} = $5;
1621 $res{'similarity'} = $6;
1622 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1623 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1625 $res{'file'} = unquote
($7);
1628 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1629 # combined diff (for merge commit)
1630 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1631 $res{'nparents'} = length($1);
1632 $res{'from_mode'} = [ split(' ', $2) ];
1633 $res{'to_mode'} = pop @{$res{'from_mode'}};
1634 $res{'from_id'} = [ split(' ', $3) ];
1635 $res{'to_id'} = pop @{$res{'from_id'}};
1636 $res{'status'} = [ split('', $4) ];
1637 $res{'to_file'} = unquote
($5);
1639 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1640 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1641 $res{'commit'} = $1;
1644 return wantarray ? %res : \
%res;
1647 # parse line of git-ls-tree output
1648 sub parse_ls_tree_line
($;%) {
1653 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1654 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1662 $res{'name'} = unquote
($4);
1665 return wantarray ? %res : \
%res;
1668 ## ......................................................................
1669 ## parse to array of hashes functions
1671 sub git_get_heads_list
{
1675 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1676 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1677 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1680 while (my $line = <$fd>) {
1684 my ($refinfo, $committerinfo) = split(/\0/, $line);
1685 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1686 my ($committer, $epoch, $tz) =
1687 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1688 $name =~ s!^refs/heads/!!;
1690 $ref_item{'name'} = $name;
1691 $ref_item{'id'} = $hash;
1692 $ref_item{'title'} = $title || '(no commit message)';
1693 $ref_item{'epoch'} = $epoch;
1695 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1697 $ref_item{'age'} = "unknown";
1700 push @headslist, \
%ref_item;
1704 return wantarray ? @headslist : \
@headslist;
1707 sub git_get_tags_list
{
1711 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1712 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1713 '--format=%(objectname) %(objecttype) %(refname) '.
1714 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1717 while (my $line = <$fd>) {
1721 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1722 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1723 my ($creator, $epoch, $tz) =
1724 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1725 $name =~ s!^refs/tags/!!;
1727 $ref_item{'type'} = $type;
1728 $ref_item{'id'} = $id;
1729 $ref_item{'name'} = $name;
1730 if ($type eq "tag") {
1731 $ref_item{'subject'} = $title;
1732 $ref_item{'reftype'} = $reftype;
1733 $ref_item{'refid'} = $refid;
1735 $ref_item{'reftype'} = $type;
1736 $ref_item{'refid'} = $id;
1739 if ($type eq "tag" || $type eq "commit") {
1740 $ref_item{'epoch'} = $epoch;
1742 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1744 $ref_item{'age'} = "unknown";
1748 push @tagslist, \
%ref_item;
1752 return wantarray ? @tagslist : \
@tagslist;
1755 ## ----------------------------------------------------------------------
1756 ## filesystem-related functions
1758 sub get_file_owner
{
1761 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1762 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1763 if (!defined $gcos) {
1767 $owner =~ s/[,;].*$//;
1768 return decode_utf8
($owner);
1771 ## ......................................................................
1772 ## mimetype related functions
1774 sub mimetype_guess_file
{
1775 my $filename = shift;
1776 my $mimemap = shift;
1777 -r
$mimemap or return undef;
1780 open(MIME
, $mimemap) or return undef;
1782 next if m/^#/; # skip comments
1783 my ($mime, $exts) = split(/\t+/);
1784 if (defined $exts) {
1785 my @exts = split(/\s+/, $exts);
1786 foreach my $ext (@exts) {
1787 $mimemap{$ext} = $mime;
1793 $filename =~ /\.([^.]*)$/;
1794 return $mimemap{$1};
1797 sub mimetype_guess
{
1798 my $filename = shift;
1800 $filename =~ /\./ or return undef;
1802 if ($mimetypes_file) {
1803 my $file = $mimetypes_file;
1804 if ($file !~ m!^/!) { # if it is relative path
1805 # it is relative to project
1806 $file = "$projectroot/$project/$file";
1808 $mime = mimetype_guess_file
($filename, $file);
1810 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1816 my $filename = shift;
1819 my $mime = mimetype_guess
($filename);
1820 $mime and return $mime;
1824 return $default_blob_plain_mimetype unless $fd;
1827 return 'text/plain' .
1828 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1829 } elsif (! $filename) {
1830 return 'application/octet-stream';
1831 } elsif ($filename =~ m/\.png$/i) {
1833 } elsif ($filename =~ m/\.gif$/i) {
1835 } elsif ($filename =~ m/\.jpe?g$/i) {
1836 return 'image/jpeg';
1838 return 'application/octet-stream';
1842 ## ======================================================================
1843 ## functions printing HTML: header, footer, error page
1845 sub git_header_html
{
1846 my $status = shift || "200 OK";
1847 my $expires = shift;
1849 my $title = "$site_name";
1850 if (defined $project) {
1851 $title .= " - " . decode_utf8
($project);
1852 if (defined $action) {
1853 $title .= "/$action";
1854 if (defined $file_name) {
1855 $title .= " - " . esc_path
($file_name);
1856 if ($action eq "tree" && $file_name !~ m
|/$|) {
1863 # require explicit support from the UA if we are to send the page as
1864 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1865 # we have to do this because MSIE sometimes globs '*/*', pretending to
1866 # support xhtml+xml but choking when it gets what it asked for.
1867 if (defined $cgi->http('HTTP_ACCEPT') &&
1868 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1869 $cgi->Accept('application/xhtml+xml') != 0) {
1870 $content_type = 'application/xhtml+xml';
1872 $content_type = 'text/html';
1874 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1875 -status
=> $status, -expires
=> $expires);
1876 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
1878 <?xml version="1.0" encoding="utf-8"?>
1879 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1880 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1881 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1882 <!-- git core binaries version $git_version -->
1884 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1885 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1886 <meta name="robots" content="index, nofollow"/>
1887 <title>$title</title>
1889 # print out each stylesheet that exist
1890 if (defined $stylesheet) {
1891 #provides backwards capability for those people who define style sheet in a config file
1892 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1894 foreach my $stylesheet (@stylesheets) {
1895 next unless $stylesheet;
1896 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1899 if (defined $project) {
1900 printf('<link rel="alternate" title="%s log RSS feed" '.
1901 'href="%s" type="application/rss+xml" />'."\n",
1902 esc_param
($project), href
(action
=>"rss"));
1903 printf('<link rel="alternate" title="%s log Atom feed" '.
1904 'href="%s" type="application/atom+xml" />'."\n",
1905 esc_param
($project), href
(action
=>"atom"));
1907 printf('<link rel="alternate" title="%s projects list" '.
1908 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1909 $site_name, href
(project
=>undef, action
=>"project_index"));
1910 printf('<link rel="alternate" title="%s projects feeds" '.
1911 'href="%s" type="text/x-opml"/>'."\n",
1912 $site_name, href
(project
=>undef, action
=>"opml"));
1914 if (defined $favicon) {
1915 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1921 if (-f
$site_header) {
1922 open (my $fd, $site_header);
1927 print "<div class=\"page_header\">\n" .
1928 $cgi->a({-href
=> esc_url
($logo_url),
1929 -title
=> $logo_label},
1930 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1931 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1932 if (defined $project) {
1933 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1934 if (defined $action) {
1941 my ($have_search) = gitweb_check_feature
('search');
1942 if ((defined $project) && ($have_search)) {
1943 if (!defined $searchtext) {
1947 if (defined $hash_base) {
1948 $search_hash = $hash_base;
1949 } elsif (defined $hash) {
1950 $search_hash = $hash;
1952 $search_hash = "HEAD";
1954 $cgi->param("a", "search");
1955 $cgi->param("h", $search_hash);
1956 $cgi->param("p", $project);
1957 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1958 "<div class=\"search\">\n" .
1959 $cgi->hidden(-name
=> "p") . "\n" .
1960 $cgi->hidden(-name
=> "a") . "\n" .
1961 $cgi->hidden(-name
=> "h") . "\n" .
1962 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1963 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
1964 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1966 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1968 $cgi->end_form() . "\n";
1972 sub git_footer_html
{
1973 print "<div class=\"page_footer\">\n";
1974 if (defined $project) {
1975 my $descr = git_get_project_description
($project);
1976 if (defined $descr) {
1977 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1979 print $cgi->a({-href
=> href
(action
=>"rss"),
1980 -class => "rss_logo"}, "RSS") . " ";
1981 print $cgi->a({-href
=> href
(action
=>"atom"),
1982 -class => "rss_logo"}, "Atom") . "\n";
1984 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1985 -class => "rss_logo"}, "OPML") . " ";
1986 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1987 -class => "rss_logo"}, "TXT") . "\n";
1991 if (-f
$site_footer) {
1992 open (my $fd, $site_footer);
2002 my $status = shift || "403 Forbidden";
2003 my $error = shift || "Malformed query, file missing or permission denied";
2005 git_header_html
($status);
2007 <div class="page_body">
2017 ## ----------------------------------------------------------------------
2018 ## functions printing or outputting HTML: navigation
2020 sub git_print_page_nav
{
2021 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2022 $extra = '' if !defined $extra; # pager or formats
2024 my @navs = qw(summary shortlog log commit commitdiff tree);
2026 @navs = grep { $_ ne $suppress } @navs;
2029 my %arg = map { $_ => {action
=>$_} } @navs;
2030 if (defined $head) {
2031 for (qw(commit commitdiff)) {
2032 $arg{$_}{'hash'} = $head;
2034 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2035 for (qw(shortlog log)) {
2036 $arg{$_}{'hash'} = $head;
2040 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2041 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2043 print "<div class=\"page_nav\">\n" .
2045 map { $_ eq $current ?
2046 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2048 print "<br/>\n$extra<br/>\n" .
2052 sub format_paging_nav
{
2053 my ($action, $hash, $head, $page, $nrevs) = @_;
2057 if ($hash ne $head || $page) {
2058 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2060 $paging_nav .= "HEAD";
2064 $paging_nav .= " ⋅ " .
2065 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2066 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2068 $paging_nav .= " ⋅ prev";
2071 if ($nrevs >= (100 * ($page+1)-1)) {
2072 $paging_nav .= " ⋅ " .
2073 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2074 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2076 $paging_nav .= " ⋅ next";
2082 ## ......................................................................
2083 ## functions printing or outputting HTML: div
2085 sub git_print_header_div
{
2086 my ($action, $title, $hash, $hash_base) = @_;
2089 $args{'action'} = $action;
2090 $args{'hash'} = $hash if $hash;
2091 $args{'hash_base'} = $hash_base if $hash_base;
2093 print "<div class=\"header\">\n" .
2094 $cgi->a({-href
=> href
(%args), -class => "title"},
2095 $title ? $title : $action) .
2099 #sub git_print_authorship (\%) {
2100 sub git_print_authorship
{
2103 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2104 print "<div class=\"author_date\">" .
2105 esc_html
($co->{'author_name'}) .
2107 if ($ad{'hour_local'} < 6) {
2108 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2109 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2111 printf(" (%02d:%02d %s)",
2112 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2117 sub git_print_page_path
{
2123 print "<div class=\"page_path\">";
2124 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2125 -title
=> 'tree root'}, decode_utf8
("[$project]"));
2127 if (defined $name) {
2128 my @dirname = split '/', $name;
2129 my $basename = pop @dirname;
2132 foreach my $dir (@dirname) {
2133 $fullname .= ($fullname ? '/' : '') . $dir;
2134 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2136 -title
=> $fullname}, esc_path
($dir));
2139 if (defined $type && $type eq 'blob') {
2140 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2142 -title
=> $name}, esc_path
($basename));
2143 } elsif (defined $type && $type eq 'tree') {
2144 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2146 -title
=> $name}, esc_path
($basename));
2149 print esc_path
($basename);
2152 print "<br/></div>\n";
2155 # sub git_print_log (\@;%) {
2156 sub git_print_log
($;%) {
2160 if ($opts{'-remove_title'}) {
2161 # remove title, i.e. first line of log
2164 # remove leading empty lines
2165 while (defined $log->[0] && $log->[0] eq "") {
2172 foreach my $line (@$log) {
2173 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2176 if (! $opts{'-remove_signoff'}) {
2177 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2180 # remove signoff lines
2187 # print only one empty line
2188 # do not print empty line after signoff
2190 next if ($empty || $signoff);
2196 print format_log_line_html
($line) . "<br/>\n";
2199 if ($opts{'-final_empty_line'}) {
2200 # end with single empty line
2201 print "<br/>\n" unless $empty;
2205 # return link target (what link points to)
2206 sub git_get_link_target
{
2211 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2215 $link_target = <$fd>;
2220 return $link_target;
2223 # given link target, and the directory (basedir) the link is in,
2224 # return target of link relative to top directory (top tree);
2225 # return undef if it is not possible (including absolute links).
2226 sub normalize_link_target
{
2227 my ($link_target, $basedir, $hash_base) = @_;
2229 # we can normalize symlink target only if $hash_base is provided
2230 return unless $hash_base;
2232 # absolute symlinks (beginning with '/') cannot be normalized
2233 return if (substr($link_target, 0, 1) eq '/');
2235 # normalize link target to path from top (root) tree (dir)
2238 $path = $basedir . '/' . $link_target;
2240 # we are in top (root) tree (dir)
2241 $path = $link_target;
2244 # remove //, /./, and /../
2246 foreach my $part (split('/', $path)) {
2247 # discard '.' and ''
2248 next if (!$part || $part eq '.');
2250 if ($part eq '..') {
2254 # link leads outside repository (outside top dir)
2258 push @path_parts, $part;
2261 $path = join('/', @path_parts);
2266 # print tree entry (row of git_tree), but without encompassing <tr> element
2267 sub git_print_tree_entry
{
2268 my ($t, $basedir, $hash_base, $have_blame) = @_;
2271 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2273 # The format of a table row is: mode list link. Where mode is
2274 # the mode of the entry, list is the name of the entry, an href,
2275 # and link is the action links of the entry.
2277 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2278 if ($t->{'type'} eq "blob") {
2279 print "<td class=\"list\">" .
2280 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2281 file_name
=>"$basedir$t->{'name'}", %base_key),
2282 -class => "list"}, esc_path
($t->{'name'}));
2283 if (S_ISLNK
(oct $t->{'mode'})) {
2284 my $link_target = git_get_link_target
($t->{'hash'});
2286 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2287 if (defined $norm_target) {
2289 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2290 file_name
=>$norm_target),
2291 -title
=> $norm_target}, esc_path
($link_target));
2293 print " -> " . esc_path
($link_target);
2298 print "<td class=\"link\">";
2299 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2300 file_name
=>"$basedir$t->{'name'}", %base_key)},
2304 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2305 file_name
=>"$basedir$t->{'name'}", %base_key)},
2308 if (defined $hash_base) {
2310 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2311 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2315 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2316 file_name
=>"$basedir$t->{'name'}")},
2320 } elsif ($t->{'type'} eq "tree") {
2321 print "<td class=\"list\">";
2322 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2323 file_name
=>"$basedir$t->{'name'}", %base_key)},
2324 esc_path
($t->{'name'}));
2326 print "<td class=\"link\">";
2327 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2328 file_name
=>"$basedir$t->{'name'}", %base_key)},
2330 if (defined $hash_base) {
2332 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2333 file_name
=>"$basedir$t->{'name'}")},
2340 ## ......................................................................
2341 ## functions printing large fragments of HTML
2343 sub fill_from_file_info
{
2344 my ($diff, @parents) = @_;
2346 $diff->{'from_file'} = [ ];
2347 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2348 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2349 if ($diff->{'status'}[$i] eq 'R' ||
2350 $diff->{'status'}[$i] eq 'C') {
2351 $diff->{'from_file'}[$i] =
2352 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2359 # parameters can be strings, or references to arrays of strings
2363 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2364 for (my $i = 0; $i < @$a; ++$i) {
2365 return 0 unless ($a->[$i] eq $b->[$i]);
2368 } elsif (!ref($a) && !ref($b)) {
2376 sub git_difftree_body
{
2377 my ($difftree, $hash, @parents) = @_;
2378 my ($parent) = $parents[0];
2379 my ($have_blame) = gitweb_check_feature
('blame');
2380 print "<div class=\"list_head\">\n";
2381 if ($#{$difftree} > 10) {
2382 print(($#{$difftree} + 1) . " files changed:\n");
2386 print "<table class=\"" .
2387 (@parents > 1 ? "combined " : "") .
2391 foreach my $line (@{$difftree}) {
2393 if (ref($line) eq "HASH") {
2394 # pre-parsed (or generated by hand)
2397 $diff = parse_difftree_raw_line
($line);
2401 print "<tr class=\"dark\">\n";
2403 print "<tr class=\"light\">\n";
2407 if (exists $diff->{'nparents'}) { # combined diff
2409 fill_from_file_info
($diff, @parents)
2410 unless exists $diff->{'from_file'};
2412 if ($diff->{'to_id'} ne ('0' x
40)) {
2413 # file exists in the result (child) commit
2415 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2416 file_name
=>$diff->{'to_file'},
2418 -class => "list"}, esc_path
($diff->{'to_file'})) .
2422 esc_path
($diff->{'to_file'}) .
2426 if ($action eq 'commitdiff') {
2429 print "<td class=\"link\">" .
2430 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2435 my $has_history = 0;
2436 my $not_deleted = 0;
2437 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2438 my $hash_parent = $parents[$i];
2439 my $from_hash = $diff->{'from_id'}[$i];
2440 my $from_path = $diff->{'from_file'}[$i];
2441 my $status = $diff->{'status'}[$i];
2443 $has_history ||= ($status ne 'A');
2444 $not_deleted ||= ($status ne 'D');
2446 if ($status eq 'A') {
2447 print "<td class=\"link\" align=\"right\"> | </td>\n";
2448 } elsif ($status eq 'D') {
2449 print "<td class=\"link\">" .
2450 $cgi->a({-href
=> href
(action
=>"blob",
2453 file_name
=>$from_path)},
2457 if ($diff->{'to_id'} eq $from_hash) {
2458 print "<td class=\"link nochange\">";
2460 print "<td class=\"link\">";
2462 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2463 hash
=>$diff->{'to_id'},
2464 hash_parent
=>$from_hash,
2466 hash_parent_base
=>$hash_parent,
2467 file_name
=>$diff->{'to_file'},
2468 file_parent
=>$from_path)},
2474 print "<td class=\"link\">";
2476 print $cgi->a({-href
=> href
(action
=>"blob",
2477 hash
=>$diff->{'to_id'},
2478 file_name
=>$diff->{'to_file'},
2481 print " | " if ($has_history);
2484 print $cgi->a({-href
=> href
(action
=>"history",
2485 file_name
=>$diff->{'to_file'},
2492 next; # instead of 'else' clause, to avoid extra indent
2494 # else ordinary diff
2496 my ($to_mode_oct, $to_mode_str, $to_file_type);
2497 my ($from_mode_oct, $from_mode_str, $from_file_type);
2498 if ($diff->{'to_mode'} ne ('0' x
6)) {
2499 $to_mode_oct = oct $diff->{'to_mode'};
2500 if (S_ISREG
($to_mode_oct)) { # only for regular file
2501 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2503 $to_file_type = file_type
($diff->{'to_mode'});
2505 if ($diff->{'from_mode'} ne ('0' x
6)) {
2506 $from_mode_oct = oct $diff->{'from_mode'};
2507 if (S_ISREG
($to_mode_oct)) { # only for regular file
2508 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2510 $from_file_type = file_type
($diff->{'from_mode'});
2513 if ($diff->{'status'} eq "A") { # created
2514 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2515 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2516 $mode_chng .= "]</span>";
2518 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2519 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2520 -class => "list"}, esc_path
($diff->{'file'}));
2522 print "<td>$mode_chng</td>\n";
2523 print "<td class=\"link\">";
2524 if ($action eq 'commitdiff') {
2527 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2530 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2531 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2535 } elsif ($diff->{'status'} eq "D") { # deleted
2536 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2538 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2539 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2540 -class => "list"}, esc_path
($diff->{'file'}));
2542 print "<td>$mode_chng</td>\n";
2543 print "<td class=\"link\">";
2544 if ($action eq 'commitdiff') {
2547 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2550 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2551 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2554 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2555 file_name
=>$diff->{'file'})},
2558 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2559 file_name
=>$diff->{'file'})},
2563 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2564 my $mode_chnge = "";
2565 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2566 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2567 if ($from_file_type ne $to_file_type) {
2568 $mode_chnge .= " from $from_file_type to $to_file_type";
2570 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2571 if ($from_mode_str && $to_mode_str) {
2572 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2573 } elsif ($to_mode_str) {
2574 $mode_chnge .= " mode: $to_mode_str";
2577 $mode_chnge .= "]</span>\n";
2580 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2581 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2582 -class => "list"}, esc_path
($diff->{'file'}));
2584 print "<td>$mode_chnge</td>\n";
2585 print "<td class=\"link\">";
2586 if ($action eq 'commitdiff') {
2589 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2591 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2592 # "commit" view and modified file (not onlu mode changed)
2593 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2594 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2595 hash_base
=>$hash, hash_parent_base
=>$parent,
2596 file_name
=>$diff->{'file'})},
2600 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2601 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2604 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2605 file_name
=>$diff->{'file'})},
2608 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2609 file_name
=>$diff->{'file'})},
2613 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2614 my %status_name = ('R' => 'moved', 'C' => 'copied');
2615 my $nstatus = $status_name{$diff->{'status'}};
2617 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2618 # mode also for directories, so we cannot use $to_mode_str
2619 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2622 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2623 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2624 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2625 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2626 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2627 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2628 -class => "list"}, esc_path
($diff->{'from_file'})) .
2629 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2630 "<td class=\"link\">";
2631 if ($action eq 'commitdiff') {
2634 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2636 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2637 # "commit" view and modified file (not only pure rename or copy)
2638 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2639 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2640 hash_base
=>$hash, hash_parent_base
=>$parent,
2641 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2645 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2646 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2649 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2650 file_name
=>$diff->{'to_file'})},
2653 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2654 file_name
=>$diff->{'to_file'})},
2658 } # we should not encounter Unmerged (U) or Unknown (X) status
2664 sub git_patchset_body
{
2665 my ($fd, $difftree, $hash, @hash_parents) = @_;
2666 my ($hash_parent) = $hash_parents[0];
2669 my $patch_number = 0;
2674 print "<div class=\"patchset\">\n";
2676 # skip to first patch
2677 while ($patch_line = <$fd>) {
2680 last if ($patch_line =~ m/^diff /);
2684 while ($patch_line) {
2686 my ($from_id, $to_id);
2689 #assert($patch_line =~ m/^diff /) if DEBUG;
2690 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2692 push @diff_header, $patch_line;
2694 # extended diff header
2696 while ($patch_line = <$fd>) {
2699 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2701 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2704 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2705 $from_id = [ split(',', $1) ];
2709 push @diff_header, $patch_line;
2711 my $last_patch_line = $patch_line;
2713 # check if current patch belong to current raw line
2714 # and parse raw git-diff line if needed
2715 if (defined $diffinfo &&
2716 defined $from_id && defined $to_id &&
2717 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2718 $diffinfo->{'to_id'} eq $to_id) {
2719 # this is continuation of a split patch
2720 print "<div class=\"patch cont\">\n";
2722 # advance raw git-diff output if needed
2723 $patch_idx++ if defined $diffinfo;
2725 # read and prepare patch information
2726 if (ref($difftree->[$patch_idx]) eq "HASH") {
2727 # pre-parsed (or generated by hand)
2728 $diffinfo = $difftree->[$patch_idx];
2730 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2732 if ($diffinfo->{'nparents'}) {
2736 fill_from_file_info
($diffinfo, @hash_parents)
2737 unless exists $diffinfo->{'from_file'};
2738 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2739 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2740 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2741 $from{'href'}[$i] = href
(action
=>"blob",
2742 hash_base
=>$hash_parents[$i],
2743 hash
=>$diffinfo->{'from_id'}[$i],
2744 file_name
=>$from{'file'}[$i]);
2746 $from{'href'}[$i] = undef;
2750 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2751 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2752 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2753 hash
=>$diffinfo->{'from_id'},
2754 file_name
=>$from{'file'});
2756 delete $from{'href'};
2760 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2761 if ($diffinfo->{'to_id'} ne ('0' x
40)) { # file exists in result
2762 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2763 hash
=>$diffinfo->{'to_id'},
2764 file_name
=>$to{'file'});
2768 # this is first patch for raw difftree line with $patch_idx index
2769 # we index @$difftree array from 0, but number patches from 1
2770 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2773 # print "git diff" header
2774 $patch_line = shift @diff_header;
2775 if ($diffinfo->{'nparents'}) {
2778 $patch_line =~ s!^(diff (.*?) )"?.*$!$1!;
2780 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2781 esc_path
($to{'file'}));
2782 } else { # file was deleted
2783 $patch_line .= esc_path
($to{'file'});
2788 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2789 if ($from{'href'}) {
2790 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2791 'a/' . esc_path
($from{'file'}));
2792 } else { # file was added
2793 $patch_line .= 'a/' . esc_path
($from{'file'});
2797 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2798 'b/' . esc_path
($to{'file'}));
2799 } else { # file was deleted
2800 $patch_line .= 'b/' . esc_path
($to{'file'});
2804 print "<div class=\"diff header\">$patch_line</div>\n";
2806 # print extended diff header
2807 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2809 foreach $patch_line (@diff_header) {
2811 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2812 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2813 esc_path
($from{'file'}));
2815 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2816 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2817 esc_path
($to{'file'}));
2819 # match single <mode>
2820 if ($patch_line =~ m/\s(\d{6})$/) {
2821 $patch_line .= '<span class="info"> (' .
2822 file_type_long
($1) .
2826 if ($patch_line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2827 # can match only for combined diff
2828 $patch_line = 'index ';
2829 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2830 if ($from{'href'}[$i]) {
2831 $patch_line .= $cgi->a({-href
=>$from{'href'}[$i],
2833 substr($diffinfo->{'from_id'}[$i],0,7));
2835 $patch_line .= '0' x
7;
2838 $patch_line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2840 $patch_line .= '..';
2842 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2843 substr($diffinfo->{'to_id'},0,7));
2845 $patch_line .= '0' x
7;
2848 } elsif ($patch_line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2849 # can match only for ordinary diff
2850 my ($from_link, $to_link);
2851 if ($from{'href'}) {
2852 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2853 substr($diffinfo->{'from_id'},0,7));
2855 $from_link = '0' x
7;
2858 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2859 substr($diffinfo->{'to_id'},0,7));
2864 # my ($from_hash, $to_hash) =
2865 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2866 # my ($from_id, $to_id) =
2867 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2868 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2870 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2871 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2873 print $patch_line . "<br/>\n";
2875 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2877 # from-file/to-file diff header
2878 $patch_line = $last_patch_line;
2879 if (! $patch_line) {
2880 print "</div>\n"; # class="patch"
2883 next PATCH
if ($patch_line =~ m/^diff /);
2884 #assert($patch_line =~ m/^---/) if DEBUG;
2885 if (!$diffinfo->{'nparents'} && # not from-file line for combined diff
2886 $from{'href'} && $patch_line =~ m!^--- "?a/!) {
2887 $patch_line = '--- a/' .
2888 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2889 esc_path
($from{'file'}));
2891 print "<div class=\"diff from_file\">$patch_line</div>\n";
2893 $patch_line = <$fd>;
2896 #assert($patch_line =~ m/^+++/) if DEBUG;
2897 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2898 $patch_line = '+++ b/' .
2899 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2900 esc_path
($to{'file'}));
2902 print "<div class=\"diff to_file\">$patch_line</div>\n";
2906 while ($patch_line = <$fd>) {
2909 next PATCH
if ($patch_line =~ m/^diff /);
2911 print format_diff_line
($patch_line, \
%from, \
%to);
2915 print "</div>\n"; # class="patch"
2918 if ($patch_number == 0) {
2919 if (@hash_parents > 1) {
2920 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
2922 print "<div class=\"diff nodifferences\">No differences found</div>\n";
2926 print "</div>\n"; # class="patchset"
2929 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2931 sub git_project_list_body
{
2932 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2934 my ($check_forks) = gitweb_check_feature
('forks');
2937 foreach my $pr (@$projlist) {
2938 my (@aa) = git_get_last_activity
($pr->{'path'});
2942 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2943 if (!defined $pr->{'descr'}) {
2944 my $descr = git_get_project_description
($pr->{'path'}) || "";
2945 $pr->{'descr_long'} = decode_utf8
($descr);
2946 $pr->{'descr'} = chop_str
($descr, 25, 5);
2948 if (!defined $pr->{'owner'}) {
2949 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2952 my $pname = $pr->{'path'};
2953 if (($pname =~ s/\.git$//) &&
2954 ($pname !~ /\/$/) &&
2955 (-d
"$projectroot/$pname")) {
2956 $pr->{'forks'} = "-d $projectroot/$pname";
2962 push @projects, $pr;
2965 $order ||= $default_projects_order;
2966 $from = 0 unless defined $from;
2967 $to = $#projects if (!defined $to || $#projects < $to);
2969 print "<table class=\"project_list\">\n";
2970 unless ($no_header) {
2973 print "<th></th>\n";
2975 if ($order eq "project") {
2976 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2977 print "<th>Project</th>\n";
2980 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2981 -class => "header"}, "Project") .
2984 if ($order eq "descr") {
2985 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2986 print "<th>Description</th>\n";
2989 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2990 -class => "header"}, "Description") .
2993 if ($order eq "owner") {
2994 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2995 print "<th>Owner</th>\n";
2998 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2999 -class => "header"}, "Owner") .
3002 if ($order eq "age") {
3003 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3004 print "<th>Last Change</th>\n";
3007 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3008 -class => "header"}, "Last Change") .
3011 print "<th></th>\n" .
3015 for (my $i = $from; $i <= $to; $i++) {
3016 my $pr = $projects[$i];
3018 print "<tr class=\"dark\">\n";
3020 print "<tr class=\"light\">\n";
3025 if ($pr->{'forks'}) {
3026 print "<!-- $pr->{'forks'} -->\n";
3027 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3031 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3032 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3033 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3034 -class => "list", -title
=> $pr->{'descr_long'}},
3035 esc_html
($pr->{'descr'})) . "</td>\n" .
3036 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3037 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3038 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3039 "<td class=\"link\">" .
3040 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3041 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3042 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3043 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3044 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3048 if (defined $extra) {
3051 print "<td></td>\n";
3053 print "<td colspan=\"5\">$extra</td>\n" .
3059 sub git_shortlog_body
{
3060 # uses global variable $project
3061 my ($commitlist, $from, $to, $refs, $extra) = @_;
3063 my $have_snapshot = gitweb_have_snapshot
();
3065 $from = 0 unless defined $from;
3066 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3068 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3070 for (my $i = $from; $i <= $to; $i++) {
3071 my %co = %{$commitlist->[$i]};
3072 my $commit = $co{'id'};
3073 my $ref = format_ref_marker
($refs, $commit);
3075 print "<tr class=\"dark\">\n";
3077 print "<tr class=\"light\">\n";
3080 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3081 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3082 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3084 print format_subject_html
($co{'title'}, $co{'title_short'},
3085 href
(action
=>"commit", hash
=>$commit), $ref);
3087 "<td class=\"link\">" .
3088 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3089 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3090 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3091 if ($have_snapshot) {
3092 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3097 if (defined $extra) {
3099 "<td colspan=\"4\">$extra</td>\n" .
3105 sub git_history_body
{
3106 # Warning: assumes constant type (blob or tree) during history
3107 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3109 $from = 0 unless defined $from;
3110 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3112 print "<table class=\"history\" cellspacing=\"0\">\n";
3114 for (my $i = $from; $i <= $to; $i++) {
3115 my %co = %{$commitlist->[$i]};
3119 my $commit = $co{'id'};
3121 my $ref = format_ref_marker
($refs, $commit);
3124 print "<tr class=\"dark\">\n";
3126 print "<tr class=\"light\">\n";
3129 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3130 # shortlog uses chop_str($co{'author_name'}, 10)
3131 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3133 # originally git_history used chop_str($co{'title'}, 50)
3134 print format_subject_html
($co{'title'}, $co{'title_short'},
3135 href
(action
=>"commit", hash
=>$commit), $ref);
3137 "<td class=\"link\">" .
3138 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3139 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3141 if ($ftype eq 'blob') {
3142 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3143 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3144 if (defined $blob_current && defined $blob_parent &&
3145 $blob_current ne $blob_parent) {
3147 $cgi->a({-href
=> href
(action
=>"blobdiff",
3148 hash
=>$blob_current, hash_parent
=>$blob_parent,
3149 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3150 file_name
=>$file_name)},
3157 if (defined $extra) {
3159 "<td colspan=\"4\">$extra</td>\n" .
3166 # uses global variable $project
3167 my ($taglist, $from, $to, $extra) = @_;
3168 $from = 0 unless defined $from;
3169 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3171 print "<table class=\"tags\" cellspacing=\"0\">\n";
3173 for (my $i = $from; $i <= $to; $i++) {
3174 my $entry = $taglist->[$i];
3176 my $comment = $tag{'subject'};
3178 if (defined $comment) {
3179 $comment_short = chop_str
($comment, 30, 5);
3182 print "<tr class=\"dark\">\n";
3184 print "<tr class=\"light\">\n";
3187 if (defined $tag{'age'}) {
3188 print "<td><i>$tag{'age'}</i></td>\n";
3190 print "<td></td>\n";
3193 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3194 -class => "list name"}, esc_html
($tag{'name'})) .
3197 if (defined $comment) {
3198 print format_subject_html
($comment, $comment_short,
3199 href
(action
=>"tag", hash
=>$tag{'id'}));
3202 "<td class=\"selflink\">";
3203 if ($tag{'type'} eq "tag") {
3204 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3209 "<td class=\"link\">" . " | " .
3210 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3211 if ($tag{'reftype'} eq "commit") {
3212 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3213 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3214 } elsif ($tag{'reftype'} eq "blob") {
3215 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3220 if (defined $extra) {
3222 "<td colspan=\"5\">$extra</td>\n" .
3228 sub git_heads_body
{
3229 # uses global variable $project
3230 my ($headlist, $head, $from, $to, $extra) = @_;
3231 $from = 0 unless defined $from;
3232 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3234 print "<table class=\"heads\" cellspacing=\"0\">\n";
3236 for (my $i = $from; $i <= $to; $i++) {
3237 my $entry = $headlist->[$i];
3239 my $curr = $ref{'id'} eq $head;
3241 print "<tr class=\"dark\">\n";
3243 print "<tr class=\"light\">\n";
3246 print "<td><i>$ref{'age'}</i></td>\n" .
3247 ($curr ? "<td class=\"current_head\">" : "<td>") .
3248 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3249 -class => "list name"},esc_html
($ref{'name'})) .
3251 "<td class=\"link\">" .
3252 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3253 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3254 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3258 if (defined $extra) {
3260 "<td colspan=\"3\">$extra</td>\n" .
3266 sub git_search_grep_body
{
3267 my ($commitlist, $from, $to, $extra) = @_;
3268 $from = 0 unless defined $from;
3269 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3271 print "<table class=\"grep\" cellspacing=\"0\">\n";
3273 for (my $i = $from; $i <= $to; $i++) {
3274 my %co = %{$commitlist->[$i]};
3278 my $commit = $co{'id'};
3280 print "<tr class=\"dark\">\n";
3282 print "<tr class=\"light\">\n";
3285 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3286 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3288 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3289 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3290 my $comment = $co{'comment'};
3291 foreach my $line (@$comment) {
3292 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3293 my $lead = esc_html
($1) || "";
3294 $lead = chop_str
($lead, 30, 10);
3295 my $match = esc_html
($2) || "";
3296 my $trail = esc_html
($3) || "";
3297 $trail = chop_str
($trail, 30, 10);
3298 my $text = "$lead<span class=\"match\">$match</span>$trail";
3299 print chop_str
($text, 80, 5) . "<br/>\n";
3303 "<td class=\"link\">" .
3304 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3306 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3310 if (defined $extra) {
3312 "<td colspan=\"3\">$extra</td>\n" .
3318 ## ======================================================================
3319 ## ======================================================================
3322 sub git_project_list
{
3323 my $order = $cgi->param('o');
3324 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3325 die_error
(undef, "Unknown order parameter");
3328 my @list = git_get_projects_list
();
3330 die_error
(undef, "No projects found");
3334 if (-f
$home_text) {
3335 print "<div class=\"index_include\">\n";
3336 open (my $fd, $home_text);
3341 git_project_list_body
(\
@list, $order);
3346 my $order = $cgi->param('o');
3347 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3348 die_error
(undef, "Unknown order parameter");
3351 my @list = git_get_projects_list
($project);
3353 die_error
(undef, "No forks found");
3357 git_print_page_nav
('','');
3358 git_print_header_div
('summary', "$project forks");
3359 git_project_list_body
(\
@list, $order);
3363 sub git_project_index
{
3364 my @projects = git_get_projects_list
($project);
3367 -type
=> 'text/plain',
3368 -charset
=> 'utf-8',
3369 -content_disposition
=> 'inline; filename="index.aux"');
3371 foreach my $pr (@projects) {
3372 if (!exists $pr->{'owner'}) {
3373 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3376 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3377 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3378 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3379 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3383 print "$path $owner\n";
3388 my $descr = git_get_project_description
($project) || "none";
3389 my %co = parse_commit
("HEAD");
3390 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3391 my $head = $co{'id'};
3393 my $owner = git_get_project_owner
($project);
3395 my $refs = git_get_references
();
3396 # These get_*_list functions return one more to allow us to see if
3397 # there are more ...
3398 my @taglist = git_get_tags_list
(16);
3399 my @headlist = git_get_heads_list
(16);
3401 my ($check_forks) = gitweb_check_feature
('forks');
3404 @forklist = git_get_projects_list
($project);
3408 git_print_page_nav
('summary','', $head);
3410 print "<div class=\"title\"> </div>\n";
3411 print "<table cellspacing=\"0\">\n" .
3412 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3413 "<tr><td>owner</td><td>$owner</td></tr>\n";
3414 if (defined $cd{'rfc2822'}) {
3415 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3418 # use per project git URL list in $projectroot/$project/cloneurl
3419 # or make project git URL from git base URL and project name
3420 my $url_tag = "URL";
3421 my @url_list = git_get_project_url_list
($project);
3422 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3423 foreach my $git_url (@url_list) {
3424 next unless $git_url;
3425 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3430 if (-s
"$projectroot/$project/README.html") {
3431 if (open my $fd, "$projectroot/$project/README.html") {
3432 print "<div class=\"title\">readme</div>\n";
3433 print $_ while (<$fd>);
3438 # we need to request one more than 16 (0..15) to check if
3440 my @commitlist = $head ? parse_commits
($head, 17) : ();
3442 git_print_header_div
('shortlog');
3443 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3444 $#commitlist <= 15 ? undef :
3445 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3449 git_print_header_div
('tags');
3450 git_tags_body
(\
@taglist, 0, 15,
3451 $#taglist <= 15 ? undef :
3452 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3456 git_print_header_div
('heads');
3457 git_heads_body
(\
@headlist, $head, 0, 15,
3458 $#headlist <= 15 ? undef :
3459 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3463 git_print_header_div
('forks');
3464 git_project_list_body
(\
@forklist, undef, 0, 15,
3465 $#forklist <= 15 ? undef :
3466 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3474 my $head = git_get_head_hash
($project);
3476 git_print_page_nav
('','', $head,undef,$head);
3477 my %tag = parse_tag
($hash);
3480 die_error
(undef, "Unknown tag object");
3483 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3484 print "<div class=\"title_text\">\n" .
3485 "<table cellspacing=\"0\">\n" .
3487 "<td>object</td>\n" .
3488 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3489 $tag{'object'}) . "</td>\n" .
3490 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3491 $tag{'type'}) . "</td>\n" .
3493 if (defined($tag{'author'})) {
3494 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3495 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3496 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3497 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3500 print "</table>\n\n" .
3502 print "<div class=\"page_body\">";
3503 my $comment = $tag{'comment'};
3504 foreach my $line (@$comment) {
3506 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3516 my ($have_blame) = gitweb_check_feature
('blame');
3518 die_error
('403 Permission denied', "Permission denied");
3520 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3521 $hash_base ||= git_get_head_hash
($project);
3522 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3523 my %co = parse_commit
($hash_base)
3524 or die_error
(undef, "Reading commit failed");
3525 if (!defined $hash) {
3526 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3527 or die_error
(undef, "Error looking up file");
3529 $ftype = git_get_type
($hash);
3530 if ($ftype !~ "blob") {
3531 die_error
('400 Bad Request', "Object is not a blob");
3533 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3534 $file_name, $hash_base)
3535 or die_error
(undef, "Open git-blame failed");
3538 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3541 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3544 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3546 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3547 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3548 git_print_page_path
($file_name, $ftype, $hash_base);
3549 my @rev_color = (qw(light2 dark2));
3550 my $num_colors = scalar(@rev_color);
3551 my $current_color = 0;
3554 <div class="page_body">
3555 <table class="blame">
3556 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3561 last unless defined $_;
3562 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3563 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3564 if (!exists $metainfo{$full_rev}) {
3565 $metainfo{$full_rev} = {};
3567 my $meta = $metainfo{$full_rev};
3570 if (/^(\S+) (.*)$/) {
3576 my $rev = substr($full_rev, 0, 8);
3577 my $author = $meta->{'author'};
3578 my %date = parse_date
($meta->{'author-time'},
3579 $meta->{'author-tz'});
3580 my $date = $date{'iso-tz'};
3582 $current_color = ++$current_color % $num_colors;
3584 print "<tr class=\"$rev_color[$current_color]\">\n";
3586 print "<td class=\"sha1\"";
3587 print " title=\"". esc_html
($author) . ", $date\"";
3588 print " rowspan=\"$group_size\"" if ($group_size > 1);
3590 print $cgi->a({-href
=> href
(action
=>"commit",
3592 file_name
=>$file_name)},
3596 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3597 or die_error
(undef, "Open git-rev-parse failed");
3598 my $parent_commit = <$dd>;
3600 chomp($parent_commit);
3601 my $blamed = href
(action
=> 'blame',
3602 file_name
=> $meta->{'filename'},
3603 hash_base
=> $parent_commit);
3604 print "<td class=\"linenr\">";
3605 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3607 -class => "linenr" },
3610 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3616 or print "Reading blob failed\n";
3623 my ($have_blame) = gitweb_check_feature
('blame');
3625 die_error
('403 Permission denied', "Permission denied");
3627 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3628 $hash_base ||= git_get_head_hash
($project);
3629 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3630 my %co = parse_commit
($hash_base)
3631 or die_error
(undef, "Reading commit failed");
3632 if (!defined $hash) {
3633 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3634 or die_error
(undef, "Error lookup file");
3636 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3637 or die_error
(undef, "Open git-annotate failed");
3640 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3643 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3646 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3648 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3649 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3650 git_print_page_path
($file_name, 'blob', $hash_base);
3651 print "<div class=\"page_body\">\n";
3653 <table class="blame">
3662 my @line_class = (qw(light dark));
3663 my $line_class_len = scalar (@line_class);
3664 my $line_class_num = $#line_class;
3665 while (my $line = <$fd>) {
3677 $line_class_num = ($line_class_num + 1) % $line_class_len;
3679 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3686 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3689 $short_rev = substr ($long_rev, 0, 8);
3690 $age = time () - $time;
3691 $age_str = age_string
($age);
3692 $age_str =~ s/ / /g;
3693 $age_class = age_class
($age);
3694 $author = esc_html
($author);
3695 $author =~ s/ / /g;
3697 $data = untabify
($data);
3698 $data = esc_html
($data);
3701 <tr class="$line_class[$line_class_num]">
3702 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3703 <td class="$age_class">$age_str</td>
3705 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3706 <td class="pre">$data</td>
3709 } # while (my $line = <$fd>)
3710 print "</table>\n\n";
3712 or print "Reading blob failed.\n";
3718 my $head = git_get_head_hash
($project);
3720 git_print_page_nav
('','', $head,undef,$head);
3721 git_print_header_div
('summary', $project);
3723 my @tagslist = git_get_tags_list
();
3725 git_tags_body
(\
@tagslist);
3731 my $head = git_get_head_hash
($project);
3733 git_print_page_nav
('','', $head,undef,$head);
3734 git_print_header_div
('summary', $project);
3736 my @headslist = git_get_heads_list
();
3738 git_heads_body
(\
@headslist, $head);
3743 sub git_blob_plain
{
3746 if (!defined $hash) {
3747 if (defined $file_name) {
3748 my $base = $hash_base || git_get_head_hash
($project);
3749 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3750 or die_error
(undef, "Error lookup file");
3752 die_error
(undef, "No file name defined");
3754 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3755 # blobs defined by non-textual hash id's can be cached
3760 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3761 or die_error
(undef, "Couldn't cat $file_name, $hash");
3763 $type ||= blob_mimetype
($fd, $file_name);
3765 # save as filename, even when no $file_name is given
3766 my $save_as = "$hash";
3767 if (defined $file_name) {
3768 $save_as = $file_name;
3769 } elsif ($type =~ m/^text\//) {
3776 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3778 binmode STDOUT
, ':raw';
3780 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3788 if (!defined $hash) {
3789 if (defined $file_name) {
3790 my $base = $hash_base || git_get_head_hash
($project);
3791 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3792 or die_error
(undef, "Error lookup file");
3794 die_error
(undef, "No file name defined");
3796 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3797 # blobs defined by non-textual hash id's can be cached
3801 my ($have_blame) = gitweb_check_feature
('blame');
3802 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3803 or die_error
(undef, "Couldn't cat $file_name, $hash");
3804 my $mimetype = blob_mimetype
($fd, $file_name);
3805 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3807 return git_blob_plain
($mimetype);
3809 # we can have blame only for text/* mimetype
3810 $have_blame &&= ($mimetype =~ m!^text/!);
3812 git_header_html
(undef, $expires);
3813 my $formats_nav = '';
3814 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3815 if (defined $file_name) {
3818 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3819 hash
=>$hash, file_name
=>$file_name)},
3824 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3825 hash
=>$hash, file_name
=>$file_name)},
3828 $cgi->a({-href
=> href
(action
=>"blob_plain",
3829 hash
=>$hash, file_name
=>$file_name)},
3832 $cgi->a({-href
=> href
(action
=>"blob",
3833 hash_base
=>"HEAD", file_name
=>$file_name)},
3837 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3839 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3840 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3842 print "<div class=\"page_nav\">\n" .
3843 "<br/><br/></div>\n" .
3844 "<div class=\"title\">$hash</div>\n";
3846 git_print_page_path
($file_name, "blob", $hash_base);
3847 print "<div class=\"page_body\">\n";
3848 if ($mimetype =~ m!^text/!) {
3850 while (my $line = <$fd>) {
3853 $line = untabify
($line);
3854 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3855 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3857 } elsif ($mimetype =~ m!^image/!) {
3858 print qq
!<img type
="$mimetype"!;
3860 print qq
! alt
="$file_name" title
="$file_name"!;
3863 href(action=>"blob_plain
", hash=>$hash,
3864 hash_base=>$hash_base, file_name=>$file_name) .
3868 or print "Reading blob failed.\n";
3874 my $have_snapshot = gitweb_have_snapshot
();
3876 if (!defined $hash_base) {
3877 $hash_base = "HEAD";
3879 if (!defined $hash) {
3880 if (defined $file_name) {
3881 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3887 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3888 or die_error
(undef, "Open git-ls-tree failed");
3889 my @entries = map { chomp; $_ } <$fd>;
3890 close $fd or die_error
(undef, "Reading tree failed");
3893 my $refs = git_get_references
();
3894 my $ref = format_ref_marker
($refs, $hash_base);
3897 my ($have_blame) = gitweb_check_feature
('blame');
3898 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3900 if (defined $file_name) {
3902 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3903 hash
=>$hash, file_name
=>$file_name)},
3905 $cgi->a({-href
=> href
(action
=>"tree",
3906 hash_base
=>"HEAD", file_name
=>$file_name)},
3909 if ($have_snapshot) {
3910 # FIXME: Should be available when we have no hash base as well.
3912 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3915 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3916 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3919 print "<div class=\"page_nav\">\n";
3920 print "<br/><br/></div>\n";
3921 print "<div class=\"title\">$hash</div>\n";
3923 if (defined $file_name) {
3924 $basedir = $file_name;
3925 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3929 git_print_page_path
($file_name, 'tree', $hash_base);
3930 print "<div class=\"page_body\">\n";
3931 print "<table cellspacing=\"0\">\n";
3933 # '..' (top directory) link if possible
3934 if (defined $hash_base &&
3935 defined $file_name && $file_name =~ m![^/]+$!) {
3937 print "<tr class=\"dark\">\n";
3939 print "<tr class=\"light\">\n";
3943 my $up = $file_name;
3944 $up =~ s!/?[^/]+$!!;
3945 undef $up unless $up;
3946 # based on git_print_tree_entry
3947 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3948 print '<td class="list">';
3949 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3953 print "<td class=\"link\"></td>\n";
3957 foreach my $line (@entries) {
3958 my %t = parse_ls_tree_line
($line, -z
=> 1);
3961 print "<tr class=\"dark\">\n";
3963 print "<tr class=\"light\">\n";
3967 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3971 print "</table>\n" .
3977 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3978 my $have_snapshot = (defined $ctype && defined $suffix);
3979 if (!$have_snapshot) {
3980 die_error
('403 Permission denied', "Permission denied");
3983 if (!defined $hash) {
3984 $hash = git_get_head_hash
($project);
3987 my $filename = decode_utf8
(basename
($project)) . "-$hash.tar.$suffix";
3990 -type
=> "application/$ctype",
3991 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3992 -status
=> '200 OK');
3994 my $git = git_cmd_str
();
3995 my $name = $project;
3996 $name =~ s/\047/\047\\\047\047/g;
3998 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3999 or die_error
(undef, "Execute git-tar-tree failed");
4000 binmode STDOUT
, ':raw';
4002 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4008 my $head = git_get_head_hash
($project);
4009 if (!defined $hash) {
4012 if (!defined $page) {
4015 my $refs = git_get_references
();
4017 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4019 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4022 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4025 my %co = parse_commit
($hash);
4027 git_print_header_div
('summary', $project);
4028 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4030 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4031 for (my $i = 0; $i <= $to; $i++) {
4032 my %co = %{$commitlist[$i]};
4034 my $commit = $co{'id'};
4035 my $ref = format_ref_marker
($refs, $commit);
4036 my %ad = parse_date
($co{'author_epoch'});
4037 git_print_header_div
('commit',
4038 "<span class=\"age\">$co{'age_string'}</span>" .
4039 esc_html
($co{'title'}) . $ref,
4041 print "<div class=\"title_text\">\n" .
4042 "<div class=\"log_link\">\n" .
4043 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4045 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4047 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4050 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4053 print "<div class=\"log_body\">\n";
4054 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4057 if ($#commitlist >= 100) {
4058 print "<div class=\"page_nav\">\n";
4059 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4060 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4067 $hash ||= $hash_base || "HEAD";
4068 my %co = parse_commit
($hash);
4070 die_error
(undef, "Unknown commit object");
4072 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4073 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4075 my $parent = $co{'parent'};
4076 my $parents = $co{'parents'}; # listref
4078 # we need to prepare $formats_nav before any parameter munging
4080 if (!defined $parent) {
4082 $formats_nav .= '(initial)';
4083 } elsif (@$parents == 1) {
4084 # single parent commit
4087 $cgi->a({-href
=> href
(action
=>"commit",
4089 esc_html
(substr($parent, 0, 7))) .
4096 $cgi->a({-href
=> href
(action
=>"commit",
4098 esc_html
(substr($_, 0, 7)));
4103 if (!defined $parent) {
4107 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4109 (@$parents <= 1 ? $parent : '-c'),
4111 or die_error
(undef, "Open git-diff-tree failed");
4112 @difftree = map { chomp; $_ } <$fd>;
4113 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4115 # non-textual hash id's can be cached
4117 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4120 my $refs = git_get_references
();
4121 my $ref = format_ref_marker
($refs, $co{'id'});
4123 my $have_snapshot = gitweb_have_snapshot
();
4125 git_header_html
(undef, $expires);
4126 git_print_page_nav
('commit', '',
4127 $hash, $co{'tree'}, $hash,
4130 if (defined $co{'parent'}) {
4131 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4133 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4135 print "<div class=\"title_text\">\n" .
4136 "<table cellspacing=\"0\">\n";
4137 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4139 "<td></td><td> $ad{'rfc2822'}";
4140 if ($ad{'hour_local'} < 6) {
4141 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4142 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4144 printf(" (%02d:%02d %s)",
4145 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4149 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4150 print "<tr><td></td><td> $cd{'rfc2822'}" .
4151 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4153 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4156 "<td class=\"sha1\">" .
4157 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4158 class => "list"}, $co{'tree'}) .
4160 "<td class=\"link\">" .
4161 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4163 if ($have_snapshot) {
4165 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4170 foreach my $par (@$parents) {
4173 "<td class=\"sha1\">" .
4174 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4175 class => "list"}, $par) .
4177 "<td class=\"link\">" .
4178 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4180 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4187 print "<div class=\"page_body\">\n";
4188 git_print_log
($co{'comment'});
4191 git_difftree_body
(\
@difftree, $hash, @$parents);
4197 # object is defined by:
4198 # - hash or hash_base alone
4199 # - hash_base and file_name
4202 # - hash or hash_base alone
4203 if ($hash || ($hash_base && !defined $file_name)) {
4204 my $object_id = $hash || $hash_base;
4206 my $git_command = git_cmd_str
();
4207 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4208 or die_error
('404 Not Found', "Object does not exist");
4212 or die_error
('404 Not Found', "Object does not exist");
4214 # - hash_base and file_name
4215 } elsif ($hash_base && defined $file_name) {
4216 $file_name =~ s
,/+$,,;
4218 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4219 or die_error
('404 Not Found', "Base object does not exist");
4221 # here errors should not hapen
4222 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4223 or die_error
(undef, "Open git-ls-tree failed");
4227 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4228 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4229 die_error
('404 Not Found', "File or directory for given base does not exist");
4234 die_error
('404 Not Found', "Not enough information to find object");
4237 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4238 hash
=>$hash, hash_base
=>$hash_base,
4239 file_name
=>$file_name),
4240 -status
=> '302 Found');
4244 my $format = shift || 'html';
4251 # preparing $fd and %diffinfo for git_patchset_body
4253 if (defined $hash_base && defined $hash_parent_base) {
4254 if (defined $file_name) {
4256 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4257 $hash_parent_base, $hash_base,
4258 "--", (defined $file_parent ? $file_parent : ()), $file_name
4259 or die_error
(undef, "Open git-diff-tree failed");
4260 @difftree = map { chomp; $_ } <$fd>;
4262 or die_error
(undef, "Reading git-diff-tree failed");
4264 or die_error
('404 Not Found', "Blob diff not found");
4266 } elsif (defined $hash &&
4267 $hash =~ /[0-9a-fA-F]{40}/) {
4268 # try to find filename from $hash
4270 # read filtered raw output
4271 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4272 $hash_parent_base, $hash_base, "--"
4273 or die_error
(undef, "Open git-diff-tree failed");
4275 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4277 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4278 map { chomp; $_ } <$fd>;
4280 or die_error
(undef, "Reading git-diff-tree failed");
4282 or die_error
('404 Not Found', "Blob diff not found");
4285 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4288 if (@difftree > 1) {
4289 die_error
('404 Not Found', "Ambiguous blob diff specification");
4292 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4293 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4294 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4296 $hash_parent ||= $diffinfo{'from_id'};
4297 $hash ||= $diffinfo{'to_id'};
4299 # non-textual hash id's can be cached
4300 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4301 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4306 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4307 '-p', ($format eq 'html' ? "--full-index" : ()),
4308 $hash_parent_base, $hash_base,
4309 "--", (defined $file_parent ? $file_parent : ()), $file_name
4310 or die_error
(undef, "Open git-diff-tree failed");
4313 # old/legacy style URI
4314 if (!%diffinfo && # if new style URI failed
4315 defined $hash && defined $hash_parent) {
4316 # fake git-diff-tree raw output
4317 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4318 $diffinfo{'from_id'} = $hash_parent;
4319 $diffinfo{'to_id'} = $hash;
4320 if (defined $file_name) {
4321 if (defined $file_parent) {
4322 $diffinfo{'status'} = '2';
4323 $diffinfo{'from_file'} = $file_parent;
4324 $diffinfo{'to_file'} = $file_name;
4325 } else { # assume not renamed
4326 $diffinfo{'status'} = '1';
4327 $diffinfo{'from_file'} = $file_name;
4328 $diffinfo{'to_file'} = $file_name;
4330 } else { # no filename given
4331 $diffinfo{'status'} = '2';
4332 $diffinfo{'from_file'} = $hash_parent;
4333 $diffinfo{'to_file'} = $hash;
4336 # non-textual hash id's can be cached
4337 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4338 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4343 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4344 '-p', ($format eq 'html' ? "--full-index" : ()),
4345 $hash_parent, $hash, "--"
4346 or die_error
(undef, "Open git-diff failed");
4348 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4353 if ($format eq 'html') {
4355 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4356 hash
=>$hash, hash_parent
=>$hash_parent,
4357 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4358 file_name
=>$file_name, file_parent
=>$file_parent)},
4360 git_header_html
(undef, $expires);
4361 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4362 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4363 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4365 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4366 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4368 if (defined $file_name) {
4369 git_print_page_path
($file_name, "blob", $hash_base);
4371 print "<div class=\"page_path\"></div>\n";
4374 } elsif ($format eq 'plain') {
4376 -type
=> 'text/plain',
4377 -charset
=> 'utf-8',
4378 -expires
=> $expires,
4379 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4381 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4384 die_error
(undef, "Unknown blobdiff format");
4388 if ($format eq 'html') {
4389 print "<div class=\"page_body\">\n";
4391 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4394 print "</div>\n"; # class="page_body"
4398 while (my $line = <$fd>) {
4399 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4400 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4404 last if $line =~ m!^\+\+\+!;
4412 sub git_blobdiff_plain
{
4413 git_blobdiff
('plain');
4416 sub git_commitdiff
{
4417 my $format = shift || 'html';
4418 $hash ||= $hash_base || "HEAD";
4419 my %co = parse_commit
($hash);
4421 die_error
(undef, "Unknown commit object");
4424 # we need to prepare $formats_nav before any parameter munging
4426 if ($format eq 'html') {
4428 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4429 hash
=>$hash, hash_parent
=>$hash_parent)},
4432 if (defined $hash_parent) {
4433 # commitdiff with two commits given
4434 my $hash_parent_short = $hash_parent;
4435 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4436 $hash_parent_short = substr($hash_parent, 0, 7);
4440 $cgi->a({-href
=> href
(action
=>"commitdiff",
4441 hash
=>$hash_parent)},
4442 esc_html
($hash_parent_short)) .
4444 } elsif (!$co{'parent'}) {
4446 $formats_nav .= ' (initial)';
4447 } elsif (scalar @{$co{'parents'}} == 1) {
4448 # single parent commit
4451 $cgi->a({-href
=> href
(action
=>"commitdiff",
4452 hash
=>$co{'parent'})},
4453 esc_html
(substr($co{'parent'}, 0, 7))) .
4460 $cgi->a({-href
=> href
(action
=>"commitdiff",
4462 esc_html
(substr($_, 0, 7)));
4463 } @{$co{'parents'}} ) .
4468 my $hash_parent_param = $hash_parent;
4469 if (!defined $hash_parent) {
4470 $hash_parent_param =
4471 @{$co{'parents'}} > 1 ? '-c' : $co{'parent'} || '--root';
4477 if ($format eq 'html') {
4478 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4479 "--no-commit-id", "--patch-with-raw", "--full-index",
4480 $hash_parent_param, $hash, "--"
4481 or die_error
(undef, "Open git-diff-tree failed");
4483 while (my $line = <$fd>) {
4485 # empty line ends raw part of diff-tree output
4487 push @difftree, scalar parse_difftree_raw_line
($line);
4490 } elsif ($format eq 'plain') {
4491 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4492 '-p', $hash_parent_param, $hash, "--"
4493 or die_error
(undef, "Open git-diff-tree failed");
4496 die_error
(undef, "Unknown commitdiff format");
4499 # non-textual hash id's can be cached
4501 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4505 # write commit message
4506 if ($format eq 'html') {
4507 my $refs = git_get_references
();
4508 my $ref = format_ref_marker
($refs, $co{'id'});
4510 git_header_html
(undef, $expires);
4511 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4512 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4513 git_print_authorship
(\
%co);
4514 print "<div class=\"page_body\">\n";
4515 if (@{$co{'comment'}} > 1) {
4516 print "<div class=\"log\">\n";
4517 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4518 print "</div>\n"; # class="log"
4521 } elsif ($format eq 'plain') {
4522 my $refs = git_get_references
("tags");
4523 my $tagname = git_get_rev_name_tags
($hash);
4524 my $filename = basename
($project) . "-$hash.patch";
4527 -type
=> 'text/plain',
4528 -charset
=> 'utf-8',
4529 -expires
=> $expires,
4530 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4531 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4534 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4535 Subject: $co{'title'}
4537 print "X-Git-Tag: $tagname\n" if $tagname;
4538 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4540 foreach my $line (@{$co{'comment'}}) {
4547 if ($format eq 'html') {
4548 git_difftree_body
(\
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4551 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4553 print "</div>\n"; # class="page_body"
4556 } elsif ($format eq 'plain') {
4560 or print "Reading git-diff-tree failed\n";
4564 sub git_commitdiff_plain
{
4565 git_commitdiff
('plain');
4569 if (!defined $hash_base) {
4570 $hash_base = git_get_head_hash
($project);
4572 if (!defined $page) {
4576 my %co = parse_commit
($hash_base);
4578 die_error
(undef, "Unknown commit object");
4581 my $refs = git_get_references
();
4582 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4584 if (!defined $hash && defined $file_name) {
4585 $hash = git_get_hash_by_path
($hash_base, $file_name);
4587 if (defined $hash) {
4588 $ftype = git_get_type
($hash);
4591 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4593 my $paging_nav = '';
4596 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4597 file_name
=>$file_name)},
4599 $paging_nav .= " ⋅ " .
4600 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4601 file_name
=>$file_name, page
=>$page-1),
4602 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4604 $paging_nav .= "first";
4605 $paging_nav .= " ⋅ prev";
4607 if ($#commitlist >= 100) {
4608 $paging_nav .= " ⋅ " .
4609 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4610 file_name
=>$file_name, page
=>$page+1),
4611 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4613 $paging_nav .= " ⋅ next";
4616 if ($#commitlist >= 100) {
4618 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4619 file_name
=>$file_name, page
=>$page+1),
4620 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4624 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4625 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4626 git_print_page_path
($file_name, $ftype, $hash_base);
4628 git_history_body
(\
@commitlist, 0, 99,
4629 $refs, $hash_base, $ftype, $next_link);
4635 my ($have_search) = gitweb_check_feature
('search');
4636 if (!$have_search) {
4637 die_error
('403 Permission denied', "Permission denied");
4639 if (!defined $searchtext) {
4640 die_error
(undef, "Text field empty");
4642 if (!defined $hash) {
4643 $hash = git_get_head_hash
($project);
4645 my %co = parse_commit
($hash);
4647 die_error
(undef, "Unknown commit object");
4649 if (!defined $page) {
4653 $searchtype ||= 'commit';
4654 if ($searchtype eq 'pickaxe') {
4655 # pickaxe may take all resources of your box and run for several minutes
4656 # with every query - so decide by yourself how public you make this feature
4657 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4658 if (!$have_pickaxe) {
4659 die_error
('403 Permission denied', "Permission denied");
4662 if ($searchtype eq 'grep') {
4663 my ($have_grep) = gitweb_check_feature
('grep');
4665 die_error
('403 Permission denied', "Permission denied");
4671 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4673 if ($searchtype eq 'commit') {
4674 $greptype = "--grep=";
4675 } elsif ($searchtype eq 'author') {
4676 $greptype = "--author=";
4677 } elsif ($searchtype eq 'committer') {
4678 $greptype = "--committer=";
4680 $greptype .= $search_regexp;
4681 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4683 my $paging_nav = '';
4686 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4687 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4689 $paging_nav .= " ⋅ " .
4690 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4691 searchtext
=>$searchtext, searchtype
=>$searchtype,
4693 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4695 $paging_nav .= "first";
4696 $paging_nav .= " ⋅ prev";
4698 if ($#commitlist >= 100) {
4699 $paging_nav .= " ⋅ " .
4700 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4701 searchtext
=>$searchtext, searchtype
=>$searchtype,
4703 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4705 $paging_nav .= " ⋅ next";
4708 if ($#commitlist >= 100) {
4710 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4711 searchtext
=>$searchtext, searchtype
=>$searchtype,
4713 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4716 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4717 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4718 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4721 if ($searchtype eq 'pickaxe') {
4722 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4723 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4725 print "<table cellspacing=\"0\">\n";
4728 my $git_command = git_cmd_str
();
4729 my $searchqtext = $searchtext;
4730 $searchqtext =~ s/'/'\\''/;
4731 open my $fd, "-|", "$git_command rev-list $hash | " .
4732 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
4735 while (my $line = <$fd>) {
4736 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4739 $set{'from_id'} = $3;
4741 $set{'id'} = $set{'to_id'};
4742 if ($set{'id'} =~ m/0{40}/) {
4743 $set{'id'} = $set{'from_id'};
4745 if ($set{'id'} =~ m/0{40}/) {
4749 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4752 print "<tr class=\"dark\">\n";
4754 print "<tr class=\"light\">\n";
4757 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4758 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4760 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4761 -class => "list subject"},
4762 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4763 while (my $setref = shift @files) {
4765 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4766 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4768 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4772 "<td class=\"link\">" .
4773 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4775 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4779 %co = parse_commit
($1);
4787 if ($searchtype eq 'grep') {
4788 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4789 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4791 print "<table cellspacing=\"0\">\n";
4795 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
4797 while (my $line = <$fd>) {
4799 my ($file, $lno, $ltext, $binary);
4800 last if ($matches++ > 1000);
4801 if ($line =~ /^Binary file (.+) matches$/) {
4805 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
4807 if ($file ne $lastfile) {
4808 $lastfile and print "</td></tr>\n";
4810 print "<tr class=\"dark\">\n";
4812 print "<tr class=\"light\">\n";
4814 print "<td class=\"list\">".
4815 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4816 file_name
=>"$file"),
4817 -class => "list"}, esc_path
($file));
4818 print "</td><td>\n";
4822 print "<div class=\"binary\">Binary file</div>\n";
4824 $ltext = untabify
($ltext);
4825 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
4826 $ltext = esc_html
($1, -nbsp
=>1);
4827 $ltext .= '<span class="match">';
4828 $ltext .= esc_html
($2, -nbsp
=>1);
4829 $ltext .= '</span>';
4830 $ltext .= esc_html
($3, -nbsp
=>1);
4832 $ltext = esc_html
($ltext, -nbsp
=>1);
4834 print "<div class=\"pre\">" .
4835 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4836 file_name
=>"$file").'#l'.$lno,
4837 -class => "linenr"}, sprintf('%4i', $lno))
4838 . ' ' . $ltext . "</div>\n";
4842 print "</td></tr>\n";
4843 if ($matches > 1000) {
4844 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
4847 print "<div class=\"diff nodifferences\">No matches found</div>\n";
4856 sub git_search_help
{
4858 git_print_page_nav
('','', $hash,$hash,$hash);
4861 <dt><b>commit</b></dt>
4862 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4864 my ($have_grep) = gitweb_check_feature
('grep');
4867 <dt><b>grep</b></dt>
4868 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
4869 a different one) are searched for the given
4870 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
4871 (POSIX extended) and the matches are listed. On large
4872 trees, this search can take a while and put some strain on the server, so please use it with
4873 some consideration.</dd>
4877 <dt><b>author</b></dt>
4878 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4879 <dt><b>committer</b></dt>
4880 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4882 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4883 if ($have_pickaxe) {
4885 <dt><b>pickaxe</b></dt>
4886 <dd>All commits that caused the string to appear or disappear from any file (changes that
4887 added, removed or "modified" the string) will be listed. This search can take a while and
4888 takes a lot of strain on the server, so please use it wisely.</dd>
4896 my $head = git_get_head_hash
($project);
4897 if (!defined $hash) {
4900 if (!defined $page) {
4903 my $refs = git_get_references
();
4905 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4907 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4909 if ($#commitlist >= 100) {
4911 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4912 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4916 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4917 git_print_header_div
('summary', $project);
4919 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4924 ## ......................................................................
4925 ## feeds (RSS, Atom; OPML)
4928 my $format = shift || 'atom';
4929 my ($have_blame) = gitweb_check_feature
('blame');
4931 # Atom: http://www.atomenabled.org/developers/syndication/
4932 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4933 if ($format ne 'rss' && $format ne 'atom') {
4934 die_error
(undef, "Unknown web feed format");
4937 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4938 my $head = $hash || 'HEAD';
4939 my @commitlist = parse_commits
($head, 150);
4943 my $content_type = "application/$format+xml";
4944 if (defined $cgi->http('HTTP_ACCEPT') &&
4945 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4946 # browser (feed reader) prefers text/xml
4947 $content_type = 'text/xml';
4949 if (defined($commitlist[0])) {
4950 %latest_commit = %{$commitlist[0]};
4951 %latest_date = parse_date
($latest_commit{'author_epoch'});
4953 -type
=> $content_type,
4954 -charset
=> 'utf-8',
4955 -last_modified
=> $latest_date{'rfc2822'});
4958 -type
=> $content_type,
4959 -charset
=> 'utf-8');
4962 # Optimization: skip generating the body if client asks only
4963 # for Last-Modified date.
4964 return if ($cgi->request_method() eq 'HEAD');
4967 my $title = "$site_name - $project/$action";
4968 my $feed_type = 'log';
4969 if (defined $hash) {
4970 $title .= " - '$hash'";
4971 $feed_type = 'branch log';
4972 if (defined $file_name) {
4973 $title .= " :: $file_name";
4974 $feed_type = 'history';
4976 } elsif (defined $file_name) {
4977 $title .= " - $file_name";
4978 $feed_type = 'history';
4980 $title .= " $feed_type";
4981 my $descr = git_get_project_description
($project);
4982 if (defined $descr) {
4983 $descr = esc_html
($descr);
4985 $descr = "$project " .
4986 ($format eq 'rss' ? 'RSS' : 'Atom') .
4989 my $owner = git_get_project_owner
($project);
4990 $owner = esc_html
($owner);
4994 if (defined $file_name) {
4995 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4996 } elsif (defined $hash) {
4997 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4999 $alt_url = href
(-full
=>1, action
=>"summary");
5001 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5002 if ($format eq 'rss') {
5004 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5007 print "<title>$title</title>\n" .
5008 "<link>$alt_url</link>\n" .
5009 "<description>$descr</description>\n" .
5010 "<language>en</language>\n";
5011 } elsif ($format eq 'atom') {
5013 <feed xmlns="http://www.w3.org/2005/Atom">
5015 print "<title>$title</title>\n" .
5016 "<subtitle>$descr</subtitle>\n" .
5017 '<link rel="alternate" type="text/html" href="' .
5018 $alt_url . '" />' . "\n" .
5019 '<link rel="self" type="' . $content_type . '" href="' .
5020 $cgi->self_url() . '" />' . "\n" .
5021 "<id>" . href
(-full
=>1) . "</id>\n" .
5022 # use project owner for feed author
5023 "<author><name>$owner</name></author>\n";
5024 if (defined $favicon) {
5025 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5027 if (defined $logo_url) {
5028 # not twice as wide as tall: 72 x 27 pixels
5029 print "<logo>" . esc_url
($logo) . "</logo>\n";
5031 if (! %latest_date) {
5032 # dummy date to keep the feed valid until commits trickle in:
5033 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5035 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5040 for (my $i = 0; $i <= $#commitlist; $i++) {
5041 my %co = %{$commitlist[$i]};
5042 my $commit = $co{'id'};
5043 # we read 150, we always show 30 and the ones more recent than 48 hours
5044 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5047 my %cd = parse_date
($co{'author_epoch'});
5049 # get list of changed files
5050 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5051 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
5053 my @difftree = map { chomp; $_ } <$fd>;
5057 # print element (entry, item)
5058 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5059 if ($format eq 'rss') {
5061 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5062 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5063 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5064 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5065 "<link>$co_url</link>\n" .
5066 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5067 "<content:encoded>" .
5069 } elsif ($format eq 'atom') {
5071 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5072 "<updated>$cd{'iso-8601'}</updated>\n" .
5074 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5075 if ($co{'author_email'}) {
5076 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5078 print "</author>\n" .
5079 # use committer for contributor
5081 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5082 if ($co{'committer_email'}) {
5083 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5085 print "</contributor>\n" .
5086 "<published>$cd{'iso-8601'}</published>\n" .
5087 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5088 "<id>$co_url</id>\n" .
5089 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5090 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5092 my $comment = $co{'comment'};
5094 foreach my $line (@$comment) {
5095 $line = esc_html
($line);
5098 print "</pre><ul>\n";
5099 foreach my $difftree_line (@difftree) {
5100 my %difftree = parse_difftree_raw_line
($difftree_line);
5101 next if !$difftree{'from_id'};
5103 my $file = $difftree{'file'} || $difftree{'to_file'};
5107 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5108 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5109 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5110 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5111 -title
=> "diff"}, 'D');
5113 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5114 file_name
=>$file, hash_base
=>$commit),
5115 -title
=> "blame"}, 'B');
5117 # if this is not a feed of a file history
5118 if (!defined $file_name || $file_name ne $file) {
5119 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5120 file_name
=>$file, hash
=>$commit),
5121 -title
=> "history"}, 'H');
5123 $file = esc_path
($file);
5127 if ($format eq 'rss') {
5128 print "</ul>]]>\n" .
5129 "</content:encoded>\n" .
5131 } elsif ($format eq 'atom') {
5132 print "</ul>\n</div>\n" .
5139 if ($format eq 'rss') {
5140 print "</channel>\n</rss>\n";
5141 } elsif ($format eq 'atom') {
5155 my @list = git_get_projects_list
();
5157 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5159 <?xml version="1.0" encoding="utf-8"?>
5160 <opml version="1.0">
5162 <title>$site_name OPML Export</title>
5165 <outline text="git RSS feeds">
5168 foreach my $pr (@list) {
5170 my $head = git_get_head_hash
($proj{'path'});
5171 if (!defined $head) {
5174 $git_dir = "$projectroot/$proj{'path'}";
5175 my %co = parse_commit
($head);
5180 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5181 my $rss = "$my_url?p=$proj{'path'};a=rss";
5182 my $html = "$my_url?p=$proj{'path'};a=summary";
5183 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";