1#!/usr/bin/perl 2 3# gitweb - simple web interface to track changes in git repositories 4# 5# (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org> 6# (C) 2005, Christian Gierke 7# 8# This program is licensed under the GPLv2 9 10use5.008; 11use strict; 12use warnings; 13use CGI qw(:standard :escapeHTML -nosticky); 14use CGI::Util qw(unescape); 15use CGI::Carp qw(fatalsToBrowser set_message); 16use Encode; 17use Fcntl ':mode'; 18use File::Find qw(); 19use File::Basename qw(basename); 20use Time::HiRes qw(gettimeofday tv_interval); 21binmode STDOUT,':utf8'; 22 23our$t0= [ gettimeofday() ]; 24our$number_of_git_cmds=0; 25 26BEGIN{ 27 CGI->compile()if$ENV{'MOD_PERL'}; 28} 29 30our$version="++GIT_VERSION++"; 31 32our($my_url,$my_uri,$base_url,$path_info,$home_link); 33sub evaluate_uri { 34our$cgi; 35 36our$my_url=$cgi->url(); 37our$my_uri=$cgi->url(-absolute =>1); 38 39# Base URL for relative URLs in gitweb ($logo, $favicon, ...), 40# needed and used only for URLs with nonempty PATH_INFO 41our$base_url=$my_url; 42 43# When the script is used as DirectoryIndex, the URL does not contain the name 44# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we 45# have to do it ourselves. We make $path_info global because it's also used 46# later on. 47# 48# Another issue with the script being the DirectoryIndex is that the resulting 49# $my_url data is not the full script URL: this is good, because we want 50# generated links to keep implying the script name if it wasn't explicitly 51# indicated in the URL we're handling, but it means that $my_url cannot be used 52# as base URL. 53# Therefore, if we needed to strip PATH_INFO, then we know that we have 54# to build the base URL ourselves: 55our$path_info=$ENV{"PATH_INFO"}; 56if($path_info) { 57if($my_url=~ s,\Q$path_info\E$,, && 58$my_uri=~ s,\Q$path_info\E$,, && 59defined$ENV{'SCRIPT_NAME'}) { 60$base_url=$cgi->url(-base =>1) .$ENV{'SCRIPT_NAME'}; 61} 62} 63 64# target of the home link on top of all pages 65our$home_link=$my_uri||"/"; 66} 67 68# core git executable to use 69# this can just be "git" if your webserver has a sensible PATH 70our$GIT="++GIT_BINDIR++/git"; 71 72# absolute fs-path which will be prepended to the project path 73#our $projectroot = "/pub/scm"; 74our$projectroot="++GITWEB_PROJECTROOT++"; 75 76# fs traversing limit for getting project list 77# the number is relative to the projectroot 78our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 79 80# string of the home link on top of all pages 81our$home_link_str="++GITWEB_HOME_LINK_STR++"; 82 83# name of your site or organization to appear in page titles 84# replace this with something more descriptive for clearer bookmarks 85our$site_name="++GITWEB_SITENAME++" 86|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 87 88# filename of html text to include at top of each page 89our$site_header="++GITWEB_SITE_HEADER++"; 90# html text to include at home page 91our$home_text="++GITWEB_HOMETEXT++"; 92# filename of html text to include at bottom of each page 93our$site_footer="++GITWEB_SITE_FOOTER++"; 94 95# URI of stylesheets 96our@stylesheets= ("++GITWEB_CSS++"); 97# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 98our$stylesheet=undef; 99# URI of GIT logo (72x27 size) 100our$logo="++GITWEB_LOGO++"; 101# URI of GIT favicon, assumed to be image/png type 102our$favicon="++GITWEB_FAVICON++"; 103# URI of gitweb.js (JavaScript code for gitweb) 104our$javascript="++GITWEB_JS++"; 105 106# URI and label (title) of GIT logo link 107#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 108#our $logo_label = "git documentation"; 109our$logo_url="http://git-scm.com/"; 110our$logo_label="git homepage"; 111 112# source of projects list 113our$projects_list="++GITWEB_LIST++"; 114 115# the width (in characters) of the projects list "Description" column 116our$projects_list_description_width=25; 117 118# default order of projects list 119# valid values are none, project, descr, owner, and age 120our$default_projects_order="project"; 121 122# show repository only if this file exists 123# (only effective if this variable evaluates to true) 124our$export_ok="++GITWEB_EXPORT_OK++"; 125 126# show repository only if this subroutine returns true 127# when given the path to the project, for example: 128# sub { return -e "$_[0]/git-daemon-export-ok"; } 129our$export_auth_hook=undef; 130 131# only allow viewing of repositories also shown on the overview page 132our$strict_export="++GITWEB_STRICT_EXPORT++"; 133 134# list of git base URLs used for URL to where fetch project from, 135# i.e. full URL is "$git_base_url/$project" 136our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 137 138# default blob_plain mimetype and default charset for text/plain blob 139our$default_blob_plain_mimetype='text/plain'; 140our$default_text_plain_charset=undef; 141 142# file to use for guessing MIME types before trying /etc/mime.types 143# (relative to the current git repository) 144our$mimetypes_file=undef; 145 146# assume this charset if line contains non-UTF-8 characters; 147# it should be valid encoding (see Encoding::Supported(3pm) for list), 148# for which encoding all byte sequences are valid, for example 149# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 150# could be even 'utf-8' for the old behavior) 151our$fallback_encoding='latin1'; 152 153# rename detection options for git-diff and git-diff-tree 154# - default is '-M', with the cost proportional to 155# (number of removed files) * (number of new files). 156# - more costly is '-C' (which implies '-M'), with the cost proportional to 157# (number of changed files + number of removed files) * (number of new files) 158# - even more costly is '-C', '--find-copies-harder' with cost 159# (number of files in the original tree) * (number of new files) 160# - one might want to include '-B' option, e.g. '-B', '-M' 161our@diff_opts= ('-M');# taken from git_commit 162 163# Disables features that would allow repository owners to inject script into 164# the gitweb domain. 165our$prevent_xss=0; 166 167# Path to the highlight executable to use (must be the one from 168# http://www.andre-simon.de due to assumptions about parameters and output). 169# Useful if highlight is not installed on your webserver's PATH. 170# [Default: highlight] 171our$highlight_bin="++HIGHLIGHT_BIN++"; 172 173# information about snapshot formats that gitweb is capable of serving 174our%known_snapshot_formats= ( 175# name => { 176# 'display' => display name, 177# 'type' => mime type, 178# 'suffix' => filename suffix, 179# 'format' => --format for git-archive, 180# 'compressor' => [compressor command and arguments] 181# (array reference, optional) 182# 'disabled' => boolean (optional)} 183# 184'tgz'=> { 185'display'=>'tar.gz', 186'type'=>'application/x-gzip', 187'suffix'=>'.tar.gz', 188'format'=>'tar', 189'compressor'=> ['gzip']}, 190 191'tbz2'=> { 192'display'=>'tar.bz2', 193'type'=>'application/x-bzip2', 194'suffix'=>'.tar.bz2', 195'format'=>'tar', 196'compressor'=> ['bzip2']}, 197 198'txz'=> { 199'display'=>'tar.xz', 200'type'=>'application/x-xz', 201'suffix'=>'.tar.xz', 202'format'=>'tar', 203'compressor'=> ['xz'], 204'disabled'=>1}, 205 206'zip'=> { 207'display'=>'zip', 208'type'=>'application/x-zip', 209'suffix'=>'.zip', 210'format'=>'zip'}, 211); 212 213# Aliases so we understand old gitweb.snapshot values in repository 214# configuration. 215our%known_snapshot_format_aliases= ( 216'gzip'=>'tgz', 217'bzip2'=>'tbz2', 218'xz'=>'txz', 219 220# backward compatibility: legacy gitweb config support 221'x-gzip'=>undef,'gz'=>undef, 222'x-bzip2'=>undef,'bz2'=>undef, 223'x-zip'=>undef,''=>undef, 224); 225 226# Pixel sizes for icons and avatars. If the default font sizes or lineheights 227# are changed, it may be appropriate to change these values too via 228# $GITWEB_CONFIG. 229our%avatar_size= ( 230'default'=>16, 231'double'=>32 232); 233 234# Used to set the maximum load that we will still respond to gitweb queries. 235# If server load exceed this value then return "503 server busy" error. 236# If gitweb cannot determined server load, it is taken to be 0. 237# Leave it undefined (or set to 'undef') to turn off load checking. 238our$maxload=300; 239 240# configuration for 'highlight' (http://www.andre-simon.de/) 241# match by basename 242our%highlight_basename= ( 243#'Program' => 'py', 244#'Library' => 'py', 245'SConstruct'=>'py',# SCons equivalent of Makefile 246'Makefile'=>'make', 247); 248# match by extension 249our%highlight_ext= ( 250# main extensions, defining name of syntax; 251# see files in /usr/share/highlight/langDefs/ directory 252map{$_=>$_} 253qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl), 254# alternate extensions, see /etc/highlight/filetypes.conf 255'h'=>'c', 256map{$_=>'cpp'}qw(cxx c++ cc), 257map{$_=>'php'}qw(php3 php4), 258map{$_=>'pl'}qw(perl pm),# perhaps also 'cgi' 259'mak'=>'make', 260map{$_=>'xml'}qw(xhtml html htm), 261); 262 263# You define site-wide feature defaults here; override them with 264# $GITWEB_CONFIG as necessary. 265our%feature= ( 266# feature => { 267# 'sub' => feature-sub (subroutine), 268# 'override' => allow-override (boolean), 269# 'default' => [ default options...] (array reference)} 270# 271# if feature is overridable (it means that allow-override has true value), 272# then feature-sub will be called with default options as parameters; 273# return value of feature-sub indicates if to enable specified feature 274# 275# if there is no 'sub' key (no feature-sub), then feature cannot be 276# overridden 277# 278# use gitweb_get_feature(<feature>) to retrieve the <feature> value 279# (an array) or gitweb_check_feature(<feature>) to check if <feature> 280# is enabled 281 282# Enable the 'blame' blob view, showing the last commit that modified 283# each line in the file. This can be very CPU-intensive. 284 285# To enable system wide have in $GITWEB_CONFIG 286# $feature{'blame'}{'default'} = [1]; 287# To have project specific config enable override in $GITWEB_CONFIG 288# $feature{'blame'}{'override'} = 1; 289# and in project config gitweb.blame = 0|1; 290'blame'=> { 291'sub'=>sub{ feature_bool('blame',@_) }, 292'override'=>0, 293'default'=> [0]}, 294 295# Enable the 'snapshot' link, providing a compressed archive of any 296# tree. This can potentially generate high traffic if you have large 297# project. 298 299# Value is a list of formats defined in %known_snapshot_formats that 300# you wish to offer. 301# To disable system wide have in $GITWEB_CONFIG 302# $feature{'snapshot'}{'default'} = []; 303# To have project specific config enable override in $GITWEB_CONFIG 304# $feature{'snapshot'}{'override'} = 1; 305# and in project config, a comma-separated list of formats or "none" 306# to disable. Example: gitweb.snapshot = tbz2,zip; 307'snapshot'=> { 308'sub'=> \&feature_snapshot, 309'override'=>0, 310'default'=> ['tgz']}, 311 312# Enable text search, which will list the commits which match author, 313# committer or commit text to a given string. Enabled by default. 314# Project specific override is not supported. 315'search'=> { 316'override'=>0, 317'default'=> [1]}, 318 319# Enable grep search, which will list the files in currently selected 320# tree containing the given string. Enabled by default. This can be 321# potentially CPU-intensive, of course. 322 323# To enable system wide have in $GITWEB_CONFIG 324# $feature{'grep'}{'default'} = [1]; 325# To have project specific config enable override in $GITWEB_CONFIG 326# $feature{'grep'}{'override'} = 1; 327# and in project config gitweb.grep = 0|1; 328'grep'=> { 329'sub'=>sub{ feature_bool('grep',@_) }, 330'override'=>0, 331'default'=> [1]}, 332 333# Enable the pickaxe search, which will list the commits that modified 334# a given string in a file. This can be practical and quite faster 335# alternative to 'blame', but still potentially CPU-intensive. 336 337# To enable system wide have in $GITWEB_CONFIG 338# $feature{'pickaxe'}{'default'} = [1]; 339# To have project specific config enable override in $GITWEB_CONFIG 340# $feature{'pickaxe'}{'override'} = 1; 341# and in project config gitweb.pickaxe = 0|1; 342'pickaxe'=> { 343'sub'=>sub{ feature_bool('pickaxe',@_) }, 344'override'=>0, 345'default'=> [1]}, 346 347# Enable showing size of blobs in a 'tree' view, in a separate 348# column, similar to what 'ls -l' does. This cost a bit of IO. 349 350# To disable system wide have in $GITWEB_CONFIG 351# $feature{'show-sizes'}{'default'} = [0]; 352# To have project specific config enable override in $GITWEB_CONFIG 353# $feature{'show-sizes'}{'override'} = 1; 354# and in project config gitweb.showsizes = 0|1; 355'show-sizes'=> { 356'sub'=>sub{ feature_bool('showsizes',@_) }, 357'override'=>0, 358'default'=> [1]}, 359 360# Make gitweb use an alternative format of the URLs which can be 361# more readable and natural-looking: project name is embedded 362# directly in the path and the query string contains other 363# auxiliary information. All gitweb installations recognize 364# URL in either format; this configures in which formats gitweb 365# generates links. 366 367# To enable system wide have in $GITWEB_CONFIG 368# $feature{'pathinfo'}{'default'} = [1]; 369# Project specific override is not supported. 370 371# Note that you will need to change the default location of CSS, 372# favicon, logo and possibly other files to an absolute URL. Also, 373# if gitweb.cgi serves as your indexfile, you will need to force 374# $my_uri to contain the script name in your $GITWEB_CONFIG. 375'pathinfo'=> { 376'override'=>0, 377'default'=> [0]}, 378 379# Make gitweb consider projects in project root subdirectories 380# to be forks of existing projects. Given project $projname.git, 381# projects matching $projname/*.git will not be shown in the main 382# projects list, instead a '+' mark will be added to $projname 383# there and a 'forks' view will be enabled for the project, listing 384# all the forks. If project list is taken from a file, forks have 385# to be listed after the main project. 386 387# To enable system wide have in $GITWEB_CONFIG 388# $feature{'forks'}{'default'} = [1]; 389# Project specific override is not supported. 390'forks'=> { 391'override'=>0, 392'default'=> [0]}, 393 394# Insert custom links to the action bar of all project pages. 395# This enables you mainly to link to third-party scripts integrating 396# into gitweb; e.g. git-browser for graphical history representation 397# or custom web-based repository administration interface. 398 399# The 'default' value consists of a list of triplets in the form 400# (label, link, position) where position is the label after which 401# to insert the link and link is a format string where %n expands 402# to the project name, %f to the project path within the filesystem, 403# %h to the current hash (h gitweb parameter) and %b to the current 404# hash base (hb gitweb parameter); %% expands to %. 405 406# To enable system wide have in $GITWEB_CONFIG e.g. 407# $feature{'actions'}{'default'} = [('graphiclog', 408# '/git-browser/by-commit.html?r=%n', 'summary')]; 409# Project specific override is not supported. 410'actions'=> { 411'override'=>0, 412'default'=> []}, 413 414# Allow gitweb scan project content tags described in ctags/ 415# of project repository, and display the popular Web 2.0-ish 416# "tag cloud" near the project list. Note that this is something 417# COMPLETELY different from the normal Git tags. 418 419# gitweb by itself can show existing tags, but it does not handle 420# tagging itself; you need an external application for that. 421# For an example script, check Girocco's cgi/tagproj.cgi. 422# You may want to install the HTML::TagCloud Perl module to get 423# a pretty tag cloud instead of just a list of tags. 424 425# To enable system wide have in $GITWEB_CONFIG 426# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 427# Project specific override is not supported. 428'ctags'=> { 429'override'=>0, 430'default'=> [0]}, 431 432# The maximum number of patches in a patchset generated in patch 433# view. Set this to 0 or undef to disable patch view, or to a 434# negative number to remove any limit. 435 436# To disable system wide have in $GITWEB_CONFIG 437# $feature{'patches'}{'default'} = [0]; 438# To have project specific config enable override in $GITWEB_CONFIG 439# $feature{'patches'}{'override'} = 1; 440# and in project config gitweb.patches = 0|n; 441# where n is the maximum number of patches allowed in a patchset. 442'patches'=> { 443'sub'=> \&feature_patches, 444'override'=>0, 445'default'=> [16]}, 446 447# Avatar support. When this feature is enabled, views such as 448# shortlog or commit will display an avatar associated with 449# the email of the committer(s) and/or author(s). 450 451# Currently available providers are gravatar and picon. 452# If an unknown provider is specified, the feature is disabled. 453 454# Gravatar depends on Digest::MD5. 455# Picon currently relies on the indiana.edu database. 456 457# To enable system wide have in $GITWEB_CONFIG 458# $feature{'avatar'}{'default'} = ['<provider>']; 459# where <provider> is either gravatar or picon. 460# To have project specific config enable override in $GITWEB_CONFIG 461# $feature{'avatar'}{'override'} = 1; 462# and in project config gitweb.avatar = <provider>; 463'avatar'=> { 464'sub'=> \&feature_avatar, 465'override'=>0, 466'default'=> ['']}, 467 468# Enable displaying how much time and how many git commands 469# it took to generate and display page. Disabled by default. 470# Project specific override is not supported. 471'timed'=> { 472'override'=>0, 473'default'=> [0]}, 474 475# Enable turning some links into links to actions which require 476# JavaScript to run (like 'blame_incremental'). Not enabled by 477# default. Project specific override is currently not supported. 478'javascript-actions'=> { 479'override'=>0, 480'default'=> [0]}, 481 482# Syntax highlighting support. This is based on Daniel Svensson's 483# and Sham Chukoury's work in gitweb-xmms2.git. 484# It requires the 'highlight' program present in $PATH, 485# and therefore is disabled by default. 486 487# To enable system wide have in $GITWEB_CONFIG 488# $feature{'highlight'}{'default'} = [1]; 489 490'highlight'=> { 491'sub'=>sub{ feature_bool('highlight',@_) }, 492'override'=>0, 493'default'=> [0]}, 494 495# Enable displaying of remote heads in the heads list 496 497# To enable system wide have in $GITWEB_CONFIG 498# $feature{'remote_heads'}{'default'} = [1]; 499# To have project specific config enable override in $GITWEB_CONFIG 500# $feature{'remote_heads'}{'override'} = 1; 501# and in project config gitweb.remote_heads = 0|1; 502'remote_heads'=> { 503'sub'=>sub{ feature_bool('remote_heads',@_) }, 504'override'=>0, 505'default'=> [0]}, 506); 507 508sub gitweb_get_feature { 509my($name) =@_; 510return unlessexists$feature{$name}; 511my($sub,$override,@defaults) = ( 512$feature{$name}{'sub'}, 513$feature{$name}{'override'}, 514@{$feature{$name}{'default'}}); 515# project specific override is possible only if we have project 516our$git_dir;# global variable, declared later 517if(!$override|| !defined$git_dir) { 518return@defaults; 519} 520if(!defined$sub) { 521warn"feature$nameis not overridable"; 522return@defaults; 523} 524return$sub->(@defaults); 525} 526 527# A wrapper to check if a given feature is enabled. 528# With this, you can say 529# 530# my $bool_feat = gitweb_check_feature('bool_feat'); 531# gitweb_check_feature('bool_feat') or somecode; 532# 533# instead of 534# 535# my ($bool_feat) = gitweb_get_feature('bool_feat'); 536# (gitweb_get_feature('bool_feat'))[0] or somecode; 537# 538sub gitweb_check_feature { 539return(gitweb_get_feature(@_))[0]; 540} 541 542 543sub feature_bool { 544my$key=shift; 545my($val) = git_get_project_config($key,'--bool'); 546 547if(!defined$val) { 548return($_[0]); 549}elsif($valeq'true') { 550return(1); 551}elsif($valeq'false') { 552return(0); 553} 554} 555 556sub feature_snapshot { 557my(@fmts) =@_; 558 559my($val) = git_get_project_config('snapshot'); 560 561if($val) { 562@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 563} 564 565return@fmts; 566} 567 568sub feature_patches { 569my@val= (git_get_project_config('patches','--int')); 570 571if(@val) { 572return@val; 573} 574 575return($_[0]); 576} 577 578sub feature_avatar { 579my@val= (git_get_project_config('avatar')); 580 581return@val?@val:@_; 582} 583 584# checking HEAD file with -e is fragile if the repository was 585# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 586# and then pruned. 587sub check_head_link { 588my($dir) =@_; 589my$headfile="$dir/HEAD"; 590return((-e $headfile) || 591(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 592} 593 594sub check_export_ok { 595my($dir) =@_; 596return(check_head_link($dir) && 597(!$export_ok|| -e "$dir/$export_ok") && 598(!$export_auth_hook||$export_auth_hook->($dir))); 599} 600 601# process alternate names for backward compatibility 602# filter out unsupported (unknown) snapshot formats 603sub filter_snapshot_fmts { 604my@fmts=@_; 605 606@fmts=map{ 607exists$known_snapshot_format_aliases{$_} ? 608$known_snapshot_format_aliases{$_} :$_}@fmts; 609@fmts=grep{ 610exists$known_snapshot_formats{$_} && 611!$known_snapshot_formats{$_}{'disabled'}}@fmts; 612} 613 614# If it is set to code reference, it is code that it is to be run once per 615# request, allowing updating configurations that change with each request, 616# while running other code in config file only once. 617# 618# Otherwise, if it is false then gitweb would process config file only once; 619# if it is true then gitweb config would be run for each request. 620our$per_request_config=1; 621 622our($GITWEB_CONFIG,$GITWEB_CONFIG_SYSTEM); 623sub evaluate_gitweb_config { 624our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 625our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 626# die if there are errors parsing config file 627if(-e $GITWEB_CONFIG) { 628do$GITWEB_CONFIG; 629die$@if$@; 630}elsif(-e $GITWEB_CONFIG_SYSTEM) { 631do$GITWEB_CONFIG_SYSTEM; 632die$@if$@; 633} 634} 635 636# Get loadavg of system, to compare against $maxload. 637# Currently it requires '/proc/loadavg' present to get loadavg; 638# if it is not present it returns 0, which means no load checking. 639sub get_loadavg { 640if( -e '/proc/loadavg'){ 641open my$fd,'<','/proc/loadavg' 642orreturn0; 643my@load=split(/\s+/,scalar<$fd>); 644close$fd; 645 646# The first three columns measure CPU and IO utilization of the last one, 647# five, and 10 minute periods. The fourth column shows the number of 648# currently running processes and the total number of processes in the m/n 649# format. The last column displays the last process ID used. 650return$load[0] ||0; 651} 652# additional checks for load average should go here for things that don't export 653# /proc/loadavg 654 655return0; 656} 657 658# version of the core git binary 659our$git_version; 660sub evaluate_git_version { 661our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 662$number_of_git_cmds++; 663} 664 665sub check_loadavg { 666if(defined$maxload&& get_loadavg() >$maxload) { 667 die_error(503,"The load average on the server is too high"); 668} 669} 670 671# ====================================================================== 672# input validation and dispatch 673 674# input parameters can be collected from a variety of sources (presently, CGI 675# and PATH_INFO), so we define an %input_params hash that collects them all 676# together during validation: this allows subsequent uses (e.g. href()) to be 677# agnostic of the parameter origin 678 679our%input_params= (); 680 681# input parameters are stored with the long parameter name as key. This will 682# also be used in the href subroutine to convert parameters to their CGI 683# equivalent, and since the href() usage is the most frequent one, we store 684# the name -> CGI key mapping here, instead of the reverse. 685# 686# XXX: Warning: If you touch this, check the search form for updating, 687# too. 688 689our@cgi_param_mapping= ( 690 project =>"p", 691 action =>"a", 692 file_name =>"f", 693 file_parent =>"fp", 694 hash =>"h", 695 hash_parent =>"hp", 696 hash_base =>"hb", 697 hash_parent_base =>"hpb", 698 page =>"pg", 699 order =>"o", 700 searchtext =>"s", 701 searchtype =>"st", 702 snapshot_format =>"sf", 703 extra_options =>"opt", 704 search_use_regexp =>"sr", 705# this must be last entry (for manipulation from JavaScript) 706 javascript =>"js" 707); 708our%cgi_param_mapping=@cgi_param_mapping; 709 710# we will also need to know the possible actions, for validation 711our%actions= ( 712"blame"=> \&git_blame, 713"blame_incremental"=> \&git_blame_incremental, 714"blame_data"=> \&git_blame_data, 715"blobdiff"=> \&git_blobdiff, 716"blobdiff_plain"=> \&git_blobdiff_plain, 717"blob"=> \&git_blob, 718"blob_plain"=> \&git_blob_plain, 719"commitdiff"=> \&git_commitdiff, 720"commitdiff_plain"=> \&git_commitdiff_plain, 721"commit"=> \&git_commit, 722"forks"=> \&git_forks, 723"heads"=> \&git_heads, 724"history"=> \&git_history, 725"log"=> \&git_log, 726"patch"=> \&git_patch, 727"patches"=> \&git_patches, 728"remotes"=> \&git_remotes, 729"rss"=> \&git_rss, 730"atom"=> \&git_atom, 731"search"=> \&git_search, 732"search_help"=> \&git_search_help, 733"shortlog"=> \&git_shortlog, 734"summary"=> \&git_summary, 735"tag"=> \&git_tag, 736"tags"=> \&git_tags, 737"tree"=> \&git_tree, 738"snapshot"=> \&git_snapshot, 739"object"=> \&git_object, 740# those below don't need $project 741"opml"=> \&git_opml, 742"project_list"=> \&git_project_list, 743"project_index"=> \&git_project_index, 744); 745 746# finally, we have the hash of allowed extra_options for the commands that 747# allow them 748our%allowed_options= ( 749"--no-merges"=> [qw(rss atom log shortlog history)], 750); 751 752# fill %input_params with the CGI parameters. All values except for 'opt' 753# should be single values, but opt can be an array. We should probably 754# build an array of parameters that can be multi-valued, but since for the time 755# being it's only this one, we just single it out 756sub evaluate_query_params { 757our$cgi; 758 759while(my($name,$symbol) =each%cgi_param_mapping) { 760if($symboleq'opt') { 761$input_params{$name} = [$cgi->param($symbol) ]; 762}else{ 763$input_params{$name} =$cgi->param($symbol); 764} 765} 766} 767 768# now read PATH_INFO and update the parameter list for missing parameters 769sub evaluate_path_info { 770return ifdefined$input_params{'project'}; 771return if!$path_info; 772$path_info=~ s,^/+,,; 773return if!$path_info; 774 775# find which part of PATH_INFO is project 776my$project=$path_info; 777$project=~ s,/+$,,; 778while($project&& !check_head_link("$projectroot/$project")) { 779$project=~ s,/*[^/]*$,,; 780} 781return unless$project; 782$input_params{'project'} =$project; 783 784# do not change any parameters if an action is given using the query string 785return if$input_params{'action'}; 786$path_info=~ s,^\Q$project\E/*,,; 787 788# next, check if we have an action 789my$action=$path_info; 790$action=~ s,/.*$,,; 791if(exists$actions{$action}) { 792$path_info=~ s,^$action/*,,; 793$input_params{'action'} =$action; 794} 795 796# list of actions that want hash_base instead of hash, but can have no 797# pathname (f) parameter 798my@wants_base= ( 799'tree', 800'history', 801); 802 803# we want to catch, among others 804# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 805my($parentrefname,$parentpathname,$refname,$pathname) = 806($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?([^:]+?)?(?::(.+))?$/); 807 808# first, analyze the 'current' part 809if(defined$pathname) { 810# we got "branch:filename" or "branch:dir/" 811# we could use git_get_type(branch:pathname), but: 812# - it needs $git_dir 813# - it does a git() call 814# - the convention of terminating directories with a slash 815# makes it superfluous 816# - embedding the action in the PATH_INFO would make it even 817# more superfluous 818$pathname=~ s,^/+,,; 819if(!$pathname||substr($pathname, -1)eq"/") { 820$input_params{'action'} ||="tree"; 821$pathname=~ s,/$,,; 822}else{ 823# the default action depends on whether we had parent info 824# or not 825if($parentrefname) { 826$input_params{'action'} ||="blobdiff_plain"; 827}else{ 828$input_params{'action'} ||="blob_plain"; 829} 830} 831$input_params{'hash_base'} ||=$refname; 832$input_params{'file_name'} ||=$pathname; 833}elsif(defined$refname) { 834# we got "branch". In this case we have to choose if we have to 835# set hash or hash_base. 836# 837# Most of the actions without a pathname only want hash to be 838# set, except for the ones specified in @wants_base that want 839# hash_base instead. It should also be noted that hand-crafted 840# links having 'history' as an action and no pathname or hash 841# set will fail, but that happens regardless of PATH_INFO. 842if(defined$parentrefname) { 843# if there is parent let the default be 'shortlog' action 844# (for http://git.example.com/repo.git/A..B links); if there 845# is no parent, dispatch will detect type of object and set 846# action appropriately if required (if action is not set) 847$input_params{'action'} ||="shortlog"; 848} 849if($input_params{'action'} && 850grep{$_eq$input_params{'action'} }@wants_base) { 851$input_params{'hash_base'} ||=$refname; 852}else{ 853$input_params{'hash'} ||=$refname; 854} 855} 856 857# next, handle the 'parent' part, if present 858if(defined$parentrefname) { 859# a missing pathspec defaults to the 'current' filename, allowing e.g. 860# someproject/blobdiff/oldrev..newrev:/filename 861if($parentpathname) { 862$parentpathname=~ s,^/+,,; 863$parentpathname=~ s,/$,,; 864$input_params{'file_parent'} ||=$parentpathname; 865}else{ 866$input_params{'file_parent'} ||=$input_params{'file_name'}; 867} 868# we assume that hash_parent_base is wanted if a path was specified, 869# or if the action wants hash_base instead of hash 870if(defined$input_params{'file_parent'} || 871grep{$_eq$input_params{'action'} }@wants_base) { 872$input_params{'hash_parent_base'} ||=$parentrefname; 873}else{ 874$input_params{'hash_parent'} ||=$parentrefname; 875} 876} 877 878# for the snapshot action, we allow URLs in the form 879# $project/snapshot/$hash.ext 880# where .ext determines the snapshot and gets removed from the 881# passed $refname to provide the $hash. 882# 883# To be able to tell that $refname includes the format extension, we 884# require the following two conditions to be satisfied: 885# - the hash input parameter MUST have been set from the $refname part 886# of the URL (i.e. they must be equal) 887# - the snapshot format MUST NOT have been defined already (e.g. from 888# CGI parameter sf) 889# It's also useless to try any matching unless $refname has a dot, 890# so we check for that too 891if(defined$input_params{'action'} && 892$input_params{'action'}eq'snapshot'&& 893defined$refname&&index($refname,'.') != -1&& 894$refnameeq$input_params{'hash'} && 895!defined$input_params{'snapshot_format'}) { 896# We loop over the known snapshot formats, checking for 897# extensions. Allowed extensions are both the defined suffix 898# (which includes the initial dot already) and the snapshot 899# format key itself, with a prepended dot 900while(my($fmt,$opt) =each%known_snapshot_formats) { 901my$hash=$refname; 902unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 903next; 904} 905my$sfx=$1; 906# a valid suffix was found, so set the snapshot format 907# and reset the hash parameter 908$input_params{'snapshot_format'} =$fmt; 909$input_params{'hash'} =$hash; 910# we also set the format suffix to the one requested 911# in the URL: this way a request for e.g. .tgz returns 912# a .tgz instead of a .tar.gz 913$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 914last; 915} 916} 917} 918 919our($action,$project,$file_name,$file_parent,$hash,$hash_parent,$hash_base, 920$hash_parent_base,@extra_options,$page,$searchtype,$search_use_regexp, 921$searchtext,$search_regexp); 922sub evaluate_and_validate_params { 923our$action=$input_params{'action'}; 924if(defined$action) { 925if(!validate_action($action)) { 926 die_error(400,"Invalid action parameter"); 927} 928} 929 930# parameters which are pathnames 931our$project=$input_params{'project'}; 932if(defined$project) { 933if(!validate_project($project)) { 934undef$project; 935 die_error(404,"No such project"); 936} 937} 938 939our$file_name=$input_params{'file_name'}; 940if(defined$file_name) { 941if(!validate_pathname($file_name)) { 942 die_error(400,"Invalid file parameter"); 943} 944} 945 946our$file_parent=$input_params{'file_parent'}; 947if(defined$file_parent) { 948if(!validate_pathname($file_parent)) { 949 die_error(400,"Invalid file parent parameter"); 950} 951} 952 953# parameters which are refnames 954our$hash=$input_params{'hash'}; 955if(defined$hash) { 956if(!validate_refname($hash)) { 957 die_error(400,"Invalid hash parameter"); 958} 959} 960 961our$hash_parent=$input_params{'hash_parent'}; 962if(defined$hash_parent) { 963if(!validate_refname($hash_parent)) { 964 die_error(400,"Invalid hash parent parameter"); 965} 966} 967 968our$hash_base=$input_params{'hash_base'}; 969if(defined$hash_base) { 970if(!validate_refname($hash_base)) { 971 die_error(400,"Invalid hash base parameter"); 972} 973} 974 975our@extra_options= @{$input_params{'extra_options'}}; 976# @extra_options is always defined, since it can only be (currently) set from 977# CGI, and $cgi->param() returns the empty array in array context if the param 978# is not set 979foreachmy$opt(@extra_options) { 980if(not exists$allowed_options{$opt}) { 981 die_error(400,"Invalid option parameter"); 982} 983if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 984 die_error(400,"Invalid option parameter for this action"); 985} 986} 987 988our$hash_parent_base=$input_params{'hash_parent_base'}; 989if(defined$hash_parent_base) { 990if(!validate_refname($hash_parent_base)) { 991 die_error(400,"Invalid hash parent base parameter"); 992} 993} 994 995# other parameters 996our$page=$input_params{'page'}; 997if(defined$page) { 998if($page=~m/[^0-9]/) { 999 die_error(400,"Invalid page parameter");1000}1001}10021003our$searchtype=$input_params{'searchtype'};1004if(defined$searchtype) {1005if($searchtype=~m/[^a-z]/) {1006 die_error(400,"Invalid searchtype parameter");1007}1008}10091010our$search_use_regexp=$input_params{'search_use_regexp'};10111012our$searchtext=$input_params{'searchtext'};1013our$search_regexp;1014if(defined$searchtext) {1015if(length($searchtext) <2) {1016 die_error(403,"At least two characters are required for search parameter");1017}1018$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext;1019}1020}10211022# path to the current git repository1023our$git_dir;1024sub evaluate_git_dir {1025our$git_dir="$projectroot/$project"if$project;1026}10271028our(@snapshot_fmts,$git_avatar);1029sub configure_gitweb_features {1030# list of supported snapshot formats1031our@snapshot_fmts= gitweb_get_feature('snapshot');1032@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts);10331034# check that the avatar feature is set to a known provider name,1035# and for each provider check if the dependencies are satisfied.1036# if the provider name is invalid or the dependencies are not met,1037# reset $git_avatar to the empty string.1038our($git_avatar) = gitweb_get_feature('avatar');1039if($git_avatareq'gravatar') {1040$git_avatar=''unless(eval{require Digest::MD5;1; });1041}elsif($git_avatareq'picon') {1042# no dependencies1043}else{1044$git_avatar='';1045}1046}10471048# custom error handler: 'die <message>' is Internal Server Error1049sub handle_errors_html {1050my$msg=shift;# it is already HTML escaped10511052# to avoid infinite loop where error occurs in die_error,1053# change handler to default handler, disabling handle_errors_html1054 set_message("Error occured when inside die_error:\n$msg");10551056# you cannot jump out of die_error when called as error handler;1057# the subroutine set via CGI::Carp::set_message is called _after_1058# HTTP headers are already written, so it cannot write them itself1059 die_error(undef,undef,$msg, -error_handler =>1, -no_http_header =>1);1060}1061set_message(\&handle_errors_html);10621063# dispatch1064sub dispatch {1065if(!defined$action) {1066if(defined$hash) {1067$action= git_get_type($hash);1068}elsif(defined$hash_base&&defined$file_name) {1069$action= git_get_type("$hash_base:$file_name");1070}elsif(defined$project) {1071$action='summary';1072}else{1073$action='project_list';1074}1075}1076if(!defined($actions{$action})) {1077 die_error(400,"Unknown action");1078}1079if($action!~m/^(?:opml|project_list|project_index)$/&&1080!$project) {1081 die_error(400,"Project needed");1082}1083$actions{$action}->();1084}10851086sub reset_timer {1087our$t0= [ gettimeofday() ]1088ifdefined$t0;1089our$number_of_git_cmds=0;1090}10911092our$first_request=1;1093sub run_request {1094 reset_timer();10951096 evaluate_uri();1097if($first_request) {1098 evaluate_gitweb_config();1099 evaluate_git_version();1100}1101if($per_request_config) {1102if(ref($per_request_config)eq'CODE') {1103$per_request_config->();1104}elsif(!$first_request) {1105 evaluate_gitweb_config();1106}1107}1108 check_loadavg();11091110# $projectroot and $projects_list might be set in gitweb config file1111$projects_list||=$projectroot;11121113 evaluate_query_params();1114 evaluate_path_info();1115 evaluate_and_validate_params();1116 evaluate_git_dir();11171118 configure_gitweb_features();11191120 dispatch();1121}11221123our$is_last_request=sub{1};1124our($pre_dispatch_hook,$post_dispatch_hook,$pre_listen_hook);1125our$CGI='CGI';1126our$cgi;1127sub configure_as_fcgi {1128require CGI::Fast;1129our$CGI='CGI::Fast';11301131my$request_number=0;1132# let each child service 100 requests1133our$is_last_request=sub{ ++$request_number>100};1134}1135sub evaluate_argv {1136my$script_name=$ENV{'SCRIPT_NAME'} ||$ENV{'SCRIPT_FILENAME'} || __FILE__;1137 configure_as_fcgi()1138if$script_name=~/\.fcgi$/;11391140return unless(@ARGV);11411142require Getopt::Long;1143 Getopt::Long::GetOptions(1144'fastcgi|fcgi|f'=> \&configure_as_fcgi,1145'nproc|n=i'=>sub{1146my($arg,$val) =@_;1147return unlesseval{require FCGI::ProcManager;1; };1148my$proc_manager= FCGI::ProcManager->new({1149 n_processes =>$val,1150});1151our$pre_listen_hook=sub{$proc_manager->pm_manage() };1152our$pre_dispatch_hook=sub{$proc_manager->pm_pre_dispatch() };1153our$post_dispatch_hook=sub{$proc_manager->pm_post_dispatch() };1154},1155);1156}11571158sub run {1159 evaluate_argv();11601161$first_request=1;1162$pre_listen_hook->()1163if$pre_listen_hook;11641165 REQUEST:1166while($cgi=$CGI->new()) {1167$pre_dispatch_hook->()1168if$pre_dispatch_hook;11691170 run_request();11711172$post_dispatch_hook->()1173if$post_dispatch_hook;1174$first_request=0;11751176last REQUEST if($is_last_request->());1177}11781179 DONE_GITWEB:11801;1181}11821183run();11841185if(defined caller) {1186# wrapped in a subroutine processing requests,1187# e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI1188return;1189}else{1190# pure CGI script, serving single request1191exit;1192}11931194## ======================================================================1195## action links11961197# possible values of extra options1198# -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)1199# -replay => 1 - start from a current view (replay with modifications)1200# -path_info => 0|1 - don't use/use path_info URL (if possible)1201sub href {1202my%params=@_;1203# default is to use -absolute url() i.e. $my_uri1204my$href=$params{-full} ?$my_url:$my_uri;12051206$params{'project'} =$projectunlessexists$params{'project'};12071208if($params{-replay}) {1209while(my($name,$symbol) =each%cgi_param_mapping) {1210if(!exists$params{$name}) {1211$params{$name} =$input_params{$name};1212}1213}1214}12151216my$use_pathinfo= gitweb_check_feature('pathinfo');1217if(defined$params{'project'} &&1218(exists$params{-path_info} ?$params{-path_info} :$use_pathinfo)) {1219# try to put as many parameters as possible in PATH_INFO:1220# - project name1221# - action1222# - hash_parent or hash_parent_base:/file_parent1223# - hash or hash_base:/filename1224# - the snapshot_format as an appropriate suffix12251226# When the script is the root DirectoryIndex for the domain,1227# $href here would be something like http://gitweb.example.com/1228# Thus, we strip any trailing / from $href, to spare us double1229# slashes in the final URL1230$href=~ s,/$,,;12311232# Then add the project name, if present1233$href.="/".esc_url($params{'project'});1234delete$params{'project'};12351236# since we destructively absorb parameters, we keep this1237# boolean that remembers if we're handling a snapshot1238my$is_snapshot=$params{'action'}eq'snapshot';12391240# Summary just uses the project path URL, any other action is1241# added to the URL1242if(defined$params{'action'}) {1243$href.="/".esc_url($params{'action'})unless$params{'action'}eq'summary';1244delete$params{'action'};1245}12461247# Next, we put hash_parent_base:/file_parent..hash_base:/file_name,1248# stripping nonexistent or useless pieces1249$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'}1250||$params{'hash_parent'} ||$params{'hash'});1251if(defined$params{'hash_base'}) {1252if(defined$params{'hash_parent_base'}) {1253$href.= esc_url($params{'hash_parent_base'});1254# skip the file_parent if it's the same as the file_name1255if(defined$params{'file_parent'}) {1256if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) {1257delete$params{'file_parent'};1258}elsif($params{'file_parent'} !~/\.\./) {1259$href.=":/".esc_url($params{'file_parent'});1260delete$params{'file_parent'};1261}1262}1263$href.="..";1264delete$params{'hash_parent'};1265delete$params{'hash_parent_base'};1266}elsif(defined$params{'hash_parent'}) {1267$href.= esc_url($params{'hash_parent'})."..";1268delete$params{'hash_parent'};1269}12701271$href.= esc_url($params{'hash_base'});1272if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) {1273$href.=":/".esc_url($params{'file_name'});1274delete$params{'file_name'};1275}1276delete$params{'hash'};1277delete$params{'hash_base'};1278}elsif(defined$params{'hash'}) {1279$href.= esc_url($params{'hash'});1280delete$params{'hash'};1281}12821283# If the action was a snapshot, we can absorb the1284# snapshot_format parameter too1285if($is_snapshot) {1286my$fmt=$params{'snapshot_format'};1287# snapshot_format should always be defined when href()1288# is called, but just in case some code forgets, we1289# fall back to the default1290$fmt||=$snapshot_fmts[0];1291$href.=$known_snapshot_formats{$fmt}{'suffix'};1292delete$params{'snapshot_format'};1293}1294}12951296# now encode the parameters explicitly1297my@result= ();1298for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1299my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1300if(defined$params{$name}) {1301if(ref($params{$name})eq"ARRAY") {1302foreachmy$par(@{$params{$name}}) {1303push@result,$symbol."=". esc_param($par);1304}1305}else{1306push@result,$symbol."=". esc_param($params{$name});1307}1308}1309}1310$href.="?".join(';',@result)ifscalar@result;13111312return$href;1313}131413151316## ======================================================================1317## validation, quoting/unquoting and escaping13181319sub validate_action {1320my$input=shift||returnundef;1321returnundefunlessexists$actions{$input};1322return$input;1323}13241325sub validate_project {1326my$input=shift||returnundef;1327if(!validate_pathname($input) ||1328!(-d "$projectroot/$input") ||1329!check_export_ok("$projectroot/$input") ||1330($strict_export&& !project_in_list($input))) {1331returnundef;1332}else{1333return$input;1334}1335}13361337sub validate_pathname {1338my$input=shift||returnundef;13391340# no '.' or '..' as elements of path, i.e. no '.' nor '..'1341# at the beginning, at the end, and between slashes.1342# also this catches doubled slashes1343if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1344returnundef;1345}1346# no null characters1347if($input=~m!\0!) {1348returnundef;1349}1350return$input;1351}13521353sub validate_refname {1354my$input=shift||returnundef;13551356# textual hashes are O.K.1357if($input=~m/^[0-9a-fA-F]{40}$/) {1358return$input;1359}1360# it must be correct pathname1361$input= validate_pathname($input)1362orreturnundef;1363# restrictions on ref name according to git-check-ref-format1364if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1365returnundef;1366}1367return$input;1368}13691370# decode sequences of octets in utf8 into Perl's internal form,1371# which is utf-8 with utf8 flag set if needed. gitweb writes out1372# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1373sub to_utf8 {1374my$str=shift;1375returnundefunlessdefined$str;1376if(utf8::valid($str)) {1377 utf8::decode($str);1378return$str;1379}else{1380return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1381}1382}13831384# quote unsafe chars, but keep the slash, even when it's not1385# correct, but quoted slashes look too horrible in bookmarks1386sub esc_param {1387my$str=shift;1388returnundefunlessdefined$str;1389$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1390$str=~s/ /\+/g;1391return$str;1392}13931394# quote unsafe chars in whole URL, so some characters cannot be quoted1395sub esc_url {1396my$str=shift;1397returnundefunlessdefined$str;1398$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg;1399$str=~s/ /\+/g;1400return$str;1401}14021403# quote unsafe characters in HTML attributes1404sub esc_attr {14051406# for XHTML conformance escaping '"' to '"' is not enough1407return esc_html(@_);1408}14091410# replace invalid utf8 character with SUBSTITUTION sequence1411sub esc_html {1412my$str=shift;1413my%opts=@_;14141415returnundefunlessdefined$str;14161417$str= to_utf8($str);1418$str=$cgi->escapeHTML($str);1419if($opts{'-nbsp'}) {1420$str=~s/ / /g;1421}1422$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1423return$str;1424}14251426# quote control characters and escape filename to HTML1427sub esc_path {1428my$str=shift;1429my%opts=@_;14301431returnundefunlessdefined$str;14321433$str= to_utf8($str);1434$str=$cgi->escapeHTML($str);1435if($opts{'-nbsp'}) {1436$str=~s/ / /g;1437}1438$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1439return$str;1440}14411442# Make control characters "printable", using character escape codes (CEC)1443sub quot_cec {1444my$cntrl=shift;1445my%opts=@_;1446my%es= (# character escape codes, aka escape sequences1447"\t"=>'\t',# tab (HT)1448"\n"=>'\n',# line feed (LF)1449"\r"=>'\r',# carrige return (CR)1450"\f"=>'\f',# form feed (FF)1451"\b"=>'\b',# backspace (BS)1452"\a"=>'\a',# alarm (bell) (BEL)1453"\e"=>'\e',# escape (ESC)1454"\013"=>'\v',# vertical tab (VT)1455"\000"=>'\0',# nul character (NUL)1456);1457my$chr= ( (exists$es{$cntrl})1458?$es{$cntrl}1459:sprintf('\%2x',ord($cntrl)) );1460if($opts{-nohtml}) {1461return$chr;1462}else{1463return"<span class=\"cntrl\">$chr</span>";1464}1465}14661467# Alternatively use unicode control pictures codepoints,1468# Unicode "printable representation" (PR)1469sub quot_upr {1470my$cntrl=shift;1471my%opts=@_;14721473my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1474if($opts{-nohtml}) {1475return$chr;1476}else{1477return"<span class=\"cntrl\">$chr</span>";1478}1479}14801481# git may return quoted and escaped filenames1482sub unquote {1483my$str=shift;14841485sub unq {1486my$seq=shift;1487my%es= (# character escape codes, aka escape sequences1488't'=>"\t",# tab (HT, TAB)1489'n'=>"\n",# newline (NL)1490'r'=>"\r",# return (CR)1491'f'=>"\f",# form feed (FF)1492'b'=>"\b",# backspace (BS)1493'a'=>"\a",# alarm (bell) (BEL)1494'e'=>"\e",# escape (ESC)1495'v'=>"\013",# vertical tab (VT)1496);14971498if($seq=~m/^[0-7]{1,3}$/) {1499# octal char sequence1500returnchr(oct($seq));1501}elsif(exists$es{$seq}) {1502# C escape sequence, aka character escape code1503return$es{$seq};1504}1505# quoted ordinary character1506return$seq;1507}15081509if($str=~m/^"(.*)"$/) {1510# needs unquoting1511$str=$1;1512$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1513}1514return$str;1515}15161517# escape tabs (convert tabs to spaces)1518sub untabify {1519my$line=shift;15201521while((my$pos=index($line,"\t")) != -1) {1522if(my$count= (8- ($pos%8))) {1523my$spaces=' ' x $count;1524$line=~s/\t/$spaces/;1525}1526}15271528return$line;1529}15301531sub project_in_list {1532my$project=shift;1533my@list= git_get_projects_list();1534return@list&&scalar(grep{$_->{'path'}eq$project}@list);1535}15361537## ----------------------------------------------------------------------1538## HTML aware string manipulation15391540# Try to chop given string on a word boundary between position1541# $len and $len+$add_len. If there is no word boundary there,1542# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1543# (marking chopped part) would be longer than given string.1544sub chop_str {1545my$str=shift;1546my$len=shift;1547my$add_len=shift||10;1548my$where=shift||'right';# 'left' | 'center' | 'right'15491550# Make sure perl knows it is utf8 encoded so we don't1551# cut in the middle of a utf8 multibyte char.1552$str= to_utf8($str);15531554# allow only $len chars, but don't cut a word if it would fit in $add_len1555# if it doesn't fit, cut it if it's still longer than the dots we would add1556# remove chopped character entities entirely15571558# when chopping in the middle, distribute $len into left and right part1559# return early if chopping wouldn't make string shorter1560if($whereeq'center') {1561return$strif($len+5>=length($str));# filler is length 51562$len=int($len/2);1563}else{1564return$strif($len+4>=length($str));# filler is length 41565}15661567# regexps: ending and beginning with word part up to $add_len1568my$endre=qr/.{$len}\w{0,$add_len}/;1569my$begre=qr/\w{0,$add_len}.{$len}/;15701571if($whereeq'left') {1572$str=~m/^(.*?)($begre)$/;1573my($lead,$body) = ($1,$2);1574if(length($lead) >4) {1575$lead=" ...";1576}1577return"$lead$body";15781579}elsif($whereeq'center') {1580$str=~m/^($endre)(.*)$/;1581my($left,$str) = ($1,$2);1582$str=~m/^(.*?)($begre)$/;1583my($mid,$right) = ($1,$2);1584if(length($mid) >5) {1585$mid=" ... ";1586}1587return"$left$mid$right";15881589}else{1590$str=~m/^($endre)(.*)$/;1591my$body=$1;1592my$tail=$2;1593if(length($tail) >4) {1594$tail="... ";1595}1596return"$body$tail";1597}1598}15991600# takes the same arguments as chop_str, but also wraps a <span> around the1601# result with a title attribute if it does get chopped. Additionally, the1602# string is HTML-escaped.1603sub chop_and_escape_str {1604my($str) =@_;16051606my$chopped= chop_str(@_);1607if($choppedeq$str) {1608return esc_html($chopped);1609}else{1610$str=~s/[[:cntrl:]]/?/g;1611return$cgi->span({-title=>$str}, esc_html($chopped));1612}1613}16141615## ----------------------------------------------------------------------1616## functions returning short strings16171618# CSS class for given age value (in seconds)1619sub age_class {1620my$age=shift;16211622if(!defined$age) {1623return"noage";1624}elsif($age<60*60*2) {1625return"age0";1626}elsif($age<60*60*24*2) {1627return"age1";1628}else{1629return"age2";1630}1631}16321633# convert age in seconds to "nn units ago" string1634sub age_string {1635my$age=shift;1636my$age_str;16371638if($age>60*60*24*365*2) {1639$age_str= (int$age/60/60/24/365);1640$age_str.=" years ago";1641}elsif($age>60*60*24*(365/12)*2) {1642$age_str=int$age/60/60/24/(365/12);1643$age_str.=" months ago";1644}elsif($age>60*60*24*7*2) {1645$age_str=int$age/60/60/24/7;1646$age_str.=" weeks ago";1647}elsif($age>60*60*24*2) {1648$age_str=int$age/60/60/24;1649$age_str.=" days ago";1650}elsif($age>60*60*2) {1651$age_str=int$age/60/60;1652$age_str.=" hours ago";1653}elsif($age>60*2) {1654$age_str=int$age/60;1655$age_str.=" min ago";1656}elsif($age>2) {1657$age_str=int$age;1658$age_str.=" sec ago";1659}else{1660$age_str.=" right now";1661}1662return$age_str;1663}16641665useconstant{1666 S_IFINVALID =>0030000,1667 S_IFGITLINK =>0160000,1668};16691670# submodule/subproject, a commit object reference1671sub S_ISGITLINK {1672my$mode=shift;16731674return(($mode& S_IFMT) == S_IFGITLINK)1675}16761677# convert file mode in octal to symbolic file mode string1678sub mode_str {1679my$mode=oct shift;16801681if(S_ISGITLINK($mode)) {1682return'm---------';1683}elsif(S_ISDIR($mode& S_IFMT)) {1684return'drwxr-xr-x';1685}elsif(S_ISLNK($mode)) {1686return'lrwxrwxrwx';1687}elsif(S_ISREG($mode)) {1688# git cares only about the executable bit1689if($mode& S_IXUSR) {1690return'-rwxr-xr-x';1691}else{1692return'-rw-r--r--';1693};1694}else{1695return'----------';1696}1697}16981699# convert file mode in octal to file type string1700sub file_type {1701my$mode=shift;17021703if($mode!~m/^[0-7]+$/) {1704return$mode;1705}else{1706$mode=oct$mode;1707}17081709if(S_ISGITLINK($mode)) {1710return"submodule";1711}elsif(S_ISDIR($mode& S_IFMT)) {1712return"directory";1713}elsif(S_ISLNK($mode)) {1714return"symlink";1715}elsif(S_ISREG($mode)) {1716return"file";1717}else{1718return"unknown";1719}1720}17211722# convert file mode in octal to file type description string1723sub file_type_long {1724my$mode=shift;17251726if($mode!~m/^[0-7]+$/) {1727return$mode;1728}else{1729$mode=oct$mode;1730}17311732if(S_ISGITLINK($mode)) {1733return"submodule";1734}elsif(S_ISDIR($mode& S_IFMT)) {1735return"directory";1736}elsif(S_ISLNK($mode)) {1737return"symlink";1738}elsif(S_ISREG($mode)) {1739if($mode& S_IXUSR) {1740return"executable";1741}else{1742return"file";1743};1744}else{1745return"unknown";1746}1747}174817491750## ----------------------------------------------------------------------1751## functions returning short HTML fragments, or transforming HTML fragments1752## which don't belong to other sections17531754# format line of commit message.1755sub format_log_line_html {1756my$line=shift;17571758$line= esc_html($line, -nbsp=>1);1759$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1760$cgi->a({-href => href(action=>"object", hash=>$1),1761-class=>"text"},$1);1762}eg;17631764return$line;1765}17661767# format marker of refs pointing to given object17681769# the destination action is chosen based on object type and current context:1770# - for annotated tags, we choose the tag view unless it's the current view1771# already, in which case we go to shortlog view1772# - for other refs, we keep the current view if we're in history, shortlog or1773# log view, and select shortlog otherwise1774sub format_ref_marker {1775my($refs,$id) =@_;1776my$markers='';17771778if(defined$refs->{$id}) {1779foreachmy$ref(@{$refs->{$id}}) {1780# this code exploits the fact that non-lightweight tags are the1781# only indirect objects, and that they are the only objects for which1782# we want to use tag instead of shortlog as action1783my($type,$name) =qw();1784my$indirect= ($ref=~s/\^\{\}$//);1785# e.g. tags/v2.6.11 or heads/next1786if($ref=~m!^(.*?)s?/(.*)$!) {1787$type=$1;1788$name=$2;1789}else{1790$type="ref";1791$name=$ref;1792}17931794my$class=$type;1795$class.=" indirect"if$indirect;17961797my$dest_action="shortlog";17981799if($indirect) {1800$dest_action="tag"unless$actioneq"tag";1801}elsif($action=~/^(history|(short)?log)$/) {1802$dest_action=$action;1803}18041805my$dest="";1806$dest.="refs/"unless$ref=~ m!^refs/!;1807$dest.=$ref;18081809my$link=$cgi->a({1810-href => href(1811 action=>$dest_action,1812 hash=>$dest1813)},$name);18141815$markers.=" <span class=\"".esc_attr($class)."\"title=\"".esc_attr($ref)."\">".1816$link."</span>";1817}1818}18191820if($markers) {1821return' <span class="refs">'.$markers.'</span>';1822}else{1823return"";1824}1825}18261827# format, perhaps shortened and with markers, title line1828sub format_subject_html {1829my($long,$short,$href,$extra) =@_;1830$extra=''unlessdefined($extra);18311832if(length($short) <length($long)) {1833$long=~s/[[:cntrl:]]/?/g;1834return$cgi->a({-href =>$href, -class=>"list subject",1835-title => to_utf8($long)},1836 esc_html($short)) .$extra;1837}else{1838return$cgi->a({-href =>$href, -class=>"list subject"},1839 esc_html($long)) .$extra;1840}1841}18421843# Rather than recomputing the url for an email multiple times, we cache it1844# after the first hit. This gives a visible benefit in views where the avatar1845# for the same email is used repeatedly (e.g. shortlog).1846# The cache is shared by all avatar engines (currently gravatar only), which1847# are free to use it as preferred. Since only one avatar engine is used for any1848# given page, there's no risk for cache conflicts.1849our%avatar_cache= ();18501851# Compute the picon url for a given email, by using the picon search service over at1852# http://www.cs.indiana.edu/picons/search.html1853sub picon_url {1854my$email=lc shift;1855if(!$avatar_cache{$email}) {1856my($user,$domain) =split('@',$email);1857$avatar_cache{$email} =1858"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".1859"$domain/$user/".1860"users+domains+unknown/up/single";1861}1862return$avatar_cache{$email};1863}18641865# Compute the gravatar url for a given email, if it's not in the cache already.1866# Gravatar stores only the part of the URL before the size, since that's the1867# one computationally more expensive. This also allows reuse of the cache for1868# different sizes (for this particular engine).1869sub gravatar_url {1870my$email=lc shift;1871my$size=shift;1872$avatar_cache{$email} ||=1873"http://www.gravatar.com/avatar/".1874 Digest::MD5::md5_hex($email) ."?s=";1875return$avatar_cache{$email} .$size;1876}18771878# Insert an avatar for the given $email at the given $size if the feature1879# is enabled.1880sub git_get_avatar {1881my($email,%opts) =@_;1882my$pre_white= ($opts{-pad_before} ?" ":"");1883my$post_white= ($opts{-pad_after} ?" ":"");1884$opts{-size} ||='default';1885my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};1886my$url="";1887if($git_avatareq'gravatar') {1888$url= gravatar_url($email,$size);1889}elsif($git_avatareq'picon') {1890$url= picon_url($email);1891}1892# Other providers can be added by extending the if chain, defining $url1893# as needed. If no variant puts something in $url, we assume avatars1894# are completely disabled/unavailable.1895if($url) {1896return$pre_white.1897"<img width=\"$size\"".1898"class=\"avatar\"".1899"src=\"".esc_url($url)."\"".1900"alt=\"\"".1901"/>".$post_white;1902}else{1903return"";1904}1905}19061907sub format_search_author {1908my($author,$searchtype,$displaytext) =@_;1909my$have_search= gitweb_check_feature('search');19101911if($have_search) {1912my$performed="";1913if($searchtypeeq'author') {1914$performed="authored";1915}elsif($searchtypeeq'committer') {1916$performed="committed";1917}19181919return$cgi->a({-href => href(action=>"search", hash=>$hash,1920 searchtext=>$author,1921 searchtype=>$searchtype),class=>"list",1922 title=>"Search for commits$performedby$author"},1923$displaytext);19241925}else{1926return$displaytext;1927}1928}19291930# format the author name of the given commit with the given tag1931# the author name is chopped and escaped according to the other1932# optional parameters (see chop_str).1933sub format_author_html {1934my$tag=shift;1935my$co=shift;1936my$author= chop_and_escape_str($co->{'author_name'},@_);1937return"<$tagclass=\"author\">".1938 format_search_author($co->{'author_name'},"author",1939 git_get_avatar($co->{'author_email'}, -pad_after =>1) .1940$author) .1941"</$tag>";1942}19431944# format git diff header line, i.e. "diff --(git|combined|cc) ..."1945sub format_git_diff_header_line {1946my$line=shift;1947my$diffinfo=shift;1948my($from,$to) =@_;19491950if($diffinfo->{'nparents'}) {1951# combined diff1952$line=~s!^(diff (.*?) )"?.*$!$1!;1953if($to->{'href'}) {1954$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1955 esc_path($to->{'file'}));1956}else{# file was deleted (no href)1957$line.= esc_path($to->{'file'});1958}1959}else{1960# "ordinary" diff1961$line=~s!^(diff (.*?) )"?a/.*$!$1!;1962if($from->{'href'}) {1963$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1964'a/'. esc_path($from->{'file'}));1965}else{# file was added (no href)1966$line.='a/'. esc_path($from->{'file'});1967}1968$line.=' ';1969if($to->{'href'}) {1970$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1971'b/'. esc_path($to->{'file'}));1972}else{# file was deleted1973$line.='b/'. esc_path($to->{'file'});1974}1975}19761977return"<div class=\"diff header\">$line</div>\n";1978}19791980# format extended diff header line, before patch itself1981sub format_extended_diff_header_line {1982my$line=shift;1983my$diffinfo=shift;1984my($from,$to) =@_;19851986# match <path>1987if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1988$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1989 esc_path($from->{'file'}));1990}1991if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1992$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1993 esc_path($to->{'file'}));1994}1995# match single <mode>1996if($line=~m/\s(\d{6})$/) {1997$line.='<span class="info"> ('.1998 file_type_long($1) .1999')</span>';2000}2001# match <hash>2002if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {2003# can match only for combined diff2004$line='index ';2005for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2006if($from->{'href'}[$i]) {2007$line.=$cgi->a({-href=>$from->{'href'}[$i],2008-class=>"hash"},2009substr($diffinfo->{'from_id'}[$i],0,7));2010}else{2011$line.='0' x 7;2012}2013# separator2014$line.=','if($i<$diffinfo->{'nparents'} -1);2015}2016$line.='..';2017if($to->{'href'}) {2018$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2019substr($diffinfo->{'to_id'},0,7));2020}else{2021$line.='0' x 7;2022}20232024}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {2025# can match only for ordinary diff2026my($from_link,$to_link);2027if($from->{'href'}) {2028$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},2029substr($diffinfo->{'from_id'},0,7));2030}else{2031$from_link='0' x 7;2032}2033if($to->{'href'}) {2034$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2035substr($diffinfo->{'to_id'},0,7));2036}else{2037$to_link='0' x 7;2038}2039my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});2040$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;2041}20422043return$line."<br/>\n";2044}20452046# format from-file/to-file diff header2047sub format_diff_from_to_header {2048my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;2049my$line;2050my$result='';20512052$line=$from_line;2053#assert($line =~ m/^---/) if DEBUG;2054# no extra formatting for "^--- /dev/null"2055if(!$diffinfo->{'nparents'}) {2056# ordinary (single parent) diff2057if($line=~m!^--- "?a/!) {2058if($from->{'href'}) {2059$line='--- a/'.2060$cgi->a({-href=>$from->{'href'}, -class=>"path"},2061 esc_path($from->{'file'}));2062}else{2063$line='--- a/'.2064 esc_path($from->{'file'});2065}2066}2067$result.= qq!<div class="diff from_file">$line</div>\n!;20682069}else{2070# combined diff (merge commit)2071for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2072if($from->{'href'}[$i]) {2073$line='--- '.2074$cgi->a({-href=>href(action=>"blobdiff",2075 hash_parent=>$diffinfo->{'from_id'}[$i],2076 hash_parent_base=>$parents[$i],2077 file_parent=>$from->{'file'}[$i],2078 hash=>$diffinfo->{'to_id'},2079 hash_base=>$hash,2080 file_name=>$to->{'file'}),2081-class=>"path",2082-title=>"diff". ($i+1)},2083$i+1) .2084'/'.2085$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},2086 esc_path($from->{'file'}[$i]));2087}else{2088$line='--- /dev/null';2089}2090$result.= qq!<div class="diff from_file">$line</div>\n!;2091}2092}20932094$line=$to_line;2095#assert($line =~ m/^\+\+\+/) if DEBUG;2096# no extra formatting for "^+++ /dev/null"2097if($line=~m!^\+\+\+ "?b/!) {2098if($to->{'href'}) {2099$line='+++ b/'.2100$cgi->a({-href=>$to->{'href'}, -class=>"path"},2101 esc_path($to->{'file'}));2102}else{2103$line='+++ b/'.2104 esc_path($to->{'file'});2105}2106}2107$result.= qq!<div class="diff to_file">$line</div>\n!;21082109return$result;2110}21112112# create note for patch simplified by combined diff2113sub format_diff_cc_simplified {2114my($diffinfo,@parents) =@_;2115my$result='';21162117$result.="<div class=\"diff header\">".2118"diff --cc ";2119if(!is_deleted($diffinfo)) {2120$result.=$cgi->a({-href => href(action=>"blob",2121 hash_base=>$hash,2122 hash=>$diffinfo->{'to_id'},2123 file_name=>$diffinfo->{'to_file'}),2124-class=>"path"},2125 esc_path($diffinfo->{'to_file'}));2126}else{2127$result.= esc_path($diffinfo->{'to_file'});2128}2129$result.="</div>\n".# class="diff header"2130"<div class=\"diff nodifferences\">".2131"Simple merge".2132"</div>\n";# class="diff nodifferences"21332134return$result;2135}21362137# format patch (diff) line (not to be used for diff headers)2138sub format_diff_line {2139my$line=shift;2140my($from,$to) =@_;2141my$diff_class="";21422143chomp$line;21442145if($from&&$to&&ref($from->{'href'})eq"ARRAY") {2146# combined diff2147my$prefix=substr($line,0,scalar@{$from->{'href'}});2148if($line=~m/^\@{3}/) {2149$diff_class=" chunk_header";2150}elsif($line=~m/^\\/) {2151$diff_class=" incomplete";2152}elsif($prefix=~tr/+/+/) {2153$diff_class=" add";2154}elsif($prefix=~tr/-/-/) {2155$diff_class=" rem";2156}2157}else{2158# assume ordinary diff2159my$char=substr($line,0,1);2160if($chareq'+') {2161$diff_class=" add";2162}elsif($chareq'-') {2163$diff_class=" rem";2164}elsif($chareq'@') {2165$diff_class=" chunk_header";2166}elsif($chareq"\\") {2167$diff_class=" incomplete";2168}2169}2170$line= untabify($line);2171if($from&&$to&&$line=~m/^\@{2} /) {2172my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =2173$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;21742175$from_lines=0unlessdefined$from_lines;2176$to_lines=0unlessdefined$to_lines;21772178if($from->{'href'}) {2179$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",2180-class=>"list"},$from_text);2181}2182if($to->{'href'}) {2183$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",2184-class=>"list"},$to_text);2185}2186$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".2187"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2188return"<div class=\"diff$diff_class\">$line</div>\n";2189}elsif($from&&$to&&$line=~m/^\@{3}/) {2190my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;2191my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);21922193@from_text=split(' ',$ranges);2194for(my$i=0;$i<@from_text; ++$i) {2195($from_start[$i],$from_nlines[$i]) =2196(split(',',substr($from_text[$i],1)),0);2197}21982199$to_text=pop@from_text;2200$to_start=pop@from_start;2201$to_nlines=pop@from_nlines;22022203$line="<span class=\"chunk_info\">$prefix";2204for(my$i=0;$i<@from_text; ++$i) {2205if($from->{'href'}[$i]) {2206$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",2207-class=>"list"},$from_text[$i]);2208}else{2209$line.=$from_text[$i];2210}2211$line.=" ";2212}2213if($to->{'href'}) {2214$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",2215-class=>"list"},$to_text);2216}else{2217$line.=$to_text;2218}2219$line.="$prefix</span>".2220"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2221return"<div class=\"diff$diff_class\">$line</div>\n";2222}2223return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";2224}22252226# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",2227# linked. Pass the hash of the tree/commit to snapshot.2228sub format_snapshot_links {2229my($hash) =@_;2230my$num_fmts=@snapshot_fmts;2231if($num_fmts>1) {2232# A parenthesized list of links bearing format names.2233# e.g. "snapshot (_tar.gz_ _zip_)"2234return"snapshot (".join(' ',map2235$cgi->a({2236-href => href(2237 action=>"snapshot",2238 hash=>$hash,2239 snapshot_format=>$_2240)2241},$known_snapshot_formats{$_}{'display'})2242,@snapshot_fmts) .")";2243}elsif($num_fmts==1) {2244# A single "snapshot" link whose tooltip bears the format name.2245# i.e. "_snapshot_"2246my($fmt) =@snapshot_fmts;2247return2248$cgi->a({2249-href => href(2250 action=>"snapshot",2251 hash=>$hash,2252 snapshot_format=>$fmt2253),2254-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"2255},"snapshot");2256}else{# $num_fmts == 02257returnundef;2258}2259}22602261## ......................................................................2262## functions returning values to be passed, perhaps after some2263## transformation, to other functions; e.g. returning arguments to href()22642265# returns hash to be passed to href to generate gitweb URL2266# in -title key it returns description of link2267sub get_feed_info {2268my$format=shift||'Atom';2269my%res= (action =>lc($format));22702271# feed links are possible only for project views2272return unless(defined$project);2273# some views should link to OPML, or to generic project feed,2274# or don't have specific feed yet (so they should use generic)2275return if($action=~/^(?:tags|heads|forks|tag|search)$/x);22762277my$branch;2278# branches refs uses 'refs/heads/' prefix (fullname) to differentiate2279# from tag links; this also makes possible to detect branch links2280if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||2281(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {2282$branch=$1;2283}2284# find log type for feed description (title)2285my$type='log';2286if(defined$file_name) {2287$type="history of$file_name";2288$type.="/"if($actioneq'tree');2289$type.=" on '$branch'"if(defined$branch);2290}else{2291$type="log of$branch"if(defined$branch);2292}22932294$res{-title} =$type;2295$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);2296$res{'file_name'} =$file_name;22972298return%res;2299}23002301## ----------------------------------------------------------------------2302## git utility subroutines, invoking git commands23032304# returns path to the core git executable and the --git-dir parameter as list2305sub git_cmd {2306$number_of_git_cmds++;2307return$GIT,'--git-dir='.$git_dir;2308}23092310# quote the given arguments for passing them to the shell2311# quote_command("command", "arg 1", "arg with ' and ! characters")2312# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2313# Try to avoid using this function wherever possible.2314sub quote_command {2315returnjoin(' ',2316map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2317}23182319# get HEAD ref of given project as hash2320sub git_get_head_hash {2321return git_get_full_hash(shift,'HEAD');2322}23232324sub git_get_full_hash {2325return git_get_hash(@_);2326}23272328sub git_get_short_hash {2329return git_get_hash(@_,'--short=7');2330}23312332sub git_get_hash {2333my($project,$hash,@options) =@_;2334my$o_git_dir=$git_dir;2335my$retval=undef;2336$git_dir="$projectroot/$project";2337if(open my$fd,'-|', git_cmd(),'rev-parse',2338'--verify','-q',@options,$hash) {2339$retval= <$fd>;2340chomp$retvalifdefined$retval;2341close$fd;2342}2343if(defined$o_git_dir) {2344$git_dir=$o_git_dir;2345}2346return$retval;2347}23482349# get type of given object2350sub git_get_type {2351my$hash=shift;23522353open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2354my$type= <$fd>;2355close$fdorreturn;2356chomp$type;2357return$type;2358}23592360# repository configuration2361our$config_file='';2362our%config;23632364# store multiple values for single key as anonymous array reference2365# single values stored directly in the hash, not as [ <value> ]2366sub hash_set_multi {2367my($hash,$key,$value) =@_;23682369if(!exists$hash->{$key}) {2370$hash->{$key} =$value;2371}elsif(!ref$hash->{$key}) {2372$hash->{$key} = [$hash->{$key},$value];2373}else{2374push@{$hash->{$key}},$value;2375}2376}23772378# return hash of git project configuration2379# optionally limited to some section, e.g. 'gitweb'2380sub git_parse_project_config {2381my$section_regexp=shift;2382my%config;23832384local$/="\0";23852386open my$fh,"-|", git_cmd(),"config",'-z','-l',2387orreturn;23882389while(my$keyval= <$fh>) {2390chomp$keyval;2391my($key,$value) =split(/\n/,$keyval,2);23922393 hash_set_multi(\%config,$key,$value)2394if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2395}2396close$fh;23972398return%config;2399}24002401# convert config value to boolean: 'true' or 'false'2402# no value, number > 0, 'true' and 'yes' values are true2403# rest of values are treated as false (never as error)2404sub config_to_bool {2405my$val=shift;24062407return1if!defined$val;# section.key24082409# strip leading and trailing whitespace2410$val=~s/^\s+//;2411$val=~s/\s+$//;24122413return(($val=~/^\d+$/&&$val) ||# section.key = 12414($val=~/^(?:true|yes)$/i));# section.key = true2415}24162417# convert config value to simple decimal number2418# an optional value suffix of 'k', 'm', or 'g' will cause the value2419# to be multiplied by 1024, 1048576, or 10737418242420sub config_to_int {2421my$val=shift;24222423# strip leading and trailing whitespace2424$val=~s/^\s+//;2425$val=~s/\s+$//;24262427if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2428$unit=lc($unit);2429# unknown unit is treated as 12430return$num* ($uniteq'g'?1073741824:2431$uniteq'm'?1048576:2432$uniteq'k'?1024:1);2433}2434return$val;2435}24362437# convert config value to array reference, if needed2438sub config_to_multi {2439my$val=shift;24402441returnref($val) ?$val: (defined($val) ? [$val] : []);2442}24432444sub git_get_project_config {2445my($key,$type) =@_;24462447return unlessdefined$git_dir;24482449# key sanity check2450return unless($key);2451$key=~s/^gitweb\.//;2452return if($key=~m/\W/);24532454# type sanity check2455if(defined$type) {2456$type=~s/^--//;2457$type=undef2458unless($typeeq'bool'||$typeeq'int');2459}24602461# get config2462if(!defined$config_file||2463$config_filene"$git_dir/config") {2464%config= git_parse_project_config('gitweb');2465$config_file="$git_dir/config";2466}24672468# check if config variable (key) exists2469return unlessexists$config{"gitweb.$key"};24702471# ensure given type2472if(!defined$type) {2473return$config{"gitweb.$key"};2474}elsif($typeeq'bool') {2475# backward compatibility: 'git config --bool' returns true/false2476return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2477}elsif($typeeq'int') {2478return config_to_int($config{"gitweb.$key"});2479}2480return$config{"gitweb.$key"};2481}24822483# get hash of given path at given ref2484sub git_get_hash_by_path {2485my$base=shift;2486my$path=shift||returnundef;2487my$type=shift;24882489$path=~ s,/+$,,;24902491open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2492or die_error(500,"Open git-ls-tree failed");2493my$line= <$fd>;2494close$fdorreturnundef;24952496if(!defined$line) {2497# there is no tree or hash given by $path at $base2498returnundef;2499}25002501#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2502$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2503if(defined$type&&$typene$2) {2504# type doesn't match2505returnundef;2506}2507return$3;2508}25092510# get path of entry with given hash at given tree-ish (ref)2511# used to get 'from' filename for combined diff (merge commit) for renames2512sub git_get_path_by_hash {2513my$base=shift||return;2514my$hash=shift||return;25152516local$/="\0";25172518open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2519orreturnundef;2520while(my$line= <$fd>) {2521chomp$line;25222523#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2524#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2525if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2526close$fd;2527return$1;2528}2529}2530close$fd;2531returnundef;2532}25332534## ......................................................................2535## git utility functions, directly accessing git repository25362537sub git_get_project_description {2538my$path=shift;25392540$git_dir="$projectroot/$path";2541open my$fd,'<',"$git_dir/description"2542orreturn git_get_project_config('description');2543my$descr= <$fd>;2544close$fd;2545if(defined$descr) {2546chomp$descr;2547}2548return$descr;2549}25502551sub git_get_project_ctags {2552my$path=shift;2553my$ctags= {};25542555$git_dir="$projectroot/$path";2556opendir my$dh,"$git_dir/ctags"2557orreturn$ctags;2558foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2559open my$ct,'<',$_ornext;2560my$val= <$ct>;2561chomp$val;2562close$ct;2563my$ctag=$_;$ctag=~ s#.*/##;2564$ctags->{$ctag} =$val;2565}2566closedir$dh;2567$ctags;2568}25692570sub git_populate_project_tagcloud {2571my$ctags=shift;25722573# First, merge different-cased tags; tags vote on casing2574my%ctags_lc;2575foreach(keys%$ctags) {2576$ctags_lc{lc$_}->{count} +=$ctags->{$_};2577if(not$ctags_lc{lc$_}->{topcount}2578or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2579$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2580$ctags_lc{lc$_}->{topname} =$_;2581}2582}25832584my$cloud;2585if(eval{require HTML::TagCloud;1; }) {2586$cloud= HTML::TagCloud->new;2587foreach(sort keys%ctags_lc) {2588# Pad the title with spaces so that the cloud looks2589# less crammed.2590my$title=$ctags_lc{$_}->{topname};2591$title=~s/ / /g;2592$title=~s/^/ /g;2593$title=~s/$/ /g;2594$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2595}2596}else{2597$cloud= \%ctags_lc;2598}2599$cloud;2600}26012602sub git_show_project_tagcloud {2603my($cloud,$count) =@_;2604print STDERR ref($cloud)."..\n";2605if(ref$cloudeq'HTML::TagCloud') {2606return$cloud->html_and_css($count);2607}else{2608my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2609return'<p align="center">'.join(', ',map{2610$cgi->a({-href=>"$home_link?by_tag=$_"},$cloud->{$_}->{topname})2611}splice(@tags,0,$count)) .'</p>';2612}2613}26142615sub git_get_project_url_list {2616my$path=shift;26172618$git_dir="$projectroot/$path";2619open my$fd,'<',"$git_dir/cloneurl"2620orreturnwantarray?2621@{ config_to_multi(git_get_project_config('url')) } :2622 config_to_multi(git_get_project_config('url'));2623my@git_project_url_list=map{chomp;$_} <$fd>;2624close$fd;26252626returnwantarray?@git_project_url_list: \@git_project_url_list;2627}26282629sub git_get_projects_list {2630my($filter) =@_;2631my@list;26322633$filter||='';2634$filter=~s/\.git$//;26352636my$check_forks= gitweb_check_feature('forks');26372638if(-d $projects_list) {2639# search in directory2640my$dir=$projects_list. ($filter?"/$filter":'');2641# remove the trailing "/"2642$dir=~s!/+$!!;2643my$pfxlen=length("$dir");2644my$pfxdepth= ($dir=~tr!/!!);26452646 File::Find::find({2647 follow_fast =>1,# follow symbolic links2648 follow_skip =>2,# ignore duplicates2649 dangling_symlinks =>0,# ignore dangling symlinks, silently2650 wanted =>sub{2651# global variables2652our$project_maxdepth;2653our$projectroot;2654# skip project-list toplevel, if we get it.2655return if(m!^[/.]$!);2656# only directories can be git repositories2657return unless(-d $_);2658# don't traverse too deep (Find is super slow on os x)2659if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2660$File::Find::prune =1;2661return;2662}26632664my$subdir=substr($File::Find::name,$pfxlen+1);2665# we check related file in $projectroot2666my$path= ($filter?"$filter/":'') .$subdir;2667if(check_export_ok("$projectroot/$path")) {2668push@list, { path =>$path};2669$File::Find::prune =1;2670}2671},2672},"$dir");26732674}elsif(-f $projects_list) {2675# read from file(url-encoded):2676# 'git%2Fgit.git Linus+Torvalds'2677# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2678# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2679my%paths;2680open my$fd,'<',$projects_listorreturn;2681 PROJECT:2682while(my$line= <$fd>) {2683chomp$line;2684my($path,$owner) =split' ',$line;2685$path= unescape($path);2686$owner= unescape($owner);2687if(!defined$path) {2688next;2689}2690if($filterne'') {2691# looking for forks;2692my$pfx=substr($path,0,length($filter));2693if($pfxne$filter) {2694next PROJECT;2695}2696my$sfx=substr($path,length($filter));2697if($sfx!~/^\/.*\.git$/) {2698next PROJECT;2699}2700}elsif($check_forks) {2701 PATH:2702foreachmy$filter(keys%paths) {2703# looking for forks;2704my$pfx=substr($path,0,length($filter));2705if($pfxne$filter) {2706next PATH;2707}2708my$sfx=substr($path,length($filter));2709if($sfx!~/^\/.*\.git$/) {2710next PATH;2711}2712# is a fork, don't include it in2713# the list2714next PROJECT;2715}2716}2717if(check_export_ok("$projectroot/$path")) {2718my$pr= {2719 path =>$path,2720 owner => to_utf8($owner),2721};2722push@list,$pr;2723(my$forks_path=$path) =~s/\.git$//;2724$paths{$forks_path}++;2725}2726}2727close$fd;2728}2729return@list;2730}27312732our$gitweb_project_owner=undef;2733sub git_get_project_list_from_file {27342735return if(defined$gitweb_project_owner);27362737$gitweb_project_owner= {};2738# read from file (url-encoded):2739# 'git%2Fgit.git Linus+Torvalds'2740# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2741# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2742if(-f $projects_list) {2743open(my$fd,'<',$projects_list);2744while(my$line= <$fd>) {2745chomp$line;2746my($pr,$ow) =split' ',$line;2747$pr= unescape($pr);2748$ow= unescape($ow);2749$gitweb_project_owner->{$pr} = to_utf8($ow);2750}2751close$fd;2752}2753}27542755sub git_get_project_owner {2756my$project=shift;2757my$owner;27582759returnundefunless$project;2760$git_dir="$projectroot/$project";27612762if(!defined$gitweb_project_owner) {2763 git_get_project_list_from_file();2764}27652766if(exists$gitweb_project_owner->{$project}) {2767$owner=$gitweb_project_owner->{$project};2768}2769if(!defined$owner){2770$owner= git_get_project_config('owner');2771}2772if(!defined$owner) {2773$owner= get_file_owner("$git_dir");2774}27752776return$owner;2777}27782779sub git_get_last_activity {2780my($path) =@_;2781my$fd;27822783$git_dir="$projectroot/$path";2784open($fd,"-|", git_cmd(),'for-each-ref',2785'--format=%(committer)',2786'--sort=-committerdate',2787'--count=1',2788'refs/heads')orreturn;2789my$most_recent= <$fd>;2790close$fdorreturn;2791if(defined$most_recent&&2792$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2793my$timestamp=$1;2794my$age=time-$timestamp;2795return($age, age_string($age));2796}2797return(undef,undef);2798}27992800# Implementation note: when a single remote is wanted, we cannot use 'git2801# remote show -n' because that command always work (assuming it's a remote URL2802# if it's not defined), and we cannot use 'git remote show' because that would2803# try to make a network roundtrip. So the only way to find if that particular2804# remote is defined is to walk the list provided by 'git remote -v' and stop if2805# and when we find what we want.2806sub git_get_remotes_list {2807my$wanted=shift;2808my%remotes= ();28092810open my$fd,'-|', git_cmd(),'remote','-v';2811return unless$fd;2812while(my$remote= <$fd>) {2813chomp$remote;2814$remote=~s!\t(.*?)\s+\((\w+)\)$!!;2815next if$wantedand not$remoteeq$wanted;2816my($url,$key) = ($1,$2);28172818$remotes{$remote} ||= {'heads'=> () };2819$remotes{$remote}{$key} =$url;2820}2821close$fdorreturn;2822returnwantarray?%remotes: \%remotes;2823}28242825# Takes a hash of remotes as first parameter and fills it by adding the2826# available remote heads for each of the indicated remotes.2827sub fill_remote_heads {2828my$remotes=shift;2829my@heads=map{"remotes/$_"}keys%$remotes;2830my@remoteheads= git_get_heads_list(undef,@heads);2831foreachmy$remote(keys%$remotes) {2832$remotes->{$remote}{'heads'} = [grep{2833$_->{'name'} =~s!^$remote/!!2834}@remoteheads];2835}2836}28372838sub git_get_references {2839my$type=shift||"";2840my%refs;2841# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112842# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2843open my$fd,"-|", git_cmd(),"show-ref","--dereference",2844($type? ("--","refs/$type") : ())# use -- <pattern> if $type2845orreturn;28462847while(my$line= <$fd>) {2848chomp$line;2849if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2850if(defined$refs{$1}) {2851push@{$refs{$1}},$2;2852}else{2853$refs{$1} = [$2];2854}2855}2856}2857close$fdorreturn;2858return \%refs;2859}28602861sub git_get_rev_name_tags {2862my$hash=shift||returnundef;28632864open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2865orreturn;2866my$name_rev= <$fd>;2867close$fd;28682869if($name_rev=~ m|^$hash tags/(.*)$|) {2870return$1;2871}else{2872# catches also '$hash undefined' output2873returnundef;2874}2875}28762877## ----------------------------------------------------------------------2878## parse to hash functions28792880sub parse_date {2881my$epoch=shift;2882my$tz=shift||"-0000";28832884my%date;2885my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2886my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2887my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2888$date{'hour'} =$hour;2889$date{'minute'} =$min;2890$date{'mday'} =$mday;2891$date{'day'} =$days[$wday];2892$date{'month'} =$months[$mon];2893$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2894$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2895$date{'mday-time'} =sprintf"%d%s%02d:%02d",2896$mday,$months[$mon],$hour,$min;2897$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",28981900+$year,1+$mon,$mday,$hour,$min,$sec;28992900$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2901my$local=$epoch+ ((int$1+ ($2/60)) *3600);2902($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2903$date{'hour_local'} =$hour;2904$date{'minute_local'} =$min;2905$date{'tz_local'} =$tz;2906$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",29071900+$year,$mon+1,$mday,2908$hour,$min,$sec,$tz);2909return%date;2910}29112912sub parse_tag {2913my$tag_id=shift;2914my%tag;2915my@comment;29162917open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2918$tag{'id'} =$tag_id;2919while(my$line= <$fd>) {2920chomp$line;2921if($line=~m/^object ([0-9a-fA-F]{40})$/) {2922$tag{'object'} =$1;2923}elsif($line=~m/^type (.+)$/) {2924$tag{'type'} =$1;2925}elsif($line=~m/^tag (.+)$/) {2926$tag{'name'} =$1;2927}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2928$tag{'author'} =$1;2929$tag{'author_epoch'} =$2;2930$tag{'author_tz'} =$3;2931if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {2932$tag{'author_name'} =$1;2933$tag{'author_email'} =$2;2934}else{2935$tag{'author_name'} =$tag{'author'};2936}2937}elsif($line=~m/--BEGIN/) {2938push@comment,$line;2939last;2940}elsif($lineeq"") {2941last;2942}2943}2944push@comment, <$fd>;2945$tag{'comment'} = \@comment;2946close$fdorreturn;2947if(!defined$tag{'name'}) {2948return2949};2950return%tag2951}29522953sub parse_commit_text {2954my($commit_text,$withparents) =@_;2955my@commit_lines=split'\n',$commit_text;2956my%co;29572958pop@commit_lines;# Remove '\0'29592960if(!@commit_lines) {2961return;2962}29632964my$header=shift@commit_lines;2965if($header!~m/^[0-9a-fA-F]{40}/) {2966return;2967}2968($co{'id'},my@parents) =split' ',$header;2969while(my$line=shift@commit_lines) {2970last if$lineeq"\n";2971if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2972$co{'tree'} =$1;2973}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2974push@parents,$1;2975}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2976$co{'author'} = to_utf8($1);2977$co{'author_epoch'} =$2;2978$co{'author_tz'} =$3;2979if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2980$co{'author_name'} =$1;2981$co{'author_email'} =$2;2982}else{2983$co{'author_name'} =$co{'author'};2984}2985}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2986$co{'committer'} = to_utf8($1);2987$co{'committer_epoch'} =$2;2988$co{'committer_tz'} =$3;2989if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2990$co{'committer_name'} =$1;2991$co{'committer_email'} =$2;2992}else{2993$co{'committer_name'} =$co{'committer'};2994}2995}2996}2997if(!defined$co{'tree'}) {2998return;2999};3000$co{'parents'} = \@parents;3001$co{'parent'} =$parents[0];30023003foreachmy$title(@commit_lines) {3004$title=~s/^ //;3005if($titlene"") {3006$co{'title'} = chop_str($title,80,5);3007# remove leading stuff of merges to make the interesting part visible3008if(length($title) >50) {3009$title=~s/^Automatic //;3010$title=~s/^merge (of|with) /Merge ... /i;3011if(length($title) >50) {3012$title=~s/(http|rsync):\/\///;3013}3014if(length($title) >50) {3015$title=~s/(master|www|rsync)\.//;3016}3017if(length($title) >50) {3018$title=~s/kernel.org:?//;3019}3020if(length($title) >50) {3021$title=~s/\/pub\/scm//;3022}3023}3024$co{'title_short'} = chop_str($title,50,5);3025last;3026}3027}3028if(!defined$co{'title'} ||$co{'title'}eq"") {3029$co{'title'} =$co{'title_short'} ='(no commit message)';3030}3031# remove added spaces3032foreachmy$line(@commit_lines) {3033$line=~s/^ //;3034}3035$co{'comment'} = \@commit_lines;30363037my$age=time-$co{'committer_epoch'};3038$co{'age'} =$age;3039$co{'age_string'} = age_string($age);3040my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});3041if($age>60*60*24*7*2) {3042$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;3043$co{'age_string_age'} =$co{'age_string'};3044}else{3045$co{'age_string_date'} =$co{'age_string'};3046$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;3047}3048return%co;3049}30503051sub parse_commit {3052my($commit_id) =@_;3053my%co;30543055local$/="\0";30563057open my$fd,"-|", git_cmd(),"rev-list",3058"--parents",3059"--header",3060"--max-count=1",3061$commit_id,3062"--",3063or die_error(500,"Open git-rev-list failed");3064%co= parse_commit_text(<$fd>,1);3065close$fd;30663067return%co;3068}30693070sub parse_commits {3071my($commit_id,$maxcount,$skip,$filename,@args) =@_;3072my@cos;30733074$maxcount||=1;3075$skip||=0;30763077local$/="\0";30783079open my$fd,"-|", git_cmd(),"rev-list",3080"--header",3081@args,3082("--max-count=".$maxcount),3083("--skip=".$skip),3084@extra_options,3085$commit_id,3086"--",3087($filename? ($filename) : ())3088or die_error(500,"Open git-rev-list failed");3089while(my$line= <$fd>) {3090my%co= parse_commit_text($line);3091push@cos, \%co;3092}3093close$fd;30943095returnwantarray?@cos: \@cos;3096}30973098# parse line of git-diff-tree "raw" output3099sub parse_difftree_raw_line {3100my$line=shift;3101my%res;31023103# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'3104# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'3105if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {3106$res{'from_mode'} =$1;3107$res{'to_mode'} =$2;3108$res{'from_id'} =$3;3109$res{'to_id'} =$4;3110$res{'status'} =$5;3111$res{'similarity'} =$6;3112if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied3113($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);3114}else{3115$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);3116}3117}3118# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'3119# combined diff (for merge commit)3120elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {3121$res{'nparents'} =length($1);3122$res{'from_mode'} = [split(' ',$2) ];3123$res{'to_mode'} =pop@{$res{'from_mode'}};3124$res{'from_id'} = [split(' ',$3) ];3125$res{'to_id'} =pop@{$res{'from_id'}};3126$res{'status'} = [split('',$4) ];3127$res{'to_file'} = unquote($5);3128}3129# 'c512b523472485aef4fff9e57b229d9d243c967f'3130elsif($line=~m/^([0-9a-fA-F]{40})$/) {3131$res{'commit'} =$1;3132}31333134returnwantarray?%res: \%res;3135}31363137# wrapper: return parsed line of git-diff-tree "raw" output3138# (the argument might be raw line, or parsed info)3139sub parsed_difftree_line {3140my$line_or_ref=shift;31413142if(ref($line_or_ref)eq"HASH") {3143# pre-parsed (or generated by hand)3144return$line_or_ref;3145}else{3146return parse_difftree_raw_line($line_or_ref);3147}3148}31493150# parse line of git-ls-tree output3151sub parse_ls_tree_line {3152my$line=shift;3153my%opts=@_;3154my%res;31553156if($opts{'-l'}) {3157#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'3158$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;31593160$res{'mode'} =$1;3161$res{'type'} =$2;3162$res{'hash'} =$3;3163$res{'size'} =$4;3164if($opts{'-z'}) {3165$res{'name'} =$5;3166}else{3167$res{'name'} = unquote($5);3168}3169}else{3170#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'3171$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;31723173$res{'mode'} =$1;3174$res{'type'} =$2;3175$res{'hash'} =$3;3176if($opts{'-z'}) {3177$res{'name'} =$4;3178}else{3179$res{'name'} = unquote($4);3180}3181}31823183returnwantarray?%res: \%res;3184}31853186# generates _two_ hashes, references to which are passed as 2 and 3 argument3187sub parse_from_to_diffinfo {3188my($diffinfo,$from,$to,@parents) =@_;31893190if($diffinfo->{'nparents'}) {3191# combined diff3192$from->{'file'} = [];3193$from->{'href'} = [];3194 fill_from_file_info($diffinfo,@parents)3195unlessexists$diffinfo->{'from_file'};3196for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {3197$from->{'file'}[$i] =3198defined$diffinfo->{'from_file'}[$i] ?3199$diffinfo->{'from_file'}[$i] :3200$diffinfo->{'to_file'};3201if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file3202$from->{'href'}[$i] = href(action=>"blob",3203 hash_base=>$parents[$i],3204 hash=>$diffinfo->{'from_id'}[$i],3205 file_name=>$from->{'file'}[$i]);3206}else{3207$from->{'href'}[$i] =undef;3208}3209}3210}else{3211# ordinary (not combined) diff3212$from->{'file'} =$diffinfo->{'from_file'};3213if($diffinfo->{'status'}ne"A") {# not new (added) file3214$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,3215 hash=>$diffinfo->{'from_id'},3216 file_name=>$from->{'file'});3217}else{3218delete$from->{'href'};3219}3220}32213222$to->{'file'} =$diffinfo->{'to_file'};3223if(!is_deleted($diffinfo)) {# file exists in result3224$to->{'href'} = href(action=>"blob", hash_base=>$hash,3225 hash=>$diffinfo->{'to_id'},3226 file_name=>$to->{'file'});3227}else{3228delete$to->{'href'};3229}3230}32313232## ......................................................................3233## parse to array of hashes functions32343235sub git_get_heads_list {3236my($limit,@classes) =@_;3237@classes= ('heads')unless@classes;3238my@patterns=map{"refs/$_"}@classes;3239my@headslist;32403241open my$fd,'-|', git_cmd(),'for-each-ref',3242($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',3243'--format=%(objectname) %(refname) %(subject)%00%(committer)',3244@patterns3245orreturn;3246while(my$line= <$fd>) {3247my%ref_item;32483249chomp$line;3250my($refinfo,$committerinfo) =split(/\0/,$line);3251my($hash,$name,$title) =split(' ',$refinfo,3);3252my($committer,$epoch,$tz) =3253($committerinfo=~/^(.*) ([0-9]+) (.*)$/);3254$ref_item{'fullname'} =$name;3255$name=~s!^refs/(?:head|remote)s/!!;32563257$ref_item{'name'} =$name;3258$ref_item{'id'} =$hash;3259$ref_item{'title'} =$title||'(no commit message)';3260$ref_item{'epoch'} =$epoch;3261if($epoch) {3262$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3263}else{3264$ref_item{'age'} ="unknown";3265}32663267push@headslist, \%ref_item;3268}3269close$fd;32703271returnwantarray?@headslist: \@headslist;3272}32733274sub git_get_tags_list {3275my$limit=shift;3276my@tagslist;32773278open my$fd,'-|', git_cmd(),'for-each-ref',3279($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',3280'--format=%(objectname) %(objecttype) %(refname) '.3281'%(*objectname) %(*objecttype) %(subject)%00%(creator)',3282'refs/tags'3283orreturn;3284while(my$line= <$fd>) {3285my%ref_item;32863287chomp$line;3288my($refinfo,$creatorinfo) =split(/\0/,$line);3289my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);3290my($creator,$epoch,$tz) =3291($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);3292$ref_item{'fullname'} =$name;3293$name=~s!^refs/tags/!!;32943295$ref_item{'type'} =$type;3296$ref_item{'id'} =$id;3297$ref_item{'name'} =$name;3298if($typeeq"tag") {3299$ref_item{'subject'} =$title;3300$ref_item{'reftype'} =$reftype;3301$ref_item{'refid'} =$refid;3302}else{3303$ref_item{'reftype'} =$type;3304$ref_item{'refid'} =$id;3305}33063307if($typeeq"tag"||$typeeq"commit") {3308$ref_item{'epoch'} =$epoch;3309if($epoch) {3310$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3311}else{3312$ref_item{'age'} ="unknown";3313}3314}33153316push@tagslist, \%ref_item;3317}3318close$fd;33193320returnwantarray?@tagslist: \@tagslist;3321}33223323## ----------------------------------------------------------------------3324## filesystem-related functions33253326sub get_file_owner {3327my$path=shift;33283329my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);3330my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);3331if(!defined$gcos) {3332returnundef;3333}3334my$owner=$gcos;3335$owner=~s/[,;].*$//;3336return to_utf8($owner);3337}33383339# assume that file exists3340sub insert_file {3341my$filename=shift;33423343open my$fd,'<',$filename;3344print map{ to_utf8($_) } <$fd>;3345close$fd;3346}33473348## ......................................................................3349## mimetype related functions33503351sub mimetype_guess_file {3352my$filename=shift;3353my$mimemap=shift;3354-r $mimemaporreturnundef;33553356my%mimemap;3357open(my$mh,'<',$mimemap)orreturnundef;3358while(<$mh>) {3359next ifm/^#/;# skip comments3360my($mimetype,$exts) =split(/\t+/);3361if(defined$exts) {3362my@exts=split(/\s+/,$exts);3363foreachmy$ext(@exts) {3364$mimemap{$ext} =$mimetype;3365}3366}3367}3368close($mh);33693370$filename=~/\.([^.]*)$/;3371return$mimemap{$1};3372}33733374sub mimetype_guess {3375my$filename=shift;3376my$mime;3377$filename=~/\./orreturnundef;33783379if($mimetypes_file) {3380my$file=$mimetypes_file;3381if($file!~m!^/!) {# if it is relative path3382# it is relative to project3383$file="$projectroot/$project/$file";3384}3385$mime= mimetype_guess_file($filename,$file);3386}3387$mime||= mimetype_guess_file($filename,'/etc/mime.types');3388return$mime;3389}33903391sub blob_mimetype {3392my$fd=shift;3393my$filename=shift;33943395if($filename) {3396my$mime= mimetype_guess($filename);3397$mimeandreturn$mime;3398}33993400# just in case3401return$default_blob_plain_mimetypeunless$fd;34023403if(-T $fd) {3404return'text/plain';3405}elsif(!$filename) {3406return'application/octet-stream';3407}elsif($filename=~m/\.png$/i) {3408return'image/png';3409}elsif($filename=~m/\.gif$/i) {3410return'image/gif';3411}elsif($filename=~m/\.jpe?g$/i) {3412return'image/jpeg';3413}else{3414return'application/octet-stream';3415}3416}34173418sub blob_contenttype {3419my($fd,$file_name,$type) =@_;34203421$type||= blob_mimetype($fd,$file_name);3422if($typeeq'text/plain'&&defined$default_text_plain_charset) {3423$type.="; charset=$default_text_plain_charset";3424}34253426return$type;3427}34283429# guess file syntax for syntax highlighting; return undef if no highlighting3430# the name of syntax can (in the future) depend on syntax highlighter used3431sub guess_file_syntax {3432my($highlight,$mimetype,$file_name) =@_;3433returnundefunless($highlight&&defined$file_name);3434my$basename= basename($file_name,'.in');3435return$highlight_basename{$basename}3436ifexists$highlight_basename{$basename};34373438$basename=~/\.([^.]*)$/;3439my$ext=$1orreturnundef;3440return$highlight_ext{$ext}3441ifexists$highlight_ext{$ext};34423443returnundef;3444}34453446# run highlighter and return FD of its output,3447# or return original FD if no highlighting3448sub run_highlighter {3449my($fd,$highlight,$syntax) =@_;3450return$fdunless($highlight&&defined$syntax);34513452close$fd3453or die_error(404,"Reading blob failed");3454open$fd, quote_command(git_cmd(),"cat-file","blob",$hash)." | ".3455 quote_command($highlight_bin).3456" --xhtml --fragment --syntax$syntax|"3457or die_error(500,"Couldn't open file or run syntax highlighter");3458return$fd;3459}34603461## ======================================================================3462## functions printing HTML: header, footer, error page34633464sub get_page_title {3465my$title= to_utf8($site_name);34663467return$titleunless(defined$project);3468$title.=" - ". to_utf8($project);34693470return$titleunless(defined$action);3471$title.="/$action";# $action is US-ASCII (7bit ASCII)34723473return$titleunless(defined$file_name);3474$title.=" - ". esc_path($file_name);3475if($actioneq"tree"&&$file_name!~ m|/$|) {3476$title.="/";3477}34783479return$title;3480}34813482sub print_feed_meta {3483if(defined$project) {3484my%href_params= get_feed_info();3485if(!exists$href_params{'-title'}) {3486$href_params{'-title'} ='log';3487}34883489foreachmy$formatqw(RSS Atom){3490my$type=lc($format);3491my%link_attr= (3492'-rel'=>'alternate',3493'-title'=> esc_attr("$project-$href_params{'-title'} -$formatfeed"),3494'-type'=>"application/$type+xml"3495);34963497$href_params{'action'} =$type;3498$link_attr{'-href'} = href(%href_params);3499print"<link ".3500"rel=\"$link_attr{'-rel'}\"".3501"title=\"$link_attr{'-title'}\"".3502"href=\"$link_attr{'-href'}\"".3503"type=\"$link_attr{'-type'}\"".3504"/>\n";35053506$href_params{'extra_options'} ='--no-merges';3507$link_attr{'-href'} = href(%href_params);3508$link_attr{'-title'} .=' (no merges)';3509print"<link ".3510"rel=\"$link_attr{'-rel'}\"".3511"title=\"$link_attr{'-title'}\"".3512"href=\"$link_attr{'-href'}\"".3513"type=\"$link_attr{'-type'}\"".3514"/>\n";3515}35163517}else{3518printf('<link rel="alternate" title="%sprojects list" '.3519'href="%s" type="text/plain; charset=utf-8" />'."\n",3520 esc_attr($site_name), href(project=>undef, action=>"project_index"));3521printf('<link rel="alternate" title="%sprojects feeds" '.3522'href="%s" type="text/x-opml" />'."\n",3523 esc_attr($site_name), href(project=>undef, action=>"opml"));3524}3525}35263527sub git_header_html {3528my$status=shift||"200 OK";3529my$expires=shift;3530my%opts=@_;35313532my$title= get_page_title();3533my$content_type;3534# require explicit support from the UA if we are to send the page as3535# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3536# we have to do this because MSIE sometimes globs '*/*', pretending to3537# support xhtml+xml but choking when it gets what it asked for.3538if(defined$cgi->http('HTTP_ACCEPT') &&3539$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3540$cgi->Accept('application/xhtml+xml') !=0) {3541$content_type='application/xhtml+xml';3542}else{3543$content_type='text/html';3544}3545print$cgi->header(-type=>$content_type, -charset =>'utf-8',3546-status=>$status, -expires =>$expires)3547unless($opts{'-no_http_header'});3548my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';3549print<<EOF;3550<?xml version="1.0" encoding="utf-8"?>3551<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">3552<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">3553<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->3554<!-- git core binaries version$git_version-->3555<head>3556<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>3557<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>3558<meta name="robots" content="index, nofollow"/>3559<title>$title</title>3560EOF3561# the stylesheet, favicon etc urls won't work correctly with path_info3562# unless we set the appropriate base URL3563if($ENV{'PATH_INFO'}) {3564print"<base href=\"".esc_url($base_url)."\"/>\n";3565}3566# print out each stylesheet that exist, providing backwards capability3567# for those people who defined $stylesheet in a config file3568if(defined$stylesheet) {3569print'<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";3570}else{3571foreachmy$stylesheet(@stylesheets) {3572next unless$stylesheet;3573print'<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";3574}3575}3576 print_feed_meta()3577if($statuseq'200 OK');3578if(defined$favicon) {3579printqq(<link rel="shortcut icon" href=").esc_url($favicon).qq(" type="image/png" />\n);3580}35813582print"</head>\n".3583"<body>\n";35843585if(defined$site_header&& -f $site_header) {3586 insert_file($site_header);3587}35883589print"<div class=\"page_header\">\n".3590$cgi->a({-href => esc_url($logo_url),3591-title =>$logo_label},3592qq(<img src=").esc_url($logo).qq(" width="72" height="27" alt="git" class="logo"/>));3593print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3594if(defined$project) {3595print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3596if(defined$action) {3597my$action_print=$action;3598if(defined$opts{-action_extra}) {3599$action_print=$cgi->a({-href => href(action=>$action)},3600$action);3601}3602print" /$action_print";3603}3604if(defined$opts{-action_extra}) {3605print" /$opts{-action_extra}";3606}3607print"\n";3608}3609print"</div>\n";36103611my$have_search= gitweb_check_feature('search');3612if(defined$project&&$have_search) {3613if(!defined$searchtext) {3614$searchtext="";3615}3616my$search_hash;3617if(defined$hash_base) {3618$search_hash=$hash_base;3619}elsif(defined$hash) {3620$search_hash=$hash;3621}else{3622$search_hash="HEAD";3623}3624my$action=$my_uri;3625my$use_pathinfo= gitweb_check_feature('pathinfo');3626if($use_pathinfo) {3627$action.="/".esc_url($project);3628}3629print$cgi->startform(-method=>"get", -action =>$action) .3630"<div class=\"search\">\n".3631(!$use_pathinfo&&3632$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3633$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3634$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3635$cgi->popup_menu(-name =>'st', -default=>'commit',3636-values=> ['commit','grep','author','committer','pickaxe']) .3637$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3638" search:\n",3639$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3640"<span title=\"Extended regular expression\">".3641$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3642-checked =>$search_use_regexp) .3643"</span>".3644"</div>".3645$cgi->end_form() ."\n";3646}3647}36483649sub git_footer_html {3650my$feed_class='rss_logo';36513652print"<div class=\"page_footer\">\n";3653if(defined$project) {3654my$descr= git_get_project_description($project);3655if(defined$descr) {3656print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3657}36583659my%href_params= get_feed_info();3660if(!%href_params) {3661$feed_class.=' generic';3662}3663$href_params{'-title'} ||='log';36643665foreachmy$formatqw(RSS Atom){3666$href_params{'action'} =lc($format);3667print$cgi->a({-href => href(%href_params),3668-title =>"$href_params{'-title'}$formatfeed",3669-class=>$feed_class},$format)."\n";3670}36713672}else{3673print$cgi->a({-href => href(project=>undef, action=>"opml"),3674-class=>$feed_class},"OPML") ." ";3675print$cgi->a({-href => href(project=>undef, action=>"project_index"),3676-class=>$feed_class},"TXT") ."\n";3677}3678print"</div>\n";# class="page_footer"36793680if(defined$t0&& gitweb_check_feature('timed')) {3681print"<div id=\"generating_info\">\n";3682print'This page took '.3683'<span id="generating_time" class="time_span">'.3684 tv_interval($t0, [ gettimeofday() ]).3685' seconds </span>'.3686' and '.3687'<span id="generating_cmd">'.3688$number_of_git_cmds.3689'</span> git commands '.3690" to generate.\n";3691print"</div>\n";# class="page_footer"3692}36933694if(defined$site_footer&& -f $site_footer) {3695 insert_file($site_footer);3696}36973698print qq!<script type="text/javascript" src="!.esc_url($javascript).qq!"></script>\n!;3699if(defined$action&&3700$actioneq'blame_incremental') {3701print qq!<script type="text/javascript">\n!.3702 qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.3703 qq!"!. href() .qq!");\n!.3704 qq!</script>\n!;3705}elsif(gitweb_check_feature('javascript-actions')) {3706print qq!<script type="text/javascript">\n!.3707 qq!window.onload = fixLinks;\n!.3708 qq!</script>\n!;3709}37103711print"</body>\n".3712"</html>";3713}37143715# die_error(<http_status_code>, <error_message>[, <detailed_html_description>])3716# Example: die_error(404, 'Hash not found')3717# By convention, use the following status codes (as defined in RFC 2616):3718# 400: Invalid or missing CGI parameters, or3719# requested object exists but has wrong type.3720# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3721# this server or project.3722# 404: Requested object/revision/project doesn't exist.3723# 500: The server isn't configured properly, or3724# an internal error occurred (e.g. failed assertions caused by bugs), or3725# an unknown error occurred (e.g. the git binary died unexpectedly).3726# 503: The server is currently unavailable (because it is overloaded,3727# or down for maintenance). Generally, this is a temporary state.3728sub die_error {3729my$status=shift||500;3730my$error= esc_html(shift) ||"Internal Server Error";3731my$extra=shift;3732my%opts=@_;37333734my%http_responses= (3735400=>'400 Bad Request',3736403=>'403 Forbidden',3737404=>'404 Not Found',3738500=>'500 Internal Server Error',3739503=>'503 Service Unavailable',3740);3741 git_header_html($http_responses{$status},undef,%opts);3742print<<EOF;3743<div class="page_body">3744<br /><br />3745$status-$error3746<br />3747EOF3748if(defined$extra) {3749print"<hr />\n".3750"$extra\n";3751}3752print"</div>\n";37533754 git_footer_html();3755goto DONE_GITWEB3756unless($opts{'-error_handler'});3757}37583759## ----------------------------------------------------------------------3760## functions printing or outputting HTML: navigation37613762sub git_print_page_nav {3763my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3764$extra=''if!defined$extra;# pager or formats37653766my@navs=qw(summary shortlog log commit commitdiff tree);3767if($suppress) {3768@navs=grep{$_ne$suppress}@navs;3769}37703771my%arg=map{$_=> {action=>$_} }@navs;3772if(defined$head) {3773for(qw(commit commitdiff)) {3774$arg{$_}{'hash'} =$head;3775}3776if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3777for(qw(shortlog log)) {3778$arg{$_}{'hash'} =$head;3779}3780}3781}37823783$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3784$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;37853786my@actions= gitweb_get_feature('actions');3787my%repl= (3788'%'=>'%',3789'n'=>$project,# project name3790'f'=>$git_dir,# project path within filesystem3791'h'=>$treehead||'',# current hash ('h' parameter)3792'b'=>$treebase||'',# hash base ('hb' parameter)3793);3794while(@actions) {3795my($label,$link,$pos) =splice(@actions,0,3);3796# insert3797@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3798# munch munch3799$link=~s/%([%nfhb])/$repl{$1}/g;3800$arg{$label}{'_href'} =$link;3801}38023803print"<div class=\"page_nav\">\n".3804(join" | ",3805map{$_eq$current?3806$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3807}@navs);3808print"<br/>\n$extra<br/>\n".3809"</div>\n";3810}38113812# returns a submenu for the nagivation of the refs views (tags, heads,3813# remotes) with the current view disabled and the remotes view only3814# available if the feature is enabled3815sub format_ref_views {3816my($current) =@_;3817my@ref_views=qw{tags heads};3818push@ref_views,'remotes'if gitweb_check_feature('remote_heads');3819returnjoin" | ",map{3820$_eq$current?$_:3821$cgi->a({-href => href(action=>$_)},$_)3822}@ref_views3823}38243825sub format_paging_nav {3826my($action,$page,$has_next_link) =@_;3827my$paging_nav;382838293830if($page>0) {3831$paging_nav.=3832$cgi->a({-href => href(-replay=>1, page=>undef)},"first") .3833" ⋅ ".3834$cgi->a({-href => href(-replay=>1, page=>$page-1),3835-accesskey =>"p", -title =>"Alt-p"},"prev");3836}else{3837$paging_nav.="first ⋅ prev";3838}38393840if($has_next_link) {3841$paging_nav.=" ⋅ ".3842$cgi->a({-href => href(-replay=>1, page=>$page+1),3843-accesskey =>"n", -title =>"Alt-n"},"next");3844}else{3845$paging_nav.=" ⋅ next";3846}38473848return$paging_nav;3849}38503851## ......................................................................3852## functions printing or outputting HTML: div38533854sub git_print_header_div {3855my($action,$title,$hash,$hash_base) =@_;3856my%args= ();38573858$args{'action'} =$action;3859$args{'hash'} =$hashif$hash;3860$args{'hash_base'} =$hash_baseif$hash_base;38613862print"<div class=\"header\">\n".3863$cgi->a({-href => href(%args), -class=>"title"},3864$title?$title:$action) .3865"\n</div>\n";3866}38673868sub format_repo_url {3869my($name,$url) =@_;3870return"<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";3871}38723873# Group output by placing it in a DIV element and adding a header.3874# Options for start_div() can be provided by passing a hash reference as the3875# first parameter to the function.3876# Options to git_print_header_div() can be provided by passing an array3877# reference. This must follow the options to start_div if they are present.3878# The content can be a scalar, which is output as-is, a scalar reference, which3879# is output after html escaping, an IO handle passed either as *handle or3880# *handle{IO}, or a function reference. In the latter case all following3881# parameters will be taken as argument to the content function call.3882sub git_print_section {3883my($div_args,$header_args,$content);3884my$arg=shift;3885if(ref($arg)eq'HASH') {3886$div_args=$arg;3887$arg=shift;3888}3889if(ref($arg)eq'ARRAY') {3890$header_args=$arg;3891$arg=shift;3892}3893$content=$arg;38943895print$cgi->start_div($div_args);3896 git_print_header_div(@$header_args);38973898if(ref($content)eq'CODE') {3899$content->(@_);3900}elsif(ref($content)eq'SCALAR') {3901print esc_html($$content);3902}elsif(ref($content)eq'GLOB'or ref($content)eq'IO::Handle') {3903print<$content>;3904}elsif(!ref($content) &&defined($content)) {3905print$content;3906}39073908print$cgi->end_div;3909}39103911sub print_local_time {3912print format_local_time(@_);3913}39143915sub format_local_time {3916my$localtime='';3917my%date=@_;3918if($date{'hour_local'} <6) {3919$localtime.=sprintf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3920$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3921}else{3922$localtime.=sprintf(" (%02d:%02d%s)",3923$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3924}39253926return$localtime;3927}39283929# Outputs the author name and date in long form3930sub git_print_authorship {3931my$co=shift;3932my%opts=@_;3933my$tag=$opts{-tag} ||'div';3934my$author=$co->{'author_name'};39353936my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3937print"<$tagclass=\"author_date\">".3938 format_search_author($author,"author", esc_html($author)) .3939" [$ad{'rfc2822'}";3940 print_local_time(%ad)if($opts{-localtime});3941print"]". git_get_avatar($co->{'author_email'}, -pad_before =>1)3942."</$tag>\n";3943}39443945# Outputs table rows containing the full author or committer information,3946# in the format expected for 'commit' view (& similar).3947# Parameters are a commit hash reference, followed by the list of people3948# to output information for. If the list is empty it defaults to both3949# author and committer.3950sub git_print_authorship_rows {3951my$co=shift;3952# too bad we can't use @people = @_ || ('author', 'committer')3953my@people=@_;3954@people= ('author','committer')unless@people;3955foreachmy$who(@people) {3956my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});3957print"<tr><td>$who</td><td>".3958 format_search_author($co->{"${who}_name"},$who,3959 esc_html($co->{"${who}_name"})) ." ".3960 format_search_author($co->{"${who}_email"},$who,3961 esc_html("<".$co->{"${who}_email"} .">")) .3962"</td><td rowspan=\"2\">".3963 git_get_avatar($co->{"${who}_email"}, -size =>'double') .3964"</td></tr>\n".3965"<tr>".3966"<td></td><td>$wd{'rfc2822'}";3967 print_local_time(%wd);3968print"</td>".3969"</tr>\n";3970}3971}39723973sub git_print_page_path {3974my$name=shift;3975my$type=shift;3976my$hb=shift;397739783979print"<div class=\"page_path\">";3980print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3981-title =>'tree root'}, to_utf8("[$project]"));3982print" / ";3983if(defined$name) {3984my@dirname=split'/',$name;3985my$basename=pop@dirname;3986my$fullname='';39873988foreachmy$dir(@dirname) {3989$fullname.= ($fullname?'/':'') .$dir;3990print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3991 hash_base=>$hb),3992-title =>$fullname}, esc_path($dir));3993print" / ";3994}3995if(defined$type&&$typeeq'blob') {3996print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3997 hash_base=>$hb),3998-title =>$name}, esc_path($basename));3999}elsif(defined$type&&$typeeq'tree') {4000print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,4001 hash_base=>$hb),4002-title =>$name}, esc_path($basename));4003print" / ";4004}else{4005print esc_path($basename);4006}4007}4008print"<br/></div>\n";4009}40104011sub git_print_log {4012my$log=shift;4013my%opts=@_;40144015if($opts{'-remove_title'}) {4016# remove title, i.e. first line of log4017shift@$log;4018}4019# remove leading empty lines4020while(defined$log->[0] &&$log->[0]eq"") {4021shift@$log;4022}40234024# print log4025my$signoff=0;4026my$empty=0;4027foreachmy$line(@$log) {4028if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {4029$signoff=1;4030$empty=0;4031if(!$opts{'-remove_signoff'}) {4032print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";4033next;4034}else{4035# remove signoff lines4036next;4037}4038}else{4039$signoff=0;4040}40414042# print only one empty line4043# do not print empty line after signoff4044if($lineeq"") {4045next if($empty||$signoff);4046$empty=1;4047}else{4048$empty=0;4049}40504051print format_log_line_html($line) ."<br/>\n";4052}40534054if($opts{'-final_empty_line'}) {4055# end with single empty line4056print"<br/>\n"unless$empty;4057}4058}40594060# return link target (what link points to)4061sub git_get_link_target {4062my$hash=shift;4063my$link_target;40644065# read link4066open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4067orreturn;4068{4069local$/=undef;4070$link_target= <$fd>;4071}4072close$fd4073orreturn;40744075return$link_target;4076}40774078# given link target, and the directory (basedir) the link is in,4079# return target of link relative to top directory (top tree);4080# return undef if it is not possible (including absolute links).4081sub normalize_link_target {4082my($link_target,$basedir) =@_;40834084# absolute symlinks (beginning with '/') cannot be normalized4085return if(substr($link_target,0,1)eq'/');40864087# normalize link target to path from top (root) tree (dir)4088my$path;4089if($basedir) {4090$path=$basedir.'/'.$link_target;4091}else{4092# we are in top (root) tree (dir)4093$path=$link_target;4094}40954096# remove //, /./, and /../4097my@path_parts;4098foreachmy$part(split('/',$path)) {4099# discard '.' and ''4100next if(!$part||$parteq'.');4101# handle '..'4102if($parteq'..') {4103if(@path_parts) {4104pop@path_parts;4105}else{4106# link leads outside repository (outside top dir)4107return;4108}4109}else{4110push@path_parts,$part;4111}4112}4113$path=join('/',@path_parts);41144115return$path;4116}41174118# print tree entry (row of git_tree), but without encompassing <tr> element4119sub git_print_tree_entry {4120my($t,$basedir,$hash_base,$have_blame) =@_;41214122my%base_key= ();4123$base_key{'hash_base'} =$hash_baseifdefined$hash_base;41244125# The format of a table row is: mode list link. Where mode is4126# the mode of the entry, list is the name of the entry, an href,4127# and link is the action links of the entry.41284129print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";4130if(exists$t->{'size'}) {4131print"<td class=\"size\">$t->{'size'}</td>\n";4132}4133if($t->{'type'}eq"blob") {4134print"<td class=\"list\">".4135$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4136 file_name=>"$basedir$t->{'name'}",%base_key),4137-class=>"list"}, esc_path($t->{'name'}));4138if(S_ISLNK(oct$t->{'mode'})) {4139my$link_target= git_get_link_target($t->{'hash'});4140if($link_target) {4141my$norm_target= normalize_link_target($link_target,$basedir);4142if(defined$norm_target) {4143print" -> ".4144$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,4145 file_name=>$norm_target),4146-title =>$norm_target}, esc_path($link_target));4147}else{4148print" -> ". esc_path($link_target);4149}4150}4151}4152print"</td>\n";4153print"<td class=\"link\">";4154print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4155 file_name=>"$basedir$t->{'name'}",%base_key)},4156"blob");4157if($have_blame) {4158print" | ".4159$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},4160 file_name=>"$basedir$t->{'name'}",%base_key)},4161"blame");4162}4163if(defined$hash_base) {4164print" | ".4165$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,4166 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},4167"history");4168}4169print" | ".4170$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,4171 file_name=>"$basedir$t->{'name'}")},4172"raw");4173print"</td>\n";41744175}elsif($t->{'type'}eq"tree") {4176print"<td class=\"list\">";4177print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},4178 file_name=>"$basedir$t->{'name'}",4179%base_key)},4180 esc_path($t->{'name'}));4181print"</td>\n";4182print"<td class=\"link\">";4183print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},4184 file_name=>"$basedir$t->{'name'}",4185%base_key)},4186"tree");4187if(defined$hash_base) {4188print" | ".4189$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,4190 file_name=>"$basedir$t->{'name'}")},4191"history");4192}4193print"</td>\n";4194}else{4195# unknown object: we can only present history for it4196# (this includes 'commit' object, i.e. submodule support)4197print"<td class=\"list\">".4198 esc_path($t->{'name'}) .4199"</td>\n";4200print"<td class=\"link\">";4201if(defined$hash_base) {4202print$cgi->a({-href => href(action=>"history",4203 hash_base=>$hash_base,4204 file_name=>"$basedir$t->{'name'}")},4205"history");4206}4207print"</td>\n";4208}4209}42104211## ......................................................................4212## functions printing large fragments of HTML42134214# get pre-image filenames for merge (combined) diff4215sub fill_from_file_info {4216my($diff,@parents) =@_;42174218$diff->{'from_file'} = [ ];4219$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;4220for(my$i=0;$i<$diff->{'nparents'};$i++) {4221if($diff->{'status'}[$i]eq'R'||4222$diff->{'status'}[$i]eq'C') {4223$diff->{'from_file'}[$i] =4224 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);4225}4226}42274228return$diff;4229}42304231# is current raw difftree line of file deletion4232sub is_deleted {4233my$diffinfo=shift;42344235return$diffinfo->{'to_id'}eq('0' x 40);4236}42374238# does patch correspond to [previous] difftree raw line4239# $diffinfo - hashref of parsed raw diff format4240# $patchinfo - hashref of parsed patch diff format4241# (the same keys as in $diffinfo)4242sub is_patch_split {4243my($diffinfo,$patchinfo) =@_;42444245returndefined$diffinfo&&defined$patchinfo4246&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};4247}424842494250sub git_difftree_body {4251my($difftree,$hash,@parents) =@_;4252my($parent) =$parents[0];4253my$have_blame= gitweb_check_feature('blame');4254print"<div class=\"list_head\">\n";4255if($#{$difftree} >10) {4256print(($#{$difftree} +1) ." files changed:\n");4257}4258print"</div>\n";42594260print"<table class=\"".4261(@parents>1?"combined ":"") .4262"diff_tree\">\n";42634264# header only for combined diff in 'commitdiff' view4265my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';4266if($has_header) {4267# table header4268print"<thead><tr>\n".4269"<th></th><th></th>\n";# filename, patchN link4270for(my$i=0;$i<@parents;$i++) {4271my$par=$parents[$i];4272print"<th>".4273$cgi->a({-href => href(action=>"commitdiff",4274 hash=>$hash, hash_parent=>$par),4275-title =>'commitdiff to parent number '.4276($i+1) .': '.substr($par,0,7)},4277$i+1) .4278" </th>\n";4279}4280print"</tr></thead>\n<tbody>\n";4281}42824283my$alternate=1;4284my$patchno=0;4285foreachmy$line(@{$difftree}) {4286my$diff= parsed_difftree_line($line);42874288if($alternate) {4289print"<tr class=\"dark\">\n";4290}else{4291print"<tr class=\"light\">\n";4292}4293$alternate^=1;42944295if(exists$diff->{'nparents'}) {# combined diff42964297 fill_from_file_info($diff,@parents)4298unlessexists$diff->{'from_file'};42994300if(!is_deleted($diff)) {4301# file exists in the result (child) commit4302print"<td>".4303$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4304 file_name=>$diff->{'to_file'},4305 hash_base=>$hash),4306-class=>"list"}, esc_path($diff->{'to_file'})) .4307"</td>\n";4308}else{4309print"<td>".4310 esc_path($diff->{'to_file'}) .4311"</td>\n";4312}43134314if($actioneq'commitdiff') {4315# link to patch4316$patchno++;4317print"<td class=\"link\">".4318$cgi->a({-href =>"#patch$patchno"},"patch") .4319" | ".4320"</td>\n";4321}43224323my$has_history=0;4324my$not_deleted=0;4325for(my$i=0;$i<$diff->{'nparents'};$i++) {4326my$hash_parent=$parents[$i];4327my$from_hash=$diff->{'from_id'}[$i];4328my$from_path=$diff->{'from_file'}[$i];4329my$status=$diff->{'status'}[$i];43304331$has_history||= ($statusne'A');4332$not_deleted||= ($statusne'D');43334334if($statuseq'A') {4335print"<td class=\"link\"align=\"right\"> | </td>\n";4336}elsif($statuseq'D') {4337print"<td class=\"link\">".4338$cgi->a({-href => href(action=>"blob",4339 hash_base=>$hash,4340 hash=>$from_hash,4341 file_name=>$from_path)},4342"blob". ($i+1)) .4343" | </td>\n";4344}else{4345if($diff->{'to_id'}eq$from_hash) {4346print"<td class=\"link nochange\">";4347}else{4348print"<td class=\"link\">";4349}4350print$cgi->a({-href => href(action=>"blobdiff",4351 hash=>$diff->{'to_id'},4352 hash_parent=>$from_hash,4353 hash_base=>$hash,4354 hash_parent_base=>$hash_parent,4355 file_name=>$diff->{'to_file'},4356 file_parent=>$from_path)},4357"diff". ($i+1)) .4358" | </td>\n";4359}4360}43614362print"<td class=\"link\">";4363if($not_deleted) {4364print$cgi->a({-href => href(action=>"blob",4365 hash=>$diff->{'to_id'},4366 file_name=>$diff->{'to_file'},4367 hash_base=>$hash)},4368"blob");4369print" | "if($has_history);4370}4371if($has_history) {4372print$cgi->a({-href => href(action=>"history",4373 file_name=>$diff->{'to_file'},4374 hash_base=>$hash)},4375"history");4376}4377print"</td>\n";43784379print"</tr>\n";4380next;# instead of 'else' clause, to avoid extra indent4381}4382# else ordinary diff43834384my($to_mode_oct,$to_mode_str,$to_file_type);4385my($from_mode_oct,$from_mode_str,$from_file_type);4386if($diff->{'to_mode'}ne('0' x 6)) {4387$to_mode_oct=oct$diff->{'to_mode'};4388if(S_ISREG($to_mode_oct)) {# only for regular file4389$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits4390}4391$to_file_type= file_type($diff->{'to_mode'});4392}4393if($diff->{'from_mode'}ne('0' x 6)) {4394$from_mode_oct=oct$diff->{'from_mode'};4395if(S_ISREG($to_mode_oct)) {# only for regular file4396$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits4397}4398$from_file_type= file_type($diff->{'from_mode'});4399}44004401if($diff->{'status'}eq"A") {# created4402my$mode_chng="<span class=\"file_status new\">[new$to_file_type";4403$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;4404$mode_chng.="]</span>";4405print"<td>";4406print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4407 hash_base=>$hash, file_name=>$diff->{'file'}),4408-class=>"list"}, esc_path($diff->{'file'}));4409print"</td>\n";4410print"<td>$mode_chng</td>\n";4411print"<td class=\"link\">";4412if($actioneq'commitdiff') {4413# link to patch4414$patchno++;4415print$cgi->a({-href =>"#patch$patchno"},"patch");4416print" | ";4417}4418print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4419 hash_base=>$hash, file_name=>$diff->{'file'})},4420"blob");4421print"</td>\n";44224423}elsif($diff->{'status'}eq"D") {# deleted4424my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";4425print"<td>";4426print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4427 hash_base=>$parent, file_name=>$diff->{'file'}),4428-class=>"list"}, esc_path($diff->{'file'}));4429print"</td>\n";4430print"<td>$mode_chng</td>\n";4431print"<td class=\"link\">";4432if($actioneq'commitdiff') {4433# link to patch4434$patchno++;4435print$cgi->a({-href =>"#patch$patchno"},"patch");4436print" | ";4437}4438print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4439 hash_base=>$parent, file_name=>$diff->{'file'})},4440"blob") ." | ";4441if($have_blame) {4442print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,4443 file_name=>$diff->{'file'})},4444"blame") ." | ";4445}4446print$cgi->a({-href => href(action=>"history", hash_base=>$parent,4447 file_name=>$diff->{'file'})},4448"history");4449print"</td>\n";44504451}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed4452my$mode_chnge="";4453if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4454$mode_chnge="<span class=\"file_status mode_chnge\">[changed";4455if($from_file_typene$to_file_type) {4456$mode_chnge.=" from$from_file_typeto$to_file_type";4457}4458if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {4459if($from_mode_str&&$to_mode_str) {4460$mode_chnge.=" mode:$from_mode_str->$to_mode_str";4461}elsif($to_mode_str) {4462$mode_chnge.=" mode:$to_mode_str";4463}4464}4465$mode_chnge.="]</span>\n";4466}4467print"<td>";4468print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4469 hash_base=>$hash, file_name=>$diff->{'file'}),4470-class=>"list"}, esc_path($diff->{'file'}));4471print"</td>\n";4472print"<td>$mode_chnge</td>\n";4473print"<td class=\"link\">";4474if($actioneq'commitdiff') {4475# link to patch4476$patchno++;4477print$cgi->a({-href =>"#patch$patchno"},"patch") .4478" | ";4479}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4480# "commit" view and modified file (not onlu mode changed)4481print$cgi->a({-href => href(action=>"blobdiff",4482 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4483 hash_base=>$hash, hash_parent_base=>$parent,4484 file_name=>$diff->{'file'})},4485"diff") .4486" | ";4487}4488print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4489 hash_base=>$hash, file_name=>$diff->{'file'})},4490"blob") ." | ";4491if($have_blame) {4492print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4493 file_name=>$diff->{'file'})},4494"blame") ." | ";4495}4496print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4497 file_name=>$diff->{'file'})},4498"history");4499print"</td>\n";45004501}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied4502my%status_name= ('R'=>'moved','C'=>'copied');4503my$nstatus=$status_name{$diff->{'status'}};4504my$mode_chng="";4505if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4506# mode also for directories, so we cannot use $to_mode_str4507$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);4508}4509print"<td>".4510$cgi->a({-href => href(action=>"blob", hash_base=>$hash,4511 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),4512-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".4513"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".4514$cgi->a({-href => href(action=>"blob", hash_base=>$parent,4515 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),4516-class=>"list"}, esc_path($diff->{'from_file'})) .4517" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".4518"<td class=\"link\">";4519if($actioneq'commitdiff') {4520# link to patch4521$patchno++;4522print$cgi->a({-href =>"#patch$patchno"},"patch") .4523" | ";4524}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4525# "commit" view and modified file (not only pure rename or copy)4526print$cgi->a({-href => href(action=>"blobdiff",4527 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4528 hash_base=>$hash, hash_parent_base=>$parent,4529 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},4530"diff") .4531" | ";4532}4533print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4534 hash_base=>$parent, file_name=>$diff->{'to_file'})},4535"blob") ." | ";4536if($have_blame) {4537print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4538 file_name=>$diff->{'to_file'})},4539"blame") ." | ";4540}4541print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4542 file_name=>$diff->{'to_file'})},4543"history");4544print"</td>\n";45454546}# we should not encounter Unmerged (U) or Unknown (X) status4547print"</tr>\n";4548}4549print"</tbody>"if$has_header;4550print"</table>\n";4551}45524553sub git_patchset_body {4554my($fd,$difftree,$hash,@hash_parents) =@_;4555my($hash_parent) =$hash_parents[0];45564557my$is_combined= (@hash_parents>1);4558my$patch_idx=0;4559my$patch_number=0;4560my$patch_line;4561my$diffinfo;4562my$to_name;4563my(%from,%to);45644565print"<div class=\"patchset\">\n";45664567# skip to first patch4568while($patch_line= <$fd>) {4569chomp$patch_line;45704571last if($patch_line=~m/^diff /);4572}45734574 PATCH:4575while($patch_line) {45764577# parse "git diff" header line4578if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {4579# $1 is from_name, which we do not use4580$to_name= unquote($2);4581$to_name=~s!^b/!!;4582}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {4583# $1 is 'cc' or 'combined', which we do not use4584$to_name= unquote($2);4585}else{4586$to_name=undef;4587}45884589# check if current patch belong to current raw line4590# and parse raw git-diff line if needed4591if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {4592# this is continuation of a split patch4593print"<div class=\"patch cont\">\n";4594}else{4595# advance raw git-diff output if needed4596$patch_idx++ifdefined$diffinfo;45974598# read and prepare patch information4599$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);46004601# compact combined diff output can have some patches skipped4602# find which patch (using pathname of result) we are at now;4603if($is_combined) {4604while($to_namene$diffinfo->{'to_file'}) {4605print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4606 format_diff_cc_simplified($diffinfo,@hash_parents) .4607"</div>\n";# class="patch"46084609$patch_idx++;4610$patch_number++;46114612last if$patch_idx>$#$difftree;4613$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);4614}4615}46164617# modifies %from, %to hashes4618 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);46194620# this is first patch for raw difftree line with $patch_idx index4621# we index @$difftree array from 0, but number patches from 14622print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";4623}46244625# git diff header4626#assert($patch_line =~ m/^diff /) if DEBUG;4627#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed4628$patch_number++;4629# print "git diff" header4630print format_git_diff_header_line($patch_line,$diffinfo,4631 \%from, \%to);46324633# print extended diff header4634print"<div class=\"diff extended_header\">\n";4635 EXTENDED_HEADER:4636while($patch_line= <$fd>) {4637chomp$patch_line;46384639last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);46404641print format_extended_diff_header_line($patch_line,$diffinfo,4642 \%from, \%to);4643}4644print"</div>\n";# class="diff extended_header"46454646# from-file/to-file diff header4647if(!$patch_line) {4648print"</div>\n";# class="patch"4649last PATCH;4650}4651next PATCH if($patch_line=~m/^diff /);4652#assert($patch_line =~ m/^---/) if DEBUG;46534654my$last_patch_line=$patch_line;4655$patch_line= <$fd>;4656chomp$patch_line;4657#assert($patch_line =~ m/^\+\+\+/) if DEBUG;46584659print format_diff_from_to_header($last_patch_line,$patch_line,4660$diffinfo, \%from, \%to,4661@hash_parents);46624663# the patch itself4664 LINE:4665while($patch_line= <$fd>) {4666chomp$patch_line;46674668next PATCH if($patch_line=~m/^diff /);46694670print format_diff_line($patch_line, \%from, \%to);4671}46724673}continue{4674print"</div>\n";# class="patch"4675}46764677# for compact combined (--cc) format, with chunk and patch simplification4678# the patchset might be empty, but there might be unprocessed raw lines4679for(++$patch_idxif$patch_number>0;4680$patch_idx<@$difftree;4681++$patch_idx) {4682# read and prepare patch information4683$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);46844685# generate anchor for "patch" links in difftree / whatchanged part4686print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4687 format_diff_cc_simplified($diffinfo,@hash_parents) .4688"</div>\n";# class="patch"46894690$patch_number++;4691}46924693if($patch_number==0) {4694if(@hash_parents>1) {4695print"<div class=\"diff nodifferences\">Trivial merge</div>\n";4696}else{4697print"<div class=\"diff nodifferences\">No differences found</div>\n";4698}4699}47004701print"</div>\n";# class="patchset"4702}47034704# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .47054706# fills project list info (age, description, owner, forks) for each4707# project in the list, removing invalid projects from returned list4708# NOTE: modifies $projlist, but does not remove entries from it4709sub fill_project_list_info {4710my($projlist,$check_forks) =@_;4711my@projects;47124713my$show_ctags= gitweb_check_feature('ctags');4714 PROJECT:4715foreachmy$pr(@$projlist) {4716my(@activity) = git_get_last_activity($pr->{'path'});4717unless(@activity) {4718next PROJECT;4719}4720($pr->{'age'},$pr->{'age_string'}) =@activity;4721if(!defined$pr->{'descr'}) {4722my$descr= git_get_project_description($pr->{'path'}) ||"";4723$descr= to_utf8($descr);4724$pr->{'descr_long'} =$descr;4725$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4726}4727if(!defined$pr->{'owner'}) {4728$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4729}4730if($check_forks) {4731my$pname=$pr->{'path'};4732if(($pname=~s/\.git$//) &&4733($pname!~/\/$/) &&4734(-d "$projectroot/$pname")) {4735$pr->{'forks'} ="-d$projectroot/$pname";4736}else{4737$pr->{'forks'} =0;4738}4739}4740$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4741push@projects,$pr;4742}47434744return@projects;4745}47464747# print 'sort by' <th> element, generating 'sort by $name' replay link4748# if that order is not selected4749sub print_sort_th {4750print format_sort_th(@_);4751}47524753sub format_sort_th {4754my($name,$order,$header) =@_;4755my$sort_th="";4756$header||=ucfirst($name);47574758if($ordereq$name) {4759$sort_th.="<th>$header</th>\n";4760}else{4761$sort_th.="<th>".4762$cgi->a({-href => href(-replay=>1, order=>$name),4763-class=>"header"},$header) .4764"</th>\n";4765}47664767return$sort_th;4768}47694770sub git_project_list_body {4771# actually uses global variable $project4772my($projlist,$order,$from,$to,$extra,$no_header) =@_;47734774my$check_forks= gitweb_check_feature('forks');4775my@projects= fill_project_list_info($projlist,$check_forks);47764777$order||=$default_projects_order;4778$from=0unlessdefined$from;4779$to=$#projectsif(!defined$to||$#projects<$to);47804781my%order_info= (4782 project => { key =>'path', type =>'str'},4783 descr => { key =>'descr_long', type =>'str'},4784 owner => { key =>'owner', type =>'str'},4785 age => { key =>'age', type =>'num'}4786);4787my$oi=$order_info{$order};4788if($oi->{'type'}eq'str') {4789@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4790}else{4791@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4792}47934794my$show_ctags= gitweb_check_feature('ctags');4795if($show_ctags) {4796my%ctags;4797foreachmy$p(@projects) {4798foreachmy$ct(keys%{$p->{'ctags'}}) {4799$ctags{$ct} +=$p->{'ctags'}->{$ct};4800}4801}4802my$cloud= git_populate_project_tagcloud(\%ctags);4803print git_show_project_tagcloud($cloud,64);4804}48054806print"<table class=\"project_list\">\n";4807unless($no_header) {4808print"<tr>\n";4809if($check_forks) {4810print"<th></th>\n";4811}4812 print_sort_th('project',$order,'Project');4813 print_sort_th('descr',$order,'Description');4814 print_sort_th('owner',$order,'Owner');4815 print_sort_th('age',$order,'Last Change');4816print"<th></th>\n".# for links4817"</tr>\n";4818}4819my$alternate=1;4820my$tagfilter=$cgi->param('by_tag');4821for(my$i=$from;$i<=$to;$i++) {4822my$pr=$projects[$i];48234824next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4825next if$searchtextand not$pr->{'path'} =~/$searchtext/4826and not$pr->{'descr_long'} =~/$searchtext/;4827# Weed out forks or non-matching entries of search4828if($check_forks) {4829my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4830$forkbase="^$forkbase"if$forkbase;4831next ifnot$searchtextand not$tagfilterand$show_ctags4832and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4833}48344835if($alternate) {4836print"<tr class=\"dark\">\n";4837}else{4838print"<tr class=\"light\">\n";4839}4840$alternate^=1;4841if($check_forks) {4842print"<td>";4843if($pr->{'forks'}) {4844print"<!--$pr->{'forks'} -->\n";4845print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4846}4847print"</td>\n";4848}4849print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4850-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4851"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4852-class=>"list", -title =>$pr->{'descr_long'}},4853 esc_html($pr->{'descr'})) ."</td>\n".4854"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4855print"<td class=\"". age_class($pr->{'age'}) ."\">".4856(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4857"<td class=\"link\">".4858$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4859$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4860$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4861$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4862($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4863"</td>\n".4864"</tr>\n";4865}4866if(defined$extra) {4867print"<tr>\n";4868if($check_forks) {4869print"<td></td>\n";4870}4871print"<td colspan=\"5\">$extra</td>\n".4872"</tr>\n";4873}4874print"</table>\n";4875}48764877sub git_log_body {4878# uses global variable $project4879my($commitlist,$from,$to,$refs,$extra) =@_;48804881$from=0unlessdefined$from;4882$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);48834884for(my$i=0;$i<=$to;$i++) {4885my%co= %{$commitlist->[$i]};4886next if!%co;4887my$commit=$co{'id'};4888my$ref= format_ref_marker($refs,$commit);4889my%ad= parse_date($co{'author_epoch'});4890 git_print_header_div('commit',4891"<span class=\"age\">$co{'age_string'}</span>".4892 esc_html($co{'title'}) .$ref,4893$commit);4894print"<div class=\"title_text\">\n".4895"<div class=\"log_link\">\n".4896$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .4897" | ".4898$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .4899" | ".4900$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .4901"<br/>\n".4902"</div>\n";4903 git_print_authorship(\%co, -tag =>'span');4904print"<br/>\n</div>\n";49054906print"<div class=\"log_body\">\n";4907 git_print_log($co{'comment'}, -final_empty_line=>1);4908print"</div>\n";4909}4910if($extra) {4911print"<div class=\"page_nav\">\n";4912print"$extra\n";4913print"</div>\n";4914}4915}49164917sub git_shortlog_body {4918# uses global variable $project4919my($commitlist,$from,$to,$refs,$extra) =@_;49204921$from=0unlessdefined$from;4922$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);49234924print"<table class=\"shortlog\">\n";4925my$alternate=1;4926for(my$i=$from;$i<=$to;$i++) {4927my%co= %{$commitlist->[$i]};4928my$commit=$co{'id'};4929my$ref= format_ref_marker($refs,$commit);4930if($alternate) {4931print"<tr class=\"dark\">\n";4932}else{4933print"<tr class=\"light\">\n";4934}4935$alternate^=1;4936# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4937print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4938 format_author_html('td', \%co,10) ."<td>";4939print format_subject_html($co{'title'},$co{'title_short'},4940 href(action=>"commit", hash=>$commit),$ref);4941print"</td>\n".4942"<td class=\"link\">".4943$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4944$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4945$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4946my$snapshot_links= format_snapshot_links($commit);4947if(defined$snapshot_links) {4948print" | ".$snapshot_links;4949}4950print"</td>\n".4951"</tr>\n";4952}4953if(defined$extra) {4954print"<tr>\n".4955"<td colspan=\"4\">$extra</td>\n".4956"</tr>\n";4957}4958print"</table>\n";4959}49604961sub git_history_body {4962# Warning: assumes constant type (blob or tree) during history4963my($commitlist,$from,$to,$refs,$extra,4964$file_name,$file_hash,$ftype) =@_;49654966$from=0unlessdefined$from;4967$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});49684969print"<table class=\"history\">\n";4970my$alternate=1;4971for(my$i=$from;$i<=$to;$i++) {4972my%co= %{$commitlist->[$i]};4973if(!%co) {4974next;4975}4976my$commit=$co{'id'};49774978my$ref= format_ref_marker($refs,$commit);49794980if($alternate) {4981print"<tr class=\"dark\">\n";4982}else{4983print"<tr class=\"light\">\n";4984}4985$alternate^=1;4986print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4987# shortlog: format_author_html('td', \%co, 10)4988 format_author_html('td', \%co,15,3) ."<td>";4989# originally git_history used chop_str($co{'title'}, 50)4990print format_subject_html($co{'title'},$co{'title_short'},4991 href(action=>"commit", hash=>$commit),$ref);4992print"</td>\n".4993"<td class=\"link\">".4994$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4995$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");49964997if($ftypeeq'blob') {4998my$blob_current=$file_hash;4999my$blob_parent= git_get_hash_by_path($commit,$file_name);5000if(defined$blob_current&&defined$blob_parent&&5001$blob_currentne$blob_parent) {5002print" | ".5003$cgi->a({-href => href(action=>"blobdiff",5004 hash=>$blob_current, hash_parent=>$blob_parent,5005 hash_base=>$hash_base, hash_parent_base=>$commit,5006 file_name=>$file_name)},5007"diff to current");5008}5009}5010print"</td>\n".5011"</tr>\n";5012}5013if(defined$extra) {5014print"<tr>\n".5015"<td colspan=\"4\">$extra</td>\n".5016"</tr>\n";5017}5018print"</table>\n";5019}50205021sub git_tags_body {5022# uses global variable $project5023my($taglist,$from,$to,$extra) =@_;5024$from=0unlessdefined$from;5025$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);50265027print"<table class=\"tags\">\n";5028my$alternate=1;5029for(my$i=$from;$i<=$to;$i++) {5030my$entry=$taglist->[$i];5031my%tag=%$entry;5032my$comment=$tag{'subject'};5033my$comment_short;5034if(defined$comment) {5035$comment_short= chop_str($comment,30,5);5036}5037if($alternate) {5038print"<tr class=\"dark\">\n";5039}else{5040print"<tr class=\"light\">\n";5041}5042$alternate^=1;5043if(defined$tag{'age'}) {5044print"<td><i>$tag{'age'}</i></td>\n";5045}else{5046print"<td></td>\n";5047}5048print"<td>".5049$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),5050-class=>"list name"}, esc_html($tag{'name'})) .5051"</td>\n".5052"<td>";5053if(defined$comment) {5054print format_subject_html($comment,$comment_short,5055 href(action=>"tag", hash=>$tag{'id'}));5056}5057print"</td>\n".5058"<td class=\"selflink\">";5059if($tag{'type'}eq"tag") {5060print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");5061}else{5062print" ";5063}5064print"</td>\n".5065"<td class=\"link\">"." | ".5066$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});5067if($tag{'reftype'}eq"commit") {5068print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .5069" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");5070}elsif($tag{'reftype'}eq"blob") {5071print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");5072}5073print"</td>\n".5074"</tr>";5075}5076if(defined$extra) {5077print"<tr>\n".5078"<td colspan=\"5\">$extra</td>\n".5079"</tr>\n";5080}5081print"</table>\n";5082}50835084sub git_heads_body {5085# uses global variable $project5086my($headlist,$head,$from,$to,$extra) =@_;5087$from=0unlessdefined$from;5088$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);50895090print"<table class=\"heads\">\n";5091my$alternate=1;5092for(my$i=$from;$i<=$to;$i++) {5093my$entry=$headlist->[$i];5094my%ref=%$entry;5095my$curr=$ref{'id'}eq$head;5096if($alternate) {5097print"<tr class=\"dark\">\n";5098}else{5099print"<tr class=\"light\">\n";5100}5101$alternate^=1;5102print"<td><i>$ref{'age'}</i></td>\n".5103($curr?"<td class=\"current_head\">":"<td>") .5104$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),5105-class=>"list name"},esc_html($ref{'name'})) .5106"</td>\n".5107"<td class=\"link\">".5108$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".5109$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".5110$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'fullname'})},"tree") .5111"</td>\n".5112"</tr>";5113}5114if(defined$extra) {5115print"<tr>\n".5116"<td colspan=\"3\">$extra</td>\n".5117"</tr>\n";5118}5119print"</table>\n";5120}51215122# Display a single remote block5123sub git_remote_block {5124my($remote,$rdata,$limit,$head) =@_;51255126my$heads=$rdata->{'heads'};5127my$fetch=$rdata->{'fetch'};5128my$push=$rdata->{'push'};51295130my$urls_table="<table class=\"projects_list\">\n";51315132if(defined$fetch) {5133if($fetcheq$push) {5134$urls_table.= format_repo_url("URL",$fetch);5135}else{5136$urls_table.= format_repo_url("Fetch URL",$fetch);5137$urls_table.= format_repo_url("Push URL",$push)ifdefined$push;5138}5139}elsif(defined$push) {5140$urls_table.= format_repo_url("Push URL",$push);5141}else{5142$urls_table.= format_repo_url("","No remote URL");5143}51445145$urls_table.="</table>\n";51465147my$dots;5148if(defined$limit&&$limit<@$heads) {5149$dots=$cgi->a({-href => href(action=>"remotes", hash=>$remote)},"...");5150}51515152print$urls_table;5153 git_heads_body($heads,$head,0,$limit,$dots);5154}51555156# Display a list of remote names with the respective fetch and push URLs5157sub git_remotes_list {5158my($remotedata,$limit) =@_;5159print"<table class=\"heads\">\n";5160my$alternate=1;5161my@remotes=sort keys%$remotedata;51625163my$limited=$limit&&$limit<@remotes;51645165$#remotes=$limit-1if$limited;51665167while(my$remote=shift@remotes) {5168my$rdata=$remotedata->{$remote};5169my$fetch=$rdata->{'fetch'};5170my$push=$rdata->{'push'};5171if($alternate) {5172print"<tr class=\"dark\">\n";5173}else{5174print"<tr class=\"light\">\n";5175}5176$alternate^=1;5177print"<td>".5178$cgi->a({-href=> href(action=>'remotes', hash=>$remote),5179-class=>"list name"},esc_html($remote)) .5180"</td>";5181print"<td class=\"link\">".5182(defined$fetch?$cgi->a({-href=>$fetch},"fetch") :"fetch") .5183" | ".5184(defined$push?$cgi->a({-href=>$push},"push") :"push") .5185"</td>";51865187print"</tr>\n";5188}51895190if($limited) {5191print"<tr>\n".5192"<td colspan=\"3\">".5193$cgi->a({-href => href(action=>"remotes")},"...") .5194"</td>\n"."</tr>\n";5195}51965197print"</table>";5198}51995200# Display remote heads grouped by remote, unless there are too many5201# remotes, in which case we only display the remote names5202sub git_remotes_body {5203my($remotedata,$limit,$head) =@_;5204if($limitand$limit<keys%$remotedata) {5205 git_remotes_list($remotedata,$limit);5206}else{5207 fill_remote_heads($remotedata);5208while(my($remote,$rdata) =each%$remotedata) {5209 git_print_section({-class=>"remote", -id=>$remote},5210["remotes",$remote,$remote],sub{5211 git_remote_block($remote,$rdata,$limit,$head);5212});5213}5214}5215}52165217sub git_search_grep_body {5218my($commitlist,$from,$to,$extra) =@_;5219$from=0unlessdefined$from;5220$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);52215222print"<table class=\"commit_search\">\n";5223my$alternate=1;5224for(my$i=$from;$i<=$to;$i++) {5225my%co= %{$commitlist->[$i]};5226if(!%co) {5227next;5228}5229my$commit=$co{'id'};5230if($alternate) {5231print"<tr class=\"dark\">\n";5232}else{5233print"<tr class=\"light\">\n";5234}5235$alternate^=1;5236print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5237 format_author_html('td', \%co,15,5) .5238"<td>".5239$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),5240-class=>"list subject"},5241 chop_and_escape_str($co{'title'},50) ."<br/>");5242my$comment=$co{'comment'};5243foreachmy$line(@$comment) {5244if($line=~m/^(.*?)($search_regexp)(.*)$/i) {5245my($lead,$match,$trail) = ($1,$2,$3);5246$match= chop_str($match,70,5,'center');5247my$contextlen=int((80-length($match))/2);5248$contextlen=30if($contextlen>30);5249$lead= chop_str($lead,$contextlen,10,'left');5250$trail= chop_str($trail,$contextlen,10,'right');52515252$lead= esc_html($lead);5253$match= esc_html($match);5254$trail= esc_html($trail);52555256print"$lead<span class=\"match\">$match</span>$trail<br />";5257}5258}5259print"</td>\n".5260"<td class=\"link\">".5261$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5262" | ".5263$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .5264" | ".5265$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5266print"</td>\n".5267"</tr>\n";5268}5269if(defined$extra) {5270print"<tr>\n".5271"<td colspan=\"3\">$extra</td>\n".5272"</tr>\n";5273}5274print"</table>\n";5275}52765277## ======================================================================5278## ======================================================================5279## actions52805281sub git_project_list {5282my$order=$input_params{'order'};5283if(defined$order&&$order!~m/none|project|descr|owner|age/) {5284 die_error(400,"Unknown order parameter");5285}52865287my@list= git_get_projects_list();5288if(!@list) {5289 die_error(404,"No projects found");5290}52915292 git_header_html();5293if(defined$home_text&& -f $home_text) {5294print"<div class=\"index_include\">\n";5295 insert_file($home_text);5296print"</div>\n";5297}5298print$cgi->startform(-method=>"get") .5299"<p class=\"projsearch\">Search:\n".5300$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".5301"</p>".5302$cgi->end_form() ."\n";5303 git_project_list_body(\@list,$order);5304 git_footer_html();5305}53065307sub git_forks {5308my$order=$input_params{'order'};5309if(defined$order&&$order!~m/none|project|descr|owner|age/) {5310 die_error(400,"Unknown order parameter");5311}53125313my@list= git_get_projects_list($project);5314if(!@list) {5315 die_error(404,"No forks found");5316}53175318 git_header_html();5319 git_print_page_nav('','');5320 git_print_header_div('summary',"$projectforks");5321 git_project_list_body(\@list,$order);5322 git_footer_html();5323}53245325sub git_project_index {5326my@projects= git_get_projects_list($project);53275328print$cgi->header(5329-type =>'text/plain',5330-charset =>'utf-8',5331-content_disposition =>'inline; filename="index.aux"');53325333foreachmy$pr(@projects) {5334if(!exists$pr->{'owner'}) {5335$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");5336}53375338my($path,$owner) = ($pr->{'path'},$pr->{'owner'});5339# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '5340$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;5341$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;5342$path=~s/ /\+/g;5343$owner=~s/ /\+/g;53445345print"$path$owner\n";5346}5347}53485349sub git_summary {5350my$descr= git_get_project_description($project) ||"none";5351my%co= parse_commit("HEAD");5352my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();5353my$head=$co{'id'};5354my$remote_heads= gitweb_check_feature('remote_heads');53555356my$owner= git_get_project_owner($project);53575358my$refs= git_get_references();5359# These get_*_list functions return one more to allow us to see if5360# there are more ...5361my@taglist= git_get_tags_list(16);5362my@headlist= git_get_heads_list(16);5363my%remotedata=$remote_heads? git_get_remotes_list() : ();5364my@forklist;5365my$check_forks= gitweb_check_feature('forks');53665367if($check_forks) {5368@forklist= git_get_projects_list($project);5369}53705371 git_header_html();5372 git_print_page_nav('summary','',$head);53735374print"<div class=\"title\"> </div>\n";5375print"<table class=\"projects_list\">\n".5376"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".5377"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";5378if(defined$cd{'rfc2822'}) {5379print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";5380}53815382# use per project git URL list in $projectroot/$project/cloneurl5383# or make project git URL from git base URL and project name5384my$url_tag="URL";5385my@url_list= git_get_project_url_list($project);5386@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;5387foreachmy$git_url(@url_list) {5388next unless$git_url;5389print format_repo_url($url_tag,$git_url);5390$url_tag="";5391}53925393# Tag cloud5394my$show_ctags= gitweb_check_feature('ctags');5395if($show_ctags) {5396my$ctags= git_get_project_ctags($project);5397my$cloud= git_populate_project_tagcloud($ctags);5398print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";5399print"</td>\n<td>"unless%$ctags;5400print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";5401print"</td>\n<td>"if%$ctags;5402print git_show_project_tagcloud($cloud,48);5403print"</td></tr>";5404}54055406print"</table>\n";54075408# If XSS prevention is on, we don't include README.html.5409# TODO: Allow a readme in some safe format.5410if(!$prevent_xss&& -s "$projectroot/$project/README.html") {5411print"<div class=\"title\">readme</div>\n".5412"<div class=\"readme\">\n";5413 insert_file("$projectroot/$project/README.html");5414print"\n</div>\n";# class="readme"5415}54165417# we need to request one more than 16 (0..15) to check if5418# those 16 are all5419my@commitlist=$head? parse_commits($head,17) : ();5420if(@commitlist) {5421 git_print_header_div('shortlog');5422 git_shortlog_body(\@commitlist,0,15,$refs,5423$#commitlist<=15?undef:5424$cgi->a({-href => href(action=>"shortlog")},"..."));5425}54265427if(@taglist) {5428 git_print_header_div('tags');5429 git_tags_body(\@taglist,0,15,5430$#taglist<=15?undef:5431$cgi->a({-href => href(action=>"tags")},"..."));5432}54335434if(@headlist) {5435 git_print_header_div('heads');5436 git_heads_body(\@headlist,$head,0,15,5437$#headlist<=15?undef:5438$cgi->a({-href => href(action=>"heads")},"..."));5439}54405441if(%remotedata) {5442 git_print_header_div('remotes');5443 git_remotes_body(\%remotedata,15,$head);5444}54455446if(@forklist) {5447 git_print_header_div('forks');5448 git_project_list_body(\@forklist,'age',0,15,5449$#forklist<=15?undef:5450$cgi->a({-href => href(action=>"forks")},"..."),5451'no_header');5452}54535454 git_footer_html();5455}54565457sub git_tag {5458my%tag= parse_tag($hash);54595460if(!%tag) {5461 die_error(404,"Unknown tag object");5462}54635464my$head= git_get_head_hash($project);5465 git_header_html();5466 git_print_page_nav('','',$head,undef,$head);5467 git_print_header_div('commit', esc_html($tag{'name'}),$hash);5468print"<div class=\"title_text\">\n".5469"<table class=\"object_header\">\n".5470"<tr>\n".5471"<td>object</td>\n".5472"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},5473$tag{'object'}) ."</td>\n".5474"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},5475$tag{'type'}) ."</td>\n".5476"</tr>\n";5477if(defined($tag{'author'})) {5478 git_print_authorship_rows(\%tag,'author');5479}5480print"</table>\n\n".5481"</div>\n";5482print"<div class=\"page_body\">";5483my$comment=$tag{'comment'};5484foreachmy$line(@$comment) {5485chomp$line;5486print esc_html($line, -nbsp=>1) ."<br/>\n";5487}5488print"</div>\n";5489 git_footer_html();5490}54915492sub git_blame_common {5493my$format=shift||'porcelain';5494if($formateq'porcelain'&&$cgi->param('js')) {5495$format='incremental';5496$action='blame_incremental';# for page title etc5497}54985499# permissions5500 gitweb_check_feature('blame')5501or die_error(403,"Blame view not allowed");55025503# error checking5504 die_error(400,"No file name given")unless$file_name;5505$hash_base||= git_get_head_hash($project);5506 die_error(404,"Couldn't find base commit")unless$hash_base;5507my%co= parse_commit($hash_base)5508or die_error(404,"Commit not found");5509my$ftype="blob";5510if(!defined$hash) {5511$hash= git_get_hash_by_path($hash_base,$file_name,"blob")5512or die_error(404,"Error looking up file");5513}else{5514$ftype= git_get_type($hash);5515if($ftype!~"blob") {5516 die_error(400,"Object is not a blob");5517}5518}55195520my$fd;5521if($formateq'incremental') {5522# get file contents (as base)5523open$fd,"-|", git_cmd(),'cat-file','blob',$hash5524or die_error(500,"Open git-cat-file failed");5525}elsif($formateq'data') {5526# run git-blame --incremental5527open$fd,"-|", git_cmd(),"blame","--incremental",5528$hash_base,"--",$file_name5529or die_error(500,"Open git-blame --incremental failed");5530}else{5531# run git-blame --porcelain5532open$fd,"-|", git_cmd(),"blame",'-p',5533$hash_base,'--',$file_name5534or die_error(500,"Open git-blame --porcelain failed");5535}55365537# incremental blame data returns early5538if($formateq'data') {5539print$cgi->header(5540-type=>"text/plain", -charset =>"utf-8",5541-status=>"200 OK");5542local$| =1;# output autoflush5543printwhile<$fd>;5544close$fd5545or print"ERROR$!\n";55465547print'END';5548if(defined$t0&& gitweb_check_feature('timed')) {5549print' '.5550 tv_interval($t0, [ gettimeofday() ]).5551' '.$number_of_git_cmds;5552}5553print"\n";55545555return;5556}55575558# page header5559 git_header_html();5560my$formats_nav=5561$cgi->a({-href => href(action=>"blob", -replay=>1)},5562"blob") .5563" | ";5564if($formateq'incremental') {5565$formats_nav.=5566$cgi->a({-href => href(action=>"blame", javascript=>0, -replay=>1)},5567"blame") ." (non-incremental)";5568}else{5569$formats_nav.=5570$cgi->a({-href => href(action=>"blame_incremental", -replay=>1)},5571"blame") ." (incremental)";5572}5573$formats_nav.=5574" | ".5575$cgi->a({-href => href(action=>"history", -replay=>1)},5576"history") .5577" | ".5578$cgi->a({-href => href(action=>$action, file_name=>$file_name)},5579"HEAD");5580 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5581 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5582 git_print_page_path($file_name,$ftype,$hash_base);55835584# page body5585if($formateq'incremental') {5586print"<noscript>\n<div class=\"error\"><center><b>\n".5587"This page requires JavaScript to run.\nUse ".5588$cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},5589'this page').5590" instead.\n".5591"</b></center></div>\n</noscript>\n";55925593print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!;5594}55955596print qq!<div class="page_body">\n!;5597print qq!<div id="progress_info">.../ ...</div>\n!5598if($formateq'incremental');5599print qq!<table id="blame_table"class="blame" width="100%">\n!.5600#qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.5601 qq!<thead>\n!.5602 qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!.5603 qq!</thead>\n!.5604 qq!<tbody>\n!;56055606my@rev_color=qw(light dark);5607my$num_colors=scalar(@rev_color);5608my$current_color=0;56095610if($formateq'incremental') {5611my$color_class=$rev_color[$current_color];56125613#contents of a file5614my$linenr=0;5615 LINE:5616while(my$line= <$fd>) {5617chomp$line;5618$linenr++;56195620print qq!<tr id="l$linenr"class="$color_class">!.5621 qq!<td class="sha1"><a href=""> </a></td>!.5622 qq!<td class="linenr">!.5623 qq!<a class="linenr" href="">$linenr</a></td>!;5624print qq!<td class="pre">! . esc_html($line) ."</td>\n";5625print qq!</tr>\n!;5626}56275628}else{# porcelain, i.e. ordinary blame5629my%metainfo= ();# saves information about commits56305631# blame data5632 LINE:5633while(my$line= <$fd>) {5634chomp$line;5635# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]5636# no <lines in group> for subsequent lines in group of lines5637my($full_rev,$orig_lineno,$lineno,$group_size) =5638($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);5639if(!exists$metainfo{$full_rev}) {5640$metainfo{$full_rev} = {'nprevious'=>0};5641}5642my$meta=$metainfo{$full_rev};5643my$data;5644while($data= <$fd>) {5645chomp$data;5646last if($data=~s/^\t//);# contents of line5647if($data=~/^(\S+)(?: (.*))?$/) {5648$meta->{$1} =$2unlessexists$meta->{$1};5649}5650if($data=~/^previous /) {5651$meta->{'nprevious'}++;5652}5653}5654my$short_rev=substr($full_rev,0,8);5655my$author=$meta->{'author'};5656my%date=5657 parse_date($meta->{'author-time'},$meta->{'author-tz'});5658my$date=$date{'iso-tz'};5659if($group_size) {5660$current_color= ($current_color+1) %$num_colors;5661}5662my$tr_class=$rev_color[$current_color];5663$tr_class.=' boundary'if(exists$meta->{'boundary'});5664$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);5665$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);5666print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";5667if($group_size) {5668print"<td class=\"sha1\"";5669print" title=\"". esc_html($author) .",$date\"";5670print" rowspan=\"$group_size\""if($group_size>1);5671print">";5672print$cgi->a({-href => href(action=>"commit",5673 hash=>$full_rev,5674 file_name=>$file_name)},5675 esc_html($short_rev));5676if($group_size>=2) {5677my@author_initials= ($author=~/\b([[:upper:]])\B/g);5678if(@author_initials) {5679print"<br />".5680 esc_html(join('',@author_initials));5681# or join('.', ...)5682}5683}5684print"</td>\n";5685}5686# 'previous' <sha1 of parent commit> <filename at commit>5687if(exists$meta->{'previous'} &&5688$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {5689$meta->{'parent'} =$1;5690$meta->{'file_parent'} = unquote($2);5691}5692my$linenr_commit=5693exists($meta->{'parent'}) ?5694$meta->{'parent'} :$full_rev;5695my$linenr_filename=5696exists($meta->{'file_parent'}) ?5697$meta->{'file_parent'} : unquote($meta->{'filename'});5698my$blamed= href(action =>'blame',5699 file_name =>$linenr_filename,5700 hash_base =>$linenr_commit);5701print"<td class=\"linenr\">";5702print$cgi->a({ -href =>"$blamed#l$orig_lineno",5703-class=>"linenr"},5704 esc_html($lineno));5705print"</td>";5706print"<td class=\"pre\">". esc_html($data) ."</td>\n";5707print"</tr>\n";5708}# end while57095710}57115712# footer5713print"</tbody>\n".5714"</table>\n";# class="blame"5715print"</div>\n";# class="blame_body"5716close$fd5717or print"Reading blob failed\n";57185719 git_footer_html();5720}57215722sub git_blame {5723 git_blame_common();5724}57255726sub git_blame_incremental {5727 git_blame_common('incremental');5728}57295730sub git_blame_data {5731 git_blame_common('data');5732}57335734sub git_tags {5735my$head= git_get_head_hash($project);5736 git_header_html();5737 git_print_page_nav('','',$head,undef,$head,format_ref_views('tags'));5738 git_print_header_div('summary',$project);57395740my@tagslist= git_get_tags_list();5741if(@tagslist) {5742 git_tags_body(\@tagslist);5743}5744 git_footer_html();5745}57465747sub git_heads {5748my$head= git_get_head_hash($project);5749 git_header_html();5750 git_print_page_nav('','',$head,undef,$head,format_ref_views('heads'));5751 git_print_header_div('summary',$project);57525753my@headslist= git_get_heads_list();5754if(@headslist) {5755 git_heads_body(\@headslist,$head);5756}5757 git_footer_html();5758}57595760# used both for single remote view and for list of all the remotes5761sub git_remotes {5762 gitweb_check_feature('remote_heads')5763or die_error(403,"Remote heads view is disabled");57645765my$head= git_get_head_hash($project);5766my$remote=$input_params{'hash'};57675768my$remotedata= git_get_remotes_list($remote);5769 die_error(500,"Unable to get remote information")unlessdefined$remotedata;57705771unless(%$remotedata) {5772 die_error(404,defined$remote?5773"Remote$remotenot found":5774"No remotes found");5775}57765777 git_header_html(undef,undef, -action_extra =>$remote);5778 git_print_page_nav('','',$head,undef,$head,5779 format_ref_views($remote?'':'remotes'));57805781 fill_remote_heads($remotedata);5782if(defined$remote) {5783 git_print_header_div('remotes',"$remoteremote for$project");5784 git_remote_block($remote,$remotedata->{$remote},undef,$head);5785}else{5786 git_print_header_div('summary',"$projectremotes");5787 git_remotes_body($remotedata,undef,$head);5788}57895790 git_footer_html();5791}57925793sub git_blob_plain {5794my$type=shift;5795my$expires;57965797if(!defined$hash) {5798if(defined$file_name) {5799my$base=$hash_base|| git_get_head_hash($project);5800$hash= git_get_hash_by_path($base,$file_name,"blob")5801or die_error(404,"Cannot find file");5802}else{5803 die_error(400,"No file name defined");5804}5805}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5806# blobs defined by non-textual hash id's can be cached5807$expires="+1d";5808}58095810open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5811or die_error(500,"Open git-cat-file blob '$hash' failed");58125813# content-type (can include charset)5814$type= blob_contenttype($fd,$file_name,$type);58155816# "save as" filename, even when no $file_name is given5817my$save_as="$hash";5818if(defined$file_name) {5819$save_as=$file_name;5820}elsif($type=~m/^text\//) {5821$save_as.='.txt';5822}58235824# With XSS prevention on, blobs of all types except a few known safe5825# ones are served with "Content-Disposition: attachment" to make sure5826# they don't run in our security domain. For certain image types,5827# blob view writes an <img> tag referring to blob_plain view, and we5828# want to be sure not to break that by serving the image as an5829# attachment (though Firefox 3 doesn't seem to care).5830my$sandbox=$prevent_xss&&5831$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;58325833print$cgi->header(5834-type =>$type,5835-expires =>$expires,5836-content_disposition =>5837($sandbox?'attachment':'inline')5838.'; filename="'.$save_as.'"');5839local$/=undef;5840binmode STDOUT,':raw';5841print<$fd>;5842binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5843close$fd;5844}58455846sub git_blob {5847my$expires;58485849if(!defined$hash) {5850if(defined$file_name) {5851my$base=$hash_base|| git_get_head_hash($project);5852$hash= git_get_hash_by_path($base,$file_name,"blob")5853or die_error(404,"Cannot find file");5854}else{5855 die_error(400,"No file name defined");5856}5857}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5858# blobs defined by non-textual hash id's can be cached5859$expires="+1d";5860}58615862my$have_blame= gitweb_check_feature('blame');5863open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5864or die_error(500,"Couldn't cat$file_name,$hash");5865my$mimetype= blob_mimetype($fd,$file_name);5866# use 'blob_plain' (aka 'raw') view for files that cannot be displayed5867if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {5868close$fd;5869return git_blob_plain($mimetype);5870}5871# we can have blame only for text/* mimetype5872$have_blame&&= ($mimetype=~m!^text/!);58735874my$highlight= gitweb_check_feature('highlight');5875my$syntax= guess_file_syntax($highlight,$mimetype,$file_name);5876$fd= run_highlighter($fd,$highlight,$syntax)5877if$syntax;58785879 git_header_html(undef,$expires);5880my$formats_nav='';5881if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5882if(defined$file_name) {5883if($have_blame) {5884$formats_nav.=5885$cgi->a({-href => href(action=>"blame", -replay=>1)},5886"blame") .5887" | ";5888}5889$formats_nav.=5890$cgi->a({-href => href(action=>"history", -replay=>1)},5891"history") .5892" | ".5893$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5894"raw") .5895" | ".5896$cgi->a({-href => href(action=>"blob",5897 hash_base=>"HEAD", file_name=>$file_name)},5898"HEAD");5899}else{5900$formats_nav.=5901$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5902"raw");5903}5904 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5905 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5906}else{5907print"<div class=\"page_nav\">\n".5908"<br/><br/></div>\n".5909"<div class=\"title\">".esc_html($hash)."</div>\n";5910}5911 git_print_page_path($file_name,"blob",$hash_base);5912print"<div class=\"page_body\">\n";5913if($mimetype=~m!^image/!) {5914print qq!<img type="!.esc_attr($mimetype).qq!"!;5915if($file_name) {5916print qq! alt="!.esc_attr($file_name).qq!" title="!.esc_attr($file_name).qq!"!;5917}5918print qq! src="! .5919 href(action=>"blob_plain", hash=>$hash,5920 hash_base=>$hash_base, file_name=>$file_name) .5921 qq!"/>\n!;5922}else{5923my$nr;5924while(my$line= <$fd>) {5925chomp$line;5926$nr++;5927$line= untabify($line);5928printf qq!<div class="pre"><a id="l%i" href="%s#l%i"class="linenr">%4i</a> %s</div>\n!,5929$nr, esc_attr(href(-replay =>1)),$nr,$nr,$syntax?$line: esc_html($line, -nbsp=>1);5930}5931}5932close$fd5933or print"Reading blob failed.\n";5934print"</div>";5935 git_footer_html();5936}59375938sub git_tree {5939if(!defined$hash_base) {5940$hash_base="HEAD";5941}5942if(!defined$hash) {5943if(defined$file_name) {5944$hash= git_get_hash_by_path($hash_base,$file_name,"tree");5945}else{5946$hash=$hash_base;5947}5948}5949 die_error(404,"No such tree")unlessdefined($hash);59505951my$show_sizes= gitweb_check_feature('show-sizes');5952my$have_blame= gitweb_check_feature('blame');59535954my@entries= ();5955{5956local$/="\0";5957open my$fd,"-|", git_cmd(),"ls-tree",'-z',5958($show_sizes?'-l': ()),@extra_options,$hash5959or die_error(500,"Open git-ls-tree failed");5960@entries=map{chomp;$_} <$fd>;5961close$fd5962or die_error(404,"Reading tree failed");5963}59645965my$refs= git_get_references();5966my$ref= format_ref_marker($refs,$hash_base);5967 git_header_html();5968my$basedir='';5969if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5970my@views_nav= ();5971if(defined$file_name) {5972push@views_nav,5973$cgi->a({-href => href(action=>"history", -replay=>1)},5974"history"),5975$cgi->a({-href => href(action=>"tree",5976 hash_base=>"HEAD", file_name=>$file_name)},5977"HEAD"),5978}5979my$snapshot_links= format_snapshot_links($hash);5980if(defined$snapshot_links) {5981# FIXME: Should be available when we have no hash base as well.5982push@views_nav,$snapshot_links;5983}5984 git_print_page_nav('tree','',$hash_base,undef,undef,5985join(' | ',@views_nav));5986 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);5987}else{5988undef$hash_base;5989print"<div class=\"page_nav\">\n";5990print"<br/><br/></div>\n";5991print"<div class=\"title\">".esc_html($hash)."</div>\n";5992}5993if(defined$file_name) {5994$basedir=$file_name;5995if($basedirne''&&substr($basedir, -1)ne'/') {5996$basedir.='/';5997}5998 git_print_page_path($file_name,'tree',$hash_base);5999}6000print"<div class=\"page_body\">\n";6001print"<table class=\"tree\">\n";6002my$alternate=1;6003# '..' (top directory) link if possible6004if(defined$hash_base&&6005defined$file_name&&$file_name=~m![^/]+$!) {6006if($alternate) {6007print"<tr class=\"dark\">\n";6008}else{6009print"<tr class=\"light\">\n";6010}6011$alternate^=1;60126013my$up=$file_name;6014$up=~s!/?[^/]+$!!;6015undef$upunless$up;6016# based on git_print_tree_entry6017print'<td class="mode">'. mode_str('040000') ."</td>\n";6018print'<td class="size"> </td>'."\n"if$show_sizes;6019print'<td class="list">';6020print$cgi->a({-href => href(action=>"tree",6021 hash_base=>$hash_base,6022 file_name=>$up)},6023"..");6024print"</td>\n";6025print"<td class=\"link\"></td>\n";60266027print"</tr>\n";6028}6029foreachmy$line(@entries) {6030my%t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);60316032if($alternate) {6033print"<tr class=\"dark\">\n";6034}else{6035print"<tr class=\"light\">\n";6036}6037$alternate^=1;60386039 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);60406041print"</tr>\n";6042}6043print"</table>\n".6044"</div>";6045 git_footer_html();6046}60476048sub snapshot_name {6049my($project,$hash) =@_;60506051# path/to/project.git -> project6052# path/to/project/.git -> project6053my$name= to_utf8($project);6054$name=~ s,([^/])/*\.git$,$1,;6055$name= basename($name);6056# sanitize name6057$name=~s/[[:cntrl:]]/?/g;60586059my$ver=$hash;6060if($hash=~/^[0-9a-fA-F]+$/) {6061# shorten SHA-1 hash6062my$full_hash= git_get_full_hash($project,$hash);6063if($full_hash=~/^$hash/&&length($hash) >7) {6064$ver= git_get_short_hash($project,$hash);6065}6066}elsif($hash=~m!^refs/tags/(.*)$!) {6067# tags don't need shortened SHA-1 hash6068$ver=$1;6069}else{6070# branches and other need shortened SHA-1 hash6071if($hash=~m!^refs/(?:heads|remotes)/(.*)$!) {6072$ver=$1;6073}6074$ver.='-'. git_get_short_hash($project,$hash);6075}6076# in case of hierarchical branch names6077$ver=~s!/!.!g;60786079# name = project-version_string6080$name="$name-$ver";60816082returnwantarray? ($name,$name) :$name;6083}60846085sub git_snapshot {6086my$format=$input_params{'snapshot_format'};6087if(!@snapshot_fmts) {6088 die_error(403,"Snapshots not allowed");6089}6090# default to first supported snapshot format6091$format||=$snapshot_fmts[0];6092if($format!~m/^[a-z0-9]+$/) {6093 die_error(400,"Invalid snapshot format parameter");6094}elsif(!exists($known_snapshot_formats{$format})) {6095 die_error(400,"Unknown snapshot format");6096}elsif($known_snapshot_formats{$format}{'disabled'}) {6097 die_error(403,"Snapshot format not allowed");6098}elsif(!grep($_eq$format,@snapshot_fmts)) {6099 die_error(403,"Unsupported snapshot format");6100}61016102my$type= git_get_type("$hash^{}");6103if(!$type) {6104 die_error(404,'Object does not exist');6105}elsif($typeeq'blob') {6106 die_error(400,'Object is not a tree-ish');6107}61086109my($name,$prefix) = snapshot_name($project,$hash);6110my$filename="$name$known_snapshot_formats{$format}{'suffix'}";6111my$cmd= quote_command(6112 git_cmd(),'archive',6113"--format=$known_snapshot_formats{$format}{'format'}",6114"--prefix=$prefix/",$hash);6115if(exists$known_snapshot_formats{$format}{'compressor'}) {6116$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});6117}61186119$filename=~s/(["\\])/\\$1/g;6120print$cgi->header(6121-type =>$known_snapshot_formats{$format}{'type'},6122-content_disposition =>'inline; filename="'.$filename.'"',6123-status =>'200 OK');61246125open my$fd,"-|",$cmd6126or die_error(500,"Execute git-archive failed");6127binmode STDOUT,':raw';6128print<$fd>;6129binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi6130close$fd;6131}61326133sub git_log_generic {6134my($fmt_name,$body_subr,$base,$parent,$file_name,$file_hash) =@_;61356136my$head= git_get_head_hash($project);6137if(!defined$base) {6138$base=$head;6139}6140if(!defined$page) {6141$page=0;6142}6143my$refs= git_get_references();61446145my$commit_hash=$base;6146if(defined$parent) {6147$commit_hash="$parent..$base";6148}6149my@commitlist=6150 parse_commits($commit_hash,101, (100*$page),6151defined$file_name? ($file_name,"--full-history") : ());61526153my$ftype;6154if(!defined$file_hash&&defined$file_name) {6155# some commits could have deleted file in question,6156# and not have it in tree, but one of them has to have it6157for(my$i=0;$i<@commitlist;$i++) {6158$file_hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);6159last ifdefined$file_hash;6160}6161}6162if(defined$file_hash) {6163$ftype= git_get_type($file_hash);6164}6165if(defined$file_name&& !defined$ftype) {6166 die_error(500,"Unknown type of object");6167}6168my%co;6169if(defined$file_name) {6170%co= parse_commit($base)6171or die_error(404,"Unknown commit object");6172}617361746175my$paging_nav= format_paging_nav($fmt_name,$page,$#commitlist>=100);6176my$next_link='';6177if($#commitlist>=100) {6178$next_link=6179$cgi->a({-href => href(-replay=>1, page=>$page+1),6180-accesskey =>"n", -title =>"Alt-n"},"next");6181}6182my$patch_max= gitweb_get_feature('patches');6183if($patch_max&& !defined$file_name) {6184if($patch_max<0||@commitlist<=$patch_max) {6185$paging_nav.=" ⋅ ".6186$cgi->a({-href => href(action=>"patches", -replay=>1)},6187"patches");6188}6189}61906191 git_header_html();6192 git_print_page_nav($fmt_name,'',$hash,$hash,$hash,$paging_nav);6193if(defined$file_name) {6194 git_print_header_div('commit', esc_html($co{'title'}),$base);6195}else{6196 git_print_header_div('summary',$project)6197}6198 git_print_page_path($file_name,$ftype,$hash_base)6199if(defined$file_name);62006201$body_subr->(\@commitlist,0,99,$refs,$next_link,6202$file_name,$file_hash,$ftype);62036204 git_footer_html();6205}62066207sub git_log {6208 git_log_generic('log', \&git_log_body,6209$hash,$hash_parent);6210}62116212sub git_commit {6213$hash||=$hash_base||"HEAD";6214my%co= parse_commit($hash)6215or die_error(404,"Unknown commit object");62166217my$parent=$co{'parent'};6218my$parents=$co{'parents'};# listref62196220# we need to prepare $formats_nav before any parameter munging6221my$formats_nav;6222if(!defined$parent) {6223# --root commitdiff6224$formats_nav.='(initial)';6225}elsif(@$parents==1) {6226# single parent commit6227$formats_nav.=6228'(parent: '.6229$cgi->a({-href => href(action=>"commit",6230 hash=>$parent)},6231 esc_html(substr($parent,0,7))) .6232')';6233}else{6234# merge commit6235$formats_nav.=6236'(merge: '.6237join(' ',map{6238$cgi->a({-href => href(action=>"commit",6239 hash=>$_)},6240 esc_html(substr($_,0,7)));6241}@$parents) .6242')';6243}6244if(gitweb_check_feature('patches') &&@$parents<=1) {6245$formats_nav.=" | ".6246$cgi->a({-href => href(action=>"patch", -replay=>1)},6247"patch");6248}62496250if(!defined$parent) {6251$parent="--root";6252}6253my@difftree;6254open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",6255@diff_opts,6256(@$parents<=1?$parent:'-c'),6257$hash,"--"6258or die_error(500,"Open git-diff-tree failed");6259@difftree=map{chomp;$_} <$fd>;6260close$fdor die_error(404,"Reading git-diff-tree failed");62616262# non-textual hash id's can be cached6263my$expires;6264if($hash=~m/^[0-9a-fA-F]{40}$/) {6265$expires="+1d";6266}6267my$refs= git_get_references();6268my$ref= format_ref_marker($refs,$co{'id'});62696270 git_header_html(undef,$expires);6271 git_print_page_nav('commit','',6272$hash,$co{'tree'},$hash,6273$formats_nav);62746275if(defined$co{'parent'}) {6276 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);6277}else{6278 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);6279}6280print"<div class=\"title_text\">\n".6281"<table class=\"object_header\">\n";6282 git_print_authorship_rows(\%co);6283print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";6284print"<tr>".6285"<td>tree</td>".6286"<td class=\"sha1\">".6287$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),6288class=>"list"},$co{'tree'}) .6289"</td>".6290"<td class=\"link\">".6291$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},6292"tree");6293my$snapshot_links= format_snapshot_links($hash);6294if(defined$snapshot_links) {6295print" | ".$snapshot_links;6296}6297print"</td>".6298"</tr>\n";62996300foreachmy$par(@$parents) {6301print"<tr>".6302"<td>parent</td>".6303"<td class=\"sha1\">".6304$cgi->a({-href => href(action=>"commit", hash=>$par),6305class=>"list"},$par) .6306"</td>".6307"<td class=\"link\">".6308$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .6309" | ".6310$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .6311"</td>".6312"</tr>\n";6313}6314print"</table>".6315"</div>\n";63166317print"<div class=\"page_body\">\n";6318 git_print_log($co{'comment'});6319print"</div>\n";63206321 git_difftree_body(\@difftree,$hash,@$parents);63226323 git_footer_html();6324}63256326sub git_object {6327# object is defined by:6328# - hash or hash_base alone6329# - hash_base and file_name6330my$type;63316332# - hash or hash_base alone6333if($hash|| ($hash_base&& !defined$file_name)) {6334my$object_id=$hash||$hash_base;63356336open my$fd,"-|", quote_command(6337 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'6338or die_error(404,"Object does not exist");6339$type= <$fd>;6340chomp$type;6341close$fd6342or die_error(404,"Object does not exist");63436344# - hash_base and file_name6345}elsif($hash_base&&defined$file_name) {6346$file_name=~ s,/+$,,;63476348system(git_cmd(),"cat-file",'-e',$hash_base) ==06349or die_error(404,"Base object does not exist");63506351# here errors should not hapen6352open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name6353or die_error(500,"Open git-ls-tree failed");6354my$line= <$fd>;6355close$fd;63566357#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'6358unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {6359 die_error(404,"File or directory for given base does not exist");6360}6361$type=$2;6362$hash=$3;6363}else{6364 die_error(400,"Not enough information to find object");6365}63666367print$cgi->redirect(-uri => href(action=>$type, -full=>1,6368 hash=>$hash, hash_base=>$hash_base,6369 file_name=>$file_name),6370-status =>'302 Found');6371}63726373sub git_blobdiff {6374my$format=shift||'html';63756376my$fd;6377my@difftree;6378my%diffinfo;6379my$expires;63806381# preparing $fd and %diffinfo for git_patchset_body6382# new style URI6383if(defined$hash_base&&defined$hash_parent_base) {6384if(defined$file_name) {6385# read raw output6386open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6387$hash_parent_base,$hash_base,6388"--", (defined$file_parent?$file_parent: ()),$file_name6389or die_error(500,"Open git-diff-tree failed");6390@difftree=map{chomp;$_} <$fd>;6391close$fd6392or die_error(404,"Reading git-diff-tree failed");6393@difftree6394or die_error(404,"Blob diff not found");63956396}elsif(defined$hash&&6397$hash=~/[0-9a-fA-F]{40}/) {6398# try to find filename from $hash63996400# read filtered raw output6401open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6402$hash_parent_base,$hash_base,"--"6403or die_error(500,"Open git-diff-tree failed");6404@difftree=6405# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'6406# $hash == to_id6407grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}6408map{chomp;$_} <$fd>;6409close$fd6410or die_error(404,"Reading git-diff-tree failed");6411@difftree6412or die_error(404,"Blob diff not found");64136414}else{6415 die_error(400,"Missing one of the blob diff parameters");6416}64176418if(@difftree>1) {6419 die_error(400,"Ambiguous blob diff specification");6420}64216422%diffinfo= parse_difftree_raw_line($difftree[0]);6423$file_parent||=$diffinfo{'from_file'} ||$file_name;6424$file_name||=$diffinfo{'to_file'};64256426$hash_parent||=$diffinfo{'from_id'};6427$hash||=$diffinfo{'to_id'};64286429# non-textual hash id's can be cached6430if($hash_base=~m/^[0-9a-fA-F]{40}$/&&6431$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {6432$expires='+1d';6433}64346435# open patch output6436open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6437'-p', ($formateq'html'?"--full-index": ()),6438$hash_parent_base,$hash_base,6439"--", (defined$file_parent?$file_parent: ()),$file_name6440or die_error(500,"Open git-diff-tree failed");6441}64426443# old/legacy style URI -- not generated anymore since 1.4.3.6444if(!%diffinfo) {6445 die_error('404 Not Found',"Missing one of the blob diff parameters")6446}64476448# header6449if($formateq'html') {6450my$formats_nav=6451$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},6452"raw");6453 git_header_html(undef,$expires);6454if(defined$hash_base&& (my%co= parse_commit($hash_base))) {6455 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);6456 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);6457}else{6458print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";6459print"<div class=\"title\">".esc_html("$hashvs$hash_parent")."</div>\n";6460}6461if(defined$file_name) {6462 git_print_page_path($file_name,"blob",$hash_base);6463}else{6464print"<div class=\"page_path\"></div>\n";6465}64666467}elsif($formateq'plain') {6468print$cgi->header(6469-type =>'text/plain',6470-charset =>'utf-8',6471-expires =>$expires,6472-content_disposition =>'inline; filename="'."$file_name".'.patch"');64736474print"X-Git-Url: ".$cgi->self_url() ."\n\n";64756476}else{6477 die_error(400,"Unknown blobdiff format");6478}64796480# patch6481if($formateq'html') {6482print"<div class=\"page_body\">\n";64836484 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);6485close$fd;64866487print"</div>\n";# class="page_body"6488 git_footer_html();64896490}else{6491while(my$line= <$fd>) {6492$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;6493$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;64946495print$line;64966497last if$line=~m!^\+\+\+!;6498}6499local$/=undef;6500print<$fd>;6501close$fd;6502}6503}65046505sub git_blobdiff_plain {6506 git_blobdiff('plain');6507}65086509sub git_commitdiff {6510my%params=@_;6511my$format=$params{-format} ||'html';65126513my($patch_max) = gitweb_get_feature('patches');6514if($formateq'patch') {6515 die_error(403,"Patch view not allowed")unless$patch_max;6516}65176518$hash||=$hash_base||"HEAD";6519my%co= parse_commit($hash)6520or die_error(404,"Unknown commit object");65216522# choose format for commitdiff for merge6523if(!defined$hash_parent&& @{$co{'parents'}} >1) {6524$hash_parent='--cc';6525}6526# we need to prepare $formats_nav before almost any parameter munging6527my$formats_nav;6528if($formateq'html') {6529$formats_nav=6530$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},6531"raw");6532if($patch_max&& @{$co{'parents'}} <=1) {6533$formats_nav.=" | ".6534$cgi->a({-href => href(action=>"patch", -replay=>1)},6535"patch");6536}65376538if(defined$hash_parent&&6539$hash_parentne'-c'&&$hash_parentne'--cc') {6540# commitdiff with two commits given6541my$hash_parent_short=$hash_parent;6542if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {6543$hash_parent_short=substr($hash_parent,0,7);6544}6545$formats_nav.=6546' (from';6547for(my$i=0;$i< @{$co{'parents'}};$i++) {6548if($co{'parents'}[$i]eq$hash_parent) {6549$formats_nav.=' parent '. ($i+1);6550last;6551}6552}6553$formats_nav.=': '.6554$cgi->a({-href => href(action=>"commitdiff",6555 hash=>$hash_parent)},6556 esc_html($hash_parent_short)) .6557')';6558}elsif(!$co{'parent'}) {6559# --root commitdiff6560$formats_nav.=' (initial)';6561}elsif(scalar@{$co{'parents'}} ==1) {6562# single parent commit6563$formats_nav.=6564' (parent: '.6565$cgi->a({-href => href(action=>"commitdiff",6566 hash=>$co{'parent'})},6567 esc_html(substr($co{'parent'},0,7))) .6568')';6569}else{6570# merge commit6571if($hash_parenteq'--cc') {6572$formats_nav.=' | '.6573$cgi->a({-href => href(action=>"commitdiff",6574 hash=>$hash, hash_parent=>'-c')},6575'combined');6576}else{# $hash_parent eq '-c'6577$formats_nav.=' | '.6578$cgi->a({-href => href(action=>"commitdiff",6579 hash=>$hash, hash_parent=>'--cc')},6580'compact');6581}6582$formats_nav.=6583' (merge: '.6584join(' ',map{6585$cgi->a({-href => href(action=>"commitdiff",6586 hash=>$_)},6587 esc_html(substr($_,0,7)));6588} @{$co{'parents'}} ) .6589')';6590}6591}65926593my$hash_parent_param=$hash_parent;6594if(!defined$hash_parent_param) {6595# --cc for multiple parents, --root for parentless6596$hash_parent_param=6597@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';6598}65996600# read commitdiff6601my$fd;6602my@difftree;6603if($formateq'html') {6604open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6605"--no-commit-id","--patch-with-raw","--full-index",6606$hash_parent_param,$hash,"--"6607or die_error(500,"Open git-diff-tree failed");66086609while(my$line= <$fd>) {6610chomp$line;6611# empty line ends raw part of diff-tree output6612last unless$line;6613push@difftree,scalar parse_difftree_raw_line($line);6614}66156616}elsif($formateq'plain') {6617open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6618'-p',$hash_parent_param,$hash,"--"6619or die_error(500,"Open git-diff-tree failed");6620}elsif($formateq'patch') {6621# For commit ranges, we limit the output to the number of6622# patches specified in the 'patches' feature.6623# For single commits, we limit the output to a single patch,6624# diverging from the git-format-patch default.6625my@commit_spec= ();6626if($hash_parent) {6627if($patch_max>0) {6628push@commit_spec,"-$patch_max";6629}6630push@commit_spec,'-n',"$hash_parent..$hash";6631}else{6632if($params{-single}) {6633push@commit_spec,'-1';6634}else{6635if($patch_max>0) {6636push@commit_spec,"-$patch_max";6637}6638push@commit_spec,"-n";6639}6640push@commit_spec,'--root',$hash;6641}6642open$fd,"-|", git_cmd(),"format-patch",@diff_opts,6643'--encoding=utf8','--stdout',@commit_spec6644or die_error(500,"Open git-format-patch failed");6645}else{6646 die_error(400,"Unknown commitdiff format");6647}66486649# non-textual hash id's can be cached6650my$expires;6651if($hash=~m/^[0-9a-fA-F]{40}$/) {6652$expires="+1d";6653}66546655# write commit message6656if($formateq'html') {6657my$refs= git_get_references();6658my$ref= format_ref_marker($refs,$co{'id'});66596660 git_header_html(undef,$expires);6661 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);6662 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);6663print"<div class=\"title_text\">\n".6664"<table class=\"object_header\">\n";6665 git_print_authorship_rows(\%co);6666print"</table>".6667"</div>\n";6668print"<div class=\"page_body\">\n";6669if(@{$co{'comment'}} >1) {6670print"<div class=\"log\">\n";6671 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);6672print"</div>\n";# class="log"6673}66746675}elsif($formateq'plain') {6676my$refs= git_get_references("tags");6677my$tagname= git_get_rev_name_tags($hash);6678my$filename= basename($project) ."-$hash.patch";66796680print$cgi->header(6681-type =>'text/plain',6682-charset =>'utf-8',6683-expires =>$expires,6684-content_disposition =>'inline; filename="'."$filename".'"');6685my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});6686print"From: ". to_utf8($co{'author'}) ."\n";6687print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";6688print"Subject: ". to_utf8($co{'title'}) ."\n";66896690print"X-Git-Tag:$tagname\n"if$tagname;6691print"X-Git-Url: ".$cgi->self_url() ."\n\n";66926693foreachmy$line(@{$co{'comment'}}) {6694print to_utf8($line) ."\n";6695}6696print"---\n\n";6697}elsif($formateq'patch') {6698my$filename= basename($project) ."-$hash.patch";66996700print$cgi->header(6701-type =>'text/plain',6702-charset =>'utf-8',6703-expires =>$expires,6704-content_disposition =>'inline; filename="'."$filename".'"');6705}67066707# write patch6708if($formateq'html') {6709my$use_parents= !defined$hash_parent||6710$hash_parenteq'-c'||$hash_parenteq'--cc';6711 git_difftree_body(\@difftree,$hash,6712$use_parents? @{$co{'parents'}} :$hash_parent);6713print"<br/>\n";67146715 git_patchset_body($fd, \@difftree,$hash,6716$use_parents? @{$co{'parents'}} :$hash_parent);6717close$fd;6718print"</div>\n";# class="page_body"6719 git_footer_html();67206721}elsif($formateq'plain') {6722local$/=undef;6723print<$fd>;6724close$fd6725or print"Reading git-diff-tree failed\n";6726}elsif($formateq'patch') {6727local$/=undef;6728print<$fd>;6729close$fd6730or print"Reading git-format-patch failed\n";6731}6732}67336734sub git_commitdiff_plain {6735 git_commitdiff(-format =>'plain');6736}67376738# format-patch-style patches6739sub git_patch {6740 git_commitdiff(-format =>'patch', -single =>1);6741}67426743sub git_patches {6744 git_commitdiff(-format =>'patch');6745}67466747sub git_history {6748 git_log_generic('history', \&git_history_body,6749$hash_base,$hash_parent_base,6750$file_name,$hash);6751}67526753sub git_search {6754 gitweb_check_feature('search')or die_error(403,"Search is disabled");6755if(!defined$searchtext) {6756 die_error(400,"Text field is empty");6757}6758if(!defined$hash) {6759$hash= git_get_head_hash($project);6760}6761my%co= parse_commit($hash);6762if(!%co) {6763 die_error(404,"Unknown commit object");6764}6765if(!defined$page) {6766$page=0;6767}67686769$searchtype||='commit';6770if($searchtypeeq'pickaxe') {6771# pickaxe may take all resources of your box and run for several minutes6772# with every query - so decide by yourself how public you make this feature6773 gitweb_check_feature('pickaxe')6774or die_error(403,"Pickaxe is disabled");6775}6776if($searchtypeeq'grep') {6777 gitweb_check_feature('grep')6778or die_error(403,"Grep is disabled");6779}67806781 git_header_html();67826783if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {6784my$greptype;6785if($searchtypeeq'commit') {6786$greptype="--grep=";6787}elsif($searchtypeeq'author') {6788$greptype="--author=";6789}elsif($searchtypeeq'committer') {6790$greptype="--committer=";6791}6792$greptype.=$searchtext;6793my@commitlist= parse_commits($hash,101, (100*$page),undef,6794$greptype,'--regexp-ignore-case',6795$search_use_regexp?'--extended-regexp':'--fixed-strings');67966797my$paging_nav='';6798if($page>0) {6799$paging_nav.=6800$cgi->a({-href => href(action=>"search", hash=>$hash,6801 searchtext=>$searchtext,6802 searchtype=>$searchtype)},6803"first");6804$paging_nav.=" ⋅ ".6805$cgi->a({-href => href(-replay=>1, page=>$page-1),6806-accesskey =>"p", -title =>"Alt-p"},"prev");6807}else{6808$paging_nav.="first";6809$paging_nav.=" ⋅ prev";6810}6811my$next_link='';6812if($#commitlist>=100) {6813$next_link=6814$cgi->a({-href => href(-replay=>1, page=>$page+1),6815-accesskey =>"n", -title =>"Alt-n"},"next");6816$paging_nav.=" ⋅$next_link";6817}else{6818$paging_nav.=" ⋅ next";6819}68206821 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);6822 git_print_header_div('commit', esc_html($co{'title'}),$hash);6823if($page==0&& !@commitlist) {6824print"<p>No match.</p>\n";6825}else{6826 git_search_grep_body(\@commitlist,0,99,$next_link);6827}6828}68296830if($searchtypeeq'pickaxe') {6831 git_print_page_nav('','',$hash,$co{'tree'},$hash);6832 git_print_header_div('commit', esc_html($co{'title'}),$hash);68336834print"<table class=\"pickaxe search\">\n";6835my$alternate=1;6836local$/="\n";6837open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,6838'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",6839($search_use_regexp?'--pickaxe-regex': ());6840undef%co;6841my@files;6842while(my$line= <$fd>) {6843chomp$line;6844next unless$line;68456846my%set= parse_difftree_raw_line($line);6847if(defined$set{'commit'}) {6848# finish previous commit6849if(%co) {6850print"</td>\n".6851"<td class=\"link\">".6852$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6853" | ".6854$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6855print"</td>\n".6856"</tr>\n";6857}68586859if($alternate) {6860print"<tr class=\"dark\">\n";6861}else{6862print"<tr class=\"light\">\n";6863}6864$alternate^=1;6865%co= parse_commit($set{'commit'});6866my$author= chop_and_escape_str($co{'author_name'},15,5);6867print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6868"<td><i>$author</i></td>\n".6869"<td>".6870$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6871-class=>"list subject"},6872 chop_and_escape_str($co{'title'},50) ."<br/>");6873}elsif(defined$set{'to_id'}) {6874next if($set{'to_id'} =~m/^0{40}$/);68756876print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6877 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6878-class=>"list"},6879"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6880"<br/>\n";6881}6882}6883close$fd;68846885# finish last commit (warning: repetition!)6886if(%co) {6887print"</td>\n".6888"<td class=\"link\">".6889$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6890" | ".6891$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6892print"</td>\n".6893"</tr>\n";6894}68956896print"</table>\n";6897}68986899if($searchtypeeq'grep') {6900 git_print_page_nav('','',$hash,$co{'tree'},$hash);6901 git_print_header_div('commit', esc_html($co{'title'}),$hash);69026903print"<table class=\"grep_search\">\n";6904my$alternate=1;6905my$matches=0;6906local$/="\n";6907open my$fd,"-|", git_cmd(),'grep','-n',6908$search_use_regexp? ('-E','-i') :'-F',6909$searchtext,$co{'tree'};6910my$lastfile='';6911while(my$line= <$fd>) {6912chomp$line;6913my($file,$lno,$ltext,$binary);6914last if($matches++>1000);6915if($line=~/^Binary file (.+) matches$/) {6916$file=$1;6917$binary=1;6918}else{6919(undef,$file,$lno,$ltext) =split(/:/,$line,4);6920}6921if($filene$lastfile) {6922$lastfileand print"</td></tr>\n";6923if($alternate++) {6924print"<tr class=\"dark\">\n";6925}else{6926print"<tr class=\"light\">\n";6927}6928print"<td class=\"list\">".6929$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6930 file_name=>"$file"),6931-class=>"list"}, esc_path($file));6932print"</td><td>\n";6933$lastfile=$file;6934}6935if($binary) {6936print"<div class=\"binary\">Binary file</div>\n";6937}else{6938$ltext= untabify($ltext);6939if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6940$ltext= esc_html($1, -nbsp=>1);6941$ltext.='<span class="match">';6942$ltext.= esc_html($2, -nbsp=>1);6943$ltext.='</span>';6944$ltext.= esc_html($3, -nbsp=>1);6945}else{6946$ltext= esc_html($ltext, -nbsp=>1);6947}6948print"<div class=\"pre\">".6949$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6950 file_name=>"$file").'#l'.$lno,6951-class=>"linenr"},sprintf('%4i',$lno))6952.' '.$ltext."</div>\n";6953}6954}6955if($lastfile) {6956print"</td></tr>\n";6957if($matches>1000) {6958print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6959}6960}else{6961print"<div class=\"diff nodifferences\">No matches found</div>\n";6962}6963close$fd;69646965print"</table>\n";6966}6967 git_footer_html();6968}69696970sub git_search_help {6971 git_header_html();6972 git_print_page_nav('','',$hash,$hash,$hash);6973print<<EOT;6974<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without6975regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,6976the pattern entered is recognized as the POSIX extended6977<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case6978insensitive).</p>6979<dl>6980<dt><b>commit</b></dt>6981<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>6982EOT6983my$have_grep= gitweb_check_feature('grep');6984if($have_grep) {6985print<<EOT;6986<dt><b>grep</b></dt>6987<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing6988 a different one) are searched for the given pattern. On large trees, this search can take6989a while and put some strain on the server, so please use it with some consideration. Note that6990due to git-grep peculiarity, currently if regexp mode is turned off, the matches are6991case-sensitive.</dd>6992EOT6993}6994print<<EOT;6995<dt><b>author</b></dt>6996<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>6997<dt><b>committer</b></dt>6998<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>6999EOT7000my$have_pickaxe= gitweb_check_feature('pickaxe');7001if($have_pickaxe) {7002print<<EOT;7003<dt><b>pickaxe</b></dt>7004<dd>All commits that caused the string to appear or disappear from any file (changes that7005added, removed or "modified" the string) will be listed. This search can take a while and7006takes a lot of strain on the server, so please use it wisely. Note that since you may be7007interested even in changes just changing the case as well, this search is case sensitive.</dd>7008EOT7009}7010print"</dl>\n";7011 git_footer_html();7012}70137014sub git_shortlog {7015 git_log_generic('shortlog', \&git_shortlog_body,7016$hash,$hash_parent);7017}70187019## ......................................................................7020## feeds (RSS, Atom; OPML)70217022sub git_feed {7023my$format=shift||'atom';7024my$have_blame= gitweb_check_feature('blame');70257026# Atom: http://www.atomenabled.org/developers/syndication/7027# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ7028if($formatne'rss'&&$formatne'atom') {7029 die_error(400,"Unknown web feed format");7030}70317032# log/feed of current (HEAD) branch, log of given branch, history of file/directory7033my$head=$hash||'HEAD';7034my@commitlist= parse_commits($head,150,0,$file_name);70357036my%latest_commit;7037my%latest_date;7038my$content_type="application/$format+xml";7039if(defined$cgi->http('HTTP_ACCEPT') &&7040$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {7041# browser (feed reader) prefers text/xml7042$content_type='text/xml';7043}7044if(defined($commitlist[0])) {7045%latest_commit= %{$commitlist[0]};7046my$latest_epoch=$latest_commit{'committer_epoch'};7047%latest_date= parse_date($latest_epoch);7048my$if_modified=$cgi->http('IF_MODIFIED_SINCE');7049if(defined$if_modified) {7050my$since;7051if(eval{require HTTP::Date;1; }) {7052$since= HTTP::Date::str2time($if_modified);7053}elsif(eval{require Time::ParseDate;1; }) {7054$since= Time::ParseDate::parsedate($if_modified, GMT =>1);7055}7056if(defined$since&&$latest_epoch<=$since) {7057print$cgi->header(7058-type =>$content_type,7059-charset =>'utf-8',7060-last_modified =>$latest_date{'rfc2822'},7061-status =>'304 Not Modified');7062return;7063}7064}7065print$cgi->header(7066-type =>$content_type,7067-charset =>'utf-8',7068-last_modified =>$latest_date{'rfc2822'});7069}else{7070print$cgi->header(7071-type =>$content_type,7072-charset =>'utf-8');7073}70747075# Optimization: skip generating the body if client asks only7076# for Last-Modified date.7077return if($cgi->request_method()eq'HEAD');70787079# header variables7080my$title="$site_name-$project/$action";7081my$feed_type='log';7082if(defined$hash) {7083$title.=" - '$hash'";7084$feed_type='branch log';7085if(defined$file_name) {7086$title.=" ::$file_name";7087$feed_type='history';7088}7089}elsif(defined$file_name) {7090$title.=" -$file_name";7091$feed_type='history';7092}7093$title.="$feed_type";7094my$descr= git_get_project_description($project);7095if(defined$descr) {7096$descr= esc_html($descr);7097}else{7098$descr="$project".7099($formateq'rss'?'RSS':'Atom') .7100" feed";7101}7102my$owner= git_get_project_owner($project);7103$owner= esc_html($owner);71047105#header7106my$alt_url;7107if(defined$file_name) {7108$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);7109}elsif(defined$hash) {7110$alt_url= href(-full=>1, action=>"log", hash=>$hash);7111}else{7112$alt_url= href(-full=>1, action=>"summary");7113}7114print qq!<?xml version="1.0" encoding="utf-8"?>\n!;7115if($formateq'rss') {7116print<<XML;7117<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">7118<channel>7119XML7120print"<title>$title</title>\n".7121"<link>$alt_url</link>\n".7122"<description>$descr</description>\n".7123"<language>en</language>\n".7124# project owner is responsible for 'editorial' content7125"<managingEditor>$owner</managingEditor>\n";7126if(defined$logo||defined$favicon) {7127# prefer the logo to the favicon, since RSS7128# doesn't allow both7129my$img= esc_url($logo||$favicon);7130print"<image>\n".7131"<url>$img</url>\n".7132"<title>$title</title>\n".7133"<link>$alt_url</link>\n".7134"</image>\n";7135}7136if(%latest_date) {7137print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";7138print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";7139}7140print"<generator>gitweb v.$version/$git_version</generator>\n";7141}elsif($formateq'atom') {7142print<<XML;7143<feed xmlns="http://www.w3.org/2005/Atom">7144XML7145print"<title>$title</title>\n".7146"<subtitle>$descr</subtitle>\n".7147'<link rel="alternate" type="text/html" href="'.7148$alt_url.'" />'."\n".7149'<link rel="self" type="'.$content_type.'" href="'.7150$cgi->self_url() .'" />'."\n".7151"<id>". href(-full=>1) ."</id>\n".7152# use project owner for feed author7153"<author><name>$owner</name></author>\n";7154if(defined$favicon) {7155print"<icon>". esc_url($favicon) ."</icon>\n";7156}7157if(defined$logo_url) {7158# not twice as wide as tall: 72 x 27 pixels7159print"<logo>". esc_url($logo) ."</logo>\n";7160}7161if(!%latest_date) {7162# dummy date to keep the feed valid until commits trickle in:7163print"<updated>1970-01-01T00:00:00Z</updated>\n";7164}else{7165print"<updated>$latest_date{'iso-8601'}</updated>\n";7166}7167print"<generator version='$version/$git_version'>gitweb</generator>\n";7168}71697170# contents7171for(my$i=0;$i<=$#commitlist;$i++) {7172my%co= %{$commitlist[$i]};7173my$commit=$co{'id'};7174# we read 150, we always show 30 and the ones more recent than 48 hours7175if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {7176last;7177}7178my%cd= parse_date($co{'author_epoch'});71797180# get list of changed files7181open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7182$co{'parent'} ||"--root",7183$co{'id'},"--", (defined$file_name?$file_name: ())7184ornext;7185my@difftree=map{chomp;$_} <$fd>;7186close$fd7187ornext;71887189# print element (entry, item)7190my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);7191if($formateq'rss') {7192print"<item>\n".7193"<title>". esc_html($co{'title'}) ."</title>\n".7194"<author>". esc_html($co{'author'}) ."</author>\n".7195"<pubDate>$cd{'rfc2822'}</pubDate>\n".7196"<guid isPermaLink=\"true\">$co_url</guid>\n".7197"<link>$co_url</link>\n".7198"<description>". esc_html($co{'title'}) ."</description>\n".7199"<content:encoded>".7200"<![CDATA[\n";7201}elsif($formateq'atom') {7202print"<entry>\n".7203"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".7204"<updated>$cd{'iso-8601'}</updated>\n".7205"<author>\n".7206" <name>". esc_html($co{'author_name'}) ."</name>\n";7207if($co{'author_email'}) {7208print" <email>". esc_html($co{'author_email'}) ."</email>\n";7209}7210print"</author>\n".7211# use committer for contributor7212"<contributor>\n".7213" <name>". esc_html($co{'committer_name'}) ."</name>\n";7214if($co{'committer_email'}) {7215print" <email>". esc_html($co{'committer_email'}) ."</email>\n";7216}7217print"</contributor>\n".7218"<published>$cd{'iso-8601'}</published>\n".7219"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".7220"<id>$co_url</id>\n".7221"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".7222"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";7223}7224my$comment=$co{'comment'};7225print"<pre>\n";7226foreachmy$line(@$comment) {7227$line= esc_html($line);7228print"$line\n";7229}7230print"</pre><ul>\n";7231foreachmy$difftree_line(@difftree) {7232my%difftree= parse_difftree_raw_line($difftree_line);7233next if!$difftree{'from_id'};72347235my$file=$difftree{'file'} ||$difftree{'to_file'};72367237print"<li>".7238"[".7239$cgi->a({-href => href(-full=>1, action=>"blobdiff",7240 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},7241 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},7242 file_name=>$file, file_parent=>$difftree{'from_file'}),7243-title =>"diff"},'D');7244if($have_blame) {7245print$cgi->a({-href => href(-full=>1, action=>"blame",7246 file_name=>$file, hash_base=>$commit),7247-title =>"blame"},'B');7248}7249# if this is not a feed of a file history7250if(!defined$file_name||$file_namene$file) {7251print$cgi->a({-href => href(-full=>1, action=>"history",7252 file_name=>$file, hash=>$commit),7253-title =>"history"},'H');7254}7255$file= esc_path($file);7256print"] ".7257"$file</li>\n";7258}7259if($formateq'rss') {7260print"</ul>]]>\n".7261"</content:encoded>\n".7262"</item>\n";7263}elsif($formateq'atom') {7264print"</ul>\n</div>\n".7265"</content>\n".7266"</entry>\n";7267}7268}72697270# end of feed7271if($formateq'rss') {7272print"</channel>\n</rss>\n";7273}elsif($formateq'atom') {7274print"</feed>\n";7275}7276}72777278sub git_rss {7279 git_feed('rss');7280}72817282sub git_atom {7283 git_feed('atom');7284}72857286sub git_opml {7287my@list= git_get_projects_list();72887289print$cgi->header(7290-type =>'text/xml',7291-charset =>'utf-8',7292-content_disposition =>'inline; filename="opml.xml"');72937294print<<XML;7295<?xml version="1.0" encoding="utf-8"?>7296<opml version="1.0">7297<head>7298 <title>$site_nameOPML Export</title>7299</head>7300<body>7301<outline text="git RSS feeds">7302XML73037304foreachmy$pr(@list) {7305my%proj=%$pr;7306my$head= git_get_head_hash($proj{'path'});7307if(!defined$head) {7308next;7309}7310$git_dir="$projectroot/$proj{'path'}";7311my%co= parse_commit($head);7312if(!%co) {7313next;7314}73157316my$path= esc_html(chop_str($proj{'path'},25,5));7317my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);7318my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);7319print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";7320}7321print<<XML;7322</outline>7323</body>7324</opml>7325XML7326}