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=$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# filename of html text to include at top of each page 89our$site_header="++GITWEB_SITE_HEADER++"; 90# html text to include at home page 91our$home_text="++GITWEB_HOMETEXT++"; 92# filename of html text to include at bottom of each page 93our$site_footer="++GITWEB_SITE_FOOTER++"; 94 95# URI of stylesheets 96our@stylesheets= ("++GITWEB_CSS++"); 97# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 98our$stylesheet=undef; 99# URI of GIT logo (72x27 size) 100our$logo="++GITWEB_LOGO++"; 101# URI of GIT favicon, assumed to be image/png type 102our$favicon="++GITWEB_FAVICON++"; 103# URI of gitweb.js (JavaScript code for gitweb) 104our$javascript="++GITWEB_JS++"; 105 106# URI and label (title) of GIT logo link 107#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 108#our $logo_label = "git documentation"; 109our$logo_url="http://git-scm.com/"; 110our$logo_label="git homepage"; 111 112# source of projects list 113our$projects_list="++GITWEB_LIST++"; 114 115# the width (in characters) of the projects list "Description" column 116our$projects_list_description_width=25; 117 118# default order of projects list 119# valid values are none, project, descr, owner, and age 120our$default_projects_order="project"; 121 122# show repository only if this file exists 123# (only effective if this variable evaluates to true) 124our$export_ok="++GITWEB_EXPORT_OK++"; 125 126# show repository only if this subroutine returns true 127# when given the path to the project, for example: 128# sub { return -e "$_[0]/git-daemon-export-ok"; } 129our$export_auth_hook=undef; 130 131# only allow viewing of repositories also shown on the overview page 132our$strict_export="++GITWEB_STRICT_EXPORT++"; 133 134# list of git base URLs used for URL to where fetch project from, 135# i.e. full URL is "$git_base_url/$project" 136our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 137 138# default blob_plain mimetype and default charset for text/plain blob 139our$default_blob_plain_mimetype='text/plain'; 140our$default_text_plain_charset=undef; 141 142# file to use for guessing MIME types before trying /etc/mime.types 143# (relative to the current git repository) 144our$mimetypes_file=undef; 145 146# assume this charset if line contains non-UTF-8 characters; 147# it should be valid encoding (see Encoding::Supported(3pm) for list), 148# for which encoding all byte sequences are valid, for example 149# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 150# could be even 'utf-8' for the old behavior) 151our$fallback_encoding='latin1'; 152 153# rename detection options for git-diff and git-diff-tree 154# - default is '-M', with the cost proportional to 155# (number of removed files) * (number of new files). 156# - more costly is '-C' (which implies '-M'), with the cost proportional to 157# (number of changed files + number of removed files) * (number of new files) 158# - even more costly is '-C', '--find-copies-harder' with cost 159# (number of files in the original tree) * (number of new files) 160# - one might want to include '-B' option, e.g. '-B', '-M' 161our@diff_opts= ('-M');# taken from git_commit 162 163# Disables features that would allow repository owners to inject script into 164# the gitweb domain. 165our$prevent_xss=0; 166 167# Path to the highlight executable to use (must be the one from 168# http://www.andre-simon.de due to assumptions about parameters and output). 169# Useful if highlight is not installed on your webserver's PATH. 170# [Default: highlight] 171our$highlight_bin="++HIGHLIGHT_BIN++"; 172 173# information about snapshot formats that gitweb is capable of serving 174our%known_snapshot_formats= ( 175# name => { 176# 'display' => display name, 177# 'type' => mime type, 178# 'suffix' => filename suffix, 179# 'format' => --format for git-archive, 180# 'compressor' => [compressor command and arguments] 181# (array reference, optional) 182# 'disabled' => boolean (optional)} 183# 184'tgz'=> { 185'display'=>'tar.gz', 186'type'=>'application/x-gzip', 187'suffix'=>'.tar.gz', 188'format'=>'tar', 189'compressor'=> ['gzip']}, 190 191'tbz2'=> { 192'display'=>'tar.bz2', 193'type'=>'application/x-bzip2', 194'suffix'=>'.tar.bz2', 195'format'=>'tar', 196'compressor'=> ['bzip2']}, 197 198'txz'=> { 199'display'=>'tar.xz', 200'type'=>'application/x-xz', 201'suffix'=>'.tar.xz', 202'format'=>'tar', 203'compressor'=> ['xz'], 204'disabled'=>1}, 205 206'zip'=> { 207'display'=>'zip', 208'type'=>'application/x-zip', 209'suffix'=>'.zip', 210'format'=>'zip'}, 211); 212 213# Aliases so we understand old gitweb.snapshot values in repository 214# configuration. 215our%known_snapshot_format_aliases= ( 216'gzip'=>'tgz', 217'bzip2'=>'tbz2', 218'xz'=>'txz', 219 220# backward compatibility: legacy gitweb config support 221'x-gzip'=>undef,'gz'=>undef, 222'x-bzip2'=>undef,'bz2'=>undef, 223'x-zip'=>undef,''=>undef, 224); 225 226# Pixel sizes for icons and avatars. If the default font sizes or lineheights 227# are changed, it may be appropriate to change these values too via 228# $GITWEB_CONFIG. 229our%avatar_size= ( 230'default'=>16, 231'double'=>32 232); 233 234# Used to set the maximum load that we will still respond to gitweb queries. 235# If server load exceed this value then return "503 server busy" error. 236# If gitweb cannot determined server load, it is taken to be 0. 237# Leave it undefined (or set to 'undef') to turn off load checking. 238our$maxload=300; 239 240# configuration for 'highlight' (http://www.andre-simon.de/) 241# match by basename 242our%highlight_basename= ( 243#'Program' => 'py', 244#'Library' => 'py', 245'SConstruct'=>'py',# SCons equivalent of Makefile 246'Makefile'=>'make', 247); 248# match by extension 249our%highlight_ext= ( 250# main extensions, defining name of syntax; 251# see files in /usr/share/highlight/langDefs/ directory 252map{$_=>$_} 253qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl sql make), 254# alternate extensions, see /etc/highlight/filetypes.conf 255'h'=>'c', 256map{$_=>'sh'}qw(bash zsh ksh), 257map{$_=>'cpp'}qw(cxx c++ cc), 258map{$_=>'php'}qw(php3 php4 php5 phps), 259map{$_=>'pl'}qw(perl pm),# perhaps also 'cgi' 260map{$_=>'make'}qw(mak mk), 261map{$_=>'xml'}qw(xhtml html htm), 262); 263 264# You define site-wide feature defaults here; override them with 265# $GITWEB_CONFIG as necessary. 266our%feature= ( 267# feature => { 268# 'sub' => feature-sub (subroutine), 269# 'override' => allow-override (boolean), 270# 'default' => [ default options...] (array reference)} 271# 272# if feature is overridable (it means that allow-override has true value), 273# then feature-sub will be called with default options as parameters; 274# return value of feature-sub indicates if to enable specified feature 275# 276# if there is no 'sub' key (no feature-sub), then feature cannot be 277# overridden 278# 279# use gitweb_get_feature(<feature>) to retrieve the <feature> value 280# (an array) or gitweb_check_feature(<feature>) to check if <feature> 281# is enabled 282 283# Enable the 'blame' blob view, showing the last commit that modified 284# each line in the file. This can be very CPU-intensive. 285 286# To enable system wide have in $GITWEB_CONFIG 287# $feature{'blame'}{'default'} = [1]; 288# To have project specific config enable override in $GITWEB_CONFIG 289# $feature{'blame'}{'override'} = 1; 290# and in project config gitweb.blame = 0|1; 291'blame'=> { 292'sub'=>sub{ feature_bool('blame',@_) }, 293'override'=>0, 294'default'=> [0]}, 295 296# Enable the 'snapshot' link, providing a compressed archive of any 297# tree. This can potentially generate high traffic if you have large 298# project. 299 300# Value is a list of formats defined in %known_snapshot_formats that 301# you wish to offer. 302# To disable system wide have in $GITWEB_CONFIG 303# $feature{'snapshot'}{'default'} = []; 304# To have project specific config enable override in $GITWEB_CONFIG 305# $feature{'snapshot'}{'override'} = 1; 306# and in project config, a comma-separated list of formats or "none" 307# to disable. Example: gitweb.snapshot = tbz2,zip; 308'snapshot'=> { 309'sub'=> \&feature_snapshot, 310'override'=>0, 311'default'=> ['tgz']}, 312 313# Enable text search, which will list the commits which match author, 314# committer or commit text to a given string. Enabled by default. 315# Project specific override is not supported. 316'search'=> { 317'override'=>0, 318'default'=> [1]}, 319 320# Enable grep search, which will list the files in currently selected 321# tree containing the given string. Enabled by default. This can be 322# potentially CPU-intensive, of course. 323 324# To enable system wide have in $GITWEB_CONFIG 325# $feature{'grep'}{'default'} = [1]; 326# To have project specific config enable override in $GITWEB_CONFIG 327# $feature{'grep'}{'override'} = 1; 328# and in project config gitweb.grep = 0|1; 329'grep'=> { 330'sub'=>sub{ feature_bool('grep',@_) }, 331'override'=>0, 332'default'=> [1]}, 333 334# Enable the pickaxe search, which will list the commits that modified 335# a given string in a file. This can be practical and quite faster 336# alternative to 'blame', but still potentially CPU-intensive. 337 338# To enable system wide have in $GITWEB_CONFIG 339# $feature{'pickaxe'}{'default'} = [1]; 340# To have project specific config enable override in $GITWEB_CONFIG 341# $feature{'pickaxe'}{'override'} = 1; 342# and in project config gitweb.pickaxe = 0|1; 343'pickaxe'=> { 344'sub'=>sub{ feature_bool('pickaxe',@_) }, 345'override'=>0, 346'default'=> [1]}, 347 348# Enable showing size of blobs in a 'tree' view, in a separate 349# column, similar to what 'ls -l' does. This cost a bit of IO. 350 351# To disable system wide have in $GITWEB_CONFIG 352# $feature{'show-sizes'}{'default'} = [0]; 353# To have project specific config enable override in $GITWEB_CONFIG 354# $feature{'show-sizes'}{'override'} = 1; 355# and in project config gitweb.showsizes = 0|1; 356'show-sizes'=> { 357'sub'=>sub{ feature_bool('showsizes',@_) }, 358'override'=>0, 359'default'=> [1]}, 360 361# Make gitweb use an alternative format of the URLs which can be 362# more readable and natural-looking: project name is embedded 363# directly in the path and the query string contains other 364# auxiliary information. All gitweb installations recognize 365# URL in either format; this configures in which formats gitweb 366# generates links. 367 368# To enable system wide have in $GITWEB_CONFIG 369# $feature{'pathinfo'}{'default'} = [1]; 370# Project specific override is not supported. 371 372# Note that you will need to change the default location of CSS, 373# favicon, logo and possibly other files to an absolute URL. Also, 374# if gitweb.cgi serves as your indexfile, you will need to force 375# $my_uri to contain the script name in your $GITWEB_CONFIG. 376'pathinfo'=> { 377'override'=>0, 378'default'=> [0]}, 379 380# Make gitweb consider projects in project root subdirectories 381# to be forks of existing projects. Given project $projname.git, 382# projects matching $projname/*.git will not be shown in the main 383# projects list, instead a '+' mark will be added to $projname 384# there and a 'forks' view will be enabled for the project, listing 385# all the forks. If project list is taken from a file, forks have 386# to be listed after the main project. 387 388# To enable system wide have in $GITWEB_CONFIG 389# $feature{'forks'}{'default'} = [1]; 390# Project specific override is not supported. 391'forks'=> { 392'override'=>0, 393'default'=> [0]}, 394 395# Insert custom links to the action bar of all project pages. 396# This enables you mainly to link to third-party scripts integrating 397# into gitweb; e.g. git-browser for graphical history representation 398# or custom web-based repository administration interface. 399 400# The 'default' value consists of a list of triplets in the form 401# (label, link, position) where position is the label after which 402# to insert the link and link is a format string where %n expands 403# to the project name, %f to the project path within the filesystem, 404# %h to the current hash (h gitweb parameter) and %b to the current 405# hash base (hb gitweb parameter); %% expands to %. 406 407# To enable system wide have in $GITWEB_CONFIG e.g. 408# $feature{'actions'}{'default'} = [('graphiclog', 409# '/git-browser/by-commit.html?r=%n', 'summary')]; 410# Project specific override is not supported. 411'actions'=> { 412'override'=>0, 413'default'=> []}, 414 415# Allow gitweb scan project content tags described in ctags/ 416# of project repository, and display the popular Web 2.0-ish 417# "tag cloud" near the project list. Note that this is something 418# COMPLETELY different from the normal Git tags. 419 420# gitweb by itself can show existing tags, but it does not handle 421# tagging itself; you need an external application for that. 422# For an example script, check Girocco's cgi/tagproj.cgi. 423# You may want to install the HTML::TagCloud Perl module to get 424# a pretty tag cloud instead of just a list of tags. 425 426# To enable system wide have in $GITWEB_CONFIG 427# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 428# Project specific override is not supported. 429'ctags'=> { 430'override'=>0, 431'default'=> [0]}, 432 433# The maximum number of patches in a patchset generated in patch 434# view. Set this to 0 or undef to disable patch view, or to a 435# negative number to remove any limit. 436 437# To disable system wide have in $GITWEB_CONFIG 438# $feature{'patches'}{'default'} = [0]; 439# To have project specific config enable override in $GITWEB_CONFIG 440# $feature{'patches'}{'override'} = 1; 441# and in project config gitweb.patches = 0|n; 442# where n is the maximum number of patches allowed in a patchset. 443'patches'=> { 444'sub'=> \&feature_patches, 445'override'=>0, 446'default'=> [16]}, 447 448# Avatar support. When this feature is enabled, views such as 449# shortlog or commit will display an avatar associated with 450# the email of the committer(s) and/or author(s). 451 452# Currently available providers are gravatar and picon. 453# If an unknown provider is specified, the feature is disabled. 454 455# Gravatar depends on Digest::MD5. 456# Picon currently relies on the indiana.edu database. 457 458# To enable system wide have in $GITWEB_CONFIG 459# $feature{'avatar'}{'default'} = ['<provider>']; 460# where <provider> is either gravatar or picon. 461# To have project specific config enable override in $GITWEB_CONFIG 462# $feature{'avatar'}{'override'} = 1; 463# and in project config gitweb.avatar = <provider>; 464'avatar'=> { 465'sub'=> \&feature_avatar, 466'override'=>0, 467'default'=> ['']}, 468 469# Enable displaying how much time and how many git commands 470# it took to generate and display page. Disabled by default. 471# Project specific override is not supported. 472'timed'=> { 473'override'=>0, 474'default'=> [0]}, 475 476# Enable turning some links into links to actions which require 477# JavaScript to run (like 'blame_incremental'). Not enabled by 478# default. Project specific override is currently not supported. 479'javascript-actions'=> { 480'override'=>0, 481'default'=> [0]}, 482 483# Enable and configure ability to change common timezone for dates 484# in gitweb output via JavaScript. Enabled by default. 485# Project specific override is not supported. 486'javascript-timezone'=> { 487'override'=>0, 488'default'=> [ 489'local',# default timezone: 'utc', 'local', or '(-|+)HHMM' format, 490# or undef to turn off this feature 491'gitweb_tz',# name of cookie where to store selected timezone 492'datetime',# CSS class used to mark up dates for manipulation 493]}, 494 495# Syntax highlighting support. This is based on Daniel Svensson's 496# and Sham Chukoury's work in gitweb-xmms2.git. 497# It requires the 'highlight' program present in $PATH, 498# and therefore is disabled by default. 499 500# To enable system wide have in $GITWEB_CONFIG 501# $feature{'highlight'}{'default'} = [1]; 502 503'highlight'=> { 504'sub'=>sub{ feature_bool('highlight',@_) }, 505'override'=>0, 506'default'=> [0]}, 507 508# Enable displaying of remote heads in the heads list 509 510# To enable system wide have in $GITWEB_CONFIG 511# $feature{'remote_heads'}{'default'} = [1]; 512# To have project specific config enable override in $GITWEB_CONFIG 513# $feature{'remote_heads'}{'override'} = 1; 514# and in project config gitweb.remote_heads = 0|1; 515'remote_heads'=> { 516'sub'=>sub{ feature_bool('remote_heads',@_) }, 517'override'=>0, 518'default'=> [0]}, 519); 520 521sub gitweb_get_feature { 522my($name) =@_; 523return unlessexists$feature{$name}; 524my($sub,$override,@defaults) = ( 525$feature{$name}{'sub'}, 526$feature{$name}{'override'}, 527@{$feature{$name}{'default'}}); 528# project specific override is possible only if we have project 529our$git_dir;# global variable, declared later 530if(!$override|| !defined$git_dir) { 531return@defaults; 532} 533if(!defined$sub) { 534warn"feature$nameis not overridable"; 535return@defaults; 536} 537return$sub->(@defaults); 538} 539 540# A wrapper to check if a given feature is enabled. 541# With this, you can say 542# 543# my $bool_feat = gitweb_check_feature('bool_feat'); 544# gitweb_check_feature('bool_feat') or somecode; 545# 546# instead of 547# 548# my ($bool_feat) = gitweb_get_feature('bool_feat'); 549# (gitweb_get_feature('bool_feat'))[0] or somecode; 550# 551sub gitweb_check_feature { 552return(gitweb_get_feature(@_))[0]; 553} 554 555 556sub feature_bool { 557my$key=shift; 558my($val) = git_get_project_config($key,'--bool'); 559 560if(!defined$val) { 561return($_[0]); 562}elsif($valeq'true') { 563return(1); 564}elsif($valeq'false') { 565return(0); 566} 567} 568 569sub feature_snapshot { 570my(@fmts) =@_; 571 572my($val) = git_get_project_config('snapshot'); 573 574if($val) { 575@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 576} 577 578return@fmts; 579} 580 581sub feature_patches { 582my@val= (git_get_project_config('patches','--int')); 583 584if(@val) { 585return@val; 586} 587 588return($_[0]); 589} 590 591sub feature_avatar { 592my@val= (git_get_project_config('avatar')); 593 594return@val?@val:@_; 595} 596 597# checking HEAD file with -e is fragile if the repository was 598# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 599# and then pruned. 600sub check_head_link { 601my($dir) =@_; 602my$headfile="$dir/HEAD"; 603return((-e $headfile) || 604(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 605} 606 607sub check_export_ok { 608my($dir) =@_; 609return(check_head_link($dir) && 610(!$export_ok|| -e "$dir/$export_ok") && 611(!$export_auth_hook||$export_auth_hook->($dir))); 612} 613 614# process alternate names for backward compatibility 615# filter out unsupported (unknown) snapshot formats 616sub filter_snapshot_fmts { 617my@fmts=@_; 618 619@fmts=map{ 620exists$known_snapshot_format_aliases{$_} ? 621$known_snapshot_format_aliases{$_} :$_}@fmts; 622@fmts=grep{ 623exists$known_snapshot_formats{$_} && 624!$known_snapshot_formats{$_}{'disabled'}}@fmts; 625} 626 627# If it is set to code reference, it is code that it is to be run once per 628# request, allowing updating configurations that change with each request, 629# while running other code in config file only once. 630# 631# Otherwise, if it is false then gitweb would process config file only once; 632# if it is true then gitweb config would be run for each request. 633our$per_request_config=1; 634 635our($GITWEB_CONFIG,$GITWEB_CONFIG_SYSTEM); 636sub evaluate_gitweb_config { 637our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 638our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 639# die if there are errors parsing config file 640if(-e $GITWEB_CONFIG) { 641do$GITWEB_CONFIG; 642die$@if$@; 643}elsif(-e $GITWEB_CONFIG_SYSTEM) { 644do$GITWEB_CONFIG_SYSTEM; 645die$@if$@; 646} 647} 648 649# Get loadavg of system, to compare against $maxload. 650# Currently it requires '/proc/loadavg' present to get loadavg; 651# if it is not present it returns 0, which means no load checking. 652sub get_loadavg { 653if( -e '/proc/loadavg'){ 654open my$fd,'<','/proc/loadavg' 655orreturn0; 656my@load=split(/\s+/,scalar<$fd>); 657close$fd; 658 659# The first three columns measure CPU and IO utilization of the last one, 660# five, and 10 minute periods. The fourth column shows the number of 661# currently running processes and the total number of processes in the m/n 662# format. The last column displays the last process ID used. 663return$load[0] ||0; 664} 665# additional checks for load average should go here for things that don't export 666# /proc/loadavg 667 668return0; 669} 670 671# version of the core git binary 672our$git_version; 673sub evaluate_git_version { 674our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 675$number_of_git_cmds++; 676} 677 678sub check_loadavg { 679if(defined$maxload&& get_loadavg() >$maxload) { 680 die_error(503,"The load average on the server is too high"); 681} 682} 683 684# ====================================================================== 685# input validation and dispatch 686 687# input parameters can be collected from a variety of sources (presently, CGI 688# and PATH_INFO), so we define an %input_params hash that collects them all 689# together during validation: this allows subsequent uses (e.g. href()) to be 690# agnostic of the parameter origin 691 692our%input_params= (); 693 694# input parameters are stored with the long parameter name as key. This will 695# also be used in the href subroutine to convert parameters to their CGI 696# equivalent, and since the href() usage is the most frequent one, we store 697# the name -> CGI key mapping here, instead of the reverse. 698# 699# XXX: Warning: If you touch this, check the search form for updating, 700# too. 701 702our@cgi_param_mapping= ( 703 project =>"p", 704 action =>"a", 705 file_name =>"f", 706 file_parent =>"fp", 707 hash =>"h", 708 hash_parent =>"hp", 709 hash_base =>"hb", 710 hash_parent_base =>"hpb", 711 page =>"pg", 712 order =>"o", 713 searchtext =>"s", 714 searchtype =>"st", 715 snapshot_format =>"sf", 716 extra_options =>"opt", 717 search_use_regexp =>"sr", 718# this must be last entry (for manipulation from JavaScript) 719 javascript =>"js" 720); 721our%cgi_param_mapping=@cgi_param_mapping; 722 723# we will also need to know the possible actions, for validation 724our%actions= ( 725"blame"=> \&git_blame, 726"blame_incremental"=> \&git_blame_incremental, 727"blame_data"=> \&git_blame_data, 728"blobdiff"=> \&git_blobdiff, 729"blobdiff_plain"=> \&git_blobdiff_plain, 730"blob"=> \&git_blob, 731"blob_plain"=> \&git_blob_plain, 732"commitdiff"=> \&git_commitdiff, 733"commitdiff_plain"=> \&git_commitdiff_plain, 734"commit"=> \&git_commit, 735"forks"=> \&git_forks, 736"heads"=> \&git_heads, 737"history"=> \&git_history, 738"log"=> \&git_log, 739"patch"=> \&git_patch, 740"patches"=> \&git_patches, 741"remotes"=> \&git_remotes, 742"rss"=> \&git_rss, 743"atom"=> \&git_atom, 744"search"=> \&git_search, 745"search_help"=> \&git_search_help, 746"shortlog"=> \&git_shortlog, 747"summary"=> \&git_summary, 748"tag"=> \&git_tag, 749"tags"=> \&git_tags, 750"tree"=> \&git_tree, 751"snapshot"=> \&git_snapshot, 752"object"=> \&git_object, 753# those below don't need $project 754"opml"=> \&git_opml, 755"project_list"=> \&git_project_list, 756"project_index"=> \&git_project_index, 757); 758 759# finally, we have the hash of allowed extra_options for the commands that 760# allow them 761our%allowed_options= ( 762"--no-merges"=> [qw(rss atom log shortlog history)], 763); 764 765# fill %input_params with the CGI parameters. All values except for 'opt' 766# should be single values, but opt can be an array. We should probably 767# build an array of parameters that can be multi-valued, but since for the time 768# being it's only this one, we just single it out 769sub evaluate_query_params { 770our$cgi; 771 772while(my($name,$symbol) =each%cgi_param_mapping) { 773if($symboleq'opt') { 774$input_params{$name} = [$cgi->param($symbol) ]; 775}else{ 776$input_params{$name} =$cgi->param($symbol); 777} 778} 779} 780 781# now read PATH_INFO and update the parameter list for missing parameters 782sub evaluate_path_info { 783return ifdefined$input_params{'project'}; 784return if!$path_info; 785$path_info=~ s,^/+,,; 786return if!$path_info; 787 788# find which part of PATH_INFO is project 789my$project=$path_info; 790$project=~ s,/+$,,; 791while($project&& !check_head_link("$projectroot/$project")) { 792$project=~ s,/*[^/]*$,,; 793} 794return unless$project; 795$input_params{'project'} =$project; 796 797# do not change any parameters if an action is given using the query string 798return if$input_params{'action'}; 799$path_info=~ s,^\Q$project\E/*,,; 800 801# next, check if we have an action 802my$action=$path_info; 803$action=~ s,/.*$,,; 804if(exists$actions{$action}) { 805$path_info=~ s,^$action/*,,; 806$input_params{'action'} =$action; 807} 808 809# list of actions that want hash_base instead of hash, but can have no 810# pathname (f) parameter 811my@wants_base= ( 812'tree', 813'history', 814); 815 816# we want to catch, among others 817# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 818my($parentrefname,$parentpathname,$refname,$pathname) = 819($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?([^:]+?)?(?::(.+))?$/); 820 821# first, analyze the 'current' part 822if(defined$pathname) { 823# we got "branch:filename" or "branch:dir/" 824# we could use git_get_type(branch:pathname), but: 825# - it needs $git_dir 826# - it does a git() call 827# - the convention of terminating directories with a slash 828# makes it superfluous 829# - embedding the action in the PATH_INFO would make it even 830# more superfluous 831$pathname=~ s,^/+,,; 832if(!$pathname||substr($pathname, -1)eq"/") { 833$input_params{'action'} ||="tree"; 834$pathname=~ s,/$,,; 835}else{ 836# the default action depends on whether we had parent info 837# or not 838if($parentrefname) { 839$input_params{'action'} ||="blobdiff_plain"; 840}else{ 841$input_params{'action'} ||="blob_plain"; 842} 843} 844$input_params{'hash_base'} ||=$refname; 845$input_params{'file_name'} ||=$pathname; 846}elsif(defined$refname) { 847# we got "branch". In this case we have to choose if we have to 848# set hash or hash_base. 849# 850# Most of the actions without a pathname only want hash to be 851# set, except for the ones specified in @wants_base that want 852# hash_base instead. It should also be noted that hand-crafted 853# links having 'history' as an action and no pathname or hash 854# set will fail, but that happens regardless of PATH_INFO. 855if(defined$parentrefname) { 856# if there is parent let the default be 'shortlog' action 857# (for http://git.example.com/repo.git/A..B links); if there 858# is no parent, dispatch will detect type of object and set 859# action appropriately if required (if action is not set) 860$input_params{'action'} ||="shortlog"; 861} 862if($input_params{'action'} && 863grep{$_eq$input_params{'action'} }@wants_base) { 864$input_params{'hash_base'} ||=$refname; 865}else{ 866$input_params{'hash'} ||=$refname; 867} 868} 869 870# next, handle the 'parent' part, if present 871if(defined$parentrefname) { 872# a missing pathspec defaults to the 'current' filename, allowing e.g. 873# someproject/blobdiff/oldrev..newrev:/filename 874if($parentpathname) { 875$parentpathname=~ s,^/+,,; 876$parentpathname=~ s,/$,,; 877$input_params{'file_parent'} ||=$parentpathname; 878}else{ 879$input_params{'file_parent'} ||=$input_params{'file_name'}; 880} 881# we assume that hash_parent_base is wanted if a path was specified, 882# or if the action wants hash_base instead of hash 883if(defined$input_params{'file_parent'} || 884grep{$_eq$input_params{'action'} }@wants_base) { 885$input_params{'hash_parent_base'} ||=$parentrefname; 886}else{ 887$input_params{'hash_parent'} ||=$parentrefname; 888} 889} 890 891# for the snapshot action, we allow URLs in the form 892# $project/snapshot/$hash.ext 893# where .ext determines the snapshot and gets removed from the 894# passed $refname to provide the $hash. 895# 896# To be able to tell that $refname includes the format extension, we 897# require the following two conditions to be satisfied: 898# - the hash input parameter MUST have been set from the $refname part 899# of the URL (i.e. they must be equal) 900# - the snapshot format MUST NOT have been defined already (e.g. from 901# CGI parameter sf) 902# It's also useless to try any matching unless $refname has a dot, 903# so we check for that too 904if(defined$input_params{'action'} && 905$input_params{'action'}eq'snapshot'&& 906defined$refname&&index($refname,'.') != -1&& 907$refnameeq$input_params{'hash'} && 908!defined$input_params{'snapshot_format'}) { 909# We loop over the known snapshot formats, checking for 910# extensions. Allowed extensions are both the defined suffix 911# (which includes the initial dot already) and the snapshot 912# format key itself, with a prepended dot 913while(my($fmt,$opt) =each%known_snapshot_formats) { 914my$hash=$refname; 915unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 916next; 917} 918my$sfx=$1; 919# a valid suffix was found, so set the snapshot format 920# and reset the hash parameter 921$input_params{'snapshot_format'} =$fmt; 922$input_params{'hash'} =$hash; 923# we also set the format suffix to the one requested 924# in the URL: this way a request for e.g. .tgz returns 925# a .tgz instead of a .tar.gz 926$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 927last; 928} 929} 930} 931 932our($action,$project,$file_name,$file_parent,$hash,$hash_parent,$hash_base, 933$hash_parent_base,@extra_options,$page,$searchtype,$search_use_regexp, 934$searchtext,$search_regexp); 935sub evaluate_and_validate_params { 936our$action=$input_params{'action'}; 937if(defined$action) { 938if(!validate_action($action)) { 939 die_error(400,"Invalid action parameter"); 940} 941} 942 943# parameters which are pathnames 944our$project=$input_params{'project'}; 945if(defined$project) { 946if(!validate_project($project)) { 947undef$project; 948 die_error(404,"No such project"); 949} 950} 951 952our$file_name=$input_params{'file_name'}; 953if(defined$file_name) { 954if(!validate_pathname($file_name)) { 955 die_error(400,"Invalid file parameter"); 956} 957} 958 959our$file_parent=$input_params{'file_parent'}; 960if(defined$file_parent) { 961if(!validate_pathname($file_parent)) { 962 die_error(400,"Invalid file parent parameter"); 963} 964} 965 966# parameters which are refnames 967our$hash=$input_params{'hash'}; 968if(defined$hash) { 969if(!validate_refname($hash)) { 970 die_error(400,"Invalid hash parameter"); 971} 972} 973 974our$hash_parent=$input_params{'hash_parent'}; 975if(defined$hash_parent) { 976if(!validate_refname($hash_parent)) { 977 die_error(400,"Invalid hash parent parameter"); 978} 979} 980 981our$hash_base=$input_params{'hash_base'}; 982if(defined$hash_base) { 983if(!validate_refname($hash_base)) { 984 die_error(400,"Invalid hash base parameter"); 985} 986} 987 988our@extra_options= @{$input_params{'extra_options'}}; 989# @extra_options is always defined, since it can only be (currently) set from 990# CGI, and $cgi->param() returns the empty array in array context if the param 991# is not set 992foreachmy$opt(@extra_options) { 993if(not exists$allowed_options{$opt}) { 994 die_error(400,"Invalid option parameter"); 995} 996if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 997 die_error(400,"Invalid option parameter for this action"); 998} 999}10001001our$hash_parent_base=$input_params{'hash_parent_base'};1002if(defined$hash_parent_base) {1003if(!validate_refname($hash_parent_base)) {1004 die_error(400,"Invalid hash parent base parameter");1005}1006}10071008# other parameters1009our$page=$input_params{'page'};1010if(defined$page) {1011if($page=~m/[^0-9]/) {1012 die_error(400,"Invalid page parameter");1013}1014}10151016our$searchtype=$input_params{'searchtype'};1017if(defined$searchtype) {1018if($searchtype=~m/[^a-z]/) {1019 die_error(400,"Invalid searchtype parameter");1020}1021}10221023our$search_use_regexp=$input_params{'search_use_regexp'};10241025our$searchtext=$input_params{'searchtext'};1026our$search_regexp;1027if(defined$searchtext) {1028if(length($searchtext) <2) {1029 die_error(403,"At least two characters are required for search parameter");1030}1031$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext;1032}1033}10341035# path to the current git repository1036our$git_dir;1037sub evaluate_git_dir {1038our$git_dir="$projectroot/$project"if$project;1039}10401041our(@snapshot_fmts,$git_avatar);1042sub configure_gitweb_features {1043# list of supported snapshot formats1044our@snapshot_fmts= gitweb_get_feature('snapshot');1045@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts);10461047# check that the avatar feature is set to a known provider name,1048# and for each provider check if the dependencies are satisfied.1049# if the provider name is invalid or the dependencies are not met,1050# reset $git_avatar to the empty string.1051our($git_avatar) = gitweb_get_feature('avatar');1052if($git_avatareq'gravatar') {1053$git_avatar=''unless(eval{require Digest::MD5;1; });1054}elsif($git_avatareq'picon') {1055# no dependencies1056}else{1057$git_avatar='';1058}1059}10601061# custom error handler: 'die <message>' is Internal Server Error1062sub handle_errors_html {1063my$msg=shift;# it is already HTML escaped10641065# to avoid infinite loop where error occurs in die_error,1066# change handler to default handler, disabling handle_errors_html1067 set_message("Error occured when inside die_error:\n$msg");10681069# you cannot jump out of die_error when called as error handler;1070# the subroutine set via CGI::Carp::set_message is called _after_1071# HTTP headers are already written, so it cannot write them itself1072 die_error(undef,undef,$msg, -error_handler =>1, -no_http_header =>1);1073}1074set_message(\&handle_errors_html);10751076# dispatch1077sub dispatch {1078if(!defined$action) {1079if(defined$hash) {1080$action= git_get_type($hash);1081}elsif(defined$hash_base&&defined$file_name) {1082$action= git_get_type("$hash_base:$file_name");1083}elsif(defined$project) {1084$action='summary';1085}else{1086$action='project_list';1087}1088}1089if(!defined($actions{$action})) {1090 die_error(400,"Unknown action");1091}1092if($action!~m/^(?:opml|project_list|project_index)$/&&1093!$project) {1094 die_error(400,"Project needed");1095}1096$actions{$action}->();1097}10981099sub reset_timer {1100our$t0= [ gettimeofday() ]1101ifdefined$t0;1102our$number_of_git_cmds=0;1103}11041105our$first_request=1;1106sub run_request {1107 reset_timer();11081109 evaluate_uri();1110if($first_request) {1111 evaluate_gitweb_config();1112 evaluate_git_version();1113}1114if($per_request_config) {1115if(ref($per_request_config)eq'CODE') {1116$per_request_config->();1117}elsif(!$first_request) {1118 evaluate_gitweb_config();1119}1120}1121 check_loadavg();11221123# $projectroot and $projects_list might be set in gitweb config file1124$projects_list||=$projectroot;11251126 evaluate_query_params();1127 evaluate_path_info();1128 evaluate_and_validate_params();1129 evaluate_git_dir();11301131 configure_gitweb_features();11321133 dispatch();1134}11351136our$is_last_request=sub{1};1137our($pre_dispatch_hook,$post_dispatch_hook,$pre_listen_hook);1138our$CGI='CGI';1139our$cgi;1140sub configure_as_fcgi {1141require CGI::Fast;1142our$CGI='CGI::Fast';11431144my$request_number=0;1145# let each child service 100 requests1146our$is_last_request=sub{ ++$request_number>100};1147}1148sub evaluate_argv {1149my$script_name=$ENV{'SCRIPT_NAME'} ||$ENV{'SCRIPT_FILENAME'} || __FILE__;1150 configure_as_fcgi()1151if$script_name=~/\.fcgi$/;11521153return unless(@ARGV);11541155require Getopt::Long;1156 Getopt::Long::GetOptions(1157'fastcgi|fcgi|f'=> \&configure_as_fcgi,1158'nproc|n=i'=>sub{1159my($arg,$val) =@_;1160return unlesseval{require FCGI::ProcManager;1; };1161my$proc_manager= FCGI::ProcManager->new({1162 n_processes =>$val,1163});1164our$pre_listen_hook=sub{$proc_manager->pm_manage() };1165our$pre_dispatch_hook=sub{$proc_manager->pm_pre_dispatch() };1166our$post_dispatch_hook=sub{$proc_manager->pm_post_dispatch() };1167},1168);1169}11701171sub run {1172 evaluate_argv();11731174$first_request=1;1175$pre_listen_hook->()1176if$pre_listen_hook;11771178 REQUEST:1179while($cgi=$CGI->new()) {1180$pre_dispatch_hook->()1181if$pre_dispatch_hook;11821183 run_request();11841185$post_dispatch_hook->()1186if$post_dispatch_hook;1187$first_request=0;11881189last REQUEST if($is_last_request->());1190}11911192 DONE_GITWEB:11931;1194}11951196run();11971198if(defined caller) {1199# wrapped in a subroutine processing requests,1200# e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI1201return;1202}else{1203# pure CGI script, serving single request1204exit;1205}12061207## ======================================================================1208## action links12091210# possible values of extra options1211# -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)1212# -replay => 1 - start from a current view (replay with modifications)1213# -path_info => 0|1 - don't use/use path_info URL (if possible)1214# -anchor => ANCHOR - add #ANCHOR to end of URL, implies -replay if used alone1215sub href {1216my%params=@_;1217# default is to use -absolute url() i.e. $my_uri1218my$href=$params{-full} ?$my_url:$my_uri;12191220# implicit -replay, must be first of implicit params1221$params{-replay} =1if(keys%params==1&&$params{-anchor});12221223$params{'project'} =$projectunlessexists$params{'project'};12241225if($params{-replay}) {1226while(my($name,$symbol) =each%cgi_param_mapping) {1227if(!exists$params{$name}) {1228$params{$name} =$input_params{$name};1229}1230}1231}12321233my$use_pathinfo= gitweb_check_feature('pathinfo');1234if(defined$params{'project'} &&1235(exists$params{-path_info} ?$params{-path_info} :$use_pathinfo)) {1236# try to put as many parameters as possible in PATH_INFO:1237# - project name1238# - action1239# - hash_parent or hash_parent_base:/file_parent1240# - hash or hash_base:/filename1241# - the snapshot_format as an appropriate suffix12421243# When the script is the root DirectoryIndex for the domain,1244# $href here would be something like http://gitweb.example.com/1245# Thus, we strip any trailing / from $href, to spare us double1246# slashes in the final URL1247$href=~ s,/$,,;12481249# Then add the project name, if present1250$href.="/".esc_path_info($params{'project'});1251delete$params{'project'};12521253# since we destructively absorb parameters, we keep this1254# boolean that remembers if we're handling a snapshot1255my$is_snapshot=$params{'action'}eq'snapshot';12561257# Summary just uses the project path URL, any other action is1258# added to the URL1259if(defined$params{'action'}) {1260$href.="/".esc_path_info($params{'action'})1261unless$params{'action'}eq'summary';1262delete$params{'action'};1263}12641265# Next, we put hash_parent_base:/file_parent..hash_base:/file_name,1266# stripping nonexistent or useless pieces1267$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'}1268||$params{'hash_parent'} ||$params{'hash'});1269if(defined$params{'hash_base'}) {1270if(defined$params{'hash_parent_base'}) {1271$href.= esc_path_info($params{'hash_parent_base'});1272# skip the file_parent if it's the same as the file_name1273if(defined$params{'file_parent'}) {1274if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) {1275delete$params{'file_parent'};1276}elsif($params{'file_parent'} !~/\.\./) {1277$href.=":/".esc_path_info($params{'file_parent'});1278delete$params{'file_parent'};1279}1280}1281$href.="..";1282delete$params{'hash_parent'};1283delete$params{'hash_parent_base'};1284}elsif(defined$params{'hash_parent'}) {1285$href.= esc_path_info($params{'hash_parent'})."..";1286delete$params{'hash_parent'};1287}12881289$href.= esc_path_info($params{'hash_base'});1290if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) {1291$href.=":/".esc_path_info($params{'file_name'});1292delete$params{'file_name'};1293}1294delete$params{'hash'};1295delete$params{'hash_base'};1296}elsif(defined$params{'hash'}) {1297$href.= esc_path_info($params{'hash'});1298delete$params{'hash'};1299}13001301# If the action was a snapshot, we can absorb the1302# snapshot_format parameter too1303if($is_snapshot) {1304my$fmt=$params{'snapshot_format'};1305# snapshot_format should always be defined when href()1306# is called, but just in case some code forgets, we1307# fall back to the default1308$fmt||=$snapshot_fmts[0];1309$href.=$known_snapshot_formats{$fmt}{'suffix'};1310delete$params{'snapshot_format'};1311}1312}13131314# now encode the parameters explicitly1315my@result= ();1316for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1317my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1318if(defined$params{$name}) {1319if(ref($params{$name})eq"ARRAY") {1320foreachmy$par(@{$params{$name}}) {1321push@result,$symbol."=". esc_param($par);1322}1323}else{1324push@result,$symbol."=". esc_param($params{$name});1325}1326}1327}1328$href.="?".join(';',@result)ifscalar@result;13291330# final transformation: trailing spaces must be escaped (URI-encoded)1331$href=~s/(\s+)$/CGI::escape($1)/e;13321333if($params{-anchor}) {1334$href.="#".esc_param($params{-anchor});1335}13361337return$href;1338}133913401341## ======================================================================1342## validation, quoting/unquoting and escaping13431344sub validate_action {1345my$input=shift||returnundef;1346returnundefunlessexists$actions{$input};1347return$input;1348}13491350sub validate_project {1351my$input=shift||returnundef;1352if(!validate_pathname($input) ||1353!(-d "$projectroot/$input") ||1354!check_export_ok("$projectroot/$input") ||1355($strict_export&& !project_in_list($input))) {1356returnundef;1357}else{1358return$input;1359}1360}13611362sub validate_pathname {1363my$input=shift||returnundef;13641365# no '.' or '..' as elements of path, i.e. no '.' nor '..'1366# at the beginning, at the end, and between slashes.1367# also this catches doubled slashes1368if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1369returnundef;1370}1371# no null characters1372if($input=~m!\0!) {1373returnundef;1374}1375return$input;1376}13771378sub validate_refname {1379my$input=shift||returnundef;13801381# textual hashes are O.K.1382if($input=~m/^[0-9a-fA-F]{40}$/) {1383return$input;1384}1385# it must be correct pathname1386$input= validate_pathname($input)1387orreturnundef;1388# restrictions on ref name according to git-check-ref-format1389if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1390returnundef;1391}1392return$input;1393}13941395# decode sequences of octets in utf8 into Perl's internal form,1396# which is utf-8 with utf8 flag set if needed. gitweb writes out1397# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1398sub to_utf8 {1399my$str=shift;1400returnundefunlessdefined$str;1401if(utf8::valid($str)) {1402 utf8::decode($str);1403return$str;1404}else{1405return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1406}1407}14081409# quote unsafe chars, but keep the slash, even when it's not1410# correct, but quoted slashes look too horrible in bookmarks1411sub esc_param {1412my$str=shift;1413returnundefunlessdefined$str;1414$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1415$str=~s/ /\+/g;1416return$str;1417}14181419# the quoting rules for path_info fragment are slightly different1420sub esc_path_info {1421my$str=shift;1422returnundefunlessdefined$str;14231424# path_info doesn't treat '+' as space (specially), but '?' must be escaped1425$str=~s/([^A-Za-z0-9\-_.~();\/;:@&= +]+)/CGI::escape($1)/eg;14261427return$str;1428}14291430# quote unsafe chars in whole URL, so some characters cannot be quoted1431sub esc_url {1432my$str=shift;1433returnundefunlessdefined$str;1434$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg;1435$str=~s/ /\+/g;1436return$str;1437}14381439# quote unsafe characters in HTML attributes1440sub esc_attr {14411442# for XHTML conformance escaping '"' to '"' is not enough1443return esc_html(@_);1444}14451446# replace invalid utf8 character with SUBSTITUTION sequence1447sub esc_html {1448my$str=shift;1449my%opts=@_;14501451returnundefunlessdefined$str;14521453$str= to_utf8($str);1454$str=$cgi->escapeHTML($str);1455if($opts{'-nbsp'}) {1456$str=~s/ / /g;1457}1458$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1459return$str;1460}14611462# quote control characters and escape filename to HTML1463sub esc_path {1464my$str=shift;1465my%opts=@_;14661467returnundefunlessdefined$str;14681469$str= to_utf8($str);1470$str=$cgi->escapeHTML($str);1471if($opts{'-nbsp'}) {1472$str=~s/ / /g;1473}1474$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1475return$str;1476}14771478# Make control characters "printable", using character escape codes (CEC)1479sub quot_cec {1480my$cntrl=shift;1481my%opts=@_;1482my%es= (# character escape codes, aka escape sequences1483"\t"=>'\t',# tab (HT)1484"\n"=>'\n',# line feed (LF)1485"\r"=>'\r',# carrige return (CR)1486"\f"=>'\f',# form feed (FF)1487"\b"=>'\b',# backspace (BS)1488"\a"=>'\a',# alarm (bell) (BEL)1489"\e"=>'\e',# escape (ESC)1490"\013"=>'\v',# vertical tab (VT)1491"\000"=>'\0',# nul character (NUL)1492);1493my$chr= ( (exists$es{$cntrl})1494?$es{$cntrl}1495:sprintf('\%2x',ord($cntrl)) );1496if($opts{-nohtml}) {1497return$chr;1498}else{1499return"<span class=\"cntrl\">$chr</span>";1500}1501}15021503# Alternatively use unicode control pictures codepoints,1504# Unicode "printable representation" (PR)1505sub quot_upr {1506my$cntrl=shift;1507my%opts=@_;15081509my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1510if($opts{-nohtml}) {1511return$chr;1512}else{1513return"<span class=\"cntrl\">$chr</span>";1514}1515}15161517# git may return quoted and escaped filenames1518sub unquote {1519my$str=shift;15201521sub unq {1522my$seq=shift;1523my%es= (# character escape codes, aka escape sequences1524't'=>"\t",# tab (HT, TAB)1525'n'=>"\n",# newline (NL)1526'r'=>"\r",# return (CR)1527'f'=>"\f",# form feed (FF)1528'b'=>"\b",# backspace (BS)1529'a'=>"\a",# alarm (bell) (BEL)1530'e'=>"\e",# escape (ESC)1531'v'=>"\013",# vertical tab (VT)1532);15331534if($seq=~m/^[0-7]{1,3}$/) {1535# octal char sequence1536returnchr(oct($seq));1537}elsif(exists$es{$seq}) {1538# C escape sequence, aka character escape code1539return$es{$seq};1540}1541# quoted ordinary character1542return$seq;1543}15441545if($str=~m/^"(.*)"$/) {1546# needs unquoting1547$str=$1;1548$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1549}1550return$str;1551}15521553# escape tabs (convert tabs to spaces)1554sub untabify {1555my$line=shift;15561557while((my$pos=index($line,"\t")) != -1) {1558if(my$count= (8- ($pos%8))) {1559my$spaces=' ' x $count;1560$line=~s/\t/$spaces/;1561}1562}15631564return$line;1565}15661567sub project_in_list {1568my$project=shift;1569my@list= git_get_projects_list();1570return@list&&scalar(grep{$_->{'path'}eq$project}@list);1571}15721573## ----------------------------------------------------------------------1574## HTML aware string manipulation15751576# Try to chop given string on a word boundary between position1577# $len and $len+$add_len. If there is no word boundary there,1578# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1579# (marking chopped part) would be longer than given string.1580sub chop_str {1581my$str=shift;1582my$len=shift;1583my$add_len=shift||10;1584my$where=shift||'right';# 'left' | 'center' | 'right'15851586# Make sure perl knows it is utf8 encoded so we don't1587# cut in the middle of a utf8 multibyte char.1588$str= to_utf8($str);15891590# allow only $len chars, but don't cut a word if it would fit in $add_len1591# if it doesn't fit, cut it if it's still longer than the dots we would add1592# remove chopped character entities entirely15931594# when chopping in the middle, distribute $len into left and right part1595# return early if chopping wouldn't make string shorter1596if($whereeq'center') {1597return$strif($len+5>=length($str));# filler is length 51598$len=int($len/2);1599}else{1600return$strif($len+4>=length($str));# filler is length 41601}16021603# regexps: ending and beginning with word part up to $add_len1604my$endre=qr/.{$len}\w{0,$add_len}/;1605my$begre=qr/\w{0,$add_len}.{$len}/;16061607if($whereeq'left') {1608$str=~m/^(.*?)($begre)$/;1609my($lead,$body) = ($1,$2);1610if(length($lead) >4) {1611$lead=" ...";1612}1613return"$lead$body";16141615}elsif($whereeq'center') {1616$str=~m/^($endre)(.*)$/;1617my($left,$str) = ($1,$2);1618$str=~m/^(.*?)($begre)$/;1619my($mid,$right) = ($1,$2);1620if(length($mid) >5) {1621$mid=" ... ";1622}1623return"$left$mid$right";16241625}else{1626$str=~m/^($endre)(.*)$/;1627my$body=$1;1628my$tail=$2;1629if(length($tail) >4) {1630$tail="... ";1631}1632return"$body$tail";1633}1634}16351636# takes the same arguments as chop_str, but also wraps a <span> around the1637# result with a title attribute if it does get chopped. Additionally, the1638# string is HTML-escaped.1639sub chop_and_escape_str {1640my($str) =@_;16411642my$chopped= chop_str(@_);1643if($choppedeq$str) {1644return esc_html($chopped);1645}else{1646$str=~s/[[:cntrl:]]/?/g;1647return$cgi->span({-title=>$str}, esc_html($chopped));1648}1649}16501651## ----------------------------------------------------------------------1652## functions returning short strings16531654# CSS class for given age value (in seconds)1655sub age_class {1656my$age=shift;16571658if(!defined$age) {1659return"noage";1660}elsif($age<60*60*2) {1661return"age0";1662}elsif($age<60*60*24*2) {1663return"age1";1664}else{1665return"age2";1666}1667}16681669# convert age in seconds to "nn units ago" string1670sub age_string {1671my$age=shift;1672my$age_str;16731674if($age>60*60*24*365*2) {1675$age_str= (int$age/60/60/24/365);1676$age_str.=" years ago";1677}elsif($age>60*60*24*(365/12)*2) {1678$age_str=int$age/60/60/24/(365/12);1679$age_str.=" months ago";1680}elsif($age>60*60*24*7*2) {1681$age_str=int$age/60/60/24/7;1682$age_str.=" weeks ago";1683}elsif($age>60*60*24*2) {1684$age_str=int$age/60/60/24;1685$age_str.=" days ago";1686}elsif($age>60*60*2) {1687$age_str=int$age/60/60;1688$age_str.=" hours ago";1689}elsif($age>60*2) {1690$age_str=int$age/60;1691$age_str.=" min ago";1692}elsif($age>2) {1693$age_str=int$age;1694$age_str.=" sec ago";1695}else{1696$age_str.=" right now";1697}1698return$age_str;1699}17001701useconstant{1702 S_IFINVALID =>0030000,1703 S_IFGITLINK =>0160000,1704};17051706# submodule/subproject, a commit object reference1707sub S_ISGITLINK {1708my$mode=shift;17091710return(($mode& S_IFMT) == S_IFGITLINK)1711}17121713# convert file mode in octal to symbolic file mode string1714sub mode_str {1715my$mode=oct shift;17161717if(S_ISGITLINK($mode)) {1718return'm---------';1719}elsif(S_ISDIR($mode& S_IFMT)) {1720return'drwxr-xr-x';1721}elsif(S_ISLNK($mode)) {1722return'lrwxrwxrwx';1723}elsif(S_ISREG($mode)) {1724# git cares only about the executable bit1725if($mode& S_IXUSR) {1726return'-rwxr-xr-x';1727}else{1728return'-rw-r--r--';1729};1730}else{1731return'----------';1732}1733}17341735# convert file mode in octal to file type string1736sub file_type {1737my$mode=shift;17381739if($mode!~m/^[0-7]+$/) {1740return$mode;1741}else{1742$mode=oct$mode;1743}17441745if(S_ISGITLINK($mode)) {1746return"submodule";1747}elsif(S_ISDIR($mode& S_IFMT)) {1748return"directory";1749}elsif(S_ISLNK($mode)) {1750return"symlink";1751}elsif(S_ISREG($mode)) {1752return"file";1753}else{1754return"unknown";1755}1756}17571758# convert file mode in octal to file type description string1759sub file_type_long {1760my$mode=shift;17611762if($mode!~m/^[0-7]+$/) {1763return$mode;1764}else{1765$mode=oct$mode;1766}17671768if(S_ISGITLINK($mode)) {1769return"submodule";1770}elsif(S_ISDIR($mode& S_IFMT)) {1771return"directory";1772}elsif(S_ISLNK($mode)) {1773return"symlink";1774}elsif(S_ISREG($mode)) {1775if($mode& S_IXUSR) {1776return"executable";1777}else{1778return"file";1779};1780}else{1781return"unknown";1782}1783}178417851786## ----------------------------------------------------------------------1787## functions returning short HTML fragments, or transforming HTML fragments1788## which don't belong to other sections17891790# format line of commit message.1791sub format_log_line_html {1792my$line=shift;17931794$line= esc_html($line, -nbsp=>1);1795$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1796$cgi->a({-href => href(action=>"object", hash=>$1),1797-class=>"text"},$1);1798}eg;17991800return$line;1801}18021803# format marker of refs pointing to given object18041805# the destination action is chosen based on object type and current context:1806# - for annotated tags, we choose the tag view unless it's the current view1807# already, in which case we go to shortlog view1808# - for other refs, we keep the current view if we're in history, shortlog or1809# log view, and select shortlog otherwise1810sub format_ref_marker {1811my($refs,$id) =@_;1812my$markers='';18131814if(defined$refs->{$id}) {1815foreachmy$ref(@{$refs->{$id}}) {1816# this code exploits the fact that non-lightweight tags are the1817# only indirect objects, and that they are the only objects for which1818# we want to use tag instead of shortlog as action1819my($type,$name) =qw();1820my$indirect= ($ref=~s/\^\{\}$//);1821# e.g. tags/v2.6.11 or heads/next1822if($ref=~m!^(.*?)s?/(.*)$!) {1823$type=$1;1824$name=$2;1825}else{1826$type="ref";1827$name=$ref;1828}18291830my$class=$type;1831$class.=" indirect"if$indirect;18321833my$dest_action="shortlog";18341835if($indirect) {1836$dest_action="tag"unless$actioneq"tag";1837}elsif($action=~/^(history|(short)?log)$/) {1838$dest_action=$action;1839}18401841my$dest="";1842$dest.="refs/"unless$ref=~ m!^refs/!;1843$dest.=$ref;18441845my$link=$cgi->a({1846-href => href(1847 action=>$dest_action,1848 hash=>$dest1849)},$name);18501851$markers.=" <span class=\"".esc_attr($class)."\"title=\"".esc_attr($ref)."\">".1852$link."</span>";1853}1854}18551856if($markers) {1857return' <span class="refs">'.$markers.'</span>';1858}else{1859return"";1860}1861}18621863# format, perhaps shortened and with markers, title line1864sub format_subject_html {1865my($long,$short,$href,$extra) =@_;1866$extra=''unlessdefined($extra);18671868if(length($short) <length($long)) {1869$long=~s/[[:cntrl:]]/?/g;1870return$cgi->a({-href =>$href, -class=>"list subject",1871-title => to_utf8($long)},1872 esc_html($short)) .$extra;1873}else{1874return$cgi->a({-href =>$href, -class=>"list subject"},1875 esc_html($long)) .$extra;1876}1877}18781879# Rather than recomputing the url for an email multiple times, we cache it1880# after the first hit. This gives a visible benefit in views where the avatar1881# for the same email is used repeatedly (e.g. shortlog).1882# The cache is shared by all avatar engines (currently gravatar only), which1883# are free to use it as preferred. Since only one avatar engine is used for any1884# given page, there's no risk for cache conflicts.1885our%avatar_cache= ();18861887# Compute the picon url for a given email, by using the picon search service over at1888# http://www.cs.indiana.edu/picons/search.html1889sub picon_url {1890my$email=lc shift;1891if(!$avatar_cache{$email}) {1892my($user,$domain) =split('@',$email);1893$avatar_cache{$email} =1894"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".1895"$domain/$user/".1896"users+domains+unknown/up/single";1897}1898return$avatar_cache{$email};1899}19001901# Compute the gravatar url for a given email, if it's not in the cache already.1902# Gravatar stores only the part of the URL before the size, since that's the1903# one computationally more expensive. This also allows reuse of the cache for1904# different sizes (for this particular engine).1905sub gravatar_url {1906my$email=lc shift;1907my$size=shift;1908$avatar_cache{$email} ||=1909"http://www.gravatar.com/avatar/".1910 Digest::MD5::md5_hex($email) ."?s=";1911return$avatar_cache{$email} .$size;1912}19131914# Insert an avatar for the given $email at the given $size if the feature1915# is enabled.1916sub git_get_avatar {1917my($email,%opts) =@_;1918my$pre_white= ($opts{-pad_before} ?" ":"");1919my$post_white= ($opts{-pad_after} ?" ":"");1920$opts{-size} ||='default';1921my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};1922my$url="";1923if($git_avatareq'gravatar') {1924$url= gravatar_url($email,$size);1925}elsif($git_avatareq'picon') {1926$url= picon_url($email);1927}1928# Other providers can be added by extending the if chain, defining $url1929# as needed. If no variant puts something in $url, we assume avatars1930# are completely disabled/unavailable.1931if($url) {1932return$pre_white.1933"<img width=\"$size\"".1934"class=\"avatar\"".1935"src=\"".esc_url($url)."\"".1936"alt=\"\"".1937"/>".$post_white;1938}else{1939return"";1940}1941}19421943sub format_search_author {1944my($author,$searchtype,$displaytext) =@_;1945my$have_search= gitweb_check_feature('search');19461947if($have_search) {1948my$performed="";1949if($searchtypeeq'author') {1950$performed="authored";1951}elsif($searchtypeeq'committer') {1952$performed="committed";1953}19541955return$cgi->a({-href => href(action=>"search", hash=>$hash,1956 searchtext=>$author,1957 searchtype=>$searchtype),class=>"list",1958 title=>"Search for commits$performedby$author"},1959$displaytext);19601961}else{1962return$displaytext;1963}1964}19651966# format the author name of the given commit with the given tag1967# the author name is chopped and escaped according to the other1968# optional parameters (see chop_str).1969sub format_author_html {1970my$tag=shift;1971my$co=shift;1972my$author= chop_and_escape_str($co->{'author_name'},@_);1973return"<$tagclass=\"author\">".1974 format_search_author($co->{'author_name'},"author",1975 git_get_avatar($co->{'author_email'}, -pad_after =>1) .1976$author) .1977"</$tag>";1978}19791980# format git diff header line, i.e. "diff --(git|combined|cc) ..."1981sub format_git_diff_header_line {1982my$line=shift;1983my$diffinfo=shift;1984my($from,$to) =@_;19851986if($diffinfo->{'nparents'}) {1987# combined diff1988$line=~s!^(diff (.*?) )"?.*$!$1!;1989if($to->{'href'}) {1990$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1991 esc_path($to->{'file'}));1992}else{# file was deleted (no href)1993$line.= esc_path($to->{'file'});1994}1995}else{1996# "ordinary" diff1997$line=~s!^(diff (.*?) )"?a/.*$!$1!;1998if($from->{'href'}) {1999$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},2000'a/'. esc_path($from->{'file'}));2001}else{# file was added (no href)2002$line.='a/'. esc_path($from->{'file'});2003}2004$line.=' ';2005if($to->{'href'}) {2006$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},2007'b/'. esc_path($to->{'file'}));2008}else{# file was deleted2009$line.='b/'. esc_path($to->{'file'});2010}2011}20122013return"<div class=\"diff header\">$line</div>\n";2014}20152016# format extended diff header line, before patch itself2017sub format_extended_diff_header_line {2018my$line=shift;2019my$diffinfo=shift;2020my($from,$to) =@_;20212022# match <path>2023if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {2024$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},2025 esc_path($from->{'file'}));2026}2027if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {2028$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},2029 esc_path($to->{'file'}));2030}2031# match single <mode>2032if($line=~m/\s(\d{6})$/) {2033$line.='<span class="info"> ('.2034 file_type_long($1) .2035')</span>';2036}2037# match <hash>2038if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {2039# can match only for combined diff2040$line='index ';2041for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2042if($from->{'href'}[$i]) {2043$line.=$cgi->a({-href=>$from->{'href'}[$i],2044-class=>"hash"},2045substr($diffinfo->{'from_id'}[$i],0,7));2046}else{2047$line.='0' x 7;2048}2049# separator2050$line.=','if($i<$diffinfo->{'nparents'} -1);2051}2052$line.='..';2053if($to->{'href'}) {2054$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2055substr($diffinfo->{'to_id'},0,7));2056}else{2057$line.='0' x 7;2058}20592060}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {2061# can match only for ordinary diff2062my($from_link,$to_link);2063if($from->{'href'}) {2064$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},2065substr($diffinfo->{'from_id'},0,7));2066}else{2067$from_link='0' x 7;2068}2069if($to->{'href'}) {2070$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2071substr($diffinfo->{'to_id'},0,7));2072}else{2073$to_link='0' x 7;2074}2075my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});2076$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;2077}20782079return$line."<br/>\n";2080}20812082# format from-file/to-file diff header2083sub format_diff_from_to_header {2084my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;2085my$line;2086my$result='';20872088$line=$from_line;2089#assert($line =~ m/^---/) if DEBUG;2090# no extra formatting for "^--- /dev/null"2091if(!$diffinfo->{'nparents'}) {2092# ordinary (single parent) diff2093if($line=~m!^--- "?a/!) {2094if($from->{'href'}) {2095$line='--- a/'.2096$cgi->a({-href=>$from->{'href'}, -class=>"path"},2097 esc_path($from->{'file'}));2098}else{2099$line='--- a/'.2100 esc_path($from->{'file'});2101}2102}2103$result.= qq!<div class="diff from_file">$line</div>\n!;21042105}else{2106# combined diff (merge commit)2107for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2108if($from->{'href'}[$i]) {2109$line='--- '.2110$cgi->a({-href=>href(action=>"blobdiff",2111 hash_parent=>$diffinfo->{'from_id'}[$i],2112 hash_parent_base=>$parents[$i],2113 file_parent=>$from->{'file'}[$i],2114 hash=>$diffinfo->{'to_id'},2115 hash_base=>$hash,2116 file_name=>$to->{'file'}),2117-class=>"path",2118-title=>"diff". ($i+1)},2119$i+1) .2120'/'.2121$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},2122 esc_path($from->{'file'}[$i]));2123}else{2124$line='--- /dev/null';2125}2126$result.= qq!<div class="diff from_file">$line</div>\n!;2127}2128}21292130$line=$to_line;2131#assert($line =~ m/^\+\+\+/) if DEBUG;2132# no extra formatting for "^+++ /dev/null"2133if($line=~m!^\+\+\+ "?b/!) {2134if($to->{'href'}) {2135$line='+++ b/'.2136$cgi->a({-href=>$to->{'href'}, -class=>"path"},2137 esc_path($to->{'file'}));2138}else{2139$line='+++ b/'.2140 esc_path($to->{'file'});2141}2142}2143$result.= qq!<div class="diff to_file">$line</div>\n!;21442145return$result;2146}21472148# create note for patch simplified by combined diff2149sub format_diff_cc_simplified {2150my($diffinfo,@parents) =@_;2151my$result='';21522153$result.="<div class=\"diff header\">".2154"diff --cc ";2155if(!is_deleted($diffinfo)) {2156$result.=$cgi->a({-href => href(action=>"blob",2157 hash_base=>$hash,2158 hash=>$diffinfo->{'to_id'},2159 file_name=>$diffinfo->{'to_file'}),2160-class=>"path"},2161 esc_path($diffinfo->{'to_file'}));2162}else{2163$result.= esc_path($diffinfo->{'to_file'});2164}2165$result.="</div>\n".# class="diff header"2166"<div class=\"diff nodifferences\">".2167"Simple merge".2168"</div>\n";# class="diff nodifferences"21692170return$result;2171}21722173# format patch (diff) line (not to be used for diff headers)2174sub format_diff_line {2175my$line=shift;2176my($from,$to) =@_;2177my$diff_class="";21782179chomp$line;21802181if($from&&$to&&ref($from->{'href'})eq"ARRAY") {2182# combined diff2183my$prefix=substr($line,0,scalar@{$from->{'href'}});2184if($line=~m/^\@{3}/) {2185$diff_class=" chunk_header";2186}elsif($line=~m/^\\/) {2187$diff_class=" incomplete";2188}elsif($prefix=~tr/+/+/) {2189$diff_class=" add";2190}elsif($prefix=~tr/-/-/) {2191$diff_class=" rem";2192}2193}else{2194# assume ordinary diff2195my$char=substr($line,0,1);2196if($chareq'+') {2197$diff_class=" add";2198}elsif($chareq'-') {2199$diff_class=" rem";2200}elsif($chareq'@') {2201$diff_class=" chunk_header";2202}elsif($chareq"\\") {2203$diff_class=" incomplete";2204}2205}2206$line= untabify($line);2207if($from&&$to&&$line=~m/^\@{2} /) {2208my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =2209$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;22102211$from_lines=0unlessdefined$from_lines;2212$to_lines=0unlessdefined$to_lines;22132214if($from->{'href'}) {2215$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",2216-class=>"list"},$from_text);2217}2218if($to->{'href'}) {2219$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",2220-class=>"list"},$to_text);2221}2222$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".2223"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2224return"<div class=\"diff$diff_class\">$line</div>\n";2225}elsif($from&&$to&&$line=~m/^\@{3}/) {2226my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;2227my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);22282229@from_text=split(' ',$ranges);2230for(my$i=0;$i<@from_text; ++$i) {2231($from_start[$i],$from_nlines[$i]) =2232(split(',',substr($from_text[$i],1)),0);2233}22342235$to_text=pop@from_text;2236$to_start=pop@from_start;2237$to_nlines=pop@from_nlines;22382239$line="<span class=\"chunk_info\">$prefix";2240for(my$i=0;$i<@from_text; ++$i) {2241if($from->{'href'}[$i]) {2242$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",2243-class=>"list"},$from_text[$i]);2244}else{2245$line.=$from_text[$i];2246}2247$line.=" ";2248}2249if($to->{'href'}) {2250$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",2251-class=>"list"},$to_text);2252}else{2253$line.=$to_text;2254}2255$line.="$prefix</span>".2256"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2257return"<div class=\"diff$diff_class\">$line</div>\n";2258}2259return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";2260}22612262# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",2263# linked. Pass the hash of the tree/commit to snapshot.2264sub format_snapshot_links {2265my($hash) =@_;2266my$num_fmts=@snapshot_fmts;2267if($num_fmts>1) {2268# A parenthesized list of links bearing format names.2269# e.g. "snapshot (_tar.gz_ _zip_)"2270return"snapshot (".join(' ',map2271$cgi->a({2272-href => href(2273 action=>"snapshot",2274 hash=>$hash,2275 snapshot_format=>$_2276)2277},$known_snapshot_formats{$_}{'display'})2278,@snapshot_fmts) .")";2279}elsif($num_fmts==1) {2280# A single "snapshot" link whose tooltip bears the format name.2281# i.e. "_snapshot_"2282my($fmt) =@snapshot_fmts;2283return2284$cgi->a({2285-href => href(2286 action=>"snapshot",2287 hash=>$hash,2288 snapshot_format=>$fmt2289),2290-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"2291},"snapshot");2292}else{# $num_fmts == 02293returnundef;2294}2295}22962297## ......................................................................2298## functions returning values to be passed, perhaps after some2299## transformation, to other functions; e.g. returning arguments to href()23002301# returns hash to be passed to href to generate gitweb URL2302# in -title key it returns description of link2303sub get_feed_info {2304my$format=shift||'Atom';2305my%res= (action =>lc($format));23062307# feed links are possible only for project views2308return unless(defined$project);2309# some views should link to OPML, or to generic project feed,2310# or don't have specific feed yet (so they should use generic)2311return if($action=~/^(?:tags|heads|forks|tag|search)$/x);23122313my$branch;2314# branches refs uses 'refs/heads/' prefix (fullname) to differentiate2315# from tag links; this also makes possible to detect branch links2316if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||2317(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {2318$branch=$1;2319}2320# find log type for feed description (title)2321my$type='log';2322if(defined$file_name) {2323$type="history of$file_name";2324$type.="/"if($actioneq'tree');2325$type.=" on '$branch'"if(defined$branch);2326}else{2327$type="log of$branch"if(defined$branch);2328}23292330$res{-title} =$type;2331$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);2332$res{'file_name'} =$file_name;23332334return%res;2335}23362337## ----------------------------------------------------------------------2338## git utility subroutines, invoking git commands23392340# returns path to the core git executable and the --git-dir parameter as list2341sub git_cmd {2342$number_of_git_cmds++;2343return$GIT,'--git-dir='.$git_dir;2344}23452346# quote the given arguments for passing them to the shell2347# quote_command("command", "arg 1", "arg with ' and ! characters")2348# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2349# Try to avoid using this function wherever possible.2350sub quote_command {2351returnjoin(' ',2352map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2353}23542355# get HEAD ref of given project as hash2356sub git_get_head_hash {2357return git_get_full_hash(shift,'HEAD');2358}23592360sub git_get_full_hash {2361return git_get_hash(@_);2362}23632364sub git_get_short_hash {2365return git_get_hash(@_,'--short=7');2366}23672368sub git_get_hash {2369my($project,$hash,@options) =@_;2370my$o_git_dir=$git_dir;2371my$retval=undef;2372$git_dir="$projectroot/$project";2373if(open my$fd,'-|', git_cmd(),'rev-parse',2374'--verify','-q',@options,$hash) {2375$retval= <$fd>;2376chomp$retvalifdefined$retval;2377close$fd;2378}2379if(defined$o_git_dir) {2380$git_dir=$o_git_dir;2381}2382return$retval;2383}23842385# get type of given object2386sub git_get_type {2387my$hash=shift;23882389open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2390my$type= <$fd>;2391close$fdorreturn;2392chomp$type;2393return$type;2394}23952396# repository configuration2397our$config_file='';2398our%config;23992400# store multiple values for single key as anonymous array reference2401# single values stored directly in the hash, not as [ <value> ]2402sub hash_set_multi {2403my($hash,$key,$value) =@_;24042405if(!exists$hash->{$key}) {2406$hash->{$key} =$value;2407}elsif(!ref$hash->{$key}) {2408$hash->{$key} = [$hash->{$key},$value];2409}else{2410push@{$hash->{$key}},$value;2411}2412}24132414# return hash of git project configuration2415# optionally limited to some section, e.g. 'gitweb'2416sub git_parse_project_config {2417my$section_regexp=shift;2418my%config;24192420local$/="\0";24212422open my$fh,"-|", git_cmd(),"config",'-z','-l',2423orreturn;24242425while(my$keyval= <$fh>) {2426chomp$keyval;2427my($key,$value) =split(/\n/,$keyval,2);24282429 hash_set_multi(\%config,$key,$value)2430if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2431}2432close$fh;24332434return%config;2435}24362437# convert config value to boolean: 'true' or 'false'2438# no value, number > 0, 'true' and 'yes' values are true2439# rest of values are treated as false (never as error)2440sub config_to_bool {2441my$val=shift;24422443return1if!defined$val;# section.key24442445# strip leading and trailing whitespace2446$val=~s/^\s+//;2447$val=~s/\s+$//;24482449return(($val=~/^\d+$/&&$val) ||# section.key = 12450($val=~/^(?:true|yes)$/i));# section.key = true2451}24522453# convert config value to simple decimal number2454# an optional value suffix of 'k', 'm', or 'g' will cause the value2455# to be multiplied by 1024, 1048576, or 10737418242456sub config_to_int {2457my$val=shift;24582459# strip leading and trailing whitespace2460$val=~s/^\s+//;2461$val=~s/\s+$//;24622463if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2464$unit=lc($unit);2465# unknown unit is treated as 12466return$num* ($uniteq'g'?1073741824:2467$uniteq'm'?1048576:2468$uniteq'k'?1024:1);2469}2470return$val;2471}24722473# convert config value to array reference, if needed2474sub config_to_multi {2475my$val=shift;24762477returnref($val) ?$val: (defined($val) ? [$val] : []);2478}24792480sub git_get_project_config {2481my($key,$type) =@_;24822483return unlessdefined$git_dir;24842485# key sanity check2486return unless($key);2487$key=~s/^gitweb\.//;2488return if($key=~m/\W/);24892490# type sanity check2491if(defined$type) {2492$type=~s/^--//;2493$type=undef2494unless($typeeq'bool'||$typeeq'int');2495}24962497# get config2498if(!defined$config_file||2499$config_filene"$git_dir/config") {2500%config= git_parse_project_config('gitweb');2501$config_file="$git_dir/config";2502}25032504# check if config variable (key) exists2505return unlessexists$config{"gitweb.$key"};25062507# ensure given type2508if(!defined$type) {2509return$config{"gitweb.$key"};2510}elsif($typeeq'bool') {2511# backward compatibility: 'git config --bool' returns true/false2512return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2513}elsif($typeeq'int') {2514return config_to_int($config{"gitweb.$key"});2515}2516return$config{"gitweb.$key"};2517}25182519# get hash of given path at given ref2520sub git_get_hash_by_path {2521my$base=shift;2522my$path=shift||returnundef;2523my$type=shift;25242525$path=~ s,/+$,,;25262527open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2528or die_error(500,"Open git-ls-tree failed");2529my$line= <$fd>;2530close$fdorreturnundef;25312532if(!defined$line) {2533# there is no tree or hash given by $path at $base2534returnundef;2535}25362537#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2538$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2539if(defined$type&&$typene$2) {2540# type doesn't match2541returnundef;2542}2543return$3;2544}25452546# get path of entry with given hash at given tree-ish (ref)2547# used to get 'from' filename for combined diff (merge commit) for renames2548sub git_get_path_by_hash {2549my$base=shift||return;2550my$hash=shift||return;25512552local$/="\0";25532554open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2555orreturnundef;2556while(my$line= <$fd>) {2557chomp$line;25582559#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2560#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2561if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2562close$fd;2563return$1;2564}2565}2566close$fd;2567returnundef;2568}25692570## ......................................................................2571## git utility functions, directly accessing git repository25722573sub git_get_project_description {2574my$path=shift;25752576$git_dir="$projectroot/$path";2577open my$fd,'<',"$git_dir/description"2578orreturn git_get_project_config('description');2579my$descr= <$fd>;2580close$fd;2581if(defined$descr) {2582chomp$descr;2583}2584return$descr;2585}25862587sub git_get_project_ctags {2588my$path=shift;2589my$ctags= {};25902591$git_dir="$projectroot/$path";2592opendir my$dh,"$git_dir/ctags"2593orreturn$ctags;2594foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2595open my$ct,'<',$_ornext;2596my$val= <$ct>;2597chomp$val;2598close$ct;2599my$ctag=$_;$ctag=~ s#.*/##;2600$ctags->{$ctag} =$val;2601}2602closedir$dh;2603$ctags;2604}26052606sub git_populate_project_tagcloud {2607my$ctags=shift;26082609# First, merge different-cased tags; tags vote on casing2610my%ctags_lc;2611foreach(keys%$ctags) {2612$ctags_lc{lc$_}->{count} +=$ctags->{$_};2613if(not$ctags_lc{lc$_}->{topcount}2614or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2615$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2616$ctags_lc{lc$_}->{topname} =$_;2617}2618}26192620my$cloud;2621if(eval{require HTML::TagCloud;1; }) {2622$cloud= HTML::TagCloud->new;2623foreach(sort keys%ctags_lc) {2624# Pad the title with spaces so that the cloud looks2625# less crammed.2626my$title=$ctags_lc{$_}->{topname};2627$title=~s/ / /g;2628$title=~s/^/ /g;2629$title=~s/$/ /g;2630$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2631}2632}else{2633$cloud= \%ctags_lc;2634}2635$cloud;2636}26372638sub git_show_project_tagcloud {2639my($cloud,$count) =@_;2640print STDERR ref($cloud)."..\n";2641if(ref$cloudeq'HTML::TagCloud') {2642return$cloud->html_and_css($count);2643}else{2644my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2645return'<p align="center">'.join(', ',map{2646$cgi->a({-href=>"$home_link?by_tag=$_"},$cloud->{$_}->{topname})2647}splice(@tags,0,$count)) .'</p>';2648}2649}26502651sub git_get_project_url_list {2652my$path=shift;26532654$git_dir="$projectroot/$path";2655open my$fd,'<',"$git_dir/cloneurl"2656orreturnwantarray?2657@{ config_to_multi(git_get_project_config('url')) } :2658 config_to_multi(git_get_project_config('url'));2659my@git_project_url_list=map{chomp;$_} <$fd>;2660close$fd;26612662returnwantarray?@git_project_url_list: \@git_project_url_list;2663}26642665sub git_get_projects_list {2666my($filter) =@_;2667my@list;26682669$filter||='';2670$filter=~s/\.git$//;26712672my$check_forks= gitweb_check_feature('forks');26732674if(-d $projects_list) {2675# search in directory2676my$dir=$projects_list. ($filter?"/$filter":'');2677# remove the trailing "/"2678$dir=~s!/+$!!;2679my$pfxlen=length("$dir");2680my$pfxdepth= ($dir=~tr!/!!);26812682 File::Find::find({2683 follow_fast =>1,# follow symbolic links2684 follow_skip =>2,# ignore duplicates2685 dangling_symlinks =>0,# ignore dangling symlinks, silently2686 wanted =>sub{2687# global variables2688our$project_maxdepth;2689our$projectroot;2690# skip project-list toplevel, if we get it.2691return if(m!^[/.]$!);2692# only directories can be git repositories2693return unless(-d $_);2694# don't traverse too deep (Find is super slow on os x)2695if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2696$File::Find::prune =1;2697return;2698}26992700my$subdir=substr($File::Find::name,$pfxlen+1);2701# we check related file in $projectroot2702my$path= ($filter?"$filter/":'') .$subdir;2703if(check_export_ok("$projectroot/$path")) {2704push@list, { path =>$path};2705$File::Find::prune =1;2706}2707},2708},"$dir");27092710}elsif(-f $projects_list) {2711# read from file(url-encoded):2712# 'git%2Fgit.git Linus+Torvalds'2713# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2714# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2715my%paths;2716open my$fd,'<',$projects_listorreturn;2717 PROJECT:2718while(my$line= <$fd>) {2719chomp$line;2720my($path,$owner) =split' ',$line;2721$path= unescape($path);2722$owner= unescape($owner);2723if(!defined$path) {2724next;2725}2726if($filterne'') {2727# looking for forks;2728my$pfx=substr($path,0,length($filter));2729if($pfxne$filter) {2730next PROJECT;2731}2732my$sfx=substr($path,length($filter));2733if($sfx!~/^\/.*\.git$/) {2734next PROJECT;2735}2736}elsif($check_forks) {2737 PATH:2738foreachmy$filter(keys%paths) {2739# looking for forks;2740my$pfx=substr($path,0,length($filter));2741if($pfxne$filter) {2742next PATH;2743}2744my$sfx=substr($path,length($filter));2745if($sfx!~/^\/.*\.git$/) {2746next PATH;2747}2748# is a fork, don't include it in2749# the list2750next PROJECT;2751}2752}2753if(check_export_ok("$projectroot/$path")) {2754my$pr= {2755 path =>$path,2756 owner => to_utf8($owner),2757};2758push@list,$pr;2759(my$forks_path=$path) =~s/\.git$//;2760$paths{$forks_path}++;2761}2762}2763close$fd;2764}2765return@list;2766}27672768our$gitweb_project_owner=undef;2769sub git_get_project_list_from_file {27702771return if(defined$gitweb_project_owner);27722773$gitweb_project_owner= {};2774# read from file (url-encoded):2775# 'git%2Fgit.git Linus+Torvalds'2776# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2777# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2778if(-f $projects_list) {2779open(my$fd,'<',$projects_list);2780while(my$line= <$fd>) {2781chomp$line;2782my($pr,$ow) =split' ',$line;2783$pr= unescape($pr);2784$ow= unescape($ow);2785$gitweb_project_owner->{$pr} = to_utf8($ow);2786}2787close$fd;2788}2789}27902791sub git_get_project_owner {2792my$project=shift;2793my$owner;27942795returnundefunless$project;2796$git_dir="$projectroot/$project";27972798if(!defined$gitweb_project_owner) {2799 git_get_project_list_from_file();2800}28012802if(exists$gitweb_project_owner->{$project}) {2803$owner=$gitweb_project_owner->{$project};2804}2805if(!defined$owner){2806$owner= git_get_project_config('owner');2807}2808if(!defined$owner) {2809$owner= get_file_owner("$git_dir");2810}28112812return$owner;2813}28142815sub git_get_last_activity {2816my($path) =@_;2817my$fd;28182819$git_dir="$projectroot/$path";2820open($fd,"-|", git_cmd(),'for-each-ref',2821'--format=%(committer)',2822'--sort=-committerdate',2823'--count=1',2824'refs/heads')orreturn;2825my$most_recent= <$fd>;2826close$fdorreturn;2827if(defined$most_recent&&2828$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2829my$timestamp=$1;2830my$age=time-$timestamp;2831return($age, age_string($age));2832}2833return(undef,undef);2834}28352836# Implementation note: when a single remote is wanted, we cannot use 'git2837# remote show -n' because that command always work (assuming it's a remote URL2838# if it's not defined), and we cannot use 'git remote show' because that would2839# try to make a network roundtrip. So the only way to find if that particular2840# remote is defined is to walk the list provided by 'git remote -v' and stop if2841# and when we find what we want.2842sub git_get_remotes_list {2843my$wanted=shift;2844my%remotes= ();28452846open my$fd,'-|', git_cmd(),'remote','-v';2847return unless$fd;2848while(my$remote= <$fd>) {2849chomp$remote;2850$remote=~s!\t(.*?)\s+\((\w+)\)$!!;2851next if$wantedand not$remoteeq$wanted;2852my($url,$key) = ($1,$2);28532854$remotes{$remote} ||= {'heads'=> () };2855$remotes{$remote}{$key} =$url;2856}2857close$fdorreturn;2858returnwantarray?%remotes: \%remotes;2859}28602861# Takes a hash of remotes as first parameter and fills it by adding the2862# available remote heads for each of the indicated remotes.2863sub fill_remote_heads {2864my$remotes=shift;2865my@heads=map{"remotes/$_"}keys%$remotes;2866my@remoteheads= git_get_heads_list(undef,@heads);2867foreachmy$remote(keys%$remotes) {2868$remotes->{$remote}{'heads'} = [grep{2869$_->{'name'} =~s!^$remote/!!2870}@remoteheads];2871}2872}28732874sub git_get_references {2875my$type=shift||"";2876my%refs;2877# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112878# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2879open my$fd,"-|", git_cmd(),"show-ref","--dereference",2880($type? ("--","refs/$type") : ())# use -- <pattern> if $type2881orreturn;28822883while(my$line= <$fd>) {2884chomp$line;2885if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2886if(defined$refs{$1}) {2887push@{$refs{$1}},$2;2888}else{2889$refs{$1} = [$2];2890}2891}2892}2893close$fdorreturn;2894return \%refs;2895}28962897sub git_get_rev_name_tags {2898my$hash=shift||returnundef;28992900open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2901orreturn;2902my$name_rev= <$fd>;2903close$fd;29042905if($name_rev=~ m|^$hash tags/(.*)$|) {2906return$1;2907}else{2908# catches also '$hash undefined' output2909returnundef;2910}2911}29122913## ----------------------------------------------------------------------2914## parse to hash functions29152916sub parse_date {2917my$epoch=shift;2918my$tz=shift||"-0000";29192920my%date;2921my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2922my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2923my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2924$date{'hour'} =$hour;2925$date{'minute'} =$min;2926$date{'mday'} =$mday;2927$date{'day'} =$days[$wday];2928$date{'month'} =$months[$mon];2929$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2930$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2931$date{'mday-time'} =sprintf"%d%s%02d:%02d",2932$mday,$months[$mon],$hour,$min;2933$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",29341900+$year,1+$mon,$mday,$hour,$min,$sec;29352936my($tz_sign,$tz_hour,$tz_min) =2937($tz=~m/^([-+])(\d\d)(\d\d)$/);2938$tz_sign= ($tz_signeq'-'? -1: +1);2939my$local=$epoch+$tz_sign*((($tz_hour*60) +$tz_min)*60);2940($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2941$date{'hour_local'} =$hour;2942$date{'minute_local'} =$min;2943$date{'tz_local'} =$tz;2944$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",29451900+$year,$mon+1,$mday,2946$hour,$min,$sec,$tz);2947return%date;2948}29492950sub parse_tag {2951my$tag_id=shift;2952my%tag;2953my@comment;29542955open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2956$tag{'id'} =$tag_id;2957while(my$line= <$fd>) {2958chomp$line;2959if($line=~m/^object ([0-9a-fA-F]{40})$/) {2960$tag{'object'} =$1;2961}elsif($line=~m/^type (.+)$/) {2962$tag{'type'} =$1;2963}elsif($line=~m/^tag (.+)$/) {2964$tag{'name'} =$1;2965}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2966$tag{'author'} =$1;2967$tag{'author_epoch'} =$2;2968$tag{'author_tz'} =$3;2969if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {2970$tag{'author_name'} =$1;2971$tag{'author_email'} =$2;2972}else{2973$tag{'author_name'} =$tag{'author'};2974}2975}elsif($line=~m/--BEGIN/) {2976push@comment,$line;2977last;2978}elsif($lineeq"") {2979last;2980}2981}2982push@comment, <$fd>;2983$tag{'comment'} = \@comment;2984close$fdorreturn;2985if(!defined$tag{'name'}) {2986return2987};2988return%tag2989}29902991sub parse_commit_text {2992my($commit_text,$withparents) =@_;2993my@commit_lines=split'\n',$commit_text;2994my%co;29952996pop@commit_lines;# Remove '\0'29972998if(!@commit_lines) {2999return;3000}30013002my$header=shift@commit_lines;3003if($header!~m/^[0-9a-fA-F]{40}/) {3004return;3005}3006($co{'id'},my@parents) =split' ',$header;3007while(my$line=shift@commit_lines) {3008last if$lineeq"\n";3009if($line=~m/^tree ([0-9a-fA-F]{40})$/) {3010$co{'tree'} =$1;3011}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {3012push@parents,$1;3013}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {3014$co{'author'} = to_utf8($1);3015$co{'author_epoch'} =$2;3016$co{'author_tz'} =$3;3017if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {3018$co{'author_name'} =$1;3019$co{'author_email'} =$2;3020}else{3021$co{'author_name'} =$co{'author'};3022}3023}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {3024$co{'committer'} = to_utf8($1);3025$co{'committer_epoch'} =$2;3026$co{'committer_tz'} =$3;3027if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {3028$co{'committer_name'} =$1;3029$co{'committer_email'} =$2;3030}else{3031$co{'committer_name'} =$co{'committer'};3032}3033}3034}3035if(!defined$co{'tree'}) {3036return;3037};3038$co{'parents'} = \@parents;3039$co{'parent'} =$parents[0];30403041foreachmy$title(@commit_lines) {3042$title=~s/^ //;3043if($titlene"") {3044$co{'title'} = chop_str($title,80,5);3045# remove leading stuff of merges to make the interesting part visible3046if(length($title) >50) {3047$title=~s/^Automatic //;3048$title=~s/^merge (of|with) /Merge ... /i;3049if(length($title) >50) {3050$title=~s/(http|rsync):\/\///;3051}3052if(length($title) >50) {3053$title=~s/(master|www|rsync)\.//;3054}3055if(length($title) >50) {3056$title=~s/kernel.org:?//;3057}3058if(length($title) >50) {3059$title=~s/\/pub\/scm//;3060}3061}3062$co{'title_short'} = chop_str($title,50,5);3063last;3064}3065}3066if(!defined$co{'title'} ||$co{'title'}eq"") {3067$co{'title'} =$co{'title_short'} ='(no commit message)';3068}3069# remove added spaces3070foreachmy$line(@commit_lines) {3071$line=~s/^ //;3072}3073$co{'comment'} = \@commit_lines;30743075my$age=time-$co{'committer_epoch'};3076$co{'age'} =$age;3077$co{'age_string'} = age_string($age);3078my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});3079if($age>60*60*24*7*2) {3080$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;3081$co{'age_string_age'} =$co{'age_string'};3082}else{3083$co{'age_string_date'} =$co{'age_string'};3084$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;3085}3086return%co;3087}30883089sub parse_commit {3090my($commit_id) =@_;3091my%co;30923093local$/="\0";30943095open my$fd,"-|", git_cmd(),"rev-list",3096"--parents",3097"--header",3098"--max-count=1",3099$commit_id,3100"--",3101or die_error(500,"Open git-rev-list failed");3102%co= parse_commit_text(<$fd>,1);3103close$fd;31043105return%co;3106}31073108sub parse_commits {3109my($commit_id,$maxcount,$skip,$filename,@args) =@_;3110my@cos;31113112$maxcount||=1;3113$skip||=0;31143115local$/="\0";31163117open my$fd,"-|", git_cmd(),"rev-list",3118"--header",3119@args,3120("--max-count=".$maxcount),3121("--skip=".$skip),3122@extra_options,3123$commit_id,3124"--",3125($filename? ($filename) : ())3126or die_error(500,"Open git-rev-list failed");3127while(my$line= <$fd>) {3128my%co= parse_commit_text($line);3129push@cos, \%co;3130}3131close$fd;31323133returnwantarray?@cos: \@cos;3134}31353136# parse line of git-diff-tree "raw" output3137sub parse_difftree_raw_line {3138my$line=shift;3139my%res;31403141# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'3142# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'3143if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {3144$res{'from_mode'} =$1;3145$res{'to_mode'} =$2;3146$res{'from_id'} =$3;3147$res{'to_id'} =$4;3148$res{'status'} =$5;3149$res{'similarity'} =$6;3150if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied3151($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);3152}else{3153$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);3154}3155}3156# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'3157# combined diff (for merge commit)3158elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {3159$res{'nparents'} =length($1);3160$res{'from_mode'} = [split(' ',$2) ];3161$res{'to_mode'} =pop@{$res{'from_mode'}};3162$res{'from_id'} = [split(' ',$3) ];3163$res{'to_id'} =pop@{$res{'from_id'}};3164$res{'status'} = [split('',$4) ];3165$res{'to_file'} = unquote($5);3166}3167# 'c512b523472485aef4fff9e57b229d9d243c967f'3168elsif($line=~m/^([0-9a-fA-F]{40})$/) {3169$res{'commit'} =$1;3170}31713172returnwantarray?%res: \%res;3173}31743175# wrapper: return parsed line of git-diff-tree "raw" output3176# (the argument might be raw line, or parsed info)3177sub parsed_difftree_line {3178my$line_or_ref=shift;31793180if(ref($line_or_ref)eq"HASH") {3181# pre-parsed (or generated by hand)3182return$line_or_ref;3183}else{3184return parse_difftree_raw_line($line_or_ref);3185}3186}31873188# parse line of git-ls-tree output3189sub parse_ls_tree_line {3190my$line=shift;3191my%opts=@_;3192my%res;31933194if($opts{'-l'}) {3195#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'3196$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;31973198$res{'mode'} =$1;3199$res{'type'} =$2;3200$res{'hash'} =$3;3201$res{'size'} =$4;3202if($opts{'-z'}) {3203$res{'name'} =$5;3204}else{3205$res{'name'} = unquote($5);3206}3207}else{3208#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'3209$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;32103211$res{'mode'} =$1;3212$res{'type'} =$2;3213$res{'hash'} =$3;3214if($opts{'-z'}) {3215$res{'name'} =$4;3216}else{3217$res{'name'} = unquote($4);3218}3219}32203221returnwantarray?%res: \%res;3222}32233224# generates _two_ hashes, references to which are passed as 2 and 3 argument3225sub parse_from_to_diffinfo {3226my($diffinfo,$from,$to,@parents) =@_;32273228if($diffinfo->{'nparents'}) {3229# combined diff3230$from->{'file'} = [];3231$from->{'href'} = [];3232 fill_from_file_info($diffinfo,@parents)3233unlessexists$diffinfo->{'from_file'};3234for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {3235$from->{'file'}[$i] =3236defined$diffinfo->{'from_file'}[$i] ?3237$diffinfo->{'from_file'}[$i] :3238$diffinfo->{'to_file'};3239if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file3240$from->{'href'}[$i] = href(action=>"blob",3241 hash_base=>$parents[$i],3242 hash=>$diffinfo->{'from_id'}[$i],3243 file_name=>$from->{'file'}[$i]);3244}else{3245$from->{'href'}[$i] =undef;3246}3247}3248}else{3249# ordinary (not combined) diff3250$from->{'file'} =$diffinfo->{'from_file'};3251if($diffinfo->{'status'}ne"A") {# not new (added) file3252$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,3253 hash=>$diffinfo->{'from_id'},3254 file_name=>$from->{'file'});3255}else{3256delete$from->{'href'};3257}3258}32593260$to->{'file'} =$diffinfo->{'to_file'};3261if(!is_deleted($diffinfo)) {# file exists in result3262$to->{'href'} = href(action=>"blob", hash_base=>$hash,3263 hash=>$diffinfo->{'to_id'},3264 file_name=>$to->{'file'});3265}else{3266delete$to->{'href'};3267}3268}32693270## ......................................................................3271## parse to array of hashes functions32723273sub git_get_heads_list {3274my($limit,@classes) =@_;3275@classes= ('heads')unless@classes;3276my@patterns=map{"refs/$_"}@classes;3277my@headslist;32783279open my$fd,'-|', git_cmd(),'for-each-ref',3280($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',3281'--format=%(objectname) %(refname) %(subject)%00%(committer)',3282@patterns3283orreturn;3284while(my$line= <$fd>) {3285my%ref_item;32863287chomp$line;3288my($refinfo,$committerinfo) =split(/\0/,$line);3289my($hash,$name,$title) =split(' ',$refinfo,3);3290my($committer,$epoch,$tz) =3291($committerinfo=~/^(.*) ([0-9]+) (.*)$/);3292$ref_item{'fullname'} =$name;3293$name=~s!^refs/(?:head|remote)s/!!;32943295$ref_item{'name'} =$name;3296$ref_item{'id'} =$hash;3297$ref_item{'title'} =$title||'(no commit message)';3298$ref_item{'epoch'} =$epoch;3299if($epoch) {3300$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3301}else{3302$ref_item{'age'} ="unknown";3303}33043305push@headslist, \%ref_item;3306}3307close$fd;33083309returnwantarray?@headslist: \@headslist;3310}33113312sub git_get_tags_list {3313my$limit=shift;3314my@tagslist;33153316open my$fd,'-|', git_cmd(),'for-each-ref',3317($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',3318'--format=%(objectname) %(objecttype) %(refname) '.3319'%(*objectname) %(*objecttype) %(subject)%00%(creator)',3320'refs/tags'3321orreturn;3322while(my$line= <$fd>) {3323my%ref_item;33243325chomp$line;3326my($refinfo,$creatorinfo) =split(/\0/,$line);3327my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);3328my($creator,$epoch,$tz) =3329($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);3330$ref_item{'fullname'} =$name;3331$name=~s!^refs/tags/!!;33323333$ref_item{'type'} =$type;3334$ref_item{'id'} =$id;3335$ref_item{'name'} =$name;3336if($typeeq"tag") {3337$ref_item{'subject'} =$title;3338$ref_item{'reftype'} =$reftype;3339$ref_item{'refid'} =$refid;3340}else{3341$ref_item{'reftype'} =$type;3342$ref_item{'refid'} =$id;3343}33443345if($typeeq"tag"||$typeeq"commit") {3346$ref_item{'epoch'} =$epoch;3347if($epoch) {3348$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3349}else{3350$ref_item{'age'} ="unknown";3351}3352}33533354push@tagslist, \%ref_item;3355}3356close$fd;33573358returnwantarray?@tagslist: \@tagslist;3359}33603361## ----------------------------------------------------------------------3362## filesystem-related functions33633364sub get_file_owner {3365my$path=shift;33663367my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);3368my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);3369if(!defined$gcos) {3370returnundef;3371}3372my$owner=$gcos;3373$owner=~s/[,;].*$//;3374return to_utf8($owner);3375}33763377# assume that file exists3378sub insert_file {3379my$filename=shift;33803381open my$fd,'<',$filename;3382print map{ to_utf8($_) } <$fd>;3383close$fd;3384}33853386## ......................................................................3387## mimetype related functions33883389sub mimetype_guess_file {3390my$filename=shift;3391my$mimemap=shift;3392-r $mimemaporreturnundef;33933394my%mimemap;3395open(my$mh,'<',$mimemap)orreturnundef;3396while(<$mh>) {3397next ifm/^#/;# skip comments3398my($mimetype,$exts) =split(/\t+/);3399if(defined$exts) {3400my@exts=split(/\s+/,$exts);3401foreachmy$ext(@exts) {3402$mimemap{$ext} =$mimetype;3403}3404}3405}3406close($mh);34073408$filename=~/\.([^.]*)$/;3409return$mimemap{$1};3410}34113412sub mimetype_guess {3413my$filename=shift;3414my$mime;3415$filename=~/\./orreturnundef;34163417if($mimetypes_file) {3418my$file=$mimetypes_file;3419if($file!~m!^/!) {# if it is relative path3420# it is relative to project3421$file="$projectroot/$project/$file";3422}3423$mime= mimetype_guess_file($filename,$file);3424}3425$mime||= mimetype_guess_file($filename,'/etc/mime.types');3426return$mime;3427}34283429sub blob_mimetype {3430my$fd=shift;3431my$filename=shift;34323433if($filename) {3434my$mime= mimetype_guess($filename);3435$mimeandreturn$mime;3436}34373438# just in case3439return$default_blob_plain_mimetypeunless$fd;34403441if(-T $fd) {3442return'text/plain';3443}elsif(!$filename) {3444return'application/octet-stream';3445}elsif($filename=~m/\.png$/i) {3446return'image/png';3447}elsif($filename=~m/\.gif$/i) {3448return'image/gif';3449}elsif($filename=~m/\.jpe?g$/i) {3450return'image/jpeg';3451}else{3452return'application/octet-stream';3453}3454}34553456sub blob_contenttype {3457my($fd,$file_name,$type) =@_;34583459$type||= blob_mimetype($fd,$file_name);3460if($typeeq'text/plain'&&defined$default_text_plain_charset) {3461$type.="; charset=$default_text_plain_charset";3462}34633464return$type;3465}34663467# guess file syntax for syntax highlighting; return undef if no highlighting3468# the name of syntax can (in the future) depend on syntax highlighter used3469sub guess_file_syntax {3470my($highlight,$mimetype,$file_name) =@_;3471returnundefunless($highlight&&defined$file_name);3472my$basename= basename($file_name,'.in');3473return$highlight_basename{$basename}3474ifexists$highlight_basename{$basename};34753476$basename=~/\.([^.]*)$/;3477my$ext=$1orreturnundef;3478return$highlight_ext{$ext}3479ifexists$highlight_ext{$ext};34803481returnundef;3482}34833484# run highlighter and return FD of its output,3485# or return original FD if no highlighting3486sub run_highlighter {3487my($fd,$highlight,$syntax) =@_;3488return$fdunless($highlight&&defined$syntax);34893490close$fd;3491open$fd, quote_command(git_cmd(),"cat-file","blob",$hash)." | ".3492 quote_command($highlight_bin).3493" --replace-tabs=8 --fragment --syntax$syntax|"3494or die_error(500,"Couldn't open file or run syntax highlighter");3495return$fd;3496}34973498## ======================================================================3499## functions printing HTML: header, footer, error page35003501sub get_page_title {3502my$title= to_utf8($site_name);35033504return$titleunless(defined$project);3505$title.=" - ". to_utf8($project);35063507return$titleunless(defined$action);3508$title.="/$action";# $action is US-ASCII (7bit ASCII)35093510return$titleunless(defined$file_name);3511$title.=" - ". esc_path($file_name);3512if($actioneq"tree"&&$file_name!~ m|/$|) {3513$title.="/";3514}35153516return$title;3517}35183519sub print_feed_meta {3520if(defined$project) {3521my%href_params= get_feed_info();3522if(!exists$href_params{'-title'}) {3523$href_params{'-title'} ='log';3524}35253526foreachmy$format(qw(RSS Atom)) {3527my$type=lc($format);3528my%link_attr= (3529'-rel'=>'alternate',3530'-title'=> esc_attr("$project-$href_params{'-title'} -$formatfeed"),3531'-type'=>"application/$type+xml"3532);35333534$href_params{'action'} =$type;3535$link_attr{'-href'} = href(%href_params);3536print"<link ".3537"rel=\"$link_attr{'-rel'}\"".3538"title=\"$link_attr{'-title'}\"".3539"href=\"$link_attr{'-href'}\"".3540"type=\"$link_attr{'-type'}\"".3541"/>\n";35423543$href_params{'extra_options'} ='--no-merges';3544$link_attr{'-href'} = href(%href_params);3545$link_attr{'-title'} .=' (no merges)';3546print"<link ".3547"rel=\"$link_attr{'-rel'}\"".3548"title=\"$link_attr{'-title'}\"".3549"href=\"$link_attr{'-href'}\"".3550"type=\"$link_attr{'-type'}\"".3551"/>\n";3552}35533554}else{3555printf('<link rel="alternate" title="%sprojects list" '.3556'href="%s" type="text/plain; charset=utf-8" />'."\n",3557 esc_attr($site_name), href(project=>undef, action=>"project_index"));3558printf('<link rel="alternate" title="%sprojects feeds" '.3559'href="%s" type="text/x-opml" />'."\n",3560 esc_attr($site_name), href(project=>undef, action=>"opml"));3561}3562}35633564sub git_header_html {3565my$status=shift||"200 OK";3566my$expires=shift;3567my%opts=@_;35683569my$title= get_page_title();3570my$content_type;3571# require explicit support from the UA if we are to send the page as3572# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3573# we have to do this because MSIE sometimes globs '*/*', pretending to3574# support xhtml+xml but choking when it gets what it asked for.3575if(defined$cgi->http('HTTP_ACCEPT') &&3576$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3577$cgi->Accept('application/xhtml+xml') !=0) {3578$content_type='application/xhtml+xml';3579}else{3580$content_type='text/html';3581}3582print$cgi->header(-type=>$content_type, -charset =>'utf-8',3583-status=>$status, -expires =>$expires)3584unless($opts{'-no_http_header'});3585my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';3586print<<EOF;3587<?xml version="1.0" encoding="utf-8"?>3588<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">3589<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">3590<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->3591<!-- git core binaries version$git_version-->3592<head>3593<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>3594<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>3595<meta name="robots" content="index, nofollow"/>3596<title>$title</title>3597EOF3598# the stylesheet, favicon etc urls won't work correctly with path_info3599# unless we set the appropriate base URL3600if($ENV{'PATH_INFO'}) {3601print"<base href=\"".esc_url($base_url)."\"/>\n";3602}3603# print out each stylesheet that exist, providing backwards capability3604# for those people who defined $stylesheet in a config file3605if(defined$stylesheet) {3606print'<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";3607}else{3608foreachmy$stylesheet(@stylesheets) {3609next unless$stylesheet;3610print'<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";3611}3612}3613 print_feed_meta()3614if($statuseq'200 OK');3615if(defined$favicon) {3616printqq(<link rel="shortcut icon" href=").esc_url($favicon).qq(" type="image/png" />\n);3617}36183619print"</head>\n".3620"<body>\n";36213622if(defined$site_header&& -f $site_header) {3623 insert_file($site_header);3624}36253626print"<div class=\"page_header\">\n";3627if(defined$logo) {3628print$cgi->a({-href => esc_url($logo_url),3629-title =>$logo_label},3630$cgi->img({-src => esc_url($logo),3631-width =>72, -height =>27,3632-alt =>"git",3633-class=>"logo"}));3634}3635print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3636if(defined$project) {3637print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3638if(defined$action) {3639my$action_print=$action;3640if(defined$opts{-action_extra}) {3641$action_print=$cgi->a({-href => href(action=>$action)},3642$action);3643}3644print" /$action_print";3645}3646if(defined$opts{-action_extra}) {3647print" /$opts{-action_extra}";3648}3649print"\n";3650}3651print"</div>\n";36523653my$have_search= gitweb_check_feature('search');3654if(defined$project&&$have_search) {3655if(!defined$searchtext) {3656$searchtext="";3657}3658my$search_hash;3659if(defined$hash_base) {3660$search_hash=$hash_base;3661}elsif(defined$hash) {3662$search_hash=$hash;3663}else{3664$search_hash="HEAD";3665}3666my$action=$my_uri;3667my$use_pathinfo= gitweb_check_feature('pathinfo');3668if($use_pathinfo) {3669$action.="/".esc_url($project);3670}3671print$cgi->startform(-method=>"get", -action =>$action) .3672"<div class=\"search\">\n".3673(!$use_pathinfo&&3674$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3675$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3676$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3677$cgi->popup_menu(-name =>'st', -default=>'commit',3678-values=> ['commit','grep','author','committer','pickaxe']) .3679$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3680" search:\n",3681$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3682"<span title=\"Extended regular expression\">".3683$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3684-checked =>$search_use_regexp) .3685"</span>".3686"</div>".3687$cgi->end_form() ."\n";3688}3689}36903691sub git_footer_html {3692my$feed_class='rss_logo';36933694print"<div class=\"page_footer\">\n";3695if(defined$project) {3696my$descr= git_get_project_description($project);3697if(defined$descr) {3698print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3699}37003701my%href_params= get_feed_info();3702if(!%href_params) {3703$feed_class.=' generic';3704}3705$href_params{'-title'} ||='log';37063707foreachmy$format(qw(RSS Atom)) {3708$href_params{'action'} =lc($format);3709print$cgi->a({-href => href(%href_params),3710-title =>"$href_params{'-title'}$formatfeed",3711-class=>$feed_class},$format)."\n";3712}37133714}else{3715print$cgi->a({-href => href(project=>undef, action=>"opml"),3716-class=>$feed_class},"OPML") ." ";3717print$cgi->a({-href => href(project=>undef, action=>"project_index"),3718-class=>$feed_class},"TXT") ."\n";3719}3720print"</div>\n";# class="page_footer"37213722if(defined$t0&& gitweb_check_feature('timed')) {3723print"<div id=\"generating_info\">\n";3724print'This page took '.3725'<span id="generating_time" class="time_span">'.3726 tv_interval($t0, [ gettimeofday() ]).3727' seconds </span>'.3728' and '.3729'<span id="generating_cmd">'.3730$number_of_git_cmds.3731'</span> git commands '.3732" to generate.\n";3733print"</div>\n";# class="page_footer"3734}37353736if(defined$site_footer&& -f $site_footer) {3737 insert_file($site_footer);3738}37393740print qq!<script type="text/javascript" src="!.esc_url($javascript).qq!"></script>\n!;3741if(defined$action&&3742$actioneq'blame_incremental') {3743print qq!<script type="text/javascript">\n!.3744 qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.3745 qq!"!. href() .qq!");\n!.3746 qq!</script>\n!;3747}else{3748my($jstimezone,$tz_cookie,$datetime_class) =3749 gitweb_get_feature('javascript-timezone');37503751print qq!<script type="text/javascript">\n!.3752 qq!window.onload = function () {\n!;3753if(gitweb_check_feature('javascript-actions')) {3754print qq! fixLinks();\n!;3755}3756if($jstimezone&&$tz_cookie&&$datetime_class) {3757print qq! var tz_cookie = { name:'$tz_cookie', expires:14, path:'/'};\n!.# in days3758 qq! onloadTZSetup('$jstimezone', tz_cookie,'$datetime_class');\n!;3759}3760print qq!};\n!.3761 qq!</script>\n!;3762}37633764print"</body>\n".3765"</html>";3766}37673768# die_error(<http_status_code>, <error_message>[, <detailed_html_description>])3769# Example: die_error(404, 'Hash not found')3770# By convention, use the following status codes (as defined in RFC 2616):3771# 400: Invalid or missing CGI parameters, or3772# requested object exists but has wrong type.3773# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3774# this server or project.3775# 404: Requested object/revision/project doesn't exist.3776# 500: The server isn't configured properly, or3777# an internal error occurred (e.g. failed assertions caused by bugs), or3778# an unknown error occurred (e.g. the git binary died unexpectedly).3779# 503: The server is currently unavailable (because it is overloaded,3780# or down for maintenance). Generally, this is a temporary state.3781sub die_error {3782my$status=shift||500;3783my$error= esc_html(shift) ||"Internal Server Error";3784my$extra=shift;3785my%opts=@_;37863787my%http_responses= (3788400=>'400 Bad Request',3789403=>'403 Forbidden',3790404=>'404 Not Found',3791500=>'500 Internal Server Error',3792503=>'503 Service Unavailable',3793);3794 git_header_html($http_responses{$status},undef,%opts);3795print<<EOF;3796<div class="page_body">3797<br /><br />3798$status-$error3799<br />3800EOF3801if(defined$extra) {3802print"<hr />\n".3803"$extra\n";3804}3805print"</div>\n";38063807 git_footer_html();3808goto DONE_GITWEB3809unless($opts{'-error_handler'});3810}38113812## ----------------------------------------------------------------------3813## functions printing or outputting HTML: navigation38143815sub git_print_page_nav {3816my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3817$extra=''if!defined$extra;# pager or formats38183819my@navs=qw(summary shortlog log commit commitdiff tree);3820if($suppress) {3821@navs=grep{$_ne$suppress}@navs;3822}38233824my%arg=map{$_=> {action=>$_} }@navs;3825if(defined$head) {3826for(qw(commit commitdiff)) {3827$arg{$_}{'hash'} =$head;3828}3829if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3830for(qw(shortlog log)) {3831$arg{$_}{'hash'} =$head;3832}3833}3834}38353836$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3837$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;38383839my@actions= gitweb_get_feature('actions');3840my%repl= (3841'%'=>'%',3842'n'=>$project,# project name3843'f'=>$git_dir,# project path within filesystem3844'h'=>$treehead||'',# current hash ('h' parameter)3845'b'=>$treebase||'',# hash base ('hb' parameter)3846);3847while(@actions) {3848my($label,$link,$pos) =splice(@actions,0,3);3849# insert3850@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3851# munch munch3852$link=~s/%([%nfhb])/$repl{$1}/g;3853$arg{$label}{'_href'} =$link;3854}38553856print"<div class=\"page_nav\">\n".3857(join" | ",3858map{$_eq$current?3859$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3860}@navs);3861print"<br/>\n$extra<br/>\n".3862"</div>\n";3863}38643865# returns a submenu for the nagivation of the refs views (tags, heads,3866# remotes) with the current view disabled and the remotes view only3867# available if the feature is enabled3868sub format_ref_views {3869my($current) =@_;3870my@ref_views=qw{tags heads};3871push@ref_views,'remotes'if gitweb_check_feature('remote_heads');3872returnjoin" | ",map{3873$_eq$current?$_:3874$cgi->a({-href => href(action=>$_)},$_)3875}@ref_views3876}38773878sub format_paging_nav {3879my($action,$page,$has_next_link) =@_;3880my$paging_nav;388138823883if($page>0) {3884$paging_nav.=3885$cgi->a({-href => href(-replay=>1, page=>undef)},"first") .3886" ⋅ ".3887$cgi->a({-href => href(-replay=>1, page=>$page-1),3888-accesskey =>"p", -title =>"Alt-p"},"prev");3889}else{3890$paging_nav.="first ⋅ prev";3891}38923893if($has_next_link) {3894$paging_nav.=" ⋅ ".3895$cgi->a({-href => href(-replay=>1, page=>$page+1),3896-accesskey =>"n", -title =>"Alt-n"},"next");3897}else{3898$paging_nav.=" ⋅ next";3899}39003901return$paging_nav;3902}39033904## ......................................................................3905## functions printing or outputting HTML: div39063907sub git_print_header_div {3908my($action,$title,$hash,$hash_base) =@_;3909my%args= ();39103911$args{'action'} =$action;3912$args{'hash'} =$hashif$hash;3913$args{'hash_base'} =$hash_baseif$hash_base;39143915print"<div class=\"header\">\n".3916$cgi->a({-href => href(%args), -class=>"title"},3917$title?$title:$action) .3918"\n</div>\n";3919}39203921sub format_repo_url {3922my($name,$url) =@_;3923return"<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";3924}39253926# Group output by placing it in a DIV element and adding a header.3927# Options for start_div() can be provided by passing a hash reference as the3928# first parameter to the function.3929# Options to git_print_header_div() can be provided by passing an array3930# reference. This must follow the options to start_div if they are present.3931# The content can be a scalar, which is output as-is, a scalar reference, which3932# is output after html escaping, an IO handle passed either as *handle or3933# *handle{IO}, or a function reference. In the latter case all following3934# parameters will be taken as argument to the content function call.3935sub git_print_section {3936my($div_args,$header_args,$content);3937my$arg=shift;3938if(ref($arg)eq'HASH') {3939$div_args=$arg;3940$arg=shift;3941}3942if(ref($arg)eq'ARRAY') {3943$header_args=$arg;3944$arg=shift;3945}3946$content=$arg;39473948print$cgi->start_div($div_args);3949 git_print_header_div(@$header_args);39503951if(ref($content)eq'CODE') {3952$content->(@_);3953}elsif(ref($content)eq'SCALAR') {3954print esc_html($$content);3955}elsif(ref($content)eq'GLOB'or ref($content)eq'IO::Handle') {3956print<$content>;3957}elsif(!ref($content) &&defined($content)) {3958print$content;3959}39603961print$cgi->end_div;3962}39633964sub format_timestamp_html {3965my$date=shift;3966my$strtime=$date->{'rfc2822'};39673968my(undef,undef,$datetime_class) =3969 gitweb_get_feature('javascript-timezone');3970if($datetime_class) {3971$strtime= qq!<span class="$datetime_class">$strtime</span>!;3972}39733974my$localtime_format='(%02d:%02d%s)';3975if($date->{'hour_local'} <6) {3976$localtime_format='(<span class="atnight">%02d:%02d</span>%s)';3977}3978$strtime.=' '.3979sprintf($localtime_format,3980$date->{'hour_local'},$date->{'minute_local'},$date->{'tz_local'});39813982return$strtime;3983}39843985# Outputs the author name and date in long form3986sub git_print_authorship {3987my$co=shift;3988my%opts=@_;3989my$tag=$opts{-tag} ||'div';3990my$author=$co->{'author_name'};39913992my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3993print"<$tagclass=\"author_date\">".3994 format_search_author($author,"author", esc_html($author)) .3995" [".format_timestamp_html(\%ad)."]".3996 git_get_avatar($co->{'author_email'}, -pad_before =>1) .3997"</$tag>\n";3998}39994000# Outputs table rows containing the full author or committer information,4001# in the format expected for 'commit' view (& similar).4002# Parameters are a commit hash reference, followed by the list of people4003# to output information for. If the list is empty it defaults to both4004# author and committer.4005sub git_print_authorship_rows {4006my$co=shift;4007# too bad we can't use @people = @_ || ('author', 'committer')4008my@people=@_;4009@people= ('author','committer')unless@people;4010foreachmy$who(@people) {4011my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});4012print"<tr><td>$who</td><td>".4013 format_search_author($co->{"${who}_name"},$who,4014 esc_html($co->{"${who}_name"})) ." ".4015 format_search_author($co->{"${who}_email"},$who,4016 esc_html("<".$co->{"${who}_email"} .">")) .4017"</td><td rowspan=\"2\">".4018 git_get_avatar($co->{"${who}_email"}, -size =>'double') .4019"</td></tr>\n".4020"<tr>".4021"<td></td><td>".4022 format_timestamp_html(\%wd) .4023"</td>".4024"</tr>\n";4025}4026}40274028sub git_print_page_path {4029my$name=shift;4030my$type=shift;4031my$hb=shift;403240334034print"<div class=\"page_path\">";4035print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),4036-title =>'tree root'}, to_utf8("[$project]"));4037print" / ";4038if(defined$name) {4039my@dirname=split'/',$name;4040my$basename=pop@dirname;4041my$fullname='';40424043foreachmy$dir(@dirname) {4044$fullname.= ($fullname?'/':'') .$dir;4045print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,4046 hash_base=>$hb),4047-title =>$fullname}, esc_path($dir));4048print" / ";4049}4050if(defined$type&&$typeeq'blob') {4051print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,4052 hash_base=>$hb),4053-title =>$name}, esc_path($basename));4054}elsif(defined$type&&$typeeq'tree') {4055print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,4056 hash_base=>$hb),4057-title =>$name}, esc_path($basename));4058print" / ";4059}else{4060print esc_path($basename);4061}4062}4063print"<br/></div>\n";4064}40654066sub git_print_log {4067my$log=shift;4068my%opts=@_;40694070if($opts{'-remove_title'}) {4071# remove title, i.e. first line of log4072shift@$log;4073}4074# remove leading empty lines4075while(defined$log->[0] &&$log->[0]eq"") {4076shift@$log;4077}40784079# print log4080my$signoff=0;4081my$empty=0;4082foreachmy$line(@$log) {4083if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {4084$signoff=1;4085$empty=0;4086if(!$opts{'-remove_signoff'}) {4087print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";4088next;4089}else{4090# remove signoff lines4091next;4092}4093}else{4094$signoff=0;4095}40964097# print only one empty line4098# do not print empty line after signoff4099if($lineeq"") {4100next if($empty||$signoff);4101$empty=1;4102}else{4103$empty=0;4104}41054106print format_log_line_html($line) ."<br/>\n";4107}41084109if($opts{'-final_empty_line'}) {4110# end with single empty line4111print"<br/>\n"unless$empty;4112}4113}41144115# return link target (what link points to)4116sub git_get_link_target {4117my$hash=shift;4118my$link_target;41194120# read link4121open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4122orreturn;4123{4124local$/=undef;4125$link_target= <$fd>;4126}4127close$fd4128orreturn;41294130return$link_target;4131}41324133# given link target, and the directory (basedir) the link is in,4134# return target of link relative to top directory (top tree);4135# return undef if it is not possible (including absolute links).4136sub normalize_link_target {4137my($link_target,$basedir) =@_;41384139# absolute symlinks (beginning with '/') cannot be normalized4140return if(substr($link_target,0,1)eq'/');41414142# normalize link target to path from top (root) tree (dir)4143my$path;4144if($basedir) {4145$path=$basedir.'/'.$link_target;4146}else{4147# we are in top (root) tree (dir)4148$path=$link_target;4149}41504151# remove //, /./, and /../4152my@path_parts;4153foreachmy$part(split('/',$path)) {4154# discard '.' and ''4155next if(!$part||$parteq'.');4156# handle '..'4157if($parteq'..') {4158if(@path_parts) {4159pop@path_parts;4160}else{4161# link leads outside repository (outside top dir)4162return;4163}4164}else{4165push@path_parts,$part;4166}4167}4168$path=join('/',@path_parts);41694170return$path;4171}41724173# print tree entry (row of git_tree), but without encompassing <tr> element4174sub git_print_tree_entry {4175my($t,$basedir,$hash_base,$have_blame) =@_;41764177my%base_key= ();4178$base_key{'hash_base'} =$hash_baseifdefined$hash_base;41794180# The format of a table row is: mode list link. Where mode is4181# the mode of the entry, list is the name of the entry, an href,4182# and link is the action links of the entry.41834184print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";4185if(exists$t->{'size'}) {4186print"<td class=\"size\">$t->{'size'}</td>\n";4187}4188if($t->{'type'}eq"blob") {4189print"<td class=\"list\">".4190$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4191 file_name=>"$basedir$t->{'name'}",%base_key),4192-class=>"list"}, esc_path($t->{'name'}));4193if(S_ISLNK(oct$t->{'mode'})) {4194my$link_target= git_get_link_target($t->{'hash'});4195if($link_target) {4196my$norm_target= normalize_link_target($link_target,$basedir);4197if(defined$norm_target) {4198print" -> ".4199$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,4200 file_name=>$norm_target),4201-title =>$norm_target}, esc_path($link_target));4202}else{4203print" -> ". esc_path($link_target);4204}4205}4206}4207print"</td>\n";4208print"<td class=\"link\">";4209print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4210 file_name=>"$basedir$t->{'name'}",%base_key)},4211"blob");4212if($have_blame) {4213print" | ".4214$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},4215 file_name=>"$basedir$t->{'name'}",%base_key)},4216"blame");4217}4218if(defined$hash_base) {4219print" | ".4220$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,4221 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},4222"history");4223}4224print" | ".4225$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,4226 file_name=>"$basedir$t->{'name'}")},4227"raw");4228print"</td>\n";42294230}elsif($t->{'type'}eq"tree") {4231print"<td class=\"list\">";4232print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},4233 file_name=>"$basedir$t->{'name'}",4234%base_key)},4235 esc_path($t->{'name'}));4236print"</td>\n";4237print"<td class=\"link\">";4238print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},4239 file_name=>"$basedir$t->{'name'}",4240%base_key)},4241"tree");4242if(defined$hash_base) {4243print" | ".4244$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,4245 file_name=>"$basedir$t->{'name'}")},4246"history");4247}4248print"</td>\n";4249}else{4250# unknown object: we can only present history for it4251# (this includes 'commit' object, i.e. submodule support)4252print"<td class=\"list\">".4253 esc_path($t->{'name'}) .4254"</td>\n";4255print"<td class=\"link\">";4256if(defined$hash_base) {4257print$cgi->a({-href => href(action=>"history",4258 hash_base=>$hash_base,4259 file_name=>"$basedir$t->{'name'}")},4260"history");4261}4262print"</td>\n";4263}4264}42654266## ......................................................................4267## functions printing large fragments of HTML42684269# get pre-image filenames for merge (combined) diff4270sub fill_from_file_info {4271my($diff,@parents) =@_;42724273$diff->{'from_file'} = [ ];4274$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;4275for(my$i=0;$i<$diff->{'nparents'};$i++) {4276if($diff->{'status'}[$i]eq'R'||4277$diff->{'status'}[$i]eq'C') {4278$diff->{'from_file'}[$i] =4279 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);4280}4281}42824283return$diff;4284}42854286# is current raw difftree line of file deletion4287sub is_deleted {4288my$diffinfo=shift;42894290return$diffinfo->{'to_id'}eq('0' x 40);4291}42924293# does patch correspond to [previous] difftree raw line4294# $diffinfo - hashref of parsed raw diff format4295# $patchinfo - hashref of parsed patch diff format4296# (the same keys as in $diffinfo)4297sub is_patch_split {4298my($diffinfo,$patchinfo) =@_;42994300returndefined$diffinfo&&defined$patchinfo4301&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};4302}430343044305sub git_difftree_body {4306my($difftree,$hash,@parents) =@_;4307my($parent) =$parents[0];4308my$have_blame= gitweb_check_feature('blame');4309print"<div class=\"list_head\">\n";4310if($#{$difftree} >10) {4311print(($#{$difftree} +1) ." files changed:\n");4312}4313print"</div>\n";43144315print"<table class=\"".4316(@parents>1?"combined ":"") .4317"diff_tree\">\n";43184319# header only for combined diff in 'commitdiff' view4320my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';4321if($has_header) {4322# table header4323print"<thead><tr>\n".4324"<th></th><th></th>\n";# filename, patchN link4325for(my$i=0;$i<@parents;$i++) {4326my$par=$parents[$i];4327print"<th>".4328$cgi->a({-href => href(action=>"commitdiff",4329 hash=>$hash, hash_parent=>$par),4330-title =>'commitdiff to parent number '.4331($i+1) .': '.substr($par,0,7)},4332$i+1) .4333" </th>\n";4334}4335print"</tr></thead>\n<tbody>\n";4336}43374338my$alternate=1;4339my$patchno=0;4340foreachmy$line(@{$difftree}) {4341my$diff= parsed_difftree_line($line);43424343if($alternate) {4344print"<tr class=\"dark\">\n";4345}else{4346print"<tr class=\"light\">\n";4347}4348$alternate^=1;43494350if(exists$diff->{'nparents'}) {# combined diff43514352 fill_from_file_info($diff,@parents)4353unlessexists$diff->{'from_file'};43544355if(!is_deleted($diff)) {4356# file exists in the result (child) commit4357print"<td>".4358$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4359 file_name=>$diff->{'to_file'},4360 hash_base=>$hash),4361-class=>"list"}, esc_path($diff->{'to_file'})) .4362"</td>\n";4363}else{4364print"<td>".4365 esc_path($diff->{'to_file'}) .4366"</td>\n";4367}43684369if($actioneq'commitdiff') {4370# link to patch4371$patchno++;4372print"<td class=\"link\">".4373$cgi->a({-href => href(-anchor=>"patch$patchno")},4374"patch") .4375" | ".4376"</td>\n";4377}43784379my$has_history=0;4380my$not_deleted=0;4381for(my$i=0;$i<$diff->{'nparents'};$i++) {4382my$hash_parent=$parents[$i];4383my$from_hash=$diff->{'from_id'}[$i];4384my$from_path=$diff->{'from_file'}[$i];4385my$status=$diff->{'status'}[$i];43864387$has_history||= ($statusne'A');4388$not_deleted||= ($statusne'D');43894390if($statuseq'A') {4391print"<td class=\"link\"align=\"right\"> | </td>\n";4392}elsif($statuseq'D') {4393print"<td class=\"link\">".4394$cgi->a({-href => href(action=>"blob",4395 hash_base=>$hash,4396 hash=>$from_hash,4397 file_name=>$from_path)},4398"blob". ($i+1)) .4399" | </td>\n";4400}else{4401if($diff->{'to_id'}eq$from_hash) {4402print"<td class=\"link nochange\">";4403}else{4404print"<td class=\"link\">";4405}4406print$cgi->a({-href => href(action=>"blobdiff",4407 hash=>$diff->{'to_id'},4408 hash_parent=>$from_hash,4409 hash_base=>$hash,4410 hash_parent_base=>$hash_parent,4411 file_name=>$diff->{'to_file'},4412 file_parent=>$from_path)},4413"diff". ($i+1)) .4414" | </td>\n";4415}4416}44174418print"<td class=\"link\">";4419if($not_deleted) {4420print$cgi->a({-href => href(action=>"blob",4421 hash=>$diff->{'to_id'},4422 file_name=>$diff->{'to_file'},4423 hash_base=>$hash)},4424"blob");4425print" | "if($has_history);4426}4427if($has_history) {4428print$cgi->a({-href => href(action=>"history",4429 file_name=>$diff->{'to_file'},4430 hash_base=>$hash)},4431"history");4432}4433print"</td>\n";44344435print"</tr>\n";4436next;# instead of 'else' clause, to avoid extra indent4437}4438# else ordinary diff44394440my($to_mode_oct,$to_mode_str,$to_file_type);4441my($from_mode_oct,$from_mode_str,$from_file_type);4442if($diff->{'to_mode'}ne('0' x 6)) {4443$to_mode_oct=oct$diff->{'to_mode'};4444if(S_ISREG($to_mode_oct)) {# only for regular file4445$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits4446}4447$to_file_type= file_type($diff->{'to_mode'});4448}4449if($diff->{'from_mode'}ne('0' x 6)) {4450$from_mode_oct=oct$diff->{'from_mode'};4451if(S_ISREG($from_mode_oct)) {# only for regular file4452$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits4453}4454$from_file_type= file_type($diff->{'from_mode'});4455}44564457if($diff->{'status'}eq"A") {# created4458my$mode_chng="<span class=\"file_status new\">[new$to_file_type";4459$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;4460$mode_chng.="]</span>";4461print"<td>";4462print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4463 hash_base=>$hash, file_name=>$diff->{'file'}),4464-class=>"list"}, esc_path($diff->{'file'}));4465print"</td>\n";4466print"<td>$mode_chng</td>\n";4467print"<td class=\"link\">";4468if($actioneq'commitdiff') {4469# link to patch4470$patchno++;4471print$cgi->a({-href => href(-anchor=>"patch$patchno")},4472"patch") .4473" | ";4474}4475print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4476 hash_base=>$hash, file_name=>$diff->{'file'})},4477"blob");4478print"</td>\n";44794480}elsif($diff->{'status'}eq"D") {# deleted4481my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";4482print"<td>";4483print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4484 hash_base=>$parent, file_name=>$diff->{'file'}),4485-class=>"list"}, esc_path($diff->{'file'}));4486print"</td>\n";4487print"<td>$mode_chng</td>\n";4488print"<td class=\"link\">";4489if($actioneq'commitdiff') {4490# link to patch4491$patchno++;4492print$cgi->a({-href => href(-anchor=>"patch$patchno")},4493"patch") .4494" | ";4495}4496print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4497 hash_base=>$parent, file_name=>$diff->{'file'})},4498"blob") ." | ";4499if($have_blame) {4500print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,4501 file_name=>$diff->{'file'})},4502"blame") ." | ";4503}4504print$cgi->a({-href => href(action=>"history", hash_base=>$parent,4505 file_name=>$diff->{'file'})},4506"history");4507print"</td>\n";45084509}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed4510my$mode_chnge="";4511if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4512$mode_chnge="<span class=\"file_status mode_chnge\">[changed";4513if($from_file_typene$to_file_type) {4514$mode_chnge.=" from$from_file_typeto$to_file_type";4515}4516if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {4517if($from_mode_str&&$to_mode_str) {4518$mode_chnge.=" mode:$from_mode_str->$to_mode_str";4519}elsif($to_mode_str) {4520$mode_chnge.=" mode:$to_mode_str";4521}4522}4523$mode_chnge.="]</span>\n";4524}4525print"<td>";4526print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4527 hash_base=>$hash, file_name=>$diff->{'file'}),4528-class=>"list"}, esc_path($diff->{'file'}));4529print"</td>\n";4530print"<td>$mode_chnge</td>\n";4531print"<td class=\"link\">";4532if($actioneq'commitdiff') {4533# link to patch4534$patchno++;4535print$cgi->a({-href => href(-anchor=>"patch$patchno")},4536"patch") .4537" | ";4538}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4539# "commit" view and modified file (not onlu mode changed)4540print$cgi->a({-href => href(action=>"blobdiff",4541 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4542 hash_base=>$hash, hash_parent_base=>$parent,4543 file_name=>$diff->{'file'})},4544"diff") .4545" | ";4546}4547print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4548 hash_base=>$hash, file_name=>$diff->{'file'})},4549"blob") ." | ";4550if($have_blame) {4551print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4552 file_name=>$diff->{'file'})},4553"blame") ." | ";4554}4555print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4556 file_name=>$diff->{'file'})},4557"history");4558print"</td>\n";45594560}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied4561my%status_name= ('R'=>'moved','C'=>'copied');4562my$nstatus=$status_name{$diff->{'status'}};4563my$mode_chng="";4564if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4565# mode also for directories, so we cannot use $to_mode_str4566$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);4567}4568print"<td>".4569$cgi->a({-href => href(action=>"blob", hash_base=>$hash,4570 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),4571-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".4572"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".4573$cgi->a({-href => href(action=>"blob", hash_base=>$parent,4574 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),4575-class=>"list"}, esc_path($diff->{'from_file'})) .4576" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".4577"<td class=\"link\">";4578if($actioneq'commitdiff') {4579# link to patch4580$patchno++;4581print$cgi->a({-href => href(-anchor=>"patch$patchno")},4582"patch") .4583" | ";4584}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4585# "commit" view and modified file (not only pure rename or copy)4586print$cgi->a({-href => href(action=>"blobdiff",4587 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4588 hash_base=>$hash, hash_parent_base=>$parent,4589 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},4590"diff") .4591" | ";4592}4593print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4594 hash_base=>$parent, file_name=>$diff->{'to_file'})},4595"blob") ." | ";4596if($have_blame) {4597print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4598 file_name=>$diff->{'to_file'})},4599"blame") ." | ";4600}4601print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4602 file_name=>$diff->{'to_file'})},4603"history");4604print"</td>\n";46054606}# we should not encounter Unmerged (U) or Unknown (X) status4607print"</tr>\n";4608}4609print"</tbody>"if$has_header;4610print"</table>\n";4611}46124613sub git_patchset_body {4614my($fd,$difftree,$hash,@hash_parents) =@_;4615my($hash_parent) =$hash_parents[0];46164617my$is_combined= (@hash_parents>1);4618my$patch_idx=0;4619my$patch_number=0;4620my$patch_line;4621my$diffinfo;4622my$to_name;4623my(%from,%to);46244625print"<div class=\"patchset\">\n";46264627# skip to first patch4628while($patch_line= <$fd>) {4629chomp$patch_line;46304631last if($patch_line=~m/^diff /);4632}46334634 PATCH:4635while($patch_line) {46364637# parse "git diff" header line4638if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {4639# $1 is from_name, which we do not use4640$to_name= unquote($2);4641$to_name=~s!^b/!!;4642}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {4643# $1 is 'cc' or 'combined', which we do not use4644$to_name= unquote($2);4645}else{4646$to_name=undef;4647}46484649# check if current patch belong to current raw line4650# and parse raw git-diff line if needed4651if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {4652# this is continuation of a split patch4653print"<div class=\"patch cont\">\n";4654}else{4655# advance raw git-diff output if needed4656$patch_idx++ifdefined$diffinfo;46574658# read and prepare patch information4659$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);46604661# compact combined diff output can have some patches skipped4662# find which patch (using pathname of result) we are at now;4663if($is_combined) {4664while($to_namene$diffinfo->{'to_file'}) {4665print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4666 format_diff_cc_simplified($diffinfo,@hash_parents) .4667"</div>\n";# class="patch"46684669$patch_idx++;4670$patch_number++;46714672last if$patch_idx>$#$difftree;4673$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);4674}4675}46764677# modifies %from, %to hashes4678 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);46794680# this is first patch for raw difftree line with $patch_idx index4681# we index @$difftree array from 0, but number patches from 14682print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";4683}46844685# git diff header4686#assert($patch_line =~ m/^diff /) if DEBUG;4687#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed4688$patch_number++;4689# print "git diff" header4690print format_git_diff_header_line($patch_line,$diffinfo,4691 \%from, \%to);46924693# print extended diff header4694print"<div class=\"diff extended_header\">\n";4695 EXTENDED_HEADER:4696while($patch_line= <$fd>) {4697chomp$patch_line;46984699last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);47004701print format_extended_diff_header_line($patch_line,$diffinfo,4702 \%from, \%to);4703}4704print"</div>\n";# class="diff extended_header"47054706# from-file/to-file diff header4707if(!$patch_line) {4708print"</div>\n";# class="patch"4709last PATCH;4710}4711next PATCH if($patch_line=~m/^diff /);4712#assert($patch_line =~ m/^---/) if DEBUG;47134714my$last_patch_line=$patch_line;4715$patch_line= <$fd>;4716chomp$patch_line;4717#assert($patch_line =~ m/^\+\+\+/) if DEBUG;47184719print format_diff_from_to_header($last_patch_line,$patch_line,4720$diffinfo, \%from, \%to,4721@hash_parents);47224723# the patch itself4724 LINE:4725while($patch_line= <$fd>) {4726chomp$patch_line;47274728next PATCH if($patch_line=~m/^diff /);47294730print format_diff_line($patch_line, \%from, \%to);4731}47324733}continue{4734print"</div>\n";# class="patch"4735}47364737# for compact combined (--cc) format, with chunk and patch simplification4738# the patchset might be empty, but there might be unprocessed raw lines4739for(++$patch_idxif$patch_number>0;4740$patch_idx<@$difftree;4741++$patch_idx) {4742# read and prepare patch information4743$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);47444745# generate anchor for "patch" links in difftree / whatchanged part4746print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4747 format_diff_cc_simplified($diffinfo,@hash_parents) .4748"</div>\n";# class="patch"47494750$patch_number++;4751}47524753if($patch_number==0) {4754if(@hash_parents>1) {4755print"<div class=\"diff nodifferences\">Trivial merge</div>\n";4756}else{4757print"<div class=\"diff nodifferences\">No differences found</div>\n";4758}4759}47604761print"</div>\n";# class="patchset"4762}47634764# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .47654766# fills project list info (age, description, owner, forks) for each4767# project in the list, removing invalid projects from returned list4768# NOTE: modifies $projlist, but does not remove entries from it4769sub fill_project_list_info {4770my($projlist,$check_forks) =@_;4771my@projects;47724773my$show_ctags= gitweb_check_feature('ctags');4774 PROJECT:4775foreachmy$pr(@$projlist) {4776my(@activity) = git_get_last_activity($pr->{'path'});4777unless(@activity) {4778next PROJECT;4779}4780($pr->{'age'},$pr->{'age_string'}) =@activity;4781if(!defined$pr->{'descr'}) {4782my$descr= git_get_project_description($pr->{'path'}) ||"";4783$descr= to_utf8($descr);4784$pr->{'descr_long'} =$descr;4785$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4786}4787if(!defined$pr->{'owner'}) {4788$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4789}4790if($check_forks) {4791my$pname=$pr->{'path'};4792if(($pname=~s/\.git$//) &&4793($pname!~/\/$/) &&4794(-d "$projectroot/$pname")) {4795$pr->{'forks'} ="-d$projectroot/$pname";4796}else{4797$pr->{'forks'} =0;4798}4799}4800$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4801push@projects,$pr;4802}48034804return@projects;4805}48064807# print 'sort by' <th> element, generating 'sort by $name' replay link4808# if that order is not selected4809sub print_sort_th {4810print format_sort_th(@_);4811}48124813sub format_sort_th {4814my($name,$order,$header) =@_;4815my$sort_th="";4816$header||=ucfirst($name);48174818if($ordereq$name) {4819$sort_th.="<th>$header</th>\n";4820}else{4821$sort_th.="<th>".4822$cgi->a({-href => href(-replay=>1, order=>$name),4823-class=>"header"},$header) .4824"</th>\n";4825}48264827return$sort_th;4828}48294830sub git_project_list_body {4831# actually uses global variable $project4832my($projlist,$order,$from,$to,$extra,$no_header) =@_;48334834my$check_forks= gitweb_check_feature('forks');4835my@projects= fill_project_list_info($projlist,$check_forks);48364837$order||=$default_projects_order;4838$from=0unlessdefined$from;4839$to=$#projectsif(!defined$to||$#projects<$to);48404841my%order_info= (4842 project => { key =>'path', type =>'str'},4843 descr => { key =>'descr_long', type =>'str'},4844 owner => { key =>'owner', type =>'str'},4845 age => { key =>'age', type =>'num'}4846);4847my$oi=$order_info{$order};4848if($oi->{'type'}eq'str') {4849@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4850}else{4851@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4852}48534854my$show_ctags= gitweb_check_feature('ctags');4855if($show_ctags) {4856my%ctags;4857foreachmy$p(@projects) {4858foreachmy$ct(keys%{$p->{'ctags'}}) {4859$ctags{$ct} +=$p->{'ctags'}->{$ct};4860}4861}4862my$cloud= git_populate_project_tagcloud(\%ctags);4863print git_show_project_tagcloud($cloud,64);4864}48654866print"<table class=\"project_list\">\n";4867unless($no_header) {4868print"<tr>\n";4869if($check_forks) {4870print"<th></th>\n";4871}4872 print_sort_th('project',$order,'Project');4873 print_sort_th('descr',$order,'Description');4874 print_sort_th('owner',$order,'Owner');4875 print_sort_th('age',$order,'Last Change');4876print"<th></th>\n".# for links4877"</tr>\n";4878}4879my$alternate=1;4880my$tagfilter=$cgi->param('by_tag');4881for(my$i=$from;$i<=$to;$i++) {4882my$pr=$projects[$i];48834884next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4885next if$searchtextand not$pr->{'path'} =~/$searchtext/4886and not$pr->{'descr_long'} =~/$searchtext/;4887# Weed out forks or non-matching entries of search4888if($check_forks) {4889my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4890$forkbase="^$forkbase"if$forkbase;4891next ifnot$searchtextand not$tagfilterand$show_ctags4892and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4893}48944895if($alternate) {4896print"<tr class=\"dark\">\n";4897}else{4898print"<tr class=\"light\">\n";4899}4900$alternate^=1;4901if($check_forks) {4902print"<td>";4903if($pr->{'forks'}) {4904print"<!--$pr->{'forks'} -->\n";4905print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4906}4907print"</td>\n";4908}4909print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4910-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4911"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4912-class=>"list", -title =>$pr->{'descr_long'}},4913 esc_html($pr->{'descr'})) ."</td>\n".4914"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4915print"<td class=\"". age_class($pr->{'age'}) ."\">".4916(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4917"<td class=\"link\">".4918$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4919$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4920$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4921$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4922($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4923"</td>\n".4924"</tr>\n";4925}4926if(defined$extra) {4927print"<tr>\n";4928if($check_forks) {4929print"<td></td>\n";4930}4931print"<td colspan=\"5\">$extra</td>\n".4932"</tr>\n";4933}4934print"</table>\n";4935}49364937sub git_log_body {4938# uses global variable $project4939my($commitlist,$from,$to,$refs,$extra) =@_;49404941$from=0unlessdefined$from;4942$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);49434944for(my$i=0;$i<=$to;$i++) {4945my%co= %{$commitlist->[$i]};4946next if!%co;4947my$commit=$co{'id'};4948my$ref= format_ref_marker($refs,$commit);4949 git_print_header_div('commit',4950"<span class=\"age\">$co{'age_string'}</span>".4951 esc_html($co{'title'}) .$ref,4952$commit);4953print"<div class=\"title_text\">\n".4954"<div class=\"log_link\">\n".4955$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .4956" | ".4957$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .4958" | ".4959$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .4960"<br/>\n".4961"</div>\n";4962 git_print_authorship(\%co, -tag =>'span');4963print"<br/>\n</div>\n";49644965print"<div class=\"log_body\">\n";4966 git_print_log($co{'comment'}, -final_empty_line=>1);4967print"</div>\n";4968}4969if($extra) {4970print"<div class=\"page_nav\">\n";4971print"$extra\n";4972print"</div>\n";4973}4974}49754976sub git_shortlog_body {4977# uses global variable $project4978my($commitlist,$from,$to,$refs,$extra) =@_;49794980$from=0unlessdefined$from;4981$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);49824983print"<table class=\"shortlog\">\n";4984my$alternate=1;4985for(my$i=$from;$i<=$to;$i++) {4986my%co= %{$commitlist->[$i]};4987my$commit=$co{'id'};4988my$ref= format_ref_marker($refs,$commit);4989if($alternate) {4990print"<tr class=\"dark\">\n";4991}else{4992print"<tr class=\"light\">\n";4993}4994$alternate^=1;4995# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4996print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4997 format_author_html('td', \%co,10) ."<td>";4998print format_subject_html($co{'title'},$co{'title_short'},4999 href(action=>"commit", hash=>$commit),$ref);5000print"</td>\n".5001"<td class=\"link\">".5002$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".5003$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".5004$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");5005my$snapshot_links= format_snapshot_links($commit);5006if(defined$snapshot_links) {5007print" | ".$snapshot_links;5008}5009print"</td>\n".5010"</tr>\n";5011}5012if(defined$extra) {5013print"<tr>\n".5014"<td colspan=\"4\">$extra</td>\n".5015"</tr>\n";5016}5017print"</table>\n";5018}50195020sub git_history_body {5021# Warning: assumes constant type (blob or tree) during history5022my($commitlist,$from,$to,$refs,$extra,5023$file_name,$file_hash,$ftype) =@_;50245025$from=0unlessdefined$from;5026$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});50275028print"<table class=\"history\">\n";5029my$alternate=1;5030for(my$i=$from;$i<=$to;$i++) {5031my%co= %{$commitlist->[$i]};5032if(!%co) {5033next;5034}5035my$commit=$co{'id'};50365037my$ref= format_ref_marker($refs,$commit);50385039if($alternate) {5040print"<tr class=\"dark\">\n";5041}else{5042print"<tr class=\"light\">\n";5043}5044$alternate^=1;5045print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5046# shortlog: format_author_html('td', \%co, 10)5047 format_author_html('td', \%co,15,3) ."<td>";5048# originally git_history used chop_str($co{'title'}, 50)5049print format_subject_html($co{'title'},$co{'title_short'},5050 href(action=>"commit", hash=>$commit),$ref);5051print"</td>\n".5052"<td class=\"link\">".5053$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".5054$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");50555056if($ftypeeq'blob') {5057my$blob_current=$file_hash;5058my$blob_parent= git_get_hash_by_path($commit,$file_name);5059if(defined$blob_current&&defined$blob_parent&&5060$blob_currentne$blob_parent) {5061print" | ".5062$cgi->a({-href => href(action=>"blobdiff",5063 hash=>$blob_current, hash_parent=>$blob_parent,5064 hash_base=>$hash_base, hash_parent_base=>$commit,5065 file_name=>$file_name)},5066"diff to current");5067}5068}5069print"</td>\n".5070"</tr>\n";5071}5072if(defined$extra) {5073print"<tr>\n".5074"<td colspan=\"4\">$extra</td>\n".5075"</tr>\n";5076}5077print"</table>\n";5078}50795080sub git_tags_body {5081# uses global variable $project5082my($taglist,$from,$to,$extra) =@_;5083$from=0unlessdefined$from;5084$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);50855086print"<table class=\"tags\">\n";5087my$alternate=1;5088for(my$i=$from;$i<=$to;$i++) {5089my$entry=$taglist->[$i];5090my%tag=%$entry;5091my$comment=$tag{'subject'};5092my$comment_short;5093if(defined$comment) {5094$comment_short= chop_str($comment,30,5);5095}5096if($alternate) {5097print"<tr class=\"dark\">\n";5098}else{5099print"<tr class=\"light\">\n";5100}5101$alternate^=1;5102if(defined$tag{'age'}) {5103print"<td><i>$tag{'age'}</i></td>\n";5104}else{5105print"<td></td>\n";5106}5107print"<td>".5108$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),5109-class=>"list name"}, esc_html($tag{'name'})) .5110"</td>\n".5111"<td>";5112if(defined$comment) {5113print format_subject_html($comment,$comment_short,5114 href(action=>"tag", hash=>$tag{'id'}));5115}5116print"</td>\n".5117"<td class=\"selflink\">";5118if($tag{'type'}eq"tag") {5119print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");5120}else{5121print" ";5122}5123print"</td>\n".5124"<td class=\"link\">"." | ".5125$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});5126if($tag{'reftype'}eq"commit") {5127print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .5128" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");5129}elsif($tag{'reftype'}eq"blob") {5130print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");5131}5132print"</td>\n".5133"</tr>";5134}5135if(defined$extra) {5136print"<tr>\n".5137"<td colspan=\"5\">$extra</td>\n".5138"</tr>\n";5139}5140print"</table>\n";5141}51425143sub git_heads_body {5144# uses global variable $project5145my($headlist,$head,$from,$to,$extra) =@_;5146$from=0unlessdefined$from;5147$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);51485149print"<table class=\"heads\">\n";5150my$alternate=1;5151for(my$i=$from;$i<=$to;$i++) {5152my$entry=$headlist->[$i];5153my%ref=%$entry;5154my$curr=$ref{'id'}eq$head;5155if($alternate) {5156print"<tr class=\"dark\">\n";5157}else{5158print"<tr class=\"light\">\n";5159}5160$alternate^=1;5161print"<td><i>$ref{'age'}</i></td>\n".5162($curr?"<td class=\"current_head\">":"<td>") .5163$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),5164-class=>"list name"},esc_html($ref{'name'})) .5165"</td>\n".5166"<td class=\"link\">".5167$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".5168$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".5169$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'fullname'})},"tree") .5170"</td>\n".5171"</tr>";5172}5173if(defined$extra) {5174print"<tr>\n".5175"<td colspan=\"3\">$extra</td>\n".5176"</tr>\n";5177}5178print"</table>\n";5179}51805181# Display a single remote block5182sub git_remote_block {5183my($remote,$rdata,$limit,$head) =@_;51845185my$heads=$rdata->{'heads'};5186my$fetch=$rdata->{'fetch'};5187my$push=$rdata->{'push'};51885189my$urls_table="<table class=\"projects_list\">\n";51905191if(defined$fetch) {5192if($fetcheq$push) {5193$urls_table.= format_repo_url("URL",$fetch);5194}else{5195$urls_table.= format_repo_url("Fetch URL",$fetch);5196$urls_table.= format_repo_url("Push URL",$push)ifdefined$push;5197}5198}elsif(defined$push) {5199$urls_table.= format_repo_url("Push URL",$push);5200}else{5201$urls_table.= format_repo_url("","No remote URL");5202}52035204$urls_table.="</table>\n";52055206my$dots;5207if(defined$limit&&$limit<@$heads) {5208$dots=$cgi->a({-href => href(action=>"remotes", hash=>$remote)},"...");5209}52105211print$urls_table;5212 git_heads_body($heads,$head,0,$limit,$dots);5213}52145215# Display a list of remote names with the respective fetch and push URLs5216sub git_remotes_list {5217my($remotedata,$limit) =@_;5218print"<table class=\"heads\">\n";5219my$alternate=1;5220my@remotes=sort keys%$remotedata;52215222my$limited=$limit&&$limit<@remotes;52235224$#remotes=$limit-1if$limited;52255226while(my$remote=shift@remotes) {5227my$rdata=$remotedata->{$remote};5228my$fetch=$rdata->{'fetch'};5229my$push=$rdata->{'push'};5230if($alternate) {5231print"<tr class=\"dark\">\n";5232}else{5233print"<tr class=\"light\">\n";5234}5235$alternate^=1;5236print"<td>".5237$cgi->a({-href=> href(action=>'remotes', hash=>$remote),5238-class=>"list name"},esc_html($remote)) .5239"</td>";5240print"<td class=\"link\">".5241(defined$fetch?$cgi->a({-href=>$fetch},"fetch") :"fetch") .5242" | ".5243(defined$push?$cgi->a({-href=>$push},"push") :"push") .5244"</td>";52455246print"</tr>\n";5247}52485249if($limited) {5250print"<tr>\n".5251"<td colspan=\"3\">".5252$cgi->a({-href => href(action=>"remotes")},"...") .5253"</td>\n"."</tr>\n";5254}52555256print"</table>";5257}52585259# Display remote heads grouped by remote, unless there are too many5260# remotes, in which case we only display the remote names5261sub git_remotes_body {5262my($remotedata,$limit,$head) =@_;5263if($limitand$limit<keys%$remotedata) {5264 git_remotes_list($remotedata,$limit);5265}else{5266 fill_remote_heads($remotedata);5267while(my($remote,$rdata) =each%$remotedata) {5268 git_print_section({-class=>"remote", -id=>$remote},5269["remotes",$remote,$remote],sub{5270 git_remote_block($remote,$rdata,$limit,$head);5271});5272}5273}5274}52755276sub git_search_grep_body {5277my($commitlist,$from,$to,$extra) =@_;5278$from=0unlessdefined$from;5279$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);52805281print"<table class=\"commit_search\">\n";5282my$alternate=1;5283for(my$i=$from;$i<=$to;$i++) {5284my%co= %{$commitlist->[$i]};5285if(!%co) {5286next;5287}5288my$commit=$co{'id'};5289if($alternate) {5290print"<tr class=\"dark\">\n";5291}else{5292print"<tr class=\"light\">\n";5293}5294$alternate^=1;5295print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5296 format_author_html('td', \%co,15,5) .5297"<td>".5298$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),5299-class=>"list subject"},5300 chop_and_escape_str($co{'title'},50) ."<br/>");5301my$comment=$co{'comment'};5302foreachmy$line(@$comment) {5303if($line=~m/^(.*?)($search_regexp)(.*)$/i) {5304my($lead,$match,$trail) = ($1,$2,$3);5305$match= chop_str($match,70,5,'center');5306my$contextlen=int((80-length($match))/2);5307$contextlen=30if($contextlen>30);5308$lead= chop_str($lead,$contextlen,10,'left');5309$trail= chop_str($trail,$contextlen,10,'right');53105311$lead= esc_html($lead);5312$match= esc_html($match);5313$trail= esc_html($trail);53145315print"$lead<span class=\"match\">$match</span>$trail<br />";5316}5317}5318print"</td>\n".5319"<td class=\"link\">".5320$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5321" | ".5322$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .5323" | ".5324$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5325print"</td>\n".5326"</tr>\n";5327}5328if(defined$extra) {5329print"<tr>\n".5330"<td colspan=\"3\">$extra</td>\n".5331"</tr>\n";5332}5333print"</table>\n";5334}53355336## ======================================================================5337## ======================================================================5338## actions53395340sub git_project_list {5341my$order=$input_params{'order'};5342if(defined$order&&$order!~m/none|project|descr|owner|age/) {5343 die_error(400,"Unknown order parameter");5344}53455346my@list= git_get_projects_list();5347if(!@list) {5348 die_error(404,"No projects found");5349}53505351 git_header_html();5352if(defined$home_text&& -f $home_text) {5353print"<div class=\"index_include\">\n";5354 insert_file($home_text);5355print"</div>\n";5356}5357print$cgi->startform(-method=>"get") .5358"<p class=\"projsearch\">Search:\n".5359$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".5360"</p>".5361$cgi->end_form() ."\n";5362 git_project_list_body(\@list,$order);5363 git_footer_html();5364}53655366sub git_forks {5367my$order=$input_params{'order'};5368if(defined$order&&$order!~m/none|project|descr|owner|age/) {5369 die_error(400,"Unknown order parameter");5370}53715372my@list= git_get_projects_list($project);5373if(!@list) {5374 die_error(404,"No forks found");5375}53765377 git_header_html();5378 git_print_page_nav('','');5379 git_print_header_div('summary',"$projectforks");5380 git_project_list_body(\@list,$order);5381 git_footer_html();5382}53835384sub git_project_index {5385my@projects= git_get_projects_list($project);53865387print$cgi->header(5388-type =>'text/plain',5389-charset =>'utf-8',5390-content_disposition =>'inline; filename="index.aux"');53915392foreachmy$pr(@projects) {5393if(!exists$pr->{'owner'}) {5394$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");5395}53965397my($path,$owner) = ($pr->{'path'},$pr->{'owner'});5398# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '5399$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;5400$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;5401$path=~s/ /\+/g;5402$owner=~s/ /\+/g;54035404print"$path$owner\n";5405}5406}54075408sub git_summary {5409my$descr= git_get_project_description($project) ||"none";5410my%co= parse_commit("HEAD");5411my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();5412my$head=$co{'id'};5413my$remote_heads= gitweb_check_feature('remote_heads');54145415my$owner= git_get_project_owner($project);54165417my$refs= git_get_references();5418# These get_*_list functions return one more to allow us to see if5419# there are more ...5420my@taglist= git_get_tags_list(16);5421my@headlist= git_get_heads_list(16);5422my%remotedata=$remote_heads? git_get_remotes_list() : ();5423my@forklist;5424my$check_forks= gitweb_check_feature('forks');54255426if($check_forks) {5427@forklist= git_get_projects_list($project);5428}54295430 git_header_html();5431 git_print_page_nav('summary','',$head);54325433print"<div class=\"title\"> </div>\n";5434print"<table class=\"projects_list\">\n".5435"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".5436"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";5437if(defined$cd{'rfc2822'}) {5438print"<tr id=\"metadata_lchange\"><td>last change</td>".5439"<td>".format_timestamp_html(\%cd)."</td></tr>\n";5440}54415442# use per project git URL list in $projectroot/$project/cloneurl5443# or make project git URL from git base URL and project name5444my$url_tag="URL";5445my@url_list= git_get_project_url_list($project);5446@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;5447foreachmy$git_url(@url_list) {5448next unless$git_url;5449print format_repo_url($url_tag,$git_url);5450$url_tag="";5451}54525453# Tag cloud5454my$show_ctags= gitweb_check_feature('ctags');5455if($show_ctags) {5456my$ctags= git_get_project_ctags($project);5457my$cloud= git_populate_project_tagcloud($ctags);5458print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";5459print"</td>\n<td>"unless%$ctags;5460print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";5461print"</td>\n<td>"if%$ctags;5462print git_show_project_tagcloud($cloud,48);5463print"</td></tr>";5464}54655466print"</table>\n";54675468# If XSS prevention is on, we don't include README.html.5469# TODO: Allow a readme in some safe format.5470if(!$prevent_xss&& -s "$projectroot/$project/README.html") {5471print"<div class=\"title\">readme</div>\n".5472"<div class=\"readme\">\n";5473 insert_file("$projectroot/$project/README.html");5474print"\n</div>\n";# class="readme"5475}54765477# we need to request one more than 16 (0..15) to check if5478# those 16 are all5479my@commitlist=$head? parse_commits($head,17) : ();5480if(@commitlist) {5481 git_print_header_div('shortlog');5482 git_shortlog_body(\@commitlist,0,15,$refs,5483$#commitlist<=15?undef:5484$cgi->a({-href => href(action=>"shortlog")},"..."));5485}54865487if(@taglist) {5488 git_print_header_div('tags');5489 git_tags_body(\@taglist,0,15,5490$#taglist<=15?undef:5491$cgi->a({-href => href(action=>"tags")},"..."));5492}54935494if(@headlist) {5495 git_print_header_div('heads');5496 git_heads_body(\@headlist,$head,0,15,5497$#headlist<=15?undef:5498$cgi->a({-href => href(action=>"heads")},"..."));5499}55005501if(%remotedata) {5502 git_print_header_div('remotes');5503 git_remotes_body(\%remotedata,15,$head);5504}55055506if(@forklist) {5507 git_print_header_div('forks');5508 git_project_list_body(\@forklist,'age',0,15,5509$#forklist<=15?undef:5510$cgi->a({-href => href(action=>"forks")},"..."),5511'no_header');5512}55135514 git_footer_html();5515}55165517sub git_tag {5518my%tag= parse_tag($hash);55195520if(!%tag) {5521 die_error(404,"Unknown tag object");5522}55235524my$head= git_get_head_hash($project);5525 git_header_html();5526 git_print_page_nav('','',$head,undef,$head);5527 git_print_header_div('commit', esc_html($tag{'name'}),$hash);5528print"<div class=\"title_text\">\n".5529"<table class=\"object_header\">\n".5530"<tr>\n".5531"<td>object</td>\n".5532"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},5533$tag{'object'}) ."</td>\n".5534"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},5535$tag{'type'}) ."</td>\n".5536"</tr>\n";5537if(defined($tag{'author'})) {5538 git_print_authorship_rows(\%tag,'author');5539}5540print"</table>\n\n".5541"</div>\n";5542print"<div class=\"page_body\">";5543my$comment=$tag{'comment'};5544foreachmy$line(@$comment) {5545chomp$line;5546print esc_html($line, -nbsp=>1) ."<br/>\n";5547}5548print"</div>\n";5549 git_footer_html();5550}55515552sub git_blame_common {5553my$format=shift||'porcelain';5554if($formateq'porcelain'&&$cgi->param('js')) {5555$format='incremental';5556$action='blame_incremental';# for page title etc5557}55585559# permissions5560 gitweb_check_feature('blame')5561or die_error(403,"Blame view not allowed");55625563# error checking5564 die_error(400,"No file name given")unless$file_name;5565$hash_base||= git_get_head_hash($project);5566 die_error(404,"Couldn't find base commit")unless$hash_base;5567my%co= parse_commit($hash_base)5568or die_error(404,"Commit not found");5569my$ftype="blob";5570if(!defined$hash) {5571$hash= git_get_hash_by_path($hash_base,$file_name,"blob")5572or die_error(404,"Error looking up file");5573}else{5574$ftype= git_get_type($hash);5575if($ftype!~"blob") {5576 die_error(400,"Object is not a blob");5577}5578}55795580my$fd;5581if($formateq'incremental') {5582# get file contents (as base)5583open$fd,"-|", git_cmd(),'cat-file','blob',$hash5584or die_error(500,"Open git-cat-file failed");5585}elsif($formateq'data') {5586# run git-blame --incremental5587open$fd,"-|", git_cmd(),"blame","--incremental",5588$hash_base,"--",$file_name5589or die_error(500,"Open git-blame --incremental failed");5590}else{5591# run git-blame --porcelain5592open$fd,"-|", git_cmd(),"blame",'-p',5593$hash_base,'--',$file_name5594or die_error(500,"Open git-blame --porcelain failed");5595}55965597# incremental blame data returns early5598if($formateq'data') {5599print$cgi->header(5600-type=>"text/plain", -charset =>"utf-8",5601-status=>"200 OK");5602local$| =1;# output autoflush5603printwhile<$fd>;5604close$fd5605or print"ERROR$!\n";56065607print'END';5608if(defined$t0&& gitweb_check_feature('timed')) {5609print' '.5610 tv_interval($t0, [ gettimeofday() ]).5611' '.$number_of_git_cmds;5612}5613print"\n";56145615return;5616}56175618# page header5619 git_header_html();5620my$formats_nav=5621$cgi->a({-href => href(action=>"blob", -replay=>1)},5622"blob") .5623" | ";5624if($formateq'incremental') {5625$formats_nav.=5626$cgi->a({-href => href(action=>"blame", javascript=>0, -replay=>1)},5627"blame") ." (non-incremental)";5628}else{5629$formats_nav.=5630$cgi->a({-href => href(action=>"blame_incremental", -replay=>1)},5631"blame") ." (incremental)";5632}5633$formats_nav.=5634" | ".5635$cgi->a({-href => href(action=>"history", -replay=>1)},5636"history") .5637" | ".5638$cgi->a({-href => href(action=>$action, file_name=>$file_name)},5639"HEAD");5640 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5641 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5642 git_print_page_path($file_name,$ftype,$hash_base);56435644# page body5645if($formateq'incremental') {5646print"<noscript>\n<div class=\"error\"><center><b>\n".5647"This page requires JavaScript to run.\nUse ".5648$cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},5649'this page').5650" instead.\n".5651"</b></center></div>\n</noscript>\n";56525653print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!;5654}56555656print qq!<div class="page_body">\n!;5657print qq!<div id="progress_info">.../ ...</div>\n!5658if($formateq'incremental');5659print qq!<table id="blame_table"class="blame" width="100%">\n!.5660#qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.5661 qq!<thead>\n!.5662 qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!.5663 qq!</thead>\n!.5664 qq!<tbody>\n!;56655666my@rev_color=qw(light dark);5667my$num_colors=scalar(@rev_color);5668my$current_color=0;56695670if($formateq'incremental') {5671my$color_class=$rev_color[$current_color];56725673#contents of a file5674my$linenr=0;5675 LINE:5676while(my$line= <$fd>) {5677chomp$line;5678$linenr++;56795680print qq!<tr id="l$linenr"class="$color_class">!.5681 qq!<td class="sha1"><a href=""> </a></td>!.5682 qq!<td class="linenr">!.5683 qq!<a class="linenr" href="">$linenr</a></td>!;5684print qq!<td class="pre">! . esc_html($line) ."</td>\n";5685print qq!</tr>\n!;5686}56875688}else{# porcelain, i.e. ordinary blame5689my%metainfo= ();# saves information about commits56905691# blame data5692 LINE:5693while(my$line= <$fd>) {5694chomp$line;5695# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]5696# no <lines in group> for subsequent lines in group of lines5697my($full_rev,$orig_lineno,$lineno,$group_size) =5698($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);5699if(!exists$metainfo{$full_rev}) {5700$metainfo{$full_rev} = {'nprevious'=>0};5701}5702my$meta=$metainfo{$full_rev};5703my$data;5704while($data= <$fd>) {5705chomp$data;5706last if($data=~s/^\t//);# contents of line5707if($data=~/^(\S+)(?: (.*))?$/) {5708$meta->{$1} =$2unlessexists$meta->{$1};5709}5710if($data=~/^previous /) {5711$meta->{'nprevious'}++;5712}5713}5714my$short_rev=substr($full_rev,0,8);5715my$author=$meta->{'author'};5716my%date=5717 parse_date($meta->{'author-time'},$meta->{'author-tz'});5718my$date=$date{'iso-tz'};5719if($group_size) {5720$current_color= ($current_color+1) %$num_colors;5721}5722my$tr_class=$rev_color[$current_color];5723$tr_class.=' boundary'if(exists$meta->{'boundary'});5724$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);5725$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);5726print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";5727if($group_size) {5728print"<td class=\"sha1\"";5729print" title=\"". esc_html($author) .",$date\"";5730print" rowspan=\"$group_size\""if($group_size>1);5731print">";5732print$cgi->a({-href => href(action=>"commit",5733 hash=>$full_rev,5734 file_name=>$file_name)},5735 esc_html($short_rev));5736if($group_size>=2) {5737my@author_initials= ($author=~/\b([[:upper:]])\B/g);5738if(@author_initials) {5739print"<br />".5740 esc_html(join('',@author_initials));5741# or join('.', ...)5742}5743}5744print"</td>\n";5745}5746# 'previous' <sha1 of parent commit> <filename at commit>5747if(exists$meta->{'previous'} &&5748$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {5749$meta->{'parent'} =$1;5750$meta->{'file_parent'} = unquote($2);5751}5752my$linenr_commit=5753exists($meta->{'parent'}) ?5754$meta->{'parent'} :$full_rev;5755my$linenr_filename=5756exists($meta->{'file_parent'}) ?5757$meta->{'file_parent'} : unquote($meta->{'filename'});5758my$blamed= href(action =>'blame',5759 file_name =>$linenr_filename,5760 hash_base =>$linenr_commit);5761print"<td class=\"linenr\">";5762print$cgi->a({ -href =>"$blamed#l$orig_lineno",5763-class=>"linenr"},5764 esc_html($lineno));5765print"</td>";5766print"<td class=\"pre\">". esc_html($data) ."</td>\n";5767print"</tr>\n";5768}# end while57695770}57715772# footer5773print"</tbody>\n".5774"</table>\n";# class="blame"5775print"</div>\n";# class="blame_body"5776close$fd5777or print"Reading blob failed\n";57785779 git_footer_html();5780}57815782sub git_blame {5783 git_blame_common();5784}57855786sub git_blame_incremental {5787 git_blame_common('incremental');5788}57895790sub git_blame_data {5791 git_blame_common('data');5792}57935794sub git_tags {5795my$head= git_get_head_hash($project);5796 git_header_html();5797 git_print_page_nav('','',$head,undef,$head,format_ref_views('tags'));5798 git_print_header_div('summary',$project);57995800my@tagslist= git_get_tags_list();5801if(@tagslist) {5802 git_tags_body(\@tagslist);5803}5804 git_footer_html();5805}58065807sub git_heads {5808my$head= git_get_head_hash($project);5809 git_header_html();5810 git_print_page_nav('','',$head,undef,$head,format_ref_views('heads'));5811 git_print_header_div('summary',$project);58125813my@headslist= git_get_heads_list();5814if(@headslist) {5815 git_heads_body(\@headslist,$head);5816}5817 git_footer_html();5818}58195820# used both for single remote view and for list of all the remotes5821sub git_remotes {5822 gitweb_check_feature('remote_heads')5823or die_error(403,"Remote heads view is disabled");58245825my$head= git_get_head_hash($project);5826my$remote=$input_params{'hash'};58275828my$remotedata= git_get_remotes_list($remote);5829 die_error(500,"Unable to get remote information")unlessdefined$remotedata;58305831unless(%$remotedata) {5832 die_error(404,defined$remote?5833"Remote$remotenot found":5834"No remotes found");5835}58365837 git_header_html(undef,undef, -action_extra =>$remote);5838 git_print_page_nav('','',$head,undef,$head,5839 format_ref_views($remote?'':'remotes'));58405841 fill_remote_heads($remotedata);5842if(defined$remote) {5843 git_print_header_div('remotes',"$remoteremote for$project");5844 git_remote_block($remote,$remotedata->{$remote},undef,$head);5845}else{5846 git_print_header_div('summary',"$projectremotes");5847 git_remotes_body($remotedata,undef,$head);5848}58495850 git_footer_html();5851}58525853sub git_blob_plain {5854my$type=shift;5855my$expires;58565857if(!defined$hash) {5858if(defined$file_name) {5859my$base=$hash_base|| git_get_head_hash($project);5860$hash= git_get_hash_by_path($base,$file_name,"blob")5861or die_error(404,"Cannot find file");5862}else{5863 die_error(400,"No file name defined");5864}5865}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5866# blobs defined by non-textual hash id's can be cached5867$expires="+1d";5868}58695870open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5871or die_error(500,"Open git-cat-file blob '$hash' failed");58725873# content-type (can include charset)5874$type= blob_contenttype($fd,$file_name,$type);58755876# "save as" filename, even when no $file_name is given5877my$save_as="$hash";5878if(defined$file_name) {5879$save_as=$file_name;5880}elsif($type=~m/^text\//) {5881$save_as.='.txt';5882}58835884# With XSS prevention on, blobs of all types except a few known safe5885# ones are served with "Content-Disposition: attachment" to make sure5886# they don't run in our security domain. For certain image types,5887# blob view writes an <img> tag referring to blob_plain view, and we5888# want to be sure not to break that by serving the image as an5889# attachment (though Firefox 3 doesn't seem to care).5890my$sandbox=$prevent_xss&&5891$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;58925893print$cgi->header(5894-type =>$type,5895-expires =>$expires,5896-content_disposition =>5897($sandbox?'attachment':'inline')5898.'; filename="'.$save_as.'"');5899local$/=undef;5900binmode STDOUT,':raw';5901print<$fd>;5902binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5903close$fd;5904}59055906sub git_blob {5907my$expires;59085909if(!defined$hash) {5910if(defined$file_name) {5911my$base=$hash_base|| git_get_head_hash($project);5912$hash= git_get_hash_by_path($base,$file_name,"blob")5913or die_error(404,"Cannot find file");5914}else{5915 die_error(400,"No file name defined");5916}5917}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5918# blobs defined by non-textual hash id's can be cached5919$expires="+1d";5920}59215922my$have_blame= gitweb_check_feature('blame');5923open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5924or die_error(500,"Couldn't cat$file_name,$hash");5925my$mimetype= blob_mimetype($fd,$file_name);5926# use 'blob_plain' (aka 'raw') view for files that cannot be displayed5927if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {5928close$fd;5929return git_blob_plain($mimetype);5930}5931# we can have blame only for text/* mimetype5932$have_blame&&= ($mimetype=~m!^text/!);59335934my$highlight= gitweb_check_feature('highlight');5935my$syntax= guess_file_syntax($highlight,$mimetype,$file_name);5936$fd= run_highlighter($fd,$highlight,$syntax)5937if$syntax;59385939 git_header_html(undef,$expires);5940my$formats_nav='';5941if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5942if(defined$file_name) {5943if($have_blame) {5944$formats_nav.=5945$cgi->a({-href => href(action=>"blame", -replay=>1)},5946"blame") .5947" | ";5948}5949$formats_nav.=5950$cgi->a({-href => href(action=>"history", -replay=>1)},5951"history") .5952" | ".5953$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5954"raw") .5955" | ".5956$cgi->a({-href => href(action=>"blob",5957 hash_base=>"HEAD", file_name=>$file_name)},5958"HEAD");5959}else{5960$formats_nav.=5961$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5962"raw");5963}5964 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5965 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5966}else{5967print"<div class=\"page_nav\">\n".5968"<br/><br/></div>\n".5969"<div class=\"title\">".esc_html($hash)."</div>\n";5970}5971 git_print_page_path($file_name,"blob",$hash_base);5972print"<div class=\"page_body\">\n";5973if($mimetype=~m!^image/!) {5974print qq!<img type="!.esc_attr($mimetype).qq!"!;5975if($file_name) {5976print qq! alt="!.esc_attr($file_name).qq!" title="!.esc_attr($file_name).qq!"!;5977}5978print qq! src="! .5979 href(action=>"blob_plain", hash=>$hash,5980 hash_base=>$hash_base, file_name=>$file_name) .5981 qq!"/>\n!;5982}else{5983my$nr;5984while(my$line= <$fd>) {5985chomp$line;5986$nr++;5987$line= untabify($line);5988printf qq!<div class="pre"><a id="l%i" href="%s#l%i"class="linenr">%4i</a> %s</div>\n!,5989$nr, esc_attr(href(-replay =>1)),$nr,$nr,$syntax?$line: esc_html($line, -nbsp=>1);5990}5991}5992close$fd5993or print"Reading blob failed.\n";5994print"</div>";5995 git_footer_html();5996}59975998sub git_tree {5999if(!defined$hash_base) {6000$hash_base="HEAD";6001}6002if(!defined$hash) {6003if(defined$file_name) {6004$hash= git_get_hash_by_path($hash_base,$file_name,"tree");6005}else{6006$hash=$hash_base;6007}6008}6009 die_error(404,"No such tree")unlessdefined($hash);60106011my$show_sizes= gitweb_check_feature('show-sizes');6012my$have_blame= gitweb_check_feature('blame');60136014my@entries= ();6015{6016local$/="\0";6017open my$fd,"-|", git_cmd(),"ls-tree",'-z',6018($show_sizes?'-l': ()),@extra_options,$hash6019or die_error(500,"Open git-ls-tree failed");6020@entries=map{chomp;$_} <$fd>;6021close$fd6022or die_error(404,"Reading tree failed");6023}60246025my$refs= git_get_references();6026my$ref= format_ref_marker($refs,$hash_base);6027 git_header_html();6028my$basedir='';6029if(defined$hash_base&& (my%co= parse_commit($hash_base))) {6030my@views_nav= ();6031if(defined$file_name) {6032push@views_nav,6033$cgi->a({-href => href(action=>"history", -replay=>1)},6034"history"),6035$cgi->a({-href => href(action=>"tree",6036 hash_base=>"HEAD", file_name=>$file_name)},6037"HEAD"),6038}6039my$snapshot_links= format_snapshot_links($hash);6040if(defined$snapshot_links) {6041# FIXME: Should be available when we have no hash base as well.6042push@views_nav,$snapshot_links;6043}6044 git_print_page_nav('tree','',$hash_base,undef,undef,6045join(' | ',@views_nav));6046 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);6047}else{6048undef$hash_base;6049print"<div class=\"page_nav\">\n";6050print"<br/><br/></div>\n";6051print"<div class=\"title\">".esc_html($hash)."</div>\n";6052}6053if(defined$file_name) {6054$basedir=$file_name;6055if($basedirne''&&substr($basedir, -1)ne'/') {6056$basedir.='/';6057}6058 git_print_page_path($file_name,'tree',$hash_base);6059}6060print"<div class=\"page_body\">\n";6061print"<table class=\"tree\">\n";6062my$alternate=1;6063# '..' (top directory) link if possible6064if(defined$hash_base&&6065defined$file_name&&$file_name=~m![^/]+$!) {6066if($alternate) {6067print"<tr class=\"dark\">\n";6068}else{6069print"<tr class=\"light\">\n";6070}6071$alternate^=1;60726073my$up=$file_name;6074$up=~s!/?[^/]+$!!;6075undef$upunless$up;6076# based on git_print_tree_entry6077print'<td class="mode">'. mode_str('040000') ."</td>\n";6078print'<td class="size"> </td>'."\n"if$show_sizes;6079print'<td class="list">';6080print$cgi->a({-href => href(action=>"tree",6081 hash_base=>$hash_base,6082 file_name=>$up)},6083"..");6084print"</td>\n";6085print"<td class=\"link\"></td>\n";60866087print"</tr>\n";6088}6089foreachmy$line(@entries) {6090my%t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);60916092if($alternate) {6093print"<tr class=\"dark\">\n";6094}else{6095print"<tr class=\"light\">\n";6096}6097$alternate^=1;60986099 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);61006101print"</tr>\n";6102}6103print"</table>\n".6104"</div>";6105 git_footer_html();6106}61076108sub snapshot_name {6109my($project,$hash) =@_;61106111# path/to/project.git -> project6112# path/to/project/.git -> project6113my$name= to_utf8($project);6114$name=~ s,([^/])/*\.git$,$1,;6115$name= basename($name);6116# sanitize name6117$name=~s/[[:cntrl:]]/?/g;61186119my$ver=$hash;6120if($hash=~/^[0-9a-fA-F]+$/) {6121# shorten SHA-1 hash6122my$full_hash= git_get_full_hash($project,$hash);6123if($full_hash=~/^$hash/&&length($hash) >7) {6124$ver= git_get_short_hash($project,$hash);6125}6126}elsif($hash=~m!^refs/tags/(.*)$!) {6127# tags don't need shortened SHA-1 hash6128$ver=$1;6129}else{6130# branches and other need shortened SHA-1 hash6131if($hash=~m!^refs/(?:heads|remotes)/(.*)$!) {6132$ver=$1;6133}6134$ver.='-'. git_get_short_hash($project,$hash);6135}6136# in case of hierarchical branch names6137$ver=~s!/!.!g;61386139# name = project-version_string6140$name="$name-$ver";61416142returnwantarray? ($name,$name) :$name;6143}61446145sub git_snapshot {6146my$format=$input_params{'snapshot_format'};6147if(!@snapshot_fmts) {6148 die_error(403,"Snapshots not allowed");6149}6150# default to first supported snapshot format6151$format||=$snapshot_fmts[0];6152if($format!~m/^[a-z0-9]+$/) {6153 die_error(400,"Invalid snapshot format parameter");6154}elsif(!exists($known_snapshot_formats{$format})) {6155 die_error(400,"Unknown snapshot format");6156}elsif($known_snapshot_formats{$format}{'disabled'}) {6157 die_error(403,"Snapshot format not allowed");6158}elsif(!grep($_eq$format,@snapshot_fmts)) {6159 die_error(403,"Unsupported snapshot format");6160}61616162my$type= git_get_type("$hash^{}");6163if(!$type) {6164 die_error(404,'Object does not exist');6165}elsif($typeeq'blob') {6166 die_error(400,'Object is not a tree-ish');6167}61686169my($name,$prefix) = snapshot_name($project,$hash);6170my$filename="$name$known_snapshot_formats{$format}{'suffix'}";6171my$cmd= quote_command(6172 git_cmd(),'archive',6173"--format=$known_snapshot_formats{$format}{'format'}",6174"--prefix=$prefix/",$hash);6175if(exists$known_snapshot_formats{$format}{'compressor'}) {6176$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});6177}61786179$filename=~s/(["\\])/\\$1/g;6180print$cgi->header(6181-type =>$known_snapshot_formats{$format}{'type'},6182-content_disposition =>'inline; filename="'.$filename.'"',6183-status =>'200 OK');61846185open my$fd,"-|",$cmd6186or die_error(500,"Execute git-archive failed");6187binmode STDOUT,':raw';6188print<$fd>;6189binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi6190close$fd;6191}61926193sub git_log_generic {6194my($fmt_name,$body_subr,$base,$parent,$file_name,$file_hash) =@_;61956196my$head= git_get_head_hash($project);6197if(!defined$base) {6198$base=$head;6199}6200if(!defined$page) {6201$page=0;6202}6203my$refs= git_get_references();62046205my$commit_hash=$base;6206if(defined$parent) {6207$commit_hash="$parent..$base";6208}6209my@commitlist=6210 parse_commits($commit_hash,101, (100*$page),6211defined$file_name? ($file_name,"--full-history") : ());62126213my$ftype;6214if(!defined$file_hash&&defined$file_name) {6215# some commits could have deleted file in question,6216# and not have it in tree, but one of them has to have it6217for(my$i=0;$i<@commitlist;$i++) {6218$file_hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);6219last ifdefined$file_hash;6220}6221}6222if(defined$file_hash) {6223$ftype= git_get_type($file_hash);6224}6225if(defined$file_name&& !defined$ftype) {6226 die_error(500,"Unknown type of object");6227}6228my%co;6229if(defined$file_name) {6230%co= parse_commit($base)6231or die_error(404,"Unknown commit object");6232}623362346235my$paging_nav= format_paging_nav($fmt_name,$page,$#commitlist>=100);6236my$next_link='';6237if($#commitlist>=100) {6238$next_link=6239$cgi->a({-href => href(-replay=>1, page=>$page+1),6240-accesskey =>"n", -title =>"Alt-n"},"next");6241}6242my$patch_max= gitweb_get_feature('patches');6243if($patch_max&& !defined$file_name) {6244if($patch_max<0||@commitlist<=$patch_max) {6245$paging_nav.=" ⋅ ".6246$cgi->a({-href => href(action=>"patches", -replay=>1)},6247"patches");6248}6249}62506251 git_header_html();6252 git_print_page_nav($fmt_name,'',$hash,$hash,$hash,$paging_nav);6253if(defined$file_name) {6254 git_print_header_div('commit', esc_html($co{'title'}),$base);6255}else{6256 git_print_header_div('summary',$project)6257}6258 git_print_page_path($file_name,$ftype,$hash_base)6259if(defined$file_name);62606261$body_subr->(\@commitlist,0,99,$refs,$next_link,6262$file_name,$file_hash,$ftype);62636264 git_footer_html();6265}62666267sub git_log {6268 git_log_generic('log', \&git_log_body,6269$hash,$hash_parent);6270}62716272sub git_commit {6273$hash||=$hash_base||"HEAD";6274my%co= parse_commit($hash)6275or die_error(404,"Unknown commit object");62766277my$parent=$co{'parent'};6278my$parents=$co{'parents'};# listref62796280# we need to prepare $formats_nav before any parameter munging6281my$formats_nav;6282if(!defined$parent) {6283# --root commitdiff6284$formats_nav.='(initial)';6285}elsif(@$parents==1) {6286# single parent commit6287$formats_nav.=6288'(parent: '.6289$cgi->a({-href => href(action=>"commit",6290 hash=>$parent)},6291 esc_html(substr($parent,0,7))) .6292')';6293}else{6294# merge commit6295$formats_nav.=6296'(merge: '.6297join(' ',map{6298$cgi->a({-href => href(action=>"commit",6299 hash=>$_)},6300 esc_html(substr($_,0,7)));6301}@$parents) .6302')';6303}6304if(gitweb_check_feature('patches') &&@$parents<=1) {6305$formats_nav.=" | ".6306$cgi->a({-href => href(action=>"patch", -replay=>1)},6307"patch");6308}63096310if(!defined$parent) {6311$parent="--root";6312}6313my@difftree;6314open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",6315@diff_opts,6316(@$parents<=1?$parent:'-c'),6317$hash,"--"6318or die_error(500,"Open git-diff-tree failed");6319@difftree=map{chomp;$_} <$fd>;6320close$fdor die_error(404,"Reading git-diff-tree failed");63216322# non-textual hash id's can be cached6323my$expires;6324if($hash=~m/^[0-9a-fA-F]{40}$/) {6325$expires="+1d";6326}6327my$refs= git_get_references();6328my$ref= format_ref_marker($refs,$co{'id'});63296330 git_header_html(undef,$expires);6331 git_print_page_nav('commit','',6332$hash,$co{'tree'},$hash,6333$formats_nav);63346335if(defined$co{'parent'}) {6336 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);6337}else{6338 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);6339}6340print"<div class=\"title_text\">\n".6341"<table class=\"object_header\">\n";6342 git_print_authorship_rows(\%co);6343print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";6344print"<tr>".6345"<td>tree</td>".6346"<td class=\"sha1\">".6347$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),6348class=>"list"},$co{'tree'}) .6349"</td>".6350"<td class=\"link\">".6351$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},6352"tree");6353my$snapshot_links= format_snapshot_links($hash);6354if(defined$snapshot_links) {6355print" | ".$snapshot_links;6356}6357print"</td>".6358"</tr>\n";63596360foreachmy$par(@$parents) {6361print"<tr>".6362"<td>parent</td>".6363"<td class=\"sha1\">".6364$cgi->a({-href => href(action=>"commit", hash=>$par),6365class=>"list"},$par) .6366"</td>".6367"<td class=\"link\">".6368$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .6369" | ".6370$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .6371"</td>".6372"</tr>\n";6373}6374print"</table>".6375"</div>\n";63766377print"<div class=\"page_body\">\n";6378 git_print_log($co{'comment'});6379print"</div>\n";63806381 git_difftree_body(\@difftree,$hash,@$parents);63826383 git_footer_html();6384}63856386sub git_object {6387# object is defined by:6388# - hash or hash_base alone6389# - hash_base and file_name6390my$type;63916392# - hash or hash_base alone6393if($hash|| ($hash_base&& !defined$file_name)) {6394my$object_id=$hash||$hash_base;63956396open my$fd,"-|", quote_command(6397 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'6398or die_error(404,"Object does not exist");6399$type= <$fd>;6400chomp$type;6401close$fd6402or die_error(404,"Object does not exist");64036404# - hash_base and file_name6405}elsif($hash_base&&defined$file_name) {6406$file_name=~ s,/+$,,;64076408system(git_cmd(),"cat-file",'-e',$hash_base) ==06409or die_error(404,"Base object does not exist");64106411# here errors should not hapen6412open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name6413or die_error(500,"Open git-ls-tree failed");6414my$line= <$fd>;6415close$fd;64166417#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'6418unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {6419 die_error(404,"File or directory for given base does not exist");6420}6421$type=$2;6422$hash=$3;6423}else{6424 die_error(400,"Not enough information to find object");6425}64266427print$cgi->redirect(-uri => href(action=>$type, -full=>1,6428 hash=>$hash, hash_base=>$hash_base,6429 file_name=>$file_name),6430-status =>'302 Found');6431}64326433sub git_blobdiff {6434my$format=shift||'html';64356436my$fd;6437my@difftree;6438my%diffinfo;6439my$expires;64406441# preparing $fd and %diffinfo for git_patchset_body6442# new style URI6443if(defined$hash_base&&defined$hash_parent_base) {6444if(defined$file_name) {6445# read raw output6446open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6447$hash_parent_base,$hash_base,6448"--", (defined$file_parent?$file_parent: ()),$file_name6449or die_error(500,"Open git-diff-tree failed");6450@difftree=map{chomp;$_} <$fd>;6451close$fd6452or die_error(404,"Reading git-diff-tree failed");6453@difftree6454or die_error(404,"Blob diff not found");64556456}elsif(defined$hash&&6457$hash=~/[0-9a-fA-F]{40}/) {6458# try to find filename from $hash64596460# read filtered raw output6461open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6462$hash_parent_base,$hash_base,"--"6463or die_error(500,"Open git-diff-tree failed");6464@difftree=6465# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'6466# $hash == to_id6467grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}6468map{chomp;$_} <$fd>;6469close$fd6470or die_error(404,"Reading git-diff-tree failed");6471@difftree6472or die_error(404,"Blob diff not found");64736474}else{6475 die_error(400,"Missing one of the blob diff parameters");6476}64776478if(@difftree>1) {6479 die_error(400,"Ambiguous blob diff specification");6480}64816482%diffinfo= parse_difftree_raw_line($difftree[0]);6483$file_parent||=$diffinfo{'from_file'} ||$file_name;6484$file_name||=$diffinfo{'to_file'};64856486$hash_parent||=$diffinfo{'from_id'};6487$hash||=$diffinfo{'to_id'};64886489# non-textual hash id's can be cached6490if($hash_base=~m/^[0-9a-fA-F]{40}$/&&6491$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {6492$expires='+1d';6493}64946495# open patch output6496open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6497'-p', ($formateq'html'?"--full-index": ()),6498$hash_parent_base,$hash_base,6499"--", (defined$file_parent?$file_parent: ()),$file_name6500or die_error(500,"Open git-diff-tree failed");6501}65026503# old/legacy style URI -- not generated anymore since 1.4.3.6504if(!%diffinfo) {6505 die_error('404 Not Found',"Missing one of the blob diff parameters")6506}65076508# header6509if($formateq'html') {6510my$formats_nav=6511$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},6512"raw");6513 git_header_html(undef,$expires);6514if(defined$hash_base&& (my%co= parse_commit($hash_base))) {6515 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);6516 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);6517}else{6518print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";6519print"<div class=\"title\">".esc_html("$hashvs$hash_parent")."</div>\n";6520}6521if(defined$file_name) {6522 git_print_page_path($file_name,"blob",$hash_base);6523}else{6524print"<div class=\"page_path\"></div>\n";6525}65266527}elsif($formateq'plain') {6528print$cgi->header(6529-type =>'text/plain',6530-charset =>'utf-8',6531-expires =>$expires,6532-content_disposition =>'inline; filename="'."$file_name".'.patch"');65336534print"X-Git-Url: ".$cgi->self_url() ."\n\n";65356536}else{6537 die_error(400,"Unknown blobdiff format");6538}65396540# patch6541if($formateq'html') {6542print"<div class=\"page_body\">\n";65436544 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);6545close$fd;65466547print"</div>\n";# class="page_body"6548 git_footer_html();65496550}else{6551while(my$line= <$fd>) {6552$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;6553$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;65546555print$line;65566557last if$line=~m!^\+\+\+!;6558}6559local$/=undef;6560print<$fd>;6561close$fd;6562}6563}65646565sub git_blobdiff_plain {6566 git_blobdiff('plain');6567}65686569sub git_commitdiff {6570my%params=@_;6571my$format=$params{-format} ||'html';65726573my($patch_max) = gitweb_get_feature('patches');6574if($formateq'patch') {6575 die_error(403,"Patch view not allowed")unless$patch_max;6576}65776578$hash||=$hash_base||"HEAD";6579my%co= parse_commit($hash)6580or die_error(404,"Unknown commit object");65816582# choose format for commitdiff for merge6583if(!defined$hash_parent&& @{$co{'parents'}} >1) {6584$hash_parent='--cc';6585}6586# we need to prepare $formats_nav before almost any parameter munging6587my$formats_nav;6588if($formateq'html') {6589$formats_nav=6590$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},6591"raw");6592if($patch_max&& @{$co{'parents'}} <=1) {6593$formats_nav.=" | ".6594$cgi->a({-href => href(action=>"patch", -replay=>1)},6595"patch");6596}65976598if(defined$hash_parent&&6599$hash_parentne'-c'&&$hash_parentne'--cc') {6600# commitdiff with two commits given6601my$hash_parent_short=$hash_parent;6602if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {6603$hash_parent_short=substr($hash_parent,0,7);6604}6605$formats_nav.=6606' (from';6607for(my$i=0;$i< @{$co{'parents'}};$i++) {6608if($co{'parents'}[$i]eq$hash_parent) {6609$formats_nav.=' parent '. ($i+1);6610last;6611}6612}6613$formats_nav.=': '.6614$cgi->a({-href => href(action=>"commitdiff",6615 hash=>$hash_parent)},6616 esc_html($hash_parent_short)) .6617')';6618}elsif(!$co{'parent'}) {6619# --root commitdiff6620$formats_nav.=' (initial)';6621}elsif(scalar@{$co{'parents'}} ==1) {6622# single parent commit6623$formats_nav.=6624' (parent: '.6625$cgi->a({-href => href(action=>"commitdiff",6626 hash=>$co{'parent'})},6627 esc_html(substr($co{'parent'},0,7))) .6628')';6629}else{6630# merge commit6631if($hash_parenteq'--cc') {6632$formats_nav.=' | '.6633$cgi->a({-href => href(action=>"commitdiff",6634 hash=>$hash, hash_parent=>'-c')},6635'combined');6636}else{# $hash_parent eq '-c'6637$formats_nav.=' | '.6638$cgi->a({-href => href(action=>"commitdiff",6639 hash=>$hash, hash_parent=>'--cc')},6640'compact');6641}6642$formats_nav.=6643' (merge: '.6644join(' ',map{6645$cgi->a({-href => href(action=>"commitdiff",6646 hash=>$_)},6647 esc_html(substr($_,0,7)));6648} @{$co{'parents'}} ) .6649')';6650}6651}66526653my$hash_parent_param=$hash_parent;6654if(!defined$hash_parent_param) {6655# --cc for multiple parents, --root for parentless6656$hash_parent_param=6657@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';6658}66596660# read commitdiff6661my$fd;6662my@difftree;6663if($formateq'html') {6664open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6665"--no-commit-id","--patch-with-raw","--full-index",6666$hash_parent_param,$hash,"--"6667or die_error(500,"Open git-diff-tree failed");66686669while(my$line= <$fd>) {6670chomp$line;6671# empty line ends raw part of diff-tree output6672last unless$line;6673push@difftree,scalar parse_difftree_raw_line($line);6674}66756676}elsif($formateq'plain') {6677open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6678'-p',$hash_parent_param,$hash,"--"6679or die_error(500,"Open git-diff-tree failed");6680}elsif($formateq'patch') {6681# For commit ranges, we limit the output to the number of6682# patches specified in the 'patches' feature.6683# For single commits, we limit the output to a single patch,6684# diverging from the git-format-patch default.6685my@commit_spec= ();6686if($hash_parent) {6687if($patch_max>0) {6688push@commit_spec,"-$patch_max";6689}6690push@commit_spec,'-n',"$hash_parent..$hash";6691}else{6692if($params{-single}) {6693push@commit_spec,'-1';6694}else{6695if($patch_max>0) {6696push@commit_spec,"-$patch_max";6697}6698push@commit_spec,"-n";6699}6700push@commit_spec,'--root',$hash;6701}6702open$fd,"-|", git_cmd(),"format-patch",@diff_opts,6703'--encoding=utf8','--stdout',@commit_spec6704or die_error(500,"Open git-format-patch failed");6705}else{6706 die_error(400,"Unknown commitdiff format");6707}67086709# non-textual hash id's can be cached6710my$expires;6711if($hash=~m/^[0-9a-fA-F]{40}$/) {6712$expires="+1d";6713}67146715# write commit message6716if($formateq'html') {6717my$refs= git_get_references();6718my$ref= format_ref_marker($refs,$co{'id'});67196720 git_header_html(undef,$expires);6721 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);6722 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);6723print"<div class=\"title_text\">\n".6724"<table class=\"object_header\">\n";6725 git_print_authorship_rows(\%co);6726print"</table>".6727"</div>\n";6728print"<div class=\"page_body\">\n";6729if(@{$co{'comment'}} >1) {6730print"<div class=\"log\">\n";6731 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);6732print"</div>\n";# class="log"6733}67346735}elsif($formateq'plain') {6736my$refs= git_get_references("tags");6737my$tagname= git_get_rev_name_tags($hash);6738my$filename= basename($project) ."-$hash.patch";67396740print$cgi->header(6741-type =>'text/plain',6742-charset =>'utf-8',6743-expires =>$expires,6744-content_disposition =>'inline; filename="'."$filename".'"');6745my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});6746print"From: ". to_utf8($co{'author'}) ."\n";6747print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";6748print"Subject: ". to_utf8($co{'title'}) ."\n";67496750print"X-Git-Tag:$tagname\n"if$tagname;6751print"X-Git-Url: ".$cgi->self_url() ."\n\n";67526753foreachmy$line(@{$co{'comment'}}) {6754print to_utf8($line) ."\n";6755}6756print"---\n\n";6757}elsif($formateq'patch') {6758my$filename= basename($project) ."-$hash.patch";67596760print$cgi->header(6761-type =>'text/plain',6762-charset =>'utf-8',6763-expires =>$expires,6764-content_disposition =>'inline; filename="'."$filename".'"');6765}67666767# write patch6768if($formateq'html') {6769my$use_parents= !defined$hash_parent||6770$hash_parenteq'-c'||$hash_parenteq'--cc';6771 git_difftree_body(\@difftree,$hash,6772$use_parents? @{$co{'parents'}} :$hash_parent);6773print"<br/>\n";67746775 git_patchset_body($fd, \@difftree,$hash,6776$use_parents? @{$co{'parents'}} :$hash_parent);6777close$fd;6778print"</div>\n";# class="page_body"6779 git_footer_html();67806781}elsif($formateq'plain') {6782local$/=undef;6783print<$fd>;6784close$fd6785or print"Reading git-diff-tree failed\n";6786}elsif($formateq'patch') {6787local$/=undef;6788print<$fd>;6789close$fd6790or print"Reading git-format-patch failed\n";6791}6792}67936794sub git_commitdiff_plain {6795 git_commitdiff(-format =>'plain');6796}67976798# format-patch-style patches6799sub git_patch {6800 git_commitdiff(-format =>'patch', -single =>1);6801}68026803sub git_patches {6804 git_commitdiff(-format =>'patch');6805}68066807sub git_history {6808 git_log_generic('history', \&git_history_body,6809$hash_base,$hash_parent_base,6810$file_name,$hash);6811}68126813sub git_search {6814 gitweb_check_feature('search')or die_error(403,"Search is disabled");6815if(!defined$searchtext) {6816 die_error(400,"Text field is empty");6817}6818if(!defined$hash) {6819$hash= git_get_head_hash($project);6820}6821my%co= parse_commit($hash);6822if(!%co) {6823 die_error(404,"Unknown commit object");6824}6825if(!defined$page) {6826$page=0;6827}68286829$searchtype||='commit';6830if($searchtypeeq'pickaxe') {6831# pickaxe may take all resources of your box and run for several minutes6832# with every query - so decide by yourself how public you make this feature6833 gitweb_check_feature('pickaxe')6834or die_error(403,"Pickaxe is disabled");6835}6836if($searchtypeeq'grep') {6837 gitweb_check_feature('grep')6838or die_error(403,"Grep is disabled");6839}68406841 git_header_html();68426843if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {6844my$greptype;6845if($searchtypeeq'commit') {6846$greptype="--grep=";6847}elsif($searchtypeeq'author') {6848$greptype="--author=";6849}elsif($searchtypeeq'committer') {6850$greptype="--committer=";6851}6852$greptype.=$searchtext;6853my@commitlist= parse_commits($hash,101, (100*$page),undef,6854$greptype,'--regexp-ignore-case',6855$search_use_regexp?'--extended-regexp':'--fixed-strings');68566857my$paging_nav='';6858if($page>0) {6859$paging_nav.=6860$cgi->a({-href => href(action=>"search", hash=>$hash,6861 searchtext=>$searchtext,6862 searchtype=>$searchtype)},6863"first");6864$paging_nav.=" ⋅ ".6865$cgi->a({-href => href(-replay=>1, page=>$page-1),6866-accesskey =>"p", -title =>"Alt-p"},"prev");6867}else{6868$paging_nav.="first";6869$paging_nav.=" ⋅ prev";6870}6871my$next_link='';6872if($#commitlist>=100) {6873$next_link=6874$cgi->a({-href => href(-replay=>1, page=>$page+1),6875-accesskey =>"n", -title =>"Alt-n"},"next");6876$paging_nav.=" ⋅$next_link";6877}else{6878$paging_nav.=" ⋅ next";6879}68806881 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);6882 git_print_header_div('commit', esc_html($co{'title'}),$hash);6883if($page==0&& !@commitlist) {6884print"<p>No match.</p>\n";6885}else{6886 git_search_grep_body(\@commitlist,0,99,$next_link);6887}6888}68896890if($searchtypeeq'pickaxe') {6891 git_print_page_nav('','',$hash,$co{'tree'},$hash);6892 git_print_header_div('commit', esc_html($co{'title'}),$hash);68936894print"<table class=\"pickaxe search\">\n";6895my$alternate=1;6896local$/="\n";6897open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,6898'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",6899($search_use_regexp?'--pickaxe-regex': ());6900undef%co;6901my@files;6902while(my$line= <$fd>) {6903chomp$line;6904next unless$line;69056906my%set= parse_difftree_raw_line($line);6907if(defined$set{'commit'}) {6908# finish previous commit6909if(%co) {6910print"</td>\n".6911"<td class=\"link\">".6912$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6913" | ".6914$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6915print"</td>\n".6916"</tr>\n";6917}69186919if($alternate) {6920print"<tr class=\"dark\">\n";6921}else{6922print"<tr class=\"light\">\n";6923}6924$alternate^=1;6925%co= parse_commit($set{'commit'});6926my$author= chop_and_escape_str($co{'author_name'},15,5);6927print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6928"<td><i>$author</i></td>\n".6929"<td>".6930$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6931-class=>"list subject"},6932 chop_and_escape_str($co{'title'},50) ."<br/>");6933}elsif(defined$set{'to_id'}) {6934next if($set{'to_id'} =~m/^0{40}$/);69356936print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6937 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6938-class=>"list"},6939"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6940"<br/>\n";6941}6942}6943close$fd;69446945# finish last commit (warning: repetition!)6946if(%co) {6947print"</td>\n".6948"<td class=\"link\">".6949$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6950" | ".6951$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6952print"</td>\n".6953"</tr>\n";6954}69556956print"</table>\n";6957}69586959if($searchtypeeq'grep') {6960 git_print_page_nav('','',$hash,$co{'tree'},$hash);6961 git_print_header_div('commit', esc_html($co{'title'}),$hash);69626963print"<table class=\"grep_search\">\n";6964my$alternate=1;6965my$matches=0;6966local$/="\n";6967open my$fd,"-|", git_cmd(),'grep','-n',6968$search_use_regexp? ('-E','-i') :'-F',6969$searchtext,$co{'tree'};6970my$lastfile='';6971while(my$line= <$fd>) {6972chomp$line;6973my($file,$lno,$ltext,$binary);6974last if($matches++>1000);6975if($line=~/^Binary file (.+) matches$/) {6976$file=$1;6977$binary=1;6978}else{6979(undef,$file,$lno,$ltext) =split(/:/,$line,4);6980}6981if($filene$lastfile) {6982$lastfileand print"</td></tr>\n";6983if($alternate++) {6984print"<tr class=\"dark\">\n";6985}else{6986print"<tr class=\"light\">\n";6987}6988print"<td class=\"list\">".6989$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6990 file_name=>"$file"),6991-class=>"list"}, esc_path($file));6992print"</td><td>\n";6993$lastfile=$file;6994}6995if($binary) {6996print"<div class=\"binary\">Binary file</div>\n";6997}else{6998$ltext= untabify($ltext);6999if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {7000$ltext= esc_html($1, -nbsp=>1);7001$ltext.='<span class="match">';7002$ltext.= esc_html($2, -nbsp=>1);7003$ltext.='</span>';7004$ltext.= esc_html($3, -nbsp=>1);7005}else{7006$ltext= esc_html($ltext, -nbsp=>1);7007}7008print"<div class=\"pre\">".7009$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},7010 file_name=>"$file").'#l'.$lno,7011-class=>"linenr"},sprintf('%4i',$lno))7012.' '.$ltext."</div>\n";7013}7014}7015if($lastfile) {7016print"</td></tr>\n";7017if($matches>1000) {7018print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";7019}7020}else{7021print"<div class=\"diff nodifferences\">No matches found</div>\n";7022}7023close$fd;70247025print"</table>\n";7026}7027 git_footer_html();7028}70297030sub git_search_help {7031 git_header_html();7032 git_print_page_nav('','',$hash,$hash,$hash);7033print<<EOT;7034<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without7035regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,7036the pattern entered is recognized as the POSIX extended7037<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case7038insensitive).</p>7039<dl>7040<dt><b>commit</b></dt>7041<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>7042EOT7043my$have_grep= gitweb_check_feature('grep');7044if($have_grep) {7045print<<EOT;7046<dt><b>grep</b></dt>7047<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing7048 a different one) are searched for the given pattern. On large trees, this search can take7049a while and put some strain on the server, so please use it with some consideration. Note that7050due to git-grep peculiarity, currently if regexp mode is turned off, the matches are7051case-sensitive.</dd>7052EOT7053}7054print<<EOT;7055<dt><b>author</b></dt>7056<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>7057<dt><b>committer</b></dt>7058<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>7059EOT7060my$have_pickaxe= gitweb_check_feature('pickaxe');7061if($have_pickaxe) {7062print<<EOT;7063<dt><b>pickaxe</b></dt>7064<dd>All commits that caused the string to appear or disappear from any file (changes that7065added, removed or "modified" the string) will be listed. This search can take a while and7066takes a lot of strain on the server, so please use it wisely. Note that since you may be7067interested even in changes just changing the case as well, this search is case sensitive.</dd>7068EOT7069}7070print"</dl>\n";7071 git_footer_html();7072}70737074sub git_shortlog {7075 git_log_generic('shortlog', \&git_shortlog_body,7076$hash,$hash_parent);7077}70787079## ......................................................................7080## feeds (RSS, Atom; OPML)70817082sub git_feed {7083my$format=shift||'atom';7084my$have_blame= gitweb_check_feature('blame');70857086# Atom: http://www.atomenabled.org/developers/syndication/7087# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ7088if($formatne'rss'&&$formatne'atom') {7089 die_error(400,"Unknown web feed format");7090}70917092# log/feed of current (HEAD) branch, log of given branch, history of file/directory7093my$head=$hash||'HEAD';7094my@commitlist= parse_commits($head,150,0,$file_name);70957096my%latest_commit;7097my%latest_date;7098my$content_type="application/$format+xml";7099if(defined$cgi->http('HTTP_ACCEPT') &&7100$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {7101# browser (feed reader) prefers text/xml7102$content_type='text/xml';7103}7104if(defined($commitlist[0])) {7105%latest_commit= %{$commitlist[0]};7106my$latest_epoch=$latest_commit{'committer_epoch'};7107%latest_date= parse_date($latest_epoch,$latest_commit{'comitter_tz'});7108my$if_modified=$cgi->http('IF_MODIFIED_SINCE');7109if(defined$if_modified) {7110my$since;7111if(eval{require HTTP::Date;1; }) {7112$since= HTTP::Date::str2time($if_modified);7113}elsif(eval{require Time::ParseDate;1; }) {7114$since= Time::ParseDate::parsedate($if_modified, GMT =>1);7115}7116if(defined$since&&$latest_epoch<=$since) {7117print$cgi->header(7118-type =>$content_type,7119-charset =>'utf-8',7120-last_modified =>$latest_date{'rfc2822'},7121-status =>'304 Not Modified');7122return;7123}7124}7125print$cgi->header(7126-type =>$content_type,7127-charset =>'utf-8',7128-last_modified =>$latest_date{'rfc2822'});7129}else{7130print$cgi->header(7131-type =>$content_type,7132-charset =>'utf-8');7133}71347135# Optimization: skip generating the body if client asks only7136# for Last-Modified date.7137return if($cgi->request_method()eq'HEAD');71387139# header variables7140my$title="$site_name-$project/$action";7141my$feed_type='log';7142if(defined$hash) {7143$title.=" - '$hash'";7144$feed_type='branch log';7145if(defined$file_name) {7146$title.=" ::$file_name";7147$feed_type='history';7148}7149}elsif(defined$file_name) {7150$title.=" -$file_name";7151$feed_type='history';7152}7153$title.="$feed_type";7154my$descr= git_get_project_description($project);7155if(defined$descr) {7156$descr= esc_html($descr);7157}else{7158$descr="$project".7159($formateq'rss'?'RSS':'Atom') .7160" feed";7161}7162my$owner= git_get_project_owner($project);7163$owner= esc_html($owner);71647165#header7166my$alt_url;7167if(defined$file_name) {7168$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);7169}elsif(defined$hash) {7170$alt_url= href(-full=>1, action=>"log", hash=>$hash);7171}else{7172$alt_url= href(-full=>1, action=>"summary");7173}7174print qq!<?xml version="1.0" encoding="utf-8"?>\n!;7175if($formateq'rss') {7176print<<XML;7177<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">7178<channel>7179XML7180print"<title>$title</title>\n".7181"<link>$alt_url</link>\n".7182"<description>$descr</description>\n".7183"<language>en</language>\n".7184# project owner is responsible for 'editorial' content7185"<managingEditor>$owner</managingEditor>\n";7186if(defined$logo||defined$favicon) {7187# prefer the logo to the favicon, since RSS7188# doesn't allow both7189my$img= esc_url($logo||$favicon);7190print"<image>\n".7191"<url>$img</url>\n".7192"<title>$title</title>\n".7193"<link>$alt_url</link>\n".7194"</image>\n";7195}7196if(%latest_date) {7197print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";7198print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";7199}7200print"<generator>gitweb v.$version/$git_version</generator>\n";7201}elsif($formateq'atom') {7202print<<XML;7203<feed xmlns="http://www.w3.org/2005/Atom">7204XML7205print"<title>$title</title>\n".7206"<subtitle>$descr</subtitle>\n".7207'<link rel="alternate" type="text/html" href="'.7208$alt_url.'" />'."\n".7209'<link rel="self" type="'.$content_type.'" href="'.7210$cgi->self_url() .'" />'."\n".7211"<id>". href(-full=>1) ."</id>\n".7212# use project owner for feed author7213"<author><name>$owner</name></author>\n";7214if(defined$favicon) {7215print"<icon>". esc_url($favicon) ."</icon>\n";7216}7217if(defined$logo) {7218# not twice as wide as tall: 72 x 27 pixels7219print"<logo>". esc_url($logo) ."</logo>\n";7220}7221if(!%latest_date) {7222# dummy date to keep the feed valid until commits trickle in:7223print"<updated>1970-01-01T00:00:00Z</updated>\n";7224}else{7225print"<updated>$latest_date{'iso-8601'}</updated>\n";7226}7227print"<generator version='$version/$git_version'>gitweb</generator>\n";7228}72297230# contents7231for(my$i=0;$i<=$#commitlist;$i++) {7232my%co= %{$commitlist[$i]};7233my$commit=$co{'id'};7234# we read 150, we always show 30 and the ones more recent than 48 hours7235if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {7236last;7237}7238my%cd= parse_date($co{'author_epoch'},$co{'author_tz'});72397240# get list of changed files7241open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7242$co{'parent'} ||"--root",7243$co{'id'},"--", (defined$file_name?$file_name: ())7244ornext;7245my@difftree=map{chomp;$_} <$fd>;7246close$fd7247ornext;72487249# print element (entry, item)7250my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);7251if($formateq'rss') {7252print"<item>\n".7253"<title>". esc_html($co{'title'}) ."</title>\n".7254"<author>". esc_html($co{'author'}) ."</author>\n".7255"<pubDate>$cd{'rfc2822'}</pubDate>\n".7256"<guid isPermaLink=\"true\">$co_url</guid>\n".7257"<link>$co_url</link>\n".7258"<description>". esc_html($co{'title'}) ."</description>\n".7259"<content:encoded>".7260"<![CDATA[\n";7261}elsif($formateq'atom') {7262print"<entry>\n".7263"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".7264"<updated>$cd{'iso-8601'}</updated>\n".7265"<author>\n".7266" <name>". esc_html($co{'author_name'}) ."</name>\n";7267if($co{'author_email'}) {7268print" <email>". esc_html($co{'author_email'}) ."</email>\n";7269}7270print"</author>\n".7271# use committer for contributor7272"<contributor>\n".7273" <name>". esc_html($co{'committer_name'}) ."</name>\n";7274if($co{'committer_email'}) {7275print" <email>". esc_html($co{'committer_email'}) ."</email>\n";7276}7277print"</contributor>\n".7278"<published>$cd{'iso-8601'}</published>\n".7279"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".7280"<id>$co_url</id>\n".7281"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".7282"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";7283}7284my$comment=$co{'comment'};7285print"<pre>\n";7286foreachmy$line(@$comment) {7287$line= esc_html($line);7288print"$line\n";7289}7290print"</pre><ul>\n";7291foreachmy$difftree_line(@difftree) {7292my%difftree= parse_difftree_raw_line($difftree_line);7293next if!$difftree{'from_id'};72947295my$file=$difftree{'file'} ||$difftree{'to_file'};72967297print"<li>".7298"[".7299$cgi->a({-href => href(-full=>1, action=>"blobdiff",7300 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},7301 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},7302 file_name=>$file, file_parent=>$difftree{'from_file'}),7303-title =>"diff"},'D');7304if($have_blame) {7305print$cgi->a({-href => href(-full=>1, action=>"blame",7306 file_name=>$file, hash_base=>$commit),7307-title =>"blame"},'B');7308}7309# if this is not a feed of a file history7310if(!defined$file_name||$file_namene$file) {7311print$cgi->a({-href => href(-full=>1, action=>"history",7312 file_name=>$file, hash=>$commit),7313-title =>"history"},'H');7314}7315$file= esc_path($file);7316print"] ".7317"$file</li>\n";7318}7319if($formateq'rss') {7320print"</ul>]]>\n".7321"</content:encoded>\n".7322"</item>\n";7323}elsif($formateq'atom') {7324print"</ul>\n</div>\n".7325"</content>\n".7326"</entry>\n";7327}7328}73297330# end of feed7331if($formateq'rss') {7332print"</channel>\n</rss>\n";7333}elsif($formateq'atom') {7334print"</feed>\n";7335}7336}73377338sub git_rss {7339 git_feed('rss');7340}73417342sub git_atom {7343 git_feed('atom');7344}73457346sub git_opml {7347my@list= git_get_projects_list();73487349print$cgi->header(7350-type =>'text/xml',7351-charset =>'utf-8',7352-content_disposition =>'inline; filename="opml.xml"');73537354print<<XML;7355<?xml version="1.0" encoding="utf-8"?>7356<opml version="1.0">7357<head>7358 <title>$site_nameOPML Export</title>7359</head>7360<body>7361<outline text="git RSS feeds">7362XML73637364foreachmy$pr(@list) {7365my%proj=%$pr;7366my$head= git_get_head_hash($proj{'path'});7367if(!defined$head) {7368next;7369}7370$git_dir="$projectroot/$proj{'path'}";7371my%co= parse_commit($head);7372if(!%co) {7373next;7374}73757376my$path= esc_html(chop_str($proj{'path'},25,5));7377my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);7378my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);7379print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";7380}7381print<<XML;7382</outline>7383</body>7384</opml>7385XML7386}