1#!/usr/bin/perl 2 3# gitweb - simple web interface to track changes in git repositories 4# 5# (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org> 6# (C) 2005, Christian Gierke 7# 8# This program is licensed under the GPLv2 9 10use strict; 11use warnings; 12use CGI qw(:standard :escapeHTML -nosticky); 13use CGI::Util qw(unescape); 14use CGI::Carp qw(fatalsToBrowser); 15use Encode; 16use Fcntl ':mode'; 17use File::Find qw(); 18use File::Basename qw(basename); 19binmode STDOUT,':utf8'; 20 21BEGIN{ 22 CGI->compile()if$ENV{'MOD_PERL'}; 23} 24 25our$cgi= new CGI; 26our$version="++GIT_VERSION++"; 27our$my_url=$cgi->url(); 28our$my_uri=$cgi->url(-absolute =>1); 29 30# if we're called with PATH_INFO, we have to strip that 31# from the URL to find our real URL 32# we make $path_info global because it's also used later on 33our$path_info=$ENV{"PATH_INFO"}; 34if($path_info) { 35$my_url=~ s,\Q$path_info\E$,,; 36$my_uri=~ s,\Q$path_info\E$,,; 37} 38 39# core git executable to use 40# this can just be "git" if your webserver has a sensible PATH 41our$GIT="++GIT_BINDIR++/git"; 42 43# absolute fs-path which will be prepended to the project path 44#our $projectroot = "/pub/scm"; 45our$projectroot="++GITWEB_PROJECTROOT++"; 46 47# fs traversing limit for getting project list 48# the number is relative to the projectroot 49our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 50 51# target of the home link on top of all pages 52our$home_link=$my_uri||"/"; 53 54# string of the home link on top of all pages 55our$home_link_str="++GITWEB_HOME_LINK_STR++"; 56 57# name of your site or organization to appear in page titles 58# replace this with something more descriptive for clearer bookmarks 59our$site_name="++GITWEB_SITENAME++" 60|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 61 62# filename of html text to include at top of each page 63our$site_header="++GITWEB_SITE_HEADER++"; 64# html text to include at home page 65our$home_text="++GITWEB_HOMETEXT++"; 66# filename of html text to include at bottom of each page 67our$site_footer="++GITWEB_SITE_FOOTER++"; 68 69# URI of stylesheets 70our@stylesheets= ("++GITWEB_CSS++"); 71# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 72our$stylesheet=undef; 73# URI of GIT logo (72x27 size) 74our$logo="++GITWEB_LOGO++"; 75# URI of GIT favicon, assumed to be image/png type 76our$favicon="++GITWEB_FAVICON++"; 77 78# URI and label (title) of GIT logo link 79#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 80#our $logo_label = "git documentation"; 81our$logo_url="http://git.or.cz/"; 82our$logo_label="git homepage"; 83 84# source of projects list 85our$projects_list="++GITWEB_LIST++"; 86 87# the width (in characters) of the projects list "Description" column 88our$projects_list_description_width=25; 89 90# default order of projects list 91# valid values are none, project, descr, owner, and age 92our$default_projects_order="project"; 93 94# show repository only if this file exists 95# (only effective if this variable evaluates to true) 96our$export_ok="++GITWEB_EXPORT_OK++"; 97 98# show repository only if this subroutine returns true 99# when given the path to the project, for example: 100# sub { return -e "$_[0]/git-daemon-export-ok"; } 101our$export_auth_hook=undef; 102 103# only allow viewing of repositories also shown on the overview page 104our$strict_export="++GITWEB_STRICT_EXPORT++"; 105 106# list of git base URLs used for URL to where fetch project from, 107# i.e. full URL is "$git_base_url/$project" 108our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 109 110# default blob_plain mimetype and default charset for text/plain blob 111our$default_blob_plain_mimetype='text/plain'; 112our$default_text_plain_charset=undef; 113 114# file to use for guessing MIME types before trying /etc/mime.types 115# (relative to the current git repository) 116our$mimetypes_file=undef; 117 118# assume this charset if line contains non-UTF-8 characters; 119# it should be valid encoding (see Encoding::Supported(3pm) for list), 120# for which encoding all byte sequences are valid, for example 121# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 122# could be even 'utf-8' for the old behavior) 123our$fallback_encoding='latin1'; 124 125# rename detection options for git-diff and git-diff-tree 126# - default is '-M', with the cost proportional to 127# (number of removed files) * (number of new files). 128# - more costly is '-C' (which implies '-M'), with the cost proportional to 129# (number of changed files + number of removed files) * (number of new files) 130# - even more costly is '-C', '--find-copies-harder' with cost 131# (number of files in the original tree) * (number of new files) 132# - one might want to include '-B' option, e.g. '-B', '-M' 133our@diff_opts= ('-M');# taken from git_commit 134 135# information about snapshot formats that gitweb is capable of serving 136our%known_snapshot_formats= ( 137# name => { 138# 'display' => display name, 139# 'type' => mime type, 140# 'suffix' => filename suffix, 141# 'format' => --format for git-archive, 142# 'compressor' => [compressor command and arguments] 143# (array reference, optional)} 144# 145'tgz'=> { 146'display'=>'tar.gz', 147'type'=>'application/x-gzip', 148'suffix'=>'.tar.gz', 149'format'=>'tar', 150'compressor'=> ['gzip']}, 151 152'tbz2'=> { 153'display'=>'tar.bz2', 154'type'=>'application/x-bzip2', 155'suffix'=>'.tar.bz2', 156'format'=>'tar', 157'compressor'=> ['bzip2']}, 158 159'zip'=> { 160'display'=>'zip', 161'type'=>'application/x-zip', 162'suffix'=>'.zip', 163'format'=>'zip'}, 164); 165 166# Aliases so we understand old gitweb.snapshot values in repository 167# configuration. 168our%known_snapshot_format_aliases= ( 169'gzip'=>'tgz', 170'bzip2'=>'tbz2', 171 172# backward compatibility: legacy gitweb config support 173'x-gzip'=>undef,'gz'=>undef, 174'x-bzip2'=>undef,'bz2'=>undef, 175'x-zip'=>undef,''=>undef, 176); 177 178# You define site-wide feature defaults here; override them with 179# $GITWEB_CONFIG as necessary. 180our%feature= ( 181# feature => { 182# 'sub' => feature-sub (subroutine), 183# 'override' => allow-override (boolean), 184# 'default' => [ default options...] (array reference)} 185# 186# if feature is overridable (it means that allow-override has true value), 187# then feature-sub will be called with default options as parameters; 188# return value of feature-sub indicates if to enable specified feature 189# 190# if there is no 'sub' key (no feature-sub), then feature cannot be 191# overriden 192# 193# use gitweb_get_feature(<feature>) to retrieve the <feature> value 194# (an array) or gitweb_check_feature(<feature>) to check if <feature> 195# is enabled 196 197# Enable the 'blame' blob view, showing the last commit that modified 198# each line in the file. This can be very CPU-intensive. 199 200# To enable system wide have in $GITWEB_CONFIG 201# $feature{'blame'}{'default'} = [1]; 202# To have project specific config enable override in $GITWEB_CONFIG 203# $feature{'blame'}{'override'} = 1; 204# and in project config gitweb.blame = 0|1; 205'blame'=> { 206'sub'=> \&feature_blame, 207'override'=>0, 208'default'=> [0]}, 209 210# Enable the 'snapshot' link, providing a compressed archive of any 211# tree. This can potentially generate high traffic if you have large 212# project. 213 214# Value is a list of formats defined in %known_snapshot_formats that 215# you wish to offer. 216# To disable system wide have in $GITWEB_CONFIG 217# $feature{'snapshot'}{'default'} = []; 218# To have project specific config enable override in $GITWEB_CONFIG 219# $feature{'snapshot'}{'override'} = 1; 220# and in project config, a comma-separated list of formats or "none" 221# to disable. Example: gitweb.snapshot = tbz2,zip; 222'snapshot'=> { 223'sub'=> \&feature_snapshot, 224'override'=>0, 225'default'=> ['tgz']}, 226 227# Enable text search, which will list the commits which match author, 228# committer or commit text to a given string. Enabled by default. 229# Project specific override is not supported. 230'search'=> { 231'override'=>0, 232'default'=> [1]}, 233 234# Enable grep search, which will list the files in currently selected 235# tree containing the given string. Enabled by default. This can be 236# potentially CPU-intensive, of course. 237 238# To enable system wide have in $GITWEB_CONFIG 239# $feature{'grep'}{'default'} = [1]; 240# To have project specific config enable override in $GITWEB_CONFIG 241# $feature{'grep'}{'override'} = 1; 242# and in project config gitweb.grep = 0|1; 243'grep'=> { 244'sub'=> \&feature_grep, 245'override'=>0, 246'default'=> [1]}, 247 248# Enable the pickaxe search, which will list the commits that modified 249# a given string in a file. This can be practical and quite faster 250# alternative to 'blame', but still potentially CPU-intensive. 251 252# To enable system wide have in $GITWEB_CONFIG 253# $feature{'pickaxe'}{'default'} = [1]; 254# To have project specific config enable override in $GITWEB_CONFIG 255# $feature{'pickaxe'}{'override'} = 1; 256# and in project config gitweb.pickaxe = 0|1; 257'pickaxe'=> { 258'sub'=> \&feature_pickaxe, 259'override'=>0, 260'default'=> [1]}, 261 262# Make gitweb use an alternative format of the URLs which can be 263# more readable and natural-looking: project name is embedded 264# directly in the path and the query string contains other 265# auxiliary information. All gitweb installations recognize 266# URL in either format; this configures in which formats gitweb 267# generates links. 268 269# To enable system wide have in $GITWEB_CONFIG 270# $feature{'pathinfo'}{'default'} = [1]; 271# Project specific override is not supported. 272 273# Note that you will need to change the default location of CSS, 274# favicon, logo and possibly other files to an absolute URL. Also, 275# if gitweb.cgi serves as your indexfile, you will need to force 276# $my_uri to contain the script name in your $GITWEB_CONFIG. 277'pathinfo'=> { 278'override'=>0, 279'default'=> [0]}, 280 281# Make gitweb consider projects in project root subdirectories 282# to be forks of existing projects. Given project $projname.git, 283# projects matching $projname/*.git will not be shown in the main 284# projects list, instead a '+' mark will be added to $projname 285# there and a 'forks' view will be enabled for the project, listing 286# all the forks. If project list is taken from a file, forks have 287# to be listed after the main project. 288 289# To enable system wide have in $GITWEB_CONFIG 290# $feature{'forks'}{'default'} = [1]; 291# Project specific override is not supported. 292'forks'=> { 293'override'=>0, 294'default'=> [0]}, 295 296# Insert custom links to the action bar of all project pages. 297# This enables you mainly to link to third-party scripts integrating 298# into gitweb; e.g. git-browser for graphical history representation 299# or custom web-based repository administration interface. 300 301# The 'default' value consists of a list of triplets in the form 302# (label, link, position) where position is the label after which 303# to insert the link and link is a format string where %n expands 304# to the project name, %f to the project path within the filesystem, 305# %h to the current hash (h gitweb parameter) and %b to the current 306# hash base (hb gitweb parameter); %% expands to %. 307 308# To enable system wide have in $GITWEB_CONFIG e.g. 309# $feature{'actions'}{'default'} = [('graphiclog', 310# '/git-browser/by-commit.html?r=%n', 'summary')]; 311# Project specific override is not supported. 312'actions'=> { 313'override'=>0, 314'default'=> []}, 315 316# Allow gitweb scan project content tags described in ctags/ 317# of project repository, and display the popular Web 2.0-ish 318# "tag cloud" near the project list. Note that this is something 319# COMPLETELY different from the normal Git tags. 320 321# gitweb by itself can show existing tags, but it does not handle 322# tagging itself; you need an external application for that. 323# For an example script, check Girocco's cgi/tagproj.cgi. 324# You may want to install the HTML::TagCloud Perl module to get 325# a pretty tag cloud instead of just a list of tags. 326 327# To enable system wide have in $GITWEB_CONFIG 328# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 329# Project specific override is not supported. 330'ctags'=> { 331'override'=>0, 332'default'=> [0]}, 333); 334 335sub gitweb_get_feature { 336my($name) =@_; 337return unlessexists$feature{$name}; 338my($sub,$override,@defaults) = ( 339$feature{$name}{'sub'}, 340$feature{$name}{'override'}, 341@{$feature{$name}{'default'}}); 342if(!$override) {return@defaults; } 343if(!defined$sub) { 344warn"feature$nameis not overrideable"; 345return@defaults; 346} 347return$sub->(@defaults); 348} 349 350# A wrapper to check if a given feature is enabled. 351# With this, you can say 352# 353# my $bool_feat = gitweb_check_feature('bool_feat'); 354# gitweb_check_feature('bool_feat') or somecode; 355# 356# instead of 357# 358# my ($bool_feat) = gitweb_get_feature('bool_feat'); 359# (gitweb_get_feature('bool_feat'))[0] or somecode; 360# 361sub gitweb_check_feature { 362return(gitweb_get_feature(@_))[0]; 363} 364 365 366sub feature_blame { 367my($val) = git_get_project_config('blame','--bool'); 368 369if($valeq'true') { 370return1; 371}elsif($valeq'false') { 372return0; 373} 374 375return$_[0]; 376} 377 378sub feature_snapshot { 379my(@fmts) =@_; 380 381my($val) = git_get_project_config('snapshot'); 382 383if($val) { 384@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 385} 386 387return@fmts; 388} 389 390sub feature_grep { 391my($val) = git_get_project_config('grep','--bool'); 392 393if($valeq'true') { 394return(1); 395}elsif($valeq'false') { 396return(0); 397} 398 399return($_[0]); 400} 401 402sub feature_pickaxe { 403my($val) = git_get_project_config('pickaxe','--bool'); 404 405if($valeq'true') { 406return(1); 407}elsif($valeq'false') { 408return(0); 409} 410 411return($_[0]); 412} 413 414# checking HEAD file with -e is fragile if the repository was 415# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 416# and then pruned. 417sub check_head_link { 418my($dir) =@_; 419my$headfile="$dir/HEAD"; 420return((-e $headfile) || 421(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 422} 423 424sub check_export_ok { 425my($dir) =@_; 426return(check_head_link($dir) && 427(!$export_ok|| -e "$dir/$export_ok") && 428(!$export_auth_hook||$export_auth_hook->($dir))); 429} 430 431# process alternate names for backward compatibility 432# filter out unsupported (unknown) snapshot formats 433sub filter_snapshot_fmts { 434my@fmts=@_; 435 436@fmts=map{ 437exists$known_snapshot_format_aliases{$_} ? 438$known_snapshot_format_aliases{$_} :$_}@fmts; 439@fmts=grep(exists$known_snapshot_formats{$_},@fmts); 440 441} 442 443our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 444if(-e $GITWEB_CONFIG) { 445do$GITWEB_CONFIG; 446}else{ 447our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 448do$GITWEB_CONFIG_SYSTEMif-e $GITWEB_CONFIG_SYSTEM; 449} 450 451# version of the core git binary 452our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 453 454$projects_list||=$projectroot; 455 456# ====================================================================== 457# input validation and dispatch 458 459# input parameters can be collected from a variety of sources (presently, CGI 460# and PATH_INFO), so we define an %input_params hash that collects them all 461# together during validation: this allows subsequent uses (e.g. href()) to be 462# agnostic of the parameter origin 463 464our%input_params= (); 465 466# input parameters are stored with the long parameter name as key. This will 467# also be used in the href subroutine to convert parameters to their CGI 468# equivalent, and since the href() usage is the most frequent one, we store 469# the name -> CGI key mapping here, instead of the reverse. 470# 471# XXX: Warning: If you touch this, check the search form for updating, 472# too. 473 474our@cgi_param_mapping= ( 475 project =>"p", 476 action =>"a", 477 file_name =>"f", 478 file_parent =>"fp", 479 hash =>"h", 480 hash_parent =>"hp", 481 hash_base =>"hb", 482 hash_parent_base =>"hpb", 483 page =>"pg", 484 order =>"o", 485 searchtext =>"s", 486 searchtype =>"st", 487 snapshot_format =>"sf", 488 extra_options =>"opt", 489 search_use_regexp =>"sr", 490); 491our%cgi_param_mapping=@cgi_param_mapping; 492 493# we will also need to know the possible actions, for validation 494our%actions= ( 495"blame"=> \&git_blame, 496"blobdiff"=> \&git_blobdiff, 497"blobdiff_plain"=> \&git_blobdiff_plain, 498"blob"=> \&git_blob, 499"blob_plain"=> \&git_blob_plain, 500"commitdiff"=> \&git_commitdiff, 501"commitdiff_plain"=> \&git_commitdiff_plain, 502"commit"=> \&git_commit, 503"forks"=> \&git_forks, 504"heads"=> \&git_heads, 505"history"=> \&git_history, 506"log"=> \&git_log, 507"rss"=> \&git_rss, 508"atom"=> \&git_atom, 509"search"=> \&git_search, 510"search_help"=> \&git_search_help, 511"shortlog"=> \&git_shortlog, 512"summary"=> \&git_summary, 513"tag"=> \&git_tag, 514"tags"=> \&git_tags, 515"tree"=> \&git_tree, 516"snapshot"=> \&git_snapshot, 517"object"=> \&git_object, 518# those below don't need $project 519"opml"=> \&git_opml, 520"project_list"=> \&git_project_list, 521"project_index"=> \&git_project_index, 522); 523 524# finally, we have the hash of allowed extra_options for the commands that 525# allow them 526our%allowed_options= ( 527"--no-merges"=> [qw(rss atom log shortlog history)], 528); 529 530# fill %input_params with the CGI parameters. All values except for 'opt' 531# should be single values, but opt can be an array. We should probably 532# build an array of parameters that can be multi-valued, but since for the time 533# being it's only this one, we just single it out 534while(my($name,$symbol) =each%cgi_param_mapping) { 535if($symboleq'opt') { 536$input_params{$name} = [$cgi->param($symbol) ]; 537}else{ 538$input_params{$name} =$cgi->param($symbol); 539} 540} 541 542# now read PATH_INFO and update the parameter list for missing parameters 543sub evaluate_path_info { 544return ifdefined$input_params{'project'}; 545return if!$path_info; 546$path_info=~ s,^/+,,; 547return if!$path_info; 548 549# find which part of PATH_INFO is project 550my$project=$path_info; 551$project=~ s,/+$,,; 552while($project&& !check_head_link("$projectroot/$project")) { 553$project=~ s,/*[^/]*$,,; 554} 555return unless$project; 556$input_params{'project'} =$project; 557 558# do not change any parameters if an action is given using the query string 559return if$input_params{'action'}; 560$path_info=~ s,^\Q$project\E/*,,; 561 562# next, check if we have an action 563my$action=$path_info; 564$action=~ s,/.*$,,; 565if(exists$actions{$action}) { 566$path_info=~ s,^$action/*,,; 567$input_params{'action'} =$action; 568} 569 570# list of actions that want hash_base instead of hash, but can have no 571# pathname (f) parameter 572my@wants_base= ( 573'tree', 574'history', 575); 576 577# we want to catch 578# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 579my($parentrefname,$parentpathname,$refname,$pathname) = 580($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/); 581 582# first, analyze the 'current' part 583if(defined$pathname) { 584# we got "branch:filename" or "branch:dir/" 585# we could use git_get_type(branch:pathname), but: 586# - it needs $git_dir 587# - it does a git() call 588# - the convention of terminating directories with a slash 589# makes it superfluous 590# - embedding the action in the PATH_INFO would make it even 591# more superfluous 592$pathname=~ s,^/+,,; 593if(!$pathname||substr($pathname, -1)eq"/") { 594$input_params{'action'} ||="tree"; 595$pathname=~ s,/$,,; 596}else{ 597# the default action depends on whether we had parent info 598# or not 599if($parentrefname) { 600$input_params{'action'} ||="blobdiff_plain"; 601}else{ 602$input_params{'action'} ||="blob_plain"; 603} 604} 605$input_params{'hash_base'} ||=$refname; 606$input_params{'file_name'} ||=$pathname; 607}elsif(defined$refname) { 608# we got "branch". In this case we have to choose if we have to 609# set hash or hash_base. 610# 611# Most of the actions without a pathname only want hash to be 612# set, except for the ones specified in @wants_base that want 613# hash_base instead. It should also be noted that hand-crafted 614# links having 'history' as an action and no pathname or hash 615# set will fail, but that happens regardless of PATH_INFO. 616$input_params{'action'} ||="shortlog"; 617if(grep{$_eq$input_params{'action'} }@wants_base) { 618$input_params{'hash_base'} ||=$refname; 619}else{ 620$input_params{'hash'} ||=$refname; 621} 622} 623 624# next, handle the 'parent' part, if present 625if(defined$parentrefname) { 626# a missing pathspec defaults to the 'current' filename, allowing e.g. 627# someproject/blobdiff/oldrev..newrev:/filename 628if($parentpathname) { 629$parentpathname=~ s,^/+,,; 630$parentpathname=~ s,/$,,; 631$input_params{'file_parent'} ||=$parentpathname; 632}else{ 633$input_params{'file_parent'} ||=$input_params{'file_name'}; 634} 635# we assume that hash_parent_base is wanted if a path was specified, 636# or if the action wants hash_base instead of hash 637if(defined$input_params{'file_parent'} || 638grep{$_eq$input_params{'action'} }@wants_base) { 639$input_params{'hash_parent_base'} ||=$parentrefname; 640}else{ 641$input_params{'hash_parent'} ||=$parentrefname; 642} 643} 644 645# for the snapshot action, we allow URLs in the form 646# $project/snapshot/$hash.ext 647# where .ext determines the snapshot and gets removed from the 648# passed $refname to provide the $hash. 649# 650# To be able to tell that $refname includes the format extension, we 651# require the following two conditions to be satisfied: 652# - the hash input parameter MUST have been set from the $refname part 653# of the URL (i.e. they must be equal) 654# - the snapshot format MUST NOT have been defined already (e.g. from 655# CGI parameter sf) 656# It's also useless to try any matching unless $refname has a dot, 657# so we check for that too 658if(defined$input_params{'action'} && 659$input_params{'action'}eq'snapshot'&& 660defined$refname&&index($refname,'.') != -1&& 661$refnameeq$input_params{'hash'} && 662!defined$input_params{'snapshot_format'}) { 663# We loop over the known snapshot formats, checking for 664# extensions. Allowed extensions are both the defined suffix 665# (which includes the initial dot already) and the snapshot 666# format key itself, with a prepended dot 667while(my($fmt,%opt) =each%known_snapshot_formats) { 668my$hash=$refname; 669my$sfx; 670$hash=~s/(\Q$opt{'suffix'}\E|\Q.$fmt\E)$//; 671next unless$sfx=$1; 672# a valid suffix was found, so set the snapshot format 673# and reset the hash parameter 674$input_params{'snapshot_format'} =$fmt; 675$input_params{'hash'} =$hash; 676# we also set the format suffix to the one requested 677# in the URL: this way a request for e.g. .tgz returns 678# a .tgz instead of a .tar.gz 679$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 680last; 681} 682} 683} 684evaluate_path_info(); 685 686our$action=$input_params{'action'}; 687if(defined$action) { 688if(!validate_action($action)) { 689 die_error(400,"Invalid action parameter"); 690} 691} 692 693# parameters which are pathnames 694our$project=$input_params{'project'}; 695if(defined$project) { 696if(!validate_project($project)) { 697undef$project; 698 die_error(404,"No such project"); 699} 700} 701 702our$file_name=$input_params{'file_name'}; 703if(defined$file_name) { 704if(!validate_pathname($file_name)) { 705 die_error(400,"Invalid file parameter"); 706} 707} 708 709our$file_parent=$input_params{'file_parent'}; 710if(defined$file_parent) { 711if(!validate_pathname($file_parent)) { 712 die_error(400,"Invalid file parent parameter"); 713} 714} 715 716# parameters which are refnames 717our$hash=$input_params{'hash'}; 718if(defined$hash) { 719if(!validate_refname($hash)) { 720 die_error(400,"Invalid hash parameter"); 721} 722} 723 724our$hash_parent=$input_params{'hash_parent'}; 725if(defined$hash_parent) { 726if(!validate_refname($hash_parent)) { 727 die_error(400,"Invalid hash parent parameter"); 728} 729} 730 731our$hash_base=$input_params{'hash_base'}; 732if(defined$hash_base) { 733if(!validate_refname($hash_base)) { 734 die_error(400,"Invalid hash base parameter"); 735} 736} 737 738our@extra_options= @{$input_params{'extra_options'}}; 739# @extra_options is always defined, since it can only be (currently) set from 740# CGI, and $cgi->param() returns the empty array in array context if the param 741# is not set 742foreachmy$opt(@extra_options) { 743if(not exists$allowed_options{$opt}) { 744 die_error(400,"Invalid option parameter"); 745} 746if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 747 die_error(400,"Invalid option parameter for this action"); 748} 749} 750 751our$hash_parent_base=$input_params{'hash_parent_base'}; 752if(defined$hash_parent_base) { 753if(!validate_refname($hash_parent_base)) { 754 die_error(400,"Invalid hash parent base parameter"); 755} 756} 757 758# other parameters 759our$page=$input_params{'page'}; 760if(defined$page) { 761if($page=~m/[^0-9]/) { 762 die_error(400,"Invalid page parameter"); 763} 764} 765 766our$searchtype=$input_params{'searchtype'}; 767if(defined$searchtype) { 768if($searchtype=~m/[^a-z]/) { 769 die_error(400,"Invalid searchtype parameter"); 770} 771} 772 773our$search_use_regexp=$input_params{'search_use_regexp'}; 774 775our$searchtext=$input_params{'searchtext'}; 776our$search_regexp; 777if(defined$searchtext) { 778if(length($searchtext) <2) { 779 die_error(403,"At least two characters are required for search parameter"); 780} 781$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 782} 783 784# path to the current git repository 785our$git_dir; 786$git_dir="$projectroot/$project"if$project; 787 788# list of supported snapshot formats 789our@snapshot_fmts= gitweb_get_feature('snapshot'); 790@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts); 791 792# dispatch 793if(!defined$action) { 794if(defined$hash) { 795$action= git_get_type($hash); 796}elsif(defined$hash_base&&defined$file_name) { 797$action= git_get_type("$hash_base:$file_name"); 798}elsif(defined$project) { 799$action='summary'; 800}else{ 801$action='project_list'; 802} 803} 804if(!defined($actions{$action})) { 805 die_error(400,"Unknown action"); 806} 807if($action!~m/^(opml|project_list|project_index)$/&& 808!$project) { 809 die_error(400,"Project needed"); 810} 811$actions{$action}->(); 812exit; 813 814## ====================================================================== 815## action links 816 817sub href (%) { 818my%params=@_; 819# default is to use -absolute url() i.e. $my_uri 820my$href=$params{-full} ?$my_url:$my_uri; 821 822$params{'project'} =$projectunlessexists$params{'project'}; 823 824if($params{-replay}) { 825while(my($name,$symbol) =each%cgi_param_mapping) { 826if(!exists$params{$name}) { 827$params{$name} =$input_params{$name}; 828} 829} 830} 831 832my$use_pathinfo= gitweb_check_feature('pathinfo'); 833if($use_pathinfo) { 834# try to put as many parameters as possible in PATH_INFO: 835# - project name 836# - action 837# - hash_parent or hash_parent_base:/file_parent 838# - hash or hash_base:/filename 839# - the snapshot_format as an appropriate suffix 840 841# When the script is the root DirectoryIndex for the domain, 842# $href here would be something like http://gitweb.example.com/ 843# Thus, we strip any trailing / from $href, to spare us double 844# slashes in the final URL 845$href=~ s,/$,,; 846 847# Then add the project name, if present 848$href.="/".esc_url($params{'project'})ifdefined$params{'project'}; 849delete$params{'project'}; 850 851# since we destructively absorb parameters, we keep this 852# boolean that remembers if we're handling a snapshot 853my$is_snapshot=$params{'action'}eq'snapshot'; 854 855# Summary just uses the project path URL, any other action is 856# added to the URL 857if(defined$params{'action'}) { 858$href.="/".esc_url($params{'action'})unless$params{'action'}eq'summary'; 859delete$params{'action'}; 860} 861 862# Next, we put hash_parent_base:/file_parent..hash_base:/file_name, 863# stripping nonexistent or useless pieces 864$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'} 865||$params{'hash_parent'} ||$params{'hash'}); 866if(defined$params{'hash_base'}) { 867if(defined$params{'hash_parent_base'}) { 868$href.= esc_url($params{'hash_parent_base'}); 869# skip the file_parent if it's the same as the file_name 870delete$params{'file_parent'}if$params{'file_parent'}eq$params{'file_name'}; 871if(defined$params{'file_parent'} &&$params{'file_parent'} !~/\.\./) { 872$href.=":/".esc_url($params{'file_parent'}); 873delete$params{'file_parent'}; 874} 875$href.=".."; 876delete$params{'hash_parent'}; 877delete$params{'hash_parent_base'}; 878}elsif(defined$params{'hash_parent'}) { 879$href.= esc_url($params{'hash_parent'}).".."; 880delete$params{'hash_parent'}; 881} 882 883$href.= esc_url($params{'hash_base'}); 884if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) { 885$href.=":/".esc_url($params{'file_name'}); 886delete$params{'file_name'}; 887} 888delete$params{'hash'}; 889delete$params{'hash_base'}; 890}elsif(defined$params{'hash'}) { 891$href.= esc_url($params{'hash'}); 892delete$params{'hash'}; 893} 894 895# If the action was a snapshot, we can absorb the 896# snapshot_format parameter too 897if($is_snapshot) { 898my$fmt=$params{'snapshot_format'}; 899# snapshot_format should always be defined when href() 900# is called, but just in case some code forgets, we 901# fall back to the default 902$fmt||=$snapshot_fmts[0]; 903$href.=$known_snapshot_formats{$fmt}{'suffix'}; 904delete$params{'snapshot_format'}; 905} 906} 907 908# now encode the parameters explicitly 909my@result= (); 910for(my$i=0;$i<@cgi_param_mapping;$i+=2) { 911my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]); 912if(defined$params{$name}) { 913if(ref($params{$name})eq"ARRAY") { 914foreachmy$par(@{$params{$name}}) { 915push@result,$symbol."=". esc_param($par); 916} 917}else{ 918push@result,$symbol."=". esc_param($params{$name}); 919} 920} 921} 922$href.="?".join(';',@result)ifscalar@result; 923 924return$href; 925} 926 927 928## ====================================================================== 929## validation, quoting/unquoting and escaping 930 931sub validate_action { 932my$input=shift||returnundef; 933returnundefunlessexists$actions{$input}; 934return$input; 935} 936 937sub validate_project { 938my$input=shift||returnundef; 939if(!validate_pathname($input) || 940!(-d "$projectroot/$input") || 941!check_export_ok("$projectroot/$input") || 942($strict_export&& !project_in_list($input))) { 943returnundef; 944}else{ 945return$input; 946} 947} 948 949sub validate_pathname { 950my$input=shift||returnundef; 951 952# no '.' or '..' as elements of path, i.e. no '.' nor '..' 953# at the beginning, at the end, and between slashes. 954# also this catches doubled slashes 955if($input=~m!(^|/)(|\.|\.\.)(/|$)!) { 956returnundef; 957} 958# no null characters 959if($input=~m!\0!) { 960returnundef; 961} 962return$input; 963} 964 965sub validate_refname { 966my$input=shift||returnundef; 967 968# textual hashes are O.K. 969if($input=~m/^[0-9a-fA-F]{40}$/) { 970return$input; 971} 972# it must be correct pathname 973$input= validate_pathname($input) 974orreturnundef; 975# restrictions on ref name according to git-check-ref-format 976if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) { 977returnundef; 978} 979return$input; 980} 981 982# decode sequences of octets in utf8 into Perl's internal form, 983# which is utf-8 with utf8 flag set if needed. gitweb writes out 984# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning 985sub to_utf8 { 986my$str=shift; 987if(utf8::valid($str)) { 988 utf8::decode($str); 989return$str; 990}else{ 991return decode($fallback_encoding,$str, Encode::FB_DEFAULT); 992} 993} 994 995# quote unsafe chars, but keep the slash, even when it's not 996# correct, but quoted slashes look too horrible in bookmarks 997sub esc_param { 998my$str=shift; 999$str=~s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X",ord($1))/eg;1000$str=~s/\+/%2B/g;1001$str=~s/ /\+/g;1002return$str;1003}10041005# quote unsafe chars in whole URL, so some charactrs cannot be quoted1006sub esc_url {1007my$str=shift;1008$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X",ord($1))/eg;1009$str=~s/\+/%2B/g;1010$str=~s/ /\+/g;1011return$str;1012}10131014# replace invalid utf8 character with SUBSTITUTION sequence1015sub esc_html ($;%) {1016my$str=shift;1017my%opts=@_;10181019$str= to_utf8($str);1020$str=$cgi->escapeHTML($str);1021if($opts{'-nbsp'}) {1022$str=~s/ / /g;1023}1024$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1025return$str;1026}10271028# quote control characters and escape filename to HTML1029sub esc_path {1030my$str=shift;1031my%opts=@_;10321033$str= to_utf8($str);1034$str=$cgi->escapeHTML($str);1035if($opts{'-nbsp'}) {1036$str=~s/ / /g;1037}1038$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1039return$str;1040}10411042# Make control characters "printable", using character escape codes (CEC)1043sub quot_cec {1044my$cntrl=shift;1045my%opts=@_;1046my%es= (# character escape codes, aka escape sequences1047"\t"=>'\t',# tab (HT)1048"\n"=>'\n',# line feed (LF)1049"\r"=>'\r',# carrige return (CR)1050"\f"=>'\f',# form feed (FF)1051"\b"=>'\b',# backspace (BS)1052"\a"=>'\a',# alarm (bell) (BEL)1053"\e"=>'\e',# escape (ESC)1054"\013"=>'\v',# vertical tab (VT)1055"\000"=>'\0',# nul character (NUL)1056);1057my$chr= ( (exists$es{$cntrl})1058?$es{$cntrl}1059:sprintf('\%2x',ord($cntrl)) );1060if($opts{-nohtml}) {1061return$chr;1062}else{1063return"<span class=\"cntrl\">$chr</span>";1064}1065}10661067# Alternatively use unicode control pictures codepoints,1068# Unicode "printable representation" (PR)1069sub quot_upr {1070my$cntrl=shift;1071my%opts=@_;10721073my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1074if($opts{-nohtml}) {1075return$chr;1076}else{1077return"<span class=\"cntrl\">$chr</span>";1078}1079}10801081# git may return quoted and escaped filenames1082sub unquote {1083my$str=shift;10841085sub unq {1086my$seq=shift;1087my%es= (# character escape codes, aka escape sequences1088't'=>"\t",# tab (HT, TAB)1089'n'=>"\n",# newline (NL)1090'r'=>"\r",# return (CR)1091'f'=>"\f",# form feed (FF)1092'b'=>"\b",# backspace (BS)1093'a'=>"\a",# alarm (bell) (BEL)1094'e'=>"\e",# escape (ESC)1095'v'=>"\013",# vertical tab (VT)1096);10971098if($seq=~m/^[0-7]{1,3}$/) {1099# octal char sequence1100returnchr(oct($seq));1101}elsif(exists$es{$seq}) {1102# C escape sequence, aka character escape code1103return$es{$seq};1104}1105# quoted ordinary character1106return$seq;1107}11081109if($str=~m/^"(.*)"$/) {1110# needs unquoting1111$str=$1;1112$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1113}1114return$str;1115}11161117# escape tabs (convert tabs to spaces)1118sub untabify {1119my$line=shift;11201121while((my$pos=index($line,"\t")) != -1) {1122if(my$count= (8- ($pos%8))) {1123my$spaces=' ' x $count;1124$line=~s/\t/$spaces/;1125}1126}11271128return$line;1129}11301131sub project_in_list {1132my$project=shift;1133my@list= git_get_projects_list();1134return@list&&scalar(grep{$_->{'path'}eq$project}@list);1135}11361137## ----------------------------------------------------------------------1138## HTML aware string manipulation11391140# Try to chop given string on a word boundary between position1141# $len and $len+$add_len. If there is no word boundary there,1142# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1143# (marking chopped part) would be longer than given string.1144sub chop_str {1145my$str=shift;1146my$len=shift;1147my$add_len=shift||10;1148my$where=shift||'right';# 'left' | 'center' | 'right'11491150# Make sure perl knows it is utf8 encoded so we don't1151# cut in the middle of a utf8 multibyte char.1152$str= to_utf8($str);11531154# allow only $len chars, but don't cut a word if it would fit in $add_len1155# if it doesn't fit, cut it if it's still longer than the dots we would add1156# remove chopped character entities entirely11571158# when chopping in the middle, distribute $len into left and right part1159# return early if chopping wouldn't make string shorter1160if($whereeq'center') {1161return$strif($len+5>=length($str));# filler is length 51162$len=int($len/2);1163}else{1164return$strif($len+4>=length($str));# filler is length 41165}11661167# regexps: ending and beginning with word part up to $add_len1168my$endre=qr/.{$len}\w{0,$add_len}/;1169my$begre=qr/\w{0,$add_len}.{$len}/;11701171if($whereeq'left') {1172$str=~m/^(.*?)($begre)$/;1173my($lead,$body) = ($1,$2);1174if(length($lead) >4) {1175$body=~s/^[^;]*;//if($lead=~m/&[^;]*$/);1176$lead=" ...";1177}1178return"$lead$body";11791180}elsif($whereeq'center') {1181$str=~m/^($endre)(.*)$/;1182my($left,$str) = ($1,$2);1183$str=~m/^(.*?)($begre)$/;1184my($mid,$right) = ($1,$2);1185if(length($mid) >5) {1186$left=~s/&[^;]*$//;1187$right=~s/^[^;]*;//if($mid=~m/&[^;]*$/);1188$mid=" ... ";1189}1190return"$left$mid$right";11911192}else{1193$str=~m/^($endre)(.*)$/;1194my$body=$1;1195my$tail=$2;1196if(length($tail) >4) {1197$body=~s/&[^;]*$//;1198$tail="... ";1199}1200return"$body$tail";1201}1202}12031204# takes the same arguments as chop_str, but also wraps a <span> around the1205# result with a title attribute if it does get chopped. Additionally, the1206# string is HTML-escaped.1207sub chop_and_escape_str {1208my($str) =@_;12091210my$chopped= chop_str(@_);1211if($choppedeq$str) {1212return esc_html($chopped);1213}else{1214$str=~s/([[:cntrl:]])/?/g;1215return$cgi->span({-title=>$str}, esc_html($chopped));1216}1217}12181219## ----------------------------------------------------------------------1220## functions returning short strings12211222# CSS class for given age value (in seconds)1223sub age_class {1224my$age=shift;12251226if(!defined$age) {1227return"noage";1228}elsif($age<60*60*2) {1229return"age0";1230}elsif($age<60*60*24*2) {1231return"age1";1232}else{1233return"age2";1234}1235}12361237# convert age in seconds to "nn units ago" string1238sub age_string {1239my$age=shift;1240my$age_str;12411242if($age>60*60*24*365*2) {1243$age_str= (int$age/60/60/24/365);1244$age_str.=" years ago";1245}elsif($age>60*60*24*(365/12)*2) {1246$age_str=int$age/60/60/24/(365/12);1247$age_str.=" months ago";1248}elsif($age>60*60*24*7*2) {1249$age_str=int$age/60/60/24/7;1250$age_str.=" weeks ago";1251}elsif($age>60*60*24*2) {1252$age_str=int$age/60/60/24;1253$age_str.=" days ago";1254}elsif($age>60*60*2) {1255$age_str=int$age/60/60;1256$age_str.=" hours ago";1257}elsif($age>60*2) {1258$age_str=int$age/60;1259$age_str.=" min ago";1260}elsif($age>2) {1261$age_str=int$age;1262$age_str.=" sec ago";1263}else{1264$age_str.=" right now";1265}1266return$age_str;1267}12681269useconstant{1270 S_IFINVALID =>0030000,1271 S_IFGITLINK =>0160000,1272};12731274# submodule/subproject, a commit object reference1275sub S_ISGITLINK($) {1276my$mode=shift;12771278return(($mode& S_IFMT) == S_IFGITLINK)1279}12801281# convert file mode in octal to symbolic file mode string1282sub mode_str {1283my$mode=oct shift;12841285if(S_ISGITLINK($mode)) {1286return'm---------';1287}elsif(S_ISDIR($mode& S_IFMT)) {1288return'drwxr-xr-x';1289}elsif(S_ISLNK($mode)) {1290return'lrwxrwxrwx';1291}elsif(S_ISREG($mode)) {1292# git cares only about the executable bit1293if($mode& S_IXUSR) {1294return'-rwxr-xr-x';1295}else{1296return'-rw-r--r--';1297};1298}else{1299return'----------';1300}1301}13021303# convert file mode in octal to file type string1304sub file_type {1305my$mode=shift;13061307if($mode!~m/^[0-7]+$/) {1308return$mode;1309}else{1310$mode=oct$mode;1311}13121313if(S_ISGITLINK($mode)) {1314return"submodule";1315}elsif(S_ISDIR($mode& S_IFMT)) {1316return"directory";1317}elsif(S_ISLNK($mode)) {1318return"symlink";1319}elsif(S_ISREG($mode)) {1320return"file";1321}else{1322return"unknown";1323}1324}13251326# convert file mode in octal to file type description string1327sub file_type_long {1328my$mode=shift;13291330if($mode!~m/^[0-7]+$/) {1331return$mode;1332}else{1333$mode=oct$mode;1334}13351336if(S_ISGITLINK($mode)) {1337return"submodule";1338}elsif(S_ISDIR($mode& S_IFMT)) {1339return"directory";1340}elsif(S_ISLNK($mode)) {1341return"symlink";1342}elsif(S_ISREG($mode)) {1343if($mode& S_IXUSR) {1344return"executable";1345}else{1346return"file";1347};1348}else{1349return"unknown";1350}1351}135213531354## ----------------------------------------------------------------------1355## functions returning short HTML fragments, or transforming HTML fragments1356## which don't belong to other sections13571358# format line of commit message.1359sub format_log_line_html {1360my$line=shift;13611362$line= esc_html($line, -nbsp=>1);1363if($line=~m/([0-9a-fA-F]{8,40})/) {1364my$hash_text=$1;1365my$link=1366$cgi->a({-href => href(action=>"object", hash=>$hash_text),1367-class=>"text"},$hash_text);1368$line=~s/$hash_text/$link/;1369}1370return$line;1371}13721373# format marker of refs pointing to given object13741375# the destination action is chosen based on object type and current context:1376# - for annotated tags, we choose the tag view unless it's the current view1377# already, in which case we go to shortlog view1378# - for other refs, we keep the current view if we're in history, shortlog or1379# log view, and select shortlog otherwise1380sub format_ref_marker {1381my($refs,$id) =@_;1382my$markers='';13831384if(defined$refs->{$id}) {1385foreachmy$ref(@{$refs->{$id}}) {1386# this code exploits the fact that non-lightweight tags are the1387# only indirect objects, and that they are the only objects for which1388# we want to use tag instead of shortlog as action1389my($type,$name) =qw();1390my$indirect= ($ref=~s/\^\{\}$//);1391# e.g. tags/v2.6.11 or heads/next1392if($ref=~m!^(.*?)s?/(.*)$!) {1393$type=$1;1394$name=$2;1395}else{1396$type="ref";1397$name=$ref;1398}13991400my$class=$type;1401$class.=" indirect"if$indirect;14021403my$dest_action="shortlog";14041405if($indirect) {1406$dest_action="tag"unless$actioneq"tag";1407}elsif($action=~/^(history|(short)?log)$/) {1408$dest_action=$action;1409}14101411my$dest="";1412$dest.="refs/"unless$ref=~ m!^refs/!;1413$dest.=$ref;14141415my$link=$cgi->a({1416-href => href(1417 action=>$dest_action,1418 hash=>$dest1419)},$name);14201421$markers.=" <span class=\"$class\"title=\"$ref\">".1422$link."</span>";1423}1424}14251426if($markers) {1427return' <span class="refs">'.$markers.'</span>';1428}else{1429return"";1430}1431}14321433# format, perhaps shortened and with markers, title line1434sub format_subject_html {1435my($long,$short,$href,$extra) =@_;1436$extra=''unlessdefined($extra);14371438if(length($short) <length($long)) {1439return$cgi->a({-href =>$href, -class=>"list subject",1440-title => to_utf8($long)},1441 esc_html($short) .$extra);1442}else{1443return$cgi->a({-href =>$href, -class=>"list subject"},1444 esc_html($long) .$extra);1445}1446}14471448# format git diff header line, i.e. "diff --(git|combined|cc) ..."1449sub format_git_diff_header_line {1450my$line=shift;1451my$diffinfo=shift;1452my($from,$to) =@_;14531454if($diffinfo->{'nparents'}) {1455# combined diff1456$line=~s!^(diff (.*?) )"?.*$!$1!;1457if($to->{'href'}) {1458$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1459 esc_path($to->{'file'}));1460}else{# file was deleted (no href)1461$line.= esc_path($to->{'file'});1462}1463}else{1464# "ordinary" diff1465$line=~s!^(diff (.*?) )"?a/.*$!$1!;1466if($from->{'href'}) {1467$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1468'a/'. esc_path($from->{'file'}));1469}else{# file was added (no href)1470$line.='a/'. esc_path($from->{'file'});1471}1472$line.=' ';1473if($to->{'href'}) {1474$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1475'b/'. esc_path($to->{'file'}));1476}else{# file was deleted1477$line.='b/'. esc_path($to->{'file'});1478}1479}14801481return"<div class=\"diff header\">$line</div>\n";1482}14831484# format extended diff header line, before patch itself1485sub format_extended_diff_header_line {1486my$line=shift;1487my$diffinfo=shift;1488my($from,$to) =@_;14891490# match <path>1491if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1492$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1493 esc_path($from->{'file'}));1494}1495if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1496$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1497 esc_path($to->{'file'}));1498}1499# match single <mode>1500if($line=~m/\s(\d{6})$/) {1501$line.='<span class="info"> ('.1502 file_type_long($1) .1503')</span>';1504}1505# match <hash>1506if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1507# can match only for combined diff1508$line='index ';1509for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1510if($from->{'href'}[$i]) {1511$line.=$cgi->a({-href=>$from->{'href'}[$i],1512-class=>"hash"},1513substr($diffinfo->{'from_id'}[$i],0,7));1514}else{1515$line.='0' x 7;1516}1517# separator1518$line.=','if($i<$diffinfo->{'nparents'} -1);1519}1520$line.='..';1521if($to->{'href'}) {1522$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1523substr($diffinfo->{'to_id'},0,7));1524}else{1525$line.='0' x 7;1526}15271528}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1529# can match only for ordinary diff1530my($from_link,$to_link);1531if($from->{'href'}) {1532$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1533substr($diffinfo->{'from_id'},0,7));1534}else{1535$from_link='0' x 7;1536}1537if($to->{'href'}) {1538$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1539substr($diffinfo->{'to_id'},0,7));1540}else{1541$to_link='0' x 7;1542}1543my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1544$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1545}15461547return$line."<br/>\n";1548}15491550# format from-file/to-file diff header1551sub format_diff_from_to_header {1552my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1553my$line;1554my$result='';15551556$line=$from_line;1557#assert($line =~ m/^---/) if DEBUG;1558# no extra formatting for "^--- /dev/null"1559if(!$diffinfo->{'nparents'}) {1560# ordinary (single parent) diff1561if($line=~m!^--- "?a/!) {1562if($from->{'href'}) {1563$line='--- a/'.1564$cgi->a({-href=>$from->{'href'}, -class=>"path"},1565 esc_path($from->{'file'}));1566}else{1567$line='--- a/'.1568 esc_path($from->{'file'});1569}1570}1571$result.= qq!<div class="diff from_file">$line</div>\n!;15721573}else{1574# combined diff (merge commit)1575for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1576if($from->{'href'}[$i]) {1577$line='--- '.1578$cgi->a({-href=>href(action=>"blobdiff",1579 hash_parent=>$diffinfo->{'from_id'}[$i],1580 hash_parent_base=>$parents[$i],1581 file_parent=>$from->{'file'}[$i],1582 hash=>$diffinfo->{'to_id'},1583 hash_base=>$hash,1584 file_name=>$to->{'file'}),1585-class=>"path",1586-title=>"diff". ($i+1)},1587$i+1) .1588'/'.1589$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1590 esc_path($from->{'file'}[$i]));1591}else{1592$line='--- /dev/null';1593}1594$result.= qq!<div class="diff from_file">$line</div>\n!;1595}1596}15971598$line=$to_line;1599#assert($line =~ m/^\+\+\+/) if DEBUG;1600# no extra formatting for "^+++ /dev/null"1601if($line=~m!^\+\+\+ "?b/!) {1602if($to->{'href'}) {1603$line='+++ b/'.1604$cgi->a({-href=>$to->{'href'}, -class=>"path"},1605 esc_path($to->{'file'}));1606}else{1607$line='+++ b/'.1608 esc_path($to->{'file'});1609}1610}1611$result.= qq!<div class="diff to_file">$line</div>\n!;16121613return$result;1614}16151616# create note for patch simplified by combined diff1617sub format_diff_cc_simplified {1618my($diffinfo,@parents) =@_;1619my$result='';16201621$result.="<div class=\"diff header\">".1622"diff --cc ";1623if(!is_deleted($diffinfo)) {1624$result.=$cgi->a({-href => href(action=>"blob",1625 hash_base=>$hash,1626 hash=>$diffinfo->{'to_id'},1627 file_name=>$diffinfo->{'to_file'}),1628-class=>"path"},1629 esc_path($diffinfo->{'to_file'}));1630}else{1631$result.= esc_path($diffinfo->{'to_file'});1632}1633$result.="</div>\n".# class="diff header"1634"<div class=\"diff nodifferences\">".1635"Simple merge".1636"</div>\n";# class="diff nodifferences"16371638return$result;1639}16401641# format patch (diff) line (not to be used for diff headers)1642sub format_diff_line {1643my$line=shift;1644my($from,$to) =@_;1645my$diff_class="";16461647chomp$line;16481649if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1650# combined diff1651my$prefix=substr($line,0,scalar@{$from->{'href'}});1652if($line=~m/^\@{3}/) {1653$diff_class=" chunk_header";1654}elsif($line=~m/^\\/) {1655$diff_class=" incomplete";1656}elsif($prefix=~tr/+/+/) {1657$diff_class=" add";1658}elsif($prefix=~tr/-/-/) {1659$diff_class=" rem";1660}1661}else{1662# assume ordinary diff1663my$char=substr($line,0,1);1664if($chareq'+') {1665$diff_class=" add";1666}elsif($chareq'-') {1667$diff_class=" rem";1668}elsif($chareq'@') {1669$diff_class=" chunk_header";1670}elsif($chareq"\\") {1671$diff_class=" incomplete";1672}1673}1674$line= untabify($line);1675if($from&&$to&&$line=~m/^\@{2} /) {1676my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1677$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;16781679$from_lines=0unlessdefined$from_lines;1680$to_lines=0unlessdefined$to_lines;16811682if($from->{'href'}) {1683$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1684-class=>"list"},$from_text);1685}1686if($to->{'href'}) {1687$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1688-class=>"list"},$to_text);1689}1690$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1691"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1692return"<div class=\"diff$diff_class\">$line</div>\n";1693}elsif($from&&$to&&$line=~m/^\@{3}/) {1694my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1695my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);16961697@from_text=split(' ',$ranges);1698for(my$i=0;$i<@from_text; ++$i) {1699($from_start[$i],$from_nlines[$i]) =1700(split(',',substr($from_text[$i],1)),0);1701}17021703$to_text=pop@from_text;1704$to_start=pop@from_start;1705$to_nlines=pop@from_nlines;17061707$line="<span class=\"chunk_info\">$prefix";1708for(my$i=0;$i<@from_text; ++$i) {1709if($from->{'href'}[$i]) {1710$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1711-class=>"list"},$from_text[$i]);1712}else{1713$line.=$from_text[$i];1714}1715$line.=" ";1716}1717if($to->{'href'}) {1718$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1719-class=>"list"},$to_text);1720}else{1721$line.=$to_text;1722}1723$line.="$prefix</span>".1724"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1725return"<div class=\"diff$diff_class\">$line</div>\n";1726}1727return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1728}17291730# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1731# linked. Pass the hash of the tree/commit to snapshot.1732sub format_snapshot_links {1733my($hash) =@_;1734my$num_fmts=@snapshot_fmts;1735if($num_fmts>1) {1736# A parenthesized list of links bearing format names.1737# e.g. "snapshot (_tar.gz_ _zip_)"1738return"snapshot (".join(' ',map1739$cgi->a({1740-href => href(1741 action=>"snapshot",1742 hash=>$hash,1743 snapshot_format=>$_1744)1745},$known_snapshot_formats{$_}{'display'})1746,@snapshot_fmts) .")";1747}elsif($num_fmts==1) {1748# A single "snapshot" link whose tooltip bears the format name.1749# i.e. "_snapshot_"1750my($fmt) =@snapshot_fmts;1751return1752$cgi->a({1753-href => href(1754 action=>"snapshot",1755 hash=>$hash,1756 snapshot_format=>$fmt1757),1758-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"1759},"snapshot");1760}else{# $num_fmts == 01761returnundef;1762}1763}17641765## ......................................................................1766## functions returning values to be passed, perhaps after some1767## transformation, to other functions; e.g. returning arguments to href()17681769# returns hash to be passed to href to generate gitweb URL1770# in -title key it returns description of link1771sub get_feed_info {1772my$format=shift||'Atom';1773my%res= (action =>lc($format));17741775# feed links are possible only for project views1776return unless(defined$project);1777# some views should link to OPML, or to generic project feed,1778# or don't have specific feed yet (so they should use generic)1779return if($action=~/^(?:tags|heads|forks|tag|search)$/x);17801781my$branch;1782# branches refs uses 'refs/heads/' prefix (fullname) to differentiate1783# from tag links; this also makes possible to detect branch links1784if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||1785(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {1786$branch=$1;1787}1788# find log type for feed description (title)1789my$type='log';1790if(defined$file_name) {1791$type="history of$file_name";1792$type.="/"if($actioneq'tree');1793$type.=" on '$branch'"if(defined$branch);1794}else{1795$type="log of$branch"if(defined$branch);1796}17971798$res{-title} =$type;1799$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);1800$res{'file_name'} =$file_name;18011802return%res;1803}18041805## ----------------------------------------------------------------------1806## git utility subroutines, invoking git commands18071808# returns path to the core git executable and the --git-dir parameter as list1809sub git_cmd {1810return$GIT,'--git-dir='.$git_dir;1811}18121813# quote the given arguments for passing them to the shell1814# quote_command("command", "arg 1", "arg with ' and ! characters")1815# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"1816# Try to avoid using this function wherever possible.1817sub quote_command {1818returnjoin(' ',1819map( {my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_));1820}18211822# get HEAD ref of given project as hash1823sub git_get_head_hash {1824my$project=shift;1825my$o_git_dir=$git_dir;1826my$retval=undef;1827$git_dir="$projectroot/$project";1828if(open my$fd,"-|", git_cmd(),"rev-parse","--verify","HEAD") {1829my$head= <$fd>;1830close$fd;1831if(defined$head&&$head=~/^([0-9a-fA-F]{40})$/) {1832$retval=$1;1833}1834}1835if(defined$o_git_dir) {1836$git_dir=$o_git_dir;1837}1838return$retval;1839}18401841# get type of given object1842sub git_get_type {1843my$hash=shift;18441845open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;1846my$type= <$fd>;1847close$fdorreturn;1848chomp$type;1849return$type;1850}18511852# repository configuration1853our$config_file='';1854our%config;18551856# store multiple values for single key as anonymous array reference1857# single values stored directly in the hash, not as [ <value> ]1858sub hash_set_multi {1859my($hash,$key,$value) =@_;18601861if(!exists$hash->{$key}) {1862$hash->{$key} =$value;1863}elsif(!ref$hash->{$key}) {1864$hash->{$key} = [$hash->{$key},$value];1865}else{1866push@{$hash->{$key}},$value;1867}1868}18691870# return hash of git project configuration1871# optionally limited to some section, e.g. 'gitweb'1872sub git_parse_project_config {1873my$section_regexp=shift;1874my%config;18751876local$/="\0";18771878open my$fh,"-|", git_cmd(),"config",'-z','-l',1879orreturn;18801881while(my$keyval= <$fh>) {1882chomp$keyval;1883my($key,$value) =split(/\n/,$keyval,2);18841885 hash_set_multi(\%config,$key,$value)1886if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);1887}1888close$fh;18891890return%config;1891}18921893# convert config value to boolean, 'true' or 'false'1894# no value, number > 0, 'true' and 'yes' values are true1895# rest of values are treated as false (never as error)1896sub config_to_bool {1897my$val=shift;18981899# strip leading and trailing whitespace1900$val=~s/^\s+//;1901$val=~s/\s+$//;19021903return(!defined$val||# section.key1904($val=~/^\d+$/&&$val) ||# section.key = 11905($val=~/^(?:true|yes)$/i));# section.key = true1906}19071908# convert config value to simple decimal number1909# an optional value suffix of 'k', 'm', or 'g' will cause the value1910# to be multiplied by 1024, 1048576, or 10737418241911sub config_to_int {1912my$val=shift;19131914# strip leading and trailing whitespace1915$val=~s/^\s+//;1916$val=~s/\s+$//;19171918if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {1919$unit=lc($unit);1920# unknown unit is treated as 11921return$num* ($uniteq'g'?1073741824:1922$uniteq'm'?1048576:1923$uniteq'k'?1024:1);1924}1925return$val;1926}19271928# convert config value to array reference, if needed1929sub config_to_multi {1930my$val=shift;19311932returnref($val) ?$val: (defined($val) ? [$val] : []);1933}19341935sub git_get_project_config {1936my($key,$type) =@_;19371938# key sanity check1939return unless($key);1940$key=~s/^gitweb\.//;1941return if($key=~m/\W/);19421943# type sanity check1944if(defined$type) {1945$type=~s/^--//;1946$type=undef1947unless($typeeq'bool'||$typeeq'int');1948}19491950# get config1951if(!defined$config_file||1952$config_filene"$git_dir/config") {1953%config= git_parse_project_config('gitweb');1954$config_file="$git_dir/config";1955}19561957# ensure given type1958if(!defined$type) {1959return$config{"gitweb.$key"};1960}elsif($typeeq'bool') {1961# backward compatibility: 'git config --bool' returns true/false1962return config_to_bool($config{"gitweb.$key"}) ?'true':'false';1963}elsif($typeeq'int') {1964return config_to_int($config{"gitweb.$key"});1965}1966return$config{"gitweb.$key"};1967}19681969# get hash of given path at given ref1970sub git_get_hash_by_path {1971my$base=shift;1972my$path=shift||returnundef;1973my$type=shift;19741975$path=~ s,/+$,,;19761977open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path1978or die_error(500,"Open git-ls-tree failed");1979my$line= <$fd>;1980close$fdorreturnundef;19811982if(!defined$line) {1983# there is no tree or hash given by $path at $base1984returnundef;1985}19861987#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'1988$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;1989if(defined$type&&$typene$2) {1990# type doesn't match1991returnundef;1992}1993return$3;1994}19951996# get path of entry with given hash at given tree-ish (ref)1997# used to get 'from' filename for combined diff (merge commit) for renames1998sub git_get_path_by_hash {1999my$base=shift||return;2000my$hash=shift||return;20012002local$/="\0";20032004open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2005orreturnundef;2006while(my$line= <$fd>) {2007chomp$line;20082009#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2010#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2011if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2012close$fd;2013return$1;2014}2015}2016close$fd;2017returnundef;2018}20192020## ......................................................................2021## git utility functions, directly accessing git repository20222023sub git_get_project_description {2024my$path=shift;20252026$git_dir="$projectroot/$path";2027open my$fd,"$git_dir/description"2028orreturn git_get_project_config('description');2029my$descr= <$fd>;2030close$fd;2031if(defined$descr) {2032chomp$descr;2033}2034return$descr;2035}20362037sub git_get_project_ctags {2038my$path=shift;2039my$ctags= {};20402041$git_dir="$projectroot/$path";2042unless(opendir D,"$git_dir/ctags") {2043return$ctags;2044}2045foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir(D)) {2046open CT,$_ornext;2047my$val= <CT>;2048chomp$val;2049close CT;2050my$ctag=$_;$ctag=~ s#.*/##;2051$ctags->{$ctag} =$val;2052}2053closedir D;2054$ctags;2055}20562057sub git_populate_project_tagcloud {2058my$ctags=shift;20592060# First, merge different-cased tags; tags vote on casing2061my%ctags_lc;2062foreach(keys%$ctags) {2063$ctags_lc{lc$_}->{count} +=$ctags->{$_};2064if(not$ctags_lc{lc$_}->{topcount}2065or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2066$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2067$ctags_lc{lc$_}->{topname} =$_;2068}2069}20702071my$cloud;2072if(eval{require HTML::TagCloud;1; }) {2073$cloud= HTML::TagCloud->new;2074foreach(sort keys%ctags_lc) {2075# Pad the title with spaces so that the cloud looks2076# less crammed.2077my$title=$ctags_lc{$_}->{topname};2078$title=~s/ / /g;2079$title=~s/^/ /g;2080$title=~s/$/ /g;2081$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2082}2083}else{2084$cloud= \%ctags_lc;2085}2086$cloud;2087}20882089sub git_show_project_tagcloud {2090my($cloud,$count) =@_;2091print STDERR ref($cloud)."..\n";2092if(ref$cloudeq'HTML::TagCloud') {2093return$cloud->html_and_css($count);2094}else{2095my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2096return'<p align="center">'.join(', ',map{2097"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"2098}splice(@tags,0,$count)) .'</p>';2099}2100}21012102sub git_get_project_url_list {2103my$path=shift;21042105$git_dir="$projectroot/$path";2106open my$fd,"$git_dir/cloneurl"2107orreturnwantarray?2108@{ config_to_multi(git_get_project_config('url')) } :2109 config_to_multi(git_get_project_config('url'));2110my@git_project_url_list=map{chomp;$_} <$fd>;2111close$fd;21122113returnwantarray?@git_project_url_list: \@git_project_url_list;2114}21152116sub git_get_projects_list {2117my($filter) =@_;2118my@list;21192120$filter||='';2121$filter=~s/\.git$//;21222123my$check_forks= gitweb_check_feature('forks');21242125if(-d $projects_list) {2126# search in directory2127my$dir=$projects_list. ($filter?"/$filter":'');2128# remove the trailing "/"2129$dir=~s!/+$!!;2130my$pfxlen=length("$dir");2131my$pfxdepth= ($dir=~tr!/!!);21322133 File::Find::find({2134 follow_fast =>1,# follow symbolic links2135 follow_skip =>2,# ignore duplicates2136 dangling_symlinks =>0,# ignore dangling symlinks, silently2137 wanted =>sub{2138# skip project-list toplevel, if we get it.2139return if(m!^[/.]$!);2140# only directories can be git repositories2141return unless(-d $_);2142# don't traverse too deep (Find is super slow on os x)2143if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2144$File::Find::prune =1;2145return;2146}21472148my$subdir=substr($File::Find::name,$pfxlen+1);2149# we check related file in $projectroot2150my$path= ($filter?"$filter/":'') .$subdir;2151if(check_export_ok("$projectroot/$path")) {2152push@list, { path =>$path};2153$File::Find::prune =1;2154}2155},2156},"$dir");21572158}elsif(-f $projects_list) {2159# read from file(url-encoded):2160# 'git%2Fgit.git Linus+Torvalds'2161# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2162# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2163my%paths;2164open my($fd),$projects_listorreturn;2165 PROJECT:2166while(my$line= <$fd>) {2167chomp$line;2168my($path,$owner) =split' ',$line;2169$path= unescape($path);2170$owner= unescape($owner);2171if(!defined$path) {2172next;2173}2174if($filterne'') {2175# looking for forks;2176my$pfx=substr($path,0,length($filter));2177if($pfxne$filter) {2178next PROJECT;2179}2180my$sfx=substr($path,length($filter));2181if($sfx!~/^\/.*\.git$/) {2182next PROJECT;2183}2184}elsif($check_forks) {2185 PATH:2186foreachmy$filter(keys%paths) {2187# looking for forks;2188my$pfx=substr($path,0,length($filter));2189if($pfxne$filter) {2190next PATH;2191}2192my$sfx=substr($path,length($filter));2193if($sfx!~/^\/.*\.git$/) {2194next PATH;2195}2196# is a fork, don't include it in2197# the list2198next PROJECT;2199}2200}2201if(check_export_ok("$projectroot/$path")) {2202my$pr= {2203 path =>$path,2204 owner => to_utf8($owner),2205};2206push@list,$pr;2207(my$forks_path=$path) =~s/\.git$//;2208$paths{$forks_path}++;2209}2210}2211close$fd;2212}2213return@list;2214}22152216our$gitweb_project_owner=undef;2217sub git_get_project_list_from_file {22182219return if(defined$gitweb_project_owner);22202221$gitweb_project_owner= {};2222# read from file (url-encoded):2223# 'git%2Fgit.git Linus+Torvalds'2224# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2225# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2226if(-f $projects_list) {2227open(my$fd,$projects_list);2228while(my$line= <$fd>) {2229chomp$line;2230my($pr,$ow) =split' ',$line;2231$pr= unescape($pr);2232$ow= unescape($ow);2233$gitweb_project_owner->{$pr} = to_utf8($ow);2234}2235close$fd;2236}2237}22382239sub git_get_project_owner {2240my$project=shift;2241my$owner;22422243returnundefunless$project;2244$git_dir="$projectroot/$project";22452246if(!defined$gitweb_project_owner) {2247 git_get_project_list_from_file();2248}22492250if(exists$gitweb_project_owner->{$project}) {2251$owner=$gitweb_project_owner->{$project};2252}2253if(!defined$owner){2254$owner= git_get_project_config('owner');2255}2256if(!defined$owner) {2257$owner= get_file_owner("$git_dir");2258}22592260return$owner;2261}22622263sub git_get_last_activity {2264my($path) =@_;2265my$fd;22662267$git_dir="$projectroot/$path";2268open($fd,"-|", git_cmd(),'for-each-ref',2269'--format=%(committer)',2270'--sort=-committerdate',2271'--count=1',2272'refs/heads')orreturn;2273my$most_recent= <$fd>;2274close$fdorreturn;2275if(defined$most_recent&&2276$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2277my$timestamp=$1;2278my$age=time-$timestamp;2279return($age, age_string($age));2280}2281return(undef,undef);2282}22832284sub git_get_references {2285my$type=shift||"";2286my%refs;2287# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112288# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2289open my$fd,"-|", git_cmd(),"show-ref","--dereference",2290($type? ("--","refs/$type") : ())# use -- <pattern> if $type2291orreturn;22922293while(my$line= <$fd>) {2294chomp$line;2295if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2296if(defined$refs{$1}) {2297push@{$refs{$1}},$2;2298}else{2299$refs{$1} = [$2];2300}2301}2302}2303close$fdorreturn;2304return \%refs;2305}23062307sub git_get_rev_name_tags {2308my$hash=shift||returnundef;23092310open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2311orreturn;2312my$name_rev= <$fd>;2313close$fd;23142315if($name_rev=~ m|^$hash tags/(.*)$|) {2316return$1;2317}else{2318# catches also '$hash undefined' output2319returnundef;2320}2321}23222323## ----------------------------------------------------------------------2324## parse to hash functions23252326sub parse_date {2327my$epoch=shift;2328my$tz=shift||"-0000";23292330my%date;2331my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2332my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2333my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2334$date{'hour'} =$hour;2335$date{'minute'} =$min;2336$date{'mday'} =$mday;2337$date{'day'} =$days[$wday];2338$date{'month'} =$months[$mon];2339$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2340$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2341$date{'mday-time'} =sprintf"%d%s%02d:%02d",2342$mday,$months[$mon],$hour,$min;2343$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",23441900+$year,1+$mon,$mday,$hour,$min,$sec;23452346$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2347my$local=$epoch+ ((int$1+ ($2/60)) *3600);2348($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2349$date{'hour_local'} =$hour;2350$date{'minute_local'} =$min;2351$date{'tz_local'} =$tz;2352$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",23531900+$year,$mon+1,$mday,2354$hour,$min,$sec,$tz);2355return%date;2356}23572358sub parse_tag {2359my$tag_id=shift;2360my%tag;2361my@comment;23622363open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2364$tag{'id'} =$tag_id;2365while(my$line= <$fd>) {2366chomp$line;2367if($line=~m/^object ([0-9a-fA-F]{40})$/) {2368$tag{'object'} =$1;2369}elsif($line=~m/^type (.+)$/) {2370$tag{'type'} =$1;2371}elsif($line=~m/^tag (.+)$/) {2372$tag{'name'} =$1;2373}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2374$tag{'author'} =$1;2375$tag{'epoch'} =$2;2376$tag{'tz'} =$3;2377}elsif($line=~m/--BEGIN/) {2378push@comment,$line;2379last;2380}elsif($lineeq"") {2381last;2382}2383}2384push@comment, <$fd>;2385$tag{'comment'} = \@comment;2386close$fdorreturn;2387if(!defined$tag{'name'}) {2388return2389};2390return%tag2391}23922393sub parse_commit_text {2394my($commit_text,$withparents) =@_;2395my@commit_lines=split'\n',$commit_text;2396my%co;23972398pop@commit_lines;# Remove '\0'23992400if(!@commit_lines) {2401return;2402}24032404my$header=shift@commit_lines;2405if($header!~m/^[0-9a-fA-F]{40}/) {2406return;2407}2408($co{'id'},my@parents) =split' ',$header;2409while(my$line=shift@commit_lines) {2410last if$lineeq"\n";2411if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2412$co{'tree'} =$1;2413}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2414push@parents,$1;2415}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2416$co{'author'} =$1;2417$co{'author_epoch'} =$2;2418$co{'author_tz'} =$3;2419if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2420$co{'author_name'} =$1;2421$co{'author_email'} =$2;2422}else{2423$co{'author_name'} =$co{'author'};2424}2425}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2426$co{'committer'} =$1;2427$co{'committer_epoch'} =$2;2428$co{'committer_tz'} =$3;2429$co{'committer_name'} =$co{'committer'};2430if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2431$co{'committer_name'} =$1;2432$co{'committer_email'} =$2;2433}else{2434$co{'committer_name'} =$co{'committer'};2435}2436}2437}2438if(!defined$co{'tree'}) {2439return;2440};2441$co{'parents'} = \@parents;2442$co{'parent'} =$parents[0];24432444foreachmy$title(@commit_lines) {2445$title=~s/^ //;2446if($titlene"") {2447$co{'title'} = chop_str($title,80,5);2448# remove leading stuff of merges to make the interesting part visible2449if(length($title) >50) {2450$title=~s/^Automatic //;2451$title=~s/^merge (of|with) /Merge ... /i;2452if(length($title) >50) {2453$title=~s/(http|rsync):\/\///;2454}2455if(length($title) >50) {2456$title=~s/(master|www|rsync)\.//;2457}2458if(length($title) >50) {2459$title=~s/kernel.org:?//;2460}2461if(length($title) >50) {2462$title=~s/\/pub\/scm//;2463}2464}2465$co{'title_short'} = chop_str($title,50,5);2466last;2467}2468}2469if(!defined$co{'title'} ||$co{'title'}eq"") {2470$co{'title'} =$co{'title_short'} ='(no commit message)';2471}2472# remove added spaces2473foreachmy$line(@commit_lines) {2474$line=~s/^ //;2475}2476$co{'comment'} = \@commit_lines;24772478my$age=time-$co{'committer_epoch'};2479$co{'age'} =$age;2480$co{'age_string'} = age_string($age);2481my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2482if($age>60*60*24*7*2) {2483$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2484$co{'age_string_age'} =$co{'age_string'};2485}else{2486$co{'age_string_date'} =$co{'age_string'};2487$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2488}2489return%co;2490}24912492sub parse_commit {2493my($commit_id) =@_;2494my%co;24952496local$/="\0";24972498open my$fd,"-|", git_cmd(),"rev-list",2499"--parents",2500"--header",2501"--max-count=1",2502$commit_id,2503"--",2504or die_error(500,"Open git-rev-list failed");2505%co= parse_commit_text(<$fd>,1);2506close$fd;25072508return%co;2509}25102511sub parse_commits {2512my($commit_id,$maxcount,$skip,$filename,@args) =@_;2513my@cos;25142515$maxcount||=1;2516$skip||=0;25172518local$/="\0";25192520open my$fd,"-|", git_cmd(),"rev-list",2521"--header",2522@args,2523("--max-count=".$maxcount),2524("--skip=".$skip),2525@extra_options,2526$commit_id,2527"--",2528($filename? ($filename) : ())2529or die_error(500,"Open git-rev-list failed");2530while(my$line= <$fd>) {2531my%co= parse_commit_text($line);2532push@cos, \%co;2533}2534close$fd;25352536returnwantarray?@cos: \@cos;2537}25382539# parse line of git-diff-tree "raw" output2540sub parse_difftree_raw_line {2541my$line=shift;2542my%res;25432544# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2545# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2546if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2547$res{'from_mode'} =$1;2548$res{'to_mode'} =$2;2549$res{'from_id'} =$3;2550$res{'to_id'} =$4;2551$res{'status'} =$5;2552$res{'similarity'} =$6;2553if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2554($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2555}else{2556$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2557}2558}2559# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2560# combined diff (for merge commit)2561elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2562$res{'nparents'} =length($1);2563$res{'from_mode'} = [split(' ',$2) ];2564$res{'to_mode'} =pop@{$res{'from_mode'}};2565$res{'from_id'} = [split(' ',$3) ];2566$res{'to_id'} =pop@{$res{'from_id'}};2567$res{'status'} = [split('',$4) ];2568$res{'to_file'} = unquote($5);2569}2570# 'c512b523472485aef4fff9e57b229d9d243c967f'2571elsif($line=~m/^([0-9a-fA-F]{40})$/) {2572$res{'commit'} =$1;2573}25742575returnwantarray?%res: \%res;2576}25772578# wrapper: return parsed line of git-diff-tree "raw" output2579# (the argument might be raw line, or parsed info)2580sub parsed_difftree_line {2581my$line_or_ref=shift;25822583if(ref($line_or_ref)eq"HASH") {2584# pre-parsed (or generated by hand)2585return$line_or_ref;2586}else{2587return parse_difftree_raw_line($line_or_ref);2588}2589}25902591# parse line of git-ls-tree output2592sub parse_ls_tree_line ($;%) {2593my$line=shift;2594my%opts=@_;2595my%res;25962597#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2598$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;25992600$res{'mode'} =$1;2601$res{'type'} =$2;2602$res{'hash'} =$3;2603if($opts{'-z'}) {2604$res{'name'} =$4;2605}else{2606$res{'name'} = unquote($4);2607}26082609returnwantarray?%res: \%res;2610}26112612# generates _two_ hashes, references to which are passed as 2 and 3 argument2613sub parse_from_to_diffinfo {2614my($diffinfo,$from,$to,@parents) =@_;26152616if($diffinfo->{'nparents'}) {2617# combined diff2618$from->{'file'} = [];2619$from->{'href'} = [];2620 fill_from_file_info($diffinfo,@parents)2621unlessexists$diffinfo->{'from_file'};2622for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2623$from->{'file'}[$i] =2624defined$diffinfo->{'from_file'}[$i] ?2625$diffinfo->{'from_file'}[$i] :2626$diffinfo->{'to_file'};2627if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2628$from->{'href'}[$i] = href(action=>"blob",2629 hash_base=>$parents[$i],2630 hash=>$diffinfo->{'from_id'}[$i],2631 file_name=>$from->{'file'}[$i]);2632}else{2633$from->{'href'}[$i] =undef;2634}2635}2636}else{2637# ordinary (not combined) diff2638$from->{'file'} =$diffinfo->{'from_file'};2639if($diffinfo->{'status'}ne"A") {# not new (added) file2640$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2641 hash=>$diffinfo->{'from_id'},2642 file_name=>$from->{'file'});2643}else{2644delete$from->{'href'};2645}2646}26472648$to->{'file'} =$diffinfo->{'to_file'};2649if(!is_deleted($diffinfo)) {# file exists in result2650$to->{'href'} = href(action=>"blob", hash_base=>$hash,2651 hash=>$diffinfo->{'to_id'},2652 file_name=>$to->{'file'});2653}else{2654delete$to->{'href'};2655}2656}26572658## ......................................................................2659## parse to array of hashes functions26602661sub git_get_heads_list {2662my$limit=shift;2663my@headslist;26642665open my$fd,'-|', git_cmd(),'for-each-ref',2666($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2667'--format=%(objectname) %(refname) %(subject)%00%(committer)',2668'refs/heads'2669orreturn;2670while(my$line= <$fd>) {2671my%ref_item;26722673chomp$line;2674my($refinfo,$committerinfo) =split(/\0/,$line);2675my($hash,$name,$title) =split(' ',$refinfo,3);2676my($committer,$epoch,$tz) =2677($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2678$ref_item{'fullname'} =$name;2679$name=~s!^refs/heads/!!;26802681$ref_item{'name'} =$name;2682$ref_item{'id'} =$hash;2683$ref_item{'title'} =$title||'(no commit message)';2684$ref_item{'epoch'} =$epoch;2685if($epoch) {2686$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2687}else{2688$ref_item{'age'} ="unknown";2689}26902691push@headslist, \%ref_item;2692}2693close$fd;26942695returnwantarray?@headslist: \@headslist;2696}26972698sub git_get_tags_list {2699my$limit=shift;2700my@tagslist;27012702open my$fd,'-|', git_cmd(),'for-each-ref',2703($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',2704'--format=%(objectname) %(objecttype) %(refname) '.2705'%(*objectname) %(*objecttype) %(subject)%00%(creator)',2706'refs/tags'2707orreturn;2708while(my$line= <$fd>) {2709my%ref_item;27102711chomp$line;2712my($refinfo,$creatorinfo) =split(/\0/,$line);2713my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);2714my($creator,$epoch,$tz) =2715($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);2716$ref_item{'fullname'} =$name;2717$name=~s!^refs/tags/!!;27182719$ref_item{'type'} =$type;2720$ref_item{'id'} =$id;2721$ref_item{'name'} =$name;2722if($typeeq"tag") {2723$ref_item{'subject'} =$title;2724$ref_item{'reftype'} =$reftype;2725$ref_item{'refid'} =$refid;2726}else{2727$ref_item{'reftype'} =$type;2728$ref_item{'refid'} =$id;2729}27302731if($typeeq"tag"||$typeeq"commit") {2732$ref_item{'epoch'} =$epoch;2733if($epoch) {2734$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2735}else{2736$ref_item{'age'} ="unknown";2737}2738}27392740push@tagslist, \%ref_item;2741}2742close$fd;27432744returnwantarray?@tagslist: \@tagslist;2745}27462747## ----------------------------------------------------------------------2748## filesystem-related functions27492750sub get_file_owner {2751my$path=shift;27522753my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);2754my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);2755if(!defined$gcos) {2756returnundef;2757}2758my$owner=$gcos;2759$owner=~s/[,;].*$//;2760return to_utf8($owner);2761}27622763# assume that file exists2764sub insert_file {2765my$filename=shift;27662767open my$fd,'<',$filename;2768print map{ to_utf8($_) } <$fd>;2769close$fd;2770}27712772## ......................................................................2773## mimetype related functions27742775sub mimetype_guess_file {2776my$filename=shift;2777my$mimemap=shift;2778-r $mimemaporreturnundef;27792780my%mimemap;2781open(MIME,$mimemap)orreturnundef;2782while(<MIME>) {2783next ifm/^#/;# skip comments2784my($mime,$exts) =split(/\t+/);2785if(defined$exts) {2786my@exts=split(/\s+/,$exts);2787foreachmy$ext(@exts) {2788$mimemap{$ext} =$mime;2789}2790}2791}2792close(MIME);27932794$filename=~/\.([^.]*)$/;2795return$mimemap{$1};2796}27972798sub mimetype_guess {2799my$filename=shift;2800my$mime;2801$filename=~/\./orreturnundef;28022803if($mimetypes_file) {2804my$file=$mimetypes_file;2805if($file!~m!^/!) {# if it is relative path2806# it is relative to project2807$file="$projectroot/$project/$file";2808}2809$mime= mimetype_guess_file($filename,$file);2810}2811$mime||= mimetype_guess_file($filename,'/etc/mime.types');2812return$mime;2813}28142815sub blob_mimetype {2816my$fd=shift;2817my$filename=shift;28182819if($filename) {2820my$mime= mimetype_guess($filename);2821$mimeandreturn$mime;2822}28232824# just in case2825return$default_blob_plain_mimetypeunless$fd;28262827if(-T $fd) {2828return'text/plain';2829}elsif(!$filename) {2830return'application/octet-stream';2831}elsif($filename=~m/\.png$/i) {2832return'image/png';2833}elsif($filename=~m/\.gif$/i) {2834return'image/gif';2835}elsif($filename=~m/\.jpe?g$/i) {2836return'image/jpeg';2837}else{2838return'application/octet-stream';2839}2840}28412842sub blob_contenttype {2843my($fd,$file_name,$type) =@_;28442845$type||= blob_mimetype($fd,$file_name);2846if($typeeq'text/plain'&&defined$default_text_plain_charset) {2847$type.="; charset=$default_text_plain_charset";2848}28492850return$type;2851}28522853## ======================================================================2854## functions printing HTML: header, footer, error page28552856sub git_header_html {2857my$status=shift||"200 OK";2858my$expires=shift;28592860my$title="$site_name";2861if(defined$project) {2862$title.=" - ". to_utf8($project);2863if(defined$action) {2864$title.="/$action";2865if(defined$file_name) {2866$title.=" - ". esc_path($file_name);2867if($actioneq"tree"&&$file_name!~ m|/$|) {2868$title.="/";2869}2870}2871}2872}2873my$content_type;2874# require explicit support from the UA if we are to send the page as2875# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.2876# we have to do this because MSIE sometimes globs '*/*', pretending to2877# support xhtml+xml but choking when it gets what it asked for.2878if(defined$cgi->http('HTTP_ACCEPT') &&2879$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&2880$cgi->Accept('application/xhtml+xml') !=0) {2881$content_type='application/xhtml+xml';2882}else{2883$content_type='text/html';2884}2885print$cgi->header(-type=>$content_type, -charset =>'utf-8',2886-status=>$status, -expires =>$expires);2887my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';2888print<<EOF;2889<?xml version="1.0" encoding="utf-8"?>2890<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">2891<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">2892<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->2893<!-- git core binaries version$git_version-->2894<head>2895<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>2896<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>2897<meta name="robots" content="index, nofollow"/>2898<title>$title</title>2899EOF2900# print out each stylesheet that exist2901if(defined$stylesheet) {2902#provides backwards capability for those people who define style sheet in a config file2903print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";2904}else{2905foreachmy$stylesheet(@stylesheets) {2906next unless$stylesheet;2907print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";2908}2909}2910if(defined$project) {2911my%href_params= get_feed_info();2912if(!exists$href_params{'-title'}) {2913$href_params{'-title'} ='log';2914}29152916foreachmy$formatqw(RSS Atom){2917my$type=lc($format);2918my%link_attr= (2919'-rel'=>'alternate',2920'-title'=>"$project-$href_params{'-title'} -$formatfeed",2921'-type'=>"application/$type+xml"2922);29232924$href_params{'action'} =$type;2925$link_attr{'-href'} = href(%href_params);2926print"<link ".2927"rel=\"$link_attr{'-rel'}\"".2928"title=\"$link_attr{'-title'}\"".2929"href=\"$link_attr{'-href'}\"".2930"type=\"$link_attr{'-type'}\"".2931"/>\n";29322933$href_params{'extra_options'} ='--no-merges';2934$link_attr{'-href'} = href(%href_params);2935$link_attr{'-title'} .=' (no merges)';2936print"<link ".2937"rel=\"$link_attr{'-rel'}\"".2938"title=\"$link_attr{'-title'}\"".2939"href=\"$link_attr{'-href'}\"".2940"type=\"$link_attr{'-type'}\"".2941"/>\n";2942}29432944}else{2945printf('<link rel="alternate" title="%sprojects list" '.2946'href="%s" type="text/plain; charset=utf-8" />'."\n",2947$site_name, href(project=>undef, action=>"project_index"));2948printf('<link rel="alternate" title="%sprojects feeds" '.2949'href="%s" type="text/x-opml" />'."\n",2950$site_name, href(project=>undef, action=>"opml"));2951}2952if(defined$favicon) {2953printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);2954}29552956print"</head>\n".2957"<body>\n";29582959if(-f $site_header) {2960 insert_file($site_header);2961}29622963print"<div class=\"page_header\">\n".2964$cgi->a({-href => esc_url($logo_url),2965-title =>$logo_label},2966qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));2967print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";2968if(defined$project) {2969print$cgi->a({-href => href(action=>"summary")}, esc_html($project));2970if(defined$action) {2971print" /$action";2972}2973print"\n";2974}2975print"</div>\n";29762977my$have_search= gitweb_check_feature('search');2978if(defined$project&&$have_search) {2979if(!defined$searchtext) {2980$searchtext="";2981}2982my$search_hash;2983if(defined$hash_base) {2984$search_hash=$hash_base;2985}elsif(defined$hash) {2986$search_hash=$hash;2987}else{2988$search_hash="HEAD";2989}2990my$action=$my_uri;2991my$use_pathinfo= gitweb_check_feature('pathinfo');2992if($use_pathinfo) {2993$action.="/".esc_url($project);2994}2995print$cgi->startform(-method=>"get", -action =>$action) .2996"<div class=\"search\">\n".2997(!$use_pathinfo&&2998$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .2999$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3000$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3001$cgi->popup_menu(-name =>'st', -default=>'commit',3002-values=> ['commit','grep','author','committer','pickaxe']) .3003$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3004" search:\n",3005$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3006"<span title=\"Extended regular expression\">".3007$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3008-checked =>$search_use_regexp) .3009"</span>".3010"</div>".3011$cgi->end_form() ."\n";3012}3013}30143015sub git_footer_html {3016my$feed_class='rss_logo';30173018print"<div class=\"page_footer\">\n";3019if(defined$project) {3020my$descr= git_get_project_description($project);3021if(defined$descr) {3022print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3023}30243025my%href_params= get_feed_info();3026if(!%href_params) {3027$feed_class.=' generic';3028}3029$href_params{'-title'} ||='log';30303031foreachmy$formatqw(RSS Atom){3032$href_params{'action'} =lc($format);3033print$cgi->a({-href => href(%href_params),3034-title =>"$href_params{'-title'}$formatfeed",3035-class=>$feed_class},$format)."\n";3036}30373038}else{3039print$cgi->a({-href => href(project=>undef, action=>"opml"),3040-class=>$feed_class},"OPML") ." ";3041print$cgi->a({-href => href(project=>undef, action=>"project_index"),3042-class=>$feed_class},"TXT") ."\n";3043}3044print"</div>\n";# class="page_footer"30453046if(-f $site_footer) {3047 insert_file($site_footer);3048}30493050print"</body>\n".3051"</html>";3052}30533054# die_error(<http_status_code>, <error_message>)3055# Example: die_error(404, 'Hash not found')3056# By convention, use the following status codes (as defined in RFC 2616):3057# 400: Invalid or missing CGI parameters, or3058# requested object exists but has wrong type.3059# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3060# this server or project.3061# 404: Requested object/revision/project doesn't exist.3062# 500: The server isn't configured properly, or3063# an internal error occurred (e.g. failed assertions caused by bugs), or3064# an unknown error occurred (e.g. the git binary died unexpectedly).3065sub die_error {3066my$status=shift||500;3067my$error=shift||"Internal server error";30683069my%http_responses= (400=>'400 Bad Request',3070403=>'403 Forbidden',3071404=>'404 Not Found',3072500=>'500 Internal Server Error');3073 git_header_html($http_responses{$status});3074print<<EOF;3075<div class="page_body">3076<br /><br />3077$status-$error3078<br />3079</div>3080EOF3081 git_footer_html();3082exit;3083}30843085## ----------------------------------------------------------------------3086## functions printing or outputting HTML: navigation30873088sub git_print_page_nav {3089my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3090$extra=''if!defined$extra;# pager or formats30913092my@navs=qw(summary shortlog log commit commitdiff tree);3093if($suppress) {3094@navs=grep{$_ne$suppress}@navs;3095}30963097my%arg=map{$_=> {action=>$_} }@navs;3098if(defined$head) {3099for(qw(commit commitdiff)) {3100$arg{$_}{'hash'} =$head;3101}3102if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3103for(qw(shortlog log)) {3104$arg{$_}{'hash'} =$head;3105}3106}3107}31083109$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3110$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;31113112my@actions= gitweb_get_feature('actions');3113my%repl= (3114'%'=>'%',3115'n'=>$project,# project name3116'f'=>$git_dir,# project path within filesystem3117'h'=>$treehead||'',# current hash ('h' parameter)3118'b'=>$treebase||'',# hash base ('hb' parameter)3119);3120while(@actions) {3121my($label,$link,$pos) =splice(@actions,0,3);3122# insert3123@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3124# munch munch3125$link=~s/%([%nfhb])/$repl{$1}/g;3126$arg{$label}{'_href'} =$link;3127}31283129print"<div class=\"page_nav\">\n".3130(join" | ",3131map{$_eq$current?3132$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3133}@navs);3134print"<br/>\n$extra<br/>\n".3135"</div>\n";3136}31373138sub format_paging_nav {3139my($action,$hash,$head,$page,$has_next_link) =@_;3140my$paging_nav;314131423143if($hashne$head||$page) {3144$paging_nav.=$cgi->a({-href => href(action=>$action)},"HEAD");3145}else{3146$paging_nav.="HEAD";3147}31483149if($page>0) {3150$paging_nav.=" ⋅ ".3151$cgi->a({-href => href(-replay=>1, page=>$page-1),3152-accesskey =>"p", -title =>"Alt-p"},"prev");3153}else{3154$paging_nav.=" ⋅ prev";3155}31563157if($has_next_link) {3158$paging_nav.=" ⋅ ".3159$cgi->a({-href => href(-replay=>1, page=>$page+1),3160-accesskey =>"n", -title =>"Alt-n"},"next");3161}else{3162$paging_nav.=" ⋅ next";3163}31643165return$paging_nav;3166}31673168## ......................................................................3169## functions printing or outputting HTML: div31703171sub git_print_header_div {3172my($action,$title,$hash,$hash_base) =@_;3173my%args= ();31743175$args{'action'} =$action;3176$args{'hash'} =$hashif$hash;3177$args{'hash_base'} =$hash_baseif$hash_base;31783179print"<div class=\"header\">\n".3180$cgi->a({-href => href(%args), -class=>"title"},3181$title?$title:$action) .3182"\n</div>\n";3183}31843185#sub git_print_authorship (\%) {3186sub git_print_authorship {3187my$co=shift;31883189my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3190print"<div class=\"author_date\">".3191 esc_html($co->{'author_name'}) .3192" [$ad{'rfc2822'}";3193if($ad{'hour_local'} <6) {3194printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3195$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});3196}else{3197printf(" (%02d:%02d%s)",3198$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});3199}3200print"]</div>\n";3201}32023203sub git_print_page_path {3204my$name=shift;3205my$type=shift;3206my$hb=shift;320732083209print"<div class=\"page_path\">";3210print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3211-title =>'tree root'}, to_utf8("[$project]"));3212print" / ";3213if(defined$name) {3214my@dirname=split'/',$name;3215my$basename=pop@dirname;3216my$fullname='';32173218foreachmy$dir(@dirname) {3219$fullname.= ($fullname?'/':'') .$dir;3220print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3221 hash_base=>$hb),3222-title =>$fullname}, esc_path($dir));3223print" / ";3224}3225if(defined$type&&$typeeq'blob') {3226print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3227 hash_base=>$hb),3228-title =>$name}, esc_path($basename));3229}elsif(defined$type&&$typeeq'tree') {3230print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3231 hash_base=>$hb),3232-title =>$name}, esc_path($basename));3233print" / ";3234}else{3235print esc_path($basename);3236}3237}3238print"<br/></div>\n";3239}32403241# sub git_print_log (\@;%) {3242sub git_print_log ($;%) {3243my$log=shift;3244my%opts=@_;32453246if($opts{'-remove_title'}) {3247# remove title, i.e. first line of log3248shift@$log;3249}3250# remove leading empty lines3251while(defined$log->[0] &&$log->[0]eq"") {3252shift@$log;3253}32543255# print log3256my$signoff=0;3257my$empty=0;3258foreachmy$line(@$log) {3259if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3260$signoff=1;3261$empty=0;3262if(!$opts{'-remove_signoff'}) {3263print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3264next;3265}else{3266# remove signoff lines3267next;3268}3269}else{3270$signoff=0;3271}32723273# print only one empty line3274# do not print empty line after signoff3275if($lineeq"") {3276next if($empty||$signoff);3277$empty=1;3278}else{3279$empty=0;3280}32813282print format_log_line_html($line) ."<br/>\n";3283}32843285if($opts{'-final_empty_line'}) {3286# end with single empty line3287print"<br/>\n"unless$empty;3288}3289}32903291# return link target (what link points to)3292sub git_get_link_target {3293my$hash=shift;3294my$link_target;32953296# read link3297open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3298orreturn;3299{3300local$/;3301$link_target= <$fd>;3302}3303close$fd3304orreturn;33053306return$link_target;3307}33083309# given link target, and the directory (basedir) the link is in,3310# return target of link relative to top directory (top tree);3311# return undef if it is not possible (including absolute links).3312sub normalize_link_target {3313my($link_target,$basedir,$hash_base) =@_;33143315# we can normalize symlink target only if $hash_base is provided3316return unless$hash_base;33173318# absolute symlinks (beginning with '/') cannot be normalized3319return if(substr($link_target,0,1)eq'/');33203321# normalize link target to path from top (root) tree (dir)3322my$path;3323if($basedir) {3324$path=$basedir.'/'.$link_target;3325}else{3326# we are in top (root) tree (dir)3327$path=$link_target;3328}33293330# remove //, /./, and /../3331my@path_parts;3332foreachmy$part(split('/',$path)) {3333# discard '.' and ''3334next if(!$part||$parteq'.');3335# handle '..'3336if($parteq'..') {3337if(@path_parts) {3338pop@path_parts;3339}else{3340# link leads outside repository (outside top dir)3341return;3342}3343}else{3344push@path_parts,$part;3345}3346}3347$path=join('/',@path_parts);33483349return$path;3350}33513352# print tree entry (row of git_tree), but without encompassing <tr> element3353sub git_print_tree_entry {3354my($t,$basedir,$hash_base,$have_blame) =@_;33553356my%base_key= ();3357$base_key{'hash_base'} =$hash_baseifdefined$hash_base;33583359# The format of a table row is: mode list link. Where mode is3360# the mode of the entry, list is the name of the entry, an href,3361# and link is the action links of the entry.33623363print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3364if($t->{'type'}eq"blob") {3365print"<td class=\"list\">".3366$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3367 file_name=>"$basedir$t->{'name'}",%base_key),3368-class=>"list"}, esc_path($t->{'name'}));3369if(S_ISLNK(oct$t->{'mode'})) {3370my$link_target= git_get_link_target($t->{'hash'});3371if($link_target) {3372my$norm_target= normalize_link_target($link_target,$basedir,$hash_base);3373if(defined$norm_target) {3374print" -> ".3375$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3376 file_name=>$norm_target),3377-title =>$norm_target}, esc_path($link_target));3378}else{3379print" -> ". esc_path($link_target);3380}3381}3382}3383print"</td>\n";3384print"<td class=\"link\">";3385print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3386 file_name=>"$basedir$t->{'name'}",%base_key)},3387"blob");3388if($have_blame) {3389print" | ".3390$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3391 file_name=>"$basedir$t->{'name'}",%base_key)},3392"blame");3393}3394if(defined$hash_base) {3395print" | ".3396$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3397 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3398"history");3399}3400print" | ".3401$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3402 file_name=>"$basedir$t->{'name'}")},3403"raw");3404print"</td>\n";34053406}elsif($t->{'type'}eq"tree") {3407print"<td class=\"list\">";3408print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3409 file_name=>"$basedir$t->{'name'}",%base_key)},3410 esc_path($t->{'name'}));3411print"</td>\n";3412print"<td class=\"link\">";3413print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3414 file_name=>"$basedir$t->{'name'}",%base_key)},3415"tree");3416if(defined$hash_base) {3417print" | ".3418$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3419 file_name=>"$basedir$t->{'name'}")},3420"history");3421}3422print"</td>\n";3423}else{3424# unknown object: we can only present history for it3425# (this includes 'commit' object, i.e. submodule support)3426print"<td class=\"list\">".3427 esc_path($t->{'name'}) .3428"</td>\n";3429print"<td class=\"link\">";3430if(defined$hash_base) {3431print$cgi->a({-href => href(action=>"history",3432 hash_base=>$hash_base,3433 file_name=>"$basedir$t->{'name'}")},3434"history");3435}3436print"</td>\n";3437}3438}34393440## ......................................................................3441## functions printing large fragments of HTML34423443# get pre-image filenames for merge (combined) diff3444sub fill_from_file_info {3445my($diff,@parents) =@_;34463447$diff->{'from_file'} = [ ];3448$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3449for(my$i=0;$i<$diff->{'nparents'};$i++) {3450if($diff->{'status'}[$i]eq'R'||3451$diff->{'status'}[$i]eq'C') {3452$diff->{'from_file'}[$i] =3453 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3454}3455}34563457return$diff;3458}34593460# is current raw difftree line of file deletion3461sub is_deleted {3462my$diffinfo=shift;34633464return$diffinfo->{'to_id'}eq('0' x 40);3465}34663467# does patch correspond to [previous] difftree raw line3468# $diffinfo - hashref of parsed raw diff format3469# $patchinfo - hashref of parsed patch diff format3470# (the same keys as in $diffinfo)3471sub is_patch_split {3472my($diffinfo,$patchinfo) =@_;34733474returndefined$diffinfo&&defined$patchinfo3475&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3476}347734783479sub git_difftree_body {3480my($difftree,$hash,@parents) =@_;3481my($parent) =$parents[0];3482my$have_blame= gitweb_check_feature('blame');3483print"<div class=\"list_head\">\n";3484if($#{$difftree} >10) {3485print(($#{$difftree} +1) ." files changed:\n");3486}3487print"</div>\n";34883489print"<table class=\"".3490(@parents>1?"combined ":"") .3491"diff_tree\">\n";34923493# header only for combined diff in 'commitdiff' view3494my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3495if($has_header) {3496# table header3497print"<thead><tr>\n".3498"<th></th><th></th>\n";# filename, patchN link3499for(my$i=0;$i<@parents;$i++) {3500my$par=$parents[$i];3501print"<th>".3502$cgi->a({-href => href(action=>"commitdiff",3503 hash=>$hash, hash_parent=>$par),3504-title =>'commitdiff to parent number '.3505($i+1) .': '.substr($par,0,7)},3506$i+1) .3507" </th>\n";3508}3509print"</tr></thead>\n<tbody>\n";3510}35113512my$alternate=1;3513my$patchno=0;3514foreachmy$line(@{$difftree}) {3515my$diff= parsed_difftree_line($line);35163517if($alternate) {3518print"<tr class=\"dark\">\n";3519}else{3520print"<tr class=\"light\">\n";3521}3522$alternate^=1;35233524if(exists$diff->{'nparents'}) {# combined diff35253526 fill_from_file_info($diff,@parents)3527unlessexists$diff->{'from_file'};35283529if(!is_deleted($diff)) {3530# file exists in the result (child) commit3531print"<td>".3532$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3533 file_name=>$diff->{'to_file'},3534 hash_base=>$hash),3535-class=>"list"}, esc_path($diff->{'to_file'})) .3536"</td>\n";3537}else{3538print"<td>".3539 esc_path($diff->{'to_file'}) .3540"</td>\n";3541}35423543if($actioneq'commitdiff') {3544# link to patch3545$patchno++;3546print"<td class=\"link\">".3547$cgi->a({-href =>"#patch$patchno"},"patch") .3548" | ".3549"</td>\n";3550}35513552my$has_history=0;3553my$not_deleted=0;3554for(my$i=0;$i<$diff->{'nparents'};$i++) {3555my$hash_parent=$parents[$i];3556my$from_hash=$diff->{'from_id'}[$i];3557my$from_path=$diff->{'from_file'}[$i];3558my$status=$diff->{'status'}[$i];35593560$has_history||= ($statusne'A');3561$not_deleted||= ($statusne'D');35623563if($statuseq'A') {3564print"<td class=\"link\"align=\"right\"> | </td>\n";3565}elsif($statuseq'D') {3566print"<td class=\"link\">".3567$cgi->a({-href => href(action=>"blob",3568 hash_base=>$hash,3569 hash=>$from_hash,3570 file_name=>$from_path)},3571"blob". ($i+1)) .3572" | </td>\n";3573}else{3574if($diff->{'to_id'}eq$from_hash) {3575print"<td class=\"link nochange\">";3576}else{3577print"<td class=\"link\">";3578}3579print$cgi->a({-href => href(action=>"blobdiff",3580 hash=>$diff->{'to_id'},3581 hash_parent=>$from_hash,3582 hash_base=>$hash,3583 hash_parent_base=>$hash_parent,3584 file_name=>$diff->{'to_file'},3585 file_parent=>$from_path)},3586"diff". ($i+1)) .3587" | </td>\n";3588}3589}35903591print"<td class=\"link\">";3592if($not_deleted) {3593print$cgi->a({-href => href(action=>"blob",3594 hash=>$diff->{'to_id'},3595 file_name=>$diff->{'to_file'},3596 hash_base=>$hash)},3597"blob");3598print" | "if($has_history);3599}3600if($has_history) {3601print$cgi->a({-href => href(action=>"history",3602 file_name=>$diff->{'to_file'},3603 hash_base=>$hash)},3604"history");3605}3606print"</td>\n";36073608print"</tr>\n";3609next;# instead of 'else' clause, to avoid extra indent3610}3611# else ordinary diff36123613my($to_mode_oct,$to_mode_str,$to_file_type);3614my($from_mode_oct,$from_mode_str,$from_file_type);3615if($diff->{'to_mode'}ne('0' x 6)) {3616$to_mode_oct=oct$diff->{'to_mode'};3617if(S_ISREG($to_mode_oct)) {# only for regular file3618$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits3619}3620$to_file_type= file_type($diff->{'to_mode'});3621}3622if($diff->{'from_mode'}ne('0' x 6)) {3623$from_mode_oct=oct$diff->{'from_mode'};3624if(S_ISREG($to_mode_oct)) {# only for regular file3625$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits3626}3627$from_file_type= file_type($diff->{'from_mode'});3628}36293630if($diff->{'status'}eq"A") {# created3631my$mode_chng="<span class=\"file_status new\">[new$to_file_type";3632$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;3633$mode_chng.="]</span>";3634print"<td>";3635print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3636 hash_base=>$hash, file_name=>$diff->{'file'}),3637-class=>"list"}, esc_path($diff->{'file'}));3638print"</td>\n";3639print"<td>$mode_chng</td>\n";3640print"<td class=\"link\">";3641if($actioneq'commitdiff') {3642# link to patch3643$patchno++;3644print$cgi->a({-href =>"#patch$patchno"},"patch");3645print" | ";3646}3647print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3648 hash_base=>$hash, file_name=>$diff->{'file'})},3649"blob");3650print"</td>\n";36513652}elsif($diff->{'status'}eq"D") {# deleted3653my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";3654print"<td>";3655print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3656 hash_base=>$parent, file_name=>$diff->{'file'}),3657-class=>"list"}, esc_path($diff->{'file'}));3658print"</td>\n";3659print"<td>$mode_chng</td>\n";3660print"<td class=\"link\">";3661if($actioneq'commitdiff') {3662# link to patch3663$patchno++;3664print$cgi->a({-href =>"#patch$patchno"},"patch");3665print" | ";3666}3667print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3668 hash_base=>$parent, file_name=>$diff->{'file'})},3669"blob") ." | ";3670if($have_blame) {3671print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,3672 file_name=>$diff->{'file'})},3673"blame") ." | ";3674}3675print$cgi->a({-href => href(action=>"history", hash_base=>$parent,3676 file_name=>$diff->{'file'})},3677"history");3678print"</td>\n";36793680}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed3681my$mode_chnge="";3682if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3683$mode_chnge="<span class=\"file_status mode_chnge\">[changed";3684if($from_file_typene$to_file_type) {3685$mode_chnge.=" from$from_file_typeto$to_file_type";3686}3687if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {3688if($from_mode_str&&$to_mode_str) {3689$mode_chnge.=" mode:$from_mode_str->$to_mode_str";3690}elsif($to_mode_str) {3691$mode_chnge.=" mode:$to_mode_str";3692}3693}3694$mode_chnge.="]</span>\n";3695}3696print"<td>";3697print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3698 hash_base=>$hash, file_name=>$diff->{'file'}),3699-class=>"list"}, esc_path($diff->{'file'}));3700print"</td>\n";3701print"<td>$mode_chnge</td>\n";3702print"<td class=\"link\">";3703if($actioneq'commitdiff') {3704# link to patch3705$patchno++;3706print$cgi->a({-href =>"#patch$patchno"},"patch") .3707" | ";3708}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3709# "commit" view and modified file (not onlu mode changed)3710print$cgi->a({-href => href(action=>"blobdiff",3711 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3712 hash_base=>$hash, hash_parent_base=>$parent,3713 file_name=>$diff->{'file'})},3714"diff") .3715" | ";3716}3717print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3718 hash_base=>$hash, file_name=>$diff->{'file'})},3719"blob") ." | ";3720if($have_blame) {3721print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3722 file_name=>$diff->{'file'})},3723"blame") ." | ";3724}3725print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3726 file_name=>$diff->{'file'})},3727"history");3728print"</td>\n";37293730}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied3731my%status_name= ('R'=>'moved','C'=>'copied');3732my$nstatus=$status_name{$diff->{'status'}};3733my$mode_chng="";3734if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3735# mode also for directories, so we cannot use $to_mode_str3736$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);3737}3738print"<td>".3739$cgi->a({-href => href(action=>"blob", hash_base=>$hash,3740 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),3741-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".3742"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".3743$cgi->a({-href => href(action=>"blob", hash_base=>$parent,3744 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),3745-class=>"list"}, esc_path($diff->{'from_file'})) .3746" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".3747"<td class=\"link\">";3748if($actioneq'commitdiff') {3749# link to patch3750$patchno++;3751print$cgi->a({-href =>"#patch$patchno"},"patch") .3752" | ";3753}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3754# "commit" view and modified file (not only pure rename or copy)3755print$cgi->a({-href => href(action=>"blobdiff",3756 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3757 hash_base=>$hash, hash_parent_base=>$parent,3758 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},3759"diff") .3760" | ";3761}3762print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3763 hash_base=>$parent, file_name=>$diff->{'to_file'})},3764"blob") ." | ";3765if($have_blame) {3766print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3767 file_name=>$diff->{'to_file'})},3768"blame") ." | ";3769}3770print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3771 file_name=>$diff->{'to_file'})},3772"history");3773print"</td>\n";37743775}# we should not encounter Unmerged (U) or Unknown (X) status3776print"</tr>\n";3777}3778print"</tbody>"if$has_header;3779print"</table>\n";3780}37813782sub git_patchset_body {3783my($fd,$difftree,$hash,@hash_parents) =@_;3784my($hash_parent) =$hash_parents[0];37853786my$is_combined= (@hash_parents>1);3787my$patch_idx=0;3788my$patch_number=0;3789my$patch_line;3790my$diffinfo;3791my$to_name;3792my(%from,%to);37933794print"<div class=\"patchset\">\n";37953796# skip to first patch3797while($patch_line= <$fd>) {3798chomp$patch_line;37993800last if($patch_line=~m/^diff /);3801}38023803 PATCH:3804while($patch_line) {38053806# parse "git diff" header line3807if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {3808# $1 is from_name, which we do not use3809$to_name= unquote($2);3810$to_name=~s!^b/!!;3811}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {3812# $1 is 'cc' or 'combined', which we do not use3813$to_name= unquote($2);3814}else{3815$to_name=undef;3816}38173818# check if current patch belong to current raw line3819# and parse raw git-diff line if needed3820if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {3821# this is continuation of a split patch3822print"<div class=\"patch cont\">\n";3823}else{3824# advance raw git-diff output if needed3825$patch_idx++ifdefined$diffinfo;38263827# read and prepare patch information3828$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);38293830# compact combined diff output can have some patches skipped3831# find which patch (using pathname of result) we are at now;3832if($is_combined) {3833while($to_namene$diffinfo->{'to_file'}) {3834print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".3835 format_diff_cc_simplified($diffinfo,@hash_parents) .3836"</div>\n";# class="patch"38373838$patch_idx++;3839$patch_number++;38403841last if$patch_idx>$#$difftree;3842$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);3843}3844}38453846# modifies %from, %to hashes3847 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);38483849# this is first patch for raw difftree line with $patch_idx index3850# we index @$difftree array from 0, but number patches from 13851print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";3852}38533854# git diff header3855#assert($patch_line =~ m/^diff /) if DEBUG;3856#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed3857$patch_number++;3858# print "git diff" header3859print format_git_diff_header_line($patch_line,$diffinfo,3860 \%from, \%to);38613862# print extended diff header3863print"<div class=\"diff extended_header\">\n";3864 EXTENDED_HEADER:3865while($patch_line= <$fd>) {3866chomp$patch_line;38673868last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);38693870print format_extended_diff_header_line($patch_line,$diffinfo,3871 \%from, \%to);3872}3873print"</div>\n";# class="diff extended_header"38743875# from-file/to-file diff header3876if(!$patch_line) {3877print"</div>\n";# class="patch"3878last PATCH;3879}3880next PATCH if($patch_line=~m/^diff /);3881#assert($patch_line =~ m/^---/) if DEBUG;38823883my$last_patch_line=$patch_line;3884$patch_line= <$fd>;3885chomp$patch_line;3886#assert($patch_line =~ m/^\+\+\+/) if DEBUG;38873888print format_diff_from_to_header($last_patch_line,$patch_line,3889$diffinfo, \%from, \%to,3890@hash_parents);38913892# the patch itself3893 LINE:3894while($patch_line= <$fd>) {3895chomp$patch_line;38963897next PATCH if($patch_line=~m/^diff /);38983899print format_diff_line($patch_line, \%from, \%to);3900}39013902}continue{3903print"</div>\n";# class="patch"3904}39053906# for compact combined (--cc) format, with chunk and patch simpliciaction3907# patchset might be empty, but there might be unprocessed raw lines3908for(++$patch_idxif$patch_number>0;3909$patch_idx<@$difftree;3910++$patch_idx) {3911# read and prepare patch information3912$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);39133914# generate anchor for "patch" links in difftree / whatchanged part3915print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".3916 format_diff_cc_simplified($diffinfo,@hash_parents) .3917"</div>\n";# class="patch"39183919$patch_number++;3920}39213922if($patch_number==0) {3923if(@hash_parents>1) {3924print"<div class=\"diff nodifferences\">Trivial merge</div>\n";3925}else{3926print"<div class=\"diff nodifferences\">No differences found</div>\n";3927}3928}39293930print"</div>\n";# class="patchset"3931}39323933# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39343935# fills project list info (age, description, owner, forks) for each3936# project in the list, removing invalid projects from returned list3937# NOTE: modifies $projlist, but does not remove entries from it3938sub fill_project_list_info {3939my($projlist,$check_forks) =@_;3940my@projects;39413942my$show_ctags= gitweb_check_feature('ctags');3943 PROJECT:3944foreachmy$pr(@$projlist) {3945my(@activity) = git_get_last_activity($pr->{'path'});3946unless(@activity) {3947next PROJECT;3948}3949($pr->{'age'},$pr->{'age_string'}) =@activity;3950if(!defined$pr->{'descr'}) {3951my$descr= git_get_project_description($pr->{'path'}) ||"";3952$descr= to_utf8($descr);3953$pr->{'descr_long'} =$descr;3954$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);3955}3956if(!defined$pr->{'owner'}) {3957$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";3958}3959if($check_forks) {3960my$pname=$pr->{'path'};3961if(($pname=~s/\.git$//) &&3962($pname!~/\/$/) &&3963(-d "$projectroot/$pname")) {3964$pr->{'forks'} ="-d$projectroot/$pname";3965}else{3966$pr->{'forks'} =0;3967}3968}3969$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});3970push@projects,$pr;3971}39723973return@projects;3974}39753976# print 'sort by' <th> element, generating 'sort by $name' replay link3977# if that order is not selected3978sub print_sort_th {3979my($name,$order,$header) =@_;3980$header||=ucfirst($name);39813982if($ordereq$name) {3983print"<th>$header</th>\n";3984}else{3985print"<th>".3986$cgi->a({-href => href(-replay=>1, order=>$name),3987-class=>"header"},$header) .3988"</th>\n";3989}3990}39913992sub git_project_list_body {3993# actually uses global variable $project3994my($projlist,$order,$from,$to,$extra,$no_header) =@_;39953996my$check_forks= gitweb_check_feature('forks');3997my@projects= fill_project_list_info($projlist,$check_forks);39983999$order||=$default_projects_order;4000$from=0unlessdefined$from;4001$to=$#projectsif(!defined$to||$#projects<$to);40024003my%order_info= (4004 project => { key =>'path', type =>'str'},4005 descr => { key =>'descr_long', type =>'str'},4006 owner => { key =>'owner', type =>'str'},4007 age => { key =>'age', type =>'num'}4008);4009my$oi=$order_info{$order};4010if($oi->{'type'}eq'str') {4011@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4012}else{4013@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4014}40154016my$show_ctags= gitweb_check_feature('ctags');4017if($show_ctags) {4018my%ctags;4019foreachmy$p(@projects) {4020foreachmy$ct(keys%{$p->{'ctags'}}) {4021$ctags{$ct} +=$p->{'ctags'}->{$ct};4022}4023}4024my$cloud= git_populate_project_tagcloud(\%ctags);4025print git_show_project_tagcloud($cloud,64);4026}40274028print"<table class=\"project_list\">\n";4029unless($no_header) {4030print"<tr>\n";4031if($check_forks) {4032print"<th></th>\n";4033}4034 print_sort_th('project',$order,'Project');4035 print_sort_th('descr',$order,'Description');4036 print_sort_th('owner',$order,'Owner');4037 print_sort_th('age',$order,'Last Change');4038print"<th></th>\n".# for links4039"</tr>\n";4040}4041my$alternate=1;4042my$tagfilter=$cgi->param('by_tag');4043for(my$i=$from;$i<=$to;$i++) {4044my$pr=$projects[$i];40454046next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4047next if$searchtextand not$pr->{'path'} =~/$searchtext/4048and not$pr->{'descr_long'} =~/$searchtext/;4049# Weed out forks or non-matching entries of search4050if($check_forks) {4051my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4052$forkbase="^$forkbase"if$forkbase;4053next ifnot$searchtextand not$tagfilterand$show_ctags4054and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4055}40564057if($alternate) {4058print"<tr class=\"dark\">\n";4059}else{4060print"<tr class=\"light\">\n";4061}4062$alternate^=1;4063if($check_forks) {4064print"<td>";4065if($pr->{'forks'}) {4066print"<!--$pr->{'forks'} -->\n";4067print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4068}4069print"</td>\n";4070}4071print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4072-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4073"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4074-class=>"list", -title =>$pr->{'descr_long'}},4075 esc_html($pr->{'descr'})) ."</td>\n".4076"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4077print"<td class=\"". age_class($pr->{'age'}) ."\">".4078(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4079"<td class=\"link\">".4080$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4081$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4082$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4083$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4084($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4085"</td>\n".4086"</tr>\n";4087}4088if(defined$extra) {4089print"<tr>\n";4090if($check_forks) {4091print"<td></td>\n";4092}4093print"<td colspan=\"5\">$extra</td>\n".4094"</tr>\n";4095}4096print"</table>\n";4097}40984099sub git_shortlog_body {4100# uses global variable $project4101my($commitlist,$from,$to,$refs,$extra) =@_;41024103$from=0unlessdefined$from;4104$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);41054106print"<table class=\"shortlog\">\n";4107my$alternate=1;4108for(my$i=$from;$i<=$to;$i++) {4109my%co= %{$commitlist->[$i]};4110my$commit=$co{'id'};4111my$ref= format_ref_marker($refs,$commit);4112if($alternate) {4113print"<tr class=\"dark\">\n";4114}else{4115print"<tr class=\"light\">\n";4116}4117$alternate^=1;4118my$author= chop_and_escape_str($co{'author_name'},10);4119# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4120print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4121"<td><i>".$author."</i></td>\n".4122"<td>";4123print format_subject_html($co{'title'},$co{'title_short'},4124 href(action=>"commit", hash=>$commit),$ref);4125print"</td>\n".4126"<td class=\"link\">".4127$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4128$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4129$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4130my$snapshot_links= format_snapshot_links($commit);4131if(defined$snapshot_links) {4132print" | ".$snapshot_links;4133}4134print"</td>\n".4135"</tr>\n";4136}4137if(defined$extra) {4138print"<tr>\n".4139"<td colspan=\"4\">$extra</td>\n".4140"</tr>\n";4141}4142print"</table>\n";4143}41444145sub git_history_body {4146# Warning: assumes constant type (blob or tree) during history4147my($commitlist,$from,$to,$refs,$hash_base,$ftype,$extra) =@_;41484149$from=0unlessdefined$from;4150$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});41514152print"<table class=\"history\">\n";4153my$alternate=1;4154for(my$i=$from;$i<=$to;$i++) {4155my%co= %{$commitlist->[$i]};4156if(!%co) {4157next;4158}4159my$commit=$co{'id'};41604161my$ref= format_ref_marker($refs,$commit);41624163if($alternate) {4164print"<tr class=\"dark\">\n";4165}else{4166print"<tr class=\"light\">\n";4167}4168$alternate^=1;4169# shortlog uses chop_str($co{'author_name'}, 10)4170my$author= chop_and_escape_str($co{'author_name'},15,3);4171print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4172"<td><i>".$author."</i></td>\n".4173"<td>";4174# originally git_history used chop_str($co{'title'}, 50)4175print format_subject_html($co{'title'},$co{'title_short'},4176 href(action=>"commit", hash=>$commit),$ref);4177print"</td>\n".4178"<td class=\"link\">".4179$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4180$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");41814182if($ftypeeq'blob') {4183my$blob_current= git_get_hash_by_path($hash_base,$file_name);4184my$blob_parent= git_get_hash_by_path($commit,$file_name);4185if(defined$blob_current&&defined$blob_parent&&4186$blob_currentne$blob_parent) {4187print" | ".4188$cgi->a({-href => href(action=>"blobdiff",4189 hash=>$blob_current, hash_parent=>$blob_parent,4190 hash_base=>$hash_base, hash_parent_base=>$commit,4191 file_name=>$file_name)},4192"diff to current");4193}4194}4195print"</td>\n".4196"</tr>\n";4197}4198if(defined$extra) {4199print"<tr>\n".4200"<td colspan=\"4\">$extra</td>\n".4201"</tr>\n";4202}4203print"</table>\n";4204}42054206sub git_tags_body {4207# uses global variable $project4208my($taglist,$from,$to,$extra) =@_;4209$from=0unlessdefined$from;4210$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);42114212print"<table class=\"tags\">\n";4213my$alternate=1;4214for(my$i=$from;$i<=$to;$i++) {4215my$entry=$taglist->[$i];4216my%tag=%$entry;4217my$comment=$tag{'subject'};4218my$comment_short;4219if(defined$comment) {4220$comment_short= chop_str($comment,30,5);4221}4222if($alternate) {4223print"<tr class=\"dark\">\n";4224}else{4225print"<tr class=\"light\">\n";4226}4227$alternate^=1;4228if(defined$tag{'age'}) {4229print"<td><i>$tag{'age'}</i></td>\n";4230}else{4231print"<td></td>\n";4232}4233print"<td>".4234$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4235-class=>"list name"}, esc_html($tag{'name'})) .4236"</td>\n".4237"<td>";4238if(defined$comment) {4239print format_subject_html($comment,$comment_short,4240 href(action=>"tag", hash=>$tag{'id'}));4241}4242print"</td>\n".4243"<td class=\"selflink\">";4244if($tag{'type'}eq"tag") {4245print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4246}else{4247print" ";4248}4249print"</td>\n".4250"<td class=\"link\">"." | ".4251$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4252if($tag{'reftype'}eq"commit") {4253print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4254" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4255}elsif($tag{'reftype'}eq"blob") {4256print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4257}4258print"</td>\n".4259"</tr>";4260}4261if(defined$extra) {4262print"<tr>\n".4263"<td colspan=\"5\">$extra</td>\n".4264"</tr>\n";4265}4266print"</table>\n";4267}42684269sub git_heads_body {4270# uses global variable $project4271my($headlist,$head,$from,$to,$extra) =@_;4272$from=0unlessdefined$from;4273$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);42744275print"<table class=\"heads\">\n";4276my$alternate=1;4277for(my$i=$from;$i<=$to;$i++) {4278my$entry=$headlist->[$i];4279my%ref=%$entry;4280my$curr=$ref{'id'}eq$head;4281if($alternate) {4282print"<tr class=\"dark\">\n";4283}else{4284print"<tr class=\"light\">\n";4285}4286$alternate^=1;4287print"<td><i>$ref{'age'}</i></td>\n".4288($curr?"<td class=\"current_head\">":"<td>") .4289$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4290-class=>"list name"},esc_html($ref{'name'})) .4291"</td>\n".4292"<td class=\"link\">".4293$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4294$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4295$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4296"</td>\n".4297"</tr>";4298}4299if(defined$extra) {4300print"<tr>\n".4301"<td colspan=\"3\">$extra</td>\n".4302"</tr>\n";4303}4304print"</table>\n";4305}43064307sub git_search_grep_body {4308my($commitlist,$from,$to,$extra) =@_;4309$from=0unlessdefined$from;4310$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);43114312print"<table class=\"commit_search\">\n";4313my$alternate=1;4314for(my$i=$from;$i<=$to;$i++) {4315my%co= %{$commitlist->[$i]};4316if(!%co) {4317next;4318}4319my$commit=$co{'id'};4320if($alternate) {4321print"<tr class=\"dark\">\n";4322}else{4323print"<tr class=\"light\">\n";4324}4325$alternate^=1;4326my$author= chop_and_escape_str($co{'author_name'},15,5);4327print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4328"<td><i>".$author."</i></td>\n".4329"<td>".4330$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4331-class=>"list subject"},4332 chop_and_escape_str($co{'title'},50) ."<br/>");4333my$comment=$co{'comment'};4334foreachmy$line(@$comment) {4335if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4336my($lead,$match,$trail) = ($1,$2,$3);4337$match= chop_str($match,70,5,'center');4338my$contextlen=int((80-length($match))/2);4339$contextlen=30if($contextlen>30);4340$lead= chop_str($lead,$contextlen,10,'left');4341$trail= chop_str($trail,$contextlen,10,'right');43424343$lead= esc_html($lead);4344$match= esc_html($match);4345$trail= esc_html($trail);43464347print"$lead<span class=\"match\">$match</span>$trail<br />";4348}4349}4350print"</td>\n".4351"<td class=\"link\">".4352$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4353" | ".4354$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4355" | ".4356$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4357print"</td>\n".4358"</tr>\n";4359}4360if(defined$extra) {4361print"<tr>\n".4362"<td colspan=\"3\">$extra</td>\n".4363"</tr>\n";4364}4365print"</table>\n";4366}43674368## ======================================================================4369## ======================================================================4370## actions43714372sub git_project_list {4373my$order=$input_params{'order'};4374if(defined$order&&$order!~m/none|project|descr|owner|age/) {4375 die_error(400,"Unknown order parameter");4376}43774378my@list= git_get_projects_list();4379if(!@list) {4380 die_error(404,"No projects found");4381}43824383 git_header_html();4384if(-f $home_text) {4385print"<div class=\"index_include\">\n";4386 insert_file($home_text);4387print"</div>\n";4388}4389print$cgi->startform(-method=>"get") .4390"<p class=\"projsearch\">Search:\n".4391$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4392"</p>".4393$cgi->end_form() ."\n";4394 git_project_list_body(\@list,$order);4395 git_footer_html();4396}43974398sub git_forks {4399my$order=$input_params{'order'};4400if(defined$order&&$order!~m/none|project|descr|owner|age/) {4401 die_error(400,"Unknown order parameter");4402}44034404my@list= git_get_projects_list($project);4405if(!@list) {4406 die_error(404,"No forks found");4407}44084409 git_header_html();4410 git_print_page_nav('','');4411 git_print_header_div('summary',"$projectforks");4412 git_project_list_body(\@list,$order);4413 git_footer_html();4414}44154416sub git_project_index {4417my@projects= git_get_projects_list($project);44184419print$cgi->header(4420-type =>'text/plain',4421-charset =>'utf-8',4422-content_disposition =>'inline; filename="index.aux"');44234424foreachmy$pr(@projects) {4425if(!exists$pr->{'owner'}) {4426$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4427}44284429my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4430# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4431$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4432$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4433$path=~s/ /\+/g;4434$owner=~s/ /\+/g;44354436print"$path$owner\n";4437}4438}44394440sub git_summary {4441my$descr= git_get_project_description($project) ||"none";4442my%co= parse_commit("HEAD");4443my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4444my$head=$co{'id'};44454446my$owner= git_get_project_owner($project);44474448my$refs= git_get_references();4449# These get_*_list functions return one more to allow us to see if4450# there are more ...4451my@taglist= git_get_tags_list(16);4452my@headlist= git_get_heads_list(16);4453my@forklist;4454my$check_forks= gitweb_check_feature('forks');44554456if($check_forks) {4457@forklist= git_get_projects_list($project);4458}44594460 git_header_html();4461 git_print_page_nav('summary','',$head);44624463print"<div class=\"title\"> </div>\n";4464print"<table class=\"projects_list\">\n".4465"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4466"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4467if(defined$cd{'rfc2822'}) {4468print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4469}44704471# use per project git URL list in $projectroot/$project/cloneurl4472# or make project git URL from git base URL and project name4473my$url_tag="URL";4474my@url_list= git_get_project_url_list($project);4475@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4476foreachmy$git_url(@url_list) {4477next unless$git_url;4478print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4479$url_tag="";4480}44814482# Tag cloud4483my$show_ctags= gitweb_check_feature('ctags');4484if($show_ctags) {4485my$ctags= git_get_project_ctags($project);4486my$cloud= git_populate_project_tagcloud($ctags);4487print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4488print"</td>\n<td>"unless%$ctags;4489print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4490print"</td>\n<td>"if%$ctags;4491print git_show_project_tagcloud($cloud,48);4492print"</td></tr>";4493}44944495print"</table>\n";44964497if(-s "$projectroot/$project/README.html") {4498print"<div class=\"title\">readme</div>\n".4499"<div class=\"readme\">\n";4500 insert_file("$projectroot/$project/README.html");4501print"\n</div>\n";# class="readme"4502}45034504# we need to request one more than 16 (0..15) to check if4505# those 16 are all4506my@commitlist=$head? parse_commits($head,17) : ();4507if(@commitlist) {4508 git_print_header_div('shortlog');4509 git_shortlog_body(\@commitlist,0,15,$refs,4510$#commitlist<=15?undef:4511$cgi->a({-href => href(action=>"shortlog")},"..."));4512}45134514if(@taglist) {4515 git_print_header_div('tags');4516 git_tags_body(\@taglist,0,15,4517$#taglist<=15?undef:4518$cgi->a({-href => href(action=>"tags")},"..."));4519}45204521if(@headlist) {4522 git_print_header_div('heads');4523 git_heads_body(\@headlist,$head,0,15,4524$#headlist<=15?undef:4525$cgi->a({-href => href(action=>"heads")},"..."));4526}45274528if(@forklist) {4529 git_print_header_div('forks');4530 git_project_list_body(\@forklist,'age',0,15,4531$#forklist<=15?undef:4532$cgi->a({-href => href(action=>"forks")},"..."),4533'no_header');4534}45354536 git_footer_html();4537}45384539sub git_tag {4540my$head= git_get_head_hash($project);4541 git_header_html();4542 git_print_page_nav('','',$head,undef,$head);4543my%tag= parse_tag($hash);45444545if(!%tag) {4546 die_error(404,"Unknown tag object");4547}45484549 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4550print"<div class=\"title_text\">\n".4551"<table class=\"object_header\">\n".4552"<tr>\n".4553"<td>object</td>\n".4554"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4555$tag{'object'}) ."</td>\n".4556"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4557$tag{'type'}) ."</td>\n".4558"</tr>\n";4559if(defined($tag{'author'})) {4560my%ad= parse_date($tag{'epoch'},$tag{'tz'});4561print"<tr><td>author</td><td>". esc_html($tag{'author'}) ."</td></tr>\n";4562print"<tr><td></td><td>".$ad{'rfc2822'} .4563sprintf(" (%02d:%02d%s)",$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'}) .4564"</td></tr>\n";4565}4566print"</table>\n\n".4567"</div>\n";4568print"<div class=\"page_body\">";4569my$comment=$tag{'comment'};4570foreachmy$line(@$comment) {4571chomp$line;4572print esc_html($line, -nbsp=>1) ."<br/>\n";4573}4574print"</div>\n";4575 git_footer_html();4576}45774578sub git_blame {4579my$fd;4580my$ftype;45814582 gitweb_check_feature('blame')4583or die_error(403,"Blame view not allowed");45844585 die_error(400,"No file name given")unless$file_name;4586$hash_base||= git_get_head_hash($project);4587 die_error(404,"Couldn't find base commit")unless($hash_base);4588my%co= parse_commit($hash_base)4589or die_error(404,"Commit not found");4590if(!defined$hash) {4591$hash= git_get_hash_by_path($hash_base,$file_name,"blob")4592or die_error(404,"Error looking up file");4593}4594$ftype= git_get_type($hash);4595if($ftype!~"blob") {4596 die_error(400,"Object is not a blob");4597}4598open($fd,"-|", git_cmd(),"blame",'-p','--',4599$file_name,$hash_base)4600or die_error(500,"Open git-blame failed");4601 git_header_html();4602my$formats_nav=4603$cgi->a({-href => href(action=>"blob", -replay=>1)},4604"blob") .4605" | ".4606$cgi->a({-href => href(action=>"history", -replay=>1)},4607"history") .4608" | ".4609$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},4610"HEAD");4611 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4612 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4613 git_print_page_path($file_name,$ftype,$hash_base);4614my@rev_color= (qw(light2 dark2));4615my$num_colors=scalar(@rev_color);4616my$current_color=0;4617my$last_rev;4618print<<HTML;4619<div class="page_body">4620<table class="blame">4621<tr><th>Commit</th><th>Line</th><th>Data</th></tr>4622HTML4623my%metainfo= ();4624while(1) {4625$_= <$fd>;4626last unlessdefined$_;4627my($full_rev,$orig_lineno,$lineno,$group_size) =4628/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;4629if(!exists$metainfo{$full_rev}) {4630$metainfo{$full_rev} = {};4631}4632my$meta=$metainfo{$full_rev};4633while(<$fd>) {4634last if(s/^\t//);4635if(/^(\S+) (.*)$/) {4636$meta->{$1} =$2;4637}4638}4639my$data=$_;4640chomp$data;4641my$rev=substr($full_rev,0,8);4642my$author=$meta->{'author'};4643my%date= parse_date($meta->{'author-time'},4644$meta->{'author-tz'});4645my$date=$date{'iso-tz'};4646if($group_size) {4647$current_color= ++$current_color%$num_colors;4648}4649print"<tr class=\"$rev_color[$current_color]\">\n";4650if($group_size) {4651print"<td class=\"sha1\"";4652print" title=\"". esc_html($author) .",$date\"";4653print" rowspan=\"$group_size\""if($group_size>1);4654print">";4655print$cgi->a({-href => href(action=>"commit",4656 hash=>$full_rev,4657 file_name=>$file_name)},4658 esc_html($rev));4659print"</td>\n";4660}4661open(my$dd,"-|", git_cmd(),"rev-parse","$full_rev^")4662or die_error(500,"Open git-rev-parse failed");4663my$parent_commit= <$dd>;4664close$dd;4665chomp($parent_commit);4666my$blamed= href(action =>'blame',4667 file_name =>$meta->{'filename'},4668 hash_base =>$parent_commit);4669print"<td class=\"linenr\">";4670print$cgi->a({ -href =>"$blamed#l$orig_lineno",4671-id =>"l$lineno",4672-class=>"linenr"},4673 esc_html($lineno));4674print"</td>";4675print"<td class=\"pre\">". esc_html($data) ."</td>\n";4676print"</tr>\n";4677}4678print"</table>\n";4679print"</div>";4680close$fd4681or print"Reading blob failed\n";4682 git_footer_html();4683}46844685sub git_tags {4686my$head= git_get_head_hash($project);4687 git_header_html();4688 git_print_page_nav('','',$head,undef,$head);4689 git_print_header_div('summary',$project);46904691my@tagslist= git_get_tags_list();4692if(@tagslist) {4693 git_tags_body(\@tagslist);4694}4695 git_footer_html();4696}46974698sub git_heads {4699my$head= git_get_head_hash($project);4700 git_header_html();4701 git_print_page_nav('','',$head,undef,$head);4702 git_print_header_div('summary',$project);47034704my@headslist= git_get_heads_list();4705if(@headslist) {4706 git_heads_body(\@headslist,$head);4707}4708 git_footer_html();4709}47104711sub git_blob_plain {4712my$type=shift;4713my$expires;47144715if(!defined$hash) {4716if(defined$file_name) {4717my$base=$hash_base|| git_get_head_hash($project);4718$hash= git_get_hash_by_path($base,$file_name,"blob")4719or die_error(404,"Cannot find file");4720}else{4721 die_error(400,"No file name defined");4722}4723}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4724# blobs defined by non-textual hash id's can be cached4725$expires="+1d";4726}47274728open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4729or die_error(500,"Open git-cat-file blob '$hash' failed");47304731# content-type (can include charset)4732$type= blob_contenttype($fd,$file_name,$type);47334734# "save as" filename, even when no $file_name is given4735my$save_as="$hash";4736if(defined$file_name) {4737$save_as=$file_name;4738}elsif($type=~m/^text\//) {4739$save_as.='.txt';4740}47414742print$cgi->header(4743-type =>$type,4744-expires =>$expires,4745-content_disposition =>'inline; filename="'.$save_as.'"');4746undef$/;4747binmode STDOUT,':raw';4748print<$fd>;4749binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi4750$/="\n";4751close$fd;4752}47534754sub git_blob {4755my$expires;47564757if(!defined$hash) {4758if(defined$file_name) {4759my$base=$hash_base|| git_get_head_hash($project);4760$hash= git_get_hash_by_path($base,$file_name,"blob")4761or die_error(404,"Cannot find file");4762}else{4763 die_error(400,"No file name defined");4764}4765}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4766# blobs defined by non-textual hash id's can be cached4767$expires="+1d";4768}47694770my$have_blame= gitweb_check_feature('blame');4771open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4772or die_error(500,"Couldn't cat$file_name,$hash");4773my$mimetype= blob_mimetype($fd,$file_name);4774if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {4775close$fd;4776return git_blob_plain($mimetype);4777}4778# we can have blame only for text/* mimetype4779$have_blame&&= ($mimetype=~m!^text/!);47804781 git_header_html(undef,$expires);4782my$formats_nav='';4783if(defined$hash_base&& (my%co= parse_commit($hash_base))) {4784if(defined$file_name) {4785if($have_blame) {4786$formats_nav.=4787$cgi->a({-href => href(action=>"blame", -replay=>1)},4788"blame") .4789" | ";4790}4791$formats_nav.=4792$cgi->a({-href => href(action=>"history", -replay=>1)},4793"history") .4794" | ".4795$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},4796"raw") .4797" | ".4798$cgi->a({-href => href(action=>"blob",4799 hash_base=>"HEAD", file_name=>$file_name)},4800"HEAD");4801}else{4802$formats_nav.=4803$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},4804"raw");4805}4806 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4807 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4808}else{4809print"<div class=\"page_nav\">\n".4810"<br/><br/></div>\n".4811"<div class=\"title\">$hash</div>\n";4812}4813 git_print_page_path($file_name,"blob",$hash_base);4814print"<div class=\"page_body\">\n";4815if($mimetype=~m!^image/!) {4816print qq!<img type="$mimetype"!;4817if($file_name) {4818print qq! alt="$file_name" title="$file_name"!;4819}4820print qq! src="! .4821 href(action=>"blob_plain", hash=>$hash,4822 hash_base=>$hash_base, file_name=>$file_name) .4823 qq!"/>\n!;4824}else{4825my$nr;4826while(my$line= <$fd>) {4827chomp$line;4828$nr++;4829$line= untabify($line);4830printf"<div class=\"pre\"><a id=\"l%i\"href=\"#l%i\"class=\"linenr\">%4i</a>%s</div>\n",4831$nr,$nr,$nr, esc_html($line, -nbsp=>1);4832}4833}4834close$fd4835or print"Reading blob failed.\n";4836print"</div>";4837 git_footer_html();4838}48394840sub git_tree {4841if(!defined$hash_base) {4842$hash_base="HEAD";4843}4844if(!defined$hash) {4845if(defined$file_name) {4846$hash= git_get_hash_by_path($hash_base,$file_name,"tree");4847}else{4848$hash=$hash_base;4849}4850}4851 die_error(404,"No such tree")unlessdefined($hash);4852$/="\0";4853open my$fd,"-|", git_cmd(),"ls-tree",'-z',$hash4854or die_error(500,"Open git-ls-tree failed");4855my@entries=map{chomp;$_} <$fd>;4856close$fdor die_error(404,"Reading tree failed");4857$/="\n";48584859my$refs= git_get_references();4860my$ref= format_ref_marker($refs,$hash_base);4861 git_header_html();4862my$basedir='';4863my$have_blame= gitweb_check_feature('blame');4864if(defined$hash_base&& (my%co= parse_commit($hash_base))) {4865my@views_nav= ();4866if(defined$file_name) {4867push@views_nav,4868$cgi->a({-href => href(action=>"history", -replay=>1)},4869"history"),4870$cgi->a({-href => href(action=>"tree",4871 hash_base=>"HEAD", file_name=>$file_name)},4872"HEAD"),4873}4874my$snapshot_links= format_snapshot_links($hash);4875if(defined$snapshot_links) {4876# FIXME: Should be available when we have no hash base as well.4877push@views_nav,$snapshot_links;4878}4879 git_print_page_nav('tree','',$hash_base,undef,undef,join(' | ',@views_nav));4880 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);4881}else{4882undef$hash_base;4883print"<div class=\"page_nav\">\n";4884print"<br/><br/></div>\n";4885print"<div class=\"title\">$hash</div>\n";4886}4887if(defined$file_name) {4888$basedir=$file_name;4889if($basedirne''&&substr($basedir, -1)ne'/') {4890$basedir.='/';4891}4892 git_print_page_path($file_name,'tree',$hash_base);4893}4894print"<div class=\"page_body\">\n";4895print"<table class=\"tree\">\n";4896my$alternate=1;4897# '..' (top directory) link if possible4898if(defined$hash_base&&4899defined$file_name&&$file_name=~m![^/]+$!) {4900if($alternate) {4901print"<tr class=\"dark\">\n";4902}else{4903print"<tr class=\"light\">\n";4904}4905$alternate^=1;49064907my$up=$file_name;4908$up=~s!/?[^/]+$!!;4909undef$upunless$up;4910# based on git_print_tree_entry4911print'<td class="mode">'. mode_str('040000') ."</td>\n";4912print'<td class="list">';4913print$cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,4914 file_name=>$up)},4915"..");4916print"</td>\n";4917print"<td class=\"link\"></td>\n";49184919print"</tr>\n";4920}4921foreachmy$line(@entries) {4922my%t= parse_ls_tree_line($line, -z =>1);49234924if($alternate) {4925print"<tr class=\"dark\">\n";4926}else{4927print"<tr class=\"light\">\n";4928}4929$alternate^=1;49304931 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);49324933print"</tr>\n";4934}4935print"</table>\n".4936"</div>";4937 git_footer_html();4938}49394940sub git_snapshot {4941my$format=$input_params{'snapshot_format'};4942if(!@snapshot_fmts) {4943 die_error(403,"Snapshots not allowed");4944}4945# default to first supported snapshot format4946$format||=$snapshot_fmts[0];4947if($format!~m/^[a-z0-9]+$/) {4948 die_error(400,"Invalid snapshot format parameter");4949}elsif(!exists($known_snapshot_formats{$format})) {4950 die_error(400,"Unknown snapshot format");4951}elsif(!grep($_eq$format,@snapshot_fmts)) {4952 die_error(403,"Unsupported snapshot format");4953}49544955if(!defined$hash) {4956$hash= git_get_head_hash($project);4957}49584959my$name=$project;4960$name=~ s,([^/])/*\.git$,$1,;4961$name= basename($name);4962my$filename= to_utf8($name);4963$name=~s/\047/\047\\\047\047/g;4964my$cmd;4965$filename.="-$hash$known_snapshot_formats{$format}{'suffix'}";4966$cmd= quote_command(4967 git_cmd(),'archive',4968"--format=$known_snapshot_formats{$format}{'format'}",4969"--prefix=$name/",$hash);4970if(exists$known_snapshot_formats{$format}{'compressor'}) {4971$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});4972}49734974print$cgi->header(4975-type =>$known_snapshot_formats{$format}{'type'},4976-content_disposition =>'inline; filename="'."$filename".'"',4977-status =>'200 OK');49784979open my$fd,"-|",$cmd4980or die_error(500,"Execute git-archive failed");4981binmode STDOUT,':raw';4982print<$fd>;4983binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi4984close$fd;4985}49864987sub git_log {4988my$head= git_get_head_hash($project);4989if(!defined$hash) {4990$hash=$head;4991}4992if(!defined$page) {4993$page=0;4994}4995my$refs= git_get_references();49964997my@commitlist= parse_commits($hash,101, (100*$page));49984999my$paging_nav= format_paging_nav('log',$hash,$head,$page,$#commitlist>=100);50005001 git_header_html();5002 git_print_page_nav('log','',$hash,undef,undef,$paging_nav);50035004if(!@commitlist) {5005my%co= parse_commit($hash);50065007 git_print_header_div('summary',$project);5008print"<div class=\"page_body\"> Last change$co{'age_string'}.<br/><br/></div>\n";5009}5010my$to= ($#commitlist>=99) ? (99) : ($#commitlist);5011for(my$i=0;$i<=$to;$i++) {5012my%co= %{$commitlist[$i]};5013next if!%co;5014my$commit=$co{'id'};5015my$ref= format_ref_marker($refs,$commit);5016my%ad= parse_date($co{'author_epoch'});5017 git_print_header_div('commit',5018"<span class=\"age\">$co{'age_string'}</span>".5019 esc_html($co{'title'}) .$ref,5020$commit);5021print"<div class=\"title_text\">\n".5022"<div class=\"log_link\">\n".5023$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .5024" | ".5025$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .5026" | ".5027$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .5028"<br/>\n".5029"</div>\n".5030"<i>". esc_html($co{'author_name'}) ." [$ad{'rfc2822'}]</i><br/>\n".5031"</div>\n";50325033print"<div class=\"log_body\">\n";5034 git_print_log($co{'comment'}, -final_empty_line=>1);5035print"</div>\n";5036}5037if($#commitlist>=100) {5038print"<div class=\"page_nav\">\n";5039print$cgi->a({-href => href(-replay=>1, page=>$page+1),5040-accesskey =>"n", -title =>"Alt-n"},"next");5041print"</div>\n";5042}5043 git_footer_html();5044}50455046sub git_commit {5047$hash||=$hash_base||"HEAD";5048my%co= parse_commit($hash)5049or die_error(404,"Unknown commit object");5050my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5051my%cd= parse_date($co{'committer_epoch'},$co{'committer_tz'});50525053my$parent=$co{'parent'};5054my$parents=$co{'parents'};# listref50555056# we need to prepare $formats_nav before any parameter munging5057my$formats_nav;5058if(!defined$parent) {5059# --root commitdiff5060$formats_nav.='(initial)';5061}elsif(@$parents==1) {5062# single parent commit5063$formats_nav.=5064'(parent: '.5065$cgi->a({-href => href(action=>"commit",5066 hash=>$parent)},5067 esc_html(substr($parent,0,7))) .5068')';5069}else{5070# merge commit5071$formats_nav.=5072'(merge: '.5073join(' ',map{5074$cgi->a({-href => href(action=>"commit",5075 hash=>$_)},5076 esc_html(substr($_,0,7)));5077}@$parents) .5078')';5079}50805081if(!defined$parent) {5082$parent="--root";5083}5084my@difftree;5085open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5086@diff_opts,5087(@$parents<=1?$parent:'-c'),5088$hash,"--"5089or die_error(500,"Open git-diff-tree failed");5090@difftree=map{chomp;$_} <$fd>;5091close$fdor die_error(404,"Reading git-diff-tree failed");50925093# non-textual hash id's can be cached5094my$expires;5095if($hash=~m/^[0-9a-fA-F]{40}$/) {5096$expires="+1d";5097}5098my$refs= git_get_references();5099my$ref= format_ref_marker($refs,$co{'id'});51005101 git_header_html(undef,$expires);5102 git_print_page_nav('commit','',5103$hash,$co{'tree'},$hash,5104$formats_nav);51055106if(defined$co{'parent'}) {5107 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5108}else{5109 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5110}5111print"<div class=\"title_text\">\n".5112"<table class=\"object_header\">\n";5113print"<tr><td>author</td><td>". esc_html($co{'author'}) ."</td></tr>\n".5114"<tr>".5115"<td></td><td>$ad{'rfc2822'}";5116if($ad{'hour_local'} <6) {5117printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",5118$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});5119}else{5120printf(" (%02d:%02d%s)",5121$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});5122}5123print"</td>".5124"</tr>\n";5125print"<tr><td>committer</td><td>". esc_html($co{'committer'}) ."</td></tr>\n";5126print"<tr><td></td><td>$cd{'rfc2822'}".5127sprintf(" (%02d:%02d%s)",$cd{'hour_local'},$cd{'minute_local'},$cd{'tz_local'}) .5128"</td></tr>\n";5129print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";5130print"<tr>".5131"<td>tree</td>".5132"<td class=\"sha1\">".5133$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),5134class=>"list"},$co{'tree'}) .5135"</td>".5136"<td class=\"link\">".5137$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},5138"tree");5139my$snapshot_links= format_snapshot_links($hash);5140if(defined$snapshot_links) {5141print" | ".$snapshot_links;5142}5143print"</td>".5144"</tr>\n";51455146foreachmy$par(@$parents) {5147print"<tr>".5148"<td>parent</td>".5149"<td class=\"sha1\">".5150$cgi->a({-href => href(action=>"commit", hash=>$par),5151class=>"list"},$par) .5152"</td>".5153"<td class=\"link\">".5154$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .5155" | ".5156$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .5157"</td>".5158"</tr>\n";5159}5160print"</table>".5161"</div>\n";51625163print"<div class=\"page_body\">\n";5164 git_print_log($co{'comment'});5165print"</div>\n";51665167 git_difftree_body(\@difftree,$hash,@$parents);51685169 git_footer_html();5170}51715172sub git_object {5173# object is defined by:5174# - hash or hash_base alone5175# - hash_base and file_name5176my$type;51775178# - hash or hash_base alone5179if($hash|| ($hash_base&& !defined$file_name)) {5180my$object_id=$hash||$hash_base;51815182open my$fd,"-|", quote_command(5183 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'5184or die_error(404,"Object does not exist");5185$type= <$fd>;5186chomp$type;5187close$fd5188or die_error(404,"Object does not exist");51895190# - hash_base and file_name5191}elsif($hash_base&&defined$file_name) {5192$file_name=~ s,/+$,,;51935194system(git_cmd(),"cat-file",'-e',$hash_base) ==05195or die_error(404,"Base object does not exist");51965197# here errors should not hapen5198open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name5199or die_error(500,"Open git-ls-tree failed");5200my$line= <$fd>;5201close$fd;52025203#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'5204unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {5205 die_error(404,"File or directory for given base does not exist");5206}5207$type=$2;5208$hash=$3;5209}else{5210 die_error(400,"Not enough information to find object");5211}52125213print$cgi->redirect(-uri => href(action=>$type, -full=>1,5214 hash=>$hash, hash_base=>$hash_base,5215 file_name=>$file_name),5216-status =>'302 Found');5217}52185219sub git_blobdiff {5220my$format=shift||'html';52215222my$fd;5223my@difftree;5224my%diffinfo;5225my$expires;52265227# preparing $fd and %diffinfo for git_patchset_body5228# new style URI5229if(defined$hash_base&&defined$hash_parent_base) {5230if(defined$file_name) {5231# read raw output5232open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5233$hash_parent_base,$hash_base,5234"--", (defined$file_parent?$file_parent: ()),$file_name5235or die_error(500,"Open git-diff-tree failed");5236@difftree=map{chomp;$_} <$fd>;5237close$fd5238or die_error(404,"Reading git-diff-tree failed");5239@difftree5240or die_error(404,"Blob diff not found");52415242}elsif(defined$hash&&5243$hash=~/[0-9a-fA-F]{40}/) {5244# try to find filename from $hash52455246# read filtered raw output5247open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5248$hash_parent_base,$hash_base,"--"5249or die_error(500,"Open git-diff-tree failed");5250@difftree=5251# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5252# $hash == to_id5253grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5254map{chomp;$_} <$fd>;5255close$fd5256or die_error(404,"Reading git-diff-tree failed");5257@difftree5258or die_error(404,"Blob diff not found");52595260}else{5261 die_error(400,"Missing one of the blob diff parameters");5262}52635264if(@difftree>1) {5265 die_error(400,"Ambiguous blob diff specification");5266}52675268%diffinfo= parse_difftree_raw_line($difftree[0]);5269$file_parent||=$diffinfo{'from_file'} ||$file_name;5270$file_name||=$diffinfo{'to_file'};52715272$hash_parent||=$diffinfo{'from_id'};5273$hash||=$diffinfo{'to_id'};52745275# non-textual hash id's can be cached5276if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5277$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5278$expires='+1d';5279}52805281# open patch output5282open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5283'-p', ($formateq'html'?"--full-index": ()),5284$hash_parent_base,$hash_base,5285"--", (defined$file_parent?$file_parent: ()),$file_name5286or die_error(500,"Open git-diff-tree failed");5287}52885289# old/legacy style URI -- not generated anymore since 1.4.3.5290if(!%diffinfo) {5291 die_error('404 Not Found',"Missing one of the blob diff parameters")5292}52935294# header5295if($formateq'html') {5296my$formats_nav=5297$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5298"raw");5299 git_header_html(undef,$expires);5300if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5301 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5302 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5303}else{5304print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5305print"<div class=\"title\">$hashvs$hash_parent</div>\n";5306}5307if(defined$file_name) {5308 git_print_page_path($file_name,"blob",$hash_base);5309}else{5310print"<div class=\"page_path\"></div>\n";5311}53125313}elsif($formateq'plain') {5314print$cgi->header(5315-type =>'text/plain',5316-charset =>'utf-8',5317-expires =>$expires,5318-content_disposition =>'inline; filename="'."$file_name".'.patch"');53195320print"X-Git-Url: ".$cgi->self_url() ."\n\n";53215322}else{5323 die_error(400,"Unknown blobdiff format");5324}53255326# patch5327if($formateq'html') {5328print"<div class=\"page_body\">\n";53295330 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5331close$fd;53325333print"</div>\n";# class="page_body"5334 git_footer_html();53355336}else{5337while(my$line= <$fd>) {5338$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5339$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;53405341print$line;53425343last if$line=~m!^\+\+\+!;5344}5345local$/=undef;5346print<$fd>;5347close$fd;5348}5349}53505351sub git_blobdiff_plain {5352 git_blobdiff('plain');5353}53545355sub git_commitdiff {5356my$format=shift||'html';5357$hash||=$hash_base||"HEAD";5358my%co= parse_commit($hash)5359or die_error(404,"Unknown commit object");53605361# choose format for commitdiff for merge5362if(!defined$hash_parent&& @{$co{'parents'}} >1) {5363$hash_parent='--cc';5364}5365# we need to prepare $formats_nav before almost any parameter munging5366my$formats_nav;5367if($formateq'html') {5368$formats_nav=5369$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},5370"raw");53715372if(defined$hash_parent&&5373$hash_parentne'-c'&&$hash_parentne'--cc') {5374# commitdiff with two commits given5375my$hash_parent_short=$hash_parent;5376if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {5377$hash_parent_short=substr($hash_parent,0,7);5378}5379$formats_nav.=5380' (from';5381for(my$i=0;$i< @{$co{'parents'}};$i++) {5382if($co{'parents'}[$i]eq$hash_parent) {5383$formats_nav.=' parent '. ($i+1);5384last;5385}5386}5387$formats_nav.=': '.5388$cgi->a({-href => href(action=>"commitdiff",5389 hash=>$hash_parent)},5390 esc_html($hash_parent_short)) .5391')';5392}elsif(!$co{'parent'}) {5393# --root commitdiff5394$formats_nav.=' (initial)';5395}elsif(scalar@{$co{'parents'}} ==1) {5396# single parent commit5397$formats_nav.=5398' (parent: '.5399$cgi->a({-href => href(action=>"commitdiff",5400 hash=>$co{'parent'})},5401 esc_html(substr($co{'parent'},0,7))) .5402')';5403}else{5404# merge commit5405if($hash_parenteq'--cc') {5406$formats_nav.=' | '.5407$cgi->a({-href => href(action=>"commitdiff",5408 hash=>$hash, hash_parent=>'-c')},5409'combined');5410}else{# $hash_parent eq '-c'5411$formats_nav.=' | '.5412$cgi->a({-href => href(action=>"commitdiff",5413 hash=>$hash, hash_parent=>'--cc')},5414'compact');5415}5416$formats_nav.=5417' (merge: '.5418join(' ',map{5419$cgi->a({-href => href(action=>"commitdiff",5420 hash=>$_)},5421 esc_html(substr($_,0,7)));5422} @{$co{'parents'}} ) .5423')';5424}5425}54265427my$hash_parent_param=$hash_parent;5428if(!defined$hash_parent_param) {5429# --cc for multiple parents, --root for parentless5430$hash_parent_param=5431@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';5432}54335434# read commitdiff5435my$fd;5436my@difftree;5437if($formateq'html') {5438open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5439"--no-commit-id","--patch-with-raw","--full-index",5440$hash_parent_param,$hash,"--"5441or die_error(500,"Open git-diff-tree failed");54425443while(my$line= <$fd>) {5444chomp$line;5445# empty line ends raw part of diff-tree output5446last unless$line;5447push@difftree,scalar parse_difftree_raw_line($line);5448}54495450}elsif($formateq'plain') {5451open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5452'-p',$hash_parent_param,$hash,"--"5453or die_error(500,"Open git-diff-tree failed");54545455}else{5456 die_error(400,"Unknown commitdiff format");5457}54585459# non-textual hash id's can be cached5460my$expires;5461if($hash=~m/^[0-9a-fA-F]{40}$/) {5462$expires="+1d";5463}54645465# write commit message5466if($formateq'html') {5467my$refs= git_get_references();5468my$ref= format_ref_marker($refs,$co{'id'});54695470 git_header_html(undef,$expires);5471 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);5472 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);5473 git_print_authorship(\%co);5474print"<div class=\"page_body\">\n";5475if(@{$co{'comment'}} >1) {5476print"<div class=\"log\">\n";5477 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);5478print"</div>\n";# class="log"5479}54805481}elsif($formateq'plain') {5482my$refs= git_get_references("tags");5483my$tagname= git_get_rev_name_tags($hash);5484my$filename= basename($project) ."-$hash.patch";54855486print$cgi->header(5487-type =>'text/plain',5488-charset =>'utf-8',5489-expires =>$expires,5490-content_disposition =>'inline; filename="'."$filename".'"');5491my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5492print"From: ". to_utf8($co{'author'}) ."\n";5493print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";5494print"Subject: ". to_utf8($co{'title'}) ."\n";54955496print"X-Git-Tag:$tagname\n"if$tagname;5497print"X-Git-Url: ".$cgi->self_url() ."\n\n";54985499foreachmy$line(@{$co{'comment'}}) {5500print to_utf8($line) ."\n";5501}5502print"---\n\n";5503}55045505# write patch5506if($formateq'html') {5507my$use_parents= !defined$hash_parent||5508$hash_parenteq'-c'||$hash_parenteq'--cc';5509 git_difftree_body(\@difftree,$hash,5510$use_parents? @{$co{'parents'}} :$hash_parent);5511print"<br/>\n";55125513 git_patchset_body($fd, \@difftree,$hash,5514$use_parents? @{$co{'parents'}} :$hash_parent);5515close$fd;5516print"</div>\n";# class="page_body"5517 git_footer_html();55185519}elsif($formateq'plain') {5520local$/=undef;5521print<$fd>;5522close$fd5523or print"Reading git-diff-tree failed\n";5524}5525}55265527sub git_commitdiff_plain {5528 git_commitdiff('plain');5529}55305531sub git_history {5532if(!defined$hash_base) {5533$hash_base= git_get_head_hash($project);5534}5535if(!defined$page) {5536$page=0;5537}5538my$ftype;5539my%co= parse_commit($hash_base)5540or die_error(404,"Unknown commit object");55415542my$refs= git_get_references();5543my$limit=sprintf("--max-count=%i", (100* ($page+1)));55445545my@commitlist= parse_commits($hash_base,101, (100*$page),5546$file_name,"--full-history")5547or die_error(404,"No such file or directory on given branch");55485549if(!defined$hash&&defined$file_name) {5550# some commits could have deleted file in question,5551# and not have it in tree, but one of them has to have it5552for(my$i=0;$i<=@commitlist;$i++) {5553$hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5554last ifdefined$hash;5555}5556}5557if(defined$hash) {5558$ftype= git_get_type($hash);5559}5560if(!defined$ftype) {5561 die_error(500,"Unknown type of object");5562}55635564my$paging_nav='';5565if($page>0) {5566$paging_nav.=5567$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,5568 file_name=>$file_name)},5569"first");5570$paging_nav.=" ⋅ ".5571$cgi->a({-href => href(-replay=>1, page=>$page-1),5572-accesskey =>"p", -title =>"Alt-p"},"prev");5573}else{5574$paging_nav.="first";5575$paging_nav.=" ⋅ prev";5576}5577my$next_link='';5578if($#commitlist>=100) {5579$next_link=5580$cgi->a({-href => href(-replay=>1, page=>$page+1),5581-accesskey =>"n", -title =>"Alt-n"},"next");5582$paging_nav.=" ⋅$next_link";5583}else{5584$paging_nav.=" ⋅ next";5585}55865587 git_header_html();5588 git_print_page_nav('history','',$hash_base,$co{'tree'},$hash_base,$paging_nav);5589 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5590 git_print_page_path($file_name,$ftype,$hash_base);55915592 git_history_body(\@commitlist,0,99,5593$refs,$hash_base,$ftype,$next_link);55945595 git_footer_html();5596}55975598sub git_search {5599 gitweb_check_feature('search')or die_error(403,"Search is disabled");5600if(!defined$searchtext) {5601 die_error(400,"Text field is empty");5602}5603if(!defined$hash) {5604$hash= git_get_head_hash($project);5605}5606my%co= parse_commit($hash);5607if(!%co) {5608 die_error(404,"Unknown commit object");5609}5610if(!defined$page) {5611$page=0;5612}56135614$searchtype||='commit';5615if($searchtypeeq'pickaxe') {5616# pickaxe may take all resources of your box and run for several minutes5617# with every query - so decide by yourself how public you make this feature5618 gitweb_check_feature('pickaxe')5619or die_error(403,"Pickaxe is disabled");5620}5621if($searchtypeeq'grep') {5622 gitweb_check_feature('grep')5623or die_error(403,"Grep is disabled");5624}56255626 git_header_html();56275628if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {5629my$greptype;5630if($searchtypeeq'commit') {5631$greptype="--grep=";5632}elsif($searchtypeeq'author') {5633$greptype="--author=";5634}elsif($searchtypeeq'committer') {5635$greptype="--committer=";5636}5637$greptype.=$searchtext;5638my@commitlist= parse_commits($hash,101, (100*$page),undef,5639$greptype,'--regexp-ignore-case',5640$search_use_regexp?'--extended-regexp':'--fixed-strings');56415642my$paging_nav='';5643if($page>0) {5644$paging_nav.=5645$cgi->a({-href => href(action=>"search", hash=>$hash,5646 searchtext=>$searchtext,5647 searchtype=>$searchtype)},5648"first");5649$paging_nav.=" ⋅ ".5650$cgi->a({-href => href(-replay=>1, page=>$page-1),5651-accesskey =>"p", -title =>"Alt-p"},"prev");5652}else{5653$paging_nav.="first";5654$paging_nav.=" ⋅ prev";5655}5656my$next_link='';5657if($#commitlist>=100) {5658$next_link=5659$cgi->a({-href => href(-replay=>1, page=>$page+1),5660-accesskey =>"n", -title =>"Alt-n"},"next");5661$paging_nav.=" ⋅$next_link";5662}else{5663$paging_nav.=" ⋅ next";5664}56655666if($#commitlist>=100) {5667}56685669 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);5670 git_print_header_div('commit', esc_html($co{'title'}),$hash);5671 git_search_grep_body(\@commitlist,0,99,$next_link);5672}56735674if($searchtypeeq'pickaxe') {5675 git_print_page_nav('','',$hash,$co{'tree'},$hash);5676 git_print_header_div('commit', esc_html($co{'title'}),$hash);56775678print"<table class=\"pickaxe search\">\n";5679my$alternate=1;5680$/="\n";5681open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,5682'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",5683($search_use_regexp?'--pickaxe-regex': ());5684undef%co;5685my@files;5686while(my$line= <$fd>) {5687chomp$line;5688next unless$line;56895690my%set= parse_difftree_raw_line($line);5691if(defined$set{'commit'}) {5692# finish previous commit5693if(%co) {5694print"</td>\n".5695"<td class=\"link\">".5696$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5697" | ".5698$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5699print"</td>\n".5700"</tr>\n";5701}57025703if($alternate) {5704print"<tr class=\"dark\">\n";5705}else{5706print"<tr class=\"light\">\n";5707}5708$alternate^=1;5709%co= parse_commit($set{'commit'});5710my$author= chop_and_escape_str($co{'author_name'},15,5);5711print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5712"<td><i>$author</i></td>\n".5713"<td>".5714$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),5715-class=>"list subject"},5716 chop_and_escape_str($co{'title'},50) ."<br/>");5717}elsif(defined$set{'to_id'}) {5718next if($set{'to_id'} =~m/^0{40}$/);57195720print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},5721 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),5722-class=>"list"},5723"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .5724"<br/>\n";5725}5726}5727close$fd;57285729# finish last commit (warning: repetition!)5730if(%co) {5731print"</td>\n".5732"<td class=\"link\">".5733$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5734" | ".5735$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5736print"</td>\n".5737"</tr>\n";5738}57395740print"</table>\n";5741}57425743if($searchtypeeq'grep') {5744 git_print_page_nav('','',$hash,$co{'tree'},$hash);5745 git_print_header_div('commit', esc_html($co{'title'}),$hash);57465747print"<table class=\"grep_search\">\n";5748my$alternate=1;5749my$matches=0;5750$/="\n";5751open my$fd,"-|", git_cmd(),'grep','-n',5752$search_use_regexp? ('-E','-i') :'-F',5753$searchtext,$co{'tree'};5754my$lastfile='';5755while(my$line= <$fd>) {5756chomp$line;5757my($file,$lno,$ltext,$binary);5758last if($matches++>1000);5759if($line=~/^Binary file (.+) matches$/) {5760$file=$1;5761$binary=1;5762}else{5763(undef,$file,$lno,$ltext) =split(/:/,$line,4);5764}5765if($filene$lastfile) {5766$lastfileand print"</td></tr>\n";5767if($alternate++) {5768print"<tr class=\"dark\">\n";5769}else{5770print"<tr class=\"light\">\n";5771}5772print"<td class=\"list\">".5773$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5774 file_name=>"$file"),5775-class=>"list"}, esc_path($file));5776print"</td><td>\n";5777$lastfile=$file;5778}5779if($binary) {5780print"<div class=\"binary\">Binary file</div>\n";5781}else{5782$ltext= untabify($ltext);5783if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {5784$ltext= esc_html($1, -nbsp=>1);5785$ltext.='<span class="match">';5786$ltext.= esc_html($2, -nbsp=>1);5787$ltext.='</span>';5788$ltext.= esc_html($3, -nbsp=>1);5789}else{5790$ltext= esc_html($ltext, -nbsp=>1);5791}5792print"<div class=\"pre\">".5793$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5794 file_name=>"$file").'#l'.$lno,5795-class=>"linenr"},sprintf('%4i',$lno))5796.' '.$ltext."</div>\n";5797}5798}5799if($lastfile) {5800print"</td></tr>\n";5801if($matches>1000) {5802print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";5803}5804}else{5805print"<div class=\"diff nodifferences\">No matches found</div>\n";5806}5807close$fd;58085809print"</table>\n";5810}5811 git_footer_html();5812}58135814sub git_search_help {5815 git_header_html();5816 git_print_page_nav('','',$hash,$hash,$hash);5817print<<EOT;5818<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without5819regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,5820the pattern entered is recognized as the POSIX extended5821<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case5822insensitive).</p>5823<dl>5824<dt><b>commit</b></dt>5825<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>5826EOT5827my$have_grep= gitweb_check_feature('grep');5828if($have_grep) {5829print<<EOT;5830<dt><b>grep</b></dt>5831<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing5832 a different one) are searched for the given pattern. On large trees, this search can take5833a while and put some strain on the server, so please use it with some consideration. Note that5834due to git-grep peculiarity, currently if regexp mode is turned off, the matches are5835case-sensitive.</dd>5836EOT5837}5838print<<EOT;5839<dt><b>author</b></dt>5840<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>5841<dt><b>committer</b></dt>5842<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>5843EOT5844my$have_pickaxe= gitweb_check_feature('pickaxe');5845if($have_pickaxe) {5846print<<EOT;5847<dt><b>pickaxe</b></dt>5848<dd>All commits that caused the string to appear or disappear from any file (changes that5849added, removed or "modified" the string) will be listed. This search can take a while and5850takes a lot of strain on the server, so please use it wisely. Note that since you may be5851interested even in changes just changing the case as well, this search is case sensitive.</dd>5852EOT5853}5854print"</dl>\n";5855 git_footer_html();5856}58575858sub git_shortlog {5859my$head= git_get_head_hash($project);5860if(!defined$hash) {5861$hash=$head;5862}5863if(!defined$page) {5864$page=0;5865}5866my$refs= git_get_references();58675868my$commit_hash=$hash;5869if(defined$hash_parent) {5870$commit_hash="$hash_parent..$hash";5871}5872my@commitlist= parse_commits($commit_hash,101, (100*$page));58735874my$paging_nav= format_paging_nav('shortlog',$hash,$head,$page,$#commitlist>=100);5875my$next_link='';5876if($#commitlist>=100) {5877$next_link=5878$cgi->a({-href => href(-replay=>1, page=>$page+1),5879-accesskey =>"n", -title =>"Alt-n"},"next");5880}58815882 git_header_html();5883 git_print_page_nav('shortlog','',$hash,$hash,$hash,$paging_nav);5884 git_print_header_div('summary',$project);58855886 git_shortlog_body(\@commitlist,0,99,$refs,$next_link);58875888 git_footer_html();5889}58905891## ......................................................................5892## feeds (RSS, Atom; OPML)58935894sub git_feed {5895my$format=shift||'atom';5896my$have_blame= gitweb_check_feature('blame');58975898# Atom: http://www.atomenabled.org/developers/syndication/5899# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ5900if($formatne'rss'&&$formatne'atom') {5901 die_error(400,"Unknown web feed format");5902}59035904# log/feed of current (HEAD) branch, log of given branch, history of file/directory5905my$head=$hash||'HEAD';5906my@commitlist= parse_commits($head,150,0,$file_name);59075908my%latest_commit;5909my%latest_date;5910my$content_type="application/$format+xml";5911if(defined$cgi->http('HTTP_ACCEPT') &&5912$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {5913# browser (feed reader) prefers text/xml5914$content_type='text/xml';5915}5916if(defined($commitlist[0])) {5917%latest_commit= %{$commitlist[0]};5918%latest_date= parse_date($latest_commit{'author_epoch'});5919print$cgi->header(5920-type =>$content_type,5921-charset =>'utf-8',5922-last_modified =>$latest_date{'rfc2822'});5923}else{5924print$cgi->header(5925-type =>$content_type,5926-charset =>'utf-8');5927}59285929# Optimization: skip generating the body if client asks only5930# for Last-Modified date.5931return if($cgi->request_method()eq'HEAD');59325933# header variables5934my$title="$site_name-$project/$action";5935my$feed_type='log';5936if(defined$hash) {5937$title.=" - '$hash'";5938$feed_type='branch log';5939if(defined$file_name) {5940$title.=" ::$file_name";5941$feed_type='history';5942}5943}elsif(defined$file_name) {5944$title.=" -$file_name";5945$feed_type='history';5946}5947$title.="$feed_type";5948my$descr= git_get_project_description($project);5949if(defined$descr) {5950$descr= esc_html($descr);5951}else{5952$descr="$project".5953($formateq'rss'?'RSS':'Atom') .5954" feed";5955}5956my$owner= git_get_project_owner($project);5957$owner= esc_html($owner);59585959#header5960my$alt_url;5961if(defined$file_name) {5962$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);5963}elsif(defined$hash) {5964$alt_url= href(-full=>1, action=>"log", hash=>$hash);5965}else{5966$alt_url= href(-full=>1, action=>"summary");5967}5968print qq!<?xml version="1.0" encoding="utf-8"?>\n!;5969if($formateq'rss') {5970print<<XML;5971<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">5972<channel>5973XML5974print"<title>$title</title>\n".5975"<link>$alt_url</link>\n".5976"<description>$descr</description>\n".5977"<language>en</language>\n";5978}elsif($formateq'atom') {5979print<<XML;5980<feed xmlns="http://www.w3.org/2005/Atom">5981XML5982print"<title>$title</title>\n".5983"<subtitle>$descr</subtitle>\n".5984'<link rel="alternate" type="text/html" href="'.5985$alt_url.'" />'."\n".5986'<link rel="self" type="'.$content_type.'" href="'.5987$cgi->self_url() .'" />'."\n".5988"<id>". href(-full=>1) ."</id>\n".5989# use project owner for feed author5990"<author><name>$owner</name></author>\n";5991if(defined$favicon) {5992print"<icon>". esc_url($favicon) ."</icon>\n";5993}5994if(defined$logo_url) {5995# not twice as wide as tall: 72 x 27 pixels5996print"<logo>". esc_url($logo) ."</logo>\n";5997}5998if(!%latest_date) {5999# dummy date to keep the feed valid until commits trickle in:6000print"<updated>1970-01-01T00:00:00Z</updated>\n";6001}else{6002print"<updated>$latest_date{'iso-8601'}</updated>\n";6003}6004}60056006# contents6007for(my$i=0;$i<=$#commitlist;$i++) {6008my%co= %{$commitlist[$i]};6009my$commit=$co{'id'};6010# we read 150, we always show 30 and the ones more recent than 48 hours6011if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6012last;6013}6014my%cd= parse_date($co{'author_epoch'});60156016# get list of changed files6017open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6018$co{'parent'} ||"--root",6019$co{'id'},"--", (defined$file_name?$file_name: ())6020ornext;6021my@difftree=map{chomp;$_} <$fd>;6022close$fd6023ornext;60246025# print element (entry, item)6026my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6027if($formateq'rss') {6028print"<item>\n".6029"<title>". esc_html($co{'title'}) ."</title>\n".6030"<author>". esc_html($co{'author'}) ."</author>\n".6031"<pubDate>$cd{'rfc2822'}</pubDate>\n".6032"<guid isPermaLink=\"true\">$co_url</guid>\n".6033"<link>$co_url</link>\n".6034"<description>". esc_html($co{'title'}) ."</description>\n".6035"<content:encoded>".6036"<![CDATA[\n";6037}elsif($formateq'atom') {6038print"<entry>\n".6039"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6040"<updated>$cd{'iso-8601'}</updated>\n".6041"<author>\n".6042" <name>". esc_html($co{'author_name'}) ."</name>\n";6043if($co{'author_email'}) {6044print" <email>". esc_html($co{'author_email'}) ."</email>\n";6045}6046print"</author>\n".6047# use committer for contributor6048"<contributor>\n".6049" <name>". esc_html($co{'committer_name'}) ."</name>\n";6050if($co{'committer_email'}) {6051print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6052}6053print"</contributor>\n".6054"<published>$cd{'iso-8601'}</published>\n".6055"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6056"<id>$co_url</id>\n".6057"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6058"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6059}6060my$comment=$co{'comment'};6061print"<pre>\n";6062foreachmy$line(@$comment) {6063$line= esc_html($line);6064print"$line\n";6065}6066print"</pre><ul>\n";6067foreachmy$difftree_line(@difftree) {6068my%difftree= parse_difftree_raw_line($difftree_line);6069next if!$difftree{'from_id'};60706071my$file=$difftree{'file'} ||$difftree{'to_file'};60726073print"<li>".6074"[".6075$cgi->a({-href => href(-full=>1, action=>"blobdiff",6076 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6077 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6078 file_name=>$file, file_parent=>$difftree{'from_file'}),6079-title =>"diff"},'D');6080if($have_blame) {6081print$cgi->a({-href => href(-full=>1, action=>"blame",6082 file_name=>$file, hash_base=>$commit),6083-title =>"blame"},'B');6084}6085# if this is not a feed of a file history6086if(!defined$file_name||$file_namene$file) {6087print$cgi->a({-href => href(-full=>1, action=>"history",6088 file_name=>$file, hash=>$commit),6089-title =>"history"},'H');6090}6091$file= esc_path($file);6092print"] ".6093"$file</li>\n";6094}6095if($formateq'rss') {6096print"</ul>]]>\n".6097"</content:encoded>\n".6098"</item>\n";6099}elsif($formateq'atom') {6100print"</ul>\n</div>\n".6101"</content>\n".6102"</entry>\n";6103}6104}61056106# end of feed6107if($formateq'rss') {6108print"</channel>\n</rss>\n";6109}elsif($formateq'atom') {6110print"</feed>\n";6111}6112}61136114sub git_rss {6115 git_feed('rss');6116}61176118sub git_atom {6119 git_feed('atom');6120}61216122sub git_opml {6123my@list= git_get_projects_list();61246125print$cgi->header(-type =>'text/xml', -charset =>'utf-8');6126print<<XML;6127<?xml version="1.0" encoding="utf-8"?>6128<opml version="1.0">6129<head>6130 <title>$site_nameOPML Export</title>6131</head>6132<body>6133<outline text="git RSS feeds">6134XML61356136foreachmy$pr(@list) {6137my%proj=%$pr;6138my$head= git_get_head_hash($proj{'path'});6139if(!defined$head) {6140next;6141}6142$git_dir="$projectroot/$proj{'path'}";6143my%co= parse_commit($head);6144if(!%co) {6145next;6146}61476148my$path= esc_html(chop_str($proj{'path'},25,5));6149my$rss="$my_url?p=$proj{'path'};a=rss";6150my$html="$my_url?p=$proj{'path'};a=summary";6151print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";6152}6153print<<XML;6154</outline>6155</body>6156</opml>6157XML6158}