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), 254# alternate extensions, see /etc/highlight/filetypes.conf 255'h'=>'c', 256map{$_=>'cpp'}qw(cxx c++ cc), 257map{$_=>'php'}qw(php3 php4), 258map{$_=>'pl'}qw(perl pm),# perhaps also 'cgi' 259'mak'=>'make', 260map{$_=>'xml'}qw(xhtml html htm), 261); 262 263# You define site-wide feature defaults here; override them with 264# $GITWEB_CONFIG as necessary. 265our%feature= ( 266# feature => { 267# 'sub' => feature-sub (subroutine), 268# 'override' => allow-override (boolean), 269# 'default' => [ default options...] (array reference)} 270# 271# if feature is overridable (it means that allow-override has true value), 272# then feature-sub will be called with default options as parameters; 273# return value of feature-sub indicates if to enable specified feature 274# 275# if there is no 'sub' key (no feature-sub), then feature cannot be 276# overridden 277# 278# use gitweb_get_feature(<feature>) to retrieve the <feature> value 279# (an array) or gitweb_check_feature(<feature>) to check if <feature> 280# is enabled 281 282# Enable the 'blame' blob view, showing the last commit that modified 283# each line in the file. This can be very CPU-intensive. 284 285# To enable system wide have in $GITWEB_CONFIG 286# $feature{'blame'}{'default'} = [1]; 287# To have project specific config enable override in $GITWEB_CONFIG 288# $feature{'blame'}{'override'} = 1; 289# and in project config gitweb.blame = 0|1; 290'blame'=> { 291'sub'=>sub{ feature_bool('blame',@_) }, 292'override'=>0, 293'default'=> [0]}, 294 295# Enable the 'snapshot' link, providing a compressed archive of any 296# tree. This can potentially generate high traffic if you have large 297# project. 298 299# Value is a list of formats defined in %known_snapshot_formats that 300# you wish to offer. 301# To disable system wide have in $GITWEB_CONFIG 302# $feature{'snapshot'}{'default'} = []; 303# To have project specific config enable override in $GITWEB_CONFIG 304# $feature{'snapshot'}{'override'} = 1; 305# and in project config, a comma-separated list of formats or "none" 306# to disable. Example: gitweb.snapshot = tbz2,zip; 307'snapshot'=> { 308'sub'=> \&feature_snapshot, 309'override'=>0, 310'default'=> ['tgz']}, 311 312# Enable text search, which will list the commits which match author, 313# committer or commit text to a given string. Enabled by default. 314# Project specific override is not supported. 315'search'=> { 316'override'=>0, 317'default'=> [1]}, 318 319# Enable grep search, which will list the files in currently selected 320# tree containing the given string. Enabled by default. This can be 321# potentially CPU-intensive, of course. 322 323# To enable system wide have in $GITWEB_CONFIG 324# $feature{'grep'}{'default'} = [1]; 325# To have project specific config enable override in $GITWEB_CONFIG 326# $feature{'grep'}{'override'} = 1; 327# and in project config gitweb.grep = 0|1; 328'grep'=> { 329'sub'=>sub{ feature_bool('grep',@_) }, 330'override'=>0, 331'default'=> [1]}, 332 333# Enable the pickaxe search, which will list the commits that modified 334# a given string in a file. This can be practical and quite faster 335# alternative to 'blame', but still potentially CPU-intensive. 336 337# To enable system wide have in $GITWEB_CONFIG 338# $feature{'pickaxe'}{'default'} = [1]; 339# To have project specific config enable override in $GITWEB_CONFIG 340# $feature{'pickaxe'}{'override'} = 1; 341# and in project config gitweb.pickaxe = 0|1; 342'pickaxe'=> { 343'sub'=>sub{ feature_bool('pickaxe',@_) }, 344'override'=>0, 345'default'=> [1]}, 346 347# Enable showing size of blobs in a 'tree' view, in a separate 348# column, similar to what 'ls -l' does. This cost a bit of IO. 349 350# To disable system wide have in $GITWEB_CONFIG 351# $feature{'show-sizes'}{'default'} = [0]; 352# To have project specific config enable override in $GITWEB_CONFIG 353# $feature{'show-sizes'}{'override'} = 1; 354# and in project config gitweb.showsizes = 0|1; 355'show-sizes'=> { 356'sub'=>sub{ feature_bool('showsizes',@_) }, 357'override'=>0, 358'default'=> [1]}, 359 360# Make gitweb use an alternative format of the URLs which can be 361# more readable and natural-looking: project name is embedded 362# directly in the path and the query string contains other 363# auxiliary information. All gitweb installations recognize 364# URL in either format; this configures in which formats gitweb 365# generates links. 366 367# To enable system wide have in $GITWEB_CONFIG 368# $feature{'pathinfo'}{'default'} = [1]; 369# Project specific override is not supported. 370 371# Note that you will need to change the default location of CSS, 372# favicon, logo and possibly other files to an absolute URL. Also, 373# if gitweb.cgi serves as your indexfile, you will need to force 374# $my_uri to contain the script name in your $GITWEB_CONFIG. 375'pathinfo'=> { 376'override'=>0, 377'default'=> [0]}, 378 379# Make gitweb consider projects in project root subdirectories 380# to be forks of existing projects. Given project $projname.git, 381# projects matching $projname/*.git will not be shown in the main 382# projects list, instead a '+' mark will be added to $projname 383# there and a 'forks' view will be enabled for the project, listing 384# all the forks. If project list is taken from a file, forks have 385# to be listed after the main project. 386 387# To enable system wide have in $GITWEB_CONFIG 388# $feature{'forks'}{'default'} = [1]; 389# Project specific override is not supported. 390'forks'=> { 391'override'=>0, 392'default'=> [0]}, 393 394# Insert custom links to the action bar of all project pages. 395# This enables you mainly to link to third-party scripts integrating 396# into gitweb; e.g. git-browser for graphical history representation 397# or custom web-based repository administration interface. 398 399# The 'default' value consists of a list of triplets in the form 400# (label, link, position) where position is the label after which 401# to insert the link and link is a format string where %n expands 402# to the project name, %f to the project path within the filesystem, 403# %h to the current hash (h gitweb parameter) and %b to the current 404# hash base (hb gitweb parameter); %% expands to %. 405 406# To enable system wide have in $GITWEB_CONFIG e.g. 407# $feature{'actions'}{'default'} = [('graphiclog', 408# '/git-browser/by-commit.html?r=%n', 'summary')]; 409# Project specific override is not supported. 410'actions'=> { 411'override'=>0, 412'default'=> []}, 413 414# Allow gitweb scan project content tags described in ctags/ 415# of project repository, and display the popular Web 2.0-ish 416# "tag cloud" near the project list. Note that this is something 417# COMPLETELY different from the normal Git tags. 418 419# gitweb by itself can show existing tags, but it does not handle 420# tagging itself; you need an external application for that. 421# For an example script, check Girocco's cgi/tagproj.cgi. 422# You may want to install the HTML::TagCloud Perl module to get 423# a pretty tag cloud instead of just a list of tags. 424 425# To enable system wide have in $GITWEB_CONFIG 426# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 427# Project specific override is not supported. 428'ctags'=> { 429'override'=>0, 430'default'=> [0]}, 431 432# The maximum number of patches in a patchset generated in patch 433# view. Set this to 0 or undef to disable patch view, or to a 434# negative number to remove any limit. 435 436# To disable system wide have in $GITWEB_CONFIG 437# $feature{'patches'}{'default'} = [0]; 438# To have project specific config enable override in $GITWEB_CONFIG 439# $feature{'patches'}{'override'} = 1; 440# and in project config gitweb.patches = 0|n; 441# where n is the maximum number of patches allowed in a patchset. 442'patches'=> { 443'sub'=> \&feature_patches, 444'override'=>0, 445'default'=> [16]}, 446 447# Avatar support. When this feature is enabled, views such as 448# shortlog or commit will display an avatar associated with 449# the email of the committer(s) and/or author(s). 450 451# Currently available providers are gravatar and picon. 452# If an unknown provider is specified, the feature is disabled. 453 454# Gravatar depends on Digest::MD5. 455# Picon currently relies on the indiana.edu database. 456 457# To enable system wide have in $GITWEB_CONFIG 458# $feature{'avatar'}{'default'} = ['<provider>']; 459# where <provider> is either gravatar or picon. 460# To have project specific config enable override in $GITWEB_CONFIG 461# $feature{'avatar'}{'override'} = 1; 462# and in project config gitweb.avatar = <provider>; 463'avatar'=> { 464'sub'=> \&feature_avatar, 465'override'=>0, 466'default'=> ['']}, 467 468# Enable displaying how much time and how many git commands 469# it took to generate and display page. Disabled by default. 470# Project specific override is not supported. 471'timed'=> { 472'override'=>0, 473'default'=> [0]}, 474 475# Enable turning some links into links to actions which require 476# JavaScript to run (like 'blame_incremental'). Not enabled by 477# default. Project specific override is currently not supported. 478'javascript-actions'=> { 479'override'=>0, 480'default'=> [0]}, 481 482# Syntax highlighting support. This is based on Daniel Svensson's 483# and Sham Chukoury's work in gitweb-xmms2.git. 484# It requires the 'highlight' program present in $PATH, 485# and therefore is disabled by default. 486 487# To enable system wide have in $GITWEB_CONFIG 488# $feature{'highlight'}{'default'} = [1]; 489 490'highlight'=> { 491'sub'=>sub{ feature_bool('highlight',@_) }, 492'override'=>0, 493'default'=> [0]}, 494 495# Enable displaying of remote heads in the heads list 496 497# To enable system wide have in $GITWEB_CONFIG 498# $feature{'remote_heads'}{'default'} = [1]; 499# To have project specific config enable override in $GITWEB_CONFIG 500# $feature{'remote_heads'}{'override'} = 1; 501# and in project config gitweb.remote_heads = 0|1; 502'remote_heads'=> { 503'sub'=>sub{ feature_bool('remote_heads',@_) }, 504'override'=>0, 505'default'=> [0]}, 506); 507 508sub gitweb_get_feature { 509my($name) =@_; 510return unlessexists$feature{$name}; 511my($sub,$override,@defaults) = ( 512$feature{$name}{'sub'}, 513$feature{$name}{'override'}, 514@{$feature{$name}{'default'}}); 515# project specific override is possible only if we have project 516our$git_dir;# global variable, declared later 517if(!$override|| !defined$git_dir) { 518return@defaults; 519} 520if(!defined$sub) { 521warn"feature$nameis not overridable"; 522return@defaults; 523} 524return$sub->(@defaults); 525} 526 527# A wrapper to check if a given feature is enabled. 528# With this, you can say 529# 530# my $bool_feat = gitweb_check_feature('bool_feat'); 531# gitweb_check_feature('bool_feat') or somecode; 532# 533# instead of 534# 535# my ($bool_feat) = gitweb_get_feature('bool_feat'); 536# (gitweb_get_feature('bool_feat'))[0] or somecode; 537# 538sub gitweb_check_feature { 539return(gitweb_get_feature(@_))[0]; 540} 541 542 543sub feature_bool { 544my$key=shift; 545my($val) = git_get_project_config($key,'--bool'); 546 547if(!defined$val) { 548return($_[0]); 549}elsif($valeq'true') { 550return(1); 551}elsif($valeq'false') { 552return(0); 553} 554} 555 556sub feature_snapshot { 557my(@fmts) =@_; 558 559my($val) = git_get_project_config('snapshot'); 560 561if($val) { 562@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 563} 564 565return@fmts; 566} 567 568sub feature_patches { 569my@val= (git_get_project_config('patches','--int')); 570 571if(@val) { 572return@val; 573} 574 575return($_[0]); 576} 577 578sub feature_avatar { 579my@val= (git_get_project_config('avatar')); 580 581return@val?@val:@_; 582} 583 584# checking HEAD file with -e is fragile if the repository was 585# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 586# and then pruned. 587sub check_head_link { 588my($dir) =@_; 589my$headfile="$dir/HEAD"; 590return((-e $headfile) || 591(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 592} 593 594sub check_export_ok { 595my($dir) =@_; 596return(check_head_link($dir) && 597(!$export_ok|| -e "$dir/$export_ok") && 598(!$export_auth_hook||$export_auth_hook->($dir))); 599} 600 601# process alternate names for backward compatibility 602# filter out unsupported (unknown) snapshot formats 603sub filter_snapshot_fmts { 604my@fmts=@_; 605 606@fmts=map{ 607exists$known_snapshot_format_aliases{$_} ? 608$known_snapshot_format_aliases{$_} :$_}@fmts; 609@fmts=grep{ 610exists$known_snapshot_formats{$_} && 611!$known_snapshot_formats{$_}{'disabled'}}@fmts; 612} 613 614# If it is set to code reference, it is code that it is to be run once per 615# request, allowing updating configurations that change with each request, 616# while running other code in config file only once. 617# 618# Otherwise, if it is false then gitweb would process config file only once; 619# if it is true then gitweb config would be run for each request. 620our$per_request_config=1; 621 622our($GITWEB_CONFIG,$GITWEB_CONFIG_SYSTEM); 623sub evaluate_gitweb_config { 624our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 625our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 626# die if there are errors parsing config file 627if(-e $GITWEB_CONFIG) { 628do$GITWEB_CONFIG; 629die$@if$@; 630}elsif(-e $GITWEB_CONFIG_SYSTEM) { 631do$GITWEB_CONFIG_SYSTEM; 632die$@if$@; 633} 634} 635 636# Get loadavg of system, to compare against $maxload. 637# Currently it requires '/proc/loadavg' present to get loadavg; 638# if it is not present it returns 0, which means no load checking. 639sub get_loadavg { 640if( -e '/proc/loadavg'){ 641open my$fd,'<','/proc/loadavg' 642orreturn0; 643my@load=split(/\s+/,scalar<$fd>); 644close$fd; 645 646# The first three columns measure CPU and IO utilization of the last one, 647# five, and 10 minute periods. The fourth column shows the number of 648# currently running processes and the total number of processes in the m/n 649# format. The last column displays the last process ID used. 650return$load[0] ||0; 651} 652# additional checks for load average should go here for things that don't export 653# /proc/loadavg 654 655return0; 656} 657 658# version of the core git binary 659our$git_version; 660sub evaluate_git_version { 661our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 662$number_of_git_cmds++; 663} 664 665sub check_loadavg { 666if(defined$maxload&& get_loadavg() >$maxload) { 667 die_error(503,"The load average on the server is too high"); 668} 669} 670 671# ====================================================================== 672# input validation and dispatch 673 674# input parameters can be collected from a variety of sources (presently, CGI 675# and PATH_INFO), so we define an %input_params hash that collects them all 676# together during validation: this allows subsequent uses (e.g. href()) to be 677# agnostic of the parameter origin 678 679our%input_params= (); 680 681# input parameters are stored with the long parameter name as key. This will 682# also be used in the href subroutine to convert parameters to their CGI 683# equivalent, and since the href() usage is the most frequent one, we store 684# the name -> CGI key mapping here, instead of the reverse. 685# 686# XXX: Warning: If you touch this, check the search form for updating, 687# too. 688 689our@cgi_param_mapping= ( 690 project =>"p", 691 action =>"a", 692 file_name =>"f", 693 file_parent =>"fp", 694 hash =>"h", 695 hash_parent =>"hp", 696 hash_base =>"hb", 697 hash_parent_base =>"hpb", 698 page =>"pg", 699 order =>"o", 700 searchtext =>"s", 701 searchtype =>"st", 702 snapshot_format =>"sf", 703 extra_options =>"opt", 704 search_use_regexp =>"sr", 705# this must be last entry (for manipulation from JavaScript) 706 javascript =>"js" 707); 708our%cgi_param_mapping=@cgi_param_mapping; 709 710# we will also need to know the possible actions, for validation 711our%actions= ( 712"blame"=> \&git_blame, 713"blame_incremental"=> \&git_blame_incremental, 714"blame_data"=> \&git_blame_data, 715"blobdiff"=> \&git_blobdiff, 716"blobdiff_plain"=> \&git_blobdiff_plain, 717"blob"=> \&git_blob, 718"blob_plain"=> \&git_blob_plain, 719"commitdiff"=> \&git_commitdiff, 720"commitdiff_plain"=> \&git_commitdiff_plain, 721"commit"=> \&git_commit, 722"forks"=> \&git_forks, 723"heads"=> \&git_heads, 724"history"=> \&git_history, 725"log"=> \&git_log, 726"patch"=> \&git_patch, 727"patches"=> \&git_patches, 728"remotes"=> \&git_remotes, 729"rss"=> \&git_rss, 730"atom"=> \&git_atom, 731"search"=> \&git_search, 732"search_help"=> \&git_search_help, 733"shortlog"=> \&git_shortlog, 734"summary"=> \&git_summary, 735"tag"=> \&git_tag, 736"tags"=> \&git_tags, 737"tree"=> \&git_tree, 738"snapshot"=> \&git_snapshot, 739"object"=> \&git_object, 740# those below don't need $project 741"opml"=> \&git_opml, 742"project_list"=> \&git_project_list, 743"project_index"=> \&git_project_index, 744); 745 746# finally, we have the hash of allowed extra_options for the commands that 747# allow them 748our%allowed_options= ( 749"--no-merges"=> [qw(rss atom log shortlog history)], 750); 751 752# fill %input_params with the CGI parameters. All values except for 'opt' 753# should be single values, but opt can be an array. We should probably 754# build an array of parameters that can be multi-valued, but since for the time 755# being it's only this one, we just single it out 756sub evaluate_query_params { 757our$cgi; 758 759while(my($name,$symbol) =each%cgi_param_mapping) { 760if($symboleq'opt') { 761$input_params{$name} = [$cgi->param($symbol) ]; 762}else{ 763$input_params{$name} =$cgi->param($symbol); 764} 765} 766} 767 768# now read PATH_INFO and update the parameter list for missing parameters 769sub evaluate_path_info { 770return ifdefined$input_params{'project'}; 771return if!$path_info; 772$path_info=~ s,^/+,,; 773return if!$path_info; 774 775# find which part of PATH_INFO is project 776my$project=$path_info; 777$project=~ s,/+$,,; 778while($project&& !check_head_link("$projectroot/$project")) { 779$project=~ s,/*[^/]*$,,; 780} 781return unless$project; 782$input_params{'project'} =$project; 783 784# do not change any parameters if an action is given using the query string 785return if$input_params{'action'}; 786$path_info=~ s,^\Q$project\E/*,,; 787 788# next, check if we have an action 789my$action=$path_info; 790$action=~ s,/.*$,,; 791if(exists$actions{$action}) { 792$path_info=~ s,^$action/*,,; 793$input_params{'action'} =$action; 794} 795 796# list of actions that want hash_base instead of hash, but can have no 797# pathname (f) parameter 798my@wants_base= ( 799'tree', 800'history', 801); 802 803# we want to catch, among others 804# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 805my($parentrefname,$parentpathname,$refname,$pathname) = 806($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?([^:]+?)?(?::(.+))?$/); 807 808# first, analyze the 'current' part 809if(defined$pathname) { 810# we got "branch:filename" or "branch:dir/" 811# we could use git_get_type(branch:pathname), but: 812# - it needs $git_dir 813# - it does a git() call 814# - the convention of terminating directories with a slash 815# makes it superfluous 816# - embedding the action in the PATH_INFO would make it even 817# more superfluous 818$pathname=~ s,^/+,,; 819if(!$pathname||substr($pathname, -1)eq"/") { 820$input_params{'action'} ||="tree"; 821$pathname=~ s,/$,,; 822}else{ 823# the default action depends on whether we had parent info 824# or not 825if($parentrefname) { 826$input_params{'action'} ||="blobdiff_plain"; 827}else{ 828$input_params{'action'} ||="blob_plain"; 829} 830} 831$input_params{'hash_base'} ||=$refname; 832$input_params{'file_name'} ||=$pathname; 833}elsif(defined$refname) { 834# we got "branch". In this case we have to choose if we have to 835# set hash or hash_base. 836# 837# Most of the actions without a pathname only want hash to be 838# set, except for the ones specified in @wants_base that want 839# hash_base instead. It should also be noted that hand-crafted 840# links having 'history' as an action and no pathname or hash 841# set will fail, but that happens regardless of PATH_INFO. 842if(defined$parentrefname) { 843# if there is parent let the default be 'shortlog' action 844# (for http://git.example.com/repo.git/A..B links); if there 845# is no parent, dispatch will detect type of object and set 846# action appropriately if required (if action is not set) 847$input_params{'action'} ||="shortlog"; 848} 849if($input_params{'action'} && 850grep{$_eq$input_params{'action'} }@wants_base) { 851$input_params{'hash_base'} ||=$refname; 852}else{ 853$input_params{'hash'} ||=$refname; 854} 855} 856 857# next, handle the 'parent' part, if present 858if(defined$parentrefname) { 859# a missing pathspec defaults to the 'current' filename, allowing e.g. 860# someproject/blobdiff/oldrev..newrev:/filename 861if($parentpathname) { 862$parentpathname=~ s,^/+,,; 863$parentpathname=~ s,/$,,; 864$input_params{'file_parent'} ||=$parentpathname; 865}else{ 866$input_params{'file_parent'} ||=$input_params{'file_name'}; 867} 868# we assume that hash_parent_base is wanted if a path was specified, 869# or if the action wants hash_base instead of hash 870if(defined$input_params{'file_parent'} || 871grep{$_eq$input_params{'action'} }@wants_base) { 872$input_params{'hash_parent_base'} ||=$parentrefname; 873}else{ 874$input_params{'hash_parent'} ||=$parentrefname; 875} 876} 877 878# for the snapshot action, we allow URLs in the form 879# $project/snapshot/$hash.ext 880# where .ext determines the snapshot and gets removed from the 881# passed $refname to provide the $hash. 882# 883# To be able to tell that $refname includes the format extension, we 884# require the following two conditions to be satisfied: 885# - the hash input parameter MUST have been set from the $refname part 886# of the URL (i.e. they must be equal) 887# - the snapshot format MUST NOT have been defined already (e.g. from 888# CGI parameter sf) 889# It's also useless to try any matching unless $refname has a dot, 890# so we check for that too 891if(defined$input_params{'action'} && 892$input_params{'action'}eq'snapshot'&& 893defined$refname&&index($refname,'.') != -1&& 894$refnameeq$input_params{'hash'} && 895!defined$input_params{'snapshot_format'}) { 896# We loop over the known snapshot formats, checking for 897# extensions. Allowed extensions are both the defined suffix 898# (which includes the initial dot already) and the snapshot 899# format key itself, with a prepended dot 900while(my($fmt,$opt) =each%known_snapshot_formats) { 901my$hash=$refname; 902unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 903next; 904} 905my$sfx=$1; 906# a valid suffix was found, so set the snapshot format 907# and reset the hash parameter 908$input_params{'snapshot_format'} =$fmt; 909$input_params{'hash'} =$hash; 910# we also set the format suffix to the one requested 911# in the URL: this way a request for e.g. .tgz returns 912# a .tgz instead of a .tar.gz 913$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 914last; 915} 916} 917} 918 919our($action,$project,$file_name,$file_parent,$hash,$hash_parent,$hash_base, 920$hash_parent_base,@extra_options,$page,$searchtype,$search_use_regexp, 921$searchtext,$search_regexp); 922sub evaluate_and_validate_params { 923our$action=$input_params{'action'}; 924if(defined$action) { 925if(!validate_action($action)) { 926 die_error(400,"Invalid action parameter"); 927} 928} 929 930# parameters which are pathnames 931our$project=$input_params{'project'}; 932if(defined$project) { 933if(!validate_project($project)) { 934undef$project; 935 die_error(404,"No such project"); 936} 937} 938 939our$file_name=$input_params{'file_name'}; 940if(defined$file_name) { 941if(!validate_pathname($file_name)) { 942 die_error(400,"Invalid file parameter"); 943} 944} 945 946our$file_parent=$input_params{'file_parent'}; 947if(defined$file_parent) { 948if(!validate_pathname($file_parent)) { 949 die_error(400,"Invalid file parent parameter"); 950} 951} 952 953# parameters which are refnames 954our$hash=$input_params{'hash'}; 955if(defined$hash) { 956if(!validate_refname($hash)) { 957 die_error(400,"Invalid hash parameter"); 958} 959} 960 961our$hash_parent=$input_params{'hash_parent'}; 962if(defined$hash_parent) { 963if(!validate_refname($hash_parent)) { 964 die_error(400,"Invalid hash parent parameter"); 965} 966} 967 968our$hash_base=$input_params{'hash_base'}; 969if(defined$hash_base) { 970if(!validate_refname($hash_base)) { 971 die_error(400,"Invalid hash base parameter"); 972} 973} 974 975our@extra_options= @{$input_params{'extra_options'}}; 976# @extra_options is always defined, since it can only be (currently) set from 977# CGI, and $cgi->param() returns the empty array in array context if the param 978# is not set 979foreachmy$opt(@extra_options) { 980if(not exists$allowed_options{$opt}) { 981 die_error(400,"Invalid option parameter"); 982} 983if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 984 die_error(400,"Invalid option parameter for this action"); 985} 986} 987 988our$hash_parent_base=$input_params{'hash_parent_base'}; 989if(defined$hash_parent_base) { 990if(!validate_refname($hash_parent_base)) { 991 die_error(400,"Invalid hash parent base parameter"); 992} 993} 994 995# other parameters 996our$page=$input_params{'page'}; 997if(defined$page) { 998if($page=~m/[^0-9]/) { 999 die_error(400,"Invalid page parameter");1000}1001}10021003our$searchtype=$input_params{'searchtype'};1004if(defined$searchtype) {1005if($searchtype=~m/[^a-z]/) {1006 die_error(400,"Invalid searchtype parameter");1007}1008}10091010our$search_use_regexp=$input_params{'search_use_regexp'};10111012our$searchtext=$input_params{'searchtext'};1013our$search_regexp;1014if(defined$searchtext) {1015if(length($searchtext) <2) {1016 die_error(403,"At least two characters are required for search parameter");1017}1018$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext;1019}1020}10211022# path to the current git repository1023our$git_dir;1024sub evaluate_git_dir {1025our$git_dir="$projectroot/$project"if$project;1026}10271028our(@snapshot_fmts,$git_avatar);1029sub configure_gitweb_features {1030# list of supported snapshot formats1031our@snapshot_fmts= gitweb_get_feature('snapshot');1032@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts);10331034# check that the avatar feature is set to a known provider name,1035# and for each provider check if the dependencies are satisfied.1036# if the provider name is invalid or the dependencies are not met,1037# reset $git_avatar to the empty string.1038our($git_avatar) = gitweb_get_feature('avatar');1039if($git_avatareq'gravatar') {1040$git_avatar=''unless(eval{require Digest::MD5;1; });1041}elsif($git_avatareq'picon') {1042# no dependencies1043}else{1044$git_avatar='';1045}1046}10471048# custom error handler: 'die <message>' is Internal Server Error1049sub handle_errors_html {1050my$msg=shift;# it is already HTML escaped10511052# to avoid infinite loop where error occurs in die_error,1053# change handler to default handler, disabling handle_errors_html1054 set_message("Error occured when inside die_error:\n$msg");10551056# you cannot jump out of die_error when called as error handler;1057# the subroutine set via CGI::Carp::set_message is called _after_1058# HTTP headers are already written, so it cannot write them itself1059 die_error(undef,undef,$msg, -error_handler =>1, -no_http_header =>1);1060}1061set_message(\&handle_errors_html);10621063# dispatch1064sub dispatch {1065if(!defined$action) {1066if(defined$hash) {1067$action= git_get_type($hash);1068}elsif(defined$hash_base&&defined$file_name) {1069$action= git_get_type("$hash_base:$file_name");1070}elsif(defined$project) {1071$action='summary';1072}else{1073$action='project_list';1074}1075}1076if(!defined($actions{$action})) {1077 die_error(400,"Unknown action");1078}1079if($action!~m/^(?:opml|project_list|project_index)$/&&1080!$project) {1081 die_error(400,"Project needed");1082}1083$actions{$action}->();1084}10851086sub reset_timer {1087our$t0= [ gettimeofday() ]1088ifdefined$t0;1089our$number_of_git_cmds=0;1090}10911092our$first_request=1;1093sub run_request {1094 reset_timer();10951096 evaluate_uri();1097if($first_request) {1098 evaluate_gitweb_config();1099 evaluate_git_version();1100}1101if($per_request_config) {1102if(ref($per_request_config)eq'CODE') {1103$per_request_config->();1104}elsif(!$first_request) {1105 evaluate_gitweb_config();1106}1107}1108 check_loadavg();11091110# $projectroot and $projects_list might be set in gitweb config file1111$projects_list||=$projectroot;11121113 evaluate_query_params();1114 evaluate_path_info();1115 evaluate_and_validate_params();1116 evaluate_git_dir();11171118 configure_gitweb_features();11191120 dispatch();1121}11221123our$is_last_request=sub{1};1124our($pre_dispatch_hook,$post_dispatch_hook,$pre_listen_hook);1125our$CGI='CGI';1126our$cgi;1127sub configure_as_fcgi {1128require CGI::Fast;1129our$CGI='CGI::Fast';11301131my$request_number=0;1132# let each child service 100 requests1133our$is_last_request=sub{ ++$request_number>100};1134}1135sub evaluate_argv {1136my$script_name=$ENV{'SCRIPT_NAME'} ||$ENV{'SCRIPT_FILENAME'} || __FILE__;1137 configure_as_fcgi()1138if$script_name=~/\.fcgi$/;11391140return unless(@ARGV);11411142require Getopt::Long;1143 Getopt::Long::GetOptions(1144'fastcgi|fcgi|f'=> \&configure_as_fcgi,1145'nproc|n=i'=>sub{1146my($arg,$val) =@_;1147return unlesseval{require FCGI::ProcManager;1; };1148my$proc_manager= FCGI::ProcManager->new({1149 n_processes =>$val,1150});1151our$pre_listen_hook=sub{$proc_manager->pm_manage() };1152our$pre_dispatch_hook=sub{$proc_manager->pm_pre_dispatch() };1153our$post_dispatch_hook=sub{$proc_manager->pm_post_dispatch() };1154},1155);1156}11571158sub run {1159 evaluate_argv();11601161$first_request=1;1162$pre_listen_hook->()1163if$pre_listen_hook;11641165 REQUEST:1166while($cgi=$CGI->new()) {1167$pre_dispatch_hook->()1168if$pre_dispatch_hook;11691170 run_request();11711172$post_dispatch_hook->()1173if$post_dispatch_hook;1174$first_request=0;11751176last REQUEST if($is_last_request->());1177}11781179 DONE_GITWEB:11801;1181}11821183run();11841185if(defined caller) {1186# wrapped in a subroutine processing requests,1187# e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI1188return;1189}else{1190# pure CGI script, serving single request1191exit;1192}11931194## ======================================================================1195## action links11961197# possible values of extra options1198# -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)1199# -replay => 1 - start from a current view (replay with modifications)1200# -path_info => 0|1 - don't use/use path_info URL (if possible)1201sub href {1202my%params=@_;1203# default is to use -absolute url() i.e. $my_uri1204my$href=$params{-full} ?$my_url:$my_uri;12051206$params{'project'} =$projectunlessexists$params{'project'};12071208if($params{-replay}) {1209while(my($name,$symbol) =each%cgi_param_mapping) {1210if(!exists$params{$name}) {1211$params{$name} =$input_params{$name};1212}1213}1214}12151216my$use_pathinfo= gitweb_check_feature('pathinfo');1217if(defined$params{'project'} &&1218(exists$params{-path_info} ?$params{-path_info} :$use_pathinfo)) {1219# try to put as many parameters as possible in PATH_INFO:1220# - project name1221# - action1222# - hash_parent or hash_parent_base:/file_parent1223# - hash or hash_base:/filename1224# - the snapshot_format as an appropriate suffix12251226# When the script is the root DirectoryIndex for the domain,1227# $href here would be something like http://gitweb.example.com/1228# Thus, we strip any trailing / from $href, to spare us double1229# slashes in the final URL1230$href=~ s,/$,,;12311232# Then add the project name, if present1233$href.="/".esc_url($params{'project'});1234delete$params{'project'};12351236# since we destructively absorb parameters, we keep this1237# boolean that remembers if we're handling a snapshot1238my$is_snapshot=$params{'action'}eq'snapshot';12391240# Summary just uses the project path URL, any other action is1241# added to the URL1242if(defined$params{'action'}) {1243$href.="/".esc_url($params{'action'})unless$params{'action'}eq'summary';1244delete$params{'action'};1245}12461247# Next, we put hash_parent_base:/file_parent..hash_base:/file_name,1248# stripping nonexistent or useless pieces1249$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'}1250||$params{'hash_parent'} ||$params{'hash'});1251if(defined$params{'hash_base'}) {1252if(defined$params{'hash_parent_base'}) {1253$href.= esc_url($params{'hash_parent_base'});1254# skip the file_parent if it's the same as the file_name1255if(defined$params{'file_parent'}) {1256if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) {1257delete$params{'file_parent'};1258}elsif($params{'file_parent'} !~/\.\./) {1259$href.=":/".esc_url($params{'file_parent'});1260delete$params{'file_parent'};1261}1262}1263$href.="..";1264delete$params{'hash_parent'};1265delete$params{'hash_parent_base'};1266}elsif(defined$params{'hash_parent'}) {1267$href.= esc_url($params{'hash_parent'})."..";1268delete$params{'hash_parent'};1269}12701271$href.= esc_url($params{'hash_base'});1272if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) {1273$href.=":/".esc_url($params{'file_name'});1274delete$params{'file_name'};1275}1276delete$params{'hash'};1277delete$params{'hash_base'};1278}elsif(defined$params{'hash'}) {1279$href.= esc_url($params{'hash'});1280delete$params{'hash'};1281}12821283# If the action was a snapshot, we can absorb the1284# snapshot_format parameter too1285if($is_snapshot) {1286my$fmt=$params{'snapshot_format'};1287# snapshot_format should always be defined when href()1288# is called, but just in case some code forgets, we1289# fall back to the default1290$fmt||=$snapshot_fmts[0];1291$href.=$known_snapshot_formats{$fmt}{'suffix'};1292delete$params{'snapshot_format'};1293}1294}12951296# now encode the parameters explicitly1297my@result= ();1298for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1299my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1300if(defined$params{$name}) {1301if(ref($params{$name})eq"ARRAY") {1302foreachmy$par(@{$params{$name}}) {1303push@result,$symbol."=". esc_param($par);1304}1305}else{1306push@result,$symbol."=". esc_param($params{$name});1307}1308}1309}1310$href.="?".join(';',@result)ifscalar@result;13111312return$href;1313}131413151316## ======================================================================1317## validation, quoting/unquoting and escaping13181319sub validate_action {1320my$input=shift||returnundef;1321returnundefunlessexists$actions{$input};1322return$input;1323}13241325sub validate_project {1326my$input=shift||returnundef;1327if(!validate_pathname($input) ||1328!(-d "$projectroot/$input") ||1329!check_export_ok("$projectroot/$input") ||1330($strict_export&& !project_in_list($input))) {1331returnundef;1332}else{1333return$input;1334}1335}13361337sub validate_pathname {1338my$input=shift||returnundef;13391340# no '.' or '..' as elements of path, i.e. no '.' nor '..'1341# at the beginning, at the end, and between slashes.1342# also this catches doubled slashes1343if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1344returnundef;1345}1346# no null characters1347if($input=~m!\0!) {1348returnundef;1349}1350return$input;1351}13521353sub validate_refname {1354my$input=shift||returnundef;13551356# textual hashes are O.K.1357if($input=~m/^[0-9a-fA-F]{40}$/) {1358return$input;1359}1360# it must be correct pathname1361$input= validate_pathname($input)1362orreturnundef;1363# restrictions on ref name according to git-check-ref-format1364if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1365returnundef;1366}1367return$input;1368}13691370# decode sequences of octets in utf8 into Perl's internal form,1371# which is utf-8 with utf8 flag set if needed. gitweb writes out1372# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1373sub to_utf8 {1374my$str=shift;1375returnundefunlessdefined$str;1376if(utf8::valid($str)) {1377 utf8::decode($str);1378return$str;1379}else{1380return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1381}1382}13831384# quote unsafe chars, but keep the slash, even when it's not1385# correct, but quoted slashes look too horrible in bookmarks1386sub esc_param {1387my$str=shift;1388returnundefunlessdefined$str;1389$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1390$str=~s/ /\+/g;1391return$str;1392}13931394# quote unsafe chars in whole URL, so some characters cannot be quoted1395sub esc_url {1396my$str=shift;1397returnundefunlessdefined$str;1398$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg;1399$str=~s/ /\+/g;1400return$str;1401}14021403# replace invalid utf8 character with SUBSTITUTION sequence1404sub esc_html {1405my$str=shift;1406my%opts=@_;14071408returnundefunlessdefined$str;14091410$str= to_utf8($str);1411$str=$cgi->escapeHTML($str);1412if($opts{'-nbsp'}) {1413$str=~s/ / /g;1414}1415$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1416return$str;1417}14181419# quote control characters and escape filename to HTML1420sub esc_path {1421my$str=shift;1422my%opts=@_;14231424returnundefunlessdefined$str;14251426$str= to_utf8($str);1427$str=$cgi->escapeHTML($str);1428if($opts{'-nbsp'}) {1429$str=~s/ / /g;1430}1431$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1432return$str;1433}14341435# Make control characters "printable", using character escape codes (CEC)1436sub quot_cec {1437my$cntrl=shift;1438my%opts=@_;1439my%es= (# character escape codes, aka escape sequences1440"\t"=>'\t',# tab (HT)1441"\n"=>'\n',# line feed (LF)1442"\r"=>'\r',# carrige return (CR)1443"\f"=>'\f',# form feed (FF)1444"\b"=>'\b',# backspace (BS)1445"\a"=>'\a',# alarm (bell) (BEL)1446"\e"=>'\e',# escape (ESC)1447"\013"=>'\v',# vertical tab (VT)1448"\000"=>'\0',# nul character (NUL)1449);1450my$chr= ( (exists$es{$cntrl})1451?$es{$cntrl}1452:sprintf('\%2x',ord($cntrl)) );1453if($opts{-nohtml}) {1454return$chr;1455}else{1456return"<span class=\"cntrl\">$chr</span>";1457}1458}14591460# Alternatively use unicode control pictures codepoints,1461# Unicode "printable representation" (PR)1462sub quot_upr {1463my$cntrl=shift;1464my%opts=@_;14651466my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1467if($opts{-nohtml}) {1468return$chr;1469}else{1470return"<span class=\"cntrl\">$chr</span>";1471}1472}14731474# git may return quoted and escaped filenames1475sub unquote {1476my$str=shift;14771478sub unq {1479my$seq=shift;1480my%es= (# character escape codes, aka escape sequences1481't'=>"\t",# tab (HT, TAB)1482'n'=>"\n",# newline (NL)1483'r'=>"\r",# return (CR)1484'f'=>"\f",# form feed (FF)1485'b'=>"\b",# backspace (BS)1486'a'=>"\a",# alarm (bell) (BEL)1487'e'=>"\e",# escape (ESC)1488'v'=>"\013",# vertical tab (VT)1489);14901491if($seq=~m/^[0-7]{1,3}$/) {1492# octal char sequence1493returnchr(oct($seq));1494}elsif(exists$es{$seq}) {1495# C escape sequence, aka character escape code1496return$es{$seq};1497}1498# quoted ordinary character1499return$seq;1500}15011502if($str=~m/^"(.*)"$/) {1503# needs unquoting1504$str=$1;1505$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1506}1507return$str;1508}15091510# escape tabs (convert tabs to spaces)1511sub untabify {1512my$line=shift;15131514while((my$pos=index($line,"\t")) != -1) {1515if(my$count= (8- ($pos%8))) {1516my$spaces=' ' x $count;1517$line=~s/\t/$spaces/;1518}1519}15201521return$line;1522}15231524sub project_in_list {1525my$project=shift;1526my@list= git_get_projects_list();1527return@list&&scalar(grep{$_->{'path'}eq$project}@list);1528}15291530## ----------------------------------------------------------------------1531## HTML aware string manipulation15321533# Try to chop given string on a word boundary between position1534# $len and $len+$add_len. If there is no word boundary there,1535# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1536# (marking chopped part) would be longer than given string.1537sub chop_str {1538my$str=shift;1539my$len=shift;1540my$add_len=shift||10;1541my$where=shift||'right';# 'left' | 'center' | 'right'15421543# Make sure perl knows it is utf8 encoded so we don't1544# cut in the middle of a utf8 multibyte char.1545$str= to_utf8($str);15461547# allow only $len chars, but don't cut a word if it would fit in $add_len1548# if it doesn't fit, cut it if it's still longer than the dots we would add1549# remove chopped character entities entirely15501551# when chopping in the middle, distribute $len into left and right part1552# return early if chopping wouldn't make string shorter1553if($whereeq'center') {1554return$strif($len+5>=length($str));# filler is length 51555$len=int($len/2);1556}else{1557return$strif($len+4>=length($str));# filler is length 41558}15591560# regexps: ending and beginning with word part up to $add_len1561my$endre=qr/.{$len}\w{0,$add_len}/;1562my$begre=qr/\w{0,$add_len}.{$len}/;15631564if($whereeq'left') {1565$str=~m/^(.*?)($begre)$/;1566my($lead,$body) = ($1,$2);1567if(length($lead) >4) {1568$lead=" ...";1569}1570return"$lead$body";15711572}elsif($whereeq'center') {1573$str=~m/^($endre)(.*)$/;1574my($left,$str) = ($1,$2);1575$str=~m/^(.*?)($begre)$/;1576my($mid,$right) = ($1,$2);1577if(length($mid) >5) {1578$mid=" ... ";1579}1580return"$left$mid$right";15811582}else{1583$str=~m/^($endre)(.*)$/;1584my$body=$1;1585my$tail=$2;1586if(length($tail) >4) {1587$tail="... ";1588}1589return"$body$tail";1590}1591}15921593# takes the same arguments as chop_str, but also wraps a <span> around the1594# result with a title attribute if it does get chopped. Additionally, the1595# string is HTML-escaped.1596sub chop_and_escape_str {1597my($str) =@_;15981599my$chopped= chop_str(@_);1600if($choppedeq$str) {1601return esc_html($chopped);1602}else{1603$str=~s/[[:cntrl:]]/?/g;1604return$cgi->span({-title=>$str}, esc_html($chopped));1605}1606}16071608## ----------------------------------------------------------------------1609## functions returning short strings16101611# CSS class for given age value (in seconds)1612sub age_class {1613my$age=shift;16141615if(!defined$age) {1616return"noage";1617}elsif($age<60*60*2) {1618return"age0";1619}elsif($age<60*60*24*2) {1620return"age1";1621}else{1622return"age2";1623}1624}16251626# convert age in seconds to "nn units ago" string1627sub age_string {1628my$age=shift;1629my$age_str;16301631if($age>60*60*24*365*2) {1632$age_str= (int$age/60/60/24/365);1633$age_str.=" years ago";1634}elsif($age>60*60*24*(365/12)*2) {1635$age_str=int$age/60/60/24/(365/12);1636$age_str.=" months ago";1637}elsif($age>60*60*24*7*2) {1638$age_str=int$age/60/60/24/7;1639$age_str.=" weeks ago";1640}elsif($age>60*60*24*2) {1641$age_str=int$age/60/60/24;1642$age_str.=" days ago";1643}elsif($age>60*60*2) {1644$age_str=int$age/60/60;1645$age_str.=" hours ago";1646}elsif($age>60*2) {1647$age_str=int$age/60;1648$age_str.=" min ago";1649}elsif($age>2) {1650$age_str=int$age;1651$age_str.=" sec ago";1652}else{1653$age_str.=" right now";1654}1655return$age_str;1656}16571658useconstant{1659 S_IFINVALID =>0030000,1660 S_IFGITLINK =>0160000,1661};16621663# submodule/subproject, a commit object reference1664sub S_ISGITLINK {1665my$mode=shift;16661667return(($mode& S_IFMT) == S_IFGITLINK)1668}16691670# convert file mode in octal to symbolic file mode string1671sub mode_str {1672my$mode=oct shift;16731674if(S_ISGITLINK($mode)) {1675return'm---------';1676}elsif(S_ISDIR($mode& S_IFMT)) {1677return'drwxr-xr-x';1678}elsif(S_ISLNK($mode)) {1679return'lrwxrwxrwx';1680}elsif(S_ISREG($mode)) {1681# git cares only about the executable bit1682if($mode& S_IXUSR) {1683return'-rwxr-xr-x';1684}else{1685return'-rw-r--r--';1686};1687}else{1688return'----------';1689}1690}16911692# convert file mode in octal to file type string1693sub file_type {1694my$mode=shift;16951696if($mode!~m/^[0-7]+$/) {1697return$mode;1698}else{1699$mode=oct$mode;1700}17011702if(S_ISGITLINK($mode)) {1703return"submodule";1704}elsif(S_ISDIR($mode& S_IFMT)) {1705return"directory";1706}elsif(S_ISLNK($mode)) {1707return"symlink";1708}elsif(S_ISREG($mode)) {1709return"file";1710}else{1711return"unknown";1712}1713}17141715# convert file mode in octal to file type description string1716sub file_type_long {1717my$mode=shift;17181719if($mode!~m/^[0-7]+$/) {1720return$mode;1721}else{1722$mode=oct$mode;1723}17241725if(S_ISGITLINK($mode)) {1726return"submodule";1727}elsif(S_ISDIR($mode& S_IFMT)) {1728return"directory";1729}elsif(S_ISLNK($mode)) {1730return"symlink";1731}elsif(S_ISREG($mode)) {1732if($mode& S_IXUSR) {1733return"executable";1734}else{1735return"file";1736};1737}else{1738return"unknown";1739}1740}174117421743## ----------------------------------------------------------------------1744## functions returning short HTML fragments, or transforming HTML fragments1745## which don't belong to other sections17461747# format line of commit message.1748sub format_log_line_html {1749my$line=shift;17501751$line= esc_html($line, -nbsp=>1);1752$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1753$cgi->a({-href => href(action=>"object", hash=>$1),1754-class=>"text"},$1);1755}eg;17561757return$line;1758}17591760# format marker of refs pointing to given object17611762# the destination action is chosen based on object type and current context:1763# - for annotated tags, we choose the tag view unless it's the current view1764# already, in which case we go to shortlog view1765# - for other refs, we keep the current view if we're in history, shortlog or1766# log view, and select shortlog otherwise1767sub format_ref_marker {1768my($refs,$id) =@_;1769my$markers='';17701771if(defined$refs->{$id}) {1772foreachmy$ref(@{$refs->{$id}}) {1773# this code exploits the fact that non-lightweight tags are the1774# only indirect objects, and that they are the only objects for which1775# we want to use tag instead of shortlog as action1776my($type,$name) =qw();1777my$indirect= ($ref=~s/\^\{\}$//);1778# e.g. tags/v2.6.11 or heads/next1779if($ref=~m!^(.*?)s?/(.*)$!) {1780$type=$1;1781$name=$2;1782}else{1783$type="ref";1784$name=$ref;1785}17861787my$class=$type;1788$class.=" indirect"if$indirect;17891790my$dest_action="shortlog";17911792if($indirect) {1793$dest_action="tag"unless$actioneq"tag";1794}elsif($action=~/^(history|(short)?log)$/) {1795$dest_action=$action;1796}17971798my$dest="";1799$dest.="refs/"unless$ref=~ m!^refs/!;1800$dest.=$ref;18011802my$link=$cgi->a({1803-href => href(1804 action=>$dest_action,1805 hash=>$dest1806)},$name);18071808$markers.=" <span class=\"$class\"title=\"$ref\">".1809$link."</span>";1810}1811}18121813if($markers) {1814return' <span class="refs">'.$markers.'</span>';1815}else{1816return"";1817}1818}18191820# format, perhaps shortened and with markers, title line1821sub format_subject_html {1822my($long,$short,$href,$extra) =@_;1823$extra=''unlessdefined($extra);18241825if(length($short) <length($long)) {1826$long=~s/[[:cntrl:]]/?/g;1827return$cgi->a({-href =>$href, -class=>"list subject",1828-title => to_utf8($long)},1829 esc_html($short)) .$extra;1830}else{1831return$cgi->a({-href =>$href, -class=>"list subject"},1832 esc_html($long)) .$extra;1833}1834}18351836# Rather than recomputing the url for an email multiple times, we cache it1837# after the first hit. This gives a visible benefit in views where the avatar1838# for the same email is used repeatedly (e.g. shortlog).1839# The cache is shared by all avatar engines (currently gravatar only), which1840# are free to use it as preferred. Since only one avatar engine is used for any1841# given page, there's no risk for cache conflicts.1842our%avatar_cache= ();18431844# Compute the picon url for a given email, by using the picon search service over at1845# http://www.cs.indiana.edu/picons/search.html1846sub picon_url {1847my$email=lc shift;1848if(!$avatar_cache{$email}) {1849my($user,$domain) =split('@',$email);1850$avatar_cache{$email} =1851"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".1852"$domain/$user/".1853"users+domains+unknown/up/single";1854}1855return$avatar_cache{$email};1856}18571858# Compute the gravatar url for a given email, if it's not in the cache already.1859# Gravatar stores only the part of the URL before the size, since that's the1860# one computationally more expensive. This also allows reuse of the cache for1861# different sizes (for this particular engine).1862sub gravatar_url {1863my$email=lc shift;1864my$size=shift;1865$avatar_cache{$email} ||=1866"http://www.gravatar.com/avatar/".1867 Digest::MD5::md5_hex($email) ."?s=";1868return$avatar_cache{$email} .$size;1869}18701871# Insert an avatar for the given $email at the given $size if the feature1872# is enabled.1873sub git_get_avatar {1874my($email,%opts) =@_;1875my$pre_white= ($opts{-pad_before} ?" ":"");1876my$post_white= ($opts{-pad_after} ?" ":"");1877$opts{-size} ||='default';1878my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};1879my$url="";1880if($git_avatareq'gravatar') {1881$url= gravatar_url($email,$size);1882}elsif($git_avatareq'picon') {1883$url= picon_url($email);1884}1885# Other providers can be added by extending the if chain, defining $url1886# as needed. If no variant puts something in $url, we assume avatars1887# are completely disabled/unavailable.1888if($url) {1889return$pre_white.1890"<img width=\"$size\"".1891"class=\"avatar\"".1892"src=\"$url\"".1893"alt=\"\"".1894"/>".$post_white;1895}else{1896return"";1897}1898}18991900sub format_search_author {1901my($author,$searchtype,$displaytext) =@_;1902my$have_search= gitweb_check_feature('search');19031904if($have_search) {1905my$performed="";1906if($searchtypeeq'author') {1907$performed="authored";1908}elsif($searchtypeeq'committer') {1909$performed="committed";1910}19111912return$cgi->a({-href => href(action=>"search", hash=>$hash,1913 searchtext=>$author,1914 searchtype=>$searchtype),class=>"list",1915 title=>"Search for commits$performedby$author"},1916$displaytext);19171918}else{1919return$displaytext;1920}1921}19221923# format the author name of the given commit with the given tag1924# the author name is chopped and escaped according to the other1925# optional parameters (see chop_str).1926sub format_author_html {1927my$tag=shift;1928my$co=shift;1929my$author= chop_and_escape_str($co->{'author_name'},@_);1930return"<$tagclass=\"author\">".1931 format_search_author($co->{'author_name'},"author",1932 git_get_avatar($co->{'author_email'}, -pad_after =>1) .1933$author) .1934"</$tag>";1935}19361937# format git diff header line, i.e. "diff --(git|combined|cc) ..."1938sub format_git_diff_header_line {1939my$line=shift;1940my$diffinfo=shift;1941my($from,$to) =@_;19421943if($diffinfo->{'nparents'}) {1944# combined diff1945$line=~s!^(diff (.*?) )"?.*$!$1!;1946if($to->{'href'}) {1947$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1948 esc_path($to->{'file'}));1949}else{# file was deleted (no href)1950$line.= esc_path($to->{'file'});1951}1952}else{1953# "ordinary" diff1954$line=~s!^(diff (.*?) )"?a/.*$!$1!;1955if($from->{'href'}) {1956$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1957'a/'. esc_path($from->{'file'}));1958}else{# file was added (no href)1959$line.='a/'. esc_path($from->{'file'});1960}1961$line.=' ';1962if($to->{'href'}) {1963$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1964'b/'. esc_path($to->{'file'}));1965}else{# file was deleted1966$line.='b/'. esc_path($to->{'file'});1967}1968}19691970return"<div class=\"diff header\">$line</div>\n";1971}19721973# format extended diff header line, before patch itself1974sub format_extended_diff_header_line {1975my$line=shift;1976my$diffinfo=shift;1977my($from,$to) =@_;19781979# match <path>1980if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1981$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1982 esc_path($from->{'file'}));1983}1984if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1985$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1986 esc_path($to->{'file'}));1987}1988# match single <mode>1989if($line=~m/\s(\d{6})$/) {1990$line.='<span class="info"> ('.1991 file_type_long($1) .1992')</span>';1993}1994# match <hash>1995if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1996# can match only for combined diff1997$line='index ';1998for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1999if($from->{'href'}[$i]) {2000$line.=$cgi->a({-href=>$from->{'href'}[$i],2001-class=>"hash"},2002substr($diffinfo->{'from_id'}[$i],0,7));2003}else{2004$line.='0' x 7;2005}2006# separator2007$line.=','if($i<$diffinfo->{'nparents'} -1);2008}2009$line.='..';2010if($to->{'href'}) {2011$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2012substr($diffinfo->{'to_id'},0,7));2013}else{2014$line.='0' x 7;2015}20162017}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {2018# can match only for ordinary diff2019my($from_link,$to_link);2020if($from->{'href'}) {2021$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},2022substr($diffinfo->{'from_id'},0,7));2023}else{2024$from_link='0' x 7;2025}2026if($to->{'href'}) {2027$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2028substr($diffinfo->{'to_id'},0,7));2029}else{2030$to_link='0' x 7;2031}2032my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});2033$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;2034}20352036return$line."<br/>\n";2037}20382039# format from-file/to-file diff header2040sub format_diff_from_to_header {2041my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;2042my$line;2043my$result='';20442045$line=$from_line;2046#assert($line =~ m/^---/) if DEBUG;2047# no extra formatting for "^--- /dev/null"2048if(!$diffinfo->{'nparents'}) {2049# ordinary (single parent) diff2050if($line=~m!^--- "?a/!) {2051if($from->{'href'}) {2052$line='--- a/'.2053$cgi->a({-href=>$from->{'href'}, -class=>"path"},2054 esc_path($from->{'file'}));2055}else{2056$line='--- a/'.2057 esc_path($from->{'file'});2058}2059}2060$result.= qq!<div class="diff from_file">$line</div>\n!;20612062}else{2063# combined diff (merge commit)2064for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2065if($from->{'href'}[$i]) {2066$line='--- '.2067$cgi->a({-href=>href(action=>"blobdiff",2068 hash_parent=>$diffinfo->{'from_id'}[$i],2069 hash_parent_base=>$parents[$i],2070 file_parent=>$from->{'file'}[$i],2071 hash=>$diffinfo->{'to_id'},2072 hash_base=>$hash,2073 file_name=>$to->{'file'}),2074-class=>"path",2075-title=>"diff". ($i+1)},2076$i+1) .2077'/'.2078$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},2079 esc_path($from->{'file'}[$i]));2080}else{2081$line='--- /dev/null';2082}2083$result.= qq!<div class="diff from_file">$line</div>\n!;2084}2085}20862087$line=$to_line;2088#assert($line =~ m/^\+\+\+/) if DEBUG;2089# no extra formatting for "^+++ /dev/null"2090if($line=~m!^\+\+\+ "?b/!) {2091if($to->{'href'}) {2092$line='+++ b/'.2093$cgi->a({-href=>$to->{'href'}, -class=>"path"},2094 esc_path($to->{'file'}));2095}else{2096$line='+++ b/'.2097 esc_path($to->{'file'});2098}2099}2100$result.= qq!<div class="diff to_file">$line</div>\n!;21012102return$result;2103}21042105# create note for patch simplified by combined diff2106sub format_diff_cc_simplified {2107my($diffinfo,@parents) =@_;2108my$result='';21092110$result.="<div class=\"diff header\">".2111"diff --cc ";2112if(!is_deleted($diffinfo)) {2113$result.=$cgi->a({-href => href(action=>"blob",2114 hash_base=>$hash,2115 hash=>$diffinfo->{'to_id'},2116 file_name=>$diffinfo->{'to_file'}),2117-class=>"path"},2118 esc_path($diffinfo->{'to_file'}));2119}else{2120$result.= esc_path($diffinfo->{'to_file'});2121}2122$result.="</div>\n".# class="diff header"2123"<div class=\"diff nodifferences\">".2124"Simple merge".2125"</div>\n";# class="diff nodifferences"21262127return$result;2128}21292130# format patch (diff) line (not to be used for diff headers)2131sub format_diff_line {2132my$line=shift;2133my($from,$to) =@_;2134my$diff_class="";21352136chomp$line;21372138if($from&&$to&&ref($from->{'href'})eq"ARRAY") {2139# combined diff2140my$prefix=substr($line,0,scalar@{$from->{'href'}});2141if($line=~m/^\@{3}/) {2142$diff_class=" chunk_header";2143}elsif($line=~m/^\\/) {2144$diff_class=" incomplete";2145}elsif($prefix=~tr/+/+/) {2146$diff_class=" add";2147}elsif($prefix=~tr/-/-/) {2148$diff_class=" rem";2149}2150}else{2151# assume ordinary diff2152my$char=substr($line,0,1);2153if($chareq'+') {2154$diff_class=" add";2155}elsif($chareq'-') {2156$diff_class=" rem";2157}elsif($chareq'@') {2158$diff_class=" chunk_header";2159}elsif($chareq"\\") {2160$diff_class=" incomplete";2161}2162}2163$line= untabify($line);2164if($from&&$to&&$line=~m/^\@{2} /) {2165my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =2166$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;21672168$from_lines=0unlessdefined$from_lines;2169$to_lines=0unlessdefined$to_lines;21702171if($from->{'href'}) {2172$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",2173-class=>"list"},$from_text);2174}2175if($to->{'href'}) {2176$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",2177-class=>"list"},$to_text);2178}2179$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".2180"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2181return"<div class=\"diff$diff_class\">$line</div>\n";2182}elsif($from&&$to&&$line=~m/^\@{3}/) {2183my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;2184my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);21852186@from_text=split(' ',$ranges);2187for(my$i=0;$i<@from_text; ++$i) {2188($from_start[$i],$from_nlines[$i]) =2189(split(',',substr($from_text[$i],1)),0);2190}21912192$to_text=pop@from_text;2193$to_start=pop@from_start;2194$to_nlines=pop@from_nlines;21952196$line="<span class=\"chunk_info\">$prefix";2197for(my$i=0;$i<@from_text; ++$i) {2198if($from->{'href'}[$i]) {2199$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",2200-class=>"list"},$from_text[$i]);2201}else{2202$line.=$from_text[$i];2203}2204$line.=" ";2205}2206if($to->{'href'}) {2207$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",2208-class=>"list"},$to_text);2209}else{2210$line.=$to_text;2211}2212$line.="$prefix</span>".2213"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2214return"<div class=\"diff$diff_class\">$line</div>\n";2215}2216return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";2217}22182219# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",2220# linked. Pass the hash of the tree/commit to snapshot.2221sub format_snapshot_links {2222my($hash) =@_;2223my$num_fmts=@snapshot_fmts;2224if($num_fmts>1) {2225# A parenthesized list of links bearing format names.2226# e.g. "snapshot (_tar.gz_ _zip_)"2227return"snapshot (".join(' ',map2228$cgi->a({2229-href => href(2230 action=>"snapshot",2231 hash=>$hash,2232 snapshot_format=>$_2233)2234},$known_snapshot_formats{$_}{'display'})2235,@snapshot_fmts) .")";2236}elsif($num_fmts==1) {2237# A single "snapshot" link whose tooltip bears the format name.2238# i.e. "_snapshot_"2239my($fmt) =@snapshot_fmts;2240return2241$cgi->a({2242-href => href(2243 action=>"snapshot",2244 hash=>$hash,2245 snapshot_format=>$fmt2246),2247-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"2248},"snapshot");2249}else{# $num_fmts == 02250returnundef;2251}2252}22532254## ......................................................................2255## functions returning values to be passed, perhaps after some2256## transformation, to other functions; e.g. returning arguments to href()22572258# returns hash to be passed to href to generate gitweb URL2259# in -title key it returns description of link2260sub get_feed_info {2261my$format=shift||'Atom';2262my%res= (action =>lc($format));22632264# feed links are possible only for project views2265return unless(defined$project);2266# some views should link to OPML, or to generic project feed,2267# or don't have specific feed yet (so they should use generic)2268return if($action=~/^(?:tags|heads|forks|tag|search)$/x);22692270my$branch;2271# branches refs uses 'refs/heads/' prefix (fullname) to differentiate2272# from tag links; this also makes possible to detect branch links2273if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||2274(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {2275$branch=$1;2276}2277# find log type for feed description (title)2278my$type='log';2279if(defined$file_name) {2280$type="history of$file_name";2281$type.="/"if($actioneq'tree');2282$type.=" on '$branch'"if(defined$branch);2283}else{2284$type="log of$branch"if(defined$branch);2285}22862287$res{-title} =$type;2288$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);2289$res{'file_name'} =$file_name;22902291return%res;2292}22932294## ----------------------------------------------------------------------2295## git utility subroutines, invoking git commands22962297# returns path to the core git executable and the --git-dir parameter as list2298sub git_cmd {2299$number_of_git_cmds++;2300return$GIT,'--git-dir='.$git_dir;2301}23022303# quote the given arguments for passing them to the shell2304# quote_command("command", "arg 1", "arg with ' and ! characters")2305# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2306# Try to avoid using this function wherever possible.2307sub quote_command {2308returnjoin(' ',2309map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2310}23112312# get HEAD ref of given project as hash2313sub git_get_head_hash {2314return git_get_full_hash(shift,'HEAD');2315}23162317sub git_get_full_hash {2318return git_get_hash(@_);2319}23202321sub git_get_short_hash {2322return git_get_hash(@_,'--short=7');2323}23242325sub git_get_hash {2326my($project,$hash,@options) =@_;2327my$o_git_dir=$git_dir;2328my$retval=undef;2329$git_dir="$projectroot/$project";2330if(open my$fd,'-|', git_cmd(),'rev-parse',2331'--verify','-q',@options,$hash) {2332$retval= <$fd>;2333chomp$retvalifdefined$retval;2334close$fd;2335}2336if(defined$o_git_dir) {2337$git_dir=$o_git_dir;2338}2339return$retval;2340}23412342# get type of given object2343sub git_get_type {2344my$hash=shift;23452346open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2347my$type= <$fd>;2348close$fdorreturn;2349chomp$type;2350return$type;2351}23522353# repository configuration2354our$config_file='';2355our%config;23562357# store multiple values for single key as anonymous array reference2358# single values stored directly in the hash, not as [ <value> ]2359sub hash_set_multi {2360my($hash,$key,$value) =@_;23612362if(!exists$hash->{$key}) {2363$hash->{$key} =$value;2364}elsif(!ref$hash->{$key}) {2365$hash->{$key} = [$hash->{$key},$value];2366}else{2367push@{$hash->{$key}},$value;2368}2369}23702371# return hash of git project configuration2372# optionally limited to some section, e.g. 'gitweb'2373sub git_parse_project_config {2374my$section_regexp=shift;2375my%config;23762377local$/="\0";23782379open my$fh,"-|", git_cmd(),"config",'-z','-l',2380orreturn;23812382while(my$keyval= <$fh>) {2383chomp$keyval;2384my($key,$value) =split(/\n/,$keyval,2);23852386 hash_set_multi(\%config,$key,$value)2387if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2388}2389close$fh;23902391return%config;2392}23932394# convert config value to boolean: 'true' or 'false'2395# no value, number > 0, 'true' and 'yes' values are true2396# rest of values are treated as false (never as error)2397sub config_to_bool {2398my$val=shift;23992400return1if!defined$val;# section.key24012402# strip leading and trailing whitespace2403$val=~s/^\s+//;2404$val=~s/\s+$//;24052406return(($val=~/^\d+$/&&$val) ||# section.key = 12407($val=~/^(?:true|yes)$/i));# section.key = true2408}24092410# convert config value to simple decimal number2411# an optional value suffix of 'k', 'm', or 'g' will cause the value2412# to be multiplied by 1024, 1048576, or 10737418242413sub config_to_int {2414my$val=shift;24152416# strip leading and trailing whitespace2417$val=~s/^\s+//;2418$val=~s/\s+$//;24192420if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2421$unit=lc($unit);2422# unknown unit is treated as 12423return$num* ($uniteq'g'?1073741824:2424$uniteq'm'?1048576:2425$uniteq'k'?1024:1);2426}2427return$val;2428}24292430# convert config value to array reference, if needed2431sub config_to_multi {2432my$val=shift;24332434returnref($val) ?$val: (defined($val) ? [$val] : []);2435}24362437sub git_get_project_config {2438my($key,$type) =@_;24392440return unlessdefined$git_dir;24412442# key sanity check2443return unless($key);2444$key=~s/^gitweb\.//;2445return if($key=~m/\W/);24462447# type sanity check2448if(defined$type) {2449$type=~s/^--//;2450$type=undef2451unless($typeeq'bool'||$typeeq'int');2452}24532454# get config2455if(!defined$config_file||2456$config_filene"$git_dir/config") {2457%config= git_parse_project_config('gitweb');2458$config_file="$git_dir/config";2459}24602461# check if config variable (key) exists2462return unlessexists$config{"gitweb.$key"};24632464# ensure given type2465if(!defined$type) {2466return$config{"gitweb.$key"};2467}elsif($typeeq'bool') {2468# backward compatibility: 'git config --bool' returns true/false2469return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2470}elsif($typeeq'int') {2471return config_to_int($config{"gitweb.$key"});2472}2473return$config{"gitweb.$key"};2474}24752476# get hash of given path at given ref2477sub git_get_hash_by_path {2478my$base=shift;2479my$path=shift||returnundef;2480my$type=shift;24812482$path=~ s,/+$,,;24832484open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2485or die_error(500,"Open git-ls-tree failed");2486my$line= <$fd>;2487close$fdorreturnundef;24882489if(!defined$line) {2490# there is no tree or hash given by $path at $base2491returnundef;2492}24932494#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2495$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2496if(defined$type&&$typene$2) {2497# type doesn't match2498returnundef;2499}2500return$3;2501}25022503# get path of entry with given hash at given tree-ish (ref)2504# used to get 'from' filename for combined diff (merge commit) for renames2505sub git_get_path_by_hash {2506my$base=shift||return;2507my$hash=shift||return;25082509local$/="\0";25102511open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2512orreturnundef;2513while(my$line= <$fd>) {2514chomp$line;25152516#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2517#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2518if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2519close$fd;2520return$1;2521}2522}2523close$fd;2524returnundef;2525}25262527## ......................................................................2528## git utility functions, directly accessing git repository25292530sub git_get_project_description {2531my$path=shift;25322533$git_dir="$projectroot/$path";2534open my$fd,'<',"$git_dir/description"2535orreturn git_get_project_config('description');2536my$descr= <$fd>;2537close$fd;2538if(defined$descr) {2539chomp$descr;2540}2541return$descr;2542}25432544sub git_get_project_ctags {2545my$path=shift;2546my$ctags= {};25472548$git_dir="$projectroot/$path";2549opendir my$dh,"$git_dir/ctags"2550orreturn$ctags;2551foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2552open my$ct,'<',$_ornext;2553my$val= <$ct>;2554chomp$val;2555close$ct;2556my$ctag=$_;$ctag=~ s#.*/##;2557$ctags->{$ctag} =$val;2558}2559closedir$dh;2560$ctags;2561}25622563sub git_populate_project_tagcloud {2564my$ctags=shift;25652566# First, merge different-cased tags; tags vote on casing2567my%ctags_lc;2568foreach(keys%$ctags) {2569$ctags_lc{lc$_}->{count} +=$ctags->{$_};2570if(not$ctags_lc{lc$_}->{topcount}2571or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2572$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2573$ctags_lc{lc$_}->{topname} =$_;2574}2575}25762577my$cloud;2578if(eval{require HTML::TagCloud;1; }) {2579$cloud= HTML::TagCloud->new;2580foreach(sort keys%ctags_lc) {2581# Pad the title with spaces so that the cloud looks2582# less crammed.2583my$title=$ctags_lc{$_}->{topname};2584$title=~s/ / /g;2585$title=~s/^/ /g;2586$title=~s/$/ /g;2587$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2588}2589}else{2590$cloud= \%ctags_lc;2591}2592$cloud;2593}25942595sub git_show_project_tagcloud {2596my($cloud,$count) =@_;2597print STDERR ref($cloud)."..\n";2598if(ref$cloudeq'HTML::TagCloud') {2599return$cloud->html_and_css($count);2600}else{2601my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2602return'<p align="center">'.join(', ',map{2603"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"2604}splice(@tags,0,$count)) .'</p>';2605}2606}26072608sub git_get_project_url_list {2609my$path=shift;26102611$git_dir="$projectroot/$path";2612open my$fd,'<',"$git_dir/cloneurl"2613orreturnwantarray?2614@{ config_to_multi(git_get_project_config('url')) } :2615 config_to_multi(git_get_project_config('url'));2616my@git_project_url_list=map{chomp;$_} <$fd>;2617close$fd;26182619returnwantarray?@git_project_url_list: \@git_project_url_list;2620}26212622sub git_get_projects_list {2623my($filter) =@_;2624my@list;26252626$filter||='';2627$filter=~s/\.git$//;26282629my$check_forks= gitweb_check_feature('forks');26302631if(-d $projects_list) {2632# search in directory2633my$dir=$projects_list. ($filter?"/$filter":'');2634# remove the trailing "/"2635$dir=~s!/+$!!;2636my$pfxlen=length("$dir");2637my$pfxdepth= ($dir=~tr!/!!);26382639 File::Find::find({2640 follow_fast =>1,# follow symbolic links2641 follow_skip =>2,# ignore duplicates2642 dangling_symlinks =>0,# ignore dangling symlinks, silently2643 wanted =>sub{2644# global variables2645our$project_maxdepth;2646our$projectroot;2647# skip project-list toplevel, if we get it.2648return if(m!^[/.]$!);2649# only directories can be git repositories2650return unless(-d $_);2651# don't traverse too deep (Find is super slow on os x)2652if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2653$File::Find::prune =1;2654return;2655}26562657my$subdir=substr($File::Find::name,$pfxlen+1);2658# we check related file in $projectroot2659my$path= ($filter?"$filter/":'') .$subdir;2660if(check_export_ok("$projectroot/$path")) {2661push@list, { path =>$path};2662$File::Find::prune =1;2663}2664},2665},"$dir");26662667}elsif(-f $projects_list) {2668# read from file(url-encoded):2669# 'git%2Fgit.git Linus+Torvalds'2670# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2671# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2672my%paths;2673open my$fd,'<',$projects_listorreturn;2674 PROJECT:2675while(my$line= <$fd>) {2676chomp$line;2677my($path,$owner) =split' ',$line;2678$path= unescape($path);2679$owner= unescape($owner);2680if(!defined$path) {2681next;2682}2683if($filterne'') {2684# looking for forks;2685my$pfx=substr($path,0,length($filter));2686if($pfxne$filter) {2687next PROJECT;2688}2689my$sfx=substr($path,length($filter));2690if($sfx!~/^\/.*\.git$/) {2691next PROJECT;2692}2693}elsif($check_forks) {2694 PATH:2695foreachmy$filter(keys%paths) {2696# looking for forks;2697my$pfx=substr($path,0,length($filter));2698if($pfxne$filter) {2699next PATH;2700}2701my$sfx=substr($path,length($filter));2702if($sfx!~/^\/.*\.git$/) {2703next PATH;2704}2705# is a fork, don't include it in2706# the list2707next PROJECT;2708}2709}2710if(check_export_ok("$projectroot/$path")) {2711my$pr= {2712 path =>$path,2713 owner => to_utf8($owner),2714};2715push@list,$pr;2716(my$forks_path=$path) =~s/\.git$//;2717$paths{$forks_path}++;2718}2719}2720close$fd;2721}2722return@list;2723}27242725our$gitweb_project_owner=undef;2726sub git_get_project_list_from_file {27272728return if(defined$gitweb_project_owner);27292730$gitweb_project_owner= {};2731# read from file (url-encoded):2732# 'git%2Fgit.git Linus+Torvalds'2733# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2734# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2735if(-f $projects_list) {2736open(my$fd,'<',$projects_list);2737while(my$line= <$fd>) {2738chomp$line;2739my($pr,$ow) =split' ',$line;2740$pr= unescape($pr);2741$ow= unescape($ow);2742$gitweb_project_owner->{$pr} = to_utf8($ow);2743}2744close$fd;2745}2746}27472748sub git_get_project_owner {2749my$project=shift;2750my$owner;27512752returnundefunless$project;2753$git_dir="$projectroot/$project";27542755if(!defined$gitweb_project_owner) {2756 git_get_project_list_from_file();2757}27582759if(exists$gitweb_project_owner->{$project}) {2760$owner=$gitweb_project_owner->{$project};2761}2762if(!defined$owner){2763$owner= git_get_project_config('owner');2764}2765if(!defined$owner) {2766$owner= get_file_owner("$git_dir");2767}27682769return$owner;2770}27712772sub git_get_last_activity {2773my($path) =@_;2774my$fd;27752776$git_dir="$projectroot/$path";2777open($fd,"-|", git_cmd(),'for-each-ref',2778'--format=%(committer)',2779'--sort=-committerdate',2780'--count=1',2781'refs/heads')orreturn;2782my$most_recent= <$fd>;2783close$fdorreturn;2784if(defined$most_recent&&2785$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2786my$timestamp=$1;2787my$age=time-$timestamp;2788return($age, age_string($age));2789}2790return(undef,undef);2791}27922793# Implementation note: when a single remote is wanted, we cannot use 'git2794# remote show -n' because that command always work (assuming it's a remote URL2795# if it's not defined), and we cannot use 'git remote show' because that would2796# try to make a network roundtrip. So the only way to find if that particular2797# remote is defined is to walk the list provided by 'git remote -v' and stop if2798# and when we find what we want.2799sub git_get_remotes_list {2800my$wanted=shift;2801my%remotes= ();28022803open my$fd,'-|', git_cmd(),'remote','-v';2804return unless$fd;2805while(my$remote= <$fd>) {2806chomp$remote;2807$remote=~s!\t(.*?)\s+\((\w+)\)$!!;2808next if$wantedand not$remoteeq$wanted;2809my($url,$key) = ($1,$2);28102811$remotes{$remote} ||= {'heads'=> () };2812$remotes{$remote}{$key} =$url;2813}2814close$fdorreturn;2815returnwantarray?%remotes: \%remotes;2816}28172818# Takes a hash of remotes as first parameter and fills it by adding the2819# available remote heads for each of the indicated remotes.2820sub fill_remote_heads {2821my$remotes=shift;2822my@heads=map{"remotes/$_"}keys%$remotes;2823my@remoteheads= git_get_heads_list(undef,@heads);2824foreachmy$remote(keys%$remotes) {2825$remotes->{$remote}{'heads'} = [grep{2826$_->{'name'} =~s!^$remote/!!2827}@remoteheads];2828}2829}28302831sub git_get_references {2832my$type=shift||"";2833my%refs;2834# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112835# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2836open my$fd,"-|", git_cmd(),"show-ref","--dereference",2837($type? ("--","refs/$type") : ())# use -- <pattern> if $type2838orreturn;28392840while(my$line= <$fd>) {2841chomp$line;2842if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2843if(defined$refs{$1}) {2844push@{$refs{$1}},$2;2845}else{2846$refs{$1} = [$2];2847}2848}2849}2850close$fdorreturn;2851return \%refs;2852}28532854sub git_get_rev_name_tags {2855my$hash=shift||returnundef;28562857open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2858orreturn;2859my$name_rev= <$fd>;2860close$fd;28612862if($name_rev=~ m|^$hash tags/(.*)$|) {2863return$1;2864}else{2865# catches also '$hash undefined' output2866returnundef;2867}2868}28692870## ----------------------------------------------------------------------2871## parse to hash functions28722873sub parse_date {2874my$epoch=shift;2875my$tz=shift||"-0000";28762877my%date;2878my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2879my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2880my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2881$date{'hour'} =$hour;2882$date{'minute'} =$min;2883$date{'mday'} =$mday;2884$date{'day'} =$days[$wday];2885$date{'month'} =$months[$mon];2886$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2887$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2888$date{'mday-time'} =sprintf"%d%s%02d:%02d",2889$mday,$months[$mon],$hour,$min;2890$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",28911900+$year,1+$mon,$mday,$hour,$min,$sec;28922893$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2894my$local=$epoch+ ((int$1+ ($2/60)) *3600);2895($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2896$date{'hour_local'} =$hour;2897$date{'minute_local'} =$min;2898$date{'tz_local'} =$tz;2899$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",29001900+$year,$mon+1,$mday,2901$hour,$min,$sec,$tz);2902return%date;2903}29042905sub parse_tag {2906my$tag_id=shift;2907my%tag;2908my@comment;29092910open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2911$tag{'id'} =$tag_id;2912while(my$line= <$fd>) {2913chomp$line;2914if($line=~m/^object ([0-9a-fA-F]{40})$/) {2915$tag{'object'} =$1;2916}elsif($line=~m/^type (.+)$/) {2917$tag{'type'} =$1;2918}elsif($line=~m/^tag (.+)$/) {2919$tag{'name'} =$1;2920}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2921$tag{'author'} =$1;2922$tag{'author_epoch'} =$2;2923$tag{'author_tz'} =$3;2924if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {2925$tag{'author_name'} =$1;2926$tag{'author_email'} =$2;2927}else{2928$tag{'author_name'} =$tag{'author'};2929}2930}elsif($line=~m/--BEGIN/) {2931push@comment,$line;2932last;2933}elsif($lineeq"") {2934last;2935}2936}2937push@comment, <$fd>;2938$tag{'comment'} = \@comment;2939close$fdorreturn;2940if(!defined$tag{'name'}) {2941return2942};2943return%tag2944}29452946sub parse_commit_text {2947my($commit_text,$withparents) =@_;2948my@commit_lines=split'\n',$commit_text;2949my%co;29502951pop@commit_lines;# Remove '\0'29522953if(!@commit_lines) {2954return;2955}29562957my$header=shift@commit_lines;2958if($header!~m/^[0-9a-fA-F]{40}/) {2959return;2960}2961($co{'id'},my@parents) =split' ',$header;2962while(my$line=shift@commit_lines) {2963last if$lineeq"\n";2964if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2965$co{'tree'} =$1;2966}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2967push@parents,$1;2968}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2969$co{'author'} = to_utf8($1);2970$co{'author_epoch'} =$2;2971$co{'author_tz'} =$3;2972if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2973$co{'author_name'} =$1;2974$co{'author_email'} =$2;2975}else{2976$co{'author_name'} =$co{'author'};2977}2978}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2979$co{'committer'} = to_utf8($1);2980$co{'committer_epoch'} =$2;2981$co{'committer_tz'} =$3;2982if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2983$co{'committer_name'} =$1;2984$co{'committer_email'} =$2;2985}else{2986$co{'committer_name'} =$co{'committer'};2987}2988}2989}2990if(!defined$co{'tree'}) {2991return;2992};2993$co{'parents'} = \@parents;2994$co{'parent'} =$parents[0];29952996foreachmy$title(@commit_lines) {2997$title=~s/^ //;2998if($titlene"") {2999$co{'title'} = chop_str($title,80,5);3000# remove leading stuff of merges to make the interesting part visible3001if(length($title) >50) {3002$title=~s/^Automatic //;3003$title=~s/^merge (of|with) /Merge ... /i;3004if(length($title) >50) {3005$title=~s/(http|rsync):\/\///;3006}3007if(length($title) >50) {3008$title=~s/(master|www|rsync)\.//;3009}3010if(length($title) >50) {3011$title=~s/kernel.org:?//;3012}3013if(length($title) >50) {3014$title=~s/\/pub\/scm//;3015}3016}3017$co{'title_short'} = chop_str($title,50,5);3018last;3019}3020}3021if(!defined$co{'title'} ||$co{'title'}eq"") {3022$co{'title'} =$co{'title_short'} ='(no commit message)';3023}3024# remove added spaces3025foreachmy$line(@commit_lines) {3026$line=~s/^ //;3027}3028$co{'comment'} = \@commit_lines;30293030my$age=time-$co{'committer_epoch'};3031$co{'age'} =$age;3032$co{'age_string'} = age_string($age);3033my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});3034if($age>60*60*24*7*2) {3035$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;3036$co{'age_string_age'} =$co{'age_string'};3037}else{3038$co{'age_string_date'} =$co{'age_string'};3039$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;3040}3041return%co;3042}30433044sub parse_commit {3045my($commit_id) =@_;3046my%co;30473048local$/="\0";30493050open my$fd,"-|", git_cmd(),"rev-list",3051"--parents",3052"--header",3053"--max-count=1",3054$commit_id,3055"--",3056or die_error(500,"Open git-rev-list failed");3057%co= parse_commit_text(<$fd>,1);3058close$fd;30593060return%co;3061}30623063sub parse_commits {3064my($commit_id,$maxcount,$skip,$filename,@args) =@_;3065my@cos;30663067$maxcount||=1;3068$skip||=0;30693070local$/="\0";30713072open my$fd,"-|", git_cmd(),"rev-list",3073"--header",3074@args,3075("--max-count=".$maxcount),3076("--skip=".$skip),3077@extra_options,3078$commit_id,3079"--",3080($filename? ($filename) : ())3081or die_error(500,"Open git-rev-list failed");3082while(my$line= <$fd>) {3083my%co= parse_commit_text($line);3084push@cos, \%co;3085}3086close$fd;30873088returnwantarray?@cos: \@cos;3089}30903091# parse line of git-diff-tree "raw" output3092sub parse_difftree_raw_line {3093my$line=shift;3094my%res;30953096# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'3097# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'3098if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {3099$res{'from_mode'} =$1;3100$res{'to_mode'} =$2;3101$res{'from_id'} =$3;3102$res{'to_id'} =$4;3103$res{'status'} =$5;3104$res{'similarity'} =$6;3105if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied3106($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);3107}else{3108$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);3109}3110}3111# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'3112# combined diff (for merge commit)3113elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {3114$res{'nparents'} =length($1);3115$res{'from_mode'} = [split(' ',$2) ];3116$res{'to_mode'} =pop@{$res{'from_mode'}};3117$res{'from_id'} = [split(' ',$3) ];3118$res{'to_id'} =pop@{$res{'from_id'}};3119$res{'status'} = [split('',$4) ];3120$res{'to_file'} = unquote($5);3121}3122# 'c512b523472485aef4fff9e57b229d9d243c967f'3123elsif($line=~m/^([0-9a-fA-F]{40})$/) {3124$res{'commit'} =$1;3125}31263127returnwantarray?%res: \%res;3128}31293130# wrapper: return parsed line of git-diff-tree "raw" output3131# (the argument might be raw line, or parsed info)3132sub parsed_difftree_line {3133my$line_or_ref=shift;31343135if(ref($line_or_ref)eq"HASH") {3136# pre-parsed (or generated by hand)3137return$line_or_ref;3138}else{3139return parse_difftree_raw_line($line_or_ref);3140}3141}31423143# parse line of git-ls-tree output3144sub parse_ls_tree_line {3145my$line=shift;3146my%opts=@_;3147my%res;31483149if($opts{'-l'}) {3150#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'3151$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;31523153$res{'mode'} =$1;3154$res{'type'} =$2;3155$res{'hash'} =$3;3156$res{'size'} =$4;3157if($opts{'-z'}) {3158$res{'name'} =$5;3159}else{3160$res{'name'} = unquote($5);3161}3162}else{3163#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'3164$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;31653166$res{'mode'} =$1;3167$res{'type'} =$2;3168$res{'hash'} =$3;3169if($opts{'-z'}) {3170$res{'name'} =$4;3171}else{3172$res{'name'} = unquote($4);3173}3174}31753176returnwantarray?%res: \%res;3177}31783179# generates _two_ hashes, references to which are passed as 2 and 3 argument3180sub parse_from_to_diffinfo {3181my($diffinfo,$from,$to,@parents) =@_;31823183if($diffinfo->{'nparents'}) {3184# combined diff3185$from->{'file'} = [];3186$from->{'href'} = [];3187 fill_from_file_info($diffinfo,@parents)3188unlessexists$diffinfo->{'from_file'};3189for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {3190$from->{'file'}[$i] =3191defined$diffinfo->{'from_file'}[$i] ?3192$diffinfo->{'from_file'}[$i] :3193$diffinfo->{'to_file'};3194if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file3195$from->{'href'}[$i] = href(action=>"blob",3196 hash_base=>$parents[$i],3197 hash=>$diffinfo->{'from_id'}[$i],3198 file_name=>$from->{'file'}[$i]);3199}else{3200$from->{'href'}[$i] =undef;3201}3202}3203}else{3204# ordinary (not combined) diff3205$from->{'file'} =$diffinfo->{'from_file'};3206if($diffinfo->{'status'}ne"A") {# not new (added) file3207$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,3208 hash=>$diffinfo->{'from_id'},3209 file_name=>$from->{'file'});3210}else{3211delete$from->{'href'};3212}3213}32143215$to->{'file'} =$diffinfo->{'to_file'};3216if(!is_deleted($diffinfo)) {# file exists in result3217$to->{'href'} = href(action=>"blob", hash_base=>$hash,3218 hash=>$diffinfo->{'to_id'},3219 file_name=>$to->{'file'});3220}else{3221delete$to->{'href'};3222}3223}32243225## ......................................................................3226## parse to array of hashes functions32273228sub git_get_heads_list {3229my($limit,@classes) =@_;3230@classes= ('heads')unless@classes;3231my@patterns=map{"refs/$_"}@classes;3232my@headslist;32333234open my$fd,'-|', git_cmd(),'for-each-ref',3235($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',3236'--format=%(objectname) %(refname) %(subject)%00%(committer)',3237@patterns3238orreturn;3239while(my$line= <$fd>) {3240my%ref_item;32413242chomp$line;3243my($refinfo,$committerinfo) =split(/\0/,$line);3244my($hash,$name,$title) =split(' ',$refinfo,3);3245my($committer,$epoch,$tz) =3246($committerinfo=~/^(.*) ([0-9]+) (.*)$/);3247$ref_item{'fullname'} =$name;3248$name=~s!^refs/(?:head|remote)s/!!;32493250$ref_item{'name'} =$name;3251$ref_item{'id'} =$hash;3252$ref_item{'title'} =$title||'(no commit message)';3253$ref_item{'epoch'} =$epoch;3254if($epoch) {3255$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3256}else{3257$ref_item{'age'} ="unknown";3258}32593260push@headslist, \%ref_item;3261}3262close$fd;32633264returnwantarray?@headslist: \@headslist;3265}32663267sub git_get_tags_list {3268my$limit=shift;3269my@tagslist;32703271open my$fd,'-|', git_cmd(),'for-each-ref',3272($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',3273'--format=%(objectname) %(objecttype) %(refname) '.3274'%(*objectname) %(*objecttype) %(subject)%00%(creator)',3275'refs/tags'3276orreturn;3277while(my$line= <$fd>) {3278my%ref_item;32793280chomp$line;3281my($refinfo,$creatorinfo) =split(/\0/,$line);3282my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);3283my($creator,$epoch,$tz) =3284($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);3285$ref_item{'fullname'} =$name;3286$name=~s!^refs/tags/!!;32873288$ref_item{'type'} =$type;3289$ref_item{'id'} =$id;3290$ref_item{'name'} =$name;3291if($typeeq"tag") {3292$ref_item{'subject'} =$title;3293$ref_item{'reftype'} =$reftype;3294$ref_item{'refid'} =$refid;3295}else{3296$ref_item{'reftype'} =$type;3297$ref_item{'refid'} =$id;3298}32993300if($typeeq"tag"||$typeeq"commit") {3301$ref_item{'epoch'} =$epoch;3302if($epoch) {3303$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3304}else{3305$ref_item{'age'} ="unknown";3306}3307}33083309push@tagslist, \%ref_item;3310}3311close$fd;33123313returnwantarray?@tagslist: \@tagslist;3314}33153316## ----------------------------------------------------------------------3317## filesystem-related functions33183319sub get_file_owner {3320my$path=shift;33213322my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);3323my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);3324if(!defined$gcos) {3325returnundef;3326}3327my$owner=$gcos;3328$owner=~s/[,;].*$//;3329return to_utf8($owner);3330}33313332# assume that file exists3333sub insert_file {3334my$filename=shift;33353336open my$fd,'<',$filename;3337print map{ to_utf8($_) } <$fd>;3338close$fd;3339}33403341## ......................................................................3342## mimetype related functions33433344sub mimetype_guess_file {3345my$filename=shift;3346my$mimemap=shift;3347-r $mimemaporreturnundef;33483349my%mimemap;3350open(my$mh,'<',$mimemap)orreturnundef;3351while(<$mh>) {3352next ifm/^#/;# skip comments3353my($mimetype,$exts) =split(/\t+/);3354if(defined$exts) {3355my@exts=split(/\s+/,$exts);3356foreachmy$ext(@exts) {3357$mimemap{$ext} =$mimetype;3358}3359}3360}3361close($mh);33623363$filename=~/\.([^.]*)$/;3364return$mimemap{$1};3365}33663367sub mimetype_guess {3368my$filename=shift;3369my$mime;3370$filename=~/\./orreturnundef;33713372if($mimetypes_file) {3373my$file=$mimetypes_file;3374if($file!~m!^/!) {# if it is relative path3375# it is relative to project3376$file="$projectroot/$project/$file";3377}3378$mime= mimetype_guess_file($filename,$file);3379}3380$mime||= mimetype_guess_file($filename,'/etc/mime.types');3381return$mime;3382}33833384sub blob_mimetype {3385my$fd=shift;3386my$filename=shift;33873388if($filename) {3389my$mime= mimetype_guess($filename);3390$mimeandreturn$mime;3391}33923393# just in case3394return$default_blob_plain_mimetypeunless$fd;33953396if(-T $fd) {3397return'text/plain';3398}elsif(!$filename) {3399return'application/octet-stream';3400}elsif($filename=~m/\.png$/i) {3401return'image/png';3402}elsif($filename=~m/\.gif$/i) {3403return'image/gif';3404}elsif($filename=~m/\.jpe?g$/i) {3405return'image/jpeg';3406}else{3407return'application/octet-stream';3408}3409}34103411sub blob_contenttype {3412my($fd,$file_name,$type) =@_;34133414$type||= blob_mimetype($fd,$file_name);3415if($typeeq'text/plain'&&defined$default_text_plain_charset) {3416$type.="; charset=$default_text_plain_charset";3417}34183419return$type;3420}34213422# guess file syntax for syntax highlighting; return undef if no highlighting3423# the name of syntax can (in the future) depend on syntax highlighter used3424sub guess_file_syntax {3425my($highlight,$mimetype,$file_name) =@_;3426returnundefunless($highlight&&defined$file_name);3427my$basename= basename($file_name,'.in');3428return$highlight_basename{$basename}3429ifexists$highlight_basename{$basename};34303431$basename=~/\.([^.]*)$/;3432my$ext=$1orreturnundef;3433return$highlight_ext{$ext}3434ifexists$highlight_ext{$ext};34353436returnundef;3437}34383439# run highlighter and return FD of its output,3440# or return original FD if no highlighting3441sub run_highlighter {3442my($fd,$highlight,$syntax) =@_;3443return$fdunless($highlight&&defined$syntax);34443445close$fd3446or die_error(404,"Reading blob failed");3447open$fd, quote_command(git_cmd(),"cat-file","blob",$hash)." | ".3448 quote_command($highlight_bin).3449" --xhtml --fragment --syntax$syntax|"3450or die_error(500,"Couldn't open file or run syntax highlighter");3451return$fd;3452}34533454## ======================================================================3455## functions printing HTML: header, footer, error page34563457sub get_page_title {3458my$title= to_utf8($site_name);34593460return$titleunless(defined$project);3461$title.=" - ". to_utf8($project);34623463return$titleunless(defined$action);3464$title.="/$action";# $action is US-ASCII (7bit ASCII)34653466return$titleunless(defined$file_name);3467$title.=" - ". esc_path($file_name);3468if($actioneq"tree"&&$file_name!~ m|/$|) {3469$title.="/";3470}34713472return$title;3473}34743475sub git_header_html {3476my$status=shift||"200 OK";3477my$expires=shift;3478my%opts=@_;34793480my$title= get_page_title();3481my$content_type;3482# require explicit support from the UA if we are to send the page as3483# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3484# we have to do this because MSIE sometimes globs '*/*', pretending to3485# support xhtml+xml but choking when it gets what it asked for.3486if(defined$cgi->http('HTTP_ACCEPT') &&3487$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3488$cgi->Accept('application/xhtml+xml') !=0) {3489$content_type='application/xhtml+xml';3490}else{3491$content_type='text/html';3492}3493print$cgi->header(-type=>$content_type, -charset =>'utf-8',3494-status=>$status, -expires =>$expires)3495unless($opts{'-no_http_header'});3496my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';3497print<<EOF;3498<?xml version="1.0" encoding="utf-8"?>3499<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">3500<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">3501<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->3502<!-- git core binaries version$git_version-->3503<head>3504<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>3505<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>3506<meta name="robots" content="index, nofollow"/>3507<title>$title</title>3508EOF3509# the stylesheet, favicon etc urls won't work correctly with path_info3510# unless we set the appropriate base URL3511if($ENV{'PATH_INFO'}) {3512print"<base href=\"".esc_url($base_url)."\"/>\n";3513}3514# print out each stylesheet that exist, providing backwards capability3515# for those people who defined $stylesheet in a config file3516if(defined$stylesheet) {3517print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3518}else{3519foreachmy$stylesheet(@stylesheets) {3520next unless$stylesheet;3521print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3522}3523}3524if(defined$project) {3525my%href_params= get_feed_info();3526if(!exists$href_params{'-title'}) {3527$href_params{'-title'} ='log';3528}35293530foreachmy$formatqw(RSS Atom){3531my$type=lc($format);3532my%link_attr= (3533'-rel'=>'alternate',3534'-title'=>"$project-$href_params{'-title'} -$formatfeed",3535'-type'=>"application/$type+xml"3536);35373538$href_params{'action'} =$type;3539$link_attr{'-href'} = href(%href_params);3540print"<link ".3541"rel=\"$link_attr{'-rel'}\"".3542"title=\"$link_attr{'-title'}\"".3543"href=\"$link_attr{'-href'}\"".3544"type=\"$link_attr{'-type'}\"".3545"/>\n";35463547$href_params{'extra_options'} ='--no-merges';3548$link_attr{'-href'} = href(%href_params);3549$link_attr{'-title'} .=' (no merges)';3550print"<link ".3551"rel=\"$link_attr{'-rel'}\"".3552"title=\"$link_attr{'-title'}\"".3553"href=\"$link_attr{'-href'}\"".3554"type=\"$link_attr{'-type'}\"".3555"/>\n";3556}35573558}else{3559printf('<link rel="alternate" title="%sprojects list" '.3560'href="%s" type="text/plain; charset=utf-8" />'."\n",3561$site_name, href(project=>undef, action=>"project_index"));3562printf('<link rel="alternate" title="%sprojects feeds" '.3563'href="%s" type="text/x-opml" />'."\n",3564$site_name, href(project=>undef, action=>"opml"));3565}3566if(defined$favicon) {3567printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);3568}35693570print"</head>\n".3571"<body>\n";35723573if(defined$site_header&& -f $site_header) {3574 insert_file($site_header);3575}35763577print"<div class=\"page_header\">\n".3578$cgi->a({-href => esc_url($logo_url),3579-title =>$logo_label},3580qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));3581print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3582if(defined$project) {3583print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3584if(defined$action) {3585my$action_print=$action;3586if(defined$opts{-action_extra}) {3587$action_print=$cgi->a({-href => href(action=>$action)},3588$action);3589}3590print" /$action_print";3591}3592if(defined$opts{-action_extra}) {3593print" /$opts{-action_extra}";3594}3595print"\n";3596}3597print"</div>\n";35983599my$have_search= gitweb_check_feature('search');3600if(defined$project&&$have_search) {3601if(!defined$searchtext) {3602$searchtext="";3603}3604my$search_hash;3605if(defined$hash_base) {3606$search_hash=$hash_base;3607}elsif(defined$hash) {3608$search_hash=$hash;3609}else{3610$search_hash="HEAD";3611}3612my$action=$my_uri;3613my$use_pathinfo= gitweb_check_feature('pathinfo');3614if($use_pathinfo) {3615$action.="/".esc_url($project);3616}3617print$cgi->startform(-method=>"get", -action =>$action) .3618"<div class=\"search\">\n".3619(!$use_pathinfo&&3620$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3621$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3622$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3623$cgi->popup_menu(-name =>'st', -default=>'commit',3624-values=> ['commit','grep','author','committer','pickaxe']) .3625$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3626" search:\n",3627$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3628"<span title=\"Extended regular expression\">".3629$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3630-checked =>$search_use_regexp) .3631"</span>".3632"</div>".3633$cgi->end_form() ."\n";3634}3635}36363637sub git_footer_html {3638my$feed_class='rss_logo';36393640print"<div class=\"page_footer\">\n";3641if(defined$project) {3642my$descr= git_get_project_description($project);3643if(defined$descr) {3644print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3645}36463647my%href_params= get_feed_info();3648if(!%href_params) {3649$feed_class.=' generic';3650}3651$href_params{'-title'} ||='log';36523653foreachmy$formatqw(RSS Atom){3654$href_params{'action'} =lc($format);3655print$cgi->a({-href => href(%href_params),3656-title =>"$href_params{'-title'}$formatfeed",3657-class=>$feed_class},$format)."\n";3658}36593660}else{3661print$cgi->a({-href => href(project=>undef, action=>"opml"),3662-class=>$feed_class},"OPML") ." ";3663print$cgi->a({-href => href(project=>undef, action=>"project_index"),3664-class=>$feed_class},"TXT") ."\n";3665}3666print"</div>\n";# class="page_footer"36673668if(defined$t0&& gitweb_check_feature('timed')) {3669print"<div id=\"generating_info\">\n";3670print'This page took '.3671'<span id="generating_time" class="time_span">'.3672 tv_interval($t0, [ gettimeofday() ]).3673' seconds </span>'.3674' and '.3675'<span id="generating_cmd">'.3676$number_of_git_cmds.3677'</span> git commands '.3678" to generate.\n";3679print"</div>\n";# class="page_footer"3680}36813682if(defined$site_footer&& -f $site_footer) {3683 insert_file($site_footer);3684}36853686print qq!<script type="text/javascript" src="$javascript"></script>\n!;3687if(defined$action&&3688$actioneq'blame_incremental') {3689print qq!<script type="text/javascript">\n!.3690 qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.3691 qq!"!. href() .qq!");\n!.3692 qq!</script>\n!;3693}elsif(gitweb_check_feature('javascript-actions')) {3694print qq!<script type="text/javascript">\n!.3695 qq!window.onload = fixLinks;\n!.3696 qq!</script>\n!;3697}36983699print"</body>\n".3700"</html>";3701}37023703# die_error(<http_status_code>, <error_message>[, <detailed_html_description>])3704# Example: die_error(404, 'Hash not found')3705# By convention, use the following status codes (as defined in RFC 2616):3706# 400: Invalid or missing CGI parameters, or3707# requested object exists but has wrong type.3708# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3709# this server or project.3710# 404: Requested object/revision/project doesn't exist.3711# 500: The server isn't configured properly, or3712# an internal error occurred (e.g. failed assertions caused by bugs), or3713# an unknown error occurred (e.g. the git binary died unexpectedly).3714# 503: The server is currently unavailable (because it is overloaded,3715# or down for maintenance). Generally, this is a temporary state.3716sub die_error {3717my$status=shift||500;3718my$error= esc_html(shift) ||"Internal Server Error";3719my$extra=shift;3720my%opts=@_;37213722my%http_responses= (3723400=>'400 Bad Request',3724403=>'403 Forbidden',3725404=>'404 Not Found',3726500=>'500 Internal Server Error',3727503=>'503 Service Unavailable',3728);3729 git_header_html($http_responses{$status},undef,%opts);3730print<<EOF;3731<div class="page_body">3732<br /><br />3733$status-$error3734<br />3735EOF3736if(defined$extra) {3737print"<hr />\n".3738"$extra\n";3739}3740print"</div>\n";37413742 git_footer_html();3743goto DONE_GITWEB3744unless($opts{'-error_handler'});3745}37463747## ----------------------------------------------------------------------3748## functions printing or outputting HTML: navigation37493750sub git_print_page_nav {3751my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3752$extra=''if!defined$extra;# pager or formats37533754my@navs=qw(summary shortlog log commit commitdiff tree);3755if($suppress) {3756@navs=grep{$_ne$suppress}@navs;3757}37583759my%arg=map{$_=> {action=>$_} }@navs;3760if(defined$head) {3761for(qw(commit commitdiff)) {3762$arg{$_}{'hash'} =$head;3763}3764if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3765for(qw(shortlog log)) {3766$arg{$_}{'hash'} =$head;3767}3768}3769}37703771$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3772$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;37733774my@actions= gitweb_get_feature('actions');3775my%repl= (3776'%'=>'%',3777'n'=>$project,# project name3778'f'=>$git_dir,# project path within filesystem3779'h'=>$treehead||'',# current hash ('h' parameter)3780'b'=>$treebase||'',# hash base ('hb' parameter)3781);3782while(@actions) {3783my($label,$link,$pos) =splice(@actions,0,3);3784# insert3785@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3786# munch munch3787$link=~s/%([%nfhb])/$repl{$1}/g;3788$arg{$label}{'_href'} =$link;3789}37903791print"<div class=\"page_nav\">\n".3792(join" | ",3793map{$_eq$current?3794$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3795}@navs);3796print"<br/>\n$extra<br/>\n".3797"</div>\n";3798}37993800# returns a submenu for the nagivation of the refs views (tags, heads,3801# remotes) with the current view disabled and the remotes view only3802# available if the feature is enabled3803sub format_ref_views {3804my($current) =@_;3805my@ref_views=qw{tags heads};3806push@ref_views,'remotes'if gitweb_check_feature('remote_heads');3807returnjoin" | ",map{3808$_eq$current?$_:3809$cgi->a({-href => href(action=>$_)},$_)3810}@ref_views3811}38123813sub format_paging_nav {3814my($action,$page,$has_next_link) =@_;3815my$paging_nav;381638173818if($page>0) {3819$paging_nav.=3820$cgi->a({-href => href(-replay=>1, page=>undef)},"first") .3821" ⋅ ".3822$cgi->a({-href => href(-replay=>1, page=>$page-1),3823-accesskey =>"p", -title =>"Alt-p"},"prev");3824}else{3825$paging_nav.="first ⋅ prev";3826}38273828if($has_next_link) {3829$paging_nav.=" ⋅ ".3830$cgi->a({-href => href(-replay=>1, page=>$page+1),3831-accesskey =>"n", -title =>"Alt-n"},"next");3832}else{3833$paging_nav.=" ⋅ next";3834}38353836return$paging_nav;3837}38383839## ......................................................................3840## functions printing or outputting HTML: div38413842sub git_print_header_div {3843my($action,$title,$hash,$hash_base) =@_;3844my%args= ();38453846$args{'action'} =$action;3847$args{'hash'} =$hashif$hash;3848$args{'hash_base'} =$hash_baseif$hash_base;38493850print"<div class=\"header\">\n".3851$cgi->a({-href => href(%args), -class=>"title"},3852$title?$title:$action) .3853"\n</div>\n";3854}38553856sub format_repo_url {3857my($name,$url) =@_;3858return"<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";3859}38603861# Group output by placing it in a DIV element and adding a header.3862# Options for start_div() can be provided by passing a hash reference as the3863# first parameter to the function.3864# Options to git_print_header_div() can be provided by passing an array3865# reference. This must follow the options to start_div if they are present.3866# The content can be a scalar, which is output as-is, a scalar reference, which3867# is output after html escaping, an IO handle passed either as *handle or3868# *handle{IO}, or a function reference. In the latter case all following3869# parameters will be taken as argument to the content function call.3870sub git_print_section {3871my($div_args,$header_args,$content);3872my$arg=shift;3873if(ref($arg)eq'HASH') {3874$div_args=$arg;3875$arg=shift;3876}3877if(ref($arg)eq'ARRAY') {3878$header_args=$arg;3879$arg=shift;3880}3881$content=$arg;38823883print$cgi->start_div($div_args);3884 git_print_header_div(@$header_args);38853886if(ref($content)eq'CODE') {3887$content->(@_);3888}elsif(ref($content)eq'SCALAR') {3889print esc_html($$content);3890}elsif(ref($content)eq'GLOB'or ref($content)eq'IO::Handle') {3891print<$content>;3892}elsif(!ref($content) &&defined($content)) {3893print$content;3894}38953896print$cgi->end_div;3897}38983899sub print_local_time {3900print format_local_time(@_);3901}39023903sub format_local_time {3904my$localtime='';3905my%date=@_;3906if($date{'hour_local'} <6) {3907$localtime.=sprintf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3908$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3909}else{3910$localtime.=sprintf(" (%02d:%02d%s)",3911$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3912}39133914return$localtime;3915}39163917# Outputs the author name and date in long form3918sub git_print_authorship {3919my$co=shift;3920my%opts=@_;3921my$tag=$opts{-tag} ||'div';3922my$author=$co->{'author_name'};39233924my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3925print"<$tagclass=\"author_date\">".3926 format_search_author($author,"author", esc_html($author)) .3927" [$ad{'rfc2822'}";3928 print_local_time(%ad)if($opts{-localtime});3929print"]". git_get_avatar($co->{'author_email'}, -pad_before =>1)3930."</$tag>\n";3931}39323933# Outputs table rows containing the full author or committer information,3934# in the format expected for 'commit' view (& similar).3935# Parameters are a commit hash reference, followed by the list of people3936# to output information for. If the list is empty it defaults to both3937# author and committer.3938sub git_print_authorship_rows {3939my$co=shift;3940# too bad we can't use @people = @_ || ('author', 'committer')3941my@people=@_;3942@people= ('author','committer')unless@people;3943foreachmy$who(@people) {3944my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});3945print"<tr><td>$who</td><td>".3946 format_search_author($co->{"${who}_name"},$who,3947 esc_html($co->{"${who}_name"})) ." ".3948 format_search_author($co->{"${who}_email"},$who,3949 esc_html("<".$co->{"${who}_email"} .">")) .3950"</td><td rowspan=\"2\">".3951 git_get_avatar($co->{"${who}_email"}, -size =>'double') .3952"</td></tr>\n".3953"<tr>".3954"<td></td><td>$wd{'rfc2822'}";3955 print_local_time(%wd);3956print"</td>".3957"</tr>\n";3958}3959}39603961sub git_print_page_path {3962my$name=shift;3963my$type=shift;3964my$hb=shift;396539663967print"<div class=\"page_path\">";3968print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3969-title =>'tree root'}, to_utf8("[$project]"));3970print" / ";3971if(defined$name) {3972my@dirname=split'/',$name;3973my$basename=pop@dirname;3974my$fullname='';39753976foreachmy$dir(@dirname) {3977$fullname.= ($fullname?'/':'') .$dir;3978print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3979 hash_base=>$hb),3980-title =>$fullname}, esc_path($dir));3981print" / ";3982}3983if(defined$type&&$typeeq'blob') {3984print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3985 hash_base=>$hb),3986-title =>$name}, esc_path($basename));3987}elsif(defined$type&&$typeeq'tree') {3988print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3989 hash_base=>$hb),3990-title =>$name}, esc_path($basename));3991print" / ";3992}else{3993print esc_path($basename);3994}3995}3996print"<br/></div>\n";3997}39983999sub git_print_log {4000my$log=shift;4001my%opts=@_;40024003if($opts{'-remove_title'}) {4004# remove title, i.e. first line of log4005shift@$log;4006}4007# remove leading empty lines4008while(defined$log->[0] &&$log->[0]eq"") {4009shift@$log;4010}40114012# print log4013my$signoff=0;4014my$empty=0;4015foreachmy$line(@$log) {4016if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {4017$signoff=1;4018$empty=0;4019if(!$opts{'-remove_signoff'}) {4020print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";4021next;4022}else{4023# remove signoff lines4024next;4025}4026}else{4027$signoff=0;4028}40294030# print only one empty line4031# do not print empty line after signoff4032if($lineeq"") {4033next if($empty||$signoff);4034$empty=1;4035}else{4036$empty=0;4037}40384039print format_log_line_html($line) ."<br/>\n";4040}40414042if($opts{'-final_empty_line'}) {4043# end with single empty line4044print"<br/>\n"unless$empty;4045}4046}40474048# return link target (what link points to)4049sub git_get_link_target {4050my$hash=shift;4051my$link_target;40524053# read link4054open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4055orreturn;4056{4057local$/=undef;4058$link_target= <$fd>;4059}4060close$fd4061orreturn;40624063return$link_target;4064}40654066# given link target, and the directory (basedir) the link is in,4067# return target of link relative to top directory (top tree);4068# return undef if it is not possible (including absolute links).4069sub normalize_link_target {4070my($link_target,$basedir) =@_;40714072# absolute symlinks (beginning with '/') cannot be normalized4073return if(substr($link_target,0,1)eq'/');40744075# normalize link target to path from top (root) tree (dir)4076my$path;4077if($basedir) {4078$path=$basedir.'/'.$link_target;4079}else{4080# we are in top (root) tree (dir)4081$path=$link_target;4082}40834084# remove //, /./, and /../4085my@path_parts;4086foreachmy$part(split('/',$path)) {4087# discard '.' and ''4088next if(!$part||$parteq'.');4089# handle '..'4090if($parteq'..') {4091if(@path_parts) {4092pop@path_parts;4093}else{4094# link leads outside repository (outside top dir)4095return;4096}4097}else{4098push@path_parts,$part;4099}4100}4101$path=join('/',@path_parts);41024103return$path;4104}41054106# print tree entry (row of git_tree), but without encompassing <tr> element4107sub git_print_tree_entry {4108my($t,$basedir,$hash_base,$have_blame) =@_;41094110my%base_key= ();4111$base_key{'hash_base'} =$hash_baseifdefined$hash_base;41124113# The format of a table row is: mode list link. Where mode is4114# the mode of the entry, list is the name of the entry, an href,4115# and link is the action links of the entry.41164117print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";4118if(exists$t->{'size'}) {4119print"<td class=\"size\">$t->{'size'}</td>\n";4120}4121if($t->{'type'}eq"blob") {4122print"<td class=\"list\">".4123$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4124 file_name=>"$basedir$t->{'name'}",%base_key),4125-class=>"list"}, esc_path($t->{'name'}));4126if(S_ISLNK(oct$t->{'mode'})) {4127my$link_target= git_get_link_target($t->{'hash'});4128if($link_target) {4129my$norm_target= normalize_link_target($link_target,$basedir);4130if(defined$norm_target) {4131print" -> ".4132$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,4133 file_name=>$norm_target),4134-title =>$norm_target}, esc_path($link_target));4135}else{4136print" -> ". esc_path($link_target);4137}4138}4139}4140print"</td>\n";4141print"<td class=\"link\">";4142print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4143 file_name=>"$basedir$t->{'name'}",%base_key)},4144"blob");4145if($have_blame) {4146print" | ".4147$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},4148 file_name=>"$basedir$t->{'name'}",%base_key)},4149"blame");4150}4151if(defined$hash_base) {4152print" | ".4153$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,4154 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},4155"history");4156}4157print" | ".4158$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,4159 file_name=>"$basedir$t->{'name'}")},4160"raw");4161print"</td>\n";41624163}elsif($t->{'type'}eq"tree") {4164print"<td class=\"list\">";4165print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},4166 file_name=>"$basedir$t->{'name'}",4167%base_key)},4168 esc_path($t->{'name'}));4169print"</td>\n";4170print"<td class=\"link\">";4171print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},4172 file_name=>"$basedir$t->{'name'}",4173%base_key)},4174"tree");4175if(defined$hash_base) {4176print" | ".4177$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,4178 file_name=>"$basedir$t->{'name'}")},4179"history");4180}4181print"</td>\n";4182}else{4183# unknown object: we can only present history for it4184# (this includes 'commit' object, i.e. submodule support)4185print"<td class=\"list\">".4186 esc_path($t->{'name'}) .4187"</td>\n";4188print"<td class=\"link\">";4189if(defined$hash_base) {4190print$cgi->a({-href => href(action=>"history",4191 hash_base=>$hash_base,4192 file_name=>"$basedir$t->{'name'}")},4193"history");4194}4195print"</td>\n";4196}4197}41984199## ......................................................................4200## functions printing large fragments of HTML42014202# get pre-image filenames for merge (combined) diff4203sub fill_from_file_info {4204my($diff,@parents) =@_;42054206$diff->{'from_file'} = [ ];4207$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;4208for(my$i=0;$i<$diff->{'nparents'};$i++) {4209if($diff->{'status'}[$i]eq'R'||4210$diff->{'status'}[$i]eq'C') {4211$diff->{'from_file'}[$i] =4212 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);4213}4214}42154216return$diff;4217}42184219# is current raw difftree line of file deletion4220sub is_deleted {4221my$diffinfo=shift;42224223return$diffinfo->{'to_id'}eq('0' x 40);4224}42254226# does patch correspond to [previous] difftree raw line4227# $diffinfo - hashref of parsed raw diff format4228# $patchinfo - hashref of parsed patch diff format4229# (the same keys as in $diffinfo)4230sub is_patch_split {4231my($diffinfo,$patchinfo) =@_;42324233returndefined$diffinfo&&defined$patchinfo4234&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};4235}423642374238sub git_difftree_body {4239my($difftree,$hash,@parents) =@_;4240my($parent) =$parents[0];4241my$have_blame= gitweb_check_feature('blame');4242print"<div class=\"list_head\">\n";4243if($#{$difftree} >10) {4244print(($#{$difftree} +1) ." files changed:\n");4245}4246print"</div>\n";42474248print"<table class=\"".4249(@parents>1?"combined ":"") .4250"diff_tree\">\n";42514252# header only for combined diff in 'commitdiff' view4253my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';4254if($has_header) {4255# table header4256print"<thead><tr>\n".4257"<th></th><th></th>\n";# filename, patchN link4258for(my$i=0;$i<@parents;$i++) {4259my$par=$parents[$i];4260print"<th>".4261$cgi->a({-href => href(action=>"commitdiff",4262 hash=>$hash, hash_parent=>$par),4263-title =>'commitdiff to parent number '.4264($i+1) .': '.substr($par,0,7)},4265$i+1) .4266" </th>\n";4267}4268print"</tr></thead>\n<tbody>\n";4269}42704271my$alternate=1;4272my$patchno=0;4273foreachmy$line(@{$difftree}) {4274my$diff= parsed_difftree_line($line);42754276if($alternate) {4277print"<tr class=\"dark\">\n";4278}else{4279print"<tr class=\"light\">\n";4280}4281$alternate^=1;42824283if(exists$diff->{'nparents'}) {# combined diff42844285 fill_from_file_info($diff,@parents)4286unlessexists$diff->{'from_file'};42874288if(!is_deleted($diff)) {4289# file exists in the result (child) commit4290print"<td>".4291$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4292 file_name=>$diff->{'to_file'},4293 hash_base=>$hash),4294-class=>"list"}, esc_path($diff->{'to_file'})) .4295"</td>\n";4296}else{4297print"<td>".4298 esc_path($diff->{'to_file'}) .4299"</td>\n";4300}43014302if($actioneq'commitdiff') {4303# link to patch4304$patchno++;4305print"<td class=\"link\">".4306$cgi->a({-href =>"#patch$patchno"},"patch") .4307" | ".4308"</td>\n";4309}43104311my$has_history=0;4312my$not_deleted=0;4313for(my$i=0;$i<$diff->{'nparents'};$i++) {4314my$hash_parent=$parents[$i];4315my$from_hash=$diff->{'from_id'}[$i];4316my$from_path=$diff->{'from_file'}[$i];4317my$status=$diff->{'status'}[$i];43184319$has_history||= ($statusne'A');4320$not_deleted||= ($statusne'D');43214322if($statuseq'A') {4323print"<td class=\"link\"align=\"right\"> | </td>\n";4324}elsif($statuseq'D') {4325print"<td class=\"link\">".4326$cgi->a({-href => href(action=>"blob",4327 hash_base=>$hash,4328 hash=>$from_hash,4329 file_name=>$from_path)},4330"blob". ($i+1)) .4331" | </td>\n";4332}else{4333if($diff->{'to_id'}eq$from_hash) {4334print"<td class=\"link nochange\">";4335}else{4336print"<td class=\"link\">";4337}4338print$cgi->a({-href => href(action=>"blobdiff",4339 hash=>$diff->{'to_id'},4340 hash_parent=>$from_hash,4341 hash_base=>$hash,4342 hash_parent_base=>$hash_parent,4343 file_name=>$diff->{'to_file'},4344 file_parent=>$from_path)},4345"diff". ($i+1)) .4346" | </td>\n";4347}4348}43494350print"<td class=\"link\">";4351if($not_deleted) {4352print$cgi->a({-href => href(action=>"blob",4353 hash=>$diff->{'to_id'},4354 file_name=>$diff->{'to_file'},4355 hash_base=>$hash)},4356"blob");4357print" | "if($has_history);4358}4359if($has_history) {4360print$cgi->a({-href => href(action=>"history",4361 file_name=>$diff->{'to_file'},4362 hash_base=>$hash)},4363"history");4364}4365print"</td>\n";43664367print"</tr>\n";4368next;# instead of 'else' clause, to avoid extra indent4369}4370# else ordinary diff43714372my($to_mode_oct,$to_mode_str,$to_file_type);4373my($from_mode_oct,$from_mode_str,$from_file_type);4374if($diff->{'to_mode'}ne('0' x 6)) {4375$to_mode_oct=oct$diff->{'to_mode'};4376if(S_ISREG($to_mode_oct)) {# only for regular file4377$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits4378}4379$to_file_type= file_type($diff->{'to_mode'});4380}4381if($diff->{'from_mode'}ne('0' x 6)) {4382$from_mode_oct=oct$diff->{'from_mode'};4383if(S_ISREG($to_mode_oct)) {# only for regular file4384$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits4385}4386$from_file_type= file_type($diff->{'from_mode'});4387}43884389if($diff->{'status'}eq"A") {# created4390my$mode_chng="<span class=\"file_status new\">[new$to_file_type";4391$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;4392$mode_chng.="]</span>";4393print"<td>";4394print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4395 hash_base=>$hash, file_name=>$diff->{'file'}),4396-class=>"list"}, esc_path($diff->{'file'}));4397print"</td>\n";4398print"<td>$mode_chng</td>\n";4399print"<td class=\"link\">";4400if($actioneq'commitdiff') {4401# link to patch4402$patchno++;4403print$cgi->a({-href =>"#patch$patchno"},"patch");4404print" | ";4405}4406print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4407 hash_base=>$hash, file_name=>$diff->{'file'})},4408"blob");4409print"</td>\n";44104411}elsif($diff->{'status'}eq"D") {# deleted4412my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";4413print"<td>";4414print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4415 hash_base=>$parent, file_name=>$diff->{'file'}),4416-class=>"list"}, esc_path($diff->{'file'}));4417print"</td>\n";4418print"<td>$mode_chng</td>\n";4419print"<td class=\"link\">";4420if($actioneq'commitdiff') {4421# link to patch4422$patchno++;4423print$cgi->a({-href =>"#patch$patchno"},"patch");4424print" | ";4425}4426print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4427 hash_base=>$parent, file_name=>$diff->{'file'})},4428"blob") ." | ";4429if($have_blame) {4430print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,4431 file_name=>$diff->{'file'})},4432"blame") ." | ";4433}4434print$cgi->a({-href => href(action=>"history", hash_base=>$parent,4435 file_name=>$diff->{'file'})},4436"history");4437print"</td>\n";44384439}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed4440my$mode_chnge="";4441if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4442$mode_chnge="<span class=\"file_status mode_chnge\">[changed";4443if($from_file_typene$to_file_type) {4444$mode_chnge.=" from$from_file_typeto$to_file_type";4445}4446if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {4447if($from_mode_str&&$to_mode_str) {4448$mode_chnge.=" mode:$from_mode_str->$to_mode_str";4449}elsif($to_mode_str) {4450$mode_chnge.=" mode:$to_mode_str";4451}4452}4453$mode_chnge.="]</span>\n";4454}4455print"<td>";4456print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4457 hash_base=>$hash, file_name=>$diff->{'file'}),4458-class=>"list"}, esc_path($diff->{'file'}));4459print"</td>\n";4460print"<td>$mode_chnge</td>\n";4461print"<td class=\"link\">";4462if($actioneq'commitdiff') {4463# link to patch4464$patchno++;4465print$cgi->a({-href =>"#patch$patchno"},"patch") .4466" | ";4467}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4468# "commit" view and modified file (not onlu mode changed)4469print$cgi->a({-href => href(action=>"blobdiff",4470 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4471 hash_base=>$hash, hash_parent_base=>$parent,4472 file_name=>$diff->{'file'})},4473"diff") .4474" | ";4475}4476print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4477 hash_base=>$hash, file_name=>$diff->{'file'})},4478"blob") ." | ";4479if($have_blame) {4480print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4481 file_name=>$diff->{'file'})},4482"blame") ." | ";4483}4484print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4485 file_name=>$diff->{'file'})},4486"history");4487print"</td>\n";44884489}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied4490my%status_name= ('R'=>'moved','C'=>'copied');4491my$nstatus=$status_name{$diff->{'status'}};4492my$mode_chng="";4493if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4494# mode also for directories, so we cannot use $to_mode_str4495$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);4496}4497print"<td>".4498$cgi->a({-href => href(action=>"blob", hash_base=>$hash,4499 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),4500-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".4501"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".4502$cgi->a({-href => href(action=>"blob", hash_base=>$parent,4503 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),4504-class=>"list"}, esc_path($diff->{'from_file'})) .4505" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".4506"<td class=\"link\">";4507if($actioneq'commitdiff') {4508# link to patch4509$patchno++;4510print$cgi->a({-href =>"#patch$patchno"},"patch") .4511" | ";4512}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4513# "commit" view and modified file (not only pure rename or copy)4514print$cgi->a({-href => href(action=>"blobdiff",4515 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4516 hash_base=>$hash, hash_parent_base=>$parent,4517 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},4518"diff") .4519" | ";4520}4521print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4522 hash_base=>$parent, file_name=>$diff->{'to_file'})},4523"blob") ." | ";4524if($have_blame) {4525print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4526 file_name=>$diff->{'to_file'})},4527"blame") ." | ";4528}4529print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4530 file_name=>$diff->{'to_file'})},4531"history");4532print"</td>\n";45334534}# we should not encounter Unmerged (U) or Unknown (X) status4535print"</tr>\n";4536}4537print"</tbody>"if$has_header;4538print"</table>\n";4539}45404541sub git_patchset_body {4542my($fd,$difftree,$hash,@hash_parents) =@_;4543my($hash_parent) =$hash_parents[0];45444545my$is_combined= (@hash_parents>1);4546my$patch_idx=0;4547my$patch_number=0;4548my$patch_line;4549my$diffinfo;4550my$to_name;4551my(%from,%to);45524553print"<div class=\"patchset\">\n";45544555# skip to first patch4556while($patch_line= <$fd>) {4557chomp$patch_line;45584559last if($patch_line=~m/^diff /);4560}45614562 PATCH:4563while($patch_line) {45644565# parse "git diff" header line4566if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {4567# $1 is from_name, which we do not use4568$to_name= unquote($2);4569$to_name=~s!^b/!!;4570}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {4571# $1 is 'cc' or 'combined', which we do not use4572$to_name= unquote($2);4573}else{4574$to_name=undef;4575}45764577# check if current patch belong to current raw line4578# and parse raw git-diff line if needed4579if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {4580# this is continuation of a split patch4581print"<div class=\"patch cont\">\n";4582}else{4583# advance raw git-diff output if needed4584$patch_idx++ifdefined$diffinfo;45854586# read and prepare patch information4587$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);45884589# compact combined diff output can have some patches skipped4590# find which patch (using pathname of result) we are at now;4591if($is_combined) {4592while($to_namene$diffinfo->{'to_file'}) {4593print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4594 format_diff_cc_simplified($diffinfo,@hash_parents) .4595"</div>\n";# class="patch"45964597$patch_idx++;4598$patch_number++;45994600last if$patch_idx>$#$difftree;4601$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);4602}4603}46044605# modifies %from, %to hashes4606 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);46074608# this is first patch for raw difftree line with $patch_idx index4609# we index @$difftree array from 0, but number patches from 14610print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";4611}46124613# git diff header4614#assert($patch_line =~ m/^diff /) if DEBUG;4615#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed4616$patch_number++;4617# print "git diff" header4618print format_git_diff_header_line($patch_line,$diffinfo,4619 \%from, \%to);46204621# print extended diff header4622print"<div class=\"diff extended_header\">\n";4623 EXTENDED_HEADER:4624while($patch_line= <$fd>) {4625chomp$patch_line;46264627last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);46284629print format_extended_diff_header_line($patch_line,$diffinfo,4630 \%from, \%to);4631}4632print"</div>\n";# class="diff extended_header"46334634# from-file/to-file diff header4635if(!$patch_line) {4636print"</div>\n";# class="patch"4637last PATCH;4638}4639next PATCH if($patch_line=~m/^diff /);4640#assert($patch_line =~ m/^---/) if DEBUG;46414642my$last_patch_line=$patch_line;4643$patch_line= <$fd>;4644chomp$patch_line;4645#assert($patch_line =~ m/^\+\+\+/) if DEBUG;46464647print format_diff_from_to_header($last_patch_line,$patch_line,4648$diffinfo, \%from, \%to,4649@hash_parents);46504651# the patch itself4652 LINE:4653while($patch_line= <$fd>) {4654chomp$patch_line;46554656next PATCH if($patch_line=~m/^diff /);46574658print format_diff_line($patch_line, \%from, \%to);4659}46604661}continue{4662print"</div>\n";# class="patch"4663}46644665# for compact combined (--cc) format, with chunk and patch simplification4666# the patchset might be empty, but there might be unprocessed raw lines4667for(++$patch_idxif$patch_number>0;4668$patch_idx<@$difftree;4669++$patch_idx) {4670# read and prepare patch information4671$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);46724673# generate anchor for "patch" links in difftree / whatchanged part4674print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4675 format_diff_cc_simplified($diffinfo,@hash_parents) .4676"</div>\n";# class="patch"46774678$patch_number++;4679}46804681if($patch_number==0) {4682if(@hash_parents>1) {4683print"<div class=\"diff nodifferences\">Trivial merge</div>\n";4684}else{4685print"<div class=\"diff nodifferences\">No differences found</div>\n";4686}4687}46884689print"</div>\n";# class="patchset"4690}46914692# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46934694# fills project list info (age, description, owner, forks) for each4695# project in the list, removing invalid projects from returned list4696# NOTE: modifies $projlist, but does not remove entries from it4697sub fill_project_list_info {4698my($projlist,$check_forks) =@_;4699my@projects;47004701my$show_ctags= gitweb_check_feature('ctags');4702 PROJECT:4703foreachmy$pr(@$projlist) {4704my(@activity) = git_get_last_activity($pr->{'path'});4705unless(@activity) {4706next PROJECT;4707}4708($pr->{'age'},$pr->{'age_string'}) =@activity;4709if(!defined$pr->{'descr'}) {4710my$descr= git_get_project_description($pr->{'path'}) ||"";4711$descr= to_utf8($descr);4712$pr->{'descr_long'} =$descr;4713$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4714}4715if(!defined$pr->{'owner'}) {4716$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4717}4718if($check_forks) {4719my$pname=$pr->{'path'};4720if(($pname=~s/\.git$//) &&4721($pname!~/\/$/) &&4722(-d "$projectroot/$pname")) {4723$pr->{'forks'} ="-d$projectroot/$pname";4724}else{4725$pr->{'forks'} =0;4726}4727}4728$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4729push@projects,$pr;4730}47314732return@projects;4733}47344735# print 'sort by' <th> element, generating 'sort by $name' replay link4736# if that order is not selected4737sub print_sort_th {4738print format_sort_th(@_);4739}47404741sub format_sort_th {4742my($name,$order,$header) =@_;4743my$sort_th="";4744$header||=ucfirst($name);47454746if($ordereq$name) {4747$sort_th.="<th>$header</th>\n";4748}else{4749$sort_th.="<th>".4750$cgi->a({-href => href(-replay=>1, order=>$name),4751-class=>"header"},$header) .4752"</th>\n";4753}47544755return$sort_th;4756}47574758sub git_project_list_body {4759# actually uses global variable $project4760my($projlist,$order,$from,$to,$extra,$no_header) =@_;47614762my$check_forks= gitweb_check_feature('forks');4763my@projects= fill_project_list_info($projlist,$check_forks);47644765$order||=$default_projects_order;4766$from=0unlessdefined$from;4767$to=$#projectsif(!defined$to||$#projects<$to);47684769my%order_info= (4770 project => { key =>'path', type =>'str'},4771 descr => { key =>'descr_long', type =>'str'},4772 owner => { key =>'owner', type =>'str'},4773 age => { key =>'age', type =>'num'}4774);4775my$oi=$order_info{$order};4776if($oi->{'type'}eq'str') {4777@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4778}else{4779@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4780}47814782my$show_ctags= gitweb_check_feature('ctags');4783if($show_ctags) {4784my%ctags;4785foreachmy$p(@projects) {4786foreachmy$ct(keys%{$p->{'ctags'}}) {4787$ctags{$ct} +=$p->{'ctags'}->{$ct};4788}4789}4790my$cloud= git_populate_project_tagcloud(\%ctags);4791print git_show_project_tagcloud($cloud,64);4792}47934794print"<table class=\"project_list\">\n";4795unless($no_header) {4796print"<tr>\n";4797if($check_forks) {4798print"<th></th>\n";4799}4800 print_sort_th('project',$order,'Project');4801 print_sort_th('descr',$order,'Description');4802 print_sort_th('owner',$order,'Owner');4803 print_sort_th('age',$order,'Last Change');4804print"<th></th>\n".# for links4805"</tr>\n";4806}4807my$alternate=1;4808my$tagfilter=$cgi->param('by_tag');4809for(my$i=$from;$i<=$to;$i++) {4810my$pr=$projects[$i];48114812next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4813next if$searchtextand not$pr->{'path'} =~/$searchtext/4814and not$pr->{'descr_long'} =~/$searchtext/;4815# Weed out forks or non-matching entries of search4816if($check_forks) {4817my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4818$forkbase="^$forkbase"if$forkbase;4819next ifnot$searchtextand not$tagfilterand$show_ctags4820and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4821}48224823if($alternate) {4824print"<tr class=\"dark\">\n";4825}else{4826print"<tr class=\"light\">\n";4827}4828$alternate^=1;4829if($check_forks) {4830print"<td>";4831if($pr->{'forks'}) {4832print"<!--$pr->{'forks'} -->\n";4833print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4834}4835print"</td>\n";4836}4837print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4838-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4839"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4840-class=>"list", -title =>$pr->{'descr_long'}},4841 esc_html($pr->{'descr'})) ."</td>\n".4842"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4843print"<td class=\"". age_class($pr->{'age'}) ."\">".4844(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4845"<td class=\"link\">".4846$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4847$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4848$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4849$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4850($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4851"</td>\n".4852"</tr>\n";4853}4854if(defined$extra) {4855print"<tr>\n";4856if($check_forks) {4857print"<td></td>\n";4858}4859print"<td colspan=\"5\">$extra</td>\n".4860"</tr>\n";4861}4862print"</table>\n";4863}48644865sub git_log_body {4866# uses global variable $project4867my($commitlist,$from,$to,$refs,$extra) =@_;48684869$from=0unlessdefined$from;4870$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);48714872for(my$i=0;$i<=$to;$i++) {4873my%co= %{$commitlist->[$i]};4874next if!%co;4875my$commit=$co{'id'};4876my$ref= format_ref_marker($refs,$commit);4877my%ad= parse_date($co{'author_epoch'});4878 git_print_header_div('commit',4879"<span class=\"age\">$co{'age_string'}</span>".4880 esc_html($co{'title'}) .$ref,4881$commit);4882print"<div class=\"title_text\">\n".4883"<div class=\"log_link\">\n".4884$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .4885" | ".4886$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .4887" | ".4888$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .4889"<br/>\n".4890"</div>\n";4891 git_print_authorship(\%co, -tag =>'span');4892print"<br/>\n</div>\n";48934894print"<div class=\"log_body\">\n";4895 git_print_log($co{'comment'}, -final_empty_line=>1);4896print"</div>\n";4897}4898if($extra) {4899print"<div class=\"page_nav\">\n";4900print"$extra\n";4901print"</div>\n";4902}4903}49044905sub git_shortlog_body {4906# uses global variable $project4907my($commitlist,$from,$to,$refs,$extra) =@_;49084909$from=0unlessdefined$from;4910$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);49114912print"<table class=\"shortlog\">\n";4913my$alternate=1;4914for(my$i=$from;$i<=$to;$i++) {4915my%co= %{$commitlist->[$i]};4916my$commit=$co{'id'};4917my$ref= format_ref_marker($refs,$commit);4918if($alternate) {4919print"<tr class=\"dark\">\n";4920}else{4921print"<tr class=\"light\">\n";4922}4923$alternate^=1;4924# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4925print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4926 format_author_html('td', \%co,10) ."<td>";4927print format_subject_html($co{'title'},$co{'title_short'},4928 href(action=>"commit", hash=>$commit),$ref);4929print"</td>\n".4930"<td class=\"link\">".4931$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4932$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4933$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4934my$snapshot_links= format_snapshot_links($commit);4935if(defined$snapshot_links) {4936print" | ".$snapshot_links;4937}4938print"</td>\n".4939"</tr>\n";4940}4941if(defined$extra) {4942print"<tr>\n".4943"<td colspan=\"4\">$extra</td>\n".4944"</tr>\n";4945}4946print"</table>\n";4947}49484949sub git_history_body {4950# Warning: assumes constant type (blob or tree) during history4951my($commitlist,$from,$to,$refs,$extra,4952$file_name,$file_hash,$ftype) =@_;49534954$from=0unlessdefined$from;4955$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});49564957print"<table class=\"history\">\n";4958my$alternate=1;4959for(my$i=$from;$i<=$to;$i++) {4960my%co= %{$commitlist->[$i]};4961if(!%co) {4962next;4963}4964my$commit=$co{'id'};49654966my$ref= format_ref_marker($refs,$commit);49674968if($alternate) {4969print"<tr class=\"dark\">\n";4970}else{4971print"<tr class=\"light\">\n";4972}4973$alternate^=1;4974print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4975# shortlog: format_author_html('td', \%co, 10)4976 format_author_html('td', \%co,15,3) ."<td>";4977# originally git_history used chop_str($co{'title'}, 50)4978print format_subject_html($co{'title'},$co{'title_short'},4979 href(action=>"commit", hash=>$commit),$ref);4980print"</td>\n".4981"<td class=\"link\">".4982$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4983$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");49844985if($ftypeeq'blob') {4986my$blob_current=$file_hash;4987my$blob_parent= git_get_hash_by_path($commit,$file_name);4988if(defined$blob_current&&defined$blob_parent&&4989$blob_currentne$blob_parent) {4990print" | ".4991$cgi->a({-href => href(action=>"blobdiff",4992 hash=>$blob_current, hash_parent=>$blob_parent,4993 hash_base=>$hash_base, hash_parent_base=>$commit,4994 file_name=>$file_name)},4995"diff to current");4996}4997}4998print"</td>\n".4999"</tr>\n";5000}5001if(defined$extra) {5002print"<tr>\n".5003"<td colspan=\"4\">$extra</td>\n".5004"</tr>\n";5005}5006print"</table>\n";5007}50085009sub git_tags_body {5010# uses global variable $project5011my($taglist,$from,$to,$extra) =@_;5012$from=0unlessdefined$from;5013$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);50145015print"<table class=\"tags\">\n";5016my$alternate=1;5017for(my$i=$from;$i<=$to;$i++) {5018my$entry=$taglist->[$i];5019my%tag=%$entry;5020my$comment=$tag{'subject'};5021my$comment_short;5022if(defined$comment) {5023$comment_short= chop_str($comment,30,5);5024}5025if($alternate) {5026print"<tr class=\"dark\">\n";5027}else{5028print"<tr class=\"light\">\n";5029}5030$alternate^=1;5031if(defined$tag{'age'}) {5032print"<td><i>$tag{'age'}</i></td>\n";5033}else{5034print"<td></td>\n";5035}5036print"<td>".5037$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),5038-class=>"list name"}, esc_html($tag{'name'})) .5039"</td>\n".5040"<td>";5041if(defined$comment) {5042print format_subject_html($comment,$comment_short,5043 href(action=>"tag", hash=>$tag{'id'}));5044}5045print"</td>\n".5046"<td class=\"selflink\">";5047if($tag{'type'}eq"tag") {5048print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");5049}else{5050print" ";5051}5052print"</td>\n".5053"<td class=\"link\">"." | ".5054$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});5055if($tag{'reftype'}eq"commit") {5056print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .5057" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");5058}elsif($tag{'reftype'}eq"blob") {5059print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");5060}5061print"</td>\n".5062"</tr>";5063}5064if(defined$extra) {5065print"<tr>\n".5066"<td colspan=\"5\">$extra</td>\n".5067"</tr>\n";5068}5069print"</table>\n";5070}50715072sub git_heads_body {5073# uses global variable $project5074my($headlist,$head,$from,$to,$extra) =@_;5075$from=0unlessdefined$from;5076$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);50775078print"<table class=\"heads\">\n";5079my$alternate=1;5080for(my$i=$from;$i<=$to;$i++) {5081my$entry=$headlist->[$i];5082my%ref=%$entry;5083my$curr=$ref{'id'}eq$head;5084if($alternate) {5085print"<tr class=\"dark\">\n";5086}else{5087print"<tr class=\"light\">\n";5088}5089$alternate^=1;5090print"<td><i>$ref{'age'}</i></td>\n".5091($curr?"<td class=\"current_head\">":"<td>") .5092$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),5093-class=>"list name"},esc_html($ref{'name'})) .5094"</td>\n".5095"<td class=\"link\">".5096$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".5097$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".5098$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'fullname'})},"tree") .5099"</td>\n".5100"</tr>";5101}5102if(defined$extra) {5103print"<tr>\n".5104"<td colspan=\"3\">$extra</td>\n".5105"</tr>\n";5106}5107print"</table>\n";5108}51095110# Display a single remote block5111sub git_remote_block {5112my($remote,$rdata,$limit,$head) =@_;51135114my$heads=$rdata->{'heads'};5115my$fetch=$rdata->{'fetch'};5116my$push=$rdata->{'push'};51175118my$urls_table="<table class=\"projects_list\">\n";51195120if(defined$fetch) {5121if($fetcheq$push) {5122$urls_table.= format_repo_url("URL",$fetch);5123}else{5124$urls_table.= format_repo_url("Fetch URL",$fetch);5125$urls_table.= format_repo_url("Push URL",$push)ifdefined$push;5126}5127}elsif(defined$push) {5128$urls_table.= format_repo_url("Push URL",$push);5129}else{5130$urls_table.= format_repo_url("","No remote URL");5131}51325133$urls_table.="</table>\n";51345135my$dots;5136if(defined$limit&&$limit<@$heads) {5137$dots=$cgi->a({-href => href(action=>"remotes", hash=>$remote)},"...");5138}51395140print$urls_table;5141 git_heads_body($heads,$head,0,$limit,$dots);5142}51435144# Display a list of remote names with the respective fetch and push URLs5145sub git_remotes_list {5146my($remotedata,$limit) =@_;5147print"<table class=\"heads\">\n";5148my$alternate=1;5149my@remotes=sort keys%$remotedata;51505151my$limited=$limit&&$limit<@remotes;51525153$#remotes=$limit-1if$limited;51545155while(my$remote=shift@remotes) {5156my$rdata=$remotedata->{$remote};5157my$fetch=$rdata->{'fetch'};5158my$push=$rdata->{'push'};5159if($alternate) {5160print"<tr class=\"dark\">\n";5161}else{5162print"<tr class=\"light\">\n";5163}5164$alternate^=1;5165print"<td>".5166$cgi->a({-href=> href(action=>'remotes', hash=>$remote),5167-class=>"list name"},esc_html($remote)) .5168"</td>";5169print"<td class=\"link\">".5170(defined$fetch?$cgi->a({-href=>$fetch},"fetch") :"fetch") .5171" | ".5172(defined$push?$cgi->a({-href=>$push},"push") :"push") .5173"</td>";51745175print"</tr>\n";5176}51775178if($limited) {5179print"<tr>\n".5180"<td colspan=\"3\">".5181$cgi->a({-href => href(action=>"remotes")},"...") .5182"</td>\n"."</tr>\n";5183}51845185print"</table>";5186}51875188# Display remote heads grouped by remote, unless there are too many5189# remotes, in which case we only display the remote names5190sub git_remotes_body {5191my($remotedata,$limit,$head) =@_;5192if($limitand$limit<keys%$remotedata) {5193 git_remotes_list($remotedata,$limit);5194}else{5195 fill_remote_heads($remotedata);5196while(my($remote,$rdata) =each%$remotedata) {5197 git_print_section({-class=>"remote", -id=>$remote},5198["remotes",$remote,$remote],sub{5199 git_remote_block($remote,$rdata,$limit,$head);5200});5201}5202}5203}52045205sub git_search_grep_body {5206my($commitlist,$from,$to,$extra) =@_;5207$from=0unlessdefined$from;5208$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);52095210print"<table class=\"commit_search\">\n";5211my$alternate=1;5212for(my$i=$from;$i<=$to;$i++) {5213my%co= %{$commitlist->[$i]};5214if(!%co) {5215next;5216}5217my$commit=$co{'id'};5218if($alternate) {5219print"<tr class=\"dark\">\n";5220}else{5221print"<tr class=\"light\">\n";5222}5223$alternate^=1;5224print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5225 format_author_html('td', \%co,15,5) .5226"<td>".5227$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),5228-class=>"list subject"},5229 chop_and_escape_str($co{'title'},50) ."<br/>");5230my$comment=$co{'comment'};5231foreachmy$line(@$comment) {5232if($line=~m/^(.*?)($search_regexp)(.*)$/i) {5233my($lead,$match,$trail) = ($1,$2,$3);5234$match= chop_str($match,70,5,'center');5235my$contextlen=int((80-length($match))/2);5236$contextlen=30if($contextlen>30);5237$lead= chop_str($lead,$contextlen,10,'left');5238$trail= chop_str($trail,$contextlen,10,'right');52395240$lead= esc_html($lead);5241$match= esc_html($match);5242$trail= esc_html($trail);52435244print"$lead<span class=\"match\">$match</span>$trail<br />";5245}5246}5247print"</td>\n".5248"<td class=\"link\">".5249$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5250" | ".5251$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .5252" | ".5253$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5254print"</td>\n".5255"</tr>\n";5256}5257if(defined$extra) {5258print"<tr>\n".5259"<td colspan=\"3\">$extra</td>\n".5260"</tr>\n";5261}5262print"</table>\n";5263}52645265## ======================================================================5266## ======================================================================5267## actions52685269sub git_project_list {5270my$order=$input_params{'order'};5271if(defined$order&&$order!~m/none|project|descr|owner|age/) {5272 die_error(400,"Unknown order parameter");5273}52745275my@list= git_get_projects_list();5276if(!@list) {5277 die_error(404,"No projects found");5278}52795280 git_header_html();5281if(defined$home_text&& -f $home_text) {5282print"<div class=\"index_include\">\n";5283 insert_file($home_text);5284print"</div>\n";5285}5286print$cgi->startform(-method=>"get") .5287"<p class=\"projsearch\">Search:\n".5288$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".5289"</p>".5290$cgi->end_form() ."\n";5291 git_project_list_body(\@list,$order);5292 git_footer_html();5293}52945295sub git_forks {5296my$order=$input_params{'order'};5297if(defined$order&&$order!~m/none|project|descr|owner|age/) {5298 die_error(400,"Unknown order parameter");5299}53005301my@list= git_get_projects_list($project);5302if(!@list) {5303 die_error(404,"No forks found");5304}53055306 git_header_html();5307 git_print_page_nav('','');5308 git_print_header_div('summary',"$projectforks");5309 git_project_list_body(\@list,$order);5310 git_footer_html();5311}53125313sub git_project_index {5314my@projects= git_get_projects_list($project);53155316print$cgi->header(5317-type =>'text/plain',5318-charset =>'utf-8',5319-content_disposition =>'inline; filename="index.aux"');53205321foreachmy$pr(@projects) {5322if(!exists$pr->{'owner'}) {5323$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");5324}53255326my($path,$owner) = ($pr->{'path'},$pr->{'owner'});5327# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '5328$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;5329$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;5330$path=~s/ /\+/g;5331$owner=~s/ /\+/g;53325333print"$path$owner\n";5334}5335}53365337sub git_summary {5338my$descr= git_get_project_description($project) ||"none";5339my%co= parse_commit("HEAD");5340my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();5341my$head=$co{'id'};5342my$remote_heads= gitweb_check_feature('remote_heads');53435344my$owner= git_get_project_owner($project);53455346my$refs= git_get_references();5347# These get_*_list functions return one more to allow us to see if5348# there are more ...5349my@taglist= git_get_tags_list(16);5350my@headlist= git_get_heads_list(16);5351my%remotedata=$remote_heads? git_get_remotes_list() : ();5352my@forklist;5353my$check_forks= gitweb_check_feature('forks');53545355if($check_forks) {5356@forklist= git_get_projects_list($project);5357}53585359 git_header_html();5360 git_print_page_nav('summary','',$head);53615362print"<div class=\"title\"> </div>\n";5363print"<table class=\"projects_list\">\n".5364"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".5365"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";5366if(defined$cd{'rfc2822'}) {5367print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";5368}53695370# use per project git URL list in $projectroot/$project/cloneurl5371# or make project git URL from git base URL and project name5372my$url_tag="URL";5373my@url_list= git_get_project_url_list($project);5374@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;5375foreachmy$git_url(@url_list) {5376next unless$git_url;5377print format_repo_url($url_tag,$git_url);5378$url_tag="";5379}53805381# Tag cloud5382my$show_ctags= gitweb_check_feature('ctags');5383if($show_ctags) {5384my$ctags= git_get_project_ctags($project);5385my$cloud= git_populate_project_tagcloud($ctags);5386print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";5387print"</td>\n<td>"unless%$ctags;5388print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";5389print"</td>\n<td>"if%$ctags;5390print git_show_project_tagcloud($cloud,48);5391print"</td></tr>";5392}53935394print"</table>\n";53955396# If XSS prevention is on, we don't include README.html.5397# TODO: Allow a readme in some safe format.5398if(!$prevent_xss&& -s "$projectroot/$project/README.html") {5399print"<div class=\"title\">readme</div>\n".5400"<div class=\"readme\">\n";5401 insert_file("$projectroot/$project/README.html");5402print"\n</div>\n";# class="readme"5403}54045405# we need to request one more than 16 (0..15) to check if5406# those 16 are all5407my@commitlist=$head? parse_commits($head,17) : ();5408if(@commitlist) {5409 git_print_header_div('shortlog');5410 git_shortlog_body(\@commitlist,0,15,$refs,5411$#commitlist<=15?undef:5412$cgi->a({-href => href(action=>"shortlog")},"..."));5413}54145415if(@taglist) {5416 git_print_header_div('tags');5417 git_tags_body(\@taglist,0,15,5418$#taglist<=15?undef:5419$cgi->a({-href => href(action=>"tags")},"..."));5420}54215422if(@headlist) {5423 git_print_header_div('heads');5424 git_heads_body(\@headlist,$head,0,15,5425$#headlist<=15?undef:5426$cgi->a({-href => href(action=>"heads")},"..."));5427}54285429if(%remotedata) {5430 git_print_header_div('remotes');5431 git_remotes_body(\%remotedata,15,$head);5432}54335434if(@forklist) {5435 git_print_header_div('forks');5436 git_project_list_body(\@forklist,'age',0,15,5437$#forklist<=15?undef:5438$cgi->a({-href => href(action=>"forks")},"..."),5439'no_header');5440}54415442 git_footer_html();5443}54445445sub git_tag {5446my%tag= parse_tag($hash);54475448if(!%tag) {5449 die_error(404,"Unknown tag object");5450}54515452my$head= git_get_head_hash($project);5453 git_header_html();5454 git_print_page_nav('','',$head,undef,$head);5455 git_print_header_div('commit', esc_html($tag{'name'}),$hash);5456print"<div class=\"title_text\">\n".5457"<table class=\"object_header\">\n".5458"<tr>\n".5459"<td>object</td>\n".5460"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},5461$tag{'object'}) ."</td>\n".5462"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},5463$tag{'type'}) ."</td>\n".5464"</tr>\n";5465if(defined($tag{'author'})) {5466 git_print_authorship_rows(\%tag,'author');5467}5468print"</table>\n\n".5469"</div>\n";5470print"<div class=\"page_body\">";5471my$comment=$tag{'comment'};5472foreachmy$line(@$comment) {5473chomp$line;5474print esc_html($line, -nbsp=>1) ."<br/>\n";5475}5476print"</div>\n";5477 git_footer_html();5478}54795480sub git_blame_common {5481my$format=shift||'porcelain';5482if($formateq'porcelain'&&$cgi->param('js')) {5483$format='incremental';5484$action='blame_incremental';# for page title etc5485}54865487# permissions5488 gitweb_check_feature('blame')5489or die_error(403,"Blame view not allowed");54905491# error checking5492 die_error(400,"No file name given")unless$file_name;5493$hash_base||= git_get_head_hash($project);5494 die_error(404,"Couldn't find base commit")unless$hash_base;5495my%co= parse_commit($hash_base)5496or die_error(404,"Commit not found");5497my$ftype="blob";5498if(!defined$hash) {5499$hash= git_get_hash_by_path($hash_base,$file_name,"blob")5500or die_error(404,"Error looking up file");5501}else{5502$ftype= git_get_type($hash);5503if($ftype!~"blob") {5504 die_error(400,"Object is not a blob");5505}5506}55075508my$fd;5509if($formateq'incremental') {5510# get file contents (as base)5511open$fd,"-|", git_cmd(),'cat-file','blob',$hash5512or die_error(500,"Open git-cat-file failed");5513}elsif($formateq'data') {5514# run git-blame --incremental5515open$fd,"-|", git_cmd(),"blame","--incremental",5516$hash_base,"--",$file_name5517or die_error(500,"Open git-blame --incremental failed");5518}else{5519# run git-blame --porcelain5520open$fd,"-|", git_cmd(),"blame",'-p',5521$hash_base,'--',$file_name5522or die_error(500,"Open git-blame --porcelain failed");5523}55245525# incremental blame data returns early5526if($formateq'data') {5527print$cgi->header(5528-type=>"text/plain", -charset =>"utf-8",5529-status=>"200 OK");5530local$| =1;# output autoflush5531printwhile<$fd>;5532close$fd5533or print"ERROR$!\n";55345535print'END';5536if(defined$t0&& gitweb_check_feature('timed')) {5537print' '.5538 tv_interval($t0, [ gettimeofday() ]).5539' '.$number_of_git_cmds;5540}5541print"\n";55425543return;5544}55455546# page header5547 git_header_html();5548my$formats_nav=5549$cgi->a({-href => href(action=>"blob", -replay=>1)},5550"blob") .5551" | ";5552if($formateq'incremental') {5553$formats_nav.=5554$cgi->a({-href => href(action=>"blame", javascript=>0, -replay=>1)},5555"blame") ." (non-incremental)";5556}else{5557$formats_nav.=5558$cgi->a({-href => href(action=>"blame_incremental", -replay=>1)},5559"blame") ." (incremental)";5560}5561$formats_nav.=5562" | ".5563$cgi->a({-href => href(action=>"history", -replay=>1)},5564"history") .5565" | ".5566$cgi->a({-href => href(action=>$action, file_name=>$file_name)},5567"HEAD");5568 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5569 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5570 git_print_page_path($file_name,$ftype,$hash_base);55715572# page body5573if($formateq'incremental') {5574print"<noscript>\n<div class=\"error\"><center><b>\n".5575"This page requires JavaScript to run.\nUse ".5576$cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},5577'this page').5578" instead.\n".5579"</b></center></div>\n</noscript>\n";55805581print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!;5582}55835584print qq!<div class="page_body">\n!;5585print qq!<div id="progress_info">.../ ...</div>\n!5586if($formateq'incremental');5587print qq!<table id="blame_table"class="blame" width="100%">\n!.5588#qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.5589 qq!<thead>\n!.5590 qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!.5591 qq!</thead>\n!.5592 qq!<tbody>\n!;55935594my@rev_color=qw(light dark);5595my$num_colors=scalar(@rev_color);5596my$current_color=0;55975598if($formateq'incremental') {5599my$color_class=$rev_color[$current_color];56005601#contents of a file5602my$linenr=0;5603 LINE:5604while(my$line= <$fd>) {5605chomp$line;5606$linenr++;56075608print qq!<tr id="l$linenr"class="$color_class">!.5609 qq!<td class="sha1"><a href=""> </a></td>!.5610 qq!<td class="linenr">!.5611 qq!<a class="linenr" href="">$linenr</a></td>!;5612print qq!<td class="pre">! . esc_html($line) ."</td>\n";5613print qq!</tr>\n!;5614}56155616}else{# porcelain, i.e. ordinary blame5617my%metainfo= ();# saves information about commits56185619# blame data5620 LINE:5621while(my$line= <$fd>) {5622chomp$line;5623# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]5624# no <lines in group> for subsequent lines in group of lines5625my($full_rev,$orig_lineno,$lineno,$group_size) =5626($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);5627if(!exists$metainfo{$full_rev}) {5628$metainfo{$full_rev} = {'nprevious'=>0};5629}5630my$meta=$metainfo{$full_rev};5631my$data;5632while($data= <$fd>) {5633chomp$data;5634last if($data=~s/^\t//);# contents of line5635if($data=~/^(\S+)(?: (.*))?$/) {5636$meta->{$1} =$2unlessexists$meta->{$1};5637}5638if($data=~/^previous /) {5639$meta->{'nprevious'}++;5640}5641}5642my$short_rev=substr($full_rev,0,8);5643my$author=$meta->{'author'};5644my%date=5645 parse_date($meta->{'author-time'},$meta->{'author-tz'});5646my$date=$date{'iso-tz'};5647if($group_size) {5648$current_color= ($current_color+1) %$num_colors;5649}5650my$tr_class=$rev_color[$current_color];5651$tr_class.=' boundary'if(exists$meta->{'boundary'});5652$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);5653$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);5654print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";5655if($group_size) {5656print"<td class=\"sha1\"";5657print" title=\"". esc_html($author) .",$date\"";5658print" rowspan=\"$group_size\""if($group_size>1);5659print">";5660print$cgi->a({-href => href(action=>"commit",5661 hash=>$full_rev,5662 file_name=>$file_name)},5663 esc_html($short_rev));5664if($group_size>=2) {5665my@author_initials= ($author=~/\b([[:upper:]])\B/g);5666if(@author_initials) {5667print"<br />".5668 esc_html(join('',@author_initials));5669# or join('.', ...)5670}5671}5672print"</td>\n";5673}5674# 'previous' <sha1 of parent commit> <filename at commit>5675if(exists$meta->{'previous'} &&5676$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {5677$meta->{'parent'} =$1;5678$meta->{'file_parent'} = unquote($2);5679}5680my$linenr_commit=5681exists($meta->{'parent'}) ?5682$meta->{'parent'} :$full_rev;5683my$linenr_filename=5684exists($meta->{'file_parent'}) ?5685$meta->{'file_parent'} : unquote($meta->{'filename'});5686my$blamed= href(action =>'blame',5687 file_name =>$linenr_filename,5688 hash_base =>$linenr_commit);5689print"<td class=\"linenr\">";5690print$cgi->a({ -href =>"$blamed#l$orig_lineno",5691-class=>"linenr"},5692 esc_html($lineno));5693print"</td>";5694print"<td class=\"pre\">". esc_html($data) ."</td>\n";5695print"</tr>\n";5696}# end while56975698}56995700# footer5701print"</tbody>\n".5702"</table>\n";# class="blame"5703print"</div>\n";# class="blame_body"5704close$fd5705or print"Reading blob failed\n";57065707 git_footer_html();5708}57095710sub git_blame {5711 git_blame_common();5712}57135714sub git_blame_incremental {5715 git_blame_common('incremental');5716}57175718sub git_blame_data {5719 git_blame_common('data');5720}57215722sub git_tags {5723my$head= git_get_head_hash($project);5724 git_header_html();5725 git_print_page_nav('','',$head,undef,$head,format_ref_views('tags'));5726 git_print_header_div('summary',$project);57275728my@tagslist= git_get_tags_list();5729if(@tagslist) {5730 git_tags_body(\@tagslist);5731}5732 git_footer_html();5733}57345735sub git_heads {5736my$head= git_get_head_hash($project);5737 git_header_html();5738 git_print_page_nav('','',$head,undef,$head,format_ref_views('heads'));5739 git_print_header_div('summary',$project);57405741my@headslist= git_get_heads_list();5742if(@headslist) {5743 git_heads_body(\@headslist,$head);5744}5745 git_footer_html();5746}57475748# used both for single remote view and for list of all the remotes5749sub git_remotes {5750 gitweb_check_feature('remote_heads')5751or die_error(403,"Remote heads view is disabled");57525753my$head= git_get_head_hash($project);5754my$remote=$input_params{'hash'};57555756my$remotedata= git_get_remotes_list($remote);5757 die_error(500,"Unable to get remote information")unlessdefined$remotedata;57585759unless(%$remotedata) {5760 die_error(404,defined$remote?5761"Remote$remotenot found":5762"No remotes found");5763}57645765 git_header_html(undef,undef, -action_extra =>$remote);5766 git_print_page_nav('','',$head,undef,$head,5767 format_ref_views($remote?'':'remotes'));57685769 fill_remote_heads($remotedata);5770if(defined$remote) {5771 git_print_header_div('remotes',"$remoteremote for$project");5772 git_remote_block($remote,$remotedata->{$remote},undef,$head);5773}else{5774 git_print_header_div('summary',"$projectremotes");5775 git_remotes_body($remotedata,undef,$head);5776}57775778 git_footer_html();5779}57805781sub git_blob_plain {5782my$type=shift;5783my$expires;57845785if(!defined$hash) {5786if(defined$file_name) {5787my$base=$hash_base|| git_get_head_hash($project);5788$hash= git_get_hash_by_path($base,$file_name,"blob")5789or die_error(404,"Cannot find file");5790}else{5791 die_error(400,"No file name defined");5792}5793}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5794# blobs defined by non-textual hash id's can be cached5795$expires="+1d";5796}57975798open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5799or die_error(500,"Open git-cat-file blob '$hash' failed");58005801# content-type (can include charset)5802$type= blob_contenttype($fd,$file_name,$type);58035804# "save as" filename, even when no $file_name is given5805my$save_as="$hash";5806if(defined$file_name) {5807$save_as=$file_name;5808}elsif($type=~m/^text\//) {5809$save_as.='.txt';5810}58115812# With XSS prevention on, blobs of all types except a few known safe5813# ones are served with "Content-Disposition: attachment" to make sure5814# they don't run in our security domain. For certain image types,5815# blob view writes an <img> tag referring to blob_plain view, and we5816# want to be sure not to break that by serving the image as an5817# attachment (though Firefox 3 doesn't seem to care).5818my$sandbox=$prevent_xss&&5819$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;58205821print$cgi->header(5822-type =>$type,5823-expires =>$expires,5824-content_disposition =>5825($sandbox?'attachment':'inline')5826.'; filename="'.$save_as.'"');5827local$/=undef;5828binmode STDOUT,':raw';5829print<$fd>;5830binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5831close$fd;5832}58335834sub git_blob {5835my$expires;58365837if(!defined$hash) {5838if(defined$file_name) {5839my$base=$hash_base|| git_get_head_hash($project);5840$hash= git_get_hash_by_path($base,$file_name,"blob")5841or die_error(404,"Cannot find file");5842}else{5843 die_error(400,"No file name defined");5844}5845}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5846# blobs defined by non-textual hash id's can be cached5847$expires="+1d";5848}58495850my$have_blame= gitweb_check_feature('blame');5851open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5852or die_error(500,"Couldn't cat$file_name,$hash");5853my$mimetype= blob_mimetype($fd,$file_name);5854# use 'blob_plain' (aka 'raw') view for files that cannot be displayed5855if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {5856close$fd;5857return git_blob_plain($mimetype);5858}5859# we can have blame only for text/* mimetype5860$have_blame&&= ($mimetype=~m!^text/!);58615862my$highlight= gitweb_check_feature('highlight');5863my$syntax= guess_file_syntax($highlight,$mimetype,$file_name);5864$fd= run_highlighter($fd,$highlight,$syntax)5865if$syntax;58665867 git_header_html(undef,$expires);5868my$formats_nav='';5869if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5870if(defined$file_name) {5871if($have_blame) {5872$formats_nav.=5873$cgi->a({-href => href(action=>"blame", -replay=>1)},5874"blame") .5875" | ";5876}5877$formats_nav.=5878$cgi->a({-href => href(action=>"history", -replay=>1)},5879"history") .5880" | ".5881$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5882"raw") .5883" | ".5884$cgi->a({-href => href(action=>"blob",5885 hash_base=>"HEAD", file_name=>$file_name)},5886"HEAD");5887}else{5888$formats_nav.=5889$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5890"raw");5891}5892 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5893 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5894}else{5895print"<div class=\"page_nav\">\n".5896"<br/><br/></div>\n".5897"<div class=\"title\">$hash</div>\n";5898}5899 git_print_page_path($file_name,"blob",$hash_base);5900print"<div class=\"page_body\">\n";5901if($mimetype=~m!^image/!) {5902print qq!<img type="$mimetype"!;5903if($file_name) {5904print qq! alt="$file_name" title="$file_name"!;5905}5906print qq! src="! .5907 href(action=>"blob_plain", hash=>$hash,5908 hash_base=>$hash_base, file_name=>$file_name) .5909 qq!"/>\n!;5910}else{5911my$nr;5912while(my$line= <$fd>) {5913chomp$line;5914$nr++;5915$line= untabify($line);5916printf qq!<div class="pre"><a id="l%i" href="%s#l%i"class="linenr">%4i</a> %s</div>\n!,5917$nr, href(-replay =>1),$nr,$nr,$syntax?$line: esc_html($line, -nbsp=>1);5918}5919}5920close$fd5921or print"Reading blob failed.\n";5922print"</div>";5923 git_footer_html();5924}59255926sub git_tree {5927if(!defined$hash_base) {5928$hash_base="HEAD";5929}5930if(!defined$hash) {5931if(defined$file_name) {5932$hash= git_get_hash_by_path($hash_base,$file_name,"tree");5933}else{5934$hash=$hash_base;5935}5936}5937 die_error(404,"No such tree")unlessdefined($hash);59385939my$show_sizes= gitweb_check_feature('show-sizes');5940my$have_blame= gitweb_check_feature('blame');59415942my@entries= ();5943{5944local$/="\0";5945open my$fd,"-|", git_cmd(),"ls-tree",'-z',5946($show_sizes?'-l': ()),@extra_options,$hash5947or die_error(500,"Open git-ls-tree failed");5948@entries=map{chomp;$_} <$fd>;5949close$fd5950or die_error(404,"Reading tree failed");5951}59525953my$refs= git_get_references();5954my$ref= format_ref_marker($refs,$hash_base);5955 git_header_html();5956my$basedir='';5957if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5958my@views_nav= ();5959if(defined$file_name) {5960push@views_nav,5961$cgi->a({-href => href(action=>"history", -replay=>1)},5962"history"),5963$cgi->a({-href => href(action=>"tree",5964 hash_base=>"HEAD", file_name=>$file_name)},5965"HEAD"),5966}5967my$snapshot_links= format_snapshot_links($hash);5968if(defined$snapshot_links) {5969# FIXME: Should be available when we have no hash base as well.5970push@views_nav,$snapshot_links;5971}5972 git_print_page_nav('tree','',$hash_base,undef,undef,5973join(' | ',@views_nav));5974 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);5975}else{5976undef$hash_base;5977print"<div class=\"page_nav\">\n";5978print"<br/><br/></div>\n";5979print"<div class=\"title\">$hash</div>\n";5980}5981if(defined$file_name) {5982$basedir=$file_name;5983if($basedirne''&&substr($basedir, -1)ne'/') {5984$basedir.='/';5985}5986 git_print_page_path($file_name,'tree',$hash_base);5987}5988print"<div class=\"page_body\">\n";5989print"<table class=\"tree\">\n";5990my$alternate=1;5991# '..' (top directory) link if possible5992if(defined$hash_base&&5993defined$file_name&&$file_name=~m![^/]+$!) {5994if($alternate) {5995print"<tr class=\"dark\">\n";5996}else{5997print"<tr class=\"light\">\n";5998}5999$alternate^=1;60006001my$up=$file_name;6002$up=~s!/?[^/]+$!!;6003undef$upunless$up;6004# based on git_print_tree_entry6005print'<td class="mode">'. mode_str('040000') ."</td>\n";6006print'<td class="size"> </td>'."\n"if$show_sizes;6007print'<td class="list">';6008print$cgi->a({-href => href(action=>"tree",6009 hash_base=>$hash_base,6010 file_name=>$up)},6011"..");6012print"</td>\n";6013print"<td class=\"link\"></td>\n";60146015print"</tr>\n";6016}6017foreachmy$line(@entries) {6018my%t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);60196020if($alternate) {6021print"<tr class=\"dark\">\n";6022}else{6023print"<tr class=\"light\">\n";6024}6025$alternate^=1;60266027 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);60286029print"</tr>\n";6030}6031print"</table>\n".6032"</div>";6033 git_footer_html();6034}60356036sub snapshot_name {6037my($project,$hash) =@_;60386039# path/to/project.git -> project6040# path/to/project/.git -> project6041my$name= to_utf8($project);6042$name=~ s,([^/])/*\.git$,$1,;6043$name= basename($name);6044# sanitize name6045$name=~s/[[:cntrl:]]/?/g;60466047my$ver=$hash;6048if($hash=~/^[0-9a-fA-F]+$/) {6049# shorten SHA-1 hash6050my$full_hash= git_get_full_hash($project,$hash);6051if($full_hash=~/^$hash/&&length($hash) >7) {6052$ver= git_get_short_hash($project,$hash);6053}6054}elsif($hash=~m!^refs/tags/(.*)$!) {6055# tags don't need shortened SHA-1 hash6056$ver=$1;6057}else{6058# branches and other need shortened SHA-1 hash6059if($hash=~m!^refs/(?:heads|remotes)/(.*)$!) {6060$ver=$1;6061}6062$ver.='-'. git_get_short_hash($project,$hash);6063}6064# in case of hierarchical branch names6065$ver=~s!/!.!g;60666067# name = project-version_string6068$name="$name-$ver";60696070returnwantarray? ($name,$name) :$name;6071}60726073sub git_snapshot {6074my$format=$input_params{'snapshot_format'};6075if(!@snapshot_fmts) {6076 die_error(403,"Snapshots not allowed");6077}6078# default to first supported snapshot format6079$format||=$snapshot_fmts[0];6080if($format!~m/^[a-z0-9]+$/) {6081 die_error(400,"Invalid snapshot format parameter");6082}elsif(!exists($known_snapshot_formats{$format})) {6083 die_error(400,"Unknown snapshot format");6084}elsif($known_snapshot_formats{$format}{'disabled'}) {6085 die_error(403,"Snapshot format not allowed");6086}elsif(!grep($_eq$format,@snapshot_fmts)) {6087 die_error(403,"Unsupported snapshot format");6088}60896090my$type= git_get_type("$hash^{}");6091if(!$type) {6092 die_error(404,'Object does not exist');6093}elsif($typeeq'blob') {6094 die_error(400,'Object is not a tree-ish');6095}60966097my($name,$prefix) = snapshot_name($project,$hash);6098my$filename="$name$known_snapshot_formats{$format}{'suffix'}";6099my$cmd= quote_command(6100 git_cmd(),'archive',6101"--format=$known_snapshot_formats{$format}{'format'}",6102"--prefix=$prefix/",$hash);6103if(exists$known_snapshot_formats{$format}{'compressor'}) {6104$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});6105}61066107$filename=~s/(["\\])/\\$1/g;6108print$cgi->header(6109-type =>$known_snapshot_formats{$format}{'type'},6110-content_disposition =>'inline; filename="'.$filename.'"',6111-status =>'200 OK');61126113open my$fd,"-|",$cmd6114or die_error(500,"Execute git-archive failed");6115binmode STDOUT,':raw';6116print<$fd>;6117binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi6118close$fd;6119}61206121sub git_log_generic {6122my($fmt_name,$body_subr,$base,$parent,$file_name,$file_hash) =@_;61236124my$head= git_get_head_hash($project);6125if(!defined$base) {6126$base=$head;6127}6128if(!defined$page) {6129$page=0;6130}6131my$refs= git_get_references();61326133my$commit_hash=$base;6134if(defined$parent) {6135$commit_hash="$parent..$base";6136}6137my@commitlist=6138 parse_commits($commit_hash,101, (100*$page),6139defined$file_name? ($file_name,"--full-history") : ());61406141my$ftype;6142if(!defined$file_hash&&defined$file_name) {6143# some commits could have deleted file in question,6144# and not have it in tree, but one of them has to have it6145for(my$i=0;$i<@commitlist;$i++) {6146$file_hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);6147last ifdefined$file_hash;6148}6149}6150if(defined$file_hash) {6151$ftype= git_get_type($file_hash);6152}6153if(defined$file_name&& !defined$ftype) {6154 die_error(500,"Unknown type of object");6155}6156my%co;6157if(defined$file_name) {6158%co= parse_commit($base)6159or die_error(404,"Unknown commit object");6160}616161626163my$paging_nav= format_paging_nav($fmt_name,$page,$#commitlist>=100);6164my$next_link='';6165if($#commitlist>=100) {6166$next_link=6167$cgi->a({-href => href(-replay=>1, page=>$page+1),6168-accesskey =>"n", -title =>"Alt-n"},"next");6169}6170my$patch_max= gitweb_get_feature('patches');6171if($patch_max&& !defined$file_name) {6172if($patch_max<0||@commitlist<=$patch_max) {6173$paging_nav.=" ⋅ ".6174$cgi->a({-href => href(action=>"patches", -replay=>1)},6175"patches");6176}6177}61786179 git_header_html();6180 git_print_page_nav($fmt_name,'',$hash,$hash,$hash,$paging_nav);6181if(defined$file_name) {6182 git_print_header_div('commit', esc_html($co{'title'}),$base);6183}else{6184 git_print_header_div('summary',$project)6185}6186 git_print_page_path($file_name,$ftype,$hash_base)6187if(defined$file_name);61886189$body_subr->(\@commitlist,0,99,$refs,$next_link,6190$file_name,$file_hash,$ftype);61916192 git_footer_html();6193}61946195sub git_log {6196 git_log_generic('log', \&git_log_body,6197$hash,$hash_parent);6198}61996200sub git_commit {6201$hash||=$hash_base||"HEAD";6202my%co= parse_commit($hash)6203or die_error(404,"Unknown commit object");62046205my$parent=$co{'parent'};6206my$parents=$co{'parents'};# listref62076208# we need to prepare $formats_nav before any parameter munging6209my$formats_nav;6210if(!defined$parent) {6211# --root commitdiff6212$formats_nav.='(initial)';6213}elsif(@$parents==1) {6214# single parent commit6215$formats_nav.=6216'(parent: '.6217$cgi->a({-href => href(action=>"commit",6218 hash=>$parent)},6219 esc_html(substr($parent,0,7))) .6220')';6221}else{6222# merge commit6223$formats_nav.=6224'(merge: '.6225join(' ',map{6226$cgi->a({-href => href(action=>"commit",6227 hash=>$_)},6228 esc_html(substr($_,0,7)));6229}@$parents) .6230')';6231}6232if(gitweb_check_feature('patches') &&@$parents<=1) {6233$formats_nav.=" | ".6234$cgi->a({-href => href(action=>"patch", -replay=>1)},6235"patch");6236}62376238if(!defined$parent) {6239$parent="--root";6240}6241my@difftree;6242open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",6243@diff_opts,6244(@$parents<=1?$parent:'-c'),6245$hash,"--"6246or die_error(500,"Open git-diff-tree failed");6247@difftree=map{chomp;$_} <$fd>;6248close$fdor die_error(404,"Reading git-diff-tree failed");62496250# non-textual hash id's can be cached6251my$expires;6252if($hash=~m/^[0-9a-fA-F]{40}$/) {6253$expires="+1d";6254}6255my$refs= git_get_references();6256my$ref= format_ref_marker($refs,$co{'id'});62576258 git_header_html(undef,$expires);6259 git_print_page_nav('commit','',6260$hash,$co{'tree'},$hash,6261$formats_nav);62626263if(defined$co{'parent'}) {6264 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);6265}else{6266 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);6267}6268print"<div class=\"title_text\">\n".6269"<table class=\"object_header\">\n";6270 git_print_authorship_rows(\%co);6271print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";6272print"<tr>".6273"<td>tree</td>".6274"<td class=\"sha1\">".6275$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),6276class=>"list"},$co{'tree'}) .6277"</td>".6278"<td class=\"link\">".6279$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},6280"tree");6281my$snapshot_links= format_snapshot_links($hash);6282if(defined$snapshot_links) {6283print" | ".$snapshot_links;6284}6285print"</td>".6286"</tr>\n";62876288foreachmy$par(@$parents) {6289print"<tr>".6290"<td>parent</td>".6291"<td class=\"sha1\">".6292$cgi->a({-href => href(action=>"commit", hash=>$par),6293class=>"list"},$par) .6294"</td>".6295"<td class=\"link\">".6296$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .6297" | ".6298$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .6299"</td>".6300"</tr>\n";6301}6302print"</table>".6303"</div>\n";63046305print"<div class=\"page_body\">\n";6306 git_print_log($co{'comment'});6307print"</div>\n";63086309 git_difftree_body(\@difftree,$hash,@$parents);63106311 git_footer_html();6312}63136314sub git_object {6315# object is defined by:6316# - hash or hash_base alone6317# - hash_base and file_name6318my$type;63196320# - hash or hash_base alone6321if($hash|| ($hash_base&& !defined$file_name)) {6322my$object_id=$hash||$hash_base;63236324open my$fd,"-|", quote_command(6325 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'6326or die_error(404,"Object does not exist");6327$type= <$fd>;6328chomp$type;6329close$fd6330or die_error(404,"Object does not exist");63316332# - hash_base and file_name6333}elsif($hash_base&&defined$file_name) {6334$file_name=~ s,/+$,,;63356336system(git_cmd(),"cat-file",'-e',$hash_base) ==06337or die_error(404,"Base object does not exist");63386339# here errors should not hapen6340open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name6341or die_error(500,"Open git-ls-tree failed");6342my$line= <$fd>;6343close$fd;63446345#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'6346unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {6347 die_error(404,"File or directory for given base does not exist");6348}6349$type=$2;6350$hash=$3;6351}else{6352 die_error(400,"Not enough information to find object");6353}63546355print$cgi->redirect(-uri => href(action=>$type, -full=>1,6356 hash=>$hash, hash_base=>$hash_base,6357 file_name=>$file_name),6358-status =>'302 Found');6359}63606361sub git_blobdiff {6362my$format=shift||'html';63636364my$fd;6365my@difftree;6366my%diffinfo;6367my$expires;63686369# preparing $fd and %diffinfo for git_patchset_body6370# new style URI6371if(defined$hash_base&&defined$hash_parent_base) {6372if(defined$file_name) {6373# read raw output6374open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6375$hash_parent_base,$hash_base,6376"--", (defined$file_parent?$file_parent: ()),$file_name6377or die_error(500,"Open git-diff-tree failed");6378@difftree=map{chomp;$_} <$fd>;6379close$fd6380or die_error(404,"Reading git-diff-tree failed");6381@difftree6382or die_error(404,"Blob diff not found");63836384}elsif(defined$hash&&6385$hash=~/[0-9a-fA-F]{40}/) {6386# try to find filename from $hash63876388# read filtered raw output6389open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6390$hash_parent_base,$hash_base,"--"6391or die_error(500,"Open git-diff-tree failed");6392@difftree=6393# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'6394# $hash == to_id6395grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}6396map{chomp;$_} <$fd>;6397close$fd6398or die_error(404,"Reading git-diff-tree failed");6399@difftree6400or die_error(404,"Blob diff not found");64016402}else{6403 die_error(400,"Missing one of the blob diff parameters");6404}64056406if(@difftree>1) {6407 die_error(400,"Ambiguous blob diff specification");6408}64096410%diffinfo= parse_difftree_raw_line($difftree[0]);6411$file_parent||=$diffinfo{'from_file'} ||$file_name;6412$file_name||=$diffinfo{'to_file'};64136414$hash_parent||=$diffinfo{'from_id'};6415$hash||=$diffinfo{'to_id'};64166417# non-textual hash id's can be cached6418if($hash_base=~m/^[0-9a-fA-F]{40}$/&&6419$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {6420$expires='+1d';6421}64226423# open patch output6424open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6425'-p', ($formateq'html'?"--full-index": ()),6426$hash_parent_base,$hash_base,6427"--", (defined$file_parent?$file_parent: ()),$file_name6428or die_error(500,"Open git-diff-tree failed");6429}64306431# old/legacy style URI -- not generated anymore since 1.4.3.6432if(!%diffinfo) {6433 die_error('404 Not Found',"Missing one of the blob diff parameters")6434}64356436# header6437if($formateq'html') {6438my$formats_nav=6439$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},6440"raw");6441 git_header_html(undef,$expires);6442if(defined$hash_base&& (my%co= parse_commit($hash_base))) {6443 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);6444 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);6445}else{6446print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";6447print"<div class=\"title\">$hashvs$hash_parent</div>\n";6448}6449if(defined$file_name) {6450 git_print_page_path($file_name,"blob",$hash_base);6451}else{6452print"<div class=\"page_path\"></div>\n";6453}64546455}elsif($formateq'plain') {6456print$cgi->header(6457-type =>'text/plain',6458-charset =>'utf-8',6459-expires =>$expires,6460-content_disposition =>'inline; filename="'."$file_name".'.patch"');64616462print"X-Git-Url: ".$cgi->self_url() ."\n\n";64636464}else{6465 die_error(400,"Unknown blobdiff format");6466}64676468# patch6469if($formateq'html') {6470print"<div class=\"page_body\">\n";64716472 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);6473close$fd;64746475print"</div>\n";# class="page_body"6476 git_footer_html();64776478}else{6479while(my$line= <$fd>) {6480$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;6481$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;64826483print$line;64846485last if$line=~m!^\+\+\+!;6486}6487local$/=undef;6488print<$fd>;6489close$fd;6490}6491}64926493sub git_blobdiff_plain {6494 git_blobdiff('plain');6495}64966497sub git_commitdiff {6498my%params=@_;6499my$format=$params{-format} ||'html';65006501my($patch_max) = gitweb_get_feature('patches');6502if($formateq'patch') {6503 die_error(403,"Patch view not allowed")unless$patch_max;6504}65056506$hash||=$hash_base||"HEAD";6507my%co= parse_commit($hash)6508or die_error(404,"Unknown commit object");65096510# choose format for commitdiff for merge6511if(!defined$hash_parent&& @{$co{'parents'}} >1) {6512$hash_parent='--cc';6513}6514# we need to prepare $formats_nav before almost any parameter munging6515my$formats_nav;6516if($formateq'html') {6517$formats_nav=6518$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},6519"raw");6520if($patch_max&& @{$co{'parents'}} <=1) {6521$formats_nav.=" | ".6522$cgi->a({-href => href(action=>"patch", -replay=>1)},6523"patch");6524}65256526if(defined$hash_parent&&6527$hash_parentne'-c'&&$hash_parentne'--cc') {6528# commitdiff with two commits given6529my$hash_parent_short=$hash_parent;6530if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {6531$hash_parent_short=substr($hash_parent,0,7);6532}6533$formats_nav.=6534' (from';6535for(my$i=0;$i< @{$co{'parents'}};$i++) {6536if($co{'parents'}[$i]eq$hash_parent) {6537$formats_nav.=' parent '. ($i+1);6538last;6539}6540}6541$formats_nav.=': '.6542$cgi->a({-href => href(action=>"commitdiff",6543 hash=>$hash_parent)},6544 esc_html($hash_parent_short)) .6545')';6546}elsif(!$co{'parent'}) {6547# --root commitdiff6548$formats_nav.=' (initial)';6549}elsif(scalar@{$co{'parents'}} ==1) {6550# single parent commit6551$formats_nav.=6552' (parent: '.6553$cgi->a({-href => href(action=>"commitdiff",6554 hash=>$co{'parent'})},6555 esc_html(substr($co{'parent'},0,7))) .6556')';6557}else{6558# merge commit6559if($hash_parenteq'--cc') {6560$formats_nav.=' | '.6561$cgi->a({-href => href(action=>"commitdiff",6562 hash=>$hash, hash_parent=>'-c')},6563'combined');6564}else{# $hash_parent eq '-c'6565$formats_nav.=' | '.6566$cgi->a({-href => href(action=>"commitdiff",6567 hash=>$hash, hash_parent=>'--cc')},6568'compact');6569}6570$formats_nav.=6571' (merge: '.6572join(' ',map{6573$cgi->a({-href => href(action=>"commitdiff",6574 hash=>$_)},6575 esc_html(substr($_,0,7)));6576} @{$co{'parents'}} ) .6577')';6578}6579}65806581my$hash_parent_param=$hash_parent;6582if(!defined$hash_parent_param) {6583# --cc for multiple parents, --root for parentless6584$hash_parent_param=6585@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';6586}65876588# read commitdiff6589my$fd;6590my@difftree;6591if($formateq'html') {6592open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6593"--no-commit-id","--patch-with-raw","--full-index",6594$hash_parent_param,$hash,"--"6595or die_error(500,"Open git-diff-tree failed");65966597while(my$line= <$fd>) {6598chomp$line;6599# empty line ends raw part of diff-tree output6600last unless$line;6601push@difftree,scalar parse_difftree_raw_line($line);6602}66036604}elsif($formateq'plain') {6605open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6606'-p',$hash_parent_param,$hash,"--"6607or die_error(500,"Open git-diff-tree failed");6608}elsif($formateq'patch') {6609# For commit ranges, we limit the output to the number of6610# patches specified in the 'patches' feature.6611# For single commits, we limit the output to a single patch,6612# diverging from the git-format-patch default.6613my@commit_spec= ();6614if($hash_parent) {6615if($patch_max>0) {6616push@commit_spec,"-$patch_max";6617}6618push@commit_spec,'-n',"$hash_parent..$hash";6619}else{6620if($params{-single}) {6621push@commit_spec,'-1';6622}else{6623if($patch_max>0) {6624push@commit_spec,"-$patch_max";6625}6626push@commit_spec,"-n";6627}6628push@commit_spec,'--root',$hash;6629}6630open$fd,"-|", git_cmd(),"format-patch",@diff_opts,6631'--encoding=utf8','--stdout',@commit_spec6632or die_error(500,"Open git-format-patch failed");6633}else{6634 die_error(400,"Unknown commitdiff format");6635}66366637# non-textual hash id's can be cached6638my$expires;6639if($hash=~m/^[0-9a-fA-F]{40}$/) {6640$expires="+1d";6641}66426643# write commit message6644if($formateq'html') {6645my$refs= git_get_references();6646my$ref= format_ref_marker($refs,$co{'id'});66476648 git_header_html(undef,$expires);6649 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);6650 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);6651print"<div class=\"title_text\">\n".6652"<table class=\"object_header\">\n";6653 git_print_authorship_rows(\%co);6654print"</table>".6655"</div>\n";6656print"<div class=\"page_body\">\n";6657if(@{$co{'comment'}} >1) {6658print"<div class=\"log\">\n";6659 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);6660print"</div>\n";# class="log"6661}66626663}elsif($formateq'plain') {6664my$refs= git_get_references("tags");6665my$tagname= git_get_rev_name_tags($hash);6666my$filename= basename($project) ."-$hash.patch";66676668print$cgi->header(6669-type =>'text/plain',6670-charset =>'utf-8',6671-expires =>$expires,6672-content_disposition =>'inline; filename="'."$filename".'"');6673my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});6674print"From: ". to_utf8($co{'author'}) ."\n";6675print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";6676print"Subject: ". to_utf8($co{'title'}) ."\n";66776678print"X-Git-Tag:$tagname\n"if$tagname;6679print"X-Git-Url: ".$cgi->self_url() ."\n\n";66806681foreachmy$line(@{$co{'comment'}}) {6682print to_utf8($line) ."\n";6683}6684print"---\n\n";6685}elsif($formateq'patch') {6686my$filename= basename($project) ."-$hash.patch";66876688print$cgi->header(6689-type =>'text/plain',6690-charset =>'utf-8',6691-expires =>$expires,6692-content_disposition =>'inline; filename="'."$filename".'"');6693}66946695# write patch6696if($formateq'html') {6697my$use_parents= !defined$hash_parent||6698$hash_parenteq'-c'||$hash_parenteq'--cc';6699 git_difftree_body(\@difftree,$hash,6700$use_parents? @{$co{'parents'}} :$hash_parent);6701print"<br/>\n";67026703 git_patchset_body($fd, \@difftree,$hash,6704$use_parents? @{$co{'parents'}} :$hash_parent);6705close$fd;6706print"</div>\n";# class="page_body"6707 git_footer_html();67086709}elsif($formateq'plain') {6710local$/=undef;6711print<$fd>;6712close$fd6713or print"Reading git-diff-tree failed\n";6714}elsif($formateq'patch') {6715local$/=undef;6716print<$fd>;6717close$fd6718or print"Reading git-format-patch failed\n";6719}6720}67216722sub git_commitdiff_plain {6723 git_commitdiff(-format =>'plain');6724}67256726# format-patch-style patches6727sub git_patch {6728 git_commitdiff(-format =>'patch', -single =>1);6729}67306731sub git_patches {6732 git_commitdiff(-format =>'patch');6733}67346735sub git_history {6736 git_log_generic('history', \&git_history_body,6737$hash_base,$hash_parent_base,6738$file_name,$hash);6739}67406741sub git_search {6742 gitweb_check_feature('search')or die_error(403,"Search is disabled");6743if(!defined$searchtext) {6744 die_error(400,"Text field is empty");6745}6746if(!defined$hash) {6747$hash= git_get_head_hash($project);6748}6749my%co= parse_commit($hash);6750if(!%co) {6751 die_error(404,"Unknown commit object");6752}6753if(!defined$page) {6754$page=0;6755}67566757$searchtype||='commit';6758if($searchtypeeq'pickaxe') {6759# pickaxe may take all resources of your box and run for several minutes6760# with every query - so decide by yourself how public you make this feature6761 gitweb_check_feature('pickaxe')6762or die_error(403,"Pickaxe is disabled");6763}6764if($searchtypeeq'grep') {6765 gitweb_check_feature('grep')6766or die_error(403,"Grep is disabled");6767}67686769 git_header_html();67706771if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {6772my$greptype;6773if($searchtypeeq'commit') {6774$greptype="--grep=";6775}elsif($searchtypeeq'author') {6776$greptype="--author=";6777}elsif($searchtypeeq'committer') {6778$greptype="--committer=";6779}6780$greptype.=$searchtext;6781my@commitlist= parse_commits($hash,101, (100*$page),undef,6782$greptype,'--regexp-ignore-case',6783$search_use_regexp?'--extended-regexp':'--fixed-strings');67846785my$paging_nav='';6786if($page>0) {6787$paging_nav.=6788$cgi->a({-href => href(action=>"search", hash=>$hash,6789 searchtext=>$searchtext,6790 searchtype=>$searchtype)},6791"first");6792$paging_nav.=" ⋅ ".6793$cgi->a({-href => href(-replay=>1, page=>$page-1),6794-accesskey =>"p", -title =>"Alt-p"},"prev");6795}else{6796$paging_nav.="first";6797$paging_nav.=" ⋅ prev";6798}6799my$next_link='';6800if($#commitlist>=100) {6801$next_link=6802$cgi->a({-href => href(-replay=>1, page=>$page+1),6803-accesskey =>"n", -title =>"Alt-n"},"next");6804$paging_nav.=" ⋅$next_link";6805}else{6806$paging_nav.=" ⋅ next";6807}68086809 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);6810 git_print_header_div('commit', esc_html($co{'title'}),$hash);6811if($page==0&& !@commitlist) {6812print"<p>No match.</p>\n";6813}else{6814 git_search_grep_body(\@commitlist,0,99,$next_link);6815}6816}68176818if($searchtypeeq'pickaxe') {6819 git_print_page_nav('','',$hash,$co{'tree'},$hash);6820 git_print_header_div('commit', esc_html($co{'title'}),$hash);68216822print"<table class=\"pickaxe search\">\n";6823my$alternate=1;6824local$/="\n";6825open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,6826'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",6827($search_use_regexp?'--pickaxe-regex': ());6828undef%co;6829my@files;6830while(my$line= <$fd>) {6831chomp$line;6832next unless$line;68336834my%set= parse_difftree_raw_line($line);6835if(defined$set{'commit'}) {6836# finish previous commit6837if(%co) {6838print"</td>\n".6839"<td class=\"link\">".6840$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6841" | ".6842$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6843print"</td>\n".6844"</tr>\n";6845}68466847if($alternate) {6848print"<tr class=\"dark\">\n";6849}else{6850print"<tr class=\"light\">\n";6851}6852$alternate^=1;6853%co= parse_commit($set{'commit'});6854my$author= chop_and_escape_str($co{'author_name'},15,5);6855print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6856"<td><i>$author</i></td>\n".6857"<td>".6858$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6859-class=>"list subject"},6860 chop_and_escape_str($co{'title'},50) ."<br/>");6861}elsif(defined$set{'to_id'}) {6862next if($set{'to_id'} =~m/^0{40}$/);68636864print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6865 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6866-class=>"list"},6867"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6868"<br/>\n";6869}6870}6871close$fd;68726873# finish last commit (warning: repetition!)6874if(%co) {6875print"</td>\n".6876"<td class=\"link\">".6877$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6878" | ".6879$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6880print"</td>\n".6881"</tr>\n";6882}68836884print"</table>\n";6885}68866887if($searchtypeeq'grep') {6888 git_print_page_nav('','',$hash,$co{'tree'},$hash);6889 git_print_header_div('commit', esc_html($co{'title'}),$hash);68906891print"<table class=\"grep_search\">\n";6892my$alternate=1;6893my$matches=0;6894local$/="\n";6895open my$fd,"-|", git_cmd(),'grep','-n',6896$search_use_regexp? ('-E','-i') :'-F',6897$searchtext,$co{'tree'};6898my$lastfile='';6899while(my$line= <$fd>) {6900chomp$line;6901my($file,$lno,$ltext,$binary);6902last if($matches++>1000);6903if($line=~/^Binary file (.+) matches$/) {6904$file=$1;6905$binary=1;6906}else{6907(undef,$file,$lno,$ltext) =split(/:/,$line,4);6908}6909if($filene$lastfile) {6910$lastfileand print"</td></tr>\n";6911if($alternate++) {6912print"<tr class=\"dark\">\n";6913}else{6914print"<tr class=\"light\">\n";6915}6916print"<td class=\"list\">".6917$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6918 file_name=>"$file"),6919-class=>"list"}, esc_path($file));6920print"</td><td>\n";6921$lastfile=$file;6922}6923if($binary) {6924print"<div class=\"binary\">Binary file</div>\n";6925}else{6926$ltext= untabify($ltext);6927if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6928$ltext= esc_html($1, -nbsp=>1);6929$ltext.='<span class="match">';6930$ltext.= esc_html($2, -nbsp=>1);6931$ltext.='</span>';6932$ltext.= esc_html($3, -nbsp=>1);6933}else{6934$ltext= esc_html($ltext, -nbsp=>1);6935}6936print"<div class=\"pre\">".6937$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6938 file_name=>"$file").'#l'.$lno,6939-class=>"linenr"},sprintf('%4i',$lno))6940.' '.$ltext."</div>\n";6941}6942}6943if($lastfile) {6944print"</td></tr>\n";6945if($matches>1000) {6946print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6947}6948}else{6949print"<div class=\"diff nodifferences\">No matches found</div>\n";6950}6951close$fd;69526953print"</table>\n";6954}6955 git_footer_html();6956}69576958sub git_search_help {6959 git_header_html();6960 git_print_page_nav('','',$hash,$hash,$hash);6961print<<EOT;6962<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without6963regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,6964the pattern entered is recognized as the POSIX extended6965<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case6966insensitive).</p>6967<dl>6968<dt><b>commit</b></dt>6969<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>6970EOT6971my$have_grep= gitweb_check_feature('grep');6972if($have_grep) {6973print<<EOT;6974<dt><b>grep</b></dt>6975<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing6976 a different one) are searched for the given pattern. On large trees, this search can take6977a while and put some strain on the server, so please use it with some consideration. Note that6978due to git-grep peculiarity, currently if regexp mode is turned off, the matches are6979case-sensitive.</dd>6980EOT6981}6982print<<EOT;6983<dt><b>author</b></dt>6984<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>6985<dt><b>committer</b></dt>6986<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>6987EOT6988my$have_pickaxe= gitweb_check_feature('pickaxe');6989if($have_pickaxe) {6990print<<EOT;6991<dt><b>pickaxe</b></dt>6992<dd>All commits that caused the string to appear or disappear from any file (changes that6993added, removed or "modified" the string) will be listed. This search can take a while and6994takes a lot of strain on the server, so please use it wisely. Note that since you may be6995interested even in changes just changing the case as well, this search is case sensitive.</dd>6996EOT6997}6998print"</dl>\n";6999 git_footer_html();7000}70017002sub git_shortlog {7003 git_log_generic('shortlog', \&git_shortlog_body,7004$hash,$hash_parent);7005}70067007## ......................................................................7008## feeds (RSS, Atom; OPML)70097010sub git_feed {7011my$format=shift||'atom';7012my$have_blame= gitweb_check_feature('blame');70137014# Atom: http://www.atomenabled.org/developers/syndication/7015# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ7016if($formatne'rss'&&$formatne'atom') {7017 die_error(400,"Unknown web feed format");7018}70197020# log/feed of current (HEAD) branch, log of given branch, history of file/directory7021my$head=$hash||'HEAD';7022my@commitlist= parse_commits($head,150,0,$file_name);70237024my%latest_commit;7025my%latest_date;7026my$content_type="application/$format+xml";7027if(defined$cgi->http('HTTP_ACCEPT') &&7028$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {7029# browser (feed reader) prefers text/xml7030$content_type='text/xml';7031}7032if(defined($commitlist[0])) {7033%latest_commit= %{$commitlist[0]};7034my$latest_epoch=$latest_commit{'committer_epoch'};7035%latest_date= parse_date($latest_epoch);7036my$if_modified=$cgi->http('IF_MODIFIED_SINCE');7037if(defined$if_modified) {7038my$since;7039if(eval{require HTTP::Date;1; }) {7040$since= HTTP::Date::str2time($if_modified);7041}elsif(eval{require Time::ParseDate;1; }) {7042$since= Time::ParseDate::parsedate($if_modified, GMT =>1);7043}7044if(defined$since&&$latest_epoch<=$since) {7045print$cgi->header(7046-type =>$content_type,7047-charset =>'utf-8',7048-last_modified =>$latest_date{'rfc2822'},7049-status =>'304 Not Modified');7050return;7051}7052}7053print$cgi->header(7054-type =>$content_type,7055-charset =>'utf-8',7056-last_modified =>$latest_date{'rfc2822'});7057}else{7058print$cgi->header(7059-type =>$content_type,7060-charset =>'utf-8');7061}70627063# Optimization: skip generating the body if client asks only7064# for Last-Modified date.7065return if($cgi->request_method()eq'HEAD');70667067# header variables7068my$title="$site_name-$project/$action";7069my$feed_type='log';7070if(defined$hash) {7071$title.=" - '$hash'";7072$feed_type='branch log';7073if(defined$file_name) {7074$title.=" ::$file_name";7075$feed_type='history';7076}7077}elsif(defined$file_name) {7078$title.=" -$file_name";7079$feed_type='history';7080}7081$title.="$feed_type";7082my$descr= git_get_project_description($project);7083if(defined$descr) {7084$descr= esc_html($descr);7085}else{7086$descr="$project".7087($formateq'rss'?'RSS':'Atom') .7088" feed";7089}7090my$owner= git_get_project_owner($project);7091$owner= esc_html($owner);70927093#header7094my$alt_url;7095if(defined$file_name) {7096$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);7097}elsif(defined$hash) {7098$alt_url= href(-full=>1, action=>"log", hash=>$hash);7099}else{7100$alt_url= href(-full=>1, action=>"summary");7101}7102print qq!<?xml version="1.0" encoding="utf-8"?>\n!;7103if($formateq'rss') {7104print<<XML;7105<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">7106<channel>7107XML7108print"<title>$title</title>\n".7109"<link>$alt_url</link>\n".7110"<description>$descr</description>\n".7111"<language>en</language>\n".7112# project owner is responsible for 'editorial' content7113"<managingEditor>$owner</managingEditor>\n";7114if(defined$logo||defined$favicon) {7115# prefer the logo to the favicon, since RSS7116# doesn't allow both7117my$img= esc_url($logo||$favicon);7118print"<image>\n".7119"<url>$img</url>\n".7120"<title>$title</title>\n".7121"<link>$alt_url</link>\n".7122"</image>\n";7123}7124if(%latest_date) {7125print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";7126print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";7127}7128print"<generator>gitweb v.$version/$git_version</generator>\n";7129}elsif($formateq'atom') {7130print<<XML;7131<feed xmlns="http://www.w3.org/2005/Atom">7132XML7133print"<title>$title</title>\n".7134"<subtitle>$descr</subtitle>\n".7135'<link rel="alternate" type="text/html" href="'.7136$alt_url.'" />'."\n".7137'<link rel="self" type="'.$content_type.'" href="'.7138$cgi->self_url() .'" />'."\n".7139"<id>". href(-full=>1) ."</id>\n".7140# use project owner for feed author7141"<author><name>$owner</name></author>\n";7142if(defined$favicon) {7143print"<icon>". esc_url($favicon) ."</icon>\n";7144}7145if(defined$logo_url) {7146# not twice as wide as tall: 72 x 27 pixels7147print"<logo>". esc_url($logo) ."</logo>\n";7148}7149if(!%latest_date) {7150# dummy date to keep the feed valid until commits trickle in:7151print"<updated>1970-01-01T00:00:00Z</updated>\n";7152}else{7153print"<updated>$latest_date{'iso-8601'}</updated>\n";7154}7155print"<generator version='$version/$git_version'>gitweb</generator>\n";7156}71577158# contents7159for(my$i=0;$i<=$#commitlist;$i++) {7160my%co= %{$commitlist[$i]};7161my$commit=$co{'id'};7162# we read 150, we always show 30 and the ones more recent than 48 hours7163if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {7164last;7165}7166my%cd= parse_date($co{'author_epoch'});71677168# get list of changed files7169open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7170$co{'parent'} ||"--root",7171$co{'id'},"--", (defined$file_name?$file_name: ())7172ornext;7173my@difftree=map{chomp;$_} <$fd>;7174close$fd7175ornext;71767177# print element (entry, item)7178my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);7179if($formateq'rss') {7180print"<item>\n".7181"<title>". esc_html($co{'title'}) ."</title>\n".7182"<author>". esc_html($co{'author'}) ."</author>\n".7183"<pubDate>$cd{'rfc2822'}</pubDate>\n".7184"<guid isPermaLink=\"true\">$co_url</guid>\n".7185"<link>$co_url</link>\n".7186"<description>". esc_html($co{'title'}) ."</description>\n".7187"<content:encoded>".7188"<![CDATA[\n";7189}elsif($formateq'atom') {7190print"<entry>\n".7191"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".7192"<updated>$cd{'iso-8601'}</updated>\n".7193"<author>\n".7194" <name>". esc_html($co{'author_name'}) ."</name>\n";7195if($co{'author_email'}) {7196print" <email>". esc_html($co{'author_email'}) ."</email>\n";7197}7198print"</author>\n".7199# use committer for contributor7200"<contributor>\n".7201" <name>". esc_html($co{'committer_name'}) ."</name>\n";7202if($co{'committer_email'}) {7203print" <email>". esc_html($co{'committer_email'}) ."</email>\n";7204}7205print"</contributor>\n".7206"<published>$cd{'iso-8601'}</published>\n".7207"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".7208"<id>$co_url</id>\n".7209"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".7210"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";7211}7212my$comment=$co{'comment'};7213print"<pre>\n";7214foreachmy$line(@$comment) {7215$line= esc_html($line);7216print"$line\n";7217}7218print"</pre><ul>\n";7219foreachmy$difftree_line(@difftree) {7220my%difftree= parse_difftree_raw_line($difftree_line);7221next if!$difftree{'from_id'};72227223my$file=$difftree{'file'} ||$difftree{'to_file'};72247225print"<li>".7226"[".7227$cgi->a({-href => href(-full=>1, action=>"blobdiff",7228 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},7229 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},7230 file_name=>$file, file_parent=>$difftree{'from_file'}),7231-title =>"diff"},'D');7232if($have_blame) {7233print$cgi->a({-href => href(-full=>1, action=>"blame",7234 file_name=>$file, hash_base=>$commit),7235-title =>"blame"},'B');7236}7237# if this is not a feed of a file history7238if(!defined$file_name||$file_namene$file) {7239print$cgi->a({-href => href(-full=>1, action=>"history",7240 file_name=>$file, hash=>$commit),7241-title =>"history"},'H');7242}7243$file= esc_path($file);7244print"] ".7245"$file</li>\n";7246}7247if($formateq'rss') {7248print"</ul>]]>\n".7249"</content:encoded>\n".7250"</item>\n";7251}elsif($formateq'atom') {7252print"</ul>\n</div>\n".7253"</content>\n".7254"</entry>\n";7255}7256}72577258# end of feed7259if($formateq'rss') {7260print"</channel>\n</rss>\n";7261}elsif($formateq'atom') {7262print"</feed>\n";7263}7264}72657266sub git_rss {7267 git_feed('rss');7268}72697270sub git_atom {7271 git_feed('atom');7272}72737274sub git_opml {7275my@list= git_get_projects_list();72767277print$cgi->header(7278-type =>'text/xml',7279-charset =>'utf-8',7280-content_disposition =>'inline; filename="opml.xml"');72817282print<<XML;7283<?xml version="1.0" encoding="utf-8"?>7284<opml version="1.0">7285<head>7286 <title>$site_nameOPML Export</title>7287</head>7288<body>7289<outline text="git RSS feeds">7290XML72917292foreachmy$pr(@list) {7293my%proj=%$pr;7294my$head= git_get_head_hash($proj{'path'});7295if(!defined$head) {7296next;7297}7298$git_dir="$projectroot/$proj{'path'}";7299my%co= parse_commit($head);7300if(!%co) {7301next;7302}73037304my$path= esc_html(chop_str($proj{'path'},25,5));7305my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);7306my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);7307print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";7308}7309print<<XML;7310</outline>7311</body>7312</opml>7313XML7314}