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 10use5.008; 11use strict; 12use warnings; 13use CGI qw(:standard :escapeHTML -nosticky); 14use CGI::Util qw(unescape); 15use CGI::Carp qw(fatalsToBrowser set_message); 16use Encode; 17use Fcntl ':mode'; 18use File::Find qw(); 19use File::Basename qw(basename); 20use Time::HiRes qw(gettimeofday tv_interval); 21binmode STDOUT,':utf8'; 22 23our$t0= [ gettimeofday() ]; 24our$number_of_git_cmds=0; 25 26BEGIN{ 27 CGI->compile()if$ENV{'MOD_PERL'}; 28} 29 30our$version="++GIT_VERSION++"; 31 32our($my_url,$my_uri,$base_url,$path_info,$home_link); 33sub evaluate_uri { 34our$cgi; 35 36our$my_url=$cgi->url(); 37our$my_uri=$cgi->url(-absolute =>1); 38 39# Base URL for relative URLs in gitweb ($logo, $favicon, ...), 40# needed and used only for URLs with nonempty PATH_INFO 41our$base_url=$my_url; 42 43# When the script is used as DirectoryIndex, the URL does not contain the name 44# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we 45# have to do it ourselves. We make $path_info global because it's also used 46# later on. 47# 48# Another issue with the script being the DirectoryIndex is that the resulting 49# $my_url data is not the full script URL: this is good, because we want 50# generated links to keep implying the script name if it wasn't explicitly 51# indicated in the URL we're handling, but it means that $my_url cannot be used 52# as base URL. 53# Therefore, if we needed to strip PATH_INFO, then we know that we have 54# to build the base URL ourselves: 55our$path_info= decode_utf8($ENV{"PATH_INFO"}); 56if($path_info) { 57if($my_url=~ s,\Q$path_info\E$,, && 58$my_uri=~ s,\Q$path_info\E$,, && 59defined$ENV{'SCRIPT_NAME'}) { 60$base_url=$cgi->url(-base =>1) .$ENV{'SCRIPT_NAME'}; 61} 62} 63 64# target of the home link on top of all pages 65our$home_link=$my_uri||"/"; 66} 67 68# core git executable to use 69# this can just be "git" if your webserver has a sensible PATH 70our$GIT="++GIT_BINDIR++/git"; 71 72# absolute fs-path which will be prepended to the project path 73#our $projectroot = "/pub/scm"; 74our$projectroot="++GITWEB_PROJECTROOT++"; 75 76# fs traversing limit for getting project list 77# the number is relative to the projectroot 78our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 79 80# string of the home link on top of all pages 81our$home_link_str="++GITWEB_HOME_LINK_STR++"; 82 83# name of your site or organization to appear in page titles 84# replace this with something more descriptive for clearer bookmarks 85our$site_name="++GITWEB_SITENAME++" 86|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 87 88# html snippet to include in the <head> section of each page 89our$site_html_head_string="++GITWEB_SITE_HTML_HEAD_STRING++"; 90# filename of html text to include at top of each page 91our$site_header="++GITWEB_SITE_HEADER++"; 92# html text to include at home page 93our$home_text="++GITWEB_HOMETEXT++"; 94# filename of html text to include at bottom of each page 95our$site_footer="++GITWEB_SITE_FOOTER++"; 96 97# URI of stylesheets 98our@stylesheets= ("++GITWEB_CSS++"); 99# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 100our$stylesheet=undef; 101# URI of GIT logo (72x27 size) 102our$logo="++GITWEB_LOGO++"; 103# URI of GIT favicon, assumed to be image/png type 104our$favicon="++GITWEB_FAVICON++"; 105# URI of gitweb.js (JavaScript code for gitweb) 106our$javascript="++GITWEB_JS++"; 107 108# URI and label (title) of GIT logo link 109#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 110#our $logo_label = "git documentation"; 111our$logo_url="http://git-scm.com/"; 112our$logo_label="git homepage"; 113 114# source of projects list 115our$projects_list="++GITWEB_LIST++"; 116 117# the width (in characters) of the projects list "Description" column 118our$projects_list_description_width=25; 119 120# group projects by category on the projects list 121# (enabled if this variable evaluates to true) 122our$projects_list_group_categories=0; 123 124# default category if none specified 125# (leave the empty string for no category) 126our$project_list_default_category=""; 127 128# default order of projects list 129# valid values are none, project, descr, owner, and age 130our$default_projects_order="project"; 131 132# show repository only if this file exists 133# (only effective if this variable evaluates to true) 134our$export_ok="++GITWEB_EXPORT_OK++"; 135 136# show repository only if this subroutine returns true 137# when given the path to the project, for example: 138# sub { return -e "$_[0]/git-daemon-export-ok"; } 139our$export_auth_hook=undef; 140 141# only allow viewing of repositories also shown on the overview page 142our$strict_export="++GITWEB_STRICT_EXPORT++"; 143 144# list of git base URLs used for URL to where fetch project from, 145# i.e. full URL is "$git_base_url/$project" 146our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 147 148# default blob_plain mimetype and default charset for text/plain blob 149our$default_blob_plain_mimetype='text/plain'; 150our$default_text_plain_charset=undef; 151 152# file to use for guessing MIME types before trying /etc/mime.types 153# (relative to the current git repository) 154our$mimetypes_file=undef; 155 156# assume this charset if line contains non-UTF-8 characters; 157# it should be valid encoding (see Encoding::Supported(3pm) for list), 158# for which encoding all byte sequences are valid, for example 159# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 160# could be even 'utf-8' for the old behavior) 161our$fallback_encoding='latin1'; 162 163# rename detection options for git-diff and git-diff-tree 164# - default is '-M', with the cost proportional to 165# (number of removed files) * (number of new files). 166# - more costly is '-C' (which implies '-M'), with the cost proportional to 167# (number of changed files + number of removed files) * (number of new files) 168# - even more costly is '-C', '--find-copies-harder' with cost 169# (number of files in the original tree) * (number of new files) 170# - one might want to include '-B' option, e.g. '-B', '-M' 171our@diff_opts= ('-M');# taken from git_commit 172 173# Disables features that would allow repository owners to inject script into 174# the gitweb domain. 175our$prevent_xss=0; 176 177# Path to the highlight executable to use (must be the one from 178# http://www.andre-simon.de due to assumptions about parameters and output). 179# Useful if highlight is not installed on your webserver's PATH. 180# [Default: highlight] 181our$highlight_bin="++HIGHLIGHT_BIN++"; 182 183# information about snapshot formats that gitweb is capable of serving 184our%known_snapshot_formats= ( 185# name => { 186# 'display' => display name, 187# 'type' => mime type, 188# 'suffix' => filename suffix, 189# 'format' => --format for git-archive, 190# 'compressor' => [compressor command and arguments] 191# (array reference, optional) 192# 'disabled' => boolean (optional)} 193# 194'tgz'=> { 195'display'=>'tar.gz', 196'type'=>'application/x-gzip', 197'suffix'=>'.tar.gz', 198'format'=>'tar', 199'compressor'=> ['gzip','-n']}, 200 201'tbz2'=> { 202'display'=>'tar.bz2', 203'type'=>'application/x-bzip2', 204'suffix'=>'.tar.bz2', 205'format'=>'tar', 206'compressor'=> ['bzip2']}, 207 208'txz'=> { 209'display'=>'tar.xz', 210'type'=>'application/x-xz', 211'suffix'=>'.tar.xz', 212'format'=>'tar', 213'compressor'=> ['xz'], 214'disabled'=>1}, 215 216'zip'=> { 217'display'=>'zip', 218'type'=>'application/x-zip', 219'suffix'=>'.zip', 220'format'=>'zip'}, 221); 222 223# Aliases so we understand old gitweb.snapshot values in repository 224# configuration. 225our%known_snapshot_format_aliases= ( 226'gzip'=>'tgz', 227'bzip2'=>'tbz2', 228'xz'=>'txz', 229 230# backward compatibility: legacy gitweb config support 231'x-gzip'=>undef,'gz'=>undef, 232'x-bzip2'=>undef,'bz2'=>undef, 233'x-zip'=>undef,''=>undef, 234); 235 236# Pixel sizes for icons and avatars. If the default font sizes or lineheights 237# are changed, it may be appropriate to change these values too via 238# $GITWEB_CONFIG. 239our%avatar_size= ( 240'default'=>16, 241'double'=>32 242); 243 244# Used to set the maximum load that we will still respond to gitweb queries. 245# If server load exceed this value then return "503 server busy" error. 246# If gitweb cannot determined server load, it is taken to be 0. 247# Leave it undefined (or set to 'undef') to turn off load checking. 248our$maxload=300; 249 250# configuration for 'highlight' (http://www.andre-simon.de/) 251# match by basename 252our%highlight_basename= ( 253#'Program' => 'py', 254#'Library' => 'py', 255'SConstruct'=>'py',# SCons equivalent of Makefile 256'Makefile'=>'make', 257); 258# match by extension 259our%highlight_ext= ( 260# main extensions, defining name of syntax; 261# see files in /usr/share/highlight/langDefs/ directory 262map{$_=>$_} 263qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl sql make), 264# alternate extensions, see /etc/highlight/filetypes.conf 265'h'=>'c', 266map{$_=>'sh'}qw(bash zsh ksh), 267map{$_=>'cpp'}qw(cxx c++ cc), 268map{$_=>'php'}qw(php3 php4 php5 phps), 269map{$_=>'pl'}qw(perl pm),# perhaps also 'cgi' 270map{$_=>'make'}qw(mak mk), 271map{$_=>'xml'}qw(xhtml html htm), 272); 273 274# You define site-wide feature defaults here; override them with 275# $GITWEB_CONFIG as necessary. 276our%feature= ( 277# feature => { 278# 'sub' => feature-sub (subroutine), 279# 'override' => allow-override (boolean), 280# 'default' => [ default options...] (array reference)} 281# 282# if feature is overridable (it means that allow-override has true value), 283# then feature-sub will be called with default options as parameters; 284# return value of feature-sub indicates if to enable specified feature 285# 286# if there is no 'sub' key (no feature-sub), then feature cannot be 287# overridden 288# 289# use gitweb_get_feature(<feature>) to retrieve the <feature> value 290# (an array) or gitweb_check_feature(<feature>) to check if <feature> 291# is enabled 292 293# Enable the 'blame' blob view, showing the last commit that modified 294# each line in the file. This can be very CPU-intensive. 295 296# To enable system wide have in $GITWEB_CONFIG 297# $feature{'blame'}{'default'} = [1]; 298# To have project specific config enable override in $GITWEB_CONFIG 299# $feature{'blame'}{'override'} = 1; 300# and in project config gitweb.blame = 0|1; 301'blame'=> { 302'sub'=>sub{ feature_bool('blame',@_) }, 303'override'=>0, 304'default'=> [0]}, 305 306# Enable the 'snapshot' link, providing a compressed archive of any 307# tree. This can potentially generate high traffic if you have large 308# project. 309 310# Value is a list of formats defined in %known_snapshot_formats that 311# you wish to offer. 312# To disable system wide have in $GITWEB_CONFIG 313# $feature{'snapshot'}{'default'} = []; 314# To have project specific config enable override in $GITWEB_CONFIG 315# $feature{'snapshot'}{'override'} = 1; 316# and in project config, a comma-separated list of formats or "none" 317# to disable. Example: gitweb.snapshot = tbz2,zip; 318'snapshot'=> { 319'sub'=> \&feature_snapshot, 320'override'=>0, 321'default'=> ['tgz']}, 322 323# Enable text search, which will list the commits which match author, 324# committer or commit text to a given string. Enabled by default. 325# Project specific override is not supported. 326# 327# Note that this controls all search features, which means that if 328# it is disabled, then 'grep' and 'pickaxe' search would also be 329# disabled. 330'search'=> { 331'override'=>0, 332'default'=> [1]}, 333 334# Enable grep search, which will list the files in currently selected 335# tree containing the given string. Enabled by default. This can be 336# potentially CPU-intensive, of course. 337# Note that you need to have 'search' feature enabled too. 338 339# To enable system wide have in $GITWEB_CONFIG 340# $feature{'grep'}{'default'} = [1]; 341# To have project specific config enable override in $GITWEB_CONFIG 342# $feature{'grep'}{'override'} = 1; 343# and in project config gitweb.grep = 0|1; 344'grep'=> { 345'sub'=>sub{ feature_bool('grep',@_) }, 346'override'=>0, 347'default'=> [1]}, 348 349# Enable the pickaxe search, which will list the commits that modified 350# a given string in a file. This can be practical and quite faster 351# alternative to 'blame', but still potentially CPU-intensive. 352# Note that you need to have 'search' feature enabled too. 353 354# To enable system wide have in $GITWEB_CONFIG 355# $feature{'pickaxe'}{'default'} = [1]; 356# To have project specific config enable override in $GITWEB_CONFIG 357# $feature{'pickaxe'}{'override'} = 1; 358# and in project config gitweb.pickaxe = 0|1; 359'pickaxe'=> { 360'sub'=>sub{ feature_bool('pickaxe',@_) }, 361'override'=>0, 362'default'=> [1]}, 363 364# Enable showing size of blobs in a 'tree' view, in a separate 365# column, similar to what 'ls -l' does. This cost a bit of IO. 366 367# To disable system wide have in $GITWEB_CONFIG 368# $feature{'show-sizes'}{'default'} = [0]; 369# To have project specific config enable override in $GITWEB_CONFIG 370# $feature{'show-sizes'}{'override'} = 1; 371# and in project config gitweb.showsizes = 0|1; 372'show-sizes'=> { 373'sub'=>sub{ feature_bool('showsizes',@_) }, 374'override'=>0, 375'default'=> [1]}, 376 377# Make gitweb use an alternative format of the URLs which can be 378# more readable and natural-looking: project name is embedded 379# directly in the path and the query string contains other 380# auxiliary information. All gitweb installations recognize 381# URL in either format; this configures in which formats gitweb 382# generates links. 383 384# To enable system wide have in $GITWEB_CONFIG 385# $feature{'pathinfo'}{'default'} = [1]; 386# Project specific override is not supported. 387 388# Note that you will need to change the default location of CSS, 389# favicon, logo and possibly other files to an absolute URL. Also, 390# if gitweb.cgi serves as your indexfile, you will need to force 391# $my_uri to contain the script name in your $GITWEB_CONFIG. 392'pathinfo'=> { 393'override'=>0, 394'default'=> [0]}, 395 396# Make gitweb consider projects in project root subdirectories 397# to be forks of existing projects. Given project $projname.git, 398# projects matching $projname/*.git will not be shown in the main 399# projects list, instead a '+' mark will be added to $projname 400# there and a 'forks' view will be enabled for the project, listing 401# all the forks. If project list is taken from a file, forks have 402# to be listed after the main project. 403 404# To enable system wide have in $GITWEB_CONFIG 405# $feature{'forks'}{'default'} = [1]; 406# Project specific override is not supported. 407'forks'=> { 408'override'=>0, 409'default'=> [0]}, 410 411# Insert custom links to the action bar of all project pages. 412# This enables you mainly to link to third-party scripts integrating 413# into gitweb; e.g. git-browser for graphical history representation 414# or custom web-based repository administration interface. 415 416# The 'default' value consists of a list of triplets in the form 417# (label, link, position) where position is the label after which 418# to insert the link and link is a format string where %n expands 419# to the project name, %f to the project path within the filesystem, 420# %h to the current hash (h gitweb parameter) and %b to the current 421# hash base (hb gitweb parameter); %% expands to %. 422 423# To enable system wide have in $GITWEB_CONFIG e.g. 424# $feature{'actions'}{'default'} = [('graphiclog', 425# '/git-browser/by-commit.html?r=%n', 'summary')]; 426# Project specific override is not supported. 427'actions'=> { 428'override'=>0, 429'default'=> []}, 430 431# Allow gitweb scan project content tags of project repository, 432# and display the popular Web 2.0-ish "tag cloud" near the projects 433# list. Note that this is something COMPLETELY different from the 434# normal Git tags. 435 436# gitweb by itself can show existing tags, but it does not handle 437# tagging itself; you need to do it externally, outside gitweb. 438# The format is described in git_get_project_ctags() subroutine. 439# You may want to install the HTML::TagCloud Perl module to get 440# a pretty tag cloud instead of just a list of tags. 441 442# To enable system wide have in $GITWEB_CONFIG 443# $feature{'ctags'}{'default'} = [1]; 444# Project specific override is not supported. 445 446# In the future whether ctags editing is enabled might depend 447# on the value, but using 1 should always mean no editing of ctags. 448'ctags'=> { 449'override'=>0, 450'default'=> [0]}, 451 452# The maximum number of patches in a patchset generated in patch 453# view. Set this to 0 or undef to disable patch view, or to a 454# negative number to remove any limit. 455 456# To disable system wide have in $GITWEB_CONFIG 457# $feature{'patches'}{'default'} = [0]; 458# To have project specific config enable override in $GITWEB_CONFIG 459# $feature{'patches'}{'override'} = 1; 460# and in project config gitweb.patches = 0|n; 461# where n is the maximum number of patches allowed in a patchset. 462'patches'=> { 463'sub'=> \&feature_patches, 464'override'=>0, 465'default'=> [16]}, 466 467# Avatar support. When this feature is enabled, views such as 468# shortlog or commit will display an avatar associated with 469# the email of the committer(s) and/or author(s). 470 471# Currently available providers are gravatar and picon. 472# If an unknown provider is specified, the feature is disabled. 473 474# Gravatar depends on Digest::MD5. 475# Picon currently relies on the indiana.edu database. 476 477# To enable system wide have in $GITWEB_CONFIG 478# $feature{'avatar'}{'default'} = ['<provider>']; 479# where <provider> is either gravatar or picon. 480# To have project specific config enable override in $GITWEB_CONFIG 481# $feature{'avatar'}{'override'} = 1; 482# and in project config gitweb.avatar = <provider>; 483'avatar'=> { 484'sub'=> \&feature_avatar, 485'override'=>0, 486'default'=> ['']}, 487 488# Enable displaying how much time and how many git commands 489# it took to generate and display page. Disabled by default. 490# Project specific override is not supported. 491'timed'=> { 492'override'=>0, 493'default'=> [0]}, 494 495# Enable turning some links into links to actions which require 496# JavaScript to run (like 'blame_incremental'). Not enabled by 497# default. Project specific override is currently not supported. 498'javascript-actions'=> { 499'override'=>0, 500'default'=> [0]}, 501 502# Enable and configure ability to change common timezone for dates 503# in gitweb output via JavaScript. Enabled by default. 504# Project specific override is not supported. 505'javascript-timezone'=> { 506'override'=>0, 507'default'=> [ 508'local',# default timezone: 'utc', 'local', or '(-|+)HHMM' format, 509# or undef to turn off this feature 510'gitweb_tz',# name of cookie where to store selected timezone 511'datetime',# CSS class used to mark up dates for manipulation 512]}, 513 514# Syntax highlighting support. This is based on Daniel Svensson's 515# and Sham Chukoury's work in gitweb-xmms2.git. 516# It requires the 'highlight' program present in $PATH, 517# and therefore is disabled by default. 518 519# To enable system wide have in $GITWEB_CONFIG 520# $feature{'highlight'}{'default'} = [1]; 521 522'highlight'=> { 523'sub'=>sub{ feature_bool('highlight',@_) }, 524'override'=>0, 525'default'=> [0]}, 526 527# Enable displaying of remote heads in the heads list 528 529# To enable system wide have in $GITWEB_CONFIG 530# $feature{'remote_heads'}{'default'} = [1]; 531# To have project specific config enable override in $GITWEB_CONFIG 532# $feature{'remote_heads'}{'override'} = 1; 533# and in project config gitweb.remote_heads = 0|1; 534'remote_heads'=> { 535'sub'=>sub{ feature_bool('remote_heads',@_) }, 536'override'=>0, 537'default'=> [0]}, 538); 539 540sub gitweb_get_feature { 541my($name) =@_; 542return unlessexists$feature{$name}; 543my($sub,$override,@defaults) = ( 544$feature{$name}{'sub'}, 545$feature{$name}{'override'}, 546@{$feature{$name}{'default'}}); 547# project specific override is possible only if we have project 548our$git_dir;# global variable, declared later 549if(!$override|| !defined$git_dir) { 550return@defaults; 551} 552if(!defined$sub) { 553warn"feature$nameis not overridable"; 554return@defaults; 555} 556return$sub->(@defaults); 557} 558 559# A wrapper to check if a given feature is enabled. 560# With this, you can say 561# 562# my $bool_feat = gitweb_check_feature('bool_feat'); 563# gitweb_check_feature('bool_feat') or somecode; 564# 565# instead of 566# 567# my ($bool_feat) = gitweb_get_feature('bool_feat'); 568# (gitweb_get_feature('bool_feat'))[0] or somecode; 569# 570sub gitweb_check_feature { 571return(gitweb_get_feature(@_))[0]; 572} 573 574 575sub feature_bool { 576my$key=shift; 577my($val) = git_get_project_config($key,'--bool'); 578 579if(!defined$val) { 580return($_[0]); 581}elsif($valeq'true') { 582return(1); 583}elsif($valeq'false') { 584return(0); 585} 586} 587 588sub feature_snapshot { 589my(@fmts) =@_; 590 591my($val) = git_get_project_config('snapshot'); 592 593if($val) { 594@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 595} 596 597return@fmts; 598} 599 600sub feature_patches { 601my@val= (git_get_project_config('patches','--int')); 602 603if(@val) { 604return@val; 605} 606 607return($_[0]); 608} 609 610sub feature_avatar { 611my@val= (git_get_project_config('avatar')); 612 613return@val?@val:@_; 614} 615 616# checking HEAD file with -e is fragile if the repository was 617# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 618# and then pruned. 619sub check_head_link { 620my($dir) =@_; 621my$headfile="$dir/HEAD"; 622return((-e $headfile) || 623(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 624} 625 626sub check_export_ok { 627my($dir) =@_; 628return(check_head_link($dir) && 629(!$export_ok|| -e "$dir/$export_ok") && 630(!$export_auth_hook||$export_auth_hook->($dir))); 631} 632 633# process alternate names for backward compatibility 634# filter out unsupported (unknown) snapshot formats 635sub filter_snapshot_fmts { 636my@fmts=@_; 637 638@fmts=map{ 639exists$known_snapshot_format_aliases{$_} ? 640$known_snapshot_format_aliases{$_} :$_}@fmts; 641@fmts=grep{ 642exists$known_snapshot_formats{$_} && 643!$known_snapshot_formats{$_}{'disabled'}}@fmts; 644} 645 646# If it is set to code reference, it is code that it is to be run once per 647# request, allowing updating configurations that change with each request, 648# while running other code in config file only once. 649# 650# Otherwise, if it is false then gitweb would process config file only once; 651# if it is true then gitweb config would be run for each request. 652our$per_request_config=1; 653 654# read and parse gitweb config file given by its parameter. 655# returns true on success, false on recoverable error, allowing 656# to chain this subroutine, using first file that exists. 657# dies on errors during parsing config file, as it is unrecoverable. 658sub read_config_file { 659my$filename=shift; 660return unlessdefined$filename; 661# die if there are errors parsing config file 662if(-e $filename) { 663do$filename; 664die$@if$@; 665return1; 666} 667return; 668} 669 670our($GITWEB_CONFIG,$GITWEB_CONFIG_SYSTEM,$GITWEB_CONFIG_COMMON); 671sub evaluate_gitweb_config { 672our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 673our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 674our$GITWEB_CONFIG_COMMON=$ENV{'GITWEB_CONFIG_COMMON'} ||"++GITWEB_CONFIG_COMMON++"; 675 676# Protect agains duplications of file names, to not read config twice. 677# Only one of $GITWEB_CONFIG and $GITWEB_CONFIG_SYSTEM is used, so 678# there possibility of duplication of filename there doesn't matter. 679$GITWEB_CONFIG=""if($GITWEB_CONFIGeq$GITWEB_CONFIG_COMMON); 680$GITWEB_CONFIG_SYSTEM=""if($GITWEB_CONFIG_SYSTEMeq$GITWEB_CONFIG_COMMON); 681 682# Common system-wide settings for convenience. 683# Those settings can be ovverriden by GITWEB_CONFIG or GITWEB_CONFIG_SYSTEM. 684 read_config_file($GITWEB_CONFIG_COMMON); 685 686# Use first config file that exists. This means use the per-instance 687# GITWEB_CONFIG if exists, otherwise use GITWEB_SYSTEM_CONFIG. 688 read_config_file($GITWEB_CONFIG)andreturn; 689 read_config_file($GITWEB_CONFIG_SYSTEM); 690} 691 692# Get loadavg of system, to compare against $maxload. 693# Currently it requires '/proc/loadavg' present to get loadavg; 694# if it is not present it returns 0, which means no load checking. 695sub get_loadavg { 696if( -e '/proc/loadavg'){ 697open my$fd,'<','/proc/loadavg' 698orreturn0; 699my@load=split(/\s+/,scalar<$fd>); 700close$fd; 701 702# The first three columns measure CPU and IO utilization of the last one, 703# five, and 10 minute periods. The fourth column shows the number of 704# currently running processes and the total number of processes in the m/n 705# format. The last column displays the last process ID used. 706return$load[0] ||0; 707} 708# additional checks for load average should go here for things that don't export 709# /proc/loadavg 710 711return0; 712} 713 714# version of the core git binary 715our$git_version; 716sub evaluate_git_version { 717our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 718$number_of_git_cmds++; 719} 720 721sub check_loadavg { 722if(defined$maxload&& get_loadavg() >$maxload) { 723 die_error(503,"The load average on the server is too high"); 724} 725} 726 727# ====================================================================== 728# input validation and dispatch 729 730# input parameters can be collected from a variety of sources (presently, CGI 731# and PATH_INFO), so we define an %input_params hash that collects them all 732# together during validation: this allows subsequent uses (e.g. href()) to be 733# agnostic of the parameter origin 734 735our%input_params= (); 736 737# input parameters are stored with the long parameter name as key. This will 738# also be used in the href subroutine to convert parameters to their CGI 739# equivalent, and since the href() usage is the most frequent one, we store 740# the name -> CGI key mapping here, instead of the reverse. 741# 742# XXX: Warning: If you touch this, check the search form for updating, 743# too. 744 745our@cgi_param_mapping= ( 746 project =>"p", 747 action =>"a", 748 file_name =>"f", 749 file_parent =>"fp", 750 hash =>"h", 751 hash_parent =>"hp", 752 hash_base =>"hb", 753 hash_parent_base =>"hpb", 754 page =>"pg", 755 order =>"o", 756 searchtext =>"s", 757 searchtype =>"st", 758 snapshot_format =>"sf", 759 extra_options =>"opt", 760 search_use_regexp =>"sr", 761 ctag =>"by_tag", 762 diff_style =>"ds", 763 project_filter =>"pf", 764# this must be last entry (for manipulation from JavaScript) 765 javascript =>"js" 766); 767our%cgi_param_mapping=@cgi_param_mapping; 768 769# we will also need to know the possible actions, for validation 770our%actions= ( 771"blame"=> \&git_blame, 772"blame_incremental"=> \&git_blame_incremental, 773"blame_data"=> \&git_blame_data, 774"blobdiff"=> \&git_blobdiff, 775"blobdiff_plain"=> \&git_blobdiff_plain, 776"blob"=> \&git_blob, 777"blob_plain"=> \&git_blob_plain, 778"commitdiff"=> \&git_commitdiff, 779"commitdiff_plain"=> \&git_commitdiff_plain, 780"commit"=> \&git_commit, 781"forks"=> \&git_forks, 782"heads"=> \&git_heads, 783"history"=> \&git_history, 784"log"=> \&git_log, 785"patch"=> \&git_patch, 786"patches"=> \&git_patches, 787"remotes"=> \&git_remotes, 788"rss"=> \&git_rss, 789"atom"=> \&git_atom, 790"search"=> \&git_search, 791"search_help"=> \&git_search_help, 792"shortlog"=> \&git_shortlog, 793"summary"=> \&git_summary, 794"tag"=> \&git_tag, 795"tags"=> \&git_tags, 796"tree"=> \&git_tree, 797"snapshot"=> \&git_snapshot, 798"object"=> \&git_object, 799# those below don't need $project 800"opml"=> \&git_opml, 801"project_list"=> \&git_project_list, 802"project_index"=> \&git_project_index, 803); 804 805# finally, we have the hash of allowed extra_options for the commands that 806# allow them 807our%allowed_options= ( 808"--no-merges"=> [qw(rss atom log shortlog history)], 809); 810 811# fill %input_params with the CGI parameters. All values except for 'opt' 812# should be single values, but opt can be an array. We should probably 813# build an array of parameters that can be multi-valued, but since for the time 814# being it's only this one, we just single it out 815sub evaluate_query_params { 816our$cgi; 817 818while(my($name,$symbol) =each%cgi_param_mapping) { 819if($symboleq'opt') { 820$input_params{$name} = [map{ decode_utf8($_) }$cgi->param($symbol) ]; 821}else{ 822$input_params{$name} = decode_utf8($cgi->param($symbol)); 823} 824} 825} 826 827# now read PATH_INFO and update the parameter list for missing parameters 828sub evaluate_path_info { 829return ifdefined$input_params{'project'}; 830return if!$path_info; 831$path_info=~ s,^/+,,; 832return if!$path_info; 833 834# find which part of PATH_INFO is project 835my$project=$path_info; 836$project=~ s,/+$,,; 837while($project&& !check_head_link("$projectroot/$project")) { 838$project=~ s,/*[^/]*$,,; 839} 840return unless$project; 841$input_params{'project'} =$project; 842 843# do not change any parameters if an action is given using the query string 844return if$input_params{'action'}; 845$path_info=~ s,^\Q$project\E/*,,; 846 847# next, check if we have an action 848my$action=$path_info; 849$action=~ s,/.*$,,; 850if(exists$actions{$action}) { 851$path_info=~ s,^$action/*,,; 852$input_params{'action'} =$action; 853} 854 855# list of actions that want hash_base instead of hash, but can have no 856# pathname (f) parameter 857my@wants_base= ( 858'tree', 859'history', 860); 861 862# we want to catch, among others 863# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 864my($parentrefname,$parentpathname,$refname,$pathname) = 865($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?([^:]+?)?(?::(.+))?$/); 866 867# first, analyze the 'current' part 868if(defined$pathname) { 869# we got "branch:filename" or "branch:dir/" 870# we could use git_get_type(branch:pathname), but: 871# - it needs $git_dir 872# - it does a git() call 873# - the convention of terminating directories with a slash 874# makes it superfluous 875# - embedding the action in the PATH_INFO would make it even 876# more superfluous 877$pathname=~ s,^/+,,; 878if(!$pathname||substr($pathname, -1)eq"/") { 879$input_params{'action'} ||="tree"; 880$pathname=~ s,/$,,; 881}else{ 882# the default action depends on whether we had parent info 883# or not 884if($parentrefname) { 885$input_params{'action'} ||="blobdiff_plain"; 886}else{ 887$input_params{'action'} ||="blob_plain"; 888} 889} 890$input_params{'hash_base'} ||=$refname; 891$input_params{'file_name'} ||=$pathname; 892}elsif(defined$refname) { 893# we got "branch". In this case we have to choose if we have to 894# set hash or hash_base. 895# 896# Most of the actions without a pathname only want hash to be 897# set, except for the ones specified in @wants_base that want 898# hash_base instead. It should also be noted that hand-crafted 899# links having 'history' as an action and no pathname or hash 900# set will fail, but that happens regardless of PATH_INFO. 901if(defined$parentrefname) { 902# if there is parent let the default be 'shortlog' action 903# (for http://git.example.com/repo.git/A..B links); if there 904# is no parent, dispatch will detect type of object and set 905# action appropriately if required (if action is not set) 906$input_params{'action'} ||="shortlog"; 907} 908if($input_params{'action'} && 909grep{$_eq$input_params{'action'} }@wants_base) { 910$input_params{'hash_base'} ||=$refname; 911}else{ 912$input_params{'hash'} ||=$refname; 913} 914} 915 916# next, handle the 'parent' part, if present 917if(defined$parentrefname) { 918# a missing pathspec defaults to the 'current' filename, allowing e.g. 919# someproject/blobdiff/oldrev..newrev:/filename 920if($parentpathname) { 921$parentpathname=~ s,^/+,,; 922$parentpathname=~ s,/$,,; 923$input_params{'file_parent'} ||=$parentpathname; 924}else{ 925$input_params{'file_parent'} ||=$input_params{'file_name'}; 926} 927# we assume that hash_parent_base is wanted if a path was specified, 928# or if the action wants hash_base instead of hash 929if(defined$input_params{'file_parent'} || 930grep{$_eq$input_params{'action'} }@wants_base) { 931$input_params{'hash_parent_base'} ||=$parentrefname; 932}else{ 933$input_params{'hash_parent'} ||=$parentrefname; 934} 935} 936 937# for the snapshot action, we allow URLs in the form 938# $project/snapshot/$hash.ext 939# where .ext determines the snapshot and gets removed from the 940# passed $refname to provide the $hash. 941# 942# To be able to tell that $refname includes the format extension, we 943# require the following two conditions to be satisfied: 944# - the hash input parameter MUST have been set from the $refname part 945# of the URL (i.e. they must be equal) 946# - the snapshot format MUST NOT have been defined already (e.g. from 947# CGI parameter sf) 948# It's also useless to try any matching unless $refname has a dot, 949# so we check for that too 950if(defined$input_params{'action'} && 951$input_params{'action'}eq'snapshot'&& 952defined$refname&&index($refname,'.') != -1&& 953$refnameeq$input_params{'hash'} && 954!defined$input_params{'snapshot_format'}) { 955# We loop over the known snapshot formats, checking for 956# extensions. Allowed extensions are both the defined suffix 957# (which includes the initial dot already) and the snapshot 958# format key itself, with a prepended dot 959while(my($fmt,$opt) =each%known_snapshot_formats) { 960my$hash=$refname; 961unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 962next; 963} 964my$sfx=$1; 965# a valid suffix was found, so set the snapshot format 966# and reset the hash parameter 967$input_params{'snapshot_format'} =$fmt; 968$input_params{'hash'} =$hash; 969# we also set the format suffix to the one requested 970# in the URL: this way a request for e.g. .tgz returns 971# a .tgz instead of a .tar.gz 972$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 973last; 974} 975} 976} 977 978our($action,$project,$file_name,$file_parent,$hash,$hash_parent,$hash_base, 979$hash_parent_base,@extra_options,$page,$searchtype,$search_use_regexp, 980$searchtext,$search_regexp,$project_filter); 981sub evaluate_and_validate_params { 982our$action=$input_params{'action'}; 983if(defined$action) { 984if(!validate_action($action)) { 985 die_error(400,"Invalid action parameter"); 986} 987} 988 989# parameters which are pathnames 990our$project=$input_params{'project'}; 991if(defined$project) { 992if(!validate_project($project)) { 993undef$project; 994 die_error(404,"No such project"); 995} 996} 997 998our$project_filter=$input_params{'project_filter'}; 999if(defined$project_filter) {1000if(!validate_pathname($project_filter)) {1001 die_error(404,"Invalid project_filter parameter");1002}1003}10041005our$file_name=$input_params{'file_name'};1006if(defined$file_name) {1007if(!validate_pathname($file_name)) {1008 die_error(400,"Invalid file parameter");1009}1010}10111012our$file_parent=$input_params{'file_parent'};1013if(defined$file_parent) {1014if(!validate_pathname($file_parent)) {1015 die_error(400,"Invalid file parent parameter");1016}1017}10181019# parameters which are refnames1020our$hash=$input_params{'hash'};1021if(defined$hash) {1022if(!validate_refname($hash)) {1023 die_error(400,"Invalid hash parameter");1024}1025}10261027our$hash_parent=$input_params{'hash_parent'};1028if(defined$hash_parent) {1029if(!validate_refname($hash_parent)) {1030 die_error(400,"Invalid hash parent parameter");1031}1032}10331034our$hash_base=$input_params{'hash_base'};1035if(defined$hash_base) {1036if(!validate_refname($hash_base)) {1037 die_error(400,"Invalid hash base parameter");1038}1039}10401041our@extra_options= @{$input_params{'extra_options'}};1042# @extra_options is always defined, since it can only be (currently) set from1043# CGI, and $cgi->param() returns the empty array in array context if the param1044# is not set1045foreachmy$opt(@extra_options) {1046if(not exists$allowed_options{$opt}) {1047 die_error(400,"Invalid option parameter");1048}1049if(not grep(/^$action$/, @{$allowed_options{$opt}})) {1050 die_error(400,"Invalid option parameter for this action");1051}1052}10531054our$hash_parent_base=$input_params{'hash_parent_base'};1055if(defined$hash_parent_base) {1056if(!validate_refname($hash_parent_base)) {1057 die_error(400,"Invalid hash parent base parameter");1058}1059}10601061# other parameters1062our$page=$input_params{'page'};1063if(defined$page) {1064if($page=~m/[^0-9]/) {1065 die_error(400,"Invalid page parameter");1066}1067}10681069our$searchtype=$input_params{'searchtype'};1070if(defined$searchtype) {1071if($searchtype=~m/[^a-z]/) {1072 die_error(400,"Invalid searchtype parameter");1073}1074}10751076our$search_use_regexp=$input_params{'search_use_regexp'};10771078our$searchtext=$input_params{'searchtext'};1079our$search_regexp;1080if(defined$searchtext) {1081if(length($searchtext) <2) {1082 die_error(403,"At least two characters are required for search parameter");1083}1084$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext;1085}1086}10871088# path to the current git repository1089our$git_dir;1090sub evaluate_git_dir {1091our$git_dir="$projectroot/$project"if$project;1092}10931094our(@snapshot_fmts,$git_avatar);1095sub configure_gitweb_features {1096# list of supported snapshot formats1097our@snapshot_fmts= gitweb_get_feature('snapshot');1098@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts);10991100# check that the avatar feature is set to a known provider name,1101# and for each provider check if the dependencies are satisfied.1102# if the provider name is invalid or the dependencies are not met,1103# reset $git_avatar to the empty string.1104our($git_avatar) = gitweb_get_feature('avatar');1105if($git_avatareq'gravatar') {1106$git_avatar=''unless(eval{require Digest::MD5;1; });1107}elsif($git_avatareq'picon') {1108# no dependencies1109}else{1110$git_avatar='';1111}1112}11131114# custom error handler: 'die <message>' is Internal Server Error1115sub handle_errors_html {1116my$msg=shift;# it is already HTML escaped11171118# to avoid infinite loop where error occurs in die_error,1119# change handler to default handler, disabling handle_errors_html1120 set_message("Error occured when inside die_error:\n$msg");11211122# you cannot jump out of die_error when called as error handler;1123# the subroutine set via CGI::Carp::set_message is called _after_1124# HTTP headers are already written, so it cannot write them itself1125 die_error(undef,undef,$msg, -error_handler =>1, -no_http_header =>1);1126}1127set_message(\&handle_errors_html);11281129# dispatch1130sub dispatch {1131if(!defined$action) {1132if(defined$hash) {1133$action= git_get_type($hash);1134$actionor die_error(404,"Object does not exist");1135}elsif(defined$hash_base&&defined$file_name) {1136$action= git_get_type("$hash_base:$file_name");1137$actionor die_error(404,"File or directory does not exist");1138}elsif(defined$project) {1139$action='summary';1140}else{1141$action='project_list';1142}1143}1144if(!defined($actions{$action})) {1145 die_error(400,"Unknown action");1146}1147if($action!~m/^(?:opml|project_list|project_index)$/&&1148!$project) {1149 die_error(400,"Project needed");1150}1151$actions{$action}->();1152}11531154sub reset_timer {1155our$t0= [ gettimeofday() ]1156ifdefined$t0;1157our$number_of_git_cmds=0;1158}11591160our$first_request=1;1161sub run_request {1162 reset_timer();11631164 evaluate_uri();1165if($first_request) {1166 evaluate_gitweb_config();1167 evaluate_git_version();1168}1169if($per_request_config) {1170if(ref($per_request_config)eq'CODE') {1171$per_request_config->();1172}elsif(!$first_request) {1173 evaluate_gitweb_config();1174}1175}1176 check_loadavg();11771178# $projectroot and $projects_list might be set in gitweb config file1179$projects_list||=$projectroot;11801181 evaluate_query_params();1182 evaluate_path_info();1183 evaluate_and_validate_params();1184 evaluate_git_dir();11851186 configure_gitweb_features();11871188 dispatch();1189}11901191our$is_last_request=sub{1};1192our($pre_dispatch_hook,$post_dispatch_hook,$pre_listen_hook);1193our$CGI='CGI';1194our$cgi;1195sub configure_as_fcgi {1196require CGI::Fast;1197our$CGI='CGI::Fast';11981199my$request_number=0;1200# let each child service 100 requests1201our$is_last_request=sub{ ++$request_number>100};1202}1203sub evaluate_argv {1204my$script_name=$ENV{'SCRIPT_NAME'} ||$ENV{'SCRIPT_FILENAME'} || __FILE__;1205 configure_as_fcgi()1206if$script_name=~/\.fcgi$/;12071208return unless(@ARGV);12091210require Getopt::Long;1211 Getopt::Long::GetOptions(1212'fastcgi|fcgi|f'=> \&configure_as_fcgi,1213'nproc|n=i'=>sub{1214my($arg,$val) =@_;1215return unlesseval{require FCGI::ProcManager;1; };1216my$proc_manager= FCGI::ProcManager->new({1217 n_processes =>$val,1218});1219our$pre_listen_hook=sub{$proc_manager->pm_manage() };1220our$pre_dispatch_hook=sub{$proc_manager->pm_pre_dispatch() };1221our$post_dispatch_hook=sub{$proc_manager->pm_post_dispatch() };1222},1223);1224}12251226sub run {1227 evaluate_argv();12281229$first_request=1;1230$pre_listen_hook->()1231if$pre_listen_hook;12321233 REQUEST:1234while($cgi=$CGI->new()) {1235$pre_dispatch_hook->()1236if$pre_dispatch_hook;12371238 run_request();12391240$post_dispatch_hook->()1241if$post_dispatch_hook;1242$first_request=0;12431244last REQUEST if($is_last_request->());1245}12461247 DONE_GITWEB:12481;1249}12501251run();12521253if(defined caller) {1254# wrapped in a subroutine processing requests,1255# e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI1256return;1257}else{1258# pure CGI script, serving single request1259exit;1260}12611262## ======================================================================1263## action links12641265# possible values of extra options1266# -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)1267# -replay => 1 - start from a current view (replay with modifications)1268# -path_info => 0|1 - don't use/use path_info URL (if possible)1269# -anchor => ANCHOR - add #ANCHOR to end of URL, implies -replay if used alone1270sub href {1271my%params=@_;1272# default is to use -absolute url() i.e. $my_uri1273my$href=$params{-full} ?$my_url:$my_uri;12741275# implicit -replay, must be first of implicit params1276$params{-replay} =1if(keys%params==1&&$params{-anchor});12771278$params{'project'} =$projectunlessexists$params{'project'};12791280if($params{-replay}) {1281while(my($name,$symbol) =each%cgi_param_mapping) {1282if(!exists$params{$name}) {1283$params{$name} =$input_params{$name};1284}1285}1286}12871288my$use_pathinfo= gitweb_check_feature('pathinfo');1289if(defined$params{'project'} &&1290(exists$params{-path_info} ?$params{-path_info} :$use_pathinfo)) {1291# try to put as many parameters as possible in PATH_INFO:1292# - project name1293# - action1294# - hash_parent or hash_parent_base:/file_parent1295# - hash or hash_base:/filename1296# - the snapshot_format as an appropriate suffix12971298# When the script is the root DirectoryIndex for the domain,1299# $href here would be something like http://gitweb.example.com/1300# Thus, we strip any trailing / from $href, to spare us double1301# slashes in the final URL1302$href=~ s,/$,,;13031304# Then add the project name, if present1305$href.="/".esc_path_info($params{'project'});1306delete$params{'project'};13071308# since we destructively absorb parameters, we keep this1309# boolean that remembers if we're handling a snapshot1310my$is_snapshot=$params{'action'}eq'snapshot';13111312# Summary just uses the project path URL, any other action is1313# added to the URL1314if(defined$params{'action'}) {1315$href.="/".esc_path_info($params{'action'})1316unless$params{'action'}eq'summary';1317delete$params{'action'};1318}13191320# Next, we put hash_parent_base:/file_parent..hash_base:/file_name,1321# stripping nonexistent or useless pieces1322$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'}1323||$params{'hash_parent'} ||$params{'hash'});1324if(defined$params{'hash_base'}) {1325if(defined$params{'hash_parent_base'}) {1326$href.= esc_path_info($params{'hash_parent_base'});1327# skip the file_parent if it's the same as the file_name1328if(defined$params{'file_parent'}) {1329if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) {1330delete$params{'file_parent'};1331}elsif($params{'file_parent'} !~/\.\./) {1332$href.=":/".esc_path_info($params{'file_parent'});1333delete$params{'file_parent'};1334}1335}1336$href.="..";1337delete$params{'hash_parent'};1338delete$params{'hash_parent_base'};1339}elsif(defined$params{'hash_parent'}) {1340$href.= esc_path_info($params{'hash_parent'})."..";1341delete$params{'hash_parent'};1342}13431344$href.= esc_path_info($params{'hash_base'});1345if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) {1346$href.=":/".esc_path_info($params{'file_name'});1347delete$params{'file_name'};1348}1349delete$params{'hash'};1350delete$params{'hash_base'};1351}elsif(defined$params{'hash'}) {1352$href.= esc_path_info($params{'hash'});1353delete$params{'hash'};1354}13551356# If the action was a snapshot, we can absorb the1357# snapshot_format parameter too1358if($is_snapshot) {1359my$fmt=$params{'snapshot_format'};1360# snapshot_format should always be defined when href()1361# is called, but just in case some code forgets, we1362# fall back to the default1363$fmt||=$snapshot_fmts[0];1364$href.=$known_snapshot_formats{$fmt}{'suffix'};1365delete$params{'snapshot_format'};1366}1367}13681369# now encode the parameters explicitly1370my@result= ();1371for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1372my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1373if(defined$params{$name}) {1374if(ref($params{$name})eq"ARRAY") {1375foreachmy$par(@{$params{$name}}) {1376push@result,$symbol."=". esc_param($par);1377}1378}else{1379push@result,$symbol."=". esc_param($params{$name});1380}1381}1382}1383$href.="?".join(';',@result)ifscalar@result;13841385# final transformation: trailing spaces must be escaped (URI-encoded)1386$href=~s/(\s+)$/CGI::escape($1)/e;13871388if($params{-anchor}) {1389$href.="#".esc_param($params{-anchor});1390}13911392return$href;1393}139413951396## ======================================================================1397## validation, quoting/unquoting and escaping13981399sub validate_action {1400my$input=shift||returnundef;1401returnundefunlessexists$actions{$input};1402return$input;1403}14041405sub validate_project {1406my$input=shift||returnundef;1407if(!validate_pathname($input) ||1408!(-d "$projectroot/$input") ||1409!check_export_ok("$projectroot/$input") ||1410($strict_export&& !project_in_list($input))) {1411returnundef;1412}else{1413return$input;1414}1415}14161417sub validate_pathname {1418my$input=shift||returnundef;14191420# no '.' or '..' as elements of path, i.e. no '.' nor '..'1421# at the beginning, at the end, and between slashes.1422# also this catches doubled slashes1423if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1424returnundef;1425}1426# no null characters1427if($input=~m!\0!) {1428returnundef;1429}1430return$input;1431}14321433sub validate_refname {1434my$input=shift||returnundef;14351436# textual hashes are O.K.1437if($input=~m/^[0-9a-fA-F]{40}$/) {1438return$input;1439}1440# it must be correct pathname1441$input= validate_pathname($input)1442orreturnundef;1443# restrictions on ref name according to git-check-ref-format1444if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1445returnundef;1446}1447return$input;1448}14491450# decode sequences of octets in utf8 into Perl's internal form,1451# which is utf-8 with utf8 flag set if needed. gitweb writes out1452# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1453sub to_utf8 {1454my$str=shift;1455returnundefunlessdefined$str;14561457if(utf8::is_utf8($str) || utf8::decode($str)) {1458return$str;1459}else{1460return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1461}1462}14631464# quote unsafe chars, but keep the slash, even when it's not1465# correct, but quoted slashes look too horrible in bookmarks1466sub esc_param {1467my$str=shift;1468returnundefunlessdefined$str;1469$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1470$str=~s/ /\+/g;1471return$str;1472}14731474# the quoting rules for path_info fragment are slightly different1475sub esc_path_info {1476my$str=shift;1477returnundefunlessdefined$str;14781479# path_info doesn't treat '+' as space (specially), but '?' must be escaped1480$str=~s/([^A-Za-z0-9\-_.~();\/;:@&= +]+)/CGI::escape($1)/eg;14811482return$str;1483}14841485# quote unsafe chars in whole URL, so some characters cannot be quoted1486sub esc_url {1487my$str=shift;1488returnundefunlessdefined$str;1489$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg;1490$str=~s/ /\+/g;1491return$str;1492}14931494# quote unsafe characters in HTML attributes1495sub esc_attr {14961497# for XHTML conformance escaping '"' to '"' is not enough1498return esc_html(@_);1499}15001501# replace invalid utf8 character with SUBSTITUTION sequence1502sub esc_html {1503my$str=shift;1504my%opts=@_;15051506returnundefunlessdefined$str;15071508$str= to_utf8($str);1509$str=$cgi->escapeHTML($str);1510if($opts{'-nbsp'}) {1511$str=~s/ / /g;1512}1513$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1514return$str;1515}15161517# quote control characters and escape filename to HTML1518sub esc_path {1519my$str=shift;1520my%opts=@_;15211522returnundefunlessdefined$str;15231524$str= to_utf8($str);1525$str=$cgi->escapeHTML($str);1526if($opts{'-nbsp'}) {1527$str=~s/ / /g;1528}1529$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1530return$str;1531}15321533# Sanitize for use in XHTML + application/xml+xhtm (valid XML 1.0)1534sub sanitize {1535my$str=shift;15361537returnundefunlessdefined$str;15381539$str= to_utf8($str);1540$str=~ s|([[:cntrl:]])|($1=~/[\t\n\r]/?$1: quot_cec($1))|eg;1541return$str;1542}15431544# Make control characters "printable", using character escape codes (CEC)1545sub quot_cec {1546my$cntrl=shift;1547my%opts=@_;1548my%es= (# character escape codes, aka escape sequences1549"\t"=>'\t',# tab (HT)1550"\n"=>'\n',# line feed (LF)1551"\r"=>'\r',# carrige return (CR)1552"\f"=>'\f',# form feed (FF)1553"\b"=>'\b',# backspace (BS)1554"\a"=>'\a',# alarm (bell) (BEL)1555"\e"=>'\e',# escape (ESC)1556"\013"=>'\v',# vertical tab (VT)1557"\000"=>'\0',# nul character (NUL)1558);1559my$chr= ( (exists$es{$cntrl})1560?$es{$cntrl}1561:sprintf('\%2x',ord($cntrl)) );1562if($opts{-nohtml}) {1563return$chr;1564}else{1565return"<span class=\"cntrl\">$chr</span>";1566}1567}15681569# Alternatively use unicode control pictures codepoints,1570# Unicode "printable representation" (PR)1571sub quot_upr {1572my$cntrl=shift;1573my%opts=@_;15741575my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1576if($opts{-nohtml}) {1577return$chr;1578}else{1579return"<span class=\"cntrl\">$chr</span>";1580}1581}15821583# git may return quoted and escaped filenames1584sub unquote {1585my$str=shift;15861587sub unq {1588my$seq=shift;1589my%es= (# character escape codes, aka escape sequences1590't'=>"\t",# tab (HT, TAB)1591'n'=>"\n",# newline (NL)1592'r'=>"\r",# return (CR)1593'f'=>"\f",# form feed (FF)1594'b'=>"\b",# backspace (BS)1595'a'=>"\a",# alarm (bell) (BEL)1596'e'=>"\e",# escape (ESC)1597'v'=>"\013",# vertical tab (VT)1598);15991600if($seq=~m/^[0-7]{1,3}$/) {1601# octal char sequence1602returnchr(oct($seq));1603}elsif(exists$es{$seq}) {1604# C escape sequence, aka character escape code1605return$es{$seq};1606}1607# quoted ordinary character1608return$seq;1609}16101611if($str=~m/^"(.*)"$/) {1612# needs unquoting1613$str=$1;1614$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1615}1616return$str;1617}16181619# escape tabs (convert tabs to spaces)1620sub untabify {1621my$line=shift;16221623while((my$pos=index($line,"\t")) != -1) {1624if(my$count= (8- ($pos%8))) {1625my$spaces=' ' x $count;1626$line=~s/\t/$spaces/;1627}1628}16291630return$line;1631}16321633sub project_in_list {1634my$project=shift;1635my@list= git_get_projects_list();1636return@list&&scalar(grep{$_->{'path'}eq$project}@list);1637}16381639## ----------------------------------------------------------------------1640## HTML aware string manipulation16411642# Try to chop given string on a word boundary between position1643# $len and $len+$add_len. If there is no word boundary there,1644# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1645# (marking chopped part) would be longer than given string.1646sub chop_str {1647my$str=shift;1648my$len=shift;1649my$add_len=shift||10;1650my$where=shift||'right';# 'left' | 'center' | 'right'16511652# Make sure perl knows it is utf8 encoded so we don't1653# cut in the middle of a utf8 multibyte char.1654$str= to_utf8($str);16551656# allow only $len chars, but don't cut a word if it would fit in $add_len1657# if it doesn't fit, cut it if it's still longer than the dots we would add1658# remove chopped character entities entirely16591660# when chopping in the middle, distribute $len into left and right part1661# return early if chopping wouldn't make string shorter1662if($whereeq'center') {1663return$strif($len+5>=length($str));# filler is length 51664$len=int($len/2);1665}else{1666return$strif($len+4>=length($str));# filler is length 41667}16681669# regexps: ending and beginning with word part up to $add_len1670my$endre=qr/.{$len}\w{0,$add_len}/;1671my$begre=qr/\w{0,$add_len}.{$len}/;16721673if($whereeq'left') {1674$str=~m/^(.*?)($begre)$/;1675my($lead,$body) = ($1,$2);1676if(length($lead) >4) {1677$lead=" ...";1678}1679return"$lead$body";16801681}elsif($whereeq'center') {1682$str=~m/^($endre)(.*)$/;1683my($left,$str) = ($1,$2);1684$str=~m/^(.*?)($begre)$/;1685my($mid,$right) = ($1,$2);1686if(length($mid) >5) {1687$mid=" ... ";1688}1689return"$left$mid$right";16901691}else{1692$str=~m/^($endre)(.*)$/;1693my$body=$1;1694my$tail=$2;1695if(length($tail) >4) {1696$tail="... ";1697}1698return"$body$tail";1699}1700}17011702# takes the same arguments as chop_str, but also wraps a <span> around the1703# result with a title attribute if it does get chopped. Additionally, the1704# string is HTML-escaped.1705sub chop_and_escape_str {1706my($str) =@_;17071708my$chopped= chop_str(@_);1709$str= to_utf8($str);1710if($choppedeq$str) {1711return esc_html($chopped);1712}else{1713$str=~s/[[:cntrl:]]/?/g;1714return$cgi->span({-title=>$str}, esc_html($chopped));1715}1716}17171718# Highlight selected fragments of string, using given CSS class,1719# and escape HTML. It is assumed that fragments do not overlap.1720# Regions are passed as list of pairs (array references).1721#1722# Example: esc_html_hl_regions("foobar", "mark", [ 0, 3 ]) returns1723# '<span class="mark">foo</span>bar'1724sub esc_html_hl_regions {1725my($str,$css_class,@sel) =@_;1726return esc_html($str)unless@sel;17271728my$out='';1729my$pos=0;17301731formy$s(@sel) {1732$out.= esc_html(substr($str,$pos,$s->[0] -$pos))1733if($s->[0] -$pos>0);1734$out.=$cgi->span({-class=>$css_class},1735 esc_html(substr($str,$s->[0],$s->[1] -$s->[0])));17361737$pos=$s->[1];1738}1739$out.= esc_html(substr($str,$pos))1740if($pos<length($str));17411742return$out;1743}17441745# return positions of beginning and end of each match1746sub matchpos_list {1747my($str,$regexp) =@_;1748return unless(defined$str&&defined$regexp);17491750my@matches;1751while($str=~/$regexp/g) {1752push@matches, [$-[0],$+[0]];1753}1754return@matches;1755}17561757# highlight match (if any), and escape HTML1758sub esc_html_match_hl {1759my($str,$regexp) =@_;1760return esc_html($str)unlessdefined$regexp;17611762my@matches= matchpos_list($str,$regexp);1763return esc_html($str)unless@matches;17641765return esc_html_hl_regions($str,'match',@matches);1766}176717681769# highlight match (if any) of shortened string, and escape HTML1770sub esc_html_match_hl_chopped {1771my($str,$chopped,$regexp) =@_;1772return esc_html_match_hl($str,$regexp)unlessdefined$chopped;17731774my@matches= matchpos_list($str,$regexp);1775return esc_html($chopped)unless@matches;17761777# filter matches so that we mark chopped string1778my$tail="... ";# see chop_str1779unless($chopped=~s/\Q$tail\E$//) {1780$tail='';1781}1782my$chop_len=length($chopped);1783my$tail_len=length($tail);1784my@filtered;17851786formy$m(@matches) {1787if($m->[0] >$chop_len) {1788push@filtered, [$chop_len,$chop_len+$tail_len]if($tail_len>0);1789last;1790}elsif($m->[1] >$chop_len) {1791push@filtered, [$m->[0],$chop_len+$tail_len];1792last;1793}1794push@filtered,$m;1795}17961797return esc_html_hl_regions($chopped.$tail,'match',@filtered);1798}17991800## ----------------------------------------------------------------------1801## functions returning short strings18021803# CSS class for given age value (in seconds)1804sub age_class {1805my$age=shift;18061807if(!defined$age) {1808return"noage";1809}elsif($age<60*60*2) {1810return"age0";1811}elsif($age<60*60*24*2) {1812return"age1";1813}else{1814return"age2";1815}1816}18171818# convert age in seconds to "nn units ago" string1819sub age_string {1820my$age=shift;1821my$age_str;18221823if($age>60*60*24*365*2) {1824$age_str= (int$age/60/60/24/365);1825$age_str.=" years ago";1826}elsif($age>60*60*24*(365/12)*2) {1827$age_str=int$age/60/60/24/(365/12);1828$age_str.=" months ago";1829}elsif($age>60*60*24*7*2) {1830$age_str=int$age/60/60/24/7;1831$age_str.=" weeks ago";1832}elsif($age>60*60*24*2) {1833$age_str=int$age/60/60/24;1834$age_str.=" days ago";1835}elsif($age>60*60*2) {1836$age_str=int$age/60/60;1837$age_str.=" hours ago";1838}elsif($age>60*2) {1839$age_str=int$age/60;1840$age_str.=" min ago";1841}elsif($age>2) {1842$age_str=int$age;1843$age_str.=" sec ago";1844}else{1845$age_str.=" right now";1846}1847return$age_str;1848}18491850useconstant{1851 S_IFINVALID =>0030000,1852 S_IFGITLINK =>0160000,1853};18541855# submodule/subproject, a commit object reference1856sub S_ISGITLINK {1857my$mode=shift;18581859return(($mode& S_IFMT) == S_IFGITLINK)1860}18611862# convert file mode in octal to symbolic file mode string1863sub mode_str {1864my$mode=oct shift;18651866if(S_ISGITLINK($mode)) {1867return'm---------';1868}elsif(S_ISDIR($mode& S_IFMT)) {1869return'drwxr-xr-x';1870}elsif(S_ISLNK($mode)) {1871return'lrwxrwxrwx';1872}elsif(S_ISREG($mode)) {1873# git cares only about the executable bit1874if($mode& S_IXUSR) {1875return'-rwxr-xr-x';1876}else{1877return'-rw-r--r--';1878};1879}else{1880return'----------';1881}1882}18831884# convert file mode in octal to file type string1885sub file_type {1886my$mode=shift;18871888if($mode!~m/^[0-7]+$/) {1889return$mode;1890}else{1891$mode=oct$mode;1892}18931894if(S_ISGITLINK($mode)) {1895return"submodule";1896}elsif(S_ISDIR($mode& S_IFMT)) {1897return"directory";1898}elsif(S_ISLNK($mode)) {1899return"symlink";1900}elsif(S_ISREG($mode)) {1901return"file";1902}else{1903return"unknown";1904}1905}19061907# convert file mode in octal to file type description string1908sub file_type_long {1909my$mode=shift;19101911if($mode!~m/^[0-7]+$/) {1912return$mode;1913}else{1914$mode=oct$mode;1915}19161917if(S_ISGITLINK($mode)) {1918return"submodule";1919}elsif(S_ISDIR($mode& S_IFMT)) {1920return"directory";1921}elsif(S_ISLNK($mode)) {1922return"symlink";1923}elsif(S_ISREG($mode)) {1924if($mode& S_IXUSR) {1925return"executable";1926}else{1927return"file";1928};1929}else{1930return"unknown";1931}1932}193319341935## ----------------------------------------------------------------------1936## functions returning short HTML fragments, or transforming HTML fragments1937## which don't belong to other sections19381939# format line of commit message.1940sub format_log_line_html {1941my$line=shift;19421943$line= esc_html($line, -nbsp=>1);1944$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1945$cgi->a({-href => href(action=>"object", hash=>$1),1946-class=>"text"},$1);1947}eg;19481949return$line;1950}19511952# format marker of refs pointing to given object19531954# the destination action is chosen based on object type and current context:1955# - for annotated tags, we choose the tag view unless it's the current view1956# already, in which case we go to shortlog view1957# - for other refs, we keep the current view if we're in history, shortlog or1958# log view, and select shortlog otherwise1959sub format_ref_marker {1960my($refs,$id) =@_;1961my$markers='';19621963if(defined$refs->{$id}) {1964foreachmy$ref(@{$refs->{$id}}) {1965# this code exploits the fact that non-lightweight tags are the1966# only indirect objects, and that they are the only objects for which1967# we want to use tag instead of shortlog as action1968my($type,$name) =qw();1969my$indirect= ($ref=~s/\^\{\}$//);1970# e.g. tags/v2.6.11 or heads/next1971if($ref=~m!^(.*?)s?/(.*)$!) {1972$type=$1;1973$name=$2;1974}else{1975$type="ref";1976$name=$ref;1977}19781979my$class=$type;1980$class.=" indirect"if$indirect;19811982my$dest_action="shortlog";19831984if($indirect) {1985$dest_action="tag"unless$actioneq"tag";1986}elsif($action=~/^(history|(short)?log)$/) {1987$dest_action=$action;1988}19891990my$dest="";1991$dest.="refs/"unless$ref=~ m!^refs/!;1992$dest.=$ref;19931994my$link=$cgi->a({1995-href => href(1996 action=>$dest_action,1997 hash=>$dest1998)},$name);19992000$markers.=" <span class=\"".esc_attr($class)."\"title=\"".esc_attr($ref)."\">".2001$link."</span>";2002}2003}20042005if($markers) {2006return' <span class="refs">'.$markers.'</span>';2007}else{2008return"";2009}2010}20112012# format, perhaps shortened and with markers, title line2013sub format_subject_html {2014my($long,$short,$href,$extra) =@_;2015$extra=''unlessdefined($extra);20162017if(length($short) <length($long)) {2018$long=~s/[[:cntrl:]]/?/g;2019return$cgi->a({-href =>$href, -class=>"list subject",2020-title => to_utf8($long)},2021 esc_html($short)) .$extra;2022}else{2023return$cgi->a({-href =>$href, -class=>"list subject"},2024 esc_html($long)) .$extra;2025}2026}20272028# Rather than recomputing the url for an email multiple times, we cache it2029# after the first hit. This gives a visible benefit in views where the avatar2030# for the same email is used repeatedly (e.g. shortlog).2031# The cache is shared by all avatar engines (currently gravatar only), which2032# are free to use it as preferred. Since only one avatar engine is used for any2033# given page, there's no risk for cache conflicts.2034our%avatar_cache= ();20352036# Compute the picon url for a given email, by using the picon search service over at2037# http://www.cs.indiana.edu/picons/search.html2038sub picon_url {2039my$email=lc shift;2040if(!$avatar_cache{$email}) {2041my($user,$domain) =split('@',$email);2042$avatar_cache{$email} =2043"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".2044"$domain/$user/".2045"users+domains+unknown/up/single";2046}2047return$avatar_cache{$email};2048}20492050# Compute the gravatar url for a given email, if it's not in the cache already.2051# Gravatar stores only the part of the URL before the size, since that's the2052# one computationally more expensive. This also allows reuse of the cache for2053# different sizes (for this particular engine).2054sub gravatar_url {2055my$email=lc shift;2056my$size=shift;2057$avatar_cache{$email} ||=2058"http://www.gravatar.com/avatar/".2059 Digest::MD5::md5_hex($email) ."?s=";2060return$avatar_cache{$email} .$size;2061}20622063# Insert an avatar for the given $email at the given $size if the feature2064# is enabled.2065sub git_get_avatar {2066my($email,%opts) =@_;2067my$pre_white= ($opts{-pad_before} ?" ":"");2068my$post_white= ($opts{-pad_after} ?" ":"");2069$opts{-size} ||='default';2070my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};2071my$url="";2072if($git_avatareq'gravatar') {2073$url= gravatar_url($email,$size);2074}elsif($git_avatareq'picon') {2075$url= picon_url($email);2076}2077# Other providers can be added by extending the if chain, defining $url2078# as needed. If no variant puts something in $url, we assume avatars2079# are completely disabled/unavailable.2080if($url) {2081return$pre_white.2082"<img width=\"$size\"".2083"class=\"avatar\"".2084"src=\"".esc_url($url)."\"".2085"alt=\"\"".2086"/>".$post_white;2087}else{2088return"";2089}2090}20912092sub format_search_author {2093my($author,$searchtype,$displaytext) =@_;2094my$have_search= gitweb_check_feature('search');20952096if($have_search) {2097my$performed="";2098if($searchtypeeq'author') {2099$performed="authored";2100}elsif($searchtypeeq'committer') {2101$performed="committed";2102}21032104return$cgi->a({-href => href(action=>"search", hash=>$hash,2105 searchtext=>$author,2106 searchtype=>$searchtype),class=>"list",2107 title=>"Search for commits$performedby$author"},2108$displaytext);21092110}else{2111return$displaytext;2112}2113}21142115# format the author name of the given commit with the given tag2116# the author name is chopped and escaped according to the other2117# optional parameters (see chop_str).2118sub format_author_html {2119my$tag=shift;2120my$co=shift;2121my$author= chop_and_escape_str($co->{'author_name'},@_);2122return"<$tagclass=\"author\">".2123 format_search_author($co->{'author_name'},"author",2124 git_get_avatar($co->{'author_email'}, -pad_after =>1) .2125$author) .2126"</$tag>";2127}21282129# format git diff header line, i.e. "diff --(git|combined|cc) ..."2130sub format_git_diff_header_line {2131my$line=shift;2132my$diffinfo=shift;2133my($from,$to) =@_;21342135if($diffinfo->{'nparents'}) {2136# combined diff2137$line=~s!^(diff (.*?) )"?.*$!$1!;2138if($to->{'href'}) {2139$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},2140 esc_path($to->{'file'}));2141}else{# file was deleted (no href)2142$line.= esc_path($to->{'file'});2143}2144}else{2145# "ordinary" diff2146$line=~s!^(diff (.*?) )"?a/.*$!$1!;2147if($from->{'href'}) {2148$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},2149'a/'. esc_path($from->{'file'}));2150}else{# file was added (no href)2151$line.='a/'. esc_path($from->{'file'});2152}2153$line.=' ';2154if($to->{'href'}) {2155$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},2156'b/'. esc_path($to->{'file'}));2157}else{# file was deleted2158$line.='b/'. esc_path($to->{'file'});2159}2160}21612162return"<div class=\"diff header\">$line</div>\n";2163}21642165# format extended diff header line, before patch itself2166sub format_extended_diff_header_line {2167my$line=shift;2168my$diffinfo=shift;2169my($from,$to) =@_;21702171# match <path>2172if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {2173$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},2174 esc_path($from->{'file'}));2175}2176if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {2177$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},2178 esc_path($to->{'file'}));2179}2180# match single <mode>2181if($line=~m/\s(\d{6})$/) {2182$line.='<span class="info"> ('.2183 file_type_long($1) .2184')</span>';2185}2186# match <hash>2187if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {2188# can match only for combined diff2189$line='index ';2190for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2191if($from->{'href'}[$i]) {2192$line.=$cgi->a({-href=>$from->{'href'}[$i],2193-class=>"hash"},2194substr($diffinfo->{'from_id'}[$i],0,7));2195}else{2196$line.='0' x 7;2197}2198# separator2199$line.=','if($i<$diffinfo->{'nparents'} -1);2200}2201$line.='..';2202if($to->{'href'}) {2203$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2204substr($diffinfo->{'to_id'},0,7));2205}else{2206$line.='0' x 7;2207}22082209}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {2210# can match only for ordinary diff2211my($from_link,$to_link);2212if($from->{'href'}) {2213$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},2214substr($diffinfo->{'from_id'},0,7));2215}else{2216$from_link='0' x 7;2217}2218if($to->{'href'}) {2219$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2220substr($diffinfo->{'to_id'},0,7));2221}else{2222$to_link='0' x 7;2223}2224my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});2225$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;2226}22272228return$line."<br/>\n";2229}22302231# format from-file/to-file diff header2232sub format_diff_from_to_header {2233my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;2234my$line;2235my$result='';22362237$line=$from_line;2238#assert($line =~ m/^---/) if DEBUG;2239# no extra formatting for "^--- /dev/null"2240if(!$diffinfo->{'nparents'}) {2241# ordinary (single parent) diff2242if($line=~m!^--- "?a/!) {2243if($from->{'href'}) {2244$line='--- a/'.2245$cgi->a({-href=>$from->{'href'}, -class=>"path"},2246 esc_path($from->{'file'}));2247}else{2248$line='--- a/'.2249 esc_path($from->{'file'});2250}2251}2252$result.= qq!<div class="diff from_file">$line</div>\n!;22532254}else{2255# combined diff (merge commit)2256for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2257if($from->{'href'}[$i]) {2258$line='--- '.2259$cgi->a({-href=>href(action=>"blobdiff",2260 hash_parent=>$diffinfo->{'from_id'}[$i],2261 hash_parent_base=>$parents[$i],2262 file_parent=>$from->{'file'}[$i],2263 hash=>$diffinfo->{'to_id'},2264 hash_base=>$hash,2265 file_name=>$to->{'file'}),2266-class=>"path",2267-title=>"diff". ($i+1)},2268$i+1) .2269'/'.2270$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},2271 esc_path($from->{'file'}[$i]));2272}else{2273$line='--- /dev/null';2274}2275$result.= qq!<div class="diff from_file">$line</div>\n!;2276}2277}22782279$line=$to_line;2280#assert($line =~ m/^\+\+\+/) if DEBUG;2281# no extra formatting for "^+++ /dev/null"2282if($line=~m!^\+\+\+ "?b/!) {2283if($to->{'href'}) {2284$line='+++ b/'.2285$cgi->a({-href=>$to->{'href'}, -class=>"path"},2286 esc_path($to->{'file'}));2287}else{2288$line='+++ b/'.2289 esc_path($to->{'file'});2290}2291}2292$result.= qq!<div class="diff to_file">$line</div>\n!;22932294return$result;2295}22962297# create note for patch simplified by combined diff2298sub format_diff_cc_simplified {2299my($diffinfo,@parents) =@_;2300my$result='';23012302$result.="<div class=\"diff header\">".2303"diff --cc ";2304if(!is_deleted($diffinfo)) {2305$result.=$cgi->a({-href => href(action=>"blob",2306 hash_base=>$hash,2307 hash=>$diffinfo->{'to_id'},2308 file_name=>$diffinfo->{'to_file'}),2309-class=>"path"},2310 esc_path($diffinfo->{'to_file'}));2311}else{2312$result.= esc_path($diffinfo->{'to_file'});2313}2314$result.="</div>\n".# class="diff header"2315"<div class=\"diff nodifferences\">".2316"Simple merge".2317"</div>\n";# class="diff nodifferences"23182319return$result;2320}23212322sub diff_line_class {2323my($line,$from,$to) =@_;23242325# ordinary diff2326my$num_sign=1;2327# combined diff2328if($from&&$to&&ref($from->{'href'})eq"ARRAY") {2329$num_sign=scalar@{$from->{'href'}};2330}23312332my@diff_line_classifier= (2333{ regexp =>qr/^\@\@{$num_sign} /,class=>"chunk_header"},2334{ regexp =>qr/^\\/,class=>"incomplete"},2335{ regexp =>qr/^ {$num_sign}/,class=>"ctx"},2336# classifier for context must come before classifier add/rem,2337# or we would have to use more complicated regexp, for example2338# qr/(?= {0,$m}\+)[+ ]{$num_sign}/, where $m = $num_sign - 1;2339{ regexp =>qr/^[+ ]{$num_sign}/,class=>"add"},2340{ regexp =>qr/^[- ]{$num_sign}/,class=>"rem"},2341);2342formy$clsfy(@diff_line_classifier) {2343return$clsfy->{'class'}2344if($line=~$clsfy->{'regexp'});2345}23462347# fallback2348return"";2349}23502351# assumes that $from and $to are defined and correctly filled,2352# and that $line holds a line of chunk header for unified diff2353sub format_unidiff_chunk_header {2354my($line,$from,$to) =@_;23552356my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =2357$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;23582359$from_lines=0unlessdefined$from_lines;2360$to_lines=0unlessdefined$to_lines;23612362if($from->{'href'}) {2363$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",2364-class=>"list"},$from_text);2365}2366if($to->{'href'}) {2367$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",2368-class=>"list"},$to_text);2369}2370$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".2371"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2372return$line;2373}23742375# assumes that $from and $to are defined and correctly filled,2376# and that $line holds a line of chunk header for combined diff2377sub format_cc_diff_chunk_header {2378my($line,$from,$to) =@_;23792380my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;2381my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);23822383@from_text=split(' ',$ranges);2384for(my$i=0;$i<@from_text; ++$i) {2385($from_start[$i],$from_nlines[$i]) =2386(split(',',substr($from_text[$i],1)),0);2387}23882389$to_text=pop@from_text;2390$to_start=pop@from_start;2391$to_nlines=pop@from_nlines;23922393$line="<span class=\"chunk_info\">$prefix";2394for(my$i=0;$i<@from_text; ++$i) {2395if($from->{'href'}[$i]) {2396$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",2397-class=>"list"},$from_text[$i]);2398}else{2399$line.=$from_text[$i];2400}2401$line.=" ";2402}2403if($to->{'href'}) {2404$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",2405-class=>"list"},$to_text);2406}else{2407$line.=$to_text;2408}2409$line.="$prefix</span>".2410"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2411return$line;2412}24132414# process patch (diff) line (not to be used for diff headers),2415# returning class and HTML-formatted (but not wrapped) line2416sub process_diff_line {2417my$line=shift;2418my($from,$to) =@_;24192420my$diff_class= diff_line_class($line,$from,$to);24212422chomp$line;2423$line= untabify($line);24242425if($from&&$to&&$line=~m/^\@{2} /) {2426$line= format_unidiff_chunk_header($line,$from,$to);2427return$diff_class,$line;24282429}elsif($from&&$to&&$line=~m/^\@{3}/) {2430$line= format_cc_diff_chunk_header($line,$from,$to);2431return$diff_class,$line;24322433}2434return$diff_class, esc_html($line, -nbsp=>1);2435}24362437# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",2438# linked. Pass the hash of the tree/commit to snapshot.2439sub format_snapshot_links {2440my($hash) =@_;2441my$num_fmts=@snapshot_fmts;2442if($num_fmts>1) {2443# A parenthesized list of links bearing format names.2444# e.g. "snapshot (_tar.gz_ _zip_)"2445return"snapshot (".join(' ',map2446$cgi->a({2447-href => href(2448 action=>"snapshot",2449 hash=>$hash,2450 snapshot_format=>$_2451)2452},$known_snapshot_formats{$_}{'display'})2453,@snapshot_fmts) .")";2454}elsif($num_fmts==1) {2455# A single "snapshot" link whose tooltip bears the format name.2456# i.e. "_snapshot_"2457my($fmt) =@snapshot_fmts;2458return2459$cgi->a({2460-href => href(2461 action=>"snapshot",2462 hash=>$hash,2463 snapshot_format=>$fmt2464),2465-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"2466},"snapshot");2467}else{# $num_fmts == 02468returnundef;2469}2470}24712472## ......................................................................2473## functions returning values to be passed, perhaps after some2474## transformation, to other functions; e.g. returning arguments to href()24752476# returns hash to be passed to href to generate gitweb URL2477# in -title key it returns description of link2478sub get_feed_info {2479my$format=shift||'Atom';2480my%res= (action =>lc($format));24812482# feed links are possible only for project views2483return unless(defined$project);2484# some views should link to OPML, or to generic project feed,2485# or don't have specific feed yet (so they should use generic)2486return if(!$action||$action=~/^(?:tags|heads|forks|tag|search)$/x);24872488my$branch;2489# branches refs uses 'refs/heads/' prefix (fullname) to differentiate2490# from tag links; this also makes possible to detect branch links2491if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||2492(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {2493$branch=$1;2494}2495# find log type for feed description (title)2496my$type='log';2497if(defined$file_name) {2498$type="history of$file_name";2499$type.="/"if($actioneq'tree');2500$type.=" on '$branch'"if(defined$branch);2501}else{2502$type="log of$branch"if(defined$branch);2503}25042505$res{-title} =$type;2506$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);2507$res{'file_name'} =$file_name;25082509return%res;2510}25112512## ----------------------------------------------------------------------2513## git utility subroutines, invoking git commands25142515# returns path to the core git executable and the --git-dir parameter as list2516sub git_cmd {2517$number_of_git_cmds++;2518return$GIT,'--git-dir='.$git_dir;2519}25202521# quote the given arguments for passing them to the shell2522# quote_command("command", "arg 1", "arg with ' and ! characters")2523# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2524# Try to avoid using this function wherever possible.2525sub quote_command {2526returnjoin(' ',2527map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2528}25292530# get HEAD ref of given project as hash2531sub git_get_head_hash {2532return git_get_full_hash(shift,'HEAD');2533}25342535sub git_get_full_hash {2536return git_get_hash(@_);2537}25382539sub git_get_short_hash {2540return git_get_hash(@_,'--short=7');2541}25422543sub git_get_hash {2544my($project,$hash,@options) =@_;2545my$o_git_dir=$git_dir;2546my$retval=undef;2547$git_dir="$projectroot/$project";2548if(open my$fd,'-|', git_cmd(),'rev-parse',2549'--verify','-q',@options,$hash) {2550$retval= <$fd>;2551chomp$retvalifdefined$retval;2552close$fd;2553}2554if(defined$o_git_dir) {2555$git_dir=$o_git_dir;2556}2557return$retval;2558}25592560# get type of given object2561sub git_get_type {2562my$hash=shift;25632564open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2565my$type= <$fd>;2566close$fdorreturn;2567chomp$type;2568return$type;2569}25702571# repository configuration2572our$config_file='';2573our%config;25742575# store multiple values for single key as anonymous array reference2576# single values stored directly in the hash, not as [ <value> ]2577sub hash_set_multi {2578my($hash,$key,$value) =@_;25792580if(!exists$hash->{$key}) {2581$hash->{$key} =$value;2582}elsif(!ref$hash->{$key}) {2583$hash->{$key} = [$hash->{$key},$value];2584}else{2585push@{$hash->{$key}},$value;2586}2587}25882589# return hash of git project configuration2590# optionally limited to some section, e.g. 'gitweb'2591sub git_parse_project_config {2592my$section_regexp=shift;2593my%config;25942595local$/="\0";25962597open my$fh,"-|", git_cmd(),"config",'-z','-l',2598orreturn;25992600while(my$keyval= <$fh>) {2601chomp$keyval;2602my($key,$value) =split(/\n/,$keyval,2);26032604 hash_set_multi(\%config,$key,$value)2605if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2606}2607close$fh;26082609return%config;2610}26112612# convert config value to boolean: 'true' or 'false'2613# no value, number > 0, 'true' and 'yes' values are true2614# rest of values are treated as false (never as error)2615sub config_to_bool {2616my$val=shift;26172618return1if!defined$val;# section.key26192620# strip leading and trailing whitespace2621$val=~s/^\s+//;2622$val=~s/\s+$//;26232624return(($val=~/^\d+$/&&$val) ||# section.key = 12625($val=~/^(?:true|yes)$/i));# section.key = true2626}26272628# convert config value to simple decimal number2629# an optional value suffix of 'k', 'm', or 'g' will cause the value2630# to be multiplied by 1024, 1048576, or 10737418242631sub config_to_int {2632my$val=shift;26332634# strip leading and trailing whitespace2635$val=~s/^\s+//;2636$val=~s/\s+$//;26372638if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2639$unit=lc($unit);2640# unknown unit is treated as 12641return$num* ($uniteq'g'?1073741824:2642$uniteq'm'?1048576:2643$uniteq'k'?1024:1);2644}2645return$val;2646}26472648# convert config value to array reference, if needed2649sub config_to_multi {2650my$val=shift;26512652returnref($val) ?$val: (defined($val) ? [$val] : []);2653}26542655sub git_get_project_config {2656my($key,$type) =@_;26572658return unlessdefined$git_dir;26592660# key sanity check2661return unless($key);2662# only subsection, if exists, is case sensitive,2663# and not lowercased by 'git config -z -l'2664if(my($hi,$mi,$lo) = ($key=~/^([^.]*)\.(.*)\.([^.]*)$/)) {2665$key=join(".",lc($hi),$mi,lc($lo));2666}else{2667$key=lc($key);2668}2669$key=~s/^gitweb\.//;2670return if($key=~m/\W/);26712672# type sanity check2673if(defined$type) {2674$type=~s/^--//;2675$type=undef2676unless($typeeq'bool'||$typeeq'int');2677}26782679# get config2680if(!defined$config_file||2681$config_filene"$git_dir/config") {2682%config= git_parse_project_config('gitweb');2683$config_file="$git_dir/config";2684}26852686# check if config variable (key) exists2687return unlessexists$config{"gitweb.$key"};26882689# ensure given type2690if(!defined$type) {2691return$config{"gitweb.$key"};2692}elsif($typeeq'bool') {2693# backward compatibility: 'git config --bool' returns true/false2694return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2695}elsif($typeeq'int') {2696return config_to_int($config{"gitweb.$key"});2697}2698return$config{"gitweb.$key"};2699}27002701# get hash of given path at given ref2702sub git_get_hash_by_path {2703my$base=shift;2704my$path=shift||returnundef;2705my$type=shift;27062707$path=~ s,/+$,,;27082709open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2710or die_error(500,"Open git-ls-tree failed");2711my$line= <$fd>;2712close$fdorreturnundef;27132714if(!defined$line) {2715# there is no tree or hash given by $path at $base2716returnundef;2717}27182719#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2720$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2721if(defined$type&&$typene$2) {2722# type doesn't match2723returnundef;2724}2725return$3;2726}27272728# get path of entry with given hash at given tree-ish (ref)2729# used to get 'from' filename for combined diff (merge commit) for renames2730sub git_get_path_by_hash {2731my$base=shift||return;2732my$hash=shift||return;27332734local$/="\0";27352736open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2737orreturnundef;2738while(my$line= <$fd>) {2739chomp$line;27402741#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2742#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2743if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2744close$fd;2745return$1;2746}2747}2748close$fd;2749returnundef;2750}27512752## ......................................................................2753## git utility functions, directly accessing git repository27542755# get the value of config variable either from file named as the variable2756# itself in the repository ($GIT_DIR/$name file), or from gitweb.$name2757# configuration variable in the repository config file.2758sub git_get_file_or_project_config {2759my($path,$name) =@_;27602761$git_dir="$projectroot/$path";2762open my$fd,'<',"$git_dir/$name"2763orreturn git_get_project_config($name);2764my$conf= <$fd>;2765close$fd;2766if(defined$conf) {2767chomp$conf;2768}2769return$conf;2770}27712772sub git_get_project_description {2773my$path=shift;2774return git_get_file_or_project_config($path,'description');2775}27762777sub git_get_project_category {2778my$path=shift;2779return git_get_file_or_project_config($path,'category');2780}278127822783# supported formats:2784# * $GIT_DIR/ctags/<tagname> file (in 'ctags' subdirectory)2785# - if its contents is a number, use it as tag weight,2786# - otherwise add a tag with weight 12787# * $GIT_DIR/ctags file, each line is a tag (with weight 1)2788# the same value multiple times increases tag weight2789# * `gitweb.ctag' multi-valued repo config variable2790sub git_get_project_ctags {2791my$project=shift;2792my$ctags= {};27932794$git_dir="$projectroot/$project";2795if(opendir my$dh,"$git_dir/ctags") {2796my@files=grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh);2797foreachmy$tagfile(@files) {2798open my$ct,'<',$tagfile2799ornext;2800my$val= <$ct>;2801chomp$valif$val;2802close$ct;28032804(my$ctag=$tagfile) =~ s#.*/##;2805if($val=~/^\d+$/) {2806$ctags->{$ctag} =$val;2807}else{2808$ctags->{$ctag} =1;2809}2810}2811closedir$dh;28122813}elsif(open my$fh,'<',"$git_dir/ctags") {2814while(my$line= <$fh>) {2815chomp$line;2816$ctags->{$line}++if$line;2817}2818close$fh;28192820}else{2821my$taglist= config_to_multi(git_get_project_config('ctag'));2822foreachmy$tag(@$taglist) {2823$ctags->{$tag}++;2824}2825}28262827return$ctags;2828}28292830# return hash, where keys are content tags ('ctags'),2831# and values are sum of weights of given tag in every project2832sub git_gather_all_ctags {2833my$projects=shift;2834my$ctags= {};28352836foreachmy$p(@$projects) {2837foreachmy$ct(keys%{$p->{'ctags'}}) {2838$ctags->{$ct} +=$p->{'ctags'}->{$ct};2839}2840}28412842return$ctags;2843}28442845sub git_populate_project_tagcloud {2846my$ctags=shift;28472848# First, merge different-cased tags; tags vote on casing2849my%ctags_lc;2850foreach(keys%$ctags) {2851$ctags_lc{lc$_}->{count} +=$ctags->{$_};2852if(not$ctags_lc{lc$_}->{topcount}2853or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2854$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2855$ctags_lc{lc$_}->{topname} =$_;2856}2857}28582859my$cloud;2860my$matched=$input_params{'ctag'};2861if(eval{require HTML::TagCloud;1; }) {2862$cloud= HTML::TagCloud->new;2863foreachmy$ctag(sort keys%ctags_lc) {2864# Pad the title with spaces so that the cloud looks2865# less crammed.2866my$title= esc_html($ctags_lc{$ctag}->{topname});2867$title=~s/ / /g;2868$title=~s/^/ /g;2869$title=~s/$/ /g;2870if(defined$matched&&$matchedeq$ctag) {2871$title=qq(<span class="match">$title</span>);2872}2873$cloud->add($title, href(project=>undef, ctag=>$ctag),2874$ctags_lc{$ctag}->{count});2875}2876}else{2877$cloud= {};2878foreachmy$ctag(keys%ctags_lc) {2879my$title= esc_html($ctags_lc{$ctag}->{topname}, -nbsp=>1);2880if(defined$matched&&$matchedeq$ctag) {2881$title=qq(<span class="match">$title</span>);2882}2883$cloud->{$ctag}{count} =$ctags_lc{$ctag}->{count};2884$cloud->{$ctag}{ctag} =2885$cgi->a({-href=>href(project=>undef, ctag=>$ctag)},$title);2886}2887}2888return$cloud;2889}28902891sub git_show_project_tagcloud {2892my($cloud,$count) =@_;2893if(ref$cloudeq'HTML::TagCloud') {2894return$cloud->html_and_css($count);2895}else{2896my@tags=sort{$cloud->{$a}->{'count'} <=>$cloud->{$b}->{'count'} }keys%$cloud;2897return2898'<div id="htmltagcloud"'.($project?'':' align="center"').'>'.2899join(', ',map{2900$cloud->{$_}->{'ctag'}2901}splice(@tags,0,$count)) .2902'</div>';2903}2904}29052906sub git_get_project_url_list {2907my$path=shift;29082909$git_dir="$projectroot/$path";2910open my$fd,'<',"$git_dir/cloneurl"2911orreturnwantarray?2912@{ config_to_multi(git_get_project_config('url')) } :2913 config_to_multi(git_get_project_config('url'));2914my@git_project_url_list=map{chomp;$_} <$fd>;2915close$fd;29162917returnwantarray?@git_project_url_list: \@git_project_url_list;2918}29192920sub git_get_projects_list {2921my$filter=shift||'';2922my$paranoid=shift;2923my@list;29242925if(-d $projects_list) {2926# search in directory2927my$dir=$projects_list;2928# remove the trailing "/"2929$dir=~s!/+$!!;2930my$pfxlen=length("$dir");2931my$pfxdepth= ($dir=~tr!/!!);2932# when filtering, search only given subdirectory2933if($filter&& !$paranoid) {2934$dir.="/$filter";2935$dir=~s!/+$!!;2936}29372938 File::Find::find({2939 follow_fast =>1,# follow symbolic links2940 follow_skip =>2,# ignore duplicates2941 dangling_symlinks =>0,# ignore dangling symlinks, silently2942 wanted =>sub{2943# global variables2944our$project_maxdepth;2945our$projectroot;2946# skip project-list toplevel, if we get it.2947return if(m!^[/.]$!);2948# only directories can be git repositories2949return unless(-d $_);2950# don't traverse too deep (Find is super slow on os x)2951# $project_maxdepth excludes depth of $projectroot2952if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2953$File::Find::prune =1;2954return;2955}29562957my$path=substr($File::Find::name,$pfxlen+1);2958# paranoidly only filter here2959if($paranoid&&$filter&&$path!~m!^\Q$filter\E/!) {2960next;2961}2962# we check related file in $projectroot2963if(check_export_ok("$projectroot/$path")) {2964push@list, { path =>$path};2965$File::Find::prune =1;2966}2967},2968},"$dir");29692970}elsif(-f $projects_list) {2971# read from file(url-encoded):2972# 'git%2Fgit.git Linus+Torvalds'2973# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2974# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2975open my$fd,'<',$projects_listorreturn;2976 PROJECT:2977while(my$line= <$fd>) {2978chomp$line;2979my($path,$owner) =split' ',$line;2980$path= unescape($path);2981$owner= unescape($owner);2982if(!defined$path) {2983next;2984}2985# if $filter is rpovided, check if $path begins with $filter2986if($filter&&$path!~m!^\Q$filter\E/!) {2987next;2988}2989if(check_export_ok("$projectroot/$path")) {2990my$pr= {2991 path =>$path,2992 owner => to_utf8($owner),2993};2994push@list,$pr;2995}2996}2997close$fd;2998}2999return@list;3000}30013002# written with help of Tree::Trie module (Perl Artistic License, GPL compatibile)3003# as side effects it sets 'forks' field to list of forks for forked projects3004sub filter_forks_from_projects_list {3005my$projects=shift;30063007my%trie;# prefix tree of directories (path components)3008# generate trie out of those directories that might contain forks3009foreachmy$pr(@$projects) {3010my$path=$pr->{'path'};3011$path=~s/\.git$//;# forks of 'repo.git' are in 'repo/' directory3012next if($path=~m!/$!);# skip non-bare repositories, e.g. 'repo/.git'3013next unless($path);# skip '.git' repository: tests, git-instaweb3014next unless(-d "$projectroot/$path");# containing directory exists3015$pr->{'forks'} = [];# there can be 0 or more forks of project30163017# add to trie3018my@dirs=split('/',$path);3019# walk the trie, until either runs out of components or out of trie3020my$ref= \%trie;3021while(scalar@dirs&&3022exists($ref->{$dirs[0]})) {3023$ref=$ref->{shift@dirs};3024}3025# create rest of trie structure from rest of components3026foreachmy$dir(@dirs) {3027$ref=$ref->{$dir} = {};3028}3029# create end marker, store $pr as a data3030$ref->{''} =$prif(!exists$ref->{''});3031}30323033# filter out forks, by finding shortest prefix match for paths3034my@filtered;3035 PROJECT:3036foreachmy$pr(@$projects) {3037# trie lookup3038my$ref= \%trie;3039 DIR:3040foreachmy$dir(split('/',$pr->{'path'})) {3041if(exists$ref->{''}) {3042# found [shortest] prefix, is a fork - skip it3043push@{$ref->{''}{'forks'}},$pr;3044next PROJECT;3045}3046if(!exists$ref->{$dir}) {3047# not in trie, cannot have prefix, not a fork3048push@filtered,$pr;3049next PROJECT;3050}3051# If the dir is there, we just walk one step down the trie.3052$ref=$ref->{$dir};3053}3054# we ran out of trie3055# (shouldn't happen: it's either no match, or end marker)3056push@filtered,$pr;3057}30583059return@filtered;3060}30613062# note: fill_project_list_info must be run first,3063# for 'descr_long' and 'ctags' to be filled3064sub search_projects_list {3065my($projlist,%opts) =@_;3066my$tagfilter=$opts{'tagfilter'};3067my$searchtext=$opts{'searchtext'};30683069return@$projlist3070unless($tagfilter||$searchtext);30713072# searching projects require filling to be run before it;3073 fill_project_list_info($projlist,3074$tagfilter?'ctags': (),3075$searchtext? ('path','descr') : ());3076my@projects;3077 PROJECT:3078foreachmy$pr(@$projlist) {30793080if($tagfilter) {3081next unlessref($pr->{'ctags'})eq'HASH';3082next unless3083grep{lc($_)eq lc($tagfilter) }keys%{$pr->{'ctags'}};3084}30853086if($searchtext) {3087next unless3088$pr->{'path'} =~/$searchtext/||3089$pr->{'descr_long'} =~/$searchtext/;3090}30913092push@projects,$pr;3093}30943095return@projects;3096}30973098our$gitweb_project_owner=undef;3099sub git_get_project_list_from_file {31003101return if(defined$gitweb_project_owner);31023103$gitweb_project_owner= {};3104# read from file (url-encoded):3105# 'git%2Fgit.git Linus+Torvalds'3106# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'3107# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'3108if(-f $projects_list) {3109open(my$fd,'<',$projects_list);3110while(my$line= <$fd>) {3111chomp$line;3112my($pr,$ow) =split' ',$line;3113$pr= unescape($pr);3114$ow= unescape($ow);3115$gitweb_project_owner->{$pr} = to_utf8($ow);3116}3117close$fd;3118}3119}31203121sub git_get_project_owner {3122my$project=shift;3123my$owner;31243125returnundefunless$project;3126$git_dir="$projectroot/$project";31273128if(!defined$gitweb_project_owner) {3129 git_get_project_list_from_file();3130}31313132if(exists$gitweb_project_owner->{$project}) {3133$owner=$gitweb_project_owner->{$project};3134}3135if(!defined$owner){3136$owner= git_get_project_config('owner');3137}3138if(!defined$owner) {3139$owner= get_file_owner("$git_dir");3140}31413142return$owner;3143}31443145sub git_get_last_activity {3146my($path) =@_;3147my$fd;31483149$git_dir="$projectroot/$path";3150open($fd,"-|", git_cmd(),'for-each-ref',3151'--format=%(committer)',3152'--sort=-committerdate',3153'--count=1',3154'refs/heads')orreturn;3155my$most_recent= <$fd>;3156close$fdorreturn;3157if(defined$most_recent&&3158$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {3159my$timestamp=$1;3160my$age=time-$timestamp;3161return($age, age_string($age));3162}3163return(undef,undef);3164}31653166# Implementation note: when a single remote is wanted, we cannot use 'git3167# remote show -n' because that command always work (assuming it's a remote URL3168# if it's not defined), and we cannot use 'git remote show' because that would3169# try to make a network roundtrip. So the only way to find if that particular3170# remote is defined is to walk the list provided by 'git remote -v' and stop if3171# and when we find what we want.3172sub git_get_remotes_list {3173my$wanted=shift;3174my%remotes= ();31753176open my$fd,'-|', git_cmd(),'remote','-v';3177return unless$fd;3178while(my$remote= <$fd>) {3179chomp$remote;3180$remote=~s!\t(.*?)\s+\((\w+)\)$!!;3181next if$wantedand not$remoteeq$wanted;3182my($url,$key) = ($1,$2);31833184$remotes{$remote} ||= {'heads'=> () };3185$remotes{$remote}{$key} =$url;3186}3187close$fdorreturn;3188returnwantarray?%remotes: \%remotes;3189}31903191# Takes a hash of remotes as first parameter and fills it by adding the3192# available remote heads for each of the indicated remotes.3193sub fill_remote_heads {3194my$remotes=shift;3195my@heads=map{"remotes/$_"}keys%$remotes;3196my@remoteheads= git_get_heads_list(undef,@heads);3197foreachmy$remote(keys%$remotes) {3198$remotes->{$remote}{'heads'} = [grep{3199$_->{'name'} =~s!^$remote/!!3200}@remoteheads];3201}3202}32033204sub git_get_references {3205my$type=shift||"";3206my%refs;3207# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.113208# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}3209open my$fd,"-|", git_cmd(),"show-ref","--dereference",3210($type? ("--","refs/$type") : ())# use -- <pattern> if $type3211orreturn;32123213while(my$line= <$fd>) {3214chomp$line;3215if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {3216if(defined$refs{$1}) {3217push@{$refs{$1}},$2;3218}else{3219$refs{$1} = [$2];3220}3221}3222}3223close$fdorreturn;3224return \%refs;3225}32263227sub git_get_rev_name_tags {3228my$hash=shift||returnundef;32293230open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash3231orreturn;3232my$name_rev= <$fd>;3233close$fd;32343235if($name_rev=~ m|^$hash tags/(.*)$|) {3236return$1;3237}else{3238# catches also '$hash undefined' output3239returnundef;3240}3241}32423243## ----------------------------------------------------------------------3244## parse to hash functions32453246sub parse_date {3247my$epoch=shift;3248my$tz=shift||"-0000";32493250my%date;3251my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");3252my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");3253my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);3254$date{'hour'} =$hour;3255$date{'minute'} =$min;3256$date{'mday'} =$mday;3257$date{'day'} =$days[$wday];3258$date{'month'} =$months[$mon];3259$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",3260$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;3261$date{'mday-time'} =sprintf"%d%s%02d:%02d",3262$mday,$months[$mon],$hour,$min;3263$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",32641900+$year,1+$mon,$mday,$hour,$min,$sec;32653266my($tz_sign,$tz_hour,$tz_min) =3267($tz=~m/^([-+])(\d\d)(\d\d)$/);3268$tz_sign= ($tz_signeq'-'? -1: +1);3269my$local=$epoch+$tz_sign*((($tz_hour*60) +$tz_min)*60);3270($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);3271$date{'hour_local'} =$hour;3272$date{'minute_local'} =$min;3273$date{'tz_local'} =$tz;3274$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",32751900+$year,$mon+1,$mday,3276$hour,$min,$sec,$tz);3277return%date;3278}32793280sub parse_tag {3281my$tag_id=shift;3282my%tag;3283my@comment;32843285open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;3286$tag{'id'} =$tag_id;3287while(my$line= <$fd>) {3288chomp$line;3289if($line=~m/^object ([0-9a-fA-F]{40})$/) {3290$tag{'object'} =$1;3291}elsif($line=~m/^type (.+)$/) {3292$tag{'type'} =$1;3293}elsif($line=~m/^tag (.+)$/) {3294$tag{'name'} =$1;3295}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {3296$tag{'author'} =$1;3297$tag{'author_epoch'} =$2;3298$tag{'author_tz'} =$3;3299if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {3300$tag{'author_name'} =$1;3301$tag{'author_email'} =$2;3302}else{3303$tag{'author_name'} =$tag{'author'};3304}3305}elsif($line=~m/--BEGIN/) {3306push@comment,$line;3307last;3308}elsif($lineeq"") {3309last;3310}3311}3312push@comment, <$fd>;3313$tag{'comment'} = \@comment;3314close$fdorreturn;3315if(!defined$tag{'name'}) {3316return3317};3318return%tag3319}33203321sub parse_commit_text {3322my($commit_text,$withparents) =@_;3323my@commit_lines=split'\n',$commit_text;3324my%co;33253326pop@commit_lines;# Remove '\0'33273328if(!@commit_lines) {3329return;3330}33313332my$header=shift@commit_lines;3333if($header!~m/^[0-9a-fA-F]{40}/) {3334return;3335}3336($co{'id'},my@parents) =split' ',$header;3337while(my$line=shift@commit_lines) {3338last if$lineeq"\n";3339if($line=~m/^tree ([0-9a-fA-F]{40})$/) {3340$co{'tree'} =$1;3341}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {3342push@parents,$1;3343}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {3344$co{'author'} = to_utf8($1);3345$co{'author_epoch'} =$2;3346$co{'author_tz'} =$3;3347if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {3348$co{'author_name'} =$1;3349$co{'author_email'} =$2;3350}else{3351$co{'author_name'} =$co{'author'};3352}3353}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {3354$co{'committer'} = to_utf8($1);3355$co{'committer_epoch'} =$2;3356$co{'committer_tz'} =$3;3357if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {3358$co{'committer_name'} =$1;3359$co{'committer_email'} =$2;3360}else{3361$co{'committer_name'} =$co{'committer'};3362}3363}3364}3365if(!defined$co{'tree'}) {3366return;3367};3368$co{'parents'} = \@parents;3369$co{'parent'} =$parents[0];33703371foreachmy$title(@commit_lines) {3372$title=~s/^ //;3373if($titlene"") {3374$co{'title'} = chop_str($title,80,5);3375# remove leading stuff of merges to make the interesting part visible3376if(length($title) >50) {3377$title=~s/^Automatic //;3378$title=~s/^merge (of|with) /Merge ... /i;3379if(length($title) >50) {3380$title=~s/(http|rsync):\/\///;3381}3382if(length($title) >50) {3383$title=~s/(master|www|rsync)\.//;3384}3385if(length($title) >50) {3386$title=~s/kernel.org:?//;3387}3388if(length($title) >50) {3389$title=~s/\/pub\/scm//;3390}3391}3392$co{'title_short'} = chop_str($title,50,5);3393last;3394}3395}3396if(!defined$co{'title'} ||$co{'title'}eq"") {3397$co{'title'} =$co{'title_short'} ='(no commit message)';3398}3399# remove added spaces3400foreachmy$line(@commit_lines) {3401$line=~s/^ //;3402}3403$co{'comment'} = \@commit_lines;34043405my$age=time-$co{'committer_epoch'};3406$co{'age'} =$age;3407$co{'age_string'} = age_string($age);3408my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});3409if($age>60*60*24*7*2) {3410$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;3411$co{'age_string_age'} =$co{'age_string'};3412}else{3413$co{'age_string_date'} =$co{'age_string'};3414$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;3415}3416return%co;3417}34183419sub parse_commit {3420my($commit_id) =@_;3421my%co;34223423local$/="\0";34243425open my$fd,"-|", git_cmd(),"rev-list",3426"--parents",3427"--header",3428"--max-count=1",3429$commit_id,3430"--",3431or die_error(500,"Open git-rev-list failed");3432%co= parse_commit_text(<$fd>,1);3433close$fd;34343435return%co;3436}34373438sub parse_commits {3439my($commit_id,$maxcount,$skip,$filename,@args) =@_;3440my@cos;34413442$maxcount||=1;3443$skip||=0;34443445local$/="\0";34463447open my$fd,"-|", git_cmd(),"rev-list",3448"--header",3449@args,3450("--max-count=".$maxcount),3451("--skip=".$skip),3452@extra_options,3453$commit_id,3454"--",3455($filename? ($filename) : ())3456or die_error(500,"Open git-rev-list failed");3457while(my$line= <$fd>) {3458my%co= parse_commit_text($line);3459push@cos, \%co;3460}3461close$fd;34623463returnwantarray?@cos: \@cos;3464}34653466# parse line of git-diff-tree "raw" output3467sub parse_difftree_raw_line {3468my$line=shift;3469my%res;34703471# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'3472# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'3473if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {3474$res{'from_mode'} =$1;3475$res{'to_mode'} =$2;3476$res{'from_id'} =$3;3477$res{'to_id'} =$4;3478$res{'status'} =$5;3479$res{'similarity'} =$6;3480if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied3481($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);3482}else{3483$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);3484}3485}3486# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'3487# combined diff (for merge commit)3488elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {3489$res{'nparents'} =length($1);3490$res{'from_mode'} = [split(' ',$2) ];3491$res{'to_mode'} =pop@{$res{'from_mode'}};3492$res{'from_id'} = [split(' ',$3) ];3493$res{'to_id'} =pop@{$res{'from_id'}};3494$res{'status'} = [split('',$4) ];3495$res{'to_file'} = unquote($5);3496}3497# 'c512b523472485aef4fff9e57b229d9d243c967f'3498elsif($line=~m/^([0-9a-fA-F]{40})$/) {3499$res{'commit'} =$1;3500}35013502returnwantarray?%res: \%res;3503}35043505# wrapper: return parsed line of git-diff-tree "raw" output3506# (the argument might be raw line, or parsed info)3507sub parsed_difftree_line {3508my$line_or_ref=shift;35093510if(ref($line_or_ref)eq"HASH") {3511# pre-parsed (or generated by hand)3512return$line_or_ref;3513}else{3514return parse_difftree_raw_line($line_or_ref);3515}3516}35173518# parse line of git-ls-tree output3519sub parse_ls_tree_line {3520my$line=shift;3521my%opts=@_;3522my%res;35233524if($opts{'-l'}) {3525#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'3526$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;35273528$res{'mode'} =$1;3529$res{'type'} =$2;3530$res{'hash'} =$3;3531$res{'size'} =$4;3532if($opts{'-z'}) {3533$res{'name'} =$5;3534}else{3535$res{'name'} = unquote($5);3536}3537}else{3538#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'3539$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;35403541$res{'mode'} =$1;3542$res{'type'} =$2;3543$res{'hash'} =$3;3544if($opts{'-z'}) {3545$res{'name'} =$4;3546}else{3547$res{'name'} = unquote($4);3548}3549}35503551returnwantarray?%res: \%res;3552}35533554# generates _two_ hashes, references to which are passed as 2 and 3 argument3555sub parse_from_to_diffinfo {3556my($diffinfo,$from,$to,@parents) =@_;35573558if($diffinfo->{'nparents'}) {3559# combined diff3560$from->{'file'} = [];3561$from->{'href'} = [];3562 fill_from_file_info($diffinfo,@parents)3563unlessexists$diffinfo->{'from_file'};3564for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {3565$from->{'file'}[$i] =3566defined$diffinfo->{'from_file'}[$i] ?3567$diffinfo->{'from_file'}[$i] :3568$diffinfo->{'to_file'};3569if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file3570$from->{'href'}[$i] = href(action=>"blob",3571 hash_base=>$parents[$i],3572 hash=>$diffinfo->{'from_id'}[$i],3573 file_name=>$from->{'file'}[$i]);3574}else{3575$from->{'href'}[$i] =undef;3576}3577}3578}else{3579# ordinary (not combined) diff3580$from->{'file'} =$diffinfo->{'from_file'};3581if($diffinfo->{'status'}ne"A") {# not new (added) file3582$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,3583 hash=>$diffinfo->{'from_id'},3584 file_name=>$from->{'file'});3585}else{3586delete$from->{'href'};3587}3588}35893590$to->{'file'} =$diffinfo->{'to_file'};3591if(!is_deleted($diffinfo)) {# file exists in result3592$to->{'href'} = href(action=>"blob", hash_base=>$hash,3593 hash=>$diffinfo->{'to_id'},3594 file_name=>$to->{'file'});3595}else{3596delete$to->{'href'};3597}3598}35993600## ......................................................................3601## parse to array of hashes functions36023603sub git_get_heads_list {3604my($limit,@classes) =@_;3605@classes= ('heads')unless@classes;3606my@patterns=map{"refs/$_"}@classes;3607my@headslist;36083609open my$fd,'-|', git_cmd(),'for-each-ref',3610($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',3611'--format=%(objectname) %(refname) %(subject)%00%(committer)',3612@patterns3613orreturn;3614while(my$line= <$fd>) {3615my%ref_item;36163617chomp$line;3618my($refinfo,$committerinfo) =split(/\0/,$line);3619my($hash,$name,$title) =split(' ',$refinfo,3);3620my($committer,$epoch,$tz) =3621($committerinfo=~/^(.*) ([0-9]+) (.*)$/);3622$ref_item{'fullname'} =$name;3623$name=~s!^refs/(?:head|remote)s/!!;36243625$ref_item{'name'} =$name;3626$ref_item{'id'} =$hash;3627$ref_item{'title'} =$title||'(no commit message)';3628$ref_item{'epoch'} =$epoch;3629if($epoch) {3630$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3631}else{3632$ref_item{'age'} ="unknown";3633}36343635push@headslist, \%ref_item;3636}3637close$fd;36383639returnwantarray?@headslist: \@headslist;3640}36413642sub git_get_tags_list {3643my$limit=shift;3644my@tagslist;36453646open my$fd,'-|', git_cmd(),'for-each-ref',3647($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',3648'--format=%(objectname) %(objecttype) %(refname) '.3649'%(*objectname) %(*objecttype) %(subject)%00%(creator)',3650'refs/tags'3651orreturn;3652while(my$line= <$fd>) {3653my%ref_item;36543655chomp$line;3656my($refinfo,$creatorinfo) =split(/\0/,$line);3657my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);3658my($creator,$epoch,$tz) =3659($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);3660$ref_item{'fullname'} =$name;3661$name=~s!^refs/tags/!!;36623663$ref_item{'type'} =$type;3664$ref_item{'id'} =$id;3665$ref_item{'name'} =$name;3666if($typeeq"tag") {3667$ref_item{'subject'} =$title;3668$ref_item{'reftype'} =$reftype;3669$ref_item{'refid'} =$refid;3670}else{3671$ref_item{'reftype'} =$type;3672$ref_item{'refid'} =$id;3673}36743675if($typeeq"tag"||$typeeq"commit") {3676$ref_item{'epoch'} =$epoch;3677if($epoch) {3678$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3679}else{3680$ref_item{'age'} ="unknown";3681}3682}36833684push@tagslist, \%ref_item;3685}3686close$fd;36873688returnwantarray?@tagslist: \@tagslist;3689}36903691## ----------------------------------------------------------------------3692## filesystem-related functions36933694sub get_file_owner {3695my$path=shift;36963697my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);3698my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);3699if(!defined$gcos) {3700returnundef;3701}3702my$owner=$gcos;3703$owner=~s/[,;].*$//;3704return to_utf8($owner);3705}37063707# assume that file exists3708sub insert_file {3709my$filename=shift;37103711open my$fd,'<',$filename;3712print map{ to_utf8($_) } <$fd>;3713close$fd;3714}37153716## ......................................................................3717## mimetype related functions37183719sub mimetype_guess_file {3720my$filename=shift;3721my$mimemap=shift;3722-r $mimemaporreturnundef;37233724my%mimemap;3725open(my$mh,'<',$mimemap)orreturnundef;3726while(<$mh>) {3727next ifm/^#/;# skip comments3728my($mimetype,@exts) =split(/\s+/);3729foreachmy$ext(@exts) {3730$mimemap{$ext} =$mimetype;3731}3732}3733close($mh);37343735$filename=~/\.([^.]*)$/;3736return$mimemap{$1};3737}37383739sub mimetype_guess {3740my$filename=shift;3741my$mime;3742$filename=~/\./orreturnundef;37433744if($mimetypes_file) {3745my$file=$mimetypes_file;3746if($file!~m!^/!) {# if it is relative path3747# it is relative to project3748$file="$projectroot/$project/$file";3749}3750$mime= mimetype_guess_file($filename,$file);3751}3752$mime||= mimetype_guess_file($filename,'/etc/mime.types');3753return$mime;3754}37553756sub blob_mimetype {3757my$fd=shift;3758my$filename=shift;37593760if($filename) {3761my$mime= mimetype_guess($filename);3762$mimeandreturn$mime;3763}37643765# just in case3766return$default_blob_plain_mimetypeunless$fd;37673768if(-T $fd) {3769return'text/plain';3770}elsif(!$filename) {3771return'application/octet-stream';3772}elsif($filename=~m/\.png$/i) {3773return'image/png';3774}elsif($filename=~m/\.gif$/i) {3775return'image/gif';3776}elsif($filename=~m/\.jpe?g$/i) {3777return'image/jpeg';3778}else{3779return'application/octet-stream';3780}3781}37823783sub blob_contenttype {3784my($fd,$file_name,$type) =@_;37853786$type||= blob_mimetype($fd,$file_name);3787if($typeeq'text/plain'&&defined$default_text_plain_charset) {3788$type.="; charset=$default_text_plain_charset";3789}37903791return$type;3792}37933794# guess file syntax for syntax highlighting; return undef if no highlighting3795# the name of syntax can (in the future) depend on syntax highlighter used3796sub guess_file_syntax {3797my($highlight,$mimetype,$file_name) =@_;3798returnundefunless($highlight&&defined$file_name);3799my$basename= basename($file_name,'.in');3800return$highlight_basename{$basename}3801ifexists$highlight_basename{$basename};38023803$basename=~/\.([^.]*)$/;3804my$ext=$1orreturnundef;3805return$highlight_ext{$ext}3806ifexists$highlight_ext{$ext};38073808returnundef;3809}38103811# run highlighter and return FD of its output,3812# or return original FD if no highlighting3813sub run_highlighter {3814my($fd,$highlight,$syntax) =@_;3815return$fdunless($highlight&&defined$syntax);38163817close$fd;3818open$fd, quote_command(git_cmd(),"cat-file","blob",$hash)." | ".3819 quote_command($highlight_bin).3820" --replace-tabs=8 --fragment --syntax$syntax|"3821or die_error(500,"Couldn't open file or run syntax highlighter");3822return$fd;3823}38243825## ======================================================================3826## functions printing HTML: header, footer, error page38273828sub get_page_title {3829my$title= to_utf8($site_name);38303831unless(defined$project) {3832if(defined$project_filter) {3833$title.=" - projects in '". esc_path($project_filter) ."'";3834}3835return$title;3836}3837$title.=" - ". to_utf8($project);38383839return$titleunless(defined$action);3840$title.="/$action";# $action is US-ASCII (7bit ASCII)38413842return$titleunless(defined$file_name);3843$title.=" - ". esc_path($file_name);3844if($actioneq"tree"&&$file_name!~ m|/$|) {3845$title.="/";3846}38473848return$title;3849}38503851sub get_content_type_html {3852# require explicit support from the UA if we are to send the page as3853# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3854# we have to do this because MSIE sometimes globs '*/*', pretending to3855# support xhtml+xml but choking when it gets what it asked for.3856if(defined$cgi->http('HTTP_ACCEPT') &&3857$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3858$cgi->Accept('application/xhtml+xml') !=0) {3859return'application/xhtml+xml';3860}else{3861return'text/html';3862}3863}38643865sub print_feed_meta {3866if(defined$project) {3867my%href_params= get_feed_info();3868if(!exists$href_params{'-title'}) {3869$href_params{'-title'} ='log';3870}38713872foreachmy$format(qw(RSS Atom)) {3873my$type=lc($format);3874my%link_attr= (3875'-rel'=>'alternate',3876'-title'=> esc_attr("$project-$href_params{'-title'} -$formatfeed"),3877'-type'=>"application/$type+xml"3878);38793880$href_params{'action'} =$type;3881$link_attr{'-href'} = href(%href_params);3882print"<link ".3883"rel=\"$link_attr{'-rel'}\"".3884"title=\"$link_attr{'-title'}\"".3885"href=\"$link_attr{'-href'}\"".3886"type=\"$link_attr{'-type'}\"".3887"/>\n";38883889$href_params{'extra_options'} ='--no-merges';3890$link_attr{'-href'} = href(%href_params);3891$link_attr{'-title'} .=' (no merges)';3892print"<link ".3893"rel=\"$link_attr{'-rel'}\"".3894"title=\"$link_attr{'-title'}\"".3895"href=\"$link_attr{'-href'}\"".3896"type=\"$link_attr{'-type'}\"".3897"/>\n";3898}38993900}else{3901printf('<link rel="alternate" title="%sprojects list" '.3902'href="%s" type="text/plain; charset=utf-8" />'."\n",3903 esc_attr($site_name), href(project=>undef, action=>"project_index"));3904printf('<link rel="alternate" title="%sprojects feeds" '.3905'href="%s" type="text/x-opml" />'."\n",3906 esc_attr($site_name), href(project=>undef, action=>"opml"));3907}3908}39093910sub print_header_links {3911my$status=shift;39123913# print out each stylesheet that exist, providing backwards capability3914# for those people who defined $stylesheet in a config file3915if(defined$stylesheet) {3916print'<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";3917}else{3918foreachmy$stylesheet(@stylesheets) {3919next unless$stylesheet;3920print'<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";3921}3922}3923 print_feed_meta()3924if($statuseq'200 OK');3925if(defined$favicon) {3926printqq(<link rel="shortcut icon" href=").esc_url($favicon).qq(" type="image/png" />\n);3927}3928}39293930sub print_nav_breadcrumbs_path {3931my$dirprefix=undef;3932while(my$part=shift) {3933$dirprefix.="/"ifdefined$dirprefix;3934$dirprefix.=$part;3935print$cgi->a({-href => href(project =>undef,3936 project_filter =>$dirprefix,3937 action =>"project_list")},3938 esc_html($part)) ." / ";3939}3940}39413942sub print_nav_breadcrumbs {3943my%opts=@_;39443945print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3946if(defined$project) {3947my@dirname=split'/',$project;3948my$projectbasename=pop@dirname;3949 print_nav_breadcrumbs_path(@dirname);3950print$cgi->a({-href => href(action=>"summary")}, esc_html($projectbasename));3951if(defined$action) {3952my$action_print=$action;3953if(defined$opts{-action_extra}) {3954$action_print=$cgi->a({-href => href(action=>$action)},3955$action);3956}3957print" /$action_print";3958}3959if(defined$opts{-action_extra}) {3960print" /$opts{-action_extra}";3961}3962print"\n";3963}elsif(defined$project_filter) {3964 print_nav_breadcrumbs_path(split'/',$project_filter);3965}3966}39673968sub print_search_form {3969if(!defined$searchtext) {3970$searchtext="";3971}3972my$search_hash;3973if(defined$hash_base) {3974$search_hash=$hash_base;3975}elsif(defined$hash) {3976$search_hash=$hash;3977}else{3978$search_hash="HEAD";3979}3980my$action=$my_uri;3981my$use_pathinfo= gitweb_check_feature('pathinfo');3982if($use_pathinfo) {3983$action.="/".esc_url($project);3984}3985print$cgi->startform(-method=>"get", -action =>$action) .3986"<div class=\"search\">\n".3987(!$use_pathinfo&&3988$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3989$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3990$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3991$cgi->popup_menu(-name =>'st', -default=>'commit',3992-values=> ['commit','grep','author','committer','pickaxe']) .3993$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3994" search:\n",3995$cgi->textfield(-name =>"s", -value =>$searchtext, -override =>1) ."\n".3996"<span title=\"Extended regular expression\">".3997$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3998-checked =>$search_use_regexp) .3999"</span>".4000"</div>".4001$cgi->end_form() ."\n";4002}40034004sub git_header_html {4005my$status=shift||"200 OK";4006my$expires=shift;4007my%opts=@_;40084009my$title= get_page_title();4010my$content_type= get_content_type_html();4011print$cgi->header(-type=>$content_type, -charset =>'utf-8',4012-status=>$status, -expires =>$expires)4013unless($opts{'-no_http_header'});4014my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';4015print<<EOF;4016<?xml version="1.0" encoding="utf-8"?>4017<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">4018<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">4019<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->4020<!-- git core binaries version$git_version-->4021<head>4022<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>4023<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>4024<meta name="robots" content="index, nofollow"/>4025<title>$title</title>4026EOF4027# the stylesheet, favicon etc urls won't work correctly with path_info4028# unless we set the appropriate base URL4029if($ENV{'PATH_INFO'}) {4030print"<base href=\"".esc_url($base_url)."\"/>\n";4031}4032 print_header_links($status);40334034if(defined$site_html_head_string) {4035print to_utf8($site_html_head_string);4036}40374038print"</head>\n".4039"<body>\n";40404041if(defined$site_header&& -f $site_header) {4042 insert_file($site_header);4043}40444045print"<div class=\"page_header\">\n";4046if(defined$logo) {4047print$cgi->a({-href => esc_url($logo_url),4048-title =>$logo_label},4049$cgi->img({-src => esc_url($logo),4050-width =>72, -height =>27,4051-alt =>"git",4052-class=>"logo"}));4053}4054 print_nav_breadcrumbs(%opts);4055print"</div>\n";40564057my$have_search= gitweb_check_feature('search');4058if(defined$project&&$have_search) {4059 print_search_form();4060}4061}40624063sub git_footer_html {4064my$feed_class='rss_logo';40654066print"<div class=\"page_footer\">\n";4067if(defined$project) {4068my$descr= git_get_project_description($project);4069if(defined$descr) {4070print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";4071}40724073my%href_params= get_feed_info();4074if(!%href_params) {4075$feed_class.=' generic';4076}4077$href_params{'-title'} ||='log';40784079foreachmy$format(qw(RSS Atom)) {4080$href_params{'action'} =lc($format);4081print$cgi->a({-href => href(%href_params),4082-title =>"$href_params{'-title'}$formatfeed",4083-class=>$feed_class},$format)."\n";4084}40854086}else{4087print$cgi->a({-href => href(project=>undef, action=>"opml",4088 project_filter =>$project_filter),4089-class=>$feed_class},"OPML") ." ";4090print$cgi->a({-href => href(project=>undef, action=>"project_index",4091 project_filter =>$project_filter),4092-class=>$feed_class},"TXT") ."\n";4093}4094print"</div>\n";# class="page_footer"40954096if(defined$t0&& gitweb_check_feature('timed')) {4097print"<div id=\"generating_info\">\n";4098print'This page took '.4099'<span id="generating_time" class="time_span">'.4100 tv_interval($t0, [ gettimeofday() ]).4101' seconds </span>'.4102' and '.4103'<span id="generating_cmd">'.4104$number_of_git_cmds.4105'</span> git commands '.4106" to generate.\n";4107print"</div>\n";# class="page_footer"4108}41094110if(defined$site_footer&& -f $site_footer) {4111 insert_file($site_footer);4112}41134114print qq!<script type="text/javascript" src="!.esc_url($javascript).qq!"></script>\n!;4115if(defined$action&&4116$actioneq'blame_incremental') {4117print qq!<script type="text/javascript">\n!.4118 qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.4119 qq!"!. href() .qq!");\n!.4120 qq!</script>\n!;4121}else{4122my($jstimezone,$tz_cookie,$datetime_class) =4123 gitweb_get_feature('javascript-timezone');41244125print qq!<script type="text/javascript">\n!.4126 qq!window.onload = function () {\n!;4127if(gitweb_check_feature('javascript-actions')) {4128print qq! fixLinks();\n!;4129}4130if($jstimezone&&$tz_cookie&&$datetime_class) {4131print qq! var tz_cookie = { name:'$tz_cookie', expires:14, path:'/'};\n!.# in days4132 qq! onloadTZSetup('$jstimezone', tz_cookie,'$datetime_class');\n!;4133}4134print qq!};\n!.4135 qq!</script>\n!;4136}41374138print"</body>\n".4139"</html>";4140}41414142# die_error(<http_status_code>, <error_message>[, <detailed_html_description>])4143# Example: die_error(404, 'Hash not found')4144# By convention, use the following status codes (as defined in RFC 2616):4145# 400: Invalid or missing CGI parameters, or4146# requested object exists but has wrong type.4147# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on4148# this server or project.4149# 404: Requested object/revision/project doesn't exist.4150# 500: The server isn't configured properly, or4151# an internal error occurred (e.g. failed assertions caused by bugs), or4152# an unknown error occurred (e.g. the git binary died unexpectedly).4153# 503: The server is currently unavailable (because it is overloaded,4154# or down for maintenance). Generally, this is a temporary state.4155sub die_error {4156my$status=shift||500;4157my$error= esc_html(shift) ||"Internal Server Error";4158my$extra=shift;4159my%opts=@_;41604161my%http_responses= (4162400=>'400 Bad Request',4163403=>'403 Forbidden',4164404=>'404 Not Found',4165500=>'500 Internal Server Error',4166503=>'503 Service Unavailable',4167);4168 git_header_html($http_responses{$status},undef,%opts);4169print<<EOF;4170<div class="page_body">4171<br /><br />4172$status-$error4173<br />4174EOF4175if(defined$extra) {4176print"<hr />\n".4177"$extra\n";4178}4179print"</div>\n";41804181 git_footer_html();4182goto DONE_GITWEB4183unless($opts{'-error_handler'});4184}41854186## ----------------------------------------------------------------------4187## functions printing or outputting HTML: navigation41884189sub git_print_page_nav {4190my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;4191$extra=''if!defined$extra;# pager or formats41924193my@navs=qw(summary shortlog log commit commitdiff tree);4194if($suppress) {4195@navs=grep{$_ne$suppress}@navs;4196}41974198my%arg=map{$_=> {action=>$_} }@navs;4199if(defined$head) {4200for(qw(commit commitdiff)) {4201$arg{$_}{'hash'} =$head;4202}4203if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {4204for(qw(shortlog log)) {4205$arg{$_}{'hash'} =$head;4206}4207}4208}42094210$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;4211$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;42124213my@actions= gitweb_get_feature('actions');4214my%repl= (4215'%'=>'%',4216'n'=>$project,# project name4217'f'=>$git_dir,# project path within filesystem4218'h'=>$treehead||'',# current hash ('h' parameter)4219'b'=>$treebase||'',# hash base ('hb' parameter)4220);4221while(@actions) {4222my($label,$link,$pos) =splice(@actions,0,3);4223# insert4224@navs=map{$_eq$pos? ($_,$label) :$_}@navs;4225# munch munch4226$link=~s/%([%nfhb])/$repl{$1}/g;4227$arg{$label}{'_href'} =$link;4228}42294230print"<div class=\"page_nav\">\n".4231(join" | ",4232map{$_eq$current?4233$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")4234}@navs);4235print"<br/>\n$extra<br/>\n".4236"</div>\n";4237}42384239# returns a submenu for the nagivation of the refs views (tags, heads,4240# remotes) with the current view disabled and the remotes view only4241# available if the feature is enabled4242sub format_ref_views {4243my($current) =@_;4244my@ref_views=qw{tags heads};4245push@ref_views,'remotes'if gitweb_check_feature('remote_heads');4246returnjoin" | ",map{4247$_eq$current?$_:4248$cgi->a({-href => href(action=>$_)},$_)4249}@ref_views4250}42514252sub format_paging_nav {4253my($action,$page,$has_next_link) =@_;4254my$paging_nav;425542564257if($page>0) {4258$paging_nav.=4259$cgi->a({-href => href(-replay=>1, page=>undef)},"first") .4260" ⋅ ".4261$cgi->a({-href => href(-replay=>1, page=>$page-1),4262-accesskey =>"p", -title =>"Alt-p"},"prev");4263}else{4264$paging_nav.="first ⋅ prev";4265}42664267if($has_next_link) {4268$paging_nav.=" ⋅ ".4269$cgi->a({-href => href(-replay=>1, page=>$page+1),4270-accesskey =>"n", -title =>"Alt-n"},"next");4271}else{4272$paging_nav.=" ⋅ next";4273}42744275return$paging_nav;4276}42774278## ......................................................................4279## functions printing or outputting HTML: div42804281sub git_print_header_div {4282my($action,$title,$hash,$hash_base) =@_;4283my%args= ();42844285$args{'action'} =$action;4286$args{'hash'} =$hashif$hash;4287$args{'hash_base'} =$hash_baseif$hash_base;42884289print"<div class=\"header\">\n".4290$cgi->a({-href => href(%args), -class=>"title"},4291$title?$title:$action) .4292"\n</div>\n";4293}42944295sub format_repo_url {4296my($name,$url) =@_;4297return"<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";4298}42994300# Group output by placing it in a DIV element and adding a header.4301# Options for start_div() can be provided by passing a hash reference as the4302# first parameter to the function.4303# Options to git_print_header_div() can be provided by passing an array4304# reference. This must follow the options to start_div if they are present.4305# The content can be a scalar, which is output as-is, a scalar reference, which4306# is output after html escaping, an IO handle passed either as *handle or4307# *handle{IO}, or a function reference. In the latter case all following4308# parameters will be taken as argument to the content function call.4309sub git_print_section {4310my($div_args,$header_args,$content);4311my$arg=shift;4312if(ref($arg)eq'HASH') {4313$div_args=$arg;4314$arg=shift;4315}4316if(ref($arg)eq'ARRAY') {4317$header_args=$arg;4318$arg=shift;4319}4320$content=$arg;43214322print$cgi->start_div($div_args);4323 git_print_header_div(@$header_args);43244325if(ref($content)eq'CODE') {4326$content->(@_);4327}elsif(ref($content)eq'SCALAR') {4328print esc_html($$content);4329}elsif(ref($content)eq'GLOB'or ref($content)eq'IO::Handle') {4330print<$content>;4331}elsif(!ref($content) &&defined($content)) {4332print$content;4333}43344335print$cgi->end_div;4336}43374338sub format_timestamp_html {4339my$date=shift;4340my$strtime=$date->{'rfc2822'};43414342my(undef,undef,$datetime_class) =4343 gitweb_get_feature('javascript-timezone');4344if($datetime_class) {4345$strtime= qq!<span class="$datetime_class">$strtime</span>!;4346}43474348my$localtime_format='(%02d:%02d%s)';4349if($date->{'hour_local'} <6) {4350$localtime_format='(<span class="atnight">%02d:%02d</span>%s)';4351}4352$strtime.=' '.4353sprintf($localtime_format,4354$date->{'hour_local'},$date->{'minute_local'},$date->{'tz_local'});43554356return$strtime;4357}43584359# Outputs the author name and date in long form4360sub git_print_authorship {4361my$co=shift;4362my%opts=@_;4363my$tag=$opts{-tag} ||'div';4364my$author=$co->{'author_name'};43654366my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});4367print"<$tagclass=\"author_date\">".4368 format_search_author($author,"author", esc_html($author)) .4369" [".format_timestamp_html(\%ad)."]".4370 git_get_avatar($co->{'author_email'}, -pad_before =>1) .4371"</$tag>\n";4372}43734374# Outputs table rows containing the full author or committer information,4375# in the format expected for 'commit' view (& similar).4376# Parameters are a commit hash reference, followed by the list of people4377# to output information for. If the list is empty it defaults to both4378# author and committer.4379sub git_print_authorship_rows {4380my$co=shift;4381# too bad we can't use @people = @_ || ('author', 'committer')4382my@people=@_;4383@people= ('author','committer')unless@people;4384foreachmy$who(@people) {4385my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});4386print"<tr><td>$who</td><td>".4387 format_search_author($co->{"${who}_name"},$who,4388 esc_html($co->{"${who}_name"})) ." ".4389 format_search_author($co->{"${who}_email"},$who,4390 esc_html("<".$co->{"${who}_email"} .">")) .4391"</td><td rowspan=\"2\">".4392 git_get_avatar($co->{"${who}_email"}, -size =>'double') .4393"</td></tr>\n".4394"<tr>".4395"<td></td><td>".4396 format_timestamp_html(\%wd) .4397"</td>".4398"</tr>\n";4399}4400}44014402sub git_print_page_path {4403my$name=shift;4404my$type=shift;4405my$hb=shift;440644074408print"<div class=\"page_path\">";4409print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),4410-title =>'tree root'}, to_utf8("[$project]"));4411print" / ";4412if(defined$name) {4413my@dirname=split'/',$name;4414my$basename=pop@dirname;4415my$fullname='';44164417foreachmy$dir(@dirname) {4418$fullname.= ($fullname?'/':'') .$dir;4419print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,4420 hash_base=>$hb),4421-title =>$fullname}, esc_path($dir));4422print" / ";4423}4424if(defined$type&&$typeeq'blob') {4425print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,4426 hash_base=>$hb),4427-title =>$name}, esc_path($basename));4428}elsif(defined$type&&$typeeq'tree') {4429print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,4430 hash_base=>$hb),4431-title =>$name}, esc_path($basename));4432print" / ";4433}else{4434print esc_path($basename);4435}4436}4437print"<br/></div>\n";4438}44394440sub git_print_log {4441my$log=shift;4442my%opts=@_;44434444if($opts{'-remove_title'}) {4445# remove title, i.e. first line of log4446shift@$log;4447}4448# remove leading empty lines4449while(defined$log->[0] &&$log->[0]eq"") {4450shift@$log;4451}44524453# print log4454my$signoff=0;4455my$empty=0;4456foreachmy$line(@$log) {4457if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {4458$signoff=1;4459$empty=0;4460if(!$opts{'-remove_signoff'}) {4461print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";4462next;4463}else{4464# remove signoff lines4465next;4466}4467}else{4468$signoff=0;4469}44704471# print only one empty line4472# do not print empty line after signoff4473if($lineeq"") {4474next if($empty||$signoff);4475$empty=1;4476}else{4477$empty=0;4478}44794480print format_log_line_html($line) ."<br/>\n";4481}44824483if($opts{'-final_empty_line'}) {4484# end with single empty line4485print"<br/>\n"unless$empty;4486}4487}44884489# return link target (what link points to)4490sub git_get_link_target {4491my$hash=shift;4492my$link_target;44934494# read link4495open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4496orreturn;4497{4498local$/=undef;4499$link_target= <$fd>;4500}4501close$fd4502orreturn;45034504return$link_target;4505}45064507# given link target, and the directory (basedir) the link is in,4508# return target of link relative to top directory (top tree);4509# return undef if it is not possible (including absolute links).4510sub normalize_link_target {4511my($link_target,$basedir) =@_;45124513# absolute symlinks (beginning with '/') cannot be normalized4514return if(substr($link_target,0,1)eq'/');45154516# normalize link target to path from top (root) tree (dir)4517my$path;4518if($basedir) {4519$path=$basedir.'/'.$link_target;4520}else{4521# we are in top (root) tree (dir)4522$path=$link_target;4523}45244525# remove //, /./, and /../4526my@path_parts;4527foreachmy$part(split('/',$path)) {4528# discard '.' and ''4529next if(!$part||$parteq'.');4530# handle '..'4531if($parteq'..') {4532if(@path_parts) {4533pop@path_parts;4534}else{4535# link leads outside repository (outside top dir)4536return;4537}4538}else{4539push@path_parts,$part;4540}4541}4542$path=join('/',@path_parts);45434544return$path;4545}45464547# print tree entry (row of git_tree), but without encompassing <tr> element4548sub git_print_tree_entry {4549my($t,$basedir,$hash_base,$have_blame) =@_;45504551my%base_key= ();4552$base_key{'hash_base'} =$hash_baseifdefined$hash_base;45534554# The format of a table row is: mode list link. Where mode is4555# the mode of the entry, list is the name of the entry, an href,4556# and link is the action links of the entry.45574558print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";4559if(exists$t->{'size'}) {4560print"<td class=\"size\">$t->{'size'}</td>\n";4561}4562if($t->{'type'}eq"blob") {4563print"<td class=\"list\">".4564$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4565 file_name=>"$basedir$t->{'name'}",%base_key),4566-class=>"list"}, esc_path($t->{'name'}));4567if(S_ISLNK(oct$t->{'mode'})) {4568my$link_target= git_get_link_target($t->{'hash'});4569if($link_target) {4570my$norm_target= normalize_link_target($link_target,$basedir);4571if(defined$norm_target) {4572print" -> ".4573$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,4574 file_name=>$norm_target),4575-title =>$norm_target}, esc_path($link_target));4576}else{4577print" -> ". esc_path($link_target);4578}4579}4580}4581print"</td>\n";4582print"<td class=\"link\">";4583print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4584 file_name=>"$basedir$t->{'name'}",%base_key)},4585"blob");4586if($have_blame) {4587print" | ".4588$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},4589 file_name=>"$basedir$t->{'name'}",%base_key)},4590"blame");4591}4592if(defined$hash_base) {4593print" | ".4594$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,4595 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},4596"history");4597}4598print" | ".4599$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,4600 file_name=>"$basedir$t->{'name'}")},4601"raw");4602print"</td>\n";46034604}elsif($t->{'type'}eq"tree") {4605print"<td class=\"list\">";4606print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},4607 file_name=>"$basedir$t->{'name'}",4608%base_key)},4609 esc_path($t->{'name'}));4610print"</td>\n";4611print"<td class=\"link\">";4612print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},4613 file_name=>"$basedir$t->{'name'}",4614%base_key)},4615"tree");4616if(defined$hash_base) {4617print" | ".4618$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,4619 file_name=>"$basedir$t->{'name'}")},4620"history");4621}4622print"</td>\n";4623}else{4624# unknown object: we can only present history for it4625# (this includes 'commit' object, i.e. submodule support)4626print"<td class=\"list\">".4627 esc_path($t->{'name'}) .4628"</td>\n";4629print"<td class=\"link\">";4630if(defined$hash_base) {4631print$cgi->a({-href => href(action=>"history",4632 hash_base=>$hash_base,4633 file_name=>"$basedir$t->{'name'}")},4634"history");4635}4636print"</td>\n";4637}4638}46394640## ......................................................................4641## functions printing large fragments of HTML46424643# get pre-image filenames for merge (combined) diff4644sub fill_from_file_info {4645my($diff,@parents) =@_;46464647$diff->{'from_file'} = [ ];4648$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;4649for(my$i=0;$i<$diff->{'nparents'};$i++) {4650if($diff->{'status'}[$i]eq'R'||4651$diff->{'status'}[$i]eq'C') {4652$diff->{'from_file'}[$i] =4653 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);4654}4655}46564657return$diff;4658}46594660# is current raw difftree line of file deletion4661sub is_deleted {4662my$diffinfo=shift;46634664return$diffinfo->{'to_id'}eq('0' x 40);4665}46664667# does patch correspond to [previous] difftree raw line4668# $diffinfo - hashref of parsed raw diff format4669# $patchinfo - hashref of parsed patch diff format4670# (the same keys as in $diffinfo)4671sub is_patch_split {4672my($diffinfo,$patchinfo) =@_;46734674returndefined$diffinfo&&defined$patchinfo4675&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};4676}467746784679sub git_difftree_body {4680my($difftree,$hash,@parents) =@_;4681my($parent) =$parents[0];4682my$have_blame= gitweb_check_feature('blame');4683print"<div class=\"list_head\">\n";4684if($#{$difftree} >10) {4685print(($#{$difftree} +1) ." files changed:\n");4686}4687print"</div>\n";46884689print"<table class=\"".4690(@parents>1?"combined ":"") .4691"diff_tree\">\n";46924693# header only for combined diff in 'commitdiff' view4694my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';4695if($has_header) {4696# table header4697print"<thead><tr>\n".4698"<th></th><th></th>\n";# filename, patchN link4699for(my$i=0;$i<@parents;$i++) {4700my$par=$parents[$i];4701print"<th>".4702$cgi->a({-href => href(action=>"commitdiff",4703 hash=>$hash, hash_parent=>$par),4704-title =>'commitdiff to parent number '.4705($i+1) .': '.substr($par,0,7)},4706$i+1) .4707" </th>\n";4708}4709print"</tr></thead>\n<tbody>\n";4710}47114712my$alternate=1;4713my$patchno=0;4714foreachmy$line(@{$difftree}) {4715my$diff= parsed_difftree_line($line);47164717if($alternate) {4718print"<tr class=\"dark\">\n";4719}else{4720print"<tr class=\"light\">\n";4721}4722$alternate^=1;47234724if(exists$diff->{'nparents'}) {# combined diff47254726 fill_from_file_info($diff,@parents)4727unlessexists$diff->{'from_file'};47284729if(!is_deleted($diff)) {4730# file exists in the result (child) commit4731print"<td>".4732$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4733 file_name=>$diff->{'to_file'},4734 hash_base=>$hash),4735-class=>"list"}, esc_path($diff->{'to_file'})) .4736"</td>\n";4737}else{4738print"<td>".4739 esc_path($diff->{'to_file'}) .4740"</td>\n";4741}47424743if($actioneq'commitdiff') {4744# link to patch4745$patchno++;4746print"<td class=\"link\">".4747$cgi->a({-href => href(-anchor=>"patch$patchno")},4748"patch") .4749" | ".4750"</td>\n";4751}47524753my$has_history=0;4754my$not_deleted=0;4755for(my$i=0;$i<$diff->{'nparents'};$i++) {4756my$hash_parent=$parents[$i];4757my$from_hash=$diff->{'from_id'}[$i];4758my$from_path=$diff->{'from_file'}[$i];4759my$status=$diff->{'status'}[$i];47604761$has_history||= ($statusne'A');4762$not_deleted||= ($statusne'D');47634764if($statuseq'A') {4765print"<td class=\"link\"align=\"right\"> | </td>\n";4766}elsif($statuseq'D') {4767print"<td class=\"link\">".4768$cgi->a({-href => href(action=>"blob",4769 hash_base=>$hash,4770 hash=>$from_hash,4771 file_name=>$from_path)},4772"blob". ($i+1)) .4773" | </td>\n";4774}else{4775if($diff->{'to_id'}eq$from_hash) {4776print"<td class=\"link nochange\">";4777}else{4778print"<td class=\"link\">";4779}4780print$cgi->a({-href => href(action=>"blobdiff",4781 hash=>$diff->{'to_id'},4782 hash_parent=>$from_hash,4783 hash_base=>$hash,4784 hash_parent_base=>$hash_parent,4785 file_name=>$diff->{'to_file'},4786 file_parent=>$from_path)},4787"diff". ($i+1)) .4788" | </td>\n";4789}4790}47914792print"<td class=\"link\">";4793if($not_deleted) {4794print$cgi->a({-href => href(action=>"blob",4795 hash=>$diff->{'to_id'},4796 file_name=>$diff->{'to_file'},4797 hash_base=>$hash)},4798"blob");4799print" | "if($has_history);4800}4801if($has_history) {4802print$cgi->a({-href => href(action=>"history",4803 file_name=>$diff->{'to_file'},4804 hash_base=>$hash)},4805"history");4806}4807print"</td>\n";48084809print"</tr>\n";4810next;# instead of 'else' clause, to avoid extra indent4811}4812# else ordinary diff48134814my($to_mode_oct,$to_mode_str,$to_file_type);4815my($from_mode_oct,$from_mode_str,$from_file_type);4816if($diff->{'to_mode'}ne('0' x 6)) {4817$to_mode_oct=oct$diff->{'to_mode'};4818if(S_ISREG($to_mode_oct)) {# only for regular file4819$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits4820}4821$to_file_type= file_type($diff->{'to_mode'});4822}4823if($diff->{'from_mode'}ne('0' x 6)) {4824$from_mode_oct=oct$diff->{'from_mode'};4825if(S_ISREG($from_mode_oct)) {# only for regular file4826$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits4827}4828$from_file_type= file_type($diff->{'from_mode'});4829}48304831if($diff->{'status'}eq"A") {# created4832my$mode_chng="<span class=\"file_status new\">[new$to_file_type";4833$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;4834$mode_chng.="]</span>";4835print"<td>";4836print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4837 hash_base=>$hash, file_name=>$diff->{'file'}),4838-class=>"list"}, esc_path($diff->{'file'}));4839print"</td>\n";4840print"<td>$mode_chng</td>\n";4841print"<td class=\"link\">";4842if($actioneq'commitdiff') {4843# link to patch4844$patchno++;4845print$cgi->a({-href => href(-anchor=>"patch$patchno")},4846"patch") .4847" | ";4848}4849print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4850 hash_base=>$hash, file_name=>$diff->{'file'})},4851"blob");4852print"</td>\n";48534854}elsif($diff->{'status'}eq"D") {# deleted4855my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";4856print"<td>";4857print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4858 hash_base=>$parent, file_name=>$diff->{'file'}),4859-class=>"list"}, esc_path($diff->{'file'}));4860print"</td>\n";4861print"<td>$mode_chng</td>\n";4862print"<td class=\"link\">";4863if($actioneq'commitdiff') {4864# link to patch4865$patchno++;4866print$cgi->a({-href => href(-anchor=>"patch$patchno")},4867"patch") .4868" | ";4869}4870print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4871 hash_base=>$parent, file_name=>$diff->{'file'})},4872"blob") ." | ";4873if($have_blame) {4874print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,4875 file_name=>$diff->{'file'})},4876"blame") ." | ";4877}4878print$cgi->a({-href => href(action=>"history", hash_base=>$parent,4879 file_name=>$diff->{'file'})},4880"history");4881print"</td>\n";48824883}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed4884my$mode_chnge="";4885if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4886$mode_chnge="<span class=\"file_status mode_chnge\">[changed";4887if($from_file_typene$to_file_type) {4888$mode_chnge.=" from$from_file_typeto$to_file_type";4889}4890if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {4891if($from_mode_str&&$to_mode_str) {4892$mode_chnge.=" mode:$from_mode_str->$to_mode_str";4893}elsif($to_mode_str) {4894$mode_chnge.=" mode:$to_mode_str";4895}4896}4897$mode_chnge.="]</span>\n";4898}4899print"<td>";4900print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4901 hash_base=>$hash, file_name=>$diff->{'file'}),4902-class=>"list"}, esc_path($diff->{'file'}));4903print"</td>\n";4904print"<td>$mode_chnge</td>\n";4905print"<td class=\"link\">";4906if($actioneq'commitdiff') {4907# link to patch4908$patchno++;4909print$cgi->a({-href => href(-anchor=>"patch$patchno")},4910"patch") .4911" | ";4912}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4913# "commit" view and modified file (not onlu mode changed)4914print$cgi->a({-href => href(action=>"blobdiff",4915 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4916 hash_base=>$hash, hash_parent_base=>$parent,4917 file_name=>$diff->{'file'})},4918"diff") .4919" | ";4920}4921print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4922 hash_base=>$hash, file_name=>$diff->{'file'})},4923"blob") ." | ";4924if($have_blame) {4925print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4926 file_name=>$diff->{'file'})},4927"blame") ." | ";4928}4929print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4930 file_name=>$diff->{'file'})},4931"history");4932print"</td>\n";49334934}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied4935my%status_name= ('R'=>'moved','C'=>'copied');4936my$nstatus=$status_name{$diff->{'status'}};4937my$mode_chng="";4938if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4939# mode also for directories, so we cannot use $to_mode_str4940$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);4941}4942print"<td>".4943$cgi->a({-href => href(action=>"blob", hash_base=>$hash,4944 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),4945-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".4946"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".4947$cgi->a({-href => href(action=>"blob", hash_base=>$parent,4948 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),4949-class=>"list"}, esc_path($diff->{'from_file'})) .4950" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".4951"<td class=\"link\">";4952if($actioneq'commitdiff') {4953# link to patch4954$patchno++;4955print$cgi->a({-href => href(-anchor=>"patch$patchno")},4956"patch") .4957" | ";4958}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4959# "commit" view and modified file (not only pure rename or copy)4960print$cgi->a({-href => href(action=>"blobdiff",4961 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4962 hash_base=>$hash, hash_parent_base=>$parent,4963 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},4964"diff") .4965" | ";4966}4967print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4968 hash_base=>$parent, file_name=>$diff->{'to_file'})},4969"blob") ." | ";4970if($have_blame) {4971print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4972 file_name=>$diff->{'to_file'})},4973"blame") ." | ";4974}4975print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4976 file_name=>$diff->{'to_file'})},4977"history");4978print"</td>\n";49794980}# we should not encounter Unmerged (U) or Unknown (X) status4981print"</tr>\n";4982}4983print"</tbody>"if$has_header;4984print"</table>\n";4985}49864987sub print_sidebyside_diff_chunk {4988my@chunk=@_;4989my(@ctx,@rem,@add);49904991return unless@chunk;49924993# incomplete last line might be among removed or added lines,4994# or both, or among context lines: find which4995for(my$i=1;$i<@chunk;$i++) {4996if($chunk[$i][0]eq'incomplete') {4997$chunk[$i][0] =$chunk[$i-1][0];4998}4999}50005001# guardian5002push@chunk, ["",""];50035004foreachmy$line_info(@chunk) {5005my($class,$line) =@$line_info;50065007# print chunk headers5008if($class&&$classeq'chunk_header') {5009print$line;5010next;5011}50125013## print from accumulator when type of class of lines change5014# empty contents block on start rem/add block, or end of chunk5015if(@ctx&& (!$class||$classeq'rem'||$classeq'add')) {5016print join'',5017'<div class="chunk_block ctx">',5018'<div class="old">',5019@ctx,5020'</div>',5021'<div class="new">',5022@ctx,5023'</div>',5024'</div>';5025@ctx= ();5026}5027# empty add/rem block on start context block, or end of chunk5028if((@rem||@add) && (!$class||$classeq'ctx')) {5029if(!@add) {5030# pure removal5031print join'',5032'<div class="chunk_block rem">',5033'<div class="old">',5034@rem,5035'</div>',5036'</div>';5037}elsif(!@rem) {5038# pure addition5039print join'',5040'<div class="chunk_block add">',5041'<div class="new">',5042@add,5043'</div>',5044'</div>';5045}else{5046# assume that it is change5047print join'',5048'<div class="chunk_block chg">',5049'<div class="old">',5050@rem,5051'</div>',5052'<div class="new">',5053@add,5054'</div>',5055'</div>';5056}5057@rem=@add= ();5058}50595060## adding lines to accumulator5061# guardian value5062last unless$line;5063# rem, add or change5064if($classeq'rem') {5065push@rem,$line;5066}elsif($classeq'add') {5067push@add,$line;5068}5069# context line5070if($classeq'ctx') {5071push@ctx,$line;5072}5073}5074}50755076sub git_patchset_body {5077my($fd,$diff_style,$difftree,$hash,@hash_parents) =@_;5078my($hash_parent) =$hash_parents[0];50795080my$is_combined= (@hash_parents>1);5081my$patch_idx=0;5082my$patch_number=0;5083my$patch_line;5084my$diffinfo;5085my$to_name;5086my(%from,%to);5087my@chunk;# for side-by-side diff50885089print"<div class=\"patchset\">\n";50905091# skip to first patch5092while($patch_line= <$fd>) {5093chomp$patch_line;50945095last if($patch_line=~m/^diff /);5096}50975098 PATCH:5099while($patch_line) {51005101# parse "git diff" header line5102if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {5103# $1 is from_name, which we do not use5104$to_name= unquote($2);5105$to_name=~s!^b/!!;5106}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {5107# $1 is 'cc' or 'combined', which we do not use5108$to_name= unquote($2);5109}else{5110$to_name=undef;5111}51125113# check if current patch belong to current raw line5114# and parse raw git-diff line if needed5115if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {5116# this is continuation of a split patch5117print"<div class=\"patch cont\">\n";5118}else{5119# advance raw git-diff output if needed5120$patch_idx++ifdefined$diffinfo;51215122# read and prepare patch information5123$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);51245125# compact combined diff output can have some patches skipped5126# find which patch (using pathname of result) we are at now;5127if($is_combined) {5128while($to_namene$diffinfo->{'to_file'}) {5129print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".5130 format_diff_cc_simplified($diffinfo,@hash_parents) .5131"</div>\n";# class="patch"51325133$patch_idx++;5134$patch_number++;51355136last if$patch_idx>$#$difftree;5137$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);5138}5139}51405141# modifies %from, %to hashes5142 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);51435144# this is first patch for raw difftree line with $patch_idx index5145# we index @$difftree array from 0, but number patches from 15146print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";5147}51485149# git diff header5150#assert($patch_line =~ m/^diff /) if DEBUG;5151#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed5152$patch_number++;5153# print "git diff" header5154print format_git_diff_header_line($patch_line,$diffinfo,5155 \%from, \%to);51565157# print extended diff header5158print"<div class=\"diff extended_header\">\n";5159 EXTENDED_HEADER:5160while($patch_line= <$fd>) {5161chomp$patch_line;51625163last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);51645165print format_extended_diff_header_line($patch_line,$diffinfo,5166 \%from, \%to);5167}5168print"</div>\n";# class="diff extended_header"51695170# from-file/to-file diff header5171if(!$patch_line) {5172print"</div>\n";# class="patch"5173last PATCH;5174}5175next PATCH if($patch_line=~m/^diff /);5176#assert($patch_line =~ m/^---/) if DEBUG;51775178my$last_patch_line=$patch_line;5179$patch_line= <$fd>;5180chomp$patch_line;5181#assert($patch_line =~ m/^\+\+\+/) if DEBUG;51825183print format_diff_from_to_header($last_patch_line,$patch_line,5184$diffinfo, \%from, \%to,5185@hash_parents);51865187# the patch itself5188 LINE:5189while($patch_line= <$fd>) {5190chomp$patch_line;51915192next PATCH if($patch_line=~m/^diff /);51935194my($class,$line) = process_diff_line($patch_line, \%from, \%to);5195my$diff_classes="diff";5196$diff_classes.="$class"if($class);5197$line="<div class=\"$diff_classes\">$line</div>\n";51985199if($diff_styleeq'sidebyside'&& !$is_combined) {5200if($classeq'chunk_header') {5201 print_sidebyside_diff_chunk(@chunk);5202@chunk= ( [$class,$line] );5203}else{5204push@chunk, [$class,$line];5205}5206}else{5207# default 'inline' style and unknown styles5208print$line;5209}5210}52115212}continue{5213if(@chunk) {5214 print_sidebyside_diff_chunk(@chunk);5215@chunk= ();5216}5217print"</div>\n";# class="patch"5218}52195220# for compact combined (--cc) format, with chunk and patch simplification5221# the patchset might be empty, but there might be unprocessed raw lines5222for(++$patch_idxif$patch_number>0;5223$patch_idx<@$difftree;5224++$patch_idx) {5225# read and prepare patch information5226$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);52275228# generate anchor for "patch" links in difftree / whatchanged part5229print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".5230 format_diff_cc_simplified($diffinfo,@hash_parents) .5231"</div>\n";# class="patch"52325233$patch_number++;5234}52355236if($patch_number==0) {5237if(@hash_parents>1) {5238print"<div class=\"diff nodifferences\">Trivial merge</div>\n";5239}else{5240print"<div class=\"diff nodifferences\">No differences found</div>\n";5241}5242}52435244print"</div>\n";# class="patchset"5245}52465247# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .52485249sub git_project_search_form {5250my($searchtext,$search_use_regexp);52515252my$limit='';5253if($project_filter) {5254$limit=" in '$project_filter/'";5255}52565257print"<div class=\"projsearch\">\n";5258print$cgi->startform(-method=>'get', -action =>$my_uri) .5259$cgi->hidden(-name =>'a', -value =>'project_list') ."\n";5260print$cgi->hidden(-name =>'pf', -value =>$project_filter)."\n"5261if(defined$project_filter);5262print$cgi->textfield(-name =>'s', -value =>$searchtext,5263-title =>"Search project by name and description$limit",5264-size =>60) ."\n".5265"<span title=\"Extended regular expression\">".5266$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',5267-checked =>$search_use_regexp) .5268"</span>\n".5269$cgi->submit(-name =>'btnS', -value =>'Search') .5270$cgi->end_form() ."\n".5271$cgi->a({-href => href(project =>undef, searchtext =>undef,5272 project_filter =>$project_filter)},5273 esc_html("List all projects$limit")) ."<br />\n";5274print"</div>\n";5275}52765277# entry for given @keys needs filling if at least one of keys in list5278# is not present in %$project_info5279sub project_info_needs_filling {5280my($project_info,@keys) =@_;52815282# return List::MoreUtils::any { !exists $project_info->{$_} } @keys;5283foreachmy$key(@keys) {5284if(!exists$project_info->{$key}) {5285return1;5286}5287}5288return;5289}52905291# fills project list info (age, description, owner, category, forks, etc.)5292# for each project in the list, removing invalid projects from5293# returned list, or fill only specified info.5294#5295# Invalid projects are removed from the returned list if and only if you5296# ask 'age' or 'age_string' to be filled, because they are the only fields5297# that run unconditionally git command that requires repository, and5298# therefore do always check if project repository is invalid.5299#5300# USAGE:5301# * fill_project_list_info(\@project_list, 'descr_long', 'ctags')5302# ensures that 'descr_long' and 'ctags' fields are filled5303# * @project_list = fill_project_list_info(\@project_list)5304# ensures that all fields are filled (and invalid projects removed)5305#5306# NOTE: modifies $projlist, but does not remove entries from it5307sub fill_project_list_info {5308my($projlist,@wanted_keys) =@_;5309my@projects;5310my$filter_set=sub{return@_; };5311if(@wanted_keys) {5312my%wanted_keys=map{$_=>1}@wanted_keys;5313$filter_set=sub{returngrep{$wanted_keys{$_} }@_; };5314}53155316my$show_ctags= gitweb_check_feature('ctags');5317 PROJECT:5318foreachmy$pr(@$projlist) {5319if(project_info_needs_filling($pr,$filter_set->('age','age_string'))) {5320my(@activity) = git_get_last_activity($pr->{'path'});5321unless(@activity) {5322next PROJECT;5323}5324($pr->{'age'},$pr->{'age_string'}) =@activity;5325}5326if(project_info_needs_filling($pr,$filter_set->('descr','descr_long'))) {5327my$descr= git_get_project_description($pr->{'path'}) ||"";5328$descr= to_utf8($descr);5329$pr->{'descr_long'} =$descr;5330$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);5331}5332if(project_info_needs_filling($pr,$filter_set->('owner'))) {5333$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";5334}5335if($show_ctags&&5336 project_info_needs_filling($pr,$filter_set->('ctags'))) {5337$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});5338}5339if($projects_list_group_categories&&5340 project_info_needs_filling($pr,$filter_set->('category'))) {5341my$cat= git_get_project_category($pr->{'path'}) ||5342$project_list_default_category;5343$pr->{'category'} = to_utf8($cat);5344}53455346push@projects,$pr;5347}53485349return@projects;5350}53515352sub sort_projects_list {5353my($projlist,$order) =@_;5354my@projects;53555356my%order_info= (5357 project => { key =>'path', type =>'str'},5358 descr => { key =>'descr_long', type =>'str'},5359 owner => { key =>'owner', type =>'str'},5360 age => { key =>'age', type =>'num'}5361);5362my$oi=$order_info{$order};5363return@$projlistunlessdefined$oi;5364if($oi->{'type'}eq'str') {5365@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@$projlist;5366}else{5367@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@$projlist;5368}53695370return@projects;5371}53725373# returns a hash of categories, containing the list of project5374# belonging to each category5375sub build_projlist_by_category {5376my($projlist,$from,$to) =@_;5377my%categories;53785379$from=0unlessdefined$from;5380$to=$#$projlistif(!defined$to||$#$projlist<$to);53815382for(my$i=$from;$i<=$to;$i++) {5383my$pr=$projlist->[$i];5384push@{$categories{$pr->{'category'} }},$pr;5385}53865387returnwantarray?%categories: \%categories;5388}53895390# print 'sort by' <th> element, generating 'sort by $name' replay link5391# if that order is not selected5392sub print_sort_th {5393print format_sort_th(@_);5394}53955396sub format_sort_th {5397my($name,$order,$header) =@_;5398my$sort_th="";5399$header||=ucfirst($name);54005401if($ordereq$name) {5402$sort_th.="<th>$header</th>\n";5403}else{5404$sort_th.="<th>".5405$cgi->a({-href => href(-replay=>1, order=>$name),5406-class=>"header"},$header) .5407"</th>\n";5408}54095410return$sort_th;5411}54125413sub git_project_list_rows {5414my($projlist,$from,$to,$check_forks) =@_;54155416$from=0unlessdefined$from;5417$to=$#$projlistif(!defined$to||$#$projlist<$to);54185419my$alternate=1;5420for(my$i=$from;$i<=$to;$i++) {5421my$pr=$projlist->[$i];54225423if($alternate) {5424print"<tr class=\"dark\">\n";5425}else{5426print"<tr class=\"light\">\n";5427}5428$alternate^=1;54295430if($check_forks) {5431print"<td>";5432if($pr->{'forks'}) {5433my$nforks=scalar@{$pr->{'forks'}};5434if($nforks>0) {5435print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks"),5436-title =>"$nforksforks"},"+");5437}else{5438print$cgi->span({-title =>"$nforksforks"},"+");5439}5440}5441print"</td>\n";5442}5443print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),5444-class=>"list"},5445 esc_html_match_hl($pr->{'path'},$search_regexp)) .5446"</td>\n".5447"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),5448-class=>"list",5449-title =>$pr->{'descr_long'}},5450$search_regexp5451? esc_html_match_hl_chopped($pr->{'descr_long'},5452$pr->{'descr'},$search_regexp)5453: esc_html($pr->{'descr'})) .5454"</td>\n".5455"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";5456print"<td class=\"". age_class($pr->{'age'}) ."\">".5457(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".5458"<td class=\"link\">".5459$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".5460$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".5461$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".5462$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .5463($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .5464"</td>\n".5465"</tr>\n";5466}5467}54685469sub git_project_list_body {5470# actually uses global variable $project5471my($projlist,$order,$from,$to,$extra,$no_header) =@_;5472my@projects=@$projlist;54735474my$check_forks= gitweb_check_feature('forks');5475my$show_ctags= gitweb_check_feature('ctags');5476my$tagfilter=$show_ctags?$input_params{'ctag'} :undef;5477$check_forks=undef5478if($tagfilter||$searchtext);54795480# filtering out forks before filling info allows to do less work5481@projects= filter_forks_from_projects_list(\@projects)5482if($check_forks);5483# search_projects_list pre-fills required info5484@projects= search_projects_list(\@projects,5485'searchtext'=>$searchtext,5486'tagfilter'=>$tagfilter)5487if($tagfilter||$searchtext);5488# fill the rest5489@projects= fill_project_list_info(\@projects);54905491$order||=$default_projects_order;5492$from=0unlessdefined$from;5493$to=$#projectsif(!defined$to||$#projects<$to);54945495# short circuit5496if($from>$to) {5497print"<center>\n".5498"<b>No such projects found</b><br />\n".5499"Click ".$cgi->a({-href=>href(project=>undef)},"here")." to view all projects<br />\n".5500"</center>\n<br />\n";5501return;5502}55035504@projects= sort_projects_list(\@projects,$order);55055506if($show_ctags) {5507my$ctags= git_gather_all_ctags(\@projects);5508my$cloud= git_populate_project_tagcloud($ctags);5509print git_show_project_tagcloud($cloud,64);5510}55115512print"<table class=\"project_list\">\n";5513unless($no_header) {5514print"<tr>\n";5515if($check_forks) {5516print"<th></th>\n";5517}5518 print_sort_th('project',$order,'Project');5519 print_sort_th('descr',$order,'Description');5520 print_sort_th('owner',$order,'Owner');5521 print_sort_th('age',$order,'Last Change');5522print"<th></th>\n".# for links5523"</tr>\n";5524}55255526if($projects_list_group_categories) {5527# only display categories with projects in the $from-$to window5528@projects=sort{$a->{'category'}cmp$b->{'category'}}@projects[$from..$to];5529my%categories= build_projlist_by_category(\@projects,$from,$to);5530foreachmy$cat(sort keys%categories) {5531unless($cateq"") {5532print"<tr>\n";5533if($check_forks) {5534print"<td></td>\n";5535}5536print"<td class=\"category\"colspan=\"5\">".esc_html($cat)."</td>\n";5537print"</tr>\n";5538}55395540 git_project_list_rows($categories{$cat},undef,undef,$check_forks);5541}5542}else{5543 git_project_list_rows(\@projects,$from,$to,$check_forks);5544}55455546if(defined$extra) {5547print"<tr>\n";5548if($check_forks) {5549print"<td></td>\n";5550}5551print"<td colspan=\"5\">$extra</td>\n".5552"</tr>\n";5553}5554print"</table>\n";5555}55565557sub git_log_body {5558# uses global variable $project5559my($commitlist,$from,$to,$refs,$extra) =@_;55605561$from=0unlessdefined$from;5562$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);55635564for(my$i=0;$i<=$to;$i++) {5565my%co= %{$commitlist->[$i]};5566next if!%co;5567my$commit=$co{'id'};5568my$ref= format_ref_marker($refs,$commit);5569 git_print_header_div('commit',5570"<span class=\"age\">$co{'age_string'}</span>".5571 esc_html($co{'title'}) .$ref,5572$commit);5573print"<div class=\"title_text\">\n".5574"<div class=\"log_link\">\n".5575$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .5576" | ".5577$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .5578" | ".5579$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .5580"<br/>\n".5581"</div>\n";5582 git_print_authorship(\%co, -tag =>'span');5583print"<br/>\n</div>\n";55845585print"<div class=\"log_body\">\n";5586 git_print_log($co{'comment'}, -final_empty_line=>1);5587print"</div>\n";5588}5589if($extra) {5590print"<div class=\"page_nav\">\n";5591print"$extra\n";5592print"</div>\n";5593}5594}55955596sub git_shortlog_body {5597# uses global variable $project5598my($commitlist,$from,$to,$refs,$extra) =@_;55995600$from=0unlessdefined$from;5601$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);56025603print"<table class=\"shortlog\">\n";5604my$alternate=1;5605for(my$i=$from;$i<=$to;$i++) {5606my%co= %{$commitlist->[$i]};5607my$commit=$co{'id'};5608my$ref= format_ref_marker($refs,$commit);5609if($alternate) {5610print"<tr class=\"dark\">\n";5611}else{5612print"<tr class=\"light\">\n";5613}5614$alternate^=1;5615# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .5616print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5617 format_author_html('td', \%co,10) ."<td>";5618print format_subject_html($co{'title'},$co{'title_short'},5619 href(action=>"commit", hash=>$commit),$ref);5620print"</td>\n".5621"<td class=\"link\">".5622$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".5623$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".5624$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");5625my$snapshot_links= format_snapshot_links($commit);5626if(defined$snapshot_links) {5627print" | ".$snapshot_links;5628}5629print"</td>\n".5630"</tr>\n";5631}5632if(defined$extra) {5633print"<tr>\n".5634"<td colspan=\"4\">$extra</td>\n".5635"</tr>\n";5636}5637print"</table>\n";5638}56395640sub git_history_body {5641# Warning: assumes constant type (blob or tree) during history5642my($commitlist,$from,$to,$refs,$extra,5643$file_name,$file_hash,$ftype) =@_;56445645$from=0unlessdefined$from;5646$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});56475648print"<table class=\"history\">\n";5649my$alternate=1;5650for(my$i=$from;$i<=$to;$i++) {5651my%co= %{$commitlist->[$i]};5652if(!%co) {5653next;5654}5655my$commit=$co{'id'};56565657my$ref= format_ref_marker($refs,$commit);56585659if($alternate) {5660print"<tr class=\"dark\">\n";5661}else{5662print"<tr class=\"light\">\n";5663}5664$alternate^=1;5665print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5666# shortlog: format_author_html('td', \%co, 10)5667 format_author_html('td', \%co,15,3) ."<td>";5668# originally git_history used chop_str($co{'title'}, 50)5669print format_subject_html($co{'title'},$co{'title_short'},5670 href(action=>"commit", hash=>$commit),$ref);5671print"</td>\n".5672"<td class=\"link\">".5673$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".5674$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");56755676if($ftypeeq'blob') {5677my$blob_current=$file_hash;5678my$blob_parent= git_get_hash_by_path($commit,$file_name);5679if(defined$blob_current&&defined$blob_parent&&5680$blob_currentne$blob_parent) {5681print" | ".5682$cgi->a({-href => href(action=>"blobdiff",5683 hash=>$blob_current, hash_parent=>$blob_parent,5684 hash_base=>$hash_base, hash_parent_base=>$commit,5685 file_name=>$file_name)},5686"diff to current");5687}5688}5689print"</td>\n".5690"</tr>\n";5691}5692if(defined$extra) {5693print"<tr>\n".5694"<td colspan=\"4\">$extra</td>\n".5695"</tr>\n";5696}5697print"</table>\n";5698}56995700sub git_tags_body {5701# uses global variable $project5702my($taglist,$from,$to,$extra) =@_;5703$from=0unlessdefined$from;5704$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);57055706print"<table class=\"tags\">\n";5707my$alternate=1;5708for(my$i=$from;$i<=$to;$i++) {5709my$entry=$taglist->[$i];5710my%tag=%$entry;5711my$comment=$tag{'subject'};5712my$comment_short;5713if(defined$comment) {5714$comment_short= chop_str($comment,30,5);5715}5716if($alternate) {5717print"<tr class=\"dark\">\n";5718}else{5719print"<tr class=\"light\">\n";5720}5721$alternate^=1;5722if(defined$tag{'age'}) {5723print"<td><i>$tag{'age'}</i></td>\n";5724}else{5725print"<td></td>\n";5726}5727print"<td>".5728$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),5729-class=>"list name"}, esc_html($tag{'name'})) .5730"</td>\n".5731"<td>";5732if(defined$comment) {5733print format_subject_html($comment,$comment_short,5734 href(action=>"tag", hash=>$tag{'id'}));5735}5736print"</td>\n".5737"<td class=\"selflink\">";5738if($tag{'type'}eq"tag") {5739print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");5740}else{5741print" ";5742}5743print"</td>\n".5744"<td class=\"link\">"." | ".5745$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});5746if($tag{'reftype'}eq"commit") {5747print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .5748" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");5749}elsif($tag{'reftype'}eq"blob") {5750print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");5751}5752print"</td>\n".5753"</tr>";5754}5755if(defined$extra) {5756print"<tr>\n".5757"<td colspan=\"5\">$extra</td>\n".5758"</tr>\n";5759}5760print"</table>\n";5761}57625763sub git_heads_body {5764# uses global variable $project5765my($headlist,$head,$from,$to,$extra) =@_;5766$from=0unlessdefined$from;5767$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);57685769print"<table class=\"heads\">\n";5770my$alternate=1;5771for(my$i=$from;$i<=$to;$i++) {5772my$entry=$headlist->[$i];5773my%ref=%$entry;5774my$curr=$ref{'id'}eq$head;5775if($alternate) {5776print"<tr class=\"dark\">\n";5777}else{5778print"<tr class=\"light\">\n";5779}5780$alternate^=1;5781print"<td><i>$ref{'age'}</i></td>\n".5782($curr?"<td class=\"current_head\">":"<td>") .5783$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),5784-class=>"list name"},esc_html($ref{'name'})) .5785"</td>\n".5786"<td class=\"link\">".5787$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".5788$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".5789$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'fullname'})},"tree") .5790"</td>\n".5791"</tr>";5792}5793if(defined$extra) {5794print"<tr>\n".5795"<td colspan=\"3\">$extra</td>\n".5796"</tr>\n";5797}5798print"</table>\n";5799}58005801# Display a single remote block5802sub git_remote_block {5803my($remote,$rdata,$limit,$head) =@_;58045805my$heads=$rdata->{'heads'};5806my$fetch=$rdata->{'fetch'};5807my$push=$rdata->{'push'};58085809my$urls_table="<table class=\"projects_list\">\n";58105811if(defined$fetch) {5812if($fetcheq$push) {5813$urls_table.= format_repo_url("URL",$fetch);5814}else{5815$urls_table.= format_repo_url("Fetch URL",$fetch);5816$urls_table.= format_repo_url("Push URL",$push)ifdefined$push;5817}5818}elsif(defined$push) {5819$urls_table.= format_repo_url("Push URL",$push);5820}else{5821$urls_table.= format_repo_url("","No remote URL");5822}58235824$urls_table.="</table>\n";58255826my$dots;5827if(defined$limit&&$limit<@$heads) {5828$dots=$cgi->a({-href => href(action=>"remotes", hash=>$remote)},"...");5829}58305831print$urls_table;5832 git_heads_body($heads,$head,0,$limit,$dots);5833}58345835# Display a list of remote names with the respective fetch and push URLs5836sub git_remotes_list {5837my($remotedata,$limit) =@_;5838print"<table class=\"heads\">\n";5839my$alternate=1;5840my@remotes=sort keys%$remotedata;58415842my$limited=$limit&&$limit<@remotes;58435844$#remotes=$limit-1if$limited;58455846while(my$remote=shift@remotes) {5847my$rdata=$remotedata->{$remote};5848my$fetch=$rdata->{'fetch'};5849my$push=$rdata->{'push'};5850if($alternate) {5851print"<tr class=\"dark\">\n";5852}else{5853print"<tr class=\"light\">\n";5854}5855$alternate^=1;5856print"<td>".5857$cgi->a({-href=> href(action=>'remotes', hash=>$remote),5858-class=>"list name"},esc_html($remote)) .5859"</td>";5860print"<td class=\"link\">".5861(defined$fetch?$cgi->a({-href=>$fetch},"fetch") :"fetch") .5862" | ".5863(defined$push?$cgi->a({-href=>$push},"push") :"push") .5864"</td>";58655866print"</tr>\n";5867}58685869if($limited) {5870print"<tr>\n".5871"<td colspan=\"3\">".5872$cgi->a({-href => href(action=>"remotes")},"...") .5873"</td>\n"."</tr>\n";5874}58755876print"</table>";5877}58785879# Display remote heads grouped by remote, unless there are too many5880# remotes, in which case we only display the remote names5881sub git_remotes_body {5882my($remotedata,$limit,$head) =@_;5883if($limitand$limit<keys%$remotedata) {5884 git_remotes_list($remotedata,$limit);5885}else{5886 fill_remote_heads($remotedata);5887while(my($remote,$rdata) =each%$remotedata) {5888 git_print_section({-class=>"remote", -id=>$remote},5889["remotes",$remote,$remote],sub{5890 git_remote_block($remote,$rdata,$limit,$head);5891});5892}5893}5894}58955896sub git_search_message {5897my%co=@_;58985899my$greptype;5900if($searchtypeeq'commit') {5901$greptype="--grep=";5902}elsif($searchtypeeq'author') {5903$greptype="--author=";5904}elsif($searchtypeeq'committer') {5905$greptype="--committer=";5906}5907$greptype.=$searchtext;5908my@commitlist= parse_commits($hash,101, (100*$page),undef,5909$greptype,'--regexp-ignore-case',5910$search_use_regexp?'--extended-regexp':'--fixed-strings');59115912my$paging_nav='';5913if($page>0) {5914$paging_nav.=5915$cgi->a({-href => href(-replay=>1, page=>undef)},5916"first") .5917" ⋅ ".5918$cgi->a({-href => href(-replay=>1, page=>$page-1),5919-accesskey =>"p", -title =>"Alt-p"},"prev");5920}else{5921$paging_nav.="first ⋅ prev";5922}5923my$next_link='';5924if($#commitlist>=100) {5925$next_link=5926$cgi->a({-href => href(-replay=>1, page=>$page+1),5927-accesskey =>"n", -title =>"Alt-n"},"next");5928$paging_nav.=" ⋅$next_link";5929}else{5930$paging_nav.=" ⋅ next";5931}59325933 git_header_html();59345935 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);5936 git_print_header_div('commit', esc_html($co{'title'}),$hash);5937if($page==0&& !@commitlist) {5938print"<p>No match.</p>\n";5939}else{5940 git_search_grep_body(\@commitlist,0,99,$next_link);5941}59425943 git_footer_html();5944}59455946sub git_search_changes {5947my%co=@_;59485949local$/="\n";5950open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,5951'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",5952($search_use_regexp?'--pickaxe-regex': ())5953or die_error(500,"Open git-log failed");59545955 git_header_html();59565957 git_print_page_nav('','',$hash,$co{'tree'},$hash);5958 git_print_header_div('commit', esc_html($co{'title'}),$hash);59595960print"<table class=\"pickaxe search\">\n";5961my$alternate=1;5962undef%co;5963my@files;5964while(my$line= <$fd>) {5965chomp$line;5966next unless$line;59675968my%set= parse_difftree_raw_line($line);5969if(defined$set{'commit'}) {5970# finish previous commit5971if(%co) {5972print"</td>\n".5973"<td class=\"link\">".5974$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},5975"commit") .5976" | ".5977$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'},5978 hash_base=>$co{'id'})},5979"tree") .5980"</td>\n".5981"</tr>\n";5982}59835984if($alternate) {5985print"<tr class=\"dark\">\n";5986}else{5987print"<tr class=\"light\">\n";5988}5989$alternate^=1;5990%co= parse_commit($set{'commit'});5991my$author= chop_and_escape_str($co{'author_name'},15,5);5992print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5993"<td><i>$author</i></td>\n".5994"<td>".5995$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),5996-class=>"list subject"},5997 chop_and_escape_str($co{'title'},50) ."<br/>");5998}elsif(defined$set{'to_id'}) {5999next if($set{'to_id'} =~m/^0{40}$/);60006001print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6002 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6003-class=>"list"},6004"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6005"<br/>\n";6006}6007}6008close$fd;60096010# finish last commit (warning: repetition!)6011if(%co) {6012print"</td>\n".6013"<td class=\"link\">".6014$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},6015"commit") .6016" | ".6017$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'},6018 hash_base=>$co{'id'})},6019"tree") .6020"</td>\n".6021"</tr>\n";6022}60236024print"</table>\n";60256026 git_footer_html();6027}60286029sub git_search_files {6030my%co=@_;60316032local$/="\n";6033open my$fd,"-|", git_cmd(),'grep','-n','-z',6034$search_use_regexp? ('-E','-i') :'-F',6035$searchtext,$co{'tree'}6036or die_error(500,"Open git-grep failed");60376038 git_header_html();60396040 git_print_page_nav('','',$hash,$co{'tree'},$hash);6041 git_print_header_div('commit', esc_html($co{'title'}),$hash);60426043print"<table class=\"grep_search\">\n";6044my$alternate=1;6045my$matches=0;6046my$lastfile='';6047while(my$line= <$fd>) {6048chomp$line;6049my($file,$file_href,$lno,$ltext,$binary);6050last if($matches++>1000);6051if($line=~/^Binary file (.+) matches$/) {6052$file=$1;6053$binary=1;6054}else{6055($file,$lno,$ltext) =split(/\0/,$line,3);6056$file=~s/^$co{'tree'}://;6057}6058if($filene$lastfile) {6059$lastfileand print"</td></tr>\n";6060if($alternate++) {6061print"<tr class=\"dark\">\n";6062}else{6063print"<tr class=\"light\">\n";6064}6065$file_href= href(action=>"blob", hash_base=>$co{'id'},6066 file_name=>$file);6067print"<td class=\"list\">".6068$cgi->a({-href =>$file_href, -class=>"list"}, esc_path($file));6069print"</td><td>\n";6070$lastfile=$file;6071}6072if($binary) {6073print"<div class=\"binary\">Binary file</div>\n";6074}else{6075$ltext= untabify($ltext);6076if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6077$ltext= esc_html($1, -nbsp=>1);6078$ltext.='<span class="match">';6079$ltext.= esc_html($2, -nbsp=>1);6080$ltext.='</span>';6081$ltext.= esc_html($3, -nbsp=>1);6082}else{6083$ltext= esc_html($ltext, -nbsp=>1);6084}6085print"<div class=\"pre\">".6086$cgi->a({-href =>$file_href.'#l'.$lno,6087-class=>"linenr"},sprintf('%4i',$lno)) .6088' '.$ltext."</div>\n";6089}6090}6091if($lastfile) {6092print"</td></tr>\n";6093if($matches>1000) {6094print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6095}6096}else{6097print"<div class=\"diff nodifferences\">No matches found</div>\n";6098}6099close$fd;61006101print"</table>\n";61026103 git_footer_html();6104}61056106sub git_search_grep_body {6107my($commitlist,$from,$to,$extra) =@_;6108$from=0unlessdefined$from;6109$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);61106111print"<table class=\"commit_search\">\n";6112my$alternate=1;6113for(my$i=$from;$i<=$to;$i++) {6114my%co= %{$commitlist->[$i]};6115if(!%co) {6116next;6117}6118my$commit=$co{'id'};6119if($alternate) {6120print"<tr class=\"dark\">\n";6121}else{6122print"<tr class=\"light\">\n";6123}6124$alternate^=1;6125print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6126 format_author_html('td', \%co,15,5) .6127"<td>".6128$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6129-class=>"list subject"},6130 chop_and_escape_str($co{'title'},50) ."<br/>");6131my$comment=$co{'comment'};6132foreachmy$line(@$comment) {6133if($line=~m/^(.*?)($search_regexp)(.*)$/i) {6134my($lead,$match,$trail) = ($1,$2,$3);6135$match= chop_str($match,70,5,'center');6136my$contextlen=int((80-length($match))/2);6137$contextlen=30if($contextlen>30);6138$lead= chop_str($lead,$contextlen,10,'left');6139$trail= chop_str($trail,$contextlen,10,'right');61406141$lead= esc_html($lead);6142$match= esc_html($match);6143$trail= esc_html($trail);61446145print"$lead<span class=\"match\">$match</span>$trail<br />";6146}6147}6148print"</td>\n".6149"<td class=\"link\">".6150$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6151" | ".6152$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .6153" | ".6154$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6155print"</td>\n".6156"</tr>\n";6157}6158if(defined$extra) {6159print"<tr>\n".6160"<td colspan=\"3\">$extra</td>\n".6161"</tr>\n";6162}6163print"</table>\n";6164}61656166## ======================================================================6167## ======================================================================6168## actions61696170sub git_project_list {6171my$order=$input_params{'order'};6172if(defined$order&&$order!~m/none|project|descr|owner|age/) {6173 die_error(400,"Unknown order parameter");6174}61756176my@list= git_get_projects_list($project_filter,$strict_export);6177if(!@list) {6178 die_error(404,"No projects found");6179}61806181 git_header_html();6182if(defined$home_text&& -f $home_text) {6183print"<div class=\"index_include\">\n";6184 insert_file($home_text);6185print"</div>\n";6186}61876188 git_project_search_form($searchtext,$search_use_regexp);6189 git_project_list_body(\@list,$order);6190 git_footer_html();6191}61926193sub git_forks {6194my$order=$input_params{'order'};6195if(defined$order&&$order!~m/none|project|descr|owner|age/) {6196 die_error(400,"Unknown order parameter");6197}61986199my$filter=$project;6200$filter=~s/\.git$//;6201my@list= git_get_projects_list($filter);6202if(!@list) {6203 die_error(404,"No forks found");6204}62056206 git_header_html();6207 git_print_page_nav('','');6208 git_print_header_div('summary',"$projectforks");6209 git_project_list_body(\@list,$order);6210 git_footer_html();6211}62126213sub git_project_index {6214my@projects= git_get_projects_list($project_filter,$strict_export);6215if(!@projects) {6216 die_error(404,"No projects found");6217}62186219print$cgi->header(6220-type =>'text/plain',6221-charset =>'utf-8',6222-content_disposition =>'inline; filename="index.aux"');62236224foreachmy$pr(@projects) {6225if(!exists$pr->{'owner'}) {6226$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");6227}62286229my($path,$owner) = ($pr->{'path'},$pr->{'owner'});6230# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '6231$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;6232$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;6233$path=~s/ /\+/g;6234$owner=~s/ /\+/g;62356236print"$path$owner\n";6237}6238}62396240sub git_summary {6241my$descr= git_get_project_description($project) ||"none";6242my%co= parse_commit("HEAD");6243my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();6244my$head=$co{'id'};6245my$remote_heads= gitweb_check_feature('remote_heads');62466247my$owner= git_get_project_owner($project);62486249my$refs= git_get_references();6250# These get_*_list functions return one more to allow us to see if6251# there are more ...6252my@taglist= git_get_tags_list(16);6253my@headlist= git_get_heads_list(16);6254my%remotedata=$remote_heads? git_get_remotes_list() : ();6255my@forklist;6256my$check_forks= gitweb_check_feature('forks');62576258if($check_forks) {6259# find forks of a project6260my$filter=$project;6261$filter=~s/\.git$//;6262@forklist= git_get_projects_list($filter);6263# filter out forks of forks6264@forklist= filter_forks_from_projects_list(\@forklist)6265if(@forklist);6266}62676268 git_header_html();6269 git_print_page_nav('summary','',$head);62706271print"<div class=\"title\"> </div>\n";6272print"<table class=\"projects_list\">\n".6273"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".6274"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";6275if(defined$cd{'rfc2822'}) {6276print"<tr id=\"metadata_lchange\"><td>last change</td>".6277"<td>".format_timestamp_html(\%cd)."</td></tr>\n";6278}62796280# use per project git URL list in $projectroot/$project/cloneurl6281# or make project git URL from git base URL and project name6282my$url_tag="URL";6283my@url_list= git_get_project_url_list($project);6284@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;6285foreachmy$git_url(@url_list) {6286next unless$git_url;6287print format_repo_url($url_tag,$git_url);6288$url_tag="";6289}62906291# Tag cloud6292my$show_ctags= gitweb_check_feature('ctags');6293if($show_ctags) {6294my$ctags= git_get_project_ctags($project);6295if(%$ctags) {6296# without ability to add tags, don't show if there are none6297my$cloud= git_populate_project_tagcloud($ctags);6298print"<tr id=\"metadata_ctags\">".6299"<td>content tags</td>".6300"<td>".git_show_project_tagcloud($cloud,48)."</td>".6301"</tr>\n";6302}6303}63046305print"</table>\n";63066307# If XSS prevention is on, we don't include README.html.6308# TODO: Allow a readme in some safe format.6309if(!$prevent_xss&& -s "$projectroot/$project/README.html") {6310print"<div class=\"title\">readme</div>\n".6311"<div class=\"readme\">\n";6312 insert_file("$projectroot/$project/README.html");6313print"\n</div>\n";# class="readme"6314}63156316# we need to request one more than 16 (0..15) to check if6317# those 16 are all6318my@commitlist=$head? parse_commits($head,17) : ();6319if(@commitlist) {6320 git_print_header_div('shortlog');6321 git_shortlog_body(\@commitlist,0,15,$refs,6322$#commitlist<=15?undef:6323$cgi->a({-href => href(action=>"shortlog")},"..."));6324}63256326if(@taglist) {6327 git_print_header_div('tags');6328 git_tags_body(\@taglist,0,15,6329$#taglist<=15?undef:6330$cgi->a({-href => href(action=>"tags")},"..."));6331}63326333if(@headlist) {6334 git_print_header_div('heads');6335 git_heads_body(\@headlist,$head,0,15,6336$#headlist<=15?undef:6337$cgi->a({-href => href(action=>"heads")},"..."));6338}63396340if(%remotedata) {6341 git_print_header_div('remotes');6342 git_remotes_body(\%remotedata,15,$head);6343}63446345if(@forklist) {6346 git_print_header_div('forks');6347 git_project_list_body(\@forklist,'age',0,15,6348$#forklist<=15?undef:6349$cgi->a({-href => href(action=>"forks")},"..."),6350'no_header');6351}63526353 git_footer_html();6354}63556356sub git_tag {6357my%tag= parse_tag($hash);63586359if(!%tag) {6360 die_error(404,"Unknown tag object");6361}63626363my$head= git_get_head_hash($project);6364 git_header_html();6365 git_print_page_nav('','',$head,undef,$head);6366 git_print_header_div('commit', esc_html($tag{'name'}),$hash);6367print"<div class=\"title_text\">\n".6368"<table class=\"object_header\">\n".6369"<tr>\n".6370"<td>object</td>\n".6371"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},6372$tag{'object'}) ."</td>\n".6373"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},6374$tag{'type'}) ."</td>\n".6375"</tr>\n";6376if(defined($tag{'author'})) {6377 git_print_authorship_rows(\%tag,'author');6378}6379print"</table>\n\n".6380"</div>\n";6381print"<div class=\"page_body\">";6382my$comment=$tag{'comment'};6383foreachmy$line(@$comment) {6384chomp$line;6385print esc_html($line, -nbsp=>1) ."<br/>\n";6386}6387print"</div>\n";6388 git_footer_html();6389}63906391sub git_blame_common {6392my$format=shift||'porcelain';6393if($formateq'porcelain'&&$input_params{'javascript'}) {6394$format='incremental';6395$action='blame_incremental';# for page title etc6396}63976398# permissions6399 gitweb_check_feature('blame')6400or die_error(403,"Blame view not allowed");64016402# error checking6403 die_error(400,"No file name given")unless$file_name;6404$hash_base||= git_get_head_hash($project);6405 die_error(404,"Couldn't find base commit")unless$hash_base;6406my%co= parse_commit($hash_base)6407or die_error(404,"Commit not found");6408my$ftype="blob";6409if(!defined$hash) {6410$hash= git_get_hash_by_path($hash_base,$file_name,"blob")6411or die_error(404,"Error looking up file");6412}else{6413$ftype= git_get_type($hash);6414if($ftype!~"blob") {6415 die_error(400,"Object is not a blob");6416}6417}64186419my$fd;6420if($formateq'incremental') {6421# get file contents (as base)6422open$fd,"-|", git_cmd(),'cat-file','blob',$hash6423or die_error(500,"Open git-cat-file failed");6424}elsif($formateq'data') {6425# run git-blame --incremental6426open$fd,"-|", git_cmd(),"blame","--incremental",6427$hash_base,"--",$file_name6428or die_error(500,"Open git-blame --incremental failed");6429}else{6430# run git-blame --porcelain6431open$fd,"-|", git_cmd(),"blame",'-p',6432$hash_base,'--',$file_name6433or die_error(500,"Open git-blame --porcelain failed");6434}64356436# incremental blame data returns early6437if($formateq'data') {6438print$cgi->header(6439-type=>"text/plain", -charset =>"utf-8",6440-status=>"200 OK");6441local$| =1;# output autoflush6442while(my$line= <$fd>) {6443print to_utf8($line);6444}6445close$fd6446or print"ERROR$!\n";64476448print'END';6449if(defined$t0&& gitweb_check_feature('timed')) {6450print' '.6451 tv_interval($t0, [ gettimeofday() ]).6452' '.$number_of_git_cmds;6453}6454print"\n";64556456return;6457}64586459# page header6460 git_header_html();6461my$formats_nav=6462$cgi->a({-href => href(action=>"blob", -replay=>1)},6463"blob") .6464" | ";6465if($formateq'incremental') {6466$formats_nav.=6467$cgi->a({-href => href(action=>"blame", javascript=>0, -replay=>1)},6468"blame") ." (non-incremental)";6469}else{6470$formats_nav.=6471$cgi->a({-href => href(action=>"blame_incremental", -replay=>1)},6472"blame") ." (incremental)";6473}6474$formats_nav.=6475" | ".6476$cgi->a({-href => href(action=>"history", -replay=>1)},6477"history") .6478" | ".6479$cgi->a({-href => href(action=>$action, file_name=>$file_name)},6480"HEAD");6481 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);6482 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);6483 git_print_page_path($file_name,$ftype,$hash_base);64846485# page body6486if($formateq'incremental') {6487print"<noscript>\n<div class=\"error\"><center><b>\n".6488"This page requires JavaScript to run.\nUse ".6489$cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},6490'this page').6491" instead.\n".6492"</b></center></div>\n</noscript>\n";64936494print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!;6495}64966497print qq!<div class="page_body">\n!;6498print qq!<div id="progress_info">.../ ...</div>\n!6499if($formateq'incremental');6500print qq!<table id="blame_table"class="blame" width="100%">\n!.6501#qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.6502 qq!<thead>\n!.6503 qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!.6504 qq!</thead>\n!.6505 qq!<tbody>\n!;65066507my@rev_color=qw(light dark);6508my$num_colors=scalar(@rev_color);6509my$current_color=0;65106511if($formateq'incremental') {6512my$color_class=$rev_color[$current_color];65136514#contents of a file6515my$linenr=0;6516 LINE:6517while(my$line= <$fd>) {6518chomp$line;6519$linenr++;65206521print qq!<tr id="l$linenr"class="$color_class">!.6522 qq!<td class="sha1"><a href=""> </a></td>!.6523 qq!<td class="linenr">!.6524 qq!<a class="linenr" href="">$linenr</a></td>!;6525print qq!<td class="pre">! . esc_html($line) ."</td>\n";6526print qq!</tr>\n!;6527}65286529}else{# porcelain, i.e. ordinary blame6530my%metainfo= ();# saves information about commits65316532# blame data6533 LINE:6534while(my$line= <$fd>) {6535chomp$line;6536# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]6537# no <lines in group> for subsequent lines in group of lines6538my($full_rev,$orig_lineno,$lineno,$group_size) =6539($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);6540if(!exists$metainfo{$full_rev}) {6541$metainfo{$full_rev} = {'nprevious'=>0};6542}6543my$meta=$metainfo{$full_rev};6544my$data;6545while($data= <$fd>) {6546chomp$data;6547last if($data=~s/^\t//);# contents of line6548if($data=~/^(\S+)(?: (.*))?$/) {6549$meta->{$1} =$2unlessexists$meta->{$1};6550}6551if($data=~/^previous /) {6552$meta->{'nprevious'}++;6553}6554}6555my$short_rev=substr($full_rev,0,8);6556my$author=$meta->{'author'};6557my%date=6558 parse_date($meta->{'author-time'},$meta->{'author-tz'});6559my$date=$date{'iso-tz'};6560if($group_size) {6561$current_color= ($current_color+1) %$num_colors;6562}6563my$tr_class=$rev_color[$current_color];6564$tr_class.=' boundary'if(exists$meta->{'boundary'});6565$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);6566$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);6567print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";6568if($group_size) {6569print"<td class=\"sha1\"";6570print" title=\"". esc_html($author) .",$date\"";6571print" rowspan=\"$group_size\""if($group_size>1);6572print">";6573print$cgi->a({-href => href(action=>"commit",6574 hash=>$full_rev,6575 file_name=>$file_name)},6576 esc_html($short_rev));6577if($group_size>=2) {6578my@author_initials= ($author=~/\b([[:upper:]])\B/g);6579if(@author_initials) {6580print"<br />".6581 esc_html(join('',@author_initials));6582# or join('.', ...)6583}6584}6585print"</td>\n";6586}6587# 'previous' <sha1 of parent commit> <filename at commit>6588if(exists$meta->{'previous'} &&6589$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {6590$meta->{'parent'} =$1;6591$meta->{'file_parent'} = unquote($2);6592}6593my$linenr_commit=6594exists($meta->{'parent'}) ?6595$meta->{'parent'} :$full_rev;6596my$linenr_filename=6597exists($meta->{'file_parent'}) ?6598$meta->{'file_parent'} : unquote($meta->{'filename'});6599my$blamed= href(action =>'blame',6600 file_name =>$linenr_filename,6601 hash_base =>$linenr_commit);6602print"<td class=\"linenr\">";6603print$cgi->a({ -href =>"$blamed#l$orig_lineno",6604-class=>"linenr"},6605 esc_html($lineno));6606print"</td>";6607print"<td class=\"pre\">". esc_html($data) ."</td>\n";6608print"</tr>\n";6609}# end while66106611}66126613# footer6614print"</tbody>\n".6615"</table>\n";# class="blame"6616print"</div>\n";# class="blame_body"6617close$fd6618or print"Reading blob failed\n";66196620 git_footer_html();6621}66226623sub git_blame {6624 git_blame_common();6625}66266627sub git_blame_incremental {6628 git_blame_common('incremental');6629}66306631sub git_blame_data {6632 git_blame_common('data');6633}66346635sub git_tags {6636my$head= git_get_head_hash($project);6637 git_header_html();6638 git_print_page_nav('','',$head,undef,$head,format_ref_views('tags'));6639 git_print_header_div('summary',$project);66406641my@tagslist= git_get_tags_list();6642if(@tagslist) {6643 git_tags_body(\@tagslist);6644}6645 git_footer_html();6646}66476648sub git_heads {6649my$head= git_get_head_hash($project);6650 git_header_html();6651 git_print_page_nav('','',$head,undef,$head,format_ref_views('heads'));6652 git_print_header_div('summary',$project);66536654my@headslist= git_get_heads_list();6655if(@headslist) {6656 git_heads_body(\@headslist,$head);6657}6658 git_footer_html();6659}66606661# used both for single remote view and for list of all the remotes6662sub git_remotes {6663 gitweb_check_feature('remote_heads')6664or die_error(403,"Remote heads view is disabled");66656666my$head= git_get_head_hash($project);6667my$remote=$input_params{'hash'};66686669my$remotedata= git_get_remotes_list($remote);6670 die_error(500,"Unable to get remote information")unlessdefined$remotedata;66716672unless(%$remotedata) {6673 die_error(404,defined$remote?6674"Remote$remotenot found":6675"No remotes found");6676}66776678 git_header_html(undef,undef, -action_extra =>$remote);6679 git_print_page_nav('','',$head,undef,$head,6680 format_ref_views($remote?'':'remotes'));66816682 fill_remote_heads($remotedata);6683if(defined$remote) {6684 git_print_header_div('remotes',"$remoteremote for$project");6685 git_remote_block($remote,$remotedata->{$remote},undef,$head);6686}else{6687 git_print_header_div('summary',"$projectremotes");6688 git_remotes_body($remotedata,undef,$head);6689}66906691 git_footer_html();6692}66936694sub git_blob_plain {6695my$type=shift;6696my$expires;66976698if(!defined$hash) {6699if(defined$file_name) {6700my$base=$hash_base|| git_get_head_hash($project);6701$hash= git_get_hash_by_path($base,$file_name,"blob")6702or die_error(404,"Cannot find file");6703}else{6704 die_error(400,"No file name defined");6705}6706}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {6707# blobs defined by non-textual hash id's can be cached6708$expires="+1d";6709}67106711open my$fd,"-|", git_cmd(),"cat-file","blob",$hash6712or die_error(500,"Open git-cat-file blob '$hash' failed");67136714# content-type (can include charset)6715$type= blob_contenttype($fd,$file_name,$type);67166717# "save as" filename, even when no $file_name is given6718my$save_as="$hash";6719if(defined$file_name) {6720$save_as=$file_name;6721}elsif($type=~m/^text\//) {6722$save_as.='.txt';6723}67246725# With XSS prevention on, blobs of all types except a few known safe6726# ones are served with "Content-Disposition: attachment" to make sure6727# they don't run in our security domain. For certain image types,6728# blob view writes an <img> tag referring to blob_plain view, and we6729# want to be sure not to break that by serving the image as an6730# attachment (though Firefox 3 doesn't seem to care).6731my$sandbox=$prevent_xss&&6732$type!~m!^(?:text/[a-z]+|image/(?:gif|png|jpeg))(?:[ ;]|$)!;67336734# serve text/* as text/plain6735if($prevent_xss&&6736($type=~m!^text/[a-z]+\b(.*)$!||6737($type=~m!^[a-z]+/[a-z]\+xml\b(.*)$!&& -T $fd))) {6738my$rest=$1;6739$rest=defined$rest?$rest:'';6740$type="text/plain$rest";6741}67426743print$cgi->header(6744-type =>$type,6745-expires =>$expires,6746-content_disposition =>6747($sandbox?'attachment':'inline')6748.'; filename="'.$save_as.'"');6749local$/=undef;6750binmode STDOUT,':raw';6751print<$fd>;6752binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi6753close$fd;6754}67556756sub git_blob {6757my$expires;67586759if(!defined$hash) {6760if(defined$file_name) {6761my$base=$hash_base|| git_get_head_hash($project);6762$hash= git_get_hash_by_path($base,$file_name,"blob")6763or die_error(404,"Cannot find file");6764}else{6765 die_error(400,"No file name defined");6766}6767}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {6768# blobs defined by non-textual hash id's can be cached6769$expires="+1d";6770}67716772my$have_blame= gitweb_check_feature('blame');6773open my$fd,"-|", git_cmd(),"cat-file","blob",$hash6774or die_error(500,"Couldn't cat$file_name,$hash");6775my$mimetype= blob_mimetype($fd,$file_name);6776# use 'blob_plain' (aka 'raw') view for files that cannot be displayed6777if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {6778close$fd;6779return git_blob_plain($mimetype);6780}6781# we can have blame only for text/* mimetype6782$have_blame&&= ($mimetype=~m!^text/!);67836784my$highlight= gitweb_check_feature('highlight');6785my$syntax= guess_file_syntax($highlight,$mimetype,$file_name);6786$fd= run_highlighter($fd,$highlight,$syntax)6787if$syntax;67886789 git_header_html(undef,$expires);6790my$formats_nav='';6791if(defined$hash_base&& (my%co= parse_commit($hash_base))) {6792if(defined$file_name) {6793if($have_blame) {6794$formats_nav.=6795$cgi->a({-href => href(action=>"blame", -replay=>1)},6796"blame") .6797" | ";6798}6799$formats_nav.=6800$cgi->a({-href => href(action=>"history", -replay=>1)},6801"history") .6802" | ".6803$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},6804"raw") .6805" | ".6806$cgi->a({-href => href(action=>"blob",6807 hash_base=>"HEAD", file_name=>$file_name)},6808"HEAD");6809}else{6810$formats_nav.=6811$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},6812"raw");6813}6814 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);6815 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);6816}else{6817print"<div class=\"page_nav\">\n".6818"<br/><br/></div>\n".6819"<div class=\"title\">".esc_html($hash)."</div>\n";6820}6821 git_print_page_path($file_name,"blob",$hash_base);6822print"<div class=\"page_body\">\n";6823if($mimetype=~m!^image/!) {6824print qq!<img type="!.esc_attr($mimetype).qq!"!;6825if($file_name) {6826print qq! alt="!.esc_attr($file_name).qq!" title="!.esc_attr($file_name).qq!"!;6827}6828print qq! src="! .6829 href(action=>"blob_plain", hash=>$hash,6830 hash_base=>$hash_base, file_name=>$file_name) .6831 qq!"/>\n!;6832}else{6833my$nr;6834while(my$line= <$fd>) {6835chomp$line;6836$nr++;6837$line= untabify($line);6838printf qq!<div class="pre"><a id="l%i" href="%s#l%i"class="linenr">%4i</a> %s</div>\n!,6839$nr, esc_attr(href(-replay =>1)),$nr,$nr,6840$syntax? sanitize($line) : esc_html($line, -nbsp=>1);6841}6842}6843close$fd6844or print"Reading blob failed.\n";6845print"</div>";6846 git_footer_html();6847}68486849sub git_tree {6850if(!defined$hash_base) {6851$hash_base="HEAD";6852}6853if(!defined$hash) {6854if(defined$file_name) {6855$hash= git_get_hash_by_path($hash_base,$file_name,"tree");6856}else{6857$hash=$hash_base;6858}6859}6860 die_error(404,"No such tree")unlessdefined($hash);68616862my$show_sizes= gitweb_check_feature('show-sizes');6863my$have_blame= gitweb_check_feature('blame');68646865my@entries= ();6866{6867local$/="\0";6868open my$fd,"-|", git_cmd(),"ls-tree",'-z',6869($show_sizes?'-l': ()),@extra_options,$hash6870or die_error(500,"Open git-ls-tree failed");6871@entries=map{chomp;$_} <$fd>;6872close$fd6873or die_error(404,"Reading tree failed");6874}68756876my$refs= git_get_references();6877my$ref= format_ref_marker($refs,$hash_base);6878 git_header_html();6879my$basedir='';6880if(defined$hash_base&& (my%co= parse_commit($hash_base))) {6881my@views_nav= ();6882if(defined$file_name) {6883push@views_nav,6884$cgi->a({-href => href(action=>"history", -replay=>1)},6885"history"),6886$cgi->a({-href => href(action=>"tree",6887 hash_base=>"HEAD", file_name=>$file_name)},6888"HEAD"),6889}6890my$snapshot_links= format_snapshot_links($hash);6891if(defined$snapshot_links) {6892# FIXME: Should be available when we have no hash base as well.6893push@views_nav,$snapshot_links;6894}6895 git_print_page_nav('tree','',$hash_base,undef,undef,6896join(' | ',@views_nav));6897 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);6898}else{6899undef$hash_base;6900print"<div class=\"page_nav\">\n";6901print"<br/><br/></div>\n";6902print"<div class=\"title\">".esc_html($hash)."</div>\n";6903}6904if(defined$file_name) {6905$basedir=$file_name;6906if($basedirne''&&substr($basedir, -1)ne'/') {6907$basedir.='/';6908}6909 git_print_page_path($file_name,'tree',$hash_base);6910}6911print"<div class=\"page_body\">\n";6912print"<table class=\"tree\">\n";6913my$alternate=1;6914# '..' (top directory) link if possible6915if(defined$hash_base&&6916defined$file_name&&$file_name=~m![^/]+$!) {6917if($alternate) {6918print"<tr class=\"dark\">\n";6919}else{6920print"<tr class=\"light\">\n";6921}6922$alternate^=1;69236924my$up=$file_name;6925$up=~s!/?[^/]+$!!;6926undef$upunless$up;6927# based on git_print_tree_entry6928print'<td class="mode">'. mode_str('040000') ."</td>\n";6929print'<td class="size"> </td>'."\n"if$show_sizes;6930print'<td class="list">';6931print$cgi->a({-href => href(action=>"tree",6932 hash_base=>$hash_base,6933 file_name=>$up)},6934"..");6935print"</td>\n";6936print"<td class=\"link\"></td>\n";69376938print"</tr>\n";6939}6940foreachmy$line(@entries) {6941my%t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);69426943if($alternate) {6944print"<tr class=\"dark\">\n";6945}else{6946print"<tr class=\"light\">\n";6947}6948$alternate^=1;69496950 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);69516952print"</tr>\n";6953}6954print"</table>\n".6955"</div>";6956 git_footer_html();6957}69586959sub snapshot_name {6960my($project,$hash) =@_;69616962# path/to/project.git -> project6963# path/to/project/.git -> project6964my$name= to_utf8($project);6965$name=~ s,([^/])/*\.git$,$1,;6966$name= basename($name);6967# sanitize name6968$name=~s/[[:cntrl:]]/?/g;69696970my$ver=$hash;6971if($hash=~/^[0-9a-fA-F]+$/) {6972# shorten SHA-1 hash6973my$full_hash= git_get_full_hash($project,$hash);6974if($full_hash=~/^$hash/&&length($hash) >7) {6975$ver= git_get_short_hash($project,$hash);6976}6977}elsif($hash=~m!^refs/tags/(.*)$!) {6978# tags don't need shortened SHA-1 hash6979$ver=$1;6980}else{6981# branches and other need shortened SHA-1 hash6982if($hash=~m!^refs/(?:heads|remotes)/(.*)$!) {6983$ver=$1;6984}6985$ver.='-'. git_get_short_hash($project,$hash);6986}6987# in case of hierarchical branch names6988$ver=~s!/!.!g;69896990# name = project-version_string6991$name="$name-$ver";69926993returnwantarray? ($name,$name) :$name;6994}69956996sub git_snapshot {6997my$format=$input_params{'snapshot_format'};6998if(!@snapshot_fmts) {6999 die_error(403,"Snapshots not allowed");7000}7001# default to first supported snapshot format7002$format||=$snapshot_fmts[0];7003if($format!~m/^[a-z0-9]+$/) {7004 die_error(400,"Invalid snapshot format parameter");7005}elsif(!exists($known_snapshot_formats{$format})) {7006 die_error(400,"Unknown snapshot format");7007}elsif($known_snapshot_formats{$format}{'disabled'}) {7008 die_error(403,"Snapshot format not allowed");7009}elsif(!grep($_eq$format,@snapshot_fmts)) {7010 die_error(403,"Unsupported snapshot format");7011}70127013my$type= git_get_type("$hash^{}");7014if(!$type) {7015 die_error(404,'Object does not exist');7016}elsif($typeeq'blob') {7017 die_error(400,'Object is not a tree-ish');7018}70197020my($name,$prefix) = snapshot_name($project,$hash);7021my$filename="$name$known_snapshot_formats{$format}{'suffix'}";7022my$cmd= quote_command(7023 git_cmd(),'archive',7024"--format=$known_snapshot_formats{$format}{'format'}",7025"--prefix=$prefix/",$hash);7026if(exists$known_snapshot_formats{$format}{'compressor'}) {7027$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});7028}70297030$filename=~s/(["\\])/\\$1/g;7031print$cgi->header(7032-type =>$known_snapshot_formats{$format}{'type'},7033-content_disposition =>'inline; filename="'.$filename.'"',7034-status =>'200 OK');70357036open my$fd,"-|",$cmd7037or die_error(500,"Execute git-archive failed");7038binmode STDOUT,':raw';7039print<$fd>;7040binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi7041close$fd;7042}70437044sub git_log_generic {7045my($fmt_name,$body_subr,$base,$parent,$file_name,$file_hash) =@_;70467047my$head= git_get_head_hash($project);7048if(!defined$base) {7049$base=$head;7050}7051if(!defined$page) {7052$page=0;7053}7054my$refs= git_get_references();70557056my$commit_hash=$base;7057if(defined$parent) {7058$commit_hash="$parent..$base";7059}7060my@commitlist=7061 parse_commits($commit_hash,101, (100*$page),7062defined$file_name? ($file_name,"--full-history") : ());70637064my$ftype;7065if(!defined$file_hash&&defined$file_name) {7066# some commits could have deleted file in question,7067# and not have it in tree, but one of them has to have it7068for(my$i=0;$i<@commitlist;$i++) {7069$file_hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);7070last ifdefined$file_hash;7071}7072}7073if(defined$file_hash) {7074$ftype= git_get_type($file_hash);7075}7076if(defined$file_name&& !defined$ftype) {7077 die_error(500,"Unknown type of object");7078}7079my%co;7080if(defined$file_name) {7081%co= parse_commit($base)7082or die_error(404,"Unknown commit object");7083}708470857086my$paging_nav= format_paging_nav($fmt_name,$page,$#commitlist>=100);7087my$next_link='';7088if($#commitlist>=100) {7089$next_link=7090$cgi->a({-href => href(-replay=>1, page=>$page+1),7091-accesskey =>"n", -title =>"Alt-n"},"next");7092}7093my$patch_max= gitweb_get_feature('patches');7094if($patch_max&& !defined$file_name) {7095if($patch_max<0||@commitlist<=$patch_max) {7096$paging_nav.=" ⋅ ".7097$cgi->a({-href => href(action=>"patches", -replay=>1)},7098"patches");7099}7100}71017102 git_header_html();7103 git_print_page_nav($fmt_name,'',$hash,$hash,$hash,$paging_nav);7104if(defined$file_name) {7105 git_print_header_div('commit', esc_html($co{'title'}),$base);7106}else{7107 git_print_header_div('summary',$project)7108}7109 git_print_page_path($file_name,$ftype,$hash_base)7110if(defined$file_name);71117112$body_subr->(\@commitlist,0,99,$refs,$next_link,7113$file_name,$file_hash,$ftype);71147115 git_footer_html();7116}71177118sub git_log {7119 git_log_generic('log', \&git_log_body,7120$hash,$hash_parent);7121}71227123sub git_commit {7124$hash||=$hash_base||"HEAD";7125my%co= parse_commit($hash)7126or die_error(404,"Unknown commit object");71277128my$parent=$co{'parent'};7129my$parents=$co{'parents'};# listref71307131# we need to prepare $formats_nav before any parameter munging7132my$formats_nav;7133if(!defined$parent) {7134# --root commitdiff7135$formats_nav.='(initial)';7136}elsif(@$parents==1) {7137# single parent commit7138$formats_nav.=7139'(parent: '.7140$cgi->a({-href => href(action=>"commit",7141 hash=>$parent)},7142 esc_html(substr($parent,0,7))) .7143')';7144}else{7145# merge commit7146$formats_nav.=7147'(merge: '.7148join(' ',map{7149$cgi->a({-href => href(action=>"commit",7150 hash=>$_)},7151 esc_html(substr($_,0,7)));7152}@$parents) .7153')';7154}7155if(gitweb_check_feature('patches') &&@$parents<=1) {7156$formats_nav.=" | ".7157$cgi->a({-href => href(action=>"patch", -replay=>1)},7158"patch");7159}71607161if(!defined$parent) {7162$parent="--root";7163}7164my@difftree;7165open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",7166@diff_opts,7167(@$parents<=1?$parent:'-c'),7168$hash,"--"7169or die_error(500,"Open git-diff-tree failed");7170@difftree=map{chomp;$_} <$fd>;7171close$fdor die_error(404,"Reading git-diff-tree failed");71727173# non-textual hash id's can be cached7174my$expires;7175if($hash=~m/^[0-9a-fA-F]{40}$/) {7176$expires="+1d";7177}7178my$refs= git_get_references();7179my$ref= format_ref_marker($refs,$co{'id'});71807181 git_header_html(undef,$expires);7182 git_print_page_nav('commit','',7183$hash,$co{'tree'},$hash,7184$formats_nav);71857186if(defined$co{'parent'}) {7187 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);7188}else{7189 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);7190}7191print"<div class=\"title_text\">\n".7192"<table class=\"object_header\">\n";7193 git_print_authorship_rows(\%co);7194print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";7195print"<tr>".7196"<td>tree</td>".7197"<td class=\"sha1\">".7198$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),7199class=>"list"},$co{'tree'}) .7200"</td>".7201"<td class=\"link\">".7202$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},7203"tree");7204my$snapshot_links= format_snapshot_links($hash);7205if(defined$snapshot_links) {7206print" | ".$snapshot_links;7207}7208print"</td>".7209"</tr>\n";72107211foreachmy$par(@$parents) {7212print"<tr>".7213"<td>parent</td>".7214"<td class=\"sha1\">".7215$cgi->a({-href => href(action=>"commit", hash=>$par),7216class=>"list"},$par) .7217"</td>".7218"<td class=\"link\">".7219$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .7220" | ".7221$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .7222"</td>".7223"</tr>\n";7224}7225print"</table>".7226"</div>\n";72277228print"<div class=\"page_body\">\n";7229 git_print_log($co{'comment'});7230print"</div>\n";72317232 git_difftree_body(\@difftree,$hash,@$parents);72337234 git_footer_html();7235}72367237sub git_object {7238# object is defined by:7239# - hash or hash_base alone7240# - hash_base and file_name7241my$type;72427243# - hash or hash_base alone7244if($hash|| ($hash_base&& !defined$file_name)) {7245my$object_id=$hash||$hash_base;72467247open my$fd,"-|", quote_command(7248 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'7249or die_error(404,"Object does not exist");7250$type= <$fd>;7251chomp$type;7252close$fd7253or die_error(404,"Object does not exist");72547255# - hash_base and file_name7256}elsif($hash_base&&defined$file_name) {7257$file_name=~ s,/+$,,;72587259system(git_cmd(),"cat-file",'-e',$hash_base) ==07260or die_error(404,"Base object does not exist");72617262# here errors should not hapen7263open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name7264or die_error(500,"Open git-ls-tree failed");7265my$line= <$fd>;7266close$fd;72677268#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'7269unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {7270 die_error(404,"File or directory for given base does not exist");7271}7272$type=$2;7273$hash=$3;7274}else{7275 die_error(400,"Not enough information to find object");7276}72777278print$cgi->redirect(-uri => href(action=>$type, -full=>1,7279 hash=>$hash, hash_base=>$hash_base,7280 file_name=>$file_name),7281-status =>'302 Found');7282}72837284sub git_blobdiff {7285my$format=shift||'html';7286my$diff_style=$input_params{'diff_style'} ||'inline';72877288my$fd;7289my@difftree;7290my%diffinfo;7291my$expires;72927293# preparing $fd and %diffinfo for git_patchset_body7294# new style URI7295if(defined$hash_base&&defined$hash_parent_base) {7296if(defined$file_name) {7297# read raw output7298open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7299$hash_parent_base,$hash_base,7300"--", (defined$file_parent?$file_parent: ()),$file_name7301or die_error(500,"Open git-diff-tree failed");7302@difftree=map{chomp;$_} <$fd>;7303close$fd7304or die_error(404,"Reading git-diff-tree failed");7305@difftree7306or die_error(404,"Blob diff not found");73077308}elsif(defined$hash&&7309$hash=~/[0-9a-fA-F]{40}/) {7310# try to find filename from $hash73117312# read filtered raw output7313open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7314$hash_parent_base,$hash_base,"--"7315or die_error(500,"Open git-diff-tree failed");7316@difftree=7317# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'7318# $hash == to_id7319grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}7320map{chomp;$_} <$fd>;7321close$fd7322or die_error(404,"Reading git-diff-tree failed");7323@difftree7324or die_error(404,"Blob diff not found");73257326}else{7327 die_error(400,"Missing one of the blob diff parameters");7328}73297330if(@difftree>1) {7331 die_error(400,"Ambiguous blob diff specification");7332}73337334%diffinfo= parse_difftree_raw_line($difftree[0]);7335$file_parent||=$diffinfo{'from_file'} ||$file_name;7336$file_name||=$diffinfo{'to_file'};73377338$hash_parent||=$diffinfo{'from_id'};7339$hash||=$diffinfo{'to_id'};73407341# non-textual hash id's can be cached7342if($hash_base=~m/^[0-9a-fA-F]{40}$/&&7343$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {7344$expires='+1d';7345}73467347# open patch output7348open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7349'-p', ($formateq'html'?"--full-index": ()),7350$hash_parent_base,$hash_base,7351"--", (defined$file_parent?$file_parent: ()),$file_name7352or die_error(500,"Open git-diff-tree failed");7353}73547355# old/legacy style URI -- not generated anymore since 1.4.3.7356if(!%diffinfo) {7357 die_error('404 Not Found',"Missing one of the blob diff parameters")7358}73597360# header7361if($formateq'html') {7362my$formats_nav=7363$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},7364"raw");7365$formats_nav.= diff_style_nav($diff_style);7366 git_header_html(undef,$expires);7367if(defined$hash_base&& (my%co= parse_commit($hash_base))) {7368 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);7369 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);7370}else{7371print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";7372print"<div class=\"title\">".esc_html("$hashvs$hash_parent")."</div>\n";7373}7374if(defined$file_name) {7375 git_print_page_path($file_name,"blob",$hash_base);7376}else{7377print"<div class=\"page_path\"></div>\n";7378}73797380}elsif($formateq'plain') {7381print$cgi->header(7382-type =>'text/plain',7383-charset =>'utf-8',7384-expires =>$expires,7385-content_disposition =>'inline; filename="'."$file_name".'.patch"');73867387print"X-Git-Url: ".$cgi->self_url() ."\n\n";73887389}else{7390 die_error(400,"Unknown blobdiff format");7391}73927393# patch7394if($formateq'html') {7395print"<div class=\"page_body\">\n";73967397 git_patchset_body($fd,$diff_style,7398[ \%diffinfo],$hash_base,$hash_parent_base);7399close$fd;74007401print"</div>\n";# class="page_body"7402 git_footer_html();74037404}else{7405while(my$line= <$fd>) {7406$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;7407$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;74087409print$line;74107411last if$line=~m!^\+\+\+!;7412}7413local$/=undef;7414print<$fd>;7415close$fd;7416}7417}74187419sub git_blobdiff_plain {7420 git_blobdiff('plain');7421}74227423# assumes that it is added as later part of already existing navigation,7424# so it returns "| foo | bar" rather than just "foo | bar"7425sub diff_style_nav {7426my($diff_style,$is_combined) =@_;7427$diff_style||='inline';74287429return""if($is_combined);74307431my@styles= (inline =>'inline','sidebyside'=>'side by side');7432my%styles=@styles;7433@styles=7434@styles[map{$_*2}0..$#styles/2];74357436returnjoin'',7437map{" | ".$_}7438map{7439$_eq$diff_style?$styles{$_} :7440$cgi->a({-href => href(-replay=>1, diff_style =>$_)},$styles{$_})7441}@styles;7442}74437444sub git_commitdiff {7445my%params=@_;7446my$format=$params{-format} ||'html';7447my$diff_style=$input_params{'diff_style'} ||'inline';74487449my($patch_max) = gitweb_get_feature('patches');7450if($formateq'patch') {7451 die_error(403,"Patch view not allowed")unless$patch_max;7452}74537454$hash||=$hash_base||"HEAD";7455my%co= parse_commit($hash)7456or die_error(404,"Unknown commit object");74577458# choose format for commitdiff for merge7459if(!defined$hash_parent&& @{$co{'parents'}} >1) {7460$hash_parent='--cc';7461}7462# we need to prepare $formats_nav before almost any parameter munging7463my$formats_nav;7464if($formateq'html') {7465$formats_nav=7466$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},7467"raw");7468if($patch_max&& @{$co{'parents'}} <=1) {7469$formats_nav.=" | ".7470$cgi->a({-href => href(action=>"patch", -replay=>1)},7471"patch");7472}7473$formats_nav.= diff_style_nav($diff_style, @{$co{'parents'}} >1);74747475if(defined$hash_parent&&7476$hash_parentne'-c'&&$hash_parentne'--cc') {7477# commitdiff with two commits given7478my$hash_parent_short=$hash_parent;7479if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {7480$hash_parent_short=substr($hash_parent,0,7);7481}7482$formats_nav.=7483' (from';7484for(my$i=0;$i< @{$co{'parents'}};$i++) {7485if($co{'parents'}[$i]eq$hash_parent) {7486$formats_nav.=' parent '. ($i+1);7487last;7488}7489}7490$formats_nav.=': '.7491$cgi->a({-href => href(-replay=>1,7492 hash=>$hash_parent, hash_base=>undef)},7493 esc_html($hash_parent_short)) .7494')';7495}elsif(!$co{'parent'}) {7496# --root commitdiff7497$formats_nav.=' (initial)';7498}elsif(scalar@{$co{'parents'}} ==1) {7499# single parent commit7500$formats_nav.=7501' (parent: '.7502$cgi->a({-href => href(-replay=>1,7503 hash=>$co{'parent'}, hash_base=>undef)},7504 esc_html(substr($co{'parent'},0,7))) .7505')';7506}else{7507# merge commit7508if($hash_parenteq'--cc') {7509$formats_nav.=' | '.7510$cgi->a({-href => href(-replay=>1,7511 hash=>$hash, hash_parent=>'-c')},7512'combined');7513}else{# $hash_parent eq '-c'7514$formats_nav.=' | '.7515$cgi->a({-href => href(-replay=>1,7516 hash=>$hash, hash_parent=>'--cc')},7517'compact');7518}7519$formats_nav.=7520' (merge: '.7521join(' ',map{7522$cgi->a({-href => href(-replay=>1,7523 hash=>$_, hash_base=>undef)},7524 esc_html(substr($_,0,7)));7525} @{$co{'parents'}} ) .7526')';7527}7528}75297530my$hash_parent_param=$hash_parent;7531if(!defined$hash_parent_param) {7532# --cc for multiple parents, --root for parentless7533$hash_parent_param=7534@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';7535}75367537# read commitdiff7538my$fd;7539my@difftree;7540if($formateq'html') {7541open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7542"--no-commit-id","--patch-with-raw","--full-index",7543$hash_parent_param,$hash,"--"7544or die_error(500,"Open git-diff-tree failed");75457546while(my$line= <$fd>) {7547chomp$line;7548# empty line ends raw part of diff-tree output7549last unless$line;7550push@difftree,scalar parse_difftree_raw_line($line);7551}75527553}elsif($formateq'plain') {7554open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7555'-p',$hash_parent_param,$hash,"--"7556or die_error(500,"Open git-diff-tree failed");7557}elsif($formateq'patch') {7558# For commit ranges, we limit the output to the number of7559# patches specified in the 'patches' feature.7560# For single commits, we limit the output to a single patch,7561# diverging from the git-format-patch default.7562my@commit_spec= ();7563if($hash_parent) {7564if($patch_max>0) {7565push@commit_spec,"-$patch_max";7566}7567push@commit_spec,'-n',"$hash_parent..$hash";7568}else{7569if($params{-single}) {7570push@commit_spec,'-1';7571}else{7572if($patch_max>0) {7573push@commit_spec,"-$patch_max";7574}7575push@commit_spec,"-n";7576}7577push@commit_spec,'--root',$hash;7578}7579open$fd,"-|", git_cmd(),"format-patch",@diff_opts,7580'--encoding=utf8','--stdout',@commit_spec7581or die_error(500,"Open git-format-patch failed");7582}else{7583 die_error(400,"Unknown commitdiff format");7584}75857586# non-textual hash id's can be cached7587my$expires;7588if($hash=~m/^[0-9a-fA-F]{40}$/) {7589$expires="+1d";7590}75917592# write commit message7593if($formateq'html') {7594my$refs= git_get_references();7595my$ref= format_ref_marker($refs,$co{'id'});75967597 git_header_html(undef,$expires);7598 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);7599 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);7600print"<div class=\"title_text\">\n".7601"<table class=\"object_header\">\n";7602 git_print_authorship_rows(\%co);7603print"</table>".7604"</div>\n";7605print"<div class=\"page_body\">\n";7606if(@{$co{'comment'}} >1) {7607print"<div class=\"log\">\n";7608 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);7609print"</div>\n";# class="log"7610}76117612}elsif($formateq'plain') {7613my$refs= git_get_references("tags");7614my$tagname= git_get_rev_name_tags($hash);7615my$filename= basename($project) ."-$hash.patch";76167617print$cgi->header(7618-type =>'text/plain',7619-charset =>'utf-8',7620-expires =>$expires,7621-content_disposition =>'inline; filename="'."$filename".'"');7622my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});7623print"From: ". to_utf8($co{'author'}) ."\n";7624print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";7625print"Subject: ". to_utf8($co{'title'}) ."\n";76267627print"X-Git-Tag:$tagname\n"if$tagname;7628print"X-Git-Url: ".$cgi->self_url() ."\n\n";76297630foreachmy$line(@{$co{'comment'}}) {7631print to_utf8($line) ."\n";7632}7633print"---\n\n";7634}elsif($formateq'patch') {7635my$filename= basename($project) ."-$hash.patch";76367637print$cgi->header(7638-type =>'text/plain',7639-charset =>'utf-8',7640-expires =>$expires,7641-content_disposition =>'inline; filename="'."$filename".'"');7642}76437644# write patch7645if($formateq'html') {7646my$use_parents= !defined$hash_parent||7647$hash_parenteq'-c'||$hash_parenteq'--cc';7648 git_difftree_body(\@difftree,$hash,7649$use_parents? @{$co{'parents'}} :$hash_parent);7650print"<br/>\n";76517652 git_patchset_body($fd,$diff_style,7653 \@difftree,$hash,7654$use_parents? @{$co{'parents'}} :$hash_parent);7655close$fd;7656print"</div>\n";# class="page_body"7657 git_footer_html();76587659}elsif($formateq'plain') {7660local$/=undef;7661print<$fd>;7662close$fd7663or print"Reading git-diff-tree failed\n";7664}elsif($formateq'patch') {7665local$/=undef;7666print<$fd>;7667close$fd7668or print"Reading git-format-patch failed\n";7669}7670}76717672sub git_commitdiff_plain {7673 git_commitdiff(-format =>'plain');7674}76757676# format-patch-style patches7677sub git_patch {7678 git_commitdiff(-format =>'patch', -single =>1);7679}76807681sub git_patches {7682 git_commitdiff(-format =>'patch');7683}76847685sub git_history {7686 git_log_generic('history', \&git_history_body,7687$hash_base,$hash_parent_base,7688$file_name,$hash);7689}76907691sub git_search {7692$searchtype||='commit';76937694# check if appropriate features are enabled7695 gitweb_check_feature('search')7696or die_error(403,"Search is disabled");7697if($searchtypeeq'pickaxe') {7698# pickaxe may take all resources of your box and run for several minutes7699# with every query - so decide by yourself how public you make this feature7700 gitweb_check_feature('pickaxe')7701or die_error(403,"Pickaxe search is disabled");7702}7703if($searchtypeeq'grep') {7704# grep search might be potentially CPU-intensive, too7705 gitweb_check_feature('grep')7706or die_error(403,"Grep search is disabled");7707}77087709if(!defined$searchtext) {7710 die_error(400,"Text field is empty");7711}7712if(!defined$hash) {7713$hash= git_get_head_hash($project);7714}7715my%co= parse_commit($hash);7716if(!%co) {7717 die_error(404,"Unknown commit object");7718}7719if(!defined$page) {7720$page=0;7721}77227723if($searchtypeeq'commit'||7724$searchtypeeq'author'||7725$searchtypeeq'committer') {7726 git_search_message(%co);7727}elsif($searchtypeeq'pickaxe') {7728 git_search_changes(%co);7729}elsif($searchtypeeq'grep') {7730 git_search_files(%co);7731}else{7732 die_error(400,"Unknown search type");7733}7734}77357736sub git_search_help {7737 git_header_html();7738 git_print_page_nav('','',$hash,$hash,$hash);7739print<<EOT;7740<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without7741regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,7742the pattern entered is recognized as the POSIX extended7743<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case7744insensitive).</p>7745<dl>7746<dt><b>commit</b></dt>7747<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>7748EOT7749my$have_grep= gitweb_check_feature('grep');7750if($have_grep) {7751print<<EOT;7752<dt><b>grep</b></dt>7753<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing7754 a different one) are searched for the given pattern. On large trees, this search can take7755a while and put some strain on the server, so please use it with some consideration. Note that7756due to git-grep peculiarity, currently if regexp mode is turned off, the matches are7757case-sensitive.</dd>7758EOT7759}7760print<<EOT;7761<dt><b>author</b></dt>7762<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>7763<dt><b>committer</b></dt>7764<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>7765EOT7766my$have_pickaxe= gitweb_check_feature('pickaxe');7767if($have_pickaxe) {7768print<<EOT;7769<dt><b>pickaxe</b></dt>7770<dd>All commits that caused the string to appear or disappear from any file (changes that7771added, removed or "modified" the string) will be listed. This search can take a while and7772takes a lot of strain on the server, so please use it wisely. Note that since you may be7773interested even in changes just changing the case as well, this search is case sensitive.</dd>7774EOT7775}7776print"</dl>\n";7777 git_footer_html();7778}77797780sub git_shortlog {7781 git_log_generic('shortlog', \&git_shortlog_body,7782$hash,$hash_parent);7783}77847785## ......................................................................7786## feeds (RSS, Atom; OPML)77877788sub git_feed {7789my$format=shift||'atom';7790my$have_blame= gitweb_check_feature('blame');77917792# Atom: http://www.atomenabled.org/developers/syndication/7793# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ7794if($formatne'rss'&&$formatne'atom') {7795 die_error(400,"Unknown web feed format");7796}77977798# log/feed of current (HEAD) branch, log of given branch, history of file/directory7799my$head=$hash||'HEAD';7800my@commitlist= parse_commits($head,150,0,$file_name);78017802my%latest_commit;7803my%latest_date;7804my$content_type="application/$format+xml";7805if(defined$cgi->http('HTTP_ACCEPT') &&7806$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {7807# browser (feed reader) prefers text/xml7808$content_type='text/xml';7809}7810if(defined($commitlist[0])) {7811%latest_commit= %{$commitlist[0]};7812my$latest_epoch=$latest_commit{'committer_epoch'};7813%latest_date= parse_date($latest_epoch,$latest_commit{'comitter_tz'});7814my$if_modified=$cgi->http('IF_MODIFIED_SINCE');7815if(defined$if_modified) {7816my$since;7817if(eval{require HTTP::Date;1; }) {7818$since= HTTP::Date::str2time($if_modified);7819}elsif(eval{require Time::ParseDate;1; }) {7820$since= Time::ParseDate::parsedate($if_modified, GMT =>1);7821}7822if(defined$since&&$latest_epoch<=$since) {7823print$cgi->header(7824-type =>$content_type,7825-charset =>'utf-8',7826-last_modified =>$latest_date{'rfc2822'},7827-status =>'304 Not Modified');7828return;7829}7830}7831print$cgi->header(7832-type =>$content_type,7833-charset =>'utf-8',7834-last_modified =>$latest_date{'rfc2822'});7835}else{7836print$cgi->header(7837-type =>$content_type,7838-charset =>'utf-8');7839}78407841# Optimization: skip generating the body if client asks only7842# for Last-Modified date.7843return if($cgi->request_method()eq'HEAD');78447845# header variables7846my$title="$site_name-$project/$action";7847my$feed_type='log';7848if(defined$hash) {7849$title.=" - '$hash'";7850$feed_type='branch log';7851if(defined$file_name) {7852$title.=" ::$file_name";7853$feed_type='history';7854}7855}elsif(defined$file_name) {7856$title.=" -$file_name";7857$feed_type='history';7858}7859$title.="$feed_type";7860my$descr= git_get_project_description($project);7861if(defined$descr) {7862$descr= esc_html($descr);7863}else{7864$descr="$project".7865($formateq'rss'?'RSS':'Atom') .7866" feed";7867}7868my$owner= git_get_project_owner($project);7869$owner= esc_html($owner);78707871#header7872my$alt_url;7873if(defined$file_name) {7874$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);7875}elsif(defined$hash) {7876$alt_url= href(-full=>1, action=>"log", hash=>$hash);7877}else{7878$alt_url= href(-full=>1, action=>"summary");7879}7880print qq!<?xml version="1.0" encoding="utf-8"?>\n!;7881if($formateq'rss') {7882print<<XML;7883<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">7884<channel>7885XML7886print"<title>$title</title>\n".7887"<link>$alt_url</link>\n".7888"<description>$descr</description>\n".7889"<language>en</language>\n".7890# project owner is responsible for 'editorial' content7891"<managingEditor>$owner</managingEditor>\n";7892if(defined$logo||defined$favicon) {7893# prefer the logo to the favicon, since RSS7894# doesn't allow both7895my$img= esc_url($logo||$favicon);7896print"<image>\n".7897"<url>$img</url>\n".7898"<title>$title</title>\n".7899"<link>$alt_url</link>\n".7900"</image>\n";7901}7902if(%latest_date) {7903print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";7904print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";7905}7906print"<generator>gitweb v.$version/$git_version</generator>\n";7907}elsif($formateq'atom') {7908print<<XML;7909<feed xmlns="http://www.w3.org/2005/Atom">7910XML7911print"<title>$title</title>\n".7912"<subtitle>$descr</subtitle>\n".7913'<link rel="alternate" type="text/html" href="'.7914$alt_url.'" />'."\n".7915'<link rel="self" type="'.$content_type.'" href="'.7916$cgi->self_url() .'" />'."\n".7917"<id>". href(-full=>1) ."</id>\n".7918# use project owner for feed author7919"<author><name>$owner</name></author>\n";7920if(defined$favicon) {7921print"<icon>". esc_url($favicon) ."</icon>\n";7922}7923if(defined$logo) {7924# not twice as wide as tall: 72 x 27 pixels7925print"<logo>". esc_url($logo) ."</logo>\n";7926}7927if(!%latest_date) {7928# dummy date to keep the feed valid until commits trickle in:7929print"<updated>1970-01-01T00:00:00Z</updated>\n";7930}else{7931print"<updated>$latest_date{'iso-8601'}</updated>\n";7932}7933print"<generator version='$version/$git_version'>gitweb</generator>\n";7934}79357936# contents7937for(my$i=0;$i<=$#commitlist;$i++) {7938my%co= %{$commitlist[$i]};7939my$commit=$co{'id'};7940# we read 150, we always show 30 and the ones more recent than 48 hours7941if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {7942last;7943}7944my%cd= parse_date($co{'author_epoch'},$co{'author_tz'});79457946# get list of changed files7947open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7948$co{'parent'} ||"--root",7949$co{'id'},"--", (defined$file_name?$file_name: ())7950ornext;7951my@difftree=map{chomp;$_} <$fd>;7952close$fd7953ornext;79547955# print element (entry, item)7956my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);7957if($formateq'rss') {7958print"<item>\n".7959"<title>". esc_html($co{'title'}) ."</title>\n".7960"<author>". esc_html($co{'author'}) ."</author>\n".7961"<pubDate>$cd{'rfc2822'}</pubDate>\n".7962"<guid isPermaLink=\"true\">$co_url</guid>\n".7963"<link>$co_url</link>\n".7964"<description>". esc_html($co{'title'}) ."</description>\n".7965"<content:encoded>".7966"<![CDATA[\n";7967}elsif($formateq'atom') {7968print"<entry>\n".7969"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".7970"<updated>$cd{'iso-8601'}</updated>\n".7971"<author>\n".7972" <name>". esc_html($co{'author_name'}) ."</name>\n";7973if($co{'author_email'}) {7974print" <email>". esc_html($co{'author_email'}) ."</email>\n";7975}7976print"</author>\n".7977# use committer for contributor7978"<contributor>\n".7979" <name>". esc_html($co{'committer_name'}) ."</name>\n";7980if($co{'committer_email'}) {7981print" <email>". esc_html($co{'committer_email'}) ."</email>\n";7982}7983print"</contributor>\n".7984"<published>$cd{'iso-8601'}</published>\n".7985"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".7986"<id>$co_url</id>\n".7987"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".7988"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";7989}7990my$comment=$co{'comment'};7991print"<pre>\n";7992foreachmy$line(@$comment) {7993$line= esc_html($line);7994print"$line\n";7995}7996print"</pre><ul>\n";7997foreachmy$difftree_line(@difftree) {7998my%difftree= parse_difftree_raw_line($difftree_line);7999next if!$difftree{'from_id'};80008001my$file=$difftree{'file'} ||$difftree{'to_file'};80028003print"<li>".8004"[".8005$cgi->a({-href => href(-full=>1, action=>"blobdiff",8006 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},8007 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},8008 file_name=>$file, file_parent=>$difftree{'from_file'}),8009-title =>"diff"},'D');8010if($have_blame) {8011print$cgi->a({-href => href(-full=>1, action=>"blame",8012 file_name=>$file, hash_base=>$commit),8013-title =>"blame"},'B');8014}8015# if this is not a feed of a file history8016if(!defined$file_name||$file_namene$file) {8017print$cgi->a({-href => href(-full=>1, action=>"history",8018 file_name=>$file, hash=>$commit),8019-title =>"history"},'H');8020}8021$file= esc_path($file);8022print"] ".8023"$file</li>\n";8024}8025if($formateq'rss') {8026print"</ul>]]>\n".8027"</content:encoded>\n".8028"</item>\n";8029}elsif($formateq'atom') {8030print"</ul>\n</div>\n".8031"</content>\n".8032"</entry>\n";8033}8034}80358036# end of feed8037if($formateq'rss') {8038print"</channel>\n</rss>\n";8039}elsif($formateq'atom') {8040print"</feed>\n";8041}8042}80438044sub git_rss {8045 git_feed('rss');8046}80478048sub git_atom {8049 git_feed('atom');8050}80518052sub git_opml {8053my@list= git_get_projects_list($project_filter,$strict_export);8054if(!@list) {8055 die_error(404,"No projects found");8056}80578058print$cgi->header(8059-type =>'text/xml',8060-charset =>'utf-8',8061-content_disposition =>'inline; filename="opml.xml"');80628063my$title= esc_html($site_name);8064my$filter=" within subdirectory ";8065if(defined$project_filter) {8066$filter.= esc_html($project_filter);8067}else{8068$filter="";8069}8070print<<XML;8071<?xml version="1.0" encoding="utf-8"?>8072<opml version="1.0">8073<head>8074 <title>$titleOPML Export$filter</title>8075</head>8076<body>8077<outline text="git RSS feeds">8078XML80798080foreachmy$pr(@list) {8081my%proj=%$pr;8082my$head= git_get_head_hash($proj{'path'});8083if(!defined$head) {8084next;8085}8086$git_dir="$projectroot/$proj{'path'}";8087my%co= parse_commit($head);8088if(!%co) {8089next;8090}80918092my$path= esc_html(chop_str($proj{'path'},25,5));8093my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);8094my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);8095print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";8096}8097print<<XML;8098</outline>8099</body>8100</opml>8101XML8102}