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 # filename of html text to include at top of each page
45 our $site_header = "++GITWEB_SITE_HEADER++";
46 # html text to include at home page
47 our $home_text = "++GITWEB_HOMETEXT++";
48 # filename of html text to include at bottom of each page
49 our $site_footer = "++GITWEB_SITE_FOOTER++";
52 our @stylesheets = ("++GITWEB_CSS++");
54 # default is not to define style sheet, but it can be overwritten later
58 our $logo = "++GITWEB_LOGO++";
59 # URI of GIT favicon, assumed to be image/png type
60 our $favicon = "++GITWEB_FAVICON++";
62 # source of projects list
63 our $projects_list = "++GITWEB_LIST++";
65 # show repository only if this file exists
66 # (only effective if this variable evaluates to true)
67 our $export_ok = "++GITWEB_EXPORT_OK++";
69 # only allow viewing of repositories also shown on the overview page
70 our $strict_export = "++GITWEB_STRICT_EXPORT++";
72 # list of git base URLs used for URL to where fetch project from,
73 # i.e. full URL is "$git_base_url/$project"
74 our @git_base_url_list = ("++GITWEB_BASE_URL++");
76 # default blob_plain mimetype and default charset for text/plain blob
77 our $default_blob_plain_mimetype = 'text/plain';
78 our $default_text_plain_charset = undef;
80 # file to use for guessing MIME types before trying /etc/mime.types
81 # (relative to the current git repository)
82 our $mimetypes_file = undef;
84 # You define site-wide feature defaults here; override them with
85 # $GITWEB_CONFIG as necessary.
88 # 'sub' => feature-sub (subroutine),
89 # 'override' => allow-override (boolean),
90 # 'default' => [ default options...] (array reference)}
92 # if feature is overridable (it means that allow-override has true value,
93 # then feature-sub will be called with default options as parameters;
94 # return value of feature-sub indicates if to enable specified feature
96 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
99 'sub' => \
&feature_blame
,
104 'sub' => \
&feature_snapshot
,
106 # => [content-encoding, suffix, program]
107 'default' => ['x-gzip', 'gz', 'gzip']},
110 'sub' => \
&feature_pickaxe
,
115 sub gitweb_check_feature
{
117 return unless exists $feature{$name};
118 my ($sub, $override, @defaults) = (
119 $feature{$name}{'sub'},
120 $feature{$name}{'override'},
121 @
{$feature{$name}{'default'}});
122 if (!$override) { return @defaults; }
123 return $sub->(@defaults);
126 # To enable system wide have in $GITWEB_CONFIG
127 # $feature{'blame'}{'default'} = [1];
128 # To have project specific config enable override in $GITWEB_CONFIG
129 # $feature{'blame'}{'override'} = 1;
130 # and in project config gitweb.blame = 0|1;
133 my ($val) = git_get_project_config
('blame', '--bool');
135 if ($val eq 'true') {
137 } elsif ($val eq 'false') {
144 # To disable system wide have in $GITWEB_CONFIG
145 # $feature{'snapshot'}{'default'} = [undef];
146 # To have project specific config enable override in $GITWEB_CONFIG
147 # $feature{'blame'}{'override'} = 1;
148 # and in project config gitweb.snapshot = none|gzip|bzip2
150 sub feature_snapshot
{
151 my ($ctype, $suffix, $command) = @_;
153 my ($val) = git_get_project_config
('snapshot');
155 if ($val eq 'gzip') {
156 return ('x-gzip', 'gz', 'gzip');
157 } elsif ($val eq 'bzip2') {
158 return ('x-bzip2', 'bz2', 'bzip2');
159 } elsif ($val eq 'none') {
163 return ($ctype, $suffix, $command);
166 sub gitweb_have_snapshot
{
167 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
168 my $have_snapshot = (defined $ctype && defined $suffix);
170 return $have_snapshot;
173 # To enable system wide have in $GITWEB_CONFIG
174 # $feature{'pickaxe'}{'default'} = [1];
175 # To have project specific config enable override in $GITWEB_CONFIG
176 # $feature{'pickaxe'}{'override'} = 1;
177 # and in project config gitweb.pickaxe = 0|1;
179 sub feature_pickaxe
{
180 my ($val) = git_get_project_config
('pickaxe', '--bool');
182 if ($val eq 'true') {
184 } elsif ($val eq 'false') {
191 # checking HEAD file with -e is fragile if the repository was
192 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
194 sub check_head_link
{
196 my $headfile = "$dir/HEAD";
197 return ((-e
$headfile) ||
198 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
201 sub check_export_ok
{
203 return (check_head_link
($dir) &&
204 (!$export_ok || -e
"$dir/$export_ok"));
207 # rename detection options for git-diff and git-diff-tree
208 # - default is '-M', with the cost proportional to
209 # (number of removed files) * (number of new files).
210 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
211 # (number of changed files + number of removed files) * (number of new files)
212 # - even more costly is '-C', '--find-copies-harder' with cost
213 # (number of files in the original tree) * (number of new files)
214 # - one might want to include '-B' option, e.g. '-B', '-M'
215 our @diff_opts = ('-M'); # taken from git_commit
217 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
218 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
220 # version of the core git binary
221 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
223 $projects_list ||= $projectroot;
225 # ======================================================================
226 # input validation and dispatch
227 our $action = $cgi->param('a');
228 if (defined $action) {
229 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
230 die_error
(undef, "Invalid action parameter");
234 # parameters which are pathnames
235 our $project = $cgi->param('p');
236 if (defined $project) {
237 if (!validate_pathname
($project) ||
238 !(-d
"$projectroot/$project") ||
239 !check_head_link
("$projectroot/$project") ||
240 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
241 ($strict_export && !project_in_list
($project))) {
243 die_error
(undef, "No such project");
247 our $file_name = $cgi->param('f');
248 if (defined $file_name) {
249 if (!validate_pathname
($file_name)) {
250 die_error
(undef, "Invalid file parameter");
254 our $file_parent = $cgi->param('fp');
255 if (defined $file_parent) {
256 if (!validate_pathname
($file_parent)) {
257 die_error
(undef, "Invalid file parent parameter");
261 # parameters which are refnames
262 our $hash = $cgi->param('h');
264 if (!validate_refname
($hash)) {
265 die_error
(undef, "Invalid hash parameter");
269 our $hash_parent = $cgi->param('hp');
270 if (defined $hash_parent) {
271 if (!validate_refname
($hash_parent)) {
272 die_error
(undef, "Invalid hash parent parameter");
276 our $hash_base = $cgi->param('hb');
277 if (defined $hash_base) {
278 if (!validate_refname
($hash_base)) {
279 die_error
(undef, "Invalid hash base parameter");
283 our $hash_parent_base = $cgi->param('hpb');
284 if (defined $hash_parent_base) {
285 if (!validate_refname
($hash_parent_base)) {
286 die_error
(undef, "Invalid hash parent base parameter");
291 our $page = $cgi->param('pg');
293 if ($page =~ m/[^0-9]/) {
294 die_error
(undef, "Invalid page parameter");
298 our $searchtext = $cgi->param('s');
299 if (defined $searchtext) {
300 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
301 die_error
(undef, "Invalid search parameter");
303 $searchtext = quotemeta $searchtext;
306 # now read PATH_INFO and use it as alternative to parameters
307 sub evaluate_path_info
{
308 return if defined $project;
309 my $path_info = $ENV{"PATH_INFO"};
310 return if !$path_info;
311 $path_info =~ s
,^/+,,;
312 return if !$path_info;
313 # find which part of PATH_INFO is project
314 $project = $path_info;
316 while ($project && !check_head_link
("$projectroot/$project")) {
317 $project =~ s
,/*[^/]*$,,;
320 $project = validate_pathname
($project);
322 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
323 ($strict_export && !project_in_list
($project))) {
327 # do not change any parameters if an action is given using the query string
329 $path_info =~ s
,^$project/*,,;
330 my ($refname, $pathname) = split(/:/, $path_info, 2);
331 if (defined $pathname) {
332 # we got "project.git/branch:filename" or "project.git/branch:dir/"
333 # we could use git_get_type(branch:pathname), but it needs $git_dir
334 $pathname =~ s
,^/+,,;
335 if (!$pathname || substr($pathname, -1) eq "/") {
339 $action ||= "blob_plain";
341 $hash_base ||= validate_refname
($refname);
342 $file_name ||= validate_pathname
($pathname);
343 } elsif (defined $refname) {
344 # we got "project.git/branch"
345 $action ||= "shortlog";
346 $hash ||= validate_refname
($refname);
349 evaluate_path_info
();
351 # path to the current git repository
353 $git_dir = "$projectroot/$project" if $project;
357 "blame" => \
&git_blame2
,
358 "blobdiff" => \
&git_blobdiff
,
359 "blobdiff_plain" => \
&git_blobdiff_plain
,
360 "blob" => \
&git_blob
,
361 "blob_plain" => \
&git_blob_plain
,
362 "commitdiff" => \
&git_commitdiff
,
363 "commitdiff_plain" => \
&git_commitdiff_plain
,
364 "commit" => \
&git_commit
,
365 "heads" => \
&git_heads
,
366 "history" => \
&git_history
,
369 "search" => \
&git_search
,
370 "shortlog" => \
&git_shortlog
,
371 "summary" => \
&git_summary
,
373 "tags" => \
&git_tags
,
374 "tree" => \
&git_tree
,
375 "snapshot" => \
&git_snapshot
,
376 # those below don't need $project
377 "opml" => \
&git_opml
,
378 "project_list" => \
&git_project_list
,
379 "project_index" => \
&git_project_index
,
382 if (defined $project) {
383 $action ||= 'summary';
385 $action ||= 'project_list';
387 if (!defined($actions{$action})) {
388 die_error
(undef, "Unknown action");
390 if ($action !~ m/^(opml|project_list|project_index)$/ &&
392 die_error
(undef, "Project needed");
394 $actions{$action}->();
397 ## ======================================================================
411 hash_parent_base
=> "hpb",
416 my %mapping = @mapping;
418 $params{'project'} = $project unless exists $params{'project'};
421 for (my $i = 0; $i < @mapping; $i += 2) {
422 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
423 if (defined $params{$name}) {
424 push @result, $symbol . "=" . esc_param
($params{$name});
427 return "$my_uri?" . join(';', @result);
431 ## ======================================================================
432 ## validation, quoting/unquoting and escaping
434 sub validate_pathname
{
435 my $input = shift || return undef;
437 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
438 # at the beginning, at the end, and between slashes.
439 # also this catches doubled slashes
440 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
444 if ($input =~ m!\0!) {
450 sub validate_refname
{
451 my $input = shift || return undef;
453 # textual hashes are O.K.
454 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
457 # it must be correct pathname
458 $input = validate_pathname
($input)
460 # restrictions on ref name according to git-check-ref-format
461 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
467 # quote unsafe chars, but keep the slash, even when it's not
468 # correct, but quoted slashes look too horrible in bookmarks
471 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
477 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
480 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
486 # replace invalid utf8 character with SUBSTITUTION sequence
489 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
490 $str = escapeHTML
($str);
491 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
492 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
496 # git may return quoted and escaped filenames
499 if ($str =~ m/^"(.*)"$/) {
501 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
506 # escape tabs (convert tabs to spaces)
510 while ((my $pos = index($line, "\t")) != -1) {
511 if (my $count = (8 - ($pos % 8))) {
512 my $spaces = ' ' x
$count;
513 $line =~ s/\t/$spaces/;
520 sub project_in_list
{
522 my @list = git_get_projects_list
();
523 return @list && scalar(grep { $_->{'path'} eq $project } @list);
526 ## ----------------------------------------------------------------------
527 ## HTML aware string manipulation
532 my $add_len = shift || 10;
534 # allow only $len chars, but don't cut a word if it would fit in $add_len
535 # if it doesn't fit, cut it if it's still longer than the dots we would add
536 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
539 if (length($tail) > 4) {
541 $body =~ s/&[^;]*$//; # remove chopped character entities
546 ## ----------------------------------------------------------------------
547 ## functions returning short strings
549 # CSS class for given age value (in seconds)
553 if ($age < 60*60*2) {
555 } elsif ($age < 60*60*24*2) {
562 # convert age in seconds to "nn units ago" string
567 if ($age > 60*60*24*365*2) {
568 $age_str = (int $age/60/60/24/365);
569 $age_str .= " years ago";
570 } elsif ($age > 60*60*24*(365/12)*2) {
571 $age_str = int $age/60/60/24/(365/12);
572 $age_str .= " months ago";
573 } elsif ($age > 60*60*24*7*2) {
574 $age_str = int $age/60/60/24/7;
575 $age_str .= " weeks ago";
576 } elsif ($age > 60*60*24*2) {
577 $age_str = int $age/60/60/24;
578 $age_str .= " days ago";
579 } elsif ($age > 60*60*2) {
580 $age_str = int $age/60/60;
581 $age_str .= " hours ago";
582 } elsif ($age > 60*2) {
583 $age_str = int $age/60;
584 $age_str .= " min ago";
587 $age_str .= " sec ago";
589 $age_str .= " right now";
594 # convert file mode in octal to symbolic file mode string
596 my $mode = oct shift;
598 if (S_ISDIR
($mode & S_IFMT
)) {
600 } elsif (S_ISLNK
($mode)) {
602 } elsif (S_ISREG
($mode)) {
603 # git cares only about the executable bit
604 if ($mode & S_IXUSR
) {
614 # convert file mode in octal to file type string
618 if ($mode !~ m/^[0-7]+$/) {
624 if (S_ISDIR
($mode & S_IFMT
)) {
626 } elsif (S_ISLNK
($mode)) {
628 } elsif (S_ISREG
($mode)) {
635 ## ----------------------------------------------------------------------
636 ## functions returning short HTML fragments, or transforming HTML fragments
637 ## which don't beling to other sections
639 # format line of commit message or tag comment
640 sub format_log_line_html
{
643 $line = esc_html
($line);
644 $line =~ s/ / /g;
645 if ($line =~ m/([0-9a-fA-F]{40})/) {
647 if (git_get_type
($hash_text) eq "commit") {
649 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
650 -class => "text"}, $hash_text);
651 $line =~ s/$hash_text/$link/;
657 # format marker of refs pointing to given object
658 sub format_ref_marker
{
659 my ($refs, $id) = @_;
662 if (defined $refs->{$id}) {
663 foreach my $ref (@
{$refs->{$id}}) {
664 my ($type, $name) = qw();
665 # e.g. tags/v2.6.11 or heads/next
666 if ($ref =~ m!^(.*?)s?/(.*)$!) {
674 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
679 return ' <span class="refs">'. $markers . '</span>';
685 # format, perhaps shortened and with markers, title line
686 sub format_subject_html
{
687 my ($long, $short, $href, $extra) = @_;
688 $extra = '' unless defined($extra);
690 if (length($short) < length($long)) {
691 return $cgi->a({-href
=> $href, -class => "list subject",
692 -title
=> decode
("utf8", $long, Encode
::FB_DEFAULT
)},
693 esc_html
($short) . $extra);
695 return $cgi->a({-href
=> $href, -class => "list subject"},
696 esc_html
($long) . $extra);
700 sub format_diff_line
{
702 my $char = substr($line, 0, 1);
708 $diff_class = " add";
709 } elsif ($char eq "-") {
710 $diff_class = " rem";
711 } elsif ($char eq "@") {
712 $diff_class = " chunk_header";
713 } elsif ($char eq "\\") {
714 $diff_class = " incomplete";
716 $line = untabify
($line);
717 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
720 ## ----------------------------------------------------------------------
721 ## git utility subroutines, invoking git commands
723 # returns path to the core git executable and the --git-dir parameter as list
725 return $GIT, '--git-dir='.$git_dir;
728 # returns path to the core git executable and the --git-dir parameter as string
730 return join(' ', git_cmd
());
733 # get HEAD ref of given project as hash
734 sub git_get_head_hash
{
736 my $o_git_dir = $git_dir;
738 $git_dir = "$projectroot/$project";
739 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
742 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
746 if (defined $o_git_dir) {
747 $git_dir = $o_git_dir;
752 # get type of given object
756 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
763 sub git_get_project_config
{
764 my ($key, $type) = @_;
766 return unless ($key);
767 $key =~ s/^gitweb\.//;
768 return if ($key =~ m/\W/);
770 my @x = (git_cmd
(), 'repo-config');
771 if (defined $type) { push @x, $type; }
773 push @x, "gitweb.$key";
779 # get hash of given path at given ref
780 sub git_get_hash_by_path
{
782 my $path = shift || return undef;
787 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
788 or die_error
(undef, "Open git-ls-tree failed");
790 close $fd or return undef;
792 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
793 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
794 if (defined $type && $type ne $2) {
801 ## ......................................................................
802 ## git utility functions, directly accessing git repository
804 sub git_get_project_description
{
807 open my $fd, "$projectroot/$path/description" or return undef;
814 sub git_get_project_url_list
{
817 open my $fd, "$projectroot/$path/cloneurl" or return;
818 my @git_project_url_list = map { chomp; $_ } <$fd>;
821 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
824 sub git_get_projects_list
{
827 if (-d
$projects_list) {
828 # search in directory
829 my $dir = $projects_list;
830 my $pfxlen = length("$dir");
833 follow_fast
=> 1, # follow symbolic links
834 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
836 # skip project-list toplevel, if we get it.
837 return if (m!^[/.]$!);
838 # only directories can be git repositories
839 return unless (-d
$_);
841 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
842 # we check related file in $projectroot
843 if (check_export_ok
("$projectroot/$subdir")) {
844 push @list, { path
=> $subdir };
845 $File::Find
::prune
= 1;
850 } elsif (-f
$projects_list) {
851 # read from file(url-encoded):
852 # 'git%2Fgit.git Linus+Torvalds'
853 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
854 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
855 open my ($fd), $projects_list or return;
856 while (my $line = <$fd>) {
858 my ($path, $owner) = split ' ', $line;
859 $path = unescape
($path);
860 $owner = unescape
($owner);
861 if (!defined $path) {
864 if (check_export_ok
("$projectroot/$path")) {
867 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
874 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
878 sub git_get_project_owner
{
882 return undef unless $project;
884 # read from file (url-encoded):
885 # 'git%2Fgit.git Linus+Torvalds'
886 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
887 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
888 if (-f
$projects_list) {
889 open (my $fd , $projects_list);
890 while (my $line = <$fd>) {
892 my ($pr, $ow) = split ' ', $line;
895 if ($pr eq $project) {
896 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
902 if (!defined $owner) {
903 $owner = get_file_owner
("$projectroot/$project");
909 sub git_get_references
{
910 my $type = shift || "";
912 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
913 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
914 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
917 while (my $line = <$fd>) {
919 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
920 if (defined $refs{$1}) {
921 push @
{$refs{$1}}, $2;
931 sub git_get_rev_name_tags
{
932 my $hash = shift || return undef;
934 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
936 my $name_rev = <$fd>;
939 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
942 # catches also '$hash undefined' output
947 ## ----------------------------------------------------------------------
948 ## parse to hash functions
952 my $tz = shift || "-0000";
955 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
956 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
957 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
958 $date{'hour'} = $hour;
959 $date{'minute'} = $min;
960 $date{'mday'} = $mday;
961 $date{'day'} = $days[$wday];
962 $date{'month'} = $months[$mon];
963 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
964 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
965 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
966 $mday, $months[$mon], $hour ,$min;
968 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
969 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
970 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
971 $date{'hour_local'} = $hour;
972 $date{'minute_local'} = $min;
973 $date{'tz_local'} = $tz;
982 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
983 $tag{'id'} = $tag_id;
984 while (my $line = <$fd>) {
986 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
988 } elsif ($line =~ m/^type (.+)$/) {
990 } elsif ($line =~ m/^tag (.+)$/) {
992 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
996 } elsif ($line =~ m/--BEGIN/) {
997 push @comment, $line;
999 } elsif ($line eq "") {
1003 push @comment, <$fd>;
1004 $tag{'comment'} = \
@comment;
1005 close $fd or return;
1006 if (!defined $tag{'name'}) {
1012 sub git_get_last_activity
{
1016 $git_dir = "$projectroot/$path";
1017 open($fd, "-|", git_cmd
(), 'for-each-ref',
1018 '--format=%(refname) %(committer)',
1019 '--sort=-committerdate',
1020 'refs/heads') or return;
1021 my $most_recent = <$fd>;
1022 close $fd or return;
1023 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1025 my $age = time - $timestamp;
1026 return ($age, age_string
($age));
1031 my $commit_id = shift;
1032 my $commit_text = shift;
1037 if (defined $commit_text) {
1038 @commit_lines = @
$commit_text;
1041 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1043 @commit_lines = split '\n', <$fd>;
1044 close $fd or return;
1048 my $header = shift @commit_lines;
1049 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1052 ($co{'id'}, my @parents) = split ' ', $header;
1053 $co{'parents'} = \
@parents;
1054 $co{'parent'} = $parents[0];
1055 while (my $line = shift @commit_lines) {
1056 last if $line eq "\n";
1057 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1059 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1061 $co{'author_epoch'} = $2;
1062 $co{'author_tz'} = $3;
1063 if ($co{'author'} =~ m/^([^<]+) </) {
1064 $co{'author_name'} = $1;
1066 $co{'author_name'} = $co{'author'};
1068 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1069 $co{'committer'} = $1;
1070 $co{'committer_epoch'} = $2;
1071 $co{'committer_tz'} = $3;
1072 $co{'committer_name'} = $co{'committer'};
1073 $co{'committer_name'} =~ s/ <.*//;
1076 if (!defined $co{'tree'}) {
1080 foreach my $title (@commit_lines) {
1083 $co{'title'} = chop_str
($title, 80, 5);
1084 # remove leading stuff of merges to make the interesting part visible
1085 if (length($title) > 50) {
1086 $title =~ s/^Automatic //;
1087 $title =~ s/^merge (of|with) /Merge ... /i;
1088 if (length($title) > 50) {
1089 $title =~ s/(http|rsync):\/\///;
1091 if (length($title) > 50) {
1092 $title =~ s/(master|www|rsync)\.//;
1094 if (length($title) > 50) {
1095 $title =~ s/kernel.org:?//;
1097 if (length($title) > 50) {
1098 $title =~ s/\/pub\/scm//;
1101 $co{'title_short'} = chop_str
($title, 50, 5);
1105 # remove added spaces
1106 foreach my $line (@commit_lines) {
1109 $co{'comment'} = \
@commit_lines;
1111 my $age = time - $co{'committer_epoch'};
1113 $co{'age_string'} = age_string
($age);
1114 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1115 if ($age > 60*60*24*7*2) {
1116 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1117 $co{'age_string_age'} = $co{'age_string'};
1119 $co{'age_string_date'} = $co{'age_string'};
1120 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1125 # parse ref from ref_file, given by ref_id, with given type
1127 my $ref_file = shift;
1129 my $type = shift || git_get_type
($ref_id);
1132 $ref_item{'type'} = $type;
1133 $ref_item{'id'} = $ref_id;
1134 $ref_item{'epoch'} = 0;
1135 $ref_item{'age'} = "unknown";
1136 if ($type eq "tag") {
1137 my %tag = parse_tag
($ref_id);
1138 $ref_item{'comment'} = $tag{'comment'};
1139 if ($tag{'type'} eq "commit") {
1140 my %co = parse_commit
($tag{'object'});
1141 $ref_item{'epoch'} = $co{'committer_epoch'};
1142 $ref_item{'age'} = $co{'age_string'};
1143 } elsif (defined($tag{'epoch'})) {
1144 my $age = time - $tag{'epoch'};
1145 $ref_item{'epoch'} = $tag{'epoch'};
1146 $ref_item{'age'} = age_string
($age);
1148 $ref_item{'reftype'} = $tag{'type'};
1149 $ref_item{'name'} = $tag{'name'};
1150 $ref_item{'refid'} = $tag{'object'};
1151 } elsif ($type eq "commit"){
1152 my %co = parse_commit
($ref_id);
1153 $ref_item{'reftype'} = "commit";
1154 $ref_item{'name'} = $ref_file;
1155 $ref_item{'title'} = $co{'title'};
1156 $ref_item{'refid'} = $ref_id;
1157 $ref_item{'epoch'} = $co{'committer_epoch'};
1158 $ref_item{'age'} = $co{'age_string'};
1160 $ref_item{'reftype'} = $type;
1161 $ref_item{'name'} = $ref_file;
1162 $ref_item{'refid'} = $ref_id;
1168 # parse line of git-diff-tree "raw" output
1169 sub parse_difftree_raw_line
{
1173 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1174 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1175 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1176 $res{'from_mode'} = $1;
1177 $res{'to_mode'} = $2;
1178 $res{'from_id'} = $3;
1180 $res{'status'} = $5;
1181 $res{'similarity'} = $6;
1182 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1183 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1185 $res{'file'} = unquote
($7);
1188 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1189 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1190 $res{'commit'} = $1;
1193 return wantarray ?
%res : \
%res;
1196 # parse line of git-ls-tree output
1197 sub parse_ls_tree_line
($;%) {
1202 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1203 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1211 $res{'name'} = unquote
($4);
1214 return wantarray ?
%res : \
%res;
1217 ## ......................................................................
1218 ## parse to array of hashes functions
1220 sub git_get_refs_list
{
1221 my $type = shift || "";
1226 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1228 while (my $line = <$fd>) {
1230 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1231 if (defined $refs{$1}) {
1232 push @
{$refs{$1}}, $2;
1237 if (! $4) { # unpeeled, direct reference
1238 push @refs, { hash
=> $1, name
=> $3 }; # without type
1239 } elsif ($3 eq $refs[-1]{'name'}) {
1240 # most likely a tag is followed by its peeled
1241 # (deref) one, and when that happens we know the
1242 # previous one was of type 'tag'.
1243 $refs[-1]{'type'} = "tag";
1249 foreach my $ref (@refs) {
1250 my $ref_file = $ref->{'name'};
1251 my $ref_id = $ref->{'hash'};
1253 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1254 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1256 push @reflist, \
%ref_item;
1259 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1260 return (\
@reflist, \
%refs);
1263 ## ----------------------------------------------------------------------
1264 ## filesystem-related functions
1266 sub get_file_owner
{
1269 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1270 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1271 if (!defined $gcos) {
1275 $owner =~ s/[,;].*$//;
1276 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1279 ## ......................................................................
1280 ## mimetype related functions
1282 sub mimetype_guess_file
{
1283 my $filename = shift;
1284 my $mimemap = shift;
1285 -r
$mimemap or return undef;
1288 open(MIME
, $mimemap) or return undef;
1290 next if m/^#/; # skip comments
1291 my ($mime, $exts) = split(/\t+/);
1292 if (defined $exts) {
1293 my @exts = split(/\s+/, $exts);
1294 foreach my $ext (@exts) {
1295 $mimemap{$ext} = $mime;
1301 $filename =~ /\.([^.]*)$/;
1302 return $mimemap{$1};
1305 sub mimetype_guess
{
1306 my $filename = shift;
1308 $filename =~ /\./ or return undef;
1310 if ($mimetypes_file) {
1311 my $file = $mimetypes_file;
1312 if ($file !~ m!^/!) { # if it is relative path
1313 # it is relative to project
1314 $file = "$projectroot/$project/$file";
1316 $mime = mimetype_guess_file
($filename, $file);
1318 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1324 my $filename = shift;
1327 my $mime = mimetype_guess
($filename);
1328 $mime and return $mime;
1332 return $default_blob_plain_mimetype unless $fd;
1335 return 'text/plain' .
1336 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1337 } elsif (! $filename) {
1338 return 'application/octet-stream';
1339 } elsif ($filename =~ m/\.png$/i) {
1341 } elsif ($filename =~ m/\.gif$/i) {
1343 } elsif ($filename =~ m/\.jpe?g$/i) {
1344 return 'image/jpeg';
1346 return 'application/octet-stream';
1350 ## ======================================================================
1351 ## functions printing HTML: header, footer, error page
1353 sub git_header_html
{
1354 my $status = shift || "200 OK";
1355 my $expires = shift;
1357 my $title = "$site_name git";
1358 if (defined $project) {
1359 $title .= " - $project";
1360 if (defined $action) {
1361 $title .= "/$action";
1362 if (defined $file_name) {
1363 $title .= " - " . esc_html
($file_name);
1364 if ($action eq "tree" && $file_name !~ m
|/$|) {
1371 # require explicit support from the UA if we are to send the page as
1372 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1373 # we have to do this because MSIE sometimes globs '*/*', pretending to
1374 # support xhtml+xml but choking when it gets what it asked for.
1375 if (defined $cgi->http('HTTP_ACCEPT') &&
1376 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1377 $cgi->Accept('application/xhtml+xml') != 0) {
1378 $content_type = 'application/xhtml+xml';
1380 $content_type = 'text/html';
1382 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1383 -status
=> $status, -expires
=> $expires);
1385 <?xml version="1.0" encoding="utf-8"?>
1386 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1387 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1388 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1389 <!-- git core binaries version $git_version -->
1391 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1392 <meta name="generator" content="gitweb/$version git/$git_version"/>
1393 <meta name="robots" content="index, nofollow"/>
1394 <title>$title</title>
1396 # print out each stylesheet that exist
1397 if (defined $stylesheet) {
1398 #provides backwards capability for those people who define style sheet in a config file
1399 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1401 foreach my $stylesheet (@stylesheets) {
1402 next unless $stylesheet;
1403 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1406 if (defined $project) {
1407 printf('<link rel="alternate" title="%s log" '.
1408 'href="%s" type="application/rss+xml"/>'."\n",
1409 esc_param
($project), href
(action
=>"rss"));
1411 printf('<link rel="alternate" title="%s projects list" '.
1412 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1413 $site_name, href
(project
=>undef, action
=>"project_index"));
1414 printf('<link rel="alternate" title="%s projects logs" '.
1415 'href="%s" type="text/x-opml"/>'."\n",
1416 $site_name, href
(project
=>undef, action
=>"opml"));
1418 if (defined $favicon) {
1419 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1425 if (-f
$site_header) {
1426 open (my $fd, $site_header);
1431 print "<div class=\"page_header\">\n" .
1432 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1433 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1435 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1436 if (defined $project) {
1437 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1438 if (defined $action) {
1442 if (!defined $searchtext) {
1446 if (defined $hash_base) {
1447 $search_hash = $hash_base;
1448 } elsif (defined $hash) {
1449 $search_hash = $hash;
1451 $search_hash = "HEAD";
1453 $cgi->param("a", "search");
1454 $cgi->param("h", $search_hash);
1455 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1456 "<div class=\"search\">\n" .
1457 $cgi->hidden(-name
=> "p") . "\n" .
1458 $cgi->hidden(-name
=> "a") . "\n" .
1459 $cgi->hidden(-name
=> "h") . "\n" .
1460 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1462 $cgi->end_form() . "\n";
1467 sub git_footer_html
{
1468 print "<div class=\"page_footer\">\n";
1469 if (defined $project) {
1470 my $descr = git_get_project_description
($project);
1471 if (defined $descr) {
1472 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1474 print $cgi->a({-href
=> href
(action
=>"rss"),
1475 -class => "rss_logo"}, "RSS") . "\n";
1477 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1478 -class => "rss_logo"}, "OPML") . " ";
1479 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1480 -class => "rss_logo"}, "TXT") . "\n";
1484 if (-f
$site_footer) {
1485 open (my $fd, $site_footer);
1495 my $status = shift || "403 Forbidden";
1496 my $error = shift || "Malformed query, file missing or permission denied";
1498 git_header_html
($status);
1500 <div class="page_body">
1510 ## ----------------------------------------------------------------------
1511 ## functions printing or outputting HTML: navigation
1513 sub git_print_page_nav
{
1514 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1515 $extra = '' if !defined $extra; # pager or formats
1517 my @navs = qw(summary shortlog log commit commitdiff tree);
1519 @navs = grep { $_ ne $suppress } @navs;
1522 my %arg = map { $_ => {action
=>$_} } @navs;
1523 if (defined $head) {
1524 for (qw(commit commitdiff)) {
1525 $arg{$_}{hash
} = $head;
1527 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1528 for (qw(shortlog log)) {
1529 $arg{$_}{hash
} = $head;
1533 $arg{tree
}{hash
} = $treehead if defined $treehead;
1534 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1536 print "<div class=\"page_nav\">\n" .
1538 map { $_ eq $current ?
1539 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1541 print "<br/>\n$extra<br/>\n" .
1545 sub format_paging_nav
{
1546 my ($action, $hash, $head, $page, $nrevs) = @_;
1550 if ($hash ne $head || $page) {
1551 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1553 $paging_nav .= "HEAD";
1557 $paging_nav .= " ⋅ " .
1558 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1559 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1561 $paging_nav .= " ⋅ prev";
1564 if ($nrevs >= (100 * ($page+1)-1)) {
1565 $paging_nav .= " ⋅ " .
1566 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1567 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1569 $paging_nav .= " ⋅ next";
1575 ## ......................................................................
1576 ## functions printing or outputting HTML: div
1578 sub git_print_header_div
{
1579 my ($action, $title, $hash, $hash_base) = @_;
1582 $args{action
} = $action;
1583 $args{hash
} = $hash if $hash;
1584 $args{hash_base
} = $hash_base if $hash_base;
1586 print "<div class=\"header\">\n" .
1587 $cgi->a({-href
=> href
(%args), -class => "title"},
1588 $title ?
$title : $action) .
1592 #sub git_print_authorship (\%) {
1593 sub git_print_authorship
{
1596 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1597 print "<div class=\"author_date\">" .
1598 esc_html
($co->{'author_name'}) .
1600 if ($ad{'hour_local'} < 6) {
1601 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1602 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1604 printf(" (%02d:%02d %s)",
1605 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1610 sub git_print_page_path
{
1615 if (!defined $name) {
1616 print "<div class=\"page_path\">/</div>\n";
1618 my @dirname = split '/', $name;
1619 my $basename = pop @dirname;
1622 print "<div class=\"page_path\">";
1623 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1624 -title
=> 'tree root'}, "[$project]");
1626 foreach my $dir (@dirname) {
1627 $fullname .= ($fullname ?
'/' : '') . $dir;
1628 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1630 -title
=> $fullname}, esc_html
($dir));
1633 if (defined $type && $type eq 'blob') {
1634 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1636 -title
=> $name}, esc_html
($basename));
1637 } elsif (defined $type && $type eq 'tree') {
1638 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1640 -title
=> $name}, esc_html
($basename));
1642 print esc_html
($basename);
1644 print "<br/></div>\n";
1648 # sub git_print_log (\@;%) {
1649 sub git_print_log
($;%) {
1653 if ($opts{'-remove_title'}) {
1654 # remove title, i.e. first line of log
1657 # remove leading empty lines
1658 while (defined $log->[0] && $log->[0] eq "") {
1665 foreach my $line (@
$log) {
1666 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1669 if (! $opts{'-remove_signoff'}) {
1670 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1673 # remove signoff lines
1680 # print only one empty line
1681 # do not print empty line after signoff
1683 next if ($empty || $signoff);
1689 print format_log_line_html
($line) . "<br/>\n";
1692 if ($opts{'-final_empty_line'}) {
1693 # end with single empty line
1694 print "<br/>\n" unless $empty;
1698 sub git_print_simplified_log
{
1700 my $remove_title = shift;
1703 -final_empty_line
=> 1,
1704 -remove_title
=> $remove_title);
1707 # print tree entry (row of git_tree), but without encompassing <tr> element
1708 sub git_print_tree_entry
{
1709 my ($t, $basedir, $hash_base, $have_blame) = @_;
1712 $base_key{hash_base
} = $hash_base if defined $hash_base;
1714 # The format of a table row is: mode list link. Where mode is
1715 # the mode of the entry, list is the name of the entry, an href,
1716 # and link is the action links of the entry.
1718 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1719 if ($t->{'type'} eq "blob") {
1720 print "<td class=\"list\">" .
1721 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1722 file_name
=>"$basedir$t->{'name'}", %base_key),
1723 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1724 print "<td class=\"link\">";
1726 print $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1727 file_name
=>"$basedir$t->{'name'}", %base_key)},
1730 if (defined $hash_base) {
1734 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1735 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1739 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1740 file_name
=>"$basedir$t->{'name'}")},
1744 } elsif ($t->{'type'} eq "tree") {
1745 print "<td class=\"list\">";
1746 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1747 file_name
=>"$basedir$t->{'name'}", %base_key)},
1748 esc_html
($t->{'name'}));
1750 print "<td class=\"link\">";
1751 if (defined $hash_base) {
1752 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1753 file_name
=>"$basedir$t->{'name'}")},
1760 ## ......................................................................
1761 ## functions printing large fragments of HTML
1763 sub git_difftree_body
{
1764 my ($difftree, $hash, $parent) = @_;
1766 print "<div class=\"list_head\">\n";
1767 if ($#{$difftree} > 10) {
1768 print(($#{$difftree} + 1) . " files changed:\n");
1772 print "<table class=\"diff_tree\">\n";
1775 foreach my $line (@
{$difftree}) {
1776 my %diff = parse_difftree_raw_line
($line);
1779 print "<tr class=\"dark\">\n";
1781 print "<tr class=\"light\">\n";
1785 my ($to_mode_oct, $to_mode_str, $to_file_type);
1786 my ($from_mode_oct, $from_mode_str, $from_file_type);
1787 if ($diff{'to_mode'} ne ('0' x
6)) {
1788 $to_mode_oct = oct $diff{'to_mode'};
1789 if (S_ISREG
($to_mode_oct)) { # only for regular file
1790 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1792 $to_file_type = file_type
($diff{'to_mode'});
1794 if ($diff{'from_mode'} ne ('0' x
6)) {
1795 $from_mode_oct = oct $diff{'from_mode'};
1796 if (S_ISREG
($to_mode_oct)) { # only for regular file
1797 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1799 $from_file_type = file_type
($diff{'from_mode'});
1802 if ($diff{'status'} eq "A") { # created
1803 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1804 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1805 $mode_chng .= "]</span>";
1807 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1808 hash_base
=>$hash, file_name
=>$diff{'file'}),
1809 -class => "list"}, esc_html
($diff{'file'}));
1811 print "<td>$mode_chng</td>\n";
1812 print "<td class=\"link\">";
1813 if ($action eq 'commitdiff') {
1816 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1820 } elsif ($diff{'status'} eq "D") { # deleted
1821 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1823 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1824 hash_base
=>$parent, file_name
=>$diff{'file'}),
1825 -class => "list"}, esc_html
($diff{'file'}));
1827 print "<td>$mode_chng</td>\n";
1828 print "<td class=\"link\">";
1829 if ($action eq 'commitdiff') {
1832 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1835 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1836 file_name
=>$diff{'file'})},
1838 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1839 file_name
=>$diff{'file'})},
1843 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1844 my $mode_chnge = "";
1845 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1846 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1847 if ($from_file_type != $to_file_type) {
1848 $mode_chnge .= " from $from_file_type to $to_file_type";
1850 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1851 if ($from_mode_str && $to_mode_str) {
1852 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1853 } elsif ($to_mode_str) {
1854 $mode_chnge .= " mode: $to_mode_str";
1857 $mode_chnge .= "]</span>\n";
1860 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1861 hash_base
=>$hash, file_name
=>$diff{'file'}),
1862 -class => "list"}, esc_html
($diff{'file'}));
1864 print "<td>$mode_chnge</td>\n";
1865 print "<td class=\"link\">";
1866 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1867 if ($action eq 'commitdiff') {
1870 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1872 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1873 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1874 hash_base
=>$hash, hash_parent_base
=>$parent,
1875 file_name
=>$diff{'file'})},
1880 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1881 file_name
=>$diff{'file'})},
1883 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1884 file_name
=>$diff{'file'})},
1888 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1889 my %status_name = ('R' => 'moved', 'C' => 'copied');
1890 my $nstatus = $status_name{$diff{'status'}};
1892 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1893 # mode also for directories, so we cannot use $to_mode_str
1894 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1897 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1898 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1899 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1900 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1901 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1902 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1903 -class => "list"}, esc_html
($diff{'from_file'})) .
1904 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1905 "<td class=\"link\">";
1906 if ($diff{'to_id'} ne $diff{'from_id'}) {
1907 if ($action eq 'commitdiff') {
1910 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1912 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1913 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1914 hash_base
=>$hash, hash_parent_base
=>$parent,
1915 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1920 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1921 file_name
=>$diff{'from_file'})},
1923 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1924 file_name
=>$diff{'from_file'})},
1928 } # we should not encounter Unmerged (U) or Unknown (X) status
1934 sub git_patchset_body
{
1935 my ($fd, $difftree, $hash, $hash_parent) = @_;
1939 my $patch_found = 0;
1942 print "<div class=\"patchset\">\n";
1945 while (my $patch_line = <$fd>) {
1948 if ($patch_line =~ m/^diff /) { # "git diff" header
1949 # beginning of patch (in patchset)
1951 # close previous patch
1952 print "</div>\n"; # class="patch"
1954 # first patch in patchset
1957 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1959 if (ref($difftree->[$patch_idx]) eq "HASH") {
1960 $diffinfo = $difftree->[$patch_idx];
1962 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1966 # for now, no extended header, hence we skip empty patches
1967 # companion to next LINE if $in_header;
1968 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1973 if ($diffinfo->{'status'} eq "A") { # added
1974 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1975 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1976 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1977 $diffinfo->{'to_id'}) . "(new)" .
1978 "</div>\n"; # class="diff_info"
1980 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1981 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1982 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1983 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1984 $diffinfo->{'from_id'}) . "(deleted)" .
1985 "</div>\n"; # class="diff_info"
1987 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1988 $diffinfo->{'status'} eq "C" || # copied
1989 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1990 print "<div class=\"diff_info\">" .
1991 file_type
($diffinfo->{'from_mode'}) . ":" .
1992 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1993 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1994 $diffinfo->{'from_id'}) .
1996 file_type
($diffinfo->{'to_mode'}) . ":" .
1997 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1998 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1999 $diffinfo->{'to_id'});
2000 print "</div>\n"; # class="diff_info"
2002 } else { # modified, mode changed, ...
2003 print "<div class=\"diff_info\">" .
2004 file_type
($diffinfo->{'from_mode'}) . ":" .
2005 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2006 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2007 $diffinfo->{'from_id'}) .
2009 file_type
($diffinfo->{'to_mode'}) . ":" .
2010 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2011 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2012 $diffinfo->{'to_id'});
2013 print "</div>\n"; # class="diff_info"
2016 #print "<div class=\"diff extended_header\">\n";
2019 } # start of patch in patchset
2022 if ($in_header && $patch_line =~ m/^---/) {
2023 #print "</div>\n"; # class="diff extended_header"
2026 my $file = $diffinfo->{'from_file'};
2027 $file ||= $diffinfo->{'file'};
2028 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2029 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2030 -class => "list"}, esc_html
($file));
2031 $patch_line =~ s
|a
/.*$|a/$file|g
;
2032 print "<div class=\"diff from_file\">$patch_line</div>\n";
2034 $patch_line = <$fd>;
2037 #$patch_line =~ m/^+++/;
2038 $file = $diffinfo->{'to_file'};
2039 $file ||= $diffinfo->{'file'};
2040 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2041 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2042 -class => "list"}, esc_html
($file));
2043 $patch_line =~ s
|b
/.*|b/$file|g
;
2044 print "<div class=\"diff to_file\">$patch_line</div>\n";
2048 next LINE
if $in_header;
2050 print format_diff_line
($patch_line);
2052 print "</div>\n" if $patch_found; # class="patch"
2054 print "</div>\n"; # class="patchset"
2057 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2059 sub git_shortlog_body
{
2060 # uses global variable $project
2061 my ($revlist, $from, $to, $refs, $extra) = @_;
2063 $from = 0 unless defined $from;
2064 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2066 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2068 for (my $i = $from; $i <= $to; $i++) {
2069 my $commit = $revlist->[$i];
2070 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2071 my $ref = format_ref_marker
($refs, $commit);
2072 my %co = parse_commit
($commit);
2074 print "<tr class=\"dark\">\n";
2076 print "<tr class=\"light\">\n";
2079 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2080 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2081 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2083 print format_subject_html
($co{'title'}, $co{'title_short'},
2084 href
(action
=>"commit", hash
=>$commit), $ref);
2086 "<td class=\"link\">" .
2087 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2088 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") . " | " .
2089 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2093 if (defined $extra) {
2095 "<td colspan=\"4\">$extra</td>\n" .
2101 sub git_history_body
{
2102 # Warning: assumes constant type (blob or tree) during history
2103 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2105 $from = 0 unless defined $from;
2106 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2108 print "<table class=\"history\" cellspacing=\"0\">\n";
2110 for (my $i = $from; $i <= $to; $i++) {
2111 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2116 my %co = parse_commit
($commit);
2121 my $ref = format_ref_marker
($refs, $commit);
2124 print "<tr class=\"dark\">\n";
2126 print "<tr class=\"light\">\n";
2129 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2130 # shortlog uses chop_str($co{'author_name'}, 10)
2131 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2133 # originally git_history used chop_str($co{'title'}, 50)
2134 print format_subject_html
($co{'title'}, $co{'title_short'},
2135 href
(action
=>"commit", hash
=>$commit), $ref);
2137 "<td class=\"link\">" .
2138 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2139 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2141 if ($ftype eq 'blob') {
2142 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2143 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2144 if (defined $blob_current && defined $blob_parent &&
2145 $blob_current ne $blob_parent) {
2147 $cgi->a({-href
=> href
(action
=>"blobdiff",
2148 hash
=>$blob_current, hash_parent
=>$blob_parent,
2149 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2150 file_name
=>$file_name)},
2157 if (defined $extra) {
2159 "<td colspan=\"4\">$extra</td>\n" .
2166 # uses global variable $project
2167 my ($taglist, $from, $to, $extra) = @_;
2168 $from = 0 unless defined $from;
2169 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2171 print "<table class=\"tags\" cellspacing=\"0\">\n";
2173 for (my $i = $from; $i <= $to; $i++) {
2174 my $entry = $taglist->[$i];
2176 my $comment_lines = $tag{'comment'};
2177 my $comment = shift @
$comment_lines;
2179 if (defined $comment) {
2180 $comment_short = chop_str
($comment, 30, 5);
2183 print "<tr class=\"dark\">\n";
2185 print "<tr class=\"light\">\n";
2188 print "<td><i>$tag{'age'}</i></td>\n" .
2190 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2191 -class => "list name"}, esc_html
($tag{'name'})) .
2194 if (defined $comment) {
2195 print format_subject_html
($comment, $comment_short,
2196 href
(action
=>"tag", hash
=>$tag{'id'}));
2199 "<td class=\"selflink\">";
2200 if ($tag{'type'} eq "tag") {
2201 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2206 "<td class=\"link\">" . " | " .
2207 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2208 if ($tag{'reftype'} eq "commit") {
2209 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2210 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2211 } elsif ($tag{'reftype'} eq "blob") {
2212 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2217 if (defined $extra) {
2219 "<td colspan=\"5\">$extra</td>\n" .
2225 sub git_heads_body
{
2226 # uses global variable $project
2227 my ($headlist, $head, $from, $to, $extra) = @_;
2228 $from = 0 unless defined $from;
2229 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2231 print "<table class=\"heads\" cellspacing=\"0\">\n";
2233 for (my $i = $from; $i <= $to; $i++) {
2234 my $entry = $headlist->[$i];
2236 my $curr = $tag{'id'} eq $head;
2238 print "<tr class=\"dark\">\n";
2240 print "<tr class=\"light\">\n";
2243 print "<td><i>$tag{'age'}</i></td>\n" .
2244 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
2245 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2246 -class => "list name"},esc_html
($tag{'name'})) .
2248 "<td class=\"link\">" .
2249 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2250 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2251 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2255 if (defined $extra) {
2257 "<td colspan=\"3\">$extra</td>\n" .
2263 ## ======================================================================
2264 ## ======================================================================
2267 sub git_project_list
{
2268 my $order = $cgi->param('o');
2269 if (defined $order && $order !~ m/project|descr|owner|age/) {
2270 die_error
(undef, "Unknown order parameter");
2273 my @list = git_get_projects_list
();
2276 die_error
(undef, "No projects found");
2278 foreach my $pr (@list) {
2279 my (@aa) = git_get_last_activity
($pr->{'path'});
2283 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2284 if (!defined $pr->{'descr'}) {
2285 my $descr = git_get_project_description
($pr->{'path'}) || "";
2286 $pr->{'descr'} = chop_str
($descr, 25, 5);
2288 if (!defined $pr->{'owner'}) {
2289 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2291 push @projects, $pr;
2295 if (-f
$home_text) {
2296 print "<div class=\"index_include\">\n";
2297 open (my $fd, $home_text);
2302 print "<table class=\"project_list\">\n" .
2304 $order ||= "project";
2305 if ($order eq "project") {
2306 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2307 print "<th>Project</th>\n";
2310 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2311 -class => "header"}, "Project") .
2314 if ($order eq "descr") {
2315 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2316 print "<th>Description</th>\n";
2319 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2320 -class => "header"}, "Description") .
2323 if ($order eq "owner") {
2324 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2325 print "<th>Owner</th>\n";
2328 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2329 -class => "header"}, "Owner") .
2332 if ($order eq "age") {
2333 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2334 print "<th>Last Change</th>\n";
2337 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2338 -class => "header"}, "Last Change") .
2341 print "<th></th>\n" .
2344 foreach my $pr (@projects) {
2346 print "<tr class=\"dark\">\n";
2348 print "<tr class=\"light\">\n";
2351 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2352 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2353 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2354 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2355 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2356 $pr->{'age_string'} . "</td>\n" .
2357 "<td class=\"link\">" .
2358 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2359 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2360 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2361 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2369 sub git_project_index
{
2370 my @projects = git_get_projects_list
();
2373 -type
=> 'text/plain',
2374 -charset
=> 'utf-8',
2375 -content_disposition
=> 'inline; filename="index.aux"');
2377 foreach my $pr (@projects) {
2378 if (!exists $pr->{'owner'}) {
2379 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2382 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2383 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2384 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2385 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2389 print "$path $owner\n";
2394 my $descr = git_get_project_description
($project) || "none";
2395 my $head = git_get_head_hash
($project);
2396 my %co = parse_commit
($head);
2397 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2399 my $owner = git_get_project_owner
($project);
2401 my ($reflist, $refs) = git_get_refs_list
();
2405 foreach my $ref (@
$reflist) {
2406 if ($ref->{'name'} =~ s!^heads/!!) {
2407 push @headlist, $ref;
2409 $ref->{'name'} =~ s!^tags/!!;
2410 push @taglist, $ref;
2415 git_print_page_nav
('summary','', $head);
2417 print "<div class=\"title\"> </div>\n";
2418 print "<table cellspacing=\"0\">\n" .
2419 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2420 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2421 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2422 # use per project git URL list in $projectroot/$project/cloneurl
2423 # or make project git URL from git base URL and project name
2424 my $url_tag = "URL";
2425 my @url_list = git_get_project_url_list
($project);
2426 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2427 foreach my $git_url (@url_list) {
2428 next unless $git_url;
2429 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2434 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2435 git_get_head_hash
($project)
2436 or die_error
(undef, "Open git-rev-list failed");
2437 my @revlist = map { chomp; $_ } <$fd>;
2439 git_print_header_div
('shortlog');
2440 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2441 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2444 git_print_header_div
('tags');
2445 git_tags_body
(\
@taglist, 0, 15,
2446 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2450 git_print_header_div
('heads');
2451 git_heads_body
(\
@headlist, $head, 0, 15,
2452 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2459 my $head = git_get_head_hash
($project);
2461 git_print_page_nav
('','', $head,undef,$head);
2462 my %tag = parse_tag
($hash);
2463 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2464 print "<div class=\"title_text\">\n" .
2465 "<table cellspacing=\"0\">\n" .
2467 "<td>object</td>\n" .
2468 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2469 $tag{'object'}) . "</td>\n" .
2470 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2471 $tag{'type'}) . "</td>\n" .
2473 if (defined($tag{'author'})) {
2474 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2475 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2476 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2477 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2480 print "</table>\n\n" .
2482 print "<div class=\"page_body\">";
2483 my $comment = $tag{'comment'};
2484 foreach my $line (@
$comment) {
2485 print esc_html
($line) . "<br/>\n";
2495 my ($have_blame) = gitweb_check_feature
('blame');
2497 die_error
('403 Permission denied', "Permission denied");
2499 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2500 $hash_base ||= git_get_head_hash
($project);
2501 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2502 my %co = parse_commit
($hash_base)
2503 or die_error
(undef, "Reading commit failed");
2504 if (!defined $hash) {
2505 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2506 or die_error
(undef, "Error looking up file");
2508 $ftype = git_get_type
($hash);
2509 if ($ftype !~ "blob") {
2510 die_error
("400 Bad Request", "Object is not a blob");
2512 open ($fd, "-|", git_cmd
(), "blame", '-l', '--', $file_name, $hash_base)
2513 or die_error
(undef, "Open git-blame failed");
2516 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2519 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2522 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2524 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2525 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2526 git_print_page_path
($file_name, $ftype, $hash_base);
2527 my @rev_color = (qw(light2 dark2));
2528 my $num_colors = scalar(@rev_color);
2529 my $current_color = 0;
2532 <div class="page_body">
2533 <table class="blame">
2534 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2537 my ($full_rev, $author, $date, $lineno, $data) =
2538 /^([0-9a-f]{40}).*?\s\((.*?)\s+([-\d]+ [:\d]+ [-+\d]+)\s+(\d+)\)\s(.*)/;
2539 my $rev = substr($full_rev, 0, 8);
2542 if (!defined $last_rev) {
2543 $last_rev = $full_rev;
2545 } elsif ($last_rev ne $full_rev) {
2546 $last_rev = $full_rev;
2547 $current_color = ++$current_color % $num_colors;
2550 print "<tr class=\"$rev_color[$current_color]\">\n";
2551 print "<td class=\"sha1\"";
2552 if ($print_c8 == 1) {
2553 print " title=\"$author, $date\"";
2556 if ($print_c8 == 1) {
2557 print $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2561 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2562 esc_html
($lineno) . "</a></td>\n";
2563 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2569 or print "Reading blob failed\n";
2576 my ($have_blame) = gitweb_check_feature
('blame');
2578 die_error
('403 Permission denied', "Permission denied");
2580 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2581 $hash_base ||= git_get_head_hash
($project);
2582 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2583 my %co = parse_commit
($hash_base)
2584 or die_error
(undef, "Reading commit failed");
2585 if (!defined $hash) {
2586 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2587 or die_error
(undef, "Error lookup file");
2589 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2590 or die_error
(undef, "Open git-annotate failed");
2593 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2596 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2599 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2601 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2602 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2603 git_print_page_path
($file_name, 'blob', $hash_base);
2604 print "<div class=\"page_body\">\n";
2606 <table class="blame">
2615 my @line_class = (qw(light dark));
2616 my $line_class_len = scalar (@line_class);
2617 my $line_class_num = $#line_class;
2618 while (my $line = <$fd>) {
2630 $line_class_num = ($line_class_num + 1) % $line_class_len;
2632 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2639 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2642 $short_rev = substr ($long_rev, 0, 8);
2643 $age = time () - $time;
2644 $age_str = age_string
($age);
2645 $age_str =~ s/ / /g;
2646 $age_class = age_class
($age);
2647 $author = esc_html
($author);
2648 $author =~ s/ / /g;
2650 $data = untabify
($data);
2651 $data = esc_html
($data);
2654 <tr class="$line_class[$line_class_num]">
2655 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2656 <td class="$age_class">$age_str</td>
2658 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2659 <td class="pre">$data</td>
2662 } # while (my $line = <$fd>)
2663 print "</table>\n\n";
2665 or print "Reading blob failed.\n";
2671 my $head = git_get_head_hash
($project);
2673 git_print_page_nav
('','', $head,undef,$head);
2674 git_print_header_div
('summary', $project);
2676 my ($taglist) = git_get_refs_list
("tags");
2678 git_tags_body
($taglist);
2684 my $head = git_get_head_hash
($project);
2686 git_print_page_nav
('','', $head,undef,$head);
2687 git_print_header_div
('summary', $project);
2689 my ($headlist) = git_get_refs_list
("heads");
2691 git_heads_body
($headlist, $head);
2696 sub git_blob_plain
{
2699 if (!defined $hash) {
2700 if (defined $file_name) {
2701 my $base = $hash_base || git_get_head_hash
($project);
2702 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2703 or die_error
(undef, "Error lookup file");
2705 die_error
(undef, "No file name defined");
2707 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2708 # blobs defined by non-textual hash id's can be cached
2713 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2714 or die_error
(undef, "Couldn't cat $file_name, $hash");
2716 $type ||= blob_mimetype
($fd, $file_name);
2718 # save as filename, even when no $file_name is given
2719 my $save_as = "$hash";
2720 if (defined $file_name) {
2721 $save_as = $file_name;
2722 } elsif ($type =~ m/^text\//) {
2729 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2731 binmode STDOUT
, ':raw';
2733 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2741 if (!defined $hash) {
2742 if (defined $file_name) {
2743 my $base = $hash_base || git_get_head_hash
($project);
2744 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2745 or die_error
(undef, "Error lookup file");
2747 die_error
(undef, "No file name defined");
2749 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2750 # blobs defined by non-textual hash id's can be cached
2754 my ($have_blame) = gitweb_check_feature
('blame');
2755 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2756 or die_error
(undef, "Couldn't cat $file_name, $hash");
2757 my $mimetype = blob_mimetype
($fd, $file_name);
2758 if ($mimetype !~ m/^text\//) {
2760 return git_blob_plain
($mimetype);
2762 git_header_html
(undef, $expires);
2763 my $formats_nav = '';
2764 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2765 if (defined $file_name) {
2768 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2769 hash
=>$hash, file_name
=>$file_name)},
2774 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2775 hash
=>$hash, file_name
=>$file_name)},
2778 $cgi->a({-href
=> href
(action
=>"blob_plain",
2779 hash
=>$hash, file_name
=>$file_name)},
2782 $cgi->a({-href
=> href
(action
=>"blob",
2783 hash_base
=>"HEAD", file_name
=>$file_name)},
2787 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2789 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2790 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2792 print "<div class=\"page_nav\">\n" .
2793 "<br/><br/></div>\n" .
2794 "<div class=\"title\">$hash</div>\n";
2796 git_print_page_path
($file_name, "blob", $hash_base);
2797 print "<div class=\"page_body\">\n";
2799 while (my $line = <$fd>) {
2802 $line = untabify
($line);
2803 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2804 $nr, $nr, $nr, esc_html
($line);
2807 or print "Reading blob failed.\n";
2813 my $have_snapshot = gitweb_have_snapshot
();
2815 if (!defined $hash_base) {
2816 $hash_base = "HEAD";
2818 if (!defined $hash) {
2819 if (defined $file_name) {
2820 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
2826 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2827 or die_error
(undef, "Open git-ls-tree failed");
2828 my @entries = map { chomp; $_ } <$fd>;
2829 close $fd or die_error
(undef, "Reading tree failed");
2832 my $refs = git_get_references
();
2833 my $ref = format_ref_marker
($refs, $hash_base);
2836 my ($have_blame) = gitweb_check_feature
('blame');
2837 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2839 if (defined $file_name) {
2841 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2842 hash
=>$hash, file_name
=>$file_name)},
2844 $cgi->a({-href
=> href
(action
=>"tree",
2845 hash_base
=>"HEAD", file_name
=>$file_name)},
2848 if ($have_snapshot) {
2849 # FIXME: Should be available when we have no hash base as well.
2851 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2854 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2855 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2858 print "<div class=\"page_nav\">\n";
2859 print "<br/><br/></div>\n";
2860 print "<div class=\"title\">$hash</div>\n";
2862 if (defined $file_name) {
2863 $base = esc_html
("$file_name/");
2865 git_print_page_path
($file_name, 'tree', $hash_base);
2866 print "<div class=\"page_body\">\n";
2867 print "<table cellspacing=\"0\">\n";
2869 foreach my $line (@entries) {
2870 my %t = parse_ls_tree_line
($line, -z
=> 1);
2873 print "<tr class=\"dark\">\n";
2875 print "<tr class=\"light\">\n";
2879 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2883 print "</table>\n" .
2889 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2890 my $have_snapshot = (defined $ctype && defined $suffix);
2891 if (!$have_snapshot) {
2892 die_error
('403 Permission denied', "Permission denied");
2895 if (!defined $hash) {
2896 $hash = git_get_head_hash
($project);
2899 my $filename = basename
($project) . "-$hash.tar.$suffix";
2902 -type
=> 'application/x-tar',
2903 -content_encoding
=> $ctype,
2904 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
2905 -status
=> '200 OK');
2907 my $git_command = git_cmd_str
();
2908 open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
2909 die_error
(undef, "Execute git-tar-tree failed.");
2910 binmode STDOUT
, ':raw';
2912 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2918 my $head = git_get_head_hash
($project);
2919 if (!defined $hash) {
2922 if (!defined $page) {
2925 my $refs = git_get_references
();
2927 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2928 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2929 or die_error
(undef, "Open git-rev-list failed");
2930 my @revlist = map { chomp; $_ } <$fd>;
2933 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2936 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2939 my %co = parse_commit
($hash);
2941 git_print_header_div
('summary', $project);
2942 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2944 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2945 my $commit = $revlist[$i];
2946 my $ref = format_ref_marker
($refs, $commit);
2947 my %co = parse_commit
($commit);
2949 my %ad = parse_date
($co{'author_epoch'});
2950 git_print_header_div
('commit',
2951 "<span class=\"age\">$co{'age_string'}</span>" .
2952 esc_html
($co{'title'}) . $ref,
2954 print "<div class=\"title_text\">\n" .
2955 "<div class=\"log_link\">\n" .
2956 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2958 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2960 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
2963 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2966 print "<div class=\"log_body\">\n";
2967 git_print_simplified_log
($co{'comment'});
2974 my %co = parse_commit
($hash);
2976 die_error
(undef, "Unknown commit object");
2978 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2979 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2981 my $parent = $co{'parent'};
2982 if (!defined $parent) {
2985 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
2986 or die_error
(undef, "Open git-diff-tree failed");
2987 my @difftree = map { chomp; $_ } <$fd>;
2988 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2990 # non-textual hash id's can be cached
2992 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2995 my $refs = git_get_references
();
2996 my $ref = format_ref_marker
($refs, $co{'id'});
2998 my $have_snapshot = gitweb_have_snapshot
();
3001 if (defined $file_name && defined $co{'parent'}) {
3003 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3006 if (defined $co{'parent'}) {
3008 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash)}, "shortlog"),
3009 $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash)}, "log");
3011 git_header_html
(undef, $expires);
3012 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
3013 $hash, $co{'tree'}, $hash,
3014 join (' | ', @views_nav));
3016 if (defined $co{'parent'}) {
3017 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3019 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3021 print "<div class=\"title_text\">\n" .
3022 "<table cellspacing=\"0\">\n";
3023 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3025 "<td></td><td> $ad{'rfc2822'}";
3026 if ($ad{'hour_local'} < 6) {
3027 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3028 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3030 printf(" (%02d:%02d %s)",
3031 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3035 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3036 print "<tr><td></td><td> $cd{'rfc2822'}" .
3037 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3039 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3042 "<td class=\"sha1\">" .
3043 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3044 class => "list"}, $co{'tree'}) .
3046 "<td class=\"link\">" .
3047 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3049 if ($have_snapshot) {
3051 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3055 my $parents = $co{'parents'};
3056 foreach my $par (@
$parents) {
3059 "<td class=\"sha1\">" .
3060 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3061 class => "list"}, $par) .
3063 "<td class=\"link\">" .
3064 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3066 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3073 print "<div class=\"page_body\">\n";
3074 git_print_log
($co{'comment'});
3077 git_difftree_body
(\
@difftree, $hash, $parent);
3083 my $format = shift || 'html';
3090 # preparing $fd and %diffinfo for git_patchset_body
3092 if (defined $hash_base && defined $hash_parent_base) {
3093 if (defined $file_name) {
3095 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3097 or die_error
(undef, "Open git-diff-tree failed");
3098 @difftree = map { chomp; $_ } <$fd>;
3100 or die_error
(undef, "Reading git-diff-tree failed");
3102 or die_error
('404 Not Found', "Blob diff not found");
3104 } elsif (defined $hash &&
3105 $hash =~ /[0-9a-fA-F]{40}/) {
3106 # try to find filename from $hash
3108 # read filtered raw output
3109 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3110 or die_error
(undef, "Open git-diff-tree failed");
3112 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3114 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3115 map { chomp; $_ } <$fd>;
3117 or die_error
(undef, "Reading git-diff-tree failed");
3119 or die_error
('404 Not Found', "Blob diff not found");
3122 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3125 if (@difftree > 1) {
3126 die_error
('404 Not Found', "Ambiguous blob diff specification");
3129 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3130 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3131 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3133 $hash_parent ||= $diffinfo{'from_id'};
3134 $hash ||= $diffinfo{'to_id'};
3136 # non-textual hash id's can be cached
3137 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3138 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3143 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3144 '-p', $hash_parent_base, $hash_base,
3146 or die_error
(undef, "Open git-diff-tree failed");
3149 # old/legacy style URI
3150 if (!%diffinfo && # if new style URI failed
3151 defined $hash && defined $hash_parent) {
3152 # fake git-diff-tree raw output
3153 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3154 $diffinfo{'from_id'} = $hash_parent;
3155 $diffinfo{'to_id'} = $hash;
3156 if (defined $file_name) {
3157 if (defined $file_parent) {
3158 $diffinfo{'status'} = '2';
3159 $diffinfo{'from_file'} = $file_parent;
3160 $diffinfo{'to_file'} = $file_name;
3161 } else { # assume not renamed
3162 $diffinfo{'status'} = '1';
3163 $diffinfo{'from_file'} = $file_name;
3164 $diffinfo{'to_file'} = $file_name;
3166 } else { # no filename given
3167 $diffinfo{'status'} = '2';
3168 $diffinfo{'from_file'} = $hash_parent;
3169 $diffinfo{'to_file'} = $hash;
3172 # non-textual hash id's can be cached
3173 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3174 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3179 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3180 or die_error
(undef, "Open git-diff failed");
3182 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3187 if ($format eq 'html') {
3189 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3190 hash
=>$hash, hash_parent
=>$hash_parent,
3191 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3192 file_name
=>$file_name, file_parent
=>$file_parent)},
3194 git_header_html
(undef, $expires);
3195 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3196 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3197 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3199 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3200 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3202 if (defined $file_name) {
3203 git_print_page_path
($file_name, "blob", $hash_base);
3205 print "<div class=\"page_path\"></div>\n";
3208 } elsif ($format eq 'plain') {
3210 -type
=> 'text/plain',
3211 -charset
=> 'utf-8',
3212 -expires
=> $expires,
3213 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3215 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3218 die_error
(undef, "Unknown blobdiff format");
3222 if ($format eq 'html') {
3223 print "<div class=\"page_body\">\n";
3225 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3228 print "</div>\n"; # class="page_body"
3232 while (my $line = <$fd>) {
3233 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3234 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3238 last if $line =~ m!^\+\+\+!;
3246 sub git_blobdiff_plain
{
3247 git_blobdiff
('plain');
3250 sub git_commitdiff
{
3251 my $format = shift || 'html';
3252 my %co = parse_commit
($hash);
3254 die_error
(undef, "Unknown commit object");
3256 if (!defined $hash_parent) {
3257 $hash_parent = $co{'parent'} || '--root';
3263 if ($format eq 'html') {
3264 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3265 "--patch-with-raw", "--full-index", $hash_parent, $hash
3266 or die_error
(undef, "Open git-diff-tree failed");
3268 while (chomp(my $line = <$fd>)) {
3269 # empty line ends raw part of diff-tree output
3271 push @difftree, $line;
3274 } elsif ($format eq 'plain') {
3275 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3276 '-p', $hash_parent, $hash
3277 or die_error
(undef, "Open git-diff-tree failed");
3280 die_error
(undef, "Unknown commitdiff format");
3283 # non-textual hash id's can be cached
3285 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3289 # write commit message
3290 if ($format eq 'html') {
3291 my $refs = git_get_references
();
3292 my $ref = format_ref_marker
($refs, $co{'id'});
3294 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3295 hash
=>$hash, hash_parent
=>$hash_parent)},
3298 git_header_html
(undef, $expires);
3299 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3300 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3301 git_print_authorship
(\
%co);
3302 print "<div class=\"page_body\">\n";
3303 print "<div class=\"log\">\n";
3304 git_print_simplified_log
($co{'comment'}, 1); # skip title
3305 print "</div>\n"; # class="log"
3307 } elsif ($format eq 'plain') {
3308 my $refs = git_get_references
("tags");
3309 my $tagname = git_get_rev_name_tags
($hash);
3310 my $filename = basename
($project) . "-$hash.patch";
3313 -type
=> 'text/plain',
3314 -charset
=> 'utf-8',
3315 -expires
=> $expires,
3316 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3317 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3320 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3321 Subject: $co{'title'}
3323 print "X-Git-Tag: $tagname\n" if $tagname;
3324 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3326 foreach my $line (@
{$co{'comment'}}) {
3333 if ($format eq 'html') {
3334 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3337 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3339 print "</div>\n"; # class="page_body"
3342 } elsif ($format eq 'plain') {
3346 or print "Reading git-diff-tree failed\n";
3350 sub git_commitdiff_plain
{
3351 git_commitdiff
('plain');
3355 if (!defined $hash_base) {
3356 $hash_base = git_get_head_hash
($project);
3358 if (!defined $page) {
3362 my %co = parse_commit
($hash_base);
3364 die_error
(undef, "Unknown commit object");
3367 my $refs = git_get_references
();
3368 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3370 if (!defined $hash && defined $file_name) {
3371 $hash = git_get_hash_by_path
($hash_base, $file_name);
3373 if (defined $hash) {
3374 $ftype = git_get_type
($hash);
3378 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3379 or die_error
(undef, "Open git-rev-list-failed");
3380 my @revlist = map { chomp; $_ } <$fd>;
3382 or die_error
(undef, "Reading git-rev-list failed");
3384 my $paging_nav = '';
3387 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3388 file_name
=>$file_name)},
3390 $paging_nav .= " ⋅ " .
3391 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3392 file_name
=>$file_name, page
=>$page-1),
3393 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3395 $paging_nav .= "first";
3396 $paging_nav .= " ⋅ prev";
3398 if ($#revlist >= (100 * ($page+1)-1)) {
3399 $paging_nav .= " ⋅ " .
3400 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3401 file_name
=>$file_name, page
=>$page+1),
3402 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3404 $paging_nav .= " ⋅ next";
3407 if ($#revlist >= (100 * ($page+1)-1)) {
3409 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3410 file_name
=>$file_name, page
=>$page+1),
3411 -title
=> "Alt-n"}, "next");
3415 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3416 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3417 git_print_page_path
($file_name, $ftype, $hash_base);
3419 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3420 $refs, $hash_base, $ftype, $next_link);
3426 if (!defined $searchtext) {
3427 die_error
(undef, "Text field empty");
3429 if (!defined $hash) {
3430 $hash = git_get_head_hash
($project);
3432 my %co = parse_commit
($hash);
3434 die_error
(undef, "Unknown commit object");
3437 my $commit_search = 1;
3438 my $author_search = 0;
3439 my $committer_search = 0;
3440 my $pickaxe_search = 0;
3441 if ($searchtext =~ s/^author\\://i) {
3443 } elsif ($searchtext =~ s/^committer\\://i) {
3444 $committer_search = 1;
3445 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3447 $pickaxe_search = 1;
3449 # pickaxe may take all resources of your box and run for several minutes
3450 # with every query - so decide by yourself how public you make this feature
3451 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3452 if (!$have_pickaxe) {
3453 die_error
('403 Permission denied', "Permission denied");
3457 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3458 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3460 print "<table cellspacing=\"0\">\n";
3462 if ($commit_search) {
3464 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3465 while (my $commit_text = <$fd>) {
3466 if (!grep m/$searchtext/i, $commit_text) {
3469 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3472 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3475 my @commit_lines = split "\n", $commit_text;
3476 my %co = parse_commit
(undef, \
@commit_lines);
3481 print "<tr class=\"dark\">\n";
3483 print "<tr class=\"light\">\n";
3486 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3487 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3489 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3490 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3491 my $comment = $co{'comment'};
3492 foreach my $line (@
$comment) {
3493 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3494 my $lead = esc_html
($1) || "";
3495 $lead = chop_str
($lead, 30, 10);
3496 my $match = esc_html
($2) || "";
3497 my $trail = esc_html
($3) || "";
3498 $trail = chop_str
($trail, 30, 10);
3499 my $text = "$lead<span class=\"match\">$match</span>$trail";
3500 print chop_str
($text, 80, 5) . "<br/>\n";
3504 "<td class=\"link\">" .
3505 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3507 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3514 if ($pickaxe_search) {
3516 my $git_command = git_cmd_str
();
3517 open my $fd, "-|", "$git_command rev-list $hash | " .
3518 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3521 while (my $line = <$fd>) {
3522 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3525 $set{'from_id'} = $3;
3527 $set{'id'} = $set{'to_id'};
3528 if ($set{'id'} =~ m/0{40}/) {
3529 $set{'id'} = $set{'from_id'};
3531 if ($set{'id'} =~ m/0{40}/) {
3535 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3538 print "<tr class=\"dark\">\n";
3540 print "<tr class=\"light\">\n";
3543 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3544 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3546 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3547 -class => "list subject"},
3548 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3549 while (my $setref = shift @files) {
3551 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3552 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3554 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3558 "<td class=\"link\">" .
3559 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3561 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3565 %co = parse_commit
($1);
3575 my $head = git_get_head_hash
($project);
3576 if (!defined $hash) {
3579 if (!defined $page) {
3582 my $refs = git_get_references
();
3584 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3585 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3586 or die_error
(undef, "Open git-rev-list failed");
3587 my @revlist = map { chomp; $_ } <$fd>;
3590 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3592 if ($#revlist >= (100 * ($page+1)-1)) {
3594 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3595 -title
=> "Alt-n"}, "next");
3600 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3601 git_print_header_div
('summary', $project);
3603 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3608 ## ......................................................................
3609 ## feeds (RSS, OPML)
3612 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3613 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3614 or die_error
(undef, "Open git-rev-list failed");
3615 my @revlist = map { chomp; $_ } <$fd>;
3616 close $fd or die_error
(undef, "Reading git-rev-list failed");
3617 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3619 <?xml version="1.0" encoding="utf-8"?>
3620 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3622 <title>$project $my_uri $my_url</title>
3623 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3624 <description>$project log</description>
3625 <language>en</language>
3628 for (my $i = 0; $i <= $#revlist; $i++) {
3629 my $commit = $revlist[$i];
3630 my %co = parse_commit
($commit);
3631 # we read 150, we always show 30 and the ones more recent than 48 hours
3632 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3635 my %cd = parse_date
($co{'committer_epoch'});
3636 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3637 $co{'parent'}, $co{'id'}
3639 my @difftree = map { chomp; $_ } <$fd>;
3644 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3646 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3647 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3648 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3649 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3650 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3651 "<content:encoded>" .
3653 my $comment = $co{'comment'};
3654 foreach my $line (@
$comment) {
3655 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3656 print "$line<br/>\n";
3659 foreach my $line (@difftree) {
3660 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3663 my $file = esc_html
(unquote
($7));
3664 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3665 print "$file<br/>\n";
3668 "</content:encoded>\n" .
3671 print "</channel></rss>";
3675 my @list = git_get_projects_list
();
3677 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3679 <?xml version="1.0" encoding="utf-8"?>
3680 <opml version="1.0">
3682 <title>$site_name Git OPML Export</title>
3685 <outline text="git RSS feeds">
3688 foreach my $pr (@list) {
3690 my $head = git_get_head_hash
($proj{'path'});
3691 if (!defined $head) {
3694 $git_dir = "$projectroot/$proj{'path'}";
3695 my %co = parse_commit
($head);
3700 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3701 my $rss = "$my_url?p=$proj{'path'};a=rss";
3702 my $html = "$my_url?p=$proj{'path'};a=summary";
3703 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";