1#!/usr/bin/perl 2 3# gitweb - simple web interface to track changes in git repositories 4# 5# (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org> 6# (C) 2005, Christian Gierke 7# 8# This program is licensed under the GPLv2 9 10use5.008; 11use strict; 12use warnings; 13use CGI qw(:standard :escapeHTML -nosticky); 14use CGI::Util qw(unescape); 15use CGI::Carp qw(fatalsToBrowser set_message); 16use Encode; 17use Fcntl ':mode'; 18use File::Find qw(); 19use File::Basename qw(basename); 20use Time::HiRes qw(gettimeofday tv_interval); 21binmode STDOUT,':utf8'; 22 23our$t0= [ gettimeofday() ]; 24our$number_of_git_cmds=0; 25 26BEGIN{ 27 CGI->compile()if$ENV{'MOD_PERL'}; 28} 29 30our$version="++GIT_VERSION++"; 31 32our($my_url,$my_uri,$base_url,$path_info,$home_link); 33sub evaluate_uri { 34our$cgi; 35 36our$my_url=$cgi->url(); 37our$my_uri=$cgi->url(-absolute =>1); 38 39# Base URL for relative URLs in gitweb ($logo, $favicon, ...), 40# needed and used only for URLs with nonempty PATH_INFO 41our$base_url=$my_url; 42 43# When the script is used as DirectoryIndex, the URL does not contain the name 44# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we 45# have to do it ourselves. We make $path_info global because it's also used 46# later on. 47# 48# Another issue with the script being the DirectoryIndex is that the resulting 49# $my_url data is not the full script URL: this is good, because we want 50# generated links to keep implying the script name if it wasn't explicitly 51# indicated in the URL we're handling, but it means that $my_url cannot be used 52# as base URL. 53# Therefore, if we needed to strip PATH_INFO, then we know that we have 54# to build the base URL ourselves: 55our$path_info= decode_utf8($ENV{"PATH_INFO"}); 56if($path_info) { 57if($my_url=~ s,\Q$path_info\E$,, && 58$my_uri=~ s,\Q$path_info\E$,, && 59defined$ENV{'SCRIPT_NAME'}) { 60$base_url=$cgi->url(-base =>1) .$ENV{'SCRIPT_NAME'}; 61} 62} 63 64# target of the home link on top of all pages 65our$home_link=$my_uri||"/"; 66} 67 68# core git executable to use 69# this can just be "git" if your webserver has a sensible PATH 70our$GIT="++GIT_BINDIR++/git"; 71 72# absolute fs-path which will be prepended to the project path 73#our $projectroot = "/pub/scm"; 74our$projectroot="++GITWEB_PROJECTROOT++"; 75 76# fs traversing limit for getting project list 77# the number is relative to the projectroot 78our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 79 80# string of the home link on top of all pages 81our$home_link_str="++GITWEB_HOME_LINK_STR++"; 82 83# name of your site or organization to appear in page titles 84# replace this with something more descriptive for clearer bookmarks 85our$site_name="++GITWEB_SITENAME++" 86|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 87 88# html snippet to include in the <head> section of each page 89our$site_html_head_string="++GITWEB_SITE_HTML_HEAD_STRING++"; 90# filename of html text to include at top of each page 91our$site_header="++GITWEB_SITE_HEADER++"; 92# html text to include at home page 93our$home_text="++GITWEB_HOMETEXT++"; 94# filename of html text to include at bottom of each page 95our$site_footer="++GITWEB_SITE_FOOTER++"; 96 97# URI of stylesheets 98our@stylesheets= ("++GITWEB_CSS++"); 99# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 100our$stylesheet=undef; 101# URI of GIT logo (72x27 size) 102our$logo="++GITWEB_LOGO++"; 103# URI of GIT favicon, assumed to be image/png type 104our$favicon="++GITWEB_FAVICON++"; 105# URI of gitweb.js (JavaScript code for gitweb) 106our$javascript="++GITWEB_JS++"; 107 108# URI and label (title) of GIT logo link 109#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 110#our $logo_label = "git documentation"; 111our$logo_url="http://git-scm.com/"; 112our$logo_label="git homepage"; 113 114# source of projects list 115our$projects_list="++GITWEB_LIST++"; 116 117# the width (in characters) of the projects list "Description" column 118our$projects_list_description_width=25; 119 120# group projects by category on the projects list 121# (enabled if this variable evaluates to true) 122our$projects_list_group_categories=0; 123 124# default category if none specified 125# (leave the empty string for no category) 126our$project_list_default_category=""; 127 128# default order of projects list 129# valid values are none, project, descr, owner, and age 130our$default_projects_order="project"; 131 132# show repository only if this file exists 133# (only effective if this variable evaluates to true) 134our$export_ok="++GITWEB_EXPORT_OK++"; 135 136# don't generate age column on the projects list page 137our$omit_age_column=0; 138 139# show repository only if this subroutine returns true 140# when given the path to the project, for example: 141# sub { return -e "$_[0]/git-daemon-export-ok"; } 142our$export_auth_hook=undef; 143 144# only allow viewing of repositories also shown on the overview page 145our$strict_export="++GITWEB_STRICT_EXPORT++"; 146 147# list of git base URLs used for URL to where fetch project from, 148# i.e. full URL is "$git_base_url/$project" 149our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 150 151# default blob_plain mimetype and default charset for text/plain blob 152our$default_blob_plain_mimetype='text/plain'; 153our$default_text_plain_charset=undef; 154 155# file to use for guessing MIME types before trying /etc/mime.types 156# (relative to the current git repository) 157our$mimetypes_file=undef; 158 159# assume this charset if line contains non-UTF-8 characters; 160# it should be valid encoding (see Encoding::Supported(3pm) for list), 161# for which encoding all byte sequences are valid, for example 162# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 163# could be even 'utf-8' for the old behavior) 164our$fallback_encoding='latin1'; 165 166# rename detection options for git-diff and git-diff-tree 167# - default is '-M', with the cost proportional to 168# (number of removed files) * (number of new files). 169# - more costly is '-C' (which implies '-M'), with the cost proportional to 170# (number of changed files + number of removed files) * (number of new files) 171# - even more costly is '-C', '--find-copies-harder' with cost 172# (number of files in the original tree) * (number of new files) 173# - one might want to include '-B' option, e.g. '-B', '-M' 174our@diff_opts= ('-M');# taken from git_commit 175 176# Disables features that would allow repository owners to inject script into 177# the gitweb domain. 178our$prevent_xss=0; 179 180# Path to the highlight executable to use (must be the one from 181# http://www.andre-simon.de due to assumptions about parameters and output). 182# Useful if highlight is not installed on your webserver's PATH. 183# [Default: highlight] 184our$highlight_bin="++HIGHLIGHT_BIN++"; 185 186# information about snapshot formats that gitweb is capable of serving 187our%known_snapshot_formats= ( 188# name => { 189# 'display' => display name, 190# 'type' => mime type, 191# 'suffix' => filename suffix, 192# 'format' => --format for git-archive, 193# 'compressor' => [compressor command and arguments] 194# (array reference, optional) 195# 'disabled' => boolean (optional)} 196# 197'tgz'=> { 198'display'=>'tar.gz', 199'type'=>'application/x-gzip', 200'suffix'=>'.tar.gz', 201'format'=>'tar', 202'compressor'=> ['gzip','-n']}, 203 204'tbz2'=> { 205'display'=>'tar.bz2', 206'type'=>'application/x-bzip2', 207'suffix'=>'.tar.bz2', 208'format'=>'tar', 209'compressor'=> ['bzip2']}, 210 211'txz'=> { 212'display'=>'tar.xz', 213'type'=>'application/x-xz', 214'suffix'=>'.tar.xz', 215'format'=>'tar', 216'compressor'=> ['xz'], 217'disabled'=>1}, 218 219'zip'=> { 220'display'=>'zip', 221'type'=>'application/x-zip', 222'suffix'=>'.zip', 223'format'=>'zip'}, 224); 225 226# Aliases so we understand old gitweb.snapshot values in repository 227# configuration. 228our%known_snapshot_format_aliases= ( 229'gzip'=>'tgz', 230'bzip2'=>'tbz2', 231'xz'=>'txz', 232 233# backward compatibility: legacy gitweb config support 234'x-gzip'=>undef,'gz'=>undef, 235'x-bzip2'=>undef,'bz2'=>undef, 236'x-zip'=>undef,''=>undef, 237); 238 239# Pixel sizes for icons and avatars. If the default font sizes or lineheights 240# are changed, it may be appropriate to change these values too via 241# $GITWEB_CONFIG. 242our%avatar_size= ( 243'default'=>16, 244'double'=>32 245); 246 247# Used to set the maximum load that we will still respond to gitweb queries. 248# If server load exceed this value then return "503 server busy" error. 249# If gitweb cannot determined server load, it is taken to be 0. 250# Leave it undefined (or set to 'undef') to turn off load checking. 251our$maxload=300; 252 253# configuration for 'highlight' (http://www.andre-simon.de/) 254# match by basename 255our%highlight_basename= ( 256#'Program' => 'py', 257#'Library' => 'py', 258'SConstruct'=>'py',# SCons equivalent of Makefile 259'Makefile'=>'make', 260); 261# match by extension 262our%highlight_ext= ( 263# main extensions, defining name of syntax; 264# see files in /usr/share/highlight/langDefs/ directory 265map{$_=>$_} 266qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl sql make), 267# alternate extensions, see /etc/highlight/filetypes.conf 268'h'=>'c', 269map{$_=>'sh'}qw(bash zsh ksh), 270map{$_=>'cpp'}qw(cxx c++ cc), 271map{$_=>'php'}qw(php3 php4 php5 phps), 272map{$_=>'pl'}qw(perl pm),# perhaps also 'cgi' 273map{$_=>'make'}qw(mak mk), 274map{$_=>'xml'}qw(xhtml html htm), 275); 276 277# You define site-wide feature defaults here; override them with 278# $GITWEB_CONFIG as necessary. 279our%feature= ( 280# feature => { 281# 'sub' => feature-sub (subroutine), 282# 'override' => allow-override (boolean), 283# 'default' => [ default options...] (array reference)} 284# 285# if feature is overridable (it means that allow-override has true value), 286# then feature-sub will be called with default options as parameters; 287# return value of feature-sub indicates if to enable specified feature 288# 289# if there is no 'sub' key (no feature-sub), then feature cannot be 290# overridden 291# 292# use gitweb_get_feature(<feature>) to retrieve the <feature> value 293# (an array) or gitweb_check_feature(<feature>) to check if <feature> 294# is enabled 295 296# Enable the 'blame' blob view, showing the last commit that modified 297# each line in the file. This can be very CPU-intensive. 298 299# To enable system wide have in $GITWEB_CONFIG 300# $feature{'blame'}{'default'} = [1]; 301# To have project specific config enable override in $GITWEB_CONFIG 302# $feature{'blame'}{'override'} = 1; 303# and in project config gitweb.blame = 0|1; 304'blame'=> { 305'sub'=>sub{ feature_bool('blame',@_) }, 306'override'=>0, 307'default'=> [0]}, 308 309# Enable the 'snapshot' link, providing a compressed archive of any 310# tree. This can potentially generate high traffic if you have large 311# project. 312 313# Value is a list of formats defined in %known_snapshot_formats that 314# you wish to offer. 315# To disable system wide have in $GITWEB_CONFIG 316# $feature{'snapshot'}{'default'} = []; 317# To have project specific config enable override in $GITWEB_CONFIG 318# $feature{'snapshot'}{'override'} = 1; 319# and in project config, a comma-separated list of formats or "none" 320# to disable. Example: gitweb.snapshot = tbz2,zip; 321'snapshot'=> { 322'sub'=> \&feature_snapshot, 323'override'=>0, 324'default'=> ['tgz']}, 325 326# Enable text search, which will list the commits which match author, 327# committer or commit text to a given string. Enabled by default. 328# Project specific override is not supported. 329# 330# Note that this controls all search features, which means that if 331# it is disabled, then 'grep' and 'pickaxe' search would also be 332# disabled. 333'search'=> { 334'override'=>0, 335'default'=> [1]}, 336 337# Enable grep search, which will list the files in currently selected 338# tree containing the given string. Enabled by default. This can be 339# potentially CPU-intensive, of course. 340# Note that you need to have 'search' feature enabled too. 341 342# To enable system wide have in $GITWEB_CONFIG 343# $feature{'grep'}{'default'} = [1]; 344# To have project specific config enable override in $GITWEB_CONFIG 345# $feature{'grep'}{'override'} = 1; 346# and in project config gitweb.grep = 0|1; 347'grep'=> { 348'sub'=>sub{ feature_bool('grep',@_) }, 349'override'=>0, 350'default'=> [1]}, 351 352# Enable the pickaxe search, which will list the commits that modified 353# a given string in a file. This can be practical and quite faster 354# alternative to 'blame', but still potentially CPU-intensive. 355# Note that you need to have 'search' feature enabled too. 356 357# To enable system wide have in $GITWEB_CONFIG 358# $feature{'pickaxe'}{'default'} = [1]; 359# To have project specific config enable override in $GITWEB_CONFIG 360# $feature{'pickaxe'}{'override'} = 1; 361# and in project config gitweb.pickaxe = 0|1; 362'pickaxe'=> { 363'sub'=>sub{ feature_bool('pickaxe',@_) }, 364'override'=>0, 365'default'=> [1]}, 366 367# Enable showing size of blobs in a 'tree' view, in a separate 368# column, similar to what 'ls -l' does. This cost a bit of IO. 369 370# To disable system wide have in $GITWEB_CONFIG 371# $feature{'show-sizes'}{'default'} = [0]; 372# To have project specific config enable override in $GITWEB_CONFIG 373# $feature{'show-sizes'}{'override'} = 1; 374# and in project config gitweb.showsizes = 0|1; 375'show-sizes'=> { 376'sub'=>sub{ feature_bool('showsizes',@_) }, 377'override'=>0, 378'default'=> [1]}, 379 380# Make gitweb use an alternative format of the URLs which can be 381# more readable and natural-looking: project name is embedded 382# directly in the path and the query string contains other 383# auxiliary information. All gitweb installations recognize 384# URL in either format; this configures in which formats gitweb 385# generates links. 386 387# To enable system wide have in $GITWEB_CONFIG 388# $feature{'pathinfo'}{'default'} = [1]; 389# Project specific override is not supported. 390 391# Note that you will need to change the default location of CSS, 392# favicon, logo and possibly other files to an absolute URL. Also, 393# if gitweb.cgi serves as your indexfile, you will need to force 394# $my_uri to contain the script name in your $GITWEB_CONFIG. 395'pathinfo'=> { 396'override'=>0, 397'default'=> [0]}, 398 399# Make gitweb consider projects in project root subdirectories 400# to be forks of existing projects. Given project $projname.git, 401# projects matching $projname/*.git will not be shown in the main 402# projects list, instead a '+' mark will be added to $projname 403# there and a 'forks' view will be enabled for the project, listing 404# all the forks. If project list is taken from a file, forks have 405# to be listed after the main project. 406 407# To enable system wide have in $GITWEB_CONFIG 408# $feature{'forks'}{'default'} = [1]; 409# Project specific override is not supported. 410'forks'=> { 411'override'=>0, 412'default'=> [0]}, 413 414# Insert custom links to the action bar of all project pages. 415# This enables you mainly to link to third-party scripts integrating 416# into gitweb; e.g. git-browser for graphical history representation 417# or custom web-based repository administration interface. 418 419# The 'default' value consists of a list of triplets in the form 420# (label, link, position) where position is the label after which 421# to insert the link and link is a format string where %n expands 422# to the project name, %f to the project path within the filesystem, 423# %h to the current hash (h gitweb parameter) and %b to the current 424# hash base (hb gitweb parameter); %% expands to %. 425 426# To enable system wide have in $GITWEB_CONFIG e.g. 427# $feature{'actions'}{'default'} = [('graphiclog', 428# '/git-browser/by-commit.html?r=%n', 'summary')]; 429# Project specific override is not supported. 430'actions'=> { 431'override'=>0, 432'default'=> []}, 433 434# Allow gitweb scan project content tags of project repository, 435# and display the popular Web 2.0-ish "tag cloud" near the projects 436# list. Note that this is something COMPLETELY different from the 437# normal Git tags. 438 439# gitweb by itself can show existing tags, but it does not handle 440# tagging itself; you need to do it externally, outside gitweb. 441# The format is described in git_get_project_ctags() subroutine. 442# You may want to install the HTML::TagCloud Perl module to get 443# a pretty tag cloud instead of just a list of tags. 444 445# To enable system wide have in $GITWEB_CONFIG 446# $feature{'ctags'}{'default'} = [1]; 447# Project specific override is not supported. 448 449# In the future whether ctags editing is enabled might depend 450# on the value, but using 1 should always mean no editing of ctags. 451'ctags'=> { 452'override'=>0, 453'default'=> [0]}, 454 455# The maximum number of patches in a patchset generated in patch 456# view. Set this to 0 or undef to disable patch view, or to a 457# negative number to remove any limit. 458 459# To disable system wide have in $GITWEB_CONFIG 460# $feature{'patches'}{'default'} = [0]; 461# To have project specific config enable override in $GITWEB_CONFIG 462# $feature{'patches'}{'override'} = 1; 463# and in project config gitweb.patches = 0|n; 464# where n is the maximum number of patches allowed in a patchset. 465'patches'=> { 466'sub'=> \&feature_patches, 467'override'=>0, 468'default'=> [16]}, 469 470# Avatar support. When this feature is enabled, views such as 471# shortlog or commit will display an avatar associated with 472# the email of the committer(s) and/or author(s). 473 474# Currently available providers are gravatar and picon. 475# If an unknown provider is specified, the feature is disabled. 476 477# Gravatar depends on Digest::MD5. 478# Picon currently relies on the indiana.edu database. 479 480# To enable system wide have in $GITWEB_CONFIG 481# $feature{'avatar'}{'default'} = ['<provider>']; 482# where <provider> is either gravatar or picon. 483# To have project specific config enable override in $GITWEB_CONFIG 484# $feature{'avatar'}{'override'} = 1; 485# and in project config gitweb.avatar = <provider>; 486'avatar'=> { 487'sub'=> \&feature_avatar, 488'override'=>0, 489'default'=> ['']}, 490 491# Enable displaying how much time and how many git commands 492# it took to generate and display page. Disabled by default. 493# Project specific override is not supported. 494'timed'=> { 495'override'=>0, 496'default'=> [0]}, 497 498# Enable turning some links into links to actions which require 499# JavaScript to run (like 'blame_incremental'). Not enabled by 500# default. Project specific override is currently not supported. 501'javascript-actions'=> { 502'override'=>0, 503'default'=> [0]}, 504 505# Enable and configure ability to change common timezone for dates 506# in gitweb output via JavaScript. Enabled by default. 507# Project specific override is not supported. 508'javascript-timezone'=> { 509'override'=>0, 510'default'=> [ 511'local',# default timezone: 'utc', 'local', or '(-|+)HHMM' format, 512# or undef to turn off this feature 513'gitweb_tz',# name of cookie where to store selected timezone 514'datetime',# CSS class used to mark up dates for manipulation 515]}, 516 517# Syntax highlighting support. This is based on Daniel Svensson's 518# and Sham Chukoury's work in gitweb-xmms2.git. 519# It requires the 'highlight' program present in $PATH, 520# and therefore is disabled by default. 521 522# To enable system wide have in $GITWEB_CONFIG 523# $feature{'highlight'}{'default'} = [1]; 524 525'highlight'=> { 526'sub'=>sub{ feature_bool('highlight',@_) }, 527'override'=>0, 528'default'=> [0]}, 529 530# Enable displaying of remote heads in the heads list 531 532# To enable system wide have in $GITWEB_CONFIG 533# $feature{'remote_heads'}{'default'} = [1]; 534# To have project specific config enable override in $GITWEB_CONFIG 535# $feature{'remote_heads'}{'override'} = 1; 536# and in project config gitweb.remote_heads = 0|1; 537'remote_heads'=> { 538'sub'=>sub{ feature_bool('remote_heads',@_) }, 539'override'=>0, 540'default'=> [0]}, 541); 542 543sub gitweb_get_feature { 544my($name) =@_; 545return unlessexists$feature{$name}; 546my($sub,$override,@defaults) = ( 547$feature{$name}{'sub'}, 548$feature{$name}{'override'}, 549@{$feature{$name}{'default'}}); 550# project specific override is possible only if we have project 551our$git_dir;# global variable, declared later 552if(!$override|| !defined$git_dir) { 553return@defaults; 554} 555if(!defined$sub) { 556warn"feature$nameis not overridable"; 557return@defaults; 558} 559return$sub->(@defaults); 560} 561 562# A wrapper to check if a given feature is enabled. 563# With this, you can say 564# 565# my $bool_feat = gitweb_check_feature('bool_feat'); 566# gitweb_check_feature('bool_feat') or somecode; 567# 568# instead of 569# 570# my ($bool_feat) = gitweb_get_feature('bool_feat'); 571# (gitweb_get_feature('bool_feat'))[0] or somecode; 572# 573sub gitweb_check_feature { 574return(gitweb_get_feature(@_))[0]; 575} 576 577 578sub feature_bool { 579my$key=shift; 580my($val) = git_get_project_config($key,'--bool'); 581 582if(!defined$val) { 583return($_[0]); 584}elsif($valeq'true') { 585return(1); 586}elsif($valeq'false') { 587return(0); 588} 589} 590 591sub feature_snapshot { 592my(@fmts) =@_; 593 594my($val) = git_get_project_config('snapshot'); 595 596if($val) { 597@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 598} 599 600return@fmts; 601} 602 603sub feature_patches { 604my@val= (git_get_project_config('patches','--int')); 605 606if(@val) { 607return@val; 608} 609 610return($_[0]); 611} 612 613sub feature_avatar { 614my@val= (git_get_project_config('avatar')); 615 616return@val?@val:@_; 617} 618 619# checking HEAD file with -e is fragile if the repository was 620# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 621# and then pruned. 622sub check_head_link { 623my($dir) =@_; 624my$headfile="$dir/HEAD"; 625return((-e $headfile) || 626(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 627} 628 629sub check_export_ok { 630my($dir) =@_; 631return(check_head_link($dir) && 632(!$export_ok|| -e "$dir/$export_ok") && 633(!$export_auth_hook||$export_auth_hook->($dir))); 634} 635 636# process alternate names for backward compatibility 637# filter out unsupported (unknown) snapshot formats 638sub filter_snapshot_fmts { 639my@fmts=@_; 640 641@fmts=map{ 642exists$known_snapshot_format_aliases{$_} ? 643$known_snapshot_format_aliases{$_} :$_}@fmts; 644@fmts=grep{ 645exists$known_snapshot_formats{$_} && 646!$known_snapshot_formats{$_}{'disabled'}}@fmts; 647} 648 649# If it is set to code reference, it is code that it is to be run once per 650# request, allowing updating configurations that change with each request, 651# while running other code in config file only once. 652# 653# Otherwise, if it is false then gitweb would process config file only once; 654# if it is true then gitweb config would be run for each request. 655our$per_request_config=1; 656 657# read and parse gitweb config file given by its parameter. 658# returns true on success, false on recoverable error, allowing 659# to chain this subroutine, using first file that exists. 660# dies on errors during parsing config file, as it is unrecoverable. 661sub read_config_file { 662my$filename=shift; 663return unlessdefined$filename; 664# die if there are errors parsing config file 665if(-e $filename) { 666do$filename; 667die$@if$@; 668return1; 669} 670return; 671} 672 673our($GITWEB_CONFIG,$GITWEB_CONFIG_SYSTEM,$GITWEB_CONFIG_COMMON); 674sub evaluate_gitweb_config { 675our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 676our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 677our$GITWEB_CONFIG_COMMON=$ENV{'GITWEB_CONFIG_COMMON'} ||"++GITWEB_CONFIG_COMMON++"; 678 679# Protect agains duplications of file names, to not read config twice. 680# Only one of $GITWEB_CONFIG and $GITWEB_CONFIG_SYSTEM is used, so 681# there possibility of duplication of filename there doesn't matter. 682$GITWEB_CONFIG=""if($GITWEB_CONFIGeq$GITWEB_CONFIG_COMMON); 683$GITWEB_CONFIG_SYSTEM=""if($GITWEB_CONFIG_SYSTEMeq$GITWEB_CONFIG_COMMON); 684 685# Common system-wide settings for convenience. 686# Those settings can be ovverriden by GITWEB_CONFIG or GITWEB_CONFIG_SYSTEM. 687 read_config_file($GITWEB_CONFIG_COMMON); 688 689# Use first config file that exists. This means use the per-instance 690# GITWEB_CONFIG if exists, otherwise use GITWEB_SYSTEM_CONFIG. 691 read_config_file($GITWEB_CONFIG)andreturn; 692 read_config_file($GITWEB_CONFIG_SYSTEM); 693} 694 695# Get loadavg of system, to compare against $maxload. 696# Currently it requires '/proc/loadavg' present to get loadavg; 697# if it is not present it returns 0, which means no load checking. 698sub get_loadavg { 699if( -e '/proc/loadavg'){ 700open my$fd,'<','/proc/loadavg' 701orreturn0; 702my@load=split(/\s+/,scalar<$fd>); 703close$fd; 704 705# The first three columns measure CPU and IO utilization of the last one, 706# five, and 10 minute periods. The fourth column shows the number of 707# currently running processes and the total number of processes in the m/n 708# format. The last column displays the last process ID used. 709return$load[0] ||0; 710} 711# additional checks for load average should go here for things that don't export 712# /proc/loadavg 713 714return0; 715} 716 717# version of the core git binary 718our$git_version; 719sub evaluate_git_version { 720our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 721$number_of_git_cmds++; 722} 723 724sub check_loadavg { 725if(defined$maxload&& get_loadavg() >$maxload) { 726 die_error(503,"The load average on the server is too high"); 727} 728} 729 730# ====================================================================== 731# input validation and dispatch 732 733# input parameters can be collected from a variety of sources (presently, CGI 734# and PATH_INFO), so we define an %input_params hash that collects them all 735# together during validation: this allows subsequent uses (e.g. href()) to be 736# agnostic of the parameter origin 737 738our%input_params= (); 739 740# input parameters are stored with the long parameter name as key. This will 741# also be used in the href subroutine to convert parameters to their CGI 742# equivalent, and since the href() usage is the most frequent one, we store 743# the name -> CGI key mapping here, instead of the reverse. 744# 745# XXX: Warning: If you touch this, check the search form for updating, 746# too. 747 748our@cgi_param_mapping= ( 749 project =>"p", 750 action =>"a", 751 file_name =>"f", 752 file_parent =>"fp", 753 hash =>"h", 754 hash_parent =>"hp", 755 hash_base =>"hb", 756 hash_parent_base =>"hpb", 757 page =>"pg", 758 order =>"o", 759 searchtext =>"s", 760 searchtype =>"st", 761 snapshot_format =>"sf", 762 extra_options =>"opt", 763 search_use_regexp =>"sr", 764 ctag =>"by_tag", 765 diff_style =>"ds", 766 project_filter =>"pf", 767# this must be last entry (for manipulation from JavaScript) 768 javascript =>"js" 769); 770our%cgi_param_mapping=@cgi_param_mapping; 771 772# we will also need to know the possible actions, for validation 773our%actions= ( 774"blame"=> \&git_blame, 775"blame_incremental"=> \&git_blame_incremental, 776"blame_data"=> \&git_blame_data, 777"blobdiff"=> \&git_blobdiff, 778"blobdiff_plain"=> \&git_blobdiff_plain, 779"blob"=> \&git_blob, 780"blob_plain"=> \&git_blob_plain, 781"commitdiff"=> \&git_commitdiff, 782"commitdiff_plain"=> \&git_commitdiff_plain, 783"commit"=> \&git_commit, 784"forks"=> \&git_forks, 785"heads"=> \&git_heads, 786"history"=> \&git_history, 787"log"=> \&git_log, 788"patch"=> \&git_patch, 789"patches"=> \&git_patches, 790"remotes"=> \&git_remotes, 791"rss"=> \&git_rss, 792"atom"=> \&git_atom, 793"search"=> \&git_search, 794"search_help"=> \&git_search_help, 795"shortlog"=> \&git_shortlog, 796"summary"=> \&git_summary, 797"tag"=> \&git_tag, 798"tags"=> \&git_tags, 799"tree"=> \&git_tree, 800"snapshot"=> \&git_snapshot, 801"object"=> \&git_object, 802# those below don't need $project 803"opml"=> \&git_opml, 804"project_list"=> \&git_project_list, 805"project_index"=> \&git_project_index, 806); 807 808# finally, we have the hash of allowed extra_options for the commands that 809# allow them 810our%allowed_options= ( 811"--no-merges"=> [qw(rss atom log shortlog history)], 812); 813 814# fill %input_params with the CGI parameters. All values except for 'opt' 815# should be single values, but opt can be an array. We should probably 816# build an array of parameters that can be multi-valued, but since for the time 817# being it's only this one, we just single it out 818sub evaluate_query_params { 819our$cgi; 820 821while(my($name,$symbol) =each%cgi_param_mapping) { 822if($symboleq'opt') { 823$input_params{$name} = [map{ decode_utf8($_) }$cgi->param($symbol) ]; 824}else{ 825$input_params{$name} = decode_utf8($cgi->param($symbol)); 826} 827} 828} 829 830# now read PATH_INFO and update the parameter list for missing parameters 831sub evaluate_path_info { 832return ifdefined$input_params{'project'}; 833return if!$path_info; 834$path_info=~ s,^/+,,; 835return if!$path_info; 836 837# find which part of PATH_INFO is project 838my$project=$path_info; 839$project=~ s,/+$,,; 840while($project&& !check_head_link("$projectroot/$project")) { 841$project=~ s,/*[^/]*$,,; 842} 843return unless$project; 844$input_params{'project'} =$project; 845 846# do not change any parameters if an action is given using the query string 847return if$input_params{'action'}; 848$path_info=~ s,^\Q$project\E/*,,; 849 850# next, check if we have an action 851my$action=$path_info; 852$action=~ s,/.*$,,; 853if(exists$actions{$action}) { 854$path_info=~ s,^$action/*,,; 855$input_params{'action'} =$action; 856} 857 858# list of actions that want hash_base instead of hash, but can have no 859# pathname (f) parameter 860my@wants_base= ( 861'tree', 862'history', 863); 864 865# we want to catch, among others 866# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 867my($parentrefname,$parentpathname,$refname,$pathname) = 868($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?([^:]+?)?(?::(.+))?$/); 869 870# first, analyze the 'current' part 871if(defined$pathname) { 872# we got "branch:filename" or "branch:dir/" 873# we could use git_get_type(branch:pathname), but: 874# - it needs $git_dir 875# - it does a git() call 876# - the convention of terminating directories with a slash 877# makes it superfluous 878# - embedding the action in the PATH_INFO would make it even 879# more superfluous 880$pathname=~ s,^/+,,; 881if(!$pathname||substr($pathname, -1)eq"/") { 882$input_params{'action'} ||="tree"; 883$pathname=~ s,/$,,; 884}else{ 885# the default action depends on whether we had parent info 886# or not 887if($parentrefname) { 888$input_params{'action'} ||="blobdiff_plain"; 889}else{ 890$input_params{'action'} ||="blob_plain"; 891} 892} 893$input_params{'hash_base'} ||=$refname; 894$input_params{'file_name'} ||=$pathname; 895}elsif(defined$refname) { 896# we got "branch". In this case we have to choose if we have to 897# set hash or hash_base. 898# 899# Most of the actions without a pathname only want hash to be 900# set, except for the ones specified in @wants_base that want 901# hash_base instead. It should also be noted that hand-crafted 902# links having 'history' as an action and no pathname or hash 903# set will fail, but that happens regardless of PATH_INFO. 904if(defined$parentrefname) { 905# if there is parent let the default be 'shortlog' action 906# (for http://git.example.com/repo.git/A..B links); if there 907# is no parent, dispatch will detect type of object and set 908# action appropriately if required (if action is not set) 909$input_params{'action'} ||="shortlog"; 910} 911if($input_params{'action'} && 912grep{$_eq$input_params{'action'} }@wants_base) { 913$input_params{'hash_base'} ||=$refname; 914}else{ 915$input_params{'hash'} ||=$refname; 916} 917} 918 919# next, handle the 'parent' part, if present 920if(defined$parentrefname) { 921# a missing pathspec defaults to the 'current' filename, allowing e.g. 922# someproject/blobdiff/oldrev..newrev:/filename 923if($parentpathname) { 924$parentpathname=~ s,^/+,,; 925$parentpathname=~ s,/$,,; 926$input_params{'file_parent'} ||=$parentpathname; 927}else{ 928$input_params{'file_parent'} ||=$input_params{'file_name'}; 929} 930# we assume that hash_parent_base is wanted if a path was specified, 931# or if the action wants hash_base instead of hash 932if(defined$input_params{'file_parent'} || 933grep{$_eq$input_params{'action'} }@wants_base) { 934$input_params{'hash_parent_base'} ||=$parentrefname; 935}else{ 936$input_params{'hash_parent'} ||=$parentrefname; 937} 938} 939 940# for the snapshot action, we allow URLs in the form 941# $project/snapshot/$hash.ext 942# where .ext determines the snapshot and gets removed from the 943# passed $refname to provide the $hash. 944# 945# To be able to tell that $refname includes the format extension, we 946# require the following two conditions to be satisfied: 947# - the hash input parameter MUST have been set from the $refname part 948# of the URL (i.e. they must be equal) 949# - the snapshot format MUST NOT have been defined already (e.g. from 950# CGI parameter sf) 951# It's also useless to try any matching unless $refname has a dot, 952# so we check for that too 953if(defined$input_params{'action'} && 954$input_params{'action'}eq'snapshot'&& 955defined$refname&&index($refname,'.') != -1&& 956$refnameeq$input_params{'hash'} && 957!defined$input_params{'snapshot_format'}) { 958# We loop over the known snapshot formats, checking for 959# extensions. Allowed extensions are both the defined suffix 960# (which includes the initial dot already) and the snapshot 961# format key itself, with a prepended dot 962while(my($fmt,$opt) =each%known_snapshot_formats) { 963my$hash=$refname; 964unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 965next; 966} 967my$sfx=$1; 968# a valid suffix was found, so set the snapshot format 969# and reset the hash parameter 970$input_params{'snapshot_format'} =$fmt; 971$input_params{'hash'} =$hash; 972# we also set the format suffix to the one requested 973# in the URL: this way a request for e.g. .tgz returns 974# a .tgz instead of a .tar.gz 975$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 976last; 977} 978} 979} 980 981our($action,$project,$file_name,$file_parent,$hash,$hash_parent,$hash_base, 982$hash_parent_base,@extra_options,$page,$searchtype,$search_use_regexp, 983$searchtext,$search_regexp,$project_filter); 984sub evaluate_and_validate_params { 985our$action=$input_params{'action'}; 986if(defined$action) { 987if(!validate_action($action)) { 988 die_error(400,"Invalid action parameter"); 989} 990} 991 992# parameters which are pathnames 993our$project=$input_params{'project'}; 994if(defined$project) { 995if(!validate_project($project)) { 996undef$project; 997 die_error(404,"No such project"); 998} 999}10001001our$project_filter=$input_params{'project_filter'};1002if(defined$project_filter) {1003if(!validate_pathname($project_filter)) {1004 die_error(404,"Invalid project_filter parameter");1005}1006}10071008our$file_name=$input_params{'file_name'};1009if(defined$file_name) {1010if(!validate_pathname($file_name)) {1011 die_error(400,"Invalid file parameter");1012}1013}10141015our$file_parent=$input_params{'file_parent'};1016if(defined$file_parent) {1017if(!validate_pathname($file_parent)) {1018 die_error(400,"Invalid file parent parameter");1019}1020}10211022# parameters which are refnames1023our$hash=$input_params{'hash'};1024if(defined$hash) {1025if(!validate_refname($hash)) {1026 die_error(400,"Invalid hash parameter");1027}1028}10291030our$hash_parent=$input_params{'hash_parent'};1031if(defined$hash_parent) {1032if(!validate_refname($hash_parent)) {1033 die_error(400,"Invalid hash parent parameter");1034}1035}10361037our$hash_base=$input_params{'hash_base'};1038if(defined$hash_base) {1039if(!validate_refname($hash_base)) {1040 die_error(400,"Invalid hash base parameter");1041}1042}10431044our@extra_options= @{$input_params{'extra_options'}};1045# @extra_options is always defined, since it can only be (currently) set from1046# CGI, and $cgi->param() returns the empty array in array context if the param1047# is not set1048foreachmy$opt(@extra_options) {1049if(not exists$allowed_options{$opt}) {1050 die_error(400,"Invalid option parameter");1051}1052if(not grep(/^$action$/, @{$allowed_options{$opt}})) {1053 die_error(400,"Invalid option parameter for this action");1054}1055}10561057our$hash_parent_base=$input_params{'hash_parent_base'};1058if(defined$hash_parent_base) {1059if(!validate_refname($hash_parent_base)) {1060 die_error(400,"Invalid hash parent base parameter");1061}1062}10631064# other parameters1065our$page=$input_params{'page'};1066if(defined$page) {1067if($page=~m/[^0-9]/) {1068 die_error(400,"Invalid page parameter");1069}1070}10711072our$searchtype=$input_params{'searchtype'};1073if(defined$searchtype) {1074if($searchtype=~m/[^a-z]/) {1075 die_error(400,"Invalid searchtype parameter");1076}1077}10781079our$search_use_regexp=$input_params{'search_use_regexp'};10801081our$searchtext=$input_params{'searchtext'};1082our$search_regexp;1083if(defined$searchtext) {1084if(length($searchtext) <2) {1085 die_error(403,"At least two characters are required for search parameter");1086}1087if($search_use_regexp) {1088$search_regexp=$searchtext;1089if(!eval{qr/$search_regexp/;1; }) {1090(my$error=$@) =~s/ at \S+ line \d+.*\n?//;1091 die_error(400,"Invalid search regexp '$search_regexp'",1092 esc_html($error));1093}1094}else{1095$search_regexp=quotemeta$searchtext;1096}1097}1098}10991100# path to the current git repository1101our$git_dir;1102sub evaluate_git_dir {1103our$git_dir="$projectroot/$project"if$project;1104}11051106our(@snapshot_fmts,$git_avatar);1107sub configure_gitweb_features {1108# list of supported snapshot formats1109our@snapshot_fmts= gitweb_get_feature('snapshot');1110@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts);11111112# check that the avatar feature is set to a known provider name,1113# and for each provider check if the dependencies are satisfied.1114# if the provider name is invalid or the dependencies are not met,1115# reset $git_avatar to the empty string.1116our($git_avatar) = gitweb_get_feature('avatar');1117if($git_avatareq'gravatar') {1118$git_avatar=''unless(eval{require Digest::MD5;1; });1119}elsif($git_avatareq'picon') {1120# no dependencies1121}else{1122$git_avatar='';1123}1124}11251126# custom error handler: 'die <message>' is Internal Server Error1127sub handle_errors_html {1128my$msg=shift;# it is already HTML escaped11291130# to avoid infinite loop where error occurs in die_error,1131# change handler to default handler, disabling handle_errors_html1132 set_message("Error occured when inside die_error:\n$msg");11331134# you cannot jump out of die_error when called as error handler;1135# the subroutine set via CGI::Carp::set_message is called _after_1136# HTTP headers are already written, so it cannot write them itself1137 die_error(undef,undef,$msg, -error_handler =>1, -no_http_header =>1);1138}1139set_message(\&handle_errors_html);11401141# dispatch1142sub dispatch {1143if(!defined$action) {1144if(defined$hash) {1145$action= git_get_type($hash);1146$actionor die_error(404,"Object does not exist");1147}elsif(defined$hash_base&&defined$file_name) {1148$action= git_get_type("$hash_base:$file_name");1149$actionor die_error(404,"File or directory does not exist");1150}elsif(defined$project) {1151$action='summary';1152}else{1153$action='project_list';1154}1155}1156if(!defined($actions{$action})) {1157 die_error(400,"Unknown action");1158}1159if($action!~m/^(?:opml|project_list|project_index)$/&&1160!$project) {1161 die_error(400,"Project needed");1162}1163$actions{$action}->();1164}11651166sub reset_timer {1167our$t0= [ gettimeofday() ]1168ifdefined$t0;1169our$number_of_git_cmds=0;1170}11711172our$first_request=1;1173sub run_request {1174 reset_timer();11751176 evaluate_uri();1177if($first_request) {1178 evaluate_gitweb_config();1179 evaluate_git_version();1180}1181if($per_request_config) {1182if(ref($per_request_config)eq'CODE') {1183$per_request_config->();1184}elsif(!$first_request) {1185 evaluate_gitweb_config();1186}1187}1188 check_loadavg();11891190# $projectroot and $projects_list might be set in gitweb config file1191$projects_list||=$projectroot;11921193 evaluate_query_params();1194 evaluate_path_info();1195 evaluate_and_validate_params();1196 evaluate_git_dir();11971198 configure_gitweb_features();11991200 dispatch();1201}12021203our$is_last_request=sub{1};1204our($pre_dispatch_hook,$post_dispatch_hook,$pre_listen_hook);1205our$CGI='CGI';1206our$cgi;1207sub configure_as_fcgi {1208require CGI::Fast;1209our$CGI='CGI::Fast';12101211my$request_number=0;1212# let each child service 100 requests1213our$is_last_request=sub{ ++$request_number>100};1214}1215sub evaluate_argv {1216my$script_name=$ENV{'SCRIPT_NAME'} ||$ENV{'SCRIPT_FILENAME'} || __FILE__;1217 configure_as_fcgi()1218if$script_name=~/\.fcgi$/;12191220return unless(@ARGV);12211222require Getopt::Long;1223 Getopt::Long::GetOptions(1224'fastcgi|fcgi|f'=> \&configure_as_fcgi,1225'nproc|n=i'=>sub{1226my($arg,$val) =@_;1227return unlesseval{require FCGI::ProcManager;1; };1228my$proc_manager= FCGI::ProcManager->new({1229 n_processes =>$val,1230});1231our$pre_listen_hook=sub{$proc_manager->pm_manage() };1232our$pre_dispatch_hook=sub{$proc_manager->pm_pre_dispatch() };1233our$post_dispatch_hook=sub{$proc_manager->pm_post_dispatch() };1234},1235);1236}12371238sub run {1239 evaluate_argv();12401241$first_request=1;1242$pre_listen_hook->()1243if$pre_listen_hook;12441245 REQUEST:1246while($cgi=$CGI->new()) {1247$pre_dispatch_hook->()1248if$pre_dispatch_hook;12491250 run_request();12511252$post_dispatch_hook->()1253if$post_dispatch_hook;1254$first_request=0;12551256last REQUEST if($is_last_request->());1257}12581259 DONE_GITWEB:12601;1261}12621263run();12641265if(defined caller) {1266# wrapped in a subroutine processing requests,1267# e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI1268return;1269}else{1270# pure CGI script, serving single request1271exit;1272}12731274## ======================================================================1275## action links12761277# possible values of extra options1278# -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)1279# -replay => 1 - start from a current view (replay with modifications)1280# -path_info => 0|1 - don't use/use path_info URL (if possible)1281# -anchor => ANCHOR - add #ANCHOR to end of URL, implies -replay if used alone1282sub href {1283my%params=@_;1284# default is to use -absolute url() i.e. $my_uri1285my$href=$params{-full} ?$my_url:$my_uri;12861287# implicit -replay, must be first of implicit params1288$params{-replay} =1if(keys%params==1&&$params{-anchor});12891290$params{'project'} =$projectunlessexists$params{'project'};12911292if($params{-replay}) {1293while(my($name,$symbol) =each%cgi_param_mapping) {1294if(!exists$params{$name}) {1295$params{$name} =$input_params{$name};1296}1297}1298}12991300my$use_pathinfo= gitweb_check_feature('pathinfo');1301if(defined$params{'project'} &&1302(exists$params{-path_info} ?$params{-path_info} :$use_pathinfo)) {1303# try to put as many parameters as possible in PATH_INFO:1304# - project name1305# - action1306# - hash_parent or hash_parent_base:/file_parent1307# - hash or hash_base:/filename1308# - the snapshot_format as an appropriate suffix13091310# When the script is the root DirectoryIndex for the domain,1311# $href here would be something like http://gitweb.example.com/1312# Thus, we strip any trailing / from $href, to spare us double1313# slashes in the final URL1314$href=~ s,/$,,;13151316# Then add the project name, if present1317$href.="/".esc_path_info($params{'project'});1318delete$params{'project'};13191320# since we destructively absorb parameters, we keep this1321# boolean that remembers if we're handling a snapshot1322my$is_snapshot=$params{'action'}eq'snapshot';13231324# Summary just uses the project path URL, any other action is1325# added to the URL1326if(defined$params{'action'}) {1327$href.="/".esc_path_info($params{'action'})1328unless$params{'action'}eq'summary';1329delete$params{'action'};1330}13311332# Next, we put hash_parent_base:/file_parent..hash_base:/file_name,1333# stripping nonexistent or useless pieces1334$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'}1335||$params{'hash_parent'} ||$params{'hash'});1336if(defined$params{'hash_base'}) {1337if(defined$params{'hash_parent_base'}) {1338$href.= esc_path_info($params{'hash_parent_base'});1339# skip the file_parent if it's the same as the file_name1340if(defined$params{'file_parent'}) {1341if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) {1342delete$params{'file_parent'};1343}elsif($params{'file_parent'} !~/\.\./) {1344$href.=":/".esc_path_info($params{'file_parent'});1345delete$params{'file_parent'};1346}1347}1348$href.="..";1349delete$params{'hash_parent'};1350delete$params{'hash_parent_base'};1351}elsif(defined$params{'hash_parent'}) {1352$href.= esc_path_info($params{'hash_parent'})."..";1353delete$params{'hash_parent'};1354}13551356$href.= esc_path_info($params{'hash_base'});1357if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) {1358$href.=":/".esc_path_info($params{'file_name'});1359delete$params{'file_name'};1360}1361delete$params{'hash'};1362delete$params{'hash_base'};1363}elsif(defined$params{'hash'}) {1364$href.= esc_path_info($params{'hash'});1365delete$params{'hash'};1366}13671368# If the action was a snapshot, we can absorb the1369# snapshot_format parameter too1370if($is_snapshot) {1371my$fmt=$params{'snapshot_format'};1372# snapshot_format should always be defined when href()1373# is called, but just in case some code forgets, we1374# fall back to the default1375$fmt||=$snapshot_fmts[0];1376$href.=$known_snapshot_formats{$fmt}{'suffix'};1377delete$params{'snapshot_format'};1378}1379}13801381# now encode the parameters explicitly1382my@result= ();1383for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1384my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1385if(defined$params{$name}) {1386if(ref($params{$name})eq"ARRAY") {1387foreachmy$par(@{$params{$name}}) {1388push@result,$symbol."=". esc_param($par);1389}1390}else{1391push@result,$symbol."=". esc_param($params{$name});1392}1393}1394}1395$href.="?".join(';',@result)ifscalar@result;13961397# final transformation: trailing spaces must be escaped (URI-encoded)1398$href=~s/(\s+)$/CGI::escape($1)/e;13991400if($params{-anchor}) {1401$href.="#".esc_param($params{-anchor});1402}14031404return$href;1405}140614071408## ======================================================================1409## validation, quoting/unquoting and escaping14101411sub validate_action {1412my$input=shift||returnundef;1413returnundefunlessexists$actions{$input};1414return$input;1415}14161417sub validate_project {1418my$input=shift||returnundef;1419if(!validate_pathname($input) ||1420!(-d "$projectroot/$input") ||1421!check_export_ok("$projectroot/$input") ||1422($strict_export&& !project_in_list($input))) {1423returnundef;1424}else{1425return$input;1426}1427}14281429sub validate_pathname {1430my$input=shift||returnundef;14311432# no '.' or '..' as elements of path, i.e. no '.' nor '..'1433# at the beginning, at the end, and between slashes.1434# also this catches doubled slashes1435if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1436returnundef;1437}1438# no null characters1439if($input=~m!\0!) {1440returnundef;1441}1442return$input;1443}14441445sub validate_refname {1446my$input=shift||returnundef;14471448# textual hashes are O.K.1449if($input=~m/^[0-9a-fA-F]{40}$/) {1450return$input;1451}1452# it must be correct pathname1453$input= validate_pathname($input)1454orreturnundef;1455# restrictions on ref name according to git-check-ref-format1456if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1457returnundef;1458}1459return$input;1460}14611462# decode sequences of octets in utf8 into Perl's internal form,1463# which is utf-8 with utf8 flag set if needed. gitweb writes out1464# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1465sub to_utf8 {1466my$str=shift;1467returnundefunlessdefined$str;14681469if(utf8::is_utf8($str) || utf8::decode($str)) {1470return$str;1471}else{1472return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1473}1474}14751476# quote unsafe chars, but keep the slash, even when it's not1477# correct, but quoted slashes look too horrible in bookmarks1478sub esc_param {1479my$str=shift;1480returnundefunlessdefined$str;1481$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1482$str=~s/ /\+/g;1483return$str;1484}14851486# the quoting rules for path_info fragment are slightly different1487sub esc_path_info {1488my$str=shift;1489returnundefunlessdefined$str;14901491# path_info doesn't treat '+' as space (specially), but '?' must be escaped1492$str=~s/([^A-Za-z0-9\-_.~();\/;:@&= +]+)/CGI::escape($1)/eg;14931494return$str;1495}14961497# quote unsafe chars in whole URL, so some characters cannot be quoted1498sub esc_url {1499my$str=shift;1500returnundefunlessdefined$str;1501$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg;1502$str=~s/ /\+/g;1503return$str;1504}15051506# quote unsafe characters in HTML attributes1507sub esc_attr {15081509# for XHTML conformance escaping '"' to '"' is not enough1510return esc_html(@_);1511}15121513# replace invalid utf8 character with SUBSTITUTION sequence1514sub esc_html {1515my$str=shift;1516my%opts=@_;15171518returnundefunlessdefined$str;15191520$str= to_utf8($str);1521$str=$cgi->escapeHTML($str);1522if($opts{'-nbsp'}) {1523$str=~s/ / /g;1524}1525$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1526return$str;1527}15281529# quote control characters and escape filename to HTML1530sub esc_path {1531my$str=shift;1532my%opts=@_;15331534returnundefunlessdefined$str;15351536$str= to_utf8($str);1537$str=$cgi->escapeHTML($str);1538if($opts{'-nbsp'}) {1539$str=~s/ / /g;1540}1541$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1542return$str;1543}15441545# Sanitize for use in XHTML + application/xml+xhtm (valid XML 1.0)1546sub sanitize {1547my$str=shift;15481549returnundefunlessdefined$str;15501551$str= to_utf8($str);1552$str=~ s|([[:cntrl:]])|($1=~/[\t\n\r]/?$1: quot_cec($1))|eg;1553return$str;1554}15551556# Make control characters "printable", using character escape codes (CEC)1557sub quot_cec {1558my$cntrl=shift;1559my%opts=@_;1560my%es= (# character escape codes, aka escape sequences1561"\t"=>'\t',# tab (HT)1562"\n"=>'\n',# line feed (LF)1563"\r"=>'\r',# carrige return (CR)1564"\f"=>'\f',# form feed (FF)1565"\b"=>'\b',# backspace (BS)1566"\a"=>'\a',# alarm (bell) (BEL)1567"\e"=>'\e',# escape (ESC)1568"\013"=>'\v',# vertical tab (VT)1569"\000"=>'\0',# nul character (NUL)1570);1571my$chr= ( (exists$es{$cntrl})1572?$es{$cntrl}1573:sprintf('\%2x',ord($cntrl)) );1574if($opts{-nohtml}) {1575return$chr;1576}else{1577return"<span class=\"cntrl\">$chr</span>";1578}1579}15801581# Alternatively use unicode control pictures codepoints,1582# Unicode "printable representation" (PR)1583sub quot_upr {1584my$cntrl=shift;1585my%opts=@_;15861587my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1588if($opts{-nohtml}) {1589return$chr;1590}else{1591return"<span class=\"cntrl\">$chr</span>";1592}1593}15941595# git may return quoted and escaped filenames1596sub unquote {1597my$str=shift;15981599sub unq {1600my$seq=shift;1601my%es= (# character escape codes, aka escape sequences1602't'=>"\t",# tab (HT, TAB)1603'n'=>"\n",# newline (NL)1604'r'=>"\r",# return (CR)1605'f'=>"\f",# form feed (FF)1606'b'=>"\b",# backspace (BS)1607'a'=>"\a",# alarm (bell) (BEL)1608'e'=>"\e",# escape (ESC)1609'v'=>"\013",# vertical tab (VT)1610);16111612if($seq=~m/^[0-7]{1,3}$/) {1613# octal char sequence1614returnchr(oct($seq));1615}elsif(exists$es{$seq}) {1616# C escape sequence, aka character escape code1617return$es{$seq};1618}1619# quoted ordinary character1620return$seq;1621}16221623if($str=~m/^"(.*)"$/) {1624# needs unquoting1625$str=$1;1626$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1627}1628return$str;1629}16301631# escape tabs (convert tabs to spaces)1632sub untabify {1633my$line=shift;16341635while((my$pos=index($line,"\t")) != -1) {1636if(my$count= (8- ($pos%8))) {1637my$spaces=' ' x $count;1638$line=~s/\t/$spaces/;1639}1640}16411642return$line;1643}16441645sub project_in_list {1646my$project=shift;1647my@list= git_get_projects_list();1648return@list&&scalar(grep{$_->{'path'}eq$project}@list);1649}16501651## ----------------------------------------------------------------------1652## HTML aware string manipulation16531654# Try to chop given string on a word boundary between position1655# $len and $len+$add_len. If there is no word boundary there,1656# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1657# (marking chopped part) would be longer than given string.1658sub chop_str {1659my$str=shift;1660my$len=shift;1661my$add_len=shift||10;1662my$where=shift||'right';# 'left' | 'center' | 'right'16631664# Make sure perl knows it is utf8 encoded so we don't1665# cut in the middle of a utf8 multibyte char.1666$str= to_utf8($str);16671668# allow only $len chars, but don't cut a word if it would fit in $add_len1669# if it doesn't fit, cut it if it's still longer than the dots we would add1670# remove chopped character entities entirely16711672# when chopping in the middle, distribute $len into left and right part1673# return early if chopping wouldn't make string shorter1674if($whereeq'center') {1675return$strif($len+5>=length($str));# filler is length 51676$len=int($len/2);1677}else{1678return$strif($len+4>=length($str));# filler is length 41679}16801681# regexps: ending and beginning with word part up to $add_len1682my$endre=qr/.{$len}\w{0,$add_len}/;1683my$begre=qr/\w{0,$add_len}.{$len}/;16841685if($whereeq'left') {1686$str=~m/^(.*?)($begre)$/;1687my($lead,$body) = ($1,$2);1688if(length($lead) >4) {1689$lead=" ...";1690}1691return"$lead$body";16921693}elsif($whereeq'center') {1694$str=~m/^($endre)(.*)$/;1695my($left,$str) = ($1,$2);1696$str=~m/^(.*?)($begre)$/;1697my($mid,$right) = ($1,$2);1698if(length($mid) >5) {1699$mid=" ... ";1700}1701return"$left$mid$right";17021703}else{1704$str=~m/^($endre)(.*)$/;1705my$body=$1;1706my$tail=$2;1707if(length($tail) >4) {1708$tail="... ";1709}1710return"$body$tail";1711}1712}17131714# takes the same arguments as chop_str, but also wraps a <span> around the1715# result with a title attribute if it does get chopped. Additionally, the1716# string is HTML-escaped.1717sub chop_and_escape_str {1718my($str) =@_;17191720my$chopped= chop_str(@_);1721$str= to_utf8($str);1722if($choppedeq$str) {1723return esc_html($chopped);1724}else{1725$str=~s/[[:cntrl:]]/?/g;1726return$cgi->span({-title=>$str}, esc_html($chopped));1727}1728}17291730# Highlight selected fragments of string, using given CSS class,1731# and escape HTML. It is assumed that fragments do not overlap.1732# Regions are passed as list of pairs (array references).1733#1734# Example: esc_html_hl_regions("foobar", "mark", [ 0, 3 ]) returns1735# '<span class="mark">foo</span>bar'1736sub esc_html_hl_regions {1737my($str,$css_class,@sel) =@_;1738return esc_html($str)unless@sel;17391740my$out='';1741my$pos=0;17421743formy$s(@sel) {1744$out.= esc_html(substr($str,$pos,$s->[0] -$pos))1745if($s->[0] -$pos>0);1746$out.=$cgi->span({-class=>$css_class},1747 esc_html(substr($str,$s->[0],$s->[1] -$s->[0])));17481749$pos=$s->[1];1750}1751$out.= esc_html(substr($str,$pos))1752if($pos<length($str));17531754return$out;1755}17561757# return positions of beginning and end of each match1758sub matchpos_list {1759my($str,$regexp) =@_;1760return unless(defined$str&&defined$regexp);17611762my@matches;1763while($str=~/$regexp/g) {1764push@matches, [$-[0],$+[0]];1765}1766return@matches;1767}17681769# highlight match (if any), and escape HTML1770sub esc_html_match_hl {1771my($str,$regexp) =@_;1772return esc_html($str)unlessdefined$regexp;17731774my@matches= matchpos_list($str,$regexp);1775return esc_html($str)unless@matches;17761777return esc_html_hl_regions($str,'match',@matches);1778}177917801781# highlight match (if any) of shortened string, and escape HTML1782sub esc_html_match_hl_chopped {1783my($str,$chopped,$regexp) =@_;1784return esc_html_match_hl($str,$regexp)unlessdefined$chopped;17851786my@matches= matchpos_list($str,$regexp);1787return esc_html($chopped)unless@matches;17881789# filter matches so that we mark chopped string1790my$tail="... ";# see chop_str1791unless($chopped=~s/\Q$tail\E$//) {1792$tail='';1793}1794my$chop_len=length($chopped);1795my$tail_len=length($tail);1796my@filtered;17971798formy$m(@matches) {1799if($m->[0] >$chop_len) {1800push@filtered, [$chop_len,$chop_len+$tail_len]if($tail_len>0);1801last;1802}elsif($m->[1] >$chop_len) {1803push@filtered, [$m->[0],$chop_len+$tail_len];1804last;1805}1806push@filtered,$m;1807}18081809return esc_html_hl_regions($chopped.$tail,'match',@filtered);1810}18111812## ----------------------------------------------------------------------1813## functions returning short strings18141815# CSS class for given age value (in seconds)1816sub age_class {1817my$age=shift;18181819if(!defined$age) {1820return"noage";1821}elsif($age<60*60*2) {1822return"age0";1823}elsif($age<60*60*24*2) {1824return"age1";1825}else{1826return"age2";1827}1828}18291830# convert age in seconds to "nn units ago" string1831sub age_string {1832my$age=shift;1833my$age_str;18341835if($age>60*60*24*365*2) {1836$age_str= (int$age/60/60/24/365);1837$age_str.=" years ago";1838}elsif($age>60*60*24*(365/12)*2) {1839$age_str=int$age/60/60/24/(365/12);1840$age_str.=" months ago";1841}elsif($age>60*60*24*7*2) {1842$age_str=int$age/60/60/24/7;1843$age_str.=" weeks ago";1844}elsif($age>60*60*24*2) {1845$age_str=int$age/60/60/24;1846$age_str.=" days ago";1847}elsif($age>60*60*2) {1848$age_str=int$age/60/60;1849$age_str.=" hours ago";1850}elsif($age>60*2) {1851$age_str=int$age/60;1852$age_str.=" min ago";1853}elsif($age>2) {1854$age_str=int$age;1855$age_str.=" sec ago";1856}else{1857$age_str.=" right now";1858}1859return$age_str;1860}18611862useconstant{1863 S_IFINVALID =>0030000,1864 S_IFGITLINK =>0160000,1865};18661867# submodule/subproject, a commit object reference1868sub S_ISGITLINK {1869my$mode=shift;18701871return(($mode& S_IFMT) == S_IFGITLINK)1872}18731874# convert file mode in octal to symbolic file mode string1875sub mode_str {1876my$mode=oct shift;18771878if(S_ISGITLINK($mode)) {1879return'm---------';1880}elsif(S_ISDIR($mode& S_IFMT)) {1881return'drwxr-xr-x';1882}elsif(S_ISLNK($mode)) {1883return'lrwxrwxrwx';1884}elsif(S_ISREG($mode)) {1885# git cares only about the executable bit1886if($mode& S_IXUSR) {1887return'-rwxr-xr-x';1888}else{1889return'-rw-r--r--';1890};1891}else{1892return'----------';1893}1894}18951896# convert file mode in octal to file type string1897sub file_type {1898my$mode=shift;18991900if($mode!~m/^[0-7]+$/) {1901return$mode;1902}else{1903$mode=oct$mode;1904}19051906if(S_ISGITLINK($mode)) {1907return"submodule";1908}elsif(S_ISDIR($mode& S_IFMT)) {1909return"directory";1910}elsif(S_ISLNK($mode)) {1911return"symlink";1912}elsif(S_ISREG($mode)) {1913return"file";1914}else{1915return"unknown";1916}1917}19181919# convert file mode in octal to file type description string1920sub file_type_long {1921my$mode=shift;19221923if($mode!~m/^[0-7]+$/) {1924return$mode;1925}else{1926$mode=oct$mode;1927}19281929if(S_ISGITLINK($mode)) {1930return"submodule";1931}elsif(S_ISDIR($mode& S_IFMT)) {1932return"directory";1933}elsif(S_ISLNK($mode)) {1934return"symlink";1935}elsif(S_ISREG($mode)) {1936if($mode& S_IXUSR) {1937return"executable";1938}else{1939return"file";1940};1941}else{1942return"unknown";1943}1944}194519461947## ----------------------------------------------------------------------1948## functions returning short HTML fragments, or transforming HTML fragments1949## which don't belong to other sections19501951# format line of commit message.1952sub format_log_line_html {1953my$line=shift;19541955$line= esc_html($line, -nbsp=>1);1956$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1957$cgi->a({-href => href(action=>"object", hash=>$1),1958-class=>"text"},$1);1959}eg;19601961return$line;1962}19631964# format marker of refs pointing to given object19651966# the destination action is chosen based on object type and current context:1967# - for annotated tags, we choose the tag view unless it's the current view1968# already, in which case we go to shortlog view1969# - for other refs, we keep the current view if we're in history, shortlog or1970# log view, and select shortlog otherwise1971sub format_ref_marker {1972my($refs,$id) =@_;1973my$markers='';19741975if(defined$refs->{$id}) {1976foreachmy$ref(@{$refs->{$id}}) {1977# this code exploits the fact that non-lightweight tags are the1978# only indirect objects, and that they are the only objects for which1979# we want to use tag instead of shortlog as action1980my($type,$name) =qw();1981my$indirect= ($ref=~s/\^\{\}$//);1982# e.g. tags/v2.6.11 or heads/next1983if($ref=~m!^(.*?)s?/(.*)$!) {1984$type=$1;1985$name=$2;1986}else{1987$type="ref";1988$name=$ref;1989}19901991my$class=$type;1992$class.=" indirect"if$indirect;19931994my$dest_action="shortlog";19951996if($indirect) {1997$dest_action="tag"unless$actioneq"tag";1998}elsif($action=~/^(history|(short)?log)$/) {1999$dest_action=$action;2000}20012002my$dest="";2003$dest.="refs/"unless$ref=~ m!^refs/!;2004$dest.=$ref;20052006my$link=$cgi->a({2007-href => href(2008 action=>$dest_action,2009 hash=>$dest2010)},$name);20112012$markers.=" <span class=\"".esc_attr($class)."\"title=\"".esc_attr($ref)."\">".2013$link."</span>";2014}2015}20162017if($markers) {2018return' <span class="refs">'.$markers.'</span>';2019}else{2020return"";2021}2022}20232024# format, perhaps shortened and with markers, title line2025sub format_subject_html {2026my($long,$short,$href,$extra) =@_;2027$extra=''unlessdefined($extra);20282029if(length($short) <length($long)) {2030$long=~s/[[:cntrl:]]/?/g;2031return$cgi->a({-href =>$href, -class=>"list subject",2032-title => to_utf8($long)},2033 esc_html($short)) .$extra;2034}else{2035return$cgi->a({-href =>$href, -class=>"list subject"},2036 esc_html($long)) .$extra;2037}2038}20392040# Rather than recomputing the url for an email multiple times, we cache it2041# after the first hit. This gives a visible benefit in views where the avatar2042# for the same email is used repeatedly (e.g. shortlog).2043# The cache is shared by all avatar engines (currently gravatar only), which2044# are free to use it as preferred. Since only one avatar engine is used for any2045# given page, there's no risk for cache conflicts.2046our%avatar_cache= ();20472048# Compute the picon url for a given email, by using the picon search service over at2049# http://www.cs.indiana.edu/picons/search.html2050sub picon_url {2051my$email=lc shift;2052if(!$avatar_cache{$email}) {2053my($user,$domain) =split('@',$email);2054$avatar_cache{$email} =2055"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".2056"$domain/$user/".2057"users+domains+unknown/up/single";2058}2059return$avatar_cache{$email};2060}20612062# Compute the gravatar url for a given email, if it's not in the cache already.2063# Gravatar stores only the part of the URL before the size, since that's the2064# one computationally more expensive. This also allows reuse of the cache for2065# different sizes (for this particular engine).2066sub gravatar_url {2067my$email=lc shift;2068my$size=shift;2069$avatar_cache{$email} ||=2070"http://www.gravatar.com/avatar/".2071 Digest::MD5::md5_hex($email) ."?s=";2072return$avatar_cache{$email} .$size;2073}20742075# Insert an avatar for the given $email at the given $size if the feature2076# is enabled.2077sub git_get_avatar {2078my($email,%opts) =@_;2079my$pre_white= ($opts{-pad_before} ?" ":"");2080my$post_white= ($opts{-pad_after} ?" ":"");2081$opts{-size} ||='default';2082my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};2083my$url="";2084if($git_avatareq'gravatar') {2085$url= gravatar_url($email,$size);2086}elsif($git_avatareq'picon') {2087$url= picon_url($email);2088}2089# Other providers can be added by extending the if chain, defining $url2090# as needed. If no variant puts something in $url, we assume avatars2091# are completely disabled/unavailable.2092if($url) {2093return$pre_white.2094"<img width=\"$size\"".2095"class=\"avatar\"".2096"src=\"".esc_url($url)."\"".2097"alt=\"\"".2098"/>".$post_white;2099}else{2100return"";2101}2102}21032104sub format_search_author {2105my($author,$searchtype,$displaytext) =@_;2106my$have_search= gitweb_check_feature('search');21072108if($have_search) {2109my$performed="";2110if($searchtypeeq'author') {2111$performed="authored";2112}elsif($searchtypeeq'committer') {2113$performed="committed";2114}21152116return$cgi->a({-href => href(action=>"search", hash=>$hash,2117 searchtext=>$author,2118 searchtype=>$searchtype),class=>"list",2119 title=>"Search for commits$performedby$author"},2120$displaytext);21212122}else{2123return$displaytext;2124}2125}21262127# format the author name of the given commit with the given tag2128# the author name is chopped and escaped according to the other2129# optional parameters (see chop_str).2130sub format_author_html {2131my$tag=shift;2132my$co=shift;2133my$author= chop_and_escape_str($co->{'author_name'},@_);2134return"<$tagclass=\"author\">".2135 format_search_author($co->{'author_name'},"author",2136 git_get_avatar($co->{'author_email'}, -pad_after =>1) .2137$author) .2138"</$tag>";2139}21402141# format git diff header line, i.e. "diff --(git|combined|cc) ..."2142sub format_git_diff_header_line {2143my$line=shift;2144my$diffinfo=shift;2145my($from,$to) =@_;21462147if($diffinfo->{'nparents'}) {2148# combined diff2149$line=~s!^(diff (.*?) )"?.*$!$1!;2150if($to->{'href'}) {2151$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},2152 esc_path($to->{'file'}));2153}else{# file was deleted (no href)2154$line.= esc_path($to->{'file'});2155}2156}else{2157# "ordinary" diff2158$line=~s!^(diff (.*?) )"?a/.*$!$1!;2159if($from->{'href'}) {2160$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},2161'a/'. esc_path($from->{'file'}));2162}else{# file was added (no href)2163$line.='a/'. esc_path($from->{'file'});2164}2165$line.=' ';2166if($to->{'href'}) {2167$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},2168'b/'. esc_path($to->{'file'}));2169}else{# file was deleted2170$line.='b/'. esc_path($to->{'file'});2171}2172}21732174return"<div class=\"diff header\">$line</div>\n";2175}21762177# format extended diff header line, before patch itself2178sub format_extended_diff_header_line {2179my$line=shift;2180my$diffinfo=shift;2181my($from,$to) =@_;21822183# match <path>2184if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {2185$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},2186 esc_path($from->{'file'}));2187}2188if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {2189$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},2190 esc_path($to->{'file'}));2191}2192# match single <mode>2193if($line=~m/\s(\d{6})$/) {2194$line.='<span class="info"> ('.2195 file_type_long($1) .2196')</span>';2197}2198# match <hash>2199if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {2200# can match only for combined diff2201$line='index ';2202for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2203if($from->{'href'}[$i]) {2204$line.=$cgi->a({-href=>$from->{'href'}[$i],2205-class=>"hash"},2206substr($diffinfo->{'from_id'}[$i],0,7));2207}else{2208$line.='0' x 7;2209}2210# separator2211$line.=','if($i<$diffinfo->{'nparents'} -1);2212}2213$line.='..';2214if($to->{'href'}) {2215$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2216substr($diffinfo->{'to_id'},0,7));2217}else{2218$line.='0' x 7;2219}22202221}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {2222# can match only for ordinary diff2223my($from_link,$to_link);2224if($from->{'href'}) {2225$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},2226substr($diffinfo->{'from_id'},0,7));2227}else{2228$from_link='0' x 7;2229}2230if($to->{'href'}) {2231$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2232substr($diffinfo->{'to_id'},0,7));2233}else{2234$to_link='0' x 7;2235}2236my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});2237$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;2238}22392240return$line."<br/>\n";2241}22422243# format from-file/to-file diff header2244sub format_diff_from_to_header {2245my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;2246my$line;2247my$result='';22482249$line=$from_line;2250#assert($line =~ m/^---/) if DEBUG;2251# no extra formatting for "^--- /dev/null"2252if(!$diffinfo->{'nparents'}) {2253# ordinary (single parent) diff2254if($line=~m!^--- "?a/!) {2255if($from->{'href'}) {2256$line='--- a/'.2257$cgi->a({-href=>$from->{'href'}, -class=>"path"},2258 esc_path($from->{'file'}));2259}else{2260$line='--- a/'.2261 esc_path($from->{'file'});2262}2263}2264$result.= qq!<div class="diff from_file">$line</div>\n!;22652266}else{2267# combined diff (merge commit)2268for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2269if($from->{'href'}[$i]) {2270$line='--- '.2271$cgi->a({-href=>href(action=>"blobdiff",2272 hash_parent=>$diffinfo->{'from_id'}[$i],2273 hash_parent_base=>$parents[$i],2274 file_parent=>$from->{'file'}[$i],2275 hash=>$diffinfo->{'to_id'},2276 hash_base=>$hash,2277 file_name=>$to->{'file'}),2278-class=>"path",2279-title=>"diff". ($i+1)},2280$i+1) .2281'/'.2282$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},2283 esc_path($from->{'file'}[$i]));2284}else{2285$line='--- /dev/null';2286}2287$result.= qq!<div class="diff from_file">$line</div>\n!;2288}2289}22902291$line=$to_line;2292#assert($line =~ m/^\+\+\+/) if DEBUG;2293# no extra formatting for "^+++ /dev/null"2294if($line=~m!^\+\+\+ "?b/!) {2295if($to->{'href'}) {2296$line='+++ b/'.2297$cgi->a({-href=>$to->{'href'}, -class=>"path"},2298 esc_path($to->{'file'}));2299}else{2300$line='+++ b/'.2301 esc_path($to->{'file'});2302}2303}2304$result.= qq!<div class="diff to_file">$line</div>\n!;23052306return$result;2307}23082309# create note for patch simplified by combined diff2310sub format_diff_cc_simplified {2311my($diffinfo,@parents) =@_;2312my$result='';23132314$result.="<div class=\"diff header\">".2315"diff --cc ";2316if(!is_deleted($diffinfo)) {2317$result.=$cgi->a({-href => href(action=>"blob",2318 hash_base=>$hash,2319 hash=>$diffinfo->{'to_id'},2320 file_name=>$diffinfo->{'to_file'}),2321-class=>"path"},2322 esc_path($diffinfo->{'to_file'}));2323}else{2324$result.= esc_path($diffinfo->{'to_file'});2325}2326$result.="</div>\n".# class="diff header"2327"<div class=\"diff nodifferences\">".2328"Simple merge".2329"</div>\n";# class="diff nodifferences"23302331return$result;2332}23332334sub diff_line_class {2335my($line,$from,$to) =@_;23362337# ordinary diff2338my$num_sign=1;2339# combined diff2340if($from&&$to&&ref($from->{'href'})eq"ARRAY") {2341$num_sign=scalar@{$from->{'href'}};2342}23432344my@diff_line_classifier= (2345{ regexp =>qr/^\@\@{$num_sign} /,class=>"chunk_header"},2346{ regexp =>qr/^\\/,class=>"incomplete"},2347{ regexp =>qr/^ {$num_sign}/,class=>"ctx"},2348# classifier for context must come before classifier add/rem,2349# or we would have to use more complicated regexp, for example2350# qr/(?= {0,$m}\+)[+ ]{$num_sign}/, where $m = $num_sign - 1;2351{ regexp =>qr/^[+ ]{$num_sign}/,class=>"add"},2352{ regexp =>qr/^[- ]{$num_sign}/,class=>"rem"},2353);2354formy$clsfy(@diff_line_classifier) {2355return$clsfy->{'class'}2356if($line=~$clsfy->{'regexp'});2357}23582359# fallback2360return"";2361}23622363# assumes that $from and $to are defined and correctly filled,2364# and that $line holds a line of chunk header for unified diff2365sub format_unidiff_chunk_header {2366my($line,$from,$to) =@_;23672368my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =2369$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;23702371$from_lines=0unlessdefined$from_lines;2372$to_lines=0unlessdefined$to_lines;23732374if($from->{'href'}) {2375$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",2376-class=>"list"},$from_text);2377}2378if($to->{'href'}) {2379$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",2380-class=>"list"},$to_text);2381}2382$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".2383"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2384return$line;2385}23862387# assumes that $from and $to are defined and correctly filled,2388# and that $line holds a line of chunk header for combined diff2389sub format_cc_diff_chunk_header {2390my($line,$from,$to) =@_;23912392my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;2393my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);23942395@from_text=split(' ',$ranges);2396for(my$i=0;$i<@from_text; ++$i) {2397($from_start[$i],$from_nlines[$i]) =2398(split(',',substr($from_text[$i],1)),0);2399}24002401$to_text=pop@from_text;2402$to_start=pop@from_start;2403$to_nlines=pop@from_nlines;24042405$line="<span class=\"chunk_info\">$prefix";2406for(my$i=0;$i<@from_text; ++$i) {2407if($from->{'href'}[$i]) {2408$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",2409-class=>"list"},$from_text[$i]);2410}else{2411$line.=$from_text[$i];2412}2413$line.=" ";2414}2415if($to->{'href'}) {2416$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",2417-class=>"list"},$to_text);2418}else{2419$line.=$to_text;2420}2421$line.="$prefix</span>".2422"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2423return$line;2424}24252426# process patch (diff) line (not to be used for diff headers),2427# returning class and HTML-formatted (but not wrapped) line2428sub process_diff_line {2429my$line=shift;2430my($from,$to) =@_;24312432my$diff_class= diff_line_class($line,$from,$to);24332434chomp$line;2435$line= untabify($line);24362437if($from&&$to&&$line=~m/^\@{2} /) {2438$line= format_unidiff_chunk_header($line,$from,$to);2439return$diff_class,$line;24402441}elsif($from&&$to&&$line=~m/^\@{3}/) {2442$line= format_cc_diff_chunk_header($line,$from,$to);2443return$diff_class,$line;24442445}2446return$diff_class, esc_html($line, -nbsp=>1);2447}24482449# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",2450# linked. Pass the hash of the tree/commit to snapshot.2451sub format_snapshot_links {2452my($hash) =@_;2453my$num_fmts=@snapshot_fmts;2454if($num_fmts>1) {2455# A parenthesized list of links bearing format names.2456# e.g. "snapshot (_tar.gz_ _zip_)"2457return"snapshot (".join(' ',map2458$cgi->a({2459-href => href(2460 action=>"snapshot",2461 hash=>$hash,2462 snapshot_format=>$_2463)2464},$known_snapshot_formats{$_}{'display'})2465,@snapshot_fmts) .")";2466}elsif($num_fmts==1) {2467# A single "snapshot" link whose tooltip bears the format name.2468# i.e. "_snapshot_"2469my($fmt) =@snapshot_fmts;2470return2471$cgi->a({2472-href => href(2473 action=>"snapshot",2474 hash=>$hash,2475 snapshot_format=>$fmt2476),2477-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"2478},"snapshot");2479}else{# $num_fmts == 02480returnundef;2481}2482}24832484## ......................................................................2485## functions returning values to be passed, perhaps after some2486## transformation, to other functions; e.g. returning arguments to href()24872488# returns hash to be passed to href to generate gitweb URL2489# in -title key it returns description of link2490sub get_feed_info {2491my$format=shift||'Atom';2492my%res= (action =>lc($format));24932494# feed links are possible only for project views2495return unless(defined$project);2496# some views should link to OPML, or to generic project feed,2497# or don't have specific feed yet (so they should use generic)2498return if(!$action||$action=~/^(?:tags|heads|forks|tag|search)$/x);24992500my$branch;2501# branches refs uses 'refs/heads/' prefix (fullname) to differentiate2502# from tag links; this also makes possible to detect branch links2503if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||2504(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {2505$branch=$1;2506}2507# find log type for feed description (title)2508my$type='log';2509if(defined$file_name) {2510$type="history of$file_name";2511$type.="/"if($actioneq'tree');2512$type.=" on '$branch'"if(defined$branch);2513}else{2514$type="log of$branch"if(defined$branch);2515}25162517$res{-title} =$type;2518$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);2519$res{'file_name'} =$file_name;25202521return%res;2522}25232524## ----------------------------------------------------------------------2525## git utility subroutines, invoking git commands25262527# returns path to the core git executable and the --git-dir parameter as list2528sub git_cmd {2529$number_of_git_cmds++;2530return$GIT,'--git-dir='.$git_dir;2531}25322533# quote the given arguments for passing them to the shell2534# quote_command("command", "arg 1", "arg with ' and ! characters")2535# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2536# Try to avoid using this function wherever possible.2537sub quote_command {2538returnjoin(' ',2539map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2540}25412542# get HEAD ref of given project as hash2543sub git_get_head_hash {2544return git_get_full_hash(shift,'HEAD');2545}25462547sub git_get_full_hash {2548return git_get_hash(@_);2549}25502551sub git_get_short_hash {2552return git_get_hash(@_,'--short=7');2553}25542555sub git_get_hash {2556my($project,$hash,@options) =@_;2557my$o_git_dir=$git_dir;2558my$retval=undef;2559$git_dir="$projectroot/$project";2560if(open my$fd,'-|', git_cmd(),'rev-parse',2561'--verify','-q',@options,$hash) {2562$retval= <$fd>;2563chomp$retvalifdefined$retval;2564close$fd;2565}2566if(defined$o_git_dir) {2567$git_dir=$o_git_dir;2568}2569return$retval;2570}25712572# get type of given object2573sub git_get_type {2574my$hash=shift;25752576open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2577my$type= <$fd>;2578close$fdorreturn;2579chomp$type;2580return$type;2581}25822583# repository configuration2584our$config_file='';2585our%config;25862587# store multiple values for single key as anonymous array reference2588# single values stored directly in the hash, not as [ <value> ]2589sub hash_set_multi {2590my($hash,$key,$value) =@_;25912592if(!exists$hash->{$key}) {2593$hash->{$key} =$value;2594}elsif(!ref$hash->{$key}) {2595$hash->{$key} = [$hash->{$key},$value];2596}else{2597push@{$hash->{$key}},$value;2598}2599}26002601# return hash of git project configuration2602# optionally limited to some section, e.g. 'gitweb'2603sub git_parse_project_config {2604my$section_regexp=shift;2605my%config;26062607local$/="\0";26082609open my$fh,"-|", git_cmd(),"config",'-z','-l',2610orreturn;26112612while(my$keyval= <$fh>) {2613chomp$keyval;2614my($key,$value) =split(/\n/,$keyval,2);26152616 hash_set_multi(\%config,$key,$value)2617if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2618}2619close$fh;26202621return%config;2622}26232624# convert config value to boolean: 'true' or 'false'2625# no value, number > 0, 'true' and 'yes' values are true2626# rest of values are treated as false (never as error)2627sub config_to_bool {2628my$val=shift;26292630return1if!defined$val;# section.key26312632# strip leading and trailing whitespace2633$val=~s/^\s+//;2634$val=~s/\s+$//;26352636return(($val=~/^\d+$/&&$val) ||# section.key = 12637($val=~/^(?:true|yes)$/i));# section.key = true2638}26392640# convert config value to simple decimal number2641# an optional value suffix of 'k', 'm', or 'g' will cause the value2642# to be multiplied by 1024, 1048576, or 10737418242643sub config_to_int {2644my$val=shift;26452646# strip leading and trailing whitespace2647$val=~s/^\s+//;2648$val=~s/\s+$//;26492650if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2651$unit=lc($unit);2652# unknown unit is treated as 12653return$num* ($uniteq'g'?1073741824:2654$uniteq'm'?1048576:2655$uniteq'k'?1024:1);2656}2657return$val;2658}26592660# convert config value to array reference, if needed2661sub config_to_multi {2662my$val=shift;26632664returnref($val) ?$val: (defined($val) ? [$val] : []);2665}26662667sub git_get_project_config {2668my($key,$type) =@_;26692670return unlessdefined$git_dir;26712672# key sanity check2673return unless($key);2674# only subsection, if exists, is case sensitive,2675# and not lowercased by 'git config -z -l'2676if(my($hi,$mi,$lo) = ($key=~/^([^.]*)\.(.*)\.([^.]*)$/)) {2677$key=join(".",lc($hi),$mi,lc($lo));2678}else{2679$key=lc($key);2680}2681$key=~s/^gitweb\.//;2682return if($key=~m/\W/);26832684# type sanity check2685if(defined$type) {2686$type=~s/^--//;2687$type=undef2688unless($typeeq'bool'||$typeeq'int');2689}26902691# get config2692if(!defined$config_file||2693$config_filene"$git_dir/config") {2694%config= git_parse_project_config('gitweb');2695$config_file="$git_dir/config";2696}26972698# check if config variable (key) exists2699return unlessexists$config{"gitweb.$key"};27002701# ensure given type2702if(!defined$type) {2703return$config{"gitweb.$key"};2704}elsif($typeeq'bool') {2705# backward compatibility: 'git config --bool' returns true/false2706return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2707}elsif($typeeq'int') {2708return config_to_int($config{"gitweb.$key"});2709}2710return$config{"gitweb.$key"};2711}27122713# get hash of given path at given ref2714sub git_get_hash_by_path {2715my$base=shift;2716my$path=shift||returnundef;2717my$type=shift;27182719$path=~ s,/+$,,;27202721open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2722or die_error(500,"Open git-ls-tree failed");2723my$line= <$fd>;2724close$fdorreturnundef;27252726if(!defined$line) {2727# there is no tree or hash given by $path at $base2728returnundef;2729}27302731#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2732$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2733if(defined$type&&$typene$2) {2734# type doesn't match2735returnundef;2736}2737return$3;2738}27392740# get path of entry with given hash at given tree-ish (ref)2741# used to get 'from' filename for combined diff (merge commit) for renames2742sub git_get_path_by_hash {2743my$base=shift||return;2744my$hash=shift||return;27452746local$/="\0";27472748open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2749orreturnundef;2750while(my$line= <$fd>) {2751chomp$line;27522753#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2754#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2755if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2756close$fd;2757return$1;2758}2759}2760close$fd;2761returnundef;2762}27632764## ......................................................................2765## git utility functions, directly accessing git repository27662767# get the value of config variable either from file named as the variable2768# itself in the repository ($GIT_DIR/$name file), or from gitweb.$name2769# configuration variable in the repository config file.2770sub git_get_file_or_project_config {2771my($path,$name) =@_;27722773$git_dir="$projectroot/$path";2774open my$fd,'<',"$git_dir/$name"2775orreturn git_get_project_config($name);2776my$conf= <$fd>;2777close$fd;2778if(defined$conf) {2779chomp$conf;2780}2781return$conf;2782}27832784sub git_get_project_description {2785my$path=shift;2786return git_get_file_or_project_config($path,'description');2787}27882789sub git_get_project_category {2790my$path=shift;2791return git_get_file_or_project_config($path,'category');2792}279327942795# supported formats:2796# * $GIT_DIR/ctags/<tagname> file (in 'ctags' subdirectory)2797# - if its contents is a number, use it as tag weight,2798# - otherwise add a tag with weight 12799# * $GIT_DIR/ctags file, each line is a tag (with weight 1)2800# the same value multiple times increases tag weight2801# * `gitweb.ctag' multi-valued repo config variable2802sub git_get_project_ctags {2803my$project=shift;2804my$ctags= {};28052806$git_dir="$projectroot/$project";2807if(opendir my$dh,"$git_dir/ctags") {2808my@files=grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh);2809foreachmy$tagfile(@files) {2810open my$ct,'<',$tagfile2811ornext;2812my$val= <$ct>;2813chomp$valif$val;2814close$ct;28152816(my$ctag=$tagfile) =~ s#.*/##;2817if($val=~/^\d+$/) {2818$ctags->{$ctag} =$val;2819}else{2820$ctags->{$ctag} =1;2821}2822}2823closedir$dh;28242825}elsif(open my$fh,'<',"$git_dir/ctags") {2826while(my$line= <$fh>) {2827chomp$line;2828$ctags->{$line}++if$line;2829}2830close$fh;28312832}else{2833my$taglist= config_to_multi(git_get_project_config('ctag'));2834foreachmy$tag(@$taglist) {2835$ctags->{$tag}++;2836}2837}28382839return$ctags;2840}28412842# return hash, where keys are content tags ('ctags'),2843# and values are sum of weights of given tag in every project2844sub git_gather_all_ctags {2845my$projects=shift;2846my$ctags= {};28472848foreachmy$p(@$projects) {2849foreachmy$ct(keys%{$p->{'ctags'}}) {2850$ctags->{$ct} +=$p->{'ctags'}->{$ct};2851}2852}28532854return$ctags;2855}28562857sub git_populate_project_tagcloud {2858my$ctags=shift;28592860# First, merge different-cased tags; tags vote on casing2861my%ctags_lc;2862foreach(keys%$ctags) {2863$ctags_lc{lc$_}->{count} +=$ctags->{$_};2864if(not$ctags_lc{lc$_}->{topcount}2865or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2866$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2867$ctags_lc{lc$_}->{topname} =$_;2868}2869}28702871my$cloud;2872my$matched=$input_params{'ctag'};2873if(eval{require HTML::TagCloud;1; }) {2874$cloud= HTML::TagCloud->new;2875foreachmy$ctag(sort keys%ctags_lc) {2876# Pad the title with spaces so that the cloud looks2877# less crammed.2878my$title= esc_html($ctags_lc{$ctag}->{topname});2879$title=~s/ / /g;2880$title=~s/^/ /g;2881$title=~s/$/ /g;2882if(defined$matched&&$matchedeq$ctag) {2883$title=qq(<span class="match">$title</span>);2884}2885$cloud->add($title, href(project=>undef, ctag=>$ctag),2886$ctags_lc{$ctag}->{count});2887}2888}else{2889$cloud= {};2890foreachmy$ctag(keys%ctags_lc) {2891my$title= esc_html($ctags_lc{$ctag}->{topname}, -nbsp=>1);2892if(defined$matched&&$matchedeq$ctag) {2893$title=qq(<span class="match">$title</span>);2894}2895$cloud->{$ctag}{count} =$ctags_lc{$ctag}->{count};2896$cloud->{$ctag}{ctag} =2897$cgi->a({-href=>href(project=>undef, ctag=>$ctag)},$title);2898}2899}2900return$cloud;2901}29022903sub git_show_project_tagcloud {2904my($cloud,$count) =@_;2905if(ref$cloudeq'HTML::TagCloud') {2906return$cloud->html_and_css($count);2907}else{2908my@tags=sort{$cloud->{$a}->{'count'} <=>$cloud->{$b}->{'count'} }keys%$cloud;2909return2910'<div id="htmltagcloud"'.($project?'':' align="center"').'>'.2911join(', ',map{2912$cloud->{$_}->{'ctag'}2913}splice(@tags,0,$count)) .2914'</div>';2915}2916}29172918sub git_get_project_url_list {2919my$path=shift;29202921$git_dir="$projectroot/$path";2922open my$fd,'<',"$git_dir/cloneurl"2923orreturnwantarray?2924@{ config_to_multi(git_get_project_config('url')) } :2925 config_to_multi(git_get_project_config('url'));2926my@git_project_url_list=map{chomp;$_} <$fd>;2927close$fd;29282929returnwantarray?@git_project_url_list: \@git_project_url_list;2930}29312932sub git_get_projects_list {2933my$filter=shift||'';2934my$paranoid=shift;2935my@list;29362937if(-d $projects_list) {2938# search in directory2939my$dir=$projects_list;2940# remove the trailing "/"2941$dir=~s!/+$!!;2942my$pfxlen=length("$dir");2943my$pfxdepth= ($dir=~tr!/!!);2944# when filtering, search only given subdirectory2945if($filter&& !$paranoid) {2946$dir.="/$filter";2947$dir=~s!/+$!!;2948}29492950 File::Find::find({2951 follow_fast =>1,# follow symbolic links2952 follow_skip =>2,# ignore duplicates2953 dangling_symlinks =>0,# ignore dangling symlinks, silently2954 wanted =>sub{2955# global variables2956our$project_maxdepth;2957our$projectroot;2958# skip project-list toplevel, if we get it.2959return if(m!^[/.]$!);2960# only directories can be git repositories2961return unless(-d $_);2962# don't traverse too deep (Find is super slow on os x)2963# $project_maxdepth excludes depth of $projectroot2964if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2965$File::Find::prune =1;2966return;2967}29682969my$path=substr($File::Find::name,$pfxlen+1);2970# paranoidly only filter here2971if($paranoid&&$filter&&$path!~m!^\Q$filter\E/!) {2972next;2973}2974# we check related file in $projectroot2975if(check_export_ok("$projectroot/$path")) {2976push@list, { path =>$path};2977$File::Find::prune =1;2978}2979},2980},"$dir");29812982}elsif(-f $projects_list) {2983# read from file(url-encoded):2984# 'git%2Fgit.git Linus+Torvalds'2985# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2986# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2987open my$fd,'<',$projects_listorreturn;2988 PROJECT:2989while(my$line= <$fd>) {2990chomp$line;2991my($path,$owner) =split' ',$line;2992$path= unescape($path);2993$owner= unescape($owner);2994if(!defined$path) {2995next;2996}2997# if $filter is rpovided, check if $path begins with $filter2998if($filter&&$path!~m!^\Q$filter\E/!) {2999next;3000}3001if(check_export_ok("$projectroot/$path")) {3002my$pr= {3003 path =>$path3004};3005if($owner) {3006$pr->{'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";5470unless($omit_age_column) {5471print"<td class=\"". age_class($pr->{'age'}) ."\">".5472(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n";5473}5474print"<td class=\"link\">".5475$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".5476$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".5477$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".5478$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .5479($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .5480"</td>\n".5481"</tr>\n";5482}5483}54845485sub git_project_list_body {5486# actually uses global variable $project5487my($projlist,$order,$from,$to,$extra,$no_header) =@_;5488my@projects=@$projlist;54895490my$check_forks= gitweb_check_feature('forks');5491my$show_ctags= gitweb_check_feature('ctags');5492my$tagfilter=$show_ctags?$input_params{'ctag'} :undef;5493$check_forks=undef5494if($tagfilter||$search_regexp);54955496# filtering out forks before filling info allows to do less work5497@projects= filter_forks_from_projects_list(\@projects)5498if($check_forks);5499# search_projects_list pre-fills required info5500@projects= search_projects_list(\@projects,5501'search_regexp'=>$search_regexp,5502'tagfilter'=>$tagfilter)5503if($tagfilter||$search_regexp);5504# fill the rest5505my@all_fields=$omit_age_column? ('descr','descr_long','owner','ctags','category') : ();5506@projects= fill_project_list_info(\@projects,@all_fields);55075508$order||=$default_projects_order;5509$from=0unlessdefined$from;5510$to=$#projectsif(!defined$to||$#projects<$to);55115512# short circuit5513if($from>$to) {5514print"<center>\n".5515"<b>No such projects found</b><br />\n".5516"Click ".$cgi->a({-href=>href(project=>undef)},"here")." to view all projects<br />\n".5517"</center>\n<br />\n";5518return;5519}55205521@projects= sort_projects_list(\@projects,$order);55225523if($show_ctags) {5524my$ctags= git_gather_all_ctags(\@projects);5525my$cloud= git_populate_project_tagcloud($ctags);5526print git_show_project_tagcloud($cloud,64);5527}55285529print"<table class=\"project_list\">\n";5530unless($no_header) {5531print"<tr>\n";5532if($check_forks) {5533print"<th></th>\n";5534}5535 print_sort_th('project',$order,'Project');5536 print_sort_th('descr',$order,'Description');5537 print_sort_th('owner',$order,'Owner');5538 print_sort_th('age',$order,'Last Change')unless$omit_age_column;5539print"<th></th>\n".# for links5540"</tr>\n";5541}55425543if($projects_list_group_categories) {5544# only display categories with projects in the $from-$to window5545@projects=sort{$a->{'category'}cmp$b->{'category'}}@projects[$from..$to];5546my%categories= build_projlist_by_category(\@projects,$from,$to);5547foreachmy$cat(sort keys%categories) {5548unless($cateq"") {5549print"<tr>\n";5550if($check_forks) {5551print"<td></td>\n";5552}5553print"<td class=\"category\"colspan=\"5\">".esc_html($cat)."</td>\n";5554print"</tr>\n";5555}55565557 git_project_list_rows($categories{$cat},undef,undef,$check_forks);5558}5559}else{5560 git_project_list_rows(\@projects,$from,$to,$check_forks);5561}55625563if(defined$extra) {5564print"<tr>\n";5565if($check_forks) {5566print"<td></td>\n";5567}5568print"<td colspan=\"5\">$extra</td>\n".5569"</tr>\n";5570}5571print"</table>\n";5572}55735574sub git_log_body {5575# uses global variable $project5576my($commitlist,$from,$to,$refs,$extra) =@_;55775578$from=0unlessdefined$from;5579$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);55805581for(my$i=0;$i<=$to;$i++) {5582my%co= %{$commitlist->[$i]};5583next if!%co;5584my$commit=$co{'id'};5585my$ref= format_ref_marker($refs,$commit);5586 git_print_header_div('commit',5587"<span class=\"age\">$co{'age_string'}</span>".5588 esc_html($co{'title'}) .$ref,5589$commit);5590print"<div class=\"title_text\">\n".5591"<div class=\"log_link\">\n".5592$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .5593" | ".5594$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .5595" | ".5596$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .5597"<br/>\n".5598"</div>\n";5599 git_print_authorship(\%co, -tag =>'span');5600print"<br/>\n</div>\n";56015602print"<div class=\"log_body\">\n";5603 git_print_log($co{'comment'}, -final_empty_line=>1);5604print"</div>\n";5605}5606if($extra) {5607print"<div class=\"page_nav\">\n";5608print"$extra\n";5609print"</div>\n";5610}5611}56125613sub git_shortlog_body {5614# uses global variable $project5615my($commitlist,$from,$to,$refs,$extra) =@_;56165617$from=0unlessdefined$from;5618$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);56195620print"<table class=\"shortlog\">\n";5621my$alternate=1;5622for(my$i=$from;$i<=$to;$i++) {5623my%co= %{$commitlist->[$i]};5624my$commit=$co{'id'};5625my$ref= format_ref_marker($refs,$commit);5626if($alternate) {5627print"<tr class=\"dark\">\n";5628}else{5629print"<tr class=\"light\">\n";5630}5631$alternate^=1;5632# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .5633print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5634 format_author_html('td', \%co,10) ."<td>";5635print format_subject_html($co{'title'},$co{'title_short'},5636 href(action=>"commit", hash=>$commit),$ref);5637print"</td>\n".5638"<td class=\"link\">".5639$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".5640$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".5641$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");5642my$snapshot_links= format_snapshot_links($commit);5643if(defined$snapshot_links) {5644print" | ".$snapshot_links;5645}5646print"</td>\n".5647"</tr>\n";5648}5649if(defined$extra) {5650print"<tr>\n".5651"<td colspan=\"4\">$extra</td>\n".5652"</tr>\n";5653}5654print"</table>\n";5655}56565657sub git_history_body {5658# Warning: assumes constant type (blob or tree) during history5659my($commitlist,$from,$to,$refs,$extra,5660$file_name,$file_hash,$ftype) =@_;56615662$from=0unlessdefined$from;5663$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});56645665print"<table class=\"history\">\n";5666my$alternate=1;5667for(my$i=$from;$i<=$to;$i++) {5668my%co= %{$commitlist->[$i]};5669if(!%co) {5670next;5671}5672my$commit=$co{'id'};56735674my$ref= format_ref_marker($refs,$commit);56755676if($alternate) {5677print"<tr class=\"dark\">\n";5678}else{5679print"<tr class=\"light\">\n";5680}5681$alternate^=1;5682print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5683# shortlog: format_author_html('td', \%co, 10)5684 format_author_html('td', \%co,15,3) ."<td>";5685# originally git_history used chop_str($co{'title'}, 50)5686print format_subject_html($co{'title'},$co{'title_short'},5687 href(action=>"commit", hash=>$commit),$ref);5688print"</td>\n".5689"<td class=\"link\">".5690$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".5691$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");56925693if($ftypeeq'blob') {5694my$blob_current=$file_hash;5695my$blob_parent= git_get_hash_by_path($commit,$file_name);5696if(defined$blob_current&&defined$blob_parent&&5697$blob_currentne$blob_parent) {5698print" | ".5699$cgi->a({-href => href(action=>"blobdiff",5700 hash=>$blob_current, hash_parent=>$blob_parent,5701 hash_base=>$hash_base, hash_parent_base=>$commit,5702 file_name=>$file_name)},5703"diff to current");5704}5705}5706print"</td>\n".5707"</tr>\n";5708}5709if(defined$extra) {5710print"<tr>\n".5711"<td colspan=\"4\">$extra</td>\n".5712"</tr>\n";5713}5714print"</table>\n";5715}57165717sub git_tags_body {5718# uses global variable $project5719my($taglist,$from,$to,$extra) =@_;5720$from=0unlessdefined$from;5721$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);57225723print"<table class=\"tags\">\n";5724my$alternate=1;5725for(my$i=$from;$i<=$to;$i++) {5726my$entry=$taglist->[$i];5727my%tag=%$entry;5728my$comment=$tag{'subject'};5729my$comment_short;5730if(defined$comment) {5731$comment_short= chop_str($comment,30,5);5732}5733if($alternate) {5734print"<tr class=\"dark\">\n";5735}else{5736print"<tr class=\"light\">\n";5737}5738$alternate^=1;5739if(defined$tag{'age'}) {5740print"<td><i>$tag{'age'}</i></td>\n";5741}else{5742print"<td></td>\n";5743}5744print"<td>".5745$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),5746-class=>"list name"}, esc_html($tag{'name'})) .5747"</td>\n".5748"<td>";5749if(defined$comment) {5750print format_subject_html($comment,$comment_short,5751 href(action=>"tag", hash=>$tag{'id'}));5752}5753print"</td>\n".5754"<td class=\"selflink\">";5755if($tag{'type'}eq"tag") {5756print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");5757}else{5758print" ";5759}5760print"</td>\n".5761"<td class=\"link\">"." | ".5762$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});5763if($tag{'reftype'}eq"commit") {5764print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .5765" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");5766}elsif($tag{'reftype'}eq"blob") {5767print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");5768}5769print"</td>\n".5770"</tr>";5771}5772if(defined$extra) {5773print"<tr>\n".5774"<td colspan=\"5\">$extra</td>\n".5775"</tr>\n";5776}5777print"</table>\n";5778}57795780sub git_heads_body {5781# uses global variable $project5782my($headlist,$head_at,$from,$to,$extra) =@_;5783$from=0unlessdefined$from;5784$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);57855786print"<table class=\"heads\">\n";5787my$alternate=1;5788for(my$i=$from;$i<=$to;$i++) {5789my$entry=$headlist->[$i];5790my%ref=%$entry;5791my$curr=defined$head_at&&$ref{'id'}eq$head_at;5792if($alternate) {5793print"<tr class=\"dark\">\n";5794}else{5795print"<tr class=\"light\">\n";5796}5797$alternate^=1;5798print"<td><i>$ref{'age'}</i></td>\n".5799($curr?"<td class=\"current_head\">":"<td>") .5800$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),5801-class=>"list name"},esc_html($ref{'name'})) .5802"</td>\n".5803"<td class=\"link\">".5804$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".5805$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".5806$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'fullname'})},"tree") .5807"</td>\n".5808"</tr>";5809}5810if(defined$extra) {5811print"<tr>\n".5812"<td colspan=\"3\">$extra</td>\n".5813"</tr>\n";5814}5815print"</table>\n";5816}58175818# Display a single remote block5819sub git_remote_block {5820my($remote,$rdata,$limit,$head) =@_;58215822my$heads=$rdata->{'heads'};5823my$fetch=$rdata->{'fetch'};5824my$push=$rdata->{'push'};58255826my$urls_table="<table class=\"projects_list\">\n";58275828if(defined$fetch) {5829if($fetcheq$push) {5830$urls_table.= format_repo_url("URL",$fetch);5831}else{5832$urls_table.= format_repo_url("Fetch URL",$fetch);5833$urls_table.= format_repo_url("Push URL",$push)ifdefined$push;5834}5835}elsif(defined$push) {5836$urls_table.= format_repo_url("Push URL",$push);5837}else{5838$urls_table.= format_repo_url("","No remote URL");5839}58405841$urls_table.="</table>\n";58425843my$dots;5844if(defined$limit&&$limit<@$heads) {5845$dots=$cgi->a({-href => href(action=>"remotes", hash=>$remote)},"...");5846}58475848print$urls_table;5849 git_heads_body($heads,$head,0,$limit,$dots);5850}58515852# Display a list of remote names with the respective fetch and push URLs5853sub git_remotes_list {5854my($remotedata,$limit) =@_;5855print"<table class=\"heads\">\n";5856my$alternate=1;5857my@remotes=sort keys%$remotedata;58585859my$limited=$limit&&$limit<@remotes;58605861$#remotes=$limit-1if$limited;58625863while(my$remote=shift@remotes) {5864my$rdata=$remotedata->{$remote};5865my$fetch=$rdata->{'fetch'};5866my$push=$rdata->{'push'};5867if($alternate) {5868print"<tr class=\"dark\">\n";5869}else{5870print"<tr class=\"light\">\n";5871}5872$alternate^=1;5873print"<td>".5874$cgi->a({-href=> href(action=>'remotes', hash=>$remote),5875-class=>"list name"},esc_html($remote)) .5876"</td>";5877print"<td class=\"link\">".5878(defined$fetch?$cgi->a({-href=>$fetch},"fetch") :"fetch") .5879" | ".5880(defined$push?$cgi->a({-href=>$push},"push") :"push") .5881"</td>";58825883print"</tr>\n";5884}58855886if($limited) {5887print"<tr>\n".5888"<td colspan=\"3\">".5889$cgi->a({-href => href(action=>"remotes")},"...") .5890"</td>\n"."</tr>\n";5891}58925893print"</table>";5894}58955896# Display remote heads grouped by remote, unless there are too many5897# remotes, in which case we only display the remote names5898sub git_remotes_body {5899my($remotedata,$limit,$head) =@_;5900if($limitand$limit<keys%$remotedata) {5901 git_remotes_list($remotedata,$limit);5902}else{5903 fill_remote_heads($remotedata);5904while(my($remote,$rdata) =each%$remotedata) {5905 git_print_section({-class=>"remote", -id=>$remote},5906["remotes",$remote,$remote],sub{5907 git_remote_block($remote,$rdata,$limit,$head);5908});5909}5910}5911}59125913sub git_search_message {5914my%co=@_;59155916my$greptype;5917if($searchtypeeq'commit') {5918$greptype="--grep=";5919}elsif($searchtypeeq'author') {5920$greptype="--author=";5921}elsif($searchtypeeq'committer') {5922$greptype="--committer=";5923}5924$greptype.=$searchtext;5925my@commitlist= parse_commits($hash,101, (100*$page),undef,5926$greptype,'--regexp-ignore-case',5927$search_use_regexp?'--extended-regexp':'--fixed-strings');59285929my$paging_nav='';5930if($page>0) {5931$paging_nav.=5932$cgi->a({-href => href(-replay=>1, page=>undef)},5933"first") .5934" ⋅ ".5935$cgi->a({-href => href(-replay=>1, page=>$page-1),5936-accesskey =>"p", -title =>"Alt-p"},"prev");5937}else{5938$paging_nav.="first ⋅ prev";5939}5940my$next_link='';5941if($#commitlist>=100) {5942$next_link=5943$cgi->a({-href => href(-replay=>1, page=>$page+1),5944-accesskey =>"n", -title =>"Alt-n"},"next");5945$paging_nav.=" ⋅$next_link";5946}else{5947$paging_nav.=" ⋅ next";5948}59495950 git_header_html();59515952 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);5953 git_print_header_div('commit', esc_html($co{'title'}),$hash);5954if($page==0&& !@commitlist) {5955print"<p>No match.</p>\n";5956}else{5957 git_search_grep_body(\@commitlist,0,99,$next_link);5958}59595960 git_footer_html();5961}59625963sub git_search_changes {5964my%co=@_;59655966local$/="\n";5967open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,5968'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",5969($search_use_regexp?'--pickaxe-regex': ())5970or die_error(500,"Open git-log failed");59715972 git_header_html();59735974 git_print_page_nav('','',$hash,$co{'tree'},$hash);5975 git_print_header_div('commit', esc_html($co{'title'}),$hash);59765977print"<table class=\"pickaxe search\">\n";5978my$alternate=1;5979undef%co;5980my@files;5981while(my$line= <$fd>) {5982chomp$line;5983next unless$line;59845985my%set= parse_difftree_raw_line($line);5986if(defined$set{'commit'}) {5987# finish previous commit5988if(%co) {5989print"</td>\n".5990"<td class=\"link\">".5991$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},5992"commit") .5993" | ".5994$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'},5995 hash_base=>$co{'id'})},5996"tree") .5997"</td>\n".5998"</tr>\n";5999}60006001if($alternate) {6002print"<tr class=\"dark\">\n";6003}else{6004print"<tr class=\"light\">\n";6005}6006$alternate^=1;6007%co= parse_commit($set{'commit'});6008my$author= chop_and_escape_str($co{'author_name'},15,5);6009print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6010"<td><i>$author</i></td>\n".6011"<td>".6012$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6013-class=>"list subject"},6014 chop_and_escape_str($co{'title'},50) ."<br/>");6015}elsif(defined$set{'to_id'}) {6016next if($set{'to_id'} =~m/^0{40}$/);60176018print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6019 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6020-class=>"list"},6021"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6022"<br/>\n";6023}6024}6025close$fd;60266027# finish last commit (warning: repetition!)6028if(%co) {6029print"</td>\n".6030"<td class=\"link\">".6031$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},6032"commit") .6033" | ".6034$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'},6035 hash_base=>$co{'id'})},6036"tree") .6037"</td>\n".6038"</tr>\n";6039}60406041print"</table>\n";60426043 git_footer_html();6044}60456046sub git_search_files {6047my%co=@_;60486049local$/="\n";6050open my$fd,"-|", git_cmd(),'grep','-n','-z',6051$search_use_regexp? ('-E','-i') :'-F',6052$searchtext,$co{'tree'}6053or die_error(500,"Open git-grep failed");60546055 git_header_html();60566057 git_print_page_nav('','',$hash,$co{'tree'},$hash);6058 git_print_header_div('commit', esc_html($co{'title'}),$hash);60596060print"<table class=\"grep_search\">\n";6061my$alternate=1;6062my$matches=0;6063my$lastfile='';6064my$file_href;6065while(my$line= <$fd>) {6066chomp$line;6067my($file,$lno,$ltext,$binary);6068last if($matches++>1000);6069if($line=~/^Binary file (.+) matches$/) {6070$file=$1;6071$binary=1;6072}else{6073($file,$lno,$ltext) =split(/\0/,$line,3);6074$file=~s/^$co{'tree'}://;6075}6076if($filene$lastfile) {6077$lastfileand print"</td></tr>\n";6078if($alternate++) {6079print"<tr class=\"dark\">\n";6080}else{6081print"<tr class=\"light\">\n";6082}6083$file_href= href(action=>"blob", hash_base=>$co{'id'},6084 file_name=>$file);6085print"<td class=\"list\">".6086$cgi->a({-href =>$file_href, -class=>"list"}, esc_path($file));6087print"</td><td>\n";6088$lastfile=$file;6089}6090if($binary) {6091print"<div class=\"binary\">Binary file</div>\n";6092}else{6093$ltext= untabify($ltext);6094if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6095$ltext= esc_html($1, -nbsp=>1);6096$ltext.='<span class="match">';6097$ltext.= esc_html($2, -nbsp=>1);6098$ltext.='</span>';6099$ltext.= esc_html($3, -nbsp=>1);6100}else{6101$ltext= esc_html($ltext, -nbsp=>1);6102}6103print"<div class=\"pre\">".6104$cgi->a({-href =>$file_href.'#l'.$lno,6105-class=>"linenr"},sprintf('%4i',$lno)) .6106' '.$ltext."</div>\n";6107}6108}6109if($lastfile) {6110print"</td></tr>\n";6111if($matches>1000) {6112print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6113}6114}else{6115print"<div class=\"diff nodifferences\">No matches found</div>\n";6116}6117close$fd;61186119print"</table>\n";61206121 git_footer_html();6122}61236124sub git_search_grep_body {6125my($commitlist,$from,$to,$extra) =@_;6126$from=0unlessdefined$from;6127$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);61286129print"<table class=\"commit_search\">\n";6130my$alternate=1;6131for(my$i=$from;$i<=$to;$i++) {6132my%co= %{$commitlist->[$i]};6133if(!%co) {6134next;6135}6136my$commit=$co{'id'};6137if($alternate) {6138print"<tr class=\"dark\">\n";6139}else{6140print"<tr class=\"light\">\n";6141}6142$alternate^=1;6143print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6144 format_author_html('td', \%co,15,5) .6145"<td>".6146$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6147-class=>"list subject"},6148 chop_and_escape_str($co{'title'},50) ."<br/>");6149my$comment=$co{'comment'};6150foreachmy$line(@$comment) {6151if($line=~m/^(.*?)($search_regexp)(.*)$/i) {6152my($lead,$match,$trail) = ($1,$2,$3);6153$match= chop_str($match,70,5,'center');6154my$contextlen=int((80-length($match))/2);6155$contextlen=30if($contextlen>30);6156$lead= chop_str($lead,$contextlen,10,'left');6157$trail= chop_str($trail,$contextlen,10,'right');61586159$lead= esc_html($lead);6160$match= esc_html($match);6161$trail= esc_html($trail);61626163print"$lead<span class=\"match\">$match</span>$trail<br />";6164}6165}6166print"</td>\n".6167"<td class=\"link\">".6168$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6169" | ".6170$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .6171" | ".6172$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6173print"</td>\n".6174"</tr>\n";6175}6176if(defined$extra) {6177print"<tr>\n".6178"<td colspan=\"3\">$extra</td>\n".6179"</tr>\n";6180}6181print"</table>\n";6182}61836184## ======================================================================6185## ======================================================================6186## actions61876188sub git_project_list {6189my$order=$input_params{'order'};6190if(defined$order&&$order!~m/none|project|descr|owner|age/) {6191 die_error(400,"Unknown order parameter");6192}61936194my@list= git_get_projects_list($project_filter,$strict_export);6195if(!@list) {6196 die_error(404,"No projects found");6197}61986199 git_header_html();6200if(defined$home_text&& -f $home_text) {6201print"<div class=\"index_include\">\n";6202 insert_file($home_text);6203print"</div>\n";6204}62056206 git_project_search_form($searchtext,$search_use_regexp);6207 git_project_list_body(\@list,$order);6208 git_footer_html();6209}62106211sub git_forks {6212my$order=$input_params{'order'};6213if(defined$order&&$order!~m/none|project|descr|owner|age/) {6214 die_error(400,"Unknown order parameter");6215}62166217my$filter=$project;6218$filter=~s/\.git$//;6219my@list= git_get_projects_list($filter);6220if(!@list) {6221 die_error(404,"No forks found");6222}62236224 git_header_html();6225 git_print_page_nav('','');6226 git_print_header_div('summary',"$projectforks");6227 git_project_list_body(\@list,$order);6228 git_footer_html();6229}62306231sub git_project_index {6232my@projects= git_get_projects_list($project_filter,$strict_export);6233if(!@projects) {6234 die_error(404,"No projects found");6235}62366237print$cgi->header(6238-type =>'text/plain',6239-charset =>'utf-8',6240-content_disposition =>'inline; filename="index.aux"');62416242foreachmy$pr(@projects) {6243if(!exists$pr->{'owner'}) {6244$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");6245}62466247my($path,$owner) = ($pr->{'path'},$pr->{'owner'});6248# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '6249$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;6250$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;6251$path=~s/ /\+/g;6252$owner=~s/ /\+/g;62536254print"$path$owner\n";6255}6256}62576258sub git_summary {6259my$descr= git_get_project_description($project) ||"none";6260my%co= parse_commit("HEAD");6261my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();6262my$head=$co{'id'};6263my$remote_heads= gitweb_check_feature('remote_heads');62646265my$owner= git_get_project_owner($project);62666267my$refs= git_get_references();6268# These get_*_list functions return one more to allow us to see if6269# there are more ...6270my@taglist= git_get_tags_list(16);6271my@headlist= git_get_heads_list(16);6272my%remotedata=$remote_heads? git_get_remotes_list() : ();6273my@forklist;6274my$check_forks= gitweb_check_feature('forks');62756276if($check_forks) {6277# find forks of a project6278my$filter=$project;6279$filter=~s/\.git$//;6280@forklist= git_get_projects_list($filter);6281# filter out forks of forks6282@forklist= filter_forks_from_projects_list(\@forklist)6283if(@forklist);6284}62856286 git_header_html();6287 git_print_page_nav('summary','',$head);62886289print"<div class=\"title\"> </div>\n";6290print"<table class=\"projects_list\">\n".6291"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".6292"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";6293if(defined$cd{'rfc2822'}) {6294print"<tr id=\"metadata_lchange\"><td>last change</td>".6295"<td>".format_timestamp_html(\%cd)."</td></tr>\n";6296}62976298# use per project git URL list in $projectroot/$project/cloneurl6299# or make project git URL from git base URL and project name6300my$url_tag="URL";6301my@url_list= git_get_project_url_list($project);6302@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;6303foreachmy$git_url(@url_list) {6304next unless$git_url;6305print format_repo_url($url_tag,$git_url);6306$url_tag="";6307}63086309# Tag cloud6310my$show_ctags= gitweb_check_feature('ctags');6311if($show_ctags) {6312my$ctags= git_get_project_ctags($project);6313if(%$ctags) {6314# without ability to add tags, don't show if there are none6315my$cloud= git_populate_project_tagcloud($ctags);6316print"<tr id=\"metadata_ctags\">".6317"<td>content tags</td>".6318"<td>".git_show_project_tagcloud($cloud,48)."</td>".6319"</tr>\n";6320}6321}63226323print"</table>\n";63246325# If XSS prevention is on, we don't include README.html.6326# TODO: Allow a readme in some safe format.6327if(!$prevent_xss&& -s "$projectroot/$project/README.html") {6328print"<div class=\"title\">readme</div>\n".6329"<div class=\"readme\">\n";6330 insert_file("$projectroot/$project/README.html");6331print"\n</div>\n";# class="readme"6332}63336334# we need to request one more than 16 (0..15) to check if6335# those 16 are all6336my@commitlist=$head? parse_commits($head,17) : ();6337if(@commitlist) {6338 git_print_header_div('shortlog');6339 git_shortlog_body(\@commitlist,0,15,$refs,6340$#commitlist<=15?undef:6341$cgi->a({-href => href(action=>"shortlog")},"..."));6342}63436344if(@taglist) {6345 git_print_header_div('tags');6346 git_tags_body(\@taglist,0,15,6347$#taglist<=15?undef:6348$cgi->a({-href => href(action=>"tags")},"..."));6349}63506351if(@headlist) {6352 git_print_header_div('heads');6353 git_heads_body(\@headlist,$head,0,15,6354$#headlist<=15?undef:6355$cgi->a({-href => href(action=>"heads")},"..."));6356}63576358if(%remotedata) {6359 git_print_header_div('remotes');6360 git_remotes_body(\%remotedata,15,$head);6361}63626363if(@forklist) {6364 git_print_header_div('forks');6365 git_project_list_body(\@forklist,'age',0,15,6366$#forklist<=15?undef:6367$cgi->a({-href => href(action=>"forks")},"..."),6368'no_header');6369}63706371 git_footer_html();6372}63736374sub git_tag {6375my%tag= parse_tag($hash);63766377if(!%tag) {6378 die_error(404,"Unknown tag object");6379}63806381my$head= git_get_head_hash($project);6382 git_header_html();6383 git_print_page_nav('','',$head,undef,$head);6384 git_print_header_div('commit', esc_html($tag{'name'}),$hash);6385print"<div class=\"title_text\">\n".6386"<table class=\"object_header\">\n".6387"<tr>\n".6388"<td>object</td>\n".6389"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},6390$tag{'object'}) ."</td>\n".6391"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},6392$tag{'type'}) ."</td>\n".6393"</tr>\n";6394if(defined($tag{'author'})) {6395 git_print_authorship_rows(\%tag,'author');6396}6397print"</table>\n\n".6398"</div>\n";6399print"<div class=\"page_body\">";6400my$comment=$tag{'comment'};6401foreachmy$line(@$comment) {6402chomp$line;6403print esc_html($line, -nbsp=>1) ."<br/>\n";6404}6405print"</div>\n";6406 git_footer_html();6407}64086409sub git_blame_common {6410my$format=shift||'porcelain';6411if($formateq'porcelain'&&$input_params{'javascript'}) {6412$format='incremental';6413$action='blame_incremental';# for page title etc6414}64156416# permissions6417 gitweb_check_feature('blame')6418or die_error(403,"Blame view not allowed");64196420# error checking6421 die_error(400,"No file name given")unless$file_name;6422$hash_base||= git_get_head_hash($project);6423 die_error(404,"Couldn't find base commit")unless$hash_base;6424my%co= parse_commit($hash_base)6425or die_error(404,"Commit not found");6426my$ftype="blob";6427if(!defined$hash) {6428$hash= git_get_hash_by_path($hash_base,$file_name,"blob")6429or die_error(404,"Error looking up file");6430}else{6431$ftype= git_get_type($hash);6432if($ftype!~"blob") {6433 die_error(400,"Object is not a blob");6434}6435}64366437my$fd;6438if($formateq'incremental') {6439# get file contents (as base)6440open$fd,"-|", git_cmd(),'cat-file','blob',$hash6441or die_error(500,"Open git-cat-file failed");6442}elsif($formateq'data') {6443# run git-blame --incremental6444open$fd,"-|", git_cmd(),"blame","--incremental",6445$hash_base,"--",$file_name6446or die_error(500,"Open git-blame --incremental failed");6447}else{6448# run git-blame --porcelain6449open$fd,"-|", git_cmd(),"blame",'-p',6450$hash_base,'--',$file_name6451or die_error(500,"Open git-blame --porcelain failed");6452}64536454# incremental blame data returns early6455if($formateq'data') {6456print$cgi->header(6457-type=>"text/plain", -charset =>"utf-8",6458-status=>"200 OK");6459local$| =1;# output autoflush6460while(my$line= <$fd>) {6461print to_utf8($line);6462}6463close$fd6464or print"ERROR$!\n";64656466print'END';6467if(defined$t0&& gitweb_check_feature('timed')) {6468print' '.6469 tv_interval($t0, [ gettimeofday() ]).6470' '.$number_of_git_cmds;6471}6472print"\n";64736474return;6475}64766477# page header6478 git_header_html();6479my$formats_nav=6480$cgi->a({-href => href(action=>"blob", -replay=>1)},6481"blob") .6482" | ";6483if($formateq'incremental') {6484$formats_nav.=6485$cgi->a({-href => href(action=>"blame", javascript=>0, -replay=>1)},6486"blame") ." (non-incremental)";6487}else{6488$formats_nav.=6489$cgi->a({-href => href(action=>"blame_incremental", -replay=>1)},6490"blame") ." (incremental)";6491}6492$formats_nav.=6493" | ".6494$cgi->a({-href => href(action=>"history", -replay=>1)},6495"history") .6496" | ".6497$cgi->a({-href => href(action=>$action, file_name=>$file_name)},6498"HEAD");6499 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);6500 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);6501 git_print_page_path($file_name,$ftype,$hash_base);65026503# page body6504if($formateq'incremental') {6505print"<noscript>\n<div class=\"error\"><center><b>\n".6506"This page requires JavaScript to run.\nUse ".6507$cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},6508'this page').6509" instead.\n".6510"</b></center></div>\n</noscript>\n";65116512print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!;6513}65146515print qq!<div class="page_body">\n!;6516print qq!<div id="progress_info">.../ ...</div>\n!6517if($formateq'incremental');6518print qq!<table id="blame_table"class="blame" width="100%">\n!.6519#qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.6520 qq!<thead>\n!.6521 qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!.6522 qq!</thead>\n!.6523 qq!<tbody>\n!;65246525my@rev_color=qw(light dark);6526my$num_colors=scalar(@rev_color);6527my$current_color=0;65286529if($formateq'incremental') {6530my$color_class=$rev_color[$current_color];65316532#contents of a file6533my$linenr=0;6534 LINE:6535while(my$line= <$fd>) {6536chomp$line;6537$linenr++;65386539print qq!<tr id="l$linenr"class="$color_class">!.6540 qq!<td class="sha1"><a href=""> </a></td>!.6541 qq!<td class="linenr">!.6542 qq!<a class="linenr" href="">$linenr</a></td>!;6543print qq!<td class="pre">! . esc_html($line) ."</td>\n";6544print qq!</tr>\n!;6545}65466547}else{# porcelain, i.e. ordinary blame6548my%metainfo= ();# saves information about commits65496550# blame data6551 LINE:6552while(my$line= <$fd>) {6553chomp$line;6554# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]6555# no <lines in group> for subsequent lines in group of lines6556my($full_rev,$orig_lineno,$lineno,$group_size) =6557($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);6558if(!exists$metainfo{$full_rev}) {6559$metainfo{$full_rev} = {'nprevious'=>0};6560}6561my$meta=$metainfo{$full_rev};6562my$data;6563while($data= <$fd>) {6564chomp$data;6565last if($data=~s/^\t//);# contents of line6566if($data=~/^(\S+)(?: (.*))?$/) {6567$meta->{$1} =$2unlessexists$meta->{$1};6568}6569if($data=~/^previous /) {6570$meta->{'nprevious'}++;6571}6572}6573my$short_rev=substr($full_rev,0,8);6574my$author=$meta->{'author'};6575my%date=6576 parse_date($meta->{'author-time'},$meta->{'author-tz'});6577my$date=$date{'iso-tz'};6578if($group_size) {6579$current_color= ($current_color+1) %$num_colors;6580}6581my$tr_class=$rev_color[$current_color];6582$tr_class.=' boundary'if(exists$meta->{'boundary'});6583$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);6584$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);6585print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";6586if($group_size) {6587print"<td class=\"sha1\"";6588print" title=\"". esc_html($author) .",$date\"";6589print" rowspan=\"$group_size\""if($group_size>1);6590print">";6591print$cgi->a({-href => href(action=>"commit",6592 hash=>$full_rev,6593 file_name=>$file_name)},6594 esc_html($short_rev));6595if($group_size>=2) {6596my@author_initials= ($author=~/\b([[:upper:]])\B/g);6597if(@author_initials) {6598print"<br />".6599 esc_html(join('',@author_initials));6600# or join('.', ...)6601}6602}6603print"</td>\n";6604}6605# 'previous' <sha1 of parent commit> <filename at commit>6606if(exists$meta->{'previous'} &&6607$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {6608$meta->{'parent'} =$1;6609$meta->{'file_parent'} = unquote($2);6610}6611my$linenr_commit=6612exists($meta->{'parent'}) ?6613$meta->{'parent'} :$full_rev;6614my$linenr_filename=6615exists($meta->{'file_parent'}) ?6616$meta->{'file_parent'} : unquote($meta->{'filename'});6617my$blamed= href(action =>'blame',6618 file_name =>$linenr_filename,6619 hash_base =>$linenr_commit);6620print"<td class=\"linenr\">";6621print$cgi->a({ -href =>"$blamed#l$orig_lineno",6622-class=>"linenr"},6623 esc_html($lineno));6624print"</td>";6625print"<td class=\"pre\">". esc_html($data) ."</td>\n";6626print"</tr>\n";6627}# end while66286629}66306631# footer6632print"</tbody>\n".6633"</table>\n";# class="blame"6634print"</div>\n";# class="blame_body"6635close$fd6636or print"Reading blob failed\n";66376638 git_footer_html();6639}66406641sub git_blame {6642 git_blame_common();6643}66446645sub git_blame_incremental {6646 git_blame_common('incremental');6647}66486649sub git_blame_data {6650 git_blame_common('data');6651}66526653sub git_tags {6654my$head= git_get_head_hash($project);6655 git_header_html();6656 git_print_page_nav('','',$head,undef,$head,format_ref_views('tags'));6657 git_print_header_div('summary',$project);66586659my@tagslist= git_get_tags_list();6660if(@tagslist) {6661 git_tags_body(\@tagslist);6662}6663 git_footer_html();6664}66656666sub git_heads {6667my$head= git_get_head_hash($project);6668 git_header_html();6669 git_print_page_nav('','',$head,undef,$head,format_ref_views('heads'));6670 git_print_header_div('summary',$project);66716672my@headslist= git_get_heads_list();6673if(@headslist) {6674 git_heads_body(\@headslist,$head);6675}6676 git_footer_html();6677}66786679# used both for single remote view and for list of all the remotes6680sub git_remotes {6681 gitweb_check_feature('remote_heads')6682or die_error(403,"Remote heads view is disabled");66836684my$head= git_get_head_hash($project);6685my$remote=$input_params{'hash'};66866687my$remotedata= git_get_remotes_list($remote);6688 die_error(500,"Unable to get remote information")unlessdefined$remotedata;66896690unless(%$remotedata) {6691 die_error(404,defined$remote?6692"Remote$remotenot found":6693"No remotes found");6694}66956696 git_header_html(undef,undef, -action_extra =>$remote);6697 git_print_page_nav('','',$head,undef,$head,6698 format_ref_views($remote?'':'remotes'));66996700 fill_remote_heads($remotedata);6701if(defined$remote) {6702 git_print_header_div('remotes',"$remoteremote for$project");6703 git_remote_block($remote,$remotedata->{$remote},undef,$head);6704}else{6705 git_print_header_div('summary',"$projectremotes");6706 git_remotes_body($remotedata,undef,$head);6707}67086709 git_footer_html();6710}67116712sub git_blob_plain {6713my$type=shift;6714my$expires;67156716if(!defined$hash) {6717if(defined$file_name) {6718my$base=$hash_base|| git_get_head_hash($project);6719$hash= git_get_hash_by_path($base,$file_name,"blob")6720or die_error(404,"Cannot find file");6721}else{6722 die_error(400,"No file name defined");6723}6724}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {6725# blobs defined by non-textual hash id's can be cached6726$expires="+1d";6727}67286729open my$fd,"-|", git_cmd(),"cat-file","blob",$hash6730or die_error(500,"Open git-cat-file blob '$hash' failed");67316732# content-type (can include charset)6733$type= blob_contenttype($fd,$file_name,$type);67346735# "save as" filename, even when no $file_name is given6736my$save_as="$hash";6737if(defined$file_name) {6738$save_as=$file_name;6739}elsif($type=~m/^text\//) {6740$save_as.='.txt';6741}67426743# With XSS prevention on, blobs of all types except a few known safe6744# ones are served with "Content-Disposition: attachment" to make sure6745# they don't run in our security domain. For certain image types,6746# blob view writes an <img> tag referring to blob_plain view, and we6747# want to be sure not to break that by serving the image as an6748# attachment (though Firefox 3 doesn't seem to care).6749my$sandbox=$prevent_xss&&6750$type!~m!^(?:text/[a-z]+|image/(?:gif|png|jpeg))(?:[ ;]|$)!;67516752# serve text/* as text/plain6753if($prevent_xss&&6754($type=~m!^text/[a-z]+\b(.*)$!||6755($type=~m!^[a-z]+/[a-z]\+xml\b(.*)$!&& -T $fd))) {6756my$rest=$1;6757$rest=defined$rest?$rest:'';6758$type="text/plain$rest";6759}67606761print$cgi->header(6762-type =>$type,6763-expires =>$expires,6764-content_disposition =>6765($sandbox?'attachment':'inline')6766.'; filename="'.$save_as.'"');6767local$/=undef;6768binmode STDOUT,':raw';6769print<$fd>;6770binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi6771close$fd;6772}67736774sub git_blob {6775my$expires;67766777if(!defined$hash) {6778if(defined$file_name) {6779my$base=$hash_base|| git_get_head_hash($project);6780$hash= git_get_hash_by_path($base,$file_name,"blob")6781or die_error(404,"Cannot find file");6782}else{6783 die_error(400,"No file name defined");6784}6785}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {6786# blobs defined by non-textual hash id's can be cached6787$expires="+1d";6788}67896790my$have_blame= gitweb_check_feature('blame');6791open my$fd,"-|", git_cmd(),"cat-file","blob",$hash6792or die_error(500,"Couldn't cat$file_name,$hash");6793my$mimetype= blob_mimetype($fd,$file_name);6794# use 'blob_plain' (aka 'raw') view for files that cannot be displayed6795if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {6796close$fd;6797return git_blob_plain($mimetype);6798}6799# we can have blame only for text/* mimetype6800$have_blame&&= ($mimetype=~m!^text/!);68016802my$highlight= gitweb_check_feature('highlight');6803my$syntax= guess_file_syntax($highlight,$mimetype,$file_name);6804$fd= run_highlighter($fd,$highlight,$syntax)6805if$syntax;68066807 git_header_html(undef,$expires);6808my$formats_nav='';6809if(defined$hash_base&& (my%co= parse_commit($hash_base))) {6810if(defined$file_name) {6811if($have_blame) {6812$formats_nav.=6813$cgi->a({-href => href(action=>"blame", -replay=>1)},6814"blame") .6815" | ";6816}6817$formats_nav.=6818$cgi->a({-href => href(action=>"history", -replay=>1)},6819"history") .6820" | ".6821$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},6822"raw") .6823" | ".6824$cgi->a({-href => href(action=>"blob",6825 hash_base=>"HEAD", file_name=>$file_name)},6826"HEAD");6827}else{6828$formats_nav.=6829$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},6830"raw");6831}6832 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);6833 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);6834}else{6835print"<div class=\"page_nav\">\n".6836"<br/><br/></div>\n".6837"<div class=\"title\">".esc_html($hash)."</div>\n";6838}6839 git_print_page_path($file_name,"blob",$hash_base);6840print"<div class=\"page_body\">\n";6841if($mimetype=~m!^image/!) {6842print qq!<img type="!.esc_attr($mimetype).qq!"!;6843if($file_name) {6844print qq! alt="!.esc_attr($file_name).qq!" title="!.esc_attr($file_name).qq!"!;6845}6846print qq! src="! .6847 href(action=>"blob_plain", hash=>$hash,6848 hash_base=>$hash_base, file_name=>$file_name) .6849 qq!"/>\n!;6850}else{6851my$nr;6852while(my$line= <$fd>) {6853chomp$line;6854$nr++;6855$line= untabify($line);6856printf qq!<div class="pre"><a id="l%i" href="%s#l%i"class="linenr">%4i</a> %s</div>\n!,6857$nr, esc_attr(href(-replay =>1)),$nr,$nr,6858$syntax? sanitize($line) : esc_html($line, -nbsp=>1);6859}6860}6861close$fd6862or print"Reading blob failed.\n";6863print"</div>";6864 git_footer_html();6865}68666867sub git_tree {6868if(!defined$hash_base) {6869$hash_base="HEAD";6870}6871if(!defined$hash) {6872if(defined$file_name) {6873$hash= git_get_hash_by_path($hash_base,$file_name,"tree");6874}else{6875$hash=$hash_base;6876}6877}6878 die_error(404,"No such tree")unlessdefined($hash);68796880my$show_sizes= gitweb_check_feature('show-sizes');6881my$have_blame= gitweb_check_feature('blame');68826883my@entries= ();6884{6885local$/="\0";6886open my$fd,"-|", git_cmd(),"ls-tree",'-z',6887($show_sizes?'-l': ()),@extra_options,$hash6888or die_error(500,"Open git-ls-tree failed");6889@entries=map{chomp;$_} <$fd>;6890close$fd6891or die_error(404,"Reading tree failed");6892}68936894my$refs= git_get_references();6895my$ref= format_ref_marker($refs,$hash_base);6896 git_header_html();6897my$basedir='';6898if(defined$hash_base&& (my%co= parse_commit($hash_base))) {6899my@views_nav= ();6900if(defined$file_name) {6901push@views_nav,6902$cgi->a({-href => href(action=>"history", -replay=>1)},6903"history"),6904$cgi->a({-href => href(action=>"tree",6905 hash_base=>"HEAD", file_name=>$file_name)},6906"HEAD"),6907}6908my$snapshot_links= format_snapshot_links($hash);6909if(defined$snapshot_links) {6910# FIXME: Should be available when we have no hash base as well.6911push@views_nav,$snapshot_links;6912}6913 git_print_page_nav('tree','',$hash_base,undef,undef,6914join(' | ',@views_nav));6915 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);6916}else{6917undef$hash_base;6918print"<div class=\"page_nav\">\n";6919print"<br/><br/></div>\n";6920print"<div class=\"title\">".esc_html($hash)."</div>\n";6921}6922if(defined$file_name) {6923$basedir=$file_name;6924if($basedirne''&&substr($basedir, -1)ne'/') {6925$basedir.='/';6926}6927 git_print_page_path($file_name,'tree',$hash_base);6928}6929print"<div class=\"page_body\">\n";6930print"<table class=\"tree\">\n";6931my$alternate=1;6932# '..' (top directory) link if possible6933if(defined$hash_base&&6934defined$file_name&&$file_name=~m![^/]+$!) {6935if($alternate) {6936print"<tr class=\"dark\">\n";6937}else{6938print"<tr class=\"light\">\n";6939}6940$alternate^=1;69416942my$up=$file_name;6943$up=~s!/?[^/]+$!!;6944undef$upunless$up;6945# based on git_print_tree_entry6946print'<td class="mode">'. mode_str('040000') ."</td>\n";6947print'<td class="size"> </td>'."\n"if$show_sizes;6948print'<td class="list">';6949print$cgi->a({-href => href(action=>"tree",6950 hash_base=>$hash_base,6951 file_name=>$up)},6952"..");6953print"</td>\n";6954print"<td class=\"link\"></td>\n";69556956print"</tr>\n";6957}6958foreachmy$line(@entries) {6959my%t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);69606961if($alternate) {6962print"<tr class=\"dark\">\n";6963}else{6964print"<tr class=\"light\">\n";6965}6966$alternate^=1;69676968 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);69696970print"</tr>\n";6971}6972print"</table>\n".6973"</div>";6974 git_footer_html();6975}69766977sub snapshot_name {6978my($project,$hash) =@_;69796980# path/to/project.git -> project6981# path/to/project/.git -> project6982my$name= to_utf8($project);6983$name=~ s,([^/])/*\.git$,$1,;6984$name= basename($name);6985# sanitize name6986$name=~s/[[:cntrl:]]/?/g;69876988my$ver=$hash;6989if($hash=~/^[0-9a-fA-F]+$/) {6990# shorten SHA-1 hash6991my$full_hash= git_get_full_hash($project,$hash);6992if($full_hash=~/^$hash/&&length($hash) >7) {6993$ver= git_get_short_hash($project,$hash);6994}6995}elsif($hash=~m!^refs/tags/(.*)$!) {6996# tags don't need shortened SHA-1 hash6997$ver=$1;6998}else{6999# branches and other need shortened SHA-1 hash7000if($hash=~m!^refs/(?:heads|remotes)/(.*)$!) {7001$ver=$1;7002}7003$ver.='-'. git_get_short_hash($project,$hash);7004}7005# in case of hierarchical branch names7006$ver=~s!/!.!g;70077008# name = project-version_string7009$name="$name-$ver";70107011returnwantarray? ($name,$name) :$name;7012}70137014sub git_snapshot {7015my$format=$input_params{'snapshot_format'};7016if(!@snapshot_fmts) {7017 die_error(403,"Snapshots not allowed");7018}7019# default to first supported snapshot format7020$format||=$snapshot_fmts[0];7021if($format!~m/^[a-z0-9]+$/) {7022 die_error(400,"Invalid snapshot format parameter");7023}elsif(!exists($known_snapshot_formats{$format})) {7024 die_error(400,"Unknown snapshot format");7025}elsif($known_snapshot_formats{$format}{'disabled'}) {7026 die_error(403,"Snapshot format not allowed");7027}elsif(!grep($_eq$format,@snapshot_fmts)) {7028 die_error(403,"Unsupported snapshot format");7029}70307031my$type= git_get_type("$hash^{}");7032if(!$type) {7033 die_error(404,'Object does not exist');7034}elsif($typeeq'blob') {7035 die_error(400,'Object is not a tree-ish');7036}70377038my($name,$prefix) = snapshot_name($project,$hash);7039my$filename="$name$known_snapshot_formats{$format}{'suffix'}";7040my$cmd= quote_command(7041 git_cmd(),'archive',7042"--format=$known_snapshot_formats{$format}{'format'}",7043"--prefix=$prefix/",$hash);7044if(exists$known_snapshot_formats{$format}{'compressor'}) {7045$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});7046}70477048$filename=~s/(["\\])/\\$1/g;7049print$cgi->header(7050-type =>$known_snapshot_formats{$format}{'type'},7051-content_disposition =>'inline; filename="'.$filename.'"',7052-status =>'200 OK');70537054open my$fd,"-|",$cmd7055or die_error(500,"Execute git-archive failed");7056binmode STDOUT,':raw';7057print<$fd>;7058binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi7059close$fd;7060}70617062sub git_log_generic {7063my($fmt_name,$body_subr,$base,$parent,$file_name,$file_hash) =@_;70647065my$head= git_get_head_hash($project);7066if(!defined$base) {7067$base=$head;7068}7069if(!defined$page) {7070$page=0;7071}7072my$refs= git_get_references();70737074my$commit_hash=$base;7075if(defined$parent) {7076$commit_hash="$parent..$base";7077}7078my@commitlist=7079 parse_commits($commit_hash,101, (100*$page),7080defined$file_name? ($file_name,"--full-history") : ());70817082my$ftype;7083if(!defined$file_hash&&defined$file_name) {7084# some commits could have deleted file in question,7085# and not have it in tree, but one of them has to have it7086for(my$i=0;$i<@commitlist;$i++) {7087$file_hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);7088last ifdefined$file_hash;7089}7090}7091if(defined$file_hash) {7092$ftype= git_get_type($file_hash);7093}7094if(defined$file_name&& !defined$ftype) {7095 die_error(500,"Unknown type of object");7096}7097my%co;7098if(defined$file_name) {7099%co= parse_commit($base)7100or die_error(404,"Unknown commit object");7101}710271037104my$paging_nav= format_paging_nav($fmt_name,$page,$#commitlist>=100);7105my$next_link='';7106if($#commitlist>=100) {7107$next_link=7108$cgi->a({-href => href(-replay=>1, page=>$page+1),7109-accesskey =>"n", -title =>"Alt-n"},"next");7110}7111my$patch_max= gitweb_get_feature('patches');7112if($patch_max&& !defined$file_name) {7113if($patch_max<0||@commitlist<=$patch_max) {7114$paging_nav.=" ⋅ ".7115$cgi->a({-href => href(action=>"patches", -replay=>1)},7116"patches");7117}7118}71197120 git_header_html();7121 git_print_page_nav($fmt_name,'',$hash,$hash,$hash,$paging_nav);7122if(defined$file_name) {7123 git_print_header_div('commit', esc_html($co{'title'}),$base);7124}else{7125 git_print_header_div('summary',$project)7126}7127 git_print_page_path($file_name,$ftype,$hash_base)7128if(defined$file_name);71297130$body_subr->(\@commitlist,0,99,$refs,$next_link,7131$file_name,$file_hash,$ftype);71327133 git_footer_html();7134}71357136sub git_log {7137 git_log_generic('log', \&git_log_body,7138$hash,$hash_parent);7139}71407141sub git_commit {7142$hash||=$hash_base||"HEAD";7143my%co= parse_commit($hash)7144or die_error(404,"Unknown commit object");71457146my$parent=$co{'parent'};7147my$parents=$co{'parents'};# listref71487149# we need to prepare $formats_nav before any parameter munging7150my$formats_nav;7151if(!defined$parent) {7152# --root commitdiff7153$formats_nav.='(initial)';7154}elsif(@$parents==1) {7155# single parent commit7156$formats_nav.=7157'(parent: '.7158$cgi->a({-href => href(action=>"commit",7159 hash=>$parent)},7160 esc_html(substr($parent,0,7))) .7161')';7162}else{7163# merge commit7164$formats_nav.=7165'(merge: '.7166join(' ',map{7167$cgi->a({-href => href(action=>"commit",7168 hash=>$_)},7169 esc_html(substr($_,0,7)));7170}@$parents) .7171')';7172}7173if(gitweb_check_feature('patches') &&@$parents<=1) {7174$formats_nav.=" | ".7175$cgi->a({-href => href(action=>"patch", -replay=>1)},7176"patch");7177}71787179if(!defined$parent) {7180$parent="--root";7181}7182my@difftree;7183open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",7184@diff_opts,7185(@$parents<=1?$parent:'-c'),7186$hash,"--"7187or die_error(500,"Open git-diff-tree failed");7188@difftree=map{chomp;$_} <$fd>;7189close$fdor die_error(404,"Reading git-diff-tree failed");71907191# non-textual hash id's can be cached7192my$expires;7193if($hash=~m/^[0-9a-fA-F]{40}$/) {7194$expires="+1d";7195}7196my$refs= git_get_references();7197my$ref= format_ref_marker($refs,$co{'id'});71987199 git_header_html(undef,$expires);7200 git_print_page_nav('commit','',7201$hash,$co{'tree'},$hash,7202$formats_nav);72037204if(defined$co{'parent'}) {7205 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);7206}else{7207 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);7208}7209print"<div class=\"title_text\">\n".7210"<table class=\"object_header\">\n";7211 git_print_authorship_rows(\%co);7212print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";7213print"<tr>".7214"<td>tree</td>".7215"<td class=\"sha1\">".7216$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),7217class=>"list"},$co{'tree'}) .7218"</td>".7219"<td class=\"link\">".7220$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},7221"tree");7222my$snapshot_links= format_snapshot_links($hash);7223if(defined$snapshot_links) {7224print" | ".$snapshot_links;7225}7226print"</td>".7227"</tr>\n";72287229foreachmy$par(@$parents) {7230print"<tr>".7231"<td>parent</td>".7232"<td class=\"sha1\">".7233$cgi->a({-href => href(action=>"commit", hash=>$par),7234class=>"list"},$par) .7235"</td>".7236"<td class=\"link\">".7237$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .7238" | ".7239$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .7240"</td>".7241"</tr>\n";7242}7243print"</table>".7244"</div>\n";72457246print"<div class=\"page_body\">\n";7247 git_print_log($co{'comment'});7248print"</div>\n";72497250 git_difftree_body(\@difftree,$hash,@$parents);72517252 git_footer_html();7253}72547255sub git_object {7256# object is defined by:7257# - hash or hash_base alone7258# - hash_base and file_name7259my$type;72607261# - hash or hash_base alone7262if($hash|| ($hash_base&& !defined$file_name)) {7263my$object_id=$hash||$hash_base;72647265open my$fd,"-|", quote_command(7266 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'7267or die_error(404,"Object does not exist");7268$type= <$fd>;7269chomp$type;7270close$fd7271or die_error(404,"Object does not exist");72727273# - hash_base and file_name7274}elsif($hash_base&&defined$file_name) {7275$file_name=~ s,/+$,,;72767277system(git_cmd(),"cat-file",'-e',$hash_base) ==07278or die_error(404,"Base object does not exist");72797280# here errors should not hapen7281open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name7282or die_error(500,"Open git-ls-tree failed");7283my$line= <$fd>;7284close$fd;72857286#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'7287unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {7288 die_error(404,"File or directory for given base does not exist");7289}7290$type=$2;7291$hash=$3;7292}else{7293 die_error(400,"Not enough information to find object");7294}72957296print$cgi->redirect(-uri => href(action=>$type, -full=>1,7297 hash=>$hash, hash_base=>$hash_base,7298 file_name=>$file_name),7299-status =>'302 Found');7300}73017302sub git_blobdiff {7303my$format=shift||'html';7304my$diff_style=$input_params{'diff_style'} ||'inline';73057306my$fd;7307my@difftree;7308my%diffinfo;7309my$expires;73107311# preparing $fd and %diffinfo for git_patchset_body7312# new style URI7313if(defined$hash_base&&defined$hash_parent_base) {7314if(defined$file_name) {7315# read raw output7316open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7317$hash_parent_base,$hash_base,7318"--", (defined$file_parent?$file_parent: ()),$file_name7319or die_error(500,"Open git-diff-tree failed");7320@difftree=map{chomp;$_} <$fd>;7321close$fd7322or die_error(404,"Reading git-diff-tree failed");7323@difftree7324or die_error(404,"Blob diff not found");73257326}elsif(defined$hash&&7327$hash=~/[0-9a-fA-F]{40}/) {7328# try to find filename from $hash73297330# read filtered raw output7331open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7332$hash_parent_base,$hash_base,"--"7333or die_error(500,"Open git-diff-tree failed");7334@difftree=7335# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'7336# $hash == to_id7337grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}7338map{chomp;$_} <$fd>;7339close$fd7340or die_error(404,"Reading git-diff-tree failed");7341@difftree7342or die_error(404,"Blob diff not found");73437344}else{7345 die_error(400,"Missing one of the blob diff parameters");7346}73477348if(@difftree>1) {7349 die_error(400,"Ambiguous blob diff specification");7350}73517352%diffinfo= parse_difftree_raw_line($difftree[0]);7353$file_parent||=$diffinfo{'from_file'} ||$file_name;7354$file_name||=$diffinfo{'to_file'};73557356$hash_parent||=$diffinfo{'from_id'};7357$hash||=$diffinfo{'to_id'};73587359# non-textual hash id's can be cached7360if($hash_base=~m/^[0-9a-fA-F]{40}$/&&7361$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {7362$expires='+1d';7363}73647365# open patch output7366open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7367'-p', ($formateq'html'?"--full-index": ()),7368$hash_parent_base,$hash_base,7369"--", (defined$file_parent?$file_parent: ()),$file_name7370or die_error(500,"Open git-diff-tree failed");7371}73727373# old/legacy style URI -- not generated anymore since 1.4.3.7374if(!%diffinfo) {7375 die_error('404 Not Found',"Missing one of the blob diff parameters")7376}73777378# header7379if($formateq'html') {7380my$formats_nav=7381$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},7382"raw");7383$formats_nav.= diff_style_nav($diff_style);7384 git_header_html(undef,$expires);7385if(defined$hash_base&& (my%co= parse_commit($hash_base))) {7386 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);7387 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);7388}else{7389print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";7390print"<div class=\"title\">".esc_html("$hashvs$hash_parent")."</div>\n";7391}7392if(defined$file_name) {7393 git_print_page_path($file_name,"blob",$hash_base);7394}else{7395print"<div class=\"page_path\"></div>\n";7396}73977398}elsif($formateq'plain') {7399print$cgi->header(7400-type =>'text/plain',7401-charset =>'utf-8',7402-expires =>$expires,7403-content_disposition =>'inline; filename="'."$file_name".'.patch"');74047405print"X-Git-Url: ".$cgi->self_url() ."\n\n";74067407}else{7408 die_error(400,"Unknown blobdiff format");7409}74107411# patch7412if($formateq'html') {7413print"<div class=\"page_body\">\n";74147415 git_patchset_body($fd,$diff_style,7416[ \%diffinfo],$hash_base,$hash_parent_base);7417close$fd;74187419print"</div>\n";# class="page_body"7420 git_footer_html();74217422}else{7423while(my$line= <$fd>) {7424$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;7425$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;74267427print$line;74287429last if$line=~m!^\+\+\+!;7430}7431local$/=undef;7432print<$fd>;7433close$fd;7434}7435}74367437sub git_blobdiff_plain {7438 git_blobdiff('plain');7439}74407441# assumes that it is added as later part of already existing navigation,7442# so it returns "| foo | bar" rather than just "foo | bar"7443sub diff_style_nav {7444my($diff_style,$is_combined) =@_;7445$diff_style||='inline';74467447return""if($is_combined);74487449my@styles= (inline =>'inline','sidebyside'=>'side by side');7450my%styles=@styles;7451@styles=7452@styles[map{$_*2}0..$#styles/2];74537454returnjoin'',7455map{" | ".$_}7456map{7457$_eq$diff_style?$styles{$_} :7458$cgi->a({-href => href(-replay=>1, diff_style =>$_)},$styles{$_})7459}@styles;7460}74617462sub git_commitdiff {7463my%params=@_;7464my$format=$params{-format} ||'html';7465my$diff_style=$input_params{'diff_style'} ||'inline';74667467my($patch_max) = gitweb_get_feature('patches');7468if($formateq'patch') {7469 die_error(403,"Patch view not allowed")unless$patch_max;7470}74717472$hash||=$hash_base||"HEAD";7473my%co= parse_commit($hash)7474or die_error(404,"Unknown commit object");74757476# choose format for commitdiff for merge7477if(!defined$hash_parent&& @{$co{'parents'}} >1) {7478$hash_parent='--cc';7479}7480# we need to prepare $formats_nav before almost any parameter munging7481my$formats_nav;7482if($formateq'html') {7483$formats_nav=7484$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},7485"raw");7486if($patch_max&& @{$co{'parents'}} <=1) {7487$formats_nav.=" | ".7488$cgi->a({-href => href(action=>"patch", -replay=>1)},7489"patch");7490}7491$formats_nav.= diff_style_nav($diff_style, @{$co{'parents'}} >1);74927493if(defined$hash_parent&&7494$hash_parentne'-c'&&$hash_parentne'--cc') {7495# commitdiff with two commits given7496my$hash_parent_short=$hash_parent;7497if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {7498$hash_parent_short=substr($hash_parent,0,7);7499}7500$formats_nav.=7501' (from';7502for(my$i=0;$i< @{$co{'parents'}};$i++) {7503if($co{'parents'}[$i]eq$hash_parent) {7504$formats_nav.=' parent '. ($i+1);7505last;7506}7507}7508$formats_nav.=': '.7509$cgi->a({-href => href(-replay=>1,7510 hash=>$hash_parent, hash_base=>undef)},7511 esc_html($hash_parent_short)) .7512')';7513}elsif(!$co{'parent'}) {7514# --root commitdiff7515$formats_nav.=' (initial)';7516}elsif(scalar@{$co{'parents'}} ==1) {7517# single parent commit7518$formats_nav.=7519' (parent: '.7520$cgi->a({-href => href(-replay=>1,7521 hash=>$co{'parent'}, hash_base=>undef)},7522 esc_html(substr($co{'parent'},0,7))) .7523')';7524}else{7525# merge commit7526if($hash_parenteq'--cc') {7527$formats_nav.=' | '.7528$cgi->a({-href => href(-replay=>1,7529 hash=>$hash, hash_parent=>'-c')},7530'combined');7531}else{# $hash_parent eq '-c'7532$formats_nav.=' | '.7533$cgi->a({-href => href(-replay=>1,7534 hash=>$hash, hash_parent=>'--cc')},7535'compact');7536}7537$formats_nav.=7538' (merge: '.7539join(' ',map{7540$cgi->a({-href => href(-replay=>1,7541 hash=>$_, hash_base=>undef)},7542 esc_html(substr($_,0,7)));7543} @{$co{'parents'}} ) .7544')';7545}7546}75477548my$hash_parent_param=$hash_parent;7549if(!defined$hash_parent_param) {7550# --cc for multiple parents, --root for parentless7551$hash_parent_param=7552@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';7553}75547555# read commitdiff7556my$fd;7557my@difftree;7558if($formateq'html') {7559open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7560"--no-commit-id","--patch-with-raw","--full-index",7561$hash_parent_param,$hash,"--"7562or die_error(500,"Open git-diff-tree failed");75637564while(my$line= <$fd>) {7565chomp$line;7566# empty line ends raw part of diff-tree output7567last unless$line;7568push@difftree,scalar parse_difftree_raw_line($line);7569}75707571}elsif($formateq'plain') {7572open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7573'-p',$hash_parent_param,$hash,"--"7574or die_error(500,"Open git-diff-tree failed");7575}elsif($formateq'patch') {7576# For commit ranges, we limit the output to the number of7577# patches specified in the 'patches' feature.7578# For single commits, we limit the output to a single patch,7579# diverging from the git-format-patch default.7580my@commit_spec= ();7581if($hash_parent) {7582if($patch_max>0) {7583push@commit_spec,"-$patch_max";7584}7585push@commit_spec,'-n',"$hash_parent..$hash";7586}else{7587if($params{-single}) {7588push@commit_spec,'-1';7589}else{7590if($patch_max>0) {7591push@commit_spec,"-$patch_max";7592}7593push@commit_spec,"-n";7594}7595push@commit_spec,'--root',$hash;7596}7597open$fd,"-|", git_cmd(),"format-patch",@diff_opts,7598'--encoding=utf8','--stdout',@commit_spec7599or die_error(500,"Open git-format-patch failed");7600}else{7601 die_error(400,"Unknown commitdiff format");7602}76037604# non-textual hash id's can be cached7605my$expires;7606if($hash=~m/^[0-9a-fA-F]{40}$/) {7607$expires="+1d";7608}76097610# write commit message7611if($formateq'html') {7612my$refs= git_get_references();7613my$ref= format_ref_marker($refs,$co{'id'});76147615 git_header_html(undef,$expires);7616 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);7617 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);7618print"<div class=\"title_text\">\n".7619"<table class=\"object_header\">\n";7620 git_print_authorship_rows(\%co);7621print"</table>".7622"</div>\n";7623print"<div class=\"page_body\">\n";7624if(@{$co{'comment'}} >1) {7625print"<div class=\"log\">\n";7626 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);7627print"</div>\n";# class="log"7628}76297630}elsif($formateq'plain') {7631my$refs= git_get_references("tags");7632my$tagname= git_get_rev_name_tags($hash);7633my$filename= basename($project) ."-$hash.patch";76347635print$cgi->header(7636-type =>'text/plain',7637-charset =>'utf-8',7638-expires =>$expires,7639-content_disposition =>'inline; filename="'."$filename".'"');7640my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});7641print"From: ". to_utf8($co{'author'}) ."\n";7642print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";7643print"Subject: ". to_utf8($co{'title'}) ."\n";76447645print"X-Git-Tag:$tagname\n"if$tagname;7646print"X-Git-Url: ".$cgi->self_url() ."\n\n";76477648foreachmy$line(@{$co{'comment'}}) {7649print to_utf8($line) ."\n";7650}7651print"---\n\n";7652}elsif($formateq'patch') {7653my$filename= basename($project) ."-$hash.patch";76547655print$cgi->header(7656-type =>'text/plain',7657-charset =>'utf-8',7658-expires =>$expires,7659-content_disposition =>'inline; filename="'."$filename".'"');7660}76617662# write patch7663if($formateq'html') {7664my$use_parents= !defined$hash_parent||7665$hash_parenteq'-c'||$hash_parenteq'--cc';7666 git_difftree_body(\@difftree,$hash,7667$use_parents? @{$co{'parents'}} :$hash_parent);7668print"<br/>\n";76697670 git_patchset_body($fd,$diff_style,7671 \@difftree,$hash,7672$use_parents? @{$co{'parents'}} :$hash_parent);7673close$fd;7674print"</div>\n";# class="page_body"7675 git_footer_html();76767677}elsif($formateq'plain') {7678local$/=undef;7679print<$fd>;7680close$fd7681or print"Reading git-diff-tree failed\n";7682}elsif($formateq'patch') {7683local$/=undef;7684print<$fd>;7685close$fd7686or print"Reading git-format-patch failed\n";7687}7688}76897690sub git_commitdiff_plain {7691 git_commitdiff(-format =>'plain');7692}76937694# format-patch-style patches7695sub git_patch {7696 git_commitdiff(-format =>'patch', -single =>1);7697}76987699sub git_patches {7700 git_commitdiff(-format =>'patch');7701}77027703sub git_history {7704 git_log_generic('history', \&git_history_body,7705$hash_base,$hash_parent_base,7706$file_name,$hash);7707}77087709sub git_search {7710$searchtype||='commit';77117712# check if appropriate features are enabled7713 gitweb_check_feature('search')7714or die_error(403,"Search is disabled");7715if($searchtypeeq'pickaxe') {7716# pickaxe may take all resources of your box and run for several minutes7717# with every query - so decide by yourself how public you make this feature7718 gitweb_check_feature('pickaxe')7719or die_error(403,"Pickaxe search is disabled");7720}7721if($searchtypeeq'grep') {7722# grep search might be potentially CPU-intensive, too7723 gitweb_check_feature('grep')7724or die_error(403,"Grep search is disabled");7725}77267727if(!defined$searchtext) {7728 die_error(400,"Text field is empty");7729}7730if(!defined$hash) {7731$hash= git_get_head_hash($project);7732}7733my%co= parse_commit($hash);7734if(!%co) {7735 die_error(404,"Unknown commit object");7736}7737if(!defined$page) {7738$page=0;7739}77407741if($searchtypeeq'commit'||7742$searchtypeeq'author'||7743$searchtypeeq'committer') {7744 git_search_message(%co);7745}elsif($searchtypeeq'pickaxe') {7746 git_search_changes(%co);7747}elsif($searchtypeeq'grep') {7748 git_search_files(%co);7749}else{7750 die_error(400,"Unknown search type");7751}7752}77537754sub git_search_help {7755 git_header_html();7756 git_print_page_nav('','',$hash,$hash,$hash);7757print<<EOT;7758<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without7759regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,7760the pattern entered is recognized as the POSIX extended7761<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case7762insensitive).</p>7763<dl>7764<dt><b>commit</b></dt>7765<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>7766EOT7767my$have_grep= gitweb_check_feature('grep');7768if($have_grep) {7769print<<EOT;7770<dt><b>grep</b></dt>7771<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing7772 a different one) are searched for the given pattern. On large trees, this search can take7773a while and put some strain on the server, so please use it with some consideration. Note that7774due to git-grep peculiarity, currently if regexp mode is turned off, the matches are7775case-sensitive.</dd>7776EOT7777}7778print<<EOT;7779<dt><b>author</b></dt>7780<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>7781<dt><b>committer</b></dt>7782<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>7783EOT7784my$have_pickaxe= gitweb_check_feature('pickaxe');7785if($have_pickaxe) {7786print<<EOT;7787<dt><b>pickaxe</b></dt>7788<dd>All commits that caused the string to appear or disappear from any file (changes that7789added, removed or "modified" the string) will be listed. This search can take a while and7790takes a lot of strain on the server, so please use it wisely. Note that since you may be7791interested even in changes just changing the case as well, this search is case sensitive.</dd>7792EOT7793}7794print"</dl>\n";7795 git_footer_html();7796}77977798sub git_shortlog {7799 git_log_generic('shortlog', \&git_shortlog_body,7800$hash,$hash_parent);7801}78027803## ......................................................................7804## feeds (RSS, Atom; OPML)78057806sub git_feed {7807my$format=shift||'atom';7808my$have_blame= gitweb_check_feature('blame');78097810# Atom: http://www.atomenabled.org/developers/syndication/7811# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ7812if($formatne'rss'&&$formatne'atom') {7813 die_error(400,"Unknown web feed format");7814}78157816# log/feed of current (HEAD) branch, log of given branch, history of file/directory7817my$head=$hash||'HEAD';7818my@commitlist= parse_commits($head,150,0,$file_name);78197820my%latest_commit;7821my%latest_date;7822my$content_type="application/$format+xml";7823if(defined$cgi->http('HTTP_ACCEPT') &&7824$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {7825# browser (feed reader) prefers text/xml7826$content_type='text/xml';7827}7828if(defined($commitlist[0])) {7829%latest_commit= %{$commitlist[0]};7830my$latest_epoch=$latest_commit{'committer_epoch'};7831%latest_date= parse_date($latest_epoch,$latest_commit{'comitter_tz'});7832my$if_modified=$cgi->http('IF_MODIFIED_SINCE');7833if(defined$if_modified) {7834my$since;7835if(eval{require HTTP::Date;1; }) {7836$since= HTTP::Date::str2time($if_modified);7837}elsif(eval{require Time::ParseDate;1; }) {7838$since= Time::ParseDate::parsedate($if_modified, GMT =>1);7839}7840if(defined$since&&$latest_epoch<=$since) {7841print$cgi->header(7842-type =>$content_type,7843-charset =>'utf-8',7844-last_modified =>$latest_date{'rfc2822'},7845-status =>'304 Not Modified');7846return;7847}7848}7849print$cgi->header(7850-type =>$content_type,7851-charset =>'utf-8',7852-last_modified =>$latest_date{'rfc2822'});7853}else{7854print$cgi->header(7855-type =>$content_type,7856-charset =>'utf-8');7857}78587859# Optimization: skip generating the body if client asks only7860# for Last-Modified date.7861return if($cgi->request_method()eq'HEAD');78627863# header variables7864my$title="$site_name-$project/$action";7865my$feed_type='log';7866if(defined$hash) {7867$title.=" - '$hash'";7868$feed_type='branch log';7869if(defined$file_name) {7870$title.=" ::$file_name";7871$feed_type='history';7872}7873}elsif(defined$file_name) {7874$title.=" -$file_name";7875$feed_type='history';7876}7877$title.="$feed_type";7878my$descr= git_get_project_description($project);7879if(defined$descr) {7880$descr= esc_html($descr);7881}else{7882$descr="$project".7883($formateq'rss'?'RSS':'Atom') .7884" feed";7885}7886my$owner= git_get_project_owner($project);7887$owner= esc_html($owner);78887889#header7890my$alt_url;7891if(defined$file_name) {7892$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);7893}elsif(defined$hash) {7894$alt_url= href(-full=>1, action=>"log", hash=>$hash);7895}else{7896$alt_url= href(-full=>1, action=>"summary");7897}7898print qq!<?xml version="1.0" encoding="utf-8"?>\n!;7899if($formateq'rss') {7900print<<XML;7901<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">7902<channel>7903XML7904print"<title>$title</title>\n".7905"<link>$alt_url</link>\n".7906"<description>$descr</description>\n".7907"<language>en</language>\n".7908# project owner is responsible for 'editorial' content7909"<managingEditor>$owner</managingEditor>\n";7910if(defined$logo||defined$favicon) {7911# prefer the logo to the favicon, since RSS7912# doesn't allow both7913my$img= esc_url($logo||$favicon);7914print"<image>\n".7915"<url>$img</url>\n".7916"<title>$title</title>\n".7917"<link>$alt_url</link>\n".7918"</image>\n";7919}7920if(%latest_date) {7921print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";7922print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";7923}7924print"<generator>gitweb v.$version/$git_version</generator>\n";7925}elsif($formateq'atom') {7926print<<XML;7927<feed xmlns="http://www.w3.org/2005/Atom">7928XML7929print"<title>$title</title>\n".7930"<subtitle>$descr</subtitle>\n".7931'<link rel="alternate" type="text/html" href="'.7932$alt_url.'" />'."\n".7933'<link rel="self" type="'.$content_type.'" href="'.7934$cgi->self_url() .'" />'."\n".7935"<id>". href(-full=>1) ."</id>\n".7936# use project owner for feed author7937"<author><name>$owner</name></author>\n";7938if(defined$favicon) {7939print"<icon>". esc_url($favicon) ."</icon>\n";7940}7941if(defined$logo) {7942# not twice as wide as tall: 72 x 27 pixels7943print"<logo>". esc_url($logo) ."</logo>\n";7944}7945if(!%latest_date) {7946# dummy date to keep the feed valid until commits trickle in:7947print"<updated>1970-01-01T00:00:00Z</updated>\n";7948}else{7949print"<updated>$latest_date{'iso-8601'}</updated>\n";7950}7951print"<generator version='$version/$git_version'>gitweb</generator>\n";7952}79537954# contents7955for(my$i=0;$i<=$#commitlist;$i++) {7956my%co= %{$commitlist[$i]};7957my$commit=$co{'id'};7958# we read 150, we always show 30 and the ones more recent than 48 hours7959if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {7960last;7961}7962my%cd= parse_date($co{'author_epoch'},$co{'author_tz'});79637964# get list of changed files7965open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7966$co{'parent'} ||"--root",7967$co{'id'},"--", (defined$file_name?$file_name: ())7968ornext;7969my@difftree=map{chomp;$_} <$fd>;7970close$fd7971ornext;79727973# print element (entry, item)7974my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);7975if($formateq'rss') {7976print"<item>\n".7977"<title>". esc_html($co{'title'}) ."</title>\n".7978"<author>". esc_html($co{'author'}) ."</author>\n".7979"<pubDate>$cd{'rfc2822'}</pubDate>\n".7980"<guid isPermaLink=\"true\">$co_url</guid>\n".7981"<link>$co_url</link>\n".7982"<description>". esc_html($co{'title'}) ."</description>\n".7983"<content:encoded>".7984"<![CDATA[\n";7985}elsif($formateq'atom') {7986print"<entry>\n".7987"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".7988"<updated>$cd{'iso-8601'}</updated>\n".7989"<author>\n".7990" <name>". esc_html($co{'author_name'}) ."</name>\n";7991if($co{'author_email'}) {7992print" <email>". esc_html($co{'author_email'}) ."</email>\n";7993}7994print"</author>\n".7995# use committer for contributor7996"<contributor>\n".7997" <name>". esc_html($co{'committer_name'}) ."</name>\n";7998if($co{'committer_email'}) {7999print" <email>". esc_html($co{'committer_email'}) ."</email>\n";8000}8001print"</contributor>\n".8002"<published>$cd{'iso-8601'}</published>\n".8003"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".8004"<id>$co_url</id>\n".8005"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".8006"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";8007}8008my$comment=$co{'comment'};8009print"<pre>\n";8010foreachmy$line(@$comment) {8011$line= esc_html($line);8012print"$line\n";8013}8014print"</pre><ul>\n";8015foreachmy$difftree_line(@difftree) {8016my%difftree= parse_difftree_raw_line($difftree_line);8017next if!$difftree{'from_id'};80188019my$file=$difftree{'file'} ||$difftree{'to_file'};80208021print"<li>".8022"[".8023$cgi->a({-href => href(-full=>1, action=>"blobdiff",8024 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},8025 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},8026 file_name=>$file, file_parent=>$difftree{'from_file'}),8027-title =>"diff"},'D');8028if($have_blame) {8029print$cgi->a({-href => href(-full=>1, action=>"blame",8030 file_name=>$file, hash_base=>$commit),8031-title =>"blame"},'B');8032}8033# if this is not a feed of a file history8034if(!defined$file_name||$file_namene$file) {8035print$cgi->a({-href => href(-full=>1, action=>"history",8036 file_name=>$file, hash=>$commit),8037-title =>"history"},'H');8038}8039$file= esc_path($file);8040print"] ".8041"$file</li>\n";8042}8043if($formateq'rss') {8044print"</ul>]]>\n".8045"</content:encoded>\n".8046"</item>\n";8047}elsif($formateq'atom') {8048print"</ul>\n</div>\n".8049"</content>\n".8050"</entry>\n";8051}8052}80538054# end of feed8055if($formateq'rss') {8056print"</channel>\n</rss>\n";8057}elsif($formateq'atom') {8058print"</feed>\n";8059}8060}80618062sub git_rss {8063 git_feed('rss');8064}80658066sub git_atom {8067 git_feed('atom');8068}80698070sub git_opml {8071my@list= git_get_projects_list($project_filter,$strict_export);8072if(!@list) {8073 die_error(404,"No projects found");8074}80758076print$cgi->header(8077-type =>'text/xml',8078-charset =>'utf-8',8079-content_disposition =>'inline; filename="opml.xml"');80808081my$title= esc_html($site_name);8082my$filter=" within subdirectory ";8083if(defined$project_filter) {8084$filter.= esc_html($project_filter);8085}else{8086$filter="";8087}8088print<<XML;8089<?xml version="1.0" encoding="utf-8"?>8090<opml version="1.0">8091<head>8092 <title>$titleOPML Export$filter</title>8093</head>8094<body>8095<outline text="git RSS feeds">8096XML80978098foreachmy$pr(@list) {8099my%proj=%$pr;8100my$head= git_get_head_hash($proj{'path'});8101if(!defined$head) {8102next;8103}8104$git_dir="$projectroot/$proj{'path'}";8105my%co= parse_commit($head);8106if(!%co) {8107next;8108}81098110my$path= esc_html(chop_str($proj{'path'},25,5));8111my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);8112my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);8113print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";8114}8115print<<XML;8116</outline>8117</body>8118</opml>8119XML8120}