1#!/usr/bin/perl 2 3# gitweb - simple web interface to track changes in git repositories 4# 5# (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org> 6# (C) 2005, Christian Gierke 7# 8# This program is licensed under the GPLv2 9 10use strict; 11use warnings; 12use CGI qw(:standard :escapeHTML -nosticky); 13use CGI::Util qw(unescape); 14use CGI::Carp qw(fatalsToBrowser); 15use Encode; 16use Fcntl ':mode'; 17use File::Find qw(); 18use File::Basename qw(basename); 19binmode STDOUT,':utf8'; 20 21our$t0; 22if(eval{require Time::HiRes;1; }) { 23$t0= [Time::HiRes::gettimeofday()]; 24} 25our$number_of_git_cmds=0; 26 27BEGIN{ 28 CGI->compile()if$ENV{'MOD_PERL'}; 29} 30 31our$cgi= new CGI; 32our$version="++GIT_VERSION++"; 33our$my_url=$cgi->url(); 34our$my_uri=$cgi->url(-absolute =>1); 35 36# Base URL for relative URLs in gitweb ($logo, $favicon, ...), 37# needed and used only for URLs with nonempty PATH_INFO 38our$base_url=$my_url; 39 40# When the script is used as DirectoryIndex, the URL does not contain the name 41# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we 42# have to do it ourselves. We make $path_info global because it's also used 43# later on. 44# 45# Another issue with the script being the DirectoryIndex is that the resulting 46# $my_url data is not the full script URL: this is good, because we want 47# generated links to keep implying the script name if it wasn't explicitly 48# indicated in the URL we're handling, but it means that $my_url cannot be used 49# as base URL. 50# Therefore, if we needed to strip PATH_INFO, then we know that we have 51# to build the base URL ourselves: 52our$path_info=$ENV{"PATH_INFO"}; 53if($path_info) { 54if($my_url=~ s,\Q$path_info\E$,, && 55$my_uri=~ s,\Q$path_info\E$,, && 56defined$ENV{'SCRIPT_NAME'}) { 57$base_url=$cgi->url(-base =>1) .$ENV{'SCRIPT_NAME'}; 58} 59} 60 61# core git executable to use 62# this can just be "git" if your webserver has a sensible PATH 63our$GIT="++GIT_BINDIR++/git"; 64 65# absolute fs-path which will be prepended to the project path 66#our $projectroot = "/pub/scm"; 67our$projectroot="++GITWEB_PROJECTROOT++"; 68 69# fs traversing limit for getting project list 70# the number is relative to the projectroot 71our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 72 73# target of the home link on top of all pages 74our$home_link=$my_uri||"/"; 75 76# string of the home link on top of all pages 77our$home_link_str="++GITWEB_HOME_LINK_STR++"; 78 79# name of your site or organization to appear in page titles 80# replace this with something more descriptive for clearer bookmarks 81our$site_name="++GITWEB_SITENAME++" 82|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 83 84# filename of html text to include at top of each page 85our$site_header="++GITWEB_SITE_HEADER++"; 86# html text to include at home page 87our$home_text="++GITWEB_HOMETEXT++"; 88# filename of html text to include at bottom of each page 89our$site_footer="++GITWEB_SITE_FOOTER++"; 90 91# URI of stylesheets 92our@stylesheets= ("++GITWEB_CSS++"); 93# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 94our$stylesheet=undef; 95# URI of GIT logo (72x27 size) 96our$logo="++GITWEB_LOGO++"; 97# URI of GIT favicon, assumed to be image/png type 98our$favicon="++GITWEB_FAVICON++"; 99# URI of gitweb.js (JavaScript code for gitweb) 100our$javascript="++GITWEB_JS++"; 101 102# URI and label (title) of GIT logo link 103#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 104#our $logo_label = "git documentation"; 105our$logo_url="http://git-scm.com/"; 106our$logo_label="git homepage"; 107 108# source of projects list 109our$projects_list="++GITWEB_LIST++"; 110 111# the width (in characters) of the projects list "Description" column 112our$projects_list_description_width=25; 113 114# default order of projects list 115# valid values are none, project, descr, owner, and age 116our$default_projects_order="project"; 117 118# show repository only if this file exists 119# (only effective if this variable evaluates to true) 120our$export_ok="++GITWEB_EXPORT_OK++"; 121 122# show repository only if this subroutine returns true 123# when given the path to the project, for example: 124# sub { return -e "$_[0]/git-daemon-export-ok"; } 125our$export_auth_hook=undef; 126 127# only allow viewing of repositories also shown on the overview page 128our$strict_export="++GITWEB_STRICT_EXPORT++"; 129 130# list of git base URLs used for URL to where fetch project from, 131# i.e. full URL is "$git_base_url/$project" 132our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 133 134# default blob_plain mimetype and default charset for text/plain blob 135our$default_blob_plain_mimetype='text/plain'; 136our$default_text_plain_charset=undef; 137 138# file to use for guessing MIME types before trying /etc/mime.types 139# (relative to the current git repository) 140our$mimetypes_file=undef; 141 142# assume this charset if line contains non-UTF-8 characters; 143# it should be valid encoding (see Encoding::Supported(3pm) for list), 144# for which encoding all byte sequences are valid, for example 145# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 146# could be even 'utf-8' for the old behavior) 147our$fallback_encoding='latin1'; 148 149# rename detection options for git-diff and git-diff-tree 150# - default is '-M', with the cost proportional to 151# (number of removed files) * (number of new files). 152# - more costly is '-C' (which implies '-M'), with the cost proportional to 153# (number of changed files + number of removed files) * (number of new files) 154# - even more costly is '-C', '--find-copies-harder' with cost 155# (number of files in the original tree) * (number of new files) 156# - one might want to include '-B' option, e.g. '-B', '-M' 157our@diff_opts= ('-M');# taken from git_commit 158 159# Disables features that would allow repository owners to inject script into 160# the gitweb domain. 161our$prevent_xss=0; 162 163# information about snapshot formats that gitweb is capable of serving 164our%known_snapshot_formats= ( 165# name => { 166# 'display' => display name, 167# 'type' => mime type, 168# 'suffix' => filename suffix, 169# 'format' => --format for git-archive, 170# 'compressor' => [compressor command and arguments] 171# (array reference, optional) 172# 'disabled' => boolean (optional)} 173# 174'tgz'=> { 175'display'=>'tar.gz', 176'type'=>'application/x-gzip', 177'suffix'=>'.tar.gz', 178'format'=>'tar', 179'compressor'=> ['gzip']}, 180 181'tbz2'=> { 182'display'=>'tar.bz2', 183'type'=>'application/x-bzip2', 184'suffix'=>'.tar.bz2', 185'format'=>'tar', 186'compressor'=> ['bzip2']}, 187 188'txz'=> { 189'display'=>'tar.xz', 190'type'=>'application/x-xz', 191'suffix'=>'.tar.xz', 192'format'=>'tar', 193'compressor'=> ['xz'], 194'disabled'=>1}, 195 196'zip'=> { 197'display'=>'zip', 198'type'=>'application/x-zip', 199'suffix'=>'.zip', 200'format'=>'zip'}, 201); 202 203# Aliases so we understand old gitweb.snapshot values in repository 204# configuration. 205our%known_snapshot_format_aliases= ( 206'gzip'=>'tgz', 207'bzip2'=>'tbz2', 208'xz'=>'txz', 209 210# backward compatibility: legacy gitweb config support 211'x-gzip'=>undef,'gz'=>undef, 212'x-bzip2'=>undef,'bz2'=>undef, 213'x-zip'=>undef,''=>undef, 214); 215 216# Pixel sizes for icons and avatars. If the default font sizes or lineheights 217# are changed, it may be appropriate to change these values too via 218# $GITWEB_CONFIG. 219our%avatar_size= ( 220'default'=>16, 221'double'=>32 222); 223 224# You define site-wide feature defaults here; override them with 225# $GITWEB_CONFIG as necessary. 226our%feature= ( 227# feature => { 228# 'sub' => feature-sub (subroutine), 229# 'override' => allow-override (boolean), 230# 'default' => [ default options...] (array reference)} 231# 232# if feature is overridable (it means that allow-override has true value), 233# then feature-sub will be called with default options as parameters; 234# return value of feature-sub indicates if to enable specified feature 235# 236# if there is no 'sub' key (no feature-sub), then feature cannot be 237# overriden 238# 239# use gitweb_get_feature(<feature>) to retrieve the <feature> value 240# (an array) or gitweb_check_feature(<feature>) to check if <feature> 241# is enabled 242 243# Enable the 'blame' blob view, showing the last commit that modified 244# each line in the file. This can be very CPU-intensive. 245 246# To enable system wide have in $GITWEB_CONFIG 247# $feature{'blame'}{'default'} = [1]; 248# To have project specific config enable override in $GITWEB_CONFIG 249# $feature{'blame'}{'override'} = 1; 250# and in project config gitweb.blame = 0|1; 251'blame'=> { 252'sub'=>sub{ feature_bool('blame',@_) }, 253'override'=>0, 254'default'=> [0]}, 255 256# Enable the 'snapshot' link, providing a compressed archive of any 257# tree. This can potentially generate high traffic if you have large 258# project. 259 260# Value is a list of formats defined in %known_snapshot_formats that 261# you wish to offer. 262# To disable system wide have in $GITWEB_CONFIG 263# $feature{'snapshot'}{'default'} = []; 264# To have project specific config enable override in $GITWEB_CONFIG 265# $feature{'snapshot'}{'override'} = 1; 266# and in project config, a comma-separated list of formats or "none" 267# to disable. Example: gitweb.snapshot = tbz2,zip; 268'snapshot'=> { 269'sub'=> \&feature_snapshot, 270'override'=>0, 271'default'=> ['tgz']}, 272 273# Enable text search, which will list the commits which match author, 274# committer or commit text to a given string. Enabled by default. 275# Project specific override is not supported. 276'search'=> { 277'override'=>0, 278'default'=> [1]}, 279 280# Enable grep search, which will list the files in currently selected 281# tree containing the given string. Enabled by default. This can be 282# potentially CPU-intensive, of course. 283 284# To enable system wide have in $GITWEB_CONFIG 285# $feature{'grep'}{'default'} = [1]; 286# To have project specific config enable override in $GITWEB_CONFIG 287# $feature{'grep'}{'override'} = 1; 288# and in project config gitweb.grep = 0|1; 289'grep'=> { 290'sub'=>sub{ feature_bool('grep',@_) }, 291'override'=>0, 292'default'=> [1]}, 293 294# Enable the pickaxe search, which will list the commits that modified 295# a given string in a file. This can be practical and quite faster 296# alternative to 'blame', but still potentially CPU-intensive. 297 298# To enable system wide have in $GITWEB_CONFIG 299# $feature{'pickaxe'}{'default'} = [1]; 300# To have project specific config enable override in $GITWEB_CONFIG 301# $feature{'pickaxe'}{'override'} = 1; 302# and in project config gitweb.pickaxe = 0|1; 303'pickaxe'=> { 304'sub'=>sub{ feature_bool('pickaxe',@_) }, 305'override'=>0, 306'default'=> [1]}, 307 308# Enable showing size of blobs in a 'tree' view, in a separate 309# column, similar to what 'ls -l' does. This cost a bit of IO. 310 311# To disable system wide have in $GITWEB_CONFIG 312# $feature{'show-sizes'}{'default'} = [0]; 313# To have project specific config enable override in $GITWEB_CONFIG 314# $feature{'show-sizes'}{'override'} = 1; 315# and in project config gitweb.showsizes = 0|1; 316'show-sizes'=> { 317'sub'=>sub{ feature_bool('showsizes',@_) }, 318'override'=>0, 319'default'=> [1]}, 320 321# Make gitweb use an alternative format of the URLs which can be 322# more readable and natural-looking: project name is embedded 323# directly in the path and the query string contains other 324# auxiliary information. All gitweb installations recognize 325# URL in either format; this configures in which formats gitweb 326# generates links. 327 328# To enable system wide have in $GITWEB_CONFIG 329# $feature{'pathinfo'}{'default'} = [1]; 330# Project specific override is not supported. 331 332# Note that you will need to change the default location of CSS, 333# favicon, logo and possibly other files to an absolute URL. Also, 334# if gitweb.cgi serves as your indexfile, you will need to force 335# $my_uri to contain the script name in your $GITWEB_CONFIG. 336'pathinfo'=> { 337'override'=>0, 338'default'=> [0]}, 339 340# Make gitweb consider projects in project root subdirectories 341# to be forks of existing projects. Given project $projname.git, 342# projects matching $projname/*.git will not be shown in the main 343# projects list, instead a '+' mark will be added to $projname 344# there and a 'forks' view will be enabled for the project, listing 345# all the forks. If project list is taken from a file, forks have 346# to be listed after the main project. 347 348# To enable system wide have in $GITWEB_CONFIG 349# $feature{'forks'}{'default'} = [1]; 350# Project specific override is not supported. 351'forks'=> { 352'override'=>0, 353'default'=> [0]}, 354 355# Insert custom links to the action bar of all project pages. 356# This enables you mainly to link to third-party scripts integrating 357# into gitweb; e.g. git-browser for graphical history representation 358# or custom web-based repository administration interface. 359 360# The 'default' value consists of a list of triplets in the form 361# (label, link, position) where position is the label after which 362# to insert the link and link is a format string where %n expands 363# to the project name, %f to the project path within the filesystem, 364# %h to the current hash (h gitweb parameter) and %b to the current 365# hash base (hb gitweb parameter); %% expands to %. 366 367# To enable system wide have in $GITWEB_CONFIG e.g. 368# $feature{'actions'}{'default'} = [('graphiclog', 369# '/git-browser/by-commit.html?r=%n', 'summary')]; 370# Project specific override is not supported. 371'actions'=> { 372'override'=>0, 373'default'=> []}, 374 375# Allow gitweb scan project content tags described in ctags/ 376# of project repository, and display the popular Web 2.0-ish 377# "tag cloud" near the project list. Note that this is something 378# COMPLETELY different from the normal Git tags. 379 380# gitweb by itself can show existing tags, but it does not handle 381# tagging itself; you need an external application for that. 382# For an example script, check Girocco's cgi/tagproj.cgi. 383# You may want to install the HTML::TagCloud Perl module to get 384# a pretty tag cloud instead of just a list of tags. 385 386# To enable system wide have in $GITWEB_CONFIG 387# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 388# Project specific override is not supported. 389'ctags'=> { 390'override'=>0, 391'default'=> [0]}, 392 393# The maximum number of patches in a patchset generated in patch 394# view. Set this to 0 or undef to disable patch view, or to a 395# negative number to remove any limit. 396 397# To disable system wide have in $GITWEB_CONFIG 398# $feature{'patches'}{'default'} = [0]; 399# To have project specific config enable override in $GITWEB_CONFIG 400# $feature{'patches'}{'override'} = 1; 401# and in project config gitweb.patches = 0|n; 402# where n is the maximum number of patches allowed in a patchset. 403'patches'=> { 404'sub'=> \&feature_patches, 405'override'=>0, 406'default'=> [16]}, 407 408# Avatar support. When this feature is enabled, views such as 409# shortlog or commit will display an avatar associated with 410# the email of the committer(s) and/or author(s). 411 412# Currently available providers are gravatar and picon. 413# If an unknown provider is specified, the feature is disabled. 414 415# Gravatar depends on Digest::MD5. 416# Picon currently relies on the indiana.edu database. 417 418# To enable system wide have in $GITWEB_CONFIG 419# $feature{'avatar'}{'default'} = ['<provider>']; 420# where <provider> is either gravatar or picon. 421# To have project specific config enable override in $GITWEB_CONFIG 422# $feature{'avatar'}{'override'} = 1; 423# and in project config gitweb.avatar = <provider>; 424'avatar'=> { 425'sub'=> \&feature_avatar, 426'override'=>0, 427'default'=> ['']}, 428 429# Enable displaying how much time and how many git commands 430# it took to generate and display page. Disabled by default. 431# Project specific override is not supported. 432'timed'=> { 433'override'=>0, 434'default'=> [0]}, 435 436# Enable turning some links into links to actions which require 437# JavaScript to run (like 'blame_incremental'). Not enabled by 438# default. Project specific override is currently not supported. 439'javascript-actions'=> { 440'override'=>0, 441'default'=> [0]}, 442); 443 444sub gitweb_get_feature { 445my($name) =@_; 446return unlessexists$feature{$name}; 447my($sub,$override,@defaults) = ( 448$feature{$name}{'sub'}, 449$feature{$name}{'override'}, 450@{$feature{$name}{'default'}}); 451if(!$override) {return@defaults; } 452if(!defined$sub) { 453warn"feature$nameis not overridable"; 454return@defaults; 455} 456return$sub->(@defaults); 457} 458 459# A wrapper to check if a given feature is enabled. 460# With this, you can say 461# 462# my $bool_feat = gitweb_check_feature('bool_feat'); 463# gitweb_check_feature('bool_feat') or somecode; 464# 465# instead of 466# 467# my ($bool_feat) = gitweb_get_feature('bool_feat'); 468# (gitweb_get_feature('bool_feat'))[0] or somecode; 469# 470sub gitweb_check_feature { 471return(gitweb_get_feature(@_))[0]; 472} 473 474 475sub feature_bool { 476my$key=shift; 477my($val) = git_get_project_config($key,'--bool'); 478 479if(!defined$val) { 480return($_[0]); 481}elsif($valeq'true') { 482return(1); 483}elsif($valeq'false') { 484return(0); 485} 486} 487 488sub feature_snapshot { 489my(@fmts) =@_; 490 491my($val) = git_get_project_config('snapshot'); 492 493if($val) { 494@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 495} 496 497return@fmts; 498} 499 500sub feature_patches { 501my@val= (git_get_project_config('patches','--int')); 502 503if(@val) { 504return@val; 505} 506 507return($_[0]); 508} 509 510sub feature_avatar { 511my@val= (git_get_project_config('avatar')); 512 513return@val?@val:@_; 514} 515 516# checking HEAD file with -e is fragile if the repository was 517# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 518# and then pruned. 519sub check_head_link { 520my($dir) =@_; 521my$headfile="$dir/HEAD"; 522return((-e $headfile) || 523(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 524} 525 526sub check_export_ok { 527my($dir) =@_; 528return(check_head_link($dir) && 529(!$export_ok|| -e "$dir/$export_ok") && 530(!$export_auth_hook||$export_auth_hook->($dir))); 531} 532 533# process alternate names for backward compatibility 534# filter out unsupported (unknown) snapshot formats 535sub filter_snapshot_fmts { 536my@fmts=@_; 537 538@fmts=map{ 539exists$known_snapshot_format_aliases{$_} ? 540$known_snapshot_format_aliases{$_} :$_}@fmts; 541@fmts=grep{ 542exists$known_snapshot_formats{$_} && 543!$known_snapshot_formats{$_}{'disabled'}}@fmts; 544} 545 546our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 547if(-e $GITWEB_CONFIG) { 548do$GITWEB_CONFIG; 549}else{ 550our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 551do$GITWEB_CONFIG_SYSTEMif-e $GITWEB_CONFIG_SYSTEM; 552} 553 554# version of the core git binary 555our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 556$number_of_git_cmds++; 557 558$projects_list||=$projectroot; 559 560# ====================================================================== 561# input validation and dispatch 562 563# input parameters can be collected from a variety of sources (presently, CGI 564# and PATH_INFO), so we define an %input_params hash that collects them all 565# together during validation: this allows subsequent uses (e.g. href()) to be 566# agnostic of the parameter origin 567 568our%input_params= (); 569 570# input parameters are stored with the long parameter name as key. This will 571# also be used in the href subroutine to convert parameters to their CGI 572# equivalent, and since the href() usage is the most frequent one, we store 573# the name -> CGI key mapping here, instead of the reverse. 574# 575# XXX: Warning: If you touch this, check the search form for updating, 576# too. 577 578our@cgi_param_mapping= ( 579 project =>"p", 580 action =>"a", 581 file_name =>"f", 582 file_parent =>"fp", 583 hash =>"h", 584 hash_parent =>"hp", 585 hash_base =>"hb", 586 hash_parent_base =>"hpb", 587 page =>"pg", 588 order =>"o", 589 searchtext =>"s", 590 searchtype =>"st", 591 snapshot_format =>"sf", 592 extra_options =>"opt", 593 search_use_regexp =>"sr", 594# this must be last entry (for manipulation from JavaScript) 595 javascript =>"js" 596); 597our%cgi_param_mapping=@cgi_param_mapping; 598 599# we will also need to know the possible actions, for validation 600our%actions= ( 601"blame"=> \&git_blame, 602"blame_incremental"=> \&git_blame_incremental, 603"blame_data"=> \&git_blame_data, 604"blobdiff"=> \&git_blobdiff, 605"blobdiff_plain"=> \&git_blobdiff_plain, 606"blob"=> \&git_blob, 607"blob_plain"=> \&git_blob_plain, 608"commitdiff"=> \&git_commitdiff, 609"commitdiff_plain"=> \&git_commitdiff_plain, 610"commit"=> \&git_commit, 611"forks"=> \&git_forks, 612"heads"=> \&git_heads, 613"history"=> \&git_history, 614"log"=> \&git_log, 615"patch"=> \&git_patch, 616"patches"=> \&git_patches, 617"rss"=> \&git_rss, 618"atom"=> \&git_atom, 619"search"=> \&git_search, 620"search_help"=> \&git_search_help, 621"shortlog"=> \&git_shortlog, 622"summary"=> \&git_summary, 623"tag"=> \&git_tag, 624"tags"=> \&git_tags, 625"tree"=> \&git_tree, 626"snapshot"=> \&git_snapshot, 627"object"=> \&git_object, 628# those below don't need $project 629"opml"=> \&git_opml, 630"project_list"=> \&git_project_list, 631"project_index"=> \&git_project_index, 632); 633 634# finally, we have the hash of allowed extra_options for the commands that 635# allow them 636our%allowed_options= ( 637"--no-merges"=> [qw(rss atom log shortlog history)], 638); 639 640# fill %input_params with the CGI parameters. All values except for 'opt' 641# should be single values, but opt can be an array. We should probably 642# build an array of parameters that can be multi-valued, but since for the time 643# being it's only this one, we just single it out 644while(my($name,$symbol) =each%cgi_param_mapping) { 645if($symboleq'opt') { 646$input_params{$name} = [$cgi->param($symbol) ]; 647}else{ 648$input_params{$name} =$cgi->param($symbol); 649} 650} 651 652# now read PATH_INFO and update the parameter list for missing parameters 653sub evaluate_path_info { 654return ifdefined$input_params{'project'}; 655return if!$path_info; 656$path_info=~ s,^/+,,; 657return if!$path_info; 658 659# find which part of PATH_INFO is project 660my$project=$path_info; 661$project=~ s,/+$,,; 662while($project&& !check_head_link("$projectroot/$project")) { 663$project=~ s,/*[^/]*$,,; 664} 665return unless$project; 666$input_params{'project'} =$project; 667 668# do not change any parameters if an action is given using the query string 669return if$input_params{'action'}; 670$path_info=~ s,^\Q$project\E/*,,; 671 672# next, check if we have an action 673my$action=$path_info; 674$action=~ s,/.*$,,; 675if(exists$actions{$action}) { 676$path_info=~ s,^$action/*,,; 677$input_params{'action'} =$action; 678} 679 680# list of actions that want hash_base instead of hash, but can have no 681# pathname (f) parameter 682my@wants_base= ( 683'tree', 684'history', 685); 686 687# we want to catch 688# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 689my($parentrefname,$parentpathname,$refname,$pathname) = 690($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/); 691 692# first, analyze the 'current' part 693if(defined$pathname) { 694# we got "branch:filename" or "branch:dir/" 695# we could use git_get_type(branch:pathname), but: 696# - it needs $git_dir 697# - it does a git() call 698# - the convention of terminating directories with a slash 699# makes it superfluous 700# - embedding the action in the PATH_INFO would make it even 701# more superfluous 702$pathname=~ s,^/+,,; 703if(!$pathname||substr($pathname, -1)eq"/") { 704$input_params{'action'} ||="tree"; 705$pathname=~ s,/$,,; 706}else{ 707# the default action depends on whether we had parent info 708# or not 709if($parentrefname) { 710$input_params{'action'} ||="blobdiff_plain"; 711}else{ 712$input_params{'action'} ||="blob_plain"; 713} 714} 715$input_params{'hash_base'} ||=$refname; 716$input_params{'file_name'} ||=$pathname; 717}elsif(defined$refname) { 718# we got "branch". In this case we have to choose if we have to 719# set hash or hash_base. 720# 721# Most of the actions without a pathname only want hash to be 722# set, except for the ones specified in @wants_base that want 723# hash_base instead. It should also be noted that hand-crafted 724# links having 'history' as an action and no pathname or hash 725# set will fail, but that happens regardless of PATH_INFO. 726$input_params{'action'} ||="shortlog"; 727if(grep{$_eq$input_params{'action'} }@wants_base) { 728$input_params{'hash_base'} ||=$refname; 729}else{ 730$input_params{'hash'} ||=$refname; 731} 732} 733 734# next, handle the 'parent' part, if present 735if(defined$parentrefname) { 736# a missing pathspec defaults to the 'current' filename, allowing e.g. 737# someproject/blobdiff/oldrev..newrev:/filename 738if($parentpathname) { 739$parentpathname=~ s,^/+,,; 740$parentpathname=~ s,/$,,; 741$input_params{'file_parent'} ||=$parentpathname; 742}else{ 743$input_params{'file_parent'} ||=$input_params{'file_name'}; 744} 745# we assume that hash_parent_base is wanted if a path was specified, 746# or if the action wants hash_base instead of hash 747if(defined$input_params{'file_parent'} || 748grep{$_eq$input_params{'action'} }@wants_base) { 749$input_params{'hash_parent_base'} ||=$parentrefname; 750}else{ 751$input_params{'hash_parent'} ||=$parentrefname; 752} 753} 754 755# for the snapshot action, we allow URLs in the form 756# $project/snapshot/$hash.ext 757# where .ext determines the snapshot and gets removed from the 758# passed $refname to provide the $hash. 759# 760# To be able to tell that $refname includes the format extension, we 761# require the following two conditions to be satisfied: 762# - the hash input parameter MUST have been set from the $refname part 763# of the URL (i.e. they must be equal) 764# - the snapshot format MUST NOT have been defined already (e.g. from 765# CGI parameter sf) 766# It's also useless to try any matching unless $refname has a dot, 767# so we check for that too 768if(defined$input_params{'action'} && 769$input_params{'action'}eq'snapshot'&& 770defined$refname&&index($refname,'.') != -1&& 771$refnameeq$input_params{'hash'} && 772!defined$input_params{'snapshot_format'}) { 773# We loop over the known snapshot formats, checking for 774# extensions. Allowed extensions are both the defined suffix 775# (which includes the initial dot already) and the snapshot 776# format key itself, with a prepended dot 777while(my($fmt,$opt) =each%known_snapshot_formats) { 778my$hash=$refname; 779unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 780next; 781} 782my$sfx=$1; 783# a valid suffix was found, so set the snapshot format 784# and reset the hash parameter 785$input_params{'snapshot_format'} =$fmt; 786$input_params{'hash'} =$hash; 787# we also set the format suffix to the one requested 788# in the URL: this way a request for e.g. .tgz returns 789# a .tgz instead of a .tar.gz 790$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 791last; 792} 793} 794} 795evaluate_path_info(); 796 797our$action=$input_params{'action'}; 798if(defined$action) { 799if(!validate_action($action)) { 800 die_error(400,"Invalid action parameter"); 801} 802} 803 804# parameters which are pathnames 805our$project=$input_params{'project'}; 806if(defined$project) { 807if(!validate_project($project)) { 808undef$project; 809 die_error(404,"No such project"); 810} 811} 812 813our$file_name=$input_params{'file_name'}; 814if(defined$file_name) { 815if(!validate_pathname($file_name)) { 816 die_error(400,"Invalid file parameter"); 817} 818} 819 820our$file_parent=$input_params{'file_parent'}; 821if(defined$file_parent) { 822if(!validate_pathname($file_parent)) { 823 die_error(400,"Invalid file parent parameter"); 824} 825} 826 827# parameters which are refnames 828our$hash=$input_params{'hash'}; 829if(defined$hash) { 830if(!validate_refname($hash)) { 831 die_error(400,"Invalid hash parameter"); 832} 833} 834 835our$hash_parent=$input_params{'hash_parent'}; 836if(defined$hash_parent) { 837if(!validate_refname($hash_parent)) { 838 die_error(400,"Invalid hash parent parameter"); 839} 840} 841 842our$hash_base=$input_params{'hash_base'}; 843if(defined$hash_base) { 844if(!validate_refname($hash_base)) { 845 die_error(400,"Invalid hash base parameter"); 846} 847} 848 849our@extra_options= @{$input_params{'extra_options'}}; 850# @extra_options is always defined, since it can only be (currently) set from 851# CGI, and $cgi->param() returns the empty array in array context if the param 852# is not set 853foreachmy$opt(@extra_options) { 854if(not exists$allowed_options{$opt}) { 855 die_error(400,"Invalid option parameter"); 856} 857if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 858 die_error(400,"Invalid option parameter for this action"); 859} 860} 861 862our$hash_parent_base=$input_params{'hash_parent_base'}; 863if(defined$hash_parent_base) { 864if(!validate_refname($hash_parent_base)) { 865 die_error(400,"Invalid hash parent base parameter"); 866} 867} 868 869# other parameters 870our$page=$input_params{'page'}; 871if(defined$page) { 872if($page=~m/[^0-9]/) { 873 die_error(400,"Invalid page parameter"); 874} 875} 876 877our$searchtype=$input_params{'searchtype'}; 878if(defined$searchtype) { 879if($searchtype=~m/[^a-z]/) { 880 die_error(400,"Invalid searchtype parameter"); 881} 882} 883 884our$search_use_regexp=$input_params{'search_use_regexp'}; 885 886our$searchtext=$input_params{'searchtext'}; 887our$search_regexp; 888if(defined$searchtext) { 889if(length($searchtext) <2) { 890 die_error(403,"At least two characters are required for search parameter"); 891} 892$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 893} 894 895# path to the current git repository 896our$git_dir; 897$git_dir="$projectroot/$project"if$project; 898 899# list of supported snapshot formats 900our@snapshot_fmts= gitweb_get_feature('snapshot'); 901@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts); 902 903# check that the avatar feature is set to a known provider name, 904# and for each provider check if the dependencies are satisfied. 905# if the provider name is invalid or the dependencies are not met, 906# reset $git_avatar to the empty string. 907our($git_avatar) = gitweb_get_feature('avatar'); 908if($git_avatareq'gravatar') { 909$git_avatar=''unless(eval{require Digest::MD5;1; }); 910}elsif($git_avatareq'picon') { 911# no dependencies 912}else{ 913$git_avatar=''; 914} 915 916# dispatch 917if(!defined$action) { 918if(defined$hash) { 919$action= git_get_type($hash); 920}elsif(defined$hash_base&&defined$file_name) { 921$action= git_get_type("$hash_base:$file_name"); 922}elsif(defined$project) { 923$action='summary'; 924}else{ 925$action='project_list'; 926} 927} 928if(!defined($actions{$action})) { 929 die_error(400,"Unknown action"); 930} 931if($action!~m/^(?:opml|project_list|project_index)$/&& 932!$project) { 933 die_error(400,"Project needed"); 934} 935$actions{$action}->(); 936exit; 937 938## ====================================================================== 939## action links 940 941sub href { 942my%params=@_; 943# default is to use -absolute url() i.e. $my_uri 944my$href=$params{-full} ?$my_url:$my_uri; 945 946$params{'project'} =$projectunlessexists$params{'project'}; 947 948if($params{-replay}) { 949while(my($name,$symbol) =each%cgi_param_mapping) { 950if(!exists$params{$name}) { 951$params{$name} =$input_params{$name}; 952} 953} 954} 955 956my$use_pathinfo= gitweb_check_feature('pathinfo'); 957if($use_pathinfoand defined$params{'project'}) { 958# try to put as many parameters as possible in PATH_INFO: 959# - project name 960# - action 961# - hash_parent or hash_parent_base:/file_parent 962# - hash or hash_base:/filename 963# - the snapshot_format as an appropriate suffix 964 965# When the script is the root DirectoryIndex for the domain, 966# $href here would be something like http://gitweb.example.com/ 967# Thus, we strip any trailing / from $href, to spare us double 968# slashes in the final URL 969$href=~ s,/$,,; 970 971# Then add the project name, if present 972$href.="/".esc_url($params{'project'}); 973delete$params{'project'}; 974 975# since we destructively absorb parameters, we keep this 976# boolean that remembers if we're handling a snapshot 977my$is_snapshot=$params{'action'}eq'snapshot'; 978 979# Summary just uses the project path URL, any other action is 980# added to the URL 981if(defined$params{'action'}) { 982$href.="/".esc_url($params{'action'})unless$params{'action'}eq'summary'; 983delete$params{'action'}; 984} 985 986# Next, we put hash_parent_base:/file_parent..hash_base:/file_name, 987# stripping nonexistent or useless pieces 988$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'} 989||$params{'hash_parent'} ||$params{'hash'}); 990if(defined$params{'hash_base'}) { 991if(defined$params{'hash_parent_base'}) { 992$href.= esc_url($params{'hash_parent_base'}); 993# skip the file_parent if it's the same as the file_name 994if(defined$params{'file_parent'}) { 995if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) { 996delete$params{'file_parent'}; 997}elsif($params{'file_parent'} !~/\.\./) { 998$href.=":/".esc_url($params{'file_parent'}); 999delete$params{'file_parent'};1000}1001}1002$href.="..";1003delete$params{'hash_parent'};1004delete$params{'hash_parent_base'};1005}elsif(defined$params{'hash_parent'}) {1006$href.= esc_url($params{'hash_parent'})."..";1007delete$params{'hash_parent'};1008}10091010$href.= esc_url($params{'hash_base'});1011if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) {1012$href.=":/".esc_url($params{'file_name'});1013delete$params{'file_name'};1014}1015delete$params{'hash'};1016delete$params{'hash_base'};1017}elsif(defined$params{'hash'}) {1018$href.= esc_url($params{'hash'});1019delete$params{'hash'};1020}10211022# If the action was a snapshot, we can absorb the1023# snapshot_format parameter too1024if($is_snapshot) {1025my$fmt=$params{'snapshot_format'};1026# snapshot_format should always be defined when href()1027# is called, but just in case some code forgets, we1028# fall back to the default1029$fmt||=$snapshot_fmts[0];1030$href.=$known_snapshot_formats{$fmt}{'suffix'};1031delete$params{'snapshot_format'};1032}1033}10341035# now encode the parameters explicitly1036my@result= ();1037for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1038my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1039if(defined$params{$name}) {1040if(ref($params{$name})eq"ARRAY") {1041foreachmy$par(@{$params{$name}}) {1042push@result,$symbol."=". esc_param($par);1043}1044}else{1045push@result,$symbol."=". esc_param($params{$name});1046}1047}1048}1049$href.="?".join(';',@result)ifscalar@result;10501051return$href;1052}105310541055## ======================================================================1056## validation, quoting/unquoting and escaping10571058sub validate_action {1059my$input=shift||returnundef;1060returnundefunlessexists$actions{$input};1061return$input;1062}10631064sub validate_project {1065my$input=shift||returnundef;1066if(!validate_pathname($input) ||1067!(-d "$projectroot/$input") ||1068!check_export_ok("$projectroot/$input") ||1069($strict_export&& !project_in_list($input))) {1070returnundef;1071}else{1072return$input;1073}1074}10751076sub validate_pathname {1077my$input=shift||returnundef;10781079# no '.' or '..' as elements of path, i.e. no '.' nor '..'1080# at the beginning, at the end, and between slashes.1081# also this catches doubled slashes1082if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1083returnundef;1084}1085# no null characters1086if($input=~m!\0!) {1087returnundef;1088}1089return$input;1090}10911092sub validate_refname {1093my$input=shift||returnundef;10941095# textual hashes are O.K.1096if($input=~m/^[0-9a-fA-F]{40}$/) {1097return$input;1098}1099# it must be correct pathname1100$input= validate_pathname($input)1101orreturnundef;1102# restrictions on ref name according to git-check-ref-format1103if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1104returnundef;1105}1106return$input;1107}11081109# decode sequences of octets in utf8 into Perl's internal form,1110# which is utf-8 with utf8 flag set if needed. gitweb writes out1111# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1112sub to_utf8 {1113my$str=shift;1114if(utf8::valid($str)) {1115 utf8::decode($str);1116return$str;1117}else{1118return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1119}1120}11211122# quote unsafe chars, but keep the slash, even when it's not1123# correct, but quoted slashes look too horrible in bookmarks1124sub esc_param {1125my$str=shift;1126$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1127$str=~s/ /\+/g;1128return$str;1129}11301131# quote unsafe chars in whole URL, so some charactrs cannot be quoted1132sub esc_url {1133my$str=shift;1134$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X",ord($1))/eg;1135$str=~s/\+/%2B/g;1136$str=~s/ /\+/g;1137return$str;1138}11391140# quote unsafe characters in HTML attributes1141sub esc_attr {11421143# for XHTML conformance escaping '"' to '"' is not enough1144return esc_html(@_);1145}11461147# replace invalid utf8 character with SUBSTITUTION sequence1148sub esc_html {1149my$str=shift;1150my%opts=@_;11511152$str= to_utf8($str);1153$str=$cgi->escapeHTML($str);1154if($opts{'-nbsp'}) {1155$str=~s/ / /g;1156}1157$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1158return$str;1159}11601161# quote control characters and escape filename to HTML1162sub esc_path {1163my$str=shift;1164my%opts=@_;11651166$str= to_utf8($str);1167$str=$cgi->escapeHTML($str);1168if($opts{'-nbsp'}) {1169$str=~s/ / /g;1170}1171$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1172return$str;1173}11741175# Make control characters "printable", using character escape codes (CEC)1176sub quot_cec {1177my$cntrl=shift;1178my%opts=@_;1179my%es= (# character escape codes, aka escape sequences1180"\t"=>'\t',# tab (HT)1181"\n"=>'\n',# line feed (LF)1182"\r"=>'\r',# carrige return (CR)1183"\f"=>'\f',# form feed (FF)1184"\b"=>'\b',# backspace (BS)1185"\a"=>'\a',# alarm (bell) (BEL)1186"\e"=>'\e',# escape (ESC)1187"\013"=>'\v',# vertical tab (VT)1188"\000"=>'\0',# nul character (NUL)1189);1190my$chr= ( (exists$es{$cntrl})1191?$es{$cntrl}1192:sprintf('\%2x',ord($cntrl)) );1193if($opts{-nohtml}) {1194return$chr;1195}else{1196return"<span class=\"cntrl\">$chr</span>";1197}1198}11991200# Alternatively use unicode control pictures codepoints,1201# Unicode "printable representation" (PR)1202sub quot_upr {1203my$cntrl=shift;1204my%opts=@_;12051206my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1207if($opts{-nohtml}) {1208return$chr;1209}else{1210return"<span class=\"cntrl\">$chr</span>";1211}1212}12131214# git may return quoted and escaped filenames1215sub unquote {1216my$str=shift;12171218sub unq {1219my$seq=shift;1220my%es= (# character escape codes, aka escape sequences1221't'=>"\t",# tab (HT, TAB)1222'n'=>"\n",# newline (NL)1223'r'=>"\r",# return (CR)1224'f'=>"\f",# form feed (FF)1225'b'=>"\b",# backspace (BS)1226'a'=>"\a",# alarm (bell) (BEL)1227'e'=>"\e",# escape (ESC)1228'v'=>"\013",# vertical tab (VT)1229);12301231if($seq=~m/^[0-7]{1,3}$/) {1232# octal char sequence1233returnchr(oct($seq));1234}elsif(exists$es{$seq}) {1235# C escape sequence, aka character escape code1236return$es{$seq};1237}1238# quoted ordinary character1239return$seq;1240}12411242if($str=~m/^"(.*)"$/) {1243# needs unquoting1244$str=$1;1245$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1246}1247return$str;1248}12491250# escape tabs (convert tabs to spaces)1251sub untabify {1252my$line=shift;12531254while((my$pos=index($line,"\t")) != -1) {1255if(my$count= (8- ($pos%8))) {1256my$spaces=' ' x $count;1257$line=~s/\t/$spaces/;1258}1259}12601261return$line;1262}12631264sub project_in_list {1265my$project=shift;1266my@list= git_get_projects_list();1267return@list&&scalar(grep{$_->{'path'}eq$project}@list);1268}12691270## ----------------------------------------------------------------------1271## HTML aware string manipulation12721273# Try to chop given string on a word boundary between position1274# $len and $len+$add_len. If there is no word boundary there,1275# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1276# (marking chopped part) would be longer than given string.1277sub chop_str {1278my$str=shift;1279my$len=shift;1280my$add_len=shift||10;1281my$where=shift||'right';# 'left' | 'center' | 'right'12821283# Make sure perl knows it is utf8 encoded so we don't1284# cut in the middle of a utf8 multibyte char.1285$str= to_utf8($str);12861287# allow only $len chars, but don't cut a word if it would fit in $add_len1288# if it doesn't fit, cut it if it's still longer than the dots we would add1289# remove chopped character entities entirely12901291# when chopping in the middle, distribute $len into left and right part1292# return early if chopping wouldn't make string shorter1293if($whereeq'center') {1294return$strif($len+5>=length($str));# filler is length 51295$len=int($len/2);1296}else{1297return$strif($len+4>=length($str));# filler is length 41298}12991300# regexps: ending and beginning with word part up to $add_len1301my$endre=qr/.{$len}\w{0,$add_len}/;1302my$begre=qr/\w{0,$add_len}.{$len}/;13031304if($whereeq'left') {1305$str=~m/^(.*?)($begre)$/;1306my($lead,$body) = ($1,$2);1307if(length($lead) >4) {1308$body=~s/^[^;]*;//if($lead=~m/&[^;]*$/);1309$lead=" ...";1310}1311return"$lead$body";13121313}elsif($whereeq'center') {1314$str=~m/^($endre)(.*)$/;1315my($left,$str) = ($1,$2);1316$str=~m/^(.*?)($begre)$/;1317my($mid,$right) = ($1,$2);1318if(length($mid) >5) {1319$left=~s/&[^;]*$//;1320$right=~s/^[^;]*;//if($mid=~m/&[^;]*$/);1321$mid=" ... ";1322}1323return"$left$mid$right";13241325}else{1326$str=~m/^($endre)(.*)$/;1327my$body=$1;1328my$tail=$2;1329if(length($tail) >4) {1330$body=~s/&[^;]*$//;1331$tail="... ";1332}1333return"$body$tail";1334}1335}13361337# takes the same arguments as chop_str, but also wraps a <span> around the1338# result with a title attribute if it does get chopped. Additionally, the1339# string is HTML-escaped.1340sub chop_and_escape_str {1341my($str) =@_;13421343my$chopped= chop_str(@_);1344if($choppedeq$str) {1345return esc_html($chopped);1346}else{1347$str=~s/[[:cntrl:]]/?/g;1348return$cgi->span({-title=>$str}, esc_html($chopped));1349}1350}13511352## ----------------------------------------------------------------------1353## functions returning short strings13541355# CSS class for given age value (in seconds)1356sub age_class {1357my$age=shift;13581359if(!defined$age) {1360return"noage";1361}elsif($age<60*60*2) {1362return"age0";1363}elsif($age<60*60*24*2) {1364return"age1";1365}else{1366return"age2";1367}1368}13691370# convert age in seconds to "nn units ago" string1371sub age_string {1372my$age=shift;1373my$age_str;13741375if($age>60*60*24*365*2) {1376$age_str= (int$age/60/60/24/365);1377$age_str.=" years ago";1378}elsif($age>60*60*24*(365/12)*2) {1379$age_str=int$age/60/60/24/(365/12);1380$age_str.=" months ago";1381}elsif($age>60*60*24*7*2) {1382$age_str=int$age/60/60/24/7;1383$age_str.=" weeks ago";1384}elsif($age>60*60*24*2) {1385$age_str=int$age/60/60/24;1386$age_str.=" days ago";1387}elsif($age>60*60*2) {1388$age_str=int$age/60/60;1389$age_str.=" hours ago";1390}elsif($age>60*2) {1391$age_str=int$age/60;1392$age_str.=" min ago";1393}elsif($age>2) {1394$age_str=int$age;1395$age_str.=" sec ago";1396}else{1397$age_str.=" right now";1398}1399return$age_str;1400}14011402useconstant{1403 S_IFINVALID =>0030000,1404 S_IFGITLINK =>0160000,1405};14061407# submodule/subproject, a commit object reference1408sub S_ISGITLINK {1409my$mode=shift;14101411return(($mode& S_IFMT) == S_IFGITLINK)1412}14131414# convert file mode in octal to symbolic file mode string1415sub mode_str {1416my$mode=oct shift;14171418if(S_ISGITLINK($mode)) {1419return'm---------';1420}elsif(S_ISDIR($mode& S_IFMT)) {1421return'drwxr-xr-x';1422}elsif(S_ISLNK($mode)) {1423return'lrwxrwxrwx';1424}elsif(S_ISREG($mode)) {1425# git cares only about the executable bit1426if($mode& S_IXUSR) {1427return'-rwxr-xr-x';1428}else{1429return'-rw-r--r--';1430};1431}else{1432return'----------';1433}1434}14351436# convert file mode in octal to file type string1437sub file_type {1438my$mode=shift;14391440if($mode!~m/^[0-7]+$/) {1441return$mode;1442}else{1443$mode=oct$mode;1444}14451446if(S_ISGITLINK($mode)) {1447return"submodule";1448}elsif(S_ISDIR($mode& S_IFMT)) {1449return"directory";1450}elsif(S_ISLNK($mode)) {1451return"symlink";1452}elsif(S_ISREG($mode)) {1453return"file";1454}else{1455return"unknown";1456}1457}14581459# convert file mode in octal to file type description string1460sub file_type_long {1461my$mode=shift;14621463if($mode!~m/^[0-7]+$/) {1464return$mode;1465}else{1466$mode=oct$mode;1467}14681469if(S_ISGITLINK($mode)) {1470return"submodule";1471}elsif(S_ISDIR($mode& S_IFMT)) {1472return"directory";1473}elsif(S_ISLNK($mode)) {1474return"symlink";1475}elsif(S_ISREG($mode)) {1476if($mode& S_IXUSR) {1477return"executable";1478}else{1479return"file";1480};1481}else{1482return"unknown";1483}1484}148514861487## ----------------------------------------------------------------------1488## functions returning short HTML fragments, or transforming HTML fragments1489## which don't belong to other sections14901491# format line of commit message.1492sub format_log_line_html {1493my$line=shift;14941495$line= esc_html($line, -nbsp=>1);1496$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1497$cgi->a({-href => href(action=>"object", hash=>$1),1498-class=>"text"},$1);1499}eg;15001501return$line;1502}15031504# format marker of refs pointing to given object15051506# the destination action is chosen based on object type and current context:1507# - for annotated tags, we choose the tag view unless it's the current view1508# already, in which case we go to shortlog view1509# - for other refs, we keep the current view if we're in history, shortlog or1510# log view, and select shortlog otherwise1511sub format_ref_marker {1512my($refs,$id) =@_;1513my$markers='';15141515if(defined$refs->{$id}) {1516foreachmy$ref(@{$refs->{$id}}) {1517# this code exploits the fact that non-lightweight tags are the1518# only indirect objects, and that they are the only objects for which1519# we want to use tag instead of shortlog as action1520my($type,$name) =qw();1521my$indirect= ($ref=~s/\^\{\}$//);1522# e.g. tags/v2.6.11 or heads/next1523if($ref=~m!^(.*?)s?/(.*)$!) {1524$type=$1;1525$name=$2;1526}else{1527$type="ref";1528$name=$ref;1529}15301531my$class=$type;1532$class.=" indirect"if$indirect;15331534my$dest_action="shortlog";15351536if($indirect) {1537$dest_action="tag"unless$actioneq"tag";1538}elsif($action=~/^(history|(short)?log)$/) {1539$dest_action=$action;1540}15411542my$dest="";1543$dest.="refs/"unless$ref=~ m!^refs/!;1544$dest.=$ref;15451546my$link=$cgi->a({1547-href => href(1548 action=>$dest_action,1549 hash=>$dest1550)},$name);15511552$markers.=" <span class=\"".esc_attr($class)."\"title=\"".esc_attr($ref)."\">".1553$link."</span>";1554}1555}15561557if($markers) {1558return' <span class="refs">'.$markers.'</span>';1559}else{1560return"";1561}1562}15631564# format, perhaps shortened and with markers, title line1565sub format_subject_html {1566my($long,$short,$href,$extra) =@_;1567$extra=''unlessdefined($extra);15681569if(length($short) <length($long)) {1570$long=~s/[[:cntrl:]]/?/g;1571return$cgi->a({-href =>$href, -class=>"list subject",1572-title => to_utf8($long)},1573 esc_html($short)) .$extra;1574}else{1575return$cgi->a({-href =>$href, -class=>"list subject"},1576 esc_html($long)) .$extra;1577}1578}15791580# Rather than recomputing the url for an email multiple times, we cache it1581# after the first hit. This gives a visible benefit in views where the avatar1582# for the same email is used repeatedly (e.g. shortlog).1583# The cache is shared by all avatar engines (currently gravatar only), which1584# are free to use it as preferred. Since only one avatar engine is used for any1585# given page, there's no risk for cache conflicts.1586our%avatar_cache= ();15871588# Compute the picon url for a given email, by using the picon search service over at1589# http://www.cs.indiana.edu/picons/search.html1590sub picon_url {1591my$email=lc shift;1592if(!$avatar_cache{$email}) {1593my($user,$domain) =split('@',$email);1594$avatar_cache{$email} =1595"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".1596"$domain/$user/".1597"users+domains+unknown/up/single";1598}1599return$avatar_cache{$email};1600}16011602# Compute the gravatar url for a given email, if it's not in the cache already.1603# Gravatar stores only the part of the URL before the size, since that's the1604# one computationally more expensive. This also allows reuse of the cache for1605# different sizes (for this particular engine).1606sub gravatar_url {1607my$email=lc shift;1608my$size=shift;1609$avatar_cache{$email} ||=1610"http://www.gravatar.com/avatar/".1611 Digest::MD5::md5_hex($email) ."?s=";1612return$avatar_cache{$email} .$size;1613}16141615# Insert an avatar for the given $email at the given $size if the feature1616# is enabled.1617sub git_get_avatar {1618my($email,%opts) =@_;1619my$pre_white= ($opts{-pad_before} ?" ":"");1620my$post_white= ($opts{-pad_after} ?" ":"");1621$opts{-size} ||='default';1622my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};1623my$url="";1624if($git_avatareq'gravatar') {1625$url= gravatar_url($email,$size);1626}elsif($git_avatareq'picon') {1627$url= picon_url($email);1628}1629# Other providers can be added by extending the if chain, defining $url1630# as needed. If no variant puts something in $url, we assume avatars1631# are completely disabled/unavailable.1632if($url) {1633return$pre_white.1634"<img width=\"$size\"".1635"class=\"avatar\"".1636"src=\"".esc_url($url)."\"".1637"alt=\"\"".1638"/>".$post_white;1639}else{1640return"";1641}1642}16431644sub format_search_author {1645my($author,$searchtype,$displaytext) =@_;1646my$have_search= gitweb_check_feature('search');16471648if($have_search) {1649my$performed="";1650if($searchtypeeq'author') {1651$performed="authored";1652}elsif($searchtypeeq'committer') {1653$performed="committed";1654}16551656return$cgi->a({-href => href(action=>"search", hash=>$hash,1657 searchtext=>$author,1658 searchtype=>$searchtype),class=>"list",1659 title=>"Search for commits$performedby$author"},1660$displaytext);16611662}else{1663return$displaytext;1664}1665}16661667# format the author name of the given commit with the given tag1668# the author name is chopped and escaped according to the other1669# optional parameters (see chop_str).1670sub format_author_html {1671my$tag=shift;1672my$co=shift;1673my$author= chop_and_escape_str($co->{'author_name'},@_);1674return"<$tagclass=\"author\">".1675 format_search_author($co->{'author_name'},"author",1676 git_get_avatar($co->{'author_email'}, -pad_after =>1) .1677$author) .1678"</$tag>";1679}16801681# format git diff header line, i.e. "diff --(git|combined|cc) ..."1682sub format_git_diff_header_line {1683my$line=shift;1684my$diffinfo=shift;1685my($from,$to) =@_;16861687if($diffinfo->{'nparents'}) {1688# combined diff1689$line=~s!^(diff (.*?) )"?.*$!$1!;1690if($to->{'href'}) {1691$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1692 esc_path($to->{'file'}));1693}else{# file was deleted (no href)1694$line.= esc_path($to->{'file'});1695}1696}else{1697# "ordinary" diff1698$line=~s!^(diff (.*?) )"?a/.*$!$1!;1699if($from->{'href'}) {1700$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1701'a/'. esc_path($from->{'file'}));1702}else{# file was added (no href)1703$line.='a/'. esc_path($from->{'file'});1704}1705$line.=' ';1706if($to->{'href'}) {1707$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1708'b/'. esc_path($to->{'file'}));1709}else{# file was deleted1710$line.='b/'. esc_path($to->{'file'});1711}1712}17131714return"<div class=\"diff header\">$line</div>\n";1715}17161717# format extended diff header line, before patch itself1718sub format_extended_diff_header_line {1719my$line=shift;1720my$diffinfo=shift;1721my($from,$to) =@_;17221723# match <path>1724if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1725$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1726 esc_path($from->{'file'}));1727}1728if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1729$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1730 esc_path($to->{'file'}));1731}1732# match single <mode>1733if($line=~m/\s(\d{6})$/) {1734$line.='<span class="info"> ('.1735 file_type_long($1) .1736')</span>';1737}1738# match <hash>1739if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1740# can match only for combined diff1741$line='index ';1742for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1743if($from->{'href'}[$i]) {1744$line.=$cgi->a({-href=>$from->{'href'}[$i],1745-class=>"hash"},1746substr($diffinfo->{'from_id'}[$i],0,7));1747}else{1748$line.='0' x 7;1749}1750# separator1751$line.=','if($i<$diffinfo->{'nparents'} -1);1752}1753$line.='..';1754if($to->{'href'}) {1755$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1756substr($diffinfo->{'to_id'},0,7));1757}else{1758$line.='0' x 7;1759}17601761}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1762# can match only for ordinary diff1763my($from_link,$to_link);1764if($from->{'href'}) {1765$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1766substr($diffinfo->{'from_id'},0,7));1767}else{1768$from_link='0' x 7;1769}1770if($to->{'href'}) {1771$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1772substr($diffinfo->{'to_id'},0,7));1773}else{1774$to_link='0' x 7;1775}1776my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1777$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1778}17791780return$line."<br/>\n";1781}17821783# format from-file/to-file diff header1784sub format_diff_from_to_header {1785my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1786my$line;1787my$result='';17881789$line=$from_line;1790#assert($line =~ m/^---/) if DEBUG;1791# no extra formatting for "^--- /dev/null"1792if(!$diffinfo->{'nparents'}) {1793# ordinary (single parent) diff1794if($line=~m!^--- "?a/!) {1795if($from->{'href'}) {1796$line='--- a/'.1797$cgi->a({-href=>$from->{'href'}, -class=>"path"},1798 esc_path($from->{'file'}));1799}else{1800$line='--- a/'.1801 esc_path($from->{'file'});1802}1803}1804$result.= qq!<div class="diff from_file">$line</div>\n!;18051806}else{1807# combined diff (merge commit)1808for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1809if($from->{'href'}[$i]) {1810$line='--- '.1811$cgi->a({-href=>href(action=>"blobdiff",1812 hash_parent=>$diffinfo->{'from_id'}[$i],1813 hash_parent_base=>$parents[$i],1814 file_parent=>$from->{'file'}[$i],1815 hash=>$diffinfo->{'to_id'},1816 hash_base=>$hash,1817 file_name=>$to->{'file'}),1818-class=>"path",1819-title=>"diff". ($i+1)},1820$i+1) .1821'/'.1822$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1823 esc_path($from->{'file'}[$i]));1824}else{1825$line='--- /dev/null';1826}1827$result.= qq!<div class="diff from_file">$line</div>\n!;1828}1829}18301831$line=$to_line;1832#assert($line =~ m/^\+\+\+/) if DEBUG;1833# no extra formatting for "^+++ /dev/null"1834if($line=~m!^\+\+\+ "?b/!) {1835if($to->{'href'}) {1836$line='+++ b/'.1837$cgi->a({-href=>$to->{'href'}, -class=>"path"},1838 esc_path($to->{'file'}));1839}else{1840$line='+++ b/'.1841 esc_path($to->{'file'});1842}1843}1844$result.= qq!<div class="diff to_file">$line</div>\n!;18451846return$result;1847}18481849# create note for patch simplified by combined diff1850sub format_diff_cc_simplified {1851my($diffinfo,@parents) =@_;1852my$result='';18531854$result.="<div class=\"diff header\">".1855"diff --cc ";1856if(!is_deleted($diffinfo)) {1857$result.=$cgi->a({-href => href(action=>"blob",1858 hash_base=>$hash,1859 hash=>$diffinfo->{'to_id'},1860 file_name=>$diffinfo->{'to_file'}),1861-class=>"path"},1862 esc_path($diffinfo->{'to_file'}));1863}else{1864$result.= esc_path($diffinfo->{'to_file'});1865}1866$result.="</div>\n".# class="diff header"1867"<div class=\"diff nodifferences\">".1868"Simple merge".1869"</div>\n";# class="diff nodifferences"18701871return$result;1872}18731874# format patch (diff) line (not to be used for diff headers)1875sub format_diff_line {1876my$line=shift;1877my($from,$to) =@_;1878my$diff_class="";18791880chomp$line;18811882if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1883# combined diff1884my$prefix=substr($line,0,scalar@{$from->{'href'}});1885if($line=~m/^\@{3}/) {1886$diff_class=" chunk_header";1887}elsif($line=~m/^\\/) {1888$diff_class=" incomplete";1889}elsif($prefix=~tr/+/+/) {1890$diff_class=" add";1891}elsif($prefix=~tr/-/-/) {1892$diff_class=" rem";1893}1894}else{1895# assume ordinary diff1896my$char=substr($line,0,1);1897if($chareq'+') {1898$diff_class=" add";1899}elsif($chareq'-') {1900$diff_class=" rem";1901}elsif($chareq'@') {1902$diff_class=" chunk_header";1903}elsif($chareq"\\") {1904$diff_class=" incomplete";1905}1906}1907$line= untabify($line);1908if($from&&$to&&$line=~m/^\@{2} /) {1909my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1910$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;19111912$from_lines=0unlessdefined$from_lines;1913$to_lines=0unlessdefined$to_lines;19141915if($from->{'href'}) {1916$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1917-class=>"list"},$from_text);1918}1919if($to->{'href'}) {1920$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1921-class=>"list"},$to_text);1922}1923$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1924"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1925return"<div class=\"diff$diff_class\">$line</div>\n";1926}elsif($from&&$to&&$line=~m/^\@{3}/) {1927my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1928my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);19291930@from_text=split(' ',$ranges);1931for(my$i=0;$i<@from_text; ++$i) {1932($from_start[$i],$from_nlines[$i]) =1933(split(',',substr($from_text[$i],1)),0);1934}19351936$to_text=pop@from_text;1937$to_start=pop@from_start;1938$to_nlines=pop@from_nlines;19391940$line="<span class=\"chunk_info\">$prefix";1941for(my$i=0;$i<@from_text; ++$i) {1942if($from->{'href'}[$i]) {1943$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1944-class=>"list"},$from_text[$i]);1945}else{1946$line.=$from_text[$i];1947}1948$line.=" ";1949}1950if($to->{'href'}) {1951$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1952-class=>"list"},$to_text);1953}else{1954$line.=$to_text;1955}1956$line.="$prefix</span>".1957"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1958return"<div class=\"diff$diff_class\">$line</div>\n";1959}1960return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1961}19621963# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1964# linked. Pass the hash of the tree/commit to snapshot.1965sub format_snapshot_links {1966my($hash) =@_;1967my$num_fmts=@snapshot_fmts;1968if($num_fmts>1) {1969# A parenthesized list of links bearing format names.1970# e.g. "snapshot (_tar.gz_ _zip_)"1971return"snapshot (".join(' ',map1972$cgi->a({1973-href => href(1974 action=>"snapshot",1975 hash=>$hash,1976 snapshot_format=>$_1977)1978},$known_snapshot_formats{$_}{'display'})1979,@snapshot_fmts) .")";1980}elsif($num_fmts==1) {1981# A single "snapshot" link whose tooltip bears the format name.1982# i.e. "_snapshot_"1983my($fmt) =@snapshot_fmts;1984return1985$cgi->a({1986-href => href(1987 action=>"snapshot",1988 hash=>$hash,1989 snapshot_format=>$fmt1990),1991-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"1992},"snapshot");1993}else{# $num_fmts == 01994returnundef;1995}1996}19971998## ......................................................................1999## functions returning values to be passed, perhaps after some2000## transformation, to other functions; e.g. returning arguments to href()20012002# returns hash to be passed to href to generate gitweb URL2003# in -title key it returns description of link2004sub get_feed_info {2005my$format=shift||'Atom';2006my%res= (action =>lc($format));20072008# feed links are possible only for project views2009return unless(defined$project);2010# some views should link to OPML, or to generic project feed,2011# or don't have specific feed yet (so they should use generic)2012return if($action=~/^(?:tags|heads|forks|tag|search)$/x);20132014my$branch;2015# branches refs uses 'refs/heads/' prefix (fullname) to differentiate2016# from tag links; this also makes possible to detect branch links2017if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||2018(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {2019$branch=$1;2020}2021# find log type for feed description (title)2022my$type='log';2023if(defined$file_name) {2024$type="history of$file_name";2025$type.="/"if($actioneq'tree');2026$type.=" on '$branch'"if(defined$branch);2027}else{2028$type="log of$branch"if(defined$branch);2029}20302031$res{-title} =$type;2032$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);2033$res{'file_name'} =$file_name;20342035return%res;2036}20372038## ----------------------------------------------------------------------2039## git utility subroutines, invoking git commands20402041# returns path to the core git executable and the --git-dir parameter as list2042sub git_cmd {2043$number_of_git_cmds++;2044return$GIT,'--git-dir='.$git_dir;2045}20462047# quote the given arguments for passing them to the shell2048# quote_command("command", "arg 1", "arg with ' and ! characters")2049# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2050# Try to avoid using this function wherever possible.2051sub quote_command {2052returnjoin(' ',2053map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2054}20552056# get HEAD ref of given project as hash2057sub git_get_head_hash {2058return git_get_full_hash(shift,'HEAD');2059}20602061sub git_get_full_hash {2062return git_get_hash(@_);2063}20642065sub git_get_short_hash {2066return git_get_hash(@_,'--short=7');2067}20682069sub git_get_hash {2070my($project,$hash,@options) =@_;2071my$o_git_dir=$git_dir;2072my$retval=undef;2073$git_dir="$projectroot/$project";2074if(open my$fd,'-|', git_cmd(),'rev-parse',2075'--verify','-q',@options,$hash) {2076$retval= <$fd>;2077chomp$retvalifdefined$retval;2078close$fd;2079}2080if(defined$o_git_dir) {2081$git_dir=$o_git_dir;2082}2083return$retval;2084}20852086# get type of given object2087sub git_get_type {2088my$hash=shift;20892090open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2091my$type= <$fd>;2092close$fdorreturn;2093chomp$type;2094return$type;2095}20962097# repository configuration2098our$config_file='';2099our%config;21002101# store multiple values for single key as anonymous array reference2102# single values stored directly in the hash, not as [ <value> ]2103sub hash_set_multi {2104my($hash,$key,$value) =@_;21052106if(!exists$hash->{$key}) {2107$hash->{$key} =$value;2108}elsif(!ref$hash->{$key}) {2109$hash->{$key} = [$hash->{$key},$value];2110}else{2111push@{$hash->{$key}},$value;2112}2113}21142115# return hash of git project configuration2116# optionally limited to some section, e.g. 'gitweb'2117sub git_parse_project_config {2118my$section_regexp=shift;2119my%config;21202121local$/="\0";21222123open my$fh,"-|", git_cmd(),"config",'-z','-l',2124orreturn;21252126while(my$keyval= <$fh>) {2127chomp$keyval;2128my($key,$value) =split(/\n/,$keyval,2);21292130 hash_set_multi(\%config,$key,$value)2131if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2132}2133close$fh;21342135return%config;2136}21372138# convert config value to boolean: 'true' or 'false'2139# no value, number > 0, 'true' and 'yes' values are true2140# rest of values are treated as false (never as error)2141sub config_to_bool {2142my$val=shift;21432144return1if!defined$val;# section.key21452146# strip leading and trailing whitespace2147$val=~s/^\s+//;2148$val=~s/\s+$//;21492150return(($val=~/^\d+$/&&$val) ||# section.key = 12151($val=~/^(?:true|yes)$/i));# section.key = true2152}21532154# convert config value to simple decimal number2155# an optional value suffix of 'k', 'm', or 'g' will cause the value2156# to be multiplied by 1024, 1048576, or 10737418242157sub config_to_int {2158my$val=shift;21592160# strip leading and trailing whitespace2161$val=~s/^\s+//;2162$val=~s/\s+$//;21632164if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2165$unit=lc($unit);2166# unknown unit is treated as 12167return$num* ($uniteq'g'?1073741824:2168$uniteq'm'?1048576:2169$uniteq'k'?1024:1);2170}2171return$val;2172}21732174# convert config value to array reference, if needed2175sub config_to_multi {2176my$val=shift;21772178returnref($val) ?$val: (defined($val) ? [$val] : []);2179}21802181sub git_get_project_config {2182my($key,$type) =@_;21832184# key sanity check2185return unless($key);2186$key=~s/^gitweb\.//;2187return if($key=~m/\W/);21882189# type sanity check2190if(defined$type) {2191$type=~s/^--//;2192$type=undef2193unless($typeeq'bool'||$typeeq'int');2194}21952196# get config2197if(!defined$config_file||2198$config_filene"$git_dir/config") {2199%config= git_parse_project_config('gitweb');2200$config_file="$git_dir/config";2201}22022203# check if config variable (key) exists2204return unlessexists$config{"gitweb.$key"};22052206# ensure given type2207if(!defined$type) {2208return$config{"gitweb.$key"};2209}elsif($typeeq'bool') {2210# backward compatibility: 'git config --bool' returns true/false2211return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2212}elsif($typeeq'int') {2213return config_to_int($config{"gitweb.$key"});2214}2215return$config{"gitweb.$key"};2216}22172218# get hash of given path at given ref2219sub git_get_hash_by_path {2220my$base=shift;2221my$path=shift||returnundef;2222my$type=shift;22232224$path=~ s,/+$,,;22252226open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2227or die_error(500,"Open git-ls-tree failed");2228my$line= <$fd>;2229close$fdorreturnundef;22302231if(!defined$line) {2232# there is no tree or hash given by $path at $base2233returnundef;2234}22352236#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2237$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2238if(defined$type&&$typene$2) {2239# type doesn't match2240returnundef;2241}2242return$3;2243}22442245# get path of entry with given hash at given tree-ish (ref)2246# used to get 'from' filename for combined diff (merge commit) for renames2247sub git_get_path_by_hash {2248my$base=shift||return;2249my$hash=shift||return;22502251local$/="\0";22522253open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2254orreturnundef;2255while(my$line= <$fd>) {2256chomp$line;22572258#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2259#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2260if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2261close$fd;2262return$1;2263}2264}2265close$fd;2266returnundef;2267}22682269## ......................................................................2270## git utility functions, directly accessing git repository22712272sub git_get_project_description {2273my$path=shift;22742275$git_dir="$projectroot/$path";2276open my$fd,'<',"$git_dir/description"2277orreturn git_get_project_config('description');2278my$descr= <$fd>;2279close$fd;2280if(defined$descr) {2281chomp$descr;2282}2283return$descr;2284}22852286sub git_get_project_ctags {2287my$path=shift;2288my$ctags= {};22892290$git_dir="$projectroot/$path";2291opendir my$dh,"$git_dir/ctags"2292orreturn$ctags;2293foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2294open my$ct,'<',$_ornext;2295my$val= <$ct>;2296chomp$val;2297close$ct;2298my$ctag=$_;$ctag=~ s#.*/##;2299$ctags->{$ctag} =$val;2300}2301closedir$dh;2302$ctags;2303}23042305sub git_populate_project_tagcloud {2306my$ctags=shift;23072308# First, merge different-cased tags; tags vote on casing2309my%ctags_lc;2310foreach(keys%$ctags) {2311$ctags_lc{lc$_}->{count} +=$ctags->{$_};2312if(not$ctags_lc{lc$_}->{topcount}2313or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2314$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2315$ctags_lc{lc$_}->{topname} =$_;2316}2317}23182319my$cloud;2320if(eval{require HTML::TagCloud;1; }) {2321$cloud= HTML::TagCloud->new;2322foreach(sort keys%ctags_lc) {2323# Pad the title with spaces so that the cloud looks2324# less crammed.2325my$title=$ctags_lc{$_}->{topname};2326$title=~s/ / /g;2327$title=~s/^/ /g;2328$title=~s/$/ /g;2329$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2330}2331}else{2332$cloud= \%ctags_lc;2333}2334$cloud;2335}23362337sub git_show_project_tagcloud {2338my($cloud,$count) =@_;2339print STDERR ref($cloud)."..\n";2340if(ref$cloudeq'HTML::TagCloud') {2341return$cloud->html_and_css($count);2342}else{2343my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2344return'<p align="center">'.join(', ',map{2345$cgi->a({-href=>"$home_link?by_tag=$_"},$cloud->{$_}->{topname})2346}splice(@tags,0,$count)) .'</p>';2347}2348}23492350sub git_get_project_url_list {2351my$path=shift;23522353$git_dir="$projectroot/$path";2354open my$fd,'<',"$git_dir/cloneurl"2355orreturnwantarray?2356@{ config_to_multi(git_get_project_config('url')) } :2357 config_to_multi(git_get_project_config('url'));2358my@git_project_url_list=map{chomp;$_} <$fd>;2359close$fd;23602361returnwantarray?@git_project_url_list: \@git_project_url_list;2362}23632364sub git_get_projects_list {2365my($filter) =@_;2366my@list;23672368$filter||='';2369$filter=~s/\.git$//;23702371my$check_forks= gitweb_check_feature('forks');23722373if(-d $projects_list) {2374# search in directory2375my$dir=$projects_list. ($filter?"/$filter":'');2376# remove the trailing "/"2377$dir=~s!/+$!!;2378my$pfxlen=length("$dir");2379my$pfxdepth= ($dir=~tr!/!!);23802381 File::Find::find({2382 follow_fast =>1,# follow symbolic links2383 follow_skip =>2,# ignore duplicates2384 dangling_symlinks =>0,# ignore dangling symlinks, silently2385 wanted =>sub{2386# skip project-list toplevel, if we get it.2387return if(m!^[/.]$!);2388# only directories can be git repositories2389return unless(-d $_);2390# don't traverse too deep (Find is super slow on os x)2391if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2392$File::Find::prune =1;2393return;2394}23952396my$subdir=substr($File::Find::name,$pfxlen+1);2397# we check related file in $projectroot2398my$path= ($filter?"$filter/":'') .$subdir;2399if(check_export_ok("$projectroot/$path")) {2400push@list, { path =>$path};2401$File::Find::prune =1;2402}2403},2404},"$dir");24052406}elsif(-f $projects_list) {2407# read from file(url-encoded):2408# 'git%2Fgit.git Linus+Torvalds'2409# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2410# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2411my%paths;2412open my$fd,'<',$projects_listorreturn;2413 PROJECT:2414while(my$line= <$fd>) {2415chomp$line;2416my($path,$owner) =split' ',$line;2417$path= unescape($path);2418$owner= unescape($owner);2419if(!defined$path) {2420next;2421}2422if($filterne'') {2423# looking for forks;2424my$pfx=substr($path,0,length($filter));2425if($pfxne$filter) {2426next PROJECT;2427}2428my$sfx=substr($path,length($filter));2429if($sfx!~/^\/.*\.git$/) {2430next PROJECT;2431}2432}elsif($check_forks) {2433 PATH:2434foreachmy$filter(keys%paths) {2435# looking for forks;2436my$pfx=substr($path,0,length($filter));2437if($pfxne$filter) {2438next PATH;2439}2440my$sfx=substr($path,length($filter));2441if($sfx!~/^\/.*\.git$/) {2442next PATH;2443}2444# is a fork, don't include it in2445# the list2446next PROJECT;2447}2448}2449if(check_export_ok("$projectroot/$path")) {2450my$pr= {2451 path =>$path,2452 owner => to_utf8($owner),2453};2454push@list,$pr;2455(my$forks_path=$path) =~s/\.git$//;2456$paths{$forks_path}++;2457}2458}2459close$fd;2460}2461return@list;2462}24632464our$gitweb_project_owner=undef;2465sub git_get_project_list_from_file {24662467return if(defined$gitweb_project_owner);24682469$gitweb_project_owner= {};2470# read from file (url-encoded):2471# 'git%2Fgit.git Linus+Torvalds'2472# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2473# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2474if(-f $projects_list) {2475open(my$fd,'<',$projects_list);2476while(my$line= <$fd>) {2477chomp$line;2478my($pr,$ow) =split' ',$line;2479$pr= unescape($pr);2480$ow= unescape($ow);2481$gitweb_project_owner->{$pr} = to_utf8($ow);2482}2483close$fd;2484}2485}24862487sub git_get_project_owner {2488my$project=shift;2489my$owner;24902491returnundefunless$project;2492$git_dir="$projectroot/$project";24932494if(!defined$gitweb_project_owner) {2495 git_get_project_list_from_file();2496}24972498if(exists$gitweb_project_owner->{$project}) {2499$owner=$gitweb_project_owner->{$project};2500}2501if(!defined$owner){2502$owner= git_get_project_config('owner');2503}2504if(!defined$owner) {2505$owner= get_file_owner("$git_dir");2506}25072508return$owner;2509}25102511sub git_get_last_activity {2512my($path) =@_;2513my$fd;25142515$git_dir="$projectroot/$path";2516open($fd,"-|", git_cmd(),'for-each-ref',2517'--format=%(committer)',2518'--sort=-committerdate',2519'--count=1',2520'refs/heads')orreturn;2521my$most_recent= <$fd>;2522close$fdorreturn;2523if(defined$most_recent&&2524$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2525my$timestamp=$1;2526my$age=time-$timestamp;2527return($age, age_string($age));2528}2529return(undef,undef);2530}25312532sub git_get_references {2533my$type=shift||"";2534my%refs;2535# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112536# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2537open my$fd,"-|", git_cmd(),"show-ref","--dereference",2538($type? ("--","refs/$type") : ())# use -- <pattern> if $type2539orreturn;25402541while(my$line= <$fd>) {2542chomp$line;2543if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2544if(defined$refs{$1}) {2545push@{$refs{$1}},$2;2546}else{2547$refs{$1} = [$2];2548}2549}2550}2551close$fdorreturn;2552return \%refs;2553}25542555sub git_get_rev_name_tags {2556my$hash=shift||returnundef;25572558open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2559orreturn;2560my$name_rev= <$fd>;2561close$fd;25622563if($name_rev=~ m|^$hash tags/(.*)$|) {2564return$1;2565}else{2566# catches also '$hash undefined' output2567returnundef;2568}2569}25702571## ----------------------------------------------------------------------2572## parse to hash functions25732574sub parse_date {2575my$epoch=shift;2576my$tz=shift||"-0000";25772578my%date;2579my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2580my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2581my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2582$date{'hour'} =$hour;2583$date{'minute'} =$min;2584$date{'mday'} =$mday;2585$date{'day'} =$days[$wday];2586$date{'month'} =$months[$mon];2587$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2588$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2589$date{'mday-time'} =sprintf"%d%s%02d:%02d",2590$mday,$months[$mon],$hour,$min;2591$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",25921900+$year,1+$mon,$mday,$hour,$min,$sec;25932594$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2595my$local=$epoch+ ((int$1+ ($2/60)) *3600);2596($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2597$date{'hour_local'} =$hour;2598$date{'minute_local'} =$min;2599$date{'tz_local'} =$tz;2600$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",26011900+$year,$mon+1,$mday,2602$hour,$min,$sec,$tz);2603return%date;2604}26052606sub parse_tag {2607my$tag_id=shift;2608my%tag;2609my@comment;26102611open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2612$tag{'id'} =$tag_id;2613while(my$line= <$fd>) {2614chomp$line;2615if($line=~m/^object ([0-9a-fA-F]{40})$/) {2616$tag{'object'} =$1;2617}elsif($line=~m/^type (.+)$/) {2618$tag{'type'} =$1;2619}elsif($line=~m/^tag (.+)$/) {2620$tag{'name'} =$1;2621}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2622$tag{'author'} =$1;2623$tag{'author_epoch'} =$2;2624$tag{'author_tz'} =$3;2625if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {2626$tag{'author_name'} =$1;2627$tag{'author_email'} =$2;2628}else{2629$tag{'author_name'} =$tag{'author'};2630}2631}elsif($line=~m/--BEGIN/) {2632push@comment,$line;2633last;2634}elsif($lineeq"") {2635last;2636}2637}2638push@comment, <$fd>;2639$tag{'comment'} = \@comment;2640close$fdorreturn;2641if(!defined$tag{'name'}) {2642return2643};2644return%tag2645}26462647sub parse_commit_text {2648my($commit_text,$withparents) =@_;2649my@commit_lines=split'\n',$commit_text;2650my%co;26512652pop@commit_lines;# Remove '\0'26532654if(!@commit_lines) {2655return;2656}26572658my$header=shift@commit_lines;2659if($header!~m/^[0-9a-fA-F]{40}/) {2660return;2661}2662($co{'id'},my@parents) =split' ',$header;2663while(my$line=shift@commit_lines) {2664last if$lineeq"\n";2665if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2666$co{'tree'} =$1;2667}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2668push@parents,$1;2669}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2670$co{'author'} = to_utf8($1);2671$co{'author_epoch'} =$2;2672$co{'author_tz'} =$3;2673if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2674$co{'author_name'} =$1;2675$co{'author_email'} =$2;2676}else{2677$co{'author_name'} =$co{'author'};2678}2679}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2680$co{'committer'} = to_utf8($1);2681$co{'committer_epoch'} =$2;2682$co{'committer_tz'} =$3;2683if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2684$co{'committer_name'} =$1;2685$co{'committer_email'} =$2;2686}else{2687$co{'committer_name'} =$co{'committer'};2688}2689}2690}2691if(!defined$co{'tree'}) {2692return;2693};2694$co{'parents'} = \@parents;2695$co{'parent'} =$parents[0];26962697foreachmy$title(@commit_lines) {2698$title=~s/^ //;2699if($titlene"") {2700$co{'title'} = chop_str($title,80,5);2701# remove leading stuff of merges to make the interesting part visible2702if(length($title) >50) {2703$title=~s/^Automatic //;2704$title=~s/^merge (of|with) /Merge ... /i;2705if(length($title) >50) {2706$title=~s/(http|rsync):\/\///;2707}2708if(length($title) >50) {2709$title=~s/(master|www|rsync)\.//;2710}2711if(length($title) >50) {2712$title=~s/kernel.org:?//;2713}2714if(length($title) >50) {2715$title=~s/\/pub\/scm//;2716}2717}2718$co{'title_short'} = chop_str($title,50,5);2719last;2720}2721}2722if(!defined$co{'title'} ||$co{'title'}eq"") {2723$co{'title'} =$co{'title_short'} ='(no commit message)';2724}2725# remove added spaces2726foreachmy$line(@commit_lines) {2727$line=~s/^ //;2728}2729$co{'comment'} = \@commit_lines;27302731my$age=time-$co{'committer_epoch'};2732$co{'age'} =$age;2733$co{'age_string'} = age_string($age);2734my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2735if($age>60*60*24*7*2) {2736$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2737$co{'age_string_age'} =$co{'age_string'};2738}else{2739$co{'age_string_date'} =$co{'age_string'};2740$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2741}2742return%co;2743}27442745sub parse_commit {2746my($commit_id) =@_;2747my%co;27482749local$/="\0";27502751open my$fd,"-|", git_cmd(),"rev-list",2752"--parents",2753"--header",2754"--max-count=1",2755$commit_id,2756"--",2757or die_error(500,"Open git-rev-list failed");2758%co= parse_commit_text(<$fd>,1);2759close$fd;27602761return%co;2762}27632764sub parse_commits {2765my($commit_id,$maxcount,$skip,$filename,@args) =@_;2766my@cos;27672768$maxcount||=1;2769$skip||=0;27702771local$/="\0";27722773open my$fd,"-|", git_cmd(),"rev-list",2774"--header",2775@args,2776("--max-count=".$maxcount),2777("--skip=".$skip),2778@extra_options,2779$commit_id,2780"--",2781($filename? ($filename) : ())2782or die_error(500,"Open git-rev-list failed");2783while(my$line= <$fd>) {2784my%co= parse_commit_text($line);2785push@cos, \%co;2786}2787close$fd;27882789returnwantarray?@cos: \@cos;2790}27912792# parse line of git-diff-tree "raw" output2793sub parse_difftree_raw_line {2794my$line=shift;2795my%res;27962797# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2798# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2799if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2800$res{'from_mode'} =$1;2801$res{'to_mode'} =$2;2802$res{'from_id'} =$3;2803$res{'to_id'} =$4;2804$res{'status'} =$5;2805$res{'similarity'} =$6;2806if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2807($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2808}else{2809$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2810}2811}2812# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2813# combined diff (for merge commit)2814elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2815$res{'nparents'} =length($1);2816$res{'from_mode'} = [split(' ',$2) ];2817$res{'to_mode'} =pop@{$res{'from_mode'}};2818$res{'from_id'} = [split(' ',$3) ];2819$res{'to_id'} =pop@{$res{'from_id'}};2820$res{'status'} = [split('',$4) ];2821$res{'to_file'} = unquote($5);2822}2823# 'c512b523472485aef4fff9e57b229d9d243c967f'2824elsif($line=~m/^([0-9a-fA-F]{40})$/) {2825$res{'commit'} =$1;2826}28272828returnwantarray?%res: \%res;2829}28302831# wrapper: return parsed line of git-diff-tree "raw" output2832# (the argument might be raw line, or parsed info)2833sub parsed_difftree_line {2834my$line_or_ref=shift;28352836if(ref($line_or_ref)eq"HASH") {2837# pre-parsed (or generated by hand)2838return$line_or_ref;2839}else{2840return parse_difftree_raw_line($line_or_ref);2841}2842}28432844# parse line of git-ls-tree output2845sub parse_ls_tree_line {2846my$line=shift;2847my%opts=@_;2848my%res;28492850if($opts{'-l'}) {2851#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'2852$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;28532854$res{'mode'} =$1;2855$res{'type'} =$2;2856$res{'hash'} =$3;2857$res{'size'} =$4;2858if($opts{'-z'}) {2859$res{'name'} =$5;2860}else{2861$res{'name'} = unquote($5);2862}2863}else{2864#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2865$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;28662867$res{'mode'} =$1;2868$res{'type'} =$2;2869$res{'hash'} =$3;2870if($opts{'-z'}) {2871$res{'name'} =$4;2872}else{2873$res{'name'} = unquote($4);2874}2875}28762877returnwantarray?%res: \%res;2878}28792880# generates _two_ hashes, references to which are passed as 2 and 3 argument2881sub parse_from_to_diffinfo {2882my($diffinfo,$from,$to,@parents) =@_;28832884if($diffinfo->{'nparents'}) {2885# combined diff2886$from->{'file'} = [];2887$from->{'href'} = [];2888 fill_from_file_info($diffinfo,@parents)2889unlessexists$diffinfo->{'from_file'};2890for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2891$from->{'file'}[$i] =2892defined$diffinfo->{'from_file'}[$i] ?2893$diffinfo->{'from_file'}[$i] :2894$diffinfo->{'to_file'};2895if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2896$from->{'href'}[$i] = href(action=>"blob",2897 hash_base=>$parents[$i],2898 hash=>$diffinfo->{'from_id'}[$i],2899 file_name=>$from->{'file'}[$i]);2900}else{2901$from->{'href'}[$i] =undef;2902}2903}2904}else{2905# ordinary (not combined) diff2906$from->{'file'} =$diffinfo->{'from_file'};2907if($diffinfo->{'status'}ne"A") {# not new (added) file2908$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2909 hash=>$diffinfo->{'from_id'},2910 file_name=>$from->{'file'});2911}else{2912delete$from->{'href'};2913}2914}29152916$to->{'file'} =$diffinfo->{'to_file'};2917if(!is_deleted($diffinfo)) {# file exists in result2918$to->{'href'} = href(action=>"blob", hash_base=>$hash,2919 hash=>$diffinfo->{'to_id'},2920 file_name=>$to->{'file'});2921}else{2922delete$to->{'href'};2923}2924}29252926## ......................................................................2927## parse to array of hashes functions29282929sub git_get_heads_list {2930my$limit=shift;2931my@headslist;29322933open my$fd,'-|', git_cmd(),'for-each-ref',2934($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2935'--format=%(objectname) %(refname) %(subject)%00%(committer)',2936'refs/heads'2937orreturn;2938while(my$line= <$fd>) {2939my%ref_item;29402941chomp$line;2942my($refinfo,$committerinfo) =split(/\0/,$line);2943my($hash,$name,$title) =split(' ',$refinfo,3);2944my($committer,$epoch,$tz) =2945($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2946$ref_item{'fullname'} =$name;2947$name=~s!^refs/heads/!!;29482949$ref_item{'name'} =$name;2950$ref_item{'id'} =$hash;2951$ref_item{'title'} =$title||'(no commit message)';2952$ref_item{'epoch'} =$epoch;2953if($epoch) {2954$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2955}else{2956$ref_item{'age'} ="unknown";2957}29582959push@headslist, \%ref_item;2960}2961close$fd;29622963returnwantarray?@headslist: \@headslist;2964}29652966sub git_get_tags_list {2967my$limit=shift;2968my@tagslist;29692970open my$fd,'-|', git_cmd(),'for-each-ref',2971($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',2972'--format=%(objectname) %(objecttype) %(refname) '.2973'%(*objectname) %(*objecttype) %(subject)%00%(creator)',2974'refs/tags'2975orreturn;2976while(my$line= <$fd>) {2977my%ref_item;29782979chomp$line;2980my($refinfo,$creatorinfo) =split(/\0/,$line);2981my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);2982my($creator,$epoch,$tz) =2983($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);2984$ref_item{'fullname'} =$name;2985$name=~s!^refs/tags/!!;29862987$ref_item{'type'} =$type;2988$ref_item{'id'} =$id;2989$ref_item{'name'} =$name;2990if($typeeq"tag") {2991$ref_item{'subject'} =$title;2992$ref_item{'reftype'} =$reftype;2993$ref_item{'refid'} =$refid;2994}else{2995$ref_item{'reftype'} =$type;2996$ref_item{'refid'} =$id;2997}29982999if($typeeq"tag"||$typeeq"commit") {3000$ref_item{'epoch'} =$epoch;3001if($epoch) {3002$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3003}else{3004$ref_item{'age'} ="unknown";3005}3006}30073008push@tagslist, \%ref_item;3009}3010close$fd;30113012returnwantarray?@tagslist: \@tagslist;3013}30143015## ----------------------------------------------------------------------3016## filesystem-related functions30173018sub get_file_owner {3019my$path=shift;30203021my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);3022my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);3023if(!defined$gcos) {3024returnundef;3025}3026my$owner=$gcos;3027$owner=~s/[,;].*$//;3028return to_utf8($owner);3029}30303031# assume that file exists3032sub insert_file {3033my$filename=shift;30343035open my$fd,'<',$filename;3036print map{ to_utf8($_) } <$fd>;3037close$fd;3038}30393040## ......................................................................3041## mimetype related functions30423043sub mimetype_guess_file {3044my$filename=shift;3045my$mimemap=shift;3046-r $mimemaporreturnundef;30473048my%mimemap;3049open(my$mh,'<',$mimemap)orreturnundef;3050while(<$mh>) {3051next ifm/^#/;# skip comments3052my($mimetype,$exts) =split(/\t+/);3053if(defined$exts) {3054my@exts=split(/\s+/,$exts);3055foreachmy$ext(@exts) {3056$mimemap{$ext} =$mimetype;3057}3058}3059}3060close($mh);30613062$filename=~/\.([^.]*)$/;3063return$mimemap{$1};3064}30653066sub mimetype_guess {3067my$filename=shift;3068my$mime;3069$filename=~/\./orreturnundef;30703071if($mimetypes_file) {3072my$file=$mimetypes_file;3073if($file!~m!^/!) {# if it is relative path3074# it is relative to project3075$file="$projectroot/$project/$file";3076}3077$mime= mimetype_guess_file($filename,$file);3078}3079$mime||= mimetype_guess_file($filename,'/etc/mime.types');3080return$mime;3081}30823083sub blob_mimetype {3084my$fd=shift;3085my$filename=shift;30863087if($filename) {3088my$mime= mimetype_guess($filename);3089$mimeandreturn$mime;3090}30913092# just in case3093return$default_blob_plain_mimetypeunless$fd;30943095if(-T $fd) {3096return'text/plain';3097}elsif(!$filename) {3098return'application/octet-stream';3099}elsif($filename=~m/\.png$/i) {3100return'image/png';3101}elsif($filename=~m/\.gif$/i) {3102return'image/gif';3103}elsif($filename=~m/\.jpe?g$/i) {3104return'image/jpeg';3105}else{3106return'application/octet-stream';3107}3108}31093110sub blob_contenttype {3111my($fd,$file_name,$type) =@_;31123113$type||= blob_mimetype($fd,$file_name);3114if($typeeq'text/plain'&&defined$default_text_plain_charset) {3115$type.="; charset=$default_text_plain_charset";3116}31173118return$type;3119}31203121## ======================================================================3122## functions printing HTML: header, footer, error page31233124sub git_header_html {3125my$status=shift||"200 OK";3126my$expires=shift;31273128my$title="$site_name";3129if(defined$project) {3130$title.=" - ". to_utf8($project);3131if(defined$action) {3132$title.="/$action";3133if(defined$file_name) {3134$title.=" - ". esc_path($file_name);3135if($actioneq"tree"&&$file_name!~ m|/$|) {3136$title.="/";3137}3138}3139}3140}3141my$content_type;3142# require explicit support from the UA if we are to send the page as3143# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3144# we have to do this because MSIE sometimes globs '*/*', pretending to3145# support xhtml+xml but choking when it gets what it asked for.3146if(defined$cgi->http('HTTP_ACCEPT') &&3147$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3148$cgi->Accept('application/xhtml+xml') !=0) {3149$content_type='application/xhtml+xml';3150}else{3151$content_type='text/html';3152}3153print$cgi->header(-type=>$content_type, -charset =>'utf-8',3154-status=>$status, -expires =>$expires);3155my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';3156print<<EOF;3157<?xml version="1.0" encoding="utf-8"?>3158<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">3159<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">3160<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->3161<!-- git core binaries version$git_version-->3162<head>3163<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>3164<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>3165<meta name="robots" content="index, nofollow"/>3166<title>$title</title>3167EOF3168# the stylesheet, favicon etc urls won't work correctly with path_info3169# unless we set the appropriate base URL3170if($ENV{'PATH_INFO'}) {3171print"<base href=\"".esc_url($base_url)."\"/>\n";3172}3173# print out each stylesheet that exist, providing backwards capability3174# for those people who defined $stylesheet in a config file3175if(defined$stylesheet) {3176print'<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";3177}else{3178foreachmy$stylesheet(@stylesheets) {3179next unless$stylesheet;3180print'<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";3181}3182}3183if(defined$project) {3184my%href_params= get_feed_info();3185if(!exists$href_params{'-title'}) {3186$href_params{'-title'} ='log';3187}31883189foreachmy$formatqw(RSS Atom){3190my$type=lc($format);3191my%link_attr= (3192'-rel'=>'alternate',3193'-title'=> esc_attr("$project-$href_params{'-title'} -$formatfeed"),3194'-type'=>"application/$type+xml"3195);31963197$href_params{'action'} =$type;3198$link_attr{'-href'} = href(%href_params);3199print"<link ".3200"rel=\"$link_attr{'-rel'}\"".3201"title=\"$link_attr{'-title'}\"".3202"href=\"$link_attr{'-href'}\"".3203"type=\"$link_attr{'-type'}\"".3204"/>\n";32053206$href_params{'extra_options'} ='--no-merges';3207$link_attr{'-href'} = href(%href_params);3208$link_attr{'-title'} .=' (no merges)';3209print"<link ".3210"rel=\"$link_attr{'-rel'}\"".3211"title=\"$link_attr{'-title'}\"".3212"href=\"$link_attr{'-href'}\"".3213"type=\"$link_attr{'-type'}\"".3214"/>\n";3215}32163217}else{3218printf('<link rel="alternate" title="%sprojects list" '.3219'href="%s" type="text/plain; charset=utf-8" />'."\n",3220 esc_attr($site_name), href(project=>undef, action=>"project_index"));3221printf('<link rel="alternate" title="%sprojects feeds" '.3222'href="%s" type="text/x-opml" />'."\n",3223 esc_attr($site_name), href(project=>undef, action=>"opml"));3224}3225if(defined$favicon) {3226printqq(<link rel="shortcut icon" href=").esc_url($favicon).qq(" type="image/png" />\n);3227}32283229print"</head>\n".3230"<body>\n";32313232if(-f $site_header) {3233 insert_file($site_header);3234}32353236print"<div class=\"page_header\">\n".3237$cgi->a({-href => esc_url($logo_url),3238-title =>$logo_label},3239qq(<img src=").esc_url($logo).qq(" width="72" height="27" alt="git" class="logo"/>));3240print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3241if(defined$project) {3242print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3243if(defined$action) {3244print" /$action";3245}3246print"\n";3247}3248print"</div>\n";32493250my$have_search= gitweb_check_feature('search');3251if(defined$project&&$have_search) {3252if(!defined$searchtext) {3253$searchtext="";3254}3255my$search_hash;3256if(defined$hash_base) {3257$search_hash=$hash_base;3258}elsif(defined$hash) {3259$search_hash=$hash;3260}else{3261$search_hash="HEAD";3262}3263my$action=$my_uri;3264my$use_pathinfo= gitweb_check_feature('pathinfo');3265if($use_pathinfo) {3266$action.="/".esc_url($project);3267}3268print$cgi->startform(-method=>"get", -action =>$action) .3269"<div class=\"search\">\n".3270(!$use_pathinfo&&3271$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3272$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3273$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3274$cgi->popup_menu(-name =>'st', -default=>'commit',3275-values=> ['commit','grep','author','committer','pickaxe']) .3276$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3277" search:\n",3278$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3279"<span title=\"Extended regular expression\">".3280$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3281-checked =>$search_use_regexp) .3282"</span>".3283"</div>".3284$cgi->end_form() ."\n";3285}3286}32873288sub git_footer_html {3289my$feed_class='rss_logo';32903291print"<div class=\"page_footer\">\n";3292if(defined$project) {3293my$descr= git_get_project_description($project);3294if(defined$descr) {3295print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3296}32973298my%href_params= get_feed_info();3299if(!%href_params) {3300$feed_class.=' generic';3301}3302$href_params{'-title'} ||='log';33033304foreachmy$formatqw(RSS Atom){3305$href_params{'action'} =lc($format);3306print$cgi->a({-href => href(%href_params),3307-title =>"$href_params{'-title'}$formatfeed",3308-class=>$feed_class},$format)."\n";3309}33103311}else{3312print$cgi->a({-href => href(project=>undef, action=>"opml"),3313-class=>$feed_class},"OPML") ." ";3314print$cgi->a({-href => href(project=>undef, action=>"project_index"),3315-class=>$feed_class},"TXT") ."\n";3316}3317print"</div>\n";# class="page_footer"33183319if(defined$t0&& gitweb_check_feature('timed')) {3320print"<div id=\"generating_info\">\n";3321print'This page took '.3322'<span id="generating_time" class="time_span">'.3323 Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).3324' seconds </span>'.3325' and '.3326'<span id="generating_cmd">'.3327$number_of_git_cmds.3328'</span> git commands '.3329" to generate.\n";3330print"</div>\n";# class="page_footer"3331}33323333if(-f $site_footer) {3334 insert_file($site_footer);3335}33363337print qq!<script type="text/javascript" src="!.esc_url($javascript).qq!"></script>\n!;3338if($actioneq'blame_incremental') {3339print qq!<script type="text/javascript">\n!.3340 qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.3341 qq!"!. href() .qq!");\n!.3342 qq!</script>\n!;3343}elsif(gitweb_check_feature('javascript-actions')) {3344print qq!<script type="text/javascript">\n!.3345 qq!window.onload = fixLinks;\n!.3346 qq!</script>\n!;3347}33483349print"</body>\n".3350"</html>";3351}33523353# die_error(<http_status_code>, <error_message>)3354# Example: die_error(404, 'Hash not found')3355# By convention, use the following status codes (as defined in RFC 2616):3356# 400: Invalid or missing CGI parameters, or3357# requested object exists but has wrong type.3358# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3359# this server or project.3360# 404: Requested object/revision/project doesn't exist.3361# 500: The server isn't configured properly, or3362# an internal error occurred (e.g. failed assertions caused by bugs), or3363# an unknown error occurred (e.g. the git binary died unexpectedly).3364sub die_error {3365my$status=shift||500;3366my$error=shift||"Internal server error";33673368my%http_responses= (400=>'400 Bad Request',3369403=>'403 Forbidden',3370404=>'404 Not Found',3371500=>'500 Internal Server Error');3372 git_header_html($http_responses{$status});3373print<<EOF;3374<div class="page_body">3375<br /><br />3376$status-$error3377<br />3378</div>3379EOF3380 git_footer_html();3381exit;3382}33833384## ----------------------------------------------------------------------3385## functions printing or outputting HTML: navigation33863387sub git_print_page_nav {3388my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3389$extra=''if!defined$extra;# pager or formats33903391my@navs=qw(summary shortlog log commit commitdiff tree);3392if($suppress) {3393@navs=grep{$_ne$suppress}@navs;3394}33953396my%arg=map{$_=> {action=>$_} }@navs;3397if(defined$head) {3398for(qw(commit commitdiff)) {3399$arg{$_}{'hash'} =$head;3400}3401if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3402for(qw(shortlog log)) {3403$arg{$_}{'hash'} =$head;3404}3405}3406}34073408$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3409$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;34103411my@actions= gitweb_get_feature('actions');3412my%repl= (3413'%'=>'%',3414'n'=>$project,# project name3415'f'=>$git_dir,# project path within filesystem3416'h'=>$treehead||'',# current hash ('h' parameter)3417'b'=>$treebase||'',# hash base ('hb' parameter)3418);3419while(@actions) {3420my($label,$link,$pos) =splice(@actions,0,3);3421# insert3422@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3423# munch munch3424$link=~s/%([%nfhb])/$repl{$1}/g;3425$arg{$label}{'_href'} =$link;3426}34273428print"<div class=\"page_nav\">\n".3429(join" | ",3430map{$_eq$current?3431$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3432}@navs);3433print"<br/>\n$extra<br/>\n".3434"</div>\n";3435}34363437sub format_paging_nav {3438my($action,$page,$has_next_link) =@_;3439my$paging_nav;344034413442if($page>0) {3443$paging_nav.=3444$cgi->a({-href => href(-replay=>1, page=>undef)},"first") .3445" ⋅ ".3446$cgi->a({-href => href(-replay=>1, page=>$page-1),3447-accesskey =>"p", -title =>"Alt-p"},"prev");3448}else{3449$paging_nav.="first ⋅ prev";3450}34513452if($has_next_link) {3453$paging_nav.=" ⋅ ".3454$cgi->a({-href => href(-replay=>1, page=>$page+1),3455-accesskey =>"n", -title =>"Alt-n"},"next");3456}else{3457$paging_nav.=" ⋅ next";3458}34593460return$paging_nav;3461}34623463## ......................................................................3464## functions printing or outputting HTML: div34653466sub git_print_header_div {3467my($action,$title,$hash,$hash_base) =@_;3468my%args= ();34693470$args{'action'} =$action;3471$args{'hash'} =$hashif$hash;3472$args{'hash_base'} =$hash_baseif$hash_base;34733474print"<div class=\"header\">\n".3475$cgi->a({-href => href(%args), -class=>"title"},3476$title?$title:$action) .3477"\n</div>\n";3478}34793480sub print_local_time {3481my%date=@_;3482if($date{'hour_local'} <6) {3483printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3484$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3485}else{3486printf(" (%02d:%02d%s)",3487$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3488}3489}34903491# Outputs the author name and date in long form3492sub git_print_authorship {3493my$co=shift;3494my%opts=@_;3495my$tag=$opts{-tag} ||'div';3496my$author=$co->{'author_name'};34973498my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3499print"<$tagclass=\"author_date\">".3500 format_search_author($author,"author", esc_html($author)) .3501" [$ad{'rfc2822'}";3502 print_local_time(%ad)if($opts{-localtime});3503print"]". git_get_avatar($co->{'author_email'}, -pad_before =>1)3504."</$tag>\n";3505}35063507# Outputs table rows containing the full author or committer information,3508# in the format expected for 'commit' view (& similia).3509# Parameters are a commit hash reference, followed by the list of people3510# to output information for. If the list is empty it defalts to both3511# author and committer.3512sub git_print_authorship_rows {3513my$co=shift;3514# too bad we can't use @people = @_ || ('author', 'committer')3515my@people=@_;3516@people= ('author','committer')unless@people;3517foreachmy$who(@people) {3518my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});3519print"<tr><td>$who</td><td>".3520 format_search_author($co->{"${who}_name"},$who,3521 esc_html($co->{"${who}_name"})) ." ".3522 format_search_author($co->{"${who}_email"},$who,3523 esc_html("<".$co->{"${who}_email"} .">")) .3524"</td><td rowspan=\"2\">".3525 git_get_avatar($co->{"${who}_email"}, -size =>'double') .3526"</td></tr>\n".3527"<tr>".3528"<td></td><td>$wd{'rfc2822'}";3529 print_local_time(%wd);3530print"</td>".3531"</tr>\n";3532}3533}35343535sub git_print_page_path {3536my$name=shift;3537my$type=shift;3538my$hb=shift;353935403541print"<div class=\"page_path\">";3542print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3543-title =>'tree root'}, to_utf8("[$project]"));3544print" / ";3545if(defined$name) {3546my@dirname=split'/',$name;3547my$basename=pop@dirname;3548my$fullname='';35493550foreachmy$dir(@dirname) {3551$fullname.= ($fullname?'/':'') .$dir;3552print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3553 hash_base=>$hb),3554-title =>$fullname}, esc_path($dir));3555print" / ";3556}3557if(defined$type&&$typeeq'blob') {3558print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3559 hash_base=>$hb),3560-title =>$name}, esc_path($basename));3561}elsif(defined$type&&$typeeq'tree') {3562print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3563 hash_base=>$hb),3564-title =>$name}, esc_path($basename));3565print" / ";3566}else{3567print esc_path($basename);3568}3569}3570print"<br/></div>\n";3571}35723573sub git_print_log {3574my$log=shift;3575my%opts=@_;35763577if($opts{'-remove_title'}) {3578# remove title, i.e. first line of log3579shift@$log;3580}3581# remove leading empty lines3582while(defined$log->[0] &&$log->[0]eq"") {3583shift@$log;3584}35853586# print log3587my$signoff=0;3588my$empty=0;3589foreachmy$line(@$log) {3590if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3591$signoff=1;3592$empty=0;3593if(!$opts{'-remove_signoff'}) {3594print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3595next;3596}else{3597# remove signoff lines3598next;3599}3600}else{3601$signoff=0;3602}36033604# print only one empty line3605# do not print empty line after signoff3606if($lineeq"") {3607next if($empty||$signoff);3608$empty=1;3609}else{3610$empty=0;3611}36123613print format_log_line_html($line) ."<br/>\n";3614}36153616if($opts{'-final_empty_line'}) {3617# end with single empty line3618print"<br/>\n"unless$empty;3619}3620}36213622# return link target (what link points to)3623sub git_get_link_target {3624my$hash=shift;3625my$link_target;36263627# read link3628open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3629orreturn;3630{3631local$/=undef;3632$link_target= <$fd>;3633}3634close$fd3635orreturn;36363637return$link_target;3638}36393640# given link target, and the directory (basedir) the link is in,3641# return target of link relative to top directory (top tree);3642# return undef if it is not possible (including absolute links).3643sub normalize_link_target {3644my($link_target,$basedir) =@_;36453646# absolute symlinks (beginning with '/') cannot be normalized3647return if(substr($link_target,0,1)eq'/');36483649# normalize link target to path from top (root) tree (dir)3650my$path;3651if($basedir) {3652$path=$basedir.'/'.$link_target;3653}else{3654# we are in top (root) tree (dir)3655$path=$link_target;3656}36573658# remove //, /./, and /../3659my@path_parts;3660foreachmy$part(split('/',$path)) {3661# discard '.' and ''3662next if(!$part||$parteq'.');3663# handle '..'3664if($parteq'..') {3665if(@path_parts) {3666pop@path_parts;3667}else{3668# link leads outside repository (outside top dir)3669return;3670}3671}else{3672push@path_parts,$part;3673}3674}3675$path=join('/',@path_parts);36763677return$path;3678}36793680# print tree entry (row of git_tree), but without encompassing <tr> element3681sub git_print_tree_entry {3682my($t,$basedir,$hash_base,$have_blame) =@_;36833684my%base_key= ();3685$base_key{'hash_base'} =$hash_baseifdefined$hash_base;36863687# The format of a table row is: mode list link. Where mode is3688# the mode of the entry, list is the name of the entry, an href,3689# and link is the action links of the entry.36903691print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3692if(exists$t->{'size'}) {3693print"<td class=\"size\">$t->{'size'}</td>\n";3694}3695if($t->{'type'}eq"blob") {3696print"<td class=\"list\">".3697$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3698 file_name=>"$basedir$t->{'name'}",%base_key),3699-class=>"list"}, esc_path($t->{'name'}));3700if(S_ISLNK(oct$t->{'mode'})) {3701my$link_target= git_get_link_target($t->{'hash'});3702if($link_target) {3703my$norm_target= normalize_link_target($link_target,$basedir);3704if(defined$norm_target) {3705print" -> ".3706$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3707 file_name=>$norm_target),3708-title =>$norm_target}, esc_path($link_target));3709}else{3710print" -> ". esc_path($link_target);3711}3712}3713}3714print"</td>\n";3715print"<td class=\"link\">";3716print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3717 file_name=>"$basedir$t->{'name'}",%base_key)},3718"blob");3719if($have_blame) {3720print" | ".3721$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3722 file_name=>"$basedir$t->{'name'}",%base_key)},3723"blame");3724}3725if(defined$hash_base) {3726print" | ".3727$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3728 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3729"history");3730}3731print" | ".3732$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3733 file_name=>"$basedir$t->{'name'}")},3734"raw");3735print"</td>\n";37363737}elsif($t->{'type'}eq"tree") {3738print"<td class=\"list\">";3739print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3740 file_name=>"$basedir$t->{'name'}",3741%base_key)},3742 esc_path($t->{'name'}));3743print"</td>\n";3744print"<td class=\"link\">";3745print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3746 file_name=>"$basedir$t->{'name'}",3747%base_key)},3748"tree");3749if(defined$hash_base) {3750print" | ".3751$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3752 file_name=>"$basedir$t->{'name'}")},3753"history");3754}3755print"</td>\n";3756}else{3757# unknown object: we can only present history for it3758# (this includes 'commit' object, i.e. submodule support)3759print"<td class=\"list\">".3760 esc_path($t->{'name'}) .3761"</td>\n";3762print"<td class=\"link\">";3763if(defined$hash_base) {3764print$cgi->a({-href => href(action=>"history",3765 hash_base=>$hash_base,3766 file_name=>"$basedir$t->{'name'}")},3767"history");3768}3769print"</td>\n";3770}3771}37723773## ......................................................................3774## functions printing large fragments of HTML37753776# get pre-image filenames for merge (combined) diff3777sub fill_from_file_info {3778my($diff,@parents) =@_;37793780$diff->{'from_file'} = [ ];3781$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3782for(my$i=0;$i<$diff->{'nparents'};$i++) {3783if($diff->{'status'}[$i]eq'R'||3784$diff->{'status'}[$i]eq'C') {3785$diff->{'from_file'}[$i] =3786 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3787}3788}37893790return$diff;3791}37923793# is current raw difftree line of file deletion3794sub is_deleted {3795my$diffinfo=shift;37963797return$diffinfo->{'to_id'}eq('0' x 40);3798}37993800# does patch correspond to [previous] difftree raw line3801# $diffinfo - hashref of parsed raw diff format3802# $patchinfo - hashref of parsed patch diff format3803# (the same keys as in $diffinfo)3804sub is_patch_split {3805my($diffinfo,$patchinfo) =@_;38063807returndefined$diffinfo&&defined$patchinfo3808&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3809}381038113812sub git_difftree_body {3813my($difftree,$hash,@parents) =@_;3814my($parent) =$parents[0];3815my$have_blame= gitweb_check_feature('blame');3816print"<div class=\"list_head\">\n";3817if($#{$difftree} >10) {3818print(($#{$difftree} +1) ." files changed:\n");3819}3820print"</div>\n";38213822print"<table class=\"".3823(@parents>1?"combined ":"") .3824"diff_tree\">\n";38253826# header only for combined diff in 'commitdiff' view3827my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3828if($has_header) {3829# table header3830print"<thead><tr>\n".3831"<th></th><th></th>\n";# filename, patchN link3832for(my$i=0;$i<@parents;$i++) {3833my$par=$parents[$i];3834print"<th>".3835$cgi->a({-href => href(action=>"commitdiff",3836 hash=>$hash, hash_parent=>$par),3837-title =>'commitdiff to parent number '.3838($i+1) .': '.substr($par,0,7)},3839$i+1) .3840" </th>\n";3841}3842print"</tr></thead>\n<tbody>\n";3843}38443845my$alternate=1;3846my$patchno=0;3847foreachmy$line(@{$difftree}) {3848my$diff= parsed_difftree_line($line);38493850if($alternate) {3851print"<tr class=\"dark\">\n";3852}else{3853print"<tr class=\"light\">\n";3854}3855$alternate^=1;38563857if(exists$diff->{'nparents'}) {# combined diff38583859 fill_from_file_info($diff,@parents)3860unlessexists$diff->{'from_file'};38613862if(!is_deleted($diff)) {3863# file exists in the result (child) commit3864print"<td>".3865$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3866 file_name=>$diff->{'to_file'},3867 hash_base=>$hash),3868-class=>"list"}, esc_path($diff->{'to_file'})) .3869"</td>\n";3870}else{3871print"<td>".3872 esc_path($diff->{'to_file'}) .3873"</td>\n";3874}38753876if($actioneq'commitdiff') {3877# link to patch3878$patchno++;3879print"<td class=\"link\">".3880$cgi->a({-href =>"#patch$patchno"},"patch") .3881" | ".3882"</td>\n";3883}38843885my$has_history=0;3886my$not_deleted=0;3887for(my$i=0;$i<$diff->{'nparents'};$i++) {3888my$hash_parent=$parents[$i];3889my$from_hash=$diff->{'from_id'}[$i];3890my$from_path=$diff->{'from_file'}[$i];3891my$status=$diff->{'status'}[$i];38923893$has_history||= ($statusne'A');3894$not_deleted||= ($statusne'D');38953896if($statuseq'A') {3897print"<td class=\"link\"align=\"right\"> | </td>\n";3898}elsif($statuseq'D') {3899print"<td class=\"link\">".3900$cgi->a({-href => href(action=>"blob",3901 hash_base=>$hash,3902 hash=>$from_hash,3903 file_name=>$from_path)},3904"blob". ($i+1)) .3905" | </td>\n";3906}else{3907if($diff->{'to_id'}eq$from_hash) {3908print"<td class=\"link nochange\">";3909}else{3910print"<td class=\"link\">";3911}3912print$cgi->a({-href => href(action=>"blobdiff",3913 hash=>$diff->{'to_id'},3914 hash_parent=>$from_hash,3915 hash_base=>$hash,3916 hash_parent_base=>$hash_parent,3917 file_name=>$diff->{'to_file'},3918 file_parent=>$from_path)},3919"diff". ($i+1)) .3920" | </td>\n";3921}3922}39233924print"<td class=\"link\">";3925if($not_deleted) {3926print$cgi->a({-href => href(action=>"blob",3927 hash=>$diff->{'to_id'},3928 file_name=>$diff->{'to_file'},3929 hash_base=>$hash)},3930"blob");3931print" | "if($has_history);3932}3933if($has_history) {3934print$cgi->a({-href => href(action=>"history",3935 file_name=>$diff->{'to_file'},3936 hash_base=>$hash)},3937"history");3938}3939print"</td>\n";39403941print"</tr>\n";3942next;# instead of 'else' clause, to avoid extra indent3943}3944# else ordinary diff39453946my($to_mode_oct,$to_mode_str,$to_file_type);3947my($from_mode_oct,$from_mode_str,$from_file_type);3948if($diff->{'to_mode'}ne('0' x 6)) {3949$to_mode_oct=oct$diff->{'to_mode'};3950if(S_ISREG($to_mode_oct)) {# only for regular file3951$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits3952}3953$to_file_type= file_type($diff->{'to_mode'});3954}3955if($diff->{'from_mode'}ne('0' x 6)) {3956$from_mode_oct=oct$diff->{'from_mode'};3957if(S_ISREG($to_mode_oct)) {# only for regular file3958$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits3959}3960$from_file_type= file_type($diff->{'from_mode'});3961}39623963if($diff->{'status'}eq"A") {# created3964my$mode_chng="<span class=\"file_status new\">[new$to_file_type";3965$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;3966$mode_chng.="]</span>";3967print"<td>";3968print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3969 hash_base=>$hash, file_name=>$diff->{'file'}),3970-class=>"list"}, esc_path($diff->{'file'}));3971print"</td>\n";3972print"<td>$mode_chng</td>\n";3973print"<td class=\"link\">";3974if($actioneq'commitdiff') {3975# link to patch3976$patchno++;3977print$cgi->a({-href =>"#patch$patchno"},"patch");3978print" | ";3979}3980print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3981 hash_base=>$hash, file_name=>$diff->{'file'})},3982"blob");3983print"</td>\n";39843985}elsif($diff->{'status'}eq"D") {# deleted3986my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";3987print"<td>";3988print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3989 hash_base=>$parent, file_name=>$diff->{'file'}),3990-class=>"list"}, esc_path($diff->{'file'}));3991print"</td>\n";3992print"<td>$mode_chng</td>\n";3993print"<td class=\"link\">";3994if($actioneq'commitdiff') {3995# link to patch3996$patchno++;3997print$cgi->a({-href =>"#patch$patchno"},"patch");3998print" | ";3999}4000print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4001 hash_base=>$parent, file_name=>$diff->{'file'})},4002"blob") ." | ";4003if($have_blame) {4004print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,4005 file_name=>$diff->{'file'})},4006"blame") ." | ";4007}4008print$cgi->a({-href => href(action=>"history", hash_base=>$parent,4009 file_name=>$diff->{'file'})},4010"history");4011print"</td>\n";40124013}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed4014my$mode_chnge="";4015if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4016$mode_chnge="<span class=\"file_status mode_chnge\">[changed";4017if($from_file_typene$to_file_type) {4018$mode_chnge.=" from$from_file_typeto$to_file_type";4019}4020if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {4021if($from_mode_str&&$to_mode_str) {4022$mode_chnge.=" mode:$from_mode_str->$to_mode_str";4023}elsif($to_mode_str) {4024$mode_chnge.=" mode:$to_mode_str";4025}4026}4027$mode_chnge.="]</span>\n";4028}4029print"<td>";4030print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4031 hash_base=>$hash, file_name=>$diff->{'file'}),4032-class=>"list"}, esc_path($diff->{'file'}));4033print"</td>\n";4034print"<td>$mode_chnge</td>\n";4035print"<td class=\"link\">";4036if($actioneq'commitdiff') {4037# link to patch4038$patchno++;4039print$cgi->a({-href =>"#patch$patchno"},"patch") .4040" | ";4041}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4042# "commit" view and modified file (not onlu mode changed)4043print$cgi->a({-href => href(action=>"blobdiff",4044 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4045 hash_base=>$hash, hash_parent_base=>$parent,4046 file_name=>$diff->{'file'})},4047"diff") .4048" | ";4049}4050print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4051 hash_base=>$hash, file_name=>$diff->{'file'})},4052"blob") ." | ";4053if($have_blame) {4054print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4055 file_name=>$diff->{'file'})},4056"blame") ." | ";4057}4058print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4059 file_name=>$diff->{'file'})},4060"history");4061print"</td>\n";40624063}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied4064my%status_name= ('R'=>'moved','C'=>'copied');4065my$nstatus=$status_name{$diff->{'status'}};4066my$mode_chng="";4067if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4068# mode also for directories, so we cannot use $to_mode_str4069$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);4070}4071print"<td>".4072$cgi->a({-href => href(action=>"blob", hash_base=>$hash,4073 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),4074-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".4075"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".4076$cgi->a({-href => href(action=>"blob", hash_base=>$parent,4077 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),4078-class=>"list"}, esc_path($diff->{'from_file'})) .4079" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".4080"<td class=\"link\">";4081if($actioneq'commitdiff') {4082# link to patch4083$patchno++;4084print$cgi->a({-href =>"#patch$patchno"},"patch") .4085" | ";4086}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4087# "commit" view and modified file (not only pure rename or copy)4088print$cgi->a({-href => href(action=>"blobdiff",4089 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4090 hash_base=>$hash, hash_parent_base=>$parent,4091 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},4092"diff") .4093" | ";4094}4095print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4096 hash_base=>$parent, file_name=>$diff->{'to_file'})},4097"blob") ." | ";4098if($have_blame) {4099print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4100 file_name=>$diff->{'to_file'})},4101"blame") ." | ";4102}4103print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4104 file_name=>$diff->{'to_file'})},4105"history");4106print"</td>\n";41074108}# we should not encounter Unmerged (U) or Unknown (X) status4109print"</tr>\n";4110}4111print"</tbody>"if$has_header;4112print"</table>\n";4113}41144115sub git_patchset_body {4116my($fd,$difftree,$hash,@hash_parents) =@_;4117my($hash_parent) =$hash_parents[0];41184119my$is_combined= (@hash_parents>1);4120my$patch_idx=0;4121my$patch_number=0;4122my$patch_line;4123my$diffinfo;4124my$to_name;4125my(%from,%to);41264127print"<div class=\"patchset\">\n";41284129# skip to first patch4130while($patch_line= <$fd>) {4131chomp$patch_line;41324133last if($patch_line=~m/^diff /);4134}41354136 PATCH:4137while($patch_line) {41384139# parse "git diff" header line4140if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {4141# $1 is from_name, which we do not use4142$to_name= unquote($2);4143$to_name=~s!^b/!!;4144}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {4145# $1 is 'cc' or 'combined', which we do not use4146$to_name= unquote($2);4147}else{4148$to_name=undef;4149}41504151# check if current patch belong to current raw line4152# and parse raw git-diff line if needed4153if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {4154# this is continuation of a split patch4155print"<div class=\"patch cont\">\n";4156}else{4157# advance raw git-diff output if needed4158$patch_idx++ifdefined$diffinfo;41594160# read and prepare patch information4161$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);41624163# compact combined diff output can have some patches skipped4164# find which patch (using pathname of result) we are at now;4165if($is_combined) {4166while($to_namene$diffinfo->{'to_file'}) {4167print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4168 format_diff_cc_simplified($diffinfo,@hash_parents) .4169"</div>\n";# class="patch"41704171$patch_idx++;4172$patch_number++;41734174last if$patch_idx>$#$difftree;4175$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);4176}4177}41784179# modifies %from, %to hashes4180 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);41814182# this is first patch for raw difftree line with $patch_idx index4183# we index @$difftree array from 0, but number patches from 14184print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";4185}41864187# git diff header4188#assert($patch_line =~ m/^diff /) if DEBUG;4189#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed4190$patch_number++;4191# print "git diff" header4192print format_git_diff_header_line($patch_line,$diffinfo,4193 \%from, \%to);41944195# print extended diff header4196print"<div class=\"diff extended_header\">\n";4197 EXTENDED_HEADER:4198while($patch_line= <$fd>) {4199chomp$patch_line;42004201last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);42024203print format_extended_diff_header_line($patch_line,$diffinfo,4204 \%from, \%to);4205}4206print"</div>\n";# class="diff extended_header"42074208# from-file/to-file diff header4209if(!$patch_line) {4210print"</div>\n";# class="patch"4211last PATCH;4212}4213next PATCH if($patch_line=~m/^diff /);4214#assert($patch_line =~ m/^---/) if DEBUG;42154216my$last_patch_line=$patch_line;4217$patch_line= <$fd>;4218chomp$patch_line;4219#assert($patch_line =~ m/^\+\+\+/) if DEBUG;42204221print format_diff_from_to_header($last_patch_line,$patch_line,4222$diffinfo, \%from, \%to,4223@hash_parents);42244225# the patch itself4226 LINE:4227while($patch_line= <$fd>) {4228chomp$patch_line;42294230next PATCH if($patch_line=~m/^diff /);42314232print format_diff_line($patch_line, \%from, \%to);4233}42344235}continue{4236print"</div>\n";# class="patch"4237}42384239# for compact combined (--cc) format, with chunk and patch simpliciaction4240# patchset might be empty, but there might be unprocessed raw lines4241for(++$patch_idxif$patch_number>0;4242$patch_idx<@$difftree;4243++$patch_idx) {4244# read and prepare patch information4245$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);42464247# generate anchor for "patch" links in difftree / whatchanged part4248print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4249 format_diff_cc_simplified($diffinfo,@hash_parents) .4250"</div>\n";# class="patch"42514252$patch_number++;4253}42544255if($patch_number==0) {4256if(@hash_parents>1) {4257print"<div class=\"diff nodifferences\">Trivial merge</div>\n";4258}else{4259print"<div class=\"diff nodifferences\">No differences found</div>\n";4260}4261}42624263print"</div>\n";# class="patchset"4264}42654266# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42674268# fills project list info (age, description, owner, forks) for each4269# project in the list, removing invalid projects from returned list4270# NOTE: modifies $projlist, but does not remove entries from it4271sub fill_project_list_info {4272my($projlist,$check_forks) =@_;4273my@projects;42744275my$show_ctags= gitweb_check_feature('ctags');4276 PROJECT:4277foreachmy$pr(@$projlist) {4278my(@activity) = git_get_last_activity($pr->{'path'});4279unless(@activity) {4280next PROJECT;4281}4282($pr->{'age'},$pr->{'age_string'}) =@activity;4283if(!defined$pr->{'descr'}) {4284my$descr= git_get_project_description($pr->{'path'}) ||"";4285$descr= to_utf8($descr);4286$pr->{'descr_long'} =$descr;4287$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4288}4289if(!defined$pr->{'owner'}) {4290$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4291}4292if($check_forks) {4293my$pname=$pr->{'path'};4294if(($pname=~s/\.git$//) &&4295($pname!~/\/$/) &&4296(-d "$projectroot/$pname")) {4297$pr->{'forks'} ="-d$projectroot/$pname";4298}else{4299$pr->{'forks'} =0;4300}4301}4302$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4303push@projects,$pr;4304}43054306return@projects;4307}43084309# print 'sort by' <th> element, generating 'sort by $name' replay link4310# if that order is not selected4311sub print_sort_th {4312my($name,$order,$header) =@_;4313$header||=ucfirst($name);43144315if($ordereq$name) {4316print"<th>$header</th>\n";4317}else{4318print"<th>".4319$cgi->a({-href => href(-replay=>1, order=>$name),4320-class=>"header"},$header) .4321"</th>\n";4322}4323}43244325sub git_project_list_body {4326# actually uses global variable $project4327my($projlist,$order,$from,$to,$extra,$no_header) =@_;43284329my$check_forks= gitweb_check_feature('forks');4330my@projects= fill_project_list_info($projlist,$check_forks);43314332$order||=$default_projects_order;4333$from=0unlessdefined$from;4334$to=$#projectsif(!defined$to||$#projects<$to);43354336my%order_info= (4337 project => { key =>'path', type =>'str'},4338 descr => { key =>'descr_long', type =>'str'},4339 owner => { key =>'owner', type =>'str'},4340 age => { key =>'age', type =>'num'}4341);4342my$oi=$order_info{$order};4343if($oi->{'type'}eq'str') {4344@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4345}else{4346@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4347}43484349my$show_ctags= gitweb_check_feature('ctags');4350if($show_ctags) {4351my%ctags;4352foreachmy$p(@projects) {4353foreachmy$ct(keys%{$p->{'ctags'}}) {4354$ctags{$ct} +=$p->{'ctags'}->{$ct};4355}4356}4357my$cloud= git_populate_project_tagcloud(\%ctags);4358print git_show_project_tagcloud($cloud,64);4359}43604361print"<table class=\"project_list\">\n";4362unless($no_header) {4363print"<tr>\n";4364if($check_forks) {4365print"<th></th>\n";4366}4367 print_sort_th('project',$order,'Project');4368 print_sort_th('descr',$order,'Description');4369 print_sort_th('owner',$order,'Owner');4370 print_sort_th('age',$order,'Last Change');4371print"<th></th>\n".# for links4372"</tr>\n";4373}4374my$alternate=1;4375my$tagfilter=$cgi->param('by_tag');4376for(my$i=$from;$i<=$to;$i++) {4377my$pr=$projects[$i];43784379next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4380next if$searchtextand not$pr->{'path'} =~/$searchtext/4381and not$pr->{'descr_long'} =~/$searchtext/;4382# Weed out forks or non-matching entries of search4383if($check_forks) {4384my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4385$forkbase="^$forkbase"if$forkbase;4386next ifnot$searchtextand not$tagfilterand$show_ctags4387and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4388}43894390if($alternate) {4391print"<tr class=\"dark\">\n";4392}else{4393print"<tr class=\"light\">\n";4394}4395$alternate^=1;4396if($check_forks) {4397print"<td>";4398if($pr->{'forks'}) {4399print"<!--$pr->{'forks'} -->\n";4400print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4401}4402print"</td>\n";4403}4404print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4405-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4406"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4407-class=>"list", -title =>$pr->{'descr_long'}},4408 esc_html($pr->{'descr'})) ."</td>\n".4409"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4410print"<td class=\"". age_class($pr->{'age'}) ."\">".4411(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4412"<td class=\"link\">".4413$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4414$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4415$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4416$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4417($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4418"</td>\n".4419"</tr>\n";4420}4421if(defined$extra) {4422print"<tr>\n";4423if($check_forks) {4424print"<td></td>\n";4425}4426print"<td colspan=\"5\">$extra</td>\n".4427"</tr>\n";4428}4429print"</table>\n";4430}44314432sub git_log_body {4433# uses global variable $project4434my($commitlist,$from,$to,$refs,$extra) =@_;44354436$from=0unlessdefined$from;4437$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);44384439for(my$i=0;$i<=$to;$i++) {4440my%co= %{$commitlist->[$i]};4441next if!%co;4442my$commit=$co{'id'};4443my$ref= format_ref_marker($refs,$commit);4444my%ad= parse_date($co{'author_epoch'});4445 git_print_header_div('commit',4446"<span class=\"age\">$co{'age_string'}</span>".4447 esc_html($co{'title'}) .$ref,4448$commit);4449print"<div class=\"title_text\">\n".4450"<div class=\"log_link\">\n".4451$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .4452" | ".4453$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .4454" | ".4455$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .4456"<br/>\n".4457"</div>\n";4458 git_print_authorship(\%co, -tag =>'span');4459print"<br/>\n</div>\n";44604461print"<div class=\"log_body\">\n";4462 git_print_log($co{'comment'}, -final_empty_line=>1);4463print"</div>\n";4464}4465if($extra) {4466print"<div class=\"page_nav\">\n";4467print"$extra\n";4468print"</div>\n";4469}4470}44714472sub git_shortlog_body {4473# uses global variable $project4474my($commitlist,$from,$to,$refs,$extra) =@_;44754476$from=0unlessdefined$from;4477$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);44784479print"<table class=\"shortlog\">\n";4480my$alternate=1;4481for(my$i=$from;$i<=$to;$i++) {4482my%co= %{$commitlist->[$i]};4483my$commit=$co{'id'};4484my$ref= format_ref_marker($refs,$commit);4485if($alternate) {4486print"<tr class=\"dark\">\n";4487}else{4488print"<tr class=\"light\">\n";4489}4490$alternate^=1;4491# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4492print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4493 format_author_html('td', \%co,10) ."<td>";4494print format_subject_html($co{'title'},$co{'title_short'},4495 href(action=>"commit", hash=>$commit),$ref);4496print"</td>\n".4497"<td class=\"link\">".4498$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4499$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4500$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4501my$snapshot_links= format_snapshot_links($commit);4502if(defined$snapshot_links) {4503print" | ".$snapshot_links;4504}4505print"</td>\n".4506"</tr>\n";4507}4508if(defined$extra) {4509print"<tr>\n".4510"<td colspan=\"4\">$extra</td>\n".4511"</tr>\n";4512}4513print"</table>\n";4514}45154516sub git_history_body {4517# Warning: assumes constant type (blob or tree) during history4518my($commitlist,$from,$to,$refs,$extra,4519$file_name,$file_hash,$ftype) =@_;45204521$from=0unlessdefined$from;4522$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});45234524print"<table class=\"history\">\n";4525my$alternate=1;4526for(my$i=$from;$i<=$to;$i++) {4527my%co= %{$commitlist->[$i]};4528if(!%co) {4529next;4530}4531my$commit=$co{'id'};45324533my$ref= format_ref_marker($refs,$commit);45344535if($alternate) {4536print"<tr class=\"dark\">\n";4537}else{4538print"<tr class=\"light\">\n";4539}4540$alternate^=1;4541print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4542# shortlog: format_author_html('td', \%co, 10)4543 format_author_html('td', \%co,15,3) ."<td>";4544# originally git_history used chop_str($co{'title'}, 50)4545print format_subject_html($co{'title'},$co{'title_short'},4546 href(action=>"commit", hash=>$commit),$ref);4547print"</td>\n".4548"<td class=\"link\">".4549$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4550$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");45514552if($ftypeeq'blob') {4553my$blob_current=$file_hash;4554my$blob_parent= git_get_hash_by_path($commit,$file_name);4555if(defined$blob_current&&defined$blob_parent&&4556$blob_currentne$blob_parent) {4557print" | ".4558$cgi->a({-href => href(action=>"blobdiff",4559 hash=>$blob_current, hash_parent=>$blob_parent,4560 hash_base=>$hash_base, hash_parent_base=>$commit,4561 file_name=>$file_name)},4562"diff to current");4563}4564}4565print"</td>\n".4566"</tr>\n";4567}4568if(defined$extra) {4569print"<tr>\n".4570"<td colspan=\"4\">$extra</td>\n".4571"</tr>\n";4572}4573print"</table>\n";4574}45754576sub git_tags_body {4577# uses global variable $project4578my($taglist,$from,$to,$extra) =@_;4579$from=0unlessdefined$from;4580$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);45814582print"<table class=\"tags\">\n";4583my$alternate=1;4584for(my$i=$from;$i<=$to;$i++) {4585my$entry=$taglist->[$i];4586my%tag=%$entry;4587my$comment=$tag{'subject'};4588my$comment_short;4589if(defined$comment) {4590$comment_short= chop_str($comment,30,5);4591}4592if($alternate) {4593print"<tr class=\"dark\">\n";4594}else{4595print"<tr class=\"light\">\n";4596}4597$alternate^=1;4598if(defined$tag{'age'}) {4599print"<td><i>$tag{'age'}</i></td>\n";4600}else{4601print"<td></td>\n";4602}4603print"<td>".4604$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4605-class=>"list name"}, esc_html($tag{'name'})) .4606"</td>\n".4607"<td>";4608if(defined$comment) {4609print format_subject_html($comment,$comment_short,4610 href(action=>"tag", hash=>$tag{'id'}));4611}4612print"</td>\n".4613"<td class=\"selflink\">";4614if($tag{'type'}eq"tag") {4615print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4616}else{4617print" ";4618}4619print"</td>\n".4620"<td class=\"link\">"." | ".4621$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4622if($tag{'reftype'}eq"commit") {4623print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4624" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4625}elsif($tag{'reftype'}eq"blob") {4626print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4627}4628print"</td>\n".4629"</tr>";4630}4631if(defined$extra) {4632print"<tr>\n".4633"<td colspan=\"5\">$extra</td>\n".4634"</tr>\n";4635}4636print"</table>\n";4637}46384639sub git_heads_body {4640# uses global variable $project4641my($headlist,$head,$from,$to,$extra) =@_;4642$from=0unlessdefined$from;4643$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);46444645print"<table class=\"heads\">\n";4646my$alternate=1;4647for(my$i=$from;$i<=$to;$i++) {4648my$entry=$headlist->[$i];4649my%ref=%$entry;4650my$curr=$ref{'id'}eq$head;4651if($alternate) {4652print"<tr class=\"dark\">\n";4653}else{4654print"<tr class=\"light\">\n";4655}4656$alternate^=1;4657print"<td><i>$ref{'age'}</i></td>\n".4658($curr?"<td class=\"current_head\">":"<td>") .4659$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4660-class=>"list name"},esc_html($ref{'name'})) .4661"</td>\n".4662"<td class=\"link\">".4663$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4664$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4665$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4666"</td>\n".4667"</tr>";4668}4669if(defined$extra) {4670print"<tr>\n".4671"<td colspan=\"3\">$extra</td>\n".4672"</tr>\n";4673}4674print"</table>\n";4675}46764677sub git_search_grep_body {4678my($commitlist,$from,$to,$extra) =@_;4679$from=0unlessdefined$from;4680$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);46814682print"<table class=\"commit_search\">\n";4683my$alternate=1;4684for(my$i=$from;$i<=$to;$i++) {4685my%co= %{$commitlist->[$i]};4686if(!%co) {4687next;4688}4689my$commit=$co{'id'};4690if($alternate) {4691print"<tr class=\"dark\">\n";4692}else{4693print"<tr class=\"light\">\n";4694}4695$alternate^=1;4696print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4697 format_author_html('td', \%co,15,5) .4698"<td>".4699$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4700-class=>"list subject"},4701 chop_and_escape_str($co{'title'},50) ."<br/>");4702my$comment=$co{'comment'};4703foreachmy$line(@$comment) {4704if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4705my($lead,$match,$trail) = ($1,$2,$3);4706$match= chop_str($match,70,5,'center');4707my$contextlen=int((80-length($match))/2);4708$contextlen=30if($contextlen>30);4709$lead= chop_str($lead,$contextlen,10,'left');4710$trail= chop_str($trail,$contextlen,10,'right');47114712$lead= esc_html($lead);4713$match= esc_html($match);4714$trail= esc_html($trail);47154716print"$lead<span class=\"match\">$match</span>$trail<br />";4717}4718}4719print"</td>\n".4720"<td class=\"link\">".4721$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4722" | ".4723$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4724" | ".4725$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4726print"</td>\n".4727"</tr>\n";4728}4729if(defined$extra) {4730print"<tr>\n".4731"<td colspan=\"3\">$extra</td>\n".4732"</tr>\n";4733}4734print"</table>\n";4735}47364737## ======================================================================4738## ======================================================================4739## actions47404741sub git_project_list {4742my$order=$input_params{'order'};4743if(defined$order&&$order!~m/none|project|descr|owner|age/) {4744 die_error(400,"Unknown order parameter");4745}47464747my@list= git_get_projects_list();4748if(!@list) {4749 die_error(404,"No projects found");4750}47514752 git_header_html();4753if(-f $home_text) {4754print"<div class=\"index_include\">\n";4755 insert_file($home_text);4756print"</div>\n";4757}4758print$cgi->startform(-method=>"get") .4759"<p class=\"projsearch\">Search:\n".4760$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4761"</p>".4762$cgi->end_form() ."\n";4763 git_project_list_body(\@list,$order);4764 git_footer_html();4765}47664767sub git_forks {4768my$order=$input_params{'order'};4769if(defined$order&&$order!~m/none|project|descr|owner|age/) {4770 die_error(400,"Unknown order parameter");4771}47724773my@list= git_get_projects_list($project);4774if(!@list) {4775 die_error(404,"No forks found");4776}47774778 git_header_html();4779 git_print_page_nav('','');4780 git_print_header_div('summary',"$projectforks");4781 git_project_list_body(\@list,$order);4782 git_footer_html();4783}47844785sub git_project_index {4786my@projects= git_get_projects_list($project);47874788print$cgi->header(4789-type =>'text/plain',4790-charset =>'utf-8',4791-content_disposition =>'inline; filename="index.aux"');47924793foreachmy$pr(@projects) {4794if(!exists$pr->{'owner'}) {4795$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4796}47974798my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4799# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4800$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4801$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4802$path=~s/ /\+/g;4803$owner=~s/ /\+/g;48044805print"$path$owner\n";4806}4807}48084809sub git_summary {4810my$descr= git_get_project_description($project) ||"none";4811my%co= parse_commit("HEAD");4812my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4813my$head=$co{'id'};48144815my$owner= git_get_project_owner($project);48164817my$refs= git_get_references();4818# These get_*_list functions return one more to allow us to see if4819# there are more ...4820my@taglist= git_get_tags_list(16);4821my@headlist= git_get_heads_list(16);4822my@forklist;4823my$check_forks= gitweb_check_feature('forks');48244825if($check_forks) {4826@forklist= git_get_projects_list($project);4827}48284829 git_header_html();4830 git_print_page_nav('summary','',$head);48314832print"<div class=\"title\"> </div>\n";4833print"<table class=\"projects_list\">\n".4834"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4835"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4836if(defined$cd{'rfc2822'}) {4837print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4838}48394840# use per project git URL list in $projectroot/$project/cloneurl4841# or make project git URL from git base URL and project name4842my$url_tag="URL";4843my@url_list= git_get_project_url_list($project);4844@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4845foreachmy$git_url(@url_list) {4846next unless$git_url;4847print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4848$url_tag="";4849}48504851# Tag cloud4852my$show_ctags= gitweb_check_feature('ctags');4853if($show_ctags) {4854my$ctags= git_get_project_ctags($project);4855my$cloud= git_populate_project_tagcloud($ctags);4856print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4857print"</td>\n<td>"unless%$ctags;4858print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4859print"</td>\n<td>"if%$ctags;4860print git_show_project_tagcloud($cloud,48);4861print"</td></tr>";4862}48634864print"</table>\n";48654866# If XSS prevention is on, we don't include README.html.4867# TODO: Allow a readme in some safe format.4868if(!$prevent_xss&& -s "$projectroot/$project/README.html") {4869print"<div class=\"title\">readme</div>\n".4870"<div class=\"readme\">\n";4871 insert_file("$projectroot/$project/README.html");4872print"\n</div>\n";# class="readme"4873}48744875# we need to request one more than 16 (0..15) to check if4876# those 16 are all4877my@commitlist=$head? parse_commits($head,17) : ();4878if(@commitlist) {4879 git_print_header_div('shortlog');4880 git_shortlog_body(\@commitlist,0,15,$refs,4881$#commitlist<=15?undef:4882$cgi->a({-href => href(action=>"shortlog")},"..."));4883}48844885if(@taglist) {4886 git_print_header_div('tags');4887 git_tags_body(\@taglist,0,15,4888$#taglist<=15?undef:4889$cgi->a({-href => href(action=>"tags")},"..."));4890}48914892if(@headlist) {4893 git_print_header_div('heads');4894 git_heads_body(\@headlist,$head,0,15,4895$#headlist<=15?undef:4896$cgi->a({-href => href(action=>"heads")},"..."));4897}48984899if(@forklist) {4900 git_print_header_div('forks');4901 git_project_list_body(\@forklist,'age',0,15,4902$#forklist<=15?undef:4903$cgi->a({-href => href(action=>"forks")},"..."),4904'no_header');4905}49064907 git_footer_html();4908}49094910sub git_tag {4911my$head= git_get_head_hash($project);4912 git_header_html();4913 git_print_page_nav('','',$head,undef,$head);4914my%tag= parse_tag($hash);49154916if(!%tag) {4917 die_error(404,"Unknown tag object");4918}49194920 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4921print"<div class=\"title_text\">\n".4922"<table class=\"object_header\">\n".4923"<tr>\n".4924"<td>object</td>\n".4925"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4926$tag{'object'}) ."</td>\n".4927"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4928$tag{'type'}) ."</td>\n".4929"</tr>\n";4930if(defined($tag{'author'})) {4931 git_print_authorship_rows(\%tag,'author');4932}4933print"</table>\n\n".4934"</div>\n";4935print"<div class=\"page_body\">";4936my$comment=$tag{'comment'};4937foreachmy$line(@$comment) {4938chomp$line;4939print esc_html($line, -nbsp=>1) ."<br/>\n";4940}4941print"</div>\n";4942 git_footer_html();4943}49444945sub git_blame_common {4946my$format=shift||'porcelain';4947if($formateq'porcelain'&&$cgi->param('js')) {4948$format='incremental';4949$action='blame_incremental';# for page title etc4950}49514952# permissions4953 gitweb_check_feature('blame')4954or die_error(403,"Blame view not allowed");49554956# error checking4957 die_error(400,"No file name given")unless$file_name;4958$hash_base||= git_get_head_hash($project);4959 die_error(404,"Couldn't find base commit")unless$hash_base;4960my%co= parse_commit($hash_base)4961or die_error(404,"Commit not found");4962my$ftype="blob";4963if(!defined$hash) {4964$hash= git_get_hash_by_path($hash_base,$file_name,"blob")4965or die_error(404,"Error looking up file");4966}else{4967$ftype= git_get_type($hash);4968if($ftype!~"blob") {4969 die_error(400,"Object is not a blob");4970}4971}49724973my$fd;4974if($formateq'incremental') {4975# get file contents (as base)4976open$fd,"-|", git_cmd(),'cat-file','blob',$hash4977or die_error(500,"Open git-cat-file failed");4978}elsif($formateq'data') {4979# run git-blame --incremental4980open$fd,"-|", git_cmd(),"blame","--incremental",4981$hash_base,"--",$file_name4982or die_error(500,"Open git-blame --incremental failed");4983}else{4984# run git-blame --porcelain4985open$fd,"-|", git_cmd(),"blame",'-p',4986$hash_base,'--',$file_name4987or die_error(500,"Open git-blame --porcelain failed");4988}49894990# incremental blame data returns early4991if($formateq'data') {4992print$cgi->header(4993-type=>"text/plain", -charset =>"utf-8",4994-status=>"200 OK");4995local$| =1;# output autoflush4996printwhile<$fd>;4997close$fd4998or print"ERROR$!\n";49995000print'END';5001if(defined$t0&& gitweb_check_feature('timed')) {5002print' '.5003 Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).5004' '.$number_of_git_cmds;5005}5006print"\n";50075008return;5009}50105011# page header5012 git_header_html();5013my$formats_nav=5014$cgi->a({-href => href(action=>"blob", -replay=>1)},5015"blob") .5016" | ";5017if($formateq'incremental') {5018$formats_nav.=5019$cgi->a({-href => href(action=>"blame", javascript=>0, -replay=>1)},5020"blame") ." (non-incremental)";5021}else{5022$formats_nav.=5023$cgi->a({-href => href(action=>"blame_incremental", -replay=>1)},5024"blame") ." (incremental)";5025}5026$formats_nav.=5027" | ".5028$cgi->a({-href => href(action=>"history", -replay=>1)},5029"history") .5030" | ".5031$cgi->a({-href => href(action=>$action, file_name=>$file_name)},5032"HEAD");5033 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5034 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5035 git_print_page_path($file_name,$ftype,$hash_base);50365037# page body5038if($formateq'incremental') {5039print"<noscript>\n<div class=\"error\"><center><b>\n".5040"This page requires JavaScript to run.\nUse ".5041$cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},5042'this page').5043" instead.\n".5044"</b></center></div>\n</noscript>\n";50455046print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!;5047}50485049print qq!<div class="page_body">\n!;5050print qq!<div id="progress_info">.../ ...</div>\n!5051if($formateq'incremental');5052print qq!<table id="blame_table"class="blame" width="100%">\n!.5053#qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.5054 qq!<thead>\n!.5055 qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!.5056 qq!</thead>\n!.5057 qq!<tbody>\n!;50585059my@rev_color=qw(light dark);5060my$num_colors=scalar(@rev_color);5061my$current_color=0;50625063if($formateq'incremental') {5064my$color_class=$rev_color[$current_color];50655066#contents of a file5067my$linenr=0;5068 LINE:5069while(my$line= <$fd>) {5070chomp$line;5071$linenr++;50725073print qq!<tr id="l$linenr"class="$color_class">!.5074 qq!<td class="sha1"><a href=""> </a></td>!.5075 qq!<td class="linenr">!.5076 qq!<a class="linenr" href="">$linenr</a></td>!;5077print qq!<td class="pre">! . esc_html($line) ."</td>\n";5078print qq!</tr>\n!;5079}50805081}else{# porcelain, i.e. ordinary blame5082my%metainfo= ();# saves information about commits50835084# blame data5085 LINE:5086while(my$line= <$fd>) {5087chomp$line;5088# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]5089# no <lines in group> for subsequent lines in group of lines5090my($full_rev,$orig_lineno,$lineno,$group_size) =5091($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);5092if(!exists$metainfo{$full_rev}) {5093$metainfo{$full_rev} = {'nprevious'=>0};5094}5095my$meta=$metainfo{$full_rev};5096my$data;5097while($data= <$fd>) {5098chomp$data;5099last if($data=~s/^\t//);# contents of line5100if($data=~/^(\S+)(?: (.*))?$/) {5101$meta->{$1} =$2unlessexists$meta->{$1};5102}5103if($data=~/^previous /) {5104$meta->{'nprevious'}++;5105}5106}5107my$short_rev=substr($full_rev,0,8);5108my$author=$meta->{'author'};5109my%date=5110 parse_date($meta->{'author-time'},$meta->{'author-tz'});5111my$date=$date{'iso-tz'};5112if($group_size) {5113$current_color= ($current_color+1) %$num_colors;5114}5115my$tr_class=$rev_color[$current_color];5116$tr_class.=' boundary'if(exists$meta->{'boundary'});5117$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);5118$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);5119print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";5120if($group_size) {5121print"<td class=\"sha1\"";5122print" title=\"". esc_html($author) .",$date\"";5123print" rowspan=\"$group_size\""if($group_size>1);5124print">";5125print$cgi->a({-href => href(action=>"commit",5126 hash=>$full_rev,5127 file_name=>$file_name)},5128 esc_html($short_rev));5129if($group_size>=2) {5130my@author_initials= ($author=~/\b([[:upper:]])\B/g);5131if(@author_initials) {5132print"<br />".5133 esc_html(join('',@author_initials));5134# or join('.', ...)5135}5136}5137print"</td>\n";5138}5139# 'previous' <sha1 of parent commit> <filename at commit>5140if(exists$meta->{'previous'} &&5141$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {5142$meta->{'parent'} =$1;5143$meta->{'file_parent'} = unquote($2);5144}5145my$linenr_commit=5146exists($meta->{'parent'}) ?5147$meta->{'parent'} :$full_rev;5148my$linenr_filename=5149exists($meta->{'file_parent'}) ?5150$meta->{'file_parent'} : unquote($meta->{'filename'});5151my$blamed= href(action =>'blame',5152 file_name =>$linenr_filename,5153 hash_base =>$linenr_commit);5154print"<td class=\"linenr\">";5155print$cgi->a({ -href =>"$blamed#l$orig_lineno",5156-class=>"linenr"},5157 esc_html($lineno));5158print"</td>";5159print"<td class=\"pre\">". esc_html($data) ."</td>\n";5160print"</tr>\n";5161}# end while51625163}51645165# footer5166print"</tbody>\n".5167"</table>\n";# class="blame"5168print"</div>\n";# class="blame_body"5169close$fd5170or print"Reading blob failed\n";51715172 git_footer_html();5173}51745175sub git_blame {5176 git_blame_common();5177}51785179sub git_blame_incremental {5180 git_blame_common('incremental');5181}51825183sub git_blame_data {5184 git_blame_common('data');5185}51865187sub git_tags {5188my$head= git_get_head_hash($project);5189 git_header_html();5190 git_print_page_nav('','',$head,undef,$head);5191 git_print_header_div('summary',$project);51925193my@tagslist= git_get_tags_list();5194if(@tagslist) {5195 git_tags_body(\@tagslist);5196}5197 git_footer_html();5198}51995200sub git_heads {5201my$head= git_get_head_hash($project);5202 git_header_html();5203 git_print_page_nav('','',$head,undef,$head);5204 git_print_header_div('summary',$project);52055206my@headslist= git_get_heads_list();5207if(@headslist) {5208 git_heads_body(\@headslist,$head);5209}5210 git_footer_html();5211}52125213sub git_blob_plain {5214my$type=shift;5215my$expires;52165217if(!defined$hash) {5218if(defined$file_name) {5219my$base=$hash_base|| git_get_head_hash($project);5220$hash= git_get_hash_by_path($base,$file_name,"blob")5221or die_error(404,"Cannot find file");5222}else{5223 die_error(400,"No file name defined");5224}5225}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5226# blobs defined by non-textual hash id's can be cached5227$expires="+1d";5228}52295230open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5231or die_error(500,"Open git-cat-file blob '$hash' failed");52325233# content-type (can include charset)5234$type= blob_contenttype($fd,$file_name,$type);52355236# "save as" filename, even when no $file_name is given5237my$save_as="$hash";5238if(defined$file_name) {5239$save_as=$file_name;5240}elsif($type=~m/^text\//) {5241$save_as.='.txt';5242}52435244# With XSS prevention on, blobs of all types except a few known safe5245# ones are served with "Content-Disposition: attachment" to make sure5246# they don't run in our security domain. For certain image types,5247# blob view writes an <img> tag referring to blob_plain view, and we5248# want to be sure not to break that by serving the image as an5249# attachment (though Firefox 3 doesn't seem to care).5250my$sandbox=$prevent_xss&&5251$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;52525253print$cgi->header(5254-type =>$type,5255-expires =>$expires,5256-content_disposition =>5257($sandbox?'attachment':'inline')5258.'; filename="'.$save_as.'"');5259local$/=undef;5260binmode STDOUT,':raw';5261print<$fd>;5262binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5263close$fd;5264}52655266sub git_blob {5267my$expires;52685269if(!defined$hash) {5270if(defined$file_name) {5271my$base=$hash_base|| git_get_head_hash($project);5272$hash= git_get_hash_by_path($base,$file_name,"blob")5273or die_error(404,"Cannot find file");5274}else{5275 die_error(400,"No file name defined");5276}5277}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5278# blobs defined by non-textual hash id's can be cached5279$expires="+1d";5280}52815282my$have_blame= gitweb_check_feature('blame');5283open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5284or die_error(500,"Couldn't cat$file_name,$hash");5285my$mimetype= blob_mimetype($fd,$file_name);5286if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {5287close$fd;5288return git_blob_plain($mimetype);5289}5290# we can have blame only for text/* mimetype5291$have_blame&&= ($mimetype=~m!^text/!);52925293 git_header_html(undef,$expires);5294my$formats_nav='';5295if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5296if(defined$file_name) {5297if($have_blame) {5298$formats_nav.=5299$cgi->a({-href => href(action=>"blame", -replay=>1)},5300"blame") .5301" | ";5302}5303$formats_nav.=5304$cgi->a({-href => href(action=>"history", -replay=>1)},5305"history") .5306" | ".5307$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5308"raw") .5309" | ".5310$cgi->a({-href => href(action=>"blob",5311 hash_base=>"HEAD", file_name=>$file_name)},5312"HEAD");5313}else{5314$formats_nav.=5315$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5316"raw");5317}5318 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5319 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5320}else{5321print"<div class=\"page_nav\">\n".5322"<br/><br/></div>\n".5323"<div class=\"title\">".esc_html($hash)."</div>\n";5324}5325 git_print_page_path($file_name,"blob",$hash_base);5326print"<div class=\"page_body\">\n";5327if($mimetype=~m!^image/!) {5328print qq!<img type="!.esc_attr($mimetype).qq!"!;5329if($file_name) {5330print qq! alt="!.esc_attr($file_name).qq!" title="!.esc_attr($file_name).qq!"!;5331}5332print qq! src="! .5333 href(action=>"blob_plain", hash=>$hash,5334 hash_base=>$hash_base, file_name=>$file_name) .5335 qq!"/>\n!;5336}else{5337my$nr;5338while(my$line= <$fd>) {5339chomp$line;5340$nr++;5341$line= untabify($line);5342printf"<div class=\"pre\"><a id=\"l%i\"href=\""5343. esc_attr(href(-replay =>1))5344."#l%i\"class=\"linenr\">%4i</a>%s</div>\n",5345$nr,$nr,$nr, esc_html($line, -nbsp=>1);5346}5347}5348close$fd5349or print"Reading blob failed.\n";5350print"</div>";5351 git_footer_html();5352}53535354sub git_tree {5355if(!defined$hash_base) {5356$hash_base="HEAD";5357}5358if(!defined$hash) {5359if(defined$file_name) {5360$hash= git_get_hash_by_path($hash_base,$file_name,"tree");5361}else{5362$hash=$hash_base;5363}5364}5365 die_error(404,"No such tree")unlessdefined($hash);53665367my$show_sizes= gitweb_check_feature('show-sizes');5368my$have_blame= gitweb_check_feature('blame');53695370my@entries= ();5371{5372local$/="\0";5373open my$fd,"-|", git_cmd(),"ls-tree",'-z',5374($show_sizes?'-l': ()),@extra_options,$hash5375or die_error(500,"Open git-ls-tree failed");5376@entries=map{chomp;$_} <$fd>;5377close$fd5378or die_error(404,"Reading tree failed");5379}53805381my$refs= git_get_references();5382my$ref= format_ref_marker($refs,$hash_base);5383 git_header_html();5384my$basedir='';5385if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5386my@views_nav= ();5387if(defined$file_name) {5388push@views_nav,5389$cgi->a({-href => href(action=>"history", -replay=>1)},5390"history"),5391$cgi->a({-href => href(action=>"tree",5392 hash_base=>"HEAD", file_name=>$file_name)},5393"HEAD"),5394}5395my$snapshot_links= format_snapshot_links($hash);5396if(defined$snapshot_links) {5397# FIXME: Should be available when we have no hash base as well.5398push@views_nav,$snapshot_links;5399}5400 git_print_page_nav('tree','',$hash_base,undef,undef,5401join(' | ',@views_nav));5402 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);5403}else{5404undef$hash_base;5405print"<div class=\"page_nav\">\n";5406print"<br/><br/></div>\n";5407print"<div class=\"title\">".esc_html($hash)."</div>\n";5408}5409if(defined$file_name) {5410$basedir=$file_name;5411if($basedirne''&&substr($basedir, -1)ne'/') {5412$basedir.='/';5413}5414 git_print_page_path($file_name,'tree',$hash_base);5415}5416print"<div class=\"page_body\">\n";5417print"<table class=\"tree\">\n";5418my$alternate=1;5419# '..' (top directory) link if possible5420if(defined$hash_base&&5421defined$file_name&&$file_name=~m![^/]+$!) {5422if($alternate) {5423print"<tr class=\"dark\">\n";5424}else{5425print"<tr class=\"light\">\n";5426}5427$alternate^=1;54285429my$up=$file_name;5430$up=~s!/?[^/]+$!!;5431undef$upunless$up;5432# based on git_print_tree_entry5433print'<td class="mode">'. mode_str('040000') ."</td>\n";5434print'<td class="size"> </td>'."\n"if$show_sizes;5435print'<td class="list">';5436print$cgi->a({-href => href(action=>"tree",5437 hash_base=>$hash_base,5438 file_name=>$up)},5439"..");5440print"</td>\n";5441print"<td class=\"link\"></td>\n";54425443print"</tr>\n";5444}5445foreachmy$line(@entries) {5446my%t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);54475448if($alternate) {5449print"<tr class=\"dark\">\n";5450}else{5451print"<tr class=\"light\">\n";5452}5453$alternate^=1;54545455 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);54565457print"</tr>\n";5458}5459print"</table>\n".5460"</div>";5461 git_footer_html();5462}54635464sub snapshot_name {5465my($project,$hash) =@_;54665467# path/to/project.git -> project5468# path/to/project/.git -> project5469my$name= to_utf8($project);5470$name=~ s,([^/])/*\.git$,$1,;5471$name= basename($name);5472# sanitize name5473$name=~s/[[:cntrl:]]/?/g;54745475my$ver=$hash;5476if($hash=~/^[0-9a-fA-F]+$/) {5477# shorten SHA-1 hash5478my$full_hash= git_get_full_hash($project,$hash);5479if($full_hash=~/^$hash/&&length($hash) >7) {5480$ver= git_get_short_hash($project,$hash);5481}5482}elsif($hash=~m!^refs/tags/(.*)$!) {5483# tags don't need shortened SHA-1 hash5484$ver=$1;5485}else{5486# branches and other need shortened SHA-1 hash5487if($hash=~m!^refs/(?:heads|remotes)/(.*)$!) {5488$ver=$1;5489}5490$ver.='-'. git_get_short_hash($project,$hash);5491}5492# in case of hierarchical branch names5493$ver=~s!/!.!g;54945495# name = project-version_string5496$name="$name-$ver";54975498returnwantarray? ($name,$name) :$name;5499}55005501sub git_snapshot {5502my$format=$input_params{'snapshot_format'};5503if(!@snapshot_fmts) {5504 die_error(403,"Snapshots not allowed");5505}5506# default to first supported snapshot format5507$format||=$snapshot_fmts[0];5508if($format!~m/^[a-z0-9]+$/) {5509 die_error(400,"Invalid snapshot format parameter");5510}elsif(!exists($known_snapshot_formats{$format})) {5511 die_error(400,"Unknown snapshot format");5512}elsif($known_snapshot_formats{$format}{'disabled'}) {5513 die_error(403,"Snapshot format not allowed");5514}elsif(!grep($_eq$format,@snapshot_fmts)) {5515 die_error(403,"Unsupported snapshot format");5516}55175518my$type= git_get_type("$hash^{}");5519if(!$type) {5520 die_error(404,'Object does not exist');5521}elsif($typeeq'blob') {5522 die_error(400,'Object is not a tree-ish');5523}55245525my($name,$prefix) = snapshot_name($project,$hash);5526my$filename="$name$known_snapshot_formats{$format}{'suffix'}";5527my$cmd= quote_command(5528 git_cmd(),'archive',5529"--format=$known_snapshot_formats{$format}{'format'}",5530"--prefix=$prefix/",$hash);5531if(exists$known_snapshot_formats{$format}{'compressor'}) {5532$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});5533}55345535$filename=~s/(["\\])/\\$1/g;5536print$cgi->header(5537-type =>$known_snapshot_formats{$format}{'type'},5538-content_disposition =>'inline; filename="'.$filename.'"',5539-status =>'200 OK');55405541open my$fd,"-|",$cmd5542or die_error(500,"Execute git-archive failed");5543binmode STDOUT,':raw';5544print<$fd>;5545binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5546close$fd;5547}55485549sub git_log_generic {5550my($fmt_name,$body_subr,$base,$parent,$file_name,$file_hash) =@_;55515552my$head= git_get_head_hash($project);5553if(!defined$base) {5554$base=$head;5555}5556if(!defined$page) {5557$page=0;5558}5559my$refs= git_get_references();55605561my$commit_hash=$base;5562if(defined$parent) {5563$commit_hash="$parent..$base";5564}5565my@commitlist=5566 parse_commits($commit_hash,101, (100*$page),5567defined$file_name? ($file_name,"--full-history") : ());55685569my$ftype;5570if(!defined$file_hash&&defined$file_name) {5571# some commits could have deleted file in question,5572# and not have it in tree, but one of them has to have it5573for(my$i=0;$i<@commitlist;$i++) {5574$file_hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5575last ifdefined$file_hash;5576}5577}5578if(defined$file_hash) {5579$ftype= git_get_type($file_hash);5580}5581if(defined$file_name&& !defined$ftype) {5582 die_error(500,"Unknown type of object");5583}5584my%co;5585if(defined$file_name) {5586%co= parse_commit($base)5587or die_error(404,"Unknown commit object");5588}558955905591my$paging_nav= format_paging_nav($fmt_name,$page,$#commitlist>=100);5592my$next_link='';5593if($#commitlist>=100) {5594$next_link=5595$cgi->a({-href => href(-replay=>1, page=>$page+1),5596-accesskey =>"n", -title =>"Alt-n"},"next");5597}5598my$patch_max= gitweb_get_feature('patches');5599if($patch_max&& !defined$file_name) {5600if($patch_max<0||@commitlist<=$patch_max) {5601$paging_nav.=" ⋅ ".5602$cgi->a({-href => href(action=>"patches", -replay=>1)},5603"patches");5604}5605}56065607 git_header_html();5608 git_print_page_nav($fmt_name,'',$hash,$hash,$hash,$paging_nav);5609if(defined$file_name) {5610 git_print_header_div('commit', esc_html($co{'title'}),$base);5611}else{5612 git_print_header_div('summary',$project)5613}5614 git_print_page_path($file_name,$ftype,$hash_base)5615if(defined$file_name);56165617$body_subr->(\@commitlist,0,99,$refs,$next_link,5618$file_name,$file_hash,$ftype);56195620 git_footer_html();5621}56225623sub git_log {5624 git_log_generic('log', \&git_log_body,5625$hash,$hash_parent);5626}56275628sub git_commit {5629$hash||=$hash_base||"HEAD";5630my%co= parse_commit($hash)5631or die_error(404,"Unknown commit object");56325633my$parent=$co{'parent'};5634my$parents=$co{'parents'};# listref56355636# we need to prepare $formats_nav before any parameter munging5637my$formats_nav;5638if(!defined$parent) {5639# --root commitdiff5640$formats_nav.='(initial)';5641}elsif(@$parents==1) {5642# single parent commit5643$formats_nav.=5644'(parent: '.5645$cgi->a({-href => href(action=>"commit",5646 hash=>$parent)},5647 esc_html(substr($parent,0,7))) .5648')';5649}else{5650# merge commit5651$formats_nav.=5652'(merge: '.5653join(' ',map{5654$cgi->a({-href => href(action=>"commit",5655 hash=>$_)},5656 esc_html(substr($_,0,7)));5657}@$parents) .5658')';5659}5660if(gitweb_check_feature('patches') &&@$parents<=1) {5661$formats_nav.=" | ".5662$cgi->a({-href => href(action=>"patch", -replay=>1)},5663"patch");5664}56655666if(!defined$parent) {5667$parent="--root";5668}5669my@difftree;5670open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5671@diff_opts,5672(@$parents<=1?$parent:'-c'),5673$hash,"--"5674or die_error(500,"Open git-diff-tree failed");5675@difftree=map{chomp;$_} <$fd>;5676close$fdor die_error(404,"Reading git-diff-tree failed");56775678# non-textual hash id's can be cached5679my$expires;5680if($hash=~m/^[0-9a-fA-F]{40}$/) {5681$expires="+1d";5682}5683my$refs= git_get_references();5684my$ref= format_ref_marker($refs,$co{'id'});56855686 git_header_html(undef,$expires);5687 git_print_page_nav('commit','',5688$hash,$co{'tree'},$hash,5689$formats_nav);56905691if(defined$co{'parent'}) {5692 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5693}else{5694 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5695}5696print"<div class=\"title_text\">\n".5697"<table class=\"object_header\">\n";5698 git_print_authorship_rows(\%co);5699print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";5700print"<tr>".5701"<td>tree</td>".5702"<td class=\"sha1\">".5703$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),5704class=>"list"},$co{'tree'}) .5705"</td>".5706"<td class=\"link\">".5707$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},5708"tree");5709my$snapshot_links= format_snapshot_links($hash);5710if(defined$snapshot_links) {5711print" | ".$snapshot_links;5712}5713print"</td>".5714"</tr>\n";57155716foreachmy$par(@$parents) {5717print"<tr>".5718"<td>parent</td>".5719"<td class=\"sha1\">".5720$cgi->a({-href => href(action=>"commit", hash=>$par),5721class=>"list"},$par) .5722"</td>".5723"<td class=\"link\">".5724$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .5725" | ".5726$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .5727"</td>".5728"</tr>\n";5729}5730print"</table>".5731"</div>\n";57325733print"<div class=\"page_body\">\n";5734 git_print_log($co{'comment'});5735print"</div>\n";57365737 git_difftree_body(\@difftree,$hash,@$parents);57385739 git_footer_html();5740}57415742sub git_object {5743# object is defined by:5744# - hash or hash_base alone5745# - hash_base and file_name5746my$type;57475748# - hash or hash_base alone5749if($hash|| ($hash_base&& !defined$file_name)) {5750my$object_id=$hash||$hash_base;57515752open my$fd,"-|", quote_command(5753 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'5754or die_error(404,"Object does not exist");5755$type= <$fd>;5756chomp$type;5757close$fd5758or die_error(404,"Object does not exist");57595760# - hash_base and file_name5761}elsif($hash_base&&defined$file_name) {5762$file_name=~ s,/+$,,;57635764system(git_cmd(),"cat-file",'-e',$hash_base) ==05765or die_error(404,"Base object does not exist");57665767# here errors should not hapen5768open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name5769or die_error(500,"Open git-ls-tree failed");5770my$line= <$fd>;5771close$fd;57725773#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'5774unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {5775 die_error(404,"File or directory for given base does not exist");5776}5777$type=$2;5778$hash=$3;5779}else{5780 die_error(400,"Not enough information to find object");5781}57825783print$cgi->redirect(-uri => href(action=>$type, -full=>1,5784 hash=>$hash, hash_base=>$hash_base,5785 file_name=>$file_name),5786-status =>'302 Found');5787}57885789sub git_blobdiff {5790my$format=shift||'html';57915792my$fd;5793my@difftree;5794my%diffinfo;5795my$expires;57965797# preparing $fd and %diffinfo for git_patchset_body5798# new style URI5799if(defined$hash_base&&defined$hash_parent_base) {5800if(defined$file_name) {5801# read raw output5802open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5803$hash_parent_base,$hash_base,5804"--", (defined$file_parent?$file_parent: ()),$file_name5805or die_error(500,"Open git-diff-tree failed");5806@difftree=map{chomp;$_} <$fd>;5807close$fd5808or die_error(404,"Reading git-diff-tree failed");5809@difftree5810or die_error(404,"Blob diff not found");58115812}elsif(defined$hash&&5813$hash=~/[0-9a-fA-F]{40}/) {5814# try to find filename from $hash58155816# read filtered raw output5817open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5818$hash_parent_base,$hash_base,"--"5819or die_error(500,"Open git-diff-tree failed");5820@difftree=5821# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5822# $hash == to_id5823grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5824map{chomp;$_} <$fd>;5825close$fd5826or die_error(404,"Reading git-diff-tree failed");5827@difftree5828or die_error(404,"Blob diff not found");58295830}else{5831 die_error(400,"Missing one of the blob diff parameters");5832}58335834if(@difftree>1) {5835 die_error(400,"Ambiguous blob diff specification");5836}58375838%diffinfo= parse_difftree_raw_line($difftree[0]);5839$file_parent||=$diffinfo{'from_file'} ||$file_name;5840$file_name||=$diffinfo{'to_file'};58415842$hash_parent||=$diffinfo{'from_id'};5843$hash||=$diffinfo{'to_id'};58445845# non-textual hash id's can be cached5846if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5847$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5848$expires='+1d';5849}58505851# open patch output5852open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5853'-p', ($formateq'html'?"--full-index": ()),5854$hash_parent_base,$hash_base,5855"--", (defined$file_parent?$file_parent: ()),$file_name5856or die_error(500,"Open git-diff-tree failed");5857}58585859# old/legacy style URI -- not generated anymore since 1.4.3.5860if(!%diffinfo) {5861 die_error('404 Not Found',"Missing one of the blob diff parameters")5862}58635864# header5865if($formateq'html') {5866my$formats_nav=5867$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5868"raw");5869 git_header_html(undef,$expires);5870if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5871 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5872 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5873}else{5874print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5875print"<div class=\"title\">".esc_html("$hashvs$hash_parent")."</div>\n";5876}5877if(defined$file_name) {5878 git_print_page_path($file_name,"blob",$hash_base);5879}else{5880print"<div class=\"page_path\"></div>\n";5881}58825883}elsif($formateq'plain') {5884print$cgi->header(5885-type =>'text/plain',5886-charset =>'utf-8',5887-expires =>$expires,5888-content_disposition =>'inline; filename="'."$file_name".'.patch"');58895890print"X-Git-Url: ".$cgi->self_url() ."\n\n";58915892}else{5893 die_error(400,"Unknown blobdiff format");5894}58955896# patch5897if($formateq'html') {5898print"<div class=\"page_body\">\n";58995900 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5901close$fd;59025903print"</div>\n";# class="page_body"5904 git_footer_html();59055906}else{5907while(my$line= <$fd>) {5908$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5909$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;59105911print$line;59125913last if$line=~m!^\+\+\+!;5914}5915local$/=undef;5916print<$fd>;5917close$fd;5918}5919}59205921sub git_blobdiff_plain {5922 git_blobdiff('plain');5923}59245925sub git_commitdiff {5926my%params=@_;5927my$format=$params{-format} ||'html';59285929my($patch_max) = gitweb_get_feature('patches');5930if($formateq'patch') {5931 die_error(403,"Patch view not allowed")unless$patch_max;5932}59335934$hash||=$hash_base||"HEAD";5935my%co= parse_commit($hash)5936or die_error(404,"Unknown commit object");59375938# choose format for commitdiff for merge5939if(!defined$hash_parent&& @{$co{'parents'}} >1) {5940$hash_parent='--cc';5941}5942# we need to prepare $formats_nav before almost any parameter munging5943my$formats_nav;5944if($formateq'html') {5945$formats_nav=5946$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},5947"raw");5948if($patch_max&& @{$co{'parents'}} <=1) {5949$formats_nav.=" | ".5950$cgi->a({-href => href(action=>"patch", -replay=>1)},5951"patch");5952}59535954if(defined$hash_parent&&5955$hash_parentne'-c'&&$hash_parentne'--cc') {5956# commitdiff with two commits given5957my$hash_parent_short=$hash_parent;5958if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {5959$hash_parent_short=substr($hash_parent,0,7);5960}5961$formats_nav.=5962' (from';5963for(my$i=0;$i< @{$co{'parents'}};$i++) {5964if($co{'parents'}[$i]eq$hash_parent) {5965$formats_nav.=' parent '. ($i+1);5966last;5967}5968}5969$formats_nav.=': '.5970$cgi->a({-href => href(action=>"commitdiff",5971 hash=>$hash_parent)},5972 esc_html($hash_parent_short)) .5973')';5974}elsif(!$co{'parent'}) {5975# --root commitdiff5976$formats_nav.=' (initial)';5977}elsif(scalar@{$co{'parents'}} ==1) {5978# single parent commit5979$formats_nav.=5980' (parent: '.5981$cgi->a({-href => href(action=>"commitdiff",5982 hash=>$co{'parent'})},5983 esc_html(substr($co{'parent'},0,7))) .5984')';5985}else{5986# merge commit5987if($hash_parenteq'--cc') {5988$formats_nav.=' | '.5989$cgi->a({-href => href(action=>"commitdiff",5990 hash=>$hash, hash_parent=>'-c')},5991'combined');5992}else{# $hash_parent eq '-c'5993$formats_nav.=' | '.5994$cgi->a({-href => href(action=>"commitdiff",5995 hash=>$hash, hash_parent=>'--cc')},5996'compact');5997}5998$formats_nav.=5999' (merge: '.6000join(' ',map{6001$cgi->a({-href => href(action=>"commitdiff",6002 hash=>$_)},6003 esc_html(substr($_,0,7)));6004} @{$co{'parents'}} ) .6005')';6006}6007}60086009my$hash_parent_param=$hash_parent;6010if(!defined$hash_parent_param) {6011# --cc for multiple parents, --root for parentless6012$hash_parent_param=6013@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';6014}60156016# read commitdiff6017my$fd;6018my@difftree;6019if($formateq'html') {6020open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6021"--no-commit-id","--patch-with-raw","--full-index",6022$hash_parent_param,$hash,"--"6023or die_error(500,"Open git-diff-tree failed");60246025while(my$line= <$fd>) {6026chomp$line;6027# empty line ends raw part of diff-tree output6028last unless$line;6029push@difftree,scalar parse_difftree_raw_line($line);6030}60316032}elsif($formateq'plain') {6033open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6034'-p',$hash_parent_param,$hash,"--"6035or die_error(500,"Open git-diff-tree failed");6036}elsif($formateq'patch') {6037# For commit ranges, we limit the output to the number of6038# patches specified in the 'patches' feature.6039# For single commits, we limit the output to a single patch,6040# diverging from the git-format-patch default.6041my@commit_spec= ();6042if($hash_parent) {6043if($patch_max>0) {6044push@commit_spec,"-$patch_max";6045}6046push@commit_spec,'-n',"$hash_parent..$hash";6047}else{6048if($params{-single}) {6049push@commit_spec,'-1';6050}else{6051if($patch_max>0) {6052push@commit_spec,"-$patch_max";6053}6054push@commit_spec,"-n";6055}6056push@commit_spec,'--root',$hash;6057}6058open$fd,"-|", git_cmd(),"format-patch",'--encoding=utf8',6059'--stdout',@commit_spec6060or die_error(500,"Open git-format-patch failed");6061}else{6062 die_error(400,"Unknown commitdiff format");6063}60646065# non-textual hash id's can be cached6066my$expires;6067if($hash=~m/^[0-9a-fA-F]{40}$/) {6068$expires="+1d";6069}60706071# write commit message6072if($formateq'html') {6073my$refs= git_get_references();6074my$ref= format_ref_marker($refs,$co{'id'});60756076 git_header_html(undef,$expires);6077 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);6078 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);6079print"<div class=\"title_text\">\n".6080"<table class=\"object_header\">\n";6081 git_print_authorship_rows(\%co);6082print"</table>".6083"</div>\n";6084print"<div class=\"page_body\">\n";6085if(@{$co{'comment'}} >1) {6086print"<div class=\"log\">\n";6087 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);6088print"</div>\n";# class="log"6089}60906091}elsif($formateq'plain') {6092my$refs= git_get_references("tags");6093my$tagname= git_get_rev_name_tags($hash);6094my$filename= basename($project) ."-$hash.patch";60956096print$cgi->header(6097-type =>'text/plain',6098-charset =>'utf-8',6099-expires =>$expires,6100-content_disposition =>'inline; filename="'."$filename".'"');6101my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});6102print"From: ". to_utf8($co{'author'}) ."\n";6103print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";6104print"Subject: ". to_utf8($co{'title'}) ."\n";61056106print"X-Git-Tag:$tagname\n"if$tagname;6107print"X-Git-Url: ".$cgi->self_url() ."\n\n";61086109foreachmy$line(@{$co{'comment'}}) {6110print to_utf8($line) ."\n";6111}6112print"---\n\n";6113}elsif($formateq'patch') {6114my$filename= basename($project) ."-$hash.patch";61156116print$cgi->header(6117-type =>'text/plain',6118-charset =>'utf-8',6119-expires =>$expires,6120-content_disposition =>'inline; filename="'."$filename".'"');6121}61226123# write patch6124if($formateq'html') {6125my$use_parents= !defined$hash_parent||6126$hash_parenteq'-c'||$hash_parenteq'--cc';6127 git_difftree_body(\@difftree,$hash,6128$use_parents? @{$co{'parents'}} :$hash_parent);6129print"<br/>\n";61306131 git_patchset_body($fd, \@difftree,$hash,6132$use_parents? @{$co{'parents'}} :$hash_parent);6133close$fd;6134print"</div>\n";# class="page_body"6135 git_footer_html();61366137}elsif($formateq'plain') {6138local$/=undef;6139print<$fd>;6140close$fd6141or print"Reading git-diff-tree failed\n";6142}elsif($formateq'patch') {6143local$/=undef;6144print<$fd>;6145close$fd6146or print"Reading git-format-patch failed\n";6147}6148}61496150sub git_commitdiff_plain {6151 git_commitdiff(-format =>'plain');6152}61536154# format-patch-style patches6155sub git_patch {6156 git_commitdiff(-format =>'patch', -single =>1);6157}61586159sub git_patches {6160 git_commitdiff(-format =>'patch');6161}61626163sub git_history {6164 git_log_generic('history', \&git_history_body,6165$hash_base,$hash_parent_base,6166$file_name,$hash);6167}61686169sub git_search {6170 gitweb_check_feature('search')or die_error(403,"Search is disabled");6171if(!defined$searchtext) {6172 die_error(400,"Text field is empty");6173}6174if(!defined$hash) {6175$hash= git_get_head_hash($project);6176}6177my%co= parse_commit($hash);6178if(!%co) {6179 die_error(404,"Unknown commit object");6180}6181if(!defined$page) {6182$page=0;6183}61846185$searchtype||='commit';6186if($searchtypeeq'pickaxe') {6187# pickaxe may take all resources of your box and run for several minutes6188# with every query - so decide by yourself how public you make this feature6189 gitweb_check_feature('pickaxe')6190or die_error(403,"Pickaxe is disabled");6191}6192if($searchtypeeq'grep') {6193 gitweb_check_feature('grep')6194or die_error(403,"Grep is disabled");6195}61966197 git_header_html();61986199if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {6200my$greptype;6201if($searchtypeeq'commit') {6202$greptype="--grep=";6203}elsif($searchtypeeq'author') {6204$greptype="--author=";6205}elsif($searchtypeeq'committer') {6206$greptype="--committer=";6207}6208$greptype.=$searchtext;6209my@commitlist= parse_commits($hash,101, (100*$page),undef,6210$greptype,'--regexp-ignore-case',6211$search_use_regexp?'--extended-regexp':'--fixed-strings');62126213my$paging_nav='';6214if($page>0) {6215$paging_nav.=6216$cgi->a({-href => href(action=>"search", hash=>$hash,6217 searchtext=>$searchtext,6218 searchtype=>$searchtype)},6219"first");6220$paging_nav.=" ⋅ ".6221$cgi->a({-href => href(-replay=>1, page=>$page-1),6222-accesskey =>"p", -title =>"Alt-p"},"prev");6223}else{6224$paging_nav.="first";6225$paging_nav.=" ⋅ prev";6226}6227my$next_link='';6228if($#commitlist>=100) {6229$next_link=6230$cgi->a({-href => href(-replay=>1, page=>$page+1),6231-accesskey =>"n", -title =>"Alt-n"},"next");6232$paging_nav.=" ⋅$next_link";6233}else{6234$paging_nav.=" ⋅ next";6235}62366237if($#commitlist>=100) {6238}62396240 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);6241 git_print_header_div('commit', esc_html($co{'title'}),$hash);6242 git_search_grep_body(\@commitlist,0,99,$next_link);6243}62446245if($searchtypeeq'pickaxe') {6246 git_print_page_nav('','',$hash,$co{'tree'},$hash);6247 git_print_header_div('commit', esc_html($co{'title'}),$hash);62486249print"<table class=\"pickaxe search\">\n";6250my$alternate=1;6251local$/="\n";6252open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,6253'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",6254($search_use_regexp?'--pickaxe-regex': ());6255undef%co;6256my@files;6257while(my$line= <$fd>) {6258chomp$line;6259next unless$line;62606261my%set= parse_difftree_raw_line($line);6262if(defined$set{'commit'}) {6263# finish previous commit6264if(%co) {6265print"</td>\n".6266"<td class=\"link\">".6267$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6268" | ".6269$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6270print"</td>\n".6271"</tr>\n";6272}62736274if($alternate) {6275print"<tr class=\"dark\">\n";6276}else{6277print"<tr class=\"light\">\n";6278}6279$alternate^=1;6280%co= parse_commit($set{'commit'});6281my$author= chop_and_escape_str($co{'author_name'},15,5);6282print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6283"<td><i>$author</i></td>\n".6284"<td>".6285$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6286-class=>"list subject"},6287 chop_and_escape_str($co{'title'},50) ."<br/>");6288}elsif(defined$set{'to_id'}) {6289next if($set{'to_id'} =~m/^0{40}$/);62906291print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6292 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6293-class=>"list"},6294"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6295"<br/>\n";6296}6297}6298close$fd;62996300# finish last commit (warning: repetition!)6301if(%co) {6302print"</td>\n".6303"<td class=\"link\">".6304$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6305" | ".6306$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6307print"</td>\n".6308"</tr>\n";6309}63106311print"</table>\n";6312}63136314if($searchtypeeq'grep') {6315 git_print_page_nav('','',$hash,$co{'tree'},$hash);6316 git_print_header_div('commit', esc_html($co{'title'}),$hash);63176318print"<table class=\"grep_search\">\n";6319my$alternate=1;6320my$matches=0;6321local$/="\n";6322open my$fd,"-|", git_cmd(),'grep','-n',6323$search_use_regexp? ('-E','-i') :'-F',6324$searchtext,$co{'tree'};6325my$lastfile='';6326while(my$line= <$fd>) {6327chomp$line;6328my($file,$lno,$ltext,$binary);6329last if($matches++>1000);6330if($line=~/^Binary file (.+) matches$/) {6331$file=$1;6332$binary=1;6333}else{6334(undef,$file,$lno,$ltext) =split(/:/,$line,4);6335}6336if($filene$lastfile) {6337$lastfileand print"</td></tr>\n";6338if($alternate++) {6339print"<tr class=\"dark\">\n";6340}else{6341print"<tr class=\"light\">\n";6342}6343print"<td class=\"list\">".6344$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6345 file_name=>"$file"),6346-class=>"list"}, esc_path($file));6347print"</td><td>\n";6348$lastfile=$file;6349}6350if($binary) {6351print"<div class=\"binary\">Binary file</div>\n";6352}else{6353$ltext= untabify($ltext);6354if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6355$ltext= esc_html($1, -nbsp=>1);6356$ltext.='<span class="match">';6357$ltext.= esc_html($2, -nbsp=>1);6358$ltext.='</span>';6359$ltext.= esc_html($3, -nbsp=>1);6360}else{6361$ltext= esc_html($ltext, -nbsp=>1);6362}6363print"<div class=\"pre\">".6364$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6365 file_name=>"$file").'#l'.$lno,6366-class=>"linenr"},sprintf('%4i',$lno))6367.' '.$ltext."</div>\n";6368}6369}6370if($lastfile) {6371print"</td></tr>\n";6372if($matches>1000) {6373print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6374}6375}else{6376print"<div class=\"diff nodifferences\">No matches found</div>\n";6377}6378close$fd;63796380print"</table>\n";6381}6382 git_footer_html();6383}63846385sub git_search_help {6386 git_header_html();6387 git_print_page_nav('','',$hash,$hash,$hash);6388print<<EOT;6389<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without6390regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,6391the pattern entered is recognized as the POSIX extended6392<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case6393insensitive).</p>6394<dl>6395<dt><b>commit</b></dt>6396<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>6397EOT6398my$have_grep= gitweb_check_feature('grep');6399if($have_grep) {6400print<<EOT;6401<dt><b>grep</b></dt>6402<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing6403 a different one) are searched for the given pattern. On large trees, this search can take6404a while and put some strain on the server, so please use it with some consideration. Note that6405due to git-grep peculiarity, currently if regexp mode is turned off, the matches are6406case-sensitive.</dd>6407EOT6408}6409print<<EOT;6410<dt><b>author</b></dt>6411<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>6412<dt><b>committer</b></dt>6413<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>6414EOT6415my$have_pickaxe= gitweb_check_feature('pickaxe');6416if($have_pickaxe) {6417print<<EOT;6418<dt><b>pickaxe</b></dt>6419<dd>All commits that caused the string to appear or disappear from any file (changes that6420added, removed or "modified" the string) will be listed. This search can take a while and6421takes a lot of strain on the server, so please use it wisely. Note that since you may be6422interested even in changes just changing the case as well, this search is case sensitive.</dd>6423EOT6424}6425print"</dl>\n";6426 git_footer_html();6427}64286429sub git_shortlog {6430 git_log_generic('shortlog', \&git_shortlog_body,6431$hash,$hash_parent);6432}64336434## ......................................................................6435## feeds (RSS, Atom; OPML)64366437sub git_feed {6438my$format=shift||'atom';6439my$have_blame= gitweb_check_feature('blame');64406441# Atom: http://www.atomenabled.org/developers/syndication/6442# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ6443if($formatne'rss'&&$formatne'atom') {6444 die_error(400,"Unknown web feed format");6445}64466447# log/feed of current (HEAD) branch, log of given branch, history of file/directory6448my$head=$hash||'HEAD';6449my@commitlist= parse_commits($head,150,0,$file_name);64506451my%latest_commit;6452my%latest_date;6453my$content_type="application/$format+xml";6454if(defined$cgi->http('HTTP_ACCEPT') &&6455$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {6456# browser (feed reader) prefers text/xml6457$content_type='text/xml';6458}6459if(defined($commitlist[0])) {6460%latest_commit= %{$commitlist[0]};6461my$latest_epoch=$latest_commit{'committer_epoch'};6462%latest_date= parse_date($latest_epoch);6463my$if_modified=$cgi->http('IF_MODIFIED_SINCE');6464if(defined$if_modified) {6465my$since;6466if(eval{require HTTP::Date;1; }) {6467$since= HTTP::Date::str2time($if_modified);6468}elsif(eval{require Time::ParseDate;1; }) {6469$since= Time::ParseDate::parsedate($if_modified, GMT =>1);6470}6471if(defined$since&&$latest_epoch<=$since) {6472print$cgi->header(6473-type =>$content_type,6474-charset =>'utf-8',6475-last_modified =>$latest_date{'rfc2822'},6476-status =>'304 Not Modified');6477return;6478}6479}6480print$cgi->header(6481-type =>$content_type,6482-charset =>'utf-8',6483-last_modified =>$latest_date{'rfc2822'});6484}else{6485print$cgi->header(6486-type =>$content_type,6487-charset =>'utf-8');6488}64896490# Optimization: skip generating the body if client asks only6491# for Last-Modified date.6492return if($cgi->request_method()eq'HEAD');64936494# header variables6495my$title="$site_name-$project/$action";6496my$feed_type='log';6497if(defined$hash) {6498$title.=" - '$hash'";6499$feed_type='branch log';6500if(defined$file_name) {6501$title.=" ::$file_name";6502$feed_type='history';6503}6504}elsif(defined$file_name) {6505$title.=" -$file_name";6506$feed_type='history';6507}6508$title.="$feed_type";6509my$descr= git_get_project_description($project);6510if(defined$descr) {6511$descr= esc_html($descr);6512}else{6513$descr="$project".6514($formateq'rss'?'RSS':'Atom') .6515" feed";6516}6517my$owner= git_get_project_owner($project);6518$owner= esc_html($owner);65196520#header6521my$alt_url;6522if(defined$file_name) {6523$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);6524}elsif(defined$hash) {6525$alt_url= href(-full=>1, action=>"log", hash=>$hash);6526}else{6527$alt_url= href(-full=>1, action=>"summary");6528}6529print qq!<?xml version="1.0" encoding="utf-8"?>\n!;6530if($formateq'rss') {6531print<<XML;6532<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">6533<channel>6534XML6535print"<title>$title</title>\n".6536"<link>$alt_url</link>\n".6537"<description>$descr</description>\n".6538"<language>en</language>\n".6539# project owner is responsible for 'editorial' content6540"<managingEditor>$owner</managingEditor>\n";6541if(defined$logo||defined$favicon) {6542# prefer the logo to the favicon, since RSS6543# doesn't allow both6544my$img= esc_url($logo||$favicon);6545print"<image>\n".6546"<url>$img</url>\n".6547"<title>$title</title>\n".6548"<link>$alt_url</link>\n".6549"</image>\n";6550}6551if(%latest_date) {6552print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";6553print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";6554}6555print"<generator>gitweb v.$version/$git_version</generator>\n";6556}elsif($formateq'atom') {6557print<<XML;6558<feed xmlns="http://www.w3.org/2005/Atom">6559XML6560print"<title>$title</title>\n".6561"<subtitle>$descr</subtitle>\n".6562'<link rel="alternate" type="text/html" href="'.6563$alt_url.'" />'."\n".6564'<link rel="self" type="'.$content_type.'" href="'.6565$cgi->self_url() .'" />'."\n".6566"<id>". href(-full=>1) ."</id>\n".6567# use project owner for feed author6568"<author><name>$owner</name></author>\n";6569if(defined$favicon) {6570print"<icon>". esc_url($favicon) ."</icon>\n";6571}6572if(defined$logo_url) {6573# not twice as wide as tall: 72 x 27 pixels6574print"<logo>". esc_url($logo) ."</logo>\n";6575}6576if(!%latest_date) {6577# dummy date to keep the feed valid until commits trickle in:6578print"<updated>1970-01-01T00:00:00Z</updated>\n";6579}else{6580print"<updated>$latest_date{'iso-8601'}</updated>\n";6581}6582print"<generator version='$version/$git_version'>gitweb</generator>\n";6583}65846585# contents6586for(my$i=0;$i<=$#commitlist;$i++) {6587my%co= %{$commitlist[$i]};6588my$commit=$co{'id'};6589# we read 150, we always show 30 and the ones more recent than 48 hours6590if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6591last;6592}6593my%cd= parse_date($co{'author_epoch'});65946595# get list of changed files6596open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6597$co{'parent'} ||"--root",6598$co{'id'},"--", (defined$file_name?$file_name: ())6599ornext;6600my@difftree=map{chomp;$_} <$fd>;6601close$fd6602ornext;66036604# print element (entry, item)6605my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6606if($formateq'rss') {6607print"<item>\n".6608"<title>". esc_html($co{'title'}) ."</title>\n".6609"<author>". esc_html($co{'author'}) ."</author>\n".6610"<pubDate>$cd{'rfc2822'}</pubDate>\n".6611"<guid isPermaLink=\"true\">$co_url</guid>\n".6612"<link>$co_url</link>\n".6613"<description>". esc_html($co{'title'}) ."</description>\n".6614"<content:encoded>".6615"<![CDATA[\n";6616}elsif($formateq'atom') {6617print"<entry>\n".6618"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6619"<updated>$cd{'iso-8601'}</updated>\n".6620"<author>\n".6621" <name>". esc_html($co{'author_name'}) ."</name>\n";6622if($co{'author_email'}) {6623print" <email>". esc_html($co{'author_email'}) ."</email>\n";6624}6625print"</author>\n".6626# use committer for contributor6627"<contributor>\n".6628" <name>". esc_html($co{'committer_name'}) ."</name>\n";6629if($co{'committer_email'}) {6630print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6631}6632print"</contributor>\n".6633"<published>$cd{'iso-8601'}</published>\n".6634"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6635"<id>$co_url</id>\n".6636"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6637"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6638}6639my$comment=$co{'comment'};6640print"<pre>\n";6641foreachmy$line(@$comment) {6642$line= esc_html($line);6643print"$line\n";6644}6645print"</pre><ul>\n";6646foreachmy$difftree_line(@difftree) {6647my%difftree= parse_difftree_raw_line($difftree_line);6648next if!$difftree{'from_id'};66496650my$file=$difftree{'file'} ||$difftree{'to_file'};66516652print"<li>".6653"[".6654$cgi->a({-href => href(-full=>1, action=>"blobdiff",6655 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6656 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6657 file_name=>$file, file_parent=>$difftree{'from_file'}),6658-title =>"diff"},'D');6659if($have_blame) {6660print$cgi->a({-href => href(-full=>1, action=>"blame",6661 file_name=>$file, hash_base=>$commit),6662-title =>"blame"},'B');6663}6664# if this is not a feed of a file history6665if(!defined$file_name||$file_namene$file) {6666print$cgi->a({-href => href(-full=>1, action=>"history",6667 file_name=>$file, hash=>$commit),6668-title =>"history"},'H');6669}6670$file= esc_path($file);6671print"] ".6672"$file</li>\n";6673}6674if($formateq'rss') {6675print"</ul>]]>\n".6676"</content:encoded>\n".6677"</item>\n";6678}elsif($formateq'atom') {6679print"</ul>\n</div>\n".6680"</content>\n".6681"</entry>\n";6682}6683}66846685# end of feed6686if($formateq'rss') {6687print"</channel>\n</rss>\n";6688}elsif($formateq'atom') {6689print"</feed>\n";6690}6691}66926693sub git_rss {6694 git_feed('rss');6695}66966697sub git_atom {6698 git_feed('atom');6699}67006701sub git_opml {6702my@list= git_get_projects_list();67036704print$cgi->header(6705-type =>'text/xml',6706-charset =>'utf-8',6707-content_disposition =>'inline; filename="opml.xml"');67086709print<<XML;6710<?xml version="1.0" encoding="utf-8"?>6711<opml version="1.0">6712<head>6713 <title>$site_nameOPML Export</title>6714</head>6715<body>6716<outline text="git RSS feeds">6717XML67186719foreachmy$pr(@list) {6720my%proj=%$pr;6721my$head= git_get_head_hash($proj{'path'});6722if(!defined$head) {6723next;6724}6725$git_dir="$projectroot/$proj{'path'}";6726my%co= parse_commit($head);6727if(!%co) {6728next;6729}67306731my$path= esc_html(chop_str($proj{'path'},25,5));6732my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);6733my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);6734print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";6735}6736print<<XML;6737</outline>6738</body>6739</opml>6740XML6741}