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# replace invalid utf8 character with SUBSTITUTION sequence1141sub esc_html {1142my$str=shift;1143my%opts=@_;11441145$str= to_utf8($str);1146$str=$cgi->escapeHTML($str);1147if($opts{'-nbsp'}) {1148$str=~s/ / /g;1149}1150$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1151return$str;1152}11531154# quote control characters and escape filename to HTML1155sub esc_path {1156my$str=shift;1157my%opts=@_;11581159$str= to_utf8($str);1160$str=$cgi->escapeHTML($str);1161if($opts{'-nbsp'}) {1162$str=~s/ / /g;1163}1164$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1165return$str;1166}11671168# Make control characters "printable", using character escape codes (CEC)1169sub quot_cec {1170my$cntrl=shift;1171my%opts=@_;1172my%es= (# character escape codes, aka escape sequences1173"\t"=>'\t',# tab (HT)1174"\n"=>'\n',# line feed (LF)1175"\r"=>'\r',# carrige return (CR)1176"\f"=>'\f',# form feed (FF)1177"\b"=>'\b',# backspace (BS)1178"\a"=>'\a',# alarm (bell) (BEL)1179"\e"=>'\e',# escape (ESC)1180"\013"=>'\v',# vertical tab (VT)1181"\000"=>'\0',# nul character (NUL)1182);1183my$chr= ( (exists$es{$cntrl})1184?$es{$cntrl}1185:sprintf('\%2x',ord($cntrl)) );1186if($opts{-nohtml}) {1187return$chr;1188}else{1189return"<span class=\"cntrl\">$chr</span>";1190}1191}11921193# Alternatively use unicode control pictures codepoints,1194# Unicode "printable representation" (PR)1195sub quot_upr {1196my$cntrl=shift;1197my%opts=@_;11981199my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1200if($opts{-nohtml}) {1201return$chr;1202}else{1203return"<span class=\"cntrl\">$chr</span>";1204}1205}12061207# git may return quoted and escaped filenames1208sub unquote {1209my$str=shift;12101211sub unq {1212my$seq=shift;1213my%es= (# character escape codes, aka escape sequences1214't'=>"\t",# tab (HT, TAB)1215'n'=>"\n",# newline (NL)1216'r'=>"\r",# return (CR)1217'f'=>"\f",# form feed (FF)1218'b'=>"\b",# backspace (BS)1219'a'=>"\a",# alarm (bell) (BEL)1220'e'=>"\e",# escape (ESC)1221'v'=>"\013",# vertical tab (VT)1222);12231224if($seq=~m/^[0-7]{1,3}$/) {1225# octal char sequence1226returnchr(oct($seq));1227}elsif(exists$es{$seq}) {1228# C escape sequence, aka character escape code1229return$es{$seq};1230}1231# quoted ordinary character1232return$seq;1233}12341235if($str=~m/^"(.*)"$/) {1236# needs unquoting1237$str=$1;1238$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1239}1240return$str;1241}12421243# escape tabs (convert tabs to spaces)1244sub untabify {1245my$line=shift;12461247while((my$pos=index($line,"\t")) != -1) {1248if(my$count= (8- ($pos%8))) {1249my$spaces=' ' x $count;1250$line=~s/\t/$spaces/;1251}1252}12531254return$line;1255}12561257sub project_in_list {1258my$project=shift;1259my@list= git_get_projects_list();1260return@list&&scalar(grep{$_->{'path'}eq$project}@list);1261}12621263## ----------------------------------------------------------------------1264## HTML aware string manipulation12651266# Try to chop given string on a word boundary between position1267# $len and $len+$add_len. If there is no word boundary there,1268# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1269# (marking chopped part) would be longer than given string.1270sub chop_str {1271my$str=shift;1272my$len=shift;1273my$add_len=shift||10;1274my$where=shift||'right';# 'left' | 'center' | 'right'12751276# Make sure perl knows it is utf8 encoded so we don't1277# cut in the middle of a utf8 multibyte char.1278$str= to_utf8($str);12791280# allow only $len chars, but don't cut a word if it would fit in $add_len1281# if it doesn't fit, cut it if it's still longer than the dots we would add1282# remove chopped character entities entirely12831284# when chopping in the middle, distribute $len into left and right part1285# return early if chopping wouldn't make string shorter1286if($whereeq'center') {1287return$strif($len+5>=length($str));# filler is length 51288$len=int($len/2);1289}else{1290return$strif($len+4>=length($str));# filler is length 41291}12921293# regexps: ending and beginning with word part up to $add_len1294my$endre=qr/.{$len}\w{0,$add_len}/;1295my$begre=qr/\w{0,$add_len}.{$len}/;12961297if($whereeq'left') {1298$str=~m/^(.*?)($begre)$/;1299my($lead,$body) = ($1,$2);1300if(length($lead) >4) {1301$body=~s/^[^;]*;//if($lead=~m/&[^;]*$/);1302$lead=" ...";1303}1304return"$lead$body";13051306}elsif($whereeq'center') {1307$str=~m/^($endre)(.*)$/;1308my($left,$str) = ($1,$2);1309$str=~m/^(.*?)($begre)$/;1310my($mid,$right) = ($1,$2);1311if(length($mid) >5) {1312$left=~s/&[^;]*$//;1313$right=~s/^[^;]*;//if($mid=~m/&[^;]*$/);1314$mid=" ... ";1315}1316return"$left$mid$right";13171318}else{1319$str=~m/^($endre)(.*)$/;1320my$body=$1;1321my$tail=$2;1322if(length($tail) >4) {1323$body=~s/&[^;]*$//;1324$tail="... ";1325}1326return"$body$tail";1327}1328}13291330# takes the same arguments as chop_str, but also wraps a <span> around the1331# result with a title attribute if it does get chopped. Additionally, the1332# string is HTML-escaped.1333sub chop_and_escape_str {1334my($str) =@_;13351336my$chopped= chop_str(@_);1337if($choppedeq$str) {1338return esc_html($chopped);1339}else{1340$str=~s/[[:cntrl:]]/?/g;1341return$cgi->span({-title=>$str}, esc_html($chopped));1342}1343}13441345## ----------------------------------------------------------------------1346## functions returning short strings13471348# CSS class for given age value (in seconds)1349sub age_class {1350my$age=shift;13511352if(!defined$age) {1353return"noage";1354}elsif($age<60*60*2) {1355return"age0";1356}elsif($age<60*60*24*2) {1357return"age1";1358}else{1359return"age2";1360}1361}13621363# convert age in seconds to "nn units ago" string1364sub age_string {1365my$age=shift;1366my$age_str;13671368if($age>60*60*24*365*2) {1369$age_str= (int$age/60/60/24/365);1370$age_str.=" years ago";1371}elsif($age>60*60*24*(365/12)*2) {1372$age_str=int$age/60/60/24/(365/12);1373$age_str.=" months ago";1374}elsif($age>60*60*24*7*2) {1375$age_str=int$age/60/60/24/7;1376$age_str.=" weeks ago";1377}elsif($age>60*60*24*2) {1378$age_str=int$age/60/60/24;1379$age_str.=" days ago";1380}elsif($age>60*60*2) {1381$age_str=int$age/60/60;1382$age_str.=" hours ago";1383}elsif($age>60*2) {1384$age_str=int$age/60;1385$age_str.=" min ago";1386}elsif($age>2) {1387$age_str=int$age;1388$age_str.=" sec ago";1389}else{1390$age_str.=" right now";1391}1392return$age_str;1393}13941395useconstant{1396 S_IFINVALID =>0030000,1397 S_IFGITLINK =>0160000,1398};13991400# submodule/subproject, a commit object reference1401sub S_ISGITLINK {1402my$mode=shift;14031404return(($mode& S_IFMT) == S_IFGITLINK)1405}14061407# convert file mode in octal to symbolic file mode string1408sub mode_str {1409my$mode=oct shift;14101411if(S_ISGITLINK($mode)) {1412return'm---------';1413}elsif(S_ISDIR($mode& S_IFMT)) {1414return'drwxr-xr-x';1415}elsif(S_ISLNK($mode)) {1416return'lrwxrwxrwx';1417}elsif(S_ISREG($mode)) {1418# git cares only about the executable bit1419if($mode& S_IXUSR) {1420return'-rwxr-xr-x';1421}else{1422return'-rw-r--r--';1423};1424}else{1425return'----------';1426}1427}14281429# convert file mode in octal to file type string1430sub file_type {1431my$mode=shift;14321433if($mode!~m/^[0-7]+$/) {1434return$mode;1435}else{1436$mode=oct$mode;1437}14381439if(S_ISGITLINK($mode)) {1440return"submodule";1441}elsif(S_ISDIR($mode& S_IFMT)) {1442return"directory";1443}elsif(S_ISLNK($mode)) {1444return"symlink";1445}elsif(S_ISREG($mode)) {1446return"file";1447}else{1448return"unknown";1449}1450}14511452# convert file mode in octal to file type description string1453sub file_type_long {1454my$mode=shift;14551456if($mode!~m/^[0-7]+$/) {1457return$mode;1458}else{1459$mode=oct$mode;1460}14611462if(S_ISGITLINK($mode)) {1463return"submodule";1464}elsif(S_ISDIR($mode& S_IFMT)) {1465return"directory";1466}elsif(S_ISLNK($mode)) {1467return"symlink";1468}elsif(S_ISREG($mode)) {1469if($mode& S_IXUSR) {1470return"executable";1471}else{1472return"file";1473};1474}else{1475return"unknown";1476}1477}147814791480## ----------------------------------------------------------------------1481## functions returning short HTML fragments, or transforming HTML fragments1482## which don't belong to other sections14831484# format line of commit message.1485sub format_log_line_html {1486my$line=shift;14871488$line= esc_html($line, -nbsp=>1);1489$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1490$cgi->a({-href => href(action=>"object", hash=>$1),1491-class=>"text"},$1);1492}eg;14931494return$line;1495}14961497# format marker of refs pointing to given object14981499# the destination action is chosen based on object type and current context:1500# - for annotated tags, we choose the tag view unless it's the current view1501# already, in which case we go to shortlog view1502# - for other refs, we keep the current view if we're in history, shortlog or1503# log view, and select shortlog otherwise1504sub format_ref_marker {1505my($refs,$id) =@_;1506my$markers='';15071508if(defined$refs->{$id}) {1509foreachmy$ref(@{$refs->{$id}}) {1510# this code exploits the fact that non-lightweight tags are the1511# only indirect objects, and that they are the only objects for which1512# we want to use tag instead of shortlog as action1513my($type,$name) =qw();1514my$indirect= ($ref=~s/\^\{\}$//);1515# e.g. tags/v2.6.11 or heads/next1516if($ref=~m!^(.*?)s?/(.*)$!) {1517$type=$1;1518$name=$2;1519}else{1520$type="ref";1521$name=$ref;1522}15231524my$class=$type;1525$class.=" indirect"if$indirect;15261527my$dest_action="shortlog";15281529if($indirect) {1530$dest_action="tag"unless$actioneq"tag";1531}elsif($action=~/^(history|(short)?log)$/) {1532$dest_action=$action;1533}15341535my$dest="";1536$dest.="refs/"unless$ref=~ m!^refs/!;1537$dest.=$ref;15381539my$link=$cgi->a({1540-href => href(1541 action=>$dest_action,1542 hash=>$dest1543)},$name);15441545$markers.=" <span class=\"$class\"title=\"$ref\">".1546$link."</span>";1547}1548}15491550if($markers) {1551return' <span class="refs">'.$markers.'</span>';1552}else{1553return"";1554}1555}15561557# format, perhaps shortened and with markers, title line1558sub format_subject_html {1559my($long,$short,$href,$extra) =@_;1560$extra=''unlessdefined($extra);15611562if(length($short) <length($long)) {1563$long=~s/[[:cntrl:]]/?/g;1564return$cgi->a({-href =>$href, -class=>"list subject",1565-title => to_utf8($long)},1566 esc_html($short)) .$extra;1567}else{1568return$cgi->a({-href =>$href, -class=>"list subject"},1569 esc_html($long)) .$extra;1570}1571}15721573# Rather than recomputing the url for an email multiple times, we cache it1574# after the first hit. This gives a visible benefit in views where the avatar1575# for the same email is used repeatedly (e.g. shortlog).1576# The cache is shared by all avatar engines (currently gravatar only), which1577# are free to use it as preferred. Since only one avatar engine is used for any1578# given page, there's no risk for cache conflicts.1579our%avatar_cache= ();15801581# Compute the picon url for a given email, by using the picon search service over at1582# http://www.cs.indiana.edu/picons/search.html1583sub picon_url {1584my$email=lc shift;1585if(!$avatar_cache{$email}) {1586my($user,$domain) =split('@',$email);1587$avatar_cache{$email} =1588"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".1589"$domain/$user/".1590"users+domains+unknown/up/single";1591}1592return$avatar_cache{$email};1593}15941595# Compute the gravatar url for a given email, if it's not in the cache already.1596# Gravatar stores only the part of the URL before the size, since that's the1597# one computationally more expensive. This also allows reuse of the cache for1598# different sizes (for this particular engine).1599sub gravatar_url {1600my$email=lc shift;1601my$size=shift;1602$avatar_cache{$email} ||=1603"http://www.gravatar.com/avatar/".1604 Digest::MD5::md5_hex($email) ."?s=";1605return$avatar_cache{$email} .$size;1606}16071608# Insert an avatar for the given $email at the given $size if the feature1609# is enabled.1610sub git_get_avatar {1611my($email,%opts) =@_;1612my$pre_white= ($opts{-pad_before} ?" ":"");1613my$post_white= ($opts{-pad_after} ?" ":"");1614$opts{-size} ||='default';1615my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};1616my$url="";1617if($git_avatareq'gravatar') {1618$url= gravatar_url($email,$size);1619}elsif($git_avatareq'picon') {1620$url= picon_url($email);1621}1622# Other providers can be added by extending the if chain, defining $url1623# as needed. If no variant puts something in $url, we assume avatars1624# are completely disabled/unavailable.1625if($url) {1626return$pre_white.1627"<img width=\"$size\"".1628"class=\"avatar\"".1629"src=\"$url\"".1630"alt=\"\"".1631"/>".$post_white;1632}else{1633return"";1634}1635}16361637sub format_search_author {1638my($author,$searchtype,$displaytext) =@_;1639my$have_search= gitweb_check_feature('search');16401641if($have_search) {1642my$performed="";1643if($searchtypeeq'author') {1644$performed="authored";1645}elsif($searchtypeeq'committer') {1646$performed="committed";1647}16481649return$cgi->a({-href => href(action=>"search", hash=>$hash,1650 searchtext=>$author,1651 searchtype=>$searchtype),class=>"list",1652 title=>"Search for commits$performedby$author"},1653$displaytext);16541655}else{1656return$displaytext;1657}1658}16591660# format the author name of the given commit with the given tag1661# the author name is chopped and escaped according to the other1662# optional parameters (see chop_str).1663sub format_author_html {1664my$tag=shift;1665my$co=shift;1666my$author= chop_and_escape_str($co->{'author_name'},@_);1667return"<$tagclass=\"author\">".1668 format_search_author($co->{'author_name'},"author",1669 git_get_avatar($co->{'author_email'}, -pad_after =>1) .1670$author) .1671"</$tag>";1672}16731674# format git diff header line, i.e. "diff --(git|combined|cc) ..."1675sub format_git_diff_header_line {1676my$line=shift;1677my$diffinfo=shift;1678my($from,$to) =@_;16791680if($diffinfo->{'nparents'}) {1681# combined diff1682$line=~s!^(diff (.*?) )"?.*$!$1!;1683if($to->{'href'}) {1684$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1685 esc_path($to->{'file'}));1686}else{# file was deleted (no href)1687$line.= esc_path($to->{'file'});1688}1689}else{1690# "ordinary" diff1691$line=~s!^(diff (.*?) )"?a/.*$!$1!;1692if($from->{'href'}) {1693$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1694'a/'. esc_path($from->{'file'}));1695}else{# file was added (no href)1696$line.='a/'. esc_path($from->{'file'});1697}1698$line.=' ';1699if($to->{'href'}) {1700$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1701'b/'. esc_path($to->{'file'}));1702}else{# file was deleted1703$line.='b/'. esc_path($to->{'file'});1704}1705}17061707return"<div class=\"diff header\">$line</div>\n";1708}17091710# format extended diff header line, before patch itself1711sub format_extended_diff_header_line {1712my$line=shift;1713my$diffinfo=shift;1714my($from,$to) =@_;17151716# match <path>1717if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1718$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1719 esc_path($from->{'file'}));1720}1721if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1722$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1723 esc_path($to->{'file'}));1724}1725# match single <mode>1726if($line=~m/\s(\d{6})$/) {1727$line.='<span class="info"> ('.1728 file_type_long($1) .1729')</span>';1730}1731# match <hash>1732if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1733# can match only for combined diff1734$line='index ';1735for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1736if($from->{'href'}[$i]) {1737$line.=$cgi->a({-href=>$from->{'href'}[$i],1738-class=>"hash"},1739substr($diffinfo->{'from_id'}[$i],0,7));1740}else{1741$line.='0' x 7;1742}1743# separator1744$line.=','if($i<$diffinfo->{'nparents'} -1);1745}1746$line.='..';1747if($to->{'href'}) {1748$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1749substr($diffinfo->{'to_id'},0,7));1750}else{1751$line.='0' x 7;1752}17531754}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1755# can match only for ordinary diff1756my($from_link,$to_link);1757if($from->{'href'}) {1758$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1759substr($diffinfo->{'from_id'},0,7));1760}else{1761$from_link='0' x 7;1762}1763if($to->{'href'}) {1764$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1765substr($diffinfo->{'to_id'},0,7));1766}else{1767$to_link='0' x 7;1768}1769my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1770$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1771}17721773return$line."<br/>\n";1774}17751776# format from-file/to-file diff header1777sub format_diff_from_to_header {1778my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1779my$line;1780my$result='';17811782$line=$from_line;1783#assert($line =~ m/^---/) if DEBUG;1784# no extra formatting for "^--- /dev/null"1785if(!$diffinfo->{'nparents'}) {1786# ordinary (single parent) diff1787if($line=~m!^--- "?a/!) {1788if($from->{'href'}) {1789$line='--- a/'.1790$cgi->a({-href=>$from->{'href'}, -class=>"path"},1791 esc_path($from->{'file'}));1792}else{1793$line='--- a/'.1794 esc_path($from->{'file'});1795}1796}1797$result.= qq!<div class="diff from_file">$line</div>\n!;17981799}else{1800# combined diff (merge commit)1801for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1802if($from->{'href'}[$i]) {1803$line='--- '.1804$cgi->a({-href=>href(action=>"blobdiff",1805 hash_parent=>$diffinfo->{'from_id'}[$i],1806 hash_parent_base=>$parents[$i],1807 file_parent=>$from->{'file'}[$i],1808 hash=>$diffinfo->{'to_id'},1809 hash_base=>$hash,1810 file_name=>$to->{'file'}),1811-class=>"path",1812-title=>"diff". ($i+1)},1813$i+1) .1814'/'.1815$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1816 esc_path($from->{'file'}[$i]));1817}else{1818$line='--- /dev/null';1819}1820$result.= qq!<div class="diff from_file">$line</div>\n!;1821}1822}18231824$line=$to_line;1825#assert($line =~ m/^\+\+\+/) if DEBUG;1826# no extra formatting for "^+++ /dev/null"1827if($line=~m!^\+\+\+ "?b/!) {1828if($to->{'href'}) {1829$line='+++ b/'.1830$cgi->a({-href=>$to->{'href'}, -class=>"path"},1831 esc_path($to->{'file'}));1832}else{1833$line='+++ b/'.1834 esc_path($to->{'file'});1835}1836}1837$result.= qq!<div class="diff to_file">$line</div>\n!;18381839return$result;1840}18411842# create note for patch simplified by combined diff1843sub format_diff_cc_simplified {1844my($diffinfo,@parents) =@_;1845my$result='';18461847$result.="<div class=\"diff header\">".1848"diff --cc ";1849if(!is_deleted($diffinfo)) {1850$result.=$cgi->a({-href => href(action=>"blob",1851 hash_base=>$hash,1852 hash=>$diffinfo->{'to_id'},1853 file_name=>$diffinfo->{'to_file'}),1854-class=>"path"},1855 esc_path($diffinfo->{'to_file'}));1856}else{1857$result.= esc_path($diffinfo->{'to_file'});1858}1859$result.="</div>\n".# class="diff header"1860"<div class=\"diff nodifferences\">".1861"Simple merge".1862"</div>\n";# class="diff nodifferences"18631864return$result;1865}18661867# format patch (diff) line (not to be used for diff headers)1868sub format_diff_line {1869my$line=shift;1870my($from,$to) =@_;1871my$diff_class="";18721873chomp$line;18741875if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1876# combined diff1877my$prefix=substr($line,0,scalar@{$from->{'href'}});1878if($line=~m/^\@{3}/) {1879$diff_class=" chunk_header";1880}elsif($line=~m/^\\/) {1881$diff_class=" incomplete";1882}elsif($prefix=~tr/+/+/) {1883$diff_class=" add";1884}elsif($prefix=~tr/-/-/) {1885$diff_class=" rem";1886}1887}else{1888# assume ordinary diff1889my$char=substr($line,0,1);1890if($chareq'+') {1891$diff_class=" add";1892}elsif($chareq'-') {1893$diff_class=" rem";1894}elsif($chareq'@') {1895$diff_class=" chunk_header";1896}elsif($chareq"\\") {1897$diff_class=" incomplete";1898}1899}1900$line= untabify($line);1901if($from&&$to&&$line=~m/^\@{2} /) {1902my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1903$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;19041905$from_lines=0unlessdefined$from_lines;1906$to_lines=0unlessdefined$to_lines;19071908if($from->{'href'}) {1909$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1910-class=>"list"},$from_text);1911}1912if($to->{'href'}) {1913$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1914-class=>"list"},$to_text);1915}1916$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1917"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1918return"<div class=\"diff$diff_class\">$line</div>\n";1919}elsif($from&&$to&&$line=~m/^\@{3}/) {1920my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1921my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);19221923@from_text=split(' ',$ranges);1924for(my$i=0;$i<@from_text; ++$i) {1925($from_start[$i],$from_nlines[$i]) =1926(split(',',substr($from_text[$i],1)),0);1927}19281929$to_text=pop@from_text;1930$to_start=pop@from_start;1931$to_nlines=pop@from_nlines;19321933$line="<span class=\"chunk_info\">$prefix";1934for(my$i=0;$i<@from_text; ++$i) {1935if($from->{'href'}[$i]) {1936$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1937-class=>"list"},$from_text[$i]);1938}else{1939$line.=$from_text[$i];1940}1941$line.=" ";1942}1943if($to->{'href'}) {1944$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1945-class=>"list"},$to_text);1946}else{1947$line.=$to_text;1948}1949$line.="$prefix</span>".1950"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1951return"<div class=\"diff$diff_class\">$line</div>\n";1952}1953return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1954}19551956# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1957# linked. Pass the hash of the tree/commit to snapshot.1958sub format_snapshot_links {1959my($hash) =@_;1960my$num_fmts=@snapshot_fmts;1961if($num_fmts>1) {1962# A parenthesized list of links bearing format names.1963# e.g. "snapshot (_tar.gz_ _zip_)"1964return"snapshot (".join(' ',map1965$cgi->a({1966-href => href(1967 action=>"snapshot",1968 hash=>$hash,1969 snapshot_format=>$_1970)1971},$known_snapshot_formats{$_}{'display'})1972,@snapshot_fmts) .")";1973}elsif($num_fmts==1) {1974# A single "snapshot" link whose tooltip bears the format name.1975# i.e. "_snapshot_"1976my($fmt) =@snapshot_fmts;1977return1978$cgi->a({1979-href => href(1980 action=>"snapshot",1981 hash=>$hash,1982 snapshot_format=>$fmt1983),1984-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"1985},"snapshot");1986}else{# $num_fmts == 01987returnundef;1988}1989}19901991## ......................................................................1992## functions returning values to be passed, perhaps after some1993## transformation, to other functions; e.g. returning arguments to href()19941995# returns hash to be passed to href to generate gitweb URL1996# in -title key it returns description of link1997sub get_feed_info {1998my$format=shift||'Atom';1999my%res= (action =>lc($format));20002001# feed links are possible only for project views2002return unless(defined$project);2003# some views should link to OPML, or to generic project feed,2004# or don't have specific feed yet (so they should use generic)2005return if($action=~/^(?:tags|heads|forks|tag|search)$/x);20062007my$branch;2008# branches refs uses 'refs/heads/' prefix (fullname) to differentiate2009# from tag links; this also makes possible to detect branch links2010if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||2011(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {2012$branch=$1;2013}2014# find log type for feed description (title)2015my$type='log';2016if(defined$file_name) {2017$type="history of$file_name";2018$type.="/"if($actioneq'tree');2019$type.=" on '$branch'"if(defined$branch);2020}else{2021$type="log of$branch"if(defined$branch);2022}20232024$res{-title} =$type;2025$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);2026$res{'file_name'} =$file_name;20272028return%res;2029}20302031## ----------------------------------------------------------------------2032## git utility subroutines, invoking git commands20332034# returns path to the core git executable and the --git-dir parameter as list2035sub git_cmd {2036$number_of_git_cmds++;2037return$GIT,'--git-dir='.$git_dir;2038}20392040# quote the given arguments for passing them to the shell2041# quote_command("command", "arg 1", "arg with ' and ! characters")2042# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2043# Try to avoid using this function wherever possible.2044sub quote_command {2045returnjoin(' ',2046map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2047}20482049# get HEAD ref of given project as hash2050sub git_get_head_hash {2051return git_get_full_hash(shift,'HEAD');2052}20532054sub git_get_full_hash {2055return git_get_hash(@_);2056}20572058sub git_get_short_hash {2059return git_get_hash(@_,'--short=7');2060}20612062sub git_get_hash {2063my($project,$hash,@options) =@_;2064my$o_git_dir=$git_dir;2065my$retval=undef;2066$git_dir="$projectroot/$project";2067if(open my$fd,'-|', git_cmd(),'rev-parse',2068'--verify','-q',@options,$hash) {2069$retval= <$fd>;2070chomp$retvalifdefined$retval;2071close$fd;2072}2073if(defined$o_git_dir) {2074$git_dir=$o_git_dir;2075}2076return$retval;2077}20782079# get type of given object2080sub git_get_type {2081my$hash=shift;20822083open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2084my$type= <$fd>;2085close$fdorreturn;2086chomp$type;2087return$type;2088}20892090# repository configuration2091our$config_file='';2092our%config;20932094# store multiple values for single key as anonymous array reference2095# single values stored directly in the hash, not as [ <value> ]2096sub hash_set_multi {2097my($hash,$key,$value) =@_;20982099if(!exists$hash->{$key}) {2100$hash->{$key} =$value;2101}elsif(!ref$hash->{$key}) {2102$hash->{$key} = [$hash->{$key},$value];2103}else{2104push@{$hash->{$key}},$value;2105}2106}21072108# return hash of git project configuration2109# optionally limited to some section, e.g. 'gitweb'2110sub git_parse_project_config {2111my$section_regexp=shift;2112my%config;21132114local$/="\0";21152116open my$fh,"-|", git_cmd(),"config",'-z','-l',2117orreturn;21182119while(my$keyval= <$fh>) {2120chomp$keyval;2121my($key,$value) =split(/\n/,$keyval,2);21222123 hash_set_multi(\%config,$key,$value)2124if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2125}2126close$fh;21272128return%config;2129}21302131# convert config value to boolean: 'true' or 'false'2132# no value, number > 0, 'true' and 'yes' values are true2133# rest of values are treated as false (never as error)2134sub config_to_bool {2135my$val=shift;21362137return1if!defined$val;# section.key21382139# strip leading and trailing whitespace2140$val=~s/^\s+//;2141$val=~s/\s+$//;21422143return(($val=~/^\d+$/&&$val) ||# section.key = 12144($val=~/^(?:true|yes)$/i));# section.key = true2145}21462147# convert config value to simple decimal number2148# an optional value suffix of 'k', 'm', or 'g' will cause the value2149# to be multiplied by 1024, 1048576, or 10737418242150sub config_to_int {2151my$val=shift;21522153# strip leading and trailing whitespace2154$val=~s/^\s+//;2155$val=~s/\s+$//;21562157if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2158$unit=lc($unit);2159# unknown unit is treated as 12160return$num* ($uniteq'g'?1073741824:2161$uniteq'm'?1048576:2162$uniteq'k'?1024:1);2163}2164return$val;2165}21662167# convert config value to array reference, if needed2168sub config_to_multi {2169my$val=shift;21702171returnref($val) ?$val: (defined($val) ? [$val] : []);2172}21732174sub git_get_project_config {2175my($key,$type) =@_;21762177# key sanity check2178return unless($key);2179$key=~s/^gitweb\.//;2180return if($key=~m/\W/);21812182# type sanity check2183if(defined$type) {2184$type=~s/^--//;2185$type=undef2186unless($typeeq'bool'||$typeeq'int');2187}21882189# get config2190if(!defined$config_file||2191$config_filene"$git_dir/config") {2192%config= git_parse_project_config('gitweb');2193$config_file="$git_dir/config";2194}21952196# check if config variable (key) exists2197return unlessexists$config{"gitweb.$key"};21982199# ensure given type2200if(!defined$type) {2201return$config{"gitweb.$key"};2202}elsif($typeeq'bool') {2203# backward compatibility: 'git config --bool' returns true/false2204return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2205}elsif($typeeq'int') {2206return config_to_int($config{"gitweb.$key"});2207}2208return$config{"gitweb.$key"};2209}22102211# get hash of given path at given ref2212sub git_get_hash_by_path {2213my$base=shift;2214my$path=shift||returnundef;2215my$type=shift;22162217$path=~ s,/+$,,;22182219open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2220or die_error(500,"Open git-ls-tree failed");2221my$line= <$fd>;2222close$fdorreturnundef;22232224if(!defined$line) {2225# there is no tree or hash given by $path at $base2226returnundef;2227}22282229#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2230$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2231if(defined$type&&$typene$2) {2232# type doesn't match2233returnundef;2234}2235return$3;2236}22372238# get path of entry with given hash at given tree-ish (ref)2239# used to get 'from' filename for combined diff (merge commit) for renames2240sub git_get_path_by_hash {2241my$base=shift||return;2242my$hash=shift||return;22432244local$/="\0";22452246open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2247orreturnundef;2248while(my$line= <$fd>) {2249chomp$line;22502251#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2252#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2253if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2254close$fd;2255return$1;2256}2257}2258close$fd;2259returnundef;2260}22612262## ......................................................................2263## git utility functions, directly accessing git repository22642265sub git_get_project_description {2266my$path=shift;22672268$git_dir="$projectroot/$path";2269open my$fd,'<',"$git_dir/description"2270orreturn git_get_project_config('description');2271my$descr= <$fd>;2272close$fd;2273if(defined$descr) {2274chomp$descr;2275}2276return$descr;2277}22782279sub git_get_project_ctags {2280my$path=shift;2281my$ctags= {};22822283$git_dir="$projectroot/$path";2284opendir my$dh,"$git_dir/ctags"2285orreturn$ctags;2286foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2287open my$ct,'<',$_ornext;2288my$val= <$ct>;2289chomp$val;2290close$ct;2291my$ctag=$_;$ctag=~ s#.*/##;2292$ctags->{$ctag} =$val;2293}2294closedir$dh;2295$ctags;2296}22972298sub git_populate_project_tagcloud {2299my$ctags=shift;23002301# First, merge different-cased tags; tags vote on casing2302my%ctags_lc;2303foreach(keys%$ctags) {2304$ctags_lc{lc$_}->{count} +=$ctags->{$_};2305if(not$ctags_lc{lc$_}->{topcount}2306or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2307$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2308$ctags_lc{lc$_}->{topname} =$_;2309}2310}23112312my$cloud;2313if(eval{require HTML::TagCloud;1; }) {2314$cloud= HTML::TagCloud->new;2315foreach(sort keys%ctags_lc) {2316# Pad the title with spaces so that the cloud looks2317# less crammed.2318my$title=$ctags_lc{$_}->{topname};2319$title=~s/ / /g;2320$title=~s/^/ /g;2321$title=~s/$/ /g;2322$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2323}2324}else{2325$cloud= \%ctags_lc;2326}2327$cloud;2328}23292330sub git_show_project_tagcloud {2331my($cloud,$count) =@_;2332print STDERR ref($cloud)."..\n";2333if(ref$cloudeq'HTML::TagCloud') {2334return$cloud->html_and_css($count);2335}else{2336my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2337return'<p align="center">'.join(', ',map{2338"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"2339}splice(@tags,0,$count)) .'</p>';2340}2341}23422343sub git_get_project_url_list {2344my$path=shift;23452346$git_dir="$projectroot/$path";2347open my$fd,'<',"$git_dir/cloneurl"2348orreturnwantarray?2349@{ config_to_multi(git_get_project_config('url')) } :2350 config_to_multi(git_get_project_config('url'));2351my@git_project_url_list=map{chomp;$_} <$fd>;2352close$fd;23532354returnwantarray?@git_project_url_list: \@git_project_url_list;2355}23562357sub git_get_projects_list {2358my($filter) =@_;2359my@list;23602361$filter||='';2362$filter=~s/\.git$//;23632364my$check_forks= gitweb_check_feature('forks');23652366if(-d $projects_list) {2367# search in directory2368my$dir=$projects_list. ($filter?"/$filter":'');2369# remove the trailing "/"2370$dir=~s!/+$!!;2371my$pfxlen=length("$dir");2372my$pfxdepth= ($dir=~tr!/!!);23732374 File::Find::find({2375 follow_fast =>1,# follow symbolic links2376 follow_skip =>2,# ignore duplicates2377 dangling_symlinks =>0,# ignore dangling symlinks, silently2378 wanted =>sub{2379# skip project-list toplevel, if we get it.2380return if(m!^[/.]$!);2381# only directories can be git repositories2382return unless(-d $_);2383# don't traverse too deep (Find is super slow on os x)2384if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2385$File::Find::prune =1;2386return;2387}23882389my$subdir=substr($File::Find::name,$pfxlen+1);2390# we check related file in $projectroot2391my$path= ($filter?"$filter/":'') .$subdir;2392if(check_export_ok("$projectroot/$path")) {2393push@list, { path =>$path};2394$File::Find::prune =1;2395}2396},2397},"$dir");23982399}elsif(-f $projects_list) {2400# read from file(url-encoded):2401# 'git%2Fgit.git Linus+Torvalds'2402# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2403# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2404my%paths;2405open my$fd,'<',$projects_listorreturn;2406 PROJECT:2407while(my$line= <$fd>) {2408chomp$line;2409my($path,$owner) =split' ',$line;2410$path= unescape($path);2411$owner= unescape($owner);2412if(!defined$path) {2413next;2414}2415if($filterne'') {2416# looking for forks;2417my$pfx=substr($path,0,length($filter));2418if($pfxne$filter) {2419next PROJECT;2420}2421my$sfx=substr($path,length($filter));2422if($sfx!~/^\/.*\.git$/) {2423next PROJECT;2424}2425}elsif($check_forks) {2426 PATH:2427foreachmy$filter(keys%paths) {2428# looking for forks;2429my$pfx=substr($path,0,length($filter));2430if($pfxne$filter) {2431next PATH;2432}2433my$sfx=substr($path,length($filter));2434if($sfx!~/^\/.*\.git$/) {2435next PATH;2436}2437# is a fork, don't include it in2438# the list2439next PROJECT;2440}2441}2442if(check_export_ok("$projectroot/$path")) {2443my$pr= {2444 path =>$path,2445 owner => to_utf8($owner),2446};2447push@list,$pr;2448(my$forks_path=$path) =~s/\.git$//;2449$paths{$forks_path}++;2450}2451}2452close$fd;2453}2454return@list;2455}24562457our$gitweb_project_owner=undef;2458sub git_get_project_list_from_file {24592460return if(defined$gitweb_project_owner);24612462$gitweb_project_owner= {};2463# read from file (url-encoded):2464# 'git%2Fgit.git Linus+Torvalds'2465# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2466# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2467if(-f $projects_list) {2468open(my$fd,'<',$projects_list);2469while(my$line= <$fd>) {2470chomp$line;2471my($pr,$ow) =split' ',$line;2472$pr= unescape($pr);2473$ow= unescape($ow);2474$gitweb_project_owner->{$pr} = to_utf8($ow);2475}2476close$fd;2477}2478}24792480sub git_get_project_owner {2481my$project=shift;2482my$owner;24832484returnundefunless$project;2485$git_dir="$projectroot/$project";24862487if(!defined$gitweb_project_owner) {2488 git_get_project_list_from_file();2489}24902491if(exists$gitweb_project_owner->{$project}) {2492$owner=$gitweb_project_owner->{$project};2493}2494if(!defined$owner){2495$owner= git_get_project_config('owner');2496}2497if(!defined$owner) {2498$owner= get_file_owner("$git_dir");2499}25002501return$owner;2502}25032504sub git_get_last_activity {2505my($path) =@_;2506my$fd;25072508$git_dir="$projectroot/$path";2509open($fd,"-|", git_cmd(),'for-each-ref',2510'--format=%(committer)',2511'--sort=-committerdate',2512'--count=1',2513'refs/heads')orreturn;2514my$most_recent= <$fd>;2515close$fdorreturn;2516if(defined$most_recent&&2517$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2518my$timestamp=$1;2519my$age=time-$timestamp;2520return($age, age_string($age));2521}2522return(undef,undef);2523}25242525sub git_get_references {2526my$type=shift||"";2527my%refs;2528# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112529# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2530open my$fd,"-|", git_cmd(),"show-ref","--dereference",2531($type? ("--","refs/$type") : ())# use -- <pattern> if $type2532orreturn;25332534while(my$line= <$fd>) {2535chomp$line;2536if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2537if(defined$refs{$1}) {2538push@{$refs{$1}},$2;2539}else{2540$refs{$1} = [$2];2541}2542}2543}2544close$fdorreturn;2545return \%refs;2546}25472548sub git_get_rev_name_tags {2549my$hash=shift||returnundef;25502551open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2552orreturn;2553my$name_rev= <$fd>;2554close$fd;25552556if($name_rev=~ m|^$hash tags/(.*)$|) {2557return$1;2558}else{2559# catches also '$hash undefined' output2560returnundef;2561}2562}25632564## ----------------------------------------------------------------------2565## parse to hash functions25662567sub parse_date {2568my$epoch=shift;2569my$tz=shift||"-0000";25702571my%date;2572my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2573my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2574my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2575$date{'hour'} =$hour;2576$date{'minute'} =$min;2577$date{'mday'} =$mday;2578$date{'day'} =$days[$wday];2579$date{'month'} =$months[$mon];2580$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2581$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2582$date{'mday-time'} =sprintf"%d%s%02d:%02d",2583$mday,$months[$mon],$hour,$min;2584$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",25851900+$year,1+$mon,$mday,$hour,$min,$sec;25862587$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2588my$local=$epoch+ ((int$1+ ($2/60)) *3600);2589($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2590$date{'hour_local'} =$hour;2591$date{'minute_local'} =$min;2592$date{'tz_local'} =$tz;2593$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",25941900+$year,$mon+1,$mday,2595$hour,$min,$sec,$tz);2596return%date;2597}25982599sub parse_tag {2600my$tag_id=shift;2601my%tag;2602my@comment;26032604open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2605$tag{'id'} =$tag_id;2606while(my$line= <$fd>) {2607chomp$line;2608if($line=~m/^object ([0-9a-fA-F]{40})$/) {2609$tag{'object'} =$1;2610}elsif($line=~m/^type (.+)$/) {2611$tag{'type'} =$1;2612}elsif($line=~m/^tag (.+)$/) {2613$tag{'name'} =$1;2614}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2615$tag{'author'} =$1;2616$tag{'author_epoch'} =$2;2617$tag{'author_tz'} =$3;2618if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {2619$tag{'author_name'} =$1;2620$tag{'author_email'} =$2;2621}else{2622$tag{'author_name'} =$tag{'author'};2623}2624}elsif($line=~m/--BEGIN/) {2625push@comment,$line;2626last;2627}elsif($lineeq"") {2628last;2629}2630}2631push@comment, <$fd>;2632$tag{'comment'} = \@comment;2633close$fdorreturn;2634if(!defined$tag{'name'}) {2635return2636};2637return%tag2638}26392640sub parse_commit_text {2641my($commit_text,$withparents) =@_;2642my@commit_lines=split'\n',$commit_text;2643my%co;26442645pop@commit_lines;# Remove '\0'26462647if(!@commit_lines) {2648return;2649}26502651my$header=shift@commit_lines;2652if($header!~m/^[0-9a-fA-F]{40}/) {2653return;2654}2655($co{'id'},my@parents) =split' ',$header;2656while(my$line=shift@commit_lines) {2657last if$lineeq"\n";2658if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2659$co{'tree'} =$1;2660}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2661push@parents,$1;2662}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2663$co{'author'} = to_utf8($1);2664$co{'author_epoch'} =$2;2665$co{'author_tz'} =$3;2666if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2667$co{'author_name'} =$1;2668$co{'author_email'} =$2;2669}else{2670$co{'author_name'} =$co{'author'};2671}2672}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2673$co{'committer'} = to_utf8($1);2674$co{'committer_epoch'} =$2;2675$co{'committer_tz'} =$3;2676if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2677$co{'committer_name'} =$1;2678$co{'committer_email'} =$2;2679}else{2680$co{'committer_name'} =$co{'committer'};2681}2682}2683}2684if(!defined$co{'tree'}) {2685return;2686};2687$co{'parents'} = \@parents;2688$co{'parent'} =$parents[0];26892690foreachmy$title(@commit_lines) {2691$title=~s/^ //;2692if($titlene"") {2693$co{'title'} = chop_str($title,80,5);2694# remove leading stuff of merges to make the interesting part visible2695if(length($title) >50) {2696$title=~s/^Automatic //;2697$title=~s/^merge (of|with) /Merge ... /i;2698if(length($title) >50) {2699$title=~s/(http|rsync):\/\///;2700}2701if(length($title) >50) {2702$title=~s/(master|www|rsync)\.//;2703}2704if(length($title) >50) {2705$title=~s/kernel.org:?//;2706}2707if(length($title) >50) {2708$title=~s/\/pub\/scm//;2709}2710}2711$co{'title_short'} = chop_str($title,50,5);2712last;2713}2714}2715if(!defined$co{'title'} ||$co{'title'}eq"") {2716$co{'title'} =$co{'title_short'} ='(no commit message)';2717}2718# remove added spaces2719foreachmy$line(@commit_lines) {2720$line=~s/^ //;2721}2722$co{'comment'} = \@commit_lines;27232724my$age=time-$co{'committer_epoch'};2725$co{'age'} =$age;2726$co{'age_string'} = age_string($age);2727my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2728if($age>60*60*24*7*2) {2729$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2730$co{'age_string_age'} =$co{'age_string'};2731}else{2732$co{'age_string_date'} =$co{'age_string'};2733$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2734}2735return%co;2736}27372738sub parse_commit {2739my($commit_id) =@_;2740my%co;27412742local$/="\0";27432744open my$fd,"-|", git_cmd(),"rev-list",2745"--parents",2746"--header",2747"--max-count=1",2748$commit_id,2749"--",2750or die_error(500,"Open git-rev-list failed");2751%co= parse_commit_text(<$fd>,1);2752close$fd;27532754return%co;2755}27562757sub parse_commits {2758my($commit_id,$maxcount,$skip,$filename,@args) =@_;2759my@cos;27602761$maxcount||=1;2762$skip||=0;27632764local$/="\0";27652766open my$fd,"-|", git_cmd(),"rev-list",2767"--header",2768@args,2769("--max-count=".$maxcount),2770("--skip=".$skip),2771@extra_options,2772$commit_id,2773"--",2774($filename? ($filename) : ())2775or die_error(500,"Open git-rev-list failed");2776while(my$line= <$fd>) {2777my%co= parse_commit_text($line);2778push@cos, \%co;2779}2780close$fd;27812782returnwantarray?@cos: \@cos;2783}27842785# parse line of git-diff-tree "raw" output2786sub parse_difftree_raw_line {2787my$line=shift;2788my%res;27892790# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2791# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2792if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2793$res{'from_mode'} =$1;2794$res{'to_mode'} =$2;2795$res{'from_id'} =$3;2796$res{'to_id'} =$4;2797$res{'status'} =$5;2798$res{'similarity'} =$6;2799if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2800($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2801}else{2802$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2803}2804}2805# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2806# combined diff (for merge commit)2807elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2808$res{'nparents'} =length($1);2809$res{'from_mode'} = [split(' ',$2) ];2810$res{'to_mode'} =pop@{$res{'from_mode'}};2811$res{'from_id'} = [split(' ',$3) ];2812$res{'to_id'} =pop@{$res{'from_id'}};2813$res{'status'} = [split('',$4) ];2814$res{'to_file'} = unquote($5);2815}2816# 'c512b523472485aef4fff9e57b229d9d243c967f'2817elsif($line=~m/^([0-9a-fA-F]{40})$/) {2818$res{'commit'} =$1;2819}28202821returnwantarray?%res: \%res;2822}28232824# wrapper: return parsed line of git-diff-tree "raw" output2825# (the argument might be raw line, or parsed info)2826sub parsed_difftree_line {2827my$line_or_ref=shift;28282829if(ref($line_or_ref)eq"HASH") {2830# pre-parsed (or generated by hand)2831return$line_or_ref;2832}else{2833return parse_difftree_raw_line($line_or_ref);2834}2835}28362837# parse line of git-ls-tree output2838sub parse_ls_tree_line {2839my$line=shift;2840my%opts=@_;2841my%res;28422843if($opts{'-l'}) {2844#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'2845$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;28462847$res{'mode'} =$1;2848$res{'type'} =$2;2849$res{'hash'} =$3;2850$res{'size'} =$4;2851if($opts{'-z'}) {2852$res{'name'} =$5;2853}else{2854$res{'name'} = unquote($5);2855}2856}else{2857#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2858$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;28592860$res{'mode'} =$1;2861$res{'type'} =$2;2862$res{'hash'} =$3;2863if($opts{'-z'}) {2864$res{'name'} =$4;2865}else{2866$res{'name'} = unquote($4);2867}2868}28692870returnwantarray?%res: \%res;2871}28722873# generates _two_ hashes, references to which are passed as 2 and 3 argument2874sub parse_from_to_diffinfo {2875my($diffinfo,$from,$to,@parents) =@_;28762877if($diffinfo->{'nparents'}) {2878# combined diff2879$from->{'file'} = [];2880$from->{'href'} = [];2881 fill_from_file_info($diffinfo,@parents)2882unlessexists$diffinfo->{'from_file'};2883for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2884$from->{'file'}[$i] =2885defined$diffinfo->{'from_file'}[$i] ?2886$diffinfo->{'from_file'}[$i] :2887$diffinfo->{'to_file'};2888if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2889$from->{'href'}[$i] = href(action=>"blob",2890 hash_base=>$parents[$i],2891 hash=>$diffinfo->{'from_id'}[$i],2892 file_name=>$from->{'file'}[$i]);2893}else{2894$from->{'href'}[$i] =undef;2895}2896}2897}else{2898# ordinary (not combined) diff2899$from->{'file'} =$diffinfo->{'from_file'};2900if($diffinfo->{'status'}ne"A") {# not new (added) file2901$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2902 hash=>$diffinfo->{'from_id'},2903 file_name=>$from->{'file'});2904}else{2905delete$from->{'href'};2906}2907}29082909$to->{'file'} =$diffinfo->{'to_file'};2910if(!is_deleted($diffinfo)) {# file exists in result2911$to->{'href'} = href(action=>"blob", hash_base=>$hash,2912 hash=>$diffinfo->{'to_id'},2913 file_name=>$to->{'file'});2914}else{2915delete$to->{'href'};2916}2917}29182919## ......................................................................2920## parse to array of hashes functions29212922sub git_get_heads_list {2923my$limit=shift;2924my@headslist;29252926open my$fd,'-|', git_cmd(),'for-each-ref',2927($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2928'--format=%(objectname) %(refname) %(subject)%00%(committer)',2929'refs/heads'2930orreturn;2931while(my$line= <$fd>) {2932my%ref_item;29332934chomp$line;2935my($refinfo,$committerinfo) =split(/\0/,$line);2936my($hash,$name,$title) =split(' ',$refinfo,3);2937my($committer,$epoch,$tz) =2938($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2939$ref_item{'fullname'} =$name;2940$name=~s!^refs/heads/!!;29412942$ref_item{'name'} =$name;2943$ref_item{'id'} =$hash;2944$ref_item{'title'} =$title||'(no commit message)';2945$ref_item{'epoch'} =$epoch;2946if($epoch) {2947$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2948}else{2949$ref_item{'age'} ="unknown";2950}29512952push@headslist, \%ref_item;2953}2954close$fd;29552956returnwantarray?@headslist: \@headslist;2957}29582959sub git_get_tags_list {2960my$limit=shift;2961my@tagslist;29622963open my$fd,'-|', git_cmd(),'for-each-ref',2964($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',2965'--format=%(objectname) %(objecttype) %(refname) '.2966'%(*objectname) %(*objecttype) %(subject)%00%(creator)',2967'refs/tags'2968orreturn;2969while(my$line= <$fd>) {2970my%ref_item;29712972chomp$line;2973my($refinfo,$creatorinfo) =split(/\0/,$line);2974my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);2975my($creator,$epoch,$tz) =2976($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);2977$ref_item{'fullname'} =$name;2978$name=~s!^refs/tags/!!;29792980$ref_item{'type'} =$type;2981$ref_item{'id'} =$id;2982$ref_item{'name'} =$name;2983if($typeeq"tag") {2984$ref_item{'subject'} =$title;2985$ref_item{'reftype'} =$reftype;2986$ref_item{'refid'} =$refid;2987}else{2988$ref_item{'reftype'} =$type;2989$ref_item{'refid'} =$id;2990}29912992if($typeeq"tag"||$typeeq"commit") {2993$ref_item{'epoch'} =$epoch;2994if($epoch) {2995$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2996}else{2997$ref_item{'age'} ="unknown";2998}2999}30003001push@tagslist, \%ref_item;3002}3003close$fd;30043005returnwantarray?@tagslist: \@tagslist;3006}30073008## ----------------------------------------------------------------------3009## filesystem-related functions30103011sub get_file_owner {3012my$path=shift;30133014my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);3015my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);3016if(!defined$gcos) {3017returnundef;3018}3019my$owner=$gcos;3020$owner=~s/[,;].*$//;3021return to_utf8($owner);3022}30233024# assume that file exists3025sub insert_file {3026my$filename=shift;30273028open my$fd,'<',$filename;3029print map{ to_utf8($_) } <$fd>;3030close$fd;3031}30323033## ......................................................................3034## mimetype related functions30353036sub mimetype_guess_file {3037my$filename=shift;3038my$mimemap=shift;3039-r $mimemaporreturnundef;30403041my%mimemap;3042open(my$mh,'<',$mimemap)orreturnundef;3043while(<$mh>) {3044next ifm/^#/;# skip comments3045my($mimetype,$exts) =split(/\t+/);3046if(defined$exts) {3047my@exts=split(/\s+/,$exts);3048foreachmy$ext(@exts) {3049$mimemap{$ext} =$mimetype;3050}3051}3052}3053close($mh);30543055$filename=~/\.([^.]*)$/;3056return$mimemap{$1};3057}30583059sub mimetype_guess {3060my$filename=shift;3061my$mime;3062$filename=~/\./orreturnundef;30633064if($mimetypes_file) {3065my$file=$mimetypes_file;3066if($file!~m!^/!) {# if it is relative path3067# it is relative to project3068$file="$projectroot/$project/$file";3069}3070$mime= mimetype_guess_file($filename,$file);3071}3072$mime||= mimetype_guess_file($filename,'/etc/mime.types');3073return$mime;3074}30753076sub blob_mimetype {3077my$fd=shift;3078my$filename=shift;30793080if($filename) {3081my$mime= mimetype_guess($filename);3082$mimeandreturn$mime;3083}30843085# just in case3086return$default_blob_plain_mimetypeunless$fd;30873088if(-T $fd) {3089return'text/plain';3090}elsif(!$filename) {3091return'application/octet-stream';3092}elsif($filename=~m/\.png$/i) {3093return'image/png';3094}elsif($filename=~m/\.gif$/i) {3095return'image/gif';3096}elsif($filename=~m/\.jpe?g$/i) {3097return'image/jpeg';3098}else{3099return'application/octet-stream';3100}3101}31023103sub blob_contenttype {3104my($fd,$file_name,$type) =@_;31053106$type||= blob_mimetype($fd,$file_name);3107if($typeeq'text/plain'&&defined$default_text_plain_charset) {3108$type.="; charset=$default_text_plain_charset";3109}31103111return$type;3112}31133114## ======================================================================3115## functions printing HTML: header, footer, error page31163117sub git_header_html {3118my$status=shift||"200 OK";3119my$expires=shift;31203121my$title="$site_name";3122if(defined$project) {3123$title.=" - ". to_utf8($project);3124if(defined$action) {3125$title.="/$action";3126if(defined$file_name) {3127$title.=" - ". esc_path($file_name);3128if($actioneq"tree"&&$file_name!~ m|/$|) {3129$title.="/";3130}3131}3132}3133}3134my$content_type;3135# require explicit support from the UA if we are to send the page as3136# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3137# we have to do this because MSIE sometimes globs '*/*', pretending to3138# support xhtml+xml but choking when it gets what it asked for.3139if(defined$cgi->http('HTTP_ACCEPT') &&3140$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3141$cgi->Accept('application/xhtml+xml') !=0) {3142$content_type='application/xhtml+xml';3143}else{3144$content_type='text/html';3145}3146print$cgi->header(-type=>$content_type, -charset =>'utf-8',3147-status=>$status, -expires =>$expires);3148my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';3149print<<EOF;3150<?xml version="1.0" encoding="utf-8"?>3151<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">3152<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">3153<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->3154<!-- git core binaries version$git_version-->3155<head>3156<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>3157<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>3158<meta name="robots" content="index, nofollow"/>3159<title>$title</title>3160EOF3161# the stylesheet, favicon etc urls won't work correctly with path_info3162# unless we set the appropriate base URL3163if($ENV{'PATH_INFO'}) {3164print"<base href=\"".esc_url($base_url)."\"/>\n";3165}3166# print out each stylesheet that exist, providing backwards capability3167# for those people who defined $stylesheet in a config file3168if(defined$stylesheet) {3169print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3170}else{3171foreachmy$stylesheet(@stylesheets) {3172next unless$stylesheet;3173print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";3174}3175}3176if(defined$project) {3177my%href_params= get_feed_info();3178if(!exists$href_params{'-title'}) {3179$href_params{'-title'} ='log';3180}31813182foreachmy$formatqw(RSS Atom){3183my$type=lc($format);3184my%link_attr= (3185'-rel'=>'alternate',3186'-title'=>"$project-$href_params{'-title'} -$formatfeed",3187'-type'=>"application/$type+xml"3188);31893190$href_params{'action'} =$type;3191$link_attr{'-href'} = href(%href_params);3192print"<link ".3193"rel=\"$link_attr{'-rel'}\"".3194"title=\"$link_attr{'-title'}\"".3195"href=\"$link_attr{'-href'}\"".3196"type=\"$link_attr{'-type'}\"".3197"/>\n";31983199$href_params{'extra_options'} ='--no-merges';3200$link_attr{'-href'} = href(%href_params);3201$link_attr{'-title'} .=' (no merges)';3202print"<link ".3203"rel=\"$link_attr{'-rel'}\"".3204"title=\"$link_attr{'-title'}\"".3205"href=\"$link_attr{'-href'}\"".3206"type=\"$link_attr{'-type'}\"".3207"/>\n";3208}32093210}else{3211printf('<link rel="alternate" title="%sprojects list" '.3212'href="%s" type="text/plain; charset=utf-8" />'."\n",3213$site_name, href(project=>undef, action=>"project_index"));3214printf('<link rel="alternate" title="%sprojects feeds" '.3215'href="%s" type="text/x-opml" />'."\n",3216$site_name, href(project=>undef, action=>"opml"));3217}3218if(defined$favicon) {3219printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);3220}32213222print"</head>\n".3223"<body>\n";32243225if(-f $site_header) {3226 insert_file($site_header);3227}32283229print"<div class=\"page_header\">\n".3230$cgi->a({-href => esc_url($logo_url),3231-title =>$logo_label},3232qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));3233print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3234if(defined$project) {3235print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3236if(defined$action) {3237print" /$action";3238}3239print"\n";3240}3241print"</div>\n";32423243my$have_search= gitweb_check_feature('search');3244if(defined$project&&$have_search) {3245if(!defined$searchtext) {3246$searchtext="";3247}3248my$search_hash;3249if(defined$hash_base) {3250$search_hash=$hash_base;3251}elsif(defined$hash) {3252$search_hash=$hash;3253}else{3254$search_hash="HEAD";3255}3256my$action=$my_uri;3257my$use_pathinfo= gitweb_check_feature('pathinfo');3258if($use_pathinfo) {3259$action.="/".esc_url($project);3260}3261print$cgi->startform(-method=>"get", -action =>$action) .3262"<div class=\"search\">\n".3263(!$use_pathinfo&&3264$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3265$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3266$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3267$cgi->popup_menu(-name =>'st', -default=>'commit',3268-values=> ['commit','grep','author','committer','pickaxe']) .3269$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3270" search:\n",3271$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3272"<span title=\"Extended regular expression\">".3273$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3274-checked =>$search_use_regexp) .3275"</span>".3276"</div>".3277$cgi->end_form() ."\n";3278}3279}32803281sub git_footer_html {3282my$feed_class='rss_logo';32833284print"<div class=\"page_footer\">\n";3285if(defined$project) {3286my$descr= git_get_project_description($project);3287if(defined$descr) {3288print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3289}32903291my%href_params= get_feed_info();3292if(!%href_params) {3293$feed_class.=' generic';3294}3295$href_params{'-title'} ||='log';32963297foreachmy$formatqw(RSS Atom){3298$href_params{'action'} =lc($format);3299print$cgi->a({-href => href(%href_params),3300-title =>"$href_params{'-title'}$formatfeed",3301-class=>$feed_class},$format)."\n";3302}33033304}else{3305print$cgi->a({-href => href(project=>undef, action=>"opml"),3306-class=>$feed_class},"OPML") ." ";3307print$cgi->a({-href => href(project=>undef, action=>"project_index"),3308-class=>$feed_class},"TXT") ."\n";3309}3310print"</div>\n";# class="page_footer"33113312if(defined$t0&& gitweb_check_feature('timed')) {3313print"<div id=\"generating_info\">\n";3314print'This page took '.3315'<span id="generating_time" class="time_span">'.3316 Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).3317' seconds </span>'.3318' and '.3319'<span id="generating_cmd">'.3320$number_of_git_cmds.3321'</span> git commands '.3322" to generate.\n";3323print"</div>\n";# class="page_footer"3324}33253326if(-f $site_footer) {3327 insert_file($site_footer);3328}33293330print qq!<script type="text/javascript" src="$javascript"></script>\n!;3331if($actioneq'blame_incremental') {3332print qq!<script type="text/javascript">\n!.3333 qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.3334 qq!"!. href() .qq!");\n!.3335 qq!</script>\n!;3336}elsif(gitweb_check_feature('javascript-actions')) {3337print qq!<script type="text/javascript">\n!.3338 qq!window.onload = fixLinks;\n!.3339 qq!</script>\n!;3340}33413342print"</body>\n".3343"</html>";3344}33453346# die_error(<http_status_code>, <error_message>)3347# Example: die_error(404, 'Hash not found')3348# By convention, use the following status codes (as defined in RFC 2616):3349# 400: Invalid or missing CGI parameters, or3350# requested object exists but has wrong type.3351# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3352# this server or project.3353# 404: Requested object/revision/project doesn't exist.3354# 500: The server isn't configured properly, or3355# an internal error occurred (e.g. failed assertions caused by bugs), or3356# an unknown error occurred (e.g. the git binary died unexpectedly).3357sub die_error {3358my$status=shift||500;3359my$error=shift||"Internal server error";33603361my%http_responses= (400=>'400 Bad Request',3362403=>'403 Forbidden',3363404=>'404 Not Found',3364500=>'500 Internal Server Error');3365 git_header_html($http_responses{$status});3366print<<EOF;3367<div class="page_body">3368<br /><br />3369$status-$error3370<br />3371</div>3372EOF3373 git_footer_html();3374exit;3375}33763377## ----------------------------------------------------------------------3378## functions printing or outputting HTML: navigation33793380sub git_print_page_nav {3381my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3382$extra=''if!defined$extra;# pager or formats33833384my@navs=qw(summary shortlog log commit commitdiff tree);3385if($suppress) {3386@navs=grep{$_ne$suppress}@navs;3387}33883389my%arg=map{$_=> {action=>$_} }@navs;3390if(defined$head) {3391for(qw(commit commitdiff)) {3392$arg{$_}{'hash'} =$head;3393}3394if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3395for(qw(shortlog log)) {3396$arg{$_}{'hash'} =$head;3397}3398}3399}34003401$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3402$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;34033404my@actions= gitweb_get_feature('actions');3405my%repl= (3406'%'=>'%',3407'n'=>$project,# project name3408'f'=>$git_dir,# project path within filesystem3409'h'=>$treehead||'',# current hash ('h' parameter)3410'b'=>$treebase||'',# hash base ('hb' parameter)3411);3412while(@actions) {3413my($label,$link,$pos) =splice(@actions,0,3);3414# insert3415@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3416# munch munch3417$link=~s/%([%nfhb])/$repl{$1}/g;3418$arg{$label}{'_href'} =$link;3419}34203421print"<div class=\"page_nav\">\n".3422(join" | ",3423map{$_eq$current?3424$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3425}@navs);3426print"<br/>\n$extra<br/>\n".3427"</div>\n";3428}34293430sub format_paging_nav {3431my($action,$page,$has_next_link) =@_;3432my$paging_nav;343334343435if($page>0) {3436$paging_nav.=3437$cgi->a({-href => href(-replay=>1, page=>undef)},"first") .3438" ⋅ ".3439$cgi->a({-href => href(-replay=>1, page=>$page-1),3440-accesskey =>"p", -title =>"Alt-p"},"prev");3441}else{3442$paging_nav.="first ⋅ prev";3443}34443445if($has_next_link) {3446$paging_nav.=" ⋅ ".3447$cgi->a({-href => href(-replay=>1, page=>$page+1),3448-accesskey =>"n", -title =>"Alt-n"},"next");3449}else{3450$paging_nav.=" ⋅ next";3451}34523453return$paging_nav;3454}34553456## ......................................................................3457## functions printing or outputting HTML: div34583459sub git_print_header_div {3460my($action,$title,$hash,$hash_base) =@_;3461my%args= ();34623463$args{'action'} =$action;3464$args{'hash'} =$hashif$hash;3465$args{'hash_base'} =$hash_baseif$hash_base;34663467print"<div class=\"header\">\n".3468$cgi->a({-href => href(%args), -class=>"title"},3469$title?$title:$action) .3470"\n</div>\n";3471}34723473sub print_local_time {3474my%date=@_;3475if($date{'hour_local'} <6) {3476printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3477$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3478}else{3479printf(" (%02d:%02d%s)",3480$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3481}3482}34833484# Outputs the author name and date in long form3485sub git_print_authorship {3486my$co=shift;3487my%opts=@_;3488my$tag=$opts{-tag} ||'div';3489my$author=$co->{'author_name'};34903491my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3492print"<$tagclass=\"author_date\">".3493 format_search_author($author,"author", esc_html($author)) .3494" [$ad{'rfc2822'}";3495 print_local_time(%ad)if($opts{-localtime});3496print"]". git_get_avatar($co->{'author_email'}, -pad_before =>1)3497."</$tag>\n";3498}34993500# Outputs table rows containing the full author or committer information,3501# in the format expected for 'commit' view (& similia).3502# Parameters are a commit hash reference, followed by the list of people3503# to output information for. If the list is empty it defalts to both3504# author and committer.3505sub git_print_authorship_rows {3506my$co=shift;3507# too bad we can't use @people = @_ || ('author', 'committer')3508my@people=@_;3509@people= ('author','committer')unless@people;3510foreachmy$who(@people) {3511my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});3512print"<tr><td>$who</td><td>".3513 format_search_author($co->{"${who}_name"},$who,3514 esc_html($co->{"${who}_name"})) ." ".3515 format_search_author($co->{"${who}_email"},$who,3516 esc_html("<".$co->{"${who}_email"} .">")) .3517"</td><td rowspan=\"2\">".3518 git_get_avatar($co->{"${who}_email"}, -size =>'double') .3519"</td></tr>\n".3520"<tr>".3521"<td></td><td>$wd{'rfc2822'}";3522 print_local_time(%wd);3523print"</td>".3524"</tr>\n";3525}3526}35273528sub git_print_page_path {3529my$name=shift;3530my$type=shift;3531my$hb=shift;353235333534print"<div class=\"page_path\">";3535print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3536-title =>'tree root'}, to_utf8("[$project]"));3537print" / ";3538if(defined$name) {3539my@dirname=split'/',$name;3540my$basename=pop@dirname;3541my$fullname='';35423543foreachmy$dir(@dirname) {3544$fullname.= ($fullname?'/':'') .$dir;3545print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3546 hash_base=>$hb),3547-title =>$fullname}, esc_path($dir));3548print" / ";3549}3550if(defined$type&&$typeeq'blob') {3551print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3552 hash_base=>$hb),3553-title =>$name}, esc_path($basename));3554}elsif(defined$type&&$typeeq'tree') {3555print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3556 hash_base=>$hb),3557-title =>$name}, esc_path($basename));3558print" / ";3559}else{3560print esc_path($basename);3561}3562}3563print"<br/></div>\n";3564}35653566sub git_print_log {3567my$log=shift;3568my%opts=@_;35693570if($opts{'-remove_title'}) {3571# remove title, i.e. first line of log3572shift@$log;3573}3574# remove leading empty lines3575while(defined$log->[0] &&$log->[0]eq"") {3576shift@$log;3577}35783579# print log3580my$signoff=0;3581my$empty=0;3582foreachmy$line(@$log) {3583if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3584$signoff=1;3585$empty=0;3586if(!$opts{'-remove_signoff'}) {3587print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3588next;3589}else{3590# remove signoff lines3591next;3592}3593}else{3594$signoff=0;3595}35963597# print only one empty line3598# do not print empty line after signoff3599if($lineeq"") {3600next if($empty||$signoff);3601$empty=1;3602}else{3603$empty=0;3604}36053606print format_log_line_html($line) ."<br/>\n";3607}36083609if($opts{'-final_empty_line'}) {3610# end with single empty line3611print"<br/>\n"unless$empty;3612}3613}36143615# return link target (what link points to)3616sub git_get_link_target {3617my$hash=shift;3618my$link_target;36193620# read link3621open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3622orreturn;3623{3624local$/=undef;3625$link_target= <$fd>;3626}3627close$fd3628orreturn;36293630return$link_target;3631}36323633# given link target, and the directory (basedir) the link is in,3634# return target of link relative to top directory (top tree);3635# return undef if it is not possible (including absolute links).3636sub normalize_link_target {3637my($link_target,$basedir) =@_;36383639# absolute symlinks (beginning with '/') cannot be normalized3640return if(substr($link_target,0,1)eq'/');36413642# normalize link target to path from top (root) tree (dir)3643my$path;3644if($basedir) {3645$path=$basedir.'/'.$link_target;3646}else{3647# we are in top (root) tree (dir)3648$path=$link_target;3649}36503651# remove //, /./, and /../3652my@path_parts;3653foreachmy$part(split('/',$path)) {3654# discard '.' and ''3655next if(!$part||$parteq'.');3656# handle '..'3657if($parteq'..') {3658if(@path_parts) {3659pop@path_parts;3660}else{3661# link leads outside repository (outside top dir)3662return;3663}3664}else{3665push@path_parts,$part;3666}3667}3668$path=join('/',@path_parts);36693670return$path;3671}36723673# print tree entry (row of git_tree), but without encompassing <tr> element3674sub git_print_tree_entry {3675my($t,$basedir,$hash_base,$have_blame) =@_;36763677my%base_key= ();3678$base_key{'hash_base'} =$hash_baseifdefined$hash_base;36793680# The format of a table row is: mode list link. Where mode is3681# the mode of the entry, list is the name of the entry, an href,3682# and link is the action links of the entry.36833684print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3685if(exists$t->{'size'}) {3686print"<td class=\"size\">$t->{'size'}</td>\n";3687}3688if($t->{'type'}eq"blob") {3689print"<td class=\"list\">".3690$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3691 file_name=>"$basedir$t->{'name'}",%base_key),3692-class=>"list"}, esc_path($t->{'name'}));3693if(S_ISLNK(oct$t->{'mode'})) {3694my$link_target= git_get_link_target($t->{'hash'});3695if($link_target) {3696my$norm_target= normalize_link_target($link_target,$basedir);3697if(defined$norm_target) {3698print" -> ".3699$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3700 file_name=>$norm_target),3701-title =>$norm_target}, esc_path($link_target));3702}else{3703print" -> ". esc_path($link_target);3704}3705}3706}3707print"</td>\n";3708print"<td class=\"link\">";3709print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3710 file_name=>"$basedir$t->{'name'}",%base_key)},3711"blob");3712if($have_blame) {3713print" | ".3714$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3715 file_name=>"$basedir$t->{'name'}",%base_key)},3716"blame");3717}3718if(defined$hash_base) {3719print" | ".3720$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3721 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3722"history");3723}3724print" | ".3725$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3726 file_name=>"$basedir$t->{'name'}")},3727"raw");3728print"</td>\n";37293730}elsif($t->{'type'}eq"tree") {3731print"<td class=\"list\">";3732print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3733 file_name=>"$basedir$t->{'name'}",3734%base_key)},3735 esc_path($t->{'name'}));3736print"</td>\n";3737print"<td class=\"link\">";3738print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3739 file_name=>"$basedir$t->{'name'}",3740%base_key)},3741"tree");3742if(defined$hash_base) {3743print" | ".3744$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3745 file_name=>"$basedir$t->{'name'}")},3746"history");3747}3748print"</td>\n";3749}else{3750# unknown object: we can only present history for it3751# (this includes 'commit' object, i.e. submodule support)3752print"<td class=\"list\">".3753 esc_path($t->{'name'}) .3754"</td>\n";3755print"<td class=\"link\">";3756if(defined$hash_base) {3757print$cgi->a({-href => href(action=>"history",3758 hash_base=>$hash_base,3759 file_name=>"$basedir$t->{'name'}")},3760"history");3761}3762print"</td>\n";3763}3764}37653766## ......................................................................3767## functions printing large fragments of HTML37683769# get pre-image filenames for merge (combined) diff3770sub fill_from_file_info {3771my($diff,@parents) =@_;37723773$diff->{'from_file'} = [ ];3774$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3775for(my$i=0;$i<$diff->{'nparents'};$i++) {3776if($diff->{'status'}[$i]eq'R'||3777$diff->{'status'}[$i]eq'C') {3778$diff->{'from_file'}[$i] =3779 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3780}3781}37823783return$diff;3784}37853786# is current raw difftree line of file deletion3787sub is_deleted {3788my$diffinfo=shift;37893790return$diffinfo->{'to_id'}eq('0' x 40);3791}37923793# does patch correspond to [previous] difftree raw line3794# $diffinfo - hashref of parsed raw diff format3795# $patchinfo - hashref of parsed patch diff format3796# (the same keys as in $diffinfo)3797sub is_patch_split {3798my($diffinfo,$patchinfo) =@_;37993800returndefined$diffinfo&&defined$patchinfo3801&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3802}380338043805sub git_difftree_body {3806my($difftree,$hash,@parents) =@_;3807my($parent) =$parents[0];3808my$have_blame= gitweb_check_feature('blame');3809print"<div class=\"list_head\">\n";3810if($#{$difftree} >10) {3811print(($#{$difftree} +1) ." files changed:\n");3812}3813print"</div>\n";38143815print"<table class=\"".3816(@parents>1?"combined ":"") .3817"diff_tree\">\n";38183819# header only for combined diff in 'commitdiff' view3820my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3821if($has_header) {3822# table header3823print"<thead><tr>\n".3824"<th></th><th></th>\n";# filename, patchN link3825for(my$i=0;$i<@parents;$i++) {3826my$par=$parents[$i];3827print"<th>".3828$cgi->a({-href => href(action=>"commitdiff",3829 hash=>$hash, hash_parent=>$par),3830-title =>'commitdiff to parent number '.3831($i+1) .': '.substr($par,0,7)},3832$i+1) .3833" </th>\n";3834}3835print"</tr></thead>\n<tbody>\n";3836}38373838my$alternate=1;3839my$patchno=0;3840foreachmy$line(@{$difftree}) {3841my$diff= parsed_difftree_line($line);38423843if($alternate) {3844print"<tr class=\"dark\">\n";3845}else{3846print"<tr class=\"light\">\n";3847}3848$alternate^=1;38493850if(exists$diff->{'nparents'}) {# combined diff38513852 fill_from_file_info($diff,@parents)3853unlessexists$diff->{'from_file'};38543855if(!is_deleted($diff)) {3856# file exists in the result (child) commit3857print"<td>".3858$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3859 file_name=>$diff->{'to_file'},3860 hash_base=>$hash),3861-class=>"list"}, esc_path($diff->{'to_file'})) .3862"</td>\n";3863}else{3864print"<td>".3865 esc_path($diff->{'to_file'}) .3866"</td>\n";3867}38683869if($actioneq'commitdiff') {3870# link to patch3871$patchno++;3872print"<td class=\"link\">".3873$cgi->a({-href =>"#patch$patchno"},"patch") .3874" | ".3875"</td>\n";3876}38773878my$has_history=0;3879my$not_deleted=0;3880for(my$i=0;$i<$diff->{'nparents'};$i++) {3881my$hash_parent=$parents[$i];3882my$from_hash=$diff->{'from_id'}[$i];3883my$from_path=$diff->{'from_file'}[$i];3884my$status=$diff->{'status'}[$i];38853886$has_history||= ($statusne'A');3887$not_deleted||= ($statusne'D');38883889if($statuseq'A') {3890print"<td class=\"link\"align=\"right\"> | </td>\n";3891}elsif($statuseq'D') {3892print"<td class=\"link\">".3893$cgi->a({-href => href(action=>"blob",3894 hash_base=>$hash,3895 hash=>$from_hash,3896 file_name=>$from_path)},3897"blob". ($i+1)) .3898" | </td>\n";3899}else{3900if($diff->{'to_id'}eq$from_hash) {3901print"<td class=\"link nochange\">";3902}else{3903print"<td class=\"link\">";3904}3905print$cgi->a({-href => href(action=>"blobdiff",3906 hash=>$diff->{'to_id'},3907 hash_parent=>$from_hash,3908 hash_base=>$hash,3909 hash_parent_base=>$hash_parent,3910 file_name=>$diff->{'to_file'},3911 file_parent=>$from_path)},3912"diff". ($i+1)) .3913" | </td>\n";3914}3915}39163917print"<td class=\"link\">";3918if($not_deleted) {3919print$cgi->a({-href => href(action=>"blob",3920 hash=>$diff->{'to_id'},3921 file_name=>$diff->{'to_file'},3922 hash_base=>$hash)},3923"blob");3924print" | "if($has_history);3925}3926if($has_history) {3927print$cgi->a({-href => href(action=>"history",3928 file_name=>$diff->{'to_file'},3929 hash_base=>$hash)},3930"history");3931}3932print"</td>\n";39333934print"</tr>\n";3935next;# instead of 'else' clause, to avoid extra indent3936}3937# else ordinary diff39383939my($to_mode_oct,$to_mode_str,$to_file_type);3940my($from_mode_oct,$from_mode_str,$from_file_type);3941if($diff->{'to_mode'}ne('0' x 6)) {3942$to_mode_oct=oct$diff->{'to_mode'};3943if(S_ISREG($to_mode_oct)) {# only for regular file3944$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits3945}3946$to_file_type= file_type($diff->{'to_mode'});3947}3948if($diff->{'from_mode'}ne('0' x 6)) {3949$from_mode_oct=oct$diff->{'from_mode'};3950if(S_ISREG($to_mode_oct)) {# only for regular file3951$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits3952}3953$from_file_type= file_type($diff->{'from_mode'});3954}39553956if($diff->{'status'}eq"A") {# created3957my$mode_chng="<span class=\"file_status new\">[new$to_file_type";3958$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;3959$mode_chng.="]</span>";3960print"<td>";3961print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3962 hash_base=>$hash, file_name=>$diff->{'file'}),3963-class=>"list"}, esc_path($diff->{'file'}));3964print"</td>\n";3965print"<td>$mode_chng</td>\n";3966print"<td class=\"link\">";3967if($actioneq'commitdiff') {3968# link to patch3969$patchno++;3970print$cgi->a({-href =>"#patch$patchno"},"patch");3971print" | ";3972}3973print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3974 hash_base=>$hash, file_name=>$diff->{'file'})},3975"blob");3976print"</td>\n";39773978}elsif($diff->{'status'}eq"D") {# deleted3979my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";3980print"<td>";3981print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3982 hash_base=>$parent, file_name=>$diff->{'file'}),3983-class=>"list"}, esc_path($diff->{'file'}));3984print"</td>\n";3985print"<td>$mode_chng</td>\n";3986print"<td class=\"link\">";3987if($actioneq'commitdiff') {3988# link to patch3989$patchno++;3990print$cgi->a({-href =>"#patch$patchno"},"patch");3991print" | ";3992}3993print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3994 hash_base=>$parent, file_name=>$diff->{'file'})},3995"blob") ." | ";3996if($have_blame) {3997print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,3998 file_name=>$diff->{'file'})},3999"blame") ." | ";4000}4001print$cgi->a({-href => href(action=>"history", hash_base=>$parent,4002 file_name=>$diff->{'file'})},4003"history");4004print"</td>\n";40054006}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed4007my$mode_chnge="";4008if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4009$mode_chnge="<span class=\"file_status mode_chnge\">[changed";4010if($from_file_typene$to_file_type) {4011$mode_chnge.=" from$from_file_typeto$to_file_type";4012}4013if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {4014if($from_mode_str&&$to_mode_str) {4015$mode_chnge.=" mode:$from_mode_str->$to_mode_str";4016}elsif($to_mode_str) {4017$mode_chnge.=" mode:$to_mode_str";4018}4019}4020$mode_chnge.="]</span>\n";4021}4022print"<td>";4023print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4024 hash_base=>$hash, file_name=>$diff->{'file'}),4025-class=>"list"}, esc_path($diff->{'file'}));4026print"</td>\n";4027print"<td>$mode_chnge</td>\n";4028print"<td class=\"link\">";4029if($actioneq'commitdiff') {4030# link to patch4031$patchno++;4032print$cgi->a({-href =>"#patch$patchno"},"patch") .4033" | ";4034}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4035# "commit" view and modified file (not onlu mode changed)4036print$cgi->a({-href => href(action=>"blobdiff",4037 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4038 hash_base=>$hash, hash_parent_base=>$parent,4039 file_name=>$diff->{'file'})},4040"diff") .4041" | ";4042}4043print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4044 hash_base=>$hash, file_name=>$diff->{'file'})},4045"blob") ." | ";4046if($have_blame) {4047print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4048 file_name=>$diff->{'file'})},4049"blame") ." | ";4050}4051print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4052 file_name=>$diff->{'file'})},4053"history");4054print"</td>\n";40554056}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied4057my%status_name= ('R'=>'moved','C'=>'copied');4058my$nstatus=$status_name{$diff->{'status'}};4059my$mode_chng="";4060if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4061# mode also for directories, so we cannot use $to_mode_str4062$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);4063}4064print"<td>".4065$cgi->a({-href => href(action=>"blob", hash_base=>$hash,4066 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),4067-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".4068"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".4069$cgi->a({-href => href(action=>"blob", hash_base=>$parent,4070 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),4071-class=>"list"}, esc_path($diff->{'from_file'})) .4072" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".4073"<td class=\"link\">";4074if($actioneq'commitdiff') {4075# link to patch4076$patchno++;4077print$cgi->a({-href =>"#patch$patchno"},"patch") .4078" | ";4079}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4080# "commit" view and modified file (not only pure rename or copy)4081print$cgi->a({-href => href(action=>"blobdiff",4082 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4083 hash_base=>$hash, hash_parent_base=>$parent,4084 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},4085"diff") .4086" | ";4087}4088print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4089 hash_base=>$parent, file_name=>$diff->{'to_file'})},4090"blob") ." | ";4091if($have_blame) {4092print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4093 file_name=>$diff->{'to_file'})},4094"blame") ." | ";4095}4096print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4097 file_name=>$diff->{'to_file'})},4098"history");4099print"</td>\n";41004101}# we should not encounter Unmerged (U) or Unknown (X) status4102print"</tr>\n";4103}4104print"</tbody>"if$has_header;4105print"</table>\n";4106}41074108sub git_patchset_body {4109my($fd,$difftree,$hash,@hash_parents) =@_;4110my($hash_parent) =$hash_parents[0];41114112my$is_combined= (@hash_parents>1);4113my$patch_idx=0;4114my$patch_number=0;4115my$patch_line;4116my$diffinfo;4117my$to_name;4118my(%from,%to);41194120print"<div class=\"patchset\">\n";41214122# skip to first patch4123while($patch_line= <$fd>) {4124chomp$patch_line;41254126last if($patch_line=~m/^diff /);4127}41284129 PATCH:4130while($patch_line) {41314132# parse "git diff" header line4133if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {4134# $1 is from_name, which we do not use4135$to_name= unquote($2);4136$to_name=~s!^b/!!;4137}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {4138# $1 is 'cc' or 'combined', which we do not use4139$to_name= unquote($2);4140}else{4141$to_name=undef;4142}41434144# check if current patch belong to current raw line4145# and parse raw git-diff line if needed4146if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {4147# this is continuation of a split patch4148print"<div class=\"patch cont\">\n";4149}else{4150# advance raw git-diff output if needed4151$patch_idx++ifdefined$diffinfo;41524153# read and prepare patch information4154$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);41554156# compact combined diff output can have some patches skipped4157# find which patch (using pathname of result) we are at now;4158if($is_combined) {4159while($to_namene$diffinfo->{'to_file'}) {4160print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4161 format_diff_cc_simplified($diffinfo,@hash_parents) .4162"</div>\n";# class="patch"41634164$patch_idx++;4165$patch_number++;41664167last if$patch_idx>$#$difftree;4168$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);4169}4170}41714172# modifies %from, %to hashes4173 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);41744175# this is first patch for raw difftree line with $patch_idx index4176# we index @$difftree array from 0, but number patches from 14177print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";4178}41794180# git diff header4181#assert($patch_line =~ m/^diff /) if DEBUG;4182#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed4183$patch_number++;4184# print "git diff" header4185print format_git_diff_header_line($patch_line,$diffinfo,4186 \%from, \%to);41874188# print extended diff header4189print"<div class=\"diff extended_header\">\n";4190 EXTENDED_HEADER:4191while($patch_line= <$fd>) {4192chomp$patch_line;41934194last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);41954196print format_extended_diff_header_line($patch_line,$diffinfo,4197 \%from, \%to);4198}4199print"</div>\n";# class="diff extended_header"42004201# from-file/to-file diff header4202if(!$patch_line) {4203print"</div>\n";# class="patch"4204last PATCH;4205}4206next PATCH if($patch_line=~m/^diff /);4207#assert($patch_line =~ m/^---/) if DEBUG;42084209my$last_patch_line=$patch_line;4210$patch_line= <$fd>;4211chomp$patch_line;4212#assert($patch_line =~ m/^\+\+\+/) if DEBUG;42134214print format_diff_from_to_header($last_patch_line,$patch_line,4215$diffinfo, \%from, \%to,4216@hash_parents);42174218# the patch itself4219 LINE:4220while($patch_line= <$fd>) {4221chomp$patch_line;42224223next PATCH if($patch_line=~m/^diff /);42244225print format_diff_line($patch_line, \%from, \%to);4226}42274228}continue{4229print"</div>\n";# class="patch"4230}42314232# for compact combined (--cc) format, with chunk and patch simpliciaction4233# patchset might be empty, but there might be unprocessed raw lines4234for(++$patch_idxif$patch_number>0;4235$patch_idx<@$difftree;4236++$patch_idx) {4237# read and prepare patch information4238$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);42394240# generate anchor for "patch" links in difftree / whatchanged part4241print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4242 format_diff_cc_simplified($diffinfo,@hash_parents) .4243"</div>\n";# class="patch"42444245$patch_number++;4246}42474248if($patch_number==0) {4249if(@hash_parents>1) {4250print"<div class=\"diff nodifferences\">Trivial merge</div>\n";4251}else{4252print"<div class=\"diff nodifferences\">No differences found</div>\n";4253}4254}42554256print"</div>\n";# class="patchset"4257}42584259# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42604261# fills project list info (age, description, owner, forks) for each4262# project in the list, removing invalid projects from returned list4263# NOTE: modifies $projlist, but does not remove entries from it4264sub fill_project_list_info {4265my($projlist,$check_forks) =@_;4266my@projects;42674268my$show_ctags= gitweb_check_feature('ctags');4269 PROJECT:4270foreachmy$pr(@$projlist) {4271my(@activity) = git_get_last_activity($pr->{'path'});4272unless(@activity) {4273next PROJECT;4274}4275($pr->{'age'},$pr->{'age_string'}) =@activity;4276if(!defined$pr->{'descr'}) {4277my$descr= git_get_project_description($pr->{'path'}) ||"";4278$descr= to_utf8($descr);4279$pr->{'descr_long'} =$descr;4280$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4281}4282if(!defined$pr->{'owner'}) {4283$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4284}4285if($check_forks) {4286my$pname=$pr->{'path'};4287if(($pname=~s/\.git$//) &&4288($pname!~/\/$/) &&4289(-d "$projectroot/$pname")) {4290$pr->{'forks'} ="-d$projectroot/$pname";4291}else{4292$pr->{'forks'} =0;4293}4294}4295$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4296push@projects,$pr;4297}42984299return@projects;4300}43014302# print 'sort by' <th> element, generating 'sort by $name' replay link4303# if that order is not selected4304sub print_sort_th {4305my($name,$order,$header) =@_;4306$header||=ucfirst($name);43074308if($ordereq$name) {4309print"<th>$header</th>\n";4310}else{4311print"<th>".4312$cgi->a({-href => href(-replay=>1, order=>$name),4313-class=>"header"},$header) .4314"</th>\n";4315}4316}43174318sub git_project_list_body {4319# actually uses global variable $project4320my($projlist,$order,$from,$to,$extra,$no_header) =@_;43214322my$check_forks= gitweb_check_feature('forks');4323my@projects= fill_project_list_info($projlist,$check_forks);43244325$order||=$default_projects_order;4326$from=0unlessdefined$from;4327$to=$#projectsif(!defined$to||$#projects<$to);43284329my%order_info= (4330 project => { key =>'path', type =>'str'},4331 descr => { key =>'descr_long', type =>'str'},4332 owner => { key =>'owner', type =>'str'},4333 age => { key =>'age', type =>'num'}4334);4335my$oi=$order_info{$order};4336if($oi->{'type'}eq'str') {4337@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4338}else{4339@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4340}43414342my$show_ctags= gitweb_check_feature('ctags');4343if($show_ctags) {4344my%ctags;4345foreachmy$p(@projects) {4346foreachmy$ct(keys%{$p->{'ctags'}}) {4347$ctags{$ct} +=$p->{'ctags'}->{$ct};4348}4349}4350my$cloud= git_populate_project_tagcloud(\%ctags);4351print git_show_project_tagcloud($cloud,64);4352}43534354print"<table class=\"project_list\">\n";4355unless($no_header) {4356print"<tr>\n";4357if($check_forks) {4358print"<th></th>\n";4359}4360 print_sort_th('project',$order,'Project');4361 print_sort_th('descr',$order,'Description');4362 print_sort_th('owner',$order,'Owner');4363 print_sort_th('age',$order,'Last Change');4364print"<th></th>\n".# for links4365"</tr>\n";4366}4367my$alternate=1;4368my$tagfilter=$cgi->param('by_tag');4369for(my$i=$from;$i<=$to;$i++) {4370my$pr=$projects[$i];43714372next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4373next if$searchtextand not$pr->{'path'} =~/$searchtext/4374and not$pr->{'descr_long'} =~/$searchtext/;4375# Weed out forks or non-matching entries of search4376if($check_forks) {4377my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4378$forkbase="^$forkbase"if$forkbase;4379next ifnot$searchtextand not$tagfilterand$show_ctags4380and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4381}43824383if($alternate) {4384print"<tr class=\"dark\">\n";4385}else{4386print"<tr class=\"light\">\n";4387}4388$alternate^=1;4389if($check_forks) {4390print"<td>";4391if($pr->{'forks'}) {4392print"<!--$pr->{'forks'} -->\n";4393print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4394}4395print"</td>\n";4396}4397print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4398-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4399"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4400-class=>"list", -title =>$pr->{'descr_long'}},4401 esc_html($pr->{'descr'})) ."</td>\n".4402"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4403print"<td class=\"". age_class($pr->{'age'}) ."\">".4404(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4405"<td class=\"link\">".4406$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4407$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4408$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4409$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4410($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4411"</td>\n".4412"</tr>\n";4413}4414if(defined$extra) {4415print"<tr>\n";4416if($check_forks) {4417print"<td></td>\n";4418}4419print"<td colspan=\"5\">$extra</td>\n".4420"</tr>\n";4421}4422print"</table>\n";4423}44244425sub git_log_body {4426# uses global variable $project4427my($commitlist,$from,$to,$refs,$extra) =@_;44284429$from=0unlessdefined$from;4430$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);44314432for(my$i=0;$i<=$to;$i++) {4433my%co= %{$commitlist->[$i]};4434next if!%co;4435my$commit=$co{'id'};4436my$ref= format_ref_marker($refs,$commit);4437my%ad= parse_date($co{'author_epoch'});4438 git_print_header_div('commit',4439"<span class=\"age\">$co{'age_string'}</span>".4440 esc_html($co{'title'}) .$ref,4441$commit);4442print"<div class=\"title_text\">\n".4443"<div class=\"log_link\">\n".4444$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .4445" | ".4446$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .4447" | ".4448$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .4449"<br/>\n".4450"</div>\n";4451 git_print_authorship(\%co, -tag =>'span');4452print"<br/>\n</div>\n";44534454print"<div class=\"log_body\">\n";4455 git_print_log($co{'comment'}, -final_empty_line=>1);4456print"</div>\n";4457}4458if($extra) {4459print"<div class=\"page_nav\">\n";4460print"$extra\n";4461print"</div>\n";4462}4463}44644465sub git_shortlog_body {4466# uses global variable $project4467my($commitlist,$from,$to,$refs,$extra) =@_;44684469$from=0unlessdefined$from;4470$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);44714472print"<table class=\"shortlog\">\n";4473my$alternate=1;4474for(my$i=$from;$i<=$to;$i++) {4475my%co= %{$commitlist->[$i]};4476my$commit=$co{'id'};4477my$ref= format_ref_marker($refs,$commit);4478if($alternate) {4479print"<tr class=\"dark\">\n";4480}else{4481print"<tr class=\"light\">\n";4482}4483$alternate^=1;4484# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4485print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4486 format_author_html('td', \%co,10) ."<td>";4487print format_subject_html($co{'title'},$co{'title_short'},4488 href(action=>"commit", hash=>$commit),$ref);4489print"</td>\n".4490"<td class=\"link\">".4491$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4492$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4493$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4494my$snapshot_links= format_snapshot_links($commit);4495if(defined$snapshot_links) {4496print" | ".$snapshot_links;4497}4498print"</td>\n".4499"</tr>\n";4500}4501if(defined$extra) {4502print"<tr>\n".4503"<td colspan=\"4\">$extra</td>\n".4504"</tr>\n";4505}4506print"</table>\n";4507}45084509sub git_history_body {4510# Warning: assumes constant type (blob or tree) during history4511my($commitlist,$from,$to,$refs,$extra,4512$file_name,$file_hash,$ftype) =@_;45134514$from=0unlessdefined$from;4515$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});45164517print"<table class=\"history\">\n";4518my$alternate=1;4519for(my$i=$from;$i<=$to;$i++) {4520my%co= %{$commitlist->[$i]};4521if(!%co) {4522next;4523}4524my$commit=$co{'id'};45254526my$ref= format_ref_marker($refs,$commit);45274528if($alternate) {4529print"<tr class=\"dark\">\n";4530}else{4531print"<tr class=\"light\">\n";4532}4533$alternate^=1;4534print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4535# shortlog: format_author_html('td', \%co, 10)4536 format_author_html('td', \%co,15,3) ."<td>";4537# originally git_history used chop_str($co{'title'}, 50)4538print format_subject_html($co{'title'},$co{'title_short'},4539 href(action=>"commit", hash=>$commit),$ref);4540print"</td>\n".4541"<td class=\"link\">".4542$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4543$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");45444545if($ftypeeq'blob') {4546my$blob_current=$file_hash;4547my$blob_parent= git_get_hash_by_path($commit,$file_name);4548if(defined$blob_current&&defined$blob_parent&&4549$blob_currentne$blob_parent) {4550print" | ".4551$cgi->a({-href => href(action=>"blobdiff",4552 hash=>$blob_current, hash_parent=>$blob_parent,4553 hash_base=>$hash_base, hash_parent_base=>$commit,4554 file_name=>$file_name)},4555"diff to current");4556}4557}4558print"</td>\n".4559"</tr>\n";4560}4561if(defined$extra) {4562print"<tr>\n".4563"<td colspan=\"4\">$extra</td>\n".4564"</tr>\n";4565}4566print"</table>\n";4567}45684569sub git_tags_body {4570# uses global variable $project4571my($taglist,$from,$to,$extra) =@_;4572$from=0unlessdefined$from;4573$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);45744575print"<table class=\"tags\">\n";4576my$alternate=1;4577for(my$i=$from;$i<=$to;$i++) {4578my$entry=$taglist->[$i];4579my%tag=%$entry;4580my$comment=$tag{'subject'};4581my$comment_short;4582if(defined$comment) {4583$comment_short= chop_str($comment,30,5);4584}4585if($alternate) {4586print"<tr class=\"dark\">\n";4587}else{4588print"<tr class=\"light\">\n";4589}4590$alternate^=1;4591if(defined$tag{'age'}) {4592print"<td><i>$tag{'age'}</i></td>\n";4593}else{4594print"<td></td>\n";4595}4596print"<td>".4597$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4598-class=>"list name"}, esc_html($tag{'name'})) .4599"</td>\n".4600"<td>";4601if(defined$comment) {4602print format_subject_html($comment,$comment_short,4603 href(action=>"tag", hash=>$tag{'id'}));4604}4605print"</td>\n".4606"<td class=\"selflink\">";4607if($tag{'type'}eq"tag") {4608print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4609}else{4610print" ";4611}4612print"</td>\n".4613"<td class=\"link\">"." | ".4614$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4615if($tag{'reftype'}eq"commit") {4616print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4617" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4618}elsif($tag{'reftype'}eq"blob") {4619print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4620}4621print"</td>\n".4622"</tr>";4623}4624if(defined$extra) {4625print"<tr>\n".4626"<td colspan=\"5\">$extra</td>\n".4627"</tr>\n";4628}4629print"</table>\n";4630}46314632sub git_heads_body {4633# uses global variable $project4634my($headlist,$head,$from,$to,$extra) =@_;4635$from=0unlessdefined$from;4636$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);46374638print"<table class=\"heads\">\n";4639my$alternate=1;4640for(my$i=$from;$i<=$to;$i++) {4641my$entry=$headlist->[$i];4642my%ref=%$entry;4643my$curr=$ref{'id'}eq$head;4644if($alternate) {4645print"<tr class=\"dark\">\n";4646}else{4647print"<tr class=\"light\">\n";4648}4649$alternate^=1;4650print"<td><i>$ref{'age'}</i></td>\n".4651($curr?"<td class=\"current_head\">":"<td>") .4652$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4653-class=>"list name"},esc_html($ref{'name'})) .4654"</td>\n".4655"<td class=\"link\">".4656$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4657$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4658$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4659"</td>\n".4660"</tr>";4661}4662if(defined$extra) {4663print"<tr>\n".4664"<td colspan=\"3\">$extra</td>\n".4665"</tr>\n";4666}4667print"</table>\n";4668}46694670sub git_search_grep_body {4671my($commitlist,$from,$to,$extra) =@_;4672$from=0unlessdefined$from;4673$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);46744675print"<table class=\"commit_search\">\n";4676my$alternate=1;4677for(my$i=$from;$i<=$to;$i++) {4678my%co= %{$commitlist->[$i]};4679if(!%co) {4680next;4681}4682my$commit=$co{'id'};4683if($alternate) {4684print"<tr class=\"dark\">\n";4685}else{4686print"<tr class=\"light\">\n";4687}4688$alternate^=1;4689print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4690 format_author_html('td', \%co,15,5) .4691"<td>".4692$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4693-class=>"list subject"},4694 chop_and_escape_str($co{'title'},50) ."<br/>");4695my$comment=$co{'comment'};4696foreachmy$line(@$comment) {4697if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4698my($lead,$match,$trail) = ($1,$2,$3);4699$match= chop_str($match,70,5,'center');4700my$contextlen=int((80-length($match))/2);4701$contextlen=30if($contextlen>30);4702$lead= chop_str($lead,$contextlen,10,'left');4703$trail= chop_str($trail,$contextlen,10,'right');47044705$lead= esc_html($lead);4706$match= esc_html($match);4707$trail= esc_html($trail);47084709print"$lead<span class=\"match\">$match</span>$trail<br />";4710}4711}4712print"</td>\n".4713"<td class=\"link\">".4714$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4715" | ".4716$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4717" | ".4718$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4719print"</td>\n".4720"</tr>\n";4721}4722if(defined$extra) {4723print"<tr>\n".4724"<td colspan=\"3\">$extra</td>\n".4725"</tr>\n";4726}4727print"</table>\n";4728}47294730## ======================================================================4731## ======================================================================4732## actions47334734sub git_project_list {4735my$order=$input_params{'order'};4736if(defined$order&&$order!~m/none|project|descr|owner|age/) {4737 die_error(400,"Unknown order parameter");4738}47394740my@list= git_get_projects_list();4741if(!@list) {4742 die_error(404,"No projects found");4743}47444745 git_header_html();4746if(-f $home_text) {4747print"<div class=\"index_include\">\n";4748 insert_file($home_text);4749print"</div>\n";4750}4751print$cgi->startform(-method=>"get") .4752"<p class=\"projsearch\">Search:\n".4753$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4754"</p>".4755$cgi->end_form() ."\n";4756 git_project_list_body(\@list,$order);4757 git_footer_html();4758}47594760sub git_forks {4761my$order=$input_params{'order'};4762if(defined$order&&$order!~m/none|project|descr|owner|age/) {4763 die_error(400,"Unknown order parameter");4764}47654766my@list= git_get_projects_list($project);4767if(!@list) {4768 die_error(404,"No forks found");4769}47704771 git_header_html();4772 git_print_page_nav('','');4773 git_print_header_div('summary',"$projectforks");4774 git_project_list_body(\@list,$order);4775 git_footer_html();4776}47774778sub git_project_index {4779my@projects= git_get_projects_list($project);47804781print$cgi->header(4782-type =>'text/plain',4783-charset =>'utf-8',4784-content_disposition =>'inline; filename="index.aux"');47854786foreachmy$pr(@projects) {4787if(!exists$pr->{'owner'}) {4788$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4789}47904791my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4792# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4793$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4794$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4795$path=~s/ /\+/g;4796$owner=~s/ /\+/g;47974798print"$path$owner\n";4799}4800}48014802sub git_summary {4803my$descr= git_get_project_description($project) ||"none";4804my%co= parse_commit("HEAD");4805my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4806my$head=$co{'id'};48074808my$owner= git_get_project_owner($project);48094810my$refs= git_get_references();4811# These get_*_list functions return one more to allow us to see if4812# there are more ...4813my@taglist= git_get_tags_list(16);4814my@headlist= git_get_heads_list(16);4815my@forklist;4816my$check_forks= gitweb_check_feature('forks');48174818if($check_forks) {4819@forklist= git_get_projects_list($project);4820}48214822 git_header_html();4823 git_print_page_nav('summary','',$head);48244825print"<div class=\"title\"> </div>\n";4826print"<table class=\"projects_list\">\n".4827"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4828"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4829if(defined$cd{'rfc2822'}) {4830print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4831}48324833# use per project git URL list in $projectroot/$project/cloneurl4834# or make project git URL from git base URL and project name4835my$url_tag="URL";4836my@url_list= git_get_project_url_list($project);4837@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4838foreachmy$git_url(@url_list) {4839next unless$git_url;4840print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4841$url_tag="";4842}48434844# Tag cloud4845my$show_ctags= gitweb_check_feature('ctags');4846if($show_ctags) {4847my$ctags= git_get_project_ctags($project);4848my$cloud= git_populate_project_tagcloud($ctags);4849print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4850print"</td>\n<td>"unless%$ctags;4851print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4852print"</td>\n<td>"if%$ctags;4853print git_show_project_tagcloud($cloud,48);4854print"</td></tr>";4855}48564857print"</table>\n";48584859# If XSS prevention is on, we don't include README.html.4860# TODO: Allow a readme in some safe format.4861if(!$prevent_xss&& -s "$projectroot/$project/README.html") {4862print"<div class=\"title\">readme</div>\n".4863"<div class=\"readme\">\n";4864 insert_file("$projectroot/$project/README.html");4865print"\n</div>\n";# class="readme"4866}48674868# we need to request one more than 16 (0..15) to check if4869# those 16 are all4870my@commitlist=$head? parse_commits($head,17) : ();4871if(@commitlist) {4872 git_print_header_div('shortlog');4873 git_shortlog_body(\@commitlist,0,15,$refs,4874$#commitlist<=15?undef:4875$cgi->a({-href => href(action=>"shortlog")},"..."));4876}48774878if(@taglist) {4879 git_print_header_div('tags');4880 git_tags_body(\@taglist,0,15,4881$#taglist<=15?undef:4882$cgi->a({-href => href(action=>"tags")},"..."));4883}48844885if(@headlist) {4886 git_print_header_div('heads');4887 git_heads_body(\@headlist,$head,0,15,4888$#headlist<=15?undef:4889$cgi->a({-href => href(action=>"heads")},"..."));4890}48914892if(@forklist) {4893 git_print_header_div('forks');4894 git_project_list_body(\@forklist,'age',0,15,4895$#forklist<=15?undef:4896$cgi->a({-href => href(action=>"forks")},"..."),4897'no_header');4898}48994900 git_footer_html();4901}49024903sub git_tag {4904my$head= git_get_head_hash($project);4905 git_header_html();4906 git_print_page_nav('','',$head,undef,$head);4907my%tag= parse_tag($hash);49084909if(!%tag) {4910 die_error(404,"Unknown tag object");4911}49124913 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4914print"<div class=\"title_text\">\n".4915"<table class=\"object_header\">\n".4916"<tr>\n".4917"<td>object</td>\n".4918"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4919$tag{'object'}) ."</td>\n".4920"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4921$tag{'type'}) ."</td>\n".4922"</tr>\n";4923if(defined($tag{'author'})) {4924 git_print_authorship_rows(\%tag,'author');4925}4926print"</table>\n\n".4927"</div>\n";4928print"<div class=\"page_body\">";4929my$comment=$tag{'comment'};4930foreachmy$line(@$comment) {4931chomp$line;4932print esc_html($line, -nbsp=>1) ."<br/>\n";4933}4934print"</div>\n";4935 git_footer_html();4936}49374938sub git_blame_common {4939my$format=shift||'porcelain';4940if($formateq'porcelain'&&$cgi->param('js')) {4941$format='incremental';4942$action='blame_incremental';# for page title etc4943}49444945# permissions4946 gitweb_check_feature('blame')4947or die_error(403,"Blame view not allowed");49484949# error checking4950 die_error(400,"No file name given")unless$file_name;4951$hash_base||= git_get_head_hash($project);4952 die_error(404,"Couldn't find base commit")unless$hash_base;4953my%co= parse_commit($hash_base)4954or die_error(404,"Commit not found");4955my$ftype="blob";4956if(!defined$hash) {4957$hash= git_get_hash_by_path($hash_base,$file_name,"blob")4958or die_error(404,"Error looking up file");4959}else{4960$ftype= git_get_type($hash);4961if($ftype!~"blob") {4962 die_error(400,"Object is not a blob");4963}4964}49654966my$fd;4967if($formateq'incremental') {4968# get file contents (as base)4969open$fd,"-|", git_cmd(),'cat-file','blob',$hash4970or die_error(500,"Open git-cat-file failed");4971}elsif($formateq'data') {4972# run git-blame --incremental4973open$fd,"-|", git_cmd(),"blame","--incremental",4974$hash_base,"--",$file_name4975or die_error(500,"Open git-blame --incremental failed");4976}else{4977# run git-blame --porcelain4978open$fd,"-|", git_cmd(),"blame",'-p',4979$hash_base,'--',$file_name4980or die_error(500,"Open git-blame --porcelain failed");4981}49824983# incremental blame data returns early4984if($formateq'data') {4985print$cgi->header(4986-type=>"text/plain", -charset =>"utf-8",4987-status=>"200 OK");4988local$| =1;# output autoflush4989printwhile<$fd>;4990close$fd4991or print"ERROR$!\n";49924993print'END';4994if(defined$t0&& gitweb_check_feature('timed')) {4995print' '.4996 Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).4997' '.$number_of_git_cmds;4998}4999print"\n";50005001return;5002}50035004# page header5005 git_header_html();5006my$formats_nav=5007$cgi->a({-href => href(action=>"blob", -replay=>1)},5008"blob") .5009" | ";5010if($formateq'incremental') {5011$formats_nav.=5012$cgi->a({-href => href(action=>"blame", javascript=>0, -replay=>1)},5013"blame") ." (non-incremental)";5014}else{5015$formats_nav.=5016$cgi->a({-href => href(action=>"blame_incremental", -replay=>1)},5017"blame") ." (incremental)";5018}5019$formats_nav.=5020" | ".5021$cgi->a({-href => href(action=>"history", -replay=>1)},5022"history") .5023" | ".5024$cgi->a({-href => href(action=>$action, file_name=>$file_name)},5025"HEAD");5026 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5027 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5028 git_print_page_path($file_name,$ftype,$hash_base);50295030# page body5031if($formateq'incremental') {5032print"<noscript>\n<div class=\"error\"><center><b>\n".5033"This page requires JavaScript to run.\nUse ".5034$cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},5035'this page').5036" instead.\n".5037"</b></center></div>\n</noscript>\n";50385039print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!;5040}50415042print qq!<div class="page_body">\n!;5043print qq!<div id="progress_info">.../ ...</div>\n!5044if($formateq'incremental');5045print qq!<table id="blame_table"class="blame" width="100%">\n!.5046#qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.5047 qq!<thead>\n!.5048 qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!.5049 qq!</thead>\n!.5050 qq!<tbody>\n!;50515052my@rev_color=qw(light dark);5053my$num_colors=scalar(@rev_color);5054my$current_color=0;50555056if($formateq'incremental') {5057my$color_class=$rev_color[$current_color];50585059#contents of a file5060my$linenr=0;5061 LINE:5062while(my$line= <$fd>) {5063chomp$line;5064$linenr++;50655066print qq!<tr id="l$linenr"class="$color_class">!.5067 qq!<td class="sha1"><a href=""> </a></td>!.5068 qq!<td class="linenr">!.5069 qq!<a class="linenr" href="">$linenr</a></td>!;5070print qq!<td class="pre">! . esc_html($line) ."</td>\n";5071print qq!</tr>\n!;5072}50735074}else{# porcelain, i.e. ordinary blame5075my%metainfo= ();# saves information about commits50765077# blame data5078 LINE:5079while(my$line= <$fd>) {5080chomp$line;5081# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]5082# no <lines in group> for subsequent lines in group of lines5083my($full_rev,$orig_lineno,$lineno,$group_size) =5084($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);5085if(!exists$metainfo{$full_rev}) {5086$metainfo{$full_rev} = {'nprevious'=>0};5087}5088my$meta=$metainfo{$full_rev};5089my$data;5090while($data= <$fd>) {5091chomp$data;5092last if($data=~s/^\t//);# contents of line5093if($data=~/^(\S+)(?: (.*))?$/) {5094$meta->{$1} =$2unlessexists$meta->{$1};5095}5096if($data=~/^previous /) {5097$meta->{'nprevious'}++;5098}5099}5100my$short_rev=substr($full_rev,0,8);5101my$author=$meta->{'author'};5102my%date=5103 parse_date($meta->{'author-time'},$meta->{'author-tz'});5104my$date=$date{'iso-tz'};5105if($group_size) {5106$current_color= ($current_color+1) %$num_colors;5107}5108my$tr_class=$rev_color[$current_color];5109$tr_class.=' boundary'if(exists$meta->{'boundary'});5110$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);5111$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);5112print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";5113if($group_size) {5114print"<td class=\"sha1\"";5115print" title=\"". esc_html($author) .",$date\"";5116print" rowspan=\"$group_size\""if($group_size>1);5117print">";5118print$cgi->a({-href => href(action=>"commit",5119 hash=>$full_rev,5120 file_name=>$file_name)},5121 esc_html($short_rev));5122if($group_size>=2) {5123my@author_initials= ($author=~/\b([[:upper:]])\B/g);5124if(@author_initials) {5125print"<br />".5126 esc_html(join('',@author_initials));5127# or join('.', ...)5128}5129}5130print"</td>\n";5131}5132# 'previous' <sha1 of parent commit> <filename at commit>5133if(exists$meta->{'previous'} &&5134$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {5135$meta->{'parent'} =$1;5136$meta->{'file_parent'} = unquote($2);5137}5138my$linenr_commit=5139exists($meta->{'parent'}) ?5140$meta->{'parent'} :$full_rev;5141my$linenr_filename=5142exists($meta->{'file_parent'}) ?5143$meta->{'file_parent'} : unquote($meta->{'filename'});5144my$blamed= href(action =>'blame',5145 file_name =>$linenr_filename,5146 hash_base =>$linenr_commit);5147print"<td class=\"linenr\">";5148print$cgi->a({ -href =>"$blamed#l$orig_lineno",5149-class=>"linenr"},5150 esc_html($lineno));5151print"</td>";5152print"<td class=\"pre\">". esc_html($data) ."</td>\n";5153print"</tr>\n";5154}# end while51555156}51575158# footer5159print"</tbody>\n".5160"</table>\n";# class="blame"5161print"</div>\n";# class="blame_body"5162close$fd5163or print"Reading blob failed\n";51645165 git_footer_html();5166}51675168sub git_blame {5169 git_blame_common();5170}51715172sub git_blame_incremental {5173 git_blame_common('incremental');5174}51755176sub git_blame_data {5177 git_blame_common('data');5178}51795180sub git_tags {5181my$head= git_get_head_hash($project);5182 git_header_html();5183 git_print_page_nav('','',$head,undef,$head);5184 git_print_header_div('summary',$project);51855186my@tagslist= git_get_tags_list();5187if(@tagslist) {5188 git_tags_body(\@tagslist);5189}5190 git_footer_html();5191}51925193sub git_heads {5194my$head= git_get_head_hash($project);5195 git_header_html();5196 git_print_page_nav('','',$head,undef,$head);5197 git_print_header_div('summary',$project);51985199my@headslist= git_get_heads_list();5200if(@headslist) {5201 git_heads_body(\@headslist,$head);5202}5203 git_footer_html();5204}52055206sub git_blob_plain {5207my$type=shift;5208my$expires;52095210if(!defined$hash) {5211if(defined$file_name) {5212my$base=$hash_base|| git_get_head_hash($project);5213$hash= git_get_hash_by_path($base,$file_name,"blob")5214or die_error(404,"Cannot find file");5215}else{5216 die_error(400,"No file name defined");5217}5218}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5219# blobs defined by non-textual hash id's can be cached5220$expires="+1d";5221}52225223open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5224or die_error(500,"Open git-cat-file blob '$hash' failed");52255226# content-type (can include charset)5227$type= blob_contenttype($fd,$file_name,$type);52285229# "save as" filename, even when no $file_name is given5230my$save_as="$hash";5231if(defined$file_name) {5232$save_as=$file_name;5233}elsif($type=~m/^text\//) {5234$save_as.='.txt';5235}52365237# With XSS prevention on, blobs of all types except a few known safe5238# ones are served with "Content-Disposition: attachment" to make sure5239# they don't run in our security domain. For certain image types,5240# blob view writes an <img> tag referring to blob_plain view, and we5241# want to be sure not to break that by serving the image as an5242# attachment (though Firefox 3 doesn't seem to care).5243my$sandbox=$prevent_xss&&5244$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;52455246print$cgi->header(5247-type =>$type,5248-expires =>$expires,5249-content_disposition =>5250($sandbox?'attachment':'inline')5251.'; filename="'.$save_as.'"');5252local$/=undef;5253binmode STDOUT,':raw';5254print<$fd>;5255binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5256close$fd;5257}52585259sub git_blob {5260my$expires;52615262if(!defined$hash) {5263if(defined$file_name) {5264my$base=$hash_base|| git_get_head_hash($project);5265$hash= git_get_hash_by_path($base,$file_name,"blob")5266or die_error(404,"Cannot find file");5267}else{5268 die_error(400,"No file name defined");5269}5270}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {5271# blobs defined by non-textual hash id's can be cached5272$expires="+1d";5273}52745275my$have_blame= gitweb_check_feature('blame');5276open my$fd,"-|", git_cmd(),"cat-file","blob",$hash5277or die_error(500,"Couldn't cat$file_name,$hash");5278my$mimetype= blob_mimetype($fd,$file_name);5279if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {5280close$fd;5281return git_blob_plain($mimetype);5282}5283# we can have blame only for text/* mimetype5284$have_blame&&= ($mimetype=~m!^text/!);52855286 git_header_html(undef,$expires);5287my$formats_nav='';5288if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5289if(defined$file_name) {5290if($have_blame) {5291$formats_nav.=5292$cgi->a({-href => href(action=>"blame", -replay=>1)},5293"blame") .5294" | ";5295}5296$formats_nav.=5297$cgi->a({-href => href(action=>"history", -replay=>1)},5298"history") .5299" | ".5300$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5301"raw") .5302" | ".5303$cgi->a({-href => href(action=>"blob",5304 hash_base=>"HEAD", file_name=>$file_name)},5305"HEAD");5306}else{5307$formats_nav.=5308$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},5309"raw");5310}5311 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5312 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5313}else{5314print"<div class=\"page_nav\">\n".5315"<br/><br/></div>\n".5316"<div class=\"title\">$hash</div>\n";5317}5318 git_print_page_path($file_name,"blob",$hash_base);5319print"<div class=\"page_body\">\n";5320if($mimetype=~m!^image/!) {5321print qq!<img type="$mimetype"!;5322if($file_name) {5323print qq! alt="$file_name" title="$file_name"!;5324}5325print qq! src="! .5326 href(action=>"blob_plain", hash=>$hash,5327 hash_base=>$hash_base, file_name=>$file_name) .5328 qq!"/>\n!;5329}else{5330my$nr;5331while(my$line= <$fd>) {5332chomp$line;5333$nr++;5334$line= untabify($line);5335printf"<div class=\"pre\"><a id=\"l%i\"href=\"". href(-replay =>1)5336."#l%i\"class=\"linenr\">%4i</a>%s</div>\n",5337$nr,$nr,$nr, esc_html($line, -nbsp=>1);5338}5339}5340close$fd5341or print"Reading blob failed.\n";5342print"</div>";5343 git_footer_html();5344}53455346sub git_tree {5347if(!defined$hash_base) {5348$hash_base="HEAD";5349}5350if(!defined$hash) {5351if(defined$file_name) {5352$hash= git_get_hash_by_path($hash_base,$file_name,"tree");5353}else{5354$hash=$hash_base;5355}5356}5357 die_error(404,"No such tree")unlessdefined($hash);53585359my$show_sizes= gitweb_check_feature('show-sizes');5360my$have_blame= gitweb_check_feature('blame');53615362my@entries= ();5363{5364local$/="\0";5365open my$fd,"-|", git_cmd(),"ls-tree",'-z',5366($show_sizes?'-l': ()),@extra_options,$hash5367or die_error(500,"Open git-ls-tree failed");5368@entries=map{chomp;$_} <$fd>;5369close$fd5370or die_error(404,"Reading tree failed");5371}53725373my$refs= git_get_references();5374my$ref= format_ref_marker($refs,$hash_base);5375 git_header_html();5376my$basedir='';5377if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5378my@views_nav= ();5379if(defined$file_name) {5380push@views_nav,5381$cgi->a({-href => href(action=>"history", -replay=>1)},5382"history"),5383$cgi->a({-href => href(action=>"tree",5384 hash_base=>"HEAD", file_name=>$file_name)},5385"HEAD"),5386}5387my$snapshot_links= format_snapshot_links($hash);5388if(defined$snapshot_links) {5389# FIXME: Should be available when we have no hash base as well.5390push@views_nav,$snapshot_links;5391}5392 git_print_page_nav('tree','',$hash_base,undef,undef,5393join(' | ',@views_nav));5394 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);5395}else{5396undef$hash_base;5397print"<div class=\"page_nav\">\n";5398print"<br/><br/></div>\n";5399print"<div class=\"title\">$hash</div>\n";5400}5401if(defined$file_name) {5402$basedir=$file_name;5403if($basedirne''&&substr($basedir, -1)ne'/') {5404$basedir.='/';5405}5406 git_print_page_path($file_name,'tree',$hash_base);5407}5408print"<div class=\"page_body\">\n";5409print"<table class=\"tree\">\n";5410my$alternate=1;5411# '..' (top directory) link if possible5412if(defined$hash_base&&5413defined$file_name&&$file_name=~m![^/]+$!) {5414if($alternate) {5415print"<tr class=\"dark\">\n";5416}else{5417print"<tr class=\"light\">\n";5418}5419$alternate^=1;54205421my$up=$file_name;5422$up=~s!/?[^/]+$!!;5423undef$upunless$up;5424# based on git_print_tree_entry5425print'<td class="mode">'. mode_str('040000') ."</td>\n";5426print'<td class="size"> </td>'."\n"if$show_sizes;5427print'<td class="list">';5428print$cgi->a({-href => href(action=>"tree",5429 hash_base=>$hash_base,5430 file_name=>$up)},5431"..");5432print"</td>\n";5433print"<td class=\"link\"></td>\n";54345435print"</tr>\n";5436}5437foreachmy$line(@entries) {5438my%t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);54395440if($alternate) {5441print"<tr class=\"dark\">\n";5442}else{5443print"<tr class=\"light\">\n";5444}5445$alternate^=1;54465447 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);54485449print"</tr>\n";5450}5451print"</table>\n".5452"</div>";5453 git_footer_html();5454}54555456sub snapshot_name {5457my($project,$hash) =@_;54585459# path/to/project.git -> project5460# path/to/project/.git -> project5461my$name= to_utf8($project);5462$name=~ s,([^/])/*\.git$,$1,;5463$name= basename($name);5464# sanitize name5465$name=~s/[[:cntrl:]]/?/g;54665467my$ver=$hash;5468if($hash=~/^[0-9a-fA-F]+$/) {5469# shorten SHA-1 hash5470my$full_hash= git_get_full_hash($project,$hash);5471if($full_hash=~/^$hash/&&length($hash) >7) {5472$ver= git_get_short_hash($project,$hash);5473}5474}elsif($hash=~m!^refs/tags/(.*)$!) {5475# tags don't need shortened SHA-1 hash5476$ver=$1;5477}else{5478# branches and other need shortened SHA-1 hash5479if($hash=~m!^refs/(?:heads|remotes)/(.*)$!) {5480$ver=$1;5481}5482$ver.='-'. git_get_short_hash($project,$hash);5483}5484# in case of hierarchical branch names5485$ver=~s!/!.!g;54865487# name = project-version_string5488$name="$name-$ver";54895490returnwantarray? ($name,$name) :$name;5491}54925493sub git_snapshot {5494my$format=$input_params{'snapshot_format'};5495if(!@snapshot_fmts) {5496 die_error(403,"Snapshots not allowed");5497}5498# default to first supported snapshot format5499$format||=$snapshot_fmts[0];5500if($format!~m/^[a-z0-9]+$/) {5501 die_error(400,"Invalid snapshot format parameter");5502}elsif(!exists($known_snapshot_formats{$format})) {5503 die_error(400,"Unknown snapshot format");5504}elsif($known_snapshot_formats{$format}{'disabled'}) {5505 die_error(403,"Snapshot format not allowed");5506}elsif(!grep($_eq$format,@snapshot_fmts)) {5507 die_error(403,"Unsupported snapshot format");5508}55095510my$type= git_get_type("$hash^{}");5511if(!$type) {5512 die_error(404,'Object does not exist');5513}elsif($typeeq'blob') {5514 die_error(400,'Object is not a tree-ish');5515}55165517my($name,$prefix) = snapshot_name($project,$hash);5518my$filename="$name$known_snapshot_formats{$format}{'suffix'}";5519my$cmd= quote_command(5520 git_cmd(),'archive',5521"--format=$known_snapshot_formats{$format}{'format'}",5522"--prefix=$prefix/",$hash);5523if(exists$known_snapshot_formats{$format}{'compressor'}) {5524$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});5525}55265527$filename=~s/(["\\])/\\$1/g;5528print$cgi->header(5529-type =>$known_snapshot_formats{$format}{'type'},5530-content_disposition =>'inline; filename="'.$filename.'"',5531-status =>'200 OK');55325533open my$fd,"-|",$cmd5534or die_error(500,"Execute git-archive failed");5535binmode STDOUT,':raw';5536print<$fd>;5537binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5538close$fd;5539}55405541sub git_log_generic {5542my($fmt_name,$body_subr,$base,$parent,$file_name,$file_hash) =@_;55435544my$head= git_get_head_hash($project);5545if(!defined$base) {5546$base=$head;5547}5548if(!defined$page) {5549$page=0;5550}5551my$refs= git_get_references();55525553my$commit_hash=$base;5554if(defined$parent) {5555$commit_hash="$parent..$base";5556}5557my@commitlist=5558 parse_commits($commit_hash,101, (100*$page),5559defined$file_name? ($file_name,"--full-history") : ());55605561my$ftype;5562if(!defined$file_hash&&defined$file_name) {5563# some commits could have deleted file in question,5564# and not have it in tree, but one of them has to have it5565for(my$i=0;$i<@commitlist;$i++) {5566$file_hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5567last ifdefined$file_hash;5568}5569}5570if(defined$file_hash) {5571$ftype= git_get_type($file_hash);5572}5573if(defined$file_name&& !defined$ftype) {5574 die_error(500,"Unknown type of object");5575}5576my%co;5577if(defined$file_name) {5578%co= parse_commit($base)5579or die_error(404,"Unknown commit object");5580}558155825583my$paging_nav= format_paging_nav($fmt_name,$page,$#commitlist>=100);5584my$next_link='';5585if($#commitlist>=100) {5586$next_link=5587$cgi->a({-href => href(-replay=>1, page=>$page+1),5588-accesskey =>"n", -title =>"Alt-n"},"next");5589}5590my$patch_max= gitweb_get_feature('patches');5591if($patch_max&& !defined$file_name) {5592if($patch_max<0||@commitlist<=$patch_max) {5593$paging_nav.=" ⋅ ".5594$cgi->a({-href => href(action=>"patches", -replay=>1)},5595"patches");5596}5597}55985599 git_header_html();5600 git_print_page_nav($fmt_name,'',$hash,$hash,$hash,$paging_nav);5601if(defined$file_name) {5602 git_print_header_div('commit', esc_html($co{'title'}),$base);5603}else{5604 git_print_header_div('summary',$project)5605}5606 git_print_page_path($file_name,$ftype,$hash_base)5607if(defined$file_name);56085609$body_subr->(\@commitlist,0,99,$refs,$next_link,5610$file_name,$file_hash,$ftype);56115612 git_footer_html();5613}56145615sub git_log {5616 git_log_generic('log', \&git_log_body,5617$hash,$hash_parent);5618}56195620sub git_commit {5621$hash||=$hash_base||"HEAD";5622my%co= parse_commit($hash)5623or die_error(404,"Unknown commit object");56245625my$parent=$co{'parent'};5626my$parents=$co{'parents'};# listref56275628# we need to prepare $formats_nav before any parameter munging5629my$formats_nav;5630if(!defined$parent) {5631# --root commitdiff5632$formats_nav.='(initial)';5633}elsif(@$parents==1) {5634# single parent commit5635$formats_nav.=5636'(parent: '.5637$cgi->a({-href => href(action=>"commit",5638 hash=>$parent)},5639 esc_html(substr($parent,0,7))) .5640')';5641}else{5642# merge commit5643$formats_nav.=5644'(merge: '.5645join(' ',map{5646$cgi->a({-href => href(action=>"commit",5647 hash=>$_)},5648 esc_html(substr($_,0,7)));5649}@$parents) .5650')';5651}5652if(gitweb_check_feature('patches') &&@$parents<=1) {5653$formats_nav.=" | ".5654$cgi->a({-href => href(action=>"patch", -replay=>1)},5655"patch");5656}56575658if(!defined$parent) {5659$parent="--root";5660}5661my@difftree;5662open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5663@diff_opts,5664(@$parents<=1?$parent:'-c'),5665$hash,"--"5666or die_error(500,"Open git-diff-tree failed");5667@difftree=map{chomp;$_} <$fd>;5668close$fdor die_error(404,"Reading git-diff-tree failed");56695670# non-textual hash id's can be cached5671my$expires;5672if($hash=~m/^[0-9a-fA-F]{40}$/) {5673$expires="+1d";5674}5675my$refs= git_get_references();5676my$ref= format_ref_marker($refs,$co{'id'});56775678 git_header_html(undef,$expires);5679 git_print_page_nav('commit','',5680$hash,$co{'tree'},$hash,5681$formats_nav);56825683if(defined$co{'parent'}) {5684 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5685}else{5686 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5687}5688print"<div class=\"title_text\">\n".5689"<table class=\"object_header\">\n";5690 git_print_authorship_rows(\%co);5691print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";5692print"<tr>".5693"<td>tree</td>".5694"<td class=\"sha1\">".5695$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),5696class=>"list"},$co{'tree'}) .5697"</td>".5698"<td class=\"link\">".5699$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},5700"tree");5701my$snapshot_links= format_snapshot_links($hash);5702if(defined$snapshot_links) {5703print" | ".$snapshot_links;5704}5705print"</td>".5706"</tr>\n";57075708foreachmy$par(@$parents) {5709print"<tr>".5710"<td>parent</td>".5711"<td class=\"sha1\">".5712$cgi->a({-href => href(action=>"commit", hash=>$par),5713class=>"list"},$par) .5714"</td>".5715"<td class=\"link\">".5716$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .5717" | ".5718$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .5719"</td>".5720"</tr>\n";5721}5722print"</table>".5723"</div>\n";57245725print"<div class=\"page_body\">\n";5726 git_print_log($co{'comment'});5727print"</div>\n";57285729 git_difftree_body(\@difftree,$hash,@$parents);57305731 git_footer_html();5732}57335734sub git_object {5735# object is defined by:5736# - hash or hash_base alone5737# - hash_base and file_name5738my$type;57395740# - hash or hash_base alone5741if($hash|| ($hash_base&& !defined$file_name)) {5742my$object_id=$hash||$hash_base;57435744open my$fd,"-|", quote_command(5745 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'5746or die_error(404,"Object does not exist");5747$type= <$fd>;5748chomp$type;5749close$fd5750or die_error(404,"Object does not exist");57515752# - hash_base and file_name5753}elsif($hash_base&&defined$file_name) {5754$file_name=~ s,/+$,,;57555756system(git_cmd(),"cat-file",'-e',$hash_base) ==05757or die_error(404,"Base object does not exist");57585759# here errors should not hapen5760open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name5761or die_error(500,"Open git-ls-tree failed");5762my$line= <$fd>;5763close$fd;57645765#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'5766unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {5767 die_error(404,"File or directory for given base does not exist");5768}5769$type=$2;5770$hash=$3;5771}else{5772 die_error(400,"Not enough information to find object");5773}57745775print$cgi->redirect(-uri => href(action=>$type, -full=>1,5776 hash=>$hash, hash_base=>$hash_base,5777 file_name=>$file_name),5778-status =>'302 Found');5779}57805781sub git_blobdiff {5782my$format=shift||'html';57835784my$fd;5785my@difftree;5786my%diffinfo;5787my$expires;57885789# preparing $fd and %diffinfo for git_patchset_body5790# new style URI5791if(defined$hash_base&&defined$hash_parent_base) {5792if(defined$file_name) {5793# read raw output5794open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5795$hash_parent_base,$hash_base,5796"--", (defined$file_parent?$file_parent: ()),$file_name5797or die_error(500,"Open git-diff-tree failed");5798@difftree=map{chomp;$_} <$fd>;5799close$fd5800or die_error(404,"Reading git-diff-tree failed");5801@difftree5802or die_error(404,"Blob diff not found");58035804}elsif(defined$hash&&5805$hash=~/[0-9a-fA-F]{40}/) {5806# try to find filename from $hash58075808# read filtered raw output5809open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5810$hash_parent_base,$hash_base,"--"5811or die_error(500,"Open git-diff-tree failed");5812@difftree=5813# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5814# $hash == to_id5815grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5816map{chomp;$_} <$fd>;5817close$fd5818or die_error(404,"Reading git-diff-tree failed");5819@difftree5820or die_error(404,"Blob diff not found");58215822}else{5823 die_error(400,"Missing one of the blob diff parameters");5824}58255826if(@difftree>1) {5827 die_error(400,"Ambiguous blob diff specification");5828}58295830%diffinfo= parse_difftree_raw_line($difftree[0]);5831$file_parent||=$diffinfo{'from_file'} ||$file_name;5832$file_name||=$diffinfo{'to_file'};58335834$hash_parent||=$diffinfo{'from_id'};5835$hash||=$diffinfo{'to_id'};58365837# non-textual hash id's can be cached5838if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5839$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5840$expires='+1d';5841}58425843# open patch output5844open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5845'-p', ($formateq'html'?"--full-index": ()),5846$hash_parent_base,$hash_base,5847"--", (defined$file_parent?$file_parent: ()),$file_name5848or die_error(500,"Open git-diff-tree failed");5849}58505851# old/legacy style URI -- not generated anymore since 1.4.3.5852if(!%diffinfo) {5853 die_error('404 Not Found',"Missing one of the blob diff parameters")5854}58555856# header5857if($formateq'html') {5858my$formats_nav=5859$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5860"raw");5861 git_header_html(undef,$expires);5862if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5863 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5864 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5865}else{5866print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5867print"<div class=\"title\">$hashvs$hash_parent</div>\n";5868}5869if(defined$file_name) {5870 git_print_page_path($file_name,"blob",$hash_base);5871}else{5872print"<div class=\"page_path\"></div>\n";5873}58745875}elsif($formateq'plain') {5876print$cgi->header(5877-type =>'text/plain',5878-charset =>'utf-8',5879-expires =>$expires,5880-content_disposition =>'inline; filename="'."$file_name".'.patch"');58815882print"X-Git-Url: ".$cgi->self_url() ."\n\n";58835884}else{5885 die_error(400,"Unknown blobdiff format");5886}58875888# patch5889if($formateq'html') {5890print"<div class=\"page_body\">\n";58915892 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5893close$fd;58945895print"</div>\n";# class="page_body"5896 git_footer_html();58975898}else{5899while(my$line= <$fd>) {5900$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5901$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;59025903print$line;59045905last if$line=~m!^\+\+\+!;5906}5907local$/=undef;5908print<$fd>;5909close$fd;5910}5911}59125913sub git_blobdiff_plain {5914 git_blobdiff('plain');5915}59165917sub git_commitdiff {5918my%params=@_;5919my$format=$params{-format} ||'html';59205921my($patch_max) = gitweb_get_feature('patches');5922if($formateq'patch') {5923 die_error(403,"Patch view not allowed")unless$patch_max;5924}59255926$hash||=$hash_base||"HEAD";5927my%co= parse_commit($hash)5928or die_error(404,"Unknown commit object");59295930# choose format for commitdiff for merge5931if(!defined$hash_parent&& @{$co{'parents'}} >1) {5932$hash_parent='--cc';5933}5934# we need to prepare $formats_nav before almost any parameter munging5935my$formats_nav;5936if($formateq'html') {5937$formats_nav=5938$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},5939"raw");5940if($patch_max&& @{$co{'parents'}} <=1) {5941$formats_nav.=" | ".5942$cgi->a({-href => href(action=>"patch", -replay=>1)},5943"patch");5944}59455946if(defined$hash_parent&&5947$hash_parentne'-c'&&$hash_parentne'--cc') {5948# commitdiff with two commits given5949my$hash_parent_short=$hash_parent;5950if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {5951$hash_parent_short=substr($hash_parent,0,7);5952}5953$formats_nav.=5954' (from';5955for(my$i=0;$i< @{$co{'parents'}};$i++) {5956if($co{'parents'}[$i]eq$hash_parent) {5957$formats_nav.=' parent '. ($i+1);5958last;5959}5960}5961$formats_nav.=': '.5962$cgi->a({-href => href(action=>"commitdiff",5963 hash=>$hash_parent)},5964 esc_html($hash_parent_short)) .5965')';5966}elsif(!$co{'parent'}) {5967# --root commitdiff5968$formats_nav.=' (initial)';5969}elsif(scalar@{$co{'parents'}} ==1) {5970# single parent commit5971$formats_nav.=5972' (parent: '.5973$cgi->a({-href => href(action=>"commitdiff",5974 hash=>$co{'parent'})},5975 esc_html(substr($co{'parent'},0,7))) .5976')';5977}else{5978# merge commit5979if($hash_parenteq'--cc') {5980$formats_nav.=' | '.5981$cgi->a({-href => href(action=>"commitdiff",5982 hash=>$hash, hash_parent=>'-c')},5983'combined');5984}else{# $hash_parent eq '-c'5985$formats_nav.=' | '.5986$cgi->a({-href => href(action=>"commitdiff",5987 hash=>$hash, hash_parent=>'--cc')},5988'compact');5989}5990$formats_nav.=5991' (merge: '.5992join(' ',map{5993$cgi->a({-href => href(action=>"commitdiff",5994 hash=>$_)},5995 esc_html(substr($_,0,7)));5996} @{$co{'parents'}} ) .5997')';5998}5999}60006001my$hash_parent_param=$hash_parent;6002if(!defined$hash_parent_param) {6003# --cc for multiple parents, --root for parentless6004$hash_parent_param=6005@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';6006}60076008# read commitdiff6009my$fd;6010my@difftree;6011if($formateq'html') {6012open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6013"--no-commit-id","--patch-with-raw","--full-index",6014$hash_parent_param,$hash,"--"6015or die_error(500,"Open git-diff-tree failed");60166017while(my$line= <$fd>) {6018chomp$line;6019# empty line ends raw part of diff-tree output6020last unless$line;6021push@difftree,scalar parse_difftree_raw_line($line);6022}60236024}elsif($formateq'plain') {6025open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6026'-p',$hash_parent_param,$hash,"--"6027or die_error(500,"Open git-diff-tree failed");6028}elsif($formateq'patch') {6029# For commit ranges, we limit the output to the number of6030# patches specified in the 'patches' feature.6031# For single commits, we limit the output to a single patch,6032# diverging from the git-format-patch default.6033my@commit_spec= ();6034if($hash_parent) {6035if($patch_max>0) {6036push@commit_spec,"-$patch_max";6037}6038push@commit_spec,'-n',"$hash_parent..$hash";6039}else{6040if($params{-single}) {6041push@commit_spec,'-1';6042}else{6043if($patch_max>0) {6044push@commit_spec,"-$patch_max";6045}6046push@commit_spec,"-n";6047}6048push@commit_spec,'--root',$hash;6049}6050open$fd,"-|", git_cmd(),"format-patch",'--encoding=utf8',6051'--stdout',@commit_spec6052or die_error(500,"Open git-format-patch failed");6053}else{6054 die_error(400,"Unknown commitdiff format");6055}60566057# non-textual hash id's can be cached6058my$expires;6059if($hash=~m/^[0-9a-fA-F]{40}$/) {6060$expires="+1d";6061}60626063# write commit message6064if($formateq'html') {6065my$refs= git_get_references();6066my$ref= format_ref_marker($refs,$co{'id'});60676068 git_header_html(undef,$expires);6069 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);6070 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);6071print"<div class=\"title_text\">\n".6072"<table class=\"object_header\">\n";6073 git_print_authorship_rows(\%co);6074print"</table>".6075"</div>\n";6076print"<div class=\"page_body\">\n";6077if(@{$co{'comment'}} >1) {6078print"<div class=\"log\">\n";6079 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);6080print"</div>\n";# class="log"6081}60826083}elsif($formateq'plain') {6084my$refs= git_get_references("tags");6085my$tagname= git_get_rev_name_tags($hash);6086my$filename= basename($project) ."-$hash.patch";60876088print$cgi->header(6089-type =>'text/plain',6090-charset =>'utf-8',6091-expires =>$expires,6092-content_disposition =>'inline; filename="'."$filename".'"');6093my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});6094print"From: ". to_utf8($co{'author'}) ."\n";6095print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";6096print"Subject: ". to_utf8($co{'title'}) ."\n";60976098print"X-Git-Tag:$tagname\n"if$tagname;6099print"X-Git-Url: ".$cgi->self_url() ."\n\n";61006101foreachmy$line(@{$co{'comment'}}) {6102print to_utf8($line) ."\n";6103}6104print"---\n\n";6105}elsif($formateq'patch') {6106my$filename= basename($project) ."-$hash.patch";61076108print$cgi->header(6109-type =>'text/plain',6110-charset =>'utf-8',6111-expires =>$expires,6112-content_disposition =>'inline; filename="'."$filename".'"');6113}61146115# write patch6116if($formateq'html') {6117my$use_parents= !defined$hash_parent||6118$hash_parenteq'-c'||$hash_parenteq'--cc';6119 git_difftree_body(\@difftree,$hash,6120$use_parents? @{$co{'parents'}} :$hash_parent);6121print"<br/>\n";61226123 git_patchset_body($fd, \@difftree,$hash,6124$use_parents? @{$co{'parents'}} :$hash_parent);6125close$fd;6126print"</div>\n";# class="page_body"6127 git_footer_html();61286129}elsif($formateq'plain') {6130local$/=undef;6131print<$fd>;6132close$fd6133or print"Reading git-diff-tree failed\n";6134}elsif($formateq'patch') {6135local$/=undef;6136print<$fd>;6137close$fd6138or print"Reading git-format-patch failed\n";6139}6140}61416142sub git_commitdiff_plain {6143 git_commitdiff(-format =>'plain');6144}61456146# format-patch-style patches6147sub git_patch {6148 git_commitdiff(-format =>'patch', -single =>1);6149}61506151sub git_patches {6152 git_commitdiff(-format =>'patch');6153}61546155sub git_history {6156 git_log_generic('history', \&git_history_body,6157$hash_base,$hash_parent_base,6158$file_name,$hash);6159}61606161sub git_search {6162 gitweb_check_feature('search')or die_error(403,"Search is disabled");6163if(!defined$searchtext) {6164 die_error(400,"Text field is empty");6165}6166if(!defined$hash) {6167$hash= git_get_head_hash($project);6168}6169my%co= parse_commit($hash);6170if(!%co) {6171 die_error(404,"Unknown commit object");6172}6173if(!defined$page) {6174$page=0;6175}61766177$searchtype||='commit';6178if($searchtypeeq'pickaxe') {6179# pickaxe may take all resources of your box and run for several minutes6180# with every query - so decide by yourself how public you make this feature6181 gitweb_check_feature('pickaxe')6182or die_error(403,"Pickaxe is disabled");6183}6184if($searchtypeeq'grep') {6185 gitweb_check_feature('grep')6186or die_error(403,"Grep is disabled");6187}61886189 git_header_html();61906191if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {6192my$greptype;6193if($searchtypeeq'commit') {6194$greptype="--grep=";6195}elsif($searchtypeeq'author') {6196$greptype="--author=";6197}elsif($searchtypeeq'committer') {6198$greptype="--committer=";6199}6200$greptype.=$searchtext;6201my@commitlist= parse_commits($hash,101, (100*$page),undef,6202$greptype,'--regexp-ignore-case',6203$search_use_regexp?'--extended-regexp':'--fixed-strings');62046205my$paging_nav='';6206if($page>0) {6207$paging_nav.=6208$cgi->a({-href => href(action=>"search", hash=>$hash,6209 searchtext=>$searchtext,6210 searchtype=>$searchtype)},6211"first");6212$paging_nav.=" ⋅ ".6213$cgi->a({-href => href(-replay=>1, page=>$page-1),6214-accesskey =>"p", -title =>"Alt-p"},"prev");6215}else{6216$paging_nav.="first";6217$paging_nav.=" ⋅ prev";6218}6219my$next_link='';6220if($#commitlist>=100) {6221$next_link=6222$cgi->a({-href => href(-replay=>1, page=>$page+1),6223-accesskey =>"n", -title =>"Alt-n"},"next");6224$paging_nav.=" ⋅$next_link";6225}else{6226$paging_nav.=" ⋅ next";6227}62286229if($#commitlist>=100) {6230}62316232 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);6233 git_print_header_div('commit', esc_html($co{'title'}),$hash);6234 git_search_grep_body(\@commitlist,0,99,$next_link);6235}62366237if($searchtypeeq'pickaxe') {6238 git_print_page_nav('','',$hash,$co{'tree'},$hash);6239 git_print_header_div('commit', esc_html($co{'title'}),$hash);62406241print"<table class=\"pickaxe search\">\n";6242my$alternate=1;6243local$/="\n";6244open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,6245'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",6246($search_use_regexp?'--pickaxe-regex': ());6247undef%co;6248my@files;6249while(my$line= <$fd>) {6250chomp$line;6251next unless$line;62526253my%set= parse_difftree_raw_line($line);6254if(defined$set{'commit'}) {6255# finish previous commit6256if(%co) {6257print"</td>\n".6258"<td class=\"link\">".6259$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6260" | ".6261$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6262print"</td>\n".6263"</tr>\n";6264}62656266if($alternate) {6267print"<tr class=\"dark\">\n";6268}else{6269print"<tr class=\"light\">\n";6270}6271$alternate^=1;6272%co= parse_commit($set{'commit'});6273my$author= chop_and_escape_str($co{'author_name'},15,5);6274print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".6275"<td><i>$author</i></td>\n".6276"<td>".6277$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6278-class=>"list subject"},6279 chop_and_escape_str($co{'title'},50) ."<br/>");6280}elsif(defined$set{'to_id'}) {6281next if($set{'to_id'} =~m/^0{40}$/);62826283print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6284 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6285-class=>"list"},6286"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6287"<br/>\n";6288}6289}6290close$fd;62916292# finish last commit (warning: repetition!)6293if(%co) {6294print"</td>\n".6295"<td class=\"link\">".6296$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .6297" | ".6298$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6299print"</td>\n".6300"</tr>\n";6301}63026303print"</table>\n";6304}63056306if($searchtypeeq'grep') {6307 git_print_page_nav('','',$hash,$co{'tree'},$hash);6308 git_print_header_div('commit', esc_html($co{'title'}),$hash);63096310print"<table class=\"grep_search\">\n";6311my$alternate=1;6312my$matches=0;6313local$/="\n";6314open my$fd,"-|", git_cmd(),'grep','-n',6315$search_use_regexp? ('-E','-i') :'-F',6316$searchtext,$co{'tree'};6317my$lastfile='';6318while(my$line= <$fd>) {6319chomp$line;6320my($file,$lno,$ltext,$binary);6321last if($matches++>1000);6322if($line=~/^Binary file (.+) matches$/) {6323$file=$1;6324$binary=1;6325}else{6326(undef,$file,$lno,$ltext) =split(/:/,$line,4);6327}6328if($filene$lastfile) {6329$lastfileand print"</td></tr>\n";6330if($alternate++) {6331print"<tr class=\"dark\">\n";6332}else{6333print"<tr class=\"light\">\n";6334}6335print"<td class=\"list\">".6336$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6337 file_name=>"$file"),6338-class=>"list"}, esc_path($file));6339print"</td><td>\n";6340$lastfile=$file;6341}6342if($binary) {6343print"<div class=\"binary\">Binary file</div>\n";6344}else{6345$ltext= untabify($ltext);6346if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6347$ltext= esc_html($1, -nbsp=>1);6348$ltext.='<span class="match">';6349$ltext.= esc_html($2, -nbsp=>1);6350$ltext.='</span>';6351$ltext.= esc_html($3, -nbsp=>1);6352}else{6353$ltext= esc_html($ltext, -nbsp=>1);6354}6355print"<div class=\"pre\">".6356$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},6357 file_name=>"$file").'#l'.$lno,6358-class=>"linenr"},sprintf('%4i',$lno))6359.' '.$ltext."</div>\n";6360}6361}6362if($lastfile) {6363print"</td></tr>\n";6364if($matches>1000) {6365print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";6366}6367}else{6368print"<div class=\"diff nodifferences\">No matches found</div>\n";6369}6370close$fd;63716372print"</table>\n";6373}6374 git_footer_html();6375}63766377sub git_search_help {6378 git_header_html();6379 git_print_page_nav('','',$hash,$hash,$hash);6380print<<EOT;6381<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without6382regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,6383the pattern entered is recognized as the POSIX extended6384<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case6385insensitive).</p>6386<dl>6387<dt><b>commit</b></dt>6388<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>6389EOT6390my$have_grep= gitweb_check_feature('grep');6391if($have_grep) {6392print<<EOT;6393<dt><b>grep</b></dt>6394<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing6395 a different one) are searched for the given pattern. On large trees, this search can take6396a while and put some strain on the server, so please use it with some consideration. Note that6397due to git-grep peculiarity, currently if regexp mode is turned off, the matches are6398case-sensitive.</dd>6399EOT6400}6401print<<EOT;6402<dt><b>author</b></dt>6403<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>6404<dt><b>committer</b></dt>6405<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>6406EOT6407my$have_pickaxe= gitweb_check_feature('pickaxe');6408if($have_pickaxe) {6409print<<EOT;6410<dt><b>pickaxe</b></dt>6411<dd>All commits that caused the string to appear or disappear from any file (changes that6412added, removed or "modified" the string) will be listed. This search can take a while and6413takes a lot of strain on the server, so please use it wisely. Note that since you may be6414interested even in changes just changing the case as well, this search is case sensitive.</dd>6415EOT6416}6417print"</dl>\n";6418 git_footer_html();6419}64206421sub git_shortlog {6422 git_log_generic('shortlog', \&git_shortlog_body,6423$hash,$hash_parent);6424}64256426## ......................................................................6427## feeds (RSS, Atom; OPML)64286429sub git_feed {6430my$format=shift||'atom';6431my$have_blame= gitweb_check_feature('blame');64326433# Atom: http://www.atomenabled.org/developers/syndication/6434# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ6435if($formatne'rss'&&$formatne'atom') {6436 die_error(400,"Unknown web feed format");6437}64386439# log/feed of current (HEAD) branch, log of given branch, history of file/directory6440my$head=$hash||'HEAD';6441my@commitlist= parse_commits($head,150,0,$file_name);64426443my%latest_commit;6444my%latest_date;6445my$content_type="application/$format+xml";6446if(defined$cgi->http('HTTP_ACCEPT') &&6447$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {6448# browser (feed reader) prefers text/xml6449$content_type='text/xml';6450}6451if(defined($commitlist[0])) {6452%latest_commit= %{$commitlist[0]};6453my$latest_epoch=$latest_commit{'committer_epoch'};6454%latest_date= parse_date($latest_epoch);6455my$if_modified=$cgi->http('IF_MODIFIED_SINCE');6456if(defined$if_modified) {6457my$since;6458if(eval{require HTTP::Date;1; }) {6459$since= HTTP::Date::str2time($if_modified);6460}elsif(eval{require Time::ParseDate;1; }) {6461$since= Time::ParseDate::parsedate($if_modified, GMT =>1);6462}6463if(defined$since&&$latest_epoch<=$since) {6464print$cgi->header(6465-type =>$content_type,6466-charset =>'utf-8',6467-last_modified =>$latest_date{'rfc2822'},6468-status =>'304 Not Modified');6469return;6470}6471}6472print$cgi->header(6473-type =>$content_type,6474-charset =>'utf-8',6475-last_modified =>$latest_date{'rfc2822'});6476}else{6477print$cgi->header(6478-type =>$content_type,6479-charset =>'utf-8');6480}64816482# Optimization: skip generating the body if client asks only6483# for Last-Modified date.6484return if($cgi->request_method()eq'HEAD');64856486# header variables6487my$title="$site_name-$project/$action";6488my$feed_type='log';6489if(defined$hash) {6490$title.=" - '$hash'";6491$feed_type='branch log';6492if(defined$file_name) {6493$title.=" ::$file_name";6494$feed_type='history';6495}6496}elsif(defined$file_name) {6497$title.=" -$file_name";6498$feed_type='history';6499}6500$title.="$feed_type";6501my$descr= git_get_project_description($project);6502if(defined$descr) {6503$descr= esc_html($descr);6504}else{6505$descr="$project".6506($formateq'rss'?'RSS':'Atom') .6507" feed";6508}6509my$owner= git_get_project_owner($project);6510$owner= esc_html($owner);65116512#header6513my$alt_url;6514if(defined$file_name) {6515$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);6516}elsif(defined$hash) {6517$alt_url= href(-full=>1, action=>"log", hash=>$hash);6518}else{6519$alt_url= href(-full=>1, action=>"summary");6520}6521print qq!<?xml version="1.0" encoding="utf-8"?>\n!;6522if($formateq'rss') {6523print<<XML;6524<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">6525<channel>6526XML6527print"<title>$title</title>\n".6528"<link>$alt_url</link>\n".6529"<description>$descr</description>\n".6530"<language>en</language>\n".6531# project owner is responsible for 'editorial' content6532"<managingEditor>$owner</managingEditor>\n";6533if(defined$logo||defined$favicon) {6534# prefer the logo to the favicon, since RSS6535# doesn't allow both6536my$img= esc_url($logo||$favicon);6537print"<image>\n".6538"<url>$img</url>\n".6539"<title>$title</title>\n".6540"<link>$alt_url</link>\n".6541"</image>\n";6542}6543if(%latest_date) {6544print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";6545print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";6546}6547print"<generator>gitweb v.$version/$git_version</generator>\n";6548}elsif($formateq'atom') {6549print<<XML;6550<feed xmlns="http://www.w3.org/2005/Atom">6551XML6552print"<title>$title</title>\n".6553"<subtitle>$descr</subtitle>\n".6554'<link rel="alternate" type="text/html" href="'.6555$alt_url.'" />'."\n".6556'<link rel="self" type="'.$content_type.'" href="'.6557$cgi->self_url() .'" />'."\n".6558"<id>". href(-full=>1) ."</id>\n".6559# use project owner for feed author6560"<author><name>$owner</name></author>\n";6561if(defined$favicon) {6562print"<icon>". esc_url($favicon) ."</icon>\n";6563}6564if(defined$logo_url) {6565# not twice as wide as tall: 72 x 27 pixels6566print"<logo>". esc_url($logo) ."</logo>\n";6567}6568if(!%latest_date) {6569# dummy date to keep the feed valid until commits trickle in:6570print"<updated>1970-01-01T00:00:00Z</updated>\n";6571}else{6572print"<updated>$latest_date{'iso-8601'}</updated>\n";6573}6574print"<generator version='$version/$git_version'>gitweb</generator>\n";6575}65766577# contents6578for(my$i=0;$i<=$#commitlist;$i++) {6579my%co= %{$commitlist[$i]};6580my$commit=$co{'id'};6581# we read 150, we always show 30 and the ones more recent than 48 hours6582if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6583last;6584}6585my%cd= parse_date($co{'author_epoch'});65866587# get list of changed files6588open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6589$co{'parent'} ||"--root",6590$co{'id'},"--", (defined$file_name?$file_name: ())6591ornext;6592my@difftree=map{chomp;$_} <$fd>;6593close$fd6594ornext;65956596# print element (entry, item)6597my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6598if($formateq'rss') {6599print"<item>\n".6600"<title>". esc_html($co{'title'}) ."</title>\n".6601"<author>". esc_html($co{'author'}) ."</author>\n".6602"<pubDate>$cd{'rfc2822'}</pubDate>\n".6603"<guid isPermaLink=\"true\">$co_url</guid>\n".6604"<link>$co_url</link>\n".6605"<description>". esc_html($co{'title'}) ."</description>\n".6606"<content:encoded>".6607"<![CDATA[\n";6608}elsif($formateq'atom') {6609print"<entry>\n".6610"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6611"<updated>$cd{'iso-8601'}</updated>\n".6612"<author>\n".6613" <name>". esc_html($co{'author_name'}) ."</name>\n";6614if($co{'author_email'}) {6615print" <email>". esc_html($co{'author_email'}) ."</email>\n";6616}6617print"</author>\n".6618# use committer for contributor6619"<contributor>\n".6620" <name>". esc_html($co{'committer_name'}) ."</name>\n";6621if($co{'committer_email'}) {6622print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6623}6624print"</contributor>\n".6625"<published>$cd{'iso-8601'}</published>\n".6626"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6627"<id>$co_url</id>\n".6628"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6629"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6630}6631my$comment=$co{'comment'};6632print"<pre>\n";6633foreachmy$line(@$comment) {6634$line= esc_html($line);6635print"$line\n";6636}6637print"</pre><ul>\n";6638foreachmy$difftree_line(@difftree) {6639my%difftree= parse_difftree_raw_line($difftree_line);6640next if!$difftree{'from_id'};66416642my$file=$difftree{'file'} ||$difftree{'to_file'};66436644print"<li>".6645"[".6646$cgi->a({-href => href(-full=>1, action=>"blobdiff",6647 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6648 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6649 file_name=>$file, file_parent=>$difftree{'from_file'}),6650-title =>"diff"},'D');6651if($have_blame) {6652print$cgi->a({-href => href(-full=>1, action=>"blame",6653 file_name=>$file, hash_base=>$commit),6654-title =>"blame"},'B');6655}6656# if this is not a feed of a file history6657if(!defined$file_name||$file_namene$file) {6658print$cgi->a({-href => href(-full=>1, action=>"history",6659 file_name=>$file, hash=>$commit),6660-title =>"history"},'H');6661}6662$file= esc_path($file);6663print"] ".6664"$file</li>\n";6665}6666if($formateq'rss') {6667print"</ul>]]>\n".6668"</content:encoded>\n".6669"</item>\n";6670}elsif($formateq'atom') {6671print"</ul>\n</div>\n".6672"</content>\n".6673"</entry>\n";6674}6675}66766677# end of feed6678if($formateq'rss') {6679print"</channel>\n</rss>\n";6680}elsif($formateq'atom') {6681print"</feed>\n";6682}6683}66846685sub git_rss {6686 git_feed('rss');6687}66886689sub git_atom {6690 git_feed('atom');6691}66926693sub git_opml {6694my@list= git_get_projects_list();66956696print$cgi->header(6697-type =>'text/xml',6698-charset =>'utf-8',6699-content_disposition =>'inline; filename="opml.xml"');67006701print<<XML;6702<?xml version="1.0" encoding="utf-8"?>6703<opml version="1.0">6704<head>6705 <title>$site_nameOPML Export</title>6706</head>6707<body>6708<outline text="git RSS feeds">6709XML67106711foreachmy$pr(@list) {6712my%proj=%$pr;6713my$head= git_get_head_hash($proj{'path'});6714if(!defined$head) {6715next;6716}6717$git_dir="$projectroot/$proj{'path'}";6718my%co= parse_commit($head);6719if(!%co) {6720next;6721}67226723my$path= esc_html(chop_str($proj{'path'},25,5));6724my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);6725my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);6726print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";6727}6728print<<XML;6729</outline>6730</body>6731</opml>6732XML6733}