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# 173'tgz'=> { 174'display'=>'tar.gz', 175'type'=>'application/x-gzip', 176'suffix'=>'.tar.gz', 177'format'=>'tar', 178'compressor'=> ['gzip']}, 179 180'tbz2'=> { 181'display'=>'tar.bz2', 182'type'=>'application/x-bzip2', 183'suffix'=>'.tar.bz2', 184'format'=>'tar', 185'compressor'=> ['bzip2']}, 186 187'zip'=> { 188'display'=>'zip', 189'type'=>'application/x-zip', 190'suffix'=>'.zip', 191'format'=>'zip'}, 192); 193 194# Aliases so we understand old gitweb.snapshot values in repository 195# configuration. 196our%known_snapshot_format_aliases= ( 197'gzip'=>'tgz', 198'bzip2'=>'tbz2', 199 200# backward compatibility: legacy gitweb config support 201'x-gzip'=>undef,'gz'=>undef, 202'x-bzip2'=>undef,'bz2'=>undef, 203'x-zip'=>undef,''=>undef, 204); 205 206# Pixel sizes for icons and avatars. If the default font sizes or lineheights 207# are changed, it may be appropriate to change these values too via 208# $GITWEB_CONFIG. 209our%avatar_size= ( 210'default'=>16, 211'double'=>32 212); 213 214# You define site-wide feature defaults here; override them with 215# $GITWEB_CONFIG as necessary. 216our%feature= ( 217# feature => { 218# 'sub' => feature-sub (subroutine), 219# 'override' => allow-override (boolean), 220# 'default' => [ default options...] (array reference)} 221# 222# if feature is overridable (it means that allow-override has true value), 223# then feature-sub will be called with default options as parameters; 224# return value of feature-sub indicates if to enable specified feature 225# 226# if there is no 'sub' key (no feature-sub), then feature cannot be 227# overriden 228# 229# use gitweb_get_feature(<feature>) to retrieve the <feature> value 230# (an array) or gitweb_check_feature(<feature>) to check if <feature> 231# is enabled 232 233# Enable the 'blame' blob view, showing the last commit that modified 234# each line in the file. This can be very CPU-intensive. 235 236# To enable system wide have in $GITWEB_CONFIG 237# $feature{'blame'}{'default'} = [1]; 238# To have project specific config enable override in $GITWEB_CONFIG 239# $feature{'blame'}{'override'} = 1; 240# and in project config gitweb.blame = 0|1; 241'blame'=> { 242'sub'=>sub{ feature_bool('blame',@_) }, 243'override'=>0, 244'default'=> [0]}, 245 246# Enable the 'snapshot' link, providing a compressed archive of any 247# tree. This can potentially generate high traffic if you have large 248# project. 249 250# Value is a list of formats defined in %known_snapshot_formats that 251# you wish to offer. 252# To disable system wide have in $GITWEB_CONFIG 253# $feature{'snapshot'}{'default'} = []; 254# To have project specific config enable override in $GITWEB_CONFIG 255# $feature{'snapshot'}{'override'} = 1; 256# and in project config, a comma-separated list of formats or "none" 257# to disable. Example: gitweb.snapshot = tbz2,zip; 258'snapshot'=> { 259'sub'=> \&feature_snapshot, 260'override'=>0, 261'default'=> ['tgz']}, 262 263# Enable text search, which will list the commits which match author, 264# committer or commit text to a given string. Enabled by default. 265# Project specific override is not supported. 266'search'=> { 267'override'=>0, 268'default'=> [1]}, 269 270# Enable grep search, which will list the files in currently selected 271# tree containing the given string. Enabled by default. This can be 272# potentially CPU-intensive, of course. 273 274# To enable system wide have in $GITWEB_CONFIG 275# $feature{'grep'}{'default'} = [1]; 276# To have project specific config enable override in $GITWEB_CONFIG 277# $feature{'grep'}{'override'} = 1; 278# and in project config gitweb.grep = 0|1; 279'grep'=> { 280'sub'=>sub{ feature_bool('grep',@_) }, 281'override'=>0, 282'default'=> [1]}, 283 284# Enable the pickaxe search, which will list the commits that modified 285# a given string in a file. This can be practical and quite faster 286# alternative to 'blame', but still potentially CPU-intensive. 287 288# To enable system wide have in $GITWEB_CONFIG 289# $feature{'pickaxe'}{'default'} = [1]; 290# To have project specific config enable override in $GITWEB_CONFIG 291# $feature{'pickaxe'}{'override'} = 1; 292# and in project config gitweb.pickaxe = 0|1; 293'pickaxe'=> { 294'sub'=>sub{ feature_bool('pickaxe',@_) }, 295'override'=>0, 296'default'=> [1]}, 297 298# Make gitweb use an alternative format of the URLs which can be 299# more readable and natural-looking: project name is embedded 300# directly in the path and the query string contains other 301# auxiliary information. All gitweb installations recognize 302# URL in either format; this configures in which formats gitweb 303# generates links. 304 305# To enable system wide have in $GITWEB_CONFIG 306# $feature{'pathinfo'}{'default'} = [1]; 307# Project specific override is not supported. 308 309# Note that you will need to change the default location of CSS, 310# favicon, logo and possibly other files to an absolute URL. Also, 311# if gitweb.cgi serves as your indexfile, you will need to force 312# $my_uri to contain the script name in your $GITWEB_CONFIG. 313'pathinfo'=> { 314'override'=>0, 315'default'=> [0]}, 316 317# Make gitweb consider projects in project root subdirectories 318# to be forks of existing projects. Given project $projname.git, 319# projects matching $projname/*.git will not be shown in the main 320# projects list, instead a '+' mark will be added to $projname 321# there and a 'forks' view will be enabled for the project, listing 322# all the forks. If project list is taken from a file, forks have 323# to be listed after the main project. 324 325# To enable system wide have in $GITWEB_CONFIG 326# $feature{'forks'}{'default'} = [1]; 327# Project specific override is not supported. 328'forks'=> { 329'override'=>0, 330'default'=> [0]}, 331 332# Insert custom links to the action bar of all project pages. 333# This enables you mainly to link to third-party scripts integrating 334# into gitweb; e.g. git-browser for graphical history representation 335# or custom web-based repository administration interface. 336 337# The 'default' value consists of a list of triplets in the form 338# (label, link, position) where position is the label after which 339# to insert the link and link is a format string where %n expands 340# to the project name, %f to the project path within the filesystem, 341# %h to the current hash (h gitweb parameter) and %b to the current 342# hash base (hb gitweb parameter); %% expands to %. 343 344# To enable system wide have in $GITWEB_CONFIG e.g. 345# $feature{'actions'}{'default'} = [('graphiclog', 346# '/git-browser/by-commit.html?r=%n', 'summary')]; 347# Project specific override is not supported. 348'actions'=> { 349'override'=>0, 350'default'=> []}, 351 352# Allow gitweb scan project content tags described in ctags/ 353# of project repository, and display the popular Web 2.0-ish 354# "tag cloud" near the project list. Note that this is something 355# COMPLETELY different from the normal Git tags. 356 357# gitweb by itself can show existing tags, but it does not handle 358# tagging itself; you need an external application for that. 359# For an example script, check Girocco's cgi/tagproj.cgi. 360# You may want to install the HTML::TagCloud Perl module to get 361# a pretty tag cloud instead of just a list of tags. 362 363# To enable system wide have in $GITWEB_CONFIG 364# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 365# Project specific override is not supported. 366'ctags'=> { 367'override'=>0, 368'default'=> [0]}, 369 370# The maximum number of patches in a patchset generated in patch 371# view. Set this to 0 or undef to disable patch view, or to a 372# negative number to remove any limit. 373 374# To disable system wide have in $GITWEB_CONFIG 375# $feature{'patches'}{'default'} = [0]; 376# To have project specific config enable override in $GITWEB_CONFIG 377# $feature{'patches'}{'override'} = 1; 378# and in project config gitweb.patches = 0|n; 379# where n is the maximum number of patches allowed in a patchset. 380'patches'=> { 381'sub'=> \&feature_patches, 382'override'=>0, 383'default'=> [16]}, 384 385# Avatar support. When this feature is enabled, views such as 386# shortlog or commit will display an avatar associated with 387# the email of the committer(s) and/or author(s). 388 389# Currently available providers are gravatar and picon. 390# If an unknown provider is specified, the feature is disabled. 391 392# Gravatar depends on Digest::MD5. 393# Picon currently relies on the indiana.edu database. 394 395# To enable system wide have in $GITWEB_CONFIG 396# $feature{'avatar'}{'default'} = ['<provider>']; 397# where <provider> is either gravatar or picon. 398# To have project specific config enable override in $GITWEB_CONFIG 399# $feature{'avatar'}{'override'} = 1; 400# and in project config gitweb.avatar = <provider>; 401'avatar'=> { 402'sub'=> \&feature_avatar, 403'override'=>0, 404'default'=> ['']}, 405 406# Enable displaying how much time and how many git commands 407# it took to generate and display page. Disabled by default. 408# Project specific override is not supported. 409'timed'=> { 410'override'=>0, 411'default'=> [0]}, 412); 413 414sub gitweb_get_feature { 415my($name) =@_; 416return unlessexists$feature{$name}; 417my($sub,$override,@defaults) = ( 418$feature{$name}{'sub'}, 419$feature{$name}{'override'}, 420@{$feature{$name}{'default'}}); 421if(!$override) {return@defaults; } 422if(!defined$sub) { 423warn"feature$nameis not overrideable"; 424return@defaults; 425} 426return$sub->(@defaults); 427} 428 429# A wrapper to check if a given feature is enabled. 430# With this, you can say 431# 432# my $bool_feat = gitweb_check_feature('bool_feat'); 433# gitweb_check_feature('bool_feat') or somecode; 434# 435# instead of 436# 437# my ($bool_feat) = gitweb_get_feature('bool_feat'); 438# (gitweb_get_feature('bool_feat'))[0] or somecode; 439# 440sub gitweb_check_feature { 441return(gitweb_get_feature(@_))[0]; 442} 443 444 445sub feature_bool { 446my$key=shift; 447my($val) = git_get_project_config($key,'--bool'); 448 449if(!defined$val) { 450return($_[0]); 451}elsif($valeq'true') { 452return(1); 453}elsif($valeq'false') { 454return(0); 455} 456} 457 458sub feature_snapshot { 459my(@fmts) =@_; 460 461my($val) = git_get_project_config('snapshot'); 462 463if($val) { 464@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 465} 466 467return@fmts; 468} 469 470sub feature_patches { 471my@val= (git_get_project_config('patches','--int')); 472 473if(@val) { 474return@val; 475} 476 477return($_[0]); 478} 479 480sub feature_avatar { 481my@val= (git_get_project_config('avatar')); 482 483return@val?@val:@_; 484} 485 486# checking HEAD file with -e is fragile if the repository was 487# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 488# and then pruned. 489sub check_head_link { 490my($dir) =@_; 491my$headfile="$dir/HEAD"; 492return((-e $headfile) || 493(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 494} 495 496sub check_export_ok { 497my($dir) =@_; 498return(check_head_link($dir) && 499(!$export_ok|| -e "$dir/$export_ok") && 500(!$export_auth_hook||$export_auth_hook->($dir))); 501} 502 503# process alternate names for backward compatibility 504# filter out unsupported (unknown) snapshot formats 505sub filter_snapshot_fmts { 506my@fmts=@_; 507 508@fmts=map{ 509exists$known_snapshot_format_aliases{$_} ? 510$known_snapshot_format_aliases{$_} :$_}@fmts; 511@fmts=grep{ 512exists$known_snapshot_formats{$_} }@fmts; 513} 514 515our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 516if(-e $GITWEB_CONFIG) { 517do$GITWEB_CONFIG; 518}else{ 519our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 520do$GITWEB_CONFIG_SYSTEMif-e $GITWEB_CONFIG_SYSTEM; 521} 522 523# version of the core git binary 524our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 525$number_of_git_cmds++; 526 527$projects_list||=$projectroot; 528 529# ====================================================================== 530# input validation and dispatch 531 532# input parameters can be collected from a variety of sources (presently, CGI 533# and PATH_INFO), so we define an %input_params hash that collects them all 534# together during validation: this allows subsequent uses (e.g. href()) to be 535# agnostic of the parameter origin 536 537our%input_params= (); 538 539# input parameters are stored with the long parameter name as key. This will 540# also be used in the href subroutine to convert parameters to their CGI 541# equivalent, and since the href() usage is the most frequent one, we store 542# the name -> CGI key mapping here, instead of the reverse. 543# 544# XXX: Warning: If you touch this, check the search form for updating, 545# too. 546 547our@cgi_param_mapping= ( 548 project =>"p", 549 action =>"a", 550 file_name =>"f", 551 file_parent =>"fp", 552 hash =>"h", 553 hash_parent =>"hp", 554 hash_base =>"hb", 555 hash_parent_base =>"hpb", 556 page =>"pg", 557 order =>"o", 558 searchtext =>"s", 559 searchtype =>"st", 560 snapshot_format =>"sf", 561 extra_options =>"opt", 562 search_use_regexp =>"sr", 563); 564our%cgi_param_mapping=@cgi_param_mapping; 565 566# we will also need to know the possible actions, for validation 567our%actions= ( 568"blame"=> \&git_blame, 569"blame_incremental"=> \&git_blame_incremental, 570"blame_data"=> \&git_blame_data, 571"blobdiff"=> \&git_blobdiff, 572"blobdiff_plain"=> \&git_blobdiff_plain, 573"blob"=> \&git_blob, 574"blob_plain"=> \&git_blob_plain, 575"commitdiff"=> \&git_commitdiff, 576"commitdiff_plain"=> \&git_commitdiff_plain, 577"commit"=> \&git_commit, 578"forks"=> \&git_forks, 579"heads"=> \&git_heads, 580"history"=> \&git_history, 581"log"=> \&git_log, 582"patch"=> \&git_patch, 583"patches"=> \&git_patches, 584"rss"=> \&git_rss, 585"atom"=> \&git_atom, 586"search"=> \&git_search, 587"search_help"=> \&git_search_help, 588"shortlog"=> \&git_shortlog, 589"summary"=> \&git_summary, 590"tag"=> \&git_tag, 591"tags"=> \&git_tags, 592"tree"=> \&git_tree, 593"snapshot"=> \&git_snapshot, 594"object"=> \&git_object, 595# those below don't need $project 596"opml"=> \&git_opml, 597"project_list"=> \&git_project_list, 598"project_index"=> \&git_project_index, 599); 600 601# finally, we have the hash of allowed extra_options for the commands that 602# allow them 603our%allowed_options= ( 604"--no-merges"=> [qw(rss atom log shortlog history)], 605); 606 607# fill %input_params with the CGI parameters. All values except for 'opt' 608# should be single values, but opt can be an array. We should probably 609# build an array of parameters that can be multi-valued, but since for the time 610# being it's only this one, we just single it out 611while(my($name,$symbol) =each%cgi_param_mapping) { 612if($symboleq'opt') { 613$input_params{$name} = [$cgi->param($symbol) ]; 614}else{ 615$input_params{$name} =$cgi->param($symbol); 616} 617} 618 619# now read PATH_INFO and update the parameter list for missing parameters 620sub evaluate_path_info { 621return ifdefined$input_params{'project'}; 622return if!$path_info; 623$path_info=~ s,^/+,,; 624return if!$path_info; 625 626# find which part of PATH_INFO is project 627my$project=$path_info; 628$project=~ s,/+$,,; 629while($project&& !check_head_link("$projectroot/$project")) { 630$project=~ s,/*[^/]*$,,; 631} 632return unless$project; 633$input_params{'project'} =$project; 634 635# do not change any parameters if an action is given using the query string 636return if$input_params{'action'}; 637$path_info=~ s,^\Q$project\E/*,,; 638 639# next, check if we have an action 640my$action=$path_info; 641$action=~ s,/.*$,,; 642if(exists$actions{$action}) { 643$path_info=~ s,^$action/*,,; 644$input_params{'action'} =$action; 645} 646 647# list of actions that want hash_base instead of hash, but can have no 648# pathname (f) parameter 649my@wants_base= ( 650'tree', 651'history', 652); 653 654# we want to catch 655# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 656my($parentrefname,$parentpathname,$refname,$pathname) = 657($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/); 658 659# first, analyze the 'current' part 660if(defined$pathname) { 661# we got "branch:filename" or "branch:dir/" 662# we could use git_get_type(branch:pathname), but: 663# - it needs $git_dir 664# - it does a git() call 665# - the convention of terminating directories with a slash 666# makes it superfluous 667# - embedding the action in the PATH_INFO would make it even 668# more superfluous 669$pathname=~ s,^/+,,; 670if(!$pathname||substr($pathname, -1)eq"/") { 671$input_params{'action'} ||="tree"; 672$pathname=~ s,/$,,; 673}else{ 674# the default action depends on whether we had parent info 675# or not 676if($parentrefname) { 677$input_params{'action'} ||="blobdiff_plain"; 678}else{ 679$input_params{'action'} ||="blob_plain"; 680} 681} 682$input_params{'hash_base'} ||=$refname; 683$input_params{'file_name'} ||=$pathname; 684}elsif(defined$refname) { 685# we got "branch". In this case we have to choose if we have to 686# set hash or hash_base. 687# 688# Most of the actions without a pathname only want hash to be 689# set, except for the ones specified in @wants_base that want 690# hash_base instead. It should also be noted that hand-crafted 691# links having 'history' as an action and no pathname or hash 692# set will fail, but that happens regardless of PATH_INFO. 693$input_params{'action'} ||="shortlog"; 694if(grep{$_eq$input_params{'action'} }@wants_base) { 695$input_params{'hash_base'} ||=$refname; 696}else{ 697$input_params{'hash'} ||=$refname; 698} 699} 700 701# next, handle the 'parent' part, if present 702if(defined$parentrefname) { 703# a missing pathspec defaults to the 'current' filename, allowing e.g. 704# someproject/blobdiff/oldrev..newrev:/filename 705if($parentpathname) { 706$parentpathname=~ s,^/+,,; 707$parentpathname=~ s,/$,,; 708$input_params{'file_parent'} ||=$parentpathname; 709}else{ 710$input_params{'file_parent'} ||=$input_params{'file_name'}; 711} 712# we assume that hash_parent_base is wanted if a path was specified, 713# or if the action wants hash_base instead of hash 714if(defined$input_params{'file_parent'} || 715grep{$_eq$input_params{'action'} }@wants_base) { 716$input_params{'hash_parent_base'} ||=$parentrefname; 717}else{ 718$input_params{'hash_parent'} ||=$parentrefname; 719} 720} 721 722# for the snapshot action, we allow URLs in the form 723# $project/snapshot/$hash.ext 724# where .ext determines the snapshot and gets removed from the 725# passed $refname to provide the $hash. 726# 727# To be able to tell that $refname includes the format extension, we 728# require the following two conditions to be satisfied: 729# - the hash input parameter MUST have been set from the $refname part 730# of the URL (i.e. they must be equal) 731# - the snapshot format MUST NOT have been defined already (e.g. from 732# CGI parameter sf) 733# It's also useless to try any matching unless $refname has a dot, 734# so we check for that too 735if(defined$input_params{'action'} && 736$input_params{'action'}eq'snapshot'&& 737defined$refname&&index($refname,'.') != -1&& 738$refnameeq$input_params{'hash'} && 739!defined$input_params{'snapshot_format'}) { 740# We loop over the known snapshot formats, checking for 741# extensions. Allowed extensions are both the defined suffix 742# (which includes the initial dot already) and the snapshot 743# format key itself, with a prepended dot 744while(my($fmt,$opt) =each%known_snapshot_formats) { 745my$hash=$refname; 746unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 747next; 748} 749my$sfx=$1; 750# a valid suffix was found, so set the snapshot format 751# and reset the hash parameter 752$input_params{'snapshot_format'} =$fmt; 753$input_params{'hash'} =$hash; 754# we also set the format suffix to the one requested 755# in the URL: this way a request for e.g. .tgz returns 756# a .tgz instead of a .tar.gz 757$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 758last; 759} 760} 761} 762evaluate_path_info(); 763 764our$action=$input_params{'action'}; 765if(defined$action) { 766if(!validate_action($action)) { 767 die_error(400,"Invalid action parameter"); 768} 769} 770 771# parameters which are pathnames 772our$project=$input_params{'project'}; 773if(defined$project) { 774if(!validate_project($project)) { 775undef$project; 776 die_error(404,"No such project"); 777} 778} 779 780our$file_name=$input_params{'file_name'}; 781if(defined$file_name) { 782if(!validate_pathname($file_name)) { 783 die_error(400,"Invalid file parameter"); 784} 785} 786 787our$file_parent=$input_params{'file_parent'}; 788if(defined$file_parent) { 789if(!validate_pathname($file_parent)) { 790 die_error(400,"Invalid file parent parameter"); 791} 792} 793 794# parameters which are refnames 795our$hash=$input_params{'hash'}; 796if(defined$hash) { 797if(!validate_refname($hash)) { 798 die_error(400,"Invalid hash parameter"); 799} 800} 801 802our$hash_parent=$input_params{'hash_parent'}; 803if(defined$hash_parent) { 804if(!validate_refname($hash_parent)) { 805 die_error(400,"Invalid hash parent parameter"); 806} 807} 808 809our$hash_base=$input_params{'hash_base'}; 810if(defined$hash_base) { 811if(!validate_refname($hash_base)) { 812 die_error(400,"Invalid hash base parameter"); 813} 814} 815 816our@extra_options= @{$input_params{'extra_options'}}; 817# @extra_options is always defined, since it can only be (currently) set from 818# CGI, and $cgi->param() returns the empty array in array context if the param 819# is not set 820foreachmy$opt(@extra_options) { 821if(not exists$allowed_options{$opt}) { 822 die_error(400,"Invalid option parameter"); 823} 824if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 825 die_error(400,"Invalid option parameter for this action"); 826} 827} 828 829our$hash_parent_base=$input_params{'hash_parent_base'}; 830if(defined$hash_parent_base) { 831if(!validate_refname($hash_parent_base)) { 832 die_error(400,"Invalid hash parent base parameter"); 833} 834} 835 836# other parameters 837our$page=$input_params{'page'}; 838if(defined$page) { 839if($page=~m/[^0-9]/) { 840 die_error(400,"Invalid page parameter"); 841} 842} 843 844our$searchtype=$input_params{'searchtype'}; 845if(defined$searchtype) { 846if($searchtype=~m/[^a-z]/) { 847 die_error(400,"Invalid searchtype parameter"); 848} 849} 850 851our$search_use_regexp=$input_params{'search_use_regexp'}; 852 853our$searchtext=$input_params{'searchtext'}; 854our$search_regexp; 855if(defined$searchtext) { 856if(length($searchtext) <2) { 857 die_error(403,"At least two characters are required for search parameter"); 858} 859$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 860} 861 862# path to the current git repository 863our$git_dir; 864$git_dir="$projectroot/$project"if$project; 865 866# list of supported snapshot formats 867our@snapshot_fmts= gitweb_get_feature('snapshot'); 868@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts); 869 870# check that the avatar feature is set to a known provider name, 871# and for each provider check if the dependencies are satisfied. 872# if the provider name is invalid or the dependencies are not met, 873# reset $git_avatar to the empty string. 874our($git_avatar) = gitweb_get_feature('avatar'); 875if($git_avatareq'gravatar') { 876$git_avatar=''unless(eval{require Digest::MD5;1; }); 877}elsif($git_avatareq'picon') { 878# no dependencies 879}else{ 880$git_avatar=''; 881} 882 883# dispatch 884if(!defined$action) { 885if(defined$hash) { 886$action= git_get_type($hash); 887}elsif(defined$hash_base&&defined$file_name) { 888$action= git_get_type("$hash_base:$file_name"); 889}elsif(defined$project) { 890$action='summary'; 891}else{ 892$action='project_list'; 893} 894} 895if(!defined($actions{$action})) { 896 die_error(400,"Unknown action"); 897} 898if($action!~m/^(?:opml|project_list|project_index)$/&& 899!$project) { 900 die_error(400,"Project needed"); 901} 902$actions{$action}->(); 903exit; 904 905## ====================================================================== 906## action links 907 908sub href { 909my%params=@_; 910# default is to use -absolute url() i.e. $my_uri 911my$href=$params{-full} ?$my_url:$my_uri; 912 913$params{'project'} =$projectunlessexists$params{'project'}; 914 915if($params{-replay}) { 916while(my($name,$symbol) =each%cgi_param_mapping) { 917if(!exists$params{$name}) { 918$params{$name} =$input_params{$name}; 919} 920} 921} 922 923my$use_pathinfo= gitweb_check_feature('pathinfo'); 924if($use_pathinfoand defined$params{'project'}) { 925# try to put as many parameters as possible in PATH_INFO: 926# - project name 927# - action 928# - hash_parent or hash_parent_base:/file_parent 929# - hash or hash_base:/filename 930# - the snapshot_format as an appropriate suffix 931 932# When the script is the root DirectoryIndex for the domain, 933# $href here would be something like http://gitweb.example.com/ 934# Thus, we strip any trailing / from $href, to spare us double 935# slashes in the final URL 936$href=~ s,/$,,; 937 938# Then add the project name, if present 939$href.="/".esc_url($params{'project'}); 940delete$params{'project'}; 941 942# since we destructively absorb parameters, we keep this 943# boolean that remembers if we're handling a snapshot 944my$is_snapshot=$params{'action'}eq'snapshot'; 945 946# Summary just uses the project path URL, any other action is 947# added to the URL 948if(defined$params{'action'}) { 949$href.="/".esc_url($params{'action'})unless$params{'action'}eq'summary'; 950delete$params{'action'}; 951} 952 953# Next, we put hash_parent_base:/file_parent..hash_base:/file_name, 954# stripping nonexistent or useless pieces 955$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'} 956||$params{'hash_parent'} ||$params{'hash'}); 957if(defined$params{'hash_base'}) { 958if(defined$params{'hash_parent_base'}) { 959$href.= esc_url($params{'hash_parent_base'}); 960# skip the file_parent if it's the same as the file_name 961delete$params{'file_parent'}if$params{'file_parent'}eq$params{'file_name'}; 962if(defined$params{'file_parent'} &&$params{'file_parent'} !~/\.\./) { 963$href.=":/".esc_url($params{'file_parent'}); 964delete$params{'file_parent'}; 965} 966$href.=".."; 967delete$params{'hash_parent'}; 968delete$params{'hash_parent_base'}; 969}elsif(defined$params{'hash_parent'}) { 970$href.= esc_url($params{'hash_parent'}).".."; 971delete$params{'hash_parent'}; 972} 973 974$href.= esc_url($params{'hash_base'}); 975if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) { 976$href.=":/".esc_url($params{'file_name'}); 977delete$params{'file_name'}; 978} 979delete$params{'hash'}; 980delete$params{'hash_base'}; 981}elsif(defined$params{'hash'}) { 982$href.= esc_url($params{'hash'}); 983delete$params{'hash'}; 984} 985 986# If the action was a snapshot, we can absorb the 987# snapshot_format parameter too 988if($is_snapshot) { 989my$fmt=$params{'snapshot_format'}; 990# snapshot_format should always be defined when href() 991# is called, but just in case some code forgets, we 992# fall back to the default 993$fmt||=$snapshot_fmts[0]; 994$href.=$known_snapshot_formats{$fmt}{'suffix'}; 995delete$params{'snapshot_format'}; 996} 997} 998 999# now encode the parameters explicitly1000my@result= ();1001for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1002my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1003if(defined$params{$name}) {1004if(ref($params{$name})eq"ARRAY") {1005foreachmy$par(@{$params{$name}}) {1006push@result,$symbol."=". esc_param($par);1007}1008}else{1009push@result,$symbol."=". esc_param($params{$name});1010}1011}1012}1013$href.="?".join(';',@result)ifscalar@result;10141015return$href;1016}101710181019## ======================================================================1020## validation, quoting/unquoting and escaping10211022sub validate_action {1023my$input=shift||returnundef;1024returnundefunlessexists$actions{$input};1025return$input;1026}10271028sub validate_project {1029my$input=shift||returnundef;1030if(!validate_pathname($input) ||1031!(-d "$projectroot/$input") ||1032!check_export_ok("$projectroot/$input") ||1033($strict_export&& !project_in_list($input))) {1034returnundef;1035}else{1036return$input;1037}1038}10391040sub validate_pathname {1041my$input=shift||returnundef;10421043# no '.' or '..' as elements of path, i.e. no '.' nor '..'1044# at the beginning, at the end, and between slashes.1045# also this catches doubled slashes1046if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1047returnundef;1048}1049# no null characters1050if($input=~m!\0!) {1051returnundef;1052}1053return$input;1054}10551056sub validate_refname {1057my$input=shift||returnundef;10581059# textual hashes are O.K.1060if($input=~m/^[0-9a-fA-F]{40}$/) {1061return$input;1062}1063# it must be correct pathname1064$input= validate_pathname($input)1065orreturnundef;1066# restrictions on ref name according to git-check-ref-format1067if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1068returnundef;1069}1070return$input;1071}10721073# decode sequences of octets in utf8 into Perl's internal form,1074# which is utf-8 with utf8 flag set if needed. gitweb writes out1075# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1076sub to_utf8 {1077my$str=shift;1078if(utf8::valid($str)) {1079 utf8::decode($str);1080return$str;1081}else{1082return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1083}1084}10851086# quote unsafe chars, but keep the slash, even when it's not1087# correct, but quoted slashes look too horrible in bookmarks1088sub esc_param {1089my$str=shift;1090$str=~s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X",ord($1))/eg;1091$str=~s/\+/%2B/g;1092$str=~s/ /\+/g;1093return$str;1094}10951096# quote unsafe chars in whole URL, so some charactrs cannot be quoted1097sub esc_url {1098my$str=shift;1099$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X",ord($1))/eg;1100$str=~s/\+/%2B/g;1101$str=~s/ /\+/g;1102return$str;1103}11041105# replace invalid utf8 character with SUBSTITUTION sequence1106sub esc_html {1107my$str=shift;1108my%opts=@_;11091110$str= to_utf8($str);1111$str=$cgi->escapeHTML($str);1112if($opts{'-nbsp'}) {1113$str=~s/ / /g;1114}1115$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1116return$str;1117}11181119# quote control characters and escape filename to HTML1120sub esc_path {1121my$str=shift;1122my%opts=@_;11231124$str= to_utf8($str);1125$str=$cgi->escapeHTML($str);1126if($opts{'-nbsp'}) {1127$str=~s/ / /g;1128}1129$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1130return$str;1131}11321133# Make control characters "printable", using character escape codes (CEC)1134sub quot_cec {1135my$cntrl=shift;1136my%opts=@_;1137my%es= (# character escape codes, aka escape sequences1138"\t"=>'\t',# tab (HT)1139"\n"=>'\n',# line feed (LF)1140"\r"=>'\r',# carrige return (CR)1141"\f"=>'\f',# form feed (FF)1142"\b"=>'\b',# backspace (BS)1143"\a"=>'\a',# alarm (bell) (BEL)1144"\e"=>'\e',# escape (ESC)1145"\013"=>'\v',# vertical tab (VT)1146"\000"=>'\0',# nul character (NUL)1147);1148my$chr= ( (exists$es{$cntrl})1149?$es{$cntrl}1150:sprintf('\%2x',ord($cntrl)) );1151if($opts{-nohtml}) {1152return$chr;1153}else{1154return"<span class=\"cntrl\">$chr</span>";1155}1156}11571158# Alternatively use unicode control pictures codepoints,1159# Unicode "printable representation" (PR)1160sub quot_upr {1161my$cntrl=shift;1162my%opts=@_;11631164my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1165if($opts{-nohtml}) {1166return$chr;1167}else{1168return"<span class=\"cntrl\">$chr</span>";1169}1170}11711172# git may return quoted and escaped filenames1173sub unquote {1174my$str=shift;11751176sub unq {1177my$seq=shift;1178my%es= (# character escape codes, aka escape sequences1179't'=>"\t",# tab (HT, TAB)1180'n'=>"\n",# newline (NL)1181'r'=>"\r",# return (CR)1182'f'=>"\f",# form feed (FF)1183'b'=>"\b",# backspace (BS)1184'a'=>"\a",# alarm (bell) (BEL)1185'e'=>"\e",# escape (ESC)1186'v'=>"\013",# vertical tab (VT)1187);11881189if($seq=~m/^[0-7]{1,3}$/) {1190# octal char sequence1191returnchr(oct($seq));1192}elsif(exists$es{$seq}) {1193# C escape sequence, aka character escape code1194return$es{$seq};1195}1196# quoted ordinary character1197return$seq;1198}11991200if($str=~m/^"(.*)"$/) {1201# needs unquoting1202$str=$1;1203$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1204}1205return$str;1206}12071208# escape tabs (convert tabs to spaces)1209sub untabify {1210my$line=shift;12111212while((my$pos=index($line,"\t")) != -1) {1213if(my$count= (8- ($pos%8))) {1214my$spaces=' ' x $count;1215$line=~s/\t/$spaces/;1216}1217}12181219return$line;1220}12211222sub project_in_list {1223my$project=shift;1224my@list= git_get_projects_list();1225return@list&&scalar(grep{$_->{'path'}eq$project}@list);1226}12271228## ----------------------------------------------------------------------1229## HTML aware string manipulation12301231# Try to chop given string on a word boundary between position1232# $len and $len+$add_len. If there is no word boundary there,1233# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1234# (marking chopped part) would be longer than given string.1235sub chop_str {1236my$str=shift;1237my$len=shift;1238my$add_len=shift||10;1239my$where=shift||'right';# 'left' | 'center' | 'right'12401241# Make sure perl knows it is utf8 encoded so we don't1242# cut in the middle of a utf8 multibyte char.1243$str= to_utf8($str);12441245# allow only $len chars, but don't cut a word if it would fit in $add_len1246# if it doesn't fit, cut it if it's still longer than the dots we would add1247# remove chopped character entities entirely12481249# when chopping in the middle, distribute $len into left and right part1250# return early if chopping wouldn't make string shorter1251if($whereeq'center') {1252return$strif($len+5>=length($str));# filler is length 51253$len=int($len/2);1254}else{1255return$strif($len+4>=length($str));# filler is length 41256}12571258# regexps: ending and beginning with word part up to $add_len1259my$endre=qr/.{$len}\w{0,$add_len}/;1260my$begre=qr/\w{0,$add_len}.{$len}/;12611262if($whereeq'left') {1263$str=~m/^(.*?)($begre)$/;1264my($lead,$body) = ($1,$2);1265if(length($lead) >4) {1266$body=~s/^[^;]*;//if($lead=~m/&[^;]*$/);1267$lead=" ...";1268}1269return"$lead$body";12701271}elsif($whereeq'center') {1272$str=~m/^($endre)(.*)$/;1273my($left,$str) = ($1,$2);1274$str=~m/^(.*?)($begre)$/;1275my($mid,$right) = ($1,$2);1276if(length($mid) >5) {1277$left=~s/&[^;]*$//;1278$right=~s/^[^;]*;//if($mid=~m/&[^;]*$/);1279$mid=" ... ";1280}1281return"$left$mid$right";12821283}else{1284$str=~m/^($endre)(.*)$/;1285my$body=$1;1286my$tail=$2;1287if(length($tail) >4) {1288$body=~s/&[^;]*$//;1289$tail="... ";1290}1291return"$body$tail";1292}1293}12941295# takes the same arguments as chop_str, but also wraps a <span> around the1296# result with a title attribute if it does get chopped. Additionally, the1297# string is HTML-escaped.1298sub chop_and_escape_str {1299my($str) =@_;13001301my$chopped= chop_str(@_);1302if($choppedeq$str) {1303return esc_html($chopped);1304}else{1305$str=~s/[[:cntrl:]]/?/g;1306return$cgi->span({-title=>$str}, esc_html($chopped));1307}1308}13091310## ----------------------------------------------------------------------1311## functions returning short strings13121313# CSS class for given age value (in seconds)1314sub age_class {1315my$age=shift;13161317if(!defined$age) {1318return"noage";1319}elsif($age<60*60*2) {1320return"age0";1321}elsif($age<60*60*24*2) {1322return"age1";1323}else{1324return"age2";1325}1326}13271328# convert age in seconds to "nn units ago" string1329sub age_string {1330my$age=shift;1331my$age_str;13321333if($age>60*60*24*365*2) {1334$age_str= (int$age/60/60/24/365);1335$age_str.=" years ago";1336}elsif($age>60*60*24*(365/12)*2) {1337$age_str=int$age/60/60/24/(365/12);1338$age_str.=" months ago";1339}elsif($age>60*60*24*7*2) {1340$age_str=int$age/60/60/24/7;1341$age_str.=" weeks ago";1342}elsif($age>60*60*24*2) {1343$age_str=int$age/60/60/24;1344$age_str.=" days ago";1345}elsif($age>60*60*2) {1346$age_str=int$age/60/60;1347$age_str.=" hours ago";1348}elsif($age>60*2) {1349$age_str=int$age/60;1350$age_str.=" min ago";1351}elsif($age>2) {1352$age_str=int$age;1353$age_str.=" sec ago";1354}else{1355$age_str.=" right now";1356}1357return$age_str;1358}13591360useconstant{1361 S_IFINVALID =>0030000,1362 S_IFGITLINK =>0160000,1363};13641365# submodule/subproject, a commit object reference1366sub S_ISGITLINK {1367my$mode=shift;13681369return(($mode& S_IFMT) == S_IFGITLINK)1370}13711372# convert file mode in octal to symbolic file mode string1373sub mode_str {1374my$mode=oct shift;13751376if(S_ISGITLINK($mode)) {1377return'm---------';1378}elsif(S_ISDIR($mode& S_IFMT)) {1379return'drwxr-xr-x';1380}elsif(S_ISLNK($mode)) {1381return'lrwxrwxrwx';1382}elsif(S_ISREG($mode)) {1383# git cares only about the executable bit1384if($mode& S_IXUSR) {1385return'-rwxr-xr-x';1386}else{1387return'-rw-r--r--';1388};1389}else{1390return'----------';1391}1392}13931394# convert file mode in octal to file type string1395sub file_type {1396my$mode=shift;13971398if($mode!~m/^[0-7]+$/) {1399return$mode;1400}else{1401$mode=oct$mode;1402}14031404if(S_ISGITLINK($mode)) {1405return"submodule";1406}elsif(S_ISDIR($mode& S_IFMT)) {1407return"directory";1408}elsif(S_ISLNK($mode)) {1409return"symlink";1410}elsif(S_ISREG($mode)) {1411return"file";1412}else{1413return"unknown";1414}1415}14161417# convert file mode in octal to file type description string1418sub file_type_long {1419my$mode=shift;14201421if($mode!~m/^[0-7]+$/) {1422return$mode;1423}else{1424$mode=oct$mode;1425}14261427if(S_ISGITLINK($mode)) {1428return"submodule";1429}elsif(S_ISDIR($mode& S_IFMT)) {1430return"directory";1431}elsif(S_ISLNK($mode)) {1432return"symlink";1433}elsif(S_ISREG($mode)) {1434if($mode& S_IXUSR) {1435return"executable";1436}else{1437return"file";1438};1439}else{1440return"unknown";1441}1442}144314441445## ----------------------------------------------------------------------1446## functions returning short HTML fragments, or transforming HTML fragments1447## which don't belong to other sections14481449# format line of commit message.1450sub format_log_line_html {1451my$line=shift;14521453$line= esc_html($line, -nbsp=>1);1454$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1455$cgi->a({-href => href(action=>"object", hash=>$1),1456-class=>"text"},$1);1457}eg;14581459return$line;1460}14611462# format marker of refs pointing to given object14631464# the destination action is chosen based on object type and current context:1465# - for annotated tags, we choose the tag view unless it's the current view1466# already, in which case we go to shortlog view1467# - for other refs, we keep the current view if we're in history, shortlog or1468# log view, and select shortlog otherwise1469sub format_ref_marker {1470my($refs,$id) =@_;1471my$markers='';14721473if(defined$refs->{$id}) {1474foreachmy$ref(@{$refs->{$id}}) {1475# this code exploits the fact that non-lightweight tags are the1476# only indirect objects, and that they are the only objects for which1477# we want to use tag instead of shortlog as action1478my($type,$name) =qw();1479my$indirect= ($ref=~s/\^\{\}$//);1480# e.g. tags/v2.6.11 or heads/next1481if($ref=~m!^(.*?)s?/(.*)$!) {1482$type=$1;1483$name=$2;1484}else{1485$type="ref";1486$name=$ref;1487}14881489my$class=$type;1490$class.=" indirect"if$indirect;14911492my$dest_action="shortlog";14931494if($indirect) {1495$dest_action="tag"unless$actioneq"tag";1496}elsif($action=~/^(history|(short)?log)$/) {1497$dest_action=$action;1498}14991500my$dest="";1501$dest.="refs/"unless$ref=~ m!^refs/!;1502$dest.=$ref;15031504my$link=$cgi->a({1505-href => href(1506 action=>$dest_action,1507 hash=>$dest1508)},$name);15091510$markers.=" <span class=\"$class\"title=\"$ref\">".1511$link."</span>";1512}1513}15141515if($markers) {1516return' <span class="refs">'.$markers.'</span>';1517}else{1518return"";1519}1520}15211522# format, perhaps shortened and with markers, title line1523sub format_subject_html {1524my($long,$short,$href,$extra) =@_;1525$extra=''unlessdefined($extra);15261527if(length($short) <length($long)) {1528$long=~s/[[:cntrl:]]/?/g;1529return$cgi->a({-href =>$href, -class=>"list subject",1530-title => to_utf8($long)},1531 esc_html($short) .$extra);1532}else{1533return$cgi->a({-href =>$href, -class=>"list subject"},1534 esc_html($long) .$extra);1535}1536}15371538# Rather than recomputing the url for an email multiple times, we cache it1539# after the first hit. This gives a visible benefit in views where the avatar1540# for the same email is used repeatedly (e.g. shortlog).1541# The cache is shared by all avatar engines (currently gravatar only), which1542# are free to use it as preferred. Since only one avatar engine is used for any1543# given page, there's no risk for cache conflicts.1544our%avatar_cache= ();15451546# Compute the picon url for a given email, by using the picon search service over at1547# http://www.cs.indiana.edu/picons/search.html1548sub picon_url {1549my$email=lc shift;1550if(!$avatar_cache{$email}) {1551my($user,$domain) =split('@',$email);1552$avatar_cache{$email} =1553"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".1554"$domain/$user/".1555"users+domains+unknown/up/single";1556}1557return$avatar_cache{$email};1558}15591560# Compute the gravatar url for a given email, if it's not in the cache already.1561# Gravatar stores only the part of the URL before the size, since that's the1562# one computationally more expensive. This also allows reuse of the cache for1563# different sizes (for this particular engine).1564sub gravatar_url {1565my$email=lc shift;1566my$size=shift;1567$avatar_cache{$email} ||=1568"http://www.gravatar.com/avatar/".1569 Digest::MD5::md5_hex($email) ."?s=";1570return$avatar_cache{$email} .$size;1571}15721573# Insert an avatar for the given $email at the given $size if the feature1574# is enabled.1575sub git_get_avatar {1576my($email,%opts) =@_;1577my$pre_white= ($opts{-pad_before} ?" ":"");1578my$post_white= ($opts{-pad_after} ?" ":"");1579$opts{-size} ||='default';1580my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};1581my$url="";1582if($git_avatareq'gravatar') {1583$url= gravatar_url($email,$size);1584}elsif($git_avatareq'picon') {1585$url= picon_url($email);1586}1587# Other providers can be added by extending the if chain, defining $url1588# as needed. If no variant puts something in $url, we assume avatars1589# are completely disabled/unavailable.1590if($url) {1591return$pre_white.1592"<img width=\"$size\"".1593"class=\"avatar\"".1594"src=\"$url\"".1595"alt=\"\"".1596"/>".$post_white;1597}else{1598return"";1599}1600}16011602# format the author name of the given commit with the given tag1603# the author name is chopped and escaped according to the other1604# optional parameters (see chop_str).1605sub format_author_html {1606my$tag=shift;1607my$co=shift;1608my$author= chop_and_escape_str($co->{'author_name'},@_);1609return"<$tagclass=\"author\">".1610 git_get_avatar($co->{'author_email'}, -pad_after =>1) .1611$author."</$tag>";1612}16131614# format git diff header line, i.e. "diff --(git|combined|cc) ..."1615sub format_git_diff_header_line {1616my$line=shift;1617my$diffinfo=shift;1618my($from,$to) =@_;16191620if($diffinfo->{'nparents'}) {1621# combined diff1622$line=~s!^(diff (.*?) )"?.*$!$1!;1623if($to->{'href'}) {1624$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1625 esc_path($to->{'file'}));1626}else{# file was deleted (no href)1627$line.= esc_path($to->{'file'});1628}1629}else{1630# "ordinary" diff1631$line=~s!^(diff (.*?) )"?a/.*$!$1!;1632if($from->{'href'}) {1633$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1634'a/'. esc_path($from->{'file'}));1635}else{# file was added (no href)1636$line.='a/'. esc_path($from->{'file'});1637}1638$line.=' ';1639if($to->{'href'}) {1640$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1641'b/'. esc_path($to->{'file'}));1642}else{# file was deleted1643$line.='b/'. esc_path($to->{'file'});1644}1645}16461647return"<div class=\"diff header\">$line</div>\n";1648}16491650# format extended diff header line, before patch itself1651sub format_extended_diff_header_line {1652my$line=shift;1653my$diffinfo=shift;1654my($from,$to) =@_;16551656# match <path>1657if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1658$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1659 esc_path($from->{'file'}));1660}1661if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1662$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1663 esc_path($to->{'file'}));1664}1665# match single <mode>1666if($line=~m/\s(\d{6})$/) {1667$line.='<span class="info"> ('.1668 file_type_long($1) .1669')</span>';1670}1671# match <hash>1672if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1673# can match only for combined diff1674$line='index ';1675for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1676if($from->{'href'}[$i]) {1677$line.=$cgi->a({-href=>$from->{'href'}[$i],1678-class=>"hash"},1679substr($diffinfo->{'from_id'}[$i],0,7));1680}else{1681$line.='0' x 7;1682}1683# separator1684$line.=','if($i<$diffinfo->{'nparents'} -1);1685}1686$line.='..';1687if($to->{'href'}) {1688$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1689substr($diffinfo->{'to_id'},0,7));1690}else{1691$line.='0' x 7;1692}16931694}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1695# can match only for ordinary diff1696my($from_link,$to_link);1697if($from->{'href'}) {1698$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1699substr($diffinfo->{'from_id'},0,7));1700}else{1701$from_link='0' x 7;1702}1703if($to->{'href'}) {1704$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1705substr($diffinfo->{'to_id'},0,7));1706}else{1707$to_link='0' x 7;1708}1709my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1710$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1711}17121713return$line."<br/>\n";1714}17151716# format from-file/to-file diff header1717sub format_diff_from_to_header {1718my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1719my$line;1720my$result='';17211722$line=$from_line;1723#assert($line =~ m/^---/) if DEBUG;1724# no extra formatting for "^--- /dev/null"1725if(!$diffinfo->{'nparents'}) {1726# ordinary (single parent) diff1727if($line=~m!^--- "?a/!) {1728if($from->{'href'}) {1729$line='--- a/'.1730$cgi->a({-href=>$from->{'href'}, -class=>"path"},1731 esc_path($from->{'file'}));1732}else{1733$line='--- a/'.1734 esc_path($from->{'file'});1735}1736}1737$result.= qq!<div class="diff from_file">$line</div>\n!;17381739}else{1740# combined diff (merge commit)1741for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1742if($from->{'href'}[$i]) {1743$line='--- '.1744$cgi->a({-href=>href(action=>"blobdiff",1745 hash_parent=>$diffinfo->{'from_id'}[$i],1746 hash_parent_base=>$parents[$i],1747 file_parent=>$from->{'file'}[$i],1748 hash=>$diffinfo->{'to_id'},1749 hash_base=>$hash,1750 file_name=>$to->{'file'}),1751-class=>"path",1752-title=>"diff". ($i+1)},1753$i+1) .1754'/'.1755$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1756 esc_path($from->{'file'}[$i]));1757}else{1758$line='--- /dev/null';1759}1760$result.= qq!<div class="diff from_file">$line</div>\n!;1761}1762}17631764$line=$to_line;1765#assert($line =~ m/^\+\+\+/) if DEBUG;1766# no extra formatting for "^+++ /dev/null"1767if($line=~m!^\+\+\+ "?b/!) {1768if($to->{'href'}) {1769$line='+++ b/'.1770$cgi->a({-href=>$to->{'href'}, -class=>"path"},1771 esc_path($to->{'file'}));1772}else{1773$line='+++ b/'.1774 esc_path($to->{'file'});1775}1776}1777$result.= qq!<div class="diff to_file">$line</div>\n!;17781779return$result;1780}17811782# create note for patch simplified by combined diff1783sub format_diff_cc_simplified {1784my($diffinfo,@parents) =@_;1785my$result='';17861787$result.="<div class=\"diff header\">".1788"diff --cc ";1789if(!is_deleted($diffinfo)) {1790$result.=$cgi->a({-href => href(action=>"blob",1791 hash_base=>$hash,1792 hash=>$diffinfo->{'to_id'},1793 file_name=>$diffinfo->{'to_file'}),1794-class=>"path"},1795 esc_path($diffinfo->{'to_file'}));1796}else{1797$result.= esc_path($diffinfo->{'to_file'});1798}1799$result.="</div>\n".# class="diff header"1800"<div class=\"diff nodifferences\">".1801"Simple merge".1802"</div>\n";# class="diff nodifferences"18031804return$result;1805}18061807# format patch (diff) line (not to be used for diff headers)1808sub format_diff_line {1809my$line=shift;1810my($from,$to) =@_;1811my$diff_class="";18121813chomp$line;18141815if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1816# combined diff1817my$prefix=substr($line,0,scalar@{$from->{'href'}});1818if($line=~m/^\@{3}/) {1819$diff_class=" chunk_header";1820}elsif($line=~m/^\\/) {1821$diff_class=" incomplete";1822}elsif($prefix=~tr/+/+/) {1823$diff_class=" add";1824}elsif($prefix=~tr/-/-/) {1825$diff_class=" rem";1826}1827}else{1828# assume ordinary diff1829my$char=substr($line,0,1);1830if($chareq'+') {1831$diff_class=" add";1832}elsif($chareq'-') {1833$diff_class=" rem";1834}elsif($chareq'@') {1835$diff_class=" chunk_header";1836}elsif($chareq"\\") {1837$diff_class=" incomplete";1838}1839}1840$line= untabify($line);1841if($from&&$to&&$line=~m/^\@{2} /) {1842my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1843$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;18441845$from_lines=0unlessdefined$from_lines;1846$to_lines=0unlessdefined$to_lines;18471848if($from->{'href'}) {1849$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1850-class=>"list"},$from_text);1851}1852if($to->{'href'}) {1853$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1854-class=>"list"},$to_text);1855}1856$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1857"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1858return"<div class=\"diff$diff_class\">$line</div>\n";1859}elsif($from&&$to&&$line=~m/^\@{3}/) {1860my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1861my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);18621863@from_text=split(' ',$ranges);1864for(my$i=0;$i<@from_text; ++$i) {1865($from_start[$i],$from_nlines[$i]) =1866(split(',',substr($from_text[$i],1)),0);1867}18681869$to_text=pop@from_text;1870$to_start=pop@from_start;1871$to_nlines=pop@from_nlines;18721873$line="<span class=\"chunk_info\">$prefix";1874for(my$i=0;$i<@from_text; ++$i) {1875if($from->{'href'}[$i]) {1876$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1877-class=>"list"},$from_text[$i]);1878}else{1879$line.=$from_text[$i];1880}1881$line.=" ";1882}1883if($to->{'href'}) {1884$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1885-class=>"list"},$to_text);1886}else{1887$line.=$to_text;1888}1889$line.="$prefix</span>".1890"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1891return"<div class=\"diff$diff_class\">$line</div>\n";1892}1893return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1894}18951896# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1897# linked. Pass the hash of the tree/commit to snapshot.1898sub format_snapshot_links {1899my($hash) =@_;1900my$num_fmts=@snapshot_fmts;1901if($num_fmts>1) {1902# A parenthesized list of links bearing format names.1903# e.g. "snapshot (_tar.gz_ _zip_)"1904return"snapshot (".join(' ',map1905$cgi->a({1906-href => href(1907 action=>"snapshot",1908 hash=>$hash,1909 snapshot_format=>$_1910)1911},$known_snapshot_formats{$_}{'display'})1912,@snapshot_fmts) .")";1913}elsif($num_fmts==1) {1914# A single "snapshot" link whose tooltip bears the format name.1915# i.e. "_snapshot_"1916my($fmt) =@snapshot_fmts;1917return1918$cgi->a({1919-href => href(1920 action=>"snapshot",1921 hash=>$hash,1922 snapshot_format=>$fmt1923),1924-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"1925},"snapshot");1926}else{# $num_fmts == 01927returnundef;1928}1929}19301931## ......................................................................1932## functions returning values to be passed, perhaps after some1933## transformation, to other functions; e.g. returning arguments to href()19341935# returns hash to be passed to href to generate gitweb URL1936# in -title key it returns description of link1937sub get_feed_info {1938my$format=shift||'Atom';1939my%res= (action =>lc($format));19401941# feed links are possible only for project views1942return unless(defined$project);1943# some views should link to OPML, or to generic project feed,1944# or don't have specific feed yet (so they should use generic)1945return if($action=~/^(?:tags|heads|forks|tag|search)$/x);19461947my$branch;1948# branches refs uses 'refs/heads/' prefix (fullname) to differentiate1949# from tag links; this also makes possible to detect branch links1950if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||1951(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {1952$branch=$1;1953}1954# find log type for feed description (title)1955my$type='log';1956if(defined$file_name) {1957$type="history of$file_name";1958$type.="/"if($actioneq'tree');1959$type.=" on '$branch'"if(defined$branch);1960}else{1961$type="log of$branch"if(defined$branch);1962}19631964$res{-title} =$type;1965$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);1966$res{'file_name'} =$file_name;19671968return%res;1969}19701971## ----------------------------------------------------------------------1972## git utility subroutines, invoking git commands19731974# returns path to the core git executable and the --git-dir parameter as list1975sub git_cmd {1976$number_of_git_cmds++;1977return$GIT,'--git-dir='.$git_dir;1978}19791980# quote the given arguments for passing them to the shell1981# quote_command("command", "arg 1", "arg with ' and ! characters")1982# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"1983# Try to avoid using this function wherever possible.1984sub quote_command {1985returnjoin(' ',1986map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);1987}19881989# get HEAD ref of given project as hash1990sub git_get_head_hash {1991my$project=shift;1992my$o_git_dir=$git_dir;1993my$retval=undef;1994$git_dir="$projectroot/$project";1995if(open my$fd,"-|", git_cmd(),"rev-parse","--verify","HEAD") {1996my$head= <$fd>;1997close$fd;1998if(defined$head&&$head=~/^([0-9a-fA-F]{40})$/) {1999$retval=$1;2000}2001}2002if(defined$o_git_dir) {2003$git_dir=$o_git_dir;2004}2005return$retval;2006}20072008# get type of given object2009sub git_get_type {2010my$hash=shift;20112012open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2013my$type= <$fd>;2014close$fdorreturn;2015chomp$type;2016return$type;2017}20182019# repository configuration2020our$config_file='';2021our%config;20222023# store multiple values for single key as anonymous array reference2024# single values stored directly in the hash, not as [ <value> ]2025sub hash_set_multi {2026my($hash,$key,$value) =@_;20272028if(!exists$hash->{$key}) {2029$hash->{$key} =$value;2030}elsif(!ref$hash->{$key}) {2031$hash->{$key} = [$hash->{$key},$value];2032}else{2033push@{$hash->{$key}},$value;2034}2035}20362037# return hash of git project configuration2038# optionally limited to some section, e.g. 'gitweb'2039sub git_parse_project_config {2040my$section_regexp=shift;2041my%config;20422043local$/="\0";20442045open my$fh,"-|", git_cmd(),"config",'-z','-l',2046orreturn;20472048while(my$keyval= <$fh>) {2049chomp$keyval;2050my($key,$value) =split(/\n/,$keyval,2);20512052 hash_set_multi(\%config,$key,$value)2053if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2054}2055close$fh;20562057return%config;2058}20592060# convert config value to boolean: 'true' or 'false'2061# no value, number > 0, 'true' and 'yes' values are true2062# rest of values are treated as false (never as error)2063sub config_to_bool {2064my$val=shift;20652066return1if!defined$val;# section.key20672068# strip leading and trailing whitespace2069$val=~s/^\s+//;2070$val=~s/\s+$//;20712072return(($val=~/^\d+$/&&$val) ||# section.key = 12073($val=~/^(?:true|yes)$/i));# section.key = true2074}20752076# convert config value to simple decimal number2077# an optional value suffix of 'k', 'm', or 'g' will cause the value2078# to be multiplied by 1024, 1048576, or 10737418242079sub config_to_int {2080my$val=shift;20812082# strip leading and trailing whitespace2083$val=~s/^\s+//;2084$val=~s/\s+$//;20852086if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2087$unit=lc($unit);2088# unknown unit is treated as 12089return$num* ($uniteq'g'?1073741824:2090$uniteq'm'?1048576:2091$uniteq'k'?1024:1);2092}2093return$val;2094}20952096# convert config value to array reference, if needed2097sub config_to_multi {2098my$val=shift;20992100returnref($val) ?$val: (defined($val) ? [$val] : []);2101}21022103sub git_get_project_config {2104my($key,$type) =@_;21052106# key sanity check2107return unless($key);2108$key=~s/^gitweb\.//;2109return if($key=~m/\W/);21102111# type sanity check2112if(defined$type) {2113$type=~s/^--//;2114$type=undef2115unless($typeeq'bool'||$typeeq'int');2116}21172118# get config2119if(!defined$config_file||2120$config_filene"$git_dir/config") {2121%config= git_parse_project_config('gitweb');2122$config_file="$git_dir/config";2123}21242125# check if config variable (key) exists2126return unlessexists$config{"gitweb.$key"};21272128# ensure given type2129if(!defined$type) {2130return$config{"gitweb.$key"};2131}elsif($typeeq'bool') {2132# backward compatibility: 'git config --bool' returns true/false2133return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2134}elsif($typeeq'int') {2135return config_to_int($config{"gitweb.$key"});2136}2137return$config{"gitweb.$key"};2138}21392140# get hash of given path at given ref2141sub git_get_hash_by_path {2142my$base=shift;2143my$path=shift||returnundef;2144my$type=shift;21452146$path=~ s,/+$,,;21472148open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2149or die_error(500,"Open git-ls-tree failed");2150my$line= <$fd>;2151close$fdorreturnundef;21522153if(!defined$line) {2154# there is no tree or hash given by $path at $base2155returnundef;2156}21572158#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2159$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2160if(defined$type&&$typene$2) {2161# type doesn't match2162returnundef;2163}2164return$3;2165}21662167# get path of entry with given hash at given tree-ish (ref)2168# used to get 'from' filename for combined diff (merge commit) for renames2169sub git_get_path_by_hash {2170my$base=shift||return;2171my$hash=shift||return;21722173local$/="\0";21742175open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2176orreturnundef;2177while(my$line= <$fd>) {2178chomp$line;21792180#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2181#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2182if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2183close$fd;2184return$1;2185}2186}2187close$fd;2188returnundef;2189}21902191## ......................................................................2192## git utility functions, directly accessing git repository21932194sub git_get_project_description {2195my$path=shift;21962197$git_dir="$projectroot/$path";2198open my$fd,'<',"$git_dir/description"2199orreturn git_get_project_config('description');2200my$descr= <$fd>;2201close$fd;2202if(defined$descr) {2203chomp$descr;2204}2205return$descr;2206}22072208sub git_get_project_ctags {2209my$path=shift;2210my$ctags= {};22112212$git_dir="$projectroot/$path";2213opendir my$dh,"$git_dir/ctags"2214orreturn$ctags;2215foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2216open my$ct,'<',$_ornext;2217my$val= <$ct>;2218chomp$val;2219close$ct;2220my$ctag=$_;$ctag=~ s#.*/##;2221$ctags->{$ctag} =$val;2222}2223closedir$dh;2224$ctags;2225}22262227sub git_populate_project_tagcloud {2228my$ctags=shift;22292230# First, merge different-cased tags; tags vote on casing2231my%ctags_lc;2232foreach(keys%$ctags) {2233$ctags_lc{lc$_}->{count} +=$ctags->{$_};2234if(not$ctags_lc{lc$_}->{topcount}2235or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2236$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2237$ctags_lc{lc$_}->{topname} =$_;2238}2239}22402241my$cloud;2242if(eval{require HTML::TagCloud;1; }) {2243$cloud= HTML::TagCloud->new;2244foreach(sort keys%ctags_lc) {2245# Pad the title with spaces so that the cloud looks2246# less crammed.2247my$title=$ctags_lc{$_}->{topname};2248$title=~s/ / /g;2249$title=~s/^/ /g;2250$title=~s/$/ /g;2251$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2252}2253}else{2254$cloud= \%ctags_lc;2255}2256$cloud;2257}22582259sub git_show_project_tagcloud {2260my($cloud,$count) =@_;2261print STDERR ref($cloud)."..\n";2262if(ref$cloudeq'HTML::TagCloud') {2263return$cloud->html_and_css($count);2264}else{2265my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2266return'<p align="center">'.join(', ',map{2267"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"2268}splice(@tags,0,$count)) .'</p>';2269}2270}22712272sub git_get_project_url_list {2273my$path=shift;22742275$git_dir="$projectroot/$path";2276open my$fd,'<',"$git_dir/cloneurl"2277orreturnwantarray?2278@{ config_to_multi(git_get_project_config('url')) } :2279 config_to_multi(git_get_project_config('url'));2280my@git_project_url_list=map{chomp;$_} <$fd>;2281close$fd;22822283returnwantarray?@git_project_url_list: \@git_project_url_list;2284}22852286sub git_get_projects_list {2287my($filter) =@_;2288my@list;22892290$filter||='';2291$filter=~s/\.git$//;22922293my$check_forks= gitweb_check_feature('forks');22942295if(-d $projects_list) {2296# search in directory2297my$dir=$projects_list. ($filter?"/$filter":'');2298# remove the trailing "/"2299$dir=~s!/+$!!;2300my$pfxlen=length("$dir");2301my$pfxdepth= ($dir=~tr!/!!);23022303 File::Find::find({2304 follow_fast =>1,# follow symbolic links2305 follow_skip =>2,# ignore duplicates2306 dangling_symlinks =>0,# ignore dangling symlinks, silently2307 wanted =>sub{2308# skip project-list toplevel, if we get it.2309return if(m!^[/.]$!);2310# only directories can be git repositories2311return unless(-d $_);2312# don't traverse too deep (Find is super slow on os x)2313if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2314$File::Find::prune =1;2315return;2316}23172318my$subdir=substr($File::Find::name,$pfxlen+1);2319# we check related file in $projectroot2320my$path= ($filter?"$filter/":'') .$subdir;2321if(check_export_ok("$projectroot/$path")) {2322push@list, { path =>$path};2323$File::Find::prune =1;2324}2325},2326},"$dir");23272328}elsif(-f $projects_list) {2329# read from file(url-encoded):2330# 'git%2Fgit.git Linus+Torvalds'2331# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2332# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2333my%paths;2334open my$fd,'<',$projects_listorreturn;2335 PROJECT:2336while(my$line= <$fd>) {2337chomp$line;2338my($path,$owner) =split' ',$line;2339$path= unescape($path);2340$owner= unescape($owner);2341if(!defined$path) {2342next;2343}2344if($filterne'') {2345# looking for forks;2346my$pfx=substr($path,0,length($filter));2347if($pfxne$filter) {2348next PROJECT;2349}2350my$sfx=substr($path,length($filter));2351if($sfx!~/^\/.*\.git$/) {2352next PROJECT;2353}2354}elsif($check_forks) {2355 PATH:2356foreachmy$filter(keys%paths) {2357# looking for forks;2358my$pfx=substr($path,0,length($filter));2359if($pfxne$filter) {2360next PATH;2361}2362my$sfx=substr($path,length($filter));2363if($sfx!~/^\/.*\.git$/) {2364next PATH;2365}2366# is a fork, don't include it in2367# the list2368next PROJECT;2369}2370}2371if(check_export_ok("$projectroot/$path")) {2372my$pr= {2373 path =>$path,2374 owner => to_utf8($owner),2375};2376push@list,$pr;2377(my$forks_path=$path) =~s/\.git$//;2378$paths{$forks_path}++;2379}2380}2381close$fd;2382}2383return@list;2384}23852386our$gitweb_project_owner=undef;2387sub git_get_project_list_from_file {23882389return if(defined$gitweb_project_owner);23902391$gitweb_project_owner= {};2392# read from file (url-encoded):2393# 'git%2Fgit.git Linus+Torvalds'2394# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2395# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2396if(-f $projects_list) {2397open(my$fd,'<',$projects_list);2398while(my$line= <$fd>) {2399chomp$line;2400my($pr,$ow) =split' ',$line;2401$pr= unescape($pr);2402$ow= unescape($ow);2403$gitweb_project_owner->{$pr} = to_utf8($ow);2404}2405close$fd;2406}2407}24082409sub git_get_project_owner {2410my$project=shift;2411my$owner;24122413returnundefunless$project;2414$git_dir="$projectroot/$project";24152416if(!defined$gitweb_project_owner) {2417 git_get_project_list_from_file();2418}24192420if(exists$gitweb_project_owner->{$project}) {2421$owner=$gitweb_project_owner->{$project};2422}2423if(!defined$owner){2424$owner= git_get_project_config('owner');2425}2426if(!defined$owner) {2427$owner= get_file_owner("$git_dir");2428}24292430return$owner;2431}24322433sub git_get_last_activity {2434my($path) =@_;2435my$fd;24362437$git_dir="$projectroot/$path";2438open($fd,"-|", git_cmd(),'for-each-ref',2439'--format=%(committer)',2440'--sort=-committerdate',2441'--count=1',2442'refs/heads')orreturn;2443my$most_recent= <$fd>;2444close$fdorreturn;2445if(defined$most_recent&&2446$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2447my$timestamp=$1;2448my$age=time-$timestamp;2449return($age, age_string($age));2450}2451return(undef,undef);2452}24532454sub git_get_references {2455my$type=shift||"";2456my%refs;2457# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112458# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2459open my$fd,"-|", git_cmd(),"show-ref","--dereference",2460($type? ("--","refs/$type") : ())# use -- <pattern> if $type2461orreturn;24622463while(my$line= <$fd>) {2464chomp$line;2465if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2466if(defined$refs{$1}) {2467push@{$refs{$1}},$2;2468}else{2469$refs{$1} = [$2];2470}2471}2472}2473close$fdorreturn;2474return \%refs;2475}24762477sub git_get_rev_name_tags {2478my$hash=shift||returnundef;24792480open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2481orreturn;2482my$name_rev= <$fd>;2483close$fd;24842485if($name_rev=~ m|^$hash tags/(.*)$|) {2486return$1;2487}else{2488# catches also '$hash undefined' output2489returnundef;2490}2491}24922493## ----------------------------------------------------------------------2494## parse to hash functions24952496sub parse_date {2497my$epoch=shift;2498my$tz=shift||"-0000";24992500my%date;2501my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2502my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2503my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2504$date{'hour'} =$hour;2505$date{'minute'} =$min;2506$date{'mday'} =$mday;2507$date{'day'} =$days[$wday];2508$date{'month'} =$months[$mon];2509$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2510$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2511$date{'mday-time'} =sprintf"%d%s%02d:%02d",2512$mday,$months[$mon],$hour,$min;2513$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",25141900+$year,1+$mon,$mday,$hour,$min,$sec;25152516$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2517my$local=$epoch+ ((int$1+ ($2/60)) *3600);2518($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2519$date{'hour_local'} =$hour;2520$date{'minute_local'} =$min;2521$date{'tz_local'} =$tz;2522$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",25231900+$year,$mon+1,$mday,2524$hour,$min,$sec,$tz);2525return%date;2526}25272528sub parse_tag {2529my$tag_id=shift;2530my%tag;2531my@comment;25322533open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2534$tag{'id'} =$tag_id;2535while(my$line= <$fd>) {2536chomp$line;2537if($line=~m/^object ([0-9a-fA-F]{40})$/) {2538$tag{'object'} =$1;2539}elsif($line=~m/^type (.+)$/) {2540$tag{'type'} =$1;2541}elsif($line=~m/^tag (.+)$/) {2542$tag{'name'} =$1;2543}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2544$tag{'author'} =$1;2545$tag{'author_epoch'} =$2;2546$tag{'author_tz'} =$3;2547if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {2548$tag{'author_name'} =$1;2549$tag{'author_email'} =$2;2550}else{2551$tag{'author_name'} =$tag{'author'};2552}2553}elsif($line=~m/--BEGIN/) {2554push@comment,$line;2555last;2556}elsif($lineeq"") {2557last;2558}2559}2560push@comment, <$fd>;2561$tag{'comment'} = \@comment;2562close$fdorreturn;2563if(!defined$tag{'name'}) {2564return2565};2566return%tag2567}25682569sub parse_commit_text {2570my($commit_text,$withparents) =@_;2571my@commit_lines=split'\n',$commit_text;2572my%co;25732574pop@commit_lines;# Remove '\0'25752576if(!@commit_lines) {2577return;2578}25792580my$header=shift@commit_lines;2581if($header!~m/^[0-9a-fA-F]{40}/) {2582return;2583}2584($co{'id'},my@parents) =split' ',$header;2585while(my$line=shift@commit_lines) {2586last if$lineeq"\n";2587if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2588$co{'tree'} =$1;2589}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2590push@parents,$1;2591}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2592$co{'author'} =$1;2593$co{'author_epoch'} =$2;2594$co{'author_tz'} =$3;2595if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2596$co{'author_name'} =$1;2597$co{'author_email'} =$2;2598}else{2599$co{'author_name'} =$co{'author'};2600}2601}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2602$co{'committer'} =$1;2603$co{'committer_epoch'} =$2;2604$co{'committer_tz'} =$3;2605$co{'committer_name'} =$co{'committer'};2606if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2607$co{'committer_name'} =$1;2608$co{'committer_email'} =$2;2609}else{2610$co{'committer_name'} =$co{'committer'};2611}2612}2613}2614if(!defined$co{'tree'}) {2615return;2616};2617$co{'parents'} = \@parents;2618$co{'parent'} =$parents[0];26192620foreachmy$title(@commit_lines) {2621$title=~s/^ //;2622if($titlene"") {2623$co{'title'} = chop_str($title,80,5);2624# remove leading stuff of merges to make the interesting part visible2625if(length($title) >50) {2626$title=~s/^Automatic //;2627$title=~s/^merge (of|with) /Merge ... /i;2628if(length($title) >50) {2629$title=~s/(http|rsync):\/\///;2630}2631if(length($title) >50) {2632$title=~s/(master|www|rsync)\.//;2633}2634if(length($title) >50) {2635$title=~s/kernel.org:?//;2636}2637if(length($title) >50) {2638$title=~s/\/pub\/scm//;2639}2640}2641$co{'title_short'} = chop_str($title,50,5);2642last;2643}2644}2645if(!defined$co{'title'} ||$co{'title'}eq"") {2646$co{'title'} =$co{'title_short'} ='(no commit message)';2647}2648# remove added spaces2649foreachmy$line(@commit_lines) {2650$line=~s/^ //;2651}2652$co{'comment'} = \@commit_lines;26532654my$age=time-$co{'committer_epoch'};2655$co{'age'} =$age;2656$co{'age_string'} = age_string($age);2657my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2658if($age>60*60*24*7*2) {2659$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2660$co{'age_string_age'} =$co{'age_string'};2661}else{2662$co{'age_string_date'} =$co{'age_string'};2663$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2664}2665return%co;2666}26672668sub parse_commit {2669my($commit_id) =@_;2670my%co;26712672local$/="\0";26732674open my$fd,"-|", git_cmd(),"rev-list",2675"--parents",2676"--header",2677"--max-count=1",2678$commit_id,2679"--",2680or die_error(500,"Open git-rev-list failed");2681%co= parse_commit_text(<$fd>,1);2682close$fd;26832684return%co;2685}26862687sub parse_commits {2688my($commit_id,$maxcount,$skip,$filename,@args) =@_;2689my@cos;26902691$maxcount||=1;2692$skip||=0;26932694local$/="\0";26952696open my$fd,"-|", git_cmd(),"rev-list",2697"--header",2698@args,2699("--max-count=".$maxcount),2700("--skip=".$skip),2701@extra_options,2702$commit_id,2703"--",2704($filename? ($filename) : ())2705or die_error(500,"Open git-rev-list failed");2706while(my$line= <$fd>) {2707my%co= parse_commit_text($line);2708push@cos, \%co;2709}2710close$fd;27112712returnwantarray?@cos: \@cos;2713}27142715# parse line of git-diff-tree "raw" output2716sub parse_difftree_raw_line {2717my$line=shift;2718my%res;27192720# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2721# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2722if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2723$res{'from_mode'} =$1;2724$res{'to_mode'} =$2;2725$res{'from_id'} =$3;2726$res{'to_id'} =$4;2727$res{'status'} =$5;2728$res{'similarity'} =$6;2729if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2730($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2731}else{2732$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2733}2734}2735# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2736# combined diff (for merge commit)2737elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2738$res{'nparents'} =length($1);2739$res{'from_mode'} = [split(' ',$2) ];2740$res{'to_mode'} =pop@{$res{'from_mode'}};2741$res{'from_id'} = [split(' ',$3) ];2742$res{'to_id'} =pop@{$res{'from_id'}};2743$res{'status'} = [split('',$4) ];2744$res{'to_file'} = unquote($5);2745}2746# 'c512b523472485aef4fff9e57b229d9d243c967f'2747elsif($line=~m/^([0-9a-fA-F]{40})$/) {2748$res{'commit'} =$1;2749}27502751returnwantarray?%res: \%res;2752}27532754# wrapper: return parsed line of git-diff-tree "raw" output2755# (the argument might be raw line, or parsed info)2756sub parsed_difftree_line {2757my$line_or_ref=shift;27582759if(ref($line_or_ref)eq"HASH") {2760# pre-parsed (or generated by hand)2761return$line_or_ref;2762}else{2763return parse_difftree_raw_line($line_or_ref);2764}2765}27662767# parse line of git-ls-tree output2768sub parse_ls_tree_line {2769my$line=shift;2770my%opts=@_;2771my%res;27722773#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2774$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;27752776$res{'mode'} =$1;2777$res{'type'} =$2;2778$res{'hash'} =$3;2779if($opts{'-z'}) {2780$res{'name'} =$4;2781}else{2782$res{'name'} = unquote($4);2783}27842785returnwantarray?%res: \%res;2786}27872788# generates _two_ hashes, references to which are passed as 2 and 3 argument2789sub parse_from_to_diffinfo {2790my($diffinfo,$from,$to,@parents) =@_;27912792if($diffinfo->{'nparents'}) {2793# combined diff2794$from->{'file'} = [];2795$from->{'href'} = [];2796 fill_from_file_info($diffinfo,@parents)2797unlessexists$diffinfo->{'from_file'};2798for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2799$from->{'file'}[$i] =2800defined$diffinfo->{'from_file'}[$i] ?2801$diffinfo->{'from_file'}[$i] :2802$diffinfo->{'to_file'};2803if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2804$from->{'href'}[$i] = href(action=>"blob",2805 hash_base=>$parents[$i],2806 hash=>$diffinfo->{'from_id'}[$i],2807 file_name=>$from->{'file'}[$i]);2808}else{2809$from->{'href'}[$i] =undef;2810}2811}2812}else{2813# ordinary (not combined) diff2814$from->{'file'} =$diffinfo->{'from_file'};2815if($diffinfo->{'status'}ne"A") {# not new (added) file2816$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2817 hash=>$diffinfo->{'from_id'},2818 file_name=>$from->{'file'});2819}else{2820delete$from->{'href'};2821}2822}28232824$to->{'file'} =$diffinfo->{'to_file'};2825if(!is_deleted($diffinfo)) {# file exists in result2826$to->{'href'} = href(action=>"blob", hash_base=>$hash,2827 hash=>$diffinfo->{'to_id'},2828 file_name=>$to->{'file'});2829}else{2830delete$to->{'href'};2831}2832}28332834## ......................................................................2835## parse to array of hashes functions28362837sub git_get_heads_list {2838my$limit=shift;2839my@headslist;28402841open my$fd,'-|', git_cmd(),'for-each-ref',2842($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2843'--format=%(objectname) %(refname) %(subject)%00%(committer)',2844'refs/heads'2845orreturn;2846while(my$line= <$fd>) {2847my%ref_item;28482849chomp$line;2850my($refinfo,$committerinfo) =split(/\0/,$line);2851my($hash,$name,$title) =split(' ',$refinfo,3);2852my($committer,$epoch,$tz) =2853($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2854$ref_item{'fullname'} =$name;2855$name=~s!^refs/heads/!!;28562857$ref_item{'name'} =$name;2858$ref_item{'id'} =$hash;2859$ref_item{'title'} =$title||'(no commit message)';2860$ref_item{'epoch'} =$epoch;2861if($epoch) {2862$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2863}else{2864$ref_item{'age'} ="unknown";2865}28662867push@headslist, \%ref_item;2868}2869close$fd;28702871returnwantarray?@headslist: \@headslist;2872}28732874sub git_get_tags_list {2875my$limit=shift;2876my@tagslist;28772878open my$fd,'-|', git_cmd(),'for-each-ref',2879($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',2880'--format=%(objectname) %(objecttype) %(refname) '.2881'%(*objectname) %(*objecttype) %(subject)%00%(creator)',2882'refs/tags'2883orreturn;2884while(my$line= <$fd>) {2885my%ref_item;28862887chomp$line;2888my($refinfo,$creatorinfo) =split(/\0/,$line);2889my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);2890my($creator,$epoch,$tz) =2891($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);2892$ref_item{'fullname'} =$name;2893$name=~s!^refs/tags/!!;28942895$ref_item{'type'} =$type;2896$ref_item{'id'} =$id;2897$ref_item{'name'} =$name;2898if($typeeq"tag") {2899$ref_item{'subject'} =$title;2900$ref_item{'reftype'} =$reftype;2901$ref_item{'refid'} =$refid;2902}else{2903$ref_item{'reftype'} =$type;2904$ref_item{'refid'} =$id;2905}29062907if($typeeq"tag"||$typeeq"commit") {2908$ref_item{'epoch'} =$epoch;2909if($epoch) {2910$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2911}else{2912$ref_item{'age'} ="unknown";2913}2914}29152916push@tagslist, \%ref_item;2917}2918close$fd;29192920returnwantarray?@tagslist: \@tagslist;2921}29222923## ----------------------------------------------------------------------2924## filesystem-related functions29252926sub get_file_owner {2927my$path=shift;29282929my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);2930my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);2931if(!defined$gcos) {2932returnundef;2933}2934my$owner=$gcos;2935$owner=~s/[,;].*$//;2936return to_utf8($owner);2937}29382939# assume that file exists2940sub insert_file {2941my$filename=shift;29422943open my$fd,'<',$filename;2944print map{ to_utf8($_) } <$fd>;2945close$fd;2946}29472948## ......................................................................2949## mimetype related functions29502951sub mimetype_guess_file {2952my$filename=shift;2953my$mimemap=shift;2954-r $mimemaporreturnundef;29552956my%mimemap;2957open(my$mh,'<',$mimemap)orreturnundef;2958while(<$mh>) {2959next ifm/^#/;# skip comments2960my($mimetype,$exts) =split(/\t+/);2961if(defined$exts) {2962my@exts=split(/\s+/,$exts);2963foreachmy$ext(@exts) {2964$mimemap{$ext} =$mimetype;2965}2966}2967}2968close($mh);29692970$filename=~/\.([^.]*)$/;2971return$mimemap{$1};2972}29732974sub mimetype_guess {2975my$filename=shift;2976my$mime;2977$filename=~/\./orreturnundef;29782979if($mimetypes_file) {2980my$file=$mimetypes_file;2981if($file!~m!^/!) {# if it is relative path2982# it is relative to project2983$file="$projectroot/$project/$file";2984}2985$mime= mimetype_guess_file($filename,$file);2986}2987$mime||= mimetype_guess_file($filename,'/etc/mime.types');2988return$mime;2989}29902991sub blob_mimetype {2992my$fd=shift;2993my$filename=shift;29942995if($filename) {2996my$mime= mimetype_guess($filename);2997$mimeandreturn$mime;2998}29993000# just in case3001return$default_blob_plain_mimetypeunless$fd;30023003if(-T $fd) {3004return'text/plain';3005}elsif(!$filename) {3006return'application/octet-stream';3007}elsif($filename=~m/\.png$/i) {3008return'image/png';3009}elsif($filename=~m/\.gif$/i) {3010return'image/gif';3011}elsif($filename=~m/\.jpe?g$/i) {3012return'image/jpeg';3013}else{3014return'application/octet-stream';3015}3016}30173018sub blob_contenttype {3019my($fd,$file_name,$type) =@_;30203021$type||= blob_mimetype($fd,$file_name);3022if($typeeq'text/plain'&&defined$default_text_plain_charset) {3023$type.="; charset=$default_text_plain_charset";3024}30253026return$type;3027}30283029## ======================================================================3030## functions printing HTML: header, footer, error page30313032sub git_header_html {3033my$status=shift||"200 OK";3034my$expires=shift;30353036my$title="$site_name";3037if(defined$project) {3038$title.=" - ". to_utf8($project);3039if(defined$action) {3040$title.="/$action";3041if(defined$file_name) {3042$title.=" - ". esc_path($file_name);3043if($actioneq"tree"&&$file_name!~ m|/$|) {3044$title.="/";3045}3046}3047}3048}3049my$content_type;3050# require explicit support from the UA if we are to send the page as3051# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3052# we have to do this because MSIE sometimes globs '*/*', pretending to3053# support xhtml+xml but choking when it gets what it asked for.3054if(defined$cgi->http('HTTP_ACCEPT') &&3055$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3056$cgi->Accept('application/xhtml+xml') !=0) {3057$content_type='application/xhtml+xml';3058}else{3059$content_type='text/html';3060}3061print$cgi->header(-type=>$content_type, -charset =>'utf-8',3062-status=>$status, -expires =>$expires);3063my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';3064print<<EOF;3065<?xml version="1.0" encoding="utf-8"?>3066<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">3067<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">3068<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->3069<!-- git core binaries version$git_version-->3070<head>3071<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>3072<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>3073<meta name="robots" content="index, nofollow"/>3074<title>$title</title>3075EOF3076# the stylesheet, favicon etc urls won't work correctly with path_info3077# unless we set the appropriate base URL3078if($ENV{'PATH_INFO'}) {3079print"<base href=\"".esc_url($base_url)."\"/>\n";3080}3081# print out each stylesheet that exist, providing backwards capability3082# for those people who defined $stylesheet in a config file3083if(defined$stylesheet) {3084print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3085}else{3086foreachmy$stylesheet(@stylesheets) {3087next unless$stylesheet;3088print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3089}3090}3091if(defined$project) {3092my%href_params= get_feed_info();3093if(!exists$href_params{'-title'}) {3094$href_params{'-title'} ='log';3095}30963097foreachmy$formatqw(RSS Atom){3098my$type=lc($format);3099my%link_attr= (3100'-rel'=>'alternate',3101'-title'=>"$project-$href_params{'-title'} -$formatfeed",3102'-type'=>"application/$type+xml"3103);31043105$href_params{'action'} =$type;3106$link_attr{'-href'} = href(%href_params);3107print"<link ".3108"rel=\"$link_attr{'-rel'}\"".3109"title=\"$link_attr{'-title'}\"".3110"href=\"$link_attr{'-href'}\"".3111"type=\"$link_attr{'-type'}\"".3112"/>\n";31133114$href_params{'extra_options'} ='--no-merges';3115$link_attr{'-href'} = href(%href_params);3116$link_attr{'-title'} .=' (no merges)';3117print"<link ".3118"rel=\"$link_attr{'-rel'}\"".3119"title=\"$link_attr{'-title'}\"".3120"href=\"$link_attr{'-href'}\"".3121"type=\"$link_attr{'-type'}\"".3122"/>\n";3123}31243125}else{3126printf('<link rel="alternate" title="%sprojects list" '.3127'href="%s" type="text/plain; charset=utf-8" />'."\n",3128$site_name, href(project=>undef, action=>"project_index"));3129printf('<link rel="alternate" title="%sprojects feeds" '.3130'href="%s" type="text/x-opml" />'."\n",3131$site_name, href(project=>undef, action=>"opml"));3132}3133if(defined$favicon) {3134printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);3135}31363137print"</head>\n".3138"<body>\n";31393140if(-f $site_header) {3141 insert_file($site_header);3142}31433144print"<div class=\"page_header\">\n".3145$cgi->a({-href => esc_url($logo_url),3146-title =>$logo_label},3147qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));3148print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3149if(defined$project) {3150print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3151if(defined$action) {3152print" /$action";3153}3154print"\n";3155}3156print"</div>\n";31573158my$have_search= gitweb_check_feature('search');3159if(defined$project&&$have_search) {3160if(!defined$searchtext) {3161$searchtext="";3162}3163my$search_hash;3164if(defined$hash_base) {3165$search_hash=$hash_base;3166}elsif(defined$hash) {3167$search_hash=$hash;3168}else{3169$search_hash="HEAD";3170}3171my$action=$my_uri;3172my$use_pathinfo= gitweb_check_feature('pathinfo');3173if($use_pathinfo) {3174$action.="/".esc_url($project);3175}3176print$cgi->startform(-method=>"get", -action =>$action) .3177"<div class=\"search\">\n".3178(!$use_pathinfo&&3179$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3180$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3181$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3182$cgi->popup_menu(-name =>'st', -default=>'commit',3183-values=> ['commit','grep','author','committer','pickaxe']) .3184$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3185" search:\n",3186$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3187"<span title=\"Extended regular expression\">".3188$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3189-checked =>$search_use_regexp) .3190"</span>".3191"</div>".3192$cgi->end_form() ."\n";3193}3194}31953196sub git_footer_html {3197my$feed_class='rss_logo';31983199print"<div class=\"page_footer\">\n";3200if(defined$project) {3201my$descr= git_get_project_description($project);3202if(defined$descr) {3203print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3204}32053206my%href_params= get_feed_info();3207if(!%href_params) {3208$feed_class.=' generic';3209}3210$href_params{'-title'} ||='log';32113212foreachmy$formatqw(RSS Atom){3213$href_params{'action'} =lc($format);3214print$cgi->a({-href => href(%href_params),3215-title =>"$href_params{'-title'}$formatfeed",3216-class=>$feed_class},$format)."\n";3217}32183219}else{3220print$cgi->a({-href => href(project=>undef, action=>"opml"),3221-class=>$feed_class},"OPML") ." ";3222print$cgi->a({-href => href(project=>undef, action=>"project_index"),3223-class=>$feed_class},"TXT") ."\n";3224}3225print"</div>\n";# class="page_footer"32263227if(defined$t0&& gitweb_check_feature('timed')) {3228print"<div id=\"generating_info\">\n";3229print'This page took '.3230'<span id="generating_time" class="time_span">'.3231 Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).3232' seconds </span>'.3233' and '.3234'<span id="generating_cmd">'.3235$number_of_git_cmds.3236'</span> git commands '.3237" to generate.\n";3238print"</div>\n";# class="page_footer"3239}32403241if(-f $site_footer) {3242 insert_file($site_footer);3243}32443245print"</body>\n".3246"</html>";3247}32483249# die_error(<http_status_code>, <error_message>)3250# Example: die_error(404, 'Hash not found')3251# By convention, use the following status codes (as defined in RFC 2616):3252# 400: Invalid or missing CGI parameters, or3253# requested object exists but has wrong type.3254# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3255# this server or project.3256# 404: Requested object/revision/project doesn't exist.3257# 500: The server isn't configured properly, or3258# an internal error occurred (e.g. failed assertions caused by bugs), or3259# an unknown error occurred (e.g. the git binary died unexpectedly).3260sub die_error {3261my$status=shift||500;3262my$error=shift||"Internal server error";32633264my%http_responses= (400=>'400 Bad Request',3265403=>'403 Forbidden',3266404=>'404 Not Found',3267500=>'500 Internal Server Error');3268 git_header_html($http_responses{$status});3269print<<EOF;3270<div class="page_body">3271<br /><br />3272$status-$error3273<br />3274</div>3275EOF3276 git_footer_html();3277exit;3278}32793280## ----------------------------------------------------------------------3281## functions printing or outputting HTML: navigation32823283sub git_print_page_nav {3284my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3285$extra=''if!defined$extra;# pager or formats32863287my@navs=qw(summary shortlog log commit commitdiff tree);3288if($suppress) {3289@navs=grep{$_ne$suppress}@navs;3290}32913292my%arg=map{$_=> {action=>$_} }@navs;3293if(defined$head) {3294for(qw(commit commitdiff)) {3295$arg{$_}{'hash'} =$head;3296}3297if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3298for(qw(shortlog log)) {3299$arg{$_}{'hash'} =$head;3300}3301}3302}33033304$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3305$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;33063307my@actions= gitweb_get_feature('actions');3308my%repl= (3309'%'=>'%',3310'n'=>$project,# project name3311'f'=>$git_dir,# project path within filesystem3312'h'=>$treehead||'',# current hash ('h' parameter)3313'b'=>$treebase||'',# hash base ('hb' parameter)3314);3315while(@actions) {3316my($label,$link,$pos) =splice(@actions,0,3);3317# insert3318@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3319# munch munch3320$link=~s/%([%nfhb])/$repl{$1}/g;3321$arg{$label}{'_href'} =$link;3322}33233324print"<div class=\"page_nav\">\n".3325(join" | ",3326map{$_eq$current?3327$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3328}@navs);3329print"<br/>\n$extra<br/>\n".3330"</div>\n";3331}33323333sub format_paging_nav {3334my($action,$hash,$head,$page,$has_next_link) =@_;3335my$paging_nav;333633373338if($hashne$head||$page) {3339$paging_nav.=$cgi->a({-href => href(action=>$action)},"HEAD");3340}else{3341$paging_nav.="HEAD";3342}33433344if($page>0) {3345$paging_nav.=" ⋅ ".3346$cgi->a({-href => href(-replay=>1, page=>$page-1),3347-accesskey =>"p", -title =>"Alt-p"},"prev");3348}else{3349$paging_nav.=" ⋅ prev";3350}33513352if($has_next_link) {3353$paging_nav.=" ⋅ ".3354$cgi->a({-href => href(-replay=>1, page=>$page+1),3355-accesskey =>"n", -title =>"Alt-n"},"next");3356}else{3357$paging_nav.=" ⋅ next";3358}33593360return$paging_nav;3361}33623363## ......................................................................3364## functions printing or outputting HTML: div33653366sub git_print_header_div {3367my($action,$title,$hash,$hash_base) =@_;3368my%args= ();33693370$args{'action'} =$action;3371$args{'hash'} =$hashif$hash;3372$args{'hash_base'} =$hash_baseif$hash_base;33733374print"<div class=\"header\">\n".3375$cgi->a({-href => href(%args), -class=>"title"},3376$title?$title:$action) .3377"\n</div>\n";3378}33793380sub print_local_time {3381my%date=@_;3382if($date{'hour_local'} <6) {3383printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3384$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3385}else{3386printf(" (%02d:%02d%s)",3387$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3388}3389}33903391# Outputs the author name and date in long form3392sub git_print_authorship {3393my$co=shift;3394my%opts=@_;3395my$tag=$opts{-tag} ||'div';33963397my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3398print"<$tagclass=\"author_date\">".3399 esc_html($co->{'author_name'}) .3400" [$ad{'rfc2822'}";3401 print_local_time(%ad)if($opts{-localtime});3402print"]". git_get_avatar($co->{'author_email'}, -pad_before =>1)3403."</$tag>\n";3404}34053406# Outputs table rows containing the full author or committer information,3407# in the format expected for 'commit' view (& similia).3408# Parameters are a commit hash reference, followed by the list of people3409# to output information for. If the list is empty it defalts to both3410# author and committer.3411sub git_print_authorship_rows {3412my$co=shift;3413# too bad we can't use @people = @_ || ('author', 'committer')3414my@people=@_;3415@people= ('author','committer')unless@people;3416foreachmy$who(@people) {3417my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});3418print"<tr><td>$who</td><td>". esc_html($co->{$who}) ."</td>".3419"<td rowspan=\"2\">".3420 git_get_avatar($co->{"${who}_email"}, -size =>'double') .3421"</td></tr>\n".3422"<tr>".3423"<td></td><td>$wd{'rfc2822'}";3424 print_local_time(%wd);3425print"</td>".3426"</tr>\n";3427}3428}34293430sub git_print_page_path {3431my$name=shift;3432my$type=shift;3433my$hb=shift;343434353436print"<div class=\"page_path\">";3437print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3438-title =>'tree root'}, to_utf8("[$project]"));3439print" / ";3440if(defined$name) {3441my@dirname=split'/',$name;3442my$basename=pop@dirname;3443my$fullname='';34443445foreachmy$dir(@dirname) {3446$fullname.= ($fullname?'/':'') .$dir;3447print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3448 hash_base=>$hb),3449-title =>$fullname}, esc_path($dir));3450print" / ";3451}3452if(defined$type&&$typeeq'blob') {3453print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3454 hash_base=>$hb),3455-title =>$name}, esc_path($basename));3456}elsif(defined$type&&$typeeq'tree') {3457print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3458 hash_base=>$hb),3459-title =>$name}, esc_path($basename));3460print" / ";3461}else{3462print esc_path($basename);3463}3464}3465print"<br/></div>\n";3466}34673468sub git_print_log {3469my$log=shift;3470my%opts=@_;34713472if($opts{'-remove_title'}) {3473# remove title, i.e. first line of log3474shift@$log;3475}3476# remove leading empty lines3477while(defined$log->[0] &&$log->[0]eq"") {3478shift@$log;3479}34803481# print log3482my$signoff=0;3483my$empty=0;3484foreachmy$line(@$log) {3485if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3486$signoff=1;3487$empty=0;3488if(!$opts{'-remove_signoff'}) {3489print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3490next;3491}else{3492# remove signoff lines3493next;3494}3495}else{3496$signoff=0;3497}34983499# print only one empty line3500# do not print empty line after signoff3501if($lineeq"") {3502next if($empty||$signoff);3503$empty=1;3504}else{3505$empty=0;3506}35073508print format_log_line_html($line) ."<br/>\n";3509}35103511if($opts{'-final_empty_line'}) {3512# end with single empty line3513print"<br/>\n"unless$empty;3514}3515}35163517# return link target (what link points to)3518sub git_get_link_target {3519my$hash=shift;3520my$link_target;35213522# read link3523open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3524orreturn;3525{3526local$/=undef;3527$link_target= <$fd>;3528}3529close$fd3530orreturn;35313532return$link_target;3533}35343535# given link target, and the directory (basedir) the link is in,3536# return target of link relative to top directory (top tree);3537# return undef if it is not possible (including absolute links).3538sub normalize_link_target {3539my($link_target,$basedir) =@_;35403541# absolute symlinks (beginning with '/') cannot be normalized3542return if(substr($link_target,0,1)eq'/');35433544# normalize link target to path from top (root) tree (dir)3545my$path;3546if($basedir) {3547$path=$basedir.'/'.$link_target;3548}else{3549# we are in top (root) tree (dir)3550$path=$link_target;3551}35523553# remove //, /./, and /../3554my@path_parts;3555foreachmy$part(split('/',$path)) {3556# discard '.' and ''3557next if(!$part||$parteq'.');3558# handle '..'3559if($parteq'..') {3560if(@path_parts) {3561pop@path_parts;3562}else{3563# link leads outside repository (outside top dir)3564return;3565}3566}else{3567push@path_parts,$part;3568}3569}3570$path=join('/',@path_parts);35713572return$path;3573}35743575# print tree entry (row of git_tree), but without encompassing <tr> element3576sub git_print_tree_entry {3577my($t,$basedir,$hash_base,$have_blame) =@_;35783579my%base_key= ();3580$base_key{'hash_base'} =$hash_baseifdefined$hash_base;35813582# The format of a table row is: mode list link. Where mode is3583# the mode of the entry, list is the name of the entry, an href,3584# and link is the action links of the entry.35853586print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3587if($t->{'type'}eq"blob") {3588print"<td class=\"list\">".3589$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3590 file_name=>"$basedir$t->{'name'}",%base_key),3591-class=>"list"}, esc_path($t->{'name'}));3592if(S_ISLNK(oct$t->{'mode'})) {3593my$link_target= git_get_link_target($t->{'hash'});3594if($link_target) {3595my$norm_target= normalize_link_target($link_target,$basedir);3596if(defined$norm_target) {3597print" -> ".3598$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3599 file_name=>$norm_target),3600-title =>$norm_target}, esc_path($link_target));3601}else{3602print" -> ". esc_path($link_target);3603}3604}3605}3606print"</td>\n";3607print"<td class=\"link\">";3608print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3609 file_name=>"$basedir$t->{'name'}",%base_key)},3610"blob");3611if($have_blame) {3612print" | ".3613$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3614 file_name=>"$basedir$t->{'name'}",%base_key)},3615"blame");3616}3617if(defined$hash_base) {3618print" | ".3619$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3620 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3621"history");3622}3623print" | ".3624$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3625 file_name=>"$basedir$t->{'name'}")},3626"raw");3627print"</td>\n";36283629}elsif($t->{'type'}eq"tree") {3630print"<td class=\"list\">";3631print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3632 file_name=>"$basedir$t->{'name'}",%base_key)},3633 esc_path($t->{'name'}));3634print"</td>\n";3635print"<td class=\"link\">";3636print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3637 file_name=>"$basedir$t->{'name'}",%base_key)},3638"tree");3639if(defined$hash_base) {3640print" | ".3641$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3642 file_name=>"$basedir$t->{'name'}")},3643"history");3644}3645print"</td>\n";3646}else{3647# unknown object: we can only present history for it3648# (this includes 'commit' object, i.e. submodule support)3649print"<td class=\"list\">".3650 esc_path($t->{'name'}) .3651"</td>\n";3652print"<td class=\"link\">";3653if(defined$hash_base) {3654print$cgi->a({-href => href(action=>"history",3655 hash_base=>$hash_base,3656 file_name=>"$basedir$t->{'name'}")},3657"history");3658}3659print"</td>\n";3660}3661}36623663## ......................................................................3664## functions printing large fragments of HTML36653666# get pre-image filenames for merge (combined) diff3667sub fill_from_file_info {3668my($diff,@parents) =@_;36693670$diff->{'from_file'} = [ ];3671$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3672for(my$i=0;$i<$diff->{'nparents'};$i++) {3673if($diff->{'status'}[$i]eq'R'||3674$diff->{'status'}[$i]eq'C') {3675$diff->{'from_file'}[$i] =3676 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3677}3678}36793680return$diff;3681}36823683# is current raw difftree line of file deletion3684sub is_deleted {3685my$diffinfo=shift;36863687return$diffinfo->{'to_id'}eq('0' x 40);3688}36893690# does patch correspond to [previous] difftree raw line3691# $diffinfo - hashref of parsed raw diff format3692# $patchinfo - hashref of parsed patch diff format3693# (the same keys as in $diffinfo)3694sub is_patch_split {3695my($diffinfo,$patchinfo) =@_;36963697returndefined$diffinfo&&defined$patchinfo3698&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3699}370037013702sub git_difftree_body {3703my($difftree,$hash,@parents) =@_;3704my($parent) =$parents[0];3705my$have_blame= gitweb_check_feature('blame');3706print"<div class=\"list_head\">\n";3707if($#{$difftree} >10) {3708print(($#{$difftree} +1) ." files changed:\n");3709}3710print"</div>\n";37113712print"<table class=\"".3713(@parents>1?"combined ":"") .3714"diff_tree\">\n";37153716# header only for combined diff in 'commitdiff' view3717my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3718if($has_header) {3719# table header3720print"<thead><tr>\n".3721"<th></th><th></th>\n";# filename, patchN link3722for(my$i=0;$i<@parents;$i++) {3723my$par=$parents[$i];3724print"<th>".3725$cgi->a({-href => href(action=>"commitdiff",3726 hash=>$hash, hash_parent=>$par),3727-title =>'commitdiff to parent number '.3728($i+1) .': '.substr($par,0,7)},3729$i+1) .3730" </th>\n";3731}3732print"</tr></thead>\n<tbody>\n";3733}37343735my$alternate=1;3736my$patchno=0;3737foreachmy$line(@{$difftree}) {3738my$diff= parsed_difftree_line($line);37393740if($alternate) {3741print"<tr class=\"dark\">\n";3742}else{3743print"<tr class=\"light\">\n";3744}3745$alternate^=1;37463747if(exists$diff->{'nparents'}) {# combined diff37483749 fill_from_file_info($diff,@parents)3750unlessexists$diff->{'from_file'};37513752if(!is_deleted($diff)) {3753# file exists in the result (child) commit3754print"<td>".3755$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3756 file_name=>$diff->{'to_file'},3757 hash_base=>$hash),3758-class=>"list"}, esc_path($diff->{'to_file'})) .3759"</td>\n";3760}else{3761print"<td>".3762 esc_path($diff->{'to_file'}) .3763"</td>\n";3764}37653766if($actioneq'commitdiff') {3767# link to patch3768$patchno++;3769print"<td class=\"link\">".3770$cgi->a({-href =>"#patch$patchno"},"patch") .3771" | ".3772"</td>\n";3773}37743775my$has_history=0;3776my$not_deleted=0;3777for(my$i=0;$i<$diff->{'nparents'};$i++) {3778my$hash_parent=$parents[$i];3779my$from_hash=$diff->{'from_id'}[$i];3780my$from_path=$diff->{'from_file'}[$i];3781my$status=$diff->{'status'}[$i];37823783$has_history||= ($statusne'A');3784$not_deleted||= ($statusne'D');37853786if($statuseq'A') {3787print"<td class=\"link\"align=\"right\"> | </td>\n";3788}elsif($statuseq'D') {3789print"<td class=\"link\">".3790$cgi->a({-href => href(action=>"blob",3791 hash_base=>$hash,3792 hash=>$from_hash,3793 file_name=>$from_path)},3794"blob". ($i+1)) .3795" | </td>\n";3796}else{3797if($diff->{'to_id'}eq$from_hash) {3798print"<td class=\"link nochange\">";3799}else{3800print"<td class=\"link\">";3801}3802print$cgi->a({-href => href(action=>"blobdiff",3803 hash=>$diff->{'to_id'},3804 hash_parent=>$from_hash,3805 hash_base=>$hash,3806 hash_parent_base=>$hash_parent,3807 file_name=>$diff->{'to_file'},3808 file_parent=>$from_path)},3809"diff". ($i+1)) .3810" | </td>\n";3811}3812}38133814print"<td class=\"link\">";3815if($not_deleted) {3816print$cgi->a({-href => href(action=>"blob",3817 hash=>$diff->{'to_id'},3818 file_name=>$diff->{'to_file'},3819 hash_base=>$hash)},3820"blob");3821print" | "if($has_history);3822}3823if($has_history) {3824print$cgi->a({-href => href(action=>"history",3825 file_name=>$diff->{'to_file'},3826 hash_base=>$hash)},3827"history");3828}3829print"</td>\n";38303831print"</tr>\n";3832next;# instead of 'else' clause, to avoid extra indent3833}3834# else ordinary diff38353836my($to_mode_oct,$to_mode_str,$to_file_type);3837my($from_mode_oct,$from_mode_str,$from_file_type);3838if($diff->{'to_mode'}ne('0' x 6)) {3839$to_mode_oct=oct$diff->{'to_mode'};3840if(S_ISREG($to_mode_oct)) {# only for regular file3841$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits3842}3843$to_file_type= file_type($diff->{'to_mode'});3844}3845if($diff->{'from_mode'}ne('0' x 6)) {3846$from_mode_oct=oct$diff->{'from_mode'};3847if(S_ISREG($to_mode_oct)) {# only for regular file3848$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits3849}3850$from_file_type= file_type($diff->{'from_mode'});3851}38523853if($diff->{'status'}eq"A") {# created3854my$mode_chng="<span class=\"file_status new\">[new$to_file_type";3855$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;3856$mode_chng.="]</span>";3857print"<td>";3858print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3859 hash_base=>$hash, file_name=>$diff->{'file'}),3860-class=>"list"}, esc_path($diff->{'file'}));3861print"</td>\n";3862print"<td>$mode_chng</td>\n";3863print"<td class=\"link\">";3864if($actioneq'commitdiff') {3865# link to patch3866$patchno++;3867print$cgi->a({-href =>"#patch$patchno"},"patch");3868print" | ";3869}3870print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3871 hash_base=>$hash, file_name=>$diff->{'file'})},3872"blob");3873print"</td>\n";38743875}elsif($diff->{'status'}eq"D") {# deleted3876my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";3877print"<td>";3878print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3879 hash_base=>$parent, file_name=>$diff->{'file'}),3880-class=>"list"}, esc_path($diff->{'file'}));3881print"</td>\n";3882print"<td>$mode_chng</td>\n";3883print"<td class=\"link\">";3884if($actioneq'commitdiff') {3885# link to patch3886$patchno++;3887print$cgi->a({-href =>"#patch$patchno"},"patch");3888print" | ";3889}3890print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3891 hash_base=>$parent, file_name=>$diff->{'file'})},3892"blob") ." | ";3893if($have_blame) {3894print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,3895 file_name=>$diff->{'file'})},3896"blame") ." | ";3897}3898print$cgi->a({-href => href(action=>"history", hash_base=>$parent,3899 file_name=>$diff->{'file'})},3900"history");3901print"</td>\n";39023903}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed3904my$mode_chnge="";3905if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3906$mode_chnge="<span class=\"file_status mode_chnge\">[changed";3907if($from_file_typene$to_file_type) {3908$mode_chnge.=" from$from_file_typeto$to_file_type";3909}3910if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {3911if($from_mode_str&&$to_mode_str) {3912$mode_chnge.=" mode:$from_mode_str->$to_mode_str";3913}elsif($to_mode_str) {3914$mode_chnge.=" mode:$to_mode_str";3915}3916}3917$mode_chnge.="]</span>\n";3918}3919print"<td>";3920print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3921 hash_base=>$hash, file_name=>$diff->{'file'}),3922-class=>"list"}, esc_path($diff->{'file'}));3923print"</td>\n";3924print"<td>$mode_chnge</td>\n";3925print"<td class=\"link\">";3926if($actioneq'commitdiff') {3927# link to patch3928$patchno++;3929print$cgi->a({-href =>"#patch$patchno"},"patch") .3930" | ";3931}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3932# "commit" view and modified file (not onlu mode changed)3933print$cgi->a({-href => href(action=>"blobdiff",3934 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3935 hash_base=>$hash, hash_parent_base=>$parent,3936 file_name=>$diff->{'file'})},3937"diff") .3938" | ";3939}3940print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3941 hash_base=>$hash, file_name=>$diff->{'file'})},3942"blob") ." | ";3943if($have_blame) {3944print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3945 file_name=>$diff->{'file'})},3946"blame") ." | ";3947}3948print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3949 file_name=>$diff->{'file'})},3950"history");3951print"</td>\n";39523953}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied3954my%status_name= ('R'=>'moved','C'=>'copied');3955my$nstatus=$status_name{$diff->{'status'}};3956my$mode_chng="";3957if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3958# mode also for directories, so we cannot use $to_mode_str3959$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);3960}3961print"<td>".3962$cgi->a({-href => href(action=>"blob", hash_base=>$hash,3963 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),3964-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".3965"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".3966$cgi->a({-href => href(action=>"blob", hash_base=>$parent,3967 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),3968-class=>"list"}, esc_path($diff->{'from_file'})) .3969" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".3970"<td class=\"link\">";3971if($actioneq'commitdiff') {3972# link to patch3973$patchno++;3974print$cgi->a({-href =>"#patch$patchno"},"patch") .3975" | ";3976}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3977# "commit" view and modified file (not only pure rename or copy)3978print$cgi->a({-href => href(action=>"blobdiff",3979 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3980 hash_base=>$hash, hash_parent_base=>$parent,3981 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},3982"diff") .3983" | ";3984}3985print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3986 hash_base=>$parent, file_name=>$diff->{'to_file'})},3987"blob") ." | ";3988if($have_blame) {3989print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3990 file_name=>$diff->{'to_file'})},3991"blame") ." | ";3992}3993print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3994 file_name=>$diff->{'to_file'})},3995"history");3996print"</td>\n";39973998}# we should not encounter Unmerged (U) or Unknown (X) status3999print"</tr>\n";4000}4001print"</tbody>"if$has_header;4002print"</table>\n";4003}40044005sub git_patchset_body {4006my($fd,$difftree,$hash,@hash_parents) =@_;4007my($hash_parent) =$hash_parents[0];40084009my$is_combined= (@hash_parents>1);4010my$patch_idx=0;4011my$patch_number=0;4012my$patch_line;4013my$diffinfo;4014my$to_name;4015my(%from,%to);40164017print"<div class=\"patchset\">\n";40184019# skip to first patch4020while($patch_line= <$fd>) {4021chomp$patch_line;40224023last if($patch_line=~m/^diff /);4024}40254026 PATCH:4027while($patch_line) {40284029# parse "git diff" header line4030if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {4031# $1 is from_name, which we do not use4032$to_name= unquote($2);4033$to_name=~s!^b/!!;4034}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {4035# $1 is 'cc' or 'combined', which we do not use4036$to_name= unquote($2);4037}else{4038$to_name=undef;4039}40404041# check if current patch belong to current raw line4042# and parse raw git-diff line if needed4043if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {4044# this is continuation of a split patch4045print"<div class=\"patch cont\">\n";4046}else{4047# advance raw git-diff output if needed4048$patch_idx++ifdefined$diffinfo;40494050# read and prepare patch information4051$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);40524053# compact combined diff output can have some patches skipped4054# find which patch (using pathname of result) we are at now;4055if($is_combined) {4056while($to_namene$diffinfo->{'to_file'}) {4057print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4058 format_diff_cc_simplified($diffinfo,@hash_parents) .4059"</div>\n";# class="patch"40604061$patch_idx++;4062$patch_number++;40634064last if$patch_idx>$#$difftree;4065$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);4066}4067}40684069# modifies %from, %to hashes4070 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);40714072# this is first patch for raw difftree line with $patch_idx index4073# we index @$difftree array from 0, but number patches from 14074print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";4075}40764077# git diff header4078#assert($patch_line =~ m/^diff /) if DEBUG;4079#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed4080$patch_number++;4081# print "git diff" header4082print format_git_diff_header_line($patch_line,$diffinfo,4083 \%from, \%to);40844085# print extended diff header4086print"<div class=\"diff extended_header\">\n";4087 EXTENDED_HEADER:4088while($patch_line= <$fd>) {4089chomp$patch_line;40904091last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);40924093print format_extended_diff_header_line($patch_line,$diffinfo,4094 \%from, \%to);4095}4096print"</div>\n";# class="diff extended_header"40974098# from-file/to-file diff header4099if(!$patch_line) {4100print"</div>\n";# class="patch"4101last PATCH;4102}4103next PATCH if($patch_line=~m/^diff /);4104#assert($patch_line =~ m/^---/) if DEBUG;41054106my$last_patch_line=$patch_line;4107$patch_line= <$fd>;4108chomp$patch_line;4109#assert($patch_line =~ m/^\+\+\+/) if DEBUG;41104111print format_diff_from_to_header($last_patch_line,$patch_line,4112$diffinfo, \%from, \%to,4113@hash_parents);41144115# the patch itself4116 LINE:4117while($patch_line= <$fd>) {4118chomp$patch_line;41194120next PATCH if($patch_line=~m/^diff /);41214122print format_diff_line($patch_line, \%from, \%to);4123}41244125}continue{4126print"</div>\n";# class="patch"4127}41284129# for compact combined (--cc) format, with chunk and patch simpliciaction4130# patchset might be empty, but there might be unprocessed raw lines4131for(++$patch_idxif$patch_number>0;4132$patch_idx<@$difftree;4133++$patch_idx) {4134# read and prepare patch information4135$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);41364137# generate anchor for "patch" links in difftree / whatchanged part4138print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4139 format_diff_cc_simplified($diffinfo,@hash_parents) .4140"</div>\n";# class="patch"41414142$patch_number++;4143}41444145if($patch_number==0) {4146if(@hash_parents>1) {4147print"<div class=\"diff nodifferences\">Trivial merge</div>\n";4148}else{4149print"<div class=\"diff nodifferences\">No differences found</div>\n";4150}4151}41524153print"</div>\n";# class="patchset"4154}41554156# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41574158# fills project list info (age, description, owner, forks) for each4159# project in the list, removing invalid projects from returned list4160# NOTE: modifies $projlist, but does not remove entries from it4161sub fill_project_list_info {4162my($projlist,$check_forks) =@_;4163my@projects;41644165my$show_ctags= gitweb_check_feature('ctags');4166 PROJECT:4167foreachmy$pr(@$projlist) {4168my(@activity) = git_get_last_activity($pr->{'path'});4169unless(@activity) {4170next PROJECT;4171}4172($pr->{'age'},$pr->{'age_string'}) =@activity;4173if(!defined$pr->{'descr'}) {4174my$descr= git_get_project_description($pr->{'path'}) ||"";4175$descr= to_utf8($descr);4176$pr->{'descr_long'} =$descr;4177$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4178}4179if(!defined$pr->{'owner'}) {4180$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4181}4182if($check_forks) {4183my$pname=$pr->{'path'};4184if(($pname=~s/\.git$//) &&4185($pname!~/\/$/) &&4186(-d "$projectroot/$pname")) {4187$pr->{'forks'} ="-d$projectroot/$pname";4188}else{4189$pr->{'forks'} =0;4190}4191}4192$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4193push@projects,$pr;4194}41954196return@projects;4197}41984199# print 'sort by' <th> element, generating 'sort by $name' replay link4200# if that order is not selected4201sub print_sort_th {4202my($name,$order,$header) =@_;4203$header||=ucfirst($name);42044205if($ordereq$name) {4206print"<th>$header</th>\n";4207}else{4208print"<th>".4209$cgi->a({-href => href(-replay=>1, order=>$name),4210-class=>"header"},$header) .4211"</th>\n";4212}4213}42144215sub git_project_list_body {4216# actually uses global variable $project4217my($projlist,$order,$from,$to,$extra,$no_header) =@_;42184219my$check_forks= gitweb_check_feature('forks');4220my@projects= fill_project_list_info($projlist,$check_forks);42214222$order||=$default_projects_order;4223$from=0unlessdefined$from;4224$to=$#projectsif(!defined$to||$#projects<$to);42254226my%order_info= (4227 project => { key =>'path', type =>'str'},4228 descr => { key =>'descr_long', type =>'str'},4229 owner => { key =>'owner', type =>'str'},4230 age => { key =>'age', type =>'num'}4231);4232my$oi=$order_info{$order};4233if($oi->{'type'}eq'str') {4234@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4235}else{4236@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4237}42384239my$show_ctags= gitweb_check_feature('ctags');4240if($show_ctags) {4241my%ctags;4242foreachmy$p(@projects) {4243foreachmy$ct(keys%{$p->{'ctags'}}) {4244$ctags{$ct} +=$p->{'ctags'}->{$ct};4245}4246}4247my$cloud= git_populate_project_tagcloud(\%ctags);4248print git_show_project_tagcloud($cloud,64);4249}42504251print"<table class=\"project_list\">\n";4252unless($no_header) {4253print"<tr>\n";4254if($check_forks) {4255print"<th></th>\n";4256}4257 print_sort_th('project',$order,'Project');4258 print_sort_th('descr',$order,'Description');4259 print_sort_th('owner',$order,'Owner');4260 print_sort_th('age',$order,'Last Change');4261print"<th></th>\n".# for links4262"</tr>\n";4263}4264my$alternate=1;4265my$tagfilter=$cgi->param('by_tag');4266for(my$i=$from;$i<=$to;$i++) {4267my$pr=$projects[$i];42684269next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4270next if$searchtextand not$pr->{'path'} =~/$searchtext/4271and not$pr->{'descr_long'} =~/$searchtext/;4272# Weed out forks or non-matching entries of search4273if($check_forks) {4274my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4275$forkbase="^$forkbase"if$forkbase;4276next ifnot$searchtextand not$tagfilterand$show_ctags4277and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4278}42794280if($alternate) {4281print"<tr class=\"dark\">\n";4282}else{4283print"<tr class=\"light\">\n";4284}4285$alternate^=1;4286if($check_forks) {4287print"<td>";4288if($pr->{'forks'}) {4289print"<!--$pr->{'forks'} -->\n";4290print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4291}4292print"</td>\n";4293}4294print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4295-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4296"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4297-class=>"list", -title =>$pr->{'descr_long'}},4298 esc_html($pr->{'descr'})) ."</td>\n".4299"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4300print"<td class=\"". age_class($pr->{'age'}) ."\">".4301(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4302"<td class=\"link\">".4303$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4304$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4305$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4306$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4307($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4308"</td>\n".4309"</tr>\n";4310}4311if(defined$extra) {4312print"<tr>\n";4313if($check_forks) {4314print"<td></td>\n";4315}4316print"<td colspan=\"5\">$extra</td>\n".4317"</tr>\n";4318}4319print"</table>\n";4320}43214322sub git_shortlog_body {4323# uses global variable $project4324my($commitlist,$from,$to,$refs,$extra) =@_;43254326$from=0unlessdefined$from;4327$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);43284329print"<table class=\"shortlog\">\n";4330my$alternate=1;4331for(my$i=$from;$i<=$to;$i++) {4332my%co= %{$commitlist->[$i]};4333my$commit=$co{'id'};4334my$ref= format_ref_marker($refs,$commit);4335if($alternate) {4336print"<tr class=\"dark\">\n";4337}else{4338print"<tr class=\"light\">\n";4339}4340$alternate^=1;4341# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4342print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4343 format_author_html('td', \%co,10) ."<td>";4344print format_subject_html($co{'title'},$co{'title_short'},4345 href(action=>"commit", hash=>$commit),$ref);4346print"</td>\n".4347"<td class=\"link\">".4348$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4349$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4350$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4351my$snapshot_links= format_snapshot_links($commit);4352if(defined$snapshot_links) {4353print" | ".$snapshot_links;4354}4355print"</td>\n".4356"</tr>\n";4357}4358if(defined$extra) {4359print"<tr>\n".4360"<td colspan=\"4\">$extra</td>\n".4361"</tr>\n";4362}4363print"</table>\n";4364}43654366sub git_history_body {4367# Warning: assumes constant type (blob or tree) during history4368my($commitlist,$from,$to,$refs,$hash_base,$ftype,$extra) =@_;43694370$from=0unlessdefined$from;4371$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});43724373print"<table class=\"history\">\n";4374my$alternate=1;4375for(my$i=$from;$i<=$to;$i++) {4376my%co= %{$commitlist->[$i]};4377if(!%co) {4378next;4379}4380my$commit=$co{'id'};43814382my$ref= format_ref_marker($refs,$commit);43834384if($alternate) {4385print"<tr class=\"dark\">\n";4386}else{4387print"<tr class=\"light\">\n";4388}4389$alternate^=1;4390print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4391# shortlog: format_author_html('td', \%co, 10)4392 format_author_html('td', \%co,15,3) ."<td>";4393# originally git_history used chop_str($co{'title'}, 50)4394print format_subject_html($co{'title'},$co{'title_short'},4395 href(action=>"commit", hash=>$commit),$ref);4396print"</td>\n".4397"<td class=\"link\">".4398$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4399$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");44004401if($ftypeeq'blob') {4402my$blob_current= git_get_hash_by_path($hash_base,$file_name);4403my$blob_parent= git_get_hash_by_path($commit,$file_name);4404if(defined$blob_current&&defined$blob_parent&&4405$blob_currentne$blob_parent) {4406print" | ".4407$cgi->a({-href => href(action=>"blobdiff",4408 hash=>$blob_current, hash_parent=>$blob_parent,4409 hash_base=>$hash_base, hash_parent_base=>$commit,4410 file_name=>$file_name)},4411"diff to current");4412}4413}4414print"</td>\n".4415"</tr>\n";4416}4417if(defined$extra) {4418print"<tr>\n".4419"<td colspan=\"4\">$extra</td>\n".4420"</tr>\n";4421}4422print"</table>\n";4423}44244425sub git_tags_body {4426# uses global variable $project4427my($taglist,$from,$to,$extra) =@_;4428$from=0unlessdefined$from;4429$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);44304431print"<table class=\"tags\">\n";4432my$alternate=1;4433for(my$i=$from;$i<=$to;$i++) {4434my$entry=$taglist->[$i];4435my%tag=%$entry;4436my$comment=$tag{'subject'};4437my$comment_short;4438if(defined$comment) {4439$comment_short= chop_str($comment,30,5);4440}4441if($alternate) {4442print"<tr class=\"dark\">\n";4443}else{4444print"<tr class=\"light\">\n";4445}4446$alternate^=1;4447if(defined$tag{'age'}) {4448print"<td><i>$tag{'age'}</i></td>\n";4449}else{4450print"<td></td>\n";4451}4452print"<td>".4453$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4454-class=>"list name"}, esc_html($tag{'name'})) .4455"</td>\n".4456"<td>";4457if(defined$comment) {4458print format_subject_html($comment,$comment_short,4459 href(action=>"tag", hash=>$tag{'id'}));4460}4461print"</td>\n".4462"<td class=\"selflink\">";4463if($tag{'type'}eq"tag") {4464print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4465}else{4466print" ";4467}4468print"</td>\n".4469"<td class=\"link\">"." | ".4470$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4471if($tag{'reftype'}eq"commit") {4472print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4473" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4474}elsif($tag{'reftype'}eq"blob") {4475print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4476}4477print"</td>\n".4478"</tr>";4479}4480if(defined$extra) {4481print"<tr>\n".4482"<td colspan=\"5\">$extra</td>\n".4483"</tr>\n";4484}4485print"</table>\n";4486}44874488sub git_heads_body {4489# uses global variable $project4490my($headlist,$head,$from,$to,$extra) =@_;4491$from=0unlessdefined$from;4492$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);44934494print"<table class=\"heads\">\n";4495my$alternate=1;4496for(my$i=$from;$i<=$to;$i++) {4497my$entry=$headlist->[$i];4498my%ref=%$entry;4499my$curr=$ref{'id'}eq$head;4500if($alternate) {4501print"<tr class=\"dark\">\n";4502}else{4503print"<tr class=\"light\">\n";4504}4505$alternate^=1;4506print"<td><i>$ref{'age'}</i></td>\n".4507($curr?"<td class=\"current_head\">":"<td>") .4508$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4509-class=>"list name"},esc_html($ref{'name'})) .4510"</td>\n".4511"<td class=\"link\">".4512$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4513$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4514$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4515"</td>\n".4516"</tr>";4517}4518if(defined$extra) {4519print"<tr>\n".4520"<td colspan=\"3\">$extra</td>\n".4521"</tr>\n";4522}4523print"</table>\n";4524}45254526sub git_search_grep_body {4527my($commitlist,$from,$to,$extra) =@_;4528$from=0unlessdefined$from;4529$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);45304531print"<table class=\"commit_search\">\n";4532my$alternate=1;4533for(my$i=$from;$i<=$to;$i++) {4534my%co= %{$commitlist->[$i]};4535if(!%co) {4536next;4537}4538my$commit=$co{'id'};4539if($alternate) {4540print"<tr class=\"dark\">\n";4541}else{4542print"<tr class=\"light\">\n";4543}4544$alternate^=1;4545print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4546 format_author_html('td', \%co,15,5) .4547"<td>".4548$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4549-class=>"list subject"},4550 chop_and_escape_str($co{'title'},50) ."<br/>");4551my$comment=$co{'comment'};4552foreachmy$line(@$comment) {4553if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4554my($lead,$match,$trail) = ($1,$2,$3);4555$match= chop_str($match,70,5,'center');4556my$contextlen=int((80-length($match))/2);4557$contextlen=30if($contextlen>30);4558$lead= chop_str($lead,$contextlen,10,'left');4559$trail= chop_str($trail,$contextlen,10,'right');45604561$lead= esc_html($lead);4562$match= esc_html($match);4563$trail= esc_html($trail);45644565print"$lead<span class=\"match\">$match</span>$trail<br />";4566}4567}4568print"</td>\n".4569"<td class=\"link\">".4570$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4571" | ".4572$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4573" | ".4574$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4575print"</td>\n".4576"</tr>\n";4577}4578if(defined$extra) {4579print"<tr>\n".4580"<td colspan=\"3\">$extra</td>\n".4581"</tr>\n";4582}4583print"</table>\n";4584}45854586## ======================================================================4587## ======================================================================4588## actions45894590sub git_project_list {4591my$order=$input_params{'order'};4592if(defined$order&&$order!~m/none|project|descr|owner|age/) {4593 die_error(400,"Unknown order parameter");4594}45954596my@list= git_get_projects_list();4597if(!@list) {4598 die_error(404,"No projects found");4599}46004601 git_header_html();4602if(-f $home_text) {4603print"<div class=\"index_include\">\n";4604 insert_file($home_text);4605print"</div>\n";4606}4607print$cgi->startform(-method=>"get") .4608"<p class=\"projsearch\">Search:\n".4609$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4610"</p>".4611$cgi->end_form() ."\n";4612 git_project_list_body(\@list,$order);4613 git_footer_html();4614}46154616sub git_forks {4617my$order=$input_params{'order'};4618if(defined$order&&$order!~m/none|project|descr|owner|age/) {4619 die_error(400,"Unknown order parameter");4620}46214622my@list= git_get_projects_list($project);4623if(!@list) {4624 die_error(404,"No forks found");4625}46264627 git_header_html();4628 git_print_page_nav('','');4629 git_print_header_div('summary',"$projectforks");4630 git_project_list_body(\@list,$order);4631 git_footer_html();4632}46334634sub git_project_index {4635my@projects= git_get_projects_list($project);46364637print$cgi->header(4638-type =>'text/plain',4639-charset =>'utf-8',4640-content_disposition =>'inline; filename="index.aux"');46414642foreachmy$pr(@projects) {4643if(!exists$pr->{'owner'}) {4644$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4645}46464647my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4648# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4649$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4650$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4651$path=~s/ /\+/g;4652$owner=~s/ /\+/g;46534654print"$path$owner\n";4655}4656}46574658sub git_summary {4659my$descr= git_get_project_description($project) ||"none";4660my%co= parse_commit("HEAD");4661my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4662my$head=$co{'id'};46634664my$owner= git_get_project_owner($project);46654666my$refs= git_get_references();4667# These get_*_list functions return one more to allow us to see if4668# there are more ...4669my@taglist= git_get_tags_list(16);4670my@headlist= git_get_heads_list(16);4671my@forklist;4672my$check_forks= gitweb_check_feature('forks');46734674if($check_forks) {4675@forklist= git_get_projects_list($project);4676}46774678 git_header_html();4679 git_print_page_nav('summary','',$head);46804681print"<div class=\"title\"> </div>\n";4682print"<table class=\"projects_list\">\n".4683"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4684"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4685if(defined$cd{'rfc2822'}) {4686print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4687}46884689# use per project git URL list in $projectroot/$project/cloneurl4690# or make project git URL from git base URL and project name4691my$url_tag="URL";4692my@url_list= git_get_project_url_list($project);4693@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4694foreachmy$git_url(@url_list) {4695next unless$git_url;4696print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4697$url_tag="";4698}46994700# Tag cloud4701my$show_ctags= gitweb_check_feature('ctags');4702if($show_ctags) {4703my$ctags= git_get_project_ctags($project);4704my$cloud= git_populate_project_tagcloud($ctags);4705print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4706print"</td>\n<td>"unless%$ctags;4707print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4708print"</td>\n<td>"if%$ctags;4709print git_show_project_tagcloud($cloud,48);4710print"</td></tr>";4711}47124713print"</table>\n";47144715# If XSS prevention is on, we don't include README.html.4716# TODO: Allow a readme in some safe format.4717if(!$prevent_xss&& -s "$projectroot/$project/README.html") {4718print"<div class=\"title\">readme</div>\n".4719"<div class=\"readme\">\n";4720 insert_file("$projectroot/$project/README.html");4721print"\n</div>\n";# class="readme"4722}47234724# we need to request one more than 16 (0..15) to check if4725# those 16 are all4726my@commitlist=$head? parse_commits($head,17) : ();4727if(@commitlist) {4728 git_print_header_div('shortlog');4729 git_shortlog_body(\@commitlist,0,15,$refs,4730$#commitlist<=15?undef:4731$cgi->a({-href => href(action=>"shortlog")},"..."));4732}47334734if(@taglist) {4735 git_print_header_div('tags');4736 git_tags_body(\@taglist,0,15,4737$#taglist<=15?undef:4738$cgi->a({-href => href(action=>"tags")},"..."));4739}47404741if(@headlist) {4742 git_print_header_div('heads');4743 git_heads_body(\@headlist,$head,0,15,4744$#headlist<=15?undef:4745$cgi->a({-href => href(action=>"heads")},"..."));4746}47474748if(@forklist) {4749 git_print_header_div('forks');4750 git_project_list_body(\@forklist,'age',0,15,4751$#forklist<=15?undef:4752$cgi->a({-href => href(action=>"forks")},"..."),4753'no_header');4754}47554756 git_footer_html();4757}47584759sub git_tag {4760my$head= git_get_head_hash($project);4761 git_header_html();4762 git_print_page_nav('','',$head,undef,$head);4763my%tag= parse_tag($hash);47644765if(!%tag) {4766 die_error(404,"Unknown tag object");4767}47684769 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4770print"<div class=\"title_text\">\n".4771"<table class=\"object_header\">\n".4772"<tr>\n".4773"<td>object</td>\n".4774"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4775$tag{'object'}) ."</td>\n".4776"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4777$tag{'type'}) ."</td>\n".4778"</tr>\n";4779if(defined($tag{'author'})) {4780 git_print_authorship_rows(\%tag,'author');4781}4782print"</table>\n\n".4783"</div>\n";4784print"<div class=\"page_body\">";4785my$comment=$tag{'comment'};4786foreachmy$line(@$comment) {4787chomp$line;4788print esc_html($line, -nbsp=>1) ."<br/>\n";4789}4790print"</div>\n";4791 git_footer_html();4792}47934794sub git_blame_common {4795my$format=shift||'porcelain';47964797# permissions4798 gitweb_check_feature('blame')4799or die_error(403,"Blame view not allowed");48004801# error checking4802 die_error(400,"No file name given")unless$file_name;4803$hash_base||= git_get_head_hash($project);4804 die_error(404,"Couldn't find base commit")unless$hash_base;4805my%co= parse_commit($hash_base)4806or die_error(404,"Commit not found");4807my$ftype="blob";4808if(!defined$hash) {4809$hash= git_get_hash_by_path($hash_base,$file_name,"blob")4810or die_error(404,"Error looking up file");4811}else{4812$ftype= git_get_type($hash);4813if($ftype!~"blob") {4814 die_error(400,"Object is not a blob");4815}4816}48174818my$fd;4819if($formateq'incremental') {4820# get file contents (as base)4821open$fd,"-|", git_cmd(),'cat-file','blob',$hash4822or die_error(500,"Open git-cat-file failed");4823}elsif($formateq'data') {4824# run git-blame --incremental4825open$fd,"-|", git_cmd(),"blame","--incremental",4826$hash_base,"--",$file_name4827or die_error(500,"Open git-blame --incremental failed");4828}else{4829# run git-blame --porcelain4830open$fd,"-|", git_cmd(),"blame",'-p',4831$hash_base,'--',$file_name4832or die_error(500,"Open git-blame --porcelain failed");4833}48344835# incremental blame data returns early4836if($formateq'data') {4837print$cgi->header(4838-type=>"text/plain", -charset =>"utf-8",4839-status=>"200 OK");4840local$| =1;# output autoflush4841printwhile<$fd>;4842close$fd4843or print"ERROR$!\n";48444845print'END';4846if(defined$t0&& gitweb_check_feature('timed')) {4847print' '.4848 Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).4849' '.$number_of_git_cmds;4850}4851print"\n";48524853return;4854}48554856# page header4857 git_header_html();4858my$formats_nav=4859$cgi->a({-href => href(action=>"blob", -replay=>1)},4860"blob") .4861" | ".4862$cgi->a({-href => href(action=>"history", -replay=>1)},4863"history") .4864" | ".4865$cgi->a({-href => href(action=>$action, file_name=>$file_name)},4866"HEAD");4867 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4868 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4869 git_print_page_path($file_name,$ftype,$hash_base);48704871# page body4872if($formateq'incremental') {4873print"<noscript>\n<div class=\"error\"><center><b>\n".4874"This page requires JavaScript to run.\nUse ".4875$cgi->a({-href => href(action=>'blame',-replay=>1)},4876'this page').4877" instead.\n".4878"</b></center></div>\n</noscript>\n";48794880print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!;4881}48824883print qq!<div class="page_body">\n!;4884print qq!<div id="progress_info">.../ ...</div>\n!4885if($formateq'incremental');4886print qq!<table id="blame_table"class="blame" width="100%">\n!.4887#qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.4888 qq!<thead>\n!.4889 qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!.4890 qq!</thead>\n!.4891 qq!<tbody>\n!;48924893my@rev_color=qw(light dark);4894my$num_colors=scalar(@rev_color);4895my$current_color=0;48964897if($formateq'incremental') {4898my$color_class=$rev_color[$current_color];48994900#contents of a file4901my$linenr=0;4902 LINE:4903while(my$line= <$fd>) {4904chomp$line;4905$linenr++;49064907print qq!<tr id="l$linenr"class="$color_class">!.4908 qq!<td class="sha1"><a href=""> </a></td>!.4909 qq!<td class="linenr">!.4910 qq!<a class="linenr" href="">$linenr</a></td>!;4911print qq!<td class="pre">! . esc_html($line) ."</td>\n";4912print qq!</tr>\n!;4913}49144915}else{# porcelain, i.e. ordinary blame4916my%metainfo= ();# saves information about commits49174918# blame data4919 LINE:4920while(my$line= <$fd>) {4921chomp$line;4922# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]4923# no <lines in group> for subsequent lines in group of lines4924my($full_rev,$orig_lineno,$lineno,$group_size) =4925($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);4926if(!exists$metainfo{$full_rev}) {4927$metainfo{$full_rev} = {'nprevious'=>0};4928}4929my$meta=$metainfo{$full_rev};4930my$data;4931while($data= <$fd>) {4932chomp$data;4933last if($data=~s/^\t//);# contents of line4934if($data=~/^(\S+)(?: (.*))?$/) {4935$meta->{$1} =$2unlessexists$meta->{$1};4936}4937if($data=~/^previous /) {4938$meta->{'nprevious'}++;4939}4940}4941my$short_rev=substr($full_rev,0,8);4942my$author=$meta->{'author'};4943my%date=4944 parse_date($meta->{'author-time'},$meta->{'author-tz'});4945my$date=$date{'iso-tz'};4946if($group_size) {4947$current_color= ($current_color+1) %$num_colors;4948}4949my$tr_class=$rev_color[$current_color];4950$tr_class.=' boundary'if(exists$meta->{'boundary'});4951$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);4952$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);4953print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";4954if($group_size) {4955print"<td class=\"sha1\"";4956print" title=\"". esc_html($author) .",$date\"";4957print" rowspan=\"$group_size\""if($group_size>1);4958print">";4959print$cgi->a({-href => href(action=>"commit",4960 hash=>$full_rev,4961 file_name=>$file_name)},4962 esc_html($short_rev));4963if($group_size>=2) {4964my@author_initials= ($author=~/\b([[:upper:]])\B/g);4965if(@author_initials) {4966print"<br />".4967 esc_html(join('',@author_initials));4968# or join('.', ...)4969}4970}4971print"</td>\n";4972}4973# 'previous' <sha1 of parent commit> <filename at commit>4974if(exists$meta->{'previous'} &&4975$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {4976$meta->{'parent'} =$1;4977$meta->{'file_parent'} = unquote($2);4978}4979my$linenr_commit=4980exists($meta->{'parent'}) ?4981$meta->{'parent'} :$full_rev;4982my$linenr_filename=4983exists($meta->{'file_parent'}) ?4984$meta->{'file_parent'} : unquote($meta->{'filename'});4985my$blamed= href(action =>'blame',4986 file_name =>$linenr_filename,4987 hash_base =>$linenr_commit);4988print"<td class=\"linenr\">";4989print$cgi->a({ -href =>"$blamed#l$orig_lineno",4990-class=>"linenr"},4991 esc_html($lineno));4992print"</td>";4993print"<td class=\"pre\">". esc_html($data) ."</td>\n";4994print"</tr>\n";4995}# end while49964997}49984999# footer5000print"</tbody>\n".5001"</table>\n";# class="blame"5002print"</div>\n";# class="blame_body"5003close$fd5004or print"Reading blob failed\n";50055006if($formateq'incremental') {5007print qq!<script type="text/javascript" src="$javascript"></script>\n!.5008 qq!<script type="text/javascript">\n!.5009 qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.5010 qq!"!. href() .qq!");\n!.5011 qq!</script>\n!;5012}50135014 git_footer_html();5015}50165017sub git_blame {5018 git_blame_common();5019}50205021sub git_blame_incremental {5022 git_blame_common('incremental');5023}50245025sub git_blame_data {5026 git_blame_common('data');5027}50285029sub git_tags {5030my$head= git_get_head_hash($project);5031 git_header_html();5032 git_print_page_nav('','',$head,undef,$head);5033 git_print_header_div('summary',$project);50345035my@tagslist= git_get_tags_list();5036if(@tagslist) {5037 git_tags_body(\@tagslist);5038}5039 git_footer_html();5040}50415042sub git_heads {5043my$head= git_get_head_hash($project);5044 git_header_html();5045 git_print_page_nav('','',$head,undef,$head);5046 git_print_header_div('summary',$project);50475048my@headslist= git_get_heads_list();5049if(@headslist) {5050 git_heads_body(\@headslist,$head);5051}5052 git_footer_html();5053}50545055sub git_blob_plain {5056my$type=shift;5057my$expires;50585059if(!defined$hash) {5060if(defined$file_name) {5061my$base=$hash_base|| git_get_head_hash($project);5062$hash= git_get_hash_by_path($base,$file_name,"blob")5063or die_error(404,"Cannot find file");5064}else{5065 die_error(400,"No file name defined");5066}5067}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5068# blobs defined by non-textual hash id's can be cached5069$expires="+1d";5070}50715072open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5073or die_error(500,"Open git-cat-file blob '$hash' failed");50745075# content-type (can include charset)5076$type= blob_contenttype($fd,$file_name,$type);50775078# "save as" filename, even when no $file_name is given5079my$save_as="$hash";5080if(defined$file_name) {5081$save_as=$file_name;5082}elsif($type=~m/^text\//) {5083$save_as.='.txt';5084}50855086# With XSS prevention on, blobs of all types except a few known safe5087# ones are served with "Content-Disposition: attachment" to make sure5088# they don't run in our security domain. For certain image types,5089# blob view writes an <img> tag referring to blob_plain view, and we5090# want to be sure not to break that by serving the image as an5091# attachment (though Firefox 3 doesn't seem to care).5092my$sandbox=$prevent_xss&&5093$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;50945095print$cgi->header(5096-type =>$type,5097-expires =>$expires,5098-content_disposition =>5099($sandbox?'attachment':'inline')5100.'; filename="'.$save_as.'"');5101local$/=undef;5102binmode STDOUT,':raw';5103print<$fd>;5104binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5105close$fd;5106}51075108sub git_blob {5109my$expires;51105111if(!defined$hash) {5112if(defined$file_name) {5113my$base=$hash_base|| git_get_head_hash($project);5114$hash= git_get_hash_by_path($base,$file_name,"blob")5115or die_error(404,"Cannot find file");5116}else{5117 die_error(400,"No file name defined");5118}5119}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5120# blobs defined by non-textual hash id's can be cached5121$expires="+1d";5122}51235124my$have_blame= gitweb_check_feature('blame');5125open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5126or die_error(500,"Couldn't cat$file_name,$hash");5127my$mimetype= blob_mimetype($fd,$file_name);5128if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {5129close$fd;5130return git_blob_plain($mimetype);5131}5132# we can have blame only for text/* mimetype5133$have_blame&&= ($mimetype=~m!^text/!);51345135 git_header_html(undef,$expires);5136my$formats_nav='';5137if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5138if(defined$file_name) {5139if($have_blame) {5140$formats_nav.=5141$cgi->a({-href => href(action=>"blame", -replay=>1)},5142"blame") .5143" | ";5144}5145$formats_nav.=5146$cgi->a({-href => href(action=>"history", -replay=>1)},5147"history") .5148" | ".5149$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5150"raw") .5151" | ".5152$cgi->a({-href => href(action=>"blob",5153 hash_base=>"HEAD", file_name=>$file_name)},5154"HEAD");5155}else{5156$formats_nav.=5157$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5158"raw");5159}5160 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5161 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5162}else{5163print"<div class=\"page_nav\">\n".5164"<br/><br/></div>\n".5165"<div class=\"title\">$hash</div>\n";5166}5167 git_print_page_path($file_name,"blob",$hash_base);5168print"<div class=\"page_body\">\n";5169if($mimetype=~m!^image/!) {5170print qq!<img type="$mimetype"!;5171if($file_name) {5172print qq! alt="$file_name" title="$file_name"!;5173}5174print qq! src="! .5175 href(action=>"blob_plain", hash=>$hash,5176 hash_base=>$hash_base, file_name=>$file_name) .5177 qq!"/>\n!;5178}else{5179my$nr;5180while(my$line= <$fd>) {5181chomp$line;5182$nr++;5183$line= untabify($line);5184printf"<div class=\"pre\"><a id=\"l%i\"href=\"#l%i\"class=\"linenr\">%4i</a>%s</div>\n",5185$nr,$nr,$nr, esc_html($line, -nbsp=>1);5186}5187}5188close$fd5189or print"Reading blob failed.\n";5190print"</div>";5191 git_footer_html();5192}51935194sub git_tree {5195if(!defined$hash_base) {5196$hash_base="HEAD";5197}5198if(!defined$hash) {5199if(defined$file_name) {5200$hash= git_get_hash_by_path($hash_base,$file_name,"tree");5201}else{5202$hash=$hash_base;5203}5204}5205 die_error(404,"No such tree")unlessdefined($hash);52065207my@entries= ();5208{5209local$/="\0";5210open my$fd,"-|", git_cmd(),"ls-tree",'-z',$hash5211or die_error(500,"Open git-ls-tree failed");5212@entries=map{chomp;$_} <$fd>;5213close$fd5214or die_error(404,"Reading tree failed");5215}52165217my$refs= git_get_references();5218my$ref= format_ref_marker($refs,$hash_base);5219 git_header_html();5220my$basedir='';5221my$have_blame= gitweb_check_feature('blame');5222if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5223my@views_nav= ();5224if(defined$file_name) {5225push@views_nav,5226$cgi->a({-href => href(action=>"history", -replay=>1)},5227"history"),5228$cgi->a({-href => href(action=>"tree",5229 hash_base=>"HEAD", file_name=>$file_name)},5230"HEAD"),5231}5232my$snapshot_links= format_snapshot_links($hash);5233if(defined$snapshot_links) {5234# FIXME: Should be available when we have no hash base as well.5235push@views_nav,$snapshot_links;5236}5237 git_print_page_nav('tree','',$hash_base,undef,undef,join(' | ',@views_nav));5238 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);5239}else{5240undef$hash_base;5241print"<div class=\"page_nav\">\n";5242print"<br/><br/></div>\n";5243print"<div class=\"title\">$hash</div>\n";5244}5245if(defined$file_name) {5246$basedir=$file_name;5247if($basedirne''&&substr($basedir, -1)ne'/') {5248$basedir.='/';5249}5250 git_print_page_path($file_name,'tree',$hash_base);5251}5252print"<div class=\"page_body\">\n";5253print"<table class=\"tree\">\n";5254my$alternate=1;5255# '..' (top directory) link if possible5256if(defined$hash_base&&5257defined$file_name&&$file_name=~m![^/]+$!) {5258if($alternate) {5259print"<tr class=\"dark\">\n";5260}else{5261print"<tr class=\"light\">\n";5262}5263$alternate^=1;52645265my$up=$file_name;5266$up=~s!/?[^/]+$!!;5267undef$upunless$up;5268# based on git_print_tree_entry5269print'<td class="mode">'. mode_str('040000') ."</td>\n";5270print'<td class="list">';5271print$cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,5272 file_name=>$up)},5273"..");5274print"</td>\n";5275print"<td class=\"link\"></td>\n";52765277print"</tr>\n";5278}5279foreachmy$line(@entries) {5280my%t= parse_ls_tree_line($line, -z =>1);52815282if($alternate) {5283print"<tr class=\"dark\">\n";5284}else{5285print"<tr class=\"light\">\n";5286}5287$alternate^=1;52885289 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);52905291print"</tr>\n";5292}5293print"</table>\n".5294"</div>";5295 git_footer_html();5296}52975298sub git_snapshot {5299my$format=$input_params{'snapshot_format'};5300if(!@snapshot_fmts) {5301 die_error(403,"Snapshots not allowed");5302}5303# default to first supported snapshot format5304$format||=$snapshot_fmts[0];5305if($format!~m/^[a-z0-9]+$/) {5306 die_error(400,"Invalid snapshot format parameter");5307}elsif(!exists($known_snapshot_formats{$format})) {5308 die_error(400,"Unknown snapshot format");5309}elsif(!grep($_eq$format,@snapshot_fmts)) {5310 die_error(403,"Unsupported snapshot format");5311}53125313if(!defined$hash) {5314$hash= git_get_head_hash($project);5315}53165317my$name=$project;5318$name=~ s,([^/])/*\.git$,$1,;5319$name= basename($name);5320my$filename= to_utf8($name);5321$name=~s/\047/\047\\\047\047/g;5322my$cmd;5323$filename.="-$hash$known_snapshot_formats{$format}{'suffix'}";5324$cmd= quote_command(5325 git_cmd(),'archive',5326"--format=$known_snapshot_formats{$format}{'format'}",5327"--prefix=$name/",$hash);5328if(exists$known_snapshot_formats{$format}{'compressor'}) {5329$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});5330}53315332print$cgi->header(5333-type =>$known_snapshot_formats{$format}{'type'},5334-content_disposition =>'inline; filename="'."$filename".'"',5335-status =>'200 OK');53365337open my$fd,"-|",$cmd5338or die_error(500,"Execute git-archive failed");5339binmode STDOUT,':raw';5340print<$fd>;5341binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5342close$fd;5343}53445345sub git_log {5346my$head= git_get_head_hash($project);5347if(!defined$hash) {5348$hash=$head;5349}5350if(!defined$page) {5351$page=0;5352}5353my$refs= git_get_references();53545355my@commitlist= parse_commits($hash,101, (100*$page));53565357my$paging_nav= format_paging_nav('log',$hash,$head,$page,$#commitlist>=100);53585359my($patch_max) = gitweb_get_feature('patches');5360if($patch_max) {5361if($patch_max<0||@commitlist<=$patch_max) {5362$paging_nav.=" ⋅ ".5363$cgi->a({-href => href(action=>"patches", -replay=>1)},5364"patches");5365}5366}53675368 git_header_html();5369 git_print_page_nav('log','',$hash,undef,undef,$paging_nav);53705371if(!@commitlist) {5372my%co= parse_commit($hash);53735374 git_print_header_div('summary',$project);5375print"<div class=\"page_body\"> Last change$co{'age_string'}.<br/><br/></div>\n";5376}5377my$to= ($#commitlist>=99) ? (99) : ($#commitlist);5378for(my$i=0;$i<=$to;$i++) {5379my%co= %{$commitlist[$i]};5380next if!%co;5381my$commit=$co{'id'};5382my$ref= format_ref_marker($refs,$commit);5383my%ad= parse_date($co{'author_epoch'});5384 git_print_header_div('commit',5385"<span class=\"age\">$co{'age_string'}</span>".5386 esc_html($co{'title'}) .$ref,5387$commit);5388print"<div class=\"title_text\">\n".5389"<div class=\"log_link\">\n".5390$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .5391" | ".5392$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .5393" | ".5394$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .5395"<br/>\n".5396"</div>\n";5397 git_print_authorship(\%co, -tag =>'span');5398print"<br/>\n</div>\n";53995400print"<div class=\"log_body\">\n";5401 git_print_log($co{'comment'}, -final_empty_line=>1);5402print"</div>\n";5403}5404if($#commitlist>=100) {5405print"<div class=\"page_nav\">\n";5406print$cgi->a({-href => href(-replay=>1, page=>$page+1),5407-accesskey =>"n", -title =>"Alt-n"},"next");5408print"</div>\n";5409}5410 git_footer_html();5411}54125413sub git_commit {5414$hash||=$hash_base||"HEAD";5415my%co= parse_commit($hash)5416or die_error(404,"Unknown commit object");54175418my$parent=$co{'parent'};5419my$parents=$co{'parents'};# listref54205421# we need to prepare $formats_nav before any parameter munging5422my$formats_nav;5423if(!defined$parent) {5424# --root commitdiff5425$formats_nav.='(initial)';5426}elsif(@$parents==1) {5427# single parent commit5428$formats_nav.=5429'(parent: '.5430$cgi->a({-href => href(action=>"commit",5431 hash=>$parent)},5432 esc_html(substr($parent,0,7))) .5433')';5434}else{5435# merge commit5436$formats_nav.=5437'(merge: '.5438join(' ',map{5439$cgi->a({-href => href(action=>"commit",5440 hash=>$_)},5441 esc_html(substr($_,0,7)));5442}@$parents) .5443')';5444}5445if(gitweb_check_feature('patches')) {5446$formats_nav.=" | ".5447$cgi->a({-href => href(action=>"patch", -replay=>1)},5448"patch");5449}54505451if(!defined$parent) {5452$parent="--root";5453}5454my@difftree;5455open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5456@diff_opts,5457(@$parents<=1?$parent:'-c'),5458$hash,"--"5459or die_error(500,"Open git-diff-tree failed");5460@difftree=map{chomp;$_} <$fd>;5461close$fdor die_error(404,"Reading git-diff-tree failed");54625463# non-textual hash id's can be cached5464my$expires;5465if($hash=~m/^[0-9a-fA-F]{40}$/) {5466$expires="+1d";5467}5468my$refs= git_get_references();5469my$ref= format_ref_marker($refs,$co{'id'});54705471 git_header_html(undef,$expires);5472 git_print_page_nav('commit','',5473$hash,$co{'tree'},$hash,5474$formats_nav);54755476if(defined$co{'parent'}) {5477 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5478}else{5479 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5480}5481print"<div class=\"title_text\">\n".5482"<table class=\"object_header\">\n";5483 git_print_authorship_rows(\%co);5484print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";5485print"<tr>".5486"<td>tree</td>".5487"<td class=\"sha1\">".5488$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),5489class=>"list"},$co{'tree'}) .5490"</td>".5491"<td class=\"link\">".5492$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},5493"tree");5494my$snapshot_links= format_snapshot_links($hash);5495if(defined$snapshot_links) {5496print" | ".$snapshot_links;5497}5498print"</td>".5499"</tr>\n";55005501foreachmy$par(@$parents) {5502print"<tr>".5503"<td>parent</td>".5504"<td class=\"sha1\">".5505$cgi->a({-href => href(action=>"commit", hash=>$par),5506class=>"list"},$par) .5507"</td>".5508"<td class=\"link\">".5509$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .5510" | ".5511$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .5512"</td>".5513"</tr>\n";5514}5515print"</table>".5516"</div>\n";55175518print"<div class=\"page_body\">\n";5519 git_print_log($co{'comment'});5520print"</div>\n";55215522 git_difftree_body(\@difftree,$hash,@$parents);55235524 git_footer_html();5525}55265527sub git_object {5528# object is defined by:5529# - hash or hash_base alone5530# - hash_base and file_name5531my$type;55325533# - hash or hash_base alone5534if($hash|| ($hash_base&& !defined$file_name)) {5535my$object_id=$hash||$hash_base;55365537open my$fd,"-|", quote_command(5538 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'5539or die_error(404,"Object does not exist");5540$type= <$fd>;5541chomp$type;5542close$fd5543or die_error(404,"Object does not exist");55445545# - hash_base and file_name5546}elsif($hash_base&&defined$file_name) {5547$file_name=~ s,/+$,,;55485549system(git_cmd(),"cat-file",'-e',$hash_base) ==05550or die_error(404,"Base object does not exist");55515552# here errors should not hapen5553open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name5554or die_error(500,"Open git-ls-tree failed");5555my$line= <$fd>;5556close$fd;55575558#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'5559unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {5560 die_error(404,"File or directory for given base does not exist");5561}5562$type=$2;5563$hash=$3;5564}else{5565 die_error(400,"Not enough information to find object");5566}55675568print$cgi->redirect(-uri => href(action=>$type, -full=>1,5569 hash=>$hash, hash_base=>$hash_base,5570 file_name=>$file_name),5571-status =>'302 Found');5572}55735574sub git_blobdiff {5575my$format=shift||'html';55765577my$fd;5578my@difftree;5579my%diffinfo;5580my$expires;55815582# preparing $fd and %diffinfo for git_patchset_body5583# new style URI5584if(defined$hash_base&&defined$hash_parent_base) {5585if(defined$file_name) {5586# read raw output5587open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5588$hash_parent_base,$hash_base,5589"--", (defined$file_parent?$file_parent: ()),$file_name5590or die_error(500,"Open git-diff-tree failed");5591@difftree=map{chomp;$_} <$fd>;5592close$fd5593or die_error(404,"Reading git-diff-tree failed");5594@difftree5595or die_error(404,"Blob diff not found");55965597}elsif(defined$hash&&5598$hash=~/[0-9a-fA-F]{40}/) {5599# try to find filename from $hash56005601# read filtered raw output5602open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5603$hash_parent_base,$hash_base,"--"5604or die_error(500,"Open git-diff-tree failed");5605@difftree=5606# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5607# $hash == to_id5608grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5609map{chomp;$_} <$fd>;5610close$fd5611or die_error(404,"Reading git-diff-tree failed");5612@difftree5613or die_error(404,"Blob diff not found");56145615}else{5616 die_error(400,"Missing one of the blob diff parameters");5617}56185619if(@difftree>1) {5620 die_error(400,"Ambiguous blob diff specification");5621}56225623%diffinfo= parse_difftree_raw_line($difftree[0]);5624$file_parent||=$diffinfo{'from_file'} ||$file_name;5625$file_name||=$diffinfo{'to_file'};56265627$hash_parent||=$diffinfo{'from_id'};5628$hash||=$diffinfo{'to_id'};56295630# non-textual hash id's can be cached5631if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5632$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5633$expires='+1d';5634}56355636# open patch output5637open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5638'-p', ($formateq'html'?"--full-index": ()),5639$hash_parent_base,$hash_base,5640"--", (defined$file_parent?$file_parent: ()),$file_name5641or die_error(500,"Open git-diff-tree failed");5642}56435644# old/legacy style URI -- not generated anymore since 1.4.3.5645if(!%diffinfo) {5646 die_error('404 Not Found',"Missing one of the blob diff parameters")5647}56485649# header5650if($formateq'html') {5651my$formats_nav=5652$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5653"raw");5654 git_header_html(undef,$expires);5655if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5656 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5657 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5658}else{5659print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5660print"<div class=\"title\">$hashvs$hash_parent</div>\n";5661}5662if(defined$file_name) {5663 git_print_page_path($file_name,"blob",$hash_base);5664}else{5665print"<div class=\"page_path\"></div>\n";5666}56675668}elsif($formateq'plain') {5669print$cgi->header(5670-type =>'text/plain',5671-charset =>'utf-8',5672-expires =>$expires,5673-content_disposition =>'inline; filename="'."$file_name".'.patch"');56745675print"X-Git-Url: ".$cgi->self_url() ."\n\n";56765677}else{5678 die_error(400,"Unknown blobdiff format");5679}56805681# patch5682if($formateq'html') {5683print"<div class=\"page_body\">\n";56845685 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5686close$fd;56875688print"</div>\n";# class="page_body"5689 git_footer_html();56905691}else{5692while(my$line= <$fd>) {5693$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5694$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;56955696print$line;56975698last if$line=~m!^\+\+\+!;5699}5700local$/=undef;5701print<$fd>;5702close$fd;5703}5704}57055706sub git_blobdiff_plain {5707 git_blobdiff('plain');5708}57095710sub git_commitdiff {5711my%params=@_;5712my$format=$params{-format} ||'html';57135714my($patch_max) = gitweb_get_feature('patches');5715if($formateq'patch') {5716 die_error(403,"Patch view not allowed")unless$patch_max;5717}57185719$hash||=$hash_base||"HEAD";5720my%co= parse_commit($hash)5721or die_error(404,"Unknown commit object");57225723# choose format for commitdiff for merge5724if(!defined$hash_parent&& @{$co{'parents'}} >1) {5725$hash_parent='--cc';5726}5727# we need to prepare $formats_nav before almost any parameter munging5728my$formats_nav;5729if($formateq'html') {5730$formats_nav=5731$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},5732"raw");5733if($patch_max) {5734$formats_nav.=" | ".5735$cgi->a({-href => href(action=>"patch", -replay=>1)},5736"patch");5737}57385739if(defined$hash_parent&&5740$hash_parentne'-c'&&$hash_parentne'--cc') {5741# commitdiff with two commits given5742my$hash_parent_short=$hash_parent;5743if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {5744$hash_parent_short=substr($hash_parent,0,7);5745}5746$formats_nav.=5747' (from';5748for(my$i=0;$i< @{$co{'parents'}};$i++) {5749if($co{'parents'}[$i]eq$hash_parent) {5750$formats_nav.=' parent '. ($i+1);5751last;5752}5753}5754$formats_nav.=': '.5755$cgi->a({-href => href(action=>"commitdiff",5756 hash=>$hash_parent)},5757 esc_html($hash_parent_short)) .5758')';5759}elsif(!$co{'parent'}) {5760# --root commitdiff5761$formats_nav.=' (initial)';5762}elsif(scalar@{$co{'parents'}} ==1) {5763# single parent commit5764$formats_nav.=5765' (parent: '.5766$cgi->a({-href => href(action=>"commitdiff",5767 hash=>$co{'parent'})},5768 esc_html(substr($co{'parent'},0,7))) .5769')';5770}else{5771# merge commit5772if($hash_parenteq'--cc') {5773$formats_nav.=' | '.5774$cgi->a({-href => href(action=>"commitdiff",5775 hash=>$hash, hash_parent=>'-c')},5776'combined');5777}else{# $hash_parent eq '-c'5778$formats_nav.=' | '.5779$cgi->a({-href => href(action=>"commitdiff",5780 hash=>$hash, hash_parent=>'--cc')},5781'compact');5782}5783$formats_nav.=5784' (merge: '.5785join(' ',map{5786$cgi->a({-href => href(action=>"commitdiff",5787 hash=>$_)},5788 esc_html(substr($_,0,7)));5789} @{$co{'parents'}} ) .5790')';5791}5792}57935794my$hash_parent_param=$hash_parent;5795if(!defined$hash_parent_param) {5796# --cc for multiple parents, --root for parentless5797$hash_parent_param=5798@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';5799}58005801# read commitdiff5802my$fd;5803my@difftree;5804if($formateq'html') {5805open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5806"--no-commit-id","--patch-with-raw","--full-index",5807$hash_parent_param,$hash,"--"5808or die_error(500,"Open git-diff-tree failed");58095810while(my$line= <$fd>) {5811chomp$line;5812# empty line ends raw part of diff-tree output5813last unless$line;5814push@difftree,scalar parse_difftree_raw_line($line);5815}58165817}elsif($formateq'plain') {5818open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5819'-p',$hash_parent_param,$hash,"--"5820or die_error(500,"Open git-diff-tree failed");5821}elsif($formateq'patch') {5822# For commit ranges, we limit the output to the number of5823# patches specified in the 'patches' feature.5824# For single commits, we limit the output to a single patch,5825# diverging from the git-format-patch default.5826my@commit_spec= ();5827if($hash_parent) {5828if($patch_max>0) {5829push@commit_spec,"-$patch_max";5830}5831push@commit_spec,'-n',"$hash_parent..$hash";5832}else{5833if($params{-single}) {5834push@commit_spec,'-1';5835}else{5836if($patch_max>0) {5837push@commit_spec,"-$patch_max";5838}5839push@commit_spec,"-n";5840}5841push@commit_spec,'--root',$hash;5842}5843open$fd,"-|", git_cmd(),"format-patch",'--encoding=utf8',5844'--stdout',@commit_spec5845or die_error(500,"Open git-format-patch failed");5846}else{5847 die_error(400,"Unknown commitdiff format");5848}58495850# non-textual hash id's can be cached5851my$expires;5852if($hash=~m/^[0-9a-fA-F]{40}$/) {5853$expires="+1d";5854}58555856# write commit message5857if($formateq'html') {5858my$refs= git_get_references();5859my$ref= format_ref_marker($refs,$co{'id'});58605861 git_header_html(undef,$expires);5862 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);5863 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);5864print"<div class=\"title_text\">\n".5865"<table class=\"object_header\">\n";5866 git_print_authorship_rows(\%co);5867print"</table>".5868"</div>\n";5869print"<div class=\"page_body\">\n";5870if(@{$co{'comment'}} >1) {5871print"<div class=\"log\">\n";5872 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);5873print"</div>\n";# class="log"5874}58755876}elsif($formateq'plain') {5877my$refs= git_get_references("tags");5878my$tagname= git_get_rev_name_tags($hash);5879my$filename= basename($project) ."-$hash.patch";58805881print$cgi->header(5882-type =>'text/plain',5883-charset =>'utf-8',5884-expires =>$expires,5885-content_disposition =>'inline; filename="'."$filename".'"');5886my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5887print"From: ". to_utf8($co{'author'}) ."\n";5888print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";5889print"Subject: ". to_utf8($co{'title'}) ."\n";58905891print"X-Git-Tag:$tagname\n"if$tagname;5892print"X-Git-Url: ".$cgi->self_url() ."\n\n";58935894foreachmy$line(@{$co{'comment'}}) {5895print to_utf8($line) ."\n";5896}5897print"---\n\n";5898}elsif($formateq'patch') {5899my$filename= basename($project) ."-$hash.patch";59005901print$cgi->header(5902-type =>'text/plain',5903-charset =>'utf-8',5904-expires =>$expires,5905-content_disposition =>'inline; filename="'."$filename".'"');5906}59075908# write patch5909if($formateq'html') {5910my$use_parents= !defined$hash_parent||5911$hash_parenteq'-c'||$hash_parenteq'--cc';5912 git_difftree_body(\@difftree,$hash,5913$use_parents? @{$co{'parents'}} :$hash_parent);5914print"<br/>\n";59155916 git_patchset_body($fd, \@difftree,$hash,5917$use_parents? @{$co{'parents'}} :$hash_parent);5918close$fd;5919print"</div>\n";# class="page_body"5920 git_footer_html();59215922}elsif($formateq'plain') {5923local$/=undef;5924print<$fd>;5925close$fd5926or print"Reading git-diff-tree failed\n";5927}elsif($formateq'patch') {5928local$/=undef;5929print<$fd>;5930close$fd5931or print"Reading git-format-patch failed\n";5932}5933}59345935sub git_commitdiff_plain {5936 git_commitdiff(-format =>'plain');5937}59385939# format-patch-style patches5940sub git_patch {5941 git_commitdiff(-format =>'patch', -single=>1);5942}59435944sub git_patches {5945 git_commitdiff(-format =>'patch');5946}59475948sub git_history {5949if(!defined$hash_base) {5950$hash_base= git_get_head_hash($project);5951}5952if(!defined$page) {5953$page=0;5954}5955my$ftype;5956my%co= parse_commit($hash_base)5957or die_error(404,"Unknown commit object");59585959my$refs= git_get_references();5960my$limit=sprintf("--max-count=%i", (100* ($page+1)));59615962my@commitlist= parse_commits($hash_base,101, (100*$page),5963$file_name,"--full-history")5964or die_error(404,"No such file or directory on given branch");59655966if(!defined$hash&&defined$file_name) {5967# some commits could have deleted file in question,5968# and not have it in tree, but one of them has to have it5969for(my$i=0;$i<=@commitlist;$i++) {5970$hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5971last ifdefined$hash;5972}5973}5974if(defined$hash) {5975$ftype= git_get_type($hash);5976}5977if(!defined$ftype) {5978 die_error(500,"Unknown type of object");5979}59805981my$paging_nav='';5982if($page>0) {5983$paging_nav.=5984$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,5985 file_name=>$file_name)},5986"first");5987$paging_nav.=" ⋅ ".5988$cgi->a({-href => href(-replay=>1, page=>$page-1),5989-accesskey =>"p", -title =>"Alt-p"},"prev");5990}else{5991$paging_nav.="first";5992$paging_nav.=" ⋅ prev";5993}5994my$next_link='';5995if($#commitlist>=100) {5996$next_link=5997$cgi->a({-href => href(-replay=>1, page=>$page+1),5998-accesskey =>"n", -title =>"Alt-n"},"next");5999$paging_nav.=" ⋅$next_link";6000}else{6001$paging_nav.=" ⋅ next";6002}60036004 git_header_html();6005 git_print_page_nav('history','',$hash_base,$co{'tree'},$hash_base,$paging_nav);6006 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);6007 git_print_page_path($file_name,$ftype,$hash_base);60086009 git_history_body(\@commitlist,0,99,6010$refs,$hash_base,$ftype,$next_link);60116012 git_footer_html();6013}60146015sub git_search {6016 gitweb_check_feature('search')or die_error(403,"Search is disabled");6017if(!defined$searchtext) {6018 die_error(400,"Text field is empty");6019}6020if(!defined$hash) {6021$hash= git_get_head_hash($project);6022}6023my%co= parse_commit($hash);6024if(!%co) {6025 die_error(404,"Unknown commit object");6026}6027if(!defined$page) {6028$page=0;6029}60306031$searchtype||='commit';6032if($searchtypeeq'pickaxe') {6033# pickaxe may take all resources of your box and run for several minutes6034# with every query - so decide by yourself how public you make this feature6035 gitweb_check_feature('pickaxe')6036or die_error(403,"Pickaxe is disabled");6037}6038if($searchtypeeq'grep') {6039 gitweb_check_feature('grep')6040or die_error(403,"Grep is disabled");6041}60426043 git_header_html();60446045if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {6046my$greptype;6047if($searchtypeeq'commit') {6048$greptype="--grep=";6049}elsif($searchtypeeq'author') {6050$greptype="--author=";6051}elsif($searchtypeeq'committer') {6052$greptype="--committer=";6053}6054$greptype.=$searchtext;6055my@commitlist= parse_commits($hash,101, (100*$page),undef,6056$greptype,'--regexp-ignore-case',6057$search_use_regexp?'--extended-regexp':'--fixed-strings');60586059my$paging_nav='';6060if($page>0) {6061$paging_nav.=6062$cgi->a({-href => href(action=>"search", hash=>$hash,6063 searchtext=>$searchtext,6064 searchtype=>$searchtype)},6065"first");6066$paging_nav.=" ⋅ ".6067$cgi->a({-href => href(-replay=>1, page=>$page-1),6068-accesskey =>"p", -title =>"Alt-p"},"prev");6069}else{6070$paging_nav.="first";6071$paging_nav.=" ⋅ prev";6072}6073my$next_link='';6074if($#commitlist>=100) {6075$next_link=6076$cgi->a({-href => href(-replay=>1, page=>$page+1),6077-accesskey =>"n", -title =>"Alt-n"},"next");6078$paging_nav.=" ⋅$next_link";6079}else{6080$paging_nav.=" ⋅ next";6081}60826083if($#commitlist>=100) {6084}60856086 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);6087 git_print_header_div('commit', esc_html($co{'title'}),$hash);6088 git_search_grep_body(\@commitlist,0,99,$next_link);6089}60906091if($searchtypeeq'pickaxe') {6092 git_print_page_nav('','',$hash,$co{'tree'},$hash);6093 git_print_header_div('commit', esc_html($co{'title'}),$hash);60946095print"<table class=\"pickaxe search\">\n";6096my$alternate=1;6097local$/="\n";6098open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,6099'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",6100($search_use_regexp?'--pickaxe-regex': ());6101undef%co;6102my@files;6103while(my$line= <$fd>) {6104chomp$line;6105next unless$line;61066107my%set= parse_difftree_raw_line($line);6108if(defined$set{'commit'}) {6109# finish previous commit6110if(%co) {6111print"</td>\n".6112"<td class=\"link\">".6113$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6114" | ".6115$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6116print"</td>\n".6117"</tr>\n";6118}61196120if($alternate) {6121print"<tr class=\"dark\">\n";6122}else{6123print"<tr class=\"light\">\n";6124}6125$alternate^=1;6126%co= parse_commit($set{'commit'});6127my$author= chop_and_escape_str($co{'author_name'},15,5);6128print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6129"<td><i>$author</i></td>\n".6130"<td>".6131$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6132-class=>"list subject"},6133 chop_and_escape_str($co{'title'},50) ."<br/>");6134}elsif(defined$set{'to_id'}) {6135next if($set{'to_id'} =~m/^0{40}$/);61366137print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6138 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6139-class=>"list"},6140"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6141"<br/>\n";6142}6143}6144close$fd;61456146# finish last commit (warning: repetition!)6147if(%co) {6148print"</td>\n".6149"<td class=\"link\">".6150$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6151" | ".6152$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6153print"</td>\n".6154"</tr>\n";6155}61566157print"</table>\n";6158}61596160if($searchtypeeq'grep') {6161 git_print_page_nav('','',$hash,$co{'tree'},$hash);6162 git_print_header_div('commit', esc_html($co{'title'}),$hash);61636164print"<table class=\"grep_search\">\n";6165my$alternate=1;6166my$matches=0;6167local$/="\n";6168open my$fd,"-|", git_cmd(),'grep','-n',6169$search_use_regexp? ('-E','-i') :'-F',6170$searchtext,$co{'tree'};6171my$lastfile='';6172while(my$line= <$fd>) {6173chomp$line;6174my($file,$lno,$ltext,$binary);6175last if($matches++>1000);6176if($line=~/^Binary file (.+) matches$/) {6177$file=$1;6178$binary=1;6179}else{6180(undef,$file,$lno,$ltext) =split(/:/,$line,4);6181}6182if($filene$lastfile) {6183$lastfileand print"</td></tr>\n";6184if($alternate++) {6185print"<tr class=\"dark\">\n";6186}else{6187print"<tr class=\"light\">\n";6188}6189print"<td class=\"list\">".6190$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6191 file_name=>"$file"),6192-class=>"list"}, esc_path($file));6193print"</td><td>\n";6194$lastfile=$file;6195}6196if($binary) {6197print"<div class=\"binary\">Binary file</div>\n";6198}else{6199$ltext= untabify($ltext);6200if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6201$ltext= esc_html($1, -nbsp=>1);6202$ltext.='<span class="match">';6203$ltext.= esc_html($2, -nbsp=>1);6204$ltext.='</span>';6205$ltext.= esc_html($3, -nbsp=>1);6206}else{6207$ltext= esc_html($ltext, -nbsp=>1);6208}6209print"<div class=\"pre\">".6210$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6211 file_name=>"$file").'#l'.$lno,6212-class=>"linenr"},sprintf('%4i',$lno))6213.' '.$ltext."</div>\n";6214}6215}6216if($lastfile) {6217print"</td></tr>\n";6218if($matches>1000) {6219print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6220}6221}else{6222print"<div class=\"diff nodifferences\">No matches found</div>\n";6223}6224close$fd;62256226print"</table>\n";6227}6228 git_footer_html();6229}62306231sub git_search_help {6232 git_header_html();6233 git_print_page_nav('','',$hash,$hash,$hash);6234print<<EOT;6235<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without6236regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,6237the pattern entered is recognized as the POSIX extended6238<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case6239insensitive).</p>6240<dl>6241<dt><b>commit</b></dt>6242<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>6243EOT6244my$have_grep= gitweb_check_feature('grep');6245if($have_grep) {6246print<<EOT;6247<dt><b>grep</b></dt>6248<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing6249 a different one) are searched for the given pattern. On large trees, this search can take6250a while and put some strain on the server, so please use it with some consideration. Note that6251due to git-grep peculiarity, currently if regexp mode is turned off, the matches are6252case-sensitive.</dd>6253EOT6254}6255print<<EOT;6256<dt><b>author</b></dt>6257<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>6258<dt><b>committer</b></dt>6259<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>6260EOT6261my$have_pickaxe= gitweb_check_feature('pickaxe');6262if($have_pickaxe) {6263print<<EOT;6264<dt><b>pickaxe</b></dt>6265<dd>All commits that caused the string to appear or disappear from any file (changes that6266added, removed or "modified" the string) will be listed. This search can take a while and6267takes a lot of strain on the server, so please use it wisely. Note that since you may be6268interested even in changes just changing the case as well, this search is case sensitive.</dd>6269EOT6270}6271print"</dl>\n";6272 git_footer_html();6273}62746275sub git_shortlog {6276my$head= git_get_head_hash($project);6277if(!defined$hash) {6278$hash=$head;6279}6280if(!defined$page) {6281$page=0;6282}6283my$refs= git_get_references();62846285my$commit_hash=$hash;6286if(defined$hash_parent) {6287$commit_hash="$hash_parent..$hash";6288}6289my@commitlist= parse_commits($commit_hash,101, (100*$page));62906291my$paging_nav= format_paging_nav('shortlog',$hash,$head,$page,$#commitlist>=100);6292my$next_link='';6293if($#commitlist>=100) {6294$next_link=6295$cgi->a({-href => href(-replay=>1, page=>$page+1),6296-accesskey =>"n", -title =>"Alt-n"},"next");6297}6298my$patch_max= gitweb_check_feature('patches');6299if($patch_max) {6300if($patch_max<0||@commitlist<=$patch_max) {6301$paging_nav.=" ⋅ ".6302$cgi->a({-href => href(action=>"patches", -replay=>1)},6303"patches");6304}6305}63066307 git_header_html();6308 git_print_page_nav('shortlog','',$hash,$hash,$hash,$paging_nav);6309 git_print_header_div('summary',$project);63106311 git_shortlog_body(\@commitlist,0,99,$refs,$next_link);63126313 git_footer_html();6314}63156316## ......................................................................6317## feeds (RSS, Atom; OPML)63186319sub git_feed {6320my$format=shift||'atom';6321my$have_blame= gitweb_check_feature('blame');63226323# Atom: http://www.atomenabled.org/developers/syndication/6324# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ6325if($formatne'rss'&&$formatne'atom') {6326 die_error(400,"Unknown web feed format");6327}63286329# log/feed of current (HEAD) branch, log of given branch, history of file/directory6330my$head=$hash||'HEAD';6331my@commitlist= parse_commits($head,150,0,$file_name);63326333my%latest_commit;6334my%latest_date;6335my$content_type="application/$format+xml";6336if(defined$cgi->http('HTTP_ACCEPT') &&6337$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {6338# browser (feed reader) prefers text/xml6339$content_type='text/xml';6340}6341if(defined($commitlist[0])) {6342%latest_commit= %{$commitlist[0]};6343my$latest_epoch=$latest_commit{'committer_epoch'};6344%latest_date= parse_date($latest_epoch);6345my$if_modified=$cgi->http('IF_MODIFIED_SINCE');6346if(defined$if_modified) {6347my$since;6348if(eval{require HTTP::Date;1; }) {6349$since= HTTP::Date::str2time($if_modified);6350}elsif(eval{require Time::ParseDate;1; }) {6351$since= Time::ParseDate::parsedate($if_modified, GMT =>1);6352}6353if(defined$since&&$latest_epoch<=$since) {6354print$cgi->header(6355-type =>$content_type,6356-charset =>'utf-8',6357-last_modified =>$latest_date{'rfc2822'},6358-status =>'304 Not Modified');6359return;6360}6361}6362print$cgi->header(6363-type =>$content_type,6364-charset =>'utf-8',6365-last_modified =>$latest_date{'rfc2822'});6366}else{6367print$cgi->header(6368-type =>$content_type,6369-charset =>'utf-8');6370}63716372# Optimization: skip generating the body if client asks only6373# for Last-Modified date.6374return if($cgi->request_method()eq'HEAD');63756376# header variables6377my$title="$site_name-$project/$action";6378my$feed_type='log';6379if(defined$hash) {6380$title.=" - '$hash'";6381$feed_type='branch log';6382if(defined$file_name) {6383$title.=" ::$file_name";6384$feed_type='history';6385}6386}elsif(defined$file_name) {6387$title.=" -$file_name";6388$feed_type='history';6389}6390$title.="$feed_type";6391my$descr= git_get_project_description($project);6392if(defined$descr) {6393$descr= esc_html($descr);6394}else{6395$descr="$project".6396($formateq'rss'?'RSS':'Atom') .6397" feed";6398}6399my$owner= git_get_project_owner($project);6400$owner= esc_html($owner);64016402#header6403my$alt_url;6404if(defined$file_name) {6405$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);6406}elsif(defined$hash) {6407$alt_url= href(-full=>1, action=>"log", hash=>$hash);6408}else{6409$alt_url= href(-full=>1, action=>"summary");6410}6411print qq!<?xml version="1.0" encoding="utf-8"?>\n!;6412if($formateq'rss') {6413print<<XML;6414<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">6415<channel>6416XML6417print"<title>$title</title>\n".6418"<link>$alt_url</link>\n".6419"<description>$descr</description>\n".6420"<language>en</language>\n".6421# project owner is responsible for 'editorial' content6422"<managingEditor>$owner</managingEditor>\n";6423if(defined$logo||defined$favicon) {6424# prefer the logo to the favicon, since RSS6425# doesn't allow both6426my$img= esc_url($logo||$favicon);6427print"<image>\n".6428"<url>$img</url>\n".6429"<title>$title</title>\n".6430"<link>$alt_url</link>\n".6431"</image>\n";6432}6433if(%latest_date) {6434print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";6435print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";6436}6437print"<generator>gitweb v.$version/$git_version</generator>\n";6438}elsif($formateq'atom') {6439print<<XML;6440<feed xmlns="http://www.w3.org/2005/Atom">6441XML6442print"<title>$title</title>\n".6443"<subtitle>$descr</subtitle>\n".6444'<link rel="alternate" type="text/html" href="'.6445$alt_url.'" />'."\n".6446'<link rel="self" type="'.$content_type.'" href="'.6447$cgi->self_url() .'" />'."\n".6448"<id>". href(-full=>1) ."</id>\n".6449# use project owner for feed author6450"<author><name>$owner</name></author>\n";6451if(defined$favicon) {6452print"<icon>". esc_url($favicon) ."</icon>\n";6453}6454if(defined$logo_url) {6455# not twice as wide as tall: 72 x 27 pixels6456print"<logo>". esc_url($logo) ."</logo>\n";6457}6458if(!%latest_date) {6459# dummy date to keep the feed valid until commits trickle in:6460print"<updated>1970-01-01T00:00:00Z</updated>\n";6461}else{6462print"<updated>$latest_date{'iso-8601'}</updated>\n";6463}6464print"<generator version='$version/$git_version'>gitweb</generator>\n";6465}64666467# contents6468for(my$i=0;$i<=$#commitlist;$i++) {6469my%co= %{$commitlist[$i]};6470my$commit=$co{'id'};6471# we read 150, we always show 30 and the ones more recent than 48 hours6472if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6473last;6474}6475my%cd= parse_date($co{'author_epoch'});64766477# get list of changed files6478open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6479$co{'parent'} ||"--root",6480$co{'id'},"--", (defined$file_name?$file_name: ())6481ornext;6482my@difftree=map{chomp;$_} <$fd>;6483close$fd6484ornext;64856486# print element (entry, item)6487my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6488if($formateq'rss') {6489print"<item>\n".6490"<title>". esc_html($co{'title'}) ."</title>\n".6491"<author>". esc_html($co{'author'}) ."</author>\n".6492"<pubDate>$cd{'rfc2822'}</pubDate>\n".6493"<guid isPermaLink=\"true\">$co_url</guid>\n".6494"<link>$co_url</link>\n".6495"<description>". esc_html($co{'title'}) ."</description>\n".6496"<content:encoded>".6497"<![CDATA[\n";6498}elsif($formateq'atom') {6499print"<entry>\n".6500"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6501"<updated>$cd{'iso-8601'}</updated>\n".6502"<author>\n".6503" <name>". esc_html($co{'author_name'}) ."</name>\n";6504if($co{'author_email'}) {6505print" <email>". esc_html($co{'author_email'}) ."</email>\n";6506}6507print"</author>\n".6508# use committer for contributor6509"<contributor>\n".6510" <name>". esc_html($co{'committer_name'}) ."</name>\n";6511if($co{'committer_email'}) {6512print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6513}6514print"</contributor>\n".6515"<published>$cd{'iso-8601'}</published>\n".6516"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6517"<id>$co_url</id>\n".6518"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6519"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6520}6521my$comment=$co{'comment'};6522print"<pre>\n";6523foreachmy$line(@$comment) {6524$line= esc_html($line);6525print"$line\n";6526}6527print"</pre><ul>\n";6528foreachmy$difftree_line(@difftree) {6529my%difftree= parse_difftree_raw_line($difftree_line);6530next if!$difftree{'from_id'};65316532my$file=$difftree{'file'} ||$difftree{'to_file'};65336534print"<li>".6535"[".6536$cgi->a({-href => href(-full=>1, action=>"blobdiff",6537 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6538 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6539 file_name=>$file, file_parent=>$difftree{'from_file'}),6540-title =>"diff"},'D');6541if($have_blame) {6542print$cgi->a({-href => href(-full=>1, action=>"blame",6543 file_name=>$file, hash_base=>$commit),6544-title =>"blame"},'B');6545}6546# if this is not a feed of a file history6547if(!defined$file_name||$file_namene$file) {6548print$cgi->a({-href => href(-full=>1, action=>"history",6549 file_name=>$file, hash=>$commit),6550-title =>"history"},'H');6551}6552$file= esc_path($file);6553print"] ".6554"$file</li>\n";6555}6556if($formateq'rss') {6557print"</ul>]]>\n".6558"</content:encoded>\n".6559"</item>\n";6560}elsif($formateq'atom') {6561print"</ul>\n</div>\n".6562"</content>\n".6563"</entry>\n";6564}6565}65666567# end of feed6568if($formateq'rss') {6569print"</channel>\n</rss>\n";6570}elsif($formateq'atom') {6571print"</feed>\n";6572}6573}65746575sub git_rss {6576 git_feed('rss');6577}65786579sub git_atom {6580 git_feed('atom');6581}65826583sub git_opml {6584my@list= git_get_projects_list();65856586print$cgi->header(6587-type =>'text/xml',6588-charset =>'utf-8',6589-content_disposition =>'inline; filename="opml.xml"');65906591print<<XML;6592<?xml version="1.0" encoding="utf-8"?>6593<opml version="1.0">6594<head>6595 <title>$site_nameOPML Export</title>6596</head>6597<body>6598<outline text="git RSS feeds">6599XML66006601foreachmy$pr(@list) {6602my%proj=%$pr;6603my$head= git_get_head_hash($proj{'path'});6604if(!defined$head) {6605next;6606}6607$git_dir="$projectroot/$proj{'path'}";6608my%co= parse_commit($head);6609if(!%co) {6610next;6611}66126613my$path= esc_html(chop_str($proj{'path'},25,5));6614my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);6615my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);6616print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";6617}6618print<<XML;6619</outline>6620</body>6621</opml>6622XML6623}