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# Make gitweb use an alternative format of the URLs which can be 301# more readable and natural-looking: project name is embedded 302# directly in the path and the query string contains other 303# auxiliary information. All gitweb installations recognize 304# URL in either format; this configures in which formats gitweb 305# generates links. 306 307# To enable system wide have in $GITWEB_CONFIG 308# $feature{'pathinfo'}{'default'} = [1]; 309# Project specific override is not supported. 310 311# Note that you will need to change the default location of CSS, 312# favicon, logo and possibly other files to an absolute URL. Also, 313# if gitweb.cgi serves as your indexfile, you will need to force 314# $my_uri to contain the script name in your $GITWEB_CONFIG. 315'pathinfo'=> { 316'override'=>0, 317'default'=> [0]}, 318 319# Make gitweb consider projects in project root subdirectories 320# to be forks of existing projects. Given project $projname.git, 321# projects matching $projname/*.git will not be shown in the main 322# projects list, instead a '+' mark will be added to $projname 323# there and a 'forks' view will be enabled for the project, listing 324# all the forks. If project list is taken from a file, forks have 325# to be listed after the main project. 326 327# To enable system wide have in $GITWEB_CONFIG 328# $feature{'forks'}{'default'} = [1]; 329# Project specific override is not supported. 330'forks'=> { 331'override'=>0, 332'default'=> [0]}, 333 334# Insert custom links to the action bar of all project pages. 335# This enables you mainly to link to third-party scripts integrating 336# into gitweb; e.g. git-browser for graphical history representation 337# or custom web-based repository administration interface. 338 339# The 'default' value consists of a list of triplets in the form 340# (label, link, position) where position is the label after which 341# to insert the link and link is a format string where %n expands 342# to the project name, %f to the project path within the filesystem, 343# %h to the current hash (h gitweb parameter) and %b to the current 344# hash base (hb gitweb parameter); %% expands to %. 345 346# To enable system wide have in $GITWEB_CONFIG e.g. 347# $feature{'actions'}{'default'} = [('graphiclog', 348# '/git-browser/by-commit.html?r=%n', 'summary')]; 349# Project specific override is not supported. 350'actions'=> { 351'override'=>0, 352'default'=> []}, 353 354# Allow gitweb scan project content tags described in ctags/ 355# of project repository, and display the popular Web 2.0-ish 356# "tag cloud" near the project list. Note that this is something 357# COMPLETELY different from the normal Git tags. 358 359# gitweb by itself can show existing tags, but it does not handle 360# tagging itself; you need an external application for that. 361# For an example script, check Girocco's cgi/tagproj.cgi. 362# You may want to install the HTML::TagCloud Perl module to get 363# a pretty tag cloud instead of just a list of tags. 364 365# To enable system wide have in $GITWEB_CONFIG 366# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 367# Project specific override is not supported. 368'ctags'=> { 369'override'=>0, 370'default'=> [0]}, 371 372# The maximum number of patches in a patchset generated in patch 373# view. Set this to 0 or undef to disable patch view, or to a 374# negative number to remove any limit. 375 376# To disable system wide have in $GITWEB_CONFIG 377# $feature{'patches'}{'default'} = [0]; 378# To have project specific config enable override in $GITWEB_CONFIG 379# $feature{'patches'}{'override'} = 1; 380# and in project config gitweb.patches = 0|n; 381# where n is the maximum number of patches allowed in a patchset. 382'patches'=> { 383'sub'=> \&feature_patches, 384'override'=>0, 385'default'=> [16]}, 386 387# Avatar support. When this feature is enabled, views such as 388# shortlog or commit will display an avatar associated with 389# the email of the committer(s) and/or author(s). 390 391# Currently available providers are gravatar and picon. 392# If an unknown provider is specified, the feature is disabled. 393 394# Gravatar depends on Digest::MD5. 395# Picon currently relies on the indiana.edu database. 396 397# To enable system wide have in $GITWEB_CONFIG 398# $feature{'avatar'}{'default'} = ['<provider>']; 399# where <provider> is either gravatar or picon. 400# To have project specific config enable override in $GITWEB_CONFIG 401# $feature{'avatar'}{'override'} = 1; 402# and in project config gitweb.avatar = <provider>; 403'avatar'=> { 404'sub'=> \&feature_avatar, 405'override'=>0, 406'default'=> ['']}, 407); 408 409sub gitweb_get_feature { 410my($name) =@_; 411return unlessexists$feature{$name}; 412my($sub,$override,@defaults) = ( 413$feature{$name}{'sub'}, 414$feature{$name}{'override'}, 415@{$feature{$name}{'default'}}); 416if(!$override) {return@defaults; } 417if(!defined$sub) { 418warn"feature$nameis not overridable"; 419return@defaults; 420} 421return$sub->(@defaults); 422} 423 424# A wrapper to check if a given feature is enabled. 425# With this, you can say 426# 427# my $bool_feat = gitweb_check_feature('bool_feat'); 428# gitweb_check_feature('bool_feat') or somecode; 429# 430# instead of 431# 432# my ($bool_feat) = gitweb_get_feature('bool_feat'); 433# (gitweb_get_feature('bool_feat'))[0] or somecode; 434# 435sub gitweb_check_feature { 436return(gitweb_get_feature(@_))[0]; 437} 438 439 440sub feature_bool { 441my$key=shift; 442my($val) = git_get_project_config($key,'--bool'); 443 444if(!defined$val) { 445return($_[0]); 446}elsif($valeq'true') { 447return(1); 448}elsif($valeq'false') { 449return(0); 450} 451} 452 453sub feature_snapshot { 454my(@fmts) =@_; 455 456my($val) = git_get_project_config('snapshot'); 457 458if($val) { 459@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 460} 461 462return@fmts; 463} 464 465sub feature_patches { 466my@val= (git_get_project_config('patches','--int')); 467 468if(@val) { 469return@val; 470} 471 472return($_[0]); 473} 474 475sub feature_avatar { 476my@val= (git_get_project_config('avatar')); 477 478return@val?@val:@_; 479} 480 481# checking HEAD file with -e is fragile if the repository was 482# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 483# and then pruned. 484sub check_head_link { 485my($dir) =@_; 486my$headfile="$dir/HEAD"; 487return((-e $headfile) || 488(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 489} 490 491sub check_export_ok { 492my($dir) =@_; 493return(check_head_link($dir) && 494(!$export_ok|| -e "$dir/$export_ok") && 495(!$export_auth_hook||$export_auth_hook->($dir))); 496} 497 498# process alternate names for backward compatibility 499# filter out unsupported (unknown) snapshot formats 500sub filter_snapshot_fmts { 501my@fmts=@_; 502 503@fmts=map{ 504exists$known_snapshot_format_aliases{$_} ? 505$known_snapshot_format_aliases{$_} :$_}@fmts; 506@fmts=grep{ 507exists$known_snapshot_formats{$_} && 508!$known_snapshot_formats{$_}{'disabled'}}@fmts; 509} 510 511our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 512if(-e $GITWEB_CONFIG) { 513do$GITWEB_CONFIG; 514}else{ 515our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 516do$GITWEB_CONFIG_SYSTEMif-e $GITWEB_CONFIG_SYSTEM; 517} 518 519# version of the core git binary 520our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 521 522$projects_list||=$projectroot; 523 524# ====================================================================== 525# input validation and dispatch 526 527# input parameters can be collected from a variety of sources (presently, CGI 528# and PATH_INFO), so we define an %input_params hash that collects them all 529# together during validation: this allows subsequent uses (e.g. href()) to be 530# agnostic of the parameter origin 531 532our%input_params= (); 533 534# input parameters are stored with the long parameter name as key. This will 535# also be used in the href subroutine to convert parameters to their CGI 536# equivalent, and since the href() usage is the most frequent one, we store 537# the name -> CGI key mapping here, instead of the reverse. 538# 539# XXX: Warning: If you touch this, check the search form for updating, 540# too. 541 542our@cgi_param_mapping= ( 543 project =>"p", 544 action =>"a", 545 file_name =>"f", 546 file_parent =>"fp", 547 hash =>"h", 548 hash_parent =>"hp", 549 hash_base =>"hb", 550 hash_parent_base =>"hpb", 551 page =>"pg", 552 order =>"o", 553 searchtext =>"s", 554 searchtype =>"st", 555 snapshot_format =>"sf", 556 extra_options =>"opt", 557 search_use_regexp =>"sr", 558); 559our%cgi_param_mapping=@cgi_param_mapping; 560 561# we will also need to know the possible actions, for validation 562our%actions= ( 563"blame"=> \&git_blame, 564"blobdiff"=> \&git_blobdiff, 565"blobdiff_plain"=> \&git_blobdiff_plain, 566"blob"=> \&git_blob, 567"blob_plain"=> \&git_blob_plain, 568"commitdiff"=> \&git_commitdiff, 569"commitdiff_plain"=> \&git_commitdiff_plain, 570"commit"=> \&git_commit, 571"forks"=> \&git_forks, 572"heads"=> \&git_heads, 573"history"=> \&git_history, 574"log"=> \&git_log, 575"patch"=> \&git_patch, 576"patches"=> \&git_patches, 577"rss"=> \&git_rss, 578"atom"=> \&git_atom, 579"search"=> \&git_search, 580"search_help"=> \&git_search_help, 581"shortlog"=> \&git_shortlog, 582"summary"=> \&git_summary, 583"tag"=> \&git_tag, 584"tags"=> \&git_tags, 585"tree"=> \&git_tree, 586"snapshot"=> \&git_snapshot, 587"object"=> \&git_object, 588# those below don't need $project 589"opml"=> \&git_opml, 590"project_list"=> \&git_project_list, 591"project_index"=> \&git_project_index, 592); 593 594# finally, we have the hash of allowed extra_options for the commands that 595# allow them 596our%allowed_options= ( 597"--no-merges"=> [qw(rss atom log shortlog history)], 598); 599 600# fill %input_params with the CGI parameters. All values except for 'opt' 601# should be single values, but opt can be an array. We should probably 602# build an array of parameters that can be multi-valued, but since for the time 603# being it's only this one, we just single it out 604while(my($name,$symbol) =each%cgi_param_mapping) { 605if($symboleq'opt') { 606$input_params{$name} = [$cgi->param($symbol) ]; 607}else{ 608$input_params{$name} =$cgi->param($symbol); 609} 610} 611 612# now read PATH_INFO and update the parameter list for missing parameters 613sub evaluate_path_info { 614return ifdefined$input_params{'project'}; 615return if!$path_info; 616$path_info=~ s,^/+,,; 617return if!$path_info; 618 619# find which part of PATH_INFO is project 620my$project=$path_info; 621$project=~ s,/+$,,; 622while($project&& !check_head_link("$projectroot/$project")) { 623$project=~ s,/*[^/]*$,,; 624} 625return unless$project; 626$input_params{'project'} =$project; 627 628# do not change any parameters if an action is given using the query string 629return if$input_params{'action'}; 630$path_info=~ s,^\Q$project\E/*,,; 631 632# next, check if we have an action 633my$action=$path_info; 634$action=~ s,/.*$,,; 635if(exists$actions{$action}) { 636$path_info=~ s,^$action/*,,; 637$input_params{'action'} =$action; 638} 639 640# list of actions that want hash_base instead of hash, but can have no 641# pathname (f) parameter 642my@wants_base= ( 643'tree', 644'history', 645); 646 647# we want to catch 648# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 649my($parentrefname,$parentpathname,$refname,$pathname) = 650($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/); 651 652# first, analyze the 'current' part 653if(defined$pathname) { 654# we got "branch:filename" or "branch:dir/" 655# we could use git_get_type(branch:pathname), but: 656# - it needs $git_dir 657# - it does a git() call 658# - the convention of terminating directories with a slash 659# makes it superfluous 660# - embedding the action in the PATH_INFO would make it even 661# more superfluous 662$pathname=~ s,^/+,,; 663if(!$pathname||substr($pathname, -1)eq"/") { 664$input_params{'action'} ||="tree"; 665$pathname=~ s,/$,,; 666}else{ 667# the default action depends on whether we had parent info 668# or not 669if($parentrefname) { 670$input_params{'action'} ||="blobdiff_plain"; 671}else{ 672$input_params{'action'} ||="blob_plain"; 673} 674} 675$input_params{'hash_base'} ||=$refname; 676$input_params{'file_name'} ||=$pathname; 677}elsif(defined$refname) { 678# we got "branch". In this case we have to choose if we have to 679# set hash or hash_base. 680# 681# Most of the actions without a pathname only want hash to be 682# set, except for the ones specified in @wants_base that want 683# hash_base instead. It should also be noted that hand-crafted 684# links having 'history' as an action and no pathname or hash 685# set will fail, but that happens regardless of PATH_INFO. 686$input_params{'action'} ||="shortlog"; 687if(grep{$_eq$input_params{'action'} }@wants_base) { 688$input_params{'hash_base'} ||=$refname; 689}else{ 690$input_params{'hash'} ||=$refname; 691} 692} 693 694# next, handle the 'parent' part, if present 695if(defined$parentrefname) { 696# a missing pathspec defaults to the 'current' filename, allowing e.g. 697# someproject/blobdiff/oldrev..newrev:/filename 698if($parentpathname) { 699$parentpathname=~ s,^/+,,; 700$parentpathname=~ s,/$,,; 701$input_params{'file_parent'} ||=$parentpathname; 702}else{ 703$input_params{'file_parent'} ||=$input_params{'file_name'}; 704} 705# we assume that hash_parent_base is wanted if a path was specified, 706# or if the action wants hash_base instead of hash 707if(defined$input_params{'file_parent'} || 708grep{$_eq$input_params{'action'} }@wants_base) { 709$input_params{'hash_parent_base'} ||=$parentrefname; 710}else{ 711$input_params{'hash_parent'} ||=$parentrefname; 712} 713} 714 715# for the snapshot action, we allow URLs in the form 716# $project/snapshot/$hash.ext 717# where .ext determines the snapshot and gets removed from the 718# passed $refname to provide the $hash. 719# 720# To be able to tell that $refname includes the format extension, we 721# require the following two conditions to be satisfied: 722# - the hash input parameter MUST have been set from the $refname part 723# of the URL (i.e. they must be equal) 724# - the snapshot format MUST NOT have been defined already (e.g. from 725# CGI parameter sf) 726# It's also useless to try any matching unless $refname has a dot, 727# so we check for that too 728if(defined$input_params{'action'} && 729$input_params{'action'}eq'snapshot'&& 730defined$refname&&index($refname,'.') != -1&& 731$refnameeq$input_params{'hash'} && 732!defined$input_params{'snapshot_format'}) { 733# We loop over the known snapshot formats, checking for 734# extensions. Allowed extensions are both the defined suffix 735# (which includes the initial dot already) and the snapshot 736# format key itself, with a prepended dot 737while(my($fmt,$opt) =each%known_snapshot_formats) { 738my$hash=$refname; 739unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 740next; 741} 742my$sfx=$1; 743# a valid suffix was found, so set the snapshot format 744# and reset the hash parameter 745$input_params{'snapshot_format'} =$fmt; 746$input_params{'hash'} =$hash; 747# we also set the format suffix to the one requested 748# in the URL: this way a request for e.g. .tgz returns 749# a .tgz instead of a .tar.gz 750$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 751last; 752} 753} 754} 755evaluate_path_info(); 756 757our$action=$input_params{'action'}; 758if(defined$action) { 759if(!validate_action($action)) { 760 die_error(400,"Invalid action parameter"); 761} 762} 763 764# parameters which are pathnames 765our$project=$input_params{'project'}; 766if(defined$project) { 767if(!validate_project($project)) { 768undef$project; 769 die_error(404,"No such project"); 770} 771} 772 773our$file_name=$input_params{'file_name'}; 774if(defined$file_name) { 775if(!validate_pathname($file_name)) { 776 die_error(400,"Invalid file parameter"); 777} 778} 779 780our$file_parent=$input_params{'file_parent'}; 781if(defined$file_parent) { 782if(!validate_pathname($file_parent)) { 783 die_error(400,"Invalid file parent parameter"); 784} 785} 786 787# parameters which are refnames 788our$hash=$input_params{'hash'}; 789if(defined$hash) { 790if(!validate_refname($hash)) { 791 die_error(400,"Invalid hash parameter"); 792} 793} 794 795our$hash_parent=$input_params{'hash_parent'}; 796if(defined$hash_parent) { 797if(!validate_refname($hash_parent)) { 798 die_error(400,"Invalid hash parent parameter"); 799} 800} 801 802our$hash_base=$input_params{'hash_base'}; 803if(defined$hash_base) { 804if(!validate_refname($hash_base)) { 805 die_error(400,"Invalid hash base parameter"); 806} 807} 808 809our@extra_options= @{$input_params{'extra_options'}}; 810# @extra_options is always defined, since it can only be (currently) set from 811# CGI, and $cgi->param() returns the empty array in array context if the param 812# is not set 813foreachmy$opt(@extra_options) { 814if(not exists$allowed_options{$opt}) { 815 die_error(400,"Invalid option parameter"); 816} 817if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 818 die_error(400,"Invalid option parameter for this action"); 819} 820} 821 822our$hash_parent_base=$input_params{'hash_parent_base'}; 823if(defined$hash_parent_base) { 824if(!validate_refname($hash_parent_base)) { 825 die_error(400,"Invalid hash parent base parameter"); 826} 827} 828 829# other parameters 830our$page=$input_params{'page'}; 831if(defined$page) { 832if($page=~m/[^0-9]/) { 833 die_error(400,"Invalid page parameter"); 834} 835} 836 837our$searchtype=$input_params{'searchtype'}; 838if(defined$searchtype) { 839if($searchtype=~m/[^a-z]/) { 840 die_error(400,"Invalid searchtype parameter"); 841} 842} 843 844our$search_use_regexp=$input_params{'search_use_regexp'}; 845 846our$searchtext=$input_params{'searchtext'}; 847our$search_regexp; 848if(defined$searchtext) { 849if(length($searchtext) <2) { 850 die_error(403,"At least two characters are required for search parameter"); 851} 852$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 853} 854 855# path to the current git repository 856our$git_dir; 857$git_dir="$projectroot/$project"if$project; 858 859# list of supported snapshot formats 860our@snapshot_fmts= gitweb_get_feature('snapshot'); 861@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts); 862 863# check that the avatar feature is set to a known provider name, 864# and for each provider check if the dependencies are satisfied. 865# if the provider name is invalid or the dependencies are not met, 866# reset $git_avatar to the empty string. 867our($git_avatar) = gitweb_get_feature('avatar'); 868if($git_avatareq'gravatar') { 869$git_avatar=''unless(eval{require Digest::MD5;1; }); 870}elsif($git_avatareq'picon') { 871# no dependencies 872}else{ 873$git_avatar=''; 874} 875 876# dispatch 877if(!defined$action) { 878if(defined$hash) { 879$action= git_get_type($hash); 880}elsif(defined$hash_base&&defined$file_name) { 881$action= git_get_type("$hash_base:$file_name"); 882}elsif(defined$project) { 883$action='summary'; 884}else{ 885$action='project_list'; 886} 887} 888if(!defined($actions{$action})) { 889 die_error(400,"Unknown action"); 890} 891if($action!~m/^(?:opml|project_list|project_index)$/&& 892!$project) { 893 die_error(400,"Project needed"); 894} 895$actions{$action}->(); 896exit; 897 898## ====================================================================== 899## action links 900 901sub href { 902my%params=@_; 903# default is to use -absolute url() i.e. $my_uri 904my$href=$params{-full} ?$my_url:$my_uri; 905 906$params{'project'} =$projectunlessexists$params{'project'}; 907 908if($params{-replay}) { 909while(my($name,$symbol) =each%cgi_param_mapping) { 910if(!exists$params{$name}) { 911$params{$name} =$input_params{$name}; 912} 913} 914} 915 916my$use_pathinfo= gitweb_check_feature('pathinfo'); 917if($use_pathinfoand defined$params{'project'}) { 918# try to put as many parameters as possible in PATH_INFO: 919# - project name 920# - action 921# - hash_parent or hash_parent_base:/file_parent 922# - hash or hash_base:/filename 923# - the snapshot_format as an appropriate suffix 924 925# When the script is the root DirectoryIndex for the domain, 926# $href here would be something like http://gitweb.example.com/ 927# Thus, we strip any trailing / from $href, to spare us double 928# slashes in the final URL 929$href=~ s,/$,,; 930 931# Then add the project name, if present 932$href.="/".esc_url($params{'project'}); 933delete$params{'project'}; 934 935# since we destructively absorb parameters, we keep this 936# boolean that remembers if we're handling a snapshot 937my$is_snapshot=$params{'action'}eq'snapshot'; 938 939# Summary just uses the project path URL, any other action is 940# added to the URL 941if(defined$params{'action'}) { 942$href.="/".esc_url($params{'action'})unless$params{'action'}eq'summary'; 943delete$params{'action'}; 944} 945 946# Next, we put hash_parent_base:/file_parent..hash_base:/file_name, 947# stripping nonexistent or useless pieces 948$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'} 949||$params{'hash_parent'} ||$params{'hash'}); 950if(defined$params{'hash_base'}) { 951if(defined$params{'hash_parent_base'}) { 952$href.= esc_url($params{'hash_parent_base'}); 953# skip the file_parent if it's the same as the file_name 954if(defined$params{'file_parent'}) { 955if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) { 956delete$params{'file_parent'}; 957}elsif($params{'file_parent'} !~/\.\./) { 958$href.=":/".esc_url($params{'file_parent'}); 959delete$params{'file_parent'}; 960} 961} 962$href.=".."; 963delete$params{'hash_parent'}; 964delete$params{'hash_parent_base'}; 965}elsif(defined$params{'hash_parent'}) { 966$href.= esc_url($params{'hash_parent'}).".."; 967delete$params{'hash_parent'}; 968} 969 970$href.= esc_url($params{'hash_base'}); 971if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) { 972$href.=":/".esc_url($params{'file_name'}); 973delete$params{'file_name'}; 974} 975delete$params{'hash'}; 976delete$params{'hash_base'}; 977}elsif(defined$params{'hash'}) { 978$href.= esc_url($params{'hash'}); 979delete$params{'hash'}; 980} 981 982# If the action was a snapshot, we can absorb the 983# snapshot_format parameter too 984if($is_snapshot) { 985my$fmt=$params{'snapshot_format'}; 986# snapshot_format should always be defined when href() 987# is called, but just in case some code forgets, we 988# fall back to the default 989$fmt||=$snapshot_fmts[0]; 990$href.=$known_snapshot_formats{$fmt}{'suffix'}; 991delete$params{'snapshot_format'}; 992} 993} 994 995# now encode the parameters explicitly 996my@result= (); 997for(my$i=0;$i<@cgi_param_mapping;$i+=2) { 998my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]); 999if(defined$params{$name}) {1000if(ref($params{$name})eq"ARRAY") {1001foreachmy$par(@{$params{$name}}) {1002push@result,$symbol."=". esc_param($par);1003}1004}else{1005push@result,$symbol."=". esc_param($params{$name});1006}1007}1008}1009$href.="?".join(';',@result)ifscalar@result;10101011return$href;1012}101310141015## ======================================================================1016## validation, quoting/unquoting and escaping10171018sub validate_action {1019my$input=shift||returnundef;1020returnundefunlessexists$actions{$input};1021return$input;1022}10231024sub validate_project {1025my$input=shift||returnundef;1026if(!validate_pathname($input) ||1027!(-d "$projectroot/$input") ||1028!check_export_ok("$projectroot/$input") ||1029($strict_export&& !project_in_list($input))) {1030returnundef;1031}else{1032return$input;1033}1034}10351036sub validate_pathname {1037my$input=shift||returnundef;10381039# no '.' or '..' as elements of path, i.e. no '.' nor '..'1040# at the beginning, at the end, and between slashes.1041# also this catches doubled slashes1042if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1043returnundef;1044}1045# no null characters1046if($input=~m!\0!) {1047returnundef;1048}1049return$input;1050}10511052sub validate_refname {1053my$input=shift||returnundef;10541055# textual hashes are O.K.1056if($input=~m/^[0-9a-fA-F]{40}$/) {1057return$input;1058}1059# it must be correct pathname1060$input= validate_pathname($input)1061orreturnundef;1062# restrictions on ref name according to git-check-ref-format1063if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1064returnundef;1065}1066return$input;1067}10681069# decode sequences of octets in utf8 into Perl's internal form,1070# which is utf-8 with utf8 flag set if needed. gitweb writes out1071# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1072sub to_utf8 {1073my$str=shift;1074if(utf8::valid($str)) {1075 utf8::decode($str);1076return$str;1077}else{1078return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1079}1080}10811082# quote unsafe chars, but keep the slash, even when it's not1083# correct, but quoted slashes look too horrible in bookmarks1084sub esc_param {1085my$str=shift;1086$str=~s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X",ord($1))/eg;1087$str=~s/\+/%2B/g;1088$str=~s/ /\+/g;1089return$str;1090}10911092# quote unsafe chars in whole URL, so some charactrs cannot be quoted1093sub esc_url {1094my$str=shift;1095$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X",ord($1))/eg;1096$str=~s/\+/%2B/g;1097$str=~s/ /\+/g;1098return$str;1099}11001101# replace invalid utf8 character with SUBSTITUTION sequence1102sub esc_html {1103my$str=shift;1104my%opts=@_;11051106$str= to_utf8($str);1107$str=$cgi->escapeHTML($str);1108if($opts{'-nbsp'}) {1109$str=~s/ / /g;1110}1111$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1112return$str;1113}11141115# quote control characters and escape filename to HTML1116sub esc_path {1117my$str=shift;1118my%opts=@_;11191120$str= to_utf8($str);1121$str=$cgi->escapeHTML($str);1122if($opts{'-nbsp'}) {1123$str=~s/ / /g;1124}1125$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1126return$str;1127}11281129# Make control characters "printable", using character escape codes (CEC)1130sub quot_cec {1131my$cntrl=shift;1132my%opts=@_;1133my%es= (# character escape codes, aka escape sequences1134"\t"=>'\t',# tab (HT)1135"\n"=>'\n',# line feed (LF)1136"\r"=>'\r',# carrige return (CR)1137"\f"=>'\f',# form feed (FF)1138"\b"=>'\b',# backspace (BS)1139"\a"=>'\a',# alarm (bell) (BEL)1140"\e"=>'\e',# escape (ESC)1141"\013"=>'\v',# vertical tab (VT)1142"\000"=>'\0',# nul character (NUL)1143);1144my$chr= ( (exists$es{$cntrl})1145?$es{$cntrl}1146:sprintf('\%2x',ord($cntrl)) );1147if($opts{-nohtml}) {1148return$chr;1149}else{1150return"<span class=\"cntrl\">$chr</span>";1151}1152}11531154# Alternatively use unicode control pictures codepoints,1155# Unicode "printable representation" (PR)1156sub quot_upr {1157my$cntrl=shift;1158my%opts=@_;11591160my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1161if($opts{-nohtml}) {1162return$chr;1163}else{1164return"<span class=\"cntrl\">$chr</span>";1165}1166}11671168# git may return quoted and escaped filenames1169sub unquote {1170my$str=shift;11711172sub unq {1173my$seq=shift;1174my%es= (# character escape codes, aka escape sequences1175't'=>"\t",# tab (HT, TAB)1176'n'=>"\n",# newline (NL)1177'r'=>"\r",# return (CR)1178'f'=>"\f",# form feed (FF)1179'b'=>"\b",# backspace (BS)1180'a'=>"\a",# alarm (bell) (BEL)1181'e'=>"\e",# escape (ESC)1182'v'=>"\013",# vertical tab (VT)1183);11841185if($seq=~m/^[0-7]{1,3}$/) {1186# octal char sequence1187returnchr(oct($seq));1188}elsif(exists$es{$seq}) {1189# C escape sequence, aka character escape code1190return$es{$seq};1191}1192# quoted ordinary character1193return$seq;1194}11951196if($str=~m/^"(.*)"$/) {1197# needs unquoting1198$str=$1;1199$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1200}1201return$str;1202}12031204# escape tabs (convert tabs to spaces)1205sub untabify {1206my$line=shift;12071208while((my$pos=index($line,"\t")) != -1) {1209if(my$count= (8- ($pos%8))) {1210my$spaces=' ' x $count;1211$line=~s/\t/$spaces/;1212}1213}12141215return$line;1216}12171218sub project_in_list {1219my$project=shift;1220my@list= git_get_projects_list();1221return@list&&scalar(grep{$_->{'path'}eq$project}@list);1222}12231224## ----------------------------------------------------------------------1225## HTML aware string manipulation12261227# Try to chop given string on a word boundary between position1228# $len and $len+$add_len. If there is no word boundary there,1229# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1230# (marking chopped part) would be longer than given string.1231sub chop_str {1232my$str=shift;1233my$len=shift;1234my$add_len=shift||10;1235my$where=shift||'right';# 'left' | 'center' | 'right'12361237# Make sure perl knows it is utf8 encoded so we don't1238# cut in the middle of a utf8 multibyte char.1239$str= to_utf8($str);12401241# allow only $len chars, but don't cut a word if it would fit in $add_len1242# if it doesn't fit, cut it if it's still longer than the dots we would add1243# remove chopped character entities entirely12441245# when chopping in the middle, distribute $len into left and right part1246# return early if chopping wouldn't make string shorter1247if($whereeq'center') {1248return$strif($len+5>=length($str));# filler is length 51249$len=int($len/2);1250}else{1251return$strif($len+4>=length($str));# filler is length 41252}12531254# regexps: ending and beginning with word part up to $add_len1255my$endre=qr/.{$len}\w{0,$add_len}/;1256my$begre=qr/\w{0,$add_len}.{$len}/;12571258if($whereeq'left') {1259$str=~m/^(.*?)($begre)$/;1260my($lead,$body) = ($1,$2);1261if(length($lead) >4) {1262$body=~s/^[^;]*;//if($lead=~m/&[^;]*$/);1263$lead=" ...";1264}1265return"$lead$body";12661267}elsif($whereeq'center') {1268$str=~m/^($endre)(.*)$/;1269my($left,$str) = ($1,$2);1270$str=~m/^(.*?)($begre)$/;1271my($mid,$right) = ($1,$2);1272if(length($mid) >5) {1273$left=~s/&[^;]*$//;1274$right=~s/^[^;]*;//if($mid=~m/&[^;]*$/);1275$mid=" ... ";1276}1277return"$left$mid$right";12781279}else{1280$str=~m/^($endre)(.*)$/;1281my$body=$1;1282my$tail=$2;1283if(length($tail) >4) {1284$body=~s/&[^;]*$//;1285$tail="... ";1286}1287return"$body$tail";1288}1289}12901291# takes the same arguments as chop_str, but also wraps a <span> around the1292# result with a title attribute if it does get chopped. Additionally, the1293# string is HTML-escaped.1294sub chop_and_escape_str {1295my($str) =@_;12961297my$chopped= chop_str(@_);1298if($choppedeq$str) {1299return esc_html($chopped);1300}else{1301$str=~s/[[:cntrl:]]/?/g;1302return$cgi->span({-title=>$str}, esc_html($chopped));1303}1304}13051306## ----------------------------------------------------------------------1307## functions returning short strings13081309# CSS class for given age value (in seconds)1310sub age_class {1311my$age=shift;13121313if(!defined$age) {1314return"noage";1315}elsif($age<60*60*2) {1316return"age0";1317}elsif($age<60*60*24*2) {1318return"age1";1319}else{1320return"age2";1321}1322}13231324# convert age in seconds to "nn units ago" string1325sub age_string {1326my$age=shift;1327my$age_str;13281329if($age>60*60*24*365*2) {1330$age_str= (int$age/60/60/24/365);1331$age_str.=" years ago";1332}elsif($age>60*60*24*(365/12)*2) {1333$age_str=int$age/60/60/24/(365/12);1334$age_str.=" months ago";1335}elsif($age>60*60*24*7*2) {1336$age_str=int$age/60/60/24/7;1337$age_str.=" weeks ago";1338}elsif($age>60*60*24*2) {1339$age_str=int$age/60/60/24;1340$age_str.=" days ago";1341}elsif($age>60*60*2) {1342$age_str=int$age/60/60;1343$age_str.=" hours ago";1344}elsif($age>60*2) {1345$age_str=int$age/60;1346$age_str.=" min ago";1347}elsif($age>2) {1348$age_str=int$age;1349$age_str.=" sec ago";1350}else{1351$age_str.=" right now";1352}1353return$age_str;1354}13551356useconstant{1357 S_IFINVALID =>0030000,1358 S_IFGITLINK =>0160000,1359};13601361# submodule/subproject, a commit object reference1362sub S_ISGITLINK {1363my$mode=shift;13641365return(($mode& S_IFMT) == S_IFGITLINK)1366}13671368# convert file mode in octal to symbolic file mode string1369sub mode_str {1370my$mode=oct shift;13711372if(S_ISGITLINK($mode)) {1373return'm---------';1374}elsif(S_ISDIR($mode& S_IFMT)) {1375return'drwxr-xr-x';1376}elsif(S_ISLNK($mode)) {1377return'lrwxrwxrwx';1378}elsif(S_ISREG($mode)) {1379# git cares only about the executable bit1380if($mode& S_IXUSR) {1381return'-rwxr-xr-x';1382}else{1383return'-rw-r--r--';1384};1385}else{1386return'----------';1387}1388}13891390# convert file mode in octal to file type string1391sub file_type {1392my$mode=shift;13931394if($mode!~m/^[0-7]+$/) {1395return$mode;1396}else{1397$mode=oct$mode;1398}13991400if(S_ISGITLINK($mode)) {1401return"submodule";1402}elsif(S_ISDIR($mode& S_IFMT)) {1403return"directory";1404}elsif(S_ISLNK($mode)) {1405return"symlink";1406}elsif(S_ISREG($mode)) {1407return"file";1408}else{1409return"unknown";1410}1411}14121413# convert file mode in octal to file type description string1414sub file_type_long {1415my$mode=shift;14161417if($mode!~m/^[0-7]+$/) {1418return$mode;1419}else{1420$mode=oct$mode;1421}14221423if(S_ISGITLINK($mode)) {1424return"submodule";1425}elsif(S_ISDIR($mode& S_IFMT)) {1426return"directory";1427}elsif(S_ISLNK($mode)) {1428return"symlink";1429}elsif(S_ISREG($mode)) {1430if($mode& S_IXUSR) {1431return"executable";1432}else{1433return"file";1434};1435}else{1436return"unknown";1437}1438}143914401441## ----------------------------------------------------------------------1442## functions returning short HTML fragments, or transforming HTML fragments1443## which don't belong to other sections14441445# format line of commit message.1446sub format_log_line_html {1447my$line=shift;14481449$line= esc_html($line, -nbsp=>1);1450$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1451$cgi->a({-href => href(action=>"object", hash=>$1),1452-class=>"text"},$1);1453}eg;14541455return$line;1456}14571458# format marker of refs pointing to given object14591460# the destination action is chosen based on object type and current context:1461# - for annotated tags, we choose the tag view unless it's the current view1462# already, in which case we go to shortlog view1463# - for other refs, we keep the current view if we're in history, shortlog or1464# log view, and select shortlog otherwise1465sub format_ref_marker {1466my($refs,$id) =@_;1467my$markers='';14681469if(defined$refs->{$id}) {1470foreachmy$ref(@{$refs->{$id}}) {1471# this code exploits the fact that non-lightweight tags are the1472# only indirect objects, and that they are the only objects for which1473# we want to use tag instead of shortlog as action1474my($type,$name) =qw();1475my$indirect= ($ref=~s/\^\{\}$//);1476# e.g. tags/v2.6.11 or heads/next1477if($ref=~m!^(.*?)s?/(.*)$!) {1478$type=$1;1479$name=$2;1480}else{1481$type="ref";1482$name=$ref;1483}14841485my$class=$type;1486$class.=" indirect"if$indirect;14871488my$dest_action="shortlog";14891490if($indirect) {1491$dest_action="tag"unless$actioneq"tag";1492}elsif($action=~/^(history|(short)?log)$/) {1493$dest_action=$action;1494}14951496my$dest="";1497$dest.="refs/"unless$ref=~ m!^refs/!;1498$dest.=$ref;14991500my$link=$cgi->a({1501-href => href(1502 action=>$dest_action,1503 hash=>$dest1504)},$name);15051506$markers.=" <span class=\"$class\"title=\"$ref\">".1507$link."</span>";1508}1509}15101511if($markers) {1512return' <span class="refs">'.$markers.'</span>';1513}else{1514return"";1515}1516}15171518# format, perhaps shortened and with markers, title line1519sub format_subject_html {1520my($long,$short,$href,$extra) =@_;1521$extra=''unlessdefined($extra);15221523if(length($short) <length($long)) {1524$long=~s/[[:cntrl:]]/?/g;1525return$cgi->a({-href =>$href, -class=>"list subject",1526-title => to_utf8($long)},1527 esc_html($short)) .$extra;1528}else{1529return$cgi->a({-href =>$href, -class=>"list subject"},1530 esc_html($long)) .$extra;1531}1532}15331534# Rather than recomputing the url for an email multiple times, we cache it1535# after the first hit. This gives a visible benefit in views where the avatar1536# for the same email is used repeatedly (e.g. shortlog).1537# The cache is shared by all avatar engines (currently gravatar only), which1538# are free to use it as preferred. Since only one avatar engine is used for any1539# given page, there's no risk for cache conflicts.1540our%avatar_cache= ();15411542# Compute the picon url for a given email, by using the picon search service over at1543# http://www.cs.indiana.edu/picons/search.html1544sub picon_url {1545my$email=lc shift;1546if(!$avatar_cache{$email}) {1547my($user,$domain) =split('@',$email);1548$avatar_cache{$email} =1549"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".1550"$domain/$user/".1551"users+domains+unknown/up/single";1552}1553return$avatar_cache{$email};1554}15551556# Compute the gravatar url for a given email, if it's not in the cache already.1557# Gravatar stores only the part of the URL before the size, since that's the1558# one computationally more expensive. This also allows reuse of the cache for1559# different sizes (for this particular engine).1560sub gravatar_url {1561my$email=lc shift;1562my$size=shift;1563$avatar_cache{$email} ||=1564"http://www.gravatar.com/avatar/".1565 Digest::MD5::md5_hex($email) ."?s=";1566return$avatar_cache{$email} .$size;1567}15681569# Insert an avatar for the given $email at the given $size if the feature1570# is enabled.1571sub git_get_avatar {1572my($email,%opts) =@_;1573my$pre_white= ($opts{-pad_before} ?" ":"");1574my$post_white= ($opts{-pad_after} ?" ":"");1575$opts{-size} ||='default';1576my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};1577my$url="";1578if($git_avatareq'gravatar') {1579$url= gravatar_url($email,$size);1580}elsif($git_avatareq'picon') {1581$url= picon_url($email);1582}1583# Other providers can be added by extending the if chain, defining $url1584# as needed. If no variant puts something in $url, we assume avatars1585# are completely disabled/unavailable.1586if($url) {1587return$pre_white.1588"<img width=\"$size\"".1589"class=\"avatar\"".1590"src=\"$url\"".1591"alt=\"\"".1592"/>".$post_white;1593}else{1594return"";1595}1596}15971598# format the author name of the given commit with the given tag1599# the author name is chopped and escaped according to the other1600# optional parameters (see chop_str).1601sub format_author_html {1602my$tag=shift;1603my$co=shift;1604my$author= chop_and_escape_str($co->{'author_name'},@_);1605return"<$tagclass=\"author\">".1606 git_get_avatar($co->{'author_email'}, -pad_after =>1) .1607$author."</$tag>";1608}16091610# format git diff header line, i.e. "diff --(git|combined|cc) ..."1611sub format_git_diff_header_line {1612my$line=shift;1613my$diffinfo=shift;1614my($from,$to) =@_;16151616if($diffinfo->{'nparents'}) {1617# combined diff1618$line=~s!^(diff (.*?) )"?.*$!$1!;1619if($to->{'href'}) {1620$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1621 esc_path($to->{'file'}));1622}else{# file was deleted (no href)1623$line.= esc_path($to->{'file'});1624}1625}else{1626# "ordinary" diff1627$line=~s!^(diff (.*?) )"?a/.*$!$1!;1628if($from->{'href'}) {1629$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1630'a/'. esc_path($from->{'file'}));1631}else{# file was added (no href)1632$line.='a/'. esc_path($from->{'file'});1633}1634$line.=' ';1635if($to->{'href'}) {1636$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1637'b/'. esc_path($to->{'file'}));1638}else{# file was deleted1639$line.='b/'. esc_path($to->{'file'});1640}1641}16421643return"<div class=\"diff header\">$line</div>\n";1644}16451646# format extended diff header line, before patch itself1647sub format_extended_diff_header_line {1648my$line=shift;1649my$diffinfo=shift;1650my($from,$to) =@_;16511652# match <path>1653if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1654$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1655 esc_path($from->{'file'}));1656}1657if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1658$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1659 esc_path($to->{'file'}));1660}1661# match single <mode>1662if($line=~m/\s(\d{6})$/) {1663$line.='<span class="info"> ('.1664 file_type_long($1) .1665')</span>';1666}1667# match <hash>1668if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1669# can match only for combined diff1670$line='index ';1671for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1672if($from->{'href'}[$i]) {1673$line.=$cgi->a({-href=>$from->{'href'}[$i],1674-class=>"hash"},1675substr($diffinfo->{'from_id'}[$i],0,7));1676}else{1677$line.='0' x 7;1678}1679# separator1680$line.=','if($i<$diffinfo->{'nparents'} -1);1681}1682$line.='..';1683if($to->{'href'}) {1684$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1685substr($diffinfo->{'to_id'},0,7));1686}else{1687$line.='0' x 7;1688}16891690}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1691# can match only for ordinary diff1692my($from_link,$to_link);1693if($from->{'href'}) {1694$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1695substr($diffinfo->{'from_id'},0,7));1696}else{1697$from_link='0' x 7;1698}1699if($to->{'href'}) {1700$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1701substr($diffinfo->{'to_id'},0,7));1702}else{1703$to_link='0' x 7;1704}1705my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1706$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1707}17081709return$line."<br/>\n";1710}17111712# format from-file/to-file diff header1713sub format_diff_from_to_header {1714my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1715my$line;1716my$result='';17171718$line=$from_line;1719#assert($line =~ m/^---/) if DEBUG;1720# no extra formatting for "^--- /dev/null"1721if(!$diffinfo->{'nparents'}) {1722# ordinary (single parent) diff1723if($line=~m!^--- "?a/!) {1724if($from->{'href'}) {1725$line='--- a/'.1726$cgi->a({-href=>$from->{'href'}, -class=>"path"},1727 esc_path($from->{'file'}));1728}else{1729$line='--- a/'.1730 esc_path($from->{'file'});1731}1732}1733$result.= qq!<div class="diff from_file">$line</div>\n!;17341735}else{1736# combined diff (merge commit)1737for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1738if($from->{'href'}[$i]) {1739$line='--- '.1740$cgi->a({-href=>href(action=>"blobdiff",1741 hash_parent=>$diffinfo->{'from_id'}[$i],1742 hash_parent_base=>$parents[$i],1743 file_parent=>$from->{'file'}[$i],1744 hash=>$diffinfo->{'to_id'},1745 hash_base=>$hash,1746 file_name=>$to->{'file'}),1747-class=>"path",1748-title=>"diff". ($i+1)},1749$i+1) .1750'/'.1751$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1752 esc_path($from->{'file'}[$i]));1753}else{1754$line='--- /dev/null';1755}1756$result.= qq!<div class="diff from_file">$line</div>\n!;1757}1758}17591760$line=$to_line;1761#assert($line =~ m/^\+\+\+/) if DEBUG;1762# no extra formatting for "^+++ /dev/null"1763if($line=~m!^\+\+\+ "?b/!) {1764if($to->{'href'}) {1765$line='+++ b/'.1766$cgi->a({-href=>$to->{'href'}, -class=>"path"},1767 esc_path($to->{'file'}));1768}else{1769$line='+++ b/'.1770 esc_path($to->{'file'});1771}1772}1773$result.= qq!<div class="diff to_file">$line</div>\n!;17741775return$result;1776}17771778# create note for patch simplified by combined diff1779sub format_diff_cc_simplified {1780my($diffinfo,@parents) =@_;1781my$result='';17821783$result.="<div class=\"diff header\">".1784"diff --cc ";1785if(!is_deleted($diffinfo)) {1786$result.=$cgi->a({-href => href(action=>"blob",1787 hash_base=>$hash,1788 hash=>$diffinfo->{'to_id'},1789 file_name=>$diffinfo->{'to_file'}),1790-class=>"path"},1791 esc_path($diffinfo->{'to_file'}));1792}else{1793$result.= esc_path($diffinfo->{'to_file'});1794}1795$result.="</div>\n".# class="diff header"1796"<div class=\"diff nodifferences\">".1797"Simple merge".1798"</div>\n";# class="diff nodifferences"17991800return$result;1801}18021803# format patch (diff) line (not to be used for diff headers)1804sub format_diff_line {1805my$line=shift;1806my($from,$to) =@_;1807my$diff_class="";18081809chomp$line;18101811if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1812# combined diff1813my$prefix=substr($line,0,scalar@{$from->{'href'}});1814if($line=~m/^\@{3}/) {1815$diff_class=" chunk_header";1816}elsif($line=~m/^\\/) {1817$diff_class=" incomplete";1818}elsif($prefix=~tr/+/+/) {1819$diff_class=" add";1820}elsif($prefix=~tr/-/-/) {1821$diff_class=" rem";1822}1823}else{1824# assume ordinary diff1825my$char=substr($line,0,1);1826if($chareq'+') {1827$diff_class=" add";1828}elsif($chareq'-') {1829$diff_class=" rem";1830}elsif($chareq'@') {1831$diff_class=" chunk_header";1832}elsif($chareq"\\") {1833$diff_class=" incomplete";1834}1835}1836$line= untabify($line);1837if($from&&$to&&$line=~m/^\@{2} /) {1838my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1839$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;18401841$from_lines=0unlessdefined$from_lines;1842$to_lines=0unlessdefined$to_lines;18431844if($from->{'href'}) {1845$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1846-class=>"list"},$from_text);1847}1848if($to->{'href'}) {1849$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1850-class=>"list"},$to_text);1851}1852$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1853"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1854return"<div class=\"diff$diff_class\">$line</div>\n";1855}elsif($from&&$to&&$line=~m/^\@{3}/) {1856my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1857my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);18581859@from_text=split(' ',$ranges);1860for(my$i=0;$i<@from_text; ++$i) {1861($from_start[$i],$from_nlines[$i]) =1862(split(',',substr($from_text[$i],1)),0);1863}18641865$to_text=pop@from_text;1866$to_start=pop@from_start;1867$to_nlines=pop@from_nlines;18681869$line="<span class=\"chunk_info\">$prefix";1870for(my$i=0;$i<@from_text; ++$i) {1871if($from->{'href'}[$i]) {1872$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1873-class=>"list"},$from_text[$i]);1874}else{1875$line.=$from_text[$i];1876}1877$line.=" ";1878}1879if($to->{'href'}) {1880$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1881-class=>"list"},$to_text);1882}else{1883$line.=$to_text;1884}1885$line.="$prefix</span>".1886"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1887return"<div class=\"diff$diff_class\">$line</div>\n";1888}1889return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1890}18911892# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1893# linked. Pass the hash of the tree/commit to snapshot.1894sub format_snapshot_links {1895my($hash) =@_;1896my$num_fmts=@snapshot_fmts;1897if($num_fmts>1) {1898# A parenthesized list of links bearing format names.1899# e.g. "snapshot (_tar.gz_ _zip_)"1900return"snapshot (".join(' ',map1901$cgi->a({1902-href => href(1903 action=>"snapshot",1904 hash=>$hash,1905 snapshot_format=>$_1906)1907},$known_snapshot_formats{$_}{'display'})1908,@snapshot_fmts) .")";1909}elsif($num_fmts==1) {1910# A single "snapshot" link whose tooltip bears the format name.1911# i.e. "_snapshot_"1912my($fmt) =@snapshot_fmts;1913return1914$cgi->a({1915-href => href(1916 action=>"snapshot",1917 hash=>$hash,1918 snapshot_format=>$fmt1919),1920-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"1921},"snapshot");1922}else{# $num_fmts == 01923returnundef;1924}1925}19261927## ......................................................................1928## functions returning values to be passed, perhaps after some1929## transformation, to other functions; e.g. returning arguments to href()19301931# returns hash to be passed to href to generate gitweb URL1932# in -title key it returns description of link1933sub get_feed_info {1934my$format=shift||'Atom';1935my%res= (action =>lc($format));19361937# feed links are possible only for project views1938return unless(defined$project);1939# some views should link to OPML, or to generic project feed,1940# or don't have specific feed yet (so they should use generic)1941return if($action=~/^(?:tags|heads|forks|tag|search)$/x);19421943my$branch;1944# branches refs uses 'refs/heads/' prefix (fullname) to differentiate1945# from tag links; this also makes possible to detect branch links1946if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||1947(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {1948$branch=$1;1949}1950# find log type for feed description (title)1951my$type='log';1952if(defined$file_name) {1953$type="history of$file_name";1954$type.="/"if($actioneq'tree');1955$type.=" on '$branch'"if(defined$branch);1956}else{1957$type="log of$branch"if(defined$branch);1958}19591960$res{-title} =$type;1961$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);1962$res{'file_name'} =$file_name;19631964return%res;1965}19661967## ----------------------------------------------------------------------1968## git utility subroutines, invoking git commands19691970# returns path to the core git executable and the --git-dir parameter as list1971sub git_cmd {1972return$GIT,'--git-dir='.$git_dir;1973}19741975# quote the given arguments for passing them to the shell1976# quote_command("command", "arg 1", "arg with ' and ! characters")1977# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"1978# Try to avoid using this function wherever possible.1979sub quote_command {1980returnjoin(' ',1981map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);1982}19831984# get HEAD ref of given project as hash1985sub git_get_head_hash {1986return git_get_full_hash(shift,'HEAD');1987}19881989sub git_get_full_hash {1990return git_get_hash(@_);1991}19921993sub git_get_short_hash {1994return git_get_hash(@_,'--short=7');1995}19961997sub git_get_hash {1998my($project,$hash,@options) =@_;1999my$o_git_dir=$git_dir;2000my$retval=undef;2001$git_dir="$projectroot/$project";2002if(open my$fd,'-|', git_cmd(),'rev-parse',2003'--verify','-q',@options,$hash) {2004$retval= <$fd>;2005chomp$retvalifdefined$retval;2006close$fd;2007}2008if(defined$o_git_dir) {2009$git_dir=$o_git_dir;2010}2011return$retval;2012}20132014# get type of given object2015sub git_get_type {2016my$hash=shift;20172018open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2019my$type= <$fd>;2020close$fdorreturn;2021chomp$type;2022return$type;2023}20242025# repository configuration2026our$config_file='';2027our%config;20282029# store multiple values for single key as anonymous array reference2030# single values stored directly in the hash, not as [ <value> ]2031sub hash_set_multi {2032my($hash,$key,$value) =@_;20332034if(!exists$hash->{$key}) {2035$hash->{$key} =$value;2036}elsif(!ref$hash->{$key}) {2037$hash->{$key} = [$hash->{$key},$value];2038}else{2039push@{$hash->{$key}},$value;2040}2041}20422043# return hash of git project configuration2044# optionally limited to some section, e.g. 'gitweb'2045sub git_parse_project_config {2046my$section_regexp=shift;2047my%config;20482049local$/="\0";20502051open my$fh,"-|", git_cmd(),"config",'-z','-l',2052orreturn;20532054while(my$keyval= <$fh>) {2055chomp$keyval;2056my($key,$value) =split(/\n/,$keyval,2);20572058 hash_set_multi(\%config,$key,$value)2059if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2060}2061close$fh;20622063return%config;2064}20652066# convert config value to boolean: 'true' or 'false'2067# no value, number > 0, 'true' and 'yes' values are true2068# rest of values are treated as false (never as error)2069sub config_to_bool {2070my$val=shift;20712072return1if!defined$val;# section.key20732074# strip leading and trailing whitespace2075$val=~s/^\s+//;2076$val=~s/\s+$//;20772078return(($val=~/^\d+$/&&$val) ||# section.key = 12079($val=~/^(?:true|yes)$/i));# section.key = true2080}20812082# convert config value to simple decimal number2083# an optional value suffix of 'k', 'm', or 'g' will cause the value2084# to be multiplied by 1024, 1048576, or 10737418242085sub config_to_int {2086my$val=shift;20872088# strip leading and trailing whitespace2089$val=~s/^\s+//;2090$val=~s/\s+$//;20912092if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2093$unit=lc($unit);2094# unknown unit is treated as 12095return$num* ($uniteq'g'?1073741824:2096$uniteq'm'?1048576:2097$uniteq'k'?1024:1);2098}2099return$val;2100}21012102# convert config value to array reference, if needed2103sub config_to_multi {2104my$val=shift;21052106returnref($val) ?$val: (defined($val) ? [$val] : []);2107}21082109sub git_get_project_config {2110my($key,$type) =@_;21112112# key sanity check2113return unless($key);2114$key=~s/^gitweb\.//;2115return if($key=~m/\W/);21162117# type sanity check2118if(defined$type) {2119$type=~s/^--//;2120$type=undef2121unless($typeeq'bool'||$typeeq'int');2122}21232124# get config2125if(!defined$config_file||2126$config_filene"$git_dir/config") {2127%config= git_parse_project_config('gitweb');2128$config_file="$git_dir/config";2129}21302131# check if config variable (key) exists2132return unlessexists$config{"gitweb.$key"};21332134# ensure given type2135if(!defined$type) {2136return$config{"gitweb.$key"};2137}elsif($typeeq'bool') {2138# backward compatibility: 'git config --bool' returns true/false2139return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2140}elsif($typeeq'int') {2141return config_to_int($config{"gitweb.$key"});2142}2143return$config{"gitweb.$key"};2144}21452146# get hash of given path at given ref2147sub git_get_hash_by_path {2148my$base=shift;2149my$path=shift||returnundef;2150my$type=shift;21512152$path=~ s,/+$,,;21532154open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2155or die_error(500,"Open git-ls-tree failed");2156my$line= <$fd>;2157close$fdorreturnundef;21582159if(!defined$line) {2160# there is no tree or hash given by $path at $base2161returnundef;2162}21632164#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2165$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2166if(defined$type&&$typene$2) {2167# type doesn't match2168returnundef;2169}2170return$3;2171}21722173# get path of entry with given hash at given tree-ish (ref)2174# used to get 'from' filename for combined diff (merge commit) for renames2175sub git_get_path_by_hash {2176my$base=shift||return;2177my$hash=shift||return;21782179local$/="\0";21802181open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2182orreturnundef;2183while(my$line= <$fd>) {2184chomp$line;21852186#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2187#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2188if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2189close$fd;2190return$1;2191}2192}2193close$fd;2194returnundef;2195}21962197## ......................................................................2198## git utility functions, directly accessing git repository21992200sub git_get_project_description {2201my$path=shift;22022203$git_dir="$projectroot/$path";2204open my$fd,'<',"$git_dir/description"2205orreturn git_get_project_config('description');2206my$descr= <$fd>;2207close$fd;2208if(defined$descr) {2209chomp$descr;2210}2211return$descr;2212}22132214sub git_get_project_ctags {2215my$path=shift;2216my$ctags= {};22172218$git_dir="$projectroot/$path";2219opendir my$dh,"$git_dir/ctags"2220orreturn$ctags;2221foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2222open my$ct,'<',$_ornext;2223my$val= <$ct>;2224chomp$val;2225close$ct;2226my$ctag=$_;$ctag=~ s#.*/##;2227$ctags->{$ctag} =$val;2228}2229closedir$dh;2230$ctags;2231}22322233sub git_populate_project_tagcloud {2234my$ctags=shift;22352236# First, merge different-cased tags; tags vote on casing2237my%ctags_lc;2238foreach(keys%$ctags) {2239$ctags_lc{lc$_}->{count} +=$ctags->{$_};2240if(not$ctags_lc{lc$_}->{topcount}2241or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2242$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2243$ctags_lc{lc$_}->{topname} =$_;2244}2245}22462247my$cloud;2248if(eval{require HTML::TagCloud;1; }) {2249$cloud= HTML::TagCloud->new;2250foreach(sort keys%ctags_lc) {2251# Pad the title with spaces so that the cloud looks2252# less crammed.2253my$title=$ctags_lc{$_}->{topname};2254$title=~s/ / /g;2255$title=~s/^/ /g;2256$title=~s/$/ /g;2257$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2258}2259}else{2260$cloud= \%ctags_lc;2261}2262$cloud;2263}22642265sub git_show_project_tagcloud {2266my($cloud,$count) =@_;2267print STDERR ref($cloud)."..\n";2268if(ref$cloudeq'HTML::TagCloud') {2269return$cloud->html_and_css($count);2270}else{2271my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2272return'<p align="center">'.join(', ',map{2273"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"2274}splice(@tags,0,$count)) .'</p>';2275}2276}22772278sub git_get_project_url_list {2279my$path=shift;22802281$git_dir="$projectroot/$path";2282open my$fd,'<',"$git_dir/cloneurl"2283orreturnwantarray?2284@{ config_to_multi(git_get_project_config('url')) } :2285 config_to_multi(git_get_project_config('url'));2286my@git_project_url_list=map{chomp;$_} <$fd>;2287close$fd;22882289returnwantarray?@git_project_url_list: \@git_project_url_list;2290}22912292sub git_get_projects_list {2293my($filter) =@_;2294my@list;22952296$filter||='';2297$filter=~s/\.git$//;22982299my$check_forks= gitweb_check_feature('forks');23002301if(-d $projects_list) {2302# search in directory2303my$dir=$projects_list. ($filter?"/$filter":'');2304# remove the trailing "/"2305$dir=~s!/+$!!;2306my$pfxlen=length("$dir");2307my$pfxdepth= ($dir=~tr!/!!);23082309 File::Find::find({2310 follow_fast =>1,# follow symbolic links2311 follow_skip =>2,# ignore duplicates2312 dangling_symlinks =>0,# ignore dangling symlinks, silently2313 wanted =>sub{2314# skip project-list toplevel, if we get it.2315return if(m!^[/.]$!);2316# only directories can be git repositories2317return unless(-d $_);2318# don't traverse too deep (Find is super slow on os x)2319if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2320$File::Find::prune =1;2321return;2322}23232324my$subdir=substr($File::Find::name,$pfxlen+1);2325# we check related file in $projectroot2326my$path= ($filter?"$filter/":'') .$subdir;2327if(check_export_ok("$projectroot/$path")) {2328push@list, { path =>$path};2329$File::Find::prune =1;2330}2331},2332},"$dir");23332334}elsif(-f $projects_list) {2335# read from file(url-encoded):2336# 'git%2Fgit.git Linus+Torvalds'2337# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2338# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2339my%paths;2340open my$fd,'<',$projects_listorreturn;2341 PROJECT:2342while(my$line= <$fd>) {2343chomp$line;2344my($path,$owner) =split' ',$line;2345$path= unescape($path);2346$owner= unescape($owner);2347if(!defined$path) {2348next;2349}2350if($filterne'') {2351# looking for forks;2352my$pfx=substr($path,0,length($filter));2353if($pfxne$filter) {2354next PROJECT;2355}2356my$sfx=substr($path,length($filter));2357if($sfx!~/^\/.*\.git$/) {2358next PROJECT;2359}2360}elsif($check_forks) {2361 PATH:2362foreachmy$filter(keys%paths) {2363# looking for forks;2364my$pfx=substr($path,0,length($filter));2365if($pfxne$filter) {2366next PATH;2367}2368my$sfx=substr($path,length($filter));2369if($sfx!~/^\/.*\.git$/) {2370next PATH;2371}2372# is a fork, don't include it in2373# the list2374next PROJECT;2375}2376}2377if(check_export_ok("$projectroot/$path")) {2378my$pr= {2379 path =>$path,2380 owner => to_utf8($owner),2381};2382push@list,$pr;2383(my$forks_path=$path) =~s/\.git$//;2384$paths{$forks_path}++;2385}2386}2387close$fd;2388}2389return@list;2390}23912392our$gitweb_project_owner=undef;2393sub git_get_project_list_from_file {23942395return if(defined$gitweb_project_owner);23962397$gitweb_project_owner= {};2398# read from file (url-encoded):2399# 'git%2Fgit.git Linus+Torvalds'2400# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2401# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2402if(-f $projects_list) {2403open(my$fd,'<',$projects_list);2404while(my$line= <$fd>) {2405chomp$line;2406my($pr,$ow) =split' ',$line;2407$pr= unescape($pr);2408$ow= unescape($ow);2409$gitweb_project_owner->{$pr} = to_utf8($ow);2410}2411close$fd;2412}2413}24142415sub git_get_project_owner {2416my$project=shift;2417my$owner;24182419returnundefunless$project;2420$git_dir="$projectroot/$project";24212422if(!defined$gitweb_project_owner) {2423 git_get_project_list_from_file();2424}24252426if(exists$gitweb_project_owner->{$project}) {2427$owner=$gitweb_project_owner->{$project};2428}2429if(!defined$owner){2430$owner= git_get_project_config('owner');2431}2432if(!defined$owner) {2433$owner= get_file_owner("$git_dir");2434}24352436return$owner;2437}24382439sub git_get_last_activity {2440my($path) =@_;2441my$fd;24422443$git_dir="$projectroot/$path";2444open($fd,"-|", git_cmd(),'for-each-ref',2445'--format=%(committer)',2446'--sort=-committerdate',2447'--count=1',2448'refs/heads')orreturn;2449my$most_recent= <$fd>;2450close$fdorreturn;2451if(defined$most_recent&&2452$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2453my$timestamp=$1;2454my$age=time-$timestamp;2455return($age, age_string($age));2456}2457return(undef,undef);2458}24592460sub git_get_references {2461my$type=shift||"";2462my%refs;2463# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112464# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2465open my$fd,"-|", git_cmd(),"show-ref","--dereference",2466($type? ("--","refs/$type") : ())# use -- <pattern> if $type2467orreturn;24682469while(my$line= <$fd>) {2470chomp$line;2471if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2472if(defined$refs{$1}) {2473push@{$refs{$1}},$2;2474}else{2475$refs{$1} = [$2];2476}2477}2478}2479close$fdorreturn;2480return \%refs;2481}24822483sub git_get_rev_name_tags {2484my$hash=shift||returnundef;24852486open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2487orreturn;2488my$name_rev= <$fd>;2489close$fd;24902491if($name_rev=~ m|^$hash tags/(.*)$|) {2492return$1;2493}else{2494# catches also '$hash undefined' output2495returnundef;2496}2497}24982499## ----------------------------------------------------------------------2500## parse to hash functions25012502sub parse_date {2503my$epoch=shift;2504my$tz=shift||"-0000";25052506my%date;2507my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2508my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2509my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2510$date{'hour'} =$hour;2511$date{'minute'} =$min;2512$date{'mday'} =$mday;2513$date{'day'} =$days[$wday];2514$date{'month'} =$months[$mon];2515$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2516$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2517$date{'mday-time'} =sprintf"%d%s%02d:%02d",2518$mday,$months[$mon],$hour,$min;2519$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",25201900+$year,1+$mon,$mday,$hour,$min,$sec;25212522$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2523my$local=$epoch+ ((int$1+ ($2/60)) *3600);2524($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2525$date{'hour_local'} =$hour;2526$date{'minute_local'} =$min;2527$date{'tz_local'} =$tz;2528$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",25291900+$year,$mon+1,$mday,2530$hour,$min,$sec,$tz);2531return%date;2532}25332534sub parse_tag {2535my$tag_id=shift;2536my%tag;2537my@comment;25382539open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2540$tag{'id'} =$tag_id;2541while(my$line= <$fd>) {2542chomp$line;2543if($line=~m/^object ([0-9a-fA-F]{40})$/) {2544$tag{'object'} =$1;2545}elsif($line=~m/^type (.+)$/) {2546$tag{'type'} =$1;2547}elsif($line=~m/^tag (.+)$/) {2548$tag{'name'} =$1;2549}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2550$tag{'author'} =$1;2551$tag{'author_epoch'} =$2;2552$tag{'author_tz'} =$3;2553if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {2554$tag{'author_name'} =$1;2555$tag{'author_email'} =$2;2556}else{2557$tag{'author_name'} =$tag{'author'};2558}2559}elsif($line=~m/--BEGIN/) {2560push@comment,$line;2561last;2562}elsif($lineeq"") {2563last;2564}2565}2566push@comment, <$fd>;2567$tag{'comment'} = \@comment;2568close$fdorreturn;2569if(!defined$tag{'name'}) {2570return2571};2572return%tag2573}25742575sub parse_commit_text {2576my($commit_text,$withparents) =@_;2577my@commit_lines=split'\n',$commit_text;2578my%co;25792580pop@commit_lines;# Remove '\0'25812582if(!@commit_lines) {2583return;2584}25852586my$header=shift@commit_lines;2587if($header!~m/^[0-9a-fA-F]{40}/) {2588return;2589}2590($co{'id'},my@parents) =split' ',$header;2591while(my$line=shift@commit_lines) {2592last if$lineeq"\n";2593if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2594$co{'tree'} =$1;2595}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2596push@parents,$1;2597}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2598$co{'author'} = to_utf8($1);2599$co{'author_epoch'} =$2;2600$co{'author_tz'} =$3;2601if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2602$co{'author_name'} =$1;2603$co{'author_email'} =$2;2604}else{2605$co{'author_name'} =$co{'author'};2606}2607}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2608$co{'committer'} = to_utf8($1);2609$co{'committer_epoch'} =$2;2610$co{'committer_tz'} =$3;2611if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2612$co{'committer_name'} =$1;2613$co{'committer_email'} =$2;2614}else{2615$co{'committer_name'} =$co{'committer'};2616}2617}2618}2619if(!defined$co{'tree'}) {2620return;2621};2622$co{'parents'} = \@parents;2623$co{'parent'} =$parents[0];26242625foreachmy$title(@commit_lines) {2626$title=~s/^ //;2627if($titlene"") {2628$co{'title'} = chop_str($title,80,5);2629# remove leading stuff of merges to make the interesting part visible2630if(length($title) >50) {2631$title=~s/^Automatic //;2632$title=~s/^merge (of|with) /Merge ... /i;2633if(length($title) >50) {2634$title=~s/(http|rsync):\/\///;2635}2636if(length($title) >50) {2637$title=~s/(master|www|rsync)\.//;2638}2639if(length($title) >50) {2640$title=~s/kernel.org:?//;2641}2642if(length($title) >50) {2643$title=~s/\/pub\/scm//;2644}2645}2646$co{'title_short'} = chop_str($title,50,5);2647last;2648}2649}2650if(!defined$co{'title'} ||$co{'title'}eq"") {2651$co{'title'} =$co{'title_short'} ='(no commit message)';2652}2653# remove added spaces2654foreachmy$line(@commit_lines) {2655$line=~s/^ //;2656}2657$co{'comment'} = \@commit_lines;26582659my$age=time-$co{'committer_epoch'};2660$co{'age'} =$age;2661$co{'age_string'} = age_string($age);2662my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2663if($age>60*60*24*7*2) {2664$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2665$co{'age_string_age'} =$co{'age_string'};2666}else{2667$co{'age_string_date'} =$co{'age_string'};2668$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2669}2670return%co;2671}26722673sub parse_commit {2674my($commit_id) =@_;2675my%co;26762677local$/="\0";26782679open my$fd,"-|", git_cmd(),"rev-list",2680"--parents",2681"--header",2682"--max-count=1",2683$commit_id,2684"--",2685or die_error(500,"Open git-rev-list failed");2686%co= parse_commit_text(<$fd>,1);2687close$fd;26882689return%co;2690}26912692sub parse_commits {2693my($commit_id,$maxcount,$skip,$filename,@args) =@_;2694my@cos;26952696$maxcount||=1;2697$skip||=0;26982699local$/="\0";27002701open my$fd,"-|", git_cmd(),"rev-list",2702"--header",2703@args,2704("--max-count=".$maxcount),2705("--skip=".$skip),2706@extra_options,2707$commit_id,2708"--",2709($filename? ($filename) : ())2710or die_error(500,"Open git-rev-list failed");2711while(my$line= <$fd>) {2712my%co= parse_commit_text($line);2713push@cos, \%co;2714}2715close$fd;27162717returnwantarray?@cos: \@cos;2718}27192720# parse line of git-diff-tree "raw" output2721sub parse_difftree_raw_line {2722my$line=shift;2723my%res;27242725# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2726# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2727if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2728$res{'from_mode'} =$1;2729$res{'to_mode'} =$2;2730$res{'from_id'} =$3;2731$res{'to_id'} =$4;2732$res{'status'} =$5;2733$res{'similarity'} =$6;2734if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2735($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2736}else{2737$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2738}2739}2740# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2741# combined diff (for merge commit)2742elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2743$res{'nparents'} =length($1);2744$res{'from_mode'} = [split(' ',$2) ];2745$res{'to_mode'} =pop@{$res{'from_mode'}};2746$res{'from_id'} = [split(' ',$3) ];2747$res{'to_id'} =pop@{$res{'from_id'}};2748$res{'status'} = [split('',$4) ];2749$res{'to_file'} = unquote($5);2750}2751# 'c512b523472485aef4fff9e57b229d9d243c967f'2752elsif($line=~m/^([0-9a-fA-F]{40})$/) {2753$res{'commit'} =$1;2754}27552756returnwantarray?%res: \%res;2757}27582759# wrapper: return parsed line of git-diff-tree "raw" output2760# (the argument might be raw line, or parsed info)2761sub parsed_difftree_line {2762my$line_or_ref=shift;27632764if(ref($line_or_ref)eq"HASH") {2765# pre-parsed (or generated by hand)2766return$line_or_ref;2767}else{2768return parse_difftree_raw_line($line_or_ref);2769}2770}27712772# parse line of git-ls-tree output2773sub parse_ls_tree_line {2774my$line=shift;2775my%opts=@_;2776my%res;27772778#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2779$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;27802781$res{'mode'} =$1;2782$res{'type'} =$2;2783$res{'hash'} =$3;2784if($opts{'-z'}) {2785$res{'name'} =$4;2786}else{2787$res{'name'} = unquote($4);2788}27892790returnwantarray?%res: \%res;2791}27922793# generates _two_ hashes, references to which are passed as 2 and 3 argument2794sub parse_from_to_diffinfo {2795my($diffinfo,$from,$to,@parents) =@_;27962797if($diffinfo->{'nparents'}) {2798# combined diff2799$from->{'file'} = [];2800$from->{'href'} = [];2801 fill_from_file_info($diffinfo,@parents)2802unlessexists$diffinfo->{'from_file'};2803for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2804$from->{'file'}[$i] =2805defined$diffinfo->{'from_file'}[$i] ?2806$diffinfo->{'from_file'}[$i] :2807$diffinfo->{'to_file'};2808if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2809$from->{'href'}[$i] = href(action=>"blob",2810 hash_base=>$parents[$i],2811 hash=>$diffinfo->{'from_id'}[$i],2812 file_name=>$from->{'file'}[$i]);2813}else{2814$from->{'href'}[$i] =undef;2815}2816}2817}else{2818# ordinary (not combined) diff2819$from->{'file'} =$diffinfo->{'from_file'};2820if($diffinfo->{'status'}ne"A") {# not new (added) file2821$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2822 hash=>$diffinfo->{'from_id'},2823 file_name=>$from->{'file'});2824}else{2825delete$from->{'href'};2826}2827}28282829$to->{'file'} =$diffinfo->{'to_file'};2830if(!is_deleted($diffinfo)) {# file exists in result2831$to->{'href'} = href(action=>"blob", hash_base=>$hash,2832 hash=>$diffinfo->{'to_id'},2833 file_name=>$to->{'file'});2834}else{2835delete$to->{'href'};2836}2837}28382839## ......................................................................2840## parse to array of hashes functions28412842sub git_get_heads_list {2843my$limit=shift;2844my@headslist;28452846open my$fd,'-|', git_cmd(),'for-each-ref',2847($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2848'--format=%(objectname) %(refname) %(subject)%00%(committer)',2849'refs/heads'2850orreturn;2851while(my$line= <$fd>) {2852my%ref_item;28532854chomp$line;2855my($refinfo,$committerinfo) =split(/\0/,$line);2856my($hash,$name,$title) =split(' ',$refinfo,3);2857my($committer,$epoch,$tz) =2858($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2859$ref_item{'fullname'} =$name;2860$name=~s!^refs/heads/!!;28612862$ref_item{'name'} =$name;2863$ref_item{'id'} =$hash;2864$ref_item{'title'} =$title||'(no commit message)';2865$ref_item{'epoch'} =$epoch;2866if($epoch) {2867$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2868}else{2869$ref_item{'age'} ="unknown";2870}28712872push@headslist, \%ref_item;2873}2874close$fd;28752876returnwantarray?@headslist: \@headslist;2877}28782879sub git_get_tags_list {2880my$limit=shift;2881my@tagslist;28822883open my$fd,'-|', git_cmd(),'for-each-ref',2884($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',2885'--format=%(objectname) %(objecttype) %(refname) '.2886'%(*objectname) %(*objecttype) %(subject)%00%(creator)',2887'refs/tags'2888orreturn;2889while(my$line= <$fd>) {2890my%ref_item;28912892chomp$line;2893my($refinfo,$creatorinfo) =split(/\0/,$line);2894my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);2895my($creator,$epoch,$tz) =2896($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);2897$ref_item{'fullname'} =$name;2898$name=~s!^refs/tags/!!;28992900$ref_item{'type'} =$type;2901$ref_item{'id'} =$id;2902$ref_item{'name'} =$name;2903if($typeeq"tag") {2904$ref_item{'subject'} =$title;2905$ref_item{'reftype'} =$reftype;2906$ref_item{'refid'} =$refid;2907}else{2908$ref_item{'reftype'} =$type;2909$ref_item{'refid'} =$id;2910}29112912if($typeeq"tag"||$typeeq"commit") {2913$ref_item{'epoch'} =$epoch;2914if($epoch) {2915$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2916}else{2917$ref_item{'age'} ="unknown";2918}2919}29202921push@tagslist, \%ref_item;2922}2923close$fd;29242925returnwantarray?@tagslist: \@tagslist;2926}29272928## ----------------------------------------------------------------------2929## filesystem-related functions29302931sub get_file_owner {2932my$path=shift;29332934my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);2935my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);2936if(!defined$gcos) {2937returnundef;2938}2939my$owner=$gcos;2940$owner=~s/[,;].*$//;2941return to_utf8($owner);2942}29432944# assume that file exists2945sub insert_file {2946my$filename=shift;29472948open my$fd,'<',$filename;2949print map{ to_utf8($_) } <$fd>;2950close$fd;2951}29522953## ......................................................................2954## mimetype related functions29552956sub mimetype_guess_file {2957my$filename=shift;2958my$mimemap=shift;2959-r $mimemaporreturnundef;29602961my%mimemap;2962open(my$mh,'<',$mimemap)orreturnundef;2963while(<$mh>) {2964next ifm/^#/;# skip comments2965my($mimetype,$exts) =split(/\t+/);2966if(defined$exts) {2967my@exts=split(/\s+/,$exts);2968foreachmy$ext(@exts) {2969$mimemap{$ext} =$mimetype;2970}2971}2972}2973close($mh);29742975$filename=~/\.([^.]*)$/;2976return$mimemap{$1};2977}29782979sub mimetype_guess {2980my$filename=shift;2981my$mime;2982$filename=~/\./orreturnundef;29832984if($mimetypes_file) {2985my$file=$mimetypes_file;2986if($file!~m!^/!) {# if it is relative path2987# it is relative to project2988$file="$projectroot/$project/$file";2989}2990$mime= mimetype_guess_file($filename,$file);2991}2992$mime||= mimetype_guess_file($filename,'/etc/mime.types');2993return$mime;2994}29952996sub blob_mimetype {2997my$fd=shift;2998my$filename=shift;29993000if($filename) {3001my$mime= mimetype_guess($filename);3002$mimeandreturn$mime;3003}30043005# just in case3006return$default_blob_plain_mimetypeunless$fd;30073008if(-T $fd) {3009return'text/plain';3010}elsif(!$filename) {3011return'application/octet-stream';3012}elsif($filename=~m/\.png$/i) {3013return'image/png';3014}elsif($filename=~m/\.gif$/i) {3015return'image/gif';3016}elsif($filename=~m/\.jpe?g$/i) {3017return'image/jpeg';3018}else{3019return'application/octet-stream';3020}3021}30223023sub blob_contenttype {3024my($fd,$file_name,$type) =@_;30253026$type||= blob_mimetype($fd,$file_name);3027if($typeeq'text/plain'&&defined$default_text_plain_charset) {3028$type.="; charset=$default_text_plain_charset";3029}30303031return$type;3032}30333034## ======================================================================3035## functions printing HTML: header, footer, error page30363037sub git_header_html {3038my$status=shift||"200 OK";3039my$expires=shift;30403041my$title="$site_name";3042if(defined$project) {3043$title.=" - ". to_utf8($project);3044if(defined$action) {3045$title.="/$action";3046if(defined$file_name) {3047$title.=" - ". esc_path($file_name);3048if($actioneq"tree"&&$file_name!~ m|/$|) {3049$title.="/";3050}3051}3052}3053}3054my$content_type;3055# require explicit support from the UA if we are to send the page as3056# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3057# we have to do this because MSIE sometimes globs '*/*', pretending to3058# support xhtml+xml but choking when it gets what it asked for.3059if(defined$cgi->http('HTTP_ACCEPT') &&3060$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3061$cgi->Accept('application/xhtml+xml') !=0) {3062$content_type='application/xhtml+xml';3063}else{3064$content_type='text/html';3065}3066print$cgi->header(-type=>$content_type, -charset =>'utf-8',3067-status=>$status, -expires =>$expires);3068my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';3069print<<EOF;3070<?xml version="1.0" encoding="utf-8"?>3071<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">3072<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">3073<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->3074<!-- git core binaries version$git_version-->3075<head>3076<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>3077<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>3078<meta name="robots" content="index, nofollow"/>3079<title>$title</title>3080EOF3081# the stylesheet, favicon etc urls won't work correctly with path_info3082# unless we set the appropriate base URL3083if($ENV{'PATH_INFO'}) {3084print"<base href=\"".esc_url($base_url)."\"/>\n";3085}3086# print out each stylesheet that exist, providing backwards capability3087# for those people who defined $stylesheet in a config file3088if(defined$stylesheet) {3089print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3090}else{3091foreachmy$stylesheet(@stylesheets) {3092next unless$stylesheet;3093print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3094}3095}3096if(defined$project) {3097my%href_params= get_feed_info();3098if(!exists$href_params{'-title'}) {3099$href_params{'-title'} ='log';3100}31013102foreachmy$formatqw(RSS Atom){3103my$type=lc($format);3104my%link_attr= (3105'-rel'=>'alternate',3106'-title'=>"$project-$href_params{'-title'} -$formatfeed",3107'-type'=>"application/$type+xml"3108);31093110$href_params{'action'} =$type;3111$link_attr{'-href'} = href(%href_params);3112print"<link ".3113"rel=\"$link_attr{'-rel'}\"".3114"title=\"$link_attr{'-title'}\"".3115"href=\"$link_attr{'-href'}\"".3116"type=\"$link_attr{'-type'}\"".3117"/>\n";31183119$href_params{'extra_options'} ='--no-merges';3120$link_attr{'-href'} = href(%href_params);3121$link_attr{'-title'} .=' (no merges)';3122print"<link ".3123"rel=\"$link_attr{'-rel'}\"".3124"title=\"$link_attr{'-title'}\"".3125"href=\"$link_attr{'-href'}\"".3126"type=\"$link_attr{'-type'}\"".3127"/>\n";3128}31293130}else{3131printf('<link rel="alternate" title="%sprojects list" '.3132'href="%s" type="text/plain; charset=utf-8" />'."\n",3133$site_name, href(project=>undef, action=>"project_index"));3134printf('<link rel="alternate" title="%sprojects feeds" '.3135'href="%s" type="text/x-opml" />'."\n",3136$site_name, href(project=>undef, action=>"opml"));3137}3138if(defined$favicon) {3139printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);3140}31413142print"</head>\n".3143"<body>\n";31443145if(-f $site_header) {3146 insert_file($site_header);3147}31483149print"<div class=\"page_header\">\n".3150$cgi->a({-href => esc_url($logo_url),3151-title =>$logo_label},3152qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));3153print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3154if(defined$project) {3155print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3156if(defined$action) {3157print" /$action";3158}3159print"\n";3160}3161print"</div>\n";31623163my$have_search= gitweb_check_feature('search');3164if(defined$project&&$have_search) {3165if(!defined$searchtext) {3166$searchtext="";3167}3168my$search_hash;3169if(defined$hash_base) {3170$search_hash=$hash_base;3171}elsif(defined$hash) {3172$search_hash=$hash;3173}else{3174$search_hash="HEAD";3175}3176my$action=$my_uri;3177my$use_pathinfo= gitweb_check_feature('pathinfo');3178if($use_pathinfo) {3179$action.="/".esc_url($project);3180}3181print$cgi->startform(-method=>"get", -action =>$action) .3182"<div class=\"search\">\n".3183(!$use_pathinfo&&3184$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3185$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3186$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3187$cgi->popup_menu(-name =>'st', -default=>'commit',3188-values=> ['commit','grep','author','committer','pickaxe']) .3189$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3190" search:\n",3191$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3192"<span title=\"Extended regular expression\">".3193$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3194-checked =>$search_use_regexp) .3195"</span>".3196"</div>".3197$cgi->end_form() ."\n";3198}3199}32003201sub git_footer_html {3202my$feed_class='rss_logo';32033204print"<div class=\"page_footer\">\n";3205if(defined$project) {3206my$descr= git_get_project_description($project);3207if(defined$descr) {3208print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3209}32103211my%href_params= get_feed_info();3212if(!%href_params) {3213$feed_class.=' generic';3214}3215$href_params{'-title'} ||='log';32163217foreachmy$formatqw(RSS Atom){3218$href_params{'action'} =lc($format);3219print$cgi->a({-href => href(%href_params),3220-title =>"$href_params{'-title'}$formatfeed",3221-class=>$feed_class},$format)."\n";3222}32233224}else{3225print$cgi->a({-href => href(project=>undef, action=>"opml"),3226-class=>$feed_class},"OPML") ." ";3227print$cgi->a({-href => href(project=>undef, action=>"project_index"),3228-class=>$feed_class},"TXT") ."\n";3229}3230print"</div>\n";# class="page_footer"32313232if(-f $site_footer) {3233 insert_file($site_footer);3234}32353236print"</body>\n".3237"</html>";3238}32393240# die_error(<http_status_code>, <error_message>)3241# Example: die_error(404, 'Hash not found')3242# By convention, use the following status codes (as defined in RFC 2616):3243# 400: Invalid or missing CGI parameters, or3244# requested object exists but has wrong type.3245# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3246# this server or project.3247# 404: Requested object/revision/project doesn't exist.3248# 500: The server isn't configured properly, or3249# an internal error occurred (e.g. failed assertions caused by bugs), or3250# an unknown error occurred (e.g. the git binary died unexpectedly).3251sub die_error {3252my$status=shift||500;3253my$error=shift||"Internal server error";32543255my%http_responses= (400=>'400 Bad Request',3256403=>'403 Forbidden',3257404=>'404 Not Found',3258500=>'500 Internal Server Error');3259 git_header_html($http_responses{$status});3260print<<EOF;3261<div class="page_body">3262<br /><br />3263$status-$error3264<br />3265</div>3266EOF3267 git_footer_html();3268exit;3269}32703271## ----------------------------------------------------------------------3272## functions printing or outputting HTML: navigation32733274sub git_print_page_nav {3275my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3276$extra=''if!defined$extra;# pager or formats32773278my@navs=qw(summary shortlog log commit commitdiff tree);3279if($suppress) {3280@navs=grep{$_ne$suppress}@navs;3281}32823283my%arg=map{$_=> {action=>$_} }@navs;3284if(defined$head) {3285for(qw(commit commitdiff)) {3286$arg{$_}{'hash'} =$head;3287}3288if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3289for(qw(shortlog log)) {3290$arg{$_}{'hash'} =$head;3291}3292}3293}32943295$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3296$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;32973298my@actions= gitweb_get_feature('actions');3299my%repl= (3300'%'=>'%',3301'n'=>$project,# project name3302'f'=>$git_dir,# project path within filesystem3303'h'=>$treehead||'',# current hash ('h' parameter)3304'b'=>$treebase||'',# hash base ('hb' parameter)3305);3306while(@actions) {3307my($label,$link,$pos) =splice(@actions,0,3);3308# insert3309@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3310# munch munch3311$link=~s/%([%nfhb])/$repl{$1}/g;3312$arg{$label}{'_href'} =$link;3313}33143315print"<div class=\"page_nav\">\n".3316(join" | ",3317map{$_eq$current?3318$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3319}@navs);3320print"<br/>\n$extra<br/>\n".3321"</div>\n";3322}33233324sub format_paging_nav {3325my($action,$hash,$head,$page,$has_next_link) =@_;3326my$paging_nav;332733283329if($hashne$head||$page) {3330$paging_nav.=$cgi->a({-href => href(action=>$action)},"HEAD");3331}else{3332$paging_nav.="HEAD";3333}33343335if($page>0) {3336$paging_nav.=" ⋅ ".3337$cgi->a({-href => href(-replay=>1, page=>$page-1),3338-accesskey =>"p", -title =>"Alt-p"},"prev");3339}else{3340$paging_nav.=" ⋅ prev";3341}33423343if($has_next_link) {3344$paging_nav.=" ⋅ ".3345$cgi->a({-href => href(-replay=>1, page=>$page+1),3346-accesskey =>"n", -title =>"Alt-n"},"next");3347}else{3348$paging_nav.=" ⋅ next";3349}33503351return$paging_nav;3352}33533354## ......................................................................3355## functions printing or outputting HTML: div33563357sub git_print_header_div {3358my($action,$title,$hash,$hash_base) =@_;3359my%args= ();33603361$args{'action'} =$action;3362$args{'hash'} =$hashif$hash;3363$args{'hash_base'} =$hash_baseif$hash_base;33643365print"<div class=\"header\">\n".3366$cgi->a({-href => href(%args), -class=>"title"},3367$title?$title:$action) .3368"\n</div>\n";3369}33703371sub print_local_time {3372my%date=@_;3373if($date{'hour_local'} <6) {3374printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3375$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3376}else{3377printf(" (%02d:%02d%s)",3378$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3379}3380}33813382# Outputs the author name and date in long form3383sub git_print_authorship {3384my$co=shift;3385my%opts=@_;3386my$tag=$opts{-tag} ||'div';33873388my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3389print"<$tagclass=\"author_date\">".3390 esc_html($co->{'author_name'}) .3391" [$ad{'rfc2822'}";3392 print_local_time(%ad)if($opts{-localtime});3393print"]". git_get_avatar($co->{'author_email'}, -pad_before =>1)3394."</$tag>\n";3395}33963397# Outputs table rows containing the full author or committer information,3398# in the format expected for 'commit' view (& similia).3399# Parameters are a commit hash reference, followed by the list of people3400# to output information for. If the list is empty it defalts to both3401# author and committer.3402sub git_print_authorship_rows {3403my$co=shift;3404# too bad we can't use @people = @_ || ('author', 'committer')3405my@people=@_;3406@people= ('author','committer')unless@people;3407foreachmy$who(@people) {3408my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});3409print"<tr><td>$who</td><td>". esc_html($co->{$who}) ."</td>".3410"<td rowspan=\"2\">".3411 git_get_avatar($co->{"${who}_email"}, -size =>'double') .3412"</td></tr>\n".3413"<tr>".3414"<td></td><td>$wd{'rfc2822'}";3415 print_local_time(%wd);3416print"</td>".3417"</tr>\n";3418}3419}34203421sub git_print_page_path {3422my$name=shift;3423my$type=shift;3424my$hb=shift;342534263427print"<div class=\"page_path\">";3428print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3429-title =>'tree root'}, to_utf8("[$project]"));3430print" / ";3431if(defined$name) {3432my@dirname=split'/',$name;3433my$basename=pop@dirname;3434my$fullname='';34353436foreachmy$dir(@dirname) {3437$fullname.= ($fullname?'/':'') .$dir;3438print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3439 hash_base=>$hb),3440-title =>$fullname}, esc_path($dir));3441print" / ";3442}3443if(defined$type&&$typeeq'blob') {3444print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3445 hash_base=>$hb),3446-title =>$name}, esc_path($basename));3447}elsif(defined$type&&$typeeq'tree') {3448print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3449 hash_base=>$hb),3450-title =>$name}, esc_path($basename));3451print" / ";3452}else{3453print esc_path($basename);3454}3455}3456print"<br/></div>\n";3457}34583459sub git_print_log {3460my$log=shift;3461my%opts=@_;34623463if($opts{'-remove_title'}) {3464# remove title, i.e. first line of log3465shift@$log;3466}3467# remove leading empty lines3468while(defined$log->[0] &&$log->[0]eq"") {3469shift@$log;3470}34713472# print log3473my$signoff=0;3474my$empty=0;3475foreachmy$line(@$log) {3476if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3477$signoff=1;3478$empty=0;3479if(!$opts{'-remove_signoff'}) {3480print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3481next;3482}else{3483# remove signoff lines3484next;3485}3486}else{3487$signoff=0;3488}34893490# print only one empty line3491# do not print empty line after signoff3492if($lineeq"") {3493next if($empty||$signoff);3494$empty=1;3495}else{3496$empty=0;3497}34983499print format_log_line_html($line) ."<br/>\n";3500}35013502if($opts{'-final_empty_line'}) {3503# end with single empty line3504print"<br/>\n"unless$empty;3505}3506}35073508# return link target (what link points to)3509sub git_get_link_target {3510my$hash=shift;3511my$link_target;35123513# read link3514open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3515orreturn;3516{3517local$/=undef;3518$link_target= <$fd>;3519}3520close$fd3521orreturn;35223523return$link_target;3524}35253526# given link target, and the directory (basedir) the link is in,3527# return target of link relative to top directory (top tree);3528# return undef if it is not possible (including absolute links).3529sub normalize_link_target {3530my($link_target,$basedir) =@_;35313532# absolute symlinks (beginning with '/') cannot be normalized3533return if(substr($link_target,0,1)eq'/');35343535# normalize link target to path from top (root) tree (dir)3536my$path;3537if($basedir) {3538$path=$basedir.'/'.$link_target;3539}else{3540# we are in top (root) tree (dir)3541$path=$link_target;3542}35433544# remove //, /./, and /../3545my@path_parts;3546foreachmy$part(split('/',$path)) {3547# discard '.' and ''3548next if(!$part||$parteq'.');3549# handle '..'3550if($parteq'..') {3551if(@path_parts) {3552pop@path_parts;3553}else{3554# link leads outside repository (outside top dir)3555return;3556}3557}else{3558push@path_parts,$part;3559}3560}3561$path=join('/',@path_parts);35623563return$path;3564}35653566# print tree entry (row of git_tree), but without encompassing <tr> element3567sub git_print_tree_entry {3568my($t,$basedir,$hash_base,$have_blame) =@_;35693570my%base_key= ();3571$base_key{'hash_base'} =$hash_baseifdefined$hash_base;35723573# The format of a table row is: mode list link. Where mode is3574# the mode of the entry, list is the name of the entry, an href,3575# and link is the action links of the entry.35763577print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3578if($t->{'type'}eq"blob") {3579print"<td class=\"list\">".3580$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3581 file_name=>"$basedir$t->{'name'}",%base_key),3582-class=>"list"}, esc_path($t->{'name'}));3583if(S_ISLNK(oct$t->{'mode'})) {3584my$link_target= git_get_link_target($t->{'hash'});3585if($link_target) {3586my$norm_target= normalize_link_target($link_target,$basedir);3587if(defined$norm_target) {3588print" -> ".3589$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3590 file_name=>$norm_target),3591-title =>$norm_target}, esc_path($link_target));3592}else{3593print" -> ". esc_path($link_target);3594}3595}3596}3597print"</td>\n";3598print"<td class=\"link\">";3599print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3600 file_name=>"$basedir$t->{'name'}",%base_key)},3601"blob");3602if($have_blame) {3603print" | ".3604$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3605 file_name=>"$basedir$t->{'name'}",%base_key)},3606"blame");3607}3608if(defined$hash_base) {3609print" | ".3610$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3611 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3612"history");3613}3614print" | ".3615$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3616 file_name=>"$basedir$t->{'name'}")},3617"raw");3618print"</td>\n";36193620}elsif($t->{'type'}eq"tree") {3621print"<td class=\"list\">";3622print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3623 file_name=>"$basedir$t->{'name'}",%base_key)},3624 esc_path($t->{'name'}));3625print"</td>\n";3626print"<td class=\"link\">";3627print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3628 file_name=>"$basedir$t->{'name'}",%base_key)},3629"tree");3630if(defined$hash_base) {3631print" | ".3632$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3633 file_name=>"$basedir$t->{'name'}")},3634"history");3635}3636print"</td>\n";3637}else{3638# unknown object: we can only present history for it3639# (this includes 'commit' object, i.e. submodule support)3640print"<td class=\"list\">".3641 esc_path($t->{'name'}) .3642"</td>\n";3643print"<td class=\"link\">";3644if(defined$hash_base) {3645print$cgi->a({-href => href(action=>"history",3646 hash_base=>$hash_base,3647 file_name=>"$basedir$t->{'name'}")},3648"history");3649}3650print"</td>\n";3651}3652}36533654## ......................................................................3655## functions printing large fragments of HTML36563657# get pre-image filenames for merge (combined) diff3658sub fill_from_file_info {3659my($diff,@parents) =@_;36603661$diff->{'from_file'} = [ ];3662$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3663for(my$i=0;$i<$diff->{'nparents'};$i++) {3664if($diff->{'status'}[$i]eq'R'||3665$diff->{'status'}[$i]eq'C') {3666$diff->{'from_file'}[$i] =3667 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3668}3669}36703671return$diff;3672}36733674# is current raw difftree line of file deletion3675sub is_deleted {3676my$diffinfo=shift;36773678return$diffinfo->{'to_id'}eq('0' x 40);3679}36803681# does patch correspond to [previous] difftree raw line3682# $diffinfo - hashref of parsed raw diff format3683# $patchinfo - hashref of parsed patch diff format3684# (the same keys as in $diffinfo)3685sub is_patch_split {3686my($diffinfo,$patchinfo) =@_;36873688returndefined$diffinfo&&defined$patchinfo3689&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3690}369136923693sub git_difftree_body {3694my($difftree,$hash,@parents) =@_;3695my($parent) =$parents[0];3696my$have_blame= gitweb_check_feature('blame');3697print"<div class=\"list_head\">\n";3698if($#{$difftree} >10) {3699print(($#{$difftree} +1) ." files changed:\n");3700}3701print"</div>\n";37023703print"<table class=\"".3704(@parents>1?"combined ":"") .3705"diff_tree\">\n";37063707# header only for combined diff in 'commitdiff' view3708my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3709if($has_header) {3710# table header3711print"<thead><tr>\n".3712"<th></th><th></th>\n";# filename, patchN link3713for(my$i=0;$i<@parents;$i++) {3714my$par=$parents[$i];3715print"<th>".3716$cgi->a({-href => href(action=>"commitdiff",3717 hash=>$hash, hash_parent=>$par),3718-title =>'commitdiff to parent number '.3719($i+1) .': '.substr($par,0,7)},3720$i+1) .3721" </th>\n";3722}3723print"</tr></thead>\n<tbody>\n";3724}37253726my$alternate=1;3727my$patchno=0;3728foreachmy$line(@{$difftree}) {3729my$diff= parsed_difftree_line($line);37303731if($alternate) {3732print"<tr class=\"dark\">\n";3733}else{3734print"<tr class=\"light\">\n";3735}3736$alternate^=1;37373738if(exists$diff->{'nparents'}) {# combined diff37393740 fill_from_file_info($diff,@parents)3741unlessexists$diff->{'from_file'};37423743if(!is_deleted($diff)) {3744# file exists in the result (child) commit3745print"<td>".3746$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3747 file_name=>$diff->{'to_file'},3748 hash_base=>$hash),3749-class=>"list"}, esc_path($diff->{'to_file'})) .3750"</td>\n";3751}else{3752print"<td>".3753 esc_path($diff->{'to_file'}) .3754"</td>\n";3755}37563757if($actioneq'commitdiff') {3758# link to patch3759$patchno++;3760print"<td class=\"link\">".3761$cgi->a({-href =>"#patch$patchno"},"patch") .3762" | ".3763"</td>\n";3764}37653766my$has_history=0;3767my$not_deleted=0;3768for(my$i=0;$i<$diff->{'nparents'};$i++) {3769my$hash_parent=$parents[$i];3770my$from_hash=$diff->{'from_id'}[$i];3771my$from_path=$diff->{'from_file'}[$i];3772my$status=$diff->{'status'}[$i];37733774$has_history||= ($statusne'A');3775$not_deleted||= ($statusne'D');37763777if($statuseq'A') {3778print"<td class=\"link\"align=\"right\"> | </td>\n";3779}elsif($statuseq'D') {3780print"<td class=\"link\">".3781$cgi->a({-href => href(action=>"blob",3782 hash_base=>$hash,3783 hash=>$from_hash,3784 file_name=>$from_path)},3785"blob". ($i+1)) .3786" | </td>\n";3787}else{3788if($diff->{'to_id'}eq$from_hash) {3789print"<td class=\"link nochange\">";3790}else{3791print"<td class=\"link\">";3792}3793print$cgi->a({-href => href(action=>"blobdiff",3794 hash=>$diff->{'to_id'},3795 hash_parent=>$from_hash,3796 hash_base=>$hash,3797 hash_parent_base=>$hash_parent,3798 file_name=>$diff->{'to_file'},3799 file_parent=>$from_path)},3800"diff". ($i+1)) .3801" | </td>\n";3802}3803}38043805print"<td class=\"link\">";3806if($not_deleted) {3807print$cgi->a({-href => href(action=>"blob",3808 hash=>$diff->{'to_id'},3809 file_name=>$diff->{'to_file'},3810 hash_base=>$hash)},3811"blob");3812print" | "if($has_history);3813}3814if($has_history) {3815print$cgi->a({-href => href(action=>"history",3816 file_name=>$diff->{'to_file'},3817 hash_base=>$hash)},3818"history");3819}3820print"</td>\n";38213822print"</tr>\n";3823next;# instead of 'else' clause, to avoid extra indent3824}3825# else ordinary diff38263827my($to_mode_oct,$to_mode_str,$to_file_type);3828my($from_mode_oct,$from_mode_str,$from_file_type);3829if($diff->{'to_mode'}ne('0' x 6)) {3830$to_mode_oct=oct$diff->{'to_mode'};3831if(S_ISREG($to_mode_oct)) {# only for regular file3832$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits3833}3834$to_file_type= file_type($diff->{'to_mode'});3835}3836if($diff->{'from_mode'}ne('0' x 6)) {3837$from_mode_oct=oct$diff->{'from_mode'};3838if(S_ISREG($to_mode_oct)) {# only for regular file3839$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits3840}3841$from_file_type= file_type($diff->{'from_mode'});3842}38433844if($diff->{'status'}eq"A") {# created3845my$mode_chng="<span class=\"file_status new\">[new$to_file_type";3846$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;3847$mode_chng.="]</span>";3848print"<td>";3849print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3850 hash_base=>$hash, file_name=>$diff->{'file'}),3851-class=>"list"}, esc_path($diff->{'file'}));3852print"</td>\n";3853print"<td>$mode_chng</td>\n";3854print"<td class=\"link\">";3855if($actioneq'commitdiff') {3856# link to patch3857$patchno++;3858print$cgi->a({-href =>"#patch$patchno"},"patch");3859print" | ";3860}3861print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3862 hash_base=>$hash, file_name=>$diff->{'file'})},3863"blob");3864print"</td>\n";38653866}elsif($diff->{'status'}eq"D") {# deleted3867my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";3868print"<td>";3869print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3870 hash_base=>$parent, file_name=>$diff->{'file'}),3871-class=>"list"}, esc_path($diff->{'file'}));3872print"</td>\n";3873print"<td>$mode_chng</td>\n";3874print"<td class=\"link\">";3875if($actioneq'commitdiff') {3876# link to patch3877$patchno++;3878print$cgi->a({-href =>"#patch$patchno"},"patch");3879print" | ";3880}3881print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3882 hash_base=>$parent, file_name=>$diff->{'file'})},3883"blob") ." | ";3884if($have_blame) {3885print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,3886 file_name=>$diff->{'file'})},3887"blame") ." | ";3888}3889print$cgi->a({-href => href(action=>"history", hash_base=>$parent,3890 file_name=>$diff->{'file'})},3891"history");3892print"</td>\n";38933894}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed3895my$mode_chnge="";3896if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3897$mode_chnge="<span class=\"file_status mode_chnge\">[changed";3898if($from_file_typene$to_file_type) {3899$mode_chnge.=" from$from_file_typeto$to_file_type";3900}3901if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {3902if($from_mode_str&&$to_mode_str) {3903$mode_chnge.=" mode:$from_mode_str->$to_mode_str";3904}elsif($to_mode_str) {3905$mode_chnge.=" mode:$to_mode_str";3906}3907}3908$mode_chnge.="]</span>\n";3909}3910print"<td>";3911print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3912 hash_base=>$hash, file_name=>$diff->{'file'}),3913-class=>"list"}, esc_path($diff->{'file'}));3914print"</td>\n";3915print"<td>$mode_chnge</td>\n";3916print"<td class=\"link\">";3917if($actioneq'commitdiff') {3918# link to patch3919$patchno++;3920print$cgi->a({-href =>"#patch$patchno"},"patch") .3921" | ";3922}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3923# "commit" view and modified file (not onlu mode changed)3924print$cgi->a({-href => href(action=>"blobdiff",3925 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3926 hash_base=>$hash, hash_parent_base=>$parent,3927 file_name=>$diff->{'file'})},3928"diff") .3929" | ";3930}3931print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3932 hash_base=>$hash, file_name=>$diff->{'file'})},3933"blob") ." | ";3934if($have_blame) {3935print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3936 file_name=>$diff->{'file'})},3937"blame") ." | ";3938}3939print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3940 file_name=>$diff->{'file'})},3941"history");3942print"</td>\n";39433944}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied3945my%status_name= ('R'=>'moved','C'=>'copied');3946my$nstatus=$status_name{$diff->{'status'}};3947my$mode_chng="";3948if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3949# mode also for directories, so we cannot use $to_mode_str3950$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);3951}3952print"<td>".3953$cgi->a({-href => href(action=>"blob", hash_base=>$hash,3954 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),3955-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".3956"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".3957$cgi->a({-href => href(action=>"blob", hash_base=>$parent,3958 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),3959-class=>"list"}, esc_path($diff->{'from_file'})) .3960" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".3961"<td class=\"link\">";3962if($actioneq'commitdiff') {3963# link to patch3964$patchno++;3965print$cgi->a({-href =>"#patch$patchno"},"patch") .3966" | ";3967}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3968# "commit" view and modified file (not only pure rename or copy)3969print$cgi->a({-href => href(action=>"blobdiff",3970 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3971 hash_base=>$hash, hash_parent_base=>$parent,3972 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},3973"diff") .3974" | ";3975}3976print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3977 hash_base=>$parent, file_name=>$diff->{'to_file'})},3978"blob") ." | ";3979if($have_blame) {3980print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3981 file_name=>$diff->{'to_file'})},3982"blame") ." | ";3983}3984print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3985 file_name=>$diff->{'to_file'})},3986"history");3987print"</td>\n";39883989}# we should not encounter Unmerged (U) or Unknown (X) status3990print"</tr>\n";3991}3992print"</tbody>"if$has_header;3993print"</table>\n";3994}39953996sub git_patchset_body {3997my($fd,$difftree,$hash,@hash_parents) =@_;3998my($hash_parent) =$hash_parents[0];39994000my$is_combined= (@hash_parents>1);4001my$patch_idx=0;4002my$patch_number=0;4003my$patch_line;4004my$diffinfo;4005my$to_name;4006my(%from,%to);40074008print"<div class=\"patchset\">\n";40094010# skip to first patch4011while($patch_line= <$fd>) {4012chomp$patch_line;40134014last if($patch_line=~m/^diff /);4015}40164017 PATCH:4018while($patch_line) {40194020# parse "git diff" header line4021if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {4022# $1 is from_name, which we do not use4023$to_name= unquote($2);4024$to_name=~s!^b/!!;4025}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {4026# $1 is 'cc' or 'combined', which we do not use4027$to_name= unquote($2);4028}else{4029$to_name=undef;4030}40314032# check if current patch belong to current raw line4033# and parse raw git-diff line if needed4034if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {4035# this is continuation of a split patch4036print"<div class=\"patch cont\">\n";4037}else{4038# advance raw git-diff output if needed4039$patch_idx++ifdefined$diffinfo;40404041# read and prepare patch information4042$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);40434044# compact combined diff output can have some patches skipped4045# find which patch (using pathname of result) we are at now;4046if($is_combined) {4047while($to_namene$diffinfo->{'to_file'}) {4048print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4049 format_diff_cc_simplified($diffinfo,@hash_parents) .4050"</div>\n";# class="patch"40514052$patch_idx++;4053$patch_number++;40544055last if$patch_idx>$#$difftree;4056$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);4057}4058}40594060# modifies %from, %to hashes4061 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);40624063# this is first patch for raw difftree line with $patch_idx index4064# we index @$difftree array from 0, but number patches from 14065print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";4066}40674068# git diff header4069#assert($patch_line =~ m/^diff /) if DEBUG;4070#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed4071$patch_number++;4072# print "git diff" header4073print format_git_diff_header_line($patch_line,$diffinfo,4074 \%from, \%to);40754076# print extended diff header4077print"<div class=\"diff extended_header\">\n";4078 EXTENDED_HEADER:4079while($patch_line= <$fd>) {4080chomp$patch_line;40814082last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);40834084print format_extended_diff_header_line($patch_line,$diffinfo,4085 \%from, \%to);4086}4087print"</div>\n";# class="diff extended_header"40884089# from-file/to-file diff header4090if(!$patch_line) {4091print"</div>\n";# class="patch"4092last PATCH;4093}4094next PATCH if($patch_line=~m/^diff /);4095#assert($patch_line =~ m/^---/) if DEBUG;40964097my$last_patch_line=$patch_line;4098$patch_line= <$fd>;4099chomp$patch_line;4100#assert($patch_line =~ m/^\+\+\+/) if DEBUG;41014102print format_diff_from_to_header($last_patch_line,$patch_line,4103$diffinfo, \%from, \%to,4104@hash_parents);41054106# the patch itself4107 LINE:4108while($patch_line= <$fd>) {4109chomp$patch_line;41104111next PATCH if($patch_line=~m/^diff /);41124113print format_diff_line($patch_line, \%from, \%to);4114}41154116}continue{4117print"</div>\n";# class="patch"4118}41194120# for compact combined (--cc) format, with chunk and patch simpliciaction4121# patchset might be empty, but there might be unprocessed raw lines4122for(++$patch_idxif$patch_number>0;4123$patch_idx<@$difftree;4124++$patch_idx) {4125# read and prepare patch information4126$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);41274128# generate anchor for "patch" links in difftree / whatchanged part4129print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4130 format_diff_cc_simplified($diffinfo,@hash_parents) .4131"</div>\n";# class="patch"41324133$patch_number++;4134}41354136if($patch_number==0) {4137if(@hash_parents>1) {4138print"<div class=\"diff nodifferences\">Trivial merge</div>\n";4139}else{4140print"<div class=\"diff nodifferences\">No differences found</div>\n";4141}4142}41434144print"</div>\n";# class="patchset"4145}41464147# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41484149# fills project list info (age, description, owner, forks) for each4150# project in the list, removing invalid projects from returned list4151# NOTE: modifies $projlist, but does not remove entries from it4152sub fill_project_list_info {4153my($projlist,$check_forks) =@_;4154my@projects;41554156my$show_ctags= gitweb_check_feature('ctags');4157 PROJECT:4158foreachmy$pr(@$projlist) {4159my(@activity) = git_get_last_activity($pr->{'path'});4160unless(@activity) {4161next PROJECT;4162}4163($pr->{'age'},$pr->{'age_string'}) =@activity;4164if(!defined$pr->{'descr'}) {4165my$descr= git_get_project_description($pr->{'path'}) ||"";4166$descr= to_utf8($descr);4167$pr->{'descr_long'} =$descr;4168$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4169}4170if(!defined$pr->{'owner'}) {4171$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4172}4173if($check_forks) {4174my$pname=$pr->{'path'};4175if(($pname=~s/\.git$//) &&4176($pname!~/\/$/) &&4177(-d "$projectroot/$pname")) {4178$pr->{'forks'} ="-d$projectroot/$pname";4179}else{4180$pr->{'forks'} =0;4181}4182}4183$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4184push@projects,$pr;4185}41864187return@projects;4188}41894190# print 'sort by' <th> element, generating 'sort by $name' replay link4191# if that order is not selected4192sub print_sort_th {4193my($name,$order,$header) =@_;4194$header||=ucfirst($name);41954196if($ordereq$name) {4197print"<th>$header</th>\n";4198}else{4199print"<th>".4200$cgi->a({-href => href(-replay=>1, order=>$name),4201-class=>"header"},$header) .4202"</th>\n";4203}4204}42054206sub git_project_list_body {4207# actually uses global variable $project4208my($projlist,$order,$from,$to,$extra,$no_header) =@_;42094210my$check_forks= gitweb_check_feature('forks');4211my@projects= fill_project_list_info($projlist,$check_forks);42124213$order||=$default_projects_order;4214$from=0unlessdefined$from;4215$to=$#projectsif(!defined$to||$#projects<$to);42164217my%order_info= (4218 project => { key =>'path', type =>'str'},4219 descr => { key =>'descr_long', type =>'str'},4220 owner => { key =>'owner', type =>'str'},4221 age => { key =>'age', type =>'num'}4222);4223my$oi=$order_info{$order};4224if($oi->{'type'}eq'str') {4225@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4226}else{4227@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4228}42294230my$show_ctags= gitweb_check_feature('ctags');4231if($show_ctags) {4232my%ctags;4233foreachmy$p(@projects) {4234foreachmy$ct(keys%{$p->{'ctags'}}) {4235$ctags{$ct} +=$p->{'ctags'}->{$ct};4236}4237}4238my$cloud= git_populate_project_tagcloud(\%ctags);4239print git_show_project_tagcloud($cloud,64);4240}42414242print"<table class=\"project_list\">\n";4243unless($no_header) {4244print"<tr>\n";4245if($check_forks) {4246print"<th></th>\n";4247}4248 print_sort_th('project',$order,'Project');4249 print_sort_th('descr',$order,'Description');4250 print_sort_th('owner',$order,'Owner');4251 print_sort_th('age',$order,'Last Change');4252print"<th></th>\n".# for links4253"</tr>\n";4254}4255my$alternate=1;4256my$tagfilter=$cgi->param('by_tag');4257for(my$i=$from;$i<=$to;$i++) {4258my$pr=$projects[$i];42594260next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4261next if$searchtextand not$pr->{'path'} =~/$searchtext/4262and not$pr->{'descr_long'} =~/$searchtext/;4263# Weed out forks or non-matching entries of search4264if($check_forks) {4265my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4266$forkbase="^$forkbase"if$forkbase;4267next ifnot$searchtextand not$tagfilterand$show_ctags4268and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4269}42704271if($alternate) {4272print"<tr class=\"dark\">\n";4273}else{4274print"<tr class=\"light\">\n";4275}4276$alternate^=1;4277if($check_forks) {4278print"<td>";4279if($pr->{'forks'}) {4280print"<!--$pr->{'forks'} -->\n";4281print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4282}4283print"</td>\n";4284}4285print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4286-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4287"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4288-class=>"list", -title =>$pr->{'descr_long'}},4289 esc_html($pr->{'descr'})) ."</td>\n".4290"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4291print"<td class=\"". age_class($pr->{'age'}) ."\">".4292(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4293"<td class=\"link\">".4294$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4295$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4296$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4297$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4298($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4299"</td>\n".4300"</tr>\n";4301}4302if(defined$extra) {4303print"<tr>\n";4304if($check_forks) {4305print"<td></td>\n";4306}4307print"<td colspan=\"5\">$extra</td>\n".4308"</tr>\n";4309}4310print"</table>\n";4311}43124313sub git_shortlog_body {4314# uses global variable $project4315my($commitlist,$from,$to,$refs,$extra) =@_;43164317$from=0unlessdefined$from;4318$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);43194320print"<table class=\"shortlog\">\n";4321my$alternate=1;4322for(my$i=$from;$i<=$to;$i++) {4323my%co= %{$commitlist->[$i]};4324my$commit=$co{'id'};4325my$ref= format_ref_marker($refs,$commit);4326if($alternate) {4327print"<tr class=\"dark\">\n";4328}else{4329print"<tr class=\"light\">\n";4330}4331$alternate^=1;4332# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4333print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4334 format_author_html('td', \%co,10) ."<td>";4335print format_subject_html($co{'title'},$co{'title_short'},4336 href(action=>"commit", hash=>$commit),$ref);4337print"</td>\n".4338"<td class=\"link\">".4339$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4340$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4341$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4342my$snapshot_links= format_snapshot_links($commit);4343if(defined$snapshot_links) {4344print" | ".$snapshot_links;4345}4346print"</td>\n".4347"</tr>\n";4348}4349if(defined$extra) {4350print"<tr>\n".4351"<td colspan=\"4\">$extra</td>\n".4352"</tr>\n";4353}4354print"</table>\n";4355}43564357sub git_history_body {4358# Warning: assumes constant type (blob or tree) during history4359my($commitlist,$from,$to,$refs,$hash_base,$ftype,$extra) =@_;43604361$from=0unlessdefined$from;4362$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});43634364print"<table class=\"history\">\n";4365my$alternate=1;4366for(my$i=$from;$i<=$to;$i++) {4367my%co= %{$commitlist->[$i]};4368if(!%co) {4369next;4370}4371my$commit=$co{'id'};43724373my$ref= format_ref_marker($refs,$commit);43744375if($alternate) {4376print"<tr class=\"dark\">\n";4377}else{4378print"<tr class=\"light\">\n";4379}4380$alternate^=1;4381print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4382# shortlog: format_author_html('td', \%co, 10)4383 format_author_html('td', \%co,15,3) ."<td>";4384# originally git_history used chop_str($co{'title'}, 50)4385print format_subject_html($co{'title'},$co{'title_short'},4386 href(action=>"commit", hash=>$commit),$ref);4387print"</td>\n".4388"<td class=\"link\">".4389$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4390$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");43914392if($ftypeeq'blob') {4393my$blob_current= git_get_hash_by_path($hash_base,$file_name);4394my$blob_parent= git_get_hash_by_path($commit,$file_name);4395if(defined$blob_current&&defined$blob_parent&&4396$blob_currentne$blob_parent) {4397print" | ".4398$cgi->a({-href => href(action=>"blobdiff",4399 hash=>$blob_current, hash_parent=>$blob_parent,4400 hash_base=>$hash_base, hash_parent_base=>$commit,4401 file_name=>$file_name)},4402"diff to current");4403}4404}4405print"</td>\n".4406"</tr>\n";4407}4408if(defined$extra) {4409print"<tr>\n".4410"<td colspan=\"4\">$extra</td>\n".4411"</tr>\n";4412}4413print"</table>\n";4414}44154416sub git_tags_body {4417# uses global variable $project4418my($taglist,$from,$to,$extra) =@_;4419$from=0unlessdefined$from;4420$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);44214422print"<table class=\"tags\">\n";4423my$alternate=1;4424for(my$i=$from;$i<=$to;$i++) {4425my$entry=$taglist->[$i];4426my%tag=%$entry;4427my$comment=$tag{'subject'};4428my$comment_short;4429if(defined$comment) {4430$comment_short= chop_str($comment,30,5);4431}4432if($alternate) {4433print"<tr class=\"dark\">\n";4434}else{4435print"<tr class=\"light\">\n";4436}4437$alternate^=1;4438if(defined$tag{'age'}) {4439print"<td><i>$tag{'age'}</i></td>\n";4440}else{4441print"<td></td>\n";4442}4443print"<td>".4444$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4445-class=>"list name"}, esc_html($tag{'name'})) .4446"</td>\n".4447"<td>";4448if(defined$comment) {4449print format_subject_html($comment,$comment_short,4450 href(action=>"tag", hash=>$tag{'id'}));4451}4452print"</td>\n".4453"<td class=\"selflink\">";4454if($tag{'type'}eq"tag") {4455print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4456}else{4457print" ";4458}4459print"</td>\n".4460"<td class=\"link\">"." | ".4461$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4462if($tag{'reftype'}eq"commit") {4463print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4464" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4465}elsif($tag{'reftype'}eq"blob") {4466print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4467}4468print"</td>\n".4469"</tr>";4470}4471if(defined$extra) {4472print"<tr>\n".4473"<td colspan=\"5\">$extra</td>\n".4474"</tr>\n";4475}4476print"</table>\n";4477}44784479sub git_heads_body {4480# uses global variable $project4481my($headlist,$head,$from,$to,$extra) =@_;4482$from=0unlessdefined$from;4483$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);44844485print"<table class=\"heads\">\n";4486my$alternate=1;4487for(my$i=$from;$i<=$to;$i++) {4488my$entry=$headlist->[$i];4489my%ref=%$entry;4490my$curr=$ref{'id'}eq$head;4491if($alternate) {4492print"<tr class=\"dark\">\n";4493}else{4494print"<tr class=\"light\">\n";4495}4496$alternate^=1;4497print"<td><i>$ref{'age'}</i></td>\n".4498($curr?"<td class=\"current_head\">":"<td>") .4499$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4500-class=>"list name"},esc_html($ref{'name'})) .4501"</td>\n".4502"<td class=\"link\">".4503$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4504$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4505$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4506"</td>\n".4507"</tr>";4508}4509if(defined$extra) {4510print"<tr>\n".4511"<td colspan=\"3\">$extra</td>\n".4512"</tr>\n";4513}4514print"</table>\n";4515}45164517sub git_search_grep_body {4518my($commitlist,$from,$to,$extra) =@_;4519$from=0unlessdefined$from;4520$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);45214522print"<table class=\"commit_search\">\n";4523my$alternate=1;4524for(my$i=$from;$i<=$to;$i++) {4525my%co= %{$commitlist->[$i]};4526if(!%co) {4527next;4528}4529my$commit=$co{'id'};4530if($alternate) {4531print"<tr class=\"dark\">\n";4532}else{4533print"<tr class=\"light\">\n";4534}4535$alternate^=1;4536print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4537 format_author_html('td', \%co,15,5) .4538"<td>".4539$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4540-class=>"list subject"},4541 chop_and_escape_str($co{'title'},50) ."<br/>");4542my$comment=$co{'comment'};4543foreachmy$line(@$comment) {4544if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4545my($lead,$match,$trail) = ($1,$2,$3);4546$match= chop_str($match,70,5,'center');4547my$contextlen=int((80-length($match))/2);4548$contextlen=30if($contextlen>30);4549$lead= chop_str($lead,$contextlen,10,'left');4550$trail= chop_str($trail,$contextlen,10,'right');45514552$lead= esc_html($lead);4553$match= esc_html($match);4554$trail= esc_html($trail);45554556print"$lead<span class=\"match\">$match</span>$trail<br />";4557}4558}4559print"</td>\n".4560"<td class=\"link\">".4561$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4562" | ".4563$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4564" | ".4565$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4566print"</td>\n".4567"</tr>\n";4568}4569if(defined$extra) {4570print"<tr>\n".4571"<td colspan=\"3\">$extra</td>\n".4572"</tr>\n";4573}4574print"</table>\n";4575}45764577## ======================================================================4578## ======================================================================4579## actions45804581sub git_project_list {4582my$order=$input_params{'order'};4583if(defined$order&&$order!~m/none|project|descr|owner|age/) {4584 die_error(400,"Unknown order parameter");4585}45864587my@list= git_get_projects_list();4588if(!@list) {4589 die_error(404,"No projects found");4590}45914592 git_header_html();4593if(-f $home_text) {4594print"<div class=\"index_include\">\n";4595 insert_file($home_text);4596print"</div>\n";4597}4598print$cgi->startform(-method=>"get") .4599"<p class=\"projsearch\">Search:\n".4600$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4601"</p>".4602$cgi->end_form() ."\n";4603 git_project_list_body(\@list,$order);4604 git_footer_html();4605}46064607sub git_forks {4608my$order=$input_params{'order'};4609if(defined$order&&$order!~m/none|project|descr|owner|age/) {4610 die_error(400,"Unknown order parameter");4611}46124613my@list= git_get_projects_list($project);4614if(!@list) {4615 die_error(404,"No forks found");4616}46174618 git_header_html();4619 git_print_page_nav('','');4620 git_print_header_div('summary',"$projectforks");4621 git_project_list_body(\@list,$order);4622 git_footer_html();4623}46244625sub git_project_index {4626my@projects= git_get_projects_list($project);46274628print$cgi->header(4629-type =>'text/plain',4630-charset =>'utf-8',4631-content_disposition =>'inline; filename="index.aux"');46324633foreachmy$pr(@projects) {4634if(!exists$pr->{'owner'}) {4635$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4636}46374638my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4639# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4640$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4641$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4642$path=~s/ /\+/g;4643$owner=~s/ /\+/g;46444645print"$path$owner\n";4646}4647}46484649sub git_summary {4650my$descr= git_get_project_description($project) ||"none";4651my%co= parse_commit("HEAD");4652my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4653my$head=$co{'id'};46544655my$owner= git_get_project_owner($project);46564657my$refs= git_get_references();4658# These get_*_list functions return one more to allow us to see if4659# there are more ...4660my@taglist= git_get_tags_list(16);4661my@headlist= git_get_heads_list(16);4662my@forklist;4663my$check_forks= gitweb_check_feature('forks');46644665if($check_forks) {4666@forklist= git_get_projects_list($project);4667}46684669 git_header_html();4670 git_print_page_nav('summary','',$head);46714672print"<div class=\"title\"> </div>\n";4673print"<table class=\"projects_list\">\n".4674"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4675"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4676if(defined$cd{'rfc2822'}) {4677print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4678}46794680# use per project git URL list in $projectroot/$project/cloneurl4681# or make project git URL from git base URL and project name4682my$url_tag="URL";4683my@url_list= git_get_project_url_list($project);4684@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4685foreachmy$git_url(@url_list) {4686next unless$git_url;4687print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4688$url_tag="";4689}46904691# Tag cloud4692my$show_ctags= gitweb_check_feature('ctags');4693if($show_ctags) {4694my$ctags= git_get_project_ctags($project);4695my$cloud= git_populate_project_tagcloud($ctags);4696print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4697print"</td>\n<td>"unless%$ctags;4698print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4699print"</td>\n<td>"if%$ctags;4700print git_show_project_tagcloud($cloud,48);4701print"</td></tr>";4702}47034704print"</table>\n";47054706# If XSS prevention is on, we don't include README.html.4707# TODO: Allow a readme in some safe format.4708if(!$prevent_xss&& -s "$projectroot/$project/README.html") {4709print"<div class=\"title\">readme</div>\n".4710"<div class=\"readme\">\n";4711 insert_file("$projectroot/$project/README.html");4712print"\n</div>\n";# class="readme"4713}47144715# we need to request one more than 16 (0..15) to check if4716# those 16 are all4717my@commitlist=$head? parse_commits($head,17) : ();4718if(@commitlist) {4719 git_print_header_div('shortlog');4720 git_shortlog_body(\@commitlist,0,15,$refs,4721$#commitlist<=15?undef:4722$cgi->a({-href => href(action=>"shortlog")},"..."));4723}47244725if(@taglist) {4726 git_print_header_div('tags');4727 git_tags_body(\@taglist,0,15,4728$#taglist<=15?undef:4729$cgi->a({-href => href(action=>"tags")},"..."));4730}47314732if(@headlist) {4733 git_print_header_div('heads');4734 git_heads_body(\@headlist,$head,0,15,4735$#headlist<=15?undef:4736$cgi->a({-href => href(action=>"heads")},"..."));4737}47384739if(@forklist) {4740 git_print_header_div('forks');4741 git_project_list_body(\@forklist,'age',0,15,4742$#forklist<=15?undef:4743$cgi->a({-href => href(action=>"forks")},"..."),4744'no_header');4745}47464747 git_footer_html();4748}47494750sub git_tag {4751my$head= git_get_head_hash($project);4752 git_header_html();4753 git_print_page_nav('','',$head,undef,$head);4754my%tag= parse_tag($hash);47554756if(!%tag) {4757 die_error(404,"Unknown tag object");4758}47594760 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4761print"<div class=\"title_text\">\n".4762"<table class=\"object_header\">\n".4763"<tr>\n".4764"<td>object</td>\n".4765"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4766$tag{'object'}) ."</td>\n".4767"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4768$tag{'type'}) ."</td>\n".4769"</tr>\n";4770if(defined($tag{'author'})) {4771 git_print_authorship_rows(\%tag,'author');4772}4773print"</table>\n\n".4774"</div>\n";4775print"<div class=\"page_body\">";4776my$comment=$tag{'comment'};4777foreachmy$line(@$comment) {4778chomp$line;4779print esc_html($line, -nbsp=>1) ."<br/>\n";4780}4781print"</div>\n";4782 git_footer_html();4783}47844785sub git_blame {4786# permissions4787 gitweb_check_feature('blame')4788or die_error(403,"Blame view not allowed");47894790# error checking4791 die_error(400,"No file name given")unless$file_name;4792$hash_base||= git_get_head_hash($project);4793 die_error(404,"Couldn't find base commit")unless$hash_base;4794my%co= parse_commit($hash_base)4795or die_error(404,"Commit not found");4796my$ftype="blob";4797if(!defined$hash) {4798$hash= git_get_hash_by_path($hash_base,$file_name,"blob")4799or die_error(404,"Error looking up file");4800}else{4801$ftype= git_get_type($hash);4802if($ftype!~"blob") {4803 die_error(400,"Object is not a blob");4804}4805}48064807# run git-blame --porcelain4808open my$fd,"-|", git_cmd(),"blame",'-p',4809$hash_base,'--',$file_name4810or die_error(500,"Open git-blame failed");48114812# page header4813 git_header_html();4814my$formats_nav=4815$cgi->a({-href => href(action=>"blob", -replay=>1)},4816"blob") .4817" | ".4818$cgi->a({-href => href(action=>"history", -replay=>1)},4819"history") .4820" | ".4821$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},4822"HEAD");4823 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4824 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4825 git_print_page_path($file_name,$ftype,$hash_base);48264827# page body4828my@rev_color=qw(light dark);4829my$num_colors=scalar(@rev_color);4830my$current_color=0;4831my%metainfo= ();48324833print<<HTML;4834<div class="page_body">4835<table class="blame">4836<tr><th>Commit</th><th>Line</th><th>Data</th></tr>4837HTML4838 LINE:4839while(my$line= <$fd>) {4840chomp$line;4841# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]4842# no <lines in group> for subsequent lines in group of lines4843my($full_rev,$orig_lineno,$lineno,$group_size) =4844($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);4845if(!exists$metainfo{$full_rev}) {4846$metainfo{$full_rev} = {'nprevious'=>0};4847}4848my$meta=$metainfo{$full_rev};4849my$data;4850while($data= <$fd>) {4851chomp$data;4852last if($data=~s/^\t//);# contents of line4853if($data=~/^(\S+)(?: (.*))?$/) {4854$meta->{$1} =$2unlessexists$meta->{$1};4855}4856if($data=~/^previous /) {4857$meta->{'nprevious'}++;4858}4859}4860my$short_rev=substr($full_rev,0,8);4861my$author=$meta->{'author'};4862my%date=4863 parse_date($meta->{'author-time'},$meta->{'author-tz'});4864my$date=$date{'iso-tz'};4865if($group_size) {4866$current_color= ($current_color+1) %$num_colors;4867}4868my$tr_class=$rev_color[$current_color];4869$tr_class.=' boundary'if(exists$meta->{'boundary'});4870$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);4871$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);4872print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";4873if($group_size) {4874print"<td class=\"sha1\"";4875print" title=\"". esc_html($author) .",$date\"";4876print" rowspan=\"$group_size\""if($group_size>1);4877print">";4878print$cgi->a({-href => href(action=>"commit",4879 hash=>$full_rev,4880 file_name=>$file_name)},4881 esc_html($short_rev));4882if($group_size>=2) {4883my@author_initials= ($author=~/\b([[:upper:]])\B/g);4884if(@author_initials) {4885print"<br />".4886 esc_html(join('',@author_initials));4887# or join('.', ...)4888}4889}4890print"</td>\n";4891}4892# 'previous' <sha1 of parent commit> <filename at commit>4893if(exists$meta->{'previous'} &&4894$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {4895$meta->{'parent'} =$1;4896$meta->{'file_parent'} = unquote($2);4897}4898my$linenr_commit=4899exists($meta->{'parent'}) ?4900$meta->{'parent'} :$full_rev;4901my$linenr_filename=4902exists($meta->{'file_parent'}) ?4903$meta->{'file_parent'} : unquote($meta->{'filename'});4904my$blamed= href(action =>'blame',4905 file_name =>$linenr_filename,4906 hash_base =>$linenr_commit);4907print"<td class=\"linenr\">";4908print$cgi->a({ -href =>"$blamed#l$orig_lineno",4909-class=>"linenr"},4910 esc_html($lineno));4911print"</td>";4912print"<td class=\"pre\">". esc_html($data) ."</td>\n";4913print"</tr>\n";4914}4915print"</table>\n";4916print"</div>";4917close$fd4918or print"Reading blob failed\n";49194920# page footer4921 git_footer_html();4922}49234924sub git_tags {4925my$head= git_get_head_hash($project);4926 git_header_html();4927 git_print_page_nav('','',$head,undef,$head);4928 git_print_header_div('summary',$project);49294930my@tagslist= git_get_tags_list();4931if(@tagslist) {4932 git_tags_body(\@tagslist);4933}4934 git_footer_html();4935}49364937sub git_heads {4938my$head= git_get_head_hash($project);4939 git_header_html();4940 git_print_page_nav('','',$head,undef,$head);4941 git_print_header_div('summary',$project);49424943my@headslist= git_get_heads_list();4944if(@headslist) {4945 git_heads_body(\@headslist,$head);4946}4947 git_footer_html();4948}49494950sub git_blob_plain {4951my$type=shift;4952my$expires;49534954if(!defined$hash) {4955if(defined$file_name) {4956my$base=$hash_base|| git_get_head_hash($project);4957$hash= git_get_hash_by_path($base,$file_name,"blob")4958or die_error(404,"Cannot find file");4959}else{4960 die_error(400,"No file name defined");4961}4962}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4963# blobs defined by non-textual hash id's can be cached4964$expires="+1d";4965}49664967open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4968or die_error(500,"Open git-cat-file blob '$hash' failed");49694970# content-type (can include charset)4971$type= blob_contenttype($fd,$file_name,$type);49724973# "save as" filename, even when no $file_name is given4974my$save_as="$hash";4975if(defined$file_name) {4976$save_as=$file_name;4977}elsif($type=~m/^text\//) {4978$save_as.='.txt';4979}49804981# With XSS prevention on, blobs of all types except a few known safe4982# ones are served with "Content-Disposition: attachment" to make sure4983# they don't run in our security domain. For certain image types,4984# blob view writes an <img> tag referring to blob_plain view, and we4985# want to be sure not to break that by serving the image as an4986# attachment (though Firefox 3 doesn't seem to care).4987my$sandbox=$prevent_xss&&4988$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;49894990print$cgi->header(4991-type =>$type,4992-expires =>$expires,4993-content_disposition =>4994($sandbox?'attachment':'inline')4995.'; filename="'.$save_as.'"');4996local$/=undef;4997binmode STDOUT,':raw';4998print<$fd>;4999binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5000close$fd;5001}50025003sub git_blob {5004my$expires;50055006if(!defined$hash) {5007if(defined$file_name) {5008my$base=$hash_base|| git_get_head_hash($project);5009$hash= git_get_hash_by_path($base,$file_name,"blob")5010or die_error(404,"Cannot find file");5011}else{5012 die_error(400,"No file name defined");5013}5014}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5015# blobs defined by non-textual hash id's can be cached5016$expires="+1d";5017}50185019my$have_blame= gitweb_check_feature('blame');5020open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5021or die_error(500,"Couldn't cat$file_name,$hash");5022my$mimetype= blob_mimetype($fd,$file_name);5023if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {5024close$fd;5025return git_blob_plain($mimetype);5026}5027# we can have blame only for text/* mimetype5028$have_blame&&= ($mimetype=~m!^text/!);50295030 git_header_html(undef,$expires);5031my$formats_nav='';5032if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5033if(defined$file_name) {5034if($have_blame) {5035$formats_nav.=5036$cgi->a({-href => href(action=>"blame", -replay=>1)},5037"blame") .5038" | ";5039}5040$formats_nav.=5041$cgi->a({-href => href(action=>"history", -replay=>1)},5042"history") .5043" | ".5044$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5045"raw") .5046" | ".5047$cgi->a({-href => href(action=>"blob",5048 hash_base=>"HEAD", file_name=>$file_name)},5049"HEAD");5050}else{5051$formats_nav.=5052$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5053"raw");5054}5055 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5056 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5057}else{5058print"<div class=\"page_nav\">\n".5059"<br/><br/></div>\n".5060"<div class=\"title\">$hash</div>\n";5061}5062 git_print_page_path($file_name,"blob",$hash_base);5063print"<div class=\"page_body\">\n";5064if($mimetype=~m!^image/!) {5065print qq!<img type="$mimetype"!;5066if($file_name) {5067print qq! alt="$file_name" title="$file_name"!;5068}5069print qq! src="! .5070 href(action=>"blob_plain", hash=>$hash,5071 hash_base=>$hash_base, file_name=>$file_name) .5072 qq!"/>\n!;5073}else{5074my$nr;5075while(my$line= <$fd>) {5076chomp$line;5077$nr++;5078$line= untabify($line);5079printf"<div class=\"pre\"><a id=\"l%i\"href=\"#l%i\"class=\"linenr\">%4i</a>%s</div>\n",5080$nr,$nr,$nr, esc_html($line, -nbsp=>1);5081}5082}5083close$fd5084or print"Reading blob failed.\n";5085print"</div>";5086 git_footer_html();5087}50885089sub git_tree {5090if(!defined$hash_base) {5091$hash_base="HEAD";5092}5093if(!defined$hash) {5094if(defined$file_name) {5095$hash= git_get_hash_by_path($hash_base,$file_name,"tree");5096}else{5097$hash=$hash_base;5098}5099}5100 die_error(404,"No such tree")unlessdefined($hash);51015102my@entries= ();5103{5104local$/="\0";5105open my$fd,"-|", git_cmd(),"ls-tree",'-z',$hash5106or die_error(500,"Open git-ls-tree failed");5107@entries=map{chomp;$_} <$fd>;5108close$fd5109or die_error(404,"Reading tree failed");5110}51115112my$refs= git_get_references();5113my$ref= format_ref_marker($refs,$hash_base);5114 git_header_html();5115my$basedir='';5116my$have_blame= gitweb_check_feature('blame');5117if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5118my@views_nav= ();5119if(defined$file_name) {5120push@views_nav,5121$cgi->a({-href => href(action=>"history", -replay=>1)},5122"history"),5123$cgi->a({-href => href(action=>"tree",5124 hash_base=>"HEAD", file_name=>$file_name)},5125"HEAD"),5126}5127my$snapshot_links= format_snapshot_links($hash);5128if(defined$snapshot_links) {5129# FIXME: Should be available when we have no hash base as well.5130push@views_nav,$snapshot_links;5131}5132 git_print_page_nav('tree','',$hash_base,undef,undef,join(' | ',@views_nav));5133 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);5134}else{5135undef$hash_base;5136print"<div class=\"page_nav\">\n";5137print"<br/><br/></div>\n";5138print"<div class=\"title\">$hash</div>\n";5139}5140if(defined$file_name) {5141$basedir=$file_name;5142if($basedirne''&&substr($basedir, -1)ne'/') {5143$basedir.='/';5144}5145 git_print_page_path($file_name,'tree',$hash_base);5146}5147print"<div class=\"page_body\">\n";5148print"<table class=\"tree\">\n";5149my$alternate=1;5150# '..' (top directory) link if possible5151if(defined$hash_base&&5152defined$file_name&&$file_name=~m![^/]+$!) {5153if($alternate) {5154print"<tr class=\"dark\">\n";5155}else{5156print"<tr class=\"light\">\n";5157}5158$alternate^=1;51595160my$up=$file_name;5161$up=~s!/?[^/]+$!!;5162undef$upunless$up;5163# based on git_print_tree_entry5164print'<td class="mode">'. mode_str('040000') ."</td>\n";5165print'<td class="list">';5166print$cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,5167 file_name=>$up)},5168"..");5169print"</td>\n";5170print"<td class=\"link\"></td>\n";51715172print"</tr>\n";5173}5174foreachmy$line(@entries) {5175my%t= parse_ls_tree_line($line, -z =>1);51765177if($alternate) {5178print"<tr class=\"dark\">\n";5179}else{5180print"<tr class=\"light\">\n";5181}5182$alternate^=1;51835184 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);51855186print"</tr>\n";5187}5188print"</table>\n".5189"</div>";5190 git_footer_html();5191}51925193sub snapshot_name {5194my($project,$hash) =@_;51955196# path/to/project.git -> project5197# path/to/project/.git -> project5198my$name= to_utf8($project);5199$name=~ s,([^/])/*\.git$,$1,;5200$name= basename($name);5201# sanitize name5202$name=~s/[[:cntrl:]]/?/g;52035204my$ver=$hash;5205if($hash=~/^[0-9a-fA-F]+$/) {5206# shorten SHA-1 hash5207my$full_hash= git_get_full_hash($project,$hash);5208if($full_hash=~/^$hash/&&length($hash) >7) {5209$ver= git_get_short_hash($project,$hash);5210}5211}elsif($hash=~m!^refs/tags/(.*)$!) {5212# tags don't need shortened SHA-1 hash5213$ver=$1;5214}else{5215# branches and other need shortened SHA-1 hash5216if($hash=~m!^refs/(?:heads|remotes)/(.*)$!) {5217$ver=$1;5218}5219$ver.='-'. git_get_short_hash($project,$hash);5220}5221# in case of hierarchical branch names5222$ver=~s!/!.!g;52235224# name = project-version_string5225$name="$name-$ver";52265227returnwantarray? ($name,$name) :$name;5228}52295230sub git_snapshot {5231my$format=$input_params{'snapshot_format'};5232if(!@snapshot_fmts) {5233 die_error(403,"Snapshots not allowed");5234}5235# default to first supported snapshot format5236$format||=$snapshot_fmts[0];5237if($format!~m/^[a-z0-9]+$/) {5238 die_error(400,"Invalid snapshot format parameter");5239}elsif(!exists($known_snapshot_formats{$format})) {5240 die_error(400,"Unknown snapshot format");5241}elsif($known_snapshot_formats{$format}{'disabled'}) {5242 die_error(403,"Snapshot format not allowed");5243}elsif(!grep($_eq$format,@snapshot_fmts)) {5244 die_error(403,"Unsupported snapshot format");5245}52465247my$type= git_get_type("$hash^{}");5248if(!$type) {5249 die_error(404,'Object does not exist');5250}elsif($typeeq'blob') {5251 die_error(400,'Object is not a tree-ish');5252}52535254my($name,$prefix) = snapshot_name($project,$hash);5255my$filename="$name$known_snapshot_formats{$format}{'suffix'}";5256my$cmd= quote_command(5257 git_cmd(),'archive',5258"--format=$known_snapshot_formats{$format}{'format'}",5259"--prefix=$prefix/",$hash);5260if(exists$known_snapshot_formats{$format}{'compressor'}) {5261$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});5262}52635264$filename=~s/(["\\])/\\$1/g;5265print$cgi->header(5266-type =>$known_snapshot_formats{$format}{'type'},5267-content_disposition =>'inline; filename="'.$filename.'"',5268-status =>'200 OK');52695270open my$fd,"-|",$cmd5271or die_error(500,"Execute git-archive failed");5272binmode STDOUT,':raw';5273print<$fd>;5274binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5275close$fd;5276}52775278sub git_log {5279my$head= git_get_head_hash($project);5280if(!defined$hash) {5281$hash=$head;5282}5283if(!defined$page) {5284$page=0;5285}5286my$refs= git_get_references();52875288my@commitlist= parse_commits($hash,101, (100*$page));52895290my$paging_nav= format_paging_nav('log',$hash,$head,$page,$#commitlist>=100);52915292my($patch_max) = gitweb_get_feature('patches');5293if($patch_max) {5294if($patch_max<0||@commitlist<=$patch_max) {5295$paging_nav.=" ⋅ ".5296$cgi->a({-href => href(action=>"patches", -replay=>1)},5297"patches");5298}5299}53005301 git_header_html();5302 git_print_page_nav('log','',$hash,undef,undef,$paging_nav);53035304if(!@commitlist) {5305my%co= parse_commit($hash);53065307 git_print_header_div('summary',$project);5308print"<div class=\"page_body\"> Last change$co{'age_string'}.<br/><br/></div>\n";5309}5310my$to= ($#commitlist>=99) ? (99) : ($#commitlist);5311for(my$i=0;$i<=$to;$i++) {5312my%co= %{$commitlist[$i]};5313next if!%co;5314my$commit=$co{'id'};5315my$ref= format_ref_marker($refs,$commit);5316my%ad= parse_date($co{'author_epoch'});5317 git_print_header_div('commit',5318"<span class=\"age\">$co{'age_string'}</span>".5319 esc_html($co{'title'}) .$ref,5320$commit);5321print"<div class=\"title_text\">\n".5322"<div class=\"log_link\">\n".5323$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .5324" | ".5325$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .5326" | ".5327$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .5328"<br/>\n".5329"</div>\n";5330 git_print_authorship(\%co, -tag =>'span');5331print"<br/>\n</div>\n";53325333print"<div class=\"log_body\">\n";5334 git_print_log($co{'comment'}, -final_empty_line=>1);5335print"</div>\n";5336}5337if($#commitlist>=100) {5338print"<div class=\"page_nav\">\n";5339print$cgi->a({-href => href(-replay=>1, page=>$page+1),5340-accesskey =>"n", -title =>"Alt-n"},"next");5341print"</div>\n";5342}5343 git_footer_html();5344}53455346sub git_commit {5347$hash||=$hash_base||"HEAD";5348my%co= parse_commit($hash)5349or die_error(404,"Unknown commit object");53505351my$parent=$co{'parent'};5352my$parents=$co{'parents'};# listref53535354# we need to prepare $formats_nav before any parameter munging5355my$formats_nav;5356if(!defined$parent) {5357# --root commitdiff5358$formats_nav.='(initial)';5359}elsif(@$parents==1) {5360# single parent commit5361$formats_nav.=5362'(parent: '.5363$cgi->a({-href => href(action=>"commit",5364 hash=>$parent)},5365 esc_html(substr($parent,0,7))) .5366')';5367}else{5368# merge commit5369$formats_nav.=5370'(merge: '.5371join(' ',map{5372$cgi->a({-href => href(action=>"commit",5373 hash=>$_)},5374 esc_html(substr($_,0,7)));5375}@$parents) .5376')';5377}5378if(gitweb_check_feature('patches')) {5379$formats_nav.=" | ".5380$cgi->a({-href => href(action=>"patch", -replay=>1)},5381"patch");5382}53835384if(!defined$parent) {5385$parent="--root";5386}5387my@difftree;5388open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5389@diff_opts,5390(@$parents<=1?$parent:'-c'),5391$hash,"--"5392or die_error(500,"Open git-diff-tree failed");5393@difftree=map{chomp;$_} <$fd>;5394close$fdor die_error(404,"Reading git-diff-tree failed");53955396# non-textual hash id's can be cached5397my$expires;5398if($hash=~m/^[0-9a-fA-F]{40}$/) {5399$expires="+1d";5400}5401my$refs= git_get_references();5402my$ref= format_ref_marker($refs,$co{'id'});54035404 git_header_html(undef,$expires);5405 git_print_page_nav('commit','',5406$hash,$co{'tree'},$hash,5407$formats_nav);54085409if(defined$co{'parent'}) {5410 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5411}else{5412 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5413}5414print"<div class=\"title_text\">\n".5415"<table class=\"object_header\">\n";5416 git_print_authorship_rows(\%co);5417print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";5418print"<tr>".5419"<td>tree</td>".5420"<td class=\"sha1\">".5421$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),5422class=>"list"},$co{'tree'}) .5423"</td>".5424"<td class=\"link\">".5425$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},5426"tree");5427my$snapshot_links= format_snapshot_links($hash);5428if(defined$snapshot_links) {5429print" | ".$snapshot_links;5430}5431print"</td>".5432"</tr>\n";54335434foreachmy$par(@$parents) {5435print"<tr>".5436"<td>parent</td>".5437"<td class=\"sha1\">".5438$cgi->a({-href => href(action=>"commit", hash=>$par),5439class=>"list"},$par) .5440"</td>".5441"<td class=\"link\">".5442$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .5443" | ".5444$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .5445"</td>".5446"</tr>\n";5447}5448print"</table>".5449"</div>\n";54505451print"<div class=\"page_body\">\n";5452 git_print_log($co{'comment'});5453print"</div>\n";54545455 git_difftree_body(\@difftree,$hash,@$parents);54565457 git_footer_html();5458}54595460sub git_object {5461# object is defined by:5462# - hash or hash_base alone5463# - hash_base and file_name5464my$type;54655466# - hash or hash_base alone5467if($hash|| ($hash_base&& !defined$file_name)) {5468my$object_id=$hash||$hash_base;54695470open my$fd,"-|", quote_command(5471 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'5472or die_error(404,"Object does not exist");5473$type= <$fd>;5474chomp$type;5475close$fd5476or die_error(404,"Object does not exist");54775478# - hash_base and file_name5479}elsif($hash_base&&defined$file_name) {5480$file_name=~ s,/+$,,;54815482system(git_cmd(),"cat-file",'-e',$hash_base) ==05483or die_error(404,"Base object does not exist");54845485# here errors should not hapen5486open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name5487or die_error(500,"Open git-ls-tree failed");5488my$line= <$fd>;5489close$fd;54905491#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'5492unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {5493 die_error(404,"File or directory for given base does not exist");5494}5495$type=$2;5496$hash=$3;5497}else{5498 die_error(400,"Not enough information to find object");5499}55005501print$cgi->redirect(-uri => href(action=>$type, -full=>1,5502 hash=>$hash, hash_base=>$hash_base,5503 file_name=>$file_name),5504-status =>'302 Found');5505}55065507sub git_blobdiff {5508my$format=shift||'html';55095510my$fd;5511my@difftree;5512my%diffinfo;5513my$expires;55145515# preparing $fd and %diffinfo for git_patchset_body5516# new style URI5517if(defined$hash_base&&defined$hash_parent_base) {5518if(defined$file_name) {5519# read raw output5520open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5521$hash_parent_base,$hash_base,5522"--", (defined$file_parent?$file_parent: ()),$file_name5523or die_error(500,"Open git-diff-tree failed");5524@difftree=map{chomp;$_} <$fd>;5525close$fd5526or die_error(404,"Reading git-diff-tree failed");5527@difftree5528or die_error(404,"Blob diff not found");55295530}elsif(defined$hash&&5531$hash=~/[0-9a-fA-F]{40}/) {5532# try to find filename from $hash55335534# read filtered raw output5535open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5536$hash_parent_base,$hash_base,"--"5537or die_error(500,"Open git-diff-tree failed");5538@difftree=5539# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5540# $hash == to_id5541grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5542map{chomp;$_} <$fd>;5543close$fd5544or die_error(404,"Reading git-diff-tree failed");5545@difftree5546or die_error(404,"Blob diff not found");55475548}else{5549 die_error(400,"Missing one of the blob diff parameters");5550}55515552if(@difftree>1) {5553 die_error(400,"Ambiguous blob diff specification");5554}55555556%diffinfo= parse_difftree_raw_line($difftree[0]);5557$file_parent||=$diffinfo{'from_file'} ||$file_name;5558$file_name||=$diffinfo{'to_file'};55595560$hash_parent||=$diffinfo{'from_id'};5561$hash||=$diffinfo{'to_id'};55625563# non-textual hash id's can be cached5564if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5565$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5566$expires='+1d';5567}55685569# open patch output5570open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5571'-p', ($formateq'html'?"--full-index": ()),5572$hash_parent_base,$hash_base,5573"--", (defined$file_parent?$file_parent: ()),$file_name5574or die_error(500,"Open git-diff-tree failed");5575}55765577# old/legacy style URI -- not generated anymore since 1.4.3.5578if(!%diffinfo) {5579 die_error('404 Not Found',"Missing one of the blob diff parameters")5580}55815582# header5583if($formateq'html') {5584my$formats_nav=5585$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5586"raw");5587 git_header_html(undef,$expires);5588if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5589 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5590 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5591}else{5592print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5593print"<div class=\"title\">$hashvs$hash_parent</div>\n";5594}5595if(defined$file_name) {5596 git_print_page_path($file_name,"blob",$hash_base);5597}else{5598print"<div class=\"page_path\"></div>\n";5599}56005601}elsif($formateq'plain') {5602print$cgi->header(5603-type =>'text/plain',5604-charset =>'utf-8',5605-expires =>$expires,5606-content_disposition =>'inline; filename="'."$file_name".'.patch"');56075608print"X-Git-Url: ".$cgi->self_url() ."\n\n";56095610}else{5611 die_error(400,"Unknown blobdiff format");5612}56135614# patch5615if($formateq'html') {5616print"<div class=\"page_body\">\n";56175618 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5619close$fd;56205621print"</div>\n";# class="page_body"5622 git_footer_html();56235624}else{5625while(my$line= <$fd>) {5626$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5627$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;56285629print$line;56305631last if$line=~m!^\+\+\+!;5632}5633local$/=undef;5634print<$fd>;5635close$fd;5636}5637}56385639sub git_blobdiff_plain {5640 git_blobdiff('plain');5641}56425643sub git_commitdiff {5644my%params=@_;5645my$format=$params{-format} ||'html';56465647my($patch_max) = gitweb_get_feature('patches');5648if($formateq'patch') {5649 die_error(403,"Patch view not allowed")unless$patch_max;5650}56515652$hash||=$hash_base||"HEAD";5653my%co= parse_commit($hash)5654or die_error(404,"Unknown commit object");56555656# choose format for commitdiff for merge5657if(!defined$hash_parent&& @{$co{'parents'}} >1) {5658$hash_parent='--cc';5659}5660# we need to prepare $formats_nav before almost any parameter munging5661my$formats_nav;5662if($formateq'html') {5663$formats_nav=5664$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},5665"raw");5666if($patch_max) {5667$formats_nav.=" | ".5668$cgi->a({-href => href(action=>"patch", -replay=>1)},5669"patch");5670}56715672if(defined$hash_parent&&5673$hash_parentne'-c'&&$hash_parentne'--cc') {5674# commitdiff with two commits given5675my$hash_parent_short=$hash_parent;5676if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {5677$hash_parent_short=substr($hash_parent,0,7);5678}5679$formats_nav.=5680' (from';5681for(my$i=0;$i< @{$co{'parents'}};$i++) {5682if($co{'parents'}[$i]eq$hash_parent) {5683$formats_nav.=' parent '. ($i+1);5684last;5685}5686}5687$formats_nav.=': '.5688$cgi->a({-href => href(action=>"commitdiff",5689 hash=>$hash_parent)},5690 esc_html($hash_parent_short)) .5691')';5692}elsif(!$co{'parent'}) {5693# --root commitdiff5694$formats_nav.=' (initial)';5695}elsif(scalar@{$co{'parents'}} ==1) {5696# single parent commit5697$formats_nav.=5698' (parent: '.5699$cgi->a({-href => href(action=>"commitdiff",5700 hash=>$co{'parent'})},5701 esc_html(substr($co{'parent'},0,7))) .5702')';5703}else{5704# merge commit5705if($hash_parenteq'--cc') {5706$formats_nav.=' | '.5707$cgi->a({-href => href(action=>"commitdiff",5708 hash=>$hash, hash_parent=>'-c')},5709'combined');5710}else{# $hash_parent eq '-c'5711$formats_nav.=' | '.5712$cgi->a({-href => href(action=>"commitdiff",5713 hash=>$hash, hash_parent=>'--cc')},5714'compact');5715}5716$formats_nav.=5717' (merge: '.5718join(' ',map{5719$cgi->a({-href => href(action=>"commitdiff",5720 hash=>$_)},5721 esc_html(substr($_,0,7)));5722} @{$co{'parents'}} ) .5723')';5724}5725}57265727my$hash_parent_param=$hash_parent;5728if(!defined$hash_parent_param) {5729# --cc for multiple parents, --root for parentless5730$hash_parent_param=5731@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';5732}57335734# read commitdiff5735my$fd;5736my@difftree;5737if($formateq'html') {5738open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5739"--no-commit-id","--patch-with-raw","--full-index",5740$hash_parent_param,$hash,"--"5741or die_error(500,"Open git-diff-tree failed");57425743while(my$line= <$fd>) {5744chomp$line;5745# empty line ends raw part of diff-tree output5746last unless$line;5747push@difftree,scalar parse_difftree_raw_line($line);5748}57495750}elsif($formateq'plain') {5751open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5752'-p',$hash_parent_param,$hash,"--"5753or die_error(500,"Open git-diff-tree failed");5754}elsif($formateq'patch') {5755# For commit ranges, we limit the output to the number of5756# patches specified in the 'patches' feature.5757# For single commits, we limit the output to a single patch,5758# diverging from the git-format-patch default.5759my@commit_spec= ();5760if($hash_parent) {5761if($patch_max>0) {5762push@commit_spec,"-$patch_max";5763}5764push@commit_spec,'-n',"$hash_parent..$hash";5765}else{5766if($params{-single}) {5767push@commit_spec,'-1';5768}else{5769if($patch_max>0) {5770push@commit_spec,"-$patch_max";5771}5772push@commit_spec,"-n";5773}5774push@commit_spec,'--root',$hash;5775}5776open$fd,"-|", git_cmd(),"format-patch",'--encoding=utf8',5777'--stdout',@commit_spec5778or die_error(500,"Open git-format-patch failed");5779}else{5780 die_error(400,"Unknown commitdiff format");5781}57825783# non-textual hash id's can be cached5784my$expires;5785if($hash=~m/^[0-9a-fA-F]{40}$/) {5786$expires="+1d";5787}57885789# write commit message5790if($formateq'html') {5791my$refs= git_get_references();5792my$ref= format_ref_marker($refs,$co{'id'});57935794 git_header_html(undef,$expires);5795 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);5796 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);5797print"<div class=\"title_text\">\n".5798"<table class=\"object_header\">\n";5799 git_print_authorship_rows(\%co);5800print"</table>".5801"</div>\n";5802print"<div class=\"page_body\">\n";5803if(@{$co{'comment'}} >1) {5804print"<div class=\"log\">\n";5805 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);5806print"</div>\n";# class="log"5807}58085809}elsif($formateq'plain') {5810my$refs= git_get_references("tags");5811my$tagname= git_get_rev_name_tags($hash);5812my$filename= basename($project) ."-$hash.patch";58135814print$cgi->header(5815-type =>'text/plain',5816-charset =>'utf-8',5817-expires =>$expires,5818-content_disposition =>'inline; filename="'."$filename".'"');5819my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5820print"From: ". to_utf8($co{'author'}) ."\n";5821print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";5822print"Subject: ". to_utf8($co{'title'}) ."\n";58235824print"X-Git-Tag:$tagname\n"if$tagname;5825print"X-Git-Url: ".$cgi->self_url() ."\n\n";58265827foreachmy$line(@{$co{'comment'}}) {5828print to_utf8($line) ."\n";5829}5830print"---\n\n";5831}elsif($formateq'patch') {5832my$filename= basename($project) ."-$hash.patch";58335834print$cgi->header(5835-type =>'text/plain',5836-charset =>'utf-8',5837-expires =>$expires,5838-content_disposition =>'inline; filename="'."$filename".'"');5839}58405841# write patch5842if($formateq'html') {5843my$use_parents= !defined$hash_parent||5844$hash_parenteq'-c'||$hash_parenteq'--cc';5845 git_difftree_body(\@difftree,$hash,5846$use_parents? @{$co{'parents'}} :$hash_parent);5847print"<br/>\n";58485849 git_patchset_body($fd, \@difftree,$hash,5850$use_parents? @{$co{'parents'}} :$hash_parent);5851close$fd;5852print"</div>\n";# class="page_body"5853 git_footer_html();58545855}elsif($formateq'plain') {5856local$/=undef;5857print<$fd>;5858close$fd5859or print"Reading git-diff-tree failed\n";5860}elsif($formateq'patch') {5861local$/=undef;5862print<$fd>;5863close$fd5864or print"Reading git-format-patch failed\n";5865}5866}58675868sub git_commitdiff_plain {5869 git_commitdiff(-format =>'plain');5870}58715872# format-patch-style patches5873sub git_patch {5874 git_commitdiff(-format =>'patch', -single=>1);5875}58765877sub git_patches {5878 git_commitdiff(-format =>'patch');5879}58805881sub git_history {5882if(!defined$hash_base) {5883$hash_base= git_get_head_hash($project);5884}5885if(!defined$page) {5886$page=0;5887}5888my$ftype;5889my%co= parse_commit($hash_base)5890or die_error(404,"Unknown commit object");58915892my$refs= git_get_references();5893my$limit=sprintf("--max-count=%i", (100* ($page+1)));58945895my@commitlist= parse_commits($hash_base,101, (100*$page),5896$file_name,"--full-history")5897or die_error(404,"No such file or directory on given branch");58985899if(!defined$hash&&defined$file_name) {5900# some commits could have deleted file in question,5901# and not have it in tree, but one of them has to have it5902for(my$i=0;$i<=@commitlist;$i++) {5903$hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5904last ifdefined$hash;5905}5906}5907if(defined$hash) {5908$ftype= git_get_type($hash);5909}5910if(!defined$ftype) {5911 die_error(500,"Unknown type of object");5912}59135914my$paging_nav='';5915if($page>0) {5916$paging_nav.=5917$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,5918 file_name=>$file_name)},5919"first");5920$paging_nav.=" ⋅ ".5921$cgi->a({-href => href(-replay=>1, page=>$page-1),5922-accesskey =>"p", -title =>"Alt-p"},"prev");5923}else{5924$paging_nav.="first";5925$paging_nav.=" ⋅ prev";5926}5927my$next_link='';5928if($#commitlist>=100) {5929$next_link=5930$cgi->a({-href => href(-replay=>1, page=>$page+1),5931-accesskey =>"n", -title =>"Alt-n"},"next");5932$paging_nav.=" ⋅$next_link";5933}else{5934$paging_nav.=" ⋅ next";5935}59365937 git_header_html();5938 git_print_page_nav('history','',$hash_base,$co{'tree'},$hash_base,$paging_nav);5939 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5940 git_print_page_path($file_name,$ftype,$hash_base);59415942 git_history_body(\@commitlist,0,99,5943$refs,$hash_base,$ftype,$next_link);59445945 git_footer_html();5946}59475948sub git_search {5949 gitweb_check_feature('search')or die_error(403,"Search is disabled");5950if(!defined$searchtext) {5951 die_error(400,"Text field is empty");5952}5953if(!defined$hash) {5954$hash= git_get_head_hash($project);5955}5956my%co= parse_commit($hash);5957if(!%co) {5958 die_error(404,"Unknown commit object");5959}5960if(!defined$page) {5961$page=0;5962}59635964$searchtype||='commit';5965if($searchtypeeq'pickaxe') {5966# pickaxe may take all resources of your box and run for several minutes5967# with every query - so decide by yourself how public you make this feature5968 gitweb_check_feature('pickaxe')5969or die_error(403,"Pickaxe is disabled");5970}5971if($searchtypeeq'grep') {5972 gitweb_check_feature('grep')5973or die_error(403,"Grep is disabled");5974}59755976 git_header_html();59775978if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {5979my$greptype;5980if($searchtypeeq'commit') {5981$greptype="--grep=";5982}elsif($searchtypeeq'author') {5983$greptype="--author=";5984}elsif($searchtypeeq'committer') {5985$greptype="--committer=";5986}5987$greptype.=$searchtext;5988my@commitlist= parse_commits($hash,101, (100*$page),undef,5989$greptype,'--regexp-ignore-case',5990$search_use_regexp?'--extended-regexp':'--fixed-strings');59915992my$paging_nav='';5993if($page>0) {5994$paging_nav.=5995$cgi->a({-href => href(action=>"search", hash=>$hash,5996 searchtext=>$searchtext,5997 searchtype=>$searchtype)},5998"first");5999$paging_nav.=" ⋅ ".6000$cgi->a({-href => href(-replay=>1, page=>$page-1),6001-accesskey =>"p", -title =>"Alt-p"},"prev");6002}else{6003$paging_nav.="first";6004$paging_nav.=" ⋅ prev";6005}6006my$next_link='';6007if($#commitlist>=100) {6008$next_link=6009$cgi->a({-href => href(-replay=>1, page=>$page+1),6010-accesskey =>"n", -title =>"Alt-n"},"next");6011$paging_nav.=" ⋅$next_link";6012}else{6013$paging_nav.=" ⋅ next";6014}60156016if($#commitlist>=100) {6017}60186019 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);6020 git_print_header_div('commit', esc_html($co{'title'}),$hash);6021 git_search_grep_body(\@commitlist,0,99,$next_link);6022}60236024if($searchtypeeq'pickaxe') {6025 git_print_page_nav('','',$hash,$co{'tree'},$hash);6026 git_print_header_div('commit', esc_html($co{'title'}),$hash);60276028print"<table class=\"pickaxe search\">\n";6029my$alternate=1;6030local$/="\n";6031open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,6032'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",6033($search_use_regexp?'--pickaxe-regex': ());6034undef%co;6035my@files;6036while(my$line= <$fd>) {6037chomp$line;6038next unless$line;60396040my%set= parse_difftree_raw_line($line);6041if(defined$set{'commit'}) {6042# finish previous commit6043if(%co) {6044print"</td>\n".6045"<td class=\"link\">".6046$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6047" | ".6048$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6049print"</td>\n".6050"</tr>\n";6051}60526053if($alternate) {6054print"<tr class=\"dark\">\n";6055}else{6056print"<tr class=\"light\">\n";6057}6058$alternate^=1;6059%co= parse_commit($set{'commit'});6060my$author= chop_and_escape_str($co{'author_name'},15,5);6061print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6062"<td><i>$author</i></td>\n".6063"<td>".6064$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6065-class=>"list subject"},6066 chop_and_escape_str($co{'title'},50) ."<br/>");6067}elsif(defined$set{'to_id'}) {6068next if($set{'to_id'} =~m/^0{40}$/);60696070print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6071 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6072-class=>"list"},6073"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6074"<br/>\n";6075}6076}6077close$fd;60786079# finish last commit (warning: repetition!)6080if(%co) {6081print"</td>\n".6082"<td class=\"link\">".6083$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6084" | ".6085$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6086print"</td>\n".6087"</tr>\n";6088}60896090print"</table>\n";6091}60926093if($searchtypeeq'grep') {6094 git_print_page_nav('','',$hash,$co{'tree'},$hash);6095 git_print_header_div('commit', esc_html($co{'title'}),$hash);60966097print"<table class=\"grep_search\">\n";6098my$alternate=1;6099my$matches=0;6100local$/="\n";6101open my$fd,"-|", git_cmd(),'grep','-n',6102$search_use_regexp? ('-E','-i') :'-F',6103$searchtext,$co{'tree'};6104my$lastfile='';6105while(my$line= <$fd>) {6106chomp$line;6107my($file,$lno,$ltext,$binary);6108last if($matches++>1000);6109if($line=~/^Binary file (.+) matches$/) {6110$file=$1;6111$binary=1;6112}else{6113(undef,$file,$lno,$ltext) =split(/:/,$line,4);6114}6115if($filene$lastfile) {6116$lastfileand print"</td></tr>\n";6117if($alternate++) {6118print"<tr class=\"dark\">\n";6119}else{6120print"<tr class=\"light\">\n";6121}6122print"<td class=\"list\">".6123$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6124 file_name=>"$file"),6125-class=>"list"}, esc_path($file));6126print"</td><td>\n";6127$lastfile=$file;6128}6129if($binary) {6130print"<div class=\"binary\">Binary file</div>\n";6131}else{6132$ltext= untabify($ltext);6133if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6134$ltext= esc_html($1, -nbsp=>1);6135$ltext.='<span class="match">';6136$ltext.= esc_html($2, -nbsp=>1);6137$ltext.='</span>';6138$ltext.= esc_html($3, -nbsp=>1);6139}else{6140$ltext= esc_html($ltext, -nbsp=>1);6141}6142print"<div class=\"pre\">".6143$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6144 file_name=>"$file").'#l'.$lno,6145-class=>"linenr"},sprintf('%4i',$lno))6146.' '.$ltext."</div>\n";6147}6148}6149if($lastfile) {6150print"</td></tr>\n";6151if($matches>1000) {6152print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6153}6154}else{6155print"<div class=\"diff nodifferences\">No matches found</div>\n";6156}6157close$fd;61586159print"</table>\n";6160}6161 git_footer_html();6162}61636164sub git_search_help {6165 git_header_html();6166 git_print_page_nav('','',$hash,$hash,$hash);6167print<<EOT;6168<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without6169regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,6170the pattern entered is recognized as the POSIX extended6171<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case6172insensitive).</p>6173<dl>6174<dt><b>commit</b></dt>6175<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>6176EOT6177my$have_grep= gitweb_check_feature('grep');6178if($have_grep) {6179print<<EOT;6180<dt><b>grep</b></dt>6181<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing6182 a different one) are searched for the given pattern. On large trees, this search can take6183a while and put some strain on the server, so please use it with some consideration. Note that6184due to git-grep peculiarity, currently if regexp mode is turned off, the matches are6185case-sensitive.</dd>6186EOT6187}6188print<<EOT;6189<dt><b>author</b></dt>6190<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>6191<dt><b>committer</b></dt>6192<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>6193EOT6194my$have_pickaxe= gitweb_check_feature('pickaxe');6195if($have_pickaxe) {6196print<<EOT;6197<dt><b>pickaxe</b></dt>6198<dd>All commits that caused the string to appear or disappear from any file (changes that6199added, removed or "modified" the string) will be listed. This search can take a while and6200takes a lot of strain on the server, so please use it wisely. Note that since you may be6201interested even in changes just changing the case as well, this search is case sensitive.</dd>6202EOT6203}6204print"</dl>\n";6205 git_footer_html();6206}62076208sub git_shortlog {6209my$head= git_get_head_hash($project);6210if(!defined$hash) {6211$hash=$head;6212}6213if(!defined$page) {6214$page=0;6215}6216my$refs= git_get_references();62176218my$commit_hash=$hash;6219if(defined$hash_parent) {6220$commit_hash="$hash_parent..$hash";6221}6222my@commitlist= parse_commits($commit_hash,101, (100*$page));62236224my$paging_nav= format_paging_nav('shortlog',$hash,$head,$page,$#commitlist>=100);6225my$next_link='';6226if($#commitlist>=100) {6227$next_link=6228$cgi->a({-href => href(-replay=>1, page=>$page+1),6229-accesskey =>"n", -title =>"Alt-n"},"next");6230}6231my$patch_max= gitweb_check_feature('patches');6232if($patch_max) {6233if($patch_max<0||@commitlist<=$patch_max) {6234$paging_nav.=" ⋅ ".6235$cgi->a({-href => href(action=>"patches", -replay=>1)},6236"patches");6237}6238}62396240 git_header_html();6241 git_print_page_nav('shortlog','',$hash,$hash,$hash,$paging_nav);6242 git_print_header_div('summary',$project);62436244 git_shortlog_body(\@commitlist,0,99,$refs,$next_link);62456246 git_footer_html();6247}62486249## ......................................................................6250## feeds (RSS, Atom; OPML)62516252sub git_feed {6253my$format=shift||'atom';6254my$have_blame= gitweb_check_feature('blame');62556256# Atom: http://www.atomenabled.org/developers/syndication/6257# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ6258if($formatne'rss'&&$formatne'atom') {6259 die_error(400,"Unknown web feed format");6260}62616262# log/feed of current (HEAD) branch, log of given branch, history of file/directory6263my$head=$hash||'HEAD';6264my@commitlist= parse_commits($head,150,0,$file_name);62656266my%latest_commit;6267my%latest_date;6268my$content_type="application/$format+xml";6269if(defined$cgi->http('HTTP_ACCEPT') &&6270$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {6271# browser (feed reader) prefers text/xml6272$content_type='text/xml';6273}6274if(defined($commitlist[0])) {6275%latest_commit= %{$commitlist[0]};6276my$latest_epoch=$latest_commit{'committer_epoch'};6277%latest_date= parse_date($latest_epoch);6278my$if_modified=$cgi->http('IF_MODIFIED_SINCE');6279if(defined$if_modified) {6280my$since;6281if(eval{require HTTP::Date;1; }) {6282$since= HTTP::Date::str2time($if_modified);6283}elsif(eval{require Time::ParseDate;1; }) {6284$since= Time::ParseDate::parsedate($if_modified, GMT =>1);6285}6286if(defined$since&&$latest_epoch<=$since) {6287print$cgi->header(6288-type =>$content_type,6289-charset =>'utf-8',6290-last_modified =>$latest_date{'rfc2822'},6291-status =>'304 Not Modified');6292return;6293}6294}6295print$cgi->header(6296-type =>$content_type,6297-charset =>'utf-8',6298-last_modified =>$latest_date{'rfc2822'});6299}else{6300print$cgi->header(6301-type =>$content_type,6302-charset =>'utf-8');6303}63046305# Optimization: skip generating the body if client asks only6306# for Last-Modified date.6307return if($cgi->request_method()eq'HEAD');63086309# header variables6310my$title="$site_name-$project/$action";6311my$feed_type='log';6312if(defined$hash) {6313$title.=" - '$hash'";6314$feed_type='branch log';6315if(defined$file_name) {6316$title.=" ::$file_name";6317$feed_type='history';6318}6319}elsif(defined$file_name) {6320$title.=" -$file_name";6321$feed_type='history';6322}6323$title.="$feed_type";6324my$descr= git_get_project_description($project);6325if(defined$descr) {6326$descr= esc_html($descr);6327}else{6328$descr="$project".6329($formateq'rss'?'RSS':'Atom') .6330" feed";6331}6332my$owner= git_get_project_owner($project);6333$owner= esc_html($owner);63346335#header6336my$alt_url;6337if(defined$file_name) {6338$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);6339}elsif(defined$hash) {6340$alt_url= href(-full=>1, action=>"log", hash=>$hash);6341}else{6342$alt_url= href(-full=>1, action=>"summary");6343}6344print qq!<?xml version="1.0" encoding="utf-8"?>\n!;6345if($formateq'rss') {6346print<<XML;6347<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">6348<channel>6349XML6350print"<title>$title</title>\n".6351"<link>$alt_url</link>\n".6352"<description>$descr</description>\n".6353"<language>en</language>\n".6354# project owner is responsible for 'editorial' content6355"<managingEditor>$owner</managingEditor>\n";6356if(defined$logo||defined$favicon) {6357# prefer the logo to the favicon, since RSS6358# doesn't allow both6359my$img= esc_url($logo||$favicon);6360print"<image>\n".6361"<url>$img</url>\n".6362"<title>$title</title>\n".6363"<link>$alt_url</link>\n".6364"</image>\n";6365}6366if(%latest_date) {6367print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";6368print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";6369}6370print"<generator>gitweb v.$version/$git_version</generator>\n";6371}elsif($formateq'atom') {6372print<<XML;6373<feed xmlns="http://www.w3.org/2005/Atom">6374XML6375print"<title>$title</title>\n".6376"<subtitle>$descr</subtitle>\n".6377'<link rel="alternate" type="text/html" href="'.6378$alt_url.'" />'."\n".6379'<link rel="self" type="'.$content_type.'" href="'.6380$cgi->self_url() .'" />'."\n".6381"<id>". href(-full=>1) ."</id>\n".6382# use project owner for feed author6383"<author><name>$owner</name></author>\n";6384if(defined$favicon) {6385print"<icon>". esc_url($favicon) ."</icon>\n";6386}6387if(defined$logo_url) {6388# not twice as wide as tall: 72 x 27 pixels6389print"<logo>". esc_url($logo) ."</logo>\n";6390}6391if(!%latest_date) {6392# dummy date to keep the feed valid until commits trickle in:6393print"<updated>1970-01-01T00:00:00Z</updated>\n";6394}else{6395print"<updated>$latest_date{'iso-8601'}</updated>\n";6396}6397print"<generator version='$version/$git_version'>gitweb</generator>\n";6398}63996400# contents6401for(my$i=0;$i<=$#commitlist;$i++) {6402my%co= %{$commitlist[$i]};6403my$commit=$co{'id'};6404# we read 150, we always show 30 and the ones more recent than 48 hours6405if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6406last;6407}6408my%cd= parse_date($co{'author_epoch'});64096410# get list of changed files6411open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6412$co{'parent'} ||"--root",6413$co{'id'},"--", (defined$file_name?$file_name: ())6414ornext;6415my@difftree=map{chomp;$_} <$fd>;6416close$fd6417ornext;64186419# print element (entry, item)6420my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6421if($formateq'rss') {6422print"<item>\n".6423"<title>". esc_html($co{'title'}) ."</title>\n".6424"<author>". esc_html($co{'author'}) ."</author>\n".6425"<pubDate>$cd{'rfc2822'}</pubDate>\n".6426"<guid isPermaLink=\"true\">$co_url</guid>\n".6427"<link>$co_url</link>\n".6428"<description>". esc_html($co{'title'}) ."</description>\n".6429"<content:encoded>".6430"<![CDATA[\n";6431}elsif($formateq'atom') {6432print"<entry>\n".6433"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6434"<updated>$cd{'iso-8601'}</updated>\n".6435"<author>\n".6436" <name>". esc_html($co{'author_name'}) ."</name>\n";6437if($co{'author_email'}) {6438print" <email>". esc_html($co{'author_email'}) ."</email>\n";6439}6440print"</author>\n".6441# use committer for contributor6442"<contributor>\n".6443" <name>". esc_html($co{'committer_name'}) ."</name>\n";6444if($co{'committer_email'}) {6445print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6446}6447print"</contributor>\n".6448"<published>$cd{'iso-8601'}</published>\n".6449"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6450"<id>$co_url</id>\n".6451"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6452"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6453}6454my$comment=$co{'comment'};6455print"<pre>\n";6456foreachmy$line(@$comment) {6457$line= esc_html($line);6458print"$line\n";6459}6460print"</pre><ul>\n";6461foreachmy$difftree_line(@difftree) {6462my%difftree= parse_difftree_raw_line($difftree_line);6463next if!$difftree{'from_id'};64646465my$file=$difftree{'file'} ||$difftree{'to_file'};64666467print"<li>".6468"[".6469$cgi->a({-href => href(-full=>1, action=>"blobdiff",6470 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6471 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6472 file_name=>$file, file_parent=>$difftree{'from_file'}),6473-title =>"diff"},'D');6474if($have_blame) {6475print$cgi->a({-href => href(-full=>1, action=>"blame",6476 file_name=>$file, hash_base=>$commit),6477-title =>"blame"},'B');6478}6479# if this is not a feed of a file history6480if(!defined$file_name||$file_namene$file) {6481print$cgi->a({-href => href(-full=>1, action=>"history",6482 file_name=>$file, hash=>$commit),6483-title =>"history"},'H');6484}6485$file= esc_path($file);6486print"] ".6487"$file</li>\n";6488}6489if($formateq'rss') {6490print"</ul>]]>\n".6491"</content:encoded>\n".6492"</item>\n";6493}elsif($formateq'atom') {6494print"</ul>\n</div>\n".6495"</content>\n".6496"</entry>\n";6497}6498}64996500# end of feed6501if($formateq'rss') {6502print"</channel>\n</rss>\n";6503}elsif($formateq'atom') {6504print"</feed>\n";6505}6506}65076508sub git_rss {6509 git_feed('rss');6510}65116512sub git_atom {6513 git_feed('atom');6514}65156516sub git_opml {6517my@list= git_get_projects_list();65186519print$cgi->header(6520-type =>'text/xml',6521-charset =>'utf-8',6522-content_disposition =>'inline; filename="opml.xml"');65236524print<<XML;6525<?xml version="1.0" encoding="utf-8"?>6526<opml version="1.0">6527<head>6528 <title>$site_nameOPML Export</title>6529</head>6530<body>6531<outline text="git RSS feeds">6532XML65336534foreachmy$pr(@list) {6535my%proj=%$pr;6536my$head= git_get_head_hash($proj{'path'});6537if(!defined$head) {6538next;6539}6540$git_dir="$projectroot/$proj{'path'}";6541my%co= parse_commit($head);6542if(!%co) {6543next;6544}65456546my$path= esc_html(chop_str($proj{'path'},25,5));6547my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);6548my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);6549print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";6550}6551print<<XML;6552</outline>6553</body>6554</opml>6555XML6556}