3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute
=> 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
44 # html text to include at home page
45 our $home_text = "++GITWEB_HOMETEXT++";
47 # URI of default stylesheet
48 our $stylesheet = "++GITWEB_CSS++";
49 # URI of GIT logo (72x27 size)
50 our $logo = "++GITWEB_LOGO++";
51 # URI of GIT favicon, assumed to be image/png type
52 our $favicon = "++GITWEB_FAVICON++";
54 # URI and label (title) of GIT logo link
55 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
56 #our $logo_label = "git documentation";
57 our $logo_url = "http://git.or.cz/";
58 our $logo_label = "git homepage";
60 # source of projects list
61 our $projects_list = "++GITWEB_LIST++";
63 # show repository only if this file exists
64 # (only effective if this variable evaluates to true)
65 our $export_ok = "++GITWEB_EXPORT_OK++";
67 # only allow viewing of repositories also shown on the overview page
68 our $strict_export = "++GITWEB_STRICT_EXPORT++";
70 # list of git base URLs used for URL to where fetch project from,
71 # i.e. full URL is "$git_base_url/$project"
72 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
74 # default blob_plain mimetype and default charset for text/plain blob
75 our $default_blob_plain_mimetype = 'text/plain';
76 our $default_text_plain_charset = undef;
78 # file to use for guessing MIME types before trying /etc/mime.types
79 # (relative to the current git repository)
80 our $mimetypes_file = undef;
82 # You define site-wide feature defaults here; override them with
83 # $GITWEB_CONFIG as necessary.
86 # 'sub' => feature-sub (subroutine),
87 # 'override' => allow-override (boolean),
88 # 'default' => [ default options...] (array reference)}
90 # if feature is overridable (it means that allow-override has true value,
91 # then feature-sub will be called with default options as parameters;
92 # return value of feature-sub indicates if to enable specified feature
94 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
97 'sub' => \
&feature_blame
,
102 'sub' => \
&feature_snapshot
,
104 # => [content-encoding, suffix, program]
105 'default' => ['x-gzip', 'gz', 'gzip']},
108 'sub' => \
&feature_pickaxe
,
113 sub gitweb_check_feature
{
115 return unless exists $feature{$name};
116 my ($sub, $override, @defaults) = (
117 $feature{$name}{'sub'},
118 $feature{$name}{'override'},
119 @
{$feature{$name}{'default'}});
120 if (!$override) { return @defaults; }
121 return $sub->(@defaults);
124 # To enable system wide have in $GITWEB_CONFIG
125 # $feature{'blame'}{'default'} = [1];
126 # To have project specific config enable override in $GITWEB_CONFIG
127 # $feature{'blame'}{'override'} = 1;
128 # and in project config gitweb.blame = 0|1;
131 my ($val) = git_get_project_config
('blame', '--bool');
133 if ($val eq 'true') {
135 } elsif ($val eq 'false') {
142 # To disable system wide have in $GITWEB_CONFIG
143 # $feature{'snapshot'}{'default'} = [undef];
144 # To have project specific config enable override in $GITWEB_CONFIG
145 # $feature{'blame'}{'override'} = 1;
146 # and in project config gitweb.snapshot = none|gzip|bzip2
148 sub feature_snapshot
{
149 my ($ctype, $suffix, $command) = @_;
151 my ($val) = git_get_project_config
('snapshot');
153 if ($val eq 'gzip') {
154 return ('x-gzip', 'gz', 'gzip');
155 } elsif ($val eq 'bzip2') {
156 return ('x-bzip2', 'bz2', 'bzip2');
157 } elsif ($val eq 'none') {
161 return ($ctype, $suffix, $command);
164 sub gitweb_have_snapshot
{
165 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
166 my $have_snapshot = (defined $ctype && defined $suffix);
168 return $have_snapshot;
171 # To enable system wide have in $GITWEB_CONFIG
172 # $feature{'pickaxe'}{'default'} = [1];
173 # To have project specific config enable override in $GITWEB_CONFIG
174 # $feature{'pickaxe'}{'override'} = 1;
175 # and in project config gitweb.pickaxe = 0|1;
177 sub feature_pickaxe
{
178 my ($val) = git_get_project_config
('pickaxe', '--bool');
180 if ($val eq 'true') {
182 } elsif ($val eq 'false') {
189 # rename detection options for git-diff and git-diff-tree
190 # - default is '-M', with the cost proportional to
191 # (number of removed files) * (number of new files).
192 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
193 # (number of changed files + number of removed files) * (number of new files)
194 # - even more costly is '-C', '--find-copies-harder' with cost
195 # (number of files in the original tree) * (number of new files)
196 # - one might want to include '-B' option, e.g. '-B', '-M'
197 our @diff_opts = ('-M'); # taken from git_commit
199 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
200 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
202 # version of the core git binary
203 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
205 $projects_list ||= $projectroot;
207 # ======================================================================
208 # input validation and dispatch
209 our $action = $cgi->param('a');
210 if (defined $action) {
211 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
212 die_error
(undef, "Invalid action parameter");
216 # parameters which are pathnames
217 our $project = $cgi->param('p');
218 if (defined $project) {
219 if (!validate_pathname
($project) ||
220 !(-d
"$projectroot/$project") ||
221 !(-e
"$projectroot/$project/HEAD") ||
222 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
223 ($strict_export && !project_in_list
($project))) {
225 die_error
(undef, "No such project");
229 our $file_name = $cgi->param('f');
230 if (defined $file_name) {
231 if (!validate_pathname
($file_name)) {
232 die_error
(undef, "Invalid file parameter");
236 our $file_parent = $cgi->param('fp');
237 if (defined $file_parent) {
238 if (!validate_pathname
($file_parent)) {
239 die_error
(undef, "Invalid file parent parameter");
243 # parameters which are refnames
244 our $hash = $cgi->param('h');
246 if (!validate_refname
($hash)) {
247 die_error
(undef, "Invalid hash parameter");
251 our $hash_parent = $cgi->param('hp');
252 if (defined $hash_parent) {
253 if (!validate_refname
($hash_parent)) {
254 die_error
(undef, "Invalid hash parent parameter");
258 our $hash_base = $cgi->param('hb');
259 if (defined $hash_base) {
260 if (!validate_refname
($hash_base)) {
261 die_error
(undef, "Invalid hash base parameter");
265 our $hash_parent_base = $cgi->param('hpb');
266 if (defined $hash_parent_base) {
267 if (!validate_refname
($hash_parent_base)) {
268 die_error
(undef, "Invalid hash parent base parameter");
273 our $page = $cgi->param('pg');
275 if ($page =~ m/[^0-9]/) {
276 die_error
(undef, "Invalid page parameter");
280 our $searchtext = $cgi->param('s');
281 if (defined $searchtext) {
282 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
283 die_error
(undef, "Invalid search parameter");
285 $searchtext = quotemeta $searchtext;
288 # now read PATH_INFO and use it as alternative to parameters
289 sub evaluate_path_info
{
290 return if defined $project;
291 my $path_info = $ENV{"PATH_INFO"};
292 return if !$path_info;
293 $path_info =~ s
,^/+,,;
294 return if !$path_info;
295 # find which part of PATH_INFO is project
296 $project = $path_info;
298 while ($project && !-e
"$projectroot/$project/HEAD") {
299 $project =~ s
,/*[^/]*$,,;
302 $project = validate_pathname
($project);
304 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
305 ($strict_export && !project_in_list
($project))) {
309 # do not change any parameters if an action is given using the query string
311 $path_info =~ s
,^$project/*,,;
312 my ($refname, $pathname) = split(/:/, $path_info, 2);
313 if (defined $pathname) {
314 # we got "project.git/branch:filename" or "project.git/branch:dir/"
315 # we could use git_get_type(branch:pathname), but it needs $git_dir
316 $pathname =~ s
,^/+,,;
317 if (!$pathname || substr($pathname, -1) eq "/") {
321 $action ||= "blob_plain";
323 $hash_base ||= validate_refname
($refname);
324 $file_name ||= validate_pathname
($pathname);
325 } elsif (defined $refname) {
326 # we got "project.git/branch"
327 $action ||= "shortlog";
328 $hash ||= validate_refname
($refname);
331 evaluate_path_info
();
333 # path to the current git repository
335 $git_dir = "$projectroot/$project" if $project;
339 "blame" => \
&git_blame2
,
340 "blobdiff" => \
&git_blobdiff
,
341 "blobdiff_plain" => \
&git_blobdiff_plain
,
342 "blob" => \
&git_blob
,
343 "blob_plain" => \
&git_blob_plain
,
344 "commitdiff" => \
&git_commitdiff
,
345 "commitdiff_plain" => \
&git_commitdiff_plain
,
346 "commit" => \
&git_commit
,
347 "heads" => \
&git_heads
,
348 "history" => \
&git_history
,
351 "search" => \
&git_search
,
352 "shortlog" => \
&git_shortlog
,
353 "summary" => \
&git_summary
,
355 "tags" => \
&git_tags
,
356 "tree" => \
&git_tree
,
357 "snapshot" => \
&git_snapshot
,
358 # those below don't need $project
359 "opml" => \
&git_opml
,
360 "project_list" => \
&git_project_list
,
361 "project_index" => \
&git_project_index
,
364 if (defined $project) {
365 $action ||= 'summary';
367 $action ||= 'project_list';
369 if (!defined($actions{$action})) {
370 die_error
(undef, "Unknown action");
372 if ($action !~ m/^(opml|project_list|project_index)$/ &&
374 die_error
(undef, "Project needed");
376 $actions{$action}->();
379 ## ======================================================================
393 hash_parent_base
=> "hpb",
398 my %mapping = @mapping;
400 $params{'project'} = $project unless exists $params{'project'};
403 for (my $i = 0; $i < @mapping; $i += 2) {
404 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
405 if (defined $params{$name}) {
406 push @result, $symbol . "=" . esc_param
($params{$name});
409 return "$my_uri?" . join(';', @result);
413 ## ======================================================================
414 ## validation, quoting/unquoting and escaping
416 sub validate_pathname
{
417 my $input = shift || return undef;
419 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
420 # at the beginning, at the end, and between slashes.
421 # also this catches doubled slashes
422 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
426 if ($input =~ m!\0!) {
432 sub validate_refname
{
433 my $input = shift || return undef;
435 # textual hashes are O.K.
436 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
439 # it must be correct pathname
440 $input = validate_pathname
($input)
442 # restrictions on ref name according to git-check-ref-format
443 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
449 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
452 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
455 # quote unsafe chars, but keep the slash, even when it's not
456 # correct, but quoted slashes look too horrible in bookmarks
459 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
465 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
468 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
474 # replace invalid utf8 character with SUBSTITUTION sequence
477 $str = to_utf8
($str);
478 $str = escapeHTML
($str);
479 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
480 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
484 # git may return quoted and escaped filenames
487 if ($str =~ m/^"(.*)"$/) {
489 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
494 # escape tabs (convert tabs to spaces)
498 while ((my $pos = index($line, "\t")) != -1) {
499 if (my $count = (8 - ($pos % 8))) {
500 my $spaces = ' ' x
$count;
501 $line =~ s/\t/$spaces/;
508 sub project_in_list
{
510 my @list = git_get_projects_list
();
511 return @list && scalar(grep { $_->{'path'} eq $project } @list);
514 ## ----------------------------------------------------------------------
515 ## HTML aware string manipulation
520 my $add_len = shift || 10;
522 # allow only $len chars, but don't cut a word if it would fit in $add_len
523 # if it doesn't fit, cut it if it's still longer than the dots we would add
524 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
527 if (length($tail) > 4) {
529 $body =~ s/&[^;]*$//; # remove chopped character entities
534 ## ----------------------------------------------------------------------
535 ## functions returning short strings
537 # CSS class for given age value (in seconds)
541 if ($age < 60*60*2) {
543 } elsif ($age < 60*60*24*2) {
550 # convert age in seconds to "nn units ago" string
555 if ($age > 60*60*24*365*2) {
556 $age_str = (int $age/60/60/24/365);
557 $age_str .= " years ago";
558 } elsif ($age > 60*60*24*(365/12)*2) {
559 $age_str = int $age/60/60/24/(365/12);
560 $age_str .= " months ago";
561 } elsif ($age > 60*60*24*7*2) {
562 $age_str = int $age/60/60/24/7;
563 $age_str .= " weeks ago";
564 } elsif ($age > 60*60*24*2) {
565 $age_str = int $age/60/60/24;
566 $age_str .= " days ago";
567 } elsif ($age > 60*60*2) {
568 $age_str = int $age/60/60;
569 $age_str .= " hours ago";
570 } elsif ($age > 60*2) {
571 $age_str = int $age/60;
572 $age_str .= " min ago";
575 $age_str .= " sec ago";
577 $age_str .= " right now";
582 # convert file mode in octal to symbolic file mode string
584 my $mode = oct shift;
586 if (S_ISDIR
($mode & S_IFMT
)) {
588 } elsif (S_ISLNK
($mode)) {
590 } elsif (S_ISREG
($mode)) {
591 # git cares only about the executable bit
592 if ($mode & S_IXUSR
) {
602 # convert file mode in octal to file type string
606 if ($mode !~ m/^[0-7]+$/) {
612 if (S_ISDIR
($mode & S_IFMT
)) {
614 } elsif (S_ISLNK
($mode)) {
616 } elsif (S_ISREG
($mode)) {
623 ## ----------------------------------------------------------------------
624 ## functions returning short HTML fragments, or transforming HTML fragments
625 ## which don't beling to other sections
627 # format line of commit message or tag comment
628 sub format_log_line_html
{
631 $line = esc_html
($line);
632 $line =~ s/ / /g;
633 if ($line =~ m/([0-9a-fA-F]{40})/) {
635 if (git_get_type
($hash_text) eq "commit") {
637 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
638 -class => "text"}, $hash_text);
639 $line =~ s/$hash_text/$link/;
645 # format marker of refs pointing to given object
646 sub format_ref_marker
{
647 my ($refs, $id) = @_;
650 if (defined $refs->{$id}) {
651 foreach my $ref (@
{$refs->{$id}}) {
652 my ($type, $name) = qw();
653 # e.g. tags/v2.6.11 or heads/next
654 if ($ref =~ m!^(.*?)s?/(.*)$!) {
662 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
667 return ' <span class="refs">'. $markers . '</span>';
673 # format, perhaps shortened and with markers, title line
674 sub format_subject_html
{
675 my ($long, $short, $href, $extra) = @_;
676 $extra = '' unless defined($extra);
678 if (length($short) < length($long)) {
679 return $cgi->a({-href
=> $href, -class => "list subject",
680 -title
=> to_utf8
($long)},
681 esc_html
($short) . $extra);
683 return $cgi->a({-href
=> $href, -class => "list subject"},
684 esc_html
($long) . $extra);
688 sub format_diff_line
{
690 my $char = substr($line, 0, 1);
696 $diff_class = " add";
697 } elsif ($char eq "-") {
698 $diff_class = " rem";
699 } elsif ($char eq "@") {
700 $diff_class = " chunk_header";
701 } elsif ($char eq "\\") {
702 $diff_class = " incomplete";
704 $line = untabify
($line);
705 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
708 ## ----------------------------------------------------------------------
709 ## git utility subroutines, invoking git commands
711 # returns path to the core git executable and the --git-dir parameter as list
713 return $GIT, '--git-dir='.$git_dir;
716 # returns path to the core git executable and the --git-dir parameter as string
718 return join(' ', git_cmd
());
721 # get HEAD ref of given project as hash
722 sub git_get_head_hash
{
724 my $o_git_dir = $git_dir;
726 $git_dir = "$projectroot/$project";
727 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
730 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
734 if (defined $o_git_dir) {
735 $git_dir = $o_git_dir;
740 # get type of given object
744 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
751 sub git_get_project_config
{
752 my ($key, $type) = @_;
754 return unless ($key);
755 $key =~ s/^gitweb\.//;
756 return if ($key =~ m/\W/);
758 my @x = (git_cmd
(), 'repo-config');
759 if (defined $type) { push @x, $type; }
761 push @x, "gitweb.$key";
767 # get hash of given path at given ref
768 sub git_get_hash_by_path
{
770 my $path = shift || return undef;
775 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
776 or die_error
(undef, "Open git-ls-tree failed");
778 close $fd or return undef;
780 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
781 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
782 if (defined $type && $type ne $2) {
789 ## ......................................................................
790 ## git utility functions, directly accessing git repository
792 sub git_get_project_description
{
795 open my $fd, "$projectroot/$path/description" or return undef;
802 sub git_get_project_url_list
{
805 open my $fd, "$projectroot/$path/cloneurl" or return;
806 my @git_project_url_list = map { chomp; $_ } <$fd>;
809 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
812 sub git_get_projects_list
{
815 if (-d
$projects_list) {
816 # search in directory
817 my $dir = $projects_list;
818 my $pfxlen = length("$dir");
821 follow_fast
=> 1, # follow symbolic links
822 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
824 # skip project-list toplevel, if we get it.
825 return if (m!^[/.]$!);
826 # only directories can be git repositories
827 return unless (-d
$_);
829 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
830 # we check related file in $projectroot
831 if (-e
"$projectroot/$subdir/HEAD" && (!$export_ok ||
832 -e
"$projectroot/$subdir/$export_ok")) {
833 push @list, { path
=> $subdir };
834 $File::Find
::prune
= 1;
839 } elsif (-f
$projects_list) {
840 # read from file(url-encoded):
841 # 'git%2Fgit.git Linus+Torvalds'
842 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
843 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
844 open my ($fd), $projects_list or return;
845 while (my $line = <$fd>) {
847 my ($path, $owner) = split ' ', $line;
848 $path = unescape
($path);
849 $owner = unescape
($owner);
850 if (!defined $path) {
853 if (-e
"$projectroot/$path/HEAD" && (!$export_ok ||
854 -e
"$projectroot/$path/$export_ok")) {
857 owner
=> to_utf8
($owner),
864 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
868 sub git_get_project_owner
{
872 return undef unless $project;
874 # read from file (url-encoded):
875 # 'git%2Fgit.git Linus+Torvalds'
876 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
877 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
878 if (-f
$projects_list) {
879 open (my $fd , $projects_list);
880 while (my $line = <$fd>) {
882 my ($pr, $ow) = split ' ', $line;
885 if ($pr eq $project) {
886 $owner = to_utf8
($ow);
892 if (!defined $owner) {
893 $owner = get_file_owner
("$projectroot/$project");
899 sub git_get_references
{
900 my $type = shift || "";
902 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
903 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
904 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
907 while (my $line = <$fd>) {
909 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
910 if (defined $refs{$1}) {
911 push @
{$refs{$1}}, $2;
921 sub git_get_rev_name_tags
{
922 my $hash = shift || return undef;
924 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
926 my $name_rev = <$fd>;
929 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
932 # catches also '$hash undefined' output
937 ## ----------------------------------------------------------------------
938 ## parse to hash functions
942 my $tz = shift || "-0000";
945 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
946 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
947 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
948 $date{'hour'} = $hour;
949 $date{'minute'} = $min;
950 $date{'mday'} = $mday;
951 $date{'day'} = $days[$wday];
952 $date{'month'} = $months[$mon];
953 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
954 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
955 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
956 $mday, $months[$mon], $hour ,$min;
958 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
959 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
960 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
961 $date{'hour_local'} = $hour;
962 $date{'minute_local'} = $min;
963 $date{'tz_local'} = $tz;
972 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
973 $tag{'id'} = $tag_id;
974 while (my $line = <$fd>) {
976 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
978 } elsif ($line =~ m/^type (.+)$/) {
980 } elsif ($line =~ m/^tag (.+)$/) {
982 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
986 } elsif ($line =~ m/--BEGIN/) {
987 push @comment, $line;
989 } elsif ($line eq "") {
993 push @comment, <$fd>;
994 $tag{'comment'} = \
@comment;
996 if (!defined $tag{'name'}) {
1003 my $commit_id = shift;
1004 my $commit_text = shift;
1009 if (defined $commit_text) {
1010 @commit_lines = @
$commit_text;
1013 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
1015 @commit_lines = split '\n', <$fd>;
1016 close $fd or return;
1019 my $header = shift @commit_lines;
1020 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1023 ($co{'id'}, my @parents) = split ' ', $header;
1024 $co{'parents'} = \
@parents;
1025 $co{'parent'} = $parents[0];
1026 while (my $line = shift @commit_lines) {
1027 last if $line eq "\n";
1028 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1030 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1032 $co{'author_epoch'} = $2;
1033 $co{'author_tz'} = $3;
1034 if ($co{'author'} =~ m/^([^<]+) </) {
1035 $co{'author_name'} = $1;
1037 $co{'author_name'} = $co{'author'};
1039 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1040 $co{'committer'} = $1;
1041 $co{'committer_epoch'} = $2;
1042 $co{'committer_tz'} = $3;
1043 $co{'committer_name'} = $co{'committer'};
1044 $co{'committer_name'} =~ s/ <.*//;
1047 if (!defined $co{'tree'}) {
1051 foreach my $title (@commit_lines) {
1054 $co{'title'} = chop_str
($title, 80, 5);
1055 # remove leading stuff of merges to make the interesting part visible
1056 if (length($title) > 50) {
1057 $title =~ s/^Automatic //;
1058 $title =~ s/^merge (of|with) /Merge ... /i;
1059 if (length($title) > 50) {
1060 $title =~ s/(http|rsync):\/\///;
1062 if (length($title) > 50) {
1063 $title =~ s/(master|www|rsync)\.//;
1065 if (length($title) > 50) {
1066 $title =~ s/kernel.org:?//;
1068 if (length($title) > 50) {
1069 $title =~ s/\/pub\/scm//;
1072 $co{'title_short'} = chop_str
($title, 50, 5);
1076 if ($co{'title'} eq "") {
1077 $co{'title'} = $co{'title_short'} = '(no commit message)';
1079 # remove added spaces
1080 foreach my $line (@commit_lines) {
1083 $co{'comment'} = \
@commit_lines;
1085 my $age = time - $co{'committer_epoch'};
1087 $co{'age_string'} = age_string
($age);
1088 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1089 if ($age > 60*60*24*7*2) {
1090 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1091 $co{'age_string_age'} = $co{'age_string'};
1093 $co{'age_string_date'} = $co{'age_string'};
1094 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1099 # parse ref from ref_file, given by ref_id, with given type
1101 my $ref_file = shift;
1103 my $type = shift || git_get_type
($ref_id);
1106 $ref_item{'type'} = $type;
1107 $ref_item{'id'} = $ref_id;
1108 $ref_item{'epoch'} = 0;
1109 $ref_item{'age'} = "unknown";
1110 if ($type eq "tag") {
1111 my %tag = parse_tag
($ref_id);
1112 $ref_item{'comment'} = $tag{'comment'};
1113 if ($tag{'type'} eq "commit") {
1114 my %co = parse_commit
($tag{'object'});
1115 $ref_item{'epoch'} = $co{'committer_epoch'};
1116 $ref_item{'age'} = $co{'age_string'};
1117 } elsif (defined($tag{'epoch'})) {
1118 my $age = time - $tag{'epoch'};
1119 $ref_item{'epoch'} = $tag{'epoch'};
1120 $ref_item{'age'} = age_string
($age);
1122 $ref_item{'reftype'} = $tag{'type'};
1123 $ref_item{'name'} = $tag{'name'};
1124 $ref_item{'refid'} = $tag{'object'};
1125 } elsif ($type eq "commit"){
1126 my %co = parse_commit
($ref_id);
1127 $ref_item{'reftype'} = "commit";
1128 $ref_item{'name'} = $ref_file;
1129 $ref_item{'title'} = $co{'title'};
1130 $ref_item{'refid'} = $ref_id;
1131 $ref_item{'epoch'} = $co{'committer_epoch'};
1132 $ref_item{'age'} = $co{'age_string'};
1134 $ref_item{'reftype'} = $type;
1135 $ref_item{'name'} = $ref_file;
1136 $ref_item{'refid'} = $ref_id;
1142 # parse line of git-diff-tree "raw" output
1143 sub parse_difftree_raw_line
{
1147 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1148 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1149 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1150 $res{'from_mode'} = $1;
1151 $res{'to_mode'} = $2;
1152 $res{'from_id'} = $3;
1154 $res{'status'} = $5;
1155 $res{'similarity'} = $6;
1156 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1157 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1159 $res{'file'} = unquote
($7);
1162 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1163 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1164 $res{'commit'} = $1;
1167 return wantarray ?
%res : \
%res;
1170 # parse line of git-ls-tree output
1171 sub parse_ls_tree_line
($;%) {
1176 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1177 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1185 $res{'name'} = unquote
($4);
1188 return wantarray ?
%res : \
%res;
1191 ## ......................................................................
1192 ## parse to array of hashes functions
1194 sub git_get_refs_list
{
1195 my $type = shift || "";
1200 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1202 while (my $line = <$fd>) {
1204 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?([^\^]+))(\^\{\})?$/) {
1205 if (defined $refs{$1}) {
1206 push @
{$refs{$1}}, $2;
1211 if (! $4) { # unpeeled, direct reference
1212 push @refs, { hash
=> $1, name
=> $3 }; # without type
1213 } elsif ($3 eq $refs[-1]{'name'}) {
1214 # most likely a tag is followed by its peeled
1215 # (deref) one, and when that happens we know the
1216 # previous one was of type 'tag'.
1217 $refs[-1]{'type'} = "tag";
1223 foreach my $ref (@refs) {
1224 my $ref_file = $ref->{'name'};
1225 my $ref_id = $ref->{'hash'};
1227 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1228 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1230 push @reflist, \
%ref_item;
1233 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1234 return (\
@reflist, \
%refs);
1237 ## ----------------------------------------------------------------------
1238 ## filesystem-related functions
1240 sub get_file_owner
{
1243 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1244 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1245 if (!defined $gcos) {
1249 $owner =~ s/[,;].*$//;
1250 return to_utf8
($owner);
1253 ## ......................................................................
1254 ## mimetype related functions
1256 sub mimetype_guess_file
{
1257 my $filename = shift;
1258 my $mimemap = shift;
1259 -r
$mimemap or return undef;
1262 open(MIME
, $mimemap) or return undef;
1264 next if m/^#/; # skip comments
1265 my ($mime, $exts) = split(/\t+/);
1266 if (defined $exts) {
1267 my @exts = split(/\s+/, $exts);
1268 foreach my $ext (@exts) {
1269 $mimemap{$ext} = $mime;
1275 $filename =~ /\.([^.]*)$/;
1276 return $mimemap{$1};
1279 sub mimetype_guess
{
1280 my $filename = shift;
1282 $filename =~ /\./ or return undef;
1284 if ($mimetypes_file) {
1285 my $file = $mimetypes_file;
1286 if ($file !~ m!^/!) { # if it is relative path
1287 # it is relative to project
1288 $file = "$projectroot/$project/$file";
1290 $mime = mimetype_guess_file
($filename, $file);
1292 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1298 my $filename = shift;
1301 my $mime = mimetype_guess
($filename);
1302 $mime and return $mime;
1306 return $default_blob_plain_mimetype unless $fd;
1309 return 'text/plain' .
1310 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1311 } elsif (! $filename) {
1312 return 'application/octet-stream';
1313 } elsif ($filename =~ m/\.png$/i) {
1315 } elsif ($filename =~ m/\.gif$/i) {
1317 } elsif ($filename =~ m/\.jpe?g$/i) {
1318 return 'image/jpeg';
1320 return 'application/octet-stream';
1324 ## ======================================================================
1325 ## functions printing HTML: header, footer, error page
1327 sub git_header_html
{
1328 my $status = shift || "200 OK";
1329 my $expires = shift;
1331 my $title = "$site_name git";
1332 if (defined $project) {
1333 $title .= " - $project";
1334 if (defined $action) {
1335 $title .= "/$action";
1336 if (defined $file_name) {
1337 $title .= " - " . esc_html
($file_name);
1338 if ($action eq "tree" && $file_name !~ m
|/$|) {
1345 # require explicit support from the UA if we are to send the page as
1346 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1347 # we have to do this because MSIE sometimes globs '*/*', pretending to
1348 # support xhtml+xml but choking when it gets what it asked for.
1349 if (defined $cgi->http('HTTP_ACCEPT') &&
1350 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1351 $cgi->Accept('application/xhtml+xml') != 0) {
1352 $content_type = 'application/xhtml+xml';
1354 $content_type = 'text/html';
1356 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1357 -status
=> $status, -expires
=> $expires);
1359 <?xml version="1.0" encoding="utf-8"?>
1360 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1361 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1362 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1363 <!-- git core binaries version $git_version -->
1365 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1366 <meta name="generator" content="gitweb/$version git/$git_version"/>
1367 <meta name="robots" content="index, nofollow"/>
1368 <title>$title</title>
1369 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1371 if (defined $project) {
1372 printf('<link rel="alternate" title="%s log" '.
1373 'href="%s" type="application/rss+xml"/>'."\n",
1374 esc_param
($project), href
(action
=>"rss"));
1376 printf('<link rel="alternate" title="%s projects list" '.
1377 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1378 $site_name, href
(project
=>undef, action
=>"project_index"));
1379 printf('<link rel="alternate" title="%s projects logs" '.
1380 'href="%s" type="text/x-opml"/>'."\n",
1381 $site_name, href
(project
=>undef, action
=>"opml"));
1383 if (defined $favicon) {
1384 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1389 "<div class=\"page_header\">\n" .
1390 $cgi->a({-href
=> esc_url
($logo_url),
1391 -title
=> $logo_label},
1392 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
1393 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1394 if (defined $project) {
1395 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1396 if (defined $action) {
1400 if (!defined $searchtext) {
1404 if (defined $hash_base) {
1405 $search_hash = $hash_base;
1406 } elsif (defined $hash) {
1407 $search_hash = $hash;
1409 $search_hash = "HEAD";
1411 $cgi->param("a", "search");
1412 $cgi->param("h", $search_hash);
1413 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1414 "<div class=\"search\">\n" .
1415 $cgi->hidden(-name
=> "p") . "\n" .
1416 $cgi->hidden(-name
=> "a") . "\n" .
1417 $cgi->hidden(-name
=> "h") . "\n" .
1418 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1420 $cgi->end_form() . "\n";
1425 sub git_footer_html
{
1426 print "<div class=\"page_footer\">\n";
1427 if (defined $project) {
1428 my $descr = git_get_project_description
($project);
1429 if (defined $descr) {
1430 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1432 print $cgi->a({-href
=> href
(action
=>"rss"),
1433 -class => "rss_logo"}, "RSS") . "\n";
1435 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1436 -class => "rss_logo"}, "OPML") . " ";
1437 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1438 -class => "rss_logo"}, "TXT") . "\n";
1446 my $status = shift || "403 Forbidden";
1447 my $error = shift || "Malformed query, file missing or permission denied";
1449 git_header_html
($status);
1451 <div class="page_body">
1461 ## ----------------------------------------------------------------------
1462 ## functions printing or outputting HTML: navigation
1464 sub git_print_page_nav
{
1465 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1466 $extra = '' if !defined $extra; # pager or formats
1468 my @navs = qw(summary shortlog log commit commitdiff tree);
1470 @navs = grep { $_ ne $suppress } @navs;
1473 my %arg = map { $_ => {action
=>$_} } @navs;
1474 if (defined $head) {
1475 for (qw(commit commitdiff)) {
1476 $arg{$_}{hash
} = $head;
1478 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1479 for (qw(shortlog log)) {
1480 $arg{$_}{hash
} = $head;
1484 $arg{tree
}{hash
} = $treehead if defined $treehead;
1485 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1487 print "<div class=\"page_nav\">\n" .
1489 map { $_ eq $current ?
1490 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1492 print "<br/>\n$extra<br/>\n" .
1496 sub format_paging_nav
{
1497 my ($action, $hash, $head, $page, $nrevs) = @_;
1501 if ($hash ne $head || $page) {
1502 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1504 $paging_nav .= "HEAD";
1508 $paging_nav .= " ⋅ " .
1509 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1510 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1512 $paging_nav .= " ⋅ prev";
1515 if ($nrevs >= (100 * ($page+1)-1)) {
1516 $paging_nav .= " ⋅ " .
1517 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1518 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1520 $paging_nav .= " ⋅ next";
1526 ## ......................................................................
1527 ## functions printing or outputting HTML: div
1529 sub git_print_header_div
{
1530 my ($action, $title, $hash, $hash_base) = @_;
1533 $args{action
} = $action;
1534 $args{hash
} = $hash if $hash;
1535 $args{hash_base
} = $hash_base if $hash_base;
1537 print "<div class=\"header\">\n" .
1538 $cgi->a({-href
=> href
(%args), -class => "title"},
1539 $title ?
$title : $action) .
1543 #sub git_print_authorship (\%) {
1544 sub git_print_authorship
{
1547 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1548 print "<div class=\"author_date\">" .
1549 esc_html
($co->{'author_name'}) .
1551 if ($ad{'hour_local'} < 6) {
1552 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1553 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1555 printf(" (%02d:%02d %s)",
1556 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1561 sub git_print_page_path
{
1566 if (!defined $name) {
1567 print "<div class=\"page_path\">/</div>\n";
1569 my @dirname = split '/', $name;
1570 my $basename = pop @dirname;
1573 print "<div class=\"page_path\">";
1574 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1575 -title
=> 'tree root'}, "[$project]");
1577 foreach my $dir (@dirname) {
1578 $fullname .= ($fullname ?
'/' : '') . $dir;
1579 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1581 -title
=> $fullname}, esc_html
($dir));
1584 if (defined $type && $type eq 'blob') {
1585 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1587 -title
=> $name}, esc_html
($basename));
1588 } elsif (defined $type && $type eq 'tree') {
1589 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1591 -title
=> $name}, esc_html
($basename));
1593 print esc_html
($basename);
1595 print "<br/></div>\n";
1599 # sub git_print_log (\@;%) {
1600 sub git_print_log
($;%) {
1604 if ($opts{'-remove_title'}) {
1605 # remove title, i.e. first line of log
1608 # remove leading empty lines
1609 while (defined $log->[0] && $log->[0] eq "") {
1616 foreach my $line (@
$log) {
1617 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1620 if (! $opts{'-remove_signoff'}) {
1621 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1624 # remove signoff lines
1631 # print only one empty line
1632 # do not print empty line after signoff
1634 next if ($empty || $signoff);
1640 print format_log_line_html
($line) . "<br/>\n";
1643 if ($opts{'-final_empty_line'}) {
1644 # end with single empty line
1645 print "<br/>\n" unless $empty;
1649 sub git_print_simplified_log
{
1651 my $remove_title = shift;
1654 -final_empty_line
=> 1,
1655 -remove_title
=> $remove_title);
1658 # print tree entry (row of git_tree), but without encompassing <tr> element
1659 sub git_print_tree_entry
{
1660 my ($t, $basedir, $hash_base, $have_blame) = @_;
1663 $base_key{hash_base
} = $hash_base if defined $hash_base;
1665 # The format of a table row is: mode list link. Where mode is
1666 # the mode of the entry, list is the name of the entry, an href,
1667 # and link is the action links of the entry.
1669 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1670 if ($t->{'type'} eq "blob") {
1671 print "<td class=\"list\">" .
1672 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1673 file_name
=>"$basedir$t->{'name'}", %base_key),
1674 -class => "list"}, esc_html
($t->{'name'})) . "</td>\n";
1675 print "<td class=\"link\">";
1677 print $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1678 file_name
=>"$basedir$t->{'name'}", %base_key)},
1681 if (defined $hash_base) {
1685 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1686 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1690 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
1691 file_name
=>"$basedir$t->{'name'}")},
1695 } elsif ($t->{'type'} eq "tree") {
1696 print "<td class=\"list\">";
1697 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1698 file_name
=>"$basedir$t->{'name'}", %base_key)},
1699 esc_html
($t->{'name'}));
1701 print "<td class=\"link\">";
1702 if (defined $hash_base) {
1703 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1704 file_name
=>"$basedir$t->{'name'}")},
1711 ## ......................................................................
1712 ## functions printing large fragments of HTML
1714 sub git_difftree_body
{
1715 my ($difftree, $hash, $parent) = @_;
1717 print "<div class=\"list_head\">\n";
1718 if ($#{$difftree} > 10) {
1719 print(($#{$difftree} + 1) . " files changed:\n");
1723 print "<table class=\"diff_tree\">\n";
1726 foreach my $line (@
{$difftree}) {
1727 my %diff = parse_difftree_raw_line
($line);
1730 print "<tr class=\"dark\">\n";
1732 print "<tr class=\"light\">\n";
1736 my ($to_mode_oct, $to_mode_str, $to_file_type);
1737 my ($from_mode_oct, $from_mode_str, $from_file_type);
1738 if ($diff{'to_mode'} ne ('0' x
6)) {
1739 $to_mode_oct = oct $diff{'to_mode'};
1740 if (S_ISREG
($to_mode_oct)) { # only for regular file
1741 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1743 $to_file_type = file_type
($diff{'to_mode'});
1745 if ($diff{'from_mode'} ne ('0' x
6)) {
1746 $from_mode_oct = oct $diff{'from_mode'};
1747 if (S_ISREG
($to_mode_oct)) { # only for regular file
1748 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1750 $from_file_type = file_type
($diff{'from_mode'});
1753 if ($diff{'status'} eq "A") { # created
1754 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1755 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1756 $mode_chng .= "]</span>";
1758 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1759 hash_base
=>$hash, file_name
=>$diff{'file'}),
1760 -class => "list"}, esc_html
($diff{'file'}));
1762 print "<td>$mode_chng</td>\n";
1763 print "<td class=\"link\">";
1764 if ($action eq 'commitdiff') {
1767 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1771 } elsif ($diff{'status'} eq "D") { # deleted
1772 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1774 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1775 hash_base
=>$parent, file_name
=>$diff{'file'}),
1776 -class => "list"}, esc_html
($diff{'file'}));
1778 print "<td>$mode_chng</td>\n";
1779 print "<td class=\"link\">";
1780 if ($action eq 'commitdiff') {
1783 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1786 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1787 file_name
=>$diff{'file'})},
1789 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1790 file_name
=>$diff{'file'})},
1794 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1795 my $mode_chnge = "";
1796 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1797 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1798 if ($from_file_type != $to_file_type) {
1799 $mode_chnge .= " from $from_file_type to $to_file_type";
1801 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1802 if ($from_mode_str && $to_mode_str) {
1803 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1804 } elsif ($to_mode_str) {
1805 $mode_chnge .= " mode: $to_mode_str";
1808 $mode_chnge .= "]</span>\n";
1811 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1812 hash_base
=>$hash, file_name
=>$diff{'file'}),
1813 -class => "list"}, esc_html
($diff{'file'}));
1815 print "<td>$mode_chnge</td>\n";
1816 print "<td class=\"link\">";
1817 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1818 if ($action eq 'commitdiff') {
1821 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1823 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1824 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1825 hash_base
=>$hash, hash_parent_base
=>$parent,
1826 file_name
=>$diff{'file'})},
1831 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
1832 file_name
=>$diff{'file'})},
1834 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
1835 file_name
=>$diff{'file'})},
1839 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1840 my %status_name = ('R' => 'moved', 'C' => 'copied');
1841 my $nstatus = $status_name{$diff{'status'}};
1843 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1844 # mode also for directories, so we cannot use $to_mode_str
1845 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1848 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1849 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1850 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1851 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1852 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1853 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1854 -class => "list"}, esc_html
($diff{'from_file'})) .
1855 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1856 "<td class=\"link\">";
1857 if ($diff{'to_id'} ne $diff{'from_id'}) {
1858 if ($action eq 'commitdiff') {
1861 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
1863 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1864 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1865 hash_base
=>$hash, hash_parent_base
=>$parent,
1866 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1871 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
1872 file_name
=>$diff{'from_file'})},
1874 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1875 file_name
=>$diff{'from_file'})},
1879 } # we should not encounter Unmerged (U) or Unknown (X) status
1885 sub git_patchset_body
{
1886 my ($fd, $difftree, $hash, $hash_parent) = @_;
1890 my $patch_found = 0;
1893 print "<div class=\"patchset\">\n";
1896 while (my $patch_line = <$fd>) {
1899 if ($patch_line =~ m/^diff /) { # "git diff" header
1900 # beginning of patch (in patchset)
1902 # close previous patch
1903 print "</div>\n"; # class="patch"
1905 # first patch in patchset
1908 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1910 if (ref($difftree->[$patch_idx]) eq "HASH") {
1911 $diffinfo = $difftree->[$patch_idx];
1913 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1917 # for now, no extended header, hence we skip empty patches
1918 # companion to next LINE if $in_header;
1919 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1924 if ($diffinfo->{'status'} eq "A") { # added
1925 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1926 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1927 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1928 $diffinfo->{'to_id'}) . " (new)" .
1929 "</div>\n"; # class="diff_info"
1931 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1932 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1933 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1934 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1935 $diffinfo->{'from_id'}) . " (deleted)" .
1936 "</div>\n"; # class="diff_info"
1938 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1939 $diffinfo->{'status'} eq "C" || # copied
1940 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1941 print "<div class=\"diff_info\">" .
1942 file_type
($diffinfo->{'from_mode'}) . ":" .
1943 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1944 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1945 $diffinfo->{'from_id'}) .
1947 file_type
($diffinfo->{'to_mode'}) . ":" .
1948 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1949 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1950 $diffinfo->{'to_id'});
1951 print "</div>\n"; # class="diff_info"
1953 } else { # modified, mode changed, ...
1954 print "<div class=\"diff_info\">" .
1955 file_type
($diffinfo->{'from_mode'}) . ":" .
1956 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1957 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1958 $diffinfo->{'from_id'}) .
1960 file_type
($diffinfo->{'to_mode'}) . ":" .
1961 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1962 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1963 $diffinfo->{'to_id'});
1964 print "</div>\n"; # class="diff_info"
1967 #print "<div class=\"diff extended_header\">\n";
1970 } # start of patch in patchset
1973 if ($in_header && $patch_line =~ m/^---/) {
1974 #print "</div>\n"; # class="diff extended_header"
1977 my $file = $diffinfo->{'from_file'};
1978 $file ||= $diffinfo->{'file'};
1979 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1980 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
1981 -class => "list"}, esc_html
($file));
1982 $patch_line =~ s
|a
/.*$|a/$file|g
;
1983 print "<div class=\"diff from_file\">$patch_line</div>\n";
1985 $patch_line = <$fd>;
1988 #$patch_line =~ m/^+++/;
1989 $file = $diffinfo->{'to_file'};
1990 $file ||= $diffinfo->{'file'};
1991 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1992 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
1993 -class => "list"}, esc_html
($file));
1994 $patch_line =~ s
|b
/.*|b/$file|g
;
1995 print "<div class=\"diff to_file\">$patch_line</div>\n";
1999 next LINE
if $in_header;
2001 print format_diff_line
($patch_line);
2003 print "</div>\n" if $patch_found; # class="patch"
2005 print "</div>\n"; # class="patchset"
2008 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2010 sub git_shortlog_body
{
2011 # uses global variable $project
2012 my ($revlist, $from, $to, $refs, $extra) = @_;
2014 $from = 0 unless defined $from;
2015 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2017 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2019 for (my $i = $from; $i <= $to; $i++) {
2020 my $commit = $revlist->[$i];
2021 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2022 my $ref = format_ref_marker
($refs, $commit);
2023 my %co = parse_commit
($commit);
2025 print "<tr class=\"dark\">\n";
2027 print "<tr class=\"light\">\n";
2030 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2031 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2032 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2034 print format_subject_html
($co{'title'}, $co{'title_short'},
2035 href
(action
=>"commit", hash
=>$commit), $ref);
2037 "<td class=\"link\">" .
2038 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2039 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2040 if (gitweb_have_snapshot
()) {
2041 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2046 if (defined $extra) {
2048 "<td colspan=\"4\">$extra</td>\n" .
2054 sub git_history_body
{
2055 # Warning: assumes constant type (blob or tree) during history
2056 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2058 $from = 0 unless defined $from;
2059 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2061 print "<table class=\"history\" cellspacing=\"0\">\n";
2063 for (my $i = $from; $i <= $to; $i++) {
2064 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2069 my %co = parse_commit
($commit);
2074 my $ref = format_ref_marker
($refs, $commit);
2077 print "<tr class=\"dark\">\n";
2079 print "<tr class=\"light\">\n";
2082 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2083 # shortlog uses chop_str($co{'author_name'}, 10)
2084 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2086 # originally git_history used chop_str($co{'title'}, 50)
2087 print format_subject_html
($co{'title'}, $co{'title_short'},
2088 href
(action
=>"commit", hash
=>$commit), $ref);
2090 "<td class=\"link\">" .
2091 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2092 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2094 if ($ftype eq 'blob') {
2095 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2096 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2097 if (defined $blob_current && defined $blob_parent &&
2098 $blob_current ne $blob_parent) {
2100 $cgi->a({-href
=> href
(action
=>"blobdiff",
2101 hash
=>$blob_current, hash_parent
=>$blob_parent,
2102 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2103 file_name
=>$file_name)},
2110 if (defined $extra) {
2112 "<td colspan=\"4\">$extra</td>\n" .
2119 # uses global variable $project
2120 my ($taglist, $from, $to, $extra) = @_;
2121 $from = 0 unless defined $from;
2122 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2124 print "<table class=\"tags\" cellspacing=\"0\">\n";
2126 for (my $i = $from; $i <= $to; $i++) {
2127 my $entry = $taglist->[$i];
2129 my $comment_lines = $tag{'comment'};
2130 my $comment = shift @
$comment_lines;
2132 if (defined $comment) {
2133 $comment_short = chop_str
($comment, 30, 5);
2136 print "<tr class=\"dark\">\n";
2138 print "<tr class=\"light\">\n";
2141 print "<td><i>$tag{'age'}</i></td>\n" .
2143 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2144 -class => "list name"}, esc_html
($tag{'name'})) .
2147 if (defined $comment) {
2148 print format_subject_html
($comment, $comment_short,
2149 href
(action
=>"tag", hash
=>$tag{'id'}));
2152 "<td class=\"selflink\">";
2153 if ($tag{'type'} eq "tag") {
2154 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2159 "<td class=\"link\">" . " | " .
2160 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2161 if ($tag{'reftype'} eq "commit") {
2162 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2163 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2164 } elsif ($tag{'reftype'} eq "blob") {
2165 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2170 if (defined $extra) {
2172 "<td colspan=\"5\">$extra</td>\n" .
2178 sub git_heads_body
{
2179 # uses global variable $project
2180 my ($headlist, $head, $from, $to, $extra) = @_;
2181 $from = 0 unless defined $from;
2182 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2184 print "<table class=\"heads\" cellspacing=\"0\">\n";
2186 for (my $i = $from; $i <= $to; $i++) {
2187 my $entry = $headlist->[$i];
2189 my $curr = $tag{'id'} eq $head;
2191 print "<tr class=\"dark\">\n";
2193 print "<tr class=\"light\">\n";
2196 print "<td><i>$tag{'age'}</i></td>\n" .
2197 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
2198 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2199 -class => "list name"},esc_html
($tag{'name'})) .
2201 "<td class=\"link\">" .
2202 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2203 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") . " | " .
2204 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$tag{'name'}, hash_base
=>$tag{'name'})}, "tree") .
2208 if (defined $extra) {
2210 "<td colspan=\"3\">$extra</td>\n" .
2216 ## ======================================================================
2217 ## ======================================================================
2220 sub git_project_list
{
2221 my $order = $cgi->param('o');
2222 if (defined $order && $order !~ m/project|descr|owner|age/) {
2223 die_error
(undef, "Unknown order parameter");
2226 my @list = git_get_projects_list
();
2229 die_error
(undef, "No projects found");
2231 foreach my $pr (@list) {
2232 my $head = git_get_head_hash
($pr->{'path'});
2233 if (!defined $head) {
2236 $git_dir = "$projectroot/$pr->{'path'}";
2237 my %co = parse_commit
($head);
2241 $pr->{'commit'} = \
%co;
2242 if (!defined $pr->{'descr'}) {
2243 my $descr = git_get_project_description
($pr->{'path'}) || "";
2244 $pr->{'descr'} = chop_str
($descr, 25, 5);
2246 if (!defined $pr->{'owner'}) {
2247 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2249 push @projects, $pr;
2253 if (-f
$home_text) {
2254 print "<div class=\"index_include\">\n";
2255 open (my $fd, $home_text);
2260 print "<table class=\"project_list\">\n" .
2262 $order ||= "project";
2263 if ($order eq "project") {
2264 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2265 print "<th>Project</th>\n";
2268 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2269 -class => "header"}, "Project") .
2272 if ($order eq "descr") {
2273 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2274 print "<th>Description</th>\n";
2277 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2278 -class => "header"}, "Description") .
2281 if ($order eq "owner") {
2282 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2283 print "<th>Owner</th>\n";
2286 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2287 -class => "header"}, "Owner") .
2290 if ($order eq "age") {
2291 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2292 print "<th>Last Change</th>\n";
2295 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2296 -class => "header"}, "Last Change") .
2299 print "<th></th>\n" .
2302 foreach my $pr (@projects) {
2304 print "<tr class=\"dark\">\n";
2306 print "<tr class=\"light\">\n";
2309 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2310 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2311 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2312 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2313 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2314 $pr->{'commit'}{'age_string'} . "</td>\n" .
2315 "<td class=\"link\">" .
2316 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2317 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2318 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2319 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2327 sub git_project_index
{
2328 my @projects = git_get_projects_list
();
2331 -type
=> 'text/plain',
2332 -charset
=> 'utf-8',
2333 -content_disposition
=> 'inline; filename="index.aux"');
2335 foreach my $pr (@projects) {
2336 if (!exists $pr->{'owner'}) {
2337 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2340 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2341 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2342 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2343 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2347 print "$path $owner\n";
2352 my $descr = git_get_project_description
($project) || "none";
2353 my $head = git_get_head_hash
($project);
2354 my %co = parse_commit
($head);
2355 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2357 my $owner = git_get_project_owner
($project);
2359 my ($reflist, $refs) = git_get_refs_list
();
2363 foreach my $ref (@
$reflist) {
2364 if ($ref->{'name'} =~ s!^heads/!!) {
2365 push @headlist, $ref;
2367 $ref->{'name'} =~ s!^tags/!!;
2368 push @taglist, $ref;
2373 git_print_page_nav
('summary','', $head);
2375 print "<div class=\"title\"> </div>\n";
2376 print "<table cellspacing=\"0\">\n" .
2377 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2378 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2379 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2380 # use per project git URL list in $projectroot/$project/cloneurl
2381 # or make project git URL from git base URL and project name
2382 my $url_tag = "URL";
2383 my @url_list = git_get_project_url_list
($project);
2384 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2385 foreach my $git_url (@url_list) {
2386 next unless $git_url;
2387 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2392 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2393 git_get_head_hash
($project)
2394 or die_error
(undef, "Open git-rev-list failed");
2395 my @revlist = map { chomp; $_ } <$fd>;
2397 git_print_header_div
('shortlog');
2398 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2399 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2402 git_print_header_div
('tags');
2403 git_tags_body
(\
@taglist, 0, 15,
2404 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2408 git_print_header_div
('heads');
2409 git_heads_body
(\
@headlist, $head, 0, 15,
2410 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2417 my $head = git_get_head_hash
($project);
2419 git_print_page_nav
('','', $head,undef,$head);
2420 my %tag = parse_tag
($hash);
2421 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2422 print "<div class=\"title_text\">\n" .
2423 "<table cellspacing=\"0\">\n" .
2425 "<td>object</td>\n" .
2426 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2427 $tag{'object'}) . "</td>\n" .
2428 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2429 $tag{'type'}) . "</td>\n" .
2431 if (defined($tag{'author'})) {
2432 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2433 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2434 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2435 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2438 print "</table>\n\n" .
2440 print "<div class=\"page_body\">";
2441 my $comment = $tag{'comment'};
2442 foreach my $line (@
$comment) {
2443 print esc_html
($line) . "<br/>\n";
2453 my ($have_blame) = gitweb_check_feature
('blame');
2455 die_error
('403 Permission denied', "Permission denied");
2457 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2458 $hash_base ||= git_get_head_hash
($project);
2459 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2460 my %co = parse_commit
($hash_base)
2461 or die_error
(undef, "Reading commit failed");
2462 if (!defined $hash) {
2463 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2464 or die_error
(undef, "Error looking up file");
2466 $ftype = git_get_type
($hash);
2467 if ($ftype !~ "blob") {
2468 die_error
("400 Bad Request", "Object is not a blob");
2470 open ($fd, "-|", git_cmd
(), "blame", '-l', '--', $file_name, $hash_base)
2471 or die_error
(undef, "Open git-blame failed");
2474 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2477 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2480 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2482 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2483 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2484 git_print_page_path
($file_name, $ftype, $hash_base);
2485 my @rev_color = (qw(light2 dark2));
2486 my $num_colors = scalar(@rev_color);
2487 my $current_color = 0;
2490 <div class="page_body">
2491 <table class="blame">
2492 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2495 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2497 my $rev = substr($full_rev, 0, 8);
2501 if (!defined $last_rev) {
2502 $last_rev = $full_rev;
2503 } elsif ($last_rev ne $full_rev) {
2504 $last_rev = $full_rev;
2505 $current_color = ++$current_color % $num_colors;
2507 print "<tr class=\"$rev_color[$current_color]\">\n";
2508 print "<td class=\"sha1\">" .
2509 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2510 esc_html
($rev)) . "</td>\n";
2511 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2512 esc_html
($lineno) . "</a></td>\n";
2513 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2519 or print "Reading blob failed\n";
2526 my ($have_blame) = gitweb_check_feature
('blame');
2528 die_error
('403 Permission denied', "Permission denied");
2530 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2531 $hash_base ||= git_get_head_hash
($project);
2532 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2533 my %co = parse_commit
($hash_base)
2534 or die_error
(undef, "Reading commit failed");
2535 if (!defined $hash) {
2536 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2537 or die_error
(undef, "Error lookup file");
2539 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2540 or die_error
(undef, "Open git-annotate failed");
2543 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2546 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2549 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2551 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2552 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2553 git_print_page_path
($file_name, 'blob', $hash_base);
2554 print "<div class=\"page_body\">\n";
2556 <table class="blame">
2565 my @line_class = (qw(light dark));
2566 my $line_class_len = scalar (@line_class);
2567 my $line_class_num = $#line_class;
2568 while (my $line = <$fd>) {
2580 $line_class_num = ($line_class_num + 1) % $line_class_len;
2582 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2589 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2592 $short_rev = substr ($long_rev, 0, 8);
2593 $age = time () - $time;
2594 $age_str = age_string
($age);
2595 $age_str =~ s/ / /g;
2596 $age_class = age_class
($age);
2597 $author = esc_html
($author);
2598 $author =~ s/ / /g;
2600 $data = untabify
($data);
2601 $data = esc_html
($data);
2604 <tr class="$line_class[$line_class_num]">
2605 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2606 <td class="$age_class">$age_str</td>
2608 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2609 <td class="pre">$data</td>
2612 } # while (my $line = <$fd>)
2613 print "</table>\n\n";
2615 or print "Reading blob failed.\n";
2621 my $head = git_get_head_hash
($project);
2623 git_print_page_nav
('','', $head,undef,$head);
2624 git_print_header_div
('summary', $project);
2626 my ($taglist) = git_get_refs_list
("tags");
2628 git_tags_body
($taglist);
2634 my $head = git_get_head_hash
($project);
2636 git_print_page_nav
('','', $head,undef,$head);
2637 git_print_header_div
('summary', $project);
2639 my ($headlist) = git_get_refs_list
("heads");
2641 git_heads_body
($headlist, $head);
2646 sub git_blob_plain
{
2649 if (!defined $hash) {
2650 if (defined $file_name) {
2651 my $base = $hash_base || git_get_head_hash
($project);
2652 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2653 or die_error
(undef, "Error lookup file");
2655 die_error
(undef, "No file name defined");
2657 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2658 # blobs defined by non-textual hash id's can be cached
2663 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2664 or die_error
(undef, "Couldn't cat $file_name, $hash");
2666 $type ||= blob_mimetype
($fd, $file_name);
2668 # save as filename, even when no $file_name is given
2669 my $save_as = "$hash";
2670 if (defined $file_name) {
2671 $save_as = $file_name;
2672 } elsif ($type =~ m/^text\//) {
2679 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
2681 binmode STDOUT
, ':raw';
2683 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2691 if (!defined $hash) {
2692 if (defined $file_name) {
2693 my $base = $hash_base || git_get_head_hash
($project);
2694 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2695 or die_error
(undef, "Error lookup file");
2697 die_error
(undef, "No file name defined");
2699 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2700 # blobs defined by non-textual hash id's can be cached
2704 my ($have_blame) = gitweb_check_feature
('blame');
2705 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2706 or die_error
(undef, "Couldn't cat $file_name, $hash");
2707 my $mimetype = blob_mimetype
($fd, $file_name);
2708 if ($mimetype !~ m/^text\//) {
2710 return git_blob_plain
($mimetype);
2712 git_header_html
(undef, $expires);
2713 my $formats_nav = '';
2714 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2715 if (defined $file_name) {
2718 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2719 hash
=>$hash, file_name
=>$file_name)},
2724 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2725 hash
=>$hash, file_name
=>$file_name)},
2728 $cgi->a({-href
=> href
(action
=>"blob_plain",
2729 hash
=>$hash, file_name
=>$file_name)},
2732 $cgi->a({-href
=> href
(action
=>"blob",
2733 hash_base
=>"HEAD", file_name
=>$file_name)},
2737 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
2739 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2740 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2742 print "<div class=\"page_nav\">\n" .
2743 "<br/><br/></div>\n" .
2744 "<div class=\"title\">$hash</div>\n";
2746 git_print_page_path
($file_name, "blob", $hash_base);
2747 print "<div class=\"page_body\">\n";
2749 while (my $line = <$fd>) {
2752 $line = untabify
($line);
2753 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2754 $nr, $nr, $nr, esc_html
($line);
2757 or print "Reading blob failed.\n";
2763 my $have_snapshot = gitweb_have_snapshot
();
2765 if (!defined $hash_base) {
2766 $hash_base = "HEAD";
2768 if (!defined $hash) {
2769 if (defined $file_name) {
2770 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
2776 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2777 or die_error
(undef, "Open git-ls-tree failed");
2778 my @entries = map { chomp; $_ } <$fd>;
2779 close $fd or die_error
(undef, "Reading tree failed");
2782 my $refs = git_get_references
();
2783 my $ref = format_ref_marker
($refs, $hash_base);
2786 my ($have_blame) = gitweb_check_feature
('blame');
2787 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2789 if (defined $file_name) {
2791 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2792 hash
=>$hash, file_name
=>$file_name)},
2794 $cgi->a({-href
=> href
(action
=>"tree",
2795 hash_base
=>"HEAD", file_name
=>$file_name)},
2798 if ($have_snapshot) {
2799 # FIXME: Should be available when we have no hash base as well.
2801 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
2804 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
2805 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2808 print "<div class=\"page_nav\">\n";
2809 print "<br/><br/></div>\n";
2810 print "<div class=\"title\">$hash</div>\n";
2812 if (defined $file_name) {
2813 $basedir = $file_name;
2814 if ($basedir ne '' && substr($basedir, -1) ne '/') {
2818 git_print_page_path
($file_name, 'tree', $hash_base);
2819 print "<div class=\"page_body\">\n";
2820 print "<table cellspacing=\"0\">\n";
2822 foreach my $line (@entries) {
2823 my %t = parse_ls_tree_line
($line, -z
=> 1);
2826 print "<tr class=\"dark\">\n";
2828 print "<tr class=\"light\">\n";
2832 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
2836 print "</table>\n" .
2842 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2843 my $have_snapshot = (defined $ctype && defined $suffix);
2844 if (!$have_snapshot) {
2845 die_error
('403 Permission denied', "Permission denied");
2848 if (!defined $hash) {
2849 $hash = git_get_head_hash
($project);
2852 my $filename = basename
($project) . "-$hash.tar.$suffix";
2855 -type
=> 'application/x-tar',
2856 -content_encoding
=> $ctype,
2857 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
2858 -status
=> '200 OK');
2860 my $git = git_cmd_str
();
2861 my $name = $project;
2862 $name =~ s/\047/\047\\\047\047/g;
2864 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
2865 or die_error
(undef, "Execute git-tar-tree failed.");
2866 binmode STDOUT
, ':raw';
2868 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2874 my $head = git_get_head_hash
($project);
2875 if (!defined $hash) {
2878 if (!defined $page) {
2881 my $refs = git_get_references
();
2883 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2884 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2885 or die_error
(undef, "Open git-rev-list failed");
2886 my @revlist = map { chomp; $_ } <$fd>;
2889 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2892 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2895 my %co = parse_commit
($hash);
2897 git_print_header_div
('summary', $project);
2898 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2900 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2901 my $commit = $revlist[$i];
2902 my $ref = format_ref_marker
($refs, $commit);
2903 my %co = parse_commit
($commit);
2905 my %ad = parse_date
($co{'author_epoch'});
2906 git_print_header_div
('commit',
2907 "<span class=\"age\">$co{'age_string'}</span>" .
2908 esc_html
($co{'title'}) . $ref,
2910 print "<div class=\"title_text\">\n" .
2911 "<div class=\"log_link\">\n" .
2912 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2914 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2916 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
2919 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2922 print "<div class=\"log_body\">\n";
2923 git_print_simplified_log
($co{'comment'});
2930 my %co = parse_commit
($hash);
2932 die_error
(undef, "Unknown commit object");
2934 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2935 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2937 my $parent = $co{'parent'};
2938 if (!defined $parent) {
2941 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
2942 or die_error
(undef, "Open git-diff-tree failed");
2943 my @difftree = map { chomp; $_ } <$fd>;
2944 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2946 # non-textual hash id's can be cached
2948 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2951 my $refs = git_get_references
();
2952 my $ref = format_ref_marker
($refs, $co{'id'});
2954 my $have_snapshot = gitweb_have_snapshot
();
2957 if (defined $file_name && defined $co{'parent'}) {
2959 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2962 git_header_html
(undef, $expires);
2963 git_print_page_nav
('commit', '',
2964 $hash, $co{'tree'}, $hash,
2965 join (' | ', @views_nav));
2967 if (defined $co{'parent'}) {
2968 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2970 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2972 print "<div class=\"title_text\">\n" .
2973 "<table cellspacing=\"0\">\n";
2974 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2976 "<td></td><td> $ad{'rfc2822'}";
2977 if ($ad{'hour_local'} < 6) {
2978 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2979 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2981 printf(" (%02d:%02d %s)",
2982 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2986 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2987 print "<tr><td></td><td> $cd{'rfc2822'}" .
2988 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2990 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2993 "<td class=\"sha1\">" .
2994 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2995 class => "list"}, $co{'tree'}) .
2997 "<td class=\"link\">" .
2998 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3000 if ($have_snapshot) {
3002 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3006 my $parents = $co{'parents'};
3007 foreach my $par (@
$parents) {
3010 "<td class=\"sha1\">" .
3011 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3012 class => "list"}, $par) .
3014 "<td class=\"link\">" .
3015 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3017 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3024 print "<div class=\"page_body\">\n";
3025 git_print_log
($co{'comment'});
3028 git_difftree_body
(\
@difftree, $hash, $parent);
3034 my $format = shift || 'html';
3041 # preparing $fd and %diffinfo for git_patchset_body
3043 if (defined $hash_base && defined $hash_parent_base) {
3044 if (defined $file_name) {
3046 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
3048 or die_error
(undef, "Open git-diff-tree failed");
3049 @difftree = map { chomp; $_ } <$fd>;
3051 or die_error
(undef, "Reading git-diff-tree failed");
3053 or die_error
('404 Not Found', "Blob diff not found");
3055 } elsif (defined $hash &&
3056 $hash =~ /[0-9a-fA-F]{40}/) {
3057 # try to find filename from $hash
3059 # read filtered raw output
3060 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
3061 or die_error
(undef, "Open git-diff-tree failed");
3063 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3065 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3066 map { chomp; $_ } <$fd>;
3068 or die_error
(undef, "Reading git-diff-tree failed");
3070 or die_error
('404 Not Found', "Blob diff not found");
3073 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3076 if (@difftree > 1) {
3077 die_error
('404 Not Found', "Ambiguous blob diff specification");
3080 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3081 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3082 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3084 $hash_parent ||= $diffinfo{'from_id'};
3085 $hash ||= $diffinfo{'to_id'};
3087 # non-textual hash id's can be cached
3088 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3089 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3094 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3095 '-p', $hash_parent_base, $hash_base,
3097 or die_error
(undef, "Open git-diff-tree failed");
3100 # old/legacy style URI
3101 if (!%diffinfo && # if new style URI failed
3102 defined $hash && defined $hash_parent) {
3103 # fake git-diff-tree raw output
3104 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3105 $diffinfo{'from_id'} = $hash_parent;
3106 $diffinfo{'to_id'} = $hash;
3107 if (defined $file_name) {
3108 if (defined $file_parent) {
3109 $diffinfo{'status'} = '2';
3110 $diffinfo{'from_file'} = $file_parent;
3111 $diffinfo{'to_file'} = $file_name;
3112 } else { # assume not renamed
3113 $diffinfo{'status'} = '1';
3114 $diffinfo{'from_file'} = $file_name;
3115 $diffinfo{'to_file'} = $file_name;
3117 } else { # no filename given
3118 $diffinfo{'status'} = '2';
3119 $diffinfo{'from_file'} = $hash_parent;
3120 $diffinfo{'to_file'} = $hash;
3123 # non-textual hash id's can be cached
3124 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3125 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3130 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
3131 or die_error
(undef, "Open git-diff failed");
3133 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3138 if ($format eq 'html') {
3140 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3141 hash
=>$hash, hash_parent
=>$hash_parent,
3142 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3143 file_name
=>$file_name, file_parent
=>$file_parent)},
3145 git_header_html
(undef, $expires);
3146 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3147 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3148 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3150 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3151 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3153 if (defined $file_name) {
3154 git_print_page_path
($file_name, "blob", $hash_base);
3156 print "<div class=\"page_path\"></div>\n";
3159 } elsif ($format eq 'plain') {
3161 -type
=> 'text/plain',
3162 -charset
=> 'utf-8',
3163 -expires
=> $expires,
3164 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3166 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3169 die_error
(undef, "Unknown blobdiff format");
3173 if ($format eq 'html') {
3174 print "<div class=\"page_body\">\n";
3176 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3179 print "</div>\n"; # class="page_body"
3183 while (my $line = <$fd>) {
3184 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_html($diffinfo{'from_file'})!eg;
3185 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_html($diffinfo{'to_file'})!eg;
3189 last if $line =~ m!^\+\+\+!;
3197 sub git_blobdiff_plain
{
3198 git_blobdiff
('plain');
3201 sub git_commitdiff
{
3202 my $format = shift || 'html';
3203 my %co = parse_commit
($hash);
3205 die_error
(undef, "Unknown commit object");
3207 if (!defined $hash_parent) {
3208 $hash_parent = $co{'parent'} || '--root';
3214 if ($format eq 'html') {
3215 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3216 "--patch-with-raw", "--full-index", $hash_parent, $hash
3217 or die_error
(undef, "Open git-diff-tree failed");
3219 while (chomp(my $line = <$fd>)) {
3220 # empty line ends raw part of diff-tree output
3222 push @difftree, $line;
3225 } elsif ($format eq 'plain') {
3226 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3227 '-p', $hash_parent, $hash
3228 or die_error
(undef, "Open git-diff-tree failed");
3231 die_error
(undef, "Unknown commitdiff format");
3234 # non-textual hash id's can be cached
3236 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3240 # write commit message
3241 if ($format eq 'html') {
3242 my $refs = git_get_references
();
3243 my $ref = format_ref_marker
($refs, $co{'id'});
3245 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3246 hash
=>$hash, hash_parent
=>$hash_parent)},
3249 git_header_html
(undef, $expires);
3250 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3251 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3252 git_print_authorship
(\
%co);
3253 print "<div class=\"page_body\">\n";
3254 print "<div class=\"log\">\n";
3255 git_print_simplified_log
($co{'comment'}, 1); # skip title
3256 print "</div>\n"; # class="log"
3258 } elsif ($format eq 'plain') {
3259 my $refs = git_get_references
("tags");
3260 my $tagname = git_get_rev_name_tags
($hash);
3261 my $filename = basename
($project) . "-$hash.patch";
3264 -type
=> 'text/plain',
3265 -charset
=> 'utf-8',
3266 -expires
=> $expires,
3267 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3268 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3271 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3272 Subject: $co{'title'}
3274 print "X-Git-Tag: $tagname\n" if $tagname;
3275 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3277 foreach my $line (@
{$co{'comment'}}) {
3284 if ($format eq 'html') {
3285 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3288 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3290 print "</div>\n"; # class="page_body"
3293 } elsif ($format eq 'plain') {
3297 or print "Reading git-diff-tree failed\n";
3301 sub git_commitdiff_plain
{
3302 git_commitdiff
('plain');
3306 if (!defined $hash_base) {
3307 $hash_base = git_get_head_hash
($project);
3309 if (!defined $page) {
3313 my %co = parse_commit
($hash_base);
3315 die_error
(undef, "Unknown commit object");
3318 my $refs = git_get_references
();
3319 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3321 if (!defined $hash && defined $file_name) {
3322 $hash = git_get_hash_by_path
($hash_base, $file_name);
3324 if (defined $hash) {
3325 $ftype = git_get_type
($hash);
3329 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3330 or die_error
(undef, "Open git-rev-list-failed");
3331 my @revlist = map { chomp; $_ } <$fd>;
3333 or die_error
(undef, "Reading git-rev-list failed");
3335 my $paging_nav = '';
3338 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3339 file_name
=>$file_name)},
3341 $paging_nav .= " ⋅ " .
3342 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3343 file_name
=>$file_name, page
=>$page-1),
3344 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3346 $paging_nav .= "first";
3347 $paging_nav .= " ⋅ prev";
3349 if ($#revlist >= (100 * ($page+1)-1)) {
3350 $paging_nav .= " ⋅ " .
3351 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3352 file_name
=>$file_name, page
=>$page+1),
3353 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3355 $paging_nav .= " ⋅ next";
3358 if ($#revlist >= (100 * ($page+1)-1)) {
3360 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3361 file_name
=>$file_name, page
=>$page+1),
3362 -title
=> "Alt-n"}, "next");
3366 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3367 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3368 git_print_page_path
($file_name, $ftype, $hash_base);
3370 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3371 $refs, $hash_base, $ftype, $next_link);
3377 if (!defined $searchtext) {
3378 die_error
(undef, "Text field empty");
3380 if (!defined $hash) {
3381 $hash = git_get_head_hash
($project);
3383 my %co = parse_commit
($hash);
3385 die_error
(undef, "Unknown commit object");
3388 my $commit_search = 1;
3389 my $author_search = 0;
3390 my $committer_search = 0;
3391 my $pickaxe_search = 0;
3392 if ($searchtext =~ s/^author\\://i) {
3394 } elsif ($searchtext =~ s/^committer\\://i) {
3395 $committer_search = 1;
3396 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3398 $pickaxe_search = 1;
3400 # pickaxe may take all resources of your box and run for several minutes
3401 # with every query - so decide by yourself how public you make this feature
3402 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3403 if (!$have_pickaxe) {
3404 die_error
('403 Permission denied', "Permission denied");
3408 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3409 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3411 print "<table cellspacing=\"0\">\n";
3413 if ($commit_search) {
3415 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3416 while (my $commit_text = <$fd>) {
3417 if (!grep m/$searchtext/i, $commit_text) {
3420 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3423 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3426 my @commit_lines = split "\n", $commit_text;
3427 my %co = parse_commit
(undef, \
@commit_lines);
3432 print "<tr class=\"dark\">\n";
3434 print "<tr class=\"light\">\n";
3437 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3438 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3440 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3441 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3442 my $comment = $co{'comment'};
3443 foreach my $line (@
$comment) {
3444 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3445 my $lead = esc_html
($1) || "";
3446 $lead = chop_str
($lead, 30, 10);
3447 my $match = esc_html
($2) || "";
3448 my $trail = esc_html
($3) || "";
3449 $trail = chop_str
($trail, 30, 10);
3450 my $text = "$lead<span class=\"match\">$match</span>$trail";
3451 print chop_str
($text, 80, 5) . "<br/>\n";
3455 "<td class=\"link\">" .
3456 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3458 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3465 if ($pickaxe_search) {
3467 my $git_command = git_cmd_str
();
3468 open my $fd, "-|", "$git_command rev-list $hash | " .
3469 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3472 while (my $line = <$fd>) {
3473 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3476 $set{'from_id'} = $3;
3478 $set{'id'} = $set{'to_id'};
3479 if ($set{'id'} =~ m/0{40}/) {
3480 $set{'id'} = $set{'from_id'};
3482 if ($set{'id'} =~ m/0{40}/) {
3486 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3489 print "<tr class=\"dark\">\n";
3491 print "<tr class=\"light\">\n";
3494 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3495 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3497 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3498 -class => "list subject"},
3499 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3500 while (my $setref = shift @files) {
3502 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3503 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3505 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3509 "<td class=\"link\">" .
3510 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3512 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3516 %co = parse_commit
($1);
3526 my $head = git_get_head_hash
($project);
3527 if (!defined $hash) {
3530 if (!defined $page) {
3533 my $refs = git_get_references
();
3535 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3536 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3537 or die_error
(undef, "Open git-rev-list failed");
3538 my @revlist = map { chomp; $_ } <$fd>;
3541 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3543 if ($#revlist >= (100 * ($page+1)-1)) {
3545 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3546 -title
=> "Alt-n"}, "next");
3551 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3552 git_print_header_div
('summary', $project);
3554 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3559 ## ......................................................................
3560 ## feeds (RSS, OPML)
3563 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3564 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3565 or die_error
(undef, "Open git-rev-list failed");
3566 my @revlist = map { chomp; $_ } <$fd>;
3567 close $fd or die_error
(undef, "Reading git-rev-list failed");
3568 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3570 <?xml version="1.0" encoding="utf-8"?>
3571 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3573 <title>$project $my_uri $my_url</title>
3574 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3575 <description>$project log</description>
3576 <language>en</language>
3579 for (my $i = 0; $i <= $#revlist; $i++) {
3580 my $commit = $revlist[$i];
3581 my %co = parse_commit
($commit);
3582 # we read 150, we always show 30 and the ones more recent than 48 hours
3583 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3586 my %cd = parse_date
($co{'committer_epoch'});
3587 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3588 $co{'parent'}, $co{'id'}
3590 my @difftree = map { chomp; $_ } <$fd>;
3595 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3597 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3598 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3599 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3600 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3601 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3602 "<content:encoded>" .
3604 my $comment = $co{'comment'};
3605 foreach my $line (@
$comment) {
3606 $line = to_utf8
($line);
3607 print "$line<br/>\n";
3610 foreach my $line (@difftree) {
3611 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3614 my $file = esc_html
(unquote
($7));
3615 $file = to_utf8
($file);
3616 print "$file<br/>\n";
3619 "</content:encoded>\n" .
3622 print "</channel></rss>";
3626 my @list = git_get_projects_list
();
3628 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3630 <?xml version="1.0" encoding="utf-8"?>
3631 <opml version="1.0">
3633 <title>$site_name Git OPML Export</title>
3636 <outline text="git RSS feeds">
3639 foreach my $pr (@list) {
3641 my $head = git_get_head_hash
($proj{'path'});
3642 if (!defined $head) {
3645 $git_dir = "$projectroot/$proj{'path'}";
3646 my %co = parse_commit
($head);
3651 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3652 my $rss = "$my_url?p=$proj{'path'};a=rss";
3653 my $html = "$my_url?p=$proj{'path'};a=summary";
3654 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";