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 21our$t0; 22if(eval{require Time::HiRes;1; }) { 23$t0= [Time::HiRes::gettimeofday()]; 24} 25our$number_of_git_cmds=0; 26 27BEGIN{ 28 CGI->compile()if$ENV{'MOD_PERL'}; 29} 30 31our$cgi= new CGI; 32our$version="++GIT_VERSION++"; 33our$my_url=$cgi->url(); 34our$my_uri=$cgi->url(-absolute =>1); 35 36# Base URL for relative URLs in gitweb ($logo, $favicon, ...), 37# needed and used only for URLs with nonempty PATH_INFO 38our$base_url=$my_url; 39 40# When the script is used as DirectoryIndex, the URL does not contain the name 41# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we 42# have to do it ourselves. We make $path_info global because it's also used 43# later on. 44# 45# Another issue with the script being the DirectoryIndex is that the resulting 46# $my_url data is not the full script URL: this is good, because we want 47# generated links to keep implying the script name if it wasn't explicitly 48# indicated in the URL we're handling, but it means that $my_url cannot be used 49# as base URL. 50# Therefore, if we needed to strip PATH_INFO, then we know that we have 51# to build the base URL ourselves: 52our$path_info=$ENV{"PATH_INFO"}; 53if($path_info) { 54if($my_url=~ s,\Q$path_info\E$,, && 55$my_uri=~ s,\Q$path_info\E$,, && 56defined$ENV{'SCRIPT_NAME'}) { 57$base_url=$cgi->url(-base =>1) .$ENV{'SCRIPT_NAME'}; 58} 59} 60 61# core git executable to use 62# this can just be "git" if your webserver has a sensible PATH 63our$GIT="++GIT_BINDIR++/git"; 64 65# absolute fs-path which will be prepended to the project path 66#our $projectroot = "/pub/scm"; 67our$projectroot="++GITWEB_PROJECTROOT++"; 68 69# fs traversing limit for getting project list 70# the number is relative to the projectroot 71our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 72 73# target of the home link on top of all pages 74our$home_link=$my_uri||"/"; 75 76# string of the home link on top of all pages 77our$home_link_str="++GITWEB_HOME_LINK_STR++"; 78 79# name of your site or organization to appear in page titles 80# replace this with something more descriptive for clearer bookmarks 81our$site_name="++GITWEB_SITENAME++" 82|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 83 84# filename of html text to include at top of each page 85our$site_header="++GITWEB_SITE_HEADER++"; 86# html text to include at home page 87our$home_text="++GITWEB_HOMETEXT++"; 88# filename of html text to include at bottom of each page 89our$site_footer="++GITWEB_SITE_FOOTER++"; 90 91# URI of stylesheets 92our@stylesheets= ("++GITWEB_CSS++"); 93# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 94our$stylesheet=undef; 95# URI of GIT logo (72x27 size) 96our$logo="++GITWEB_LOGO++"; 97# URI of GIT favicon, assumed to be image/png type 98our$favicon="++GITWEB_FAVICON++"; 99# URI of gitweb.js (JavaScript code for gitweb) 100our$javascript="++GITWEB_JS++"; 101 102# URI and label (title) of GIT logo link 103#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 104#our $logo_label = "git documentation"; 105our$logo_url="http://git-scm.com/"; 106our$logo_label="git homepage"; 107 108# source of projects list 109our$projects_list="++GITWEB_LIST++"; 110 111# the width (in characters) of the projects list "Description" column 112our$projects_list_description_width=25; 113 114# default order of projects list 115# valid values are none, project, descr, owner, and age 116our$default_projects_order="project"; 117 118# show repository only if this file exists 119# (only effective if this variable evaluates to true) 120our$export_ok="++GITWEB_EXPORT_OK++"; 121 122# show repository only if this subroutine returns true 123# when given the path to the project, for example: 124# sub { return -e "$_[0]/git-daemon-export-ok"; } 125our$export_auth_hook=undef; 126 127# only allow viewing of repositories also shown on the overview page 128our$strict_export="++GITWEB_STRICT_EXPORT++"; 129 130# list of git base URLs used for URL to where fetch project from, 131# i.e. full URL is "$git_base_url/$project" 132our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 133 134# default blob_plain mimetype and default charset for text/plain blob 135our$default_blob_plain_mimetype='text/plain'; 136our$default_text_plain_charset=undef; 137 138# file to use for guessing MIME types before trying /etc/mime.types 139# (relative to the current git repository) 140our$mimetypes_file=undef; 141 142# assume this charset if line contains non-UTF-8 characters; 143# it should be valid encoding (see Encoding::Supported(3pm) for list), 144# for which encoding all byte sequences are valid, for example 145# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 146# could be even 'utf-8' for the old behavior) 147our$fallback_encoding='latin1'; 148 149# rename detection options for git-diff and git-diff-tree 150# - default is '-M', with the cost proportional to 151# (number of removed files) * (number of new files). 152# - more costly is '-C' (which implies '-M'), with the cost proportional to 153# (number of changed files + number of removed files) * (number of new files) 154# - even more costly is '-C', '--find-copies-harder' with cost 155# (number of files in the original tree) * (number of new files) 156# - one might want to include '-B' option, e.g. '-B', '-M' 157our@diff_opts= ('-M');# taken from git_commit 158 159# Disables features that would allow repository owners to inject script into 160# the gitweb domain. 161our$prevent_xss=0; 162 163# information about snapshot formats that gitweb is capable of serving 164our%known_snapshot_formats= ( 165# name => { 166# 'display' => display name, 167# 'type' => mime type, 168# 'suffix' => filename suffix, 169# 'format' => --format for git-archive, 170# 'compressor' => [compressor command and arguments] 171# (array reference, optional) 172# 'disabled' => boolean (optional)} 173# 174'tgz'=> { 175'display'=>'tar.gz', 176'type'=>'application/x-gzip', 177'suffix'=>'.tar.gz', 178'format'=>'tar', 179'compressor'=> ['gzip']}, 180 181'tbz2'=> { 182'display'=>'tar.bz2', 183'type'=>'application/x-bzip2', 184'suffix'=>'.tar.bz2', 185'format'=>'tar', 186'compressor'=> ['bzip2']}, 187 188'txz'=> { 189'display'=>'tar.xz', 190'type'=>'application/x-xz', 191'suffix'=>'.tar.xz', 192'format'=>'tar', 193'compressor'=> ['xz'], 194'disabled'=>1}, 195 196'zip'=> { 197'display'=>'zip', 198'type'=>'application/x-zip', 199'suffix'=>'.zip', 200'format'=>'zip'}, 201); 202 203# Aliases so we understand old gitweb.snapshot values in repository 204# configuration. 205our%known_snapshot_format_aliases= ( 206'gzip'=>'tgz', 207'bzip2'=>'tbz2', 208'xz'=>'txz', 209 210# backward compatibility: legacy gitweb config support 211'x-gzip'=>undef,'gz'=>undef, 212'x-bzip2'=>undef,'bz2'=>undef, 213'x-zip'=>undef,''=>undef, 214); 215 216# Pixel sizes for icons and avatars. If the default font sizes or lineheights 217# are changed, it may be appropriate to change these values too via 218# $GITWEB_CONFIG. 219our%avatar_size= ( 220'default'=>16, 221'double'=>32 222); 223 224# Used to set the maximum load that we will still respond to gitweb queries. 225# If server load exceed this value then return "503 server busy" error. 226# If gitweb cannot determined server load, it is taken to be 0. 227# Leave it undefined (or set to 'undef') to turn off load checking. 228our$maxload=300; 229 230# You define site-wide feature defaults here; override them with 231# $GITWEB_CONFIG as necessary. 232our%feature= ( 233# feature => { 234# 'sub' => feature-sub (subroutine), 235# 'override' => allow-override (boolean), 236# 'default' => [ default options...] (array reference)} 237# 238# if feature is overridable (it means that allow-override has true value), 239# then feature-sub will be called with default options as parameters; 240# return value of feature-sub indicates if to enable specified feature 241# 242# if there is no 'sub' key (no feature-sub), then feature cannot be 243# overriden 244# 245# use gitweb_get_feature(<feature>) to retrieve the <feature> value 246# (an array) or gitweb_check_feature(<feature>) to check if <feature> 247# is enabled 248 249# Enable the 'blame' blob view, showing the last commit that modified 250# each line in the file. This can be very CPU-intensive. 251 252# To enable system wide have in $GITWEB_CONFIG 253# $feature{'blame'}{'default'} = [1]; 254# To have project specific config enable override in $GITWEB_CONFIG 255# $feature{'blame'}{'override'} = 1; 256# and in project config gitweb.blame = 0|1; 257'blame'=> { 258'sub'=>sub{ feature_bool('blame',@_) }, 259'override'=>0, 260'default'=> [0]}, 261 262# Enable the 'snapshot' link, providing a compressed archive of any 263# tree. This can potentially generate high traffic if you have large 264# project. 265 266# Value is a list of formats defined in %known_snapshot_formats that 267# you wish to offer. 268# To disable system wide have in $GITWEB_CONFIG 269# $feature{'snapshot'}{'default'} = []; 270# To have project specific config enable override in $GITWEB_CONFIG 271# $feature{'snapshot'}{'override'} = 1; 272# and in project config, a comma-separated list of formats or "none" 273# to disable. Example: gitweb.snapshot = tbz2,zip; 274'snapshot'=> { 275'sub'=> \&feature_snapshot, 276'override'=>0, 277'default'=> ['tgz']}, 278 279# Enable text search, which will list the commits which match author, 280# committer or commit text to a given string. Enabled by default. 281# Project specific override is not supported. 282'search'=> { 283'override'=>0, 284'default'=> [1]}, 285 286# Enable grep search, which will list the files in currently selected 287# tree containing the given string. Enabled by default. This can be 288# potentially CPU-intensive, of course. 289 290# To enable system wide have in $GITWEB_CONFIG 291# $feature{'grep'}{'default'} = [1]; 292# To have project specific config enable override in $GITWEB_CONFIG 293# $feature{'grep'}{'override'} = 1; 294# and in project config gitweb.grep = 0|1; 295'grep'=> { 296'sub'=>sub{ feature_bool('grep',@_) }, 297'override'=>0, 298'default'=> [1]}, 299 300# Enable the pickaxe search, which will list the commits that modified 301# a given string in a file. This can be practical and quite faster 302# alternative to 'blame', but still potentially CPU-intensive. 303 304# To enable system wide have in $GITWEB_CONFIG 305# $feature{'pickaxe'}{'default'} = [1]; 306# To have project specific config enable override in $GITWEB_CONFIG 307# $feature{'pickaxe'}{'override'} = 1; 308# and in project config gitweb.pickaxe = 0|1; 309'pickaxe'=> { 310'sub'=>sub{ feature_bool('pickaxe',@_) }, 311'override'=>0, 312'default'=> [1]}, 313 314# Enable showing size of blobs in a 'tree' view, in a separate 315# column, similar to what 'ls -l' does. This cost a bit of IO. 316 317# To disable system wide have in $GITWEB_CONFIG 318# $feature{'show-sizes'}{'default'} = [0]; 319# To have project specific config enable override in $GITWEB_CONFIG 320# $feature{'show-sizes'}{'override'} = 1; 321# and in project config gitweb.showsizes = 0|1; 322'show-sizes'=> { 323'sub'=>sub{ feature_bool('showsizes',@_) }, 324'override'=>0, 325'default'=> [1]}, 326 327# Make gitweb use an alternative format of the URLs which can be 328# more readable and natural-looking: project name is embedded 329# directly in the path and the query string contains other 330# auxiliary information. All gitweb installations recognize 331# URL in either format; this configures in which formats gitweb 332# generates links. 333 334# To enable system wide have in $GITWEB_CONFIG 335# $feature{'pathinfo'}{'default'} = [1]; 336# Project specific override is not supported. 337 338# Note that you will need to change the default location of CSS, 339# favicon, logo and possibly other files to an absolute URL. Also, 340# if gitweb.cgi serves as your indexfile, you will need to force 341# $my_uri to contain the script name in your $GITWEB_CONFIG. 342'pathinfo'=> { 343'override'=>0, 344'default'=> [0]}, 345 346# Make gitweb consider projects in project root subdirectories 347# to be forks of existing projects. Given project $projname.git, 348# projects matching $projname/*.git will not be shown in the main 349# projects list, instead a '+' mark will be added to $projname 350# there and a 'forks' view will be enabled for the project, listing 351# all the forks. If project list is taken from a file, forks have 352# to be listed after the main project. 353 354# To enable system wide have in $GITWEB_CONFIG 355# $feature{'forks'}{'default'} = [1]; 356# Project specific override is not supported. 357'forks'=> { 358'override'=>0, 359'default'=> [0]}, 360 361# Insert custom links to the action bar of all project pages. 362# This enables you mainly to link to third-party scripts integrating 363# into gitweb; e.g. git-browser for graphical history representation 364# or custom web-based repository administration interface. 365 366# The 'default' value consists of a list of triplets in the form 367# (label, link, position) where position is the label after which 368# to insert the link and link is a format string where %n expands 369# to the project name, %f to the project path within the filesystem, 370# %h to the current hash (h gitweb parameter) and %b to the current 371# hash base (hb gitweb parameter); %% expands to %. 372 373# To enable system wide have in $GITWEB_CONFIG e.g. 374# $feature{'actions'}{'default'} = [('graphiclog', 375# '/git-browser/by-commit.html?r=%n', 'summary')]; 376# Project specific override is not supported. 377'actions'=> { 378'override'=>0, 379'default'=> []}, 380 381# Allow gitweb scan project content tags described in ctags/ 382# of project repository, and display the popular Web 2.0-ish 383# "tag cloud" near the project list. Note that this is something 384# COMPLETELY different from the normal Git tags. 385 386# gitweb by itself can show existing tags, but it does not handle 387# tagging itself; you need an external application for that. 388# For an example script, check Girocco's cgi/tagproj.cgi. 389# You may want to install the HTML::TagCloud Perl module to get 390# a pretty tag cloud instead of just a list of tags. 391 392# To enable system wide have in $GITWEB_CONFIG 393# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 394# Project specific override is not supported. 395'ctags'=> { 396'override'=>0, 397'default'=> [0]}, 398 399# The maximum number of patches in a patchset generated in patch 400# view. Set this to 0 or undef to disable patch view, or to a 401# negative number to remove any limit. 402 403# To disable system wide have in $GITWEB_CONFIG 404# $feature{'patches'}{'default'} = [0]; 405# To have project specific config enable override in $GITWEB_CONFIG 406# $feature{'patches'}{'override'} = 1; 407# and in project config gitweb.patches = 0|n; 408# where n is the maximum number of patches allowed in a patchset. 409'patches'=> { 410'sub'=> \&feature_patches, 411'override'=>0, 412'default'=> [16]}, 413 414# Avatar support. When this feature is enabled, views such as 415# shortlog or commit will display an avatar associated with 416# the email of the committer(s) and/or author(s). 417 418# Currently available providers are gravatar and picon. 419# If an unknown provider is specified, the feature is disabled. 420 421# Gravatar depends on Digest::MD5. 422# Picon currently relies on the indiana.edu database. 423 424# To enable system wide have in $GITWEB_CONFIG 425# $feature{'avatar'}{'default'} = ['<provider>']; 426# where <provider> is either gravatar or picon. 427# To have project specific config enable override in $GITWEB_CONFIG 428# $feature{'avatar'}{'override'} = 1; 429# and in project config gitweb.avatar = <provider>; 430'avatar'=> { 431'sub'=> \&feature_avatar, 432'override'=>0, 433'default'=> ['']}, 434 435# Enable displaying how much time and how many git commands 436# it took to generate and display page. Disabled by default. 437# Project specific override is not supported. 438'timed'=> { 439'override'=>0, 440'default'=> [0]}, 441 442# Enable turning some links into links to actions which require 443# JavaScript to run (like 'blame_incremental'). Not enabled by 444# default. Project specific override is currently not supported. 445'javascript-actions'=> { 446'override'=>0, 447'default'=> [0]}, 448); 449 450sub gitweb_get_feature { 451my($name) =@_; 452return unlessexists$feature{$name}; 453my($sub,$override,@defaults) = ( 454$feature{$name}{'sub'}, 455$feature{$name}{'override'}, 456@{$feature{$name}{'default'}}); 457# project specific override is possible only if we have project 458our$git_dir;# global variable, declared later 459if(!$override|| !defined$git_dir) { 460return@defaults; 461} 462if(!defined$sub) { 463warn"feature$nameis not overridable"; 464return@defaults; 465} 466return$sub->(@defaults); 467} 468 469# A wrapper to check if a given feature is enabled. 470# With this, you can say 471# 472# my $bool_feat = gitweb_check_feature('bool_feat'); 473# gitweb_check_feature('bool_feat') or somecode; 474# 475# instead of 476# 477# my ($bool_feat) = gitweb_get_feature('bool_feat'); 478# (gitweb_get_feature('bool_feat'))[0] or somecode; 479# 480sub gitweb_check_feature { 481return(gitweb_get_feature(@_))[0]; 482} 483 484 485sub feature_bool { 486my$key=shift; 487my($val) = git_get_project_config($key,'--bool'); 488 489if(!defined$val) { 490return($_[0]); 491}elsif($valeq'true') { 492return(1); 493}elsif($valeq'false') { 494return(0); 495} 496} 497 498sub feature_snapshot { 499my(@fmts) =@_; 500 501my($val) = git_get_project_config('snapshot'); 502 503if($val) { 504@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 505} 506 507return@fmts; 508} 509 510sub feature_patches { 511my@val= (git_get_project_config('patches','--int')); 512 513if(@val) { 514return@val; 515} 516 517return($_[0]); 518} 519 520sub feature_avatar { 521my@val= (git_get_project_config('avatar')); 522 523return@val?@val:@_; 524} 525 526# checking HEAD file with -e is fragile if the repository was 527# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 528# and then pruned. 529sub check_head_link { 530my($dir) =@_; 531my$headfile="$dir/HEAD"; 532return((-e $headfile) || 533(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 534} 535 536sub check_export_ok { 537my($dir) =@_; 538return(check_head_link($dir) && 539(!$export_ok|| -e "$dir/$export_ok") && 540(!$export_auth_hook||$export_auth_hook->($dir))); 541} 542 543# process alternate names for backward compatibility 544# filter out unsupported (unknown) snapshot formats 545sub filter_snapshot_fmts { 546my@fmts=@_; 547 548@fmts=map{ 549exists$known_snapshot_format_aliases{$_} ? 550$known_snapshot_format_aliases{$_} :$_}@fmts; 551@fmts=grep{ 552exists$known_snapshot_formats{$_} && 553!$known_snapshot_formats{$_}{'disabled'}}@fmts; 554} 555 556our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 557our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 558# die if there are errors parsing config file 559if(-e $GITWEB_CONFIG) { 560do$GITWEB_CONFIG; 561die$@if$@; 562}elsif(-e $GITWEB_CONFIG_SYSTEM) { 563do$GITWEB_CONFIG_SYSTEM; 564die$@if$@; 565} 566 567# Get loadavg of system, to compare against $maxload. 568# Currently it requires '/proc/loadavg' present to get loadavg; 569# if it is not present it returns 0, which means no load checking. 570sub get_loadavg { 571if( -e '/proc/loadavg'){ 572open my$fd,'<','/proc/loadavg' 573orreturn0; 574my@load=split(/\s+/,scalar<$fd>); 575close$fd; 576 577# The first three columns measure CPU and IO utilization of the last one, 578# five, and 10 minute periods. The fourth column shows the number of 579# currently running processes and the total number of processes in the m/n 580# format. The last column displays the last process ID used. 581return$load[0] ||0; 582} 583# additional checks for load average should go here for things that don't export 584# /proc/loadavg 585 586return0; 587} 588 589# version of the core git binary 590our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 591$number_of_git_cmds++; 592 593$projects_list||=$projectroot; 594 595if(defined$maxload&& get_loadavg() >$maxload) { 596 die_error(503,"The load average on the server is too high"); 597} 598 599# ====================================================================== 600# input validation and dispatch 601 602# input parameters can be collected from a variety of sources (presently, CGI 603# and PATH_INFO), so we define an %input_params hash that collects them all 604# together during validation: this allows subsequent uses (e.g. href()) to be 605# agnostic of the parameter origin 606 607our%input_params= (); 608 609# input parameters are stored with the long parameter name as key. This will 610# also be used in the href subroutine to convert parameters to their CGI 611# equivalent, and since the href() usage is the most frequent one, we store 612# the name -> CGI key mapping here, instead of the reverse. 613# 614# XXX: Warning: If you touch this, check the search form for updating, 615# too. 616 617our@cgi_param_mapping= ( 618 project =>"p", 619 action =>"a", 620 file_name =>"f", 621 file_parent =>"fp", 622 hash =>"h", 623 hash_parent =>"hp", 624 hash_base =>"hb", 625 hash_parent_base =>"hpb", 626 page =>"pg", 627 order =>"o", 628 searchtext =>"s", 629 searchtype =>"st", 630 snapshot_format =>"sf", 631 extra_options =>"opt", 632 search_use_regexp =>"sr", 633# this must be last entry (for manipulation from JavaScript) 634 javascript =>"js" 635); 636our%cgi_param_mapping=@cgi_param_mapping; 637 638# we will also need to know the possible actions, for validation 639our%actions= ( 640"blame"=> \&git_blame, 641"blame_incremental"=> \&git_blame_incremental, 642"blame_data"=> \&git_blame_data, 643"blobdiff"=> \&git_blobdiff, 644"blobdiff_plain"=> \&git_blobdiff_plain, 645"blob"=> \&git_blob, 646"blob_plain"=> \&git_blob_plain, 647"commitdiff"=> \&git_commitdiff, 648"commitdiff_plain"=> \&git_commitdiff_plain, 649"commit"=> \&git_commit, 650"forks"=> \&git_forks, 651"heads"=> \&git_heads, 652"history"=> \&git_history, 653"log"=> \&git_log, 654"patch"=> \&git_patch, 655"patches"=> \&git_patches, 656"rss"=> \&git_rss, 657"atom"=> \&git_atom, 658"search"=> \&git_search, 659"search_help"=> \&git_search_help, 660"shortlog"=> \&git_shortlog, 661"summary"=> \&git_summary, 662"tag"=> \&git_tag, 663"tags"=> \&git_tags, 664"tree"=> \&git_tree, 665"snapshot"=> \&git_snapshot, 666"object"=> \&git_object, 667# those below don't need $project 668"opml"=> \&git_opml, 669"project_list"=> \&git_project_list, 670"project_index"=> \&git_project_index, 671); 672 673# finally, we have the hash of allowed extra_options for the commands that 674# allow them 675our%allowed_options= ( 676"--no-merges"=> [qw(rss atom log shortlog history)], 677); 678 679# fill %input_params with the CGI parameters. All values except for 'opt' 680# should be single values, but opt can be an array. We should probably 681# build an array of parameters that can be multi-valued, but since for the time 682# being it's only this one, we just single it out 683while(my($name,$symbol) =each%cgi_param_mapping) { 684if($symboleq'opt') { 685$input_params{$name} = [$cgi->param($symbol) ]; 686}else{ 687$input_params{$name} =$cgi->param($symbol); 688} 689} 690 691# now read PATH_INFO and update the parameter list for missing parameters 692sub evaluate_path_info { 693return ifdefined$input_params{'project'}; 694return if!$path_info; 695$path_info=~ s,^/+,,; 696return if!$path_info; 697 698# find which part of PATH_INFO is project 699my$project=$path_info; 700$project=~ s,/+$,,; 701while($project&& !check_head_link("$projectroot/$project")) { 702$project=~ s,/*[^/]*$,,; 703} 704return unless$project; 705$input_params{'project'} =$project; 706 707# do not change any parameters if an action is given using the query string 708return if$input_params{'action'}; 709$path_info=~ s,^\Q$project\E/*,,; 710 711# next, check if we have an action 712my$action=$path_info; 713$action=~ s,/.*$,,; 714if(exists$actions{$action}) { 715$path_info=~ s,^$action/*,,; 716$input_params{'action'} =$action; 717} 718 719# list of actions that want hash_base instead of hash, but can have no 720# pathname (f) parameter 721my@wants_base= ( 722'tree', 723'history', 724); 725 726# we want to catch 727# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 728my($parentrefname,$parentpathname,$refname,$pathname) = 729($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/); 730 731# first, analyze the 'current' part 732if(defined$pathname) { 733# we got "branch:filename" or "branch:dir/" 734# we could use git_get_type(branch:pathname), but: 735# - it needs $git_dir 736# - it does a git() call 737# - the convention of terminating directories with a slash 738# makes it superfluous 739# - embedding the action in the PATH_INFO would make it even 740# more superfluous 741$pathname=~ s,^/+,,; 742if(!$pathname||substr($pathname, -1)eq"/") { 743$input_params{'action'} ||="tree"; 744$pathname=~ s,/$,,; 745}else{ 746# the default action depends on whether we had parent info 747# or not 748if($parentrefname) { 749$input_params{'action'} ||="blobdiff_plain"; 750}else{ 751$input_params{'action'} ||="blob_plain"; 752} 753} 754$input_params{'hash_base'} ||=$refname; 755$input_params{'file_name'} ||=$pathname; 756}elsif(defined$refname) { 757# we got "branch". In this case we have to choose if we have to 758# set hash or hash_base. 759# 760# Most of the actions without a pathname only want hash to be 761# set, except for the ones specified in @wants_base that want 762# hash_base instead. It should also be noted that hand-crafted 763# links having 'history' as an action and no pathname or hash 764# set will fail, but that happens regardless of PATH_INFO. 765$input_params{'action'} ||="shortlog"; 766if(grep{$_eq$input_params{'action'} }@wants_base) { 767$input_params{'hash_base'} ||=$refname; 768}else{ 769$input_params{'hash'} ||=$refname; 770} 771} 772 773# next, handle the 'parent' part, if present 774if(defined$parentrefname) { 775# a missing pathspec defaults to the 'current' filename, allowing e.g. 776# someproject/blobdiff/oldrev..newrev:/filename 777if($parentpathname) { 778$parentpathname=~ s,^/+,,; 779$parentpathname=~ s,/$,,; 780$input_params{'file_parent'} ||=$parentpathname; 781}else{ 782$input_params{'file_parent'} ||=$input_params{'file_name'}; 783} 784# we assume that hash_parent_base is wanted if a path was specified, 785# or if the action wants hash_base instead of hash 786if(defined$input_params{'file_parent'} || 787grep{$_eq$input_params{'action'} }@wants_base) { 788$input_params{'hash_parent_base'} ||=$parentrefname; 789}else{ 790$input_params{'hash_parent'} ||=$parentrefname; 791} 792} 793 794# for the snapshot action, we allow URLs in the form 795# $project/snapshot/$hash.ext 796# where .ext determines the snapshot and gets removed from the 797# passed $refname to provide the $hash. 798# 799# To be able to tell that $refname includes the format extension, we 800# require the following two conditions to be satisfied: 801# - the hash input parameter MUST have been set from the $refname part 802# of the URL (i.e. they must be equal) 803# - the snapshot format MUST NOT have been defined already (e.g. from 804# CGI parameter sf) 805# It's also useless to try any matching unless $refname has a dot, 806# so we check for that too 807if(defined$input_params{'action'} && 808$input_params{'action'}eq'snapshot'&& 809defined$refname&&index($refname,'.') != -1&& 810$refnameeq$input_params{'hash'} && 811!defined$input_params{'snapshot_format'}) { 812# We loop over the known snapshot formats, checking for 813# extensions. Allowed extensions are both the defined suffix 814# (which includes the initial dot already) and the snapshot 815# format key itself, with a prepended dot 816while(my($fmt,$opt) =each%known_snapshot_formats) { 817my$hash=$refname; 818unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 819next; 820} 821my$sfx=$1; 822# a valid suffix was found, so set the snapshot format 823# and reset the hash parameter 824$input_params{'snapshot_format'} =$fmt; 825$input_params{'hash'} =$hash; 826# we also set the format suffix to the one requested 827# in the URL: this way a request for e.g. .tgz returns 828# a .tgz instead of a .tar.gz 829$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 830last; 831} 832} 833} 834evaluate_path_info(); 835 836our$action=$input_params{'action'}; 837if(defined$action) { 838if(!validate_action($action)) { 839 die_error(400,"Invalid action parameter"); 840} 841} 842 843# parameters which are pathnames 844our$project=$input_params{'project'}; 845if(defined$project) { 846if(!validate_project($project)) { 847undef$project; 848 die_error(404,"No such project"); 849} 850} 851 852our$file_name=$input_params{'file_name'}; 853if(defined$file_name) { 854if(!validate_pathname($file_name)) { 855 die_error(400,"Invalid file parameter"); 856} 857} 858 859our$file_parent=$input_params{'file_parent'}; 860if(defined$file_parent) { 861if(!validate_pathname($file_parent)) { 862 die_error(400,"Invalid file parent parameter"); 863} 864} 865 866# parameters which are refnames 867our$hash=$input_params{'hash'}; 868if(defined$hash) { 869if(!validate_refname($hash)) { 870 die_error(400,"Invalid hash parameter"); 871} 872} 873 874our$hash_parent=$input_params{'hash_parent'}; 875if(defined$hash_parent) { 876if(!validate_refname($hash_parent)) { 877 die_error(400,"Invalid hash parent parameter"); 878} 879} 880 881our$hash_base=$input_params{'hash_base'}; 882if(defined$hash_base) { 883if(!validate_refname($hash_base)) { 884 die_error(400,"Invalid hash base parameter"); 885} 886} 887 888our@extra_options= @{$input_params{'extra_options'}}; 889# @extra_options is always defined, since it can only be (currently) set from 890# CGI, and $cgi->param() returns the empty array in array context if the param 891# is not set 892foreachmy$opt(@extra_options) { 893if(not exists$allowed_options{$opt}) { 894 die_error(400,"Invalid option parameter"); 895} 896if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 897 die_error(400,"Invalid option parameter for this action"); 898} 899} 900 901our$hash_parent_base=$input_params{'hash_parent_base'}; 902if(defined$hash_parent_base) { 903if(!validate_refname($hash_parent_base)) { 904 die_error(400,"Invalid hash parent base parameter"); 905} 906} 907 908# other parameters 909our$page=$input_params{'page'}; 910if(defined$page) { 911if($page=~m/[^0-9]/) { 912 die_error(400,"Invalid page parameter"); 913} 914} 915 916our$searchtype=$input_params{'searchtype'}; 917if(defined$searchtype) { 918if($searchtype=~m/[^a-z]/) { 919 die_error(400,"Invalid searchtype parameter"); 920} 921} 922 923our$search_use_regexp=$input_params{'search_use_regexp'}; 924 925our$searchtext=$input_params{'searchtext'}; 926our$search_regexp; 927if(defined$searchtext) { 928if(length($searchtext) <2) { 929 die_error(403,"At least two characters are required for search parameter"); 930} 931$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 932} 933 934# path to the current git repository 935our$git_dir; 936$git_dir="$projectroot/$project"if$project; 937 938# list of supported snapshot formats 939our@snapshot_fmts= gitweb_get_feature('snapshot'); 940@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts); 941 942# check that the avatar feature is set to a known provider name, 943# and for each provider check if the dependencies are satisfied. 944# if the provider name is invalid or the dependencies are not met, 945# reset $git_avatar to the empty string. 946our($git_avatar) = gitweb_get_feature('avatar'); 947if($git_avatareq'gravatar') { 948$git_avatar=''unless(eval{require Digest::MD5;1; }); 949}elsif($git_avatareq'picon') { 950# no dependencies 951}else{ 952$git_avatar=''; 953} 954 955# dispatch 956if(!defined$action) { 957if(defined$hash) { 958$action= git_get_type($hash); 959}elsif(defined$hash_base&&defined$file_name) { 960$action= git_get_type("$hash_base:$file_name"); 961}elsif(defined$project) { 962$action='summary'; 963}else{ 964$action='project_list'; 965} 966} 967if(!defined($actions{$action})) { 968 die_error(400,"Unknown action"); 969} 970if($action!~m/^(?:opml|project_list|project_index)$/&& 971!$project) { 972 die_error(400,"Project needed"); 973} 974$actions{$action}->(); 975exit; 976 977## ====================================================================== 978## action links 979 980sub href { 981my%params=@_; 982# default is to use -absolute url() i.e. $my_uri 983my$href=$params{-full} ?$my_url:$my_uri; 984 985$params{'project'} =$projectunlessexists$params{'project'}; 986 987if($params{-replay}) { 988while(my($name,$symbol) =each%cgi_param_mapping) { 989if(!exists$params{$name}) { 990$params{$name} =$input_params{$name}; 991} 992} 993} 994 995my$use_pathinfo= gitweb_check_feature('pathinfo'); 996if($use_pathinfoand defined$params{'project'}) { 997# try to put as many parameters as possible in PATH_INFO: 998# - project name 999# - action1000# - hash_parent or hash_parent_base:/file_parent1001# - hash or hash_base:/filename1002# - the snapshot_format as an appropriate suffix10031004# When the script is the root DirectoryIndex for the domain,1005# $href here would be something like http://gitweb.example.com/1006# Thus, we strip any trailing / from $href, to spare us double1007# slashes in the final URL1008$href=~ s,/$,,;10091010# Then add the project name, if present1011$href.="/".esc_url($params{'project'});1012delete$params{'project'};10131014# since we destructively absorb parameters, we keep this1015# boolean that remembers if we're handling a snapshot1016my$is_snapshot=$params{'action'}eq'snapshot';10171018# Summary just uses the project path URL, any other action is1019# added to the URL1020if(defined$params{'action'}) {1021$href.="/".esc_url($params{'action'})unless$params{'action'}eq'summary';1022delete$params{'action'};1023}10241025# Next, we put hash_parent_base:/file_parent..hash_base:/file_name,1026# stripping nonexistent or useless pieces1027$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'}1028||$params{'hash_parent'} ||$params{'hash'});1029if(defined$params{'hash_base'}) {1030if(defined$params{'hash_parent_base'}) {1031$href.= esc_url($params{'hash_parent_base'});1032# skip the file_parent if it's the same as the file_name1033if(defined$params{'file_parent'}) {1034if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) {1035delete$params{'file_parent'};1036}elsif($params{'file_parent'} !~/\.\./) {1037$href.=":/".esc_url($params{'file_parent'});1038delete$params{'file_parent'};1039}1040}1041$href.="..";1042delete$params{'hash_parent'};1043delete$params{'hash_parent_base'};1044}elsif(defined$params{'hash_parent'}) {1045$href.= esc_url($params{'hash_parent'})."..";1046delete$params{'hash_parent'};1047}10481049$href.= esc_url($params{'hash_base'});1050if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) {1051$href.=":/".esc_url($params{'file_name'});1052delete$params{'file_name'};1053}1054delete$params{'hash'};1055delete$params{'hash_base'};1056}elsif(defined$params{'hash'}) {1057$href.= esc_url($params{'hash'});1058delete$params{'hash'};1059}10601061# If the action was a snapshot, we can absorb the1062# snapshot_format parameter too1063if($is_snapshot) {1064my$fmt=$params{'snapshot_format'};1065# snapshot_format should always be defined when href()1066# is called, but just in case some code forgets, we1067# fall back to the default1068$fmt||=$snapshot_fmts[0];1069$href.=$known_snapshot_formats{$fmt}{'suffix'};1070delete$params{'snapshot_format'};1071}1072}10731074# now encode the parameters explicitly1075my@result= ();1076for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1077my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1078if(defined$params{$name}) {1079if(ref($params{$name})eq"ARRAY") {1080foreachmy$par(@{$params{$name}}) {1081push@result,$symbol."=". esc_param($par);1082}1083}else{1084push@result,$symbol."=". esc_param($params{$name});1085}1086}1087}1088$href.="?".join(';',@result)ifscalar@result;10891090return$href;1091}109210931094## ======================================================================1095## validation, quoting/unquoting and escaping10961097sub validate_action {1098my$input=shift||returnundef;1099returnundefunlessexists$actions{$input};1100return$input;1101}11021103sub validate_project {1104my$input=shift||returnundef;1105if(!validate_pathname($input) ||1106!(-d "$projectroot/$input") ||1107!check_export_ok("$projectroot/$input") ||1108($strict_export&& !project_in_list($input))) {1109returnundef;1110}else{1111return$input;1112}1113}11141115sub validate_pathname {1116my$input=shift||returnundef;11171118# no '.' or '..' as elements of path, i.e. no '.' nor '..'1119# at the beginning, at the end, and between slashes.1120# also this catches doubled slashes1121if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1122returnundef;1123}1124# no null characters1125if($input=~m!\0!) {1126returnundef;1127}1128return$input;1129}11301131sub validate_refname {1132my$input=shift||returnundef;11331134# textual hashes are O.K.1135if($input=~m/^[0-9a-fA-F]{40}$/) {1136return$input;1137}1138# it must be correct pathname1139$input= validate_pathname($input)1140orreturnundef;1141# restrictions on ref name according to git-check-ref-format1142if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1143returnundef;1144}1145return$input;1146}11471148# decode sequences of octets in utf8 into Perl's internal form,1149# which is utf-8 with utf8 flag set if needed. gitweb writes out1150# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1151sub to_utf8 {1152my$str=shift;1153returnundefunlessdefined$str;1154if(utf8::valid($str)) {1155 utf8::decode($str);1156return$str;1157}else{1158return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1159}1160}11611162# quote unsafe chars, but keep the slash, even when it's not1163# correct, but quoted slashes look too horrible in bookmarks1164sub esc_param {1165my$str=shift;1166returnundefunlessdefined$str;1167$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1168$str=~s/ /\+/g;1169return$str;1170}11711172# quote unsafe chars in whole URL, so some charactrs cannot be quoted1173sub esc_url {1174my$str=shift;1175returnundefunlessdefined$str;1176$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg;1177$str=~s/ /\+/g;1178return$str;1179}11801181# replace invalid utf8 character with SUBSTITUTION sequence1182sub esc_html {1183my$str=shift;1184my%opts=@_;11851186returnundefunlessdefined$str;11871188$str= to_utf8($str);1189$str=$cgi->escapeHTML($str);1190if($opts{'-nbsp'}) {1191$str=~s/ / /g;1192}1193$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1194return$str;1195}11961197# quote control characters and escape filename to HTML1198sub esc_path {1199my$str=shift;1200my%opts=@_;12011202returnundefunlessdefined$str;12031204$str= to_utf8($str);1205$str=$cgi->escapeHTML($str);1206if($opts{'-nbsp'}) {1207$str=~s/ / /g;1208}1209$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1210return$str;1211}12121213# Make control characters "printable", using character escape codes (CEC)1214sub quot_cec {1215my$cntrl=shift;1216my%opts=@_;1217my%es= (# character escape codes, aka escape sequences1218"\t"=>'\t',# tab (HT)1219"\n"=>'\n',# line feed (LF)1220"\r"=>'\r',# carrige return (CR)1221"\f"=>'\f',# form feed (FF)1222"\b"=>'\b',# backspace (BS)1223"\a"=>'\a',# alarm (bell) (BEL)1224"\e"=>'\e',# escape (ESC)1225"\013"=>'\v',# vertical tab (VT)1226"\000"=>'\0',# nul character (NUL)1227);1228my$chr= ( (exists$es{$cntrl})1229?$es{$cntrl}1230:sprintf('\%2x',ord($cntrl)) );1231if($opts{-nohtml}) {1232return$chr;1233}else{1234return"<span class=\"cntrl\">$chr</span>";1235}1236}12371238# Alternatively use unicode control pictures codepoints,1239# Unicode "printable representation" (PR)1240sub quot_upr {1241my$cntrl=shift;1242my%opts=@_;12431244my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1245if($opts{-nohtml}) {1246return$chr;1247}else{1248return"<span class=\"cntrl\">$chr</span>";1249}1250}12511252# git may return quoted and escaped filenames1253sub unquote {1254my$str=shift;12551256sub unq {1257my$seq=shift;1258my%es= (# character escape codes, aka escape sequences1259't'=>"\t",# tab (HT, TAB)1260'n'=>"\n",# newline (NL)1261'r'=>"\r",# return (CR)1262'f'=>"\f",# form feed (FF)1263'b'=>"\b",# backspace (BS)1264'a'=>"\a",# alarm (bell) (BEL)1265'e'=>"\e",# escape (ESC)1266'v'=>"\013",# vertical tab (VT)1267);12681269if($seq=~m/^[0-7]{1,3}$/) {1270# octal char sequence1271returnchr(oct($seq));1272}elsif(exists$es{$seq}) {1273# C escape sequence, aka character escape code1274return$es{$seq};1275}1276# quoted ordinary character1277return$seq;1278}12791280if($str=~m/^"(.*)"$/) {1281# needs unquoting1282$str=$1;1283$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1284}1285return$str;1286}12871288# escape tabs (convert tabs to spaces)1289sub untabify {1290my$line=shift;12911292while((my$pos=index($line,"\t")) != -1) {1293if(my$count= (8- ($pos%8))) {1294my$spaces=' ' x $count;1295$line=~s/\t/$spaces/;1296}1297}12981299return$line;1300}13011302sub project_in_list {1303my$project=shift;1304my@list= git_get_projects_list();1305return@list&&scalar(grep{$_->{'path'}eq$project}@list);1306}13071308## ----------------------------------------------------------------------1309## HTML aware string manipulation13101311# Try to chop given string on a word boundary between position1312# $len and $len+$add_len. If there is no word boundary there,1313# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1314# (marking chopped part) would be longer than given string.1315sub chop_str {1316my$str=shift;1317my$len=shift;1318my$add_len=shift||10;1319my$where=shift||'right';# 'left' | 'center' | 'right'13201321# Make sure perl knows it is utf8 encoded so we don't1322# cut in the middle of a utf8 multibyte char.1323$str= to_utf8($str);13241325# allow only $len chars, but don't cut a word if it would fit in $add_len1326# if it doesn't fit, cut it if it's still longer than the dots we would add1327# remove chopped character entities entirely13281329# when chopping in the middle, distribute $len into left and right part1330# return early if chopping wouldn't make string shorter1331if($whereeq'center') {1332return$strif($len+5>=length($str));# filler is length 51333$len=int($len/2);1334}else{1335return$strif($len+4>=length($str));# filler is length 41336}13371338# regexps: ending and beginning with word part up to $add_len1339my$endre=qr/.{$len}\w{0,$add_len}/;1340my$begre=qr/\w{0,$add_len}.{$len}/;13411342if($whereeq'left') {1343$str=~m/^(.*?)($begre)$/;1344my($lead,$body) = ($1,$2);1345if(length($lead) >4) {1346$lead=" ...";1347}1348return"$lead$body";13491350}elsif($whereeq'center') {1351$str=~m/^($endre)(.*)$/;1352my($left,$str) = ($1,$2);1353$str=~m/^(.*?)($begre)$/;1354my($mid,$right) = ($1,$2);1355if(length($mid) >5) {1356$mid=" ... ";1357}1358return"$left$mid$right";13591360}else{1361$str=~m/^($endre)(.*)$/;1362my$body=$1;1363my$tail=$2;1364if(length($tail) >4) {1365$tail="... ";1366}1367return"$body$tail";1368}1369}13701371# takes the same arguments as chop_str, but also wraps a <span> around the1372# result with a title attribute if it does get chopped. Additionally, the1373# string is HTML-escaped.1374sub chop_and_escape_str {1375my($str) =@_;13761377my$chopped= chop_str(@_);1378if($choppedeq$str) {1379return esc_html($chopped);1380}else{1381$str=~s/[[:cntrl:]]/?/g;1382return$cgi->span({-title=>$str}, esc_html($chopped));1383}1384}13851386## ----------------------------------------------------------------------1387## functions returning short strings13881389# CSS class for given age value (in seconds)1390sub age_class {1391my$age=shift;13921393if(!defined$age) {1394return"noage";1395}elsif($age<60*60*2) {1396return"age0";1397}elsif($age<60*60*24*2) {1398return"age1";1399}else{1400return"age2";1401}1402}14031404# convert age in seconds to "nn units ago" string1405sub age_string {1406my$age=shift;1407my$age_str;14081409if($age>60*60*24*365*2) {1410$age_str= (int$age/60/60/24/365);1411$age_str.=" years ago";1412}elsif($age>60*60*24*(365/12)*2) {1413$age_str=int$age/60/60/24/(365/12);1414$age_str.=" months ago";1415}elsif($age>60*60*24*7*2) {1416$age_str=int$age/60/60/24/7;1417$age_str.=" weeks ago";1418}elsif($age>60*60*24*2) {1419$age_str=int$age/60/60/24;1420$age_str.=" days ago";1421}elsif($age>60*60*2) {1422$age_str=int$age/60/60;1423$age_str.=" hours ago";1424}elsif($age>60*2) {1425$age_str=int$age/60;1426$age_str.=" min ago";1427}elsif($age>2) {1428$age_str=int$age;1429$age_str.=" sec ago";1430}else{1431$age_str.=" right now";1432}1433return$age_str;1434}14351436useconstant{1437 S_IFINVALID =>0030000,1438 S_IFGITLINK =>0160000,1439};14401441# submodule/subproject, a commit object reference1442sub S_ISGITLINK {1443my$mode=shift;14441445return(($mode& S_IFMT) == S_IFGITLINK)1446}14471448# convert file mode in octal to symbolic file mode string1449sub mode_str {1450my$mode=oct shift;14511452if(S_ISGITLINK($mode)) {1453return'm---------';1454}elsif(S_ISDIR($mode& S_IFMT)) {1455return'drwxr-xr-x';1456}elsif(S_ISLNK($mode)) {1457return'lrwxrwxrwx';1458}elsif(S_ISREG($mode)) {1459# git cares only about the executable bit1460if($mode& S_IXUSR) {1461return'-rwxr-xr-x';1462}else{1463return'-rw-r--r--';1464};1465}else{1466return'----------';1467}1468}14691470# convert file mode in octal to file type string1471sub file_type {1472my$mode=shift;14731474if($mode!~m/^[0-7]+$/) {1475return$mode;1476}else{1477$mode=oct$mode;1478}14791480if(S_ISGITLINK($mode)) {1481return"submodule";1482}elsif(S_ISDIR($mode& S_IFMT)) {1483return"directory";1484}elsif(S_ISLNK($mode)) {1485return"symlink";1486}elsif(S_ISREG($mode)) {1487return"file";1488}else{1489return"unknown";1490}1491}14921493# convert file mode in octal to file type description string1494sub file_type_long {1495my$mode=shift;14961497if($mode!~m/^[0-7]+$/) {1498return$mode;1499}else{1500$mode=oct$mode;1501}15021503if(S_ISGITLINK($mode)) {1504return"submodule";1505}elsif(S_ISDIR($mode& S_IFMT)) {1506return"directory";1507}elsif(S_ISLNK($mode)) {1508return"symlink";1509}elsif(S_ISREG($mode)) {1510if($mode& S_IXUSR) {1511return"executable";1512}else{1513return"file";1514};1515}else{1516return"unknown";1517}1518}151915201521## ----------------------------------------------------------------------1522## functions returning short HTML fragments, or transforming HTML fragments1523## which don't belong to other sections15241525# format line of commit message.1526sub format_log_line_html {1527my$line=shift;15281529$line= esc_html($line, -nbsp=>1);1530$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1531$cgi->a({-href => href(action=>"object", hash=>$1),1532-class=>"text"},$1);1533}eg;15341535return$line;1536}15371538# format marker of refs pointing to given object15391540# the destination action is chosen based on object type and current context:1541# - for annotated tags, we choose the tag view unless it's the current view1542# already, in which case we go to shortlog view1543# - for other refs, we keep the current view if we're in history, shortlog or1544# log view, and select shortlog otherwise1545sub format_ref_marker {1546my($refs,$id) =@_;1547my$markers='';15481549if(defined$refs->{$id}) {1550foreachmy$ref(@{$refs->{$id}}) {1551# this code exploits the fact that non-lightweight tags are the1552# only indirect objects, and that they are the only objects for which1553# we want to use tag instead of shortlog as action1554my($type,$name) =qw();1555my$indirect= ($ref=~s/\^\{\}$//);1556# e.g. tags/v2.6.11 or heads/next1557if($ref=~m!^(.*?)s?/(.*)$!) {1558$type=$1;1559$name=$2;1560}else{1561$type="ref";1562$name=$ref;1563}15641565my$class=$type;1566$class.=" indirect"if$indirect;15671568my$dest_action="shortlog";15691570if($indirect) {1571$dest_action="tag"unless$actioneq"tag";1572}elsif($action=~/^(history|(short)?log)$/) {1573$dest_action=$action;1574}15751576my$dest="";1577$dest.="refs/"unless$ref=~ m!^refs/!;1578$dest.=$ref;15791580my$link=$cgi->a({1581-href => href(1582 action=>$dest_action,1583 hash=>$dest1584)},$name);15851586$markers.=" <span class=\"$class\"title=\"$ref\">".1587$link."</span>";1588}1589}15901591if($markers) {1592return' <span class="refs">'.$markers.'</span>';1593}else{1594return"";1595}1596}15971598# format, perhaps shortened and with markers, title line1599sub format_subject_html {1600my($long,$short,$href,$extra) =@_;1601$extra=''unlessdefined($extra);16021603if(length($short) <length($long)) {1604$long=~s/[[:cntrl:]]/?/g;1605return$cgi->a({-href =>$href, -class=>"list subject",1606-title => to_utf8($long)},1607 esc_html($short)) .$extra;1608}else{1609return$cgi->a({-href =>$href, -class=>"list subject"},1610 esc_html($long)) .$extra;1611}1612}16131614# Rather than recomputing the url for an email multiple times, we cache it1615# after the first hit. This gives a visible benefit in views where the avatar1616# for the same email is used repeatedly (e.g. shortlog).1617# The cache is shared by all avatar engines (currently gravatar only), which1618# are free to use it as preferred. Since only one avatar engine is used for any1619# given page, there's no risk for cache conflicts.1620our%avatar_cache= ();16211622# Compute the picon url for a given email, by using the picon search service over at1623# http://www.cs.indiana.edu/picons/search.html1624sub picon_url {1625my$email=lc shift;1626if(!$avatar_cache{$email}) {1627my($user,$domain) =split('@',$email);1628$avatar_cache{$email} =1629"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".1630"$domain/$user/".1631"users+domains+unknown/up/single";1632}1633return$avatar_cache{$email};1634}16351636# Compute the gravatar url for a given email, if it's not in the cache already.1637# Gravatar stores only the part of the URL before the size, since that's the1638# one computationally more expensive. This also allows reuse of the cache for1639# different sizes (for this particular engine).1640sub gravatar_url {1641my$email=lc shift;1642my$size=shift;1643$avatar_cache{$email} ||=1644"http://www.gravatar.com/avatar/".1645 Digest::MD5::md5_hex($email) ."?s=";1646return$avatar_cache{$email} .$size;1647}16481649# Insert an avatar for the given $email at the given $size if the feature1650# is enabled.1651sub git_get_avatar {1652my($email,%opts) =@_;1653my$pre_white= ($opts{-pad_before} ?" ":"");1654my$post_white= ($opts{-pad_after} ?" ":"");1655$opts{-size} ||='default';1656my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};1657my$url="";1658if($git_avatareq'gravatar') {1659$url= gravatar_url($email,$size);1660}elsif($git_avatareq'picon') {1661$url= picon_url($email);1662}1663# Other providers can be added by extending the if chain, defining $url1664# as needed. If no variant puts something in $url, we assume avatars1665# are completely disabled/unavailable.1666if($url) {1667return$pre_white.1668"<img width=\"$size\"".1669"class=\"avatar\"".1670"src=\"$url\"".1671"alt=\"\"".1672"/>".$post_white;1673}else{1674return"";1675}1676}16771678sub format_search_author {1679my($author,$searchtype,$displaytext) =@_;1680my$have_search= gitweb_check_feature('search');16811682if($have_search) {1683my$performed="";1684if($searchtypeeq'author') {1685$performed="authored";1686}elsif($searchtypeeq'committer') {1687$performed="committed";1688}16891690return$cgi->a({-href => href(action=>"search", hash=>$hash,1691 searchtext=>$author,1692 searchtype=>$searchtype),class=>"list",1693 title=>"Search for commits$performedby$author"},1694$displaytext);16951696}else{1697return$displaytext;1698}1699}17001701# format the author name of the given commit with the given tag1702# the author name is chopped and escaped according to the other1703# optional parameters (see chop_str).1704sub format_author_html {1705my$tag=shift;1706my$co=shift;1707my$author= chop_and_escape_str($co->{'author_name'},@_);1708return"<$tagclass=\"author\">".1709 format_search_author($co->{'author_name'},"author",1710 git_get_avatar($co->{'author_email'}, -pad_after =>1) .1711$author) .1712"</$tag>";1713}17141715# format git diff header line, i.e. "diff --(git|combined|cc) ..."1716sub format_git_diff_header_line {1717my$line=shift;1718my$diffinfo=shift;1719my($from,$to) =@_;17201721if($diffinfo->{'nparents'}) {1722# combined diff1723$line=~s!^(diff (.*?) )"?.*$!$1!;1724if($to->{'href'}) {1725$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1726 esc_path($to->{'file'}));1727}else{# file was deleted (no href)1728$line.= esc_path($to->{'file'});1729}1730}else{1731# "ordinary" diff1732$line=~s!^(diff (.*?) )"?a/.*$!$1!;1733if($from->{'href'}) {1734$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1735'a/'. esc_path($from->{'file'}));1736}else{# file was added (no href)1737$line.='a/'. esc_path($from->{'file'});1738}1739$line.=' ';1740if($to->{'href'}) {1741$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1742'b/'. esc_path($to->{'file'}));1743}else{# file was deleted1744$line.='b/'. esc_path($to->{'file'});1745}1746}17471748return"<div class=\"diff header\">$line</div>\n";1749}17501751# format extended diff header line, before patch itself1752sub format_extended_diff_header_line {1753my$line=shift;1754my$diffinfo=shift;1755my($from,$to) =@_;17561757# match <path>1758if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1759$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1760 esc_path($from->{'file'}));1761}1762if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1763$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1764 esc_path($to->{'file'}));1765}1766# match single <mode>1767if($line=~m/\s(\d{6})$/) {1768$line.='<span class="info"> ('.1769 file_type_long($1) .1770')</span>';1771}1772# match <hash>1773if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1774# can match only for combined diff1775$line='index ';1776for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1777if($from->{'href'}[$i]) {1778$line.=$cgi->a({-href=>$from->{'href'}[$i],1779-class=>"hash"},1780substr($diffinfo->{'from_id'}[$i],0,7));1781}else{1782$line.='0' x 7;1783}1784# separator1785$line.=','if($i<$diffinfo->{'nparents'} -1);1786}1787$line.='..';1788if($to->{'href'}) {1789$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1790substr($diffinfo->{'to_id'},0,7));1791}else{1792$line.='0' x 7;1793}17941795}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1796# can match only for ordinary diff1797my($from_link,$to_link);1798if($from->{'href'}) {1799$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1800substr($diffinfo->{'from_id'},0,7));1801}else{1802$from_link='0' x 7;1803}1804if($to->{'href'}) {1805$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1806substr($diffinfo->{'to_id'},0,7));1807}else{1808$to_link='0' x 7;1809}1810my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1811$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1812}18131814return$line."<br/>\n";1815}18161817# format from-file/to-file diff header1818sub format_diff_from_to_header {1819my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1820my$line;1821my$result='';18221823$line=$from_line;1824#assert($line =~ m/^---/) if DEBUG;1825# no extra formatting for "^--- /dev/null"1826if(!$diffinfo->{'nparents'}) {1827# ordinary (single parent) diff1828if($line=~m!^--- "?a/!) {1829if($from->{'href'}) {1830$line='--- a/'.1831$cgi->a({-href=>$from->{'href'}, -class=>"path"},1832 esc_path($from->{'file'}));1833}else{1834$line='--- a/'.1835 esc_path($from->{'file'});1836}1837}1838$result.= qq!<div class="diff from_file">$line</div>\n!;18391840}else{1841# combined diff (merge commit)1842for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1843if($from->{'href'}[$i]) {1844$line='--- '.1845$cgi->a({-href=>href(action=>"blobdiff",1846 hash_parent=>$diffinfo->{'from_id'}[$i],1847 hash_parent_base=>$parents[$i],1848 file_parent=>$from->{'file'}[$i],1849 hash=>$diffinfo->{'to_id'},1850 hash_base=>$hash,1851 file_name=>$to->{'file'}),1852-class=>"path",1853-title=>"diff". ($i+1)},1854$i+1) .1855'/'.1856$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1857 esc_path($from->{'file'}[$i]));1858}else{1859$line='--- /dev/null';1860}1861$result.= qq!<div class="diff from_file">$line</div>\n!;1862}1863}18641865$line=$to_line;1866#assert($line =~ m/^\+\+\+/) if DEBUG;1867# no extra formatting for "^+++ /dev/null"1868if($line=~m!^\+\+\+ "?b/!) {1869if($to->{'href'}) {1870$line='+++ b/'.1871$cgi->a({-href=>$to->{'href'}, -class=>"path"},1872 esc_path($to->{'file'}));1873}else{1874$line='+++ b/'.1875 esc_path($to->{'file'});1876}1877}1878$result.= qq!<div class="diff to_file">$line</div>\n!;18791880return$result;1881}18821883# create note for patch simplified by combined diff1884sub format_diff_cc_simplified {1885my($diffinfo,@parents) =@_;1886my$result='';18871888$result.="<div class=\"diff header\">".1889"diff --cc ";1890if(!is_deleted($diffinfo)) {1891$result.=$cgi->a({-href => href(action=>"blob",1892 hash_base=>$hash,1893 hash=>$diffinfo->{'to_id'},1894 file_name=>$diffinfo->{'to_file'}),1895-class=>"path"},1896 esc_path($diffinfo->{'to_file'}));1897}else{1898$result.= esc_path($diffinfo->{'to_file'});1899}1900$result.="</div>\n".# class="diff header"1901"<div class=\"diff nodifferences\">".1902"Simple merge".1903"</div>\n";# class="diff nodifferences"19041905return$result;1906}19071908# format patch (diff) line (not to be used for diff headers)1909sub format_diff_line {1910my$line=shift;1911my($from,$to) =@_;1912my$diff_class="";19131914chomp$line;19151916if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1917# combined diff1918my$prefix=substr($line,0,scalar@{$from->{'href'}});1919if($line=~m/^\@{3}/) {1920$diff_class=" chunk_header";1921}elsif($line=~m/^\\/) {1922$diff_class=" incomplete";1923}elsif($prefix=~tr/+/+/) {1924$diff_class=" add";1925}elsif($prefix=~tr/-/-/) {1926$diff_class=" rem";1927}1928}else{1929# assume ordinary diff1930my$char=substr($line,0,1);1931if($chareq'+') {1932$diff_class=" add";1933}elsif($chareq'-') {1934$diff_class=" rem";1935}elsif($chareq'@') {1936$diff_class=" chunk_header";1937}elsif($chareq"\\") {1938$diff_class=" incomplete";1939}1940}1941$line= untabify($line);1942if($from&&$to&&$line=~m/^\@{2} /) {1943my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1944$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;19451946$from_lines=0unlessdefined$from_lines;1947$to_lines=0unlessdefined$to_lines;19481949if($from->{'href'}) {1950$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1951-class=>"list"},$from_text);1952}1953if($to->{'href'}) {1954$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1955-class=>"list"},$to_text);1956}1957$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1958"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1959return"<div class=\"diff$diff_class\">$line</div>\n";1960}elsif($from&&$to&&$line=~m/^\@{3}/) {1961my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1962my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);19631964@from_text=split(' ',$ranges);1965for(my$i=0;$i<@from_text; ++$i) {1966($from_start[$i],$from_nlines[$i]) =1967(split(',',substr($from_text[$i],1)),0);1968}19691970$to_text=pop@from_text;1971$to_start=pop@from_start;1972$to_nlines=pop@from_nlines;19731974$line="<span class=\"chunk_info\">$prefix";1975for(my$i=0;$i<@from_text; ++$i) {1976if($from->{'href'}[$i]) {1977$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1978-class=>"list"},$from_text[$i]);1979}else{1980$line.=$from_text[$i];1981}1982$line.=" ";1983}1984if($to->{'href'}) {1985$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1986-class=>"list"},$to_text);1987}else{1988$line.=$to_text;1989}1990$line.="$prefix</span>".1991"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1992return"<div class=\"diff$diff_class\">$line</div>\n";1993}1994return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1995}19961997# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1998# linked. Pass the hash of the tree/commit to snapshot.1999sub format_snapshot_links {2000my($hash) =@_;2001my$num_fmts=@snapshot_fmts;2002if($num_fmts>1) {2003# A parenthesized list of links bearing format names.2004# e.g. "snapshot (_tar.gz_ _zip_)"2005return"snapshot (".join(' ',map2006$cgi->a({2007-href => href(2008 action=>"snapshot",2009 hash=>$hash,2010 snapshot_format=>$_2011)2012},$known_snapshot_formats{$_}{'display'})2013,@snapshot_fmts) .")";2014}elsif($num_fmts==1) {2015# A single "snapshot" link whose tooltip bears the format name.2016# i.e. "_snapshot_"2017my($fmt) =@snapshot_fmts;2018return2019$cgi->a({2020-href => href(2021 action=>"snapshot",2022 hash=>$hash,2023 snapshot_format=>$fmt2024),2025-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"2026},"snapshot");2027}else{# $num_fmts == 02028returnundef;2029}2030}20312032## ......................................................................2033## functions returning values to be passed, perhaps after some2034## transformation, to other functions; e.g. returning arguments to href()20352036# returns hash to be passed to href to generate gitweb URL2037# in -title key it returns description of link2038sub get_feed_info {2039my$format=shift||'Atom';2040my%res= (action =>lc($format));20412042# feed links are possible only for project views2043return unless(defined$project);2044# some views should link to OPML, or to generic project feed,2045# or don't have specific feed yet (so they should use generic)2046return if($action=~/^(?:tags|heads|forks|tag|search)$/x);20472048my$branch;2049# branches refs uses 'refs/heads/' prefix (fullname) to differentiate2050# from tag links; this also makes possible to detect branch links2051if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||2052(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {2053$branch=$1;2054}2055# find log type for feed description (title)2056my$type='log';2057if(defined$file_name) {2058$type="history of$file_name";2059$type.="/"if($actioneq'tree');2060$type.=" on '$branch'"if(defined$branch);2061}else{2062$type="log of$branch"if(defined$branch);2063}20642065$res{-title} =$type;2066$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);2067$res{'file_name'} =$file_name;20682069return%res;2070}20712072## ----------------------------------------------------------------------2073## git utility subroutines, invoking git commands20742075# returns path to the core git executable and the --git-dir parameter as list2076sub git_cmd {2077$number_of_git_cmds++;2078return$GIT,'--git-dir='.$git_dir;2079}20802081# quote the given arguments for passing them to the shell2082# quote_command("command", "arg 1", "arg with ' and ! characters")2083# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2084# Try to avoid using this function wherever possible.2085sub quote_command {2086returnjoin(' ',2087map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2088}20892090# get HEAD ref of given project as hash2091sub git_get_head_hash {2092return git_get_full_hash(shift,'HEAD');2093}20942095sub git_get_full_hash {2096return git_get_hash(@_);2097}20982099sub git_get_short_hash {2100return git_get_hash(@_,'--short=7');2101}21022103sub git_get_hash {2104my($project,$hash,@options) =@_;2105my$o_git_dir=$git_dir;2106my$retval=undef;2107$git_dir="$projectroot/$project";2108if(open my$fd,'-|', git_cmd(),'rev-parse',2109'--verify','-q',@options,$hash) {2110$retval= <$fd>;2111chomp$retvalifdefined$retval;2112close$fd;2113}2114if(defined$o_git_dir) {2115$git_dir=$o_git_dir;2116}2117return$retval;2118}21192120# get type of given object2121sub git_get_type {2122my$hash=shift;21232124open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2125my$type= <$fd>;2126close$fdorreturn;2127chomp$type;2128return$type;2129}21302131# repository configuration2132our$config_file='';2133our%config;21342135# store multiple values for single key as anonymous array reference2136# single values stored directly in the hash, not as [ <value> ]2137sub hash_set_multi {2138my($hash,$key,$value) =@_;21392140if(!exists$hash->{$key}) {2141$hash->{$key} =$value;2142}elsif(!ref$hash->{$key}) {2143$hash->{$key} = [$hash->{$key},$value];2144}else{2145push@{$hash->{$key}},$value;2146}2147}21482149# return hash of git project configuration2150# optionally limited to some section, e.g. 'gitweb'2151sub git_parse_project_config {2152my$section_regexp=shift;2153my%config;21542155local$/="\0";21562157open my$fh,"-|", git_cmd(),"config",'-z','-l',2158orreturn;21592160while(my$keyval= <$fh>) {2161chomp$keyval;2162my($key,$value) =split(/\n/,$keyval,2);21632164 hash_set_multi(\%config,$key,$value)2165if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2166}2167close$fh;21682169return%config;2170}21712172# convert config value to boolean: 'true' or 'false'2173# no value, number > 0, 'true' and 'yes' values are true2174# rest of values are treated as false (never as error)2175sub config_to_bool {2176my$val=shift;21772178return1if!defined$val;# section.key21792180# strip leading and trailing whitespace2181$val=~s/^\s+//;2182$val=~s/\s+$//;21832184return(($val=~/^\d+$/&&$val) ||# section.key = 12185($val=~/^(?:true|yes)$/i));# section.key = true2186}21872188# convert config value to simple decimal number2189# an optional value suffix of 'k', 'm', or 'g' will cause the value2190# to be multiplied by 1024, 1048576, or 10737418242191sub config_to_int {2192my$val=shift;21932194# strip leading and trailing whitespace2195$val=~s/^\s+//;2196$val=~s/\s+$//;21972198if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2199$unit=lc($unit);2200# unknown unit is treated as 12201return$num* ($uniteq'g'?1073741824:2202$uniteq'm'?1048576:2203$uniteq'k'?1024:1);2204}2205return$val;2206}22072208# convert config value to array reference, if needed2209sub config_to_multi {2210my$val=shift;22112212returnref($val) ?$val: (defined($val) ? [$val] : []);2213}22142215sub git_get_project_config {2216my($key,$type) =@_;22172218return unlessdefined$git_dir;22192220# key sanity check2221return unless($key);2222$key=~s/^gitweb\.//;2223return if($key=~m/\W/);22242225# type sanity check2226if(defined$type) {2227$type=~s/^--//;2228$type=undef2229unless($typeeq'bool'||$typeeq'int');2230}22312232# get config2233if(!defined$config_file||2234$config_filene"$git_dir/config") {2235%config= git_parse_project_config('gitweb');2236$config_file="$git_dir/config";2237}22382239# check if config variable (key) exists2240return unlessexists$config{"gitweb.$key"};22412242# ensure given type2243if(!defined$type) {2244return$config{"gitweb.$key"};2245}elsif($typeeq'bool') {2246# backward compatibility: 'git config --bool' returns true/false2247return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2248}elsif($typeeq'int') {2249return config_to_int($config{"gitweb.$key"});2250}2251return$config{"gitweb.$key"};2252}22532254# get hash of given path at given ref2255sub git_get_hash_by_path {2256my$base=shift;2257my$path=shift||returnundef;2258my$type=shift;22592260$path=~ s,/+$,,;22612262open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2263or die_error(500,"Open git-ls-tree failed");2264my$line= <$fd>;2265close$fdorreturnundef;22662267if(!defined$line) {2268# there is no tree or hash given by $path at $base2269returnundef;2270}22712272#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2273$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2274if(defined$type&&$typene$2) {2275# type doesn't match2276returnundef;2277}2278return$3;2279}22802281# get path of entry with given hash at given tree-ish (ref)2282# used to get 'from' filename for combined diff (merge commit) for renames2283sub git_get_path_by_hash {2284my$base=shift||return;2285my$hash=shift||return;22862287local$/="\0";22882289open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2290orreturnundef;2291while(my$line= <$fd>) {2292chomp$line;22932294#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2295#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2296if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2297close$fd;2298return$1;2299}2300}2301close$fd;2302returnundef;2303}23042305## ......................................................................2306## git utility functions, directly accessing git repository23072308sub git_get_project_description {2309my$path=shift;23102311$git_dir="$projectroot/$path";2312open my$fd,'<',"$git_dir/description"2313orreturn git_get_project_config('description');2314my$descr= <$fd>;2315close$fd;2316if(defined$descr) {2317chomp$descr;2318}2319return$descr;2320}23212322sub git_get_project_ctags {2323my$path=shift;2324my$ctags= {};23252326$git_dir="$projectroot/$path";2327opendir my$dh,"$git_dir/ctags"2328orreturn$ctags;2329foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2330open my$ct,'<',$_ornext;2331my$val= <$ct>;2332chomp$val;2333close$ct;2334my$ctag=$_;$ctag=~ s#.*/##;2335$ctags->{$ctag} =$val;2336}2337closedir$dh;2338$ctags;2339}23402341sub git_populate_project_tagcloud {2342my$ctags=shift;23432344# First, merge different-cased tags; tags vote on casing2345my%ctags_lc;2346foreach(keys%$ctags) {2347$ctags_lc{lc$_}->{count} +=$ctags->{$_};2348if(not$ctags_lc{lc$_}->{topcount}2349or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2350$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2351$ctags_lc{lc$_}->{topname} =$_;2352}2353}23542355my$cloud;2356if(eval{require HTML::TagCloud;1; }) {2357$cloud= HTML::TagCloud->new;2358foreach(sort keys%ctags_lc) {2359# Pad the title with spaces so that the cloud looks2360# less crammed.2361my$title=$ctags_lc{$_}->{topname};2362$title=~s/ / /g;2363$title=~s/^/ /g;2364$title=~s/$/ /g;2365$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2366}2367}else{2368$cloud= \%ctags_lc;2369}2370$cloud;2371}23722373sub git_show_project_tagcloud {2374my($cloud,$count) =@_;2375print STDERR ref($cloud)."..\n";2376if(ref$cloudeq'HTML::TagCloud') {2377return$cloud->html_and_css($count);2378}else{2379my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2380return'<p align="center">'.join(', ',map{2381"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"2382}splice(@tags,0,$count)) .'</p>';2383}2384}23852386sub git_get_project_url_list {2387my$path=shift;23882389$git_dir="$projectroot/$path";2390open my$fd,'<',"$git_dir/cloneurl"2391orreturnwantarray?2392@{ config_to_multi(git_get_project_config('url')) } :2393 config_to_multi(git_get_project_config('url'));2394my@git_project_url_list=map{chomp;$_} <$fd>;2395close$fd;23962397returnwantarray?@git_project_url_list: \@git_project_url_list;2398}23992400sub git_get_projects_list {2401my($filter) =@_;2402my@list;24032404$filter||='';2405$filter=~s/\.git$//;24062407my$check_forks= gitweb_check_feature('forks');24082409if(-d $projects_list) {2410# search in directory2411my$dir=$projects_list. ($filter?"/$filter":'');2412# remove the trailing "/"2413$dir=~s!/+$!!;2414my$pfxlen=length("$dir");2415my$pfxdepth= ($dir=~tr!/!!);24162417 File::Find::find({2418 follow_fast =>1,# follow symbolic links2419 follow_skip =>2,# ignore duplicates2420 dangling_symlinks =>0,# ignore dangling symlinks, silently2421 wanted =>sub{2422# skip project-list toplevel, if we get it.2423return if(m!^[/.]$!);2424# only directories can be git repositories2425return unless(-d $_);2426# don't traverse too deep (Find is super slow on os x)2427if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2428$File::Find::prune =1;2429return;2430}24312432my$subdir=substr($File::Find::name,$pfxlen+1);2433# we check related file in $projectroot2434my$path= ($filter?"$filter/":'') .$subdir;2435if(check_export_ok("$projectroot/$path")) {2436push@list, { path =>$path};2437$File::Find::prune =1;2438}2439},2440},"$dir");24412442}elsif(-f $projects_list) {2443# read from file(url-encoded):2444# 'git%2Fgit.git Linus+Torvalds'2445# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2446# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2447my%paths;2448open my$fd,'<',$projects_listorreturn;2449 PROJECT:2450while(my$line= <$fd>) {2451chomp$line;2452my($path,$owner) =split' ',$line;2453$path= unescape($path);2454$owner= unescape($owner);2455if(!defined$path) {2456next;2457}2458if($filterne'') {2459# looking for forks;2460my$pfx=substr($path,0,length($filter));2461if($pfxne$filter) {2462next PROJECT;2463}2464my$sfx=substr($path,length($filter));2465if($sfx!~/^\/.*\.git$/) {2466next PROJECT;2467}2468}elsif($check_forks) {2469 PATH:2470foreachmy$filter(keys%paths) {2471# looking for forks;2472my$pfx=substr($path,0,length($filter));2473if($pfxne$filter) {2474next PATH;2475}2476my$sfx=substr($path,length($filter));2477if($sfx!~/^\/.*\.git$/) {2478next PATH;2479}2480# is a fork, don't include it in2481# the list2482next PROJECT;2483}2484}2485if(check_export_ok("$projectroot/$path")) {2486my$pr= {2487 path =>$path,2488 owner => to_utf8($owner),2489};2490push@list,$pr;2491(my$forks_path=$path) =~s/\.git$//;2492$paths{$forks_path}++;2493}2494}2495close$fd;2496}2497return@list;2498}24992500our$gitweb_project_owner=undef;2501sub git_get_project_list_from_file {25022503return if(defined$gitweb_project_owner);25042505$gitweb_project_owner= {};2506# read from file (url-encoded):2507# 'git%2Fgit.git Linus+Torvalds'2508# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2509# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2510if(-f $projects_list) {2511open(my$fd,'<',$projects_list);2512while(my$line= <$fd>) {2513chomp$line;2514my($pr,$ow) =split' ',$line;2515$pr= unescape($pr);2516$ow= unescape($ow);2517$gitweb_project_owner->{$pr} = to_utf8($ow);2518}2519close$fd;2520}2521}25222523sub git_get_project_owner {2524my$project=shift;2525my$owner;25262527returnundefunless$project;2528$git_dir="$projectroot/$project";25292530if(!defined$gitweb_project_owner) {2531 git_get_project_list_from_file();2532}25332534if(exists$gitweb_project_owner->{$project}) {2535$owner=$gitweb_project_owner->{$project};2536}2537if(!defined$owner){2538$owner= git_get_project_config('owner');2539}2540if(!defined$owner) {2541$owner= get_file_owner("$git_dir");2542}25432544return$owner;2545}25462547sub git_get_last_activity {2548my($path) =@_;2549my$fd;25502551$git_dir="$projectroot/$path";2552open($fd,"-|", git_cmd(),'for-each-ref',2553'--format=%(committer)',2554'--sort=-committerdate',2555'--count=1',2556'refs/heads')orreturn;2557my$most_recent= <$fd>;2558close$fdorreturn;2559if(defined$most_recent&&2560$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2561my$timestamp=$1;2562my$age=time-$timestamp;2563return($age, age_string($age));2564}2565return(undef,undef);2566}25672568sub git_get_references {2569my$type=shift||"";2570my%refs;2571# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112572# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2573open my$fd,"-|", git_cmd(),"show-ref","--dereference",2574($type? ("--","refs/$type") : ())# use -- <pattern> if $type2575orreturn;25762577while(my$line= <$fd>) {2578chomp$line;2579if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2580if(defined$refs{$1}) {2581push@{$refs{$1}},$2;2582}else{2583$refs{$1} = [$2];2584}2585}2586}2587close$fdorreturn;2588return \%refs;2589}25902591sub git_get_rev_name_tags {2592my$hash=shift||returnundef;25932594open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2595orreturn;2596my$name_rev= <$fd>;2597close$fd;25982599if($name_rev=~ m|^$hash tags/(.*)$|) {2600return$1;2601}else{2602# catches also '$hash undefined' output2603returnundef;2604}2605}26062607## ----------------------------------------------------------------------2608## parse to hash functions26092610sub parse_date {2611my$epoch=shift;2612my$tz=shift||"-0000";26132614my%date;2615my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2616my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2617my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2618$date{'hour'} =$hour;2619$date{'minute'} =$min;2620$date{'mday'} =$mday;2621$date{'day'} =$days[$wday];2622$date{'month'} =$months[$mon];2623$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2624$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2625$date{'mday-time'} =sprintf"%d%s%02d:%02d",2626$mday,$months[$mon],$hour,$min;2627$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",26281900+$year,1+$mon,$mday,$hour,$min,$sec;26292630$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2631my$local=$epoch+ ((int$1+ ($2/60)) *3600);2632($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2633$date{'hour_local'} =$hour;2634$date{'minute_local'} =$min;2635$date{'tz_local'} =$tz;2636$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",26371900+$year,$mon+1,$mday,2638$hour,$min,$sec,$tz);2639return%date;2640}26412642sub parse_tag {2643my$tag_id=shift;2644my%tag;2645my@comment;26462647open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2648$tag{'id'} =$tag_id;2649while(my$line= <$fd>) {2650chomp$line;2651if($line=~m/^object ([0-9a-fA-F]{40})$/) {2652$tag{'object'} =$1;2653}elsif($line=~m/^type (.+)$/) {2654$tag{'type'} =$1;2655}elsif($line=~m/^tag (.+)$/) {2656$tag{'name'} =$1;2657}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2658$tag{'author'} =$1;2659$tag{'author_epoch'} =$2;2660$tag{'author_tz'} =$3;2661if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {2662$tag{'author_name'} =$1;2663$tag{'author_email'} =$2;2664}else{2665$tag{'author_name'} =$tag{'author'};2666}2667}elsif($line=~m/--BEGIN/) {2668push@comment,$line;2669last;2670}elsif($lineeq"") {2671last;2672}2673}2674push@comment, <$fd>;2675$tag{'comment'} = \@comment;2676close$fdorreturn;2677if(!defined$tag{'name'}) {2678return2679};2680return%tag2681}26822683sub parse_commit_text {2684my($commit_text,$withparents) =@_;2685my@commit_lines=split'\n',$commit_text;2686my%co;26872688pop@commit_lines;# Remove '\0'26892690if(!@commit_lines) {2691return;2692}26932694my$header=shift@commit_lines;2695if($header!~m/^[0-9a-fA-F]{40}/) {2696return;2697}2698($co{'id'},my@parents) =split' ',$header;2699while(my$line=shift@commit_lines) {2700last if$lineeq"\n";2701if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2702$co{'tree'} =$1;2703}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2704push@parents,$1;2705}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2706$co{'author'} = to_utf8($1);2707$co{'author_epoch'} =$2;2708$co{'author_tz'} =$3;2709if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2710$co{'author_name'} =$1;2711$co{'author_email'} =$2;2712}else{2713$co{'author_name'} =$co{'author'};2714}2715}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2716$co{'committer'} = to_utf8($1);2717$co{'committer_epoch'} =$2;2718$co{'committer_tz'} =$3;2719if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2720$co{'committer_name'} =$1;2721$co{'committer_email'} =$2;2722}else{2723$co{'committer_name'} =$co{'committer'};2724}2725}2726}2727if(!defined$co{'tree'}) {2728return;2729};2730$co{'parents'} = \@parents;2731$co{'parent'} =$parents[0];27322733foreachmy$title(@commit_lines) {2734$title=~s/^ //;2735if($titlene"") {2736$co{'title'} = chop_str($title,80,5);2737# remove leading stuff of merges to make the interesting part visible2738if(length($title) >50) {2739$title=~s/^Automatic //;2740$title=~s/^merge (of|with) /Merge ... /i;2741if(length($title) >50) {2742$title=~s/(http|rsync):\/\///;2743}2744if(length($title) >50) {2745$title=~s/(master|www|rsync)\.//;2746}2747if(length($title) >50) {2748$title=~s/kernel.org:?//;2749}2750if(length($title) >50) {2751$title=~s/\/pub\/scm//;2752}2753}2754$co{'title_short'} = chop_str($title,50,5);2755last;2756}2757}2758if(!defined$co{'title'} ||$co{'title'}eq"") {2759$co{'title'} =$co{'title_short'} ='(no commit message)';2760}2761# remove added spaces2762foreachmy$line(@commit_lines) {2763$line=~s/^ //;2764}2765$co{'comment'} = \@commit_lines;27662767my$age=time-$co{'committer_epoch'};2768$co{'age'} =$age;2769$co{'age_string'} = age_string($age);2770my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2771if($age>60*60*24*7*2) {2772$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2773$co{'age_string_age'} =$co{'age_string'};2774}else{2775$co{'age_string_date'} =$co{'age_string'};2776$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2777}2778return%co;2779}27802781sub parse_commit {2782my($commit_id) =@_;2783my%co;27842785local$/="\0";27862787open my$fd,"-|", git_cmd(),"rev-list",2788"--parents",2789"--header",2790"--max-count=1",2791$commit_id,2792"--",2793or die_error(500,"Open git-rev-list failed");2794%co= parse_commit_text(<$fd>,1);2795close$fd;27962797return%co;2798}27992800sub parse_commits {2801my($commit_id,$maxcount,$skip,$filename,@args) =@_;2802my@cos;28032804$maxcount||=1;2805$skip||=0;28062807local$/="\0";28082809open my$fd,"-|", git_cmd(),"rev-list",2810"--header",2811@args,2812("--max-count=".$maxcount),2813("--skip=".$skip),2814@extra_options,2815$commit_id,2816"--",2817($filename? ($filename) : ())2818or die_error(500,"Open git-rev-list failed");2819while(my$line= <$fd>) {2820my%co= parse_commit_text($line);2821push@cos, \%co;2822}2823close$fd;28242825returnwantarray?@cos: \@cos;2826}28272828# parse line of git-diff-tree "raw" output2829sub parse_difftree_raw_line {2830my$line=shift;2831my%res;28322833# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2834# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2835if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2836$res{'from_mode'} =$1;2837$res{'to_mode'} =$2;2838$res{'from_id'} =$3;2839$res{'to_id'} =$4;2840$res{'status'} =$5;2841$res{'similarity'} =$6;2842if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2843($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2844}else{2845$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2846}2847}2848# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2849# combined diff (for merge commit)2850elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2851$res{'nparents'} =length($1);2852$res{'from_mode'} = [split(' ',$2) ];2853$res{'to_mode'} =pop@{$res{'from_mode'}};2854$res{'from_id'} = [split(' ',$3) ];2855$res{'to_id'} =pop@{$res{'from_id'}};2856$res{'status'} = [split('',$4) ];2857$res{'to_file'} = unquote($5);2858}2859# 'c512b523472485aef4fff9e57b229d9d243c967f'2860elsif($line=~m/^([0-9a-fA-F]{40})$/) {2861$res{'commit'} =$1;2862}28632864returnwantarray?%res: \%res;2865}28662867# wrapper: return parsed line of git-diff-tree "raw" output2868# (the argument might be raw line, or parsed info)2869sub parsed_difftree_line {2870my$line_or_ref=shift;28712872if(ref($line_or_ref)eq"HASH") {2873# pre-parsed (or generated by hand)2874return$line_or_ref;2875}else{2876return parse_difftree_raw_line($line_or_ref);2877}2878}28792880# parse line of git-ls-tree output2881sub parse_ls_tree_line {2882my$line=shift;2883my%opts=@_;2884my%res;28852886if($opts{'-l'}) {2887#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'2888$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;28892890$res{'mode'} =$1;2891$res{'type'} =$2;2892$res{'hash'} =$3;2893$res{'size'} =$4;2894if($opts{'-z'}) {2895$res{'name'} =$5;2896}else{2897$res{'name'} = unquote($5);2898}2899}else{2900#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2901$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;29022903$res{'mode'} =$1;2904$res{'type'} =$2;2905$res{'hash'} =$3;2906if($opts{'-z'}) {2907$res{'name'} =$4;2908}else{2909$res{'name'} = unquote($4);2910}2911}29122913returnwantarray?%res: \%res;2914}29152916# generates _two_ hashes, references to which are passed as 2 and 3 argument2917sub parse_from_to_diffinfo {2918my($diffinfo,$from,$to,@parents) =@_;29192920if($diffinfo->{'nparents'}) {2921# combined diff2922$from->{'file'} = [];2923$from->{'href'} = [];2924 fill_from_file_info($diffinfo,@parents)2925unlessexists$diffinfo->{'from_file'};2926for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2927$from->{'file'}[$i] =2928defined$diffinfo->{'from_file'}[$i] ?2929$diffinfo->{'from_file'}[$i] :2930$diffinfo->{'to_file'};2931if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2932$from->{'href'}[$i] = href(action=>"blob",2933 hash_base=>$parents[$i],2934 hash=>$diffinfo->{'from_id'}[$i],2935 file_name=>$from->{'file'}[$i]);2936}else{2937$from->{'href'}[$i] =undef;2938}2939}2940}else{2941# ordinary (not combined) diff2942$from->{'file'} =$diffinfo->{'from_file'};2943if($diffinfo->{'status'}ne"A") {# not new (added) file2944$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2945 hash=>$diffinfo->{'from_id'},2946 file_name=>$from->{'file'});2947}else{2948delete$from->{'href'};2949}2950}29512952$to->{'file'} =$diffinfo->{'to_file'};2953if(!is_deleted($diffinfo)) {# file exists in result2954$to->{'href'} = href(action=>"blob", hash_base=>$hash,2955 hash=>$diffinfo->{'to_id'},2956 file_name=>$to->{'file'});2957}else{2958delete$to->{'href'};2959}2960}29612962## ......................................................................2963## parse to array of hashes functions29642965sub git_get_heads_list {2966my$limit=shift;2967my@headslist;29682969open my$fd,'-|', git_cmd(),'for-each-ref',2970($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2971'--format=%(objectname) %(refname) %(subject)%00%(committer)',2972'refs/heads'2973orreturn;2974while(my$line= <$fd>) {2975my%ref_item;29762977chomp$line;2978my($refinfo,$committerinfo) =split(/\0/,$line);2979my($hash,$name,$title) =split(' ',$refinfo,3);2980my($committer,$epoch,$tz) =2981($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2982$ref_item{'fullname'} =$name;2983$name=~s!^refs/heads/!!;29842985$ref_item{'name'} =$name;2986$ref_item{'id'} =$hash;2987$ref_item{'title'} =$title||'(no commit message)';2988$ref_item{'epoch'} =$epoch;2989if($epoch) {2990$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2991}else{2992$ref_item{'age'} ="unknown";2993}29942995push@headslist, \%ref_item;2996}2997close$fd;29982999returnwantarray?@headslist: \@headslist;3000}30013002sub git_get_tags_list {3003my$limit=shift;3004my@tagslist;30053006open my$fd,'-|', git_cmd(),'for-each-ref',3007($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',3008'--format=%(objectname) %(objecttype) %(refname) '.3009'%(*objectname) %(*objecttype) %(subject)%00%(creator)',3010'refs/tags'3011orreturn;3012while(my$line= <$fd>) {3013my%ref_item;30143015chomp$line;3016my($refinfo,$creatorinfo) =split(/\0/,$line);3017my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);3018my($creator,$epoch,$tz) =3019($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);3020$ref_item{'fullname'} =$name;3021$name=~s!^refs/tags/!!;30223023$ref_item{'type'} =$type;3024$ref_item{'id'} =$id;3025$ref_item{'name'} =$name;3026if($typeeq"tag") {3027$ref_item{'subject'} =$title;3028$ref_item{'reftype'} =$reftype;3029$ref_item{'refid'} =$refid;3030}else{3031$ref_item{'reftype'} =$type;3032$ref_item{'refid'} =$id;3033}30343035if($typeeq"tag"||$typeeq"commit") {3036$ref_item{'epoch'} =$epoch;3037if($epoch) {3038$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3039}else{3040$ref_item{'age'} ="unknown";3041}3042}30433044push@tagslist, \%ref_item;3045}3046close$fd;30473048returnwantarray?@tagslist: \@tagslist;3049}30503051## ----------------------------------------------------------------------3052## filesystem-related functions30533054sub get_file_owner {3055my$path=shift;30563057my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);3058my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);3059if(!defined$gcos) {3060returnundef;3061}3062my$owner=$gcos;3063$owner=~s/[,;].*$//;3064return to_utf8($owner);3065}30663067# assume that file exists3068sub insert_file {3069my$filename=shift;30703071open my$fd,'<',$filename;3072print map{ to_utf8($_) } <$fd>;3073close$fd;3074}30753076## ......................................................................3077## mimetype related functions30783079sub mimetype_guess_file {3080my$filename=shift;3081my$mimemap=shift;3082-r $mimemaporreturnundef;30833084my%mimemap;3085open(my$mh,'<',$mimemap)orreturnundef;3086while(<$mh>) {3087next ifm/^#/;# skip comments3088my($mimetype,$exts) =split(/\t+/);3089if(defined$exts) {3090my@exts=split(/\s+/,$exts);3091foreachmy$ext(@exts) {3092$mimemap{$ext} =$mimetype;3093}3094}3095}3096close($mh);30973098$filename=~/\.([^.]*)$/;3099return$mimemap{$1};3100}31013102sub mimetype_guess {3103my$filename=shift;3104my$mime;3105$filename=~/\./orreturnundef;31063107if($mimetypes_file) {3108my$file=$mimetypes_file;3109if($file!~m!^/!) {# if it is relative path3110# it is relative to project3111$file="$projectroot/$project/$file";3112}3113$mime= mimetype_guess_file($filename,$file);3114}3115$mime||= mimetype_guess_file($filename,'/etc/mime.types');3116return$mime;3117}31183119sub blob_mimetype {3120my$fd=shift;3121my$filename=shift;31223123if($filename) {3124my$mime= mimetype_guess($filename);3125$mimeandreturn$mime;3126}31273128# just in case3129return$default_blob_plain_mimetypeunless$fd;31303131if(-T $fd) {3132return'text/plain';3133}elsif(!$filename) {3134return'application/octet-stream';3135}elsif($filename=~m/\.png$/i) {3136return'image/png';3137}elsif($filename=~m/\.gif$/i) {3138return'image/gif';3139}elsif($filename=~m/\.jpe?g$/i) {3140return'image/jpeg';3141}else{3142return'application/octet-stream';3143}3144}31453146sub blob_contenttype {3147my($fd,$file_name,$type) =@_;31483149$type||= blob_mimetype($fd,$file_name);3150if($typeeq'text/plain'&&defined$default_text_plain_charset) {3151$type.="; charset=$default_text_plain_charset";3152}31533154return$type;3155}31563157## ======================================================================3158## functions printing HTML: header, footer, error page31593160sub git_header_html {3161my$status=shift||"200 OK";3162my$expires=shift;31633164my$title="$site_name";3165if(defined$project) {3166$title.=" - ". to_utf8($project);3167if(defined$action) {3168$title.="/$action";3169if(defined$file_name) {3170$title.=" - ". esc_path($file_name);3171if($actioneq"tree"&&$file_name!~ m|/$|) {3172$title.="/";3173}3174}3175}3176}3177my$content_type;3178# require explicit support from the UA if we are to send the page as3179# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3180# we have to do this because MSIE sometimes globs '*/*', pretending to3181# support xhtml+xml but choking when it gets what it asked for.3182if(defined$cgi->http('HTTP_ACCEPT') &&3183$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3184$cgi->Accept('application/xhtml+xml') !=0) {3185$content_type='application/xhtml+xml';3186}else{3187$content_type='text/html';3188}3189print$cgi->header(-type=>$content_type, -charset =>'utf-8',3190-status=>$status, -expires =>$expires);3191my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';3192print<<EOF;3193<?xml version="1.0" encoding="utf-8"?>3194<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">3195<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">3196<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->3197<!-- git core binaries version$git_version-->3198<head>3199<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>3200<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>3201<meta name="robots" content="index, nofollow"/>3202<title>$title</title>3203EOF3204# the stylesheet, favicon etc urls won't work correctly with path_info3205# unless we set the appropriate base URL3206if($ENV{'PATH_INFO'}) {3207print"<base href=\"".esc_url($base_url)."\"/>\n";3208}3209# print out each stylesheet that exist, providing backwards capability3210# for those people who defined $stylesheet in a config file3211if(defined$stylesheet) {3212print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3213}else{3214foreachmy$stylesheet(@stylesheets) {3215next unless$stylesheet;3216print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3217}3218}3219if(defined$project) {3220my%href_params= get_feed_info();3221if(!exists$href_params{'-title'}) {3222$href_params{'-title'} ='log';3223}32243225foreachmy$formatqw(RSS Atom){3226my$type=lc($format);3227my%link_attr= (3228'-rel'=>'alternate',3229'-title'=>"$project-$href_params{'-title'} -$formatfeed",3230'-type'=>"application/$type+xml"3231);32323233$href_params{'action'} =$type;3234$link_attr{'-href'} = href(%href_params);3235print"<link ".3236"rel=\"$link_attr{'-rel'}\"".3237"title=\"$link_attr{'-title'}\"".3238"href=\"$link_attr{'-href'}\"".3239"type=\"$link_attr{'-type'}\"".3240"/>\n";32413242$href_params{'extra_options'} ='--no-merges';3243$link_attr{'-href'} = href(%href_params);3244$link_attr{'-title'} .=' (no merges)';3245print"<link ".3246"rel=\"$link_attr{'-rel'}\"".3247"title=\"$link_attr{'-title'}\"".3248"href=\"$link_attr{'-href'}\"".3249"type=\"$link_attr{'-type'}\"".3250"/>\n";3251}32523253}else{3254printf('<link rel="alternate" title="%sprojects list" '.3255'href="%s" type="text/plain; charset=utf-8" />'."\n",3256$site_name, href(project=>undef, action=>"project_index"));3257printf('<link rel="alternate" title="%sprojects feeds" '.3258'href="%s" type="text/x-opml" />'."\n",3259$site_name, href(project=>undef, action=>"opml"));3260}3261if(defined$favicon) {3262printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);3263}32643265print"</head>\n".3266"<body>\n";32673268if(defined$site_header&& -f $site_header) {3269 insert_file($site_header);3270}32713272print"<div class=\"page_header\">\n".3273$cgi->a({-href => esc_url($logo_url),3274-title =>$logo_label},3275qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));3276print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3277if(defined$project) {3278print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3279if(defined$action) {3280print" /$action";3281}3282print"\n";3283}3284print"</div>\n";32853286my$have_search= gitweb_check_feature('search');3287if(defined$project&&$have_search) {3288if(!defined$searchtext) {3289$searchtext="";3290}3291my$search_hash;3292if(defined$hash_base) {3293$search_hash=$hash_base;3294}elsif(defined$hash) {3295$search_hash=$hash;3296}else{3297$search_hash="HEAD";3298}3299my$action=$my_uri;3300my$use_pathinfo= gitweb_check_feature('pathinfo');3301if($use_pathinfo) {3302$action.="/".esc_url($project);3303}3304print$cgi->startform(-method=>"get", -action =>$action) .3305"<div class=\"search\">\n".3306(!$use_pathinfo&&3307$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3308$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3309$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3310$cgi->popup_menu(-name =>'st', -default=>'commit',3311-values=> ['commit','grep','author','committer','pickaxe']) .3312$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3313" search:\n",3314$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3315"<span title=\"Extended regular expression\">".3316$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3317-checked =>$search_use_regexp) .3318"</span>".3319"</div>".3320$cgi->end_form() ."\n";3321}3322}33233324sub git_footer_html {3325my$feed_class='rss_logo';33263327print"<div class=\"page_footer\">\n";3328if(defined$project) {3329my$descr= git_get_project_description($project);3330if(defined$descr) {3331print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3332}33333334my%href_params= get_feed_info();3335if(!%href_params) {3336$feed_class.=' generic';3337}3338$href_params{'-title'} ||='log';33393340foreachmy$formatqw(RSS Atom){3341$href_params{'action'} =lc($format);3342print$cgi->a({-href => href(%href_params),3343-title =>"$href_params{'-title'}$formatfeed",3344-class=>$feed_class},$format)."\n";3345}33463347}else{3348print$cgi->a({-href => href(project=>undef, action=>"opml"),3349-class=>$feed_class},"OPML") ." ";3350print$cgi->a({-href => href(project=>undef, action=>"project_index"),3351-class=>$feed_class},"TXT") ."\n";3352}3353print"</div>\n";# class="page_footer"33543355if(defined$t0&& gitweb_check_feature('timed')) {3356print"<div id=\"generating_info\">\n";3357print'This page took '.3358'<span id="generating_time" class="time_span">'.3359 Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).3360' seconds </span>'.3361' and '.3362'<span id="generating_cmd">'.3363$number_of_git_cmds.3364'</span> git commands '.3365" to generate.\n";3366print"</div>\n";# class="page_footer"3367}33683369if(defined$site_footer&& -f $site_footer) {3370 insert_file($site_footer);3371}33723373print qq!<script type="text/javascript" src="$javascript"></script>\n!;3374if(defined$action&&3375$actioneq'blame_incremental') {3376print qq!<script type="text/javascript">\n!.3377 qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.3378 qq!"!. href() .qq!");\n!.3379 qq!</script>\n!;3380}elsif(gitweb_check_feature('javascript-actions')) {3381print qq!<script type="text/javascript">\n!.3382 qq!window.onload = fixLinks;\n!.3383 qq!</script>\n!;3384}33853386print"</body>\n".3387"</html>";3388}33893390# die_error(<http_status_code>, <error_message>[, <detailed_html_description>])3391# Example: die_error(404, 'Hash not found')3392# By convention, use the following status codes (as defined in RFC 2616):3393# 400: Invalid or missing CGI parameters, or3394# requested object exists but has wrong type.3395# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3396# this server or project.3397# 404: Requested object/revision/project doesn't exist.3398# 500: The server isn't configured properly, or3399# an internal error occurred (e.g. failed assertions caused by bugs), or3400# an unknown error occurred (e.g. the git binary died unexpectedly).3401# 503: The server is currently unavailable (because it is overloaded,3402# or down for maintenance). Generally, this is a temporary state.3403sub die_error {3404my$status=shift||500;3405my$error= esc_html(shift) ||"Internal Server Error";3406my$extra=shift;34073408my%http_responses= (3409400=>'400 Bad Request',3410403=>'403 Forbidden',3411404=>'404 Not Found',3412500=>'500 Internal Server Error',3413503=>'503 Service Unavailable',3414);3415 git_header_html($http_responses{$status});3416print<<EOF;3417<div class="page_body">3418<br /><br />3419$status-$error3420<br />3421EOF3422if(defined$extra) {3423print"<hr />\n".3424"$extra\n";3425}3426print"</div>\n";34273428 git_footer_html();3429exit;3430}34313432## ----------------------------------------------------------------------3433## functions printing or outputting HTML: navigation34343435sub git_print_page_nav {3436my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3437$extra=''if!defined$extra;# pager or formats34383439my@navs=qw(summary shortlog log commit commitdiff tree);3440if($suppress) {3441@navs=grep{$_ne$suppress}@navs;3442}34433444my%arg=map{$_=> {action=>$_} }@navs;3445if(defined$head) {3446for(qw(commit commitdiff)) {3447$arg{$_}{'hash'} =$head;3448}3449if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3450for(qw(shortlog log)) {3451$arg{$_}{'hash'} =$head;3452}3453}3454}34553456$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3457$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;34583459my@actions= gitweb_get_feature('actions');3460my%repl= (3461'%'=>'%',3462'n'=>$project,# project name3463'f'=>$git_dir,# project path within filesystem3464'h'=>$treehead||'',# current hash ('h' parameter)3465'b'=>$treebase||'',# hash base ('hb' parameter)3466);3467while(@actions) {3468my($label,$link,$pos) =splice(@actions,0,3);3469# insert3470@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3471# munch munch3472$link=~s/%([%nfhb])/$repl{$1}/g;3473$arg{$label}{'_href'} =$link;3474}34753476print"<div class=\"page_nav\">\n".3477(join" | ",3478map{$_eq$current?3479$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3480}@navs);3481print"<br/>\n$extra<br/>\n".3482"</div>\n";3483}34843485sub format_paging_nav {3486my($action,$page,$has_next_link) =@_;3487my$paging_nav;348834893490if($page>0) {3491$paging_nav.=3492$cgi->a({-href => href(-replay=>1, page=>undef)},"first") .3493" ⋅ ".3494$cgi->a({-href => href(-replay=>1, page=>$page-1),3495-accesskey =>"p", -title =>"Alt-p"},"prev");3496}else{3497$paging_nav.="first ⋅ prev";3498}34993500if($has_next_link) {3501$paging_nav.=" ⋅ ".3502$cgi->a({-href => href(-replay=>1, page=>$page+1),3503-accesskey =>"n", -title =>"Alt-n"},"next");3504}else{3505$paging_nav.=" ⋅ next";3506}35073508return$paging_nav;3509}35103511## ......................................................................3512## functions printing or outputting HTML: div35133514sub git_print_header_div {3515my($action,$title,$hash,$hash_base) =@_;3516my%args= ();35173518$args{'action'} =$action;3519$args{'hash'} =$hashif$hash;3520$args{'hash_base'} =$hash_baseif$hash_base;35213522print"<div class=\"header\">\n".3523$cgi->a({-href => href(%args), -class=>"title"},3524$title?$title:$action) .3525"\n</div>\n";3526}35273528sub print_local_time {3529print format_local_time(@_);3530}35313532sub format_local_time {3533my$localtime='';3534my%date=@_;3535if($date{'hour_local'} <6) {3536$localtime.=sprintf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3537$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3538}else{3539$localtime.=sprintf(" (%02d:%02d%s)",3540$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3541}35423543return$localtime;3544}35453546# Outputs the author name and date in long form3547sub git_print_authorship {3548my$co=shift;3549my%opts=@_;3550my$tag=$opts{-tag} ||'div';3551my$author=$co->{'author_name'};35523553my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3554print"<$tagclass=\"author_date\">".3555 format_search_author($author,"author", esc_html($author)) .3556" [$ad{'rfc2822'}";3557 print_local_time(%ad)if($opts{-localtime});3558print"]". git_get_avatar($co->{'author_email'}, -pad_before =>1)3559."</$tag>\n";3560}35613562# Outputs table rows containing the full author or committer information,3563# in the format expected for 'commit' view (& similia).3564# Parameters are a commit hash reference, followed by the list of people3565# to output information for. If the list is empty it defalts to both3566# author and committer.3567sub git_print_authorship_rows {3568my$co=shift;3569# too bad we can't use @people = @_ || ('author', 'committer')3570my@people=@_;3571@people= ('author','committer')unless@people;3572foreachmy$who(@people) {3573my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});3574print"<tr><td>$who</td><td>".3575 format_search_author($co->{"${who}_name"},$who,3576 esc_html($co->{"${who}_name"})) ." ".3577 format_search_author($co->{"${who}_email"},$who,3578 esc_html("<".$co->{"${who}_email"} .">")) .3579"</td><td rowspan=\"2\">".3580 git_get_avatar($co->{"${who}_email"}, -size =>'double') .3581"</td></tr>\n".3582"<tr>".3583"<td></td><td>$wd{'rfc2822'}";3584 print_local_time(%wd);3585print"</td>".3586"</tr>\n";3587}3588}35893590sub git_print_page_path {3591my$name=shift;3592my$type=shift;3593my$hb=shift;359435953596print"<div class=\"page_path\">";3597print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3598-title =>'tree root'}, to_utf8("[$project]"));3599print" / ";3600if(defined$name) {3601my@dirname=split'/',$name;3602my$basename=pop@dirname;3603my$fullname='';36043605foreachmy$dir(@dirname) {3606$fullname.= ($fullname?'/':'') .$dir;3607print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3608 hash_base=>$hb),3609-title =>$fullname}, esc_path($dir));3610print" / ";3611}3612if(defined$type&&$typeeq'blob') {3613print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3614 hash_base=>$hb),3615-title =>$name}, esc_path($basename));3616}elsif(defined$type&&$typeeq'tree') {3617print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3618 hash_base=>$hb),3619-title =>$name}, esc_path($basename));3620print" / ";3621}else{3622print esc_path($basename);3623}3624}3625print"<br/></div>\n";3626}36273628sub git_print_log {3629my$log=shift;3630my%opts=@_;36313632if($opts{'-remove_title'}) {3633# remove title, i.e. first line of log3634shift@$log;3635}3636# remove leading empty lines3637while(defined$log->[0] &&$log->[0]eq"") {3638shift@$log;3639}36403641# print log3642my$signoff=0;3643my$empty=0;3644foreachmy$line(@$log) {3645if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3646$signoff=1;3647$empty=0;3648if(!$opts{'-remove_signoff'}) {3649print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3650next;3651}else{3652# remove signoff lines3653next;3654}3655}else{3656$signoff=0;3657}36583659# print only one empty line3660# do not print empty line after signoff3661if($lineeq"") {3662next if($empty||$signoff);3663$empty=1;3664}else{3665$empty=0;3666}36673668print format_log_line_html($line) ."<br/>\n";3669}36703671if($opts{'-final_empty_line'}) {3672# end with single empty line3673print"<br/>\n"unless$empty;3674}3675}36763677# return link target (what link points to)3678sub git_get_link_target {3679my$hash=shift;3680my$link_target;36813682# read link3683open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3684orreturn;3685{3686local$/=undef;3687$link_target= <$fd>;3688}3689close$fd3690orreturn;36913692return$link_target;3693}36943695# given link target, and the directory (basedir) the link is in,3696# return target of link relative to top directory (top tree);3697# return undef if it is not possible (including absolute links).3698sub normalize_link_target {3699my($link_target,$basedir) =@_;37003701# absolute symlinks (beginning with '/') cannot be normalized3702return if(substr($link_target,0,1)eq'/');37033704# normalize link target to path from top (root) tree (dir)3705my$path;3706if($basedir) {3707$path=$basedir.'/'.$link_target;3708}else{3709# we are in top (root) tree (dir)3710$path=$link_target;3711}37123713# remove //, /./, and /../3714my@path_parts;3715foreachmy$part(split('/',$path)) {3716# discard '.' and ''3717next if(!$part||$parteq'.');3718# handle '..'3719if($parteq'..') {3720if(@path_parts) {3721pop@path_parts;3722}else{3723# link leads outside repository (outside top dir)3724return;3725}3726}else{3727push@path_parts,$part;3728}3729}3730$path=join('/',@path_parts);37313732return$path;3733}37343735# print tree entry (row of git_tree), but without encompassing <tr> element3736sub git_print_tree_entry {3737my($t,$basedir,$hash_base,$have_blame) =@_;37383739my%base_key= ();3740$base_key{'hash_base'} =$hash_baseifdefined$hash_base;37413742# The format of a table row is: mode list link. Where mode is3743# the mode of the entry, list is the name of the entry, an href,3744# and link is the action links of the entry.37453746print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3747if(exists$t->{'size'}) {3748print"<td class=\"size\">$t->{'size'}</td>\n";3749}3750if($t->{'type'}eq"blob") {3751print"<td class=\"list\">".3752$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3753 file_name=>"$basedir$t->{'name'}",%base_key),3754-class=>"list"}, esc_path($t->{'name'}));3755if(S_ISLNK(oct$t->{'mode'})) {3756my$link_target= git_get_link_target($t->{'hash'});3757if($link_target) {3758my$norm_target= normalize_link_target($link_target,$basedir);3759if(defined$norm_target) {3760print" -> ".3761$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3762 file_name=>$norm_target),3763-title =>$norm_target}, esc_path($link_target));3764}else{3765print" -> ". esc_path($link_target);3766}3767}3768}3769print"</td>\n";3770print"<td class=\"link\">";3771print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3772 file_name=>"$basedir$t->{'name'}",%base_key)},3773"blob");3774if($have_blame) {3775print" | ".3776$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3777 file_name=>"$basedir$t->{'name'}",%base_key)},3778"blame");3779}3780if(defined$hash_base) {3781print" | ".3782$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3783 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3784"history");3785}3786print" | ".3787$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3788 file_name=>"$basedir$t->{'name'}")},3789"raw");3790print"</td>\n";37913792}elsif($t->{'type'}eq"tree") {3793print"<td class=\"list\">";3794print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3795 file_name=>"$basedir$t->{'name'}",3796%base_key)},3797 esc_path($t->{'name'}));3798print"</td>\n";3799print"<td class=\"link\">";3800print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3801 file_name=>"$basedir$t->{'name'}",3802%base_key)},3803"tree");3804if(defined$hash_base) {3805print" | ".3806$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3807 file_name=>"$basedir$t->{'name'}")},3808"history");3809}3810print"</td>\n";3811}else{3812# unknown object: we can only present history for it3813# (this includes 'commit' object, i.e. submodule support)3814print"<td class=\"list\">".3815 esc_path($t->{'name'}) .3816"</td>\n";3817print"<td class=\"link\">";3818if(defined$hash_base) {3819print$cgi->a({-href => href(action=>"history",3820 hash_base=>$hash_base,3821 file_name=>"$basedir$t->{'name'}")},3822"history");3823}3824print"</td>\n";3825}3826}38273828## ......................................................................3829## functions printing large fragments of HTML38303831# get pre-image filenames for merge (combined) diff3832sub fill_from_file_info {3833my($diff,@parents) =@_;38343835$diff->{'from_file'} = [ ];3836$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3837for(my$i=0;$i<$diff->{'nparents'};$i++) {3838if($diff->{'status'}[$i]eq'R'||3839$diff->{'status'}[$i]eq'C') {3840$diff->{'from_file'}[$i] =3841 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3842}3843}38443845return$diff;3846}38473848# is current raw difftree line of file deletion3849sub is_deleted {3850my$diffinfo=shift;38513852return$diffinfo->{'to_id'}eq('0' x 40);3853}38543855# does patch correspond to [previous] difftree raw line3856# $diffinfo - hashref of parsed raw diff format3857# $patchinfo - hashref of parsed patch diff format3858# (the same keys as in $diffinfo)3859sub is_patch_split {3860my($diffinfo,$patchinfo) =@_;38613862returndefined$diffinfo&&defined$patchinfo3863&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3864}386538663867sub git_difftree_body {3868my($difftree,$hash,@parents) =@_;3869my($parent) =$parents[0];3870my$have_blame= gitweb_check_feature('blame');3871print"<div class=\"list_head\">\n";3872if($#{$difftree} >10) {3873print(($#{$difftree} +1) ." files changed:\n");3874}3875print"</div>\n";38763877print"<table class=\"".3878(@parents>1?"combined ":"") .3879"diff_tree\">\n";38803881# header only for combined diff in 'commitdiff' view3882my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3883if($has_header) {3884# table header3885print"<thead><tr>\n".3886"<th></th><th></th>\n";# filename, patchN link3887for(my$i=0;$i<@parents;$i++) {3888my$par=$parents[$i];3889print"<th>".3890$cgi->a({-href => href(action=>"commitdiff",3891 hash=>$hash, hash_parent=>$par),3892-title =>'commitdiff to parent number '.3893($i+1) .': '.substr($par,0,7)},3894$i+1) .3895" </th>\n";3896}3897print"</tr></thead>\n<tbody>\n";3898}38993900my$alternate=1;3901my$patchno=0;3902foreachmy$line(@{$difftree}) {3903my$diff= parsed_difftree_line($line);39043905if($alternate) {3906print"<tr class=\"dark\">\n";3907}else{3908print"<tr class=\"light\">\n";3909}3910$alternate^=1;39113912if(exists$diff->{'nparents'}) {# combined diff39133914 fill_from_file_info($diff,@parents)3915unlessexists$diff->{'from_file'};39163917if(!is_deleted($diff)) {3918# file exists in the result (child) commit3919print"<td>".3920$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3921 file_name=>$diff->{'to_file'},3922 hash_base=>$hash),3923-class=>"list"}, esc_path($diff->{'to_file'})) .3924"</td>\n";3925}else{3926print"<td>".3927 esc_path($diff->{'to_file'}) .3928"</td>\n";3929}39303931if($actioneq'commitdiff') {3932# link to patch3933$patchno++;3934print"<td class=\"link\">".3935$cgi->a({-href =>"#patch$patchno"},"patch") .3936" | ".3937"</td>\n";3938}39393940my$has_history=0;3941my$not_deleted=0;3942for(my$i=0;$i<$diff->{'nparents'};$i++) {3943my$hash_parent=$parents[$i];3944my$from_hash=$diff->{'from_id'}[$i];3945my$from_path=$diff->{'from_file'}[$i];3946my$status=$diff->{'status'}[$i];39473948$has_history||= ($statusne'A');3949$not_deleted||= ($statusne'D');39503951if($statuseq'A') {3952print"<td class=\"link\"align=\"right\"> | </td>\n";3953}elsif($statuseq'D') {3954print"<td class=\"link\">".3955$cgi->a({-href => href(action=>"blob",3956 hash_base=>$hash,3957 hash=>$from_hash,3958 file_name=>$from_path)},3959"blob". ($i+1)) .3960" | </td>\n";3961}else{3962if($diff->{'to_id'}eq$from_hash) {3963print"<td class=\"link nochange\">";3964}else{3965print"<td class=\"link\">";3966}3967print$cgi->a({-href => href(action=>"blobdiff",3968 hash=>$diff->{'to_id'},3969 hash_parent=>$from_hash,3970 hash_base=>$hash,3971 hash_parent_base=>$hash_parent,3972 file_name=>$diff->{'to_file'},3973 file_parent=>$from_path)},3974"diff". ($i+1)) .3975" | </td>\n";3976}3977}39783979print"<td class=\"link\">";3980if($not_deleted) {3981print$cgi->a({-href => href(action=>"blob",3982 hash=>$diff->{'to_id'},3983 file_name=>$diff->{'to_file'},3984 hash_base=>$hash)},3985"blob");3986print" | "if($has_history);3987}3988if($has_history) {3989print$cgi->a({-href => href(action=>"history",3990 file_name=>$diff->{'to_file'},3991 hash_base=>$hash)},3992"history");3993}3994print"</td>\n";39953996print"</tr>\n";3997next;# instead of 'else' clause, to avoid extra indent3998}3999# else ordinary diff40004001my($to_mode_oct,$to_mode_str,$to_file_type);4002my($from_mode_oct,$from_mode_str,$from_file_type);4003if($diff->{'to_mode'}ne('0' x 6)) {4004$to_mode_oct=oct$diff->{'to_mode'};4005if(S_ISREG($to_mode_oct)) {# only for regular file4006$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits4007}4008$to_file_type= file_type($diff->{'to_mode'});4009}4010if($diff->{'from_mode'}ne('0' x 6)) {4011$from_mode_oct=oct$diff->{'from_mode'};4012if(S_ISREG($to_mode_oct)) {# only for regular file4013$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits4014}4015$from_file_type= file_type($diff->{'from_mode'});4016}40174018if($diff->{'status'}eq"A") {# created4019my$mode_chng="<span class=\"file_status new\">[new$to_file_type";4020$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;4021$mode_chng.="]</span>";4022print"<td>";4023print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4024 hash_base=>$hash, file_name=>$diff->{'file'}),4025-class=>"list"}, esc_path($diff->{'file'}));4026print"</td>\n";4027print"<td>$mode_chng</td>\n";4028print"<td class=\"link\">";4029if($actioneq'commitdiff') {4030# link to patch4031$patchno++;4032print$cgi->a({-href =>"#patch$patchno"},"patch");4033print" | ";4034}4035print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4036 hash_base=>$hash, file_name=>$diff->{'file'})},4037"blob");4038print"</td>\n";40394040}elsif($diff->{'status'}eq"D") {# deleted4041my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";4042print"<td>";4043print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4044 hash_base=>$parent, file_name=>$diff->{'file'}),4045-class=>"list"}, esc_path($diff->{'file'}));4046print"</td>\n";4047print"<td>$mode_chng</td>\n";4048print"<td class=\"link\">";4049if($actioneq'commitdiff') {4050# link to patch4051$patchno++;4052print$cgi->a({-href =>"#patch$patchno"},"patch");4053print" | ";4054}4055print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4056 hash_base=>$parent, file_name=>$diff->{'file'})},4057"blob") ." | ";4058if($have_blame) {4059print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,4060 file_name=>$diff->{'file'})},4061"blame") ." | ";4062}4063print$cgi->a({-href => href(action=>"history", hash_base=>$parent,4064 file_name=>$diff->{'file'})},4065"history");4066print"</td>\n";40674068}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed4069my$mode_chnge="";4070if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4071$mode_chnge="<span class=\"file_status mode_chnge\">[changed";4072if($from_file_typene$to_file_type) {4073$mode_chnge.=" from$from_file_typeto$to_file_type";4074}4075if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {4076if($from_mode_str&&$to_mode_str) {4077$mode_chnge.=" mode:$from_mode_str->$to_mode_str";4078}elsif($to_mode_str) {4079$mode_chnge.=" mode:$to_mode_str";4080}4081}4082$mode_chnge.="]</span>\n";4083}4084print"<td>";4085print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4086 hash_base=>$hash, file_name=>$diff->{'file'}),4087-class=>"list"}, esc_path($diff->{'file'}));4088print"</td>\n";4089print"<td>$mode_chnge</td>\n";4090print"<td class=\"link\">";4091if($actioneq'commitdiff') {4092# link to patch4093$patchno++;4094print$cgi->a({-href =>"#patch$patchno"},"patch") .4095" | ";4096}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4097# "commit" view and modified file (not onlu mode changed)4098print$cgi->a({-href => href(action=>"blobdiff",4099 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4100 hash_base=>$hash, hash_parent_base=>$parent,4101 file_name=>$diff->{'file'})},4102"diff") .4103" | ";4104}4105print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4106 hash_base=>$hash, file_name=>$diff->{'file'})},4107"blob") ." | ";4108if($have_blame) {4109print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4110 file_name=>$diff->{'file'})},4111"blame") ." | ";4112}4113print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4114 file_name=>$diff->{'file'})},4115"history");4116print"</td>\n";41174118}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied4119my%status_name= ('R'=>'moved','C'=>'copied');4120my$nstatus=$status_name{$diff->{'status'}};4121my$mode_chng="";4122if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4123# mode also for directories, so we cannot use $to_mode_str4124$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);4125}4126print"<td>".4127$cgi->a({-href => href(action=>"blob", hash_base=>$hash,4128 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),4129-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".4130"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".4131$cgi->a({-href => href(action=>"blob", hash_base=>$parent,4132 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),4133-class=>"list"}, esc_path($diff->{'from_file'})) .4134" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".4135"<td class=\"link\">";4136if($actioneq'commitdiff') {4137# link to patch4138$patchno++;4139print$cgi->a({-href =>"#patch$patchno"},"patch") .4140" | ";4141}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4142# "commit" view and modified file (not only pure rename or copy)4143print$cgi->a({-href => href(action=>"blobdiff",4144 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4145 hash_base=>$hash, hash_parent_base=>$parent,4146 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},4147"diff") .4148" | ";4149}4150print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4151 hash_base=>$parent, file_name=>$diff->{'to_file'})},4152"blob") ." | ";4153if($have_blame) {4154print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4155 file_name=>$diff->{'to_file'})},4156"blame") ." | ";4157}4158print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4159 file_name=>$diff->{'to_file'})},4160"history");4161print"</td>\n";41624163}# we should not encounter Unmerged (U) or Unknown (X) status4164print"</tr>\n";4165}4166print"</tbody>"if$has_header;4167print"</table>\n";4168}41694170sub git_patchset_body {4171my($fd,$difftree,$hash,@hash_parents) =@_;4172my($hash_parent) =$hash_parents[0];41734174my$is_combined= (@hash_parents>1);4175my$patch_idx=0;4176my$patch_number=0;4177my$patch_line;4178my$diffinfo;4179my$to_name;4180my(%from,%to);41814182print"<div class=\"patchset\">\n";41834184# skip to first patch4185while($patch_line= <$fd>) {4186chomp$patch_line;41874188last if($patch_line=~m/^diff /);4189}41904191 PATCH:4192while($patch_line) {41934194# parse "git diff" header line4195if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {4196# $1 is from_name, which we do not use4197$to_name= unquote($2);4198$to_name=~s!^b/!!;4199}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {4200# $1 is 'cc' or 'combined', which we do not use4201$to_name= unquote($2);4202}else{4203$to_name=undef;4204}42054206# check if current patch belong to current raw line4207# and parse raw git-diff line if needed4208if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {4209# this is continuation of a split patch4210print"<div class=\"patch cont\">\n";4211}else{4212# advance raw git-diff output if needed4213$patch_idx++ifdefined$diffinfo;42144215# read and prepare patch information4216$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);42174218# compact combined diff output can have some patches skipped4219# find which patch (using pathname of result) we are at now;4220if($is_combined) {4221while($to_namene$diffinfo->{'to_file'}) {4222print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4223 format_diff_cc_simplified($diffinfo,@hash_parents) .4224"</div>\n";# class="patch"42254226$patch_idx++;4227$patch_number++;42284229last if$patch_idx>$#$difftree;4230$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);4231}4232}42334234# modifies %from, %to hashes4235 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);42364237# this is first patch for raw difftree line with $patch_idx index4238# we index @$difftree array from 0, but number patches from 14239print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";4240}42414242# git diff header4243#assert($patch_line =~ m/^diff /) if DEBUG;4244#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed4245$patch_number++;4246# print "git diff" header4247print format_git_diff_header_line($patch_line,$diffinfo,4248 \%from, \%to);42494250# print extended diff header4251print"<div class=\"diff extended_header\">\n";4252 EXTENDED_HEADER:4253while($patch_line= <$fd>) {4254chomp$patch_line;42554256last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);42574258print format_extended_diff_header_line($patch_line,$diffinfo,4259 \%from, \%to);4260}4261print"</div>\n";# class="diff extended_header"42624263# from-file/to-file diff header4264if(!$patch_line) {4265print"</div>\n";# class="patch"4266last PATCH;4267}4268next PATCH if($patch_line=~m/^diff /);4269#assert($patch_line =~ m/^---/) if DEBUG;42704271my$last_patch_line=$patch_line;4272$patch_line= <$fd>;4273chomp$patch_line;4274#assert($patch_line =~ m/^\+\+\+/) if DEBUG;42754276print format_diff_from_to_header($last_patch_line,$patch_line,4277$diffinfo, \%from, \%to,4278@hash_parents);42794280# the patch itself4281 LINE:4282while($patch_line= <$fd>) {4283chomp$patch_line;42844285next PATCH if($patch_line=~m/^diff /);42864287print format_diff_line($patch_line, \%from, \%to);4288}42894290}continue{4291print"</div>\n";# class="patch"4292}42934294# for compact combined (--cc) format, with chunk and patch simpliciaction4295# patchset might be empty, but there might be unprocessed raw lines4296for(++$patch_idxif$patch_number>0;4297$patch_idx<@$difftree;4298++$patch_idx) {4299# read and prepare patch information4300$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);43014302# generate anchor for "patch" links in difftree / whatchanged part4303print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4304 format_diff_cc_simplified($diffinfo,@hash_parents) .4305"</div>\n";# class="patch"43064307$patch_number++;4308}43094310if($patch_number==0) {4311if(@hash_parents>1) {4312print"<div class=\"diff nodifferences\">Trivial merge</div>\n";4313}else{4314print"<div class=\"diff nodifferences\">No differences found</div>\n";4315}4316}43174318print"</div>\n";# class="patchset"4319}43204321# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43224323# fills project list info (age, description, owner, forks) for each4324# project in the list, removing invalid projects from returned list4325# NOTE: modifies $projlist, but does not remove entries from it4326sub fill_project_list_info {4327my($projlist,$check_forks) =@_;4328my@projects;43294330my$show_ctags= gitweb_check_feature('ctags');4331 PROJECT:4332foreachmy$pr(@$projlist) {4333my(@activity) = git_get_last_activity($pr->{'path'});4334unless(@activity) {4335next PROJECT;4336}4337($pr->{'age'},$pr->{'age_string'}) =@activity;4338if(!defined$pr->{'descr'}) {4339my$descr= git_get_project_description($pr->{'path'}) ||"";4340$descr= to_utf8($descr);4341$pr->{'descr_long'} =$descr;4342$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4343}4344if(!defined$pr->{'owner'}) {4345$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4346}4347if($check_forks) {4348my$pname=$pr->{'path'};4349if(($pname=~s/\.git$//) &&4350($pname!~/\/$/) &&4351(-d "$projectroot/$pname")) {4352$pr->{'forks'} ="-d$projectroot/$pname";4353}else{4354$pr->{'forks'} =0;4355}4356}4357$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4358push@projects,$pr;4359}43604361return@projects;4362}43634364# print 'sort by' <th> element, generating 'sort by $name' replay link4365# if that order is not selected4366sub print_sort_th {4367print format_sort_th(@_);4368}43694370sub format_sort_th {4371my($name,$order,$header) =@_;4372my$sort_th="";4373$header||=ucfirst($name);43744375if($ordereq$name) {4376$sort_th.="<th>$header</th>\n";4377}else{4378$sort_th.="<th>".4379$cgi->a({-href => href(-replay=>1, order=>$name),4380-class=>"header"},$header) .4381"</th>\n";4382}43834384return$sort_th;4385}43864387sub git_project_list_body {4388# actually uses global variable $project4389my($projlist,$order,$from,$to,$extra,$no_header) =@_;43904391my$check_forks= gitweb_check_feature('forks');4392my@projects= fill_project_list_info($projlist,$check_forks);43934394$order||=$default_projects_order;4395$from=0unlessdefined$from;4396$to=$#projectsif(!defined$to||$#projects<$to);43974398my%order_info= (4399 project => { key =>'path', type =>'str'},4400 descr => { key =>'descr_long', type =>'str'},4401 owner => { key =>'owner', type =>'str'},4402 age => { key =>'age', type =>'num'}4403);4404my$oi=$order_info{$order};4405if($oi->{'type'}eq'str') {4406@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4407}else{4408@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4409}44104411my$show_ctags= gitweb_check_feature('ctags');4412if($show_ctags) {4413my%ctags;4414foreachmy$p(@projects) {4415foreachmy$ct(keys%{$p->{'ctags'}}) {4416$ctags{$ct} +=$p->{'ctags'}->{$ct};4417}4418}4419my$cloud= git_populate_project_tagcloud(\%ctags);4420print git_show_project_tagcloud($cloud,64);4421}44224423print"<table class=\"project_list\">\n";4424unless($no_header) {4425print"<tr>\n";4426if($check_forks) {4427print"<th></th>\n";4428}4429 print_sort_th('project',$order,'Project');4430 print_sort_th('descr',$order,'Description');4431 print_sort_th('owner',$order,'Owner');4432 print_sort_th('age',$order,'Last Change');4433print"<th></th>\n".# for links4434"</tr>\n";4435}4436my$alternate=1;4437my$tagfilter=$cgi->param('by_tag');4438for(my$i=$from;$i<=$to;$i++) {4439my$pr=$projects[$i];44404441next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4442next if$searchtextand not$pr->{'path'} =~/$searchtext/4443and not$pr->{'descr_long'} =~/$searchtext/;4444# Weed out forks or non-matching entries of search4445if($check_forks) {4446my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4447$forkbase="^$forkbase"if$forkbase;4448next ifnot$searchtextand not$tagfilterand$show_ctags4449and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4450}44514452if($alternate) {4453print"<tr class=\"dark\">\n";4454}else{4455print"<tr class=\"light\">\n";4456}4457$alternate^=1;4458if($check_forks) {4459print"<td>";4460if($pr->{'forks'}) {4461print"<!--$pr->{'forks'} -->\n";4462print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4463}4464print"</td>\n";4465}4466print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4467-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4468"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4469-class=>"list", -title =>$pr->{'descr_long'}},4470 esc_html($pr->{'descr'})) ."</td>\n".4471"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4472print"<td class=\"". age_class($pr->{'age'}) ."\">".4473(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4474"<td class=\"link\">".4475$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4476$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4477$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4478$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4479($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4480"</td>\n".4481"</tr>\n";4482}4483if(defined$extra) {4484print"<tr>\n";4485if($check_forks) {4486print"<td></td>\n";4487}4488print"<td colspan=\"5\">$extra</td>\n".4489"</tr>\n";4490}4491print"</table>\n";4492}44934494sub git_log_body {4495# uses global variable $project4496my($commitlist,$from,$to,$refs,$extra) =@_;44974498$from=0unlessdefined$from;4499$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);45004501for(my$i=0;$i<=$to;$i++) {4502my%co= %{$commitlist->[$i]};4503next if!%co;4504my$commit=$co{'id'};4505my$ref= format_ref_marker($refs,$commit);4506my%ad= parse_date($co{'author_epoch'});4507 git_print_header_div('commit',4508"<span class=\"age\">$co{'age_string'}</span>".4509 esc_html($co{'title'}) .$ref,4510$commit);4511print"<div class=\"title_text\">\n".4512"<div class=\"log_link\">\n".4513$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .4514" | ".4515$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .4516" | ".4517$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .4518"<br/>\n".4519"</div>\n";4520 git_print_authorship(\%co, -tag =>'span');4521print"<br/>\n</div>\n";45224523print"<div class=\"log_body\">\n";4524 git_print_log($co{'comment'}, -final_empty_line=>1);4525print"</div>\n";4526}4527if($extra) {4528print"<div class=\"page_nav\">\n";4529print"$extra\n";4530print"</div>\n";4531}4532}45334534sub git_shortlog_body {4535# uses global variable $project4536my($commitlist,$from,$to,$refs,$extra) =@_;45374538$from=0unlessdefined$from;4539$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);45404541print"<table class=\"shortlog\">\n";4542my$alternate=1;4543for(my$i=$from;$i<=$to;$i++) {4544my%co= %{$commitlist->[$i]};4545my$commit=$co{'id'};4546my$ref= format_ref_marker($refs,$commit);4547if($alternate) {4548print"<tr class=\"dark\">\n";4549}else{4550print"<tr class=\"light\">\n";4551}4552$alternate^=1;4553# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4554print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4555 format_author_html('td', \%co,10) ."<td>";4556print format_subject_html($co{'title'},$co{'title_short'},4557 href(action=>"commit", hash=>$commit),$ref);4558print"</td>\n".4559"<td class=\"link\">".4560$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4561$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4562$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4563my$snapshot_links= format_snapshot_links($commit);4564if(defined$snapshot_links) {4565print" | ".$snapshot_links;4566}4567print"</td>\n".4568"</tr>\n";4569}4570if(defined$extra) {4571print"<tr>\n".4572"<td colspan=\"4\">$extra</td>\n".4573"</tr>\n";4574}4575print"</table>\n";4576}45774578sub git_history_body {4579# Warning: assumes constant type (blob or tree) during history4580my($commitlist,$from,$to,$refs,$extra,4581$file_name,$file_hash,$ftype) =@_;45824583$from=0unlessdefined$from;4584$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});45854586print"<table class=\"history\">\n";4587my$alternate=1;4588for(my$i=$from;$i<=$to;$i++) {4589my%co= %{$commitlist->[$i]};4590if(!%co) {4591next;4592}4593my$commit=$co{'id'};45944595my$ref= format_ref_marker($refs,$commit);45964597if($alternate) {4598print"<tr class=\"dark\">\n";4599}else{4600print"<tr class=\"light\">\n";4601}4602$alternate^=1;4603print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4604# shortlog: format_author_html('td', \%co, 10)4605 format_author_html('td', \%co,15,3) ."<td>";4606# originally git_history used chop_str($co{'title'}, 50)4607print format_subject_html($co{'title'},$co{'title_short'},4608 href(action=>"commit", hash=>$commit),$ref);4609print"</td>\n".4610"<td class=\"link\">".4611$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4612$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");46134614if($ftypeeq'blob') {4615my$blob_current=$file_hash;4616my$blob_parent= git_get_hash_by_path($commit,$file_name);4617if(defined$blob_current&&defined$blob_parent&&4618$blob_currentne$blob_parent) {4619print" | ".4620$cgi->a({-href => href(action=>"blobdiff",4621 hash=>$blob_current, hash_parent=>$blob_parent,4622 hash_base=>$hash_base, hash_parent_base=>$commit,4623 file_name=>$file_name)},4624"diff to current");4625}4626}4627print"</td>\n".4628"</tr>\n";4629}4630if(defined$extra) {4631print"<tr>\n".4632"<td colspan=\"4\">$extra</td>\n".4633"</tr>\n";4634}4635print"</table>\n";4636}46374638sub git_tags_body {4639# uses global variable $project4640my($taglist,$from,$to,$extra) =@_;4641$from=0unlessdefined$from;4642$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);46434644print"<table class=\"tags\">\n";4645my$alternate=1;4646for(my$i=$from;$i<=$to;$i++) {4647my$entry=$taglist->[$i];4648my%tag=%$entry;4649my$comment=$tag{'subject'};4650my$comment_short;4651if(defined$comment) {4652$comment_short= chop_str($comment,30,5);4653}4654if($alternate) {4655print"<tr class=\"dark\">\n";4656}else{4657print"<tr class=\"light\">\n";4658}4659$alternate^=1;4660if(defined$tag{'age'}) {4661print"<td><i>$tag{'age'}</i></td>\n";4662}else{4663print"<td></td>\n";4664}4665print"<td>".4666$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4667-class=>"list name"}, esc_html($tag{'name'})) .4668"</td>\n".4669"<td>";4670if(defined$comment) {4671print format_subject_html($comment,$comment_short,4672 href(action=>"tag", hash=>$tag{'id'}));4673}4674print"</td>\n".4675"<td class=\"selflink\">";4676if($tag{'type'}eq"tag") {4677print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4678}else{4679print" ";4680}4681print"</td>\n".4682"<td class=\"link\">"." | ".4683$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4684if($tag{'reftype'}eq"commit") {4685print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4686" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4687}elsif($tag{'reftype'}eq"blob") {4688print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4689}4690print"</td>\n".4691"</tr>";4692}4693if(defined$extra) {4694print"<tr>\n".4695"<td colspan=\"5\">$extra</td>\n".4696"</tr>\n";4697}4698print"</table>\n";4699}47004701sub git_heads_body {4702# uses global variable $project4703my($headlist,$head,$from,$to,$extra) =@_;4704$from=0unlessdefined$from;4705$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);47064707print"<table class=\"heads\">\n";4708my$alternate=1;4709for(my$i=$from;$i<=$to;$i++) {4710my$entry=$headlist->[$i];4711my%ref=%$entry;4712my$curr=$ref{'id'}eq$head;4713if($alternate) {4714print"<tr class=\"dark\">\n";4715}else{4716print"<tr class=\"light\">\n";4717}4718$alternate^=1;4719print"<td><i>$ref{'age'}</i></td>\n".4720($curr?"<td class=\"current_head\">":"<td>") .4721$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4722-class=>"list name"},esc_html($ref{'name'})) .4723"</td>\n".4724"<td class=\"link\">".4725$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4726$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4727$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4728"</td>\n".4729"</tr>";4730}4731if(defined$extra) {4732print"<tr>\n".4733"<td colspan=\"3\">$extra</td>\n".4734"</tr>\n";4735}4736print"</table>\n";4737}47384739sub git_search_grep_body {4740my($commitlist,$from,$to,$extra) =@_;4741$from=0unlessdefined$from;4742$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);47434744print"<table class=\"commit_search\">\n";4745my$alternate=1;4746for(my$i=$from;$i<=$to;$i++) {4747my%co= %{$commitlist->[$i]};4748if(!%co) {4749next;4750}4751my$commit=$co{'id'};4752if($alternate) {4753print"<tr class=\"dark\">\n";4754}else{4755print"<tr class=\"light\">\n";4756}4757$alternate^=1;4758print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4759 format_author_html('td', \%co,15,5) .4760"<td>".4761$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4762-class=>"list subject"},4763 chop_and_escape_str($co{'title'},50) ."<br/>");4764my$comment=$co{'comment'};4765foreachmy$line(@$comment) {4766if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4767my($lead,$match,$trail) = ($1,$2,$3);4768$match= chop_str($match,70,5,'center');4769my$contextlen=int((80-length($match))/2);4770$contextlen=30if($contextlen>30);4771$lead= chop_str($lead,$contextlen,10,'left');4772$trail= chop_str($trail,$contextlen,10,'right');47734774$lead= esc_html($lead);4775$match= esc_html($match);4776$trail= esc_html($trail);47774778print"$lead<span class=\"match\">$match</span>$trail<br />";4779}4780}4781print"</td>\n".4782"<td class=\"link\">".4783$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4784" | ".4785$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4786" | ".4787$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4788print"</td>\n".4789"</tr>\n";4790}4791if(defined$extra) {4792print"<tr>\n".4793"<td colspan=\"3\">$extra</td>\n".4794"</tr>\n";4795}4796print"</table>\n";4797}47984799## ======================================================================4800## ======================================================================4801## actions48024803sub git_project_list {4804my$order=$input_params{'order'};4805if(defined$order&&$order!~m/none|project|descr|owner|age/) {4806 die_error(400,"Unknown order parameter");4807}48084809my@list= git_get_projects_list();4810if(!@list) {4811 die_error(404,"No projects found");4812}48134814 git_header_html();4815if(defined$home_text&& -f $home_text) {4816print"<div class=\"index_include\">\n";4817 insert_file($home_text);4818print"</div>\n";4819}4820print$cgi->startform(-method=>"get") .4821"<p class=\"projsearch\">Search:\n".4822$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4823"</p>".4824$cgi->end_form() ."\n";4825 git_project_list_body(\@list,$order);4826 git_footer_html();4827}48284829sub git_forks {4830my$order=$input_params{'order'};4831if(defined$order&&$order!~m/none|project|descr|owner|age/) {4832 die_error(400,"Unknown order parameter");4833}48344835my@list= git_get_projects_list($project);4836if(!@list) {4837 die_error(404,"No forks found");4838}48394840 git_header_html();4841 git_print_page_nav('','');4842 git_print_header_div('summary',"$projectforks");4843 git_project_list_body(\@list,$order);4844 git_footer_html();4845}48464847sub git_project_index {4848my@projects= git_get_projects_list($project);48494850print$cgi->header(4851-type =>'text/plain',4852-charset =>'utf-8',4853-content_disposition =>'inline; filename="index.aux"');48544855foreachmy$pr(@projects) {4856if(!exists$pr->{'owner'}) {4857$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4858}48594860my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4861# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4862$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4863$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4864$path=~s/ /\+/g;4865$owner=~s/ /\+/g;48664867print"$path$owner\n";4868}4869}48704871sub git_summary {4872my$descr= git_get_project_description($project) ||"none";4873my%co= parse_commit("HEAD");4874my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4875my$head=$co{'id'};48764877my$owner= git_get_project_owner($project);48784879my$refs= git_get_references();4880# These get_*_list functions return one more to allow us to see if4881# there are more ...4882my@taglist= git_get_tags_list(16);4883my@headlist= git_get_heads_list(16);4884my@forklist;4885my$check_forks= gitweb_check_feature('forks');48864887if($check_forks) {4888@forklist= git_get_projects_list($project);4889}48904891 git_header_html();4892 git_print_page_nav('summary','',$head);48934894print"<div class=\"title\"> </div>\n";4895print"<table class=\"projects_list\">\n".4896"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4897"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4898if(defined$cd{'rfc2822'}) {4899print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4900}49014902# use per project git URL list in $projectroot/$project/cloneurl4903# or make project git URL from git base URL and project name4904my$url_tag="URL";4905my@url_list= git_get_project_url_list($project);4906@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4907foreachmy$git_url(@url_list) {4908next unless$git_url;4909print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4910$url_tag="";4911}49124913# Tag cloud4914my$show_ctags= gitweb_check_feature('ctags');4915if($show_ctags) {4916my$ctags= git_get_project_ctags($project);4917my$cloud= git_populate_project_tagcloud($ctags);4918print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4919print"</td>\n<td>"unless%$ctags;4920print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4921print"</td>\n<td>"if%$ctags;4922print git_show_project_tagcloud($cloud,48);4923print"</td></tr>";4924}49254926print"</table>\n";49274928# If XSS prevention is on, we don't include README.html.4929# TODO: Allow a readme in some safe format.4930if(!$prevent_xss&& -s "$projectroot/$project/README.html") {4931print"<div class=\"title\">readme</div>\n".4932"<div class=\"readme\">\n";4933 insert_file("$projectroot/$project/README.html");4934print"\n</div>\n";# class="readme"4935}49364937# we need to request one more than 16 (0..15) to check if4938# those 16 are all4939my@commitlist=$head? parse_commits($head,17) : ();4940if(@commitlist) {4941 git_print_header_div('shortlog');4942 git_shortlog_body(\@commitlist,0,15,$refs,4943$#commitlist<=15?undef:4944$cgi->a({-href => href(action=>"shortlog")},"..."));4945}49464947if(@taglist) {4948 git_print_header_div('tags');4949 git_tags_body(\@taglist,0,15,4950$#taglist<=15?undef:4951$cgi->a({-href => href(action=>"tags")},"..."));4952}49534954if(@headlist) {4955 git_print_header_div('heads');4956 git_heads_body(\@headlist,$head,0,15,4957$#headlist<=15?undef:4958$cgi->a({-href => href(action=>"heads")},"..."));4959}49604961if(@forklist) {4962 git_print_header_div('forks');4963 git_project_list_body(\@forklist,'age',0,15,4964$#forklist<=15?undef:4965$cgi->a({-href => href(action=>"forks")},"..."),4966'no_header');4967}49684969 git_footer_html();4970}49714972sub git_tag {4973my$head= git_get_head_hash($project);4974 git_header_html();4975 git_print_page_nav('','',$head,undef,$head);4976my%tag= parse_tag($hash);49774978if(!%tag) {4979 die_error(404,"Unknown tag object");4980}49814982 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4983print"<div class=\"title_text\">\n".4984"<table class=\"object_header\">\n".4985"<tr>\n".4986"<td>object</td>\n".4987"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4988$tag{'object'}) ."</td>\n".4989"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4990$tag{'type'}) ."</td>\n".4991"</tr>\n";4992if(defined($tag{'author'})) {4993 git_print_authorship_rows(\%tag,'author');4994}4995print"</table>\n\n".4996"</div>\n";4997print"<div class=\"page_body\">";4998my$comment=$tag{'comment'};4999foreachmy$line(@$comment) {5000chomp$line;5001print esc_html($line, -nbsp=>1) ."<br/>\n";5002}5003print"</div>\n";5004 git_footer_html();5005}50065007sub git_blame_common {5008my$format=shift||'porcelain';5009if($formateq'porcelain'&&$cgi->param('js')) {5010$format='incremental';5011$action='blame_incremental';# for page title etc5012}50135014# permissions5015 gitweb_check_feature('blame')5016or die_error(403,"Blame view not allowed");50175018# error checking5019 die_error(400,"No file name given")unless$file_name;5020$hash_base||= git_get_head_hash($project);5021 die_error(404,"Couldn't find base commit")unless$hash_base;5022my%co= parse_commit($hash_base)5023or die_error(404,"Commit not found");5024my$ftype="blob";5025if(!defined$hash) {5026$hash= git_get_hash_by_path($hash_base,$file_name,"blob")5027or die_error(404,"Error looking up file");5028}else{5029$ftype= git_get_type($hash);5030if($ftype!~"blob") {5031 die_error(400,"Object is not a blob");5032}5033}50345035my$fd;5036if($formateq'incremental') {5037# get file contents (as base)5038open$fd,"-|", git_cmd(),'cat-file','blob',$hash5039or die_error(500,"Open git-cat-file failed");5040}elsif($formateq'data') {5041# run git-blame --incremental5042open$fd,"-|", git_cmd(),"blame","--incremental",5043$hash_base,"--",$file_name5044or die_error(500,"Open git-blame --incremental failed");5045}else{5046# run git-blame --porcelain5047open$fd,"-|", git_cmd(),"blame",'-p',5048$hash_base,'--',$file_name5049or die_error(500,"Open git-blame --porcelain failed");5050}50515052# incremental blame data returns early5053if($formateq'data') {5054print$cgi->header(5055-type=>"text/plain", -charset =>"utf-8",5056-status=>"200 OK");5057local$| =1;# output autoflush5058printwhile<$fd>;5059close$fd5060or print"ERROR$!\n";50615062print'END';5063if(defined$t0&& gitweb_check_feature('timed')) {5064print' '.5065 Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).5066' '.$number_of_git_cmds;5067}5068print"\n";50695070return;5071}50725073# page header5074 git_header_html();5075my$formats_nav=5076$cgi->a({-href => href(action=>"blob", -replay=>1)},5077"blob") .5078" | ";5079if($formateq'incremental') {5080$formats_nav.=5081$cgi->a({-href => href(action=>"blame", javascript=>0, -replay=>1)},5082"blame") ." (non-incremental)";5083}else{5084$formats_nav.=5085$cgi->a({-href => href(action=>"blame_incremental", -replay=>1)},5086"blame") ." (incremental)";5087}5088$formats_nav.=5089" | ".5090$cgi->a({-href => href(action=>"history", -replay=>1)},5091"history") .5092" | ".5093$cgi->a({-href => href(action=>$action, file_name=>$file_name)},5094"HEAD");5095 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5096 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5097 git_print_page_path($file_name,$ftype,$hash_base);50985099# page body5100if($formateq'incremental') {5101print"<noscript>\n<div class=\"error\"><center><b>\n".5102"This page requires JavaScript to run.\nUse ".5103$cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},5104'this page').5105" instead.\n".5106"</b></center></div>\n</noscript>\n";51075108print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!;5109}51105111print qq!<div class="page_body">\n!;5112print qq!<div id="progress_info">.../ ...</div>\n!5113if($formateq'incremental');5114print qq!<table id="blame_table"class="blame" width="100%">\n!.5115#qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.5116 qq!<thead>\n!.5117 qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!.5118 qq!</thead>\n!.5119 qq!<tbody>\n!;51205121my@rev_color=qw(light dark);5122my$num_colors=scalar(@rev_color);5123my$current_color=0;51245125if($formateq'incremental') {5126my$color_class=$rev_color[$current_color];51275128#contents of a file5129my$linenr=0;5130 LINE:5131while(my$line= <$fd>) {5132chomp$line;5133$linenr++;51345135print qq!<tr id="l$linenr"class="$color_class">!.5136 qq!<td class="sha1"><a href=""> </a></td>!.5137 qq!<td class="linenr">!.5138 qq!<a class="linenr" href="">$linenr</a></td>!;5139print qq!<td class="pre">! . esc_html($line) ."</td>\n";5140print qq!</tr>\n!;5141}51425143}else{# porcelain, i.e. ordinary blame5144my%metainfo= ();# saves information about commits51455146# blame data5147 LINE:5148while(my$line= <$fd>) {5149chomp$line;5150# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]5151# no <lines in group> for subsequent lines in group of lines5152my($full_rev,$orig_lineno,$lineno,$group_size) =5153($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);5154if(!exists$metainfo{$full_rev}) {5155$metainfo{$full_rev} = {'nprevious'=>0};5156}5157my$meta=$metainfo{$full_rev};5158my$data;5159while($data= <$fd>) {5160chomp$data;5161last if($data=~s/^\t//);# contents of line5162if($data=~/^(\S+)(?: (.*))?$/) {5163$meta->{$1} =$2unlessexists$meta->{$1};5164}5165if($data=~/^previous /) {5166$meta->{'nprevious'}++;5167}5168}5169my$short_rev=substr($full_rev,0,8);5170my$author=$meta->{'author'};5171my%date=5172 parse_date($meta->{'author-time'},$meta->{'author-tz'});5173my$date=$date{'iso-tz'};5174if($group_size) {5175$current_color= ($current_color+1) %$num_colors;5176}5177my$tr_class=$rev_color[$current_color];5178$tr_class.=' boundary'if(exists$meta->{'boundary'});5179$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);5180$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);5181print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";5182if($group_size) {5183print"<td class=\"sha1\"";5184print" title=\"". esc_html($author) .",$date\"";5185print" rowspan=\"$group_size\""if($group_size>1);5186print">";5187print$cgi->a({-href => href(action=>"commit",5188 hash=>$full_rev,5189 file_name=>$file_name)},5190 esc_html($short_rev));5191if($group_size>=2) {5192my@author_initials= ($author=~/\b([[:upper:]])\B/g);5193if(@author_initials) {5194print"<br />".5195 esc_html(join('',@author_initials));5196# or join('.', ...)5197}5198}5199print"</td>\n";5200}5201# 'previous' <sha1 of parent commit> <filename at commit>5202if(exists$meta->{'previous'} &&5203$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {5204$meta->{'parent'} =$1;5205$meta->{'file_parent'} = unquote($2);5206}5207my$linenr_commit=5208exists($meta->{'parent'}) ?5209$meta->{'parent'} :$full_rev;5210my$linenr_filename=5211exists($meta->{'file_parent'}) ?5212$meta->{'file_parent'} : unquote($meta->{'filename'});5213my$blamed= href(action =>'blame',5214 file_name =>$linenr_filename,5215 hash_base =>$linenr_commit);5216print"<td class=\"linenr\">";5217print$cgi->a({ -href =>"$blamed#l$orig_lineno",5218-class=>"linenr"},5219 esc_html($lineno));5220print"</td>";5221print"<td class=\"pre\">". esc_html($data) ."</td>\n";5222print"</tr>\n";5223}# end while52245225}52265227# footer5228print"</tbody>\n".5229"</table>\n";# class="blame"5230print"</div>\n";# class="blame_body"5231close$fd5232or print"Reading blob failed\n";52335234 git_footer_html();5235}52365237sub git_blame {5238 git_blame_common();5239}52405241sub git_blame_incremental {5242 git_blame_common('incremental');5243}52445245sub git_blame_data {5246 git_blame_common('data');5247}52485249sub git_tags {5250my$head= git_get_head_hash($project);5251 git_header_html();5252 git_print_page_nav('','',$head,undef,$head);5253 git_print_header_div('summary',$project);52545255my@tagslist= git_get_tags_list();5256if(@tagslist) {5257 git_tags_body(\@tagslist);5258}5259 git_footer_html();5260}52615262sub git_heads {5263my$head= git_get_head_hash($project);5264 git_header_html();5265 git_print_page_nav('','',$head,undef,$head);5266 git_print_header_div('summary',$project);52675268my@headslist= git_get_heads_list();5269if(@headslist) {5270 git_heads_body(\@headslist,$head);5271}5272 git_footer_html();5273}52745275sub git_blob_plain {5276my$type=shift;5277my$expires;52785279if(!defined$hash) {5280if(defined$file_name) {5281my$base=$hash_base|| git_get_head_hash($project);5282$hash= git_get_hash_by_path($base,$file_name,"blob")5283or die_error(404,"Cannot find file");5284}else{5285 die_error(400,"No file name defined");5286}5287}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5288# blobs defined by non-textual hash id's can be cached5289$expires="+1d";5290}52915292open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5293or die_error(500,"Open git-cat-file blob '$hash' failed");52945295# content-type (can include charset)5296$type= blob_contenttype($fd,$file_name,$type);52975298# "save as" filename, even when no $file_name is given5299my$save_as="$hash";5300if(defined$file_name) {5301$save_as=$file_name;5302}elsif($type=~m/^text\//) {5303$save_as.='.txt';5304}53055306# With XSS prevention on, blobs of all types except a few known safe5307# ones are served with "Content-Disposition: attachment" to make sure5308# they don't run in our security domain. For certain image types,5309# blob view writes an <img> tag referring to blob_plain view, and we5310# want to be sure not to break that by serving the image as an5311# attachment (though Firefox 3 doesn't seem to care).5312my$sandbox=$prevent_xss&&5313$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;53145315print$cgi->header(5316-type =>$type,5317-expires =>$expires,5318-content_disposition =>5319($sandbox?'attachment':'inline')5320.'; filename="'.$save_as.'"');5321local$/=undef;5322binmode STDOUT,':raw';5323print<$fd>;5324binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5325close$fd;5326}53275328sub git_blob {5329my$expires;53305331if(!defined$hash) {5332if(defined$file_name) {5333my$base=$hash_base|| git_get_head_hash($project);5334$hash= git_get_hash_by_path($base,$file_name,"blob")5335or die_error(404,"Cannot find file");5336}else{5337 die_error(400,"No file name defined");5338}5339}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5340# blobs defined by non-textual hash id's can be cached5341$expires="+1d";5342}53435344my$have_blame= gitweb_check_feature('blame');5345open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5346or die_error(500,"Couldn't cat$file_name,$hash");5347my$mimetype= blob_mimetype($fd,$file_name);5348if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {5349close$fd;5350return git_blob_plain($mimetype);5351}5352# we can have blame only for text/* mimetype5353$have_blame&&= ($mimetype=~m!^text/!);53545355 git_header_html(undef,$expires);5356my$formats_nav='';5357if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5358if(defined$file_name) {5359if($have_blame) {5360$formats_nav.=5361$cgi->a({-href => href(action=>"blame", -replay=>1)},5362"blame") .5363" | ";5364}5365$formats_nav.=5366$cgi->a({-href => href(action=>"history", -replay=>1)},5367"history") .5368" | ".5369$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5370"raw") .5371" | ".5372$cgi->a({-href => href(action=>"blob",5373 hash_base=>"HEAD", file_name=>$file_name)},5374"HEAD");5375}else{5376$formats_nav.=5377$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5378"raw");5379}5380 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5381 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5382}else{5383print"<div class=\"page_nav\">\n".5384"<br/><br/></div>\n".5385"<div class=\"title\">$hash</div>\n";5386}5387 git_print_page_path($file_name,"blob",$hash_base);5388print"<div class=\"page_body\">\n";5389if($mimetype=~m!^image/!) {5390print qq!<img type="$mimetype"!;5391if($file_name) {5392print qq! alt="$file_name" title="$file_name"!;5393}5394print qq! src="! .5395 href(action=>"blob_plain", hash=>$hash,5396 hash_base=>$hash_base, file_name=>$file_name) .5397 qq!"/>\n!;5398}else{5399my$nr;5400while(my$line= <$fd>) {5401chomp$line;5402$nr++;5403$line= untabify($line);5404printf"<div class=\"pre\"><a id=\"l%i\"href=\"". href(-replay =>1)5405."#l%i\"class=\"linenr\">%4i</a>%s</div>\n",5406$nr,$nr,$nr, esc_html($line, -nbsp=>1);5407}5408}5409close$fd5410or print"Reading blob failed.\n";5411print"</div>";5412 git_footer_html();5413}54145415sub git_tree {5416if(!defined$hash_base) {5417$hash_base="HEAD";5418}5419if(!defined$hash) {5420if(defined$file_name) {5421$hash= git_get_hash_by_path($hash_base,$file_name,"tree");5422}else{5423$hash=$hash_base;5424}5425}5426 die_error(404,"No such tree")unlessdefined($hash);54275428my$show_sizes= gitweb_check_feature('show-sizes');5429my$have_blame= gitweb_check_feature('blame');54305431my@entries= ();5432{5433local$/="\0";5434open my$fd,"-|", git_cmd(),"ls-tree",'-z',5435($show_sizes?'-l': ()),@extra_options,$hash5436or die_error(500,"Open git-ls-tree failed");5437@entries=map{chomp;$_} <$fd>;5438close$fd5439or die_error(404,"Reading tree failed");5440}54415442my$refs= git_get_references();5443my$ref= format_ref_marker($refs,$hash_base);5444 git_header_html();5445my$basedir='';5446if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5447my@views_nav= ();5448if(defined$file_name) {5449push@views_nav,5450$cgi->a({-href => href(action=>"history", -replay=>1)},5451"history"),5452$cgi->a({-href => href(action=>"tree",5453 hash_base=>"HEAD", file_name=>$file_name)},5454"HEAD"),5455}5456my$snapshot_links= format_snapshot_links($hash);5457if(defined$snapshot_links) {5458# FIXME: Should be available when we have no hash base as well.5459push@views_nav,$snapshot_links;5460}5461 git_print_page_nav('tree','',$hash_base,undef,undef,5462join(' | ',@views_nav));5463 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);5464}else{5465undef$hash_base;5466print"<div class=\"page_nav\">\n";5467print"<br/><br/></div>\n";5468print"<div class=\"title\">$hash</div>\n";5469}5470if(defined$file_name) {5471$basedir=$file_name;5472if($basedirne''&&substr($basedir, -1)ne'/') {5473$basedir.='/';5474}5475 git_print_page_path($file_name,'tree',$hash_base);5476}5477print"<div class=\"page_body\">\n";5478print"<table class=\"tree\">\n";5479my$alternate=1;5480# '..' (top directory) link if possible5481if(defined$hash_base&&5482defined$file_name&&$file_name=~m![^/]+$!) {5483if($alternate) {5484print"<tr class=\"dark\">\n";5485}else{5486print"<tr class=\"light\">\n";5487}5488$alternate^=1;54895490my$up=$file_name;5491$up=~s!/?[^/]+$!!;5492undef$upunless$up;5493# based on git_print_tree_entry5494print'<td class="mode">'. mode_str('040000') ."</td>\n";5495print'<td class="size"> </td>'."\n"if$show_sizes;5496print'<td class="list">';5497print$cgi->a({-href => href(action=>"tree",5498 hash_base=>$hash_base,5499 file_name=>$up)},5500"..");5501print"</td>\n";5502print"<td class=\"link\"></td>\n";55035504print"</tr>\n";5505}5506foreachmy$line(@entries) {5507my%t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);55085509if($alternate) {5510print"<tr class=\"dark\">\n";5511}else{5512print"<tr class=\"light\">\n";5513}5514$alternate^=1;55155516 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);55175518print"</tr>\n";5519}5520print"</table>\n".5521"</div>";5522 git_footer_html();5523}55245525sub snapshot_name {5526my($project,$hash) =@_;55275528# path/to/project.git -> project5529# path/to/project/.git -> project5530my$name= to_utf8($project);5531$name=~ s,([^/])/*\.git$,$1,;5532$name= basename($name);5533# sanitize name5534$name=~s/[[:cntrl:]]/?/g;55355536my$ver=$hash;5537if($hash=~/^[0-9a-fA-F]+$/) {5538# shorten SHA-1 hash5539my$full_hash= git_get_full_hash($project,$hash);5540if($full_hash=~/^$hash/&&length($hash) >7) {5541$ver= git_get_short_hash($project,$hash);5542}5543}elsif($hash=~m!^refs/tags/(.*)$!) {5544# tags don't need shortened SHA-1 hash5545$ver=$1;5546}else{5547# branches and other need shortened SHA-1 hash5548if($hash=~m!^refs/(?:heads|remotes)/(.*)$!) {5549$ver=$1;5550}5551$ver.='-'. git_get_short_hash($project,$hash);5552}5553# in case of hierarchical branch names5554$ver=~s!/!.!g;55555556# name = project-version_string5557$name="$name-$ver";55585559returnwantarray? ($name,$name) :$name;5560}55615562sub git_snapshot {5563my$format=$input_params{'snapshot_format'};5564if(!@snapshot_fmts) {5565 die_error(403,"Snapshots not allowed");5566}5567# default to first supported snapshot format5568$format||=$snapshot_fmts[0];5569if($format!~m/^[a-z0-9]+$/) {5570 die_error(400,"Invalid snapshot format parameter");5571}elsif(!exists($known_snapshot_formats{$format})) {5572 die_error(400,"Unknown snapshot format");5573}elsif($known_snapshot_formats{$format}{'disabled'}) {5574 die_error(403,"Snapshot format not allowed");5575}elsif(!grep($_eq$format,@snapshot_fmts)) {5576 die_error(403,"Unsupported snapshot format");5577}55785579my$type= git_get_type("$hash^{}");5580if(!$type) {5581 die_error(404,'Object does not exist');5582}elsif($typeeq'blob') {5583 die_error(400,'Object is not a tree-ish');5584}55855586my($name,$prefix) = snapshot_name($project,$hash);5587my$filename="$name$known_snapshot_formats{$format}{'suffix'}";5588my$cmd= quote_command(5589 git_cmd(),'archive',5590"--format=$known_snapshot_formats{$format}{'format'}",5591"--prefix=$prefix/",$hash);5592if(exists$known_snapshot_formats{$format}{'compressor'}) {5593$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});5594}55955596$filename=~s/(["\\])/\\$1/g;5597print$cgi->header(5598-type =>$known_snapshot_formats{$format}{'type'},5599-content_disposition =>'inline; filename="'.$filename.'"',5600-status =>'200 OK');56015602open my$fd,"-|",$cmd5603or die_error(500,"Execute git-archive failed");5604binmode STDOUT,':raw';5605print<$fd>;5606binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5607close$fd;5608}56095610sub git_log_generic {5611my($fmt_name,$body_subr,$base,$parent,$file_name,$file_hash) =@_;56125613my$head= git_get_head_hash($project);5614if(!defined$base) {5615$base=$head;5616}5617if(!defined$page) {5618$page=0;5619}5620my$refs= git_get_references();56215622my$commit_hash=$base;5623if(defined$parent) {5624$commit_hash="$parent..$base";5625}5626my@commitlist=5627 parse_commits($commit_hash,101, (100*$page),5628defined$file_name? ($file_name,"--full-history") : ());56295630my$ftype;5631if(!defined$file_hash&&defined$file_name) {5632# some commits could have deleted file in question,5633# and not have it in tree, but one of them has to have it5634for(my$i=0;$i<@commitlist;$i++) {5635$file_hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5636last ifdefined$file_hash;5637}5638}5639if(defined$file_hash) {5640$ftype= git_get_type($file_hash);5641}5642if(defined$file_name&& !defined$ftype) {5643 die_error(500,"Unknown type of object");5644}5645my%co;5646if(defined$file_name) {5647%co= parse_commit($base)5648or die_error(404,"Unknown commit object");5649}565056515652my$paging_nav= format_paging_nav($fmt_name,$page,$#commitlist>=100);5653my$next_link='';5654if($#commitlist>=100) {5655$next_link=5656$cgi->a({-href => href(-replay=>1, page=>$page+1),5657-accesskey =>"n", -title =>"Alt-n"},"next");5658}5659my$patch_max= gitweb_get_feature('patches');5660if($patch_max&& !defined$file_name) {5661if($patch_max<0||@commitlist<=$patch_max) {5662$paging_nav.=" ⋅ ".5663$cgi->a({-href => href(action=>"patches", -replay=>1)},5664"patches");5665}5666}56675668 git_header_html();5669 git_print_page_nav($fmt_name,'',$hash,$hash,$hash,$paging_nav);5670if(defined$file_name) {5671 git_print_header_div('commit', esc_html($co{'title'}),$base);5672}else{5673 git_print_header_div('summary',$project)5674}5675 git_print_page_path($file_name,$ftype,$hash_base)5676if(defined$file_name);56775678$body_subr->(\@commitlist,0,99,$refs,$next_link,5679$file_name,$file_hash,$ftype);56805681 git_footer_html();5682}56835684sub git_log {5685 git_log_generic('log', \&git_log_body,5686$hash,$hash_parent);5687}56885689sub git_commit {5690$hash||=$hash_base||"HEAD";5691my%co= parse_commit($hash)5692or die_error(404,"Unknown commit object");56935694my$parent=$co{'parent'};5695my$parents=$co{'parents'};# listref56965697# we need to prepare $formats_nav before any parameter munging5698my$formats_nav;5699if(!defined$parent) {5700# --root commitdiff5701$formats_nav.='(initial)';5702}elsif(@$parents==1) {5703# single parent commit5704$formats_nav.=5705'(parent: '.5706$cgi->a({-href => href(action=>"commit",5707 hash=>$parent)},5708 esc_html(substr($parent,0,7))) .5709')';5710}else{5711# merge commit5712$formats_nav.=5713'(merge: '.5714join(' ',map{5715$cgi->a({-href => href(action=>"commit",5716 hash=>$_)},5717 esc_html(substr($_,0,7)));5718}@$parents) .5719')';5720}5721if(gitweb_check_feature('patches') &&@$parents<=1) {5722$formats_nav.=" | ".5723$cgi->a({-href => href(action=>"patch", -replay=>1)},5724"patch");5725}57265727if(!defined$parent) {5728$parent="--root";5729}5730my@difftree;5731open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5732@diff_opts,5733(@$parents<=1?$parent:'-c'),5734$hash,"--"5735or die_error(500,"Open git-diff-tree failed");5736@difftree=map{chomp;$_} <$fd>;5737close$fdor die_error(404,"Reading git-diff-tree failed");57385739# non-textual hash id's can be cached5740my$expires;5741if($hash=~m/^[0-9a-fA-F]{40}$/) {5742$expires="+1d";5743}5744my$refs= git_get_references();5745my$ref= format_ref_marker($refs,$co{'id'});57465747 git_header_html(undef,$expires);5748 git_print_page_nav('commit','',5749$hash,$co{'tree'},$hash,5750$formats_nav);57515752if(defined$co{'parent'}) {5753 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5754}else{5755 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5756}5757print"<div class=\"title_text\">\n".5758"<table class=\"object_header\">\n";5759 git_print_authorship_rows(\%co);5760print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";5761print"<tr>".5762"<td>tree</td>".5763"<td class=\"sha1\">".5764$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),5765class=>"list"},$co{'tree'}) .5766"</td>".5767"<td class=\"link\">".5768$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},5769"tree");5770my$snapshot_links= format_snapshot_links($hash);5771if(defined$snapshot_links) {5772print" | ".$snapshot_links;5773}5774print"</td>".5775"</tr>\n";57765777foreachmy$par(@$parents) {5778print"<tr>".5779"<td>parent</td>".5780"<td class=\"sha1\">".5781$cgi->a({-href => href(action=>"commit", hash=>$par),5782class=>"list"},$par) .5783"</td>".5784"<td class=\"link\">".5785$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .5786" | ".5787$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .5788"</td>".5789"</tr>\n";5790}5791print"</table>".5792"</div>\n";57935794print"<div class=\"page_body\">\n";5795 git_print_log($co{'comment'});5796print"</div>\n";57975798 git_difftree_body(\@difftree,$hash,@$parents);57995800 git_footer_html();5801}58025803sub git_object {5804# object is defined by:5805# - hash or hash_base alone5806# - hash_base and file_name5807my$type;58085809# - hash or hash_base alone5810if($hash|| ($hash_base&& !defined$file_name)) {5811my$object_id=$hash||$hash_base;58125813open my$fd,"-|", quote_command(5814 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'5815or die_error(404,"Object does not exist");5816$type= <$fd>;5817chomp$type;5818close$fd5819or die_error(404,"Object does not exist");58205821# - hash_base and file_name5822}elsif($hash_base&&defined$file_name) {5823$file_name=~ s,/+$,,;58245825system(git_cmd(),"cat-file",'-e',$hash_base) ==05826or die_error(404,"Base object does not exist");58275828# here errors should not hapen5829open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name5830or die_error(500,"Open git-ls-tree failed");5831my$line= <$fd>;5832close$fd;58335834#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'5835unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {5836 die_error(404,"File or directory for given base does not exist");5837}5838$type=$2;5839$hash=$3;5840}else{5841 die_error(400,"Not enough information to find object");5842}58435844print$cgi->redirect(-uri => href(action=>$type, -full=>1,5845 hash=>$hash, hash_base=>$hash_base,5846 file_name=>$file_name),5847-status =>'302 Found');5848}58495850sub git_blobdiff {5851my$format=shift||'html';58525853my$fd;5854my@difftree;5855my%diffinfo;5856my$expires;58575858# preparing $fd and %diffinfo for git_patchset_body5859# new style URI5860if(defined$hash_base&&defined$hash_parent_base) {5861if(defined$file_name) {5862# read raw output5863open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5864$hash_parent_base,$hash_base,5865"--", (defined$file_parent?$file_parent: ()),$file_name5866or die_error(500,"Open git-diff-tree failed");5867@difftree=map{chomp;$_} <$fd>;5868close$fd5869or die_error(404,"Reading git-diff-tree failed");5870@difftree5871or die_error(404,"Blob diff not found");58725873}elsif(defined$hash&&5874$hash=~/[0-9a-fA-F]{40}/) {5875# try to find filename from $hash58765877# read filtered raw output5878open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5879$hash_parent_base,$hash_base,"--"5880or die_error(500,"Open git-diff-tree failed");5881@difftree=5882# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5883# $hash == to_id5884grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5885map{chomp;$_} <$fd>;5886close$fd5887or die_error(404,"Reading git-diff-tree failed");5888@difftree5889or die_error(404,"Blob diff not found");58905891}else{5892 die_error(400,"Missing one of the blob diff parameters");5893}58945895if(@difftree>1) {5896 die_error(400,"Ambiguous blob diff specification");5897}58985899%diffinfo= parse_difftree_raw_line($difftree[0]);5900$file_parent||=$diffinfo{'from_file'} ||$file_name;5901$file_name||=$diffinfo{'to_file'};59025903$hash_parent||=$diffinfo{'from_id'};5904$hash||=$diffinfo{'to_id'};59055906# non-textual hash id's can be cached5907if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5908$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5909$expires='+1d';5910}59115912# open patch output5913open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5914'-p', ($formateq'html'?"--full-index": ()),5915$hash_parent_base,$hash_base,5916"--", (defined$file_parent?$file_parent: ()),$file_name5917or die_error(500,"Open git-diff-tree failed");5918}59195920# old/legacy style URI -- not generated anymore since 1.4.3.5921if(!%diffinfo) {5922 die_error('404 Not Found',"Missing one of the blob diff parameters")5923}59245925# header5926if($formateq'html') {5927my$formats_nav=5928$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5929"raw");5930 git_header_html(undef,$expires);5931if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5932 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5933 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5934}else{5935print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5936print"<div class=\"title\">$hashvs$hash_parent</div>\n";5937}5938if(defined$file_name) {5939 git_print_page_path($file_name,"blob",$hash_base);5940}else{5941print"<div class=\"page_path\"></div>\n";5942}59435944}elsif($formateq'plain') {5945print$cgi->header(5946-type =>'text/plain',5947-charset =>'utf-8',5948-expires =>$expires,5949-content_disposition =>'inline; filename="'."$file_name".'.patch"');59505951print"X-Git-Url: ".$cgi->self_url() ."\n\n";59525953}else{5954 die_error(400,"Unknown blobdiff format");5955}59565957# patch5958if($formateq'html') {5959print"<div class=\"page_body\">\n";59605961 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5962close$fd;59635964print"</div>\n";# class="page_body"5965 git_footer_html();59665967}else{5968while(my$line= <$fd>) {5969$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5970$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;59715972print$line;59735974last if$line=~m!^\+\+\+!;5975}5976local$/=undef;5977print<$fd>;5978close$fd;5979}5980}59815982sub git_blobdiff_plain {5983 git_blobdiff('plain');5984}59855986sub git_commitdiff {5987my%params=@_;5988my$format=$params{-format} ||'html';59895990my($patch_max) = gitweb_get_feature('patches');5991if($formateq'patch') {5992 die_error(403,"Patch view not allowed")unless$patch_max;5993}59945995$hash||=$hash_base||"HEAD";5996my%co= parse_commit($hash)5997or die_error(404,"Unknown commit object");59985999# choose format for commitdiff for merge6000if(!defined$hash_parent&& @{$co{'parents'}} >1) {6001$hash_parent='--cc';6002}6003# we need to prepare $formats_nav before almost any parameter munging6004my$formats_nav;6005if($formateq'html') {6006$formats_nav=6007$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},6008"raw");6009if($patch_max&& @{$co{'parents'}} <=1) {6010$formats_nav.=" | ".6011$cgi->a({-href => href(action=>"patch", -replay=>1)},6012"patch");6013}60146015if(defined$hash_parent&&6016$hash_parentne'-c'&&$hash_parentne'--cc') {6017# commitdiff with two commits given6018my$hash_parent_short=$hash_parent;6019if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {6020$hash_parent_short=substr($hash_parent,0,7);6021}6022$formats_nav.=6023' (from';6024for(my$i=0;$i< @{$co{'parents'}};$i++) {6025if($co{'parents'}[$i]eq$hash_parent) {6026$formats_nav.=' parent '. ($i+1);6027last;6028}6029}6030$formats_nav.=': '.6031$cgi->a({-href => href(action=>"commitdiff",6032 hash=>$hash_parent)},6033 esc_html($hash_parent_short)) .6034')';6035}elsif(!$co{'parent'}) {6036# --root commitdiff6037$formats_nav.=' (initial)';6038}elsif(scalar@{$co{'parents'}} ==1) {6039# single parent commit6040$formats_nav.=6041' (parent: '.6042$cgi->a({-href => href(action=>"commitdiff",6043 hash=>$co{'parent'})},6044 esc_html(substr($co{'parent'},0,7))) .6045')';6046}else{6047# merge commit6048if($hash_parenteq'--cc') {6049$formats_nav.=' | '.6050$cgi->a({-href => href(action=>"commitdiff",6051 hash=>$hash, hash_parent=>'-c')},6052'combined');6053}else{# $hash_parent eq '-c'6054$formats_nav.=' | '.6055$cgi->a({-href => href(action=>"commitdiff",6056 hash=>$hash, hash_parent=>'--cc')},6057'compact');6058}6059$formats_nav.=6060' (merge: '.6061join(' ',map{6062$cgi->a({-href => href(action=>"commitdiff",6063 hash=>$_)},6064 esc_html(substr($_,0,7)));6065} @{$co{'parents'}} ) .6066')';6067}6068}60696070my$hash_parent_param=$hash_parent;6071if(!defined$hash_parent_param) {6072# --cc for multiple parents, --root for parentless6073$hash_parent_param=6074@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';6075}60766077# read commitdiff6078my$fd;6079my@difftree;6080if($formateq'html') {6081open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6082"--no-commit-id","--patch-with-raw","--full-index",6083$hash_parent_param,$hash,"--"6084or die_error(500,"Open git-diff-tree failed");60856086while(my$line= <$fd>) {6087chomp$line;6088# empty line ends raw part of diff-tree output6089last unless$line;6090push@difftree,scalar parse_difftree_raw_line($line);6091}60926093}elsif($formateq'plain') {6094open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6095'-p',$hash_parent_param,$hash,"--"6096or die_error(500,"Open git-diff-tree failed");6097}elsif($formateq'patch') {6098# For commit ranges, we limit the output to the number of6099# patches specified in the 'patches' feature.6100# For single commits, we limit the output to a single patch,6101# diverging from the git-format-patch default.6102my@commit_spec= ();6103if($hash_parent) {6104if($patch_max>0) {6105push@commit_spec,"-$patch_max";6106}6107push@commit_spec,'-n',"$hash_parent..$hash";6108}else{6109if($params{-single}) {6110push@commit_spec,'-1';6111}else{6112if($patch_max>0) {6113push@commit_spec,"-$patch_max";6114}6115push@commit_spec,"-n";6116}6117push@commit_spec,'--root',$hash;6118}6119open$fd,"-|", git_cmd(),"format-patch",'--encoding=utf8',6120'--stdout',@commit_spec6121or die_error(500,"Open git-format-patch failed");6122}else{6123 die_error(400,"Unknown commitdiff format");6124}61256126# non-textual hash id's can be cached6127my$expires;6128if($hash=~m/^[0-9a-fA-F]{40}$/) {6129$expires="+1d";6130}61316132# write commit message6133if($formateq'html') {6134my$refs= git_get_references();6135my$ref= format_ref_marker($refs,$co{'id'});61366137 git_header_html(undef,$expires);6138 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);6139 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);6140print"<div class=\"title_text\">\n".6141"<table class=\"object_header\">\n";6142 git_print_authorship_rows(\%co);6143print"</table>".6144"</div>\n";6145print"<div class=\"page_body\">\n";6146if(@{$co{'comment'}} >1) {6147print"<div class=\"log\">\n";6148 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);6149print"</div>\n";# class="log"6150}61516152}elsif($formateq'plain') {6153my$refs= git_get_references("tags");6154my$tagname= git_get_rev_name_tags($hash);6155my$filename= basename($project) ."-$hash.patch";61566157print$cgi->header(6158-type =>'text/plain',6159-charset =>'utf-8',6160-expires =>$expires,6161-content_disposition =>'inline; filename="'."$filename".'"');6162my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});6163print"From: ". to_utf8($co{'author'}) ."\n";6164print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";6165print"Subject: ". to_utf8($co{'title'}) ."\n";61666167print"X-Git-Tag:$tagname\n"if$tagname;6168print"X-Git-Url: ".$cgi->self_url() ."\n\n";61696170foreachmy$line(@{$co{'comment'}}) {6171print to_utf8($line) ."\n";6172}6173print"---\n\n";6174}elsif($formateq'patch') {6175my$filename= basename($project) ."-$hash.patch";61766177print$cgi->header(6178-type =>'text/plain',6179-charset =>'utf-8',6180-expires =>$expires,6181-content_disposition =>'inline; filename="'."$filename".'"');6182}61836184# write patch6185if($formateq'html') {6186my$use_parents= !defined$hash_parent||6187$hash_parenteq'-c'||$hash_parenteq'--cc';6188 git_difftree_body(\@difftree,$hash,6189$use_parents? @{$co{'parents'}} :$hash_parent);6190print"<br/>\n";61916192 git_patchset_body($fd, \@difftree,$hash,6193$use_parents? @{$co{'parents'}} :$hash_parent);6194close$fd;6195print"</div>\n";# class="page_body"6196 git_footer_html();61976198}elsif($formateq'plain') {6199local$/=undef;6200print<$fd>;6201close$fd6202or print"Reading git-diff-tree failed\n";6203}elsif($formateq'patch') {6204local$/=undef;6205print<$fd>;6206close$fd6207or print"Reading git-format-patch failed\n";6208}6209}62106211sub git_commitdiff_plain {6212 git_commitdiff(-format =>'plain');6213}62146215# format-patch-style patches6216sub git_patch {6217 git_commitdiff(-format =>'patch', -single =>1);6218}62196220sub git_patches {6221 git_commitdiff(-format =>'patch');6222}62236224sub git_history {6225 git_log_generic('history', \&git_history_body,6226$hash_base,$hash_parent_base,6227$file_name,$hash);6228}62296230sub git_search {6231 gitweb_check_feature('search')or die_error(403,"Search is disabled");6232if(!defined$searchtext) {6233 die_error(400,"Text field is empty");6234}6235if(!defined$hash) {6236$hash= git_get_head_hash($project);6237}6238my%co= parse_commit($hash);6239if(!%co) {6240 die_error(404,"Unknown commit object");6241}6242if(!defined$page) {6243$page=0;6244}62456246$searchtype||='commit';6247if($searchtypeeq'pickaxe') {6248# pickaxe may take all resources of your box and run for several minutes6249# with every query - so decide by yourself how public you make this feature6250 gitweb_check_feature('pickaxe')6251or die_error(403,"Pickaxe is disabled");6252}6253if($searchtypeeq'grep') {6254 gitweb_check_feature('grep')6255or die_error(403,"Grep is disabled");6256}62576258 git_header_html();62596260if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {6261my$greptype;6262if($searchtypeeq'commit') {6263$greptype="--grep=";6264}elsif($searchtypeeq'author') {6265$greptype="--author=";6266}elsif($searchtypeeq'committer') {6267$greptype="--committer=";6268}6269$greptype.=$searchtext;6270my@commitlist= parse_commits($hash,101, (100*$page),undef,6271$greptype,'--regexp-ignore-case',6272$search_use_regexp?'--extended-regexp':'--fixed-strings');62736274my$paging_nav='';6275if($page>0) {6276$paging_nav.=6277$cgi->a({-href => href(action=>"search", hash=>$hash,6278 searchtext=>$searchtext,6279 searchtype=>$searchtype)},6280"first");6281$paging_nav.=" ⋅ ".6282$cgi->a({-href => href(-replay=>1, page=>$page-1),6283-accesskey =>"p", -title =>"Alt-p"},"prev");6284}else{6285$paging_nav.="first";6286$paging_nav.=" ⋅ prev";6287}6288my$next_link='';6289if($#commitlist>=100) {6290$next_link=6291$cgi->a({-href => href(-replay=>1, page=>$page+1),6292-accesskey =>"n", -title =>"Alt-n"},"next");6293$paging_nav.=" ⋅$next_link";6294}else{6295$paging_nav.=" ⋅ next";6296}62976298if($#commitlist>=100) {6299}63006301 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);6302 git_print_header_div('commit', esc_html($co{'title'}),$hash);6303 git_search_grep_body(\@commitlist,0,99,$next_link);6304}63056306if($searchtypeeq'pickaxe') {6307 git_print_page_nav('','',$hash,$co{'tree'},$hash);6308 git_print_header_div('commit', esc_html($co{'title'}),$hash);63096310print"<table class=\"pickaxe search\">\n";6311my$alternate=1;6312local$/="\n";6313open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,6314'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",6315($search_use_regexp?'--pickaxe-regex': ());6316undef%co;6317my@files;6318while(my$line= <$fd>) {6319chomp$line;6320next unless$line;63216322my%set= parse_difftree_raw_line($line);6323if(defined$set{'commit'}) {6324# finish previous commit6325if(%co) {6326print"</td>\n".6327"<td class=\"link\">".6328$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6329" | ".6330$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6331print"</td>\n".6332"</tr>\n";6333}63346335if($alternate) {6336print"<tr class=\"dark\">\n";6337}else{6338print"<tr class=\"light\">\n";6339}6340$alternate^=1;6341%co= parse_commit($set{'commit'});6342my$author= chop_and_escape_str($co{'author_name'},15,5);6343print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6344"<td><i>$author</i></td>\n".6345"<td>".6346$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6347-class=>"list subject"},6348 chop_and_escape_str($co{'title'},50) ."<br/>");6349}elsif(defined$set{'to_id'}) {6350next if($set{'to_id'} =~m/^0{40}$/);63516352print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6353 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6354-class=>"list"},6355"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6356"<br/>\n";6357}6358}6359close$fd;63606361# finish last commit (warning: repetition!)6362if(%co) {6363print"</td>\n".6364"<td class=\"link\">".6365$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6366" | ".6367$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6368print"</td>\n".6369"</tr>\n";6370}63716372print"</table>\n";6373}63746375if($searchtypeeq'grep') {6376 git_print_page_nav('','',$hash,$co{'tree'},$hash);6377 git_print_header_div('commit', esc_html($co{'title'}),$hash);63786379print"<table class=\"grep_search\">\n";6380my$alternate=1;6381my$matches=0;6382local$/="\n";6383open my$fd,"-|", git_cmd(),'grep','-n',6384$search_use_regexp? ('-E','-i') :'-F',6385$searchtext,$co{'tree'};6386my$lastfile='';6387while(my$line= <$fd>) {6388chomp$line;6389my($file,$lno,$ltext,$binary);6390last if($matches++>1000);6391if($line=~/^Binary file (.+) matches$/) {6392$file=$1;6393$binary=1;6394}else{6395(undef,$file,$lno,$ltext) =split(/:/,$line,4);6396}6397if($filene$lastfile) {6398$lastfileand print"</td></tr>\n";6399if($alternate++) {6400print"<tr class=\"dark\">\n";6401}else{6402print"<tr class=\"light\">\n";6403}6404print"<td class=\"list\">".6405$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6406 file_name=>"$file"),6407-class=>"list"}, esc_path($file));6408print"</td><td>\n";6409$lastfile=$file;6410}6411if($binary) {6412print"<div class=\"binary\">Binary file</div>\n";6413}else{6414$ltext= untabify($ltext);6415if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6416$ltext= esc_html($1, -nbsp=>1);6417$ltext.='<span class="match">';6418$ltext.= esc_html($2, -nbsp=>1);6419$ltext.='</span>';6420$ltext.= esc_html($3, -nbsp=>1);6421}else{6422$ltext= esc_html($ltext, -nbsp=>1);6423}6424print"<div class=\"pre\">".6425$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6426 file_name=>"$file").'#l'.$lno,6427-class=>"linenr"},sprintf('%4i',$lno))6428.' '.$ltext."</div>\n";6429}6430}6431if($lastfile) {6432print"</td></tr>\n";6433if($matches>1000) {6434print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6435}6436}else{6437print"<div class=\"diff nodifferences\">No matches found</div>\n";6438}6439close$fd;64406441print"</table>\n";6442}6443 git_footer_html();6444}64456446sub git_search_help {6447 git_header_html();6448 git_print_page_nav('','',$hash,$hash,$hash);6449print<<EOT;6450<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without6451regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,6452the pattern entered is recognized as the POSIX extended6453<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case6454insensitive).</p>6455<dl>6456<dt><b>commit</b></dt>6457<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>6458EOT6459my$have_grep= gitweb_check_feature('grep');6460if($have_grep) {6461print<<EOT;6462<dt><b>grep</b></dt>6463<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing6464 a different one) are searched for the given pattern. On large trees, this search can take6465a while and put some strain on the server, so please use it with some consideration. Note that6466due to git-grep peculiarity, currently if regexp mode is turned off, the matches are6467case-sensitive.</dd>6468EOT6469}6470print<<EOT;6471<dt><b>author</b></dt>6472<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>6473<dt><b>committer</b></dt>6474<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>6475EOT6476my$have_pickaxe= gitweb_check_feature('pickaxe');6477if($have_pickaxe) {6478print<<EOT;6479<dt><b>pickaxe</b></dt>6480<dd>All commits that caused the string to appear or disappear from any file (changes that6481added, removed or "modified" the string) will be listed. This search can take a while and6482takes a lot of strain on the server, so please use it wisely. Note that since you may be6483interested even in changes just changing the case as well, this search is case sensitive.</dd>6484EOT6485}6486print"</dl>\n";6487 git_footer_html();6488}64896490sub git_shortlog {6491 git_log_generic('shortlog', \&git_shortlog_body,6492$hash,$hash_parent);6493}64946495## ......................................................................6496## feeds (RSS, Atom; OPML)64976498sub git_feed {6499my$format=shift||'atom';6500my$have_blame= gitweb_check_feature('blame');65016502# Atom: http://www.atomenabled.org/developers/syndication/6503# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ6504if($formatne'rss'&&$formatne'atom') {6505 die_error(400,"Unknown web feed format");6506}65076508# log/feed of current (HEAD) branch, log of given branch, history of file/directory6509my$head=$hash||'HEAD';6510my@commitlist= parse_commits($head,150,0,$file_name);65116512my%latest_commit;6513my%latest_date;6514my$content_type="application/$format+xml";6515if(defined$cgi->http('HTTP_ACCEPT') &&6516$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {6517# browser (feed reader) prefers text/xml6518$content_type='text/xml';6519}6520if(defined($commitlist[0])) {6521%latest_commit= %{$commitlist[0]};6522my$latest_epoch=$latest_commit{'committer_epoch'};6523%latest_date= parse_date($latest_epoch);6524my$if_modified=$cgi->http('IF_MODIFIED_SINCE');6525if(defined$if_modified) {6526my$since;6527if(eval{require HTTP::Date;1; }) {6528$since= HTTP::Date::str2time($if_modified);6529}elsif(eval{require Time::ParseDate;1; }) {6530$since= Time::ParseDate::parsedate($if_modified, GMT =>1);6531}6532if(defined$since&&$latest_epoch<=$since) {6533print$cgi->header(6534-type =>$content_type,6535-charset =>'utf-8',6536-last_modified =>$latest_date{'rfc2822'},6537-status =>'304 Not Modified');6538return;6539}6540}6541print$cgi->header(6542-type =>$content_type,6543-charset =>'utf-8',6544-last_modified =>$latest_date{'rfc2822'});6545}else{6546print$cgi->header(6547-type =>$content_type,6548-charset =>'utf-8');6549}65506551# Optimization: skip generating the body if client asks only6552# for Last-Modified date.6553return if($cgi->request_method()eq'HEAD');65546555# header variables6556my$title="$site_name-$project/$action";6557my$feed_type='log';6558if(defined$hash) {6559$title.=" - '$hash'";6560$feed_type='branch log';6561if(defined$file_name) {6562$title.=" ::$file_name";6563$feed_type='history';6564}6565}elsif(defined$file_name) {6566$title.=" -$file_name";6567$feed_type='history';6568}6569$title.="$feed_type";6570my$descr= git_get_project_description($project);6571if(defined$descr) {6572$descr= esc_html($descr);6573}else{6574$descr="$project".6575($formateq'rss'?'RSS':'Atom') .6576" feed";6577}6578my$owner= git_get_project_owner($project);6579$owner= esc_html($owner);65806581#header6582my$alt_url;6583if(defined$file_name) {6584$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);6585}elsif(defined$hash) {6586$alt_url= href(-full=>1, action=>"log", hash=>$hash);6587}else{6588$alt_url= href(-full=>1, action=>"summary");6589}6590print qq!<?xml version="1.0" encoding="utf-8"?>\n!;6591if($formateq'rss') {6592print<<XML;6593<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">6594<channel>6595XML6596print"<title>$title</title>\n".6597"<link>$alt_url</link>\n".6598"<description>$descr</description>\n".6599"<language>en</language>\n".6600# project owner is responsible for 'editorial' content6601"<managingEditor>$owner</managingEditor>\n";6602if(defined$logo||defined$favicon) {6603# prefer the logo to the favicon, since RSS6604# doesn't allow both6605my$img= esc_url($logo||$favicon);6606print"<image>\n".6607"<url>$img</url>\n".6608"<title>$title</title>\n".6609"<link>$alt_url</link>\n".6610"</image>\n";6611}6612if(%latest_date) {6613print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";6614print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";6615}6616print"<generator>gitweb v.$version/$git_version</generator>\n";6617}elsif($formateq'atom') {6618print<<XML;6619<feed xmlns="http://www.w3.org/2005/Atom">6620XML6621print"<title>$title</title>\n".6622"<subtitle>$descr</subtitle>\n".6623'<link rel="alternate" type="text/html" href="'.6624$alt_url.'" />'."\n".6625'<link rel="self" type="'.$content_type.'" href="'.6626$cgi->self_url() .'" />'."\n".6627"<id>". href(-full=>1) ."</id>\n".6628# use project owner for feed author6629"<author><name>$owner</name></author>\n";6630if(defined$favicon) {6631print"<icon>". esc_url($favicon) ."</icon>\n";6632}6633if(defined$logo_url) {6634# not twice as wide as tall: 72 x 27 pixels6635print"<logo>". esc_url($logo) ."</logo>\n";6636}6637if(!%latest_date) {6638# dummy date to keep the feed valid until commits trickle in:6639print"<updated>1970-01-01T00:00:00Z</updated>\n";6640}else{6641print"<updated>$latest_date{'iso-8601'}</updated>\n";6642}6643print"<generator version='$version/$git_version'>gitweb</generator>\n";6644}66456646# contents6647for(my$i=0;$i<=$#commitlist;$i++) {6648my%co= %{$commitlist[$i]};6649my$commit=$co{'id'};6650# we read 150, we always show 30 and the ones more recent than 48 hours6651if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6652last;6653}6654my%cd= parse_date($co{'author_epoch'});66556656# get list of changed files6657open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6658$co{'parent'} ||"--root",6659$co{'id'},"--", (defined$file_name?$file_name: ())6660ornext;6661my@difftree=map{chomp;$_} <$fd>;6662close$fd6663ornext;66646665# print element (entry, item)6666my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6667if($formateq'rss') {6668print"<item>\n".6669"<title>". esc_html($co{'title'}) ."</title>\n".6670"<author>". esc_html($co{'author'}) ."</author>\n".6671"<pubDate>$cd{'rfc2822'}</pubDate>\n".6672"<guid isPermaLink=\"true\">$co_url</guid>\n".6673"<link>$co_url</link>\n".6674"<description>". esc_html($co{'title'}) ."</description>\n".6675"<content:encoded>".6676"<![CDATA[\n";6677}elsif($formateq'atom') {6678print"<entry>\n".6679"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6680"<updated>$cd{'iso-8601'}</updated>\n".6681"<author>\n".6682" <name>". esc_html($co{'author_name'}) ."</name>\n";6683if($co{'author_email'}) {6684print" <email>". esc_html($co{'author_email'}) ."</email>\n";6685}6686print"</author>\n".6687# use committer for contributor6688"<contributor>\n".6689" <name>". esc_html($co{'committer_name'}) ."</name>\n";6690if($co{'committer_email'}) {6691print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6692}6693print"</contributor>\n".6694"<published>$cd{'iso-8601'}</published>\n".6695"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6696"<id>$co_url</id>\n".6697"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6698"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6699}6700my$comment=$co{'comment'};6701print"<pre>\n";6702foreachmy$line(@$comment) {6703$line= esc_html($line);6704print"$line\n";6705}6706print"</pre><ul>\n";6707foreachmy$difftree_line(@difftree) {6708my%difftree= parse_difftree_raw_line($difftree_line);6709next if!$difftree{'from_id'};67106711my$file=$difftree{'file'} ||$difftree{'to_file'};67126713print"<li>".6714"[".6715$cgi->a({-href => href(-full=>1, action=>"blobdiff",6716 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6717 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6718 file_name=>$file, file_parent=>$difftree{'from_file'}),6719-title =>"diff"},'D');6720if($have_blame) {6721print$cgi->a({-href => href(-full=>1, action=>"blame",6722 file_name=>$file, hash_base=>$commit),6723-title =>"blame"},'B');6724}6725# if this is not a feed of a file history6726if(!defined$file_name||$file_namene$file) {6727print$cgi->a({-href => href(-full=>1, action=>"history",6728 file_name=>$file, hash=>$commit),6729-title =>"history"},'H');6730}6731$file= esc_path($file);6732print"] ".6733"$file</li>\n";6734}6735if($formateq'rss') {6736print"</ul>]]>\n".6737"</content:encoded>\n".6738"</item>\n";6739}elsif($formateq'atom') {6740print"</ul>\n</div>\n".6741"</content>\n".6742"</entry>\n";6743}6744}67456746# end of feed6747if($formateq'rss') {6748print"</channel>\n</rss>\n";6749}elsif($formateq'atom') {6750print"</feed>\n";6751}6752}67536754sub git_rss {6755 git_feed('rss');6756}67576758sub git_atom {6759 git_feed('atom');6760}67616762sub git_opml {6763my@list= git_get_projects_list();67646765print$cgi->header(6766-type =>'text/xml',6767-charset =>'utf-8',6768-content_disposition =>'inline; filename="opml.xml"');67696770print<<XML;6771<?xml version="1.0" encoding="utf-8"?>6772<opml version="1.0">6773<head>6774 <title>$site_nameOPML Export</title>6775</head>6776<body>6777<outline text="git RSS feeds">6778XML67796780foreachmy$pr(@list) {6781my%proj=%$pr;6782my$head= git_get_head_hash($proj{'path'});6783if(!defined$head) {6784next;6785}6786$git_dir="$projectroot/$proj{'path'}";6787my%co= parse_commit($head);6788if(!%co) {6789next;6790}67916792my$path= esc_html(chop_str($proj{'path'},25,5));6793my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);6794my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);6795print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";6796}6797print<<XML;6798</outline>6799</body>6800</opml>6801XML6802}