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 21BEGIN{ 22 CGI->compile()if$ENV{'MOD_PERL'}; 23} 24 25our$cgi= new CGI; 26our$version="++GIT_VERSION++"; 27our$my_url=$cgi->url(); 28our$my_uri=$cgi->url(-absolute =>1); 29 30# Base URL for relative URLs in gitweb ($logo, $favicon, ...), 31# needed and used only for URLs with nonempty PATH_INFO 32our$base_url=$my_url; 33 34# When the script is used as DirectoryIndex, the URL does not contain the name 35# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we 36# have to do it ourselves. We make $path_info global because it's also used 37# later on. 38# 39# Another issue with the script being the DirectoryIndex is that the resulting 40# $my_url data is not the full script URL: this is good, because we want 41# generated links to keep implying the script name if it wasn't explicitly 42# indicated in the URL we're handling, but it means that $my_url cannot be used 43# as base URL. 44# Therefore, if we needed to strip PATH_INFO, then we know that we have 45# to build the base URL ourselves: 46our$path_info=$ENV{"PATH_INFO"}; 47if($path_info) { 48if($my_url=~ s,\Q$path_info\E$,, && 49$my_uri=~ s,\Q$path_info\E$,, && 50defined$ENV{'SCRIPT_NAME'}) { 51$base_url=$cgi->url(-base =>1) .$ENV{'SCRIPT_NAME'}; 52} 53} 54 55# core git executable to use 56# this can just be "git" if your webserver has a sensible PATH 57our$GIT="++GIT_BINDIR++/git"; 58 59# absolute fs-path which will be prepended to the project path 60#our $projectroot = "/pub/scm"; 61our$projectroot="++GITWEB_PROJECTROOT++"; 62 63# fs traversing limit for getting project list 64# the number is relative to the projectroot 65our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 66 67# target of the home link on top of all pages 68our$home_link=$my_uri||"/"; 69 70# string of the home link on top of all pages 71our$home_link_str="++GITWEB_HOME_LINK_STR++"; 72 73# name of your site or organization to appear in page titles 74# replace this with something more descriptive for clearer bookmarks 75our$site_name="++GITWEB_SITENAME++" 76|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 77 78# filename of html text to include at top of each page 79our$site_header="++GITWEB_SITE_HEADER++"; 80# html text to include at home page 81our$home_text="++GITWEB_HOMETEXT++"; 82# filename of html text to include at bottom of each page 83our$site_footer="++GITWEB_SITE_FOOTER++"; 84 85# URI of stylesheets 86our@stylesheets= ("++GITWEB_CSS++"); 87# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 88our$stylesheet=undef; 89# URI of GIT logo (72x27 size) 90our$logo="++GITWEB_LOGO++"; 91# URI of GIT favicon, assumed to be image/png type 92our$favicon="++GITWEB_FAVICON++"; 93 94# URI and label (title) of GIT logo link 95#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 96#our $logo_label = "git documentation"; 97our$logo_url="http://git-scm.com/"; 98our$logo_label="git homepage"; 99 100# source of projects list 101our$projects_list="++GITWEB_LIST++"; 102 103# the width (in characters) of the projects list "Description" column 104our$projects_list_description_width=25; 105 106# default order of projects list 107# valid values are none, project, descr, owner, and age 108our$default_projects_order="project"; 109 110# show repository only if this file exists 111# (only effective if this variable evaluates to true) 112our$export_ok="++GITWEB_EXPORT_OK++"; 113 114# show repository only if this subroutine returns true 115# when given the path to the project, for example: 116# sub { return -e "$_[0]/git-daemon-export-ok"; } 117our$export_auth_hook=undef; 118 119# only allow viewing of repositories also shown on the overview page 120our$strict_export="++GITWEB_STRICT_EXPORT++"; 121 122# list of git base URLs used for URL to where fetch project from, 123# i.e. full URL is "$git_base_url/$project" 124our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 125 126# default blob_plain mimetype and default charset for text/plain blob 127our$default_blob_plain_mimetype='text/plain'; 128our$default_text_plain_charset=undef; 129 130# file to use for guessing MIME types before trying /etc/mime.types 131# (relative to the current git repository) 132our$mimetypes_file=undef; 133 134# assume this charset if line contains non-UTF-8 characters; 135# it should be valid encoding (see Encoding::Supported(3pm) for list), 136# for which encoding all byte sequences are valid, for example 137# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 138# could be even 'utf-8' for the old behavior) 139our$fallback_encoding='latin1'; 140 141# rename detection options for git-diff and git-diff-tree 142# - default is '-M', with the cost proportional to 143# (number of removed files) * (number of new files). 144# - more costly is '-C' (which implies '-M'), with the cost proportional to 145# (number of changed files + number of removed files) * (number of new files) 146# - even more costly is '-C', '--find-copies-harder' with cost 147# (number of files in the original tree) * (number of new files) 148# - one might want to include '-B' option, e.g. '-B', '-M' 149our@diff_opts= ('-M');# taken from git_commit 150 151# Disables features that would allow repository owners to inject script into 152# the gitweb domain. 153our$prevent_xss=0; 154 155# information about snapshot formats that gitweb is capable of serving 156our%known_snapshot_formats= ( 157# name => { 158# 'display' => display name, 159# 'type' => mime type, 160# 'suffix' => filename suffix, 161# 'format' => --format for git-archive, 162# 'compressor' => [compressor command and arguments] 163# (array reference, optional) 164# 'disabled' => boolean (optional)} 165# 166'tgz'=> { 167'display'=>'tar.gz', 168'type'=>'application/x-gzip', 169'suffix'=>'.tar.gz', 170'format'=>'tar', 171'compressor'=> ['gzip']}, 172 173'tbz2'=> { 174'display'=>'tar.bz2', 175'type'=>'application/x-bzip2', 176'suffix'=>'.tar.bz2', 177'format'=>'tar', 178'compressor'=> ['bzip2']}, 179 180'txz'=> { 181'display'=>'tar.xz', 182'type'=>'application/x-xz', 183'suffix'=>'.tar.xz', 184'format'=>'tar', 185'compressor'=> ['xz'], 186'disabled'=>1}, 187 188'zip'=> { 189'display'=>'zip', 190'type'=>'application/x-zip', 191'suffix'=>'.zip', 192'format'=>'zip'}, 193); 194 195# Aliases so we understand old gitweb.snapshot values in repository 196# configuration. 197our%known_snapshot_format_aliases= ( 198'gzip'=>'tgz', 199'bzip2'=>'tbz2', 200'xz'=>'txz', 201 202# backward compatibility: legacy gitweb config support 203'x-gzip'=>undef,'gz'=>undef, 204'x-bzip2'=>undef,'bz2'=>undef, 205'x-zip'=>undef,''=>undef, 206); 207 208# Pixel sizes for icons and avatars. If the default font sizes or lineheights 209# are changed, it may be appropriate to change these values too via 210# $GITWEB_CONFIG. 211our%avatar_size= ( 212'default'=>16, 213'double'=>32 214); 215 216# You define site-wide feature defaults here; override them with 217# $GITWEB_CONFIG as necessary. 218our%feature= ( 219# feature => { 220# 'sub' => feature-sub (subroutine), 221# 'override' => allow-override (boolean), 222# 'default' => [ default options...] (array reference)} 223# 224# if feature is overridable (it means that allow-override has true value), 225# then feature-sub will be called with default options as parameters; 226# return value of feature-sub indicates if to enable specified feature 227# 228# if there is no 'sub' key (no feature-sub), then feature cannot be 229# overriden 230# 231# use gitweb_get_feature(<feature>) to retrieve the <feature> value 232# (an array) or gitweb_check_feature(<feature>) to check if <feature> 233# is enabled 234 235# Enable the 'blame' blob view, showing the last commit that modified 236# each line in the file. This can be very CPU-intensive. 237 238# To enable system wide have in $GITWEB_CONFIG 239# $feature{'blame'}{'default'} = [1]; 240# To have project specific config enable override in $GITWEB_CONFIG 241# $feature{'blame'}{'override'} = 1; 242# and in project config gitweb.blame = 0|1; 243'blame'=> { 244'sub'=>sub{ feature_bool('blame',@_) }, 245'override'=>0, 246'default'=> [0]}, 247 248# Enable the 'snapshot' link, providing a compressed archive of any 249# tree. This can potentially generate high traffic if you have large 250# project. 251 252# Value is a list of formats defined in %known_snapshot_formats that 253# you wish to offer. 254# To disable system wide have in $GITWEB_CONFIG 255# $feature{'snapshot'}{'default'} = []; 256# To have project specific config enable override in $GITWEB_CONFIG 257# $feature{'snapshot'}{'override'} = 1; 258# and in project config, a comma-separated list of formats or "none" 259# to disable. Example: gitweb.snapshot = tbz2,zip; 260'snapshot'=> { 261'sub'=> \&feature_snapshot, 262'override'=>0, 263'default'=> ['tgz']}, 264 265# Enable text search, which will list the commits which match author, 266# committer or commit text to a given string. Enabled by default. 267# Project specific override is not supported. 268'search'=> { 269'override'=>0, 270'default'=> [1]}, 271 272# Enable grep search, which will list the files in currently selected 273# tree containing the given string. Enabled by default. This can be 274# potentially CPU-intensive, of course. 275 276# To enable system wide have in $GITWEB_CONFIG 277# $feature{'grep'}{'default'} = [1]; 278# To have project specific config enable override in $GITWEB_CONFIG 279# $feature{'grep'}{'override'} = 1; 280# and in project config gitweb.grep = 0|1; 281'grep'=> { 282'sub'=>sub{ feature_bool('grep',@_) }, 283'override'=>0, 284'default'=> [1]}, 285 286# Enable the pickaxe search, which will list the commits that modified 287# a given string in a file. This can be practical and quite faster 288# alternative to 'blame', but still potentially CPU-intensive. 289 290# To enable system wide have in $GITWEB_CONFIG 291# $feature{'pickaxe'}{'default'} = [1]; 292# To have project specific config enable override in $GITWEB_CONFIG 293# $feature{'pickaxe'}{'override'} = 1; 294# and in project config gitweb.pickaxe = 0|1; 295'pickaxe'=> { 296'sub'=>sub{ feature_bool('pickaxe',@_) }, 297'override'=>0, 298'default'=> [1]}, 299 300# Make gitweb use an alternative format of the URLs which can be 301# more readable and natural-looking: project name is embedded 302# directly in the path and the query string contains other 303# auxiliary information. All gitweb installations recognize 304# URL in either format; this configures in which formats gitweb 305# generates links. 306 307# To enable system wide have in $GITWEB_CONFIG 308# $feature{'pathinfo'}{'default'} = [1]; 309# Project specific override is not supported. 310 311# Note that you will need to change the default location of CSS, 312# favicon, logo and possibly other files to an absolute URL. Also, 313# if gitweb.cgi serves as your indexfile, you will need to force 314# $my_uri to contain the script name in your $GITWEB_CONFIG. 315'pathinfo'=> { 316'override'=>0, 317'default'=> [0]}, 318 319# Make gitweb consider projects in project root subdirectories 320# to be forks of existing projects. Given project $projname.git, 321# projects matching $projname/*.git will not be shown in the main 322# projects list, instead a '+' mark will be added to $projname 323# there and a 'forks' view will be enabled for the project, listing 324# all the forks. If project list is taken from a file, forks have 325# to be listed after the main project. 326 327# To enable system wide have in $GITWEB_CONFIG 328# $feature{'forks'}{'default'} = [1]; 329# Project specific override is not supported. 330'forks'=> { 331'override'=>0, 332'default'=> [0]}, 333 334# Insert custom links to the action bar of all project pages. 335# This enables you mainly to link to third-party scripts integrating 336# into gitweb; e.g. git-browser for graphical history representation 337# or custom web-based repository administration interface. 338 339# The 'default' value consists of a list of triplets in the form 340# (label, link, position) where position is the label after which 341# to insert the link and link is a format string where %n expands 342# to the project name, %f to the project path within the filesystem, 343# %h to the current hash (h gitweb parameter) and %b to the current 344# hash base (hb gitweb parameter); %% expands to %. 345 346# To enable system wide have in $GITWEB_CONFIG e.g. 347# $feature{'actions'}{'default'} = [('graphiclog', 348# '/git-browser/by-commit.html?r=%n', 'summary')]; 349# Project specific override is not supported. 350'actions'=> { 351'override'=>0, 352'default'=> []}, 353 354# Allow gitweb scan project content tags described in ctags/ 355# of project repository, and display the popular Web 2.0-ish 356# "tag cloud" near the project list. Note that this is something 357# COMPLETELY different from the normal Git tags. 358 359# gitweb by itself can show existing tags, but it does not handle 360# tagging itself; you need an external application for that. 361# For an example script, check Girocco's cgi/tagproj.cgi. 362# You may want to install the HTML::TagCloud Perl module to get 363# a pretty tag cloud instead of just a list of tags. 364 365# To enable system wide have in $GITWEB_CONFIG 366# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 367# Project specific override is not supported. 368'ctags'=> { 369'override'=>0, 370'default'=> [0]}, 371 372# The maximum number of patches in a patchset generated in patch 373# view. Set this to 0 or undef to disable patch view, or to a 374# negative number to remove any limit. 375 376# To disable system wide have in $GITWEB_CONFIG 377# $feature{'patches'}{'default'} = [0]; 378# To have project specific config enable override in $GITWEB_CONFIG 379# $feature{'patches'}{'override'} = 1; 380# and in project config gitweb.patches = 0|n; 381# where n is the maximum number of patches allowed in a patchset. 382'patches'=> { 383'sub'=> \&feature_patches, 384'override'=>0, 385'default'=> [16]}, 386 387# Avatar support. When this feature is enabled, views such as 388# shortlog or commit will display an avatar associated with 389# the email of the committer(s) and/or author(s). 390 391# Currently available providers are gravatar and picon. 392# If an unknown provider is specified, the feature is disabled. 393 394# Gravatar depends on Digest::MD5. 395# Picon currently relies on the indiana.edu database. 396 397# To enable system wide have in $GITWEB_CONFIG 398# $feature{'avatar'}{'default'} = ['<provider>']; 399# where <provider> is either gravatar or picon. 400# To have project specific config enable override in $GITWEB_CONFIG 401# $feature{'avatar'}{'override'} = 1; 402# and in project config gitweb.avatar = <provider>; 403'avatar'=> { 404'sub'=> \&feature_avatar, 405'override'=>0, 406'default'=> ['']}, 407); 408 409sub gitweb_get_feature { 410my($name) =@_; 411return unlessexists$feature{$name}; 412my($sub,$override,@defaults) = ( 413$feature{$name}{'sub'}, 414$feature{$name}{'override'}, 415@{$feature{$name}{'default'}}); 416if(!$override) {return@defaults; } 417if(!defined$sub) { 418warn"feature$nameis not overridable"; 419return@defaults; 420} 421return$sub->(@defaults); 422} 423 424# A wrapper to check if a given feature is enabled. 425# With this, you can say 426# 427# my $bool_feat = gitweb_check_feature('bool_feat'); 428# gitweb_check_feature('bool_feat') or somecode; 429# 430# instead of 431# 432# my ($bool_feat) = gitweb_get_feature('bool_feat'); 433# (gitweb_get_feature('bool_feat'))[0] or somecode; 434# 435sub gitweb_check_feature { 436return(gitweb_get_feature(@_))[0]; 437} 438 439 440sub feature_bool { 441my$key=shift; 442my($val) = git_get_project_config($key,'--bool'); 443 444if(!defined$val) { 445return($_[0]); 446}elsif($valeq'true') { 447return(1); 448}elsif($valeq'false') { 449return(0); 450} 451} 452 453sub feature_snapshot { 454my(@fmts) =@_; 455 456my($val) = git_get_project_config('snapshot'); 457 458if($val) { 459@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 460} 461 462return@fmts; 463} 464 465sub feature_patches { 466my@val= (git_get_project_config('patches','--int')); 467 468if(@val) { 469return@val; 470} 471 472return($_[0]); 473} 474 475sub feature_avatar { 476my@val= (git_get_project_config('avatar')); 477 478return@val?@val:@_; 479} 480 481# checking HEAD file with -e is fragile if the repository was 482# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 483# and then pruned. 484sub check_head_link { 485my($dir) =@_; 486my$headfile="$dir/HEAD"; 487return((-e $headfile) || 488(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 489} 490 491sub check_export_ok { 492my($dir) =@_; 493return(check_head_link($dir) && 494(!$export_ok|| -e "$dir/$export_ok") && 495(!$export_auth_hook||$export_auth_hook->($dir))); 496} 497 498# process alternate names for backward compatibility 499# filter out unsupported (unknown) snapshot formats 500sub filter_snapshot_fmts { 501my@fmts=@_; 502 503@fmts=map{ 504exists$known_snapshot_format_aliases{$_} ? 505$known_snapshot_format_aliases{$_} :$_}@fmts; 506@fmts=grep{ 507exists$known_snapshot_formats{$_} && 508!$known_snapshot_formats{$_}{'disabled'}}@fmts; 509} 510 511our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 512if(-e $GITWEB_CONFIG) { 513do$GITWEB_CONFIG; 514}else{ 515our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 516do$GITWEB_CONFIG_SYSTEMif-e $GITWEB_CONFIG_SYSTEM; 517} 518 519# version of the core git binary 520our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 521 522$projects_list||=$projectroot; 523 524# ====================================================================== 525# input validation and dispatch 526 527# input parameters can be collected from a variety of sources (presently, CGI 528# and PATH_INFO), so we define an %input_params hash that collects them all 529# together during validation: this allows subsequent uses (e.g. href()) to be 530# agnostic of the parameter origin 531 532our%input_params= (); 533 534# input parameters are stored with the long parameter name as key. This will 535# also be used in the href subroutine to convert parameters to their CGI 536# equivalent, and since the href() usage is the most frequent one, we store 537# the name -> CGI key mapping here, instead of the reverse. 538# 539# XXX: Warning: If you touch this, check the search form for updating, 540# too. 541 542our@cgi_param_mapping= ( 543 project =>"p", 544 action =>"a", 545 file_name =>"f", 546 file_parent =>"fp", 547 hash =>"h", 548 hash_parent =>"hp", 549 hash_base =>"hb", 550 hash_parent_base =>"hpb", 551 page =>"pg", 552 order =>"o", 553 searchtext =>"s", 554 searchtype =>"st", 555 snapshot_format =>"sf", 556 extra_options =>"opt", 557 search_use_regexp =>"sr", 558); 559our%cgi_param_mapping=@cgi_param_mapping; 560 561# we will also need to know the possible actions, for validation 562our%actions= ( 563"blame"=> \&git_blame, 564"blobdiff"=> \&git_blobdiff, 565"blobdiff_plain"=> \&git_blobdiff_plain, 566"blob"=> \&git_blob, 567"blob_plain"=> \&git_blob_plain, 568"commitdiff"=> \&git_commitdiff, 569"commitdiff_plain"=> \&git_commitdiff_plain, 570"commit"=> \&git_commit, 571"forks"=> \&git_forks, 572"heads"=> \&git_heads, 573"history"=> \&git_history, 574"log"=> \&git_log, 575"patch"=> \&git_patch, 576"patches"=> \&git_patches, 577"rss"=> \&git_rss, 578"atom"=> \&git_atom, 579"search"=> \&git_search, 580"search_help"=> \&git_search_help, 581"shortlog"=> \&git_shortlog, 582"summary"=> \&git_summary, 583"tag"=> \&git_tag, 584"tags"=> \&git_tags, 585"tree"=> \&git_tree, 586"snapshot"=> \&git_snapshot, 587"object"=> \&git_object, 588# those below don't need $project 589"opml"=> \&git_opml, 590"project_list"=> \&git_project_list, 591"project_index"=> \&git_project_index, 592); 593 594# finally, we have the hash of allowed extra_options for the commands that 595# allow them 596our%allowed_options= ( 597"--no-merges"=> [qw(rss atom log shortlog history)], 598); 599 600# fill %input_params with the CGI parameters. All values except for 'opt' 601# should be single values, but opt can be an array. We should probably 602# build an array of parameters that can be multi-valued, but since for the time 603# being it's only this one, we just single it out 604while(my($name,$symbol) =each%cgi_param_mapping) { 605if($symboleq'opt') { 606$input_params{$name} = [$cgi->param($symbol) ]; 607}else{ 608$input_params{$name} =$cgi->param($symbol); 609} 610} 611 612# now read PATH_INFO and update the parameter list for missing parameters 613sub evaluate_path_info { 614return ifdefined$input_params{'project'}; 615return if!$path_info; 616$path_info=~ s,^/+,,; 617return if!$path_info; 618 619# find which part of PATH_INFO is project 620my$project=$path_info; 621$project=~ s,/+$,,; 622while($project&& !check_head_link("$projectroot/$project")) { 623$project=~ s,/*[^/]*$,,; 624} 625return unless$project; 626$input_params{'project'} =$project; 627 628# do not change any parameters if an action is given using the query string 629return if$input_params{'action'}; 630$path_info=~ s,^\Q$project\E/*,,; 631 632# next, check if we have an action 633my$action=$path_info; 634$action=~ s,/.*$,,; 635if(exists$actions{$action}) { 636$path_info=~ s,^$action/*,,; 637$input_params{'action'} =$action; 638} 639 640# list of actions that want hash_base instead of hash, but can have no 641# pathname (f) parameter 642my@wants_base= ( 643'tree', 644'history', 645); 646 647# we want to catch 648# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 649my($parentrefname,$parentpathname,$refname,$pathname) = 650($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/); 651 652# first, analyze the 'current' part 653if(defined$pathname) { 654# we got "branch:filename" or "branch:dir/" 655# we could use git_get_type(branch:pathname), but: 656# - it needs $git_dir 657# - it does a git() call 658# - the convention of terminating directories with a slash 659# makes it superfluous 660# - embedding the action in the PATH_INFO would make it even 661# more superfluous 662$pathname=~ s,^/+,,; 663if(!$pathname||substr($pathname, -1)eq"/") { 664$input_params{'action'} ||="tree"; 665$pathname=~ s,/$,,; 666}else{ 667# the default action depends on whether we had parent info 668# or not 669if($parentrefname) { 670$input_params{'action'} ||="blobdiff_plain"; 671}else{ 672$input_params{'action'} ||="blob_plain"; 673} 674} 675$input_params{'hash_base'} ||=$refname; 676$input_params{'file_name'} ||=$pathname; 677}elsif(defined$refname) { 678# we got "branch". In this case we have to choose if we have to 679# set hash or hash_base. 680# 681# Most of the actions without a pathname only want hash to be 682# set, except for the ones specified in @wants_base that want 683# hash_base instead. It should also be noted that hand-crafted 684# links having 'history' as an action and no pathname or hash 685# set will fail, but that happens regardless of PATH_INFO. 686$input_params{'action'} ||="shortlog"; 687if(grep{$_eq$input_params{'action'} }@wants_base) { 688$input_params{'hash_base'} ||=$refname; 689}else{ 690$input_params{'hash'} ||=$refname; 691} 692} 693 694# next, handle the 'parent' part, if present 695if(defined$parentrefname) { 696# a missing pathspec defaults to the 'current' filename, allowing e.g. 697# someproject/blobdiff/oldrev..newrev:/filename 698if($parentpathname) { 699$parentpathname=~ s,^/+,,; 700$parentpathname=~ s,/$,,; 701$input_params{'file_parent'} ||=$parentpathname; 702}else{ 703$input_params{'file_parent'} ||=$input_params{'file_name'}; 704} 705# we assume that hash_parent_base is wanted if a path was specified, 706# or if the action wants hash_base instead of hash 707if(defined$input_params{'file_parent'} || 708grep{$_eq$input_params{'action'} }@wants_base) { 709$input_params{'hash_parent_base'} ||=$parentrefname; 710}else{ 711$input_params{'hash_parent'} ||=$parentrefname; 712} 713} 714 715# for the snapshot action, we allow URLs in the form 716# $project/snapshot/$hash.ext 717# where .ext determines the snapshot and gets removed from the 718# passed $refname to provide the $hash. 719# 720# To be able to tell that $refname includes the format extension, we 721# require the following two conditions to be satisfied: 722# - the hash input parameter MUST have been set from the $refname part 723# of the URL (i.e. they must be equal) 724# - the snapshot format MUST NOT have been defined already (e.g. from 725# CGI parameter sf) 726# It's also useless to try any matching unless $refname has a dot, 727# so we check for that too 728if(defined$input_params{'action'} && 729$input_params{'action'}eq'snapshot'&& 730defined$refname&&index($refname,'.') != -1&& 731$refnameeq$input_params{'hash'} && 732!defined$input_params{'snapshot_format'}) { 733# We loop over the known snapshot formats, checking for 734# extensions. Allowed extensions are both the defined suffix 735# (which includes the initial dot already) and the snapshot 736# format key itself, with a prepended dot 737while(my($fmt,$opt) =each%known_snapshot_formats) { 738my$hash=$refname; 739unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 740next; 741} 742my$sfx=$1; 743# a valid suffix was found, so set the snapshot format 744# and reset the hash parameter 745$input_params{'snapshot_format'} =$fmt; 746$input_params{'hash'} =$hash; 747# we also set the format suffix to the one requested 748# in the URL: this way a request for e.g. .tgz returns 749# a .tgz instead of a .tar.gz 750$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 751last; 752} 753} 754} 755evaluate_path_info(); 756 757our$action=$input_params{'action'}; 758if(defined$action) { 759if(!validate_action($action)) { 760 die_error(400,"Invalid action parameter"); 761} 762} 763 764# parameters which are pathnames 765our$project=$input_params{'project'}; 766if(defined$project) { 767if(!validate_project($project)) { 768undef$project; 769 die_error(404,"No such project"); 770} 771} 772 773our$file_name=$input_params{'file_name'}; 774if(defined$file_name) { 775if(!validate_pathname($file_name)) { 776 die_error(400,"Invalid file parameter"); 777} 778} 779 780our$file_parent=$input_params{'file_parent'}; 781if(defined$file_parent) { 782if(!validate_pathname($file_parent)) { 783 die_error(400,"Invalid file parent parameter"); 784} 785} 786 787# parameters which are refnames 788our$hash=$input_params{'hash'}; 789if(defined$hash) { 790if(!validate_refname($hash)) { 791 die_error(400,"Invalid hash parameter"); 792} 793} 794 795our$hash_parent=$input_params{'hash_parent'}; 796if(defined$hash_parent) { 797if(!validate_refname($hash_parent)) { 798 die_error(400,"Invalid hash parent parameter"); 799} 800} 801 802our$hash_base=$input_params{'hash_base'}; 803if(defined$hash_base) { 804if(!validate_refname($hash_base)) { 805 die_error(400,"Invalid hash base parameter"); 806} 807} 808 809our@extra_options= @{$input_params{'extra_options'}}; 810# @extra_options is always defined, since it can only be (currently) set from 811# CGI, and $cgi->param() returns the empty array in array context if the param 812# is not set 813foreachmy$opt(@extra_options) { 814if(not exists$allowed_options{$opt}) { 815 die_error(400,"Invalid option parameter"); 816} 817if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 818 die_error(400,"Invalid option parameter for this action"); 819} 820} 821 822our$hash_parent_base=$input_params{'hash_parent_base'}; 823if(defined$hash_parent_base) { 824if(!validate_refname($hash_parent_base)) { 825 die_error(400,"Invalid hash parent base parameter"); 826} 827} 828 829# other parameters 830our$page=$input_params{'page'}; 831if(defined$page) { 832if($page=~m/[^0-9]/) { 833 die_error(400,"Invalid page parameter"); 834} 835} 836 837our$searchtype=$input_params{'searchtype'}; 838if(defined$searchtype) { 839if($searchtype=~m/[^a-z]/) { 840 die_error(400,"Invalid searchtype parameter"); 841} 842} 843 844our$search_use_regexp=$input_params{'search_use_regexp'}; 845 846our$searchtext=$input_params{'searchtext'}; 847our$search_regexp; 848if(defined$searchtext) { 849if(length($searchtext) <2) { 850 die_error(403,"At least two characters are required for search parameter"); 851} 852$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 853} 854 855# path to the current git repository 856our$git_dir; 857$git_dir="$projectroot/$project"if$project; 858 859# list of supported snapshot formats 860our@snapshot_fmts= gitweb_get_feature('snapshot'); 861@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts); 862 863# check that the avatar feature is set to a known provider name, 864# and for each provider check if the dependencies are satisfied. 865# if the provider name is invalid or the dependencies are not met, 866# reset $git_avatar to the empty string. 867our($git_avatar) = gitweb_get_feature('avatar'); 868if($git_avatareq'gravatar') { 869$git_avatar=''unless(eval{require Digest::MD5;1; }); 870}elsif($git_avatareq'picon') { 871# no dependencies 872}else{ 873$git_avatar=''; 874} 875 876# dispatch 877if(!defined$action) { 878if(defined$hash) { 879$action= git_get_type($hash); 880}elsif(defined$hash_base&&defined$file_name) { 881$action= git_get_type("$hash_base:$file_name"); 882}elsif(defined$project) { 883$action='summary'; 884}else{ 885$action='project_list'; 886} 887} 888if(!defined($actions{$action})) { 889 die_error(400,"Unknown action"); 890} 891if($action!~m/^(?:opml|project_list|project_index)$/&& 892!$project) { 893 die_error(400,"Project needed"); 894} 895$actions{$action}->(); 896exit; 897 898## ====================================================================== 899## action links 900 901sub href { 902my%params=@_; 903# default is to use -absolute url() i.e. $my_uri 904my$href=$params{-full} ?$my_url:$my_uri; 905 906$params{'project'} =$projectunlessexists$params{'project'}; 907 908if($params{-replay}) { 909while(my($name,$symbol) =each%cgi_param_mapping) { 910if(!exists$params{$name}) { 911$params{$name} =$input_params{$name}; 912} 913} 914} 915 916my$use_pathinfo= gitweb_check_feature('pathinfo'); 917if($use_pathinfoand defined$params{'project'}) { 918# try to put as many parameters as possible in PATH_INFO: 919# - project name 920# - action 921# - hash_parent or hash_parent_base:/file_parent 922# - hash or hash_base:/filename 923# - the snapshot_format as an appropriate suffix 924 925# When the script is the root DirectoryIndex for the domain, 926# $href here would be something like http://gitweb.example.com/ 927# Thus, we strip any trailing / from $href, to spare us double 928# slashes in the final URL 929$href=~ s,/$,,; 930 931# Then add the project name, if present 932$href.="/".esc_url($params{'project'}); 933delete$params{'project'}; 934 935# since we destructively absorb parameters, we keep this 936# boolean that remembers if we're handling a snapshot 937my$is_snapshot=$params{'action'}eq'snapshot'; 938 939# Summary just uses the project path URL, any other action is 940# added to the URL 941if(defined$params{'action'}) { 942$href.="/".esc_url($params{'action'})unless$params{'action'}eq'summary'; 943delete$params{'action'}; 944} 945 946# Next, we put hash_parent_base:/file_parent..hash_base:/file_name, 947# stripping nonexistent or useless pieces 948$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'} 949||$params{'hash_parent'} ||$params{'hash'}); 950if(defined$params{'hash_base'}) { 951if(defined$params{'hash_parent_base'}) { 952$href.= esc_url($params{'hash_parent_base'}); 953# skip the file_parent if it's the same as the file_name 954if(defined$params{'file_parent'}) { 955if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) { 956delete$params{'file_parent'}; 957}elsif($params{'file_parent'} !~/\.\./) { 958$href.=":/".esc_url($params{'file_parent'}); 959delete$params{'file_parent'}; 960} 961} 962$href.=".."; 963delete$params{'hash_parent'}; 964delete$params{'hash_parent_base'}; 965}elsif(defined$params{'hash_parent'}) { 966$href.= esc_url($params{'hash_parent'}).".."; 967delete$params{'hash_parent'}; 968} 969 970$href.= esc_url($params{'hash_base'}); 971if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) { 972$href.=":/".esc_url($params{'file_name'}); 973delete$params{'file_name'}; 974} 975delete$params{'hash'}; 976delete$params{'hash_base'}; 977}elsif(defined$params{'hash'}) { 978$href.= esc_url($params{'hash'}); 979delete$params{'hash'}; 980} 981 982# If the action was a snapshot, we can absorb the 983# snapshot_format parameter too 984if($is_snapshot) { 985my$fmt=$params{'snapshot_format'}; 986# snapshot_format should always be defined when href() 987# is called, but just in case some code forgets, we 988# fall back to the default 989$fmt||=$snapshot_fmts[0]; 990$href.=$known_snapshot_formats{$fmt}{'suffix'}; 991delete$params{'snapshot_format'}; 992} 993} 994 995# now encode the parameters explicitly 996my@result= (); 997for(my$i=0;$i<@cgi_param_mapping;$i+=2) { 998my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]); 999if(defined$params{$name}) {1000if(ref($params{$name})eq"ARRAY") {1001foreachmy$par(@{$params{$name}}) {1002push@result,$symbol."=". esc_param($par);1003}1004}else{1005push@result,$symbol."=". esc_param($params{$name});1006}1007}1008}1009$href.="?".join(';',@result)ifscalar@result;10101011return$href;1012}101310141015## ======================================================================1016## validation, quoting/unquoting and escaping10171018sub validate_action {1019my$input=shift||returnundef;1020returnundefunlessexists$actions{$input};1021return$input;1022}10231024sub validate_project {1025my$input=shift||returnundef;1026if(!validate_pathname($input) ||1027!(-d "$projectroot/$input") ||1028!check_export_ok("$projectroot/$input") ||1029($strict_export&& !project_in_list($input))) {1030returnundef;1031}else{1032return$input;1033}1034}10351036sub validate_pathname {1037my$input=shift||returnundef;10381039# no '.' or '..' as elements of path, i.e. no '.' nor '..'1040# at the beginning, at the end, and between slashes.1041# also this catches doubled slashes1042if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1043returnundef;1044}1045# no null characters1046if($input=~m!\0!) {1047returnundef;1048}1049return$input;1050}10511052sub validate_refname {1053my$input=shift||returnundef;10541055# textual hashes are O.K.1056if($input=~m/^[0-9a-fA-F]{40}$/) {1057return$input;1058}1059# it must be correct pathname1060$input= validate_pathname($input)1061orreturnundef;1062# restrictions on ref name according to git-check-ref-format1063if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1064returnundef;1065}1066return$input;1067}10681069# decode sequences of octets in utf8 into Perl's internal form,1070# which is utf-8 with utf8 flag set if needed. gitweb writes out1071# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1072sub to_utf8 {1073my$str=shift;1074if(utf8::valid($str)) {1075 utf8::decode($str);1076return$str;1077}else{1078return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1079}1080}10811082# quote unsafe chars, but keep the slash, even when it's not1083# correct, but quoted slashes look too horrible in bookmarks1084sub esc_param {1085my$str=shift;1086$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1087$str=~s/ /\+/g;1088return$str;1089}10901091# quote unsafe chars in whole URL, so some charactrs cannot be quoted1092sub esc_url {1093my$str=shift;1094$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X",ord($1))/eg;1095$str=~s/\+/%2B/g;1096$str=~s/ /\+/g;1097return$str;1098}10991100# replace invalid utf8 character with SUBSTITUTION sequence1101sub esc_html {1102my$str=shift;1103my%opts=@_;11041105$str= to_utf8($str);1106$str=$cgi->escapeHTML($str);1107if($opts{'-nbsp'}) {1108$str=~s/ / /g;1109}1110$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1111return$str;1112}11131114# quote control characters and escape filename to HTML1115sub esc_path {1116my$str=shift;1117my%opts=@_;11181119$str= to_utf8($str);1120$str=$cgi->escapeHTML($str);1121if($opts{'-nbsp'}) {1122$str=~s/ / /g;1123}1124$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1125return$str;1126}11271128# Make control characters "printable", using character escape codes (CEC)1129sub quot_cec {1130my$cntrl=shift;1131my%opts=@_;1132my%es= (# character escape codes, aka escape sequences1133"\t"=>'\t',# tab (HT)1134"\n"=>'\n',# line feed (LF)1135"\r"=>'\r',# carrige return (CR)1136"\f"=>'\f',# form feed (FF)1137"\b"=>'\b',# backspace (BS)1138"\a"=>'\a',# alarm (bell) (BEL)1139"\e"=>'\e',# escape (ESC)1140"\013"=>'\v',# vertical tab (VT)1141"\000"=>'\0',# nul character (NUL)1142);1143my$chr= ( (exists$es{$cntrl})1144?$es{$cntrl}1145:sprintf('\%2x',ord($cntrl)) );1146if($opts{-nohtml}) {1147return$chr;1148}else{1149return"<span class=\"cntrl\">$chr</span>";1150}1151}11521153# Alternatively use unicode control pictures codepoints,1154# Unicode "printable representation" (PR)1155sub quot_upr {1156my$cntrl=shift;1157my%opts=@_;11581159my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1160if($opts{-nohtml}) {1161return$chr;1162}else{1163return"<span class=\"cntrl\">$chr</span>";1164}1165}11661167# git may return quoted and escaped filenames1168sub unquote {1169my$str=shift;11701171sub unq {1172my$seq=shift;1173my%es= (# character escape codes, aka escape sequences1174't'=>"\t",# tab (HT, TAB)1175'n'=>"\n",# newline (NL)1176'r'=>"\r",# return (CR)1177'f'=>"\f",# form feed (FF)1178'b'=>"\b",# backspace (BS)1179'a'=>"\a",# alarm (bell) (BEL)1180'e'=>"\e",# escape (ESC)1181'v'=>"\013",# vertical tab (VT)1182);11831184if($seq=~m/^[0-7]{1,3}$/) {1185# octal char sequence1186returnchr(oct($seq));1187}elsif(exists$es{$seq}) {1188# C escape sequence, aka character escape code1189return$es{$seq};1190}1191# quoted ordinary character1192return$seq;1193}11941195if($str=~m/^"(.*)"$/) {1196# needs unquoting1197$str=$1;1198$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1199}1200return$str;1201}12021203# escape tabs (convert tabs to spaces)1204sub untabify {1205my$line=shift;12061207while((my$pos=index($line,"\t")) != -1) {1208if(my$count= (8- ($pos%8))) {1209my$spaces=' ' x $count;1210$line=~s/\t/$spaces/;1211}1212}12131214return$line;1215}12161217sub project_in_list {1218my$project=shift;1219my@list= git_get_projects_list();1220return@list&&scalar(grep{$_->{'path'}eq$project}@list);1221}12221223## ----------------------------------------------------------------------1224## HTML aware string manipulation12251226# Try to chop given string on a word boundary between position1227# $len and $len+$add_len. If there is no word boundary there,1228# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1229# (marking chopped part) would be longer than given string.1230sub chop_str {1231my$str=shift;1232my$len=shift;1233my$add_len=shift||10;1234my$where=shift||'right';# 'left' | 'center' | 'right'12351236# Make sure perl knows it is utf8 encoded so we don't1237# cut in the middle of a utf8 multibyte char.1238$str= to_utf8($str);12391240# allow only $len chars, but don't cut a word if it would fit in $add_len1241# if it doesn't fit, cut it if it's still longer than the dots we would add1242# remove chopped character entities entirely12431244# when chopping in the middle, distribute $len into left and right part1245# return early if chopping wouldn't make string shorter1246if($whereeq'center') {1247return$strif($len+5>=length($str));# filler is length 51248$len=int($len/2);1249}else{1250return$strif($len+4>=length($str));# filler is length 41251}12521253# regexps: ending and beginning with word part up to $add_len1254my$endre=qr/.{$len}\w{0,$add_len}/;1255my$begre=qr/\w{0,$add_len}.{$len}/;12561257if($whereeq'left') {1258$str=~m/^(.*?)($begre)$/;1259my($lead,$body) = ($1,$2);1260if(length($lead) >4) {1261$body=~s/^[^;]*;//if($lead=~m/&[^;]*$/);1262$lead=" ...";1263}1264return"$lead$body";12651266}elsif($whereeq'center') {1267$str=~m/^($endre)(.*)$/;1268my($left,$str) = ($1,$2);1269$str=~m/^(.*?)($begre)$/;1270my($mid,$right) = ($1,$2);1271if(length($mid) >5) {1272$left=~s/&[^;]*$//;1273$right=~s/^[^;]*;//if($mid=~m/&[^;]*$/);1274$mid=" ... ";1275}1276return"$left$mid$right";12771278}else{1279$str=~m/^($endre)(.*)$/;1280my$body=$1;1281my$tail=$2;1282if(length($tail) >4) {1283$body=~s/&[^;]*$//;1284$tail="... ";1285}1286return"$body$tail";1287}1288}12891290# takes the same arguments as chop_str, but also wraps a <span> around the1291# result with a title attribute if it does get chopped. Additionally, the1292# string is HTML-escaped.1293sub chop_and_escape_str {1294my($str) =@_;12951296my$chopped= chop_str(@_);1297if($choppedeq$str) {1298return esc_html($chopped);1299}else{1300$str=~s/[[:cntrl:]]/?/g;1301return$cgi->span({-title=>$str}, esc_html($chopped));1302}1303}13041305## ----------------------------------------------------------------------1306## functions returning short strings13071308# CSS class for given age value (in seconds)1309sub age_class {1310my$age=shift;13111312if(!defined$age) {1313return"noage";1314}elsif($age<60*60*2) {1315return"age0";1316}elsif($age<60*60*24*2) {1317return"age1";1318}else{1319return"age2";1320}1321}13221323# convert age in seconds to "nn units ago" string1324sub age_string {1325my$age=shift;1326my$age_str;13271328if($age>60*60*24*365*2) {1329$age_str= (int$age/60/60/24/365);1330$age_str.=" years ago";1331}elsif($age>60*60*24*(365/12)*2) {1332$age_str=int$age/60/60/24/(365/12);1333$age_str.=" months ago";1334}elsif($age>60*60*24*7*2) {1335$age_str=int$age/60/60/24/7;1336$age_str.=" weeks ago";1337}elsif($age>60*60*24*2) {1338$age_str=int$age/60/60/24;1339$age_str.=" days ago";1340}elsif($age>60*60*2) {1341$age_str=int$age/60/60;1342$age_str.=" hours ago";1343}elsif($age>60*2) {1344$age_str=int$age/60;1345$age_str.=" min ago";1346}elsif($age>2) {1347$age_str=int$age;1348$age_str.=" sec ago";1349}else{1350$age_str.=" right now";1351}1352return$age_str;1353}13541355useconstant{1356 S_IFINVALID =>0030000,1357 S_IFGITLINK =>0160000,1358};13591360# submodule/subproject, a commit object reference1361sub S_ISGITLINK {1362my$mode=shift;13631364return(($mode& S_IFMT) == S_IFGITLINK)1365}13661367# convert file mode in octal to symbolic file mode string1368sub mode_str {1369my$mode=oct shift;13701371if(S_ISGITLINK($mode)) {1372return'm---------';1373}elsif(S_ISDIR($mode& S_IFMT)) {1374return'drwxr-xr-x';1375}elsif(S_ISLNK($mode)) {1376return'lrwxrwxrwx';1377}elsif(S_ISREG($mode)) {1378# git cares only about the executable bit1379if($mode& S_IXUSR) {1380return'-rwxr-xr-x';1381}else{1382return'-rw-r--r--';1383};1384}else{1385return'----------';1386}1387}13881389# convert file mode in octal to file type string1390sub file_type {1391my$mode=shift;13921393if($mode!~m/^[0-7]+$/) {1394return$mode;1395}else{1396$mode=oct$mode;1397}13981399if(S_ISGITLINK($mode)) {1400return"submodule";1401}elsif(S_ISDIR($mode& S_IFMT)) {1402return"directory";1403}elsif(S_ISLNK($mode)) {1404return"symlink";1405}elsif(S_ISREG($mode)) {1406return"file";1407}else{1408return"unknown";1409}1410}14111412# convert file mode in octal to file type description string1413sub file_type_long {1414my$mode=shift;14151416if($mode!~m/^[0-7]+$/) {1417return$mode;1418}else{1419$mode=oct$mode;1420}14211422if(S_ISGITLINK($mode)) {1423return"submodule";1424}elsif(S_ISDIR($mode& S_IFMT)) {1425return"directory";1426}elsif(S_ISLNK($mode)) {1427return"symlink";1428}elsif(S_ISREG($mode)) {1429if($mode& S_IXUSR) {1430return"executable";1431}else{1432return"file";1433};1434}else{1435return"unknown";1436}1437}143814391440## ----------------------------------------------------------------------1441## functions returning short HTML fragments, or transforming HTML fragments1442## which don't belong to other sections14431444# format line of commit message.1445sub format_log_line_html {1446my$line=shift;14471448$line= esc_html($line, -nbsp=>1);1449$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1450$cgi->a({-href => href(action=>"object", hash=>$1),1451-class=>"text"},$1);1452}eg;14531454return$line;1455}14561457# format marker of refs pointing to given object14581459# the destination action is chosen based on object type and current context:1460# - for annotated tags, we choose the tag view unless it's the current view1461# already, in which case we go to shortlog view1462# - for other refs, we keep the current view if we're in history, shortlog or1463# log view, and select shortlog otherwise1464sub format_ref_marker {1465my($refs,$id) =@_;1466my$markers='';14671468if(defined$refs->{$id}) {1469foreachmy$ref(@{$refs->{$id}}) {1470# this code exploits the fact that non-lightweight tags are the1471# only indirect objects, and that they are the only objects for which1472# we want to use tag instead of shortlog as action1473my($type,$name) =qw();1474my$indirect= ($ref=~s/\^\{\}$//);1475# e.g. tags/v2.6.11 or heads/next1476if($ref=~m!^(.*?)s?/(.*)$!) {1477$type=$1;1478$name=$2;1479}else{1480$type="ref";1481$name=$ref;1482}14831484my$class=$type;1485$class.=" indirect"if$indirect;14861487my$dest_action="shortlog";14881489if($indirect) {1490$dest_action="tag"unless$actioneq"tag";1491}elsif($action=~/^(history|(short)?log)$/) {1492$dest_action=$action;1493}14941495my$dest="";1496$dest.="refs/"unless$ref=~ m!^refs/!;1497$dest.=$ref;14981499my$link=$cgi->a({1500-href => href(1501 action=>$dest_action,1502 hash=>$dest1503)},$name);15041505$markers.=" <span class=\"$class\"title=\"$ref\">".1506$link."</span>";1507}1508}15091510if($markers) {1511return' <span class="refs">'.$markers.'</span>';1512}else{1513return"";1514}1515}15161517# format, perhaps shortened and with markers, title line1518sub format_subject_html {1519my($long,$short,$href,$extra) =@_;1520$extra=''unlessdefined($extra);15211522if(length($short) <length($long)) {1523$long=~s/[[:cntrl:]]/?/g;1524return$cgi->a({-href =>$href, -class=>"list subject",1525-title => to_utf8($long)},1526 esc_html($short)) .$extra;1527}else{1528return$cgi->a({-href =>$href, -class=>"list subject"},1529 esc_html($long)) .$extra;1530}1531}15321533# Rather than recomputing the url for an email multiple times, we cache it1534# after the first hit. This gives a visible benefit in views where the avatar1535# for the same email is used repeatedly (e.g. shortlog).1536# The cache is shared by all avatar engines (currently gravatar only), which1537# are free to use it as preferred. Since only one avatar engine is used for any1538# given page, there's no risk for cache conflicts.1539our%avatar_cache= ();15401541# Compute the picon url for a given email, by using the picon search service over at1542# http://www.cs.indiana.edu/picons/search.html1543sub picon_url {1544my$email=lc shift;1545if(!$avatar_cache{$email}) {1546my($user,$domain) =split('@',$email);1547$avatar_cache{$email} =1548"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".1549"$domain/$user/".1550"users+domains+unknown/up/single";1551}1552return$avatar_cache{$email};1553}15541555# Compute the gravatar url for a given email, if it's not in the cache already.1556# Gravatar stores only the part of the URL before the size, since that's the1557# one computationally more expensive. This also allows reuse of the cache for1558# different sizes (for this particular engine).1559sub gravatar_url {1560my$email=lc shift;1561my$size=shift;1562$avatar_cache{$email} ||=1563"http://www.gravatar.com/avatar/".1564 Digest::MD5::md5_hex($email) ."?s=";1565return$avatar_cache{$email} .$size;1566}15671568# Insert an avatar for the given $email at the given $size if the feature1569# is enabled.1570sub git_get_avatar {1571my($email,%opts) =@_;1572my$pre_white= ($opts{-pad_before} ?" ":"");1573my$post_white= ($opts{-pad_after} ?" ":"");1574$opts{-size} ||='default';1575my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};1576my$url="";1577if($git_avatareq'gravatar') {1578$url= gravatar_url($email,$size);1579}elsif($git_avatareq'picon') {1580$url= picon_url($email);1581}1582# Other providers can be added by extending the if chain, defining $url1583# as needed. If no variant puts something in $url, we assume avatars1584# are completely disabled/unavailable.1585if($url) {1586return$pre_white.1587"<img width=\"$size\"".1588"class=\"avatar\"".1589"src=\"$url\"".1590"alt=\"\"".1591"/>".$post_white;1592}else{1593return"";1594}1595}15961597sub format_search_author {1598my($author,$searchtype,$displaytext) =@_;1599my$have_search= gitweb_check_feature('search');16001601if($have_search) {1602my$performed="";1603if($searchtypeeq'author') {1604$performed="authored";1605}elsif($searchtypeeq'committer') {1606$performed="committed";1607}16081609return$cgi->a({-href => href(action=>"search", hash=>$hash,1610 searchtext=>$author,1611 searchtype=>$searchtype),class=>"list",1612 title=>"Search for commits$performedby$author"},1613$displaytext);16141615}else{1616return$displaytext;1617}1618}16191620# format the author name of the given commit with the given tag1621# the author name is chopped and escaped according to the other1622# optional parameters (see chop_str).1623sub format_author_html {1624my$tag=shift;1625my$co=shift;1626my$author= chop_and_escape_str($co->{'author_name'},@_);1627return"<$tagclass=\"author\">".1628 format_search_author($co->{'author_name'},"author",1629 git_get_avatar($co->{'author_email'}, -pad_after =>1) .1630$author) .1631"</$tag>";1632}16331634# format git diff header line, i.e. "diff --(git|combined|cc) ..."1635sub format_git_diff_header_line {1636my$line=shift;1637my$diffinfo=shift;1638my($from,$to) =@_;16391640if($diffinfo->{'nparents'}) {1641# combined diff1642$line=~s!^(diff (.*?) )"?.*$!$1!;1643if($to->{'href'}) {1644$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1645 esc_path($to->{'file'}));1646}else{# file was deleted (no href)1647$line.= esc_path($to->{'file'});1648}1649}else{1650# "ordinary" diff1651$line=~s!^(diff (.*?) )"?a/.*$!$1!;1652if($from->{'href'}) {1653$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1654'a/'. esc_path($from->{'file'}));1655}else{# file was added (no href)1656$line.='a/'. esc_path($from->{'file'});1657}1658$line.=' ';1659if($to->{'href'}) {1660$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1661'b/'. esc_path($to->{'file'}));1662}else{# file was deleted1663$line.='b/'. esc_path($to->{'file'});1664}1665}16661667return"<div class=\"diff header\">$line</div>\n";1668}16691670# format extended diff header line, before patch itself1671sub format_extended_diff_header_line {1672my$line=shift;1673my$diffinfo=shift;1674my($from,$to) =@_;16751676# match <path>1677if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1678$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1679 esc_path($from->{'file'}));1680}1681if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1682$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1683 esc_path($to->{'file'}));1684}1685# match single <mode>1686if($line=~m/\s(\d{6})$/) {1687$line.='<span class="info"> ('.1688 file_type_long($1) .1689')</span>';1690}1691# match <hash>1692if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1693# can match only for combined diff1694$line='index ';1695for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1696if($from->{'href'}[$i]) {1697$line.=$cgi->a({-href=>$from->{'href'}[$i],1698-class=>"hash"},1699substr($diffinfo->{'from_id'}[$i],0,7));1700}else{1701$line.='0' x 7;1702}1703# separator1704$line.=','if($i<$diffinfo->{'nparents'} -1);1705}1706$line.='..';1707if($to->{'href'}) {1708$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1709substr($diffinfo->{'to_id'},0,7));1710}else{1711$line.='0' x 7;1712}17131714}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1715# can match only for ordinary diff1716my($from_link,$to_link);1717if($from->{'href'}) {1718$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1719substr($diffinfo->{'from_id'},0,7));1720}else{1721$from_link='0' x 7;1722}1723if($to->{'href'}) {1724$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1725substr($diffinfo->{'to_id'},0,7));1726}else{1727$to_link='0' x 7;1728}1729my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1730$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1731}17321733return$line."<br/>\n";1734}17351736# format from-file/to-file diff header1737sub format_diff_from_to_header {1738my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1739my$line;1740my$result='';17411742$line=$from_line;1743#assert($line =~ m/^---/) if DEBUG;1744# no extra formatting for "^--- /dev/null"1745if(!$diffinfo->{'nparents'}) {1746# ordinary (single parent) diff1747if($line=~m!^--- "?a/!) {1748if($from->{'href'}) {1749$line='--- a/'.1750$cgi->a({-href=>$from->{'href'}, -class=>"path"},1751 esc_path($from->{'file'}));1752}else{1753$line='--- a/'.1754 esc_path($from->{'file'});1755}1756}1757$result.= qq!<div class="diff from_file">$line</div>\n!;17581759}else{1760# combined diff (merge commit)1761for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1762if($from->{'href'}[$i]) {1763$line='--- '.1764$cgi->a({-href=>href(action=>"blobdiff",1765 hash_parent=>$diffinfo->{'from_id'}[$i],1766 hash_parent_base=>$parents[$i],1767 file_parent=>$from->{'file'}[$i],1768 hash=>$diffinfo->{'to_id'},1769 hash_base=>$hash,1770 file_name=>$to->{'file'}),1771-class=>"path",1772-title=>"diff". ($i+1)},1773$i+1) .1774'/'.1775$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1776 esc_path($from->{'file'}[$i]));1777}else{1778$line='--- /dev/null';1779}1780$result.= qq!<div class="diff from_file">$line</div>\n!;1781}1782}17831784$line=$to_line;1785#assert($line =~ m/^\+\+\+/) if DEBUG;1786# no extra formatting for "^+++ /dev/null"1787if($line=~m!^\+\+\+ "?b/!) {1788if($to->{'href'}) {1789$line='+++ b/'.1790$cgi->a({-href=>$to->{'href'}, -class=>"path"},1791 esc_path($to->{'file'}));1792}else{1793$line='+++ b/'.1794 esc_path($to->{'file'});1795}1796}1797$result.= qq!<div class="diff to_file">$line</div>\n!;17981799return$result;1800}18011802# create note for patch simplified by combined diff1803sub format_diff_cc_simplified {1804my($diffinfo,@parents) =@_;1805my$result='';18061807$result.="<div class=\"diff header\">".1808"diff --cc ";1809if(!is_deleted($diffinfo)) {1810$result.=$cgi->a({-href => href(action=>"blob",1811 hash_base=>$hash,1812 hash=>$diffinfo->{'to_id'},1813 file_name=>$diffinfo->{'to_file'}),1814-class=>"path"},1815 esc_path($diffinfo->{'to_file'}));1816}else{1817$result.= esc_path($diffinfo->{'to_file'});1818}1819$result.="</div>\n".# class="diff header"1820"<div class=\"diff nodifferences\">".1821"Simple merge".1822"</div>\n";# class="diff nodifferences"18231824return$result;1825}18261827# format patch (diff) line (not to be used for diff headers)1828sub format_diff_line {1829my$line=shift;1830my($from,$to) =@_;1831my$diff_class="";18321833chomp$line;18341835if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1836# combined diff1837my$prefix=substr($line,0,scalar@{$from->{'href'}});1838if($line=~m/^\@{3}/) {1839$diff_class=" chunk_header";1840}elsif($line=~m/^\\/) {1841$diff_class=" incomplete";1842}elsif($prefix=~tr/+/+/) {1843$diff_class=" add";1844}elsif($prefix=~tr/-/-/) {1845$diff_class=" rem";1846}1847}else{1848# assume ordinary diff1849my$char=substr($line,0,1);1850if($chareq'+') {1851$diff_class=" add";1852}elsif($chareq'-') {1853$diff_class=" rem";1854}elsif($chareq'@') {1855$diff_class=" chunk_header";1856}elsif($chareq"\\") {1857$diff_class=" incomplete";1858}1859}1860$line= untabify($line);1861if($from&&$to&&$line=~m/^\@{2} /) {1862my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1863$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;18641865$from_lines=0unlessdefined$from_lines;1866$to_lines=0unlessdefined$to_lines;18671868if($from->{'href'}) {1869$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1870-class=>"list"},$from_text);1871}1872if($to->{'href'}) {1873$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1874-class=>"list"},$to_text);1875}1876$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1877"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1878return"<div class=\"diff$diff_class\">$line</div>\n";1879}elsif($from&&$to&&$line=~m/^\@{3}/) {1880my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1881my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);18821883@from_text=split(' ',$ranges);1884for(my$i=0;$i<@from_text; ++$i) {1885($from_start[$i],$from_nlines[$i]) =1886(split(',',substr($from_text[$i],1)),0);1887}18881889$to_text=pop@from_text;1890$to_start=pop@from_start;1891$to_nlines=pop@from_nlines;18921893$line="<span class=\"chunk_info\">$prefix";1894for(my$i=0;$i<@from_text; ++$i) {1895if($from->{'href'}[$i]) {1896$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1897-class=>"list"},$from_text[$i]);1898}else{1899$line.=$from_text[$i];1900}1901$line.=" ";1902}1903if($to->{'href'}) {1904$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1905-class=>"list"},$to_text);1906}else{1907$line.=$to_text;1908}1909$line.="$prefix</span>".1910"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1911return"<div class=\"diff$diff_class\">$line</div>\n";1912}1913return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1914}19151916# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1917# linked. Pass the hash of the tree/commit to snapshot.1918sub format_snapshot_links {1919my($hash) =@_;1920my$num_fmts=@snapshot_fmts;1921if($num_fmts>1) {1922# A parenthesized list of links bearing format names.1923# e.g. "snapshot (_tar.gz_ _zip_)"1924return"snapshot (".join(' ',map1925$cgi->a({1926-href => href(1927 action=>"snapshot",1928 hash=>$hash,1929 snapshot_format=>$_1930)1931},$known_snapshot_formats{$_}{'display'})1932,@snapshot_fmts) .")";1933}elsif($num_fmts==1) {1934# A single "snapshot" link whose tooltip bears the format name.1935# i.e. "_snapshot_"1936my($fmt) =@snapshot_fmts;1937return1938$cgi->a({1939-href => href(1940 action=>"snapshot",1941 hash=>$hash,1942 snapshot_format=>$fmt1943),1944-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"1945},"snapshot");1946}else{# $num_fmts == 01947returnundef;1948}1949}19501951## ......................................................................1952## functions returning values to be passed, perhaps after some1953## transformation, to other functions; e.g. returning arguments to href()19541955# returns hash to be passed to href to generate gitweb URL1956# in -title key it returns description of link1957sub get_feed_info {1958my$format=shift||'Atom';1959my%res= (action =>lc($format));19601961# feed links are possible only for project views1962return unless(defined$project);1963# some views should link to OPML, or to generic project feed,1964# or don't have specific feed yet (so they should use generic)1965return if($action=~/^(?:tags|heads|forks|tag|search)$/x);19661967my$branch;1968# branches refs uses 'refs/heads/' prefix (fullname) to differentiate1969# from tag links; this also makes possible to detect branch links1970if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||1971(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {1972$branch=$1;1973}1974# find log type for feed description (title)1975my$type='log';1976if(defined$file_name) {1977$type="history of$file_name";1978$type.="/"if($actioneq'tree');1979$type.=" on '$branch'"if(defined$branch);1980}else{1981$type="log of$branch"if(defined$branch);1982}19831984$res{-title} =$type;1985$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);1986$res{'file_name'} =$file_name;19871988return%res;1989}19901991## ----------------------------------------------------------------------1992## git utility subroutines, invoking git commands19931994# returns path to the core git executable and the --git-dir parameter as list1995sub git_cmd {1996return$GIT,'--git-dir='.$git_dir;1997}19981999# quote the given arguments for passing them to the shell2000# quote_command("command", "arg 1", "arg with ' and ! characters")2001# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2002# Try to avoid using this function wherever possible.2003sub quote_command {2004returnjoin(' ',2005map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2006}20072008# get HEAD ref of given project as hash2009sub git_get_head_hash {2010my$project=shift;2011my$o_git_dir=$git_dir;2012my$retval=undef;2013$git_dir="$projectroot/$project";2014if(open my$fd,"-|", git_cmd(),"rev-parse","--verify","HEAD") {2015my$head= <$fd>;2016close$fd;2017if(defined$head&&$head=~/^([0-9a-fA-F]{40})$/) {2018$retval=$1;2019}2020}2021if(defined$o_git_dir) {2022$git_dir=$o_git_dir;2023}2024return$retval;2025}20262027# get type of given object2028sub git_get_type {2029my$hash=shift;20302031open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2032my$type= <$fd>;2033close$fdorreturn;2034chomp$type;2035return$type;2036}20372038# repository configuration2039our$config_file='';2040our%config;20412042# store multiple values for single key as anonymous array reference2043# single values stored directly in the hash, not as [ <value> ]2044sub hash_set_multi {2045my($hash,$key,$value) =@_;20462047if(!exists$hash->{$key}) {2048$hash->{$key} =$value;2049}elsif(!ref$hash->{$key}) {2050$hash->{$key} = [$hash->{$key},$value];2051}else{2052push@{$hash->{$key}},$value;2053}2054}20552056# return hash of git project configuration2057# optionally limited to some section, e.g. 'gitweb'2058sub git_parse_project_config {2059my$section_regexp=shift;2060my%config;20612062local$/="\0";20632064open my$fh,"-|", git_cmd(),"config",'-z','-l',2065orreturn;20662067while(my$keyval= <$fh>) {2068chomp$keyval;2069my($key,$value) =split(/\n/,$keyval,2);20702071 hash_set_multi(\%config,$key,$value)2072if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2073}2074close$fh;20752076return%config;2077}20782079# convert config value to boolean: 'true' or 'false'2080# no value, number > 0, 'true' and 'yes' values are true2081# rest of values are treated as false (never as error)2082sub config_to_bool {2083my$val=shift;20842085return1if!defined$val;# section.key20862087# strip leading and trailing whitespace2088$val=~s/^\s+//;2089$val=~s/\s+$//;20902091return(($val=~/^\d+$/&&$val) ||# section.key = 12092($val=~/^(?:true|yes)$/i));# section.key = true2093}20942095# convert config value to simple decimal number2096# an optional value suffix of 'k', 'm', or 'g' will cause the value2097# to be multiplied by 1024, 1048576, or 10737418242098sub config_to_int {2099my$val=shift;21002101# strip leading and trailing whitespace2102$val=~s/^\s+//;2103$val=~s/\s+$//;21042105if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2106$unit=lc($unit);2107# unknown unit is treated as 12108return$num* ($uniteq'g'?1073741824:2109$uniteq'm'?1048576:2110$uniteq'k'?1024:1);2111}2112return$val;2113}21142115# convert config value to array reference, if needed2116sub config_to_multi {2117my$val=shift;21182119returnref($val) ?$val: (defined($val) ? [$val] : []);2120}21212122sub git_get_project_config {2123my($key,$type) =@_;21242125# key sanity check2126return unless($key);2127$key=~s/^gitweb\.//;2128return if($key=~m/\W/);21292130# type sanity check2131if(defined$type) {2132$type=~s/^--//;2133$type=undef2134unless($typeeq'bool'||$typeeq'int');2135}21362137# get config2138if(!defined$config_file||2139$config_filene"$git_dir/config") {2140%config= git_parse_project_config('gitweb');2141$config_file="$git_dir/config";2142}21432144# check if config variable (key) exists2145return unlessexists$config{"gitweb.$key"};21462147# ensure given type2148if(!defined$type) {2149return$config{"gitweb.$key"};2150}elsif($typeeq'bool') {2151# backward compatibility: 'git config --bool' returns true/false2152return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2153}elsif($typeeq'int') {2154return config_to_int($config{"gitweb.$key"});2155}2156return$config{"gitweb.$key"};2157}21582159# get hash of given path at given ref2160sub git_get_hash_by_path {2161my$base=shift;2162my$path=shift||returnundef;2163my$type=shift;21642165$path=~ s,/+$,,;21662167open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2168or die_error(500,"Open git-ls-tree failed");2169my$line= <$fd>;2170close$fdorreturnundef;21712172if(!defined$line) {2173# there is no tree or hash given by $path at $base2174returnundef;2175}21762177#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2178$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2179if(defined$type&&$typene$2) {2180# type doesn't match2181returnundef;2182}2183return$3;2184}21852186# get path of entry with given hash at given tree-ish (ref)2187# used to get 'from' filename for combined diff (merge commit) for renames2188sub git_get_path_by_hash {2189my$base=shift||return;2190my$hash=shift||return;21912192local$/="\0";21932194open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2195orreturnundef;2196while(my$line= <$fd>) {2197chomp$line;21982199#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2200#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2201if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2202close$fd;2203return$1;2204}2205}2206close$fd;2207returnundef;2208}22092210## ......................................................................2211## git utility functions, directly accessing git repository22122213sub git_get_project_description {2214my$path=shift;22152216$git_dir="$projectroot/$path";2217open my$fd,'<',"$git_dir/description"2218orreturn git_get_project_config('description');2219my$descr= <$fd>;2220close$fd;2221if(defined$descr) {2222chomp$descr;2223}2224return$descr;2225}22262227sub git_get_project_ctags {2228my$path=shift;2229my$ctags= {};22302231$git_dir="$projectroot/$path";2232opendir my$dh,"$git_dir/ctags"2233orreturn$ctags;2234foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2235open my$ct,'<',$_ornext;2236my$val= <$ct>;2237chomp$val;2238close$ct;2239my$ctag=$_;$ctag=~ s#.*/##;2240$ctags->{$ctag} =$val;2241}2242closedir$dh;2243$ctags;2244}22452246sub git_populate_project_tagcloud {2247my$ctags=shift;22482249# First, merge different-cased tags; tags vote on casing2250my%ctags_lc;2251foreach(keys%$ctags) {2252$ctags_lc{lc$_}->{count} +=$ctags->{$_};2253if(not$ctags_lc{lc$_}->{topcount}2254or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2255$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2256$ctags_lc{lc$_}->{topname} =$_;2257}2258}22592260my$cloud;2261if(eval{require HTML::TagCloud;1; }) {2262$cloud= HTML::TagCloud->new;2263foreach(sort keys%ctags_lc) {2264# Pad the title with spaces so that the cloud looks2265# less crammed.2266my$title=$ctags_lc{$_}->{topname};2267$title=~s/ / /g;2268$title=~s/^/ /g;2269$title=~s/$/ /g;2270$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2271}2272}else{2273$cloud= \%ctags_lc;2274}2275$cloud;2276}22772278sub git_show_project_tagcloud {2279my($cloud,$count) =@_;2280print STDERR ref($cloud)."..\n";2281if(ref$cloudeq'HTML::TagCloud') {2282return$cloud->html_and_css($count);2283}else{2284my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2285return'<p align="center">'.join(', ',map{2286"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"2287}splice(@tags,0,$count)) .'</p>';2288}2289}22902291sub git_get_project_url_list {2292my$path=shift;22932294$git_dir="$projectroot/$path";2295open my$fd,'<',"$git_dir/cloneurl"2296orreturnwantarray?2297@{ config_to_multi(git_get_project_config('url')) } :2298 config_to_multi(git_get_project_config('url'));2299my@git_project_url_list=map{chomp;$_} <$fd>;2300close$fd;23012302returnwantarray?@git_project_url_list: \@git_project_url_list;2303}23042305sub git_get_projects_list {2306my($filter) =@_;2307my@list;23082309$filter||='';2310$filter=~s/\.git$//;23112312my$check_forks= gitweb_check_feature('forks');23132314if(-d $projects_list) {2315# search in directory2316my$dir=$projects_list. ($filter?"/$filter":'');2317# remove the trailing "/"2318$dir=~s!/+$!!;2319my$pfxlen=length("$dir");2320my$pfxdepth= ($dir=~tr!/!!);23212322 File::Find::find({2323 follow_fast =>1,# follow symbolic links2324 follow_skip =>2,# ignore duplicates2325 dangling_symlinks =>0,# ignore dangling symlinks, silently2326 wanted =>sub{2327# skip project-list toplevel, if we get it.2328return if(m!^[/.]$!);2329# only directories can be git repositories2330return unless(-d $_);2331# don't traverse too deep (Find is super slow on os x)2332if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2333$File::Find::prune =1;2334return;2335}23362337my$subdir=substr($File::Find::name,$pfxlen+1);2338# we check related file in $projectroot2339my$path= ($filter?"$filter/":'') .$subdir;2340if(check_export_ok("$projectroot/$path")) {2341push@list, { path =>$path};2342$File::Find::prune =1;2343}2344},2345},"$dir");23462347}elsif(-f $projects_list) {2348# read from file(url-encoded):2349# 'git%2Fgit.git Linus+Torvalds'2350# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2351# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2352my%paths;2353open my$fd,'<',$projects_listorreturn;2354 PROJECT:2355while(my$line= <$fd>) {2356chomp$line;2357my($path,$owner) =split' ',$line;2358$path= unescape($path);2359$owner= unescape($owner);2360if(!defined$path) {2361next;2362}2363if($filterne'') {2364# looking for forks;2365my$pfx=substr($path,0,length($filter));2366if($pfxne$filter) {2367next PROJECT;2368}2369my$sfx=substr($path,length($filter));2370if($sfx!~/^\/.*\.git$/) {2371next PROJECT;2372}2373}elsif($check_forks) {2374 PATH:2375foreachmy$filter(keys%paths) {2376# looking for forks;2377my$pfx=substr($path,0,length($filter));2378if($pfxne$filter) {2379next PATH;2380}2381my$sfx=substr($path,length($filter));2382if($sfx!~/^\/.*\.git$/) {2383next PATH;2384}2385# is a fork, don't include it in2386# the list2387next PROJECT;2388}2389}2390if(check_export_ok("$projectroot/$path")) {2391my$pr= {2392 path =>$path,2393 owner => to_utf8($owner),2394};2395push@list,$pr;2396(my$forks_path=$path) =~s/\.git$//;2397$paths{$forks_path}++;2398}2399}2400close$fd;2401}2402return@list;2403}24042405our$gitweb_project_owner=undef;2406sub git_get_project_list_from_file {24072408return if(defined$gitweb_project_owner);24092410$gitweb_project_owner= {};2411# read from file (url-encoded):2412# 'git%2Fgit.git Linus+Torvalds'2413# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2414# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2415if(-f $projects_list) {2416open(my$fd,'<',$projects_list);2417while(my$line= <$fd>) {2418chomp$line;2419my($pr,$ow) =split' ',$line;2420$pr= unescape($pr);2421$ow= unescape($ow);2422$gitweb_project_owner->{$pr} = to_utf8($ow);2423}2424close$fd;2425}2426}24272428sub git_get_project_owner {2429my$project=shift;2430my$owner;24312432returnundefunless$project;2433$git_dir="$projectroot/$project";24342435if(!defined$gitweb_project_owner) {2436 git_get_project_list_from_file();2437}24382439if(exists$gitweb_project_owner->{$project}) {2440$owner=$gitweb_project_owner->{$project};2441}2442if(!defined$owner){2443$owner= git_get_project_config('owner');2444}2445if(!defined$owner) {2446$owner= get_file_owner("$git_dir");2447}24482449return$owner;2450}24512452sub git_get_last_activity {2453my($path) =@_;2454my$fd;24552456$git_dir="$projectroot/$path";2457open($fd,"-|", git_cmd(),'for-each-ref',2458'--format=%(committer)',2459'--sort=-committerdate',2460'--count=1',2461'refs/heads')orreturn;2462my$most_recent= <$fd>;2463close$fdorreturn;2464if(defined$most_recent&&2465$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2466my$timestamp=$1;2467my$age=time-$timestamp;2468return($age, age_string($age));2469}2470return(undef,undef);2471}24722473sub git_get_references {2474my$type=shift||"";2475my%refs;2476# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112477# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2478open my$fd,"-|", git_cmd(),"show-ref","--dereference",2479($type? ("--","refs/$type") : ())# use -- <pattern> if $type2480orreturn;24812482while(my$line= <$fd>) {2483chomp$line;2484if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2485if(defined$refs{$1}) {2486push@{$refs{$1}},$2;2487}else{2488$refs{$1} = [$2];2489}2490}2491}2492close$fdorreturn;2493return \%refs;2494}24952496sub git_get_rev_name_tags {2497my$hash=shift||returnundef;24982499open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2500orreturn;2501my$name_rev= <$fd>;2502close$fd;25032504if($name_rev=~ m|^$hash tags/(.*)$|) {2505return$1;2506}else{2507# catches also '$hash undefined' output2508returnundef;2509}2510}25112512## ----------------------------------------------------------------------2513## parse to hash functions25142515sub parse_date {2516my$epoch=shift;2517my$tz=shift||"-0000";25182519my%date;2520my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2521my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2522my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2523$date{'hour'} =$hour;2524$date{'minute'} =$min;2525$date{'mday'} =$mday;2526$date{'day'} =$days[$wday];2527$date{'month'} =$months[$mon];2528$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2529$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2530$date{'mday-time'} =sprintf"%d%s%02d:%02d",2531$mday,$months[$mon],$hour,$min;2532$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",25331900+$year,1+$mon,$mday,$hour,$min,$sec;25342535$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2536my$local=$epoch+ ((int$1+ ($2/60)) *3600);2537($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2538$date{'hour_local'} =$hour;2539$date{'minute_local'} =$min;2540$date{'tz_local'} =$tz;2541$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",25421900+$year,$mon+1,$mday,2543$hour,$min,$sec,$tz);2544return%date;2545}25462547sub parse_tag {2548my$tag_id=shift;2549my%tag;2550my@comment;25512552open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2553$tag{'id'} =$tag_id;2554while(my$line= <$fd>) {2555chomp$line;2556if($line=~m/^object ([0-9a-fA-F]{40})$/) {2557$tag{'object'} =$1;2558}elsif($line=~m/^type (.+)$/) {2559$tag{'type'} =$1;2560}elsif($line=~m/^tag (.+)$/) {2561$tag{'name'} =$1;2562}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2563$tag{'author'} =$1;2564$tag{'author_epoch'} =$2;2565$tag{'author_tz'} =$3;2566if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {2567$tag{'author_name'} =$1;2568$tag{'author_email'} =$2;2569}else{2570$tag{'author_name'} =$tag{'author'};2571}2572}elsif($line=~m/--BEGIN/) {2573push@comment,$line;2574last;2575}elsif($lineeq"") {2576last;2577}2578}2579push@comment, <$fd>;2580$tag{'comment'} = \@comment;2581close$fdorreturn;2582if(!defined$tag{'name'}) {2583return2584};2585return%tag2586}25872588sub parse_commit_text {2589my($commit_text,$withparents) =@_;2590my@commit_lines=split'\n',$commit_text;2591my%co;25922593pop@commit_lines;# Remove '\0'25942595if(!@commit_lines) {2596return;2597}25982599my$header=shift@commit_lines;2600if($header!~m/^[0-9a-fA-F]{40}/) {2601return;2602}2603($co{'id'},my@parents) =split' ',$header;2604while(my$line=shift@commit_lines) {2605last if$lineeq"\n";2606if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2607$co{'tree'} =$1;2608}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2609push@parents,$1;2610}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2611$co{'author'} = to_utf8($1);2612$co{'author_epoch'} =$2;2613$co{'author_tz'} =$3;2614if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2615$co{'author_name'} =$1;2616$co{'author_email'} =$2;2617}else{2618$co{'author_name'} =$co{'author'};2619}2620}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2621$co{'committer'} = to_utf8($1);2622$co{'committer_epoch'} =$2;2623$co{'committer_tz'} =$3;2624if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2625$co{'committer_name'} =$1;2626$co{'committer_email'} =$2;2627}else{2628$co{'committer_name'} =$co{'committer'};2629}2630}2631}2632if(!defined$co{'tree'}) {2633return;2634};2635$co{'parents'} = \@parents;2636$co{'parent'} =$parents[0];26372638foreachmy$title(@commit_lines) {2639$title=~s/^ //;2640if($titlene"") {2641$co{'title'} = chop_str($title,80,5);2642# remove leading stuff of merges to make the interesting part visible2643if(length($title) >50) {2644$title=~s/^Automatic //;2645$title=~s/^merge (of|with) /Merge ... /i;2646if(length($title) >50) {2647$title=~s/(http|rsync):\/\///;2648}2649if(length($title) >50) {2650$title=~s/(master|www|rsync)\.//;2651}2652if(length($title) >50) {2653$title=~s/kernel.org:?//;2654}2655if(length($title) >50) {2656$title=~s/\/pub\/scm//;2657}2658}2659$co{'title_short'} = chop_str($title,50,5);2660last;2661}2662}2663if(!defined$co{'title'} ||$co{'title'}eq"") {2664$co{'title'} =$co{'title_short'} ='(no commit message)';2665}2666# remove added spaces2667foreachmy$line(@commit_lines) {2668$line=~s/^ //;2669}2670$co{'comment'} = \@commit_lines;26712672my$age=time-$co{'committer_epoch'};2673$co{'age'} =$age;2674$co{'age_string'} = age_string($age);2675my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2676if($age>60*60*24*7*2) {2677$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2678$co{'age_string_age'} =$co{'age_string'};2679}else{2680$co{'age_string_date'} =$co{'age_string'};2681$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2682}2683return%co;2684}26852686sub parse_commit {2687my($commit_id) =@_;2688my%co;26892690local$/="\0";26912692open my$fd,"-|", git_cmd(),"rev-list",2693"--parents",2694"--header",2695"--max-count=1",2696$commit_id,2697"--",2698or die_error(500,"Open git-rev-list failed");2699%co= parse_commit_text(<$fd>,1);2700close$fd;27012702return%co;2703}27042705sub parse_commits {2706my($commit_id,$maxcount,$skip,$filename,@args) =@_;2707my@cos;27082709$maxcount||=1;2710$skip||=0;27112712local$/="\0";27132714open my$fd,"-|", git_cmd(),"rev-list",2715"--header",2716@args,2717("--max-count=".$maxcount),2718("--skip=".$skip),2719@extra_options,2720$commit_id,2721"--",2722($filename? ($filename) : ())2723or die_error(500,"Open git-rev-list failed");2724while(my$line= <$fd>) {2725my%co= parse_commit_text($line);2726push@cos, \%co;2727}2728close$fd;27292730returnwantarray?@cos: \@cos;2731}27322733# parse line of git-diff-tree "raw" output2734sub parse_difftree_raw_line {2735my$line=shift;2736my%res;27372738# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2739# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2740if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2741$res{'from_mode'} =$1;2742$res{'to_mode'} =$2;2743$res{'from_id'} =$3;2744$res{'to_id'} =$4;2745$res{'status'} =$5;2746$res{'similarity'} =$6;2747if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2748($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2749}else{2750$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2751}2752}2753# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2754# combined diff (for merge commit)2755elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2756$res{'nparents'} =length($1);2757$res{'from_mode'} = [split(' ',$2) ];2758$res{'to_mode'} =pop@{$res{'from_mode'}};2759$res{'from_id'} = [split(' ',$3) ];2760$res{'to_id'} =pop@{$res{'from_id'}};2761$res{'status'} = [split('',$4) ];2762$res{'to_file'} = unquote($5);2763}2764# 'c512b523472485aef4fff9e57b229d9d243c967f'2765elsif($line=~m/^([0-9a-fA-F]{40})$/) {2766$res{'commit'} =$1;2767}27682769returnwantarray?%res: \%res;2770}27712772# wrapper: return parsed line of git-diff-tree "raw" output2773# (the argument might be raw line, or parsed info)2774sub parsed_difftree_line {2775my$line_or_ref=shift;27762777if(ref($line_or_ref)eq"HASH") {2778# pre-parsed (or generated by hand)2779return$line_or_ref;2780}else{2781return parse_difftree_raw_line($line_or_ref);2782}2783}27842785# parse line of git-ls-tree output2786sub parse_ls_tree_line {2787my$line=shift;2788my%opts=@_;2789my%res;27902791#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2792$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;27932794$res{'mode'} =$1;2795$res{'type'} =$2;2796$res{'hash'} =$3;2797if($opts{'-z'}) {2798$res{'name'} =$4;2799}else{2800$res{'name'} = unquote($4);2801}28022803returnwantarray?%res: \%res;2804}28052806# generates _two_ hashes, references to which are passed as 2 and 3 argument2807sub parse_from_to_diffinfo {2808my($diffinfo,$from,$to,@parents) =@_;28092810if($diffinfo->{'nparents'}) {2811# combined diff2812$from->{'file'} = [];2813$from->{'href'} = [];2814 fill_from_file_info($diffinfo,@parents)2815unlessexists$diffinfo->{'from_file'};2816for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2817$from->{'file'}[$i] =2818defined$diffinfo->{'from_file'}[$i] ?2819$diffinfo->{'from_file'}[$i] :2820$diffinfo->{'to_file'};2821if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2822$from->{'href'}[$i] = href(action=>"blob",2823 hash_base=>$parents[$i],2824 hash=>$diffinfo->{'from_id'}[$i],2825 file_name=>$from->{'file'}[$i]);2826}else{2827$from->{'href'}[$i] =undef;2828}2829}2830}else{2831# ordinary (not combined) diff2832$from->{'file'} =$diffinfo->{'from_file'};2833if($diffinfo->{'status'}ne"A") {# not new (added) file2834$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2835 hash=>$diffinfo->{'from_id'},2836 file_name=>$from->{'file'});2837}else{2838delete$from->{'href'};2839}2840}28412842$to->{'file'} =$diffinfo->{'to_file'};2843if(!is_deleted($diffinfo)) {# file exists in result2844$to->{'href'} = href(action=>"blob", hash_base=>$hash,2845 hash=>$diffinfo->{'to_id'},2846 file_name=>$to->{'file'});2847}else{2848delete$to->{'href'};2849}2850}28512852## ......................................................................2853## parse to array of hashes functions28542855sub git_get_heads_list {2856my$limit=shift;2857my@headslist;28582859open my$fd,'-|', git_cmd(),'for-each-ref',2860($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2861'--format=%(objectname) %(refname) %(subject)%00%(committer)',2862'refs/heads'2863orreturn;2864while(my$line= <$fd>) {2865my%ref_item;28662867chomp$line;2868my($refinfo,$committerinfo) =split(/\0/,$line);2869my($hash,$name,$title) =split(' ',$refinfo,3);2870my($committer,$epoch,$tz) =2871($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2872$ref_item{'fullname'} =$name;2873$name=~s!^refs/heads/!!;28742875$ref_item{'name'} =$name;2876$ref_item{'id'} =$hash;2877$ref_item{'title'} =$title||'(no commit message)';2878$ref_item{'epoch'} =$epoch;2879if($epoch) {2880$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2881}else{2882$ref_item{'age'} ="unknown";2883}28842885push@headslist, \%ref_item;2886}2887close$fd;28882889returnwantarray?@headslist: \@headslist;2890}28912892sub git_get_tags_list {2893my$limit=shift;2894my@tagslist;28952896open my$fd,'-|', git_cmd(),'for-each-ref',2897($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',2898'--format=%(objectname) %(objecttype) %(refname) '.2899'%(*objectname) %(*objecttype) %(subject)%00%(creator)',2900'refs/tags'2901orreturn;2902while(my$line= <$fd>) {2903my%ref_item;29042905chomp$line;2906my($refinfo,$creatorinfo) =split(/\0/,$line);2907my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);2908my($creator,$epoch,$tz) =2909($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);2910$ref_item{'fullname'} =$name;2911$name=~s!^refs/tags/!!;29122913$ref_item{'type'} =$type;2914$ref_item{'id'} =$id;2915$ref_item{'name'} =$name;2916if($typeeq"tag") {2917$ref_item{'subject'} =$title;2918$ref_item{'reftype'} =$reftype;2919$ref_item{'refid'} =$refid;2920}else{2921$ref_item{'reftype'} =$type;2922$ref_item{'refid'} =$id;2923}29242925if($typeeq"tag"||$typeeq"commit") {2926$ref_item{'epoch'} =$epoch;2927if($epoch) {2928$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2929}else{2930$ref_item{'age'} ="unknown";2931}2932}29332934push@tagslist, \%ref_item;2935}2936close$fd;29372938returnwantarray?@tagslist: \@tagslist;2939}29402941## ----------------------------------------------------------------------2942## filesystem-related functions29432944sub get_file_owner {2945my$path=shift;29462947my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);2948my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);2949if(!defined$gcos) {2950returnundef;2951}2952my$owner=$gcos;2953$owner=~s/[,;].*$//;2954return to_utf8($owner);2955}29562957# assume that file exists2958sub insert_file {2959my$filename=shift;29602961open my$fd,'<',$filename;2962print map{ to_utf8($_) } <$fd>;2963close$fd;2964}29652966## ......................................................................2967## mimetype related functions29682969sub mimetype_guess_file {2970my$filename=shift;2971my$mimemap=shift;2972-r $mimemaporreturnundef;29732974my%mimemap;2975open(my$mh,'<',$mimemap)orreturnundef;2976while(<$mh>) {2977next ifm/^#/;# skip comments2978my($mimetype,$exts) =split(/\t+/);2979if(defined$exts) {2980my@exts=split(/\s+/,$exts);2981foreachmy$ext(@exts) {2982$mimemap{$ext} =$mimetype;2983}2984}2985}2986close($mh);29872988$filename=~/\.([^.]*)$/;2989return$mimemap{$1};2990}29912992sub mimetype_guess {2993my$filename=shift;2994my$mime;2995$filename=~/\./orreturnundef;29962997if($mimetypes_file) {2998my$file=$mimetypes_file;2999if($file!~m!^/!) {# if it is relative path3000# it is relative to project3001$file="$projectroot/$project/$file";3002}3003$mime= mimetype_guess_file($filename,$file);3004}3005$mime||= mimetype_guess_file($filename,'/etc/mime.types');3006return$mime;3007}30083009sub blob_mimetype {3010my$fd=shift;3011my$filename=shift;30123013if($filename) {3014my$mime= mimetype_guess($filename);3015$mimeandreturn$mime;3016}30173018# just in case3019return$default_blob_plain_mimetypeunless$fd;30203021if(-T $fd) {3022return'text/plain';3023}elsif(!$filename) {3024return'application/octet-stream';3025}elsif($filename=~m/\.png$/i) {3026return'image/png';3027}elsif($filename=~m/\.gif$/i) {3028return'image/gif';3029}elsif($filename=~m/\.jpe?g$/i) {3030return'image/jpeg';3031}else{3032return'application/octet-stream';3033}3034}30353036sub blob_contenttype {3037my($fd,$file_name,$type) =@_;30383039$type||= blob_mimetype($fd,$file_name);3040if($typeeq'text/plain'&&defined$default_text_plain_charset) {3041$type.="; charset=$default_text_plain_charset";3042}30433044return$type;3045}30463047## ======================================================================3048## functions printing HTML: header, footer, error page30493050sub git_header_html {3051my$status=shift||"200 OK";3052my$expires=shift;30533054my$title="$site_name";3055if(defined$project) {3056$title.=" - ". to_utf8($project);3057if(defined$action) {3058$title.="/$action";3059if(defined$file_name) {3060$title.=" - ". esc_path($file_name);3061if($actioneq"tree"&&$file_name!~ m|/$|) {3062$title.="/";3063}3064}3065}3066}3067my$content_type;3068# require explicit support from the UA if we are to send the page as3069# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3070# we have to do this because MSIE sometimes globs '*/*', pretending to3071# support xhtml+xml but choking when it gets what it asked for.3072if(defined$cgi->http('HTTP_ACCEPT') &&3073$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3074$cgi->Accept('application/xhtml+xml') !=0) {3075$content_type='application/xhtml+xml';3076}else{3077$content_type='text/html';3078}3079print$cgi->header(-type=>$content_type, -charset =>'utf-8',3080-status=>$status, -expires =>$expires);3081my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';3082print<<EOF;3083<?xml version="1.0" encoding="utf-8"?>3084<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">3085<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">3086<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->3087<!-- git core binaries version$git_version-->3088<head>3089<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>3090<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>3091<meta name="robots" content="index, nofollow"/>3092<title>$title</title>3093EOF3094# the stylesheet, favicon etc urls won't work correctly with path_info3095# unless we set the appropriate base URL3096if($ENV{'PATH_INFO'}) {3097print"<base href=\"".esc_url($base_url)."\"/>\n";3098}3099# print out each stylesheet that exist, providing backwards capability3100# for those people who defined $stylesheet in a config file3101if(defined$stylesheet) {3102print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3103}else{3104foreachmy$stylesheet(@stylesheets) {3105next unless$stylesheet;3106print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3107}3108}3109if(defined$project) {3110my%href_params= get_feed_info();3111if(!exists$href_params{'-title'}) {3112$href_params{'-title'} ='log';3113}31143115foreachmy$formatqw(RSS Atom){3116my$type=lc($format);3117my%link_attr= (3118'-rel'=>'alternate',3119'-title'=>"$project-$href_params{'-title'} -$formatfeed",3120'-type'=>"application/$type+xml"3121);31223123$href_params{'action'} =$type;3124$link_attr{'-href'} = href(%href_params);3125print"<link ".3126"rel=\"$link_attr{'-rel'}\"".3127"title=\"$link_attr{'-title'}\"".3128"href=\"$link_attr{'-href'}\"".3129"type=\"$link_attr{'-type'}\"".3130"/>\n";31313132$href_params{'extra_options'} ='--no-merges';3133$link_attr{'-href'} = href(%href_params);3134$link_attr{'-title'} .=' (no merges)';3135print"<link ".3136"rel=\"$link_attr{'-rel'}\"".3137"title=\"$link_attr{'-title'}\"".3138"href=\"$link_attr{'-href'}\"".3139"type=\"$link_attr{'-type'}\"".3140"/>\n";3141}31423143}else{3144printf('<link rel="alternate" title="%sprojects list" '.3145'href="%s" type="text/plain; charset=utf-8" />'."\n",3146$site_name, href(project=>undef, action=>"project_index"));3147printf('<link rel="alternate" title="%sprojects feeds" '.3148'href="%s" type="text/x-opml" />'."\n",3149$site_name, href(project=>undef, action=>"opml"));3150}3151if(defined$favicon) {3152printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);3153}31543155print"</head>\n".3156"<body>\n";31573158if(-f $site_header) {3159 insert_file($site_header);3160}31613162print"<div class=\"page_header\">\n".3163$cgi->a({-href => esc_url($logo_url),3164-title =>$logo_label},3165qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));3166print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3167if(defined$project) {3168print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3169if(defined$action) {3170print" /$action";3171}3172print"\n";3173}3174print"</div>\n";31753176my$have_search= gitweb_check_feature('search');3177if(defined$project&&$have_search) {3178if(!defined$searchtext) {3179$searchtext="";3180}3181my$search_hash;3182if(defined$hash_base) {3183$search_hash=$hash_base;3184}elsif(defined$hash) {3185$search_hash=$hash;3186}else{3187$search_hash="HEAD";3188}3189my$action=$my_uri;3190my$use_pathinfo= gitweb_check_feature('pathinfo');3191if($use_pathinfo) {3192$action.="/".esc_url($project);3193}3194print$cgi->startform(-method=>"get", -action =>$action) .3195"<div class=\"search\">\n".3196(!$use_pathinfo&&3197$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3198$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3199$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3200$cgi->popup_menu(-name =>'st', -default=>'commit',3201-values=> ['commit','grep','author','committer','pickaxe']) .3202$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3203" search:\n",3204$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3205"<span title=\"Extended regular expression\">".3206$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3207-checked =>$search_use_regexp) .3208"</span>".3209"</div>".3210$cgi->end_form() ."\n";3211}3212}32133214sub git_footer_html {3215my$feed_class='rss_logo';32163217print"<div class=\"page_footer\">\n";3218if(defined$project) {3219my$descr= git_get_project_description($project);3220if(defined$descr) {3221print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3222}32233224my%href_params= get_feed_info();3225if(!%href_params) {3226$feed_class.=' generic';3227}3228$href_params{'-title'} ||='log';32293230foreachmy$formatqw(RSS Atom){3231$href_params{'action'} =lc($format);3232print$cgi->a({-href => href(%href_params),3233-title =>"$href_params{'-title'}$formatfeed",3234-class=>$feed_class},$format)."\n";3235}32363237}else{3238print$cgi->a({-href => href(project=>undef, action=>"opml"),3239-class=>$feed_class},"OPML") ." ";3240print$cgi->a({-href => href(project=>undef, action=>"project_index"),3241-class=>$feed_class},"TXT") ."\n";3242}3243print"</div>\n";# class="page_footer"32443245if(-f $site_footer) {3246 insert_file($site_footer);3247}32483249print"</body>\n".3250"</html>";3251}32523253# die_error(<http_status_code>, <error_message>)3254# Example: die_error(404, 'Hash not found')3255# By convention, use the following status codes (as defined in RFC 2616):3256# 400: Invalid or missing CGI parameters, or3257# requested object exists but has wrong type.3258# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3259# this server or project.3260# 404: Requested object/revision/project doesn't exist.3261# 500: The server isn't configured properly, or3262# an internal error occurred (e.g. failed assertions caused by bugs), or3263# an unknown error occurred (e.g. the git binary died unexpectedly).3264sub die_error {3265my$status=shift||500;3266my$error=shift||"Internal server error";32673268my%http_responses= (400=>'400 Bad Request',3269403=>'403 Forbidden',3270404=>'404 Not Found',3271500=>'500 Internal Server Error');3272 git_header_html($http_responses{$status});3273print<<EOF;3274<div class="page_body">3275<br /><br />3276$status-$error3277<br />3278</div>3279EOF3280 git_footer_html();3281exit;3282}32833284## ----------------------------------------------------------------------3285## functions printing or outputting HTML: navigation32863287sub git_print_page_nav {3288my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3289$extra=''if!defined$extra;# pager or formats32903291my@navs=qw(summary shortlog log commit commitdiff tree);3292if($suppress) {3293@navs=grep{$_ne$suppress}@navs;3294}32953296my%arg=map{$_=> {action=>$_} }@navs;3297if(defined$head) {3298for(qw(commit commitdiff)) {3299$arg{$_}{'hash'} =$head;3300}3301if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3302for(qw(shortlog log)) {3303$arg{$_}{'hash'} =$head;3304}3305}3306}33073308$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3309$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;33103311my@actions= gitweb_get_feature('actions');3312my%repl= (3313'%'=>'%',3314'n'=>$project,# project name3315'f'=>$git_dir,# project path within filesystem3316'h'=>$treehead||'',# current hash ('h' parameter)3317'b'=>$treebase||'',# hash base ('hb' parameter)3318);3319while(@actions) {3320my($label,$link,$pos) =splice(@actions,0,3);3321# insert3322@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3323# munch munch3324$link=~s/%([%nfhb])/$repl{$1}/g;3325$arg{$label}{'_href'} =$link;3326}33273328print"<div class=\"page_nav\">\n".3329(join" | ",3330map{$_eq$current?3331$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3332}@navs);3333print"<br/>\n$extra<br/>\n".3334"</div>\n";3335}33363337sub format_paging_nav {3338my($action,$hash,$head,$page,$has_next_link) =@_;3339my$paging_nav;334033413342if($hashne$head||$page) {3343$paging_nav.=$cgi->a({-href => href(action=>$action)},"HEAD");3344}else{3345$paging_nav.="HEAD";3346}33473348if($page>0) {3349$paging_nav.=" ⋅ ".3350$cgi->a({-href => href(-replay=>1, page=>$page-1),3351-accesskey =>"p", -title =>"Alt-p"},"prev");3352}else{3353$paging_nav.=" ⋅ prev";3354}33553356if($has_next_link) {3357$paging_nav.=" ⋅ ".3358$cgi->a({-href => href(-replay=>1, page=>$page+1),3359-accesskey =>"n", -title =>"Alt-n"},"next");3360}else{3361$paging_nav.=" ⋅ next";3362}33633364return$paging_nav;3365}33663367## ......................................................................3368## functions printing or outputting HTML: div33693370sub git_print_header_div {3371my($action,$title,$hash,$hash_base) =@_;3372my%args= ();33733374$args{'action'} =$action;3375$args{'hash'} =$hashif$hash;3376$args{'hash_base'} =$hash_baseif$hash_base;33773378print"<div class=\"header\">\n".3379$cgi->a({-href => href(%args), -class=>"title"},3380$title?$title:$action) .3381"\n</div>\n";3382}33833384sub print_local_time {3385my%date=@_;3386if($date{'hour_local'} <6) {3387printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3388$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3389}else{3390printf(" (%02d:%02d%s)",3391$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3392}3393}33943395# Outputs the author name and date in long form3396sub git_print_authorship {3397my$co=shift;3398my%opts=@_;3399my$tag=$opts{-tag} ||'div';3400my$author=$co->{'author_name'};34013402my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3403print"<$tagclass=\"author_date\">".3404 format_search_author($author,"author", esc_html($author)) .3405" [$ad{'rfc2822'}";3406 print_local_time(%ad)if($opts{-localtime});3407print"]". git_get_avatar($co->{'author_email'}, -pad_before =>1)3408."</$tag>\n";3409}34103411# Outputs table rows containing the full author or committer information,3412# in the format expected for 'commit' view (& similia).3413# Parameters are a commit hash reference, followed by the list of people3414# to output information for. If the list is empty it defalts to both3415# author and committer.3416sub git_print_authorship_rows {3417my$co=shift;3418# too bad we can't use @people = @_ || ('author', 'committer')3419my@people=@_;3420@people= ('author','committer')unless@people;3421foreachmy$who(@people) {3422my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});3423print"<tr><td>$who</td><td>".3424 format_search_author($co->{"${who}_name"},$who,3425 esc_html($co->{"${who}_name"})) ." ".3426 format_search_author($co->{"${who}_email"},$who,3427 esc_html("<".$co->{"${who}_email"} .">")) .3428"</td><td rowspan=\"2\">".3429 git_get_avatar($co->{"${who}_email"}, -size =>'double') .3430"</td></tr>\n".3431"<tr>".3432"<td></td><td>$wd{'rfc2822'}";3433 print_local_time(%wd);3434print"</td>".3435"</tr>\n";3436}3437}34383439sub git_print_page_path {3440my$name=shift;3441my$type=shift;3442my$hb=shift;344334443445print"<div class=\"page_path\">";3446print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3447-title =>'tree root'}, to_utf8("[$project]"));3448print" / ";3449if(defined$name) {3450my@dirname=split'/',$name;3451my$basename=pop@dirname;3452my$fullname='';34533454foreachmy$dir(@dirname) {3455$fullname.= ($fullname?'/':'') .$dir;3456print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3457 hash_base=>$hb),3458-title =>$fullname}, esc_path($dir));3459print" / ";3460}3461if(defined$type&&$typeeq'blob') {3462print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3463 hash_base=>$hb),3464-title =>$name}, esc_path($basename));3465}elsif(defined$type&&$typeeq'tree') {3466print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3467 hash_base=>$hb),3468-title =>$name}, esc_path($basename));3469print" / ";3470}else{3471print esc_path($basename);3472}3473}3474print"<br/></div>\n";3475}34763477sub git_print_log {3478my$log=shift;3479my%opts=@_;34803481if($opts{'-remove_title'}) {3482# remove title, i.e. first line of log3483shift@$log;3484}3485# remove leading empty lines3486while(defined$log->[0] &&$log->[0]eq"") {3487shift@$log;3488}34893490# print log3491my$signoff=0;3492my$empty=0;3493foreachmy$line(@$log) {3494if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3495$signoff=1;3496$empty=0;3497if(!$opts{'-remove_signoff'}) {3498print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3499next;3500}else{3501# remove signoff lines3502next;3503}3504}else{3505$signoff=0;3506}35073508# print only one empty line3509# do not print empty line after signoff3510if($lineeq"") {3511next if($empty||$signoff);3512$empty=1;3513}else{3514$empty=0;3515}35163517print format_log_line_html($line) ."<br/>\n";3518}35193520if($opts{'-final_empty_line'}) {3521# end with single empty line3522print"<br/>\n"unless$empty;3523}3524}35253526# return link target (what link points to)3527sub git_get_link_target {3528my$hash=shift;3529my$link_target;35303531# read link3532open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3533orreturn;3534{3535local$/=undef;3536$link_target= <$fd>;3537}3538close$fd3539orreturn;35403541return$link_target;3542}35433544# given link target, and the directory (basedir) the link is in,3545# return target of link relative to top directory (top tree);3546# return undef if it is not possible (including absolute links).3547sub normalize_link_target {3548my($link_target,$basedir) =@_;35493550# absolute symlinks (beginning with '/') cannot be normalized3551return if(substr($link_target,0,1)eq'/');35523553# normalize link target to path from top (root) tree (dir)3554my$path;3555if($basedir) {3556$path=$basedir.'/'.$link_target;3557}else{3558# we are in top (root) tree (dir)3559$path=$link_target;3560}35613562# remove //, /./, and /../3563my@path_parts;3564foreachmy$part(split('/',$path)) {3565# discard '.' and ''3566next if(!$part||$parteq'.');3567# handle '..'3568if($parteq'..') {3569if(@path_parts) {3570pop@path_parts;3571}else{3572# link leads outside repository (outside top dir)3573return;3574}3575}else{3576push@path_parts,$part;3577}3578}3579$path=join('/',@path_parts);35803581return$path;3582}35833584# print tree entry (row of git_tree), but without encompassing <tr> element3585sub git_print_tree_entry {3586my($t,$basedir,$hash_base,$have_blame) =@_;35873588my%base_key= ();3589$base_key{'hash_base'} =$hash_baseifdefined$hash_base;35903591# The format of a table row is: mode list link. Where mode is3592# the mode of the entry, list is the name of the entry, an href,3593# and link is the action links of the entry.35943595print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3596if($t->{'type'}eq"blob") {3597print"<td class=\"list\">".3598$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3599 file_name=>"$basedir$t->{'name'}",%base_key),3600-class=>"list"}, esc_path($t->{'name'}));3601if(S_ISLNK(oct$t->{'mode'})) {3602my$link_target= git_get_link_target($t->{'hash'});3603if($link_target) {3604my$norm_target= normalize_link_target($link_target,$basedir);3605if(defined$norm_target) {3606print" -> ".3607$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3608 file_name=>$norm_target),3609-title =>$norm_target}, esc_path($link_target));3610}else{3611print" -> ". esc_path($link_target);3612}3613}3614}3615print"</td>\n";3616print"<td class=\"link\">";3617print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3618 file_name=>"$basedir$t->{'name'}",%base_key)},3619"blob");3620if($have_blame) {3621print" | ".3622$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3623 file_name=>"$basedir$t->{'name'}",%base_key)},3624"blame");3625}3626if(defined$hash_base) {3627print" | ".3628$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3629 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3630"history");3631}3632print" | ".3633$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3634 file_name=>"$basedir$t->{'name'}")},3635"raw");3636print"</td>\n";36373638}elsif($t->{'type'}eq"tree") {3639print"<td class=\"list\">";3640print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3641 file_name=>"$basedir$t->{'name'}",%base_key)},3642 esc_path($t->{'name'}));3643print"</td>\n";3644print"<td class=\"link\">";3645print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3646 file_name=>"$basedir$t->{'name'}",%base_key)},3647"tree");3648if(defined$hash_base) {3649print" | ".3650$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3651 file_name=>"$basedir$t->{'name'}")},3652"history");3653}3654print"</td>\n";3655}else{3656# unknown object: we can only present history for it3657# (this includes 'commit' object, i.e. submodule support)3658print"<td class=\"list\">".3659 esc_path($t->{'name'}) .3660"</td>\n";3661print"<td class=\"link\">";3662if(defined$hash_base) {3663print$cgi->a({-href => href(action=>"history",3664 hash_base=>$hash_base,3665 file_name=>"$basedir$t->{'name'}")},3666"history");3667}3668print"</td>\n";3669}3670}36713672## ......................................................................3673## functions printing large fragments of HTML36743675# get pre-image filenames for merge (combined) diff3676sub fill_from_file_info {3677my($diff,@parents) =@_;36783679$diff->{'from_file'} = [ ];3680$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3681for(my$i=0;$i<$diff->{'nparents'};$i++) {3682if($diff->{'status'}[$i]eq'R'||3683$diff->{'status'}[$i]eq'C') {3684$diff->{'from_file'}[$i] =3685 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3686}3687}36883689return$diff;3690}36913692# is current raw difftree line of file deletion3693sub is_deleted {3694my$diffinfo=shift;36953696return$diffinfo->{'to_id'}eq('0' x 40);3697}36983699# does patch correspond to [previous] difftree raw line3700# $diffinfo - hashref of parsed raw diff format3701# $patchinfo - hashref of parsed patch diff format3702# (the same keys as in $diffinfo)3703sub is_patch_split {3704my($diffinfo,$patchinfo) =@_;37053706returndefined$diffinfo&&defined$patchinfo3707&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3708}370937103711sub git_difftree_body {3712my($difftree,$hash,@parents) =@_;3713my($parent) =$parents[0];3714my$have_blame= gitweb_check_feature('blame');3715print"<div class=\"list_head\">\n";3716if($#{$difftree} >10) {3717print(($#{$difftree} +1) ." files changed:\n");3718}3719print"</div>\n";37203721print"<table class=\"".3722(@parents>1?"combined ":"") .3723"diff_tree\">\n";37243725# header only for combined diff in 'commitdiff' view3726my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3727if($has_header) {3728# table header3729print"<thead><tr>\n".3730"<th></th><th></th>\n";# filename, patchN link3731for(my$i=0;$i<@parents;$i++) {3732my$par=$parents[$i];3733print"<th>".3734$cgi->a({-href => href(action=>"commitdiff",3735 hash=>$hash, hash_parent=>$par),3736-title =>'commitdiff to parent number '.3737($i+1) .': '.substr($par,0,7)},3738$i+1) .3739" </th>\n";3740}3741print"</tr></thead>\n<tbody>\n";3742}37433744my$alternate=1;3745my$patchno=0;3746foreachmy$line(@{$difftree}) {3747my$diff= parsed_difftree_line($line);37483749if($alternate) {3750print"<tr class=\"dark\">\n";3751}else{3752print"<tr class=\"light\">\n";3753}3754$alternate^=1;37553756if(exists$diff->{'nparents'}) {# combined diff37573758 fill_from_file_info($diff,@parents)3759unlessexists$diff->{'from_file'};37603761if(!is_deleted($diff)) {3762# file exists in the result (child) commit3763print"<td>".3764$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3765 file_name=>$diff->{'to_file'},3766 hash_base=>$hash),3767-class=>"list"}, esc_path($diff->{'to_file'})) .3768"</td>\n";3769}else{3770print"<td>".3771 esc_path($diff->{'to_file'}) .3772"</td>\n";3773}37743775if($actioneq'commitdiff') {3776# link to patch3777$patchno++;3778print"<td class=\"link\">".3779$cgi->a({-href =>"#patch$patchno"},"patch") .3780" | ".3781"</td>\n";3782}37833784my$has_history=0;3785my$not_deleted=0;3786for(my$i=0;$i<$diff->{'nparents'};$i++) {3787my$hash_parent=$parents[$i];3788my$from_hash=$diff->{'from_id'}[$i];3789my$from_path=$diff->{'from_file'}[$i];3790my$status=$diff->{'status'}[$i];37913792$has_history||= ($statusne'A');3793$not_deleted||= ($statusne'D');37943795if($statuseq'A') {3796print"<td class=\"link\"align=\"right\"> | </td>\n";3797}elsif($statuseq'D') {3798print"<td class=\"link\">".3799$cgi->a({-href => href(action=>"blob",3800 hash_base=>$hash,3801 hash=>$from_hash,3802 file_name=>$from_path)},3803"blob". ($i+1)) .3804" | </td>\n";3805}else{3806if($diff->{'to_id'}eq$from_hash) {3807print"<td class=\"link nochange\">";3808}else{3809print"<td class=\"link\">";3810}3811print$cgi->a({-href => href(action=>"blobdiff",3812 hash=>$diff->{'to_id'},3813 hash_parent=>$from_hash,3814 hash_base=>$hash,3815 hash_parent_base=>$hash_parent,3816 file_name=>$diff->{'to_file'},3817 file_parent=>$from_path)},3818"diff". ($i+1)) .3819" | </td>\n";3820}3821}38223823print"<td class=\"link\">";3824if($not_deleted) {3825print$cgi->a({-href => href(action=>"blob",3826 hash=>$diff->{'to_id'},3827 file_name=>$diff->{'to_file'},3828 hash_base=>$hash)},3829"blob");3830print" | "if($has_history);3831}3832if($has_history) {3833print$cgi->a({-href => href(action=>"history",3834 file_name=>$diff->{'to_file'},3835 hash_base=>$hash)},3836"history");3837}3838print"</td>\n";38393840print"</tr>\n";3841next;# instead of 'else' clause, to avoid extra indent3842}3843# else ordinary diff38443845my($to_mode_oct,$to_mode_str,$to_file_type);3846my($from_mode_oct,$from_mode_str,$from_file_type);3847if($diff->{'to_mode'}ne('0' x 6)) {3848$to_mode_oct=oct$diff->{'to_mode'};3849if(S_ISREG($to_mode_oct)) {# only for regular file3850$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits3851}3852$to_file_type= file_type($diff->{'to_mode'});3853}3854if($diff->{'from_mode'}ne('0' x 6)) {3855$from_mode_oct=oct$diff->{'from_mode'};3856if(S_ISREG($to_mode_oct)) {# only for regular file3857$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits3858}3859$from_file_type= file_type($diff->{'from_mode'});3860}38613862if($diff->{'status'}eq"A") {# created3863my$mode_chng="<span class=\"file_status new\">[new$to_file_type";3864$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;3865$mode_chng.="]</span>";3866print"<td>";3867print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3868 hash_base=>$hash, file_name=>$diff->{'file'}),3869-class=>"list"}, esc_path($diff->{'file'}));3870print"</td>\n";3871print"<td>$mode_chng</td>\n";3872print"<td class=\"link\">";3873if($actioneq'commitdiff') {3874# link to patch3875$patchno++;3876print$cgi->a({-href =>"#patch$patchno"},"patch");3877print" | ";3878}3879print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3880 hash_base=>$hash, file_name=>$diff->{'file'})},3881"blob");3882print"</td>\n";38833884}elsif($diff->{'status'}eq"D") {# deleted3885my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";3886print"<td>";3887print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3888 hash_base=>$parent, file_name=>$diff->{'file'}),3889-class=>"list"}, esc_path($diff->{'file'}));3890print"</td>\n";3891print"<td>$mode_chng</td>\n";3892print"<td class=\"link\">";3893if($actioneq'commitdiff') {3894# link to patch3895$patchno++;3896print$cgi->a({-href =>"#patch$patchno"},"patch");3897print" | ";3898}3899print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3900 hash_base=>$parent, file_name=>$diff->{'file'})},3901"blob") ." | ";3902if($have_blame) {3903print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,3904 file_name=>$diff->{'file'})},3905"blame") ." | ";3906}3907print$cgi->a({-href => href(action=>"history", hash_base=>$parent,3908 file_name=>$diff->{'file'})},3909"history");3910print"</td>\n";39113912}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed3913my$mode_chnge="";3914if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3915$mode_chnge="<span class=\"file_status mode_chnge\">[changed";3916if($from_file_typene$to_file_type) {3917$mode_chnge.=" from$from_file_typeto$to_file_type";3918}3919if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {3920if($from_mode_str&&$to_mode_str) {3921$mode_chnge.=" mode:$from_mode_str->$to_mode_str";3922}elsif($to_mode_str) {3923$mode_chnge.=" mode:$to_mode_str";3924}3925}3926$mode_chnge.="]</span>\n";3927}3928print"<td>";3929print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3930 hash_base=>$hash, file_name=>$diff->{'file'}),3931-class=>"list"}, esc_path($diff->{'file'}));3932print"</td>\n";3933print"<td>$mode_chnge</td>\n";3934print"<td class=\"link\">";3935if($actioneq'commitdiff') {3936# link to patch3937$patchno++;3938print$cgi->a({-href =>"#patch$patchno"},"patch") .3939" | ";3940}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3941# "commit" view and modified file (not onlu mode changed)3942print$cgi->a({-href => href(action=>"blobdiff",3943 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3944 hash_base=>$hash, hash_parent_base=>$parent,3945 file_name=>$diff->{'file'})},3946"diff") .3947" | ";3948}3949print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3950 hash_base=>$hash, file_name=>$diff->{'file'})},3951"blob") ." | ";3952if($have_blame) {3953print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3954 file_name=>$diff->{'file'})},3955"blame") ." | ";3956}3957print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3958 file_name=>$diff->{'file'})},3959"history");3960print"</td>\n";39613962}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied3963my%status_name= ('R'=>'moved','C'=>'copied');3964my$nstatus=$status_name{$diff->{'status'}};3965my$mode_chng="";3966if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3967# mode also for directories, so we cannot use $to_mode_str3968$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);3969}3970print"<td>".3971$cgi->a({-href => href(action=>"blob", hash_base=>$hash,3972 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),3973-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".3974"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".3975$cgi->a({-href => href(action=>"blob", hash_base=>$parent,3976 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),3977-class=>"list"}, esc_path($diff->{'from_file'})) .3978" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".3979"<td class=\"link\">";3980if($actioneq'commitdiff') {3981# link to patch3982$patchno++;3983print$cgi->a({-href =>"#patch$patchno"},"patch") .3984" | ";3985}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3986# "commit" view and modified file (not only pure rename or copy)3987print$cgi->a({-href => href(action=>"blobdiff",3988 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3989 hash_base=>$hash, hash_parent_base=>$parent,3990 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},3991"diff") .3992" | ";3993}3994print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3995 hash_base=>$parent, file_name=>$diff->{'to_file'})},3996"blob") ." | ";3997if($have_blame) {3998print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3999 file_name=>$diff->{'to_file'})},4000"blame") ." | ";4001}4002print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4003 file_name=>$diff->{'to_file'})},4004"history");4005print"</td>\n";40064007}# we should not encounter Unmerged (U) or Unknown (X) status4008print"</tr>\n";4009}4010print"</tbody>"if$has_header;4011print"</table>\n";4012}40134014sub git_patchset_body {4015my($fd,$difftree,$hash,@hash_parents) =@_;4016my($hash_parent) =$hash_parents[0];40174018my$is_combined= (@hash_parents>1);4019my$patch_idx=0;4020my$patch_number=0;4021my$patch_line;4022my$diffinfo;4023my$to_name;4024my(%from,%to);40254026print"<div class=\"patchset\">\n";40274028# skip to first patch4029while($patch_line= <$fd>) {4030chomp$patch_line;40314032last if($patch_line=~m/^diff /);4033}40344035 PATCH:4036while($patch_line) {40374038# parse "git diff" header line4039if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {4040# $1 is from_name, which we do not use4041$to_name= unquote($2);4042$to_name=~s!^b/!!;4043}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {4044# $1 is 'cc' or 'combined', which we do not use4045$to_name= unquote($2);4046}else{4047$to_name=undef;4048}40494050# check if current patch belong to current raw line4051# and parse raw git-diff line if needed4052if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {4053# this is continuation of a split patch4054print"<div class=\"patch cont\">\n";4055}else{4056# advance raw git-diff output if needed4057$patch_idx++ifdefined$diffinfo;40584059# read and prepare patch information4060$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);40614062# compact combined diff output can have some patches skipped4063# find which patch (using pathname of result) we are at now;4064if($is_combined) {4065while($to_namene$diffinfo->{'to_file'}) {4066print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4067 format_diff_cc_simplified($diffinfo,@hash_parents) .4068"</div>\n";# class="patch"40694070$patch_idx++;4071$patch_number++;40724073last if$patch_idx>$#$difftree;4074$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);4075}4076}40774078# modifies %from, %to hashes4079 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);40804081# this is first patch for raw difftree line with $patch_idx index4082# we index @$difftree array from 0, but number patches from 14083print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";4084}40854086# git diff header4087#assert($patch_line =~ m/^diff /) if DEBUG;4088#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed4089$patch_number++;4090# print "git diff" header4091print format_git_diff_header_line($patch_line,$diffinfo,4092 \%from, \%to);40934094# print extended diff header4095print"<div class=\"diff extended_header\">\n";4096 EXTENDED_HEADER:4097while($patch_line= <$fd>) {4098chomp$patch_line;40994100last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);41014102print format_extended_diff_header_line($patch_line,$diffinfo,4103 \%from, \%to);4104}4105print"</div>\n";# class="diff extended_header"41064107# from-file/to-file diff header4108if(!$patch_line) {4109print"</div>\n";# class="patch"4110last PATCH;4111}4112next PATCH if($patch_line=~m/^diff /);4113#assert($patch_line =~ m/^---/) if DEBUG;41144115my$last_patch_line=$patch_line;4116$patch_line= <$fd>;4117chomp$patch_line;4118#assert($patch_line =~ m/^\+\+\+/) if DEBUG;41194120print format_diff_from_to_header($last_patch_line,$patch_line,4121$diffinfo, \%from, \%to,4122@hash_parents);41234124# the patch itself4125 LINE:4126while($patch_line= <$fd>) {4127chomp$patch_line;41284129next PATCH if($patch_line=~m/^diff /);41304131print format_diff_line($patch_line, \%from, \%to);4132}41334134}continue{4135print"</div>\n";# class="patch"4136}41374138# for compact combined (--cc) format, with chunk and patch simpliciaction4139# patchset might be empty, but there might be unprocessed raw lines4140for(++$patch_idxif$patch_number>0;4141$patch_idx<@$difftree;4142++$patch_idx) {4143# read and prepare patch information4144$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);41454146# generate anchor for "patch" links in difftree / whatchanged part4147print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4148 format_diff_cc_simplified($diffinfo,@hash_parents) .4149"</div>\n";# class="patch"41504151$patch_number++;4152}41534154if($patch_number==0) {4155if(@hash_parents>1) {4156print"<div class=\"diff nodifferences\">Trivial merge</div>\n";4157}else{4158print"<div class=\"diff nodifferences\">No differences found</div>\n";4159}4160}41614162print"</div>\n";# class="patchset"4163}41644165# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41664167# fills project list info (age, description, owner, forks) for each4168# project in the list, removing invalid projects from returned list4169# NOTE: modifies $projlist, but does not remove entries from it4170sub fill_project_list_info {4171my($projlist,$check_forks) =@_;4172my@projects;41734174my$show_ctags= gitweb_check_feature('ctags');4175 PROJECT:4176foreachmy$pr(@$projlist) {4177my(@activity) = git_get_last_activity($pr->{'path'});4178unless(@activity) {4179next PROJECT;4180}4181($pr->{'age'},$pr->{'age_string'}) =@activity;4182if(!defined$pr->{'descr'}) {4183my$descr= git_get_project_description($pr->{'path'}) ||"";4184$descr= to_utf8($descr);4185$pr->{'descr_long'} =$descr;4186$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4187}4188if(!defined$pr->{'owner'}) {4189$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4190}4191if($check_forks) {4192my$pname=$pr->{'path'};4193if(($pname=~s/\.git$//) &&4194($pname!~/\/$/) &&4195(-d "$projectroot/$pname")) {4196$pr->{'forks'} ="-d$projectroot/$pname";4197}else{4198$pr->{'forks'} =0;4199}4200}4201$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4202push@projects,$pr;4203}42044205return@projects;4206}42074208# print 'sort by' <th> element, generating 'sort by $name' replay link4209# if that order is not selected4210sub print_sort_th {4211my($name,$order,$header) =@_;4212$header||=ucfirst($name);42134214if($ordereq$name) {4215print"<th>$header</th>\n";4216}else{4217print"<th>".4218$cgi->a({-href => href(-replay=>1, order=>$name),4219-class=>"header"},$header) .4220"</th>\n";4221}4222}42234224sub git_project_list_body {4225# actually uses global variable $project4226my($projlist,$order,$from,$to,$extra,$no_header) =@_;42274228my$check_forks= gitweb_check_feature('forks');4229my@projects= fill_project_list_info($projlist,$check_forks);42304231$order||=$default_projects_order;4232$from=0unlessdefined$from;4233$to=$#projectsif(!defined$to||$#projects<$to);42344235my%order_info= (4236 project => { key =>'path', type =>'str'},4237 descr => { key =>'descr_long', type =>'str'},4238 owner => { key =>'owner', type =>'str'},4239 age => { key =>'age', type =>'num'}4240);4241my$oi=$order_info{$order};4242if($oi->{'type'}eq'str') {4243@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4244}else{4245@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4246}42474248my$show_ctags= gitweb_check_feature('ctags');4249if($show_ctags) {4250my%ctags;4251foreachmy$p(@projects) {4252foreachmy$ct(keys%{$p->{'ctags'}}) {4253$ctags{$ct} +=$p->{'ctags'}->{$ct};4254}4255}4256my$cloud= git_populate_project_tagcloud(\%ctags);4257print git_show_project_tagcloud($cloud,64);4258}42594260print"<table class=\"project_list\">\n";4261unless($no_header) {4262print"<tr>\n";4263if($check_forks) {4264print"<th></th>\n";4265}4266 print_sort_th('project',$order,'Project');4267 print_sort_th('descr',$order,'Description');4268 print_sort_th('owner',$order,'Owner');4269 print_sort_th('age',$order,'Last Change');4270print"<th></th>\n".# for links4271"</tr>\n";4272}4273my$alternate=1;4274my$tagfilter=$cgi->param('by_tag');4275for(my$i=$from;$i<=$to;$i++) {4276my$pr=$projects[$i];42774278next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4279next if$searchtextand not$pr->{'path'} =~/$searchtext/4280and not$pr->{'descr_long'} =~/$searchtext/;4281# Weed out forks or non-matching entries of search4282if($check_forks) {4283my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4284$forkbase="^$forkbase"if$forkbase;4285next ifnot$searchtextand not$tagfilterand$show_ctags4286and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4287}42884289if($alternate) {4290print"<tr class=\"dark\">\n";4291}else{4292print"<tr class=\"light\">\n";4293}4294$alternate^=1;4295if($check_forks) {4296print"<td>";4297if($pr->{'forks'}) {4298print"<!--$pr->{'forks'} -->\n";4299print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4300}4301print"</td>\n";4302}4303print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4304-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4305"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4306-class=>"list", -title =>$pr->{'descr_long'}},4307 esc_html($pr->{'descr'})) ."</td>\n".4308"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4309print"<td class=\"". age_class($pr->{'age'}) ."\">".4310(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4311"<td class=\"link\">".4312$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4313$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4314$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4315$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4316($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4317"</td>\n".4318"</tr>\n";4319}4320if(defined$extra) {4321print"<tr>\n";4322if($check_forks) {4323print"<td></td>\n";4324}4325print"<td colspan=\"5\">$extra</td>\n".4326"</tr>\n";4327}4328print"</table>\n";4329}43304331sub git_shortlog_body {4332# uses global variable $project4333my($commitlist,$from,$to,$refs,$extra) =@_;43344335$from=0unlessdefined$from;4336$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);43374338print"<table class=\"shortlog\">\n";4339my$alternate=1;4340for(my$i=$from;$i<=$to;$i++) {4341my%co= %{$commitlist->[$i]};4342my$commit=$co{'id'};4343my$ref= format_ref_marker($refs,$commit);4344if($alternate) {4345print"<tr class=\"dark\">\n";4346}else{4347print"<tr class=\"light\">\n";4348}4349$alternate^=1;4350# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4351print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4352 format_author_html('td', \%co,10) ."<td>";4353print format_subject_html($co{'title'},$co{'title_short'},4354 href(action=>"commit", hash=>$commit),$ref);4355print"</td>\n".4356"<td class=\"link\">".4357$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4358$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4359$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4360my$snapshot_links= format_snapshot_links($commit);4361if(defined$snapshot_links) {4362print" | ".$snapshot_links;4363}4364print"</td>\n".4365"</tr>\n";4366}4367if(defined$extra) {4368print"<tr>\n".4369"<td colspan=\"4\">$extra</td>\n".4370"</tr>\n";4371}4372print"</table>\n";4373}43744375sub git_history_body {4376# Warning: assumes constant type (blob or tree) during history4377my($commitlist,$from,$to,$refs,$hash_base,$ftype,$extra) =@_;43784379$from=0unlessdefined$from;4380$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});43814382print"<table class=\"history\">\n";4383my$alternate=1;4384for(my$i=$from;$i<=$to;$i++) {4385my%co= %{$commitlist->[$i]};4386if(!%co) {4387next;4388}4389my$commit=$co{'id'};43904391my$ref= format_ref_marker($refs,$commit);43924393if($alternate) {4394print"<tr class=\"dark\">\n";4395}else{4396print"<tr class=\"light\">\n";4397}4398$alternate^=1;4399print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4400# shortlog: format_author_html('td', \%co, 10)4401 format_author_html('td', \%co,15,3) ."<td>";4402# originally git_history used chop_str($co{'title'}, 50)4403print format_subject_html($co{'title'},$co{'title_short'},4404 href(action=>"commit", hash=>$commit),$ref);4405print"</td>\n".4406"<td class=\"link\">".4407$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4408$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");44094410if($ftypeeq'blob') {4411my$blob_current= git_get_hash_by_path($hash_base,$file_name);4412my$blob_parent= git_get_hash_by_path($commit,$file_name);4413if(defined$blob_current&&defined$blob_parent&&4414$blob_currentne$blob_parent) {4415print" | ".4416$cgi->a({-href => href(action=>"blobdiff",4417 hash=>$blob_current, hash_parent=>$blob_parent,4418 hash_base=>$hash_base, hash_parent_base=>$commit,4419 file_name=>$file_name)},4420"diff to current");4421}4422}4423print"</td>\n".4424"</tr>\n";4425}4426if(defined$extra) {4427print"<tr>\n".4428"<td colspan=\"4\">$extra</td>\n".4429"</tr>\n";4430}4431print"</table>\n";4432}44334434sub git_tags_body {4435# uses global variable $project4436my($taglist,$from,$to,$extra) =@_;4437$from=0unlessdefined$from;4438$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);44394440print"<table class=\"tags\">\n";4441my$alternate=1;4442for(my$i=$from;$i<=$to;$i++) {4443my$entry=$taglist->[$i];4444my%tag=%$entry;4445my$comment=$tag{'subject'};4446my$comment_short;4447if(defined$comment) {4448$comment_short= chop_str($comment,30,5);4449}4450if($alternate) {4451print"<tr class=\"dark\">\n";4452}else{4453print"<tr class=\"light\">\n";4454}4455$alternate^=1;4456if(defined$tag{'age'}) {4457print"<td><i>$tag{'age'}</i></td>\n";4458}else{4459print"<td></td>\n";4460}4461print"<td>".4462$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4463-class=>"list name"}, esc_html($tag{'name'})) .4464"</td>\n".4465"<td>";4466if(defined$comment) {4467print format_subject_html($comment,$comment_short,4468 href(action=>"tag", hash=>$tag{'id'}));4469}4470print"</td>\n".4471"<td class=\"selflink\">";4472if($tag{'type'}eq"tag") {4473print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4474}else{4475print" ";4476}4477print"</td>\n".4478"<td class=\"link\">"." | ".4479$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4480if($tag{'reftype'}eq"commit") {4481print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4482" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4483}elsif($tag{'reftype'}eq"blob") {4484print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4485}4486print"</td>\n".4487"</tr>";4488}4489if(defined$extra) {4490print"<tr>\n".4491"<td colspan=\"5\">$extra</td>\n".4492"</tr>\n";4493}4494print"</table>\n";4495}44964497sub git_heads_body {4498# uses global variable $project4499my($headlist,$head,$from,$to,$extra) =@_;4500$from=0unlessdefined$from;4501$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);45024503print"<table class=\"heads\">\n";4504my$alternate=1;4505for(my$i=$from;$i<=$to;$i++) {4506my$entry=$headlist->[$i];4507my%ref=%$entry;4508my$curr=$ref{'id'}eq$head;4509if($alternate) {4510print"<tr class=\"dark\">\n";4511}else{4512print"<tr class=\"light\">\n";4513}4514$alternate^=1;4515print"<td><i>$ref{'age'}</i></td>\n".4516($curr?"<td class=\"current_head\">":"<td>") .4517$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4518-class=>"list name"},esc_html($ref{'name'})) .4519"</td>\n".4520"<td class=\"link\">".4521$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4522$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4523$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4524"</td>\n".4525"</tr>";4526}4527if(defined$extra) {4528print"<tr>\n".4529"<td colspan=\"3\">$extra</td>\n".4530"</tr>\n";4531}4532print"</table>\n";4533}45344535sub git_search_grep_body {4536my($commitlist,$from,$to,$extra) =@_;4537$from=0unlessdefined$from;4538$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);45394540print"<table class=\"commit_search\">\n";4541my$alternate=1;4542for(my$i=$from;$i<=$to;$i++) {4543my%co= %{$commitlist->[$i]};4544if(!%co) {4545next;4546}4547my$commit=$co{'id'};4548if($alternate) {4549print"<tr class=\"dark\">\n";4550}else{4551print"<tr class=\"light\">\n";4552}4553$alternate^=1;4554print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4555 format_author_html('td', \%co,15,5) .4556"<td>".4557$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4558-class=>"list subject"},4559 chop_and_escape_str($co{'title'},50) ."<br/>");4560my$comment=$co{'comment'};4561foreachmy$line(@$comment) {4562if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4563my($lead,$match,$trail) = ($1,$2,$3);4564$match= chop_str($match,70,5,'center');4565my$contextlen=int((80-length($match))/2);4566$contextlen=30if($contextlen>30);4567$lead= chop_str($lead,$contextlen,10,'left');4568$trail= chop_str($trail,$contextlen,10,'right');45694570$lead= esc_html($lead);4571$match= esc_html($match);4572$trail= esc_html($trail);45734574print"$lead<span class=\"match\">$match</span>$trail<br />";4575}4576}4577print"</td>\n".4578"<td class=\"link\">".4579$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4580" | ".4581$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4582" | ".4583$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4584print"</td>\n".4585"</tr>\n";4586}4587if(defined$extra) {4588print"<tr>\n".4589"<td colspan=\"3\">$extra</td>\n".4590"</tr>\n";4591}4592print"</table>\n";4593}45944595## ======================================================================4596## ======================================================================4597## actions45984599sub git_project_list {4600my$order=$input_params{'order'};4601if(defined$order&&$order!~m/none|project|descr|owner|age/) {4602 die_error(400,"Unknown order parameter");4603}46044605my@list= git_get_projects_list();4606if(!@list) {4607 die_error(404,"No projects found");4608}46094610 git_header_html();4611if(-f $home_text) {4612print"<div class=\"index_include\">\n";4613 insert_file($home_text);4614print"</div>\n";4615}4616print$cgi->startform(-method=>"get") .4617"<p class=\"projsearch\">Search:\n".4618$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4619"</p>".4620$cgi->end_form() ."\n";4621 git_project_list_body(\@list,$order);4622 git_footer_html();4623}46244625sub git_forks {4626my$order=$input_params{'order'};4627if(defined$order&&$order!~m/none|project|descr|owner|age/) {4628 die_error(400,"Unknown order parameter");4629}46304631my@list= git_get_projects_list($project);4632if(!@list) {4633 die_error(404,"No forks found");4634}46354636 git_header_html();4637 git_print_page_nav('','');4638 git_print_header_div('summary',"$projectforks");4639 git_project_list_body(\@list,$order);4640 git_footer_html();4641}46424643sub git_project_index {4644my@projects= git_get_projects_list($project);46454646print$cgi->header(4647-type =>'text/plain',4648-charset =>'utf-8',4649-content_disposition =>'inline; filename="index.aux"');46504651foreachmy$pr(@projects) {4652if(!exists$pr->{'owner'}) {4653$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4654}46554656my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4657# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4658$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4659$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4660$path=~s/ /\+/g;4661$owner=~s/ /\+/g;46624663print"$path$owner\n";4664}4665}46664667sub git_summary {4668my$descr= git_get_project_description($project) ||"none";4669my%co= parse_commit("HEAD");4670my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4671my$head=$co{'id'};46724673my$owner= git_get_project_owner($project);46744675my$refs= git_get_references();4676# These get_*_list functions return one more to allow us to see if4677# there are more ...4678my@taglist= git_get_tags_list(16);4679my@headlist= git_get_heads_list(16);4680my@forklist;4681my$check_forks= gitweb_check_feature('forks');46824683if($check_forks) {4684@forklist= git_get_projects_list($project);4685}46864687 git_header_html();4688 git_print_page_nav('summary','',$head);46894690print"<div class=\"title\"> </div>\n";4691print"<table class=\"projects_list\">\n".4692"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4693"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4694if(defined$cd{'rfc2822'}) {4695print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4696}46974698# use per project git URL list in $projectroot/$project/cloneurl4699# or make project git URL from git base URL and project name4700my$url_tag="URL";4701my@url_list= git_get_project_url_list($project);4702@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4703foreachmy$git_url(@url_list) {4704next unless$git_url;4705print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4706$url_tag="";4707}47084709# Tag cloud4710my$show_ctags= gitweb_check_feature('ctags');4711if($show_ctags) {4712my$ctags= git_get_project_ctags($project);4713my$cloud= git_populate_project_tagcloud($ctags);4714print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4715print"</td>\n<td>"unless%$ctags;4716print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4717print"</td>\n<td>"if%$ctags;4718print git_show_project_tagcloud($cloud,48);4719print"</td></tr>";4720}47214722print"</table>\n";47234724# If XSS prevention is on, we don't include README.html.4725# TODO: Allow a readme in some safe format.4726if(!$prevent_xss&& -s "$projectroot/$project/README.html") {4727print"<div class=\"title\">readme</div>\n".4728"<div class=\"readme\">\n";4729 insert_file("$projectroot/$project/README.html");4730print"\n</div>\n";# class="readme"4731}47324733# we need to request one more than 16 (0..15) to check if4734# those 16 are all4735my@commitlist=$head? parse_commits($head,17) : ();4736if(@commitlist) {4737 git_print_header_div('shortlog');4738 git_shortlog_body(\@commitlist,0,15,$refs,4739$#commitlist<=15?undef:4740$cgi->a({-href => href(action=>"shortlog")},"..."));4741}47424743if(@taglist) {4744 git_print_header_div('tags');4745 git_tags_body(\@taglist,0,15,4746$#taglist<=15?undef:4747$cgi->a({-href => href(action=>"tags")},"..."));4748}47494750if(@headlist) {4751 git_print_header_div('heads');4752 git_heads_body(\@headlist,$head,0,15,4753$#headlist<=15?undef:4754$cgi->a({-href => href(action=>"heads")},"..."));4755}47564757if(@forklist) {4758 git_print_header_div('forks');4759 git_project_list_body(\@forklist,'age',0,15,4760$#forklist<=15?undef:4761$cgi->a({-href => href(action=>"forks")},"..."),4762'no_header');4763}47644765 git_footer_html();4766}47674768sub git_tag {4769my$head= git_get_head_hash($project);4770 git_header_html();4771 git_print_page_nav('','',$head,undef,$head);4772my%tag= parse_tag($hash);47734774if(!%tag) {4775 die_error(404,"Unknown tag object");4776}47774778 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4779print"<div class=\"title_text\">\n".4780"<table class=\"object_header\">\n".4781"<tr>\n".4782"<td>object</td>\n".4783"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4784$tag{'object'}) ."</td>\n".4785"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4786$tag{'type'}) ."</td>\n".4787"</tr>\n";4788if(defined($tag{'author'})) {4789 git_print_authorship_rows(\%tag,'author');4790}4791print"</table>\n\n".4792"</div>\n";4793print"<div class=\"page_body\">";4794my$comment=$tag{'comment'};4795foreachmy$line(@$comment) {4796chomp$line;4797print esc_html($line, -nbsp=>1) ."<br/>\n";4798}4799print"</div>\n";4800 git_footer_html();4801}48024803sub git_blame {4804# permissions4805 gitweb_check_feature('blame')4806or die_error(403,"Blame view not allowed");48074808# error checking4809 die_error(400,"No file name given")unless$file_name;4810$hash_base||= git_get_head_hash($project);4811 die_error(404,"Couldn't find base commit")unless$hash_base;4812my%co= parse_commit($hash_base)4813or die_error(404,"Commit not found");4814my$ftype="blob";4815if(!defined$hash) {4816$hash= git_get_hash_by_path($hash_base,$file_name,"blob")4817or die_error(404,"Error looking up file");4818}else{4819$ftype= git_get_type($hash);4820if($ftype!~"blob") {4821 die_error(400,"Object is not a blob");4822}4823}48244825# run git-blame --porcelain4826open my$fd,"-|", git_cmd(),"blame",'-p',4827$hash_base,'--',$file_name4828or die_error(500,"Open git-blame failed");48294830# page header4831 git_header_html();4832my$formats_nav=4833$cgi->a({-href => href(action=>"blob", -replay=>1)},4834"blob") .4835" | ".4836$cgi->a({-href => href(action=>"history", -replay=>1)},4837"history") .4838" | ".4839$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},4840"HEAD");4841 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4842 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4843 git_print_page_path($file_name,$ftype,$hash_base);48444845# page body4846my@rev_color=qw(light dark);4847my$num_colors=scalar(@rev_color);4848my$current_color=0;4849my%metainfo= ();48504851print<<HTML;4852<div class="page_body">4853<table class="blame">4854<tr><th>Commit</th><th>Line</th><th>Data</th></tr>4855HTML4856 LINE:4857while(my$line= <$fd>) {4858chomp$line;4859# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]4860# no <lines in group> for subsequent lines in group of lines4861my($full_rev,$orig_lineno,$lineno,$group_size) =4862($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);4863if(!exists$metainfo{$full_rev}) {4864$metainfo{$full_rev} = {'nprevious'=>0};4865}4866my$meta=$metainfo{$full_rev};4867my$data;4868while($data= <$fd>) {4869chomp$data;4870last if($data=~s/^\t//);# contents of line4871if($data=~/^(\S+)(?: (.*))?$/) {4872$meta->{$1} =$2unlessexists$meta->{$1};4873}4874if($data=~/^previous /) {4875$meta->{'nprevious'}++;4876}4877}4878my$short_rev=substr($full_rev,0,8);4879my$author=$meta->{'author'};4880my%date=4881 parse_date($meta->{'author-time'},$meta->{'author-tz'});4882my$date=$date{'iso-tz'};4883if($group_size) {4884$current_color= ($current_color+1) %$num_colors;4885}4886my$tr_class=$rev_color[$current_color];4887$tr_class.=' boundary'if(exists$meta->{'boundary'});4888$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);4889$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);4890print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";4891if($group_size) {4892print"<td class=\"sha1\"";4893print" title=\"". esc_html($author) .",$date\"";4894print" rowspan=\"$group_size\""if($group_size>1);4895print">";4896print$cgi->a({-href => href(action=>"commit",4897 hash=>$full_rev,4898 file_name=>$file_name)},4899 esc_html($short_rev));4900if($group_size>=2) {4901my@author_initials= ($author=~/\b([[:upper:]])\B/g);4902if(@author_initials) {4903print"<br />".4904 esc_html(join('',@author_initials));4905# or join('.', ...)4906}4907}4908print"</td>\n";4909}4910# 'previous' <sha1 of parent commit> <filename at commit>4911if(exists$meta->{'previous'} &&4912$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {4913$meta->{'parent'} =$1;4914$meta->{'file_parent'} = unquote($2);4915}4916my$linenr_commit=4917exists($meta->{'parent'}) ?4918$meta->{'parent'} :$full_rev;4919my$linenr_filename=4920exists($meta->{'file_parent'}) ?4921$meta->{'file_parent'} : unquote($meta->{'filename'});4922my$blamed= href(action =>'blame',4923 file_name =>$linenr_filename,4924 hash_base =>$linenr_commit);4925print"<td class=\"linenr\">";4926print$cgi->a({ -href =>"$blamed#l$orig_lineno",4927-class=>"linenr"},4928 esc_html($lineno));4929print"</td>";4930print"<td class=\"pre\">". esc_html($data) ."</td>\n";4931print"</tr>\n";4932}4933print"</table>\n";4934print"</div>";4935close$fd4936or print"Reading blob failed\n";49374938# page footer4939 git_footer_html();4940}49414942sub git_tags {4943my$head= git_get_head_hash($project);4944 git_header_html();4945 git_print_page_nav('','',$head,undef,$head);4946 git_print_header_div('summary',$project);49474948my@tagslist= git_get_tags_list();4949if(@tagslist) {4950 git_tags_body(\@tagslist);4951}4952 git_footer_html();4953}49544955sub git_heads {4956my$head= git_get_head_hash($project);4957 git_header_html();4958 git_print_page_nav('','',$head,undef,$head);4959 git_print_header_div('summary',$project);49604961my@headslist= git_get_heads_list();4962if(@headslist) {4963 git_heads_body(\@headslist,$head);4964}4965 git_footer_html();4966}49674968sub git_blob_plain {4969my$type=shift;4970my$expires;49714972if(!defined$hash) {4973if(defined$file_name) {4974my$base=$hash_base|| git_get_head_hash($project);4975$hash= git_get_hash_by_path($base,$file_name,"blob")4976or die_error(404,"Cannot find file");4977}else{4978 die_error(400,"No file name defined");4979}4980}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4981# blobs defined by non-textual hash id's can be cached4982$expires="+1d";4983}49844985open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4986or die_error(500,"Open git-cat-file blob '$hash' failed");49874988# content-type (can include charset)4989$type= blob_contenttype($fd,$file_name,$type);49904991# "save as" filename, even when no $file_name is given4992my$save_as="$hash";4993if(defined$file_name) {4994$save_as=$file_name;4995}elsif($type=~m/^text\//) {4996$save_as.='.txt';4997}49984999# With XSS prevention on, blobs of all types except a few known safe5000# ones are served with "Content-Disposition: attachment" to make sure5001# they don't run in our security domain. For certain image types,5002# blob view writes an <img> tag referring to blob_plain view, and we5003# want to be sure not to break that by serving the image as an5004# attachment (though Firefox 3 doesn't seem to care).5005my$sandbox=$prevent_xss&&5006$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;50075008print$cgi->header(5009-type =>$type,5010-expires =>$expires,5011-content_disposition =>5012($sandbox?'attachment':'inline')5013.'; filename="'.$save_as.'"');5014local$/=undef;5015binmode STDOUT,':raw';5016print<$fd>;5017binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5018close$fd;5019}50205021sub git_blob {5022my$expires;50235024if(!defined$hash) {5025if(defined$file_name) {5026my$base=$hash_base|| git_get_head_hash($project);5027$hash= git_get_hash_by_path($base,$file_name,"blob")5028or die_error(404,"Cannot find file");5029}else{5030 die_error(400,"No file name defined");5031}5032}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5033# blobs defined by non-textual hash id's can be cached5034$expires="+1d";5035}50365037my$have_blame= gitweb_check_feature('blame');5038open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5039or die_error(500,"Couldn't cat$file_name,$hash");5040my$mimetype= blob_mimetype($fd,$file_name);5041if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {5042close$fd;5043return git_blob_plain($mimetype);5044}5045# we can have blame only for text/* mimetype5046$have_blame&&= ($mimetype=~m!^text/!);50475048 git_header_html(undef,$expires);5049my$formats_nav='';5050if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5051if(defined$file_name) {5052if($have_blame) {5053$formats_nav.=5054$cgi->a({-href => href(action=>"blame", -replay=>1)},5055"blame") .5056" | ";5057}5058$formats_nav.=5059$cgi->a({-href => href(action=>"history", -replay=>1)},5060"history") .5061" | ".5062$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5063"raw") .5064" | ".5065$cgi->a({-href => href(action=>"blob",5066 hash_base=>"HEAD", file_name=>$file_name)},5067"HEAD");5068}else{5069$formats_nav.=5070$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5071"raw");5072}5073 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5074 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5075}else{5076print"<div class=\"page_nav\">\n".5077"<br/><br/></div>\n".5078"<div class=\"title\">$hash</div>\n";5079}5080 git_print_page_path($file_name,"blob",$hash_base);5081print"<div class=\"page_body\">\n";5082if($mimetype=~m!^image/!) {5083print qq!<img type="$mimetype"!;5084if($file_name) {5085print qq! alt="$file_name" title="$file_name"!;5086}5087print qq! src="! .5088 href(action=>"blob_plain", hash=>$hash,5089 hash_base=>$hash_base, file_name=>$file_name) .5090 qq!"/>\n!;5091}else{5092my$nr;5093while(my$line= <$fd>) {5094chomp$line;5095$nr++;5096$line= untabify($line);5097printf"<div class=\"pre\"><a id=\"l%i\"href=\"#l%i\"class=\"linenr\">%4i</a>%s</div>\n",5098$nr,$nr,$nr, esc_html($line, -nbsp=>1);5099}5100}5101close$fd5102or print"Reading blob failed.\n";5103print"</div>";5104 git_footer_html();5105}51065107sub git_tree {5108if(!defined$hash_base) {5109$hash_base="HEAD";5110}5111if(!defined$hash) {5112if(defined$file_name) {5113$hash= git_get_hash_by_path($hash_base,$file_name,"tree");5114}else{5115$hash=$hash_base;5116}5117}5118 die_error(404,"No such tree")unlessdefined($hash);51195120my@entries= ();5121{5122local$/="\0";5123open my$fd,"-|", git_cmd(),"ls-tree",'-z',$hash5124or die_error(500,"Open git-ls-tree failed");5125@entries=map{chomp;$_} <$fd>;5126close$fd5127or die_error(404,"Reading tree failed");5128}51295130my$refs= git_get_references();5131my$ref= format_ref_marker($refs,$hash_base);5132 git_header_html();5133my$basedir='';5134my$have_blame= gitweb_check_feature('blame');5135if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5136my@views_nav= ();5137if(defined$file_name) {5138push@views_nav,5139$cgi->a({-href => href(action=>"history", -replay=>1)},5140"history"),5141$cgi->a({-href => href(action=>"tree",5142 hash_base=>"HEAD", file_name=>$file_name)},5143"HEAD"),5144}5145my$snapshot_links= format_snapshot_links($hash);5146if(defined$snapshot_links) {5147# FIXME: Should be available when we have no hash base as well.5148push@views_nav,$snapshot_links;5149}5150 git_print_page_nav('tree','',$hash_base,undef,undef,join(' | ',@views_nav));5151 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);5152}else{5153undef$hash_base;5154print"<div class=\"page_nav\">\n";5155print"<br/><br/></div>\n";5156print"<div class=\"title\">$hash</div>\n";5157}5158if(defined$file_name) {5159$basedir=$file_name;5160if($basedirne''&&substr($basedir, -1)ne'/') {5161$basedir.='/';5162}5163 git_print_page_path($file_name,'tree',$hash_base);5164}5165print"<div class=\"page_body\">\n";5166print"<table class=\"tree\">\n";5167my$alternate=1;5168# '..' (top directory) link if possible5169if(defined$hash_base&&5170defined$file_name&&$file_name=~m![^/]+$!) {5171if($alternate) {5172print"<tr class=\"dark\">\n";5173}else{5174print"<tr class=\"light\">\n";5175}5176$alternate^=1;51775178my$up=$file_name;5179$up=~s!/?[^/]+$!!;5180undef$upunless$up;5181# based on git_print_tree_entry5182print'<td class="mode">'. mode_str('040000') ."</td>\n";5183print'<td class="list">';5184print$cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,5185 file_name=>$up)},5186"..");5187print"</td>\n";5188print"<td class=\"link\"></td>\n";51895190print"</tr>\n";5191}5192foreachmy$line(@entries) {5193my%t= parse_ls_tree_line($line, -z =>1);51945195if($alternate) {5196print"<tr class=\"dark\">\n";5197}else{5198print"<tr class=\"light\">\n";5199}5200$alternate^=1;52015202 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);52035204print"</tr>\n";5205}5206print"</table>\n".5207"</div>";5208 git_footer_html();5209}52105211sub git_snapshot {5212my$format=$input_params{'snapshot_format'};5213if(!@snapshot_fmts) {5214 die_error(403,"Snapshots not allowed");5215}5216# default to first supported snapshot format5217$format||=$snapshot_fmts[0];5218if($format!~m/^[a-z0-9]+$/) {5219 die_error(400,"Invalid snapshot format parameter");5220}elsif(!exists($known_snapshot_formats{$format})) {5221 die_error(400,"Unknown snapshot format");5222}elsif($known_snapshot_formats{$format}{'disabled'}) {5223 die_error(403,"Snapshot format not allowed");5224}elsif(!grep($_eq$format,@snapshot_fmts)) {5225 die_error(403,"Unsupported snapshot format");5226}52275228if(!defined$hash) {5229$hash= git_get_head_hash($project);5230}52315232my$name=$project;5233$name=~ s,([^/])/*\.git$,$1,;5234$name= basename($name);5235my$filename= to_utf8($name);5236$name=~s/\047/\047\\\047\047/g;5237my$cmd;5238$filename.="-$hash$known_snapshot_formats{$format}{'suffix'}";5239$cmd= quote_command(5240 git_cmd(),'archive',5241"--format=$known_snapshot_formats{$format}{'format'}",5242"--prefix=$name/",$hash);5243if(exists$known_snapshot_formats{$format}{'compressor'}) {5244$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});5245}52465247print$cgi->header(5248-type =>$known_snapshot_formats{$format}{'type'},5249-content_disposition =>'inline; filename="'."$filename".'"',5250-status =>'200 OK');52515252open my$fd,"-|",$cmd5253or die_error(500,"Execute git-archive failed");5254binmode STDOUT,':raw';5255print<$fd>;5256binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5257close$fd;5258}52595260sub git_log {5261my$head= git_get_head_hash($project);5262if(!defined$hash) {5263$hash=$head;5264}5265if(!defined$page) {5266$page=0;5267}5268my$refs= git_get_references();52695270my@commitlist= parse_commits($hash,101, (100*$page));52715272my$paging_nav= format_paging_nav('log',$hash,$head,$page,$#commitlist>=100);52735274my($patch_max) = gitweb_get_feature('patches');5275if($patch_max) {5276if($patch_max<0||@commitlist<=$patch_max) {5277$paging_nav.=" ⋅ ".5278$cgi->a({-href => href(action=>"patches", -replay=>1)},5279"patches");5280}5281}52825283 git_header_html();5284 git_print_page_nav('log','',$hash,undef,undef,$paging_nav);52855286if(!@commitlist) {5287my%co= parse_commit($hash);52885289 git_print_header_div('summary',$project);5290print"<div class=\"page_body\"> Last change$co{'age_string'}.<br/><br/></div>\n";5291}5292my$to= ($#commitlist>=99) ? (99) : ($#commitlist);5293for(my$i=0;$i<=$to;$i++) {5294my%co= %{$commitlist[$i]};5295next if!%co;5296my$commit=$co{'id'};5297my$ref= format_ref_marker($refs,$commit);5298my%ad= parse_date($co{'author_epoch'});5299 git_print_header_div('commit',5300"<span class=\"age\">$co{'age_string'}</span>".5301 esc_html($co{'title'}) .$ref,5302$commit);5303print"<div class=\"title_text\">\n".5304"<div class=\"log_link\">\n".5305$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .5306" | ".5307$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .5308" | ".5309$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .5310"<br/>\n".5311"</div>\n";5312 git_print_authorship(\%co, -tag =>'span');5313print"<br/>\n</div>\n";53145315print"<div class=\"log_body\">\n";5316 git_print_log($co{'comment'}, -final_empty_line=>1);5317print"</div>\n";5318}5319if($#commitlist>=100) {5320print"<div class=\"page_nav\">\n";5321print$cgi->a({-href => href(-replay=>1, page=>$page+1),5322-accesskey =>"n", -title =>"Alt-n"},"next");5323print"</div>\n";5324}5325 git_footer_html();5326}53275328sub git_commit {5329$hash||=$hash_base||"HEAD";5330my%co= parse_commit($hash)5331or die_error(404,"Unknown commit object");53325333my$parent=$co{'parent'};5334my$parents=$co{'parents'};# listref53355336# we need to prepare $formats_nav before any parameter munging5337my$formats_nav;5338if(!defined$parent) {5339# --root commitdiff5340$formats_nav.='(initial)';5341}elsif(@$parents==1) {5342# single parent commit5343$formats_nav.=5344'(parent: '.5345$cgi->a({-href => href(action=>"commit",5346 hash=>$parent)},5347 esc_html(substr($parent,0,7))) .5348')';5349}else{5350# merge commit5351$formats_nav.=5352'(merge: '.5353join(' ',map{5354$cgi->a({-href => href(action=>"commit",5355 hash=>$_)},5356 esc_html(substr($_,0,7)));5357}@$parents) .5358')';5359}5360if(gitweb_check_feature('patches')) {5361$formats_nav.=" | ".5362$cgi->a({-href => href(action=>"patch", -replay=>1)},5363"patch");5364}53655366if(!defined$parent) {5367$parent="--root";5368}5369my@difftree;5370open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5371@diff_opts,5372(@$parents<=1?$parent:'-c'),5373$hash,"--"5374or die_error(500,"Open git-diff-tree failed");5375@difftree=map{chomp;$_} <$fd>;5376close$fdor die_error(404,"Reading git-diff-tree failed");53775378# non-textual hash id's can be cached5379my$expires;5380if($hash=~m/^[0-9a-fA-F]{40}$/) {5381$expires="+1d";5382}5383my$refs= git_get_references();5384my$ref= format_ref_marker($refs,$co{'id'});53855386 git_header_html(undef,$expires);5387 git_print_page_nav('commit','',5388$hash,$co{'tree'},$hash,5389$formats_nav);53905391if(defined$co{'parent'}) {5392 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5393}else{5394 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5395}5396print"<div class=\"title_text\">\n".5397"<table class=\"object_header\">\n";5398 git_print_authorship_rows(\%co);5399print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";5400print"<tr>".5401"<td>tree</td>".5402"<td class=\"sha1\">".5403$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),5404class=>"list"},$co{'tree'}) .5405"</td>".5406"<td class=\"link\">".5407$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},5408"tree");5409my$snapshot_links= format_snapshot_links($hash);5410if(defined$snapshot_links) {5411print" | ".$snapshot_links;5412}5413print"</td>".5414"</tr>\n";54155416foreachmy$par(@$parents) {5417print"<tr>".5418"<td>parent</td>".5419"<td class=\"sha1\">".5420$cgi->a({-href => href(action=>"commit", hash=>$par),5421class=>"list"},$par) .5422"</td>".5423"<td class=\"link\">".5424$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .5425" | ".5426$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .5427"</td>".5428"</tr>\n";5429}5430print"</table>".5431"</div>\n";54325433print"<div class=\"page_body\">\n";5434 git_print_log($co{'comment'});5435print"</div>\n";54365437 git_difftree_body(\@difftree,$hash,@$parents);54385439 git_footer_html();5440}54415442sub git_object {5443# object is defined by:5444# - hash or hash_base alone5445# - hash_base and file_name5446my$type;54475448# - hash or hash_base alone5449if($hash|| ($hash_base&& !defined$file_name)) {5450my$object_id=$hash||$hash_base;54515452open my$fd,"-|", quote_command(5453 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'5454or die_error(404,"Object does not exist");5455$type= <$fd>;5456chomp$type;5457close$fd5458or die_error(404,"Object does not exist");54595460# - hash_base and file_name5461}elsif($hash_base&&defined$file_name) {5462$file_name=~ s,/+$,,;54635464system(git_cmd(),"cat-file",'-e',$hash_base) ==05465or die_error(404,"Base object does not exist");54665467# here errors should not hapen5468open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name5469or die_error(500,"Open git-ls-tree failed");5470my$line= <$fd>;5471close$fd;54725473#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'5474unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {5475 die_error(404,"File or directory for given base does not exist");5476}5477$type=$2;5478$hash=$3;5479}else{5480 die_error(400,"Not enough information to find object");5481}54825483print$cgi->redirect(-uri => href(action=>$type, -full=>1,5484 hash=>$hash, hash_base=>$hash_base,5485 file_name=>$file_name),5486-status =>'302 Found');5487}54885489sub git_blobdiff {5490my$format=shift||'html';54915492my$fd;5493my@difftree;5494my%diffinfo;5495my$expires;54965497# preparing $fd and %diffinfo for git_patchset_body5498# new style URI5499if(defined$hash_base&&defined$hash_parent_base) {5500if(defined$file_name) {5501# read raw output5502open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5503$hash_parent_base,$hash_base,5504"--", (defined$file_parent?$file_parent: ()),$file_name5505or die_error(500,"Open git-diff-tree failed");5506@difftree=map{chomp;$_} <$fd>;5507close$fd5508or die_error(404,"Reading git-diff-tree failed");5509@difftree5510or die_error(404,"Blob diff not found");55115512}elsif(defined$hash&&5513$hash=~/[0-9a-fA-F]{40}/) {5514# try to find filename from $hash55155516# read filtered raw output5517open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5518$hash_parent_base,$hash_base,"--"5519or die_error(500,"Open git-diff-tree failed");5520@difftree=5521# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5522# $hash == to_id5523grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5524map{chomp;$_} <$fd>;5525close$fd5526or die_error(404,"Reading git-diff-tree failed");5527@difftree5528or die_error(404,"Blob diff not found");55295530}else{5531 die_error(400,"Missing one of the blob diff parameters");5532}55335534if(@difftree>1) {5535 die_error(400,"Ambiguous blob diff specification");5536}55375538%diffinfo= parse_difftree_raw_line($difftree[0]);5539$file_parent||=$diffinfo{'from_file'} ||$file_name;5540$file_name||=$diffinfo{'to_file'};55415542$hash_parent||=$diffinfo{'from_id'};5543$hash||=$diffinfo{'to_id'};55445545# non-textual hash id's can be cached5546if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5547$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5548$expires='+1d';5549}55505551# open patch output5552open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5553'-p', ($formateq'html'?"--full-index": ()),5554$hash_parent_base,$hash_base,5555"--", (defined$file_parent?$file_parent: ()),$file_name5556or die_error(500,"Open git-diff-tree failed");5557}55585559# old/legacy style URI -- not generated anymore since 1.4.3.5560if(!%diffinfo) {5561 die_error('404 Not Found',"Missing one of the blob diff parameters")5562}55635564# header5565if($formateq'html') {5566my$formats_nav=5567$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5568"raw");5569 git_header_html(undef,$expires);5570if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5571 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5572 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5573}else{5574print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5575print"<div class=\"title\">$hashvs$hash_parent</div>\n";5576}5577if(defined$file_name) {5578 git_print_page_path($file_name,"blob",$hash_base);5579}else{5580print"<div class=\"page_path\"></div>\n";5581}55825583}elsif($formateq'plain') {5584print$cgi->header(5585-type =>'text/plain',5586-charset =>'utf-8',5587-expires =>$expires,5588-content_disposition =>'inline; filename="'."$file_name".'.patch"');55895590print"X-Git-Url: ".$cgi->self_url() ."\n\n";55915592}else{5593 die_error(400,"Unknown blobdiff format");5594}55955596# patch5597if($formateq'html') {5598print"<div class=\"page_body\">\n";55995600 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5601close$fd;56025603print"</div>\n";# class="page_body"5604 git_footer_html();56055606}else{5607while(my$line= <$fd>) {5608$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5609$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;56105611print$line;56125613last if$line=~m!^\+\+\+!;5614}5615local$/=undef;5616print<$fd>;5617close$fd;5618}5619}56205621sub git_blobdiff_plain {5622 git_blobdiff('plain');5623}56245625sub git_commitdiff {5626my%params=@_;5627my$format=$params{-format} ||'html';56285629my($patch_max) = gitweb_get_feature('patches');5630if($formateq'patch') {5631 die_error(403,"Patch view not allowed")unless$patch_max;5632}56335634$hash||=$hash_base||"HEAD";5635my%co= parse_commit($hash)5636or die_error(404,"Unknown commit object");56375638# choose format for commitdiff for merge5639if(!defined$hash_parent&& @{$co{'parents'}} >1) {5640$hash_parent='--cc';5641}5642# we need to prepare $formats_nav before almost any parameter munging5643my$formats_nav;5644if($formateq'html') {5645$formats_nav=5646$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},5647"raw");5648if($patch_max) {5649$formats_nav.=" | ".5650$cgi->a({-href => href(action=>"patch", -replay=>1)},5651"patch");5652}56535654if(defined$hash_parent&&5655$hash_parentne'-c'&&$hash_parentne'--cc') {5656# commitdiff with two commits given5657my$hash_parent_short=$hash_parent;5658if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {5659$hash_parent_short=substr($hash_parent,0,7);5660}5661$formats_nav.=5662' (from';5663for(my$i=0;$i< @{$co{'parents'}};$i++) {5664if($co{'parents'}[$i]eq$hash_parent) {5665$formats_nav.=' parent '. ($i+1);5666last;5667}5668}5669$formats_nav.=': '.5670$cgi->a({-href => href(action=>"commitdiff",5671 hash=>$hash_parent)},5672 esc_html($hash_parent_short)) .5673')';5674}elsif(!$co{'parent'}) {5675# --root commitdiff5676$formats_nav.=' (initial)';5677}elsif(scalar@{$co{'parents'}} ==1) {5678# single parent commit5679$formats_nav.=5680' (parent: '.5681$cgi->a({-href => href(action=>"commitdiff",5682 hash=>$co{'parent'})},5683 esc_html(substr($co{'parent'},0,7))) .5684')';5685}else{5686# merge commit5687if($hash_parenteq'--cc') {5688$formats_nav.=' | '.5689$cgi->a({-href => href(action=>"commitdiff",5690 hash=>$hash, hash_parent=>'-c')},5691'combined');5692}else{# $hash_parent eq '-c'5693$formats_nav.=' | '.5694$cgi->a({-href => href(action=>"commitdiff",5695 hash=>$hash, hash_parent=>'--cc')},5696'compact');5697}5698$formats_nav.=5699' (merge: '.5700join(' ',map{5701$cgi->a({-href => href(action=>"commitdiff",5702 hash=>$_)},5703 esc_html(substr($_,0,7)));5704} @{$co{'parents'}} ) .5705')';5706}5707}57085709my$hash_parent_param=$hash_parent;5710if(!defined$hash_parent_param) {5711# --cc for multiple parents, --root for parentless5712$hash_parent_param=5713@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';5714}57155716# read commitdiff5717my$fd;5718my@difftree;5719if($formateq'html') {5720open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5721"--no-commit-id","--patch-with-raw","--full-index",5722$hash_parent_param,$hash,"--"5723or die_error(500,"Open git-diff-tree failed");57245725while(my$line= <$fd>) {5726chomp$line;5727# empty line ends raw part of diff-tree output5728last unless$line;5729push@difftree,scalar parse_difftree_raw_line($line);5730}57315732}elsif($formateq'plain') {5733open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5734'-p',$hash_parent_param,$hash,"--"5735or die_error(500,"Open git-diff-tree failed");5736}elsif($formateq'patch') {5737# For commit ranges, we limit the output to the number of5738# patches specified in the 'patches' feature.5739# For single commits, we limit the output to a single patch,5740# diverging from the git-format-patch default.5741my@commit_spec= ();5742if($hash_parent) {5743if($patch_max>0) {5744push@commit_spec,"-$patch_max";5745}5746push@commit_spec,'-n',"$hash_parent..$hash";5747}else{5748if($params{-single}) {5749push@commit_spec,'-1';5750}else{5751if($patch_max>0) {5752push@commit_spec,"-$patch_max";5753}5754push@commit_spec,"-n";5755}5756push@commit_spec,'--root',$hash;5757}5758open$fd,"-|", git_cmd(),"format-patch",'--encoding=utf8',5759'--stdout',@commit_spec5760or die_error(500,"Open git-format-patch failed");5761}else{5762 die_error(400,"Unknown commitdiff format");5763}57645765# non-textual hash id's can be cached5766my$expires;5767if($hash=~m/^[0-9a-fA-F]{40}$/) {5768$expires="+1d";5769}57705771# write commit message5772if($formateq'html') {5773my$refs= git_get_references();5774my$ref= format_ref_marker($refs,$co{'id'});57755776 git_header_html(undef,$expires);5777 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);5778 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);5779print"<div class=\"title_text\">\n".5780"<table class=\"object_header\">\n";5781 git_print_authorship_rows(\%co);5782print"</table>".5783"</div>\n";5784print"<div class=\"page_body\">\n";5785if(@{$co{'comment'}} >1) {5786print"<div class=\"log\">\n";5787 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);5788print"</div>\n";# class="log"5789}57905791}elsif($formateq'plain') {5792my$refs= git_get_references("tags");5793my$tagname= git_get_rev_name_tags($hash);5794my$filename= basename($project) ."-$hash.patch";57955796print$cgi->header(5797-type =>'text/plain',5798-charset =>'utf-8',5799-expires =>$expires,5800-content_disposition =>'inline; filename="'."$filename".'"');5801my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5802print"From: ". to_utf8($co{'author'}) ."\n";5803print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";5804print"Subject: ". to_utf8($co{'title'}) ."\n";58055806print"X-Git-Tag:$tagname\n"if$tagname;5807print"X-Git-Url: ".$cgi->self_url() ."\n\n";58085809foreachmy$line(@{$co{'comment'}}) {5810print to_utf8($line) ."\n";5811}5812print"---\n\n";5813}elsif($formateq'patch') {5814my$filename= basename($project) ."-$hash.patch";58155816print$cgi->header(5817-type =>'text/plain',5818-charset =>'utf-8',5819-expires =>$expires,5820-content_disposition =>'inline; filename="'."$filename".'"');5821}58225823# write patch5824if($formateq'html') {5825my$use_parents= !defined$hash_parent||5826$hash_parenteq'-c'||$hash_parenteq'--cc';5827 git_difftree_body(\@difftree,$hash,5828$use_parents? @{$co{'parents'}} :$hash_parent);5829print"<br/>\n";58305831 git_patchset_body($fd, \@difftree,$hash,5832$use_parents? @{$co{'parents'}} :$hash_parent);5833close$fd;5834print"</div>\n";# class="page_body"5835 git_footer_html();58365837}elsif($formateq'plain') {5838local$/=undef;5839print<$fd>;5840close$fd5841or print"Reading git-diff-tree failed\n";5842}elsif($formateq'patch') {5843local$/=undef;5844print<$fd>;5845close$fd5846or print"Reading git-format-patch failed\n";5847}5848}58495850sub git_commitdiff_plain {5851 git_commitdiff(-format =>'plain');5852}58535854# format-patch-style patches5855sub git_patch {5856 git_commitdiff(-format =>'patch', -single=>1);5857}58585859sub git_patches {5860 git_commitdiff(-format =>'patch');5861}58625863sub git_history {5864if(!defined$hash_base) {5865$hash_base= git_get_head_hash($project);5866}5867if(!defined$page) {5868$page=0;5869}5870my$ftype;5871my%co= parse_commit($hash_base)5872or die_error(404,"Unknown commit object");58735874my$refs= git_get_references();5875my$limit=sprintf("--max-count=%i", (100* ($page+1)));58765877my@commitlist= parse_commits($hash_base,101, (100*$page),5878$file_name,"--full-history")5879or die_error(404,"No such file or directory on given branch");58805881if(!defined$hash&&defined$file_name) {5882# some commits could have deleted file in question,5883# and not have it in tree, but one of them has to have it5884for(my$i=0;$i<=@commitlist;$i++) {5885$hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5886last ifdefined$hash;5887}5888}5889if(defined$hash) {5890$ftype= git_get_type($hash);5891}5892if(!defined$ftype) {5893 die_error(500,"Unknown type of object");5894}58955896my$paging_nav='';5897if($page>0) {5898$paging_nav.=5899$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,5900 file_name=>$file_name)},5901"first");5902$paging_nav.=" ⋅ ".5903$cgi->a({-href => href(-replay=>1, page=>$page-1),5904-accesskey =>"p", -title =>"Alt-p"},"prev");5905}else{5906$paging_nav.="first";5907$paging_nav.=" ⋅ prev";5908}5909my$next_link='';5910if($#commitlist>=100) {5911$next_link=5912$cgi->a({-href => href(-replay=>1, page=>$page+1),5913-accesskey =>"n", -title =>"Alt-n"},"next");5914$paging_nav.=" ⋅$next_link";5915}else{5916$paging_nav.=" ⋅ next";5917}59185919 git_header_html();5920 git_print_page_nav('history','',$hash_base,$co{'tree'},$hash_base,$paging_nav);5921 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5922 git_print_page_path($file_name,$ftype,$hash_base);59235924 git_history_body(\@commitlist,0,99,5925$refs,$hash_base,$ftype,$next_link);59265927 git_footer_html();5928}59295930sub git_search {5931 gitweb_check_feature('search')or die_error(403,"Search is disabled");5932if(!defined$searchtext) {5933 die_error(400,"Text field is empty");5934}5935if(!defined$hash) {5936$hash= git_get_head_hash($project);5937}5938my%co= parse_commit($hash);5939if(!%co) {5940 die_error(404,"Unknown commit object");5941}5942if(!defined$page) {5943$page=0;5944}59455946$searchtype||='commit';5947if($searchtypeeq'pickaxe') {5948# pickaxe may take all resources of your box and run for several minutes5949# with every query - so decide by yourself how public you make this feature5950 gitweb_check_feature('pickaxe')5951or die_error(403,"Pickaxe is disabled");5952}5953if($searchtypeeq'grep') {5954 gitweb_check_feature('grep')5955or die_error(403,"Grep is disabled");5956}59575958 git_header_html();59595960if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {5961my$greptype;5962if($searchtypeeq'commit') {5963$greptype="--grep=";5964}elsif($searchtypeeq'author') {5965$greptype="--author=";5966}elsif($searchtypeeq'committer') {5967$greptype="--committer=";5968}5969$greptype.=$searchtext;5970my@commitlist= parse_commits($hash,101, (100*$page),undef,5971$greptype,'--regexp-ignore-case',5972$search_use_regexp?'--extended-regexp':'--fixed-strings');59735974my$paging_nav='';5975if($page>0) {5976$paging_nav.=5977$cgi->a({-href => href(action=>"search", hash=>$hash,5978 searchtext=>$searchtext,5979 searchtype=>$searchtype)},5980"first");5981$paging_nav.=" ⋅ ".5982$cgi->a({-href => href(-replay=>1, page=>$page-1),5983-accesskey =>"p", -title =>"Alt-p"},"prev");5984}else{5985$paging_nav.="first";5986$paging_nav.=" ⋅ prev";5987}5988my$next_link='';5989if($#commitlist>=100) {5990$next_link=5991$cgi->a({-href => href(-replay=>1, page=>$page+1),5992-accesskey =>"n", -title =>"Alt-n"},"next");5993$paging_nav.=" ⋅$next_link";5994}else{5995$paging_nav.=" ⋅ next";5996}59975998if($#commitlist>=100) {5999}60006001 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);6002 git_print_header_div('commit', esc_html($co{'title'}),$hash);6003 git_search_grep_body(\@commitlist,0,99,$next_link);6004}60056006if($searchtypeeq'pickaxe') {6007 git_print_page_nav('','',$hash,$co{'tree'},$hash);6008 git_print_header_div('commit', esc_html($co{'title'}),$hash);60096010print"<table class=\"pickaxe search\">\n";6011my$alternate=1;6012local$/="\n";6013open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,6014'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",6015($search_use_regexp?'--pickaxe-regex': ());6016undef%co;6017my@files;6018while(my$line= <$fd>) {6019chomp$line;6020next unless$line;60216022my%set= parse_difftree_raw_line($line);6023if(defined$set{'commit'}) {6024# finish previous commit6025if(%co) {6026print"</td>\n".6027"<td class=\"link\">".6028$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6029" | ".6030$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6031print"</td>\n".6032"</tr>\n";6033}60346035if($alternate) {6036print"<tr class=\"dark\">\n";6037}else{6038print"<tr class=\"light\">\n";6039}6040$alternate^=1;6041%co= parse_commit($set{'commit'});6042my$author= chop_and_escape_str($co{'author_name'},15,5);6043print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6044"<td><i>$author</i></td>\n".6045"<td>".6046$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6047-class=>"list subject"},6048 chop_and_escape_str($co{'title'},50) ."<br/>");6049}elsif(defined$set{'to_id'}) {6050next if($set{'to_id'} =~m/^0{40}$/);60516052print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6053 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6054-class=>"list"},6055"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6056"<br/>\n";6057}6058}6059close$fd;60606061# finish last commit (warning: repetition!)6062if(%co) {6063print"</td>\n".6064"<td class=\"link\">".6065$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6066" | ".6067$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6068print"</td>\n".6069"</tr>\n";6070}60716072print"</table>\n";6073}60746075if($searchtypeeq'grep') {6076 git_print_page_nav('','',$hash,$co{'tree'},$hash);6077 git_print_header_div('commit', esc_html($co{'title'}),$hash);60786079print"<table class=\"grep_search\">\n";6080my$alternate=1;6081my$matches=0;6082local$/="\n";6083open my$fd,"-|", git_cmd(),'grep','-n',6084$search_use_regexp? ('-E','-i') :'-F',6085$searchtext,$co{'tree'};6086my$lastfile='';6087while(my$line= <$fd>) {6088chomp$line;6089my($file,$lno,$ltext,$binary);6090last if($matches++>1000);6091if($line=~/^Binary file (.+) matches$/) {6092$file=$1;6093$binary=1;6094}else{6095(undef,$file,$lno,$ltext) =split(/:/,$line,4);6096}6097if($filene$lastfile) {6098$lastfileand print"</td></tr>\n";6099if($alternate++) {6100print"<tr class=\"dark\">\n";6101}else{6102print"<tr class=\"light\">\n";6103}6104print"<td class=\"list\">".6105$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6106 file_name=>"$file"),6107-class=>"list"}, esc_path($file));6108print"</td><td>\n";6109$lastfile=$file;6110}6111if($binary) {6112print"<div class=\"binary\">Binary file</div>\n";6113}else{6114$ltext= untabify($ltext);6115if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6116$ltext= esc_html($1, -nbsp=>1);6117$ltext.='<span class="match">';6118$ltext.= esc_html($2, -nbsp=>1);6119$ltext.='</span>';6120$ltext.= esc_html($3, -nbsp=>1);6121}else{6122$ltext= esc_html($ltext, -nbsp=>1);6123}6124print"<div class=\"pre\">".6125$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6126 file_name=>"$file").'#l'.$lno,6127-class=>"linenr"},sprintf('%4i',$lno))6128.' '.$ltext."</div>\n";6129}6130}6131if($lastfile) {6132print"</td></tr>\n";6133if($matches>1000) {6134print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6135}6136}else{6137print"<div class=\"diff nodifferences\">No matches found</div>\n";6138}6139close$fd;61406141print"</table>\n";6142}6143 git_footer_html();6144}61456146sub git_search_help {6147 git_header_html();6148 git_print_page_nav('','',$hash,$hash,$hash);6149print<<EOT;6150<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without6151regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,6152the pattern entered is recognized as the POSIX extended6153<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case6154insensitive).</p>6155<dl>6156<dt><b>commit</b></dt>6157<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>6158EOT6159my$have_grep= gitweb_check_feature('grep');6160if($have_grep) {6161print<<EOT;6162<dt><b>grep</b></dt>6163<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing6164 a different one) are searched for the given pattern. On large trees, this search can take6165a while and put some strain on the server, so please use it with some consideration. Note that6166due to git-grep peculiarity, currently if regexp mode is turned off, the matches are6167case-sensitive.</dd>6168EOT6169}6170print<<EOT;6171<dt><b>author</b></dt>6172<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>6173<dt><b>committer</b></dt>6174<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>6175EOT6176my$have_pickaxe= gitweb_check_feature('pickaxe');6177if($have_pickaxe) {6178print<<EOT;6179<dt><b>pickaxe</b></dt>6180<dd>All commits that caused the string to appear or disappear from any file (changes that6181added, removed or "modified" the string) will be listed. This search can take a while and6182takes a lot of strain on the server, so please use it wisely. Note that since you may be6183interested even in changes just changing the case as well, this search is case sensitive.</dd>6184EOT6185}6186print"</dl>\n";6187 git_footer_html();6188}61896190sub git_shortlog {6191my$head= git_get_head_hash($project);6192if(!defined$hash) {6193$hash=$head;6194}6195if(!defined$page) {6196$page=0;6197}6198my$refs= git_get_references();61996200my$commit_hash=$hash;6201if(defined$hash_parent) {6202$commit_hash="$hash_parent..$hash";6203}6204my@commitlist= parse_commits($commit_hash,101, (100*$page));62056206my$paging_nav= format_paging_nav('shortlog',$hash,$head,$page,$#commitlist>=100);6207my$next_link='';6208if($#commitlist>=100) {6209$next_link=6210$cgi->a({-href => href(-replay=>1, page=>$page+1),6211-accesskey =>"n", -title =>"Alt-n"},"next");6212}6213my$patch_max= gitweb_check_feature('patches');6214if($patch_max) {6215if($patch_max<0||@commitlist<=$patch_max) {6216$paging_nav.=" ⋅ ".6217$cgi->a({-href => href(action=>"patches", -replay=>1)},6218"patches");6219}6220}62216222 git_header_html();6223 git_print_page_nav('shortlog','',$hash,$hash,$hash,$paging_nav);6224 git_print_header_div('summary',$project);62256226 git_shortlog_body(\@commitlist,0,99,$refs,$next_link);62276228 git_footer_html();6229}62306231## ......................................................................6232## feeds (RSS, Atom; OPML)62336234sub git_feed {6235my$format=shift||'atom';6236my$have_blame= gitweb_check_feature('blame');62376238# Atom: http://www.atomenabled.org/developers/syndication/6239# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ6240if($formatne'rss'&&$formatne'atom') {6241 die_error(400,"Unknown web feed format");6242}62436244# log/feed of current (HEAD) branch, log of given branch, history of file/directory6245my$head=$hash||'HEAD';6246my@commitlist= parse_commits($head,150,0,$file_name);62476248my%latest_commit;6249my%latest_date;6250my$content_type="application/$format+xml";6251if(defined$cgi->http('HTTP_ACCEPT') &&6252$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {6253# browser (feed reader) prefers text/xml6254$content_type='text/xml';6255}6256if(defined($commitlist[0])) {6257%latest_commit= %{$commitlist[0]};6258my$latest_epoch=$latest_commit{'committer_epoch'};6259%latest_date= parse_date($latest_epoch);6260my$if_modified=$cgi->http('IF_MODIFIED_SINCE');6261if(defined$if_modified) {6262my$since;6263if(eval{require HTTP::Date;1; }) {6264$since= HTTP::Date::str2time($if_modified);6265}elsif(eval{require Time::ParseDate;1; }) {6266$since= Time::ParseDate::parsedate($if_modified, GMT =>1);6267}6268if(defined$since&&$latest_epoch<=$since) {6269print$cgi->header(6270-type =>$content_type,6271-charset =>'utf-8',6272-last_modified =>$latest_date{'rfc2822'},6273-status =>'304 Not Modified');6274return;6275}6276}6277print$cgi->header(6278-type =>$content_type,6279-charset =>'utf-8',6280-last_modified =>$latest_date{'rfc2822'});6281}else{6282print$cgi->header(6283-type =>$content_type,6284-charset =>'utf-8');6285}62866287# Optimization: skip generating the body if client asks only6288# for Last-Modified date.6289return if($cgi->request_method()eq'HEAD');62906291# header variables6292my$title="$site_name-$project/$action";6293my$feed_type='log';6294if(defined$hash) {6295$title.=" - '$hash'";6296$feed_type='branch log';6297if(defined$file_name) {6298$title.=" ::$file_name";6299$feed_type='history';6300}6301}elsif(defined$file_name) {6302$title.=" -$file_name";6303$feed_type='history';6304}6305$title.="$feed_type";6306my$descr= git_get_project_description($project);6307if(defined$descr) {6308$descr= esc_html($descr);6309}else{6310$descr="$project".6311($formateq'rss'?'RSS':'Atom') .6312" feed";6313}6314my$owner= git_get_project_owner($project);6315$owner= esc_html($owner);63166317#header6318my$alt_url;6319if(defined$file_name) {6320$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);6321}elsif(defined$hash) {6322$alt_url= href(-full=>1, action=>"log", hash=>$hash);6323}else{6324$alt_url= href(-full=>1, action=>"summary");6325}6326print qq!<?xml version="1.0" encoding="utf-8"?>\n!;6327if($formateq'rss') {6328print<<XML;6329<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">6330<channel>6331XML6332print"<title>$title</title>\n".6333"<link>$alt_url</link>\n".6334"<description>$descr</description>\n".6335"<language>en</language>\n".6336# project owner is responsible for 'editorial' content6337"<managingEditor>$owner</managingEditor>\n";6338if(defined$logo||defined$favicon) {6339# prefer the logo to the favicon, since RSS6340# doesn't allow both6341my$img= esc_url($logo||$favicon);6342print"<image>\n".6343"<url>$img</url>\n".6344"<title>$title</title>\n".6345"<link>$alt_url</link>\n".6346"</image>\n";6347}6348if(%latest_date) {6349print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";6350print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";6351}6352print"<generator>gitweb v.$version/$git_version</generator>\n";6353}elsif($formateq'atom') {6354print<<XML;6355<feed xmlns="http://www.w3.org/2005/Atom">6356XML6357print"<title>$title</title>\n".6358"<subtitle>$descr</subtitle>\n".6359'<link rel="alternate" type="text/html" href="'.6360$alt_url.'" />'."\n".6361'<link rel="self" type="'.$content_type.'" href="'.6362$cgi->self_url() .'" />'."\n".6363"<id>". href(-full=>1) ."</id>\n".6364# use project owner for feed author6365"<author><name>$owner</name></author>\n";6366if(defined$favicon) {6367print"<icon>". esc_url($favicon) ."</icon>\n";6368}6369if(defined$logo_url) {6370# not twice as wide as tall: 72 x 27 pixels6371print"<logo>". esc_url($logo) ."</logo>\n";6372}6373if(!%latest_date) {6374# dummy date to keep the feed valid until commits trickle in:6375print"<updated>1970-01-01T00:00:00Z</updated>\n";6376}else{6377print"<updated>$latest_date{'iso-8601'}</updated>\n";6378}6379print"<generator version='$version/$git_version'>gitweb</generator>\n";6380}63816382# contents6383for(my$i=0;$i<=$#commitlist;$i++) {6384my%co= %{$commitlist[$i]};6385my$commit=$co{'id'};6386# we read 150, we always show 30 and the ones more recent than 48 hours6387if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6388last;6389}6390my%cd= parse_date($co{'author_epoch'});63916392# get list of changed files6393open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6394$co{'parent'} ||"--root",6395$co{'id'},"--", (defined$file_name?$file_name: ())6396ornext;6397my@difftree=map{chomp;$_} <$fd>;6398close$fd6399ornext;64006401# print element (entry, item)6402my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6403if($formateq'rss') {6404print"<item>\n".6405"<title>". esc_html($co{'title'}) ."</title>\n".6406"<author>". esc_html($co{'author'}) ."</author>\n".6407"<pubDate>$cd{'rfc2822'}</pubDate>\n".6408"<guid isPermaLink=\"true\">$co_url</guid>\n".6409"<link>$co_url</link>\n".6410"<description>". esc_html($co{'title'}) ."</description>\n".6411"<content:encoded>".6412"<![CDATA[\n";6413}elsif($formateq'atom') {6414print"<entry>\n".6415"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6416"<updated>$cd{'iso-8601'}</updated>\n".6417"<author>\n".6418" <name>". esc_html($co{'author_name'}) ."</name>\n";6419if($co{'author_email'}) {6420print" <email>". esc_html($co{'author_email'}) ."</email>\n";6421}6422print"</author>\n".6423# use committer for contributor6424"<contributor>\n".6425" <name>". esc_html($co{'committer_name'}) ."</name>\n";6426if($co{'committer_email'}) {6427print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6428}6429print"</contributor>\n".6430"<published>$cd{'iso-8601'}</published>\n".6431"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6432"<id>$co_url</id>\n".6433"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6434"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6435}6436my$comment=$co{'comment'};6437print"<pre>\n";6438foreachmy$line(@$comment) {6439$line= esc_html($line);6440print"$line\n";6441}6442print"</pre><ul>\n";6443foreachmy$difftree_line(@difftree) {6444my%difftree= parse_difftree_raw_line($difftree_line);6445next if!$difftree{'from_id'};64466447my$file=$difftree{'file'} ||$difftree{'to_file'};64486449print"<li>".6450"[".6451$cgi->a({-href => href(-full=>1, action=>"blobdiff",6452 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6453 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6454 file_name=>$file, file_parent=>$difftree{'from_file'}),6455-title =>"diff"},'D');6456if($have_blame) {6457print$cgi->a({-href => href(-full=>1, action=>"blame",6458 file_name=>$file, hash_base=>$commit),6459-title =>"blame"},'B');6460}6461# if this is not a feed of a file history6462if(!defined$file_name||$file_namene$file) {6463print$cgi->a({-href => href(-full=>1, action=>"history",6464 file_name=>$file, hash=>$commit),6465-title =>"history"},'H');6466}6467$file= esc_path($file);6468print"] ".6469"$file</li>\n";6470}6471if($formateq'rss') {6472print"</ul>]]>\n".6473"</content:encoded>\n".6474"</item>\n";6475}elsif($formateq'atom') {6476print"</ul>\n</div>\n".6477"</content>\n".6478"</entry>\n";6479}6480}64816482# end of feed6483if($formateq'rss') {6484print"</channel>\n</rss>\n";6485}elsif($formateq'atom') {6486print"</feed>\n";6487}6488}64896490sub git_rss {6491 git_feed('rss');6492}64936494sub git_atom {6495 git_feed('atom');6496}64976498sub git_opml {6499my@list= git_get_projects_list();65006501print$cgi->header(6502-type =>'text/xml',6503-charset =>'utf-8',6504-content_disposition =>'inline; filename="opml.xml"');65056506print<<XML;6507<?xml version="1.0" encoding="utf-8"?>6508<opml version="1.0">6509<head>6510 <title>$site_nameOPML Export</title>6511</head>6512<body>6513<outline text="git RSS feeds">6514XML65156516foreachmy$pr(@list) {6517my%proj=%$pr;6518my$head= git_get_head_hash($proj{'path'});6519if(!defined$head) {6520next;6521}6522$git_dir="$projectroot/$proj{'path'}";6523my%co= parse_commit($head);6524if(!%co) {6525next;6526}65276528my$path= esc_html(chop_str($proj{'path'},25,5));6529my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);6530my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);6531print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";6532}6533print<<XML;6534</outline>6535</body>6536</opml>6537XML6538}