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) { 57# $path_info has already been URL-decoded by the web server, but 58# $my_url and $my_uri have not. URL-decode them so we can properly 59# strip $path_info. 60$my_url= unescape($my_url); 61$my_uri= unescape($my_uri); 62if($my_url=~ s,\Q$path_info\E$,, && 63$my_uri=~ s,\Q$path_info\E$,, && 64defined$ENV{'SCRIPT_NAME'}) { 65$base_url=$cgi->url(-base =>1) .$ENV{'SCRIPT_NAME'}; 66} 67} 68 69# target of the home link on top of all pages 70our$home_link=$my_uri||"/"; 71} 72 73# core git executable to use 74# this can just be "git" if your webserver has a sensible PATH 75our$GIT="++GIT_BINDIR++/git"; 76 77# absolute fs-path which will be prepended to the project path 78#our $projectroot = "/pub/scm"; 79our$projectroot="++GITWEB_PROJECTROOT++"; 80 81# fs traversing limit for getting project list 82# the number is relative to the projectroot 83our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 84 85# string of the home link on top of all pages 86our$home_link_str="++GITWEB_HOME_LINK_STR++"; 87 88# name of your site or organization to appear in page titles 89# replace this with something more descriptive for clearer bookmarks 90our$site_name="++GITWEB_SITENAME++" 91|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 92 93# html snippet to include in the <head> section of each page 94our$site_html_head_string="++GITWEB_SITE_HTML_HEAD_STRING++"; 95# filename of html text to include at top of each page 96our$site_header="++GITWEB_SITE_HEADER++"; 97# html text to include at home page 98our$home_text="++GITWEB_HOMETEXT++"; 99# filename of html text to include at bottom of each page 100our$site_footer="++GITWEB_SITE_FOOTER++"; 101 102# URI of stylesheets 103our@stylesheets= ("++GITWEB_CSS++"); 104# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 105our$stylesheet=undef; 106# URI of GIT logo (72x27 size) 107our$logo="++GITWEB_LOGO++"; 108# URI of GIT favicon, assumed to be image/png type 109our$favicon="++GITWEB_FAVICON++"; 110# URI of gitweb.js (JavaScript code for gitweb) 111our$javascript="++GITWEB_JS++"; 112 113# URI and label (title) of GIT logo link 114#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 115#our $logo_label = "git documentation"; 116our$logo_url="http://git-scm.com/"; 117our$logo_label="git homepage"; 118 119# source of projects list 120our$projects_list="++GITWEB_LIST++"; 121 122# the width (in characters) of the projects list "Description" column 123our$projects_list_description_width=25; 124 125# group projects by category on the projects list 126# (enabled if this variable evaluates to true) 127our$projects_list_group_categories=0; 128 129# default category if none specified 130# (leave the empty string for no category) 131our$project_list_default_category=""; 132 133# default order of projects list 134# valid values are none, project, descr, owner, and age 135our$default_projects_order="project"; 136 137# show repository only if this file exists 138# (only effective if this variable evaluates to true) 139our$export_ok="++GITWEB_EXPORT_OK++"; 140 141# show repository only if this subroutine returns true 142# when given the path to the project, for example: 143# sub { return -e "$_[0]/git-daemon-export-ok"; } 144our$export_auth_hook=undef; 145 146# only allow viewing of repositories also shown on the overview page 147our$strict_export="++GITWEB_STRICT_EXPORT++"; 148 149# list of git base URLs used for URL to where fetch project from, 150# i.e. full URL is "$git_base_url/$project" 151our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 152 153# default blob_plain mimetype and default charset for text/plain blob 154our$default_blob_plain_mimetype='text/plain'; 155our$default_text_plain_charset=undef; 156 157# file to use for guessing MIME types before trying /etc/mime.types 158# (relative to the current git repository) 159our$mimetypes_file=undef; 160 161# assume this charset if line contains non-UTF-8 characters; 162# it should be valid encoding (see Encoding::Supported(3pm) for list), 163# for which encoding all byte sequences are valid, for example 164# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 165# could be even 'utf-8' for the old behavior) 166our$fallback_encoding='latin1'; 167 168# rename detection options for git-diff and git-diff-tree 169# - default is '-M', with the cost proportional to 170# (number of removed files) * (number of new files). 171# - more costly is '-C' (which implies '-M'), with the cost proportional to 172# (number of changed files + number of removed files) * (number of new files) 173# - even more costly is '-C', '--find-copies-harder' with cost 174# (number of files in the original tree) * (number of new files) 175# - one might want to include '-B' option, e.g. '-B', '-M' 176our@diff_opts= ('-M');# taken from git_commit 177 178# Disables features that would allow repository owners to inject script into 179# the gitweb domain. 180our$prevent_xss=0; 181 182# Path to the highlight executable to use (must be the one from 183# http://www.andre-simon.de due to assumptions about parameters and output). 184# Useful if highlight is not installed on your webserver's PATH. 185# [Default: highlight] 186our$highlight_bin="++HIGHLIGHT_BIN++"; 187 188# information about snapshot formats that gitweb is capable of serving 189our%known_snapshot_formats= ( 190# name => { 191# 'display' => display name, 192# 'type' => mime type, 193# 'suffix' => filename suffix, 194# 'format' => --format for git-archive, 195# 'compressor' => [compressor command and arguments] 196# (array reference, optional) 197# 'disabled' => boolean (optional)} 198# 199'tgz'=> { 200'display'=>'tar.gz', 201'type'=>'application/x-gzip', 202'suffix'=>'.tar.gz', 203'format'=>'tar', 204'compressor'=> ['gzip','-n']}, 205 206'tbz2'=> { 207'display'=>'tar.bz2', 208'type'=>'application/x-bzip2', 209'suffix'=>'.tar.bz2', 210'format'=>'tar', 211'compressor'=> ['bzip2']}, 212 213'txz'=> { 214'display'=>'tar.xz', 215'type'=>'application/x-xz', 216'suffix'=>'.tar.xz', 217'format'=>'tar', 218'compressor'=> ['xz'], 219'disabled'=>1}, 220 221'zip'=> { 222'display'=>'zip', 223'type'=>'application/x-zip', 224'suffix'=>'.zip', 225'format'=>'zip'}, 226); 227 228# Aliases so we understand old gitweb.snapshot values in repository 229# configuration. 230our%known_snapshot_format_aliases= ( 231'gzip'=>'tgz', 232'bzip2'=>'tbz2', 233'xz'=>'txz', 234 235# backward compatibility: legacy gitweb config support 236'x-gzip'=>undef,'gz'=>undef, 237'x-bzip2'=>undef,'bz2'=>undef, 238'x-zip'=>undef,''=>undef, 239); 240 241# Pixel sizes for icons and avatars. If the default font sizes or lineheights 242# are changed, it may be appropriate to change these values too via 243# $GITWEB_CONFIG. 244our%avatar_size= ( 245'default'=>16, 246'double'=>32 247); 248 249# Used to set the maximum load that we will still respond to gitweb queries. 250# If server load exceed this value then return "503 server busy" error. 251# If gitweb cannot determined server load, it is taken to be 0. 252# Leave it undefined (or set to 'undef') to turn off load checking. 253our$maxload=300; 254 255# configuration for 'highlight' (http://www.andre-simon.de/) 256# match by basename 257our%highlight_basename= ( 258#'Program' => 'py', 259#'Library' => 'py', 260'SConstruct'=>'py',# SCons equivalent of Makefile 261'Makefile'=>'make', 262); 263# match by extension 264our%highlight_ext= ( 265# main extensions, defining name of syntax; 266# see files in /usr/share/highlight/langDefs/ directory 267map{$_=>$_} 268qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl sql make), 269# alternate extensions, see /etc/highlight/filetypes.conf 270'h'=>'c', 271map{$_=>'sh'}qw(bash zsh ksh), 272map{$_=>'cpp'}qw(cxx c++ cc), 273map{$_=>'php'}qw(php3 php4 php5 phps), 274map{$_=>'pl'}qw(perl pm),# perhaps also 'cgi' 275map{$_=>'make'}qw(mak mk), 276map{$_=>'xml'}qw(xhtml html htm), 277); 278 279# You define site-wide feature defaults here; override them with 280# $GITWEB_CONFIG as necessary. 281our%feature= ( 282# feature => { 283# 'sub' => feature-sub (subroutine), 284# 'override' => allow-override (boolean), 285# 'default' => [ default options...] (array reference)} 286# 287# if feature is overridable (it means that allow-override has true value), 288# then feature-sub will be called with default options as parameters; 289# return value of feature-sub indicates if to enable specified feature 290# 291# if there is no 'sub' key (no feature-sub), then feature cannot be 292# overridden 293# 294# use gitweb_get_feature(<feature>) to retrieve the <feature> value 295# (an array) or gitweb_check_feature(<feature>) to check if <feature> 296# is enabled 297 298# Enable the 'blame' blob view, showing the last commit that modified 299# each line in the file. This can be very CPU-intensive. 300 301# To enable system wide have in $GITWEB_CONFIG 302# $feature{'blame'}{'default'} = [1]; 303# To have project specific config enable override in $GITWEB_CONFIG 304# $feature{'blame'}{'override'} = 1; 305# and in project config gitweb.blame = 0|1; 306'blame'=> { 307'sub'=>sub{ feature_bool('blame',@_) }, 308'override'=>0, 309'default'=> [0]}, 310 311# Enable the 'snapshot' link, providing a compressed archive of any 312# tree. This can potentially generate high traffic if you have large 313# project. 314 315# Value is a list of formats defined in %known_snapshot_formats that 316# you wish to offer. 317# To disable system wide have in $GITWEB_CONFIG 318# $feature{'snapshot'}{'default'} = []; 319# To have project specific config enable override in $GITWEB_CONFIG 320# $feature{'snapshot'}{'override'} = 1; 321# and in project config, a comma-separated list of formats or "none" 322# to disable. Example: gitweb.snapshot = tbz2,zip; 323'snapshot'=> { 324'sub'=> \&feature_snapshot, 325'override'=>0, 326'default'=> ['tgz']}, 327 328# Enable text search, which will list the commits which match author, 329# committer or commit text to a given string. Enabled by default. 330# Project specific override is not supported. 331# 332# Note that this controls all search features, which means that if 333# it is disabled, then 'grep' and 'pickaxe' search would also be 334# disabled. 335'search'=> { 336'override'=>0, 337'default'=> [1]}, 338 339# Enable grep search, which will list the files in currently selected 340# tree containing the given string. Enabled by default. This can be 341# potentially CPU-intensive, of course. 342# Note that you need to have 'search' feature enabled too. 343 344# To enable system wide have in $GITWEB_CONFIG 345# $feature{'grep'}{'default'} = [1]; 346# To have project specific config enable override in $GITWEB_CONFIG 347# $feature{'grep'}{'override'} = 1; 348# and in project config gitweb.grep = 0|1; 349'grep'=> { 350'sub'=>sub{ feature_bool('grep',@_) }, 351'override'=>0, 352'default'=> [1]}, 353 354# Enable the pickaxe search, which will list the commits that modified 355# a given string in a file. This can be practical and quite faster 356# alternative to 'blame', but still potentially CPU-intensive. 357# Note that you need to have 'search' feature enabled too. 358 359# To enable system wide have in $GITWEB_CONFIG 360# $feature{'pickaxe'}{'default'} = [1]; 361# To have project specific config enable override in $GITWEB_CONFIG 362# $feature{'pickaxe'}{'override'} = 1; 363# and in project config gitweb.pickaxe = 0|1; 364'pickaxe'=> { 365'sub'=>sub{ feature_bool('pickaxe',@_) }, 366'override'=>0, 367'default'=> [1]}, 368 369# Enable showing size of blobs in a 'tree' view, in a separate 370# column, similar to what 'ls -l' does. This cost a bit of IO. 371 372# To disable system wide have in $GITWEB_CONFIG 373# $feature{'show-sizes'}{'default'} = [0]; 374# To have project specific config enable override in $GITWEB_CONFIG 375# $feature{'show-sizes'}{'override'} = 1; 376# and in project config gitweb.showsizes = 0|1; 377'show-sizes'=> { 378'sub'=>sub{ feature_bool('showsizes',@_) }, 379'override'=>0, 380'default'=> [1]}, 381 382# Make gitweb use an alternative format of the URLs which can be 383# more readable and natural-looking: project name is embedded 384# directly in the path and the query string contains other 385# auxiliary information. All gitweb installations recognize 386# URL in either format; this configures in which formats gitweb 387# generates links. 388 389# To enable system wide have in $GITWEB_CONFIG 390# $feature{'pathinfo'}{'default'} = [1]; 391# Project specific override is not supported. 392 393# Note that you will need to change the default location of CSS, 394# favicon, logo and possibly other files to an absolute URL. Also, 395# if gitweb.cgi serves as your indexfile, you will need to force 396# $my_uri to contain the script name in your $GITWEB_CONFIG. 397'pathinfo'=> { 398'override'=>0, 399'default'=> [0]}, 400 401# Make gitweb consider projects in project root subdirectories 402# to be forks of existing projects. Given project $projname.git, 403# projects matching $projname/*.git will not be shown in the main 404# projects list, instead a '+' mark will be added to $projname 405# there and a 'forks' view will be enabled for the project, listing 406# all the forks. If project list is taken from a file, forks have 407# to be listed after the main project. 408 409# To enable system wide have in $GITWEB_CONFIG 410# $feature{'forks'}{'default'} = [1]; 411# Project specific override is not supported. 412'forks'=> { 413'override'=>0, 414'default'=> [0]}, 415 416# Insert custom links to the action bar of all project pages. 417# This enables you mainly to link to third-party scripts integrating 418# into gitweb; e.g. git-browser for graphical history representation 419# or custom web-based repository administration interface. 420 421# The 'default' value consists of a list of triplets in the form 422# (label, link, position) where position is the label after which 423# to insert the link and link is a format string where %n expands 424# to the project name, %f to the project path within the filesystem, 425# %h to the current hash (h gitweb parameter) and %b to the current 426# hash base (hb gitweb parameter); %% expands to %. 427 428# To enable system wide have in $GITWEB_CONFIG e.g. 429# $feature{'actions'}{'default'} = [('graphiclog', 430# '/git-browser/by-commit.html?r=%n', 'summary')]; 431# Project specific override is not supported. 432'actions'=> { 433'override'=>0, 434'default'=> []}, 435 436# Allow gitweb scan project content tags of project repository, 437# and display the popular Web 2.0-ish "tag cloud" near the projects 438# list. Note that this is something COMPLETELY different from the 439# normal Git tags. 440 441# gitweb by itself can show existing tags, but it does not handle 442# tagging itself; you need to do it externally, outside gitweb. 443# The format is described in git_get_project_ctags() subroutine. 444# You may want to install the HTML::TagCloud Perl module to get 445# a pretty tag cloud instead of just a list of tags. 446 447# To enable system wide have in $GITWEB_CONFIG 448# $feature{'ctags'}{'default'} = [1]; 449# Project specific override is not supported. 450 451# In the future whether ctags editing is enabled might depend 452# on the value, but using 1 should always mean no editing of ctags. 453'ctags'=> { 454'override'=>0, 455'default'=> [0]}, 456 457# The maximum number of patches in a patchset generated in patch 458# view. Set this to 0 or undef to disable patch view, or to a 459# negative number to remove any limit. 460 461# To disable system wide have in $GITWEB_CONFIG 462# $feature{'patches'}{'default'} = [0]; 463# To have project specific config enable override in $GITWEB_CONFIG 464# $feature{'patches'}{'override'} = 1; 465# and in project config gitweb.patches = 0|n; 466# where n is the maximum number of patches allowed in a patchset. 467'patches'=> { 468'sub'=> \&feature_patches, 469'override'=>0, 470'default'=> [16]}, 471 472# Avatar support. When this feature is enabled, views such as 473# shortlog or commit will display an avatar associated with 474# the email of the committer(s) and/or author(s). 475 476# Currently available providers are gravatar and picon. 477# If an unknown provider is specified, the feature is disabled. 478 479# Gravatar depends on Digest::MD5. 480# Picon currently relies on the indiana.edu database. 481 482# To enable system wide have in $GITWEB_CONFIG 483# $feature{'avatar'}{'default'} = ['<provider>']; 484# where <provider> is either gravatar or picon. 485# To have project specific config enable override in $GITWEB_CONFIG 486# $feature{'avatar'}{'override'} = 1; 487# and in project config gitweb.avatar = <provider>; 488'avatar'=> { 489'sub'=> \&feature_avatar, 490'override'=>0, 491'default'=> ['']}, 492 493# Enable displaying how much time and how many git commands 494# it took to generate and display page. Disabled by default. 495# Project specific override is not supported. 496'timed'=> { 497'override'=>0, 498'default'=> [0]}, 499 500# Enable turning some links into links to actions which require 501# JavaScript to run (like 'blame_incremental'). Not enabled by 502# default. Project specific override is currently not supported. 503'javascript-actions'=> { 504'override'=>0, 505'default'=> [0]}, 506 507# Enable and configure ability to change common timezone for dates 508# in gitweb output via JavaScript. Enabled by default. 509# Project specific override is not supported. 510'javascript-timezone'=> { 511'override'=>0, 512'default'=> [ 513'local',# default timezone: 'utc', 'local', or '(-|+)HHMM' format, 514# or undef to turn off this feature 515'gitweb_tz',# name of cookie where to store selected timezone 516'datetime',# CSS class used to mark up dates for manipulation 517]}, 518 519# Syntax highlighting support. This is based on Daniel Svensson's 520# and Sham Chukoury's work in gitweb-xmms2.git. 521# It requires the 'highlight' program present in $PATH, 522# and therefore is disabled by default. 523 524# To enable system wide have in $GITWEB_CONFIG 525# $feature{'highlight'}{'default'} = [1]; 526 527'highlight'=> { 528'sub'=>sub{ feature_bool('highlight',@_) }, 529'override'=>0, 530'default'=> [0]}, 531 532# Enable displaying of remote heads in the heads list 533 534# To enable system wide have in $GITWEB_CONFIG 535# $feature{'remote_heads'}{'default'} = [1]; 536# To have project specific config enable override in $GITWEB_CONFIG 537# $feature{'remote_heads'}{'override'} = 1; 538# and in project config gitweb.remote_heads = 0|1; 539'remote_heads'=> { 540'sub'=>sub{ feature_bool('remote_heads',@_) }, 541'override'=>0, 542'default'=> [0]}, 543); 544 545sub gitweb_get_feature { 546my($name) =@_; 547return unlessexists$feature{$name}; 548my($sub,$override,@defaults) = ( 549$feature{$name}{'sub'}, 550$feature{$name}{'override'}, 551@{$feature{$name}{'default'}}); 552# project specific override is possible only if we have project 553our$git_dir;# global variable, declared later 554if(!$override|| !defined$git_dir) { 555return@defaults; 556} 557if(!defined$sub) { 558warn"feature$nameis not overridable"; 559return@defaults; 560} 561return$sub->(@defaults); 562} 563 564# A wrapper to check if a given feature is enabled. 565# With this, you can say 566# 567# my $bool_feat = gitweb_check_feature('bool_feat'); 568# gitweb_check_feature('bool_feat') or somecode; 569# 570# instead of 571# 572# my ($bool_feat) = gitweb_get_feature('bool_feat'); 573# (gitweb_get_feature('bool_feat'))[0] or somecode; 574# 575sub gitweb_check_feature { 576return(gitweb_get_feature(@_))[0]; 577} 578 579 580sub feature_bool { 581my$key=shift; 582my($val) = git_get_project_config($key,'--bool'); 583 584if(!defined$val) { 585return($_[0]); 586}elsif($valeq'true') { 587return(1); 588}elsif($valeq'false') { 589return(0); 590} 591} 592 593sub feature_snapshot { 594my(@fmts) =@_; 595 596my($val) = git_get_project_config('snapshot'); 597 598if($val) { 599@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 600} 601 602return@fmts; 603} 604 605sub feature_patches { 606my@val= (git_get_project_config('patches','--int')); 607 608if(@val) { 609return@val; 610} 611 612return($_[0]); 613} 614 615sub feature_avatar { 616my@val= (git_get_project_config('avatar')); 617 618return@val?@val:@_; 619} 620 621# checking HEAD file with -e is fragile if the repository was 622# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 623# and then pruned. 624sub check_head_link { 625my($dir) =@_; 626my$headfile="$dir/HEAD"; 627return((-e $headfile) || 628(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 629} 630 631sub check_export_ok { 632my($dir) =@_; 633return(check_head_link($dir) && 634(!$export_ok|| -e "$dir/$export_ok") && 635(!$export_auth_hook||$export_auth_hook->($dir))); 636} 637 638# process alternate names for backward compatibility 639# filter out unsupported (unknown) snapshot formats 640sub filter_snapshot_fmts { 641my@fmts=@_; 642 643@fmts=map{ 644exists$known_snapshot_format_aliases{$_} ? 645$known_snapshot_format_aliases{$_} :$_}@fmts; 646@fmts=grep{ 647exists$known_snapshot_formats{$_} && 648!$known_snapshot_formats{$_}{'disabled'}}@fmts; 649} 650 651# If it is set to code reference, it is code that it is to be run once per 652# request, allowing updating configurations that change with each request, 653# while running other code in config file only once. 654# 655# Otherwise, if it is false then gitweb would process config file only once; 656# if it is true then gitweb config would be run for each request. 657our$per_request_config=1; 658 659# read and parse gitweb config file given by its parameter. 660# returns true on success, false on recoverable error, allowing 661# to chain this subroutine, using first file that exists. 662# dies on errors during parsing config file, as it is unrecoverable. 663sub read_config_file { 664my$filename=shift; 665return unlessdefined$filename; 666# die if there are errors parsing config file 667if(-e $filename) { 668do$filename; 669die$@if$@; 670return1; 671} 672return; 673} 674 675our($GITWEB_CONFIG,$GITWEB_CONFIG_SYSTEM,$GITWEB_CONFIG_COMMON); 676sub evaluate_gitweb_config { 677our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 678our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 679our$GITWEB_CONFIG_COMMON=$ENV{'GITWEB_CONFIG_COMMON'} ||"++GITWEB_CONFIG_COMMON++"; 680 681# Protect agains duplications of file names, to not read config twice. 682# Only one of $GITWEB_CONFIG and $GITWEB_CONFIG_SYSTEM is used, so 683# there possibility of duplication of filename there doesn't matter. 684$GITWEB_CONFIG=""if($GITWEB_CONFIGeq$GITWEB_CONFIG_COMMON); 685$GITWEB_CONFIG_SYSTEM=""if($GITWEB_CONFIG_SYSTEMeq$GITWEB_CONFIG_COMMON); 686 687# Common system-wide settings for convenience. 688# Those settings can be ovverriden by GITWEB_CONFIG or GITWEB_CONFIG_SYSTEM. 689 read_config_file($GITWEB_CONFIG_COMMON); 690 691# Use first config file that exists. This means use the per-instance 692# GITWEB_CONFIG if exists, otherwise use GITWEB_SYSTEM_CONFIG. 693 read_config_file($GITWEB_CONFIG)andreturn; 694 read_config_file($GITWEB_CONFIG_SYSTEM); 695} 696 697# Get loadavg of system, to compare against $maxload. 698# Currently it requires '/proc/loadavg' present to get loadavg; 699# if it is not present it returns 0, which means no load checking. 700sub get_loadavg { 701if( -e '/proc/loadavg'){ 702open my$fd,'<','/proc/loadavg' 703orreturn0; 704my@load=split(/\s+/,scalar<$fd>); 705close$fd; 706 707# The first three columns measure CPU and IO utilization of the last one, 708# five, and 10 minute periods. The fourth column shows the number of 709# currently running processes and the total number of processes in the m/n 710# format. The last column displays the last process ID used. 711return$load[0] ||0; 712} 713# additional checks for load average should go here for things that don't export 714# /proc/loadavg 715 716return0; 717} 718 719# version of the core git binary 720our$git_version; 721sub evaluate_git_version { 722our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 723$number_of_git_cmds++; 724} 725 726sub check_loadavg { 727if(defined$maxload&& get_loadavg() >$maxload) { 728 die_error(503,"The load average on the server is too high"); 729} 730} 731 732# ====================================================================== 733# input validation and dispatch 734 735# input parameters can be collected from a variety of sources (presently, CGI 736# and PATH_INFO), so we define an %input_params hash that collects them all 737# together during validation: this allows subsequent uses (e.g. href()) to be 738# agnostic of the parameter origin 739 740our%input_params= (); 741 742# input parameters are stored with the long parameter name as key. This will 743# also be used in the href subroutine to convert parameters to their CGI 744# equivalent, and since the href() usage is the most frequent one, we store 745# the name -> CGI key mapping here, instead of the reverse. 746# 747# XXX: Warning: If you touch this, check the search form for updating, 748# too. 749 750our@cgi_param_mapping= ( 751 project =>"p", 752 action =>"a", 753 file_name =>"f", 754 file_parent =>"fp", 755 hash =>"h", 756 hash_parent =>"hp", 757 hash_base =>"hb", 758 hash_parent_base =>"hpb", 759 page =>"pg", 760 order =>"o", 761 searchtext =>"s", 762 searchtype =>"st", 763 snapshot_format =>"sf", 764 extra_options =>"opt", 765 search_use_regexp =>"sr", 766 ctag =>"by_tag", 767 diff_style =>"ds", 768 project_filter =>"pf", 769# this must be last entry (for manipulation from JavaScript) 770 javascript =>"js" 771); 772our%cgi_param_mapping=@cgi_param_mapping; 773 774# we will also need to know the possible actions, for validation 775our%actions= ( 776"blame"=> \&git_blame, 777"blame_incremental"=> \&git_blame_incremental, 778"blame_data"=> \&git_blame_data, 779"blobdiff"=> \&git_blobdiff, 780"blobdiff_plain"=> \&git_blobdiff_plain, 781"blob"=> \&git_blob, 782"blob_plain"=> \&git_blob_plain, 783"commitdiff"=> \&git_commitdiff, 784"commitdiff_plain"=> \&git_commitdiff_plain, 785"commit"=> \&git_commit, 786"forks"=> \&git_forks, 787"heads"=> \&git_heads, 788"history"=> \&git_history, 789"log"=> \&git_log, 790"patch"=> \&git_patch, 791"patches"=> \&git_patches, 792"remotes"=> \&git_remotes, 793"rss"=> \&git_rss, 794"atom"=> \&git_atom, 795"search"=> \&git_search, 796"search_help"=> \&git_search_help, 797"shortlog"=> \&git_shortlog, 798"summary"=> \&git_summary, 799"tag"=> \&git_tag, 800"tags"=> \&git_tags, 801"tree"=> \&git_tree, 802"snapshot"=> \&git_snapshot, 803"object"=> \&git_object, 804# those below don't need $project 805"opml"=> \&git_opml, 806"project_list"=> \&git_project_list, 807"project_index"=> \&git_project_index, 808); 809 810# finally, we have the hash of allowed extra_options for the commands that 811# allow them 812our%allowed_options= ( 813"--no-merges"=> [qw(rss atom log shortlog history)], 814); 815 816# fill %input_params with the CGI parameters. All values except for 'opt' 817# should be single values, but opt can be an array. We should probably 818# build an array of parameters that can be multi-valued, but since for the time 819# being it's only this one, we just single it out 820sub evaluate_query_params { 821our$cgi; 822 823while(my($name,$symbol) =each%cgi_param_mapping) { 824if($symboleq'opt') { 825$input_params{$name} = [map{ decode_utf8($_) }$cgi->param($symbol) ]; 826}else{ 827$input_params{$name} = decode_utf8($cgi->param($symbol)); 828} 829} 830} 831 832# now read PATH_INFO and update the parameter list for missing parameters 833sub evaluate_path_info { 834return ifdefined$input_params{'project'}; 835return if!$path_info; 836$path_info=~ s,^/+,,; 837return if!$path_info; 838 839# find which part of PATH_INFO is project 840my$project=$path_info; 841$project=~ s,/+$,,; 842while($project&& !check_head_link("$projectroot/$project")) { 843$project=~ s,/*[^/]*$,,; 844} 845return unless$project; 846$input_params{'project'} =$project; 847 848# do not change any parameters if an action is given using the query string 849return if$input_params{'action'}; 850$path_info=~ s,^\Q$project\E/*,,; 851 852# next, check if we have an action 853my$action=$path_info; 854$action=~ s,/.*$,,; 855if(exists$actions{$action}) { 856$path_info=~ s,^$action/*,,; 857$input_params{'action'} =$action; 858} 859 860# list of actions that want hash_base instead of hash, but can have no 861# pathname (f) parameter 862my@wants_base= ( 863'tree', 864'history', 865); 866 867# we want to catch, among others 868# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 869my($parentrefname,$parentpathname,$refname,$pathname) = 870($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?([^:]+?)?(?::(.+))?$/); 871 872# first, analyze the 'current' part 873if(defined$pathname) { 874# we got "branch:filename" or "branch:dir/" 875# we could use git_get_type(branch:pathname), but: 876# - it needs $git_dir 877# - it does a git() call 878# - the convention of terminating directories with a slash 879# makes it superfluous 880# - embedding the action in the PATH_INFO would make it even 881# more superfluous 882$pathname=~ s,^/+,,; 883if(!$pathname||substr($pathname, -1)eq"/") { 884$input_params{'action'} ||="tree"; 885$pathname=~ s,/$,,; 886}else{ 887# the default action depends on whether we had parent info 888# or not 889if($parentrefname) { 890$input_params{'action'} ||="blobdiff_plain"; 891}else{ 892$input_params{'action'} ||="blob_plain"; 893} 894} 895$input_params{'hash_base'} ||=$refname; 896$input_params{'file_name'} ||=$pathname; 897}elsif(defined$refname) { 898# we got "branch". In this case we have to choose if we have to 899# set hash or hash_base. 900# 901# Most of the actions without a pathname only want hash to be 902# set, except for the ones specified in @wants_base that want 903# hash_base instead. It should also be noted that hand-crafted 904# links having 'history' as an action and no pathname or hash 905# set will fail, but that happens regardless of PATH_INFO. 906if(defined$parentrefname) { 907# if there is parent let the default be 'shortlog' action 908# (for http://git.example.com/repo.git/A..B links); if there 909# is no parent, dispatch will detect type of object and set 910# action appropriately if required (if action is not set) 911$input_params{'action'} ||="shortlog"; 912} 913if($input_params{'action'} && 914grep{$_eq$input_params{'action'} }@wants_base) { 915$input_params{'hash_base'} ||=$refname; 916}else{ 917$input_params{'hash'} ||=$refname; 918} 919} 920 921# next, handle the 'parent' part, if present 922if(defined$parentrefname) { 923# a missing pathspec defaults to the 'current' filename, allowing e.g. 924# someproject/blobdiff/oldrev..newrev:/filename 925if($parentpathname) { 926$parentpathname=~ s,^/+,,; 927$parentpathname=~ s,/$,,; 928$input_params{'file_parent'} ||=$parentpathname; 929}else{ 930$input_params{'file_parent'} ||=$input_params{'file_name'}; 931} 932# we assume that hash_parent_base is wanted if a path was specified, 933# or if the action wants hash_base instead of hash 934if(defined$input_params{'file_parent'} || 935grep{$_eq$input_params{'action'} }@wants_base) { 936$input_params{'hash_parent_base'} ||=$parentrefname; 937}else{ 938$input_params{'hash_parent'} ||=$parentrefname; 939} 940} 941 942# for the snapshot action, we allow URLs in the form 943# $project/snapshot/$hash.ext 944# where .ext determines the snapshot and gets removed from the 945# passed $refname to provide the $hash. 946# 947# To be able to tell that $refname includes the format extension, we 948# require the following two conditions to be satisfied: 949# - the hash input parameter MUST have been set from the $refname part 950# of the URL (i.e. they must be equal) 951# - the snapshot format MUST NOT have been defined already (e.g. from 952# CGI parameter sf) 953# It's also useless to try any matching unless $refname has a dot, 954# so we check for that too 955if(defined$input_params{'action'} && 956$input_params{'action'}eq'snapshot'&& 957defined$refname&&index($refname,'.') != -1&& 958$refnameeq$input_params{'hash'} && 959!defined$input_params{'snapshot_format'}) { 960# We loop over the known snapshot formats, checking for 961# extensions. Allowed extensions are both the defined suffix 962# (which includes the initial dot already) and the snapshot 963# format key itself, with a prepended dot 964while(my($fmt,$opt) =each%known_snapshot_formats) { 965my$hash=$refname; 966unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 967next; 968} 969my$sfx=$1; 970# a valid suffix was found, so set the snapshot format 971# and reset the hash parameter 972$input_params{'snapshot_format'} =$fmt; 973$input_params{'hash'} =$hash; 974# we also set the format suffix to the one requested 975# in the URL: this way a request for e.g. .tgz returns 976# a .tgz instead of a .tar.gz 977$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 978last; 979} 980} 981} 982 983our($action,$project,$file_name,$file_parent,$hash,$hash_parent,$hash_base, 984$hash_parent_base,@extra_options,$page,$searchtype,$search_use_regexp, 985$searchtext,$search_regexp,$project_filter); 986sub evaluate_and_validate_params { 987our$action=$input_params{'action'}; 988if(defined$action) { 989if(!validate_action($action)) { 990 die_error(400,"Invalid action parameter"); 991} 992} 993 994# parameters which are pathnames 995our$project=$input_params{'project'}; 996if(defined$project) { 997if(!validate_project($project)) { 998undef$project; 999 die_error(404,"No such project");1000}1001}10021003our$project_filter=$input_params{'project_filter'};1004if(defined$project_filter) {1005if(!validate_pathname($project_filter)) {1006 die_error(404,"Invalid project_filter parameter");1007}1008}10091010our$file_name=$input_params{'file_name'};1011if(defined$file_name) {1012if(!validate_pathname($file_name)) {1013 die_error(400,"Invalid file parameter");1014}1015}10161017our$file_parent=$input_params{'file_parent'};1018if(defined$file_parent) {1019if(!validate_pathname($file_parent)) {1020 die_error(400,"Invalid file parent parameter");1021}1022}10231024# parameters which are refnames1025our$hash=$input_params{'hash'};1026if(defined$hash) {1027if(!validate_refname($hash)) {1028 die_error(400,"Invalid hash parameter");1029}1030}10311032our$hash_parent=$input_params{'hash_parent'};1033if(defined$hash_parent) {1034if(!validate_refname($hash_parent)) {1035 die_error(400,"Invalid hash parent parameter");1036}1037}10381039our$hash_base=$input_params{'hash_base'};1040if(defined$hash_base) {1041if(!validate_refname($hash_base)) {1042 die_error(400,"Invalid hash base parameter");1043}1044}10451046our@extra_options= @{$input_params{'extra_options'}};1047# @extra_options is always defined, since it can only be (currently) set from1048# CGI, and $cgi->param() returns the empty array in array context if the param1049# is not set1050foreachmy$opt(@extra_options) {1051if(not exists$allowed_options{$opt}) {1052 die_error(400,"Invalid option parameter");1053}1054if(not grep(/^$action$/, @{$allowed_options{$opt}})) {1055 die_error(400,"Invalid option parameter for this action");1056}1057}10581059our$hash_parent_base=$input_params{'hash_parent_base'};1060if(defined$hash_parent_base) {1061if(!validate_refname($hash_parent_base)) {1062 die_error(400,"Invalid hash parent base parameter");1063}1064}10651066# other parameters1067our$page=$input_params{'page'};1068if(defined$page) {1069if($page=~m/[^0-9]/) {1070 die_error(400,"Invalid page parameter");1071}1072}10731074our$searchtype=$input_params{'searchtype'};1075if(defined$searchtype) {1076if($searchtype=~m/[^a-z]/) {1077 die_error(400,"Invalid searchtype parameter");1078}1079}10801081our$search_use_regexp=$input_params{'search_use_regexp'};10821083our$searchtext=$input_params{'searchtext'};1084our$search_regexp;1085if(defined$searchtext) {1086if(length($searchtext) <2) {1087 die_error(403,"At least two characters are required for search parameter");1088}1089if($search_use_regexp) {1090$search_regexp=$searchtext;1091if(!eval{qr/$search_regexp/;1; }) {1092(my$error=$@) =~s/ at \S+ line \d+.*\n?//;1093 die_error(400,"Invalid search regexp '$search_regexp'",1094 esc_html($error));1095}1096}else{1097$search_regexp=quotemeta$searchtext;1098}1099}1100}11011102# path to the current git repository1103our$git_dir;1104sub evaluate_git_dir {1105our$git_dir="$projectroot/$project"if$project;1106}11071108our(@snapshot_fmts,$git_avatar);1109sub configure_gitweb_features {1110# list of supported snapshot formats1111our@snapshot_fmts= gitweb_get_feature('snapshot');1112@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts);11131114# check that the avatar feature is set to a known provider name,1115# and for each provider check if the dependencies are satisfied.1116# if the provider name is invalid or the dependencies are not met,1117# reset $git_avatar to the empty string.1118our($git_avatar) = gitweb_get_feature('avatar');1119if($git_avatareq'gravatar') {1120$git_avatar=''unless(eval{require Digest::MD5;1; });1121}elsif($git_avatareq'picon') {1122# no dependencies1123}else{1124$git_avatar='';1125}1126}11271128# custom error handler: 'die <message>' is Internal Server Error1129sub handle_errors_html {1130my$msg=shift;# it is already HTML escaped11311132# to avoid infinite loop where error occurs in die_error,1133# change handler to default handler, disabling handle_errors_html1134 set_message("Error occured when inside die_error:\n$msg");11351136# you cannot jump out of die_error when called as error handler;1137# the subroutine set via CGI::Carp::set_message is called _after_1138# HTTP headers are already written, so it cannot write them itself1139 die_error(undef,undef,$msg, -error_handler =>1, -no_http_header =>1);1140}1141set_message(\&handle_errors_html);11421143# dispatch1144sub dispatch {1145if(!defined$action) {1146if(defined$hash) {1147$action= git_get_type($hash);1148$actionor die_error(404,"Object does not exist");1149}elsif(defined$hash_base&&defined$file_name) {1150$action= git_get_type("$hash_base:$file_name");1151$actionor die_error(404,"File or directory does not exist");1152}elsif(defined$project) {1153$action='summary';1154}else{1155$action='project_list';1156}1157}1158if(!defined($actions{$action})) {1159 die_error(400,"Unknown action");1160}1161if($action!~m/^(?:opml|project_list|project_index)$/&&1162!$project) {1163 die_error(400,"Project needed");1164}1165$actions{$action}->();1166}11671168sub reset_timer {1169our$t0= [ gettimeofday() ]1170ifdefined$t0;1171our$number_of_git_cmds=0;1172}11731174our$first_request=1;1175sub run_request {1176 reset_timer();11771178 evaluate_uri();1179if($first_request) {1180 evaluate_gitweb_config();1181 evaluate_git_version();1182}1183if($per_request_config) {1184if(ref($per_request_config)eq'CODE') {1185$per_request_config->();1186}elsif(!$first_request) {1187 evaluate_gitweb_config();1188}1189}1190 check_loadavg();11911192# $projectroot and $projects_list might be set in gitweb config file1193$projects_list||=$projectroot;11941195 evaluate_query_params();1196 evaluate_path_info();1197 evaluate_and_validate_params();1198 evaluate_git_dir();11991200 configure_gitweb_features();12011202 dispatch();1203}12041205our$is_last_request=sub{1};1206our($pre_dispatch_hook,$post_dispatch_hook,$pre_listen_hook);1207our$CGI='CGI';1208our$cgi;1209sub configure_as_fcgi {1210require CGI::Fast;1211our$CGI='CGI::Fast';12121213my$request_number=0;1214# let each child service 100 requests1215our$is_last_request=sub{ ++$request_number>100};1216}1217sub evaluate_argv {1218my$script_name=$ENV{'SCRIPT_NAME'} ||$ENV{'SCRIPT_FILENAME'} || __FILE__;1219 configure_as_fcgi()1220if$script_name=~/\.fcgi$/;12211222return unless(@ARGV);12231224require Getopt::Long;1225 Getopt::Long::GetOptions(1226'fastcgi|fcgi|f'=> \&configure_as_fcgi,1227'nproc|n=i'=>sub{1228my($arg,$val) =@_;1229return unlesseval{require FCGI::ProcManager;1; };1230my$proc_manager= FCGI::ProcManager->new({1231 n_processes =>$val,1232});1233our$pre_listen_hook=sub{$proc_manager->pm_manage() };1234our$pre_dispatch_hook=sub{$proc_manager->pm_pre_dispatch() };1235our$post_dispatch_hook=sub{$proc_manager->pm_post_dispatch() };1236},1237);1238}12391240sub run {1241 evaluate_argv();12421243$first_request=1;1244$pre_listen_hook->()1245if$pre_listen_hook;12461247 REQUEST:1248while($cgi=$CGI->new()) {1249$pre_dispatch_hook->()1250if$pre_dispatch_hook;12511252 run_request();12531254$post_dispatch_hook->()1255if$post_dispatch_hook;1256$first_request=0;12571258last REQUEST if($is_last_request->());1259}12601261 DONE_GITWEB:12621;1263}12641265run();12661267if(defined caller) {1268# wrapped in a subroutine processing requests,1269# e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI1270return;1271}else{1272# pure CGI script, serving single request1273exit;1274}12751276## ======================================================================1277## action links12781279# possible values of extra options1280# -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)1281# -replay => 1 - start from a current view (replay with modifications)1282# -path_info => 0|1 - don't use/use path_info URL (if possible)1283# -anchor => ANCHOR - add #ANCHOR to end of URL, implies -replay if used alone1284sub href {1285my%params=@_;1286# default is to use -absolute url() i.e. $my_uri1287my$href=$params{-full} ?$my_url:$my_uri;12881289# implicit -replay, must be first of implicit params1290$params{-replay} =1if(keys%params==1&&$params{-anchor});12911292$params{'project'} =$projectunlessexists$params{'project'};12931294if($params{-replay}) {1295while(my($name,$symbol) =each%cgi_param_mapping) {1296if(!exists$params{$name}) {1297$params{$name} =$input_params{$name};1298}1299}1300}13011302my$use_pathinfo= gitweb_check_feature('pathinfo');1303if(defined$params{'project'} &&1304(exists$params{-path_info} ?$params{-path_info} :$use_pathinfo)) {1305# try to put as many parameters as possible in PATH_INFO:1306# - project name1307# - action1308# - hash_parent or hash_parent_base:/file_parent1309# - hash or hash_base:/filename1310# - the snapshot_format as an appropriate suffix13111312# When the script is the root DirectoryIndex for the domain,1313# $href here would be something like http://gitweb.example.com/1314# Thus, we strip any trailing / from $href, to spare us double1315# slashes in the final URL1316$href=~ s,/$,,;13171318# Then add the project name, if present1319$href.="/".esc_path_info($params{'project'});1320delete$params{'project'};13211322# since we destructively absorb parameters, we keep this1323# boolean that remembers if we're handling a snapshot1324my$is_snapshot=$params{'action'}eq'snapshot';13251326# Summary just uses the project path URL, any other action is1327# added to the URL1328if(defined$params{'action'}) {1329$href.="/".esc_path_info($params{'action'})1330unless$params{'action'}eq'summary';1331delete$params{'action'};1332}13331334# Next, we put hash_parent_base:/file_parent..hash_base:/file_name,1335# stripping nonexistent or useless pieces1336$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'}1337||$params{'hash_parent'} ||$params{'hash'});1338if(defined$params{'hash_base'}) {1339if(defined$params{'hash_parent_base'}) {1340$href.= esc_path_info($params{'hash_parent_base'});1341# skip the file_parent if it's the same as the file_name1342if(defined$params{'file_parent'}) {1343if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) {1344delete$params{'file_parent'};1345}elsif($params{'file_parent'} !~/\.\./) {1346$href.=":/".esc_path_info($params{'file_parent'});1347delete$params{'file_parent'};1348}1349}1350$href.="..";1351delete$params{'hash_parent'};1352delete$params{'hash_parent_base'};1353}elsif(defined$params{'hash_parent'}) {1354$href.= esc_path_info($params{'hash_parent'})."..";1355delete$params{'hash_parent'};1356}13571358$href.= esc_path_info($params{'hash_base'});1359if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) {1360$href.=":/".esc_path_info($params{'file_name'});1361delete$params{'file_name'};1362}1363delete$params{'hash'};1364delete$params{'hash_base'};1365}elsif(defined$params{'hash'}) {1366$href.= esc_path_info($params{'hash'});1367delete$params{'hash'};1368}13691370# If the action was a snapshot, we can absorb the1371# snapshot_format parameter too1372if($is_snapshot) {1373my$fmt=$params{'snapshot_format'};1374# snapshot_format should always be defined when href()1375# is called, but just in case some code forgets, we1376# fall back to the default1377$fmt||=$snapshot_fmts[0];1378$href.=$known_snapshot_formats{$fmt}{'suffix'};1379delete$params{'snapshot_format'};1380}1381}13821383# now encode the parameters explicitly1384my@result= ();1385for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1386my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1387if(defined$params{$name}) {1388if(ref($params{$name})eq"ARRAY") {1389foreachmy$par(@{$params{$name}}) {1390push@result,$symbol."=". esc_param($par);1391}1392}else{1393push@result,$symbol."=". esc_param($params{$name});1394}1395}1396}1397$href.="?".join(';',@result)ifscalar@result;13981399# final transformation: trailing spaces must be escaped (URI-encoded)1400$href=~s/(\s+)$/CGI::escape($1)/e;14011402if($params{-anchor}) {1403$href.="#".esc_param($params{-anchor});1404}14051406return$href;1407}140814091410## ======================================================================1411## validation, quoting/unquoting and escaping14121413sub validate_action {1414my$input=shift||returnundef;1415returnundefunlessexists$actions{$input};1416return$input;1417}14181419sub validate_project {1420my$input=shift||returnundef;1421if(!validate_pathname($input) ||1422!(-d "$projectroot/$input") ||1423!check_export_ok("$projectroot/$input") ||1424($strict_export&& !project_in_list($input))) {1425returnundef;1426}else{1427return$input;1428}1429}14301431sub validate_pathname {1432my$input=shift||returnundef;14331434# no '.' or '..' as elements of path, i.e. no '.' nor '..'1435# at the beginning, at the end, and between slashes.1436# also this catches doubled slashes1437if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1438returnundef;1439}1440# no null characters1441if($input=~m!\0!) {1442returnundef;1443}1444return$input;1445}14461447sub validate_refname {1448my$input=shift||returnundef;14491450# textual hashes are O.K.1451if($input=~m/^[0-9a-fA-F]{40}$/) {1452return$input;1453}1454# it must be correct pathname1455$input= validate_pathname($input)1456orreturnundef;1457# restrictions on ref name according to git-check-ref-format1458if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1459returnundef;1460}1461return$input;1462}14631464# decode sequences of octets in utf8 into Perl's internal form,1465# which is utf-8 with utf8 flag set if needed. gitweb writes out1466# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1467sub to_utf8 {1468my$str=shift;1469returnundefunlessdefined$str;14701471if(utf8::is_utf8($str) || utf8::decode($str)) {1472return$str;1473}else{1474return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1475}1476}14771478# quote unsafe chars, but keep the slash, even when it's not1479# correct, but quoted slashes look too horrible in bookmarks1480sub esc_param {1481my$str=shift;1482returnundefunlessdefined$str;1483$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1484$str=~s/ /\+/g;1485return$str;1486}14871488# the quoting rules for path_info fragment are slightly different1489sub esc_path_info {1490my$str=shift;1491returnundefunlessdefined$str;14921493# path_info doesn't treat '+' as space (specially), but '?' must be escaped1494$str=~s/([^A-Za-z0-9\-_.~();\/;:@&= +]+)/CGI::escape($1)/eg;14951496return$str;1497}14981499# quote unsafe chars in whole URL, so some characters cannot be quoted1500sub esc_url {1501my$str=shift;1502returnundefunlessdefined$str;1503$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg;1504$str=~s/ /\+/g;1505return$str;1506}15071508# quote unsafe characters in HTML attributes1509sub esc_attr {15101511# for XHTML conformance escaping '"' to '"' is not enough1512return esc_html(@_);1513}15141515# replace invalid utf8 character with SUBSTITUTION sequence1516sub esc_html {1517my$str=shift;1518my%opts=@_;15191520returnundefunlessdefined$str;15211522$str= to_utf8($str);1523$str=$cgi->escapeHTML($str);1524if($opts{'-nbsp'}) {1525$str=~s/ / /g;1526}1527$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1528return$str;1529}15301531# quote control characters and escape filename to HTML1532sub esc_path {1533my$str=shift;1534my%opts=@_;15351536returnundefunlessdefined$str;15371538$str= to_utf8($str);1539$str=$cgi->escapeHTML($str);1540if($opts{'-nbsp'}) {1541$str=~s/ / /g;1542}1543$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1544return$str;1545}15461547# Sanitize for use in XHTML + application/xml+xhtm (valid XML 1.0)1548sub sanitize {1549my$str=shift;15501551returnundefunlessdefined$str;15521553$str= to_utf8($str);1554$str=~ s|([[:cntrl:]])|($1=~/[\t\n\r]/?$1: quot_cec($1))|eg;1555return$str;1556}15571558# Make control characters "printable", using character escape codes (CEC)1559sub quot_cec {1560my$cntrl=shift;1561my%opts=@_;1562my%es= (# character escape codes, aka escape sequences1563"\t"=>'\t',# tab (HT)1564"\n"=>'\n',# line feed (LF)1565"\r"=>'\r',# carrige return (CR)1566"\f"=>'\f',# form feed (FF)1567"\b"=>'\b',# backspace (BS)1568"\a"=>'\a',# alarm (bell) (BEL)1569"\e"=>'\e',# escape (ESC)1570"\013"=>'\v',# vertical tab (VT)1571"\000"=>'\0',# nul character (NUL)1572);1573my$chr= ( (exists$es{$cntrl})1574?$es{$cntrl}1575:sprintf('\%2x',ord($cntrl)) );1576if($opts{-nohtml}) {1577return$chr;1578}else{1579return"<span class=\"cntrl\">$chr</span>";1580}1581}15821583# Alternatively use unicode control pictures codepoints,1584# Unicode "printable representation" (PR)1585sub quot_upr {1586my$cntrl=shift;1587my%opts=@_;15881589my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1590if($opts{-nohtml}) {1591return$chr;1592}else{1593return"<span class=\"cntrl\">$chr</span>";1594}1595}15961597# git may return quoted and escaped filenames1598sub unquote {1599my$str=shift;16001601sub unq {1602my$seq=shift;1603my%es= (# character escape codes, aka escape sequences1604't'=>"\t",# tab (HT, TAB)1605'n'=>"\n",# newline (NL)1606'r'=>"\r",# return (CR)1607'f'=>"\f",# form feed (FF)1608'b'=>"\b",# backspace (BS)1609'a'=>"\a",# alarm (bell) (BEL)1610'e'=>"\e",# escape (ESC)1611'v'=>"\013",# vertical tab (VT)1612);16131614if($seq=~m/^[0-7]{1,3}$/) {1615# octal char sequence1616returnchr(oct($seq));1617}elsif(exists$es{$seq}) {1618# C escape sequence, aka character escape code1619return$es{$seq};1620}1621# quoted ordinary character1622return$seq;1623}16241625if($str=~m/^"(.*)"$/) {1626# needs unquoting1627$str=$1;1628$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1629}1630return$str;1631}16321633# escape tabs (convert tabs to spaces)1634sub untabify {1635my$line=shift;16361637while((my$pos=index($line,"\t")) != -1) {1638if(my$count= (8- ($pos%8))) {1639my$spaces=' ' x $count;1640$line=~s/\t/$spaces/;1641}1642}16431644return$line;1645}16461647sub project_in_list {1648my$project=shift;1649my@list= git_get_projects_list();1650return@list&&scalar(grep{$_->{'path'}eq$project}@list);1651}16521653## ----------------------------------------------------------------------1654## HTML aware string manipulation16551656# Try to chop given string on a word boundary between position1657# $len and $len+$add_len. If there is no word boundary there,1658# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1659# (marking chopped part) would be longer than given string.1660sub chop_str {1661my$str=shift;1662my$len=shift;1663my$add_len=shift||10;1664my$where=shift||'right';# 'left' | 'center' | 'right'16651666# Make sure perl knows it is utf8 encoded so we don't1667# cut in the middle of a utf8 multibyte char.1668$str= to_utf8($str);16691670# allow only $len chars, but don't cut a word if it would fit in $add_len1671# if it doesn't fit, cut it if it's still longer than the dots we would add1672# remove chopped character entities entirely16731674# when chopping in the middle, distribute $len into left and right part1675# return early if chopping wouldn't make string shorter1676if($whereeq'center') {1677return$strif($len+5>=length($str));# filler is length 51678$len=int($len/2);1679}else{1680return$strif($len+4>=length($str));# filler is length 41681}16821683# regexps: ending and beginning with word part up to $add_len1684my$endre=qr/.{$len}\w{0,$add_len}/;1685my$begre=qr/\w{0,$add_len}.{$len}/;16861687if($whereeq'left') {1688$str=~m/^(.*?)($begre)$/;1689my($lead,$body) = ($1,$2);1690if(length($lead) >4) {1691$lead=" ...";1692}1693return"$lead$body";16941695}elsif($whereeq'center') {1696$str=~m/^($endre)(.*)$/;1697my($left,$str) = ($1,$2);1698$str=~m/^(.*?)($begre)$/;1699my($mid,$right) = ($1,$2);1700if(length($mid) >5) {1701$mid=" ... ";1702}1703return"$left$mid$right";17041705}else{1706$str=~m/^($endre)(.*)$/;1707my$body=$1;1708my$tail=$2;1709if(length($tail) >4) {1710$tail="... ";1711}1712return"$body$tail";1713}1714}17151716# takes the same arguments as chop_str, but also wraps a <span> around the1717# result with a title attribute if it does get chopped. Additionally, the1718# string is HTML-escaped.1719sub chop_and_escape_str {1720my($str) =@_;17211722my$chopped= chop_str(@_);1723$str= to_utf8($str);1724if($choppedeq$str) {1725return esc_html($chopped);1726}else{1727$str=~s/[[:cntrl:]]/?/g;1728return$cgi->span({-title=>$str}, esc_html($chopped));1729}1730}17311732# Highlight selected fragments of string, using given CSS class,1733# and escape HTML. It is assumed that fragments do not overlap.1734# Regions are passed as list of pairs (array references).1735#1736# Example: esc_html_hl_regions("foobar", "mark", [ 0, 3 ]) returns1737# '<span class="mark">foo</span>bar'1738sub esc_html_hl_regions {1739my($str,$css_class,@sel) =@_;1740return esc_html($str)unless@sel;17411742my$out='';1743my$pos=0;17441745formy$s(@sel) {1746$out.= esc_html(substr($str,$pos,$s->[0] -$pos))1747if($s->[0] -$pos>0);1748$out.=$cgi->span({-class=>$css_class},1749 esc_html(substr($str,$s->[0],$s->[1] -$s->[0])));17501751$pos=$s->[1];1752}1753$out.= esc_html(substr($str,$pos))1754if($pos<length($str));17551756return$out;1757}17581759# return positions of beginning and end of each match1760sub matchpos_list {1761my($str,$regexp) =@_;1762return unless(defined$str&&defined$regexp);17631764my@matches;1765while($str=~/$regexp/g) {1766push@matches, [$-[0],$+[0]];1767}1768return@matches;1769}17701771# highlight match (if any), and escape HTML1772sub esc_html_match_hl {1773my($str,$regexp) =@_;1774return esc_html($str)unlessdefined$regexp;17751776my@matches= matchpos_list($str,$regexp);1777return esc_html($str)unless@matches;17781779return esc_html_hl_regions($str,'match',@matches);1780}178117821783# highlight match (if any) of shortened string, and escape HTML1784sub esc_html_match_hl_chopped {1785my($str,$chopped,$regexp) =@_;1786return esc_html_match_hl($str,$regexp)unlessdefined$chopped;17871788my@matches= matchpos_list($str,$regexp);1789return esc_html($chopped)unless@matches;17901791# filter matches so that we mark chopped string1792my$tail="... ";# see chop_str1793unless($chopped=~s/\Q$tail\E$//) {1794$tail='';1795}1796my$chop_len=length($chopped);1797my$tail_len=length($tail);1798my@filtered;17991800formy$m(@matches) {1801if($m->[0] >$chop_len) {1802push@filtered, [$chop_len,$chop_len+$tail_len]if($tail_len>0);1803last;1804}elsif($m->[1] >$chop_len) {1805push@filtered, [$m->[0],$chop_len+$tail_len];1806last;1807}1808push@filtered,$m;1809}18101811return esc_html_hl_regions($chopped.$tail,'match',@filtered);1812}18131814## ----------------------------------------------------------------------1815## functions returning short strings18161817# CSS class for given age value (in seconds)1818sub age_class {1819my$age=shift;18201821if(!defined$age) {1822return"noage";1823}elsif($age<60*60*2) {1824return"age0";1825}elsif($age<60*60*24*2) {1826return"age1";1827}else{1828return"age2";1829}1830}18311832# convert age in seconds to "nn units ago" string1833sub age_string {1834my$age=shift;1835my$age_str;18361837if($age>60*60*24*365*2) {1838$age_str= (int$age/60/60/24/365);1839$age_str.=" years ago";1840}elsif($age>60*60*24*(365/12)*2) {1841$age_str=int$age/60/60/24/(365/12);1842$age_str.=" months ago";1843}elsif($age>60*60*24*7*2) {1844$age_str=int$age/60/60/24/7;1845$age_str.=" weeks ago";1846}elsif($age>60*60*24*2) {1847$age_str=int$age/60/60/24;1848$age_str.=" days ago";1849}elsif($age>60*60*2) {1850$age_str=int$age/60/60;1851$age_str.=" hours ago";1852}elsif($age>60*2) {1853$age_str=int$age/60;1854$age_str.=" min ago";1855}elsif($age>2) {1856$age_str=int$age;1857$age_str.=" sec ago";1858}else{1859$age_str.=" right now";1860}1861return$age_str;1862}18631864useconstant{1865 S_IFINVALID =>0030000,1866 S_IFGITLINK =>0160000,1867};18681869# submodule/subproject, a commit object reference1870sub S_ISGITLINK {1871my$mode=shift;18721873return(($mode& S_IFMT) == S_IFGITLINK)1874}18751876# convert file mode in octal to symbolic file mode string1877sub mode_str {1878my$mode=oct shift;18791880if(S_ISGITLINK($mode)) {1881return'm---------';1882}elsif(S_ISDIR($mode& S_IFMT)) {1883return'drwxr-xr-x';1884}elsif(S_ISLNK($mode)) {1885return'lrwxrwxrwx';1886}elsif(S_ISREG($mode)) {1887# git cares only about the executable bit1888if($mode& S_IXUSR) {1889return'-rwxr-xr-x';1890}else{1891return'-rw-r--r--';1892};1893}else{1894return'----------';1895}1896}18971898# convert file mode in octal to file type string1899sub file_type {1900my$mode=shift;19011902if($mode!~m/^[0-7]+$/) {1903return$mode;1904}else{1905$mode=oct$mode;1906}19071908if(S_ISGITLINK($mode)) {1909return"submodule";1910}elsif(S_ISDIR($mode& S_IFMT)) {1911return"directory";1912}elsif(S_ISLNK($mode)) {1913return"symlink";1914}elsif(S_ISREG($mode)) {1915return"file";1916}else{1917return"unknown";1918}1919}19201921# convert file mode in octal to file type description string1922sub file_type_long {1923my$mode=shift;19241925if($mode!~m/^[0-7]+$/) {1926return$mode;1927}else{1928$mode=oct$mode;1929}19301931if(S_ISGITLINK($mode)) {1932return"submodule";1933}elsif(S_ISDIR($mode& S_IFMT)) {1934return"directory";1935}elsif(S_ISLNK($mode)) {1936return"symlink";1937}elsif(S_ISREG($mode)) {1938if($mode& S_IXUSR) {1939return"executable";1940}else{1941return"file";1942};1943}else{1944return"unknown";1945}1946}194719481949## ----------------------------------------------------------------------1950## functions returning short HTML fragments, or transforming HTML fragments1951## which don't belong to other sections19521953# format line of commit message.1954sub format_log_line_html {1955my$line=shift;19561957$line= esc_html($line, -nbsp=>1);1958$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1959$cgi->a({-href => href(action=>"object", hash=>$1),1960-class=>"text"},$1);1961}eg;19621963return$line;1964}19651966# format marker of refs pointing to given object19671968# the destination action is chosen based on object type and current context:1969# - for annotated tags, we choose the tag view unless it's the current view1970# already, in which case we go to shortlog view1971# - for other refs, we keep the current view if we're in history, shortlog or1972# log view, and select shortlog otherwise1973sub format_ref_marker {1974my($refs,$id) =@_;1975my$markers='';19761977if(defined$refs->{$id}) {1978foreachmy$ref(@{$refs->{$id}}) {1979# this code exploits the fact that non-lightweight tags are the1980# only indirect objects, and that they are the only objects for which1981# we want to use tag instead of shortlog as action1982my($type,$name) =qw();1983my$indirect= ($ref=~s/\^\{\}$//);1984# e.g. tags/v2.6.11 or heads/next1985if($ref=~m!^(.*?)s?/(.*)$!) {1986$type=$1;1987$name=$2;1988}else{1989$type="ref";1990$name=$ref;1991}19921993my$class=$type;1994$class.=" indirect"if$indirect;19951996my$dest_action="shortlog";19971998if($indirect) {1999$dest_action="tag"unless$actioneq"tag";2000}elsif($action=~/^(history|(short)?log)$/) {2001$dest_action=$action;2002}20032004my$dest="";2005$dest.="refs/"unless$ref=~ m!^refs/!;2006$dest.=$ref;20072008my$link=$cgi->a({2009-href => href(2010 action=>$dest_action,2011 hash=>$dest2012)},$name);20132014$markers.=" <span class=\"".esc_attr($class)."\"title=\"".esc_attr($ref)."\">".2015$link."</span>";2016}2017}20182019if($markers) {2020return' <span class="refs">'.$markers.'</span>';2021}else{2022return"";2023}2024}20252026# format, perhaps shortened and with markers, title line2027sub format_subject_html {2028my($long,$short,$href,$extra) =@_;2029$extra=''unlessdefined($extra);20302031if(length($short) <length($long)) {2032$long=~s/[[:cntrl:]]/?/g;2033return$cgi->a({-href =>$href, -class=>"list subject",2034-title => to_utf8($long)},2035 esc_html($short)) .$extra;2036}else{2037return$cgi->a({-href =>$href, -class=>"list subject"},2038 esc_html($long)) .$extra;2039}2040}20412042# Rather than recomputing the url for an email multiple times, we cache it2043# after the first hit. This gives a visible benefit in views where the avatar2044# for the same email is used repeatedly (e.g. shortlog).2045# The cache is shared by all avatar engines (currently gravatar only), which2046# are free to use it as preferred. Since only one avatar engine is used for any2047# given page, there's no risk for cache conflicts.2048our%avatar_cache= ();20492050# Compute the picon url for a given email, by using the picon search service over at2051# http://www.cs.indiana.edu/picons/search.html2052sub picon_url {2053my$email=lc shift;2054if(!$avatar_cache{$email}) {2055my($user,$domain) =split('@',$email);2056$avatar_cache{$email} =2057"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".2058"$domain/$user/".2059"users+domains+unknown/up/single";2060}2061return$avatar_cache{$email};2062}20632064# Compute the gravatar url for a given email, if it's not in the cache already.2065# Gravatar stores only the part of the URL before the size, since that's the2066# one computationally more expensive. This also allows reuse of the cache for2067# different sizes (for this particular engine).2068sub gravatar_url {2069my$email=lc shift;2070my$size=shift;2071$avatar_cache{$email} ||=2072"http://www.gravatar.com/avatar/".2073 Digest::MD5::md5_hex($email) ."?s=";2074return$avatar_cache{$email} .$size;2075}20762077# Insert an avatar for the given $email at the given $size if the feature2078# is enabled.2079sub git_get_avatar {2080my($email,%opts) =@_;2081my$pre_white= ($opts{-pad_before} ?" ":"");2082my$post_white= ($opts{-pad_after} ?" ":"");2083$opts{-size} ||='default';2084my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};2085my$url="";2086if($git_avatareq'gravatar') {2087$url= gravatar_url($email,$size);2088}elsif($git_avatareq'picon') {2089$url= picon_url($email);2090}2091# Other providers can be added by extending the if chain, defining $url2092# as needed. If no variant puts something in $url, we assume avatars2093# are completely disabled/unavailable.2094if($url) {2095return$pre_white.2096"<img width=\"$size\"".2097"class=\"avatar\"".2098"src=\"".esc_url($url)."\"".2099"alt=\"\"".2100"/>".$post_white;2101}else{2102return"";2103}2104}21052106sub format_search_author {2107my($author,$searchtype,$displaytext) =@_;2108my$have_search= gitweb_check_feature('search');21092110if($have_search) {2111my$performed="";2112if($searchtypeeq'author') {2113$performed="authored";2114}elsif($searchtypeeq'committer') {2115$performed="committed";2116}21172118return$cgi->a({-href => href(action=>"search", hash=>$hash,2119 searchtext=>$author,2120 searchtype=>$searchtype),class=>"list",2121 title=>"Search for commits$performedby$author"},2122$displaytext);21232124}else{2125return$displaytext;2126}2127}21282129# format the author name of the given commit with the given tag2130# the author name is chopped and escaped according to the other2131# optional parameters (see chop_str).2132sub format_author_html {2133my$tag=shift;2134my$co=shift;2135my$author= chop_and_escape_str($co->{'author_name'},@_);2136return"<$tagclass=\"author\">".2137 format_search_author($co->{'author_name'},"author",2138 git_get_avatar($co->{'author_email'}, -pad_after =>1) .2139$author) .2140"</$tag>";2141}21422143# format git diff header line, i.e. "diff --(git|combined|cc) ..."2144sub format_git_diff_header_line {2145my$line=shift;2146my$diffinfo=shift;2147my($from,$to) =@_;21482149if($diffinfo->{'nparents'}) {2150# combined diff2151$line=~s!^(diff (.*?) )"?.*$!$1!;2152if($to->{'href'}) {2153$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},2154 esc_path($to->{'file'}));2155}else{# file was deleted (no href)2156$line.= esc_path($to->{'file'});2157}2158}else{2159# "ordinary" diff2160$line=~s!^(diff (.*?) )"?a/.*$!$1!;2161if($from->{'href'}) {2162$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},2163'a/'. esc_path($from->{'file'}));2164}else{# file was added (no href)2165$line.='a/'. esc_path($from->{'file'});2166}2167$line.=' ';2168if($to->{'href'}) {2169$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},2170'b/'. esc_path($to->{'file'}));2171}else{# file was deleted2172$line.='b/'. esc_path($to->{'file'});2173}2174}21752176return"<div class=\"diff header\">$line</div>\n";2177}21782179# format extended diff header line, before patch itself2180sub format_extended_diff_header_line {2181my$line=shift;2182my$diffinfo=shift;2183my($from,$to) =@_;21842185# match <path>2186if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {2187$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},2188 esc_path($from->{'file'}));2189}2190if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {2191$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},2192 esc_path($to->{'file'}));2193}2194# match single <mode>2195if($line=~m/\s(\d{6})$/) {2196$line.='<span class="info"> ('.2197 file_type_long($1) .2198')</span>';2199}2200# match <hash>2201if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {2202# can match only for combined diff2203$line='index ';2204for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2205if($from->{'href'}[$i]) {2206$line.=$cgi->a({-href=>$from->{'href'}[$i],2207-class=>"hash"},2208substr($diffinfo->{'from_id'}[$i],0,7));2209}else{2210$line.='0' x 7;2211}2212# separator2213$line.=','if($i<$diffinfo->{'nparents'} -1);2214}2215$line.='..';2216if($to->{'href'}) {2217$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2218substr($diffinfo->{'to_id'},0,7));2219}else{2220$line.='0' x 7;2221}22222223}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {2224# can match only for ordinary diff2225my($from_link,$to_link);2226if($from->{'href'}) {2227$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},2228substr($diffinfo->{'from_id'},0,7));2229}else{2230$from_link='0' x 7;2231}2232if($to->{'href'}) {2233$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2234substr($diffinfo->{'to_id'},0,7));2235}else{2236$to_link='0' x 7;2237}2238my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});2239$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;2240}22412242return$line."<br/>\n";2243}22442245# format from-file/to-file diff header2246sub format_diff_from_to_header {2247my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;2248my$line;2249my$result='';22502251$line=$from_line;2252#assert($line =~ m/^---/) if DEBUG;2253# no extra formatting for "^--- /dev/null"2254if(!$diffinfo->{'nparents'}) {2255# ordinary (single parent) diff2256if($line=~m!^--- "?a/!) {2257if($from->{'href'}) {2258$line='--- a/'.2259$cgi->a({-href=>$from->{'href'}, -class=>"path"},2260 esc_path($from->{'file'}));2261}else{2262$line='--- a/'.2263 esc_path($from->{'file'});2264}2265}2266$result.= qq!<div class="diff from_file">$line</div>\n!;22672268}else{2269# combined diff (merge commit)2270for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2271if($from->{'href'}[$i]) {2272$line='--- '.2273$cgi->a({-href=>href(action=>"blobdiff",2274 hash_parent=>$diffinfo->{'from_id'}[$i],2275 hash_parent_base=>$parents[$i],2276 file_parent=>$from->{'file'}[$i],2277 hash=>$diffinfo->{'to_id'},2278 hash_base=>$hash,2279 file_name=>$to->{'file'}),2280-class=>"path",2281-title=>"diff". ($i+1)},2282$i+1) .2283'/'.2284$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},2285 esc_path($from->{'file'}[$i]));2286}else{2287$line='--- /dev/null';2288}2289$result.= qq!<div class="diff from_file">$line</div>\n!;2290}2291}22922293$line=$to_line;2294#assert($line =~ m/^\+\+\+/) if DEBUG;2295# no extra formatting for "^+++ /dev/null"2296if($line=~m!^\+\+\+ "?b/!) {2297if($to->{'href'}) {2298$line='+++ b/'.2299$cgi->a({-href=>$to->{'href'}, -class=>"path"},2300 esc_path($to->{'file'}));2301}else{2302$line='+++ b/'.2303 esc_path($to->{'file'});2304}2305}2306$result.= qq!<div class="diff to_file">$line</div>\n!;23072308return$result;2309}23102311# create note for patch simplified by combined diff2312sub format_diff_cc_simplified {2313my($diffinfo,@parents) =@_;2314my$result='';23152316$result.="<div class=\"diff header\">".2317"diff --cc ";2318if(!is_deleted($diffinfo)) {2319$result.=$cgi->a({-href => href(action=>"blob",2320 hash_base=>$hash,2321 hash=>$diffinfo->{'to_id'},2322 file_name=>$diffinfo->{'to_file'}),2323-class=>"path"},2324 esc_path($diffinfo->{'to_file'}));2325}else{2326$result.= esc_path($diffinfo->{'to_file'});2327}2328$result.="</div>\n".# class="diff header"2329"<div class=\"diff nodifferences\">".2330"Simple merge".2331"</div>\n";# class="diff nodifferences"23322333return$result;2334}23352336sub diff_line_class {2337my($line,$from,$to) =@_;23382339# ordinary diff2340my$num_sign=1;2341# combined diff2342if($from&&$to&&ref($from->{'href'})eq"ARRAY") {2343$num_sign=scalar@{$from->{'href'}};2344}23452346my@diff_line_classifier= (2347{ regexp =>qr/^\@\@{$num_sign} /,class=>"chunk_header"},2348{ regexp =>qr/^\\/,class=>"incomplete"},2349{ regexp =>qr/^ {$num_sign}/,class=>"ctx"},2350# classifier for context must come before classifier add/rem,2351# or we would have to use more complicated regexp, for example2352# qr/(?= {0,$m}\+)[+ ]{$num_sign}/, where $m = $num_sign - 1;2353{ regexp =>qr/^[+ ]{$num_sign}/,class=>"add"},2354{ regexp =>qr/^[- ]{$num_sign}/,class=>"rem"},2355);2356formy$clsfy(@diff_line_classifier) {2357return$clsfy->{'class'}2358if($line=~$clsfy->{'regexp'});2359}23602361# fallback2362return"";2363}23642365# assumes that $from and $to are defined and correctly filled,2366# and that $line holds a line of chunk header for unified diff2367sub format_unidiff_chunk_header {2368my($line,$from,$to) =@_;23692370my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =2371$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;23722373$from_lines=0unlessdefined$from_lines;2374$to_lines=0unlessdefined$to_lines;23752376if($from->{'href'}) {2377$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",2378-class=>"list"},$from_text);2379}2380if($to->{'href'}) {2381$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",2382-class=>"list"},$to_text);2383}2384$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".2385"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2386return$line;2387}23882389# assumes that $from and $to are defined and correctly filled,2390# and that $line holds a line of chunk header for combined diff2391sub format_cc_diff_chunk_header {2392my($line,$from,$to) =@_;23932394my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;2395my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);23962397@from_text=split(' ',$ranges);2398for(my$i=0;$i<@from_text; ++$i) {2399($from_start[$i],$from_nlines[$i]) =2400(split(',',substr($from_text[$i],1)),0);2401}24022403$to_text=pop@from_text;2404$to_start=pop@from_start;2405$to_nlines=pop@from_nlines;24062407$line="<span class=\"chunk_info\">$prefix";2408for(my$i=0;$i<@from_text; ++$i) {2409if($from->{'href'}[$i]) {2410$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",2411-class=>"list"},$from_text[$i]);2412}else{2413$line.=$from_text[$i];2414}2415$line.=" ";2416}2417if($to->{'href'}) {2418$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",2419-class=>"list"},$to_text);2420}else{2421$line.=$to_text;2422}2423$line.="$prefix</span>".2424"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2425return$line;2426}24272428# process patch (diff) line (not to be used for diff headers),2429# returning class and HTML-formatted (but not wrapped) line2430sub process_diff_line {2431my$line=shift;2432my($from,$to) =@_;24332434my$diff_class= diff_line_class($line,$from,$to);24352436chomp$line;2437$line= untabify($line);24382439if($from&&$to&&$line=~m/^\@{2} /) {2440$line= format_unidiff_chunk_header($line,$from,$to);2441return$diff_class,$line;24422443}elsif($from&&$to&&$line=~m/^\@{3}/) {2444$line= format_cc_diff_chunk_header($line,$from,$to);2445return$diff_class,$line;24462447}2448return$diff_class, esc_html($line, -nbsp=>1);2449}24502451# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",2452# linked. Pass the hash of the tree/commit to snapshot.2453sub format_snapshot_links {2454my($hash) =@_;2455my$num_fmts=@snapshot_fmts;2456if($num_fmts>1) {2457# A parenthesized list of links bearing format names.2458# e.g. "snapshot (_tar.gz_ _zip_)"2459return"snapshot (".join(' ',map2460$cgi->a({2461-href => href(2462 action=>"snapshot",2463 hash=>$hash,2464 snapshot_format=>$_2465)2466},$known_snapshot_formats{$_}{'display'})2467,@snapshot_fmts) .")";2468}elsif($num_fmts==1) {2469# A single "snapshot" link whose tooltip bears the format name.2470# i.e. "_snapshot_"2471my($fmt) =@snapshot_fmts;2472return2473$cgi->a({2474-href => href(2475 action=>"snapshot",2476 hash=>$hash,2477 snapshot_format=>$fmt2478),2479-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"2480},"snapshot");2481}else{# $num_fmts == 02482returnundef;2483}2484}24852486## ......................................................................2487## functions returning values to be passed, perhaps after some2488## transformation, to other functions; e.g. returning arguments to href()24892490# returns hash to be passed to href to generate gitweb URL2491# in -title key it returns description of link2492sub get_feed_info {2493my$format=shift||'Atom';2494my%res= (action =>lc($format));24952496# feed links are possible only for project views2497return unless(defined$project);2498# some views should link to OPML, or to generic project feed,2499# or don't have specific feed yet (so they should use generic)2500return if(!$action||$action=~/^(?:tags|heads|forks|tag|search)$/x);25012502my$branch;2503# branches refs uses 'refs/heads/' prefix (fullname) to differentiate2504# from tag links; this also makes possible to detect branch links2505if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||2506(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {2507$branch=$1;2508}2509# find log type for feed description (title)2510my$type='log';2511if(defined$file_name) {2512$type="history of$file_name";2513$type.="/"if($actioneq'tree');2514$type.=" on '$branch'"if(defined$branch);2515}else{2516$type="log of$branch"if(defined$branch);2517}25182519$res{-title} =$type;2520$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);2521$res{'file_name'} =$file_name;25222523return%res;2524}25252526## ----------------------------------------------------------------------2527## git utility subroutines, invoking git commands25282529# returns path to the core git executable and the --git-dir parameter as list2530sub git_cmd {2531$number_of_git_cmds++;2532return$GIT,'--git-dir='.$git_dir;2533}25342535# quote the given arguments for passing them to the shell2536# quote_command("command", "arg 1", "arg with ' and ! characters")2537# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2538# Try to avoid using this function wherever possible.2539sub quote_command {2540returnjoin(' ',2541map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2542}25432544# get HEAD ref of given project as hash2545sub git_get_head_hash {2546return git_get_full_hash(shift,'HEAD');2547}25482549sub git_get_full_hash {2550return git_get_hash(@_);2551}25522553sub git_get_short_hash {2554return git_get_hash(@_,'--short=7');2555}25562557sub git_get_hash {2558my($project,$hash,@options) =@_;2559my$o_git_dir=$git_dir;2560my$retval=undef;2561$git_dir="$projectroot/$project";2562if(open my$fd,'-|', git_cmd(),'rev-parse',2563'--verify','-q',@options,$hash) {2564$retval= <$fd>;2565chomp$retvalifdefined$retval;2566close$fd;2567}2568if(defined$o_git_dir) {2569$git_dir=$o_git_dir;2570}2571return$retval;2572}25732574# get type of given object2575sub git_get_type {2576my$hash=shift;25772578open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2579my$type= <$fd>;2580close$fdorreturn;2581chomp$type;2582return$type;2583}25842585# repository configuration2586our$config_file='';2587our%config;25882589# store multiple values for single key as anonymous array reference2590# single values stored directly in the hash, not as [ <value> ]2591sub hash_set_multi {2592my($hash,$key,$value) =@_;25932594if(!exists$hash->{$key}) {2595$hash->{$key} =$value;2596}elsif(!ref$hash->{$key}) {2597$hash->{$key} = [$hash->{$key},$value];2598}else{2599push@{$hash->{$key}},$value;2600}2601}26022603# return hash of git project configuration2604# optionally limited to some section, e.g. 'gitweb'2605sub git_parse_project_config {2606my$section_regexp=shift;2607my%config;26082609local$/="\0";26102611open my$fh,"-|", git_cmd(),"config",'-z','-l',2612orreturn;26132614while(my$keyval= <$fh>) {2615chomp$keyval;2616my($key,$value) =split(/\n/,$keyval,2);26172618 hash_set_multi(\%config,$key,$value)2619if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2620}2621close$fh;26222623return%config;2624}26252626# convert config value to boolean: 'true' or 'false'2627# no value, number > 0, 'true' and 'yes' values are true2628# rest of values are treated as false (never as error)2629sub config_to_bool {2630my$val=shift;26312632return1if!defined$val;# section.key26332634# strip leading and trailing whitespace2635$val=~s/^\s+//;2636$val=~s/\s+$//;26372638return(($val=~/^\d+$/&&$val) ||# section.key = 12639($val=~/^(?:true|yes)$/i));# section.key = true2640}26412642# convert config value to simple decimal number2643# an optional value suffix of 'k', 'm', or 'g' will cause the value2644# to be multiplied by 1024, 1048576, or 10737418242645sub config_to_int {2646my$val=shift;26472648# strip leading and trailing whitespace2649$val=~s/^\s+//;2650$val=~s/\s+$//;26512652if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2653$unit=lc($unit);2654# unknown unit is treated as 12655return$num* ($uniteq'g'?1073741824:2656$uniteq'm'?1048576:2657$uniteq'k'?1024:1);2658}2659return$val;2660}26612662# convert config value to array reference, if needed2663sub config_to_multi {2664my$val=shift;26652666returnref($val) ?$val: (defined($val) ? [$val] : []);2667}26682669sub git_get_project_config {2670my($key,$type) =@_;26712672return unlessdefined$git_dir;26732674# key sanity check2675return unless($key);2676# only subsection, if exists, is case sensitive,2677# and not lowercased by 'git config -z -l'2678if(my($hi,$mi,$lo) = ($key=~/^([^.]*)\.(.*)\.([^.]*)$/)) {2679$key=join(".",lc($hi),$mi,lc($lo));2680}else{2681$key=lc($key);2682}2683$key=~s/^gitweb\.//;2684return if($key=~m/\W/);26852686# type sanity check2687if(defined$type) {2688$type=~s/^--//;2689$type=undef2690unless($typeeq'bool'||$typeeq'int');2691}26922693# get config2694if(!defined$config_file||2695$config_filene"$git_dir/config") {2696%config= git_parse_project_config('gitweb');2697$config_file="$git_dir/config";2698}26992700# check if config variable (key) exists2701return unlessexists$config{"gitweb.$key"};27022703# ensure given type2704if(!defined$type) {2705return$config{"gitweb.$key"};2706}elsif($typeeq'bool') {2707# backward compatibility: 'git config --bool' returns true/false2708return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2709}elsif($typeeq'int') {2710return config_to_int($config{"gitweb.$key"});2711}2712return$config{"gitweb.$key"};2713}27142715# get hash of given path at given ref2716sub git_get_hash_by_path {2717my$base=shift;2718my$path=shift||returnundef;2719my$type=shift;27202721$path=~ s,/+$,,;27222723open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2724or die_error(500,"Open git-ls-tree failed");2725my$line= <$fd>;2726close$fdorreturnundef;27272728if(!defined$line) {2729# there is no tree or hash given by $path at $base2730returnundef;2731}27322733#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2734$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2735if(defined$type&&$typene$2) {2736# type doesn't match2737returnundef;2738}2739return$3;2740}27412742# get path of entry with given hash at given tree-ish (ref)2743# used to get 'from' filename for combined diff (merge commit) for renames2744sub git_get_path_by_hash {2745my$base=shift||return;2746my$hash=shift||return;27472748local$/="\0";27492750open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2751orreturnundef;2752while(my$line= <$fd>) {2753chomp$line;27542755#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2756#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2757if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2758close$fd;2759return$1;2760}2761}2762close$fd;2763returnundef;2764}27652766## ......................................................................2767## git utility functions, directly accessing git repository27682769# get the value of config variable either from file named as the variable2770# itself in the repository ($GIT_DIR/$name file), or from gitweb.$name2771# configuration variable in the repository config file.2772sub git_get_file_or_project_config {2773my($path,$name) =@_;27742775$git_dir="$projectroot/$path";2776open my$fd,'<',"$git_dir/$name"2777orreturn git_get_project_config($name);2778my$conf= <$fd>;2779close$fd;2780if(defined$conf) {2781chomp$conf;2782}2783return$conf;2784}27852786sub git_get_project_description {2787my$path=shift;2788return git_get_file_or_project_config($path,'description');2789}27902791sub git_get_project_category {2792my$path=shift;2793return git_get_file_or_project_config($path,'category');2794}279527962797# supported formats:2798# * $GIT_DIR/ctags/<tagname> file (in 'ctags' subdirectory)2799# - if its contents is a number, use it as tag weight,2800# - otherwise add a tag with weight 12801# * $GIT_DIR/ctags file, each line is a tag (with weight 1)2802# the same value multiple times increases tag weight2803# * `gitweb.ctag' multi-valued repo config variable2804sub git_get_project_ctags {2805my$project=shift;2806my$ctags= {};28072808$git_dir="$projectroot/$project";2809if(opendir my$dh,"$git_dir/ctags") {2810my@files=grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh);2811foreachmy$tagfile(@files) {2812open my$ct,'<',$tagfile2813ornext;2814my$val= <$ct>;2815chomp$valif$val;2816close$ct;28172818(my$ctag=$tagfile) =~ s#.*/##;2819if($val=~/^\d+$/) {2820$ctags->{$ctag} =$val;2821}else{2822$ctags->{$ctag} =1;2823}2824}2825closedir$dh;28262827}elsif(open my$fh,'<',"$git_dir/ctags") {2828while(my$line= <$fh>) {2829chomp$line;2830$ctags->{$line}++if$line;2831}2832close$fh;28332834}else{2835my$taglist= config_to_multi(git_get_project_config('ctag'));2836foreachmy$tag(@$taglist) {2837$ctags->{$tag}++;2838}2839}28402841return$ctags;2842}28432844# return hash, where keys are content tags ('ctags'),2845# and values are sum of weights of given tag in every project2846sub git_gather_all_ctags {2847my$projects=shift;2848my$ctags= {};28492850foreachmy$p(@$projects) {2851foreachmy$ct(keys%{$p->{'ctags'}}) {2852$ctags->{$ct} +=$p->{'ctags'}->{$ct};2853}2854}28552856return$ctags;2857}28582859sub git_populate_project_tagcloud {2860my$ctags=shift;28612862# First, merge different-cased tags; tags vote on casing2863my%ctags_lc;2864foreach(keys%$ctags) {2865$ctags_lc{lc$_}->{count} +=$ctags->{$_};2866if(not$ctags_lc{lc$_}->{topcount}2867or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2868$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2869$ctags_lc{lc$_}->{topname} =$_;2870}2871}28722873my$cloud;2874my$matched=$input_params{'ctag'};2875if(eval{require HTML::TagCloud;1; }) {2876$cloud= HTML::TagCloud->new;2877foreachmy$ctag(sort keys%ctags_lc) {2878# Pad the title with spaces so that the cloud looks2879# less crammed.2880my$title= esc_html($ctags_lc{$ctag}->{topname});2881$title=~s/ / /g;2882$title=~s/^/ /g;2883$title=~s/$/ /g;2884if(defined$matched&&$matchedeq$ctag) {2885$title=qq(<span class="match">$title</span>);2886}2887$cloud->add($title, href(project=>undef, ctag=>$ctag),2888$ctags_lc{$ctag}->{count});2889}2890}else{2891$cloud= {};2892foreachmy$ctag(keys%ctags_lc) {2893my$title= esc_html($ctags_lc{$ctag}->{topname}, -nbsp=>1);2894if(defined$matched&&$matchedeq$ctag) {2895$title=qq(<span class="match">$title</span>);2896}2897$cloud->{$ctag}{count} =$ctags_lc{$ctag}->{count};2898$cloud->{$ctag}{ctag} =2899$cgi->a({-href=>href(project=>undef, ctag=>$ctag)},$title);2900}2901}2902return$cloud;2903}29042905sub git_show_project_tagcloud {2906my($cloud,$count) =@_;2907if(ref$cloudeq'HTML::TagCloud') {2908return$cloud->html_and_css($count);2909}else{2910my@tags=sort{$cloud->{$a}->{'count'} <=>$cloud->{$b}->{'count'} }keys%$cloud;2911return2912'<div id="htmltagcloud"'.($project?'':' align="center"').'>'.2913join(', ',map{2914$cloud->{$_}->{'ctag'}2915}splice(@tags,0,$count)) .2916'</div>';2917}2918}29192920sub git_get_project_url_list {2921my$path=shift;29222923$git_dir="$projectroot/$path";2924open my$fd,'<',"$git_dir/cloneurl"2925orreturnwantarray?2926@{ config_to_multi(git_get_project_config('url')) } :2927 config_to_multi(git_get_project_config('url'));2928my@git_project_url_list=map{chomp;$_} <$fd>;2929close$fd;29302931returnwantarray?@git_project_url_list: \@git_project_url_list;2932}29332934sub git_get_projects_list {2935my$filter=shift||'';2936my$paranoid=shift;2937my@list;29382939if(-d $projects_list) {2940# search in directory2941my$dir=$projects_list;2942# remove the trailing "/"2943$dir=~s!/+$!!;2944my$pfxlen=length("$dir");2945my$pfxdepth= ($dir=~tr!/!!);2946# when filtering, search only given subdirectory2947if($filter&& !$paranoid) {2948$dir.="/$filter";2949$dir=~s!/+$!!;2950}29512952 File::Find::find({2953 follow_fast =>1,# follow symbolic links2954 follow_skip =>2,# ignore duplicates2955 dangling_symlinks =>0,# ignore dangling symlinks, silently2956 wanted =>sub{2957# global variables2958our$project_maxdepth;2959our$projectroot;2960# skip project-list toplevel, if we get it.2961return if(m!^[/.]$!);2962# only directories can be git repositories2963return unless(-d $_);2964# don't traverse too deep (Find is super slow on os x)2965# $project_maxdepth excludes depth of $projectroot2966if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2967$File::Find::prune =1;2968return;2969}29702971my$path=substr($File::Find::name,$pfxlen+1);2972# paranoidly only filter here2973if($paranoid&&$filter&&$path!~m!^\Q$filter\E/!) {2974next;2975}2976# we check related file in $projectroot2977if(check_export_ok("$projectroot/$path")) {2978push@list, { path =>$path};2979$File::Find::prune =1;2980}2981},2982},"$dir");29832984}elsif(-f $projects_list) {2985# read from file(url-encoded):2986# 'git%2Fgit.git Linus+Torvalds'2987# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2988# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2989open my$fd,'<',$projects_listorreturn;2990 PROJECT:2991while(my$line= <$fd>) {2992chomp$line;2993my($path,$owner) =split' ',$line;2994$path= unescape($path);2995$owner= unescape($owner);2996if(!defined$path) {2997next;2998}2999# if $filter is rpovided, check if $path begins with $filter3000if($filter&&$path!~m!^\Q$filter\E/!) {3001next;3002}3003if(check_export_ok("$projectroot/$path")) {3004my$pr= {3005 path =>$path,3006 owner => to_utf8($owner),3007};3008push@list,$pr;3009}3010}3011close$fd;3012}3013return@list;3014}30153016# written with help of Tree::Trie module (Perl Artistic License, GPL compatibile)3017# as side effects it sets 'forks' field to list of forks for forked projects3018sub filter_forks_from_projects_list {3019my$projects=shift;30203021my%trie;# prefix tree of directories (path components)3022# generate trie out of those directories that might contain forks3023foreachmy$pr(@$projects) {3024my$path=$pr->{'path'};3025$path=~s/\.git$//;# forks of 'repo.git' are in 'repo/' directory3026next if($path=~m!/$!);# skip non-bare repositories, e.g. 'repo/.git'3027next unless($path);# skip '.git' repository: tests, git-instaweb3028next unless(-d "$projectroot/$path");# containing directory exists3029$pr->{'forks'} = [];# there can be 0 or more forks of project30303031# add to trie3032my@dirs=split('/',$path);3033# walk the trie, until either runs out of components or out of trie3034my$ref= \%trie;3035while(scalar@dirs&&3036exists($ref->{$dirs[0]})) {3037$ref=$ref->{shift@dirs};3038}3039# create rest of trie structure from rest of components3040foreachmy$dir(@dirs) {3041$ref=$ref->{$dir} = {};3042}3043# create end marker, store $pr as a data3044$ref->{''} =$prif(!exists$ref->{''});3045}30463047# filter out forks, by finding shortest prefix match for paths3048my@filtered;3049 PROJECT:3050foreachmy$pr(@$projects) {3051# trie lookup3052my$ref= \%trie;3053 DIR:3054foreachmy$dir(split('/',$pr->{'path'})) {3055if(exists$ref->{''}) {3056# found [shortest] prefix, is a fork - skip it3057push@{$ref->{''}{'forks'}},$pr;3058next PROJECT;3059}3060if(!exists$ref->{$dir}) {3061# not in trie, cannot have prefix, not a fork3062push@filtered,$pr;3063next PROJECT;3064}3065# If the dir is there, we just walk one step down the trie.3066$ref=$ref->{$dir};3067}3068# we ran out of trie3069# (shouldn't happen: it's either no match, or end marker)3070push@filtered,$pr;3071}30723073return@filtered;3074}30753076# note: fill_project_list_info must be run first,3077# for 'descr_long' and 'ctags' to be filled3078sub search_projects_list {3079my($projlist,%opts) =@_;3080my$tagfilter=$opts{'tagfilter'};3081my$search_re=$opts{'search_regexp'};30823083return@$projlist3084unless($tagfilter||$search_re);30853086# searching projects require filling to be run before it;3087 fill_project_list_info($projlist,3088$tagfilter?'ctags': (),3089$search_re? ('path','descr') : ());3090my@projects;3091 PROJECT:3092foreachmy$pr(@$projlist) {30933094if($tagfilter) {3095next unlessref($pr->{'ctags'})eq'HASH';3096next unless3097grep{lc($_)eq lc($tagfilter) }keys%{$pr->{'ctags'}};3098}30993100if($search_re) {3101next unless3102$pr->{'path'} =~/$search_re/||3103$pr->{'descr_long'} =~/$search_re/;3104}31053106push@projects,$pr;3107}31083109return@projects;3110}31113112our$gitweb_project_owner=undef;3113sub git_get_project_list_from_file {31143115return if(defined$gitweb_project_owner);31163117$gitweb_project_owner= {};3118# read from file (url-encoded):3119# 'git%2Fgit.git Linus+Torvalds'3120# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'3121# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'3122if(-f $projects_list) {3123open(my$fd,'<',$projects_list);3124while(my$line= <$fd>) {3125chomp$line;3126my($pr,$ow) =split' ',$line;3127$pr= unescape($pr);3128$ow= unescape($ow);3129$gitweb_project_owner->{$pr} = to_utf8($ow);3130}3131close$fd;3132}3133}31343135sub git_get_project_owner {3136my$project=shift;3137my$owner;31383139returnundefunless$project;3140$git_dir="$projectroot/$project";31413142if(!defined$gitweb_project_owner) {3143 git_get_project_list_from_file();3144}31453146if(exists$gitweb_project_owner->{$project}) {3147$owner=$gitweb_project_owner->{$project};3148}3149if(!defined$owner){3150$owner= git_get_project_config('owner');3151}3152if(!defined$owner) {3153$owner= get_file_owner("$git_dir");3154}31553156return$owner;3157}31583159sub git_get_last_activity {3160my($path) =@_;3161my$fd;31623163$git_dir="$projectroot/$path";3164open($fd,"-|", git_cmd(),'for-each-ref',3165'--format=%(committer)',3166'--sort=-committerdate',3167'--count=1',3168'refs/heads')orreturn;3169my$most_recent= <$fd>;3170close$fdorreturn;3171if(defined$most_recent&&3172$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {3173my$timestamp=$1;3174my$age=time-$timestamp;3175return($age, age_string($age));3176}3177return(undef,undef);3178}31793180# Implementation note: when a single remote is wanted, we cannot use 'git3181# remote show -n' because that command always work (assuming it's a remote URL3182# if it's not defined), and we cannot use 'git remote show' because that would3183# try to make a network roundtrip. So the only way to find if that particular3184# remote is defined is to walk the list provided by 'git remote -v' and stop if3185# and when we find what we want.3186sub git_get_remotes_list {3187my$wanted=shift;3188my%remotes= ();31893190open my$fd,'-|', git_cmd(),'remote','-v';3191return unless$fd;3192while(my$remote= <$fd>) {3193chomp$remote;3194$remote=~s!\t(.*?)\s+\((\w+)\)$!!;3195next if$wantedand not$remoteeq$wanted;3196my($url,$key) = ($1,$2);31973198$remotes{$remote} ||= {'heads'=> () };3199$remotes{$remote}{$key} =$url;3200}3201close$fdorreturn;3202returnwantarray?%remotes: \%remotes;3203}32043205# Takes a hash of remotes as first parameter and fills it by adding the3206# available remote heads for each of the indicated remotes.3207sub fill_remote_heads {3208my$remotes=shift;3209my@heads=map{"remotes/$_"}keys%$remotes;3210my@remoteheads= git_get_heads_list(undef,@heads);3211foreachmy$remote(keys%$remotes) {3212$remotes->{$remote}{'heads'} = [grep{3213$_->{'name'} =~s!^$remote/!!3214}@remoteheads];3215}3216}32173218sub git_get_references {3219my$type=shift||"";3220my%refs;3221# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.113222# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}3223open my$fd,"-|", git_cmd(),"show-ref","--dereference",3224($type? ("--","refs/$type") : ())# use -- <pattern> if $type3225orreturn;32263227while(my$line= <$fd>) {3228chomp$line;3229if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {3230if(defined$refs{$1}) {3231push@{$refs{$1}},$2;3232}else{3233$refs{$1} = [$2];3234}3235}3236}3237close$fdorreturn;3238return \%refs;3239}32403241sub git_get_rev_name_tags {3242my$hash=shift||returnundef;32433244open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash3245orreturn;3246my$name_rev= <$fd>;3247close$fd;32483249if($name_rev=~ m|^$hash tags/(.*)$|) {3250return$1;3251}else{3252# catches also '$hash undefined' output3253returnundef;3254}3255}32563257## ----------------------------------------------------------------------3258## parse to hash functions32593260sub parse_date {3261my$epoch=shift;3262my$tz=shift||"-0000";32633264my%date;3265my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");3266my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");3267my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);3268$date{'hour'} =$hour;3269$date{'minute'} =$min;3270$date{'mday'} =$mday;3271$date{'day'} =$days[$wday];3272$date{'month'} =$months[$mon];3273$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",3274$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;3275$date{'mday-time'} =sprintf"%d%s%02d:%02d",3276$mday,$months[$mon],$hour,$min;3277$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",32781900+$year,1+$mon,$mday,$hour,$min,$sec;32793280my($tz_sign,$tz_hour,$tz_min) =3281($tz=~m/^([-+])(\d\d)(\d\d)$/);3282$tz_sign= ($tz_signeq'-'? -1: +1);3283my$local=$epoch+$tz_sign*((($tz_hour*60) +$tz_min)*60);3284($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);3285$date{'hour_local'} =$hour;3286$date{'minute_local'} =$min;3287$date{'tz_local'} =$tz;3288$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",32891900+$year,$mon+1,$mday,3290$hour,$min,$sec,$tz);3291return%date;3292}32933294sub parse_tag {3295my$tag_id=shift;3296my%tag;3297my@comment;32983299open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;3300$tag{'id'} =$tag_id;3301while(my$line= <$fd>) {3302chomp$line;3303if($line=~m/^object ([0-9a-fA-F]{40})$/) {3304$tag{'object'} =$1;3305}elsif($line=~m/^type (.+)$/) {3306$tag{'type'} =$1;3307}elsif($line=~m/^tag (.+)$/) {3308$tag{'name'} =$1;3309}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {3310$tag{'author'} =$1;3311$tag{'author_epoch'} =$2;3312$tag{'author_tz'} =$3;3313if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {3314$tag{'author_name'} =$1;3315$tag{'author_email'} =$2;3316}else{3317$tag{'author_name'} =$tag{'author'};3318}3319}elsif($line=~m/--BEGIN/) {3320push@comment,$line;3321last;3322}elsif($lineeq"") {3323last;3324}3325}3326push@comment, <$fd>;3327$tag{'comment'} = \@comment;3328close$fdorreturn;3329if(!defined$tag{'name'}) {3330return3331};3332return%tag3333}33343335sub parse_commit_text {3336my($commit_text,$withparents) =@_;3337my@commit_lines=split'\n',$commit_text;3338my%co;33393340pop@commit_lines;# Remove '\0'33413342if(!@commit_lines) {3343return;3344}33453346my$header=shift@commit_lines;3347if($header!~m/^[0-9a-fA-F]{40}/) {3348return;3349}3350($co{'id'},my@parents) =split' ',$header;3351while(my$line=shift@commit_lines) {3352last if$lineeq"\n";3353if($line=~m/^tree ([0-9a-fA-F]{40})$/) {3354$co{'tree'} =$1;3355}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {3356push@parents,$1;3357}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {3358$co{'author'} = to_utf8($1);3359$co{'author_epoch'} =$2;3360$co{'author_tz'} =$3;3361if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {3362$co{'author_name'} =$1;3363$co{'author_email'} =$2;3364}else{3365$co{'author_name'} =$co{'author'};3366}3367}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {3368$co{'committer'} = to_utf8($1);3369$co{'committer_epoch'} =$2;3370$co{'committer_tz'} =$3;3371if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {3372$co{'committer_name'} =$1;3373$co{'committer_email'} =$2;3374}else{3375$co{'committer_name'} =$co{'committer'};3376}3377}3378}3379if(!defined$co{'tree'}) {3380return;3381};3382$co{'parents'} = \@parents;3383$co{'parent'} =$parents[0];33843385foreachmy$title(@commit_lines) {3386$title=~s/^ //;3387if($titlene"") {3388$co{'title'} = chop_str($title,80,5);3389# remove leading stuff of merges to make the interesting part visible3390if(length($title) >50) {3391$title=~s/^Automatic //;3392$title=~s/^merge (of|with) /Merge ... /i;3393if(length($title) >50) {3394$title=~s/(http|rsync):\/\///;3395}3396if(length($title) >50) {3397$title=~s/(master|www|rsync)\.//;3398}3399if(length($title) >50) {3400$title=~s/kernel.org:?//;3401}3402if(length($title) >50) {3403$title=~s/\/pub\/scm//;3404}3405}3406$co{'title_short'} = chop_str($title,50,5);3407last;3408}3409}3410if(!defined$co{'title'} ||$co{'title'}eq"") {3411$co{'title'} =$co{'title_short'} ='(no commit message)';3412}3413# remove added spaces3414foreachmy$line(@commit_lines) {3415$line=~s/^ //;3416}3417$co{'comment'} = \@commit_lines;34183419my$age=time-$co{'committer_epoch'};3420$co{'age'} =$age;3421$co{'age_string'} = age_string($age);3422my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});3423if($age>60*60*24*7*2) {3424$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;3425$co{'age_string_age'} =$co{'age_string'};3426}else{3427$co{'age_string_date'} =$co{'age_string'};3428$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;3429}3430return%co;3431}34323433sub parse_commit {3434my($commit_id) =@_;3435my%co;34363437local$/="\0";34383439open my$fd,"-|", git_cmd(),"rev-list",3440"--parents",3441"--header",3442"--max-count=1",3443$commit_id,3444"--",3445or die_error(500,"Open git-rev-list failed");3446%co= parse_commit_text(<$fd>,1);3447close$fd;34483449return%co;3450}34513452sub parse_commits {3453my($commit_id,$maxcount,$skip,$filename,@args) =@_;3454my@cos;34553456$maxcount||=1;3457$skip||=0;34583459local$/="\0";34603461open my$fd,"-|", git_cmd(),"rev-list",3462"--header",3463@args,3464("--max-count=".$maxcount),3465("--skip=".$skip),3466@extra_options,3467$commit_id,3468"--",3469($filename? ($filename) : ())3470or die_error(500,"Open git-rev-list failed");3471while(my$line= <$fd>) {3472my%co= parse_commit_text($line);3473push@cos, \%co;3474}3475close$fd;34763477returnwantarray?@cos: \@cos;3478}34793480# parse line of git-diff-tree "raw" output3481sub parse_difftree_raw_line {3482my$line=shift;3483my%res;34843485# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'3486# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'3487if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {3488$res{'from_mode'} =$1;3489$res{'to_mode'} =$2;3490$res{'from_id'} =$3;3491$res{'to_id'} =$4;3492$res{'status'} =$5;3493$res{'similarity'} =$6;3494if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied3495($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);3496}else{3497$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);3498}3499}3500# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'3501# combined diff (for merge commit)3502elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {3503$res{'nparents'} =length($1);3504$res{'from_mode'} = [split(' ',$2) ];3505$res{'to_mode'} =pop@{$res{'from_mode'}};3506$res{'from_id'} = [split(' ',$3) ];3507$res{'to_id'} =pop@{$res{'from_id'}};3508$res{'status'} = [split('',$4) ];3509$res{'to_file'} = unquote($5);3510}3511# 'c512b523472485aef4fff9e57b229d9d243c967f'3512elsif($line=~m/^([0-9a-fA-F]{40})$/) {3513$res{'commit'} =$1;3514}35153516returnwantarray?%res: \%res;3517}35183519# wrapper: return parsed line of git-diff-tree "raw" output3520# (the argument might be raw line, or parsed info)3521sub parsed_difftree_line {3522my$line_or_ref=shift;35233524if(ref($line_or_ref)eq"HASH") {3525# pre-parsed (or generated by hand)3526return$line_or_ref;3527}else{3528return parse_difftree_raw_line($line_or_ref);3529}3530}35313532# parse line of git-ls-tree output3533sub parse_ls_tree_line {3534my$line=shift;3535my%opts=@_;3536my%res;35373538if($opts{'-l'}) {3539#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'3540$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;35413542$res{'mode'} =$1;3543$res{'type'} =$2;3544$res{'hash'} =$3;3545$res{'size'} =$4;3546if($opts{'-z'}) {3547$res{'name'} =$5;3548}else{3549$res{'name'} = unquote($5);3550}3551}else{3552#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'3553$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;35543555$res{'mode'} =$1;3556$res{'type'} =$2;3557$res{'hash'} =$3;3558if($opts{'-z'}) {3559$res{'name'} =$4;3560}else{3561$res{'name'} = unquote($4);3562}3563}35643565returnwantarray?%res: \%res;3566}35673568# generates _two_ hashes, references to which are passed as 2 and 3 argument3569sub parse_from_to_diffinfo {3570my($diffinfo,$from,$to,@parents) =@_;35713572if($diffinfo->{'nparents'}) {3573# combined diff3574$from->{'file'} = [];3575$from->{'href'} = [];3576 fill_from_file_info($diffinfo,@parents)3577unlessexists$diffinfo->{'from_file'};3578for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {3579$from->{'file'}[$i] =3580defined$diffinfo->{'from_file'}[$i] ?3581$diffinfo->{'from_file'}[$i] :3582$diffinfo->{'to_file'};3583if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file3584$from->{'href'}[$i] = href(action=>"blob",3585 hash_base=>$parents[$i],3586 hash=>$diffinfo->{'from_id'}[$i],3587 file_name=>$from->{'file'}[$i]);3588}else{3589$from->{'href'}[$i] =undef;3590}3591}3592}else{3593# ordinary (not combined) diff3594$from->{'file'} =$diffinfo->{'from_file'};3595if($diffinfo->{'status'}ne"A") {# not new (added) file3596$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,3597 hash=>$diffinfo->{'from_id'},3598 file_name=>$from->{'file'});3599}else{3600delete$from->{'href'};3601}3602}36033604$to->{'file'} =$diffinfo->{'to_file'};3605if(!is_deleted($diffinfo)) {# file exists in result3606$to->{'href'} = href(action=>"blob", hash_base=>$hash,3607 hash=>$diffinfo->{'to_id'},3608 file_name=>$to->{'file'});3609}else{3610delete$to->{'href'};3611}3612}36133614## ......................................................................3615## parse to array of hashes functions36163617sub git_get_heads_list {3618my($limit,@classes) =@_;3619@classes= ('heads')unless@classes;3620my@patterns=map{"refs/$_"}@classes;3621my@headslist;36223623open my$fd,'-|', git_cmd(),'for-each-ref',3624($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',3625'--format=%(objectname) %(refname) %(subject)%00%(committer)',3626@patterns3627orreturn;3628while(my$line= <$fd>) {3629my%ref_item;36303631chomp$line;3632my($refinfo,$committerinfo) =split(/\0/,$line);3633my($hash,$name,$title) =split(' ',$refinfo,3);3634my($committer,$epoch,$tz) =3635($committerinfo=~/^(.*) ([0-9]+) (.*)$/);3636$ref_item{'fullname'} =$name;3637$name=~s!^refs/(?:head|remote)s/!!;36383639$ref_item{'name'} =$name;3640$ref_item{'id'} =$hash;3641$ref_item{'title'} =$title||'(no commit message)';3642$ref_item{'epoch'} =$epoch;3643if($epoch) {3644$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3645}else{3646$ref_item{'age'} ="unknown";3647}36483649push@headslist, \%ref_item;3650}3651close$fd;36523653returnwantarray?@headslist: \@headslist;3654}36553656sub git_get_tags_list {3657my$limit=shift;3658my@tagslist;36593660open my$fd,'-|', git_cmd(),'for-each-ref',3661($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',3662'--format=%(objectname) %(objecttype) %(refname) '.3663'%(*objectname) %(*objecttype) %(subject)%00%(creator)',3664'refs/tags'3665orreturn;3666while(my$line= <$fd>) {3667my%ref_item;36683669chomp$line;3670my($refinfo,$creatorinfo) =split(/\0/,$line);3671my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);3672my($creator,$epoch,$tz) =3673($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);3674$ref_item{'fullname'} =$name;3675$name=~s!^refs/tags/!!;36763677$ref_item{'type'} =$type;3678$ref_item{'id'} =$id;3679$ref_item{'name'} =$name;3680if($typeeq"tag") {3681$ref_item{'subject'} =$title;3682$ref_item{'reftype'} =$reftype;3683$ref_item{'refid'} =$refid;3684}else{3685$ref_item{'reftype'} =$type;3686$ref_item{'refid'} =$id;3687}36883689if($typeeq"tag"||$typeeq"commit") {3690$ref_item{'epoch'} =$epoch;3691if($epoch) {3692$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3693}else{3694$ref_item{'age'} ="unknown";3695}3696}36973698push@tagslist, \%ref_item;3699}3700close$fd;37013702returnwantarray?@tagslist: \@tagslist;3703}37043705## ----------------------------------------------------------------------3706## filesystem-related functions37073708sub get_file_owner {3709my$path=shift;37103711my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);3712my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);3713if(!defined$gcos) {3714returnundef;3715}3716my$owner=$gcos;3717$owner=~s/[,;].*$//;3718return to_utf8($owner);3719}37203721# assume that file exists3722sub insert_file {3723my$filename=shift;37243725open my$fd,'<',$filename;3726print map{ to_utf8($_) } <$fd>;3727close$fd;3728}37293730## ......................................................................3731## mimetype related functions37323733sub mimetype_guess_file {3734my$filename=shift;3735my$mimemap=shift;3736-r $mimemaporreturnundef;37373738my%mimemap;3739open(my$mh,'<',$mimemap)orreturnundef;3740while(<$mh>) {3741next ifm/^#/;# skip comments3742my($mimetype,@exts) =split(/\s+/);3743foreachmy$ext(@exts) {3744$mimemap{$ext} =$mimetype;3745}3746}3747close($mh);37483749$filename=~/\.([^.]*)$/;3750return$mimemap{$1};3751}37523753sub mimetype_guess {3754my$filename=shift;3755my$mime;3756$filename=~/\./orreturnundef;37573758if($mimetypes_file) {3759my$file=$mimetypes_file;3760if($file!~m!^/!) {# if it is relative path3761# it is relative to project3762$file="$projectroot/$project/$file";3763}3764$mime= mimetype_guess_file($filename,$file);3765}3766$mime||= mimetype_guess_file($filename,'/etc/mime.types');3767return$mime;3768}37693770sub blob_mimetype {3771my$fd=shift;3772my$filename=shift;37733774if($filename) {3775my$mime= mimetype_guess($filename);3776$mimeandreturn$mime;3777}37783779# just in case3780return$default_blob_plain_mimetypeunless$fd;37813782if(-T $fd) {3783return'text/plain';3784}elsif(!$filename) {3785return'application/octet-stream';3786}elsif($filename=~m/\.png$/i) {3787return'image/png';3788}elsif($filename=~m/\.gif$/i) {3789return'image/gif';3790}elsif($filename=~m/\.jpe?g$/i) {3791return'image/jpeg';3792}else{3793return'application/octet-stream';3794}3795}37963797sub blob_contenttype {3798my($fd,$file_name,$type) =@_;37993800$type||= blob_mimetype($fd,$file_name);3801if($typeeq'text/plain'&&defined$default_text_plain_charset) {3802$type.="; charset=$default_text_plain_charset";3803}38043805return$type;3806}38073808# guess file syntax for syntax highlighting; return undef if no highlighting3809# the name of syntax can (in the future) depend on syntax highlighter used3810sub guess_file_syntax {3811my($highlight,$mimetype,$file_name) =@_;3812returnundefunless($highlight&&defined$file_name);3813my$basename= basename($file_name,'.in');3814return$highlight_basename{$basename}3815ifexists$highlight_basename{$basename};38163817$basename=~/\.([^.]*)$/;3818my$ext=$1orreturnundef;3819return$highlight_ext{$ext}3820ifexists$highlight_ext{$ext};38213822returnundef;3823}38243825# run highlighter and return FD of its output,3826# or return original FD if no highlighting3827sub run_highlighter {3828my($fd,$highlight,$syntax) =@_;3829return$fdunless($highlight&&defined$syntax);38303831close$fd;3832open$fd, quote_command(git_cmd(),"cat-file","blob",$hash)." | ".3833 quote_command($highlight_bin).3834" --replace-tabs=8 --fragment --syntax$syntax|"3835or die_error(500,"Couldn't open file or run syntax highlighter");3836return$fd;3837}38383839## ======================================================================3840## functions printing HTML: header, footer, error page38413842sub get_page_title {3843my$title= to_utf8($site_name);38443845unless(defined$project) {3846if(defined$project_filter) {3847$title.=" - projects in '". esc_path($project_filter) ."'";3848}3849return$title;3850}3851$title.=" - ". to_utf8($project);38523853return$titleunless(defined$action);3854$title.="/$action";# $action is US-ASCII (7bit ASCII)38553856return$titleunless(defined$file_name);3857$title.=" - ". esc_path($file_name);3858if($actioneq"tree"&&$file_name!~ m|/$|) {3859$title.="/";3860}38613862return$title;3863}38643865sub get_content_type_html {3866# require explicit support from the UA if we are to send the page as3867# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3868# we have to do this because MSIE sometimes globs '*/*', pretending to3869# support xhtml+xml but choking when it gets what it asked for.3870if(defined$cgi->http('HTTP_ACCEPT') &&3871$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3872$cgi->Accept('application/xhtml+xml') !=0) {3873return'application/xhtml+xml';3874}else{3875return'text/html';3876}3877}38783879sub print_feed_meta {3880if(defined$project) {3881my%href_params= get_feed_info();3882if(!exists$href_params{'-title'}) {3883$href_params{'-title'} ='log';3884}38853886foreachmy$format(qw(RSS Atom)) {3887my$type=lc($format);3888my%link_attr= (3889'-rel'=>'alternate',3890'-title'=> esc_attr("$project-$href_params{'-title'} -$formatfeed"),3891'-type'=>"application/$type+xml"3892);38933894$href_params{'action'} =$type;3895$link_attr{'-href'} = href(%href_params);3896print"<link ".3897"rel=\"$link_attr{'-rel'}\"".3898"title=\"$link_attr{'-title'}\"".3899"href=\"$link_attr{'-href'}\"".3900"type=\"$link_attr{'-type'}\"".3901"/>\n";39023903$href_params{'extra_options'} ='--no-merges';3904$link_attr{'-href'} = href(%href_params);3905$link_attr{'-title'} .=' (no merges)';3906print"<link ".3907"rel=\"$link_attr{'-rel'}\"".3908"title=\"$link_attr{'-title'}\"".3909"href=\"$link_attr{'-href'}\"".3910"type=\"$link_attr{'-type'}\"".3911"/>\n";3912}39133914}else{3915printf('<link rel="alternate" title="%sprojects list" '.3916'href="%s" type="text/plain; charset=utf-8" />'."\n",3917 esc_attr($site_name), href(project=>undef, action=>"project_index"));3918printf('<link rel="alternate" title="%sprojects feeds" '.3919'href="%s" type="text/x-opml" />'."\n",3920 esc_attr($site_name), href(project=>undef, action=>"opml"));3921}3922}39233924sub print_header_links {3925my$status=shift;39263927# print out each stylesheet that exist, providing backwards capability3928# for those people who defined $stylesheet in a config file3929if(defined$stylesheet) {3930print'<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";3931}else{3932foreachmy$stylesheet(@stylesheets) {3933next unless$stylesheet;3934print'<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";3935}3936}3937 print_feed_meta()3938if($statuseq'200 OK');3939if(defined$favicon) {3940printqq(<link rel="shortcut icon" href=").esc_url($favicon).qq(" type="image/png" />\n);3941}3942}39433944sub print_nav_breadcrumbs_path {3945my$dirprefix=undef;3946while(my$part=shift) {3947$dirprefix.="/"ifdefined$dirprefix;3948$dirprefix.=$part;3949print$cgi->a({-href => href(project =>undef,3950 project_filter =>$dirprefix,3951 action =>"project_list")},3952 esc_html($part)) ." / ";3953}3954}39553956sub print_nav_breadcrumbs {3957my%opts=@_;39583959print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3960if(defined$project) {3961my@dirname=split'/',$project;3962my$projectbasename=pop@dirname;3963 print_nav_breadcrumbs_path(@dirname);3964print$cgi->a({-href => href(action=>"summary")}, esc_html($projectbasename));3965if(defined$action) {3966my$action_print=$action;3967if(defined$opts{-action_extra}) {3968$action_print=$cgi->a({-href => href(action=>$action)},3969$action);3970}3971print" /$action_print";3972}3973if(defined$opts{-action_extra}) {3974print" /$opts{-action_extra}";3975}3976print"\n";3977}elsif(defined$project_filter) {3978 print_nav_breadcrumbs_path(split'/',$project_filter);3979}3980}39813982sub print_search_form {3983if(!defined$searchtext) {3984$searchtext="";3985}3986my$search_hash;3987if(defined$hash_base) {3988$search_hash=$hash_base;3989}elsif(defined$hash) {3990$search_hash=$hash;3991}else{3992$search_hash="HEAD";3993}3994my$action=$my_uri;3995my$use_pathinfo= gitweb_check_feature('pathinfo');3996if($use_pathinfo) {3997$action.="/".esc_url($project);3998}3999print$cgi->startform(-method=>"get", -action =>$action) .4000"<div class=\"search\">\n".4001(!$use_pathinfo&&4002$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .4003$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".4004$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".4005$cgi->popup_menu(-name =>'st', -default=>'commit',4006-values=> ['commit','grep','author','committer','pickaxe']) .4007$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .4008" search:\n",4009$cgi->textfield(-name =>"s", -value =>$searchtext, -override =>1) ."\n".4010"<span title=\"Extended regular expression\">".4011$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',4012-checked =>$search_use_regexp) .4013"</span>".4014"</div>".4015$cgi->end_form() ."\n";4016}40174018sub git_header_html {4019my$status=shift||"200 OK";4020my$expires=shift;4021my%opts=@_;40224023my$title= get_page_title();4024my$content_type= get_content_type_html();4025print$cgi->header(-type=>$content_type, -charset =>'utf-8',4026-status=>$status, -expires =>$expires)4027unless($opts{'-no_http_header'});4028my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';4029print<<EOF;4030<?xml version="1.0" encoding="utf-8"?>4031<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">4032<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">4033<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->4034<!-- git core binaries version$git_version-->4035<head>4036<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>4037<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>4038<meta name="robots" content="index, nofollow"/>4039<title>$title</title>4040EOF4041# the stylesheet, favicon etc urls won't work correctly with path_info4042# unless we set the appropriate base URL4043if($ENV{'PATH_INFO'}) {4044print"<base href=\"".esc_url($base_url)."\"/>\n";4045}4046 print_header_links($status);40474048if(defined$site_html_head_string) {4049print to_utf8($site_html_head_string);4050}40514052print"</head>\n".4053"<body>\n";40544055if(defined$site_header&& -f $site_header) {4056 insert_file($site_header);4057}40584059print"<div class=\"page_header\">\n";4060if(defined$logo) {4061print$cgi->a({-href => esc_url($logo_url),4062-title =>$logo_label},4063$cgi->img({-src => esc_url($logo),4064-width =>72, -height =>27,4065-alt =>"git",4066-class=>"logo"}));4067}4068 print_nav_breadcrumbs(%opts);4069print"</div>\n";40704071my$have_search= gitweb_check_feature('search');4072if(defined$project&&$have_search) {4073 print_search_form();4074}4075}40764077sub git_footer_html {4078my$feed_class='rss_logo';40794080print"<div class=\"page_footer\">\n";4081if(defined$project) {4082my$descr= git_get_project_description($project);4083if(defined$descr) {4084print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";4085}40864087my%href_params= get_feed_info();4088if(!%href_params) {4089$feed_class.=' generic';4090}4091$href_params{'-title'} ||='log';40924093foreachmy$format(qw(RSS Atom)) {4094$href_params{'action'} =lc($format);4095print$cgi->a({-href => href(%href_params),4096-title =>"$href_params{'-title'}$formatfeed",4097-class=>$feed_class},$format)."\n";4098}40994100}else{4101print$cgi->a({-href => href(project=>undef, action=>"opml",4102 project_filter =>$project_filter),4103-class=>$feed_class},"OPML") ." ";4104print$cgi->a({-href => href(project=>undef, action=>"project_index",4105 project_filter =>$project_filter),4106-class=>$feed_class},"TXT") ."\n";4107}4108print"</div>\n";# class="page_footer"41094110if(defined$t0&& gitweb_check_feature('timed')) {4111print"<div id=\"generating_info\">\n";4112print'This page took '.4113'<span id="generating_time" class="time_span">'.4114 tv_interval($t0, [ gettimeofday() ]).4115' seconds </span>'.4116' and '.4117'<span id="generating_cmd">'.4118$number_of_git_cmds.4119'</span> git commands '.4120" to generate.\n";4121print"</div>\n";# class="page_footer"4122}41234124if(defined$site_footer&& -f $site_footer) {4125 insert_file($site_footer);4126}41274128print qq!<script type="text/javascript" src="!.esc_url($javascript).qq!"></script>\n!;4129if(defined$action&&4130$actioneq'blame_incremental') {4131print qq!<script type="text/javascript">\n!.4132 qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.4133 qq!"!. href() .qq!");\n!.4134 qq!</script>\n!;4135}else{4136my($jstimezone,$tz_cookie,$datetime_class) =4137 gitweb_get_feature('javascript-timezone');41384139print qq!<script type="text/javascript">\n!.4140 qq!window.onload = function () {\n!;4141if(gitweb_check_feature('javascript-actions')) {4142print qq! fixLinks();\n!;4143}4144if($jstimezone&&$tz_cookie&&$datetime_class) {4145print qq! var tz_cookie = { name:'$tz_cookie', expires:14, path:'/'};\n!.# in days4146 qq! onloadTZSetup('$jstimezone', tz_cookie,'$datetime_class');\n!;4147}4148print qq!};\n!.4149 qq!</script>\n!;4150}41514152print"</body>\n".4153"</html>";4154}41554156# die_error(<http_status_code>, <error_message>[, <detailed_html_description>])4157# Example: die_error(404, 'Hash not found')4158# By convention, use the following status codes (as defined in RFC 2616):4159# 400: Invalid or missing CGI parameters, or4160# requested object exists but has wrong type.4161# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on4162# this server or project.4163# 404: Requested object/revision/project doesn't exist.4164# 500: The server isn't configured properly, or4165# an internal error occurred (e.g. failed assertions caused by bugs), or4166# an unknown error occurred (e.g. the git binary died unexpectedly).4167# 503: The server is currently unavailable (because it is overloaded,4168# or down for maintenance). Generally, this is a temporary state.4169sub die_error {4170my$status=shift||500;4171my$error= esc_html(shift) ||"Internal Server Error";4172my$extra=shift;4173my%opts=@_;41744175my%http_responses= (4176400=>'400 Bad Request',4177403=>'403 Forbidden',4178404=>'404 Not Found',4179500=>'500 Internal Server Error',4180503=>'503 Service Unavailable',4181);4182 git_header_html($http_responses{$status},undef,%opts);4183print<<EOF;4184<div class="page_body">4185<br /><br />4186$status-$error4187<br />4188EOF4189if(defined$extra) {4190print"<hr />\n".4191"$extra\n";4192}4193print"</div>\n";41944195 git_footer_html();4196goto DONE_GITWEB4197unless($opts{'-error_handler'});4198}41994200## ----------------------------------------------------------------------4201## functions printing or outputting HTML: navigation42024203sub git_print_page_nav {4204my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;4205$extra=''if!defined$extra;# pager or formats42064207my@navs=qw(summary shortlog log commit commitdiff tree);4208if($suppress) {4209@navs=grep{$_ne$suppress}@navs;4210}42114212my%arg=map{$_=> {action=>$_} }@navs;4213if(defined$head) {4214for(qw(commit commitdiff)) {4215$arg{$_}{'hash'} =$head;4216}4217if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {4218for(qw(shortlog log)) {4219$arg{$_}{'hash'} =$head;4220}4221}4222}42234224$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;4225$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;42264227my@actions= gitweb_get_feature('actions');4228my%repl= (4229'%'=>'%',4230'n'=>$project,# project name4231'f'=>$git_dir,# project path within filesystem4232'h'=>$treehead||'',# current hash ('h' parameter)4233'b'=>$treebase||'',# hash base ('hb' parameter)4234);4235while(@actions) {4236my($label,$link,$pos) =splice(@actions,0,3);4237# insert4238@navs=map{$_eq$pos? ($_,$label) :$_}@navs;4239# munch munch4240$link=~s/%([%nfhb])/$repl{$1}/g;4241$arg{$label}{'_href'} =$link;4242}42434244print"<div class=\"page_nav\">\n".4245(join" | ",4246map{$_eq$current?4247$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")4248}@navs);4249print"<br/>\n$extra<br/>\n".4250"</div>\n";4251}42524253# returns a submenu for the nagivation of the refs views (tags, heads,4254# remotes) with the current view disabled and the remotes view only4255# available if the feature is enabled4256sub format_ref_views {4257my($current) =@_;4258my@ref_views=qw{tags heads};4259push@ref_views,'remotes'if gitweb_check_feature('remote_heads');4260returnjoin" | ",map{4261$_eq$current?$_:4262$cgi->a({-href => href(action=>$_)},$_)4263}@ref_views4264}42654266sub format_paging_nav {4267my($action,$page,$has_next_link) =@_;4268my$paging_nav;426942704271if($page>0) {4272$paging_nav.=4273$cgi->a({-href => href(-replay=>1, page=>undef)},"first") .4274" ⋅ ".4275$cgi->a({-href => href(-replay=>1, page=>$page-1),4276-accesskey =>"p", -title =>"Alt-p"},"prev");4277}else{4278$paging_nav.="first ⋅ prev";4279}42804281if($has_next_link) {4282$paging_nav.=" ⋅ ".4283$cgi->a({-href => href(-replay=>1, page=>$page+1),4284-accesskey =>"n", -title =>"Alt-n"},"next");4285}else{4286$paging_nav.=" ⋅ next";4287}42884289return$paging_nav;4290}42914292## ......................................................................4293## functions printing or outputting HTML: div42944295sub git_print_header_div {4296my($action,$title,$hash,$hash_base) =@_;4297my%args= ();42984299$args{'action'} =$action;4300$args{'hash'} =$hashif$hash;4301$args{'hash_base'} =$hash_baseif$hash_base;43024303print"<div class=\"header\">\n".4304$cgi->a({-href => href(%args), -class=>"title"},4305$title?$title:$action) .4306"\n</div>\n";4307}43084309sub format_repo_url {4310my($name,$url) =@_;4311return"<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";4312}43134314# Group output by placing it in a DIV element and adding a header.4315# Options for start_div() can be provided by passing a hash reference as the4316# first parameter to the function.4317# Options to git_print_header_div() can be provided by passing an array4318# reference. This must follow the options to start_div if they are present.4319# The content can be a scalar, which is output as-is, a scalar reference, which4320# is output after html escaping, an IO handle passed either as *handle or4321# *handle{IO}, or a function reference. In the latter case all following4322# parameters will be taken as argument to the content function call.4323sub git_print_section {4324my($div_args,$header_args,$content);4325my$arg=shift;4326if(ref($arg)eq'HASH') {4327$div_args=$arg;4328$arg=shift;4329}4330if(ref($arg)eq'ARRAY') {4331$header_args=$arg;4332$arg=shift;4333}4334$content=$arg;43354336print$cgi->start_div($div_args);4337 git_print_header_div(@$header_args);43384339if(ref($content)eq'CODE') {4340$content->(@_);4341}elsif(ref($content)eq'SCALAR') {4342print esc_html($$content);4343}elsif(ref($content)eq'GLOB'or ref($content)eq'IO::Handle') {4344print<$content>;4345}elsif(!ref($content) &&defined($content)) {4346print$content;4347}43484349print$cgi->end_div;4350}43514352sub format_timestamp_html {4353my$date=shift;4354my$strtime=$date->{'rfc2822'};43554356my(undef,undef,$datetime_class) =4357 gitweb_get_feature('javascript-timezone');4358if($datetime_class) {4359$strtime= qq!<span class="$datetime_class">$strtime</span>!;4360}43614362my$localtime_format='(%02d:%02d%s)';4363if($date->{'hour_local'} <6) {4364$localtime_format='(<span class="atnight">%02d:%02d</span>%s)';4365}4366$strtime.=' '.4367sprintf($localtime_format,4368$date->{'hour_local'},$date->{'minute_local'},$date->{'tz_local'});43694370return$strtime;4371}43724373# Outputs the author name and date in long form4374sub git_print_authorship {4375my$co=shift;4376my%opts=@_;4377my$tag=$opts{-tag} ||'div';4378my$author=$co->{'author_name'};43794380my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});4381print"<$tagclass=\"author_date\">".4382 format_search_author($author,"author", esc_html($author)) .4383" [".format_timestamp_html(\%ad)."]".4384 git_get_avatar($co->{'author_email'}, -pad_before =>1) .4385"</$tag>\n";4386}43874388# Outputs table rows containing the full author or committer information,4389# in the format expected for 'commit' view (& similar).4390# Parameters are a commit hash reference, followed by the list of people4391# to output information for. If the list is empty it defaults to both4392# author and committer.4393sub git_print_authorship_rows {4394my$co=shift;4395# too bad we can't use @people = @_ || ('author', 'committer')4396my@people=@_;4397@people= ('author','committer')unless@people;4398foreachmy$who(@people) {4399my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});4400print"<tr><td>$who</td><td>".4401 format_search_author($co->{"${who}_name"},$who,4402 esc_html($co->{"${who}_name"})) ." ".4403 format_search_author($co->{"${who}_email"},$who,4404 esc_html("<".$co->{"${who}_email"} .">")) .4405"</td><td rowspan=\"2\">".4406 git_get_avatar($co->{"${who}_email"}, -size =>'double') .4407"</td></tr>\n".4408"<tr>".4409"<td></td><td>".4410 format_timestamp_html(\%wd) .4411"</td>".4412"</tr>\n";4413}4414}44154416sub git_print_page_path {4417my$name=shift;4418my$type=shift;4419my$hb=shift;442044214422print"<div class=\"page_path\">";4423print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),4424-title =>'tree root'}, to_utf8("[$project]"));4425print" / ";4426if(defined$name) {4427my@dirname=split'/',$name;4428my$basename=pop@dirname;4429my$fullname='';44304431foreachmy$dir(@dirname) {4432$fullname.= ($fullname?'/':'') .$dir;4433print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,4434 hash_base=>$hb),4435-title =>$fullname}, esc_path($dir));4436print" / ";4437}4438if(defined$type&&$typeeq'blob') {4439print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,4440 hash_base=>$hb),4441-title =>$name}, esc_path($basename));4442}elsif(defined$type&&$typeeq'tree') {4443print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,4444 hash_base=>$hb),4445-title =>$name}, esc_path($basename));4446print" / ";4447}else{4448print esc_path($basename);4449}4450}4451print"<br/></div>\n";4452}44534454sub git_print_log {4455my$log=shift;4456my%opts=@_;44574458if($opts{'-remove_title'}) {4459# remove title, i.e. first line of log4460shift@$log;4461}4462# remove leading empty lines4463while(defined$log->[0] &&$log->[0]eq"") {4464shift@$log;4465}44664467# print log4468my$signoff=0;4469my$empty=0;4470foreachmy$line(@$log) {4471if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {4472$signoff=1;4473$empty=0;4474if(!$opts{'-remove_signoff'}) {4475print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";4476next;4477}else{4478# remove signoff lines4479next;4480}4481}else{4482$signoff=0;4483}44844485# print only one empty line4486# do not print empty line after signoff4487if($lineeq"") {4488next if($empty||$signoff);4489$empty=1;4490}else{4491$empty=0;4492}44934494print format_log_line_html($line) ."<br/>\n";4495}44964497if($opts{'-final_empty_line'}) {4498# end with single empty line4499print"<br/>\n"unless$empty;4500}4501}45024503# return link target (what link points to)4504sub git_get_link_target {4505my$hash=shift;4506my$link_target;45074508# read link4509open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4510orreturn;4511{4512local$/=undef;4513$link_target= <$fd>;4514}4515close$fd4516orreturn;45174518return$link_target;4519}45204521# given link target, and the directory (basedir) the link is in,4522# return target of link relative to top directory (top tree);4523# return undef if it is not possible (including absolute links).4524sub normalize_link_target {4525my($link_target,$basedir) =@_;45264527# absolute symlinks (beginning with '/') cannot be normalized4528return if(substr($link_target,0,1)eq'/');45294530# normalize link target to path from top (root) tree (dir)4531my$path;4532if($basedir) {4533$path=$basedir.'/'.$link_target;4534}else{4535# we are in top (root) tree (dir)4536$path=$link_target;4537}45384539# remove //, /./, and /../4540my@path_parts;4541foreachmy$part(split('/',$path)) {4542# discard '.' and ''4543next if(!$part||$parteq'.');4544# handle '..'4545if($parteq'..') {4546if(@path_parts) {4547pop@path_parts;4548}else{4549# link leads outside repository (outside top dir)4550return;4551}4552}else{4553push@path_parts,$part;4554}4555}4556$path=join('/',@path_parts);45574558return$path;4559}45604561# print tree entry (row of git_tree), but without encompassing <tr> element4562sub git_print_tree_entry {4563my($t,$basedir,$hash_base,$have_blame) =@_;45644565my%base_key= ();4566$base_key{'hash_base'} =$hash_baseifdefined$hash_base;45674568# The format of a table row is: mode list link. Where mode is4569# the mode of the entry, list is the name of the entry, an href,4570# and link is the action links of the entry.45714572print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";4573if(exists$t->{'size'}) {4574print"<td class=\"size\">$t->{'size'}</td>\n";4575}4576if($t->{'type'}eq"blob") {4577print"<td class=\"list\">".4578$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4579 file_name=>"$basedir$t->{'name'}",%base_key),4580-class=>"list"}, esc_path($t->{'name'}));4581if(S_ISLNK(oct$t->{'mode'})) {4582my$link_target= git_get_link_target($t->{'hash'});4583if($link_target) {4584my$norm_target= normalize_link_target($link_target,$basedir);4585if(defined$norm_target) {4586print" -> ".4587$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,4588 file_name=>$norm_target),4589-title =>$norm_target}, esc_path($link_target));4590}else{4591print" -> ". esc_path($link_target);4592}4593}4594}4595print"</td>\n";4596print"<td class=\"link\">";4597print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4598 file_name=>"$basedir$t->{'name'}",%base_key)},4599"blob");4600if($have_blame) {4601print" | ".4602$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},4603 file_name=>"$basedir$t->{'name'}",%base_key)},4604"blame");4605}4606if(defined$hash_base) {4607print" | ".4608$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,4609 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},4610"history");4611}4612print" | ".4613$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,4614 file_name=>"$basedir$t->{'name'}")},4615"raw");4616print"</td>\n";46174618}elsif($t->{'type'}eq"tree") {4619print"<td class=\"list\">";4620print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},4621 file_name=>"$basedir$t->{'name'}",4622%base_key)},4623 esc_path($t->{'name'}));4624print"</td>\n";4625print"<td class=\"link\">";4626print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},4627 file_name=>"$basedir$t->{'name'}",4628%base_key)},4629"tree");4630if(defined$hash_base) {4631print" | ".4632$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,4633 file_name=>"$basedir$t->{'name'}")},4634"history");4635}4636print"</td>\n";4637}else{4638# unknown object: we can only present history for it4639# (this includes 'commit' object, i.e. submodule support)4640print"<td class=\"list\">".4641 esc_path($t->{'name'}) .4642"</td>\n";4643print"<td class=\"link\">";4644if(defined$hash_base) {4645print$cgi->a({-href => href(action=>"history",4646 hash_base=>$hash_base,4647 file_name=>"$basedir$t->{'name'}")},4648"history");4649}4650print"</td>\n";4651}4652}46534654## ......................................................................4655## functions printing large fragments of HTML46564657# get pre-image filenames for merge (combined) diff4658sub fill_from_file_info {4659my($diff,@parents) =@_;46604661$diff->{'from_file'} = [ ];4662$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;4663for(my$i=0;$i<$diff->{'nparents'};$i++) {4664if($diff->{'status'}[$i]eq'R'||4665$diff->{'status'}[$i]eq'C') {4666$diff->{'from_file'}[$i] =4667 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);4668}4669}46704671return$diff;4672}46734674# is current raw difftree line of file deletion4675sub is_deleted {4676my$diffinfo=shift;46774678return$diffinfo->{'to_id'}eq('0' x 40);4679}46804681# does patch correspond to [previous] difftree raw line4682# $diffinfo - hashref of parsed raw diff format4683# $patchinfo - hashref of parsed patch diff format4684# (the same keys as in $diffinfo)4685sub is_patch_split {4686my($diffinfo,$patchinfo) =@_;46874688returndefined$diffinfo&&defined$patchinfo4689&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};4690}469146924693sub git_difftree_body {4694my($difftree,$hash,@parents) =@_;4695my($parent) =$parents[0];4696my$have_blame= gitweb_check_feature('blame');4697print"<div class=\"list_head\">\n";4698if($#{$difftree} >10) {4699print(($#{$difftree} +1) ." files changed:\n");4700}4701print"</div>\n";47024703print"<table class=\"".4704(@parents>1?"combined ":"") .4705"diff_tree\">\n";47064707# header only for combined diff in 'commitdiff' view4708my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';4709if($has_header) {4710# table header4711print"<thead><tr>\n".4712"<th></th><th></th>\n";# filename, patchN link4713for(my$i=0;$i<@parents;$i++) {4714my$par=$parents[$i];4715print"<th>".4716$cgi->a({-href => href(action=>"commitdiff",4717 hash=>$hash, hash_parent=>$par),4718-title =>'commitdiff to parent number '.4719($i+1) .': '.substr($par,0,7)},4720$i+1) .4721" </th>\n";4722}4723print"</tr></thead>\n<tbody>\n";4724}47254726my$alternate=1;4727my$patchno=0;4728foreachmy$line(@{$difftree}) {4729my$diff= parsed_difftree_line($line);47304731if($alternate) {4732print"<tr class=\"dark\">\n";4733}else{4734print"<tr class=\"light\">\n";4735}4736$alternate^=1;47374738if(exists$diff->{'nparents'}) {# combined diff47394740 fill_from_file_info($diff,@parents)4741unlessexists$diff->{'from_file'};47424743if(!is_deleted($diff)) {4744# file exists in the result (child) commit4745print"<td>".4746$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4747 file_name=>$diff->{'to_file'},4748 hash_base=>$hash),4749-class=>"list"}, esc_path($diff->{'to_file'})) .4750"</td>\n";4751}else{4752print"<td>".4753 esc_path($diff->{'to_file'}) .4754"</td>\n";4755}47564757if($actioneq'commitdiff') {4758# link to patch4759$patchno++;4760print"<td class=\"link\">".4761$cgi->a({-href => href(-anchor=>"patch$patchno")},4762"patch") .4763" | ".4764"</td>\n";4765}47664767my$has_history=0;4768my$not_deleted=0;4769for(my$i=0;$i<$diff->{'nparents'};$i++) {4770my$hash_parent=$parents[$i];4771my$from_hash=$diff->{'from_id'}[$i];4772my$from_path=$diff->{'from_file'}[$i];4773my$status=$diff->{'status'}[$i];47744775$has_history||= ($statusne'A');4776$not_deleted||= ($statusne'D');47774778if($statuseq'A') {4779print"<td class=\"link\"align=\"right\"> | </td>\n";4780}elsif($statuseq'D') {4781print"<td class=\"link\">".4782$cgi->a({-href => href(action=>"blob",4783 hash_base=>$hash,4784 hash=>$from_hash,4785 file_name=>$from_path)},4786"blob". ($i+1)) .4787" | </td>\n";4788}else{4789if($diff->{'to_id'}eq$from_hash) {4790print"<td class=\"link nochange\">";4791}else{4792print"<td class=\"link\">";4793}4794print$cgi->a({-href => href(action=>"blobdiff",4795 hash=>$diff->{'to_id'},4796 hash_parent=>$from_hash,4797 hash_base=>$hash,4798 hash_parent_base=>$hash_parent,4799 file_name=>$diff->{'to_file'},4800 file_parent=>$from_path)},4801"diff". ($i+1)) .4802" | </td>\n";4803}4804}48054806print"<td class=\"link\">";4807if($not_deleted) {4808print$cgi->a({-href => href(action=>"blob",4809 hash=>$diff->{'to_id'},4810 file_name=>$diff->{'to_file'},4811 hash_base=>$hash)},4812"blob");4813print" | "if($has_history);4814}4815if($has_history) {4816print$cgi->a({-href => href(action=>"history",4817 file_name=>$diff->{'to_file'},4818 hash_base=>$hash)},4819"history");4820}4821print"</td>\n";48224823print"</tr>\n";4824next;# instead of 'else' clause, to avoid extra indent4825}4826# else ordinary diff48274828my($to_mode_oct,$to_mode_str,$to_file_type);4829my($from_mode_oct,$from_mode_str,$from_file_type);4830if($diff->{'to_mode'}ne('0' x 6)) {4831$to_mode_oct=oct$diff->{'to_mode'};4832if(S_ISREG($to_mode_oct)) {# only for regular file4833$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits4834}4835$to_file_type= file_type($diff->{'to_mode'});4836}4837if($diff->{'from_mode'}ne('0' x 6)) {4838$from_mode_oct=oct$diff->{'from_mode'};4839if(S_ISREG($from_mode_oct)) {# only for regular file4840$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits4841}4842$from_file_type= file_type($diff->{'from_mode'});4843}48444845if($diff->{'status'}eq"A") {# created4846my$mode_chng="<span class=\"file_status new\">[new$to_file_type";4847$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;4848$mode_chng.="]</span>";4849print"<td>";4850print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4851 hash_base=>$hash, file_name=>$diff->{'file'}),4852-class=>"list"}, esc_path($diff->{'file'}));4853print"</td>\n";4854print"<td>$mode_chng</td>\n";4855print"<td class=\"link\">";4856if($actioneq'commitdiff') {4857# link to patch4858$patchno++;4859print$cgi->a({-href => href(-anchor=>"patch$patchno")},4860"patch") .4861" | ";4862}4863print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4864 hash_base=>$hash, file_name=>$diff->{'file'})},4865"blob");4866print"</td>\n";48674868}elsif($diff->{'status'}eq"D") {# deleted4869my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";4870print"<td>";4871print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4872 hash_base=>$parent, file_name=>$diff->{'file'}),4873-class=>"list"}, esc_path($diff->{'file'}));4874print"</td>\n";4875print"<td>$mode_chng</td>\n";4876print"<td class=\"link\">";4877if($actioneq'commitdiff') {4878# link to patch4879$patchno++;4880print$cgi->a({-href => href(-anchor=>"patch$patchno")},4881"patch") .4882" | ";4883}4884print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4885 hash_base=>$parent, file_name=>$diff->{'file'})},4886"blob") ." | ";4887if($have_blame) {4888print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,4889 file_name=>$diff->{'file'})},4890"blame") ." | ";4891}4892print$cgi->a({-href => href(action=>"history", hash_base=>$parent,4893 file_name=>$diff->{'file'})},4894"history");4895print"</td>\n";48964897}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed4898my$mode_chnge="";4899if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4900$mode_chnge="<span class=\"file_status mode_chnge\">[changed";4901if($from_file_typene$to_file_type) {4902$mode_chnge.=" from$from_file_typeto$to_file_type";4903}4904if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {4905if($from_mode_str&&$to_mode_str) {4906$mode_chnge.=" mode:$from_mode_str->$to_mode_str";4907}elsif($to_mode_str) {4908$mode_chnge.=" mode:$to_mode_str";4909}4910}4911$mode_chnge.="]</span>\n";4912}4913print"<td>";4914print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4915 hash_base=>$hash, file_name=>$diff->{'file'}),4916-class=>"list"}, esc_path($diff->{'file'}));4917print"</td>\n";4918print"<td>$mode_chnge</td>\n";4919print"<td class=\"link\">";4920if($actioneq'commitdiff') {4921# link to patch4922$patchno++;4923print$cgi->a({-href => href(-anchor=>"patch$patchno")},4924"patch") .4925" | ";4926}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4927# "commit" view and modified file (not onlu mode changed)4928print$cgi->a({-href => href(action=>"blobdiff",4929 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4930 hash_base=>$hash, hash_parent_base=>$parent,4931 file_name=>$diff->{'file'})},4932"diff") .4933" | ";4934}4935print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4936 hash_base=>$hash, file_name=>$diff->{'file'})},4937"blob") ." | ";4938if($have_blame) {4939print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4940 file_name=>$diff->{'file'})},4941"blame") ." | ";4942}4943print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4944 file_name=>$diff->{'file'})},4945"history");4946print"</td>\n";49474948}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied4949my%status_name= ('R'=>'moved','C'=>'copied');4950my$nstatus=$status_name{$diff->{'status'}};4951my$mode_chng="";4952if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4953# mode also for directories, so we cannot use $to_mode_str4954$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);4955}4956print"<td>".4957$cgi->a({-href => href(action=>"blob", hash_base=>$hash,4958 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),4959-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".4960"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".4961$cgi->a({-href => href(action=>"blob", hash_base=>$parent,4962 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),4963-class=>"list"}, esc_path($diff->{'from_file'})) .4964" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".4965"<td class=\"link\">";4966if($actioneq'commitdiff') {4967# link to patch4968$patchno++;4969print$cgi->a({-href => href(-anchor=>"patch$patchno")},4970"patch") .4971" | ";4972}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4973# "commit" view and modified file (not only pure rename or copy)4974print$cgi->a({-href => href(action=>"blobdiff",4975 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4976 hash_base=>$hash, hash_parent_base=>$parent,4977 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},4978"diff") .4979" | ";4980}4981print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4982 hash_base=>$parent, file_name=>$diff->{'to_file'})},4983"blob") ." | ";4984if($have_blame) {4985print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4986 file_name=>$diff->{'to_file'})},4987"blame") ." | ";4988}4989print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4990 file_name=>$diff->{'to_file'})},4991"history");4992print"</td>\n";49934994}# we should not encounter Unmerged (U) or Unknown (X) status4995print"</tr>\n";4996}4997print"</tbody>"if$has_header;4998print"</table>\n";4999}50005001sub print_sidebyside_diff_chunk {5002my@chunk=@_;5003my(@ctx,@rem,@add);50045005return unless@chunk;50065007# incomplete last line might be among removed or added lines,5008# or both, or among context lines: find which5009for(my$i=1;$i<@chunk;$i++) {5010if($chunk[$i][0]eq'incomplete') {5011$chunk[$i][0] =$chunk[$i-1][0];5012}5013}50145015# guardian5016push@chunk, ["",""];50175018foreachmy$line_info(@chunk) {5019my($class,$line) =@$line_info;50205021# print chunk headers5022if($class&&$classeq'chunk_header') {5023print$line;5024next;5025}50265027## print from accumulator when type of class of lines change5028# empty contents block on start rem/add block, or end of chunk5029if(@ctx&& (!$class||$classeq'rem'||$classeq'add')) {5030print join'',5031'<div class="chunk_block ctx">',5032'<div class="old">',5033@ctx,5034'</div>',5035'<div class="new">',5036@ctx,5037'</div>',5038'</div>';5039@ctx= ();5040}5041# empty add/rem block on start context block, or end of chunk5042if((@rem||@add) && (!$class||$classeq'ctx')) {5043if(!@add) {5044# pure removal5045print join'',5046'<div class="chunk_block rem">',5047'<div class="old">',5048@rem,5049'</div>',5050'</div>';5051}elsif(!@rem) {5052# pure addition5053print join'',5054'<div class="chunk_block add">',5055'<div class="new">',5056@add,5057'</div>',5058'</div>';5059}else{5060# assume that it is change5061print join'',5062'<div class="chunk_block chg">',5063'<div class="old">',5064@rem,5065'</div>',5066'<div class="new">',5067@add,5068'</div>',5069'</div>';5070}5071@rem=@add= ();5072}50735074## adding lines to accumulator5075# guardian value5076last unless$line;5077# rem, add or change5078if($classeq'rem') {5079push@rem,$line;5080}elsif($classeq'add') {5081push@add,$line;5082}5083# context line5084if($classeq'ctx') {5085push@ctx,$line;5086}5087}5088}50895090sub git_patchset_body {5091my($fd,$diff_style,$difftree,$hash,@hash_parents) =@_;5092my($hash_parent) =$hash_parents[0];50935094my$is_combined= (@hash_parents>1);5095my$patch_idx=0;5096my$patch_number=0;5097my$patch_line;5098my$diffinfo;5099my$to_name;5100my(%from,%to);5101my@chunk;# for side-by-side diff51025103print"<div class=\"patchset\">\n";51045105# skip to first patch5106while($patch_line= <$fd>) {5107chomp$patch_line;51085109last if($patch_line=~m/^diff /);5110}51115112 PATCH:5113while($patch_line) {51145115# parse "git diff" header line5116if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {5117# $1 is from_name, which we do not use5118$to_name= unquote($2);5119$to_name=~s!^b/!!;5120}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {5121# $1 is 'cc' or 'combined', which we do not use5122$to_name= unquote($2);5123}else{5124$to_name=undef;5125}51265127# check if current patch belong to current raw line5128# and parse raw git-diff line if needed5129if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {5130# this is continuation of a split patch5131print"<div class=\"patch cont\">\n";5132}else{5133# advance raw git-diff output if needed5134$patch_idx++ifdefined$diffinfo;51355136# read and prepare patch information5137$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);51385139# compact combined diff output can have some patches skipped5140# find which patch (using pathname of result) we are at now;5141if($is_combined) {5142while($to_namene$diffinfo->{'to_file'}) {5143print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".5144 format_diff_cc_simplified($diffinfo,@hash_parents) .5145"</div>\n";# class="patch"51465147$patch_idx++;5148$patch_number++;51495150last if$patch_idx>$#$difftree;5151$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);5152}5153}51545155# modifies %from, %to hashes5156 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);51575158# this is first patch for raw difftree line with $patch_idx index5159# we index @$difftree array from 0, but number patches from 15160print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";5161}51625163# git diff header5164#assert($patch_line =~ m/^diff /) if DEBUG;5165#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed5166$patch_number++;5167# print "git diff" header5168print format_git_diff_header_line($patch_line,$diffinfo,5169 \%from, \%to);51705171# print extended diff header5172print"<div class=\"diff extended_header\">\n";5173 EXTENDED_HEADER:5174while($patch_line= <$fd>) {5175chomp$patch_line;51765177last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);51785179print format_extended_diff_header_line($patch_line,$diffinfo,5180 \%from, \%to);5181}5182print"</div>\n";# class="diff extended_header"51835184# from-file/to-file diff header5185if(!$patch_line) {5186print"</div>\n";# class="patch"5187last PATCH;5188}5189next PATCH if($patch_line=~m/^diff /);5190#assert($patch_line =~ m/^---/) if DEBUG;51915192my$last_patch_line=$patch_line;5193$patch_line= <$fd>;5194chomp$patch_line;5195#assert($patch_line =~ m/^\+\+\+/) if DEBUG;51965197print format_diff_from_to_header($last_patch_line,$patch_line,5198$diffinfo, \%from, \%to,5199@hash_parents);52005201# the patch itself5202 LINE:5203while($patch_line= <$fd>) {5204chomp$patch_line;52055206next PATCH if($patch_line=~m/^diff /);52075208my($class,$line) = process_diff_line($patch_line, \%from, \%to);5209my$diff_classes="diff";5210$diff_classes.="$class"if($class);5211$line="<div class=\"$diff_classes\">$line</div>\n";52125213if($diff_styleeq'sidebyside'&& !$is_combined) {5214if($classeq'chunk_header') {5215 print_sidebyside_diff_chunk(@chunk);5216@chunk= ( [$class,$line] );5217}else{5218push@chunk, [$class,$line];5219}5220}else{5221# default 'inline' style and unknown styles5222print$line;5223}5224}52255226}continue{5227if(@chunk) {5228 print_sidebyside_diff_chunk(@chunk);5229@chunk= ();5230}5231print"</div>\n";# class="patch"5232}52335234# for compact combined (--cc) format, with chunk and patch simplification5235# the patchset might be empty, but there might be unprocessed raw lines5236for(++$patch_idxif$patch_number>0;5237$patch_idx<@$difftree;5238++$patch_idx) {5239# read and prepare patch information5240$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);52415242# generate anchor for "patch" links in difftree / whatchanged part5243print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".5244 format_diff_cc_simplified($diffinfo,@hash_parents) .5245"</div>\n";# class="patch"52465247$patch_number++;5248}52495250if($patch_number==0) {5251if(@hash_parents>1) {5252print"<div class=\"diff nodifferences\">Trivial merge</div>\n";5253}else{5254print"<div class=\"diff nodifferences\">No differences found</div>\n";5255}5256}52575258print"</div>\n";# class="patchset"5259}52605261# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .52625263sub git_project_search_form {5264my($searchtext,$search_use_regexp) =@_;52655266my$limit='';5267if($project_filter) {5268$limit=" in '$project_filter/'";5269}52705271print"<div class=\"projsearch\">\n";5272print$cgi->startform(-method=>'get', -action =>$my_uri) .5273$cgi->hidden(-name =>'a', -value =>'project_list') ."\n";5274print$cgi->hidden(-name =>'pf', -value =>$project_filter)."\n"5275if(defined$project_filter);5276print$cgi->textfield(-name =>'s', -value =>$searchtext,5277-title =>"Search project by name and description$limit",5278-size =>60) ."\n".5279"<span title=\"Extended regular expression\">".5280$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',5281-checked =>$search_use_regexp) .5282"</span>\n".5283$cgi->submit(-name =>'btnS', -value =>'Search') .5284$cgi->end_form() ."\n".5285$cgi->a({-href => href(project =>undef, searchtext =>undef,5286 project_filter =>$project_filter)},5287 esc_html("List all projects$limit")) ."<br />\n";5288print"</div>\n";5289}52905291# entry for given @keys needs filling if at least one of keys in list5292# is not present in %$project_info5293sub project_info_needs_filling {5294my($project_info,@keys) =@_;52955296# return List::MoreUtils::any { !exists $project_info->{$_} } @keys;5297foreachmy$key(@keys) {5298if(!exists$project_info->{$key}) {5299return1;5300}5301}5302return;5303}53045305# fills project list info (age, description, owner, category, forks, etc.)5306# for each project in the list, removing invalid projects from5307# returned list, or fill only specified info.5308#5309# Invalid projects are removed from the returned list if and only if you5310# ask 'age' or 'age_string' to be filled, because they are the only fields5311# that run unconditionally git command that requires repository, and5312# therefore do always check if project repository is invalid.5313#5314# USAGE:5315# * fill_project_list_info(\@project_list, 'descr_long', 'ctags')5316# ensures that 'descr_long' and 'ctags' fields are filled5317# * @project_list = fill_project_list_info(\@project_list)5318# ensures that all fields are filled (and invalid projects removed)5319#5320# NOTE: modifies $projlist, but does not remove entries from it5321sub fill_project_list_info {5322my($projlist,@wanted_keys) =@_;5323my@projects;5324my$filter_set=sub{return@_; };5325if(@wanted_keys) {5326my%wanted_keys=map{$_=>1}@wanted_keys;5327$filter_set=sub{returngrep{$wanted_keys{$_} }@_; };5328}53295330my$show_ctags= gitweb_check_feature('ctags');5331 PROJECT:5332foreachmy$pr(@$projlist) {5333if(project_info_needs_filling($pr,$filter_set->('age','age_string'))) {5334my(@activity) = git_get_last_activity($pr->{'path'});5335unless(@activity) {5336next PROJECT;5337}5338($pr->{'age'},$pr->{'age_string'}) =@activity;5339}5340if(project_info_needs_filling($pr,$filter_set->('descr','descr_long'))) {5341my$descr= git_get_project_description($pr->{'path'}) ||"";5342$descr= to_utf8($descr);5343$pr->{'descr_long'} =$descr;5344$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);5345}5346if(project_info_needs_filling($pr,$filter_set->('owner'))) {5347$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";5348}5349if($show_ctags&&5350 project_info_needs_filling($pr,$filter_set->('ctags'))) {5351$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});5352}5353if($projects_list_group_categories&&5354 project_info_needs_filling($pr,$filter_set->('category'))) {5355my$cat= git_get_project_category($pr->{'path'}) ||5356$project_list_default_category;5357$pr->{'category'} = to_utf8($cat);5358}53595360push@projects,$pr;5361}53625363return@projects;5364}53655366sub sort_projects_list {5367my($projlist,$order) =@_;5368my@projects;53695370my%order_info= (5371 project => { key =>'path', type =>'str'},5372 descr => { key =>'descr_long', type =>'str'},5373 owner => { key =>'owner', type =>'str'},5374 age => { key =>'age', type =>'num'}5375);5376my$oi=$order_info{$order};5377return@$projlistunlessdefined$oi;5378if($oi->{'type'}eq'str') {5379@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@$projlist;5380}else{5381@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@$projlist;5382}53835384return@projects;5385}53865387# returns a hash of categories, containing the list of project5388# belonging to each category5389sub build_projlist_by_category {5390my($projlist,$from,$to) =@_;5391my%categories;53925393$from=0unlessdefined$from;5394$to=$#$projlistif(!defined$to||$#$projlist<$to);53955396for(my$i=$from;$i<=$to;$i++) {5397my$pr=$projlist->[$i];5398push@{$categories{$pr->{'category'} }},$pr;5399}54005401returnwantarray?%categories: \%categories;5402}54035404# print 'sort by' <th> element, generating 'sort by $name' replay link5405# if that order is not selected5406sub print_sort_th {5407print format_sort_th(@_);5408}54095410sub format_sort_th {5411my($name,$order,$header) =@_;5412my$sort_th="";5413$header||=ucfirst($name);54145415if($ordereq$name) {5416$sort_th.="<th>$header</th>\n";5417}else{5418$sort_th.="<th>".5419$cgi->a({-href => href(-replay=>1, order=>$name),5420-class=>"header"},$header) .5421"</th>\n";5422}54235424return$sort_th;5425}54265427sub git_project_list_rows {5428my($projlist,$from,$to,$check_forks) =@_;54295430$from=0unlessdefined$from;5431$to=$#$projlistif(!defined$to||$#$projlist<$to);54325433my$alternate=1;5434for(my$i=$from;$i<=$to;$i++) {5435my$pr=$projlist->[$i];54365437if($alternate) {5438print"<tr class=\"dark\">\n";5439}else{5440print"<tr class=\"light\">\n";5441}5442$alternate^=1;54435444if($check_forks) {5445print"<td>";5446if($pr->{'forks'}) {5447my$nforks=scalar@{$pr->{'forks'}};5448if($nforks>0) {5449print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks"),5450-title =>"$nforksforks"},"+");5451}else{5452print$cgi->span({-title =>"$nforksforks"},"+");5453}5454}5455print"</td>\n";5456}5457print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),5458-class=>"list"},5459 esc_html_match_hl($pr->{'path'},$search_regexp)) .5460"</td>\n".5461"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),5462-class=>"list",5463-title =>$pr->{'descr_long'}},5464$search_regexp5465? esc_html_match_hl_chopped($pr->{'descr_long'},5466$pr->{'descr'},$search_regexp)5467: esc_html($pr->{'descr'})) .5468"</td>\n".5469"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";5470print"<td class=\"". age_class($pr->{'age'}) ."\">".5471(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".5472"<td class=\"link\">".5473$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".5474$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".5475$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".5476$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .5477($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .5478"</td>\n".5479"</tr>\n";5480}5481}54825483sub git_project_list_body {5484# actually uses global variable $project5485my($projlist,$order,$from,$to,$extra,$no_header) =@_;5486my@projects=@$projlist;54875488my$check_forks= gitweb_check_feature('forks');5489my$show_ctags= gitweb_check_feature('ctags');5490my$tagfilter=$show_ctags?$input_params{'ctag'} :undef;5491$check_forks=undef5492if($tagfilter||$search_regexp);54935494# filtering out forks before filling info allows to do less work5495@projects= filter_forks_from_projects_list(\@projects)5496if($check_forks);5497# search_projects_list pre-fills required info5498@projects= search_projects_list(\@projects,5499'search_regexp'=>$search_regexp,5500'tagfilter'=>$tagfilter)5501if($tagfilter||$search_regexp);5502# fill the rest5503@projects= fill_project_list_info(\@projects);55045505$order||=$default_projects_order;5506$from=0unlessdefined$from;5507$to=$#projectsif(!defined$to||$#projects<$to);55085509# short circuit5510if($from>$to) {5511print"<center>\n".5512"<b>No such projects found</b><br />\n".5513"Click ".$cgi->a({-href=>href(project=>undef)},"here")." to view all projects<br />\n".5514"</center>\n<br />\n";5515return;5516}55175518@projects= sort_projects_list(\@projects,$order);55195520if($show_ctags) {5521my$ctags= git_gather_all_ctags(\@projects);5522my$cloud= git_populate_project_tagcloud($ctags);5523print git_show_project_tagcloud($cloud,64);5524}55255526print"<table class=\"project_list\">\n";5527unless($no_header) {5528print"<tr>\n";5529if($check_forks) {5530print"<th></th>\n";5531}5532 print_sort_th('project',$order,'Project');5533 print_sort_th('descr',$order,'Description');5534 print_sort_th('owner',$order,'Owner');5535 print_sort_th('age',$order,'Last Change');5536print"<th></th>\n".# for links5537"</tr>\n";5538}55395540if($projects_list_group_categories) {5541# only display categories with projects in the $from-$to window5542@projects=sort{$a->{'category'}cmp$b->{'category'}}@projects[$from..$to];5543my%categories= build_projlist_by_category(\@projects,$from,$to);5544foreachmy$cat(sort keys%categories) {5545unless($cateq"") {5546print"<tr>\n";5547if($check_forks) {5548print"<td></td>\n";5549}5550print"<td class=\"category\"colspan=\"5\">".esc_html($cat)."</td>\n";5551print"</tr>\n";5552}55535554 git_project_list_rows($categories{$cat},undef,undef,$check_forks);5555}5556}else{5557 git_project_list_rows(\@projects,$from,$to,$check_forks);5558}55595560if(defined$extra) {5561print"<tr>\n";5562if($check_forks) {5563print"<td></td>\n";5564}5565print"<td colspan=\"5\">$extra</td>\n".5566"</tr>\n";5567}5568print"</table>\n";5569}55705571sub git_log_body {5572# uses global variable $project5573my($commitlist,$from,$to,$refs,$extra) =@_;55745575$from=0unlessdefined$from;5576$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);55775578for(my$i=0;$i<=$to;$i++) {5579my%co= %{$commitlist->[$i]};5580next if!%co;5581my$commit=$co{'id'};5582my$ref= format_ref_marker($refs,$commit);5583 git_print_header_div('commit',5584"<span class=\"age\">$co{'age_string'}</span>".5585 esc_html($co{'title'}) .$ref,5586$commit);5587print"<div class=\"title_text\">\n".5588"<div class=\"log_link\">\n".5589$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .5590" | ".5591$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .5592" | ".5593$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .5594"<br/>\n".5595"</div>\n";5596 git_print_authorship(\%co, -tag =>'span');5597print"<br/>\n</div>\n";55985599print"<div class=\"log_body\">\n";5600 git_print_log($co{'comment'}, -final_empty_line=>1);5601print"</div>\n";5602}5603if($extra) {5604print"<div class=\"page_nav\">\n";5605print"$extra\n";5606print"</div>\n";5607}5608}56095610sub git_shortlog_body {5611# uses global variable $project5612my($commitlist,$from,$to,$refs,$extra) =@_;56135614$from=0unlessdefined$from;5615$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);56165617print"<table class=\"shortlog\">\n";5618my$alternate=1;5619for(my$i=$from;$i<=$to;$i++) {5620my%co= %{$commitlist->[$i]};5621my$commit=$co{'id'};5622my$ref= format_ref_marker($refs,$commit);5623if($alternate) {5624print"<tr class=\"dark\">\n";5625}else{5626print"<tr class=\"light\">\n";5627}5628$alternate^=1;5629# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .5630print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5631 format_author_html('td', \%co,10) ."<td>";5632print format_subject_html($co{'title'},$co{'title_short'},5633 href(action=>"commit", hash=>$commit),$ref);5634print"</td>\n".5635"<td class=\"link\">".5636$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".5637$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".5638$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");5639my$snapshot_links= format_snapshot_links($commit);5640if(defined$snapshot_links) {5641print" | ".$snapshot_links;5642}5643print"</td>\n".5644"</tr>\n";5645}5646if(defined$extra) {5647print"<tr>\n".5648"<td colspan=\"4\">$extra</td>\n".5649"</tr>\n";5650}5651print"</table>\n";5652}56535654sub git_history_body {5655# Warning: assumes constant type (blob or tree) during history5656my($commitlist,$from,$to,$refs,$extra,5657$file_name,$file_hash,$ftype) =@_;56585659$from=0unlessdefined$from;5660$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});56615662print"<table class=\"history\">\n";5663my$alternate=1;5664for(my$i=$from;$i<=$to;$i++) {5665my%co= %{$commitlist->[$i]};5666if(!%co) {5667next;5668}5669my$commit=$co{'id'};56705671my$ref= format_ref_marker($refs,$commit);56725673if($alternate) {5674print"<tr class=\"dark\">\n";5675}else{5676print"<tr class=\"light\">\n";5677}5678$alternate^=1;5679print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5680# shortlog: format_author_html('td', \%co, 10)5681 format_author_html('td', \%co,15,3) ."<td>";5682# originally git_history used chop_str($co{'title'}, 50)5683print format_subject_html($co{'title'},$co{'title_short'},5684 href(action=>"commit", hash=>$commit),$ref);5685print"</td>\n".5686"<td class=\"link\">".5687$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".5688$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");56895690if($ftypeeq'blob') {5691my$blob_current=$file_hash;5692my$blob_parent= git_get_hash_by_path($commit,$file_name);5693if(defined$blob_current&&defined$blob_parent&&5694$blob_currentne$blob_parent) {5695print" | ".5696$cgi->a({-href => href(action=>"blobdiff",5697 hash=>$blob_current, hash_parent=>$blob_parent,5698 hash_base=>$hash_base, hash_parent_base=>$commit,5699 file_name=>$file_name)},5700"diff to current");5701}5702}5703print"</td>\n".5704"</tr>\n";5705}5706if(defined$extra) {5707print"<tr>\n".5708"<td colspan=\"4\">$extra</td>\n".5709"</tr>\n";5710}5711print"</table>\n";5712}57135714sub git_tags_body {5715# uses global variable $project5716my($taglist,$from,$to,$extra) =@_;5717$from=0unlessdefined$from;5718$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);57195720print"<table class=\"tags\">\n";5721my$alternate=1;5722for(my$i=$from;$i<=$to;$i++) {5723my$entry=$taglist->[$i];5724my%tag=%$entry;5725my$comment=$tag{'subject'};5726my$comment_short;5727if(defined$comment) {5728$comment_short= chop_str($comment,30,5);5729}5730if($alternate) {5731print"<tr class=\"dark\">\n";5732}else{5733print"<tr class=\"light\">\n";5734}5735$alternate^=1;5736if(defined$tag{'age'}) {5737print"<td><i>$tag{'age'}</i></td>\n";5738}else{5739print"<td></td>\n";5740}5741print"<td>".5742$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),5743-class=>"list name"}, esc_html($tag{'name'})) .5744"</td>\n".5745"<td>";5746if(defined$comment) {5747print format_subject_html($comment,$comment_short,5748 href(action=>"tag", hash=>$tag{'id'}));5749}5750print"</td>\n".5751"<td class=\"selflink\">";5752if($tag{'type'}eq"tag") {5753print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");5754}else{5755print" ";5756}5757print"</td>\n".5758"<td class=\"link\">"." | ".5759$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});5760if($tag{'reftype'}eq"commit") {5761print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .5762" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");5763}elsif($tag{'reftype'}eq"blob") {5764print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");5765}5766print"</td>\n".5767"</tr>";5768}5769if(defined$extra) {5770print"<tr>\n".5771"<td colspan=\"5\">$extra</td>\n".5772"</tr>\n";5773}5774print"</table>\n";5775}57765777sub git_heads_body {5778# uses global variable $project5779my($headlist,$head_at,$from,$to,$extra) =@_;5780$from=0unlessdefined$from;5781$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);57825783print"<table class=\"heads\">\n";5784my$alternate=1;5785for(my$i=$from;$i<=$to;$i++) {5786my$entry=$headlist->[$i];5787my%ref=%$entry;5788my$curr=defined$head_at&&$ref{'id'}eq$head_at;5789if($alternate) {5790print"<tr class=\"dark\">\n";5791}else{5792print"<tr class=\"light\">\n";5793}5794$alternate^=1;5795print"<td><i>$ref{'age'}</i></td>\n".5796($curr?"<td class=\"current_head\">":"<td>") .5797$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),5798-class=>"list name"},esc_html($ref{'name'})) .5799"</td>\n".5800"<td class=\"link\">".5801$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".5802$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".5803$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'fullname'})},"tree") .5804"</td>\n".5805"</tr>";5806}5807if(defined$extra) {5808print"<tr>\n".5809"<td colspan=\"3\">$extra</td>\n".5810"</tr>\n";5811}5812print"</table>\n";5813}58145815# Display a single remote block5816sub git_remote_block {5817my($remote,$rdata,$limit,$head) =@_;58185819my$heads=$rdata->{'heads'};5820my$fetch=$rdata->{'fetch'};5821my$push=$rdata->{'push'};58225823my$urls_table="<table class=\"projects_list\">\n";58245825if(defined$fetch) {5826if($fetcheq$push) {5827$urls_table.= format_repo_url("URL",$fetch);5828}else{5829$urls_table.= format_repo_url("Fetch URL",$fetch);5830$urls_table.= format_repo_url("Push URL",$push)ifdefined$push;5831}5832}elsif(defined$push) {5833$urls_table.= format_repo_url("Push URL",$push);5834}else{5835$urls_table.= format_repo_url("","No remote URL");5836}58375838$urls_table.="</table>\n";58395840my$dots;5841if(defined$limit&&$limit<@$heads) {5842$dots=$cgi->a({-href => href(action=>"remotes", hash=>$remote)},"...");5843}58445845print$urls_table;5846 git_heads_body($heads,$head,0,$limit,$dots);5847}58485849# Display a list of remote names with the respective fetch and push URLs5850sub git_remotes_list {5851my($remotedata,$limit) =@_;5852print"<table class=\"heads\">\n";5853my$alternate=1;5854my@remotes=sort keys%$remotedata;58555856my$limited=$limit&&$limit<@remotes;58575858$#remotes=$limit-1if$limited;58595860while(my$remote=shift@remotes) {5861my$rdata=$remotedata->{$remote};5862my$fetch=$rdata->{'fetch'};5863my$push=$rdata->{'push'};5864if($alternate) {5865print"<tr class=\"dark\">\n";5866}else{5867print"<tr class=\"light\">\n";5868}5869$alternate^=1;5870print"<td>".5871$cgi->a({-href=> href(action=>'remotes', hash=>$remote),5872-class=>"list name"},esc_html($remote)) .5873"</td>";5874print"<td class=\"link\">".5875(defined$fetch?$cgi->a({-href=>$fetch},"fetch") :"fetch") .5876" | ".5877(defined$push?$cgi->a({-href=>$push},"push") :"push") .5878"</td>";58795880print"</tr>\n";5881}58825883if($limited) {5884print"<tr>\n".5885"<td colspan=\"3\">".5886$cgi->a({-href => href(action=>"remotes")},"...") .5887"</td>\n"."</tr>\n";5888}58895890print"</table>";5891}58925893# Display remote heads grouped by remote, unless there are too many5894# remotes, in which case we only display the remote names5895sub git_remotes_body {5896my($remotedata,$limit,$head) =@_;5897if($limitand$limit<keys%$remotedata) {5898 git_remotes_list($remotedata,$limit);5899}else{5900 fill_remote_heads($remotedata);5901while(my($remote,$rdata) =each%$remotedata) {5902 git_print_section({-class=>"remote", -id=>$remote},5903["remotes",$remote,$remote],sub{5904 git_remote_block($remote,$rdata,$limit,$head);5905});5906}5907}5908}59095910sub git_search_message {5911my%co=@_;59125913my$greptype;5914if($searchtypeeq'commit') {5915$greptype="--grep=";5916}elsif($searchtypeeq'author') {5917$greptype="--author=";5918}elsif($searchtypeeq'committer') {5919$greptype="--committer=";5920}5921$greptype.=$searchtext;5922my@commitlist= parse_commits($hash,101, (100*$page),undef,5923$greptype,'--regexp-ignore-case',5924$search_use_regexp?'--extended-regexp':'--fixed-strings');59255926my$paging_nav='';5927if($page>0) {5928$paging_nav.=5929$cgi->a({-href => href(-replay=>1, page=>undef)},5930"first") .5931" ⋅ ".5932$cgi->a({-href => href(-replay=>1, page=>$page-1),5933-accesskey =>"p", -title =>"Alt-p"},"prev");5934}else{5935$paging_nav.="first ⋅ prev";5936}5937my$next_link='';5938if($#commitlist>=100) {5939$next_link=5940$cgi->a({-href => href(-replay=>1, page=>$page+1),5941-accesskey =>"n", -title =>"Alt-n"},"next");5942$paging_nav.=" ⋅$next_link";5943}else{5944$paging_nav.=" ⋅ next";5945}59465947 git_header_html();59485949 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);5950 git_print_header_div('commit', esc_html($co{'title'}),$hash);5951if($page==0&& !@commitlist) {5952print"<p>No match.</p>\n";5953}else{5954 git_search_grep_body(\@commitlist,0,99,$next_link);5955}59565957 git_footer_html();5958}59595960sub git_search_changes {5961my%co=@_;59625963local$/="\n";5964open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,5965'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",5966($search_use_regexp?'--pickaxe-regex': ())5967or die_error(500,"Open git-log failed");59685969 git_header_html();59705971 git_print_page_nav('','',$hash,$co{'tree'},$hash);5972 git_print_header_div('commit', esc_html($co{'title'}),$hash);59735974print"<table class=\"pickaxe search\">\n";5975my$alternate=1;5976undef%co;5977my@files;5978while(my$line= <$fd>) {5979chomp$line;5980next unless$line;59815982my%set= parse_difftree_raw_line($line);5983if(defined$set{'commit'}) {5984# finish previous commit5985if(%co) {5986print"</td>\n".5987"<td class=\"link\">".5988$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},5989"commit") .5990" | ".5991$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'},5992 hash_base=>$co{'id'})},5993"tree") .5994"</td>\n".5995"</tr>\n";5996}59975998if($alternate) {5999print"<tr class=\"dark\">\n";6000}else{6001print"<tr class=\"light\">\n";6002}6003$alternate^=1;6004%co= parse_commit($set{'commit'});6005my$author= chop_and_escape_str($co{'author_name'},15,5);6006print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6007"<td><i>$author</i></td>\n".6008"<td>".6009$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6010-class=>"list subject"},6011 chop_and_escape_str($co{'title'},50) ."<br/>");6012}elsif(defined$set{'to_id'}) {6013next if($set{'to_id'} =~m/^0{40}$/);60146015print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6016 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6017-class=>"list"},6018"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6019"<br/>\n";6020}6021}6022close$fd;60236024# finish last commit (warning: repetition!)6025if(%co) {6026print"</td>\n".6027"<td class=\"link\">".6028$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},6029"commit") .6030" | ".6031$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'},6032 hash_base=>$co{'id'})},6033"tree") .6034"</td>\n".6035"</tr>\n";6036}60376038print"</table>\n";60396040 git_footer_html();6041}60426043sub git_search_files {6044my%co=@_;60456046local$/="\n";6047open my$fd,"-|", git_cmd(),'grep','-n','-z',6048$search_use_regexp? ('-E','-i') :'-F',6049$searchtext,$co{'tree'}6050or die_error(500,"Open git-grep failed");60516052 git_header_html();60536054 git_print_page_nav('','',$hash,$co{'tree'},$hash);6055 git_print_header_div('commit', esc_html($co{'title'}),$hash);60566057print"<table class=\"grep_search\">\n";6058my$alternate=1;6059my$matches=0;6060my$lastfile='';6061my$file_href;6062while(my$line= <$fd>) {6063chomp$line;6064my($file,$lno,$ltext,$binary);6065last if($matches++>1000);6066if($line=~/^Binary file (.+) matches$/) {6067$file=$1;6068$binary=1;6069}else{6070($file,$lno,$ltext) =split(/\0/,$line,3);6071$file=~s/^$co{'tree'}://;6072}6073if($filene$lastfile) {6074$lastfileand print"</td></tr>\n";6075if($alternate++) {6076print"<tr class=\"dark\">\n";6077}else{6078print"<tr class=\"light\">\n";6079}6080$file_href= href(action=>"blob", hash_base=>$co{'id'},6081 file_name=>$file);6082print"<td class=\"list\">".6083$cgi->a({-href =>$file_href, -class=>"list"}, esc_path($file));6084print"</td><td>\n";6085$lastfile=$file;6086}6087if($binary) {6088print"<div class=\"binary\">Binary file</div>\n";6089}else{6090$ltext= untabify($ltext);6091if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6092$ltext= esc_html($1, -nbsp=>1);6093$ltext.='<span class="match">';6094$ltext.= esc_html($2, -nbsp=>1);6095$ltext.='</span>';6096$ltext.= esc_html($3, -nbsp=>1);6097}else{6098$ltext= esc_html($ltext, -nbsp=>1);6099}6100print"<div class=\"pre\">".6101$cgi->a({-href =>$file_href.'#l'.$lno,6102-class=>"linenr"},sprintf('%4i',$lno)) .6103' '.$ltext."</div>\n";6104}6105}6106if($lastfile) {6107print"</td></tr>\n";6108if($matches>1000) {6109print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6110}6111}else{6112print"<div class=\"diff nodifferences\">No matches found</div>\n";6113}6114close$fd;61156116print"</table>\n";61176118 git_footer_html();6119}61206121sub git_search_grep_body {6122my($commitlist,$from,$to,$extra) =@_;6123$from=0unlessdefined$from;6124$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);61256126print"<table class=\"commit_search\">\n";6127my$alternate=1;6128for(my$i=$from;$i<=$to;$i++) {6129my%co= %{$commitlist->[$i]};6130if(!%co) {6131next;6132}6133my$commit=$co{'id'};6134if($alternate) {6135print"<tr class=\"dark\">\n";6136}else{6137print"<tr class=\"light\">\n";6138}6139$alternate^=1;6140print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6141 format_author_html('td', \%co,15,5) .6142"<td>".6143$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6144-class=>"list subject"},6145 chop_and_escape_str($co{'title'},50) ."<br/>");6146my$comment=$co{'comment'};6147foreachmy$line(@$comment) {6148if($line=~m/^(.*?)($search_regexp)(.*)$/i) {6149my($lead,$match,$trail) = ($1,$2,$3);6150$match= chop_str($match,70,5,'center');6151my$contextlen=int((80-length($match))/2);6152$contextlen=30if($contextlen>30);6153$lead= chop_str($lead,$contextlen,10,'left');6154$trail= chop_str($trail,$contextlen,10,'right');61556156$lead= esc_html($lead);6157$match= esc_html($match);6158$trail= esc_html($trail);61596160print"$lead<span class=\"match\">$match</span>$trail<br />";6161}6162}6163print"</td>\n".6164"<td class=\"link\">".6165$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6166" | ".6167$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .6168" | ".6169$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6170print"</td>\n".6171"</tr>\n";6172}6173if(defined$extra) {6174print"<tr>\n".6175"<td colspan=\"3\">$extra</td>\n".6176"</tr>\n";6177}6178print"</table>\n";6179}61806181## ======================================================================6182## ======================================================================6183## actions61846185sub git_project_list {6186my$order=$input_params{'order'};6187if(defined$order&&$order!~m/none|project|descr|owner|age/) {6188 die_error(400,"Unknown order parameter");6189}61906191my@list= git_get_projects_list($project_filter,$strict_export);6192if(!@list) {6193 die_error(404,"No projects found");6194}61956196 git_header_html();6197if(defined$home_text&& -f $home_text) {6198print"<div class=\"index_include\">\n";6199 insert_file($home_text);6200print"</div>\n";6201}62026203 git_project_search_form($searchtext,$search_use_regexp);6204 git_project_list_body(\@list,$order);6205 git_footer_html();6206}62076208sub git_forks {6209my$order=$input_params{'order'};6210if(defined$order&&$order!~m/none|project|descr|owner|age/) {6211 die_error(400,"Unknown order parameter");6212}62136214my$filter=$project;6215$filter=~s/\.git$//;6216my@list= git_get_projects_list($filter);6217if(!@list) {6218 die_error(404,"No forks found");6219}62206221 git_header_html();6222 git_print_page_nav('','');6223 git_print_header_div('summary',"$projectforks");6224 git_project_list_body(\@list,$order);6225 git_footer_html();6226}62276228sub git_project_index {6229my@projects= git_get_projects_list($project_filter,$strict_export);6230if(!@projects) {6231 die_error(404,"No projects found");6232}62336234print$cgi->header(6235-type =>'text/plain',6236-charset =>'utf-8',6237-content_disposition =>'inline; filename="index.aux"');62386239foreachmy$pr(@projects) {6240if(!exists$pr->{'owner'}) {6241$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");6242}62436244my($path,$owner) = ($pr->{'path'},$pr->{'owner'});6245# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '6246$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;6247$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;6248$path=~s/ /\+/g;6249$owner=~s/ /\+/g;62506251print"$path$owner\n";6252}6253}62546255sub git_summary {6256my$descr= git_get_project_description($project) ||"none";6257my%co= parse_commit("HEAD");6258my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();6259my$head=$co{'id'};6260my$remote_heads= gitweb_check_feature('remote_heads');62616262my$owner= git_get_project_owner($project);62636264my$refs= git_get_references();6265# These get_*_list functions return one more to allow us to see if6266# there are more ...6267my@taglist= git_get_tags_list(16);6268my@headlist= git_get_heads_list(16);6269my%remotedata=$remote_heads? git_get_remotes_list() : ();6270my@forklist;6271my$check_forks= gitweb_check_feature('forks');62726273if($check_forks) {6274# find forks of a project6275my$filter=$project;6276$filter=~s/\.git$//;6277@forklist= git_get_projects_list($filter);6278# filter out forks of forks6279@forklist= filter_forks_from_projects_list(\@forklist)6280if(@forklist);6281}62826283 git_header_html();6284 git_print_page_nav('summary','',$head);62856286print"<div class=\"title\"> </div>\n";6287print"<table class=\"projects_list\">\n".6288"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".6289"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";6290if(defined$cd{'rfc2822'}) {6291print"<tr id=\"metadata_lchange\"><td>last change</td>".6292"<td>".format_timestamp_html(\%cd)."</td></tr>\n";6293}62946295# use per project git URL list in $projectroot/$project/cloneurl6296# or make project git URL from git base URL and project name6297my$url_tag="URL";6298my@url_list= git_get_project_url_list($project);6299@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;6300foreachmy$git_url(@url_list) {6301next unless$git_url;6302print format_repo_url($url_tag,$git_url);6303$url_tag="";6304}63056306# Tag cloud6307my$show_ctags= gitweb_check_feature('ctags');6308if($show_ctags) {6309my$ctags= git_get_project_ctags($project);6310if(%$ctags) {6311# without ability to add tags, don't show if there are none6312my$cloud= git_populate_project_tagcloud($ctags);6313print"<tr id=\"metadata_ctags\">".6314"<td>content tags</td>".6315"<td>".git_show_project_tagcloud($cloud,48)."</td>".6316"</tr>\n";6317}6318}63196320print"</table>\n";63216322# If XSS prevention is on, we don't include README.html.6323# TODO: Allow a readme in some safe format.6324if(!$prevent_xss&& -s "$projectroot/$project/README.html") {6325print"<div class=\"title\">readme</div>\n".6326"<div class=\"readme\">\n";6327 insert_file("$projectroot/$project/README.html");6328print"\n</div>\n";# class="readme"6329}63306331# we need to request one more than 16 (0..15) to check if6332# those 16 are all6333my@commitlist=$head? parse_commits($head,17) : ();6334if(@commitlist) {6335 git_print_header_div('shortlog');6336 git_shortlog_body(\@commitlist,0,15,$refs,6337$#commitlist<=15?undef:6338$cgi->a({-href => href(action=>"shortlog")},"..."));6339}63406341if(@taglist) {6342 git_print_header_div('tags');6343 git_tags_body(\@taglist,0,15,6344$#taglist<=15?undef:6345$cgi->a({-href => href(action=>"tags")},"..."));6346}63476348if(@headlist) {6349 git_print_header_div('heads');6350 git_heads_body(\@headlist,$head,0,15,6351$#headlist<=15?undef:6352$cgi->a({-href => href(action=>"heads")},"..."));6353}63546355if(%remotedata) {6356 git_print_header_div('remotes');6357 git_remotes_body(\%remotedata,15,$head);6358}63596360if(@forklist) {6361 git_print_header_div('forks');6362 git_project_list_body(\@forklist,'age',0,15,6363$#forklist<=15?undef:6364$cgi->a({-href => href(action=>"forks")},"..."),6365'no_header');6366}63676368 git_footer_html();6369}63706371sub git_tag {6372my%tag= parse_tag($hash);63736374if(!%tag) {6375 die_error(404,"Unknown tag object");6376}63776378my$head= git_get_head_hash($project);6379 git_header_html();6380 git_print_page_nav('','',$head,undef,$head);6381 git_print_header_div('commit', esc_html($tag{'name'}),$hash);6382print"<div class=\"title_text\">\n".6383"<table class=\"object_header\">\n".6384"<tr>\n".6385"<td>object</td>\n".6386"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},6387$tag{'object'}) ."</td>\n".6388"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},6389$tag{'type'}) ."</td>\n".6390"</tr>\n";6391if(defined($tag{'author'})) {6392 git_print_authorship_rows(\%tag,'author');6393}6394print"</table>\n\n".6395"</div>\n";6396print"<div class=\"page_body\">";6397my$comment=$tag{'comment'};6398foreachmy$line(@$comment) {6399chomp$line;6400print esc_html($line, -nbsp=>1) ."<br/>\n";6401}6402print"</div>\n";6403 git_footer_html();6404}64056406sub git_blame_common {6407my$format=shift||'porcelain';6408if($formateq'porcelain'&&$input_params{'javascript'}) {6409$format='incremental';6410$action='blame_incremental';# for page title etc6411}64126413# permissions6414 gitweb_check_feature('blame')6415or die_error(403,"Blame view not allowed");64166417# error checking6418 die_error(400,"No file name given")unless$file_name;6419$hash_base||= git_get_head_hash($project);6420 die_error(404,"Couldn't find base commit")unless$hash_base;6421my%co= parse_commit($hash_base)6422or die_error(404,"Commit not found");6423my$ftype="blob";6424if(!defined$hash) {6425$hash= git_get_hash_by_path($hash_base,$file_name,"blob")6426or die_error(404,"Error looking up file");6427}else{6428$ftype= git_get_type($hash);6429if($ftype!~"blob") {6430 die_error(400,"Object is not a blob");6431}6432}64336434my$fd;6435if($formateq'incremental') {6436# get file contents (as base)6437open$fd,"-|", git_cmd(),'cat-file','blob',$hash6438or die_error(500,"Open git-cat-file failed");6439}elsif($formateq'data') {6440# run git-blame --incremental6441open$fd,"-|", git_cmd(),"blame","--incremental",6442$hash_base,"--",$file_name6443or die_error(500,"Open git-blame --incremental failed");6444}else{6445# run git-blame --porcelain6446open$fd,"-|", git_cmd(),"blame",'-p',6447$hash_base,'--',$file_name6448or die_error(500,"Open git-blame --porcelain failed");6449}64506451# incremental blame data returns early6452if($formateq'data') {6453print$cgi->header(6454-type=>"text/plain", -charset =>"utf-8",6455-status=>"200 OK");6456local$| =1;# output autoflush6457while(my$line= <$fd>) {6458print to_utf8($line);6459}6460close$fd6461or print"ERROR$!\n";64626463print'END';6464if(defined$t0&& gitweb_check_feature('timed')) {6465print' '.6466 tv_interval($t0, [ gettimeofday() ]).6467' '.$number_of_git_cmds;6468}6469print"\n";64706471return;6472}64736474# page header6475 git_header_html();6476my$formats_nav=6477$cgi->a({-href => href(action=>"blob", -replay=>1)},6478"blob") .6479" | ";6480if($formateq'incremental') {6481$formats_nav.=6482$cgi->a({-href => href(action=>"blame", javascript=>0, -replay=>1)},6483"blame") ." (non-incremental)";6484}else{6485$formats_nav.=6486$cgi->a({-href => href(action=>"blame_incremental", -replay=>1)},6487"blame") ." (incremental)";6488}6489$formats_nav.=6490" | ".6491$cgi->a({-href => href(action=>"history", -replay=>1)},6492"history") .6493" | ".6494$cgi->a({-href => href(action=>$action, file_name=>$file_name)},6495"HEAD");6496 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);6497 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);6498 git_print_page_path($file_name,$ftype,$hash_base);64996500# page body6501if($formateq'incremental') {6502print"<noscript>\n<div class=\"error\"><center><b>\n".6503"This page requires JavaScript to run.\nUse ".6504$cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},6505'this page').6506" instead.\n".6507"</b></center></div>\n</noscript>\n";65086509print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!;6510}65116512print qq!<div class="page_body">\n!;6513print qq!<div id="progress_info">.../ ...</div>\n!6514if($formateq'incremental');6515print qq!<table id="blame_table"class="blame" width="100%">\n!.6516#qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.6517 qq!<thead>\n!.6518 qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!.6519 qq!</thead>\n!.6520 qq!<tbody>\n!;65216522my@rev_color=qw(light dark);6523my$num_colors=scalar(@rev_color);6524my$current_color=0;65256526if($formateq'incremental') {6527my$color_class=$rev_color[$current_color];65286529#contents of a file6530my$linenr=0;6531 LINE:6532while(my$line= <$fd>) {6533chomp$line;6534$linenr++;65356536print qq!<tr id="l$linenr"class="$color_class">!.6537 qq!<td class="sha1"><a href=""> </a></td>!.6538 qq!<td class="linenr">!.6539 qq!<a class="linenr" href="">$linenr</a></td>!;6540print qq!<td class="pre">! . esc_html($line) ."</td>\n";6541print qq!</tr>\n!;6542}65436544}else{# porcelain, i.e. ordinary blame6545my%metainfo= ();# saves information about commits65466547# blame data6548 LINE:6549while(my$line= <$fd>) {6550chomp$line;6551# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]6552# no <lines in group> for subsequent lines in group of lines6553my($full_rev,$orig_lineno,$lineno,$group_size) =6554($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);6555if(!exists$metainfo{$full_rev}) {6556$metainfo{$full_rev} = {'nprevious'=>0};6557}6558my$meta=$metainfo{$full_rev};6559my$data;6560while($data= <$fd>) {6561chomp$data;6562last if($data=~s/^\t//);# contents of line6563if($data=~/^(\S+)(?: (.*))?$/) {6564$meta->{$1} =$2unlessexists$meta->{$1};6565}6566if($data=~/^previous /) {6567$meta->{'nprevious'}++;6568}6569}6570my$short_rev=substr($full_rev,0,8);6571my$author=$meta->{'author'};6572my%date=6573 parse_date($meta->{'author-time'},$meta->{'author-tz'});6574my$date=$date{'iso-tz'};6575if($group_size) {6576$current_color= ($current_color+1) %$num_colors;6577}6578my$tr_class=$rev_color[$current_color];6579$tr_class.=' boundary'if(exists$meta->{'boundary'});6580$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);6581$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);6582print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";6583if($group_size) {6584print"<td class=\"sha1\"";6585print" title=\"". esc_html($author) .",$date\"";6586print" rowspan=\"$group_size\""if($group_size>1);6587print">";6588print$cgi->a({-href => href(action=>"commit",6589 hash=>$full_rev,6590 file_name=>$file_name)},6591 esc_html($short_rev));6592if($group_size>=2) {6593my@author_initials= ($author=~/\b([[:upper:]])\B/g);6594if(@author_initials) {6595print"<br />".6596 esc_html(join('',@author_initials));6597# or join('.', ...)6598}6599}6600print"</td>\n";6601}6602# 'previous' <sha1 of parent commit> <filename at commit>6603if(exists$meta->{'previous'} &&6604$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {6605$meta->{'parent'} =$1;6606$meta->{'file_parent'} = unquote($2);6607}6608my$linenr_commit=6609exists($meta->{'parent'}) ?6610$meta->{'parent'} :$full_rev;6611my$linenr_filename=6612exists($meta->{'file_parent'}) ?6613$meta->{'file_parent'} : unquote($meta->{'filename'});6614my$blamed= href(action =>'blame',6615 file_name =>$linenr_filename,6616 hash_base =>$linenr_commit);6617print"<td class=\"linenr\">";6618print$cgi->a({ -href =>"$blamed#l$orig_lineno",6619-class=>"linenr"},6620 esc_html($lineno));6621print"</td>";6622print"<td class=\"pre\">". esc_html($data) ."</td>\n";6623print"</tr>\n";6624}# end while66256626}66276628# footer6629print"</tbody>\n".6630"</table>\n";# class="blame"6631print"</div>\n";# class="blame_body"6632close$fd6633or print"Reading blob failed\n";66346635 git_footer_html();6636}66376638sub git_blame {6639 git_blame_common();6640}66416642sub git_blame_incremental {6643 git_blame_common('incremental');6644}66456646sub git_blame_data {6647 git_blame_common('data');6648}66496650sub git_tags {6651my$head= git_get_head_hash($project);6652 git_header_html();6653 git_print_page_nav('','',$head,undef,$head,format_ref_views('tags'));6654 git_print_header_div('summary',$project);66556656my@tagslist= git_get_tags_list();6657if(@tagslist) {6658 git_tags_body(\@tagslist);6659}6660 git_footer_html();6661}66626663sub git_heads {6664my$head= git_get_head_hash($project);6665 git_header_html();6666 git_print_page_nav('','',$head,undef,$head,format_ref_views('heads'));6667 git_print_header_div('summary',$project);66686669my@headslist= git_get_heads_list();6670if(@headslist) {6671 git_heads_body(\@headslist,$head);6672}6673 git_footer_html();6674}66756676# used both for single remote view and for list of all the remotes6677sub git_remotes {6678 gitweb_check_feature('remote_heads')6679or die_error(403,"Remote heads view is disabled");66806681my$head= git_get_head_hash($project);6682my$remote=$input_params{'hash'};66836684my$remotedata= git_get_remotes_list($remote);6685 die_error(500,"Unable to get remote information")unlessdefined$remotedata;66866687unless(%$remotedata) {6688 die_error(404,defined$remote?6689"Remote$remotenot found":6690"No remotes found");6691}66926693 git_header_html(undef,undef, -action_extra =>$remote);6694 git_print_page_nav('','',$head,undef,$head,6695 format_ref_views($remote?'':'remotes'));66966697 fill_remote_heads($remotedata);6698if(defined$remote) {6699 git_print_header_div('remotes',"$remoteremote for$project");6700 git_remote_block($remote,$remotedata->{$remote},undef,$head);6701}else{6702 git_print_header_div('summary',"$projectremotes");6703 git_remotes_body($remotedata,undef,$head);6704}67056706 git_footer_html();6707}67086709sub git_blob_plain {6710my$type=shift;6711my$expires;67126713if(!defined$hash) {6714if(defined$file_name) {6715my$base=$hash_base|| git_get_head_hash($project);6716$hash= git_get_hash_by_path($base,$file_name,"blob")6717or die_error(404,"Cannot find file");6718}else{6719 die_error(400,"No file name defined");6720}6721}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {6722# blobs defined by non-textual hash id's can be cached6723$expires="+1d";6724}67256726open my$fd,"-|", git_cmd(),"cat-file","blob",$hash6727or die_error(500,"Open git-cat-file blob '$hash' failed");67286729# content-type (can include charset)6730$type= blob_contenttype($fd,$file_name,$type);67316732# "save as" filename, even when no $file_name is given6733my$save_as="$hash";6734if(defined$file_name) {6735$save_as=$file_name;6736}elsif($type=~m/^text\//) {6737$save_as.='.txt';6738}67396740# With XSS prevention on, blobs of all types except a few known safe6741# ones are served with "Content-Disposition: attachment" to make sure6742# they don't run in our security domain. For certain image types,6743# blob view writes an <img> tag referring to blob_plain view, and we6744# want to be sure not to break that by serving the image as an6745# attachment (though Firefox 3 doesn't seem to care).6746my$sandbox=$prevent_xss&&6747$type!~m!^(?:text/[a-z]+|image/(?:gif|png|jpeg))(?:[ ;]|$)!;67486749# serve text/* as text/plain6750if($prevent_xss&&6751($type=~m!^text/[a-z]+\b(.*)$!||6752($type=~m!^[a-z]+/[a-z]\+xml\b(.*)$!&& -T $fd))) {6753my$rest=$1;6754$rest=defined$rest?$rest:'';6755$type="text/plain$rest";6756}67576758print$cgi->header(6759-type =>$type,6760-expires =>$expires,6761-content_disposition =>6762($sandbox?'attachment':'inline')6763.'; filename="'.$save_as.'"');6764local$/=undef;6765binmode STDOUT,':raw';6766print<$fd>;6767binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi6768close$fd;6769}67706771sub git_blob {6772my$expires;67736774if(!defined$hash) {6775if(defined$file_name) {6776my$base=$hash_base|| git_get_head_hash($project);6777$hash= git_get_hash_by_path($base,$file_name,"blob")6778or die_error(404,"Cannot find file");6779}else{6780 die_error(400,"No file name defined");6781}6782}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {6783# blobs defined by non-textual hash id's can be cached6784$expires="+1d";6785}67866787my$have_blame= gitweb_check_feature('blame');6788open my$fd,"-|", git_cmd(),"cat-file","blob",$hash6789or die_error(500,"Couldn't cat$file_name,$hash");6790my$mimetype= blob_mimetype($fd,$file_name);6791# use 'blob_plain' (aka 'raw') view for files that cannot be displayed6792if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {6793close$fd;6794return git_blob_plain($mimetype);6795}6796# we can have blame only for text/* mimetype6797$have_blame&&= ($mimetype=~m!^text/!);67986799my$highlight= gitweb_check_feature('highlight');6800my$syntax= guess_file_syntax($highlight,$mimetype,$file_name);6801$fd= run_highlighter($fd,$highlight,$syntax)6802if$syntax;68036804 git_header_html(undef,$expires);6805my$formats_nav='';6806if(defined$hash_base&& (my%co= parse_commit($hash_base))) {6807if(defined$file_name) {6808if($have_blame) {6809$formats_nav.=6810$cgi->a({-href => href(action=>"blame", -replay=>1)},6811"blame") .6812" | ";6813}6814$formats_nav.=6815$cgi->a({-href => href(action=>"history", -replay=>1)},6816"history") .6817" | ".6818$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},6819"raw") .6820" | ".6821$cgi->a({-href => href(action=>"blob",6822 hash_base=>"HEAD", file_name=>$file_name)},6823"HEAD");6824}else{6825$formats_nav.=6826$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},6827"raw");6828}6829 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);6830 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);6831}else{6832print"<div class=\"page_nav\">\n".6833"<br/><br/></div>\n".6834"<div class=\"title\">".esc_html($hash)."</div>\n";6835}6836 git_print_page_path($file_name,"blob",$hash_base);6837print"<div class=\"page_body\">\n";6838if($mimetype=~m!^image/!) {6839print qq!<img type="!.esc_attr($mimetype).qq!"!;6840if($file_name) {6841print qq! alt="!.esc_attr($file_name).qq!" title="!.esc_attr($file_name).qq!"!;6842}6843print qq! src="! .6844 href(action=>"blob_plain", hash=>$hash,6845 hash_base=>$hash_base, file_name=>$file_name) .6846 qq!"/>\n!;6847}else{6848my$nr;6849while(my$line= <$fd>) {6850chomp$line;6851$nr++;6852$line= untabify($line);6853printf qq!<div class="pre"><a id="l%i" href="%s#l%i"class="linenr">%4i</a> %s</div>\n!,6854$nr, esc_attr(href(-replay =>1)),$nr,$nr,6855$syntax? sanitize($line) : esc_html($line, -nbsp=>1);6856}6857}6858close$fd6859or print"Reading blob failed.\n";6860print"</div>";6861 git_footer_html();6862}68636864sub git_tree {6865if(!defined$hash_base) {6866$hash_base="HEAD";6867}6868if(!defined$hash) {6869if(defined$file_name) {6870$hash= git_get_hash_by_path($hash_base,$file_name,"tree");6871}else{6872$hash=$hash_base;6873}6874}6875 die_error(404,"No such tree")unlessdefined($hash);68766877my$show_sizes= gitweb_check_feature('show-sizes');6878my$have_blame= gitweb_check_feature('blame');68796880my@entries= ();6881{6882local$/="\0";6883open my$fd,"-|", git_cmd(),"ls-tree",'-z',6884($show_sizes?'-l': ()),@extra_options,$hash6885or die_error(500,"Open git-ls-tree failed");6886@entries=map{chomp;$_} <$fd>;6887close$fd6888or die_error(404,"Reading tree failed");6889}68906891my$refs= git_get_references();6892my$ref= format_ref_marker($refs,$hash_base);6893 git_header_html();6894my$basedir='';6895if(defined$hash_base&& (my%co= parse_commit($hash_base))) {6896my@views_nav= ();6897if(defined$file_name) {6898push@views_nav,6899$cgi->a({-href => href(action=>"history", -replay=>1)},6900"history"),6901$cgi->a({-href => href(action=>"tree",6902 hash_base=>"HEAD", file_name=>$file_name)},6903"HEAD"),6904}6905my$snapshot_links= format_snapshot_links($hash);6906if(defined$snapshot_links) {6907# FIXME: Should be available when we have no hash base as well.6908push@views_nav,$snapshot_links;6909}6910 git_print_page_nav('tree','',$hash_base,undef,undef,6911join(' | ',@views_nav));6912 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);6913}else{6914undef$hash_base;6915print"<div class=\"page_nav\">\n";6916print"<br/><br/></div>\n";6917print"<div class=\"title\">".esc_html($hash)."</div>\n";6918}6919if(defined$file_name) {6920$basedir=$file_name;6921if($basedirne''&&substr($basedir, -1)ne'/') {6922$basedir.='/';6923}6924 git_print_page_path($file_name,'tree',$hash_base);6925}6926print"<div class=\"page_body\">\n";6927print"<table class=\"tree\">\n";6928my$alternate=1;6929# '..' (top directory) link if possible6930if(defined$hash_base&&6931defined$file_name&&$file_name=~m![^/]+$!) {6932if($alternate) {6933print"<tr class=\"dark\">\n";6934}else{6935print"<tr class=\"light\">\n";6936}6937$alternate^=1;69386939my$up=$file_name;6940$up=~s!/?[^/]+$!!;6941undef$upunless$up;6942# based on git_print_tree_entry6943print'<td class="mode">'. mode_str('040000') ."</td>\n";6944print'<td class="size"> </td>'."\n"if$show_sizes;6945print'<td class="list">';6946print$cgi->a({-href => href(action=>"tree",6947 hash_base=>$hash_base,6948 file_name=>$up)},6949"..");6950print"</td>\n";6951print"<td class=\"link\"></td>\n";69526953print"</tr>\n";6954}6955foreachmy$line(@entries) {6956my%t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);69576958if($alternate) {6959print"<tr class=\"dark\">\n";6960}else{6961print"<tr class=\"light\">\n";6962}6963$alternate^=1;69646965 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);69666967print"</tr>\n";6968}6969print"</table>\n".6970"</div>";6971 git_footer_html();6972}69736974sub snapshot_name {6975my($project,$hash) =@_;69766977# path/to/project.git -> project6978# path/to/project/.git -> project6979my$name= to_utf8($project);6980$name=~ s,([^/])/*\.git$,$1,;6981$name= basename($name);6982# sanitize name6983$name=~s/[[:cntrl:]]/?/g;69846985my$ver=$hash;6986if($hash=~/^[0-9a-fA-F]+$/) {6987# shorten SHA-1 hash6988my$full_hash= git_get_full_hash($project,$hash);6989if($full_hash=~/^$hash/&&length($hash) >7) {6990$ver= git_get_short_hash($project,$hash);6991}6992}elsif($hash=~m!^refs/tags/(.*)$!) {6993# tags don't need shortened SHA-1 hash6994$ver=$1;6995}else{6996# branches and other need shortened SHA-1 hash6997if($hash=~m!^refs/(?:heads|remotes)/(.*)$!) {6998$ver=$1;6999}7000$ver.='-'. git_get_short_hash($project,$hash);7001}7002# in case of hierarchical branch names7003$ver=~s!/!.!g;70047005# name = project-version_string7006$name="$name-$ver";70077008returnwantarray? ($name,$name) :$name;7009}70107011sub git_snapshot {7012my$format=$input_params{'snapshot_format'};7013if(!@snapshot_fmts) {7014 die_error(403,"Snapshots not allowed");7015}7016# default to first supported snapshot format7017$format||=$snapshot_fmts[0];7018if($format!~m/^[a-z0-9]+$/) {7019 die_error(400,"Invalid snapshot format parameter");7020}elsif(!exists($known_snapshot_formats{$format})) {7021 die_error(400,"Unknown snapshot format");7022}elsif($known_snapshot_formats{$format}{'disabled'}) {7023 die_error(403,"Snapshot format not allowed");7024}elsif(!grep($_eq$format,@snapshot_fmts)) {7025 die_error(403,"Unsupported snapshot format");7026}70277028my$type= git_get_type("$hash^{}");7029if(!$type) {7030 die_error(404,'Object does not exist');7031}elsif($typeeq'blob') {7032 die_error(400,'Object is not a tree-ish');7033}70347035my($name,$prefix) = snapshot_name($project,$hash);7036my$filename="$name$known_snapshot_formats{$format}{'suffix'}";7037my$cmd= quote_command(7038 git_cmd(),'archive',7039"--format=$known_snapshot_formats{$format}{'format'}",7040"--prefix=$prefix/",$hash);7041if(exists$known_snapshot_formats{$format}{'compressor'}) {7042$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});7043}70447045$filename=~s/(["\\])/\\$1/g;7046print$cgi->header(7047-type =>$known_snapshot_formats{$format}{'type'},7048-content_disposition =>'inline; filename="'.$filename.'"',7049-status =>'200 OK');70507051open my$fd,"-|",$cmd7052or die_error(500,"Execute git-archive failed");7053binmode STDOUT,':raw';7054print<$fd>;7055binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi7056close$fd;7057}70587059sub git_log_generic {7060my($fmt_name,$body_subr,$base,$parent,$file_name,$file_hash) =@_;70617062my$head= git_get_head_hash($project);7063if(!defined$base) {7064$base=$head;7065}7066if(!defined$page) {7067$page=0;7068}7069my$refs= git_get_references();70707071my$commit_hash=$base;7072if(defined$parent) {7073$commit_hash="$parent..$base";7074}7075my@commitlist=7076 parse_commits($commit_hash,101, (100*$page),7077defined$file_name? ($file_name,"--full-history") : ());70787079my$ftype;7080if(!defined$file_hash&&defined$file_name) {7081# some commits could have deleted file in question,7082# and not have it in tree, but one of them has to have it7083for(my$i=0;$i<@commitlist;$i++) {7084$file_hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);7085last ifdefined$file_hash;7086}7087}7088if(defined$file_hash) {7089$ftype= git_get_type($file_hash);7090}7091if(defined$file_name&& !defined$ftype) {7092 die_error(500,"Unknown type of object");7093}7094my%co;7095if(defined$file_name) {7096%co= parse_commit($base)7097or die_error(404,"Unknown commit object");7098}709971007101my$paging_nav= format_paging_nav($fmt_name,$page,$#commitlist>=100);7102my$next_link='';7103if($#commitlist>=100) {7104$next_link=7105$cgi->a({-href => href(-replay=>1, page=>$page+1),7106-accesskey =>"n", -title =>"Alt-n"},"next");7107}7108my$patch_max= gitweb_get_feature('patches');7109if($patch_max&& !defined$file_name) {7110if($patch_max<0||@commitlist<=$patch_max) {7111$paging_nav.=" ⋅ ".7112$cgi->a({-href => href(action=>"patches", -replay=>1)},7113"patches");7114}7115}71167117 git_header_html();7118 git_print_page_nav($fmt_name,'',$hash,$hash,$hash,$paging_nav);7119if(defined$file_name) {7120 git_print_header_div('commit', esc_html($co{'title'}),$base);7121}else{7122 git_print_header_div('summary',$project)7123}7124 git_print_page_path($file_name,$ftype,$hash_base)7125if(defined$file_name);71267127$body_subr->(\@commitlist,0,99,$refs,$next_link,7128$file_name,$file_hash,$ftype);71297130 git_footer_html();7131}71327133sub git_log {7134 git_log_generic('log', \&git_log_body,7135$hash,$hash_parent);7136}71377138sub git_commit {7139$hash||=$hash_base||"HEAD";7140my%co= parse_commit($hash)7141or die_error(404,"Unknown commit object");71427143my$parent=$co{'parent'};7144my$parents=$co{'parents'};# listref71457146# we need to prepare $formats_nav before any parameter munging7147my$formats_nav;7148if(!defined$parent) {7149# --root commitdiff7150$formats_nav.='(initial)';7151}elsif(@$parents==1) {7152# single parent commit7153$formats_nav.=7154'(parent: '.7155$cgi->a({-href => href(action=>"commit",7156 hash=>$parent)},7157 esc_html(substr($parent,0,7))) .7158')';7159}else{7160# merge commit7161$formats_nav.=7162'(merge: '.7163join(' ',map{7164$cgi->a({-href => href(action=>"commit",7165 hash=>$_)},7166 esc_html(substr($_,0,7)));7167}@$parents) .7168')';7169}7170if(gitweb_check_feature('patches') &&@$parents<=1) {7171$formats_nav.=" | ".7172$cgi->a({-href => href(action=>"patch", -replay=>1)},7173"patch");7174}71757176if(!defined$parent) {7177$parent="--root";7178}7179my@difftree;7180open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",7181@diff_opts,7182(@$parents<=1?$parent:'-c'),7183$hash,"--"7184or die_error(500,"Open git-diff-tree failed");7185@difftree=map{chomp;$_} <$fd>;7186close$fdor die_error(404,"Reading git-diff-tree failed");71877188# non-textual hash id's can be cached7189my$expires;7190if($hash=~m/^[0-9a-fA-F]{40}$/) {7191$expires="+1d";7192}7193my$refs= git_get_references();7194my$ref= format_ref_marker($refs,$co{'id'});71957196 git_header_html(undef,$expires);7197 git_print_page_nav('commit','',7198$hash,$co{'tree'},$hash,7199$formats_nav);72007201if(defined$co{'parent'}) {7202 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);7203}else{7204 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);7205}7206print"<div class=\"title_text\">\n".7207"<table class=\"object_header\">\n";7208 git_print_authorship_rows(\%co);7209print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";7210print"<tr>".7211"<td>tree</td>".7212"<td class=\"sha1\">".7213$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),7214class=>"list"},$co{'tree'}) .7215"</td>".7216"<td class=\"link\">".7217$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},7218"tree");7219my$snapshot_links= format_snapshot_links($hash);7220if(defined$snapshot_links) {7221print" | ".$snapshot_links;7222}7223print"</td>".7224"</tr>\n";72257226foreachmy$par(@$parents) {7227print"<tr>".7228"<td>parent</td>".7229"<td class=\"sha1\">".7230$cgi->a({-href => href(action=>"commit", hash=>$par),7231class=>"list"},$par) .7232"</td>".7233"<td class=\"link\">".7234$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .7235" | ".7236$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .7237"</td>".7238"</tr>\n";7239}7240print"</table>".7241"</div>\n";72427243print"<div class=\"page_body\">\n";7244 git_print_log($co{'comment'});7245print"</div>\n";72467247 git_difftree_body(\@difftree,$hash,@$parents);72487249 git_footer_html();7250}72517252sub git_object {7253# object is defined by:7254# - hash or hash_base alone7255# - hash_base and file_name7256my$type;72577258# - hash or hash_base alone7259if($hash|| ($hash_base&& !defined$file_name)) {7260my$object_id=$hash||$hash_base;72617262open my$fd,"-|", quote_command(7263 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'7264or die_error(404,"Object does not exist");7265$type= <$fd>;7266chomp$type;7267close$fd7268or die_error(404,"Object does not exist");72697270# - hash_base and file_name7271}elsif($hash_base&&defined$file_name) {7272$file_name=~ s,/+$,,;72737274system(git_cmd(),"cat-file",'-e',$hash_base) ==07275or die_error(404,"Base object does not exist");72767277# here errors should not hapen7278open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name7279or die_error(500,"Open git-ls-tree failed");7280my$line= <$fd>;7281close$fd;72827283#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'7284unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {7285 die_error(404,"File or directory for given base does not exist");7286}7287$type=$2;7288$hash=$3;7289}else{7290 die_error(400,"Not enough information to find object");7291}72927293print$cgi->redirect(-uri => href(action=>$type, -full=>1,7294 hash=>$hash, hash_base=>$hash_base,7295 file_name=>$file_name),7296-status =>'302 Found');7297}72987299sub git_blobdiff {7300my$format=shift||'html';7301my$diff_style=$input_params{'diff_style'} ||'inline';73027303my$fd;7304my@difftree;7305my%diffinfo;7306my$expires;73077308# preparing $fd and %diffinfo for git_patchset_body7309# new style URI7310if(defined$hash_base&&defined$hash_parent_base) {7311if(defined$file_name) {7312# read raw output7313open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7314$hash_parent_base,$hash_base,7315"--", (defined$file_parent?$file_parent: ()),$file_name7316or die_error(500,"Open git-diff-tree failed");7317@difftree=map{chomp;$_} <$fd>;7318close$fd7319or die_error(404,"Reading git-diff-tree failed");7320@difftree7321or die_error(404,"Blob diff not found");73227323}elsif(defined$hash&&7324$hash=~/[0-9a-fA-F]{40}/) {7325# try to find filename from $hash73267327# read filtered raw output7328open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7329$hash_parent_base,$hash_base,"--"7330or die_error(500,"Open git-diff-tree failed");7331@difftree=7332# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'7333# $hash == to_id7334grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}7335map{chomp;$_} <$fd>;7336close$fd7337or die_error(404,"Reading git-diff-tree failed");7338@difftree7339or die_error(404,"Blob diff not found");73407341}else{7342 die_error(400,"Missing one of the blob diff parameters");7343}73447345if(@difftree>1) {7346 die_error(400,"Ambiguous blob diff specification");7347}73487349%diffinfo= parse_difftree_raw_line($difftree[0]);7350$file_parent||=$diffinfo{'from_file'} ||$file_name;7351$file_name||=$diffinfo{'to_file'};73527353$hash_parent||=$diffinfo{'from_id'};7354$hash||=$diffinfo{'to_id'};73557356# non-textual hash id's can be cached7357if($hash_base=~m/^[0-9a-fA-F]{40}$/&&7358$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {7359$expires='+1d';7360}73617362# open patch output7363open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7364'-p', ($formateq'html'?"--full-index": ()),7365$hash_parent_base,$hash_base,7366"--", (defined$file_parent?$file_parent: ()),$file_name7367or die_error(500,"Open git-diff-tree failed");7368}73697370# old/legacy style URI -- not generated anymore since 1.4.3.7371if(!%diffinfo) {7372 die_error('404 Not Found',"Missing one of the blob diff parameters")7373}73747375# header7376if($formateq'html') {7377my$formats_nav=7378$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},7379"raw");7380$formats_nav.= diff_style_nav($diff_style);7381 git_header_html(undef,$expires);7382if(defined$hash_base&& (my%co= parse_commit($hash_base))) {7383 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);7384 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);7385}else{7386print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";7387print"<div class=\"title\">".esc_html("$hashvs$hash_parent")."</div>\n";7388}7389if(defined$file_name) {7390 git_print_page_path($file_name,"blob",$hash_base);7391}else{7392print"<div class=\"page_path\"></div>\n";7393}73947395}elsif($formateq'plain') {7396print$cgi->header(7397-type =>'text/plain',7398-charset =>'utf-8',7399-expires =>$expires,7400-content_disposition =>'inline; filename="'."$file_name".'.patch"');74017402print"X-Git-Url: ".$cgi->self_url() ."\n\n";74037404}else{7405 die_error(400,"Unknown blobdiff format");7406}74077408# patch7409if($formateq'html') {7410print"<div class=\"page_body\">\n";74117412 git_patchset_body($fd,$diff_style,7413[ \%diffinfo],$hash_base,$hash_parent_base);7414close$fd;74157416print"</div>\n";# class="page_body"7417 git_footer_html();74187419}else{7420while(my$line= <$fd>) {7421$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;7422$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;74237424print$line;74257426last if$line=~m!^\+\+\+!;7427}7428local$/=undef;7429print<$fd>;7430close$fd;7431}7432}74337434sub git_blobdiff_plain {7435 git_blobdiff('plain');7436}74377438# assumes that it is added as later part of already existing navigation,7439# so it returns "| foo | bar" rather than just "foo | bar"7440sub diff_style_nav {7441my($diff_style,$is_combined) =@_;7442$diff_style||='inline';74437444return""if($is_combined);74457446my@styles= (inline =>'inline','sidebyside'=>'side by side');7447my%styles=@styles;7448@styles=7449@styles[map{$_*2}0..$#styles/2];74507451returnjoin'',7452map{" | ".$_}7453map{7454$_eq$diff_style?$styles{$_} :7455$cgi->a({-href => href(-replay=>1, diff_style =>$_)},$styles{$_})7456}@styles;7457}74587459sub git_commitdiff {7460my%params=@_;7461my$format=$params{-format} ||'html';7462my$diff_style=$input_params{'diff_style'} ||'inline';74637464my($patch_max) = gitweb_get_feature('patches');7465if($formateq'patch') {7466 die_error(403,"Patch view not allowed")unless$patch_max;7467}74687469$hash||=$hash_base||"HEAD";7470my%co= parse_commit($hash)7471or die_error(404,"Unknown commit object");74727473# choose format for commitdiff for merge7474if(!defined$hash_parent&& @{$co{'parents'}} >1) {7475$hash_parent='--cc';7476}7477# we need to prepare $formats_nav before almost any parameter munging7478my$formats_nav;7479if($formateq'html') {7480$formats_nav=7481$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},7482"raw");7483if($patch_max&& @{$co{'parents'}} <=1) {7484$formats_nav.=" | ".7485$cgi->a({-href => href(action=>"patch", -replay=>1)},7486"patch");7487}7488$formats_nav.= diff_style_nav($diff_style, @{$co{'parents'}} >1);74897490if(defined$hash_parent&&7491$hash_parentne'-c'&&$hash_parentne'--cc') {7492# commitdiff with two commits given7493my$hash_parent_short=$hash_parent;7494if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {7495$hash_parent_short=substr($hash_parent,0,7);7496}7497$formats_nav.=7498' (from';7499for(my$i=0;$i< @{$co{'parents'}};$i++) {7500if($co{'parents'}[$i]eq$hash_parent) {7501$formats_nav.=' parent '. ($i+1);7502last;7503}7504}7505$formats_nav.=': '.7506$cgi->a({-href => href(-replay=>1,7507 hash=>$hash_parent, hash_base=>undef)},7508 esc_html($hash_parent_short)) .7509')';7510}elsif(!$co{'parent'}) {7511# --root commitdiff7512$formats_nav.=' (initial)';7513}elsif(scalar@{$co{'parents'}} ==1) {7514# single parent commit7515$formats_nav.=7516' (parent: '.7517$cgi->a({-href => href(-replay=>1,7518 hash=>$co{'parent'}, hash_base=>undef)},7519 esc_html(substr($co{'parent'},0,7))) .7520')';7521}else{7522# merge commit7523if($hash_parenteq'--cc') {7524$formats_nav.=' | '.7525$cgi->a({-href => href(-replay=>1,7526 hash=>$hash, hash_parent=>'-c')},7527'combined');7528}else{# $hash_parent eq '-c'7529$formats_nav.=' | '.7530$cgi->a({-href => href(-replay=>1,7531 hash=>$hash, hash_parent=>'--cc')},7532'compact');7533}7534$formats_nav.=7535' (merge: '.7536join(' ',map{7537$cgi->a({-href => href(-replay=>1,7538 hash=>$_, hash_base=>undef)},7539 esc_html(substr($_,0,7)));7540} @{$co{'parents'}} ) .7541')';7542}7543}75447545my$hash_parent_param=$hash_parent;7546if(!defined$hash_parent_param) {7547# --cc for multiple parents, --root for parentless7548$hash_parent_param=7549@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';7550}75517552# read commitdiff7553my$fd;7554my@difftree;7555if($formateq'html') {7556open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7557"--no-commit-id","--patch-with-raw","--full-index",7558$hash_parent_param,$hash,"--"7559or die_error(500,"Open git-diff-tree failed");75607561while(my$line= <$fd>) {7562chomp$line;7563# empty line ends raw part of diff-tree output7564last unless$line;7565push@difftree,scalar parse_difftree_raw_line($line);7566}75677568}elsif($formateq'plain') {7569open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7570'-p',$hash_parent_param,$hash,"--"7571or die_error(500,"Open git-diff-tree failed");7572}elsif($formateq'patch') {7573# For commit ranges, we limit the output to the number of7574# patches specified in the 'patches' feature.7575# For single commits, we limit the output to a single patch,7576# diverging from the git-format-patch default.7577my@commit_spec= ();7578if($hash_parent) {7579if($patch_max>0) {7580push@commit_spec,"-$patch_max";7581}7582push@commit_spec,'-n',"$hash_parent..$hash";7583}else{7584if($params{-single}) {7585push@commit_spec,'-1';7586}else{7587if($patch_max>0) {7588push@commit_spec,"-$patch_max";7589}7590push@commit_spec,"-n";7591}7592push@commit_spec,'--root',$hash;7593}7594open$fd,"-|", git_cmd(),"format-patch",@diff_opts,7595'--encoding=utf8','--stdout',@commit_spec7596or die_error(500,"Open git-format-patch failed");7597}else{7598 die_error(400,"Unknown commitdiff format");7599}76007601# non-textual hash id's can be cached7602my$expires;7603if($hash=~m/^[0-9a-fA-F]{40}$/) {7604$expires="+1d";7605}76067607# write commit message7608if($formateq'html') {7609my$refs= git_get_references();7610my$ref= format_ref_marker($refs,$co{'id'});76117612 git_header_html(undef,$expires);7613 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);7614 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);7615print"<div class=\"title_text\">\n".7616"<table class=\"object_header\">\n";7617 git_print_authorship_rows(\%co);7618print"</table>".7619"</div>\n";7620print"<div class=\"page_body\">\n";7621if(@{$co{'comment'}} >1) {7622print"<div class=\"log\">\n";7623 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);7624print"</div>\n";# class="log"7625}76267627}elsif($formateq'plain') {7628my$refs= git_get_references("tags");7629my$tagname= git_get_rev_name_tags($hash);7630my$filename= basename($project) ."-$hash.patch";76317632print$cgi->header(7633-type =>'text/plain',7634-charset =>'utf-8',7635-expires =>$expires,7636-content_disposition =>'inline; filename="'."$filename".'"');7637my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});7638print"From: ". to_utf8($co{'author'}) ."\n";7639print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";7640print"Subject: ". to_utf8($co{'title'}) ."\n";76417642print"X-Git-Tag:$tagname\n"if$tagname;7643print"X-Git-Url: ".$cgi->self_url() ."\n\n";76447645foreachmy$line(@{$co{'comment'}}) {7646print to_utf8($line) ."\n";7647}7648print"---\n\n";7649}elsif($formateq'patch') {7650my$filename= basename($project) ."-$hash.patch";76517652print$cgi->header(7653-type =>'text/plain',7654-charset =>'utf-8',7655-expires =>$expires,7656-content_disposition =>'inline; filename="'."$filename".'"');7657}76587659# write patch7660if($formateq'html') {7661my$use_parents= !defined$hash_parent||7662$hash_parenteq'-c'||$hash_parenteq'--cc';7663 git_difftree_body(\@difftree,$hash,7664$use_parents? @{$co{'parents'}} :$hash_parent);7665print"<br/>\n";76667667 git_patchset_body($fd,$diff_style,7668 \@difftree,$hash,7669$use_parents? @{$co{'parents'}} :$hash_parent);7670close$fd;7671print"</div>\n";# class="page_body"7672 git_footer_html();76737674}elsif($formateq'plain') {7675local$/=undef;7676print<$fd>;7677close$fd7678or print"Reading git-diff-tree failed\n";7679}elsif($formateq'patch') {7680local$/=undef;7681print<$fd>;7682close$fd7683or print"Reading git-format-patch failed\n";7684}7685}76867687sub git_commitdiff_plain {7688 git_commitdiff(-format =>'plain');7689}76907691# format-patch-style patches7692sub git_patch {7693 git_commitdiff(-format =>'patch', -single =>1);7694}76957696sub git_patches {7697 git_commitdiff(-format =>'patch');7698}76997700sub git_history {7701 git_log_generic('history', \&git_history_body,7702$hash_base,$hash_parent_base,7703$file_name,$hash);7704}77057706sub git_search {7707$searchtype||='commit';77087709# check if appropriate features are enabled7710 gitweb_check_feature('search')7711or die_error(403,"Search is disabled");7712if($searchtypeeq'pickaxe') {7713# pickaxe may take all resources of your box and run for several minutes7714# with every query - so decide by yourself how public you make this feature7715 gitweb_check_feature('pickaxe')7716or die_error(403,"Pickaxe search is disabled");7717}7718if($searchtypeeq'grep') {7719# grep search might be potentially CPU-intensive, too7720 gitweb_check_feature('grep')7721or die_error(403,"Grep search is disabled");7722}77237724if(!defined$searchtext) {7725 die_error(400,"Text field is empty");7726}7727if(!defined$hash) {7728$hash= git_get_head_hash($project);7729}7730my%co= parse_commit($hash);7731if(!%co) {7732 die_error(404,"Unknown commit object");7733}7734if(!defined$page) {7735$page=0;7736}77377738if($searchtypeeq'commit'||7739$searchtypeeq'author'||7740$searchtypeeq'committer') {7741 git_search_message(%co);7742}elsif($searchtypeeq'pickaxe') {7743 git_search_changes(%co);7744}elsif($searchtypeeq'grep') {7745 git_search_files(%co);7746}else{7747 die_error(400,"Unknown search type");7748}7749}77507751sub git_search_help {7752 git_header_html();7753 git_print_page_nav('','',$hash,$hash,$hash);7754print<<EOT;7755<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without7756regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,7757the pattern entered is recognized as the POSIX extended7758<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case7759insensitive).</p>7760<dl>7761<dt><b>commit</b></dt>7762<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>7763EOT7764my$have_grep= gitweb_check_feature('grep');7765if($have_grep) {7766print<<EOT;7767<dt><b>grep</b></dt>7768<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing7769 a different one) are searched for the given pattern. On large trees, this search can take7770a while and put some strain on the server, so please use it with some consideration. Note that7771due to git-grep peculiarity, currently if regexp mode is turned off, the matches are7772case-sensitive.</dd>7773EOT7774}7775print<<EOT;7776<dt><b>author</b></dt>7777<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>7778<dt><b>committer</b></dt>7779<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>7780EOT7781my$have_pickaxe= gitweb_check_feature('pickaxe');7782if($have_pickaxe) {7783print<<EOT;7784<dt><b>pickaxe</b></dt>7785<dd>All commits that caused the string to appear or disappear from any file (changes that7786added, removed or "modified" the string) will be listed. This search can take a while and7787takes a lot of strain on the server, so please use it wisely. Note that since you may be7788interested even in changes just changing the case as well, this search is case sensitive.</dd>7789EOT7790}7791print"</dl>\n";7792 git_footer_html();7793}77947795sub git_shortlog {7796 git_log_generic('shortlog', \&git_shortlog_body,7797$hash,$hash_parent);7798}77997800## ......................................................................7801## feeds (RSS, Atom; OPML)78027803sub git_feed {7804my$format=shift||'atom';7805my$have_blame= gitweb_check_feature('blame');78067807# Atom: http://www.atomenabled.org/developers/syndication/7808# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ7809if($formatne'rss'&&$formatne'atom') {7810 die_error(400,"Unknown web feed format");7811}78127813# log/feed of current (HEAD) branch, log of given branch, history of file/directory7814my$head=$hash||'HEAD';7815my@commitlist= parse_commits($head,150,0,$file_name);78167817my%latest_commit;7818my%latest_date;7819my$content_type="application/$format+xml";7820if(defined$cgi->http('HTTP_ACCEPT') &&7821$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {7822# browser (feed reader) prefers text/xml7823$content_type='text/xml';7824}7825if(defined($commitlist[0])) {7826%latest_commit= %{$commitlist[0]};7827my$latest_epoch=$latest_commit{'committer_epoch'};7828%latest_date= parse_date($latest_epoch,$latest_commit{'comitter_tz'});7829my$if_modified=$cgi->http('IF_MODIFIED_SINCE');7830if(defined$if_modified) {7831my$since;7832if(eval{require HTTP::Date;1; }) {7833$since= HTTP::Date::str2time($if_modified);7834}elsif(eval{require Time::ParseDate;1; }) {7835$since= Time::ParseDate::parsedate($if_modified, GMT =>1);7836}7837if(defined$since&&$latest_epoch<=$since) {7838print$cgi->header(7839-type =>$content_type,7840-charset =>'utf-8',7841-last_modified =>$latest_date{'rfc2822'},7842-status =>'304 Not Modified');7843return;7844}7845}7846print$cgi->header(7847-type =>$content_type,7848-charset =>'utf-8',7849-last_modified =>$latest_date{'rfc2822'});7850}else{7851print$cgi->header(7852-type =>$content_type,7853-charset =>'utf-8');7854}78557856# Optimization: skip generating the body if client asks only7857# for Last-Modified date.7858return if($cgi->request_method()eq'HEAD');78597860# header variables7861my$title="$site_name-$project/$action";7862my$feed_type='log';7863if(defined$hash) {7864$title.=" - '$hash'";7865$feed_type='branch log';7866if(defined$file_name) {7867$title.=" ::$file_name";7868$feed_type='history';7869}7870}elsif(defined$file_name) {7871$title.=" -$file_name";7872$feed_type='history';7873}7874$title.="$feed_type";7875my$descr= git_get_project_description($project);7876if(defined$descr) {7877$descr= esc_html($descr);7878}else{7879$descr="$project".7880($formateq'rss'?'RSS':'Atom') .7881" feed";7882}7883my$owner= git_get_project_owner($project);7884$owner= esc_html($owner);78857886#header7887my$alt_url;7888if(defined$file_name) {7889$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);7890}elsif(defined$hash) {7891$alt_url= href(-full=>1, action=>"log", hash=>$hash);7892}else{7893$alt_url= href(-full=>1, action=>"summary");7894}7895print qq!<?xml version="1.0" encoding="utf-8"?>\n!;7896if($formateq'rss') {7897print<<XML;7898<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">7899<channel>7900XML7901print"<title>$title</title>\n".7902"<link>$alt_url</link>\n".7903"<description>$descr</description>\n".7904"<language>en</language>\n".7905# project owner is responsible for 'editorial' content7906"<managingEditor>$owner</managingEditor>\n";7907if(defined$logo||defined$favicon) {7908# prefer the logo to the favicon, since RSS7909# doesn't allow both7910my$img= esc_url($logo||$favicon);7911print"<image>\n".7912"<url>$img</url>\n".7913"<title>$title</title>\n".7914"<link>$alt_url</link>\n".7915"</image>\n";7916}7917if(%latest_date) {7918print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";7919print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";7920}7921print"<generator>gitweb v.$version/$git_version</generator>\n";7922}elsif($formateq'atom') {7923print<<XML;7924<feed xmlns="http://www.w3.org/2005/Atom">7925XML7926print"<title>$title</title>\n".7927"<subtitle>$descr</subtitle>\n".7928'<link rel="alternate" type="text/html" href="'.7929$alt_url.'" />'."\n".7930'<link rel="self" type="'.$content_type.'" href="'.7931$cgi->self_url() .'" />'."\n".7932"<id>". href(-full=>1) ."</id>\n".7933# use project owner for feed author7934"<author><name>$owner</name></author>\n";7935if(defined$favicon) {7936print"<icon>". esc_url($favicon) ."</icon>\n";7937}7938if(defined$logo) {7939# not twice as wide as tall: 72 x 27 pixels7940print"<logo>". esc_url($logo) ."</logo>\n";7941}7942if(!%latest_date) {7943# dummy date to keep the feed valid until commits trickle in:7944print"<updated>1970-01-01T00:00:00Z</updated>\n";7945}else{7946print"<updated>$latest_date{'iso-8601'}</updated>\n";7947}7948print"<generator version='$version/$git_version'>gitweb</generator>\n";7949}79507951# contents7952for(my$i=0;$i<=$#commitlist;$i++) {7953my%co= %{$commitlist[$i]};7954my$commit=$co{'id'};7955# we read 150, we always show 30 and the ones more recent than 48 hours7956if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {7957last;7958}7959my%cd= parse_date($co{'author_epoch'},$co{'author_tz'});79607961# get list of changed files7962open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7963$co{'parent'} ||"--root",7964$co{'id'},"--", (defined$file_name?$file_name: ())7965ornext;7966my@difftree=map{chomp;$_} <$fd>;7967close$fd7968ornext;79697970# print element (entry, item)7971my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);7972if($formateq'rss') {7973print"<item>\n".7974"<title>". esc_html($co{'title'}) ."</title>\n".7975"<author>". esc_html($co{'author'}) ."</author>\n".7976"<pubDate>$cd{'rfc2822'}</pubDate>\n".7977"<guid isPermaLink=\"true\">$co_url</guid>\n".7978"<link>$co_url</link>\n".7979"<description>". esc_html($co{'title'}) ."</description>\n".7980"<content:encoded>".7981"<![CDATA[\n";7982}elsif($formateq'atom') {7983print"<entry>\n".7984"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".7985"<updated>$cd{'iso-8601'}</updated>\n".7986"<author>\n".7987" <name>". esc_html($co{'author_name'}) ."</name>\n";7988if($co{'author_email'}) {7989print" <email>". esc_html($co{'author_email'}) ."</email>\n";7990}7991print"</author>\n".7992# use committer for contributor7993"<contributor>\n".7994" <name>". esc_html($co{'committer_name'}) ."</name>\n";7995if($co{'committer_email'}) {7996print" <email>". esc_html($co{'committer_email'}) ."</email>\n";7997}7998print"</contributor>\n".7999"<published>$cd{'iso-8601'}</published>\n".8000"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".8001"<id>$co_url</id>\n".8002"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".8003"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";8004}8005my$comment=$co{'comment'};8006print"<pre>\n";8007foreachmy$line(@$comment) {8008$line= esc_html($line);8009print"$line\n";8010}8011print"</pre><ul>\n";8012foreachmy$difftree_line(@difftree) {8013my%difftree= parse_difftree_raw_line($difftree_line);8014next if!$difftree{'from_id'};80158016my$file=$difftree{'file'} ||$difftree{'to_file'};80178018print"<li>".8019"[".8020$cgi->a({-href => href(-full=>1, action=>"blobdiff",8021 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},8022 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},8023 file_name=>$file, file_parent=>$difftree{'from_file'}),8024-title =>"diff"},'D');8025if($have_blame) {8026print$cgi->a({-href => href(-full=>1, action=>"blame",8027 file_name=>$file, hash_base=>$commit),8028-title =>"blame"},'B');8029}8030# if this is not a feed of a file history8031if(!defined$file_name||$file_namene$file) {8032print$cgi->a({-href => href(-full=>1, action=>"history",8033 file_name=>$file, hash=>$commit),8034-title =>"history"},'H');8035}8036$file= esc_path($file);8037print"] ".8038"$file</li>\n";8039}8040if($formateq'rss') {8041print"</ul>]]>\n".8042"</content:encoded>\n".8043"</item>\n";8044}elsif($formateq'atom') {8045print"</ul>\n</div>\n".8046"</content>\n".8047"</entry>\n";8048}8049}80508051# end of feed8052if($formateq'rss') {8053print"</channel>\n</rss>\n";8054}elsif($formateq'atom') {8055print"</feed>\n";8056}8057}80588059sub git_rss {8060 git_feed('rss');8061}80628063sub git_atom {8064 git_feed('atom');8065}80668067sub git_opml {8068my@list= git_get_projects_list($project_filter,$strict_export);8069if(!@list) {8070 die_error(404,"No projects found");8071}80728073print$cgi->header(8074-type =>'text/xml',8075-charset =>'utf-8',8076-content_disposition =>'inline; filename="opml.xml"');80778078my$title= esc_html($site_name);8079my$filter=" within subdirectory ";8080if(defined$project_filter) {8081$filter.= esc_html($project_filter);8082}else{8083$filter="";8084}8085print<<XML;8086<?xml version="1.0" encoding="utf-8"?>8087<opml version="1.0">8088<head>8089 <title>$titleOPML Export$filter</title>8090</head>8091<body>8092<outline text="git RSS feeds">8093XML80948095foreachmy$pr(@list) {8096my%proj=%$pr;8097my$head= git_get_head_hash($proj{'path'});8098if(!defined$head) {8099next;8100}8101$git_dir="$projectroot/$proj{'path'}";8102my%co= parse_commit($head);8103if(!%co) {8104next;8105}81068107my$path= esc_html(chop_str($proj{'path'},25,5));8108my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);8109my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);8110print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";8111}8112print<<XML;8113</outline>8114</body>8115</opml>8116XML8117}