3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute
=> 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++"
43 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
45 # filename of html text to include at top of each page
46 our $site_header = "++GITWEB_SITE_HEADER++";
47 # html text to include at home page
48 our $home_text = "++GITWEB_HOMETEXT++";
49 # filename of html text to include at bottom of each page
50 our $site_footer = "++GITWEB_SITE_FOOTER++";
53 our @stylesheets = ("++GITWEB_CSS++");
55 # default is not to define style sheet, but it can be overwritten later
58 # URI of default stylesheet
59 our $stylesheet = "++GITWEB_CSS++";
60 # URI of GIT logo (72x27 size)
61 our $logo = "++GITWEB_LOGO++";
62 # URI of GIT favicon, assumed to be image/png type
63 our $favicon = "++GITWEB_FAVICON++";
65 # URI and label (title) of GIT logo link
66 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
67 #our $logo_label = "git documentation";
68 our $logo_url = "http://git.or.cz/";
69 our $logo_label = "git homepage";
71 # source of projects list
72 our $projects_list = "++GITWEB_LIST++";
74 # show repository only if this file exists
75 # (only effective if this variable evaluates to true)
76 our $export_ok = "++GITWEB_EXPORT_OK++";
78 # only allow viewing of repositories also shown on the overview page
79 our $strict_export = "++GITWEB_STRICT_EXPORT++";
81 # list of git base URLs used for URL to where fetch project from,
82 # i.e. full URL is "$git_base_url/$project"
83 our @git_base_url_list = ("++GITWEB_BASE_URL++");
85 # default blob_plain mimetype and default charset for text/plain blob
86 our $default_blob_plain_mimetype = 'text/plain';
87 our $default_text_plain_charset = undef;
89 # file to use for guessing MIME types before trying /etc/mime.types
90 # (relative to the current git repository)
91 our $mimetypes_file = undef;
93 # You define site-wide feature defaults here; override them with
94 # $GITWEB_CONFIG as necessary.
97 # 'sub' => feature-sub (subroutine),
98 # 'override' => allow-override (boolean),
99 # 'default' => [ default options...] (array reference)}
101 # if feature is overridable (it means that allow-override has true value,
102 # then feature-sub will be called with default options as parameters;
103 # return value of feature-sub indicates if to enable specified feature
105 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
107 # Enable the 'blame' blob view, showing the last commit that modified
108 # each line in the file. This can be very CPU-intensive.
110 # To enable system wide have in $GITWEB_CONFIG
111 # $feature{'blame'}{'default'} = [1];
112 # To have project specific config enable override in $GITWEB_CONFIG
113 # $feature{'blame'}{'override'} = 1;
114 # and in project config gitweb.blame = 0|1;
116 'sub' => \
&feature_blame
,
120 # Enable the 'snapshot' link, providing a compressed tarball of any
121 # tree. This can potentially generate high traffic if you have large
124 # To disable system wide have in $GITWEB_CONFIG
125 # $feature{'snapshot'}{'default'} = [undef];
126 # To have project specific config enable override in $GITWEB_CONFIG
127 # $feature{'blame'}{'override'} = 1;
128 # and in project config gitweb.snapshot = none|gzip|bzip2;
130 'sub' => \
&feature_snapshot
,
132 # => [content-encoding, suffix, program]
133 'default' => ['x-gzip', 'gz', 'gzip']},
135 # Enable the pickaxe search, which will list the commits that modified
136 # a given string in a file. This can be practical and quite faster
137 # alternative to 'blame', but still potentially CPU-intensive.
139 # To enable system wide have in $GITWEB_CONFIG
140 # $feature{'pickaxe'}{'default'} = [1];
141 # To have project specific config enable override in $GITWEB_CONFIG
142 # $feature{'pickaxe'}{'override'} = 1;
143 # and in project config gitweb.pickaxe = 0|1;
145 'sub' => \
&feature_pickaxe
,
149 # Make gitweb use an alternative format of the URLs which can be
150 # more readable and natural-looking: project name is embedded
151 # directly in the path and the query string contains other
152 # auxiliary information. All gitweb installations recognize
153 # URL in either format; this configures in which formats gitweb
156 # To enable system wide have in $GITWEB_CONFIG
157 # $feature{'pathinfo'}{'default'} = [1];
158 # Project specific override is not supported.
160 # Note that you will need to change the default location of CSS,
161 # favicon, logo and possibly other files to an absolute URL. Also,
162 # if gitweb.cgi serves as your indexfile, you will need to force
163 # $my_uri to contain the script name in your $GITWEB_CONFIG.
168 # Make gitweb consider projects in project root subdirectories
169 # to be forks of existing projects. Given project $projname.git,
170 # projects matching $projname/*.git will not be shown in the main
171 # projects list, instead a '+' mark will be added to $projname
172 # there and a 'forks' view will be enabled for the project, listing
173 # all the forks. This feature is supported only if project list
174 # is taken from a directory, not file.
176 # To enable system wide have in $GITWEB_CONFIG
177 # $feature{'forks'}{'default'} = [1];
178 # Project specific override is not supported.
184 sub gitweb_check_feature
{
186 return unless exists $feature{$name};
187 my ($sub, $override, @defaults) = (
188 $feature{$name}{'sub'},
189 $feature{$name}{'override'},
190 @
{$feature{$name}{'default'}});
191 if (!$override) { return @defaults; }
193 warn "feature $name is not overrideable";
196 return $sub->(@defaults);
200 my ($val) = git_get_project_config
('blame', '--bool');
202 if ($val eq 'true') {
204 } elsif ($val eq 'false') {
211 sub feature_snapshot
{
212 my ($ctype, $suffix, $command) = @_;
214 my ($val) = git_get_project_config
('snapshot');
216 if ($val eq 'gzip') {
217 return ('x-gzip', 'gz', 'gzip');
218 } elsif ($val eq 'bzip2') {
219 return ('x-bzip2', 'bz2', 'bzip2');
220 } elsif ($val eq 'none') {
224 return ($ctype, $suffix, $command);
227 sub gitweb_have_snapshot
{
228 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
229 my $have_snapshot = (defined $ctype && defined $suffix);
231 return $have_snapshot;
234 sub feature_pickaxe
{
235 my ($val) = git_get_project_config
('pickaxe', '--bool');
237 if ($val eq 'true') {
239 } elsif ($val eq 'false') {
246 # checking HEAD file with -e is fragile if the repository was
247 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
249 sub check_head_link
{
251 my $headfile = "$dir/HEAD";
252 return ((-e
$headfile) ||
253 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
256 sub check_export_ok
{
258 return (check_head_link
($dir) &&
259 (!$export_ok || -e
"$dir/$export_ok"));
262 # rename detection options for git-diff and git-diff-tree
263 # - default is '-M', with the cost proportional to
264 # (number of removed files) * (number of new files).
265 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
266 # (number of changed files + number of removed files) * (number of new files)
267 # - even more costly is '-C', '--find-copies-harder' with cost
268 # (number of files in the original tree) * (number of new files)
269 # - one might want to include '-B' option, e.g. '-B', '-M'
270 our @diff_opts = ('-M'); # taken from git_commit
272 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
273 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
275 # version of the core git binary
276 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
278 $projects_list ||= $projectroot;
280 # ======================================================================
281 # input validation and dispatch
282 our $action = $cgi->param('a');
283 if (defined $action) {
284 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
285 die_error
(undef, "Invalid action parameter");
289 # parameters which are pathnames
290 our $project = $cgi->param('p');
291 if (defined $project) {
292 if (!validate_pathname
($project) ||
293 !(-d
"$projectroot/$project") ||
294 !check_head_link
("$projectroot/$project") ||
295 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
296 ($strict_export && !project_in_list
($project))) {
298 die_error
(undef, "No such project");
302 our $file_name = $cgi->param('f');
303 if (defined $file_name) {
304 if (!validate_pathname
($file_name)) {
305 die_error
(undef, "Invalid file parameter");
309 our $file_parent = $cgi->param('fp');
310 if (defined $file_parent) {
311 if (!validate_pathname
($file_parent)) {
312 die_error
(undef, "Invalid file parent parameter");
316 # parameters which are refnames
317 our $hash = $cgi->param('h');
319 if (!validate_refname
($hash)) {
320 die_error
(undef, "Invalid hash parameter");
324 our $hash_parent = $cgi->param('hp');
325 if (defined $hash_parent) {
326 if (!validate_refname
($hash_parent)) {
327 die_error
(undef, "Invalid hash parent parameter");
331 our $hash_base = $cgi->param('hb');
332 if (defined $hash_base) {
333 if (!validate_refname
($hash_base)) {
334 die_error
(undef, "Invalid hash base parameter");
338 our $hash_parent_base = $cgi->param('hpb');
339 if (defined $hash_parent_base) {
340 if (!validate_refname
($hash_parent_base)) {
341 die_error
(undef, "Invalid hash parent base parameter");
346 our $page = $cgi->param('pg');
348 if ($page =~ m/[^0-9]/) {
349 die_error
(undef, "Invalid page parameter");
353 our $searchtext = $cgi->param('s');
354 if (defined $searchtext) {
355 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
356 die_error
(undef, "Invalid search parameter");
358 $searchtext = quotemeta $searchtext;
361 our $searchtype = $cgi->param('st');
362 if (defined $searchtype) {
363 if ($searchtype =~ m/[^a-z]/) {
364 die_error
(undef, "Invalid searchtype parameter");
368 # now read PATH_INFO and use it as alternative to parameters
369 sub evaluate_path_info
{
370 return if defined $project;
371 my $path_info = $ENV{"PATH_INFO"};
372 return if !$path_info;
373 $path_info =~ s
,^/+,,;
374 return if !$path_info;
375 # find which part of PATH_INFO is project
376 $project = $path_info;
378 while ($project && !check_head_link
("$projectroot/$project")) {
379 $project =~ s
,/*[^/]*$,,;
382 $project = validate_pathname
($project);
384 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
385 ($strict_export && !project_in_list
($project))) {
389 # do not change any parameters if an action is given using the query string
391 $path_info =~ s
,^$project/*,,;
392 my ($refname, $pathname) = split(/:/, $path_info, 2);
393 if (defined $pathname) {
394 # we got "project.git/branch:filename" or "project.git/branch:dir/"
395 # we could use git_get_type(branch:pathname), but it needs $git_dir
396 $pathname =~ s
,^/+,,;
397 if (!$pathname || substr($pathname, -1) eq "/") {
401 $action ||= "blob_plain";
403 $hash_base ||= validate_refname
($refname);
404 $file_name ||= validate_pathname
($pathname);
405 } elsif (defined $refname) {
406 # we got "project.git/branch"
407 $action ||= "shortlog";
408 $hash ||= validate_refname
($refname);
411 evaluate_path_info
();
413 # path to the current git repository
415 $git_dir = "$projectroot/$project" if $project;
419 "blame" => \
&git_blame2
,
420 "blobdiff" => \
&git_blobdiff
,
421 "blobdiff_plain" => \
&git_blobdiff_plain
,
422 "blob" => \
&git_blob
,
423 "blob_plain" => \
&git_blob_plain
,
424 "commitdiff" => \
&git_commitdiff
,
425 "commitdiff_plain" => \
&git_commitdiff_plain
,
426 "commit" => \
&git_commit
,
427 "forks" => \
&git_forks
,
428 "heads" => \
&git_heads
,
429 "history" => \
&git_history
,
432 "search" => \
&git_search
,
433 "search_help" => \
&git_search_help
,
434 "shortlog" => \
&git_shortlog
,
435 "summary" => \
&git_summary
,
437 "tags" => \
&git_tags
,
438 "tree" => \
&git_tree
,
439 "snapshot" => \
&git_snapshot
,
440 # those below don't need $project
441 "opml" => \
&git_opml
,
442 "project_list" => \
&git_project_list
,
443 "project_index" => \
&git_project_index
,
446 if (defined $project) {
447 $action ||= 'summary';
449 $action ||= 'project_list';
451 if (!defined($actions{$action})) {
452 die_error
(undef, "Unknown action");
454 if ($action !~ m/^(opml|project_list|project_index)$/ &&
456 die_error
(undef, "Project needed");
458 $actions{$action}->();
461 ## ======================================================================
468 # XXX: Warning: If you touch this, check the search form for updating,
479 hash_parent_base
=> "hpb",
485 my %mapping = @mapping;
487 $params{'project'} = $project unless exists $params{'project'};
489 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
491 # use PATH_INFO for project name
492 $href .= "/$params{'project'}" if defined $params{'project'};
493 delete $params{'project'};
495 # Summary just uses the project path URL
496 if (defined $params{'action'} && $params{'action'} eq 'summary') {
497 delete $params{'action'};
501 # now encode the parameters explicitly
503 for (my $i = 0; $i < @mapping; $i += 2) {
504 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
505 if (defined $params{$name}) {
506 push @result, $symbol . "=" . esc_param
($params{$name});
509 $href .= "?" . join(';', @result) if scalar @result;
515 ## ======================================================================
516 ## validation, quoting/unquoting and escaping
518 sub validate_pathname
{
519 my $input = shift || return undef;
521 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
522 # at the beginning, at the end, and between slashes.
523 # also this catches doubled slashes
524 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
528 if ($input =~ m!\0!) {
534 sub validate_refname
{
535 my $input = shift || return undef;
537 # textual hashes are O.K.
538 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
541 # it must be correct pathname
542 $input = validate_pathname
($input)
544 # restrictions on ref name according to git-check-ref-format
545 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
551 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
554 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
557 # quote unsafe chars, but keep the slash, even when it's not
558 # correct, but quoted slashes look too horrible in bookmarks
561 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
567 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
570 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
576 # replace invalid utf8 character with SUBSTITUTION sequence
579 $str = to_utf8
($str);
580 $str = escapeHTML
($str);
581 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
582 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
586 # git may return quoted and escaped filenames
589 if ($str =~ m/^"(.*)"$/) {
591 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
596 # escape tabs (convert tabs to spaces)
600 while ((my $pos = index($line, "\t")) != -1) {
601 if (my $count = (8 - ($pos % 8))) {
602 my $spaces = ' ' x
$count;
603 $line =~ s/\t/$spaces/;
610 sub project_in_list
{
612 my @list = git_get_projects_list
();
613 return @list && scalar(grep { $_->{'path'} eq $project } @list);
616 ## ----------------------------------------------------------------------
617 ## HTML aware string manipulation
622 my $add_len = shift || 10;
624 # allow only $len chars, but don't cut a word if it would fit in $add_len
625 # if it doesn't fit, cut it if it's still longer than the dots we would add
626 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
629 if (length($tail) > 4) {
631 $body =~ s/&[^;]*$//; # remove chopped character entities
636 ## ----------------------------------------------------------------------
637 ## functions returning short strings
639 # CSS class for given age value (in seconds)
643 if ($age < 60*60*2) {
645 } elsif ($age < 60*60*24*2) {
652 # convert age in seconds to "nn units ago" string
657 if ($age > 60*60*24*365*2) {
658 $age_str = (int $age/60/60/24/365);
659 $age_str .= " years ago";
660 } elsif ($age > 60*60*24*(365/12)*2) {
661 $age_str = int $age/60/60/24/(365/12);
662 $age_str .= " months ago";
663 } elsif ($age > 60*60*24*7*2) {
664 $age_str = int $age/60/60/24/7;
665 $age_str .= " weeks ago";
666 } elsif ($age > 60*60*24*2) {
667 $age_str = int $age/60/60/24;
668 $age_str .= " days ago";
669 } elsif ($age > 60*60*2) {
670 $age_str = int $age/60/60;
671 $age_str .= " hours ago";
672 } elsif ($age > 60*2) {
673 $age_str = int $age/60;
674 $age_str .= " min ago";
677 $age_str .= " sec ago";
679 $age_str .= " right now";
684 # convert file mode in octal to symbolic file mode string
686 my $mode = oct shift;
688 if (S_ISDIR
($mode & S_IFMT
)) {
690 } elsif (S_ISLNK
($mode)) {
692 } elsif (S_ISREG
($mode)) {
693 # git cares only about the executable bit
694 if ($mode & S_IXUSR
) {
704 # convert file mode in octal to file type string
708 if ($mode !~ m/^[0-7]+$/) {
714 if (S_ISDIR
($mode & S_IFMT
)) {
716 } elsif (S_ISLNK
($mode)) {
718 } elsif (S_ISREG
($mode)) {
725 ## ----------------------------------------------------------------------
726 ## functions returning short HTML fragments, or transforming HTML fragments
727 ## which don't beling to other sections
729 # format line of commit message or tag comment
730 sub format_log_line_html
{
733 $line = esc_html
($line);
734 $line =~ s/ / /g;
735 if ($line =~ m/([0-9a-fA-F]{40})/) {
737 if (git_get_type
($hash_text) eq "commit") {
739 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
740 -class => "text"}, $hash_text);
741 $line =~ s/$hash_text/$link/;
747 # format marker of refs pointing to given object
748 sub format_ref_marker
{
749 my ($refs, $id) = @_;
752 if (defined $refs->{$id}) {
753 foreach my $ref (@
{$refs->{$id}}) {
754 my ($type, $name) = qw();
755 # e.g. tags/v2.6.11 or heads/next
756 if ($ref =~ m!^(.*?)s?/(.*)$!) {
764 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
769 return ' <span class="refs">'. $markers . '</span>';
775 # format, perhaps shortened and with markers, title line
776 sub format_subject_html
{
777 my ($long, $short, $href, $extra) = @_;
778 $extra = '' unless defined($extra);
780 if (length($short) < length($long)) {
781 return $cgi->a({-href
=> $href, -class => "list subject",
782 -title
=> to_utf8
($long)},
783 esc_html
($short) . $extra);
785 return $cgi->a({-href
=> $href, -class => "list subject"},
786 esc_html
($long) . $extra);
790 sub format_diff_line
{
792 my $char = substr($line, 0, 1);
798 $diff_class = " add";
799 } elsif ($char eq "-") {
800 $diff_class = " rem";
801 } elsif ($char eq "@") {
802 $diff_class = " chunk_header";
803 } elsif ($char eq "\\") {
804 $diff_class = " incomplete";
806 $line = untabify
($line);
807 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
810 ## ----------------------------------------------------------------------
811 ## git utility subroutines, invoking git commands
813 # returns path to the core git executable and the --git-dir parameter as list
815 return $GIT, '--git-dir='.$git_dir;
818 # returns path to the core git executable and the --git-dir parameter as string
820 return join(' ', git_cmd
());
823 # get HEAD ref of given project as hash
824 sub git_get_head_hash
{
826 my $o_git_dir = $git_dir;
828 $git_dir = "$projectroot/$project";
829 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
832 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
836 if (defined $o_git_dir) {
837 $git_dir = $o_git_dir;
842 # get type of given object
846 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
853 sub git_get_project_config
{
854 my ($key, $type) = @_;
856 return unless ($key);
857 $key =~ s/^gitweb\.//;
858 return if ($key =~ m/\W/);
860 my @x = (git_cmd
(), 'repo-config');
861 if (defined $type) { push @x, $type; }
863 push @x, "gitweb.$key";
869 # get hash of given path at given ref
870 sub git_get_hash_by_path
{
872 my $path = shift || return undef;
877 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
878 or die_error
(undef, "Open git-ls-tree failed");
880 close $fd or return undef;
882 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
883 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
884 if (defined $type && $type ne $2) {
891 ## ......................................................................
892 ## git utility functions, directly accessing git repository
894 sub git_get_project_description
{
897 open my $fd, "$projectroot/$path/description" or return undef;
904 sub git_get_project_url_list
{
907 open my $fd, "$projectroot/$path/cloneurl" or return;
908 my @git_project_url_list = map { chomp; $_ } <$fd>;
911 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
914 sub git_get_projects_list
{
919 $filter =~ s/\.git$//;
921 if (-d
$projects_list) {
922 # search in directory
923 my $dir = $projects_list . ($filter ?
"/$filter" : '');
924 my $pfxlen = length("$dir");
926 my $check_forks = gitweb_check_feature
('forks');
929 follow_fast
=> 1, # follow symbolic links
930 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
932 # skip project-list toplevel, if we get it.
933 return if (m!^[/.]$!);
934 # only directories can be git repositories
935 return unless (-d
$_);
937 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
938 # we check related file in $projectroot
939 if ($check_forks and $subdir =~ m
#/.#) {
940 $File::Find
::prune
= 1;
941 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
942 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
943 $File::Find
::prune
= 1;
948 } elsif (-f
$projects_list) {
949 # read from file(url-encoded):
950 # 'git%2Fgit.git Linus+Torvalds'
951 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
952 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
953 open my ($fd), $projects_list or return;
954 while (my $line = <$fd>) {
956 my ($path, $owner) = split ' ', $line;
957 $path = unescape
($path);
958 $owner = unescape
($owner);
959 if (!defined $path) {
962 if (check_export_ok
("$projectroot/$path")) {
965 owner
=> to_utf8
($owner),
972 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
976 sub git_get_project_owner
{
980 return undef unless $project;
982 # read from file (url-encoded):
983 # 'git%2Fgit.git Linus+Torvalds'
984 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
985 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
986 if (-f
$projects_list) {
987 open (my $fd , $projects_list);
988 while (my $line = <$fd>) {
990 my ($pr, $ow) = split ' ', $line;
993 if ($pr eq $project) {
994 $owner = to_utf8
($ow);
1000 if (!defined $owner) {
1001 $owner = get_file_owner
("$projectroot/$project");
1007 sub git_get_references
{
1008 my $type = shift || "";
1010 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1011 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1012 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1015 while (my $line = <$fd>) {
1017 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
1018 if (defined $refs{$1}) {
1019 push @
{$refs{$1}}, $2;
1025 close $fd or return;
1029 sub git_get_rev_name_tags
{
1030 my $hash = shift || return undef;
1032 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1034 my $name_rev = <$fd>;
1037 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1040 # catches also '$hash undefined' output
1045 ## ----------------------------------------------------------------------
1046 ## parse to hash functions
1050 my $tz = shift || "-0000";
1053 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1054 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1055 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1056 $date{'hour'} = $hour;
1057 $date{'minute'} = $min;
1058 $date{'mday'} = $mday;
1059 $date{'day'} = $days[$wday];
1060 $date{'month'} = $months[$mon];
1061 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1062 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1063 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1064 $mday, $months[$mon], $hour ,$min;
1066 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1067 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1068 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1069 $date{'hour_local'} = $hour;
1070 $date{'minute_local'} = $min;
1071 $date{'tz_local'} = $tz;
1072 $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
1073 1900+$year, $mon+1, $mday,
1074 $hour, $min, $sec, $tz);
1083 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1084 $tag{'id'} = $tag_id;
1085 while (my $line = <$fd>) {
1087 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1088 $tag{'object'} = $1;
1089 } elsif ($line =~ m/^type (.+)$/) {
1091 } elsif ($line =~ m/^tag (.+)$/) {
1093 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1094 $tag{'author'} = $1;
1097 } elsif ($line =~ m/--BEGIN/) {
1098 push @comment, $line;
1100 } elsif ($line eq "") {
1104 push @comment, <$fd>;
1105 $tag{'comment'} = \
@comment;
1106 close $fd or return;
1107 if (!defined $tag{'name'}) {
1113 sub git_get_last_activity
{
1117 $git_dir = "$projectroot/$path";
1118 open($fd, "-|", git_cmd
(), 'for-each-ref',
1119 '--format=%(refname) %(committer)',
1120 '--sort=-committerdate',
1121 'refs/heads') or return;
1122 my $most_recent = <$fd>;
1123 close $fd or return;
1124 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1126 my $age = time - $timestamp;
1127 return ($age, age_string
($age));
1132 my $commit_id = shift;
1133 my $commit_text = shift;
1138 if (defined $commit_text) {
1139 @commit_lines = @
$commit_text;
1142 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1144 @commit_lines = split '\n', <$fd>;
1145 close $fd or return;
1148 my $header = shift @commit_lines;
1149 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1152 ($co{'id'}, my @parents) = split ' ', $header;
1153 $co{'parents'} = \
@parents;
1154 $co{'parent'} = $parents[0];
1155 while (my $line = shift @commit_lines) {
1156 last if $line eq "\n";
1157 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1159 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1161 $co{'author_epoch'} = $2;
1162 $co{'author_tz'} = $3;
1163 if ($co{'author'} =~ m/^([^<]+) </) {
1164 $co{'author_name'} = $1;
1166 $co{'author_name'} = $co{'author'};
1168 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1169 $co{'committer'} = $1;
1170 $co{'committer_epoch'} = $2;
1171 $co{'committer_tz'} = $3;
1172 $co{'committer_name'} = $co{'committer'};
1173 $co{'committer_name'} =~ s/ <.*//;
1176 if (!defined $co{'tree'}) {
1180 foreach my $title (@commit_lines) {
1183 $co{'title'} = chop_str
($title, 80, 5);
1184 # remove leading stuff of merges to make the interesting part visible
1185 if (length($title) > 50) {
1186 $title =~ s/^Automatic //;
1187 $title =~ s/^merge (of|with) /Merge ... /i;
1188 if (length($title) > 50) {
1189 $title =~ s/(http|rsync):\/\///;
1191 if (length($title) > 50) {
1192 $title =~ s/(master|www|rsync)\.//;
1194 if (length($title) > 50) {
1195 $title =~ s/kernel.org:?//;
1197 if (length($title) > 50) {
1198 $title =~ s/\/pub\/scm//;
1201 $co{'title_short'} = chop_str
($title, 50, 5);
1205 if ($co{'title'} eq "") {
1206 $co{'title'} = $co{'title_short'} = '(no commit message)';
1208 # remove added spaces
1209 foreach my $line (@commit_lines) {
1212 $co{'comment'} = \
@commit_lines;
1214 my $age = time - $co{'committer_epoch'};
1216 $co{'age_string'} = age_string
($age);
1217 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1218 if ($age > 60*60*24*7*2) {
1219 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1220 $co{'age_string_age'} = $co{'age_string'};
1222 $co{'age_string_date'} = $co{'age_string'};
1223 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1228 # parse ref from ref_file, given by ref_id, with given type
1230 my $ref_file = shift;
1232 my $type = shift || git_get_type
($ref_id);
1235 $ref_item{'type'} = $type;
1236 $ref_item{'id'} = $ref_id;
1237 $ref_item{'epoch'} = 0;
1238 $ref_item{'age'} = "unknown";
1239 if ($type eq "tag") {
1240 my %tag = parse_tag
($ref_id);
1241 $ref_item{'comment'} = $tag{'comment'};
1242 if ($tag{'type'} eq "commit") {
1243 my %co = parse_commit
($tag{'object'});
1244 $ref_item{'epoch'} = $co{'committer_epoch'};
1245 $ref_item{'age'} = $co{'age_string'};
1246 } elsif (defined($tag{'epoch'})) {
1247 my $age = time - $tag{'epoch'};
1248 $ref_item{'epoch'} = $tag{'epoch'};
1249 $ref_item{'age'} = age_string
($age);
1251 $ref_item{'reftype'} = $tag{'type'};
1252 $ref_item{'name'} = $tag{'name'};
1253 $ref_item{'refid'} = $tag{'object'};
1254 } elsif ($type eq "commit"){
1255 my %co = parse_commit
($ref_id);
1256 $ref_item{'reftype'} = "commit";
1257 $ref_item{'name'} = $ref_file;
1258 $ref_item{'title'} = $co{'title'};
1259 $ref_item{'refid'} = $ref_id;
1260 $ref_item{'epoch'} = $co{'committer_epoch'};
1261 $ref_item{'age'} = $co{'age_string'};
1263 $ref_item{'reftype'} = $type;
1264 $ref_item{'name'} = $ref_file;
1265 $ref_item{'refid'} = $ref_id;
1271 # parse line of git-diff-tree "raw" output
1272 sub parse_difftree_raw_line
{
1276 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1277 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1278 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1279 $res{'from_mode'} = $1;
1280 $res{'to_mode'} = $2;
1281 $res{'from_id'} = $3;
1283 $res{'status'} = $5;
1284 $res{'similarity'} = $6;
1285 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1286 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1288 $res{'file'} = unquote
($7);
1291 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1292 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1293 $res{'commit'} = $1;
1296 return wantarray ?
%res : \
%res;
1299 # parse line of git-ls-tree output
1300 sub parse_ls_tree_line
($;%) {
1305 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1306 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1314 $res{'name'} = unquote
($4);
1317 return wantarray ?
%res : \
%res;
1320 ## ......................................................................
1321 ## parse to array of hashes functions
1323 sub git_get_refs_list
{
1324 my $type = shift || "";
1329 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1331 while (my $line = <$fd>) {
1333 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1334 if (defined $refs{$1}) {
1335 push @
{$refs{$1}}, $2;
1340 if (! $4) { # unpeeled, direct reference
1341 push @refs, { hash
=> $1, name
=> $3 }; # without type
1342 } elsif ($3 eq $refs[-1]{'name'}) {
1343 # most likely a tag is followed by its peeled
1344 # (deref) one, and when that happens we know the
1345 # previous one was of type 'tag'.
1346 $refs[-1]{'type'} = "tag";
1352 foreach my $ref (@refs) {
1353 my $ref_file = $ref->{'name'};
1354 my $ref_id = $ref->{'hash'};
1356 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1357 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1359 push @reflist, \
%ref_item;
1362 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1363 return (\
@reflist, \
%refs);
1366 ## ----------------------------------------------------------------------
1367 ## filesystem-related functions
1369 sub get_file_owner
{
1372 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1373 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1374 if (!defined $gcos) {
1378 $owner =~ s/[,;].*$//;
1379 return to_utf8
($owner);
1382 ## ......................................................................
1383 ## mimetype related functions
1385 sub mimetype_guess_file
{
1386 my $filename = shift;
1387 my $mimemap = shift;
1388 -r
$mimemap or return undef;
1391 open(MIME
, $mimemap) or return undef;
1393 next if m/^#/; # skip comments
1394 my ($mime, $exts) = split(/\t+/);
1395 if (defined $exts) {
1396 my @exts = split(/\s+/, $exts);
1397 foreach my $ext (@exts) {
1398 $mimemap{$ext} = $mime;
1404 $filename =~ /\.([^.]*)$/;
1405 return $mimemap{$1};
1408 sub mimetype_guess
{
1409 my $filename = shift;
1411 $filename =~ /\./ or return undef;
1413 if ($mimetypes_file) {
1414 my $file = $mimetypes_file;
1415 if ($file !~ m!^/!) { # if it is relative path
1416 # it is relative to project
1417 $file = "$projectroot/$project/$file";
1419 $mime = mimetype_guess_file
($filename, $file);
1421 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1427 my $filename = shift;
1430 my $mime = mimetype_guess
($filename);
1431 $mime and return $mime;
1435 return $default_blob_plain_mimetype unless $fd;
1438 return 'text/plain' .
1439 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1440 } elsif (! $filename) {
1441 return 'application/octet-stream';
1442 } elsif ($filename =~ m/\.png$/i) {
1444 } elsif ($filename =~ m/\.gif$/i) {
1446 } elsif ($filename =~ m/\.jpe?g$/i) {
1447 return 'image/jpeg';
1449 return 'application/octet-stream';
1453 ## ======================================================================
1454 ## functions printing HTML: header, footer, error page
1456 sub git_header_html
{
1457 my $status = shift || "200 OK";
1458 my $expires = shift;
1460 my $title = "$site_name";
1461 if (defined $project) {
1462 $title .= " - $project";
1463 if (defined $action) {
1464 $title .= "/$action";
1465 if (defined $file_name) {
1466 $title .= " - " . esc_html
($file_name);
1467 if ($action eq "tree" && $file_name !~ m
|/$|) {
1474 # require explicit support from the UA if we are to send the page as
1475 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1476 # we have to do this because MSIE sometimes globs '*/*', pretending to
1477 # support xhtml+xml but choking when it gets what it asked for.
1478 if (defined $cgi->http('HTTP_ACCEPT') &&
1479 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1480 $cgi->Accept('application/xhtml+xml') != 0) {
1481 $content_type = 'application/xhtml+xml';
1483 $content_type = 'text/html';
1485 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1486 -status
=> $status, -expires
=> $expires);
1488 <?xml version="1.0" encoding="utf-8"?>
1489 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1490 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1491 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1492 <!-- git core binaries version $git_version -->
1494 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1495 <meta name="generator" content="gitweb/$version git/$git_version"/>
1496 <meta name="robots" content="index, nofollow"/>
1497 <title>$title</title>
1499 # print out each stylesheet that exist
1500 if (defined $stylesheet) {
1501 #provides backwards capability for those people who define style sheet in a config file
1502 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1504 foreach my $stylesheet (@stylesheets) {
1505 next unless $stylesheet;
1506 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1509 if (defined $project) {
1510 printf('<link rel="alternate" title="%s log" '.
1511 'href="%s" type="application/rss+xml"/>'."\n",
1512 esc_param
($project), href
(action
=>"rss"));
1514 printf('<link rel="alternate" title="%s projects list" '.
1515 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1516 $site_name, href
(project
=>undef, action
=>"project_index"));
1517 printf('<link rel="alternate" title="%s projects logs" '.
1518 'href="%s" type="text/x-opml"/>'."\n",
1519 $site_name, href
(project
=>undef, action
=>"opml"));
1521 if (defined $favicon) {
1522 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1528 if (-f
$site_header) {
1529 open (my $fd, $site_header);
1534 print "<div class=\"page_header\">\n" .
1535 $cgi->a({-href
=> esc_url
($logo_url),
1536 -title
=> $logo_label},
1537 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
1538 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1539 if (defined $project) {
1540 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1541 if (defined $action) {
1545 if (!defined $searchtext) {
1549 if (defined $hash_base) {
1550 $search_hash = $hash_base;
1551 } elsif (defined $hash) {
1552 $search_hash = $hash;
1554 $search_hash = "HEAD";
1556 $cgi->param("a", "search");
1557 $cgi->param("h", $search_hash);
1558 $cgi->param("p", $project);
1559 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1560 "<div class=\"search\">\n" .
1561 $cgi->hidden(-name
=> "p") . "\n" .
1562 $cgi->hidden(-name
=> "a") . "\n" .
1563 $cgi->hidden(-name
=> "h") . "\n" .
1564 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1565 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1566 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1568 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1570 $cgi->end_form() . "\n";
1575 sub git_footer_html
{
1576 print "<div class=\"page_footer\">\n";
1577 if (defined $project) {
1578 my $descr = git_get_project_description
($project);
1579 if (defined $descr) {
1580 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1582 print $cgi->a({-href
=> href
(action
=>"rss"),
1583 -class => "rss_logo"}, "RSS") . "\n";
1585 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1586 -class => "rss_logo"}, "OPML") . " ";
1587 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1588 -class => "rss_logo"}, "TXT") . "\n";
1592 if (-f
$site_footer) {
1593 open (my $fd, $site_footer);
1603 my $status = shift || "403 Forbidden";
1604 my $error = shift || "Malformed query, file missing or permission denied";
1606 git_header_html
($status);
1608 <div class="page_body">
1618 ## ----------------------------------------------------------------------
1619 ## functions printing or outputting HTML: navigation
1621 sub git_print_page_nav
{
1622 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1623 $extra = '' if !defined $extra; # pager or formats
1625 my @navs = qw(summary shortlog log commit commitdiff tree);
1627 @navs = grep { $_ ne $suppress } @navs;
1630 my %arg = map { $_ => {action
=>$_} } @navs;
1631 if (defined $head) {
1632 for (qw(commit commitdiff)) {
1633 $arg{$_}{hash
} = $head;
1635 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1636 for (qw(shortlog log)) {
1637 $arg{$_}{hash
} = $head;
1641 $arg{tree
}{hash
} = $treehead if defined $treehead;
1642 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1644 print "<div class=\"page_nav\">\n" .
1646 map { $_ eq $current ?
1647 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1649 print "<br/>\n$extra<br/>\n" .
1653 sub format_paging_nav
{
1654 my ($action, $hash, $head, $page, $nrevs) = @_;
1658 if ($hash ne $head || $page) {
1659 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1661 $paging_nav .= "HEAD";
1665 $paging_nav .= " ⋅ " .
1666 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1667 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1669 $paging_nav .= " ⋅ prev";
1672 if ($nrevs >= (100 * ($page+1)-1)) {
1673 $paging_nav .= " ⋅ " .
1674 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1675 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1677 $paging_nav .= " ⋅ next";
1683 ## ......................................................................
1684 ## functions printing or outputting HTML: div
1686 sub git_print_header_div
{
1687 my ($action, $title, $hash, $hash_base) = @_;
1690 $args{action
} = $action;
1691 $args{hash
} = $hash if $hash;
1692 $args{hash_base
} = $hash_base if $hash_base;
1694 print "<div class=\"header\">\n" .
1695 $cgi->a({-href
=> href
(%args), -class => "title"},
1696 $title ?
$title : $action) .
1700 #sub git_print_authorship (\%) {
1701 sub git_print_authorship
{
1704 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1705 print "<div class=\"author_date\">" .
1706 esc_html
($co->{'author_name'}) .
1708 if ($ad{'hour_local'} < 6) {
1709 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1710 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1712 printf(" (%02d:%02d %s)",
1713 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1718 sub git_print_page_path
{
1724 print "<div class=\"page_path\">";
1725 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1726 -title
=> 'tree root'}, "[$project]");
1728 if (defined $name) {
1729 my @dirname = split '/', $name;
1730 my $basename = pop @dirname;
1733 foreach my $dir (@dirname) {
1734 $fullname .= ($fullname ?
'/' : '') . $dir;
1735 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1737 -title
=> $fullname}, esc_html
($dir));
1740 if (defined $type && $type eq 'blob') {
1741 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1743 -title
=> $name}, esc_html
($basename));
1744 } elsif (defined $type && $type eq 'tree') {
1745 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1747 -title
=> $name}, esc_html
($basename));
1750 print esc_html
($basename);
1753 print "<br/></div>\n";
1756 # sub git_print_log (\@;%) {
1757 sub git_print_log
($;%) {
1761 if ($opts{'-remove_title'}) {
1762 # remove title, i.e. first line of log
1765 # remove leading empty lines
1766 while (defined $log->[0] && $log->[0] eq "") {
1773 foreach my $line (@
$log) {
1774 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1777 if (! $opts{'-remove_signoff'}) {
1778 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1781 # remove signoff lines
1788 # print only one empty line
1789 # do not print empty line after signoff
1791 next if ($empty || $signoff);
1797 print format_log_line_html
($line) . "<br/>\n";
1800 if ($opts{'-final_empty_line'}) {
1801 # end with single empty line
1802 print "<br/>\n" unless $empty;
1806 # print tree entry (row of git_tree), but without encompassing <tr> element
1807 sub git_print_tree_entry
{
1808 my ($t, $basedir, $hash_base, $have_blame) = @_;
1811 $base_key{hash_base
} = $hash_base if defined $hash_base;
1813 # The format of a table row is: mode list link. Where mode is
1814 # the mode of the entry, list is the name of the entry, an href,
1815 # and link is the action links of the entry.
1817 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1818 if ($t->{'type'} eq "blob") {
1819 print "<td class=\"list\">" .
1820 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1821 file_name
=>"$basedir$t->{'name'}", %base_key),
1822 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1823 print "<td class=\"link\">";
1824 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1825 file_name
=>"$basedir$t->{'name'}", %base_key)},
1829 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1830 file_name
=>"$basedir$t->{'name'}", %base_key)},
1833 if (defined $hash_base) {
1835 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1836 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1840 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1841 file_name
=>"$basedir$t->{'name'}")},
1845 } elsif ($t->{'type'} eq "tree") {
1846 print "<td class=\"list\">";
1847 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1848 file_name
=>"$basedir$t->{'name'}", %base_key)},
1849 esc_html
($t->{'name'}));
1851 print "<td class=\"link\">";
1852 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1853 file_name
=>"$basedir$t->{'name'}", %base_key)},
1855 if (defined $hash_base) {
1857 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1858 file_name
=>"$basedir$t->{'name'}")},
1865 ## ......................................................................
1866 ## functions printing large fragments of HTML
1868 sub git_difftree_body
{
1869 my ($difftree, $hash, $parent) = @_;
1871 print "<div class=\"list_head\">\n";
1872 if ($#{$difftree} > 10) {
1873 print(($#{$difftree} + 1) . " files changed:\n");
1877 print "<table class=\"diff_tree\">\n";
1880 foreach my $line (@
{$difftree}) {
1881 my %diff = parse_difftree_raw_line
($line);
1884 print "<tr class=\"dark\">\n";
1886 print "<tr class=\"light\">\n";
1890 my ($to_mode_oct, $to_mode_str, $to_file_type);
1891 my ($from_mode_oct, $from_mode_str, $from_file_type);
1892 if ($diff{'to_mode'} ne ('0' x
6)) {
1893 $to_mode_oct = oct $diff{'to_mode'};
1894 if (S_ISREG
($to_mode_oct)) { # only for regular file
1895 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1897 $to_file_type = file_type
($diff{'to_mode'});
1899 if ($diff{'from_mode'} ne ('0' x
6)) {
1900 $from_mode_oct = oct $diff{'from_mode'};
1901 if (S_ISREG
($to_mode_oct)) { # only for regular file
1902 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1904 $from_file_type = file_type
($diff{'from_mode'});
1907 if ($diff{'status'} eq "A") { # created
1908 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1909 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1910 $mode_chng .= "]</span>";
1912 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1913 hash_base
=>$hash, file_name
=>$diff{'file'}),
1914 -class => "list"}, esc_html
($diff{'file'}));
1916 print "<td>$mode_chng</td>\n";
1917 print "<td class=\"link\">";
1918 if ($action eq 'commitdiff') {
1921 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1925 } elsif ($diff{'status'} eq "D") { # deleted
1926 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1928 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1929 hash_base
=>$parent, file_name
=>$diff{'file'}),
1930 -class => "list"}, esc_html
($diff{'file'}));
1932 print "<td>$mode_chng</td>\n";
1933 print "<td class=\"link\">";
1934 if ($action eq 'commitdiff') {
1937 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1940 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1941 hash_base
=>$parent, file_name
=>$diff{'file'})},
1943 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1944 file_name
=>$diff{'file'})},
1946 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1947 file_name
=>$diff{'file'})},
1951 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1952 my $mode_chnge = "";
1953 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1954 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1955 if ($from_file_type != $to_file_type) {
1956 $mode_chnge .= " from $from_file_type to $to_file_type";
1958 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1959 if ($from_mode_str && $to_mode_str) {
1960 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1961 } elsif ($to_mode_str) {
1962 $mode_chnge .= " mode: $to_mode_str";
1965 $mode_chnge .= "]</span>\n";
1968 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1969 hash_base
=>$hash, file_name
=>$diff{'file'}),
1970 -class => "list"}, esc_html
($diff{'file'}));
1972 print "<td>$mode_chnge</td>\n";
1973 print "<td class=\"link\">";
1974 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1975 if ($action eq 'commitdiff') {
1978 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1980 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1981 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1982 hash_base
=>$hash, hash_parent_base
=>$parent,
1983 file_name
=>$diff{'file'})},
1988 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1989 hash_base
=>$hash, file_name
=>$diff{'file'})},
1991 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1992 file_name
=>$diff{'file'})},
1994 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1995 file_name
=>$diff{'file'})},
1999 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2000 my %status_name = ('R' => 'moved', 'C' => 'copied');
2001 my $nstatus = $status_name{$diff{'status'}};
2003 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2004 # mode also for directories, so we cannot use $to_mode_str
2005 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2008 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2009 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2010 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
2011 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2012 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2013 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2014 -class => "list"}, esc_html
($diff{'from_file'})) .
2015 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2016 "<td class=\"link\">";
2017 if ($diff{'to_id'} ne $diff{'from_id'}) {
2018 if ($action eq 'commitdiff') {
2021 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2023 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2024 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2025 hash_base
=>$hash, hash_parent_base
=>$parent,
2026 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2031 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2032 hash_base
=>$parent, file_name
=>$diff{'from_file'})},
2034 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2035 file_name
=>$diff{'from_file'})},
2037 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2038 file_name
=>$diff{'from_file'})},
2042 } # we should not encounter Unmerged (U) or Unknown (X) status
2048 sub git_patchset_body
{
2049 my ($fd, $difftree, $hash, $hash_parent) = @_;
2053 my $patch_found = 0;
2056 print "<div class=\"patchset\">\n";
2059 while (my $patch_line = <$fd>) {
2062 if ($patch_line =~ m/^diff /) { # "git diff" header
2063 # beginning of patch (in patchset)
2065 # close previous patch
2066 print "</div>\n"; # class="patch"
2068 # first patch in patchset
2071 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2073 if (ref($difftree->[$patch_idx]) eq "HASH") {
2074 $diffinfo = $difftree->[$patch_idx];
2076 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2080 # for now, no extended header, hence we skip empty patches
2081 # companion to next LINE if $in_header;
2082 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
2087 if ($diffinfo->{'status'} eq "A") { # added
2088 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
2089 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2090 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2091 $diffinfo->{'to_id'}) . " (new)" .
2092 "</div>\n"; # class="diff_info"
2094 } elsif ($diffinfo->{'status'} eq "D") { # deleted
2095 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
2096 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2097 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2098 $diffinfo->{'from_id'}) . " (deleted)" .
2099 "</div>\n"; # class="diff_info"
2101 } elsif ($diffinfo->{'status'} eq "R" || # renamed
2102 $diffinfo->{'status'} eq "C" || # copied
2103 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
2104 print "<div class=\"diff_info\">" .
2105 file_type
($diffinfo->{'from_mode'}) . ":" .
2106 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2107 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
2108 $diffinfo->{'from_id'}) .
2110 file_type
($diffinfo->{'to_mode'}) . ":" .
2111 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2112 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
2113 $diffinfo->{'to_id'});
2114 print "</div>\n"; # class="diff_info"
2116 } else { # modified, mode changed, ...
2117 print "<div class=\"diff_info\">" .
2118 file_type
($diffinfo->{'from_mode'}) . ":" .
2119 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2120 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2121 $diffinfo->{'from_id'}) .
2123 file_type
($diffinfo->{'to_mode'}) . ":" .
2124 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2125 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2126 $diffinfo->{'to_id'});
2127 print "</div>\n"; # class="diff_info"
2130 #print "<div class=\"diff extended_header\">\n";
2133 } # start of patch in patchset
2136 if ($in_header && $patch_line =~ m/^---/) {
2137 #print "</div>\n"; # class="diff extended_header"
2140 my $file = $diffinfo->{'from_file'};
2141 $file ||= $diffinfo->{'file'};
2142 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2143 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2144 -class => "list"}, esc_html
($file));
2145 $patch_line =~ s
|a
/.*$|a/$file|g
;
2146 print "<div class=\"diff from_file\">$patch_line</div>\n";
2148 $patch_line = <$fd>;
2151 #$patch_line =~ m/^+++/;
2152 $file = $diffinfo->{'to_file'};
2153 $file ||= $diffinfo->{'file'};
2154 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2155 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2156 -class => "list"}, esc_html
($file));
2157 $patch_line =~ s
|b
/.*|b/$file|g
;
2158 print "<div class=\"diff to_file\">$patch_line</div>\n";
2162 next LINE
if $in_header;
2164 print format_diff_line
($patch_line);
2166 print "</div>\n" if $patch_found; # class="patch"
2168 print "</div>\n"; # class="patchset"
2171 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2173 sub git_project_list_body
{
2174 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2176 my $check_forks = gitweb_check_feature
('forks');
2179 foreach my $pr (@
$projlist) {
2180 my (@aa) = git_get_last_activity
($pr->{'path'});
2184 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2185 if (!defined $pr->{'descr'}) {
2186 my $descr = git_get_project_description
($pr->{'path'}) || "";
2187 $pr->{'descr'} = chop_str
($descr, 25, 5);
2189 if (!defined $pr->{'owner'}) {
2190 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2193 my $pname = $pr->{'path'};
2194 $pname =~ s/\.git$//;
2195 $pr->{'forks'} = -d
"$projectroot/$pname";
2197 push @projects, $pr;
2200 $order ||= "project";
2201 $from = 0 unless defined $from;
2202 $to = $#projects if (!defined $to || $#projects < $to);
2204 print "<table class=\"project_list\">\n";
2205 unless ($no_header) {
2208 print "<th></th>\n";
2210 if ($order eq "project") {
2211 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2212 print "<th>Project</th>\n";
2215 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2216 -class => "header"}, "Project") .
2219 if ($order eq "descr") {
2220 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2221 print "<th>Description</th>\n";
2224 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2225 -class => "header"}, "Description") .
2228 if ($order eq "owner") {
2229 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2230 print "<th>Owner</th>\n";
2233 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2234 -class => "header"}, "Owner") .
2237 if ($order eq "age") {
2238 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2239 print "<th>Last Change</th>\n";
2242 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2243 -class => "header"}, "Last Change") .
2246 print "<th></th>\n" .
2250 for (my $i = $from; $i <= $to; $i++) {
2251 my $pr = $projects[$i];
2253 print "<tr class=\"dark\">\n";
2255 print "<tr class=\"light\">\n";
2260 if ($pr->{'forks'}) {
2261 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2265 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2266 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2267 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2268 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2269 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2270 $pr->{'age_string'} . "</td>\n" .
2271 "<td class=\"link\">" .
2272 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2273 $cgi->a({-href
=> '/git-browser/by-commit.html?r='.$pr->{'path'}}, "graphiclog") . " | " .
2274 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2275 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2276 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2280 if (defined $extra) {
2283 print "<td></td>\n";
2285 print "<td colspan=\"5\">$extra</td>\n" .
2291 sub git_shortlog_body
{
2292 # uses global variable $project
2293 my ($revlist, $from, $to, $refs, $extra) = @_;
2295 $from = 0 unless defined $from;
2296 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2298 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2300 for (my $i = $from; $i <= $to; $i++) {
2301 my $commit = $revlist->[$i];
2302 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2303 my $ref = format_ref_marker
($refs, $commit);
2304 my %co = parse_commit
($commit);
2306 print "<tr class=\"dark\">\n";
2308 print "<tr class=\"light\">\n";
2311 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2312 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2313 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2315 print format_subject_html
($co{'title'}, $co{'title_short'},
2316 href
(action
=>"commit", hash
=>$commit), $ref);
2318 "<td class=\"link\">" .
2319 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2320 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2321 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2322 if (gitweb_have_snapshot
()) {
2323 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2328 if (defined $extra) {
2330 "<td colspan=\"4\">$extra</td>\n" .
2336 sub git_history_body
{
2337 # Warning: assumes constant type (blob or tree) during history
2338 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2340 $from = 0 unless defined $from;
2341 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2343 print "<table class=\"history\" cellspacing=\"0\">\n";
2345 for (my $i = $from; $i <= $to; $i++) {
2346 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2351 my %co = parse_commit
($commit);
2356 my $ref = format_ref_marker
($refs, $commit);
2359 print "<tr class=\"dark\">\n";
2361 print "<tr class=\"light\">\n";
2364 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2365 # shortlog uses chop_str($co{'author_name'}, 10)
2366 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2368 # originally git_history used chop_str($co{'title'}, 50)
2369 print format_subject_html
($co{'title'}, $co{'title_short'},
2370 href
(action
=>"commit", hash
=>$commit), $ref);
2372 "<td class=\"link\">" .
2373 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2374 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2376 if ($ftype eq 'blob') {
2377 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2378 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2379 if (defined $blob_current && defined $blob_parent &&
2380 $blob_current ne $blob_parent) {
2382 $cgi->a({-href
=> href
(action
=>"blobdiff",
2383 hash
=>$blob_current, hash_parent
=>$blob_parent,
2384 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2385 file_name
=>$file_name)},
2392 if (defined $extra) {
2394 "<td colspan=\"4\">$extra</td>\n" .
2401 # uses global variable $project
2402 my ($taglist, $from, $to, $extra) = @_;
2403 $from = 0 unless defined $from;
2404 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2406 print "<table class=\"tags\" cellspacing=\"0\">\n";
2408 for (my $i = $from; $i <= $to; $i++) {
2409 my $entry = $taglist->[$i];
2411 my $comment_lines = $tag{'comment'};
2412 my $comment = shift @
$comment_lines;
2414 if (defined $comment) {
2415 $comment_short = chop_str
($comment, 30, 5);
2418 print "<tr class=\"dark\">\n";
2420 print "<tr class=\"light\">\n";
2423 print "<td><i>$tag{'age'}</i></td>\n" .
2425 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2426 -class => "list name"}, esc_html
($tag{'name'})) .
2429 if (defined $comment) {
2430 print format_subject_html
($comment, $comment_short,
2431 href
(action
=>"tag", hash
=>$tag{'id'}));
2434 "<td class=\"selflink\">";
2435 if ($tag{'type'} eq "tag") {
2436 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2441 "<td class=\"link\">" . " | " .
2442 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2443 if ($tag{'reftype'} eq "commit") {
2444 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2445 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2446 } elsif ($tag{'reftype'} eq "blob") {
2447 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2452 if (defined $extra) {
2454 "<td colspan=\"5\">$extra</td>\n" .
2460 sub git_heads_body
{
2461 # uses global variable $project
2462 my ($headlist, $head, $from, $to, $extra) = @_;
2463 $from = 0 unless defined $from;
2464 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2466 print "<table class=\"heads\" cellspacing=\"0\">\n";
2468 for (my $i = $from; $i <= $to; $i++) {
2469 my $entry = $headlist->[$i];
2471 my $curr = $tag{'id'} eq $head;
2473 print "<tr class=\"dark\">\n";
2475 print "<tr class=\"light\">\n";
2478 print "<td><i>$tag{'age'}</i></td>\n" .
2479 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
2480 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2481 -class => "list name"},esc_html
($tag{'name'})) .
2483 "<td class=\"link\">" .
2484 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2485 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2486 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2490 if (defined $extra) {
2492 "<td colspan=\"3\">$extra</td>\n" .
2498 ## ======================================================================
2499 ## ======================================================================
2502 sub git_project_list
{
2503 my $order = $cgi->param('o');
2504 if (defined $order && $order !~ m/project|descr|owner|age/) {
2505 die_error
(undef, "Unknown order parameter");
2508 my @list = git_get_projects_list
();
2510 die_error
(undef, "No projects found");
2514 if (-f
$home_text) {
2515 print "<div class=\"index_include\">\n";
2516 open (my $fd, $home_text);
2521 git_project_list_body
(\
@list, $order);
2526 my $order = $cgi->param('o');
2527 if (defined $order && $order !~ m/project|descr|owner|age/) {
2528 die_error
(undef, "Unknown order parameter");
2531 my @list = git_get_projects_list
($project);
2533 die_error
(undef, "No forks found");
2537 git_print_page_nav
('','');
2538 git_print_header_div
('summary', "$project forks");
2539 git_project_list_body
(\
@list, $order);
2543 sub git_project_index
{
2544 my @projects = git_get_projects_list
($project);
2547 -type
=> 'text/plain',
2548 -charset
=> 'utf-8',
2549 -content_disposition
=> 'inline; filename="index.aux"');
2551 foreach my $pr (@projects) {
2552 if (!exists $pr->{'owner'}) {
2553 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2556 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2557 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2558 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2559 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2563 print "$path $owner\n";
2568 my $descr = git_get_project_description
($project) || "none";
2569 my $head = git_get_head_hash
($project);
2570 my %co = parse_commit
($head);
2571 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2573 my $owner = git_get_project_owner
($project);
2575 my ($reflist, $refs) = git_get_refs_list
();
2579 foreach my $ref (@
$reflist) {
2580 if ($ref->{'name'} =~ s!^heads/!!) {
2581 push @headlist, $ref;
2583 $ref->{'name'} =~ s!^tags/!!;
2584 push @taglist, $ref;
2588 if (gitweb_check_feature
('forks')) {
2589 @forklist = git_get_projects_list
($project);
2593 git_print_page_nav
('summary','', $head);
2595 print "<div class=\"title\"> </div>\n";
2596 print "<table cellspacing=\"0\">\n" .
2597 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2598 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2599 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2600 # use per project git URL list in $projectroot/$project/cloneurl
2601 # or make project git URL from git base URL and project name
2602 my $url_tag = "URL";
2603 my @url_list = git_get_project_url_list
($project);
2604 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2605 foreach my $git_url (@url_list) {
2606 next unless $git_url;
2607 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2612 if (-s
"$projectroot/$project/README.html") {
2613 if (open my $fd, "$projectroot/$project/README.html") {
2614 print "<div class=\"title\">readme</div>\n";
2615 print $_ while (<$fd>);
2620 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2621 git_get_head_hash
($project)
2622 or die_error
(undef, "Open git-rev-list failed");
2623 my @revlist = map { chomp; $_ } <$fd>;
2625 git_print_header_div
('shortlog');
2626 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2627 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2630 git_print_header_div
('tags');
2631 git_tags_body
(\
@taglist, 0, 15,
2632 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2636 git_print_header_div
('heads');
2637 git_heads_body
(\
@headlist, $head, 0, 15,
2638 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2642 git_print_header_div
('forks');
2643 git_project_list_body
(\
@forklist, undef, 0, 15,
2644 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
2652 my $head = git_get_head_hash
($project);
2654 git_print_page_nav
('','', $head,undef,$head);
2655 my %tag = parse_tag
($hash);
2656 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2657 print "<div class=\"title_text\">\n" .
2658 "<table cellspacing=\"0\">\n" .
2660 "<td>object</td>\n" .
2661 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2662 $tag{'object'}) . "</td>\n" .
2663 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2664 $tag{'type'}) . "</td>\n" .
2666 if (defined($tag{'author'})) {
2667 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2668 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2669 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2670 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2673 print "</table>\n\n" .
2675 print "<div class=\"page_body\">";
2676 my $comment = $tag{'comment'};
2677 foreach my $line (@
$comment) {
2678 print esc_html
($line) . "<br/>\n";
2688 my ($have_blame) = gitweb_check_feature
('blame');
2690 die_error
('403 Permission denied', "Permission denied");
2692 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2693 $hash_base ||= git_get_head_hash
($project);
2694 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2695 my %co = parse_commit
($hash_base)
2696 or die_error
(undef, "Reading commit failed");
2697 if (!defined $hash) {
2698 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2699 or die_error
(undef, "Error looking up file");
2701 $ftype = git_get_type
($hash);
2702 if ($ftype !~ "blob") {
2703 die_error
("400 Bad Request", "Object is not a blob");
2705 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
2706 $file_name, $hash_base)
2707 or die_error
(undef, "Open git-blame failed");
2710 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2713 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2716 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2718 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2719 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2720 git_print_page_path
($file_name, $ftype, $hash_base);
2721 my @rev_color = (qw(light2 dark2));
2722 my $num_colors = scalar(@rev_color);
2723 my $current_color = 0;
2726 <div class="page_body">
2727 <table class="blame">
2728 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2733 last unless defined $_;
2734 my ($full_rev, $orig_lineno, $lineno, $group_size) =
2735 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2736 if (!exists $metainfo{$full_rev}) {
2737 $metainfo{$full_rev} = {};
2739 my $meta = $metainfo{$full_rev};
2742 if (/^(\S+) (.*)$/) {
2747 my $rev = substr($full_rev, 0, 8);
2748 my $author = $meta->{'author'};
2749 my %date = parse_date
($meta->{'author-time'},
2750 $meta->{'author-tz'});
2751 my $date = $date{'iso-tz'};
2753 $current_color = ++$current_color % $num_colors;
2755 print "<tr class=\"$rev_color[$current_color]\">\n";
2757 print "<td class=\"sha1\"";
2758 print " title=\"$author, $date\"";
2759 print " rowspan=\"$group_size\"" if ($group_size > 1);
2761 print $cgi->a({-href
=> href
(action
=>"commit",
2763 file_name
=>$file_name)},
2767 my $blamed = href
(action
=> 'blame',
2768 file_name
=> $meta->{'filename'},
2769 hash_base
=> $full_rev);
2770 print "<td class=\"linenr\">";
2771 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
2773 -class => "linenr" },
2776 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2782 or print "Reading blob failed\n";
2789 my ($have_blame) = gitweb_check_feature
('blame');
2791 die_error
('403 Permission denied', "Permission denied");
2793 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2794 $hash_base ||= git_get_head_hash
($project);
2795 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2796 my %co = parse_commit
($hash_base)
2797 or die_error
(undef, "Reading commit failed");
2798 if (!defined $hash) {
2799 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2800 or die_error
(undef, "Error lookup file");
2802 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2803 or die_error
(undef, "Open git-annotate failed");
2806 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2809 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2812 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2814 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2815 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2816 git_print_page_path
($file_name, 'blob', $hash_base);
2817 print "<div class=\"page_body\">\n";
2819 <table class="blame">
2828 my @line_class = (qw(light dark));
2829 my $line_class_len = scalar (@line_class);
2830 my $line_class_num = $#line_class;
2831 while (my $line = <$fd>) {
2843 $line_class_num = ($line_class_num + 1) % $line_class_len;
2845 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2852 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2855 $short_rev = substr ($long_rev, 0, 8);
2856 $age = time () - $time;
2857 $age_str = age_string
($age);
2858 $age_str =~ s/ / /g;
2859 $age_class = age_class
($age);
2860 $author = esc_html
($author);
2861 $author =~ s/ / /g;
2863 $data = untabify
($data);
2864 $data = esc_html
($data);
2867 <tr class="$line_class[$line_class_num]">
2868 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2869 <td class="$age_class">$age_str</td>
2871 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2872 <td class="pre">$data</td>
2875 } # while (my $line = <$fd>)
2876 print "</table>\n\n";
2878 or print "Reading blob failed.\n";
2884 my $head = git_get_head_hash
($project);
2886 git_print_page_nav
('','', $head,undef,$head);
2887 git_print_header_div
('summary', $project);
2889 my ($taglist) = git_get_refs_list
("tags");
2891 git_tags_body
($taglist);
2897 my $head = git_get_head_hash
($project);
2899 git_print_page_nav
('','', $head,undef,$head);
2900 git_print_header_div
('summary', $project);
2902 my ($headlist) = git_get_refs_list
("heads");
2904 git_heads_body
($headlist, $head);
2909 sub git_blob_plain
{
2912 if (!defined $hash) {
2913 if (defined $file_name) {
2914 my $base = $hash_base || git_get_head_hash
($project);
2915 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2916 or die_error
(undef, "Error lookup file");
2918 die_error
(undef, "No file name defined");
2920 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2921 # blobs defined by non-textual hash id's can be cached
2926 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2927 or die_error
(undef, "Couldn't cat $file_name, $hash");
2929 $type ||= blob_mimetype
($fd, $file_name);
2931 # save as filename, even when no $file_name is given
2932 my $save_as = "$hash";
2933 if (defined $file_name) {
2934 $save_as = $file_name;
2935 } elsif ($type =~ m/^text\//) {
2942 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2944 binmode STDOUT
, ':raw';
2946 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2954 if (!defined $hash) {
2955 if (defined $file_name) {
2956 my $base = $hash_base || git_get_head_hash
($project);
2957 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2958 or die_error
(undef, "Error lookup file");
2960 die_error
(undef, "No file name defined");
2962 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2963 # blobs defined by non-textual hash id's can be cached
2967 my ($have_blame) = gitweb_check_feature
('blame');
2968 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2969 or die_error
(undef, "Couldn't cat $file_name, $hash");
2970 my $mimetype = blob_mimetype
($fd, $file_name);
2971 if ($mimetype !~ m/^text\//) {
2973 return git_blob_plain
($mimetype);
2975 git_header_html
(undef, $expires);
2976 my $formats_nav = '';
2977 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2978 if (defined $file_name) {
2981 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2982 hash
=>$hash, file_name
=>$file_name)},
2987 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2988 hash
=>$hash, file_name
=>$file_name)},
2991 $cgi->a({-href
=> href
(action
=>"blob_plain",
2992 hash
=>$hash, file_name
=>$file_name)},
2995 $cgi->a({-href
=> href
(action
=>"blob",
2996 hash_base
=>"HEAD", file_name
=>$file_name)},
3000 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3002 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3003 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3005 print "<div class=\"page_nav\">\n" .
3006 "<br/><br/></div>\n" .
3007 "<div class=\"title\">$hash</div>\n";
3009 git_print_page_path
($file_name, "blob", $hash_base);
3010 print "<div class=\"page_body\">\n";
3012 while (my $line = <$fd>) {
3015 $line = untabify
($line);
3016 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3017 $nr, $nr, $nr, esc_html
($line);
3020 or print "Reading blob failed.\n";
3026 my $have_snapshot = gitweb_have_snapshot
();
3028 if (!defined $hash_base) {
3029 $hash_base = "HEAD";
3031 if (!defined $hash) {
3032 if (defined $file_name) {
3033 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3039 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3040 or die_error
(undef, "Open git-ls-tree failed");
3041 my @entries = map { chomp; $_ } <$fd>;
3042 close $fd or die_error
(undef, "Reading tree failed");
3045 my $refs = git_get_references
();
3046 my $ref = format_ref_marker
($refs, $hash_base);
3049 my ($have_blame) = gitweb_check_feature
('blame');
3050 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3052 if (defined $file_name) {
3054 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3055 hash
=>$hash, file_name
=>$file_name)},
3057 $cgi->a({-href
=> href
(action
=>"tree",
3058 hash_base
=>"HEAD", file_name
=>$file_name)},
3061 if ($have_snapshot) {
3062 # FIXME: Should be available when we have no hash base as well.
3064 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3067 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3068 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3071 print "<div class=\"page_nav\">\n";
3072 print "<br/><br/></div>\n";
3073 print "<div class=\"title\">$hash</div>\n";
3075 if (defined $file_name) {
3076 $basedir = $file_name;
3077 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3081 git_print_page_path
($file_name, 'tree', $hash_base);
3082 print "<div class=\"page_body\">\n";
3083 print "<table cellspacing=\"0\">\n";
3085 # '..' (top directory) link if possible
3086 if (defined $hash_base &&
3087 defined $file_name && $file_name =~ m![^/]+$!) {
3089 print "<tr class=\"dark\">\n";
3091 print "<tr class=\"light\">\n";
3095 my $up = $file_name;
3096 $up =~ s!/?[^/]+$!!;
3097 undef $up unless $up;
3098 # based on git_print_tree_entry
3099 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3100 print '<td class="list">';
3101 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3105 print "<td class=\"link\"></td>\n";
3109 foreach my $line (@entries) {
3110 my %t = parse_ls_tree_line
($line, -z
=> 1);
3113 print "<tr class=\"dark\">\n";
3115 print "<tr class=\"light\">\n";
3119 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3123 print "</table>\n" .
3129 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3130 my $have_snapshot = (defined $ctype && defined $suffix);
3131 if (!$have_snapshot) {
3132 die_error
('403 Permission denied', "Permission denied");
3135 if (!defined $hash) {
3136 $hash = git_get_head_hash
($project);
3139 my $filename = basename
($project) . "-$hash.tar.$suffix";
3142 -type
=> 'application/x-tar',
3143 -content_encoding
=> $ctype,
3144 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3145 -status
=> '200 OK');
3147 my $git = git_cmd_str
();
3148 my $name = $project;
3149 $name =~ s/\047/\047\\\047\047/g;
3151 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3152 or die_error
(undef, "Execute git-tar-tree failed.");
3153 binmode STDOUT
, ':raw';
3155 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3161 my $head = git_get_head_hash
($project);
3162 if (!defined $hash) {
3165 if (!defined $page) {
3168 my $refs = git_get_references
();
3170 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3171 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3172 or die_error
(undef, "Open git-rev-list failed");
3173 my @revlist = map { chomp; $_ } <$fd>;
3176 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3179 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3182 my %co = parse_commit
($hash);
3184 git_print_header_div
('summary', $project);
3185 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3187 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3188 my $commit = $revlist[$i];
3189 my $ref = format_ref_marker
($refs, $commit);
3190 my %co = parse_commit
($commit);
3192 my %ad = parse_date
($co{'author_epoch'});
3193 git_print_header_div
('commit',
3194 "<span class=\"age\">$co{'age_string'}</span>" .
3195 esc_html
($co{'title'}) . $ref,
3197 print "<div class=\"title_text\">\n" .
3198 "<div class=\"log_link\">\n" .
3199 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3201 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3203 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3206 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3209 print "<div class=\"log_body\">\n";
3210 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3217 my %co = parse_commit
($hash);
3219 die_error
(undef, "Unknown commit object");
3221 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3222 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3224 my $parent = $co{'parent'};
3225 if (!defined $parent) {
3228 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
3229 or die_error
(undef, "Open git-diff-tree failed");
3230 my @difftree = map { chomp; $_ } <$fd>;
3231 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3233 # filter out commit ID output
3234 @difftree = grep(!/^[0-9a-fA-F]{40}$/, @difftree);
3236 # non-textual hash id's can be cached
3238 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3241 my $refs = git_get_references
();
3242 my $ref = format_ref_marker
($refs, $co{'id'});
3244 my $have_snapshot = gitweb_have_snapshot
();
3247 if (defined $file_name && defined $co{'parent'}) {
3249 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3252 git_header_html
(undef, $expires);
3253 git_print_page_nav
('commit', '',
3254 $hash, $co{'tree'}, $hash,
3255 join (' | ', @views_nav));
3257 if (defined $co{'parent'}) {
3258 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3260 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3262 print "<div class=\"title_text\">\n" .
3263 "<table cellspacing=\"0\">\n";
3264 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3266 "<td></td><td> $ad{'rfc2822'}";
3267 if ($ad{'hour_local'} < 6) {
3268 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3269 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3271 printf(" (%02d:%02d %s)",
3272 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3276 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3277 print "<tr><td></td><td> $cd{'rfc2822'}" .
3278 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3280 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3283 "<td class=\"sha1\">" .
3284 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3285 class => "list"}, $co{'tree'}) .
3287 "<td class=\"link\">" .
3288 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3290 if ($have_snapshot) {
3292 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3296 my $parents = $co{'parents'};
3297 foreach my $par (@
$parents) {
3300 "<td class=\"sha1\">" .
3301 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3302 class => "list"}, $par) .
3304 "<td class=\"link\">" .
3305 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3307 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3314 print "<div class=\"page_body\">\n";
3315 git_print_log
($co{'comment'});
3318 git_difftree_body
(\
@difftree, $hash, $parent);
3324 my $format = shift || 'html';
3331 # preparing $fd and %diffinfo for git_patchset_body
3333 if (defined $hash_base && defined $hash_parent_base) {
3334 if (defined $file_name) {
3336 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3338 or die_error
(undef, "Open git-diff-tree failed");
3339 @difftree = map { chomp; $_ } <$fd>;
3341 or die_error
(undef, "Reading git-diff-tree failed");
3343 or die_error
('404 Not Found', "Blob diff not found");
3345 } elsif (defined $hash &&
3346 $hash =~ /[0-9a-fA-F]{40}/) {
3347 # try to find filename from $hash
3349 # read filtered raw output
3350 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3351 or die_error
(undef, "Open git-diff-tree failed");
3353 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3355 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3356 map { chomp; $_ } <$fd>;
3358 or die_error
(undef, "Reading git-diff-tree failed");
3360 or die_error
('404 Not Found', "Blob diff not found");
3363 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3366 if (@difftree > 1) {
3367 die_error
('404 Not Found', "Ambiguous blob diff specification");
3370 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3371 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3372 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3374 $hash_parent ||= $diffinfo{'from_id'};
3375 $hash ||= $diffinfo{'to_id'};
3377 # non-textual hash id's can be cached
3378 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3379 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3384 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3385 '-p', $hash_parent_base, $hash_base,
3387 or die_error
(undef, "Open git-diff-tree failed");
3390 # old/legacy style URI
3391 if (!%diffinfo && # if new style URI failed
3392 defined $hash && defined $hash_parent) {
3393 # fake git-diff-tree raw output
3394 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3395 $diffinfo{'from_id'} = $hash_parent;
3396 $diffinfo{'to_id'} = $hash;
3397 if (defined $file_name) {
3398 if (defined $file_parent) {
3399 $diffinfo{'status'} = '2';
3400 $diffinfo{'from_file'} = $file_parent;
3401 $diffinfo{'to_file'} = $file_name;
3402 } else { # assume not renamed
3403 $diffinfo{'status'} = '1';
3404 $diffinfo{'from_file'} = $file_name;
3405 $diffinfo{'to_file'} = $file_name;
3407 } else { # no filename given
3408 $diffinfo{'status'} = '2';
3409 $diffinfo{'from_file'} = $hash_parent;
3410 $diffinfo{'to_file'} = $hash;
3413 # non-textual hash id's can be cached
3414 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3415 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3420 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3421 or die_error
(undef, "Open git-diff failed");
3423 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3428 if ($format eq 'html') {
3430 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3431 hash
=>$hash, hash_parent
=>$hash_parent,
3432 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3433 file_name
=>$file_name, file_parent
=>$file_parent)},
3435 git_header_html
(undef, $expires);
3436 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3437 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3438 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3440 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3441 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3443 if (defined $file_name) {
3444 git_print_page_path
($file_name, "blob", $hash_base);
3446 print "<div class=\"page_path\"></div>\n";
3449 } elsif ($format eq 'plain') {
3451 -type
=> 'text/plain',
3452 -charset
=> 'utf-8',
3453 -expires
=> $expires,
3454 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3456 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3459 die_error
(undef, "Unknown blobdiff format");
3463 if ($format eq 'html') {
3464 print "<div class=\"page_body\">\n";
3466 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3469 print "</div>\n"; # class="page_body"
3473 while (my $line = <$fd>) {
3474 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3475 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3479 last if $line =~ m!^\+\+\+!;
3487 sub git_blobdiff_plain
{
3488 git_blobdiff
('plain');
3491 sub git_commitdiff
{
3492 my $format = shift || 'html';
3493 my %co = parse_commit
($hash);
3495 die_error
(undef, "Unknown commit object");
3497 if (!defined $hash_parent) {
3498 $hash_parent = $co{'parent'} || '--root';
3504 if ($format eq 'html') {
3505 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3506 "--patch-with-raw", "--full-index", $hash_parent, $hash
3507 or die_error
(undef, "Open git-diff-tree failed");
3509 while (chomp(my $line = <$fd>)) {
3510 # empty line ends raw part of diff-tree output
3512 # filter out commit ID output
3513 push @difftree, $line
3514 unless $line =~ m/^[0-9a-fA-F]{40}$/;
3517 } elsif ($format eq 'plain') {
3518 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3519 '-p', $hash_parent, $hash
3520 or die_error
(undef, "Open git-diff-tree failed");
3523 die_error
(undef, "Unknown commitdiff format");
3526 # non-textual hash id's can be cached
3528 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3532 # write commit message
3533 if ($format eq 'html') {
3534 my $refs = git_get_references
();
3535 my $ref = format_ref_marker
($refs, $co{'id'});
3537 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3538 hash
=>$hash, hash_parent
=>$hash_parent)},
3541 git_header_html
(undef, $expires);
3542 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3543 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3544 git_print_authorship
(\
%co);
3545 print "<div class=\"page_body\">\n";
3546 if (@
{$co{'comment'}} > 1) {
3547 print "<div class=\"log\">\n";
3548 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
3549 print "</div>\n"; # class="log"
3552 } elsif ($format eq 'plain') {
3553 my $refs = git_get_references
("tags");
3554 my $tagname = git_get_rev_name_tags
($hash);
3555 my $filename = basename
($project) . "-$hash.patch";
3558 -type
=> 'text/plain',
3559 -charset
=> 'utf-8',
3560 -expires
=> $expires,
3561 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3562 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3565 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3566 Subject: $co{'title'}
3568 print "X-Git-Tag: $tagname\n" if $tagname;
3569 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3571 foreach my $line (@
{$co{'comment'}}) {
3578 if ($format eq 'html') {
3579 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3582 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3584 print "</div>\n"; # class="page_body"
3587 } elsif ($format eq 'plain') {
3591 or print "Reading git-diff-tree failed\n";
3595 sub git_commitdiff_plain
{
3596 git_commitdiff
('plain');
3600 if (!defined $hash_base) {
3601 $hash_base = git_get_head_hash
($project);
3603 if (!defined $page) {
3607 my %co = parse_commit
($hash_base);
3609 die_error
(undef, "Unknown commit object");
3612 my $refs = git_get_references
();
3613 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3615 if (!defined $hash && defined $file_name) {
3616 $hash = git_get_hash_by_path
($hash_base, $file_name);
3618 if (defined $hash) {
3619 $ftype = git_get_type
($hash);
3623 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3624 or die_error
(undef, "Open git-rev-list-failed");
3625 my @revlist = map { chomp; $_ } <$fd>;
3627 or die_error
(undef, "Reading git-rev-list failed");
3629 my $paging_nav = '';
3632 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3633 file_name
=>$file_name)},
3635 $paging_nav .= " ⋅ " .
3636 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3637 file_name
=>$file_name, page
=>$page-1),
3638 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3640 $paging_nav .= "first";
3641 $paging_nav .= " ⋅ prev";
3643 if ($#revlist >= (100 * ($page+1)-1)) {
3644 $paging_nav .= " ⋅ " .
3645 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3646 file_name
=>$file_name, page
=>$page+1),
3647 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3649 $paging_nav .= " ⋅ next";
3652 if ($#revlist >= (100 * ($page+1)-1)) {
3654 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3655 file_name
=>$file_name, page
=>$page+1),
3656 -title
=> "Alt-n"}, "next");
3660 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3661 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3662 git_print_page_path
($file_name, $ftype, $hash_base);
3664 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3665 $refs, $hash_base, $ftype, $next_link);
3671 if (!defined $searchtext) {
3672 die_error
(undef, "Text field empty");
3674 if (!defined $hash) {
3675 $hash = git_get_head_hash
($project);
3677 my %co = parse_commit
($hash);
3679 die_error
(undef, "Unknown commit object");
3682 $searchtype ||= 'commit';
3683 if ($searchtype eq 'pickaxe') {
3684 # pickaxe may take all resources of your box and run for several minutes
3685 # with every query - so decide by yourself how public you make this feature
3686 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3687 if (!$have_pickaxe) {
3688 die_error
('403 Permission denied', "Permission denied");
3693 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3694 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3696 print "<table cellspacing=\"0\">\n";
3698 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
3700 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3701 while (my $commit_text = <$fd>) {
3702 if (!grep m/$searchtext/i, $commit_text) {
3705 if ($searchtype eq 'author' && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3708 if ($searchtype eq 'committer' && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3711 my @commit_lines = split "\n", $commit_text;
3712 my %co = parse_commit
(undef, \
@commit_lines);
3717 print "<tr class=\"dark\">\n";
3719 print "<tr class=\"light\">\n";
3722 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3723 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3725 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3726 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3727 my $comment = $co{'comment'};
3728 foreach my $line (@
$comment) {
3729 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3730 my $lead = esc_html
($1) || "";
3731 $lead = chop_str
($lead, 30, 10);
3732 my $match = esc_html
($2) || "";
3733 my $trail = esc_html
($3) || "";
3734 $trail = chop_str
($trail, 30, 10);
3735 my $text = "$lead<span class=\"match\">$match</span>$trail";
3736 print chop_str
($text, 80, 5) . "<br/>\n";
3740 "<td class=\"link\">" .
3741 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3743 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3750 if ($searchtype eq 'pickaxe') {
3752 my $git_command = git_cmd_str
();
3753 open my $fd, "-|", "$git_command rev-list $hash | " .
3754 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3757 while (my $line = <$fd>) {
3758 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3761 $set{'from_id'} = $3;
3763 $set{'id'} = $set{'to_id'};
3764 if ($set{'id'} =~ m/0{40}/) {
3765 $set{'id'} = $set{'from_id'};
3767 if ($set{'id'} =~ m/0{40}/) {
3771 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3774 print "<tr class=\"dark\">\n";
3776 print "<tr class=\"light\">\n";
3779 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3780 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3782 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3783 -class => "list subject"},
3784 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3785 while (my $setref = shift @files) {
3787 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3788 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3790 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3794 "<td class=\"link\">" .
3795 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3797 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3801 %co = parse_commit
($1);
3810 sub git_search_help
{
3812 git_print_page_nav
('','', $hash,$hash,$hash);
3815 <dt><b>commit</b></dt>
3816 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
3817 <dt><b>author</b></dt>
3818 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
3819 <dt><b>committer</b></dt>
3820 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
3822 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3823 if ($have_pickaxe) {
3825 <dt><b>pickaxe</b></dt>
3826 <dd>All commits that caused the string to appear or disappear from any file (changes that
3827 added, removed or "modified" the string) will be listed. This search can take a while and
3828 takes a lot of strain on the server, so please use it wisely.</dd>
3836 my $head = git_get_head_hash
($project);
3837 if (!defined $hash) {
3840 if (!defined $page) {
3843 my $refs = git_get_references
();
3845 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3846 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3847 or die_error
(undef, "Open git-rev-list failed");
3848 my @revlist = map { chomp; $_ } <$fd>;
3851 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3853 if ($#revlist >= (100 * ($page+1)-1)) {
3855 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3856 -title
=> "Alt-n"}, "next");
3861 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3862 git_print_header_div
('summary', $project);
3864 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3869 ## ......................................................................
3870 ## feeds (RSS, OPML)
3873 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3874 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3875 or die_error
(undef, "Open git-rev-list failed");
3876 my @revlist = map { chomp; $_ } <$fd>;
3877 close $fd or die_error
(undef, "Reading git-rev-list failed");
3878 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3880 <?xml version="1.0" encoding="utf-8"?>
3881 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3883 <title>$project $my_uri $my_url</title>
3884 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3885 <description>$project log</description>
3886 <language>en</language>
3889 for (my $i = 0; $i <= $#revlist; $i++) {
3890 my $commit = $revlist[$i];
3891 my %co = parse_commit
($commit);
3892 # we read 150, we always show 30 and the ones more recent than 48 hours
3893 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3896 my %cd = parse_date
($co{'committer_epoch'});
3897 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3898 $co{'parent'}, $co{'id'}
3900 my @difftree = map { chomp; $_ } <$fd>;
3905 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3907 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3908 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3909 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3910 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3911 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3912 "<content:encoded>" .
3914 my $comment = $co{'comment'};
3915 foreach my $line (@
$comment) {
3916 $line = to_utf8
($line);
3917 print "$line<br/>\n";
3920 foreach my $line (@difftree) {
3921 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3924 my $file = esc_html
(unquote
($7));
3925 $file = to_utf8
($file);
3926 print "$file<br/>\n";
3929 "</content:encoded>\n" .
3932 print "</channel></rss>";
3936 my @list = git_get_projects_list
();
3938 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3940 <?xml version="1.0" encoding="utf-8"?>
3941 <opml version="1.0">
3943 <title>$site_name OPML Export</title>
3946 <outline text="git RSS feeds">
3949 foreach my $pr (@list) {
3951 my $head = git_get_head_hash
($proj{'path'});
3952 if (!defined $head) {
3955 $git_dir = "$projectroot/$proj{'path'}";
3956 my %co = parse_commit
($head);
3961 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3962 my $rss = "$my_url?p=$proj{'path'};a=rss";
3963 my $html = "$my_url?p=$proj{'path'};a=summary";
3964 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";