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 our $githelp_url = "http://git.or.cz/";
63 our $githelp_label = "git homepage";
65 # source of projects list
66 our $projects_list = "++GITWEB_LIST++";
68 # show repository only if this file exists
69 # (only effective if this variable evaluates to true)
70 our $export_ok = "++GITWEB_EXPORT_OK++";
72 # only allow viewing of repositories also shown on the overview page
73 our $strict_export = "++GITWEB_STRICT_EXPORT++";
75 # list of git base URLs used for URL to where fetch project from,
76 # i.e. full URL is "$git_base_url/$project"
77 our @git_base_url_list = ("++GITWEB_BASE_URL++");
79 # default blob_plain mimetype and default charset for text/plain blob
80 our $default_blob_plain_mimetype = 'text/plain';
81 our $default_text_plain_charset = undef;
83 # file to use for guessing MIME types before trying /etc/mime.types
84 # (relative to the current git repository)
85 our $mimetypes_file = undef;
87 # You define site-wide feature defaults here; override them with
88 # $GITWEB_CONFIG as necessary.
91 # 'sub' => feature-sub (subroutine),
92 # 'override' => allow-override (boolean),
93 # 'default' => [ default options...] (array reference)}
95 # if feature is overridable (it means that allow-override has true value,
96 # then feature-sub will be called with default options as parameters;
97 # return value of feature-sub indicates if to enable specified feature
99 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
102 'sub' => \
&feature_blame
,
107 'sub' => \
&feature_snapshot
,
109 # => [content-encoding, suffix, program]
110 'default' => ['x-gzip', 'gz', 'gzip']},
113 'sub' => \
&feature_pickaxe
,
122 sub gitweb_check_feature
{
124 return unless exists $feature{$name};
125 my ($sub, $override, @defaults) = (
126 $feature{$name}{'sub'},
127 $feature{$name}{'override'},
128 @{$feature{$name}{'default'}});
129 if (!$override) { return @defaults; }
131 warn "feature $name is not overrideable";
134 return $sub->(@defaults);
137 # To enable system wide have in $GITWEB_CONFIG
138 # $feature{'blame'}{'default'} = [1];
139 # To have project specific config enable override in $GITWEB_CONFIG
140 # $feature{'blame'}{'override'} = 1;
141 # and in project config gitweb.blame = 0|1;
144 my ($val) = git_get_project_config
('blame', '--bool');
146 if ($val eq 'true') {
148 } elsif ($val eq 'false') {
155 # To disable system wide have in $GITWEB_CONFIG
156 # $feature{'snapshot'}{'default'} = [undef];
157 # To have project specific config enable override in $GITWEB_CONFIG
158 # $feature{'blame'}{'override'} = 1;
159 # and in project config gitweb.snapshot = none|gzip|bzip2
161 sub feature_snapshot
{
162 my ($ctype, $suffix, $command) = @_;
164 my ($val) = git_get_project_config
('snapshot');
166 if ($val eq 'gzip') {
167 return ('x-gzip', 'gz', 'gzip');
168 } elsif ($val eq 'bzip2') {
169 return ('x-bzip2', 'bz2', 'bzip2');
170 } elsif ($val eq 'none') {
174 return ($ctype, $suffix, $command);
177 sub gitweb_have_snapshot
{
178 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
179 my $have_snapshot = (defined $ctype && defined $suffix);
181 return $have_snapshot;
184 # To enable system wide have in $GITWEB_CONFIG
185 # $feature{'pickaxe'}{'default'} = [1];
186 # To have project specific config enable override in $GITWEB_CONFIG
187 # $feature{'pickaxe'}{'override'} = 1;
188 # and in project config gitweb.pickaxe = 0|1;
190 sub feature_pickaxe
{
191 my ($val) = git_get_project_config
('pickaxe', '--bool');
193 if ($val eq 'true') {
195 } elsif ($val eq 'false') {
202 # checking HEAD file with -e is fragile if the repository was
203 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
205 sub check_head_link
{
207 my $headfile = "$dir/HEAD";
208 return ((-e
$headfile) ||
209 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
212 sub check_export_ok
{
214 return (check_head_link
($dir) &&
215 (!$export_ok || -e
"$dir/$export_ok"));
218 # rename detection options for git-diff and git-diff-tree
219 # - default is '-M', with the cost proportional to
220 # (number of removed files) * (number of new files).
221 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
222 # (number of changed files + number of removed files) * (number of new files)
223 # - even more costly is '-C', '--find-copies-harder' with cost
224 # (number of files in the original tree) * (number of new files)
225 # - one might want to include '-B' option, e.g. '-B', '-M'
226 our @diff_opts = ('-M'); # taken from git_commit
228 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
229 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
231 # version of the core git binary
232 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
234 $projects_list ||= $projectroot;
236 # ======================================================================
237 # input validation and dispatch
238 our $action = $cgi->param('a');
239 if (defined $action) {
240 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
241 die_error
(undef, "Invalid action parameter");
245 # parameters which are pathnames
246 our $project = $cgi->param('p');
247 if (defined $project) {
248 if (!validate_pathname
($project) ||
249 !(-d
"$projectroot/$project") ||
250 !check_head_link
("$projectroot/$project") ||
251 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
252 ($strict_export && !project_in_list
($project))) {
254 die_error
(undef, "No such project");
258 our $file_name = $cgi->param('f');
259 if (defined $file_name) {
260 if (!validate_pathname
($file_name)) {
261 die_error
(undef, "Invalid file parameter");
265 our $file_parent = $cgi->param('fp');
266 if (defined $file_parent) {
267 if (!validate_pathname
($file_parent)) {
268 die_error
(undef, "Invalid file parent parameter");
272 # parameters which are refnames
273 our $hash = $cgi->param('h');
275 if (!validate_refname
($hash)) {
276 die_error
(undef, "Invalid hash parameter");
280 our $hash_parent = $cgi->param('hp');
281 if (defined $hash_parent) {
282 if (!validate_refname
($hash_parent)) {
283 die_error
(undef, "Invalid hash parent parameter");
287 our $hash_base = $cgi->param('hb');
288 if (defined $hash_base) {
289 if (!validate_refname
($hash_base)) {
290 die_error
(undef, "Invalid hash base parameter");
294 our $hash_parent_base = $cgi->param('hpb');
295 if (defined $hash_parent_base) {
296 if (!validate_refname
($hash_parent_base)) {
297 die_error
(undef, "Invalid hash parent base parameter");
302 our $page = $cgi->param('pg');
304 if ($page =~ m/[^0-9]/) {
305 die_error
(undef, "Invalid page parameter");
309 our $searchtext = $cgi->param('s');
310 if (defined $searchtext) {
311 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
312 die_error
(undef, "Invalid search parameter");
314 $searchtext = quotemeta $searchtext;
317 # now read PATH_INFO and use it as alternative to parameters
318 sub evaluate_path_info
{
319 return if defined $project;
320 my $path_info = $ENV{"PATH_INFO"};
321 return if !$path_info;
322 $path_info =~ s
,^/+,,;
323 return if !$path_info;
324 # find which part of PATH_INFO is project
325 $project = $path_info;
327 while ($project && !check_head_link
("$projectroot/$project")) {
328 $project =~ s
,/*[^/]*$,,;
331 $project = validate_pathname
($project);
333 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
334 ($strict_export && !project_in_list
($project))) {
338 # do not change any parameters if an action is given using the query string
340 $path_info =~ s
,^$project/*,,;
341 my ($refname, $pathname) = split(/:/, $path_info, 2);
342 if (defined $pathname) {
343 # we got "project.git/branch:filename" or "project.git/branch:dir/"
344 # we could use git_get_type(branch:pathname), but it needs $git_dir
345 $pathname =~ s
,^/+,,;
346 if (!$pathname || substr($pathname, -1) eq "/") {
350 $action ||= "blob_plain";
352 $hash_base ||= validate_refname
($refname);
353 $file_name ||= validate_pathname
($pathname);
354 } elsif (defined $refname) {
355 # we got "project.git/branch"
356 $action ||= "shortlog";
357 $hash ||= validate_refname
($refname);
360 evaluate_path_info
();
362 # path to the current git repository
364 $git_dir = "$projectroot/$project" if $project;
368 "blame" => \
&git_blame2
,
369 "blobdiff" => \
&git_blobdiff
,
370 "blobdiff_plain" => \
&git_blobdiff_plain
,
371 "blob" => \
&git_blob
,
372 "blob_plain" => \
&git_blob_plain
,
373 "commitdiff" => \
&git_commitdiff
,
374 "commitdiff_plain" => \
&git_commitdiff_plain
,
375 "commit" => \
&git_commit
,
376 "heads" => \
&git_heads
,
377 "history" => \
&git_history
,
380 "search" => \
&git_search
,
381 "shortlog" => \
&git_shortlog
,
382 "summary" => \
&git_summary
,
384 "tags" => \
&git_tags
,
385 "tree" => \
&git_tree
,
386 "snapshot" => \
&git_snapshot
,
387 # those below don't need $project
388 "opml" => \
&git_opml
,
389 "project_list" => \
&git_project_list
,
390 "project_index" => \
&git_project_index
,
393 if (defined $project) {
394 $action ||= 'summary';
396 $action ||= 'project_list';
398 if (!defined($actions{$action})) {
399 die_error
(undef, "Unknown action");
401 if ($action !~ m/^(opml|project_list|project_index)$/ &&
403 die_error
(undef, "Project needed");
405 $actions{$action}->();
408 ## ======================================================================
423 hash_parent_base
=> "hpb",
428 my %mapping = @mapping;
430 $params{'project'} = $project unless exists $params{'project'};
432 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
434 # use PATH_INFO for project name
435 $href .= "/$params{'project'}" if defined $params{'project'};
436 delete $params{'project'};
438 # Summary just uses the project path URL
439 if (defined $params{'action'} && $params{'action'} eq 'summary') {
440 delete $params{'action'};
444 # now encode the parameters explicitly
446 for (my $i = 0; $i < @mapping; $i += 2) {
447 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
448 if (defined $params{$name}) {
449 push @result, $symbol . "=" . esc_param
($params{$name});
452 $href .= "?" . join(';', @result) if scalar @result;
458 ## ======================================================================
459 ## validation, quoting/unquoting and escaping
461 sub validate_pathname
{
462 my $input = shift || return undef;
464 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
465 # at the beginning, at the end, and between slashes.
466 # also this catches doubled slashes
467 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
471 if ($input =~ m!\0!) {
477 sub validate_refname
{
478 my $input = shift || return undef;
480 # textual hashes are O.K.
481 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
484 # it must be correct pathname
485 $input = validate_pathname
($input)
487 # restrictions on ref name according to git-check-ref-format
488 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
494 # quote unsafe chars, but keep the slash, even when it's not
495 # correct, but quoted slashes look too horrible in bookmarks
498 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
504 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
507 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
513 # replace invalid utf8 character with SUBSTITUTION sequence
516 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
517 $str = escapeHTML
($str);
518 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
519 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
523 # git may return quoted and escaped filenames
526 if ($str =~ m/^"(.*)"$/) {
528 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
533 # escape tabs (convert tabs to spaces)
537 while ((my $pos = index($line, "\t")) != -1) {
538 if (my $count = (8 - ($pos % 8))) {
539 my $spaces = ' ' x
$count;
540 $line =~ s/\t/$spaces/;
547 sub project_in_list
{
549 my @list = git_get_projects_list
();
550 return @list && scalar(grep { $_->{'path'} eq $project } @list);
553 ## ----------------------------------------------------------------------
554 ## HTML aware string manipulation
559 my $add_len = shift || 10;
561 # allow only $len chars, but don't cut a word if it would fit in $add_len
562 # if it doesn't fit, cut it if it's still longer than the dots we would add
563 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
566 if (length($tail) > 4) {
568 $body =~ s/&[^;]*$//; # remove chopped character entities
573 ## ----------------------------------------------------------------------
574 ## functions returning short strings
576 # CSS class for given age value (in seconds)
580 if ($age < 60*60*2) {
582 } elsif ($age < 60*60*24*2) {
589 # convert age in seconds to "nn units ago" string
594 if ($age > 60*60*24*365*2) {
595 $age_str = (int $age/60/60/24/365);
596 $age_str .= " years ago";
597 } elsif ($age > 60*60*24*(365/12)*2) {
598 $age_str = int $age/60/60/24/(365/12);
599 $age_str .= " months ago";
600 } elsif ($age > 60*60*24*7*2) {
601 $age_str = int $age/60/60/24/7;
602 $age_str .= " weeks ago";
603 } elsif ($age > 60*60*24*2) {
604 $age_str = int $age/60/60/24;
605 $age_str .= " days ago";
606 } elsif ($age > 60*60*2) {
607 $age_str = int $age/60/60;
608 $age_str .= " hours ago";
609 } elsif ($age > 60*2) {
610 $age_str = int $age/60;
611 $age_str .= " min ago";
614 $age_str .= " sec ago";
616 $age_str .= " right now";
621 # convert file mode in octal to symbolic file mode string
623 my $mode = oct shift;
625 if (S_ISDIR
($mode & S_IFMT
)) {
627 } elsif (S_ISLNK
($mode)) {
629 } elsif (S_ISREG
($mode)) {
630 # git cares only about the executable bit
631 if ($mode & S_IXUSR
) {
641 # convert file mode in octal to file type string
645 if ($mode !~ m/^[0-7]+$/) {
651 if (S_ISDIR
($mode & S_IFMT
)) {
653 } elsif (S_ISLNK
($mode)) {
655 } elsif (S_ISREG
($mode)) {
662 ## ----------------------------------------------------------------------
663 ## functions returning short HTML fragments, or transforming HTML fragments
664 ## which don't beling to other sections
666 # format line of commit message or tag comment
667 sub format_log_line_html
{
670 $line = esc_html
($line);
671 $line =~ s/ / /g;
672 if ($line =~ m/([0-9a-fA-F]{40})/) {
674 if (git_get_type
($hash_text) eq "commit") {
676 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
677 -class => "text"}, $hash_text);
678 $line =~ s/$hash_text/$link/;
684 # format marker of refs pointing to given object
685 sub format_ref_marker
{
686 my ($refs, $id) = @_;
689 if (defined $refs->{$id}) {
690 foreach my $ref (@{$refs->{$id}}) {
691 my ($type, $name) = qw();
692 # e.g. tags/v2.6.11 or heads/next
693 if ($ref =~ m!^(.*?)s?/(.*)$!) {
701 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
706 return ' <span class="refs">'. $markers . '</span>';
712 # format, perhaps shortened and with markers, title line
713 sub format_subject_html
{
714 my ($long, $short, $href, $extra) = @_;
715 $extra = '' unless defined($extra);
717 if (length($short) < length($long)) {
718 return $cgi->a({-href
=> $href, -class => "list subject",
719 -title
=> decode
("utf8", $long, Encode
::FB_DEFAULT
)},
720 esc_html
($short) . $extra);
722 return $cgi->a({-href
=> $href, -class => "list subject"},
723 esc_html
($long) . $extra);
727 sub format_diff_line
{
729 my $char = substr($line, 0, 1);
735 $diff_class = " add";
736 } elsif ($char eq "-") {
737 $diff_class = " rem";
738 } elsif ($char eq "@") {
739 $diff_class = " chunk_header";
740 } elsif ($char eq "\\") {
741 $diff_class = " incomplete";
743 $line = untabify
($line);
744 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
747 ## ----------------------------------------------------------------------
748 ## git utility subroutines, invoking git commands
750 # returns path to the core git executable and the --git-dir parameter as list
752 return $GIT, '--git-dir='.$git_dir;
755 # returns path to the core git executable and the --git-dir parameter as string
757 return join(' ', git_cmd
());
760 # get HEAD ref of given project as hash
761 sub git_get_head_hash
{
763 my $o_git_dir = $git_dir;
765 $git_dir = "$projectroot/$project";
766 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
769 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
773 if (defined $o_git_dir) {
774 $git_dir = $o_git_dir;
779 # get type of given object
783 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
790 sub git_get_project_config
{
791 my ($key, $type) = @_;
793 return unless ($key);
794 $key =~ s/^gitweb\.//;
795 return if ($key =~ m/\W/);
797 my @x = (git_cmd
(), 'repo-config');
798 if (defined $type) { push @x, $type; }
800 push @x, "gitweb.$key";
806 # get hash of given path at given ref
807 sub git_get_hash_by_path
{
809 my $path = shift || return undef;
814 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
815 or die_error
(undef, "Open git-ls-tree failed");
817 close $fd or return undef;
819 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
820 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
821 if (defined $type && $type ne $2) {
828 ## ......................................................................
829 ## git utility functions, directly accessing git repository
831 sub git_get_project_description
{
834 open my $fd, "$projectroot/$path/description" or return undef;
841 sub git_get_project_url_list
{
844 open my $fd, "$projectroot/$path/cloneurl" or return;
845 my @git_project_url_list = map { chomp; $_ } <$fd>;
848 return wantarray ? @git_project_url_list : \
@git_project_url_list;
851 sub git_get_projects_list
{
854 if (-d
$projects_list) {
855 # search in directory
856 my $dir = $projects_list;
857 my $pfxlen = length("$dir");
860 follow_fast
=> 1, # follow symbolic links
861 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
863 # skip project-list toplevel, if we get it.
864 return if (m!^[/.]$!);
865 # only directories can be git repositories
866 return unless (-d
$_);
868 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
869 # we check related file in $projectroot
870 if (check_export_ok
("$projectroot/$subdir")) {
871 push @list, { path
=> $subdir };
872 $File::Find
::prune
= 1;
877 } elsif (-f
$projects_list) {
878 # read from file(url-encoded):
879 # 'git%2Fgit.git Linus+Torvalds'
880 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
881 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
882 open my ($fd), $projects_list or return;
883 while (my $line = <$fd>) {
885 my ($path, $owner) = split ' ', $line;
886 $path = unescape
($path);
887 $owner = unescape
($owner);
888 if (!defined $path) {
891 if (check_export_ok
("$projectroot/$path")) {
894 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
901 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
905 sub git_get_project_owner
{
909 return undef unless $project;
911 # read from file (url-encoded):
912 # 'git%2Fgit.git Linus+Torvalds'
913 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
914 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
915 if (-f
$projects_list) {
916 open (my $fd , $projects_list);
917 while (my $line = <$fd>) {
919 my ($pr, $ow) = split ' ', $line;
922 if ($pr eq $project) {
923 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
929 if (!defined $owner) {
930 $owner = get_file_owner
("$projectroot/$project");
936 sub git_get_references
{
937 my $type = shift || "";
939 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
940 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
941 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
944 while (my $line = <$fd>) {
946 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
947 if (defined $refs{$1}) {
948 push @{$refs{$1}}, $2;
958 sub git_get_rev_name_tags
{
959 my $hash = shift || return undef;
961 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
963 my $name_rev = <$fd>;
966 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
969 # catches also '$hash undefined' output
974 ## ----------------------------------------------------------------------
975 ## parse to hash functions
979 my $tz = shift || "-0000";
982 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
983 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
984 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
985 $date{'hour'} = $hour;
986 $date{'minute'} = $min;
987 $date{'mday'} = $mday;
988 $date{'day'} = $days[$wday];
989 $date{'month'} = $months[$mon];
990 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
991 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
992 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
993 $mday, $months[$mon], $hour ,$min;
995 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
996 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
997 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
998 $date{'hour_local'} = $hour;
999 $date{'minute_local'} = $min;
1000 $date{'tz_local'} = $tz;
1001 $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
1002 1900+$year, $mon+1, $mday,
1003 $hour, $min, $sec, $tz);
1012 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1013 $tag{'id'} = $tag_id;
1014 while (my $line = <$fd>) {
1016 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1017 $tag{'object'} = $1;
1018 } elsif ($line =~ m/^type (.+)$/) {
1020 } elsif ($line =~ m/^tag (.+)$/) {
1022 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1023 $tag{'author'} = $1;
1026 } elsif ($line =~ m/--BEGIN/) {
1027 push @comment, $line;
1029 } elsif ($line eq "") {
1033 push @comment, <$fd>;
1034 $tag{'comment'} = \
@comment;
1035 close $fd or return;
1036 if (!defined $tag{'name'}) {
1043 my $commit_id = shift;
1044 my $commit_text = shift;
1049 if (defined $commit_text) {
1050 @commit_lines = @$commit_text;
1053 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1055 @commit_lines = split '\n', <$fd>;
1056 close $fd or return;
1060 my $header = shift @commit_lines;
1061 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1064 ($co{'id'}, my @parents) = split ' ', $header;
1065 $co{'parents'} = \
@parents;
1066 $co{'parent'} = $parents[0];
1067 while (my $line = shift @commit_lines) {
1068 last if $line eq "\n";
1069 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1071 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1073 $co{'author_epoch'} = $2;
1074 $co{'author_tz'} = $3;
1075 if ($co{'author'} =~ m/^([^<]+) </) {
1076 $co{'author_name'} = $1;
1078 $co{'author_name'} = $co{'author'};
1080 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1081 $co{'committer'} = $1;
1082 $co{'committer_epoch'} = $2;
1083 $co{'committer_tz'} = $3;
1084 $co{'committer_name'} = $co{'committer'};
1085 $co{'committer_name'} =~ s/ <.*//;
1088 if (!defined $co{'tree'}) {
1092 foreach my $title (@commit_lines) {
1095 $co{'title'} = chop_str
($title, 80, 5);
1096 # remove leading stuff of merges to make the interesting part visible
1097 if (length($title) > 50) {
1098 $title =~ s/^Automatic //;
1099 $title =~ s/^merge (of|with) /Merge ... /i;
1100 if (length($title) > 50) {
1101 $title =~ s/(http|rsync):\/\///;
1103 if (length($title) > 50) {
1104 $title =~ s/(master|www|rsync)\.//;
1106 if (length($title) > 50) {
1107 $title =~ s/kernel.org:?//;
1109 if (length($title) > 50) {
1110 $title =~ s/\/pub\/scm//;
1113 $co{'title_short'} = chop_str
($title, 50, 5);
1117 # remove added spaces
1118 foreach my $line (@commit_lines) {
1121 $co{'comment'} = \
@commit_lines;
1123 my $age = time - $co{'committer_epoch'};
1125 $co{'age_string'} = age_string
($age);
1126 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1127 if ($age > 60*60*24*7*2) {
1128 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1129 $co{'age_string_age'} = $co{'age_string'};
1131 $co{'age_string_date'} = $co{'age_string'};
1132 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1137 # parse ref from ref_file, given by ref_id, with given type
1139 my $ref_file = shift;
1141 my $type = shift || git_get_type
($ref_id);
1144 $ref_item{'type'} = $type;
1145 $ref_item{'id'} = $ref_id;
1146 $ref_item{'epoch'} = 0;
1147 $ref_item{'age'} = "unknown";
1148 if ($type eq "tag") {
1149 my %tag = parse_tag
($ref_id);
1150 $ref_item{'comment'} = $tag{'comment'};
1151 if ($tag{'type'} eq "commit") {
1152 my %co = parse_commit
($tag{'object'});
1153 $ref_item{'epoch'} = $co{'committer_epoch'};
1154 $ref_item{'age'} = $co{'age_string'};
1155 } elsif (defined($tag{'epoch'})) {
1156 my $age = time - $tag{'epoch'};
1157 $ref_item{'epoch'} = $tag{'epoch'};
1158 $ref_item{'age'} = age_string
($age);
1160 $ref_item{'reftype'} = $tag{'type'};
1161 $ref_item{'name'} = $tag{'name'};
1162 $ref_item{'refid'} = $tag{'object'};
1163 } elsif ($type eq "commit"){
1164 my %co = parse_commit
($ref_id);
1165 $ref_item{'reftype'} = "commit";
1166 $ref_item{'name'} = $ref_file;
1167 $ref_item{'title'} = $co{'title'};
1168 $ref_item{'refid'} = $ref_id;
1169 $ref_item{'epoch'} = $co{'committer_epoch'};
1170 $ref_item{'age'} = $co{'age_string'};
1172 $ref_item{'reftype'} = $type;
1173 $ref_item{'name'} = $ref_file;
1174 $ref_item{'refid'} = $ref_id;
1180 # parse line of git-diff-tree "raw" output
1181 sub parse_difftree_raw_line
{
1185 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1186 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1187 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1188 $res{'from_mode'} = $1;
1189 $res{'to_mode'} = $2;
1190 $res{'from_id'} = $3;
1192 $res{'status'} = $5;
1193 $res{'similarity'} = $6;
1194 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1195 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1197 $res{'file'} = unquote
($7);
1200 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1201 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1202 $res{'commit'} = $1;
1205 return wantarray ? %res : \
%res;
1208 # parse line of git-ls-tree output
1209 sub parse_ls_tree_line
($;%) {
1214 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1215 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1223 $res{'name'} = unquote
($4);
1226 return wantarray ? %res : \
%res;
1229 ## ......................................................................
1230 ## parse to array of hashes functions
1232 sub git_get_refs_list
{
1233 my $type = shift || "";
1238 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1240 while (my $line = <$fd>) {
1242 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1243 if (defined $refs{$1}) {
1244 push @{$refs{$1}}, $2;
1249 if (! $4) { # unpeeled, direct reference
1250 push @refs, { hash
=> $1, name
=> $3 }; # without type
1251 } elsif ($3 eq $refs[-1]{'name'}) {
1252 # most likely a tag is followed by its peeled
1253 # (deref) one, and when that happens we know the
1254 # previous one was of type 'tag'.
1255 $refs[-1]{'type'} = "tag";
1261 foreach my $ref (@refs) {
1262 my $ref_file = $ref->{'name'};
1263 my $ref_id = $ref->{'hash'};
1265 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1266 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1268 push @reflist, \
%ref_item;
1271 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1272 return (\
@reflist, \
%refs);
1275 ## ----------------------------------------------------------------------
1276 ## filesystem-related functions
1278 sub get_file_owner
{
1281 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1282 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1283 if (!defined $gcos) {
1287 $owner =~ s/[,;].*$//;
1288 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1291 ## ......................................................................
1292 ## mimetype related functions
1294 sub mimetype_guess_file
{
1295 my $filename = shift;
1296 my $mimemap = shift;
1297 -r
$mimemap or return undef;
1300 open(MIME
, $mimemap) or return undef;
1302 next if m/^#/; # skip comments
1303 my ($mime, $exts) = split(/\t+/);
1304 if (defined $exts) {
1305 my @exts = split(/\s+/, $exts);
1306 foreach my $ext (@exts) {
1307 $mimemap{$ext} = $mime;
1313 $filename =~ /\.([^.]*)$/;
1314 return $mimemap{$1};
1317 sub mimetype_guess
{
1318 my $filename = shift;
1320 $filename =~ /\./ or return undef;
1322 if ($mimetypes_file) {
1323 my $file = $mimetypes_file;
1324 if ($file !~ m!^/!) { # if it is relative path
1325 # it is relative to project
1326 $file = "$projectroot/$project/$file";
1328 $mime = mimetype_guess_file
($filename, $file);
1330 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1336 my $filename = shift;
1339 my $mime = mimetype_guess
($filename);
1340 $mime and return $mime;
1344 return $default_blob_plain_mimetype unless $fd;
1347 return 'text/plain' .
1348 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1349 } elsif (! $filename) {
1350 return 'application/octet-stream';
1351 } elsif ($filename =~ m/\.png$/i) {
1353 } elsif ($filename =~ m/\.gif$/i) {
1355 } elsif ($filename =~ m/\.jpe?g$/i) {
1356 return 'image/jpeg';
1358 return 'application/octet-stream';
1362 ## ======================================================================
1363 ## functions printing HTML: header, footer, error page
1365 sub git_header_html
{
1366 my $status = shift || "200 OK";
1367 my $expires = shift;
1369 my $title = "$site_name git";
1370 if (defined $project) {
1371 $title .= " - $project";
1372 if (defined $action) {
1373 $title .= "/$action";
1374 if (defined $file_name) {
1375 $title .= " - " . esc_html
($file_name);
1376 if ($action eq "tree" && $file_name !~ m
|/$|) {
1383 # require explicit support from the UA if we are to send the page as
1384 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1385 # we have to do this because MSIE sometimes globs '*/*', pretending to
1386 # support xhtml+xml but choking when it gets what it asked for.
1387 if (defined $cgi->http('HTTP_ACCEPT') &&
1388 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1389 $cgi->Accept('application/xhtml+xml') != 0) {
1390 $content_type = 'application/xhtml+xml';
1392 $content_type = 'text/html';
1394 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1395 -status
=> $status, -expires
=> $expires);
1397 <?xml version="1.0" encoding="utf-8"?>
1398 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1399 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1400 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1401 <!-- git core binaries version $git_version -->
1403 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1404 <meta name="generator" content="gitweb/$version git/$git_version"/>
1405 <meta name="robots" content="index, nofollow"/>
1406 <title>$title</title>
1408 # print out each stylesheet that exist
1409 if (defined $stylesheet) {
1410 #provides backwards capability for those people who define style sheet in a config file
1411 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1413 foreach my $stylesheet (@stylesheets) {
1414 next unless $stylesheet;
1415 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1418 if (defined $project) {
1419 printf('<link rel="alternate" title="%s log" '.
1420 'href="%s" type="application/rss+xml"/>'."\n",
1421 esc_param
($project), href
(action
=>"rss"));
1423 printf('<link rel="alternate" title="%s projects list" '.
1424 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1425 $site_name, href
(project
=>undef, action
=>"project_index"));
1426 printf('<link rel="alternate" title="%s projects logs" '.
1427 'href="%s" type="text/x-opml"/>'."\n",
1428 $site_name, href
(project
=>undef, action
=>"opml"));
1430 if (defined $favicon) {
1431 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1437 if (-f
$site_header) {
1438 open (my $fd, $site_header);
1443 print "<div class=\"page_header\">\n" .
1444 "<a href=\"" . esc_html
($githelp_url) .
1445 "\" title=\"" . esc_html
($githelp_label) .
1447 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1449 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1450 if (defined $project) {
1451 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1452 if (defined $action) {
1456 if (!defined $searchtext) {
1460 if (defined $hash_base) {
1461 $search_hash = $hash_base;
1462 } elsif (defined $hash) {
1463 $search_hash = $hash;
1465 $search_hash = "HEAD";
1467 $cgi->param("a", "search");
1468 $cgi->param("h", $search_hash);
1469 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1470 "<div class=\"search\">\n" .
1471 $cgi->hidden(-name
=> "p") . "\n" .
1472 $cgi->hidden(-name
=> "a") . "\n" .
1473 $cgi->hidden(-name
=> "h") . "\n" .
1474 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1476 $cgi->end_form() . "\n";
1481 sub git_footer_html
{
1482 print "<div class=\"page_footer\">\n";
1483 if (defined $project) {
1484 my $descr = git_get_project_description
($project);
1485 if (defined $descr) {
1486 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1488 print $cgi->a({-href
=> href
(action
=>"rss"),
1489 -class => "rss_logo"}, "RSS") . "\n";
1491 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1492 -class => "rss_logo"}, "OPML") . " ";
1493 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1494 -class => "rss_logo"}, "TXT") . "\n";
1498 if (-f
$site_footer) {
1499 open (my $fd, $site_footer);
1509 my $status = shift || "403 Forbidden";
1510 my $error = shift || "Malformed query, file missing or permission denied";
1512 git_header_html
($status);
1514 <div class="page_body">
1524 ## ----------------------------------------------------------------------
1525 ## functions printing or outputting HTML: navigation
1527 sub git_print_page_nav
{
1528 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1529 $extra = '' if !defined $extra; # pager or formats
1531 my @navs = qw(summary shortlog log commit commitdiff tree);
1533 @navs = grep { $_ ne $suppress } @navs;
1536 my %arg = map { $_ => {action
=>$_} } @navs;
1537 if (defined $head) {
1538 for (qw(commit commitdiff)) {
1539 $arg{$_}{hash
} = $head;
1541 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1542 for (qw(shortlog log)) {
1543 $arg{$_}{hash
} = $head;
1547 $arg{tree
}{hash
} = $treehead if defined $treehead;
1548 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1550 print "<div class=\"page_nav\">\n" .
1552 map { $_ eq $current ?
1553 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1555 print "<br/>\n$extra<br/>\n" .
1559 sub format_paging_nav
{
1560 my ($action, $hash, $head, $page, $nrevs) = @_;
1564 if ($hash ne $head || $page) {
1565 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1567 $paging_nav .= "HEAD";
1571 $paging_nav .= " ⋅ " .
1572 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1573 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1575 $paging_nav .= " ⋅ prev";
1578 if ($nrevs >= (100 * ($page+1)-1)) {
1579 $paging_nav .= " ⋅ " .
1580 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1581 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1583 $paging_nav .= " ⋅ next";
1589 ## ......................................................................
1590 ## functions printing or outputting HTML: div
1592 sub git_print_header_div
{
1593 my ($action, $title, $hash, $hash_base) = @_;
1596 $args{action
} = $action;
1597 $args{hash
} = $hash if $hash;
1598 $args{hash_base
} = $hash_base if $hash_base;
1600 print "<div class=\"header\">\n" .
1601 $cgi->a({-href
=> href
(%args), -class => "title"},
1602 $title ? $title : $action) .
1606 #sub git_print_authorship (\%) {
1607 sub git_print_authorship
{
1610 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1611 print "<div class=\"author_date\">" .
1612 esc_html
($co->{'author_name'}) .
1614 if ($ad{'hour_local'} < 6) {
1615 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1616 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1618 printf(" (%02d:%02d %s)",
1619 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1624 sub git_print_page_path
{
1629 if (!defined $name) {
1630 print "<div class=\"page_path\">/</div>\n";
1632 my @dirname = split '/', $name;
1633 my $basename = pop @dirname;
1636 print "<div class=\"page_path\">";
1637 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1638 -title
=> 'tree root'}, "[$project]");
1640 foreach my $dir (@dirname) {
1641 $fullname .= ($fullname ? '/' : '') . $dir;
1642 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1644 -title
=> $fullname}, esc_html
($dir));
1647 if (defined $type && $type eq 'blob') {
1648 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1650 -title
=> $name}, esc_html
($basename));
1651 } elsif (defined $type && $type eq 'tree') {
1652 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1654 -title
=> $name}, esc_html
($basename));
1656 print esc_html
($basename);
1658 print "<br/></div>\n";
1662 # sub git_print_log (\@;%) {
1663 sub git_print_log
($;%) {
1667 if ($opts{'-remove_title'}) {
1668 # remove title, i.e. first line of log
1671 # remove leading empty lines
1672 while (defined $log->[0] && $log->[0] eq "") {
1679 foreach my $line (@$log) {
1680 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1683 if (! $opts{'-remove_signoff'}) {
1684 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1687 # remove signoff lines
1694 # print only one empty line
1695 # do not print empty line after signoff
1697 next if ($empty || $signoff);
1703 print format_log_line_html
($line) . "<br/>\n";
1706 if ($opts{'-final_empty_line'}) {
1707 # end with single empty line
1708 print "<br/>\n" unless $empty;
1712 sub git_print_simplified_log
{
1714 my $remove_title = shift;
1717 -final_empty_line
=> 1,
1718 -remove_title
=> $remove_title);
1721 # print tree entry (row of git_tree), but without encompassing <tr> element
1722 sub git_print_tree_entry
{
1723 my ($t, $basedir, $hash_base, $have_blame) = @_;
1726 $base_key{hash_base
} = $hash_base if defined $hash_base;
1728 # The format of a table row is: mode list link. Where mode is
1729 # the mode of the entry, list is the name of the entry, an href,
1730 # and link is the action links of the entry.
1732 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1733 if ($t->{'type'} eq "blob") {
1734 print "<td class=\"list\">" .
1735 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1736 file_name
=>"$basedir$t->{'name'}", %base_key),
1737 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1738 print "<td class=\"link\">";
1740 print $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1741 file_name
=>"$basedir$t->{'name'}", %base_key)},
1744 if (defined $hash_base) {
1748 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1749 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1753 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1754 file_name
=>"$basedir$t->{'name'}")},
1758 } elsif ($t->{'type'} eq "tree") {
1759 print "<td class=\"list\">";
1760 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1761 file_name
=>"$basedir$t->{'name'}", %base_key)},
1762 esc_html
($t->{'name'}));
1764 print "<td class=\"link\">";
1765 if (defined $hash_base) {
1766 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1767 file_name
=>"$basedir$t->{'name'}")},
1774 ## ......................................................................
1775 ## functions printing large fragments of HTML
1777 sub git_difftree_body
{
1778 my ($difftree, $hash, $parent) = @_;
1780 print "<div class=\"list_head\">\n";
1781 if ($#{$difftree} > 10) {
1782 print(($#{$difftree} + 1) . " files changed:\n");
1786 print "<table class=\"diff_tree\">\n";
1789 foreach my $line (@{$difftree}) {
1790 my %diff = parse_difftree_raw_line
($line);
1793 print "<tr class=\"dark\">\n";
1795 print "<tr class=\"light\">\n";
1799 my ($to_mode_oct, $to_mode_str, $to_file_type);
1800 my ($from_mode_oct, $from_mode_str, $from_file_type);
1801 if ($diff{'to_mode'} ne ('0' x
6)) {
1802 $to_mode_oct = oct $diff{'to_mode'};
1803 if (S_ISREG
($to_mode_oct)) { # only for regular file
1804 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1806 $to_file_type = file_type
($diff{'to_mode'});
1808 if ($diff{'from_mode'} ne ('0' x
6)) {
1809 $from_mode_oct = oct $diff{'from_mode'};
1810 if (S_ISREG
($to_mode_oct)) { # only for regular file
1811 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1813 $from_file_type = file_type
($diff{'from_mode'});
1816 if ($diff{'status'} eq "A") { # created
1817 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1818 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1819 $mode_chng .= "]</span>";
1821 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1822 hash_base
=>$hash, file_name
=>$diff{'file'}),
1823 -class => "list"}, esc_html
($diff{'file'}));
1825 print "<td>$mode_chng</td>\n";
1826 print "<td class=\"link\">";
1827 if ($action eq 'commitdiff') {
1830 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1834 } elsif ($diff{'status'} eq "D") { # deleted
1835 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1837 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1838 hash_base
=>$parent, file_name
=>$diff{'file'}),
1839 -class => "list"}, esc_html
($diff{'file'}));
1841 print "<td>$mode_chng</td>\n";
1842 print "<td class=\"link\">";
1843 if ($action eq 'commitdiff') {
1846 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1849 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1850 file_name
=>$diff{'file'})},
1852 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1853 file_name
=>$diff{'file'})},
1857 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1858 my $mode_chnge = "";
1859 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1860 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1861 if ($from_file_type != $to_file_type) {
1862 $mode_chnge .= " from $from_file_type to $to_file_type";
1864 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1865 if ($from_mode_str && $to_mode_str) {
1866 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1867 } elsif ($to_mode_str) {
1868 $mode_chnge .= " mode: $to_mode_str";
1871 $mode_chnge .= "]</span>\n";
1874 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1875 hash_base
=>$hash, file_name
=>$diff{'file'}),
1876 -class => "list"}, esc_html
($diff{'file'}));
1878 print "<td>$mode_chnge</td>\n";
1879 print "<td class=\"link\">";
1880 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1881 if ($action eq 'commitdiff') {
1884 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1886 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1887 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1888 hash_base
=>$hash, hash_parent_base
=>$parent,
1889 file_name
=>$diff{'file'})},
1894 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1895 file_name
=>$diff{'file'})},
1897 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1898 file_name
=>$diff{'file'})},
1902 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1903 my %status_name = ('R' => 'moved', 'C' => 'copied');
1904 my $nstatus = $status_name{$diff{'status'}};
1906 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1907 # mode also for directories, so we cannot use $to_mode_str
1908 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1911 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1912 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1913 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1914 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1915 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1916 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1917 -class => "list"}, esc_html
($diff{'from_file'})) .
1918 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1919 "<td class=\"link\">";
1920 if ($diff{'to_id'} ne $diff{'from_id'}) {
1921 if ($action eq 'commitdiff') {
1924 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1926 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1927 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1928 hash_base
=>$hash, hash_parent_base
=>$parent,
1929 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1934 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1935 file_name
=>$diff{'from_file'})},
1937 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1938 file_name
=>$diff{'from_file'})},
1942 } # we should not encounter Unmerged (U) or Unknown (X) status
1948 sub git_patchset_body
{
1949 my ($fd, $difftree, $hash, $hash_parent) = @_;
1953 my $patch_found = 0;
1956 print "<div class=\"patchset\">\n";
1959 while (my $patch_line = <$fd>) {
1962 if ($patch_line =~ m/^diff /) { # "git diff" header
1963 # beginning of patch (in patchset)
1965 # close previous patch
1966 print "</div>\n"; # class="patch"
1968 # first patch in patchset
1971 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1973 if (ref($difftree->[$patch_idx]) eq "HASH") {
1974 $diffinfo = $difftree->[$patch_idx];
1976 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1980 # for now, no extended header, hence we skip empty patches
1981 # companion to next LINE if $in_header;
1982 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1987 if ($diffinfo->{'status'} eq "A") { # added
1988 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1989 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1990 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1991 $diffinfo->{'to_id'}) . "(new)" .
1992 "</div>\n"; # class="diff_info"
1994 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1995 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1996 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1997 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1998 $diffinfo->{'from_id'}) . "(deleted)" .
1999 "</div>\n"; # class="diff_info"
2001 } elsif ($diffinfo->{'status'} eq "R" || # renamed
2002 $diffinfo->{'status'} eq "C" || # copied
2003 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
2004 print "<div class=\"diff_info\">" .
2005 file_type
($diffinfo->{'from_mode'}) . ":" .
2006 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2007 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
2008 $diffinfo->{'from_id'}) .
2010 file_type
($diffinfo->{'to_mode'}) . ":" .
2011 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2012 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
2013 $diffinfo->{'to_id'});
2014 print "</div>\n"; # class="diff_info"
2016 } else { # modified, mode changed, ...
2017 print "<div class=\"diff_info\">" .
2018 file_type
($diffinfo->{'from_mode'}) . ":" .
2019 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2020 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2021 $diffinfo->{'from_id'}) .
2023 file_type
($diffinfo->{'to_mode'}) . ":" .
2024 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2025 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2026 $diffinfo->{'to_id'});
2027 print "</div>\n"; # class="diff_info"
2030 #print "<div class=\"diff extended_header\">\n";
2033 } # start of patch in patchset
2036 if ($in_header && $patch_line =~ m/^---/) {
2037 #print "</div>\n"; # class="diff extended_header"
2040 my $file = $diffinfo->{'from_file'};
2041 $file ||= $diffinfo->{'file'};
2042 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2043 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2044 -class => "list"}, esc_html
($file));
2045 $patch_line =~ s
|a
/.*$|a/$file|g
;
2046 print "<div class=\"diff from_file\">$patch_line</div>\n";
2048 $patch_line = <$fd>;
2051 #$patch_line =~ m/^+++/;
2052 $file = $diffinfo->{'to_file'};
2053 $file ||= $diffinfo->{'file'};
2054 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2055 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2056 -class => "list"}, esc_html
($file));
2057 $patch_line =~ s
|b
/.*|b/$file|g
;
2058 print "<div class=\"diff to_file\">$patch_line</div>\n";
2062 next LINE
if $in_header;
2064 print format_diff_line
($patch_line);
2066 print "</div>\n" if $patch_found; # class="patch"
2068 print "</div>\n"; # class="patchset"
2071 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2073 sub git_shortlog_body
{
2074 # uses global variable $project
2075 my ($revlist, $from, $to, $refs, $extra) = @_;
2077 $from = 0 unless defined $from;
2078 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2080 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2082 for (my $i = $from; $i <= $to; $i++) {
2083 my $commit = $revlist->[$i];
2084 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2085 my $ref = format_ref_marker
($refs, $commit);
2086 my %co = parse_commit
($commit);
2088 print "<tr class=\"dark\">\n";
2090 print "<tr class=\"light\">\n";
2093 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2094 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2095 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2097 print format_subject_html
($co{'title'}, $co{'title_short'},
2098 href
(action
=>"commit", hash
=>$commit), $ref);
2100 "<td class=\"link\">" .
2101 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2102 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") . " | " .
2103 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2107 if (defined $extra) {
2109 "<td colspan=\"4\">$extra</td>\n" .
2115 sub git_history_body
{
2116 # Warning: assumes constant type (blob or tree) during history
2117 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2119 $from = 0 unless defined $from;
2120 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2122 print "<table class=\"history\" cellspacing=\"0\">\n";
2124 for (my $i = $from; $i <= $to; $i++) {
2125 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2130 my %co = parse_commit
($commit);
2135 my $ref = format_ref_marker
($refs, $commit);
2138 print "<tr class=\"dark\">\n";
2140 print "<tr class=\"light\">\n";
2143 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2144 # shortlog uses chop_str($co{'author_name'}, 10)
2145 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2147 # originally git_history used chop_str($co{'title'}, 50)
2148 print format_subject_html
($co{'title'}, $co{'title_short'},
2149 href
(action
=>"commit", hash
=>$commit), $ref);
2151 "<td class=\"link\">" .
2152 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2153 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2155 if ($ftype eq 'blob') {
2156 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2157 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2158 if (defined $blob_current && defined $blob_parent &&
2159 $blob_current ne $blob_parent) {
2161 $cgi->a({-href
=> href
(action
=>"blobdiff",
2162 hash
=>$blob_current, hash_parent
=>$blob_parent,
2163 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2164 file_name
=>$file_name)},
2171 if (defined $extra) {
2173 "<td colspan=\"4\">$extra</td>\n" .
2180 # uses global variable $project
2181 my ($taglist, $from, $to, $extra) = @_;
2182 $from = 0 unless defined $from;
2183 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2185 print "<table class=\"tags\" cellspacing=\"0\">\n";
2187 for (my $i = $from; $i <= $to; $i++) {
2188 my $entry = $taglist->[$i];
2190 my $comment_lines = $tag{'comment'};
2191 my $comment = shift @$comment_lines;
2193 if (defined $comment) {
2194 $comment_short = chop_str
($comment, 30, 5);
2197 print "<tr class=\"dark\">\n";
2199 print "<tr class=\"light\">\n";
2202 print "<td><i>$tag{'age'}</i></td>\n" .
2204 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2205 -class => "list name"}, esc_html
($tag{'name'})) .
2208 if (defined $comment) {
2209 print format_subject_html
($comment, $comment_short,
2210 href
(action
=>"tag", hash
=>$tag{'id'}));
2213 "<td class=\"selflink\">";
2214 if ($tag{'type'} eq "tag") {
2215 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2220 "<td class=\"link\">" . " | " .
2221 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2222 if ($tag{'reftype'} eq "commit") {
2223 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2224 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2225 } elsif ($tag{'reftype'} eq "blob") {
2226 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2231 if (defined $extra) {
2233 "<td colspan=\"5\">$extra</td>\n" .
2239 sub git_heads_body
{
2240 # uses global variable $project
2241 my ($headlist, $head, $from, $to, $extra) = @_;
2242 $from = 0 unless defined $from;
2243 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2245 print "<table class=\"heads\" cellspacing=\"0\">\n";
2247 for (my $i = $from; $i <= $to; $i++) {
2248 my $entry = $headlist->[$i];
2250 my $curr = $tag{'id'} eq $head;
2252 print "<tr class=\"dark\">\n";
2254 print "<tr class=\"light\">\n";
2257 print "<td><i>$tag{'age'}</i></td>\n" .
2258 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
2259 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2260 -class => "list name"},esc_html
($tag{'name'})) .
2262 "<td class=\"link\">" .
2263 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2264 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2265 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2269 if (defined $extra) {
2271 "<td colspan=\"3\">$extra</td>\n" .
2277 ## ======================================================================
2278 ## ======================================================================
2281 sub git_project_list
{
2282 my $order = $cgi->param('o');
2283 if (defined $order && $order !~ m/project|descr|owner|age/) {
2284 die_error
(undef, "Unknown order parameter");
2287 my @list = git_get_projects_list
();
2290 die_error
(undef, "No projects found");
2292 foreach my $pr (@list) {
2293 my $head = git_get_head_hash
($pr->{'path'});
2294 if (!defined $head) {
2297 $git_dir = "$projectroot/$pr->{'path'}";
2298 my %co = parse_commit
($head);
2302 $pr->{'commit'} = \
%co;
2303 if (!defined $pr->{'descr'}) {
2304 my $descr = git_get_project_description
($pr->{'path'}) || "";
2305 $pr->{'descr'} = chop_str
($descr, 25, 5);
2307 if (!defined $pr->{'owner'}) {
2308 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2310 push @projects, $pr;
2314 if (-f
$home_text) {
2315 print "<div class=\"index_include\">\n";
2316 open (my $fd, $home_text);
2321 print "<table class=\"project_list\">\n" .
2323 $order ||= "project";
2324 if ($order eq "project") {
2325 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2326 print "<th>Project</th>\n";
2329 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2330 -class => "header"}, "Project") .
2333 if ($order eq "descr") {
2334 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2335 print "<th>Description</th>\n";
2338 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2339 -class => "header"}, "Description") .
2342 if ($order eq "owner") {
2343 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2344 print "<th>Owner</th>\n";
2347 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2348 -class => "header"}, "Owner") .
2351 if ($order eq "age") {
2352 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2353 print "<th>Last Change</th>\n";
2356 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2357 -class => "header"}, "Last Change") .
2360 print "<th></th>\n" .
2363 foreach my $pr (@projects) {
2365 print "<tr class=\"dark\">\n";
2367 print "<tr class=\"light\">\n";
2370 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2371 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2372 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2373 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2374 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2375 $pr->{'commit'}{'age_string'} . "</td>\n" .
2376 "<td class=\"link\">" .
2377 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2378 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2379 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2380 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2388 sub git_project_index
{
2389 my @projects = git_get_projects_list
();
2392 -type
=> 'text/plain',
2393 -charset
=> 'utf-8',
2394 -content_disposition
=> 'inline; filename="index.aux"');
2396 foreach my $pr (@projects) {
2397 if (!exists $pr->{'owner'}) {
2398 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2401 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2402 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2403 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2404 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2408 print "$path $owner\n";
2413 my $descr = git_get_project_description
($project) || "none";
2414 my $head = git_get_head_hash
($project);
2415 my %co = parse_commit
($head);
2416 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2418 my $owner = git_get_project_owner
($project);
2420 my ($reflist, $refs) = git_get_refs_list
();
2424 foreach my $ref (@$reflist) {
2425 if ($ref->{'name'} =~ s!^heads/!!) {
2426 push @headlist, $ref;
2428 $ref->{'name'} =~ s!^tags/!!;
2429 push @taglist, $ref;
2434 git_print_page_nav
('summary','', $head);
2436 print "<div class=\"title\"> </div>\n";
2437 print "<table cellspacing=\"0\">\n" .
2438 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2439 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2440 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2441 # use per project git URL list in $projectroot/$project/cloneurl
2442 # or make project git URL from git base URL and project name
2443 my $url_tag = "URL";
2444 my @url_list = git_get_project_url_list
($project);
2445 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2446 foreach my $git_url (@url_list) {
2447 next unless $git_url;
2448 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2453 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2454 git_get_head_hash
($project)
2455 or die_error
(undef, "Open git-rev-list failed");
2456 my @revlist = map { chomp; $_ } <$fd>;
2458 git_print_header_div
('shortlog');
2459 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2460 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2463 git_print_header_div
('tags');
2464 git_tags_body
(\
@taglist, 0, 15,
2465 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2469 git_print_header_div
('heads');
2470 git_heads_body
(\
@headlist, $head, 0, 15,
2471 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2478 my $head = git_get_head_hash
($project);
2480 git_print_page_nav
('','', $head,undef,$head);
2481 my %tag = parse_tag
($hash);
2482 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2483 print "<div class=\"title_text\">\n" .
2484 "<table cellspacing=\"0\">\n" .
2486 "<td>object</td>\n" .
2487 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2488 $tag{'object'}) . "</td>\n" .
2489 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2490 $tag{'type'}) . "</td>\n" .
2492 if (defined($tag{'author'})) {
2493 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2494 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2495 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2496 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2499 print "</table>\n\n" .
2501 print "<div class=\"page_body\">";
2502 my $comment = $tag{'comment'};
2503 foreach my $line (@$comment) {
2504 print esc_html
($line) . "<br/>\n";
2514 my ($have_blame) = gitweb_check_feature
('blame');
2516 die_error
('403 Permission denied', "Permission denied");
2518 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2519 $hash_base ||= git_get_head_hash
($project);
2520 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2521 my %co = parse_commit
($hash_base)
2522 or die_error
(undef, "Reading commit failed");
2523 if (!defined $hash) {
2524 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2525 or die_error
(undef, "Error looking up file");
2527 $ftype = git_get_type
($hash);
2528 if ($ftype !~ "blob") {
2529 die_error
("400 Bad Request", "Object is not a blob");
2531 open ($fd, "-|", git_cmd
(), "blame", '--porcelain', '--',
2532 $file_name, $hash_base)
2533 or die_error
(undef, "Open git-blame failed");
2536 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2539 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2542 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2544 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2545 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2546 git_print_page_path
($file_name, $ftype, $hash_base);
2547 my @rev_color = (qw(light2 dark2));
2548 my $num_colors = scalar(@rev_color);
2549 my $current_color = 0;
2552 <div class="page_body">
2553 <table class="blame">
2554 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2559 last unless defined $_;
2560 my ($full_rev, $lineno, $orig_lineno, $group_size) =
2561 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2562 if (!exists $metainfo{$full_rev}) {
2563 $metainfo{$full_rev} = {};
2565 my $meta = $metainfo{$full_rev};
2568 if (/^(\S+) (.*)$/) {
2573 my $rev = substr($full_rev, 0, 8);
2574 my $author = $meta->{'author'};
2575 my %date = parse_date
($meta->{'author-time'},
2576 $meta->{'author-tz'});
2577 my $date = $date{'iso-tz'};
2579 $current_color = ++$current_color % $num_colors;
2581 print "<tr class=\"$rev_color[$current_color]\">\n";
2583 print "<td class=\"sha1\"";
2584 print " title=\"$author, $date\"";
2585 print " rowspan=\"$group_size\"" if ($group_size > 1);
2587 print $cgi->a({-href
=> href
(action
=>"commit",
2589 file_name
=>$file_name)},
2593 my $blamed = href
(action
=> 'blame',
2594 file_name
=> $meta->{'filename'},
2595 hash_base
=> $full_rev);
2596 print "<td class=\"linenr\">";
2597 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
2599 -class => "linenr" },
2602 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2608 or print "Reading blob failed\n";
2615 my ($have_blame) = gitweb_check_feature
('blame');
2617 die_error
('403 Permission denied', "Permission denied");
2619 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2620 $hash_base ||= git_get_head_hash
($project);
2621 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2622 my %co = parse_commit
($hash_base)
2623 or die_error
(undef, "Reading commit failed");
2624 if (!defined $hash) {
2625 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2626 or die_error
(undef, "Error lookup file");
2628 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2629 or die_error
(undef, "Open git-annotate failed");
2632 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2635 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2638 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2640 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2641 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2642 git_print_page_path
($file_name, 'blob', $hash_base);
2643 print "<div class=\"page_body\">\n";
2645 <table class="blame">
2654 my @line_class = (qw(light dark));
2655 my $line_class_len = scalar (@line_class);
2656 my $line_class_num = $#line_class;
2657 while (my $line = <$fd>) {
2669 $line_class_num = ($line_class_num + 1) % $line_class_len;
2671 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2678 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2681 $short_rev = substr ($long_rev, 0, 8);
2682 $age = time () - $time;
2683 $age_str = age_string
($age);
2684 $age_str =~ s/ / /g;
2685 $age_class = age_class
($age);
2686 $author = esc_html
($author);
2687 $author =~ s/ / /g;
2689 $data = untabify
($data);
2690 $data = esc_html
($data);
2693 <tr class="$line_class[$line_class_num]">
2694 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2695 <td class="$age_class">$age_str</td>
2697 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2698 <td class="pre">$data</td>
2701 } # while (my $line = <$fd>)
2702 print "</table>\n\n";
2704 or print "Reading blob failed.\n";
2710 my $head = git_get_head_hash
($project);
2712 git_print_page_nav
('','', $head,undef,$head);
2713 git_print_header_div
('summary', $project);
2715 my ($taglist) = git_get_refs_list
("tags");
2717 git_tags_body
($taglist);
2723 my $head = git_get_head_hash
($project);
2725 git_print_page_nav
('','', $head,undef,$head);
2726 git_print_header_div
('summary', $project);
2728 my ($headlist) = git_get_refs_list
("heads");
2730 git_heads_body
($headlist, $head);
2735 sub git_blob_plain
{
2738 if (!defined $hash) {
2739 if (defined $file_name) {
2740 my $base = $hash_base || git_get_head_hash
($project);
2741 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2742 or die_error
(undef, "Error lookup file");
2744 die_error
(undef, "No file name defined");
2746 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2747 # blobs defined by non-textual hash id's can be cached
2752 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2753 or die_error
(undef, "Couldn't cat $file_name, $hash");
2755 $type ||= blob_mimetype
($fd, $file_name);
2757 # save as filename, even when no $file_name is given
2758 my $save_as = "$hash";
2759 if (defined $file_name) {
2760 $save_as = $file_name;
2761 } elsif ($type =~ m/^text\//) {
2768 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2770 binmode STDOUT
, ':raw';
2772 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2780 if (!defined $hash) {
2781 if (defined $file_name) {
2782 my $base = $hash_base || git_get_head_hash
($project);
2783 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2784 or die_error
(undef, "Error lookup file");
2786 die_error
(undef, "No file name defined");
2788 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2789 # blobs defined by non-textual hash id's can be cached
2793 my ($have_blame) = gitweb_check_feature
('blame');
2794 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2795 or die_error
(undef, "Couldn't cat $file_name, $hash");
2796 my $mimetype = blob_mimetype
($fd, $file_name);
2797 if ($mimetype !~ m/^text\//) {
2799 return git_blob_plain
($mimetype);
2801 git_header_html
(undef, $expires);
2802 my $formats_nav = '';
2803 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2804 if (defined $file_name) {
2807 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2808 hash
=>$hash, file_name
=>$file_name)},
2813 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2814 hash
=>$hash, file_name
=>$file_name)},
2817 $cgi->a({-href
=> href
(action
=>"blob_plain",
2818 hash
=>$hash, file_name
=>$file_name)},
2821 $cgi->a({-href
=> href
(action
=>"blob",
2822 hash_base
=>"HEAD", file_name
=>$file_name)},
2826 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2828 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2829 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2831 print "<div class=\"page_nav\">\n" .
2832 "<br/><br/></div>\n" .
2833 "<div class=\"title\">$hash</div>\n";
2835 git_print_page_path
($file_name, "blob", $hash_base);
2836 print "<div class=\"page_body\">\n";
2838 while (my $line = <$fd>) {
2841 $line = untabify
($line);
2842 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2843 $nr, $nr, $nr, esc_html
($line);
2846 or print "Reading blob failed.\n";
2852 my $have_snapshot = gitweb_have_snapshot
();
2854 if (!defined $hash_base) {
2855 $hash_base = "HEAD";
2857 if (!defined $hash) {
2858 if (defined $file_name) {
2859 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
2865 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2866 or die_error
(undef, "Open git-ls-tree failed");
2867 my @entries = map { chomp; $_ } <$fd>;
2868 close $fd or die_error
(undef, "Reading tree failed");
2871 my $refs = git_get_references
();
2872 my $ref = format_ref_marker
($refs, $hash_base);
2875 my ($have_blame) = gitweb_check_feature
('blame');
2876 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2878 if (defined $file_name) {
2880 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2881 hash
=>$hash, file_name
=>$file_name)},
2883 $cgi->a({-href
=> href
(action
=>"tree",
2884 hash_base
=>"HEAD", file_name
=>$file_name)},
2887 if ($have_snapshot) {
2888 # FIXME: Should be available when we have no hash base as well.
2890 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2893 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2894 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2897 print "<div class=\"page_nav\">\n";
2898 print "<br/><br/></div>\n";
2899 print "<div class=\"title\">$hash</div>\n";
2901 if (defined $file_name) {
2902 $base = esc_html
("$file_name/");
2904 git_print_page_path
($file_name, 'tree', $hash_base);
2905 print "<div class=\"page_body\">\n";
2906 print "<table cellspacing=\"0\">\n";
2908 foreach my $line (@entries) {
2909 my %t = parse_ls_tree_line
($line, -z
=> 1);
2912 print "<tr class=\"dark\">\n";
2914 print "<tr class=\"light\">\n";
2918 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2922 print "</table>\n" .
2928 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2929 my $have_snapshot = (defined $ctype && defined $suffix);
2930 if (!$have_snapshot) {
2931 die_error
('403 Permission denied', "Permission denied");
2934 if (!defined $hash) {
2935 $hash = git_get_head_hash
($project);
2938 my $filename = basename
($project) . "-$hash.tar.$suffix";
2941 -type
=> 'application/x-tar',
2942 -content_encoding
=> $ctype,
2943 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
2944 -status
=> '200 OK');
2946 my $git = git_cmd_str
();
2947 my $name = $project;
2948 $name =~ s/\047/\047\\\047\047/g;
2950 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
2951 or die_error
(undef, "Execute git-tar-tree failed.");
2952 binmode STDOUT
, ':raw';
2954 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2960 my $head = git_get_head_hash
($project);
2961 if (!defined $hash) {
2964 if (!defined $page) {
2967 my $refs = git_get_references
();
2969 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2970 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2971 or die_error
(undef, "Open git-rev-list failed");
2972 my @revlist = map { chomp; $_ } <$fd>;
2975 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2978 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2981 my %co = parse_commit
($hash);
2983 git_print_header_div
('summary', $project);
2984 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2986 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2987 my $commit = $revlist[$i];
2988 my $ref = format_ref_marker
($refs, $commit);
2989 my %co = parse_commit
($commit);
2991 my %ad = parse_date
($co{'author_epoch'});
2992 git_print_header_div
('commit',
2993 "<span class=\"age\">$co{'age_string'}</span>" .
2994 esc_html
($co{'title'}) . $ref,
2996 print "<div class=\"title_text\">\n" .
2997 "<div class=\"log_link\">\n" .
2998 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3000 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3002 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3005 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3008 print "<div class=\"log_body\">\n";
3009 git_print_simplified_log
($co{'comment'});
3016 my %co = parse_commit
($hash);
3018 die_error
(undef, "Unknown commit object");
3020 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3021 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3023 my $parent = $co{'parent'};
3024 if (!defined $parent) {
3027 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
3028 or die_error
(undef, "Open git-diff-tree failed");
3029 my @difftree = map { chomp; $_ } <$fd>;
3030 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3032 # non-textual hash id's can be cached
3034 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3037 my $refs = git_get_references
();
3038 my $ref = format_ref_marker
($refs, $co{'id'});
3040 my $have_snapshot = gitweb_have_snapshot
();
3043 if (defined $file_name && defined $co{'parent'}) {
3045 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3048 git_header_html
(undef, $expires);
3049 git_print_page_nav
('commit', defined $co{'parent'} ? '' : 'commitdiff',
3050 $hash, $co{'tree'}, $hash,
3051 join (' | ', @views_nav));
3053 if (defined $co{'parent'}) {
3054 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3056 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3058 print "<div class=\"title_text\">\n" .
3059 "<table cellspacing=\"0\">\n";
3060 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3062 "<td></td><td> $ad{'rfc2822'}";
3063 if ($ad{'hour_local'} < 6) {
3064 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3065 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3067 printf(" (%02d:%02d %s)",
3068 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3072 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3073 print "<tr><td></td><td> $cd{'rfc2822'}" .
3074 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3076 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3079 "<td class=\"sha1\">" .
3080 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3081 class => "list"}, $co{'tree'}) .
3083 "<td class=\"link\">" .
3084 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3086 if ($have_snapshot) {
3088 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3092 my $parents = $co{'parents'};
3093 foreach my $par (@$parents) {
3096 "<td class=\"sha1\">" .
3097 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3098 class => "list"}, $par) .
3100 "<td class=\"link\">" .
3101 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3103 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3110 print "<div class=\"page_body\">\n";
3111 git_print_log
($co{'comment'});
3114 git_difftree_body
(\
@difftree, $hash, $parent);
3120 my $format = shift || 'html';
3127 # preparing $fd and %diffinfo for git_patchset_body
3129 if (defined $hash_base && defined $hash_parent_base) {
3130 if (defined $file_name) {
3132 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3134 or die_error
(undef, "Open git-diff-tree failed");
3135 @difftree = map { chomp; $_ } <$fd>;
3137 or die_error
(undef, "Reading git-diff-tree failed");
3139 or die_error
('404 Not Found', "Blob diff not found");
3141 } elsif (defined $hash &&
3142 $hash =~ /[0-9a-fA-F]{40}/) {
3143 # try to find filename from $hash
3145 # read filtered raw output
3146 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3147 or die_error
(undef, "Open git-diff-tree failed");
3149 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3151 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3152 map { chomp; $_ } <$fd>;
3154 or die_error
(undef, "Reading git-diff-tree failed");
3156 or die_error
('404 Not Found', "Blob diff not found");
3159 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3162 if (@difftree > 1) {
3163 die_error
('404 Not Found', "Ambiguous blob diff specification");
3166 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3167 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3168 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3170 $hash_parent ||= $diffinfo{'from_id'};
3171 $hash ||= $diffinfo{'to_id'};
3173 # non-textual hash id's can be cached
3174 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3175 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3180 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3181 '-p', $hash_parent_base, $hash_base,
3183 or die_error
(undef, "Open git-diff-tree failed");
3186 # old/legacy style URI
3187 if (!%diffinfo && # if new style URI failed
3188 defined $hash && defined $hash_parent) {
3189 # fake git-diff-tree raw output
3190 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3191 $diffinfo{'from_id'} = $hash_parent;
3192 $diffinfo{'to_id'} = $hash;
3193 if (defined $file_name) {
3194 if (defined $file_parent) {
3195 $diffinfo{'status'} = '2';
3196 $diffinfo{'from_file'} = $file_parent;
3197 $diffinfo{'to_file'} = $file_name;
3198 } else { # assume not renamed
3199 $diffinfo{'status'} = '1';
3200 $diffinfo{'from_file'} = $file_name;
3201 $diffinfo{'to_file'} = $file_name;
3203 } else { # no filename given
3204 $diffinfo{'status'} = '2';
3205 $diffinfo{'from_file'} = $hash_parent;
3206 $diffinfo{'to_file'} = $hash;
3209 # non-textual hash id's can be cached
3210 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3211 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3216 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3217 or die_error
(undef, "Open git-diff failed");
3219 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3224 if ($format eq 'html') {
3226 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3227 hash
=>$hash, hash_parent
=>$hash_parent,
3228 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3229 file_name
=>$file_name, file_parent
=>$file_parent)},
3231 git_header_html
(undef, $expires);
3232 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3233 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3234 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3236 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3237 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3239 if (defined $file_name) {
3240 git_print_page_path
($file_name, "blob", $hash_base);
3242 print "<div class=\"page_path\"></div>\n";
3245 } elsif ($format eq 'plain') {
3247 -type
=> 'text/plain',
3248 -charset
=> 'utf-8',
3249 -expires
=> $expires,
3250 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3252 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3255 die_error
(undef, "Unknown blobdiff format");
3259 if ($format eq 'html') {
3260 print "<div class=\"page_body\">\n";
3262 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3265 print "</div>\n"; # class="page_body"
3269 while (my $line = <$fd>) {
3270 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3271 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3275 last if $line =~ m!^\+\+\+!;
3283 sub git_blobdiff_plain
{
3284 git_blobdiff
('plain');
3287 sub git_commitdiff
{
3288 my $format = shift || 'html';
3289 my %co = parse_commit
($hash);
3291 die_error
(undef, "Unknown commit object");
3293 if (!defined $hash_parent) {
3294 $hash_parent = $co{'parent'} || '--root';
3300 if ($format eq 'html') {
3301 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3302 "--patch-with-raw", "--full-index", $hash_parent, $hash
3303 or die_error
(undef, "Open git-diff-tree failed");
3305 while (chomp(my $line = <$fd>)) {
3306 # empty line ends raw part of diff-tree output
3308 push @difftree, $line;
3311 } elsif ($format eq 'plain') {
3312 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3313 '-p', $hash_parent, $hash
3314 or die_error
(undef, "Open git-diff-tree failed");
3317 die_error
(undef, "Unknown commitdiff format");
3320 # non-textual hash id's can be cached
3322 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3326 # write commit message
3327 if ($format eq 'html') {
3328 my $refs = git_get_references
();
3329 my $ref = format_ref_marker
($refs, $co{'id'});
3331 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3332 hash
=>$hash, hash_parent
=>$hash_parent)},
3335 git_header_html
(undef, $expires);
3336 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3337 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3338 git_print_authorship
(\
%co);
3339 print "<div class=\"page_body\">\n";
3340 print "<div class=\"log\">\n";
3341 git_print_simplified_log
($co{'comment'}, 1); # skip title
3342 print "</div>\n"; # class="log"
3344 } elsif ($format eq 'plain') {
3345 my $refs = git_get_references
("tags");
3346 my $tagname = git_get_rev_name_tags
($hash);
3347 my $filename = basename
($project) . "-$hash.patch";
3350 -type
=> 'text/plain',
3351 -charset
=> 'utf-8',
3352 -expires
=> $expires,
3353 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3354 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3357 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3358 Subject: $co{'title'}
3360 print "X-Git-Tag: $tagname\n" if $tagname;
3361 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3363 foreach my $line (@{$co{'comment'}}) {
3370 if ($format eq 'html') {
3371 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3374 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3376 print "</div>\n"; # class="page_body"
3379 } elsif ($format eq 'plain') {
3383 or print "Reading git-diff-tree failed\n";
3387 sub git_commitdiff_plain
{
3388 git_commitdiff
('plain');
3392 if (!defined $hash_base) {
3393 $hash_base = git_get_head_hash
($project);
3395 if (!defined $page) {
3399 my %co = parse_commit
($hash_base);
3401 die_error
(undef, "Unknown commit object");
3404 my $refs = git_get_references
();
3405 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3407 if (!defined $hash && defined $file_name) {
3408 $hash = git_get_hash_by_path
($hash_base, $file_name);
3410 if (defined $hash) {
3411 $ftype = git_get_type
($hash);
3415 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3416 or die_error
(undef, "Open git-rev-list-failed");
3417 my @revlist = map { chomp; $_ } <$fd>;
3419 or die_error
(undef, "Reading git-rev-list failed");
3421 my $paging_nav = '';
3424 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3425 file_name
=>$file_name)},
3427 $paging_nav .= " ⋅ " .
3428 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3429 file_name
=>$file_name, page
=>$page-1),
3430 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3432 $paging_nav .= "first";
3433 $paging_nav .= " ⋅ prev";
3435 if ($#revlist >= (100 * ($page+1)-1)) {
3436 $paging_nav .= " ⋅ " .
3437 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3438 file_name
=>$file_name, page
=>$page+1),
3439 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3441 $paging_nav .= " ⋅ next";
3444 if ($#revlist >= (100 * ($page+1)-1)) {
3446 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3447 file_name
=>$file_name, page
=>$page+1),
3448 -title
=> "Alt-n"}, "next");
3452 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3453 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3454 git_print_page_path
($file_name, $ftype, $hash_base);
3456 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3457 $refs, $hash_base, $ftype, $next_link);
3463 if (!defined $searchtext) {
3464 die_error
(undef, "Text field empty");
3466 if (!defined $hash) {
3467 $hash = git_get_head_hash
($project);
3469 my %co = parse_commit
($hash);
3471 die_error
(undef, "Unknown commit object");
3474 my $commit_search = 1;
3475 my $author_search = 0;
3476 my $committer_search = 0;
3477 my $pickaxe_search = 0;
3478 if ($searchtext =~ s/^author\\://i) {
3480 } elsif ($searchtext =~ s/^committer\\://i) {
3481 $committer_search = 1;
3482 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3484 $pickaxe_search = 1;
3486 # pickaxe may take all resources of your box and run for several minutes
3487 # with every query - so decide by yourself how public you make this feature
3488 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3489 if (!$have_pickaxe) {
3490 die_error
('403 Permission denied', "Permission denied");
3494 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3495 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3497 print "<table cellspacing=\"0\">\n";
3499 if ($commit_search) {
3501 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3502 while (my $commit_text = <$fd>) {
3503 if (!grep m/$searchtext/i, $commit_text) {
3506 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3509 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3512 my @commit_lines = split "\n", $commit_text;
3513 my %co = parse_commit
(undef, \
@commit_lines);
3518 print "<tr class=\"dark\">\n";
3520 print "<tr class=\"light\">\n";
3523 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3524 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3526 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3527 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3528 my $comment = $co{'comment'};
3529 foreach my $line (@$comment) {
3530 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3531 my $lead = esc_html
($1) || "";
3532 $lead = chop_str
($lead, 30, 10);
3533 my $match = esc_html
($2) || "";
3534 my $trail = esc_html
($3) || "";
3535 $trail = chop_str
($trail, 30, 10);
3536 my $text = "$lead<span class=\"match\">$match</span>$trail";
3537 print chop_str
($text, 80, 5) . "<br/>\n";
3541 "<td class=\"link\">" .
3542 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3544 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3551 if ($pickaxe_search) {
3553 my $git_command = git_cmd_str
();
3554 open my $fd, "-|", "$git_command rev-list $hash | " .
3555 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3558 while (my $line = <$fd>) {
3559 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3562 $set{'from_id'} = $3;
3564 $set{'id'} = $set{'to_id'};
3565 if ($set{'id'} =~ m/0{40}/) {
3566 $set{'id'} = $set{'from_id'};
3568 if ($set{'id'} =~ m/0{40}/) {
3572 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3575 print "<tr class=\"dark\">\n";
3577 print "<tr class=\"light\">\n";
3580 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3581 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3583 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3584 -class => "list subject"},
3585 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3586 while (my $setref = shift @files) {
3588 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3589 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3591 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3595 "<td class=\"link\">" .
3596 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3598 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3602 %co = parse_commit
($1);
3612 my $head = git_get_head_hash
($project);
3613 if (!defined $hash) {
3616 if (!defined $page) {
3619 my $refs = git_get_references
();
3621 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3622 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3623 or die_error
(undef, "Open git-rev-list failed");
3624 my @revlist = map { chomp; $_ } <$fd>;
3627 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3629 if ($#revlist >= (100 * ($page+1)-1)) {
3631 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3632 -title
=> "Alt-n"}, "next");
3637 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3638 git_print_header_div
('summary', $project);
3640 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3645 ## ......................................................................
3646 ## feeds (RSS, OPML)
3649 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3650 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3651 or die_error
(undef, "Open git-rev-list failed");
3652 my @revlist = map { chomp; $_ } <$fd>;
3653 close $fd or die_error
(undef, "Reading git-rev-list failed");
3654 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3656 <?xml version="1.0" encoding="utf-8"?>
3657 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3659 <title>$project $my_uri $my_url</title>
3660 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3661 <description>$project log</description>
3662 <language>en</language>
3665 for (my $i = 0; $i <= $#revlist; $i++) {
3666 my $commit = $revlist[$i];
3667 my %co = parse_commit
($commit);
3668 # we read 150, we always show 30 and the ones more recent than 48 hours
3669 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3672 my %cd = parse_date
($co{'committer_epoch'});
3673 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3674 $co{'parent'}, $co{'id'}
3676 my @difftree = map { chomp; $_ } <$fd>;
3681 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3683 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3684 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3685 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3686 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3687 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3688 "<content:encoded>" .
3690 my $comment = $co{'comment'};
3691 foreach my $line (@$comment) {
3692 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3693 print "$line<br/>\n";
3696 foreach my $line (@difftree) {
3697 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3700 my $file = esc_html
(unquote
($7));
3701 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3702 print "$file<br/>\n";
3705 "</content:encoded>\n" .
3708 print "</channel></rss>";
3712 my @list = git_get_projects_list
();
3714 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3716 <?xml version="1.0" encoding="utf-8"?>
3717 <opml version="1.0">
3719 <title>$site_name Git OPML Export</title>
3722 <outline text="git RSS feeds">
3725 foreach my $pr (@list) {
3727 my $head = git_get_head_hash
($proj{'path'});
3728 if (!defined $head) {
3731 $git_dir = "$projectroot/$proj{'path'}";
3732 my %co = parse_commit
($head);
3737 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3738 my $rss = "$my_url?p=$proj{'path'};a=rss";
3739 my $html = "$my_url?p=$proj{'path'};a=summary";
3740 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";