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 $projectroot2150if(check_export_ok("$projectroot/$filter/$subdir")) {2151push@list, { path => ($filter?"$filter/":'') .$subdir};2152$File::Find::prune =1;2153}2154},2155},"$dir");21562157}elsif(-f $projects_list) {2158# read from file(url-encoded):2159# 'git%2Fgit.git Linus+Torvalds'2160# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2161# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2162my%paths;2163open my($fd),$projects_listorreturn;2164 PROJECT:2165while(my$line= <$fd>) {2166chomp$line;2167my($path,$owner) =split' ',$line;2168$path= unescape($path);2169$owner= unescape($owner);2170if(!defined$path) {2171next;2172}2173if($filterne'') {2174# looking for forks;2175my$pfx=substr($path,0,length($filter));2176if($pfxne$filter) {2177next PROJECT;2178}2179my$sfx=substr($path,length($filter));2180if($sfx!~/^\/.*\.git$/) {2181next PROJECT;2182}2183}elsif($check_forks) {2184 PATH:2185foreachmy$filter(keys%paths) {2186# looking for forks;2187my$pfx=substr($path,0,length($filter));2188if($pfxne$filter) {2189next PATH;2190}2191my$sfx=substr($path,length($filter));2192if($sfx!~/^\/.*\.git$/) {2193next PATH;2194}2195# is a fork, don't include it in2196# the list2197next PROJECT;2198}2199}2200if(check_export_ok("$projectroot/$path")) {2201my$pr= {2202 path =>$path,2203 owner => to_utf8($owner),2204};2205push@list,$pr;2206(my$forks_path=$path) =~s/\.git$//;2207$paths{$forks_path}++;2208}2209}2210close$fd;2211}2212return@list;2213}22142215our$gitweb_project_owner=undef;2216sub git_get_project_list_from_file {22172218return if(defined$gitweb_project_owner);22192220$gitweb_project_owner= {};2221# read from file (url-encoded):2222# 'git%2Fgit.git Linus+Torvalds'2223# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2224# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2225if(-f $projects_list) {2226open(my$fd,$projects_list);2227while(my$line= <$fd>) {2228chomp$line;2229my($pr,$ow) =split' ',$line;2230$pr= unescape($pr);2231$ow= unescape($ow);2232$gitweb_project_owner->{$pr} = to_utf8($ow);2233}2234close$fd;2235}2236}22372238sub git_get_project_owner {2239my$project=shift;2240my$owner;22412242returnundefunless$project;2243$git_dir="$projectroot/$project";22442245if(!defined$gitweb_project_owner) {2246 git_get_project_list_from_file();2247}22482249if(exists$gitweb_project_owner->{$project}) {2250$owner=$gitweb_project_owner->{$project};2251}2252if(!defined$owner){2253$owner= git_get_project_config('owner');2254}2255if(!defined$owner) {2256$owner= get_file_owner("$git_dir");2257}22582259return$owner;2260}22612262sub git_get_last_activity {2263my($path) =@_;2264my$fd;22652266$git_dir="$projectroot/$path";2267open($fd,"-|", git_cmd(),'for-each-ref',2268'--format=%(committer)',2269'--sort=-committerdate',2270'--count=1',2271'refs/heads')orreturn;2272my$most_recent= <$fd>;2273close$fdorreturn;2274if(defined$most_recent&&2275$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2276my$timestamp=$1;2277my$age=time-$timestamp;2278return($age, age_string($age));2279}2280return(undef,undef);2281}22822283sub git_get_references {2284my$type=shift||"";2285my%refs;2286# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112287# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2288open my$fd,"-|", git_cmd(),"show-ref","--dereference",2289($type? ("--","refs/$type") : ())# use -- <pattern> if $type2290orreturn;22912292while(my$line= <$fd>) {2293chomp$line;2294if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2295if(defined$refs{$1}) {2296push@{$refs{$1}},$2;2297}else{2298$refs{$1} = [$2];2299}2300}2301}2302close$fdorreturn;2303return \%refs;2304}23052306sub git_get_rev_name_tags {2307my$hash=shift||returnundef;23082309open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2310orreturn;2311my$name_rev= <$fd>;2312close$fd;23132314if($name_rev=~ m|^$hash tags/(.*)$|) {2315return$1;2316}else{2317# catches also '$hash undefined' output2318returnundef;2319}2320}23212322## ----------------------------------------------------------------------2323## parse to hash functions23242325sub parse_date {2326my$epoch=shift;2327my$tz=shift||"-0000";23282329my%date;2330my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2331my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2332my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2333$date{'hour'} =$hour;2334$date{'minute'} =$min;2335$date{'mday'} =$mday;2336$date{'day'} =$days[$wday];2337$date{'month'} =$months[$mon];2338$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2339$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2340$date{'mday-time'} =sprintf"%d%s%02d:%02d",2341$mday,$months[$mon],$hour,$min;2342$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",23431900+$year,1+$mon,$mday,$hour,$min,$sec;23442345$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2346my$local=$epoch+ ((int$1+ ($2/60)) *3600);2347($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2348$date{'hour_local'} =$hour;2349$date{'minute_local'} =$min;2350$date{'tz_local'} =$tz;2351$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",23521900+$year,$mon+1,$mday,2353$hour,$min,$sec,$tz);2354return%date;2355}23562357sub parse_tag {2358my$tag_id=shift;2359my%tag;2360my@comment;23612362open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2363$tag{'id'} =$tag_id;2364while(my$line= <$fd>) {2365chomp$line;2366if($line=~m/^object ([0-9a-fA-F]{40})$/) {2367$tag{'object'} =$1;2368}elsif($line=~m/^type (.+)$/) {2369$tag{'type'} =$1;2370}elsif($line=~m/^tag (.+)$/) {2371$tag{'name'} =$1;2372}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2373$tag{'author'} =$1;2374$tag{'epoch'} =$2;2375$tag{'tz'} =$3;2376}elsif($line=~m/--BEGIN/) {2377push@comment,$line;2378last;2379}elsif($lineeq"") {2380last;2381}2382}2383push@comment, <$fd>;2384$tag{'comment'} = \@comment;2385close$fdorreturn;2386if(!defined$tag{'name'}) {2387return2388};2389return%tag2390}23912392sub parse_commit_text {2393my($commit_text,$withparents) =@_;2394my@commit_lines=split'\n',$commit_text;2395my%co;23962397pop@commit_lines;# Remove '\0'23982399if(!@commit_lines) {2400return;2401}24022403my$header=shift@commit_lines;2404if($header!~m/^[0-9a-fA-F]{40}/) {2405return;2406}2407($co{'id'},my@parents) =split' ',$header;2408while(my$line=shift@commit_lines) {2409last if$lineeq"\n";2410if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2411$co{'tree'} =$1;2412}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2413push@parents,$1;2414}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2415$co{'author'} =$1;2416$co{'author_epoch'} =$2;2417$co{'author_tz'} =$3;2418if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2419$co{'author_name'} =$1;2420$co{'author_email'} =$2;2421}else{2422$co{'author_name'} =$co{'author'};2423}2424}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2425$co{'committer'} =$1;2426$co{'committer_epoch'} =$2;2427$co{'committer_tz'} =$3;2428$co{'committer_name'} =$co{'committer'};2429if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2430$co{'committer_name'} =$1;2431$co{'committer_email'} =$2;2432}else{2433$co{'committer_name'} =$co{'committer'};2434}2435}2436}2437if(!defined$co{'tree'}) {2438return;2439};2440$co{'parents'} = \@parents;2441$co{'parent'} =$parents[0];24422443foreachmy$title(@commit_lines) {2444$title=~s/^ //;2445if($titlene"") {2446$co{'title'} = chop_str($title,80,5);2447# remove leading stuff of merges to make the interesting part visible2448if(length($title) >50) {2449$title=~s/^Automatic //;2450$title=~s/^merge (of|with) /Merge ... /i;2451if(length($title) >50) {2452$title=~s/(http|rsync):\/\///;2453}2454if(length($title) >50) {2455$title=~s/(master|www|rsync)\.//;2456}2457if(length($title) >50) {2458$title=~s/kernel.org:?//;2459}2460if(length($title) >50) {2461$title=~s/\/pub\/scm//;2462}2463}2464$co{'title_short'} = chop_str($title,50,5);2465last;2466}2467}2468if(!defined$co{'title'} ||$co{'title'}eq"") {2469$co{'title'} =$co{'title_short'} ='(no commit message)';2470}2471# remove added spaces2472foreachmy$line(@commit_lines) {2473$line=~s/^ //;2474}2475$co{'comment'} = \@commit_lines;24762477my$age=time-$co{'committer_epoch'};2478$co{'age'} =$age;2479$co{'age_string'} = age_string($age);2480my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2481if($age>60*60*24*7*2) {2482$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2483$co{'age_string_age'} =$co{'age_string'};2484}else{2485$co{'age_string_date'} =$co{'age_string'};2486$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2487}2488return%co;2489}24902491sub parse_commit {2492my($commit_id) =@_;2493my%co;24942495local$/="\0";24962497open my$fd,"-|", git_cmd(),"rev-list",2498"--parents",2499"--header",2500"--max-count=1",2501$commit_id,2502"--",2503or die_error(500,"Open git-rev-list failed");2504%co= parse_commit_text(<$fd>,1);2505close$fd;25062507return%co;2508}25092510sub parse_commits {2511my($commit_id,$maxcount,$skip,$filename,@args) =@_;2512my@cos;25132514$maxcount||=1;2515$skip||=0;25162517local$/="\0";25182519open my$fd,"-|", git_cmd(),"rev-list",2520"--header",2521@args,2522("--max-count=".$maxcount),2523("--skip=".$skip),2524@extra_options,2525$commit_id,2526"--",2527($filename? ($filename) : ())2528or die_error(500,"Open git-rev-list failed");2529while(my$line= <$fd>) {2530my%co= parse_commit_text($line);2531push@cos, \%co;2532}2533close$fd;25342535returnwantarray?@cos: \@cos;2536}25372538# parse line of git-diff-tree "raw" output2539sub parse_difftree_raw_line {2540my$line=shift;2541my%res;25422543# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2544# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2545if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2546$res{'from_mode'} =$1;2547$res{'to_mode'} =$2;2548$res{'from_id'} =$3;2549$res{'to_id'} =$4;2550$res{'status'} =$5;2551$res{'similarity'} =$6;2552if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2553($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2554}else{2555$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2556}2557}2558# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2559# combined diff (for merge commit)2560elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2561$res{'nparents'} =length($1);2562$res{'from_mode'} = [split(' ',$2) ];2563$res{'to_mode'} =pop@{$res{'from_mode'}};2564$res{'from_id'} = [split(' ',$3) ];2565$res{'to_id'} =pop@{$res{'from_id'}};2566$res{'status'} = [split('',$4) ];2567$res{'to_file'} = unquote($5);2568}2569# 'c512b523472485aef4fff9e57b229d9d243c967f'2570elsif($line=~m/^([0-9a-fA-F]{40})$/) {2571$res{'commit'} =$1;2572}25732574returnwantarray?%res: \%res;2575}25762577# wrapper: return parsed line of git-diff-tree "raw" output2578# (the argument might be raw line, or parsed info)2579sub parsed_difftree_line {2580my$line_or_ref=shift;25812582if(ref($line_or_ref)eq"HASH") {2583# pre-parsed (or generated by hand)2584return$line_or_ref;2585}else{2586return parse_difftree_raw_line($line_or_ref);2587}2588}25892590# parse line of git-ls-tree output2591sub parse_ls_tree_line ($;%) {2592my$line=shift;2593my%opts=@_;2594my%res;25952596#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2597$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;25982599$res{'mode'} =$1;2600$res{'type'} =$2;2601$res{'hash'} =$3;2602if($opts{'-z'}) {2603$res{'name'} =$4;2604}else{2605$res{'name'} = unquote($4);2606}26072608returnwantarray?%res: \%res;2609}26102611# generates _two_ hashes, references to which are passed as 2 and 3 argument2612sub parse_from_to_diffinfo {2613my($diffinfo,$from,$to,@parents) =@_;26142615if($diffinfo->{'nparents'}) {2616# combined diff2617$from->{'file'} = [];2618$from->{'href'} = [];2619 fill_from_file_info($diffinfo,@parents)2620unlessexists$diffinfo->{'from_file'};2621for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2622$from->{'file'}[$i] =2623defined$diffinfo->{'from_file'}[$i] ?2624$diffinfo->{'from_file'}[$i] :2625$diffinfo->{'to_file'};2626if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2627$from->{'href'}[$i] = href(action=>"blob",2628 hash_base=>$parents[$i],2629 hash=>$diffinfo->{'from_id'}[$i],2630 file_name=>$from->{'file'}[$i]);2631}else{2632$from->{'href'}[$i] =undef;2633}2634}2635}else{2636# ordinary (not combined) diff2637$from->{'file'} =$diffinfo->{'from_file'};2638if($diffinfo->{'status'}ne"A") {# not new (added) file2639$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2640 hash=>$diffinfo->{'from_id'},2641 file_name=>$from->{'file'});2642}else{2643delete$from->{'href'};2644}2645}26462647$to->{'file'} =$diffinfo->{'to_file'};2648if(!is_deleted($diffinfo)) {# file exists in result2649$to->{'href'} = href(action=>"blob", hash_base=>$hash,2650 hash=>$diffinfo->{'to_id'},2651 file_name=>$to->{'file'});2652}else{2653delete$to->{'href'};2654}2655}26562657## ......................................................................2658## parse to array of hashes functions26592660sub git_get_heads_list {2661my$limit=shift;2662my@headslist;26632664open my$fd,'-|', git_cmd(),'for-each-ref',2665($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2666'--format=%(objectname) %(refname) %(subject)%00%(committer)',2667'refs/heads'2668orreturn;2669while(my$line= <$fd>) {2670my%ref_item;26712672chomp$line;2673my($refinfo,$committerinfo) =split(/\0/,$line);2674my($hash,$name,$title) =split(' ',$refinfo,3);2675my($committer,$epoch,$tz) =2676($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2677$ref_item{'fullname'} =$name;2678$name=~s!^refs/heads/!!;26792680$ref_item{'name'} =$name;2681$ref_item{'id'} =$hash;2682$ref_item{'title'} =$title||'(no commit message)';2683$ref_item{'epoch'} =$epoch;2684if($epoch) {2685$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2686}else{2687$ref_item{'age'} ="unknown";2688}26892690push@headslist, \%ref_item;2691}2692close$fd;26932694returnwantarray?@headslist: \@headslist;2695}26962697sub git_get_tags_list {2698my$limit=shift;2699my@tagslist;27002701open my$fd,'-|', git_cmd(),'for-each-ref',2702($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',2703'--format=%(objectname) %(objecttype) %(refname) '.2704'%(*objectname) %(*objecttype) %(subject)%00%(creator)',2705'refs/tags'2706orreturn;2707while(my$line= <$fd>) {2708my%ref_item;27092710chomp$line;2711my($refinfo,$creatorinfo) =split(/\0/,$line);2712my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);2713my($creator,$epoch,$tz) =2714($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);2715$ref_item{'fullname'} =$name;2716$name=~s!^refs/tags/!!;27172718$ref_item{'type'} =$type;2719$ref_item{'id'} =$id;2720$ref_item{'name'} =$name;2721if($typeeq"tag") {2722$ref_item{'subject'} =$title;2723$ref_item{'reftype'} =$reftype;2724$ref_item{'refid'} =$refid;2725}else{2726$ref_item{'reftype'} =$type;2727$ref_item{'refid'} =$id;2728}27292730if($typeeq"tag"||$typeeq"commit") {2731$ref_item{'epoch'} =$epoch;2732if($epoch) {2733$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2734}else{2735$ref_item{'age'} ="unknown";2736}2737}27382739push@tagslist, \%ref_item;2740}2741close$fd;27422743returnwantarray?@tagslist: \@tagslist;2744}27452746## ----------------------------------------------------------------------2747## filesystem-related functions27482749sub get_file_owner {2750my$path=shift;27512752my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);2753my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);2754if(!defined$gcos) {2755returnundef;2756}2757my$owner=$gcos;2758$owner=~s/[,;].*$//;2759return to_utf8($owner);2760}27612762# assume that file exists2763sub insert_file {2764my$filename=shift;27652766open my$fd,'<',$filename;2767print map(to_utf8, <$fd>);2768close$fd;2769}27702771## ......................................................................2772## mimetype related functions27732774sub mimetype_guess_file {2775my$filename=shift;2776my$mimemap=shift;2777-r $mimemaporreturnundef;27782779my%mimemap;2780open(MIME,$mimemap)orreturnundef;2781while(<MIME>) {2782next ifm/^#/;# skip comments2783my($mime,$exts) =split(/\t+/);2784if(defined$exts) {2785my@exts=split(/\s+/,$exts);2786foreachmy$ext(@exts) {2787$mimemap{$ext} =$mime;2788}2789}2790}2791close(MIME);27922793$filename=~/\.([^.]*)$/;2794return$mimemap{$1};2795}27962797sub mimetype_guess {2798my$filename=shift;2799my$mime;2800$filename=~/\./orreturnundef;28012802if($mimetypes_file) {2803my$file=$mimetypes_file;2804if($file!~m!^/!) {# if it is relative path2805# it is relative to project2806$file="$projectroot/$project/$file";2807}2808$mime= mimetype_guess_file($filename,$file);2809}2810$mime||= mimetype_guess_file($filename,'/etc/mime.types');2811return$mime;2812}28132814sub blob_mimetype {2815my$fd=shift;2816my$filename=shift;28172818if($filename) {2819my$mime= mimetype_guess($filename);2820$mimeandreturn$mime;2821}28222823# just in case2824return$default_blob_plain_mimetypeunless$fd;28252826if(-T $fd) {2827return'text/plain';2828}elsif(!$filename) {2829return'application/octet-stream';2830}elsif($filename=~m/\.png$/i) {2831return'image/png';2832}elsif($filename=~m/\.gif$/i) {2833return'image/gif';2834}elsif($filename=~m/\.jpe?g$/i) {2835return'image/jpeg';2836}else{2837return'application/octet-stream';2838}2839}28402841sub blob_contenttype {2842my($fd,$file_name,$type) =@_;28432844$type||= blob_mimetype($fd,$file_name);2845if($typeeq'text/plain'&&defined$default_text_plain_charset) {2846$type.="; charset=$default_text_plain_charset";2847}28482849return$type;2850}28512852## ======================================================================2853## functions printing HTML: header, footer, error page28542855sub git_header_html {2856my$status=shift||"200 OK";2857my$expires=shift;28582859my$title="$site_name";2860if(defined$project) {2861$title.=" - ". to_utf8($project);2862if(defined$action) {2863$title.="/$action";2864if(defined$file_name) {2865$title.=" - ". esc_path($file_name);2866if($actioneq"tree"&&$file_name!~ m|/$|) {2867$title.="/";2868}2869}2870}2871}2872my$content_type;2873# require explicit support from the UA if we are to send the page as2874# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.2875# we have to do this because MSIE sometimes globs '*/*', pretending to2876# support xhtml+xml but choking when it gets what it asked for.2877if(defined$cgi->http('HTTP_ACCEPT') &&2878$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&2879$cgi->Accept('application/xhtml+xml') !=0) {2880$content_type='application/xhtml+xml';2881}else{2882$content_type='text/html';2883}2884print$cgi->header(-type=>$content_type, -charset =>'utf-8',2885-status=>$status, -expires =>$expires);2886my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';2887print<<EOF;2888<?xml version="1.0" encoding="utf-8"?>2889<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">2890<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">2891<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->2892<!-- git core binaries version$git_version-->2893<head>2894<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>2895<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>2896<meta name="robots" content="index, nofollow"/>2897<title>$title</title>2898EOF2899# print out each stylesheet that exist2900if(defined$stylesheet) {2901#provides backwards capability for those people who define style sheet in a config file2902print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";2903}else{2904foreachmy$stylesheet(@stylesheets) {2905next unless$stylesheet;2906print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";2907}2908}2909if(defined$project) {2910my%href_params= get_feed_info();2911if(!exists$href_params{'-title'}) {2912$href_params{'-title'} ='log';2913}29142915foreachmy$formatqw(RSS Atom){2916my$type=lc($format);2917my%link_attr= (2918'-rel'=>'alternate',2919'-title'=>"$project-$href_params{'-title'} -$formatfeed",2920'-type'=>"application/$type+xml"2921);29222923$href_params{'action'} =$type;2924$link_attr{'-href'} = href(%href_params);2925print"<link ".2926"rel=\"$link_attr{'-rel'}\"".2927"title=\"$link_attr{'-title'}\"".2928"href=\"$link_attr{'-href'}\"".2929"type=\"$link_attr{'-type'}\"".2930"/>\n";29312932$href_params{'extra_options'} ='--no-merges';2933$link_attr{'-href'} = href(%href_params);2934$link_attr{'-title'} .=' (no merges)';2935print"<link ".2936"rel=\"$link_attr{'-rel'}\"".2937"title=\"$link_attr{'-title'}\"".2938"href=\"$link_attr{'-href'}\"".2939"type=\"$link_attr{'-type'}\"".2940"/>\n";2941}29422943}else{2944printf('<link rel="alternate" title="%sprojects list" '.2945'href="%s" type="text/plain; charset=utf-8" />'."\n",2946$site_name, href(project=>undef, action=>"project_index"));2947printf('<link rel="alternate" title="%sprojects feeds" '.2948'href="%s" type="text/x-opml" />'."\n",2949$site_name, href(project=>undef, action=>"opml"));2950}2951if(defined$favicon) {2952printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);2953}29542955print"</head>\n".2956"<body>\n";29572958if(-f $site_header) {2959 insert_file($site_header);2960}29612962print"<div class=\"page_header\">\n".2963$cgi->a({-href => esc_url($logo_url),2964-title =>$logo_label},2965qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));2966print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";2967if(defined$project) {2968print$cgi->a({-href => href(action=>"summary")}, esc_html($project));2969if(defined$action) {2970print" /$action";2971}2972print"\n";2973}2974print"</div>\n";29752976my$have_search= gitweb_check_feature('search');2977if(defined$project&&$have_search) {2978if(!defined$searchtext) {2979$searchtext="";2980}2981my$search_hash;2982if(defined$hash_base) {2983$search_hash=$hash_base;2984}elsif(defined$hash) {2985$search_hash=$hash;2986}else{2987$search_hash="HEAD";2988}2989my$action=$my_uri;2990my$use_pathinfo= gitweb_check_feature('pathinfo');2991if($use_pathinfo) {2992$action.="/".esc_url($project);2993}2994print$cgi->startform(-method=>"get", -action =>$action) .2995"<div class=\"search\">\n".2996(!$use_pathinfo&&2997$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .2998$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".2999$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3000$cgi->popup_menu(-name =>'st', -default=>'commit',3001-values=> ['commit','grep','author','committer','pickaxe']) .3002$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3003" search:\n",3004$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3005"<span title=\"Extended regular expression\">".3006$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3007-checked =>$search_use_regexp) .3008"</span>".3009"</div>".3010$cgi->end_form() ."\n";3011}3012}30133014sub git_footer_html {3015my$feed_class='rss_logo';30163017print"<div class=\"page_footer\">\n";3018if(defined$project) {3019my$descr= git_get_project_description($project);3020if(defined$descr) {3021print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3022}30233024my%href_params= get_feed_info();3025if(!%href_params) {3026$feed_class.=' generic';3027}3028$href_params{'-title'} ||='log';30293030foreachmy$formatqw(RSS Atom){3031$href_params{'action'} =lc($format);3032print$cgi->a({-href => href(%href_params),3033-title =>"$href_params{'-title'}$formatfeed",3034-class=>$feed_class},$format)."\n";3035}30363037}else{3038print$cgi->a({-href => href(project=>undef, action=>"opml"),3039-class=>$feed_class},"OPML") ." ";3040print$cgi->a({-href => href(project=>undef, action=>"project_index"),3041-class=>$feed_class},"TXT") ."\n";3042}3043print"</div>\n";# class="page_footer"30443045if(-f $site_footer) {3046 insert_file($site_footer);3047}30483049print"</body>\n".3050"</html>";3051}30523053# die_error(<http_status_code>, <error_message>)3054# Example: die_error(404, 'Hash not found')3055# By convention, use the following status codes (as defined in RFC 2616):3056# 400: Invalid or missing CGI parameters, or3057# requested object exists but has wrong type.3058# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3059# this server or project.3060# 404: Requested object/revision/project doesn't exist.3061# 500: The server isn't configured properly, or3062# an internal error occurred (e.g. failed assertions caused by bugs), or3063# an unknown error occurred (e.g. the git binary died unexpectedly).3064sub die_error {3065my$status=shift||500;3066my$error=shift||"Internal server error";30673068my%http_responses= (400=>'400 Bad Request',3069403=>'403 Forbidden',3070404=>'404 Not Found',3071500=>'500 Internal Server Error');3072 git_header_html($http_responses{$status});3073print<<EOF;3074<div class="page_body">3075<br /><br />3076$status-$error3077<br />3078</div>3079EOF3080 git_footer_html();3081exit;3082}30833084## ----------------------------------------------------------------------3085## functions printing or outputting HTML: navigation30863087sub git_print_page_nav {3088my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3089$extra=''if!defined$extra;# pager or formats30903091my@navs=qw(summary shortlog log commit commitdiff tree);3092if($suppress) {3093@navs=grep{$_ne$suppress}@navs;3094}30953096my%arg=map{$_=> {action=>$_} }@navs;3097if(defined$head) {3098for(qw(commit commitdiff)) {3099$arg{$_}{'hash'} =$head;3100}3101if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3102for(qw(shortlog log)) {3103$arg{$_}{'hash'} =$head;3104}3105}3106}31073108$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3109$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;31103111my@actions= gitweb_get_feature('actions');3112my%repl= (3113'%'=>'%',3114'n'=>$project,# project name3115'f'=>$git_dir,# project path within filesystem3116'h'=>$treehead||'',# current hash ('h' parameter)3117'b'=>$treebase||'',# hash base ('hb' parameter)3118);3119while(@actions) {3120my($label,$link,$pos) =splice(@actions,0,3);3121# insert3122@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3123# munch munch3124$link=~s/%([%nfhb])/$repl{$1}/g;3125$arg{$label}{'_href'} =$link;3126}31273128print"<div class=\"page_nav\">\n".3129(join" | ",3130map{$_eq$current?3131$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3132}@navs);3133print"<br/>\n$extra<br/>\n".3134"</div>\n";3135}31363137sub format_paging_nav {3138my($action,$hash,$head,$page,$has_next_link) =@_;3139my$paging_nav;314031413142if($hashne$head||$page) {3143$paging_nav.=$cgi->a({-href => href(action=>$action)},"HEAD");3144}else{3145$paging_nav.="HEAD";3146}31473148if($page>0) {3149$paging_nav.=" ⋅ ".3150$cgi->a({-href => href(-replay=>1, page=>$page-1),3151-accesskey =>"p", -title =>"Alt-p"},"prev");3152}else{3153$paging_nav.=" ⋅ prev";3154}31553156if($has_next_link) {3157$paging_nav.=" ⋅ ".3158$cgi->a({-href => href(-replay=>1, page=>$page+1),3159-accesskey =>"n", -title =>"Alt-n"},"next");3160}else{3161$paging_nav.=" ⋅ next";3162}31633164return$paging_nav;3165}31663167## ......................................................................3168## functions printing or outputting HTML: div31693170sub git_print_header_div {3171my($action,$title,$hash,$hash_base) =@_;3172my%args= ();31733174$args{'action'} =$action;3175$args{'hash'} =$hashif$hash;3176$args{'hash_base'} =$hash_baseif$hash_base;31773178print"<div class=\"header\">\n".3179$cgi->a({-href => href(%args), -class=>"title"},3180$title?$title:$action) .3181"\n</div>\n";3182}31833184#sub git_print_authorship (\%) {3185sub git_print_authorship {3186my$co=shift;31873188my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3189print"<div class=\"author_date\">".3190 esc_html($co->{'author_name'}) .3191" [$ad{'rfc2822'}";3192if($ad{'hour_local'} <6) {3193printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3194$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});3195}else{3196printf(" (%02d:%02d%s)",3197$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});3198}3199print"]</div>\n";3200}32013202sub git_print_page_path {3203my$name=shift;3204my$type=shift;3205my$hb=shift;320632073208print"<div class=\"page_path\">";3209print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3210-title =>'tree root'}, to_utf8("[$project]"));3211print" / ";3212if(defined$name) {3213my@dirname=split'/',$name;3214my$basename=pop@dirname;3215my$fullname='';32163217foreachmy$dir(@dirname) {3218$fullname.= ($fullname?'/':'') .$dir;3219print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3220 hash_base=>$hb),3221-title =>$fullname}, esc_path($dir));3222print" / ";3223}3224if(defined$type&&$typeeq'blob') {3225print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3226 hash_base=>$hb),3227-title =>$name}, esc_path($basename));3228}elsif(defined$type&&$typeeq'tree') {3229print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3230 hash_base=>$hb),3231-title =>$name}, esc_path($basename));3232print" / ";3233}else{3234print esc_path($basename);3235}3236}3237print"<br/></div>\n";3238}32393240# sub git_print_log (\@;%) {3241sub git_print_log ($;%) {3242my$log=shift;3243my%opts=@_;32443245if($opts{'-remove_title'}) {3246# remove title, i.e. first line of log3247shift@$log;3248}3249# remove leading empty lines3250while(defined$log->[0] &&$log->[0]eq"") {3251shift@$log;3252}32533254# print log3255my$signoff=0;3256my$empty=0;3257foreachmy$line(@$log) {3258if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3259$signoff=1;3260$empty=0;3261if(!$opts{'-remove_signoff'}) {3262print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3263next;3264}else{3265# remove signoff lines3266next;3267}3268}else{3269$signoff=0;3270}32713272# print only one empty line3273# do not print empty line after signoff3274if($lineeq"") {3275next if($empty||$signoff);3276$empty=1;3277}else{3278$empty=0;3279}32803281print format_log_line_html($line) ."<br/>\n";3282}32833284if($opts{'-final_empty_line'}) {3285# end with single empty line3286print"<br/>\n"unless$empty;3287}3288}32893290# return link target (what link points to)3291sub git_get_link_target {3292my$hash=shift;3293my$link_target;32943295# read link3296open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3297orreturn;3298{3299local$/;3300$link_target= <$fd>;3301}3302close$fd3303orreturn;33043305return$link_target;3306}33073308# given link target, and the directory (basedir) the link is in,3309# return target of link relative to top directory (top tree);3310# return undef if it is not possible (including absolute links).3311sub normalize_link_target {3312my($link_target,$basedir,$hash_base) =@_;33133314# we can normalize symlink target only if $hash_base is provided3315return unless$hash_base;33163317# absolute symlinks (beginning with '/') cannot be normalized3318return if(substr($link_target,0,1)eq'/');33193320# normalize link target to path from top (root) tree (dir)3321my$path;3322if($basedir) {3323$path=$basedir.'/'.$link_target;3324}else{3325# we are in top (root) tree (dir)3326$path=$link_target;3327}33283329# remove //, /./, and /../3330my@path_parts;3331foreachmy$part(split('/',$path)) {3332# discard '.' and ''3333next if(!$part||$parteq'.');3334# handle '..'3335if($parteq'..') {3336if(@path_parts) {3337pop@path_parts;3338}else{3339# link leads outside repository (outside top dir)3340return;3341}3342}else{3343push@path_parts,$part;3344}3345}3346$path=join('/',@path_parts);33473348return$path;3349}33503351# print tree entry (row of git_tree), but without encompassing <tr> element3352sub git_print_tree_entry {3353my($t,$basedir,$hash_base,$have_blame) =@_;33543355my%base_key= ();3356$base_key{'hash_base'} =$hash_baseifdefined$hash_base;33573358# The format of a table row is: mode list link. Where mode is3359# the mode of the entry, list is the name of the entry, an href,3360# and link is the action links of the entry.33613362print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3363if($t->{'type'}eq"blob") {3364print"<td class=\"list\">".3365$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3366 file_name=>"$basedir$t->{'name'}",%base_key),3367-class=>"list"}, esc_path($t->{'name'}));3368if(S_ISLNK(oct$t->{'mode'})) {3369my$link_target= git_get_link_target($t->{'hash'});3370if($link_target) {3371my$norm_target= normalize_link_target($link_target,$basedir,$hash_base);3372if(defined$norm_target) {3373print" -> ".3374$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3375 file_name=>$norm_target),3376-title =>$norm_target}, esc_path($link_target));3377}else{3378print" -> ". esc_path($link_target);3379}3380}3381}3382print"</td>\n";3383print"<td class=\"link\">";3384print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3385 file_name=>"$basedir$t->{'name'}",%base_key)},3386"blob");3387if($have_blame) {3388print" | ".3389$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3390 file_name=>"$basedir$t->{'name'}",%base_key)},3391"blame");3392}3393if(defined$hash_base) {3394print" | ".3395$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3396 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3397"history");3398}3399print" | ".3400$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3401 file_name=>"$basedir$t->{'name'}")},3402"raw");3403print"</td>\n";34043405}elsif($t->{'type'}eq"tree") {3406print"<td class=\"list\">";3407print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3408 file_name=>"$basedir$t->{'name'}",%base_key)},3409 esc_path($t->{'name'}));3410print"</td>\n";3411print"<td class=\"link\">";3412print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3413 file_name=>"$basedir$t->{'name'}",%base_key)},3414"tree");3415if(defined$hash_base) {3416print" | ".3417$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3418 file_name=>"$basedir$t->{'name'}")},3419"history");3420}3421print"</td>\n";3422}else{3423# unknown object: we can only present history for it3424# (this includes 'commit' object, i.e. submodule support)3425print"<td class=\"list\">".3426 esc_path($t->{'name'}) .3427"</td>\n";3428print"<td class=\"link\">";3429if(defined$hash_base) {3430print$cgi->a({-href => href(action=>"history",3431 hash_base=>$hash_base,3432 file_name=>"$basedir$t->{'name'}")},3433"history");3434}3435print"</td>\n";3436}3437}34383439## ......................................................................3440## functions printing large fragments of HTML34413442# get pre-image filenames for merge (combined) diff3443sub fill_from_file_info {3444my($diff,@parents) =@_;34453446$diff->{'from_file'} = [ ];3447$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3448for(my$i=0;$i<$diff->{'nparents'};$i++) {3449if($diff->{'status'}[$i]eq'R'||3450$diff->{'status'}[$i]eq'C') {3451$diff->{'from_file'}[$i] =3452 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3453}3454}34553456return$diff;3457}34583459# is current raw difftree line of file deletion3460sub is_deleted {3461my$diffinfo=shift;34623463return$diffinfo->{'to_id'}eq('0' x 40);3464}34653466# does patch correspond to [previous] difftree raw line3467# $diffinfo - hashref of parsed raw diff format3468# $patchinfo - hashref of parsed patch diff format3469# (the same keys as in $diffinfo)3470sub is_patch_split {3471my($diffinfo,$patchinfo) =@_;34723473returndefined$diffinfo&&defined$patchinfo3474&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3475}347634773478sub git_difftree_body {3479my($difftree,$hash,@parents) =@_;3480my($parent) =$parents[0];3481my$have_blame= gitweb_check_feature('blame');3482print"<div class=\"list_head\">\n";3483if($#{$difftree} >10) {3484print(($#{$difftree} +1) ." files changed:\n");3485}3486print"</div>\n";34873488print"<table class=\"".3489(@parents>1?"combined ":"") .3490"diff_tree\">\n";34913492# header only for combined diff in 'commitdiff' view3493my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3494if($has_header) {3495# table header3496print"<thead><tr>\n".3497"<th></th><th></th>\n";# filename, patchN link3498for(my$i=0;$i<@parents;$i++) {3499my$par=$parents[$i];3500print"<th>".3501$cgi->a({-href => href(action=>"commitdiff",3502 hash=>$hash, hash_parent=>$par),3503-title =>'commitdiff to parent number '.3504($i+1) .': '.substr($par,0,7)},3505$i+1) .3506" </th>\n";3507}3508print"</tr></thead>\n<tbody>\n";3509}35103511my$alternate=1;3512my$patchno=0;3513foreachmy$line(@{$difftree}) {3514my$diff= parsed_difftree_line($line);35153516if($alternate) {3517print"<tr class=\"dark\">\n";3518}else{3519print"<tr class=\"light\">\n";3520}3521$alternate^=1;35223523if(exists$diff->{'nparents'}) {# combined diff35243525 fill_from_file_info($diff,@parents)3526unlessexists$diff->{'from_file'};35273528if(!is_deleted($diff)) {3529# file exists in the result (child) commit3530print"<td>".3531$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3532 file_name=>$diff->{'to_file'},3533 hash_base=>$hash),3534-class=>"list"}, esc_path($diff->{'to_file'})) .3535"</td>\n";3536}else{3537print"<td>".3538 esc_path($diff->{'to_file'}) .3539"</td>\n";3540}35413542if($actioneq'commitdiff') {3543# link to patch3544$patchno++;3545print"<td class=\"link\">".3546$cgi->a({-href =>"#patch$patchno"},"patch") .3547" | ".3548"</td>\n";3549}35503551my$has_history=0;3552my$not_deleted=0;3553for(my$i=0;$i<$diff->{'nparents'};$i++) {3554my$hash_parent=$parents[$i];3555my$from_hash=$diff->{'from_id'}[$i];3556my$from_path=$diff->{'from_file'}[$i];3557my$status=$diff->{'status'}[$i];35583559$has_history||= ($statusne'A');3560$not_deleted||= ($statusne'D');35613562if($statuseq'A') {3563print"<td class=\"link\"align=\"right\"> | </td>\n";3564}elsif($statuseq'D') {3565print"<td class=\"link\">".3566$cgi->a({-href => href(action=>"blob",3567 hash_base=>$hash,3568 hash=>$from_hash,3569 file_name=>$from_path)},3570"blob". ($i+1)) .3571" | </td>\n";3572}else{3573if($diff->{'to_id'}eq$from_hash) {3574print"<td class=\"link nochange\">";3575}else{3576print"<td class=\"link\">";3577}3578print$cgi->a({-href => href(action=>"blobdiff",3579 hash=>$diff->{'to_id'},3580 hash_parent=>$from_hash,3581 hash_base=>$hash,3582 hash_parent_base=>$hash_parent,3583 file_name=>$diff->{'to_file'},3584 file_parent=>$from_path)},3585"diff". ($i+1)) .3586" | </td>\n";3587}3588}35893590print"<td class=\"link\">";3591if($not_deleted) {3592print$cgi->a({-href => href(action=>"blob",3593 hash=>$diff->{'to_id'},3594 file_name=>$diff->{'to_file'},3595 hash_base=>$hash)},3596"blob");3597print" | "if($has_history);3598}3599if($has_history) {3600print$cgi->a({-href => href(action=>"history",3601 file_name=>$diff->{'to_file'},3602 hash_base=>$hash)},3603"history");3604}3605print"</td>\n";36063607print"</tr>\n";3608next;# instead of 'else' clause, to avoid extra indent3609}3610# else ordinary diff36113612my($to_mode_oct,$to_mode_str,$to_file_type);3613my($from_mode_oct,$from_mode_str,$from_file_type);3614if($diff->{'to_mode'}ne('0' x 6)) {3615$to_mode_oct=oct$diff->{'to_mode'};3616if(S_ISREG($to_mode_oct)) {# only for regular file3617$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits3618}3619$to_file_type= file_type($diff->{'to_mode'});3620}3621if($diff->{'from_mode'}ne('0' x 6)) {3622$from_mode_oct=oct$diff->{'from_mode'};3623if(S_ISREG($to_mode_oct)) {# only for regular file3624$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits3625}3626$from_file_type= file_type($diff->{'from_mode'});3627}36283629if($diff->{'status'}eq"A") {# created3630my$mode_chng="<span class=\"file_status new\">[new$to_file_type";3631$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;3632$mode_chng.="]</span>";3633print"<td>";3634print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3635 hash_base=>$hash, file_name=>$diff->{'file'}),3636-class=>"list"}, esc_path($diff->{'file'}));3637print"</td>\n";3638print"<td>$mode_chng</td>\n";3639print"<td class=\"link\">";3640if($actioneq'commitdiff') {3641# link to patch3642$patchno++;3643print$cgi->a({-href =>"#patch$patchno"},"patch");3644print" | ";3645}3646print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3647 hash_base=>$hash, file_name=>$diff->{'file'})},3648"blob");3649print"</td>\n";36503651}elsif($diff->{'status'}eq"D") {# deleted3652my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";3653print"<td>";3654print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3655 hash_base=>$parent, file_name=>$diff->{'file'}),3656-class=>"list"}, esc_path($diff->{'file'}));3657print"</td>\n";3658print"<td>$mode_chng</td>\n";3659print"<td class=\"link\">";3660if($actioneq'commitdiff') {3661# link to patch3662$patchno++;3663print$cgi->a({-href =>"#patch$patchno"},"patch");3664print" | ";3665}3666print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3667 hash_base=>$parent, file_name=>$diff->{'file'})},3668"blob") ." | ";3669if($have_blame) {3670print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,3671 file_name=>$diff->{'file'})},3672"blame") ." | ";3673}3674print$cgi->a({-href => href(action=>"history", hash_base=>$parent,3675 file_name=>$diff->{'file'})},3676"history");3677print"</td>\n";36783679}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed3680my$mode_chnge="";3681if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3682$mode_chnge="<span class=\"file_status mode_chnge\">[changed";3683if($from_file_typene$to_file_type) {3684$mode_chnge.=" from$from_file_typeto$to_file_type";3685}3686if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {3687if($from_mode_str&&$to_mode_str) {3688$mode_chnge.=" mode:$from_mode_str->$to_mode_str";3689}elsif($to_mode_str) {3690$mode_chnge.=" mode:$to_mode_str";3691}3692}3693$mode_chnge.="]</span>\n";3694}3695print"<td>";3696print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3697 hash_base=>$hash, file_name=>$diff->{'file'}),3698-class=>"list"}, esc_path($diff->{'file'}));3699print"</td>\n";3700print"<td>$mode_chnge</td>\n";3701print"<td class=\"link\">";3702if($actioneq'commitdiff') {3703# link to patch3704$patchno++;3705print$cgi->a({-href =>"#patch$patchno"},"patch") .3706" | ";3707}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3708# "commit" view and modified file (not onlu mode changed)3709print$cgi->a({-href => href(action=>"blobdiff",3710 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3711 hash_base=>$hash, hash_parent_base=>$parent,3712 file_name=>$diff->{'file'})},3713"diff") .3714" | ";3715}3716print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3717 hash_base=>$hash, file_name=>$diff->{'file'})},3718"blob") ." | ";3719if($have_blame) {3720print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3721 file_name=>$diff->{'file'})},3722"blame") ." | ";3723}3724print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3725 file_name=>$diff->{'file'})},3726"history");3727print"</td>\n";37283729}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied3730my%status_name= ('R'=>'moved','C'=>'copied');3731my$nstatus=$status_name{$diff->{'status'}};3732my$mode_chng="";3733if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3734# mode also for directories, so we cannot use $to_mode_str3735$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);3736}3737print"<td>".3738$cgi->a({-href => href(action=>"blob", hash_base=>$hash,3739 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),3740-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".3741"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".3742$cgi->a({-href => href(action=>"blob", hash_base=>$parent,3743 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),3744-class=>"list"}, esc_path($diff->{'from_file'})) .3745" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".3746"<td class=\"link\">";3747if($actioneq'commitdiff') {3748# link to patch3749$patchno++;3750print$cgi->a({-href =>"#patch$patchno"},"patch") .3751" | ";3752}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3753# "commit" view and modified file (not only pure rename or copy)3754print$cgi->a({-href => href(action=>"blobdiff",3755 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3756 hash_base=>$hash, hash_parent_base=>$parent,3757 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},3758"diff") .3759" | ";3760}3761print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3762 hash_base=>$parent, file_name=>$diff->{'to_file'})},3763"blob") ." | ";3764if($have_blame) {3765print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3766 file_name=>$diff->{'to_file'})},3767"blame") ." | ";3768}3769print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3770 file_name=>$diff->{'to_file'})},3771"history");3772print"</td>\n";37733774}# we should not encounter Unmerged (U) or Unknown (X) status3775print"</tr>\n";3776}3777print"</tbody>"if$has_header;3778print"</table>\n";3779}37803781sub git_patchset_body {3782my($fd,$difftree,$hash,@hash_parents) =@_;3783my($hash_parent) =$hash_parents[0];37843785my$is_combined= (@hash_parents>1);3786my$patch_idx=0;3787my$patch_number=0;3788my$patch_line;3789my$diffinfo;3790my$to_name;3791my(%from,%to);37923793print"<div class=\"patchset\">\n";37943795# skip to first patch3796while($patch_line= <$fd>) {3797chomp$patch_line;37983799last if($patch_line=~m/^diff /);3800}38013802 PATCH:3803while($patch_line) {38043805# parse "git diff" header line3806if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {3807# $1 is from_name, which we do not use3808$to_name= unquote($2);3809$to_name=~s!^b/!!;3810}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {3811# $1 is 'cc' or 'combined', which we do not use3812$to_name= unquote($2);3813}else{3814$to_name=undef;3815}38163817# check if current patch belong to current raw line3818# and parse raw git-diff line if needed3819if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {3820# this is continuation of a split patch3821print"<div class=\"patch cont\">\n";3822}else{3823# advance raw git-diff output if needed3824$patch_idx++ifdefined$diffinfo;38253826# read and prepare patch information3827$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);38283829# compact combined diff output can have some patches skipped3830# find which patch (using pathname of result) we are at now;3831if($is_combined) {3832while($to_namene$diffinfo->{'to_file'}) {3833print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".3834 format_diff_cc_simplified($diffinfo,@hash_parents) .3835"</div>\n";# class="patch"38363837$patch_idx++;3838$patch_number++;38393840last if$patch_idx>$#$difftree;3841$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);3842}3843}38443845# modifies %from, %to hashes3846 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);38473848# this is first patch for raw difftree line with $patch_idx index3849# we index @$difftree array from 0, but number patches from 13850print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";3851}38523853# git diff header3854#assert($patch_line =~ m/^diff /) if DEBUG;3855#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed3856$patch_number++;3857# print "git diff" header3858print format_git_diff_header_line($patch_line,$diffinfo,3859 \%from, \%to);38603861# print extended diff header3862print"<div class=\"diff extended_header\">\n";3863 EXTENDED_HEADER:3864while($patch_line= <$fd>) {3865chomp$patch_line;38663867last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);38683869print format_extended_diff_header_line($patch_line,$diffinfo,3870 \%from, \%to);3871}3872print"</div>\n";# class="diff extended_header"38733874# from-file/to-file diff header3875if(!$patch_line) {3876print"</div>\n";# class="patch"3877last PATCH;3878}3879next PATCH if($patch_line=~m/^diff /);3880#assert($patch_line =~ m/^---/) if DEBUG;38813882my$last_patch_line=$patch_line;3883$patch_line= <$fd>;3884chomp$patch_line;3885#assert($patch_line =~ m/^\+\+\+/) if DEBUG;38863887print format_diff_from_to_header($last_patch_line,$patch_line,3888$diffinfo, \%from, \%to,3889@hash_parents);38903891# the patch itself3892 LINE:3893while($patch_line= <$fd>) {3894chomp$patch_line;38953896next PATCH if($patch_line=~m/^diff /);38973898print format_diff_line($patch_line, \%from, \%to);3899}39003901}continue{3902print"</div>\n";# class="patch"3903}39043905# for compact combined (--cc) format, with chunk and patch simpliciaction3906# patchset might be empty, but there might be unprocessed raw lines3907for(++$patch_idxif$patch_number>0;3908$patch_idx<@$difftree;3909++$patch_idx) {3910# read and prepare patch information3911$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);39123913# generate anchor for "patch" links in difftree / whatchanged part3914print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".3915 format_diff_cc_simplified($diffinfo,@hash_parents) .3916"</div>\n";# class="patch"39173918$patch_number++;3919}39203921if($patch_number==0) {3922if(@hash_parents>1) {3923print"<div class=\"diff nodifferences\">Trivial merge</div>\n";3924}else{3925print"<div class=\"diff nodifferences\">No differences found</div>\n";3926}3927}39283929print"</div>\n";# class="patchset"3930}39313932# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39333934# fills project list info (age, description, owner, forks) for each3935# project in the list, removing invalid projects from returned list3936# NOTE: modifies $projlist, but does not remove entries from it3937sub fill_project_list_info {3938my($projlist,$check_forks) =@_;3939my@projects;39403941my$show_ctags= gitweb_check_feature('ctags');3942 PROJECT:3943foreachmy$pr(@$projlist) {3944my(@activity) = git_get_last_activity($pr->{'path'});3945unless(@activity) {3946next PROJECT;3947}3948($pr->{'age'},$pr->{'age_string'}) =@activity;3949if(!defined$pr->{'descr'}) {3950my$descr= git_get_project_description($pr->{'path'}) ||"";3951$descr= to_utf8($descr);3952$pr->{'descr_long'} =$descr;3953$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);3954}3955if(!defined$pr->{'owner'}) {3956$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";3957}3958if($check_forks) {3959my$pname=$pr->{'path'};3960if(($pname=~s/\.git$//) &&3961($pname!~/\/$/) &&3962(-d "$projectroot/$pname")) {3963$pr->{'forks'} ="-d$projectroot/$pname";3964}else{3965$pr->{'forks'} =0;3966}3967}3968$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});3969push@projects,$pr;3970}39713972return@projects;3973}39743975# print 'sort by' <th> element, generating 'sort by $name' replay link3976# if that order is not selected3977sub print_sort_th {3978my($name,$order,$header) =@_;3979$header||=ucfirst($name);39803981if($ordereq$name) {3982print"<th>$header</th>\n";3983}else{3984print"<th>".3985$cgi->a({-href => href(-replay=>1, order=>$name),3986-class=>"header"},$header) .3987"</th>\n";3988}3989}39903991sub git_project_list_body {3992# actually uses global variable $project3993my($projlist,$order,$from,$to,$extra,$no_header) =@_;39943995my$check_forks= gitweb_check_feature('forks');3996my@projects= fill_project_list_info($projlist,$check_forks);39973998$order||=$default_projects_order;3999$from=0unlessdefined$from;4000$to=$#projectsif(!defined$to||$#projects<$to);40014002my%order_info= (4003 project => { key =>'path', type =>'str'},4004 descr => { key =>'descr_long', type =>'str'},4005 owner => { key =>'owner', type =>'str'},4006 age => { key =>'age', type =>'num'}4007);4008my$oi=$order_info{$order};4009if($oi->{'type'}eq'str') {4010@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4011}else{4012@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4013}40144015my$show_ctags= gitweb_check_feature('ctags');4016if($show_ctags) {4017my%ctags;4018foreachmy$p(@projects) {4019foreachmy$ct(keys%{$p->{'ctags'}}) {4020$ctags{$ct} +=$p->{'ctags'}->{$ct};4021}4022}4023my$cloud= git_populate_project_tagcloud(\%ctags);4024print git_show_project_tagcloud($cloud,64);4025}40264027print"<table class=\"project_list\">\n";4028unless($no_header) {4029print"<tr>\n";4030if($check_forks) {4031print"<th></th>\n";4032}4033 print_sort_th('project',$order,'Project');4034 print_sort_th('descr',$order,'Description');4035 print_sort_th('owner',$order,'Owner');4036 print_sort_th('age',$order,'Last Change');4037print"<th></th>\n".# for links4038"</tr>\n";4039}4040my$alternate=1;4041my$tagfilter=$cgi->param('by_tag');4042for(my$i=$from;$i<=$to;$i++) {4043my$pr=$projects[$i];40444045next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4046next if$searchtextand not$pr->{'path'} =~/$searchtext/4047and not$pr->{'descr_long'} =~/$searchtext/;4048# Weed out forks or non-matching entries of search4049if($check_forks) {4050my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4051$forkbase="^$forkbase"if$forkbase;4052next ifnot$searchtextand not$tagfilterand$show_ctags4053and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4054}40554056if($alternate) {4057print"<tr class=\"dark\">\n";4058}else{4059print"<tr class=\"light\">\n";4060}4061$alternate^=1;4062if($check_forks) {4063print"<td>";4064if($pr->{'forks'}) {4065print"<!--$pr->{'forks'} -->\n";4066print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4067}4068print"</td>\n";4069}4070print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4071-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4072"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4073-class=>"list", -title =>$pr->{'descr_long'}},4074 esc_html($pr->{'descr'})) ."</td>\n".4075"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4076print"<td class=\"". age_class($pr->{'age'}) ."\">".4077(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4078"<td class=\"link\">".4079$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4080$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4081$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4082$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4083($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4084"</td>\n".4085"</tr>\n";4086}4087if(defined$extra) {4088print"<tr>\n";4089if($check_forks) {4090print"<td></td>\n";4091}4092print"<td colspan=\"5\">$extra</td>\n".4093"</tr>\n";4094}4095print"</table>\n";4096}40974098sub git_shortlog_body {4099# uses global variable $project4100my($commitlist,$from,$to,$refs,$extra) =@_;41014102$from=0unlessdefined$from;4103$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);41044105print"<table class=\"shortlog\">\n";4106my$alternate=1;4107for(my$i=$from;$i<=$to;$i++) {4108my%co= %{$commitlist->[$i]};4109my$commit=$co{'id'};4110my$ref= format_ref_marker($refs,$commit);4111if($alternate) {4112print"<tr class=\"dark\">\n";4113}else{4114print"<tr class=\"light\">\n";4115}4116$alternate^=1;4117my$author= chop_and_escape_str($co{'author_name'},10);4118# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4119print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4120"<td><i>".$author."</i></td>\n".4121"<td>";4122print format_subject_html($co{'title'},$co{'title_short'},4123 href(action=>"commit", hash=>$commit),$ref);4124print"</td>\n".4125"<td class=\"link\">".4126$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4127$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4128$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4129my$snapshot_links= format_snapshot_links($commit);4130if(defined$snapshot_links) {4131print" | ".$snapshot_links;4132}4133print"</td>\n".4134"</tr>\n";4135}4136if(defined$extra) {4137print"<tr>\n".4138"<td colspan=\"4\">$extra</td>\n".4139"</tr>\n";4140}4141print"</table>\n";4142}41434144sub git_history_body {4145# Warning: assumes constant type (blob or tree) during history4146my($commitlist,$from,$to,$refs,$hash_base,$ftype,$extra) =@_;41474148$from=0unlessdefined$from;4149$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});41504151print"<table class=\"history\">\n";4152my$alternate=1;4153for(my$i=$from;$i<=$to;$i++) {4154my%co= %{$commitlist->[$i]};4155if(!%co) {4156next;4157}4158my$commit=$co{'id'};41594160my$ref= format_ref_marker($refs,$commit);41614162if($alternate) {4163print"<tr class=\"dark\">\n";4164}else{4165print"<tr class=\"light\">\n";4166}4167$alternate^=1;4168# shortlog uses chop_str($co{'author_name'}, 10)4169my$author= chop_and_escape_str($co{'author_name'},15,3);4170print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4171"<td><i>".$author."</i></td>\n".4172"<td>";4173# originally git_history used chop_str($co{'title'}, 50)4174print format_subject_html($co{'title'},$co{'title_short'},4175 href(action=>"commit", hash=>$commit),$ref);4176print"</td>\n".4177"<td class=\"link\">".4178$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4179$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");41804181if($ftypeeq'blob') {4182my$blob_current= git_get_hash_by_path($hash_base,$file_name);4183my$blob_parent= git_get_hash_by_path($commit,$file_name);4184if(defined$blob_current&&defined$blob_parent&&4185$blob_currentne$blob_parent) {4186print" | ".4187$cgi->a({-href => href(action=>"blobdiff",4188 hash=>$blob_current, hash_parent=>$blob_parent,4189 hash_base=>$hash_base, hash_parent_base=>$commit,4190 file_name=>$file_name)},4191"diff to current");4192}4193}4194print"</td>\n".4195"</tr>\n";4196}4197if(defined$extra) {4198print"<tr>\n".4199"<td colspan=\"4\">$extra</td>\n".4200"</tr>\n";4201}4202print"</table>\n";4203}42044205sub git_tags_body {4206# uses global variable $project4207my($taglist,$from,$to,$extra) =@_;4208$from=0unlessdefined$from;4209$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);42104211print"<table class=\"tags\">\n";4212my$alternate=1;4213for(my$i=$from;$i<=$to;$i++) {4214my$entry=$taglist->[$i];4215my%tag=%$entry;4216my$comment=$tag{'subject'};4217my$comment_short;4218if(defined$comment) {4219$comment_short= chop_str($comment,30,5);4220}4221if($alternate) {4222print"<tr class=\"dark\">\n";4223}else{4224print"<tr class=\"light\">\n";4225}4226$alternate^=1;4227if(defined$tag{'age'}) {4228print"<td><i>$tag{'age'}</i></td>\n";4229}else{4230print"<td></td>\n";4231}4232print"<td>".4233$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4234-class=>"list name"}, esc_html($tag{'name'})) .4235"</td>\n".4236"<td>";4237if(defined$comment) {4238print format_subject_html($comment,$comment_short,4239 href(action=>"tag", hash=>$tag{'id'}));4240}4241print"</td>\n".4242"<td class=\"selflink\">";4243if($tag{'type'}eq"tag") {4244print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4245}else{4246print" ";4247}4248print"</td>\n".4249"<td class=\"link\">"." | ".4250$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4251if($tag{'reftype'}eq"commit") {4252print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4253" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4254}elsif($tag{'reftype'}eq"blob") {4255print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4256}4257print"</td>\n".4258"</tr>";4259}4260if(defined$extra) {4261print"<tr>\n".4262"<td colspan=\"5\">$extra</td>\n".4263"</tr>\n";4264}4265print"</table>\n";4266}42674268sub git_heads_body {4269# uses global variable $project4270my($headlist,$head,$from,$to,$extra) =@_;4271$from=0unlessdefined$from;4272$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);42734274print"<table class=\"heads\">\n";4275my$alternate=1;4276for(my$i=$from;$i<=$to;$i++) {4277my$entry=$headlist->[$i];4278my%ref=%$entry;4279my$curr=$ref{'id'}eq$head;4280if($alternate) {4281print"<tr class=\"dark\">\n";4282}else{4283print"<tr class=\"light\">\n";4284}4285$alternate^=1;4286print"<td><i>$ref{'age'}</i></td>\n".4287($curr?"<td class=\"current_head\">":"<td>") .4288$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4289-class=>"list name"},esc_html($ref{'name'})) .4290"</td>\n".4291"<td class=\"link\">".4292$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4293$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4294$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4295"</td>\n".4296"</tr>";4297}4298if(defined$extra) {4299print"<tr>\n".4300"<td colspan=\"3\">$extra</td>\n".4301"</tr>\n";4302}4303print"</table>\n";4304}43054306sub git_search_grep_body {4307my($commitlist,$from,$to,$extra) =@_;4308$from=0unlessdefined$from;4309$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);43104311print"<table class=\"commit_search\">\n";4312my$alternate=1;4313for(my$i=$from;$i<=$to;$i++) {4314my%co= %{$commitlist->[$i]};4315if(!%co) {4316next;4317}4318my$commit=$co{'id'};4319if($alternate) {4320print"<tr class=\"dark\">\n";4321}else{4322print"<tr class=\"light\">\n";4323}4324$alternate^=1;4325my$author= chop_and_escape_str($co{'author_name'},15,5);4326print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4327"<td><i>".$author."</i></td>\n".4328"<td>".4329$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4330-class=>"list subject"},4331 chop_and_escape_str($co{'title'},50) ."<br/>");4332my$comment=$co{'comment'};4333foreachmy$line(@$comment) {4334if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4335my($lead,$match,$trail) = ($1,$2,$3);4336$match= chop_str($match,70,5,'center');4337my$contextlen=int((80-length($match))/2);4338$contextlen=30if($contextlen>30);4339$lead= chop_str($lead,$contextlen,10,'left');4340$trail= chop_str($trail,$contextlen,10,'right');43414342$lead= esc_html($lead);4343$match= esc_html($match);4344$trail= esc_html($trail);43454346print"$lead<span class=\"match\">$match</span>$trail<br />";4347}4348}4349print"</td>\n".4350"<td class=\"link\">".4351$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4352" | ".4353$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4354" | ".4355$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4356print"</td>\n".4357"</tr>\n";4358}4359if(defined$extra) {4360print"<tr>\n".4361"<td colspan=\"3\">$extra</td>\n".4362"</tr>\n";4363}4364print"</table>\n";4365}43664367## ======================================================================4368## ======================================================================4369## actions43704371sub git_project_list {4372my$order=$input_params{'order'};4373if(defined$order&&$order!~m/none|project|descr|owner|age/) {4374 die_error(400,"Unknown order parameter");4375}43764377my@list= git_get_projects_list();4378if(!@list) {4379 die_error(404,"No projects found");4380}43814382 git_header_html();4383if(-f $home_text) {4384print"<div class=\"index_include\">\n";4385 insert_file($home_text);4386print"</div>\n";4387}4388print$cgi->startform(-method=>"get") .4389"<p class=\"projsearch\">Search:\n".4390$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4391"</p>".4392$cgi->end_form() ."\n";4393 git_project_list_body(\@list,$order);4394 git_footer_html();4395}43964397sub git_forks {4398my$order=$input_params{'order'};4399if(defined$order&&$order!~m/none|project|descr|owner|age/) {4400 die_error(400,"Unknown order parameter");4401}44024403my@list= git_get_projects_list($project);4404if(!@list) {4405 die_error(404,"No forks found");4406}44074408 git_header_html();4409 git_print_page_nav('','');4410 git_print_header_div('summary',"$projectforks");4411 git_project_list_body(\@list,$order);4412 git_footer_html();4413}44144415sub git_project_index {4416my@projects= git_get_projects_list($project);44174418print$cgi->header(4419-type =>'text/plain',4420-charset =>'utf-8',4421-content_disposition =>'inline; filename="index.aux"');44224423foreachmy$pr(@projects) {4424if(!exists$pr->{'owner'}) {4425$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4426}44274428my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4429# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4430$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4431$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4432$path=~s/ /\+/g;4433$owner=~s/ /\+/g;44344435print"$path$owner\n";4436}4437}44384439sub git_summary {4440my$descr= git_get_project_description($project) ||"none";4441my%co= parse_commit("HEAD");4442my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4443my$head=$co{'id'};44444445my$owner= git_get_project_owner($project);44464447my$refs= git_get_references();4448# These get_*_list functions return one more to allow us to see if4449# there are more ...4450my@taglist= git_get_tags_list(16);4451my@headlist= git_get_heads_list(16);4452my@forklist;4453my$check_forks= gitweb_check_feature('forks');44544455if($check_forks) {4456@forklist= git_get_projects_list($project);4457}44584459 git_header_html();4460 git_print_page_nav('summary','',$head);44614462print"<div class=\"title\"> </div>\n";4463print"<table class=\"projects_list\">\n".4464"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4465"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4466if(defined$cd{'rfc2822'}) {4467print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4468}44694470# use per project git URL list in $projectroot/$project/cloneurl4471# or make project git URL from git base URL and project name4472my$url_tag="URL";4473my@url_list= git_get_project_url_list($project);4474@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4475foreachmy$git_url(@url_list) {4476next unless$git_url;4477print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4478$url_tag="";4479}44804481# Tag cloud4482my$show_ctags= gitweb_check_feature('ctags');4483if($show_ctags) {4484my$ctags= git_get_project_ctags($project);4485my$cloud= git_populate_project_tagcloud($ctags);4486print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4487print"</td>\n<td>"unless%$ctags;4488print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4489print"</td>\n<td>"if%$ctags;4490print git_show_project_tagcloud($cloud,48);4491print"</td></tr>";4492}44934494print"</table>\n";44954496if(-s "$projectroot/$project/README.html") {4497print"<div class=\"title\">readme</div>\n".4498"<div class=\"readme\">\n";4499 insert_file("$projectroot/$project/README.html");4500print"\n</div>\n";# class="readme"4501}45024503# we need to request one more than 16 (0..15) to check if4504# those 16 are all4505my@commitlist=$head? parse_commits($head,17) : ();4506if(@commitlist) {4507 git_print_header_div('shortlog');4508 git_shortlog_body(\@commitlist,0,15,$refs,4509$#commitlist<=15?undef:4510$cgi->a({-href => href(action=>"shortlog")},"..."));4511}45124513if(@taglist) {4514 git_print_header_div('tags');4515 git_tags_body(\@taglist,0,15,4516$#taglist<=15?undef:4517$cgi->a({-href => href(action=>"tags")},"..."));4518}45194520if(@headlist) {4521 git_print_header_div('heads');4522 git_heads_body(\@headlist,$head,0,15,4523$#headlist<=15?undef:4524$cgi->a({-href => href(action=>"heads")},"..."));4525}45264527if(@forklist) {4528 git_print_header_div('forks');4529 git_project_list_body(\@forklist,'age',0,15,4530$#forklist<=15?undef:4531$cgi->a({-href => href(action=>"forks")},"..."),4532'no_header');4533}45344535 git_footer_html();4536}45374538sub git_tag {4539my$head= git_get_head_hash($project);4540 git_header_html();4541 git_print_page_nav('','',$head,undef,$head);4542my%tag= parse_tag($hash);45434544if(!%tag) {4545 die_error(404,"Unknown tag object");4546}45474548 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4549print"<div class=\"title_text\">\n".4550"<table class=\"object_header\">\n".4551"<tr>\n".4552"<td>object</td>\n".4553"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4554$tag{'object'}) ."</td>\n".4555"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4556$tag{'type'}) ."</td>\n".4557"</tr>\n";4558if(defined($tag{'author'})) {4559my%ad= parse_date($tag{'epoch'},$tag{'tz'});4560print"<tr><td>author</td><td>". esc_html($tag{'author'}) ."</td></tr>\n";4561print"<tr><td></td><td>".$ad{'rfc2822'} .4562sprintf(" (%02d:%02d%s)",$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'}) .4563"</td></tr>\n";4564}4565print"</table>\n\n".4566"</div>\n";4567print"<div class=\"page_body\">";4568my$comment=$tag{'comment'};4569foreachmy$line(@$comment) {4570chomp$line;4571print esc_html($line, -nbsp=>1) ."<br/>\n";4572}4573print"</div>\n";4574 git_footer_html();4575}45764577sub git_blame {4578# permissions4579 gitweb_check_feature('blame')4580or die_error(403,"Blame view not allowed");45814582# error checking4583 die_error(400,"No file name given")unless$file_name;4584$hash_base||= git_get_head_hash($project);4585 die_error(404,"Couldn't find base commit")unless$hash_base;4586my%co= parse_commit($hash_base)4587or die_error(404,"Commit not found");4588my$ftype="blob";4589if(!defined$hash) {4590$hash= git_get_hash_by_path($hash_base,$file_name,"blob")4591or die_error(404,"Error looking up file");4592}else{4593$ftype= git_get_type($hash);4594if($ftype!~"blob") {4595 die_error(400,"Object is not a blob");4596}4597}45984599# run git-blame --porcelain4600open my$fd,"-|", git_cmd(),"blame",'-p',4601$hash_base,'--',$file_name4602or die_error(500,"Open git-blame failed");46034604# page header4605 git_header_html();4606my$formats_nav=4607$cgi->a({-href => href(action=>"blob", -replay=>1)},4608"blob") .4609" | ".4610$cgi->a({-href => href(action=>"history", -replay=>1)},4611"history") .4612" | ".4613$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},4614"HEAD");4615 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4616 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4617 git_print_page_path($file_name,$ftype,$hash_base);46184619# page body4620my@rev_color=qw(light2 dark2);4621my$num_colors=scalar(@rev_color);4622my$current_color=0;4623my%metainfo= ();46244625print<<HTML;4626<div class="page_body">4627<table class="blame">4628<tr><th>Commit</th><th>Line</th><th>Data</th></tr>4629HTML4630 LINE:4631while(my$line= <$fd>) {4632chomp$line;4633# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]4634# no <lines in group> for subsequent lines in group of lines4635my($full_rev,$orig_lineno,$lineno,$group_size) =4636($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);4637if(!exists$metainfo{$full_rev}) {4638$metainfo{$full_rev} = {};4639}4640my$meta=$metainfo{$full_rev};4641my$data;4642while($data= <$fd>) {4643chomp$data;4644last if($data=~s/^\t//);# contents of line4645if($data=~/^(\S+) (.*)$/) {4646$meta->{$1} =$2;4647}4648}4649my$short_rev=substr($full_rev,0,8);4650my$author=$meta->{'author'};4651my%date=4652 parse_date($meta->{'author-time'},$meta->{'author-tz'});4653my$date=$date{'iso-tz'};4654if($group_size) {4655$current_color= ($current_color+1) %$num_colors;4656}4657print"<tr id=\"l$lineno\"class=\"$rev_color[$current_color]\">\n";4658if($group_size) {4659print"<td class=\"sha1\"";4660print" title=\"". esc_html($author) .",$date\"";4661print" rowspan=\"$group_size\""if($group_size>1);4662print">";4663print$cgi->a({-href => href(action=>"commit",4664 hash=>$full_rev,4665 file_name=>$file_name)},4666 esc_html($short_rev));4667print"</td>\n";4668}4669open(my$dd,"-|", git_cmd(),"rev-parse","$full_rev^")4670or die_error(500,"Open git-rev-parse failed");4671my$parent_commit= <$dd>;4672close$dd;4673chomp($parent_commit);4674my$blamed= href(action =>'blame',4675 file_name =>$meta->{'filename'},4676 hash_base =>$parent_commit);4677print"<td class=\"linenr\">";4678print$cgi->a({ -href =>"$blamed#l$orig_lineno",4679-class=>"linenr"},4680 esc_html($lineno));4681print"</td>";4682print"<td class=\"pre\">". esc_html($data) ."</td>\n";4683print"</tr>\n";4684}4685print"</table>\n";4686print"</div>";4687close$fd4688or print"Reading blob failed\n";46894690# page footer4691 git_footer_html();4692}46934694sub git_tags {4695my$head= git_get_head_hash($project);4696 git_header_html();4697 git_print_page_nav('','',$head,undef,$head);4698 git_print_header_div('summary',$project);46994700my@tagslist= git_get_tags_list();4701if(@tagslist) {4702 git_tags_body(\@tagslist);4703}4704 git_footer_html();4705}47064707sub git_heads {4708my$head= git_get_head_hash($project);4709 git_header_html();4710 git_print_page_nav('','',$head,undef,$head);4711 git_print_header_div('summary',$project);47124713my@headslist= git_get_heads_list();4714if(@headslist) {4715 git_heads_body(\@headslist,$head);4716}4717 git_footer_html();4718}47194720sub git_blob_plain {4721my$type=shift;4722my$expires;47234724if(!defined$hash) {4725if(defined$file_name) {4726my$base=$hash_base|| git_get_head_hash($project);4727$hash= git_get_hash_by_path($base,$file_name,"blob")4728or die_error(404,"Cannot find file");4729}else{4730 die_error(400,"No file name defined");4731}4732}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4733# blobs defined by non-textual hash id's can be cached4734$expires="+1d";4735}47364737open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4738or die_error(500,"Open git-cat-file blob '$hash' failed");47394740# content-type (can include charset)4741$type= blob_contenttype($fd,$file_name,$type);47424743# "save as" filename, even when no $file_name is given4744my$save_as="$hash";4745if(defined$file_name) {4746$save_as=$file_name;4747}elsif($type=~m/^text\//) {4748$save_as.='.txt';4749}47504751print$cgi->header(4752-type =>$type,4753-expires =>$expires,4754-content_disposition =>'inline; filename="'.$save_as.'"');4755undef$/;4756binmode STDOUT,':raw';4757print<$fd>;4758binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi4759$/="\n";4760close$fd;4761}47624763sub git_blob {4764my$expires;47654766if(!defined$hash) {4767if(defined$file_name) {4768my$base=$hash_base|| git_get_head_hash($project);4769$hash= git_get_hash_by_path($base,$file_name,"blob")4770or die_error(404,"Cannot find file");4771}else{4772 die_error(400,"No file name defined");4773}4774}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4775# blobs defined by non-textual hash id's can be cached4776$expires="+1d";4777}47784779my$have_blame= gitweb_check_feature('blame');4780open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4781or die_error(500,"Couldn't cat$file_name,$hash");4782my$mimetype= blob_mimetype($fd,$file_name);4783if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {4784close$fd;4785return git_blob_plain($mimetype);4786}4787# we can have blame only for text/* mimetype4788$have_blame&&= ($mimetype=~m!^text/!);47894790 git_header_html(undef,$expires);4791my$formats_nav='';4792if(defined$hash_base&& (my%co= parse_commit($hash_base))) {4793if(defined$file_name) {4794if($have_blame) {4795$formats_nav.=4796$cgi->a({-href => href(action=>"blame", -replay=>1)},4797"blame") .4798" | ";4799}4800$formats_nav.=4801$cgi->a({-href => href(action=>"history", -replay=>1)},4802"history") .4803" | ".4804$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},4805"raw") .4806" | ".4807$cgi->a({-href => href(action=>"blob",4808 hash_base=>"HEAD", file_name=>$file_name)},4809"HEAD");4810}else{4811$formats_nav.=4812$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},4813"raw");4814}4815 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4816 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4817}else{4818print"<div class=\"page_nav\">\n".4819"<br/><br/></div>\n".4820"<div class=\"title\">$hash</div>\n";4821}4822 git_print_page_path($file_name,"blob",$hash_base);4823print"<div class=\"page_body\">\n";4824if($mimetype=~m!^image/!) {4825print qq!<img type="$mimetype"!;4826if($file_name) {4827print qq! alt="$file_name" title="$file_name"!;4828}4829print qq! src="! .4830 href(action=>"blob_plain", hash=>$hash,4831 hash_base=>$hash_base, file_name=>$file_name) .4832 qq!"/>\n!;4833}else{4834my$nr;4835while(my$line= <$fd>) {4836chomp$line;4837$nr++;4838$line= untabify($line);4839printf"<div class=\"pre\"><a id=\"l%i\"href=\"#l%i\"class=\"linenr\">%4i</a>%s</div>\n",4840$nr,$nr,$nr, esc_html($line, -nbsp=>1);4841}4842}4843close$fd4844or print"Reading blob failed.\n";4845print"</div>";4846 git_footer_html();4847}48484849sub git_tree {4850if(!defined$hash_base) {4851$hash_base="HEAD";4852}4853if(!defined$hash) {4854if(defined$file_name) {4855$hash= git_get_hash_by_path($hash_base,$file_name,"tree");4856}else{4857$hash=$hash_base;4858}4859}4860 die_error(404,"No such tree")unlessdefined($hash);4861$/="\0";4862open my$fd,"-|", git_cmd(),"ls-tree",'-z',$hash4863or die_error(500,"Open git-ls-tree failed");4864my@entries=map{chomp;$_} <$fd>;4865close$fdor die_error(404,"Reading tree failed");4866$/="\n";48674868my$refs= git_get_references();4869my$ref= format_ref_marker($refs,$hash_base);4870 git_header_html();4871my$basedir='';4872my$have_blame= gitweb_check_feature('blame');4873if(defined$hash_base&& (my%co= parse_commit($hash_base))) {4874my@views_nav= ();4875if(defined$file_name) {4876push@views_nav,4877$cgi->a({-href => href(action=>"history", -replay=>1)},4878"history"),4879$cgi->a({-href => href(action=>"tree",4880 hash_base=>"HEAD", file_name=>$file_name)},4881"HEAD"),4882}4883my$snapshot_links= format_snapshot_links($hash);4884if(defined$snapshot_links) {4885# FIXME: Should be available when we have no hash base as well.4886push@views_nav,$snapshot_links;4887}4888 git_print_page_nav('tree','',$hash_base,undef,undef,join(' | ',@views_nav));4889 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);4890}else{4891undef$hash_base;4892print"<div class=\"page_nav\">\n";4893print"<br/><br/></div>\n";4894print"<div class=\"title\">$hash</div>\n";4895}4896if(defined$file_name) {4897$basedir=$file_name;4898if($basedirne''&&substr($basedir, -1)ne'/') {4899$basedir.='/';4900}4901 git_print_page_path($file_name,'tree',$hash_base);4902}4903print"<div class=\"page_body\">\n";4904print"<table class=\"tree\">\n";4905my$alternate=1;4906# '..' (top directory) link if possible4907if(defined$hash_base&&4908defined$file_name&&$file_name=~m![^/]+$!) {4909if($alternate) {4910print"<tr class=\"dark\">\n";4911}else{4912print"<tr class=\"light\">\n";4913}4914$alternate^=1;49154916my$up=$file_name;4917$up=~s!/?[^/]+$!!;4918undef$upunless$up;4919# based on git_print_tree_entry4920print'<td class="mode">'. mode_str('040000') ."</td>\n";4921print'<td class="list">';4922print$cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,4923 file_name=>$up)},4924"..");4925print"</td>\n";4926print"<td class=\"link\"></td>\n";49274928print"</tr>\n";4929}4930foreachmy$line(@entries) {4931my%t= parse_ls_tree_line($line, -z =>1);49324933if($alternate) {4934print"<tr class=\"dark\">\n";4935}else{4936print"<tr class=\"light\">\n";4937}4938$alternate^=1;49394940 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);49414942print"</tr>\n";4943}4944print"</table>\n".4945"</div>";4946 git_footer_html();4947}49484949sub git_snapshot {4950my$format=$input_params{'snapshot_format'};4951if(!@snapshot_fmts) {4952 die_error(403,"Snapshots not allowed");4953}4954# default to first supported snapshot format4955$format||=$snapshot_fmts[0];4956if($format!~m/^[a-z0-9]+$/) {4957 die_error(400,"Invalid snapshot format parameter");4958}elsif(!exists($known_snapshot_formats{$format})) {4959 die_error(400,"Unknown snapshot format");4960}elsif(!grep($_eq$format,@snapshot_fmts)) {4961 die_error(403,"Unsupported snapshot format");4962}49634964if(!defined$hash) {4965$hash= git_get_head_hash($project);4966}49674968my$name=$project;4969$name=~ s,([^/])/*\.git$,$1,;4970$name= basename($name);4971my$filename= to_utf8($name);4972$name=~s/\047/\047\\\047\047/g;4973my$cmd;4974$filename.="-$hash$known_snapshot_formats{$format}{'suffix'}";4975$cmd= quote_command(4976 git_cmd(),'archive',4977"--format=$known_snapshot_formats{$format}{'format'}",4978"--prefix=$name/",$hash);4979if(exists$known_snapshot_formats{$format}{'compressor'}) {4980$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});4981}49824983print$cgi->header(4984-type =>$known_snapshot_formats{$format}{'type'},4985-content_disposition =>'inline; filename="'."$filename".'"',4986-status =>'200 OK');49874988open my$fd,"-|",$cmd4989or die_error(500,"Execute git-archive failed");4990binmode STDOUT,':raw';4991print<$fd>;4992binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi4993close$fd;4994}49954996sub git_log {4997my$head= git_get_head_hash($project);4998if(!defined$hash) {4999$hash=$head;5000}5001if(!defined$page) {5002$page=0;5003}5004my$refs= git_get_references();50055006my@commitlist= parse_commits($hash,101, (100*$page));50075008my$paging_nav= format_paging_nav('log',$hash,$head,$page,$#commitlist>=100);50095010 git_header_html();5011 git_print_page_nav('log','',$hash,undef,undef,$paging_nav);50125013if(!@commitlist) {5014my%co= parse_commit($hash);50155016 git_print_header_div('summary',$project);5017print"<div class=\"page_body\"> Last change$co{'age_string'}.<br/><br/></div>\n";5018}5019my$to= ($#commitlist>=99) ? (99) : ($#commitlist);5020for(my$i=0;$i<=$to;$i++) {5021my%co= %{$commitlist[$i]};5022next if!%co;5023my$commit=$co{'id'};5024my$ref= format_ref_marker($refs,$commit);5025my%ad= parse_date($co{'author_epoch'});5026 git_print_header_div('commit',5027"<span class=\"age\">$co{'age_string'}</span>".5028 esc_html($co{'title'}) .$ref,5029$commit);5030print"<div class=\"title_text\">\n".5031"<div class=\"log_link\">\n".5032$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .5033" | ".5034$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .5035" | ".5036$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .5037"<br/>\n".5038"</div>\n".5039"<i>". esc_html($co{'author_name'}) ." [$ad{'rfc2822'}]</i><br/>\n".5040"</div>\n";50415042print"<div class=\"log_body\">\n";5043 git_print_log($co{'comment'}, -final_empty_line=>1);5044print"</div>\n";5045}5046if($#commitlist>=100) {5047print"<div class=\"page_nav\">\n";5048print$cgi->a({-href => href(-replay=>1, page=>$page+1),5049-accesskey =>"n", -title =>"Alt-n"},"next");5050print"</div>\n";5051}5052 git_footer_html();5053}50545055sub git_commit {5056$hash||=$hash_base||"HEAD";5057my%co= parse_commit($hash)5058or die_error(404,"Unknown commit object");5059my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5060my%cd= parse_date($co{'committer_epoch'},$co{'committer_tz'});50615062my$parent=$co{'parent'};5063my$parents=$co{'parents'};# listref50645065# we need to prepare $formats_nav before any parameter munging5066my$formats_nav;5067if(!defined$parent) {5068# --root commitdiff5069$formats_nav.='(initial)';5070}elsif(@$parents==1) {5071# single parent commit5072$formats_nav.=5073'(parent: '.5074$cgi->a({-href => href(action=>"commit",5075 hash=>$parent)},5076 esc_html(substr($parent,0,7))) .5077')';5078}else{5079# merge commit5080$formats_nav.=5081'(merge: '.5082join(' ',map{5083$cgi->a({-href => href(action=>"commit",5084 hash=>$_)},5085 esc_html(substr($_,0,7)));5086}@$parents) .5087')';5088}50895090if(!defined$parent) {5091$parent="--root";5092}5093my@difftree;5094open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5095@diff_opts,5096(@$parents<=1?$parent:'-c'),5097$hash,"--"5098or die_error(500,"Open git-diff-tree failed");5099@difftree=map{chomp;$_} <$fd>;5100close$fdor die_error(404,"Reading git-diff-tree failed");51015102# non-textual hash id's can be cached5103my$expires;5104if($hash=~m/^[0-9a-fA-F]{40}$/) {5105$expires="+1d";5106}5107my$refs= git_get_references();5108my$ref= format_ref_marker($refs,$co{'id'});51095110 git_header_html(undef,$expires);5111 git_print_page_nav('commit','',5112$hash,$co{'tree'},$hash,5113$formats_nav);51145115if(defined$co{'parent'}) {5116 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5117}else{5118 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5119}5120print"<div class=\"title_text\">\n".5121"<table class=\"object_header\">\n";5122print"<tr><td>author</td><td>". esc_html($co{'author'}) ."</td></tr>\n".5123"<tr>".5124"<td></td><td>$ad{'rfc2822'}";5125if($ad{'hour_local'} <6) {5126printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",5127$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});5128}else{5129printf(" (%02d:%02d%s)",5130$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});5131}5132print"</td>".5133"</tr>\n";5134print"<tr><td>committer</td><td>". esc_html($co{'committer'}) ."</td></tr>\n";5135print"<tr><td></td><td>$cd{'rfc2822'}".5136sprintf(" (%02d:%02d%s)",$cd{'hour_local'},$cd{'minute_local'},$cd{'tz_local'}) .5137"</td></tr>\n";5138print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";5139print"<tr>".5140"<td>tree</td>".5141"<td class=\"sha1\">".5142$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),5143class=>"list"},$co{'tree'}) .5144"</td>".5145"<td class=\"link\">".5146$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},5147"tree");5148my$snapshot_links= format_snapshot_links($hash);5149if(defined$snapshot_links) {5150print" | ".$snapshot_links;5151}5152print"</td>".5153"</tr>\n";51545155foreachmy$par(@$parents) {5156print"<tr>".5157"<td>parent</td>".5158"<td class=\"sha1\">".5159$cgi->a({-href => href(action=>"commit", hash=>$par),5160class=>"list"},$par) .5161"</td>".5162"<td class=\"link\">".5163$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .5164" | ".5165$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .5166"</td>".5167"</tr>\n";5168}5169print"</table>".5170"</div>\n";51715172print"<div class=\"page_body\">\n";5173 git_print_log($co{'comment'});5174print"</div>\n";51755176 git_difftree_body(\@difftree,$hash,@$parents);51775178 git_footer_html();5179}51805181sub git_object {5182# object is defined by:5183# - hash or hash_base alone5184# - hash_base and file_name5185my$type;51865187# - hash or hash_base alone5188if($hash|| ($hash_base&& !defined$file_name)) {5189my$object_id=$hash||$hash_base;51905191open my$fd,"-|", quote_command(5192 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'5193or die_error(404,"Object does not exist");5194$type= <$fd>;5195chomp$type;5196close$fd5197or die_error(404,"Object does not exist");51985199# - hash_base and file_name5200}elsif($hash_base&&defined$file_name) {5201$file_name=~ s,/+$,,;52025203system(git_cmd(),"cat-file",'-e',$hash_base) ==05204or die_error(404,"Base object does not exist");52055206# here errors should not hapen5207open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name5208or die_error(500,"Open git-ls-tree failed");5209my$line= <$fd>;5210close$fd;52115212#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'5213unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {5214 die_error(404,"File or directory for given base does not exist");5215}5216$type=$2;5217$hash=$3;5218}else{5219 die_error(400,"Not enough information to find object");5220}52215222print$cgi->redirect(-uri => href(action=>$type, -full=>1,5223 hash=>$hash, hash_base=>$hash_base,5224 file_name=>$file_name),5225-status =>'302 Found');5226}52275228sub git_blobdiff {5229my$format=shift||'html';52305231my$fd;5232my@difftree;5233my%diffinfo;5234my$expires;52355236# preparing $fd and %diffinfo for git_patchset_body5237# new style URI5238if(defined$hash_base&&defined$hash_parent_base) {5239if(defined$file_name) {5240# read raw output5241open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5242$hash_parent_base,$hash_base,5243"--", (defined$file_parent?$file_parent: ()),$file_name5244or die_error(500,"Open git-diff-tree failed");5245@difftree=map{chomp;$_} <$fd>;5246close$fd5247or die_error(404,"Reading git-diff-tree failed");5248@difftree5249or die_error(404,"Blob diff not found");52505251}elsif(defined$hash&&5252$hash=~/[0-9a-fA-F]{40}/) {5253# try to find filename from $hash52545255# read filtered raw output5256open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5257$hash_parent_base,$hash_base,"--"5258or die_error(500,"Open git-diff-tree failed");5259@difftree=5260# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5261# $hash == to_id5262grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5263map{chomp;$_} <$fd>;5264close$fd5265or die_error(404,"Reading git-diff-tree failed");5266@difftree5267or die_error(404,"Blob diff not found");52685269}else{5270 die_error(400,"Missing one of the blob diff parameters");5271}52725273if(@difftree>1) {5274 die_error(400,"Ambiguous blob diff specification");5275}52765277%diffinfo= parse_difftree_raw_line($difftree[0]);5278$file_parent||=$diffinfo{'from_file'} ||$file_name;5279$file_name||=$diffinfo{'to_file'};52805281$hash_parent||=$diffinfo{'from_id'};5282$hash||=$diffinfo{'to_id'};52835284# non-textual hash id's can be cached5285if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5286$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5287$expires='+1d';5288}52895290# open patch output5291open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5292'-p', ($formateq'html'?"--full-index": ()),5293$hash_parent_base,$hash_base,5294"--", (defined$file_parent?$file_parent: ()),$file_name5295or die_error(500,"Open git-diff-tree failed");5296}52975298# old/legacy style URI5299if(!%diffinfo&&# if new style URI failed5300defined$hash&&defined$hash_parent) {5301# fake git-diff-tree raw output5302$diffinfo{'from_mode'} =$diffinfo{'to_mode'} ="blob";5303$diffinfo{'from_id'} =$hash_parent;5304$diffinfo{'to_id'} =$hash;5305if(defined$file_name) {5306if(defined$file_parent) {5307$diffinfo{'status'} ='2';5308$diffinfo{'from_file'} =$file_parent;5309$diffinfo{'to_file'} =$file_name;5310}else{# assume not renamed5311$diffinfo{'status'} ='1';5312$diffinfo{'from_file'} =$file_name;5313$diffinfo{'to_file'} =$file_name;5314}5315}else{# no filename given5316$diffinfo{'status'} ='2';5317$diffinfo{'from_file'} =$hash_parent;5318$diffinfo{'to_file'} =$hash;5319}53205321# non-textual hash id's can be cached5322if($hash=~m/^[0-9a-fA-F]{40}$/&&5323$hash_parent=~m/^[0-9a-fA-F]{40}$/) {5324$expires='+1d';5325}53265327# open patch output5328open$fd,"-|", git_cmd(),"diff",@diff_opts,5329'-p', ($formateq'html'?"--full-index": ()),5330$hash_parent,$hash,"--"5331or die_error(500,"Open git-diff failed");5332}else{5333 die_error(400,"Missing one of the blob diff parameters")5334unless%diffinfo;5335}53365337# header5338if($formateq'html') {5339my$formats_nav=5340$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5341"raw");5342 git_header_html(undef,$expires);5343if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5344 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5345 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5346}else{5347print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5348print"<div class=\"title\">$hashvs$hash_parent</div>\n";5349}5350if(defined$file_name) {5351 git_print_page_path($file_name,"blob",$hash_base);5352}else{5353print"<div class=\"page_path\"></div>\n";5354}53555356}elsif($formateq'plain') {5357print$cgi->header(5358-type =>'text/plain',5359-charset =>'utf-8',5360-expires =>$expires,5361-content_disposition =>'inline; filename="'."$file_name".'.patch"');53625363print"X-Git-Url: ".$cgi->self_url() ."\n\n";53645365}else{5366 die_error(400,"Unknown blobdiff format");5367}53685369# patch5370if($formateq'html') {5371print"<div class=\"page_body\">\n";53725373 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5374close$fd;53755376print"</div>\n";# class="page_body"5377 git_footer_html();53785379}else{5380while(my$line= <$fd>) {5381$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5382$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;53835384print$line;53855386last if$line=~m!^\+\+\+!;5387}5388local$/=undef;5389print<$fd>;5390close$fd;5391}5392}53935394sub git_blobdiff_plain {5395 git_blobdiff('plain');5396}53975398sub git_commitdiff {5399my$format=shift||'html';5400$hash||=$hash_base||"HEAD";5401my%co= parse_commit($hash)5402or die_error(404,"Unknown commit object");54035404# choose format for commitdiff for merge5405if(!defined$hash_parent&& @{$co{'parents'}} >1) {5406$hash_parent='--cc';5407}5408# we need to prepare $formats_nav before almost any parameter munging5409my$formats_nav;5410if($formateq'html') {5411$formats_nav=5412$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},5413"raw");54145415if(defined$hash_parent&&5416$hash_parentne'-c'&&$hash_parentne'--cc') {5417# commitdiff with two commits given5418my$hash_parent_short=$hash_parent;5419if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {5420$hash_parent_short=substr($hash_parent,0,7);5421}5422$formats_nav.=5423' (from';5424for(my$i=0;$i< @{$co{'parents'}};$i++) {5425if($co{'parents'}[$i]eq$hash_parent) {5426$formats_nav.=' parent '. ($i+1);5427last;5428}5429}5430$formats_nav.=': '.5431$cgi->a({-href => href(action=>"commitdiff",5432 hash=>$hash_parent)},5433 esc_html($hash_parent_short)) .5434')';5435}elsif(!$co{'parent'}) {5436# --root commitdiff5437$formats_nav.=' (initial)';5438}elsif(scalar@{$co{'parents'}} ==1) {5439# single parent commit5440$formats_nav.=5441' (parent: '.5442$cgi->a({-href => href(action=>"commitdiff",5443 hash=>$co{'parent'})},5444 esc_html(substr($co{'parent'},0,7))) .5445')';5446}else{5447# merge commit5448if($hash_parenteq'--cc') {5449$formats_nav.=' | '.5450$cgi->a({-href => href(action=>"commitdiff",5451 hash=>$hash, hash_parent=>'-c')},5452'combined');5453}else{# $hash_parent eq '-c'5454$formats_nav.=' | '.5455$cgi->a({-href => href(action=>"commitdiff",5456 hash=>$hash, hash_parent=>'--cc')},5457'compact');5458}5459$formats_nav.=5460' (merge: '.5461join(' ',map{5462$cgi->a({-href => href(action=>"commitdiff",5463 hash=>$_)},5464 esc_html(substr($_,0,7)));5465} @{$co{'parents'}} ) .5466')';5467}5468}54695470my$hash_parent_param=$hash_parent;5471if(!defined$hash_parent_param) {5472# --cc for multiple parents, --root for parentless5473$hash_parent_param=5474@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';5475}54765477# read commitdiff5478my$fd;5479my@difftree;5480if($formateq'html') {5481open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5482"--no-commit-id","--patch-with-raw","--full-index",5483$hash_parent_param,$hash,"--"5484or die_error(500,"Open git-diff-tree failed");54855486while(my$line= <$fd>) {5487chomp$line;5488# empty line ends raw part of diff-tree output5489last unless$line;5490push@difftree,scalar parse_difftree_raw_line($line);5491}54925493}elsif($formateq'plain') {5494open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5495'-p',$hash_parent_param,$hash,"--"5496or die_error(500,"Open git-diff-tree failed");54975498}else{5499 die_error(400,"Unknown commitdiff format");5500}55015502# non-textual hash id's can be cached5503my$expires;5504if($hash=~m/^[0-9a-fA-F]{40}$/) {5505$expires="+1d";5506}55075508# write commit message5509if($formateq'html') {5510my$refs= git_get_references();5511my$ref= format_ref_marker($refs,$co{'id'});55125513 git_header_html(undef,$expires);5514 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);5515 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);5516 git_print_authorship(\%co);5517print"<div class=\"page_body\">\n";5518if(@{$co{'comment'}} >1) {5519print"<div class=\"log\">\n";5520 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);5521print"</div>\n";# class="log"5522}55235524}elsif($formateq'plain') {5525my$refs= git_get_references("tags");5526my$tagname= git_get_rev_name_tags($hash);5527my$filename= basename($project) ."-$hash.patch";55285529print$cgi->header(5530-type =>'text/plain',5531-charset =>'utf-8',5532-expires =>$expires,5533-content_disposition =>'inline; filename="'."$filename".'"');5534my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5535print"From: ". to_utf8($co{'author'}) ."\n";5536print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";5537print"Subject: ". to_utf8($co{'title'}) ."\n";55385539print"X-Git-Tag:$tagname\n"if$tagname;5540print"X-Git-Url: ".$cgi->self_url() ."\n\n";55415542foreachmy$line(@{$co{'comment'}}) {5543print to_utf8($line) ."\n";5544}5545print"---\n\n";5546}55475548# write patch5549if($formateq'html') {5550my$use_parents= !defined$hash_parent||5551$hash_parenteq'-c'||$hash_parenteq'--cc';5552 git_difftree_body(\@difftree,$hash,5553$use_parents? @{$co{'parents'}} :$hash_parent);5554print"<br/>\n";55555556 git_patchset_body($fd, \@difftree,$hash,5557$use_parents? @{$co{'parents'}} :$hash_parent);5558close$fd;5559print"</div>\n";# class="page_body"5560 git_footer_html();55615562}elsif($formateq'plain') {5563local$/=undef;5564print<$fd>;5565close$fd5566or print"Reading git-diff-tree failed\n";5567}5568}55695570sub git_commitdiff_plain {5571 git_commitdiff('plain');5572}55735574sub git_history {5575if(!defined$hash_base) {5576$hash_base= git_get_head_hash($project);5577}5578if(!defined$page) {5579$page=0;5580}5581my$ftype;5582my%co= parse_commit($hash_base)5583or die_error(404,"Unknown commit object");55845585my$refs= git_get_references();5586my$limit=sprintf("--max-count=%i", (100* ($page+1)));55875588my@commitlist= parse_commits($hash_base,101, (100*$page),5589$file_name,"--full-history")5590or die_error(404,"No such file or directory on given branch");55915592if(!defined$hash&&defined$file_name) {5593# some commits could have deleted file in question,5594# and not have it in tree, but one of them has to have it5595for(my$i=0;$i<=@commitlist;$i++) {5596$hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5597last ifdefined$hash;5598}5599}5600if(defined$hash) {5601$ftype= git_get_type($hash);5602}5603if(!defined$ftype) {5604 die_error(500,"Unknown type of object");5605}56065607my$paging_nav='';5608if($page>0) {5609$paging_nav.=5610$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,5611 file_name=>$file_name)},5612"first");5613$paging_nav.=" ⋅ ".5614$cgi->a({-href => href(-replay=>1, page=>$page-1),5615-accesskey =>"p", -title =>"Alt-p"},"prev");5616}else{5617$paging_nav.="first";5618$paging_nav.=" ⋅ prev";5619}5620my$next_link='';5621if($#commitlist>=100) {5622$next_link=5623$cgi->a({-href => href(-replay=>1, page=>$page+1),5624-accesskey =>"n", -title =>"Alt-n"},"next");5625$paging_nav.=" ⋅$next_link";5626}else{5627$paging_nav.=" ⋅ next";5628}56295630 git_header_html();5631 git_print_page_nav('history','',$hash_base,$co{'tree'},$hash_base,$paging_nav);5632 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5633 git_print_page_path($file_name,$ftype,$hash_base);56345635 git_history_body(\@commitlist,0,99,5636$refs,$hash_base,$ftype,$next_link);56375638 git_footer_html();5639}56405641sub git_search {5642 gitweb_check_feature('search')or die_error(403,"Search is disabled");5643if(!defined$searchtext) {5644 die_error(400,"Text field is empty");5645}5646if(!defined$hash) {5647$hash= git_get_head_hash($project);5648}5649my%co= parse_commit($hash);5650if(!%co) {5651 die_error(404,"Unknown commit object");5652}5653if(!defined$page) {5654$page=0;5655}56565657$searchtype||='commit';5658if($searchtypeeq'pickaxe') {5659# pickaxe may take all resources of your box and run for several minutes5660# with every query - so decide by yourself how public you make this feature5661 gitweb_check_feature('pickaxe')5662or die_error(403,"Pickaxe is disabled");5663}5664if($searchtypeeq'grep') {5665 gitweb_check_feature('grep')5666or die_error(403,"Grep is disabled");5667}56685669 git_header_html();56705671if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {5672my$greptype;5673if($searchtypeeq'commit') {5674$greptype="--grep=";5675}elsif($searchtypeeq'author') {5676$greptype="--author=";5677}elsif($searchtypeeq'committer') {5678$greptype="--committer=";5679}5680$greptype.=$searchtext;5681my@commitlist= parse_commits($hash,101, (100*$page),undef,5682$greptype,'--regexp-ignore-case',5683$search_use_regexp?'--extended-regexp':'--fixed-strings');56845685my$paging_nav='';5686if($page>0) {5687$paging_nav.=5688$cgi->a({-href => href(action=>"search", hash=>$hash,5689 searchtext=>$searchtext,5690 searchtype=>$searchtype)},5691"first");5692$paging_nav.=" ⋅ ".5693$cgi->a({-href => href(-replay=>1, page=>$page-1),5694-accesskey =>"p", -title =>"Alt-p"},"prev");5695}else{5696$paging_nav.="first";5697$paging_nav.=" ⋅ prev";5698}5699my$next_link='';5700if($#commitlist>=100) {5701$next_link=5702$cgi->a({-href => href(-replay=>1, page=>$page+1),5703-accesskey =>"n", -title =>"Alt-n"},"next");5704$paging_nav.=" ⋅$next_link";5705}else{5706$paging_nav.=" ⋅ next";5707}57085709if($#commitlist>=100) {5710}57115712 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);5713 git_print_header_div('commit', esc_html($co{'title'}),$hash);5714 git_search_grep_body(\@commitlist,0,99,$next_link);5715}57165717if($searchtypeeq'pickaxe') {5718 git_print_page_nav('','',$hash,$co{'tree'},$hash);5719 git_print_header_div('commit', esc_html($co{'title'}),$hash);57205721print"<table class=\"pickaxe search\">\n";5722my$alternate=1;5723$/="\n";5724open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,5725'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",5726($search_use_regexp?'--pickaxe-regex': ());5727undef%co;5728my@files;5729while(my$line= <$fd>) {5730chomp$line;5731next unless$line;57325733my%set= parse_difftree_raw_line($line);5734if(defined$set{'commit'}) {5735# finish previous commit5736if(%co) {5737print"</td>\n".5738"<td class=\"link\">".5739$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5740" | ".5741$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5742print"</td>\n".5743"</tr>\n";5744}57455746if($alternate) {5747print"<tr class=\"dark\">\n";5748}else{5749print"<tr class=\"light\">\n";5750}5751$alternate^=1;5752%co= parse_commit($set{'commit'});5753my$author= chop_and_escape_str($co{'author_name'},15,5);5754print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5755"<td><i>$author</i></td>\n".5756"<td>".5757$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),5758-class=>"list subject"},5759 chop_and_escape_str($co{'title'},50) ."<br/>");5760}elsif(defined$set{'to_id'}) {5761next if($set{'to_id'} =~m/^0{40}$/);57625763print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},5764 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),5765-class=>"list"},5766"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .5767"<br/>\n";5768}5769}5770close$fd;57715772# finish last commit (warning: repetition!)5773if(%co) {5774print"</td>\n".5775"<td class=\"link\">".5776$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5777" | ".5778$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5779print"</td>\n".5780"</tr>\n";5781}57825783print"</table>\n";5784}57855786if($searchtypeeq'grep') {5787 git_print_page_nav('','',$hash,$co{'tree'},$hash);5788 git_print_header_div('commit', esc_html($co{'title'}),$hash);57895790print"<table class=\"grep_search\">\n";5791my$alternate=1;5792my$matches=0;5793$/="\n";5794open my$fd,"-|", git_cmd(),'grep','-n',5795$search_use_regexp? ('-E','-i') :'-F',5796$searchtext,$co{'tree'};5797my$lastfile='';5798while(my$line= <$fd>) {5799chomp$line;5800my($file,$lno,$ltext,$binary);5801last if($matches++>1000);5802if($line=~/^Binary file (.+) matches$/) {5803$file=$1;5804$binary=1;5805}else{5806(undef,$file,$lno,$ltext) =split(/:/,$line,4);5807}5808if($filene$lastfile) {5809$lastfileand print"</td></tr>\n";5810if($alternate++) {5811print"<tr class=\"dark\">\n";5812}else{5813print"<tr class=\"light\">\n";5814}5815print"<td class=\"list\">".5816$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5817 file_name=>"$file"),5818-class=>"list"}, esc_path($file));5819print"</td><td>\n";5820$lastfile=$file;5821}5822if($binary) {5823print"<div class=\"binary\">Binary file</div>\n";5824}else{5825$ltext= untabify($ltext);5826if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {5827$ltext= esc_html($1, -nbsp=>1);5828$ltext.='<span class="match">';5829$ltext.= esc_html($2, -nbsp=>1);5830$ltext.='</span>';5831$ltext.= esc_html($3, -nbsp=>1);5832}else{5833$ltext= esc_html($ltext, -nbsp=>1);5834}5835print"<div class=\"pre\">".5836$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5837 file_name=>"$file").'#l'.$lno,5838-class=>"linenr"},sprintf('%4i',$lno))5839.' '.$ltext."</div>\n";5840}5841}5842if($lastfile) {5843print"</td></tr>\n";5844if($matches>1000) {5845print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";5846}5847}else{5848print"<div class=\"diff nodifferences\">No matches found</div>\n";5849}5850close$fd;58515852print"</table>\n";5853}5854 git_footer_html();5855}58565857sub git_search_help {5858 git_header_html();5859 git_print_page_nav('','',$hash,$hash,$hash);5860print<<EOT;5861<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without5862regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,5863the pattern entered is recognized as the POSIX extended5864<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case5865insensitive).</p>5866<dl>5867<dt><b>commit</b></dt>5868<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>5869EOT5870my$have_grep= gitweb_check_feature('grep');5871if($have_grep) {5872print<<EOT;5873<dt><b>grep</b></dt>5874<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing5875 a different one) are searched for the given pattern. On large trees, this search can take5876a while and put some strain on the server, so please use it with some consideration. Note that5877due to git-grep peculiarity, currently if regexp mode is turned off, the matches are5878case-sensitive.</dd>5879EOT5880}5881print<<EOT;5882<dt><b>author</b></dt>5883<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>5884<dt><b>committer</b></dt>5885<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>5886EOT5887my$have_pickaxe= gitweb_check_feature('pickaxe');5888if($have_pickaxe) {5889print<<EOT;5890<dt><b>pickaxe</b></dt>5891<dd>All commits that caused the string to appear or disappear from any file (changes that5892added, removed or "modified" the string) will be listed. This search can take a while and5893takes a lot of strain on the server, so please use it wisely. Note that since you may be5894interested even in changes just changing the case as well, this search is case sensitive.</dd>5895EOT5896}5897print"</dl>\n";5898 git_footer_html();5899}59005901sub git_shortlog {5902my$head= git_get_head_hash($project);5903if(!defined$hash) {5904$hash=$head;5905}5906if(!defined$page) {5907$page=0;5908}5909my$refs= git_get_references();59105911my$commit_hash=$hash;5912if(defined$hash_parent) {5913$commit_hash="$hash_parent..$hash";5914}5915my@commitlist= parse_commits($commit_hash,101, (100*$page));59165917my$paging_nav= format_paging_nav('shortlog',$hash,$head,$page,$#commitlist>=100);5918my$next_link='';5919if($#commitlist>=100) {5920$next_link=5921$cgi->a({-href => href(-replay=>1, page=>$page+1),5922-accesskey =>"n", -title =>"Alt-n"},"next");5923}59245925 git_header_html();5926 git_print_page_nav('shortlog','',$hash,$hash,$hash,$paging_nav);5927 git_print_header_div('summary',$project);59285929 git_shortlog_body(\@commitlist,0,99,$refs,$next_link);59305931 git_footer_html();5932}59335934## ......................................................................5935## feeds (RSS, Atom; OPML)59365937sub git_feed {5938my$format=shift||'atom';5939my$have_blame= gitweb_check_feature('blame');59405941# Atom: http://www.atomenabled.org/developers/syndication/5942# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ5943if($formatne'rss'&&$formatne'atom') {5944 die_error(400,"Unknown web feed format");5945}59465947# log/feed of current (HEAD) branch, log of given branch, history of file/directory5948my$head=$hash||'HEAD';5949my@commitlist= parse_commits($head,150,0,$file_name);59505951my%latest_commit;5952my%latest_date;5953my$content_type="application/$format+xml";5954if(defined$cgi->http('HTTP_ACCEPT') &&5955$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {5956# browser (feed reader) prefers text/xml5957$content_type='text/xml';5958}5959if(defined($commitlist[0])) {5960%latest_commit= %{$commitlist[0]};5961%latest_date= parse_date($latest_commit{'author_epoch'});5962print$cgi->header(5963-type =>$content_type,5964-charset =>'utf-8',5965-last_modified =>$latest_date{'rfc2822'});5966}else{5967print$cgi->header(5968-type =>$content_type,5969-charset =>'utf-8');5970}59715972# Optimization: skip generating the body if client asks only5973# for Last-Modified date.5974return if($cgi->request_method()eq'HEAD');59755976# header variables5977my$title="$site_name-$project/$action";5978my$feed_type='log';5979if(defined$hash) {5980$title.=" - '$hash'";5981$feed_type='branch log';5982if(defined$file_name) {5983$title.=" ::$file_name";5984$feed_type='history';5985}5986}elsif(defined$file_name) {5987$title.=" -$file_name";5988$feed_type='history';5989}5990$title.="$feed_type";5991my$descr= git_get_project_description($project);5992if(defined$descr) {5993$descr= esc_html($descr);5994}else{5995$descr="$project".5996($formateq'rss'?'RSS':'Atom') .5997" feed";5998}5999my$owner= git_get_project_owner($project);6000$owner= esc_html($owner);60016002#header6003my$alt_url;6004if(defined$file_name) {6005$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);6006}elsif(defined$hash) {6007$alt_url= href(-full=>1, action=>"log", hash=>$hash);6008}else{6009$alt_url= href(-full=>1, action=>"summary");6010}6011print qq!<?xml version="1.0" encoding="utf-8"?>\n!;6012if($formateq'rss') {6013print<<XML;6014<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">6015<channel>6016XML6017print"<title>$title</title>\n".6018"<link>$alt_url</link>\n".6019"<description>$descr</description>\n".6020"<language>en</language>\n";6021}elsif($formateq'atom') {6022print<<XML;6023<feed xmlns="http://www.w3.org/2005/Atom">6024XML6025print"<title>$title</title>\n".6026"<subtitle>$descr</subtitle>\n".6027'<link rel="alternate" type="text/html" href="'.6028$alt_url.'" />'."\n".6029'<link rel="self" type="'.$content_type.'" href="'.6030$cgi->self_url() .'" />'."\n".6031"<id>". href(-full=>1) ."</id>\n".6032# use project owner for feed author6033"<author><name>$owner</name></author>\n";6034if(defined$favicon) {6035print"<icon>". esc_url($favicon) ."</icon>\n";6036}6037if(defined$logo_url) {6038# not twice as wide as tall: 72 x 27 pixels6039print"<logo>". esc_url($logo) ."</logo>\n";6040}6041if(!%latest_date) {6042# dummy date to keep the feed valid until commits trickle in:6043print"<updated>1970-01-01T00:00:00Z</updated>\n";6044}else{6045print"<updated>$latest_date{'iso-8601'}</updated>\n";6046}6047}60486049# contents6050for(my$i=0;$i<=$#commitlist;$i++) {6051my%co= %{$commitlist[$i]};6052my$commit=$co{'id'};6053# we read 150, we always show 30 and the ones more recent than 48 hours6054if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6055last;6056}6057my%cd= parse_date($co{'author_epoch'});60586059# get list of changed files6060open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6061$co{'parent'} ||"--root",6062$co{'id'},"--", (defined$file_name?$file_name: ())6063ornext;6064my@difftree=map{chomp;$_} <$fd>;6065close$fd6066ornext;60676068# print element (entry, item)6069my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6070if($formateq'rss') {6071print"<item>\n".6072"<title>". esc_html($co{'title'}) ."</title>\n".6073"<author>". esc_html($co{'author'}) ."</author>\n".6074"<pubDate>$cd{'rfc2822'}</pubDate>\n".6075"<guid isPermaLink=\"true\">$co_url</guid>\n".6076"<link>$co_url</link>\n".6077"<description>". esc_html($co{'title'}) ."</description>\n".6078"<content:encoded>".6079"<![CDATA[\n";6080}elsif($formateq'atom') {6081print"<entry>\n".6082"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6083"<updated>$cd{'iso-8601'}</updated>\n".6084"<author>\n".6085" <name>". esc_html($co{'author_name'}) ."</name>\n";6086if($co{'author_email'}) {6087print" <email>". esc_html($co{'author_email'}) ."</email>\n";6088}6089print"</author>\n".6090# use committer for contributor6091"<contributor>\n".6092" <name>". esc_html($co{'committer_name'}) ."</name>\n";6093if($co{'committer_email'}) {6094print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6095}6096print"</contributor>\n".6097"<published>$cd{'iso-8601'}</published>\n".6098"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6099"<id>$co_url</id>\n".6100"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6101"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6102}6103my$comment=$co{'comment'};6104print"<pre>\n";6105foreachmy$line(@$comment) {6106$line= esc_html($line);6107print"$line\n";6108}6109print"</pre><ul>\n";6110foreachmy$difftree_line(@difftree) {6111my%difftree= parse_difftree_raw_line($difftree_line);6112next if!$difftree{'from_id'};61136114my$file=$difftree{'file'} ||$difftree{'to_file'};61156116print"<li>".6117"[".6118$cgi->a({-href => href(-full=>1, action=>"blobdiff",6119 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6120 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6121 file_name=>$file, file_parent=>$difftree{'from_file'}),6122-title =>"diff"},'D');6123if($have_blame) {6124print$cgi->a({-href => href(-full=>1, action=>"blame",6125 file_name=>$file, hash_base=>$commit),6126-title =>"blame"},'B');6127}6128# if this is not a feed of a file history6129if(!defined$file_name||$file_namene$file) {6130print$cgi->a({-href => href(-full=>1, action=>"history",6131 file_name=>$file, hash=>$commit),6132-title =>"history"},'H');6133}6134$file= esc_path($file);6135print"] ".6136"$file</li>\n";6137}6138if($formateq'rss') {6139print"</ul>]]>\n".6140"</content:encoded>\n".6141"</item>\n";6142}elsif($formateq'atom') {6143print"</ul>\n</div>\n".6144"</content>\n".6145"</entry>\n";6146}6147}61486149# end of feed6150if($formateq'rss') {6151print"</channel>\n</rss>\n";6152}elsif($formateq'atom') {6153print"</feed>\n";6154}6155}61566157sub git_rss {6158 git_feed('rss');6159}61606161sub git_atom {6162 git_feed('atom');6163}61646165sub git_opml {6166my@list= git_get_projects_list();61676168print$cgi->header(-type =>'text/xml', -charset =>'utf-8');6169print<<XML;6170<?xml version="1.0" encoding="utf-8"?>6171<opml version="1.0">6172<head>6173 <title>$site_nameOPML Export</title>6174</head>6175<body>6176<outline text="git RSS feeds">6177XML61786179foreachmy$pr(@list) {6180my%proj=%$pr;6181my$head= git_get_head_hash($proj{'path'});6182if(!defined$head) {6183next;6184}6185$git_dir="$projectroot/$proj{'path'}";6186my%co= parse_commit($head);6187if(!%co) {6188next;6189}61906191my$path= esc_html(chop_str($proj{'path'},25,5));6192my$rss="$my_url?p=$proj{'path'};a=rss";6193my$html="$my_url?p=$proj{'path'};a=summary";6194print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";6195}6196print<<XML;6197</outline>6198</body>6199</opml>6200XML6201}