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 if ($co{'title'} eq "") {
1124 $co{'title'} = $co{'title_short'} = '(no commit message)';
1126 # remove added spaces
1127 foreach my $line (@commit_lines) {
1130 $co{'comment'} = \
@commit_lines;
1132 my $age = time - $co{'committer_epoch'};
1134 $co{'age_string'} = age_string
($age);
1135 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1136 if ($age > 60*60*24*7*2) {
1137 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1138 $co{'age_string_age'} = $co{'age_string'};
1140 $co{'age_string_date'} = $co{'age_string'};
1141 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1146 # parse ref from ref_file, given by ref_id, with given type
1148 my $ref_file = shift;
1150 my $type = shift || git_get_type
($ref_id);
1153 $ref_item{'type'} = $type;
1154 $ref_item{'id'} = $ref_id;
1155 $ref_item{'epoch'} = 0;
1156 $ref_item{'age'} = "unknown";
1157 if ($type eq "tag") {
1158 my %tag = parse_tag
($ref_id);
1159 $ref_item{'comment'} = $tag{'comment'};
1160 if ($tag{'type'} eq "commit") {
1161 my %co = parse_commit
($tag{'object'});
1162 $ref_item{'epoch'} = $co{'committer_epoch'};
1163 $ref_item{'age'} = $co{'age_string'};
1164 } elsif (defined($tag{'epoch'})) {
1165 my $age = time - $tag{'epoch'};
1166 $ref_item{'epoch'} = $tag{'epoch'};
1167 $ref_item{'age'} = age_string
($age);
1169 $ref_item{'reftype'} = $tag{'type'};
1170 $ref_item{'name'} = $tag{'name'};
1171 $ref_item{'refid'} = $tag{'object'};
1172 } elsif ($type eq "commit"){
1173 my %co = parse_commit
($ref_id);
1174 $ref_item{'reftype'} = "commit";
1175 $ref_item{'name'} = $ref_file;
1176 $ref_item{'title'} = $co{'title'};
1177 $ref_item{'refid'} = $ref_id;
1178 $ref_item{'epoch'} = $co{'committer_epoch'};
1179 $ref_item{'age'} = $co{'age_string'};
1181 $ref_item{'reftype'} = $type;
1182 $ref_item{'name'} = $ref_file;
1183 $ref_item{'refid'} = $ref_id;
1189 # parse line of git-diff-tree "raw" output
1190 sub parse_difftree_raw_line
{
1194 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1195 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1196 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1197 $res{'from_mode'} = $1;
1198 $res{'to_mode'} = $2;
1199 $res{'from_id'} = $3;
1201 $res{'status'} = $5;
1202 $res{'similarity'} = $6;
1203 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1204 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1206 $res{'file'} = unquote
($7);
1209 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1210 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1211 $res{'commit'} = $1;
1214 return wantarray ? %res : \
%res;
1217 # parse line of git-ls-tree output
1218 sub parse_ls_tree_line
($;%) {
1223 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1224 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1232 $res{'name'} = unquote
($4);
1235 return wantarray ? %res : \
%res;
1238 ## ......................................................................
1239 ## parse to array of hashes functions
1241 sub git_get_refs_list
{
1242 my $type = shift || "";
1247 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1249 while (my $line = <$fd>) {
1251 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1252 if (defined $refs{$1}) {
1253 push @{$refs{$1}}, $2;
1258 if (! $4) { # unpeeled, direct reference
1259 push @refs, { hash
=> $1, name
=> $3 }; # without type
1260 } elsif ($3 eq $refs[-1]{'name'}) {
1261 # most likely a tag is followed by its peeled
1262 # (deref) one, and when that happens we know the
1263 # previous one was of type 'tag'.
1264 $refs[-1]{'type'} = "tag";
1270 foreach my $ref (@refs) {
1271 my $ref_file = $ref->{'name'};
1272 my $ref_id = $ref->{'hash'};
1274 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1275 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1277 push @reflist, \
%ref_item;
1280 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1281 return (\
@reflist, \
%refs);
1284 ## ----------------------------------------------------------------------
1285 ## filesystem-related functions
1287 sub get_file_owner
{
1290 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1291 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1292 if (!defined $gcos) {
1296 $owner =~ s/[,;].*$//;
1297 return to_utf8
($owner);
1300 ## ......................................................................
1301 ## mimetype related functions
1303 sub mimetype_guess_file
{
1304 my $filename = shift;
1305 my $mimemap = shift;
1306 -r
$mimemap or return undef;
1309 open(MIME
, $mimemap) or return undef;
1311 next if m/^#/; # skip comments
1312 my ($mime, $exts) = split(/\t+/);
1313 if (defined $exts) {
1314 my @exts = split(/\s+/, $exts);
1315 foreach my $ext (@exts) {
1316 $mimemap{$ext} = $mime;
1322 $filename =~ /\.([^.]*)$/;
1323 return $mimemap{$1};
1326 sub mimetype_guess
{
1327 my $filename = shift;
1329 $filename =~ /\./ or return undef;
1331 if ($mimetypes_file) {
1332 my $file = $mimetypes_file;
1333 if ($file !~ m!^/!) { # if it is relative path
1334 # it is relative to project
1335 $file = "$projectroot/$project/$file";
1337 $mime = mimetype_guess_file
($filename, $file);
1339 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1345 my $filename = shift;
1348 my $mime = mimetype_guess
($filename);
1349 $mime and return $mime;
1353 return $default_blob_plain_mimetype unless $fd;
1356 return 'text/plain' .
1357 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1358 } elsif (! $filename) {
1359 return 'application/octet-stream';
1360 } elsif ($filename =~ m/\.png$/i) {
1362 } elsif ($filename =~ m/\.gif$/i) {
1364 } elsif ($filename =~ m/\.jpe?g$/i) {
1365 return 'image/jpeg';
1367 return 'application/octet-stream';
1371 ## ======================================================================
1372 ## functions printing HTML: header, footer, error page
1374 sub git_header_html
{
1375 my $status = shift || "200 OK";
1376 my $expires = shift;
1378 my $title = "$site_name git";
1379 if (defined $project) {
1380 $title .= " - $project";
1381 if (defined $action) {
1382 $title .= "/$action";
1383 if (defined $file_name) {
1384 $title .= " - " . esc_html
($file_name);
1385 if ($action eq "tree" && $file_name !~ m
|/$|) {
1392 # require explicit support from the UA if we are to send the page as
1393 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1394 # we have to do this because MSIE sometimes globs '*/*', pretending to
1395 # support xhtml+xml but choking when it gets what it asked for.
1396 if (defined $cgi->http('HTTP_ACCEPT') &&
1397 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1398 $cgi->Accept('application/xhtml+xml') != 0) {
1399 $content_type = 'application/xhtml+xml';
1401 $content_type = 'text/html';
1403 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1404 -status
=> $status, -expires
=> $expires);
1406 <?xml version="1.0" encoding="utf-8"?>
1407 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1408 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1409 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1410 <!-- git core binaries version $git_version -->
1412 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1413 <meta name="generator" content="gitweb/$version git/$git_version"/>
1414 <meta name="robots" content="index, nofollow"/>
1415 <title>$title</title>
1417 # print out each stylesheet that exist
1418 if (defined $stylesheet) {
1419 #provides backwards capability for those people who define style sheet in a config file
1420 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1422 foreach my $stylesheet (@stylesheets) {
1423 next unless $stylesheet;
1424 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1427 if (defined $project) {
1428 printf('<link rel="alternate" title="%s log" '.
1429 'href="%s" type="application/rss+xml"/>'."\n",
1430 esc_param
($project), href
(action
=>"rss"));
1432 printf('<link rel="alternate" title="%s projects list" '.
1433 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1434 $site_name, href
(project
=>undef, action
=>"project_index"));
1435 printf('<link rel="alternate" title="%s projects logs" '.
1436 'href="%s" type="text/x-opml"/>'."\n",
1437 $site_name, href
(project
=>undef, action
=>"opml"));
1439 if (defined $favicon) {
1440 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1446 if (-f
$site_header) {
1447 open (my $fd, $site_header);
1452 print "<div class=\"page_header\">\n" .
1453 "<a href=\"" . esc_html
($githelp_url) .
1454 "\" title=\"" . esc_html
($githelp_label) .
1456 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1458 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1459 if (defined $project) {
1460 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1461 if (defined $action) {
1465 if (!defined $searchtext) {
1469 if (defined $hash_base) {
1470 $search_hash = $hash_base;
1471 } elsif (defined $hash) {
1472 $search_hash = $hash;
1474 $search_hash = "HEAD";
1476 $cgi->param("a", "search");
1477 $cgi->param("h", $search_hash);
1478 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1479 "<div class=\"search\">\n" .
1480 $cgi->hidden(-name
=> "p") . "\n" .
1481 $cgi->hidden(-name
=> "a") . "\n" .
1482 $cgi->hidden(-name
=> "h") . "\n" .
1483 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1485 $cgi->end_form() . "\n";
1490 sub git_footer_html
{
1491 print "<div class=\"page_footer\">\n";
1492 if (defined $project) {
1493 my $descr = git_get_project_description
($project);
1494 if (defined $descr) {
1495 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1497 print $cgi->a({-href
=> href
(action
=>"rss"),
1498 -class => "rss_logo"}, "RSS") . "\n";
1500 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1501 -class => "rss_logo"}, "OPML") . " ";
1502 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1503 -class => "rss_logo"}, "TXT") . "\n";
1507 if (-f
$site_footer) {
1508 open (my $fd, $site_footer);
1518 my $status = shift || "403 Forbidden";
1519 my $error = shift || "Malformed query, file missing or permission denied";
1521 git_header_html
($status);
1523 <div class="page_body">
1533 ## ----------------------------------------------------------------------
1534 ## functions printing or outputting HTML: navigation
1536 sub git_print_page_nav
{
1537 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1538 $extra = '' if !defined $extra; # pager or formats
1540 my @navs = qw(summary shortlog log commit commitdiff tree);
1542 @navs = grep { $_ ne $suppress } @navs;
1545 my %arg = map { $_ => {action
=>$_} } @navs;
1546 if (defined $head) {
1547 for (qw(commit commitdiff)) {
1548 $arg{$_}{hash
} = $head;
1550 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1551 for (qw(shortlog log)) {
1552 $arg{$_}{hash
} = $head;
1556 $arg{tree
}{hash
} = $treehead if defined $treehead;
1557 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1559 print "<div class=\"page_nav\">\n" .
1561 map { $_ eq $current ?
1562 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1564 print "<br/>\n$extra<br/>\n" .
1568 sub format_paging_nav
{
1569 my ($action, $hash, $head, $page, $nrevs) = @_;
1573 if ($hash ne $head || $page) {
1574 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1576 $paging_nav .= "HEAD";
1580 $paging_nav .= " ⋅ " .
1581 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1582 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1584 $paging_nav .= " ⋅ prev";
1587 if ($nrevs >= (100 * ($page+1)-1)) {
1588 $paging_nav .= " ⋅ " .
1589 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1590 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1592 $paging_nav .= " ⋅ next";
1598 ## ......................................................................
1599 ## functions printing or outputting HTML: div
1601 sub git_print_header_div
{
1602 my ($action, $title, $hash, $hash_base) = @_;
1605 $args{action
} = $action;
1606 $args{hash
} = $hash if $hash;
1607 $args{hash_base
} = $hash_base if $hash_base;
1609 print "<div class=\"header\">\n" .
1610 $cgi->a({-href
=> href
(%args), -class => "title"},
1611 $title ? $title : $action) .
1615 #sub git_print_authorship (\%) {
1616 sub git_print_authorship
{
1619 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1620 print "<div class=\"author_date\">" .
1621 esc_html
($co->{'author_name'}) .
1623 if ($ad{'hour_local'} < 6) {
1624 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1625 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1627 printf(" (%02d:%02d %s)",
1628 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1633 sub git_print_page_path
{
1638 if (!defined $name) {
1639 print "<div class=\"page_path\">/</div>\n";
1641 my @dirname = split '/', $name;
1642 my $basename = pop @dirname;
1645 print "<div class=\"page_path\">";
1646 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1647 -title
=> 'tree root'}, "[$project]");
1649 foreach my $dir (@dirname) {
1650 $fullname .= ($fullname ? '/' : '') . $dir;
1651 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1653 -title
=> $fullname}, esc_html
($dir));
1656 if (defined $type && $type eq 'blob') {
1657 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1659 -title
=> $name}, esc_html
($basename));
1660 } elsif (defined $type && $type eq 'tree') {
1661 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1663 -title
=> $name}, esc_html
($basename));
1665 print esc_html
($basename);
1667 print "<br/></div>\n";
1671 # sub git_print_log (\@;%) {
1672 sub git_print_log
($;%) {
1676 if ($opts{'-remove_title'}) {
1677 # remove title, i.e. first line of log
1680 # remove leading empty lines
1681 while (defined $log->[0] && $log->[0] eq "") {
1688 foreach my $line (@$log) {
1689 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1692 if (! $opts{'-remove_signoff'}) {
1693 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1696 # remove signoff lines
1703 # print only one empty line
1704 # do not print empty line after signoff
1706 next if ($empty || $signoff);
1712 print format_log_line_html
($line) . "<br/>\n";
1715 if ($opts{'-final_empty_line'}) {
1716 # end with single empty line
1717 print "<br/>\n" unless $empty;
1721 sub git_print_simplified_log
{
1723 my $remove_title = shift;
1726 -final_empty_line
=> 1,
1727 -remove_title
=> $remove_title);
1730 # print tree entry (row of git_tree), but without encompassing <tr> element
1731 sub git_print_tree_entry
{
1732 my ($t, $basedir, $hash_base, $have_blame) = @_;
1735 $base_key{hash_base
} = $hash_base if defined $hash_base;
1737 # The format of a table row is: mode list link. Where mode is
1738 # the mode of the entry, list is the name of the entry, an href,
1739 # and link is the action links of the entry.
1741 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1742 if ($t->{'type'} eq "blob") {
1743 print "<td class=\"list\">" .
1744 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1745 file_name
=>"$basedir$t->{'name'}", %base_key),
1746 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1747 print "<td class=\"link\">";
1749 print $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1750 file_name
=>"$basedir$t->{'name'}", %base_key)},
1753 if (defined $hash_base) {
1757 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1758 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1762 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1763 file_name
=>"$basedir$t->{'name'}")},
1767 } elsif ($t->{'type'} eq "tree") {
1768 print "<td class=\"list\">";
1769 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1770 file_name
=>"$basedir$t->{'name'}", %base_key)},
1771 esc_html
($t->{'name'}));
1773 print "<td class=\"link\">";
1774 if (defined $hash_base) {
1775 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1776 file_name
=>"$basedir$t->{'name'}")},
1783 ## ......................................................................
1784 ## functions printing large fragments of HTML
1786 sub git_difftree_body
{
1787 my ($difftree, $hash, $parent) = @_;
1789 print "<div class=\"list_head\">\n";
1790 if ($#{$difftree} > 10) {
1791 print(($#{$difftree} + 1) . " files changed:\n");
1795 print "<table class=\"diff_tree\">\n";
1798 foreach my $line (@{$difftree}) {
1799 my %diff = parse_difftree_raw_line
($line);
1802 print "<tr class=\"dark\">\n";
1804 print "<tr class=\"light\">\n";
1808 my ($to_mode_oct, $to_mode_str, $to_file_type);
1809 my ($from_mode_oct, $from_mode_str, $from_file_type);
1810 if ($diff{'to_mode'} ne ('0' x
6)) {
1811 $to_mode_oct = oct $diff{'to_mode'};
1812 if (S_ISREG
($to_mode_oct)) { # only for regular file
1813 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1815 $to_file_type = file_type
($diff{'to_mode'});
1817 if ($diff{'from_mode'} ne ('0' x
6)) {
1818 $from_mode_oct = oct $diff{'from_mode'};
1819 if (S_ISREG
($to_mode_oct)) { # only for regular file
1820 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1822 $from_file_type = file_type
($diff{'from_mode'});
1825 if ($diff{'status'} eq "A") { # created
1826 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1827 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1828 $mode_chng .= "]</span>";
1830 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1831 hash_base
=>$hash, file_name
=>$diff{'file'}),
1832 -class => "list"}, esc_html
($diff{'file'}));
1834 print "<td>$mode_chng</td>\n";
1835 print "<td class=\"link\">";
1836 if ($action eq 'commitdiff') {
1839 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1843 } elsif ($diff{'status'} eq "D") { # deleted
1844 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1846 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1847 hash_base
=>$parent, file_name
=>$diff{'file'}),
1848 -class => "list"}, esc_html
($diff{'file'}));
1850 print "<td>$mode_chng</td>\n";
1851 print "<td class=\"link\">";
1852 if ($action eq 'commitdiff') {
1855 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1858 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1859 file_name
=>$diff{'file'})},
1861 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1862 file_name
=>$diff{'file'})},
1866 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1867 my $mode_chnge = "";
1868 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1869 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1870 if ($from_file_type != $to_file_type) {
1871 $mode_chnge .= " from $from_file_type to $to_file_type";
1873 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1874 if ($from_mode_str && $to_mode_str) {
1875 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1876 } elsif ($to_mode_str) {
1877 $mode_chnge .= " mode: $to_mode_str";
1880 $mode_chnge .= "]</span>\n";
1883 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1884 hash_base
=>$hash, file_name
=>$diff{'file'}),
1885 -class => "list"}, esc_html
($diff{'file'}));
1887 print "<td>$mode_chnge</td>\n";
1888 print "<td class=\"link\">";
1889 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1890 if ($action eq 'commitdiff') {
1893 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1895 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1896 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1897 hash_base
=>$hash, hash_parent_base
=>$parent,
1898 file_name
=>$diff{'file'})},
1903 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1904 file_name
=>$diff{'file'})},
1906 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1907 file_name
=>$diff{'file'})},
1911 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1912 my %status_name = ('R' => 'moved', 'C' => 'copied');
1913 my $nstatus = $status_name{$diff{'status'}};
1915 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1916 # mode also for directories, so we cannot use $to_mode_str
1917 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1920 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1921 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1922 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1923 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1924 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1925 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1926 -class => "list"}, esc_html
($diff{'from_file'})) .
1927 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1928 "<td class=\"link\">";
1929 if ($diff{'to_id'} ne $diff{'from_id'}) {
1930 if ($action eq 'commitdiff') {
1933 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1935 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1936 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1937 hash_base
=>$hash, hash_parent_base
=>$parent,
1938 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1943 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1944 file_name
=>$diff{'from_file'})},
1946 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1947 file_name
=>$diff{'from_file'})},
1951 } # we should not encounter Unmerged (U) or Unknown (X) status
1957 sub git_patchset_body
{
1958 my ($fd, $difftree, $hash, $hash_parent) = @_;
1962 my $patch_found = 0;
1965 print "<div class=\"patchset\">\n";
1968 while (my $patch_line = <$fd>) {
1971 if ($patch_line =~ m/^diff /) { # "git diff" header
1972 # beginning of patch (in patchset)
1974 # close previous patch
1975 print "</div>\n"; # class="patch"
1977 # first patch in patchset
1980 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1982 if (ref($difftree->[$patch_idx]) eq "HASH") {
1983 $diffinfo = $difftree->[$patch_idx];
1985 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1989 # for now, no extended header, hence we skip empty patches
1990 # companion to next LINE if $in_header;
1991 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1996 if ($diffinfo->{'status'} eq "A") { # added
1997 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1998 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1999 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2000 $diffinfo->{'to_id'}) . " (new)" .
2001 "</div>\n"; # class="diff_info"
2003 } elsif ($diffinfo->{'status'} eq "D") { # deleted
2004 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
2005 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2006 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2007 $diffinfo->{'from_id'}) . " (deleted)" .
2008 "</div>\n"; # class="diff_info"
2010 } elsif ($diffinfo->{'status'} eq "R" || # renamed
2011 $diffinfo->{'status'} eq "C" || # copied
2012 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
2013 print "<div class=\"diff_info\">" .
2014 file_type
($diffinfo->{'from_mode'}) . ":" .
2015 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2016 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
2017 $diffinfo->{'from_id'}) .
2019 file_type
($diffinfo->{'to_mode'}) . ":" .
2020 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2021 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
2022 $diffinfo->{'to_id'});
2023 print "</div>\n"; # class="diff_info"
2025 } else { # modified, mode changed, ...
2026 print "<div class=\"diff_info\">" .
2027 file_type
($diffinfo->{'from_mode'}) . ":" .
2028 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2029 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
2030 $diffinfo->{'from_id'}) .
2032 file_type
($diffinfo->{'to_mode'}) . ":" .
2033 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2034 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
2035 $diffinfo->{'to_id'});
2036 print "</div>\n"; # class="diff_info"
2039 #print "<div class=\"diff extended_header\">\n";
2042 } # start of patch in patchset
2045 if ($in_header && $patch_line =~ m/^---/) {
2046 #print "</div>\n"; # class="diff extended_header"
2049 my $file = $diffinfo->{'from_file'};
2050 $file ||= $diffinfo->{'file'};
2051 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
2052 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
2053 -class => "list"}, esc_html
($file));
2054 $patch_line =~ s
|a
/.*$|a/$file|g
;
2055 print "<div class=\"diff from_file\">$patch_line</div>\n";
2057 $patch_line = <$fd>;
2060 #$patch_line =~ m/^+++/;
2061 $file = $diffinfo->{'to_file'};
2062 $file ||= $diffinfo->{'file'};
2063 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2064 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
2065 -class => "list"}, esc_html
($file));
2066 $patch_line =~ s
|b
/.*|b/$file|g
;
2067 print "<div class=\"diff to_file\">$patch_line</div>\n";
2071 next LINE
if $in_header;
2073 print format_diff_line
($patch_line);
2075 print "</div>\n" if $patch_found; # class="patch"
2077 print "</div>\n"; # class="patchset"
2080 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2082 sub git_shortlog_body
{
2083 # uses global variable $project
2084 my ($revlist, $from, $to, $refs, $extra) = @_;
2086 $from = 0 unless defined $from;
2087 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2089 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2091 for (my $i = $from; $i <= $to; $i++) {
2092 my $commit = $revlist->[$i];
2093 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2094 my $ref = format_ref_marker
($refs, $commit);
2095 my %co = parse_commit
($commit);
2097 print "<tr class=\"dark\">\n";
2099 print "<tr class=\"light\">\n";
2102 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2103 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2104 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2106 print format_subject_html
($co{'title'}, $co{'title_short'},
2107 href
(action
=>"commit", hash
=>$commit), $ref);
2109 "<td class=\"link\">" .
2110 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2111 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2112 if (gitweb_have_snapshot
()) {
2113 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2118 if (defined $extra) {
2120 "<td colspan=\"4\">$extra</td>\n" .
2126 sub git_history_body
{
2127 # Warning: assumes constant type (blob or tree) during history
2128 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2130 $from = 0 unless defined $from;
2131 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2133 print "<table class=\"history\" cellspacing=\"0\">\n";
2135 for (my $i = $from; $i <= $to; $i++) {
2136 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2141 my %co = parse_commit
($commit);
2146 my $ref = format_ref_marker
($refs, $commit);
2149 print "<tr class=\"dark\">\n";
2151 print "<tr class=\"light\">\n";
2154 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2155 # shortlog uses chop_str($co{'author_name'}, 10)
2156 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2158 # originally git_history used chop_str($co{'title'}, 50)
2159 print format_subject_html
($co{'title'}, $co{'title_short'},
2160 href
(action
=>"commit", hash
=>$commit), $ref);
2162 "<td class=\"link\">" .
2163 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2164 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2166 if ($ftype eq 'blob') {
2167 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2168 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2169 if (defined $blob_current && defined $blob_parent &&
2170 $blob_current ne $blob_parent) {
2172 $cgi->a({-href
=> href
(action
=>"blobdiff",
2173 hash
=>$blob_current, hash_parent
=>$blob_parent,
2174 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2175 file_name
=>$file_name)},
2182 if (defined $extra) {
2184 "<td colspan=\"4\">$extra</td>\n" .
2191 # uses global variable $project
2192 my ($taglist, $from, $to, $extra) = @_;
2193 $from = 0 unless defined $from;
2194 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2196 print "<table class=\"tags\" cellspacing=\"0\">\n";
2198 for (my $i = $from; $i <= $to; $i++) {
2199 my $entry = $taglist->[$i];
2201 my $comment_lines = $tag{'comment'};
2202 my $comment = shift @$comment_lines;
2204 if (defined $comment) {
2205 $comment_short = chop_str
($comment, 30, 5);
2208 print "<tr class=\"dark\">\n";
2210 print "<tr class=\"light\">\n";
2213 print "<td><i>$tag{'age'}</i></td>\n" .
2215 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2216 -class => "list name"}, esc_html
($tag{'name'})) .
2219 if (defined $comment) {
2220 print format_subject_html
($comment, $comment_short,
2221 href
(action
=>"tag", hash
=>$tag{'id'}));
2224 "<td class=\"selflink\">";
2225 if ($tag{'type'} eq "tag") {
2226 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2231 "<td class=\"link\">" . " | " .
2232 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2233 if ($tag{'reftype'} eq "commit") {
2234 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2235 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2236 } elsif ($tag{'reftype'} eq "blob") {
2237 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2242 if (defined $extra) {
2244 "<td colspan=\"5\">$extra</td>\n" .
2250 sub git_heads_body
{
2251 # uses global variable $project
2252 my ($headlist, $head, $from, $to, $extra) = @_;
2253 $from = 0 unless defined $from;
2254 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2256 print "<table class=\"heads\" cellspacing=\"0\">\n";
2258 for (my $i = $from; $i <= $to; $i++) {
2259 my $entry = $headlist->[$i];
2261 my $curr = $tag{'id'} eq $head;
2263 print "<tr class=\"dark\">\n";
2265 print "<tr class=\"light\">\n";
2268 print "<td><i>$tag{'age'}</i></td>\n" .
2269 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
2270 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2271 -class => "list name"},esc_html
($tag{'name'})) .
2273 "<td class=\"link\">" .
2274 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2275 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2276 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2280 if (defined $extra) {
2282 "<td colspan=\"3\">$extra</td>\n" .
2288 ## ======================================================================
2289 ## ======================================================================
2292 sub git_project_list
{
2293 my $order = $cgi->param('o');
2294 if (defined $order && $order !~ m/project|descr|owner|age/) {
2295 die_error
(undef, "Unknown order parameter");
2298 my @list = git_get_projects_list
();
2301 die_error
(undef, "No projects found");
2303 foreach my $pr (@list) {
2304 my $head = git_get_head_hash
($pr->{'path'});
2305 if (!defined $head) {
2308 $git_dir = "$projectroot/$pr->{'path'}";
2309 my %co = parse_commit
($head);
2313 $pr->{'commit'} = \
%co;
2314 if (!defined $pr->{'descr'}) {
2315 my $descr = git_get_project_description
($pr->{'path'}) || "";
2316 $pr->{'descr'} = chop_str
($descr, 25, 5);
2318 if (!defined $pr->{'owner'}) {
2319 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2321 push @projects, $pr;
2325 if (-f
$home_text) {
2326 print "<div class=\"index_include\">\n";
2327 open (my $fd, $home_text);
2332 print "<table class=\"project_list\">\n" .
2334 $order ||= "project";
2335 if ($order eq "project") {
2336 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2337 print "<th>Project</th>\n";
2340 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2341 -class => "header"}, "Project") .
2344 if ($order eq "descr") {
2345 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2346 print "<th>Description</th>\n";
2349 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2350 -class => "header"}, "Description") .
2353 if ($order eq "owner") {
2354 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2355 print "<th>Owner</th>\n";
2358 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2359 -class => "header"}, "Owner") .
2362 if ($order eq "age") {
2363 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2364 print "<th>Last Change</th>\n";
2367 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2368 -class => "header"}, "Last Change") .
2371 print "<th></th>\n" .
2374 foreach my $pr (@projects) {
2376 print "<tr class=\"dark\">\n";
2378 print "<tr class=\"light\">\n";
2381 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2382 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2383 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2384 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2385 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2386 $pr->{'commit'}{'age_string'} . "</td>\n" .
2387 "<td class=\"link\">" .
2388 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2389 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2390 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2391 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2399 sub git_project_index
{
2400 my @projects = git_get_projects_list
();
2403 -type
=> 'text/plain',
2404 -charset
=> 'utf-8',
2405 -content_disposition
=> 'inline; filename="index.aux"');
2407 foreach my $pr (@projects) {
2408 if (!exists $pr->{'owner'}) {
2409 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2412 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2413 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2414 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2415 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2419 print "$path $owner\n";
2424 my $descr = git_get_project_description
($project) || "none";
2425 my $head = git_get_head_hash
($project);
2426 my %co = parse_commit
($head);
2427 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2429 my $owner = git_get_project_owner
($project);
2431 my ($reflist, $refs) = git_get_refs_list
();
2435 foreach my $ref (@$reflist) {
2436 if ($ref->{'name'} =~ s!^heads/!!) {
2437 push @headlist, $ref;
2439 $ref->{'name'} =~ s!^tags/!!;
2440 push @taglist, $ref;
2445 git_print_page_nav
('summary','', $head);
2447 print "<div class=\"title\"> </div>\n";
2448 print "<table cellspacing=\"0\">\n" .
2449 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2450 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2451 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2452 # use per project git URL list in $projectroot/$project/cloneurl
2453 # or make project git URL from git base URL and project name
2454 my $url_tag = "URL";
2455 my @url_list = git_get_project_url_list
($project);
2456 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2457 foreach my $git_url (@url_list) {
2458 next unless $git_url;
2459 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2464 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2465 git_get_head_hash
($project)
2466 or die_error
(undef, "Open git-rev-list failed");
2467 my @revlist = map { chomp; $_ } <$fd>;
2469 git_print_header_div
('shortlog');
2470 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2471 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2474 git_print_header_div
('tags');
2475 git_tags_body
(\
@taglist, 0, 15,
2476 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2480 git_print_header_div
('heads');
2481 git_heads_body
(\
@headlist, $head, 0, 15,
2482 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2489 my $head = git_get_head_hash
($project);
2491 git_print_page_nav
('','', $head,undef,$head);
2492 my %tag = parse_tag
($hash);
2493 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2494 print "<div class=\"title_text\">\n" .
2495 "<table cellspacing=\"0\">\n" .
2497 "<td>object</td>\n" .
2498 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2499 $tag{'object'}) . "</td>\n" .
2500 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2501 $tag{'type'}) . "</td>\n" .
2503 if (defined($tag{'author'})) {
2504 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2505 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2506 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2507 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2510 print "</table>\n\n" .
2512 print "<div class=\"page_body\">";
2513 my $comment = $tag{'comment'};
2514 foreach my $line (@$comment) {
2515 print esc_html
($line) . "<br/>\n";
2525 my ($have_blame) = gitweb_check_feature
('blame');
2527 die_error
('403 Permission denied', "Permission denied");
2529 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2530 $hash_base ||= git_get_head_hash
($project);
2531 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2532 my %co = parse_commit
($hash_base)
2533 or die_error
(undef, "Reading commit failed");
2534 if (!defined $hash) {
2535 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2536 or die_error
(undef, "Error looking up file");
2538 $ftype = git_get_type
($hash);
2539 if ($ftype !~ "blob") {
2540 die_error
("400 Bad Request", "Object is not a blob");
2542 open ($fd, "-|", git_cmd
(), "blame", '--porcelain', '--',
2543 $file_name, $hash_base)
2544 or die_error
(undef, "Open git-blame failed");
2547 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2550 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2553 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2555 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2556 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2557 git_print_page_path
($file_name, $ftype, $hash_base);
2558 my @rev_color = (qw(light2 dark2));
2559 my $num_colors = scalar(@rev_color);
2560 my $current_color = 0;
2563 <div class="page_body">
2564 <table class="blame">
2565 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2570 last unless defined $_;
2571 my ($full_rev, $lineno, $orig_lineno, $group_size) =
2572 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2573 if (!exists $metainfo{$full_rev}) {
2574 $metainfo{$full_rev} = {};
2576 my $meta = $metainfo{$full_rev};
2579 if (/^(\S+) (.*)$/) {
2584 my $rev = substr($full_rev, 0, 8);
2585 my $author = $meta->{'author'};
2586 my %date = parse_date
($meta->{'author-time'},
2587 $meta->{'author-tz'});
2588 my $date = $date{'iso-tz'};
2590 $current_color = ++$current_color % $num_colors;
2592 print "<tr class=\"$rev_color[$current_color]\">\n";
2594 print "<td class=\"sha1\"";
2595 print " title=\"$author, $date\"";
2596 print " rowspan=\"$group_size\"" if ($group_size > 1);
2598 print $cgi->a({-href
=> href
(action
=>"commit",
2600 file_name
=>$file_name)},
2604 my $blamed = href
(action
=> 'blame',
2605 file_name
=> $meta->{'filename'},
2606 hash_base
=> $full_rev);
2607 print "<td class=\"linenr\">";
2608 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
2610 -class => "linenr" },
2613 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2619 or print "Reading blob failed\n";
2626 my ($have_blame) = gitweb_check_feature
('blame');
2628 die_error
('403 Permission denied', "Permission denied");
2630 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2631 $hash_base ||= git_get_head_hash
($project);
2632 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2633 my %co = parse_commit
($hash_base)
2634 or die_error
(undef, "Reading commit failed");
2635 if (!defined $hash) {
2636 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2637 or die_error
(undef, "Error lookup file");
2639 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2640 or die_error
(undef, "Open git-annotate failed");
2643 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2646 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2649 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2651 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2652 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2653 git_print_page_path
($file_name, 'blob', $hash_base);
2654 print "<div class=\"page_body\">\n";
2656 <table class="blame">
2665 my @line_class = (qw(light dark));
2666 my $line_class_len = scalar (@line_class);
2667 my $line_class_num = $#line_class;
2668 while (my $line = <$fd>) {
2680 $line_class_num = ($line_class_num + 1) % $line_class_len;
2682 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2689 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
2692 $short_rev = substr ($long_rev, 0, 8);
2693 $age = time () - $time;
2694 $age_str = age_string
($age);
2695 $age_str =~ s/ / /g;
2696 $age_class = age_class
($age);
2697 $author = esc_html
($author);
2698 $author =~ s/ / /g;
2700 $data = untabify
($data);
2701 $data = esc_html
($data);
2704 <tr class="$line_class[$line_class_num]">
2705 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2706 <td class="$age_class">$age_str</td>
2708 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2709 <td class="pre">$data</td>
2712 } # while (my $line = <$fd>)
2713 print "</table>\n\n";
2715 or print "Reading blob failed.\n";
2721 my $head = git_get_head_hash
($project);
2723 git_print_page_nav
('','', $head,undef,$head);
2724 git_print_header_div
('summary', $project);
2726 my ($taglist) = git_get_refs_list
("tags");
2728 git_tags_body
($taglist);
2734 my $head = git_get_head_hash
($project);
2736 git_print_page_nav
('','', $head,undef,$head);
2737 git_print_header_div
('summary', $project);
2739 my ($headlist) = git_get_refs_list
("heads");
2741 git_heads_body
($headlist, $head);
2746 sub git_blob_plain
{
2749 if (!defined $hash) {
2750 if (defined $file_name) {
2751 my $base = $hash_base || git_get_head_hash
($project);
2752 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2753 or die_error
(undef, "Error lookup file");
2755 die_error
(undef, "No file name defined");
2757 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2758 # blobs defined by non-textual hash id's can be cached
2763 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2764 or die_error
(undef, "Couldn't cat $file_name, $hash");
2766 $type ||= blob_mimetype
($fd, $file_name);
2768 # save as filename, even when no $file_name is given
2769 my $save_as = "$hash";
2770 if (defined $file_name) {
2771 $save_as = $file_name;
2772 } elsif ($type =~ m/^text\//) {
2779 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2781 binmode STDOUT
, ':raw';
2783 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2791 if (!defined $hash) {
2792 if (defined $file_name) {
2793 my $base = $hash_base || git_get_head_hash
($project);
2794 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2795 or die_error
(undef, "Error lookup file");
2797 die_error
(undef, "No file name defined");
2799 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2800 # blobs defined by non-textual hash id's can be cached
2804 my ($have_blame) = gitweb_check_feature
('blame');
2805 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2806 or die_error
(undef, "Couldn't cat $file_name, $hash");
2807 my $mimetype = blob_mimetype
($fd, $file_name);
2808 if ($mimetype !~ m/^text\//) {
2810 return git_blob_plain
($mimetype);
2812 git_header_html
(undef, $expires);
2813 my $formats_nav = '';
2814 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2815 if (defined $file_name) {
2818 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2819 hash
=>$hash, file_name
=>$file_name)},
2824 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2825 hash
=>$hash, file_name
=>$file_name)},
2828 $cgi->a({-href
=> href
(action
=>"blob_plain",
2829 hash
=>$hash, file_name
=>$file_name)},
2832 $cgi->a({-href
=> href
(action
=>"blob",
2833 hash_base
=>"HEAD", file_name
=>$file_name)},
2837 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2839 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2840 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2842 print "<div class=\"page_nav\">\n" .
2843 "<br/><br/></div>\n" .
2844 "<div class=\"title\">$hash</div>\n";
2846 git_print_page_path
($file_name, "blob", $hash_base);
2847 print "<div class=\"page_body\">\n";
2849 while (my $line = <$fd>) {
2852 $line = untabify
($line);
2853 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2854 $nr, $nr, $nr, esc_html
($line);
2857 or print "Reading blob failed.\n";
2863 my $have_snapshot = gitweb_have_snapshot
();
2865 if (!defined $hash_base) {
2866 $hash_base = "HEAD";
2868 if (!defined $hash) {
2869 if (defined $file_name) {
2870 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
2876 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2877 or die_error
(undef, "Open git-ls-tree failed");
2878 my @entries = map { chomp; $_ } <$fd>;
2879 close $fd or die_error
(undef, "Reading tree failed");
2882 my $refs = git_get_references
();
2883 my $ref = format_ref_marker
($refs, $hash_base);
2886 my ($have_blame) = gitweb_check_feature
('blame');
2887 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2889 if (defined $file_name) {
2891 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2892 hash
=>$hash, file_name
=>$file_name)},
2894 $cgi->a({-href
=> href
(action
=>"tree",
2895 hash_base
=>"HEAD", file_name
=>$file_name)},
2898 if ($have_snapshot) {
2899 # FIXME: Should be available when we have no hash base as well.
2901 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2904 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2905 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2908 print "<div class=\"page_nav\">\n";
2909 print "<br/><br/></div>\n";
2910 print "<div class=\"title\">$hash</div>\n";
2912 if (defined $file_name) {
2913 $base = esc_html
("$file_name/");
2915 git_print_page_path
($file_name, 'tree', $hash_base);
2916 print "<div class=\"page_body\">\n";
2917 print "<table cellspacing=\"0\">\n";
2919 foreach my $line (@entries) {
2920 my %t = parse_ls_tree_line
($line, -z
=> 1);
2923 print "<tr class=\"dark\">\n";
2925 print "<tr class=\"light\">\n";
2929 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2933 print "</table>\n" .
2939 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2940 my $have_snapshot = (defined $ctype && defined $suffix);
2941 if (!$have_snapshot) {
2942 die_error
('403 Permission denied', "Permission denied");
2945 if (!defined $hash) {
2946 $hash = git_get_head_hash
($project);
2949 my $filename = basename
($project) . "-$hash.tar.$suffix";
2952 -type
=> 'application/x-tar',
2953 -content_encoding
=> $ctype,
2954 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
2955 -status
=> '200 OK');
2957 my $git = git_cmd_str
();
2958 my $name = $project;
2959 $name =~ s/\047/\047\\\047\047/g;
2961 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
2962 or die_error
(undef, "Execute git-tar-tree failed.");
2963 binmode STDOUT
, ':raw';
2965 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2971 my $head = git_get_head_hash
($project);
2972 if (!defined $hash) {
2975 if (!defined $page) {
2978 my $refs = git_get_references
();
2980 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2981 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2982 or die_error
(undef, "Open git-rev-list failed");
2983 my @revlist = map { chomp; $_ } <$fd>;
2986 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2989 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2992 my %co = parse_commit
($hash);
2994 git_print_header_div
('summary', $project);
2995 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2997 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2998 my $commit = $revlist[$i];
2999 my $ref = format_ref_marker
($refs, $commit);
3000 my %co = parse_commit
($commit);
3002 my %ad = parse_date
($co{'author_epoch'});
3003 git_print_header_div
('commit',
3004 "<span class=\"age\">$co{'age_string'}</span>" .
3005 esc_html
($co{'title'}) . $ref,
3007 print "<div class=\"title_text\">\n" .
3008 "<div class=\"log_link\">\n" .
3009 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3011 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3013 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3016 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3019 print "<div class=\"log_body\">\n";
3020 git_print_simplified_log
($co{'comment'});
3027 my %co = parse_commit
($hash);
3029 die_error
(undef, "Unknown commit object");
3031 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3032 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3034 my $parent = $co{'parent'};
3035 if (!defined $parent) {
3038 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
3039 or die_error
(undef, "Open git-diff-tree failed");
3040 my @difftree = map { chomp; $_ } <$fd>;
3041 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3043 # non-textual hash id's can be cached
3045 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3048 my $refs = git_get_references
();
3049 my $ref = format_ref_marker
($refs, $co{'id'});
3051 my $have_snapshot = gitweb_have_snapshot
();
3054 if (defined $file_name && defined $co{'parent'}) {
3056 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3059 git_header_html
(undef, $expires);
3060 git_print_page_nav
('commit', '',
3061 $hash, $co{'tree'}, $hash,
3062 join (' | ', @views_nav));
3064 if (defined $co{'parent'}) {
3065 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3067 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3069 print "<div class=\"title_text\">\n" .
3070 "<table cellspacing=\"0\">\n";
3071 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3073 "<td></td><td> $ad{'rfc2822'}";
3074 if ($ad{'hour_local'} < 6) {
3075 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3076 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3078 printf(" (%02d:%02d %s)",
3079 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3083 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3084 print "<tr><td></td><td> $cd{'rfc2822'}" .
3085 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3087 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3090 "<td class=\"sha1\">" .
3091 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3092 class => "list"}, $co{'tree'}) .
3094 "<td class=\"link\">" .
3095 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3097 if ($have_snapshot) {
3099 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3103 my $parents = $co{'parents'};
3104 foreach my $par (@$parents) {
3107 "<td class=\"sha1\">" .
3108 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3109 class => "list"}, $par) .
3111 "<td class=\"link\">" .
3112 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3114 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3121 print "<div class=\"page_body\">\n";
3122 git_print_log
($co{'comment'});
3125 git_difftree_body
(\
@difftree, $hash, $parent);
3131 my $format = shift || 'html';
3138 # preparing $fd and %diffinfo for git_patchset_body
3140 if (defined $hash_base && defined $hash_parent_base) {
3141 if (defined $file_name) {
3143 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3145 or die_error
(undef, "Open git-diff-tree failed");
3146 @difftree = map { chomp; $_ } <$fd>;
3148 or die_error
(undef, "Reading git-diff-tree failed");
3150 or die_error
('404 Not Found', "Blob diff not found");
3152 } elsif (defined $hash &&
3153 $hash =~ /[0-9a-fA-F]{40}/) {
3154 # try to find filename from $hash
3156 # read filtered raw output
3157 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3158 or die_error
(undef, "Open git-diff-tree failed");
3160 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3162 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3163 map { chomp; $_ } <$fd>;
3165 or die_error
(undef, "Reading git-diff-tree failed");
3167 or die_error
('404 Not Found', "Blob diff not found");
3170 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3173 if (@difftree > 1) {
3174 die_error
('404 Not Found', "Ambiguous blob diff specification");
3177 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3178 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3179 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3181 $hash_parent ||= $diffinfo{'from_id'};
3182 $hash ||= $diffinfo{'to_id'};
3184 # non-textual hash id's can be cached
3185 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3186 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3191 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3192 '-p', $hash_parent_base, $hash_base,
3194 or die_error
(undef, "Open git-diff-tree failed");
3197 # old/legacy style URI
3198 if (!%diffinfo && # if new style URI failed
3199 defined $hash && defined $hash_parent) {
3200 # fake git-diff-tree raw output
3201 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3202 $diffinfo{'from_id'} = $hash_parent;
3203 $diffinfo{'to_id'} = $hash;
3204 if (defined $file_name) {
3205 if (defined $file_parent) {
3206 $diffinfo{'status'} = '2';
3207 $diffinfo{'from_file'} = $file_parent;
3208 $diffinfo{'to_file'} = $file_name;
3209 } else { # assume not renamed
3210 $diffinfo{'status'} = '1';
3211 $diffinfo{'from_file'} = $file_name;
3212 $diffinfo{'to_file'} = $file_name;
3214 } else { # no filename given
3215 $diffinfo{'status'} = '2';
3216 $diffinfo{'from_file'} = $hash_parent;
3217 $diffinfo{'to_file'} = $hash;
3220 # non-textual hash id's can be cached
3221 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3222 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3227 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3228 or die_error
(undef, "Open git-diff failed");
3230 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3235 if ($format eq 'html') {
3237 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3238 hash
=>$hash, hash_parent
=>$hash_parent,
3239 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3240 file_name
=>$file_name, file_parent
=>$file_parent)},
3242 git_header_html
(undef, $expires);
3243 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3244 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3245 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3247 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3248 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3250 if (defined $file_name) {
3251 git_print_page_path
($file_name, "blob", $hash_base);
3253 print "<div class=\"page_path\"></div>\n";
3256 } elsif ($format eq 'plain') {
3258 -type
=> 'text/plain',
3259 -charset
=> 'utf-8',
3260 -expires
=> $expires,
3261 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3263 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3266 die_error
(undef, "Unknown blobdiff format");
3270 if ($format eq 'html') {
3271 print "<div class=\"page_body\">\n";
3273 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3276 print "</div>\n"; # class="page_body"
3280 while (my $line = <$fd>) {
3281 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3282 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3286 last if $line =~ m!^\+\+\+!;
3294 sub git_blobdiff_plain
{
3295 git_blobdiff
('plain');
3298 sub git_commitdiff
{
3299 my $format = shift || 'html';
3300 my %co = parse_commit
($hash);
3302 die_error
(undef, "Unknown commit object");
3304 if (!defined $hash_parent) {
3305 $hash_parent = $co{'parent'} || '--root';
3311 if ($format eq 'html') {
3312 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3313 "--patch-with-raw", "--full-index", $hash_parent, $hash
3314 or die_error
(undef, "Open git-diff-tree failed");
3316 while (chomp(my $line = <$fd>)) {
3317 # empty line ends raw part of diff-tree output
3319 push @difftree, $line;
3322 } elsif ($format eq 'plain') {
3323 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3324 '-p', $hash_parent, $hash
3325 or die_error
(undef, "Open git-diff-tree failed");
3328 die_error
(undef, "Unknown commitdiff format");
3331 # non-textual hash id's can be cached
3333 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3337 # write commit message
3338 if ($format eq 'html') {
3339 my $refs = git_get_references
();
3340 my $ref = format_ref_marker
($refs, $co{'id'});
3342 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3343 hash
=>$hash, hash_parent
=>$hash_parent)},
3346 git_header_html
(undef, $expires);
3347 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3348 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3349 git_print_authorship
(\
%co);
3350 print "<div class=\"page_body\">\n";
3351 print "<div class=\"log\">\n";
3352 git_print_simplified_log
($co{'comment'}, 1); # skip title
3353 print "</div>\n"; # class="log"
3355 } elsif ($format eq 'plain') {
3356 my $refs = git_get_references
("tags");
3357 my $tagname = git_get_rev_name_tags
($hash);
3358 my $filename = basename
($project) . "-$hash.patch";
3361 -type
=> 'text/plain',
3362 -charset
=> 'utf-8',
3363 -expires
=> $expires,
3364 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3365 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3368 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3369 Subject: $co{'title'}
3371 print "X-Git-Tag: $tagname\n" if $tagname;
3372 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3374 foreach my $line (@{$co{'comment'}}) {
3381 if ($format eq 'html') {
3382 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3385 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3387 print "</div>\n"; # class="page_body"
3390 } elsif ($format eq 'plain') {
3394 or print "Reading git-diff-tree failed\n";
3398 sub git_commitdiff_plain
{
3399 git_commitdiff
('plain');
3403 if (!defined $hash_base) {
3404 $hash_base = git_get_head_hash
($project);
3406 if (!defined $page) {
3410 my %co = parse_commit
($hash_base);
3412 die_error
(undef, "Unknown commit object");
3415 my $refs = git_get_references
();
3416 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3418 if (!defined $hash && defined $file_name) {
3419 $hash = git_get_hash_by_path
($hash_base, $file_name);
3421 if (defined $hash) {
3422 $ftype = git_get_type
($hash);
3426 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3427 or die_error
(undef, "Open git-rev-list-failed");
3428 my @revlist = map { chomp; $_ } <$fd>;
3430 or die_error
(undef, "Reading git-rev-list failed");
3432 my $paging_nav = '';
3435 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3436 file_name
=>$file_name)},
3438 $paging_nav .= " ⋅ " .
3439 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3440 file_name
=>$file_name, page
=>$page-1),
3441 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3443 $paging_nav .= "first";
3444 $paging_nav .= " ⋅ prev";
3446 if ($#revlist >= (100 * ($page+1)-1)) {
3447 $paging_nav .= " ⋅ " .
3448 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3449 file_name
=>$file_name, page
=>$page+1),
3450 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3452 $paging_nav .= " ⋅ next";
3455 if ($#revlist >= (100 * ($page+1)-1)) {
3457 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3458 file_name
=>$file_name, page
=>$page+1),
3459 -title
=> "Alt-n"}, "next");
3463 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3464 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3465 git_print_page_path
($file_name, $ftype, $hash_base);
3467 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3468 $refs, $hash_base, $ftype, $next_link);
3474 if (!defined $searchtext) {
3475 die_error
(undef, "Text field empty");
3477 if (!defined $hash) {
3478 $hash = git_get_head_hash
($project);
3480 my %co = parse_commit
($hash);
3482 die_error
(undef, "Unknown commit object");
3485 my $commit_search = 1;
3486 my $author_search = 0;
3487 my $committer_search = 0;
3488 my $pickaxe_search = 0;
3489 if ($searchtext =~ s/^author\\://i) {
3491 } elsif ($searchtext =~ s/^committer\\://i) {
3492 $committer_search = 1;
3493 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3495 $pickaxe_search = 1;
3497 # pickaxe may take all resources of your box and run for several minutes
3498 # with every query - so decide by yourself how public you make this feature
3499 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3500 if (!$have_pickaxe) {
3501 die_error
('403 Permission denied', "Permission denied");
3505 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3506 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3508 print "<table cellspacing=\"0\">\n";
3510 if ($commit_search) {
3512 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3513 while (my $commit_text = <$fd>) {
3514 if (!grep m/$searchtext/i, $commit_text) {
3517 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3520 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3523 my @commit_lines = split "\n", $commit_text;
3524 my %co = parse_commit
(undef, \
@commit_lines);
3529 print "<tr class=\"dark\">\n";
3531 print "<tr class=\"light\">\n";
3534 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3535 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3537 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3538 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3539 my $comment = $co{'comment'};
3540 foreach my $line (@$comment) {
3541 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3542 my $lead = esc_html
($1) || "";
3543 $lead = chop_str
($lead, 30, 10);
3544 my $match = esc_html
($2) || "";
3545 my $trail = esc_html
($3) || "";
3546 $trail = chop_str
($trail, 30, 10);
3547 my $text = "$lead<span class=\"match\">$match</span>$trail";
3548 print chop_str
($text, 80, 5) . "<br/>\n";
3552 "<td class=\"link\">" .
3553 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3555 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3562 if ($pickaxe_search) {
3564 my $git_command = git_cmd_str
();
3565 open my $fd, "-|", "$git_command rev-list $hash | " .
3566 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3569 while (my $line = <$fd>) {
3570 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3573 $set{'from_id'} = $3;
3575 $set{'id'} = $set{'to_id'};
3576 if ($set{'id'} =~ m/0{40}/) {
3577 $set{'id'} = $set{'from_id'};
3579 if ($set{'id'} =~ m/0{40}/) {
3583 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3586 print "<tr class=\"dark\">\n";
3588 print "<tr class=\"light\">\n";
3591 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3592 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3594 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3595 -class => "list subject"},
3596 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3597 while (my $setref = shift @files) {
3599 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3600 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3602 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3606 "<td class=\"link\">" .
3607 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3609 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3613 %co = parse_commit
($1);
3623 my $head = git_get_head_hash
($project);
3624 if (!defined $hash) {
3627 if (!defined $page) {
3630 my $refs = git_get_references
();
3632 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3633 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3634 or die_error
(undef, "Open git-rev-list failed");
3635 my @revlist = map { chomp; $_ } <$fd>;
3638 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3640 if ($#revlist >= (100 * ($page+1)-1)) {
3642 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3643 -title
=> "Alt-n"}, "next");
3648 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3649 git_print_header_div
('summary', $project);
3651 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3656 ## ......................................................................
3657 ## feeds (RSS, OPML)
3660 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3661 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3662 or die_error
(undef, "Open git-rev-list failed");
3663 my @revlist = map { chomp; $_ } <$fd>;
3664 close $fd or die_error
(undef, "Reading git-rev-list failed");
3665 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3667 <?xml version="1.0" encoding="utf-8"?>
3668 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3670 <title>$project $my_uri $my_url</title>
3671 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3672 <description>$project log</description>
3673 <language>en</language>
3676 for (my $i = 0; $i <= $#revlist; $i++) {
3677 my $commit = $revlist[$i];
3678 my %co = parse_commit
($commit);
3679 # we read 150, we always show 30 and the ones more recent than 48 hours
3680 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3683 my %cd = parse_date
($co{'committer_epoch'});
3684 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3685 $co{'parent'}, $co{'id'}
3687 my @difftree = map { chomp; $_ } <$fd>;
3692 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3694 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3695 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3696 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3697 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3698 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3699 "<content:encoded>" .
3701 my $comment = $co{'comment'};
3702 foreach my $line (@$comment) {
3703 $line = to_utf8
($line);
3704 print "$line<br/>\n";
3707 foreach my $line (@difftree) {
3708 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3711 my $file = esc_html
(unquote
($7));
3712 $file = to_utf8
($file);
3713 print "$file<br/>\n";
3716 "</content:encoded>\n" .
3719 print "</channel></rss>";
3723 my @list = git_get_projects_list
();
3725 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3727 <?xml version="1.0" encoding="utf-8"?>
3728 <opml version="1.0">
3730 <title>$site_name Git OPML Export</title>
3733 <outline text="git RSS feeds">
3736 foreach my $pr (@list) {
3738 my $head = git_get_head_hash
($proj{'path'});
3739 if (!defined $head) {
3742 $git_dir = "$projectroot/$proj{'path'}";
3743 my %co = parse_commit
($head);
3748 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3749 my $rss = "$my_url?p=$proj{'path'};a=rss";
3750 my $html = "$my_url?p=$proj{'path'};a=summary";
3751 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";