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); 20binmode STDOUT,':utf8'; 21 22our$t0; 23if(eval{require Time::HiRes;1; }) { 24$t0= [Time::HiRes::gettimeofday()]; 25} 26our$number_of_git_cmds=0; 27 28BEGIN{ 29 CGI->compile()if$ENV{'MOD_PERL'}; 30} 31 32our$version="++GIT_VERSION++"; 33 34our($my_url,$my_uri,$base_url,$path_info,$home_link); 35sub evaluate_uri { 36our$cgi; 37 38our$my_url=$cgi->url(); 39our$my_uri=$cgi->url(-absolute =>1); 40 41# Base URL for relative URLs in gitweb ($logo, $favicon, ...), 42# needed and used only for URLs with nonempty PATH_INFO 43our$base_url=$my_url; 44 45# When the script is used as DirectoryIndex, the URL does not contain the name 46# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we 47# have to do it ourselves. We make $path_info global because it's also used 48# later on. 49# 50# Another issue with the script being the DirectoryIndex is that the resulting 51# $my_url data is not the full script URL: this is good, because we want 52# generated links to keep implying the script name if it wasn't explicitly 53# indicated in the URL we're handling, but it means that $my_url cannot be used 54# as base URL. 55# Therefore, if we needed to strip PATH_INFO, then we know that we have 56# to build the base URL ourselves: 57our$path_info=$ENV{"PATH_INFO"}; 58if($path_info) { 59if($my_url=~ s,\Q$path_info\E$,, && 60$my_uri=~ s,\Q$path_info\E$,, && 61defined$ENV{'SCRIPT_NAME'}) { 62$base_url=$cgi->url(-base =>1) .$ENV{'SCRIPT_NAME'}; 63} 64} 65 66# target of the home link on top of all pages 67our$home_link=$my_uri||"/"; 68} 69 70# core git executable to use 71# this can just be "git" if your webserver has a sensible PATH 72our$GIT="++GIT_BINDIR++/git"; 73 74# absolute fs-path which will be prepended to the project path 75#our $projectroot = "/pub/scm"; 76our$projectroot="++GITWEB_PROJECTROOT++"; 77 78# fs traversing limit for getting project list 79# the number is relative to the projectroot 80our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 81 82# string of the home link on top of all pages 83our$home_link_str="++GITWEB_HOME_LINK_STR++"; 84 85# name of your site or organization to appear in page titles 86# replace this with something more descriptive for clearer bookmarks 87our$site_name="++GITWEB_SITENAME++" 88|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 89 90# filename of html text to include at top of each page 91our$site_header="++GITWEB_SITE_HEADER++"; 92# html text to include at home page 93our$home_text="++GITWEB_HOMETEXT++"; 94# filename of html text to include at bottom of each page 95our$site_footer="++GITWEB_SITE_FOOTER++"; 96 97# URI of stylesheets 98our@stylesheets= ("++GITWEB_CSS++"); 99# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 100our$stylesheet=undef; 101# URI of GIT logo (72x27 size) 102our$logo="++GITWEB_LOGO++"; 103# URI of GIT favicon, assumed to be image/png type 104our$favicon="++GITWEB_FAVICON++"; 105# URI of gitweb.js (JavaScript code for gitweb) 106our$javascript="++GITWEB_JS++"; 107 108# URI and label (title) of GIT logo link 109#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 110#our $logo_label = "git documentation"; 111our$logo_url="http://git-scm.com/"; 112our$logo_label="git homepage"; 113 114# source of projects list 115our$projects_list="++GITWEB_LIST++"; 116 117# the width (in characters) of the projects list "Description" column 118our$projects_list_description_width=25; 119 120# default order of projects list 121# valid values are none, project, descr, owner, and age 122our$default_projects_order="project"; 123 124# show repository only if this file exists 125# (only effective if this variable evaluates to true) 126our$export_ok="++GITWEB_EXPORT_OK++"; 127 128# show repository only if this subroutine returns true 129# when given the path to the project, for example: 130# sub { return -e "$_[0]/git-daemon-export-ok"; } 131our$export_auth_hook=undef; 132 133# only allow viewing of repositories also shown on the overview page 134our$strict_export="++GITWEB_STRICT_EXPORT++"; 135 136# list of git base URLs used for URL to where fetch project from, 137# i.e. full URL is "$git_base_url/$project" 138our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 139 140# default blob_plain mimetype and default charset for text/plain blob 141our$default_blob_plain_mimetype='text/plain'; 142our$default_text_plain_charset=undef; 143 144# file to use for guessing MIME types before trying /etc/mime.types 145# (relative to the current git repository) 146our$mimetypes_file=undef; 147 148# assume this charset if line contains non-UTF-8 characters; 149# it should be valid encoding (see Encoding::Supported(3pm) for list), 150# for which encoding all byte sequences are valid, for example 151# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 152# could be even 'utf-8' for the old behavior) 153our$fallback_encoding='latin1'; 154 155# rename detection options for git-diff and git-diff-tree 156# - default is '-M', with the cost proportional to 157# (number of removed files) * (number of new files). 158# - more costly is '-C' (which implies '-M'), with the cost proportional to 159# (number of changed files + number of removed files) * (number of new files) 160# - even more costly is '-C', '--find-copies-harder' with cost 161# (number of files in the original tree) * (number of new files) 162# - one might want to include '-B' option, e.g. '-B', '-M' 163our@diff_opts= ('-M');# taken from git_commit 164 165# Disables features that would allow repository owners to inject script into 166# the gitweb domain. 167our$prevent_xss=0; 168 169# information about snapshot formats that gitweb is capable of serving 170our%known_snapshot_formats= ( 171# name => { 172# 'display' => display name, 173# 'type' => mime type, 174# 'suffix' => filename suffix, 175# 'format' => --format for git-archive, 176# 'compressor' => [compressor command and arguments] 177# (array reference, optional) 178# 'disabled' => boolean (optional)} 179# 180'tgz'=> { 181'display'=>'tar.gz', 182'type'=>'application/x-gzip', 183'suffix'=>'.tar.gz', 184'format'=>'tar', 185'compressor'=> ['gzip']}, 186 187'tbz2'=> { 188'display'=>'tar.bz2', 189'type'=>'application/x-bzip2', 190'suffix'=>'.tar.bz2', 191'format'=>'tar', 192'compressor'=> ['bzip2']}, 193 194'txz'=> { 195'display'=>'tar.xz', 196'type'=>'application/x-xz', 197'suffix'=>'.tar.xz', 198'format'=>'tar', 199'compressor'=> ['xz'], 200'disabled'=>1}, 201 202'zip'=> { 203'display'=>'zip', 204'type'=>'application/x-zip', 205'suffix'=>'.zip', 206'format'=>'zip'}, 207); 208 209# Aliases so we understand old gitweb.snapshot values in repository 210# configuration. 211our%known_snapshot_format_aliases= ( 212'gzip'=>'tgz', 213'bzip2'=>'tbz2', 214'xz'=>'txz', 215 216# backward compatibility: legacy gitweb config support 217'x-gzip'=>undef,'gz'=>undef, 218'x-bzip2'=>undef,'bz2'=>undef, 219'x-zip'=>undef,''=>undef, 220); 221 222# Pixel sizes for icons and avatars. If the default font sizes or lineheights 223# are changed, it may be appropriate to change these values too via 224# $GITWEB_CONFIG. 225our%avatar_size= ( 226'default'=>16, 227'double'=>32 228); 229 230# Used to set the maximum load that we will still respond to gitweb queries. 231# If server load exceed this value then return "503 server busy" error. 232# If gitweb cannot determined server load, it is taken to be 0. 233# Leave it undefined (or set to 'undef') to turn off load checking. 234our$maxload=300; 235 236# configuration for 'highlight' (http://www.andre-simon.de/) 237# match by basename 238our%highlight_basename= ( 239#'Program' => 'py', 240#'Library' => 'py', 241'SConstruct'=>'py',# SCons equivalent of Makefile 242'Makefile'=>'make', 243); 244# match by extension 245our%highlight_ext= ( 246# main extensions, defining name of syntax; 247# see files in /usr/share/highlight/langDefs/ directory 248map{$_=>$_} 249qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl), 250# alternate extensions, see /etc/highlight/filetypes.conf 251'h'=>'c', 252map{$_=>'cpp'}qw(cxx c++ cc), 253map{$_=>'php'}qw(php3 php4), 254map{$_=>'pl'}qw(perl pm),# perhaps also 'cgi' 255'mak'=>'make', 256map{$_=>'xml'}qw(xhtml html htm), 257); 258 259# You define site-wide feature defaults here; override them with 260# $GITWEB_CONFIG as necessary. 261our%feature= ( 262# feature => { 263# 'sub' => feature-sub (subroutine), 264# 'override' => allow-override (boolean), 265# 'default' => [ default options...] (array reference)} 266# 267# if feature is overridable (it means that allow-override has true value), 268# then feature-sub will be called with default options as parameters; 269# return value of feature-sub indicates if to enable specified feature 270# 271# if there is no 'sub' key (no feature-sub), then feature cannot be 272# overridden 273# 274# use gitweb_get_feature(<feature>) to retrieve the <feature> value 275# (an array) or gitweb_check_feature(<feature>) to check if <feature> 276# is enabled 277 278# Enable the 'blame' blob view, showing the last commit that modified 279# each line in the file. This can be very CPU-intensive. 280 281# To enable system wide have in $GITWEB_CONFIG 282# $feature{'blame'}{'default'} = [1]; 283# To have project specific config enable override in $GITWEB_CONFIG 284# $feature{'blame'}{'override'} = 1; 285# and in project config gitweb.blame = 0|1; 286'blame'=> { 287'sub'=>sub{ feature_bool('blame',@_) }, 288'override'=>0, 289'default'=> [0]}, 290 291# Enable the 'snapshot' link, providing a compressed archive of any 292# tree. This can potentially generate high traffic if you have large 293# project. 294 295# Value is a list of formats defined in %known_snapshot_formats that 296# you wish to offer. 297# To disable system wide have in $GITWEB_CONFIG 298# $feature{'snapshot'}{'default'} = []; 299# To have project specific config enable override in $GITWEB_CONFIG 300# $feature{'snapshot'}{'override'} = 1; 301# and in project config, a comma-separated list of formats or "none" 302# to disable. Example: gitweb.snapshot = tbz2,zip; 303'snapshot'=> { 304'sub'=> \&feature_snapshot, 305'override'=>0, 306'default'=> ['tgz']}, 307 308# Enable text search, which will list the commits which match author, 309# committer or commit text to a given string. Enabled by default. 310# Project specific override is not supported. 311'search'=> { 312'override'=>0, 313'default'=> [1]}, 314 315# Enable grep search, which will list the files in currently selected 316# tree containing the given string. Enabled by default. This can be 317# potentially CPU-intensive, of course. 318 319# To enable system wide have in $GITWEB_CONFIG 320# $feature{'grep'}{'default'} = [1]; 321# To have project specific config enable override in $GITWEB_CONFIG 322# $feature{'grep'}{'override'} = 1; 323# and in project config gitweb.grep = 0|1; 324'grep'=> { 325'sub'=>sub{ feature_bool('grep',@_) }, 326'override'=>0, 327'default'=> [1]}, 328 329# Enable the pickaxe search, which will list the commits that modified 330# a given string in a file. This can be practical and quite faster 331# alternative to 'blame', but still potentially CPU-intensive. 332 333# To enable system wide have in $GITWEB_CONFIG 334# $feature{'pickaxe'}{'default'} = [1]; 335# To have project specific config enable override in $GITWEB_CONFIG 336# $feature{'pickaxe'}{'override'} = 1; 337# and in project config gitweb.pickaxe = 0|1; 338'pickaxe'=> { 339'sub'=>sub{ feature_bool('pickaxe',@_) }, 340'override'=>0, 341'default'=> [1]}, 342 343# Enable showing size of blobs in a 'tree' view, in a separate 344# column, similar to what 'ls -l' does. This cost a bit of IO. 345 346# To disable system wide have in $GITWEB_CONFIG 347# $feature{'show-sizes'}{'default'} = [0]; 348# To have project specific config enable override in $GITWEB_CONFIG 349# $feature{'show-sizes'}{'override'} = 1; 350# and in project config gitweb.showsizes = 0|1; 351'show-sizes'=> { 352'sub'=>sub{ feature_bool('showsizes',@_) }, 353'override'=>0, 354'default'=> [1]}, 355 356# Make gitweb use an alternative format of the URLs which can be 357# more readable and natural-looking: project name is embedded 358# directly in the path and the query string contains other 359# auxiliary information. All gitweb installations recognize 360# URL in either format; this configures in which formats gitweb 361# generates links. 362 363# To enable system wide have in $GITWEB_CONFIG 364# $feature{'pathinfo'}{'default'} = [1]; 365# Project specific override is not supported. 366 367# Note that you will need to change the default location of CSS, 368# favicon, logo and possibly other files to an absolute URL. Also, 369# if gitweb.cgi serves as your indexfile, you will need to force 370# $my_uri to contain the script name in your $GITWEB_CONFIG. 371'pathinfo'=> { 372'override'=>0, 373'default'=> [0]}, 374 375# Make gitweb consider projects in project root subdirectories 376# to be forks of existing projects. Given project $projname.git, 377# projects matching $projname/*.git will not be shown in the main 378# projects list, instead a '+' mark will be added to $projname 379# there and a 'forks' view will be enabled for the project, listing 380# all the forks. If project list is taken from a file, forks have 381# to be listed after the main project. 382 383# To enable system wide have in $GITWEB_CONFIG 384# $feature{'forks'}{'default'} = [1]; 385# Project specific override is not supported. 386'forks'=> { 387'override'=>0, 388'default'=> [0]}, 389 390# Insert custom links to the action bar of all project pages. 391# This enables you mainly to link to third-party scripts integrating 392# into gitweb; e.g. git-browser for graphical history representation 393# or custom web-based repository administration interface. 394 395# The 'default' value consists of a list of triplets in the form 396# (label, link, position) where position is the label after which 397# to insert the link and link is a format string where %n expands 398# to the project name, %f to the project path within the filesystem, 399# %h to the current hash (h gitweb parameter) and %b to the current 400# hash base (hb gitweb parameter); %% expands to %. 401 402# To enable system wide have in $GITWEB_CONFIG e.g. 403# $feature{'actions'}{'default'} = [('graphiclog', 404# '/git-browser/by-commit.html?r=%n', 'summary')]; 405# Project specific override is not supported. 406'actions'=> { 407'override'=>0, 408'default'=> []}, 409 410# Allow gitweb scan project content tags described in ctags/ 411# of project repository, and display the popular Web 2.0-ish 412# "tag cloud" near the project list. Note that this is something 413# COMPLETELY different from the normal Git tags. 414 415# gitweb by itself can show existing tags, but it does not handle 416# tagging itself; you need an external application for that. 417# For an example script, check Girocco's cgi/tagproj.cgi. 418# You may want to install the HTML::TagCloud Perl module to get 419# a pretty tag cloud instead of just a list of tags. 420 421# To enable system wide have in $GITWEB_CONFIG 422# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 423# Project specific override is not supported. 424'ctags'=> { 425'override'=>0, 426'default'=> [0]}, 427 428# The maximum number of patches in a patchset generated in patch 429# view. Set this to 0 or undef to disable patch view, or to a 430# negative number to remove any limit. 431 432# To disable system wide have in $GITWEB_CONFIG 433# $feature{'patches'}{'default'} = [0]; 434# To have project specific config enable override in $GITWEB_CONFIG 435# $feature{'patches'}{'override'} = 1; 436# and in project config gitweb.patches = 0|n; 437# where n is the maximum number of patches allowed in a patchset. 438'patches'=> { 439'sub'=> \&feature_patches, 440'override'=>0, 441'default'=> [16]}, 442 443# Avatar support. When this feature is enabled, views such as 444# shortlog or commit will display an avatar associated with 445# the email of the committer(s) and/or author(s). 446 447# Currently available providers are gravatar and picon. 448# If an unknown provider is specified, the feature is disabled. 449 450# Gravatar depends on Digest::MD5. 451# Picon currently relies on the indiana.edu database. 452 453# To enable system wide have in $GITWEB_CONFIG 454# $feature{'avatar'}{'default'} = ['<provider>']; 455# where <provider> is either gravatar or picon. 456# To have project specific config enable override in $GITWEB_CONFIG 457# $feature{'avatar'}{'override'} = 1; 458# and in project config gitweb.avatar = <provider>; 459'avatar'=> { 460'sub'=> \&feature_avatar, 461'override'=>0, 462'default'=> ['']}, 463 464# Enable displaying how much time and how many git commands 465# it took to generate and display page. Disabled by default. 466# Project specific override is not supported. 467'timed'=> { 468'override'=>0, 469'default'=> [0]}, 470 471# Enable turning some links into links to actions which require 472# JavaScript to run (like 'blame_incremental'). Not enabled by 473# default. Project specific override is currently not supported. 474'javascript-actions'=> { 475'override'=>0, 476'default'=> [0]}, 477 478# Syntax highlighting support. This is based on Daniel Svensson's 479# and Sham Chukoury's work in gitweb-xmms2.git. 480# It requires the 'highlight' program present in $PATH, 481# and therefore is disabled by default. 482 483# To enable system wide have in $GITWEB_CONFIG 484# $feature{'highlight'}{'default'} = [1]; 485 486'highlight'=> { 487'sub'=>sub{ feature_bool('highlight',@_) }, 488'override'=>0, 489'default'=> [0]}, 490); 491 492sub gitweb_get_feature { 493my($name) =@_; 494return unlessexists$feature{$name}; 495my($sub,$override,@defaults) = ( 496$feature{$name}{'sub'}, 497$feature{$name}{'override'}, 498@{$feature{$name}{'default'}}); 499# project specific override is possible only if we have project 500our$git_dir;# global variable, declared later 501if(!$override|| !defined$git_dir) { 502return@defaults; 503} 504if(!defined$sub) { 505warn"feature$nameis not overridable"; 506return@defaults; 507} 508return$sub->(@defaults); 509} 510 511# A wrapper to check if a given feature is enabled. 512# With this, you can say 513# 514# my $bool_feat = gitweb_check_feature('bool_feat'); 515# gitweb_check_feature('bool_feat') or somecode; 516# 517# instead of 518# 519# my ($bool_feat) = gitweb_get_feature('bool_feat'); 520# (gitweb_get_feature('bool_feat'))[0] or somecode; 521# 522sub gitweb_check_feature { 523return(gitweb_get_feature(@_))[0]; 524} 525 526 527sub feature_bool { 528my$key=shift; 529my($val) = git_get_project_config($key,'--bool'); 530 531if(!defined$val) { 532return($_[0]); 533}elsif($valeq'true') { 534return(1); 535}elsif($valeq'false') { 536return(0); 537} 538} 539 540sub feature_snapshot { 541my(@fmts) =@_; 542 543my($val) = git_get_project_config('snapshot'); 544 545if($val) { 546@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 547} 548 549return@fmts; 550} 551 552sub feature_patches { 553my@val= (git_get_project_config('patches','--int')); 554 555if(@val) { 556return@val; 557} 558 559return($_[0]); 560} 561 562sub feature_avatar { 563my@val= (git_get_project_config('avatar')); 564 565return@val?@val:@_; 566} 567 568# checking HEAD file with -e is fragile if the repository was 569# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 570# and then pruned. 571sub check_head_link { 572my($dir) =@_; 573my$headfile="$dir/HEAD"; 574return((-e $headfile) || 575(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 576} 577 578sub check_export_ok { 579my($dir) =@_; 580return(check_head_link($dir) && 581(!$export_ok|| -e "$dir/$export_ok") && 582(!$export_auth_hook||$export_auth_hook->($dir))); 583} 584 585# process alternate names for backward compatibility 586# filter out unsupported (unknown) snapshot formats 587sub filter_snapshot_fmts { 588my@fmts=@_; 589 590@fmts=map{ 591exists$known_snapshot_format_aliases{$_} ? 592$known_snapshot_format_aliases{$_} :$_}@fmts; 593@fmts=grep{ 594exists$known_snapshot_formats{$_} && 595!$known_snapshot_formats{$_}{'disabled'}}@fmts; 596} 597 598our($GITWEB_CONFIG,$GITWEB_CONFIG_SYSTEM); 599sub evaluate_gitweb_config { 600our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 601our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 602# die if there are errors parsing config file 603if(-e $GITWEB_CONFIG) { 604do$GITWEB_CONFIG; 605die$@if$@; 606}elsif(-e $GITWEB_CONFIG_SYSTEM) { 607do$GITWEB_CONFIG_SYSTEM; 608die$@if$@; 609} 610} 611 612# Get loadavg of system, to compare against $maxload. 613# Currently it requires '/proc/loadavg' present to get loadavg; 614# if it is not present it returns 0, which means no load checking. 615sub get_loadavg { 616if( -e '/proc/loadavg'){ 617open my$fd,'<','/proc/loadavg' 618orreturn0; 619my@load=split(/\s+/,scalar<$fd>); 620close$fd; 621 622# The first three columns measure CPU and IO utilization of the last one, 623# five, and 10 minute periods. The fourth column shows the number of 624# currently running processes and the total number of processes in the m/n 625# format. The last column displays the last process ID used. 626return$load[0] ||0; 627} 628# additional checks for load average should go here for things that don't export 629# /proc/loadavg 630 631return0; 632} 633 634# version of the core git binary 635our$git_version; 636sub evaluate_git_version { 637our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 638$number_of_git_cmds++; 639} 640 641sub check_loadavg { 642if(defined$maxload&& get_loadavg() >$maxload) { 643 die_error(503,"The load average on the server is too high"); 644} 645} 646 647# ====================================================================== 648# input validation and dispatch 649 650# input parameters can be collected from a variety of sources (presently, CGI 651# and PATH_INFO), so we define an %input_params hash that collects them all 652# together during validation: this allows subsequent uses (e.g. href()) to be 653# agnostic of the parameter origin 654 655our%input_params= (); 656 657# input parameters are stored with the long parameter name as key. This will 658# also be used in the href subroutine to convert parameters to their CGI 659# equivalent, and since the href() usage is the most frequent one, we store 660# the name -> CGI key mapping here, instead of the reverse. 661# 662# XXX: Warning: If you touch this, check the search form for updating, 663# too. 664 665our@cgi_param_mapping= ( 666 project =>"p", 667 action =>"a", 668 file_name =>"f", 669 file_parent =>"fp", 670 hash =>"h", 671 hash_parent =>"hp", 672 hash_base =>"hb", 673 hash_parent_base =>"hpb", 674 page =>"pg", 675 order =>"o", 676 searchtext =>"s", 677 searchtype =>"st", 678 snapshot_format =>"sf", 679 extra_options =>"opt", 680 search_use_regexp =>"sr", 681# this must be last entry (for manipulation from JavaScript) 682 javascript =>"js" 683); 684our%cgi_param_mapping=@cgi_param_mapping; 685 686# we will also need to know the possible actions, for validation 687our%actions= ( 688"blame"=> \&git_blame, 689"blame_incremental"=> \&git_blame_incremental, 690"blame_data"=> \&git_blame_data, 691"blobdiff"=> \&git_blobdiff, 692"blobdiff_plain"=> \&git_blobdiff_plain, 693"blob"=> \&git_blob, 694"blob_plain"=> \&git_blob_plain, 695"commitdiff"=> \&git_commitdiff, 696"commitdiff_plain"=> \&git_commitdiff_plain, 697"commit"=> \&git_commit, 698"forks"=> \&git_forks, 699"heads"=> \&git_heads, 700"history"=> \&git_history, 701"log"=> \&git_log, 702"patch"=> \&git_patch, 703"patches"=> \&git_patches, 704"rss"=> \&git_rss, 705"atom"=> \&git_atom, 706"search"=> \&git_search, 707"search_help"=> \&git_search_help, 708"shortlog"=> \&git_shortlog, 709"summary"=> \&git_summary, 710"tag"=> \&git_tag, 711"tags"=> \&git_tags, 712"tree"=> \&git_tree, 713"snapshot"=> \&git_snapshot, 714"object"=> \&git_object, 715# those below don't need $project 716"opml"=> \&git_opml, 717"project_list"=> \&git_project_list, 718"project_index"=> \&git_project_index, 719); 720 721# finally, we have the hash of allowed extra_options for the commands that 722# allow them 723our%allowed_options= ( 724"--no-merges"=> [qw(rss atom log shortlog history)], 725); 726 727# fill %input_params with the CGI parameters. All values except for 'opt' 728# should be single values, but opt can be an array. We should probably 729# build an array of parameters that can be multi-valued, but since for the time 730# being it's only this one, we just single it out 731sub evaluate_query_params { 732our$cgi; 733 734while(my($name,$symbol) =each%cgi_param_mapping) { 735if($symboleq'opt') { 736$input_params{$name} = [$cgi->param($symbol) ]; 737}else{ 738$input_params{$name} =$cgi->param($symbol); 739} 740} 741} 742 743# now read PATH_INFO and update the parameter list for missing parameters 744sub evaluate_path_info { 745return ifdefined$input_params{'project'}; 746return if!$path_info; 747$path_info=~ s,^/+,,; 748return if!$path_info; 749 750# find which part of PATH_INFO is project 751my$project=$path_info; 752$project=~ s,/+$,,; 753while($project&& !check_head_link("$projectroot/$project")) { 754$project=~ s,/*[^/]*$,,; 755} 756return unless$project; 757$input_params{'project'} =$project; 758 759# do not change any parameters if an action is given using the query string 760return if$input_params{'action'}; 761$path_info=~ s,^\Q$project\E/*,,; 762 763# next, check if we have an action 764my$action=$path_info; 765$action=~ s,/.*$,,; 766if(exists$actions{$action}) { 767$path_info=~ s,^$action/*,,; 768$input_params{'action'} =$action; 769} 770 771# list of actions that want hash_base instead of hash, but can have no 772# pathname (f) parameter 773my@wants_base= ( 774'tree', 775'history', 776); 777 778# we want to catch 779# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 780my($parentrefname,$parentpathname,$refname,$pathname) = 781($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/); 782 783# first, analyze the 'current' part 784if(defined$pathname) { 785# we got "branch:filename" or "branch:dir/" 786# we could use git_get_type(branch:pathname), but: 787# - it needs $git_dir 788# - it does a git() call 789# - the convention of terminating directories with a slash 790# makes it superfluous 791# - embedding the action in the PATH_INFO would make it even 792# more superfluous 793$pathname=~ s,^/+,,; 794if(!$pathname||substr($pathname, -1)eq"/") { 795$input_params{'action'} ||="tree"; 796$pathname=~ s,/$,,; 797}else{ 798# the default action depends on whether we had parent info 799# or not 800if($parentrefname) { 801$input_params{'action'} ||="blobdiff_plain"; 802}else{ 803$input_params{'action'} ||="blob_plain"; 804} 805} 806$input_params{'hash_base'} ||=$refname; 807$input_params{'file_name'} ||=$pathname; 808}elsif(defined$refname) { 809# we got "branch". In this case we have to choose if we have to 810# set hash or hash_base. 811# 812# Most of the actions without a pathname only want hash to be 813# set, except for the ones specified in @wants_base that want 814# hash_base instead. It should also be noted that hand-crafted 815# links having 'history' as an action and no pathname or hash 816# set will fail, but that happens regardless of PATH_INFO. 817$input_params{'action'} ||="shortlog"; 818if(grep{$_eq$input_params{'action'} }@wants_base) { 819$input_params{'hash_base'} ||=$refname; 820}else{ 821$input_params{'hash'} ||=$refname; 822} 823} 824 825# next, handle the 'parent' part, if present 826if(defined$parentrefname) { 827# a missing pathspec defaults to the 'current' filename, allowing e.g. 828# someproject/blobdiff/oldrev..newrev:/filename 829if($parentpathname) { 830$parentpathname=~ s,^/+,,; 831$parentpathname=~ s,/$,,; 832$input_params{'file_parent'} ||=$parentpathname; 833}else{ 834$input_params{'file_parent'} ||=$input_params{'file_name'}; 835} 836# we assume that hash_parent_base is wanted if a path was specified, 837# or if the action wants hash_base instead of hash 838if(defined$input_params{'file_parent'} || 839grep{$_eq$input_params{'action'} }@wants_base) { 840$input_params{'hash_parent_base'} ||=$parentrefname; 841}else{ 842$input_params{'hash_parent'} ||=$parentrefname; 843} 844} 845 846# for the snapshot action, we allow URLs in the form 847# $project/snapshot/$hash.ext 848# where .ext determines the snapshot and gets removed from the 849# passed $refname to provide the $hash. 850# 851# To be able to tell that $refname includes the format extension, we 852# require the following two conditions to be satisfied: 853# - the hash input parameter MUST have been set from the $refname part 854# of the URL (i.e. they must be equal) 855# - the snapshot format MUST NOT have been defined already (e.g. from 856# CGI parameter sf) 857# It's also useless to try any matching unless $refname has a dot, 858# so we check for that too 859if(defined$input_params{'action'} && 860$input_params{'action'}eq'snapshot'&& 861defined$refname&&index($refname,'.') != -1&& 862$refnameeq$input_params{'hash'} && 863!defined$input_params{'snapshot_format'}) { 864# We loop over the known snapshot formats, checking for 865# extensions. Allowed extensions are both the defined suffix 866# (which includes the initial dot already) and the snapshot 867# format key itself, with a prepended dot 868while(my($fmt,$opt) =each%known_snapshot_formats) { 869my$hash=$refname; 870unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 871next; 872} 873my$sfx=$1; 874# a valid suffix was found, so set the snapshot format 875# and reset the hash parameter 876$input_params{'snapshot_format'} =$fmt; 877$input_params{'hash'} =$hash; 878# we also set the format suffix to the one requested 879# in the URL: this way a request for e.g. .tgz returns 880# a .tgz instead of a .tar.gz 881$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 882last; 883} 884} 885} 886 887our($action,$project,$file_name,$file_parent,$hash,$hash_parent,$hash_base, 888$hash_parent_base,@extra_options,$page,$searchtype,$search_use_regexp, 889$searchtext,$search_regexp); 890sub evaluate_and_validate_params { 891our$action=$input_params{'action'}; 892if(defined$action) { 893if(!validate_action($action)) { 894 die_error(400,"Invalid action parameter"); 895} 896} 897 898# parameters which are pathnames 899our$project=$input_params{'project'}; 900if(defined$project) { 901if(!validate_project($project)) { 902undef$project; 903 die_error(404,"No such project"); 904} 905} 906 907our$file_name=$input_params{'file_name'}; 908if(defined$file_name) { 909if(!validate_pathname($file_name)) { 910 die_error(400,"Invalid file parameter"); 911} 912} 913 914our$file_parent=$input_params{'file_parent'}; 915if(defined$file_parent) { 916if(!validate_pathname($file_parent)) { 917 die_error(400,"Invalid file parent parameter"); 918} 919} 920 921# parameters which are refnames 922our$hash=$input_params{'hash'}; 923if(defined$hash) { 924if(!validate_refname($hash)) { 925 die_error(400,"Invalid hash parameter"); 926} 927} 928 929our$hash_parent=$input_params{'hash_parent'}; 930if(defined$hash_parent) { 931if(!validate_refname($hash_parent)) { 932 die_error(400,"Invalid hash parent parameter"); 933} 934} 935 936our$hash_base=$input_params{'hash_base'}; 937if(defined$hash_base) { 938if(!validate_refname($hash_base)) { 939 die_error(400,"Invalid hash base parameter"); 940} 941} 942 943our@extra_options= @{$input_params{'extra_options'}}; 944# @extra_options is always defined, since it can only be (currently) set from 945# CGI, and $cgi->param() returns the empty array in array context if the param 946# is not set 947foreachmy$opt(@extra_options) { 948if(not exists$allowed_options{$opt}) { 949 die_error(400,"Invalid option parameter"); 950} 951if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 952 die_error(400,"Invalid option parameter for this action"); 953} 954} 955 956our$hash_parent_base=$input_params{'hash_parent_base'}; 957if(defined$hash_parent_base) { 958if(!validate_refname($hash_parent_base)) { 959 die_error(400,"Invalid hash parent base parameter"); 960} 961} 962 963# other parameters 964our$page=$input_params{'page'}; 965if(defined$page) { 966if($page=~m/[^0-9]/) { 967 die_error(400,"Invalid page parameter"); 968} 969} 970 971our$searchtype=$input_params{'searchtype'}; 972if(defined$searchtype) { 973if($searchtype=~m/[^a-z]/) { 974 die_error(400,"Invalid searchtype parameter"); 975} 976} 977 978our$search_use_regexp=$input_params{'search_use_regexp'}; 979 980our$searchtext=$input_params{'searchtext'}; 981our$search_regexp; 982if(defined$searchtext) { 983if(length($searchtext) <2) { 984 die_error(403,"At least two characters are required for search parameter"); 985} 986$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 987} 988} 989 990# path to the current git repository 991our$git_dir; 992sub evaluate_git_dir { 993our$git_dir="$projectroot/$project"if$project; 994} 995 996our(@snapshot_fmts,$git_avatar); 997sub configure_gitweb_features { 998# list of supported snapshot formats 999our@snapshot_fmts= gitweb_get_feature('snapshot');1000@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts);10011002# check that the avatar feature is set to a known provider name,1003# and for each provider check if the dependencies are satisfied.1004# if the provider name is invalid or the dependencies are not met,1005# reset $git_avatar to the empty string.1006our($git_avatar) = gitweb_get_feature('avatar');1007if($git_avatareq'gravatar') {1008$git_avatar=''unless(eval{require Digest::MD5;1; });1009}elsif($git_avatareq'picon') {1010# no dependencies1011}else{1012$git_avatar='';1013}1014}10151016# custom error handler: 'die <message>' is Internal Server Error1017sub handle_errors_html {1018my$msg=shift;# it is already HTML escaped10191020# to avoid infinite loop where error occurs in die_error,1021# change handler to default handler, disabling handle_errors_html1022 set_message("Error occured when inside die_error:\n$msg");10231024# you cannot jump out of die_error when called as error handler;1025# the subroutine set via CGI::Carp::set_message is called _after_1026# HTTP headers are already written, so it cannot write them itself1027 die_error(undef,undef,$msg, -error_handler =>1, -no_http_header =>1);1028}1029set_message(\&handle_errors_html);10301031# dispatch1032sub dispatch {1033if(!defined$action) {1034if(defined$hash) {1035$action= git_get_type($hash);1036}elsif(defined$hash_base&&defined$file_name) {1037$action= git_get_type("$hash_base:$file_name");1038}elsif(defined$project) {1039$action='summary';1040}else{1041$action='project_list';1042}1043}1044if(!defined($actions{$action})) {1045 die_error(400,"Unknown action");1046}1047if($action!~m/^(?:opml|project_list|project_index)$/&&1048!$project) {1049 die_error(400,"Project needed");1050}1051$actions{$action}->();1052}10531054sub reset_timer {1055our$t0= [Time::HiRes::gettimeofday()]1056ifdefined$t0;1057our$number_of_git_cmds=0;1058}10591060sub run_request {1061 reset_timer();10621063 evaluate_uri();1064 evaluate_gitweb_config();1065 check_loadavg();10661067# $projectroot and $projects_list might be set in gitweb config file1068$projects_list||=$projectroot;10691070 evaluate_query_params();1071 evaluate_path_info();1072 evaluate_and_validate_params();1073 evaluate_git_dir();10741075 configure_gitweb_features();10761077 dispatch();1078}10791080our$is_last_request=sub{1};1081our($pre_dispatch_hook,$post_dispatch_hook,$pre_listen_hook);1082our$CGI='CGI';1083our$cgi;1084sub configure_as_fcgi {1085require CGI::Fast;1086our$CGI='CGI::Fast';10871088my$request_number=0;1089# let each child service 100 requests1090our$is_last_request=sub{ ++$request_number>100};1091}1092sub evaluate_argv {1093my$script_name=$ENV{'SCRIPT_NAME'} ||$ENV{'SCRIPT_FILENAME'} || __FILE__;1094 configure_as_fcgi()1095if$script_name=~/\.fcgi$/;10961097return unless(@ARGV);10981099require Getopt::Long;1100 Getopt::Long::GetOptions(1101'fastcgi|fcgi|f'=> \&configure_as_fcgi,1102'nproc|n=i'=>sub{1103my($arg,$val) =@_;1104return unlesseval{require FCGI::ProcManager;1; };1105my$proc_manager= FCGI::ProcManager->new({1106 n_processes =>$val,1107});1108our$pre_listen_hook=sub{$proc_manager->pm_manage() };1109our$pre_dispatch_hook=sub{$proc_manager->pm_pre_dispatch() };1110our$post_dispatch_hook=sub{$proc_manager->pm_post_dispatch() };1111},1112);1113}11141115sub run {1116 evaluate_argv();1117 evaluate_git_version();11181119$pre_listen_hook->()1120if$pre_listen_hook;11211122 REQUEST:1123while($cgi=$CGI->new()) {1124$pre_dispatch_hook->()1125if$pre_dispatch_hook;11261127 run_request();11281129$post_dispatch_hook->()1130if$post_dispatch_hook;11311132last REQUEST if($is_last_request->());1133}11341135 DONE_GITWEB:11361;1137}11381139run();11401141if(defined caller) {1142# wrapped in a subroutine processing requests,1143# e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI1144return;1145}else{1146# pure CGI script, serving single request1147exit;1148}11491150## ======================================================================1151## action links11521153# possible values of extra options1154# -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)1155# -replay => 1 - start from a current view (replay with modifications)1156# -path_info => 0|1 - don't use/use path_info URL (if possible)1157sub href {1158my%params=@_;1159# default is to use -absolute url() i.e. $my_uri1160my$href=$params{-full} ?$my_url:$my_uri;11611162$params{'project'} =$projectunlessexists$params{'project'};11631164if($params{-replay}) {1165while(my($name,$symbol) =each%cgi_param_mapping) {1166if(!exists$params{$name}) {1167$params{$name} =$input_params{$name};1168}1169}1170}11711172my$use_pathinfo= gitweb_check_feature('pathinfo');1173if(defined$params{'project'} &&1174(exists$params{-path_info} ?$params{-path_info} :$use_pathinfo)) {1175# try to put as many parameters as possible in PATH_INFO:1176# - project name1177# - action1178# - hash_parent or hash_parent_base:/file_parent1179# - hash or hash_base:/filename1180# - the snapshot_format as an appropriate suffix11811182# When the script is the root DirectoryIndex for the domain,1183# $href here would be something like http://gitweb.example.com/1184# Thus, we strip any trailing / from $href, to spare us double1185# slashes in the final URL1186$href=~ s,/$,,;11871188# Then add the project name, if present1189$href.="/".esc_path_info($params{'project'});1190delete$params{'project'};11911192# since we destructively absorb parameters, we keep this1193# boolean that remembers if we're handling a snapshot1194my$is_snapshot=$params{'action'}eq'snapshot';11951196# Summary just uses the project path URL, any other action is1197# added to the URL1198if(defined$params{'action'}) {1199$href.="/".esc_path_info($params{'action'})1200unless$params{'action'}eq'summary';1201delete$params{'action'};1202}12031204# Next, we put hash_parent_base:/file_parent..hash_base:/file_name,1205# stripping nonexistent or useless pieces1206$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'}1207||$params{'hash_parent'} ||$params{'hash'});1208if(defined$params{'hash_base'}) {1209if(defined$params{'hash_parent_base'}) {1210$href.= esc_path_info($params{'hash_parent_base'});1211# skip the file_parent if it's the same as the file_name1212if(defined$params{'file_parent'}) {1213if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) {1214delete$params{'file_parent'};1215}elsif($params{'file_parent'} !~/\.\./) {1216$href.=":/".esc_path_info($params{'file_parent'});1217delete$params{'file_parent'};1218}1219}1220$href.="..";1221delete$params{'hash_parent'};1222delete$params{'hash_parent_base'};1223}elsif(defined$params{'hash_parent'}) {1224$href.= esc_path_info($params{'hash_parent'})."..";1225delete$params{'hash_parent'};1226}12271228$href.= esc_path_info($params{'hash_base'});1229if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) {1230$href.=":/".esc_path_info($params{'file_name'});1231delete$params{'file_name'};1232}1233delete$params{'hash'};1234delete$params{'hash_base'};1235}elsif(defined$params{'hash'}) {1236$href.= esc_path_info($params{'hash'});1237delete$params{'hash'};1238}12391240# If the action was a snapshot, we can absorb the1241# snapshot_format parameter too1242if($is_snapshot) {1243my$fmt=$params{'snapshot_format'};1244# snapshot_format should always be defined when href()1245# is called, but just in case some code forgets, we1246# fall back to the default1247$fmt||=$snapshot_fmts[0];1248$href.=$known_snapshot_formats{$fmt}{'suffix'};1249delete$params{'snapshot_format'};1250}1251}12521253# now encode the parameters explicitly1254my@result= ();1255for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1256my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1257if(defined$params{$name}) {1258if(ref($params{$name})eq"ARRAY") {1259foreachmy$par(@{$params{$name}}) {1260push@result,$symbol."=". esc_param($par);1261}1262}else{1263push@result,$symbol."=". esc_param($params{$name});1264}1265}1266}1267$href.="?".join(';',@result)ifscalar@result;12681269# final transformation: trailing spaces must be escaped (URI-encoded)1270$href=~s/(\s+)$/CGI::escape($1)/e;12711272return$href;1273}127412751276## ======================================================================1277## validation, quoting/unquoting and escaping12781279sub validate_action {1280my$input=shift||returnundef;1281returnundefunlessexists$actions{$input};1282return$input;1283}12841285sub validate_project {1286my$input=shift||returnundef;1287if(!validate_pathname($input) ||1288!(-d "$projectroot/$input") ||1289!check_export_ok("$projectroot/$input") ||1290($strict_export&& !project_in_list($input))) {1291returnundef;1292}else{1293return$input;1294}1295}12961297sub validate_pathname {1298my$input=shift||returnundef;12991300# no '.' or '..' as elements of path, i.e. no '.' nor '..'1301# at the beginning, at the end, and between slashes.1302# also this catches doubled slashes1303if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1304returnundef;1305}1306# no null characters1307if($input=~m!\0!) {1308returnundef;1309}1310return$input;1311}13121313sub validate_refname {1314my$input=shift||returnundef;13151316# textual hashes are O.K.1317if($input=~m/^[0-9a-fA-F]{40}$/) {1318return$input;1319}1320# it must be correct pathname1321$input= validate_pathname($input)1322orreturnundef;1323# restrictions on ref name according to git-check-ref-format1324if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1325returnundef;1326}1327return$input;1328}13291330# decode sequences of octets in utf8 into Perl's internal form,1331# which is utf-8 with utf8 flag set if needed. gitweb writes out1332# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1333sub to_utf8 {1334my$str=shift;1335returnundefunlessdefined$str;1336if(utf8::valid($str)) {1337 utf8::decode($str);1338return$str;1339}else{1340return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1341}1342}13431344# quote unsafe chars, but keep the slash, even when it's not1345# correct, but quoted slashes look too horrible in bookmarks1346sub esc_param {1347my$str=shift;1348returnundefunlessdefined$str;1349$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1350$str=~s/ /\+/g;1351return$str;1352}13531354# the quoting rules for path_info fragment are slightly different1355sub esc_path_info {1356my$str=shift;1357returnundefunlessdefined$str;13581359# path_info doesn't treat '+' as space (specially), but '?' must be escaped1360$str=~s/([^A-Za-z0-9\-_.~();\/;:@&= +]+)/CGI::escape($1)/eg;13611362return$str;1363}13641365# quote unsafe chars in whole URL, so some characters cannot be quoted1366sub esc_url {1367my$str=shift;1368returnundefunlessdefined$str;1369$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg;1370$str=~s/ /\+/g;1371return$str;1372}13731374# replace invalid utf8 character with SUBSTITUTION sequence1375sub esc_html {1376my$str=shift;1377my%opts=@_;13781379returnundefunlessdefined$str;13801381$str= to_utf8($str);1382$str=$cgi->escapeHTML($str);1383if($opts{'-nbsp'}) {1384$str=~s/ / /g;1385}1386$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1387return$str;1388}13891390# quote control characters and escape filename to HTML1391sub esc_path {1392my$str=shift;1393my%opts=@_;13941395returnundefunlessdefined$str;13961397$str= to_utf8($str);1398$str=$cgi->escapeHTML($str);1399if($opts{'-nbsp'}) {1400$str=~s/ / /g;1401}1402$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1403return$str;1404}14051406# Make control characters "printable", using character escape codes (CEC)1407sub quot_cec {1408my$cntrl=shift;1409my%opts=@_;1410my%es= (# character escape codes, aka escape sequences1411"\t"=>'\t',# tab (HT)1412"\n"=>'\n',# line feed (LF)1413"\r"=>'\r',# carrige return (CR)1414"\f"=>'\f',# form feed (FF)1415"\b"=>'\b',# backspace (BS)1416"\a"=>'\a',# alarm (bell) (BEL)1417"\e"=>'\e',# escape (ESC)1418"\013"=>'\v',# vertical tab (VT)1419"\000"=>'\0',# nul character (NUL)1420);1421my$chr= ( (exists$es{$cntrl})1422?$es{$cntrl}1423:sprintf('\%2x',ord($cntrl)) );1424if($opts{-nohtml}) {1425return$chr;1426}else{1427return"<span class=\"cntrl\">$chr</span>";1428}1429}14301431# Alternatively use unicode control pictures codepoints,1432# Unicode "printable representation" (PR)1433sub quot_upr {1434my$cntrl=shift;1435my%opts=@_;14361437my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1438if($opts{-nohtml}) {1439return$chr;1440}else{1441return"<span class=\"cntrl\">$chr</span>";1442}1443}14441445# git may return quoted and escaped filenames1446sub unquote {1447my$str=shift;14481449sub unq {1450my$seq=shift;1451my%es= (# character escape codes, aka escape sequences1452't'=>"\t",# tab (HT, TAB)1453'n'=>"\n",# newline (NL)1454'r'=>"\r",# return (CR)1455'f'=>"\f",# form feed (FF)1456'b'=>"\b",# backspace (BS)1457'a'=>"\a",# alarm (bell) (BEL)1458'e'=>"\e",# escape (ESC)1459'v'=>"\013",# vertical tab (VT)1460);14611462if($seq=~m/^[0-7]{1,3}$/) {1463# octal char sequence1464returnchr(oct($seq));1465}elsif(exists$es{$seq}) {1466# C escape sequence, aka character escape code1467return$es{$seq};1468}1469# quoted ordinary character1470return$seq;1471}14721473if($str=~m/^"(.*)"$/) {1474# needs unquoting1475$str=$1;1476$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1477}1478return$str;1479}14801481# escape tabs (convert tabs to spaces)1482sub untabify {1483my$line=shift;14841485while((my$pos=index($line,"\t")) != -1) {1486if(my$count= (8- ($pos%8))) {1487my$spaces=' ' x $count;1488$line=~s/\t/$spaces/;1489}1490}14911492return$line;1493}14941495sub project_in_list {1496my$project=shift;1497my@list= git_get_projects_list();1498return@list&&scalar(grep{$_->{'path'}eq$project}@list);1499}15001501## ----------------------------------------------------------------------1502## HTML aware string manipulation15031504# Try to chop given string on a word boundary between position1505# $len and $len+$add_len. If there is no word boundary there,1506# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1507# (marking chopped part) would be longer than given string.1508sub chop_str {1509my$str=shift;1510my$len=shift;1511my$add_len=shift||10;1512my$where=shift||'right';# 'left' | 'center' | 'right'15131514# Make sure perl knows it is utf8 encoded so we don't1515# cut in the middle of a utf8 multibyte char.1516$str= to_utf8($str);15171518# allow only $len chars, but don't cut a word if it would fit in $add_len1519# if it doesn't fit, cut it if it's still longer than the dots we would add1520# remove chopped character entities entirely15211522# when chopping in the middle, distribute $len into left and right part1523# return early if chopping wouldn't make string shorter1524if($whereeq'center') {1525return$strif($len+5>=length($str));# filler is length 51526$len=int($len/2);1527}else{1528return$strif($len+4>=length($str));# filler is length 41529}15301531# regexps: ending and beginning with word part up to $add_len1532my$endre=qr/.{$len}\w{0,$add_len}/;1533my$begre=qr/\w{0,$add_len}.{$len}/;15341535if($whereeq'left') {1536$str=~m/^(.*?)($begre)$/;1537my($lead,$body) = ($1,$2);1538if(length($lead) >4) {1539$lead=" ...";1540}1541return"$lead$body";15421543}elsif($whereeq'center') {1544$str=~m/^($endre)(.*)$/;1545my($left,$str) = ($1,$2);1546$str=~m/^(.*?)($begre)$/;1547my($mid,$right) = ($1,$2);1548if(length($mid) >5) {1549$mid=" ... ";1550}1551return"$left$mid$right";15521553}else{1554$str=~m/^($endre)(.*)$/;1555my$body=$1;1556my$tail=$2;1557if(length($tail) >4) {1558$tail="... ";1559}1560return"$body$tail";1561}1562}15631564# takes the same arguments as chop_str, but also wraps a <span> around the1565# result with a title attribute if it does get chopped. Additionally, the1566# string is HTML-escaped.1567sub chop_and_escape_str {1568my($str) =@_;15691570my$chopped= chop_str(@_);1571if($choppedeq$str) {1572return esc_html($chopped);1573}else{1574$str=~s/[[:cntrl:]]/?/g;1575return$cgi->span({-title=>$str}, esc_html($chopped));1576}1577}15781579## ----------------------------------------------------------------------1580## functions returning short strings15811582# CSS class for given age value (in seconds)1583sub age_class {1584my$age=shift;15851586if(!defined$age) {1587return"noage";1588}elsif($age<60*60*2) {1589return"age0";1590}elsif($age<60*60*24*2) {1591return"age1";1592}else{1593return"age2";1594}1595}15961597# convert age in seconds to "nn units ago" string1598sub age_string {1599my$age=shift;1600my$age_str;16011602if($age>60*60*24*365*2) {1603$age_str= (int$age/60/60/24/365);1604$age_str.=" years ago";1605}elsif($age>60*60*24*(365/12)*2) {1606$age_str=int$age/60/60/24/(365/12);1607$age_str.=" months ago";1608}elsif($age>60*60*24*7*2) {1609$age_str=int$age/60/60/24/7;1610$age_str.=" weeks ago";1611}elsif($age>60*60*24*2) {1612$age_str=int$age/60/60/24;1613$age_str.=" days ago";1614}elsif($age>60*60*2) {1615$age_str=int$age/60/60;1616$age_str.=" hours ago";1617}elsif($age>60*2) {1618$age_str=int$age/60;1619$age_str.=" min ago";1620}elsif($age>2) {1621$age_str=int$age;1622$age_str.=" sec ago";1623}else{1624$age_str.=" right now";1625}1626return$age_str;1627}16281629useconstant{1630 S_IFINVALID =>0030000,1631 S_IFGITLINK =>0160000,1632};16331634# submodule/subproject, a commit object reference1635sub S_ISGITLINK {1636my$mode=shift;16371638return(($mode& S_IFMT) == S_IFGITLINK)1639}16401641# convert file mode in octal to symbolic file mode string1642sub mode_str {1643my$mode=oct shift;16441645if(S_ISGITLINK($mode)) {1646return'm---------';1647}elsif(S_ISDIR($mode& S_IFMT)) {1648return'drwxr-xr-x';1649}elsif(S_ISLNK($mode)) {1650return'lrwxrwxrwx';1651}elsif(S_ISREG($mode)) {1652# git cares only about the executable bit1653if($mode& S_IXUSR) {1654return'-rwxr-xr-x';1655}else{1656return'-rw-r--r--';1657};1658}else{1659return'----------';1660}1661}16621663# convert file mode in octal to file type string1664sub file_type {1665my$mode=shift;16661667if($mode!~m/^[0-7]+$/) {1668return$mode;1669}else{1670$mode=oct$mode;1671}16721673if(S_ISGITLINK($mode)) {1674return"submodule";1675}elsif(S_ISDIR($mode& S_IFMT)) {1676return"directory";1677}elsif(S_ISLNK($mode)) {1678return"symlink";1679}elsif(S_ISREG($mode)) {1680return"file";1681}else{1682return"unknown";1683}1684}16851686# convert file mode in octal to file type description string1687sub file_type_long {1688my$mode=shift;16891690if($mode!~m/^[0-7]+$/) {1691return$mode;1692}else{1693$mode=oct$mode;1694}16951696if(S_ISGITLINK($mode)) {1697return"submodule";1698}elsif(S_ISDIR($mode& S_IFMT)) {1699return"directory";1700}elsif(S_ISLNK($mode)) {1701return"symlink";1702}elsif(S_ISREG($mode)) {1703if($mode& S_IXUSR) {1704return"executable";1705}else{1706return"file";1707};1708}else{1709return"unknown";1710}1711}171217131714## ----------------------------------------------------------------------1715## functions returning short HTML fragments, or transforming HTML fragments1716## which don't belong to other sections17171718# format line of commit message.1719sub format_log_line_html {1720my$line=shift;17211722$line= esc_html($line, -nbsp=>1);1723$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1724$cgi->a({-href => href(action=>"object", hash=>$1),1725-class=>"text"},$1);1726}eg;17271728return$line;1729}17301731# format marker of refs pointing to given object17321733# the destination action is chosen based on object type and current context:1734# - for annotated tags, we choose the tag view unless it's the current view1735# already, in which case we go to shortlog view1736# - for other refs, we keep the current view if we're in history, shortlog or1737# log view, and select shortlog otherwise1738sub format_ref_marker {1739my($refs,$id) =@_;1740my$markers='';17411742if(defined$refs->{$id}) {1743foreachmy$ref(@{$refs->{$id}}) {1744# this code exploits the fact that non-lightweight tags are the1745# only indirect objects, and that they are the only objects for which1746# we want to use tag instead of shortlog as action1747my($type,$name) =qw();1748my$indirect= ($ref=~s/\^\{\}$//);1749# e.g. tags/v2.6.11 or heads/next1750if($ref=~m!^(.*?)s?/(.*)$!) {1751$type=$1;1752$name=$2;1753}else{1754$type="ref";1755$name=$ref;1756}17571758my$class=$type;1759$class.=" indirect"if$indirect;17601761my$dest_action="shortlog";17621763if($indirect) {1764$dest_action="tag"unless$actioneq"tag";1765}elsif($action=~/^(history|(short)?log)$/) {1766$dest_action=$action;1767}17681769my$dest="";1770$dest.="refs/"unless$ref=~ m!^refs/!;1771$dest.=$ref;17721773my$link=$cgi->a({1774-href => href(1775 action=>$dest_action,1776 hash=>$dest1777)},$name);17781779$markers.=" <span class=\"$class\"title=\"$ref\">".1780$link."</span>";1781}1782}17831784if($markers) {1785return' <span class="refs">'.$markers.'</span>';1786}else{1787return"";1788}1789}17901791# format, perhaps shortened and with markers, title line1792sub format_subject_html {1793my($long,$short,$href,$extra) =@_;1794$extra=''unlessdefined($extra);17951796if(length($short) <length($long)) {1797$long=~s/[[:cntrl:]]/?/g;1798return$cgi->a({-href =>$href, -class=>"list subject",1799-title => to_utf8($long)},1800 esc_html($short)) .$extra;1801}else{1802return$cgi->a({-href =>$href, -class=>"list subject"},1803 esc_html($long)) .$extra;1804}1805}18061807# Rather than recomputing the url for an email multiple times, we cache it1808# after the first hit. This gives a visible benefit in views where the avatar1809# for the same email is used repeatedly (e.g. shortlog).1810# The cache is shared by all avatar engines (currently gravatar only), which1811# are free to use it as preferred. Since only one avatar engine is used for any1812# given page, there's no risk for cache conflicts.1813our%avatar_cache= ();18141815# Compute the picon url for a given email, by using the picon search service over at1816# http://www.cs.indiana.edu/picons/search.html1817sub picon_url {1818my$email=lc shift;1819if(!$avatar_cache{$email}) {1820my($user,$domain) =split('@',$email);1821$avatar_cache{$email} =1822"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".1823"$domain/$user/".1824"users+domains+unknown/up/single";1825}1826return$avatar_cache{$email};1827}18281829# Compute the gravatar url for a given email, if it's not in the cache already.1830# Gravatar stores only the part of the URL before the size, since that's the1831# one computationally more expensive. This also allows reuse of the cache for1832# different sizes (for this particular engine).1833sub gravatar_url {1834my$email=lc shift;1835my$size=shift;1836$avatar_cache{$email} ||=1837"http://www.gravatar.com/avatar/".1838 Digest::MD5::md5_hex($email) ."?s=";1839return$avatar_cache{$email} .$size;1840}18411842# Insert an avatar for the given $email at the given $size if the feature1843# is enabled.1844sub git_get_avatar {1845my($email,%opts) =@_;1846my$pre_white= ($opts{-pad_before} ?" ":"");1847my$post_white= ($opts{-pad_after} ?" ":"");1848$opts{-size} ||='default';1849my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};1850my$url="";1851if($git_avatareq'gravatar') {1852$url= gravatar_url($email,$size);1853}elsif($git_avatareq'picon') {1854$url= picon_url($email);1855}1856# Other providers can be added by extending the if chain, defining $url1857# as needed. If no variant puts something in $url, we assume avatars1858# are completely disabled/unavailable.1859if($url) {1860return$pre_white.1861"<img width=\"$size\"".1862"class=\"avatar\"".1863"src=\"$url\"".1864"alt=\"\"".1865"/>".$post_white;1866}else{1867return"";1868}1869}18701871sub format_search_author {1872my($author,$searchtype,$displaytext) =@_;1873my$have_search= gitweb_check_feature('search');18741875if($have_search) {1876my$performed="";1877if($searchtypeeq'author') {1878$performed="authored";1879}elsif($searchtypeeq'committer') {1880$performed="committed";1881}18821883return$cgi->a({-href => href(action=>"search", hash=>$hash,1884 searchtext=>$author,1885 searchtype=>$searchtype),class=>"list",1886 title=>"Search for commits$performedby$author"},1887$displaytext);18881889}else{1890return$displaytext;1891}1892}18931894# format the author name of the given commit with the given tag1895# the author name is chopped and escaped according to the other1896# optional parameters (see chop_str).1897sub format_author_html {1898my$tag=shift;1899my$co=shift;1900my$author= chop_and_escape_str($co->{'author_name'},@_);1901return"<$tagclass=\"author\">".1902 format_search_author($co->{'author_name'},"author",1903 git_get_avatar($co->{'author_email'}, -pad_after =>1) .1904$author) .1905"</$tag>";1906}19071908# format git diff header line, i.e. "diff --(git|combined|cc) ..."1909sub format_git_diff_header_line {1910my$line=shift;1911my$diffinfo=shift;1912my($from,$to) =@_;19131914if($diffinfo->{'nparents'}) {1915# combined diff1916$line=~s!^(diff (.*?) )"?.*$!$1!;1917if($to->{'href'}) {1918$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1919 esc_path($to->{'file'}));1920}else{# file was deleted (no href)1921$line.= esc_path($to->{'file'});1922}1923}else{1924# "ordinary" diff1925$line=~s!^(diff (.*?) )"?a/.*$!$1!;1926if($from->{'href'}) {1927$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1928'a/'. esc_path($from->{'file'}));1929}else{# file was added (no href)1930$line.='a/'. esc_path($from->{'file'});1931}1932$line.=' ';1933if($to->{'href'}) {1934$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1935'b/'. esc_path($to->{'file'}));1936}else{# file was deleted1937$line.='b/'. esc_path($to->{'file'});1938}1939}19401941return"<div class=\"diff header\">$line</div>\n";1942}19431944# format extended diff header line, before patch itself1945sub format_extended_diff_header_line {1946my$line=shift;1947my$diffinfo=shift;1948my($from,$to) =@_;19491950# match <path>1951if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1952$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1953 esc_path($from->{'file'}));1954}1955if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1956$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1957 esc_path($to->{'file'}));1958}1959# match single <mode>1960if($line=~m/\s(\d{6})$/) {1961$line.='<span class="info"> ('.1962 file_type_long($1) .1963')</span>';1964}1965# match <hash>1966if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1967# can match only for combined diff1968$line='index ';1969for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1970if($from->{'href'}[$i]) {1971$line.=$cgi->a({-href=>$from->{'href'}[$i],1972-class=>"hash"},1973substr($diffinfo->{'from_id'}[$i],0,7));1974}else{1975$line.='0' x 7;1976}1977# separator1978$line.=','if($i<$diffinfo->{'nparents'} -1);1979}1980$line.='..';1981if($to->{'href'}) {1982$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1983substr($diffinfo->{'to_id'},0,7));1984}else{1985$line.='0' x 7;1986}19871988}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1989# can match only for ordinary diff1990my($from_link,$to_link);1991if($from->{'href'}) {1992$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1993substr($diffinfo->{'from_id'},0,7));1994}else{1995$from_link='0' x 7;1996}1997if($to->{'href'}) {1998$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1999substr($diffinfo->{'to_id'},0,7));2000}else{2001$to_link='0' x 7;2002}2003my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});2004$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;2005}20062007return$line."<br/>\n";2008}20092010# format from-file/to-file diff header2011sub format_diff_from_to_header {2012my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;2013my$line;2014my$result='';20152016$line=$from_line;2017#assert($line =~ m/^---/) if DEBUG;2018# no extra formatting for "^--- /dev/null"2019if(!$diffinfo->{'nparents'}) {2020# ordinary (single parent) diff2021if($line=~m!^--- "?a/!) {2022if($from->{'href'}) {2023$line='--- a/'.2024$cgi->a({-href=>$from->{'href'}, -class=>"path"},2025 esc_path($from->{'file'}));2026}else{2027$line='--- a/'.2028 esc_path($from->{'file'});2029}2030}2031$result.= qq!<div class="diff from_file">$line</div>\n!;20322033}else{2034# combined diff (merge commit)2035for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2036if($from->{'href'}[$i]) {2037$line='--- '.2038$cgi->a({-href=>href(action=>"blobdiff",2039 hash_parent=>$diffinfo->{'from_id'}[$i],2040 hash_parent_base=>$parents[$i],2041 file_parent=>$from->{'file'}[$i],2042 hash=>$diffinfo->{'to_id'},2043 hash_base=>$hash,2044 file_name=>$to->{'file'}),2045-class=>"path",2046-title=>"diff". ($i+1)},2047$i+1) .2048'/'.2049$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},2050 esc_path($from->{'file'}[$i]));2051}else{2052$line='--- /dev/null';2053}2054$result.= qq!<div class="diff from_file">$line</div>\n!;2055}2056}20572058$line=$to_line;2059#assert($line =~ m/^\+\+\+/) if DEBUG;2060# no extra formatting for "^+++ /dev/null"2061if($line=~m!^\+\+\+ "?b/!) {2062if($to->{'href'}) {2063$line='+++ b/'.2064$cgi->a({-href=>$to->{'href'}, -class=>"path"},2065 esc_path($to->{'file'}));2066}else{2067$line='+++ b/'.2068 esc_path($to->{'file'});2069}2070}2071$result.= qq!<div class="diff to_file">$line</div>\n!;20722073return$result;2074}20752076# create note for patch simplified by combined diff2077sub format_diff_cc_simplified {2078my($diffinfo,@parents) =@_;2079my$result='';20802081$result.="<div class=\"diff header\">".2082"diff --cc ";2083if(!is_deleted($diffinfo)) {2084$result.=$cgi->a({-href => href(action=>"blob",2085 hash_base=>$hash,2086 hash=>$diffinfo->{'to_id'},2087 file_name=>$diffinfo->{'to_file'}),2088-class=>"path"},2089 esc_path($diffinfo->{'to_file'}));2090}else{2091$result.= esc_path($diffinfo->{'to_file'});2092}2093$result.="</div>\n".# class="diff header"2094"<div class=\"diff nodifferences\">".2095"Simple merge".2096"</div>\n";# class="diff nodifferences"20972098return$result;2099}21002101# format patch (diff) line (not to be used for diff headers)2102sub format_diff_line {2103my$line=shift;2104my($from,$to) =@_;2105my$diff_class="";21062107chomp$line;21082109if($from&&$to&&ref($from->{'href'})eq"ARRAY") {2110# combined diff2111my$prefix=substr($line,0,scalar@{$from->{'href'}});2112if($line=~m/^\@{3}/) {2113$diff_class=" chunk_header";2114}elsif($line=~m/^\\/) {2115$diff_class=" incomplete";2116}elsif($prefix=~tr/+/+/) {2117$diff_class=" add";2118}elsif($prefix=~tr/-/-/) {2119$diff_class=" rem";2120}2121}else{2122# assume ordinary diff2123my$char=substr($line,0,1);2124if($chareq'+') {2125$diff_class=" add";2126}elsif($chareq'-') {2127$diff_class=" rem";2128}elsif($chareq'@') {2129$diff_class=" chunk_header";2130}elsif($chareq"\\") {2131$diff_class=" incomplete";2132}2133}2134$line= untabify($line);2135if($from&&$to&&$line=~m/^\@{2} /) {2136my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =2137$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;21382139$from_lines=0unlessdefined$from_lines;2140$to_lines=0unlessdefined$to_lines;21412142if($from->{'href'}) {2143$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",2144-class=>"list"},$from_text);2145}2146if($to->{'href'}) {2147$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",2148-class=>"list"},$to_text);2149}2150$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".2151"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2152return"<div class=\"diff$diff_class\">$line</div>\n";2153}elsif($from&&$to&&$line=~m/^\@{3}/) {2154my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;2155my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);21562157@from_text=split(' ',$ranges);2158for(my$i=0;$i<@from_text; ++$i) {2159($from_start[$i],$from_nlines[$i]) =2160(split(',',substr($from_text[$i],1)),0);2161}21622163$to_text=pop@from_text;2164$to_start=pop@from_start;2165$to_nlines=pop@from_nlines;21662167$line="<span class=\"chunk_info\">$prefix";2168for(my$i=0;$i<@from_text; ++$i) {2169if($from->{'href'}[$i]) {2170$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",2171-class=>"list"},$from_text[$i]);2172}else{2173$line.=$from_text[$i];2174}2175$line.=" ";2176}2177if($to->{'href'}) {2178$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",2179-class=>"list"},$to_text);2180}else{2181$line.=$to_text;2182}2183$line.="$prefix</span>".2184"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2185return"<div class=\"diff$diff_class\">$line</div>\n";2186}2187return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";2188}21892190# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",2191# linked. Pass the hash of the tree/commit to snapshot.2192sub format_snapshot_links {2193my($hash) =@_;2194my$num_fmts=@snapshot_fmts;2195if($num_fmts>1) {2196# A parenthesized list of links bearing format names.2197# e.g. "snapshot (_tar.gz_ _zip_)"2198return"snapshot (".join(' ',map2199$cgi->a({2200-href => href(2201 action=>"snapshot",2202 hash=>$hash,2203 snapshot_format=>$_2204)2205},$known_snapshot_formats{$_}{'display'})2206,@snapshot_fmts) .")";2207}elsif($num_fmts==1) {2208# A single "snapshot" link whose tooltip bears the format name.2209# i.e. "_snapshot_"2210my($fmt) =@snapshot_fmts;2211return2212$cgi->a({2213-href => href(2214 action=>"snapshot",2215 hash=>$hash,2216 snapshot_format=>$fmt2217),2218-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"2219},"snapshot");2220}else{# $num_fmts == 02221returnundef;2222}2223}22242225## ......................................................................2226## functions returning values to be passed, perhaps after some2227## transformation, to other functions; e.g. returning arguments to href()22282229# returns hash to be passed to href to generate gitweb URL2230# in -title key it returns description of link2231sub get_feed_info {2232my$format=shift||'Atom';2233my%res= (action =>lc($format));22342235# feed links are possible only for project views2236return unless(defined$project);2237# some views should link to OPML, or to generic project feed,2238# or don't have specific feed yet (so they should use generic)2239return if($action=~/^(?:tags|heads|forks|tag|search)$/x);22402241my$branch;2242# branches refs uses 'refs/heads/' prefix (fullname) to differentiate2243# from tag links; this also makes possible to detect branch links2244if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||2245(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {2246$branch=$1;2247}2248# find log type for feed description (title)2249my$type='log';2250if(defined$file_name) {2251$type="history of$file_name";2252$type.="/"if($actioneq'tree');2253$type.=" on '$branch'"if(defined$branch);2254}else{2255$type="log of$branch"if(defined$branch);2256}22572258$res{-title} =$type;2259$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);2260$res{'file_name'} =$file_name;22612262return%res;2263}22642265## ----------------------------------------------------------------------2266## git utility subroutines, invoking git commands22672268# returns path to the core git executable and the --git-dir parameter as list2269sub git_cmd {2270$number_of_git_cmds++;2271return$GIT,'--git-dir='.$git_dir;2272}22732274# quote the given arguments for passing them to the shell2275# quote_command("command", "arg 1", "arg with ' and ! characters")2276# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2277# Try to avoid using this function wherever possible.2278sub quote_command {2279returnjoin(' ',2280map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2281}22822283# get HEAD ref of given project as hash2284sub git_get_head_hash {2285return git_get_full_hash(shift,'HEAD');2286}22872288sub git_get_full_hash {2289return git_get_hash(@_);2290}22912292sub git_get_short_hash {2293return git_get_hash(@_,'--short=7');2294}22952296sub git_get_hash {2297my($project,$hash,@options) =@_;2298my$o_git_dir=$git_dir;2299my$retval=undef;2300$git_dir="$projectroot/$project";2301if(open my$fd,'-|', git_cmd(),'rev-parse',2302'--verify','-q',@options,$hash) {2303$retval= <$fd>;2304chomp$retvalifdefined$retval;2305close$fd;2306}2307if(defined$o_git_dir) {2308$git_dir=$o_git_dir;2309}2310return$retval;2311}23122313# get type of given object2314sub git_get_type {2315my$hash=shift;23162317open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2318my$type= <$fd>;2319close$fdorreturn;2320chomp$type;2321return$type;2322}23232324# repository configuration2325our$config_file='';2326our%config;23272328# store multiple values for single key as anonymous array reference2329# single values stored directly in the hash, not as [ <value> ]2330sub hash_set_multi {2331my($hash,$key,$value) =@_;23322333if(!exists$hash->{$key}) {2334$hash->{$key} =$value;2335}elsif(!ref$hash->{$key}) {2336$hash->{$key} = [$hash->{$key},$value];2337}else{2338push@{$hash->{$key}},$value;2339}2340}23412342# return hash of git project configuration2343# optionally limited to some section, e.g. 'gitweb'2344sub git_parse_project_config {2345my$section_regexp=shift;2346my%config;23472348local$/="\0";23492350open my$fh,"-|", git_cmd(),"config",'-z','-l',2351orreturn;23522353while(my$keyval= <$fh>) {2354chomp$keyval;2355my($key,$value) =split(/\n/,$keyval,2);23562357 hash_set_multi(\%config,$key,$value)2358if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2359}2360close$fh;23612362return%config;2363}23642365# convert config value to boolean: 'true' or 'false'2366# no value, number > 0, 'true' and 'yes' values are true2367# rest of values are treated as false (never as error)2368sub config_to_bool {2369my$val=shift;23702371return1if!defined$val;# section.key23722373# strip leading and trailing whitespace2374$val=~s/^\s+//;2375$val=~s/\s+$//;23762377return(($val=~/^\d+$/&&$val) ||# section.key = 12378($val=~/^(?:true|yes)$/i));# section.key = true2379}23802381# convert config value to simple decimal number2382# an optional value suffix of 'k', 'm', or 'g' will cause the value2383# to be multiplied by 1024, 1048576, or 10737418242384sub config_to_int {2385my$val=shift;23862387# strip leading and trailing whitespace2388$val=~s/^\s+//;2389$val=~s/\s+$//;23902391if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2392$unit=lc($unit);2393# unknown unit is treated as 12394return$num* ($uniteq'g'?1073741824:2395$uniteq'm'?1048576:2396$uniteq'k'?1024:1);2397}2398return$val;2399}24002401# convert config value to array reference, if needed2402sub config_to_multi {2403my$val=shift;24042405returnref($val) ?$val: (defined($val) ? [$val] : []);2406}24072408sub git_get_project_config {2409my($key,$type) =@_;24102411return unlessdefined$git_dir;24122413# key sanity check2414return unless($key);2415$key=~s/^gitweb\.//;2416return if($key=~m/\W/);24172418# type sanity check2419if(defined$type) {2420$type=~s/^--//;2421$type=undef2422unless($typeeq'bool'||$typeeq'int');2423}24242425# get config2426if(!defined$config_file||2427$config_filene"$git_dir/config") {2428%config= git_parse_project_config('gitweb');2429$config_file="$git_dir/config";2430}24312432# check if config variable (key) exists2433return unlessexists$config{"gitweb.$key"};24342435# ensure given type2436if(!defined$type) {2437return$config{"gitweb.$key"};2438}elsif($typeeq'bool') {2439# backward compatibility: 'git config --bool' returns true/false2440return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2441}elsif($typeeq'int') {2442return config_to_int($config{"gitweb.$key"});2443}2444return$config{"gitweb.$key"};2445}24462447# get hash of given path at given ref2448sub git_get_hash_by_path {2449my$base=shift;2450my$path=shift||returnundef;2451my$type=shift;24522453$path=~ s,/+$,,;24542455open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2456or die_error(500,"Open git-ls-tree failed");2457my$line= <$fd>;2458close$fdorreturnundef;24592460if(!defined$line) {2461# there is no tree or hash given by $path at $base2462returnundef;2463}24642465#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2466$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2467if(defined$type&&$typene$2) {2468# type doesn't match2469returnundef;2470}2471return$3;2472}24732474# get path of entry with given hash at given tree-ish (ref)2475# used to get 'from' filename for combined diff (merge commit) for renames2476sub git_get_path_by_hash {2477my$base=shift||return;2478my$hash=shift||return;24792480local$/="\0";24812482open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2483orreturnundef;2484while(my$line= <$fd>) {2485chomp$line;24862487#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2488#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2489if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2490close$fd;2491return$1;2492}2493}2494close$fd;2495returnundef;2496}24972498## ......................................................................2499## git utility functions, directly accessing git repository25002501sub git_get_project_description {2502my$path=shift;25032504$git_dir="$projectroot/$path";2505open my$fd,'<',"$git_dir/description"2506orreturn git_get_project_config('description');2507my$descr= <$fd>;2508close$fd;2509if(defined$descr) {2510chomp$descr;2511}2512return$descr;2513}25142515sub git_get_project_ctags {2516my$path=shift;2517my$ctags= {};25182519$git_dir="$projectroot/$path";2520opendir my$dh,"$git_dir/ctags"2521orreturn$ctags;2522foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2523open my$ct,'<',$_ornext;2524my$val= <$ct>;2525chomp$val;2526close$ct;2527my$ctag=$_;$ctag=~ s#.*/##;2528$ctags->{$ctag} =$val;2529}2530closedir$dh;2531$ctags;2532}25332534sub git_populate_project_tagcloud {2535my$ctags=shift;25362537# First, merge different-cased tags; tags vote on casing2538my%ctags_lc;2539foreach(keys%$ctags) {2540$ctags_lc{lc$_}->{count} +=$ctags->{$_};2541if(not$ctags_lc{lc$_}->{topcount}2542or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2543$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2544$ctags_lc{lc$_}->{topname} =$_;2545}2546}25472548my$cloud;2549if(eval{require HTML::TagCloud;1; }) {2550$cloud= HTML::TagCloud->new;2551foreach(sort keys%ctags_lc) {2552# Pad the title with spaces so that the cloud looks2553# less crammed.2554my$title=$ctags_lc{$_}->{topname};2555$title=~s/ / /g;2556$title=~s/^/ /g;2557$title=~s/$/ /g;2558$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2559}2560}else{2561$cloud= \%ctags_lc;2562}2563$cloud;2564}25652566sub git_show_project_tagcloud {2567my($cloud,$count) =@_;2568print STDERR ref($cloud)."..\n";2569if(ref$cloudeq'HTML::TagCloud') {2570return$cloud->html_and_css($count);2571}else{2572my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2573return'<p align="center">'.join(', ',map{2574"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"2575}splice(@tags,0,$count)) .'</p>';2576}2577}25782579sub git_get_project_url_list {2580my$path=shift;25812582$git_dir="$projectroot/$path";2583open my$fd,'<',"$git_dir/cloneurl"2584orreturnwantarray?2585@{ config_to_multi(git_get_project_config('url')) } :2586 config_to_multi(git_get_project_config('url'));2587my@git_project_url_list=map{chomp;$_} <$fd>;2588close$fd;25892590returnwantarray?@git_project_url_list: \@git_project_url_list;2591}25922593sub git_get_projects_list {2594my($filter) =@_;2595my@list;25962597$filter||='';2598$filter=~s/\.git$//;25992600my$check_forks= gitweb_check_feature('forks');26012602if(-d $projects_list) {2603# search in directory2604my$dir=$projects_list. ($filter?"/$filter":'');2605# remove the trailing "/"2606$dir=~s!/+$!!;2607my$pfxlen=length("$dir");2608my$pfxdepth= ($dir=~tr!/!!);26092610 File::Find::find({2611 follow_fast =>1,# follow symbolic links2612 follow_skip =>2,# ignore duplicates2613 dangling_symlinks =>0,# ignore dangling symlinks, silently2614 wanted =>sub{2615# global variables2616our$project_maxdepth;2617our$projectroot;2618# skip project-list toplevel, if we get it.2619return if(m!^[/.]$!);2620# only directories can be git repositories2621return unless(-d $_);2622# don't traverse too deep (Find is super slow on os x)2623if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2624$File::Find::prune =1;2625return;2626}26272628my$subdir=substr($File::Find::name,$pfxlen+1);2629# we check related file in $projectroot2630my$path= ($filter?"$filter/":'') .$subdir;2631if(check_export_ok("$projectroot/$path")) {2632push@list, { path =>$path};2633$File::Find::prune =1;2634}2635},2636},"$dir");26372638}elsif(-f $projects_list) {2639# read from file(url-encoded):2640# 'git%2Fgit.git Linus+Torvalds'2641# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2642# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2643my%paths;2644open my$fd,'<',$projects_listorreturn;2645 PROJECT:2646while(my$line= <$fd>) {2647chomp$line;2648my($path,$owner) =split' ',$line;2649$path= unescape($path);2650$owner= unescape($owner);2651if(!defined$path) {2652next;2653}2654if($filterne'') {2655# looking for forks;2656my$pfx=substr($path,0,length($filter));2657if($pfxne$filter) {2658next PROJECT;2659}2660my$sfx=substr($path,length($filter));2661if($sfx!~/^\/.*\.git$/) {2662next PROJECT;2663}2664}elsif($check_forks) {2665 PATH:2666foreachmy$filter(keys%paths) {2667# looking for forks;2668my$pfx=substr($path,0,length($filter));2669if($pfxne$filter) {2670next PATH;2671}2672my$sfx=substr($path,length($filter));2673if($sfx!~/^\/.*\.git$/) {2674next PATH;2675}2676# is a fork, don't include it in2677# the list2678next PROJECT;2679}2680}2681if(check_export_ok("$projectroot/$path")) {2682my$pr= {2683 path =>$path,2684 owner => to_utf8($owner),2685};2686push@list,$pr;2687(my$forks_path=$path) =~s/\.git$//;2688$paths{$forks_path}++;2689}2690}2691close$fd;2692}2693return@list;2694}26952696our$gitweb_project_owner=undef;2697sub git_get_project_list_from_file {26982699return if(defined$gitweb_project_owner);27002701$gitweb_project_owner= {};2702# read from file (url-encoded):2703# 'git%2Fgit.git Linus+Torvalds'2704# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2705# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2706if(-f $projects_list) {2707open(my$fd,'<',$projects_list);2708while(my$line= <$fd>) {2709chomp$line;2710my($pr,$ow) =split' ',$line;2711$pr= unescape($pr);2712$ow= unescape($ow);2713$gitweb_project_owner->{$pr} = to_utf8($ow);2714}2715close$fd;2716}2717}27182719sub git_get_project_owner {2720my$project=shift;2721my$owner;27222723returnundefunless$project;2724$git_dir="$projectroot/$project";27252726if(!defined$gitweb_project_owner) {2727 git_get_project_list_from_file();2728}27292730if(exists$gitweb_project_owner->{$project}) {2731$owner=$gitweb_project_owner->{$project};2732}2733if(!defined$owner){2734$owner= git_get_project_config('owner');2735}2736if(!defined$owner) {2737$owner= get_file_owner("$git_dir");2738}27392740return$owner;2741}27422743sub git_get_last_activity {2744my($path) =@_;2745my$fd;27462747$git_dir="$projectroot/$path";2748open($fd,"-|", git_cmd(),'for-each-ref',2749'--format=%(committer)',2750'--sort=-committerdate',2751'--count=1',2752'refs/heads')orreturn;2753my$most_recent= <$fd>;2754close$fdorreturn;2755if(defined$most_recent&&2756$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2757my$timestamp=$1;2758my$age=time-$timestamp;2759return($age, age_string($age));2760}2761return(undef,undef);2762}27632764sub git_get_references {2765my$type=shift||"";2766my%refs;2767# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112768# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2769open my$fd,"-|", git_cmd(),"show-ref","--dereference",2770($type? ("--","refs/$type") : ())# use -- <pattern> if $type2771orreturn;27722773while(my$line= <$fd>) {2774chomp$line;2775if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2776if(defined$refs{$1}) {2777push@{$refs{$1}},$2;2778}else{2779$refs{$1} = [$2];2780}2781}2782}2783close$fdorreturn;2784return \%refs;2785}27862787sub git_get_rev_name_tags {2788my$hash=shift||returnundef;27892790open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2791orreturn;2792my$name_rev= <$fd>;2793close$fd;27942795if($name_rev=~ m|^$hash tags/(.*)$|) {2796return$1;2797}else{2798# catches also '$hash undefined' output2799returnundef;2800}2801}28022803## ----------------------------------------------------------------------2804## parse to hash functions28052806sub parse_date {2807my$epoch=shift;2808my$tz=shift||"-0000";28092810my%date;2811my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2812my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2813my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2814$date{'hour'} =$hour;2815$date{'minute'} =$min;2816$date{'mday'} =$mday;2817$date{'day'} =$days[$wday];2818$date{'month'} =$months[$mon];2819$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2820$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2821$date{'mday-time'} =sprintf"%d%s%02d:%02d",2822$mday,$months[$mon],$hour,$min;2823$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",28241900+$year,1+$mon,$mday,$hour,$min,$sec;28252826$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2827my$local=$epoch+ ((int$1+ ($2/60)) *3600);2828($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2829$date{'hour_local'} =$hour;2830$date{'minute_local'} =$min;2831$date{'tz_local'} =$tz;2832$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",28331900+$year,$mon+1,$mday,2834$hour,$min,$sec,$tz);2835return%date;2836}28372838sub parse_tag {2839my$tag_id=shift;2840my%tag;2841my@comment;28422843open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2844$tag{'id'} =$tag_id;2845while(my$line= <$fd>) {2846chomp$line;2847if($line=~m/^object ([0-9a-fA-F]{40})$/) {2848$tag{'object'} =$1;2849}elsif($line=~m/^type (.+)$/) {2850$tag{'type'} =$1;2851}elsif($line=~m/^tag (.+)$/) {2852$tag{'name'} =$1;2853}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2854$tag{'author'} =$1;2855$tag{'author_epoch'} =$2;2856$tag{'author_tz'} =$3;2857if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {2858$tag{'author_name'} =$1;2859$tag{'author_email'} =$2;2860}else{2861$tag{'author_name'} =$tag{'author'};2862}2863}elsif($line=~m/--BEGIN/) {2864push@comment,$line;2865last;2866}elsif($lineeq"") {2867last;2868}2869}2870push@comment, <$fd>;2871$tag{'comment'} = \@comment;2872close$fdorreturn;2873if(!defined$tag{'name'}) {2874return2875};2876return%tag2877}28782879sub parse_commit_text {2880my($commit_text,$withparents) =@_;2881my@commit_lines=split'\n',$commit_text;2882my%co;28832884pop@commit_lines;# Remove '\0'28852886if(!@commit_lines) {2887return;2888}28892890my$header=shift@commit_lines;2891if($header!~m/^[0-9a-fA-F]{40}/) {2892return;2893}2894($co{'id'},my@parents) =split' ',$header;2895while(my$line=shift@commit_lines) {2896last if$lineeq"\n";2897if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2898$co{'tree'} =$1;2899}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2900push@parents,$1;2901}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2902$co{'author'} = to_utf8($1);2903$co{'author_epoch'} =$2;2904$co{'author_tz'} =$3;2905if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2906$co{'author_name'} =$1;2907$co{'author_email'} =$2;2908}else{2909$co{'author_name'} =$co{'author'};2910}2911}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2912$co{'committer'} = to_utf8($1);2913$co{'committer_epoch'} =$2;2914$co{'committer_tz'} =$3;2915if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2916$co{'committer_name'} =$1;2917$co{'committer_email'} =$2;2918}else{2919$co{'committer_name'} =$co{'committer'};2920}2921}2922}2923if(!defined$co{'tree'}) {2924return;2925};2926$co{'parents'} = \@parents;2927$co{'parent'} =$parents[0];29282929foreachmy$title(@commit_lines) {2930$title=~s/^ //;2931if($titlene"") {2932$co{'title'} = chop_str($title,80,5);2933# remove leading stuff of merges to make the interesting part visible2934if(length($title) >50) {2935$title=~s/^Automatic //;2936$title=~s/^merge (of|with) /Merge ... /i;2937if(length($title) >50) {2938$title=~s/(http|rsync):\/\///;2939}2940if(length($title) >50) {2941$title=~s/(master|www|rsync)\.//;2942}2943if(length($title) >50) {2944$title=~s/kernel.org:?//;2945}2946if(length($title) >50) {2947$title=~s/\/pub\/scm//;2948}2949}2950$co{'title_short'} = chop_str($title,50,5);2951last;2952}2953}2954if(!defined$co{'title'} ||$co{'title'}eq"") {2955$co{'title'} =$co{'title_short'} ='(no commit message)';2956}2957# remove added spaces2958foreachmy$line(@commit_lines) {2959$line=~s/^ //;2960}2961$co{'comment'} = \@commit_lines;29622963my$age=time-$co{'committer_epoch'};2964$co{'age'} =$age;2965$co{'age_string'} = age_string($age);2966my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2967if($age>60*60*24*7*2) {2968$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2969$co{'age_string_age'} =$co{'age_string'};2970}else{2971$co{'age_string_date'} =$co{'age_string'};2972$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2973}2974return%co;2975}29762977sub parse_commit {2978my($commit_id) =@_;2979my%co;29802981local$/="\0";29822983open my$fd,"-|", git_cmd(),"rev-list",2984"--parents",2985"--header",2986"--max-count=1",2987$commit_id,2988"--",2989or die_error(500,"Open git-rev-list failed");2990%co= parse_commit_text(<$fd>,1);2991close$fd;29922993return%co;2994}29952996sub parse_commits {2997my($commit_id,$maxcount,$skip,$filename,@args) =@_;2998my@cos;29993000$maxcount||=1;3001$skip||=0;30023003local$/="\0";30043005open my$fd,"-|", git_cmd(),"rev-list",3006"--header",3007@args,3008("--max-count=".$maxcount),3009("--skip=".$skip),3010@extra_options,3011$commit_id,3012"--",3013($filename? ($filename) : ())3014or die_error(500,"Open git-rev-list failed");3015while(my$line= <$fd>) {3016my%co= parse_commit_text($line);3017push@cos, \%co;3018}3019close$fd;30203021returnwantarray?@cos: \@cos;3022}30233024# parse line of git-diff-tree "raw" output3025sub parse_difftree_raw_line {3026my$line=shift;3027my%res;30283029# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'3030# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'3031if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {3032$res{'from_mode'} =$1;3033$res{'to_mode'} =$2;3034$res{'from_id'} =$3;3035$res{'to_id'} =$4;3036$res{'status'} =$5;3037$res{'similarity'} =$6;3038if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied3039($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);3040}else{3041$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);3042}3043}3044# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'3045# combined diff (for merge commit)3046elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {3047$res{'nparents'} =length($1);3048$res{'from_mode'} = [split(' ',$2) ];3049$res{'to_mode'} =pop@{$res{'from_mode'}};3050$res{'from_id'} = [split(' ',$3) ];3051$res{'to_id'} =pop@{$res{'from_id'}};3052$res{'status'} = [split('',$4) ];3053$res{'to_file'} = unquote($5);3054}3055# 'c512b523472485aef4fff9e57b229d9d243c967f'3056elsif($line=~m/^([0-9a-fA-F]{40})$/) {3057$res{'commit'} =$1;3058}30593060returnwantarray?%res: \%res;3061}30623063# wrapper: return parsed line of git-diff-tree "raw" output3064# (the argument might be raw line, or parsed info)3065sub parsed_difftree_line {3066my$line_or_ref=shift;30673068if(ref($line_or_ref)eq"HASH") {3069# pre-parsed (or generated by hand)3070return$line_or_ref;3071}else{3072return parse_difftree_raw_line($line_or_ref);3073}3074}30753076# parse line of git-ls-tree output3077sub parse_ls_tree_line {3078my$line=shift;3079my%opts=@_;3080my%res;30813082if($opts{'-l'}) {3083#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'3084$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;30853086$res{'mode'} =$1;3087$res{'type'} =$2;3088$res{'hash'} =$3;3089$res{'size'} =$4;3090if($opts{'-z'}) {3091$res{'name'} =$5;3092}else{3093$res{'name'} = unquote($5);3094}3095}else{3096#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'3097$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;30983099$res{'mode'} =$1;3100$res{'type'} =$2;3101$res{'hash'} =$3;3102if($opts{'-z'}) {3103$res{'name'} =$4;3104}else{3105$res{'name'} = unquote($4);3106}3107}31083109returnwantarray?%res: \%res;3110}31113112# generates _two_ hashes, references to which are passed as 2 and 3 argument3113sub parse_from_to_diffinfo {3114my($diffinfo,$from,$to,@parents) =@_;31153116if($diffinfo->{'nparents'}) {3117# combined diff3118$from->{'file'} = [];3119$from->{'href'} = [];3120 fill_from_file_info($diffinfo,@parents)3121unlessexists$diffinfo->{'from_file'};3122for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {3123$from->{'file'}[$i] =3124defined$diffinfo->{'from_file'}[$i] ?3125$diffinfo->{'from_file'}[$i] :3126$diffinfo->{'to_file'};3127if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file3128$from->{'href'}[$i] = href(action=>"blob",3129 hash_base=>$parents[$i],3130 hash=>$diffinfo->{'from_id'}[$i],3131 file_name=>$from->{'file'}[$i]);3132}else{3133$from->{'href'}[$i] =undef;3134}3135}3136}else{3137# ordinary (not combined) diff3138$from->{'file'} =$diffinfo->{'from_file'};3139if($diffinfo->{'status'}ne"A") {# not new (added) file3140$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,3141 hash=>$diffinfo->{'from_id'},3142 file_name=>$from->{'file'});3143}else{3144delete$from->{'href'};3145}3146}31473148$to->{'file'} =$diffinfo->{'to_file'};3149if(!is_deleted($diffinfo)) {# file exists in result3150$to->{'href'} = href(action=>"blob", hash_base=>$hash,3151 hash=>$diffinfo->{'to_id'},3152 file_name=>$to->{'file'});3153}else{3154delete$to->{'href'};3155}3156}31573158## ......................................................................3159## parse to array of hashes functions31603161sub git_get_heads_list {3162my$limit=shift;3163my@headslist;31643165open my$fd,'-|', git_cmd(),'for-each-ref',3166($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',3167'--format=%(objectname) %(refname) %(subject)%00%(committer)',3168'refs/heads'3169orreturn;3170while(my$line= <$fd>) {3171my%ref_item;31723173chomp$line;3174my($refinfo,$committerinfo) =split(/\0/,$line);3175my($hash,$name,$title) =split(' ',$refinfo,3);3176my($committer,$epoch,$tz) =3177($committerinfo=~/^(.*) ([0-9]+) (.*)$/);3178$ref_item{'fullname'} =$name;3179$name=~s!^refs/heads/!!;31803181$ref_item{'name'} =$name;3182$ref_item{'id'} =$hash;3183$ref_item{'title'} =$title||'(no commit message)';3184$ref_item{'epoch'} =$epoch;3185if($epoch) {3186$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3187}else{3188$ref_item{'age'} ="unknown";3189}31903191push@headslist, \%ref_item;3192}3193close$fd;31943195returnwantarray?@headslist: \@headslist;3196}31973198sub git_get_tags_list {3199my$limit=shift;3200my@tagslist;32013202open my$fd,'-|', git_cmd(),'for-each-ref',3203($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',3204'--format=%(objectname) %(objecttype) %(refname) '.3205'%(*objectname) %(*objecttype) %(subject)%00%(creator)',3206'refs/tags'3207orreturn;3208while(my$line= <$fd>) {3209my%ref_item;32103211chomp$line;3212my($refinfo,$creatorinfo) =split(/\0/,$line);3213my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);3214my($creator,$epoch,$tz) =3215($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);3216$ref_item{'fullname'} =$name;3217$name=~s!^refs/tags/!!;32183219$ref_item{'type'} =$type;3220$ref_item{'id'} =$id;3221$ref_item{'name'} =$name;3222if($typeeq"tag") {3223$ref_item{'subject'} =$title;3224$ref_item{'reftype'} =$reftype;3225$ref_item{'refid'} =$refid;3226}else{3227$ref_item{'reftype'} =$type;3228$ref_item{'refid'} =$id;3229}32303231if($typeeq"tag"||$typeeq"commit") {3232$ref_item{'epoch'} =$epoch;3233if($epoch) {3234$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3235}else{3236$ref_item{'age'} ="unknown";3237}3238}32393240push@tagslist, \%ref_item;3241}3242close$fd;32433244returnwantarray?@tagslist: \@tagslist;3245}32463247## ----------------------------------------------------------------------3248## filesystem-related functions32493250sub get_file_owner {3251my$path=shift;32523253my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);3254my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);3255if(!defined$gcos) {3256returnundef;3257}3258my$owner=$gcos;3259$owner=~s/[,;].*$//;3260return to_utf8($owner);3261}32623263# assume that file exists3264sub insert_file {3265my$filename=shift;32663267open my$fd,'<',$filename;3268print map{ to_utf8($_) } <$fd>;3269close$fd;3270}32713272## ......................................................................3273## mimetype related functions32743275sub mimetype_guess_file {3276my$filename=shift;3277my$mimemap=shift;3278-r $mimemaporreturnundef;32793280my%mimemap;3281open(my$mh,'<',$mimemap)orreturnundef;3282while(<$mh>) {3283next ifm/^#/;# skip comments3284my($mimetype,$exts) =split(/\t+/);3285if(defined$exts) {3286my@exts=split(/\s+/,$exts);3287foreachmy$ext(@exts) {3288$mimemap{$ext} =$mimetype;3289}3290}3291}3292close($mh);32933294$filename=~/\.([^.]*)$/;3295return$mimemap{$1};3296}32973298sub mimetype_guess {3299my$filename=shift;3300my$mime;3301$filename=~/\./orreturnundef;33023303if($mimetypes_file) {3304my$file=$mimetypes_file;3305if($file!~m!^/!) {# if it is relative path3306# it is relative to project3307$file="$projectroot/$project/$file";3308}3309$mime= mimetype_guess_file($filename,$file);3310}3311$mime||= mimetype_guess_file($filename,'/etc/mime.types');3312return$mime;3313}33143315sub blob_mimetype {3316my$fd=shift;3317my$filename=shift;33183319if($filename) {3320my$mime= mimetype_guess($filename);3321$mimeandreturn$mime;3322}33233324# just in case3325return$default_blob_plain_mimetypeunless$fd;33263327if(-T $fd) {3328return'text/plain';3329}elsif(!$filename) {3330return'application/octet-stream';3331}elsif($filename=~m/\.png$/i) {3332return'image/png';3333}elsif($filename=~m/\.gif$/i) {3334return'image/gif';3335}elsif($filename=~m/\.jpe?g$/i) {3336return'image/jpeg';3337}else{3338return'application/octet-stream';3339}3340}33413342sub blob_contenttype {3343my($fd,$file_name,$type) =@_;33443345$type||= blob_mimetype($fd,$file_name);3346if($typeeq'text/plain'&&defined$default_text_plain_charset) {3347$type.="; charset=$default_text_plain_charset";3348}33493350return$type;3351}33523353# guess file syntax for syntax highlighting; return undef if no highlighting3354# the name of syntax can (in the future) depend on syntax highlighter used3355sub guess_file_syntax {3356my($highlight,$mimetype,$file_name) =@_;3357returnundefunless($highlight&&defined$file_name);3358my$basename= basename($file_name,'.in');3359return$highlight_basename{$basename}3360ifexists$highlight_basename{$basename};33613362$basename=~/\.([^.]*)$/;3363my$ext=$1orreturnundef;3364return$highlight_ext{$ext}3365ifexists$highlight_ext{$ext};33663367returnundef;3368}33693370# run highlighter and return FD of its output,3371# or return original FD if no highlighting3372sub run_highlighter {3373my($fd,$highlight,$syntax) =@_;3374return$fdunless($highlight&&defined$syntax);33753376close$fd3377or die_error(404,"Reading blob failed");3378open$fd, quote_command(git_cmd(),"cat-file","blob",$hash)." | ".3379"highlight --xhtml --fragment --syntax$syntax|"3380or die_error(500,"Couldn't open file or run syntax highlighter");3381return$fd;3382}33833384## ======================================================================3385## functions printing HTML: header, footer, error page33863387sub get_page_title {3388my$title= to_utf8($site_name);33893390return$titleunless(defined$project);3391$title.=" - ". to_utf8($project);33923393return$titleunless(defined$action);3394$title.="/$action";# $action is US-ASCII (7bit ASCII)33953396return$titleunless(defined$file_name);3397$title.=" - ". esc_path($file_name);3398if($actioneq"tree"&&$file_name!~ m|/$|) {3399$title.="/";3400}34013402return$title;3403}34043405sub git_header_html {3406my$status=shift||"200 OK";3407my$expires=shift;3408my%opts=@_;34093410my$title= get_page_title();3411my$content_type;3412# require explicit support from the UA if we are to send the page as3413# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3414# we have to do this because MSIE sometimes globs '*/*', pretending to3415# support xhtml+xml but choking when it gets what it asked for.3416if(defined$cgi->http('HTTP_ACCEPT') &&3417$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3418$cgi->Accept('application/xhtml+xml') !=0) {3419$content_type='application/xhtml+xml';3420}else{3421$content_type='text/html';3422}3423print$cgi->header(-type=>$content_type, -charset =>'utf-8',3424-status=>$status, -expires =>$expires)3425unless($opts{'-no_http_header'});3426my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';3427print<<EOF;3428<?xml version="1.0" encoding="utf-8"?>3429<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">3430<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">3431<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->3432<!-- git core binaries version$git_version-->3433<head>3434<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>3435<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>3436<meta name="robots" content="index, nofollow"/>3437<title>$title</title>3438EOF3439# the stylesheet, favicon etc urls won't work correctly with path_info3440# unless we set the appropriate base URL3441if($ENV{'PATH_INFO'}) {3442print"<base href=\"".esc_url($base_url)."\"/>\n";3443}3444# print out each stylesheet that exist, providing backwards capability3445# for those people who defined $stylesheet in a config file3446if(defined$stylesheet) {3447print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3448}else{3449foreachmy$stylesheet(@stylesheets) {3450next unless$stylesheet;3451print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3452}3453}3454if(defined$project) {3455my%href_params= get_feed_info();3456if(!exists$href_params{'-title'}) {3457$href_params{'-title'} ='log';3458}34593460foreachmy$formatqw(RSS Atom){3461my$type=lc($format);3462my%link_attr= (3463'-rel'=>'alternate',3464'-title'=>"$project-$href_params{'-title'} -$formatfeed",3465'-type'=>"application/$type+xml"3466);34673468$href_params{'action'} =$type;3469$link_attr{'-href'} = href(%href_params);3470print"<link ".3471"rel=\"$link_attr{'-rel'}\"".3472"title=\"$link_attr{'-title'}\"".3473"href=\"$link_attr{'-href'}\"".3474"type=\"$link_attr{'-type'}\"".3475"/>\n";34763477$href_params{'extra_options'} ='--no-merges';3478$link_attr{'-href'} = href(%href_params);3479$link_attr{'-title'} .=' (no merges)';3480print"<link ".3481"rel=\"$link_attr{'-rel'}\"".3482"title=\"$link_attr{'-title'}\"".3483"href=\"$link_attr{'-href'}\"".3484"type=\"$link_attr{'-type'}\"".3485"/>\n";3486}34873488}else{3489printf('<link rel="alternate" title="%sprojects list" '.3490'href="%s" type="text/plain; charset=utf-8" />'."\n",3491$site_name, href(project=>undef, action=>"project_index"));3492printf('<link rel="alternate" title="%sprojects feeds" '.3493'href="%s" type="text/x-opml" />'."\n",3494$site_name, href(project=>undef, action=>"opml"));3495}3496if(defined$favicon) {3497printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);3498}34993500print"</head>\n".3501"<body>\n";35023503if(defined$site_header&& -f $site_header) {3504 insert_file($site_header);3505}35063507print"<div class=\"page_header\">\n".3508$cgi->a({-href => esc_url($logo_url),3509-title =>$logo_label},3510qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));3511print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3512if(defined$project) {3513print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3514if(defined$action) {3515print" /$action";3516}3517print"\n";3518}3519print"</div>\n";35203521my$have_search= gitweb_check_feature('search');3522if(defined$project&&$have_search) {3523if(!defined$searchtext) {3524$searchtext="";3525}3526my$search_hash;3527if(defined$hash_base) {3528$search_hash=$hash_base;3529}elsif(defined$hash) {3530$search_hash=$hash;3531}else{3532$search_hash="HEAD";3533}3534my$action=$my_uri;3535my$use_pathinfo= gitweb_check_feature('pathinfo');3536if($use_pathinfo) {3537$action.="/".esc_url($project);3538}3539print$cgi->startform(-method=>"get", -action =>$action) .3540"<div class=\"search\">\n".3541(!$use_pathinfo&&3542$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3543$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3544$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3545$cgi->popup_menu(-name =>'st', -default=>'commit',3546-values=> ['commit','grep','author','committer','pickaxe']) .3547$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3548" search:\n",3549$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3550"<span title=\"Extended regular expression\">".3551$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3552-checked =>$search_use_regexp) .3553"</span>".3554"</div>".3555$cgi->end_form() ."\n";3556}3557}35583559sub git_footer_html {3560my$feed_class='rss_logo';35613562print"<div class=\"page_footer\">\n";3563if(defined$project) {3564my$descr= git_get_project_description($project);3565if(defined$descr) {3566print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3567}35683569my%href_params= get_feed_info();3570if(!%href_params) {3571$feed_class.=' generic';3572}3573$href_params{'-title'} ||='log';35743575foreachmy$formatqw(RSS Atom){3576$href_params{'action'} =lc($format);3577print$cgi->a({-href => href(%href_params),3578-title =>"$href_params{'-title'}$formatfeed",3579-class=>$feed_class},$format)."\n";3580}35813582}else{3583print$cgi->a({-href => href(project=>undef, action=>"opml"),3584-class=>$feed_class},"OPML") ." ";3585print$cgi->a({-href => href(project=>undef, action=>"project_index"),3586-class=>$feed_class},"TXT") ."\n";3587}3588print"</div>\n";# class="page_footer"35893590if(defined$t0&& gitweb_check_feature('timed')) {3591print"<div id=\"generating_info\">\n";3592print'This page took '.3593'<span id="generating_time" class="time_span">'.3594 Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).3595' seconds </span>'.3596' and '.3597'<span id="generating_cmd">'.3598$number_of_git_cmds.3599'</span> git commands '.3600" to generate.\n";3601print"</div>\n";# class="page_footer"3602}36033604if(defined$site_footer&& -f $site_footer) {3605 insert_file($site_footer);3606}36073608print qq!<script type="text/javascript" src="$javascript"></script>\n!;3609if(defined$action&&3610$actioneq'blame_incremental') {3611print qq!<script type="text/javascript">\n!.3612 qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.3613 qq!"!. href() .qq!");\n!.3614 qq!</script>\n!;3615}elsif(gitweb_check_feature('javascript-actions')) {3616print qq!<script type="text/javascript">\n!.3617 qq!window.onload = fixLinks;\n!.3618 qq!</script>\n!;3619}36203621print"</body>\n".3622"</html>";3623}36243625# die_error(<http_status_code>, <error_message>[, <detailed_html_description>])3626# Example: die_error(404, 'Hash not found')3627# By convention, use the following status codes (as defined in RFC 2616):3628# 400: Invalid or missing CGI parameters, or3629# requested object exists but has wrong type.3630# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3631# this server or project.3632# 404: Requested object/revision/project doesn't exist.3633# 500: The server isn't configured properly, or3634# an internal error occurred (e.g. failed assertions caused by bugs), or3635# an unknown error occurred (e.g. the git binary died unexpectedly).3636# 503: The server is currently unavailable (because it is overloaded,3637# or down for maintenance). Generally, this is a temporary state.3638sub die_error {3639my$status=shift||500;3640my$error= esc_html(shift) ||"Internal Server Error";3641my$extra=shift;3642my%opts=@_;36433644my%http_responses= (3645400=>'400 Bad Request',3646403=>'403 Forbidden',3647404=>'404 Not Found',3648500=>'500 Internal Server Error',3649503=>'503 Service Unavailable',3650);3651 git_header_html($http_responses{$status},undef,%opts);3652print<<EOF;3653<div class="page_body">3654<br /><br />3655$status-$error3656<br />3657EOF3658if(defined$extra) {3659print"<hr />\n".3660"$extra\n";3661}3662print"</div>\n";36633664 git_footer_html();3665goto DONE_GITWEB3666unless($opts{'-error_handler'});3667}36683669## ----------------------------------------------------------------------3670## functions printing or outputting HTML: navigation36713672sub git_print_page_nav {3673my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3674$extra=''if!defined$extra;# pager or formats36753676my@navs=qw(summary shortlog log commit commitdiff tree);3677if($suppress) {3678@navs=grep{$_ne$suppress}@navs;3679}36803681my%arg=map{$_=> {action=>$_} }@navs;3682if(defined$head) {3683for(qw(commit commitdiff)) {3684$arg{$_}{'hash'} =$head;3685}3686if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3687for(qw(shortlog log)) {3688$arg{$_}{'hash'} =$head;3689}3690}3691}36923693$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3694$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;36953696my@actions= gitweb_get_feature('actions');3697my%repl= (3698'%'=>'%',3699'n'=>$project,# project name3700'f'=>$git_dir,# project path within filesystem3701'h'=>$treehead||'',# current hash ('h' parameter)3702'b'=>$treebase||'',# hash base ('hb' parameter)3703);3704while(@actions) {3705my($label,$link,$pos) =splice(@actions,0,3);3706# insert3707@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3708# munch munch3709$link=~s/%([%nfhb])/$repl{$1}/g;3710$arg{$label}{'_href'} =$link;3711}37123713print"<div class=\"page_nav\">\n".3714(join" | ",3715map{$_eq$current?3716$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3717}@navs);3718print"<br/>\n$extra<br/>\n".3719"</div>\n";3720}37213722sub format_paging_nav {3723my($action,$page,$has_next_link) =@_;3724my$paging_nav;372537263727if($page>0) {3728$paging_nav.=3729$cgi->a({-href => href(-replay=>1, page=>undef)},"first") .3730" ⋅ ".3731$cgi->a({-href => href(-replay=>1, page=>$page-1),3732-accesskey =>"p", -title =>"Alt-p"},"prev");3733}else{3734$paging_nav.="first ⋅ prev";3735}37363737if($has_next_link) {3738$paging_nav.=" ⋅ ".3739$cgi->a({-href => href(-replay=>1, page=>$page+1),3740-accesskey =>"n", -title =>"Alt-n"},"next");3741}else{3742$paging_nav.=" ⋅ next";3743}37443745return$paging_nav;3746}37473748## ......................................................................3749## functions printing or outputting HTML: div37503751sub git_print_header_div {3752my($action,$title,$hash,$hash_base) =@_;3753my%args= ();37543755$args{'action'} =$action;3756$args{'hash'} =$hashif$hash;3757$args{'hash_base'} =$hash_baseif$hash_base;37583759print"<div class=\"header\">\n".3760$cgi->a({-href => href(%args), -class=>"title"},3761$title?$title:$action) .3762"\n</div>\n";3763}37643765sub print_local_time {3766print format_local_time(@_);3767}37683769sub format_local_time {3770my$localtime='';3771my%date=@_;3772if($date{'hour_local'} <6) {3773$localtime.=sprintf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3774$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3775}else{3776$localtime.=sprintf(" (%02d:%02d%s)",3777$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3778}37793780return$localtime;3781}37823783# Outputs the author name and date in long form3784sub git_print_authorship {3785my$co=shift;3786my%opts=@_;3787my$tag=$opts{-tag} ||'div';3788my$author=$co->{'author_name'};37893790my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3791print"<$tagclass=\"author_date\">".3792 format_search_author($author,"author", esc_html($author)) .3793" [$ad{'rfc2822'}";3794 print_local_time(%ad)if($opts{-localtime});3795print"]". git_get_avatar($co->{'author_email'}, -pad_before =>1)3796."</$tag>\n";3797}37983799# Outputs table rows containing the full author or committer information,3800# in the format expected for 'commit' view (& similar).3801# Parameters are a commit hash reference, followed by the list of people3802# to output information for. If the list is empty it defaults to both3803# author and committer.3804sub git_print_authorship_rows {3805my$co=shift;3806# too bad we can't use @people = @_ || ('author', 'committer')3807my@people=@_;3808@people= ('author','committer')unless@people;3809foreachmy$who(@people) {3810my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});3811print"<tr><td>$who</td><td>".3812 format_search_author($co->{"${who}_name"},$who,3813 esc_html($co->{"${who}_name"})) ." ".3814 format_search_author($co->{"${who}_email"},$who,3815 esc_html("<".$co->{"${who}_email"} .">")) .3816"</td><td rowspan=\"2\">".3817 git_get_avatar($co->{"${who}_email"}, -size =>'double') .3818"</td></tr>\n".3819"<tr>".3820"<td></td><td>$wd{'rfc2822'}";3821 print_local_time(%wd);3822print"</td>".3823"</tr>\n";3824}3825}38263827sub git_print_page_path {3828my$name=shift;3829my$type=shift;3830my$hb=shift;383138323833print"<div class=\"page_path\">";3834print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3835-title =>'tree root'}, to_utf8("[$project]"));3836print" / ";3837if(defined$name) {3838my@dirname=split'/',$name;3839my$basename=pop@dirname;3840my$fullname='';38413842foreachmy$dir(@dirname) {3843$fullname.= ($fullname?'/':'') .$dir;3844print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3845 hash_base=>$hb),3846-title =>$fullname}, esc_path($dir));3847print" / ";3848}3849if(defined$type&&$typeeq'blob') {3850print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3851 hash_base=>$hb),3852-title =>$name}, esc_path($basename));3853}elsif(defined$type&&$typeeq'tree') {3854print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3855 hash_base=>$hb),3856-title =>$name}, esc_path($basename));3857print" / ";3858}else{3859print esc_path($basename);3860}3861}3862print"<br/></div>\n";3863}38643865sub git_print_log {3866my$log=shift;3867my%opts=@_;38683869if($opts{'-remove_title'}) {3870# remove title, i.e. first line of log3871shift@$log;3872}3873# remove leading empty lines3874while(defined$log->[0] &&$log->[0]eq"") {3875shift@$log;3876}38773878# print log3879my$signoff=0;3880my$empty=0;3881foreachmy$line(@$log) {3882if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3883$signoff=1;3884$empty=0;3885if(!$opts{'-remove_signoff'}) {3886print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3887next;3888}else{3889# remove signoff lines3890next;3891}3892}else{3893$signoff=0;3894}38953896# print only one empty line3897# do not print empty line after signoff3898if($lineeq"") {3899next if($empty||$signoff);3900$empty=1;3901}else{3902$empty=0;3903}39043905print format_log_line_html($line) ."<br/>\n";3906}39073908if($opts{'-final_empty_line'}) {3909# end with single empty line3910print"<br/>\n"unless$empty;3911}3912}39133914# return link target (what link points to)3915sub git_get_link_target {3916my$hash=shift;3917my$link_target;39183919# read link3920open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3921orreturn;3922{3923local$/=undef;3924$link_target= <$fd>;3925}3926close$fd3927orreturn;39283929return$link_target;3930}39313932# given link target, and the directory (basedir) the link is in,3933# return target of link relative to top directory (top tree);3934# return undef if it is not possible (including absolute links).3935sub normalize_link_target {3936my($link_target,$basedir) =@_;39373938# absolute symlinks (beginning with '/') cannot be normalized3939return if(substr($link_target,0,1)eq'/');39403941# normalize link target to path from top (root) tree (dir)3942my$path;3943if($basedir) {3944$path=$basedir.'/'.$link_target;3945}else{3946# we are in top (root) tree (dir)3947$path=$link_target;3948}39493950# remove //, /./, and /../3951my@path_parts;3952foreachmy$part(split('/',$path)) {3953# discard '.' and ''3954next if(!$part||$parteq'.');3955# handle '..'3956if($parteq'..') {3957if(@path_parts) {3958pop@path_parts;3959}else{3960# link leads outside repository (outside top dir)3961return;3962}3963}else{3964push@path_parts,$part;3965}3966}3967$path=join('/',@path_parts);39683969return$path;3970}39713972# print tree entry (row of git_tree), but without encompassing <tr> element3973sub git_print_tree_entry {3974my($t,$basedir,$hash_base,$have_blame) =@_;39753976my%base_key= ();3977$base_key{'hash_base'} =$hash_baseifdefined$hash_base;39783979# The format of a table row is: mode list link. Where mode is3980# the mode of the entry, list is the name of the entry, an href,3981# and link is the action links of the entry.39823983print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3984if(exists$t->{'size'}) {3985print"<td class=\"size\">$t->{'size'}</td>\n";3986}3987if($t->{'type'}eq"blob") {3988print"<td class=\"list\">".3989$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3990 file_name=>"$basedir$t->{'name'}",%base_key),3991-class=>"list"}, esc_path($t->{'name'}));3992if(S_ISLNK(oct$t->{'mode'})) {3993my$link_target= git_get_link_target($t->{'hash'});3994if($link_target) {3995my$norm_target= normalize_link_target($link_target,$basedir);3996if(defined$norm_target) {3997print" -> ".3998$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3999 file_name=>$norm_target),4000-title =>$norm_target}, esc_path($link_target));4001}else{4002print" -> ". esc_path($link_target);4003}4004}4005}4006print"</td>\n";4007print"<td class=\"link\">";4008print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4009 file_name=>"$basedir$t->{'name'}",%base_key)},4010"blob");4011if($have_blame) {4012print" | ".4013$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},4014 file_name=>"$basedir$t->{'name'}",%base_key)},4015"blame");4016}4017if(defined$hash_base) {4018print" | ".4019$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,4020 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},4021"history");4022}4023print" | ".4024$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,4025 file_name=>"$basedir$t->{'name'}")},4026"raw");4027print"</td>\n";40284029}elsif($t->{'type'}eq"tree") {4030print"<td class=\"list\">";4031print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},4032 file_name=>"$basedir$t->{'name'}",4033%base_key)},4034 esc_path($t->{'name'}));4035print"</td>\n";4036print"<td class=\"link\">";4037print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},4038 file_name=>"$basedir$t->{'name'}",4039%base_key)},4040"tree");4041if(defined$hash_base) {4042print" | ".4043$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,4044 file_name=>"$basedir$t->{'name'}")},4045"history");4046}4047print"</td>\n";4048}else{4049# unknown object: we can only present history for it4050# (this includes 'commit' object, i.e. submodule support)4051print"<td class=\"list\">".4052 esc_path($t->{'name'}) .4053"</td>\n";4054print"<td class=\"link\">";4055if(defined$hash_base) {4056print$cgi->a({-href => href(action=>"history",4057 hash_base=>$hash_base,4058 file_name=>"$basedir$t->{'name'}")},4059"history");4060}4061print"</td>\n";4062}4063}40644065## ......................................................................4066## functions printing large fragments of HTML40674068# get pre-image filenames for merge (combined) diff4069sub fill_from_file_info {4070my($diff,@parents) =@_;40714072$diff->{'from_file'} = [ ];4073$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;4074for(my$i=0;$i<$diff->{'nparents'};$i++) {4075if($diff->{'status'}[$i]eq'R'||4076$diff->{'status'}[$i]eq'C') {4077$diff->{'from_file'}[$i] =4078 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);4079}4080}40814082return$diff;4083}40844085# is current raw difftree line of file deletion4086sub is_deleted {4087my$diffinfo=shift;40884089return$diffinfo->{'to_id'}eq('0' x 40);4090}40914092# does patch correspond to [previous] difftree raw line4093# $diffinfo - hashref of parsed raw diff format4094# $patchinfo - hashref of parsed patch diff format4095# (the same keys as in $diffinfo)4096sub is_patch_split {4097my($diffinfo,$patchinfo) =@_;40984099returndefined$diffinfo&&defined$patchinfo4100&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};4101}410241034104sub git_difftree_body {4105my($difftree,$hash,@parents) =@_;4106my($parent) =$parents[0];4107my$have_blame= gitweb_check_feature('blame');4108print"<div class=\"list_head\">\n";4109if($#{$difftree} >10) {4110print(($#{$difftree} +1) ." files changed:\n");4111}4112print"</div>\n";41134114print"<table class=\"".4115(@parents>1?"combined ":"") .4116"diff_tree\">\n";41174118# header only for combined diff in 'commitdiff' view4119my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';4120if($has_header) {4121# table header4122print"<thead><tr>\n".4123"<th></th><th></th>\n";# filename, patchN link4124for(my$i=0;$i<@parents;$i++) {4125my$par=$parents[$i];4126print"<th>".4127$cgi->a({-href => href(action=>"commitdiff",4128 hash=>$hash, hash_parent=>$par),4129-title =>'commitdiff to parent number '.4130($i+1) .': '.substr($par,0,7)},4131$i+1) .4132" </th>\n";4133}4134print"</tr></thead>\n<tbody>\n";4135}41364137my$alternate=1;4138my$patchno=0;4139foreachmy$line(@{$difftree}) {4140my$diff= parsed_difftree_line($line);41414142if($alternate) {4143print"<tr class=\"dark\">\n";4144}else{4145print"<tr class=\"light\">\n";4146}4147$alternate^=1;41484149if(exists$diff->{'nparents'}) {# combined diff41504151 fill_from_file_info($diff,@parents)4152unlessexists$diff->{'from_file'};41534154if(!is_deleted($diff)) {4155# file exists in the result (child) commit4156print"<td>".4157$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4158 file_name=>$diff->{'to_file'},4159 hash_base=>$hash),4160-class=>"list"}, esc_path($diff->{'to_file'})) .4161"</td>\n";4162}else{4163print"<td>".4164 esc_path($diff->{'to_file'}) .4165"</td>\n";4166}41674168if($actioneq'commitdiff') {4169# link to patch4170$patchno++;4171print"<td class=\"link\">".4172$cgi->a({-href =>"#patch$patchno"},"patch") .4173" | ".4174"</td>\n";4175}41764177my$has_history=0;4178my$not_deleted=0;4179for(my$i=0;$i<$diff->{'nparents'};$i++) {4180my$hash_parent=$parents[$i];4181my$from_hash=$diff->{'from_id'}[$i];4182my$from_path=$diff->{'from_file'}[$i];4183my$status=$diff->{'status'}[$i];41844185$has_history||= ($statusne'A');4186$not_deleted||= ($statusne'D');41874188if($statuseq'A') {4189print"<td class=\"link\"align=\"right\"> | </td>\n";4190}elsif($statuseq'D') {4191print"<td class=\"link\">".4192$cgi->a({-href => href(action=>"blob",4193 hash_base=>$hash,4194 hash=>$from_hash,4195 file_name=>$from_path)},4196"blob". ($i+1)) .4197" | </td>\n";4198}else{4199if($diff->{'to_id'}eq$from_hash) {4200print"<td class=\"link nochange\">";4201}else{4202print"<td class=\"link\">";4203}4204print$cgi->a({-href => href(action=>"blobdiff",4205 hash=>$diff->{'to_id'},4206 hash_parent=>$from_hash,4207 hash_base=>$hash,4208 hash_parent_base=>$hash_parent,4209 file_name=>$diff->{'to_file'},4210 file_parent=>$from_path)},4211"diff". ($i+1)) .4212" | </td>\n";4213}4214}42154216print"<td class=\"link\">";4217if($not_deleted) {4218print$cgi->a({-href => href(action=>"blob",4219 hash=>$diff->{'to_id'},4220 file_name=>$diff->{'to_file'},4221 hash_base=>$hash)},4222"blob");4223print" | "if($has_history);4224}4225if($has_history) {4226print$cgi->a({-href => href(action=>"history",4227 file_name=>$diff->{'to_file'},4228 hash_base=>$hash)},4229"history");4230}4231print"</td>\n";42324233print"</tr>\n";4234next;# instead of 'else' clause, to avoid extra indent4235}4236# else ordinary diff42374238my($to_mode_oct,$to_mode_str,$to_file_type);4239my($from_mode_oct,$from_mode_str,$from_file_type);4240if($diff->{'to_mode'}ne('0' x 6)) {4241$to_mode_oct=oct$diff->{'to_mode'};4242if(S_ISREG($to_mode_oct)) {# only for regular file4243$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits4244}4245$to_file_type= file_type($diff->{'to_mode'});4246}4247if($diff->{'from_mode'}ne('0' x 6)) {4248$from_mode_oct=oct$diff->{'from_mode'};4249if(S_ISREG($to_mode_oct)) {# only for regular file4250$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits4251}4252$from_file_type= file_type($diff->{'from_mode'});4253}42544255if($diff->{'status'}eq"A") {# created4256my$mode_chng="<span class=\"file_status new\">[new$to_file_type";4257$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;4258$mode_chng.="]</span>";4259print"<td>";4260print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4261 hash_base=>$hash, file_name=>$diff->{'file'}),4262-class=>"list"}, esc_path($diff->{'file'}));4263print"</td>\n";4264print"<td>$mode_chng</td>\n";4265print"<td class=\"link\">";4266if($actioneq'commitdiff') {4267# link to patch4268$patchno++;4269print$cgi->a({-href =>"#patch$patchno"},"patch");4270print" | ";4271}4272print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4273 hash_base=>$hash, file_name=>$diff->{'file'})},4274"blob");4275print"</td>\n";42764277}elsif($diff->{'status'}eq"D") {# deleted4278my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";4279print"<td>";4280print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4281 hash_base=>$parent, file_name=>$diff->{'file'}),4282-class=>"list"}, esc_path($diff->{'file'}));4283print"</td>\n";4284print"<td>$mode_chng</td>\n";4285print"<td class=\"link\">";4286if($actioneq'commitdiff') {4287# link to patch4288$patchno++;4289print$cgi->a({-href =>"#patch$patchno"},"patch");4290print" | ";4291}4292print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4293 hash_base=>$parent, file_name=>$diff->{'file'})},4294"blob") ." | ";4295if($have_blame) {4296print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,4297 file_name=>$diff->{'file'})},4298"blame") ." | ";4299}4300print$cgi->a({-href => href(action=>"history", hash_base=>$parent,4301 file_name=>$diff->{'file'})},4302"history");4303print"</td>\n";43044305}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed4306my$mode_chnge="";4307if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4308$mode_chnge="<span class=\"file_status mode_chnge\">[changed";4309if($from_file_typene$to_file_type) {4310$mode_chnge.=" from$from_file_typeto$to_file_type";4311}4312if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {4313if($from_mode_str&&$to_mode_str) {4314$mode_chnge.=" mode:$from_mode_str->$to_mode_str";4315}elsif($to_mode_str) {4316$mode_chnge.=" mode:$to_mode_str";4317}4318}4319$mode_chnge.="]</span>\n";4320}4321print"<td>";4322print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4323 hash_base=>$hash, file_name=>$diff->{'file'}),4324-class=>"list"}, esc_path($diff->{'file'}));4325print"</td>\n";4326print"<td>$mode_chnge</td>\n";4327print"<td class=\"link\">";4328if($actioneq'commitdiff') {4329# link to patch4330$patchno++;4331print$cgi->a({-href =>"#patch$patchno"},"patch") .4332" | ";4333}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4334# "commit" view and modified file (not onlu mode changed)4335print$cgi->a({-href => href(action=>"blobdiff",4336 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4337 hash_base=>$hash, hash_parent_base=>$parent,4338 file_name=>$diff->{'file'})},4339"diff") .4340" | ";4341}4342print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4343 hash_base=>$hash, file_name=>$diff->{'file'})},4344"blob") ." | ";4345if($have_blame) {4346print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4347 file_name=>$diff->{'file'})},4348"blame") ." | ";4349}4350print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4351 file_name=>$diff->{'file'})},4352"history");4353print"</td>\n";43544355}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied4356my%status_name= ('R'=>'moved','C'=>'copied');4357my$nstatus=$status_name{$diff->{'status'}};4358my$mode_chng="";4359if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4360# mode also for directories, so we cannot use $to_mode_str4361$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);4362}4363print"<td>".4364$cgi->a({-href => href(action=>"blob", hash_base=>$hash,4365 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),4366-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".4367"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".4368$cgi->a({-href => href(action=>"blob", hash_base=>$parent,4369 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),4370-class=>"list"}, esc_path($diff->{'from_file'})) .4371" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".4372"<td class=\"link\">";4373if($actioneq'commitdiff') {4374# link to patch4375$patchno++;4376print$cgi->a({-href =>"#patch$patchno"},"patch") .4377" | ";4378}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4379# "commit" view and modified file (not only pure rename or copy)4380print$cgi->a({-href => href(action=>"blobdiff",4381 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4382 hash_base=>$hash, hash_parent_base=>$parent,4383 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},4384"diff") .4385" | ";4386}4387print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4388 hash_base=>$parent, file_name=>$diff->{'to_file'})},4389"blob") ." | ";4390if($have_blame) {4391print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4392 file_name=>$diff->{'to_file'})},4393"blame") ." | ";4394}4395print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4396 file_name=>$diff->{'to_file'})},4397"history");4398print"</td>\n";43994400}# we should not encounter Unmerged (U) or Unknown (X) status4401print"</tr>\n";4402}4403print"</tbody>"if$has_header;4404print"</table>\n";4405}44064407sub git_patchset_body {4408my($fd,$difftree,$hash,@hash_parents) =@_;4409my($hash_parent) =$hash_parents[0];44104411my$is_combined= (@hash_parents>1);4412my$patch_idx=0;4413my$patch_number=0;4414my$patch_line;4415my$diffinfo;4416my$to_name;4417my(%from,%to);44184419print"<div class=\"patchset\">\n";44204421# skip to first patch4422while($patch_line= <$fd>) {4423chomp$patch_line;44244425last if($patch_line=~m/^diff /);4426}44274428 PATCH:4429while($patch_line) {44304431# parse "git diff" header line4432if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {4433# $1 is from_name, which we do not use4434$to_name= unquote($2);4435$to_name=~s!^b/!!;4436}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {4437# $1 is 'cc' or 'combined', which we do not use4438$to_name= unquote($2);4439}else{4440$to_name=undef;4441}44424443# check if current patch belong to current raw line4444# and parse raw git-diff line if needed4445if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {4446# this is continuation of a split patch4447print"<div class=\"patch cont\">\n";4448}else{4449# advance raw git-diff output if needed4450$patch_idx++ifdefined$diffinfo;44514452# read and prepare patch information4453$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);44544455# compact combined diff output can have some patches skipped4456# find which patch (using pathname of result) we are at now;4457if($is_combined) {4458while($to_namene$diffinfo->{'to_file'}) {4459print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4460 format_diff_cc_simplified($diffinfo,@hash_parents) .4461"</div>\n";# class="patch"44624463$patch_idx++;4464$patch_number++;44654466last if$patch_idx>$#$difftree;4467$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);4468}4469}44704471# modifies %from, %to hashes4472 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);44734474# this is first patch for raw difftree line with $patch_idx index4475# we index @$difftree array from 0, but number patches from 14476print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";4477}44784479# git diff header4480#assert($patch_line =~ m/^diff /) if DEBUG;4481#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed4482$patch_number++;4483# print "git diff" header4484print format_git_diff_header_line($patch_line,$diffinfo,4485 \%from, \%to);44864487# print extended diff header4488print"<div class=\"diff extended_header\">\n";4489 EXTENDED_HEADER:4490while($patch_line= <$fd>) {4491chomp$patch_line;44924493last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);44944495print format_extended_diff_header_line($patch_line,$diffinfo,4496 \%from, \%to);4497}4498print"</div>\n";# class="diff extended_header"44994500# from-file/to-file diff header4501if(!$patch_line) {4502print"</div>\n";# class="patch"4503last PATCH;4504}4505next PATCH if($patch_line=~m/^diff /);4506#assert($patch_line =~ m/^---/) if DEBUG;45074508my$last_patch_line=$patch_line;4509$patch_line= <$fd>;4510chomp$patch_line;4511#assert($patch_line =~ m/^\+\+\+/) if DEBUG;45124513print format_diff_from_to_header($last_patch_line,$patch_line,4514$diffinfo, \%from, \%to,4515@hash_parents);45164517# the patch itself4518 LINE:4519while($patch_line= <$fd>) {4520chomp$patch_line;45214522next PATCH if($patch_line=~m/^diff /);45234524print format_diff_line($patch_line, \%from, \%to);4525}45264527}continue{4528print"</div>\n";# class="patch"4529}45304531# for compact combined (--cc) format, with chunk and patch simplification4532# the patchset might be empty, but there might be unprocessed raw lines4533for(++$patch_idxif$patch_number>0;4534$patch_idx<@$difftree;4535++$patch_idx) {4536# read and prepare patch information4537$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);45384539# generate anchor for "patch" links in difftree / whatchanged part4540print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4541 format_diff_cc_simplified($diffinfo,@hash_parents) .4542"</div>\n";# class="patch"45434544$patch_number++;4545}45464547if($patch_number==0) {4548if(@hash_parents>1) {4549print"<div class=\"diff nodifferences\">Trivial merge</div>\n";4550}else{4551print"<div class=\"diff nodifferences\">No differences found</div>\n";4552}4553}45544555print"</div>\n";# class="patchset"4556}45574558# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45594560# fills project list info (age, description, owner, forks) for each4561# project in the list, removing invalid projects from returned list4562# NOTE: modifies $projlist, but does not remove entries from it4563sub fill_project_list_info {4564my($projlist,$check_forks) =@_;4565my@projects;45664567my$show_ctags= gitweb_check_feature('ctags');4568 PROJECT:4569foreachmy$pr(@$projlist) {4570my(@activity) = git_get_last_activity($pr->{'path'});4571unless(@activity) {4572next PROJECT;4573}4574($pr->{'age'},$pr->{'age_string'}) =@activity;4575if(!defined$pr->{'descr'}) {4576my$descr= git_get_project_description($pr->{'path'}) ||"";4577$descr= to_utf8($descr);4578$pr->{'descr_long'} =$descr;4579$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4580}4581if(!defined$pr->{'owner'}) {4582$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4583}4584if($check_forks) {4585my$pname=$pr->{'path'};4586if(($pname=~s/\.git$//) &&4587($pname!~/\/$/) &&4588(-d "$projectroot/$pname")) {4589$pr->{'forks'} ="-d$projectroot/$pname";4590}else{4591$pr->{'forks'} =0;4592}4593}4594$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4595push@projects,$pr;4596}45974598return@projects;4599}46004601# print 'sort by' <th> element, generating 'sort by $name' replay link4602# if that order is not selected4603sub print_sort_th {4604print format_sort_th(@_);4605}46064607sub format_sort_th {4608my($name,$order,$header) =@_;4609my$sort_th="";4610$header||=ucfirst($name);46114612if($ordereq$name) {4613$sort_th.="<th>$header</th>\n";4614}else{4615$sort_th.="<th>".4616$cgi->a({-href => href(-replay=>1, order=>$name),4617-class=>"header"},$header) .4618"</th>\n";4619}46204621return$sort_th;4622}46234624sub git_project_list_body {4625# actually uses global variable $project4626my($projlist,$order,$from,$to,$extra,$no_header) =@_;46274628my$check_forks= gitweb_check_feature('forks');4629my@projects= fill_project_list_info($projlist,$check_forks);46304631$order||=$default_projects_order;4632$from=0unlessdefined$from;4633$to=$#projectsif(!defined$to||$#projects<$to);46344635my%order_info= (4636 project => { key =>'path', type =>'str'},4637 descr => { key =>'descr_long', type =>'str'},4638 owner => { key =>'owner', type =>'str'},4639 age => { key =>'age', type =>'num'}4640);4641my$oi=$order_info{$order};4642if($oi->{'type'}eq'str') {4643@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4644}else{4645@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4646}46474648my$show_ctags= gitweb_check_feature('ctags');4649if($show_ctags) {4650my%ctags;4651foreachmy$p(@projects) {4652foreachmy$ct(keys%{$p->{'ctags'}}) {4653$ctags{$ct} +=$p->{'ctags'}->{$ct};4654}4655}4656my$cloud= git_populate_project_tagcloud(\%ctags);4657print git_show_project_tagcloud($cloud,64);4658}46594660print"<table class=\"project_list\">\n";4661unless($no_header) {4662print"<tr>\n";4663if($check_forks) {4664print"<th></th>\n";4665}4666 print_sort_th('project',$order,'Project');4667 print_sort_th('descr',$order,'Description');4668 print_sort_th('owner',$order,'Owner');4669 print_sort_th('age',$order,'Last Change');4670print"<th></th>\n".# for links4671"</tr>\n";4672}4673my$alternate=1;4674my$tagfilter=$cgi->param('by_tag');4675for(my$i=$from;$i<=$to;$i++) {4676my$pr=$projects[$i];46774678next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4679next if$searchtextand not$pr->{'path'} =~/$searchtext/4680and not$pr->{'descr_long'} =~/$searchtext/;4681# Weed out forks or non-matching entries of search4682if($check_forks) {4683my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4684$forkbase="^$forkbase"if$forkbase;4685next ifnot$searchtextand not$tagfilterand$show_ctags4686and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4687}46884689if($alternate) {4690print"<tr class=\"dark\">\n";4691}else{4692print"<tr class=\"light\">\n";4693}4694$alternate^=1;4695if($check_forks) {4696print"<td>";4697if($pr->{'forks'}) {4698print"<!--$pr->{'forks'} -->\n";4699print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4700}4701print"</td>\n";4702}4703print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4704-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4705"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4706-class=>"list", -title =>$pr->{'descr_long'}},4707 esc_html($pr->{'descr'})) ."</td>\n".4708"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4709print"<td class=\"". age_class($pr->{'age'}) ."\">".4710(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4711"<td class=\"link\">".4712$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4713$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4714$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4715$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4716($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4717"</td>\n".4718"</tr>\n";4719}4720if(defined$extra) {4721print"<tr>\n";4722if($check_forks) {4723print"<td></td>\n";4724}4725print"<td colspan=\"5\">$extra</td>\n".4726"</tr>\n";4727}4728print"</table>\n";4729}47304731sub git_log_body {4732# uses global variable $project4733my($commitlist,$from,$to,$refs,$extra) =@_;47344735$from=0unlessdefined$from;4736$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);47374738for(my$i=0;$i<=$to;$i++) {4739my%co= %{$commitlist->[$i]};4740next if!%co;4741my$commit=$co{'id'};4742my$ref= format_ref_marker($refs,$commit);4743my%ad= parse_date($co{'author_epoch'});4744 git_print_header_div('commit',4745"<span class=\"age\">$co{'age_string'}</span>".4746 esc_html($co{'title'}) .$ref,4747$commit);4748print"<div class=\"title_text\">\n".4749"<div class=\"log_link\">\n".4750$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .4751" | ".4752$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .4753" | ".4754$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .4755"<br/>\n".4756"</div>\n";4757 git_print_authorship(\%co, -tag =>'span');4758print"<br/>\n</div>\n";47594760print"<div class=\"log_body\">\n";4761 git_print_log($co{'comment'}, -final_empty_line=>1);4762print"</div>\n";4763}4764if($extra) {4765print"<div class=\"page_nav\">\n";4766print"$extra\n";4767print"</div>\n";4768}4769}47704771sub git_shortlog_body {4772# uses global variable $project4773my($commitlist,$from,$to,$refs,$extra) =@_;47744775$from=0unlessdefined$from;4776$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);47774778print"<table class=\"shortlog\">\n";4779my$alternate=1;4780for(my$i=$from;$i<=$to;$i++) {4781my%co= %{$commitlist->[$i]};4782my$commit=$co{'id'};4783my$ref= format_ref_marker($refs,$commit);4784if($alternate) {4785print"<tr class=\"dark\">\n";4786}else{4787print"<tr class=\"light\">\n";4788}4789$alternate^=1;4790# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4791print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4792 format_author_html('td', \%co,10) ."<td>";4793print format_subject_html($co{'title'},$co{'title_short'},4794 href(action=>"commit", hash=>$commit),$ref);4795print"</td>\n".4796"<td class=\"link\">".4797$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4798$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4799$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4800my$snapshot_links= format_snapshot_links($commit);4801if(defined$snapshot_links) {4802print" | ".$snapshot_links;4803}4804print"</td>\n".4805"</tr>\n";4806}4807if(defined$extra) {4808print"<tr>\n".4809"<td colspan=\"4\">$extra</td>\n".4810"</tr>\n";4811}4812print"</table>\n";4813}48144815sub git_history_body {4816# Warning: assumes constant type (blob or tree) during history4817my($commitlist,$from,$to,$refs,$extra,4818$file_name,$file_hash,$ftype) =@_;48194820$from=0unlessdefined$from;4821$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});48224823print"<table class=\"history\">\n";4824my$alternate=1;4825for(my$i=$from;$i<=$to;$i++) {4826my%co= %{$commitlist->[$i]};4827if(!%co) {4828next;4829}4830my$commit=$co{'id'};48314832my$ref= format_ref_marker($refs,$commit);48334834if($alternate) {4835print"<tr class=\"dark\">\n";4836}else{4837print"<tr class=\"light\">\n";4838}4839$alternate^=1;4840print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4841# shortlog: format_author_html('td', \%co, 10)4842 format_author_html('td', \%co,15,3) ."<td>";4843# originally git_history used chop_str($co{'title'}, 50)4844print format_subject_html($co{'title'},$co{'title_short'},4845 href(action=>"commit", hash=>$commit),$ref);4846print"</td>\n".4847"<td class=\"link\">".4848$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4849$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");48504851if($ftypeeq'blob') {4852my$blob_current=$file_hash;4853my$blob_parent= git_get_hash_by_path($commit,$file_name);4854if(defined$blob_current&&defined$blob_parent&&4855$blob_currentne$blob_parent) {4856print" | ".4857$cgi->a({-href => href(action=>"blobdiff",4858 hash=>$blob_current, hash_parent=>$blob_parent,4859 hash_base=>$hash_base, hash_parent_base=>$commit,4860 file_name=>$file_name)},4861"diff to current");4862}4863}4864print"</td>\n".4865"</tr>\n";4866}4867if(defined$extra) {4868print"<tr>\n".4869"<td colspan=\"4\">$extra</td>\n".4870"</tr>\n";4871}4872print"</table>\n";4873}48744875sub git_tags_body {4876# uses global variable $project4877my($taglist,$from,$to,$extra) =@_;4878$from=0unlessdefined$from;4879$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);48804881print"<table class=\"tags\">\n";4882my$alternate=1;4883for(my$i=$from;$i<=$to;$i++) {4884my$entry=$taglist->[$i];4885my%tag=%$entry;4886my$comment=$tag{'subject'};4887my$comment_short;4888if(defined$comment) {4889$comment_short= chop_str($comment,30,5);4890}4891if($alternate) {4892print"<tr class=\"dark\">\n";4893}else{4894print"<tr class=\"light\">\n";4895}4896$alternate^=1;4897if(defined$tag{'age'}) {4898print"<td><i>$tag{'age'}</i></td>\n";4899}else{4900print"<td></td>\n";4901}4902print"<td>".4903$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4904-class=>"list name"}, esc_html($tag{'name'})) .4905"</td>\n".4906"<td>";4907if(defined$comment) {4908print format_subject_html($comment,$comment_short,4909 href(action=>"tag", hash=>$tag{'id'}));4910}4911print"</td>\n".4912"<td class=\"selflink\">";4913if($tag{'type'}eq"tag") {4914print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4915}else{4916print" ";4917}4918print"</td>\n".4919"<td class=\"link\">"." | ".4920$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4921if($tag{'reftype'}eq"commit") {4922print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4923" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4924}elsif($tag{'reftype'}eq"blob") {4925print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4926}4927print"</td>\n".4928"</tr>";4929}4930if(defined$extra) {4931print"<tr>\n".4932"<td colspan=\"5\">$extra</td>\n".4933"</tr>\n";4934}4935print"</table>\n";4936}49374938sub git_heads_body {4939# uses global variable $project4940my($headlist,$head,$from,$to,$extra) =@_;4941$from=0unlessdefined$from;4942$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);49434944print"<table class=\"heads\">\n";4945my$alternate=1;4946for(my$i=$from;$i<=$to;$i++) {4947my$entry=$headlist->[$i];4948my%ref=%$entry;4949my$curr=$ref{'id'}eq$head;4950if($alternate) {4951print"<tr class=\"dark\">\n";4952}else{4953print"<tr class=\"light\">\n";4954}4955$alternate^=1;4956print"<td><i>$ref{'age'}</i></td>\n".4957($curr?"<td class=\"current_head\">":"<td>") .4958$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4959-class=>"list name"},esc_html($ref{'name'})) .4960"</td>\n".4961"<td class=\"link\">".4962$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4963$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4964$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4965"</td>\n".4966"</tr>";4967}4968if(defined$extra) {4969print"<tr>\n".4970"<td colspan=\"3\">$extra</td>\n".4971"</tr>\n";4972}4973print"</table>\n";4974}49754976sub git_search_grep_body {4977my($commitlist,$from,$to,$extra) =@_;4978$from=0unlessdefined$from;4979$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);49804981print"<table class=\"commit_search\">\n";4982my$alternate=1;4983for(my$i=$from;$i<=$to;$i++) {4984my%co= %{$commitlist->[$i]};4985if(!%co) {4986next;4987}4988my$commit=$co{'id'};4989if($alternate) {4990print"<tr class=\"dark\">\n";4991}else{4992print"<tr class=\"light\">\n";4993}4994$alternate^=1;4995print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4996 format_author_html('td', \%co,15,5) .4997"<td>".4998$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4999-class=>"list subject"},5000 chop_and_escape_str($co{'title'},50) ."<br/>");5001my$comment=$co{'comment'};5002foreachmy$line(@$comment) {5003if($line=~m/^(.*?)($search_regexp)(.*)$/i) {5004my($lead,$match,$trail) = ($1,$2,$3);5005$match= chop_str($match,70,5,'center');5006my$contextlen=int((80-length($match))/2);5007$contextlen=30if($contextlen>30);5008$lead= chop_str($lead,$contextlen,10,'left');5009$trail= chop_str($trail,$contextlen,10,'right');50105011$lead= esc_html($lead);5012$match= esc_html($match);5013$trail= esc_html($trail);50145015print"$lead<span class=\"match\">$match</span>$trail<br />";5016}5017}5018print"</td>\n".5019"<td class=\"link\">".5020$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5021" | ".5022$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .5023" | ".5024$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5025print"</td>\n".5026"</tr>\n";5027}5028if(defined$extra) {5029print"<tr>\n".5030"<td colspan=\"3\">$extra</td>\n".5031"</tr>\n";5032}5033print"</table>\n";5034}50355036## ======================================================================5037## ======================================================================5038## actions50395040sub git_project_list {5041my$order=$input_params{'order'};5042if(defined$order&&$order!~m/none|project|descr|owner|age/) {5043 die_error(400,"Unknown order parameter");5044}50455046my@list= git_get_projects_list();5047if(!@list) {5048 die_error(404,"No projects found");5049}50505051 git_header_html();5052if(defined$home_text&& -f $home_text) {5053print"<div class=\"index_include\">\n";5054 insert_file($home_text);5055print"</div>\n";5056}5057print$cgi->startform(-method=>"get") .5058"<p class=\"projsearch\">Search:\n".5059$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".5060"</p>".5061$cgi->end_form() ."\n";5062 git_project_list_body(\@list,$order);5063 git_footer_html();5064}50655066sub git_forks {5067my$order=$input_params{'order'};5068if(defined$order&&$order!~m/none|project|descr|owner|age/) {5069 die_error(400,"Unknown order parameter");5070}50715072my@list= git_get_projects_list($project);5073if(!@list) {5074 die_error(404,"No forks found");5075}50765077 git_header_html();5078 git_print_page_nav('','');5079 git_print_header_div('summary',"$projectforks");5080 git_project_list_body(\@list,$order);5081 git_footer_html();5082}50835084sub git_project_index {5085my@projects= git_get_projects_list($project);50865087print$cgi->header(5088-type =>'text/plain',5089-charset =>'utf-8',5090-content_disposition =>'inline; filename="index.aux"');50915092foreachmy$pr(@projects) {5093if(!exists$pr->{'owner'}) {5094$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");5095}50965097my($path,$owner) = ($pr->{'path'},$pr->{'owner'});5098# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '5099$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;5100$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;5101$path=~s/ /\+/g;5102$owner=~s/ /\+/g;51035104print"$path$owner\n";5105}5106}51075108sub git_summary {5109my$descr= git_get_project_description($project) ||"none";5110my%co= parse_commit("HEAD");5111my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();5112my$head=$co{'id'};51135114my$owner= git_get_project_owner($project);51155116my$refs= git_get_references();5117# These get_*_list functions return one more to allow us to see if5118# there are more ...5119my@taglist= git_get_tags_list(16);5120my@headlist= git_get_heads_list(16);5121my@forklist;5122my$check_forks= gitweb_check_feature('forks');51235124if($check_forks) {5125@forklist= git_get_projects_list($project);5126}51275128 git_header_html();5129 git_print_page_nav('summary','',$head);51305131print"<div class=\"title\"> </div>\n";5132print"<table class=\"projects_list\">\n".5133"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".5134"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";5135if(defined$cd{'rfc2822'}) {5136print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";5137}51385139# use per project git URL list in $projectroot/$project/cloneurl5140# or make project git URL from git base URL and project name5141my$url_tag="URL";5142my@url_list= git_get_project_url_list($project);5143@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;5144foreachmy$git_url(@url_list) {5145next unless$git_url;5146print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";5147$url_tag="";5148}51495150# Tag cloud5151my$show_ctags= gitweb_check_feature('ctags');5152if($show_ctags) {5153my$ctags= git_get_project_ctags($project);5154my$cloud= git_populate_project_tagcloud($ctags);5155print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";5156print"</td>\n<td>"unless%$ctags;5157print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";5158print"</td>\n<td>"if%$ctags;5159print git_show_project_tagcloud($cloud,48);5160print"</td></tr>";5161}51625163print"</table>\n";51645165# If XSS prevention is on, we don't include README.html.5166# TODO: Allow a readme in some safe format.5167if(!$prevent_xss&& -s "$projectroot/$project/README.html") {5168print"<div class=\"title\">readme</div>\n".5169"<div class=\"readme\">\n";5170 insert_file("$projectroot/$project/README.html");5171print"\n</div>\n";# class="readme"5172}51735174# we need to request one more than 16 (0..15) to check if5175# those 16 are all5176my@commitlist=$head? parse_commits($head,17) : ();5177if(@commitlist) {5178 git_print_header_div('shortlog');5179 git_shortlog_body(\@commitlist,0,15,$refs,5180$#commitlist<=15?undef:5181$cgi->a({-href => href(action=>"shortlog")},"..."));5182}51835184if(@taglist) {5185 git_print_header_div('tags');5186 git_tags_body(\@taglist,0,15,5187$#taglist<=15?undef:5188$cgi->a({-href => href(action=>"tags")},"..."));5189}51905191if(@headlist) {5192 git_print_header_div('heads');5193 git_heads_body(\@headlist,$head,0,15,5194$#headlist<=15?undef:5195$cgi->a({-href => href(action=>"heads")},"..."));5196}51975198if(@forklist) {5199 git_print_header_div('forks');5200 git_project_list_body(\@forklist,'age',0,15,5201$#forklist<=15?undef:5202$cgi->a({-href => href(action=>"forks")},"..."),5203'no_header');5204}52055206 git_footer_html();5207}52085209sub git_tag {5210my%tag= parse_tag($hash);52115212if(!%tag) {5213 die_error(404,"Unknown tag object");5214}52155216my$head= git_get_head_hash($project);5217 git_header_html();5218 git_print_page_nav('','',$head,undef,$head);5219 git_print_header_div('commit', esc_html($tag{'name'}),$hash);5220print"<div class=\"title_text\">\n".5221"<table class=\"object_header\">\n".5222"<tr>\n".5223"<td>object</td>\n".5224"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},5225$tag{'object'}) ."</td>\n".5226"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},5227$tag{'type'}) ."</td>\n".5228"</tr>\n";5229if(defined($tag{'author'})) {5230 git_print_authorship_rows(\%tag,'author');5231}5232print"</table>\n\n".5233"</div>\n";5234print"<div class=\"page_body\">";5235my$comment=$tag{'comment'};5236foreachmy$line(@$comment) {5237chomp$line;5238print esc_html($line, -nbsp=>1) ."<br/>\n";5239}5240print"</div>\n";5241 git_footer_html();5242}52435244sub git_blame_common {5245my$format=shift||'porcelain';5246if($formateq'porcelain'&&$cgi->param('js')) {5247$format='incremental';5248$action='blame_incremental';# for page title etc5249}52505251# permissions5252 gitweb_check_feature('blame')5253or die_error(403,"Blame view not allowed");52545255# error checking5256 die_error(400,"No file name given")unless$file_name;5257$hash_base||= git_get_head_hash($project);5258 die_error(404,"Couldn't find base commit")unless$hash_base;5259my%co= parse_commit($hash_base)5260or die_error(404,"Commit not found");5261my$ftype="blob";5262if(!defined$hash) {5263$hash= git_get_hash_by_path($hash_base,$file_name,"blob")5264or die_error(404,"Error looking up file");5265}else{5266$ftype= git_get_type($hash);5267if($ftype!~"blob") {5268 die_error(400,"Object is not a blob");5269}5270}52715272my$fd;5273if($formateq'incremental') {5274# get file contents (as base)5275open$fd,"-|", git_cmd(),'cat-file','blob',$hash5276or die_error(500,"Open git-cat-file failed");5277}elsif($formateq'data') {5278# run git-blame --incremental5279open$fd,"-|", git_cmd(),"blame","--incremental",5280$hash_base,"--",$file_name5281or die_error(500,"Open git-blame --incremental failed");5282}else{5283# run git-blame --porcelain5284open$fd,"-|", git_cmd(),"blame",'-p',5285$hash_base,'--',$file_name5286or die_error(500,"Open git-blame --porcelain failed");5287}52885289# incremental blame data returns early5290if($formateq'data') {5291print$cgi->header(5292-type=>"text/plain", -charset =>"utf-8",5293-status=>"200 OK");5294local$| =1;# output autoflush5295printwhile<$fd>;5296close$fd5297or print"ERROR$!\n";52985299print'END';5300if(defined$t0&& gitweb_check_feature('timed')) {5301print' '.5302 Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).5303' '.$number_of_git_cmds;5304}5305print"\n";53065307return;5308}53095310# page header5311 git_header_html();5312my$formats_nav=5313$cgi->a({-href => href(action=>"blob", -replay=>1)},5314"blob") .5315" | ";5316if($formateq'incremental') {5317$formats_nav.=5318$cgi->a({-href => href(action=>"blame", javascript=>0, -replay=>1)},5319"blame") ." (non-incremental)";5320}else{5321$formats_nav.=5322$cgi->a({-href => href(action=>"blame_incremental", -replay=>1)},5323"blame") ." (incremental)";5324}5325$formats_nav.=5326" | ".5327$cgi->a({-href => href(action=>"history", -replay=>1)},5328"history") .5329" | ".5330$cgi->a({-href => href(action=>$action, file_name=>$file_name)},5331"HEAD");5332 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5333 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5334 git_print_page_path($file_name,$ftype,$hash_base);53355336# page body5337if($formateq'incremental') {5338print"<noscript>\n<div class=\"error\"><center><b>\n".5339"This page requires JavaScript to run.\nUse ".5340$cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},5341'this page').5342" instead.\n".5343"</b></center></div>\n</noscript>\n";53445345print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!;5346}53475348print qq!<div class="page_body">\n!;5349print qq!<div id="progress_info">.../ ...</div>\n!5350if($formateq'incremental');5351print qq!<table id="blame_table"class="blame" width="100%">\n!.5352#qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.5353 qq!<thead>\n!.5354 qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!.5355 qq!</thead>\n!.5356 qq!<tbody>\n!;53575358my@rev_color=qw(light dark);5359my$num_colors=scalar(@rev_color);5360my$current_color=0;53615362if($formateq'incremental') {5363my$color_class=$rev_color[$current_color];53645365#contents of a file5366my$linenr=0;5367 LINE:5368while(my$line= <$fd>) {5369chomp$line;5370$linenr++;53715372print qq!<tr id="l$linenr"class="$color_class">!.5373 qq!<td class="sha1"><a href=""> </a></td>!.5374 qq!<td class="linenr">!.5375 qq!<a class="linenr" href="">$linenr</a></td>!;5376print qq!<td class="pre">! . esc_html($line) ."</td>\n";5377print qq!</tr>\n!;5378}53795380}else{# porcelain, i.e. ordinary blame5381my%metainfo= ();# saves information about commits53825383# blame data5384 LINE:5385while(my$line= <$fd>) {5386chomp$line;5387# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]5388# no <lines in group> for subsequent lines in group of lines5389my($full_rev,$orig_lineno,$lineno,$group_size) =5390($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);5391if(!exists$metainfo{$full_rev}) {5392$metainfo{$full_rev} = {'nprevious'=>0};5393}5394my$meta=$metainfo{$full_rev};5395my$data;5396while($data= <$fd>) {5397chomp$data;5398last if($data=~s/^\t//);# contents of line5399if($data=~/^(\S+)(?: (.*))?$/) {5400$meta->{$1} =$2unlessexists$meta->{$1};5401}5402if($data=~/^previous /) {5403$meta->{'nprevious'}++;5404}5405}5406my$short_rev=substr($full_rev,0,8);5407my$author=$meta->{'author'};5408my%date=5409 parse_date($meta->{'author-time'},$meta->{'author-tz'});5410my$date=$date{'iso-tz'};5411if($group_size) {5412$current_color= ($current_color+1) %$num_colors;5413}5414my$tr_class=$rev_color[$current_color];5415$tr_class.=' boundary'if(exists$meta->{'boundary'});5416$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);5417$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);5418print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";5419if($group_size) {5420print"<td class=\"sha1\"";5421print" title=\"". esc_html($author) .",$date\"";5422print" rowspan=\"$group_size\""if($group_size>1);5423print">";5424print$cgi->a({-href => href(action=>"commit",5425 hash=>$full_rev,5426 file_name=>$file_name)},5427 esc_html($short_rev));5428if($group_size>=2) {5429my@author_initials= ($author=~/\b([[:upper:]])\B/g);5430if(@author_initials) {5431print"<br />".5432 esc_html(join('',@author_initials));5433# or join('.', ...)5434}5435}5436print"</td>\n";5437}5438# 'previous' <sha1 of parent commit> <filename at commit>5439if(exists$meta->{'previous'} &&5440$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {5441$meta->{'parent'} =$1;5442$meta->{'file_parent'} = unquote($2);5443}5444my$linenr_commit=5445exists($meta->{'parent'}) ?5446$meta->{'parent'} :$full_rev;5447my$linenr_filename=5448exists($meta->{'file_parent'}) ?5449$meta->{'file_parent'} : unquote($meta->{'filename'});5450my$blamed= href(action =>'blame',5451 file_name =>$linenr_filename,5452 hash_base =>$linenr_commit);5453print"<td class=\"linenr\">";5454print$cgi->a({ -href =>"$blamed#l$orig_lineno",5455-class=>"linenr"},5456 esc_html($lineno));5457print"</td>";5458print"<td class=\"pre\">". esc_html($data) ."</td>\n";5459print"</tr>\n";5460}# end while54615462}54635464# footer5465print"</tbody>\n".5466"</table>\n";# class="blame"5467print"</div>\n";# class="blame_body"5468close$fd5469or print"Reading blob failed\n";54705471 git_footer_html();5472}54735474sub git_blame {5475 git_blame_common();5476}54775478sub git_blame_incremental {5479 git_blame_common('incremental');5480}54815482sub git_blame_data {5483 git_blame_common('data');5484}54855486sub git_tags {5487my$head= git_get_head_hash($project);5488 git_header_html();5489 git_print_page_nav('','',$head,undef,$head);5490 git_print_header_div('summary',$project);54915492my@tagslist= git_get_tags_list();5493if(@tagslist) {5494 git_tags_body(\@tagslist);5495}5496 git_footer_html();5497}54985499sub git_heads {5500my$head= git_get_head_hash($project);5501 git_header_html();5502 git_print_page_nav('','',$head,undef,$head);5503 git_print_header_div('summary',$project);55045505my@headslist= git_get_heads_list();5506if(@headslist) {5507 git_heads_body(\@headslist,$head);5508}5509 git_footer_html();5510}55115512sub git_blob_plain {5513my$type=shift;5514my$expires;55155516if(!defined$hash) {5517if(defined$file_name) {5518my$base=$hash_base|| git_get_head_hash($project);5519$hash= git_get_hash_by_path($base,$file_name,"blob")5520or die_error(404,"Cannot find file");5521}else{5522 die_error(400,"No file name defined");5523}5524}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5525# blobs defined by non-textual hash id's can be cached5526$expires="+1d";5527}55285529open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5530or die_error(500,"Open git-cat-file blob '$hash' failed");55315532# content-type (can include charset)5533$type= blob_contenttype($fd,$file_name,$type);55345535# "save as" filename, even when no $file_name is given5536my$save_as="$hash";5537if(defined$file_name) {5538$save_as=$file_name;5539}elsif($type=~m/^text\//) {5540$save_as.='.txt';5541}55425543# With XSS prevention on, blobs of all types except a few known safe5544# ones are served with "Content-Disposition: attachment" to make sure5545# they don't run in our security domain. For certain image types,5546# blob view writes an <img> tag referring to blob_plain view, and we5547# want to be sure not to break that by serving the image as an5548# attachment (though Firefox 3 doesn't seem to care).5549my$sandbox=$prevent_xss&&5550$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;55515552print$cgi->header(5553-type =>$type,5554-expires =>$expires,5555-content_disposition =>5556($sandbox?'attachment':'inline')5557.'; filename="'.$save_as.'"');5558local$/=undef;5559binmode STDOUT,':raw';5560print<$fd>;5561binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5562close$fd;5563}55645565sub git_blob {5566my$expires;55675568if(!defined$hash) {5569if(defined$file_name) {5570my$base=$hash_base|| git_get_head_hash($project);5571$hash= git_get_hash_by_path($base,$file_name,"blob")5572or die_error(404,"Cannot find file");5573}else{5574 die_error(400,"No file name defined");5575}5576}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5577# blobs defined by non-textual hash id's can be cached5578$expires="+1d";5579}55805581my$have_blame= gitweb_check_feature('blame');5582open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5583or die_error(500,"Couldn't cat$file_name,$hash");5584my$mimetype= blob_mimetype($fd,$file_name);5585# use 'blob_plain' (aka 'raw') view for files that cannot be displayed5586if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {5587close$fd;5588return git_blob_plain($mimetype);5589}5590# we can have blame only for text/* mimetype5591$have_blame&&= ($mimetype=~m!^text/!);55925593my$highlight= gitweb_check_feature('highlight');5594my$syntax= guess_file_syntax($highlight,$mimetype,$file_name);5595$fd= run_highlighter($fd,$highlight,$syntax)5596if$syntax;55975598 git_header_html(undef,$expires);5599my$formats_nav='';5600if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5601if(defined$file_name) {5602if($have_blame) {5603$formats_nav.=5604$cgi->a({-href => href(action=>"blame", -replay=>1)},5605"blame") .5606" | ";5607}5608$formats_nav.=5609$cgi->a({-href => href(action=>"history", -replay=>1)},5610"history") .5611" | ".5612$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5613"raw") .5614" | ".5615$cgi->a({-href => href(action=>"blob",5616 hash_base=>"HEAD", file_name=>$file_name)},5617"HEAD");5618}else{5619$formats_nav.=5620$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5621"raw");5622}5623 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5624 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5625}else{5626print"<div class=\"page_nav\">\n".5627"<br/><br/></div>\n".5628"<div class=\"title\">$hash</div>\n";5629}5630 git_print_page_path($file_name,"blob",$hash_base);5631print"<div class=\"page_body\">\n";5632if($mimetype=~m!^image/!) {5633print qq!<img type="$mimetype"!;5634if($file_name) {5635print qq! alt="$file_name" title="$file_name"!;5636}5637print qq! src="! .5638 href(action=>"blob_plain", hash=>$hash,5639 hash_base=>$hash_base, file_name=>$file_name) .5640 qq!"/>\n!;5641}else{5642my$nr;5643while(my$line= <$fd>) {5644chomp$line;5645$nr++;5646$line= untabify($line);5647printf qq!<div class="pre"><a id="l%i" href="%s#l%i"class="linenr">%4i</a> %s</div>\n!,5648$nr, href(-replay =>1),$nr,$nr,$syntax?$line: esc_html($line, -nbsp=>1);5649}5650}5651close$fd5652or print"Reading blob failed.\n";5653print"</div>";5654 git_footer_html();5655}56565657sub git_tree {5658if(!defined$hash_base) {5659$hash_base="HEAD";5660}5661if(!defined$hash) {5662if(defined$file_name) {5663$hash= git_get_hash_by_path($hash_base,$file_name,"tree");5664}else{5665$hash=$hash_base;5666}5667}5668 die_error(404,"No such tree")unlessdefined($hash);56695670my$show_sizes= gitweb_check_feature('show-sizes');5671my$have_blame= gitweb_check_feature('blame');56725673my@entries= ();5674{5675local$/="\0";5676open my$fd,"-|", git_cmd(),"ls-tree",'-z',5677($show_sizes?'-l': ()),@extra_options,$hash5678or die_error(500,"Open git-ls-tree failed");5679@entries=map{chomp;$_} <$fd>;5680close$fd5681or die_error(404,"Reading tree failed");5682}56835684my$refs= git_get_references();5685my$ref= format_ref_marker($refs,$hash_base);5686 git_header_html();5687my$basedir='';5688if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5689my@views_nav= ();5690if(defined$file_name) {5691push@views_nav,5692$cgi->a({-href => href(action=>"history", -replay=>1)},5693"history"),5694$cgi->a({-href => href(action=>"tree",5695 hash_base=>"HEAD", file_name=>$file_name)},5696"HEAD"),5697}5698my$snapshot_links= format_snapshot_links($hash);5699if(defined$snapshot_links) {5700# FIXME: Should be available when we have no hash base as well.5701push@views_nav,$snapshot_links;5702}5703 git_print_page_nav('tree','',$hash_base,undef,undef,5704join(' | ',@views_nav));5705 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);5706}else{5707undef$hash_base;5708print"<div class=\"page_nav\">\n";5709print"<br/><br/></div>\n";5710print"<div class=\"title\">$hash</div>\n";5711}5712if(defined$file_name) {5713$basedir=$file_name;5714if($basedirne''&&substr($basedir, -1)ne'/') {5715$basedir.='/';5716}5717 git_print_page_path($file_name,'tree',$hash_base);5718}5719print"<div class=\"page_body\">\n";5720print"<table class=\"tree\">\n";5721my$alternate=1;5722# '..' (top directory) link if possible5723if(defined$hash_base&&5724defined$file_name&&$file_name=~m![^/]+$!) {5725if($alternate) {5726print"<tr class=\"dark\">\n";5727}else{5728print"<tr class=\"light\">\n";5729}5730$alternate^=1;57315732my$up=$file_name;5733$up=~s!/?[^/]+$!!;5734undef$upunless$up;5735# based on git_print_tree_entry5736print'<td class="mode">'. mode_str('040000') ."</td>\n";5737print'<td class="size"> </td>'."\n"if$show_sizes;5738print'<td class="list">';5739print$cgi->a({-href => href(action=>"tree",5740 hash_base=>$hash_base,5741 file_name=>$up)},5742"..");5743print"</td>\n";5744print"<td class=\"link\"></td>\n";57455746print"</tr>\n";5747}5748foreachmy$line(@entries) {5749my%t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);57505751if($alternate) {5752print"<tr class=\"dark\">\n";5753}else{5754print"<tr class=\"light\">\n";5755}5756$alternate^=1;57575758 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);57595760print"</tr>\n";5761}5762print"</table>\n".5763"</div>";5764 git_footer_html();5765}57665767sub snapshot_name {5768my($project,$hash) =@_;57695770# path/to/project.git -> project5771# path/to/project/.git -> project5772my$name= to_utf8($project);5773$name=~ s,([^/])/*\.git$,$1,;5774$name= basename($name);5775# sanitize name5776$name=~s/[[:cntrl:]]/?/g;57775778my$ver=$hash;5779if($hash=~/^[0-9a-fA-F]+$/) {5780# shorten SHA-1 hash5781my$full_hash= git_get_full_hash($project,$hash);5782if($full_hash=~/^$hash/&&length($hash) >7) {5783$ver= git_get_short_hash($project,$hash);5784}5785}elsif($hash=~m!^refs/tags/(.*)$!) {5786# tags don't need shortened SHA-1 hash5787$ver=$1;5788}else{5789# branches and other need shortened SHA-1 hash5790if($hash=~m!^refs/(?:heads|remotes)/(.*)$!) {5791$ver=$1;5792}5793$ver.='-'. git_get_short_hash($project,$hash);5794}5795# in case of hierarchical branch names5796$ver=~s!/!.!g;57975798# name = project-version_string5799$name="$name-$ver";58005801returnwantarray? ($name,$name) :$name;5802}58035804sub git_snapshot {5805my$format=$input_params{'snapshot_format'};5806if(!@snapshot_fmts) {5807 die_error(403,"Snapshots not allowed");5808}5809# default to first supported snapshot format5810$format||=$snapshot_fmts[0];5811if($format!~m/^[a-z0-9]+$/) {5812 die_error(400,"Invalid snapshot format parameter");5813}elsif(!exists($known_snapshot_formats{$format})) {5814 die_error(400,"Unknown snapshot format");5815}elsif($known_snapshot_formats{$format}{'disabled'}) {5816 die_error(403,"Snapshot format not allowed");5817}elsif(!grep($_eq$format,@snapshot_fmts)) {5818 die_error(403,"Unsupported snapshot format");5819}58205821my$type= git_get_type("$hash^{}");5822if(!$type) {5823 die_error(404,'Object does not exist');5824}elsif($typeeq'blob') {5825 die_error(400,'Object is not a tree-ish');5826}58275828my($name,$prefix) = snapshot_name($project,$hash);5829my$filename="$name$known_snapshot_formats{$format}{'suffix'}";5830my$cmd= quote_command(5831 git_cmd(),'archive',5832"--format=$known_snapshot_formats{$format}{'format'}",5833"--prefix=$prefix/",$hash);5834if(exists$known_snapshot_formats{$format}{'compressor'}) {5835$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});5836}58375838$filename=~s/(["\\])/\\$1/g;5839print$cgi->header(5840-type =>$known_snapshot_formats{$format}{'type'},5841-content_disposition =>'inline; filename="'.$filename.'"',5842-status =>'200 OK');58435844open my$fd,"-|",$cmd5845or die_error(500,"Execute git-archive failed");5846binmode STDOUT,':raw';5847print<$fd>;5848binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5849close$fd;5850}58515852sub git_log_generic {5853my($fmt_name,$body_subr,$base,$parent,$file_name,$file_hash) =@_;58545855my$head= git_get_head_hash($project);5856if(!defined$base) {5857$base=$head;5858}5859if(!defined$page) {5860$page=0;5861}5862my$refs= git_get_references();58635864my$commit_hash=$base;5865if(defined$parent) {5866$commit_hash="$parent..$base";5867}5868my@commitlist=5869 parse_commits($commit_hash,101, (100*$page),5870defined$file_name? ($file_name,"--full-history") : ());58715872my$ftype;5873if(!defined$file_hash&&defined$file_name) {5874# some commits could have deleted file in question,5875# and not have it in tree, but one of them has to have it5876for(my$i=0;$i<@commitlist;$i++) {5877$file_hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5878last ifdefined$file_hash;5879}5880}5881if(defined$file_hash) {5882$ftype= git_get_type($file_hash);5883}5884if(defined$file_name&& !defined$ftype) {5885 die_error(500,"Unknown type of object");5886}5887my%co;5888if(defined$file_name) {5889%co= parse_commit($base)5890or die_error(404,"Unknown commit object");5891}589258935894my$paging_nav= format_paging_nav($fmt_name,$page,$#commitlist>=100);5895my$next_link='';5896if($#commitlist>=100) {5897$next_link=5898$cgi->a({-href => href(-replay=>1, page=>$page+1),5899-accesskey =>"n", -title =>"Alt-n"},"next");5900}5901my$patch_max= gitweb_get_feature('patches');5902if($patch_max&& !defined$file_name) {5903if($patch_max<0||@commitlist<=$patch_max) {5904$paging_nav.=" ⋅ ".5905$cgi->a({-href => href(action=>"patches", -replay=>1)},5906"patches");5907}5908}59095910 git_header_html();5911 git_print_page_nav($fmt_name,'',$hash,$hash,$hash,$paging_nav);5912if(defined$file_name) {5913 git_print_header_div('commit', esc_html($co{'title'}),$base);5914}else{5915 git_print_header_div('summary',$project)5916}5917 git_print_page_path($file_name,$ftype,$hash_base)5918if(defined$file_name);59195920$body_subr->(\@commitlist,0,99,$refs,$next_link,5921$file_name,$file_hash,$ftype);59225923 git_footer_html();5924}59255926sub git_log {5927 git_log_generic('log', \&git_log_body,5928$hash,$hash_parent);5929}59305931sub git_commit {5932$hash||=$hash_base||"HEAD";5933my%co= parse_commit($hash)5934or die_error(404,"Unknown commit object");59355936my$parent=$co{'parent'};5937my$parents=$co{'parents'};# listref59385939# we need to prepare $formats_nav before any parameter munging5940my$formats_nav;5941if(!defined$parent) {5942# --root commitdiff5943$formats_nav.='(initial)';5944}elsif(@$parents==1) {5945# single parent commit5946$formats_nav.=5947'(parent: '.5948$cgi->a({-href => href(action=>"commit",5949 hash=>$parent)},5950 esc_html(substr($parent,0,7))) .5951')';5952}else{5953# merge commit5954$formats_nav.=5955'(merge: '.5956join(' ',map{5957$cgi->a({-href => href(action=>"commit",5958 hash=>$_)},5959 esc_html(substr($_,0,7)));5960}@$parents) .5961')';5962}5963if(gitweb_check_feature('patches') &&@$parents<=1) {5964$formats_nav.=" | ".5965$cgi->a({-href => href(action=>"patch", -replay=>1)},5966"patch");5967}59685969if(!defined$parent) {5970$parent="--root";5971}5972my@difftree;5973open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5974@diff_opts,5975(@$parents<=1?$parent:'-c'),5976$hash,"--"5977or die_error(500,"Open git-diff-tree failed");5978@difftree=map{chomp;$_} <$fd>;5979close$fdor die_error(404,"Reading git-diff-tree failed");59805981# non-textual hash id's can be cached5982my$expires;5983if($hash=~m/^[0-9a-fA-F]{40}$/) {5984$expires="+1d";5985}5986my$refs= git_get_references();5987my$ref= format_ref_marker($refs,$co{'id'});59885989 git_header_html(undef,$expires);5990 git_print_page_nav('commit','',5991$hash,$co{'tree'},$hash,5992$formats_nav);59935994if(defined$co{'parent'}) {5995 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5996}else{5997 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5998}5999print"<div class=\"title_text\">\n".6000"<table class=\"object_header\">\n";6001 git_print_authorship_rows(\%co);6002print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";6003print"<tr>".6004"<td>tree</td>".6005"<td class=\"sha1\">".6006$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),6007class=>"list"},$co{'tree'}) .6008"</td>".6009"<td class=\"link\">".6010$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},6011"tree");6012my$snapshot_links= format_snapshot_links($hash);6013if(defined$snapshot_links) {6014print" | ".$snapshot_links;6015}6016print"</td>".6017"</tr>\n";60186019foreachmy$par(@$parents) {6020print"<tr>".6021"<td>parent</td>".6022"<td class=\"sha1\">".6023$cgi->a({-href => href(action=>"commit", hash=>$par),6024class=>"list"},$par) .6025"</td>".6026"<td class=\"link\">".6027$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .6028" | ".6029$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .6030"</td>".6031"</tr>\n";6032}6033print"</table>".6034"</div>\n";60356036print"<div class=\"page_body\">\n";6037 git_print_log($co{'comment'});6038print"</div>\n";60396040 git_difftree_body(\@difftree,$hash,@$parents);60416042 git_footer_html();6043}60446045sub git_object {6046# object is defined by:6047# - hash or hash_base alone6048# - hash_base and file_name6049my$type;60506051# - hash or hash_base alone6052if($hash|| ($hash_base&& !defined$file_name)) {6053my$object_id=$hash||$hash_base;60546055open my$fd,"-|", quote_command(6056 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'6057or die_error(404,"Object does not exist");6058$type= <$fd>;6059chomp$type;6060close$fd6061or die_error(404,"Object does not exist");60626063# - hash_base and file_name6064}elsif($hash_base&&defined$file_name) {6065$file_name=~ s,/+$,,;60666067system(git_cmd(),"cat-file",'-e',$hash_base) ==06068or die_error(404,"Base object does not exist");60696070# here errors should not hapen6071open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name6072or die_error(500,"Open git-ls-tree failed");6073my$line= <$fd>;6074close$fd;60756076#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'6077unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {6078 die_error(404,"File or directory for given base does not exist");6079}6080$type=$2;6081$hash=$3;6082}else{6083 die_error(400,"Not enough information to find object");6084}60856086print$cgi->redirect(-uri => href(action=>$type, -full=>1,6087 hash=>$hash, hash_base=>$hash_base,6088 file_name=>$file_name),6089-status =>'302 Found');6090}60916092sub git_blobdiff {6093my$format=shift||'html';60946095my$fd;6096my@difftree;6097my%diffinfo;6098my$expires;60996100# preparing $fd and %diffinfo for git_patchset_body6101# new style URI6102if(defined$hash_base&&defined$hash_parent_base) {6103if(defined$file_name) {6104# read raw output6105open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6106$hash_parent_base,$hash_base,6107"--", (defined$file_parent?$file_parent: ()),$file_name6108or die_error(500,"Open git-diff-tree failed");6109@difftree=map{chomp;$_} <$fd>;6110close$fd6111or die_error(404,"Reading git-diff-tree failed");6112@difftree6113or die_error(404,"Blob diff not found");61146115}elsif(defined$hash&&6116$hash=~/[0-9a-fA-F]{40}/) {6117# try to find filename from $hash61186119# read filtered raw output6120open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6121$hash_parent_base,$hash_base,"--"6122or die_error(500,"Open git-diff-tree failed");6123@difftree=6124# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'6125# $hash == to_id6126grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}6127map{chomp;$_} <$fd>;6128close$fd6129or die_error(404,"Reading git-diff-tree failed");6130@difftree6131or die_error(404,"Blob diff not found");61326133}else{6134 die_error(400,"Missing one of the blob diff parameters");6135}61366137if(@difftree>1) {6138 die_error(400,"Ambiguous blob diff specification");6139}61406141%diffinfo= parse_difftree_raw_line($difftree[0]);6142$file_parent||=$diffinfo{'from_file'} ||$file_name;6143$file_name||=$diffinfo{'to_file'};61446145$hash_parent||=$diffinfo{'from_id'};6146$hash||=$diffinfo{'to_id'};61476148# non-textual hash id's can be cached6149if($hash_base=~m/^[0-9a-fA-F]{40}$/&&6150$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {6151$expires='+1d';6152}61536154# open patch output6155open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6156'-p', ($formateq'html'?"--full-index": ()),6157$hash_parent_base,$hash_base,6158"--", (defined$file_parent?$file_parent: ()),$file_name6159or die_error(500,"Open git-diff-tree failed");6160}61616162# old/legacy style URI -- not generated anymore since 1.4.3.6163if(!%diffinfo) {6164 die_error('404 Not Found',"Missing one of the blob diff parameters")6165}61666167# header6168if($formateq'html') {6169my$formats_nav=6170$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},6171"raw");6172 git_header_html(undef,$expires);6173if(defined$hash_base&& (my%co= parse_commit($hash_base))) {6174 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);6175 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);6176}else{6177print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";6178print"<div class=\"title\">$hashvs$hash_parent</div>\n";6179}6180if(defined$file_name) {6181 git_print_page_path($file_name,"blob",$hash_base);6182}else{6183print"<div class=\"page_path\"></div>\n";6184}61856186}elsif($formateq'plain') {6187print$cgi->header(6188-type =>'text/plain',6189-charset =>'utf-8',6190-expires =>$expires,6191-content_disposition =>'inline; filename="'."$file_name".'.patch"');61926193print"X-Git-Url: ".$cgi->self_url() ."\n\n";61946195}else{6196 die_error(400,"Unknown blobdiff format");6197}61986199# patch6200if($formateq'html') {6201print"<div class=\"page_body\">\n";62026203 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);6204close$fd;62056206print"</div>\n";# class="page_body"6207 git_footer_html();62086209}else{6210while(my$line= <$fd>) {6211$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;6212$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;62136214print$line;62156216last if$line=~m!^\+\+\+!;6217}6218local$/=undef;6219print<$fd>;6220close$fd;6221}6222}62236224sub git_blobdiff_plain {6225 git_blobdiff('plain');6226}62276228sub git_commitdiff {6229my%params=@_;6230my$format=$params{-format} ||'html';62316232my($patch_max) = gitweb_get_feature('patches');6233if($formateq'patch') {6234 die_error(403,"Patch view not allowed")unless$patch_max;6235}62366237$hash||=$hash_base||"HEAD";6238my%co= parse_commit($hash)6239or die_error(404,"Unknown commit object");62406241# choose format for commitdiff for merge6242if(!defined$hash_parent&& @{$co{'parents'}} >1) {6243$hash_parent='--cc';6244}6245# we need to prepare $formats_nav before almost any parameter munging6246my$formats_nav;6247if($formateq'html') {6248$formats_nav=6249$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},6250"raw");6251if($patch_max&& @{$co{'parents'}} <=1) {6252$formats_nav.=" | ".6253$cgi->a({-href => href(action=>"patch", -replay=>1)},6254"patch");6255}62566257if(defined$hash_parent&&6258$hash_parentne'-c'&&$hash_parentne'--cc') {6259# commitdiff with two commits given6260my$hash_parent_short=$hash_parent;6261if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {6262$hash_parent_short=substr($hash_parent,0,7);6263}6264$formats_nav.=6265' (from';6266for(my$i=0;$i< @{$co{'parents'}};$i++) {6267if($co{'parents'}[$i]eq$hash_parent) {6268$formats_nav.=' parent '. ($i+1);6269last;6270}6271}6272$formats_nav.=': '.6273$cgi->a({-href => href(action=>"commitdiff",6274 hash=>$hash_parent)},6275 esc_html($hash_parent_short)) .6276')';6277}elsif(!$co{'parent'}) {6278# --root commitdiff6279$formats_nav.=' (initial)';6280}elsif(scalar@{$co{'parents'}} ==1) {6281# single parent commit6282$formats_nav.=6283' (parent: '.6284$cgi->a({-href => href(action=>"commitdiff",6285 hash=>$co{'parent'})},6286 esc_html(substr($co{'parent'},0,7))) .6287')';6288}else{6289# merge commit6290if($hash_parenteq'--cc') {6291$formats_nav.=' | '.6292$cgi->a({-href => href(action=>"commitdiff",6293 hash=>$hash, hash_parent=>'-c')},6294'combined');6295}else{# $hash_parent eq '-c'6296$formats_nav.=' | '.6297$cgi->a({-href => href(action=>"commitdiff",6298 hash=>$hash, hash_parent=>'--cc')},6299'compact');6300}6301$formats_nav.=6302' (merge: '.6303join(' ',map{6304$cgi->a({-href => href(action=>"commitdiff",6305 hash=>$_)},6306 esc_html(substr($_,0,7)));6307} @{$co{'parents'}} ) .6308')';6309}6310}63116312my$hash_parent_param=$hash_parent;6313if(!defined$hash_parent_param) {6314# --cc for multiple parents, --root for parentless6315$hash_parent_param=6316@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';6317}63186319# read commitdiff6320my$fd;6321my@difftree;6322if($formateq'html') {6323open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6324"--no-commit-id","--patch-with-raw","--full-index",6325$hash_parent_param,$hash,"--"6326or die_error(500,"Open git-diff-tree failed");63276328while(my$line= <$fd>) {6329chomp$line;6330# empty line ends raw part of diff-tree output6331last unless$line;6332push@difftree,scalar parse_difftree_raw_line($line);6333}63346335}elsif($formateq'plain') {6336open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6337'-p',$hash_parent_param,$hash,"--"6338or die_error(500,"Open git-diff-tree failed");6339}elsif($formateq'patch') {6340# For commit ranges, we limit the output to the number of6341# patches specified in the 'patches' feature.6342# For single commits, we limit the output to a single patch,6343# diverging from the git-format-patch default.6344my@commit_spec= ();6345if($hash_parent) {6346if($patch_max>0) {6347push@commit_spec,"-$patch_max";6348}6349push@commit_spec,'-n',"$hash_parent..$hash";6350}else{6351if($params{-single}) {6352push@commit_spec,'-1';6353}else{6354if($patch_max>0) {6355push@commit_spec,"-$patch_max";6356}6357push@commit_spec,"-n";6358}6359push@commit_spec,'--root',$hash;6360}6361open$fd,"-|", git_cmd(),"format-patch",@diff_opts,6362'--encoding=utf8','--stdout',@commit_spec6363or die_error(500,"Open git-format-patch failed");6364}else{6365 die_error(400,"Unknown commitdiff format");6366}63676368# non-textual hash id's can be cached6369my$expires;6370if($hash=~m/^[0-9a-fA-F]{40}$/) {6371$expires="+1d";6372}63736374# write commit message6375if($formateq'html') {6376my$refs= git_get_references();6377my$ref= format_ref_marker($refs,$co{'id'});63786379 git_header_html(undef,$expires);6380 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);6381 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);6382print"<div class=\"title_text\">\n".6383"<table class=\"object_header\">\n";6384 git_print_authorship_rows(\%co);6385print"</table>".6386"</div>\n";6387print"<div class=\"page_body\">\n";6388if(@{$co{'comment'}} >1) {6389print"<div class=\"log\">\n";6390 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);6391print"</div>\n";# class="log"6392}63936394}elsif($formateq'plain') {6395my$refs= git_get_references("tags");6396my$tagname= git_get_rev_name_tags($hash);6397my$filename= basename($project) ."-$hash.patch";63986399print$cgi->header(6400-type =>'text/plain',6401-charset =>'utf-8',6402-expires =>$expires,6403-content_disposition =>'inline; filename="'."$filename".'"');6404my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});6405print"From: ". to_utf8($co{'author'}) ."\n";6406print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";6407print"Subject: ". to_utf8($co{'title'}) ."\n";64086409print"X-Git-Tag:$tagname\n"if$tagname;6410print"X-Git-Url: ".$cgi->self_url() ."\n\n";64116412foreachmy$line(@{$co{'comment'}}) {6413print to_utf8($line) ."\n";6414}6415print"---\n\n";6416}elsif($formateq'patch') {6417my$filename= basename($project) ."-$hash.patch";64186419print$cgi->header(6420-type =>'text/plain',6421-charset =>'utf-8',6422-expires =>$expires,6423-content_disposition =>'inline; filename="'."$filename".'"');6424}64256426# write patch6427if($formateq'html') {6428my$use_parents= !defined$hash_parent||6429$hash_parenteq'-c'||$hash_parenteq'--cc';6430 git_difftree_body(\@difftree,$hash,6431$use_parents? @{$co{'parents'}} :$hash_parent);6432print"<br/>\n";64336434 git_patchset_body($fd, \@difftree,$hash,6435$use_parents? @{$co{'parents'}} :$hash_parent);6436close$fd;6437print"</div>\n";# class="page_body"6438 git_footer_html();64396440}elsif($formateq'plain') {6441local$/=undef;6442print<$fd>;6443close$fd6444or print"Reading git-diff-tree failed\n";6445}elsif($formateq'patch') {6446local$/=undef;6447print<$fd>;6448close$fd6449or print"Reading git-format-patch failed\n";6450}6451}64526453sub git_commitdiff_plain {6454 git_commitdiff(-format =>'plain');6455}64566457# format-patch-style patches6458sub git_patch {6459 git_commitdiff(-format =>'patch', -single =>1);6460}64616462sub git_patches {6463 git_commitdiff(-format =>'patch');6464}64656466sub git_history {6467 git_log_generic('history', \&git_history_body,6468$hash_base,$hash_parent_base,6469$file_name,$hash);6470}64716472sub git_search {6473 gitweb_check_feature('search')or die_error(403,"Search is disabled");6474if(!defined$searchtext) {6475 die_error(400,"Text field is empty");6476}6477if(!defined$hash) {6478$hash= git_get_head_hash($project);6479}6480my%co= parse_commit($hash);6481if(!%co) {6482 die_error(404,"Unknown commit object");6483}6484if(!defined$page) {6485$page=0;6486}64876488$searchtype||='commit';6489if($searchtypeeq'pickaxe') {6490# pickaxe may take all resources of your box and run for several minutes6491# with every query - so decide by yourself how public you make this feature6492 gitweb_check_feature('pickaxe')6493or die_error(403,"Pickaxe is disabled");6494}6495if($searchtypeeq'grep') {6496 gitweb_check_feature('grep')6497or die_error(403,"Grep is disabled");6498}64996500 git_header_html();65016502if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {6503my$greptype;6504if($searchtypeeq'commit') {6505$greptype="--grep=";6506}elsif($searchtypeeq'author') {6507$greptype="--author=";6508}elsif($searchtypeeq'committer') {6509$greptype="--committer=";6510}6511$greptype.=$searchtext;6512my@commitlist= parse_commits($hash,101, (100*$page),undef,6513$greptype,'--regexp-ignore-case',6514$search_use_regexp?'--extended-regexp':'--fixed-strings');65156516my$paging_nav='';6517if($page>0) {6518$paging_nav.=6519$cgi->a({-href => href(action=>"search", hash=>$hash,6520 searchtext=>$searchtext,6521 searchtype=>$searchtype)},6522"first");6523$paging_nav.=" ⋅ ".6524$cgi->a({-href => href(-replay=>1, page=>$page-1),6525-accesskey =>"p", -title =>"Alt-p"},"prev");6526}else{6527$paging_nav.="first";6528$paging_nav.=" ⋅ prev";6529}6530my$next_link='';6531if($#commitlist>=100) {6532$next_link=6533$cgi->a({-href => href(-replay=>1, page=>$page+1),6534-accesskey =>"n", -title =>"Alt-n"},"next");6535$paging_nav.=" ⋅$next_link";6536}else{6537$paging_nav.=" ⋅ next";6538}65396540 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);6541 git_print_header_div('commit', esc_html($co{'title'}),$hash);6542if($page==0&& !@commitlist) {6543print"<p>No match.</p>\n";6544}else{6545 git_search_grep_body(\@commitlist,0,99,$next_link);6546}6547}65486549if($searchtypeeq'pickaxe') {6550 git_print_page_nav('','',$hash,$co{'tree'},$hash);6551 git_print_header_div('commit', esc_html($co{'title'}),$hash);65526553print"<table class=\"pickaxe search\">\n";6554my$alternate=1;6555local$/="\n";6556open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,6557'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",6558($search_use_regexp?'--pickaxe-regex': ());6559undef%co;6560my@files;6561while(my$line= <$fd>) {6562chomp$line;6563next unless$line;65646565my%set= parse_difftree_raw_line($line);6566if(defined$set{'commit'}) {6567# finish previous commit6568if(%co) {6569print"</td>\n".6570"<td class=\"link\">".6571$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6572" | ".6573$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6574print"</td>\n".6575"</tr>\n";6576}65776578if($alternate) {6579print"<tr class=\"dark\">\n";6580}else{6581print"<tr class=\"light\">\n";6582}6583$alternate^=1;6584%co= parse_commit($set{'commit'});6585my$author= chop_and_escape_str($co{'author_name'},15,5);6586print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6587"<td><i>$author</i></td>\n".6588"<td>".6589$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6590-class=>"list subject"},6591 chop_and_escape_str($co{'title'},50) ."<br/>");6592}elsif(defined$set{'to_id'}) {6593next if($set{'to_id'} =~m/^0{40}$/);65946595print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6596 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6597-class=>"list"},6598"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6599"<br/>\n";6600}6601}6602close$fd;66036604# finish last commit (warning: repetition!)6605if(%co) {6606print"</td>\n".6607"<td class=\"link\">".6608$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6609" | ".6610$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6611print"</td>\n".6612"</tr>\n";6613}66146615print"</table>\n";6616}66176618if($searchtypeeq'grep') {6619 git_print_page_nav('','',$hash,$co{'tree'},$hash);6620 git_print_header_div('commit', esc_html($co{'title'}),$hash);66216622print"<table class=\"grep_search\">\n";6623my$alternate=1;6624my$matches=0;6625local$/="\n";6626open my$fd,"-|", git_cmd(),'grep','-n',6627$search_use_regexp? ('-E','-i') :'-F',6628$searchtext,$co{'tree'};6629my$lastfile='';6630while(my$line= <$fd>) {6631chomp$line;6632my($file,$lno,$ltext,$binary);6633last if($matches++>1000);6634if($line=~/^Binary file (.+) matches$/) {6635$file=$1;6636$binary=1;6637}else{6638(undef,$file,$lno,$ltext) =split(/:/,$line,4);6639}6640if($filene$lastfile) {6641$lastfileand print"</td></tr>\n";6642if($alternate++) {6643print"<tr class=\"dark\">\n";6644}else{6645print"<tr class=\"light\">\n";6646}6647print"<td class=\"list\">".6648$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6649 file_name=>"$file"),6650-class=>"list"}, esc_path($file));6651print"</td><td>\n";6652$lastfile=$file;6653}6654if($binary) {6655print"<div class=\"binary\">Binary file</div>\n";6656}else{6657$ltext= untabify($ltext);6658if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6659$ltext= esc_html($1, -nbsp=>1);6660$ltext.='<span class="match">';6661$ltext.= esc_html($2, -nbsp=>1);6662$ltext.='</span>';6663$ltext.= esc_html($3, -nbsp=>1);6664}else{6665$ltext= esc_html($ltext, -nbsp=>1);6666}6667print"<div class=\"pre\">".6668$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6669 file_name=>"$file").'#l'.$lno,6670-class=>"linenr"},sprintf('%4i',$lno))6671.' '.$ltext."</div>\n";6672}6673}6674if($lastfile) {6675print"</td></tr>\n";6676if($matches>1000) {6677print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6678}6679}else{6680print"<div class=\"diff nodifferences\">No matches found</div>\n";6681}6682close$fd;66836684print"</table>\n";6685}6686 git_footer_html();6687}66886689sub git_search_help {6690 git_header_html();6691 git_print_page_nav('','',$hash,$hash,$hash);6692print<<EOT;6693<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without6694regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,6695the pattern entered is recognized as the POSIX extended6696<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case6697insensitive).</p>6698<dl>6699<dt><b>commit</b></dt>6700<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>6701EOT6702my$have_grep= gitweb_check_feature('grep');6703if($have_grep) {6704print<<EOT;6705<dt><b>grep</b></dt>6706<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing6707 a different one) are searched for the given pattern. On large trees, this search can take6708a while and put some strain on the server, so please use it with some consideration. Note that6709due to git-grep peculiarity, currently if regexp mode is turned off, the matches are6710case-sensitive.</dd>6711EOT6712}6713print<<EOT;6714<dt><b>author</b></dt>6715<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>6716<dt><b>committer</b></dt>6717<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>6718EOT6719my$have_pickaxe= gitweb_check_feature('pickaxe');6720if($have_pickaxe) {6721print<<EOT;6722<dt><b>pickaxe</b></dt>6723<dd>All commits that caused the string to appear or disappear from any file (changes that6724added, removed or "modified" the string) will be listed. This search can take a while and6725takes a lot of strain on the server, so please use it wisely. Note that since you may be6726interested even in changes just changing the case as well, this search is case sensitive.</dd>6727EOT6728}6729print"</dl>\n";6730 git_footer_html();6731}67326733sub git_shortlog {6734 git_log_generic('shortlog', \&git_shortlog_body,6735$hash,$hash_parent);6736}67376738## ......................................................................6739## feeds (RSS, Atom; OPML)67406741sub git_feed {6742my$format=shift||'atom';6743my$have_blame= gitweb_check_feature('blame');67446745# Atom: http://www.atomenabled.org/developers/syndication/6746# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ6747if($formatne'rss'&&$formatne'atom') {6748 die_error(400,"Unknown web feed format");6749}67506751# log/feed of current (HEAD) branch, log of given branch, history of file/directory6752my$head=$hash||'HEAD';6753my@commitlist= parse_commits($head,150,0,$file_name);67546755my%latest_commit;6756my%latest_date;6757my$content_type="application/$format+xml";6758if(defined$cgi->http('HTTP_ACCEPT') &&6759$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {6760# browser (feed reader) prefers text/xml6761$content_type='text/xml';6762}6763if(defined($commitlist[0])) {6764%latest_commit= %{$commitlist[0]};6765my$latest_epoch=$latest_commit{'committer_epoch'};6766%latest_date= parse_date($latest_epoch);6767my$if_modified=$cgi->http('IF_MODIFIED_SINCE');6768if(defined$if_modified) {6769my$since;6770if(eval{require HTTP::Date;1; }) {6771$since= HTTP::Date::str2time($if_modified);6772}elsif(eval{require Time::ParseDate;1; }) {6773$since= Time::ParseDate::parsedate($if_modified, GMT =>1);6774}6775if(defined$since&&$latest_epoch<=$since) {6776print$cgi->header(6777-type =>$content_type,6778-charset =>'utf-8',6779-last_modified =>$latest_date{'rfc2822'},6780-status =>'304 Not Modified');6781return;6782}6783}6784print$cgi->header(6785-type =>$content_type,6786-charset =>'utf-8',6787-last_modified =>$latest_date{'rfc2822'});6788}else{6789print$cgi->header(6790-type =>$content_type,6791-charset =>'utf-8');6792}67936794# Optimization: skip generating the body if client asks only6795# for Last-Modified date.6796return if($cgi->request_method()eq'HEAD');67976798# header variables6799my$title="$site_name-$project/$action";6800my$feed_type='log';6801if(defined$hash) {6802$title.=" - '$hash'";6803$feed_type='branch log';6804if(defined$file_name) {6805$title.=" ::$file_name";6806$feed_type='history';6807}6808}elsif(defined$file_name) {6809$title.=" -$file_name";6810$feed_type='history';6811}6812$title.="$feed_type";6813my$descr= git_get_project_description($project);6814if(defined$descr) {6815$descr= esc_html($descr);6816}else{6817$descr="$project".6818($formateq'rss'?'RSS':'Atom') .6819" feed";6820}6821my$owner= git_get_project_owner($project);6822$owner= esc_html($owner);68236824#header6825my$alt_url;6826if(defined$file_name) {6827$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);6828}elsif(defined$hash) {6829$alt_url= href(-full=>1, action=>"log", hash=>$hash);6830}else{6831$alt_url= href(-full=>1, action=>"summary");6832}6833print qq!<?xml version="1.0" encoding="utf-8"?>\n!;6834if($formateq'rss') {6835print<<XML;6836<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">6837<channel>6838XML6839print"<title>$title</title>\n".6840"<link>$alt_url</link>\n".6841"<description>$descr</description>\n".6842"<language>en</language>\n".6843# project owner is responsible for 'editorial' content6844"<managingEditor>$owner</managingEditor>\n";6845if(defined$logo||defined$favicon) {6846# prefer the logo to the favicon, since RSS6847# doesn't allow both6848my$img= esc_url($logo||$favicon);6849print"<image>\n".6850"<url>$img</url>\n".6851"<title>$title</title>\n".6852"<link>$alt_url</link>\n".6853"</image>\n";6854}6855if(%latest_date) {6856print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";6857print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";6858}6859print"<generator>gitweb v.$version/$git_version</generator>\n";6860}elsif($formateq'atom') {6861print<<XML;6862<feed xmlns="http://www.w3.org/2005/Atom">6863XML6864print"<title>$title</title>\n".6865"<subtitle>$descr</subtitle>\n".6866'<link rel="alternate" type="text/html" href="'.6867$alt_url.'" />'."\n".6868'<link rel="self" type="'.$content_type.'" href="'.6869$cgi->self_url() .'" />'."\n".6870"<id>". href(-full=>1) ."</id>\n".6871# use project owner for feed author6872"<author><name>$owner</name></author>\n";6873if(defined$favicon) {6874print"<icon>". esc_url($favicon) ."</icon>\n";6875}6876if(defined$logo_url) {6877# not twice as wide as tall: 72 x 27 pixels6878print"<logo>". esc_url($logo) ."</logo>\n";6879}6880if(!%latest_date) {6881# dummy date to keep the feed valid until commits trickle in:6882print"<updated>1970-01-01T00:00:00Z</updated>\n";6883}else{6884print"<updated>$latest_date{'iso-8601'}</updated>\n";6885}6886print"<generator version='$version/$git_version'>gitweb</generator>\n";6887}68886889# contents6890for(my$i=0;$i<=$#commitlist;$i++) {6891my%co= %{$commitlist[$i]};6892my$commit=$co{'id'};6893# we read 150, we always show 30 and the ones more recent than 48 hours6894if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6895last;6896}6897my%cd= parse_date($co{'author_epoch'});68986899# get list of changed files6900open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6901$co{'parent'} ||"--root",6902$co{'id'},"--", (defined$file_name?$file_name: ())6903ornext;6904my@difftree=map{chomp;$_} <$fd>;6905close$fd6906ornext;69076908# print element (entry, item)6909my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6910if($formateq'rss') {6911print"<item>\n".6912"<title>". esc_html($co{'title'}) ."</title>\n".6913"<author>". esc_html($co{'author'}) ."</author>\n".6914"<pubDate>$cd{'rfc2822'}</pubDate>\n".6915"<guid isPermaLink=\"true\">$co_url</guid>\n".6916"<link>$co_url</link>\n".6917"<description>". esc_html($co{'title'}) ."</description>\n".6918"<content:encoded>".6919"<![CDATA[\n";6920}elsif($formateq'atom') {6921print"<entry>\n".6922"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6923"<updated>$cd{'iso-8601'}</updated>\n".6924"<author>\n".6925" <name>". esc_html($co{'author_name'}) ."</name>\n";6926if($co{'author_email'}) {6927print" <email>". esc_html($co{'author_email'}) ."</email>\n";6928}6929print"</author>\n".6930# use committer for contributor6931"<contributor>\n".6932" <name>". esc_html($co{'committer_name'}) ."</name>\n";6933if($co{'committer_email'}) {6934print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6935}6936print"</contributor>\n".6937"<published>$cd{'iso-8601'}</published>\n".6938"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6939"<id>$co_url</id>\n".6940"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6941"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6942}6943my$comment=$co{'comment'};6944print"<pre>\n";6945foreachmy$line(@$comment) {6946$line= esc_html($line);6947print"$line\n";6948}6949print"</pre><ul>\n";6950foreachmy$difftree_line(@difftree) {6951my%difftree= parse_difftree_raw_line($difftree_line);6952next if!$difftree{'from_id'};69536954my$file=$difftree{'file'} ||$difftree{'to_file'};69556956print"<li>".6957"[".6958$cgi->a({-href => href(-full=>1, action=>"blobdiff",6959 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6960 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6961 file_name=>$file, file_parent=>$difftree{'from_file'}),6962-title =>"diff"},'D');6963if($have_blame) {6964print$cgi->a({-href => href(-full=>1, action=>"blame",6965 file_name=>$file, hash_base=>$commit),6966-title =>"blame"},'B');6967}6968# if this is not a feed of a file history6969if(!defined$file_name||$file_namene$file) {6970print$cgi->a({-href => href(-full=>1, action=>"history",6971 file_name=>$file, hash=>$commit),6972-title =>"history"},'H');6973}6974$file= esc_path($file);6975print"] ".6976"$file</li>\n";6977}6978if($formateq'rss') {6979print"</ul>]]>\n".6980"</content:encoded>\n".6981"</item>\n";6982}elsif($formateq'atom') {6983print"</ul>\n</div>\n".6984"</content>\n".6985"</entry>\n";6986}6987}69886989# end of feed6990if($formateq'rss') {6991print"</channel>\n</rss>\n";6992}elsif($formateq'atom') {6993print"</feed>\n";6994}6995}69966997sub git_rss {6998 git_feed('rss');6999}70007001sub git_atom {7002 git_feed('atom');7003}70047005sub git_opml {7006my@list= git_get_projects_list();70077008print$cgi->header(7009-type =>'text/xml',7010-charset =>'utf-8',7011-content_disposition =>'inline; filename="opml.xml"');70127013print<<XML;7014<?xml version="1.0" encoding="utf-8"?>7015<opml version="1.0">7016<head>7017 <title>$site_nameOPML Export</title>7018</head>7019<body>7020<outline text="git RSS feeds">7021XML70227023foreachmy$pr(@list) {7024my%proj=%$pr;7025my$head= git_get_head_hash($proj{'path'});7026if(!defined$head) {7027next;7028}7029$git_dir="$projectroot/$proj{'path'}";7030my%co= parse_commit($head);7031if(!%co) {7032next;7033}70347035my$path= esc_html(chop_str($proj{'path'},25,5));7036my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);7037my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);7038print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";7039}7040print<<XML;7041</outline>7042</body>7043</opml>7044XML7045}