1#!/usr/bin/perl 2 3# gitweb - simple web interface to track changes in git repositories 4# 5# (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org> 6# (C) 2005, Christian Gierke 7# 8# This program is licensed under the GPLv2 9 10use strict; 11use warnings; 12use CGI qw(:standard :escapeHTML -nosticky); 13use CGI::Util qw(unescape); 14use CGI::Carp qw(fatalsToBrowser); 15use Encode; 16use Fcntl ':mode'; 17use File::Find qw(); 18use File::Basename qw(basename); 19binmode STDOUT,':utf8'; 20 21BEGIN{ 22 CGI->compile()if$ENV{'MOD_PERL'}; 23} 24 25our$cgi= new CGI; 26our$version="++GIT_VERSION++"; 27our$my_url=$cgi->url(); 28our$my_uri=$cgi->url(-absolute =>1); 29 30# Base URL for relative URLs in gitweb ($logo, $favicon, ...), 31# needed and used only for URLs with nonempty PATH_INFO 32our$base_url=$my_url; 33 34# When the script is used as DirectoryIndex, the URL does not contain the name 35# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we 36# have to do it ourselves. We make $path_info global because it's also used 37# later on. 38# 39# Another issue with the script being the DirectoryIndex is that the resulting 40# $my_url data is not the full script URL: this is good, because we want 41# generated links to keep implying the script name if it wasn't explicitly 42# indicated in the URL we're handling, but it means that $my_url cannot be used 43# as base URL. 44# Therefore, if we needed to strip PATH_INFO, then we know that we have 45# to build the base URL ourselves: 46our$path_info=$ENV{"PATH_INFO"}; 47if($path_info) { 48if($my_url=~ s,\Q$path_info\E$,, && 49$my_uri=~ s,\Q$path_info\E$,, && 50defined$ENV{'SCRIPT_NAME'}) { 51$base_url=$cgi->url(-base =>1) .$ENV{'SCRIPT_NAME'}; 52} 53} 54 55# core git executable to use 56# this can just be "git" if your webserver has a sensible PATH 57our$GIT="++GIT_BINDIR++/git"; 58 59# absolute fs-path which will be prepended to the project path 60#our $projectroot = "/pub/scm"; 61our$projectroot="++GITWEB_PROJECTROOT++"; 62 63# fs traversing limit for getting project list 64# the number is relative to the projectroot 65our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 66 67# target of the home link on top of all pages 68our$home_link=$my_uri||"/"; 69 70# string of the home link on top of all pages 71our$home_link_str="++GITWEB_HOME_LINK_STR++"; 72 73# name of your site or organization to appear in page titles 74# replace this with something more descriptive for clearer bookmarks 75our$site_name="++GITWEB_SITENAME++" 76|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 77 78# filename of html text to include at top of each page 79our$site_header="++GITWEB_SITE_HEADER++"; 80# html text to include at home page 81our$home_text="++GITWEB_HOMETEXT++"; 82# filename of html text to include at bottom of each page 83our$site_footer="++GITWEB_SITE_FOOTER++"; 84 85# URI of stylesheets 86our@stylesheets= ("++GITWEB_CSS++"); 87# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 88our$stylesheet=undef; 89# URI of GIT logo (72x27 size) 90our$logo="++GITWEB_LOGO++"; 91# URI of GIT favicon, assumed to be image/png type 92our$favicon="++GITWEB_FAVICON++"; 93 94# URI and label (title) of GIT logo link 95#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 96#our $logo_label = "git documentation"; 97our$logo_url="http://git-scm.com/"; 98our$logo_label="git homepage"; 99 100# source of projects list 101our$projects_list="++GITWEB_LIST++"; 102 103# the width (in characters) of the projects list "Description" column 104our$projects_list_description_width=25; 105 106# default order of projects list 107# valid values are none, project, descr, owner, and age 108our$default_projects_order="project"; 109 110# show repository only if this file exists 111# (only effective if this variable evaluates to true) 112our$export_ok="++GITWEB_EXPORT_OK++"; 113 114# show repository only if this subroutine returns true 115# when given the path to the project, for example: 116# sub { return -e "$_[0]/git-daemon-export-ok"; } 117our$export_auth_hook=undef; 118 119# only allow viewing of repositories also shown on the overview page 120our$strict_export="++GITWEB_STRICT_EXPORT++"; 121 122# list of git base URLs used for URL to where fetch project from, 123# i.e. full URL is "$git_base_url/$project" 124our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 125 126# default blob_plain mimetype and default charset for text/plain blob 127our$default_blob_plain_mimetype='text/plain'; 128our$default_text_plain_charset=undef; 129 130# file to use for guessing MIME types before trying /etc/mime.types 131# (relative to the current git repository) 132our$mimetypes_file=undef; 133 134# assume this charset if line contains non-UTF-8 characters; 135# it should be valid encoding (see Encoding::Supported(3pm) for list), 136# for which encoding all byte sequences are valid, for example 137# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 138# could be even 'utf-8' for the old behavior) 139our$fallback_encoding='latin1'; 140 141# rename detection options for git-diff and git-diff-tree 142# - default is '-M', with the cost proportional to 143# (number of removed files) * (number of new files). 144# - more costly is '-C' (which implies '-M'), with the cost proportional to 145# (number of changed files + number of removed files) * (number of new files) 146# - even more costly is '-C', '--find-copies-harder' with cost 147# (number of files in the original tree) * (number of new files) 148# - one might want to include '-B' option, e.g. '-B', '-M' 149our@diff_opts= ('-M');# taken from git_commit 150 151# Disables features that would allow repository owners to inject script into 152# the gitweb domain. 153our$prevent_xss=0; 154 155# information about snapshot formats that gitweb is capable of serving 156our%known_snapshot_formats= ( 157# name => { 158# 'display' => display name, 159# 'type' => mime type, 160# 'suffix' => filename suffix, 161# 'format' => --format for git-archive, 162# 'compressor' => [compressor command and arguments] 163# (array reference, optional) 164# 'disabled' => boolean (optional)} 165# 166'tgz'=> { 167'display'=>'tar.gz', 168'type'=>'application/x-gzip', 169'suffix'=>'.tar.gz', 170'format'=>'tar', 171'compressor'=> ['gzip']}, 172 173'tbz2'=> { 174'display'=>'tar.bz2', 175'type'=>'application/x-bzip2', 176'suffix'=>'.tar.bz2', 177'format'=>'tar', 178'compressor'=> ['bzip2']}, 179 180'txz'=> { 181'display'=>'tar.xz', 182'type'=>'application/x-xz', 183'suffix'=>'.tar.xz', 184'format'=>'tar', 185'compressor'=> ['xz'], 186'disabled'=>1}, 187 188'zip'=> { 189'display'=>'zip', 190'type'=>'application/x-zip', 191'suffix'=>'.zip', 192'format'=>'zip'}, 193); 194 195# Aliases so we understand old gitweb.snapshot values in repository 196# configuration. 197our%known_snapshot_format_aliases= ( 198'gzip'=>'tgz', 199'bzip2'=>'tbz2', 200'xz'=>'txz', 201 202# backward compatibility: legacy gitweb config support 203'x-gzip'=>undef,'gz'=>undef, 204'x-bzip2'=>undef,'bz2'=>undef, 205'x-zip'=>undef,''=>undef, 206); 207 208# Pixel sizes for icons and avatars. If the default font sizes or lineheights 209# are changed, it may be appropriate to change these values too via 210# $GITWEB_CONFIG. 211our%avatar_size= ( 212'default'=>16, 213'double'=>32 214); 215 216# You define site-wide feature defaults here; override them with 217# $GITWEB_CONFIG as necessary. 218our%feature= ( 219# feature => { 220# 'sub' => feature-sub (subroutine), 221# 'override' => allow-override (boolean), 222# 'default' => [ default options...] (array reference)} 223# 224# if feature is overridable (it means that allow-override has true value), 225# then feature-sub will be called with default options as parameters; 226# return value of feature-sub indicates if to enable specified feature 227# 228# if there is no 'sub' key (no feature-sub), then feature cannot be 229# overriden 230# 231# use gitweb_get_feature(<feature>) to retrieve the <feature> value 232# (an array) or gitweb_check_feature(<feature>) to check if <feature> 233# is enabled 234 235# Enable the 'blame' blob view, showing the last commit that modified 236# each line in the file. This can be very CPU-intensive. 237 238# To enable system wide have in $GITWEB_CONFIG 239# $feature{'blame'}{'default'} = [1]; 240# To have project specific config enable override in $GITWEB_CONFIG 241# $feature{'blame'}{'override'} = 1; 242# and in project config gitweb.blame = 0|1; 243'blame'=> { 244'sub'=>sub{ feature_bool('blame',@_) }, 245'override'=>0, 246'default'=> [0]}, 247 248# Enable the 'snapshot' link, providing a compressed archive of any 249# tree. This can potentially generate high traffic if you have large 250# project. 251 252# Value is a list of formats defined in %known_snapshot_formats that 253# you wish to offer. 254# To disable system wide have in $GITWEB_CONFIG 255# $feature{'snapshot'}{'default'} = []; 256# To have project specific config enable override in $GITWEB_CONFIG 257# $feature{'snapshot'}{'override'} = 1; 258# and in project config, a comma-separated list of formats or "none" 259# to disable. Example: gitweb.snapshot = tbz2,zip; 260'snapshot'=> { 261'sub'=> \&feature_snapshot, 262'override'=>0, 263'default'=> ['tgz']}, 264 265# Enable text search, which will list the commits which match author, 266# committer or commit text to a given string. Enabled by default. 267# Project specific override is not supported. 268'search'=> { 269'override'=>0, 270'default'=> [1]}, 271 272# Enable grep search, which will list the files in currently selected 273# tree containing the given string. Enabled by default. This can be 274# potentially CPU-intensive, of course. 275 276# To enable system wide have in $GITWEB_CONFIG 277# $feature{'grep'}{'default'} = [1]; 278# To have project specific config enable override in $GITWEB_CONFIG 279# $feature{'grep'}{'override'} = 1; 280# and in project config gitweb.grep = 0|1; 281'grep'=> { 282'sub'=>sub{ feature_bool('grep',@_) }, 283'override'=>0, 284'default'=> [1]}, 285 286# Enable the pickaxe search, which will list the commits that modified 287# a given string in a file. This can be practical and quite faster 288# alternative to 'blame', but still potentially CPU-intensive. 289 290# To enable system wide have in $GITWEB_CONFIG 291# $feature{'pickaxe'}{'default'} = [1]; 292# To have project specific config enable override in $GITWEB_CONFIG 293# $feature{'pickaxe'}{'override'} = 1; 294# and in project config gitweb.pickaxe = 0|1; 295'pickaxe'=> { 296'sub'=>sub{ feature_bool('pickaxe',@_) }, 297'override'=>0, 298'default'=> [1]}, 299 300# Enable showing size of blobs in a 'tree' view, in a separate 301# column, similar to what 'ls -l' does. This cost a bit of IO. 302 303# To disable system wide have in $GITWEB_CONFIG 304# $feature{'show-sizes'}{'default'} = [0]; 305# To have project specific config enable override in $GITWEB_CONFIG 306# $feature{'show-sizes'}{'override'} = 1; 307# and in project config gitweb.showsizes = 0|1; 308'show-sizes'=> { 309'sub'=>sub{ feature_bool('showsizes',@_) }, 310'override'=>0, 311'default'=> [1]}, 312 313# Make gitweb use an alternative format of the URLs which can be 314# more readable and natural-looking: project name is embedded 315# directly in the path and the query string contains other 316# auxiliary information. All gitweb installations recognize 317# URL in either format; this configures in which formats gitweb 318# generates links. 319 320# To enable system wide have in $GITWEB_CONFIG 321# $feature{'pathinfo'}{'default'} = [1]; 322# Project specific override is not supported. 323 324# Note that you will need to change the default location of CSS, 325# favicon, logo and possibly other files to an absolute URL. Also, 326# if gitweb.cgi serves as your indexfile, you will need to force 327# $my_uri to contain the script name in your $GITWEB_CONFIG. 328'pathinfo'=> { 329'override'=>0, 330'default'=> [0]}, 331 332# Make gitweb consider projects in project root subdirectories 333# to be forks of existing projects. Given project $projname.git, 334# projects matching $projname/*.git will not be shown in the main 335# projects list, instead a '+' mark will be added to $projname 336# there and a 'forks' view will be enabled for the project, listing 337# all the forks. If project list is taken from a file, forks have 338# to be listed after the main project. 339 340# To enable system wide have in $GITWEB_CONFIG 341# $feature{'forks'}{'default'} = [1]; 342# Project specific override is not supported. 343'forks'=> { 344'override'=>0, 345'default'=> [0]}, 346 347# Insert custom links to the action bar of all project pages. 348# This enables you mainly to link to third-party scripts integrating 349# into gitweb; e.g. git-browser for graphical history representation 350# or custom web-based repository administration interface. 351 352# The 'default' value consists of a list of triplets in the form 353# (label, link, position) where position is the label after which 354# to insert the link and link is a format string where %n expands 355# to the project name, %f to the project path within the filesystem, 356# %h to the current hash (h gitweb parameter) and %b to the current 357# hash base (hb gitweb parameter); %% expands to %. 358 359# To enable system wide have in $GITWEB_CONFIG e.g. 360# $feature{'actions'}{'default'} = [('graphiclog', 361# '/git-browser/by-commit.html?r=%n', 'summary')]; 362# Project specific override is not supported. 363'actions'=> { 364'override'=>0, 365'default'=> []}, 366 367# Allow gitweb scan project content tags described in ctags/ 368# of project repository, and display the popular Web 2.0-ish 369# "tag cloud" near the project list. Note that this is something 370# COMPLETELY different from the normal Git tags. 371 372# gitweb by itself can show existing tags, but it does not handle 373# tagging itself; you need an external application for that. 374# For an example script, check Girocco's cgi/tagproj.cgi. 375# You may want to install the HTML::TagCloud Perl module to get 376# a pretty tag cloud instead of just a list of tags. 377 378# To enable system wide have in $GITWEB_CONFIG 379# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 380# Project specific override is not supported. 381'ctags'=> { 382'override'=>0, 383'default'=> [0]}, 384 385# The maximum number of patches in a patchset generated in patch 386# view. Set this to 0 or undef to disable patch view, or to a 387# negative number to remove any limit. 388 389# To disable system wide have in $GITWEB_CONFIG 390# $feature{'patches'}{'default'} = [0]; 391# To have project specific config enable override in $GITWEB_CONFIG 392# $feature{'patches'}{'override'} = 1; 393# and in project config gitweb.patches = 0|n; 394# where n is the maximum number of patches allowed in a patchset. 395'patches'=> { 396'sub'=> \&feature_patches, 397'override'=>0, 398'default'=> [16]}, 399 400# Avatar support. When this feature is enabled, views such as 401# shortlog or commit will display an avatar associated with 402# the email of the committer(s) and/or author(s). 403 404# Currently available providers are gravatar and picon. 405# If an unknown provider is specified, the feature is disabled. 406 407# Gravatar depends on Digest::MD5. 408# Picon currently relies on the indiana.edu database. 409 410# To enable system wide have in $GITWEB_CONFIG 411# $feature{'avatar'}{'default'} = ['<provider>']; 412# where <provider> is either gravatar or picon. 413# To have project specific config enable override in $GITWEB_CONFIG 414# $feature{'avatar'}{'override'} = 1; 415# and in project config gitweb.avatar = <provider>; 416'avatar'=> { 417'sub'=> \&feature_avatar, 418'override'=>0, 419'default'=> ['']}, 420); 421 422sub gitweb_get_feature { 423my($name) =@_; 424return unlessexists$feature{$name}; 425my($sub,$override,@defaults) = ( 426$feature{$name}{'sub'}, 427$feature{$name}{'override'}, 428@{$feature{$name}{'default'}}); 429if(!$override) {return@defaults; } 430if(!defined$sub) { 431warn"feature$nameis not overridable"; 432return@defaults; 433} 434return$sub->(@defaults); 435} 436 437# A wrapper to check if a given feature is enabled. 438# With this, you can say 439# 440# my $bool_feat = gitweb_check_feature('bool_feat'); 441# gitweb_check_feature('bool_feat') or somecode; 442# 443# instead of 444# 445# my ($bool_feat) = gitweb_get_feature('bool_feat'); 446# (gitweb_get_feature('bool_feat'))[0] or somecode; 447# 448sub gitweb_check_feature { 449return(gitweb_get_feature(@_))[0]; 450} 451 452 453sub feature_bool { 454my$key=shift; 455my($val) = git_get_project_config($key,'--bool'); 456 457if(!defined$val) { 458return($_[0]); 459}elsif($valeq'true') { 460return(1); 461}elsif($valeq'false') { 462return(0); 463} 464} 465 466sub feature_snapshot { 467my(@fmts) =@_; 468 469my($val) = git_get_project_config('snapshot'); 470 471if($val) { 472@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 473} 474 475return@fmts; 476} 477 478sub feature_patches { 479my@val= (git_get_project_config('patches','--int')); 480 481if(@val) { 482return@val; 483} 484 485return($_[0]); 486} 487 488sub feature_avatar { 489my@val= (git_get_project_config('avatar')); 490 491return@val?@val:@_; 492} 493 494# checking HEAD file with -e is fragile if the repository was 495# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 496# and then pruned. 497sub check_head_link { 498my($dir) =@_; 499my$headfile="$dir/HEAD"; 500return((-e $headfile) || 501(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 502} 503 504sub check_export_ok { 505my($dir) =@_; 506return(check_head_link($dir) && 507(!$export_ok|| -e "$dir/$export_ok") && 508(!$export_auth_hook||$export_auth_hook->($dir))); 509} 510 511# process alternate names for backward compatibility 512# filter out unsupported (unknown) snapshot formats 513sub filter_snapshot_fmts { 514my@fmts=@_; 515 516@fmts=map{ 517exists$known_snapshot_format_aliases{$_} ? 518$known_snapshot_format_aliases{$_} :$_}@fmts; 519@fmts=grep{ 520exists$known_snapshot_formats{$_} && 521!$known_snapshot_formats{$_}{'disabled'}}@fmts; 522} 523 524our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 525if(-e $GITWEB_CONFIG) { 526do$GITWEB_CONFIG; 527}else{ 528our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 529do$GITWEB_CONFIG_SYSTEMif-e $GITWEB_CONFIG_SYSTEM; 530} 531 532# version of the core git binary 533our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 534 535$projects_list||=$projectroot; 536 537# ====================================================================== 538# input validation and dispatch 539 540# input parameters can be collected from a variety of sources (presently, CGI 541# and PATH_INFO), so we define an %input_params hash that collects them all 542# together during validation: this allows subsequent uses (e.g. href()) to be 543# agnostic of the parameter origin 544 545our%input_params= (); 546 547# input parameters are stored with the long parameter name as key. This will 548# also be used in the href subroutine to convert parameters to their CGI 549# equivalent, and since the href() usage is the most frequent one, we store 550# the name -> CGI key mapping here, instead of the reverse. 551# 552# XXX: Warning: If you touch this, check the search form for updating, 553# too. 554 555our@cgi_param_mapping= ( 556 project =>"p", 557 action =>"a", 558 file_name =>"f", 559 file_parent =>"fp", 560 hash =>"h", 561 hash_parent =>"hp", 562 hash_base =>"hb", 563 hash_parent_base =>"hpb", 564 page =>"pg", 565 order =>"o", 566 searchtext =>"s", 567 searchtype =>"st", 568 snapshot_format =>"sf", 569 extra_options =>"opt", 570 search_use_regexp =>"sr", 571); 572our%cgi_param_mapping=@cgi_param_mapping; 573 574# we will also need to know the possible actions, for validation 575our%actions= ( 576"blame"=> \&git_blame, 577"blobdiff"=> \&git_blobdiff, 578"blobdiff_plain"=> \&git_blobdiff_plain, 579"blob"=> \&git_blob, 580"blob_plain"=> \&git_blob_plain, 581"commitdiff"=> \&git_commitdiff, 582"commitdiff_plain"=> \&git_commitdiff_plain, 583"commit"=> \&git_commit, 584"forks"=> \&git_forks, 585"heads"=> \&git_heads, 586"history"=> \&git_history, 587"log"=> \&git_log, 588"patch"=> \&git_patch, 589"patches"=> \&git_patches, 590"rss"=> \&git_rss, 591"atom"=> \&git_atom, 592"search"=> \&git_search, 593"search_help"=> \&git_search_help, 594"shortlog"=> \&git_shortlog, 595"summary"=> \&git_summary, 596"tag"=> \&git_tag, 597"tags"=> \&git_tags, 598"tree"=> \&git_tree, 599"snapshot"=> \&git_snapshot, 600"object"=> \&git_object, 601# those below don't need $project 602"opml"=> \&git_opml, 603"project_list"=> \&git_project_list, 604"project_index"=> \&git_project_index, 605); 606 607# finally, we have the hash of allowed extra_options for the commands that 608# allow them 609our%allowed_options= ( 610"--no-merges"=> [qw(rss atom log shortlog history)], 611); 612 613# fill %input_params with the CGI parameters. All values except for 'opt' 614# should be single values, but opt can be an array. We should probably 615# build an array of parameters that can be multi-valued, but since for the time 616# being it's only this one, we just single it out 617while(my($name,$symbol) =each%cgi_param_mapping) { 618if($symboleq'opt') { 619$input_params{$name} = [$cgi->param($symbol) ]; 620}else{ 621$input_params{$name} =$cgi->param($symbol); 622} 623} 624 625# now read PATH_INFO and update the parameter list for missing parameters 626sub evaluate_path_info { 627return ifdefined$input_params{'project'}; 628return if!$path_info; 629$path_info=~ s,^/+,,; 630return if!$path_info; 631 632# find which part of PATH_INFO is project 633my$project=$path_info; 634$project=~ s,/+$,,; 635while($project&& !check_head_link("$projectroot/$project")) { 636$project=~ s,/*[^/]*$,,; 637} 638return unless$project; 639$input_params{'project'} =$project; 640 641# do not change any parameters if an action is given using the query string 642return if$input_params{'action'}; 643$path_info=~ s,^\Q$project\E/*,,; 644 645# next, check if we have an action 646my$action=$path_info; 647$action=~ s,/.*$,,; 648if(exists$actions{$action}) { 649$path_info=~ s,^$action/*,,; 650$input_params{'action'} =$action; 651} 652 653# list of actions that want hash_base instead of hash, but can have no 654# pathname (f) parameter 655my@wants_base= ( 656'tree', 657'history', 658); 659 660# we want to catch 661# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 662my($parentrefname,$parentpathname,$refname,$pathname) = 663($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/); 664 665# first, analyze the 'current' part 666if(defined$pathname) { 667# we got "branch:filename" or "branch:dir/" 668# we could use git_get_type(branch:pathname), but: 669# - it needs $git_dir 670# - it does a git() call 671# - the convention of terminating directories with a slash 672# makes it superfluous 673# - embedding the action in the PATH_INFO would make it even 674# more superfluous 675$pathname=~ s,^/+,,; 676if(!$pathname||substr($pathname, -1)eq"/") { 677$input_params{'action'} ||="tree"; 678$pathname=~ s,/$,,; 679}else{ 680# the default action depends on whether we had parent info 681# or not 682if($parentrefname) { 683$input_params{'action'} ||="blobdiff_plain"; 684}else{ 685$input_params{'action'} ||="blob_plain"; 686} 687} 688$input_params{'hash_base'} ||=$refname; 689$input_params{'file_name'} ||=$pathname; 690}elsif(defined$refname) { 691# we got "branch". In this case we have to choose if we have to 692# set hash or hash_base. 693# 694# Most of the actions without a pathname only want hash to be 695# set, except for the ones specified in @wants_base that want 696# hash_base instead. It should also be noted that hand-crafted 697# links having 'history' as an action and no pathname or hash 698# set will fail, but that happens regardless of PATH_INFO. 699$input_params{'action'} ||="shortlog"; 700if(grep{$_eq$input_params{'action'} }@wants_base) { 701$input_params{'hash_base'} ||=$refname; 702}else{ 703$input_params{'hash'} ||=$refname; 704} 705} 706 707# next, handle the 'parent' part, if present 708if(defined$parentrefname) { 709# a missing pathspec defaults to the 'current' filename, allowing e.g. 710# someproject/blobdiff/oldrev..newrev:/filename 711if($parentpathname) { 712$parentpathname=~ s,^/+,,; 713$parentpathname=~ s,/$,,; 714$input_params{'file_parent'} ||=$parentpathname; 715}else{ 716$input_params{'file_parent'} ||=$input_params{'file_name'}; 717} 718# we assume that hash_parent_base is wanted if a path was specified, 719# or if the action wants hash_base instead of hash 720if(defined$input_params{'file_parent'} || 721grep{$_eq$input_params{'action'} }@wants_base) { 722$input_params{'hash_parent_base'} ||=$parentrefname; 723}else{ 724$input_params{'hash_parent'} ||=$parentrefname; 725} 726} 727 728# for the snapshot action, we allow URLs in the form 729# $project/snapshot/$hash.ext 730# where .ext determines the snapshot and gets removed from the 731# passed $refname to provide the $hash. 732# 733# To be able to tell that $refname includes the format extension, we 734# require the following two conditions to be satisfied: 735# - the hash input parameter MUST have been set from the $refname part 736# of the URL (i.e. they must be equal) 737# - the snapshot format MUST NOT have been defined already (e.g. from 738# CGI parameter sf) 739# It's also useless to try any matching unless $refname has a dot, 740# so we check for that too 741if(defined$input_params{'action'} && 742$input_params{'action'}eq'snapshot'&& 743defined$refname&&index($refname,'.') != -1&& 744$refnameeq$input_params{'hash'} && 745!defined$input_params{'snapshot_format'}) { 746# We loop over the known snapshot formats, checking for 747# extensions. Allowed extensions are both the defined suffix 748# (which includes the initial dot already) and the snapshot 749# format key itself, with a prepended dot 750while(my($fmt,$opt) =each%known_snapshot_formats) { 751my$hash=$refname; 752unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 753next; 754} 755my$sfx=$1; 756# a valid suffix was found, so set the snapshot format 757# and reset the hash parameter 758$input_params{'snapshot_format'} =$fmt; 759$input_params{'hash'} =$hash; 760# we also set the format suffix to the one requested 761# in the URL: this way a request for e.g. .tgz returns 762# a .tgz instead of a .tar.gz 763$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 764last; 765} 766} 767} 768evaluate_path_info(); 769 770our$action=$input_params{'action'}; 771if(defined$action) { 772if(!validate_action($action)) { 773 die_error(400,"Invalid action parameter"); 774} 775} 776 777# parameters which are pathnames 778our$project=$input_params{'project'}; 779if(defined$project) { 780if(!validate_project($project)) { 781undef$project; 782 die_error(404,"No such project"); 783} 784} 785 786our$file_name=$input_params{'file_name'}; 787if(defined$file_name) { 788if(!validate_pathname($file_name)) { 789 die_error(400,"Invalid file parameter"); 790} 791} 792 793our$file_parent=$input_params{'file_parent'}; 794if(defined$file_parent) { 795if(!validate_pathname($file_parent)) { 796 die_error(400,"Invalid file parent parameter"); 797} 798} 799 800# parameters which are refnames 801our$hash=$input_params{'hash'}; 802if(defined$hash) { 803if(!validate_refname($hash)) { 804 die_error(400,"Invalid hash parameter"); 805} 806} 807 808our$hash_parent=$input_params{'hash_parent'}; 809if(defined$hash_parent) { 810if(!validate_refname($hash_parent)) { 811 die_error(400,"Invalid hash parent parameter"); 812} 813} 814 815our$hash_base=$input_params{'hash_base'}; 816if(defined$hash_base) { 817if(!validate_refname($hash_base)) { 818 die_error(400,"Invalid hash base parameter"); 819} 820} 821 822our@extra_options= @{$input_params{'extra_options'}}; 823# @extra_options is always defined, since it can only be (currently) set from 824# CGI, and $cgi->param() returns the empty array in array context if the param 825# is not set 826foreachmy$opt(@extra_options) { 827if(not exists$allowed_options{$opt}) { 828 die_error(400,"Invalid option parameter"); 829} 830if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 831 die_error(400,"Invalid option parameter for this action"); 832} 833} 834 835our$hash_parent_base=$input_params{'hash_parent_base'}; 836if(defined$hash_parent_base) { 837if(!validate_refname($hash_parent_base)) { 838 die_error(400,"Invalid hash parent base parameter"); 839} 840} 841 842# other parameters 843our$page=$input_params{'page'}; 844if(defined$page) { 845if($page=~m/[^0-9]/) { 846 die_error(400,"Invalid page parameter"); 847} 848} 849 850our$searchtype=$input_params{'searchtype'}; 851if(defined$searchtype) { 852if($searchtype=~m/[^a-z]/) { 853 die_error(400,"Invalid searchtype parameter"); 854} 855} 856 857our$search_use_regexp=$input_params{'search_use_regexp'}; 858 859our$searchtext=$input_params{'searchtext'}; 860our$search_regexp; 861if(defined$searchtext) { 862if(length($searchtext) <2) { 863 die_error(403,"At least two characters are required for search parameter"); 864} 865$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 866} 867 868# path to the current git repository 869our$git_dir; 870$git_dir="$projectroot/$project"if$project; 871 872# list of supported snapshot formats 873our@snapshot_fmts= gitweb_get_feature('snapshot'); 874@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts); 875 876# check that the avatar feature is set to a known provider name, 877# and for each provider check if the dependencies are satisfied. 878# if the provider name is invalid or the dependencies are not met, 879# reset $git_avatar to the empty string. 880our($git_avatar) = gitweb_get_feature('avatar'); 881if($git_avatareq'gravatar') { 882$git_avatar=''unless(eval{require Digest::MD5;1; }); 883}elsif($git_avatareq'picon') { 884# no dependencies 885}else{ 886$git_avatar=''; 887} 888 889# dispatch 890if(!defined$action) { 891if(defined$hash) { 892$action= git_get_type($hash); 893}elsif(defined$hash_base&&defined$file_name) { 894$action= git_get_type("$hash_base:$file_name"); 895}elsif(defined$project) { 896$action='summary'; 897}else{ 898$action='project_list'; 899} 900} 901if(!defined($actions{$action})) { 902 die_error(400,"Unknown action"); 903} 904if($action!~m/^(?:opml|project_list|project_index)$/&& 905!$project) { 906 die_error(400,"Project needed"); 907} 908$actions{$action}->(); 909exit; 910 911## ====================================================================== 912## action links 913 914sub href { 915my%params=@_; 916# default is to use -absolute url() i.e. $my_uri 917my$href=$params{-full} ?$my_url:$my_uri; 918 919$params{'project'} =$projectunlessexists$params{'project'}; 920 921if($params{-replay}) { 922while(my($name,$symbol) =each%cgi_param_mapping) { 923if(!exists$params{$name}) { 924$params{$name} =$input_params{$name}; 925} 926} 927} 928 929my$use_pathinfo= gitweb_check_feature('pathinfo'); 930if($use_pathinfoand defined$params{'project'}) { 931# try to put as many parameters as possible in PATH_INFO: 932# - project name 933# - action 934# - hash_parent or hash_parent_base:/file_parent 935# - hash or hash_base:/filename 936# - the snapshot_format as an appropriate suffix 937 938# When the script is the root DirectoryIndex for the domain, 939# $href here would be something like http://gitweb.example.com/ 940# Thus, we strip any trailing / from $href, to spare us double 941# slashes in the final URL 942$href=~ s,/$,,; 943 944# Then add the project name, if present 945$href.="/".esc_url($params{'project'}); 946delete$params{'project'}; 947 948# since we destructively absorb parameters, we keep this 949# boolean that remembers if we're handling a snapshot 950my$is_snapshot=$params{'action'}eq'snapshot'; 951 952# Summary just uses the project path URL, any other action is 953# added to the URL 954if(defined$params{'action'}) { 955$href.="/".esc_url($params{'action'})unless$params{'action'}eq'summary'; 956delete$params{'action'}; 957} 958 959# Next, we put hash_parent_base:/file_parent..hash_base:/file_name, 960# stripping nonexistent or useless pieces 961$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'} 962||$params{'hash_parent'} ||$params{'hash'}); 963if(defined$params{'hash_base'}) { 964if(defined$params{'hash_parent_base'}) { 965$href.= esc_url($params{'hash_parent_base'}); 966# skip the file_parent if it's the same as the file_name 967if(defined$params{'file_parent'}) { 968if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) { 969delete$params{'file_parent'}; 970}elsif($params{'file_parent'} !~/\.\./) { 971$href.=":/".esc_url($params{'file_parent'}); 972delete$params{'file_parent'}; 973} 974} 975$href.=".."; 976delete$params{'hash_parent'}; 977delete$params{'hash_parent_base'}; 978}elsif(defined$params{'hash_parent'}) { 979$href.= esc_url($params{'hash_parent'}).".."; 980delete$params{'hash_parent'}; 981} 982 983$href.= esc_url($params{'hash_base'}); 984if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) { 985$href.=":/".esc_url($params{'file_name'}); 986delete$params{'file_name'}; 987} 988delete$params{'hash'}; 989delete$params{'hash_base'}; 990}elsif(defined$params{'hash'}) { 991$href.= esc_url($params{'hash'}); 992delete$params{'hash'}; 993} 994 995# If the action was a snapshot, we can absorb the 996# snapshot_format parameter too 997if($is_snapshot) { 998my$fmt=$params{'snapshot_format'}; 999# snapshot_format should always be defined when href()1000# is called, but just in case some code forgets, we1001# fall back to the default1002$fmt||=$snapshot_fmts[0];1003$href.=$known_snapshot_formats{$fmt}{'suffix'};1004delete$params{'snapshot_format'};1005}1006}10071008# now encode the parameters explicitly1009my@result= ();1010for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1011my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1012if(defined$params{$name}) {1013if(ref($params{$name})eq"ARRAY") {1014foreachmy$par(@{$params{$name}}) {1015push@result,$symbol."=". esc_param($par);1016}1017}else{1018push@result,$symbol."=". esc_param($params{$name});1019}1020}1021}1022$href.="?".join(';',@result)ifscalar@result;10231024return$href;1025}102610271028## ======================================================================1029## validation, quoting/unquoting and escaping10301031sub validate_action {1032my$input=shift||returnundef;1033returnundefunlessexists$actions{$input};1034return$input;1035}10361037sub validate_project {1038my$input=shift||returnundef;1039if(!validate_pathname($input) ||1040!(-d "$projectroot/$input") ||1041!check_export_ok("$projectroot/$input") ||1042($strict_export&& !project_in_list($input))) {1043returnundef;1044}else{1045return$input;1046}1047}10481049sub validate_pathname {1050my$input=shift||returnundef;10511052# no '.' or '..' as elements of path, i.e. no '.' nor '..'1053# at the beginning, at the end, and between slashes.1054# also this catches doubled slashes1055if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1056returnundef;1057}1058# no null characters1059if($input=~m!\0!) {1060returnundef;1061}1062return$input;1063}10641065sub validate_refname {1066my$input=shift||returnundef;10671068# textual hashes are O.K.1069if($input=~m/^[0-9a-fA-F]{40}$/) {1070return$input;1071}1072# it must be correct pathname1073$input= validate_pathname($input)1074orreturnundef;1075# restrictions on ref name according to git-check-ref-format1076if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1077returnundef;1078}1079return$input;1080}10811082# decode sequences of octets in utf8 into Perl's internal form,1083# which is utf-8 with utf8 flag set if needed. gitweb writes out1084# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1085sub to_utf8 {1086my$str=shift;1087if(utf8::valid($str)) {1088 utf8::decode($str);1089return$str;1090}else{1091return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1092}1093}10941095# quote unsafe chars, but keep the slash, even when it's not1096# correct, but quoted slashes look too horrible in bookmarks1097sub esc_param {1098my$str=shift;1099$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1100$str=~s/ /\+/g;1101return$str;1102}11031104# quote unsafe chars in whole URL, so some charactrs cannot be quoted1105sub esc_url {1106my$str=shift;1107$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X",ord($1))/eg;1108$str=~s/\+/%2B/g;1109$str=~s/ /\+/g;1110return$str;1111}11121113# replace invalid utf8 character with SUBSTITUTION sequence1114sub esc_html {1115my$str=shift;1116my%opts=@_;11171118$str= to_utf8($str);1119$str=$cgi->escapeHTML($str);1120if($opts{'-nbsp'}) {1121$str=~s/ / /g;1122}1123$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1124return$str;1125}11261127# quote control characters and escape filename to HTML1128sub esc_path {1129my$str=shift;1130my%opts=@_;11311132$str= to_utf8($str);1133$str=$cgi->escapeHTML($str);1134if($opts{'-nbsp'}) {1135$str=~s/ / /g;1136}1137$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1138return$str;1139}11401141# Make control characters "printable", using character escape codes (CEC)1142sub quot_cec {1143my$cntrl=shift;1144my%opts=@_;1145my%es= (# character escape codes, aka escape sequences1146"\t"=>'\t',# tab (HT)1147"\n"=>'\n',# line feed (LF)1148"\r"=>'\r',# carrige return (CR)1149"\f"=>'\f',# form feed (FF)1150"\b"=>'\b',# backspace (BS)1151"\a"=>'\a',# alarm (bell) (BEL)1152"\e"=>'\e',# escape (ESC)1153"\013"=>'\v',# vertical tab (VT)1154"\000"=>'\0',# nul character (NUL)1155);1156my$chr= ( (exists$es{$cntrl})1157?$es{$cntrl}1158:sprintf('\%2x',ord($cntrl)) );1159if($opts{-nohtml}) {1160return$chr;1161}else{1162return"<span class=\"cntrl\">$chr</span>";1163}1164}11651166# Alternatively use unicode control pictures codepoints,1167# Unicode "printable representation" (PR)1168sub quot_upr {1169my$cntrl=shift;1170my%opts=@_;11711172my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1173if($opts{-nohtml}) {1174return$chr;1175}else{1176return"<span class=\"cntrl\">$chr</span>";1177}1178}11791180# git may return quoted and escaped filenames1181sub unquote {1182my$str=shift;11831184sub unq {1185my$seq=shift;1186my%es= (# character escape codes, aka escape sequences1187't'=>"\t",# tab (HT, TAB)1188'n'=>"\n",# newline (NL)1189'r'=>"\r",# return (CR)1190'f'=>"\f",# form feed (FF)1191'b'=>"\b",# backspace (BS)1192'a'=>"\a",# alarm (bell) (BEL)1193'e'=>"\e",# escape (ESC)1194'v'=>"\013",# vertical tab (VT)1195);11961197if($seq=~m/^[0-7]{1,3}$/) {1198# octal char sequence1199returnchr(oct($seq));1200}elsif(exists$es{$seq}) {1201# C escape sequence, aka character escape code1202return$es{$seq};1203}1204# quoted ordinary character1205return$seq;1206}12071208if($str=~m/^"(.*)"$/) {1209# needs unquoting1210$str=$1;1211$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1212}1213return$str;1214}12151216# escape tabs (convert tabs to spaces)1217sub untabify {1218my$line=shift;12191220while((my$pos=index($line,"\t")) != -1) {1221if(my$count= (8- ($pos%8))) {1222my$spaces=' ' x $count;1223$line=~s/\t/$spaces/;1224}1225}12261227return$line;1228}12291230sub project_in_list {1231my$project=shift;1232my@list= git_get_projects_list();1233return@list&&scalar(grep{$_->{'path'}eq$project}@list);1234}12351236## ----------------------------------------------------------------------1237## HTML aware string manipulation12381239# Try to chop given string on a word boundary between position1240# $len and $len+$add_len. If there is no word boundary there,1241# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1242# (marking chopped part) would be longer than given string.1243sub chop_str {1244my$str=shift;1245my$len=shift;1246my$add_len=shift||10;1247my$where=shift||'right';# 'left' | 'center' | 'right'12481249# Make sure perl knows it is utf8 encoded so we don't1250# cut in the middle of a utf8 multibyte char.1251$str= to_utf8($str);12521253# allow only $len chars, but don't cut a word if it would fit in $add_len1254# if it doesn't fit, cut it if it's still longer than the dots we would add1255# remove chopped character entities entirely12561257# when chopping in the middle, distribute $len into left and right part1258# return early if chopping wouldn't make string shorter1259if($whereeq'center') {1260return$strif($len+5>=length($str));# filler is length 51261$len=int($len/2);1262}else{1263return$strif($len+4>=length($str));# filler is length 41264}12651266# regexps: ending and beginning with word part up to $add_len1267my$endre=qr/.{$len}\w{0,$add_len}/;1268my$begre=qr/\w{0,$add_len}.{$len}/;12691270if($whereeq'left') {1271$str=~m/^(.*?)($begre)$/;1272my($lead,$body) = ($1,$2);1273if(length($lead) >4) {1274$body=~s/^[^;]*;//if($lead=~m/&[^;]*$/);1275$lead=" ...";1276}1277return"$lead$body";12781279}elsif($whereeq'center') {1280$str=~m/^($endre)(.*)$/;1281my($left,$str) = ($1,$2);1282$str=~m/^(.*?)($begre)$/;1283my($mid,$right) = ($1,$2);1284if(length($mid) >5) {1285$left=~s/&[^;]*$//;1286$right=~s/^[^;]*;//if($mid=~m/&[^;]*$/);1287$mid=" ... ";1288}1289return"$left$mid$right";12901291}else{1292$str=~m/^($endre)(.*)$/;1293my$body=$1;1294my$tail=$2;1295if(length($tail) >4) {1296$body=~s/&[^;]*$//;1297$tail="... ";1298}1299return"$body$tail";1300}1301}13021303# takes the same arguments as chop_str, but also wraps a <span> around the1304# result with a title attribute if it does get chopped. Additionally, the1305# string is HTML-escaped.1306sub chop_and_escape_str {1307my($str) =@_;13081309my$chopped= chop_str(@_);1310if($choppedeq$str) {1311return esc_html($chopped);1312}else{1313$str=~s/[[:cntrl:]]/?/g;1314return$cgi->span({-title=>$str}, esc_html($chopped));1315}1316}13171318## ----------------------------------------------------------------------1319## functions returning short strings13201321# CSS class for given age value (in seconds)1322sub age_class {1323my$age=shift;13241325if(!defined$age) {1326return"noage";1327}elsif($age<60*60*2) {1328return"age0";1329}elsif($age<60*60*24*2) {1330return"age1";1331}else{1332return"age2";1333}1334}13351336# convert age in seconds to "nn units ago" string1337sub age_string {1338my$age=shift;1339my$age_str;13401341if($age>60*60*24*365*2) {1342$age_str= (int$age/60/60/24/365);1343$age_str.=" years ago";1344}elsif($age>60*60*24*(365/12)*2) {1345$age_str=int$age/60/60/24/(365/12);1346$age_str.=" months ago";1347}elsif($age>60*60*24*7*2) {1348$age_str=int$age/60/60/24/7;1349$age_str.=" weeks ago";1350}elsif($age>60*60*24*2) {1351$age_str=int$age/60/60/24;1352$age_str.=" days ago";1353}elsif($age>60*60*2) {1354$age_str=int$age/60/60;1355$age_str.=" hours ago";1356}elsif($age>60*2) {1357$age_str=int$age/60;1358$age_str.=" min ago";1359}elsif($age>2) {1360$age_str=int$age;1361$age_str.=" sec ago";1362}else{1363$age_str.=" right now";1364}1365return$age_str;1366}13671368useconstant{1369 S_IFINVALID =>0030000,1370 S_IFGITLINK =>0160000,1371};13721373# submodule/subproject, a commit object reference1374sub S_ISGITLINK {1375my$mode=shift;13761377return(($mode& S_IFMT) == S_IFGITLINK)1378}13791380# convert file mode in octal to symbolic file mode string1381sub mode_str {1382my$mode=oct shift;13831384if(S_ISGITLINK($mode)) {1385return'm---------';1386}elsif(S_ISDIR($mode& S_IFMT)) {1387return'drwxr-xr-x';1388}elsif(S_ISLNK($mode)) {1389return'lrwxrwxrwx';1390}elsif(S_ISREG($mode)) {1391# git cares only about the executable bit1392if($mode& S_IXUSR) {1393return'-rwxr-xr-x';1394}else{1395return'-rw-r--r--';1396};1397}else{1398return'----------';1399}1400}14011402# convert file mode in octal to file type string1403sub file_type {1404my$mode=shift;14051406if($mode!~m/^[0-7]+$/) {1407return$mode;1408}else{1409$mode=oct$mode;1410}14111412if(S_ISGITLINK($mode)) {1413return"submodule";1414}elsif(S_ISDIR($mode& S_IFMT)) {1415return"directory";1416}elsif(S_ISLNK($mode)) {1417return"symlink";1418}elsif(S_ISREG($mode)) {1419return"file";1420}else{1421return"unknown";1422}1423}14241425# convert file mode in octal to file type description string1426sub file_type_long {1427my$mode=shift;14281429if($mode!~m/^[0-7]+$/) {1430return$mode;1431}else{1432$mode=oct$mode;1433}14341435if(S_ISGITLINK($mode)) {1436return"submodule";1437}elsif(S_ISDIR($mode& S_IFMT)) {1438return"directory";1439}elsif(S_ISLNK($mode)) {1440return"symlink";1441}elsif(S_ISREG($mode)) {1442if($mode& S_IXUSR) {1443return"executable";1444}else{1445return"file";1446};1447}else{1448return"unknown";1449}1450}145114521453## ----------------------------------------------------------------------1454## functions returning short HTML fragments, or transforming HTML fragments1455## which don't belong to other sections14561457# format line of commit message.1458sub format_log_line_html {1459my$line=shift;14601461$line= esc_html($line, -nbsp=>1);1462$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1463$cgi->a({-href => href(action=>"object", hash=>$1),1464-class=>"text"},$1);1465}eg;14661467return$line;1468}14691470# format marker of refs pointing to given object14711472# the destination action is chosen based on object type and current context:1473# - for annotated tags, we choose the tag view unless it's the current view1474# already, in which case we go to shortlog view1475# - for other refs, we keep the current view if we're in history, shortlog or1476# log view, and select shortlog otherwise1477sub format_ref_marker {1478my($refs,$id) =@_;1479my$markers='';14801481if(defined$refs->{$id}) {1482foreachmy$ref(@{$refs->{$id}}) {1483# this code exploits the fact that non-lightweight tags are the1484# only indirect objects, and that they are the only objects for which1485# we want to use tag instead of shortlog as action1486my($type,$name) =qw();1487my$indirect= ($ref=~s/\^\{\}$//);1488# e.g. tags/v2.6.11 or heads/next1489if($ref=~m!^(.*?)s?/(.*)$!) {1490$type=$1;1491$name=$2;1492}else{1493$type="ref";1494$name=$ref;1495}14961497my$class=$type;1498$class.=" indirect"if$indirect;14991500my$dest_action="shortlog";15011502if($indirect) {1503$dest_action="tag"unless$actioneq"tag";1504}elsif($action=~/^(history|(short)?log)$/) {1505$dest_action=$action;1506}15071508my$dest="";1509$dest.="refs/"unless$ref=~ m!^refs/!;1510$dest.=$ref;15111512my$link=$cgi->a({1513-href => href(1514 action=>$dest_action,1515 hash=>$dest1516)},$name);15171518$markers.=" <span class=\"$class\"title=\"$ref\">".1519$link."</span>";1520}1521}15221523if($markers) {1524return' <span class="refs">'.$markers.'</span>';1525}else{1526return"";1527}1528}15291530# format, perhaps shortened and with markers, title line1531sub format_subject_html {1532my($long,$short,$href,$extra) =@_;1533$extra=''unlessdefined($extra);15341535if(length($short) <length($long)) {1536$long=~s/[[:cntrl:]]/?/g;1537return$cgi->a({-href =>$href, -class=>"list subject",1538-title => to_utf8($long)},1539 esc_html($short)) .$extra;1540}else{1541return$cgi->a({-href =>$href, -class=>"list subject"},1542 esc_html($long)) .$extra;1543}1544}15451546# Rather than recomputing the url for an email multiple times, we cache it1547# after the first hit. This gives a visible benefit in views where the avatar1548# for the same email is used repeatedly (e.g. shortlog).1549# The cache is shared by all avatar engines (currently gravatar only), which1550# are free to use it as preferred. Since only one avatar engine is used for any1551# given page, there's no risk for cache conflicts.1552our%avatar_cache= ();15531554# Compute the picon url for a given email, by using the picon search service over at1555# http://www.cs.indiana.edu/picons/search.html1556sub picon_url {1557my$email=lc shift;1558if(!$avatar_cache{$email}) {1559my($user,$domain) =split('@',$email);1560$avatar_cache{$email} =1561"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".1562"$domain/$user/".1563"users+domains+unknown/up/single";1564}1565return$avatar_cache{$email};1566}15671568# Compute the gravatar url for a given email, if it's not in the cache already.1569# Gravatar stores only the part of the URL before the size, since that's the1570# one computationally more expensive. This also allows reuse of the cache for1571# different sizes (for this particular engine).1572sub gravatar_url {1573my$email=lc shift;1574my$size=shift;1575$avatar_cache{$email} ||=1576"http://www.gravatar.com/avatar/".1577 Digest::MD5::md5_hex($email) ."?s=";1578return$avatar_cache{$email} .$size;1579}15801581# Insert an avatar for the given $email at the given $size if the feature1582# is enabled.1583sub git_get_avatar {1584my($email,%opts) =@_;1585my$pre_white= ($opts{-pad_before} ?" ":"");1586my$post_white= ($opts{-pad_after} ?" ":"");1587$opts{-size} ||='default';1588my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};1589my$url="";1590if($git_avatareq'gravatar') {1591$url= gravatar_url($email,$size);1592}elsif($git_avatareq'picon') {1593$url= picon_url($email);1594}1595# Other providers can be added by extending the if chain, defining $url1596# as needed. If no variant puts something in $url, we assume avatars1597# are completely disabled/unavailable.1598if($url) {1599return$pre_white.1600"<img width=\"$size\"".1601"class=\"avatar\"".1602"src=\"$url\"".1603"alt=\"\"".1604"/>".$post_white;1605}else{1606return"";1607}1608}16091610sub format_search_author {1611my($author,$searchtype,$displaytext) =@_;1612my$have_search= gitweb_check_feature('search');16131614if($have_search) {1615my$performed="";1616if($searchtypeeq'author') {1617$performed="authored";1618}elsif($searchtypeeq'committer') {1619$performed="committed";1620}16211622return$cgi->a({-href => href(action=>"search", hash=>$hash,1623 searchtext=>$author,1624 searchtype=>$searchtype),class=>"list",1625 title=>"Search for commits$performedby$author"},1626$displaytext);16271628}else{1629return$displaytext;1630}1631}16321633# format the author name of the given commit with the given tag1634# the author name is chopped and escaped according to the other1635# optional parameters (see chop_str).1636sub format_author_html {1637my$tag=shift;1638my$co=shift;1639my$author= chop_and_escape_str($co->{'author_name'},@_);1640return"<$tagclass=\"author\">".1641 format_search_author($co->{'author_name'},"author",1642 git_get_avatar($co->{'author_email'}, -pad_after =>1) .1643$author) .1644"</$tag>";1645}16461647# format git diff header line, i.e. "diff --(git|combined|cc) ..."1648sub format_git_diff_header_line {1649my$line=shift;1650my$diffinfo=shift;1651my($from,$to) =@_;16521653if($diffinfo->{'nparents'}) {1654# combined diff1655$line=~s!^(diff (.*?) )"?.*$!$1!;1656if($to->{'href'}) {1657$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1658 esc_path($to->{'file'}));1659}else{# file was deleted (no href)1660$line.= esc_path($to->{'file'});1661}1662}else{1663# "ordinary" diff1664$line=~s!^(diff (.*?) )"?a/.*$!$1!;1665if($from->{'href'}) {1666$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1667'a/'. esc_path($from->{'file'}));1668}else{# file was added (no href)1669$line.='a/'. esc_path($from->{'file'});1670}1671$line.=' ';1672if($to->{'href'}) {1673$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1674'b/'. esc_path($to->{'file'}));1675}else{# file was deleted1676$line.='b/'. esc_path($to->{'file'});1677}1678}16791680return"<div class=\"diff header\">$line</div>\n";1681}16821683# format extended diff header line, before patch itself1684sub format_extended_diff_header_line {1685my$line=shift;1686my$diffinfo=shift;1687my($from,$to) =@_;16881689# match <path>1690if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1691$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1692 esc_path($from->{'file'}));1693}1694if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1695$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1696 esc_path($to->{'file'}));1697}1698# match single <mode>1699if($line=~m/\s(\d{6})$/) {1700$line.='<span class="info"> ('.1701 file_type_long($1) .1702')</span>';1703}1704# match <hash>1705if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1706# can match only for combined diff1707$line='index ';1708for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1709if($from->{'href'}[$i]) {1710$line.=$cgi->a({-href=>$from->{'href'}[$i],1711-class=>"hash"},1712substr($diffinfo->{'from_id'}[$i],0,7));1713}else{1714$line.='0' x 7;1715}1716# separator1717$line.=','if($i<$diffinfo->{'nparents'} -1);1718}1719$line.='..';1720if($to->{'href'}) {1721$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1722substr($diffinfo->{'to_id'},0,7));1723}else{1724$line.='0' x 7;1725}17261727}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1728# can match only for ordinary diff1729my($from_link,$to_link);1730if($from->{'href'}) {1731$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1732substr($diffinfo->{'from_id'},0,7));1733}else{1734$from_link='0' x 7;1735}1736if($to->{'href'}) {1737$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1738substr($diffinfo->{'to_id'},0,7));1739}else{1740$to_link='0' x 7;1741}1742my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1743$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1744}17451746return$line."<br/>\n";1747}17481749# format from-file/to-file diff header1750sub format_diff_from_to_header {1751my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1752my$line;1753my$result='';17541755$line=$from_line;1756#assert($line =~ m/^---/) if DEBUG;1757# no extra formatting for "^--- /dev/null"1758if(!$diffinfo->{'nparents'}) {1759# ordinary (single parent) diff1760if($line=~m!^--- "?a/!) {1761if($from->{'href'}) {1762$line='--- a/'.1763$cgi->a({-href=>$from->{'href'}, -class=>"path"},1764 esc_path($from->{'file'}));1765}else{1766$line='--- a/'.1767 esc_path($from->{'file'});1768}1769}1770$result.= qq!<div class="diff from_file">$line</div>\n!;17711772}else{1773# combined diff (merge commit)1774for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1775if($from->{'href'}[$i]) {1776$line='--- '.1777$cgi->a({-href=>href(action=>"blobdiff",1778 hash_parent=>$diffinfo->{'from_id'}[$i],1779 hash_parent_base=>$parents[$i],1780 file_parent=>$from->{'file'}[$i],1781 hash=>$diffinfo->{'to_id'},1782 hash_base=>$hash,1783 file_name=>$to->{'file'}),1784-class=>"path",1785-title=>"diff". ($i+1)},1786$i+1) .1787'/'.1788$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1789 esc_path($from->{'file'}[$i]));1790}else{1791$line='--- /dev/null';1792}1793$result.= qq!<div class="diff from_file">$line</div>\n!;1794}1795}17961797$line=$to_line;1798#assert($line =~ m/^\+\+\+/) if DEBUG;1799# no extra formatting for "^+++ /dev/null"1800if($line=~m!^\+\+\+ "?b/!) {1801if($to->{'href'}) {1802$line='+++ b/'.1803$cgi->a({-href=>$to->{'href'}, -class=>"path"},1804 esc_path($to->{'file'}));1805}else{1806$line='+++ b/'.1807 esc_path($to->{'file'});1808}1809}1810$result.= qq!<div class="diff to_file">$line</div>\n!;18111812return$result;1813}18141815# create note for patch simplified by combined diff1816sub format_diff_cc_simplified {1817my($diffinfo,@parents) =@_;1818my$result='';18191820$result.="<div class=\"diff header\">".1821"diff --cc ";1822if(!is_deleted($diffinfo)) {1823$result.=$cgi->a({-href => href(action=>"blob",1824 hash_base=>$hash,1825 hash=>$diffinfo->{'to_id'},1826 file_name=>$diffinfo->{'to_file'}),1827-class=>"path"},1828 esc_path($diffinfo->{'to_file'}));1829}else{1830$result.= esc_path($diffinfo->{'to_file'});1831}1832$result.="</div>\n".# class="diff header"1833"<div class=\"diff nodifferences\">".1834"Simple merge".1835"</div>\n";# class="diff nodifferences"18361837return$result;1838}18391840# format patch (diff) line (not to be used for diff headers)1841sub format_diff_line {1842my$line=shift;1843my($from,$to) =@_;1844my$diff_class="";18451846chomp$line;18471848if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1849# combined diff1850my$prefix=substr($line,0,scalar@{$from->{'href'}});1851if($line=~m/^\@{3}/) {1852$diff_class=" chunk_header";1853}elsif($line=~m/^\\/) {1854$diff_class=" incomplete";1855}elsif($prefix=~tr/+/+/) {1856$diff_class=" add";1857}elsif($prefix=~tr/-/-/) {1858$diff_class=" rem";1859}1860}else{1861# assume ordinary diff1862my$char=substr($line,0,1);1863if($chareq'+') {1864$diff_class=" add";1865}elsif($chareq'-') {1866$diff_class=" rem";1867}elsif($chareq'@') {1868$diff_class=" chunk_header";1869}elsif($chareq"\\") {1870$diff_class=" incomplete";1871}1872}1873$line= untabify($line);1874if($from&&$to&&$line=~m/^\@{2} /) {1875my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1876$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;18771878$from_lines=0unlessdefined$from_lines;1879$to_lines=0unlessdefined$to_lines;18801881if($from->{'href'}) {1882$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1883-class=>"list"},$from_text);1884}1885if($to->{'href'}) {1886$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1887-class=>"list"},$to_text);1888}1889$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1890"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1891return"<div class=\"diff$diff_class\">$line</div>\n";1892}elsif($from&&$to&&$line=~m/^\@{3}/) {1893my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1894my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);18951896@from_text=split(' ',$ranges);1897for(my$i=0;$i<@from_text; ++$i) {1898($from_start[$i],$from_nlines[$i]) =1899(split(',',substr($from_text[$i],1)),0);1900}19011902$to_text=pop@from_text;1903$to_start=pop@from_start;1904$to_nlines=pop@from_nlines;19051906$line="<span class=\"chunk_info\">$prefix";1907for(my$i=0;$i<@from_text; ++$i) {1908if($from->{'href'}[$i]) {1909$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1910-class=>"list"},$from_text[$i]);1911}else{1912$line.=$from_text[$i];1913}1914$line.=" ";1915}1916if($to->{'href'}) {1917$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1918-class=>"list"},$to_text);1919}else{1920$line.=$to_text;1921}1922$line.="$prefix</span>".1923"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1924return"<div class=\"diff$diff_class\">$line</div>\n";1925}1926return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1927}19281929# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1930# linked. Pass the hash of the tree/commit to snapshot.1931sub format_snapshot_links {1932my($hash) =@_;1933my$num_fmts=@snapshot_fmts;1934if($num_fmts>1) {1935# A parenthesized list of links bearing format names.1936# e.g. "snapshot (_tar.gz_ _zip_)"1937return"snapshot (".join(' ',map1938$cgi->a({1939-href => href(1940 action=>"snapshot",1941 hash=>$hash,1942 snapshot_format=>$_1943)1944},$known_snapshot_formats{$_}{'display'})1945,@snapshot_fmts) .")";1946}elsif($num_fmts==1) {1947# A single "snapshot" link whose tooltip bears the format name.1948# i.e. "_snapshot_"1949my($fmt) =@snapshot_fmts;1950return1951$cgi->a({1952-href => href(1953 action=>"snapshot",1954 hash=>$hash,1955 snapshot_format=>$fmt1956),1957-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"1958},"snapshot");1959}else{# $num_fmts == 01960returnundef;1961}1962}19631964## ......................................................................1965## functions returning values to be passed, perhaps after some1966## transformation, to other functions; e.g. returning arguments to href()19671968# returns hash to be passed to href to generate gitweb URL1969# in -title key it returns description of link1970sub get_feed_info {1971my$format=shift||'Atom';1972my%res= (action =>lc($format));19731974# feed links are possible only for project views1975return unless(defined$project);1976# some views should link to OPML, or to generic project feed,1977# or don't have specific feed yet (so they should use generic)1978return if($action=~/^(?:tags|heads|forks|tag|search)$/x);19791980my$branch;1981# branches refs uses 'refs/heads/' prefix (fullname) to differentiate1982# from tag links; this also makes possible to detect branch links1983if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||1984(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {1985$branch=$1;1986}1987# find log type for feed description (title)1988my$type='log';1989if(defined$file_name) {1990$type="history of$file_name";1991$type.="/"if($actioneq'tree');1992$type.=" on '$branch'"if(defined$branch);1993}else{1994$type="log of$branch"if(defined$branch);1995}19961997$res{-title} =$type;1998$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);1999$res{'file_name'} =$file_name;20002001return%res;2002}20032004## ----------------------------------------------------------------------2005## git utility subroutines, invoking git commands20062007# returns path to the core git executable and the --git-dir parameter as list2008sub git_cmd {2009return$GIT,'--git-dir='.$git_dir;2010}20112012# quote the given arguments for passing them to the shell2013# quote_command("command", "arg 1", "arg with ' and ! characters")2014# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2015# Try to avoid using this function wherever possible.2016sub quote_command {2017returnjoin(' ',2018map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2019}20202021# get HEAD ref of given project as hash2022sub git_get_head_hash {2023return git_get_full_hash(shift,'HEAD');2024}20252026sub git_get_full_hash {2027return git_get_hash(@_);2028}20292030sub git_get_short_hash {2031return git_get_hash(@_,'--short=7');2032}20332034sub git_get_hash {2035my($project,$hash,@options) =@_;2036my$o_git_dir=$git_dir;2037my$retval=undef;2038$git_dir="$projectroot/$project";2039if(open my$fd,'-|', git_cmd(),'rev-parse',2040'--verify','-q',@options,$hash) {2041$retval= <$fd>;2042chomp$retvalifdefined$retval;2043close$fd;2044}2045if(defined$o_git_dir) {2046$git_dir=$o_git_dir;2047}2048return$retval;2049}20502051# get type of given object2052sub git_get_type {2053my$hash=shift;20542055open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2056my$type= <$fd>;2057close$fdorreturn;2058chomp$type;2059return$type;2060}20612062# repository configuration2063our$config_file='';2064our%config;20652066# store multiple values for single key as anonymous array reference2067# single values stored directly in the hash, not as [ <value> ]2068sub hash_set_multi {2069my($hash,$key,$value) =@_;20702071if(!exists$hash->{$key}) {2072$hash->{$key} =$value;2073}elsif(!ref$hash->{$key}) {2074$hash->{$key} = [$hash->{$key},$value];2075}else{2076push@{$hash->{$key}},$value;2077}2078}20792080# return hash of git project configuration2081# optionally limited to some section, e.g. 'gitweb'2082sub git_parse_project_config {2083my$section_regexp=shift;2084my%config;20852086local$/="\0";20872088open my$fh,"-|", git_cmd(),"config",'-z','-l',2089orreturn;20902091while(my$keyval= <$fh>) {2092chomp$keyval;2093my($key,$value) =split(/\n/,$keyval,2);20942095 hash_set_multi(\%config,$key,$value)2096if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2097}2098close$fh;20992100return%config;2101}21022103# convert config value to boolean: 'true' or 'false'2104# no value, number > 0, 'true' and 'yes' values are true2105# rest of values are treated as false (never as error)2106sub config_to_bool {2107my$val=shift;21082109return1if!defined$val;# section.key21102111# strip leading and trailing whitespace2112$val=~s/^\s+//;2113$val=~s/\s+$//;21142115return(($val=~/^\d+$/&&$val) ||# section.key = 12116($val=~/^(?:true|yes)$/i));# section.key = true2117}21182119# convert config value to simple decimal number2120# an optional value suffix of 'k', 'm', or 'g' will cause the value2121# to be multiplied by 1024, 1048576, or 10737418242122sub config_to_int {2123my$val=shift;21242125# strip leading and trailing whitespace2126$val=~s/^\s+//;2127$val=~s/\s+$//;21282129if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2130$unit=lc($unit);2131# unknown unit is treated as 12132return$num* ($uniteq'g'?1073741824:2133$uniteq'm'?1048576:2134$uniteq'k'?1024:1);2135}2136return$val;2137}21382139# convert config value to array reference, if needed2140sub config_to_multi {2141my$val=shift;21422143returnref($val) ?$val: (defined($val) ? [$val] : []);2144}21452146sub git_get_project_config {2147my($key,$type) =@_;21482149# key sanity check2150return unless($key);2151$key=~s/^gitweb\.//;2152return if($key=~m/\W/);21532154# type sanity check2155if(defined$type) {2156$type=~s/^--//;2157$type=undef2158unless($typeeq'bool'||$typeeq'int');2159}21602161# get config2162if(!defined$config_file||2163$config_filene"$git_dir/config") {2164%config= git_parse_project_config('gitweb');2165$config_file="$git_dir/config";2166}21672168# check if config variable (key) exists2169return unlessexists$config{"gitweb.$key"};21702171# ensure given type2172if(!defined$type) {2173return$config{"gitweb.$key"};2174}elsif($typeeq'bool') {2175# backward compatibility: 'git config --bool' returns true/false2176return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2177}elsif($typeeq'int') {2178return config_to_int($config{"gitweb.$key"});2179}2180return$config{"gitweb.$key"};2181}21822183# get hash of given path at given ref2184sub git_get_hash_by_path {2185my$base=shift;2186my$path=shift||returnundef;2187my$type=shift;21882189$path=~ s,/+$,,;21902191open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2192or die_error(500,"Open git-ls-tree failed");2193my$line= <$fd>;2194close$fdorreturnundef;21952196if(!defined$line) {2197# there is no tree or hash given by $path at $base2198returnundef;2199}22002201#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2202$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2203if(defined$type&&$typene$2) {2204# type doesn't match2205returnundef;2206}2207return$3;2208}22092210# get path of entry with given hash at given tree-ish (ref)2211# used to get 'from' filename for combined diff (merge commit) for renames2212sub git_get_path_by_hash {2213my$base=shift||return;2214my$hash=shift||return;22152216local$/="\0";22172218open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2219orreturnundef;2220while(my$line= <$fd>) {2221chomp$line;22222223#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2224#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2225if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2226close$fd;2227return$1;2228}2229}2230close$fd;2231returnundef;2232}22332234## ......................................................................2235## git utility functions, directly accessing git repository22362237sub git_get_project_description {2238my$path=shift;22392240$git_dir="$projectroot/$path";2241open my$fd,'<',"$git_dir/description"2242orreturn git_get_project_config('description');2243my$descr= <$fd>;2244close$fd;2245if(defined$descr) {2246chomp$descr;2247}2248return$descr;2249}22502251sub git_get_project_ctags {2252my$path=shift;2253my$ctags= {};22542255$git_dir="$projectroot/$path";2256opendir my$dh,"$git_dir/ctags"2257orreturn$ctags;2258foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2259open my$ct,'<',$_ornext;2260my$val= <$ct>;2261chomp$val;2262close$ct;2263my$ctag=$_;$ctag=~ s#.*/##;2264$ctags->{$ctag} =$val;2265}2266closedir$dh;2267$ctags;2268}22692270sub git_populate_project_tagcloud {2271my$ctags=shift;22722273# First, merge different-cased tags; tags vote on casing2274my%ctags_lc;2275foreach(keys%$ctags) {2276$ctags_lc{lc$_}->{count} +=$ctags->{$_};2277if(not$ctags_lc{lc$_}->{topcount}2278or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2279$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2280$ctags_lc{lc$_}->{topname} =$_;2281}2282}22832284my$cloud;2285if(eval{require HTML::TagCloud;1; }) {2286$cloud= HTML::TagCloud->new;2287foreach(sort keys%ctags_lc) {2288# Pad the title with spaces so that the cloud looks2289# less crammed.2290my$title=$ctags_lc{$_}->{topname};2291$title=~s/ / /g;2292$title=~s/^/ /g;2293$title=~s/$/ /g;2294$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2295}2296}else{2297$cloud= \%ctags_lc;2298}2299$cloud;2300}23012302sub git_show_project_tagcloud {2303my($cloud,$count) =@_;2304print STDERR ref($cloud)."..\n";2305if(ref$cloudeq'HTML::TagCloud') {2306return$cloud->html_and_css($count);2307}else{2308my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2309return'<p align="center">'.join(', ',map{2310"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"2311}splice(@tags,0,$count)) .'</p>';2312}2313}23142315sub git_get_project_url_list {2316my$path=shift;23172318$git_dir="$projectroot/$path";2319open my$fd,'<',"$git_dir/cloneurl"2320orreturnwantarray?2321@{ config_to_multi(git_get_project_config('url')) } :2322 config_to_multi(git_get_project_config('url'));2323my@git_project_url_list=map{chomp;$_} <$fd>;2324close$fd;23252326returnwantarray?@git_project_url_list: \@git_project_url_list;2327}23282329sub git_get_projects_list {2330my($filter) =@_;2331my@list;23322333$filter||='';2334$filter=~s/\.git$//;23352336my$check_forks= gitweb_check_feature('forks');23372338if(-d $projects_list) {2339# search in directory2340my$dir=$projects_list. ($filter?"/$filter":'');2341# remove the trailing "/"2342$dir=~s!/+$!!;2343my$pfxlen=length("$dir");2344my$pfxdepth= ($dir=~tr!/!!);23452346 File::Find::find({2347 follow_fast =>1,# follow symbolic links2348 follow_skip =>2,# ignore duplicates2349 dangling_symlinks =>0,# ignore dangling symlinks, silently2350 wanted =>sub{2351# skip project-list toplevel, if we get it.2352return if(m!^[/.]$!);2353# only directories can be git repositories2354return unless(-d $_);2355# don't traverse too deep (Find is super slow on os x)2356if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2357$File::Find::prune =1;2358return;2359}23602361my$subdir=substr($File::Find::name,$pfxlen+1);2362# we check related file in $projectroot2363my$path= ($filter?"$filter/":'') .$subdir;2364if(check_export_ok("$projectroot/$path")) {2365push@list, { path =>$path};2366$File::Find::prune =1;2367}2368},2369},"$dir");23702371}elsif(-f $projects_list) {2372# read from file(url-encoded):2373# 'git%2Fgit.git Linus+Torvalds'2374# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2375# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2376my%paths;2377open my$fd,'<',$projects_listorreturn;2378 PROJECT:2379while(my$line= <$fd>) {2380chomp$line;2381my($path,$owner) =split' ',$line;2382$path= unescape($path);2383$owner= unescape($owner);2384if(!defined$path) {2385next;2386}2387if($filterne'') {2388# looking for forks;2389my$pfx=substr($path,0,length($filter));2390if($pfxne$filter) {2391next PROJECT;2392}2393my$sfx=substr($path,length($filter));2394if($sfx!~/^\/.*\.git$/) {2395next PROJECT;2396}2397}elsif($check_forks) {2398 PATH:2399foreachmy$filter(keys%paths) {2400# looking for forks;2401my$pfx=substr($path,0,length($filter));2402if($pfxne$filter) {2403next PATH;2404}2405my$sfx=substr($path,length($filter));2406if($sfx!~/^\/.*\.git$/) {2407next PATH;2408}2409# is a fork, don't include it in2410# the list2411next PROJECT;2412}2413}2414if(check_export_ok("$projectroot/$path")) {2415my$pr= {2416 path =>$path,2417 owner => to_utf8($owner),2418};2419push@list,$pr;2420(my$forks_path=$path) =~s/\.git$//;2421$paths{$forks_path}++;2422}2423}2424close$fd;2425}2426return@list;2427}24282429our$gitweb_project_owner=undef;2430sub git_get_project_list_from_file {24312432return if(defined$gitweb_project_owner);24332434$gitweb_project_owner= {};2435# read from file (url-encoded):2436# 'git%2Fgit.git Linus+Torvalds'2437# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2438# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2439if(-f $projects_list) {2440open(my$fd,'<',$projects_list);2441while(my$line= <$fd>) {2442chomp$line;2443my($pr,$ow) =split' ',$line;2444$pr= unescape($pr);2445$ow= unescape($ow);2446$gitweb_project_owner->{$pr} = to_utf8($ow);2447}2448close$fd;2449}2450}24512452sub git_get_project_owner {2453my$project=shift;2454my$owner;24552456returnundefunless$project;2457$git_dir="$projectroot/$project";24582459if(!defined$gitweb_project_owner) {2460 git_get_project_list_from_file();2461}24622463if(exists$gitweb_project_owner->{$project}) {2464$owner=$gitweb_project_owner->{$project};2465}2466if(!defined$owner){2467$owner= git_get_project_config('owner');2468}2469if(!defined$owner) {2470$owner= get_file_owner("$git_dir");2471}24722473return$owner;2474}24752476sub git_get_last_activity {2477my($path) =@_;2478my$fd;24792480$git_dir="$projectroot/$path";2481open($fd,"-|", git_cmd(),'for-each-ref',2482'--format=%(committer)',2483'--sort=-committerdate',2484'--count=1',2485'refs/heads')orreturn;2486my$most_recent= <$fd>;2487close$fdorreturn;2488if(defined$most_recent&&2489$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2490my$timestamp=$1;2491my$age=time-$timestamp;2492return($age, age_string($age));2493}2494return(undef,undef);2495}24962497sub git_get_references {2498my$type=shift||"";2499my%refs;2500# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112501# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2502open my$fd,"-|", git_cmd(),"show-ref","--dereference",2503($type? ("--","refs/$type") : ())# use -- <pattern> if $type2504orreturn;25052506while(my$line= <$fd>) {2507chomp$line;2508if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2509if(defined$refs{$1}) {2510push@{$refs{$1}},$2;2511}else{2512$refs{$1} = [$2];2513}2514}2515}2516close$fdorreturn;2517return \%refs;2518}25192520sub git_get_rev_name_tags {2521my$hash=shift||returnundef;25222523open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2524orreturn;2525my$name_rev= <$fd>;2526close$fd;25272528if($name_rev=~ m|^$hash tags/(.*)$|) {2529return$1;2530}else{2531# catches also '$hash undefined' output2532returnundef;2533}2534}25352536## ----------------------------------------------------------------------2537## parse to hash functions25382539sub parse_date {2540my$epoch=shift;2541my$tz=shift||"-0000";25422543my%date;2544my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2545my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2546my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2547$date{'hour'} =$hour;2548$date{'minute'} =$min;2549$date{'mday'} =$mday;2550$date{'day'} =$days[$wday];2551$date{'month'} =$months[$mon];2552$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2553$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2554$date{'mday-time'} =sprintf"%d%s%02d:%02d",2555$mday,$months[$mon],$hour,$min;2556$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",25571900+$year,1+$mon,$mday,$hour,$min,$sec;25582559$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2560my$local=$epoch+ ((int$1+ ($2/60)) *3600);2561($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2562$date{'hour_local'} =$hour;2563$date{'minute_local'} =$min;2564$date{'tz_local'} =$tz;2565$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",25661900+$year,$mon+1,$mday,2567$hour,$min,$sec,$tz);2568return%date;2569}25702571sub parse_tag {2572my$tag_id=shift;2573my%tag;2574my@comment;25752576open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2577$tag{'id'} =$tag_id;2578while(my$line= <$fd>) {2579chomp$line;2580if($line=~m/^object ([0-9a-fA-F]{40})$/) {2581$tag{'object'} =$1;2582}elsif($line=~m/^type (.+)$/) {2583$tag{'type'} =$1;2584}elsif($line=~m/^tag (.+)$/) {2585$tag{'name'} =$1;2586}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2587$tag{'author'} =$1;2588$tag{'author_epoch'} =$2;2589$tag{'author_tz'} =$3;2590if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {2591$tag{'author_name'} =$1;2592$tag{'author_email'} =$2;2593}else{2594$tag{'author_name'} =$tag{'author'};2595}2596}elsif($line=~m/--BEGIN/) {2597push@comment,$line;2598last;2599}elsif($lineeq"") {2600last;2601}2602}2603push@comment, <$fd>;2604$tag{'comment'} = \@comment;2605close$fdorreturn;2606if(!defined$tag{'name'}) {2607return2608};2609return%tag2610}26112612sub parse_commit_text {2613my($commit_text,$withparents) =@_;2614my@commit_lines=split'\n',$commit_text;2615my%co;26162617pop@commit_lines;# Remove '\0'26182619if(!@commit_lines) {2620return;2621}26222623my$header=shift@commit_lines;2624if($header!~m/^[0-9a-fA-F]{40}/) {2625return;2626}2627($co{'id'},my@parents) =split' ',$header;2628while(my$line=shift@commit_lines) {2629last if$lineeq"\n";2630if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2631$co{'tree'} =$1;2632}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2633push@parents,$1;2634}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2635$co{'author'} = to_utf8($1);2636$co{'author_epoch'} =$2;2637$co{'author_tz'} =$3;2638if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2639$co{'author_name'} =$1;2640$co{'author_email'} =$2;2641}else{2642$co{'author_name'} =$co{'author'};2643}2644}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2645$co{'committer'} = to_utf8($1);2646$co{'committer_epoch'} =$2;2647$co{'committer_tz'} =$3;2648if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2649$co{'committer_name'} =$1;2650$co{'committer_email'} =$2;2651}else{2652$co{'committer_name'} =$co{'committer'};2653}2654}2655}2656if(!defined$co{'tree'}) {2657return;2658};2659$co{'parents'} = \@parents;2660$co{'parent'} =$parents[0];26612662foreachmy$title(@commit_lines) {2663$title=~s/^ //;2664if($titlene"") {2665$co{'title'} = chop_str($title,80,5);2666# remove leading stuff of merges to make the interesting part visible2667if(length($title) >50) {2668$title=~s/^Automatic //;2669$title=~s/^merge (of|with) /Merge ... /i;2670if(length($title) >50) {2671$title=~s/(http|rsync):\/\///;2672}2673if(length($title) >50) {2674$title=~s/(master|www|rsync)\.//;2675}2676if(length($title) >50) {2677$title=~s/kernel.org:?//;2678}2679if(length($title) >50) {2680$title=~s/\/pub\/scm//;2681}2682}2683$co{'title_short'} = chop_str($title,50,5);2684last;2685}2686}2687if(!defined$co{'title'} ||$co{'title'}eq"") {2688$co{'title'} =$co{'title_short'} ='(no commit message)';2689}2690# remove added spaces2691foreachmy$line(@commit_lines) {2692$line=~s/^ //;2693}2694$co{'comment'} = \@commit_lines;26952696my$age=time-$co{'committer_epoch'};2697$co{'age'} =$age;2698$co{'age_string'} = age_string($age);2699my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2700if($age>60*60*24*7*2) {2701$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2702$co{'age_string_age'} =$co{'age_string'};2703}else{2704$co{'age_string_date'} =$co{'age_string'};2705$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2706}2707return%co;2708}27092710sub parse_commit {2711my($commit_id) =@_;2712my%co;27132714local$/="\0";27152716open my$fd,"-|", git_cmd(),"rev-list",2717"--parents",2718"--header",2719"--max-count=1",2720$commit_id,2721"--",2722or die_error(500,"Open git-rev-list failed");2723%co= parse_commit_text(<$fd>,1);2724close$fd;27252726return%co;2727}27282729sub parse_commits {2730my($commit_id,$maxcount,$skip,$filename,@args) =@_;2731my@cos;27322733$maxcount||=1;2734$skip||=0;27352736local$/="\0";27372738open my$fd,"-|", git_cmd(),"rev-list",2739"--header",2740@args,2741("--max-count=".$maxcount),2742("--skip=".$skip),2743@extra_options,2744$commit_id,2745"--",2746($filename? ($filename) : ())2747or die_error(500,"Open git-rev-list failed");2748while(my$line= <$fd>) {2749my%co= parse_commit_text($line);2750push@cos, \%co;2751}2752close$fd;27532754returnwantarray?@cos: \@cos;2755}27562757# parse line of git-diff-tree "raw" output2758sub parse_difftree_raw_line {2759my$line=shift;2760my%res;27612762# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2763# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2764if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2765$res{'from_mode'} =$1;2766$res{'to_mode'} =$2;2767$res{'from_id'} =$3;2768$res{'to_id'} =$4;2769$res{'status'} =$5;2770$res{'similarity'} =$6;2771if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2772($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2773}else{2774$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2775}2776}2777# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2778# combined diff (for merge commit)2779elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2780$res{'nparents'} =length($1);2781$res{'from_mode'} = [split(' ',$2) ];2782$res{'to_mode'} =pop@{$res{'from_mode'}};2783$res{'from_id'} = [split(' ',$3) ];2784$res{'to_id'} =pop@{$res{'from_id'}};2785$res{'status'} = [split('',$4) ];2786$res{'to_file'} = unquote($5);2787}2788# 'c512b523472485aef4fff9e57b229d9d243c967f'2789elsif($line=~m/^([0-9a-fA-F]{40})$/) {2790$res{'commit'} =$1;2791}27922793returnwantarray?%res: \%res;2794}27952796# wrapper: return parsed line of git-diff-tree "raw" output2797# (the argument might be raw line, or parsed info)2798sub parsed_difftree_line {2799my$line_or_ref=shift;28002801if(ref($line_or_ref)eq"HASH") {2802# pre-parsed (or generated by hand)2803return$line_or_ref;2804}else{2805return parse_difftree_raw_line($line_or_ref);2806}2807}28082809# parse line of git-ls-tree output2810sub parse_ls_tree_line {2811my$line=shift;2812my%opts=@_;2813my%res;28142815if($opts{'-l'}) {2816#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'2817$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;28182819$res{'mode'} =$1;2820$res{'type'} =$2;2821$res{'hash'} =$3;2822$res{'size'} =$4;2823if($opts{'-z'}) {2824$res{'name'} =$5;2825}else{2826$res{'name'} = unquote($5);2827}2828}else{2829#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2830$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;28312832$res{'mode'} =$1;2833$res{'type'} =$2;2834$res{'hash'} =$3;2835if($opts{'-z'}) {2836$res{'name'} =$4;2837}else{2838$res{'name'} = unquote($4);2839}2840}28412842returnwantarray?%res: \%res;2843}28442845# generates _two_ hashes, references to which are passed as 2 and 3 argument2846sub parse_from_to_diffinfo {2847my($diffinfo,$from,$to,@parents) =@_;28482849if($diffinfo->{'nparents'}) {2850# combined diff2851$from->{'file'} = [];2852$from->{'href'} = [];2853 fill_from_file_info($diffinfo,@parents)2854unlessexists$diffinfo->{'from_file'};2855for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2856$from->{'file'}[$i] =2857defined$diffinfo->{'from_file'}[$i] ?2858$diffinfo->{'from_file'}[$i] :2859$diffinfo->{'to_file'};2860if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2861$from->{'href'}[$i] = href(action=>"blob",2862 hash_base=>$parents[$i],2863 hash=>$diffinfo->{'from_id'}[$i],2864 file_name=>$from->{'file'}[$i]);2865}else{2866$from->{'href'}[$i] =undef;2867}2868}2869}else{2870# ordinary (not combined) diff2871$from->{'file'} =$diffinfo->{'from_file'};2872if($diffinfo->{'status'}ne"A") {# not new (added) file2873$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2874 hash=>$diffinfo->{'from_id'},2875 file_name=>$from->{'file'});2876}else{2877delete$from->{'href'};2878}2879}28802881$to->{'file'} =$diffinfo->{'to_file'};2882if(!is_deleted($diffinfo)) {# file exists in result2883$to->{'href'} = href(action=>"blob", hash_base=>$hash,2884 hash=>$diffinfo->{'to_id'},2885 file_name=>$to->{'file'});2886}else{2887delete$to->{'href'};2888}2889}28902891## ......................................................................2892## parse to array of hashes functions28932894sub git_get_heads_list {2895my$limit=shift;2896my@headslist;28972898open my$fd,'-|', git_cmd(),'for-each-ref',2899($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2900'--format=%(objectname) %(refname) %(subject)%00%(committer)',2901'refs/heads'2902orreturn;2903while(my$line= <$fd>) {2904my%ref_item;29052906chomp$line;2907my($refinfo,$committerinfo) =split(/\0/,$line);2908my($hash,$name,$title) =split(' ',$refinfo,3);2909my($committer,$epoch,$tz) =2910($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2911$ref_item{'fullname'} =$name;2912$name=~s!^refs/heads/!!;29132914$ref_item{'name'} =$name;2915$ref_item{'id'} =$hash;2916$ref_item{'title'} =$title||'(no commit message)';2917$ref_item{'epoch'} =$epoch;2918if($epoch) {2919$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2920}else{2921$ref_item{'age'} ="unknown";2922}29232924push@headslist, \%ref_item;2925}2926close$fd;29272928returnwantarray?@headslist: \@headslist;2929}29302931sub git_get_tags_list {2932my$limit=shift;2933my@tagslist;29342935open my$fd,'-|', git_cmd(),'for-each-ref',2936($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',2937'--format=%(objectname) %(objecttype) %(refname) '.2938'%(*objectname) %(*objecttype) %(subject)%00%(creator)',2939'refs/tags'2940orreturn;2941while(my$line= <$fd>) {2942my%ref_item;29432944chomp$line;2945my($refinfo,$creatorinfo) =split(/\0/,$line);2946my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);2947my($creator,$epoch,$tz) =2948($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);2949$ref_item{'fullname'} =$name;2950$name=~s!^refs/tags/!!;29512952$ref_item{'type'} =$type;2953$ref_item{'id'} =$id;2954$ref_item{'name'} =$name;2955if($typeeq"tag") {2956$ref_item{'subject'} =$title;2957$ref_item{'reftype'} =$reftype;2958$ref_item{'refid'} =$refid;2959}else{2960$ref_item{'reftype'} =$type;2961$ref_item{'refid'} =$id;2962}29632964if($typeeq"tag"||$typeeq"commit") {2965$ref_item{'epoch'} =$epoch;2966if($epoch) {2967$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2968}else{2969$ref_item{'age'} ="unknown";2970}2971}29722973push@tagslist, \%ref_item;2974}2975close$fd;29762977returnwantarray?@tagslist: \@tagslist;2978}29792980## ----------------------------------------------------------------------2981## filesystem-related functions29822983sub get_file_owner {2984my$path=shift;29852986my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);2987my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);2988if(!defined$gcos) {2989returnundef;2990}2991my$owner=$gcos;2992$owner=~s/[,;].*$//;2993return to_utf8($owner);2994}29952996# assume that file exists2997sub insert_file {2998my$filename=shift;29993000open my$fd,'<',$filename;3001print map{ to_utf8($_) } <$fd>;3002close$fd;3003}30043005## ......................................................................3006## mimetype related functions30073008sub mimetype_guess_file {3009my$filename=shift;3010my$mimemap=shift;3011-r $mimemaporreturnundef;30123013my%mimemap;3014open(my$mh,'<',$mimemap)orreturnundef;3015while(<$mh>) {3016next ifm/^#/;# skip comments3017my($mimetype,$exts) =split(/\t+/);3018if(defined$exts) {3019my@exts=split(/\s+/,$exts);3020foreachmy$ext(@exts) {3021$mimemap{$ext} =$mimetype;3022}3023}3024}3025close($mh);30263027$filename=~/\.([^.]*)$/;3028return$mimemap{$1};3029}30303031sub mimetype_guess {3032my$filename=shift;3033my$mime;3034$filename=~/\./orreturnundef;30353036if($mimetypes_file) {3037my$file=$mimetypes_file;3038if($file!~m!^/!) {# if it is relative path3039# it is relative to project3040$file="$projectroot/$project/$file";3041}3042$mime= mimetype_guess_file($filename,$file);3043}3044$mime||= mimetype_guess_file($filename,'/etc/mime.types');3045return$mime;3046}30473048sub blob_mimetype {3049my$fd=shift;3050my$filename=shift;30513052if($filename) {3053my$mime= mimetype_guess($filename);3054$mimeandreturn$mime;3055}30563057# just in case3058return$default_blob_plain_mimetypeunless$fd;30593060if(-T $fd) {3061return'text/plain';3062}elsif(!$filename) {3063return'application/octet-stream';3064}elsif($filename=~m/\.png$/i) {3065return'image/png';3066}elsif($filename=~m/\.gif$/i) {3067return'image/gif';3068}elsif($filename=~m/\.jpe?g$/i) {3069return'image/jpeg';3070}else{3071return'application/octet-stream';3072}3073}30743075sub blob_contenttype {3076my($fd,$file_name,$type) =@_;30773078$type||= blob_mimetype($fd,$file_name);3079if($typeeq'text/plain'&&defined$default_text_plain_charset) {3080$type.="; charset=$default_text_plain_charset";3081}30823083return$type;3084}30853086## ======================================================================3087## functions printing HTML: header, footer, error page30883089sub git_header_html {3090my$status=shift||"200 OK";3091my$expires=shift;30923093my$title="$site_name";3094if(defined$project) {3095$title.=" - ". to_utf8($project);3096if(defined$action) {3097$title.="/$action";3098if(defined$file_name) {3099$title.=" - ". esc_path($file_name);3100if($actioneq"tree"&&$file_name!~ m|/$|) {3101$title.="/";3102}3103}3104}3105}3106my$content_type;3107# require explicit support from the UA if we are to send the page as3108# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3109# we have to do this because MSIE sometimes globs '*/*', pretending to3110# support xhtml+xml but choking when it gets what it asked for.3111if(defined$cgi->http('HTTP_ACCEPT') &&3112$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3113$cgi->Accept('application/xhtml+xml') !=0) {3114$content_type='application/xhtml+xml';3115}else{3116$content_type='text/html';3117}3118print$cgi->header(-type=>$content_type, -charset =>'utf-8',3119-status=>$status, -expires =>$expires);3120my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';3121print<<EOF;3122<?xml version="1.0" encoding="utf-8"?>3123<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">3124<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">3125<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->3126<!-- git core binaries version$git_version-->3127<head>3128<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>3129<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>3130<meta name="robots" content="index, nofollow"/>3131<title>$title</title>3132EOF3133# the stylesheet, favicon etc urls won't work correctly with path_info3134# unless we set the appropriate base URL3135if($ENV{'PATH_INFO'}) {3136print"<base href=\"".esc_url($base_url)."\"/>\n";3137}3138# print out each stylesheet that exist, providing backwards capability3139# for those people who defined $stylesheet in a config file3140if(defined$stylesheet) {3141print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3142}else{3143foreachmy$stylesheet(@stylesheets) {3144next unless$stylesheet;3145print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3146}3147}3148if(defined$project) {3149my%href_params= get_feed_info();3150if(!exists$href_params{'-title'}) {3151$href_params{'-title'} ='log';3152}31533154foreachmy$formatqw(RSS Atom){3155my$type=lc($format);3156my%link_attr= (3157'-rel'=>'alternate',3158'-title'=>"$project-$href_params{'-title'} -$formatfeed",3159'-type'=>"application/$type+xml"3160);31613162$href_params{'action'} =$type;3163$link_attr{'-href'} = href(%href_params);3164print"<link ".3165"rel=\"$link_attr{'-rel'}\"".3166"title=\"$link_attr{'-title'}\"".3167"href=\"$link_attr{'-href'}\"".3168"type=\"$link_attr{'-type'}\"".3169"/>\n";31703171$href_params{'extra_options'} ='--no-merges';3172$link_attr{'-href'} = href(%href_params);3173$link_attr{'-title'} .=' (no merges)';3174print"<link ".3175"rel=\"$link_attr{'-rel'}\"".3176"title=\"$link_attr{'-title'}\"".3177"href=\"$link_attr{'-href'}\"".3178"type=\"$link_attr{'-type'}\"".3179"/>\n";3180}31813182}else{3183printf('<link rel="alternate" title="%sprojects list" '.3184'href="%s" type="text/plain; charset=utf-8" />'."\n",3185$site_name, href(project=>undef, action=>"project_index"));3186printf('<link rel="alternate" title="%sprojects feeds" '.3187'href="%s" type="text/x-opml" />'."\n",3188$site_name, href(project=>undef, action=>"opml"));3189}3190if(defined$favicon) {3191printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);3192}31933194print"</head>\n".3195"<body>\n";31963197if(-f $site_header) {3198 insert_file($site_header);3199}32003201print"<div class=\"page_header\">\n".3202$cgi->a({-href => esc_url($logo_url),3203-title =>$logo_label},3204qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));3205print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3206if(defined$project) {3207print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3208if(defined$action) {3209print" /$action";3210}3211print"\n";3212}3213print"</div>\n";32143215my$have_search= gitweb_check_feature('search');3216if(defined$project&&$have_search) {3217if(!defined$searchtext) {3218$searchtext="";3219}3220my$search_hash;3221if(defined$hash_base) {3222$search_hash=$hash_base;3223}elsif(defined$hash) {3224$search_hash=$hash;3225}else{3226$search_hash="HEAD";3227}3228my$action=$my_uri;3229my$use_pathinfo= gitweb_check_feature('pathinfo');3230if($use_pathinfo) {3231$action.="/".esc_url($project);3232}3233print$cgi->startform(-method=>"get", -action =>$action) .3234"<div class=\"search\">\n".3235(!$use_pathinfo&&3236$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3237$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3238$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3239$cgi->popup_menu(-name =>'st', -default=>'commit',3240-values=> ['commit','grep','author','committer','pickaxe']) .3241$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3242" search:\n",3243$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3244"<span title=\"Extended regular expression\">".3245$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3246-checked =>$search_use_regexp) .3247"</span>".3248"</div>".3249$cgi->end_form() ."\n";3250}3251}32523253sub git_footer_html {3254my$feed_class='rss_logo';32553256print"<div class=\"page_footer\">\n";3257if(defined$project) {3258my$descr= git_get_project_description($project);3259if(defined$descr) {3260print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3261}32623263my%href_params= get_feed_info();3264if(!%href_params) {3265$feed_class.=' generic';3266}3267$href_params{'-title'} ||='log';32683269foreachmy$formatqw(RSS Atom){3270$href_params{'action'} =lc($format);3271print$cgi->a({-href => href(%href_params),3272-title =>"$href_params{'-title'}$formatfeed",3273-class=>$feed_class},$format)."\n";3274}32753276}else{3277print$cgi->a({-href => href(project=>undef, action=>"opml"),3278-class=>$feed_class},"OPML") ." ";3279print$cgi->a({-href => href(project=>undef, action=>"project_index"),3280-class=>$feed_class},"TXT") ."\n";3281}3282print"</div>\n";# class="page_footer"32833284if(-f $site_footer) {3285 insert_file($site_footer);3286}32873288print"</body>\n".3289"</html>";3290}32913292# die_error(<http_status_code>, <error_message>)3293# Example: die_error(404, 'Hash not found')3294# By convention, use the following status codes (as defined in RFC 2616):3295# 400: Invalid or missing CGI parameters, or3296# requested object exists but has wrong type.3297# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3298# this server or project.3299# 404: Requested object/revision/project doesn't exist.3300# 500: The server isn't configured properly, or3301# an internal error occurred (e.g. failed assertions caused by bugs), or3302# an unknown error occurred (e.g. the git binary died unexpectedly).3303sub die_error {3304my$status=shift||500;3305my$error=shift||"Internal server error";33063307my%http_responses= (400=>'400 Bad Request',3308403=>'403 Forbidden',3309404=>'404 Not Found',3310500=>'500 Internal Server Error');3311 git_header_html($http_responses{$status});3312print<<EOF;3313<div class="page_body">3314<br /><br />3315$status-$error3316<br />3317</div>3318EOF3319 git_footer_html();3320exit;3321}33223323## ----------------------------------------------------------------------3324## functions printing or outputting HTML: navigation33253326sub git_print_page_nav {3327my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3328$extra=''if!defined$extra;# pager or formats33293330my@navs=qw(summary shortlog log commit commitdiff tree);3331if($suppress) {3332@navs=grep{$_ne$suppress}@navs;3333}33343335my%arg=map{$_=> {action=>$_} }@navs;3336if(defined$head) {3337for(qw(commit commitdiff)) {3338$arg{$_}{'hash'} =$head;3339}3340if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3341for(qw(shortlog log)) {3342$arg{$_}{'hash'} =$head;3343}3344}3345}33463347$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3348$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;33493350my@actions= gitweb_get_feature('actions');3351my%repl= (3352'%'=>'%',3353'n'=>$project,# project name3354'f'=>$git_dir,# project path within filesystem3355'h'=>$treehead||'',# current hash ('h' parameter)3356'b'=>$treebase||'',# hash base ('hb' parameter)3357);3358while(@actions) {3359my($label,$link,$pos) =splice(@actions,0,3);3360# insert3361@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3362# munch munch3363$link=~s/%([%nfhb])/$repl{$1}/g;3364$arg{$label}{'_href'} =$link;3365}33663367print"<div class=\"page_nav\">\n".3368(join" | ",3369map{$_eq$current?3370$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3371}@navs);3372print"<br/>\n$extra<br/>\n".3373"</div>\n";3374}33753376sub format_paging_nav {3377my($action,$page,$has_next_link) =@_;3378my$paging_nav;337933803381if($page>0) {3382$paging_nav.=3383$cgi->a({-href => href(-replay=>1, page=>undef)},"first") .3384" ⋅ ".3385$cgi->a({-href => href(-replay=>1, page=>$page-1),3386-accesskey =>"p", -title =>"Alt-p"},"prev");3387}else{3388$paging_nav.="first ⋅ prev";3389}33903391if($has_next_link) {3392$paging_nav.=" ⋅ ".3393$cgi->a({-href => href(-replay=>1, page=>$page+1),3394-accesskey =>"n", -title =>"Alt-n"},"next");3395}else{3396$paging_nav.=" ⋅ next";3397}33983399return$paging_nav;3400}34013402## ......................................................................3403## functions printing or outputting HTML: div34043405sub git_print_header_div {3406my($action,$title,$hash,$hash_base) =@_;3407my%args= ();34083409$args{'action'} =$action;3410$args{'hash'} =$hashif$hash;3411$args{'hash_base'} =$hash_baseif$hash_base;34123413print"<div class=\"header\">\n".3414$cgi->a({-href => href(%args), -class=>"title"},3415$title?$title:$action) .3416"\n</div>\n";3417}34183419sub print_local_time {3420my%date=@_;3421if($date{'hour_local'} <6) {3422printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3423$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3424}else{3425printf(" (%02d:%02d%s)",3426$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3427}3428}34293430# Outputs the author name and date in long form3431sub git_print_authorship {3432my$co=shift;3433my%opts=@_;3434my$tag=$opts{-tag} ||'div';3435my$author=$co->{'author_name'};34363437my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3438print"<$tagclass=\"author_date\">".3439 format_search_author($author,"author", esc_html($author)) .3440" [$ad{'rfc2822'}";3441 print_local_time(%ad)if($opts{-localtime});3442print"]". git_get_avatar($co->{'author_email'}, -pad_before =>1)3443."</$tag>\n";3444}34453446# Outputs table rows containing the full author or committer information,3447# in the format expected for 'commit' view (& similia).3448# Parameters are a commit hash reference, followed by the list of people3449# to output information for. If the list is empty it defalts to both3450# author and committer.3451sub git_print_authorship_rows {3452my$co=shift;3453# too bad we can't use @people = @_ || ('author', 'committer')3454my@people=@_;3455@people= ('author','committer')unless@people;3456foreachmy$who(@people) {3457my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});3458print"<tr><td>$who</td><td>".3459 format_search_author($co->{"${who}_name"},$who,3460 esc_html($co->{"${who}_name"})) ." ".3461 format_search_author($co->{"${who}_email"},$who,3462 esc_html("<".$co->{"${who}_email"} .">")) .3463"</td><td rowspan=\"2\">".3464 git_get_avatar($co->{"${who}_email"}, -size =>'double') .3465"</td></tr>\n".3466"<tr>".3467"<td></td><td>$wd{'rfc2822'}";3468 print_local_time(%wd);3469print"</td>".3470"</tr>\n";3471}3472}34733474sub git_print_page_path {3475my$name=shift;3476my$type=shift;3477my$hb=shift;347834793480print"<div class=\"page_path\">";3481print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3482-title =>'tree root'}, to_utf8("[$project]"));3483print" / ";3484if(defined$name) {3485my@dirname=split'/',$name;3486my$basename=pop@dirname;3487my$fullname='';34883489foreachmy$dir(@dirname) {3490$fullname.= ($fullname?'/':'') .$dir;3491print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3492 hash_base=>$hb),3493-title =>$fullname}, esc_path($dir));3494print" / ";3495}3496if(defined$type&&$typeeq'blob') {3497print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3498 hash_base=>$hb),3499-title =>$name}, esc_path($basename));3500}elsif(defined$type&&$typeeq'tree') {3501print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3502 hash_base=>$hb),3503-title =>$name}, esc_path($basename));3504print" / ";3505}else{3506print esc_path($basename);3507}3508}3509print"<br/></div>\n";3510}35113512sub git_print_log {3513my$log=shift;3514my%opts=@_;35153516if($opts{'-remove_title'}) {3517# remove title, i.e. first line of log3518shift@$log;3519}3520# remove leading empty lines3521while(defined$log->[0] &&$log->[0]eq"") {3522shift@$log;3523}35243525# print log3526my$signoff=0;3527my$empty=0;3528foreachmy$line(@$log) {3529if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3530$signoff=1;3531$empty=0;3532if(!$opts{'-remove_signoff'}) {3533print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3534next;3535}else{3536# remove signoff lines3537next;3538}3539}else{3540$signoff=0;3541}35423543# print only one empty line3544# do not print empty line after signoff3545if($lineeq"") {3546next if($empty||$signoff);3547$empty=1;3548}else{3549$empty=0;3550}35513552print format_log_line_html($line) ."<br/>\n";3553}35543555if($opts{'-final_empty_line'}) {3556# end with single empty line3557print"<br/>\n"unless$empty;3558}3559}35603561# return link target (what link points to)3562sub git_get_link_target {3563my$hash=shift;3564my$link_target;35653566# read link3567open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3568orreturn;3569{3570local$/=undef;3571$link_target= <$fd>;3572}3573close$fd3574orreturn;35753576return$link_target;3577}35783579# given link target, and the directory (basedir) the link is in,3580# return target of link relative to top directory (top tree);3581# return undef if it is not possible (including absolute links).3582sub normalize_link_target {3583my($link_target,$basedir) =@_;35843585# absolute symlinks (beginning with '/') cannot be normalized3586return if(substr($link_target,0,1)eq'/');35873588# normalize link target to path from top (root) tree (dir)3589my$path;3590if($basedir) {3591$path=$basedir.'/'.$link_target;3592}else{3593# we are in top (root) tree (dir)3594$path=$link_target;3595}35963597# remove //, /./, and /../3598my@path_parts;3599foreachmy$part(split('/',$path)) {3600# discard '.' and ''3601next if(!$part||$parteq'.');3602# handle '..'3603if($parteq'..') {3604if(@path_parts) {3605pop@path_parts;3606}else{3607# link leads outside repository (outside top dir)3608return;3609}3610}else{3611push@path_parts,$part;3612}3613}3614$path=join('/',@path_parts);36153616return$path;3617}36183619# print tree entry (row of git_tree), but without encompassing <tr> element3620sub git_print_tree_entry {3621my($t,$basedir,$hash_base,$have_blame) =@_;36223623my%base_key= ();3624$base_key{'hash_base'} =$hash_baseifdefined$hash_base;36253626# The format of a table row is: mode list link. Where mode is3627# the mode of the entry, list is the name of the entry, an href,3628# and link is the action links of the entry.36293630print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3631if(exists$t->{'size'}) {3632print"<td class=\"size\">$t->{'size'}</td>\n";3633}3634if($t->{'type'}eq"blob") {3635print"<td class=\"list\">".3636$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3637 file_name=>"$basedir$t->{'name'}",%base_key),3638-class=>"list"}, esc_path($t->{'name'}));3639if(S_ISLNK(oct$t->{'mode'})) {3640my$link_target= git_get_link_target($t->{'hash'});3641if($link_target) {3642my$norm_target= normalize_link_target($link_target,$basedir);3643if(defined$norm_target) {3644print" -> ".3645$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3646 file_name=>$norm_target),3647-title =>$norm_target}, esc_path($link_target));3648}else{3649print" -> ". esc_path($link_target);3650}3651}3652}3653print"</td>\n";3654print"<td class=\"link\">";3655print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3656 file_name=>"$basedir$t->{'name'}",%base_key)},3657"blob");3658if($have_blame) {3659print" | ".3660$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3661 file_name=>"$basedir$t->{'name'}",%base_key)},3662"blame");3663}3664if(defined$hash_base) {3665print" | ".3666$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3667 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3668"history");3669}3670print" | ".3671$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3672 file_name=>"$basedir$t->{'name'}")},3673"raw");3674print"</td>\n";36753676}elsif($t->{'type'}eq"tree") {3677print"<td class=\"list\">";3678print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3679 file_name=>"$basedir$t->{'name'}",3680%base_key)},3681 esc_path($t->{'name'}));3682print"</td>\n";3683print"<td class=\"link\">";3684print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3685 file_name=>"$basedir$t->{'name'}",3686%base_key)},3687"tree");3688if(defined$hash_base) {3689print" | ".3690$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3691 file_name=>"$basedir$t->{'name'}")},3692"history");3693}3694print"</td>\n";3695}else{3696# unknown object: we can only present history for it3697# (this includes 'commit' object, i.e. submodule support)3698print"<td class=\"list\">".3699 esc_path($t->{'name'}) .3700"</td>\n";3701print"<td class=\"link\">";3702if(defined$hash_base) {3703print$cgi->a({-href => href(action=>"history",3704 hash_base=>$hash_base,3705 file_name=>"$basedir$t->{'name'}")},3706"history");3707}3708print"</td>\n";3709}3710}37113712## ......................................................................3713## functions printing large fragments of HTML37143715# get pre-image filenames for merge (combined) diff3716sub fill_from_file_info {3717my($diff,@parents) =@_;37183719$diff->{'from_file'} = [ ];3720$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3721for(my$i=0;$i<$diff->{'nparents'};$i++) {3722if($diff->{'status'}[$i]eq'R'||3723$diff->{'status'}[$i]eq'C') {3724$diff->{'from_file'}[$i] =3725 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3726}3727}37283729return$diff;3730}37313732# is current raw difftree line of file deletion3733sub is_deleted {3734my$diffinfo=shift;37353736return$diffinfo->{'to_id'}eq('0' x 40);3737}37383739# does patch correspond to [previous] difftree raw line3740# $diffinfo - hashref of parsed raw diff format3741# $patchinfo - hashref of parsed patch diff format3742# (the same keys as in $diffinfo)3743sub is_patch_split {3744my($diffinfo,$patchinfo) =@_;37453746returndefined$diffinfo&&defined$patchinfo3747&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3748}374937503751sub git_difftree_body {3752my($difftree,$hash,@parents) =@_;3753my($parent) =$parents[0];3754my$have_blame= gitweb_check_feature('blame');3755print"<div class=\"list_head\">\n";3756if($#{$difftree} >10) {3757print(($#{$difftree} +1) ." files changed:\n");3758}3759print"</div>\n";37603761print"<table class=\"".3762(@parents>1?"combined ":"") .3763"diff_tree\">\n";37643765# header only for combined diff in 'commitdiff' view3766my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3767if($has_header) {3768# table header3769print"<thead><tr>\n".3770"<th></th><th></th>\n";# filename, patchN link3771for(my$i=0;$i<@parents;$i++) {3772my$par=$parents[$i];3773print"<th>".3774$cgi->a({-href => href(action=>"commitdiff",3775 hash=>$hash, hash_parent=>$par),3776-title =>'commitdiff to parent number '.3777($i+1) .': '.substr($par,0,7)},3778$i+1) .3779" </th>\n";3780}3781print"</tr></thead>\n<tbody>\n";3782}37833784my$alternate=1;3785my$patchno=0;3786foreachmy$line(@{$difftree}) {3787my$diff= parsed_difftree_line($line);37883789if($alternate) {3790print"<tr class=\"dark\">\n";3791}else{3792print"<tr class=\"light\">\n";3793}3794$alternate^=1;37953796if(exists$diff->{'nparents'}) {# combined diff37973798 fill_from_file_info($diff,@parents)3799unlessexists$diff->{'from_file'};38003801if(!is_deleted($diff)) {3802# file exists in the result (child) commit3803print"<td>".3804$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3805 file_name=>$diff->{'to_file'},3806 hash_base=>$hash),3807-class=>"list"}, esc_path($diff->{'to_file'})) .3808"</td>\n";3809}else{3810print"<td>".3811 esc_path($diff->{'to_file'}) .3812"</td>\n";3813}38143815if($actioneq'commitdiff') {3816# link to patch3817$patchno++;3818print"<td class=\"link\">".3819$cgi->a({-href =>"#patch$patchno"},"patch") .3820" | ".3821"</td>\n";3822}38233824my$has_history=0;3825my$not_deleted=0;3826for(my$i=0;$i<$diff->{'nparents'};$i++) {3827my$hash_parent=$parents[$i];3828my$from_hash=$diff->{'from_id'}[$i];3829my$from_path=$diff->{'from_file'}[$i];3830my$status=$diff->{'status'}[$i];38313832$has_history||= ($statusne'A');3833$not_deleted||= ($statusne'D');38343835if($statuseq'A') {3836print"<td class=\"link\"align=\"right\"> | </td>\n";3837}elsif($statuseq'D') {3838print"<td class=\"link\">".3839$cgi->a({-href => href(action=>"blob",3840 hash_base=>$hash,3841 hash=>$from_hash,3842 file_name=>$from_path)},3843"blob". ($i+1)) .3844" | </td>\n";3845}else{3846if($diff->{'to_id'}eq$from_hash) {3847print"<td class=\"link nochange\">";3848}else{3849print"<td class=\"link\">";3850}3851print$cgi->a({-href => href(action=>"blobdiff",3852 hash=>$diff->{'to_id'},3853 hash_parent=>$from_hash,3854 hash_base=>$hash,3855 hash_parent_base=>$hash_parent,3856 file_name=>$diff->{'to_file'},3857 file_parent=>$from_path)},3858"diff". ($i+1)) .3859" | </td>\n";3860}3861}38623863print"<td class=\"link\">";3864if($not_deleted) {3865print$cgi->a({-href => href(action=>"blob",3866 hash=>$diff->{'to_id'},3867 file_name=>$diff->{'to_file'},3868 hash_base=>$hash)},3869"blob");3870print" | "if($has_history);3871}3872if($has_history) {3873print$cgi->a({-href => href(action=>"history",3874 file_name=>$diff->{'to_file'},3875 hash_base=>$hash)},3876"history");3877}3878print"</td>\n";38793880print"</tr>\n";3881next;# instead of 'else' clause, to avoid extra indent3882}3883# else ordinary diff38843885my($to_mode_oct,$to_mode_str,$to_file_type);3886my($from_mode_oct,$from_mode_str,$from_file_type);3887if($diff->{'to_mode'}ne('0' x 6)) {3888$to_mode_oct=oct$diff->{'to_mode'};3889if(S_ISREG($to_mode_oct)) {# only for regular file3890$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits3891}3892$to_file_type= file_type($diff->{'to_mode'});3893}3894if($diff->{'from_mode'}ne('0' x 6)) {3895$from_mode_oct=oct$diff->{'from_mode'};3896if(S_ISREG($to_mode_oct)) {# only for regular file3897$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits3898}3899$from_file_type= file_type($diff->{'from_mode'});3900}39013902if($diff->{'status'}eq"A") {# created3903my$mode_chng="<span class=\"file_status new\">[new$to_file_type";3904$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;3905$mode_chng.="]</span>";3906print"<td>";3907print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3908 hash_base=>$hash, file_name=>$diff->{'file'}),3909-class=>"list"}, esc_path($diff->{'file'}));3910print"</td>\n";3911print"<td>$mode_chng</td>\n";3912print"<td class=\"link\">";3913if($actioneq'commitdiff') {3914# link to patch3915$patchno++;3916print$cgi->a({-href =>"#patch$patchno"},"patch");3917print" | ";3918}3919print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3920 hash_base=>$hash, file_name=>$diff->{'file'})},3921"blob");3922print"</td>\n";39233924}elsif($diff->{'status'}eq"D") {# deleted3925my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";3926print"<td>";3927print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3928 hash_base=>$parent, file_name=>$diff->{'file'}),3929-class=>"list"}, esc_path($diff->{'file'}));3930print"</td>\n";3931print"<td>$mode_chng</td>\n";3932print"<td class=\"link\">";3933if($actioneq'commitdiff') {3934# link to patch3935$patchno++;3936print$cgi->a({-href =>"#patch$patchno"},"patch");3937print" | ";3938}3939print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3940 hash_base=>$parent, file_name=>$diff->{'file'})},3941"blob") ." | ";3942if($have_blame) {3943print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,3944 file_name=>$diff->{'file'})},3945"blame") ." | ";3946}3947print$cgi->a({-href => href(action=>"history", hash_base=>$parent,3948 file_name=>$diff->{'file'})},3949"history");3950print"</td>\n";39513952}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed3953my$mode_chnge="";3954if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3955$mode_chnge="<span class=\"file_status mode_chnge\">[changed";3956if($from_file_typene$to_file_type) {3957$mode_chnge.=" from$from_file_typeto$to_file_type";3958}3959if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {3960if($from_mode_str&&$to_mode_str) {3961$mode_chnge.=" mode:$from_mode_str->$to_mode_str";3962}elsif($to_mode_str) {3963$mode_chnge.=" mode:$to_mode_str";3964}3965}3966$mode_chnge.="]</span>\n";3967}3968print"<td>";3969print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3970 hash_base=>$hash, file_name=>$diff->{'file'}),3971-class=>"list"}, esc_path($diff->{'file'}));3972print"</td>\n";3973print"<td>$mode_chnge</td>\n";3974print"<td class=\"link\">";3975if($actioneq'commitdiff') {3976# link to patch3977$patchno++;3978print$cgi->a({-href =>"#patch$patchno"},"patch") .3979" | ";3980}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3981# "commit" view and modified file (not onlu mode changed)3982print$cgi->a({-href => href(action=>"blobdiff",3983 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3984 hash_base=>$hash, hash_parent_base=>$parent,3985 file_name=>$diff->{'file'})},3986"diff") .3987" | ";3988}3989print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3990 hash_base=>$hash, file_name=>$diff->{'file'})},3991"blob") ." | ";3992if($have_blame) {3993print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3994 file_name=>$diff->{'file'})},3995"blame") ." | ";3996}3997print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3998 file_name=>$diff->{'file'})},3999"history");4000print"</td>\n";40014002}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied4003my%status_name= ('R'=>'moved','C'=>'copied');4004my$nstatus=$status_name{$diff->{'status'}};4005my$mode_chng="";4006if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4007# mode also for directories, so we cannot use $to_mode_str4008$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);4009}4010print"<td>".4011$cgi->a({-href => href(action=>"blob", hash_base=>$hash,4012 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),4013-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".4014"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".4015$cgi->a({-href => href(action=>"blob", hash_base=>$parent,4016 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),4017-class=>"list"}, esc_path($diff->{'from_file'})) .4018" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".4019"<td class=\"link\">";4020if($actioneq'commitdiff') {4021# link to patch4022$patchno++;4023print$cgi->a({-href =>"#patch$patchno"},"patch") .4024" | ";4025}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4026# "commit" view and modified file (not only pure rename or copy)4027print$cgi->a({-href => href(action=>"blobdiff",4028 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4029 hash_base=>$hash, hash_parent_base=>$parent,4030 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},4031"diff") .4032" | ";4033}4034print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4035 hash_base=>$parent, file_name=>$diff->{'to_file'})},4036"blob") ." | ";4037if($have_blame) {4038print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4039 file_name=>$diff->{'to_file'})},4040"blame") ." | ";4041}4042print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4043 file_name=>$diff->{'to_file'})},4044"history");4045print"</td>\n";40464047}# we should not encounter Unmerged (U) or Unknown (X) status4048print"</tr>\n";4049}4050print"</tbody>"if$has_header;4051print"</table>\n";4052}40534054sub git_patchset_body {4055my($fd,$difftree,$hash,@hash_parents) =@_;4056my($hash_parent) =$hash_parents[0];40574058my$is_combined= (@hash_parents>1);4059my$patch_idx=0;4060my$patch_number=0;4061my$patch_line;4062my$diffinfo;4063my$to_name;4064my(%from,%to);40654066print"<div class=\"patchset\">\n";40674068# skip to first patch4069while($patch_line= <$fd>) {4070chomp$patch_line;40714072last if($patch_line=~m/^diff /);4073}40744075 PATCH:4076while($patch_line) {40774078# parse "git diff" header line4079if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {4080# $1 is from_name, which we do not use4081$to_name= unquote($2);4082$to_name=~s!^b/!!;4083}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {4084# $1 is 'cc' or 'combined', which we do not use4085$to_name= unquote($2);4086}else{4087$to_name=undef;4088}40894090# check if current patch belong to current raw line4091# and parse raw git-diff line if needed4092if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {4093# this is continuation of a split patch4094print"<div class=\"patch cont\">\n";4095}else{4096# advance raw git-diff output if needed4097$patch_idx++ifdefined$diffinfo;40984099# read and prepare patch information4100$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);41014102# compact combined diff output can have some patches skipped4103# find which patch (using pathname of result) we are at now;4104if($is_combined) {4105while($to_namene$diffinfo->{'to_file'}) {4106print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4107 format_diff_cc_simplified($diffinfo,@hash_parents) .4108"</div>\n";# class="patch"41094110$patch_idx++;4111$patch_number++;41124113last if$patch_idx>$#$difftree;4114$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);4115}4116}41174118# modifies %from, %to hashes4119 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);41204121# this is first patch for raw difftree line with $patch_idx index4122# we index @$difftree array from 0, but number patches from 14123print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";4124}41254126# git diff header4127#assert($patch_line =~ m/^diff /) if DEBUG;4128#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed4129$patch_number++;4130# print "git diff" header4131print format_git_diff_header_line($patch_line,$diffinfo,4132 \%from, \%to);41334134# print extended diff header4135print"<div class=\"diff extended_header\">\n";4136 EXTENDED_HEADER:4137while($patch_line= <$fd>) {4138chomp$patch_line;41394140last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);41414142print format_extended_diff_header_line($patch_line,$diffinfo,4143 \%from, \%to);4144}4145print"</div>\n";# class="diff extended_header"41464147# from-file/to-file diff header4148if(!$patch_line) {4149print"</div>\n";# class="patch"4150last PATCH;4151}4152next PATCH if($patch_line=~m/^diff /);4153#assert($patch_line =~ m/^---/) if DEBUG;41544155my$last_patch_line=$patch_line;4156$patch_line= <$fd>;4157chomp$patch_line;4158#assert($patch_line =~ m/^\+\+\+/) if DEBUG;41594160print format_diff_from_to_header($last_patch_line,$patch_line,4161$diffinfo, \%from, \%to,4162@hash_parents);41634164# the patch itself4165 LINE:4166while($patch_line= <$fd>) {4167chomp$patch_line;41684169next PATCH if($patch_line=~m/^diff /);41704171print format_diff_line($patch_line, \%from, \%to);4172}41734174}continue{4175print"</div>\n";# class="patch"4176}41774178# for compact combined (--cc) format, with chunk and patch simpliciaction4179# patchset might be empty, but there might be unprocessed raw lines4180for(++$patch_idxif$patch_number>0;4181$patch_idx<@$difftree;4182++$patch_idx) {4183# read and prepare patch information4184$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);41854186# generate anchor for "patch" links in difftree / whatchanged part4187print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4188 format_diff_cc_simplified($diffinfo,@hash_parents) .4189"</div>\n";# class="patch"41904191$patch_number++;4192}41934194if($patch_number==0) {4195if(@hash_parents>1) {4196print"<div class=\"diff nodifferences\">Trivial merge</div>\n";4197}else{4198print"<div class=\"diff nodifferences\">No differences found</div>\n";4199}4200}42014202print"</div>\n";# class="patchset"4203}42044205# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42064207# fills project list info (age, description, owner, forks) for each4208# project in the list, removing invalid projects from returned list4209# NOTE: modifies $projlist, but does not remove entries from it4210sub fill_project_list_info {4211my($projlist,$check_forks) =@_;4212my@projects;42134214my$show_ctags= gitweb_check_feature('ctags');4215 PROJECT:4216foreachmy$pr(@$projlist) {4217my(@activity) = git_get_last_activity($pr->{'path'});4218unless(@activity) {4219next PROJECT;4220}4221($pr->{'age'},$pr->{'age_string'}) =@activity;4222if(!defined$pr->{'descr'}) {4223my$descr= git_get_project_description($pr->{'path'}) ||"";4224$descr= to_utf8($descr);4225$pr->{'descr_long'} =$descr;4226$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4227}4228if(!defined$pr->{'owner'}) {4229$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4230}4231if($check_forks) {4232my$pname=$pr->{'path'};4233if(($pname=~s/\.git$//) &&4234($pname!~/\/$/) &&4235(-d "$projectroot/$pname")) {4236$pr->{'forks'} ="-d$projectroot/$pname";4237}else{4238$pr->{'forks'} =0;4239}4240}4241$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4242push@projects,$pr;4243}42444245return@projects;4246}42474248# print 'sort by' <th> element, generating 'sort by $name' replay link4249# if that order is not selected4250sub print_sort_th {4251my($name,$order,$header) =@_;4252$header||=ucfirst($name);42534254if($ordereq$name) {4255print"<th>$header</th>\n";4256}else{4257print"<th>".4258$cgi->a({-href => href(-replay=>1, order=>$name),4259-class=>"header"},$header) .4260"</th>\n";4261}4262}42634264sub git_project_list_body {4265# actually uses global variable $project4266my($projlist,$order,$from,$to,$extra,$no_header) =@_;42674268my$check_forks= gitweb_check_feature('forks');4269my@projects= fill_project_list_info($projlist,$check_forks);42704271$order||=$default_projects_order;4272$from=0unlessdefined$from;4273$to=$#projectsif(!defined$to||$#projects<$to);42744275my%order_info= (4276 project => { key =>'path', type =>'str'},4277 descr => { key =>'descr_long', type =>'str'},4278 owner => { key =>'owner', type =>'str'},4279 age => { key =>'age', type =>'num'}4280);4281my$oi=$order_info{$order};4282if($oi->{'type'}eq'str') {4283@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4284}else{4285@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4286}42874288my$show_ctags= gitweb_check_feature('ctags');4289if($show_ctags) {4290my%ctags;4291foreachmy$p(@projects) {4292foreachmy$ct(keys%{$p->{'ctags'}}) {4293$ctags{$ct} +=$p->{'ctags'}->{$ct};4294}4295}4296my$cloud= git_populate_project_tagcloud(\%ctags);4297print git_show_project_tagcloud($cloud,64);4298}42994300print"<table class=\"project_list\">\n";4301unless($no_header) {4302print"<tr>\n";4303if($check_forks) {4304print"<th></th>\n";4305}4306 print_sort_th('project',$order,'Project');4307 print_sort_th('descr',$order,'Description');4308 print_sort_th('owner',$order,'Owner');4309 print_sort_th('age',$order,'Last Change');4310print"<th></th>\n".# for links4311"</tr>\n";4312}4313my$alternate=1;4314my$tagfilter=$cgi->param('by_tag');4315for(my$i=$from;$i<=$to;$i++) {4316my$pr=$projects[$i];43174318next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4319next if$searchtextand not$pr->{'path'} =~/$searchtext/4320and not$pr->{'descr_long'} =~/$searchtext/;4321# Weed out forks or non-matching entries of search4322if($check_forks) {4323my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4324$forkbase="^$forkbase"if$forkbase;4325next ifnot$searchtextand not$tagfilterand$show_ctags4326and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4327}43284329if($alternate) {4330print"<tr class=\"dark\">\n";4331}else{4332print"<tr class=\"light\">\n";4333}4334$alternate^=1;4335if($check_forks) {4336print"<td>";4337if($pr->{'forks'}) {4338print"<!--$pr->{'forks'} -->\n";4339print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4340}4341print"</td>\n";4342}4343print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4344-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4345"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4346-class=>"list", -title =>$pr->{'descr_long'}},4347 esc_html($pr->{'descr'})) ."</td>\n".4348"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4349print"<td class=\"". age_class($pr->{'age'}) ."\">".4350(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4351"<td class=\"link\">".4352$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4353$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4354$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4355$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4356($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4357"</td>\n".4358"</tr>\n";4359}4360if(defined$extra) {4361print"<tr>\n";4362if($check_forks) {4363print"<td></td>\n";4364}4365print"<td colspan=\"5\">$extra</td>\n".4366"</tr>\n";4367}4368print"</table>\n";4369}43704371sub git_log_body {4372# uses global variable $project4373my($commitlist,$from,$to,$refs,$extra) =@_;43744375$from=0unlessdefined$from;4376$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);43774378for(my$i=0;$i<=$to;$i++) {4379my%co= %{$commitlist->[$i]};4380next if!%co;4381my$commit=$co{'id'};4382my$ref= format_ref_marker($refs,$commit);4383my%ad= parse_date($co{'author_epoch'});4384 git_print_header_div('commit',4385"<span class=\"age\">$co{'age_string'}</span>".4386 esc_html($co{'title'}) .$ref,4387$commit);4388print"<div class=\"title_text\">\n".4389"<div class=\"log_link\">\n".4390$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .4391" | ".4392$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .4393" | ".4394$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .4395"<br/>\n".4396"</div>\n";4397 git_print_authorship(\%co, -tag =>'span');4398print"<br/>\n</div>\n";43994400print"<div class=\"log_body\">\n";4401 git_print_log($co{'comment'}, -final_empty_line=>1);4402print"</div>\n";4403}4404if($extra) {4405print"<div class=\"page_nav\">\n";4406print"$extra\n";4407print"</div>\n";4408}4409}44104411sub git_shortlog_body {4412# uses global variable $project4413my($commitlist,$from,$to,$refs,$extra) =@_;44144415$from=0unlessdefined$from;4416$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);44174418print"<table class=\"shortlog\">\n";4419my$alternate=1;4420for(my$i=$from;$i<=$to;$i++) {4421my%co= %{$commitlist->[$i]};4422my$commit=$co{'id'};4423my$ref= format_ref_marker($refs,$commit);4424if($alternate) {4425print"<tr class=\"dark\">\n";4426}else{4427print"<tr class=\"light\">\n";4428}4429$alternate^=1;4430# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4431print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4432 format_author_html('td', \%co,10) ."<td>";4433print format_subject_html($co{'title'},$co{'title_short'},4434 href(action=>"commit", hash=>$commit),$ref);4435print"</td>\n".4436"<td class=\"link\">".4437$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4438$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4439$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4440my$snapshot_links= format_snapshot_links($commit);4441if(defined$snapshot_links) {4442print" | ".$snapshot_links;4443}4444print"</td>\n".4445"</tr>\n";4446}4447if(defined$extra) {4448print"<tr>\n".4449"<td colspan=\"4\">$extra</td>\n".4450"</tr>\n";4451}4452print"</table>\n";4453}44544455sub git_history_body {4456# Warning: assumes constant type (blob or tree) during history4457my($commitlist,$from,$to,$refs,$extra,4458$file_name,$file_hash,$ftype) =@_;44594460$from=0unlessdefined$from;4461$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});44624463print"<table class=\"history\">\n";4464my$alternate=1;4465for(my$i=$from;$i<=$to;$i++) {4466my%co= %{$commitlist->[$i]};4467if(!%co) {4468next;4469}4470my$commit=$co{'id'};44714472my$ref= format_ref_marker($refs,$commit);44734474if($alternate) {4475print"<tr class=\"dark\">\n";4476}else{4477print"<tr class=\"light\">\n";4478}4479$alternate^=1;4480print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4481# shortlog: format_author_html('td', \%co, 10)4482 format_author_html('td', \%co,15,3) ."<td>";4483# originally git_history used chop_str($co{'title'}, 50)4484print format_subject_html($co{'title'},$co{'title_short'},4485 href(action=>"commit", hash=>$commit),$ref);4486print"</td>\n".4487"<td class=\"link\">".4488$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4489$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");44904491if($ftypeeq'blob') {4492my$blob_current=$file_hash;4493my$blob_parent= git_get_hash_by_path($commit,$file_name);4494if(defined$blob_current&&defined$blob_parent&&4495$blob_currentne$blob_parent) {4496print" | ".4497$cgi->a({-href => href(action=>"blobdiff",4498 hash=>$blob_current, hash_parent=>$blob_parent,4499 hash_base=>$hash_base, hash_parent_base=>$commit,4500 file_name=>$file_name)},4501"diff to current");4502}4503}4504print"</td>\n".4505"</tr>\n";4506}4507if(defined$extra) {4508print"<tr>\n".4509"<td colspan=\"4\">$extra</td>\n".4510"</tr>\n";4511}4512print"</table>\n";4513}45144515sub git_tags_body {4516# uses global variable $project4517my($taglist,$from,$to,$extra) =@_;4518$from=0unlessdefined$from;4519$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);45204521print"<table class=\"tags\">\n";4522my$alternate=1;4523for(my$i=$from;$i<=$to;$i++) {4524my$entry=$taglist->[$i];4525my%tag=%$entry;4526my$comment=$tag{'subject'};4527my$comment_short;4528if(defined$comment) {4529$comment_short= chop_str($comment,30,5);4530}4531if($alternate) {4532print"<tr class=\"dark\">\n";4533}else{4534print"<tr class=\"light\">\n";4535}4536$alternate^=1;4537if(defined$tag{'age'}) {4538print"<td><i>$tag{'age'}</i></td>\n";4539}else{4540print"<td></td>\n";4541}4542print"<td>".4543$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4544-class=>"list name"}, esc_html($tag{'name'})) .4545"</td>\n".4546"<td>";4547if(defined$comment) {4548print format_subject_html($comment,$comment_short,4549 href(action=>"tag", hash=>$tag{'id'}));4550}4551print"</td>\n".4552"<td class=\"selflink\">";4553if($tag{'type'}eq"tag") {4554print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4555}else{4556print" ";4557}4558print"</td>\n".4559"<td class=\"link\">"." | ".4560$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4561if($tag{'reftype'}eq"commit") {4562print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4563" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4564}elsif($tag{'reftype'}eq"blob") {4565print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4566}4567print"</td>\n".4568"</tr>";4569}4570if(defined$extra) {4571print"<tr>\n".4572"<td colspan=\"5\">$extra</td>\n".4573"</tr>\n";4574}4575print"</table>\n";4576}45774578sub git_heads_body {4579# uses global variable $project4580my($headlist,$head,$from,$to,$extra) =@_;4581$from=0unlessdefined$from;4582$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);45834584print"<table class=\"heads\">\n";4585my$alternate=1;4586for(my$i=$from;$i<=$to;$i++) {4587my$entry=$headlist->[$i];4588my%ref=%$entry;4589my$curr=$ref{'id'}eq$head;4590if($alternate) {4591print"<tr class=\"dark\">\n";4592}else{4593print"<tr class=\"light\">\n";4594}4595$alternate^=1;4596print"<td><i>$ref{'age'}</i></td>\n".4597($curr?"<td class=\"current_head\">":"<td>") .4598$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4599-class=>"list name"},esc_html($ref{'name'})) .4600"</td>\n".4601"<td class=\"link\">".4602$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4603$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4604$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4605"</td>\n".4606"</tr>";4607}4608if(defined$extra) {4609print"<tr>\n".4610"<td colspan=\"3\">$extra</td>\n".4611"</tr>\n";4612}4613print"</table>\n";4614}46154616sub git_search_grep_body {4617my($commitlist,$from,$to,$extra) =@_;4618$from=0unlessdefined$from;4619$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);46204621print"<table class=\"commit_search\">\n";4622my$alternate=1;4623for(my$i=$from;$i<=$to;$i++) {4624my%co= %{$commitlist->[$i]};4625if(!%co) {4626next;4627}4628my$commit=$co{'id'};4629if($alternate) {4630print"<tr class=\"dark\">\n";4631}else{4632print"<tr class=\"light\">\n";4633}4634$alternate^=1;4635print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4636 format_author_html('td', \%co,15,5) .4637"<td>".4638$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4639-class=>"list subject"},4640 chop_and_escape_str($co{'title'},50) ."<br/>");4641my$comment=$co{'comment'};4642foreachmy$line(@$comment) {4643if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4644my($lead,$match,$trail) = ($1,$2,$3);4645$match= chop_str($match,70,5,'center');4646my$contextlen=int((80-length($match))/2);4647$contextlen=30if($contextlen>30);4648$lead= chop_str($lead,$contextlen,10,'left');4649$trail= chop_str($trail,$contextlen,10,'right');46504651$lead= esc_html($lead);4652$match= esc_html($match);4653$trail= esc_html($trail);46544655print"$lead<span class=\"match\">$match</span>$trail<br />";4656}4657}4658print"</td>\n".4659"<td class=\"link\">".4660$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4661" | ".4662$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4663" | ".4664$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4665print"</td>\n".4666"</tr>\n";4667}4668if(defined$extra) {4669print"<tr>\n".4670"<td colspan=\"3\">$extra</td>\n".4671"</tr>\n";4672}4673print"</table>\n";4674}46754676## ======================================================================4677## ======================================================================4678## actions46794680sub git_project_list {4681my$order=$input_params{'order'};4682if(defined$order&&$order!~m/none|project|descr|owner|age/) {4683 die_error(400,"Unknown order parameter");4684}46854686my@list= git_get_projects_list();4687if(!@list) {4688 die_error(404,"No projects found");4689}46904691 git_header_html();4692if(-f $home_text) {4693print"<div class=\"index_include\">\n";4694 insert_file($home_text);4695print"</div>\n";4696}4697print$cgi->startform(-method=>"get") .4698"<p class=\"projsearch\">Search:\n".4699$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4700"</p>".4701$cgi->end_form() ."\n";4702 git_project_list_body(\@list,$order);4703 git_footer_html();4704}47054706sub git_forks {4707my$order=$input_params{'order'};4708if(defined$order&&$order!~m/none|project|descr|owner|age/) {4709 die_error(400,"Unknown order parameter");4710}47114712my@list= git_get_projects_list($project);4713if(!@list) {4714 die_error(404,"No forks found");4715}47164717 git_header_html();4718 git_print_page_nav('','');4719 git_print_header_div('summary',"$projectforks");4720 git_project_list_body(\@list,$order);4721 git_footer_html();4722}47234724sub git_project_index {4725my@projects= git_get_projects_list($project);47264727print$cgi->header(4728-type =>'text/plain',4729-charset =>'utf-8',4730-content_disposition =>'inline; filename="index.aux"');47314732foreachmy$pr(@projects) {4733if(!exists$pr->{'owner'}) {4734$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4735}47364737my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4738# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4739$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4740$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4741$path=~s/ /\+/g;4742$owner=~s/ /\+/g;47434744print"$path$owner\n";4745}4746}47474748sub git_summary {4749my$descr= git_get_project_description($project) ||"none";4750my%co= parse_commit("HEAD");4751my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4752my$head=$co{'id'};47534754my$owner= git_get_project_owner($project);47554756my$refs= git_get_references();4757# These get_*_list functions return one more to allow us to see if4758# there are more ...4759my@taglist= git_get_tags_list(16);4760my@headlist= git_get_heads_list(16);4761my@forklist;4762my$check_forks= gitweb_check_feature('forks');47634764if($check_forks) {4765@forklist= git_get_projects_list($project);4766}47674768 git_header_html();4769 git_print_page_nav('summary','',$head);47704771print"<div class=\"title\"> </div>\n";4772print"<table class=\"projects_list\">\n".4773"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4774"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4775if(defined$cd{'rfc2822'}) {4776print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4777}47784779# use per project git URL list in $projectroot/$project/cloneurl4780# or make project git URL from git base URL and project name4781my$url_tag="URL";4782my@url_list= git_get_project_url_list($project);4783@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4784foreachmy$git_url(@url_list) {4785next unless$git_url;4786print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4787$url_tag="";4788}47894790# Tag cloud4791my$show_ctags= gitweb_check_feature('ctags');4792if($show_ctags) {4793my$ctags= git_get_project_ctags($project);4794my$cloud= git_populate_project_tagcloud($ctags);4795print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4796print"</td>\n<td>"unless%$ctags;4797print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4798print"</td>\n<td>"if%$ctags;4799print git_show_project_tagcloud($cloud,48);4800print"</td></tr>";4801}48024803print"</table>\n";48044805# If XSS prevention is on, we don't include README.html.4806# TODO: Allow a readme in some safe format.4807if(!$prevent_xss&& -s "$projectroot/$project/README.html") {4808print"<div class=\"title\">readme</div>\n".4809"<div class=\"readme\">\n";4810 insert_file("$projectroot/$project/README.html");4811print"\n</div>\n";# class="readme"4812}48134814# we need to request one more than 16 (0..15) to check if4815# those 16 are all4816my@commitlist=$head? parse_commits($head,17) : ();4817if(@commitlist) {4818 git_print_header_div('shortlog');4819 git_shortlog_body(\@commitlist,0,15,$refs,4820$#commitlist<=15?undef:4821$cgi->a({-href => href(action=>"shortlog")},"..."));4822}48234824if(@taglist) {4825 git_print_header_div('tags');4826 git_tags_body(\@taglist,0,15,4827$#taglist<=15?undef:4828$cgi->a({-href => href(action=>"tags")},"..."));4829}48304831if(@headlist) {4832 git_print_header_div('heads');4833 git_heads_body(\@headlist,$head,0,15,4834$#headlist<=15?undef:4835$cgi->a({-href => href(action=>"heads")},"..."));4836}48374838if(@forklist) {4839 git_print_header_div('forks');4840 git_project_list_body(\@forklist,'age',0,15,4841$#forklist<=15?undef:4842$cgi->a({-href => href(action=>"forks")},"..."),4843'no_header');4844}48454846 git_footer_html();4847}48484849sub git_tag {4850my$head= git_get_head_hash($project);4851 git_header_html();4852 git_print_page_nav('','',$head,undef,$head);4853my%tag= parse_tag($hash);48544855if(!%tag) {4856 die_error(404,"Unknown tag object");4857}48584859 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4860print"<div class=\"title_text\">\n".4861"<table class=\"object_header\">\n".4862"<tr>\n".4863"<td>object</td>\n".4864"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4865$tag{'object'}) ."</td>\n".4866"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4867$tag{'type'}) ."</td>\n".4868"</tr>\n";4869if(defined($tag{'author'})) {4870 git_print_authorship_rows(\%tag,'author');4871}4872print"</table>\n\n".4873"</div>\n";4874print"<div class=\"page_body\">";4875my$comment=$tag{'comment'};4876foreachmy$line(@$comment) {4877chomp$line;4878print esc_html($line, -nbsp=>1) ."<br/>\n";4879}4880print"</div>\n";4881 git_footer_html();4882}48834884sub git_blame {4885# permissions4886 gitweb_check_feature('blame')4887or die_error(403,"Blame view not allowed");48884889# error checking4890 die_error(400,"No file name given")unless$file_name;4891$hash_base||= git_get_head_hash($project);4892 die_error(404,"Couldn't find base commit")unless$hash_base;4893my%co= parse_commit($hash_base)4894or die_error(404,"Commit not found");4895my$ftype="blob";4896if(!defined$hash) {4897$hash= git_get_hash_by_path($hash_base,$file_name,"blob")4898or die_error(404,"Error looking up file");4899}else{4900$ftype= git_get_type($hash);4901if($ftype!~"blob") {4902 die_error(400,"Object is not a blob");4903}4904}49054906# run git-blame --porcelain4907open my$fd,"-|", git_cmd(),"blame",'-p',4908$hash_base,'--',$file_name4909or die_error(500,"Open git-blame failed");49104911# page header4912 git_header_html();4913my$formats_nav=4914$cgi->a({-href => href(action=>"blob", -replay=>1)},4915"blob") .4916" | ".4917$cgi->a({-href => href(action=>"history", -replay=>1)},4918"history") .4919" | ".4920$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},4921"HEAD");4922 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4923 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4924 git_print_page_path($file_name,$ftype,$hash_base);49254926# page body4927my@rev_color=qw(light dark);4928my$num_colors=scalar(@rev_color);4929my$current_color=0;4930my%metainfo= ();49314932print<<HTML;4933<div class="page_body">4934<table class="blame">4935<tr><th>Commit</th><th>Line</th><th>Data</th></tr>4936HTML4937 LINE:4938while(my$line= <$fd>) {4939chomp$line;4940# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]4941# no <lines in group> for subsequent lines in group of lines4942my($full_rev,$orig_lineno,$lineno,$group_size) =4943($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);4944if(!exists$metainfo{$full_rev}) {4945$metainfo{$full_rev} = {'nprevious'=>0};4946}4947my$meta=$metainfo{$full_rev};4948my$data;4949while($data= <$fd>) {4950chomp$data;4951last if($data=~s/^\t//);# contents of line4952if($data=~/^(\S+)(?: (.*))?$/) {4953$meta->{$1} =$2unlessexists$meta->{$1};4954}4955if($data=~/^previous /) {4956$meta->{'nprevious'}++;4957}4958}4959my$short_rev=substr($full_rev,0,8);4960my$author=$meta->{'author'};4961my%date=4962 parse_date($meta->{'author-time'},$meta->{'author-tz'});4963my$date=$date{'iso-tz'};4964if($group_size) {4965$current_color= ($current_color+1) %$num_colors;4966}4967my$tr_class=$rev_color[$current_color];4968$tr_class.=' boundary'if(exists$meta->{'boundary'});4969$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);4970$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);4971print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";4972if($group_size) {4973print"<td class=\"sha1\"";4974print" title=\"". esc_html($author) .",$date\"";4975print" rowspan=\"$group_size\""if($group_size>1);4976print">";4977print$cgi->a({-href => href(action=>"commit",4978 hash=>$full_rev,4979 file_name=>$file_name)},4980 esc_html($short_rev));4981if($group_size>=2) {4982my@author_initials= ($author=~/\b([[:upper:]])\B/g);4983if(@author_initials) {4984print"<br />".4985 esc_html(join('',@author_initials));4986# or join('.', ...)4987}4988}4989print"</td>\n";4990}4991# 'previous' <sha1 of parent commit> <filename at commit>4992if(exists$meta->{'previous'} &&4993$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {4994$meta->{'parent'} =$1;4995$meta->{'file_parent'} = unquote($2);4996}4997my$linenr_commit=4998exists($meta->{'parent'}) ?4999$meta->{'parent'} :$full_rev;5000my$linenr_filename=5001exists($meta->{'file_parent'}) ?5002$meta->{'file_parent'} : unquote($meta->{'filename'});5003my$blamed= href(action =>'blame',5004 file_name =>$linenr_filename,5005 hash_base =>$linenr_commit);5006print"<td class=\"linenr\">";5007print$cgi->a({ -href =>"$blamed#l$orig_lineno",5008-class=>"linenr"},5009 esc_html($lineno));5010print"</td>";5011print"<td class=\"pre\">". esc_html($data) ."</td>\n";5012print"</tr>\n";5013}5014print"</table>\n";5015print"</div>";5016close$fd5017or print"Reading blob failed\n";50185019# page footer5020 git_footer_html();5021}50225023sub git_tags {5024my$head= git_get_head_hash($project);5025 git_header_html();5026 git_print_page_nav('','',$head,undef,$head);5027 git_print_header_div('summary',$project);50285029my@tagslist= git_get_tags_list();5030if(@tagslist) {5031 git_tags_body(\@tagslist);5032}5033 git_footer_html();5034}50355036sub git_heads {5037my$head= git_get_head_hash($project);5038 git_header_html();5039 git_print_page_nav('','',$head,undef,$head);5040 git_print_header_div('summary',$project);50415042my@headslist= git_get_heads_list();5043if(@headslist) {5044 git_heads_body(\@headslist,$head);5045}5046 git_footer_html();5047}50485049sub git_blob_plain {5050my$type=shift;5051my$expires;50525053if(!defined$hash) {5054if(defined$file_name) {5055my$base=$hash_base|| git_get_head_hash($project);5056$hash= git_get_hash_by_path($base,$file_name,"blob")5057or die_error(404,"Cannot find file");5058}else{5059 die_error(400,"No file name defined");5060}5061}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5062# blobs defined by non-textual hash id's can be cached5063$expires="+1d";5064}50655066open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5067or die_error(500,"Open git-cat-file blob '$hash' failed");50685069# content-type (can include charset)5070$type= blob_contenttype($fd,$file_name,$type);50715072# "save as" filename, even when no $file_name is given5073my$save_as="$hash";5074if(defined$file_name) {5075$save_as=$file_name;5076}elsif($type=~m/^text\//) {5077$save_as.='.txt';5078}50795080# With XSS prevention on, blobs of all types except a few known safe5081# ones are served with "Content-Disposition: attachment" to make sure5082# they don't run in our security domain. For certain image types,5083# blob view writes an <img> tag referring to blob_plain view, and we5084# want to be sure not to break that by serving the image as an5085# attachment (though Firefox 3 doesn't seem to care).5086my$sandbox=$prevent_xss&&5087$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;50885089print$cgi->header(5090-type =>$type,5091-expires =>$expires,5092-content_disposition =>5093($sandbox?'attachment':'inline')5094.'; filename="'.$save_as.'"');5095local$/=undef;5096binmode STDOUT,':raw';5097print<$fd>;5098binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5099close$fd;5100}51015102sub git_blob {5103my$expires;51045105if(!defined$hash) {5106if(defined$file_name) {5107my$base=$hash_base|| git_get_head_hash($project);5108$hash= git_get_hash_by_path($base,$file_name,"blob")5109or die_error(404,"Cannot find file");5110}else{5111 die_error(400,"No file name defined");5112}5113}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5114# blobs defined by non-textual hash id's can be cached5115$expires="+1d";5116}51175118my$have_blame= gitweb_check_feature('blame');5119open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5120or die_error(500,"Couldn't cat$file_name,$hash");5121my$mimetype= blob_mimetype($fd,$file_name);5122if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {5123close$fd;5124return git_blob_plain($mimetype);5125}5126# we can have blame only for text/* mimetype5127$have_blame&&= ($mimetype=~m!^text/!);51285129 git_header_html(undef,$expires);5130my$formats_nav='';5131if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5132if(defined$file_name) {5133if($have_blame) {5134$formats_nav.=5135$cgi->a({-href => href(action=>"blame", -replay=>1)},5136"blame") .5137" | ";5138}5139$formats_nav.=5140$cgi->a({-href => href(action=>"history", -replay=>1)},5141"history") .5142" | ".5143$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5144"raw") .5145" | ".5146$cgi->a({-href => href(action=>"blob",5147 hash_base=>"HEAD", file_name=>$file_name)},5148"HEAD");5149}else{5150$formats_nav.=5151$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5152"raw");5153}5154 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5155 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5156}else{5157print"<div class=\"page_nav\">\n".5158"<br/><br/></div>\n".5159"<div class=\"title\">$hash</div>\n";5160}5161 git_print_page_path($file_name,"blob",$hash_base);5162print"<div class=\"page_body\">\n";5163if($mimetype=~m!^image/!) {5164print qq!<img type="$mimetype"!;5165if($file_name) {5166print qq! alt="$file_name" title="$file_name"!;5167}5168print qq! src="! .5169 href(action=>"blob_plain", hash=>$hash,5170 hash_base=>$hash_base, file_name=>$file_name) .5171 qq!"/>\n!;5172}else{5173my$nr;5174while(my$line= <$fd>) {5175chomp$line;5176$nr++;5177$line= untabify($line);5178printf"<div class=\"pre\"><a id=\"l%i\"href=\"". href(-replay =>1)5179."#l%i\"class=\"linenr\">%4i</a>%s</div>\n",5180$nr,$nr,$nr, esc_html($line, -nbsp=>1);5181}5182}5183close$fd5184or print"Reading blob failed.\n";5185print"</div>";5186 git_footer_html();5187}51885189sub git_tree {5190if(!defined$hash_base) {5191$hash_base="HEAD";5192}5193if(!defined$hash) {5194if(defined$file_name) {5195$hash= git_get_hash_by_path($hash_base,$file_name,"tree");5196}else{5197$hash=$hash_base;5198}5199}5200 die_error(404,"No such tree")unlessdefined($hash);52015202my$show_sizes= gitweb_check_feature('show-sizes');5203my$have_blame= gitweb_check_feature('blame');52045205my@entries= ();5206{5207local$/="\0";5208open my$fd,"-|", git_cmd(),"ls-tree",'-z',5209($show_sizes?'-l': ()),@extra_options,$hash5210or die_error(500,"Open git-ls-tree failed");5211@entries=map{chomp;$_} <$fd>;5212close$fd5213or die_error(404,"Reading tree failed");5214}52155216my$refs= git_get_references();5217my$ref= format_ref_marker($refs,$hash_base);5218 git_header_html();5219my$basedir='';5220if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5221my@views_nav= ();5222if(defined$file_name) {5223push@views_nav,5224$cgi->a({-href => href(action=>"history", -replay=>1)},5225"history"),5226$cgi->a({-href => href(action=>"tree",5227 hash_base=>"HEAD", file_name=>$file_name)},5228"HEAD"),5229}5230my$snapshot_links= format_snapshot_links($hash);5231if(defined$snapshot_links) {5232# FIXME: Should be available when we have no hash base as well.5233push@views_nav,$snapshot_links;5234}5235 git_print_page_nav('tree','',$hash_base,undef,undef,5236join(' | ',@views_nav));5237 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);5238}else{5239undef$hash_base;5240print"<div class=\"page_nav\">\n";5241print"<br/><br/></div>\n";5242print"<div class=\"title\">$hash</div>\n";5243}5244if(defined$file_name) {5245$basedir=$file_name;5246if($basedirne''&&substr($basedir, -1)ne'/') {5247$basedir.='/';5248}5249 git_print_page_path($file_name,'tree',$hash_base);5250}5251print"<div class=\"page_body\">\n";5252print"<table class=\"tree\">\n";5253my$alternate=1;5254# '..' (top directory) link if possible5255if(defined$hash_base&&5256defined$file_name&&$file_name=~m![^/]+$!) {5257if($alternate) {5258print"<tr class=\"dark\">\n";5259}else{5260print"<tr class=\"light\">\n";5261}5262$alternate^=1;52635264my$up=$file_name;5265$up=~s!/?[^/]+$!!;5266undef$upunless$up;5267# based on git_print_tree_entry5268print'<td class="mode">'. mode_str('040000') ."</td>\n";5269print'<td class="size"> </td>'."\n"if$show_sizes;5270print'<td class="list">';5271print$cgi->a({-href => href(action=>"tree",5272 hash_base=>$hash_base,5273 file_name=>$up)},5274"..");5275print"</td>\n";5276print"<td class=\"link\"></td>\n";52775278print"</tr>\n";5279}5280foreachmy$line(@entries) {5281my%t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);52825283if($alternate) {5284print"<tr class=\"dark\">\n";5285}else{5286print"<tr class=\"light\">\n";5287}5288$alternate^=1;52895290 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);52915292print"</tr>\n";5293}5294print"</table>\n".5295"</div>";5296 git_footer_html();5297}52985299sub snapshot_name {5300my($project,$hash) =@_;53015302# path/to/project.git -> project5303# path/to/project/.git -> project5304my$name= to_utf8($project);5305$name=~ s,([^/])/*\.git$,$1,;5306$name= basename($name);5307# sanitize name5308$name=~s/[[:cntrl:]]/?/g;53095310my$ver=$hash;5311if($hash=~/^[0-9a-fA-F]+$/) {5312# shorten SHA-1 hash5313my$full_hash= git_get_full_hash($project,$hash);5314if($full_hash=~/^$hash/&&length($hash) >7) {5315$ver= git_get_short_hash($project,$hash);5316}5317}elsif($hash=~m!^refs/tags/(.*)$!) {5318# tags don't need shortened SHA-1 hash5319$ver=$1;5320}else{5321# branches and other need shortened SHA-1 hash5322if($hash=~m!^refs/(?:heads|remotes)/(.*)$!) {5323$ver=$1;5324}5325$ver.='-'. git_get_short_hash($project,$hash);5326}5327# in case of hierarchical branch names5328$ver=~s!/!.!g;53295330# name = project-version_string5331$name="$name-$ver";53325333returnwantarray? ($name,$name) :$name;5334}53355336sub git_snapshot {5337my$format=$input_params{'snapshot_format'};5338if(!@snapshot_fmts) {5339 die_error(403,"Snapshots not allowed");5340}5341# default to first supported snapshot format5342$format||=$snapshot_fmts[0];5343if($format!~m/^[a-z0-9]+$/) {5344 die_error(400,"Invalid snapshot format parameter");5345}elsif(!exists($known_snapshot_formats{$format})) {5346 die_error(400,"Unknown snapshot format");5347}elsif($known_snapshot_formats{$format}{'disabled'}) {5348 die_error(403,"Snapshot format not allowed");5349}elsif(!grep($_eq$format,@snapshot_fmts)) {5350 die_error(403,"Unsupported snapshot format");5351}53525353my$type= git_get_type("$hash^{}");5354if(!$type) {5355 die_error(404,'Object does not exist');5356}elsif($typeeq'blob') {5357 die_error(400,'Object is not a tree-ish');5358}53595360my($name,$prefix) = snapshot_name($project,$hash);5361my$filename="$name$known_snapshot_formats{$format}{'suffix'}";5362my$cmd= quote_command(5363 git_cmd(),'archive',5364"--format=$known_snapshot_formats{$format}{'format'}",5365"--prefix=$prefix/",$hash);5366if(exists$known_snapshot_formats{$format}{'compressor'}) {5367$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});5368}53695370$filename=~s/(["\\])/\\$1/g;5371print$cgi->header(5372-type =>$known_snapshot_formats{$format}{'type'},5373-content_disposition =>'inline; filename="'.$filename.'"',5374-status =>'200 OK');53755376open my$fd,"-|",$cmd5377or die_error(500,"Execute git-archive failed");5378binmode STDOUT,':raw';5379print<$fd>;5380binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5381close$fd;5382}53835384sub git_log_generic {5385my($fmt_name,$body_subr,$base,$parent,$file_name,$file_hash) =@_;53865387my$head= git_get_head_hash($project);5388if(!defined$base) {5389$base=$head;5390}5391if(!defined$page) {5392$page=0;5393}5394my$refs= git_get_references();53955396my$commit_hash=$base;5397if(defined$parent) {5398$commit_hash="$parent..$base";5399}5400my@commitlist=5401 parse_commits($commit_hash,101, (100*$page),5402defined$file_name? ($file_name,"--full-history") : ());54035404my$ftype;5405if(!defined$file_hash&&defined$file_name) {5406# some commits could have deleted file in question,5407# and not have it in tree, but one of them has to have it5408for(my$i=0;$i<@commitlist;$i++) {5409$file_hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5410last ifdefined$file_hash;5411}5412}5413if(defined$file_hash) {5414$ftype= git_get_type($file_hash);5415}5416if(defined$file_name&& !defined$ftype) {5417 die_error(500,"Unknown type of object");5418}5419my%co;5420if(defined$file_name) {5421%co= parse_commit($base)5422or die_error(404,"Unknown commit object");5423}542454255426my$paging_nav= format_paging_nav($fmt_name,$page,$#commitlist>=100);5427my$next_link='';5428if($#commitlist>=100) {5429$next_link=5430$cgi->a({-href => href(-replay=>1, page=>$page+1),5431-accesskey =>"n", -title =>"Alt-n"},"next");5432}5433my$patch_max= gitweb_get_feature('patches');5434if($patch_max&& !defined$file_name) {5435if($patch_max<0||@commitlist<=$patch_max) {5436$paging_nav.=" ⋅ ".5437$cgi->a({-href => href(action=>"patches", -replay=>1)},5438"patches");5439}5440}54415442 git_header_html();5443 git_print_page_nav($fmt_name,'',$hash,$hash,$hash,$paging_nav);5444if(defined$file_name) {5445 git_print_header_div('commit', esc_html($co{'title'}),$base);5446}else{5447 git_print_header_div('summary',$project)5448}5449 git_print_page_path($file_name,$ftype,$hash_base)5450if(defined$file_name);54515452$body_subr->(\@commitlist,0,99,$refs,$next_link,5453$file_name,$file_hash,$ftype);54545455 git_footer_html();5456}54575458sub git_log {5459 git_log_generic('log', \&git_log_body,5460$hash,$hash_parent);5461}54625463sub git_commit {5464$hash||=$hash_base||"HEAD";5465my%co= parse_commit($hash)5466or die_error(404,"Unknown commit object");54675468my$parent=$co{'parent'};5469my$parents=$co{'parents'};# listref54705471# we need to prepare $formats_nav before any parameter munging5472my$formats_nav;5473if(!defined$parent) {5474# --root commitdiff5475$formats_nav.='(initial)';5476}elsif(@$parents==1) {5477# single parent commit5478$formats_nav.=5479'(parent: '.5480$cgi->a({-href => href(action=>"commit",5481 hash=>$parent)},5482 esc_html(substr($parent,0,7))) .5483')';5484}else{5485# merge commit5486$formats_nav.=5487'(merge: '.5488join(' ',map{5489$cgi->a({-href => href(action=>"commit",5490 hash=>$_)},5491 esc_html(substr($_,0,7)));5492}@$parents) .5493')';5494}5495if(gitweb_check_feature('patches') &&@$parents<=1) {5496$formats_nav.=" | ".5497$cgi->a({-href => href(action=>"patch", -replay=>1)},5498"patch");5499}55005501if(!defined$parent) {5502$parent="--root";5503}5504my@difftree;5505open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5506@diff_opts,5507(@$parents<=1?$parent:'-c'),5508$hash,"--"5509or die_error(500,"Open git-diff-tree failed");5510@difftree=map{chomp;$_} <$fd>;5511close$fdor die_error(404,"Reading git-diff-tree failed");55125513# non-textual hash id's can be cached5514my$expires;5515if($hash=~m/^[0-9a-fA-F]{40}$/) {5516$expires="+1d";5517}5518my$refs= git_get_references();5519my$ref= format_ref_marker($refs,$co{'id'});55205521 git_header_html(undef,$expires);5522 git_print_page_nav('commit','',5523$hash,$co{'tree'},$hash,5524$formats_nav);55255526if(defined$co{'parent'}) {5527 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5528}else{5529 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5530}5531print"<div class=\"title_text\">\n".5532"<table class=\"object_header\">\n";5533 git_print_authorship_rows(\%co);5534print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";5535print"<tr>".5536"<td>tree</td>".5537"<td class=\"sha1\">".5538$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),5539class=>"list"},$co{'tree'}) .5540"</td>".5541"<td class=\"link\">".5542$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},5543"tree");5544my$snapshot_links= format_snapshot_links($hash);5545if(defined$snapshot_links) {5546print" | ".$snapshot_links;5547}5548print"</td>".5549"</tr>\n";55505551foreachmy$par(@$parents) {5552print"<tr>".5553"<td>parent</td>".5554"<td class=\"sha1\">".5555$cgi->a({-href => href(action=>"commit", hash=>$par),5556class=>"list"},$par) .5557"</td>".5558"<td class=\"link\">".5559$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .5560" | ".5561$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .5562"</td>".5563"</tr>\n";5564}5565print"</table>".5566"</div>\n";55675568print"<div class=\"page_body\">\n";5569 git_print_log($co{'comment'});5570print"</div>\n";55715572 git_difftree_body(\@difftree,$hash,@$parents);55735574 git_footer_html();5575}55765577sub git_object {5578# object is defined by:5579# - hash or hash_base alone5580# - hash_base and file_name5581my$type;55825583# - hash or hash_base alone5584if($hash|| ($hash_base&& !defined$file_name)) {5585my$object_id=$hash||$hash_base;55865587open my$fd,"-|", quote_command(5588 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'5589or die_error(404,"Object does not exist");5590$type= <$fd>;5591chomp$type;5592close$fd5593or die_error(404,"Object does not exist");55945595# - hash_base and file_name5596}elsif($hash_base&&defined$file_name) {5597$file_name=~ s,/+$,,;55985599system(git_cmd(),"cat-file",'-e',$hash_base) ==05600or die_error(404,"Base object does not exist");56015602# here errors should not hapen5603open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name5604or die_error(500,"Open git-ls-tree failed");5605my$line= <$fd>;5606close$fd;56075608#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'5609unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {5610 die_error(404,"File or directory for given base does not exist");5611}5612$type=$2;5613$hash=$3;5614}else{5615 die_error(400,"Not enough information to find object");5616}56175618print$cgi->redirect(-uri => href(action=>$type, -full=>1,5619 hash=>$hash, hash_base=>$hash_base,5620 file_name=>$file_name),5621-status =>'302 Found');5622}56235624sub git_blobdiff {5625my$format=shift||'html';56265627my$fd;5628my@difftree;5629my%diffinfo;5630my$expires;56315632# preparing $fd and %diffinfo for git_patchset_body5633# new style URI5634if(defined$hash_base&&defined$hash_parent_base) {5635if(defined$file_name) {5636# read raw output5637open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5638$hash_parent_base,$hash_base,5639"--", (defined$file_parent?$file_parent: ()),$file_name5640or die_error(500,"Open git-diff-tree failed");5641@difftree=map{chomp;$_} <$fd>;5642close$fd5643or die_error(404,"Reading git-diff-tree failed");5644@difftree5645or die_error(404,"Blob diff not found");56465647}elsif(defined$hash&&5648$hash=~/[0-9a-fA-F]{40}/) {5649# try to find filename from $hash56505651# read filtered raw output5652open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5653$hash_parent_base,$hash_base,"--"5654or die_error(500,"Open git-diff-tree failed");5655@difftree=5656# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5657# $hash == to_id5658grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5659map{chomp;$_} <$fd>;5660close$fd5661or die_error(404,"Reading git-diff-tree failed");5662@difftree5663or die_error(404,"Blob diff not found");56645665}else{5666 die_error(400,"Missing one of the blob diff parameters");5667}56685669if(@difftree>1) {5670 die_error(400,"Ambiguous blob diff specification");5671}56725673%diffinfo= parse_difftree_raw_line($difftree[0]);5674$file_parent||=$diffinfo{'from_file'} ||$file_name;5675$file_name||=$diffinfo{'to_file'};56765677$hash_parent||=$diffinfo{'from_id'};5678$hash||=$diffinfo{'to_id'};56795680# non-textual hash id's can be cached5681if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5682$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5683$expires='+1d';5684}56855686# open patch output5687open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5688'-p', ($formateq'html'?"--full-index": ()),5689$hash_parent_base,$hash_base,5690"--", (defined$file_parent?$file_parent: ()),$file_name5691or die_error(500,"Open git-diff-tree failed");5692}56935694# old/legacy style URI -- not generated anymore since 1.4.3.5695if(!%diffinfo) {5696 die_error('404 Not Found',"Missing one of the blob diff parameters")5697}56985699# header5700if($formateq'html') {5701my$formats_nav=5702$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5703"raw");5704 git_header_html(undef,$expires);5705if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5706 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5707 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5708}else{5709print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5710print"<div class=\"title\">$hashvs$hash_parent</div>\n";5711}5712if(defined$file_name) {5713 git_print_page_path($file_name,"blob",$hash_base);5714}else{5715print"<div class=\"page_path\"></div>\n";5716}57175718}elsif($formateq'plain') {5719print$cgi->header(5720-type =>'text/plain',5721-charset =>'utf-8',5722-expires =>$expires,5723-content_disposition =>'inline; filename="'."$file_name".'.patch"');57245725print"X-Git-Url: ".$cgi->self_url() ."\n\n";57265727}else{5728 die_error(400,"Unknown blobdiff format");5729}57305731# patch5732if($formateq'html') {5733print"<div class=\"page_body\">\n";57345735 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5736close$fd;57375738print"</div>\n";# class="page_body"5739 git_footer_html();57405741}else{5742while(my$line= <$fd>) {5743$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5744$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;57455746print$line;57475748last if$line=~m!^\+\+\+!;5749}5750local$/=undef;5751print<$fd>;5752close$fd;5753}5754}57555756sub git_blobdiff_plain {5757 git_blobdiff('plain');5758}57595760sub git_commitdiff {5761my%params=@_;5762my$format=$params{-format} ||'html';57635764my($patch_max) = gitweb_get_feature('patches');5765if($formateq'patch') {5766 die_error(403,"Patch view not allowed")unless$patch_max;5767}57685769$hash||=$hash_base||"HEAD";5770my%co= parse_commit($hash)5771or die_error(404,"Unknown commit object");57725773# choose format for commitdiff for merge5774if(!defined$hash_parent&& @{$co{'parents'}} >1) {5775$hash_parent='--cc';5776}5777# we need to prepare $formats_nav before almost any parameter munging5778my$formats_nav;5779if($formateq'html') {5780$formats_nav=5781$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},5782"raw");5783if($patch_max&& @{$co{'parents'}} <=1) {5784$formats_nav.=" | ".5785$cgi->a({-href => href(action=>"patch", -replay=>1)},5786"patch");5787}57885789if(defined$hash_parent&&5790$hash_parentne'-c'&&$hash_parentne'--cc') {5791# commitdiff with two commits given5792my$hash_parent_short=$hash_parent;5793if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {5794$hash_parent_short=substr($hash_parent,0,7);5795}5796$formats_nav.=5797' (from';5798for(my$i=0;$i< @{$co{'parents'}};$i++) {5799if($co{'parents'}[$i]eq$hash_parent) {5800$formats_nav.=' parent '. ($i+1);5801last;5802}5803}5804$formats_nav.=': '.5805$cgi->a({-href => href(action=>"commitdiff",5806 hash=>$hash_parent)},5807 esc_html($hash_parent_short)) .5808')';5809}elsif(!$co{'parent'}) {5810# --root commitdiff5811$formats_nav.=' (initial)';5812}elsif(scalar@{$co{'parents'}} ==1) {5813# single parent commit5814$formats_nav.=5815' (parent: '.5816$cgi->a({-href => href(action=>"commitdiff",5817 hash=>$co{'parent'})},5818 esc_html(substr($co{'parent'},0,7))) .5819')';5820}else{5821# merge commit5822if($hash_parenteq'--cc') {5823$formats_nav.=' | '.5824$cgi->a({-href => href(action=>"commitdiff",5825 hash=>$hash, hash_parent=>'-c')},5826'combined');5827}else{# $hash_parent eq '-c'5828$formats_nav.=' | '.5829$cgi->a({-href => href(action=>"commitdiff",5830 hash=>$hash, hash_parent=>'--cc')},5831'compact');5832}5833$formats_nav.=5834' (merge: '.5835join(' ',map{5836$cgi->a({-href => href(action=>"commitdiff",5837 hash=>$_)},5838 esc_html(substr($_,0,7)));5839} @{$co{'parents'}} ) .5840')';5841}5842}58435844my$hash_parent_param=$hash_parent;5845if(!defined$hash_parent_param) {5846# --cc for multiple parents, --root for parentless5847$hash_parent_param=5848@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';5849}58505851# read commitdiff5852my$fd;5853my@difftree;5854if($formateq'html') {5855open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5856"--no-commit-id","--patch-with-raw","--full-index",5857$hash_parent_param,$hash,"--"5858or die_error(500,"Open git-diff-tree failed");58595860while(my$line= <$fd>) {5861chomp$line;5862# empty line ends raw part of diff-tree output5863last unless$line;5864push@difftree,scalar parse_difftree_raw_line($line);5865}58665867}elsif($formateq'plain') {5868open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5869'-p',$hash_parent_param,$hash,"--"5870or die_error(500,"Open git-diff-tree failed");5871}elsif($formateq'patch') {5872# For commit ranges, we limit the output to the number of5873# patches specified in the 'patches' feature.5874# For single commits, we limit the output to a single patch,5875# diverging from the git-format-patch default.5876my@commit_spec= ();5877if($hash_parent) {5878if($patch_max>0) {5879push@commit_spec,"-$patch_max";5880}5881push@commit_spec,'-n',"$hash_parent..$hash";5882}else{5883if($params{-single}) {5884push@commit_spec,'-1';5885}else{5886if($patch_max>0) {5887push@commit_spec,"-$patch_max";5888}5889push@commit_spec,"-n";5890}5891push@commit_spec,'--root',$hash;5892}5893open$fd,"-|", git_cmd(),"format-patch",'--encoding=utf8',5894'--stdout',@commit_spec5895or die_error(500,"Open git-format-patch failed");5896}else{5897 die_error(400,"Unknown commitdiff format");5898}58995900# non-textual hash id's can be cached5901my$expires;5902if($hash=~m/^[0-9a-fA-F]{40}$/) {5903$expires="+1d";5904}59055906# write commit message5907if($formateq'html') {5908my$refs= git_get_references();5909my$ref= format_ref_marker($refs,$co{'id'});59105911 git_header_html(undef,$expires);5912 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);5913 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);5914print"<div class=\"title_text\">\n".5915"<table class=\"object_header\">\n";5916 git_print_authorship_rows(\%co);5917print"</table>".5918"</div>\n";5919print"<div class=\"page_body\">\n";5920if(@{$co{'comment'}} >1) {5921print"<div class=\"log\">\n";5922 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);5923print"</div>\n";# class="log"5924}59255926}elsif($formateq'plain') {5927my$refs= git_get_references("tags");5928my$tagname= git_get_rev_name_tags($hash);5929my$filename= basename($project) ."-$hash.patch";59305931print$cgi->header(5932-type =>'text/plain',5933-charset =>'utf-8',5934-expires =>$expires,5935-content_disposition =>'inline; filename="'."$filename".'"');5936my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5937print"From: ". to_utf8($co{'author'}) ."\n";5938print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";5939print"Subject: ". to_utf8($co{'title'}) ."\n";59405941print"X-Git-Tag:$tagname\n"if$tagname;5942print"X-Git-Url: ".$cgi->self_url() ."\n\n";59435944foreachmy$line(@{$co{'comment'}}) {5945print to_utf8($line) ."\n";5946}5947print"---\n\n";5948}elsif($formateq'patch') {5949my$filename= basename($project) ."-$hash.patch";59505951print$cgi->header(5952-type =>'text/plain',5953-charset =>'utf-8',5954-expires =>$expires,5955-content_disposition =>'inline; filename="'."$filename".'"');5956}59575958# write patch5959if($formateq'html') {5960my$use_parents= !defined$hash_parent||5961$hash_parenteq'-c'||$hash_parenteq'--cc';5962 git_difftree_body(\@difftree,$hash,5963$use_parents? @{$co{'parents'}} :$hash_parent);5964print"<br/>\n";59655966 git_patchset_body($fd, \@difftree,$hash,5967$use_parents? @{$co{'parents'}} :$hash_parent);5968close$fd;5969print"</div>\n";# class="page_body"5970 git_footer_html();59715972}elsif($formateq'plain') {5973local$/=undef;5974print<$fd>;5975close$fd5976or print"Reading git-diff-tree failed\n";5977}elsif($formateq'patch') {5978local$/=undef;5979print<$fd>;5980close$fd5981or print"Reading git-format-patch failed\n";5982}5983}59845985sub git_commitdiff_plain {5986 git_commitdiff(-format =>'plain');5987}59885989# format-patch-style patches5990sub git_patch {5991 git_commitdiff(-format =>'patch', -single =>1);5992}59935994sub git_patches {5995 git_commitdiff(-format =>'patch');5996}59975998sub git_history {5999 git_log_generic('history', \&git_history_body,6000$hash_base,$hash_parent_base,6001$file_name,$hash);6002}60036004sub git_search {6005 gitweb_check_feature('search')or die_error(403,"Search is disabled");6006if(!defined$searchtext) {6007 die_error(400,"Text field is empty");6008}6009if(!defined$hash) {6010$hash= git_get_head_hash($project);6011}6012my%co= parse_commit($hash);6013if(!%co) {6014 die_error(404,"Unknown commit object");6015}6016if(!defined$page) {6017$page=0;6018}60196020$searchtype||='commit';6021if($searchtypeeq'pickaxe') {6022# pickaxe may take all resources of your box and run for several minutes6023# with every query - so decide by yourself how public you make this feature6024 gitweb_check_feature('pickaxe')6025or die_error(403,"Pickaxe is disabled");6026}6027if($searchtypeeq'grep') {6028 gitweb_check_feature('grep')6029or die_error(403,"Grep is disabled");6030}60316032 git_header_html();60336034if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {6035my$greptype;6036if($searchtypeeq'commit') {6037$greptype="--grep=";6038}elsif($searchtypeeq'author') {6039$greptype="--author=";6040}elsif($searchtypeeq'committer') {6041$greptype="--committer=";6042}6043$greptype.=$searchtext;6044my@commitlist= parse_commits($hash,101, (100*$page),undef,6045$greptype,'--regexp-ignore-case',6046$search_use_regexp?'--extended-regexp':'--fixed-strings');60476048my$paging_nav='';6049if($page>0) {6050$paging_nav.=6051$cgi->a({-href => href(action=>"search", hash=>$hash,6052 searchtext=>$searchtext,6053 searchtype=>$searchtype)},6054"first");6055$paging_nav.=" ⋅ ".6056$cgi->a({-href => href(-replay=>1, page=>$page-1),6057-accesskey =>"p", -title =>"Alt-p"},"prev");6058}else{6059$paging_nav.="first";6060$paging_nav.=" ⋅ prev";6061}6062my$next_link='';6063if($#commitlist>=100) {6064$next_link=6065$cgi->a({-href => href(-replay=>1, page=>$page+1),6066-accesskey =>"n", -title =>"Alt-n"},"next");6067$paging_nav.=" ⋅$next_link";6068}else{6069$paging_nav.=" ⋅ next";6070}60716072if($#commitlist>=100) {6073}60746075 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);6076 git_print_header_div('commit', esc_html($co{'title'}),$hash);6077 git_search_grep_body(\@commitlist,0,99,$next_link);6078}60796080if($searchtypeeq'pickaxe') {6081 git_print_page_nav('','',$hash,$co{'tree'},$hash);6082 git_print_header_div('commit', esc_html($co{'title'}),$hash);60836084print"<table class=\"pickaxe search\">\n";6085my$alternate=1;6086local$/="\n";6087open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,6088'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",6089($search_use_regexp?'--pickaxe-regex': ());6090undef%co;6091my@files;6092while(my$line= <$fd>) {6093chomp$line;6094next unless$line;60956096my%set= parse_difftree_raw_line($line);6097if(defined$set{'commit'}) {6098# finish previous commit6099if(%co) {6100print"</td>\n".6101"<td class=\"link\">".6102$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6103" | ".6104$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6105print"</td>\n".6106"</tr>\n";6107}61086109if($alternate) {6110print"<tr class=\"dark\">\n";6111}else{6112print"<tr class=\"light\">\n";6113}6114$alternate^=1;6115%co= parse_commit($set{'commit'});6116my$author= chop_and_escape_str($co{'author_name'},15,5);6117print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6118"<td><i>$author</i></td>\n".6119"<td>".6120$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6121-class=>"list subject"},6122 chop_and_escape_str($co{'title'},50) ."<br/>");6123}elsif(defined$set{'to_id'}) {6124next if($set{'to_id'} =~m/^0{40}$/);61256126print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6127 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6128-class=>"list"},6129"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6130"<br/>\n";6131}6132}6133close$fd;61346135# finish last commit (warning: repetition!)6136if(%co) {6137print"</td>\n".6138"<td class=\"link\">".6139$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6140" | ".6141$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6142print"</td>\n".6143"</tr>\n";6144}61456146print"</table>\n";6147}61486149if($searchtypeeq'grep') {6150 git_print_page_nav('','',$hash,$co{'tree'},$hash);6151 git_print_header_div('commit', esc_html($co{'title'}),$hash);61526153print"<table class=\"grep_search\">\n";6154my$alternate=1;6155my$matches=0;6156local$/="\n";6157open my$fd,"-|", git_cmd(),'grep','-n',6158$search_use_regexp? ('-E','-i') :'-F',6159$searchtext,$co{'tree'};6160my$lastfile='';6161while(my$line= <$fd>) {6162chomp$line;6163my($file,$lno,$ltext,$binary);6164last if($matches++>1000);6165if($line=~/^Binary file (.+) matches$/) {6166$file=$1;6167$binary=1;6168}else{6169(undef,$file,$lno,$ltext) =split(/:/,$line,4);6170}6171if($filene$lastfile) {6172$lastfileand print"</td></tr>\n";6173if($alternate++) {6174print"<tr class=\"dark\">\n";6175}else{6176print"<tr class=\"light\">\n";6177}6178print"<td class=\"list\">".6179$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6180 file_name=>"$file"),6181-class=>"list"}, esc_path($file));6182print"</td><td>\n";6183$lastfile=$file;6184}6185if($binary) {6186print"<div class=\"binary\">Binary file</div>\n";6187}else{6188$ltext= untabify($ltext);6189if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6190$ltext= esc_html($1, -nbsp=>1);6191$ltext.='<span class="match">';6192$ltext.= esc_html($2, -nbsp=>1);6193$ltext.='</span>';6194$ltext.= esc_html($3, -nbsp=>1);6195}else{6196$ltext= esc_html($ltext, -nbsp=>1);6197}6198print"<div class=\"pre\">".6199$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6200 file_name=>"$file").'#l'.$lno,6201-class=>"linenr"},sprintf('%4i',$lno))6202.' '.$ltext."</div>\n";6203}6204}6205if($lastfile) {6206print"</td></tr>\n";6207if($matches>1000) {6208print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6209}6210}else{6211print"<div class=\"diff nodifferences\">No matches found</div>\n";6212}6213close$fd;62146215print"</table>\n";6216}6217 git_footer_html();6218}62196220sub git_search_help {6221 git_header_html();6222 git_print_page_nav('','',$hash,$hash,$hash);6223print<<EOT;6224<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without6225regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,6226the pattern entered is recognized as the POSIX extended6227<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case6228insensitive).</p>6229<dl>6230<dt><b>commit</b></dt>6231<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>6232EOT6233my$have_grep= gitweb_check_feature('grep');6234if($have_grep) {6235print<<EOT;6236<dt><b>grep</b></dt>6237<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing6238 a different one) are searched for the given pattern. On large trees, this search can take6239a while and put some strain on the server, so please use it with some consideration. Note that6240due to git-grep peculiarity, currently if regexp mode is turned off, the matches are6241case-sensitive.</dd>6242EOT6243}6244print<<EOT;6245<dt><b>author</b></dt>6246<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>6247<dt><b>committer</b></dt>6248<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>6249EOT6250my$have_pickaxe= gitweb_check_feature('pickaxe');6251if($have_pickaxe) {6252print<<EOT;6253<dt><b>pickaxe</b></dt>6254<dd>All commits that caused the string to appear or disappear from any file (changes that6255added, removed or "modified" the string) will be listed. This search can take a while and6256takes a lot of strain on the server, so please use it wisely. Note that since you may be6257interested even in changes just changing the case as well, this search is case sensitive.</dd>6258EOT6259}6260print"</dl>\n";6261 git_footer_html();6262}62636264sub git_shortlog {6265 git_log_generic('shortlog', \&git_shortlog_body,6266$hash,$hash_parent);6267}62686269## ......................................................................6270## feeds (RSS, Atom; OPML)62716272sub git_feed {6273my$format=shift||'atom';6274my$have_blame= gitweb_check_feature('blame');62756276# Atom: http://www.atomenabled.org/developers/syndication/6277# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ6278if($formatne'rss'&&$formatne'atom') {6279 die_error(400,"Unknown web feed format");6280}62816282# log/feed of current (HEAD) branch, log of given branch, history of file/directory6283my$head=$hash||'HEAD';6284my@commitlist= parse_commits($head,150,0,$file_name);62856286my%latest_commit;6287my%latest_date;6288my$content_type="application/$format+xml";6289if(defined$cgi->http('HTTP_ACCEPT') &&6290$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {6291# browser (feed reader) prefers text/xml6292$content_type='text/xml';6293}6294if(defined($commitlist[0])) {6295%latest_commit= %{$commitlist[0]};6296my$latest_epoch=$latest_commit{'committer_epoch'};6297%latest_date= parse_date($latest_epoch);6298my$if_modified=$cgi->http('IF_MODIFIED_SINCE');6299if(defined$if_modified) {6300my$since;6301if(eval{require HTTP::Date;1; }) {6302$since= HTTP::Date::str2time($if_modified);6303}elsif(eval{require Time::ParseDate;1; }) {6304$since= Time::ParseDate::parsedate($if_modified, GMT =>1);6305}6306if(defined$since&&$latest_epoch<=$since) {6307print$cgi->header(6308-type =>$content_type,6309-charset =>'utf-8',6310-last_modified =>$latest_date{'rfc2822'},6311-status =>'304 Not Modified');6312return;6313}6314}6315print$cgi->header(6316-type =>$content_type,6317-charset =>'utf-8',6318-last_modified =>$latest_date{'rfc2822'});6319}else{6320print$cgi->header(6321-type =>$content_type,6322-charset =>'utf-8');6323}63246325# Optimization: skip generating the body if client asks only6326# for Last-Modified date.6327return if($cgi->request_method()eq'HEAD');63286329# header variables6330my$title="$site_name-$project/$action";6331my$feed_type='log';6332if(defined$hash) {6333$title.=" - '$hash'";6334$feed_type='branch log';6335if(defined$file_name) {6336$title.=" ::$file_name";6337$feed_type='history';6338}6339}elsif(defined$file_name) {6340$title.=" -$file_name";6341$feed_type='history';6342}6343$title.="$feed_type";6344my$descr= git_get_project_description($project);6345if(defined$descr) {6346$descr= esc_html($descr);6347}else{6348$descr="$project".6349($formateq'rss'?'RSS':'Atom') .6350" feed";6351}6352my$owner= git_get_project_owner($project);6353$owner= esc_html($owner);63546355#header6356my$alt_url;6357if(defined$file_name) {6358$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);6359}elsif(defined$hash) {6360$alt_url= href(-full=>1, action=>"log", hash=>$hash);6361}else{6362$alt_url= href(-full=>1, action=>"summary");6363}6364print qq!<?xml version="1.0" encoding="utf-8"?>\n!;6365if($formateq'rss') {6366print<<XML;6367<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">6368<channel>6369XML6370print"<title>$title</title>\n".6371"<link>$alt_url</link>\n".6372"<description>$descr</description>\n".6373"<language>en</language>\n".6374# project owner is responsible for 'editorial' content6375"<managingEditor>$owner</managingEditor>\n";6376if(defined$logo||defined$favicon) {6377# prefer the logo to the favicon, since RSS6378# doesn't allow both6379my$img= esc_url($logo||$favicon);6380print"<image>\n".6381"<url>$img</url>\n".6382"<title>$title</title>\n".6383"<link>$alt_url</link>\n".6384"</image>\n";6385}6386if(%latest_date) {6387print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";6388print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";6389}6390print"<generator>gitweb v.$version/$git_version</generator>\n";6391}elsif($formateq'atom') {6392print<<XML;6393<feed xmlns="http://www.w3.org/2005/Atom">6394XML6395print"<title>$title</title>\n".6396"<subtitle>$descr</subtitle>\n".6397'<link rel="alternate" type="text/html" href="'.6398$alt_url.'" />'."\n".6399'<link rel="self" type="'.$content_type.'" href="'.6400$cgi->self_url() .'" />'."\n".6401"<id>". href(-full=>1) ."</id>\n".6402# use project owner for feed author6403"<author><name>$owner</name></author>\n";6404if(defined$favicon) {6405print"<icon>". esc_url($favicon) ."</icon>\n";6406}6407if(defined$logo_url) {6408# not twice as wide as tall: 72 x 27 pixels6409print"<logo>". esc_url($logo) ."</logo>\n";6410}6411if(!%latest_date) {6412# dummy date to keep the feed valid until commits trickle in:6413print"<updated>1970-01-01T00:00:00Z</updated>\n";6414}else{6415print"<updated>$latest_date{'iso-8601'}</updated>\n";6416}6417print"<generator version='$version/$git_version'>gitweb</generator>\n";6418}64196420# contents6421for(my$i=0;$i<=$#commitlist;$i++) {6422my%co= %{$commitlist[$i]};6423my$commit=$co{'id'};6424# we read 150, we always show 30 and the ones more recent than 48 hours6425if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6426last;6427}6428my%cd= parse_date($co{'author_epoch'});64296430# get list of changed files6431open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6432$co{'parent'} ||"--root",6433$co{'id'},"--", (defined$file_name?$file_name: ())6434ornext;6435my@difftree=map{chomp;$_} <$fd>;6436close$fd6437ornext;64386439# print element (entry, item)6440my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6441if($formateq'rss') {6442print"<item>\n".6443"<title>". esc_html($co{'title'}) ."</title>\n".6444"<author>". esc_html($co{'author'}) ."</author>\n".6445"<pubDate>$cd{'rfc2822'}</pubDate>\n".6446"<guid isPermaLink=\"true\">$co_url</guid>\n".6447"<link>$co_url</link>\n".6448"<description>". esc_html($co{'title'}) ."</description>\n".6449"<content:encoded>".6450"<![CDATA[\n";6451}elsif($formateq'atom') {6452print"<entry>\n".6453"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6454"<updated>$cd{'iso-8601'}</updated>\n".6455"<author>\n".6456" <name>". esc_html($co{'author_name'}) ."</name>\n";6457if($co{'author_email'}) {6458print" <email>". esc_html($co{'author_email'}) ."</email>\n";6459}6460print"</author>\n".6461# use committer for contributor6462"<contributor>\n".6463" <name>". esc_html($co{'committer_name'}) ."</name>\n";6464if($co{'committer_email'}) {6465print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6466}6467print"</contributor>\n".6468"<published>$cd{'iso-8601'}</published>\n".6469"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6470"<id>$co_url</id>\n".6471"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6472"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6473}6474my$comment=$co{'comment'};6475print"<pre>\n";6476foreachmy$line(@$comment) {6477$line= esc_html($line);6478print"$line\n";6479}6480print"</pre><ul>\n";6481foreachmy$difftree_line(@difftree) {6482my%difftree= parse_difftree_raw_line($difftree_line);6483next if!$difftree{'from_id'};64846485my$file=$difftree{'file'} ||$difftree{'to_file'};64866487print"<li>".6488"[".6489$cgi->a({-href => href(-full=>1, action=>"blobdiff",6490 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6491 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6492 file_name=>$file, file_parent=>$difftree{'from_file'}),6493-title =>"diff"},'D');6494if($have_blame) {6495print$cgi->a({-href => href(-full=>1, action=>"blame",6496 file_name=>$file, hash_base=>$commit),6497-title =>"blame"},'B');6498}6499# if this is not a feed of a file history6500if(!defined$file_name||$file_namene$file) {6501print$cgi->a({-href => href(-full=>1, action=>"history",6502 file_name=>$file, hash=>$commit),6503-title =>"history"},'H');6504}6505$file= esc_path($file);6506print"] ".6507"$file</li>\n";6508}6509if($formateq'rss') {6510print"</ul>]]>\n".6511"</content:encoded>\n".6512"</item>\n";6513}elsif($formateq'atom') {6514print"</ul>\n</div>\n".6515"</content>\n".6516"</entry>\n";6517}6518}65196520# end of feed6521if($formateq'rss') {6522print"</channel>\n</rss>\n";6523}elsif($formateq'atom') {6524print"</feed>\n";6525}6526}65276528sub git_rss {6529 git_feed('rss');6530}65316532sub git_atom {6533 git_feed('atom');6534}65356536sub git_opml {6537my@list= git_get_projects_list();65386539print$cgi->header(6540-type =>'text/xml',6541-charset =>'utf-8',6542-content_disposition =>'inline; filename="opml.xml"');65436544print<<XML;6545<?xml version="1.0" encoding="utf-8"?>6546<opml version="1.0">6547<head>6548 <title>$site_nameOPML Export</title>6549</head>6550<body>6551<outline text="git RSS feeds">6552XML65536554foreachmy$pr(@list) {6555my%proj=%$pr;6556my$head= git_get_head_hash($proj{'path'});6557if(!defined$head) {6558next;6559}6560$git_dir="$projectroot/$proj{'path'}";6561my%co= parse_commit($head);6562if(!%co) {6563next;6564}65656566my$path= esc_html(chop_str($proj{'path'},25,5));6567my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);6568my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);6569print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";6570}6571print<<XML;6572</outline>6573</body>6574</opml>6575XML6576}