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 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
497 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
500 # quote unsafe chars, but keep the slash, even when it's not
501 # correct, but quoted slashes look too horrible in bookmarks
504 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
510 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
513 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
519 # replace invalid utf8 character with SUBSTITUTION sequence
522 $str = to_utf8
($str);
523 $str = escapeHTML
($str);
524 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
525 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
529 # git may return quoted and escaped filenames
532 if ($str =~ m/^"(.*)"$/) {
534 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
539 # escape tabs (convert tabs to spaces)
543 while ((my $pos = index($line, "\t")) != -1) {
544 if (my $count = (8 - ($pos % 8))) {
545 my $spaces = ' ' x
$count;
546 $line =~ s/\t/$spaces/;
553 sub project_in_list
{
555 my @list = git_get_projects_list
();
556 return @list && scalar(grep { $_->{'path'} eq $project } @list);
559 ## ----------------------------------------------------------------------
560 ## HTML aware string manipulation
565 my $add_len = shift || 10;
567 # allow only $len chars, but don't cut a word if it would fit in $add_len
568 # if it doesn't fit, cut it if it's still longer than the dots we would add
569 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
572 if (length($tail) > 4) {
574 $body =~ s/&[^;]*$//; # remove chopped character entities
579 ## ----------------------------------------------------------------------
580 ## functions returning short strings
582 # CSS class for given age value (in seconds)
586 if ($age < 60*60*2) {
588 } elsif ($age < 60*60*24*2) {
595 # convert age in seconds to "nn units ago" string
600 if ($age > 60*60*24*365*2) {
601 $age_str = (int $age/60/60/24/365);
602 $age_str .= " years ago";
603 } elsif ($age > 60*60*24*(365/12)*2) {
604 $age_str = int $age/60/60/24/(365/12);
605 $age_str .= " months ago";
606 } elsif ($age > 60*60*24*7*2) {
607 $age_str = int $age/60/60/24/7;
608 $age_str .= " weeks ago";
609 } elsif ($age > 60*60*24*2) {
610 $age_str = int $age/60/60/24;
611 $age_str .= " days ago";
612 } elsif ($age > 60*60*2) {
613 $age_str = int $age/60/60;
614 $age_str .= " hours ago";
615 } elsif ($age > 60*2) {
616 $age_str = int $age/60;
617 $age_str .= " min ago";
620 $age_str .= " sec ago";
622 $age_str .= " right now";
627 # convert file mode in octal to symbolic file mode string
629 my $mode = oct shift;
631 if (S_ISDIR
($mode & S_IFMT
)) {
633 } elsif (S_ISLNK
($mode)) {
635 } elsif (S_ISREG
($mode)) {
636 # git cares only about the executable bit
637 if ($mode & S_IXUSR
) {
647 # convert file mode in octal to file type string
651 if ($mode !~ m/^[0-7]+$/) {
657 if (S_ISDIR
($mode & S_IFMT
)) {
659 } elsif (S_ISLNK
($mode)) {
661 } elsif (S_ISREG
($mode)) {
668 ## ----------------------------------------------------------------------
669 ## functions returning short HTML fragments, or transforming HTML fragments
670 ## which don't beling to other sections
672 # format line of commit message or tag comment
673 sub format_log_line_html
{
676 $line = esc_html
($line);
677 $line =~ s/ / /g;
678 if ($line =~ m/([0-9a-fA-F]{40})/) {
680 if (git_get_type
($hash_text) eq "commit") {
682 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
683 -class => "text"}, $hash_text);
684 $line =~ s/$hash_text/$link/;
690 # format marker of refs pointing to given object
691 sub format_ref_marker
{
692 my ($refs, $id) = @_;
695 if (defined $refs->{$id}) {
696 foreach my $ref (@{$refs->{$id}}) {
697 my ($type, $name) = qw();
698 # e.g. tags/v2.6.11 or heads/next
699 if ($ref =~ m!^(.*?)s?/(.*)$!) {
707 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
712 return ' <span class="refs">'. $markers . '</span>';
718 # format, perhaps shortened and with markers, title line
719 sub format_subject_html
{
720 my ($long, $short, $href, $extra) = @_;
721 $extra = '' unless defined($extra);
723 if (length($short) < length($long)) {
724 return $cgi->a({-href
=> $href, -class => "list subject",
725 -title
=> to_utf8
($long)},
726 esc_html
($short) . $extra);
728 return $cgi->a({-href
=> $href, -class => "list subject"},
729 esc_html
($long) . $extra);
733 sub format_diff_line
{
735 my $char = substr($line, 0, 1);
741 $diff_class = " add";
742 } elsif ($char eq "-") {
743 $diff_class = " rem";
744 } elsif ($char eq "@") {
745 $diff_class = " chunk_header";
746 } elsif ($char eq "\\") {
747 $diff_class = " incomplete";
749 $line = untabify
($line);
750 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
753 ## ----------------------------------------------------------------------
754 ## git utility subroutines, invoking git commands
756 # returns path to the core git executable and the --git-dir parameter as list
758 return $GIT, '--git-dir='.$git_dir;
761 # returns path to the core git executable and the --git-dir parameter as string
763 return join(' ', git_cmd
());
766 # get HEAD ref of given project as hash
767 sub git_get_head_hash
{
769 my $o_git_dir = $git_dir;
771 $git_dir = "$projectroot/$project";
772 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
775 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
779 if (defined $o_git_dir) {
780 $git_dir = $o_git_dir;
785 # get type of given object
789 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
796 sub git_get_project_config
{
797 my ($key, $type) = @_;
799 return unless ($key);
800 $key =~ s/^gitweb\.//;
801 return if ($key =~ m/\W/);
803 my @x = (git_cmd
(), 'repo-config');
804 if (defined $type) { push @x, $type; }
806 push @x, "gitweb.$key";
812 # get hash of given path at given ref
813 sub git_get_hash_by_path
{
815 my $path = shift || return undef;
820 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
821 or die_error
(undef, "Open git-ls-tree failed");
823 close $fd or return undef;
825 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
826 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
827 if (defined $type && $type ne $2) {
834 ## ......................................................................
835 ## git utility functions, directly accessing git repository
837 sub git_get_project_description
{
840 open my $fd, "$projectroot/$path/description" or return undef;
847 sub git_get_project_url_list
{
850 open my $fd, "$projectroot/$path/cloneurl" or return;
851 my @git_project_url_list = map { chomp; $_ } <$fd>;
854 return wantarray ? @git_project_url_list : \
@git_project_url_list;
857 sub git_get_projects_list
{
860 if (-d
$projects_list) {
861 # search in directory
862 my $dir = $projects_list;
863 my $pfxlen = length("$dir");
866 follow_fast
=> 1, # follow symbolic links
867 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
869 # skip project-list toplevel, if we get it.
870 return if (m!^[/.]$!);
871 # only directories can be git repositories
872 return unless (-d
$_);
874 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
875 # we check related file in $projectroot
876 if (check_export_ok
("$projectroot/$subdir")) {
877 push @list, { path
=> $subdir };
878 $File::Find
::prune
= 1;
883 } elsif (-f
$projects_list) {
884 # read from file(url-encoded):
885 # 'git%2Fgit.git Linus+Torvalds'
886 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
887 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
888 open my ($fd), $projects_list or return;
889 while (my $line = <$fd>) {
891 my ($path, $owner) = split ' ', $line;
892 $path = unescape
($path);
893 $owner = unescape
($owner);
894 if (!defined $path) {
897 if (check_export_ok
("$projectroot/$path")) {
900 owner
=> to_utf8
($owner),
907 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
911 sub git_get_project_owner
{
915 return undef unless $project;
917 # read from file (url-encoded):
918 # 'git%2Fgit.git Linus+Torvalds'
919 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
920 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
921 if (-f
$projects_list) {
922 open (my $fd , $projects_list);
923 while (my $line = <$fd>) {
925 my ($pr, $ow) = split ' ', $line;
928 if ($pr eq $project) {
929 $owner = to_utf8
($ow);
935 if (!defined $owner) {
936 $owner = get_file_owner
("$projectroot/$project");
942 sub git_get_references
{
943 my $type = shift || "";
945 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
946 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
947 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
950 while (my $line = <$fd>) {
952 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
953 if (defined $refs{$1}) {
954 push @{$refs{$1}}, $2;
964 sub git_get_rev_name_tags
{
965 my $hash = shift || return undef;
967 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
969 my $name_rev = <$fd>;
972 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
975 # catches also '$hash undefined' output
980 ## ----------------------------------------------------------------------
981 ## parse to hash functions
985 my $tz = shift || "-0000";
988 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
989 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
990 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
991 $date{'hour'} = $hour;
992 $date{'minute'} = $min;
993 $date{'mday'} = $mday;
994 $date{'day'} = $days[$wday];
995 $date{'month'} = $months[$mon];
996 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
997 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
998 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
999 $mday, $months[$mon], $hour ,$min;
1001 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1002 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1003 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1004 $date{'hour_local'} = $hour;
1005 $date{'minute_local'} = $min;
1006 $date{'tz_local'} = $tz;
1007 $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
1008 1900+$year, $mon+1, $mday,
1009 $hour, $min, $sec, $tz);
1018 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1019 $tag{'id'} = $tag_id;
1020 while (my $line = <$fd>) {
1022 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1023 $tag{'object'} = $1;
1024 } elsif ($line =~ m/^type (.+)$/) {
1026 } elsif ($line =~ m/^tag (.+)$/) {
1028 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1029 $tag{'author'} = $1;
1032 } elsif ($line =~ m/--BEGIN/) {
1033 push @comment, $line;
1035 } elsif ($line eq "") {
1039 push @comment, <$fd>;
1040 $tag{'comment'} = \
@comment;
1041 close $fd or return;
1042 if (!defined $tag{'name'}) {
1049 my $commit_id = shift;
1050 my $commit_text = shift;
1055 if (defined $commit_text) {
1056 @commit_lines = @$commit_text;
1059 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1061 @commit_lines = split '\n', <$fd>;
1062 close $fd or return;
1066 my $header = shift @commit_lines;
1067 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1070 ($co{'id'}, my @parents) = split ' ', $header;
1071 $co{'parents'} = \
@parents;
1072 $co{'parent'} = $parents[0];
1073 while (my $line = shift @commit_lines) {
1074 last if $line eq "\n";
1075 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1077 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1079 $co{'author_epoch'} = $2;
1080 $co{'author_tz'} = $3;
1081 if ($co{'author'} =~ m/^([^<]+) </) {
1082 $co{'author_name'} = $1;
1084 $co{'author_name'} = $co{'author'};
1086 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1087 $co{'committer'} = $1;
1088 $co{'committer_epoch'} = $2;
1089 $co{'committer_tz'} = $3;
1090 $co{'committer_name'} = $co{'committer'};
1091 $co{'committer_name'} =~ s/ <.*//;
1094 if (!defined $co{'tree'}) {
1098 foreach my $title (@commit_lines) {
1101 $co{'title'} = chop_str
($title, 80, 5);
1102 # remove leading stuff of merges to make the interesting part visible
1103 if (length($title) > 50) {
1104 $title =~ s/^Automatic //;
1105 $title =~ s/^merge (of|with) /Merge ... /i;
1106 if (length($title) > 50) {
1107 $title =~ s/(http|rsync):\/\///;
1109 if (length($title) > 50) {
1110 $title =~ s/(master|www|rsync)\.//;
1112 if (length($title) > 50) {
1113 $title =~ s/kernel.org:?//;
1115 if (length($title) > 50) {
1116 $title =~ s/\/pub\/scm//;
1119 $co{'title_short'} = chop_str
($title, 50, 5);
1123 # remove added spaces
1124 foreach my $line (@commit_lines) {
1127 $co{'comment'} = \
@commit_lines;
1129 my $age = time - $co{'committer_epoch'};
1131 $co{'age_string'} = age_string
($age);
1132 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1133 if ($age > 60*60*24*7*2) {
1134 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1135 $co{'age_string_age'} = $co{'age_string'};
1137 $co{'age_string_date'} = $co{'age_string'};
1138 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1143 # parse ref from ref_file, given by ref_id, with given type
1145 my $ref_file = shift;
1147 my $type = shift || git_get_type
($ref_id);
1150 $ref_item{'type'} = $type;
1151 $ref_item{'id'} = $ref_id;
1152 $ref_item{'epoch'} = 0;
1153 $ref_item{'age'} = "unknown";
1154 if ($type eq "tag") {
1155 my %tag = parse_tag
($ref_id);
1156 $ref_item{'comment'} = $tag{'comment'};
1157 if ($tag{'type'} eq "commit") {
1158 my %co = parse_commit
($tag{'object'});
1159 $ref_item{'epoch'} = $co{'committer_epoch'};
1160 $ref_item{'age'} = $co{'age_string'};
1161 } elsif (defined($tag{'epoch'})) {
1162 my $age = time - $tag{'epoch'};
1163 $ref_item{'epoch'} = $tag{'epoch'};
1164 $ref_item{'age'} = age_string
($age);
1166 $ref_item{'reftype'} = $tag{'type'};
1167 $ref_item{'name'} = $tag{'name'};
1168 $ref_item{'refid'} = $tag{'object'};
1169 } elsif ($type eq "commit"){
1170 my %co = parse_commit
($ref_id);
1171 $ref_item{'reftype'} = "commit";
1172 $ref_item{'name'} = $ref_file;
1173 $ref_item{'title'} = $co{'title'};
1174 $ref_item{'refid'} = $ref_id;
1175 $ref_item{'epoch'} = $co{'committer_epoch'};
1176 $ref_item{'age'} = $co{'age_string'};
1178 $ref_item{'reftype'} = $type;
1179 $ref_item{'name'} = $ref_file;
1180 $ref_item{'refid'} = $ref_id;
1186 # parse line of git-diff-tree "raw" output
1187 sub parse_difftree_raw_line
{
1191 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1192 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1193 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1194 $res{'from_mode'} = $1;
1195 $res{'to_mode'} = $2;
1196 $res{'from_id'} = $3;
1198 $res{'status'} = $5;
1199 $res{'similarity'} = $6;
1200 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1201 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1203 $res{'file'} = unquote
($7);
1206 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1207 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1208 $res{'commit'} = $1;
1211 return wantarray ? %res : \
%res;
1214 # parse line of git-ls-tree output
1215 sub parse_ls_tree_line
($;%) {
1220 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1221 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1229 $res{'name'} = unquote
($4);
1232 return wantarray ? %res : \
%res;
1235 ## ......................................................................
1236 ## parse to array of hashes functions
1238 sub git_get_refs_list
{
1239 my $type = shift || "";
1244 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1246 while (my $line = <$fd>) {
1248 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1249 if (defined $refs{$1}) {
1250 push @{$refs{$1}}, $2;
1255 if (! $4) { # unpeeled, direct reference
1256 push @refs, { hash
=> $1, name
=> $3 }; # without type
1257 } elsif ($3 eq $refs[-1]{'name'}) {
1258 # most likely a tag is followed by its peeled
1259 # (deref) one, and when that happens we know the
1260 # previous one was of type 'tag'.
1261 $refs[-1]{'type'} = "tag";
1267 foreach my $ref (@refs) {
1268 my $ref_file = $ref->{'name'};
1269 my $ref_id = $ref->{'hash'};
1271 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1272 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1274 push @reflist, \
%ref_item;
1277 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1278 return (\
@reflist, \
%refs);
1281 ## ----------------------------------------------------------------------
1282 ## filesystem-related functions
1284 sub get_file_owner
{
1287 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1288 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1289 if (!defined $gcos) {
1293 $owner =~ s/[,;].*$//;
1294 return to_utf8
($owner);
1297 ## ......................................................................
1298 ## mimetype related functions
1300 sub mimetype_guess_file
{
1301 my $filename = shift;
1302 my $mimemap = shift;
1303 -r
$mimemap or return undef;
1306 open(MIME
, $mimemap) or return undef;
1308 next if m/^#/; # skip comments
1309 my ($mime, $exts) = split(/\t+/);
1310 if (defined $exts) {
1311 my @exts = split(/\s+/, $exts);
1312 foreach my $ext (@exts) {
1313 $mimemap{$ext} = $mime;
1319 $filename =~ /\.([^.]*)$/;
1320 return $mimemap{$1};
1323 sub mimetype_guess
{
1324 my $filename = shift;
1326 $filename =~ /\./ or return undef;
1328 if ($mimetypes_file) {
1329 my $file = $mimetypes_file;
1330 if ($file !~ m!^/!) { # if it is relative path
1331 # it is relative to project
1332 $file = "$projectroot/$project/$file";
1334 $mime = mimetype_guess_file
($filename, $file);
1336 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1342 my $filename = shift;
1345 my $mime = mimetype_guess
($filename);
1346 $mime and return $mime;
1350 return $default_blob_plain_mimetype unless $fd;
1353 return 'text/plain' .
1354 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1355 } elsif (! $filename) {
1356 return 'application/octet-stream';
1357 } elsif ($filename =~ m/\.png$/i) {
1359 } elsif ($filename =~ m/\.gif$/i) {
1361 } elsif ($filename =~ m/\.jpe?g$/i) {
1362 return 'image/jpeg';
1364 return 'application/octet-stream';
1368 ## ======================================================================
1369 ## functions printing HTML: header, footer, error page
1371 sub git_header_html
{
1372 my $status = shift || "200 OK";
1373 my $expires = shift;
1375 my $title = "$site_name git";
1376 if (defined $project) {
1377 $title .= " - $project";
1378 if (defined $action) {
1379 $title .= "/$action";
1380 if (defined $file_name) {
1381 $title .= " - " . esc_html
($file_name);
1382 if ($action eq "tree" && $file_name !~ m
|/$|) {
1389 # require explicit support from the UA if we are to send the page as
1390 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1391 # we have to do this because MSIE sometimes globs '*/*', pretending to
1392 # support xhtml+xml but choking when it gets what it asked for.
1393 if (defined $cgi->http('HTTP_ACCEPT') &&
1394 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1395 $cgi->Accept('application/xhtml+xml') != 0) {
1396 $content_type = 'application/xhtml+xml';
1398 $content_type = 'text/html';
1400 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1401 -status
=> $status, -expires
=> $expires);
1403 <?xml version="1.0" encoding="utf-8"?>
1404 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1405 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1406 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1407 <!-- git core binaries version $git_version -->
1409 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1410 <meta name="generator" content="gitweb/$version git/$git_version"/>
1411 <meta name="robots" content="index, nofollow"/>
1412 <title>$title</title>
1414 # print out each stylesheet that exist
1415 if (defined $stylesheet) {
1416 #provides backwards capability for those people who define style sheet in a config file
1417 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1419 foreach my $stylesheet (@stylesheets) {
1420 next unless $stylesheet;
1421 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1424 if (defined $project) {
1425 printf('<link rel="alternate" title="%s log" '.
1426 'href="%s" type="application/rss+xml"/>'."\n",
1427 esc_param
($project), href
(action
=>"rss"));
1429 printf('<link rel="alternate" title="%s projects list" '.
1430 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1431 $site_name, href
(project
=>undef, action
=>"project_index"));
1432 printf('<link rel="alternate" title="%s projects logs" '.
1433 'href="%s" type="text/x-opml"/>'."\n",
1434 $site_name, href
(project
=>undef, action
=>"opml"));
1436 if (defined $favicon) {
1437 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1443 if (-f
$site_header) {
1444 open (my $fd, $site_header);
1449 print "<div class=\"page_header\">\n" .
1450 "<a href=\"" . esc_html
($githelp_url) .
1451 "\" title=\"" . esc_html
($githelp_label) .
1453 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1455 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1456 if (defined $project) {
1457 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1458 if (defined $action) {
1462 if (!defined $searchtext) {
1466 if (defined $hash_base) {
1467 $search_hash = $hash_base;
1468 } elsif (defined $hash) {
1469 $search_hash = $hash;
1471 $search_hash = "HEAD";
1473 $cgi->param("a", "search");
1474 $cgi->param("h", $search_hash);
1475 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1476 "<div class=\"search\">\n" .
1477 $cgi->hidden(-name
=> "p") . "\n" .
1478 $cgi->hidden(-name
=> "a") . "\n" .
1479 $cgi->hidden(-name
=> "h") . "\n" .
1480 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1482 $cgi->end_form() . "\n";
1487 sub git_footer_html
{
1488 print "<div class=\"page_footer\">\n";
1489 if (defined $project) {
1490 my $descr = git_get_project_description
($project);
1491 if (defined $descr) {
1492 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1494 print $cgi->a({-href
=> href
(action
=>"rss"),
1495 -class => "rss_logo"}, "RSS") . "\n";
1497 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1498 -class => "rss_logo"}, "OPML") . " ";
1499 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1500 -class => "rss_logo"}, "TXT") . "\n";
1504 if (-f
$site_footer) {
1505 open (my $fd, $site_footer);
1515 my $status = shift || "403 Forbidden";
1516 my $error = shift || "Malformed query, file missing or permission denied";
1518 git_header_html
($status);
1520 <div class="page_body">
1530 ## ----------------------------------------------------------------------
1531 ## functions printing or outputting HTML: navigation
1533 sub git_print_page_nav
{
1534 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1535 $extra = '' if !defined $extra; # pager or formats
1537 my @navs = qw(summary shortlog log commit commitdiff tree);
1539 @navs = grep { $_ ne $suppress } @navs;
1542 my %arg = map { $_ => {action
=>$_} } @navs;
1543 if (defined $head) {
1544 for (qw(commit commitdiff)) {
1545 $arg{$_}{hash
} = $head;
1547 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1548 for (qw(shortlog log)) {
1549 $arg{$_}{hash
} = $head;
1553 $arg{tree
}{hash
} = $treehead if defined $treehead;
1554 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1556 print "<div class=\"page_nav\">\n" .
1558 map { $_ eq $current ?
1559 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1561 print "<br/>\n$extra<br/>\n" .
1565 sub format_paging_nav
{
1566 my ($action, $hash, $head, $page, $nrevs) = @_;
1570 if ($hash ne $head || $page) {
1571 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1573 $paging_nav .= "HEAD";
1577 $paging_nav .= " ⋅ " .
1578 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1579 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1581 $paging_nav .= " ⋅ prev";
1584 if ($nrevs >= (100 * ($page+1)-1)) {
1585 $paging_nav .= " ⋅ " .
1586 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1587 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1589 $paging_nav .= " ⋅ next";
1595 ## ......................................................................
1596 ## functions printing or outputting HTML: div
1598 sub git_print_header_div
{
1599 my ($action, $title, $hash, $hash_base) = @_;
1602 $args{action
} = $action;
1603 $args{hash
} = $hash if $hash;
1604 $args{hash_base
} = $hash_base if $hash_base;
1606 print "<div class=\"header\">\n" .
1607 $cgi->a({-href
=> href
(%args), -class => "title"},
1608 $title ? $title : $action) .
1612 #sub git_print_authorship (\%) {
1613 sub git_print_authorship
{
1616 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1617 print "<div class=\"author_date\">" .
1618 esc_html
($co->{'author_name'}) .
1620 if ($ad{'hour_local'} < 6) {
1621 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1622 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1624 printf(" (%02d:%02d %s)",
1625 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1630 sub git_print_page_path
{
1635 if (!defined $name) {
1636 print "<div class=\"page_path\">/</div>\n";
1638 my @dirname = split '/', $name;
1639 my $basename = pop @dirname;
1642 print "<div class=\"page_path\">";
1643 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1644 -title
=> 'tree root'}, "[$project]");
1646 foreach my $dir (@dirname) {
1647 $fullname .= ($fullname ? '/' : '') . $dir;
1648 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1650 -title
=> $fullname}, esc_html
($dir));
1653 if (defined $type && $type eq 'blob') {
1654 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1656 -title
=> $name}, esc_html
($basename));
1657 } elsif (defined $type && $type eq 'tree') {
1658 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1660 -title
=> $name}, esc_html
($basename));
1662 print esc_html
($basename);
1664 print "<br/></div>\n";
1668 # sub git_print_log (\@;%) {
1669 sub git_print_log
($;%) {
1673 if ($opts{'-remove_title'}) {
1674 # remove title, i.e. first line of log
1677 # remove leading empty lines
1678 while (defined $log->[0] && $log->[0] eq "") {
1685 foreach my $line (@$log) {
1686 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1689 if (! $opts{'-remove_signoff'}) {
1690 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1693 # remove signoff lines
1700 # print only one empty line
1701 # do not print empty line after signoff
1703 next if ($empty || $signoff);
1709 print format_log_line_html
($line) . "<br/>\n";
1712 if ($opts{'-final_empty_line'}) {
1713 # end with single empty line
1714 print "<br/>\n" unless $empty;
1718 sub git_print_simplified_log
{
1720 my $remove_title = shift;
1723 -final_empty_line
=> 1,
1724 -remove_title
=> $remove_title);
1727 # print tree entry (row of git_tree), but without encompassing <tr> element
1728 sub git_print_tree_entry
{
1729 my ($t, $basedir, $hash_base, $have_blame) = @_;
1732 $base_key{hash_base
} = $hash_base if defined $hash_base;
1734 # The format of a table row is: mode list link. Where mode is
1735 # the mode of the entry, list is the name of the entry, an href,
1736 # and link is the action links of the entry.
1738 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1739 if ($t->{'type'} eq "blob") {
1740 print "<td class=\"list\">" .
1741 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1742 file_name
=>"$basedir$t->{'name'}", %base_key),
1743 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1744 print "<td class=\"link\">";
1746 print $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1747 file_name
=>"$basedir$t->{'name'}", %base_key)},
1750 if (defined $hash_base) {
1754 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1755 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1759 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1760 file_name
=>"$basedir$t->{'name'}")},
1764 } elsif ($t->{'type'} eq "tree") {
1765 print "<td class=\"list\">";
1766 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1767 file_name
=>"$basedir$t->{'name'}", %base_key)},
1768 esc_html
($t->{'name'}));
1770 print "<td class=\"link\">";
1771 if (defined $hash_base) {
1772 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1773 file_name
=>"$basedir$t->{'name'}")},
1780 ## ......................................................................
1781 ## functions printing large fragments of HTML
1783 sub git_difftree_body
{
1784 my ($difftree, $hash, $parent) = @_;
1786 print "<div class=\"list_head\">\n";
1787 if ($#{$difftree} > 10) {
1788 print(($#{$difftree} + 1) . " files changed:\n");
1792 print "<table class=\"diff_tree\">\n";
1795 foreach my $line (@{$difftree}) {
1796 my %diff = parse_difftree_raw_line
($line);
1799 print "<tr class=\"dark\">\n";
1801 print "<tr class=\"light\">\n";
1805 my ($to_mode_oct, $to_mode_str, $to_file_type);
1806 my ($from_mode_oct, $from_mode_str, $from_file_type);
1807 if ($diff{'to_mode'} ne ('0' x
6)) {
1808 $to_mode_oct = oct $diff{'to_mode'};
1809 if (S_ISREG
($to_mode_oct)) { # only for regular file
1810 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1812 $to_file_type = file_type
($diff{'to_mode'});
1814 if ($diff{'from_mode'} ne ('0' x
6)) {
1815 $from_mode_oct = oct $diff{'from_mode'};
1816 if (S_ISREG
($to_mode_oct)) { # only for regular file
1817 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1819 $from_file_type = file_type
($diff{'from_mode'});
1822 if ($diff{'status'} eq "A") { # created
1823 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1824 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1825 $mode_chng .= "]</span>";
1827 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1828 hash_base
=>$hash, file_name
=>$diff{'file'}),
1829 -class => "list"}, esc_html
($diff{'file'}));
1831 print "<td>$mode_chng</td>\n";
1832 print "<td class=\"link\">";
1833 if ($action eq 'commitdiff') {
1836 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1840 } elsif ($diff{'status'} eq "D") { # deleted
1841 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1843 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1844 hash_base
=>$parent, file_name
=>$diff{'file'}),
1845 -class => "list"}, esc_html
($diff{'file'}));
1847 print "<td>$mode_chng</td>\n";
1848 print "<td class=\"link\">";
1849 if ($action eq 'commitdiff') {
1852 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1855 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1856 file_name
=>$diff{'file'})},
1858 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1859 file_name
=>$diff{'file'})},
1863 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1864 my $mode_chnge = "";
1865 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1866 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1867 if ($from_file_type != $to_file_type) {
1868 $mode_chnge .= " from $from_file_type to $to_file_type";
1870 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1871 if ($from_mode_str && $to_mode_str) {
1872 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1873 } elsif ($to_mode_str) {
1874 $mode_chnge .= " mode: $to_mode_str";
1877 $mode_chnge .= "]</span>\n";
1880 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1881 hash_base
=>$hash, file_name
=>$diff{'file'}),
1882 -class => "list"}, esc_html
($diff{'file'}));
1884 print "<td>$mode_chnge</td>\n";
1885 print "<td class=\"link\">";
1886 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1887 if ($action eq 'commitdiff') {
1890 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1892 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1893 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1894 hash_base
=>$hash, hash_parent_base
=>$parent,
1895 file_name
=>$diff{'file'})},
1900 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1901 file_name
=>$diff{'file'})},
1903 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1904 file_name
=>$diff{'file'})},
1908 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1909 my %status_name = ('R' => 'moved', 'C' => 'copied');
1910 my $nstatus = $status_name{$diff{'status'}};
1912 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1913 # mode also for directories, so we cannot use $to_mode_str
1914 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1917 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1918 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1919 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1920 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1921 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1922 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1923 -class => "list"}, esc_html
($diff{'from_file'})) .
1924 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1925 "<td class=\"link\">";
1926 if ($diff{'to_id'} ne $diff{'from_id'}) {
1927 if ($action eq 'commitdiff') {
1930 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1932 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1933 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1934 hash_base
=>$hash, hash_parent_base
=>$parent,
1935 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1940 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1941 file_name
=>$diff{'from_file'})},
1943 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1944 file_name
=>$diff{'from_file'})},
1948 } # we should not encounter Unmerged (U) or Unknown (X) status
1954 sub git_patchset_body
{
1955 my ($fd, $difftree, $hash, $hash_parent) = @_;
1959 my $patch_found = 0;
1962 print "<div class=\"patchset\">\n";
1965 while (my $patch_line = <$fd>) {
1968 if ($patch_line =~ m/^diff /) { # "git diff" header
1969 # beginning of patch (in patchset)
1971 # close previous patch
1972 print "</div>\n"; # class="patch"
1974 # first patch in patchset
1977 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1979 if (ref($difftree->[$patch_idx]) eq "HASH") {
1980 $diffinfo = $difftree->[$patch_idx];
1982 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1986 # for now, no extended header, hence we skip empty patches
1987 # companion to next LINE if $in_header;
1988 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1993 if ($diffinfo->{'status'} eq "A") { # added
1994 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1995 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1996 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1997 $diffinfo->{'to_id'}) . "(new)" .
1998 "</div>\n"; # class="diff_info"
2000 } elsif ($diffinfo->{'status'} eq "D") { # deleted
2001 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
2002 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2003 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2004 $diffinfo->{'from_id'}) . "(deleted)" .
2005 "</div>\n"; # class="diff_info"
2007 } elsif ($diffinfo->{'status'} eq "R" || # renamed
2008 $diffinfo->{'status'} eq "C" || # copied
2009 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
2010 print "<div class=\"diff_info\">" .
2011 file_type
($diffinfo->{'from_mode'}) . ":" .
2012 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2013 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
2014 $diffinfo->{'from_id'}) .
2016 file_type
($diffinfo->{'to_mode'}) . ":" .
2017 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2018 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
2019 $diffinfo->{'to_id'});
2020 print "</div>\n"; # class="diff_info"
2022 } else { # modified, mode changed, ...
2023 print "<div class=\"diff_info\">" .
2024 file_type
($diffinfo->{'from_mode'}) . ":" .
2025 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2026 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2027 $diffinfo->{'from_id'}) .
2029 file_type
($diffinfo->{'to_mode'}) . ":" .
2030 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2031 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2032 $diffinfo->{'to_id'});
2033 print "</div>\n"; # class="diff_info"
2036 #print "<div class=\"diff extended_header\">\n";
2039 } # start of patch in patchset
2042 if ($in_header && $patch_line =~ m/^---/) {
2043 #print "</div>\n"; # class="diff extended_header"
2046 my $file = $diffinfo->{'from_file'};
2047 $file ||= $diffinfo->{'file'};
2048 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2049 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2050 -class => "list"}, esc_html
($file));
2051 $patch_line =~ s
|a
/.*$|a/$file|g
;
2052 print "<div class=\"diff from_file\">$patch_line</div>\n";
2054 $patch_line = <$fd>;
2057 #$patch_line =~ m/^+++/;
2058 $file = $diffinfo->{'to_file'};
2059 $file ||= $diffinfo->{'file'};
2060 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2061 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2062 -class => "list"}, esc_html
($file));
2063 $patch_line =~ s
|b
/.*|b/$file|g
;
2064 print "<div class=\"diff to_file\">$patch_line</div>\n";
2068 next LINE
if $in_header;
2070 print format_diff_line
($patch_line);
2072 print "</div>\n" if $patch_found; # class="patch"
2074 print "</div>\n"; # class="patchset"
2077 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2079 sub git_shortlog_body
{
2080 # uses global variable $project
2081 my ($revlist, $from, $to, $refs, $extra) = @_;
2083 $from = 0 unless defined $from;
2084 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2086 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2088 for (my $i = $from; $i <= $to; $i++) {
2089 my $commit = $revlist->[$i];
2090 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2091 my $ref = format_ref_marker
($refs, $commit);
2092 my %co = parse_commit
($commit);
2094 print "<tr class=\"dark\">\n";
2096 print "<tr class=\"light\">\n";
2099 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2100 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2101 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2103 print format_subject_html
($co{'title'}, $co{'title_short'},
2104 href
(action
=>"commit", hash
=>$commit), $ref);
2106 "<td class=\"link\">" .
2107 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2108 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") . " | " .
2109 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2113 if (defined $extra) {
2115 "<td colspan=\"4\">$extra</td>\n" .
2121 sub git_history_body
{
2122 # Warning: assumes constant type (blob or tree) during history
2123 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2125 $from = 0 unless defined $from;
2126 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2128 print "<table class=\"history\" cellspacing=\"0\">\n";
2130 for (my $i = $from; $i <= $to; $i++) {
2131 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2136 my %co = parse_commit
($commit);
2141 my $ref = format_ref_marker
($refs, $commit);
2144 print "<tr class=\"dark\">\n";
2146 print "<tr class=\"light\">\n";
2149 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2150 # shortlog uses chop_str($co{'author_name'}, 10)
2151 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2153 # originally git_history used chop_str($co{'title'}, 50)
2154 print format_subject_html
($co{'title'}, $co{'title_short'},
2155 href
(action
=>"commit", hash
=>$commit), $ref);
2157 "<td class=\"link\">" .
2158 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2159 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2161 if ($ftype eq 'blob') {
2162 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2163 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2164 if (defined $blob_current && defined $blob_parent &&
2165 $blob_current ne $blob_parent) {
2167 $cgi->a({-href
=> href
(action
=>"blobdiff",
2168 hash
=>$blob_current, hash_parent
=>$blob_parent,
2169 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2170 file_name
=>$file_name)},
2177 if (defined $extra) {
2179 "<td colspan=\"4\">$extra</td>\n" .
2186 # uses global variable $project
2187 my ($taglist, $from, $to, $extra) = @_;
2188 $from = 0 unless defined $from;
2189 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2191 print "<table class=\"tags\" cellspacing=\"0\">\n";
2193 for (my $i = $from; $i <= $to; $i++) {
2194 my $entry = $taglist->[$i];
2196 my $comment_lines = $tag{'comment'};
2197 my $comment = shift @$comment_lines;
2199 if (defined $comment) {
2200 $comment_short = chop_str
($comment, 30, 5);
2203 print "<tr class=\"dark\">\n";
2205 print "<tr class=\"light\">\n";
2208 print "<td><i>$tag{'age'}</i></td>\n" .
2210 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2211 -class => "list name"}, esc_html
($tag{'name'})) .
2214 if (defined $comment) {
2215 print format_subject_html
($comment, $comment_short,
2216 href
(action
=>"tag", hash
=>$tag{'id'}));
2219 "<td class=\"selflink\">";
2220 if ($tag{'type'} eq "tag") {
2221 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2226 "<td class=\"link\">" . " | " .
2227 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2228 if ($tag{'reftype'} eq "commit") {
2229 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2230 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2231 } elsif ($tag{'reftype'} eq "blob") {
2232 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2237 if (defined $extra) {
2239 "<td colspan=\"5\">$extra</td>\n" .
2245 sub git_heads_body
{
2246 # uses global variable $project
2247 my ($headlist, $head, $from, $to, $extra) = @_;
2248 $from = 0 unless defined $from;
2249 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2251 print "<table class=\"heads\" cellspacing=\"0\">\n";
2253 for (my $i = $from; $i <= $to; $i++) {
2254 my $entry = $headlist->[$i];
2256 my $curr = $tag{'id'} eq $head;
2258 print "<tr class=\"dark\">\n";
2260 print "<tr class=\"light\">\n";
2263 print "<td><i>$tag{'age'}</i></td>\n" .
2264 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
2265 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2266 -class => "list name"},esc_html
($tag{'name'})) .
2268 "<td class=\"link\">" .
2269 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2270 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2271 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2275 if (defined $extra) {
2277 "<td colspan=\"3\">$extra</td>\n" .
2283 ## ======================================================================
2284 ## ======================================================================
2287 sub git_project_list
{
2288 my $order = $cgi->param('o');
2289 if (defined $order && $order !~ m/project|descr|owner|age/) {
2290 die_error
(undef, "Unknown order parameter");
2293 my @list = git_get_projects_list
();
2296 die_error
(undef, "No projects found");
2298 foreach my $pr (@list) {
2299 my $head = git_get_head_hash
($pr->{'path'});
2300 if (!defined $head) {
2303 $git_dir = "$projectroot/$pr->{'path'}";
2304 my %co = parse_commit
($head);
2308 $pr->{'commit'} = \
%co;
2309 if (!defined $pr->{'descr'}) {
2310 my $descr = git_get_project_description
($pr->{'path'}) || "";
2311 $pr->{'descr'} = chop_str
($descr, 25, 5);
2313 if (!defined $pr->{'owner'}) {
2314 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2316 push @projects, $pr;
2320 if (-f
$home_text) {
2321 print "<div class=\"index_include\">\n";
2322 open (my $fd, $home_text);
2327 print "<table class=\"project_list\">\n" .
2329 $order ||= "project";
2330 if ($order eq "project") {
2331 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2332 print "<th>Project</th>\n";
2335 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2336 -class => "header"}, "Project") .
2339 if ($order eq "descr") {
2340 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2341 print "<th>Description</th>\n";
2344 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2345 -class => "header"}, "Description") .
2348 if ($order eq "owner") {
2349 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2350 print "<th>Owner</th>\n";
2353 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2354 -class => "header"}, "Owner") .
2357 if ($order eq "age") {
2358 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2359 print "<th>Last Change</th>\n";
2362 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2363 -class => "header"}, "Last Change") .
2366 print "<th></th>\n" .
2369 foreach my $pr (@projects) {
2371 print "<tr class=\"dark\">\n";
2373 print "<tr class=\"light\">\n";
2376 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2377 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2378 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2379 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2380 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2381 $pr->{'commit'}{'age_string'} . "</td>\n" .
2382 "<td class=\"link\">" .
2383 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2384 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2385 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2386 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2394 sub git_project_index
{
2395 my @projects = git_get_projects_list
();
2398 -type
=> 'text/plain',
2399 -charset
=> 'utf-8',
2400 -content_disposition
=> 'inline; filename="index.aux"');
2402 foreach my $pr (@projects) {
2403 if (!exists $pr->{'owner'}) {
2404 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2407 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2408 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2409 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2410 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2414 print "$path $owner\n";
2419 my $descr = git_get_project_description
($project) || "none";
2420 my $head = git_get_head_hash
($project);
2421 my %co = parse_commit
($head);
2422 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2424 my $owner = git_get_project_owner
($project);
2426 my ($reflist, $refs) = git_get_refs_list
();
2430 foreach my $ref (@$reflist) {
2431 if ($ref->{'name'} =~ s!^heads/!!) {
2432 push @headlist, $ref;
2434 $ref->{'name'} =~ s!^tags/!!;
2435 push @taglist, $ref;
2440 git_print_page_nav
('summary','', $head);
2442 print "<div class=\"title\"> </div>\n";
2443 print "<table cellspacing=\"0\">\n" .
2444 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2445 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2446 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2447 # use per project git URL list in $projectroot/$project/cloneurl
2448 # or make project git URL from git base URL and project name
2449 my $url_tag = "URL";
2450 my @url_list = git_get_project_url_list
($project);
2451 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2452 foreach my $git_url (@url_list) {
2453 next unless $git_url;
2454 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2459 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2460 git_get_head_hash
($project)
2461 or die_error
(undef, "Open git-rev-list failed");
2462 my @revlist = map { chomp; $_ } <$fd>;
2464 git_print_header_div
('shortlog');
2465 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2466 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2469 git_print_header_div
('tags');
2470 git_tags_body
(\
@taglist, 0, 15,
2471 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2475 git_print_header_div
('heads');
2476 git_heads_body
(\
@headlist, $head, 0, 15,
2477 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2484 my $head = git_get_head_hash
($project);
2486 git_print_page_nav
('','', $head,undef,$head);
2487 my %tag = parse_tag
($hash);
2488 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2489 print "<div class=\"title_text\">\n" .
2490 "<table cellspacing=\"0\">\n" .
2492 "<td>object</td>\n" .
2493 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2494 $tag{'object'}) . "</td>\n" .
2495 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2496 $tag{'type'}) . "</td>\n" .
2498 if (defined($tag{'author'})) {
2499 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2500 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2501 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2502 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2505 print "</table>\n\n" .
2507 print "<div class=\"page_body\">";
2508 my $comment = $tag{'comment'};
2509 foreach my $line (@$comment) {
2510 print esc_html
($line) . "<br/>\n";
2520 my ($have_blame) = gitweb_check_feature
('blame');
2522 die_error
('403 Permission denied', "Permission denied");
2524 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2525 $hash_base ||= git_get_head_hash
($project);
2526 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2527 my %co = parse_commit
($hash_base)
2528 or die_error
(undef, "Reading commit failed");
2529 if (!defined $hash) {
2530 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2531 or die_error
(undef, "Error looking up file");
2533 $ftype = git_get_type
($hash);
2534 if ($ftype !~ "blob") {
2535 die_error
("400 Bad Request", "Object is not a blob");
2537 open ($fd, "-|", git_cmd
(), "blame", '--porcelain', '--',
2538 $file_name, $hash_base)
2539 or die_error
(undef, "Open git-blame failed");
2542 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2545 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2548 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2550 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2551 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2552 git_print_page_path
($file_name, $ftype, $hash_base);
2553 my @rev_color = (qw(light2 dark2));
2554 my $num_colors = scalar(@rev_color);
2555 my $current_color = 0;
2558 <div class="page_body">
2559 <table class="blame">
2560 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2565 last unless defined $_;
2566 my ($full_rev, $lineno, $orig_lineno, $group_size) =
2567 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2568 if (!exists $metainfo{$full_rev}) {
2569 $metainfo{$full_rev} = {};
2571 my $meta = $metainfo{$full_rev};
2574 if (/^(\S+) (.*)$/) {
2579 my $rev = substr($full_rev, 0, 8);
2580 my $author = $meta->{'author'};
2581 my %date = parse_date
($meta->{'author-time'},
2582 $meta->{'author-tz'});
2583 my $date = $date{'iso-tz'};
2585 $current_color = ++$current_color % $num_colors;
2587 print "<tr class=\"$rev_color[$current_color]\">\n";
2589 print "<td class=\"sha1\"";
2590 print " title=\"$author, $date\"";
2591 print " rowspan=\"$group_size\"" if ($group_size > 1);
2593 print $cgi->a({-href
=> href
(action
=>"commit",
2595 file_name
=>$file_name)},
2599 my $blamed = href
(action
=> 'blame',
2600 file_name
=> $meta->{'filename'},
2601 hash_base
=> $full_rev);
2602 print "<td class=\"linenr\">";
2603 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
2605 -class => "linenr" },
2608 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2614 or print "Reading blob failed\n";
2621 my ($have_blame) = gitweb_check_feature
('blame');
2623 die_error
('403 Permission denied', "Permission denied");
2625 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2626 $hash_base ||= git_get_head_hash
($project);
2627 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2628 my %co = parse_commit
($hash_base)
2629 or die_error
(undef, "Reading commit failed");
2630 if (!defined $hash) {
2631 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2632 or die_error
(undef, "Error lookup file");
2634 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2635 or die_error
(undef, "Open git-annotate failed");
2638 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2641 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2644 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2646 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2647 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2648 git_print_page_path
($file_name, 'blob', $hash_base);
2649 print "<div class=\"page_body\">\n";
2651 <table class="blame">
2660 my @line_class = (qw(light dark));
2661 my $line_class_len = scalar (@line_class);
2662 my $line_class_num = $#line_class;
2663 while (my $line = <$fd>) {
2675 $line_class_num = ($line_class_num + 1) % $line_class_len;
2677 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2684 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2687 $short_rev = substr ($long_rev, 0, 8);
2688 $age = time () - $time;
2689 $age_str = age_string
($age);
2690 $age_str =~ s/ / /g;
2691 $age_class = age_class
($age);
2692 $author = esc_html
($author);
2693 $author =~ s/ / /g;
2695 $data = untabify
($data);
2696 $data = esc_html
($data);
2699 <tr class="$line_class[$line_class_num]">
2700 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2701 <td class="$age_class">$age_str</td>
2703 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2704 <td class="pre">$data</td>
2707 } # while (my $line = <$fd>)
2708 print "</table>\n\n";
2710 or print "Reading blob failed.\n";
2716 my $head = git_get_head_hash
($project);
2718 git_print_page_nav
('','', $head,undef,$head);
2719 git_print_header_div
('summary', $project);
2721 my ($taglist) = git_get_refs_list
("tags");
2723 git_tags_body
($taglist);
2729 my $head = git_get_head_hash
($project);
2731 git_print_page_nav
('','', $head,undef,$head);
2732 git_print_header_div
('summary', $project);
2734 my ($headlist) = git_get_refs_list
("heads");
2736 git_heads_body
($headlist, $head);
2741 sub git_blob_plain
{
2744 if (!defined $hash) {
2745 if (defined $file_name) {
2746 my $base = $hash_base || git_get_head_hash
($project);
2747 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2748 or die_error
(undef, "Error lookup file");
2750 die_error
(undef, "No file name defined");
2752 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2753 # blobs defined by non-textual hash id's can be cached
2758 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2759 or die_error
(undef, "Couldn't cat $file_name, $hash");
2761 $type ||= blob_mimetype
($fd, $file_name);
2763 # save as filename, even when no $file_name is given
2764 my $save_as = "$hash";
2765 if (defined $file_name) {
2766 $save_as = $file_name;
2767 } elsif ($type =~ m/^text\//) {
2774 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2776 binmode STDOUT
, ':raw';
2778 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2786 if (!defined $hash) {
2787 if (defined $file_name) {
2788 my $base = $hash_base || git_get_head_hash
($project);
2789 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2790 or die_error
(undef, "Error lookup file");
2792 die_error
(undef, "No file name defined");
2794 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2795 # blobs defined by non-textual hash id's can be cached
2799 my ($have_blame) = gitweb_check_feature
('blame');
2800 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2801 or die_error
(undef, "Couldn't cat $file_name, $hash");
2802 my $mimetype = blob_mimetype
($fd, $file_name);
2803 if ($mimetype !~ m/^text\//) {
2805 return git_blob_plain
($mimetype);
2807 git_header_html
(undef, $expires);
2808 my $formats_nav = '';
2809 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2810 if (defined $file_name) {
2813 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2814 hash
=>$hash, file_name
=>$file_name)},
2819 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2820 hash
=>$hash, file_name
=>$file_name)},
2823 $cgi->a({-href
=> href
(action
=>"blob_plain",
2824 hash
=>$hash, file_name
=>$file_name)},
2827 $cgi->a({-href
=> href
(action
=>"blob",
2828 hash_base
=>"HEAD", file_name
=>$file_name)},
2832 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2834 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2835 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2837 print "<div class=\"page_nav\">\n" .
2838 "<br/><br/></div>\n" .
2839 "<div class=\"title\">$hash</div>\n";
2841 git_print_page_path
($file_name, "blob", $hash_base);
2842 print "<div class=\"page_body\">\n";
2844 while (my $line = <$fd>) {
2847 $line = untabify
($line);
2848 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2849 $nr, $nr, $nr, esc_html
($line);
2852 or print "Reading blob failed.\n";
2858 my $have_snapshot = gitweb_have_snapshot
();
2860 if (!defined $hash_base) {
2861 $hash_base = "HEAD";
2863 if (!defined $hash) {
2864 if (defined $file_name) {
2865 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
2871 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2872 or die_error
(undef, "Open git-ls-tree failed");
2873 my @entries = map { chomp; $_ } <$fd>;
2874 close $fd or die_error
(undef, "Reading tree failed");
2877 my $refs = git_get_references
();
2878 my $ref = format_ref_marker
($refs, $hash_base);
2881 my ($have_blame) = gitweb_check_feature
('blame');
2882 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2884 if (defined $file_name) {
2886 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2887 hash
=>$hash, file_name
=>$file_name)},
2889 $cgi->a({-href
=> href
(action
=>"tree",
2890 hash_base
=>"HEAD", file_name
=>$file_name)},
2893 if ($have_snapshot) {
2894 # FIXME: Should be available when we have no hash base as well.
2896 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2899 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2900 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2903 print "<div class=\"page_nav\">\n";
2904 print "<br/><br/></div>\n";
2905 print "<div class=\"title\">$hash</div>\n";
2907 if (defined $file_name) {
2908 $base = esc_html
("$file_name/");
2910 git_print_page_path
($file_name, 'tree', $hash_base);
2911 print "<div class=\"page_body\">\n";
2912 print "<table cellspacing=\"0\">\n";
2914 foreach my $line (@entries) {
2915 my %t = parse_ls_tree_line
($line, -z
=> 1);
2918 print "<tr class=\"dark\">\n";
2920 print "<tr class=\"light\">\n";
2924 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2928 print "</table>\n" .
2934 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2935 my $have_snapshot = (defined $ctype && defined $suffix);
2936 if (!$have_snapshot) {
2937 die_error
('403 Permission denied', "Permission denied");
2940 if (!defined $hash) {
2941 $hash = git_get_head_hash
($project);
2944 my $filename = basename
($project) . "-$hash.tar.$suffix";
2947 -type
=> 'application/x-tar',
2948 -content_encoding
=> $ctype,
2949 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
2950 -status
=> '200 OK');
2952 my $git = git_cmd_str
();
2953 my $name = $project;
2954 $name =~ s/\047/\047\\\047\047/g;
2956 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
2957 or die_error
(undef, "Execute git-tar-tree failed.");
2958 binmode STDOUT
, ':raw';
2960 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2966 my $head = git_get_head_hash
($project);
2967 if (!defined $hash) {
2970 if (!defined $page) {
2973 my $refs = git_get_references
();
2975 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2976 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2977 or die_error
(undef, "Open git-rev-list failed");
2978 my @revlist = map { chomp; $_ } <$fd>;
2981 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2984 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2987 my %co = parse_commit
($hash);
2989 git_print_header_div
('summary', $project);
2990 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2992 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2993 my $commit = $revlist[$i];
2994 my $ref = format_ref_marker
($refs, $commit);
2995 my %co = parse_commit
($commit);
2997 my %ad = parse_date
($co{'author_epoch'});
2998 git_print_header_div
('commit',
2999 "<span class=\"age\">$co{'age_string'}</span>" .
3000 esc_html
($co{'title'}) . $ref,
3002 print "<div class=\"title_text\">\n" .
3003 "<div class=\"log_link\">\n" .
3004 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3006 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3008 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3011 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3014 print "<div class=\"log_body\">\n";
3015 git_print_simplified_log
($co{'comment'});
3022 my %co = parse_commit
($hash);
3024 die_error
(undef, "Unknown commit object");
3026 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3027 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3029 my $parent = $co{'parent'};
3030 if (!defined $parent) {
3033 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
3034 or die_error
(undef, "Open git-diff-tree failed");
3035 my @difftree = map { chomp; $_ } <$fd>;
3036 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3038 # non-textual hash id's can be cached
3040 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3043 my $refs = git_get_references
();
3044 my $ref = format_ref_marker
($refs, $co{'id'});
3046 my $have_snapshot = gitweb_have_snapshot
();
3049 if (defined $file_name && defined $co{'parent'}) {
3051 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3054 git_header_html
(undef, $expires);
3055 git_print_page_nav
('commit', defined $co{'parent'} ? '' : 'commitdiff',
3056 $hash, $co{'tree'}, $hash,
3057 join (' | ', @views_nav));
3059 if (defined $co{'parent'}) {
3060 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3062 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3064 print "<div class=\"title_text\">\n" .
3065 "<table cellspacing=\"0\">\n";
3066 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3068 "<td></td><td> $ad{'rfc2822'}";
3069 if ($ad{'hour_local'} < 6) {
3070 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3071 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3073 printf(" (%02d:%02d %s)",
3074 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3078 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3079 print "<tr><td></td><td> $cd{'rfc2822'}" .
3080 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3082 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3085 "<td class=\"sha1\">" .
3086 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3087 class => "list"}, $co{'tree'}) .
3089 "<td class=\"link\">" .
3090 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3092 if ($have_snapshot) {
3094 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3098 my $parents = $co{'parents'};
3099 foreach my $par (@$parents) {
3102 "<td class=\"sha1\">" .
3103 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3104 class => "list"}, $par) .
3106 "<td class=\"link\">" .
3107 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3109 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3116 print "<div class=\"page_body\">\n";
3117 git_print_log
($co{'comment'});
3120 git_difftree_body
(\
@difftree, $hash, $parent);
3126 my $format = shift || 'html';
3133 # preparing $fd and %diffinfo for git_patchset_body
3135 if (defined $hash_base && defined $hash_parent_base) {
3136 if (defined $file_name) {
3138 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3140 or die_error
(undef, "Open git-diff-tree failed");
3141 @difftree = map { chomp; $_ } <$fd>;
3143 or die_error
(undef, "Reading git-diff-tree failed");
3145 or die_error
('404 Not Found', "Blob diff not found");
3147 } elsif (defined $hash &&
3148 $hash =~ /[0-9a-fA-F]{40}/) {
3149 # try to find filename from $hash
3151 # read filtered raw output
3152 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3153 or die_error
(undef, "Open git-diff-tree failed");
3155 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3157 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3158 map { chomp; $_ } <$fd>;
3160 or die_error
(undef, "Reading git-diff-tree failed");
3162 or die_error
('404 Not Found', "Blob diff not found");
3165 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3168 if (@difftree > 1) {
3169 die_error
('404 Not Found', "Ambiguous blob diff specification");
3172 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3173 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3174 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3176 $hash_parent ||= $diffinfo{'from_id'};
3177 $hash ||= $diffinfo{'to_id'};
3179 # non-textual hash id's can be cached
3180 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3181 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3186 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3187 '-p', $hash_parent_base, $hash_base,
3189 or die_error
(undef, "Open git-diff-tree failed");
3192 # old/legacy style URI
3193 if (!%diffinfo && # if new style URI failed
3194 defined $hash && defined $hash_parent) {
3195 # fake git-diff-tree raw output
3196 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3197 $diffinfo{'from_id'} = $hash_parent;
3198 $diffinfo{'to_id'} = $hash;
3199 if (defined $file_name) {
3200 if (defined $file_parent) {
3201 $diffinfo{'status'} = '2';
3202 $diffinfo{'from_file'} = $file_parent;
3203 $diffinfo{'to_file'} = $file_name;
3204 } else { # assume not renamed
3205 $diffinfo{'status'} = '1';
3206 $diffinfo{'from_file'} = $file_name;
3207 $diffinfo{'to_file'} = $file_name;
3209 } else { # no filename given
3210 $diffinfo{'status'} = '2';
3211 $diffinfo{'from_file'} = $hash_parent;
3212 $diffinfo{'to_file'} = $hash;
3215 # non-textual hash id's can be cached
3216 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3217 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3222 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3223 or die_error
(undef, "Open git-diff failed");
3225 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3230 if ($format eq 'html') {
3232 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3233 hash
=>$hash, hash_parent
=>$hash_parent,
3234 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3235 file_name
=>$file_name, file_parent
=>$file_parent)},
3237 git_header_html
(undef, $expires);
3238 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3239 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3240 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3242 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3243 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3245 if (defined $file_name) {
3246 git_print_page_path
($file_name, "blob", $hash_base);
3248 print "<div class=\"page_path\"></div>\n";
3251 } elsif ($format eq 'plain') {
3253 -type
=> 'text/plain',
3254 -charset
=> 'utf-8',
3255 -expires
=> $expires,
3256 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3258 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3261 die_error
(undef, "Unknown blobdiff format");
3265 if ($format eq 'html') {
3266 print "<div class=\"page_body\">\n";
3268 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3271 print "</div>\n"; # class="page_body"
3275 while (my $line = <$fd>) {
3276 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3277 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3281 last if $line =~ m!^\+\+\+!;
3289 sub git_blobdiff_plain
{
3290 git_blobdiff
('plain');
3293 sub git_commitdiff
{
3294 my $format = shift || 'html';
3295 my %co = parse_commit
($hash);
3297 die_error
(undef, "Unknown commit object");
3299 if (!defined $hash_parent) {
3300 $hash_parent = $co{'parent'} || '--root';
3306 if ($format eq 'html') {
3307 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3308 "--patch-with-raw", "--full-index", $hash_parent, $hash
3309 or die_error
(undef, "Open git-diff-tree failed");
3311 while (chomp(my $line = <$fd>)) {
3312 # empty line ends raw part of diff-tree output
3314 push @difftree, $line;
3317 } elsif ($format eq 'plain') {
3318 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3319 '-p', $hash_parent, $hash
3320 or die_error
(undef, "Open git-diff-tree failed");
3323 die_error
(undef, "Unknown commitdiff format");
3326 # non-textual hash id's can be cached
3328 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3332 # write commit message
3333 if ($format eq 'html') {
3334 my $refs = git_get_references
();
3335 my $ref = format_ref_marker
($refs, $co{'id'});
3337 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3338 hash
=>$hash, hash_parent
=>$hash_parent)},
3341 git_header_html
(undef, $expires);
3342 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3343 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3344 git_print_authorship
(\
%co);
3345 print "<div class=\"page_body\">\n";
3346 print "<div class=\"log\">\n";
3347 git_print_simplified_log
($co{'comment'}, 1); # skip title
3348 print "</div>\n"; # class="log"
3350 } elsif ($format eq 'plain') {
3351 my $refs = git_get_references
("tags");
3352 my $tagname = git_get_rev_name_tags
($hash);
3353 my $filename = basename
($project) . "-$hash.patch";
3356 -type
=> 'text/plain',
3357 -charset
=> 'utf-8',
3358 -expires
=> $expires,
3359 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3360 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3363 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3364 Subject: $co{'title'}
3366 print "X-Git-Tag: $tagname\n" if $tagname;
3367 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3369 foreach my $line (@{$co{'comment'}}) {
3376 if ($format eq 'html') {
3377 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3380 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3382 print "</div>\n"; # class="page_body"
3385 } elsif ($format eq 'plain') {
3389 or print "Reading git-diff-tree failed\n";
3393 sub git_commitdiff_plain
{
3394 git_commitdiff
('plain');
3398 if (!defined $hash_base) {
3399 $hash_base = git_get_head_hash
($project);
3401 if (!defined $page) {
3405 my %co = parse_commit
($hash_base);
3407 die_error
(undef, "Unknown commit object");
3410 my $refs = git_get_references
();
3411 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3413 if (!defined $hash && defined $file_name) {
3414 $hash = git_get_hash_by_path
($hash_base, $file_name);
3416 if (defined $hash) {
3417 $ftype = git_get_type
($hash);
3421 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3422 or die_error
(undef, "Open git-rev-list-failed");
3423 my @revlist = map { chomp; $_ } <$fd>;
3425 or die_error
(undef, "Reading git-rev-list failed");
3427 my $paging_nav = '';
3430 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3431 file_name
=>$file_name)},
3433 $paging_nav .= " ⋅ " .
3434 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3435 file_name
=>$file_name, page
=>$page-1),
3436 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3438 $paging_nav .= "first";
3439 $paging_nav .= " ⋅ prev";
3441 if ($#revlist >= (100 * ($page+1)-1)) {
3442 $paging_nav .= " ⋅ " .
3443 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3444 file_name
=>$file_name, page
=>$page+1),
3445 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3447 $paging_nav .= " ⋅ next";
3450 if ($#revlist >= (100 * ($page+1)-1)) {
3452 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3453 file_name
=>$file_name, page
=>$page+1),
3454 -title
=> "Alt-n"}, "next");
3458 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3459 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3460 git_print_page_path
($file_name, $ftype, $hash_base);
3462 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3463 $refs, $hash_base, $ftype, $next_link);
3469 if (!defined $searchtext) {
3470 die_error
(undef, "Text field empty");
3472 if (!defined $hash) {
3473 $hash = git_get_head_hash
($project);
3475 my %co = parse_commit
($hash);
3477 die_error
(undef, "Unknown commit object");
3480 my $commit_search = 1;
3481 my $author_search = 0;
3482 my $committer_search = 0;
3483 my $pickaxe_search = 0;
3484 if ($searchtext =~ s/^author\\://i) {
3486 } elsif ($searchtext =~ s/^committer\\://i) {
3487 $committer_search = 1;
3488 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3490 $pickaxe_search = 1;
3492 # pickaxe may take all resources of your box and run for several minutes
3493 # with every query - so decide by yourself how public you make this feature
3494 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3495 if (!$have_pickaxe) {
3496 die_error
('403 Permission denied', "Permission denied");
3500 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3501 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3503 print "<table cellspacing=\"0\">\n";
3505 if ($commit_search) {
3507 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3508 while (my $commit_text = <$fd>) {
3509 if (!grep m/$searchtext/i, $commit_text) {
3512 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3515 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3518 my @commit_lines = split "\n", $commit_text;
3519 my %co = parse_commit
(undef, \
@commit_lines);
3524 print "<tr class=\"dark\">\n";
3526 print "<tr class=\"light\">\n";
3529 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3530 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3532 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3533 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3534 my $comment = $co{'comment'};
3535 foreach my $line (@$comment) {
3536 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3537 my $lead = esc_html
($1) || "";
3538 $lead = chop_str
($lead, 30, 10);
3539 my $match = esc_html
($2) || "";
3540 my $trail = esc_html
($3) || "";
3541 $trail = chop_str
($trail, 30, 10);
3542 my $text = "$lead<span class=\"match\">$match</span>$trail";
3543 print chop_str
($text, 80, 5) . "<br/>\n";
3547 "<td class=\"link\">" .
3548 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3550 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3557 if ($pickaxe_search) {
3559 my $git_command = git_cmd_str
();
3560 open my $fd, "-|", "$git_command rev-list $hash | " .
3561 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3564 while (my $line = <$fd>) {
3565 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3568 $set{'from_id'} = $3;
3570 $set{'id'} = $set{'to_id'};
3571 if ($set{'id'} =~ m/0{40}/) {
3572 $set{'id'} = $set{'from_id'};
3574 if ($set{'id'} =~ m/0{40}/) {
3578 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3581 print "<tr class=\"dark\">\n";
3583 print "<tr class=\"light\">\n";
3586 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3587 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3589 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3590 -class => "list subject"},
3591 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3592 while (my $setref = shift @files) {
3594 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3595 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3597 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3601 "<td class=\"link\">" .
3602 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3604 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3608 %co = parse_commit
($1);
3618 my $head = git_get_head_hash
($project);
3619 if (!defined $hash) {
3622 if (!defined $page) {
3625 my $refs = git_get_references
();
3627 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3628 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3629 or die_error
(undef, "Open git-rev-list failed");
3630 my @revlist = map { chomp; $_ } <$fd>;
3633 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3635 if ($#revlist >= (100 * ($page+1)-1)) {
3637 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3638 -title
=> "Alt-n"}, "next");
3643 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3644 git_print_header_div
('summary', $project);
3646 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3651 ## ......................................................................
3652 ## feeds (RSS, OPML)
3655 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3656 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3657 or die_error
(undef, "Open git-rev-list failed");
3658 my @revlist = map { chomp; $_ } <$fd>;
3659 close $fd or die_error
(undef, "Reading git-rev-list failed");
3660 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3662 <?xml version="1.0" encoding="utf-8"?>
3663 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3665 <title>$project $my_uri $my_url</title>
3666 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3667 <description>$project log</description>
3668 <language>en</language>
3671 for (my $i = 0; $i <= $#revlist; $i++) {
3672 my $commit = $revlist[$i];
3673 my %co = parse_commit
($commit);
3674 # we read 150, we always show 30 and the ones more recent than 48 hours
3675 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3678 my %cd = parse_date
($co{'committer_epoch'});
3679 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3680 $co{'parent'}, $co{'id'}
3682 my @difftree = map { chomp; $_ } <$fd>;
3687 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3689 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3690 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3691 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3692 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3693 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3694 "<content:encoded>" .
3696 my $comment = $co{'comment'};
3697 foreach my $line (@$comment) {
3698 $line = to_utf8
($line);
3699 print "$line<br/>\n";
3702 foreach my $line (@difftree) {
3703 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3706 my $file = esc_html
(unquote
($7));
3707 $file = to_utf8
($file);
3708 print "$file<br/>\n";
3711 "</content:encoded>\n" .
3714 print "</channel></rss>";
3718 my @list = git_get_projects_list
();
3720 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3722 <?xml version="1.0" encoding="utf-8"?>
3723 <opml version="1.0">
3725 <title>$site_name Git OPML Export</title>
3728 <outline text="git RSS feeds">
3731 foreach my $pr (@list) {
3733 my $head = git_get_head_hash
($proj{'path'});
3734 if (!defined $head) {
3737 $git_dir = "$projectroot/$proj{'path'}";
3738 my %co = parse_commit
($head);
3743 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3744 my $rss = "$my_url?p=$proj{'path'};a=rss";
3745 my $html = "$my_url?p=$proj{'path'};a=summary";
3746 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";