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 10use strict; 11use warnings; 12use CGI qw(:standard :escapeHTML -nosticky); 13use CGI::Util qw(unescape); 14use CGI::Carp qw(fatalsToBrowser); 15use Encode; 16use Fcntl ':mode'; 17use File::Find qw(); 18use File::Basename qw(basename); 19binmode STDOUT,':utf8'; 20 21BEGIN{ 22 CGI->compile()if$ENV{'MOD_PERL'}; 23} 24 25our$cgi= new CGI; 26our$version="++GIT_VERSION++"; 27our$my_url=$cgi->url(); 28our$my_uri=$cgi->url(-absolute =>1); 29 30# Base URL for relative URLs in gitweb ($logo, $favicon, ...), 31# needed and used only for URLs with nonempty PATH_INFO 32our$base_url=$my_url; 33 34# When the script is used as DirectoryIndex, the URL does not contain the name 35# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we 36# have to do it ourselves. We make $path_info global because it's also used 37# later on. 38# 39# Another issue with the script being the DirectoryIndex is that the resulting 40# $my_url data is not the full script URL: this is good, because we want 41# generated links to keep implying the script name if it wasn't explicitly 42# indicated in the URL we're handling, but it means that $my_url cannot be used 43# as base URL. 44# Therefore, if we needed to strip PATH_INFO, then we know that we have 45# to build the base URL ourselves: 46our$path_info=$ENV{"PATH_INFO"}; 47if($path_info) { 48if($my_url=~ s,\Q$path_info\E$,, && 49$my_uri=~ s,\Q$path_info\E$,, && 50defined$ENV{'SCRIPT_NAME'}) { 51$base_url=$cgi->url(-base =>1) .$ENV{'SCRIPT_NAME'}; 52} 53} 54 55# core git executable to use 56# this can just be "git" if your webserver has a sensible PATH 57our$GIT="++GIT_BINDIR++/git"; 58 59# absolute fs-path which will be prepended to the project path 60#our $projectroot = "/pub/scm"; 61our$projectroot="++GITWEB_PROJECTROOT++"; 62 63# fs traversing limit for getting project list 64# the number is relative to the projectroot 65our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 66 67# target of the home link on top of all pages 68our$home_link=$my_uri||"/"; 69 70# string of the home link on top of all pages 71our$home_link_str="++GITWEB_HOME_LINK_STR++"; 72 73# name of your site or organization to appear in page titles 74# replace this with something more descriptive for clearer bookmarks 75our$site_name="++GITWEB_SITENAME++" 76|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 77 78# filename of html text to include at top of each page 79our$site_header="++GITWEB_SITE_HEADER++"; 80# html text to include at home page 81our$home_text="++GITWEB_HOMETEXT++"; 82# filename of html text to include at bottom of each page 83our$site_footer="++GITWEB_SITE_FOOTER++"; 84 85# URI of stylesheets 86our@stylesheets= ("++GITWEB_CSS++"); 87# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 88our$stylesheet=undef; 89# URI of GIT logo (72x27 size) 90our$logo="++GITWEB_LOGO++"; 91# URI of GIT favicon, assumed to be image/png type 92our$favicon="++GITWEB_FAVICON++"; 93 94# URI and label (title) of GIT logo link 95#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 96#our $logo_label = "git documentation"; 97our$logo_url="http://git-scm.com/"; 98our$logo_label="git homepage"; 99 100# source of projects list 101our$projects_list="++GITWEB_LIST++"; 102 103# the width (in characters) of the projects list "Description" column 104our$projects_list_description_width=25; 105 106# default order of projects list 107# valid values are none, project, descr, owner, and age 108our$default_projects_order="project"; 109 110# show repository only if this file exists 111# (only effective if this variable evaluates to true) 112our$export_ok="++GITWEB_EXPORT_OK++"; 113 114# show repository only if this subroutine returns true 115# when given the path to the project, for example: 116# sub { return -e "$_[0]/git-daemon-export-ok"; } 117our$export_auth_hook=undef; 118 119# only allow viewing of repositories also shown on the overview page 120our$strict_export="++GITWEB_STRICT_EXPORT++"; 121 122# list of git base URLs used for URL to where fetch project from, 123# i.e. full URL is "$git_base_url/$project" 124our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 125 126# default blob_plain mimetype and default charset for text/plain blob 127our$default_blob_plain_mimetype='text/plain'; 128our$default_text_plain_charset=undef; 129 130# file to use for guessing MIME types before trying /etc/mime.types 131# (relative to the current git repository) 132our$mimetypes_file=undef; 133 134# assume this charset if line contains non-UTF-8 characters; 135# it should be valid encoding (see Encoding::Supported(3pm) for list), 136# for which encoding all byte sequences are valid, for example 137# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 138# could be even 'utf-8' for the old behavior) 139our$fallback_encoding='latin1'; 140 141# rename detection options for git-diff and git-diff-tree 142# - default is '-M', with the cost proportional to 143# (number of removed files) * (number of new files). 144# - more costly is '-C' (which implies '-M'), with the cost proportional to 145# (number of changed files + number of removed files) * (number of new files) 146# - even more costly is '-C', '--find-copies-harder' with cost 147# (number of files in the original tree) * (number of new files) 148# - one might want to include '-B' option, e.g. '-B', '-M' 149our@diff_opts= ('-M');# taken from git_commit 150 151# Disables features that would allow repository owners to inject script into 152# the gitweb domain. 153our$prevent_xss=0; 154 155# information about snapshot formats that gitweb is capable of serving 156our%known_snapshot_formats= ( 157# name => { 158# 'display' => display name, 159# 'type' => mime type, 160# 'suffix' => filename suffix, 161# 'format' => --format for git-archive, 162# 'compressor' => [compressor command and arguments] 163# (array reference, optional) 164# 'disabled' => boolean (optional)} 165# 166'tgz'=> { 167'display'=>'tar.gz', 168'type'=>'application/x-gzip', 169'suffix'=>'.tar.gz', 170'format'=>'tar', 171'compressor'=> ['gzip']}, 172 173'tbz2'=> { 174'display'=>'tar.bz2', 175'type'=>'application/x-bzip2', 176'suffix'=>'.tar.bz2', 177'format'=>'tar', 178'compressor'=> ['bzip2']}, 179 180'txz'=> { 181'display'=>'tar.xz', 182'type'=>'application/x-xz', 183'suffix'=>'.tar.xz', 184'format'=>'tar', 185'compressor'=> ['xz'], 186'disabled'=>1}, 187 188'zip'=> { 189'display'=>'zip', 190'type'=>'application/x-zip', 191'suffix'=>'.zip', 192'format'=>'zip'}, 193); 194 195# Aliases so we understand old gitweb.snapshot values in repository 196# configuration. 197our%known_snapshot_format_aliases= ( 198'gzip'=>'tgz', 199'bzip2'=>'tbz2', 200'xz'=>'txz', 201 202# backward compatibility: legacy gitweb config support 203'x-gzip'=>undef,'gz'=>undef, 204'x-bzip2'=>undef,'bz2'=>undef, 205'x-zip'=>undef,''=>undef, 206); 207 208# Pixel sizes for icons and avatars. If the default font sizes or lineheights 209# are changed, it may be appropriate to change these values too via 210# $GITWEB_CONFIG. 211our%avatar_size= ( 212'default'=>16, 213'double'=>32 214); 215 216# You define site-wide feature defaults here; override them with 217# $GITWEB_CONFIG as necessary. 218our%feature= ( 219# feature => { 220# 'sub' => feature-sub (subroutine), 221# 'override' => allow-override (boolean), 222# 'default' => [ default options...] (array reference)} 223# 224# if feature is overridable (it means that allow-override has true value), 225# then feature-sub will be called with default options as parameters; 226# return value of feature-sub indicates if to enable specified feature 227# 228# if there is no 'sub' key (no feature-sub), then feature cannot be 229# overriden 230# 231# use gitweb_get_feature(<feature>) to retrieve the <feature> value 232# (an array) or gitweb_check_feature(<feature>) to check if <feature> 233# is enabled 234 235# Enable the 'blame' blob view, showing the last commit that modified 236# each line in the file. This can be very CPU-intensive. 237 238# To enable system wide have in $GITWEB_CONFIG 239# $feature{'blame'}{'default'} = [1]; 240# To have project specific config enable override in $GITWEB_CONFIG 241# $feature{'blame'}{'override'} = 1; 242# and in project config gitweb.blame = 0|1; 243'blame'=> { 244'sub'=>sub{ feature_bool('blame',@_) }, 245'override'=>0, 246'default'=> [0]}, 247 248# Enable the 'snapshot' link, providing a compressed archive of any 249# tree. This can potentially generate high traffic if you have large 250# project. 251 252# Value is a list of formats defined in %known_snapshot_formats that 253# you wish to offer. 254# To disable system wide have in $GITWEB_CONFIG 255# $feature{'snapshot'}{'default'} = []; 256# To have project specific config enable override in $GITWEB_CONFIG 257# $feature{'snapshot'}{'override'} = 1; 258# and in project config, a comma-separated list of formats or "none" 259# to disable. Example: gitweb.snapshot = tbz2,zip; 260'snapshot'=> { 261'sub'=> \&feature_snapshot, 262'override'=>0, 263'default'=> ['tgz']}, 264 265# Enable text search, which will list the commits which match author, 266# committer or commit text to a given string. Enabled by default. 267# Project specific override is not supported. 268'search'=> { 269'override'=>0, 270'default'=> [1]}, 271 272# Enable grep search, which will list the files in currently selected 273# tree containing the given string. Enabled by default. This can be 274# potentially CPU-intensive, of course. 275 276# To enable system wide have in $GITWEB_CONFIG 277# $feature{'grep'}{'default'} = [1]; 278# To have project specific config enable override in $GITWEB_CONFIG 279# $feature{'grep'}{'override'} = 1; 280# and in project config gitweb.grep = 0|1; 281'grep'=> { 282'sub'=>sub{ feature_bool('grep',@_) }, 283'override'=>0, 284'default'=> [1]}, 285 286# Enable the pickaxe search, which will list the commits that modified 287# a given string in a file. This can be practical and quite faster 288# alternative to 'blame', but still potentially CPU-intensive. 289 290# To enable system wide have in $GITWEB_CONFIG 291# $feature{'pickaxe'}{'default'} = [1]; 292# To have project specific config enable override in $GITWEB_CONFIG 293# $feature{'pickaxe'}{'override'} = 1; 294# and in project config gitweb.pickaxe = 0|1; 295'pickaxe'=> { 296'sub'=>sub{ feature_bool('pickaxe',@_) }, 297'override'=>0, 298'default'=> [1]}, 299 300# Enable showing size of blobs in a 'tree' view, in a separate 301# column, similar to what 'ls -l' does. This cost a bit of IO. 302 303# To disable system wide have in $GITWEB_CONFIG 304# $feature{'show-sizes'}{'default'} = [0]; 305# To have project specific config enable override in $GITWEB_CONFIG 306# $feature{'show-sizes'}{'override'} = 1; 307# and in project config gitweb.showsizes = 0|1; 308'show-sizes'=> { 309'sub'=>sub{ feature_bool('showsizes',@_) }, 310'override'=>0, 311'default'=> [1]}, 312 313# Make gitweb use an alternative format of the URLs which can be 314# more readable and natural-looking: project name is embedded 315# directly in the path and the query string contains other 316# auxiliary information. All gitweb installations recognize 317# URL in either format; this configures in which formats gitweb 318# generates links. 319 320# To enable system wide have in $GITWEB_CONFIG 321# $feature{'pathinfo'}{'default'} = [1]; 322# Project specific override is not supported. 323 324# Note that you will need to change the default location of CSS, 325# favicon, logo and possibly other files to an absolute URL. Also, 326# if gitweb.cgi serves as your indexfile, you will need to force 327# $my_uri to contain the script name in your $GITWEB_CONFIG. 328'pathinfo'=> { 329'override'=>0, 330'default'=> [0]}, 331 332# Make gitweb consider projects in project root subdirectories 333# to be forks of existing projects. Given project $projname.git, 334# projects matching $projname/*.git will not be shown in the main 335# projects list, instead a '+' mark will be added to $projname 336# there and a 'forks' view will be enabled for the project, listing 337# all the forks. If project list is taken from a file, forks have 338# to be listed after the main project. 339 340# To enable system wide have in $GITWEB_CONFIG 341# $feature{'forks'}{'default'} = [1]; 342# Project specific override is not supported. 343'forks'=> { 344'override'=>0, 345'default'=> [0]}, 346 347# Insert custom links to the action bar of all project pages. 348# This enables you mainly to link to third-party scripts integrating 349# into gitweb; e.g. git-browser for graphical history representation 350# or custom web-based repository administration interface. 351 352# The 'default' value consists of a list of triplets in the form 353# (label, link, position) where position is the label after which 354# to insert the link and link is a format string where %n expands 355# to the project name, %f to the project path within the filesystem, 356# %h to the current hash (h gitweb parameter) and %b to the current 357# hash base (hb gitweb parameter); %% expands to %. 358 359# To enable system wide have in $GITWEB_CONFIG e.g. 360# $feature{'actions'}{'default'} = [('graphiclog', 361# '/git-browser/by-commit.html?r=%n', 'summary')]; 362# Project specific override is not supported. 363'actions'=> { 364'override'=>0, 365'default'=> []}, 366 367# Allow gitweb scan project content tags described in ctags/ 368# of project repository, and display the popular Web 2.0-ish 369# "tag cloud" near the project list. Note that this is something 370# COMPLETELY different from the normal Git tags. 371 372# gitweb by itself can show existing tags, but it does not handle 373# tagging itself; you need an external application for that. 374# For an example script, check Girocco's cgi/tagproj.cgi. 375# You may want to install the HTML::TagCloud Perl module to get 376# a pretty tag cloud instead of just a list of tags. 377 378# To enable system wide have in $GITWEB_CONFIG 379# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 380# Project specific override is not supported. 381'ctags'=> { 382'override'=>0, 383'default'=> [0]}, 384 385# The maximum number of patches in a patchset generated in patch 386# view. Set this to 0 or undef to disable patch view, or to a 387# negative number to remove any limit. 388 389# To disable system wide have in $GITWEB_CONFIG 390# $feature{'patches'}{'default'} = [0]; 391# To have project specific config enable override in $GITWEB_CONFIG 392# $feature{'patches'}{'override'} = 1; 393# and in project config gitweb.patches = 0|n; 394# where n is the maximum number of patches allowed in a patchset. 395'patches'=> { 396'sub'=> \&feature_patches, 397'override'=>0, 398'default'=> [16]}, 399 400# Avatar support. When this feature is enabled, views such as 401# shortlog or commit will display an avatar associated with 402# the email of the committer(s) and/or author(s). 403 404# Currently available providers are gravatar and picon. 405# If an unknown provider is specified, the feature is disabled. 406 407# Gravatar depends on Digest::MD5. 408# Picon currently relies on the indiana.edu database. 409 410# To enable system wide have in $GITWEB_CONFIG 411# $feature{'avatar'}{'default'} = ['<provider>']; 412# where <provider> is either gravatar or picon. 413# To have project specific config enable override in $GITWEB_CONFIG 414# $feature{'avatar'}{'override'} = 1; 415# and in project config gitweb.avatar = <provider>; 416'avatar'=> { 417'sub'=> \&feature_avatar, 418'override'=>0, 419'default'=> ['']}, 420); 421 422sub gitweb_get_feature { 423my($name) =@_; 424return unlessexists$feature{$name}; 425my($sub,$override,@defaults) = ( 426$feature{$name}{'sub'}, 427$feature{$name}{'override'}, 428@{$feature{$name}{'default'}}); 429if(!$override) {return@defaults; } 430if(!defined$sub) { 431warn"feature$nameis not overridable"; 432return@defaults; 433} 434return$sub->(@defaults); 435} 436 437# A wrapper to check if a given feature is enabled. 438# With this, you can say 439# 440# my $bool_feat = gitweb_check_feature('bool_feat'); 441# gitweb_check_feature('bool_feat') or somecode; 442# 443# instead of 444# 445# my ($bool_feat) = gitweb_get_feature('bool_feat'); 446# (gitweb_get_feature('bool_feat'))[0] or somecode; 447# 448sub gitweb_check_feature { 449return(gitweb_get_feature(@_))[0]; 450} 451 452 453sub feature_bool { 454my$key=shift; 455my($val) = git_get_project_config($key,'--bool'); 456 457if(!defined$val) { 458return($_[0]); 459}elsif($valeq'true') { 460return(1); 461}elsif($valeq'false') { 462return(0); 463} 464} 465 466sub feature_snapshot { 467my(@fmts) =@_; 468 469my($val) = git_get_project_config('snapshot'); 470 471if($val) { 472@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 473} 474 475return@fmts; 476} 477 478sub feature_patches { 479my@val= (git_get_project_config('patches','--int')); 480 481if(@val) { 482return@val; 483} 484 485return($_[0]); 486} 487 488sub feature_avatar { 489my@val= (git_get_project_config('avatar')); 490 491return@val?@val:@_; 492} 493 494# checking HEAD file with -e is fragile if the repository was 495# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 496# and then pruned. 497sub check_head_link { 498my($dir) =@_; 499my$headfile="$dir/HEAD"; 500return((-e $headfile) || 501(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 502} 503 504sub check_export_ok { 505my($dir) =@_; 506return(check_head_link($dir) && 507(!$export_ok|| -e "$dir/$export_ok") && 508(!$export_auth_hook||$export_auth_hook->($dir))); 509} 510 511# process alternate names for backward compatibility 512# filter out unsupported (unknown) snapshot formats 513sub filter_snapshot_fmts { 514my@fmts=@_; 515 516@fmts=map{ 517exists$known_snapshot_format_aliases{$_} ? 518$known_snapshot_format_aliases{$_} :$_}@fmts; 519@fmts=grep{ 520exists$known_snapshot_formats{$_} && 521!$known_snapshot_formats{$_}{'disabled'}}@fmts; 522} 523 524our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 525if(-e $GITWEB_CONFIG) { 526do$GITWEB_CONFIG; 527}else{ 528our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 529do$GITWEB_CONFIG_SYSTEMif-e $GITWEB_CONFIG_SYSTEM; 530} 531 532# version of the core git binary 533our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 534 535$projects_list||=$projectroot; 536 537# ====================================================================== 538# input validation and dispatch 539 540# input parameters can be collected from a variety of sources (presently, CGI 541# and PATH_INFO), so we define an %input_params hash that collects them all 542# together during validation: this allows subsequent uses (e.g. href()) to be 543# agnostic of the parameter origin 544 545our%input_params= (); 546 547# input parameters are stored with the long parameter name as key. This will 548# also be used in the href subroutine to convert parameters to their CGI 549# equivalent, and since the href() usage is the most frequent one, we store 550# the name -> CGI key mapping here, instead of the reverse. 551# 552# XXX: Warning: If you touch this, check the search form for updating, 553# too. 554 555our@cgi_param_mapping= ( 556 project =>"p", 557 action =>"a", 558 file_name =>"f", 559 file_parent =>"fp", 560 hash =>"h", 561 hash_parent =>"hp", 562 hash_base =>"hb", 563 hash_parent_base =>"hpb", 564 page =>"pg", 565 order =>"o", 566 searchtext =>"s", 567 searchtype =>"st", 568 snapshot_format =>"sf", 569 extra_options =>"opt", 570 search_use_regexp =>"sr", 571); 572our%cgi_param_mapping=@cgi_param_mapping; 573 574# we will also need to know the possible actions, for validation 575our%actions= ( 576"blame"=> \&git_blame, 577"blobdiff"=> \&git_blobdiff, 578"blobdiff_plain"=> \&git_blobdiff_plain, 579"blob"=> \&git_blob, 580"blob_plain"=> \&git_blob_plain, 581"commitdiff"=> \&git_commitdiff, 582"commitdiff_plain"=> \&git_commitdiff_plain, 583"commit"=> \&git_commit, 584"forks"=> \&git_forks, 585"heads"=> \&git_heads, 586"history"=> \&git_history, 587"log"=> \&git_log, 588"patch"=> \&git_patch, 589"patches"=> \&git_patches, 590"rss"=> \&git_rss, 591"atom"=> \&git_atom, 592"search"=> \&git_search, 593"search_help"=> \&git_search_help, 594"shortlog"=> \&git_shortlog, 595"summary"=> \&git_summary, 596"tag"=> \&git_tag, 597"tags"=> \&git_tags, 598"tree"=> \&git_tree, 599"snapshot"=> \&git_snapshot, 600"object"=> \&git_object, 601# those below don't need $project 602"opml"=> \&git_opml, 603"project_list"=> \&git_project_list, 604"project_index"=> \&git_project_index, 605); 606 607# finally, we have the hash of allowed extra_options for the commands that 608# allow them 609our%allowed_options= ( 610"--no-merges"=> [qw(rss atom log shortlog history)], 611); 612 613# fill %input_params with the CGI parameters. All values except for 'opt' 614# should be single values, but opt can be an array. We should probably 615# build an array of parameters that can be multi-valued, but since for the time 616# being it's only this one, we just single it out 617while(my($name,$symbol) =each%cgi_param_mapping) { 618if($symboleq'opt') { 619$input_params{$name} = [$cgi->param($symbol) ]; 620}else{ 621$input_params{$name} =$cgi->param($symbol); 622} 623} 624 625# now read PATH_INFO and update the parameter list for missing parameters 626sub evaluate_path_info { 627return ifdefined$input_params{'project'}; 628return if!$path_info; 629$path_info=~ s,^/+,,; 630return if!$path_info; 631 632# find which part of PATH_INFO is project 633my$project=$path_info; 634$project=~ s,/+$,,; 635while($project&& !check_head_link("$projectroot/$project")) { 636$project=~ s,/*[^/]*$,,; 637} 638return unless$project; 639$input_params{'project'} =$project; 640 641# do not change any parameters if an action is given using the query string 642return if$input_params{'action'}; 643$path_info=~ s,^\Q$project\E/*,,; 644 645# next, check if we have an action 646my$action=$path_info; 647$action=~ s,/.*$,,; 648if(exists$actions{$action}) { 649$path_info=~ s,^$action/*,,; 650$input_params{'action'} =$action; 651} 652 653# list of actions that want hash_base instead of hash, but can have no 654# pathname (f) parameter 655my@wants_base= ( 656'tree', 657'history', 658); 659 660# we want to catch 661# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 662my($parentrefname,$parentpathname,$refname,$pathname) = 663($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/); 664 665# first, analyze the 'current' part 666if(defined$pathname) { 667# we got "branch:filename" or "branch:dir/" 668# we could use git_get_type(branch:pathname), but: 669# - it needs $git_dir 670# - it does a git() call 671# - the convention of terminating directories with a slash 672# makes it superfluous 673# - embedding the action in the PATH_INFO would make it even 674# more superfluous 675$pathname=~ s,^/+,,; 676if(!$pathname||substr($pathname, -1)eq"/") { 677$input_params{'action'} ||="tree"; 678$pathname=~ s,/$,,; 679}else{ 680# the default action depends on whether we had parent info 681# or not 682if($parentrefname) { 683$input_params{'action'} ||="blobdiff_plain"; 684}else{ 685$input_params{'action'} ||="blob_plain"; 686} 687} 688$input_params{'hash_base'} ||=$refname; 689$input_params{'file_name'} ||=$pathname; 690}elsif(defined$refname) { 691# we got "branch". In this case we have to choose if we have to 692# set hash or hash_base. 693# 694# Most of the actions without a pathname only want hash to be 695# set, except for the ones specified in @wants_base that want 696# hash_base instead. It should also be noted that hand-crafted 697# links having 'history' as an action and no pathname or hash 698# set will fail, but that happens regardless of PATH_INFO. 699$input_params{'action'} ||="shortlog"; 700if(grep{$_eq$input_params{'action'} }@wants_base) { 701$input_params{'hash_base'} ||=$refname; 702}else{ 703$input_params{'hash'} ||=$refname; 704} 705} 706 707# next, handle the 'parent' part, if present 708if(defined$parentrefname) { 709# a missing pathspec defaults to the 'current' filename, allowing e.g. 710# someproject/blobdiff/oldrev..newrev:/filename 711if($parentpathname) { 712$parentpathname=~ s,^/+,,; 713$parentpathname=~ s,/$,,; 714$input_params{'file_parent'} ||=$parentpathname; 715}else{ 716$input_params{'file_parent'} ||=$input_params{'file_name'}; 717} 718# we assume that hash_parent_base is wanted if a path was specified, 719# or if the action wants hash_base instead of hash 720if(defined$input_params{'file_parent'} || 721grep{$_eq$input_params{'action'} }@wants_base) { 722$input_params{'hash_parent_base'} ||=$parentrefname; 723}else{ 724$input_params{'hash_parent'} ||=$parentrefname; 725} 726} 727 728# for the snapshot action, we allow URLs in the form 729# $project/snapshot/$hash.ext 730# where .ext determines the snapshot and gets removed from the 731# passed $refname to provide the $hash. 732# 733# To be able to tell that $refname includes the format extension, we 734# require the following two conditions to be satisfied: 735# - the hash input parameter MUST have been set from the $refname part 736# of the URL (i.e. they must be equal) 737# - the snapshot format MUST NOT have been defined already (e.g. from 738# CGI parameter sf) 739# It's also useless to try any matching unless $refname has a dot, 740# so we check for that too 741if(defined$input_params{'action'} && 742$input_params{'action'}eq'snapshot'&& 743defined$refname&&index($refname,'.') != -1&& 744$refnameeq$input_params{'hash'} && 745!defined$input_params{'snapshot_format'}) { 746# We loop over the known snapshot formats, checking for 747# extensions. Allowed extensions are both the defined suffix 748# (which includes the initial dot already) and the snapshot 749# format key itself, with a prepended dot 750while(my($fmt,$opt) =each%known_snapshot_formats) { 751my$hash=$refname; 752unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 753next; 754} 755my$sfx=$1; 756# a valid suffix was found, so set the snapshot format 757# and reset the hash parameter 758$input_params{'snapshot_format'} =$fmt; 759$input_params{'hash'} =$hash; 760# we also set the format suffix to the one requested 761# in the URL: this way a request for e.g. .tgz returns 762# a .tgz instead of a .tar.gz 763$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 764last; 765} 766} 767} 768evaluate_path_info(); 769 770our$action=$input_params{'action'}; 771if(defined$action) { 772if(!validate_action($action)) { 773 die_error(400,"Invalid action parameter"); 774} 775} 776 777# parameters which are pathnames 778our$project=$input_params{'project'}; 779if(defined$project) { 780if(!validate_project($project)) { 781undef$project; 782 die_error(404,"No such project"); 783} 784} 785 786our$file_name=$input_params{'file_name'}; 787if(defined$file_name) { 788if(!validate_pathname($file_name)) { 789 die_error(400,"Invalid file parameter"); 790} 791} 792 793our$file_parent=$input_params{'file_parent'}; 794if(defined$file_parent) { 795if(!validate_pathname($file_parent)) { 796 die_error(400,"Invalid file parent parameter"); 797} 798} 799 800# parameters which are refnames 801our$hash=$input_params{'hash'}; 802if(defined$hash) { 803if(!validate_refname($hash)) { 804 die_error(400,"Invalid hash parameter"); 805} 806} 807 808our$hash_parent=$input_params{'hash_parent'}; 809if(defined$hash_parent) { 810if(!validate_refname($hash_parent)) { 811 die_error(400,"Invalid hash parent parameter"); 812} 813} 814 815our$hash_base=$input_params{'hash_base'}; 816if(defined$hash_base) { 817if(!validate_refname($hash_base)) { 818 die_error(400,"Invalid hash base parameter"); 819} 820} 821 822our@extra_options= @{$input_params{'extra_options'}}; 823# @extra_options is always defined, since it can only be (currently) set from 824# CGI, and $cgi->param() returns the empty array in array context if the param 825# is not set 826foreachmy$opt(@extra_options) { 827if(not exists$allowed_options{$opt}) { 828 die_error(400,"Invalid option parameter"); 829} 830if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 831 die_error(400,"Invalid option parameter for this action"); 832} 833} 834 835our$hash_parent_base=$input_params{'hash_parent_base'}; 836if(defined$hash_parent_base) { 837if(!validate_refname($hash_parent_base)) { 838 die_error(400,"Invalid hash parent base parameter"); 839} 840} 841 842# other parameters 843our$page=$input_params{'page'}; 844if(defined$page) { 845if($page=~m/[^0-9]/) { 846 die_error(400,"Invalid page parameter"); 847} 848} 849 850our$searchtype=$input_params{'searchtype'}; 851if(defined$searchtype) { 852if($searchtype=~m/[^a-z]/) { 853 die_error(400,"Invalid searchtype parameter"); 854} 855} 856 857our$search_use_regexp=$input_params{'search_use_regexp'}; 858 859our$searchtext=$input_params{'searchtext'}; 860our$search_regexp; 861if(defined$searchtext) { 862if(length($searchtext) <2) { 863 die_error(403,"At least two characters are required for search parameter"); 864} 865$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 866} 867 868# path to the current git repository 869our$git_dir; 870$git_dir="$projectroot/$project"if$project; 871 872# list of supported snapshot formats 873our@snapshot_fmts= gitweb_get_feature('snapshot'); 874@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts); 875 876# check that the avatar feature is set to a known provider name, 877# and for each provider check if the dependencies are satisfied. 878# if the provider name is invalid or the dependencies are not met, 879# reset $git_avatar to the empty string. 880our($git_avatar) = gitweb_get_feature('avatar'); 881if($git_avatareq'gravatar') { 882$git_avatar=''unless(eval{require Digest::MD5;1; }); 883}elsif($git_avatareq'picon') { 884# no dependencies 885}else{ 886$git_avatar=''; 887} 888 889# dispatch 890if(!defined$action) { 891if(defined$hash) { 892$action= git_get_type($hash); 893}elsif(defined$hash_base&&defined$file_name) { 894$action= git_get_type("$hash_base:$file_name"); 895}elsif(defined$project) { 896$action='summary'; 897}else{ 898$action='project_list'; 899} 900} 901if(!defined($actions{$action})) { 902 die_error(400,"Unknown action"); 903} 904if($action!~m/^(?:opml|project_list|project_index)$/&& 905!$project) { 906 die_error(400,"Project needed"); 907} 908$actions{$action}->(); 909exit; 910 911## ====================================================================== 912## action links 913 914sub href { 915my%params=@_; 916# default is to use -absolute url() i.e. $my_uri 917my$href=$params{-full} ?$my_url:$my_uri; 918 919$params{'project'} =$projectunlessexists$params{'project'}; 920 921if($params{-replay}) { 922while(my($name,$symbol) =each%cgi_param_mapping) { 923if(!exists$params{$name}) { 924$params{$name} =$input_params{$name}; 925} 926} 927} 928 929my$use_pathinfo= gitweb_check_feature('pathinfo'); 930if($use_pathinfoand defined$params{'project'}) { 931# try to put as many parameters as possible in PATH_INFO: 932# - project name 933# - action 934# - hash_parent or hash_parent_base:/file_parent 935# - hash or hash_base:/filename 936# - the snapshot_format as an appropriate suffix 937 938# When the script is the root DirectoryIndex for the domain, 939# $href here would be something like http://gitweb.example.com/ 940# Thus, we strip any trailing / from $href, to spare us double 941# slashes in the final URL 942$href=~ s,/$,,; 943 944# Then add the project name, if present 945$href.="/".esc_url($params{'project'}); 946delete$params{'project'}; 947 948# since we destructively absorb parameters, we keep this 949# boolean that remembers if we're handling a snapshot 950my$is_snapshot=$params{'action'}eq'snapshot'; 951 952# Summary just uses the project path URL, any other action is 953# added to the URL 954if(defined$params{'action'}) { 955$href.="/".esc_url($params{'action'})unless$params{'action'}eq'summary'; 956delete$params{'action'}; 957} 958 959# Next, we put hash_parent_base:/file_parent..hash_base:/file_name, 960# stripping nonexistent or useless pieces 961$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'} 962||$params{'hash_parent'} ||$params{'hash'}); 963if(defined$params{'hash_base'}) { 964if(defined$params{'hash_parent_base'}) { 965$href.= esc_url($params{'hash_parent_base'}); 966# skip the file_parent if it's the same as the file_name 967if(defined$params{'file_parent'}) { 968if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) { 969delete$params{'file_parent'}; 970}elsif($params{'file_parent'} !~/\.\./) { 971$href.=":/".esc_url($params{'file_parent'}); 972delete$params{'file_parent'}; 973} 974} 975$href.=".."; 976delete$params{'hash_parent'}; 977delete$params{'hash_parent_base'}; 978}elsif(defined$params{'hash_parent'}) { 979$href.= esc_url($params{'hash_parent'}).".."; 980delete$params{'hash_parent'}; 981} 982 983$href.= esc_url($params{'hash_base'}); 984if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) { 985$href.=":/".esc_url($params{'file_name'}); 986delete$params{'file_name'}; 987} 988delete$params{'hash'}; 989delete$params{'hash_base'}; 990}elsif(defined$params{'hash'}) { 991$href.= esc_url($params{'hash'}); 992delete$params{'hash'}; 993} 994 995# If the action was a snapshot, we can absorb the 996# snapshot_format parameter too 997if($is_snapshot) { 998my$fmt=$params{'snapshot_format'}; 999# snapshot_format should always be defined when href()1000# is called, but just in case some code forgets, we1001# fall back to the default1002$fmt||=$snapshot_fmts[0];1003$href.=$known_snapshot_formats{$fmt}{'suffix'};1004delete$params{'snapshot_format'};1005}1006}10071008# now encode the parameters explicitly1009my@result= ();1010for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1011my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1012if(defined$params{$name}) {1013if(ref($params{$name})eq"ARRAY") {1014foreachmy$par(@{$params{$name}}) {1015push@result,$symbol."=". esc_param($par);1016}1017}else{1018push@result,$symbol."=". esc_param($params{$name});1019}1020}1021}1022$href.="?".join(';',@result)ifscalar@result;10231024return$href;1025}102610271028## ======================================================================1029## validation, quoting/unquoting and escaping10301031sub validate_action {1032my$input=shift||returnundef;1033returnundefunlessexists$actions{$input};1034return$input;1035}10361037sub validate_project {1038my$input=shift||returnundef;1039if(!validate_pathname($input) ||1040!(-d "$projectroot/$input") ||1041!check_export_ok("$projectroot/$input") ||1042($strict_export&& !project_in_list($input))) {1043returnundef;1044}else{1045return$input;1046}1047}10481049sub validate_pathname {1050my$input=shift||returnundef;10511052# no '.' or '..' as elements of path, i.e. no '.' nor '..'1053# at the beginning, at the end, and between slashes.1054# also this catches doubled slashes1055if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1056returnundef;1057}1058# no null characters1059if($input=~m!\0!) {1060returnundef;1061}1062return$input;1063}10641065sub validate_refname {1066my$input=shift||returnundef;10671068# textual hashes are O.K.1069if($input=~m/^[0-9a-fA-F]{40}$/) {1070return$input;1071}1072# it must be correct pathname1073$input= validate_pathname($input)1074orreturnundef;1075# restrictions on ref name according to git-check-ref-format1076if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1077returnundef;1078}1079return$input;1080}10811082# decode sequences of octets in utf8 into Perl's internal form,1083# which is utf-8 with utf8 flag set if needed. gitweb writes out1084# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1085sub to_utf8 {1086my$str=shift;1087if(utf8::valid($str)) {1088 utf8::decode($str);1089return$str;1090}else{1091return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1092}1093}10941095# quote unsafe chars, but keep the slash, even when it's not1096# correct, but quoted slashes look too horrible in bookmarks1097sub esc_param {1098my$str=shift;1099$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1100$str=~s/ /\+/g;1101return$str;1102}11031104# quote unsafe chars in whole URL, so some charactrs cannot be quoted1105sub esc_url {1106my$str=shift;1107$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X",ord($1))/eg;1108$str=~s/\+/%2B/g;1109$str=~s/ /\+/g;1110return$str;1111}11121113# replace invalid utf8 character with SUBSTITUTION sequence1114sub esc_html {1115my$str=shift;1116my%opts=@_;11171118$str= to_utf8($str);1119$str=$cgi->escapeHTML($str);1120if($opts{'-nbsp'}) {1121$str=~s/ / /g;1122}1123$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1124return$str;1125}11261127# quote control characters and escape filename to HTML1128sub esc_path {1129my$str=shift;1130my%opts=@_;11311132$str= to_utf8($str);1133$str=$cgi->escapeHTML($str);1134if($opts{'-nbsp'}) {1135$str=~s/ / /g;1136}1137$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1138return$str;1139}11401141# Make control characters "printable", using character escape codes (CEC)1142sub quot_cec {1143my$cntrl=shift;1144my%opts=@_;1145my%es= (# character escape codes, aka escape sequences1146"\t"=>'\t',# tab (HT)1147"\n"=>'\n',# line feed (LF)1148"\r"=>'\r',# carrige return (CR)1149"\f"=>'\f',# form feed (FF)1150"\b"=>'\b',# backspace (BS)1151"\a"=>'\a',# alarm (bell) (BEL)1152"\e"=>'\e',# escape (ESC)1153"\013"=>'\v',# vertical tab (VT)1154"\000"=>'\0',# nul character (NUL)1155);1156my$chr= ( (exists$es{$cntrl})1157?$es{$cntrl}1158:sprintf('\%2x',ord($cntrl)) );1159if($opts{-nohtml}) {1160return$chr;1161}else{1162return"<span class=\"cntrl\">$chr</span>";1163}1164}11651166# Alternatively use unicode control pictures codepoints,1167# Unicode "printable representation" (PR)1168sub quot_upr {1169my$cntrl=shift;1170my%opts=@_;11711172my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1173if($opts{-nohtml}) {1174return$chr;1175}else{1176return"<span class=\"cntrl\">$chr</span>";1177}1178}11791180# git may return quoted and escaped filenames1181sub unquote {1182my$str=shift;11831184sub unq {1185my$seq=shift;1186my%es= (# character escape codes, aka escape sequences1187't'=>"\t",# tab (HT, TAB)1188'n'=>"\n",# newline (NL)1189'r'=>"\r",# return (CR)1190'f'=>"\f",# form feed (FF)1191'b'=>"\b",# backspace (BS)1192'a'=>"\a",# alarm (bell) (BEL)1193'e'=>"\e",# escape (ESC)1194'v'=>"\013",# vertical tab (VT)1195);11961197if($seq=~m/^[0-7]{1,3}$/) {1198# octal char sequence1199returnchr(oct($seq));1200}elsif(exists$es{$seq}) {1201# C escape sequence, aka character escape code1202return$es{$seq};1203}1204# quoted ordinary character1205return$seq;1206}12071208if($str=~m/^"(.*)"$/) {1209# needs unquoting1210$str=$1;1211$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1212}1213return$str;1214}12151216# escape tabs (convert tabs to spaces)1217sub untabify {1218my$line=shift;12191220while((my$pos=index($line,"\t")) != -1) {1221if(my$count= (8- ($pos%8))) {1222my$spaces=' ' x $count;1223$line=~s/\t/$spaces/;1224}1225}12261227return$line;1228}12291230sub project_in_list {1231my$project=shift;1232my@list= git_get_projects_list();1233return@list&&scalar(grep{$_->{'path'}eq$project}@list);1234}12351236## ----------------------------------------------------------------------1237## HTML aware string manipulation12381239# Try to chop given string on a word boundary between position1240# $len and $len+$add_len. If there is no word boundary there,1241# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1242# (marking chopped part) would be longer than given string.1243sub chop_str {1244my$str=shift;1245my$len=shift;1246my$add_len=shift||10;1247my$where=shift||'right';# 'left' | 'center' | 'right'12481249# Make sure perl knows it is utf8 encoded so we don't1250# cut in the middle of a utf8 multibyte char.1251$str= to_utf8($str);12521253# allow only $len chars, but don't cut a word if it would fit in $add_len1254# if it doesn't fit, cut it if it's still longer than the dots we would add1255# remove chopped character entities entirely12561257# when chopping in the middle, distribute $len into left and right part1258# return early if chopping wouldn't make string shorter1259if($whereeq'center') {1260return$strif($len+5>=length($str));# filler is length 51261$len=int($len/2);1262}else{1263return$strif($len+4>=length($str));# filler is length 41264}12651266# regexps: ending and beginning with word part up to $add_len1267my$endre=qr/.{$len}\w{0,$add_len}/;1268my$begre=qr/\w{0,$add_len}.{$len}/;12691270if($whereeq'left') {1271$str=~m/^(.*?)($begre)$/;1272my($lead,$body) = ($1,$2);1273if(length($lead) >4) {1274$body=~s/^[^;]*;//if($lead=~m/&[^;]*$/);1275$lead=" ...";1276}1277return"$lead$body";12781279}elsif($whereeq'center') {1280$str=~m/^($endre)(.*)$/;1281my($left,$str) = ($1,$2);1282$str=~m/^(.*?)($begre)$/;1283my($mid,$right) = ($1,$2);1284if(length($mid) >5) {1285$left=~s/&[^;]*$//;1286$right=~s/^[^;]*;//if($mid=~m/&[^;]*$/);1287$mid=" ... ";1288}1289return"$left$mid$right";12901291}else{1292$str=~m/^($endre)(.*)$/;1293my$body=$1;1294my$tail=$2;1295if(length($tail) >4) {1296$body=~s/&[^;]*$//;1297$tail="... ";1298}1299return"$body$tail";1300}1301}13021303# takes the same arguments as chop_str, but also wraps a <span> around the1304# result with a title attribute if it does get chopped. Additionally, the1305# string is HTML-escaped.1306sub chop_and_escape_str {1307my($str) =@_;13081309my$chopped= chop_str(@_);1310if($choppedeq$str) {1311return esc_html($chopped);1312}else{1313$str=~s/[[:cntrl:]]/?/g;1314return$cgi->span({-title=>$str}, esc_html($chopped));1315}1316}13171318## ----------------------------------------------------------------------1319## functions returning short strings13201321# CSS class for given age value (in seconds)1322sub age_class {1323my$age=shift;13241325if(!defined$age) {1326return"noage";1327}elsif($age<60*60*2) {1328return"age0";1329}elsif($age<60*60*24*2) {1330return"age1";1331}else{1332return"age2";1333}1334}13351336# convert age in seconds to "nn units ago" string1337sub age_string {1338my$age=shift;1339my$age_str;13401341if($age>60*60*24*365*2) {1342$age_str= (int$age/60/60/24/365);1343$age_str.=" years ago";1344}elsif($age>60*60*24*(365/12)*2) {1345$age_str=int$age/60/60/24/(365/12);1346$age_str.=" months ago";1347}elsif($age>60*60*24*7*2) {1348$age_str=int$age/60/60/24/7;1349$age_str.=" weeks ago";1350}elsif($age>60*60*24*2) {1351$age_str=int$age/60/60/24;1352$age_str.=" days ago";1353}elsif($age>60*60*2) {1354$age_str=int$age/60/60;1355$age_str.=" hours ago";1356}elsif($age>60*2) {1357$age_str=int$age/60;1358$age_str.=" min ago";1359}elsif($age>2) {1360$age_str=int$age;1361$age_str.=" sec ago";1362}else{1363$age_str.=" right now";1364}1365return$age_str;1366}13671368useconstant{1369 S_IFINVALID =>0030000,1370 S_IFGITLINK =>0160000,1371};13721373# submodule/subproject, a commit object reference1374sub S_ISGITLINK {1375my$mode=shift;13761377return(($mode& S_IFMT) == S_IFGITLINK)1378}13791380# convert file mode in octal to symbolic file mode string1381sub mode_str {1382my$mode=oct shift;13831384if(S_ISGITLINK($mode)) {1385return'm---------';1386}elsif(S_ISDIR($mode& S_IFMT)) {1387return'drwxr-xr-x';1388}elsif(S_ISLNK($mode)) {1389return'lrwxrwxrwx';1390}elsif(S_ISREG($mode)) {1391# git cares only about the executable bit1392if($mode& S_IXUSR) {1393return'-rwxr-xr-x';1394}else{1395return'-rw-r--r--';1396};1397}else{1398return'----------';1399}1400}14011402# convert file mode in octal to file type string1403sub file_type {1404my$mode=shift;14051406if($mode!~m/^[0-7]+$/) {1407return$mode;1408}else{1409$mode=oct$mode;1410}14111412if(S_ISGITLINK($mode)) {1413return"submodule";1414}elsif(S_ISDIR($mode& S_IFMT)) {1415return"directory";1416}elsif(S_ISLNK($mode)) {1417return"symlink";1418}elsif(S_ISREG($mode)) {1419return"file";1420}else{1421return"unknown";1422}1423}14241425# convert file mode in octal to file type description string1426sub file_type_long {1427my$mode=shift;14281429if($mode!~m/^[0-7]+$/) {1430return$mode;1431}else{1432$mode=oct$mode;1433}14341435if(S_ISGITLINK($mode)) {1436return"submodule";1437}elsif(S_ISDIR($mode& S_IFMT)) {1438return"directory";1439}elsif(S_ISLNK($mode)) {1440return"symlink";1441}elsif(S_ISREG($mode)) {1442if($mode& S_IXUSR) {1443return"executable";1444}else{1445return"file";1446};1447}else{1448return"unknown";1449}1450}145114521453## ----------------------------------------------------------------------1454## functions returning short HTML fragments, or transforming HTML fragments1455## which don't belong to other sections14561457# format line of commit message.1458sub format_log_line_html {1459my$line=shift;14601461$line= esc_html($line, -nbsp=>1);1462$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1463$cgi->a({-href => href(action=>"object", hash=>$1),1464-class=>"text"},$1);1465}eg;14661467return$line;1468}14691470# format marker of refs pointing to given object14711472# the destination action is chosen based on object type and current context:1473# - for annotated tags, we choose the tag view unless it's the current view1474# already, in which case we go to shortlog view1475# - for other refs, we keep the current view if we're in history, shortlog or1476# log view, and select shortlog otherwise1477sub format_ref_marker {1478my($refs,$id) =@_;1479my$markers='';14801481if(defined$refs->{$id}) {1482foreachmy$ref(@{$refs->{$id}}) {1483# this code exploits the fact that non-lightweight tags are the1484# only indirect objects, and that they are the only objects for which1485# we want to use tag instead of shortlog as action1486my($type,$name) =qw();1487my$indirect= ($ref=~s/\^\{\}$//);1488# e.g. tags/v2.6.11 or heads/next1489if($ref=~m!^(.*?)s?/(.*)$!) {1490$type=$1;1491$name=$2;1492}else{1493$type="ref";1494$name=$ref;1495}14961497my$class=$type;1498$class.=" indirect"if$indirect;14991500my$dest_action="shortlog";15011502if($indirect) {1503$dest_action="tag"unless$actioneq"tag";1504}elsif($action=~/^(history|(short)?log)$/) {1505$dest_action=$action;1506}15071508my$dest="";1509$dest.="refs/"unless$ref=~ m!^refs/!;1510$dest.=$ref;15111512my$link=$cgi->a({1513-href => href(1514 action=>$dest_action,1515 hash=>$dest1516)},$name);15171518$markers.=" <span class=\"$class\"title=\"$ref\">".1519$link."</span>";1520}1521}15221523if($markers) {1524return' <span class="refs">'.$markers.'</span>';1525}else{1526return"";1527}1528}15291530# format, perhaps shortened and with markers, title line1531sub format_subject_html {1532my($long,$short,$href,$extra) =@_;1533$extra=''unlessdefined($extra);15341535if(length($short) <length($long)) {1536$long=~s/[[:cntrl:]]/?/g;1537return$cgi->a({-href =>$href, -class=>"list subject",1538-title => to_utf8($long)},1539 esc_html($short)) .$extra;1540}else{1541return$cgi->a({-href =>$href, -class=>"list subject"},1542 esc_html($long)) .$extra;1543}1544}15451546# Rather than recomputing the url for an email multiple times, we cache it1547# after the first hit. This gives a visible benefit in views where the avatar1548# for the same email is used repeatedly (e.g. shortlog).1549# The cache is shared by all avatar engines (currently gravatar only), which1550# are free to use it as preferred. Since only one avatar engine is used for any1551# given page, there's no risk for cache conflicts.1552our%avatar_cache= ();15531554# Compute the picon url for a given email, by using the picon search service over at1555# http://www.cs.indiana.edu/picons/search.html1556sub picon_url {1557my$email=lc shift;1558if(!$avatar_cache{$email}) {1559my($user,$domain) =split('@',$email);1560$avatar_cache{$email} =1561"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".1562"$domain/$user/".1563"users+domains+unknown/up/single";1564}1565return$avatar_cache{$email};1566}15671568# Compute the gravatar url for a given email, if it's not in the cache already.1569# Gravatar stores only the part of the URL before the size, since that's the1570# one computationally more expensive. This also allows reuse of the cache for1571# different sizes (for this particular engine).1572sub gravatar_url {1573my$email=lc shift;1574my$size=shift;1575$avatar_cache{$email} ||=1576"http://www.gravatar.com/avatar/".1577 Digest::MD5::md5_hex($email) ."?s=";1578return$avatar_cache{$email} .$size;1579}15801581# Insert an avatar for the given $email at the given $size if the feature1582# is enabled.1583sub git_get_avatar {1584my($email,%opts) =@_;1585my$pre_white= ($opts{-pad_before} ?" ":"");1586my$post_white= ($opts{-pad_after} ?" ":"");1587$opts{-size} ||='default';1588my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};1589my$url="";1590if($git_avatareq'gravatar') {1591$url= gravatar_url($email,$size);1592}elsif($git_avatareq'picon') {1593$url= picon_url($email);1594}1595# Other providers can be added by extending the if chain, defining $url1596# as needed. If no variant puts something in $url, we assume avatars1597# are completely disabled/unavailable.1598if($url) {1599return$pre_white.1600"<img width=\"$size\"".1601"class=\"avatar\"".1602"src=\"$url\"".1603"alt=\"\"".1604"/>".$post_white;1605}else{1606return"";1607}1608}16091610# format the author name of the given commit with the given tag1611# the author name is chopped and escaped according to the other1612# optional parameters (see chop_str).1613sub format_author_html {1614my$tag=shift;1615my$co=shift;1616my$author= chop_and_escape_str($co->{'author_name'},@_);1617return"<$tagclass=\"author\">".1618 git_get_avatar($co->{'author_email'}, -pad_after =>1) .1619$author."</$tag>";1620}16211622# format git diff header line, i.e. "diff --(git|combined|cc) ..."1623sub format_git_diff_header_line {1624my$line=shift;1625my$diffinfo=shift;1626my($from,$to) =@_;16271628if($diffinfo->{'nparents'}) {1629# combined diff1630$line=~s!^(diff (.*?) )"?.*$!$1!;1631if($to->{'href'}) {1632$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1633 esc_path($to->{'file'}));1634}else{# file was deleted (no href)1635$line.= esc_path($to->{'file'});1636}1637}else{1638# "ordinary" diff1639$line=~s!^(diff (.*?) )"?a/.*$!$1!;1640if($from->{'href'}) {1641$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1642'a/'. esc_path($from->{'file'}));1643}else{# file was added (no href)1644$line.='a/'. esc_path($from->{'file'});1645}1646$line.=' ';1647if($to->{'href'}) {1648$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1649'b/'. esc_path($to->{'file'}));1650}else{# file was deleted1651$line.='b/'. esc_path($to->{'file'});1652}1653}16541655return"<div class=\"diff header\">$line</div>\n";1656}16571658# format extended diff header line, before patch itself1659sub format_extended_diff_header_line {1660my$line=shift;1661my$diffinfo=shift;1662my($from,$to) =@_;16631664# match <path>1665if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1666$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1667 esc_path($from->{'file'}));1668}1669if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1670$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1671 esc_path($to->{'file'}));1672}1673# match single <mode>1674if($line=~m/\s(\d{6})$/) {1675$line.='<span class="info"> ('.1676 file_type_long($1) .1677')</span>';1678}1679# match <hash>1680if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1681# can match only for combined diff1682$line='index ';1683for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1684if($from->{'href'}[$i]) {1685$line.=$cgi->a({-href=>$from->{'href'}[$i],1686-class=>"hash"},1687substr($diffinfo->{'from_id'}[$i],0,7));1688}else{1689$line.='0' x 7;1690}1691# separator1692$line.=','if($i<$diffinfo->{'nparents'} -1);1693}1694$line.='..';1695if($to->{'href'}) {1696$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1697substr($diffinfo->{'to_id'},0,7));1698}else{1699$line.='0' x 7;1700}17011702}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1703# can match only for ordinary diff1704my($from_link,$to_link);1705if($from->{'href'}) {1706$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1707substr($diffinfo->{'from_id'},0,7));1708}else{1709$from_link='0' x 7;1710}1711if($to->{'href'}) {1712$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1713substr($diffinfo->{'to_id'},0,7));1714}else{1715$to_link='0' x 7;1716}1717my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1718$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1719}17201721return$line."<br/>\n";1722}17231724# format from-file/to-file diff header1725sub format_diff_from_to_header {1726my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1727my$line;1728my$result='';17291730$line=$from_line;1731#assert($line =~ m/^---/) if DEBUG;1732# no extra formatting for "^--- /dev/null"1733if(!$diffinfo->{'nparents'}) {1734# ordinary (single parent) diff1735if($line=~m!^--- "?a/!) {1736if($from->{'href'}) {1737$line='--- a/'.1738$cgi->a({-href=>$from->{'href'}, -class=>"path"},1739 esc_path($from->{'file'}));1740}else{1741$line='--- a/'.1742 esc_path($from->{'file'});1743}1744}1745$result.= qq!<div class="diff from_file">$line</div>\n!;17461747}else{1748# combined diff (merge commit)1749for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1750if($from->{'href'}[$i]) {1751$line='--- '.1752$cgi->a({-href=>href(action=>"blobdiff",1753 hash_parent=>$diffinfo->{'from_id'}[$i],1754 hash_parent_base=>$parents[$i],1755 file_parent=>$from->{'file'}[$i],1756 hash=>$diffinfo->{'to_id'},1757 hash_base=>$hash,1758 file_name=>$to->{'file'}),1759-class=>"path",1760-title=>"diff". ($i+1)},1761$i+1) .1762'/'.1763$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1764 esc_path($from->{'file'}[$i]));1765}else{1766$line='--- /dev/null';1767}1768$result.= qq!<div class="diff from_file">$line</div>\n!;1769}1770}17711772$line=$to_line;1773#assert($line =~ m/^\+\+\+/) if DEBUG;1774# no extra formatting for "^+++ /dev/null"1775if($line=~m!^\+\+\+ "?b/!) {1776if($to->{'href'}) {1777$line='+++ b/'.1778$cgi->a({-href=>$to->{'href'}, -class=>"path"},1779 esc_path($to->{'file'}));1780}else{1781$line='+++ b/'.1782 esc_path($to->{'file'});1783}1784}1785$result.= qq!<div class="diff to_file">$line</div>\n!;17861787return$result;1788}17891790# create note for patch simplified by combined diff1791sub format_diff_cc_simplified {1792my($diffinfo,@parents) =@_;1793my$result='';17941795$result.="<div class=\"diff header\">".1796"diff --cc ";1797if(!is_deleted($diffinfo)) {1798$result.=$cgi->a({-href => href(action=>"blob",1799 hash_base=>$hash,1800 hash=>$diffinfo->{'to_id'},1801 file_name=>$diffinfo->{'to_file'}),1802-class=>"path"},1803 esc_path($diffinfo->{'to_file'}));1804}else{1805$result.= esc_path($diffinfo->{'to_file'});1806}1807$result.="</div>\n".# class="diff header"1808"<div class=\"diff nodifferences\">".1809"Simple merge".1810"</div>\n";# class="diff nodifferences"18111812return$result;1813}18141815# format patch (diff) line (not to be used for diff headers)1816sub format_diff_line {1817my$line=shift;1818my($from,$to) =@_;1819my$diff_class="";18201821chomp$line;18221823if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1824# combined diff1825my$prefix=substr($line,0,scalar@{$from->{'href'}});1826if($line=~m/^\@{3}/) {1827$diff_class=" chunk_header";1828}elsif($line=~m/^\\/) {1829$diff_class=" incomplete";1830}elsif($prefix=~tr/+/+/) {1831$diff_class=" add";1832}elsif($prefix=~tr/-/-/) {1833$diff_class=" rem";1834}1835}else{1836# assume ordinary diff1837my$char=substr($line,0,1);1838if($chareq'+') {1839$diff_class=" add";1840}elsif($chareq'-') {1841$diff_class=" rem";1842}elsif($chareq'@') {1843$diff_class=" chunk_header";1844}elsif($chareq"\\") {1845$diff_class=" incomplete";1846}1847}1848$line= untabify($line);1849if($from&&$to&&$line=~m/^\@{2} /) {1850my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1851$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;18521853$from_lines=0unlessdefined$from_lines;1854$to_lines=0unlessdefined$to_lines;18551856if($from->{'href'}) {1857$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1858-class=>"list"},$from_text);1859}1860if($to->{'href'}) {1861$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1862-class=>"list"},$to_text);1863}1864$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1865"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1866return"<div class=\"diff$diff_class\">$line</div>\n";1867}elsif($from&&$to&&$line=~m/^\@{3}/) {1868my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1869my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);18701871@from_text=split(' ',$ranges);1872for(my$i=0;$i<@from_text; ++$i) {1873($from_start[$i],$from_nlines[$i]) =1874(split(',',substr($from_text[$i],1)),0);1875}18761877$to_text=pop@from_text;1878$to_start=pop@from_start;1879$to_nlines=pop@from_nlines;18801881$line="<span class=\"chunk_info\">$prefix";1882for(my$i=0;$i<@from_text; ++$i) {1883if($from->{'href'}[$i]) {1884$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1885-class=>"list"},$from_text[$i]);1886}else{1887$line.=$from_text[$i];1888}1889$line.=" ";1890}1891if($to->{'href'}) {1892$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1893-class=>"list"},$to_text);1894}else{1895$line.=$to_text;1896}1897$line.="$prefix</span>".1898"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1899return"<div class=\"diff$diff_class\">$line</div>\n";1900}1901return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1902}19031904# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1905# linked. Pass the hash of the tree/commit to snapshot.1906sub format_snapshot_links {1907my($hash) =@_;1908my$num_fmts=@snapshot_fmts;1909if($num_fmts>1) {1910# A parenthesized list of links bearing format names.1911# e.g. "snapshot (_tar.gz_ _zip_)"1912return"snapshot (".join(' ',map1913$cgi->a({1914-href => href(1915 action=>"snapshot",1916 hash=>$hash,1917 snapshot_format=>$_1918)1919},$known_snapshot_formats{$_}{'display'})1920,@snapshot_fmts) .")";1921}elsif($num_fmts==1) {1922# A single "snapshot" link whose tooltip bears the format name.1923# i.e. "_snapshot_"1924my($fmt) =@snapshot_fmts;1925return1926$cgi->a({1927-href => href(1928 action=>"snapshot",1929 hash=>$hash,1930 snapshot_format=>$fmt1931),1932-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"1933},"snapshot");1934}else{# $num_fmts == 01935returnundef;1936}1937}19381939## ......................................................................1940## functions returning values to be passed, perhaps after some1941## transformation, to other functions; e.g. returning arguments to href()19421943# returns hash to be passed to href to generate gitweb URL1944# in -title key it returns description of link1945sub get_feed_info {1946my$format=shift||'Atom';1947my%res= (action =>lc($format));19481949# feed links are possible only for project views1950return unless(defined$project);1951# some views should link to OPML, or to generic project feed,1952# or don't have specific feed yet (so they should use generic)1953return if($action=~/^(?:tags|heads|forks|tag|search)$/x);19541955my$branch;1956# branches refs uses 'refs/heads/' prefix (fullname) to differentiate1957# from tag links; this also makes possible to detect branch links1958if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||1959(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {1960$branch=$1;1961}1962# find log type for feed description (title)1963my$type='log';1964if(defined$file_name) {1965$type="history of$file_name";1966$type.="/"if($actioneq'tree');1967$type.=" on '$branch'"if(defined$branch);1968}else{1969$type="log of$branch"if(defined$branch);1970}19711972$res{-title} =$type;1973$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);1974$res{'file_name'} =$file_name;19751976return%res;1977}19781979## ----------------------------------------------------------------------1980## git utility subroutines, invoking git commands19811982# returns path to the core git executable and the --git-dir parameter as list1983sub git_cmd {1984return$GIT,'--git-dir='.$git_dir;1985}19861987# quote the given arguments for passing them to the shell1988# quote_command("command", "arg 1", "arg with ' and ! characters")1989# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"1990# Try to avoid using this function wherever possible.1991sub quote_command {1992returnjoin(' ',1993map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);1994}19951996# get HEAD ref of given project as hash1997sub git_get_head_hash {1998my$project=shift;1999my$o_git_dir=$git_dir;2000my$retval=undef;2001$git_dir="$projectroot/$project";2002if(open my$fd,"-|", git_cmd(),"rev-parse","--verify","HEAD") {2003my$head= <$fd>;2004close$fd;2005if(defined$head&&$head=~/^([0-9a-fA-F]{40})$/) {2006$retval=$1;2007}2008}2009if(defined$o_git_dir) {2010$git_dir=$o_git_dir;2011}2012return$retval;2013}20142015# get type of given object2016sub git_get_type {2017my$hash=shift;20182019open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2020my$type= <$fd>;2021close$fdorreturn;2022chomp$type;2023return$type;2024}20252026# repository configuration2027our$config_file='';2028our%config;20292030# store multiple values for single key as anonymous array reference2031# single values stored directly in the hash, not as [ <value> ]2032sub hash_set_multi {2033my($hash,$key,$value) =@_;20342035if(!exists$hash->{$key}) {2036$hash->{$key} =$value;2037}elsif(!ref$hash->{$key}) {2038$hash->{$key} = [$hash->{$key},$value];2039}else{2040push@{$hash->{$key}},$value;2041}2042}20432044# return hash of git project configuration2045# optionally limited to some section, e.g. 'gitweb'2046sub git_parse_project_config {2047my$section_regexp=shift;2048my%config;20492050local$/="\0";20512052open my$fh,"-|", git_cmd(),"config",'-z','-l',2053orreturn;20542055while(my$keyval= <$fh>) {2056chomp$keyval;2057my($key,$value) =split(/\n/,$keyval,2);20582059 hash_set_multi(\%config,$key,$value)2060if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2061}2062close$fh;20632064return%config;2065}20662067# convert config value to boolean: 'true' or 'false'2068# no value, number > 0, 'true' and 'yes' values are true2069# rest of values are treated as false (never as error)2070sub config_to_bool {2071my$val=shift;20722073return1if!defined$val;# section.key20742075# strip leading and trailing whitespace2076$val=~s/^\s+//;2077$val=~s/\s+$//;20782079return(($val=~/^\d+$/&&$val) ||# section.key = 12080($val=~/^(?:true|yes)$/i));# section.key = true2081}20822083# convert config value to simple decimal number2084# an optional value suffix of 'k', 'm', or 'g' will cause the value2085# to be multiplied by 1024, 1048576, or 10737418242086sub config_to_int {2087my$val=shift;20882089# strip leading and trailing whitespace2090$val=~s/^\s+//;2091$val=~s/\s+$//;20922093if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2094$unit=lc($unit);2095# unknown unit is treated as 12096return$num* ($uniteq'g'?1073741824:2097$uniteq'm'?1048576:2098$uniteq'k'?1024:1);2099}2100return$val;2101}21022103# convert config value to array reference, if needed2104sub config_to_multi {2105my$val=shift;21062107returnref($val) ?$val: (defined($val) ? [$val] : []);2108}21092110sub git_get_project_config {2111my($key,$type) =@_;21122113# key sanity check2114return unless($key);2115$key=~s/^gitweb\.//;2116return if($key=~m/\W/);21172118# type sanity check2119if(defined$type) {2120$type=~s/^--//;2121$type=undef2122unless($typeeq'bool'||$typeeq'int');2123}21242125# get config2126if(!defined$config_file||2127$config_filene"$git_dir/config") {2128%config= git_parse_project_config('gitweb');2129$config_file="$git_dir/config";2130}21312132# check if config variable (key) exists2133return unlessexists$config{"gitweb.$key"};21342135# ensure given type2136if(!defined$type) {2137return$config{"gitweb.$key"};2138}elsif($typeeq'bool') {2139# backward compatibility: 'git config --bool' returns true/false2140return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2141}elsif($typeeq'int') {2142return config_to_int($config{"gitweb.$key"});2143}2144return$config{"gitweb.$key"};2145}21462147# get hash of given path at given ref2148sub git_get_hash_by_path {2149my$base=shift;2150my$path=shift||returnundef;2151my$type=shift;21522153$path=~ s,/+$,,;21542155open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2156or die_error(500,"Open git-ls-tree failed");2157my$line= <$fd>;2158close$fdorreturnundef;21592160if(!defined$line) {2161# there is no tree or hash given by $path at $base2162returnundef;2163}21642165#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2166$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2167if(defined$type&&$typene$2) {2168# type doesn't match2169returnundef;2170}2171return$3;2172}21732174# get path of entry with given hash at given tree-ish (ref)2175# used to get 'from' filename for combined diff (merge commit) for renames2176sub git_get_path_by_hash {2177my$base=shift||return;2178my$hash=shift||return;21792180local$/="\0";21812182open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2183orreturnundef;2184while(my$line= <$fd>) {2185chomp$line;21862187#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2188#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2189if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2190close$fd;2191return$1;2192}2193}2194close$fd;2195returnundef;2196}21972198## ......................................................................2199## git utility functions, directly accessing git repository22002201sub git_get_project_description {2202my$path=shift;22032204$git_dir="$projectroot/$path";2205open my$fd,'<',"$git_dir/description"2206orreturn git_get_project_config('description');2207my$descr= <$fd>;2208close$fd;2209if(defined$descr) {2210chomp$descr;2211}2212return$descr;2213}22142215sub git_get_project_ctags {2216my$path=shift;2217my$ctags= {};22182219$git_dir="$projectroot/$path";2220opendir my$dh,"$git_dir/ctags"2221orreturn$ctags;2222foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2223open my$ct,'<',$_ornext;2224my$val= <$ct>;2225chomp$val;2226close$ct;2227my$ctag=$_;$ctag=~ s#.*/##;2228$ctags->{$ctag} =$val;2229}2230closedir$dh;2231$ctags;2232}22332234sub git_populate_project_tagcloud {2235my$ctags=shift;22362237# First, merge different-cased tags; tags vote on casing2238my%ctags_lc;2239foreach(keys%$ctags) {2240$ctags_lc{lc$_}->{count} +=$ctags->{$_};2241if(not$ctags_lc{lc$_}->{topcount}2242or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2243$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2244$ctags_lc{lc$_}->{topname} =$_;2245}2246}22472248my$cloud;2249if(eval{require HTML::TagCloud;1; }) {2250$cloud= HTML::TagCloud->new;2251foreach(sort keys%ctags_lc) {2252# Pad the title with spaces so that the cloud looks2253# less crammed.2254my$title=$ctags_lc{$_}->{topname};2255$title=~s/ / /g;2256$title=~s/^/ /g;2257$title=~s/$/ /g;2258$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2259}2260}else{2261$cloud= \%ctags_lc;2262}2263$cloud;2264}22652266sub git_show_project_tagcloud {2267my($cloud,$count) =@_;2268print STDERR ref($cloud)."..\n";2269if(ref$cloudeq'HTML::TagCloud') {2270return$cloud->html_and_css($count);2271}else{2272my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2273return'<p align="center">'.join(', ',map{2274"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"2275}splice(@tags,0,$count)) .'</p>';2276}2277}22782279sub git_get_project_url_list {2280my$path=shift;22812282$git_dir="$projectroot/$path";2283open my$fd,'<',"$git_dir/cloneurl"2284orreturnwantarray?2285@{ config_to_multi(git_get_project_config('url')) } :2286 config_to_multi(git_get_project_config('url'));2287my@git_project_url_list=map{chomp;$_} <$fd>;2288close$fd;22892290returnwantarray?@git_project_url_list: \@git_project_url_list;2291}22922293sub git_get_projects_list {2294my($filter) =@_;2295my@list;22962297$filter||='';2298$filter=~s/\.git$//;22992300my$check_forks= gitweb_check_feature('forks');23012302if(-d $projects_list) {2303# search in directory2304my$dir=$projects_list. ($filter?"/$filter":'');2305# remove the trailing "/"2306$dir=~s!/+$!!;2307my$pfxlen=length("$dir");2308my$pfxdepth= ($dir=~tr!/!!);23092310 File::Find::find({2311 follow_fast =>1,# follow symbolic links2312 follow_skip =>2,# ignore duplicates2313 dangling_symlinks =>0,# ignore dangling symlinks, silently2314 wanted =>sub{2315# skip project-list toplevel, if we get it.2316return if(m!^[/.]$!);2317# only directories can be git repositories2318return unless(-d $_);2319# don't traverse too deep (Find is super slow on os x)2320if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2321$File::Find::prune =1;2322return;2323}23242325my$subdir=substr($File::Find::name,$pfxlen+1);2326# we check related file in $projectroot2327my$path= ($filter?"$filter/":'') .$subdir;2328if(check_export_ok("$projectroot/$path")) {2329push@list, { path =>$path};2330$File::Find::prune =1;2331}2332},2333},"$dir");23342335}elsif(-f $projects_list) {2336# read from file(url-encoded):2337# 'git%2Fgit.git Linus+Torvalds'2338# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2339# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2340my%paths;2341open my$fd,'<',$projects_listorreturn;2342 PROJECT:2343while(my$line= <$fd>) {2344chomp$line;2345my($path,$owner) =split' ',$line;2346$path= unescape($path);2347$owner= unescape($owner);2348if(!defined$path) {2349next;2350}2351if($filterne'') {2352# looking for forks;2353my$pfx=substr($path,0,length($filter));2354if($pfxne$filter) {2355next PROJECT;2356}2357my$sfx=substr($path,length($filter));2358if($sfx!~/^\/.*\.git$/) {2359next PROJECT;2360}2361}elsif($check_forks) {2362 PATH:2363foreachmy$filter(keys%paths) {2364# looking for forks;2365my$pfx=substr($path,0,length($filter));2366if($pfxne$filter) {2367next PATH;2368}2369my$sfx=substr($path,length($filter));2370if($sfx!~/^\/.*\.git$/) {2371next PATH;2372}2373# is a fork, don't include it in2374# the list2375next PROJECT;2376}2377}2378if(check_export_ok("$projectroot/$path")) {2379my$pr= {2380 path =>$path,2381 owner => to_utf8($owner),2382};2383push@list,$pr;2384(my$forks_path=$path) =~s/\.git$//;2385$paths{$forks_path}++;2386}2387}2388close$fd;2389}2390return@list;2391}23922393our$gitweb_project_owner=undef;2394sub git_get_project_list_from_file {23952396return if(defined$gitweb_project_owner);23972398$gitweb_project_owner= {};2399# read from file (url-encoded):2400# 'git%2Fgit.git Linus+Torvalds'2401# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2402# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2403if(-f $projects_list) {2404open(my$fd,'<',$projects_list);2405while(my$line= <$fd>) {2406chomp$line;2407my($pr,$ow) =split' ',$line;2408$pr= unescape($pr);2409$ow= unescape($ow);2410$gitweb_project_owner->{$pr} = to_utf8($ow);2411}2412close$fd;2413}2414}24152416sub git_get_project_owner {2417my$project=shift;2418my$owner;24192420returnundefunless$project;2421$git_dir="$projectroot/$project";24222423if(!defined$gitweb_project_owner) {2424 git_get_project_list_from_file();2425}24262427if(exists$gitweb_project_owner->{$project}) {2428$owner=$gitweb_project_owner->{$project};2429}2430if(!defined$owner){2431$owner= git_get_project_config('owner');2432}2433if(!defined$owner) {2434$owner= get_file_owner("$git_dir");2435}24362437return$owner;2438}24392440sub git_get_last_activity {2441my($path) =@_;2442my$fd;24432444$git_dir="$projectroot/$path";2445open($fd,"-|", git_cmd(),'for-each-ref',2446'--format=%(committer)',2447'--sort=-committerdate',2448'--count=1',2449'refs/heads')orreturn;2450my$most_recent= <$fd>;2451close$fdorreturn;2452if(defined$most_recent&&2453$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2454my$timestamp=$1;2455my$age=time-$timestamp;2456return($age, age_string($age));2457}2458return(undef,undef);2459}24602461sub git_get_references {2462my$type=shift||"";2463my%refs;2464# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112465# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2466open my$fd,"-|", git_cmd(),"show-ref","--dereference",2467($type? ("--","refs/$type") : ())# use -- <pattern> if $type2468orreturn;24692470while(my$line= <$fd>) {2471chomp$line;2472if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2473if(defined$refs{$1}) {2474push@{$refs{$1}},$2;2475}else{2476$refs{$1} = [$2];2477}2478}2479}2480close$fdorreturn;2481return \%refs;2482}24832484sub git_get_rev_name_tags {2485my$hash=shift||returnundef;24862487open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2488orreturn;2489my$name_rev= <$fd>;2490close$fd;24912492if($name_rev=~ m|^$hash tags/(.*)$|) {2493return$1;2494}else{2495# catches also '$hash undefined' output2496returnundef;2497}2498}24992500## ----------------------------------------------------------------------2501## parse to hash functions25022503sub parse_date {2504my$epoch=shift;2505my$tz=shift||"-0000";25062507my%date;2508my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2509my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2510my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2511$date{'hour'} =$hour;2512$date{'minute'} =$min;2513$date{'mday'} =$mday;2514$date{'day'} =$days[$wday];2515$date{'month'} =$months[$mon];2516$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2517$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2518$date{'mday-time'} =sprintf"%d%s%02d:%02d",2519$mday,$months[$mon],$hour,$min;2520$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",25211900+$year,1+$mon,$mday,$hour,$min,$sec;25222523$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2524my$local=$epoch+ ((int$1+ ($2/60)) *3600);2525($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2526$date{'hour_local'} =$hour;2527$date{'minute_local'} =$min;2528$date{'tz_local'} =$tz;2529$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",25301900+$year,$mon+1,$mday,2531$hour,$min,$sec,$tz);2532return%date;2533}25342535sub parse_tag {2536my$tag_id=shift;2537my%tag;2538my@comment;25392540open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2541$tag{'id'} =$tag_id;2542while(my$line= <$fd>) {2543chomp$line;2544if($line=~m/^object ([0-9a-fA-F]{40})$/) {2545$tag{'object'} =$1;2546}elsif($line=~m/^type (.+)$/) {2547$tag{'type'} =$1;2548}elsif($line=~m/^tag (.+)$/) {2549$tag{'name'} =$1;2550}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2551$tag{'author'} =$1;2552$tag{'author_epoch'} =$2;2553$tag{'author_tz'} =$3;2554if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {2555$tag{'author_name'} =$1;2556$tag{'author_email'} =$2;2557}else{2558$tag{'author_name'} =$tag{'author'};2559}2560}elsif($line=~m/--BEGIN/) {2561push@comment,$line;2562last;2563}elsif($lineeq"") {2564last;2565}2566}2567push@comment, <$fd>;2568$tag{'comment'} = \@comment;2569close$fdorreturn;2570if(!defined$tag{'name'}) {2571return2572};2573return%tag2574}25752576sub parse_commit_text {2577my($commit_text,$withparents) =@_;2578my@commit_lines=split'\n',$commit_text;2579my%co;25802581pop@commit_lines;# Remove '\0'25822583if(!@commit_lines) {2584return;2585}25862587my$header=shift@commit_lines;2588if($header!~m/^[0-9a-fA-F]{40}/) {2589return;2590}2591($co{'id'},my@parents) =split' ',$header;2592while(my$line=shift@commit_lines) {2593last if$lineeq"\n";2594if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2595$co{'tree'} =$1;2596}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2597push@parents,$1;2598}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2599$co{'author'} = to_utf8($1);2600$co{'author_epoch'} =$2;2601$co{'author_tz'} =$3;2602if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2603$co{'author_name'} =$1;2604$co{'author_email'} =$2;2605}else{2606$co{'author_name'} =$co{'author'};2607}2608}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2609$co{'committer'} = to_utf8($1);2610$co{'committer_epoch'} =$2;2611$co{'committer_tz'} =$3;2612if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2613$co{'committer_name'} =$1;2614$co{'committer_email'} =$2;2615}else{2616$co{'committer_name'} =$co{'committer'};2617}2618}2619}2620if(!defined$co{'tree'}) {2621return;2622};2623$co{'parents'} = \@parents;2624$co{'parent'} =$parents[0];26252626foreachmy$title(@commit_lines) {2627$title=~s/^ //;2628if($titlene"") {2629$co{'title'} = chop_str($title,80,5);2630# remove leading stuff of merges to make the interesting part visible2631if(length($title) >50) {2632$title=~s/^Automatic //;2633$title=~s/^merge (of|with) /Merge ... /i;2634if(length($title) >50) {2635$title=~s/(http|rsync):\/\///;2636}2637if(length($title) >50) {2638$title=~s/(master|www|rsync)\.//;2639}2640if(length($title) >50) {2641$title=~s/kernel.org:?//;2642}2643if(length($title) >50) {2644$title=~s/\/pub\/scm//;2645}2646}2647$co{'title_short'} = chop_str($title,50,5);2648last;2649}2650}2651if(!defined$co{'title'} ||$co{'title'}eq"") {2652$co{'title'} =$co{'title_short'} ='(no commit message)';2653}2654# remove added spaces2655foreachmy$line(@commit_lines) {2656$line=~s/^ //;2657}2658$co{'comment'} = \@commit_lines;26592660my$age=time-$co{'committer_epoch'};2661$co{'age'} =$age;2662$co{'age_string'} = age_string($age);2663my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2664if($age>60*60*24*7*2) {2665$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2666$co{'age_string_age'} =$co{'age_string'};2667}else{2668$co{'age_string_date'} =$co{'age_string'};2669$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2670}2671return%co;2672}26732674sub parse_commit {2675my($commit_id) =@_;2676my%co;26772678local$/="\0";26792680open my$fd,"-|", git_cmd(),"rev-list",2681"--parents",2682"--header",2683"--max-count=1",2684$commit_id,2685"--",2686or die_error(500,"Open git-rev-list failed");2687%co= parse_commit_text(<$fd>,1);2688close$fd;26892690return%co;2691}26922693sub parse_commits {2694my($commit_id,$maxcount,$skip,$filename,@args) =@_;2695my@cos;26962697$maxcount||=1;2698$skip||=0;26992700local$/="\0";27012702open my$fd,"-|", git_cmd(),"rev-list",2703"--header",2704@args,2705("--max-count=".$maxcount),2706("--skip=".$skip),2707@extra_options,2708$commit_id,2709"--",2710($filename? ($filename) : ())2711or die_error(500,"Open git-rev-list failed");2712while(my$line= <$fd>) {2713my%co= parse_commit_text($line);2714push@cos, \%co;2715}2716close$fd;27172718returnwantarray?@cos: \@cos;2719}27202721# parse line of git-diff-tree "raw" output2722sub parse_difftree_raw_line {2723my$line=shift;2724my%res;27252726# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2727# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2728if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2729$res{'from_mode'} =$1;2730$res{'to_mode'} =$2;2731$res{'from_id'} =$3;2732$res{'to_id'} =$4;2733$res{'status'} =$5;2734$res{'similarity'} =$6;2735if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2736($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2737}else{2738$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2739}2740}2741# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2742# combined diff (for merge commit)2743elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2744$res{'nparents'} =length($1);2745$res{'from_mode'} = [split(' ',$2) ];2746$res{'to_mode'} =pop@{$res{'from_mode'}};2747$res{'from_id'} = [split(' ',$3) ];2748$res{'to_id'} =pop@{$res{'from_id'}};2749$res{'status'} = [split('',$4) ];2750$res{'to_file'} = unquote($5);2751}2752# 'c512b523472485aef4fff9e57b229d9d243c967f'2753elsif($line=~m/^([0-9a-fA-F]{40})$/) {2754$res{'commit'} =$1;2755}27562757returnwantarray?%res: \%res;2758}27592760# wrapper: return parsed line of git-diff-tree "raw" output2761# (the argument might be raw line, or parsed info)2762sub parsed_difftree_line {2763my$line_or_ref=shift;27642765if(ref($line_or_ref)eq"HASH") {2766# pre-parsed (or generated by hand)2767return$line_or_ref;2768}else{2769return parse_difftree_raw_line($line_or_ref);2770}2771}27722773# parse line of git-ls-tree output2774sub parse_ls_tree_line {2775my$line=shift;2776my%opts=@_;2777my%res;27782779if($opts{'-l'}) {2780#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'2781$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;27822783$res{'mode'} =$1;2784$res{'type'} =$2;2785$res{'hash'} =$3;2786$res{'size'} =$4;2787if($opts{'-z'}) {2788$res{'name'} =$5;2789}else{2790$res{'name'} = unquote($5);2791}2792}else{2793#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2794$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;27952796$res{'mode'} =$1;2797$res{'type'} =$2;2798$res{'hash'} =$3;2799if($opts{'-z'}) {2800$res{'name'} =$4;2801}else{2802$res{'name'} = unquote($4);2803}2804}28052806returnwantarray?%res: \%res;2807}28082809# generates _two_ hashes, references to which are passed as 2 and 3 argument2810sub parse_from_to_diffinfo {2811my($diffinfo,$from,$to,@parents) =@_;28122813if($diffinfo->{'nparents'}) {2814# combined diff2815$from->{'file'} = [];2816$from->{'href'} = [];2817 fill_from_file_info($diffinfo,@parents)2818unlessexists$diffinfo->{'from_file'};2819for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2820$from->{'file'}[$i] =2821defined$diffinfo->{'from_file'}[$i] ?2822$diffinfo->{'from_file'}[$i] :2823$diffinfo->{'to_file'};2824if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2825$from->{'href'}[$i] = href(action=>"blob",2826 hash_base=>$parents[$i],2827 hash=>$diffinfo->{'from_id'}[$i],2828 file_name=>$from->{'file'}[$i]);2829}else{2830$from->{'href'}[$i] =undef;2831}2832}2833}else{2834# ordinary (not combined) diff2835$from->{'file'} =$diffinfo->{'from_file'};2836if($diffinfo->{'status'}ne"A") {# not new (added) file2837$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2838 hash=>$diffinfo->{'from_id'},2839 file_name=>$from->{'file'});2840}else{2841delete$from->{'href'};2842}2843}28442845$to->{'file'} =$diffinfo->{'to_file'};2846if(!is_deleted($diffinfo)) {# file exists in result2847$to->{'href'} = href(action=>"blob", hash_base=>$hash,2848 hash=>$diffinfo->{'to_id'},2849 file_name=>$to->{'file'});2850}else{2851delete$to->{'href'};2852}2853}28542855## ......................................................................2856## parse to array of hashes functions28572858sub git_get_heads_list {2859my$limit=shift;2860my@headslist;28612862open my$fd,'-|', git_cmd(),'for-each-ref',2863($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2864'--format=%(objectname) %(refname) %(subject)%00%(committer)',2865'refs/heads'2866orreturn;2867while(my$line= <$fd>) {2868my%ref_item;28692870chomp$line;2871my($refinfo,$committerinfo) =split(/\0/,$line);2872my($hash,$name,$title) =split(' ',$refinfo,3);2873my($committer,$epoch,$tz) =2874($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2875$ref_item{'fullname'} =$name;2876$name=~s!^refs/heads/!!;28772878$ref_item{'name'} =$name;2879$ref_item{'id'} =$hash;2880$ref_item{'title'} =$title||'(no commit message)';2881$ref_item{'epoch'} =$epoch;2882if($epoch) {2883$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2884}else{2885$ref_item{'age'} ="unknown";2886}28872888push@headslist, \%ref_item;2889}2890close$fd;28912892returnwantarray?@headslist: \@headslist;2893}28942895sub git_get_tags_list {2896my$limit=shift;2897my@tagslist;28982899open my$fd,'-|', git_cmd(),'for-each-ref',2900($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',2901'--format=%(objectname) %(objecttype) %(refname) '.2902'%(*objectname) %(*objecttype) %(subject)%00%(creator)',2903'refs/tags'2904orreturn;2905while(my$line= <$fd>) {2906my%ref_item;29072908chomp$line;2909my($refinfo,$creatorinfo) =split(/\0/,$line);2910my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);2911my($creator,$epoch,$tz) =2912($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);2913$ref_item{'fullname'} =$name;2914$name=~s!^refs/tags/!!;29152916$ref_item{'type'} =$type;2917$ref_item{'id'} =$id;2918$ref_item{'name'} =$name;2919if($typeeq"tag") {2920$ref_item{'subject'} =$title;2921$ref_item{'reftype'} =$reftype;2922$ref_item{'refid'} =$refid;2923}else{2924$ref_item{'reftype'} =$type;2925$ref_item{'refid'} =$id;2926}29272928if($typeeq"tag"||$typeeq"commit") {2929$ref_item{'epoch'} =$epoch;2930if($epoch) {2931$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2932}else{2933$ref_item{'age'} ="unknown";2934}2935}29362937push@tagslist, \%ref_item;2938}2939close$fd;29402941returnwantarray?@tagslist: \@tagslist;2942}29432944## ----------------------------------------------------------------------2945## filesystem-related functions29462947sub get_file_owner {2948my$path=shift;29492950my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);2951my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);2952if(!defined$gcos) {2953returnundef;2954}2955my$owner=$gcos;2956$owner=~s/[,;].*$//;2957return to_utf8($owner);2958}29592960# assume that file exists2961sub insert_file {2962my$filename=shift;29632964open my$fd,'<',$filename;2965print map{ to_utf8($_) } <$fd>;2966close$fd;2967}29682969## ......................................................................2970## mimetype related functions29712972sub mimetype_guess_file {2973my$filename=shift;2974my$mimemap=shift;2975-r $mimemaporreturnundef;29762977my%mimemap;2978open(my$mh,'<',$mimemap)orreturnundef;2979while(<$mh>) {2980next ifm/^#/;# skip comments2981my($mimetype,$exts) =split(/\t+/);2982if(defined$exts) {2983my@exts=split(/\s+/,$exts);2984foreachmy$ext(@exts) {2985$mimemap{$ext} =$mimetype;2986}2987}2988}2989close($mh);29902991$filename=~/\.([^.]*)$/;2992return$mimemap{$1};2993}29942995sub mimetype_guess {2996my$filename=shift;2997my$mime;2998$filename=~/\./orreturnundef;29993000if($mimetypes_file) {3001my$file=$mimetypes_file;3002if($file!~m!^/!) {# if it is relative path3003# it is relative to project3004$file="$projectroot/$project/$file";3005}3006$mime= mimetype_guess_file($filename,$file);3007}3008$mime||= mimetype_guess_file($filename,'/etc/mime.types');3009return$mime;3010}30113012sub blob_mimetype {3013my$fd=shift;3014my$filename=shift;30153016if($filename) {3017my$mime= mimetype_guess($filename);3018$mimeandreturn$mime;3019}30203021# just in case3022return$default_blob_plain_mimetypeunless$fd;30233024if(-T $fd) {3025return'text/plain';3026}elsif(!$filename) {3027return'application/octet-stream';3028}elsif($filename=~m/\.png$/i) {3029return'image/png';3030}elsif($filename=~m/\.gif$/i) {3031return'image/gif';3032}elsif($filename=~m/\.jpe?g$/i) {3033return'image/jpeg';3034}else{3035return'application/octet-stream';3036}3037}30383039sub blob_contenttype {3040my($fd,$file_name,$type) =@_;30413042$type||= blob_mimetype($fd,$file_name);3043if($typeeq'text/plain'&&defined$default_text_plain_charset) {3044$type.="; charset=$default_text_plain_charset";3045}30463047return$type;3048}30493050## ======================================================================3051## functions printing HTML: header, footer, error page30523053sub git_header_html {3054my$status=shift||"200 OK";3055my$expires=shift;30563057my$title="$site_name";3058if(defined$project) {3059$title.=" - ". to_utf8($project);3060if(defined$action) {3061$title.="/$action";3062if(defined$file_name) {3063$title.=" - ". esc_path($file_name);3064if($actioneq"tree"&&$file_name!~ m|/$|) {3065$title.="/";3066}3067}3068}3069}3070my$content_type;3071# require explicit support from the UA if we are to send the page as3072# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3073# we have to do this because MSIE sometimes globs '*/*', pretending to3074# support xhtml+xml but choking when it gets what it asked for.3075if(defined$cgi->http('HTTP_ACCEPT') &&3076$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3077$cgi->Accept('application/xhtml+xml') !=0) {3078$content_type='application/xhtml+xml';3079}else{3080$content_type='text/html';3081}3082print$cgi->header(-type=>$content_type, -charset =>'utf-8',3083-status=>$status, -expires =>$expires);3084my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';3085print<<EOF;3086<?xml version="1.0" encoding="utf-8"?>3087<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">3088<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">3089<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->3090<!-- git core binaries version$git_version-->3091<head>3092<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>3093<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>3094<meta name="robots" content="index, nofollow"/>3095<title>$title</title>3096EOF3097# the stylesheet, favicon etc urls won't work correctly with path_info3098# unless we set the appropriate base URL3099if($ENV{'PATH_INFO'}) {3100print"<base href=\"".esc_url($base_url)."\"/>\n";3101}3102# print out each stylesheet that exist, providing backwards capability3103# for those people who defined $stylesheet in a config file3104if(defined$stylesheet) {3105print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3106}else{3107foreachmy$stylesheet(@stylesheets) {3108next unless$stylesheet;3109print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3110}3111}3112if(defined$project) {3113my%href_params= get_feed_info();3114if(!exists$href_params{'-title'}) {3115$href_params{'-title'} ='log';3116}31173118foreachmy$formatqw(RSS Atom){3119my$type=lc($format);3120my%link_attr= (3121'-rel'=>'alternate',3122'-title'=>"$project-$href_params{'-title'} -$formatfeed",3123'-type'=>"application/$type+xml"3124);31253126$href_params{'action'} =$type;3127$link_attr{'-href'} = href(%href_params);3128print"<link ".3129"rel=\"$link_attr{'-rel'}\"".3130"title=\"$link_attr{'-title'}\"".3131"href=\"$link_attr{'-href'}\"".3132"type=\"$link_attr{'-type'}\"".3133"/>\n";31343135$href_params{'extra_options'} ='--no-merges';3136$link_attr{'-href'} = href(%href_params);3137$link_attr{'-title'} .=' (no merges)';3138print"<link ".3139"rel=\"$link_attr{'-rel'}\"".3140"title=\"$link_attr{'-title'}\"".3141"href=\"$link_attr{'-href'}\"".3142"type=\"$link_attr{'-type'}\"".3143"/>\n";3144}31453146}else{3147printf('<link rel="alternate" title="%sprojects list" '.3148'href="%s" type="text/plain; charset=utf-8" />'."\n",3149$site_name, href(project=>undef, action=>"project_index"));3150printf('<link rel="alternate" title="%sprojects feeds" '.3151'href="%s" type="text/x-opml" />'."\n",3152$site_name, href(project=>undef, action=>"opml"));3153}3154if(defined$favicon) {3155printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);3156}31573158print"</head>\n".3159"<body>\n";31603161if(-f $site_header) {3162 insert_file($site_header);3163}31643165print"<div class=\"page_header\">\n".3166$cgi->a({-href => esc_url($logo_url),3167-title =>$logo_label},3168qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));3169print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3170if(defined$project) {3171print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3172if(defined$action) {3173print" /$action";3174}3175print"\n";3176}3177print"</div>\n";31783179my$have_search= gitweb_check_feature('search');3180if(defined$project&&$have_search) {3181if(!defined$searchtext) {3182$searchtext="";3183}3184my$search_hash;3185if(defined$hash_base) {3186$search_hash=$hash_base;3187}elsif(defined$hash) {3188$search_hash=$hash;3189}else{3190$search_hash="HEAD";3191}3192my$action=$my_uri;3193my$use_pathinfo= gitweb_check_feature('pathinfo');3194if($use_pathinfo) {3195$action.="/".esc_url($project);3196}3197print$cgi->startform(-method=>"get", -action =>$action) .3198"<div class=\"search\">\n".3199(!$use_pathinfo&&3200$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3201$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3202$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3203$cgi->popup_menu(-name =>'st', -default=>'commit',3204-values=> ['commit','grep','author','committer','pickaxe']) .3205$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3206" search:\n",3207$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3208"<span title=\"Extended regular expression\">".3209$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3210-checked =>$search_use_regexp) .3211"</span>".3212"</div>".3213$cgi->end_form() ."\n";3214}3215}32163217sub git_footer_html {3218my$feed_class='rss_logo';32193220print"<div class=\"page_footer\">\n";3221if(defined$project) {3222my$descr= git_get_project_description($project);3223if(defined$descr) {3224print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3225}32263227my%href_params= get_feed_info();3228if(!%href_params) {3229$feed_class.=' generic';3230}3231$href_params{'-title'} ||='log';32323233foreachmy$formatqw(RSS Atom){3234$href_params{'action'} =lc($format);3235print$cgi->a({-href => href(%href_params),3236-title =>"$href_params{'-title'}$formatfeed",3237-class=>$feed_class},$format)."\n";3238}32393240}else{3241print$cgi->a({-href => href(project=>undef, action=>"opml"),3242-class=>$feed_class},"OPML") ." ";3243print$cgi->a({-href => href(project=>undef, action=>"project_index"),3244-class=>$feed_class},"TXT") ."\n";3245}3246print"</div>\n";# class="page_footer"32473248if(-f $site_footer) {3249 insert_file($site_footer);3250}32513252print"</body>\n".3253"</html>";3254}32553256# die_error(<http_status_code>, <error_message>)3257# Example: die_error(404, 'Hash not found')3258# By convention, use the following status codes (as defined in RFC 2616):3259# 400: Invalid or missing CGI parameters, or3260# requested object exists but has wrong type.3261# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3262# this server or project.3263# 404: Requested object/revision/project doesn't exist.3264# 500: The server isn't configured properly, or3265# an internal error occurred (e.g. failed assertions caused by bugs), or3266# an unknown error occurred (e.g. the git binary died unexpectedly).3267sub die_error {3268my$status=shift||500;3269my$error=shift||"Internal server error";32703271my%http_responses= (400=>'400 Bad Request',3272403=>'403 Forbidden',3273404=>'404 Not Found',3274500=>'500 Internal Server Error');3275 git_header_html($http_responses{$status});3276print<<EOF;3277<div class="page_body">3278<br /><br />3279$status-$error3280<br />3281</div>3282EOF3283 git_footer_html();3284exit;3285}32863287## ----------------------------------------------------------------------3288## functions printing or outputting HTML: navigation32893290sub git_print_page_nav {3291my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3292$extra=''if!defined$extra;# pager or formats32933294my@navs=qw(summary shortlog log commit commitdiff tree);3295if($suppress) {3296@navs=grep{$_ne$suppress}@navs;3297}32983299my%arg=map{$_=> {action=>$_} }@navs;3300if(defined$head) {3301for(qw(commit commitdiff)) {3302$arg{$_}{'hash'} =$head;3303}3304if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3305for(qw(shortlog log)) {3306$arg{$_}{'hash'} =$head;3307}3308}3309}33103311$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3312$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;33133314my@actions= gitweb_get_feature('actions');3315my%repl= (3316'%'=>'%',3317'n'=>$project,# project name3318'f'=>$git_dir,# project path within filesystem3319'h'=>$treehead||'',# current hash ('h' parameter)3320'b'=>$treebase||'',# hash base ('hb' parameter)3321);3322while(@actions) {3323my($label,$link,$pos) =splice(@actions,0,3);3324# insert3325@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3326# munch munch3327$link=~s/%([%nfhb])/$repl{$1}/g;3328$arg{$label}{'_href'} =$link;3329}33303331print"<div class=\"page_nav\">\n".3332(join" | ",3333map{$_eq$current?3334$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3335}@navs);3336print"<br/>\n$extra<br/>\n".3337"</div>\n";3338}33393340sub format_paging_nav {3341my($action,$hash,$head,$page,$has_next_link) =@_;3342my$paging_nav;334333443345if($hashne$head||$page) {3346$paging_nav.=$cgi->a({-href => href(action=>$action)},"HEAD");3347}else{3348$paging_nav.="HEAD";3349}33503351if($page>0) {3352$paging_nav.=" ⋅ ".3353$cgi->a({-href => href(-replay=>1, page=>$page-1),3354-accesskey =>"p", -title =>"Alt-p"},"prev");3355}else{3356$paging_nav.=" ⋅ prev";3357}33583359if($has_next_link) {3360$paging_nav.=" ⋅ ".3361$cgi->a({-href => href(-replay=>1, page=>$page+1),3362-accesskey =>"n", -title =>"Alt-n"},"next");3363}else{3364$paging_nav.=" ⋅ next";3365}33663367return$paging_nav;3368}33693370## ......................................................................3371## functions printing or outputting HTML: div33723373sub git_print_header_div {3374my($action,$title,$hash,$hash_base) =@_;3375my%args= ();33763377$args{'action'} =$action;3378$args{'hash'} =$hashif$hash;3379$args{'hash_base'} =$hash_baseif$hash_base;33803381print"<div class=\"header\">\n".3382$cgi->a({-href => href(%args), -class=>"title"},3383$title?$title:$action) .3384"\n</div>\n";3385}33863387sub print_local_time {3388my%date=@_;3389if($date{'hour_local'} <6) {3390printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3391$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3392}else{3393printf(" (%02d:%02d%s)",3394$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3395}3396}33973398# Outputs the author name and date in long form3399sub git_print_authorship {3400my$co=shift;3401my%opts=@_;3402my$tag=$opts{-tag} ||'div';34033404my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3405print"<$tagclass=\"author_date\">".3406 esc_html($co->{'author_name'}) .3407" [$ad{'rfc2822'}";3408 print_local_time(%ad)if($opts{-localtime});3409print"]". git_get_avatar($co->{'author_email'}, -pad_before =>1)3410."</$tag>\n";3411}34123413# Outputs table rows containing the full author or committer information,3414# in the format expected for 'commit' view (& similia).3415# Parameters are a commit hash reference, followed by the list of people3416# to output information for. If the list is empty it defalts to both3417# author and committer.3418sub git_print_authorship_rows {3419my$co=shift;3420# too bad we can't use @people = @_ || ('author', 'committer')3421my@people=@_;3422@people= ('author','committer')unless@people;3423foreachmy$who(@people) {3424my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});3425print"<tr><td>$who</td><td>". esc_html($co->{$who}) ."</td>".3426"<td rowspan=\"2\">".3427 git_get_avatar($co->{"${who}_email"}, -size =>'double') .3428"</td></tr>\n".3429"<tr>".3430"<td></td><td>$wd{'rfc2822'}";3431 print_local_time(%wd);3432print"</td>".3433"</tr>\n";3434}3435}34363437sub git_print_page_path {3438my$name=shift;3439my$type=shift;3440my$hb=shift;344134423443print"<div class=\"page_path\">";3444print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3445-title =>'tree root'}, to_utf8("[$project]"));3446print" / ";3447if(defined$name) {3448my@dirname=split'/',$name;3449my$basename=pop@dirname;3450my$fullname='';34513452foreachmy$dir(@dirname) {3453$fullname.= ($fullname?'/':'') .$dir;3454print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3455 hash_base=>$hb),3456-title =>$fullname}, esc_path($dir));3457print" / ";3458}3459if(defined$type&&$typeeq'blob') {3460print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3461 hash_base=>$hb),3462-title =>$name}, esc_path($basename));3463}elsif(defined$type&&$typeeq'tree') {3464print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3465 hash_base=>$hb),3466-title =>$name}, esc_path($basename));3467print" / ";3468}else{3469print esc_path($basename);3470}3471}3472print"<br/></div>\n";3473}34743475sub git_print_log {3476my$log=shift;3477my%opts=@_;34783479if($opts{'-remove_title'}) {3480# remove title, i.e. first line of log3481shift@$log;3482}3483# remove leading empty lines3484while(defined$log->[0] &&$log->[0]eq"") {3485shift@$log;3486}34873488# print log3489my$signoff=0;3490my$empty=0;3491foreachmy$line(@$log) {3492if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3493$signoff=1;3494$empty=0;3495if(!$opts{'-remove_signoff'}) {3496print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3497next;3498}else{3499# remove signoff lines3500next;3501}3502}else{3503$signoff=0;3504}35053506# print only one empty line3507# do not print empty line after signoff3508if($lineeq"") {3509next if($empty||$signoff);3510$empty=1;3511}else{3512$empty=0;3513}35143515print format_log_line_html($line) ."<br/>\n";3516}35173518if($opts{'-final_empty_line'}) {3519# end with single empty line3520print"<br/>\n"unless$empty;3521}3522}35233524# return link target (what link points to)3525sub git_get_link_target {3526my$hash=shift;3527my$link_target;35283529# read link3530open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3531orreturn;3532{3533local$/=undef;3534$link_target= <$fd>;3535}3536close$fd3537orreturn;35383539return$link_target;3540}35413542# given link target, and the directory (basedir) the link is in,3543# return target of link relative to top directory (top tree);3544# return undef if it is not possible (including absolute links).3545sub normalize_link_target {3546my($link_target,$basedir) =@_;35473548# absolute symlinks (beginning with '/') cannot be normalized3549return if(substr($link_target,0,1)eq'/');35503551# normalize link target to path from top (root) tree (dir)3552my$path;3553if($basedir) {3554$path=$basedir.'/'.$link_target;3555}else{3556# we are in top (root) tree (dir)3557$path=$link_target;3558}35593560# remove //, /./, and /../3561my@path_parts;3562foreachmy$part(split('/',$path)) {3563# discard '.' and ''3564next if(!$part||$parteq'.');3565# handle '..'3566if($parteq'..') {3567if(@path_parts) {3568pop@path_parts;3569}else{3570# link leads outside repository (outside top dir)3571return;3572}3573}else{3574push@path_parts,$part;3575}3576}3577$path=join('/',@path_parts);35783579return$path;3580}35813582# print tree entry (row of git_tree), but without encompassing <tr> element3583sub git_print_tree_entry {3584my($t,$basedir,$hash_base,$have_blame) =@_;35853586my%base_key= ();3587$base_key{'hash_base'} =$hash_baseifdefined$hash_base;35883589# The format of a table row is: mode list link. Where mode is3590# the mode of the entry, list is the name of the entry, an href,3591# and link is the action links of the entry.35923593print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3594if(exists$t->{'size'}) {3595print"<td class=\"size\">$t->{'size'}</td>\n";3596}3597if($t->{'type'}eq"blob") {3598print"<td class=\"list\">".3599$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3600 file_name=>"$basedir$t->{'name'}",%base_key),3601-class=>"list"}, esc_path($t->{'name'}));3602if(S_ISLNK(oct$t->{'mode'})) {3603my$link_target= git_get_link_target($t->{'hash'});3604if($link_target) {3605my$norm_target= normalize_link_target($link_target,$basedir);3606if(defined$norm_target) {3607print" -> ".3608$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3609 file_name=>$norm_target),3610-title =>$norm_target}, esc_path($link_target));3611}else{3612print" -> ". esc_path($link_target);3613}3614}3615}3616print"</td>\n";3617print"<td class=\"link\">";3618print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3619 file_name=>"$basedir$t->{'name'}",%base_key)},3620"blob");3621if($have_blame) {3622print" | ".3623$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3624 file_name=>"$basedir$t->{'name'}",%base_key)},3625"blame");3626}3627if(defined$hash_base) {3628print" | ".3629$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3630 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3631"history");3632}3633print" | ".3634$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3635 file_name=>"$basedir$t->{'name'}")},3636"raw");3637print"</td>\n";36383639}elsif($t->{'type'}eq"tree") {3640print"<td class=\"list\">";3641print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3642 file_name=>"$basedir$t->{'name'}",3643%base_key)},3644 esc_path($t->{'name'}));3645print"</td>\n";3646print"<td class=\"link\">";3647print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3648 file_name=>"$basedir$t->{'name'}",3649%base_key)},3650"tree");3651if(defined$hash_base) {3652print" | ".3653$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3654 file_name=>"$basedir$t->{'name'}")},3655"history");3656}3657print"</td>\n";3658}else{3659# unknown object: we can only present history for it3660# (this includes 'commit' object, i.e. submodule support)3661print"<td class=\"list\">".3662 esc_path($t->{'name'}) .3663"</td>\n";3664print"<td class=\"link\">";3665if(defined$hash_base) {3666print$cgi->a({-href => href(action=>"history",3667 hash_base=>$hash_base,3668 file_name=>"$basedir$t->{'name'}")},3669"history");3670}3671print"</td>\n";3672}3673}36743675## ......................................................................3676## functions printing large fragments of HTML36773678# get pre-image filenames for merge (combined) diff3679sub fill_from_file_info {3680my($diff,@parents) =@_;36813682$diff->{'from_file'} = [ ];3683$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3684for(my$i=0;$i<$diff->{'nparents'};$i++) {3685if($diff->{'status'}[$i]eq'R'||3686$diff->{'status'}[$i]eq'C') {3687$diff->{'from_file'}[$i] =3688 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3689}3690}36913692return$diff;3693}36943695# is current raw difftree line of file deletion3696sub is_deleted {3697my$diffinfo=shift;36983699return$diffinfo->{'to_id'}eq('0' x 40);3700}37013702# does patch correspond to [previous] difftree raw line3703# $diffinfo - hashref of parsed raw diff format3704# $patchinfo - hashref of parsed patch diff format3705# (the same keys as in $diffinfo)3706sub is_patch_split {3707my($diffinfo,$patchinfo) =@_;37083709returndefined$diffinfo&&defined$patchinfo3710&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3711}371237133714sub git_difftree_body {3715my($difftree,$hash,@parents) =@_;3716my($parent) =$parents[0];3717my$have_blame= gitweb_check_feature('blame');3718print"<div class=\"list_head\">\n";3719if($#{$difftree} >10) {3720print(($#{$difftree} +1) ." files changed:\n");3721}3722print"</div>\n";37233724print"<table class=\"".3725(@parents>1?"combined ":"") .3726"diff_tree\">\n";37273728# header only for combined diff in 'commitdiff' view3729my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3730if($has_header) {3731# table header3732print"<thead><tr>\n".3733"<th></th><th></th>\n";# filename, patchN link3734for(my$i=0;$i<@parents;$i++) {3735my$par=$parents[$i];3736print"<th>".3737$cgi->a({-href => href(action=>"commitdiff",3738 hash=>$hash, hash_parent=>$par),3739-title =>'commitdiff to parent number '.3740($i+1) .': '.substr($par,0,7)},3741$i+1) .3742" </th>\n";3743}3744print"</tr></thead>\n<tbody>\n";3745}37463747my$alternate=1;3748my$patchno=0;3749foreachmy$line(@{$difftree}) {3750my$diff= parsed_difftree_line($line);37513752if($alternate) {3753print"<tr class=\"dark\">\n";3754}else{3755print"<tr class=\"light\">\n";3756}3757$alternate^=1;37583759if(exists$diff->{'nparents'}) {# combined diff37603761 fill_from_file_info($diff,@parents)3762unlessexists$diff->{'from_file'};37633764if(!is_deleted($diff)) {3765# file exists in the result (child) commit3766print"<td>".3767$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3768 file_name=>$diff->{'to_file'},3769 hash_base=>$hash),3770-class=>"list"}, esc_path($diff->{'to_file'})) .3771"</td>\n";3772}else{3773print"<td>".3774 esc_path($diff->{'to_file'}) .3775"</td>\n";3776}37773778if($actioneq'commitdiff') {3779# link to patch3780$patchno++;3781print"<td class=\"link\">".3782$cgi->a({-href =>"#patch$patchno"},"patch") .3783" | ".3784"</td>\n";3785}37863787my$has_history=0;3788my$not_deleted=0;3789for(my$i=0;$i<$diff->{'nparents'};$i++) {3790my$hash_parent=$parents[$i];3791my$from_hash=$diff->{'from_id'}[$i];3792my$from_path=$diff->{'from_file'}[$i];3793my$status=$diff->{'status'}[$i];37943795$has_history||= ($statusne'A');3796$not_deleted||= ($statusne'D');37973798if($statuseq'A') {3799print"<td class=\"link\"align=\"right\"> | </td>\n";3800}elsif($statuseq'D') {3801print"<td class=\"link\">".3802$cgi->a({-href => href(action=>"blob",3803 hash_base=>$hash,3804 hash=>$from_hash,3805 file_name=>$from_path)},3806"blob". ($i+1)) .3807" | </td>\n";3808}else{3809if($diff->{'to_id'}eq$from_hash) {3810print"<td class=\"link nochange\">";3811}else{3812print"<td class=\"link\">";3813}3814print$cgi->a({-href => href(action=>"blobdiff",3815 hash=>$diff->{'to_id'},3816 hash_parent=>$from_hash,3817 hash_base=>$hash,3818 hash_parent_base=>$hash_parent,3819 file_name=>$diff->{'to_file'},3820 file_parent=>$from_path)},3821"diff". ($i+1)) .3822" | </td>\n";3823}3824}38253826print"<td class=\"link\">";3827if($not_deleted) {3828print$cgi->a({-href => href(action=>"blob",3829 hash=>$diff->{'to_id'},3830 file_name=>$diff->{'to_file'},3831 hash_base=>$hash)},3832"blob");3833print" | "if($has_history);3834}3835if($has_history) {3836print$cgi->a({-href => href(action=>"history",3837 file_name=>$diff->{'to_file'},3838 hash_base=>$hash)},3839"history");3840}3841print"</td>\n";38423843print"</tr>\n";3844next;# instead of 'else' clause, to avoid extra indent3845}3846# else ordinary diff38473848my($to_mode_oct,$to_mode_str,$to_file_type);3849my($from_mode_oct,$from_mode_str,$from_file_type);3850if($diff->{'to_mode'}ne('0' x 6)) {3851$to_mode_oct=oct$diff->{'to_mode'};3852if(S_ISREG($to_mode_oct)) {# only for regular file3853$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits3854}3855$to_file_type= file_type($diff->{'to_mode'});3856}3857if($diff->{'from_mode'}ne('0' x 6)) {3858$from_mode_oct=oct$diff->{'from_mode'};3859if(S_ISREG($to_mode_oct)) {# only for regular file3860$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits3861}3862$from_file_type= file_type($diff->{'from_mode'});3863}38643865if($diff->{'status'}eq"A") {# created3866my$mode_chng="<span class=\"file_status new\">[new$to_file_type";3867$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;3868$mode_chng.="]</span>";3869print"<td>";3870print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3871 hash_base=>$hash, file_name=>$diff->{'file'}),3872-class=>"list"}, esc_path($diff->{'file'}));3873print"</td>\n";3874print"<td>$mode_chng</td>\n";3875print"<td class=\"link\">";3876if($actioneq'commitdiff') {3877# link to patch3878$patchno++;3879print$cgi->a({-href =>"#patch$patchno"},"patch");3880print" | ";3881}3882print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3883 hash_base=>$hash, file_name=>$diff->{'file'})},3884"blob");3885print"</td>\n";38863887}elsif($diff->{'status'}eq"D") {# deleted3888my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";3889print"<td>";3890print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3891 hash_base=>$parent, file_name=>$diff->{'file'}),3892-class=>"list"}, esc_path($diff->{'file'}));3893print"</td>\n";3894print"<td>$mode_chng</td>\n";3895print"<td class=\"link\">";3896if($actioneq'commitdiff') {3897# link to patch3898$patchno++;3899print$cgi->a({-href =>"#patch$patchno"},"patch");3900print" | ";3901}3902print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3903 hash_base=>$parent, file_name=>$diff->{'file'})},3904"blob") ." | ";3905if($have_blame) {3906print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,3907 file_name=>$diff->{'file'})},3908"blame") ." | ";3909}3910print$cgi->a({-href => href(action=>"history", hash_base=>$parent,3911 file_name=>$diff->{'file'})},3912"history");3913print"</td>\n";39143915}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed3916my$mode_chnge="";3917if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3918$mode_chnge="<span class=\"file_status mode_chnge\">[changed";3919if($from_file_typene$to_file_type) {3920$mode_chnge.=" from$from_file_typeto$to_file_type";3921}3922if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {3923if($from_mode_str&&$to_mode_str) {3924$mode_chnge.=" mode:$from_mode_str->$to_mode_str";3925}elsif($to_mode_str) {3926$mode_chnge.=" mode:$to_mode_str";3927}3928}3929$mode_chnge.="]</span>\n";3930}3931print"<td>";3932print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3933 hash_base=>$hash, file_name=>$diff->{'file'}),3934-class=>"list"}, esc_path($diff->{'file'}));3935print"</td>\n";3936print"<td>$mode_chnge</td>\n";3937print"<td class=\"link\">";3938if($actioneq'commitdiff') {3939# link to patch3940$patchno++;3941print$cgi->a({-href =>"#patch$patchno"},"patch") .3942" | ";3943}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3944# "commit" view and modified file (not onlu mode changed)3945print$cgi->a({-href => href(action=>"blobdiff",3946 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3947 hash_base=>$hash, hash_parent_base=>$parent,3948 file_name=>$diff->{'file'})},3949"diff") .3950" | ";3951}3952print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3953 hash_base=>$hash, file_name=>$diff->{'file'})},3954"blob") ." | ";3955if($have_blame) {3956print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3957 file_name=>$diff->{'file'})},3958"blame") ." | ";3959}3960print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3961 file_name=>$diff->{'file'})},3962"history");3963print"</td>\n";39643965}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied3966my%status_name= ('R'=>'moved','C'=>'copied');3967my$nstatus=$status_name{$diff->{'status'}};3968my$mode_chng="";3969if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3970# mode also for directories, so we cannot use $to_mode_str3971$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);3972}3973print"<td>".3974$cgi->a({-href => href(action=>"blob", hash_base=>$hash,3975 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),3976-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".3977"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".3978$cgi->a({-href => href(action=>"blob", hash_base=>$parent,3979 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),3980-class=>"list"}, esc_path($diff->{'from_file'})) .3981" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".3982"<td class=\"link\">";3983if($actioneq'commitdiff') {3984# link to patch3985$patchno++;3986print$cgi->a({-href =>"#patch$patchno"},"patch") .3987" | ";3988}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3989# "commit" view and modified file (not only pure rename or copy)3990print$cgi->a({-href => href(action=>"blobdiff",3991 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3992 hash_base=>$hash, hash_parent_base=>$parent,3993 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},3994"diff") .3995" | ";3996}3997print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3998 hash_base=>$parent, file_name=>$diff->{'to_file'})},3999"blob") ." | ";4000if($have_blame) {4001print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4002 file_name=>$diff->{'to_file'})},4003"blame") ." | ";4004}4005print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4006 file_name=>$diff->{'to_file'})},4007"history");4008print"</td>\n";40094010}# we should not encounter Unmerged (U) or Unknown (X) status4011print"</tr>\n";4012}4013print"</tbody>"if$has_header;4014print"</table>\n";4015}40164017sub git_patchset_body {4018my($fd,$difftree,$hash,@hash_parents) =@_;4019my($hash_parent) =$hash_parents[0];40204021my$is_combined= (@hash_parents>1);4022my$patch_idx=0;4023my$patch_number=0;4024my$patch_line;4025my$diffinfo;4026my$to_name;4027my(%from,%to);40284029print"<div class=\"patchset\">\n";40304031# skip to first patch4032while($patch_line= <$fd>) {4033chomp$patch_line;40344035last if($patch_line=~m/^diff /);4036}40374038 PATCH:4039while($patch_line) {40404041# parse "git diff" header line4042if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {4043# $1 is from_name, which we do not use4044$to_name= unquote($2);4045$to_name=~s!^b/!!;4046}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {4047# $1 is 'cc' or 'combined', which we do not use4048$to_name= unquote($2);4049}else{4050$to_name=undef;4051}40524053# check if current patch belong to current raw line4054# and parse raw git-diff line if needed4055if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {4056# this is continuation of a split patch4057print"<div class=\"patch cont\">\n";4058}else{4059# advance raw git-diff output if needed4060$patch_idx++ifdefined$diffinfo;40614062# read and prepare patch information4063$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);40644065# compact combined diff output can have some patches skipped4066# find which patch (using pathname of result) we are at now;4067if($is_combined) {4068while($to_namene$diffinfo->{'to_file'}) {4069print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4070 format_diff_cc_simplified($diffinfo,@hash_parents) .4071"</div>\n";# class="patch"40724073$patch_idx++;4074$patch_number++;40754076last if$patch_idx>$#$difftree;4077$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);4078}4079}40804081# modifies %from, %to hashes4082 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);40834084# this is first patch for raw difftree line with $patch_idx index4085# we index @$difftree array from 0, but number patches from 14086print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";4087}40884089# git diff header4090#assert($patch_line =~ m/^diff /) if DEBUG;4091#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed4092$patch_number++;4093# print "git diff" header4094print format_git_diff_header_line($patch_line,$diffinfo,4095 \%from, \%to);40964097# print extended diff header4098print"<div class=\"diff extended_header\">\n";4099 EXTENDED_HEADER:4100while($patch_line= <$fd>) {4101chomp$patch_line;41024103last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);41044105print format_extended_diff_header_line($patch_line,$diffinfo,4106 \%from, \%to);4107}4108print"</div>\n";# class="diff extended_header"41094110# from-file/to-file diff header4111if(!$patch_line) {4112print"</div>\n";# class="patch"4113last PATCH;4114}4115next PATCH if($patch_line=~m/^diff /);4116#assert($patch_line =~ m/^---/) if DEBUG;41174118my$last_patch_line=$patch_line;4119$patch_line= <$fd>;4120chomp$patch_line;4121#assert($patch_line =~ m/^\+\+\+/) if DEBUG;41224123print format_diff_from_to_header($last_patch_line,$patch_line,4124$diffinfo, \%from, \%to,4125@hash_parents);41264127# the patch itself4128 LINE:4129while($patch_line= <$fd>) {4130chomp$patch_line;41314132next PATCH if($patch_line=~m/^diff /);41334134print format_diff_line($patch_line, \%from, \%to);4135}41364137}continue{4138print"</div>\n";# class="patch"4139}41404141# for compact combined (--cc) format, with chunk and patch simpliciaction4142# patchset might be empty, but there might be unprocessed raw lines4143for(++$patch_idxif$patch_number>0;4144$patch_idx<@$difftree;4145++$patch_idx) {4146# read and prepare patch information4147$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);41484149# generate anchor for "patch" links in difftree / whatchanged part4150print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4151 format_diff_cc_simplified($diffinfo,@hash_parents) .4152"</div>\n";# class="patch"41534154$patch_number++;4155}41564157if($patch_number==0) {4158if(@hash_parents>1) {4159print"<div class=\"diff nodifferences\">Trivial merge</div>\n";4160}else{4161print"<div class=\"diff nodifferences\">No differences found</div>\n";4162}4163}41644165print"</div>\n";# class="patchset"4166}41674168# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41694170# fills project list info (age, description, owner, forks) for each4171# project in the list, removing invalid projects from returned list4172# NOTE: modifies $projlist, but does not remove entries from it4173sub fill_project_list_info {4174my($projlist,$check_forks) =@_;4175my@projects;41764177my$show_ctags= gitweb_check_feature('ctags');4178 PROJECT:4179foreachmy$pr(@$projlist) {4180my(@activity) = git_get_last_activity($pr->{'path'});4181unless(@activity) {4182next PROJECT;4183}4184($pr->{'age'},$pr->{'age_string'}) =@activity;4185if(!defined$pr->{'descr'}) {4186my$descr= git_get_project_description($pr->{'path'}) ||"";4187$descr= to_utf8($descr);4188$pr->{'descr_long'} =$descr;4189$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4190}4191if(!defined$pr->{'owner'}) {4192$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4193}4194if($check_forks) {4195my$pname=$pr->{'path'};4196if(($pname=~s/\.git$//) &&4197($pname!~/\/$/) &&4198(-d "$projectroot/$pname")) {4199$pr->{'forks'} ="-d$projectroot/$pname";4200}else{4201$pr->{'forks'} =0;4202}4203}4204$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4205push@projects,$pr;4206}42074208return@projects;4209}42104211# print 'sort by' <th> element, generating 'sort by $name' replay link4212# if that order is not selected4213sub print_sort_th {4214my($name,$order,$header) =@_;4215$header||=ucfirst($name);42164217if($ordereq$name) {4218print"<th>$header</th>\n";4219}else{4220print"<th>".4221$cgi->a({-href => href(-replay=>1, order=>$name),4222-class=>"header"},$header) .4223"</th>\n";4224}4225}42264227sub git_project_list_body {4228# actually uses global variable $project4229my($projlist,$order,$from,$to,$extra,$no_header) =@_;42304231my$check_forks= gitweb_check_feature('forks');4232my@projects= fill_project_list_info($projlist,$check_forks);42334234$order||=$default_projects_order;4235$from=0unlessdefined$from;4236$to=$#projectsif(!defined$to||$#projects<$to);42374238my%order_info= (4239 project => { key =>'path', type =>'str'},4240 descr => { key =>'descr_long', type =>'str'},4241 owner => { key =>'owner', type =>'str'},4242 age => { key =>'age', type =>'num'}4243);4244my$oi=$order_info{$order};4245if($oi->{'type'}eq'str') {4246@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4247}else{4248@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4249}42504251my$show_ctags= gitweb_check_feature('ctags');4252if($show_ctags) {4253my%ctags;4254foreachmy$p(@projects) {4255foreachmy$ct(keys%{$p->{'ctags'}}) {4256$ctags{$ct} +=$p->{'ctags'}->{$ct};4257}4258}4259my$cloud= git_populate_project_tagcloud(\%ctags);4260print git_show_project_tagcloud($cloud,64);4261}42624263print"<table class=\"project_list\">\n";4264unless($no_header) {4265print"<tr>\n";4266if($check_forks) {4267print"<th></th>\n";4268}4269 print_sort_th('project',$order,'Project');4270 print_sort_th('descr',$order,'Description');4271 print_sort_th('owner',$order,'Owner');4272 print_sort_th('age',$order,'Last Change');4273print"<th></th>\n".# for links4274"</tr>\n";4275}4276my$alternate=1;4277my$tagfilter=$cgi->param('by_tag');4278for(my$i=$from;$i<=$to;$i++) {4279my$pr=$projects[$i];42804281next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4282next if$searchtextand not$pr->{'path'} =~/$searchtext/4283and not$pr->{'descr_long'} =~/$searchtext/;4284# Weed out forks or non-matching entries of search4285if($check_forks) {4286my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4287$forkbase="^$forkbase"if$forkbase;4288next ifnot$searchtextand not$tagfilterand$show_ctags4289and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4290}42914292if($alternate) {4293print"<tr class=\"dark\">\n";4294}else{4295print"<tr class=\"light\">\n";4296}4297$alternate^=1;4298if($check_forks) {4299print"<td>";4300if($pr->{'forks'}) {4301print"<!--$pr->{'forks'} -->\n";4302print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4303}4304print"</td>\n";4305}4306print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4307-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4308"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4309-class=>"list", -title =>$pr->{'descr_long'}},4310 esc_html($pr->{'descr'})) ."</td>\n".4311"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4312print"<td class=\"". age_class($pr->{'age'}) ."\">".4313(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4314"<td class=\"link\">".4315$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4316$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4317$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4318$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4319($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4320"</td>\n".4321"</tr>\n";4322}4323if(defined$extra) {4324print"<tr>\n";4325if($check_forks) {4326print"<td></td>\n";4327}4328print"<td colspan=\"5\">$extra</td>\n".4329"</tr>\n";4330}4331print"</table>\n";4332}43334334sub git_shortlog_body {4335# uses global variable $project4336my($commitlist,$from,$to,$refs,$extra) =@_;43374338$from=0unlessdefined$from;4339$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);43404341print"<table class=\"shortlog\">\n";4342my$alternate=1;4343for(my$i=$from;$i<=$to;$i++) {4344my%co= %{$commitlist->[$i]};4345my$commit=$co{'id'};4346my$ref= format_ref_marker($refs,$commit);4347if($alternate) {4348print"<tr class=\"dark\">\n";4349}else{4350print"<tr class=\"light\">\n";4351}4352$alternate^=1;4353# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4354print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4355 format_author_html('td', \%co,10) ."<td>";4356print format_subject_html($co{'title'},$co{'title_short'},4357 href(action=>"commit", hash=>$commit),$ref);4358print"</td>\n".4359"<td class=\"link\">".4360$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4361$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4362$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4363my$snapshot_links= format_snapshot_links($commit);4364if(defined$snapshot_links) {4365print" | ".$snapshot_links;4366}4367print"</td>\n".4368"</tr>\n";4369}4370if(defined$extra) {4371print"<tr>\n".4372"<td colspan=\"4\">$extra</td>\n".4373"</tr>\n";4374}4375print"</table>\n";4376}43774378sub git_history_body {4379# Warning: assumes constant type (blob or tree) during history4380my($commitlist,$from,$to,$refs,$hash_base,$ftype,$extra) =@_;43814382$from=0unlessdefined$from;4383$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});43844385print"<table class=\"history\">\n";4386my$alternate=1;4387for(my$i=$from;$i<=$to;$i++) {4388my%co= %{$commitlist->[$i]};4389if(!%co) {4390next;4391}4392my$commit=$co{'id'};43934394my$ref= format_ref_marker($refs,$commit);43954396if($alternate) {4397print"<tr class=\"dark\">\n";4398}else{4399print"<tr class=\"light\">\n";4400}4401$alternate^=1;4402print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4403# shortlog: format_author_html('td', \%co, 10)4404 format_author_html('td', \%co,15,3) ."<td>";4405# originally git_history used chop_str($co{'title'}, 50)4406print format_subject_html($co{'title'},$co{'title_short'},4407 href(action=>"commit", hash=>$commit),$ref);4408print"</td>\n".4409"<td class=\"link\">".4410$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4411$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");44124413if($ftypeeq'blob') {4414my$blob_current= git_get_hash_by_path($hash_base,$file_name);4415my$blob_parent= git_get_hash_by_path($commit,$file_name);4416if(defined$blob_current&&defined$blob_parent&&4417$blob_currentne$blob_parent) {4418print" | ".4419$cgi->a({-href => href(action=>"blobdiff",4420 hash=>$blob_current, hash_parent=>$blob_parent,4421 hash_base=>$hash_base, hash_parent_base=>$commit,4422 file_name=>$file_name)},4423"diff to current");4424}4425}4426print"</td>\n".4427"</tr>\n";4428}4429if(defined$extra) {4430print"<tr>\n".4431"<td colspan=\"4\">$extra</td>\n".4432"</tr>\n";4433}4434print"</table>\n";4435}44364437sub git_tags_body {4438# uses global variable $project4439my($taglist,$from,$to,$extra) =@_;4440$from=0unlessdefined$from;4441$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);44424443print"<table class=\"tags\">\n";4444my$alternate=1;4445for(my$i=$from;$i<=$to;$i++) {4446my$entry=$taglist->[$i];4447my%tag=%$entry;4448my$comment=$tag{'subject'};4449my$comment_short;4450if(defined$comment) {4451$comment_short= chop_str($comment,30,5);4452}4453if($alternate) {4454print"<tr class=\"dark\">\n";4455}else{4456print"<tr class=\"light\">\n";4457}4458$alternate^=1;4459if(defined$tag{'age'}) {4460print"<td><i>$tag{'age'}</i></td>\n";4461}else{4462print"<td></td>\n";4463}4464print"<td>".4465$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4466-class=>"list name"}, esc_html($tag{'name'})) .4467"</td>\n".4468"<td>";4469if(defined$comment) {4470print format_subject_html($comment,$comment_short,4471 href(action=>"tag", hash=>$tag{'id'}));4472}4473print"</td>\n".4474"<td class=\"selflink\">";4475if($tag{'type'}eq"tag") {4476print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4477}else{4478print" ";4479}4480print"</td>\n".4481"<td class=\"link\">"." | ".4482$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4483if($tag{'reftype'}eq"commit") {4484print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4485" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4486}elsif($tag{'reftype'}eq"blob") {4487print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4488}4489print"</td>\n".4490"</tr>";4491}4492if(defined$extra) {4493print"<tr>\n".4494"<td colspan=\"5\">$extra</td>\n".4495"</tr>\n";4496}4497print"</table>\n";4498}44994500sub git_heads_body {4501# uses global variable $project4502my($headlist,$head,$from,$to,$extra) =@_;4503$from=0unlessdefined$from;4504$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);45054506print"<table class=\"heads\">\n";4507my$alternate=1;4508for(my$i=$from;$i<=$to;$i++) {4509my$entry=$headlist->[$i];4510my%ref=%$entry;4511my$curr=$ref{'id'}eq$head;4512if($alternate) {4513print"<tr class=\"dark\">\n";4514}else{4515print"<tr class=\"light\">\n";4516}4517$alternate^=1;4518print"<td><i>$ref{'age'}</i></td>\n".4519($curr?"<td class=\"current_head\">":"<td>") .4520$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4521-class=>"list name"},esc_html($ref{'name'})) .4522"</td>\n".4523"<td class=\"link\">".4524$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4525$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4526$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4527"</td>\n".4528"</tr>";4529}4530if(defined$extra) {4531print"<tr>\n".4532"<td colspan=\"3\">$extra</td>\n".4533"</tr>\n";4534}4535print"</table>\n";4536}45374538sub git_search_grep_body {4539my($commitlist,$from,$to,$extra) =@_;4540$from=0unlessdefined$from;4541$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);45424543print"<table class=\"commit_search\">\n";4544my$alternate=1;4545for(my$i=$from;$i<=$to;$i++) {4546my%co= %{$commitlist->[$i]};4547if(!%co) {4548next;4549}4550my$commit=$co{'id'};4551if($alternate) {4552print"<tr class=\"dark\">\n";4553}else{4554print"<tr class=\"light\">\n";4555}4556$alternate^=1;4557print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4558 format_author_html('td', \%co,15,5) .4559"<td>".4560$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4561-class=>"list subject"},4562 chop_and_escape_str($co{'title'},50) ."<br/>");4563my$comment=$co{'comment'};4564foreachmy$line(@$comment) {4565if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4566my($lead,$match,$trail) = ($1,$2,$3);4567$match= chop_str($match,70,5,'center');4568my$contextlen=int((80-length($match))/2);4569$contextlen=30if($contextlen>30);4570$lead= chop_str($lead,$contextlen,10,'left');4571$trail= chop_str($trail,$contextlen,10,'right');45724573$lead= esc_html($lead);4574$match= esc_html($match);4575$trail= esc_html($trail);45764577print"$lead<span class=\"match\">$match</span>$trail<br />";4578}4579}4580print"</td>\n".4581"<td class=\"link\">".4582$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4583" | ".4584$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4585" | ".4586$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4587print"</td>\n".4588"</tr>\n";4589}4590if(defined$extra) {4591print"<tr>\n".4592"<td colspan=\"3\">$extra</td>\n".4593"</tr>\n";4594}4595print"</table>\n";4596}45974598## ======================================================================4599## ======================================================================4600## actions46014602sub git_project_list {4603my$order=$input_params{'order'};4604if(defined$order&&$order!~m/none|project|descr|owner|age/) {4605 die_error(400,"Unknown order parameter");4606}46074608my@list= git_get_projects_list();4609if(!@list) {4610 die_error(404,"No projects found");4611}46124613 git_header_html();4614if(-f $home_text) {4615print"<div class=\"index_include\">\n";4616 insert_file($home_text);4617print"</div>\n";4618}4619print$cgi->startform(-method=>"get") .4620"<p class=\"projsearch\">Search:\n".4621$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4622"</p>".4623$cgi->end_form() ."\n";4624 git_project_list_body(\@list,$order);4625 git_footer_html();4626}46274628sub git_forks {4629my$order=$input_params{'order'};4630if(defined$order&&$order!~m/none|project|descr|owner|age/) {4631 die_error(400,"Unknown order parameter");4632}46334634my@list= git_get_projects_list($project);4635if(!@list) {4636 die_error(404,"No forks found");4637}46384639 git_header_html();4640 git_print_page_nav('','');4641 git_print_header_div('summary',"$projectforks");4642 git_project_list_body(\@list,$order);4643 git_footer_html();4644}46454646sub git_project_index {4647my@projects= git_get_projects_list($project);46484649print$cgi->header(4650-type =>'text/plain',4651-charset =>'utf-8',4652-content_disposition =>'inline; filename="index.aux"');46534654foreachmy$pr(@projects) {4655if(!exists$pr->{'owner'}) {4656$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4657}46584659my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4660# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4661$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4662$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4663$path=~s/ /\+/g;4664$owner=~s/ /\+/g;46654666print"$path$owner\n";4667}4668}46694670sub git_summary {4671my$descr= git_get_project_description($project) ||"none";4672my%co= parse_commit("HEAD");4673my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4674my$head=$co{'id'};46754676my$owner= git_get_project_owner($project);46774678my$refs= git_get_references();4679# These get_*_list functions return one more to allow us to see if4680# there are more ...4681my@taglist= git_get_tags_list(16);4682my@headlist= git_get_heads_list(16);4683my@forklist;4684my$check_forks= gitweb_check_feature('forks');46854686if($check_forks) {4687@forklist= git_get_projects_list($project);4688}46894690 git_header_html();4691 git_print_page_nav('summary','',$head);46924693print"<div class=\"title\"> </div>\n";4694print"<table class=\"projects_list\">\n".4695"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4696"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4697if(defined$cd{'rfc2822'}) {4698print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4699}47004701# use per project git URL list in $projectroot/$project/cloneurl4702# or make project git URL from git base URL and project name4703my$url_tag="URL";4704my@url_list= git_get_project_url_list($project);4705@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4706foreachmy$git_url(@url_list) {4707next unless$git_url;4708print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4709$url_tag="";4710}47114712# Tag cloud4713my$show_ctags= gitweb_check_feature('ctags');4714if($show_ctags) {4715my$ctags= git_get_project_ctags($project);4716my$cloud= git_populate_project_tagcloud($ctags);4717print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4718print"</td>\n<td>"unless%$ctags;4719print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4720print"</td>\n<td>"if%$ctags;4721print git_show_project_tagcloud($cloud,48);4722print"</td></tr>";4723}47244725print"</table>\n";47264727# If XSS prevention is on, we don't include README.html.4728# TODO: Allow a readme in some safe format.4729if(!$prevent_xss&& -s "$projectroot/$project/README.html") {4730print"<div class=\"title\">readme</div>\n".4731"<div class=\"readme\">\n";4732 insert_file("$projectroot/$project/README.html");4733print"\n</div>\n";# class="readme"4734}47354736# we need to request one more than 16 (0..15) to check if4737# those 16 are all4738my@commitlist=$head? parse_commits($head,17) : ();4739if(@commitlist) {4740 git_print_header_div('shortlog');4741 git_shortlog_body(\@commitlist,0,15,$refs,4742$#commitlist<=15?undef:4743$cgi->a({-href => href(action=>"shortlog")},"..."));4744}47454746if(@taglist) {4747 git_print_header_div('tags');4748 git_tags_body(\@taglist,0,15,4749$#taglist<=15?undef:4750$cgi->a({-href => href(action=>"tags")},"..."));4751}47524753if(@headlist) {4754 git_print_header_div('heads');4755 git_heads_body(\@headlist,$head,0,15,4756$#headlist<=15?undef:4757$cgi->a({-href => href(action=>"heads")},"..."));4758}47594760if(@forklist) {4761 git_print_header_div('forks');4762 git_project_list_body(\@forklist,'age',0,15,4763$#forklist<=15?undef:4764$cgi->a({-href => href(action=>"forks")},"..."),4765'no_header');4766}47674768 git_footer_html();4769}47704771sub git_tag {4772my$head= git_get_head_hash($project);4773 git_header_html();4774 git_print_page_nav('','',$head,undef,$head);4775my%tag= parse_tag($hash);47764777if(!%tag) {4778 die_error(404,"Unknown tag object");4779}47804781 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4782print"<div class=\"title_text\">\n".4783"<table class=\"object_header\">\n".4784"<tr>\n".4785"<td>object</td>\n".4786"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4787$tag{'object'}) ."</td>\n".4788"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4789$tag{'type'}) ."</td>\n".4790"</tr>\n";4791if(defined($tag{'author'})) {4792 git_print_authorship_rows(\%tag,'author');4793}4794print"</table>\n\n".4795"</div>\n";4796print"<div class=\"page_body\">";4797my$comment=$tag{'comment'};4798foreachmy$line(@$comment) {4799chomp$line;4800print esc_html($line, -nbsp=>1) ."<br/>\n";4801}4802print"</div>\n";4803 git_footer_html();4804}48054806sub git_blame {4807# permissions4808 gitweb_check_feature('blame')4809or die_error(403,"Blame view not allowed");48104811# error checking4812 die_error(400,"No file name given")unless$file_name;4813$hash_base||= git_get_head_hash($project);4814 die_error(404,"Couldn't find base commit")unless$hash_base;4815my%co= parse_commit($hash_base)4816or die_error(404,"Commit not found");4817my$ftype="blob";4818if(!defined$hash) {4819$hash= git_get_hash_by_path($hash_base,$file_name,"blob")4820or die_error(404,"Error looking up file");4821}else{4822$ftype= git_get_type($hash);4823if($ftype!~"blob") {4824 die_error(400,"Object is not a blob");4825}4826}48274828# run git-blame --porcelain4829open my$fd,"-|", git_cmd(),"blame",'-p',4830$hash_base,'--',$file_name4831or die_error(500,"Open git-blame failed");48324833# page header4834 git_header_html();4835my$formats_nav=4836$cgi->a({-href => href(action=>"blob", -replay=>1)},4837"blob") .4838" | ".4839$cgi->a({-href => href(action=>"history", -replay=>1)},4840"history") .4841" | ".4842$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},4843"HEAD");4844 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4845 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4846 git_print_page_path($file_name,$ftype,$hash_base);48474848# page body4849my@rev_color=qw(light dark);4850my$num_colors=scalar(@rev_color);4851my$current_color=0;4852my%metainfo= ();48534854print<<HTML;4855<div class="page_body">4856<table class="blame">4857<tr><th>Commit</th><th>Line</th><th>Data</th></tr>4858HTML4859 LINE:4860while(my$line= <$fd>) {4861chomp$line;4862# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]4863# no <lines in group> for subsequent lines in group of lines4864my($full_rev,$orig_lineno,$lineno,$group_size) =4865($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);4866if(!exists$metainfo{$full_rev}) {4867$metainfo{$full_rev} = {'nprevious'=>0};4868}4869my$meta=$metainfo{$full_rev};4870my$data;4871while($data= <$fd>) {4872chomp$data;4873last if($data=~s/^\t//);# contents of line4874if($data=~/^(\S+)(?: (.*))?$/) {4875$meta->{$1} =$2unlessexists$meta->{$1};4876}4877if($data=~/^previous /) {4878$meta->{'nprevious'}++;4879}4880}4881my$short_rev=substr($full_rev,0,8);4882my$author=$meta->{'author'};4883my%date=4884 parse_date($meta->{'author-time'},$meta->{'author-tz'});4885my$date=$date{'iso-tz'};4886if($group_size) {4887$current_color= ($current_color+1) %$num_colors;4888}4889my$tr_class=$rev_color[$current_color];4890$tr_class.=' boundary'if(exists$meta->{'boundary'});4891$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);4892$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);4893print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";4894if($group_size) {4895print"<td class=\"sha1\"";4896print" title=\"". esc_html($author) .",$date\"";4897print" rowspan=\"$group_size\""if($group_size>1);4898print">";4899print$cgi->a({-href => href(action=>"commit",4900 hash=>$full_rev,4901 file_name=>$file_name)},4902 esc_html($short_rev));4903if($group_size>=2) {4904my@author_initials= ($author=~/\b([[:upper:]])\B/g);4905if(@author_initials) {4906print"<br />".4907 esc_html(join('',@author_initials));4908# or join('.', ...)4909}4910}4911print"</td>\n";4912}4913# 'previous' <sha1 of parent commit> <filename at commit>4914if(exists$meta->{'previous'} &&4915$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {4916$meta->{'parent'} =$1;4917$meta->{'file_parent'} = unquote($2);4918}4919my$linenr_commit=4920exists($meta->{'parent'}) ?4921$meta->{'parent'} :$full_rev;4922my$linenr_filename=4923exists($meta->{'file_parent'}) ?4924$meta->{'file_parent'} : unquote($meta->{'filename'});4925my$blamed= href(action =>'blame',4926 file_name =>$linenr_filename,4927 hash_base =>$linenr_commit);4928print"<td class=\"linenr\">";4929print$cgi->a({ -href =>"$blamed#l$orig_lineno",4930-class=>"linenr"},4931 esc_html($lineno));4932print"</td>";4933print"<td class=\"pre\">". esc_html($data) ."</td>\n";4934print"</tr>\n";4935}4936print"</table>\n";4937print"</div>";4938close$fd4939or print"Reading blob failed\n";49404941# page footer4942 git_footer_html();4943}49444945sub git_tags {4946my$head= git_get_head_hash($project);4947 git_header_html();4948 git_print_page_nav('','',$head,undef,$head);4949 git_print_header_div('summary',$project);49504951my@tagslist= git_get_tags_list();4952if(@tagslist) {4953 git_tags_body(\@tagslist);4954}4955 git_footer_html();4956}49574958sub git_heads {4959my$head= git_get_head_hash($project);4960 git_header_html();4961 git_print_page_nav('','',$head,undef,$head);4962 git_print_header_div('summary',$project);49634964my@headslist= git_get_heads_list();4965if(@headslist) {4966 git_heads_body(\@headslist,$head);4967}4968 git_footer_html();4969}49704971sub git_blob_plain {4972my$type=shift;4973my$expires;49744975if(!defined$hash) {4976if(defined$file_name) {4977my$base=$hash_base|| git_get_head_hash($project);4978$hash= git_get_hash_by_path($base,$file_name,"blob")4979or die_error(404,"Cannot find file");4980}else{4981 die_error(400,"No file name defined");4982}4983}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4984# blobs defined by non-textual hash id's can be cached4985$expires="+1d";4986}49874988open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4989or die_error(500,"Open git-cat-file blob '$hash' failed");49904991# content-type (can include charset)4992$type= blob_contenttype($fd,$file_name,$type);49934994# "save as" filename, even when no $file_name is given4995my$save_as="$hash";4996if(defined$file_name) {4997$save_as=$file_name;4998}elsif($type=~m/^text\//) {4999$save_as.='.txt';5000}50015002# With XSS prevention on, blobs of all types except a few known safe5003# ones are served with "Content-Disposition: attachment" to make sure5004# they don't run in our security domain. For certain image types,5005# blob view writes an <img> tag referring to blob_plain view, and we5006# want to be sure not to break that by serving the image as an5007# attachment (though Firefox 3 doesn't seem to care).5008my$sandbox=$prevent_xss&&5009$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;50105011print$cgi->header(5012-type =>$type,5013-expires =>$expires,5014-content_disposition =>5015($sandbox?'attachment':'inline')5016.'; filename="'.$save_as.'"');5017local$/=undef;5018binmode STDOUT,':raw';5019print<$fd>;5020binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5021close$fd;5022}50235024sub git_blob {5025my$expires;50265027if(!defined$hash) {5028if(defined$file_name) {5029my$base=$hash_base|| git_get_head_hash($project);5030$hash= git_get_hash_by_path($base,$file_name,"blob")5031or die_error(404,"Cannot find file");5032}else{5033 die_error(400,"No file name defined");5034}5035}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5036# blobs defined by non-textual hash id's can be cached5037$expires="+1d";5038}50395040my$have_blame= gitweb_check_feature('blame');5041open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5042or die_error(500,"Couldn't cat$file_name,$hash");5043my$mimetype= blob_mimetype($fd,$file_name);5044if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {5045close$fd;5046return git_blob_plain($mimetype);5047}5048# we can have blame only for text/* mimetype5049$have_blame&&= ($mimetype=~m!^text/!);50505051 git_header_html(undef,$expires);5052my$formats_nav='';5053if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5054if(defined$file_name) {5055if($have_blame) {5056$formats_nav.=5057$cgi->a({-href => href(action=>"blame", -replay=>1)},5058"blame") .5059" | ";5060}5061$formats_nav.=5062$cgi->a({-href => href(action=>"history", -replay=>1)},5063"history") .5064" | ".5065$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5066"raw") .5067" | ".5068$cgi->a({-href => href(action=>"blob",5069 hash_base=>"HEAD", file_name=>$file_name)},5070"HEAD");5071}else{5072$formats_nav.=5073$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5074"raw");5075}5076 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5077 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5078}else{5079print"<div class=\"page_nav\">\n".5080"<br/><br/></div>\n".5081"<div class=\"title\">$hash</div>\n";5082}5083 git_print_page_path($file_name,"blob",$hash_base);5084print"<div class=\"page_body\">\n";5085if($mimetype=~m!^image/!) {5086print qq!<img type="$mimetype"!;5087if($file_name) {5088print qq! alt="$file_name" title="$file_name"!;5089}5090print qq! src="! .5091 href(action=>"blob_plain", hash=>$hash,5092 hash_base=>$hash_base, file_name=>$file_name) .5093 qq!"/>\n!;5094}else{5095my$nr;5096while(my$line= <$fd>) {5097chomp$line;5098$nr++;5099$line= untabify($line);5100printf"<div class=\"pre\"><a id=\"l%i\"href=\"#l%i\"class=\"linenr\">%4i</a>%s</div>\n",5101$nr,$nr,$nr, esc_html($line, -nbsp=>1);5102}5103}5104close$fd5105or print"Reading blob failed.\n";5106print"</div>";5107 git_footer_html();5108}51095110sub git_tree {5111if(!defined$hash_base) {5112$hash_base="HEAD";5113}5114if(!defined$hash) {5115if(defined$file_name) {5116$hash= git_get_hash_by_path($hash_base,$file_name,"tree");5117}else{5118$hash=$hash_base;5119}5120}5121 die_error(404,"No such tree")unlessdefined($hash);51225123my$show_sizes= gitweb_check_feature('show-sizes');5124my$have_blame= gitweb_check_feature('blame');51255126my@entries= ();5127{5128local$/="\0";5129open my$fd,"-|", git_cmd(),"ls-tree",'-z',5130($show_sizes?'-l': ()),@extra_options,$hash5131or die_error(500,"Open git-ls-tree failed");5132@entries=map{chomp;$_} <$fd>;5133close$fd5134or die_error(404,"Reading tree failed");5135}51365137my$refs= git_get_references();5138my$ref= format_ref_marker($refs,$hash_base);5139 git_header_html();5140my$basedir='';5141if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5142my@views_nav= ();5143if(defined$file_name) {5144push@views_nav,5145$cgi->a({-href => href(action=>"history", -replay=>1)},5146"history"),5147$cgi->a({-href => href(action=>"tree",5148 hash_base=>"HEAD", file_name=>$file_name)},5149"HEAD"),5150}5151my$snapshot_links= format_snapshot_links($hash);5152if(defined$snapshot_links) {5153# FIXME: Should be available when we have no hash base as well.5154push@views_nav,$snapshot_links;5155}5156 git_print_page_nav('tree','',$hash_base,undef,undef,5157join(' | ',@views_nav));5158 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);5159}else{5160undef$hash_base;5161print"<div class=\"page_nav\">\n";5162print"<br/><br/></div>\n";5163print"<div class=\"title\">$hash</div>\n";5164}5165if(defined$file_name) {5166$basedir=$file_name;5167if($basedirne''&&substr($basedir, -1)ne'/') {5168$basedir.='/';5169}5170 git_print_page_path($file_name,'tree',$hash_base);5171}5172print"<div class=\"page_body\">\n";5173print"<table class=\"tree\">\n";5174my$alternate=1;5175# '..' (top directory) link if possible5176if(defined$hash_base&&5177defined$file_name&&$file_name=~m![^/]+$!) {5178if($alternate) {5179print"<tr class=\"dark\">\n";5180}else{5181print"<tr class=\"light\">\n";5182}5183$alternate^=1;51845185my$up=$file_name;5186$up=~s!/?[^/]+$!!;5187undef$upunless$up;5188# based on git_print_tree_entry5189print'<td class="mode">'. mode_str('040000') ."</td>\n";5190print'<td class="size"> </td>'."\n"if$show_sizes;5191print'<td class="list">';5192print$cgi->a({-href => href(action=>"tree",5193 hash_base=>$hash_base,5194 file_name=>$up)},5195"..");5196print"</td>\n";5197print"<td class=\"link\"></td>\n";51985199print"</tr>\n";5200}5201foreachmy$line(@entries) {5202my%t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);52035204if($alternate) {5205print"<tr class=\"dark\">\n";5206}else{5207print"<tr class=\"light\">\n";5208}5209$alternate^=1;52105211 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);52125213print"</tr>\n";5214}5215print"</table>\n".5216"</div>";5217 git_footer_html();5218}52195220sub git_snapshot {5221my$format=$input_params{'snapshot_format'};5222if(!@snapshot_fmts) {5223 die_error(403,"Snapshots not allowed");5224}5225# default to first supported snapshot format5226$format||=$snapshot_fmts[0];5227if($format!~m/^[a-z0-9]+$/) {5228 die_error(400,"Invalid snapshot format parameter");5229}elsif(!exists($known_snapshot_formats{$format})) {5230 die_error(400,"Unknown snapshot format");5231}elsif($known_snapshot_formats{$format}{'disabled'}) {5232 die_error(403,"Snapshot format not allowed");5233}elsif(!grep($_eq$format,@snapshot_fmts)) {5234 die_error(403,"Unsupported snapshot format");5235}52365237if(!defined$hash) {5238$hash= git_get_head_hash($project);5239}52405241my$name=$project;5242$name=~ s,([^/])/*\.git$,$1,;5243$name= basename($name);5244my$filename= to_utf8($name);5245$name=~s/\047/\047\\\047\047/g;5246my$cmd;5247$filename.="-$hash$known_snapshot_formats{$format}{'suffix'}";5248$cmd= quote_command(5249 git_cmd(),'archive',5250"--format=$known_snapshot_formats{$format}{'format'}",5251"--prefix=$name/",$hash);5252if(exists$known_snapshot_formats{$format}{'compressor'}) {5253$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});5254}52555256print$cgi->header(5257-type =>$known_snapshot_formats{$format}{'type'},5258-content_disposition =>'inline; filename="'."$filename".'"',5259-status =>'200 OK');52605261open my$fd,"-|",$cmd5262or die_error(500,"Execute git-archive failed");5263binmode STDOUT,':raw';5264print<$fd>;5265binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5266close$fd;5267}52685269sub git_log {5270my$head= git_get_head_hash($project);5271if(!defined$hash) {5272$hash=$head;5273}5274if(!defined$page) {5275$page=0;5276}5277my$refs= git_get_references();52785279my@commitlist= parse_commits($hash,101, (100*$page));52805281my$paging_nav= format_paging_nav('log',$hash,$head,$page,$#commitlist>=100);52825283my($patch_max) = gitweb_get_feature('patches');5284if($patch_max) {5285if($patch_max<0||@commitlist<=$patch_max) {5286$paging_nav.=" ⋅ ".5287$cgi->a({-href => href(action=>"patches", -replay=>1)},5288"patches");5289}5290}52915292 git_header_html();5293 git_print_page_nav('log','',$hash,undef,undef,$paging_nav);52945295if(!@commitlist) {5296my%co= parse_commit($hash);52975298 git_print_header_div('summary',$project);5299print"<div class=\"page_body\"> Last change$co{'age_string'}.<br/><br/></div>\n";5300}5301my$to= ($#commitlist>=99) ? (99) : ($#commitlist);5302for(my$i=0;$i<=$to;$i++) {5303my%co= %{$commitlist[$i]};5304next if!%co;5305my$commit=$co{'id'};5306my$ref= format_ref_marker($refs,$commit);5307my%ad= parse_date($co{'author_epoch'});5308 git_print_header_div('commit',5309"<span class=\"age\">$co{'age_string'}</span>".5310 esc_html($co{'title'}) .$ref,5311$commit);5312print"<div class=\"title_text\">\n".5313"<div class=\"log_link\">\n".5314$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .5315" | ".5316$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .5317" | ".5318$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .5319"<br/>\n".5320"</div>\n";5321 git_print_authorship(\%co, -tag =>'span');5322print"<br/>\n</div>\n";53235324print"<div class=\"log_body\">\n";5325 git_print_log($co{'comment'}, -final_empty_line=>1);5326print"</div>\n";5327}5328if($#commitlist>=100) {5329print"<div class=\"page_nav\">\n";5330print$cgi->a({-href => href(-replay=>1, page=>$page+1),5331-accesskey =>"n", -title =>"Alt-n"},"next");5332print"</div>\n";5333}5334 git_footer_html();5335}53365337sub git_commit {5338$hash||=$hash_base||"HEAD";5339my%co= parse_commit($hash)5340or die_error(404,"Unknown commit object");53415342my$parent=$co{'parent'};5343my$parents=$co{'parents'};# listref53445345# we need to prepare $formats_nav before any parameter munging5346my$formats_nav;5347if(!defined$parent) {5348# --root commitdiff5349$formats_nav.='(initial)';5350}elsif(@$parents==1) {5351# single parent commit5352$formats_nav.=5353'(parent: '.5354$cgi->a({-href => href(action=>"commit",5355 hash=>$parent)},5356 esc_html(substr($parent,0,7))) .5357')';5358}else{5359# merge commit5360$formats_nav.=5361'(merge: '.5362join(' ',map{5363$cgi->a({-href => href(action=>"commit",5364 hash=>$_)},5365 esc_html(substr($_,0,7)));5366}@$parents) .5367')';5368}5369if(gitweb_check_feature('patches') &&@$parents<=1) {5370$formats_nav.=" | ".5371$cgi->a({-href => href(action=>"patch", -replay=>1)},5372"patch");5373}53745375if(!defined$parent) {5376$parent="--root";5377}5378my@difftree;5379open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5380@diff_opts,5381(@$parents<=1?$parent:'-c'),5382$hash,"--"5383or die_error(500,"Open git-diff-tree failed");5384@difftree=map{chomp;$_} <$fd>;5385close$fdor die_error(404,"Reading git-diff-tree failed");53865387# non-textual hash id's can be cached5388my$expires;5389if($hash=~m/^[0-9a-fA-F]{40}$/) {5390$expires="+1d";5391}5392my$refs= git_get_references();5393my$ref= format_ref_marker($refs,$co{'id'});53945395 git_header_html(undef,$expires);5396 git_print_page_nav('commit','',5397$hash,$co{'tree'},$hash,5398$formats_nav);53995400if(defined$co{'parent'}) {5401 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5402}else{5403 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5404}5405print"<div class=\"title_text\">\n".5406"<table class=\"object_header\">\n";5407 git_print_authorship_rows(\%co);5408print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";5409print"<tr>".5410"<td>tree</td>".5411"<td class=\"sha1\">".5412$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),5413class=>"list"},$co{'tree'}) .5414"</td>".5415"<td class=\"link\">".5416$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},5417"tree");5418my$snapshot_links= format_snapshot_links($hash);5419if(defined$snapshot_links) {5420print" | ".$snapshot_links;5421}5422print"</td>".5423"</tr>\n";54245425foreachmy$par(@$parents) {5426print"<tr>".5427"<td>parent</td>".5428"<td class=\"sha1\">".5429$cgi->a({-href => href(action=>"commit", hash=>$par),5430class=>"list"},$par) .5431"</td>".5432"<td class=\"link\">".5433$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .5434" | ".5435$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .5436"</td>".5437"</tr>\n";5438}5439print"</table>".5440"</div>\n";54415442print"<div class=\"page_body\">\n";5443 git_print_log($co{'comment'});5444print"</div>\n";54455446 git_difftree_body(\@difftree,$hash,@$parents);54475448 git_footer_html();5449}54505451sub git_object {5452# object is defined by:5453# - hash or hash_base alone5454# - hash_base and file_name5455my$type;54565457# - hash or hash_base alone5458if($hash|| ($hash_base&& !defined$file_name)) {5459my$object_id=$hash||$hash_base;54605461open my$fd,"-|", quote_command(5462 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'5463or die_error(404,"Object does not exist");5464$type= <$fd>;5465chomp$type;5466close$fd5467or die_error(404,"Object does not exist");54685469# - hash_base and file_name5470}elsif($hash_base&&defined$file_name) {5471$file_name=~ s,/+$,,;54725473system(git_cmd(),"cat-file",'-e',$hash_base) ==05474or die_error(404,"Base object does not exist");54755476# here errors should not hapen5477open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name5478or die_error(500,"Open git-ls-tree failed");5479my$line= <$fd>;5480close$fd;54815482#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'5483unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {5484 die_error(404,"File or directory for given base does not exist");5485}5486$type=$2;5487$hash=$3;5488}else{5489 die_error(400,"Not enough information to find object");5490}54915492print$cgi->redirect(-uri => href(action=>$type, -full=>1,5493 hash=>$hash, hash_base=>$hash_base,5494 file_name=>$file_name),5495-status =>'302 Found');5496}54975498sub git_blobdiff {5499my$format=shift||'html';55005501my$fd;5502my@difftree;5503my%diffinfo;5504my$expires;55055506# preparing $fd and %diffinfo for git_patchset_body5507# new style URI5508if(defined$hash_base&&defined$hash_parent_base) {5509if(defined$file_name) {5510# read raw output5511open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5512$hash_parent_base,$hash_base,5513"--", (defined$file_parent?$file_parent: ()),$file_name5514or die_error(500,"Open git-diff-tree failed");5515@difftree=map{chomp;$_} <$fd>;5516close$fd5517or die_error(404,"Reading git-diff-tree failed");5518@difftree5519or die_error(404,"Blob diff not found");55205521}elsif(defined$hash&&5522$hash=~/[0-9a-fA-F]{40}/) {5523# try to find filename from $hash55245525# read filtered raw output5526open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5527$hash_parent_base,$hash_base,"--"5528or die_error(500,"Open git-diff-tree failed");5529@difftree=5530# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5531# $hash == to_id5532grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5533map{chomp;$_} <$fd>;5534close$fd5535or die_error(404,"Reading git-diff-tree failed");5536@difftree5537or die_error(404,"Blob diff not found");55385539}else{5540 die_error(400,"Missing one of the blob diff parameters");5541}55425543if(@difftree>1) {5544 die_error(400,"Ambiguous blob diff specification");5545}55465547%diffinfo= parse_difftree_raw_line($difftree[0]);5548$file_parent||=$diffinfo{'from_file'} ||$file_name;5549$file_name||=$diffinfo{'to_file'};55505551$hash_parent||=$diffinfo{'from_id'};5552$hash||=$diffinfo{'to_id'};55535554# non-textual hash id's can be cached5555if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5556$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5557$expires='+1d';5558}55595560# open patch output5561open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5562'-p', ($formateq'html'?"--full-index": ()),5563$hash_parent_base,$hash_base,5564"--", (defined$file_parent?$file_parent: ()),$file_name5565or die_error(500,"Open git-diff-tree failed");5566}55675568# old/legacy style URI -- not generated anymore since 1.4.3.5569if(!%diffinfo) {5570 die_error('404 Not Found',"Missing one of the blob diff parameters")5571}55725573# header5574if($formateq'html') {5575my$formats_nav=5576$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5577"raw");5578 git_header_html(undef,$expires);5579if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5580 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5581 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5582}else{5583print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5584print"<div class=\"title\">$hashvs$hash_parent</div>\n";5585}5586if(defined$file_name) {5587 git_print_page_path($file_name,"blob",$hash_base);5588}else{5589print"<div class=\"page_path\"></div>\n";5590}55915592}elsif($formateq'plain') {5593print$cgi->header(5594-type =>'text/plain',5595-charset =>'utf-8',5596-expires =>$expires,5597-content_disposition =>'inline; filename="'."$file_name".'.patch"');55985599print"X-Git-Url: ".$cgi->self_url() ."\n\n";56005601}else{5602 die_error(400,"Unknown blobdiff format");5603}56045605# patch5606if($formateq'html') {5607print"<div class=\"page_body\">\n";56085609 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5610close$fd;56115612print"</div>\n";# class="page_body"5613 git_footer_html();56145615}else{5616while(my$line= <$fd>) {5617$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5618$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;56195620print$line;56215622last if$line=~m!^\+\+\+!;5623}5624local$/=undef;5625print<$fd>;5626close$fd;5627}5628}56295630sub git_blobdiff_plain {5631 git_blobdiff('plain');5632}56335634sub git_commitdiff {5635my%params=@_;5636my$format=$params{-format} ||'html';56375638my($patch_max) = gitweb_get_feature('patches');5639if($formateq'patch') {5640 die_error(403,"Patch view not allowed")unless$patch_max;5641}56425643$hash||=$hash_base||"HEAD";5644my%co= parse_commit($hash)5645or die_error(404,"Unknown commit object");56465647# choose format for commitdiff for merge5648if(!defined$hash_parent&& @{$co{'parents'}} >1) {5649$hash_parent='--cc';5650}5651# we need to prepare $formats_nav before almost any parameter munging5652my$formats_nav;5653if($formateq'html') {5654$formats_nav=5655$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},5656"raw");5657if($patch_max&& @{$co{'parents'}} <=1) {5658$formats_nav.=" | ".5659$cgi->a({-href => href(action=>"patch", -replay=>1)},5660"patch");5661}56625663if(defined$hash_parent&&5664$hash_parentne'-c'&&$hash_parentne'--cc') {5665# commitdiff with two commits given5666my$hash_parent_short=$hash_parent;5667if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {5668$hash_parent_short=substr($hash_parent,0,7);5669}5670$formats_nav.=5671' (from';5672for(my$i=0;$i< @{$co{'parents'}};$i++) {5673if($co{'parents'}[$i]eq$hash_parent) {5674$formats_nav.=' parent '. ($i+1);5675last;5676}5677}5678$formats_nav.=': '.5679$cgi->a({-href => href(action=>"commitdiff",5680 hash=>$hash_parent)},5681 esc_html($hash_parent_short)) .5682')';5683}elsif(!$co{'parent'}) {5684# --root commitdiff5685$formats_nav.=' (initial)';5686}elsif(scalar@{$co{'parents'}} ==1) {5687# single parent commit5688$formats_nav.=5689' (parent: '.5690$cgi->a({-href => href(action=>"commitdiff",5691 hash=>$co{'parent'})},5692 esc_html(substr($co{'parent'},0,7))) .5693')';5694}else{5695# merge commit5696if($hash_parenteq'--cc') {5697$formats_nav.=' | '.5698$cgi->a({-href => href(action=>"commitdiff",5699 hash=>$hash, hash_parent=>'-c')},5700'combined');5701}else{# $hash_parent eq '-c'5702$formats_nav.=' | '.5703$cgi->a({-href => href(action=>"commitdiff",5704 hash=>$hash, hash_parent=>'--cc')},5705'compact');5706}5707$formats_nav.=5708' (merge: '.5709join(' ',map{5710$cgi->a({-href => href(action=>"commitdiff",5711 hash=>$_)},5712 esc_html(substr($_,0,7)));5713} @{$co{'parents'}} ) .5714')';5715}5716}57175718my$hash_parent_param=$hash_parent;5719if(!defined$hash_parent_param) {5720# --cc for multiple parents, --root for parentless5721$hash_parent_param=5722@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';5723}57245725# read commitdiff5726my$fd;5727my@difftree;5728if($formateq'html') {5729open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5730"--no-commit-id","--patch-with-raw","--full-index",5731$hash_parent_param,$hash,"--"5732or die_error(500,"Open git-diff-tree failed");57335734while(my$line= <$fd>) {5735chomp$line;5736# empty line ends raw part of diff-tree output5737last unless$line;5738push@difftree,scalar parse_difftree_raw_line($line);5739}57405741}elsif($formateq'plain') {5742open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5743'-p',$hash_parent_param,$hash,"--"5744or die_error(500,"Open git-diff-tree failed");5745}elsif($formateq'patch') {5746# For commit ranges, we limit the output to the number of5747# patches specified in the 'patches' feature.5748# For single commits, we limit the output to a single patch,5749# diverging from the git-format-patch default.5750my@commit_spec= ();5751if($hash_parent) {5752if($patch_max>0) {5753push@commit_spec,"-$patch_max";5754}5755push@commit_spec,'-n',"$hash_parent..$hash";5756}else{5757if($params{-single}) {5758push@commit_spec,'-1';5759}else{5760if($patch_max>0) {5761push@commit_spec,"-$patch_max";5762}5763push@commit_spec,"-n";5764}5765push@commit_spec,'--root',$hash;5766}5767open$fd,"-|", git_cmd(),"format-patch",'--encoding=utf8',5768'--stdout',@commit_spec5769or die_error(500,"Open git-format-patch failed");5770}else{5771 die_error(400,"Unknown commitdiff format");5772}57735774# non-textual hash id's can be cached5775my$expires;5776if($hash=~m/^[0-9a-fA-F]{40}$/) {5777$expires="+1d";5778}57795780# write commit message5781if($formateq'html') {5782my$refs= git_get_references();5783my$ref= format_ref_marker($refs,$co{'id'});57845785 git_header_html(undef,$expires);5786 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);5787 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);5788print"<div class=\"title_text\">\n".5789"<table class=\"object_header\">\n";5790 git_print_authorship_rows(\%co);5791print"</table>".5792"</div>\n";5793print"<div class=\"page_body\">\n";5794if(@{$co{'comment'}} >1) {5795print"<div class=\"log\">\n";5796 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);5797print"</div>\n";# class="log"5798}57995800}elsif($formateq'plain') {5801my$refs= git_get_references("tags");5802my$tagname= git_get_rev_name_tags($hash);5803my$filename= basename($project) ."-$hash.patch";58045805print$cgi->header(5806-type =>'text/plain',5807-charset =>'utf-8',5808-expires =>$expires,5809-content_disposition =>'inline; filename="'."$filename".'"');5810my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5811print"From: ". to_utf8($co{'author'}) ."\n";5812print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";5813print"Subject: ". to_utf8($co{'title'}) ."\n";58145815print"X-Git-Tag:$tagname\n"if$tagname;5816print"X-Git-Url: ".$cgi->self_url() ."\n\n";58175818foreachmy$line(@{$co{'comment'}}) {5819print to_utf8($line) ."\n";5820}5821print"---\n\n";5822}elsif($formateq'patch') {5823my$filename= basename($project) ."-$hash.patch";58245825print$cgi->header(5826-type =>'text/plain',5827-charset =>'utf-8',5828-expires =>$expires,5829-content_disposition =>'inline; filename="'."$filename".'"');5830}58315832# write patch5833if($formateq'html') {5834my$use_parents= !defined$hash_parent||5835$hash_parenteq'-c'||$hash_parenteq'--cc';5836 git_difftree_body(\@difftree,$hash,5837$use_parents? @{$co{'parents'}} :$hash_parent);5838print"<br/>\n";58395840 git_patchset_body($fd, \@difftree,$hash,5841$use_parents? @{$co{'parents'}} :$hash_parent);5842close$fd;5843print"</div>\n";# class="page_body"5844 git_footer_html();58455846}elsif($formateq'plain') {5847local$/=undef;5848print<$fd>;5849close$fd5850or print"Reading git-diff-tree failed\n";5851}elsif($formateq'patch') {5852local$/=undef;5853print<$fd>;5854close$fd5855or print"Reading git-format-patch failed\n";5856}5857}58585859sub git_commitdiff_plain {5860 git_commitdiff(-format =>'plain');5861}58625863# format-patch-style patches5864sub git_patch {5865 git_commitdiff(-format =>'patch', -single =>1);5866}58675868sub git_patches {5869 git_commitdiff(-format =>'patch');5870}58715872sub git_history {5873if(!defined$hash_base) {5874$hash_base= git_get_head_hash($project);5875}5876if(!defined$page) {5877$page=0;5878}5879my$ftype;5880my%co= parse_commit($hash_base)5881or die_error(404,"Unknown commit object");58825883my$refs= git_get_references();5884my$limit=sprintf("--max-count=%i", (100* ($page+1)));58855886my@commitlist= parse_commits($hash_base,101, (100*$page),5887$file_name,"--full-history")5888or die_error(404,"No such file or directory on given branch");58895890if(!defined$hash&&defined$file_name) {5891# some commits could have deleted file in question,5892# and not have it in tree, but one of them has to have it5893for(my$i=0;$i<=@commitlist;$i++) {5894$hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5895last ifdefined$hash;5896}5897}5898if(defined$hash) {5899$ftype= git_get_type($hash);5900}5901if(!defined$ftype) {5902 die_error(500,"Unknown type of object");5903}59045905my$paging_nav='';5906if($page>0) {5907$paging_nav.=5908$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,5909 file_name=>$file_name)},5910"first");5911$paging_nav.=" ⋅ ".5912$cgi->a({-href => href(-replay=>1, page=>$page-1),5913-accesskey =>"p", -title =>"Alt-p"},"prev");5914}else{5915$paging_nav.="first";5916$paging_nav.=" ⋅ prev";5917}5918my$next_link='';5919if($#commitlist>=100) {5920$next_link=5921$cgi->a({-href => href(-replay=>1, page=>$page+1),5922-accesskey =>"n", -title =>"Alt-n"},"next");5923$paging_nav.=" ⋅$next_link";5924}else{5925$paging_nav.=" ⋅ next";5926}59275928 git_header_html();5929 git_print_page_nav('history','',$hash_base,$co{'tree'},$hash_base,$paging_nav);5930 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5931 git_print_page_path($file_name,$ftype,$hash_base);59325933 git_history_body(\@commitlist,0,99,5934$refs,$hash_base,$ftype,$next_link);59355936 git_footer_html();5937}59385939sub git_search {5940 gitweb_check_feature('search')or die_error(403,"Search is disabled");5941if(!defined$searchtext) {5942 die_error(400,"Text field is empty");5943}5944if(!defined$hash) {5945$hash= git_get_head_hash($project);5946}5947my%co= parse_commit($hash);5948if(!%co) {5949 die_error(404,"Unknown commit object");5950}5951if(!defined$page) {5952$page=0;5953}59545955$searchtype||='commit';5956if($searchtypeeq'pickaxe') {5957# pickaxe may take all resources of your box and run for several minutes5958# with every query - so decide by yourself how public you make this feature5959 gitweb_check_feature('pickaxe')5960or die_error(403,"Pickaxe is disabled");5961}5962if($searchtypeeq'grep') {5963 gitweb_check_feature('grep')5964or die_error(403,"Grep is disabled");5965}59665967 git_header_html();59685969if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {5970my$greptype;5971if($searchtypeeq'commit') {5972$greptype="--grep=";5973}elsif($searchtypeeq'author') {5974$greptype="--author=";5975}elsif($searchtypeeq'committer') {5976$greptype="--committer=";5977}5978$greptype.=$searchtext;5979my@commitlist= parse_commits($hash,101, (100*$page),undef,5980$greptype,'--regexp-ignore-case',5981$search_use_regexp?'--extended-regexp':'--fixed-strings');59825983my$paging_nav='';5984if($page>0) {5985$paging_nav.=5986$cgi->a({-href => href(action=>"search", hash=>$hash,5987 searchtext=>$searchtext,5988 searchtype=>$searchtype)},5989"first");5990$paging_nav.=" ⋅ ".5991$cgi->a({-href => href(-replay=>1, page=>$page-1),5992-accesskey =>"p", -title =>"Alt-p"},"prev");5993}else{5994$paging_nav.="first";5995$paging_nav.=" ⋅ prev";5996}5997my$next_link='';5998if($#commitlist>=100) {5999$next_link=6000$cgi->a({-href => href(-replay=>1, page=>$page+1),6001-accesskey =>"n", -title =>"Alt-n"},"next");6002$paging_nav.=" ⋅$next_link";6003}else{6004$paging_nav.=" ⋅ next";6005}60066007if($#commitlist>=100) {6008}60096010 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);6011 git_print_header_div('commit', esc_html($co{'title'}),$hash);6012 git_search_grep_body(\@commitlist,0,99,$next_link);6013}60146015if($searchtypeeq'pickaxe') {6016 git_print_page_nav('','',$hash,$co{'tree'},$hash);6017 git_print_header_div('commit', esc_html($co{'title'}),$hash);60186019print"<table class=\"pickaxe search\">\n";6020my$alternate=1;6021local$/="\n";6022open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,6023'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",6024($search_use_regexp?'--pickaxe-regex': ());6025undef%co;6026my@files;6027while(my$line= <$fd>) {6028chomp$line;6029next unless$line;60306031my%set= parse_difftree_raw_line($line);6032if(defined$set{'commit'}) {6033# finish previous commit6034if(%co) {6035print"</td>\n".6036"<td class=\"link\">".6037$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6038" | ".6039$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6040print"</td>\n".6041"</tr>\n";6042}60436044if($alternate) {6045print"<tr class=\"dark\">\n";6046}else{6047print"<tr class=\"light\">\n";6048}6049$alternate^=1;6050%co= parse_commit($set{'commit'});6051my$author= chop_and_escape_str($co{'author_name'},15,5);6052print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6053"<td><i>$author</i></td>\n".6054"<td>".6055$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6056-class=>"list subject"},6057 chop_and_escape_str($co{'title'},50) ."<br/>");6058}elsif(defined$set{'to_id'}) {6059next if($set{'to_id'} =~m/^0{40}$/);60606061print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6062 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6063-class=>"list"},6064"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6065"<br/>\n";6066}6067}6068close$fd;60696070# finish last commit (warning: repetition!)6071if(%co) {6072print"</td>\n".6073"<td class=\"link\">".6074$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6075" | ".6076$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6077print"</td>\n".6078"</tr>\n";6079}60806081print"</table>\n";6082}60836084if($searchtypeeq'grep') {6085 git_print_page_nav('','',$hash,$co{'tree'},$hash);6086 git_print_header_div('commit', esc_html($co{'title'}),$hash);60876088print"<table class=\"grep_search\">\n";6089my$alternate=1;6090my$matches=0;6091local$/="\n";6092open my$fd,"-|", git_cmd(),'grep','-n',6093$search_use_regexp? ('-E','-i') :'-F',6094$searchtext,$co{'tree'};6095my$lastfile='';6096while(my$line= <$fd>) {6097chomp$line;6098my($file,$lno,$ltext,$binary);6099last if($matches++>1000);6100if($line=~/^Binary file (.+) matches$/) {6101$file=$1;6102$binary=1;6103}else{6104(undef,$file,$lno,$ltext) =split(/:/,$line,4);6105}6106if($filene$lastfile) {6107$lastfileand print"</td></tr>\n";6108if($alternate++) {6109print"<tr class=\"dark\">\n";6110}else{6111print"<tr class=\"light\">\n";6112}6113print"<td class=\"list\">".6114$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6115 file_name=>"$file"),6116-class=>"list"}, esc_path($file));6117print"</td><td>\n";6118$lastfile=$file;6119}6120if($binary) {6121print"<div class=\"binary\">Binary file</div>\n";6122}else{6123$ltext= untabify($ltext);6124if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6125$ltext= esc_html($1, -nbsp=>1);6126$ltext.='<span class="match">';6127$ltext.= esc_html($2, -nbsp=>1);6128$ltext.='</span>';6129$ltext.= esc_html($3, -nbsp=>1);6130}else{6131$ltext= esc_html($ltext, -nbsp=>1);6132}6133print"<div class=\"pre\">".6134$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6135 file_name=>"$file").'#l'.$lno,6136-class=>"linenr"},sprintf('%4i',$lno))6137.' '.$ltext."</div>\n";6138}6139}6140if($lastfile) {6141print"</td></tr>\n";6142if($matches>1000) {6143print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6144}6145}else{6146print"<div class=\"diff nodifferences\">No matches found</div>\n";6147}6148close$fd;61496150print"</table>\n";6151}6152 git_footer_html();6153}61546155sub git_search_help {6156 git_header_html();6157 git_print_page_nav('','',$hash,$hash,$hash);6158print<<EOT;6159<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without6160regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,6161the pattern entered is recognized as the POSIX extended6162<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case6163insensitive).</p>6164<dl>6165<dt><b>commit</b></dt>6166<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>6167EOT6168my$have_grep= gitweb_check_feature('grep');6169if($have_grep) {6170print<<EOT;6171<dt><b>grep</b></dt>6172<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing6173 a different one) are searched for the given pattern. On large trees, this search can take6174a while and put some strain on the server, so please use it with some consideration. Note that6175due to git-grep peculiarity, currently if regexp mode is turned off, the matches are6176case-sensitive.</dd>6177EOT6178}6179print<<EOT;6180<dt><b>author</b></dt>6181<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>6182<dt><b>committer</b></dt>6183<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>6184EOT6185my$have_pickaxe= gitweb_check_feature('pickaxe');6186if($have_pickaxe) {6187print<<EOT;6188<dt><b>pickaxe</b></dt>6189<dd>All commits that caused the string to appear or disappear from any file (changes that6190added, removed or "modified" the string) will be listed. This search can take a while and6191takes a lot of strain on the server, so please use it wisely. Note that since you may be6192interested even in changes just changing the case as well, this search is case sensitive.</dd>6193EOT6194}6195print"</dl>\n";6196 git_footer_html();6197}61986199sub git_shortlog {6200my$head= git_get_head_hash($project);6201if(!defined$hash) {6202$hash=$head;6203}6204if(!defined$page) {6205$page=0;6206}6207my$refs= git_get_references();62086209my$commit_hash=$hash;6210if(defined$hash_parent) {6211$commit_hash="$hash_parent..$hash";6212}6213my@commitlist= parse_commits($commit_hash,101, (100*$page));62146215my$paging_nav= format_paging_nav('shortlog',$hash,$head,$page,$#commitlist>=100);6216my$next_link='';6217if($#commitlist>=100) {6218$next_link=6219$cgi->a({-href => href(-replay=>1, page=>$page+1),6220-accesskey =>"n", -title =>"Alt-n"},"next");6221}6222my$patch_max= gitweb_check_feature('patches');6223if($patch_max) {6224if($patch_max<0||@commitlist<=$patch_max) {6225$paging_nav.=" ⋅ ".6226$cgi->a({-href => href(action=>"patches", -replay=>1)},6227"patches");6228}6229}62306231 git_header_html();6232 git_print_page_nav('shortlog','',$hash,$hash,$hash,$paging_nav);6233 git_print_header_div('summary',$project);62346235 git_shortlog_body(\@commitlist,0,99,$refs,$next_link);62366237 git_footer_html();6238}62396240## ......................................................................6241## feeds (RSS, Atom; OPML)62426243sub git_feed {6244my$format=shift||'atom';6245my$have_blame= gitweb_check_feature('blame');62466247# Atom: http://www.atomenabled.org/developers/syndication/6248# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ6249if($formatne'rss'&&$formatne'atom') {6250 die_error(400,"Unknown web feed format");6251}62526253# log/feed of current (HEAD) branch, log of given branch, history of file/directory6254my$head=$hash||'HEAD';6255my@commitlist= parse_commits($head,150,0,$file_name);62566257my%latest_commit;6258my%latest_date;6259my$content_type="application/$format+xml";6260if(defined$cgi->http('HTTP_ACCEPT') &&6261$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {6262# browser (feed reader) prefers text/xml6263$content_type='text/xml';6264}6265if(defined($commitlist[0])) {6266%latest_commit= %{$commitlist[0]};6267my$latest_epoch=$latest_commit{'committer_epoch'};6268%latest_date= parse_date($latest_epoch);6269my$if_modified=$cgi->http('IF_MODIFIED_SINCE');6270if(defined$if_modified) {6271my$since;6272if(eval{require HTTP::Date;1; }) {6273$since= HTTP::Date::str2time($if_modified);6274}elsif(eval{require Time::ParseDate;1; }) {6275$since= Time::ParseDate::parsedate($if_modified, GMT =>1);6276}6277if(defined$since&&$latest_epoch<=$since) {6278print$cgi->header(6279-type =>$content_type,6280-charset =>'utf-8',6281-last_modified =>$latest_date{'rfc2822'},6282-status =>'304 Not Modified');6283return;6284}6285}6286print$cgi->header(6287-type =>$content_type,6288-charset =>'utf-8',6289-last_modified =>$latest_date{'rfc2822'});6290}else{6291print$cgi->header(6292-type =>$content_type,6293-charset =>'utf-8');6294}62956296# Optimization: skip generating the body if client asks only6297# for Last-Modified date.6298return if($cgi->request_method()eq'HEAD');62996300# header variables6301my$title="$site_name-$project/$action";6302my$feed_type='log';6303if(defined$hash) {6304$title.=" - '$hash'";6305$feed_type='branch log';6306if(defined$file_name) {6307$title.=" ::$file_name";6308$feed_type='history';6309}6310}elsif(defined$file_name) {6311$title.=" -$file_name";6312$feed_type='history';6313}6314$title.="$feed_type";6315my$descr= git_get_project_description($project);6316if(defined$descr) {6317$descr= esc_html($descr);6318}else{6319$descr="$project".6320($formateq'rss'?'RSS':'Atom') .6321" feed";6322}6323my$owner= git_get_project_owner($project);6324$owner= esc_html($owner);63256326#header6327my$alt_url;6328if(defined$file_name) {6329$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);6330}elsif(defined$hash) {6331$alt_url= href(-full=>1, action=>"log", hash=>$hash);6332}else{6333$alt_url= href(-full=>1, action=>"summary");6334}6335print qq!<?xml version="1.0" encoding="utf-8"?>\n!;6336if($formateq'rss') {6337print<<XML;6338<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">6339<channel>6340XML6341print"<title>$title</title>\n".6342"<link>$alt_url</link>\n".6343"<description>$descr</description>\n".6344"<language>en</language>\n".6345# project owner is responsible for 'editorial' content6346"<managingEditor>$owner</managingEditor>\n";6347if(defined$logo||defined$favicon) {6348# prefer the logo to the favicon, since RSS6349# doesn't allow both6350my$img= esc_url($logo||$favicon);6351print"<image>\n".6352"<url>$img</url>\n".6353"<title>$title</title>\n".6354"<link>$alt_url</link>\n".6355"</image>\n";6356}6357if(%latest_date) {6358print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";6359print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";6360}6361print"<generator>gitweb v.$version/$git_version</generator>\n";6362}elsif($formateq'atom') {6363print<<XML;6364<feed xmlns="http://www.w3.org/2005/Atom">6365XML6366print"<title>$title</title>\n".6367"<subtitle>$descr</subtitle>\n".6368'<link rel="alternate" type="text/html" href="'.6369$alt_url.'" />'."\n".6370'<link rel="self" type="'.$content_type.'" href="'.6371$cgi->self_url() .'" />'."\n".6372"<id>". href(-full=>1) ."</id>\n".6373# use project owner for feed author6374"<author><name>$owner</name></author>\n";6375if(defined$favicon) {6376print"<icon>". esc_url($favicon) ."</icon>\n";6377}6378if(defined$logo_url) {6379# not twice as wide as tall: 72 x 27 pixels6380print"<logo>". esc_url($logo) ."</logo>\n";6381}6382if(!%latest_date) {6383# dummy date to keep the feed valid until commits trickle in:6384print"<updated>1970-01-01T00:00:00Z</updated>\n";6385}else{6386print"<updated>$latest_date{'iso-8601'}</updated>\n";6387}6388print"<generator version='$version/$git_version'>gitweb</generator>\n";6389}63906391# contents6392for(my$i=0;$i<=$#commitlist;$i++) {6393my%co= %{$commitlist[$i]};6394my$commit=$co{'id'};6395# we read 150, we always show 30 and the ones more recent than 48 hours6396if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6397last;6398}6399my%cd= parse_date($co{'author_epoch'});64006401# get list of changed files6402open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6403$co{'parent'} ||"--root",6404$co{'id'},"--", (defined$file_name?$file_name: ())6405ornext;6406my@difftree=map{chomp;$_} <$fd>;6407close$fd6408ornext;64096410# print element (entry, item)6411my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6412if($formateq'rss') {6413print"<item>\n".6414"<title>". esc_html($co{'title'}) ."</title>\n".6415"<author>". esc_html($co{'author'}) ."</author>\n".6416"<pubDate>$cd{'rfc2822'}</pubDate>\n".6417"<guid isPermaLink=\"true\">$co_url</guid>\n".6418"<link>$co_url</link>\n".6419"<description>". esc_html($co{'title'}) ."</description>\n".6420"<content:encoded>".6421"<![CDATA[\n";6422}elsif($formateq'atom') {6423print"<entry>\n".6424"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6425"<updated>$cd{'iso-8601'}</updated>\n".6426"<author>\n".6427" <name>". esc_html($co{'author_name'}) ."</name>\n";6428if($co{'author_email'}) {6429print" <email>". esc_html($co{'author_email'}) ."</email>\n";6430}6431print"</author>\n".6432# use committer for contributor6433"<contributor>\n".6434" <name>". esc_html($co{'committer_name'}) ."</name>\n";6435if($co{'committer_email'}) {6436print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6437}6438print"</contributor>\n".6439"<published>$cd{'iso-8601'}</published>\n".6440"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6441"<id>$co_url</id>\n".6442"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6443"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6444}6445my$comment=$co{'comment'};6446print"<pre>\n";6447foreachmy$line(@$comment) {6448$line= esc_html($line);6449print"$line\n";6450}6451print"</pre><ul>\n";6452foreachmy$difftree_line(@difftree) {6453my%difftree= parse_difftree_raw_line($difftree_line);6454next if!$difftree{'from_id'};64556456my$file=$difftree{'file'} ||$difftree{'to_file'};64576458print"<li>".6459"[".6460$cgi->a({-href => href(-full=>1, action=>"blobdiff",6461 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6462 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6463 file_name=>$file, file_parent=>$difftree{'from_file'}),6464-title =>"diff"},'D');6465if($have_blame) {6466print$cgi->a({-href => href(-full=>1, action=>"blame",6467 file_name=>$file, hash_base=>$commit),6468-title =>"blame"},'B');6469}6470# if this is not a feed of a file history6471if(!defined$file_name||$file_namene$file) {6472print$cgi->a({-href => href(-full=>1, action=>"history",6473 file_name=>$file, hash=>$commit),6474-title =>"history"},'H');6475}6476$file= esc_path($file);6477print"] ".6478"$file</li>\n";6479}6480if($formateq'rss') {6481print"</ul>]]>\n".6482"</content:encoded>\n".6483"</item>\n";6484}elsif($formateq'atom') {6485print"</ul>\n</div>\n".6486"</content>\n".6487"</entry>\n";6488}6489}64906491# end of feed6492if($formateq'rss') {6493print"</channel>\n</rss>\n";6494}elsif($formateq'atom') {6495print"</feed>\n";6496}6497}64986499sub git_rss {6500 git_feed('rss');6501}65026503sub git_atom {6504 git_feed('atom');6505}65066507sub git_opml {6508my@list= git_get_projects_list();65096510print$cgi->header(6511-type =>'text/xml',6512-charset =>'utf-8',6513-content_disposition =>'inline; filename="opml.xml"');65146515print<<XML;6516<?xml version="1.0" encoding="utf-8"?>6517<opml version="1.0">6518<head>6519 <title>$site_nameOPML Export</title>6520</head>6521<body>6522<outline text="git RSS feeds">6523XML65246525foreachmy$pr(@list) {6526my%proj=%$pr;6527my$head= git_get_head_hash($proj{'path'});6528if(!defined$head) {6529next;6530}6531$git_dir="$projectroot/$proj{'path'}";6532my%co= parse_commit($head);6533if(!%co) {6534next;6535}65366537my$path= esc_html(chop_str($proj{'path'},25,5));6538my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);6539my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);6540print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";6541}6542print<<XML;6543</outline>6544</body>6545</opml>6546XML6547}