1#!/usr/bin/perl 2 3# gitweb - simple web interface to track changes in git repositories 4# 5# (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org> 6# (C) 2005, Christian Gierke 7# 8# This program is licensed under the GPLv2 9 10use strict; 11use warnings; 12use CGI qw(:standard :escapeHTML -nosticky); 13use CGI::Util qw(unescape); 14use CGI::Carp qw(fatalsToBrowser); 15use Encode; 16use Fcntl ':mode'; 17use File::Find qw(); 18use File::Basename qw(basename); 19binmode STDOUT,':utf8'; 20 21our$t0; 22if(eval{require Time::HiRes;1; }) { 23$t0= [Time::HiRes::gettimeofday()]; 24} 25our$number_of_git_cmds=0; 26 27BEGIN{ 28 CGI->compile()if$ENV{'MOD_PERL'}; 29} 30 31our$cgi= new CGI; 32our$version="++GIT_VERSION++"; 33our$my_url=$cgi->url(); 34our$my_uri=$cgi->url(-absolute =>1); 35 36# Base URL for relative URLs in gitweb ($logo, $favicon, ...), 37# needed and used only for URLs with nonempty PATH_INFO 38our$base_url=$my_url; 39 40# When the script is used as DirectoryIndex, the URL does not contain the name 41# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we 42# have to do it ourselves. We make $path_info global because it's also used 43# later on. 44# 45# Another issue with the script being the DirectoryIndex is that the resulting 46# $my_url data is not the full script URL: this is good, because we want 47# generated links to keep implying the script name if it wasn't explicitly 48# indicated in the URL we're handling, but it means that $my_url cannot be used 49# as base URL. 50# Therefore, if we needed to strip PATH_INFO, then we know that we have 51# to build the base URL ourselves: 52our$path_info=$ENV{"PATH_INFO"}; 53if($path_info) { 54if($my_url=~ s,\Q$path_info\E$,, && 55$my_uri=~ s,\Q$path_info\E$,, && 56defined$ENV{'SCRIPT_NAME'}) { 57$base_url=$cgi->url(-base =>1) .$ENV{'SCRIPT_NAME'}; 58} 59} 60 61# core git executable to use 62# this can just be "git" if your webserver has a sensible PATH 63our$GIT="++GIT_BINDIR++/git"; 64 65# absolute fs-path which will be prepended to the project path 66#our $projectroot = "/pub/scm"; 67our$projectroot="++GITWEB_PROJECTROOT++"; 68 69# fs traversing limit for getting project list 70# the number is relative to the projectroot 71our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 72 73# target of the home link on top of all pages 74our$home_link=$my_uri||"/"; 75 76# string of the home link on top of all pages 77our$home_link_str="++GITWEB_HOME_LINK_STR++"; 78 79# name of your site or organization to appear in page titles 80# replace this with something more descriptive for clearer bookmarks 81our$site_name="++GITWEB_SITENAME++" 82|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 83 84# filename of html text to include at top of each page 85our$site_header="++GITWEB_SITE_HEADER++"; 86# html text to include at home page 87our$home_text="++GITWEB_HOMETEXT++"; 88# filename of html text to include at bottom of each page 89our$site_footer="++GITWEB_SITE_FOOTER++"; 90 91# URI of stylesheets 92our@stylesheets= ("++GITWEB_CSS++"); 93# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 94our$stylesheet=undef; 95# URI of GIT logo (72x27 size) 96our$logo="++GITWEB_LOGO++"; 97# URI of GIT favicon, assumed to be image/png type 98our$favicon="++GITWEB_FAVICON++"; 99# URI of gitweb.js (JavaScript code for gitweb) 100our$javascript="++GITWEB_JS++"; 101 102# URI and label (title) of GIT logo link 103#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 104#our $logo_label = "git documentation"; 105our$logo_url="http://git-scm.com/"; 106our$logo_label="git homepage"; 107 108# source of projects list 109our$projects_list="++GITWEB_LIST++"; 110 111# the width (in characters) of the projects list "Description" column 112our$projects_list_description_width=25; 113 114# default order of projects list 115# valid values are none, project, descr, owner, and age 116our$default_projects_order="project"; 117 118# show repository only if this file exists 119# (only effective if this variable evaluates to true) 120our$export_ok="++GITWEB_EXPORT_OK++"; 121 122# show repository only if this subroutine returns true 123# when given the path to the project, for example: 124# sub { return -e "$_[0]/git-daemon-export-ok"; } 125our$export_auth_hook=undef; 126 127# only allow viewing of repositories also shown on the overview page 128our$strict_export="++GITWEB_STRICT_EXPORT++"; 129 130# list of git base URLs used for URL to where fetch project from, 131# i.e. full URL is "$git_base_url/$project" 132our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 133 134# default blob_plain mimetype and default charset for text/plain blob 135our$default_blob_plain_mimetype='text/plain'; 136our$default_text_plain_charset=undef; 137 138# file to use for guessing MIME types before trying /etc/mime.types 139# (relative to the current git repository) 140our$mimetypes_file=undef; 141 142# assume this charset if line contains non-UTF-8 characters; 143# it should be valid encoding (see Encoding::Supported(3pm) for list), 144# for which encoding all byte sequences are valid, for example 145# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 146# could be even 'utf-8' for the old behavior) 147our$fallback_encoding='latin1'; 148 149# rename detection options for git-diff and git-diff-tree 150# - default is '-M', with the cost proportional to 151# (number of removed files) * (number of new files). 152# - more costly is '-C' (which implies '-M'), with the cost proportional to 153# (number of changed files + number of removed files) * (number of new files) 154# - even more costly is '-C', '--find-copies-harder' with cost 155# (number of files in the original tree) * (number of new files) 156# - one might want to include '-B' option, e.g. '-B', '-M' 157our@diff_opts= ('-M');# taken from git_commit 158 159# Disables features that would allow repository owners to inject script into 160# the gitweb domain. 161our$prevent_xss=0; 162 163# information about snapshot formats that gitweb is capable of serving 164our%known_snapshot_formats= ( 165# name => { 166# 'display' => display name, 167# 'type' => mime type, 168# 'suffix' => filename suffix, 169# 'format' => --format for git-archive, 170# 'compressor' => [compressor command and arguments] 171# (array reference, optional) 172# 'disabled' => boolean (optional)} 173# 174'tgz'=> { 175'display'=>'tar.gz', 176'type'=>'application/x-gzip', 177'suffix'=>'.tar.gz', 178'format'=>'tar', 179'compressor'=> ['gzip']}, 180 181'tbz2'=> { 182'display'=>'tar.bz2', 183'type'=>'application/x-bzip2', 184'suffix'=>'.tar.bz2', 185'format'=>'tar', 186'compressor'=> ['bzip2']}, 187 188'txz'=> { 189'display'=>'tar.xz', 190'type'=>'application/x-xz', 191'suffix'=>'.tar.xz', 192'format'=>'tar', 193'compressor'=> ['xz'], 194'disabled'=>1}, 195 196'zip'=> { 197'display'=>'zip', 198'type'=>'application/x-zip', 199'suffix'=>'.zip', 200'format'=>'zip'}, 201); 202 203# Aliases so we understand old gitweb.snapshot values in repository 204# configuration. 205our%known_snapshot_format_aliases= ( 206'gzip'=>'tgz', 207'bzip2'=>'tbz2', 208'xz'=>'txz', 209 210# backward compatibility: legacy gitweb config support 211'x-gzip'=>undef,'gz'=>undef, 212'x-bzip2'=>undef,'bz2'=>undef, 213'x-zip'=>undef,''=>undef, 214); 215 216# Pixel sizes for icons and avatars. If the default font sizes or lineheights 217# are changed, it may be appropriate to change these values too via 218# $GITWEB_CONFIG. 219our%avatar_size= ( 220'default'=>16, 221'double'=>32 222); 223 224# Used to set the maximum load that we will still respond to gitweb queries. 225# If server load exceed this value then return "503 server busy" error. 226# If gitweb cannot determined server load, it is taken to be 0. 227# Leave it undefined (or set to 'undef') to turn off load checking. 228our$maxload=300; 229 230# You define site-wide feature defaults here; override them with 231# $GITWEB_CONFIG as necessary. 232our%feature= ( 233# feature => { 234# 'sub' => feature-sub (subroutine), 235# 'override' => allow-override (boolean), 236# 'default' => [ default options...] (array reference)} 237# 238# if feature is overridable (it means that allow-override has true value), 239# then feature-sub will be called with default options as parameters; 240# return value of feature-sub indicates if to enable specified feature 241# 242# if there is no 'sub' key (no feature-sub), then feature cannot be 243# overriden 244# 245# use gitweb_get_feature(<feature>) to retrieve the <feature> value 246# (an array) or gitweb_check_feature(<feature>) to check if <feature> 247# is enabled 248 249# Enable the 'blame' blob view, showing the last commit that modified 250# each line in the file. This can be very CPU-intensive. 251 252# To enable system wide have in $GITWEB_CONFIG 253# $feature{'blame'}{'default'} = [1]; 254# To have project specific config enable override in $GITWEB_CONFIG 255# $feature{'blame'}{'override'} = 1; 256# and in project config gitweb.blame = 0|1; 257'blame'=> { 258'sub'=>sub{ feature_bool('blame',@_) }, 259'override'=>0, 260'default'=> [0]}, 261 262# Enable the 'snapshot' link, providing a compressed archive of any 263# tree. This can potentially generate high traffic if you have large 264# project. 265 266# Value is a list of formats defined in %known_snapshot_formats that 267# you wish to offer. 268# To disable system wide have in $GITWEB_CONFIG 269# $feature{'snapshot'}{'default'} = []; 270# To have project specific config enable override in $GITWEB_CONFIG 271# $feature{'snapshot'}{'override'} = 1; 272# and in project config, a comma-separated list of formats or "none" 273# to disable. Example: gitweb.snapshot = tbz2,zip; 274'snapshot'=> { 275'sub'=> \&feature_snapshot, 276'override'=>0, 277'default'=> ['tgz']}, 278 279# Enable text search, which will list the commits which match author, 280# committer or commit text to a given string. Enabled by default. 281# Project specific override is not supported. 282'search'=> { 283'override'=>0, 284'default'=> [1]}, 285 286# Enable grep search, which will list the files in currently selected 287# tree containing the given string. Enabled by default. This can be 288# potentially CPU-intensive, of course. 289 290# To enable system wide have in $GITWEB_CONFIG 291# $feature{'grep'}{'default'} = [1]; 292# To have project specific config enable override in $GITWEB_CONFIG 293# $feature{'grep'}{'override'} = 1; 294# and in project config gitweb.grep = 0|1; 295'grep'=> { 296'sub'=>sub{ feature_bool('grep',@_) }, 297'override'=>0, 298'default'=> [1]}, 299 300# Enable the pickaxe search, which will list the commits that modified 301# a given string in a file. This can be practical and quite faster 302# alternative to 'blame', but still potentially CPU-intensive. 303 304# To enable system wide have in $GITWEB_CONFIG 305# $feature{'pickaxe'}{'default'} = [1]; 306# To have project specific config enable override in $GITWEB_CONFIG 307# $feature{'pickaxe'}{'override'} = 1; 308# and in project config gitweb.pickaxe = 0|1; 309'pickaxe'=> { 310'sub'=>sub{ feature_bool('pickaxe',@_) }, 311'override'=>0, 312'default'=> [1]}, 313 314# Enable showing size of blobs in a 'tree' view, in a separate 315# column, similar to what 'ls -l' does. This cost a bit of IO. 316 317# To disable system wide have in $GITWEB_CONFIG 318# $feature{'show-sizes'}{'default'} = [0]; 319# To have project specific config enable override in $GITWEB_CONFIG 320# $feature{'show-sizes'}{'override'} = 1; 321# and in project config gitweb.showsizes = 0|1; 322'show-sizes'=> { 323'sub'=>sub{ feature_bool('showsizes',@_) }, 324'override'=>0, 325'default'=> [1]}, 326 327# Make gitweb use an alternative format of the URLs which can be 328# more readable and natural-looking: project name is embedded 329# directly in the path and the query string contains other 330# auxiliary information. All gitweb installations recognize 331# URL in either format; this configures in which formats gitweb 332# generates links. 333 334# To enable system wide have in $GITWEB_CONFIG 335# $feature{'pathinfo'}{'default'} = [1]; 336# Project specific override is not supported. 337 338# Note that you will need to change the default location of CSS, 339# favicon, logo and possibly other files to an absolute URL. Also, 340# if gitweb.cgi serves as your indexfile, you will need to force 341# $my_uri to contain the script name in your $GITWEB_CONFIG. 342'pathinfo'=> { 343'override'=>0, 344'default'=> [0]}, 345 346# Make gitweb consider projects in project root subdirectories 347# to be forks of existing projects. Given project $projname.git, 348# projects matching $projname/*.git will not be shown in the main 349# projects list, instead a '+' mark will be added to $projname 350# there and a 'forks' view will be enabled for the project, listing 351# all the forks. If project list is taken from a file, forks have 352# to be listed after the main project. 353 354# To enable system wide have in $GITWEB_CONFIG 355# $feature{'forks'}{'default'} = [1]; 356# Project specific override is not supported. 357'forks'=> { 358'override'=>0, 359'default'=> [0]}, 360 361# Insert custom links to the action bar of all project pages. 362# This enables you mainly to link to third-party scripts integrating 363# into gitweb; e.g. git-browser for graphical history representation 364# or custom web-based repository administration interface. 365 366# The 'default' value consists of a list of triplets in the form 367# (label, link, position) where position is the label after which 368# to insert the link and link is a format string where %n expands 369# to the project name, %f to the project path within the filesystem, 370# %h to the current hash (h gitweb parameter) and %b to the current 371# hash base (hb gitweb parameter); %% expands to %. 372 373# To enable system wide have in $GITWEB_CONFIG e.g. 374# $feature{'actions'}{'default'} = [('graphiclog', 375# '/git-browser/by-commit.html?r=%n', 'summary')]; 376# Project specific override is not supported. 377'actions'=> { 378'override'=>0, 379'default'=> []}, 380 381# Allow gitweb scan project content tags described in ctags/ 382# of project repository, and display the popular Web 2.0-ish 383# "tag cloud" near the project list. Note that this is something 384# COMPLETELY different from the normal Git tags. 385 386# gitweb by itself can show existing tags, but it does not handle 387# tagging itself; you need an external application for that. 388# For an example script, check Girocco's cgi/tagproj.cgi. 389# You may want to install the HTML::TagCloud Perl module to get 390# a pretty tag cloud instead of just a list of tags. 391 392# To enable system wide have in $GITWEB_CONFIG 393# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 394# Project specific override is not supported. 395'ctags'=> { 396'override'=>0, 397'default'=> [0]}, 398 399# The maximum number of patches in a patchset generated in patch 400# view. Set this to 0 or undef to disable patch view, or to a 401# negative number to remove any limit. 402 403# To disable system wide have in $GITWEB_CONFIG 404# $feature{'patches'}{'default'} = [0]; 405# To have project specific config enable override in $GITWEB_CONFIG 406# $feature{'patches'}{'override'} = 1; 407# and in project config gitweb.patches = 0|n; 408# where n is the maximum number of patches allowed in a patchset. 409'patches'=> { 410'sub'=> \&feature_patches, 411'override'=>0, 412'default'=> [16]}, 413 414# Avatar support. When this feature is enabled, views such as 415# shortlog or commit will display an avatar associated with 416# the email of the committer(s) and/or author(s). 417 418# Currently available providers are gravatar and picon. 419# If an unknown provider is specified, the feature is disabled. 420 421# Gravatar depends on Digest::MD5. 422# Picon currently relies on the indiana.edu database. 423 424# To enable system wide have in $GITWEB_CONFIG 425# $feature{'avatar'}{'default'} = ['<provider>']; 426# where <provider> is either gravatar or picon. 427# To have project specific config enable override in $GITWEB_CONFIG 428# $feature{'avatar'}{'override'} = 1; 429# and in project config gitweb.avatar = <provider>; 430'avatar'=> { 431'sub'=> \&feature_avatar, 432'override'=>0, 433'default'=> ['']}, 434 435# Enable displaying how much time and how many git commands 436# it took to generate and display page. Disabled by default. 437# Project specific override is not supported. 438'timed'=> { 439'override'=>0, 440'default'=> [0]}, 441 442# Enable turning some links into links to actions which require 443# JavaScript to run (like 'blame_incremental'). Not enabled by 444# default. Project specific override is currently not supported. 445'javascript-actions'=> { 446'override'=>0, 447'default'=> [0]}, 448); 449 450sub gitweb_get_feature { 451my($name) =@_; 452return unlessexists$feature{$name}; 453my($sub,$override,@defaults) = ( 454$feature{$name}{'sub'}, 455$feature{$name}{'override'}, 456@{$feature{$name}{'default'}}); 457# project specific override is possible only if we have project 458our$git_dir;# global variable, declared later 459if(!$override|| !defined$git_dir) { 460return@defaults; 461} 462if(!defined$sub) { 463warn"feature$nameis not overridable"; 464return@defaults; 465} 466return$sub->(@defaults); 467} 468 469# A wrapper to check if a given feature is enabled. 470# With this, you can say 471# 472# my $bool_feat = gitweb_check_feature('bool_feat'); 473# gitweb_check_feature('bool_feat') or somecode; 474# 475# instead of 476# 477# my ($bool_feat) = gitweb_get_feature('bool_feat'); 478# (gitweb_get_feature('bool_feat'))[0] or somecode; 479# 480sub gitweb_check_feature { 481return(gitweb_get_feature(@_))[0]; 482} 483 484 485sub feature_bool { 486my$key=shift; 487my($val) = git_get_project_config($key,'--bool'); 488 489if(!defined$val) { 490return($_[0]); 491}elsif($valeq'true') { 492return(1); 493}elsif($valeq'false') { 494return(0); 495} 496} 497 498sub feature_snapshot { 499my(@fmts) =@_; 500 501my($val) = git_get_project_config('snapshot'); 502 503if($val) { 504@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 505} 506 507return@fmts; 508} 509 510sub feature_patches { 511my@val= (git_get_project_config('patches','--int')); 512 513if(@val) { 514return@val; 515} 516 517return($_[0]); 518} 519 520sub feature_avatar { 521my@val= (git_get_project_config('avatar')); 522 523return@val?@val:@_; 524} 525 526# checking HEAD file with -e is fragile if the repository was 527# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 528# and then pruned. 529sub check_head_link { 530my($dir) =@_; 531my$headfile="$dir/HEAD"; 532return((-e $headfile) || 533(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 534} 535 536sub check_export_ok { 537my($dir) =@_; 538return(check_head_link($dir) && 539(!$export_ok|| -e "$dir/$export_ok") && 540(!$export_auth_hook||$export_auth_hook->($dir))); 541} 542 543# process alternate names for backward compatibility 544# filter out unsupported (unknown) snapshot formats 545sub filter_snapshot_fmts { 546my@fmts=@_; 547 548@fmts=map{ 549exists$known_snapshot_format_aliases{$_} ? 550$known_snapshot_format_aliases{$_} :$_}@fmts; 551@fmts=grep{ 552exists$known_snapshot_formats{$_} && 553!$known_snapshot_formats{$_}{'disabled'}}@fmts; 554} 555 556our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 557our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 558# die if there are errors parsing config file 559if(-e $GITWEB_CONFIG) { 560do$GITWEB_CONFIG; 561die$@if$@; 562}elsif(-e $GITWEB_CONFIG_SYSTEM) { 563do$GITWEB_CONFIG_SYSTEM; 564die$@if$@; 565} 566 567# Get loadavg of system, to compare against $maxload. 568# Currently it requires '/proc/loadavg' present to get loadavg; 569# if it is not present it returns 0, which means no load checking. 570sub get_loadavg { 571if( -e '/proc/loadavg'){ 572open my$fd,'<','/proc/loadavg' 573orreturn0; 574my@load=split(/\s+/,scalar<$fd>); 575close$fd; 576 577# The first three columns measure CPU and IO utilization of the last one, 578# five, and 10 minute periods. The fourth column shows the number of 579# currently running processes and the total number of processes in the m/n 580# format. The last column displays the last process ID used. 581return$load[0] ||0; 582} 583# additional checks for load average should go here for things that don't export 584# /proc/loadavg 585 586return0; 587} 588 589# version of the core git binary 590our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 591$number_of_git_cmds++; 592 593$projects_list||=$projectroot; 594 595if(defined$maxload&& get_loadavg() >$maxload) { 596 die_error(503,"The load average on the server is too high"); 597} 598 599# ====================================================================== 600# input validation and dispatch 601 602# input parameters can be collected from a variety of sources (presently, CGI 603# and PATH_INFO), so we define an %input_params hash that collects them all 604# together during validation: this allows subsequent uses (e.g. href()) to be 605# agnostic of the parameter origin 606 607our%input_params= (); 608 609# input parameters are stored with the long parameter name as key. This will 610# also be used in the href subroutine to convert parameters to their CGI 611# equivalent, and since the href() usage is the most frequent one, we store 612# the name -> CGI key mapping here, instead of the reverse. 613# 614# XXX: Warning: If you touch this, check the search form for updating, 615# too. 616 617our@cgi_param_mapping= ( 618 project =>"p", 619 action =>"a", 620 file_name =>"f", 621 file_parent =>"fp", 622 hash =>"h", 623 hash_parent =>"hp", 624 hash_base =>"hb", 625 hash_parent_base =>"hpb", 626 page =>"pg", 627 order =>"o", 628 searchtext =>"s", 629 searchtype =>"st", 630 snapshot_format =>"sf", 631 extra_options =>"opt", 632 search_use_regexp =>"sr", 633# this must be last entry (for manipulation from JavaScript) 634 javascript =>"js" 635); 636our%cgi_param_mapping=@cgi_param_mapping; 637 638# we will also need to know the possible actions, for validation 639our%actions= ( 640"blame"=> \&git_blame, 641"blame_incremental"=> \&git_blame_incremental, 642"blame_data"=> \&git_blame_data, 643"blobdiff"=> \&git_blobdiff, 644"blobdiff_plain"=> \&git_blobdiff_plain, 645"blob"=> \&git_blob, 646"blob_plain"=> \&git_blob_plain, 647"commitdiff"=> \&git_commitdiff, 648"commitdiff_plain"=> \&git_commitdiff_plain, 649"commit"=> \&git_commit, 650"forks"=> \&git_forks, 651"heads"=> \&git_heads, 652"history"=> \&git_history, 653"log"=> \&git_log, 654"patch"=> \&git_patch, 655"patches"=> \&git_patches, 656"rss"=> \&git_rss, 657"atom"=> \&git_atom, 658"search"=> \&git_search, 659"search_help"=> \&git_search_help, 660"shortlog"=> \&git_shortlog, 661"summary"=> \&git_summary, 662"tag"=> \&git_tag, 663"tags"=> \&git_tags, 664"tree"=> \&git_tree, 665"snapshot"=> \&git_snapshot, 666"object"=> \&git_object, 667# those below don't need $project 668"opml"=> \&git_opml, 669"project_list"=> \&git_project_list, 670"project_index"=> \&git_project_index, 671); 672 673# finally, we have the hash of allowed extra_options for the commands that 674# allow them 675our%allowed_options= ( 676"--no-merges"=> [qw(rss atom log shortlog history)], 677); 678 679# fill %input_params with the CGI parameters. All values except for 'opt' 680# should be single values, but opt can be an array. We should probably 681# build an array of parameters that can be multi-valued, but since for the time 682# being it's only this one, we just single it out 683while(my($name,$symbol) =each%cgi_param_mapping) { 684if($symboleq'opt') { 685$input_params{$name} = [$cgi->param($symbol) ]; 686}else{ 687$input_params{$name} =$cgi->param($symbol); 688} 689} 690 691# now read PATH_INFO and update the parameter list for missing parameters 692sub evaluate_path_info { 693return ifdefined$input_params{'project'}; 694return if!$path_info; 695$path_info=~ s,^/+,,; 696return if!$path_info; 697 698# find which part of PATH_INFO is project 699my$project=$path_info; 700$project=~ s,/+$,,; 701while($project&& !check_head_link("$projectroot/$project")) { 702$project=~ s,/*[^/]*$,,; 703} 704return unless$project; 705$input_params{'project'} =$project; 706 707# do not change any parameters if an action is given using the query string 708return if$input_params{'action'}; 709$path_info=~ s,^\Q$project\E/*,,; 710 711# next, check if we have an action 712my$action=$path_info; 713$action=~ s,/.*$,,; 714if(exists$actions{$action}) { 715$path_info=~ s,^$action/*,,; 716$input_params{'action'} =$action; 717} 718 719# list of actions that want hash_base instead of hash, but can have no 720# pathname (f) parameter 721my@wants_base= ( 722'tree', 723'history', 724); 725 726# we want to catch 727# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 728my($parentrefname,$parentpathname,$refname,$pathname) = 729($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/); 730 731# first, analyze the 'current' part 732if(defined$pathname) { 733# we got "branch:filename" or "branch:dir/" 734# we could use git_get_type(branch:pathname), but: 735# - it needs $git_dir 736# - it does a git() call 737# - the convention of terminating directories with a slash 738# makes it superfluous 739# - embedding the action in the PATH_INFO would make it even 740# more superfluous 741$pathname=~ s,^/+,,; 742if(!$pathname||substr($pathname, -1)eq"/") { 743$input_params{'action'} ||="tree"; 744$pathname=~ s,/$,,; 745}else{ 746# the default action depends on whether we had parent info 747# or not 748if($parentrefname) { 749$input_params{'action'} ||="blobdiff_plain"; 750}else{ 751$input_params{'action'} ||="blob_plain"; 752} 753} 754$input_params{'hash_base'} ||=$refname; 755$input_params{'file_name'} ||=$pathname; 756}elsif(defined$refname) { 757# we got "branch". In this case we have to choose if we have to 758# set hash or hash_base. 759# 760# Most of the actions without a pathname only want hash to be 761# set, except for the ones specified in @wants_base that want 762# hash_base instead. It should also be noted that hand-crafted 763# links having 'history' as an action and no pathname or hash 764# set will fail, but that happens regardless of PATH_INFO. 765$input_params{'action'} ||="shortlog"; 766if(grep{$_eq$input_params{'action'} }@wants_base) { 767$input_params{'hash_base'} ||=$refname; 768}else{ 769$input_params{'hash'} ||=$refname; 770} 771} 772 773# next, handle the 'parent' part, if present 774if(defined$parentrefname) { 775# a missing pathspec defaults to the 'current' filename, allowing e.g. 776# someproject/blobdiff/oldrev..newrev:/filename 777if($parentpathname) { 778$parentpathname=~ s,^/+,,; 779$parentpathname=~ s,/$,,; 780$input_params{'file_parent'} ||=$parentpathname; 781}else{ 782$input_params{'file_parent'} ||=$input_params{'file_name'}; 783} 784# we assume that hash_parent_base is wanted if a path was specified, 785# or if the action wants hash_base instead of hash 786if(defined$input_params{'file_parent'} || 787grep{$_eq$input_params{'action'} }@wants_base) { 788$input_params{'hash_parent_base'} ||=$parentrefname; 789}else{ 790$input_params{'hash_parent'} ||=$parentrefname; 791} 792} 793 794# for the snapshot action, we allow URLs in the form 795# $project/snapshot/$hash.ext 796# where .ext determines the snapshot and gets removed from the 797# passed $refname to provide the $hash. 798# 799# To be able to tell that $refname includes the format extension, we 800# require the following two conditions to be satisfied: 801# - the hash input parameter MUST have been set from the $refname part 802# of the URL (i.e. they must be equal) 803# - the snapshot format MUST NOT have been defined already (e.g. from 804# CGI parameter sf) 805# It's also useless to try any matching unless $refname has a dot, 806# so we check for that too 807if(defined$input_params{'action'} && 808$input_params{'action'}eq'snapshot'&& 809defined$refname&&index($refname,'.') != -1&& 810$refnameeq$input_params{'hash'} && 811!defined$input_params{'snapshot_format'}) { 812# We loop over the known snapshot formats, checking for 813# extensions. Allowed extensions are both the defined suffix 814# (which includes the initial dot already) and the snapshot 815# format key itself, with a prepended dot 816while(my($fmt,$opt) =each%known_snapshot_formats) { 817my$hash=$refname; 818unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 819next; 820} 821my$sfx=$1; 822# a valid suffix was found, so set the snapshot format 823# and reset the hash parameter 824$input_params{'snapshot_format'} =$fmt; 825$input_params{'hash'} =$hash; 826# we also set the format suffix to the one requested 827# in the URL: this way a request for e.g. .tgz returns 828# a .tgz instead of a .tar.gz 829$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 830last; 831} 832} 833} 834evaluate_path_info(); 835 836our$action=$input_params{'action'}; 837if(defined$action) { 838if(!validate_action($action)) { 839 die_error(400,"Invalid action parameter"); 840} 841} 842 843# parameters which are pathnames 844our$project=$input_params{'project'}; 845if(defined$project) { 846if(!validate_project($project)) { 847undef$project; 848 die_error(404,"No such project"); 849} 850} 851 852our$file_name=$input_params{'file_name'}; 853if(defined$file_name) { 854if(!validate_pathname($file_name)) { 855 die_error(400,"Invalid file parameter"); 856} 857} 858 859our$file_parent=$input_params{'file_parent'}; 860if(defined$file_parent) { 861if(!validate_pathname($file_parent)) { 862 die_error(400,"Invalid file parent parameter"); 863} 864} 865 866# parameters which are refnames 867our$hash=$input_params{'hash'}; 868if(defined$hash) { 869if(!validate_refname($hash)) { 870 die_error(400,"Invalid hash parameter"); 871} 872} 873 874our$hash_parent=$input_params{'hash_parent'}; 875if(defined$hash_parent) { 876if(!validate_refname($hash_parent)) { 877 die_error(400,"Invalid hash parent parameter"); 878} 879} 880 881our$hash_base=$input_params{'hash_base'}; 882if(defined$hash_base) { 883if(!validate_refname($hash_base)) { 884 die_error(400,"Invalid hash base parameter"); 885} 886} 887 888our@extra_options= @{$input_params{'extra_options'}}; 889# @extra_options is always defined, since it can only be (currently) set from 890# CGI, and $cgi->param() returns the empty array in array context if the param 891# is not set 892foreachmy$opt(@extra_options) { 893if(not exists$allowed_options{$opt}) { 894 die_error(400,"Invalid option parameter"); 895} 896if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 897 die_error(400,"Invalid option parameter for this action"); 898} 899} 900 901our$hash_parent_base=$input_params{'hash_parent_base'}; 902if(defined$hash_parent_base) { 903if(!validate_refname($hash_parent_base)) { 904 die_error(400,"Invalid hash parent base parameter"); 905} 906} 907 908# other parameters 909our$page=$input_params{'page'}; 910if(defined$page) { 911if($page=~m/[^0-9]/) { 912 die_error(400,"Invalid page parameter"); 913} 914} 915 916our$searchtype=$input_params{'searchtype'}; 917if(defined$searchtype) { 918if($searchtype=~m/[^a-z]/) { 919 die_error(400,"Invalid searchtype parameter"); 920} 921} 922 923our$search_use_regexp=$input_params{'search_use_regexp'}; 924 925our$searchtext=$input_params{'searchtext'}; 926our$search_regexp; 927if(defined$searchtext) { 928if(length($searchtext) <2) { 929 die_error(403,"At least two characters are required for search parameter"); 930} 931$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 932} 933 934# path to the current git repository 935our$git_dir; 936$git_dir="$projectroot/$project"if$project; 937 938# list of supported snapshot formats 939our@snapshot_fmts= gitweb_get_feature('snapshot'); 940@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts); 941 942# check that the avatar feature is set to a known provider name, 943# and for each provider check if the dependencies are satisfied. 944# if the provider name is invalid or the dependencies are not met, 945# reset $git_avatar to the empty string. 946our($git_avatar) = gitweb_get_feature('avatar'); 947if($git_avatareq'gravatar') { 948$git_avatar=''unless(eval{require Digest::MD5;1; }); 949}elsif($git_avatareq'picon') { 950# no dependencies 951}else{ 952$git_avatar=''; 953} 954 955# dispatch 956if(!defined$action) { 957if(defined$hash) { 958$action= git_get_type($hash); 959}elsif(defined$hash_base&&defined$file_name) { 960$action= git_get_type("$hash_base:$file_name"); 961}elsif(defined$project) { 962$action='summary'; 963}else{ 964$action='project_list'; 965} 966} 967if(!defined($actions{$action})) { 968 die_error(400,"Unknown action"); 969} 970if($action!~m/^(?:opml|project_list|project_index)$/&& 971!$project) { 972 die_error(400,"Project needed"); 973} 974$actions{$action}->(); 975exit; 976 977## ====================================================================== 978## action links 979 980sub href { 981my%params=@_; 982# default is to use -absolute url() i.e. $my_uri 983my$href=$params{-full} ?$my_url:$my_uri; 984 985$params{'project'} =$projectunlessexists$params{'project'}; 986 987if($params{-replay}) { 988while(my($name,$symbol) =each%cgi_param_mapping) { 989if(!exists$params{$name}) { 990$params{$name} =$input_params{$name}; 991} 992} 993} 994 995my$use_pathinfo= gitweb_check_feature('pathinfo'); 996if($use_pathinfoand defined$params{'project'}) { 997# try to put as many parameters as possible in PATH_INFO: 998# - project name 999# - action1000# - hash_parent or hash_parent_base:/file_parent1001# - hash or hash_base:/filename1002# - the snapshot_format as an appropriate suffix10031004# When the script is the root DirectoryIndex for the domain,1005# $href here would be something like http://gitweb.example.com/1006# Thus, we strip any trailing / from $href, to spare us double1007# slashes in the final URL1008$href=~ s,/$,,;10091010# Then add the project name, if present1011$href.="/".esc_url($params{'project'});1012delete$params{'project'};10131014# since we destructively absorb parameters, we keep this1015# boolean that remembers if we're handling a snapshot1016my$is_snapshot=$params{'action'}eq'snapshot';10171018# Summary just uses the project path URL, any other action is1019# added to the URL1020if(defined$params{'action'}) {1021$href.="/".esc_url($params{'action'})unless$params{'action'}eq'summary';1022delete$params{'action'};1023}10241025# Next, we put hash_parent_base:/file_parent..hash_base:/file_name,1026# stripping nonexistent or useless pieces1027$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'}1028||$params{'hash_parent'} ||$params{'hash'});1029if(defined$params{'hash_base'}) {1030if(defined$params{'hash_parent_base'}) {1031$href.= esc_url($params{'hash_parent_base'});1032# skip the file_parent if it's the same as the file_name1033if(defined$params{'file_parent'}) {1034if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) {1035delete$params{'file_parent'};1036}elsif($params{'file_parent'} !~/\.\./) {1037$href.=":/".esc_url($params{'file_parent'});1038delete$params{'file_parent'};1039}1040}1041$href.="..";1042delete$params{'hash_parent'};1043delete$params{'hash_parent_base'};1044}elsif(defined$params{'hash_parent'}) {1045$href.= esc_url($params{'hash_parent'})."..";1046delete$params{'hash_parent'};1047}10481049$href.= esc_url($params{'hash_base'});1050if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) {1051$href.=":/".esc_url($params{'file_name'});1052delete$params{'file_name'};1053}1054delete$params{'hash'};1055delete$params{'hash_base'};1056}elsif(defined$params{'hash'}) {1057$href.= esc_url($params{'hash'});1058delete$params{'hash'};1059}10601061# If the action was a snapshot, we can absorb the1062# snapshot_format parameter too1063if($is_snapshot) {1064my$fmt=$params{'snapshot_format'};1065# snapshot_format should always be defined when href()1066# is called, but just in case some code forgets, we1067# fall back to the default1068$fmt||=$snapshot_fmts[0];1069$href.=$known_snapshot_formats{$fmt}{'suffix'};1070delete$params{'snapshot_format'};1071}1072}10731074# now encode the parameters explicitly1075my@result= ();1076for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1077my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1078if(defined$params{$name}) {1079if(ref($params{$name})eq"ARRAY") {1080foreachmy$par(@{$params{$name}}) {1081push@result,$symbol."=". esc_param($par);1082}1083}else{1084push@result,$symbol."=". esc_param($params{$name});1085}1086}1087}1088$href.="?".join(';',@result)ifscalar@result;10891090return$href;1091}109210931094## ======================================================================1095## validation, quoting/unquoting and escaping10961097sub validate_action {1098my$input=shift||returnundef;1099returnundefunlessexists$actions{$input};1100return$input;1101}11021103sub validate_project {1104my$input=shift||returnundef;1105if(!validate_pathname($input) ||1106!(-d "$projectroot/$input") ||1107!check_export_ok("$projectroot/$input") ||1108($strict_export&& !project_in_list($input))) {1109returnundef;1110}else{1111return$input;1112}1113}11141115sub validate_pathname {1116my$input=shift||returnundef;11171118# no '.' or '..' as elements of path, i.e. no '.' nor '..'1119# at the beginning, at the end, and between slashes.1120# also this catches doubled slashes1121if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1122returnundef;1123}1124# no null characters1125if($input=~m!\0!) {1126returnundef;1127}1128return$input;1129}11301131sub validate_refname {1132my$input=shift||returnundef;11331134# textual hashes are O.K.1135if($input=~m/^[0-9a-fA-F]{40}$/) {1136return$input;1137}1138# it must be correct pathname1139$input= validate_pathname($input)1140orreturnundef;1141# restrictions on ref name according to git-check-ref-format1142if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1143returnundef;1144}1145return$input;1146}11471148# decode sequences of octets in utf8 into Perl's internal form,1149# which is utf-8 with utf8 flag set if needed. gitweb writes out1150# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1151sub to_utf8 {1152my$str=shift;1153returnundefunlessdefined$str;1154if(utf8::valid($str)) {1155 utf8::decode($str);1156return$str;1157}else{1158return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1159}1160}11611162# quote unsafe chars, but keep the slash, even when it's not1163# correct, but quoted slashes look too horrible in bookmarks1164sub esc_param {1165my$str=shift;1166returnundefunlessdefined$str;1167$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1168$str=~s/ /\+/g;1169return$str;1170}11711172# quote unsafe chars in whole URL, so some charactrs cannot be quoted1173sub esc_url {1174my$str=shift;1175returnundefunlessdefined$str;1176$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X",ord($1))/eg;1177$str=~s/\+/%2B/g;1178$str=~s/ /\+/g;1179return$str;1180}11811182# replace invalid utf8 character with SUBSTITUTION sequence1183sub esc_html {1184my$str=shift;1185my%opts=@_;11861187returnundefunlessdefined$str;11881189$str= to_utf8($str);1190$str=$cgi->escapeHTML($str);1191if($opts{'-nbsp'}) {1192$str=~s/ / /g;1193}1194$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1195return$str;1196}11971198# quote control characters and escape filename to HTML1199sub esc_path {1200my$str=shift;1201my%opts=@_;12021203returnundefunlessdefined$str;12041205$str= to_utf8($str);1206$str=$cgi->escapeHTML($str);1207if($opts{'-nbsp'}) {1208$str=~s/ / /g;1209}1210$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1211return$str;1212}12131214# Make control characters "printable", using character escape codes (CEC)1215sub quot_cec {1216my$cntrl=shift;1217my%opts=@_;1218my%es= (# character escape codes, aka escape sequences1219"\t"=>'\t',# tab (HT)1220"\n"=>'\n',# line feed (LF)1221"\r"=>'\r',# carrige return (CR)1222"\f"=>'\f',# form feed (FF)1223"\b"=>'\b',# backspace (BS)1224"\a"=>'\a',# alarm (bell) (BEL)1225"\e"=>'\e',# escape (ESC)1226"\013"=>'\v',# vertical tab (VT)1227"\000"=>'\0',# nul character (NUL)1228);1229my$chr= ( (exists$es{$cntrl})1230?$es{$cntrl}1231:sprintf('\%2x',ord($cntrl)) );1232if($opts{-nohtml}) {1233return$chr;1234}else{1235return"<span class=\"cntrl\">$chr</span>";1236}1237}12381239# Alternatively use unicode control pictures codepoints,1240# Unicode "printable representation" (PR)1241sub quot_upr {1242my$cntrl=shift;1243my%opts=@_;12441245my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1246if($opts{-nohtml}) {1247return$chr;1248}else{1249return"<span class=\"cntrl\">$chr</span>";1250}1251}12521253# git may return quoted and escaped filenames1254sub unquote {1255my$str=shift;12561257sub unq {1258my$seq=shift;1259my%es= (# character escape codes, aka escape sequences1260't'=>"\t",# tab (HT, TAB)1261'n'=>"\n",# newline (NL)1262'r'=>"\r",# return (CR)1263'f'=>"\f",# form feed (FF)1264'b'=>"\b",# backspace (BS)1265'a'=>"\a",# alarm (bell) (BEL)1266'e'=>"\e",# escape (ESC)1267'v'=>"\013",# vertical tab (VT)1268);12691270if($seq=~m/^[0-7]{1,3}$/) {1271# octal char sequence1272returnchr(oct($seq));1273}elsif(exists$es{$seq}) {1274# C escape sequence, aka character escape code1275return$es{$seq};1276}1277# quoted ordinary character1278return$seq;1279}12801281if($str=~m/^"(.*)"$/) {1282# needs unquoting1283$str=$1;1284$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1285}1286return$str;1287}12881289# escape tabs (convert tabs to spaces)1290sub untabify {1291my$line=shift;12921293while((my$pos=index($line,"\t")) != -1) {1294if(my$count= (8- ($pos%8))) {1295my$spaces=' ' x $count;1296$line=~s/\t/$spaces/;1297}1298}12991300return$line;1301}13021303sub project_in_list {1304my$project=shift;1305my@list= git_get_projects_list();1306return@list&&scalar(grep{$_->{'path'}eq$project}@list);1307}13081309## ----------------------------------------------------------------------1310## HTML aware string manipulation13111312# Try to chop given string on a word boundary between position1313# $len and $len+$add_len. If there is no word boundary there,1314# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1315# (marking chopped part) would be longer than given string.1316sub chop_str {1317my$str=shift;1318my$len=shift;1319my$add_len=shift||10;1320my$where=shift||'right';# 'left' | 'center' | 'right'13211322# Make sure perl knows it is utf8 encoded so we don't1323# cut in the middle of a utf8 multibyte char.1324$str= to_utf8($str);13251326# allow only $len chars, but don't cut a word if it would fit in $add_len1327# if it doesn't fit, cut it if it's still longer than the dots we would add1328# remove chopped character entities entirely13291330# when chopping in the middle, distribute $len into left and right part1331# return early if chopping wouldn't make string shorter1332if($whereeq'center') {1333return$strif($len+5>=length($str));# filler is length 51334$len=int($len/2);1335}else{1336return$strif($len+4>=length($str));# filler is length 41337}13381339# regexps: ending and beginning with word part up to $add_len1340my$endre=qr/.{$len}\w{0,$add_len}/;1341my$begre=qr/\w{0,$add_len}.{$len}/;13421343if($whereeq'left') {1344$str=~m/^(.*?)($begre)$/;1345my($lead,$body) = ($1,$2);1346if(length($lead) >4) {1347$lead=" ...";1348}1349return"$lead$body";13501351}elsif($whereeq'center') {1352$str=~m/^($endre)(.*)$/;1353my($left,$str) = ($1,$2);1354$str=~m/^(.*?)($begre)$/;1355my($mid,$right) = ($1,$2);1356if(length($mid) >5) {1357$mid=" ... ";1358}1359return"$left$mid$right";13601361}else{1362$str=~m/^($endre)(.*)$/;1363my$body=$1;1364my$tail=$2;1365if(length($tail) >4) {1366$tail="... ";1367}1368return"$body$tail";1369}1370}13711372# takes the same arguments as chop_str, but also wraps a <span> around the1373# result with a title attribute if it does get chopped. Additionally, the1374# string is HTML-escaped.1375sub chop_and_escape_str {1376my($str) =@_;13771378my$chopped= chop_str(@_);1379if($choppedeq$str) {1380return esc_html($chopped);1381}else{1382$str=~s/[[:cntrl:]]/?/g;1383return$cgi->span({-title=>$str}, esc_html($chopped));1384}1385}13861387## ----------------------------------------------------------------------1388## functions returning short strings13891390# CSS class for given age value (in seconds)1391sub age_class {1392my$age=shift;13931394if(!defined$age) {1395return"noage";1396}elsif($age<60*60*2) {1397return"age0";1398}elsif($age<60*60*24*2) {1399return"age1";1400}else{1401return"age2";1402}1403}14041405# convert age in seconds to "nn units ago" string1406sub age_string {1407my$age=shift;1408my$age_str;14091410if($age>60*60*24*365*2) {1411$age_str= (int$age/60/60/24/365);1412$age_str.=" years ago";1413}elsif($age>60*60*24*(365/12)*2) {1414$age_str=int$age/60/60/24/(365/12);1415$age_str.=" months ago";1416}elsif($age>60*60*24*7*2) {1417$age_str=int$age/60/60/24/7;1418$age_str.=" weeks ago";1419}elsif($age>60*60*24*2) {1420$age_str=int$age/60/60/24;1421$age_str.=" days ago";1422}elsif($age>60*60*2) {1423$age_str=int$age/60/60;1424$age_str.=" hours ago";1425}elsif($age>60*2) {1426$age_str=int$age/60;1427$age_str.=" min ago";1428}elsif($age>2) {1429$age_str=int$age;1430$age_str.=" sec ago";1431}else{1432$age_str.=" right now";1433}1434return$age_str;1435}14361437useconstant{1438 S_IFINVALID =>0030000,1439 S_IFGITLINK =>0160000,1440};14411442# submodule/subproject, a commit object reference1443sub S_ISGITLINK {1444my$mode=shift;14451446return(($mode& S_IFMT) == S_IFGITLINK)1447}14481449# convert file mode in octal to symbolic file mode string1450sub mode_str {1451my$mode=oct shift;14521453if(S_ISGITLINK($mode)) {1454return'm---------';1455}elsif(S_ISDIR($mode& S_IFMT)) {1456return'drwxr-xr-x';1457}elsif(S_ISLNK($mode)) {1458return'lrwxrwxrwx';1459}elsif(S_ISREG($mode)) {1460# git cares only about the executable bit1461if($mode& S_IXUSR) {1462return'-rwxr-xr-x';1463}else{1464return'-rw-r--r--';1465};1466}else{1467return'----------';1468}1469}14701471# convert file mode in octal to file type string1472sub file_type {1473my$mode=shift;14741475if($mode!~m/^[0-7]+$/) {1476return$mode;1477}else{1478$mode=oct$mode;1479}14801481if(S_ISGITLINK($mode)) {1482return"submodule";1483}elsif(S_ISDIR($mode& S_IFMT)) {1484return"directory";1485}elsif(S_ISLNK($mode)) {1486return"symlink";1487}elsif(S_ISREG($mode)) {1488return"file";1489}else{1490return"unknown";1491}1492}14931494# convert file mode in octal to file type description string1495sub file_type_long {1496my$mode=shift;14971498if($mode!~m/^[0-7]+$/) {1499return$mode;1500}else{1501$mode=oct$mode;1502}15031504if(S_ISGITLINK($mode)) {1505return"submodule";1506}elsif(S_ISDIR($mode& S_IFMT)) {1507return"directory";1508}elsif(S_ISLNK($mode)) {1509return"symlink";1510}elsif(S_ISREG($mode)) {1511if($mode& S_IXUSR) {1512return"executable";1513}else{1514return"file";1515};1516}else{1517return"unknown";1518}1519}152015211522## ----------------------------------------------------------------------1523## functions returning short HTML fragments, or transforming HTML fragments1524## which don't belong to other sections15251526# format line of commit message.1527sub format_log_line_html {1528my$line=shift;15291530$line= esc_html($line, -nbsp=>1);1531$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1532$cgi->a({-href => href(action=>"object", hash=>$1),1533-class=>"text"},$1);1534}eg;15351536return$line;1537}15381539# format marker of refs pointing to given object15401541# the destination action is chosen based on object type and current context:1542# - for annotated tags, we choose the tag view unless it's the current view1543# already, in which case we go to shortlog view1544# - for other refs, we keep the current view if we're in history, shortlog or1545# log view, and select shortlog otherwise1546sub format_ref_marker {1547my($refs,$id) =@_;1548my$markers='';15491550if(defined$refs->{$id}) {1551foreachmy$ref(@{$refs->{$id}}) {1552# this code exploits the fact that non-lightweight tags are the1553# only indirect objects, and that they are the only objects for which1554# we want to use tag instead of shortlog as action1555my($type,$name) =qw();1556my$indirect= ($ref=~s/\^\{\}$//);1557# e.g. tags/v2.6.11 or heads/next1558if($ref=~m!^(.*?)s?/(.*)$!) {1559$type=$1;1560$name=$2;1561}else{1562$type="ref";1563$name=$ref;1564}15651566my$class=$type;1567$class.=" indirect"if$indirect;15681569my$dest_action="shortlog";15701571if($indirect) {1572$dest_action="tag"unless$actioneq"tag";1573}elsif($action=~/^(history|(short)?log)$/) {1574$dest_action=$action;1575}15761577my$dest="";1578$dest.="refs/"unless$ref=~ m!^refs/!;1579$dest.=$ref;15801581my$link=$cgi->a({1582-href => href(1583 action=>$dest_action,1584 hash=>$dest1585)},$name);15861587$markers.=" <span class=\"$class\"title=\"$ref\">".1588$link."</span>";1589}1590}15911592if($markers) {1593return' <span class="refs">'.$markers.'</span>';1594}else{1595return"";1596}1597}15981599# format, perhaps shortened and with markers, title line1600sub format_subject_html {1601my($long,$short,$href,$extra) =@_;1602$extra=''unlessdefined($extra);16031604if(length($short) <length($long)) {1605$long=~s/[[:cntrl:]]/?/g;1606return$cgi->a({-href =>$href, -class=>"list subject",1607-title => to_utf8($long)},1608 esc_html($short)) .$extra;1609}else{1610return$cgi->a({-href =>$href, -class=>"list subject"},1611 esc_html($long)) .$extra;1612}1613}16141615# Rather than recomputing the url for an email multiple times, we cache it1616# after the first hit. This gives a visible benefit in views where the avatar1617# for the same email is used repeatedly (e.g. shortlog).1618# The cache is shared by all avatar engines (currently gravatar only), which1619# are free to use it as preferred. Since only one avatar engine is used for any1620# given page, there's no risk for cache conflicts.1621our%avatar_cache= ();16221623# Compute the picon url for a given email, by using the picon search service over at1624# http://www.cs.indiana.edu/picons/search.html1625sub picon_url {1626my$email=lc shift;1627if(!$avatar_cache{$email}) {1628my($user,$domain) =split('@',$email);1629$avatar_cache{$email} =1630"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".1631"$domain/$user/".1632"users+domains+unknown/up/single";1633}1634return$avatar_cache{$email};1635}16361637# Compute the gravatar url for a given email, if it's not in the cache already.1638# Gravatar stores only the part of the URL before the size, since that's the1639# one computationally more expensive. This also allows reuse of the cache for1640# different sizes (for this particular engine).1641sub gravatar_url {1642my$email=lc shift;1643my$size=shift;1644$avatar_cache{$email} ||=1645"http://www.gravatar.com/avatar/".1646 Digest::MD5::md5_hex($email) ."?s=";1647return$avatar_cache{$email} .$size;1648}16491650# Insert an avatar for the given $email at the given $size if the feature1651# is enabled.1652sub git_get_avatar {1653my($email,%opts) =@_;1654my$pre_white= ($opts{-pad_before} ?" ":"");1655my$post_white= ($opts{-pad_after} ?" ":"");1656$opts{-size} ||='default';1657my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};1658my$url="";1659if($git_avatareq'gravatar') {1660$url= gravatar_url($email,$size);1661}elsif($git_avatareq'picon') {1662$url= picon_url($email);1663}1664# Other providers can be added by extending the if chain, defining $url1665# as needed. If no variant puts something in $url, we assume avatars1666# are completely disabled/unavailable.1667if($url) {1668return$pre_white.1669"<img width=\"$size\"".1670"class=\"avatar\"".1671"src=\"$url\"".1672"alt=\"\"".1673"/>".$post_white;1674}else{1675return"";1676}1677}16781679sub format_search_author {1680my($author,$searchtype,$displaytext) =@_;1681my$have_search= gitweb_check_feature('search');16821683if($have_search) {1684my$performed="";1685if($searchtypeeq'author') {1686$performed="authored";1687}elsif($searchtypeeq'committer') {1688$performed="committed";1689}16901691return$cgi->a({-href => href(action=>"search", hash=>$hash,1692 searchtext=>$author,1693 searchtype=>$searchtype),class=>"list",1694 title=>"Search for commits$performedby$author"},1695$displaytext);16961697}else{1698return$displaytext;1699}1700}17011702# format the author name of the given commit with the given tag1703# the author name is chopped and escaped according to the other1704# optional parameters (see chop_str).1705sub format_author_html {1706my$tag=shift;1707my$co=shift;1708my$author= chop_and_escape_str($co->{'author_name'},@_);1709return"<$tagclass=\"author\">".1710 format_search_author($co->{'author_name'},"author",1711 git_get_avatar($co->{'author_email'}, -pad_after =>1) .1712$author) .1713"</$tag>";1714}17151716# format git diff header line, i.e. "diff --(git|combined|cc) ..."1717sub format_git_diff_header_line {1718my$line=shift;1719my$diffinfo=shift;1720my($from,$to) =@_;17211722if($diffinfo->{'nparents'}) {1723# combined diff1724$line=~s!^(diff (.*?) )"?.*$!$1!;1725if($to->{'href'}) {1726$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1727 esc_path($to->{'file'}));1728}else{# file was deleted (no href)1729$line.= esc_path($to->{'file'});1730}1731}else{1732# "ordinary" diff1733$line=~s!^(diff (.*?) )"?a/.*$!$1!;1734if($from->{'href'}) {1735$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1736'a/'. esc_path($from->{'file'}));1737}else{# file was added (no href)1738$line.='a/'. esc_path($from->{'file'});1739}1740$line.=' ';1741if($to->{'href'}) {1742$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1743'b/'. esc_path($to->{'file'}));1744}else{# file was deleted1745$line.='b/'. esc_path($to->{'file'});1746}1747}17481749return"<div class=\"diff header\">$line</div>\n";1750}17511752# format extended diff header line, before patch itself1753sub format_extended_diff_header_line {1754my$line=shift;1755my$diffinfo=shift;1756my($from,$to) =@_;17571758# match <path>1759if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1760$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1761 esc_path($from->{'file'}));1762}1763if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1764$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1765 esc_path($to->{'file'}));1766}1767# match single <mode>1768if($line=~m/\s(\d{6})$/) {1769$line.='<span class="info"> ('.1770 file_type_long($1) .1771')</span>';1772}1773# match <hash>1774if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1775# can match only for combined diff1776$line='index ';1777for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1778if($from->{'href'}[$i]) {1779$line.=$cgi->a({-href=>$from->{'href'}[$i],1780-class=>"hash"},1781substr($diffinfo->{'from_id'}[$i],0,7));1782}else{1783$line.='0' x 7;1784}1785# separator1786$line.=','if($i<$diffinfo->{'nparents'} -1);1787}1788$line.='..';1789if($to->{'href'}) {1790$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1791substr($diffinfo->{'to_id'},0,7));1792}else{1793$line.='0' x 7;1794}17951796}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1797# can match only for ordinary diff1798my($from_link,$to_link);1799if($from->{'href'}) {1800$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1801substr($diffinfo->{'from_id'},0,7));1802}else{1803$from_link='0' x 7;1804}1805if($to->{'href'}) {1806$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1807substr($diffinfo->{'to_id'},0,7));1808}else{1809$to_link='0' x 7;1810}1811my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1812$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1813}18141815return$line."<br/>\n";1816}18171818# format from-file/to-file diff header1819sub format_diff_from_to_header {1820my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1821my$line;1822my$result='';18231824$line=$from_line;1825#assert($line =~ m/^---/) if DEBUG;1826# no extra formatting for "^--- /dev/null"1827if(!$diffinfo->{'nparents'}) {1828# ordinary (single parent) diff1829if($line=~m!^--- "?a/!) {1830if($from->{'href'}) {1831$line='--- a/'.1832$cgi->a({-href=>$from->{'href'}, -class=>"path"},1833 esc_path($from->{'file'}));1834}else{1835$line='--- a/'.1836 esc_path($from->{'file'});1837}1838}1839$result.= qq!<div class="diff from_file">$line</div>\n!;18401841}else{1842# combined diff (merge commit)1843for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1844if($from->{'href'}[$i]) {1845$line='--- '.1846$cgi->a({-href=>href(action=>"blobdiff",1847 hash_parent=>$diffinfo->{'from_id'}[$i],1848 hash_parent_base=>$parents[$i],1849 file_parent=>$from->{'file'}[$i],1850 hash=>$diffinfo->{'to_id'},1851 hash_base=>$hash,1852 file_name=>$to->{'file'}),1853-class=>"path",1854-title=>"diff". ($i+1)},1855$i+1) .1856'/'.1857$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1858 esc_path($from->{'file'}[$i]));1859}else{1860$line='--- /dev/null';1861}1862$result.= qq!<div class="diff from_file">$line</div>\n!;1863}1864}18651866$line=$to_line;1867#assert($line =~ m/^\+\+\+/) if DEBUG;1868# no extra formatting for "^+++ /dev/null"1869if($line=~m!^\+\+\+ "?b/!) {1870if($to->{'href'}) {1871$line='+++ b/'.1872$cgi->a({-href=>$to->{'href'}, -class=>"path"},1873 esc_path($to->{'file'}));1874}else{1875$line='+++ b/'.1876 esc_path($to->{'file'});1877}1878}1879$result.= qq!<div class="diff to_file">$line</div>\n!;18801881return$result;1882}18831884# create note for patch simplified by combined diff1885sub format_diff_cc_simplified {1886my($diffinfo,@parents) =@_;1887my$result='';18881889$result.="<div class=\"diff header\">".1890"diff --cc ";1891if(!is_deleted($diffinfo)) {1892$result.=$cgi->a({-href => href(action=>"blob",1893 hash_base=>$hash,1894 hash=>$diffinfo->{'to_id'},1895 file_name=>$diffinfo->{'to_file'}),1896-class=>"path"},1897 esc_path($diffinfo->{'to_file'}));1898}else{1899$result.= esc_path($diffinfo->{'to_file'});1900}1901$result.="</div>\n".# class="diff header"1902"<div class=\"diff nodifferences\">".1903"Simple merge".1904"</div>\n";# class="diff nodifferences"19051906return$result;1907}19081909# format patch (diff) line (not to be used for diff headers)1910sub format_diff_line {1911my$line=shift;1912my($from,$to) =@_;1913my$diff_class="";19141915chomp$line;19161917if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1918# combined diff1919my$prefix=substr($line,0,scalar@{$from->{'href'}});1920if($line=~m/^\@{3}/) {1921$diff_class=" chunk_header";1922}elsif($line=~m/^\\/) {1923$diff_class=" incomplete";1924}elsif($prefix=~tr/+/+/) {1925$diff_class=" add";1926}elsif($prefix=~tr/-/-/) {1927$diff_class=" rem";1928}1929}else{1930# assume ordinary diff1931my$char=substr($line,0,1);1932if($chareq'+') {1933$diff_class=" add";1934}elsif($chareq'-') {1935$diff_class=" rem";1936}elsif($chareq'@') {1937$diff_class=" chunk_header";1938}elsif($chareq"\\") {1939$diff_class=" incomplete";1940}1941}1942$line= untabify($line);1943if($from&&$to&&$line=~m/^\@{2} /) {1944my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1945$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;19461947$from_lines=0unlessdefined$from_lines;1948$to_lines=0unlessdefined$to_lines;19491950if($from->{'href'}) {1951$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1952-class=>"list"},$from_text);1953}1954if($to->{'href'}) {1955$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1956-class=>"list"},$to_text);1957}1958$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1959"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1960return"<div class=\"diff$diff_class\">$line</div>\n";1961}elsif($from&&$to&&$line=~m/^\@{3}/) {1962my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1963my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);19641965@from_text=split(' ',$ranges);1966for(my$i=0;$i<@from_text; ++$i) {1967($from_start[$i],$from_nlines[$i]) =1968(split(',',substr($from_text[$i],1)),0);1969}19701971$to_text=pop@from_text;1972$to_start=pop@from_start;1973$to_nlines=pop@from_nlines;19741975$line="<span class=\"chunk_info\">$prefix";1976for(my$i=0;$i<@from_text; ++$i) {1977if($from->{'href'}[$i]) {1978$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1979-class=>"list"},$from_text[$i]);1980}else{1981$line.=$from_text[$i];1982}1983$line.=" ";1984}1985if($to->{'href'}) {1986$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1987-class=>"list"},$to_text);1988}else{1989$line.=$to_text;1990}1991$line.="$prefix</span>".1992"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1993return"<div class=\"diff$diff_class\">$line</div>\n";1994}1995return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1996}19971998# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1999# linked. Pass the hash of the tree/commit to snapshot.2000sub format_snapshot_links {2001my($hash) =@_;2002my$num_fmts=@snapshot_fmts;2003if($num_fmts>1) {2004# A parenthesized list of links bearing format names.2005# e.g. "snapshot (_tar.gz_ _zip_)"2006return"snapshot (".join(' ',map2007$cgi->a({2008-href => href(2009 action=>"snapshot",2010 hash=>$hash,2011 snapshot_format=>$_2012)2013},$known_snapshot_formats{$_}{'display'})2014,@snapshot_fmts) .")";2015}elsif($num_fmts==1) {2016# A single "snapshot" link whose tooltip bears the format name.2017# i.e. "_snapshot_"2018my($fmt) =@snapshot_fmts;2019return2020$cgi->a({2021-href => href(2022 action=>"snapshot",2023 hash=>$hash,2024 snapshot_format=>$fmt2025),2026-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"2027},"snapshot");2028}else{# $num_fmts == 02029returnundef;2030}2031}20322033## ......................................................................2034## functions returning values to be passed, perhaps after some2035## transformation, to other functions; e.g. returning arguments to href()20362037# returns hash to be passed to href to generate gitweb URL2038# in -title key it returns description of link2039sub get_feed_info {2040my$format=shift||'Atom';2041my%res= (action =>lc($format));20422043# feed links are possible only for project views2044return unless(defined$project);2045# some views should link to OPML, or to generic project feed,2046# or don't have specific feed yet (so they should use generic)2047return if($action=~/^(?:tags|heads|forks|tag|search)$/x);20482049my$branch;2050# branches refs uses 'refs/heads/' prefix (fullname) to differentiate2051# from tag links; this also makes possible to detect branch links2052if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||2053(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {2054$branch=$1;2055}2056# find log type for feed description (title)2057my$type='log';2058if(defined$file_name) {2059$type="history of$file_name";2060$type.="/"if($actioneq'tree');2061$type.=" on '$branch'"if(defined$branch);2062}else{2063$type="log of$branch"if(defined$branch);2064}20652066$res{-title} =$type;2067$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);2068$res{'file_name'} =$file_name;20692070return%res;2071}20722073## ----------------------------------------------------------------------2074## git utility subroutines, invoking git commands20752076# returns path to the core git executable and the --git-dir parameter as list2077sub git_cmd {2078$number_of_git_cmds++;2079return$GIT,'--git-dir='.$git_dir;2080}20812082# quote the given arguments for passing them to the shell2083# quote_command("command", "arg 1", "arg with ' and ! characters")2084# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2085# Try to avoid using this function wherever possible.2086sub quote_command {2087returnjoin(' ',2088map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2089}20902091# get HEAD ref of given project as hash2092sub git_get_head_hash {2093return git_get_full_hash(shift,'HEAD');2094}20952096sub git_get_full_hash {2097return git_get_hash(@_);2098}20992100sub git_get_short_hash {2101return git_get_hash(@_,'--short=7');2102}21032104sub git_get_hash {2105my($project,$hash,@options) =@_;2106my$o_git_dir=$git_dir;2107my$retval=undef;2108$git_dir="$projectroot/$project";2109if(open my$fd,'-|', git_cmd(),'rev-parse',2110'--verify','-q',@options,$hash) {2111$retval= <$fd>;2112chomp$retvalifdefined$retval;2113close$fd;2114}2115if(defined$o_git_dir) {2116$git_dir=$o_git_dir;2117}2118return$retval;2119}21202121# get type of given object2122sub git_get_type {2123my$hash=shift;21242125open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2126my$type= <$fd>;2127close$fdorreturn;2128chomp$type;2129return$type;2130}21312132# repository configuration2133our$config_file='';2134our%config;21352136# store multiple values for single key as anonymous array reference2137# single values stored directly in the hash, not as [ <value> ]2138sub hash_set_multi {2139my($hash,$key,$value) =@_;21402141if(!exists$hash->{$key}) {2142$hash->{$key} =$value;2143}elsif(!ref$hash->{$key}) {2144$hash->{$key} = [$hash->{$key},$value];2145}else{2146push@{$hash->{$key}},$value;2147}2148}21492150# return hash of git project configuration2151# optionally limited to some section, e.g. 'gitweb'2152sub git_parse_project_config {2153my$section_regexp=shift;2154my%config;21552156local$/="\0";21572158open my$fh,"-|", git_cmd(),"config",'-z','-l',2159orreturn;21602161while(my$keyval= <$fh>) {2162chomp$keyval;2163my($key,$value) =split(/\n/,$keyval,2);21642165 hash_set_multi(\%config,$key,$value)2166if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2167}2168close$fh;21692170return%config;2171}21722173# convert config value to boolean: 'true' or 'false'2174# no value, number > 0, 'true' and 'yes' values are true2175# rest of values are treated as false (never as error)2176sub config_to_bool {2177my$val=shift;21782179return1if!defined$val;# section.key21802181# strip leading and trailing whitespace2182$val=~s/^\s+//;2183$val=~s/\s+$//;21842185return(($val=~/^\d+$/&&$val) ||# section.key = 12186($val=~/^(?:true|yes)$/i));# section.key = true2187}21882189# convert config value to simple decimal number2190# an optional value suffix of 'k', 'm', or 'g' will cause the value2191# to be multiplied by 1024, 1048576, or 10737418242192sub config_to_int {2193my$val=shift;21942195# strip leading and trailing whitespace2196$val=~s/^\s+//;2197$val=~s/\s+$//;21982199if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2200$unit=lc($unit);2201# unknown unit is treated as 12202return$num* ($uniteq'g'?1073741824:2203$uniteq'm'?1048576:2204$uniteq'k'?1024:1);2205}2206return$val;2207}22082209# convert config value to array reference, if needed2210sub config_to_multi {2211my$val=shift;22122213returnref($val) ?$val: (defined($val) ? [$val] : []);2214}22152216sub git_get_project_config {2217my($key,$type) =@_;22182219# do we have project2220return unless(defined$project&&defined$git_dir);22212222# key sanity check2223return unless($key);2224$key=~s/^gitweb\.//;2225return if($key=~m/\W/);22262227# type sanity check2228if(defined$type) {2229$type=~s/^--//;2230$type=undef2231unless($typeeq'bool'||$typeeq'int');2232}22332234# get config2235if(!defined$config_file||2236$config_filene"$git_dir/config") {2237%config= git_parse_project_config('gitweb');2238$config_file="$git_dir/config";2239}22402241# check if config variable (key) exists2242return unlessexists$config{"gitweb.$key"};22432244# ensure given type2245if(!defined$type) {2246return$config{"gitweb.$key"};2247}elsif($typeeq'bool') {2248# backward compatibility: 'git config --bool' returns true/false2249return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2250}elsif($typeeq'int') {2251return config_to_int($config{"gitweb.$key"});2252}2253return$config{"gitweb.$key"};2254}22552256# get hash of given path at given ref2257sub git_get_hash_by_path {2258my$base=shift;2259my$path=shift||returnundef;2260my$type=shift;22612262$path=~ s,/+$,,;22632264open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2265or die_error(500,"Open git-ls-tree failed");2266my$line= <$fd>;2267close$fdorreturnundef;22682269if(!defined$line) {2270# there is no tree or hash given by $path at $base2271returnundef;2272}22732274#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2275$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2276if(defined$type&&$typene$2) {2277# type doesn't match2278returnundef;2279}2280return$3;2281}22822283# get path of entry with given hash at given tree-ish (ref)2284# used to get 'from' filename for combined diff (merge commit) for renames2285sub git_get_path_by_hash {2286my$base=shift||return;2287my$hash=shift||return;22882289local$/="\0";22902291open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2292orreturnundef;2293while(my$line= <$fd>) {2294chomp$line;22952296#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2297#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2298if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2299close$fd;2300return$1;2301}2302}2303close$fd;2304returnundef;2305}23062307## ......................................................................2308## git utility functions, directly accessing git repository23092310sub git_get_project_description {2311my$path=shift;23122313$git_dir="$projectroot/$path";2314open my$fd,'<',"$git_dir/description"2315orreturn git_get_project_config('description');2316my$descr= <$fd>;2317close$fd;2318if(defined$descr) {2319chomp$descr;2320}2321return$descr;2322}23232324sub git_get_project_ctags {2325my$path=shift;2326my$ctags= {};23272328$git_dir="$projectroot/$path";2329opendir my$dh,"$git_dir/ctags"2330orreturn$ctags;2331foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2332open my$ct,'<',$_ornext;2333my$val= <$ct>;2334chomp$val;2335close$ct;2336my$ctag=$_;$ctag=~ s#.*/##;2337$ctags->{$ctag} =$val;2338}2339closedir$dh;2340$ctags;2341}23422343sub git_populate_project_tagcloud {2344my$ctags=shift;23452346# First, merge different-cased tags; tags vote on casing2347my%ctags_lc;2348foreach(keys%$ctags) {2349$ctags_lc{lc$_}->{count} +=$ctags->{$_};2350if(not$ctags_lc{lc$_}->{topcount}2351or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2352$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2353$ctags_lc{lc$_}->{topname} =$_;2354}2355}23562357my$cloud;2358if(eval{require HTML::TagCloud;1; }) {2359$cloud= HTML::TagCloud->new;2360foreach(sort keys%ctags_lc) {2361# Pad the title with spaces so that the cloud looks2362# less crammed.2363my$title=$ctags_lc{$_}->{topname};2364$title=~s/ / /g;2365$title=~s/^/ /g;2366$title=~s/$/ /g;2367$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2368}2369}else{2370$cloud= \%ctags_lc;2371}2372$cloud;2373}23742375sub git_show_project_tagcloud {2376my($cloud,$count) =@_;2377print STDERR ref($cloud)."..\n";2378if(ref$cloudeq'HTML::TagCloud') {2379return$cloud->html_and_css($count);2380}else{2381my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2382return'<p align="center">'.join(', ',map{2383"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"2384}splice(@tags,0,$count)) .'</p>';2385}2386}23872388sub git_get_project_url_list {2389my$path=shift;23902391$git_dir="$projectroot/$path";2392open my$fd,'<',"$git_dir/cloneurl"2393orreturnwantarray?2394@{ config_to_multi(git_get_project_config('url')) } :2395 config_to_multi(git_get_project_config('url'));2396my@git_project_url_list=map{chomp;$_} <$fd>;2397close$fd;23982399returnwantarray?@git_project_url_list: \@git_project_url_list;2400}24012402sub git_get_projects_list {2403my($filter) =@_;2404my@list;24052406$filter||='';2407$filter=~s/\.git$//;24082409my$check_forks= gitweb_check_feature('forks');24102411if(-d $projects_list) {2412# search in directory2413my$dir=$projects_list. ($filter?"/$filter":'');2414# remove the trailing "/"2415$dir=~s!/+$!!;2416my$pfxlen=length("$dir");2417my$pfxdepth= ($dir=~tr!/!!);24182419 File::Find::find({2420 follow_fast =>1,# follow symbolic links2421 follow_skip =>2,# ignore duplicates2422 dangling_symlinks =>0,# ignore dangling symlinks, silently2423 wanted =>sub{2424# skip project-list toplevel, if we get it.2425return if(m!^[/.]$!);2426# only directories can be git repositories2427return unless(-d $_);2428# don't traverse too deep (Find is super slow on os x)2429if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2430$File::Find::prune =1;2431return;2432}24332434my$subdir=substr($File::Find::name,$pfxlen+1);2435# we check related file in $projectroot2436my$path= ($filter?"$filter/":'') .$subdir;2437if(check_export_ok("$projectroot/$path")) {2438push@list, { path =>$path};2439$File::Find::prune =1;2440}2441},2442},"$dir");24432444}elsif(-f $projects_list) {2445# read from file(url-encoded):2446# 'git%2Fgit.git Linus+Torvalds'2447# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2448# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2449my%paths;2450open my$fd,'<',$projects_listorreturn;2451 PROJECT:2452while(my$line= <$fd>) {2453chomp$line;2454my($path,$owner) =split' ',$line;2455$path= unescape($path);2456$owner= unescape($owner);2457if(!defined$path) {2458next;2459}2460if($filterne'') {2461# looking for forks;2462my$pfx=substr($path,0,length($filter));2463if($pfxne$filter) {2464next PROJECT;2465}2466my$sfx=substr($path,length($filter));2467if($sfx!~/^\/.*\.git$/) {2468next PROJECT;2469}2470}elsif($check_forks) {2471 PATH:2472foreachmy$filter(keys%paths) {2473# looking for forks;2474my$pfx=substr($path,0,length($filter));2475if($pfxne$filter) {2476next PATH;2477}2478my$sfx=substr($path,length($filter));2479if($sfx!~/^\/.*\.git$/) {2480next PATH;2481}2482# is a fork, don't include it in2483# the list2484next PROJECT;2485}2486}2487if(check_export_ok("$projectroot/$path")) {2488my$pr= {2489 path =>$path,2490 owner => to_utf8($owner),2491};2492push@list,$pr;2493(my$forks_path=$path) =~s/\.git$//;2494$paths{$forks_path}++;2495}2496}2497close$fd;2498}2499return@list;2500}25012502our$gitweb_project_owner=undef;2503sub git_get_project_list_from_file {25042505return if(defined$gitweb_project_owner);25062507$gitweb_project_owner= {};2508# read from file (url-encoded):2509# 'git%2Fgit.git Linus+Torvalds'2510# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2511# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2512if(-f $projects_list) {2513open(my$fd,'<',$projects_list);2514while(my$line= <$fd>) {2515chomp$line;2516my($pr,$ow) =split' ',$line;2517$pr= unescape($pr);2518$ow= unescape($ow);2519$gitweb_project_owner->{$pr} = to_utf8($ow);2520}2521close$fd;2522}2523}25242525sub git_get_project_owner {2526my$project=shift;2527my$owner;25282529returnundefunless$project;2530$git_dir="$projectroot/$project";25312532if(!defined$gitweb_project_owner) {2533 git_get_project_list_from_file();2534}25352536if(exists$gitweb_project_owner->{$project}) {2537$owner=$gitweb_project_owner->{$project};2538}2539if(!defined$owner){2540$owner= git_get_project_config('owner');2541}2542if(!defined$owner) {2543$owner= get_file_owner("$git_dir");2544}25452546return$owner;2547}25482549sub git_get_last_activity {2550my($path) =@_;2551my$fd;25522553$git_dir="$projectroot/$path";2554open($fd,"-|", git_cmd(),'for-each-ref',2555'--format=%(committer)',2556'--sort=-committerdate',2557'--count=1',2558'refs/heads')orreturn;2559my$most_recent= <$fd>;2560close$fdorreturn;2561if(defined$most_recent&&2562$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2563my$timestamp=$1;2564my$age=time-$timestamp;2565return($age, age_string($age));2566}2567return(undef,undef);2568}25692570sub git_get_references {2571my$type=shift||"";2572my%refs;2573# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112574# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2575open my$fd,"-|", git_cmd(),"show-ref","--dereference",2576($type? ("--","refs/$type") : ())# use -- <pattern> if $type2577orreturn;25782579while(my$line= <$fd>) {2580chomp$line;2581if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2582if(defined$refs{$1}) {2583push@{$refs{$1}},$2;2584}else{2585$refs{$1} = [$2];2586}2587}2588}2589close$fdorreturn;2590return \%refs;2591}25922593sub git_get_rev_name_tags {2594my$hash=shift||returnundef;25952596open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2597orreturn;2598my$name_rev= <$fd>;2599close$fd;26002601if($name_rev=~ m|^$hash tags/(.*)$|) {2602return$1;2603}else{2604# catches also '$hash undefined' output2605returnundef;2606}2607}26082609## ----------------------------------------------------------------------2610## parse to hash functions26112612sub parse_date {2613my$epoch=shift;2614my$tz=shift||"-0000";26152616my%date;2617my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2618my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2619my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2620$date{'hour'} =$hour;2621$date{'minute'} =$min;2622$date{'mday'} =$mday;2623$date{'day'} =$days[$wday];2624$date{'month'} =$months[$mon];2625$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2626$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2627$date{'mday-time'} =sprintf"%d%s%02d:%02d",2628$mday,$months[$mon],$hour,$min;2629$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",26301900+$year,1+$mon,$mday,$hour,$min,$sec;26312632$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2633my$local=$epoch+ ((int$1+ ($2/60)) *3600);2634($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2635$date{'hour_local'} =$hour;2636$date{'minute_local'} =$min;2637$date{'tz_local'} =$tz;2638$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",26391900+$year,$mon+1,$mday,2640$hour,$min,$sec,$tz);2641return%date;2642}26432644sub parse_tag {2645my$tag_id=shift;2646my%tag;2647my@comment;26482649open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2650$tag{'id'} =$tag_id;2651while(my$line= <$fd>) {2652chomp$line;2653if($line=~m/^object ([0-9a-fA-F]{40})$/) {2654$tag{'object'} =$1;2655}elsif($line=~m/^type (.+)$/) {2656$tag{'type'} =$1;2657}elsif($line=~m/^tag (.+)$/) {2658$tag{'name'} =$1;2659}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2660$tag{'author'} =$1;2661$tag{'author_epoch'} =$2;2662$tag{'author_tz'} =$3;2663if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {2664$tag{'author_name'} =$1;2665$tag{'author_email'} =$2;2666}else{2667$tag{'author_name'} =$tag{'author'};2668}2669}elsif($line=~m/--BEGIN/) {2670push@comment,$line;2671last;2672}elsif($lineeq"") {2673last;2674}2675}2676push@comment, <$fd>;2677$tag{'comment'} = \@comment;2678close$fdorreturn;2679if(!defined$tag{'name'}) {2680return2681};2682return%tag2683}26842685sub parse_commit_text {2686my($commit_text,$withparents) =@_;2687my@commit_lines=split'\n',$commit_text;2688my%co;26892690pop@commit_lines;# Remove '\0'26912692if(!@commit_lines) {2693return;2694}26952696my$header=shift@commit_lines;2697if($header!~m/^[0-9a-fA-F]{40}/) {2698return;2699}2700($co{'id'},my@parents) =split' ',$header;2701while(my$line=shift@commit_lines) {2702last if$lineeq"\n";2703if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2704$co{'tree'} =$1;2705}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2706push@parents,$1;2707}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2708$co{'author'} = to_utf8($1);2709$co{'author_epoch'} =$2;2710$co{'author_tz'} =$3;2711if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2712$co{'author_name'} =$1;2713$co{'author_email'} =$2;2714}else{2715$co{'author_name'} =$co{'author'};2716}2717}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2718$co{'committer'} = to_utf8($1);2719$co{'committer_epoch'} =$2;2720$co{'committer_tz'} =$3;2721if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2722$co{'committer_name'} =$1;2723$co{'committer_email'} =$2;2724}else{2725$co{'committer_name'} =$co{'committer'};2726}2727}2728}2729if(!defined$co{'tree'}) {2730return;2731};2732$co{'parents'} = \@parents;2733$co{'parent'} =$parents[0];27342735foreachmy$title(@commit_lines) {2736$title=~s/^ //;2737if($titlene"") {2738$co{'title'} = chop_str($title,80,5);2739# remove leading stuff of merges to make the interesting part visible2740if(length($title) >50) {2741$title=~s/^Automatic //;2742$title=~s/^merge (of|with) /Merge ... /i;2743if(length($title) >50) {2744$title=~s/(http|rsync):\/\///;2745}2746if(length($title) >50) {2747$title=~s/(master|www|rsync)\.//;2748}2749if(length($title) >50) {2750$title=~s/kernel.org:?//;2751}2752if(length($title) >50) {2753$title=~s/\/pub\/scm//;2754}2755}2756$co{'title_short'} = chop_str($title,50,5);2757last;2758}2759}2760if(!defined$co{'title'} ||$co{'title'}eq"") {2761$co{'title'} =$co{'title_short'} ='(no commit message)';2762}2763# remove added spaces2764foreachmy$line(@commit_lines) {2765$line=~s/^ //;2766}2767$co{'comment'} = \@commit_lines;27682769my$age=time-$co{'committer_epoch'};2770$co{'age'} =$age;2771$co{'age_string'} = age_string($age);2772my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2773if($age>60*60*24*7*2) {2774$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2775$co{'age_string_age'} =$co{'age_string'};2776}else{2777$co{'age_string_date'} =$co{'age_string'};2778$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2779}2780return%co;2781}27822783sub parse_commit {2784my($commit_id) =@_;2785my%co;27862787local$/="\0";27882789open my$fd,"-|", git_cmd(),"rev-list",2790"--parents",2791"--header",2792"--max-count=1",2793$commit_id,2794"--",2795or die_error(500,"Open git-rev-list failed");2796%co= parse_commit_text(<$fd>,1);2797close$fd;27982799return%co;2800}28012802sub parse_commits {2803my($commit_id,$maxcount,$skip,$filename,@args) =@_;2804my@cos;28052806$maxcount||=1;2807$skip||=0;28082809local$/="\0";28102811open my$fd,"-|", git_cmd(),"rev-list",2812"--header",2813@args,2814("--max-count=".$maxcount),2815("--skip=".$skip),2816@extra_options,2817$commit_id,2818"--",2819($filename? ($filename) : ())2820or die_error(500,"Open git-rev-list failed");2821while(my$line= <$fd>) {2822my%co= parse_commit_text($line);2823push@cos, \%co;2824}2825close$fd;28262827returnwantarray?@cos: \@cos;2828}28292830# parse line of git-diff-tree "raw" output2831sub parse_difftree_raw_line {2832my$line=shift;2833my%res;28342835# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2836# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2837if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2838$res{'from_mode'} =$1;2839$res{'to_mode'} =$2;2840$res{'from_id'} =$3;2841$res{'to_id'} =$4;2842$res{'status'} =$5;2843$res{'similarity'} =$6;2844if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2845($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2846}else{2847$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2848}2849}2850# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2851# combined diff (for merge commit)2852elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2853$res{'nparents'} =length($1);2854$res{'from_mode'} = [split(' ',$2) ];2855$res{'to_mode'} =pop@{$res{'from_mode'}};2856$res{'from_id'} = [split(' ',$3) ];2857$res{'to_id'} =pop@{$res{'from_id'}};2858$res{'status'} = [split('',$4) ];2859$res{'to_file'} = unquote($5);2860}2861# 'c512b523472485aef4fff9e57b229d9d243c967f'2862elsif($line=~m/^([0-9a-fA-F]{40})$/) {2863$res{'commit'} =$1;2864}28652866returnwantarray?%res: \%res;2867}28682869# wrapper: return parsed line of git-diff-tree "raw" output2870# (the argument might be raw line, or parsed info)2871sub parsed_difftree_line {2872my$line_or_ref=shift;28732874if(ref($line_or_ref)eq"HASH") {2875# pre-parsed (or generated by hand)2876return$line_or_ref;2877}else{2878return parse_difftree_raw_line($line_or_ref);2879}2880}28812882# parse line of git-ls-tree output2883sub parse_ls_tree_line {2884my$line=shift;2885my%opts=@_;2886my%res;28872888if($opts{'-l'}) {2889#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'2890$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;28912892$res{'mode'} =$1;2893$res{'type'} =$2;2894$res{'hash'} =$3;2895$res{'size'} =$4;2896if($opts{'-z'}) {2897$res{'name'} =$5;2898}else{2899$res{'name'} = unquote($5);2900}2901}else{2902#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2903$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;29042905$res{'mode'} =$1;2906$res{'type'} =$2;2907$res{'hash'} =$3;2908if($opts{'-z'}) {2909$res{'name'} =$4;2910}else{2911$res{'name'} = unquote($4);2912}2913}29142915returnwantarray?%res: \%res;2916}29172918# generates _two_ hashes, references to which are passed as 2 and 3 argument2919sub parse_from_to_diffinfo {2920my($diffinfo,$from,$to,@parents) =@_;29212922if($diffinfo->{'nparents'}) {2923# combined diff2924$from->{'file'} = [];2925$from->{'href'} = [];2926 fill_from_file_info($diffinfo,@parents)2927unlessexists$diffinfo->{'from_file'};2928for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2929$from->{'file'}[$i] =2930defined$diffinfo->{'from_file'}[$i] ?2931$diffinfo->{'from_file'}[$i] :2932$diffinfo->{'to_file'};2933if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2934$from->{'href'}[$i] = href(action=>"blob",2935 hash_base=>$parents[$i],2936 hash=>$diffinfo->{'from_id'}[$i],2937 file_name=>$from->{'file'}[$i]);2938}else{2939$from->{'href'}[$i] =undef;2940}2941}2942}else{2943# ordinary (not combined) diff2944$from->{'file'} =$diffinfo->{'from_file'};2945if($diffinfo->{'status'}ne"A") {# not new (added) file2946$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2947 hash=>$diffinfo->{'from_id'},2948 file_name=>$from->{'file'});2949}else{2950delete$from->{'href'};2951}2952}29532954$to->{'file'} =$diffinfo->{'to_file'};2955if(!is_deleted($diffinfo)) {# file exists in result2956$to->{'href'} = href(action=>"blob", hash_base=>$hash,2957 hash=>$diffinfo->{'to_id'},2958 file_name=>$to->{'file'});2959}else{2960delete$to->{'href'};2961}2962}29632964## ......................................................................2965## parse to array of hashes functions29662967sub git_get_heads_list {2968my$limit=shift;2969my@headslist;29702971open my$fd,'-|', git_cmd(),'for-each-ref',2972($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2973'--format=%(objectname) %(refname) %(subject)%00%(committer)',2974'refs/heads'2975orreturn;2976while(my$line= <$fd>) {2977my%ref_item;29782979chomp$line;2980my($refinfo,$committerinfo) =split(/\0/,$line);2981my($hash,$name,$title) =split(' ',$refinfo,3);2982my($committer,$epoch,$tz) =2983($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2984$ref_item{'fullname'} =$name;2985$name=~s!^refs/heads/!!;29862987$ref_item{'name'} =$name;2988$ref_item{'id'} =$hash;2989$ref_item{'title'} =$title||'(no commit message)';2990$ref_item{'epoch'} =$epoch;2991if($epoch) {2992$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2993}else{2994$ref_item{'age'} ="unknown";2995}29962997push@headslist, \%ref_item;2998}2999close$fd;30003001returnwantarray?@headslist: \@headslist;3002}30033004sub git_get_tags_list {3005my$limit=shift;3006my@tagslist;30073008open my$fd,'-|', git_cmd(),'for-each-ref',3009($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',3010'--format=%(objectname) %(objecttype) %(refname) '.3011'%(*objectname) %(*objecttype) %(subject)%00%(creator)',3012'refs/tags'3013orreturn;3014while(my$line= <$fd>) {3015my%ref_item;30163017chomp$line;3018my($refinfo,$creatorinfo) =split(/\0/,$line);3019my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);3020my($creator,$epoch,$tz) =3021($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);3022$ref_item{'fullname'} =$name;3023$name=~s!^refs/tags/!!;30243025$ref_item{'type'} =$type;3026$ref_item{'id'} =$id;3027$ref_item{'name'} =$name;3028if($typeeq"tag") {3029$ref_item{'subject'} =$title;3030$ref_item{'reftype'} =$reftype;3031$ref_item{'refid'} =$refid;3032}else{3033$ref_item{'reftype'} =$type;3034$ref_item{'refid'} =$id;3035}30363037if($typeeq"tag"||$typeeq"commit") {3038$ref_item{'epoch'} =$epoch;3039if($epoch) {3040$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3041}else{3042$ref_item{'age'} ="unknown";3043}3044}30453046push@tagslist, \%ref_item;3047}3048close$fd;30493050returnwantarray?@tagslist: \@tagslist;3051}30523053## ----------------------------------------------------------------------3054## filesystem-related functions30553056sub get_file_owner {3057my$path=shift;30583059my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);3060my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);3061if(!defined$gcos) {3062returnundef;3063}3064my$owner=$gcos;3065$owner=~s/[,;].*$//;3066return to_utf8($owner);3067}30683069# assume that file exists3070sub insert_file {3071my$filename=shift;30723073open my$fd,'<',$filename;3074print map{ to_utf8($_) } <$fd>;3075close$fd;3076}30773078## ......................................................................3079## mimetype related functions30803081sub mimetype_guess_file {3082my$filename=shift;3083my$mimemap=shift;3084-r $mimemaporreturnundef;30853086my%mimemap;3087open(my$mh,'<',$mimemap)orreturnundef;3088while(<$mh>) {3089next ifm/^#/;# skip comments3090my($mimetype,$exts) =split(/\t+/);3091if(defined$exts) {3092my@exts=split(/\s+/,$exts);3093foreachmy$ext(@exts) {3094$mimemap{$ext} =$mimetype;3095}3096}3097}3098close($mh);30993100$filename=~/\.([^.]*)$/;3101return$mimemap{$1};3102}31033104sub mimetype_guess {3105my$filename=shift;3106my$mime;3107$filename=~/\./orreturnundef;31083109if($mimetypes_file) {3110my$file=$mimetypes_file;3111if($file!~m!^/!) {# if it is relative path3112# it is relative to project3113$file="$projectroot/$project/$file";3114}3115$mime= mimetype_guess_file($filename,$file);3116}3117$mime||= mimetype_guess_file($filename,'/etc/mime.types');3118return$mime;3119}31203121sub blob_mimetype {3122my$fd=shift;3123my$filename=shift;31243125if($filename) {3126my$mime= mimetype_guess($filename);3127$mimeandreturn$mime;3128}31293130# just in case3131return$default_blob_plain_mimetypeunless$fd;31323133if(-T $fd) {3134return'text/plain';3135}elsif(!$filename) {3136return'application/octet-stream';3137}elsif($filename=~m/\.png$/i) {3138return'image/png';3139}elsif($filename=~m/\.gif$/i) {3140return'image/gif';3141}elsif($filename=~m/\.jpe?g$/i) {3142return'image/jpeg';3143}else{3144return'application/octet-stream';3145}3146}31473148sub blob_contenttype {3149my($fd,$file_name,$type) =@_;31503151$type||= blob_mimetype($fd,$file_name);3152if($typeeq'text/plain'&&defined$default_text_plain_charset) {3153$type.="; charset=$default_text_plain_charset";3154}31553156return$type;3157}31583159## ======================================================================3160## functions printing HTML: header, footer, error page31613162sub git_header_html {3163my$status=shift||"200 OK";3164my$expires=shift;31653166my$title="$site_name";3167if(defined$project) {3168$title.=" - ". to_utf8($project);3169if(defined$action) {3170$title.="/$action";3171if(defined$file_name) {3172$title.=" - ". esc_path($file_name);3173if($actioneq"tree"&&$file_name!~ m|/$|) {3174$title.="/";3175}3176}3177}3178}3179my$content_type;3180# require explicit support from the UA if we are to send the page as3181# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3182# we have to do this because MSIE sometimes globs '*/*', pretending to3183# support xhtml+xml but choking when it gets what it asked for.3184if(defined$cgi->http('HTTP_ACCEPT') &&3185$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3186$cgi->Accept('application/xhtml+xml') !=0) {3187$content_type='application/xhtml+xml';3188}else{3189$content_type='text/html';3190}3191print$cgi->header(-type=>$content_type, -charset =>'utf-8',3192-status=>$status, -expires =>$expires);3193my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';3194print<<EOF;3195<?xml version="1.0" encoding="utf-8"?>3196<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">3197<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">3198<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->3199<!-- git core binaries version$git_version-->3200<head>3201<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>3202<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>3203<meta name="robots" content="index, nofollow"/>3204<title>$title</title>3205EOF3206# the stylesheet, favicon etc urls won't work correctly with path_info3207# unless we set the appropriate base URL3208if($ENV{'PATH_INFO'}) {3209print"<base href=\"".esc_url($base_url)."\"/>\n";3210}3211# print out each stylesheet that exist, providing backwards capability3212# for those people who defined $stylesheet in a config file3213if(defined$stylesheet) {3214print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3215}else{3216foreachmy$stylesheet(@stylesheets) {3217next unless$stylesheet;3218print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3219}3220}3221if(defined$project) {3222my%href_params= get_feed_info();3223if(!exists$href_params{'-title'}) {3224$href_params{'-title'} ='log';3225}32263227foreachmy$formatqw(RSS Atom){3228my$type=lc($format);3229my%link_attr= (3230'-rel'=>'alternate',3231'-title'=>"$project-$href_params{'-title'} -$formatfeed",3232'-type'=>"application/$type+xml"3233);32343235$href_params{'action'} =$type;3236$link_attr{'-href'} = href(%href_params);3237print"<link ".3238"rel=\"$link_attr{'-rel'}\"".3239"title=\"$link_attr{'-title'}\"".3240"href=\"$link_attr{'-href'}\"".3241"type=\"$link_attr{'-type'}\"".3242"/>\n";32433244$href_params{'extra_options'} ='--no-merges';3245$link_attr{'-href'} = href(%href_params);3246$link_attr{'-title'} .=' (no merges)';3247print"<link ".3248"rel=\"$link_attr{'-rel'}\"".3249"title=\"$link_attr{'-title'}\"".3250"href=\"$link_attr{'-href'}\"".3251"type=\"$link_attr{'-type'}\"".3252"/>\n";3253}32543255}else{3256printf('<link rel="alternate" title="%sprojects list" '.3257'href="%s" type="text/plain; charset=utf-8" />'."\n",3258$site_name, href(project=>undef, action=>"project_index"));3259printf('<link rel="alternate" title="%sprojects feeds" '.3260'href="%s" type="text/x-opml" />'."\n",3261$site_name, href(project=>undef, action=>"opml"));3262}3263if(defined$favicon) {3264printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);3265}32663267print"</head>\n".3268"<body>\n";32693270if(defined$site_header&& -f $site_header) {3271 insert_file($site_header);3272}32733274print"<div class=\"page_header\">\n".3275$cgi->a({-href => esc_url($logo_url),3276-title =>$logo_label},3277qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));3278print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3279if(defined$project) {3280print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3281if(defined$action) {3282print" /$action";3283}3284print"\n";3285}3286print"</div>\n";32873288my$have_search= gitweb_check_feature('search');3289if(defined$project&&$have_search) {3290if(!defined$searchtext) {3291$searchtext="";3292}3293my$search_hash;3294if(defined$hash_base) {3295$search_hash=$hash_base;3296}elsif(defined$hash) {3297$search_hash=$hash;3298}else{3299$search_hash="HEAD";3300}3301my$action=$my_uri;3302my$use_pathinfo= gitweb_check_feature('pathinfo');3303if($use_pathinfo) {3304$action.="/".esc_url($project);3305}3306print$cgi->startform(-method=>"get", -action =>$action) .3307"<div class=\"search\">\n".3308(!$use_pathinfo&&3309$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3310$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3311$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3312$cgi->popup_menu(-name =>'st', -default=>'commit',3313-values=> ['commit','grep','author','committer','pickaxe']) .3314$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3315" search:\n",3316$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3317"<span title=\"Extended regular expression\">".3318$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3319-checked =>$search_use_regexp) .3320"</span>".3321"</div>".3322$cgi->end_form() ."\n";3323}3324}33253326sub git_footer_html {3327my$feed_class='rss_logo';33283329print"<div class=\"page_footer\">\n";3330if(defined$project) {3331my$descr= git_get_project_description($project);3332if(defined$descr) {3333print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3334}33353336my%href_params= get_feed_info();3337if(!%href_params) {3338$feed_class.=' generic';3339}3340$href_params{'-title'} ||='log';33413342foreachmy$formatqw(RSS Atom){3343$href_params{'action'} =lc($format);3344print$cgi->a({-href => href(%href_params),3345-title =>"$href_params{'-title'}$formatfeed",3346-class=>$feed_class},$format)."\n";3347}33483349}else{3350print$cgi->a({-href => href(project=>undef, action=>"opml"),3351-class=>$feed_class},"OPML") ." ";3352print$cgi->a({-href => href(project=>undef, action=>"project_index"),3353-class=>$feed_class},"TXT") ."\n";3354}3355print"</div>\n";# class="page_footer"33563357if(defined$t0&& gitweb_check_feature('timed')) {3358print"<div id=\"generating_info\">\n";3359print'This page took '.3360'<span id="generating_time" class="time_span">'.3361 Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).3362' seconds </span>'.3363' and '.3364'<span id="generating_cmd">'.3365$number_of_git_cmds.3366'</span> git commands '.3367" to generate.\n";3368print"</div>\n";# class="page_footer"3369}33703371if(defined$site_footer&& -f $site_footer) {3372 insert_file($site_footer);3373}33743375print qq!<script type="text/javascript" src="$javascript"></script>\n!;3376if(defined$action&&3377$actioneq'blame_incremental') {3378print qq!<script type="text/javascript">\n!.3379 qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.3380 qq!"!. href() .qq!");\n!.3381 qq!</script>\n!;3382}elsif(gitweb_check_feature('javascript-actions')) {3383print qq!<script type="text/javascript">\n!.3384 qq!window.onload = fixLinks;\n!.3385 qq!</script>\n!;3386}33873388print"</body>\n".3389"</html>";3390}33913392# die_error(<http_status_code>, <error_message>[, <detailed_html_description>])3393# Example: die_error(404, 'Hash not found')3394# By convention, use the following status codes (as defined in RFC 2616):3395# 400: Invalid or missing CGI parameters, or3396# requested object exists but has wrong type.3397# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3398# this server or project.3399# 404: Requested object/revision/project doesn't exist.3400# 500: The server isn't configured properly, or3401# an internal error occurred (e.g. failed assertions caused by bugs), or3402# an unknown error occurred (e.g. the git binary died unexpectedly).3403# 503: The server is currently unavailable (because it is overloaded,3404# or down for maintenance). Generally, this is a temporary state.3405sub die_error {3406my$status=shift||500;3407my$error= esc_html(shift) ||"Internal Server Error";3408my$extra=shift;34093410my%http_responses= (3411400=>'400 Bad Request',3412403=>'403 Forbidden',3413404=>'404 Not Found',3414500=>'500 Internal Server Error',3415503=>'503 Service Unavailable',3416);3417 git_header_html($http_responses{$status});3418print<<EOF;3419<div class="page_body">3420<br /><br />3421$status-$error3422<br />3423EOF3424if(defined$extra) {3425print"<hr />\n".3426"$extra\n";3427}3428print"</div>\n";34293430 git_footer_html();3431exit;3432}34333434## ----------------------------------------------------------------------3435## functions printing or outputting HTML: navigation34363437sub git_print_page_nav {3438my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3439$extra=''if!defined$extra;# pager or formats34403441my@navs=qw(summary shortlog log commit commitdiff tree);3442if($suppress) {3443@navs=grep{$_ne$suppress}@navs;3444}34453446my%arg=map{$_=> {action=>$_} }@navs;3447if(defined$head) {3448for(qw(commit commitdiff)) {3449$arg{$_}{'hash'} =$head;3450}3451if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3452for(qw(shortlog log)) {3453$arg{$_}{'hash'} =$head;3454}3455}3456}34573458$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3459$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;34603461my@actions= gitweb_get_feature('actions');3462my%repl= (3463'%'=>'%',3464'n'=>$project,# project name3465'f'=>$git_dir,# project path within filesystem3466'h'=>$treehead||'',# current hash ('h' parameter)3467'b'=>$treebase||'',# hash base ('hb' parameter)3468);3469while(@actions) {3470my($label,$link,$pos) =splice(@actions,0,3);3471# insert3472@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3473# munch munch3474$link=~s/%([%nfhb])/$repl{$1}/g;3475$arg{$label}{'_href'} =$link;3476}34773478print"<div class=\"page_nav\">\n".3479(join" | ",3480map{$_eq$current?3481$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3482}@navs);3483print"<br/>\n$extra<br/>\n".3484"</div>\n";3485}34863487sub format_paging_nav {3488my($action,$page,$has_next_link) =@_;3489my$paging_nav;349034913492if($page>0) {3493$paging_nav.=3494$cgi->a({-href => href(-replay=>1, page=>undef)},"first") .3495" ⋅ ".3496$cgi->a({-href => href(-replay=>1, page=>$page-1),3497-accesskey =>"p", -title =>"Alt-p"},"prev");3498}else{3499$paging_nav.="first ⋅ prev";3500}35013502if($has_next_link) {3503$paging_nav.=" ⋅ ".3504$cgi->a({-href => href(-replay=>1, page=>$page+1),3505-accesskey =>"n", -title =>"Alt-n"},"next");3506}else{3507$paging_nav.=" ⋅ next";3508}35093510return$paging_nav;3511}35123513## ......................................................................3514## functions printing or outputting HTML: div35153516sub git_print_header_div {3517my($action,$title,$hash,$hash_base) =@_;3518my%args= ();35193520$args{'action'} =$action;3521$args{'hash'} =$hashif$hash;3522$args{'hash_base'} =$hash_baseif$hash_base;35233524print"<div class=\"header\">\n".3525$cgi->a({-href => href(%args), -class=>"title"},3526$title?$title:$action) .3527"\n</div>\n";3528}35293530sub print_local_time {3531print format_local_time(@_);3532}35333534sub format_local_time {3535my$localtime='';3536my%date=@_;3537if($date{'hour_local'} <6) {3538$localtime.=sprintf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3539$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3540}else{3541$localtime.=sprintf(" (%02d:%02d%s)",3542$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3543}35443545return$localtime;3546}35473548# Outputs the author name and date in long form3549sub git_print_authorship {3550my$co=shift;3551my%opts=@_;3552my$tag=$opts{-tag} ||'div';3553my$author=$co->{'author_name'};35543555my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3556print"<$tagclass=\"author_date\">".3557 format_search_author($author,"author", esc_html($author)) .3558" [$ad{'rfc2822'}";3559 print_local_time(%ad)if($opts{-localtime});3560print"]". git_get_avatar($co->{'author_email'}, -pad_before =>1)3561."</$tag>\n";3562}35633564# Outputs table rows containing the full author or committer information,3565# in the format expected for 'commit' view (& similia).3566# Parameters are a commit hash reference, followed by the list of people3567# to output information for. If the list is empty it defalts to both3568# author and committer.3569sub git_print_authorship_rows {3570my$co=shift;3571# too bad we can't use @people = @_ || ('author', 'committer')3572my@people=@_;3573@people= ('author','committer')unless@people;3574foreachmy$who(@people) {3575my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});3576print"<tr><td>$who</td><td>".3577 format_search_author($co->{"${who}_name"},$who,3578 esc_html($co->{"${who}_name"})) ." ".3579 format_search_author($co->{"${who}_email"},$who,3580 esc_html("<".$co->{"${who}_email"} .">")) .3581"</td><td rowspan=\"2\">".3582 git_get_avatar($co->{"${who}_email"}, -size =>'double') .3583"</td></tr>\n".3584"<tr>".3585"<td></td><td>$wd{'rfc2822'}";3586 print_local_time(%wd);3587print"</td>".3588"</tr>\n";3589}3590}35913592sub git_print_page_path {3593my$name=shift;3594my$type=shift;3595my$hb=shift;359635973598print"<div class=\"page_path\">";3599print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3600-title =>'tree root'}, to_utf8("[$project]"));3601print" / ";3602if(defined$name) {3603my@dirname=split'/',$name;3604my$basename=pop@dirname;3605my$fullname='';36063607foreachmy$dir(@dirname) {3608$fullname.= ($fullname?'/':'') .$dir;3609print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3610 hash_base=>$hb),3611-title =>$fullname}, esc_path($dir));3612print" / ";3613}3614if(defined$type&&$typeeq'blob') {3615print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3616 hash_base=>$hb),3617-title =>$name}, esc_path($basename));3618}elsif(defined$type&&$typeeq'tree') {3619print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3620 hash_base=>$hb),3621-title =>$name}, esc_path($basename));3622print" / ";3623}else{3624print esc_path($basename);3625}3626}3627print"<br/></div>\n";3628}36293630sub git_print_log {3631my$log=shift;3632my%opts=@_;36333634if($opts{'-remove_title'}) {3635# remove title, i.e. first line of log3636shift@$log;3637}3638# remove leading empty lines3639while(defined$log->[0] &&$log->[0]eq"") {3640shift@$log;3641}36423643# print log3644my$signoff=0;3645my$empty=0;3646foreachmy$line(@$log) {3647if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3648$signoff=1;3649$empty=0;3650if(!$opts{'-remove_signoff'}) {3651print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3652next;3653}else{3654# remove signoff lines3655next;3656}3657}else{3658$signoff=0;3659}36603661# print only one empty line3662# do not print empty line after signoff3663if($lineeq"") {3664next if($empty||$signoff);3665$empty=1;3666}else{3667$empty=0;3668}36693670print format_log_line_html($line) ."<br/>\n";3671}36723673if($opts{'-final_empty_line'}) {3674# end with single empty line3675print"<br/>\n"unless$empty;3676}3677}36783679# return link target (what link points to)3680sub git_get_link_target {3681my$hash=shift;3682my$link_target;36833684# read link3685open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3686orreturn;3687{3688local$/=undef;3689$link_target= <$fd>;3690}3691close$fd3692orreturn;36933694return$link_target;3695}36963697# given link target, and the directory (basedir) the link is in,3698# return target of link relative to top directory (top tree);3699# return undef if it is not possible (including absolute links).3700sub normalize_link_target {3701my($link_target,$basedir) =@_;37023703# absolute symlinks (beginning with '/') cannot be normalized3704return if(substr($link_target,0,1)eq'/');37053706# normalize link target to path from top (root) tree (dir)3707my$path;3708if($basedir) {3709$path=$basedir.'/'.$link_target;3710}else{3711# we are in top (root) tree (dir)3712$path=$link_target;3713}37143715# remove //, /./, and /../3716my@path_parts;3717foreachmy$part(split('/',$path)) {3718# discard '.' and ''3719next if(!$part||$parteq'.');3720# handle '..'3721if($parteq'..') {3722if(@path_parts) {3723pop@path_parts;3724}else{3725# link leads outside repository (outside top dir)3726return;3727}3728}else{3729push@path_parts,$part;3730}3731}3732$path=join('/',@path_parts);37333734return$path;3735}37363737# print tree entry (row of git_tree), but without encompassing <tr> element3738sub git_print_tree_entry {3739my($t,$basedir,$hash_base,$have_blame) =@_;37403741my%base_key= ();3742$base_key{'hash_base'} =$hash_baseifdefined$hash_base;37433744# The format of a table row is: mode list link. Where mode is3745# the mode of the entry, list is the name of the entry, an href,3746# and link is the action links of the entry.37473748print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3749if(exists$t->{'size'}) {3750print"<td class=\"size\">$t->{'size'}</td>\n";3751}3752if($t->{'type'}eq"blob") {3753print"<td class=\"list\">".3754$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3755 file_name=>"$basedir$t->{'name'}",%base_key),3756-class=>"list"}, esc_path($t->{'name'}));3757if(S_ISLNK(oct$t->{'mode'})) {3758my$link_target= git_get_link_target($t->{'hash'});3759if($link_target) {3760my$norm_target= normalize_link_target($link_target,$basedir);3761if(defined$norm_target) {3762print" -> ".3763$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3764 file_name=>$norm_target),3765-title =>$norm_target}, esc_path($link_target));3766}else{3767print" -> ". esc_path($link_target);3768}3769}3770}3771print"</td>\n";3772print"<td class=\"link\">";3773print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3774 file_name=>"$basedir$t->{'name'}",%base_key)},3775"blob");3776if($have_blame) {3777print" | ".3778$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3779 file_name=>"$basedir$t->{'name'}",%base_key)},3780"blame");3781}3782if(defined$hash_base) {3783print" | ".3784$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3785 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3786"history");3787}3788print" | ".3789$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3790 file_name=>"$basedir$t->{'name'}")},3791"raw");3792print"</td>\n";37933794}elsif($t->{'type'}eq"tree") {3795print"<td class=\"list\">";3796print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3797 file_name=>"$basedir$t->{'name'}",3798%base_key)},3799 esc_path($t->{'name'}));3800print"</td>\n";3801print"<td class=\"link\">";3802print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3803 file_name=>"$basedir$t->{'name'}",3804%base_key)},3805"tree");3806if(defined$hash_base) {3807print" | ".3808$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3809 file_name=>"$basedir$t->{'name'}")},3810"history");3811}3812print"</td>\n";3813}else{3814# unknown object: we can only present history for it3815# (this includes 'commit' object, i.e. submodule support)3816print"<td class=\"list\">".3817 esc_path($t->{'name'}) .3818"</td>\n";3819print"<td class=\"link\">";3820if(defined$hash_base) {3821print$cgi->a({-href => href(action=>"history",3822 hash_base=>$hash_base,3823 file_name=>"$basedir$t->{'name'}")},3824"history");3825}3826print"</td>\n";3827}3828}38293830## ......................................................................3831## functions printing large fragments of HTML38323833# get pre-image filenames for merge (combined) diff3834sub fill_from_file_info {3835my($diff,@parents) =@_;38363837$diff->{'from_file'} = [ ];3838$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3839for(my$i=0;$i<$diff->{'nparents'};$i++) {3840if($diff->{'status'}[$i]eq'R'||3841$diff->{'status'}[$i]eq'C') {3842$diff->{'from_file'}[$i] =3843 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3844}3845}38463847return$diff;3848}38493850# is current raw difftree line of file deletion3851sub is_deleted {3852my$diffinfo=shift;38533854return$diffinfo->{'to_id'}eq('0' x 40);3855}38563857# does patch correspond to [previous] difftree raw line3858# $diffinfo - hashref of parsed raw diff format3859# $patchinfo - hashref of parsed patch diff format3860# (the same keys as in $diffinfo)3861sub is_patch_split {3862my($diffinfo,$patchinfo) =@_;38633864returndefined$diffinfo&&defined$patchinfo3865&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3866}386738683869sub git_difftree_body {3870my($difftree,$hash,@parents) =@_;3871my($parent) =$parents[0];3872my$have_blame= gitweb_check_feature('blame');3873print"<div class=\"list_head\">\n";3874if($#{$difftree} >10) {3875print(($#{$difftree} +1) ." files changed:\n");3876}3877print"</div>\n";38783879print"<table class=\"".3880(@parents>1?"combined ":"") .3881"diff_tree\">\n";38823883# header only for combined diff in 'commitdiff' view3884my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3885if($has_header) {3886# table header3887print"<thead><tr>\n".3888"<th></th><th></th>\n";# filename, patchN link3889for(my$i=0;$i<@parents;$i++) {3890my$par=$parents[$i];3891print"<th>".3892$cgi->a({-href => href(action=>"commitdiff",3893 hash=>$hash, hash_parent=>$par),3894-title =>'commitdiff to parent number '.3895($i+1) .': '.substr($par,0,7)},3896$i+1) .3897" </th>\n";3898}3899print"</tr></thead>\n<tbody>\n";3900}39013902my$alternate=1;3903my$patchno=0;3904foreachmy$line(@{$difftree}) {3905my$diff= parsed_difftree_line($line);39063907if($alternate) {3908print"<tr class=\"dark\">\n";3909}else{3910print"<tr class=\"light\">\n";3911}3912$alternate^=1;39133914if(exists$diff->{'nparents'}) {# combined diff39153916 fill_from_file_info($diff,@parents)3917unlessexists$diff->{'from_file'};39183919if(!is_deleted($diff)) {3920# file exists in the result (child) commit3921print"<td>".3922$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3923 file_name=>$diff->{'to_file'},3924 hash_base=>$hash),3925-class=>"list"}, esc_path($diff->{'to_file'})) .3926"</td>\n";3927}else{3928print"<td>".3929 esc_path($diff->{'to_file'}) .3930"</td>\n";3931}39323933if($actioneq'commitdiff') {3934# link to patch3935$patchno++;3936print"<td class=\"link\">".3937$cgi->a({-href =>"#patch$patchno"},"patch") .3938" | ".3939"</td>\n";3940}39413942my$has_history=0;3943my$not_deleted=0;3944for(my$i=0;$i<$diff->{'nparents'};$i++) {3945my$hash_parent=$parents[$i];3946my$from_hash=$diff->{'from_id'}[$i];3947my$from_path=$diff->{'from_file'}[$i];3948my$status=$diff->{'status'}[$i];39493950$has_history||= ($statusne'A');3951$not_deleted||= ($statusne'D');39523953if($statuseq'A') {3954print"<td class=\"link\"align=\"right\"> | </td>\n";3955}elsif($statuseq'D') {3956print"<td class=\"link\">".3957$cgi->a({-href => href(action=>"blob",3958 hash_base=>$hash,3959 hash=>$from_hash,3960 file_name=>$from_path)},3961"blob". ($i+1)) .3962" | </td>\n";3963}else{3964if($diff->{'to_id'}eq$from_hash) {3965print"<td class=\"link nochange\">";3966}else{3967print"<td class=\"link\">";3968}3969print$cgi->a({-href => href(action=>"blobdiff",3970 hash=>$diff->{'to_id'},3971 hash_parent=>$from_hash,3972 hash_base=>$hash,3973 hash_parent_base=>$hash_parent,3974 file_name=>$diff->{'to_file'},3975 file_parent=>$from_path)},3976"diff". ($i+1)) .3977" | </td>\n";3978}3979}39803981print"<td class=\"link\">";3982if($not_deleted) {3983print$cgi->a({-href => href(action=>"blob",3984 hash=>$diff->{'to_id'},3985 file_name=>$diff->{'to_file'},3986 hash_base=>$hash)},3987"blob");3988print" | "if($has_history);3989}3990if($has_history) {3991print$cgi->a({-href => href(action=>"history",3992 file_name=>$diff->{'to_file'},3993 hash_base=>$hash)},3994"history");3995}3996print"</td>\n";39973998print"</tr>\n";3999next;# instead of 'else' clause, to avoid extra indent4000}4001# else ordinary diff40024003my($to_mode_oct,$to_mode_str,$to_file_type);4004my($from_mode_oct,$from_mode_str,$from_file_type);4005if($diff->{'to_mode'}ne('0' x 6)) {4006$to_mode_oct=oct$diff->{'to_mode'};4007if(S_ISREG($to_mode_oct)) {# only for regular file4008$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits4009}4010$to_file_type= file_type($diff->{'to_mode'});4011}4012if($diff->{'from_mode'}ne('0' x 6)) {4013$from_mode_oct=oct$diff->{'from_mode'};4014if(S_ISREG($to_mode_oct)) {# only for regular file4015$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits4016}4017$from_file_type= file_type($diff->{'from_mode'});4018}40194020if($diff->{'status'}eq"A") {# created4021my$mode_chng="<span class=\"file_status new\">[new$to_file_type";4022$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;4023$mode_chng.="]</span>";4024print"<td>";4025print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4026 hash_base=>$hash, file_name=>$diff->{'file'}),4027-class=>"list"}, esc_path($diff->{'file'}));4028print"</td>\n";4029print"<td>$mode_chng</td>\n";4030print"<td class=\"link\">";4031if($actioneq'commitdiff') {4032# link to patch4033$patchno++;4034print$cgi->a({-href =>"#patch$patchno"},"patch");4035print" | ";4036}4037print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4038 hash_base=>$hash, file_name=>$diff->{'file'})},4039"blob");4040print"</td>\n";40414042}elsif($diff->{'status'}eq"D") {# deleted4043my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";4044print"<td>";4045print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4046 hash_base=>$parent, file_name=>$diff->{'file'}),4047-class=>"list"}, esc_path($diff->{'file'}));4048print"</td>\n";4049print"<td>$mode_chng</td>\n";4050print"<td class=\"link\">";4051if($actioneq'commitdiff') {4052# link to patch4053$patchno++;4054print$cgi->a({-href =>"#patch$patchno"},"patch");4055print" | ";4056}4057print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4058 hash_base=>$parent, file_name=>$diff->{'file'})},4059"blob") ." | ";4060if($have_blame) {4061print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,4062 file_name=>$diff->{'file'})},4063"blame") ." | ";4064}4065print$cgi->a({-href => href(action=>"history", hash_base=>$parent,4066 file_name=>$diff->{'file'})},4067"history");4068print"</td>\n";40694070}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed4071my$mode_chnge="";4072if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4073$mode_chnge="<span class=\"file_status mode_chnge\">[changed";4074if($from_file_typene$to_file_type) {4075$mode_chnge.=" from$from_file_typeto$to_file_type";4076}4077if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {4078if($from_mode_str&&$to_mode_str) {4079$mode_chnge.=" mode:$from_mode_str->$to_mode_str";4080}elsif($to_mode_str) {4081$mode_chnge.=" mode:$to_mode_str";4082}4083}4084$mode_chnge.="]</span>\n";4085}4086print"<td>";4087print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4088 hash_base=>$hash, file_name=>$diff->{'file'}),4089-class=>"list"}, esc_path($diff->{'file'}));4090print"</td>\n";4091print"<td>$mode_chnge</td>\n";4092print"<td class=\"link\">";4093if($actioneq'commitdiff') {4094# link to patch4095$patchno++;4096print$cgi->a({-href =>"#patch$patchno"},"patch") .4097" | ";4098}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4099# "commit" view and modified file (not onlu mode changed)4100print$cgi->a({-href => href(action=>"blobdiff",4101 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4102 hash_base=>$hash, hash_parent_base=>$parent,4103 file_name=>$diff->{'file'})},4104"diff") .4105" | ";4106}4107print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4108 hash_base=>$hash, file_name=>$diff->{'file'})},4109"blob") ." | ";4110if($have_blame) {4111print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4112 file_name=>$diff->{'file'})},4113"blame") ." | ";4114}4115print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4116 file_name=>$diff->{'file'})},4117"history");4118print"</td>\n";41194120}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied4121my%status_name= ('R'=>'moved','C'=>'copied');4122my$nstatus=$status_name{$diff->{'status'}};4123my$mode_chng="";4124if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4125# mode also for directories, so we cannot use $to_mode_str4126$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);4127}4128print"<td>".4129$cgi->a({-href => href(action=>"blob", hash_base=>$hash,4130 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),4131-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".4132"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".4133$cgi->a({-href => href(action=>"blob", hash_base=>$parent,4134 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),4135-class=>"list"}, esc_path($diff->{'from_file'})) .4136" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".4137"<td class=\"link\">";4138if($actioneq'commitdiff') {4139# link to patch4140$patchno++;4141print$cgi->a({-href =>"#patch$patchno"},"patch") .4142" | ";4143}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4144# "commit" view and modified file (not only pure rename or copy)4145print$cgi->a({-href => href(action=>"blobdiff",4146 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4147 hash_base=>$hash, hash_parent_base=>$parent,4148 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},4149"diff") .4150" | ";4151}4152print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4153 hash_base=>$parent, file_name=>$diff->{'to_file'})},4154"blob") ." | ";4155if($have_blame) {4156print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4157 file_name=>$diff->{'to_file'})},4158"blame") ." | ";4159}4160print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4161 file_name=>$diff->{'to_file'})},4162"history");4163print"</td>\n";41644165}# we should not encounter Unmerged (U) or Unknown (X) status4166print"</tr>\n";4167}4168print"</tbody>"if$has_header;4169print"</table>\n";4170}41714172sub git_patchset_body {4173my($fd,$difftree,$hash,@hash_parents) =@_;4174my($hash_parent) =$hash_parents[0];41754176my$is_combined= (@hash_parents>1);4177my$patch_idx=0;4178my$patch_number=0;4179my$patch_line;4180my$diffinfo;4181my$to_name;4182my(%from,%to);41834184print"<div class=\"patchset\">\n";41854186# skip to first patch4187while($patch_line= <$fd>) {4188chomp$patch_line;41894190last if($patch_line=~m/^diff /);4191}41924193 PATCH:4194while($patch_line) {41954196# parse "git diff" header line4197if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {4198# $1 is from_name, which we do not use4199$to_name= unquote($2);4200$to_name=~s!^b/!!;4201}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {4202# $1 is 'cc' or 'combined', which we do not use4203$to_name= unquote($2);4204}else{4205$to_name=undef;4206}42074208# check if current patch belong to current raw line4209# and parse raw git-diff line if needed4210if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {4211# this is continuation of a split patch4212print"<div class=\"patch cont\">\n";4213}else{4214# advance raw git-diff output if needed4215$patch_idx++ifdefined$diffinfo;42164217# read and prepare patch information4218$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);42194220# compact combined diff output can have some patches skipped4221# find which patch (using pathname of result) we are at now;4222if($is_combined) {4223while($to_namene$diffinfo->{'to_file'}) {4224print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4225 format_diff_cc_simplified($diffinfo,@hash_parents) .4226"</div>\n";# class="patch"42274228$patch_idx++;4229$patch_number++;42304231last if$patch_idx>$#$difftree;4232$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);4233}4234}42354236# modifies %from, %to hashes4237 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);42384239# this is first patch for raw difftree line with $patch_idx index4240# we index @$difftree array from 0, but number patches from 14241print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";4242}42434244# git diff header4245#assert($patch_line =~ m/^diff /) if DEBUG;4246#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed4247$patch_number++;4248# print "git diff" header4249print format_git_diff_header_line($patch_line,$diffinfo,4250 \%from, \%to);42514252# print extended diff header4253print"<div class=\"diff extended_header\">\n";4254 EXTENDED_HEADER:4255while($patch_line= <$fd>) {4256chomp$patch_line;42574258last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);42594260print format_extended_diff_header_line($patch_line,$diffinfo,4261 \%from, \%to);4262}4263print"</div>\n";# class="diff extended_header"42644265# from-file/to-file diff header4266if(!$patch_line) {4267print"</div>\n";# class="patch"4268last PATCH;4269}4270next PATCH if($patch_line=~m/^diff /);4271#assert($patch_line =~ m/^---/) if DEBUG;42724273my$last_patch_line=$patch_line;4274$patch_line= <$fd>;4275chomp$patch_line;4276#assert($patch_line =~ m/^\+\+\+/) if DEBUG;42774278print format_diff_from_to_header($last_patch_line,$patch_line,4279$diffinfo, \%from, \%to,4280@hash_parents);42814282# the patch itself4283 LINE:4284while($patch_line= <$fd>) {4285chomp$patch_line;42864287next PATCH if($patch_line=~m/^diff /);42884289print format_diff_line($patch_line, \%from, \%to);4290}42914292}continue{4293print"</div>\n";# class="patch"4294}42954296# for compact combined (--cc) format, with chunk and patch simpliciaction4297# patchset might be empty, but there might be unprocessed raw lines4298for(++$patch_idxif$patch_number>0;4299$patch_idx<@$difftree;4300++$patch_idx) {4301# read and prepare patch information4302$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);43034304# generate anchor for "patch" links in difftree / whatchanged part4305print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4306 format_diff_cc_simplified($diffinfo,@hash_parents) .4307"</div>\n";# class="patch"43084309$patch_number++;4310}43114312if($patch_number==0) {4313if(@hash_parents>1) {4314print"<div class=\"diff nodifferences\">Trivial merge</div>\n";4315}else{4316print"<div class=\"diff nodifferences\">No differences found</div>\n";4317}4318}43194320print"</div>\n";# class="patchset"4321}43224323# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43244325# fills project list info (age, description, owner, forks) for each4326# project in the list, removing invalid projects from returned list4327# NOTE: modifies $projlist, but does not remove entries from it4328sub fill_project_list_info {4329my($projlist,$check_forks) =@_;4330my@projects;43314332my$show_ctags= gitweb_check_feature('ctags');4333 PROJECT:4334foreachmy$pr(@$projlist) {4335my(@activity) = git_get_last_activity($pr->{'path'});4336unless(@activity) {4337next PROJECT;4338}4339($pr->{'age'},$pr->{'age_string'}) =@activity;4340if(!defined$pr->{'descr'}) {4341my$descr= git_get_project_description($pr->{'path'}) ||"";4342$descr= to_utf8($descr);4343$pr->{'descr_long'} =$descr;4344$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4345}4346if(!defined$pr->{'owner'}) {4347$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4348}4349if($check_forks) {4350my$pname=$pr->{'path'};4351if(($pname=~s/\.git$//) &&4352($pname!~/\/$/) &&4353(-d "$projectroot/$pname")) {4354$pr->{'forks'} ="-d$projectroot/$pname";4355}else{4356$pr->{'forks'} =0;4357}4358}4359$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4360push@projects,$pr;4361}43624363return@projects;4364}43654366# print 'sort by' <th> element, generating 'sort by $name' replay link4367# if that order is not selected4368sub print_sort_th {4369print format_sort_th(@_);4370}43714372sub format_sort_th {4373my($name,$order,$header) =@_;4374my$sort_th="";4375$header||=ucfirst($name);43764377if($ordereq$name) {4378$sort_th.="<th>$header</th>\n";4379}else{4380$sort_th.="<th>".4381$cgi->a({-href => href(-replay=>1, order=>$name),4382-class=>"header"},$header) .4383"</th>\n";4384}43854386return$sort_th;4387}43884389sub git_project_list_body {4390# actually uses global variable $project4391my($projlist,$order,$from,$to,$extra,$no_header) =@_;43924393my$check_forks= gitweb_check_feature('forks');4394my@projects= fill_project_list_info($projlist,$check_forks);43954396$order||=$default_projects_order;4397$from=0unlessdefined$from;4398$to=$#projectsif(!defined$to||$#projects<$to);43994400my%order_info= (4401 project => { key =>'path', type =>'str'},4402 descr => { key =>'descr_long', type =>'str'},4403 owner => { key =>'owner', type =>'str'},4404 age => { key =>'age', type =>'num'}4405);4406my$oi=$order_info{$order};4407if($oi->{'type'}eq'str') {4408@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4409}else{4410@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4411}44124413my$show_ctags= gitweb_check_feature('ctags');4414if($show_ctags) {4415my%ctags;4416foreachmy$p(@projects) {4417foreachmy$ct(keys%{$p->{'ctags'}}) {4418$ctags{$ct} +=$p->{'ctags'}->{$ct};4419}4420}4421my$cloud= git_populate_project_tagcloud(\%ctags);4422print git_show_project_tagcloud($cloud,64);4423}44244425print"<table class=\"project_list\">\n";4426unless($no_header) {4427print"<tr>\n";4428if($check_forks) {4429print"<th></th>\n";4430}4431 print_sort_th('project',$order,'Project');4432 print_sort_th('descr',$order,'Description');4433 print_sort_th('owner',$order,'Owner');4434 print_sort_th('age',$order,'Last Change');4435print"<th></th>\n".# for links4436"</tr>\n";4437}4438my$alternate=1;4439my$tagfilter=$cgi->param('by_tag');4440for(my$i=$from;$i<=$to;$i++) {4441my$pr=$projects[$i];44424443next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4444next if$searchtextand not$pr->{'path'} =~/$searchtext/4445and not$pr->{'descr_long'} =~/$searchtext/;4446# Weed out forks or non-matching entries of search4447if($check_forks) {4448my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4449$forkbase="^$forkbase"if$forkbase;4450next ifnot$searchtextand not$tagfilterand$show_ctags4451and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4452}44534454if($alternate) {4455print"<tr class=\"dark\">\n";4456}else{4457print"<tr class=\"light\">\n";4458}4459$alternate^=1;4460if($check_forks) {4461print"<td>";4462if($pr->{'forks'}) {4463print"<!--$pr->{'forks'} -->\n";4464print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4465}4466print"</td>\n";4467}4468print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4469-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4470"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4471-class=>"list", -title =>$pr->{'descr_long'}},4472 esc_html($pr->{'descr'})) ."</td>\n".4473"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4474print"<td class=\"". age_class($pr->{'age'}) ."\">".4475(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4476"<td class=\"link\">".4477$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4478$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4479$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4480$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4481($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4482"</td>\n".4483"</tr>\n";4484}4485if(defined$extra) {4486print"<tr>\n";4487if($check_forks) {4488print"<td></td>\n";4489}4490print"<td colspan=\"5\">$extra</td>\n".4491"</tr>\n";4492}4493print"</table>\n";4494}44954496sub git_log_body {4497# uses global variable $project4498my($commitlist,$from,$to,$refs,$extra) =@_;44994500$from=0unlessdefined$from;4501$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);45024503for(my$i=0;$i<=$to;$i++) {4504my%co= %{$commitlist->[$i]};4505next if!%co;4506my$commit=$co{'id'};4507my$ref= format_ref_marker($refs,$commit);4508my%ad= parse_date($co{'author_epoch'});4509 git_print_header_div('commit',4510"<span class=\"age\">$co{'age_string'}</span>".4511 esc_html($co{'title'}) .$ref,4512$commit);4513print"<div class=\"title_text\">\n".4514"<div class=\"log_link\">\n".4515$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .4516" | ".4517$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .4518" | ".4519$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .4520"<br/>\n".4521"</div>\n";4522 git_print_authorship(\%co, -tag =>'span');4523print"<br/>\n</div>\n";45244525print"<div class=\"log_body\">\n";4526 git_print_log($co{'comment'}, -final_empty_line=>1);4527print"</div>\n";4528}4529if($extra) {4530print"<div class=\"page_nav\">\n";4531print"$extra\n";4532print"</div>\n";4533}4534}45354536sub git_shortlog_body {4537# uses global variable $project4538my($commitlist,$from,$to,$refs,$extra) =@_;45394540$from=0unlessdefined$from;4541$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);45424543print"<table class=\"shortlog\">\n";4544my$alternate=1;4545for(my$i=$from;$i<=$to;$i++) {4546my%co= %{$commitlist->[$i]};4547my$commit=$co{'id'};4548my$ref= format_ref_marker($refs,$commit);4549if($alternate) {4550print"<tr class=\"dark\">\n";4551}else{4552print"<tr class=\"light\">\n";4553}4554$alternate^=1;4555# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4556print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4557 format_author_html('td', \%co,10) ."<td>";4558print format_subject_html($co{'title'},$co{'title_short'},4559 href(action=>"commit", hash=>$commit),$ref);4560print"</td>\n".4561"<td class=\"link\">".4562$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4563$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4564$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4565my$snapshot_links= format_snapshot_links($commit);4566if(defined$snapshot_links) {4567print" | ".$snapshot_links;4568}4569print"</td>\n".4570"</tr>\n";4571}4572if(defined$extra) {4573print"<tr>\n".4574"<td colspan=\"4\">$extra</td>\n".4575"</tr>\n";4576}4577print"</table>\n";4578}45794580sub git_history_body {4581# Warning: assumes constant type (blob or tree) during history4582my($commitlist,$from,$to,$refs,$extra,4583$file_name,$file_hash,$ftype) =@_;45844585$from=0unlessdefined$from;4586$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});45874588print"<table class=\"history\">\n";4589my$alternate=1;4590for(my$i=$from;$i<=$to;$i++) {4591my%co= %{$commitlist->[$i]};4592if(!%co) {4593next;4594}4595my$commit=$co{'id'};45964597my$ref= format_ref_marker($refs,$commit);45984599if($alternate) {4600print"<tr class=\"dark\">\n";4601}else{4602print"<tr class=\"light\">\n";4603}4604$alternate^=1;4605print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4606# shortlog: format_author_html('td', \%co, 10)4607 format_author_html('td', \%co,15,3) ."<td>";4608# originally git_history used chop_str($co{'title'}, 50)4609print format_subject_html($co{'title'},$co{'title_short'},4610 href(action=>"commit", hash=>$commit),$ref);4611print"</td>\n".4612"<td class=\"link\">".4613$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4614$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");46154616if($ftypeeq'blob') {4617my$blob_current=$file_hash;4618my$blob_parent= git_get_hash_by_path($commit,$file_name);4619if(defined$blob_current&&defined$blob_parent&&4620$blob_currentne$blob_parent) {4621print" | ".4622$cgi->a({-href => href(action=>"blobdiff",4623 hash=>$blob_current, hash_parent=>$blob_parent,4624 hash_base=>$hash_base, hash_parent_base=>$commit,4625 file_name=>$file_name)},4626"diff to current");4627}4628}4629print"</td>\n".4630"</tr>\n";4631}4632if(defined$extra) {4633print"<tr>\n".4634"<td colspan=\"4\">$extra</td>\n".4635"</tr>\n";4636}4637print"</table>\n";4638}46394640sub git_tags_body {4641# uses global variable $project4642my($taglist,$from,$to,$extra) =@_;4643$from=0unlessdefined$from;4644$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);46454646print"<table class=\"tags\">\n";4647my$alternate=1;4648for(my$i=$from;$i<=$to;$i++) {4649my$entry=$taglist->[$i];4650my%tag=%$entry;4651my$comment=$tag{'subject'};4652my$comment_short;4653if(defined$comment) {4654$comment_short= chop_str($comment,30,5);4655}4656if($alternate) {4657print"<tr class=\"dark\">\n";4658}else{4659print"<tr class=\"light\">\n";4660}4661$alternate^=1;4662if(defined$tag{'age'}) {4663print"<td><i>$tag{'age'}</i></td>\n";4664}else{4665print"<td></td>\n";4666}4667print"<td>".4668$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4669-class=>"list name"}, esc_html($tag{'name'})) .4670"</td>\n".4671"<td>";4672if(defined$comment) {4673print format_subject_html($comment,$comment_short,4674 href(action=>"tag", hash=>$tag{'id'}));4675}4676print"</td>\n".4677"<td class=\"selflink\">";4678if($tag{'type'}eq"tag") {4679print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4680}else{4681print" ";4682}4683print"</td>\n".4684"<td class=\"link\">"." | ".4685$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4686if($tag{'reftype'}eq"commit") {4687print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4688" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4689}elsif($tag{'reftype'}eq"blob") {4690print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4691}4692print"</td>\n".4693"</tr>";4694}4695if(defined$extra) {4696print"<tr>\n".4697"<td colspan=\"5\">$extra</td>\n".4698"</tr>\n";4699}4700print"</table>\n";4701}47024703sub git_heads_body {4704# uses global variable $project4705my($headlist,$head,$from,$to,$extra) =@_;4706$from=0unlessdefined$from;4707$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);47084709print"<table class=\"heads\">\n";4710my$alternate=1;4711for(my$i=$from;$i<=$to;$i++) {4712my$entry=$headlist->[$i];4713my%ref=%$entry;4714my$curr=$ref{'id'}eq$head;4715if($alternate) {4716print"<tr class=\"dark\">\n";4717}else{4718print"<tr class=\"light\">\n";4719}4720$alternate^=1;4721print"<td><i>$ref{'age'}</i></td>\n".4722($curr?"<td class=\"current_head\">":"<td>") .4723$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4724-class=>"list name"},esc_html($ref{'name'})) .4725"</td>\n".4726"<td class=\"link\">".4727$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4728$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4729$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4730"</td>\n".4731"</tr>";4732}4733if(defined$extra) {4734print"<tr>\n".4735"<td colspan=\"3\">$extra</td>\n".4736"</tr>\n";4737}4738print"</table>\n";4739}47404741sub git_search_grep_body {4742my($commitlist,$from,$to,$extra) =@_;4743$from=0unlessdefined$from;4744$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);47454746print"<table class=\"commit_search\">\n";4747my$alternate=1;4748for(my$i=$from;$i<=$to;$i++) {4749my%co= %{$commitlist->[$i]};4750if(!%co) {4751next;4752}4753my$commit=$co{'id'};4754if($alternate) {4755print"<tr class=\"dark\">\n";4756}else{4757print"<tr class=\"light\">\n";4758}4759$alternate^=1;4760print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4761 format_author_html('td', \%co,15,5) .4762"<td>".4763$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4764-class=>"list subject"},4765 chop_and_escape_str($co{'title'},50) ."<br/>");4766my$comment=$co{'comment'};4767foreachmy$line(@$comment) {4768if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4769my($lead,$match,$trail) = ($1,$2,$3);4770$match= chop_str($match,70,5,'center');4771my$contextlen=int((80-length($match))/2);4772$contextlen=30if($contextlen>30);4773$lead= chop_str($lead,$contextlen,10,'left');4774$trail= chop_str($trail,$contextlen,10,'right');47754776$lead= esc_html($lead);4777$match= esc_html($match);4778$trail= esc_html($trail);47794780print"$lead<span class=\"match\">$match</span>$trail<br />";4781}4782}4783print"</td>\n".4784"<td class=\"link\">".4785$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4786" | ".4787$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4788" | ".4789$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4790print"</td>\n".4791"</tr>\n";4792}4793if(defined$extra) {4794print"<tr>\n".4795"<td colspan=\"3\">$extra</td>\n".4796"</tr>\n";4797}4798print"</table>\n";4799}48004801## ======================================================================4802## ======================================================================4803## actions48044805sub git_project_list {4806my$order=$input_params{'order'};4807if(defined$order&&$order!~m/none|project|descr|owner|age/) {4808 die_error(400,"Unknown order parameter");4809}48104811my@list= git_get_projects_list();4812if(!@list) {4813 die_error(404,"No projects found");4814}48154816 git_header_html();4817if(defined$home_text&& -f $home_text) {4818print"<div class=\"index_include\">\n";4819 insert_file($home_text);4820print"</div>\n";4821}4822print$cgi->startform(-method=>"get") .4823"<p class=\"projsearch\">Search:\n".4824$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4825"</p>".4826$cgi->end_form() ."\n";4827 git_project_list_body(\@list,$order);4828 git_footer_html();4829}48304831sub git_forks {4832my$order=$input_params{'order'};4833if(defined$order&&$order!~m/none|project|descr|owner|age/) {4834 die_error(400,"Unknown order parameter");4835}48364837my@list= git_get_projects_list($project);4838if(!@list) {4839 die_error(404,"No forks found");4840}48414842 git_header_html();4843 git_print_page_nav('','');4844 git_print_header_div('summary',"$projectforks");4845 git_project_list_body(\@list,$order);4846 git_footer_html();4847}48484849sub git_project_index {4850my@projects= git_get_projects_list($project);48514852print$cgi->header(4853-type =>'text/plain',4854-charset =>'utf-8',4855-content_disposition =>'inline; filename="index.aux"');48564857foreachmy$pr(@projects) {4858if(!exists$pr->{'owner'}) {4859$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4860}48614862my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4863# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4864$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4865$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4866$path=~s/ /\+/g;4867$owner=~s/ /\+/g;48684869print"$path$owner\n";4870}4871}48724873sub git_summary {4874my$descr= git_get_project_description($project) ||"none";4875my%co= parse_commit("HEAD");4876my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4877my$head=$co{'id'};48784879my$owner= git_get_project_owner($project);48804881my$refs= git_get_references();4882# These get_*_list functions return one more to allow us to see if4883# there are more ...4884my@taglist= git_get_tags_list(16);4885my@headlist= git_get_heads_list(16);4886my@forklist;4887my$check_forks= gitweb_check_feature('forks');48884889if($check_forks) {4890@forklist= git_get_projects_list($project);4891}48924893 git_header_html();4894 git_print_page_nav('summary','',$head);48954896print"<div class=\"title\"> </div>\n";4897print"<table class=\"projects_list\">\n".4898"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4899"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4900if(defined$cd{'rfc2822'}) {4901print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4902}49034904# use per project git URL list in $projectroot/$project/cloneurl4905# or make project git URL from git base URL and project name4906my$url_tag="URL";4907my@url_list= git_get_project_url_list($project);4908@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4909foreachmy$git_url(@url_list) {4910next unless$git_url;4911print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4912$url_tag="";4913}49144915# Tag cloud4916my$show_ctags= gitweb_check_feature('ctags');4917if($show_ctags) {4918my$ctags= git_get_project_ctags($project);4919my$cloud= git_populate_project_tagcloud($ctags);4920print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4921print"</td>\n<td>"unless%$ctags;4922print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4923print"</td>\n<td>"if%$ctags;4924print git_show_project_tagcloud($cloud,48);4925print"</td></tr>";4926}49274928print"</table>\n";49294930# If XSS prevention is on, we don't include README.html.4931# TODO: Allow a readme in some safe format.4932if(!$prevent_xss&& -s "$projectroot/$project/README.html") {4933print"<div class=\"title\">readme</div>\n".4934"<div class=\"readme\">\n";4935 insert_file("$projectroot/$project/README.html");4936print"\n</div>\n";# class="readme"4937}49384939# we need to request one more than 16 (0..15) to check if4940# those 16 are all4941my@commitlist=$head? parse_commits($head,17) : ();4942if(@commitlist) {4943 git_print_header_div('shortlog');4944 git_shortlog_body(\@commitlist,0,15,$refs,4945$#commitlist<=15?undef:4946$cgi->a({-href => href(action=>"shortlog")},"..."));4947}49484949if(@taglist) {4950 git_print_header_div('tags');4951 git_tags_body(\@taglist,0,15,4952$#taglist<=15?undef:4953$cgi->a({-href => href(action=>"tags")},"..."));4954}49554956if(@headlist) {4957 git_print_header_div('heads');4958 git_heads_body(\@headlist,$head,0,15,4959$#headlist<=15?undef:4960$cgi->a({-href => href(action=>"heads")},"..."));4961}49624963if(@forklist) {4964 git_print_header_div('forks');4965 git_project_list_body(\@forklist,'age',0,15,4966$#forklist<=15?undef:4967$cgi->a({-href => href(action=>"forks")},"..."),4968'no_header');4969}49704971 git_footer_html();4972}49734974sub git_tag {4975my$head= git_get_head_hash($project);4976 git_header_html();4977 git_print_page_nav('','',$head,undef,$head);4978my%tag= parse_tag($hash);49794980if(!%tag) {4981 die_error(404,"Unknown tag object");4982}49834984 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4985print"<div class=\"title_text\">\n".4986"<table class=\"object_header\">\n".4987"<tr>\n".4988"<td>object</td>\n".4989"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4990$tag{'object'}) ."</td>\n".4991"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4992$tag{'type'}) ."</td>\n".4993"</tr>\n";4994if(defined($tag{'author'})) {4995 git_print_authorship_rows(\%tag,'author');4996}4997print"</table>\n\n".4998"</div>\n";4999print"<div class=\"page_body\">";5000my$comment=$tag{'comment'};5001foreachmy$line(@$comment) {5002chomp$line;5003print esc_html($line, -nbsp=>1) ."<br/>\n";5004}5005print"</div>\n";5006 git_footer_html();5007}50085009sub git_blame_common {5010my$format=shift||'porcelain';5011if($formateq'porcelain'&&$cgi->param('js')) {5012$format='incremental';5013$action='blame_incremental';# for page title etc5014}50155016# permissions5017 gitweb_check_feature('blame')5018or die_error(403,"Blame view not allowed");50195020# error checking5021 die_error(400,"No file name given")unless$file_name;5022$hash_base||= git_get_head_hash($project);5023 die_error(404,"Couldn't find base commit")unless$hash_base;5024my%co= parse_commit($hash_base)5025or die_error(404,"Commit not found");5026my$ftype="blob";5027if(!defined$hash) {5028$hash= git_get_hash_by_path($hash_base,$file_name,"blob")5029or die_error(404,"Error looking up file");5030}else{5031$ftype= git_get_type($hash);5032if($ftype!~"blob") {5033 die_error(400,"Object is not a blob");5034}5035}50365037my$fd;5038if($formateq'incremental') {5039# get file contents (as base)5040open$fd,"-|", git_cmd(),'cat-file','blob',$hash5041or die_error(500,"Open git-cat-file failed");5042}elsif($formateq'data') {5043# run git-blame --incremental5044open$fd,"-|", git_cmd(),"blame","--incremental",5045$hash_base,"--",$file_name5046or die_error(500,"Open git-blame --incremental failed");5047}else{5048# run git-blame --porcelain5049open$fd,"-|", git_cmd(),"blame",'-p',5050$hash_base,'--',$file_name5051or die_error(500,"Open git-blame --porcelain failed");5052}50535054# incremental blame data returns early5055if($formateq'data') {5056print$cgi->header(5057-type=>"text/plain", -charset =>"utf-8",5058-status=>"200 OK");5059local$| =1;# output autoflush5060printwhile<$fd>;5061close$fd5062or print"ERROR$!\n";50635064print'END';5065if(defined$t0&& gitweb_check_feature('timed')) {5066print' '.5067 Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).5068' '.$number_of_git_cmds;5069}5070print"\n";50715072return;5073}50745075# page header5076 git_header_html();5077my$formats_nav=5078$cgi->a({-href => href(action=>"blob", -replay=>1)},5079"blob") .5080" | ";5081if($formateq'incremental') {5082$formats_nav.=5083$cgi->a({-href => href(action=>"blame", javascript=>0, -replay=>1)},5084"blame") ." (non-incremental)";5085}else{5086$formats_nav.=5087$cgi->a({-href => href(action=>"blame_incremental", -replay=>1)},5088"blame") ." (incremental)";5089}5090$formats_nav.=5091" | ".5092$cgi->a({-href => href(action=>"history", -replay=>1)},5093"history") .5094" | ".5095$cgi->a({-href => href(action=>$action, file_name=>$file_name)},5096"HEAD");5097 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5098 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5099 git_print_page_path($file_name,$ftype,$hash_base);51005101# page body5102if($formateq'incremental') {5103print"<noscript>\n<div class=\"error\"><center><b>\n".5104"This page requires JavaScript to run.\nUse ".5105$cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},5106'this page').5107" instead.\n".5108"</b></center></div>\n</noscript>\n";51095110print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!;5111}51125113print qq!<div class="page_body">\n!;5114print qq!<div id="progress_info">.../ ...</div>\n!5115if($formateq'incremental');5116print qq!<table id="blame_table"class="blame" width="100%">\n!.5117#qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.5118 qq!<thead>\n!.5119 qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!.5120 qq!</thead>\n!.5121 qq!<tbody>\n!;51225123my@rev_color=qw(light dark);5124my$num_colors=scalar(@rev_color);5125my$current_color=0;51265127if($formateq'incremental') {5128my$color_class=$rev_color[$current_color];51295130#contents of a file5131my$linenr=0;5132 LINE:5133while(my$line= <$fd>) {5134chomp$line;5135$linenr++;51365137print qq!<tr id="l$linenr"class="$color_class">!.5138 qq!<td class="sha1"><a href=""> </a></td>!.5139 qq!<td class="linenr">!.5140 qq!<a class="linenr" href="">$linenr</a></td>!;5141print qq!<td class="pre">! . esc_html($line) ."</td>\n";5142print qq!</tr>\n!;5143}51445145}else{# porcelain, i.e. ordinary blame5146my%metainfo= ();# saves information about commits51475148# blame data5149 LINE:5150while(my$line= <$fd>) {5151chomp$line;5152# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]5153# no <lines in group> for subsequent lines in group of lines5154my($full_rev,$orig_lineno,$lineno,$group_size) =5155($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);5156if(!exists$metainfo{$full_rev}) {5157$metainfo{$full_rev} = {'nprevious'=>0};5158}5159my$meta=$metainfo{$full_rev};5160my$data;5161while($data= <$fd>) {5162chomp$data;5163last if($data=~s/^\t//);# contents of line5164if($data=~/^(\S+)(?: (.*))?$/) {5165$meta->{$1} =$2unlessexists$meta->{$1};5166}5167if($data=~/^previous /) {5168$meta->{'nprevious'}++;5169}5170}5171my$short_rev=substr($full_rev,0,8);5172my$author=$meta->{'author'};5173my%date=5174 parse_date($meta->{'author-time'},$meta->{'author-tz'});5175my$date=$date{'iso-tz'};5176if($group_size) {5177$current_color= ($current_color+1) %$num_colors;5178}5179my$tr_class=$rev_color[$current_color];5180$tr_class.=' boundary'if(exists$meta->{'boundary'});5181$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);5182$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);5183print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";5184if($group_size) {5185print"<td class=\"sha1\"";5186print" title=\"". esc_html($author) .",$date\"";5187print" rowspan=\"$group_size\""if($group_size>1);5188print">";5189print$cgi->a({-href => href(action=>"commit",5190 hash=>$full_rev,5191 file_name=>$file_name)},5192 esc_html($short_rev));5193if($group_size>=2) {5194my@author_initials= ($author=~/\b([[:upper:]])\B/g);5195if(@author_initials) {5196print"<br />".5197 esc_html(join('',@author_initials));5198# or join('.', ...)5199}5200}5201print"</td>\n";5202}5203# 'previous' <sha1 of parent commit> <filename at commit>5204if(exists$meta->{'previous'} &&5205$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {5206$meta->{'parent'} =$1;5207$meta->{'file_parent'} = unquote($2);5208}5209my$linenr_commit=5210exists($meta->{'parent'}) ?5211$meta->{'parent'} :$full_rev;5212my$linenr_filename=5213exists($meta->{'file_parent'}) ?5214$meta->{'file_parent'} : unquote($meta->{'filename'});5215my$blamed= href(action =>'blame',5216 file_name =>$linenr_filename,5217 hash_base =>$linenr_commit);5218print"<td class=\"linenr\">";5219print$cgi->a({ -href =>"$blamed#l$orig_lineno",5220-class=>"linenr"},5221 esc_html($lineno));5222print"</td>";5223print"<td class=\"pre\">". esc_html($data) ."</td>\n";5224print"</tr>\n";5225}# end while52265227}52285229# footer5230print"</tbody>\n".5231"</table>\n";# class="blame"5232print"</div>\n";# class="blame_body"5233close$fd5234or print"Reading blob failed\n";52355236 git_footer_html();5237}52385239sub git_blame {5240 git_blame_common();5241}52425243sub git_blame_incremental {5244 git_blame_common('incremental');5245}52465247sub git_blame_data {5248 git_blame_common('data');5249}52505251sub git_tags {5252my$head= git_get_head_hash($project);5253 git_header_html();5254 git_print_page_nav('','',$head,undef,$head);5255 git_print_header_div('summary',$project);52565257my@tagslist= git_get_tags_list();5258if(@tagslist) {5259 git_tags_body(\@tagslist);5260}5261 git_footer_html();5262}52635264sub git_heads {5265my$head= git_get_head_hash($project);5266 git_header_html();5267 git_print_page_nav('','',$head,undef,$head);5268 git_print_header_div('summary',$project);52695270my@headslist= git_get_heads_list();5271if(@headslist) {5272 git_heads_body(\@headslist,$head);5273}5274 git_footer_html();5275}52765277sub git_blob_plain {5278my$type=shift;5279my$expires;52805281if(!defined$hash) {5282if(defined$file_name) {5283my$base=$hash_base|| git_get_head_hash($project);5284$hash= git_get_hash_by_path($base,$file_name,"blob")5285or die_error(404,"Cannot find file");5286}else{5287 die_error(400,"No file name defined");5288}5289}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5290# blobs defined by non-textual hash id's can be cached5291$expires="+1d";5292}52935294open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5295or die_error(500,"Open git-cat-file blob '$hash' failed");52965297# content-type (can include charset)5298$type= blob_contenttype($fd,$file_name,$type);52995300# "save as" filename, even when no $file_name is given5301my$save_as="$hash";5302if(defined$file_name) {5303$save_as=$file_name;5304}elsif($type=~m/^text\//) {5305$save_as.='.txt';5306}53075308# With XSS prevention on, blobs of all types except a few known safe5309# ones are served with "Content-Disposition: attachment" to make sure5310# they don't run in our security domain. For certain image types,5311# blob view writes an <img> tag referring to blob_plain view, and we5312# want to be sure not to break that by serving the image as an5313# attachment (though Firefox 3 doesn't seem to care).5314my$sandbox=$prevent_xss&&5315$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;53165317print$cgi->header(5318-type =>$type,5319-expires =>$expires,5320-content_disposition =>5321($sandbox?'attachment':'inline')5322.'; filename="'.$save_as.'"');5323local$/=undef;5324binmode STDOUT,':raw';5325print<$fd>;5326binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5327close$fd;5328}53295330sub git_blob {5331my$expires;53325333if(!defined$hash) {5334if(defined$file_name) {5335my$base=$hash_base|| git_get_head_hash($project);5336$hash= git_get_hash_by_path($base,$file_name,"blob")5337or die_error(404,"Cannot find file");5338}else{5339 die_error(400,"No file name defined");5340}5341}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5342# blobs defined by non-textual hash id's can be cached5343$expires="+1d";5344}53455346my$have_blame= gitweb_check_feature('blame');5347open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5348or die_error(500,"Couldn't cat$file_name,$hash");5349my$mimetype= blob_mimetype($fd,$file_name);5350if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {5351close$fd;5352return git_blob_plain($mimetype);5353}5354# we can have blame only for text/* mimetype5355$have_blame&&= ($mimetype=~m!^text/!);53565357 git_header_html(undef,$expires);5358my$formats_nav='';5359if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5360if(defined$file_name) {5361if($have_blame) {5362$formats_nav.=5363$cgi->a({-href => href(action=>"blame", -replay=>1)},5364"blame") .5365" | ";5366}5367$formats_nav.=5368$cgi->a({-href => href(action=>"history", -replay=>1)},5369"history") .5370" | ".5371$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5372"raw") .5373" | ".5374$cgi->a({-href => href(action=>"blob",5375 hash_base=>"HEAD", file_name=>$file_name)},5376"HEAD");5377}else{5378$formats_nav.=5379$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5380"raw");5381}5382 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5383 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5384}else{5385print"<div class=\"page_nav\">\n".5386"<br/><br/></div>\n".5387"<div class=\"title\">$hash</div>\n";5388}5389 git_print_page_path($file_name,"blob",$hash_base);5390print"<div class=\"page_body\">\n";5391if($mimetype=~m!^image/!) {5392print qq!<img type="$mimetype"!;5393if($file_name) {5394print qq! alt="$file_name" title="$file_name"!;5395}5396print qq! src="! .5397 href(action=>"blob_plain", hash=>$hash,5398 hash_base=>$hash_base, file_name=>$file_name) .5399 qq!"/>\n!;5400}else{5401my$nr;5402while(my$line= <$fd>) {5403chomp$line;5404$nr++;5405$line= untabify($line);5406printf"<div class=\"pre\"><a id=\"l%i\"href=\"". href(-replay =>1)5407."#l%i\"class=\"linenr\">%4i</a>%s</div>\n",5408$nr,$nr,$nr, esc_html($line, -nbsp=>1);5409}5410}5411close$fd5412or print"Reading blob failed.\n";5413print"</div>";5414 git_footer_html();5415}54165417sub git_tree {5418if(!defined$hash_base) {5419$hash_base="HEAD";5420}5421if(!defined$hash) {5422if(defined$file_name) {5423$hash= git_get_hash_by_path($hash_base,$file_name,"tree");5424}else{5425$hash=$hash_base;5426}5427}5428 die_error(404,"No such tree")unlessdefined($hash);54295430my$show_sizes= gitweb_check_feature('show-sizes');5431my$have_blame= gitweb_check_feature('blame');54325433my@entries= ();5434{5435local$/="\0";5436open my$fd,"-|", git_cmd(),"ls-tree",'-z',5437($show_sizes?'-l': ()),@extra_options,$hash5438or die_error(500,"Open git-ls-tree failed");5439@entries=map{chomp;$_} <$fd>;5440close$fd5441or die_error(404,"Reading tree failed");5442}54435444my$refs= git_get_references();5445my$ref= format_ref_marker($refs,$hash_base);5446 git_header_html();5447my$basedir='';5448if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5449my@views_nav= ();5450if(defined$file_name) {5451push@views_nav,5452$cgi->a({-href => href(action=>"history", -replay=>1)},5453"history"),5454$cgi->a({-href => href(action=>"tree",5455 hash_base=>"HEAD", file_name=>$file_name)},5456"HEAD"),5457}5458my$snapshot_links= format_snapshot_links($hash);5459if(defined$snapshot_links) {5460# FIXME: Should be available when we have no hash base as well.5461push@views_nav,$snapshot_links;5462}5463 git_print_page_nav('tree','',$hash_base,undef,undef,5464join(' | ',@views_nav));5465 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);5466}else{5467undef$hash_base;5468print"<div class=\"page_nav\">\n";5469print"<br/><br/></div>\n";5470print"<div class=\"title\">$hash</div>\n";5471}5472if(defined$file_name) {5473$basedir=$file_name;5474if($basedirne''&&substr($basedir, -1)ne'/') {5475$basedir.='/';5476}5477 git_print_page_path($file_name,'tree',$hash_base);5478}5479print"<div class=\"page_body\">\n";5480print"<table class=\"tree\">\n";5481my$alternate=1;5482# '..' (top directory) link if possible5483if(defined$hash_base&&5484defined$file_name&&$file_name=~m![^/]+$!) {5485if($alternate) {5486print"<tr class=\"dark\">\n";5487}else{5488print"<tr class=\"light\">\n";5489}5490$alternate^=1;54915492my$up=$file_name;5493$up=~s!/?[^/]+$!!;5494undef$upunless$up;5495# based on git_print_tree_entry5496print'<td class="mode">'. mode_str('040000') ."</td>\n";5497print'<td class="size"> </td>'."\n"if$show_sizes;5498print'<td class="list">';5499print$cgi->a({-href => href(action=>"tree",5500 hash_base=>$hash_base,5501 file_name=>$up)},5502"..");5503print"</td>\n";5504print"<td class=\"link\"></td>\n";55055506print"</tr>\n";5507}5508foreachmy$line(@entries) {5509my%t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);55105511if($alternate) {5512print"<tr class=\"dark\">\n";5513}else{5514print"<tr class=\"light\">\n";5515}5516$alternate^=1;55175518 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);55195520print"</tr>\n";5521}5522print"</table>\n".5523"</div>";5524 git_footer_html();5525}55265527sub snapshot_name {5528my($project,$hash) =@_;55295530# path/to/project.git -> project5531# path/to/project/.git -> project5532my$name= to_utf8($project);5533$name=~ s,([^/])/*\.git$,$1,;5534$name= basename($name);5535# sanitize name5536$name=~s/[[:cntrl:]]/?/g;55375538my$ver=$hash;5539if($hash=~/^[0-9a-fA-F]+$/) {5540# shorten SHA-1 hash5541my$full_hash= git_get_full_hash($project,$hash);5542if($full_hash=~/^$hash/&&length($hash) >7) {5543$ver= git_get_short_hash($project,$hash);5544}5545}elsif($hash=~m!^refs/tags/(.*)$!) {5546# tags don't need shortened SHA-1 hash5547$ver=$1;5548}else{5549# branches and other need shortened SHA-1 hash5550if($hash=~m!^refs/(?:heads|remotes)/(.*)$!) {5551$ver=$1;5552}5553$ver.='-'. git_get_short_hash($project,$hash);5554}5555# in case of hierarchical branch names5556$ver=~s!/!.!g;55575558# name = project-version_string5559$name="$name-$ver";55605561returnwantarray? ($name,$name) :$name;5562}55635564sub git_snapshot {5565my$format=$input_params{'snapshot_format'};5566if(!@snapshot_fmts) {5567 die_error(403,"Snapshots not allowed");5568}5569# default to first supported snapshot format5570$format||=$snapshot_fmts[0];5571if($format!~m/^[a-z0-9]+$/) {5572 die_error(400,"Invalid snapshot format parameter");5573}elsif(!exists($known_snapshot_formats{$format})) {5574 die_error(400,"Unknown snapshot format");5575}elsif($known_snapshot_formats{$format}{'disabled'}) {5576 die_error(403,"Snapshot format not allowed");5577}elsif(!grep($_eq$format,@snapshot_fmts)) {5578 die_error(403,"Unsupported snapshot format");5579}55805581my$type= git_get_type("$hash^{}");5582if(!$type) {5583 die_error(404,'Object does not exist');5584}elsif($typeeq'blob') {5585 die_error(400,'Object is not a tree-ish');5586}55875588my($name,$prefix) = snapshot_name($project,$hash);5589my$filename="$name$known_snapshot_formats{$format}{'suffix'}";5590my$cmd= quote_command(5591 git_cmd(),'archive',5592"--format=$known_snapshot_formats{$format}{'format'}",5593"--prefix=$prefix/",$hash);5594if(exists$known_snapshot_formats{$format}{'compressor'}) {5595$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});5596}55975598$filename=~s/(["\\])/\\$1/g;5599print$cgi->header(5600-type =>$known_snapshot_formats{$format}{'type'},5601-content_disposition =>'inline; filename="'.$filename.'"',5602-status =>'200 OK');56035604open my$fd,"-|",$cmd5605or die_error(500,"Execute git-archive failed");5606binmode STDOUT,':raw';5607print<$fd>;5608binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5609close$fd;5610}56115612sub git_log_generic {5613my($fmt_name,$body_subr,$base,$parent,$file_name,$file_hash) =@_;56145615my$head= git_get_head_hash($project);5616if(!defined$base) {5617$base=$head;5618}5619if(!defined$page) {5620$page=0;5621}5622my$refs= git_get_references();56235624my$commit_hash=$base;5625if(defined$parent) {5626$commit_hash="$parent..$base";5627}5628my@commitlist=5629 parse_commits($commit_hash,101, (100*$page),5630defined$file_name? ($file_name,"--full-history") : ());56315632my$ftype;5633if(!defined$file_hash&&defined$file_name) {5634# some commits could have deleted file in question,5635# and not have it in tree, but one of them has to have it5636for(my$i=0;$i<@commitlist;$i++) {5637$file_hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5638last ifdefined$file_hash;5639}5640}5641if(defined$file_hash) {5642$ftype= git_get_type($file_hash);5643}5644if(defined$file_name&& !defined$ftype) {5645 die_error(500,"Unknown type of object");5646}5647my%co;5648if(defined$file_name) {5649%co= parse_commit($base)5650or die_error(404,"Unknown commit object");5651}565256535654my$paging_nav= format_paging_nav($fmt_name,$page,$#commitlist>=100);5655my$next_link='';5656if($#commitlist>=100) {5657$next_link=5658$cgi->a({-href => href(-replay=>1, page=>$page+1),5659-accesskey =>"n", -title =>"Alt-n"},"next");5660}5661my$patch_max= gitweb_get_feature('patches');5662if($patch_max&& !defined$file_name) {5663if($patch_max<0||@commitlist<=$patch_max) {5664$paging_nav.=" ⋅ ".5665$cgi->a({-href => href(action=>"patches", -replay=>1)},5666"patches");5667}5668}56695670 git_header_html();5671 git_print_page_nav($fmt_name,'',$hash,$hash,$hash,$paging_nav);5672if(defined$file_name) {5673 git_print_header_div('commit', esc_html($co{'title'}),$base);5674}else{5675 git_print_header_div('summary',$project)5676}5677 git_print_page_path($file_name,$ftype,$hash_base)5678if(defined$file_name);56795680$body_subr->(\@commitlist,0,99,$refs,$next_link,5681$file_name,$file_hash,$ftype);56825683 git_footer_html();5684}56855686sub git_log {5687 git_log_generic('log', \&git_log_body,5688$hash,$hash_parent);5689}56905691sub git_commit {5692$hash||=$hash_base||"HEAD";5693my%co= parse_commit($hash)5694or die_error(404,"Unknown commit object");56955696my$parent=$co{'parent'};5697my$parents=$co{'parents'};# listref56985699# we need to prepare $formats_nav before any parameter munging5700my$formats_nav;5701if(!defined$parent) {5702# --root commitdiff5703$formats_nav.='(initial)';5704}elsif(@$parents==1) {5705# single parent commit5706$formats_nav.=5707'(parent: '.5708$cgi->a({-href => href(action=>"commit",5709 hash=>$parent)},5710 esc_html(substr($parent,0,7))) .5711')';5712}else{5713# merge commit5714$formats_nav.=5715'(merge: '.5716join(' ',map{5717$cgi->a({-href => href(action=>"commit",5718 hash=>$_)},5719 esc_html(substr($_,0,7)));5720}@$parents) .5721')';5722}5723if(gitweb_check_feature('patches') &&@$parents<=1) {5724$formats_nav.=" | ".5725$cgi->a({-href => href(action=>"patch", -replay=>1)},5726"patch");5727}57285729if(!defined$parent) {5730$parent="--root";5731}5732my@difftree;5733open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5734@diff_opts,5735(@$parents<=1?$parent:'-c'),5736$hash,"--"5737or die_error(500,"Open git-diff-tree failed");5738@difftree=map{chomp;$_} <$fd>;5739close$fdor die_error(404,"Reading git-diff-tree failed");57405741# non-textual hash id's can be cached5742my$expires;5743if($hash=~m/^[0-9a-fA-F]{40}$/) {5744$expires="+1d";5745}5746my$refs= git_get_references();5747my$ref= format_ref_marker($refs,$co{'id'});57485749 git_header_html(undef,$expires);5750 git_print_page_nav('commit','',5751$hash,$co{'tree'},$hash,5752$formats_nav);57535754if(defined$co{'parent'}) {5755 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5756}else{5757 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5758}5759print"<div class=\"title_text\">\n".5760"<table class=\"object_header\">\n";5761 git_print_authorship_rows(\%co);5762print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";5763print"<tr>".5764"<td>tree</td>".5765"<td class=\"sha1\">".5766$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),5767class=>"list"},$co{'tree'}) .5768"</td>".5769"<td class=\"link\">".5770$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},5771"tree");5772my$snapshot_links= format_snapshot_links($hash);5773if(defined$snapshot_links) {5774print" | ".$snapshot_links;5775}5776print"</td>".5777"</tr>\n";57785779foreachmy$par(@$parents) {5780print"<tr>".5781"<td>parent</td>".5782"<td class=\"sha1\">".5783$cgi->a({-href => href(action=>"commit", hash=>$par),5784class=>"list"},$par) .5785"</td>".5786"<td class=\"link\">".5787$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .5788" | ".5789$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .5790"</td>".5791"</tr>\n";5792}5793print"</table>".5794"</div>\n";57955796print"<div class=\"page_body\">\n";5797 git_print_log($co{'comment'});5798print"</div>\n";57995800 git_difftree_body(\@difftree,$hash,@$parents);58015802 git_footer_html();5803}58045805sub git_object {5806# object is defined by:5807# - hash or hash_base alone5808# - hash_base and file_name5809my$type;58105811# - hash or hash_base alone5812if($hash|| ($hash_base&& !defined$file_name)) {5813my$object_id=$hash||$hash_base;58145815open my$fd,"-|", quote_command(5816 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'5817or die_error(404,"Object does not exist");5818$type= <$fd>;5819chomp$type;5820close$fd5821or die_error(404,"Object does not exist");58225823# - hash_base and file_name5824}elsif($hash_base&&defined$file_name) {5825$file_name=~ s,/+$,,;58265827system(git_cmd(),"cat-file",'-e',$hash_base) ==05828or die_error(404,"Base object does not exist");58295830# here errors should not hapen5831open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name5832or die_error(500,"Open git-ls-tree failed");5833my$line= <$fd>;5834close$fd;58355836#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'5837unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {5838 die_error(404,"File or directory for given base does not exist");5839}5840$type=$2;5841$hash=$3;5842}else{5843 die_error(400,"Not enough information to find object");5844}58455846print$cgi->redirect(-uri => href(action=>$type, -full=>1,5847 hash=>$hash, hash_base=>$hash_base,5848 file_name=>$file_name),5849-status =>'302 Found');5850}58515852sub git_blobdiff {5853my$format=shift||'html';58545855my$fd;5856my@difftree;5857my%diffinfo;5858my$expires;58595860# preparing $fd and %diffinfo for git_patchset_body5861# new style URI5862if(defined$hash_base&&defined$hash_parent_base) {5863if(defined$file_name) {5864# read raw output5865open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5866$hash_parent_base,$hash_base,5867"--", (defined$file_parent?$file_parent: ()),$file_name5868or die_error(500,"Open git-diff-tree failed");5869@difftree=map{chomp;$_} <$fd>;5870close$fd5871or die_error(404,"Reading git-diff-tree failed");5872@difftree5873or die_error(404,"Blob diff not found");58745875}elsif(defined$hash&&5876$hash=~/[0-9a-fA-F]{40}/) {5877# try to find filename from $hash58785879# read filtered raw output5880open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5881$hash_parent_base,$hash_base,"--"5882or die_error(500,"Open git-diff-tree failed");5883@difftree=5884# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5885# $hash == to_id5886grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5887map{chomp;$_} <$fd>;5888close$fd5889or die_error(404,"Reading git-diff-tree failed");5890@difftree5891or die_error(404,"Blob diff not found");58925893}else{5894 die_error(400,"Missing one of the blob diff parameters");5895}58965897if(@difftree>1) {5898 die_error(400,"Ambiguous blob diff specification");5899}59005901%diffinfo= parse_difftree_raw_line($difftree[0]);5902$file_parent||=$diffinfo{'from_file'} ||$file_name;5903$file_name||=$diffinfo{'to_file'};59045905$hash_parent||=$diffinfo{'from_id'};5906$hash||=$diffinfo{'to_id'};59075908# non-textual hash id's can be cached5909if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5910$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5911$expires='+1d';5912}59135914# open patch output5915open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5916'-p', ($formateq'html'?"--full-index": ()),5917$hash_parent_base,$hash_base,5918"--", (defined$file_parent?$file_parent: ()),$file_name5919or die_error(500,"Open git-diff-tree failed");5920}59215922# old/legacy style URI -- not generated anymore since 1.4.3.5923if(!%diffinfo) {5924 die_error('404 Not Found',"Missing one of the blob diff parameters")5925}59265927# header5928if($formateq'html') {5929my$formats_nav=5930$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5931"raw");5932 git_header_html(undef,$expires);5933if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5934 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5935 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5936}else{5937print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5938print"<div class=\"title\">$hashvs$hash_parent</div>\n";5939}5940if(defined$file_name) {5941 git_print_page_path($file_name,"blob",$hash_base);5942}else{5943print"<div class=\"page_path\"></div>\n";5944}59455946}elsif($formateq'plain') {5947print$cgi->header(5948-type =>'text/plain',5949-charset =>'utf-8',5950-expires =>$expires,5951-content_disposition =>'inline; filename="'."$file_name".'.patch"');59525953print"X-Git-Url: ".$cgi->self_url() ."\n\n";59545955}else{5956 die_error(400,"Unknown blobdiff format");5957}59585959# patch5960if($formateq'html') {5961print"<div class=\"page_body\">\n";59625963 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5964close$fd;59655966print"</div>\n";# class="page_body"5967 git_footer_html();59685969}else{5970while(my$line= <$fd>) {5971$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5972$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;59735974print$line;59755976last if$line=~m!^\+\+\+!;5977}5978local$/=undef;5979print<$fd>;5980close$fd;5981}5982}59835984sub git_blobdiff_plain {5985 git_blobdiff('plain');5986}59875988sub git_commitdiff {5989my%params=@_;5990my$format=$params{-format} ||'html';59915992my($patch_max) = gitweb_get_feature('patches');5993if($formateq'patch') {5994 die_error(403,"Patch view not allowed")unless$patch_max;5995}59965997$hash||=$hash_base||"HEAD";5998my%co= parse_commit($hash)5999or die_error(404,"Unknown commit object");60006001# choose format for commitdiff for merge6002if(!defined$hash_parent&& @{$co{'parents'}} >1) {6003$hash_parent='--cc';6004}6005# we need to prepare $formats_nav before almost any parameter munging6006my$formats_nav;6007if($formateq'html') {6008$formats_nav=6009$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},6010"raw");6011if($patch_max&& @{$co{'parents'}} <=1) {6012$formats_nav.=" | ".6013$cgi->a({-href => href(action=>"patch", -replay=>1)},6014"patch");6015}60166017if(defined$hash_parent&&6018$hash_parentne'-c'&&$hash_parentne'--cc') {6019# commitdiff with two commits given6020my$hash_parent_short=$hash_parent;6021if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {6022$hash_parent_short=substr($hash_parent,0,7);6023}6024$formats_nav.=6025' (from';6026for(my$i=0;$i< @{$co{'parents'}};$i++) {6027if($co{'parents'}[$i]eq$hash_parent) {6028$formats_nav.=' parent '. ($i+1);6029last;6030}6031}6032$formats_nav.=': '.6033$cgi->a({-href => href(action=>"commitdiff",6034 hash=>$hash_parent)},6035 esc_html($hash_parent_short)) .6036')';6037}elsif(!$co{'parent'}) {6038# --root commitdiff6039$formats_nav.=' (initial)';6040}elsif(scalar@{$co{'parents'}} ==1) {6041# single parent commit6042$formats_nav.=6043' (parent: '.6044$cgi->a({-href => href(action=>"commitdiff",6045 hash=>$co{'parent'})},6046 esc_html(substr($co{'parent'},0,7))) .6047')';6048}else{6049# merge commit6050if($hash_parenteq'--cc') {6051$formats_nav.=' | '.6052$cgi->a({-href => href(action=>"commitdiff",6053 hash=>$hash, hash_parent=>'-c')},6054'combined');6055}else{# $hash_parent eq '-c'6056$formats_nav.=' | '.6057$cgi->a({-href => href(action=>"commitdiff",6058 hash=>$hash, hash_parent=>'--cc')},6059'compact');6060}6061$formats_nav.=6062' (merge: '.6063join(' ',map{6064$cgi->a({-href => href(action=>"commitdiff",6065 hash=>$_)},6066 esc_html(substr($_,0,7)));6067} @{$co{'parents'}} ) .6068')';6069}6070}60716072my$hash_parent_param=$hash_parent;6073if(!defined$hash_parent_param) {6074# --cc for multiple parents, --root for parentless6075$hash_parent_param=6076@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';6077}60786079# read commitdiff6080my$fd;6081my@difftree;6082if($formateq'html') {6083open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6084"--no-commit-id","--patch-with-raw","--full-index",6085$hash_parent_param,$hash,"--"6086or die_error(500,"Open git-diff-tree failed");60876088while(my$line= <$fd>) {6089chomp$line;6090# empty line ends raw part of diff-tree output6091last unless$line;6092push@difftree,scalar parse_difftree_raw_line($line);6093}60946095}elsif($formateq'plain') {6096open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6097'-p',$hash_parent_param,$hash,"--"6098or die_error(500,"Open git-diff-tree failed");6099}elsif($formateq'patch') {6100# For commit ranges, we limit the output to the number of6101# patches specified in the 'patches' feature.6102# For single commits, we limit the output to a single patch,6103# diverging from the git-format-patch default.6104my@commit_spec= ();6105if($hash_parent) {6106if($patch_max>0) {6107push@commit_spec,"-$patch_max";6108}6109push@commit_spec,'-n',"$hash_parent..$hash";6110}else{6111if($params{-single}) {6112push@commit_spec,'-1';6113}else{6114if($patch_max>0) {6115push@commit_spec,"-$patch_max";6116}6117push@commit_spec,"-n";6118}6119push@commit_spec,'--root',$hash;6120}6121open$fd,"-|", git_cmd(),"format-patch",'--encoding=utf8',6122'--stdout',@commit_spec6123or die_error(500,"Open git-format-patch failed");6124}else{6125 die_error(400,"Unknown commitdiff format");6126}61276128# non-textual hash id's can be cached6129my$expires;6130if($hash=~m/^[0-9a-fA-F]{40}$/) {6131$expires="+1d";6132}61336134# write commit message6135if($formateq'html') {6136my$refs= git_get_references();6137my$ref= format_ref_marker($refs,$co{'id'});61386139 git_header_html(undef,$expires);6140 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);6141 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);6142print"<div class=\"title_text\">\n".6143"<table class=\"object_header\">\n";6144 git_print_authorship_rows(\%co);6145print"</table>".6146"</div>\n";6147print"<div class=\"page_body\">\n";6148if(@{$co{'comment'}} >1) {6149print"<div class=\"log\">\n";6150 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);6151print"</div>\n";# class="log"6152}61536154}elsif($formateq'plain') {6155my$refs= git_get_references("tags");6156my$tagname= git_get_rev_name_tags($hash);6157my$filename= basename($project) ."-$hash.patch";61586159print$cgi->header(6160-type =>'text/plain',6161-charset =>'utf-8',6162-expires =>$expires,6163-content_disposition =>'inline; filename="'."$filename".'"');6164my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});6165print"From: ". to_utf8($co{'author'}) ."\n";6166print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";6167print"Subject: ". to_utf8($co{'title'}) ."\n";61686169print"X-Git-Tag:$tagname\n"if$tagname;6170print"X-Git-Url: ".$cgi->self_url() ."\n\n";61716172foreachmy$line(@{$co{'comment'}}) {6173print to_utf8($line) ."\n";6174}6175print"---\n\n";6176}elsif($formateq'patch') {6177my$filename= basename($project) ."-$hash.patch";61786179print$cgi->header(6180-type =>'text/plain',6181-charset =>'utf-8',6182-expires =>$expires,6183-content_disposition =>'inline; filename="'."$filename".'"');6184}61856186# write patch6187if($formateq'html') {6188my$use_parents= !defined$hash_parent||6189$hash_parenteq'-c'||$hash_parenteq'--cc';6190 git_difftree_body(\@difftree,$hash,6191$use_parents? @{$co{'parents'}} :$hash_parent);6192print"<br/>\n";61936194 git_patchset_body($fd, \@difftree,$hash,6195$use_parents? @{$co{'parents'}} :$hash_parent);6196close$fd;6197print"</div>\n";# class="page_body"6198 git_footer_html();61996200}elsif($formateq'plain') {6201local$/=undef;6202print<$fd>;6203close$fd6204or print"Reading git-diff-tree failed\n";6205}elsif($formateq'patch') {6206local$/=undef;6207print<$fd>;6208close$fd6209or print"Reading git-format-patch failed\n";6210}6211}62126213sub git_commitdiff_plain {6214 git_commitdiff(-format =>'plain');6215}62166217# format-patch-style patches6218sub git_patch {6219 git_commitdiff(-format =>'patch', -single =>1);6220}62216222sub git_patches {6223 git_commitdiff(-format =>'patch');6224}62256226sub git_history {6227 git_log_generic('history', \&git_history_body,6228$hash_base,$hash_parent_base,6229$file_name,$hash);6230}62316232sub git_search {6233 gitweb_check_feature('search')or die_error(403,"Search is disabled");6234if(!defined$searchtext) {6235 die_error(400,"Text field is empty");6236}6237if(!defined$hash) {6238$hash= git_get_head_hash($project);6239}6240my%co= parse_commit($hash);6241if(!%co) {6242 die_error(404,"Unknown commit object");6243}6244if(!defined$page) {6245$page=0;6246}62476248$searchtype||='commit';6249if($searchtypeeq'pickaxe') {6250# pickaxe may take all resources of your box and run for several minutes6251# with every query - so decide by yourself how public you make this feature6252 gitweb_check_feature('pickaxe')6253or die_error(403,"Pickaxe is disabled");6254}6255if($searchtypeeq'grep') {6256 gitweb_check_feature('grep')6257or die_error(403,"Grep is disabled");6258}62596260 git_header_html();62616262if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {6263my$greptype;6264if($searchtypeeq'commit') {6265$greptype="--grep=";6266}elsif($searchtypeeq'author') {6267$greptype="--author=";6268}elsif($searchtypeeq'committer') {6269$greptype="--committer=";6270}6271$greptype.=$searchtext;6272my@commitlist= parse_commits($hash,101, (100*$page),undef,6273$greptype,'--regexp-ignore-case',6274$search_use_regexp?'--extended-regexp':'--fixed-strings');62756276my$paging_nav='';6277if($page>0) {6278$paging_nav.=6279$cgi->a({-href => href(action=>"search", hash=>$hash,6280 searchtext=>$searchtext,6281 searchtype=>$searchtype)},6282"first");6283$paging_nav.=" ⋅ ".6284$cgi->a({-href => href(-replay=>1, page=>$page-1),6285-accesskey =>"p", -title =>"Alt-p"},"prev");6286}else{6287$paging_nav.="first";6288$paging_nav.=" ⋅ prev";6289}6290my$next_link='';6291if($#commitlist>=100) {6292$next_link=6293$cgi->a({-href => href(-replay=>1, page=>$page+1),6294-accesskey =>"n", -title =>"Alt-n"},"next");6295$paging_nav.=" ⋅$next_link";6296}else{6297$paging_nav.=" ⋅ next";6298}62996300if($#commitlist>=100) {6301}63026303 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);6304 git_print_header_div('commit', esc_html($co{'title'}),$hash);6305 git_search_grep_body(\@commitlist,0,99,$next_link);6306}63076308if($searchtypeeq'pickaxe') {6309 git_print_page_nav('','',$hash,$co{'tree'},$hash);6310 git_print_header_div('commit', esc_html($co{'title'}),$hash);63116312print"<table class=\"pickaxe search\">\n";6313my$alternate=1;6314local$/="\n";6315open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,6316'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",6317($search_use_regexp?'--pickaxe-regex': ());6318undef%co;6319my@files;6320while(my$line= <$fd>) {6321chomp$line;6322next unless$line;63236324my%set= parse_difftree_raw_line($line);6325if(defined$set{'commit'}) {6326# finish previous commit6327if(%co) {6328print"</td>\n".6329"<td class=\"link\">".6330$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6331" | ".6332$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6333print"</td>\n".6334"</tr>\n";6335}63366337if($alternate) {6338print"<tr class=\"dark\">\n";6339}else{6340print"<tr class=\"light\">\n";6341}6342$alternate^=1;6343%co= parse_commit($set{'commit'});6344my$author= chop_and_escape_str($co{'author_name'},15,5);6345print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6346"<td><i>$author</i></td>\n".6347"<td>".6348$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6349-class=>"list subject"},6350 chop_and_escape_str($co{'title'},50) ."<br/>");6351}elsif(defined$set{'to_id'}) {6352next if($set{'to_id'} =~m/^0{40}$/);63536354print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6355 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6356-class=>"list"},6357"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6358"<br/>\n";6359}6360}6361close$fd;63626363# finish last commit (warning: repetition!)6364if(%co) {6365print"</td>\n".6366"<td class=\"link\">".6367$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6368" | ".6369$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6370print"</td>\n".6371"</tr>\n";6372}63736374print"</table>\n";6375}63766377if($searchtypeeq'grep') {6378 git_print_page_nav('','',$hash,$co{'tree'},$hash);6379 git_print_header_div('commit', esc_html($co{'title'}),$hash);63806381print"<table class=\"grep_search\">\n";6382my$alternate=1;6383my$matches=0;6384local$/="\n";6385open my$fd,"-|", git_cmd(),'grep','-n',6386$search_use_regexp? ('-E','-i') :'-F',6387$searchtext,$co{'tree'};6388my$lastfile='';6389while(my$line= <$fd>) {6390chomp$line;6391my($file,$lno,$ltext,$binary);6392last if($matches++>1000);6393if($line=~/^Binary file (.+) matches$/) {6394$file=$1;6395$binary=1;6396}else{6397(undef,$file,$lno,$ltext) =split(/:/,$line,4);6398}6399if($filene$lastfile) {6400$lastfileand print"</td></tr>\n";6401if($alternate++) {6402print"<tr class=\"dark\">\n";6403}else{6404print"<tr class=\"light\">\n";6405}6406print"<td class=\"list\">".6407$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6408 file_name=>"$file"),6409-class=>"list"}, esc_path($file));6410print"</td><td>\n";6411$lastfile=$file;6412}6413if($binary) {6414print"<div class=\"binary\">Binary file</div>\n";6415}else{6416$ltext= untabify($ltext);6417if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6418$ltext= esc_html($1, -nbsp=>1);6419$ltext.='<span class="match">';6420$ltext.= esc_html($2, -nbsp=>1);6421$ltext.='</span>';6422$ltext.= esc_html($3, -nbsp=>1);6423}else{6424$ltext= esc_html($ltext, -nbsp=>1);6425}6426print"<div class=\"pre\">".6427$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6428 file_name=>"$file").'#l'.$lno,6429-class=>"linenr"},sprintf('%4i',$lno))6430.' '.$ltext."</div>\n";6431}6432}6433if($lastfile) {6434print"</td></tr>\n";6435if($matches>1000) {6436print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6437}6438}else{6439print"<div class=\"diff nodifferences\">No matches found</div>\n";6440}6441close$fd;64426443print"</table>\n";6444}6445 git_footer_html();6446}64476448sub git_search_help {6449 git_header_html();6450 git_print_page_nav('','',$hash,$hash,$hash);6451print<<EOT;6452<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without6453regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,6454the pattern entered is recognized as the POSIX extended6455<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case6456insensitive).</p>6457<dl>6458<dt><b>commit</b></dt>6459<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>6460EOT6461my$have_grep= gitweb_check_feature('grep');6462if($have_grep) {6463print<<EOT;6464<dt><b>grep</b></dt>6465<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing6466 a different one) are searched for the given pattern. On large trees, this search can take6467a while and put some strain on the server, so please use it with some consideration. Note that6468due to git-grep peculiarity, currently if regexp mode is turned off, the matches are6469case-sensitive.</dd>6470EOT6471}6472print<<EOT;6473<dt><b>author</b></dt>6474<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>6475<dt><b>committer</b></dt>6476<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>6477EOT6478my$have_pickaxe= gitweb_check_feature('pickaxe');6479if($have_pickaxe) {6480print<<EOT;6481<dt><b>pickaxe</b></dt>6482<dd>All commits that caused the string to appear or disappear from any file (changes that6483added, removed or "modified" the string) will be listed. This search can take a while and6484takes a lot of strain on the server, so please use it wisely. Note that since you may be6485interested even in changes just changing the case as well, this search is case sensitive.</dd>6486EOT6487}6488print"</dl>\n";6489 git_footer_html();6490}64916492sub git_shortlog {6493 git_log_generic('shortlog', \&git_shortlog_body,6494$hash,$hash_parent);6495}64966497## ......................................................................6498## feeds (RSS, Atom; OPML)64996500sub git_feed {6501my$format=shift||'atom';6502my$have_blame= gitweb_check_feature('blame');65036504# Atom: http://www.atomenabled.org/developers/syndication/6505# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ6506if($formatne'rss'&&$formatne'atom') {6507 die_error(400,"Unknown web feed format");6508}65096510# log/feed of current (HEAD) branch, log of given branch, history of file/directory6511my$head=$hash||'HEAD';6512my@commitlist= parse_commits($head,150,0,$file_name);65136514my%latest_commit;6515my%latest_date;6516my$content_type="application/$format+xml";6517if(defined$cgi->http('HTTP_ACCEPT') &&6518$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {6519# browser (feed reader) prefers text/xml6520$content_type='text/xml';6521}6522if(defined($commitlist[0])) {6523%latest_commit= %{$commitlist[0]};6524my$latest_epoch=$latest_commit{'committer_epoch'};6525%latest_date= parse_date($latest_epoch);6526my$if_modified=$cgi->http('IF_MODIFIED_SINCE');6527if(defined$if_modified) {6528my$since;6529if(eval{require HTTP::Date;1; }) {6530$since= HTTP::Date::str2time($if_modified);6531}elsif(eval{require Time::ParseDate;1; }) {6532$since= Time::ParseDate::parsedate($if_modified, GMT =>1);6533}6534if(defined$since&&$latest_epoch<=$since) {6535print$cgi->header(6536-type =>$content_type,6537-charset =>'utf-8',6538-last_modified =>$latest_date{'rfc2822'},6539-status =>'304 Not Modified');6540return;6541}6542}6543print$cgi->header(6544-type =>$content_type,6545-charset =>'utf-8',6546-last_modified =>$latest_date{'rfc2822'});6547}else{6548print$cgi->header(6549-type =>$content_type,6550-charset =>'utf-8');6551}65526553# Optimization: skip generating the body if client asks only6554# for Last-Modified date.6555return if($cgi->request_method()eq'HEAD');65566557# header variables6558my$title="$site_name-$project/$action";6559my$feed_type='log';6560if(defined$hash) {6561$title.=" - '$hash'";6562$feed_type='branch log';6563if(defined$file_name) {6564$title.=" ::$file_name";6565$feed_type='history';6566}6567}elsif(defined$file_name) {6568$title.=" -$file_name";6569$feed_type='history';6570}6571$title.="$feed_type";6572my$descr= git_get_project_description($project);6573if(defined$descr) {6574$descr= esc_html($descr);6575}else{6576$descr="$project".6577($formateq'rss'?'RSS':'Atom') .6578" feed";6579}6580my$owner= git_get_project_owner($project);6581$owner= esc_html($owner);65826583#header6584my$alt_url;6585if(defined$file_name) {6586$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);6587}elsif(defined$hash) {6588$alt_url= href(-full=>1, action=>"log", hash=>$hash);6589}else{6590$alt_url= href(-full=>1, action=>"summary");6591}6592print qq!<?xml version="1.0" encoding="utf-8"?>\n!;6593if($formateq'rss') {6594print<<XML;6595<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">6596<channel>6597XML6598print"<title>$title</title>\n".6599"<link>$alt_url</link>\n".6600"<description>$descr</description>\n".6601"<language>en</language>\n".6602# project owner is responsible for 'editorial' content6603"<managingEditor>$owner</managingEditor>\n";6604if(defined$logo||defined$favicon) {6605# prefer the logo to the favicon, since RSS6606# doesn't allow both6607my$img= esc_url($logo||$favicon);6608print"<image>\n".6609"<url>$img</url>\n".6610"<title>$title</title>\n".6611"<link>$alt_url</link>\n".6612"</image>\n";6613}6614if(%latest_date) {6615print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";6616print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";6617}6618print"<generator>gitweb v.$version/$git_version</generator>\n";6619}elsif($formateq'atom') {6620print<<XML;6621<feed xmlns="http://www.w3.org/2005/Atom">6622XML6623print"<title>$title</title>\n".6624"<subtitle>$descr</subtitle>\n".6625'<link rel="alternate" type="text/html" href="'.6626$alt_url.'" />'."\n".6627'<link rel="self" type="'.$content_type.'" href="'.6628$cgi->self_url() .'" />'."\n".6629"<id>". href(-full=>1) ."</id>\n".6630# use project owner for feed author6631"<author><name>$owner</name></author>\n";6632if(defined$favicon) {6633print"<icon>". esc_url($favicon) ."</icon>\n";6634}6635if(defined$logo_url) {6636# not twice as wide as tall: 72 x 27 pixels6637print"<logo>". esc_url($logo) ."</logo>\n";6638}6639if(!%latest_date) {6640# dummy date to keep the feed valid until commits trickle in:6641print"<updated>1970-01-01T00:00:00Z</updated>\n";6642}else{6643print"<updated>$latest_date{'iso-8601'}</updated>\n";6644}6645print"<generator version='$version/$git_version'>gitweb</generator>\n";6646}66476648# contents6649for(my$i=0;$i<=$#commitlist;$i++) {6650my%co= %{$commitlist[$i]};6651my$commit=$co{'id'};6652# we read 150, we always show 30 and the ones more recent than 48 hours6653if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6654last;6655}6656my%cd= parse_date($co{'author_epoch'});66576658# get list of changed files6659open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6660$co{'parent'} ||"--root",6661$co{'id'},"--", (defined$file_name?$file_name: ())6662ornext;6663my@difftree=map{chomp;$_} <$fd>;6664close$fd6665ornext;66666667# print element (entry, item)6668my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6669if($formateq'rss') {6670print"<item>\n".6671"<title>". esc_html($co{'title'}) ."</title>\n".6672"<author>". esc_html($co{'author'}) ."</author>\n".6673"<pubDate>$cd{'rfc2822'}</pubDate>\n".6674"<guid isPermaLink=\"true\">$co_url</guid>\n".6675"<link>$co_url</link>\n".6676"<description>". esc_html($co{'title'}) ."</description>\n".6677"<content:encoded>".6678"<![CDATA[\n";6679}elsif($formateq'atom') {6680print"<entry>\n".6681"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6682"<updated>$cd{'iso-8601'}</updated>\n".6683"<author>\n".6684" <name>". esc_html($co{'author_name'}) ."</name>\n";6685if($co{'author_email'}) {6686print" <email>". esc_html($co{'author_email'}) ."</email>\n";6687}6688print"</author>\n".6689# use committer for contributor6690"<contributor>\n".6691" <name>". esc_html($co{'committer_name'}) ."</name>\n";6692if($co{'committer_email'}) {6693print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6694}6695print"</contributor>\n".6696"<published>$cd{'iso-8601'}</published>\n".6697"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6698"<id>$co_url</id>\n".6699"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6700"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6701}6702my$comment=$co{'comment'};6703print"<pre>\n";6704foreachmy$line(@$comment) {6705$line= esc_html($line);6706print"$line\n";6707}6708print"</pre><ul>\n";6709foreachmy$difftree_line(@difftree) {6710my%difftree= parse_difftree_raw_line($difftree_line);6711next if!$difftree{'from_id'};67126713my$file=$difftree{'file'} ||$difftree{'to_file'};67146715print"<li>".6716"[".6717$cgi->a({-href => href(-full=>1, action=>"blobdiff",6718 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6719 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6720 file_name=>$file, file_parent=>$difftree{'from_file'}),6721-title =>"diff"},'D');6722if($have_blame) {6723print$cgi->a({-href => href(-full=>1, action=>"blame",6724 file_name=>$file, hash_base=>$commit),6725-title =>"blame"},'B');6726}6727# if this is not a feed of a file history6728if(!defined$file_name||$file_namene$file) {6729print$cgi->a({-href => href(-full=>1, action=>"history",6730 file_name=>$file, hash=>$commit),6731-title =>"history"},'H');6732}6733$file= esc_path($file);6734print"] ".6735"$file</li>\n";6736}6737if($formateq'rss') {6738print"</ul>]]>\n".6739"</content:encoded>\n".6740"</item>\n";6741}elsif($formateq'atom') {6742print"</ul>\n</div>\n".6743"</content>\n".6744"</entry>\n";6745}6746}67476748# end of feed6749if($formateq'rss') {6750print"</channel>\n</rss>\n";6751}elsif($formateq'atom') {6752print"</feed>\n";6753}6754}67556756sub git_rss {6757 git_feed('rss');6758}67596760sub git_atom {6761 git_feed('atom');6762}67636764sub git_opml {6765my@list= git_get_projects_list();67666767print$cgi->header(6768-type =>'text/xml',6769-charset =>'utf-8',6770-content_disposition =>'inline; filename="opml.xml"');67716772print<<XML;6773<?xml version="1.0" encoding="utf-8"?>6774<opml version="1.0">6775<head>6776 <title>$site_nameOPML Export</title>6777</head>6778<body>6779<outline text="git RSS feeds">6780XML67816782foreachmy$pr(@list) {6783my%proj=%$pr;6784my$head= git_get_head_hash($proj{'path'});6785if(!defined$head) {6786next;6787}6788$git_dir="$projectroot/$proj{'path'}";6789my%co= parse_commit($head);6790if(!%co) {6791next;6792}67936794my$path= esc_html(chop_str($proj{'path'},25,5));6795my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);6796my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);6797print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";6798}6799print<<XML;6800</outline>6801</body>6802</opml>6803XML6804}