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++" || $ENV{'SERVER_NAME'} || "Untitled";
44 # html text to include at home page
45 our $home_text = "++GITWEB_HOMETEXT++";
47 # URI of default stylesheet
48 our $stylesheet = "++GITWEB_CSS++";
50 our $logo = "++GITWEB_LOGO++";
52 # source of projects list
53 our $projects_list = "++GITWEB_LIST++";
55 # list of git base URLs used for URL to where fetch project from,
56 # i.e. full URL is "$git_base_url/$project"
57 our @git_base_url_list = ("++GITWEB_BASE_URL++");
59 # default blob_plain mimetype and default charset for text/plain blob
60 our $default_blob_plain_mimetype = 'text/plain';
61 our $default_text_plain_charset = undef;
63 # file to use for guessing MIME types before trying /etc/mime.types
64 # (relative to the current git repository)
65 our $mimetypes_file = undef;
67 # You define site-wide feature defaults here; override them with
68 # $GITWEB_CONFIG as necessary.
71 # 'sub' => feature-sub (subroutine),
72 # 'override' => allow-override (boolean),
73 # 'default' => [ default options...] (array reference)}
75 # if feature is overridable (it means that allow-override has true value,
76 # then feature-sub will be called with default options as parameters;
77 # return value of feature-sub indicates if to enable specified feature
79 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
82 'sub' => \
&feature_blame
,
87 'sub' => \
&feature_snapshot
,
89 # => [content-encoding, suffix, program]
90 'default' => ['x-gzip', 'gz', 'gzip']},
93 sub gitweb_check_feature
{
95 return undef unless exists $feature{$name};
96 my ($sub, $override, @defaults) = (
97 $feature{$name}{'sub'},
98 $feature{$name}{'override'},
99 @
{$feature{$name}{'default'}});
100 if (!$override) { return @defaults; }
101 return $sub->(@defaults);
104 # To enable system wide have in $GITWEB_CONFIG
105 # $feature{'blame'}{'default'} = [1];
106 # To have project specific config enable override in $GITWEB_CONFIG
107 # $feature{'blame'}{'override'} = 1;
108 # and in project config gitweb.blame = 0|1;
111 my ($val) = git_get_project_config
('blame', '--bool');
113 if ($val eq 'true') {
115 } elsif ($val eq 'false') {
122 # To disable system wide have in $GITWEB_CONFIG
123 # $feature{'snapshot'}{'default'} = [undef];
124 # To have project specific config enable override in $GITWEB_CONFIG
125 # $feature{'blame'}{'override'} = 1;
126 # and in project config gitweb.snapshot = none|gzip|bzip2
128 sub feature_snapshot
{
129 my ($ctype, $suffix, $command) = @_;
131 my ($val) = git_get_project_config
('snapshot');
133 if ($val eq 'gzip') {
134 return ('x-gzip', 'gz', 'gzip');
135 } elsif ($val eq 'bzip2') {
136 return ('x-bzip2', 'bz2', 'bzip2');
137 } elsif ($val eq 'none') {
141 return ($ctype, $suffix, $command);
144 # rename detection options for git-diff and git-diff-tree
145 # - default is '-M', with the cost proportional to
146 # (number of removed files) * (number of new files).
147 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
148 # (number of changed files + number of removed files) * (number of new files)
149 # - even more costly is '-C', '--find-copies-harder' with cost
150 # (number of files in the original tree) * (number of new files)
151 # - one might want to include '-B' option, e.g. '-B', '-M'
152 our @diff_opts = ('-M'); # taken from git_commit
154 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
155 require $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
157 # version of the core git binary
158 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
160 # path to the current git repository
163 $projects_list ||= $projectroot;
165 # ======================================================================
166 # input validation and dispatch
167 our $action = $cgi->param('a');
168 if (defined $action) {
169 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
170 die_error
(undef, "Invalid action parameter");
174 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
175 if (defined $project) {
178 $project = undef unless $project;
180 if (defined $project) {
181 if (!validate_input
($project)) {
182 die_error
(undef, "Invalid project parameter");
184 if (!(-d
"$projectroot/$project")) {
185 die_error
(undef, "No such directory");
187 if (!(-e
"$projectroot/$project/HEAD")) {
188 die_error
(undef, "No such project");
190 $git_dir = "$projectroot/$project";
193 our $file_name = $cgi->param('f');
194 if (defined $file_name) {
195 if (!validate_input
($file_name)) {
196 die_error
(undef, "Invalid file parameter");
200 our $file_parent = $cgi->param('fp');
201 if (defined $file_parent) {
202 if (!validate_input
($file_parent)) {
203 die_error
(undef, "Invalid file parent parameter");
207 our $hash = $cgi->param('h');
209 if (!validate_input
($hash)) {
210 die_error
(undef, "Invalid hash parameter");
214 our $hash_parent = $cgi->param('hp');
215 if (defined $hash_parent) {
216 if (!validate_input
($hash_parent)) {
217 die_error
(undef, "Invalid hash parent parameter");
221 our $hash_base = $cgi->param('hb');
222 if (defined $hash_base) {
223 if (!validate_input
($hash_base)) {
224 die_error
(undef, "Invalid hash base parameter");
228 our $hash_parent_base = $cgi->param('hpb');
229 if (defined $hash_parent_base) {
230 if (!validate_input
($hash_parent_base)) {
231 die_error
(undef, "Invalid hash parent base parameter");
235 our $page = $cgi->param('pg');
237 if ($page =~ m/[^0-9]$/) {
238 die_error
(undef, "Invalid page parameter");
242 our $searchtext = $cgi->param('s');
243 if (defined $searchtext) {
244 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
245 die_error
(undef, "Invalid search parameter");
247 $searchtext = quotemeta $searchtext;
252 "blame" => \
&git_blame2
,
253 "blobdiff" => \
&git_blobdiff
,
254 "blobdiff_plain" => \
&git_blobdiff_plain
,
255 "blob" => \
&git_blob
,
256 "blob_plain" => \
&git_blob_plain
,
257 "commitdiff" => \
&git_commitdiff
,
258 "commitdiff_plain" => \
&git_commitdiff_plain
,
259 "commit" => \
&git_commit
,
260 "heads" => \
&git_heads
,
261 "history" => \
&git_history
,
264 "search" => \
&git_search
,
265 "shortlog" => \
&git_shortlog
,
266 "summary" => \
&git_summary
,
268 "tags" => \
&git_tags
,
269 "tree" => \
&git_tree
,
270 "snapshot" => \
&git_snapshot
,
271 # those below don't need $project
272 "opml" => \
&git_opml
,
273 "project_list" => \
&git_project_list
,
276 if (defined $project) {
277 $action ||= 'summary';
279 $action ||= 'project_list';
281 if (!defined($actions{$action})) {
282 die_error
(undef, "Unknown action");
284 $actions{$action}->();
287 ## ======================================================================
301 hash_parent_base
=> "hpb",
305 my %mapping = @mapping;
307 $params{"project"} ||= $project;
310 for (my $i = 0; $i < @mapping; $i += 2) {
311 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
312 if (defined $params{$name}) {
313 push @result, $symbol . "=" . esc_param
($params{$name});
316 return "$my_uri?" . join(';', @result);
320 ## ======================================================================
321 ## validation, quoting/unquoting and escaping
326 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
329 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
332 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
338 # quote unsafe chars, but keep the slash, even when it's not
339 # correct, but quoted slashes look too horrible in bookmarks
342 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
348 # replace invalid utf8 character with SUBSTITUTION sequence
351 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
352 $str = escapeHTML
($str);
353 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
357 # git may return quoted and escaped filenames
360 if ($str =~ m/^"(.*)"$/) {
362 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
367 # escape tabs (convert tabs to spaces)
371 while ((my $pos = index($line, "\t")) != -1) {
372 if (my $count = (8 - ($pos % 8))) {
373 my $spaces = ' ' x
$count;
374 $line =~ s/\t/$spaces/;
381 ## ----------------------------------------------------------------------
382 ## HTML aware string manipulation
387 my $add_len = shift || 10;
389 # allow only $len chars, but don't cut a word if it would fit in $add_len
390 # if it doesn't fit, cut it if it's still longer than the dots we would add
391 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
394 if (length($tail) > 4) {
396 $body =~ s/&[^;]*$//; # remove chopped character entities
401 ## ----------------------------------------------------------------------
402 ## functions returning short strings
404 # CSS class for given age value (in seconds)
408 if ($age < 60*60*2) {
410 } elsif ($age < 60*60*24*2) {
417 # convert age in seconds to "nn units ago" string
422 if ($age > 60*60*24*365*2) {
423 $age_str = (int $age/60/60/24/365);
424 $age_str .= " years ago";
425 } elsif ($age > 60*60*24*(365/12)*2) {
426 $age_str = int $age/60/60/24/(365/12);
427 $age_str .= " months ago";
428 } elsif ($age > 60*60*24*7*2) {
429 $age_str = int $age/60/60/24/7;
430 $age_str .= " weeks ago";
431 } elsif ($age > 60*60*24*2) {
432 $age_str = int $age/60/60/24;
433 $age_str .= " days ago";
434 } elsif ($age > 60*60*2) {
435 $age_str = int $age/60/60;
436 $age_str .= " hours ago";
437 } elsif ($age > 60*2) {
438 $age_str = int $age/60;
439 $age_str .= " min ago";
442 $age_str .= " sec ago";
444 $age_str .= " right now";
449 # convert file mode in octal to symbolic file mode string
451 my $mode = oct shift;
453 if (S_ISDIR
($mode & S_IFMT
)) {
455 } elsif (S_ISLNK
($mode)) {
457 } elsif (S_ISREG
($mode)) {
458 # git cares only about the executable bit
459 if ($mode & S_IXUSR
) {
469 # convert file mode in octal to file type string
473 if ($mode !~ m/^[0-7]+$/) {
479 if (S_ISDIR
($mode & S_IFMT
)) {
481 } elsif (S_ISLNK
($mode)) {
483 } elsif (S_ISREG
($mode)) {
490 ## ----------------------------------------------------------------------
491 ## functions returning short HTML fragments, or transforming HTML fragments
492 ## which don't beling to other sections
494 # format line of commit message or tag comment
495 sub format_log_line_html
{
498 $line = esc_html
($line);
499 $line =~ s/ / /g;
500 if ($line =~ m/([0-9a-fA-F]{40})/) {
502 if (git_get_type
($hash_text) eq "commit") {
504 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
505 -class => "text"}, $hash_text);
506 $line =~ s/$hash_text/$link/;
512 # format marker of refs pointing to given object
513 sub format_ref_marker
{
514 my ($refs, $id) = @_;
517 if (defined $refs->{$id}) {
518 foreach my $ref (@
{$refs->{$id}}) {
519 my ($type, $name) = qw();
520 # e.g. tags/v2.6.11 or heads/next
521 if ($ref =~ m!^(.*?)s?/(.*)$!) {
529 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
534 return ' <span class="refs">'. $markers . '</span>';
540 # format, perhaps shortened and with markers, title line
541 sub format_subject_html
{
542 my ($long, $short, $href, $extra) = @_;
543 $extra = '' unless defined($extra);
545 if (length($short) < length($long)) {
546 return $cgi->a({-href
=> $href, -class => "list subject",
548 esc_html
($short) . $extra);
550 return $cgi->a({-href
=> $href, -class => "list subject"},
551 esc_html
($long) . $extra);
555 sub format_diff_line
{
557 my $char = substr($line, 0, 1);
563 $diff_class = " add";
564 } elsif ($char eq "-") {
565 $diff_class = " rem";
566 } elsif ($char eq "@") {
567 $diff_class = " chunk_header";
568 } elsif ($char eq "\\") {
569 $diff_class = " incomplete";
571 $line = untabify
($line);
572 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
575 ## ----------------------------------------------------------------------
576 ## git utility subroutines, invoking git commands
578 # returns path to the core git executable and the --git-dir parameter as list
580 return $GIT, '--git-dir='.$git_dir;
583 # returns path to the core git executable and the --git-dir parameter as string
585 return join(' ', git_cmd
());
588 # get HEAD ref of given project as hash
589 sub git_get_head_hash
{
591 my $o_git_dir = $git_dir;
593 $git_dir = "$projectroot/$project";
594 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
597 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
601 if (defined $o_git_dir) {
602 $git_dir = $o_git_dir;
607 # get type of given object
611 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
618 sub git_get_project_config
{
619 my ($key, $type) = @_;
621 return unless ($key);
622 $key =~ s/^gitweb\.//;
623 return if ($key =~ m/\W/);
625 my @x = (git_cmd
(), 'repo-config');
626 if (defined $type) { push @x, $type; }
628 push @x, "gitweb.$key";
634 # get hash of given path at given ref
635 sub git_get_hash_by_path
{
637 my $path = shift || return undef;
641 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
642 or die_error
(undef, "Open git-ls-tree failed");
644 close $fd or return undef;
646 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
647 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
651 ## ......................................................................
652 ## git utility functions, directly accessing git repository
654 # assumes that PATH is not symref
655 sub git_get_hash_by_ref
{
658 open my $fd, "$projectroot/$path" or return undef;
662 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
667 sub git_get_project_description
{
670 open my $fd, "$projectroot/$path/description" or return undef;
677 sub git_get_project_url_list
{
680 open my $fd, "$projectroot/$path/cloneurl" or return undef;
681 my @git_project_url_list = map { chomp; $_ } <$fd>;
684 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
687 sub git_get_projects_list
{
690 if (-d
$projects_list) {
691 # search in directory
692 my $dir = $projects_list;
693 opendir my ($dh), $dir or return undef;
694 while (my $dir = readdir($dh)) {
695 if (-e
"$projectroot/$dir/HEAD") {
703 } elsif (-f
$projects_list) {
704 # read from file(url-encoded):
705 # 'git%2Fgit.git Linus+Torvalds'
706 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
707 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
708 open my ($fd), $projects_list or return undef;
709 while (my $line = <$fd>) {
711 my ($path, $owner) = split ' ', $line;
712 $path = unescape
($path);
713 $owner = unescape
($owner);
714 if (!defined $path) {
717 if (-e
"$projectroot/$path/HEAD") {
720 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
727 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
731 sub git_get_project_owner
{
735 return undef unless $project;
737 # read from file (url-encoded):
738 # 'git%2Fgit.git Linus+Torvalds'
739 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
740 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
741 if (-f
$projects_list) {
742 open (my $fd , $projects_list);
743 while (my $line = <$fd>) {
745 my ($pr, $ow) = split ' ', $line;
748 if ($pr eq $project) {
749 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
755 if (!defined $owner) {
756 $owner = get_file_owner
("$projectroot/$project");
762 sub git_get_references
{
763 my $type = shift || "";
766 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
767 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
768 if (-f
"$projectroot/$project/info/refs") {
769 open $fd, "$projectroot/$project/info/refs"
772 open $fd, "-|", git_cmd
(), "ls-remote", "."
776 while (my $line = <$fd>) {
778 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
779 if (defined $refs{$1}) {
780 push @
{$refs{$1}}, $2;
790 sub git_get_rev_name_tags
{
791 my $hash = shift || return undef;
793 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
795 my $name_rev = <$fd>;
798 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
801 # catches also '$hash undefined' output
806 ## ----------------------------------------------------------------------
807 ## parse to hash functions
811 my $tz = shift || "-0000";
814 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
815 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
816 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
817 $date{'hour'} = $hour;
818 $date{'minute'} = $min;
819 $date{'mday'} = $mday;
820 $date{'day'} = $days[$wday];
821 $date{'month'} = $months[$mon];
822 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
823 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
824 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
825 $mday, $months[$mon], $hour ,$min;
827 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
828 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
829 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
830 $date{'hour_local'} = $hour;
831 $date{'minute_local'} = $min;
832 $date{'tz_local'} = $tz;
841 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
842 $tag{'id'} = $tag_id;
843 while (my $line = <$fd>) {
845 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
847 } elsif ($line =~ m/^type (.+)$/) {
849 } elsif ($line =~ m/^tag (.+)$/) {
851 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
855 } elsif ($line =~ m/--BEGIN/) {
856 push @comment, $line;
858 } elsif ($line eq "") {
862 push @comment, <$fd>;
863 $tag{'comment'} = \
@comment;
865 if (!defined $tag{'name'}) {
872 my $commit_id = shift;
873 my $commit_text = shift;
878 if (defined $commit_text) {
879 @commit_lines = @
$commit_text;
882 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
884 @commit_lines = split '\n', <$fd>;
889 my $header = shift @commit_lines;
890 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
893 ($co{'id'}, my @parents) = split ' ', $header;
894 $co{'parents'} = \
@parents;
895 $co{'parent'} = $parents[0];
896 while (my $line = shift @commit_lines) {
897 last if $line eq "\n";
898 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
900 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
902 $co{'author_epoch'} = $2;
903 $co{'author_tz'} = $3;
904 if ($co{'author'} =~ m/^([^<]+) </) {
905 $co{'author_name'} = $1;
907 $co{'author_name'} = $co{'author'};
909 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
910 $co{'committer'} = $1;
911 $co{'committer_epoch'} = $2;
912 $co{'committer_tz'} = $3;
913 $co{'committer_name'} = $co{'committer'};
914 $co{'committer_name'} =~ s/ <.*//;
917 if (!defined $co{'tree'}) {
921 foreach my $title (@commit_lines) {
924 $co{'title'} = chop_str
($title, 80, 5);
925 # remove leading stuff of merges to make the interesting part visible
926 if (length($title) > 50) {
927 $title =~ s/^Automatic //;
928 $title =~ s/^merge (of|with) /Merge ... /i;
929 if (length($title) > 50) {
930 $title =~ s/(http|rsync):\/\///;
932 if (length($title) > 50) {
933 $title =~ s/(master|www|rsync)\.//;
935 if (length($title) > 50) {
936 $title =~ s/kernel.org:?//;
938 if (length($title) > 50) {
939 $title =~ s/\/pub\/scm//;
942 $co{'title_short'} = chop_str
($title, 50, 5);
946 # remove added spaces
947 foreach my $line (@commit_lines) {
950 $co{'comment'} = \
@commit_lines;
952 my $age = time - $co{'committer_epoch'};
954 $co{'age_string'} = age_string
($age);
955 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
956 if ($age > 60*60*24*7*2) {
957 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
958 $co{'age_string_age'} = $co{'age_string'};
960 $co{'age_string_date'} = $co{'age_string'};
961 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
966 # parse ref from ref_file, given by ref_id, with given type
968 my $ref_file = shift;
970 my $type = shift || git_get_type
($ref_id);
973 $ref_item{'type'} = $type;
974 $ref_item{'id'} = $ref_id;
975 $ref_item{'epoch'} = 0;
976 $ref_item{'age'} = "unknown";
977 if ($type eq "tag") {
978 my %tag = parse_tag
($ref_id);
979 $ref_item{'comment'} = $tag{'comment'};
980 if ($tag{'type'} eq "commit") {
981 my %co = parse_commit
($tag{'object'});
982 $ref_item{'epoch'} = $co{'committer_epoch'};
983 $ref_item{'age'} = $co{'age_string'};
984 } elsif (defined($tag{'epoch'})) {
985 my $age = time - $tag{'epoch'};
986 $ref_item{'epoch'} = $tag{'epoch'};
987 $ref_item{'age'} = age_string
($age);
989 $ref_item{'reftype'} = $tag{'type'};
990 $ref_item{'name'} = $tag{'name'};
991 $ref_item{'refid'} = $tag{'object'};
992 } elsif ($type eq "commit"){
993 my %co = parse_commit
($ref_id);
994 $ref_item{'reftype'} = "commit";
995 $ref_item{'name'} = $ref_file;
996 $ref_item{'title'} = $co{'title'};
997 $ref_item{'refid'} = $ref_id;
998 $ref_item{'epoch'} = $co{'committer_epoch'};
999 $ref_item{'age'} = $co{'age_string'};
1001 $ref_item{'reftype'} = $type;
1002 $ref_item{'name'} = $ref_file;
1003 $ref_item{'refid'} = $ref_id;
1009 # parse line of git-diff-tree "raw" output
1010 sub parse_difftree_raw_line
{
1014 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1015 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1016 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1017 $res{'from_mode'} = $1;
1018 $res{'to_mode'} = $2;
1019 $res{'from_id'} = $3;
1021 $res{'status'} = $5;
1022 $res{'similarity'} = $6;
1023 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1024 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1026 $res{'file'} = unquote
($7);
1029 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1030 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1031 # $res{'commit'} = $1;
1034 return wantarray ?
%res : \
%res;
1037 ## ......................................................................
1038 ## parse to array of hashes functions
1040 sub git_get_refs_list
{
1041 my $ref_dir = shift;
1045 my $pfxlen = length("$projectroot/$project/$ref_dir");
1046 File
::Find
::find
(sub {
1049 push @refs, substr($File::Find
::name
, $pfxlen + 1);
1051 }, "$projectroot/$project/$ref_dir");
1053 foreach my $ref_file (@refs) {
1054 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
1055 my $type = git_get_type
($ref_id) || next;
1056 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1058 push @reflist, \
%ref_item;
1061 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1065 ## ----------------------------------------------------------------------
1066 ## filesystem-related functions
1068 sub get_file_owner
{
1071 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1072 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1073 if (!defined $gcos) {
1077 $owner =~ s/[,;].*$//;
1078 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1081 ## ......................................................................
1082 ## mimetype related functions
1084 sub mimetype_guess_file
{
1085 my $filename = shift;
1086 my $mimemap = shift;
1087 -r
$mimemap or return undef;
1090 open(MIME
, $mimemap) or return undef;
1092 next if m/^#/; # skip comments
1093 my ($mime, $exts) = split(/\t+/);
1094 if (defined $exts) {
1095 my @exts = split(/\s+/, $exts);
1096 foreach my $ext (@exts) {
1097 $mimemap{$ext} = $mime;
1103 $filename =~ /\.(.*?)$/;
1104 return $mimemap{$1};
1107 sub mimetype_guess
{
1108 my $filename = shift;
1110 $filename =~ /\./ or return undef;
1112 if ($mimetypes_file) {
1113 my $file = $mimetypes_file;
1114 if ($file !~ m!^/!) { # if it is relative path
1115 # it is relative to project
1116 $file = "$projectroot/$project/$file";
1118 $mime = mimetype_guess_file
($filename, $file);
1120 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1126 my $filename = shift;
1129 my $mime = mimetype_guess
($filename);
1130 $mime and return $mime;
1134 return $default_blob_plain_mimetype unless $fd;
1137 return 'text/plain' .
1138 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1139 } elsif (! $filename) {
1140 return 'application/octet-stream';
1141 } elsif ($filename =~ m/\.png$/i) {
1143 } elsif ($filename =~ m/\.gif$/i) {
1145 } elsif ($filename =~ m/\.jpe?g$/i) {
1146 return 'image/jpeg';
1148 return 'application/octet-stream';
1152 ## ======================================================================
1153 ## functions printing HTML: header, footer, error page
1155 sub git_header_html
{
1156 my $status = shift || "200 OK";
1157 my $expires = shift;
1159 my $title = "$site_name git";
1160 if (defined $project) {
1161 $title .= " - $project";
1162 if (defined $action) {
1163 $title .= "/$action";
1164 if (defined $file_name) {
1165 $title .= " - $file_name";
1166 if ($action eq "tree" && $file_name !~ m
|/$|) {
1173 # require explicit support from the UA if we are to send the page as
1174 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1175 # we have to do this because MSIE sometimes globs '*/*', pretending to
1176 # support xhtml+xml but choking when it gets what it asked for.
1177 if (defined $cgi->http('HTTP_ACCEPT') &&
1178 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1179 $cgi->Accept('application/xhtml+xml') != 0) {
1180 $content_type = 'application/xhtml+xml';
1182 $content_type = 'text/html';
1184 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1185 -status
=> $status, -expires
=> $expires);
1187 <?xml version="1.0" encoding="utf-8"?>
1188 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1189 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1190 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1191 <!-- git core binaries version $git_version -->
1193 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1194 <meta name="generator" content="gitweb/$version git/$git_version"/>
1195 <meta name="robots" content="index, nofollow"/>
1196 <title>$title</title>
1197 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1199 if (defined $project) {
1200 printf('<link rel="alternate" title="%s log" '.
1201 'href="%s" type="application/rss+xml"/>'."\n",
1202 esc_param
($project), href
(action
=>"rss"));
1207 "<div class=\"page_header\">\n" .
1208 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1209 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1211 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1212 if (defined $project) {
1213 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1214 if (defined $action) {
1218 if (!defined $searchtext) {
1222 if (defined $hash_base) {
1223 $search_hash = $hash_base;
1224 } elsif (defined $hash) {
1225 $search_hash = $hash;
1227 $search_hash = "HEAD";
1229 $cgi->param("a", "search");
1230 $cgi->param("h", $search_hash);
1231 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1232 "<div class=\"search\">\n" .
1233 $cgi->hidden(-name
=> "p") . "\n" .
1234 $cgi->hidden(-name
=> "a") . "\n" .
1235 $cgi->hidden(-name
=> "h") . "\n" .
1236 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1238 $cgi->end_form() . "\n";
1243 sub git_footer_html
{
1244 print "<div class=\"page_footer\">\n";
1245 if (defined $project) {
1246 my $descr = git_get_project_description
($project);
1247 if (defined $descr) {
1248 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1250 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1252 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1260 my $status = shift || "403 Forbidden";
1261 my $error = shift || "Malformed query, file missing or permission denied";
1263 git_header_html
($status);
1265 <div class="page_body">
1275 ## ----------------------------------------------------------------------
1276 ## functions printing or outputting HTML: navigation
1278 sub git_print_page_nav
{
1279 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1280 $extra = '' if !defined $extra; # pager or formats
1282 my @navs = qw(summary shortlog log commit commitdiff tree);
1284 @navs = grep { $_ ne $suppress } @navs;
1287 my %arg = map { $_ => {action
=>$_} } @navs;
1288 if (defined $head) {
1289 for (qw(commit commitdiff)) {
1290 $arg{$_}{hash
} = $head;
1292 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1293 for (qw(shortlog log)) {
1294 $arg{$_}{hash
} = $head;
1298 $arg{tree
}{hash
} = $treehead if defined $treehead;
1299 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1301 print "<div class=\"page_nav\">\n" .
1303 map { $_ eq $current ?
1304 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1306 print "<br/>\n$extra<br/>\n" .
1310 sub format_paging_nav
{
1311 my ($action, $hash, $head, $page, $nrevs) = @_;
1315 if ($hash ne $head || $page) {
1316 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1318 $paging_nav .= "HEAD";
1322 $paging_nav .= " ⋅ " .
1323 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1324 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1326 $paging_nav .= " ⋅ prev";
1329 if ($nrevs >= (100 * ($page+1)-1)) {
1330 $paging_nav .= " ⋅ " .
1331 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1332 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1334 $paging_nav .= " ⋅ next";
1340 ## ......................................................................
1341 ## functions printing or outputting HTML: div
1343 sub git_print_header_div
{
1344 my ($action, $title, $hash, $hash_base) = @_;
1347 $args{action
} = $action;
1348 $args{hash
} = $hash if $hash;
1349 $args{hash_base
} = $hash_base if $hash_base;
1351 print "<div class=\"header\">\n" .
1352 $cgi->a({-href
=> href
(%args), -class => "title"},
1353 $title ?
$title : $action) .
1357 sub git_print_page_path
{
1362 if (!defined $name) {
1363 print "<div class=\"page_path\">/</div>\n";
1364 } elsif (defined $type && $type eq 'blob') {
1365 print "<div class=\"page_path\">";
1367 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1371 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)},
1374 print "<br/></div>\n";
1376 print "<div class=\"page_path\">" . esc_html
($name) . "<br/></div>\n";
1383 # remove leading empty lines
1384 while (defined $log->[0] && $log->[0] eq "") {
1391 foreach my $line (@
$log) {
1392 # print only one empty line
1393 # do not print empty line after signoff
1395 next if ($empty || $signoff);
1400 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1402 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1405 print format_log_line_html
($line) . "<br/>\n";
1410 sub git_print_simplified_log
{
1412 my $remove_title = shift;
1414 shift @
$log if $remove_title;
1415 # remove leading empty lines
1416 while (defined $log->[0] && $log->[0] eq "") {
1420 # simplify and print log
1422 foreach my $line (@
$log) {
1423 # remove signoff lines
1424 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1427 # print only one empty line
1434 print format_log_line_html
($line) . "<br/>\n";
1436 # end with single empty line
1437 print "<br/>\n" unless $empty;
1440 ## ......................................................................
1441 ## functions printing large fragments of HTML
1443 sub git_difftree_body
{
1444 my ($difftree, $hash, $parent) = @_;
1446 print "<div class=\"list_head\">\n";
1447 if ($#{$difftree} > 10) {
1448 print(($#{$difftree} + 1) . " files changed:\n");
1452 print "<table class=\"diff_tree\">\n";
1454 foreach my $line (@
{$difftree}) {
1455 my %diff = parse_difftree_raw_line
($line);
1458 print "<tr class=\"dark\">\n";
1460 print "<tr class=\"light\">\n";
1464 my ($to_mode_oct, $to_mode_str, $to_file_type);
1465 my ($from_mode_oct, $from_mode_str, $from_file_type);
1466 if ($diff{'to_mode'} ne ('0' x
6)) {
1467 $to_mode_oct = oct $diff{'to_mode'};
1468 if (S_ISREG
($to_mode_oct)) { # only for regular file
1469 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1471 $to_file_type = file_type
($diff{'to_mode'});
1473 if ($diff{'from_mode'} ne ('0' x
6)) {
1474 $from_mode_oct = oct $diff{'from_mode'};
1475 if (S_ISREG
($to_mode_oct)) { # only for regular file
1476 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1478 $from_file_type = file_type
($diff{'from_mode'});
1481 if ($diff{'status'} eq "A") { # created
1482 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1483 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1484 $mode_chng .= "]</span>";
1486 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1487 hash_base
=>$hash, file_name
=>$diff{'file'}),
1488 -class => "list"}, esc_html
($diff{'file'})) .
1490 "<td>$mode_chng</td>\n" .
1491 "<td class=\"link\">" .
1492 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1493 hash_base
=>$hash, file_name
=>$diff{'file'})},
1497 } elsif ($diff{'status'} eq "D") { # deleted
1498 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1500 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1501 hash_base
=>$parent, file_name
=>$diff{'file'}),
1502 -class => "list"}, esc_html
($diff{'file'})) .
1504 "<td>$mode_chng</td>\n" .
1505 "<td class=\"link\">" .
1506 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1507 hash_base
=>$parent, file_name
=>$diff{'file'})},
1510 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1511 file_name
=>$diff{'file'})},
1515 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1516 my $mode_chnge = "";
1517 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1518 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1519 if ($from_file_type != $to_file_type) {
1520 $mode_chnge .= " from $from_file_type to $to_file_type";
1522 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1523 if ($from_mode_str && $to_mode_str) {
1524 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1525 } elsif ($to_mode_str) {
1526 $mode_chnge .= " mode: $to_mode_str";
1529 $mode_chnge .= "]</span>\n";
1532 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1533 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1534 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1535 hash_base
=>$hash, hash_parent_base
=>$parent,
1536 file_name
=>$diff{'file'}),
1537 -class => "list"}, esc_html
($diff{'file'}));
1538 } else { # only mode changed
1539 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1540 hash_base
=>$hash, file_name
=>$diff{'file'}),
1541 -class => "list"}, esc_html
($diff{'file'}));
1544 "<td>$mode_chnge</td>\n" .
1545 "<td class=\"link\">" .
1546 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1547 hash_base
=>$hash, file_name
=>$diff{'file'})},
1549 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1551 $cgi->a({-href
=> href
(action
=>"blobdiff",
1552 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1553 hash_base
=>$hash, hash_parent_base
=>$parent,
1554 file_name
=>$diff{'file'})},
1558 $cgi->a({-href
=> href
(action
=>"history",
1559 hash_base
=>$hash, file_name
=>$diff{'file'})},
1563 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1564 my %status_name = ('R' => 'moved', 'C' => 'copied');
1565 my $nstatus = $status_name{$diff{'status'}};
1567 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1568 # mode also for directories, so we cannot use $to_mode_str
1569 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1572 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1573 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1574 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1575 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1576 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1577 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1578 -class => "list"}, esc_html
($diff{'from_file'})) .
1579 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1580 "<td class=\"link\">" .
1581 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1582 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1584 if ($diff{'to_id'} ne $diff{'from_id'}) {
1586 $cgi->a({-href
=> href
(action
=>"blobdiff",
1587 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1588 hash_base
=>$hash, hash_parent_base
=>$parent,
1589 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1594 } # we should not encounter Unmerged (U) or Unknown (X) status
1600 sub git_patchset_body
{
1601 my ($fd, $difftree, $hash, $hash_parent) = @_;
1605 my $patch_found = 0;
1608 print "<div class=\"patchset\">\n";
1611 while (my $patch_line = <$fd>) {
1614 if ($patch_line =~ m/^diff /) { # "git diff" header
1615 # beginning of patch (in patchset)
1617 # close previous patch
1618 print "</div>\n"; # class="patch"
1620 # first patch in patchset
1623 print "<div class=\"patch\">\n";
1625 if (ref($difftree->[$patch_idx]) eq "HASH") {
1626 $diffinfo = $difftree->[$patch_idx];
1628 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1632 # for now, no extended header, hence we skip empty patches
1633 # companion to next LINE if $in_header;
1634 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1639 if ($diffinfo->{'status'} eq "A") { # added
1640 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1641 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1642 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1643 $diffinfo->{'to_id'}) . "(new)" .
1644 "</div>\n"; # class="diff_info"
1646 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1647 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1648 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1649 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1650 $diffinfo->{'from_id'}) . "(deleted)" .
1651 "</div>\n"; # class="diff_info"
1653 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1654 $diffinfo->{'status'} eq "C" || # copied
1655 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1656 print "<div class=\"diff_info\">" .
1657 file_type
($diffinfo->{'from_mode'}) . ":" .
1658 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1659 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1660 $diffinfo->{'from_id'}) .
1662 file_type
($diffinfo->{'to_mode'}) . ":" .
1663 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1664 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1665 $diffinfo->{'to_id'});
1666 print "</div>\n"; # class="diff_info"
1668 } else { # modified, mode changed, ...
1669 print "<div class=\"diff_info\">" .
1670 file_type
($diffinfo->{'from_mode'}) . ":" .
1671 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1672 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1673 $diffinfo->{'from_id'}) .
1675 file_type
($diffinfo->{'to_mode'}) . ":" .
1676 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1677 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1678 $diffinfo->{'to_id'});
1679 print "</div>\n"; # class="diff_info"
1682 #print "<div class=\"diff extended_header\">\n";
1685 } # start of patch in patchset
1688 if ($in_header && $patch_line =~ m/^---/) {
1689 #print "</div>\n"; # class="diff extended_header"
1692 my $file = $diffinfo->{'from_file'};
1693 $file ||= $diffinfo->{'file'};
1694 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1695 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
1696 -class => "list"}, esc_html
($file));
1697 $patch_line =~ s
|a
/.*$|a/$file|g
;
1698 print "<div class=\"diff from_file\">$patch_line</div>\n";
1700 $patch_line = <$fd>;
1703 #$patch_line =~ m/^+++/;
1704 $file = $diffinfo->{'to_file'};
1705 $file ||= $diffinfo->{'file'};
1706 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1707 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
1708 -class => "list"}, esc_html
($file));
1709 $patch_line =~ s
|b
/.*|b/$file|g
;
1710 print "<div class=\"diff to_file\">$patch_line</div>\n";
1714 next LINE
if $in_header;
1716 print format_diff_line
($patch_line);
1718 print "</div>\n" if $patch_found; # class="patch"
1720 print "</div>\n"; # class="patchset"
1723 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1725 sub git_shortlog_body
{
1726 # uses global variable $project
1727 my ($revlist, $from, $to, $refs, $extra) = @_;
1729 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1730 my $have_snapshot = (defined $ctype && defined $suffix);
1732 $from = 0 unless defined $from;
1733 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1735 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1737 for (my $i = $from; $i <= $to; $i++) {
1738 my $commit = $revlist->[$i];
1739 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1740 my $ref = format_ref_marker
($refs, $commit);
1741 my %co = parse_commit
($commit);
1743 print "<tr class=\"dark\">\n";
1745 print "<tr class=\"light\">\n";
1748 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1749 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1750 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1752 print format_subject_html
($co{'title'}, $co{'title_short'},
1753 href
(action
=>"commit", hash
=>$commit), $ref);
1755 "<td class=\"link\">" .
1756 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1757 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1758 if ($have_snapshot) {
1759 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1764 if (defined $extra) {
1766 "<td colspan=\"4\">$extra</td>\n" .
1772 sub git_history_body
{
1773 # Warning: assumes constant type (blob or tree) during history
1774 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1776 print "<table class=\"history\" cellspacing=\"0\">\n";
1778 while (my $line = <$fd>) {
1779 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1784 my %co = parse_commit
($commit);
1789 my $ref = format_ref_marker
($refs, $commit);
1792 print "<tr class=\"dark\">\n";
1794 print "<tr class=\"light\">\n";
1797 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1798 # shortlog uses chop_str($co{'author_name'}, 10)
1799 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1801 # originally git_history used chop_str($co{'title'}, 50)
1802 print format_subject_html
($co{'title'}, $co{'title_short'},
1803 href
(action
=>"commit", hash
=>$commit), $ref);
1805 "<td class=\"link\">" .
1806 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1807 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1808 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1810 if ($ftype eq 'blob') {
1811 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1812 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1813 if (defined $blob_current && defined $blob_parent &&
1814 $blob_current ne $blob_parent) {
1816 $cgi->a({-href
=> href
(action
=>"blobdiff",
1817 hash
=>$blob_current, hash_parent
=>$blob_parent,
1818 hash_base
=>$hash_base, hash_parent_base
=>$commit,
1819 file_name
=>$file_name)},
1826 if (defined $extra) {
1828 "<td colspan=\"4\">$extra</td>\n" .
1835 # uses global variable $project
1836 my ($taglist, $from, $to, $extra) = @_;
1837 $from = 0 unless defined $from;
1838 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1840 print "<table class=\"tags\" cellspacing=\"0\">\n";
1842 for (my $i = $from; $i <= $to; $i++) {
1843 my $entry = $taglist->[$i];
1845 my $comment_lines = $tag{'comment'};
1846 my $comment = shift @
$comment_lines;
1848 if (defined $comment) {
1849 $comment_short = chop_str
($comment, 30, 5);
1852 print "<tr class=\"dark\">\n";
1854 print "<tr class=\"light\">\n";
1857 print "<td><i>$tag{'age'}</i></td>\n" .
1859 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1860 -class => "list name"}, esc_html
($tag{'name'})) .
1863 if (defined $comment) {
1864 print format_subject_html
($comment, $comment_short,
1865 href
(action
=>"tag", hash
=>$tag{'id'}));
1868 "<td class=\"selflink\">";
1869 if ($tag{'type'} eq "tag") {
1870 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1875 "<td class=\"link\">" . " | " .
1876 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1877 if ($tag{'reftype'} eq "commit") {
1878 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1879 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1880 } elsif ($tag{'reftype'} eq "blob") {
1881 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1886 if (defined $extra) {
1888 "<td colspan=\"5\">$extra</td>\n" .
1894 sub git_heads_body
{
1895 # uses global variable $project
1896 my ($taglist, $head, $from, $to, $extra) = @_;
1897 $from = 0 unless defined $from;
1898 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1900 print "<table class=\"heads\" cellspacing=\"0\">\n";
1902 for (my $i = $from; $i <= $to; $i++) {
1903 my $entry = $taglist->[$i];
1905 my $curr = $tag{'id'} eq $head;
1907 print "<tr class=\"dark\">\n";
1909 print "<tr class=\"light\">\n";
1912 print "<td><i>$tag{'age'}</i></td>\n" .
1913 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1914 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1915 -class => "list name"},esc_html
($tag{'name'})) .
1917 "<td class=\"link\">" .
1918 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1919 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1923 if (defined $extra) {
1925 "<td colspan=\"3\">$extra</td>\n" .
1931 ## ======================================================================
1932 ## ======================================================================
1935 sub git_project_list
{
1936 my $order = $cgi->param('o');
1937 if (defined $order && $order !~ m/project|descr|owner|age/) {
1938 die_error
(undef, "Unknown order parameter");
1941 my @list = git_get_projects_list
();
1944 die_error
(undef, "No projects found");
1946 foreach my $pr (@list) {
1947 my $head = git_get_head_hash
($pr->{'path'});
1948 if (!defined $head) {
1951 $git_dir = "$projectroot/$pr->{'path'}";
1952 my %co = parse_commit
($head);
1956 $pr->{'commit'} = \
%co;
1957 if (!defined $pr->{'descr'}) {
1958 my $descr = git_get_project_description
($pr->{'path'}) || "";
1959 $pr->{'descr'} = chop_str
($descr, 25, 5);
1961 if (!defined $pr->{'owner'}) {
1962 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1964 push @projects, $pr;
1968 if (-f
$home_text) {
1969 print "<div class=\"index_include\">\n";
1970 open (my $fd, $home_text);
1975 print "<table class=\"project_list\">\n" .
1977 $order ||= "project";
1978 if ($order eq "project") {
1979 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1980 print "<th>Project</th>\n";
1983 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1984 -class => "header"}, "Project") .
1987 if ($order eq "descr") {
1988 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1989 print "<th>Description</th>\n";
1992 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1993 -class => "header"}, "Description") .
1996 if ($order eq "owner") {
1997 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1998 print "<th>Owner</th>\n";
2001 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
2002 -class => "header"}, "Owner") .
2005 if ($order eq "age") {
2006 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2007 print "<th>Last Change</th>\n";
2010 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
2011 -class => "header"}, "Last Change") .
2014 print "<th></th>\n" .
2017 foreach my $pr (@projects) {
2019 print "<tr class=\"dark\">\n";
2021 print "<tr class=\"light\">\n";
2024 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2025 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2026 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2027 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2028 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2029 $pr->{'commit'}{'age_string'} . "</td>\n" .
2030 "<td class=\"link\">" .
2031 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2032 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2033 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
2042 my $descr = git_get_project_description
($project) || "none";
2043 my $head = git_get_head_hash
($project);
2044 my %co = parse_commit
($head);
2045 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2047 my $owner = git_get_project_owner
($project);
2049 my $refs = git_get_references
();
2051 git_print_page_nav
('summary','', $head);
2053 print "<div class=\"title\"> </div>\n";
2054 print "<table cellspacing=\"0\">\n" .
2055 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2056 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2057 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2058 # use per project git URL list in $projectroot/$project/cloneurl
2059 # or make project git URL from git base URL and project name
2060 my $url_tag = "URL";
2061 my @url_list = git_get_project_url_list
($project);
2062 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2063 foreach my $git_url (@url_list) {
2064 next unless $git_url;
2065 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2070 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2071 git_get_head_hash
($project)
2072 or die_error
(undef, "Open git-rev-list failed");
2073 my @revlist = map { chomp; $_ } <$fd>;
2075 git_print_header_div
('shortlog');
2076 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2077 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2079 my $taglist = git_get_refs_list
("refs/tags");
2080 if (defined @
$taglist) {
2081 git_print_header_div
('tags');
2082 git_tags_body
($taglist, 0, 15,
2083 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2086 my $headlist = git_get_refs_list
("refs/heads");
2087 if (defined @
$headlist) {
2088 git_print_header_div
('heads');
2089 git_heads_body
($headlist, $head, 0, 15,
2090 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2097 my $head = git_get_head_hash
($project);
2099 git_print_page_nav
('','', $head,undef,$head);
2100 my %tag = parse_tag
($hash);
2101 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2102 print "<div class=\"title_text\">\n" .
2103 "<table cellspacing=\"0\">\n" .
2105 "<td>object</td>\n" .
2106 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2107 $tag{'object'}) . "</td>\n" .
2108 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2109 $tag{'type'}) . "</td>\n" .
2111 if (defined($tag{'author'})) {
2112 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2113 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2114 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2115 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2118 print "</table>\n\n" .
2120 print "<div class=\"page_body\">";
2121 my $comment = $tag{'comment'};
2122 foreach my $line (@
$comment) {
2123 print esc_html
($line) . "<br/>\n";
2133 if (!gitweb_check_feature
('blame')) {
2134 die_error
('403 Permission denied', "Permission denied");
2136 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2137 $hash_base ||= git_get_head_hash
($project);
2138 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2139 my %co = parse_commit
($hash_base)
2140 or die_error
(undef, "Reading commit failed");
2141 if (!defined $hash) {
2142 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2143 or die_error
(undef, "Error looking up file");
2145 $ftype = git_get_type
($hash);
2146 if ($ftype !~ "blob") {
2147 die_error
("400 Bad Request", "Object is not a blob");
2149 open ($fd, "-|", git_cmd
(), "blame", '-l', $file_name, $hash_base)
2150 or die_error
(undef, "Open git-blame failed");
2153 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2156 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2158 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2159 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2160 git_print_page_path
($file_name, $ftype, $hash_base);
2161 my @rev_color = (qw(light2 dark2));
2162 my $num_colors = scalar(@rev_color);
2163 my $current_color = 0;
2166 <div class="page_body">
2167 <table class="blame">
2168 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2171 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2173 my $rev = substr($full_rev, 0, 8);
2177 if (!defined $last_rev) {
2178 $last_rev = $full_rev;
2179 } elsif ($last_rev ne $full_rev) {
2180 $last_rev = $full_rev;
2181 $current_color = ++$current_color % $num_colors;
2183 print "<tr class=\"$rev_color[$current_color]\">\n";
2184 print "<td class=\"sha1\">" .
2185 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2186 esc_html
($rev)) . "</td>\n";
2187 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2188 esc_html
($lineno) . "</a></td>\n";
2189 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2195 or print "Reading blob failed\n";
2202 if (!gitweb_check_feature
('blame')) {
2203 die_error
('403 Permission denied', "Permission denied");
2205 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2206 $hash_base ||= git_get_head_hash
($project);
2207 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2208 my %co = parse_commit
($hash_base)
2209 or die_error
(undef, "Reading commit failed");
2210 if (!defined $hash) {
2211 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2212 or die_error
(undef, "Error lookup file");
2214 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2215 or die_error
(undef, "Open git-annotate failed");
2218 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2221 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2223 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2224 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2225 git_print_page_path
($file_name, 'blob', $hash_base);
2226 print "<div class=\"page_body\">\n";
2228 <table class="blame">
2237 my @line_class = (qw(light dark));
2238 my $line_class_len = scalar (@line_class);
2239 my $line_class_num = $#line_class;
2240 while (my $line = <$fd>) {
2252 $line_class_num = ($line_class_num + 1) % $line_class_len;
2254 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2261 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2264 $short_rev = substr ($long_rev, 0, 8);
2265 $age = time () - $time;
2266 $age_str = age_string
($age);
2267 $age_str =~ s/ / /g;
2268 $age_class = age_class
($age);
2269 $author = esc_html
($author);
2270 $author =~ s/ / /g;
2272 $data = untabify
($data);
2273 $data = esc_html
($data);
2276 <tr class="$line_class[$line_class_num]">
2277 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2278 <td class="$age_class">$age_str</td>
2280 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2281 <td class="pre">$data</td>
2284 } # while (my $line = <$fd>)
2285 print "</table>\n\n";
2287 or print "Reading blob failed.\n";
2293 my $head = git_get_head_hash
($project);
2295 git_print_page_nav
('','', $head,undef,$head);
2296 git_print_header_div
('summary', $project);
2298 my $taglist = git_get_refs_list
("refs/tags");
2299 if (defined @
$taglist) {
2300 git_tags_body
($taglist);
2306 my $head = git_get_head_hash
($project);
2308 git_print_page_nav
('','', $head,undef,$head);
2309 git_print_header_div
('summary', $project);
2311 my $taglist = git_get_refs_list
("refs/heads");
2312 if (defined @
$taglist) {
2313 git_heads_body
($taglist, $head);
2318 sub git_blob_plain
{
2319 # blobs defined by non-textual hash id's can be cached
2321 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2325 if (!defined $hash) {
2326 if (defined $file_name) {
2327 my $base = $hash_base || git_get_head_hash
($project);
2328 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2329 or die_error
(undef, "Error lookup file");
2331 die_error
(undef, "No file name defined");
2335 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2336 or die_error
(undef, "Couldn't cat $file_name, $hash");
2338 $type ||= blob_mimetype
($fd, $file_name);
2340 # save as filename, even when no $file_name is given
2341 my $save_as = "$hash";
2342 if (defined $file_name) {
2343 $save_as = $file_name;
2344 } elsif ($type =~ m/^text\//) {
2351 -content_disposition
=> "inline; filename=\"$save_as\"");
2353 binmode STDOUT
, ':raw';
2355 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2361 # blobs defined by non-textual hash id's can be cached
2363 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2367 if (!defined $hash) {
2368 if (defined $file_name) {
2369 my $base = $hash_base || git_get_head_hash
($project);
2370 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2371 or die_error
(undef, "Error lookup file");
2373 die_error
(undef, "No file name defined");
2376 my $have_blame = gitweb_check_feature
('blame');
2377 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2378 or die_error
(undef, "Couldn't cat $file_name, $hash");
2379 my $mimetype = blob_mimetype
($fd, $file_name);
2380 if ($mimetype !~ m/^text\//) {
2382 return git_blob_plain
($mimetype);
2384 git_header_html
(undef, $expires);
2385 my $formats_nav = '';
2386 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2387 if (defined $file_name) {
2390 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2391 hash
=>$hash, file_name
=>$file_name)},
2396 $cgi->a({-href
=> href
(action
=>"blob_plain",
2397 hash
=>$hash, file_name
=>$file_name)},
2400 $cgi->a({-href
=> href
(action
=>"blob",
2401 hash_base
=>"HEAD", file_name
=>$file_name)},
2405 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2407 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2408 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2410 print "<div class=\"page_nav\">\n" .
2411 "<br/><br/></div>\n" .
2412 "<div class=\"title\">$hash</div>\n";
2414 git_print_page_path
($file_name, "blob", $hash_base);
2415 print "<div class=\"page_body\">\n";
2417 while (my $line = <$fd>) {
2420 $line = untabify
($line);
2421 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2422 $nr, $nr, $nr, esc_html
($line);
2425 or print "Reading blob failed.\n";
2431 if (!defined $hash) {
2432 $hash = git_get_head_hash
($project);
2433 if (defined $file_name) {
2434 my $base = $hash_base || $hash;
2435 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2437 if (!defined $hash_base) {
2442 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2443 or die_error
(undef, "Open git-ls-tree failed");
2444 my @entries = map { chomp; $_ } <$fd>;
2445 close $fd or die_error
(undef, "Reading tree failed");
2448 my $refs = git_get_references
();
2449 my $ref = format_ref_marker
($refs, $hash_base);
2453 my $have_blame = gitweb_check_feature
('blame');
2454 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2455 $base_key{hash_base
} = $hash_base;
2456 git_print_page_nav
('tree','', $hash_base);
2457 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2459 print "<div class=\"page_nav\">\n";
2460 print "<br/><br/></div>\n";
2461 print "<div class=\"title\">$hash</div>\n";
2463 if (defined $file_name) {
2464 $base = esc_html
("$file_name/");
2466 git_print_page_path
($file_name, 'tree', $hash_base);
2467 print "<div class=\"page_body\">\n";
2468 print "<table cellspacing=\"0\">\n";
2470 foreach my $line (@entries) {
2471 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2472 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2476 my $t_name = validate_input
($4);
2478 print "<tr class=\"dark\">\n";
2480 print "<tr class=\"light\">\n";
2483 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2484 if ($t_type eq "blob") {
2485 print "<td class=\"list\">" .
2486 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key),
2487 -class => "list"}, esc_html
($t_name)) .
2489 "<td class=\"link\">" .
2490 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2494 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2498 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2499 hash
=>$t_hash, file_name
=>"$base$t_name")},
2502 $cgi->a({-href
=> href
(action
=>"blob_plain",
2503 hash
=>$t_hash, file_name
=>"$base$t_name")},
2506 } elsif ($t_type eq "tree") {
2507 print "<td class=\"list\">" .
2508 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2509 esc_html
($t_name)) .
2511 "<td class=\"link\">" .
2512 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2515 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")},
2521 print "</table>\n" .
2528 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2529 my $have_snapshot = (defined $ctype && defined $suffix);
2530 if (!$have_snapshot) {
2531 die_error
('403 Permission denied', "Permission denied");
2534 if (!defined $hash) {
2535 $hash = git_get_head_hash
($project);
2538 my $filename = basename
($project) . "-$hash.tar.$suffix";
2540 print $cgi->header(-type
=> 'application/x-tar',
2541 -content_encoding
=> $ctype,
2542 -content_disposition
=> "inline; filename=\"$filename\"",
2543 -status
=> '200 OK');
2545 my $git_command = git_cmd_str
();
2546 open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
2547 die_error
(undef, "Execute git-tar-tree failed.");
2548 binmode STDOUT
, ':raw';
2550 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2556 my $head = git_get_head_hash
($project);
2557 if (!defined $hash) {
2560 if (!defined $page) {
2563 my $refs = git_get_references
();
2565 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2566 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2567 or die_error
(undef, "Open git-rev-list failed");
2568 my @revlist = map { chomp; $_ } <$fd>;
2571 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2574 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2577 my %co = parse_commit
($hash);
2579 git_print_header_div
('summary', $project);
2580 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2582 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2583 my $commit = $revlist[$i];
2584 my $ref = format_ref_marker
($refs, $commit);
2585 my %co = parse_commit
($commit);
2587 my %ad = parse_date
($co{'author_epoch'});
2588 git_print_header_div
('commit',
2589 "<span class=\"age\">$co{'age_string'}</span>" .
2590 esc_html
($co{'title'}) . $ref,
2592 print "<div class=\"title_text\">\n" .
2593 "<div class=\"log_link\">\n" .
2594 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2596 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2599 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2602 print "<div class=\"log_body\">\n";
2603 git_print_simplified_log
($co{'comment'});
2610 my %co = parse_commit
($hash);
2612 die_error
(undef, "Unknown commit object");
2614 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2615 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2617 my $parent = $co{'parent'};
2618 if (!defined $parent) {
2621 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
2622 or die_error
(undef, "Open git-diff-tree failed");
2623 my @difftree = map { chomp; $_ } <$fd>;
2624 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2626 # non-textual hash id's can be cached
2628 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2631 my $refs = git_get_references
();
2632 my $ref = format_ref_marker
($refs, $co{'id'});
2634 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2635 my $have_snapshot = (defined $ctype && defined $suffix);
2637 my $formats_nav = '';
2638 if (defined $file_name && defined $co{'parent'}) {
2639 my $parent = $co{'parent'};
2641 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2644 git_header_html
(undef, $expires);
2645 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2646 $hash, $co{'tree'}, $hash,
2649 if (defined $co{'parent'}) {
2650 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2652 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2654 print "<div class=\"title_text\">\n" .
2655 "<table cellspacing=\"0\">\n";
2656 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2658 "<td></td><td> $ad{'rfc2822'}";
2659 if ($ad{'hour_local'} < 6) {
2660 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2661 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2663 printf(" (%02d:%02d %s)",
2664 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2668 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2669 print "<tr><td></td><td> $cd{'rfc2822'}" .
2670 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2672 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2675 "<td class=\"sha1\">" .
2676 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2677 class => "list"}, $co{'tree'}) .
2679 "<td class=\"link\">" .
2680 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
2682 if ($have_snapshot) {
2684 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2688 my $parents = $co{'parents'};
2689 foreach my $par (@
$parents) {
2692 "<td class=\"sha1\">" .
2693 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
2694 class => "list"}, $par) .
2696 "<td class=\"link\">" .
2697 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2699 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2706 print "<div class=\"page_body\">\n";
2707 git_print_log
($co{'comment'});
2710 git_difftree_body
(\
@difftree, $hash, $parent);
2716 my $format = shift || 'html';
2723 # preparing $fd and %diffinfo for git_patchset_body
2725 if (defined $hash_base && defined $hash_parent_base) {
2726 if (defined $file_name) {
2728 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
2730 or die_error
(undef, "Open git-diff-tree failed");
2731 @difftree = map { chomp; $_ } <$fd>;
2733 or die_error
(undef, "Reading git-diff-tree failed");
2735 or die_error
('404 Not Found', "Blob diff not found");
2737 } elsif (defined $hash) { # try to find filename from $hash
2738 if ($hash !~ /[0-9a-fA-F]{40}/) {
2739 $hash = git_to_hash
($hash);
2741 } elsif (defined $hash &&
2742 $hash =~ /[0-9a-fA-F]{40}/) {
2743 # try to find filename from $hash
2745 # read filtered raw output
2746 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
2747 or die_error
(undef, "Open git-diff-tree failed");
2749 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2751 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2752 map { chomp; $_ } <$fd>;
2754 or die_error
(undef, "Reading git-diff-tree failed");
2756 or die_error
('404 Not Found', "Blob diff not found");
2759 die_error
('404 Not Found', "Missing one of the blob diff parameters");
2762 if (@difftree > 1) {
2763 die_error
('404 Not Found', "Ambiguous blob diff specification");
2766 %diffinfo = parse_difftree_raw_line
($difftree[0]);
2767 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2768 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2770 $hash_parent ||= $diffinfo{'from_id'};
2771 $hash ||= $diffinfo{'to_id'};
2773 # non-textual hash id's can be cached
2774 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
2775 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
2780 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
2781 '-p', $hash_parent_base, $hash_base,
2783 or die_error
(undef, "Open git-diff-tree failed");
2786 # old/legacy style URI
2787 if (!%diffinfo && # if new style URI failed
2788 defined $hash && defined $hash_parent) {
2789 # fake git-diff-tree raw output
2790 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2791 $diffinfo{'from_id'} = $hash_parent;
2792 $diffinfo{'to_id'} = $hash;
2793 if (defined $file_name) {
2794 if (defined $file_parent) {
2795 $diffinfo{'status'} = '2';
2796 $diffinfo{'from_file'} = $file_parent;
2797 $diffinfo{'to_file'} = $file_name;
2798 } else { # assume not renamed
2799 $diffinfo{'status'} = '1';
2800 $diffinfo{'from_file'} = $file_name;
2801 $diffinfo{'to_file'} = $file_name;
2803 } else { # no filename given
2804 $diffinfo{'status'} = '2';
2805 $diffinfo{'from_file'} = $hash_parent;
2806 $diffinfo{'to_file'} = $hash;
2809 # non-textual hash id's can be cached
2810 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
2811 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
2816 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
2817 or die_error
(undef, "Open git-diff failed");
2819 die_error
('404 Not Found', "Missing one of the blob diff parameters")
2824 if ($format eq 'html') {
2826 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
2827 hash
=>$hash, hash_parent
=>$hash_parent,
2828 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
2829 file_name
=>$file_name, file_parent
=>$file_parent)},
2831 git_header_html
(undef, $expires);
2832 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2833 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2834 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2836 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
2837 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
2839 if (defined $file_name) {
2840 git_print_page_path
($file_name, "blob", $hash_base);
2842 print "<div class=\"page_path\"></div>\n";
2845 } elsif ($format eq 'plain') {
2847 -type
=> 'text/plain',
2848 -charset
=> 'utf-8',
2849 -expires
=> $expires,
2850 -content_disposition
=> qq(inline
; filename
="${file_name}.patch"));
2852 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2855 die_error
(undef, "Unknown blobdiff format");
2859 if ($format eq 'html') {
2860 print "<div class=\"page_body\">\n";
2862 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
2865 print "</div>\n"; # class="page_body"
2869 while (my $line = <$fd>) {
2870 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
2871 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
2875 last if $line =~ m!^\+\+\+!;
2883 sub git_blobdiff_plain
{
2884 git_blobdiff
('plain');
2887 sub git_commitdiff
{
2888 my $format = shift || 'html';
2889 my %co = parse_commit
($hash);
2891 die_error
(undef, "Unknown commit object");
2893 if (!defined $hash_parent) {
2894 $hash_parent = $co{'parent'} || '--root';
2900 if ($format eq 'html') {
2901 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
2902 "--patch-with-raw", "--full-index", $hash_parent, $hash
2903 or die_error
(undef, "Open git-diff-tree failed");
2905 while (chomp(my $line = <$fd>)) {
2906 # empty line ends raw part of diff-tree output
2908 push @difftree, $line;
2911 } elsif ($format eq 'plain') {
2912 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
2913 '-p', $hash_parent, $hash
2914 or die_error
(undef, "Open git-diff-tree failed");
2917 die_error
(undef, "Unknown commitdiff format");
2920 # non-textual hash id's can be cached
2922 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2926 # write commit message
2927 if ($format eq 'html') {
2928 my $refs = git_get_references
();
2929 my $ref = format_ref_marker
($refs, $co{'id'});
2931 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
2932 hash
=>$hash, hash_parent
=>$hash_parent)},
2935 git_header_html
(undef, $expires);
2936 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2937 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2938 print "<div class=\"page_body\">\n";
2939 print "<div class=\"log\">\n";
2940 git_print_simplified_log
($co{'comment'}, 1); # skip title
2941 print "</div>\n"; # class="log"
2943 } elsif ($format eq 'plain') {
2944 my $refs = git_get_references
("tags");
2945 my $tagname = git_get_rev_name_tags
($hash);
2946 my $filename = basename
($project) . "-$hash.patch";
2949 -type
=> 'text/plain',
2950 -charset
=> 'utf-8',
2951 -expires
=> $expires,
2952 -content_disposition
=> qq(inline
; filename
="$filename"));
2953 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2956 Date: $ad{'rfc2822'} ($ad{'tz_local'})
2957 Subject: $co{'title'}
2959 print "X-Git-Tag: $tagname\n" if $tagname;
2960 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2962 foreach my $line (@
{$co{'comment'}}) {
2969 if ($format eq 'html') {
2970 #git_difftree_body(\@difftree, $hash, $hash_parent);
2973 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
2975 print "</div>\n"; # class="page_body"
2978 } elsif ($format eq 'plain') {
2982 or print "Reading git-diff-tree failed\n";
2986 sub git_commitdiff_plain
{
2987 git_commitdiff
('plain');
2991 if (!defined $hash_base) {
2992 $hash_base = git_get_head_hash
($project);
2995 my %co = parse_commit
($hash_base);
2997 die_error
(undef, "Unknown commit object");
2999 my $refs = git_get_references
();
3001 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
3002 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3003 if (!defined $hash && defined $file_name) {
3004 $hash = git_get_hash_by_path
($hash_base, $file_name);
3006 if (defined $hash) {
3007 $ftype = git_get_type
($hash);
3009 git_print_page_path
($file_name, $ftype, $hash_base);
3012 git_cmd
(), "rev-list", "--full-history", $hash_base, "--", $file_name;
3014 git_history_body
($fd, $refs, $hash_base, $ftype);
3021 if (!defined $searchtext) {
3022 die_error
(undef, "Text field empty");
3024 if (!defined $hash) {
3025 $hash = git_get_head_hash
($project);
3027 my %co = parse_commit
($hash);
3029 die_error
(undef, "Unknown commit object");
3031 # pickaxe may take all resources of your box and run for several minutes
3032 # with every query - so decide by yourself how public you make this feature :)
3033 my $commit_search = 1;
3034 my $author_search = 0;
3035 my $committer_search = 0;
3036 my $pickaxe_search = 0;
3037 if ($searchtext =~ s/^author\\://i) {
3039 } elsif ($searchtext =~ s/^committer\\://i) {
3040 $committer_search = 1;
3041 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3043 $pickaxe_search = 1;
3046 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3047 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3049 print "<table cellspacing=\"0\">\n";
3051 if ($commit_search) {
3053 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3054 while (my $commit_text = <$fd>) {
3055 if (!grep m/$searchtext/i, $commit_text) {
3058 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3061 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3064 my @commit_lines = split "\n", $commit_text;
3065 my %co = parse_commit
(undef, \
@commit_lines);
3070 print "<tr class=\"dark\">\n";
3072 print "<tr class=\"light\">\n";
3075 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3076 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3078 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3079 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3080 my $comment = $co{'comment'};
3081 foreach my $line (@
$comment) {
3082 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3083 my $lead = esc_html
($1) || "";
3084 $lead = chop_str
($lead, 30, 10);
3085 my $match = esc_html
($2) || "";
3086 my $trail = esc_html
($3) || "";
3087 $trail = chop_str
($trail, 30, 10);
3088 my $text = "$lead<span class=\"match\">$match</span>$trail";
3089 print chop_str
($text, 80, 5) . "<br/>\n";
3093 "<td class=\"link\">" .
3094 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3096 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3103 if ($pickaxe_search) {
3105 my $git_command = git_cmd_str
();
3106 open my $fd, "-|", "$git_command rev-list $hash | " .
3107 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3110 while (my $line = <$fd>) {
3111 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3114 $set{'from_id'} = $3;
3116 $set{'id'} = $set{'to_id'};
3117 if ($set{'id'} =~ m/0{40}/) {
3118 $set{'id'} = $set{'from_id'};
3120 if ($set{'id'} =~ m/0{40}/) {
3124 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3127 print "<tr class=\"dark\">\n";
3129 print "<tr class=\"light\">\n";
3132 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3133 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3135 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3136 -class => "list subject"},
3137 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3138 while (my $setref = shift @files) {
3140 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3141 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3143 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3147 "<td class=\"link\">" .
3148 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3150 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3154 %co = parse_commit
($1);
3164 my $head = git_get_head_hash
($project);
3165 if (!defined $hash) {
3168 if (!defined $page) {
3171 my $refs = git_get_references
();
3173 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3174 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3175 or die_error
(undef, "Open git-rev-list failed");
3176 my @revlist = map { chomp; $_ } <$fd>;
3179 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3181 if ($#revlist >= (100 * ($page+1)-1)) {
3183 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3184 -title
=> "Alt-n"}, "next");
3189 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3190 git_print_header_div
('summary', $project);
3192 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3197 ## ......................................................................
3198 ## feeds (RSS, OPML)
3201 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3202 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3203 or die_error
(undef, "Open git-rev-list failed");
3204 my @revlist = map { chomp; $_ } <$fd>;
3205 close $fd or die_error
(undef, "Reading git-rev-list failed");
3206 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3208 <?xml version="1.0" encoding="utf-8"?>
3209 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3211 <title>$project $my_uri $my_url</title>
3212 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3213 <description>$project log</description>
3214 <language>en</language>
3217 for (my $i = 0; $i <= $#revlist; $i++) {
3218 my $commit = $revlist[$i];
3219 my %co = parse_commit
($commit);
3220 # we read 150, we always show 30 and the ones more recent than 48 hours
3221 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3224 my %cd = parse_date
($co{'committer_epoch'});
3225 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3226 $co{'parent'}, $co{'id'}
3228 my @difftree = map { chomp; $_ } <$fd>;
3233 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3235 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3236 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3237 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3238 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3239 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3240 "<content:encoded>" .
3242 my $comment = $co{'comment'};
3243 foreach my $line (@
$comment) {
3244 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3245 print "$line<br/>\n";
3248 foreach my $line (@difftree) {
3249 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3252 my $file = validate_input
(unquote
($7));
3253 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3254 print "$file<br/>\n";
3257 "</content:encoded>\n" .
3260 print "</channel></rss>";
3264 my @list = git_get_projects_list
();
3266 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3268 <?xml version="1.0" encoding="utf-8"?>
3269 <opml version="1.0">
3271 <title>$site_name Git OPML Export</title>
3274 <outline text="git RSS feeds">
3277 foreach my $pr (@list) {
3279 my $head = git_get_head_hash
($proj{'path'});
3280 if (!defined $head) {
3283 $git_dir = "$projectroot/$proj{'path'}";
3284 my %co = parse_commit
($head);
3289 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3290 my $rss = "$my_url?p=$proj{'path'};a=rss";
3291 my $html = "$my_url?p=$proj{'path'};a=summary";
3292 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";