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# Disables features that would allow repository owners to inject script into 136# the gitweb domain. 137our$prevent_xss=0; 138 139# information about snapshot formats that gitweb is capable of serving 140our%known_snapshot_formats= ( 141# name => { 142# 'display' => display name, 143# 'type' => mime type, 144# 'suffix' => filename suffix, 145# 'format' => --format for git-archive, 146# 'compressor' => [compressor command and arguments] 147# (array reference, optional)} 148# 149'tgz'=> { 150'display'=>'tar.gz', 151'type'=>'application/x-gzip', 152'suffix'=>'.tar.gz', 153'format'=>'tar', 154'compressor'=> ['gzip']}, 155 156'tbz2'=> { 157'display'=>'tar.bz2', 158'type'=>'application/x-bzip2', 159'suffix'=>'.tar.bz2', 160'format'=>'tar', 161'compressor'=> ['bzip2']}, 162 163'zip'=> { 164'display'=>'zip', 165'type'=>'application/x-zip', 166'suffix'=>'.zip', 167'format'=>'zip'}, 168); 169 170# Aliases so we understand old gitweb.snapshot values in repository 171# configuration. 172our%known_snapshot_format_aliases= ( 173'gzip'=>'tgz', 174'bzip2'=>'tbz2', 175 176# backward compatibility: legacy gitweb config support 177'x-gzip'=>undef,'gz'=>undef, 178'x-bzip2'=>undef,'bz2'=>undef, 179'x-zip'=>undef,''=>undef, 180); 181 182# You define site-wide feature defaults here; override them with 183# $GITWEB_CONFIG as necessary. 184our%feature= ( 185# feature => { 186# 'sub' => feature-sub (subroutine), 187# 'override' => allow-override (boolean), 188# 'default' => [ default options...] (array reference)} 189# 190# if feature is overridable (it means that allow-override has true value), 191# then feature-sub will be called with default options as parameters; 192# return value of feature-sub indicates if to enable specified feature 193# 194# if there is no 'sub' key (no feature-sub), then feature cannot be 195# overriden 196# 197# use gitweb_get_feature(<feature>) to retrieve the <feature> value 198# (an array) or gitweb_check_feature(<feature>) to check if <feature> 199# is enabled 200 201# Enable the 'blame' blob view, showing the last commit that modified 202# each line in the file. This can be very CPU-intensive. 203 204# To enable system wide have in $GITWEB_CONFIG 205# $feature{'blame'}{'default'} = [1]; 206# To have project specific config enable override in $GITWEB_CONFIG 207# $feature{'blame'}{'override'} = 1; 208# and in project config gitweb.blame = 0|1; 209'blame'=> { 210'sub'=> \&feature_blame, 211'override'=>0, 212'default'=> [0]}, 213 214# Enable the 'snapshot' link, providing a compressed archive of any 215# tree. This can potentially generate high traffic if you have large 216# project. 217 218# Value is a list of formats defined in %known_snapshot_formats that 219# you wish to offer. 220# To disable system wide have in $GITWEB_CONFIG 221# $feature{'snapshot'}{'default'} = []; 222# To have project specific config enable override in $GITWEB_CONFIG 223# $feature{'snapshot'}{'override'} = 1; 224# and in project config, a comma-separated list of formats or "none" 225# to disable. Example: gitweb.snapshot = tbz2,zip; 226'snapshot'=> { 227'sub'=> \&feature_snapshot, 228'override'=>0, 229'default'=> ['tgz']}, 230 231# Enable text search, which will list the commits which match author, 232# committer or commit text to a given string. Enabled by default. 233# Project specific override is not supported. 234'search'=> { 235'override'=>0, 236'default'=> [1]}, 237 238# Enable grep search, which will list the files in currently selected 239# tree containing the given string. Enabled by default. This can be 240# potentially CPU-intensive, of course. 241 242# To enable system wide have in $GITWEB_CONFIG 243# $feature{'grep'}{'default'} = [1]; 244# To have project specific config enable override in $GITWEB_CONFIG 245# $feature{'grep'}{'override'} = 1; 246# and in project config gitweb.grep = 0|1; 247'grep'=> { 248'sub'=> \&feature_grep, 249'override'=>0, 250'default'=> [1]}, 251 252# Enable the pickaxe search, which will list the commits that modified 253# a given string in a file. This can be practical and quite faster 254# alternative to 'blame', but still potentially CPU-intensive. 255 256# To enable system wide have in $GITWEB_CONFIG 257# $feature{'pickaxe'}{'default'} = [1]; 258# To have project specific config enable override in $GITWEB_CONFIG 259# $feature{'pickaxe'}{'override'} = 1; 260# and in project config gitweb.pickaxe = 0|1; 261'pickaxe'=> { 262'sub'=> \&feature_pickaxe, 263'override'=>0, 264'default'=> [1]}, 265 266# Make gitweb use an alternative format of the URLs which can be 267# more readable and natural-looking: project name is embedded 268# directly in the path and the query string contains other 269# auxiliary information. All gitweb installations recognize 270# URL in either format; this configures in which formats gitweb 271# generates links. 272 273# To enable system wide have in $GITWEB_CONFIG 274# $feature{'pathinfo'}{'default'} = [1]; 275# Project specific override is not supported. 276 277# Note that you will need to change the default location of CSS, 278# favicon, logo and possibly other files to an absolute URL. Also, 279# if gitweb.cgi serves as your indexfile, you will need to force 280# $my_uri to contain the script name in your $GITWEB_CONFIG. 281'pathinfo'=> { 282'override'=>0, 283'default'=> [0]}, 284 285# Make gitweb consider projects in project root subdirectories 286# to be forks of existing projects. Given project $projname.git, 287# projects matching $projname/*.git will not be shown in the main 288# projects list, instead a '+' mark will be added to $projname 289# there and a 'forks' view will be enabled for the project, listing 290# all the forks. If project list is taken from a file, forks have 291# to be listed after the main project. 292 293# To enable system wide have in $GITWEB_CONFIG 294# $feature{'forks'}{'default'} = [1]; 295# Project specific override is not supported. 296'forks'=> { 297'override'=>0, 298'default'=> [0]}, 299 300# Insert custom links to the action bar of all project pages. 301# This enables you mainly to link to third-party scripts integrating 302# into gitweb; e.g. git-browser for graphical history representation 303# or custom web-based repository administration interface. 304 305# The 'default' value consists of a list of triplets in the form 306# (label, link, position) where position is the label after which 307# to insert the link and link is a format string where %n expands 308# to the project name, %f to the project path within the filesystem, 309# %h to the current hash (h gitweb parameter) and %b to the current 310# hash base (hb gitweb parameter); %% expands to %. 311 312# To enable system wide have in $GITWEB_CONFIG e.g. 313# $feature{'actions'}{'default'} = [('graphiclog', 314# '/git-browser/by-commit.html?r=%n', 'summary')]; 315# Project specific override is not supported. 316'actions'=> { 317'override'=>0, 318'default'=> []}, 319 320# Allow gitweb scan project content tags described in ctags/ 321# of project repository, and display the popular Web 2.0-ish 322# "tag cloud" near the project list. Note that this is something 323# COMPLETELY different from the normal Git tags. 324 325# gitweb by itself can show existing tags, but it does not handle 326# tagging itself; you need an external application for that. 327# For an example script, check Girocco's cgi/tagproj.cgi. 328# You may want to install the HTML::TagCloud Perl module to get 329# a pretty tag cloud instead of just a list of tags. 330 331# To enable system wide have in $GITWEB_CONFIG 332# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 333# Project specific override is not supported. 334'ctags'=> { 335'override'=>0, 336'default'=> [0]}, 337); 338 339sub gitweb_get_feature { 340my($name) =@_; 341return unlessexists$feature{$name}; 342my($sub,$override,@defaults) = ( 343$feature{$name}{'sub'}, 344$feature{$name}{'override'}, 345@{$feature{$name}{'default'}}); 346if(!$override) {return@defaults; } 347if(!defined$sub) { 348warn"feature$nameis not overrideable"; 349return@defaults; 350} 351return$sub->(@defaults); 352} 353 354# A wrapper to check if a given feature is enabled. 355# With this, you can say 356# 357# my $bool_feat = gitweb_check_feature('bool_feat'); 358# gitweb_check_feature('bool_feat') or somecode; 359# 360# instead of 361# 362# my ($bool_feat) = gitweb_get_feature('bool_feat'); 363# (gitweb_get_feature('bool_feat'))[0] or somecode; 364# 365sub gitweb_check_feature { 366return(gitweb_get_feature(@_))[0]; 367} 368 369 370sub feature_blame { 371my($val) = git_get_project_config('blame','--bool'); 372 373if($valeq'true') { 374return1; 375}elsif($valeq'false') { 376return0; 377} 378 379return$_[0]; 380} 381 382sub feature_snapshot { 383my(@fmts) =@_; 384 385my($val) = git_get_project_config('snapshot'); 386 387if($val) { 388@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 389} 390 391return@fmts; 392} 393 394sub feature_grep { 395my($val) = git_get_project_config('grep','--bool'); 396 397if($valeq'true') { 398return(1); 399}elsif($valeq'false') { 400return(0); 401} 402 403return($_[0]); 404} 405 406sub feature_pickaxe { 407my($val) = git_get_project_config('pickaxe','--bool'); 408 409if($valeq'true') { 410return(1); 411}elsif($valeq'false') { 412return(0); 413} 414 415return($_[0]); 416} 417 418# checking HEAD file with -e is fragile if the repository was 419# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 420# and then pruned. 421sub check_head_link { 422my($dir) =@_; 423my$headfile="$dir/HEAD"; 424return((-e $headfile) || 425(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 426} 427 428sub check_export_ok { 429my($dir) =@_; 430return(check_head_link($dir) && 431(!$export_ok|| -e "$dir/$export_ok") && 432(!$export_auth_hook||$export_auth_hook->($dir))); 433} 434 435# process alternate names for backward compatibility 436# filter out unsupported (unknown) snapshot formats 437sub filter_snapshot_fmts { 438my@fmts=@_; 439 440@fmts=map{ 441exists$known_snapshot_format_aliases{$_} ? 442$known_snapshot_format_aliases{$_} :$_}@fmts; 443@fmts=grep(exists$known_snapshot_formats{$_},@fmts); 444 445} 446 447our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 448if(-e $GITWEB_CONFIG) { 449do$GITWEB_CONFIG; 450}else{ 451our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 452do$GITWEB_CONFIG_SYSTEMif-e $GITWEB_CONFIG_SYSTEM; 453} 454 455# version of the core git binary 456our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 457 458$projects_list||=$projectroot; 459 460# ====================================================================== 461# input validation and dispatch 462 463# input parameters can be collected from a variety of sources (presently, CGI 464# and PATH_INFO), so we define an %input_params hash that collects them all 465# together during validation: this allows subsequent uses (e.g. href()) to be 466# agnostic of the parameter origin 467 468our%input_params= (); 469 470# input parameters are stored with the long parameter name as key. This will 471# also be used in the href subroutine to convert parameters to their CGI 472# equivalent, and since the href() usage is the most frequent one, we store 473# the name -> CGI key mapping here, instead of the reverse. 474# 475# XXX: Warning: If you touch this, check the search form for updating, 476# too. 477 478our@cgi_param_mapping= ( 479 project =>"p", 480 action =>"a", 481 file_name =>"f", 482 file_parent =>"fp", 483 hash =>"h", 484 hash_parent =>"hp", 485 hash_base =>"hb", 486 hash_parent_base =>"hpb", 487 page =>"pg", 488 order =>"o", 489 searchtext =>"s", 490 searchtype =>"st", 491 snapshot_format =>"sf", 492 extra_options =>"opt", 493 search_use_regexp =>"sr", 494); 495our%cgi_param_mapping=@cgi_param_mapping; 496 497# we will also need to know the possible actions, for validation 498our%actions= ( 499"blame"=> \&git_blame, 500"blobdiff"=> \&git_blobdiff, 501"blobdiff_plain"=> \&git_blobdiff_plain, 502"blob"=> \&git_blob, 503"blob_plain"=> \&git_blob_plain, 504"commitdiff"=> \&git_commitdiff, 505"commitdiff_plain"=> \&git_commitdiff_plain, 506"commit"=> \&git_commit, 507"forks"=> \&git_forks, 508"heads"=> \&git_heads, 509"history"=> \&git_history, 510"log"=> \&git_log, 511"rss"=> \&git_rss, 512"atom"=> \&git_atom, 513"search"=> \&git_search, 514"search_help"=> \&git_search_help, 515"shortlog"=> \&git_shortlog, 516"summary"=> \&git_summary, 517"tag"=> \&git_tag, 518"tags"=> \&git_tags, 519"tree"=> \&git_tree, 520"snapshot"=> \&git_snapshot, 521"object"=> \&git_object, 522# those below don't need $project 523"opml"=> \&git_opml, 524"project_list"=> \&git_project_list, 525"project_index"=> \&git_project_index, 526); 527 528# finally, we have the hash of allowed extra_options for the commands that 529# allow them 530our%allowed_options= ( 531"--no-merges"=> [qw(rss atom log shortlog history)], 532); 533 534# fill %input_params with the CGI parameters. All values except for 'opt' 535# should be single values, but opt can be an array. We should probably 536# build an array of parameters that can be multi-valued, but since for the time 537# being it's only this one, we just single it out 538while(my($name,$symbol) =each%cgi_param_mapping) { 539if($symboleq'opt') { 540$input_params{$name} = [$cgi->param($symbol) ]; 541}else{ 542$input_params{$name} =$cgi->param($symbol); 543} 544} 545 546# now read PATH_INFO and update the parameter list for missing parameters 547sub evaluate_path_info { 548return ifdefined$input_params{'project'}; 549return if!$path_info; 550$path_info=~ s,^/+,,; 551return if!$path_info; 552 553# find which part of PATH_INFO is project 554my$project=$path_info; 555$project=~ s,/+$,,; 556while($project&& !check_head_link("$projectroot/$project")) { 557$project=~ s,/*[^/]*$,,; 558} 559return unless$project; 560$input_params{'project'} =$project; 561 562# do not change any parameters if an action is given using the query string 563return if$input_params{'action'}; 564$path_info=~ s,^\Q$project\E/*,,; 565 566# next, check if we have an action 567my$action=$path_info; 568$action=~ s,/.*$,,; 569if(exists$actions{$action}) { 570$path_info=~ s,^$action/*,,; 571$input_params{'action'} =$action; 572} 573 574# list of actions that want hash_base instead of hash, but can have no 575# pathname (f) parameter 576my@wants_base= ( 577'tree', 578'history', 579); 580 581# we want to catch 582# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 583my($parentrefname,$parentpathname,$refname,$pathname) = 584($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/); 585 586# first, analyze the 'current' part 587if(defined$pathname) { 588# we got "branch:filename" or "branch:dir/" 589# we could use git_get_type(branch:pathname), but: 590# - it needs $git_dir 591# - it does a git() call 592# - the convention of terminating directories with a slash 593# makes it superfluous 594# - embedding the action in the PATH_INFO would make it even 595# more superfluous 596$pathname=~ s,^/+,,; 597if(!$pathname||substr($pathname, -1)eq"/") { 598$input_params{'action'} ||="tree"; 599$pathname=~ s,/$,,; 600}else{ 601# the default action depends on whether we had parent info 602# or not 603if($parentrefname) { 604$input_params{'action'} ||="blobdiff_plain"; 605}else{ 606$input_params{'action'} ||="blob_plain"; 607} 608} 609$input_params{'hash_base'} ||=$refname; 610$input_params{'file_name'} ||=$pathname; 611}elsif(defined$refname) { 612# we got "branch". In this case we have to choose if we have to 613# set hash or hash_base. 614# 615# Most of the actions without a pathname only want hash to be 616# set, except for the ones specified in @wants_base that want 617# hash_base instead. It should also be noted that hand-crafted 618# links having 'history' as an action and no pathname or hash 619# set will fail, but that happens regardless of PATH_INFO. 620$input_params{'action'} ||="shortlog"; 621if(grep{$_eq$input_params{'action'} }@wants_base) { 622$input_params{'hash_base'} ||=$refname; 623}else{ 624$input_params{'hash'} ||=$refname; 625} 626} 627 628# next, handle the 'parent' part, if present 629if(defined$parentrefname) { 630# a missing pathspec defaults to the 'current' filename, allowing e.g. 631# someproject/blobdiff/oldrev..newrev:/filename 632if($parentpathname) { 633$parentpathname=~ s,^/+,,; 634$parentpathname=~ s,/$,,; 635$input_params{'file_parent'} ||=$parentpathname; 636}else{ 637$input_params{'file_parent'} ||=$input_params{'file_name'}; 638} 639# we assume that hash_parent_base is wanted if a path was specified, 640# or if the action wants hash_base instead of hash 641if(defined$input_params{'file_parent'} || 642grep{$_eq$input_params{'action'} }@wants_base) { 643$input_params{'hash_parent_base'} ||=$parentrefname; 644}else{ 645$input_params{'hash_parent'} ||=$parentrefname; 646} 647} 648 649# for the snapshot action, we allow URLs in the form 650# $project/snapshot/$hash.ext 651# where .ext determines the snapshot and gets removed from the 652# passed $refname to provide the $hash. 653# 654# To be able to tell that $refname includes the format extension, we 655# require the following two conditions to be satisfied: 656# - the hash input parameter MUST have been set from the $refname part 657# of the URL (i.e. they must be equal) 658# - the snapshot format MUST NOT have been defined already (e.g. from 659# CGI parameter sf) 660# It's also useless to try any matching unless $refname has a dot, 661# so we check for that too 662if(defined$input_params{'action'} && 663$input_params{'action'}eq'snapshot'&& 664defined$refname&&index($refname,'.') != -1&& 665$refnameeq$input_params{'hash'} && 666!defined$input_params{'snapshot_format'}) { 667# We loop over the known snapshot formats, checking for 668# extensions. Allowed extensions are both the defined suffix 669# (which includes the initial dot already) and the snapshot 670# format key itself, with a prepended dot 671while(my($fmt,%opt) =each%known_snapshot_formats) { 672my$hash=$refname; 673my$sfx; 674$hash=~s/(\Q$opt{'suffix'}\E|\Q.$fmt\E)$//; 675next unless$sfx=$1; 676# a valid suffix was found, so set the snapshot format 677# and reset the hash parameter 678$input_params{'snapshot_format'} =$fmt; 679$input_params{'hash'} =$hash; 680# we also set the format suffix to the one requested 681# in the URL: this way a request for e.g. .tgz returns 682# a .tgz instead of a .tar.gz 683$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 684last; 685} 686} 687} 688evaluate_path_info(); 689 690our$action=$input_params{'action'}; 691if(defined$action) { 692if(!validate_action($action)) { 693 die_error(400,"Invalid action parameter"); 694} 695} 696 697# parameters which are pathnames 698our$project=$input_params{'project'}; 699if(defined$project) { 700if(!validate_project($project)) { 701undef$project; 702 die_error(404,"No such project"); 703} 704} 705 706our$file_name=$input_params{'file_name'}; 707if(defined$file_name) { 708if(!validate_pathname($file_name)) { 709 die_error(400,"Invalid file parameter"); 710} 711} 712 713our$file_parent=$input_params{'file_parent'}; 714if(defined$file_parent) { 715if(!validate_pathname($file_parent)) { 716 die_error(400,"Invalid file parent parameter"); 717} 718} 719 720# parameters which are refnames 721our$hash=$input_params{'hash'}; 722if(defined$hash) { 723if(!validate_refname($hash)) { 724 die_error(400,"Invalid hash parameter"); 725} 726} 727 728our$hash_parent=$input_params{'hash_parent'}; 729if(defined$hash_parent) { 730if(!validate_refname($hash_parent)) { 731 die_error(400,"Invalid hash parent parameter"); 732} 733} 734 735our$hash_base=$input_params{'hash_base'}; 736if(defined$hash_base) { 737if(!validate_refname($hash_base)) { 738 die_error(400,"Invalid hash base parameter"); 739} 740} 741 742our@extra_options= @{$input_params{'extra_options'}}; 743# @extra_options is always defined, since it can only be (currently) set from 744# CGI, and $cgi->param() returns the empty array in array context if the param 745# is not set 746foreachmy$opt(@extra_options) { 747if(not exists$allowed_options{$opt}) { 748 die_error(400,"Invalid option parameter"); 749} 750if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 751 die_error(400,"Invalid option parameter for this action"); 752} 753} 754 755our$hash_parent_base=$input_params{'hash_parent_base'}; 756if(defined$hash_parent_base) { 757if(!validate_refname($hash_parent_base)) { 758 die_error(400,"Invalid hash parent base parameter"); 759} 760} 761 762# other parameters 763our$page=$input_params{'page'}; 764if(defined$page) { 765if($page=~m/[^0-9]/) { 766 die_error(400,"Invalid page parameter"); 767} 768} 769 770our$searchtype=$input_params{'searchtype'}; 771if(defined$searchtype) { 772if($searchtype=~m/[^a-z]/) { 773 die_error(400,"Invalid searchtype parameter"); 774} 775} 776 777our$search_use_regexp=$input_params{'search_use_regexp'}; 778 779our$searchtext=$input_params{'searchtext'}; 780our$search_regexp; 781if(defined$searchtext) { 782if(length($searchtext) <2) { 783 die_error(403,"At least two characters are required for search parameter"); 784} 785$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 786} 787 788# path to the current git repository 789our$git_dir; 790$git_dir="$projectroot/$project"if$project; 791 792# list of supported snapshot formats 793our@snapshot_fmts= gitweb_get_feature('snapshot'); 794@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts); 795 796# dispatch 797if(!defined$action) { 798if(defined$hash) { 799$action= git_get_type($hash); 800}elsif(defined$hash_base&&defined$file_name) { 801$action= git_get_type("$hash_base:$file_name"); 802}elsif(defined$project) { 803$action='summary'; 804}else{ 805$action='project_list'; 806} 807} 808if(!defined($actions{$action})) { 809 die_error(400,"Unknown action"); 810} 811if($action!~m/^(opml|project_list|project_index)$/&& 812!$project) { 813 die_error(400,"Project needed"); 814} 815$actions{$action}->(); 816exit; 817 818## ====================================================================== 819## action links 820 821sub href (%) { 822my%params=@_; 823# default is to use -absolute url() i.e. $my_uri 824my$href=$params{-full} ?$my_url:$my_uri; 825 826$params{'project'} =$projectunlessexists$params{'project'}; 827 828if($params{-replay}) { 829while(my($name,$symbol) =each%cgi_param_mapping) { 830if(!exists$params{$name}) { 831$params{$name} =$input_params{$name}; 832} 833} 834} 835 836my$use_pathinfo= gitweb_check_feature('pathinfo'); 837if($use_pathinfo) { 838# try to put as many parameters as possible in PATH_INFO: 839# - project name 840# - action 841# - hash_parent or hash_parent_base:/file_parent 842# - hash or hash_base:/filename 843# - the snapshot_format as an appropriate suffix 844 845# When the script is the root DirectoryIndex for the domain, 846# $href here would be something like http://gitweb.example.com/ 847# Thus, we strip any trailing / from $href, to spare us double 848# slashes in the final URL 849$href=~ s,/$,,; 850 851# Then add the project name, if present 852$href.="/".esc_url($params{'project'})ifdefined$params{'project'}; 853delete$params{'project'}; 854 855# since we destructively absorb parameters, we keep this 856# boolean that remembers if we're handling a snapshot 857my$is_snapshot=$params{'action'}eq'snapshot'; 858 859# Summary just uses the project path URL, any other action is 860# added to the URL 861if(defined$params{'action'}) { 862$href.="/".esc_url($params{'action'})unless$params{'action'}eq'summary'; 863delete$params{'action'}; 864} 865 866# Next, we put hash_parent_base:/file_parent..hash_base:/file_name, 867# stripping nonexistent or useless pieces 868$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'} 869||$params{'hash_parent'} ||$params{'hash'}); 870if(defined$params{'hash_base'}) { 871if(defined$params{'hash_parent_base'}) { 872$href.= esc_url($params{'hash_parent_base'}); 873# skip the file_parent if it's the same as the file_name 874delete$params{'file_parent'}if$params{'file_parent'}eq$params{'file_name'}; 875if(defined$params{'file_parent'} &&$params{'file_parent'} !~/\.\./) { 876$href.=":/".esc_url($params{'file_parent'}); 877delete$params{'file_parent'}; 878} 879$href.=".."; 880delete$params{'hash_parent'}; 881delete$params{'hash_parent_base'}; 882}elsif(defined$params{'hash_parent'}) { 883$href.= esc_url($params{'hash_parent'}).".."; 884delete$params{'hash_parent'}; 885} 886 887$href.= esc_url($params{'hash_base'}); 888if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) { 889$href.=":/".esc_url($params{'file_name'}); 890delete$params{'file_name'}; 891} 892delete$params{'hash'}; 893delete$params{'hash_base'}; 894}elsif(defined$params{'hash'}) { 895$href.= esc_url($params{'hash'}); 896delete$params{'hash'}; 897} 898 899# If the action was a snapshot, we can absorb the 900# snapshot_format parameter too 901if($is_snapshot) { 902my$fmt=$params{'snapshot_format'}; 903# snapshot_format should always be defined when href() 904# is called, but just in case some code forgets, we 905# fall back to the default 906$fmt||=$snapshot_fmts[0]; 907$href.=$known_snapshot_formats{$fmt}{'suffix'}; 908delete$params{'snapshot_format'}; 909} 910} 911 912# now encode the parameters explicitly 913my@result= (); 914for(my$i=0;$i<@cgi_param_mapping;$i+=2) { 915my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]); 916if(defined$params{$name}) { 917if(ref($params{$name})eq"ARRAY") { 918foreachmy$par(@{$params{$name}}) { 919push@result,$symbol."=". esc_param($par); 920} 921}else{ 922push@result,$symbol."=". esc_param($params{$name}); 923} 924} 925} 926$href.="?".join(';',@result)ifscalar@result; 927 928return$href; 929} 930 931 932## ====================================================================== 933## validation, quoting/unquoting and escaping 934 935sub validate_action { 936my$input=shift||returnundef; 937returnundefunlessexists$actions{$input}; 938return$input; 939} 940 941sub validate_project { 942my$input=shift||returnundef; 943if(!validate_pathname($input) || 944!(-d "$projectroot/$input") || 945!check_export_ok("$projectroot/$input") || 946($strict_export&& !project_in_list($input))) { 947returnundef; 948}else{ 949return$input; 950} 951} 952 953sub validate_pathname { 954my$input=shift||returnundef; 955 956# no '.' or '..' as elements of path, i.e. no '.' nor '..' 957# at the beginning, at the end, and between slashes. 958# also this catches doubled slashes 959if($input=~m!(^|/)(|\.|\.\.)(/|$)!) { 960returnundef; 961} 962# no null characters 963if($input=~m!\0!) { 964returnundef; 965} 966return$input; 967} 968 969sub validate_refname { 970my$input=shift||returnundef; 971 972# textual hashes are O.K. 973if($input=~m/^[0-9a-fA-F]{40}$/) { 974return$input; 975} 976# it must be correct pathname 977$input= validate_pathname($input) 978orreturnundef; 979# restrictions on ref name according to git-check-ref-format 980if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) { 981returnundef; 982} 983return$input; 984} 985 986# decode sequences of octets in utf8 into Perl's internal form, 987# which is utf-8 with utf8 flag set if needed. gitweb writes out 988# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning 989sub to_utf8 { 990my$str=shift; 991if(utf8::valid($str)) { 992 utf8::decode($str); 993return$str; 994}else{ 995return decode($fallback_encoding,$str, Encode::FB_DEFAULT); 996} 997} 998 999# quote unsafe chars, but keep the slash, even when it's not1000# correct, but quoted slashes look too horrible in bookmarks1001sub esc_param {1002my$str=shift;1003$str=~s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X",ord($1))/eg;1004$str=~s/\+/%2B/g;1005$str=~s/ /\+/g;1006return$str;1007}10081009# quote unsafe chars in whole URL, so some charactrs cannot be quoted1010sub esc_url {1011my$str=shift;1012$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X",ord($1))/eg;1013$str=~s/\+/%2B/g;1014$str=~s/ /\+/g;1015return$str;1016}10171018# replace invalid utf8 character with SUBSTITUTION sequence1019sub esc_html ($;%) {1020my$str=shift;1021my%opts=@_;10221023$str= to_utf8($str);1024$str=$cgi->escapeHTML($str);1025if($opts{'-nbsp'}) {1026$str=~s/ / /g;1027}1028$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1029return$str;1030}10311032# quote control characters and escape filename to HTML1033sub esc_path {1034my$str=shift;1035my%opts=@_;10361037$str= to_utf8($str);1038$str=$cgi->escapeHTML($str);1039if($opts{'-nbsp'}) {1040$str=~s/ / /g;1041}1042$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1043return$str;1044}10451046# Make control characters "printable", using character escape codes (CEC)1047sub quot_cec {1048my$cntrl=shift;1049my%opts=@_;1050my%es= (# character escape codes, aka escape sequences1051"\t"=>'\t',# tab (HT)1052"\n"=>'\n',# line feed (LF)1053"\r"=>'\r',# carrige return (CR)1054"\f"=>'\f',# form feed (FF)1055"\b"=>'\b',# backspace (BS)1056"\a"=>'\a',# alarm (bell) (BEL)1057"\e"=>'\e',# escape (ESC)1058"\013"=>'\v',# vertical tab (VT)1059"\000"=>'\0',# nul character (NUL)1060);1061my$chr= ( (exists$es{$cntrl})1062?$es{$cntrl}1063:sprintf('\%2x',ord($cntrl)) );1064if($opts{-nohtml}) {1065return$chr;1066}else{1067return"<span class=\"cntrl\">$chr</span>";1068}1069}10701071# Alternatively use unicode control pictures codepoints,1072# Unicode "printable representation" (PR)1073sub quot_upr {1074my$cntrl=shift;1075my%opts=@_;10761077my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1078if($opts{-nohtml}) {1079return$chr;1080}else{1081return"<span class=\"cntrl\">$chr</span>";1082}1083}10841085# git may return quoted and escaped filenames1086sub unquote {1087my$str=shift;10881089sub unq {1090my$seq=shift;1091my%es= (# character escape codes, aka escape sequences1092't'=>"\t",# tab (HT, TAB)1093'n'=>"\n",# newline (NL)1094'r'=>"\r",# return (CR)1095'f'=>"\f",# form feed (FF)1096'b'=>"\b",# backspace (BS)1097'a'=>"\a",# alarm (bell) (BEL)1098'e'=>"\e",# escape (ESC)1099'v'=>"\013",# vertical tab (VT)1100);11011102if($seq=~m/^[0-7]{1,3}$/) {1103# octal char sequence1104returnchr(oct($seq));1105}elsif(exists$es{$seq}) {1106# C escape sequence, aka character escape code1107return$es{$seq};1108}1109# quoted ordinary character1110return$seq;1111}11121113if($str=~m/^"(.*)"$/) {1114# needs unquoting1115$str=$1;1116$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1117}1118return$str;1119}11201121# escape tabs (convert tabs to spaces)1122sub untabify {1123my$line=shift;11241125while((my$pos=index($line,"\t")) != -1) {1126if(my$count= (8- ($pos%8))) {1127my$spaces=' ' x $count;1128$line=~s/\t/$spaces/;1129}1130}11311132return$line;1133}11341135sub project_in_list {1136my$project=shift;1137my@list= git_get_projects_list();1138return@list&&scalar(grep{$_->{'path'}eq$project}@list);1139}11401141## ----------------------------------------------------------------------1142## HTML aware string manipulation11431144# Try to chop given string on a word boundary between position1145# $len and $len+$add_len. If there is no word boundary there,1146# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1147# (marking chopped part) would be longer than given string.1148sub chop_str {1149my$str=shift;1150my$len=shift;1151my$add_len=shift||10;1152my$where=shift||'right';# 'left' | 'center' | 'right'11531154# Make sure perl knows it is utf8 encoded so we don't1155# cut in the middle of a utf8 multibyte char.1156$str= to_utf8($str);11571158# allow only $len chars, but don't cut a word if it would fit in $add_len1159# if it doesn't fit, cut it if it's still longer than the dots we would add1160# remove chopped character entities entirely11611162# when chopping in the middle, distribute $len into left and right part1163# return early if chopping wouldn't make string shorter1164if($whereeq'center') {1165return$strif($len+5>=length($str));# filler is length 51166$len=int($len/2);1167}else{1168return$strif($len+4>=length($str));# filler is length 41169}11701171# regexps: ending and beginning with word part up to $add_len1172my$endre=qr/.{$len}\w{0,$add_len}/;1173my$begre=qr/\w{0,$add_len}.{$len}/;11741175if($whereeq'left') {1176$str=~m/^(.*?)($begre)$/;1177my($lead,$body) = ($1,$2);1178if(length($lead) >4) {1179$body=~s/^[^;]*;//if($lead=~m/&[^;]*$/);1180$lead=" ...";1181}1182return"$lead$body";11831184}elsif($whereeq'center') {1185$str=~m/^($endre)(.*)$/;1186my($left,$str) = ($1,$2);1187$str=~m/^(.*?)($begre)$/;1188my($mid,$right) = ($1,$2);1189if(length($mid) >5) {1190$left=~s/&[^;]*$//;1191$right=~s/^[^;]*;//if($mid=~m/&[^;]*$/);1192$mid=" ... ";1193}1194return"$left$mid$right";11951196}else{1197$str=~m/^($endre)(.*)$/;1198my$body=$1;1199my$tail=$2;1200if(length($tail) >4) {1201$body=~s/&[^;]*$//;1202$tail="... ";1203}1204return"$body$tail";1205}1206}12071208# takes the same arguments as chop_str, but also wraps a <span> around the1209# result with a title attribute if it does get chopped. Additionally, the1210# string is HTML-escaped.1211sub chop_and_escape_str {1212my($str) =@_;12131214my$chopped= chop_str(@_);1215if($choppedeq$str) {1216return esc_html($chopped);1217}else{1218$str=~s/([[:cntrl:]])/?/g;1219return$cgi->span({-title=>$str}, esc_html($chopped));1220}1221}12221223## ----------------------------------------------------------------------1224## functions returning short strings12251226# CSS class for given age value (in seconds)1227sub age_class {1228my$age=shift;12291230if(!defined$age) {1231return"noage";1232}elsif($age<60*60*2) {1233return"age0";1234}elsif($age<60*60*24*2) {1235return"age1";1236}else{1237return"age2";1238}1239}12401241# convert age in seconds to "nn units ago" string1242sub age_string {1243my$age=shift;1244my$age_str;12451246if($age>60*60*24*365*2) {1247$age_str= (int$age/60/60/24/365);1248$age_str.=" years ago";1249}elsif($age>60*60*24*(365/12)*2) {1250$age_str=int$age/60/60/24/(365/12);1251$age_str.=" months ago";1252}elsif($age>60*60*24*7*2) {1253$age_str=int$age/60/60/24/7;1254$age_str.=" weeks ago";1255}elsif($age>60*60*24*2) {1256$age_str=int$age/60/60/24;1257$age_str.=" days ago";1258}elsif($age>60*60*2) {1259$age_str=int$age/60/60;1260$age_str.=" hours ago";1261}elsif($age>60*2) {1262$age_str=int$age/60;1263$age_str.=" min ago";1264}elsif($age>2) {1265$age_str=int$age;1266$age_str.=" sec ago";1267}else{1268$age_str.=" right now";1269}1270return$age_str;1271}12721273useconstant{1274 S_IFINVALID =>0030000,1275 S_IFGITLINK =>0160000,1276};12771278# submodule/subproject, a commit object reference1279sub S_ISGITLINK($) {1280my$mode=shift;12811282return(($mode& S_IFMT) == S_IFGITLINK)1283}12841285# convert file mode in octal to symbolic file mode string1286sub mode_str {1287my$mode=oct shift;12881289if(S_ISGITLINK($mode)) {1290return'm---------';1291}elsif(S_ISDIR($mode& S_IFMT)) {1292return'drwxr-xr-x';1293}elsif(S_ISLNK($mode)) {1294return'lrwxrwxrwx';1295}elsif(S_ISREG($mode)) {1296# git cares only about the executable bit1297if($mode& S_IXUSR) {1298return'-rwxr-xr-x';1299}else{1300return'-rw-r--r--';1301};1302}else{1303return'----------';1304}1305}13061307# convert file mode in octal to file type string1308sub file_type {1309my$mode=shift;13101311if($mode!~m/^[0-7]+$/) {1312return$mode;1313}else{1314$mode=oct$mode;1315}13161317if(S_ISGITLINK($mode)) {1318return"submodule";1319}elsif(S_ISDIR($mode& S_IFMT)) {1320return"directory";1321}elsif(S_ISLNK($mode)) {1322return"symlink";1323}elsif(S_ISREG($mode)) {1324return"file";1325}else{1326return"unknown";1327}1328}13291330# convert file mode in octal to file type description string1331sub file_type_long {1332my$mode=shift;13331334if($mode!~m/^[0-7]+$/) {1335return$mode;1336}else{1337$mode=oct$mode;1338}13391340if(S_ISGITLINK($mode)) {1341return"submodule";1342}elsif(S_ISDIR($mode& S_IFMT)) {1343return"directory";1344}elsif(S_ISLNK($mode)) {1345return"symlink";1346}elsif(S_ISREG($mode)) {1347if($mode& S_IXUSR) {1348return"executable";1349}else{1350return"file";1351};1352}else{1353return"unknown";1354}1355}135613571358## ----------------------------------------------------------------------1359## functions returning short HTML fragments, or transforming HTML fragments1360## which don't belong to other sections13611362# format line of commit message.1363sub format_log_line_html {1364my$line=shift;13651366$line= esc_html($line, -nbsp=>1);1367if($line=~m/([0-9a-fA-F]{8,40})/) {1368my$hash_text=$1;1369my$link=1370$cgi->a({-href => href(action=>"object", hash=>$hash_text),1371-class=>"text"},$hash_text);1372$line=~s/$hash_text/$link/;1373}1374return$line;1375}13761377# format marker of refs pointing to given object13781379# the destination action is chosen based on object type and current context:1380# - for annotated tags, we choose the tag view unless it's the current view1381# already, in which case we go to shortlog view1382# - for other refs, we keep the current view if we're in history, shortlog or1383# log view, and select shortlog otherwise1384sub format_ref_marker {1385my($refs,$id) =@_;1386my$markers='';13871388if(defined$refs->{$id}) {1389foreachmy$ref(@{$refs->{$id}}) {1390# this code exploits the fact that non-lightweight tags are the1391# only indirect objects, and that they are the only objects for which1392# we want to use tag instead of shortlog as action1393my($type,$name) =qw();1394my$indirect= ($ref=~s/\^\{\}$//);1395# e.g. tags/v2.6.11 or heads/next1396if($ref=~m!^(.*?)s?/(.*)$!) {1397$type=$1;1398$name=$2;1399}else{1400$type="ref";1401$name=$ref;1402}14031404my$class=$type;1405$class.=" indirect"if$indirect;14061407my$dest_action="shortlog";14081409if($indirect) {1410$dest_action="tag"unless$actioneq"tag";1411}elsif($action=~/^(history|(short)?log)$/) {1412$dest_action=$action;1413}14141415my$dest="";1416$dest.="refs/"unless$ref=~ m!^refs/!;1417$dest.=$ref;14181419my$link=$cgi->a({1420-href => href(1421 action=>$dest_action,1422 hash=>$dest1423)},$name);14241425$markers.=" <span class=\"$class\"title=\"$ref\">".1426$link."</span>";1427}1428}14291430if($markers) {1431return' <span class="refs">'.$markers.'</span>';1432}else{1433return"";1434}1435}14361437# format, perhaps shortened and with markers, title line1438sub format_subject_html {1439my($long,$short,$href,$extra) =@_;1440$extra=''unlessdefined($extra);14411442if(length($short) <length($long)) {1443return$cgi->a({-href =>$href, -class=>"list subject",1444-title => to_utf8($long)},1445 esc_html($short) .$extra);1446}else{1447return$cgi->a({-href =>$href, -class=>"list subject"},1448 esc_html($long) .$extra);1449}1450}14511452# format git diff header line, i.e. "diff --(git|combined|cc) ..."1453sub format_git_diff_header_line {1454my$line=shift;1455my$diffinfo=shift;1456my($from,$to) =@_;14571458if($diffinfo->{'nparents'}) {1459# combined diff1460$line=~s!^(diff (.*?) )"?.*$!$1!;1461if($to->{'href'}) {1462$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1463 esc_path($to->{'file'}));1464}else{# file was deleted (no href)1465$line.= esc_path($to->{'file'});1466}1467}else{1468# "ordinary" diff1469$line=~s!^(diff (.*?) )"?a/.*$!$1!;1470if($from->{'href'}) {1471$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1472'a/'. esc_path($from->{'file'}));1473}else{# file was added (no href)1474$line.='a/'. esc_path($from->{'file'});1475}1476$line.=' ';1477if($to->{'href'}) {1478$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1479'b/'. esc_path($to->{'file'}));1480}else{# file was deleted1481$line.='b/'. esc_path($to->{'file'});1482}1483}14841485return"<div class=\"diff header\">$line</div>\n";1486}14871488# format extended diff header line, before patch itself1489sub format_extended_diff_header_line {1490my$line=shift;1491my$diffinfo=shift;1492my($from,$to) =@_;14931494# match <path>1495if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1496$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1497 esc_path($from->{'file'}));1498}1499if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1500$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1501 esc_path($to->{'file'}));1502}1503# match single <mode>1504if($line=~m/\s(\d{6})$/) {1505$line.='<span class="info"> ('.1506 file_type_long($1) .1507')</span>';1508}1509# match <hash>1510if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1511# can match only for combined diff1512$line='index ';1513for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1514if($from->{'href'}[$i]) {1515$line.=$cgi->a({-href=>$from->{'href'}[$i],1516-class=>"hash"},1517substr($diffinfo->{'from_id'}[$i],0,7));1518}else{1519$line.='0' x 7;1520}1521# separator1522$line.=','if($i<$diffinfo->{'nparents'} -1);1523}1524$line.='..';1525if($to->{'href'}) {1526$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1527substr($diffinfo->{'to_id'},0,7));1528}else{1529$line.='0' x 7;1530}15311532}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1533# can match only for ordinary diff1534my($from_link,$to_link);1535if($from->{'href'}) {1536$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1537substr($diffinfo->{'from_id'},0,7));1538}else{1539$from_link='0' x 7;1540}1541if($to->{'href'}) {1542$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1543substr($diffinfo->{'to_id'},0,7));1544}else{1545$to_link='0' x 7;1546}1547my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1548$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1549}15501551return$line."<br/>\n";1552}15531554# format from-file/to-file diff header1555sub format_diff_from_to_header {1556my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1557my$line;1558my$result='';15591560$line=$from_line;1561#assert($line =~ m/^---/) if DEBUG;1562# no extra formatting for "^--- /dev/null"1563if(!$diffinfo->{'nparents'}) {1564# ordinary (single parent) diff1565if($line=~m!^--- "?a/!) {1566if($from->{'href'}) {1567$line='--- a/'.1568$cgi->a({-href=>$from->{'href'}, -class=>"path"},1569 esc_path($from->{'file'}));1570}else{1571$line='--- a/'.1572 esc_path($from->{'file'});1573}1574}1575$result.= qq!<div class="diff from_file">$line</div>\n!;15761577}else{1578# combined diff (merge commit)1579for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1580if($from->{'href'}[$i]) {1581$line='--- '.1582$cgi->a({-href=>href(action=>"blobdiff",1583 hash_parent=>$diffinfo->{'from_id'}[$i],1584 hash_parent_base=>$parents[$i],1585 file_parent=>$from->{'file'}[$i],1586 hash=>$diffinfo->{'to_id'},1587 hash_base=>$hash,1588 file_name=>$to->{'file'}),1589-class=>"path",1590-title=>"diff". ($i+1)},1591$i+1) .1592'/'.1593$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1594 esc_path($from->{'file'}[$i]));1595}else{1596$line='--- /dev/null';1597}1598$result.= qq!<div class="diff from_file">$line</div>\n!;1599}1600}16011602$line=$to_line;1603#assert($line =~ m/^\+\+\+/) if DEBUG;1604# no extra formatting for "^+++ /dev/null"1605if($line=~m!^\+\+\+ "?b/!) {1606if($to->{'href'}) {1607$line='+++ b/'.1608$cgi->a({-href=>$to->{'href'}, -class=>"path"},1609 esc_path($to->{'file'}));1610}else{1611$line='+++ b/'.1612 esc_path($to->{'file'});1613}1614}1615$result.= qq!<div class="diff to_file">$line</div>\n!;16161617return$result;1618}16191620# create note for patch simplified by combined diff1621sub format_diff_cc_simplified {1622my($diffinfo,@parents) =@_;1623my$result='';16241625$result.="<div class=\"diff header\">".1626"diff --cc ";1627if(!is_deleted($diffinfo)) {1628$result.=$cgi->a({-href => href(action=>"blob",1629 hash_base=>$hash,1630 hash=>$diffinfo->{'to_id'},1631 file_name=>$diffinfo->{'to_file'}),1632-class=>"path"},1633 esc_path($diffinfo->{'to_file'}));1634}else{1635$result.= esc_path($diffinfo->{'to_file'});1636}1637$result.="</div>\n".# class="diff header"1638"<div class=\"diff nodifferences\">".1639"Simple merge".1640"</div>\n";# class="diff nodifferences"16411642return$result;1643}16441645# format patch (diff) line (not to be used for diff headers)1646sub format_diff_line {1647my$line=shift;1648my($from,$to) =@_;1649my$diff_class="";16501651chomp$line;16521653if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1654# combined diff1655my$prefix=substr($line,0,scalar@{$from->{'href'}});1656if($line=~m/^\@{3}/) {1657$diff_class=" chunk_header";1658}elsif($line=~m/^\\/) {1659$diff_class=" incomplete";1660}elsif($prefix=~tr/+/+/) {1661$diff_class=" add";1662}elsif($prefix=~tr/-/-/) {1663$diff_class=" rem";1664}1665}else{1666# assume ordinary diff1667my$char=substr($line,0,1);1668if($chareq'+') {1669$diff_class=" add";1670}elsif($chareq'-') {1671$diff_class=" rem";1672}elsif($chareq'@') {1673$diff_class=" chunk_header";1674}elsif($chareq"\\") {1675$diff_class=" incomplete";1676}1677}1678$line= untabify($line);1679if($from&&$to&&$line=~m/^\@{2} /) {1680my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1681$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;16821683$from_lines=0unlessdefined$from_lines;1684$to_lines=0unlessdefined$to_lines;16851686if($from->{'href'}) {1687$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1688-class=>"list"},$from_text);1689}1690if($to->{'href'}) {1691$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1692-class=>"list"},$to_text);1693}1694$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1695"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1696return"<div class=\"diff$diff_class\">$line</div>\n";1697}elsif($from&&$to&&$line=~m/^\@{3}/) {1698my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1699my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);17001701@from_text=split(' ',$ranges);1702for(my$i=0;$i<@from_text; ++$i) {1703($from_start[$i],$from_nlines[$i]) =1704(split(',',substr($from_text[$i],1)),0);1705}17061707$to_text=pop@from_text;1708$to_start=pop@from_start;1709$to_nlines=pop@from_nlines;17101711$line="<span class=\"chunk_info\">$prefix";1712for(my$i=0;$i<@from_text; ++$i) {1713if($from->{'href'}[$i]) {1714$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1715-class=>"list"},$from_text[$i]);1716}else{1717$line.=$from_text[$i];1718}1719$line.=" ";1720}1721if($to->{'href'}) {1722$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1723-class=>"list"},$to_text);1724}else{1725$line.=$to_text;1726}1727$line.="$prefix</span>".1728"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1729return"<div class=\"diff$diff_class\">$line</div>\n";1730}1731return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1732}17331734# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1735# linked. Pass the hash of the tree/commit to snapshot.1736sub format_snapshot_links {1737my($hash) =@_;1738my$num_fmts=@snapshot_fmts;1739if($num_fmts>1) {1740# A parenthesized list of links bearing format names.1741# e.g. "snapshot (_tar.gz_ _zip_)"1742return"snapshot (".join(' ',map1743$cgi->a({1744-href => href(1745 action=>"snapshot",1746 hash=>$hash,1747 snapshot_format=>$_1748)1749},$known_snapshot_formats{$_}{'display'})1750,@snapshot_fmts) .")";1751}elsif($num_fmts==1) {1752# A single "snapshot" link whose tooltip bears the format name.1753# i.e. "_snapshot_"1754my($fmt) =@snapshot_fmts;1755return1756$cgi->a({1757-href => href(1758 action=>"snapshot",1759 hash=>$hash,1760 snapshot_format=>$fmt1761),1762-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"1763},"snapshot");1764}else{# $num_fmts == 01765returnundef;1766}1767}17681769## ......................................................................1770## functions returning values to be passed, perhaps after some1771## transformation, to other functions; e.g. returning arguments to href()17721773# returns hash to be passed to href to generate gitweb URL1774# in -title key it returns description of link1775sub get_feed_info {1776my$format=shift||'Atom';1777my%res= (action =>lc($format));17781779# feed links are possible only for project views1780return unless(defined$project);1781# some views should link to OPML, or to generic project feed,1782# or don't have specific feed yet (so they should use generic)1783return if($action=~/^(?:tags|heads|forks|tag|search)$/x);17841785my$branch;1786# branches refs uses 'refs/heads/' prefix (fullname) to differentiate1787# from tag links; this also makes possible to detect branch links1788if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||1789(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {1790$branch=$1;1791}1792# find log type for feed description (title)1793my$type='log';1794if(defined$file_name) {1795$type="history of$file_name";1796$type.="/"if($actioneq'tree');1797$type.=" on '$branch'"if(defined$branch);1798}else{1799$type="log of$branch"if(defined$branch);1800}18011802$res{-title} =$type;1803$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);1804$res{'file_name'} =$file_name;18051806return%res;1807}18081809## ----------------------------------------------------------------------1810## git utility subroutines, invoking git commands18111812# returns path to the core git executable and the --git-dir parameter as list1813sub git_cmd {1814return$GIT,'--git-dir='.$git_dir;1815}18161817# quote the given arguments for passing them to the shell1818# quote_command("command", "arg 1", "arg with ' and ! characters")1819# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"1820# Try to avoid using this function wherever possible.1821sub quote_command {1822returnjoin(' ',1823map( {my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_));1824}18251826# get HEAD ref of given project as hash1827sub git_get_head_hash {1828my$project=shift;1829my$o_git_dir=$git_dir;1830my$retval=undef;1831$git_dir="$projectroot/$project";1832if(open my$fd,"-|", git_cmd(),"rev-parse","--verify","HEAD") {1833my$head= <$fd>;1834close$fd;1835if(defined$head&&$head=~/^([0-9a-fA-F]{40})$/) {1836$retval=$1;1837}1838}1839if(defined$o_git_dir) {1840$git_dir=$o_git_dir;1841}1842return$retval;1843}18441845# get type of given object1846sub git_get_type {1847my$hash=shift;18481849open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;1850my$type= <$fd>;1851close$fdorreturn;1852chomp$type;1853return$type;1854}18551856# repository configuration1857our$config_file='';1858our%config;18591860# store multiple values for single key as anonymous array reference1861# single values stored directly in the hash, not as [ <value> ]1862sub hash_set_multi {1863my($hash,$key,$value) =@_;18641865if(!exists$hash->{$key}) {1866$hash->{$key} =$value;1867}elsif(!ref$hash->{$key}) {1868$hash->{$key} = [$hash->{$key},$value];1869}else{1870push@{$hash->{$key}},$value;1871}1872}18731874# return hash of git project configuration1875# optionally limited to some section, e.g. 'gitweb'1876sub git_parse_project_config {1877my$section_regexp=shift;1878my%config;18791880local$/="\0";18811882open my$fh,"-|", git_cmd(),"config",'-z','-l',1883orreturn;18841885while(my$keyval= <$fh>) {1886chomp$keyval;1887my($key,$value) =split(/\n/,$keyval,2);18881889 hash_set_multi(\%config,$key,$value)1890if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);1891}1892close$fh;18931894return%config;1895}18961897# convert config value to boolean, 'true' or 'false'1898# no value, number > 0, 'true' and 'yes' values are true1899# rest of values are treated as false (never as error)1900sub config_to_bool {1901my$val=shift;19021903# strip leading and trailing whitespace1904$val=~s/^\s+//;1905$val=~s/\s+$//;19061907return(!defined$val||# section.key1908($val=~/^\d+$/&&$val) ||# section.key = 11909($val=~/^(?:true|yes)$/i));# section.key = true1910}19111912# convert config value to simple decimal number1913# an optional value suffix of 'k', 'm', or 'g' will cause the value1914# to be multiplied by 1024, 1048576, or 10737418241915sub config_to_int {1916my$val=shift;19171918# strip leading and trailing whitespace1919$val=~s/^\s+//;1920$val=~s/\s+$//;19211922if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {1923$unit=lc($unit);1924# unknown unit is treated as 11925return$num* ($uniteq'g'?1073741824:1926$uniteq'm'?1048576:1927$uniteq'k'?1024:1);1928}1929return$val;1930}19311932# convert config value to array reference, if needed1933sub config_to_multi {1934my$val=shift;19351936returnref($val) ?$val: (defined($val) ? [$val] : []);1937}19381939sub git_get_project_config {1940my($key,$type) =@_;19411942# key sanity check1943return unless($key);1944$key=~s/^gitweb\.//;1945return if($key=~m/\W/);19461947# type sanity check1948if(defined$type) {1949$type=~s/^--//;1950$type=undef1951unless($typeeq'bool'||$typeeq'int');1952}19531954# get config1955if(!defined$config_file||1956$config_filene"$git_dir/config") {1957%config= git_parse_project_config('gitweb');1958$config_file="$git_dir/config";1959}19601961# ensure given type1962if(!defined$type) {1963return$config{"gitweb.$key"};1964}elsif($typeeq'bool') {1965# backward compatibility: 'git config --bool' returns true/false1966return config_to_bool($config{"gitweb.$key"}) ?'true':'false';1967}elsif($typeeq'int') {1968return config_to_int($config{"gitweb.$key"});1969}1970return$config{"gitweb.$key"};1971}19721973# get hash of given path at given ref1974sub git_get_hash_by_path {1975my$base=shift;1976my$path=shift||returnundef;1977my$type=shift;19781979$path=~ s,/+$,,;19801981open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path1982or die_error(500,"Open git-ls-tree failed");1983my$line= <$fd>;1984close$fdorreturnundef;19851986if(!defined$line) {1987# there is no tree or hash given by $path at $base1988returnundef;1989}19901991#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'1992$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;1993if(defined$type&&$typene$2) {1994# type doesn't match1995returnundef;1996}1997return$3;1998}19992000# get path of entry with given hash at given tree-ish (ref)2001# used to get 'from' filename for combined diff (merge commit) for renames2002sub git_get_path_by_hash {2003my$base=shift||return;2004my$hash=shift||return;20052006local$/="\0";20072008open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2009orreturnundef;2010while(my$line= <$fd>) {2011chomp$line;20122013#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2014#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2015if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2016close$fd;2017return$1;2018}2019}2020close$fd;2021returnundef;2022}20232024## ......................................................................2025## git utility functions, directly accessing git repository20262027sub git_get_project_description {2028my$path=shift;20292030$git_dir="$projectroot/$path";2031open my$fd,"$git_dir/description"2032orreturn git_get_project_config('description');2033my$descr= <$fd>;2034close$fd;2035if(defined$descr) {2036chomp$descr;2037}2038return$descr;2039}20402041sub git_get_project_ctags {2042my$path=shift;2043my$ctags= {};20442045$git_dir="$projectroot/$path";2046unless(opendir D,"$git_dir/ctags") {2047return$ctags;2048}2049foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir(D)) {2050open CT,$_ornext;2051my$val= <CT>;2052chomp$val;2053close CT;2054my$ctag=$_;$ctag=~ s#.*/##;2055$ctags->{$ctag} =$val;2056}2057closedir D;2058$ctags;2059}20602061sub git_populate_project_tagcloud {2062my$ctags=shift;20632064# First, merge different-cased tags; tags vote on casing2065my%ctags_lc;2066foreach(keys%$ctags) {2067$ctags_lc{lc$_}->{count} +=$ctags->{$_};2068if(not$ctags_lc{lc$_}->{topcount}2069or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2070$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2071$ctags_lc{lc$_}->{topname} =$_;2072}2073}20742075my$cloud;2076if(eval{require HTML::TagCloud;1; }) {2077$cloud= HTML::TagCloud->new;2078foreach(sort keys%ctags_lc) {2079# Pad the title with spaces so that the cloud looks2080# less crammed.2081my$title=$ctags_lc{$_}->{topname};2082$title=~s/ / /g;2083$title=~s/^/ /g;2084$title=~s/$/ /g;2085$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2086}2087}else{2088$cloud= \%ctags_lc;2089}2090$cloud;2091}20922093sub git_show_project_tagcloud {2094my($cloud,$count) =@_;2095print STDERR ref($cloud)."..\n";2096if(ref$cloudeq'HTML::TagCloud') {2097return$cloud->html_and_css($count);2098}else{2099my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2100return'<p align="center">'.join(', ',map{2101"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"2102}splice(@tags,0,$count)) .'</p>';2103}2104}21052106sub git_get_project_url_list {2107my$path=shift;21082109$git_dir="$projectroot/$path";2110open my$fd,"$git_dir/cloneurl"2111orreturnwantarray?2112@{ config_to_multi(git_get_project_config('url')) } :2113 config_to_multi(git_get_project_config('url'));2114my@git_project_url_list=map{chomp;$_} <$fd>;2115close$fd;21162117returnwantarray?@git_project_url_list: \@git_project_url_list;2118}21192120sub git_get_projects_list {2121my($filter) =@_;2122my@list;21232124$filter||='';2125$filter=~s/\.git$//;21262127my$check_forks= gitweb_check_feature('forks');21282129if(-d $projects_list) {2130# search in directory2131my$dir=$projects_list. ($filter?"/$filter":'');2132# remove the trailing "/"2133$dir=~s!/+$!!;2134my$pfxlen=length("$dir");2135my$pfxdepth= ($dir=~tr!/!!);21362137 File::Find::find({2138 follow_fast =>1,# follow symbolic links2139 follow_skip =>2,# ignore duplicates2140 dangling_symlinks =>0,# ignore dangling symlinks, silently2141 wanted =>sub{2142# skip project-list toplevel, if we get it.2143return if(m!^[/.]$!);2144# only directories can be git repositories2145return unless(-d $_);2146# don't traverse too deep (Find is super slow on os x)2147if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2148$File::Find::prune =1;2149return;2150}21512152my$subdir=substr($File::Find::name,$pfxlen+1);2153# we check related file in $projectroot2154my$path= ($filter?"$filter/":'') .$subdir;2155if(check_export_ok("$projectroot/$path")) {2156push@list, { path =>$path};2157$File::Find::prune =1;2158}2159},2160},"$dir");21612162}elsif(-f $projects_list) {2163# read from file(url-encoded):2164# 'git%2Fgit.git Linus+Torvalds'2165# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2166# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2167my%paths;2168open my($fd),$projects_listorreturn;2169 PROJECT:2170while(my$line= <$fd>) {2171chomp$line;2172my($path,$owner) =split' ',$line;2173$path= unescape($path);2174$owner= unescape($owner);2175if(!defined$path) {2176next;2177}2178if($filterne'') {2179# looking for forks;2180my$pfx=substr($path,0,length($filter));2181if($pfxne$filter) {2182next PROJECT;2183}2184my$sfx=substr($path,length($filter));2185if($sfx!~/^\/.*\.git$/) {2186next PROJECT;2187}2188}elsif($check_forks) {2189 PATH:2190foreachmy$filter(keys%paths) {2191# looking for forks;2192my$pfx=substr($path,0,length($filter));2193if($pfxne$filter) {2194next PATH;2195}2196my$sfx=substr($path,length($filter));2197if($sfx!~/^\/.*\.git$/) {2198next PATH;2199}2200# is a fork, don't include it in2201# the list2202next PROJECT;2203}2204}2205if(check_export_ok("$projectroot/$path")) {2206my$pr= {2207 path =>$path,2208 owner => to_utf8($owner),2209};2210push@list,$pr;2211(my$forks_path=$path) =~s/\.git$//;2212$paths{$forks_path}++;2213}2214}2215close$fd;2216}2217return@list;2218}22192220our$gitweb_project_owner=undef;2221sub git_get_project_list_from_file {22222223return if(defined$gitweb_project_owner);22242225$gitweb_project_owner= {};2226# read from file (url-encoded):2227# 'git%2Fgit.git Linus+Torvalds'2228# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2229# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2230if(-f $projects_list) {2231open(my$fd,$projects_list);2232while(my$line= <$fd>) {2233chomp$line;2234my($pr,$ow) =split' ',$line;2235$pr= unescape($pr);2236$ow= unescape($ow);2237$gitweb_project_owner->{$pr} = to_utf8($ow);2238}2239close$fd;2240}2241}22422243sub git_get_project_owner {2244my$project=shift;2245my$owner;22462247returnundefunless$project;2248$git_dir="$projectroot/$project";22492250if(!defined$gitweb_project_owner) {2251 git_get_project_list_from_file();2252}22532254if(exists$gitweb_project_owner->{$project}) {2255$owner=$gitweb_project_owner->{$project};2256}2257if(!defined$owner){2258$owner= git_get_project_config('owner');2259}2260if(!defined$owner) {2261$owner= get_file_owner("$git_dir");2262}22632264return$owner;2265}22662267sub git_get_last_activity {2268my($path) =@_;2269my$fd;22702271$git_dir="$projectroot/$path";2272open($fd,"-|", git_cmd(),'for-each-ref',2273'--format=%(committer)',2274'--sort=-committerdate',2275'--count=1',2276'refs/heads')orreturn;2277my$most_recent= <$fd>;2278close$fdorreturn;2279if(defined$most_recent&&2280$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2281my$timestamp=$1;2282my$age=time-$timestamp;2283return($age, age_string($age));2284}2285return(undef,undef);2286}22872288sub git_get_references {2289my$type=shift||"";2290my%refs;2291# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112292# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2293open my$fd,"-|", git_cmd(),"show-ref","--dereference",2294($type? ("--","refs/$type") : ())# use -- <pattern> if $type2295orreturn;22962297while(my$line= <$fd>) {2298chomp$line;2299if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2300if(defined$refs{$1}) {2301push@{$refs{$1}},$2;2302}else{2303$refs{$1} = [$2];2304}2305}2306}2307close$fdorreturn;2308return \%refs;2309}23102311sub git_get_rev_name_tags {2312my$hash=shift||returnundef;23132314open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2315orreturn;2316my$name_rev= <$fd>;2317close$fd;23182319if($name_rev=~ m|^$hash tags/(.*)$|) {2320return$1;2321}else{2322# catches also '$hash undefined' output2323returnundef;2324}2325}23262327## ----------------------------------------------------------------------2328## parse to hash functions23292330sub parse_date {2331my$epoch=shift;2332my$tz=shift||"-0000";23332334my%date;2335my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2336my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2337my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2338$date{'hour'} =$hour;2339$date{'minute'} =$min;2340$date{'mday'} =$mday;2341$date{'day'} =$days[$wday];2342$date{'month'} =$months[$mon];2343$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2344$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2345$date{'mday-time'} =sprintf"%d%s%02d:%02d",2346$mday,$months[$mon],$hour,$min;2347$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",23481900+$year,1+$mon,$mday,$hour,$min,$sec;23492350$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2351my$local=$epoch+ ((int$1+ ($2/60)) *3600);2352($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2353$date{'hour_local'} =$hour;2354$date{'minute_local'} =$min;2355$date{'tz_local'} =$tz;2356$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",23571900+$year,$mon+1,$mday,2358$hour,$min,$sec,$tz);2359return%date;2360}23612362sub parse_tag {2363my$tag_id=shift;2364my%tag;2365my@comment;23662367open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2368$tag{'id'} =$tag_id;2369while(my$line= <$fd>) {2370chomp$line;2371if($line=~m/^object ([0-9a-fA-F]{40})$/) {2372$tag{'object'} =$1;2373}elsif($line=~m/^type (.+)$/) {2374$tag{'type'} =$1;2375}elsif($line=~m/^tag (.+)$/) {2376$tag{'name'} =$1;2377}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2378$tag{'author'} =$1;2379$tag{'epoch'} =$2;2380$tag{'tz'} =$3;2381}elsif($line=~m/--BEGIN/) {2382push@comment,$line;2383last;2384}elsif($lineeq"") {2385last;2386}2387}2388push@comment, <$fd>;2389$tag{'comment'} = \@comment;2390close$fdorreturn;2391if(!defined$tag{'name'}) {2392return2393};2394return%tag2395}23962397sub parse_commit_text {2398my($commit_text,$withparents) =@_;2399my@commit_lines=split'\n',$commit_text;2400my%co;24012402pop@commit_lines;# Remove '\0'24032404if(!@commit_lines) {2405return;2406}24072408my$header=shift@commit_lines;2409if($header!~m/^[0-9a-fA-F]{40}/) {2410return;2411}2412($co{'id'},my@parents) =split' ',$header;2413while(my$line=shift@commit_lines) {2414last if$lineeq"\n";2415if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2416$co{'tree'} =$1;2417}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2418push@parents,$1;2419}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2420$co{'author'} =$1;2421$co{'author_epoch'} =$2;2422$co{'author_tz'} =$3;2423if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2424$co{'author_name'} =$1;2425$co{'author_email'} =$2;2426}else{2427$co{'author_name'} =$co{'author'};2428}2429}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2430$co{'committer'} =$1;2431$co{'committer_epoch'} =$2;2432$co{'committer_tz'} =$3;2433$co{'committer_name'} =$co{'committer'};2434if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2435$co{'committer_name'} =$1;2436$co{'committer_email'} =$2;2437}else{2438$co{'committer_name'} =$co{'committer'};2439}2440}2441}2442if(!defined$co{'tree'}) {2443return;2444};2445$co{'parents'} = \@parents;2446$co{'parent'} =$parents[0];24472448foreachmy$title(@commit_lines) {2449$title=~s/^ //;2450if($titlene"") {2451$co{'title'} = chop_str($title,80,5);2452# remove leading stuff of merges to make the interesting part visible2453if(length($title) >50) {2454$title=~s/^Automatic //;2455$title=~s/^merge (of|with) /Merge ... /i;2456if(length($title) >50) {2457$title=~s/(http|rsync):\/\///;2458}2459if(length($title) >50) {2460$title=~s/(master|www|rsync)\.//;2461}2462if(length($title) >50) {2463$title=~s/kernel.org:?//;2464}2465if(length($title) >50) {2466$title=~s/\/pub\/scm//;2467}2468}2469$co{'title_short'} = chop_str($title,50,5);2470last;2471}2472}2473if(!defined$co{'title'} ||$co{'title'}eq"") {2474$co{'title'} =$co{'title_short'} ='(no commit message)';2475}2476# remove added spaces2477foreachmy$line(@commit_lines) {2478$line=~s/^ //;2479}2480$co{'comment'} = \@commit_lines;24812482my$age=time-$co{'committer_epoch'};2483$co{'age'} =$age;2484$co{'age_string'} = age_string($age);2485my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2486if($age>60*60*24*7*2) {2487$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2488$co{'age_string_age'} =$co{'age_string'};2489}else{2490$co{'age_string_date'} =$co{'age_string'};2491$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2492}2493return%co;2494}24952496sub parse_commit {2497my($commit_id) =@_;2498my%co;24992500local$/="\0";25012502open my$fd,"-|", git_cmd(),"rev-list",2503"--parents",2504"--header",2505"--max-count=1",2506$commit_id,2507"--",2508or die_error(500,"Open git-rev-list failed");2509%co= parse_commit_text(<$fd>,1);2510close$fd;25112512return%co;2513}25142515sub parse_commits {2516my($commit_id,$maxcount,$skip,$filename,@args) =@_;2517my@cos;25182519$maxcount||=1;2520$skip||=0;25212522local$/="\0";25232524open my$fd,"-|", git_cmd(),"rev-list",2525"--header",2526@args,2527("--max-count=".$maxcount),2528("--skip=".$skip),2529@extra_options,2530$commit_id,2531"--",2532($filename? ($filename) : ())2533or die_error(500,"Open git-rev-list failed");2534while(my$line= <$fd>) {2535my%co= parse_commit_text($line);2536push@cos, \%co;2537}2538close$fd;25392540returnwantarray?@cos: \@cos;2541}25422543# parse line of git-diff-tree "raw" output2544sub parse_difftree_raw_line {2545my$line=shift;2546my%res;25472548# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2549# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2550if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2551$res{'from_mode'} =$1;2552$res{'to_mode'} =$2;2553$res{'from_id'} =$3;2554$res{'to_id'} =$4;2555$res{'status'} =$5;2556$res{'similarity'} =$6;2557if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2558($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2559}else{2560$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2561}2562}2563# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2564# combined diff (for merge commit)2565elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2566$res{'nparents'} =length($1);2567$res{'from_mode'} = [split(' ',$2) ];2568$res{'to_mode'} =pop@{$res{'from_mode'}};2569$res{'from_id'} = [split(' ',$3) ];2570$res{'to_id'} =pop@{$res{'from_id'}};2571$res{'status'} = [split('',$4) ];2572$res{'to_file'} = unquote($5);2573}2574# 'c512b523472485aef4fff9e57b229d9d243c967f'2575elsif($line=~m/^([0-9a-fA-F]{40})$/) {2576$res{'commit'} =$1;2577}25782579returnwantarray?%res: \%res;2580}25812582# wrapper: return parsed line of git-diff-tree "raw" output2583# (the argument might be raw line, or parsed info)2584sub parsed_difftree_line {2585my$line_or_ref=shift;25862587if(ref($line_or_ref)eq"HASH") {2588# pre-parsed (or generated by hand)2589return$line_or_ref;2590}else{2591return parse_difftree_raw_line($line_or_ref);2592}2593}25942595# parse line of git-ls-tree output2596sub parse_ls_tree_line ($;%) {2597my$line=shift;2598my%opts=@_;2599my%res;26002601#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2602$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;26032604$res{'mode'} =$1;2605$res{'type'} =$2;2606$res{'hash'} =$3;2607if($opts{'-z'}) {2608$res{'name'} =$4;2609}else{2610$res{'name'} = unquote($4);2611}26122613returnwantarray?%res: \%res;2614}26152616# generates _two_ hashes, references to which are passed as 2 and 3 argument2617sub parse_from_to_diffinfo {2618my($diffinfo,$from,$to,@parents) =@_;26192620if($diffinfo->{'nparents'}) {2621# combined diff2622$from->{'file'} = [];2623$from->{'href'} = [];2624 fill_from_file_info($diffinfo,@parents)2625unlessexists$diffinfo->{'from_file'};2626for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2627$from->{'file'}[$i] =2628defined$diffinfo->{'from_file'}[$i] ?2629$diffinfo->{'from_file'}[$i] :2630$diffinfo->{'to_file'};2631if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2632$from->{'href'}[$i] = href(action=>"blob",2633 hash_base=>$parents[$i],2634 hash=>$diffinfo->{'from_id'}[$i],2635 file_name=>$from->{'file'}[$i]);2636}else{2637$from->{'href'}[$i] =undef;2638}2639}2640}else{2641# ordinary (not combined) diff2642$from->{'file'} =$diffinfo->{'from_file'};2643if($diffinfo->{'status'}ne"A") {# not new (added) file2644$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2645 hash=>$diffinfo->{'from_id'},2646 file_name=>$from->{'file'});2647}else{2648delete$from->{'href'};2649}2650}26512652$to->{'file'} =$diffinfo->{'to_file'};2653if(!is_deleted($diffinfo)) {# file exists in result2654$to->{'href'} = href(action=>"blob", hash_base=>$hash,2655 hash=>$diffinfo->{'to_id'},2656 file_name=>$to->{'file'});2657}else{2658delete$to->{'href'};2659}2660}26612662## ......................................................................2663## parse to array of hashes functions26642665sub git_get_heads_list {2666my$limit=shift;2667my@headslist;26682669open my$fd,'-|', git_cmd(),'for-each-ref',2670($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2671'--format=%(objectname) %(refname) %(subject)%00%(committer)',2672'refs/heads'2673orreturn;2674while(my$line= <$fd>) {2675my%ref_item;26762677chomp$line;2678my($refinfo,$committerinfo) =split(/\0/,$line);2679my($hash,$name,$title) =split(' ',$refinfo,3);2680my($committer,$epoch,$tz) =2681($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2682$ref_item{'fullname'} =$name;2683$name=~s!^refs/heads/!!;26842685$ref_item{'name'} =$name;2686$ref_item{'id'} =$hash;2687$ref_item{'title'} =$title||'(no commit message)';2688$ref_item{'epoch'} =$epoch;2689if($epoch) {2690$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2691}else{2692$ref_item{'age'} ="unknown";2693}26942695push@headslist, \%ref_item;2696}2697close$fd;26982699returnwantarray?@headslist: \@headslist;2700}27012702sub git_get_tags_list {2703my$limit=shift;2704my@tagslist;27052706open my$fd,'-|', git_cmd(),'for-each-ref',2707($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',2708'--format=%(objectname) %(objecttype) %(refname) '.2709'%(*objectname) %(*objecttype) %(subject)%00%(creator)',2710'refs/tags'2711orreturn;2712while(my$line= <$fd>) {2713my%ref_item;27142715chomp$line;2716my($refinfo,$creatorinfo) =split(/\0/,$line);2717my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);2718my($creator,$epoch,$tz) =2719($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);2720$ref_item{'fullname'} =$name;2721$name=~s!^refs/tags/!!;27222723$ref_item{'type'} =$type;2724$ref_item{'id'} =$id;2725$ref_item{'name'} =$name;2726if($typeeq"tag") {2727$ref_item{'subject'} =$title;2728$ref_item{'reftype'} =$reftype;2729$ref_item{'refid'} =$refid;2730}else{2731$ref_item{'reftype'} =$type;2732$ref_item{'refid'} =$id;2733}27342735if($typeeq"tag"||$typeeq"commit") {2736$ref_item{'epoch'} =$epoch;2737if($epoch) {2738$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2739}else{2740$ref_item{'age'} ="unknown";2741}2742}27432744push@tagslist, \%ref_item;2745}2746close$fd;27472748returnwantarray?@tagslist: \@tagslist;2749}27502751## ----------------------------------------------------------------------2752## filesystem-related functions27532754sub get_file_owner {2755my$path=shift;27562757my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);2758my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);2759if(!defined$gcos) {2760returnundef;2761}2762my$owner=$gcos;2763$owner=~s/[,;].*$//;2764return to_utf8($owner);2765}27662767# assume that file exists2768sub insert_file {2769my$filename=shift;27702771open my$fd,'<',$filename;2772print map{ to_utf8($_) } <$fd>;2773close$fd;2774}27752776## ......................................................................2777## mimetype related functions27782779sub mimetype_guess_file {2780my$filename=shift;2781my$mimemap=shift;2782-r $mimemaporreturnundef;27832784my%mimemap;2785open(MIME,$mimemap)orreturnundef;2786while(<MIME>) {2787next ifm/^#/;# skip comments2788my($mime,$exts) =split(/\t+/);2789if(defined$exts) {2790my@exts=split(/\s+/,$exts);2791foreachmy$ext(@exts) {2792$mimemap{$ext} =$mime;2793}2794}2795}2796close(MIME);27972798$filename=~/\.([^.]*)$/;2799return$mimemap{$1};2800}28012802sub mimetype_guess {2803my$filename=shift;2804my$mime;2805$filename=~/\./orreturnundef;28062807if($mimetypes_file) {2808my$file=$mimetypes_file;2809if($file!~m!^/!) {# if it is relative path2810# it is relative to project2811$file="$projectroot/$project/$file";2812}2813$mime= mimetype_guess_file($filename,$file);2814}2815$mime||= mimetype_guess_file($filename,'/etc/mime.types');2816return$mime;2817}28182819sub blob_mimetype {2820my$fd=shift;2821my$filename=shift;28222823if($filename) {2824my$mime= mimetype_guess($filename);2825$mimeandreturn$mime;2826}28272828# just in case2829return$default_blob_plain_mimetypeunless$fd;28302831if(-T $fd) {2832return'text/plain';2833}elsif(!$filename) {2834return'application/octet-stream';2835}elsif($filename=~m/\.png$/i) {2836return'image/png';2837}elsif($filename=~m/\.gif$/i) {2838return'image/gif';2839}elsif($filename=~m/\.jpe?g$/i) {2840return'image/jpeg';2841}else{2842return'application/octet-stream';2843}2844}28452846sub blob_contenttype {2847my($fd,$file_name,$type) =@_;28482849$type||= blob_mimetype($fd,$file_name);2850if($typeeq'text/plain'&&defined$default_text_plain_charset) {2851$type.="; charset=$default_text_plain_charset";2852}28532854return$type;2855}28562857## ======================================================================2858## functions printing HTML: header, footer, error page28592860sub git_header_html {2861my$status=shift||"200 OK";2862my$expires=shift;28632864my$title="$site_name";2865if(defined$project) {2866$title.=" - ". to_utf8($project);2867if(defined$action) {2868$title.="/$action";2869if(defined$file_name) {2870$title.=" - ". esc_path($file_name);2871if($actioneq"tree"&&$file_name!~ m|/$|) {2872$title.="/";2873}2874}2875}2876}2877my$content_type;2878# require explicit support from the UA if we are to send the page as2879# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.2880# we have to do this because MSIE sometimes globs '*/*', pretending to2881# support xhtml+xml but choking when it gets what it asked for.2882if(defined$cgi->http('HTTP_ACCEPT') &&2883$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&2884$cgi->Accept('application/xhtml+xml') !=0) {2885$content_type='application/xhtml+xml';2886}else{2887$content_type='text/html';2888}2889print$cgi->header(-type=>$content_type, -charset =>'utf-8',2890-status=>$status, -expires =>$expires);2891my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';2892print<<EOF;2893<?xml version="1.0" encoding="utf-8"?>2894<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">2895<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">2896<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->2897<!-- git core binaries version$git_version-->2898<head>2899<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>2900<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>2901<meta name="robots" content="index, nofollow"/>2902<title>$title</title>2903EOF2904# print out each stylesheet that exist2905if(defined$stylesheet) {2906#provides backwards capability for those people who define style sheet in a config file2907print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";2908}else{2909foreachmy$stylesheet(@stylesheets) {2910next unless$stylesheet;2911print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";2912}2913}2914if(defined$project) {2915my%href_params= get_feed_info();2916if(!exists$href_params{'-title'}) {2917$href_params{'-title'} ='log';2918}29192920foreachmy$formatqw(RSS Atom){2921my$type=lc($format);2922my%link_attr= (2923'-rel'=>'alternate',2924'-title'=>"$project-$href_params{'-title'} -$formatfeed",2925'-type'=>"application/$type+xml"2926);29272928$href_params{'action'} =$type;2929$link_attr{'-href'} = href(%href_params);2930print"<link ".2931"rel=\"$link_attr{'-rel'}\"".2932"title=\"$link_attr{'-title'}\"".2933"href=\"$link_attr{'-href'}\"".2934"type=\"$link_attr{'-type'}\"".2935"/>\n";29362937$href_params{'extra_options'} ='--no-merges';2938$link_attr{'-href'} = href(%href_params);2939$link_attr{'-title'} .=' (no merges)';2940print"<link ".2941"rel=\"$link_attr{'-rel'}\"".2942"title=\"$link_attr{'-title'}\"".2943"href=\"$link_attr{'-href'}\"".2944"type=\"$link_attr{'-type'}\"".2945"/>\n";2946}29472948}else{2949printf('<link rel="alternate" title="%sprojects list" '.2950'href="%s" type="text/plain; charset=utf-8" />'."\n",2951$site_name, href(project=>undef, action=>"project_index"));2952printf('<link rel="alternate" title="%sprojects feeds" '.2953'href="%s" type="text/x-opml" />'."\n",2954$site_name, href(project=>undef, action=>"opml"));2955}2956if(defined$favicon) {2957printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);2958}29592960print"</head>\n".2961"<body>\n";29622963if(-f $site_header) {2964 insert_file($site_header);2965}29662967print"<div class=\"page_header\">\n".2968$cgi->a({-href => esc_url($logo_url),2969-title =>$logo_label},2970qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));2971print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";2972if(defined$project) {2973print$cgi->a({-href => href(action=>"summary")}, esc_html($project));2974if(defined$action) {2975print" /$action";2976}2977print"\n";2978}2979print"</div>\n";29802981my$have_search= gitweb_check_feature('search');2982if(defined$project&&$have_search) {2983if(!defined$searchtext) {2984$searchtext="";2985}2986my$search_hash;2987if(defined$hash_base) {2988$search_hash=$hash_base;2989}elsif(defined$hash) {2990$search_hash=$hash;2991}else{2992$search_hash="HEAD";2993}2994my$action=$my_uri;2995my$use_pathinfo= gitweb_check_feature('pathinfo');2996if($use_pathinfo) {2997$action.="/".esc_url($project);2998}2999print$cgi->startform(-method=>"get", -action =>$action) .3000"<div class=\"search\">\n".3001(!$use_pathinfo&&3002$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3003$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3004$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3005$cgi->popup_menu(-name =>'st', -default=>'commit',3006-values=> ['commit','grep','author','committer','pickaxe']) .3007$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3008" search:\n",3009$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3010"<span title=\"Extended regular expression\">".3011$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3012-checked =>$search_use_regexp) .3013"</span>".3014"</div>".3015$cgi->end_form() ."\n";3016}3017}30183019sub git_footer_html {3020my$feed_class='rss_logo';30213022print"<div class=\"page_footer\">\n";3023if(defined$project) {3024my$descr= git_get_project_description($project);3025if(defined$descr) {3026print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3027}30283029my%href_params= get_feed_info();3030if(!%href_params) {3031$feed_class.=' generic';3032}3033$href_params{'-title'} ||='log';30343035foreachmy$formatqw(RSS Atom){3036$href_params{'action'} =lc($format);3037print$cgi->a({-href => href(%href_params),3038-title =>"$href_params{'-title'}$formatfeed",3039-class=>$feed_class},$format)."\n";3040}30413042}else{3043print$cgi->a({-href => href(project=>undef, action=>"opml"),3044-class=>$feed_class},"OPML") ." ";3045print$cgi->a({-href => href(project=>undef, action=>"project_index"),3046-class=>$feed_class},"TXT") ."\n";3047}3048print"</div>\n";# class="page_footer"30493050if(-f $site_footer) {3051 insert_file($site_footer);3052}30533054print"</body>\n".3055"</html>";3056}30573058# die_error(<http_status_code>, <error_message>)3059# Example: die_error(404, 'Hash not found')3060# By convention, use the following status codes (as defined in RFC 2616):3061# 400: Invalid or missing CGI parameters, or3062# requested object exists but has wrong type.3063# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3064# this server or project.3065# 404: Requested object/revision/project doesn't exist.3066# 500: The server isn't configured properly, or3067# an internal error occurred (e.g. failed assertions caused by bugs), or3068# an unknown error occurred (e.g. the git binary died unexpectedly).3069sub die_error {3070my$status=shift||500;3071my$error=shift||"Internal server error";30723073my%http_responses= (400=>'400 Bad Request',3074403=>'403 Forbidden',3075404=>'404 Not Found',3076500=>'500 Internal Server Error');3077 git_header_html($http_responses{$status});3078print<<EOF;3079<div class="page_body">3080<br /><br />3081$status-$error3082<br />3083</div>3084EOF3085 git_footer_html();3086exit;3087}30883089## ----------------------------------------------------------------------3090## functions printing or outputting HTML: navigation30913092sub git_print_page_nav {3093my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3094$extra=''if!defined$extra;# pager or formats30953096my@navs=qw(summary shortlog log commit commitdiff tree);3097if($suppress) {3098@navs=grep{$_ne$suppress}@navs;3099}31003101my%arg=map{$_=> {action=>$_} }@navs;3102if(defined$head) {3103for(qw(commit commitdiff)) {3104$arg{$_}{'hash'} =$head;3105}3106if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3107for(qw(shortlog log)) {3108$arg{$_}{'hash'} =$head;3109}3110}3111}31123113$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3114$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;31153116my@actions= gitweb_get_feature('actions');3117my%repl= (3118'%'=>'%',3119'n'=>$project,# project name3120'f'=>$git_dir,# project path within filesystem3121'h'=>$treehead||'',# current hash ('h' parameter)3122'b'=>$treebase||'',# hash base ('hb' parameter)3123);3124while(@actions) {3125my($label,$link,$pos) =splice(@actions,0,3);3126# insert3127@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3128# munch munch3129$link=~s/%([%nfhb])/$repl{$1}/g;3130$arg{$label}{'_href'} =$link;3131}31323133print"<div class=\"page_nav\">\n".3134(join" | ",3135map{$_eq$current?3136$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3137}@navs);3138print"<br/>\n$extra<br/>\n".3139"</div>\n";3140}31413142sub format_paging_nav {3143my($action,$hash,$head,$page,$has_next_link) =@_;3144my$paging_nav;314531463147if($hashne$head||$page) {3148$paging_nav.=$cgi->a({-href => href(action=>$action)},"HEAD");3149}else{3150$paging_nav.="HEAD";3151}31523153if($page>0) {3154$paging_nav.=" ⋅ ".3155$cgi->a({-href => href(-replay=>1, page=>$page-1),3156-accesskey =>"p", -title =>"Alt-p"},"prev");3157}else{3158$paging_nav.=" ⋅ prev";3159}31603161if($has_next_link) {3162$paging_nav.=" ⋅ ".3163$cgi->a({-href => href(-replay=>1, page=>$page+1),3164-accesskey =>"n", -title =>"Alt-n"},"next");3165}else{3166$paging_nav.=" ⋅ next";3167}31683169return$paging_nav;3170}31713172## ......................................................................3173## functions printing or outputting HTML: div31743175sub git_print_header_div {3176my($action,$title,$hash,$hash_base) =@_;3177my%args= ();31783179$args{'action'} =$action;3180$args{'hash'} =$hashif$hash;3181$args{'hash_base'} =$hash_baseif$hash_base;31823183print"<div class=\"header\">\n".3184$cgi->a({-href => href(%args), -class=>"title"},3185$title?$title:$action) .3186"\n</div>\n";3187}31883189#sub git_print_authorship (\%) {3190sub git_print_authorship {3191my$co=shift;31923193my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3194print"<div class=\"author_date\">".3195 esc_html($co->{'author_name'}) .3196" [$ad{'rfc2822'}";3197if($ad{'hour_local'} <6) {3198printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3199$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});3200}else{3201printf(" (%02d:%02d%s)",3202$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});3203}3204print"]</div>\n";3205}32063207sub git_print_page_path {3208my$name=shift;3209my$type=shift;3210my$hb=shift;321132123213print"<div class=\"page_path\">";3214print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3215-title =>'tree root'}, to_utf8("[$project]"));3216print" / ";3217if(defined$name) {3218my@dirname=split'/',$name;3219my$basename=pop@dirname;3220my$fullname='';32213222foreachmy$dir(@dirname) {3223$fullname.= ($fullname?'/':'') .$dir;3224print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3225 hash_base=>$hb),3226-title =>$fullname}, esc_path($dir));3227print" / ";3228}3229if(defined$type&&$typeeq'blob') {3230print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3231 hash_base=>$hb),3232-title =>$name}, esc_path($basename));3233}elsif(defined$type&&$typeeq'tree') {3234print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3235 hash_base=>$hb),3236-title =>$name}, esc_path($basename));3237print" / ";3238}else{3239print esc_path($basename);3240}3241}3242print"<br/></div>\n";3243}32443245# sub git_print_log (\@;%) {3246sub git_print_log ($;%) {3247my$log=shift;3248my%opts=@_;32493250if($opts{'-remove_title'}) {3251# remove title, i.e. first line of log3252shift@$log;3253}3254# remove leading empty lines3255while(defined$log->[0] &&$log->[0]eq"") {3256shift@$log;3257}32583259# print log3260my$signoff=0;3261my$empty=0;3262foreachmy$line(@$log) {3263if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3264$signoff=1;3265$empty=0;3266if(!$opts{'-remove_signoff'}) {3267print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3268next;3269}else{3270# remove signoff lines3271next;3272}3273}else{3274$signoff=0;3275}32763277# print only one empty line3278# do not print empty line after signoff3279if($lineeq"") {3280next if($empty||$signoff);3281$empty=1;3282}else{3283$empty=0;3284}32853286print format_log_line_html($line) ."<br/>\n";3287}32883289if($opts{'-final_empty_line'}) {3290# end with single empty line3291print"<br/>\n"unless$empty;3292}3293}32943295# return link target (what link points to)3296sub git_get_link_target {3297my$hash=shift;3298my$link_target;32993300# read link3301open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3302orreturn;3303{3304local$/;3305$link_target= <$fd>;3306}3307close$fd3308orreturn;33093310return$link_target;3311}33123313# given link target, and the directory (basedir) the link is in,3314# return target of link relative to top directory (top tree);3315# return undef if it is not possible (including absolute links).3316sub normalize_link_target {3317my($link_target,$basedir,$hash_base) =@_;33183319# we can normalize symlink target only if $hash_base is provided3320return unless$hash_base;33213322# absolute symlinks (beginning with '/') cannot be normalized3323return if(substr($link_target,0,1)eq'/');33243325# normalize link target to path from top (root) tree (dir)3326my$path;3327if($basedir) {3328$path=$basedir.'/'.$link_target;3329}else{3330# we are in top (root) tree (dir)3331$path=$link_target;3332}33333334# remove //, /./, and /../3335my@path_parts;3336foreachmy$part(split('/',$path)) {3337# discard '.' and ''3338next if(!$part||$parteq'.');3339# handle '..'3340if($parteq'..') {3341if(@path_parts) {3342pop@path_parts;3343}else{3344# link leads outside repository (outside top dir)3345return;3346}3347}else{3348push@path_parts,$part;3349}3350}3351$path=join('/',@path_parts);33523353return$path;3354}33553356# print tree entry (row of git_tree), but without encompassing <tr> element3357sub git_print_tree_entry {3358my($t,$basedir,$hash_base,$have_blame) =@_;33593360my%base_key= ();3361$base_key{'hash_base'} =$hash_baseifdefined$hash_base;33623363# The format of a table row is: mode list link. Where mode is3364# the mode of the entry, list is the name of the entry, an href,3365# and link is the action links of the entry.33663367print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3368if($t->{'type'}eq"blob") {3369print"<td class=\"list\">".3370$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3371 file_name=>"$basedir$t->{'name'}",%base_key),3372-class=>"list"}, esc_path($t->{'name'}));3373if(S_ISLNK(oct$t->{'mode'})) {3374my$link_target= git_get_link_target($t->{'hash'});3375if($link_target) {3376my$norm_target= normalize_link_target($link_target,$basedir,$hash_base);3377if(defined$norm_target) {3378print" -> ".3379$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3380 file_name=>$norm_target),3381-title =>$norm_target}, esc_path($link_target));3382}else{3383print" -> ". esc_path($link_target);3384}3385}3386}3387print"</td>\n";3388print"<td class=\"link\">";3389print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3390 file_name=>"$basedir$t->{'name'}",%base_key)},3391"blob");3392if($have_blame) {3393print" | ".3394$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3395 file_name=>"$basedir$t->{'name'}",%base_key)},3396"blame");3397}3398if(defined$hash_base) {3399print" | ".3400$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3401 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3402"history");3403}3404print" | ".3405$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3406 file_name=>"$basedir$t->{'name'}")},3407"raw");3408print"</td>\n";34093410}elsif($t->{'type'}eq"tree") {3411print"<td class=\"list\">";3412print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3413 file_name=>"$basedir$t->{'name'}",%base_key)},3414 esc_path($t->{'name'}));3415print"</td>\n";3416print"<td class=\"link\">";3417print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3418 file_name=>"$basedir$t->{'name'}",%base_key)},3419"tree");3420if(defined$hash_base) {3421print" | ".3422$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3423 file_name=>"$basedir$t->{'name'}")},3424"history");3425}3426print"</td>\n";3427}else{3428# unknown object: we can only present history for it3429# (this includes 'commit' object, i.e. submodule support)3430print"<td class=\"list\">".3431 esc_path($t->{'name'}) .3432"</td>\n";3433print"<td class=\"link\">";3434if(defined$hash_base) {3435print$cgi->a({-href => href(action=>"history",3436 hash_base=>$hash_base,3437 file_name=>"$basedir$t->{'name'}")},3438"history");3439}3440print"</td>\n";3441}3442}34433444## ......................................................................3445## functions printing large fragments of HTML34463447# get pre-image filenames for merge (combined) diff3448sub fill_from_file_info {3449my($diff,@parents) =@_;34503451$diff->{'from_file'} = [ ];3452$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3453for(my$i=0;$i<$diff->{'nparents'};$i++) {3454if($diff->{'status'}[$i]eq'R'||3455$diff->{'status'}[$i]eq'C') {3456$diff->{'from_file'}[$i] =3457 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3458}3459}34603461return$diff;3462}34633464# is current raw difftree line of file deletion3465sub is_deleted {3466my$diffinfo=shift;34673468return$diffinfo->{'to_id'}eq('0' x 40);3469}34703471# does patch correspond to [previous] difftree raw line3472# $diffinfo - hashref of parsed raw diff format3473# $patchinfo - hashref of parsed patch diff format3474# (the same keys as in $diffinfo)3475sub is_patch_split {3476my($diffinfo,$patchinfo) =@_;34773478returndefined$diffinfo&&defined$patchinfo3479&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3480}348134823483sub git_difftree_body {3484my($difftree,$hash,@parents) =@_;3485my($parent) =$parents[0];3486my$have_blame= gitweb_check_feature('blame');3487print"<div class=\"list_head\">\n";3488if($#{$difftree} >10) {3489print(($#{$difftree} +1) ." files changed:\n");3490}3491print"</div>\n";34923493print"<table class=\"".3494(@parents>1?"combined ":"") .3495"diff_tree\">\n";34963497# header only for combined diff in 'commitdiff' view3498my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3499if($has_header) {3500# table header3501print"<thead><tr>\n".3502"<th></th><th></th>\n";# filename, patchN link3503for(my$i=0;$i<@parents;$i++) {3504my$par=$parents[$i];3505print"<th>".3506$cgi->a({-href => href(action=>"commitdiff",3507 hash=>$hash, hash_parent=>$par),3508-title =>'commitdiff to parent number '.3509($i+1) .': '.substr($par,0,7)},3510$i+1) .3511" </th>\n";3512}3513print"</tr></thead>\n<tbody>\n";3514}35153516my$alternate=1;3517my$patchno=0;3518foreachmy$line(@{$difftree}) {3519my$diff= parsed_difftree_line($line);35203521if($alternate) {3522print"<tr class=\"dark\">\n";3523}else{3524print"<tr class=\"light\">\n";3525}3526$alternate^=1;35273528if(exists$diff->{'nparents'}) {# combined diff35293530 fill_from_file_info($diff,@parents)3531unlessexists$diff->{'from_file'};35323533if(!is_deleted($diff)) {3534# file exists in the result (child) commit3535print"<td>".3536$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3537 file_name=>$diff->{'to_file'},3538 hash_base=>$hash),3539-class=>"list"}, esc_path($diff->{'to_file'})) .3540"</td>\n";3541}else{3542print"<td>".3543 esc_path($diff->{'to_file'}) .3544"</td>\n";3545}35463547if($actioneq'commitdiff') {3548# link to patch3549$patchno++;3550print"<td class=\"link\">".3551$cgi->a({-href =>"#patch$patchno"},"patch") .3552" | ".3553"</td>\n";3554}35553556my$has_history=0;3557my$not_deleted=0;3558for(my$i=0;$i<$diff->{'nparents'};$i++) {3559my$hash_parent=$parents[$i];3560my$from_hash=$diff->{'from_id'}[$i];3561my$from_path=$diff->{'from_file'}[$i];3562my$status=$diff->{'status'}[$i];35633564$has_history||= ($statusne'A');3565$not_deleted||= ($statusne'D');35663567if($statuseq'A') {3568print"<td class=\"link\"align=\"right\"> | </td>\n";3569}elsif($statuseq'D') {3570print"<td class=\"link\">".3571$cgi->a({-href => href(action=>"blob",3572 hash_base=>$hash,3573 hash=>$from_hash,3574 file_name=>$from_path)},3575"blob". ($i+1)) .3576" | </td>\n";3577}else{3578if($diff->{'to_id'}eq$from_hash) {3579print"<td class=\"link nochange\">";3580}else{3581print"<td class=\"link\">";3582}3583print$cgi->a({-href => href(action=>"blobdiff",3584 hash=>$diff->{'to_id'},3585 hash_parent=>$from_hash,3586 hash_base=>$hash,3587 hash_parent_base=>$hash_parent,3588 file_name=>$diff->{'to_file'},3589 file_parent=>$from_path)},3590"diff". ($i+1)) .3591" | </td>\n";3592}3593}35943595print"<td class=\"link\">";3596if($not_deleted) {3597print$cgi->a({-href => href(action=>"blob",3598 hash=>$diff->{'to_id'},3599 file_name=>$diff->{'to_file'},3600 hash_base=>$hash)},3601"blob");3602print" | "if($has_history);3603}3604if($has_history) {3605print$cgi->a({-href => href(action=>"history",3606 file_name=>$diff->{'to_file'},3607 hash_base=>$hash)},3608"history");3609}3610print"</td>\n";36113612print"</tr>\n";3613next;# instead of 'else' clause, to avoid extra indent3614}3615# else ordinary diff36163617my($to_mode_oct,$to_mode_str,$to_file_type);3618my($from_mode_oct,$from_mode_str,$from_file_type);3619if($diff->{'to_mode'}ne('0' x 6)) {3620$to_mode_oct=oct$diff->{'to_mode'};3621if(S_ISREG($to_mode_oct)) {# only for regular file3622$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits3623}3624$to_file_type= file_type($diff->{'to_mode'});3625}3626if($diff->{'from_mode'}ne('0' x 6)) {3627$from_mode_oct=oct$diff->{'from_mode'};3628if(S_ISREG($to_mode_oct)) {# only for regular file3629$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits3630}3631$from_file_type= file_type($diff->{'from_mode'});3632}36333634if($diff->{'status'}eq"A") {# created3635my$mode_chng="<span class=\"file_status new\">[new$to_file_type";3636$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;3637$mode_chng.="]</span>";3638print"<td>";3639print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3640 hash_base=>$hash, file_name=>$diff->{'file'}),3641-class=>"list"}, esc_path($diff->{'file'}));3642print"</td>\n";3643print"<td>$mode_chng</td>\n";3644print"<td class=\"link\">";3645if($actioneq'commitdiff') {3646# link to patch3647$patchno++;3648print$cgi->a({-href =>"#patch$patchno"},"patch");3649print" | ";3650}3651print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3652 hash_base=>$hash, file_name=>$diff->{'file'})},3653"blob");3654print"</td>\n";36553656}elsif($diff->{'status'}eq"D") {# deleted3657my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";3658print"<td>";3659print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3660 hash_base=>$parent, file_name=>$diff->{'file'}),3661-class=>"list"}, esc_path($diff->{'file'}));3662print"</td>\n";3663print"<td>$mode_chng</td>\n";3664print"<td class=\"link\">";3665if($actioneq'commitdiff') {3666# link to patch3667$patchno++;3668print$cgi->a({-href =>"#patch$patchno"},"patch");3669print" | ";3670}3671print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3672 hash_base=>$parent, file_name=>$diff->{'file'})},3673"blob") ." | ";3674if($have_blame) {3675print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,3676 file_name=>$diff->{'file'})},3677"blame") ." | ";3678}3679print$cgi->a({-href => href(action=>"history", hash_base=>$parent,3680 file_name=>$diff->{'file'})},3681"history");3682print"</td>\n";36833684}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed3685my$mode_chnge="";3686if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3687$mode_chnge="<span class=\"file_status mode_chnge\">[changed";3688if($from_file_typene$to_file_type) {3689$mode_chnge.=" from$from_file_typeto$to_file_type";3690}3691if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {3692if($from_mode_str&&$to_mode_str) {3693$mode_chnge.=" mode:$from_mode_str->$to_mode_str";3694}elsif($to_mode_str) {3695$mode_chnge.=" mode:$to_mode_str";3696}3697}3698$mode_chnge.="]</span>\n";3699}3700print"<td>";3701print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3702 hash_base=>$hash, file_name=>$diff->{'file'}),3703-class=>"list"}, esc_path($diff->{'file'}));3704print"</td>\n";3705print"<td>$mode_chnge</td>\n";3706print"<td class=\"link\">";3707if($actioneq'commitdiff') {3708# link to patch3709$patchno++;3710print$cgi->a({-href =>"#patch$patchno"},"patch") .3711" | ";3712}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3713# "commit" view and modified file (not onlu mode changed)3714print$cgi->a({-href => href(action=>"blobdiff",3715 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3716 hash_base=>$hash, hash_parent_base=>$parent,3717 file_name=>$diff->{'file'})},3718"diff") .3719" | ";3720}3721print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3722 hash_base=>$hash, file_name=>$diff->{'file'})},3723"blob") ." | ";3724if($have_blame) {3725print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3726 file_name=>$diff->{'file'})},3727"blame") ." | ";3728}3729print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3730 file_name=>$diff->{'file'})},3731"history");3732print"</td>\n";37333734}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied3735my%status_name= ('R'=>'moved','C'=>'copied');3736my$nstatus=$status_name{$diff->{'status'}};3737my$mode_chng="";3738if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3739# mode also for directories, so we cannot use $to_mode_str3740$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);3741}3742print"<td>".3743$cgi->a({-href => href(action=>"blob", hash_base=>$hash,3744 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),3745-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".3746"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".3747$cgi->a({-href => href(action=>"blob", hash_base=>$parent,3748 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),3749-class=>"list"}, esc_path($diff->{'from_file'})) .3750" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".3751"<td class=\"link\">";3752if($actioneq'commitdiff') {3753# link to patch3754$patchno++;3755print$cgi->a({-href =>"#patch$patchno"},"patch") .3756" | ";3757}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3758# "commit" view and modified file (not only pure rename or copy)3759print$cgi->a({-href => href(action=>"blobdiff",3760 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3761 hash_base=>$hash, hash_parent_base=>$parent,3762 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},3763"diff") .3764" | ";3765}3766print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3767 hash_base=>$parent, file_name=>$diff->{'to_file'})},3768"blob") ." | ";3769if($have_blame) {3770print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3771 file_name=>$diff->{'to_file'})},3772"blame") ." | ";3773}3774print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3775 file_name=>$diff->{'to_file'})},3776"history");3777print"</td>\n";37783779}# we should not encounter Unmerged (U) or Unknown (X) status3780print"</tr>\n";3781}3782print"</tbody>"if$has_header;3783print"</table>\n";3784}37853786sub git_patchset_body {3787my($fd,$difftree,$hash,@hash_parents) =@_;3788my($hash_parent) =$hash_parents[0];37893790my$is_combined= (@hash_parents>1);3791my$patch_idx=0;3792my$patch_number=0;3793my$patch_line;3794my$diffinfo;3795my$to_name;3796my(%from,%to);37973798print"<div class=\"patchset\">\n";37993800# skip to first patch3801while($patch_line= <$fd>) {3802chomp$patch_line;38033804last if($patch_line=~m/^diff /);3805}38063807 PATCH:3808while($patch_line) {38093810# parse "git diff" header line3811if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {3812# $1 is from_name, which we do not use3813$to_name= unquote($2);3814$to_name=~s!^b/!!;3815}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {3816# $1 is 'cc' or 'combined', which we do not use3817$to_name= unquote($2);3818}else{3819$to_name=undef;3820}38213822# check if current patch belong to current raw line3823# and parse raw git-diff line if needed3824if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {3825# this is continuation of a split patch3826print"<div class=\"patch cont\">\n";3827}else{3828# advance raw git-diff output if needed3829$patch_idx++ifdefined$diffinfo;38303831# read and prepare patch information3832$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);38333834# compact combined diff output can have some patches skipped3835# find which patch (using pathname of result) we are at now;3836if($is_combined) {3837while($to_namene$diffinfo->{'to_file'}) {3838print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".3839 format_diff_cc_simplified($diffinfo,@hash_parents) .3840"</div>\n";# class="patch"38413842$patch_idx++;3843$patch_number++;38443845last if$patch_idx>$#$difftree;3846$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);3847}3848}38493850# modifies %from, %to hashes3851 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);38523853# this is first patch for raw difftree line with $patch_idx index3854# we index @$difftree array from 0, but number patches from 13855print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";3856}38573858# git diff header3859#assert($patch_line =~ m/^diff /) if DEBUG;3860#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed3861$patch_number++;3862# print "git diff" header3863print format_git_diff_header_line($patch_line,$diffinfo,3864 \%from, \%to);38653866# print extended diff header3867print"<div class=\"diff extended_header\">\n";3868 EXTENDED_HEADER:3869while($patch_line= <$fd>) {3870chomp$patch_line;38713872last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);38733874print format_extended_diff_header_line($patch_line,$diffinfo,3875 \%from, \%to);3876}3877print"</div>\n";# class="diff extended_header"38783879# from-file/to-file diff header3880if(!$patch_line) {3881print"</div>\n";# class="patch"3882last PATCH;3883}3884next PATCH if($patch_line=~m/^diff /);3885#assert($patch_line =~ m/^---/) if DEBUG;38863887my$last_patch_line=$patch_line;3888$patch_line= <$fd>;3889chomp$patch_line;3890#assert($patch_line =~ m/^\+\+\+/) if DEBUG;38913892print format_diff_from_to_header($last_patch_line,$patch_line,3893$diffinfo, \%from, \%to,3894@hash_parents);38953896# the patch itself3897 LINE:3898while($patch_line= <$fd>) {3899chomp$patch_line;39003901next PATCH if($patch_line=~m/^diff /);39023903print format_diff_line($patch_line, \%from, \%to);3904}39053906}continue{3907print"</div>\n";# class="patch"3908}39093910# for compact combined (--cc) format, with chunk and patch simpliciaction3911# patchset might be empty, but there might be unprocessed raw lines3912for(++$patch_idxif$patch_number>0;3913$patch_idx<@$difftree;3914++$patch_idx) {3915# read and prepare patch information3916$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);39173918# generate anchor for "patch" links in difftree / whatchanged part3919print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".3920 format_diff_cc_simplified($diffinfo,@hash_parents) .3921"</div>\n";# class="patch"39223923$patch_number++;3924}39253926if($patch_number==0) {3927if(@hash_parents>1) {3928print"<div class=\"diff nodifferences\">Trivial merge</div>\n";3929}else{3930print"<div class=\"diff nodifferences\">No differences found</div>\n";3931}3932}39333934print"</div>\n";# class="patchset"3935}39363937# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39383939# fills project list info (age, description, owner, forks) for each3940# project in the list, removing invalid projects from returned list3941# NOTE: modifies $projlist, but does not remove entries from it3942sub fill_project_list_info {3943my($projlist,$check_forks) =@_;3944my@projects;39453946my$show_ctags= gitweb_check_feature('ctags');3947 PROJECT:3948foreachmy$pr(@$projlist) {3949my(@activity) = git_get_last_activity($pr->{'path'});3950unless(@activity) {3951next PROJECT;3952}3953($pr->{'age'},$pr->{'age_string'}) =@activity;3954if(!defined$pr->{'descr'}) {3955my$descr= git_get_project_description($pr->{'path'}) ||"";3956$descr= to_utf8($descr);3957$pr->{'descr_long'} =$descr;3958$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);3959}3960if(!defined$pr->{'owner'}) {3961$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";3962}3963if($check_forks) {3964my$pname=$pr->{'path'};3965if(($pname=~s/\.git$//) &&3966($pname!~/\/$/) &&3967(-d "$projectroot/$pname")) {3968$pr->{'forks'} ="-d$projectroot/$pname";3969}else{3970$pr->{'forks'} =0;3971}3972}3973$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});3974push@projects,$pr;3975}39763977return@projects;3978}39793980# print 'sort by' <th> element, generating 'sort by $name' replay link3981# if that order is not selected3982sub print_sort_th {3983my($name,$order,$header) =@_;3984$header||=ucfirst($name);39853986if($ordereq$name) {3987print"<th>$header</th>\n";3988}else{3989print"<th>".3990$cgi->a({-href => href(-replay=>1, order=>$name),3991-class=>"header"},$header) .3992"</th>\n";3993}3994}39953996sub git_project_list_body {3997# actually uses global variable $project3998my($projlist,$order,$from,$to,$extra,$no_header) =@_;39994000my$check_forks= gitweb_check_feature('forks');4001my@projects= fill_project_list_info($projlist,$check_forks);40024003$order||=$default_projects_order;4004$from=0unlessdefined$from;4005$to=$#projectsif(!defined$to||$#projects<$to);40064007my%order_info= (4008 project => { key =>'path', type =>'str'},4009 descr => { key =>'descr_long', type =>'str'},4010 owner => { key =>'owner', type =>'str'},4011 age => { key =>'age', type =>'num'}4012);4013my$oi=$order_info{$order};4014if($oi->{'type'}eq'str') {4015@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4016}else{4017@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4018}40194020my$show_ctags= gitweb_check_feature('ctags');4021if($show_ctags) {4022my%ctags;4023foreachmy$p(@projects) {4024foreachmy$ct(keys%{$p->{'ctags'}}) {4025$ctags{$ct} +=$p->{'ctags'}->{$ct};4026}4027}4028my$cloud= git_populate_project_tagcloud(\%ctags);4029print git_show_project_tagcloud($cloud,64);4030}40314032print"<table class=\"project_list\">\n";4033unless($no_header) {4034print"<tr>\n";4035if($check_forks) {4036print"<th></th>\n";4037}4038 print_sort_th('project',$order,'Project');4039 print_sort_th('descr',$order,'Description');4040 print_sort_th('owner',$order,'Owner');4041 print_sort_th('age',$order,'Last Change');4042print"<th></th>\n".# for links4043"</tr>\n";4044}4045my$alternate=1;4046my$tagfilter=$cgi->param('by_tag');4047for(my$i=$from;$i<=$to;$i++) {4048my$pr=$projects[$i];40494050next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4051next if$searchtextand not$pr->{'path'} =~/$searchtext/4052and not$pr->{'descr_long'} =~/$searchtext/;4053# Weed out forks or non-matching entries of search4054if($check_forks) {4055my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4056$forkbase="^$forkbase"if$forkbase;4057next ifnot$searchtextand not$tagfilterand$show_ctags4058and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4059}40604061if($alternate) {4062print"<tr class=\"dark\">\n";4063}else{4064print"<tr class=\"light\">\n";4065}4066$alternate^=1;4067if($check_forks) {4068print"<td>";4069if($pr->{'forks'}) {4070print"<!--$pr->{'forks'} -->\n";4071print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4072}4073print"</td>\n";4074}4075print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4076-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4077"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4078-class=>"list", -title =>$pr->{'descr_long'}},4079 esc_html($pr->{'descr'})) ."</td>\n".4080"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4081print"<td class=\"". age_class($pr->{'age'}) ."\">".4082(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4083"<td class=\"link\">".4084$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4085$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4086$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4087$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4088($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4089"</td>\n".4090"</tr>\n";4091}4092if(defined$extra) {4093print"<tr>\n";4094if($check_forks) {4095print"<td></td>\n";4096}4097print"<td colspan=\"5\">$extra</td>\n".4098"</tr>\n";4099}4100print"</table>\n";4101}41024103sub git_shortlog_body {4104# uses global variable $project4105my($commitlist,$from,$to,$refs,$extra) =@_;41064107$from=0unlessdefined$from;4108$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);41094110print"<table class=\"shortlog\">\n";4111my$alternate=1;4112for(my$i=$from;$i<=$to;$i++) {4113my%co= %{$commitlist->[$i]};4114my$commit=$co{'id'};4115my$ref= format_ref_marker($refs,$commit);4116if($alternate) {4117print"<tr class=\"dark\">\n";4118}else{4119print"<tr class=\"light\">\n";4120}4121$alternate^=1;4122my$author= chop_and_escape_str($co{'author_name'},10);4123# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4124print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4125"<td><i>".$author."</i></td>\n".4126"<td>";4127print format_subject_html($co{'title'},$co{'title_short'},4128 href(action=>"commit", hash=>$commit),$ref);4129print"</td>\n".4130"<td class=\"link\">".4131$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4132$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4133$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4134my$snapshot_links= format_snapshot_links($commit);4135if(defined$snapshot_links) {4136print" | ".$snapshot_links;4137}4138print"</td>\n".4139"</tr>\n";4140}4141if(defined$extra) {4142print"<tr>\n".4143"<td colspan=\"4\">$extra</td>\n".4144"</tr>\n";4145}4146print"</table>\n";4147}41484149sub git_history_body {4150# Warning: assumes constant type (blob or tree) during history4151my($commitlist,$from,$to,$refs,$hash_base,$ftype,$extra) =@_;41524153$from=0unlessdefined$from;4154$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});41554156print"<table class=\"history\">\n";4157my$alternate=1;4158for(my$i=$from;$i<=$to;$i++) {4159my%co= %{$commitlist->[$i]};4160if(!%co) {4161next;4162}4163my$commit=$co{'id'};41644165my$ref= format_ref_marker($refs,$commit);41664167if($alternate) {4168print"<tr class=\"dark\">\n";4169}else{4170print"<tr class=\"light\">\n";4171}4172$alternate^=1;4173# shortlog uses chop_str($co{'author_name'}, 10)4174my$author= chop_and_escape_str($co{'author_name'},15,3);4175print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4176"<td><i>".$author."</i></td>\n".4177"<td>";4178# originally git_history used chop_str($co{'title'}, 50)4179print format_subject_html($co{'title'},$co{'title_short'},4180 href(action=>"commit", hash=>$commit),$ref);4181print"</td>\n".4182"<td class=\"link\">".4183$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4184$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");41854186if($ftypeeq'blob') {4187my$blob_current= git_get_hash_by_path($hash_base,$file_name);4188my$blob_parent= git_get_hash_by_path($commit,$file_name);4189if(defined$blob_current&&defined$blob_parent&&4190$blob_currentne$blob_parent) {4191print" | ".4192$cgi->a({-href => href(action=>"blobdiff",4193 hash=>$blob_current, hash_parent=>$blob_parent,4194 hash_base=>$hash_base, hash_parent_base=>$commit,4195 file_name=>$file_name)},4196"diff to current");4197}4198}4199print"</td>\n".4200"</tr>\n";4201}4202if(defined$extra) {4203print"<tr>\n".4204"<td colspan=\"4\">$extra</td>\n".4205"</tr>\n";4206}4207print"</table>\n";4208}42094210sub git_tags_body {4211# uses global variable $project4212my($taglist,$from,$to,$extra) =@_;4213$from=0unlessdefined$from;4214$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);42154216print"<table class=\"tags\">\n";4217my$alternate=1;4218for(my$i=$from;$i<=$to;$i++) {4219my$entry=$taglist->[$i];4220my%tag=%$entry;4221my$comment=$tag{'subject'};4222my$comment_short;4223if(defined$comment) {4224$comment_short= chop_str($comment,30,5);4225}4226if($alternate) {4227print"<tr class=\"dark\">\n";4228}else{4229print"<tr class=\"light\">\n";4230}4231$alternate^=1;4232if(defined$tag{'age'}) {4233print"<td><i>$tag{'age'}</i></td>\n";4234}else{4235print"<td></td>\n";4236}4237print"<td>".4238$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4239-class=>"list name"}, esc_html($tag{'name'})) .4240"</td>\n".4241"<td>";4242if(defined$comment) {4243print format_subject_html($comment,$comment_short,4244 href(action=>"tag", hash=>$tag{'id'}));4245}4246print"</td>\n".4247"<td class=\"selflink\">";4248if($tag{'type'}eq"tag") {4249print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4250}else{4251print" ";4252}4253print"</td>\n".4254"<td class=\"link\">"." | ".4255$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4256if($tag{'reftype'}eq"commit") {4257print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4258" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4259}elsif($tag{'reftype'}eq"blob") {4260print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4261}4262print"</td>\n".4263"</tr>";4264}4265if(defined$extra) {4266print"<tr>\n".4267"<td colspan=\"5\">$extra</td>\n".4268"</tr>\n";4269}4270print"</table>\n";4271}42724273sub git_heads_body {4274# uses global variable $project4275my($headlist,$head,$from,$to,$extra) =@_;4276$from=0unlessdefined$from;4277$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);42784279print"<table class=\"heads\">\n";4280my$alternate=1;4281for(my$i=$from;$i<=$to;$i++) {4282my$entry=$headlist->[$i];4283my%ref=%$entry;4284my$curr=$ref{'id'}eq$head;4285if($alternate) {4286print"<tr class=\"dark\">\n";4287}else{4288print"<tr class=\"light\">\n";4289}4290$alternate^=1;4291print"<td><i>$ref{'age'}</i></td>\n".4292($curr?"<td class=\"current_head\">":"<td>") .4293$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4294-class=>"list name"},esc_html($ref{'name'})) .4295"</td>\n".4296"<td class=\"link\">".4297$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4298$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4299$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4300"</td>\n".4301"</tr>";4302}4303if(defined$extra) {4304print"<tr>\n".4305"<td colspan=\"3\">$extra</td>\n".4306"</tr>\n";4307}4308print"</table>\n";4309}43104311sub git_search_grep_body {4312my($commitlist,$from,$to,$extra) =@_;4313$from=0unlessdefined$from;4314$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);43154316print"<table class=\"commit_search\">\n";4317my$alternate=1;4318for(my$i=$from;$i<=$to;$i++) {4319my%co= %{$commitlist->[$i]};4320if(!%co) {4321next;4322}4323my$commit=$co{'id'};4324if($alternate) {4325print"<tr class=\"dark\">\n";4326}else{4327print"<tr class=\"light\">\n";4328}4329$alternate^=1;4330my$author= chop_and_escape_str($co{'author_name'},15,5);4331print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4332"<td><i>".$author."</i></td>\n".4333"<td>".4334$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4335-class=>"list subject"},4336 chop_and_escape_str($co{'title'},50) ."<br/>");4337my$comment=$co{'comment'};4338foreachmy$line(@$comment) {4339if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4340my($lead,$match,$trail) = ($1,$2,$3);4341$match= chop_str($match,70,5,'center');4342my$contextlen=int((80-length($match))/2);4343$contextlen=30if($contextlen>30);4344$lead= chop_str($lead,$contextlen,10,'left');4345$trail= chop_str($trail,$contextlen,10,'right');43464347$lead= esc_html($lead);4348$match= esc_html($match);4349$trail= esc_html($trail);43504351print"$lead<span class=\"match\">$match</span>$trail<br />";4352}4353}4354print"</td>\n".4355"<td class=\"link\">".4356$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4357" | ".4358$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4359" | ".4360$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4361print"</td>\n".4362"</tr>\n";4363}4364if(defined$extra) {4365print"<tr>\n".4366"<td colspan=\"3\">$extra</td>\n".4367"</tr>\n";4368}4369print"</table>\n";4370}43714372## ======================================================================4373## ======================================================================4374## actions43754376sub git_project_list {4377my$order=$input_params{'order'};4378if(defined$order&&$order!~m/none|project|descr|owner|age/) {4379 die_error(400,"Unknown order parameter");4380}43814382my@list= git_get_projects_list();4383if(!@list) {4384 die_error(404,"No projects found");4385}43864387 git_header_html();4388if(-f $home_text) {4389print"<div class=\"index_include\">\n";4390 insert_file($home_text);4391print"</div>\n";4392}4393print$cgi->startform(-method=>"get") .4394"<p class=\"projsearch\">Search:\n".4395$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4396"</p>".4397$cgi->end_form() ."\n";4398 git_project_list_body(\@list,$order);4399 git_footer_html();4400}44014402sub git_forks {4403my$order=$input_params{'order'};4404if(defined$order&&$order!~m/none|project|descr|owner|age/) {4405 die_error(400,"Unknown order parameter");4406}44074408my@list= git_get_projects_list($project);4409if(!@list) {4410 die_error(404,"No forks found");4411}44124413 git_header_html();4414 git_print_page_nav('','');4415 git_print_header_div('summary',"$projectforks");4416 git_project_list_body(\@list,$order);4417 git_footer_html();4418}44194420sub git_project_index {4421my@projects= git_get_projects_list($project);44224423print$cgi->header(4424-type =>'text/plain',4425-charset =>'utf-8',4426-content_disposition =>'inline; filename="index.aux"');44274428foreachmy$pr(@projects) {4429if(!exists$pr->{'owner'}) {4430$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4431}44324433my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4434# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4435$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4436$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4437$path=~s/ /\+/g;4438$owner=~s/ /\+/g;44394440print"$path$owner\n";4441}4442}44434444sub git_summary {4445my$descr= git_get_project_description($project) ||"none";4446my%co= parse_commit("HEAD");4447my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4448my$head=$co{'id'};44494450my$owner= git_get_project_owner($project);44514452my$refs= git_get_references();4453# These get_*_list functions return one more to allow us to see if4454# there are more ...4455my@taglist= git_get_tags_list(16);4456my@headlist= git_get_heads_list(16);4457my@forklist;4458my$check_forks= gitweb_check_feature('forks');44594460if($check_forks) {4461@forklist= git_get_projects_list($project);4462}44634464 git_header_html();4465 git_print_page_nav('summary','',$head);44664467print"<div class=\"title\"> </div>\n";4468print"<table class=\"projects_list\">\n".4469"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4470"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4471if(defined$cd{'rfc2822'}) {4472print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4473}44744475# use per project git URL list in $projectroot/$project/cloneurl4476# or make project git URL from git base URL and project name4477my$url_tag="URL";4478my@url_list= git_get_project_url_list($project);4479@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4480foreachmy$git_url(@url_list) {4481next unless$git_url;4482print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4483$url_tag="";4484}44854486# Tag cloud4487my$show_ctags= gitweb_check_feature('ctags');4488if($show_ctags) {4489my$ctags= git_get_project_ctags($project);4490my$cloud= git_populate_project_tagcloud($ctags);4491print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4492print"</td>\n<td>"unless%$ctags;4493print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4494print"</td>\n<td>"if%$ctags;4495print git_show_project_tagcloud($cloud,48);4496print"</td></tr>";4497}44984499print"</table>\n";45004501# If XSS prevention is on, we don't include README.html.4502# TODO: Allow a readme in some safe format.4503if(!$prevent_xss&& -s "$projectroot/$project/README.html") {4504print"<div class=\"title\">readme</div>\n".4505"<div class=\"readme\">\n";4506 insert_file("$projectroot/$project/README.html");4507print"\n</div>\n";# class="readme"4508}45094510# we need to request one more than 16 (0..15) to check if4511# those 16 are all4512my@commitlist=$head? parse_commits($head,17) : ();4513if(@commitlist) {4514 git_print_header_div('shortlog');4515 git_shortlog_body(\@commitlist,0,15,$refs,4516$#commitlist<=15?undef:4517$cgi->a({-href => href(action=>"shortlog")},"..."));4518}45194520if(@taglist) {4521 git_print_header_div('tags');4522 git_tags_body(\@taglist,0,15,4523$#taglist<=15?undef:4524$cgi->a({-href => href(action=>"tags")},"..."));4525}45264527if(@headlist) {4528 git_print_header_div('heads');4529 git_heads_body(\@headlist,$head,0,15,4530$#headlist<=15?undef:4531$cgi->a({-href => href(action=>"heads")},"..."));4532}45334534if(@forklist) {4535 git_print_header_div('forks');4536 git_project_list_body(\@forklist,'age',0,15,4537$#forklist<=15?undef:4538$cgi->a({-href => href(action=>"forks")},"..."),4539'no_header');4540}45414542 git_footer_html();4543}45444545sub git_tag {4546my$head= git_get_head_hash($project);4547 git_header_html();4548 git_print_page_nav('','',$head,undef,$head);4549my%tag= parse_tag($hash);45504551if(!%tag) {4552 die_error(404,"Unknown tag object");4553}45544555 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4556print"<div class=\"title_text\">\n".4557"<table class=\"object_header\">\n".4558"<tr>\n".4559"<td>object</td>\n".4560"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4561$tag{'object'}) ."</td>\n".4562"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4563$tag{'type'}) ."</td>\n".4564"</tr>\n";4565if(defined($tag{'author'})) {4566my%ad= parse_date($tag{'epoch'},$tag{'tz'});4567print"<tr><td>author</td><td>". esc_html($tag{'author'}) ."</td></tr>\n";4568print"<tr><td></td><td>".$ad{'rfc2822'} .4569sprintf(" (%02d:%02d%s)",$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'}) .4570"</td></tr>\n";4571}4572print"</table>\n\n".4573"</div>\n";4574print"<div class=\"page_body\">";4575my$comment=$tag{'comment'};4576foreachmy$line(@$comment) {4577chomp$line;4578print esc_html($line, -nbsp=>1) ."<br/>\n";4579}4580print"</div>\n";4581 git_footer_html();4582}45834584sub git_blame {4585my$fd;4586my$ftype;45874588 gitweb_check_feature('blame')4589or die_error(403,"Blame view not allowed");45904591 die_error(400,"No file name given")unless$file_name;4592$hash_base||= git_get_head_hash($project);4593 die_error(404,"Couldn't find base commit")unless($hash_base);4594my%co= parse_commit($hash_base)4595or die_error(404,"Commit not found");4596if(!defined$hash) {4597$hash= git_get_hash_by_path($hash_base,$file_name,"blob")4598or die_error(404,"Error looking up file");4599}4600$ftype= git_get_type($hash);4601if($ftype!~"blob") {4602 die_error(400,"Object is not a blob");4603}4604open($fd,"-|", git_cmd(),"blame",'-p','--',4605$file_name,$hash_base)4606or die_error(500,"Open git-blame failed");4607 git_header_html();4608my$formats_nav=4609$cgi->a({-href => href(action=>"blob", -replay=>1)},4610"blob") .4611" | ".4612$cgi->a({-href => href(action=>"history", -replay=>1)},4613"history") .4614" | ".4615$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},4616"HEAD");4617 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4618 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4619 git_print_page_path($file_name,$ftype,$hash_base);4620my@rev_color= (qw(light2 dark2));4621my$num_colors=scalar(@rev_color);4622my$current_color=0;4623my$last_rev;4624print<<HTML;4625<div class="page_body">4626<table class="blame">4627<tr><th>Commit</th><th>Line</th><th>Data</th></tr>4628HTML4629my%metainfo= ();4630while(1) {4631$_= <$fd>;4632last unlessdefined$_;4633my($full_rev,$orig_lineno,$lineno,$group_size) =4634/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;4635if(!exists$metainfo{$full_rev}) {4636$metainfo{$full_rev} = {};4637}4638my$meta=$metainfo{$full_rev};4639while(<$fd>) {4640last if(s/^\t//);4641if(/^(\S+) (.*)$/) {4642$meta->{$1} =$2;4643}4644}4645my$data=$_;4646chomp$data;4647my$rev=substr($full_rev,0,8);4648my$author=$meta->{'author'};4649my%date= parse_date($meta->{'author-time'},4650$meta->{'author-tz'});4651my$date=$date{'iso-tz'};4652if($group_size) {4653$current_color= ++$current_color%$num_colors;4654}4655print"<tr class=\"$rev_color[$current_color]\">\n";4656if($group_size) {4657print"<td class=\"sha1\"";4658print" title=\"". esc_html($author) .",$date\"";4659print" rowspan=\"$group_size\""if($group_size>1);4660print">";4661print$cgi->a({-href => href(action=>"commit",4662 hash=>$full_rev,4663 file_name=>$file_name)},4664 esc_html($rev));4665print"</td>\n";4666}4667open(my$dd,"-|", git_cmd(),"rev-parse","$full_rev^")4668or die_error(500,"Open git-rev-parse failed");4669my$parent_commit= <$dd>;4670close$dd;4671chomp($parent_commit);4672my$blamed= href(action =>'blame',4673 file_name =>$meta->{'filename'},4674 hash_base =>$parent_commit);4675print"<td class=\"linenr\">";4676print$cgi->a({ -href =>"$blamed#l$orig_lineno",4677-id =>"l$lineno",4678-class=>"linenr"},4679 esc_html($lineno));4680print"</td>";4681print"<td class=\"pre\">". esc_html($data) ."</td>\n";4682print"</tr>\n";4683}4684print"</table>\n";4685print"</div>";4686close$fd4687or print"Reading blob failed\n";4688 git_footer_html();4689}46904691sub git_tags {4692my$head= git_get_head_hash($project);4693 git_header_html();4694 git_print_page_nav('','',$head,undef,$head);4695 git_print_header_div('summary',$project);46964697my@tagslist= git_get_tags_list();4698if(@tagslist) {4699 git_tags_body(\@tagslist);4700}4701 git_footer_html();4702}47034704sub git_heads {4705my$head= git_get_head_hash($project);4706 git_header_html();4707 git_print_page_nav('','',$head,undef,$head);4708 git_print_header_div('summary',$project);47094710my@headslist= git_get_heads_list();4711if(@headslist) {4712 git_heads_body(\@headslist,$head);4713}4714 git_footer_html();4715}47164717sub git_blob_plain {4718my$type=shift;4719my$expires;47204721if(!defined$hash) {4722if(defined$file_name) {4723my$base=$hash_base|| git_get_head_hash($project);4724$hash= git_get_hash_by_path($base,$file_name,"blob")4725or die_error(404,"Cannot find file");4726}else{4727 die_error(400,"No file name defined");4728}4729}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4730# blobs defined by non-textual hash id's can be cached4731$expires="+1d";4732}47334734open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4735or die_error(500,"Open git-cat-file blob '$hash' failed");47364737# content-type (can include charset)4738$type= blob_contenttype($fd,$file_name,$type);47394740# "save as" filename, even when no $file_name is given4741my$save_as="$hash";4742if(defined$file_name) {4743$save_as=$file_name;4744}elsif($type=~m/^text\//) {4745$save_as.='.txt';4746}47474748# With XSS prevention on, blobs of all types except a few known safe4749# ones are served with "Content-Disposition: attachment" to make sure4750# they don't run in our security domain. For certain image types,4751# blob view writes an <img> tag referring to blob_plain view, and we4752# want to be sure not to break that by serving the image as an4753# attachment (though Firefox 3 doesn't seem to care).4754my$sandbox=$prevent_xss&&4755$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;47564757print$cgi->header(4758-type =>$type,4759-expires =>$expires,4760-content_disposition =>4761($sandbox?'attachment':'inline')4762.'; filename="'.$save_as.'"');4763undef$/;4764binmode STDOUT,':raw';4765print<$fd>;4766binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi4767$/="\n";4768close$fd;4769}47704771sub git_blob {4772my$expires;47734774if(!defined$hash) {4775if(defined$file_name) {4776my$base=$hash_base|| git_get_head_hash($project);4777$hash= git_get_hash_by_path($base,$file_name,"blob")4778or die_error(404,"Cannot find file");4779}else{4780 die_error(400,"No file name defined");4781}4782}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4783# blobs defined by non-textual hash id's can be cached4784$expires="+1d";4785}47864787my$have_blame= gitweb_check_feature('blame');4788open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4789or die_error(500,"Couldn't cat$file_name,$hash");4790my$mimetype= blob_mimetype($fd,$file_name);4791if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {4792close$fd;4793return git_blob_plain($mimetype);4794}4795# we can have blame only for text/* mimetype4796$have_blame&&= ($mimetype=~m!^text/!);47974798 git_header_html(undef,$expires);4799my$formats_nav='';4800if(defined$hash_base&& (my%co= parse_commit($hash_base))) {4801if(defined$file_name) {4802if($have_blame) {4803$formats_nav.=4804$cgi->a({-href => href(action=>"blame", -replay=>1)},4805"blame") .4806" | ";4807}4808$formats_nav.=4809$cgi->a({-href => href(action=>"history", -replay=>1)},4810"history") .4811" | ".4812$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},4813"raw") .4814" | ".4815$cgi->a({-href => href(action=>"blob",4816 hash_base=>"HEAD", file_name=>$file_name)},4817"HEAD");4818}else{4819$formats_nav.=4820$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},4821"raw");4822}4823 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4824 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4825}else{4826print"<div class=\"page_nav\">\n".4827"<br/><br/></div>\n".4828"<div class=\"title\">$hash</div>\n";4829}4830 git_print_page_path($file_name,"blob",$hash_base);4831print"<div class=\"page_body\">\n";4832if($mimetype=~m!^image/!) {4833print qq!<img type="$mimetype"!;4834if($file_name) {4835print qq! alt="$file_name" title="$file_name"!;4836}4837print qq! src="! .4838 href(action=>"blob_plain", hash=>$hash,4839 hash_base=>$hash_base, file_name=>$file_name) .4840 qq!"/>\n!;4841}else{4842my$nr;4843while(my$line= <$fd>) {4844chomp$line;4845$nr++;4846$line= untabify($line);4847printf"<div class=\"pre\"><a id=\"l%i\"href=\"#l%i\"class=\"linenr\">%4i</a>%s</div>\n",4848$nr,$nr,$nr, esc_html($line, -nbsp=>1);4849}4850}4851close$fd4852or print"Reading blob failed.\n";4853print"</div>";4854 git_footer_html();4855}48564857sub git_tree {4858if(!defined$hash_base) {4859$hash_base="HEAD";4860}4861if(!defined$hash) {4862if(defined$file_name) {4863$hash= git_get_hash_by_path($hash_base,$file_name,"tree");4864}else{4865$hash=$hash_base;4866}4867}4868 die_error(404,"No such tree")unlessdefined($hash);4869$/="\0";4870open my$fd,"-|", git_cmd(),"ls-tree",'-z',$hash4871or die_error(500,"Open git-ls-tree failed");4872my@entries=map{chomp;$_} <$fd>;4873close$fdor die_error(404,"Reading tree failed");4874$/="\n";48754876my$refs= git_get_references();4877my$ref= format_ref_marker($refs,$hash_base);4878 git_header_html();4879my$basedir='';4880my$have_blame= gitweb_check_feature('blame');4881if(defined$hash_base&& (my%co= parse_commit($hash_base))) {4882my@views_nav= ();4883if(defined$file_name) {4884push@views_nav,4885$cgi->a({-href => href(action=>"history", -replay=>1)},4886"history"),4887$cgi->a({-href => href(action=>"tree",4888 hash_base=>"HEAD", file_name=>$file_name)},4889"HEAD"),4890}4891my$snapshot_links= format_snapshot_links($hash);4892if(defined$snapshot_links) {4893# FIXME: Should be available when we have no hash base as well.4894push@views_nav,$snapshot_links;4895}4896 git_print_page_nav('tree','',$hash_base,undef,undef,join(' | ',@views_nav));4897 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);4898}else{4899undef$hash_base;4900print"<div class=\"page_nav\">\n";4901print"<br/><br/></div>\n";4902print"<div class=\"title\">$hash</div>\n";4903}4904if(defined$file_name) {4905$basedir=$file_name;4906if($basedirne''&&substr($basedir, -1)ne'/') {4907$basedir.='/';4908}4909 git_print_page_path($file_name,'tree',$hash_base);4910}4911print"<div class=\"page_body\">\n";4912print"<table class=\"tree\">\n";4913my$alternate=1;4914# '..' (top directory) link if possible4915if(defined$hash_base&&4916defined$file_name&&$file_name=~m![^/]+$!) {4917if($alternate) {4918print"<tr class=\"dark\">\n";4919}else{4920print"<tr class=\"light\">\n";4921}4922$alternate^=1;49234924my$up=$file_name;4925$up=~s!/?[^/]+$!!;4926undef$upunless$up;4927# based on git_print_tree_entry4928print'<td class="mode">'. mode_str('040000') ."</td>\n";4929print'<td class="list">';4930print$cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,4931 file_name=>$up)},4932"..");4933print"</td>\n";4934print"<td class=\"link\"></td>\n";49354936print"</tr>\n";4937}4938foreachmy$line(@entries) {4939my%t= parse_ls_tree_line($line, -z =>1);49404941if($alternate) {4942print"<tr class=\"dark\">\n";4943}else{4944print"<tr class=\"light\">\n";4945}4946$alternate^=1;49474948 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);49494950print"</tr>\n";4951}4952print"</table>\n".4953"</div>";4954 git_footer_html();4955}49564957sub git_snapshot {4958my$format=$input_params{'snapshot_format'};4959if(!@snapshot_fmts) {4960 die_error(403,"Snapshots not allowed");4961}4962# default to first supported snapshot format4963$format||=$snapshot_fmts[0];4964if($format!~m/^[a-z0-9]+$/) {4965 die_error(400,"Invalid snapshot format parameter");4966}elsif(!exists($known_snapshot_formats{$format})) {4967 die_error(400,"Unknown snapshot format");4968}elsif(!grep($_eq$format,@snapshot_fmts)) {4969 die_error(403,"Unsupported snapshot format");4970}49714972if(!defined$hash) {4973$hash= git_get_head_hash($project);4974}49754976my$name=$project;4977$name=~ s,([^/])/*\.git$,$1,;4978$name= basename($name);4979my$filename= to_utf8($name);4980$name=~s/\047/\047\\\047\047/g;4981my$cmd;4982$filename.="-$hash$known_snapshot_formats{$format}{'suffix'}";4983$cmd= quote_command(4984 git_cmd(),'archive',4985"--format=$known_snapshot_formats{$format}{'format'}",4986"--prefix=$name/",$hash);4987if(exists$known_snapshot_formats{$format}{'compressor'}) {4988$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});4989}49904991print$cgi->header(4992-type =>$known_snapshot_formats{$format}{'type'},4993-content_disposition =>'inline; filename="'."$filename".'"',4994-status =>'200 OK');49954996open my$fd,"-|",$cmd4997or die_error(500,"Execute git-archive failed");4998binmode STDOUT,':raw';4999print<$fd>;5000binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5001close$fd;5002}50035004sub git_log {5005my$head= git_get_head_hash($project);5006if(!defined$hash) {5007$hash=$head;5008}5009if(!defined$page) {5010$page=0;5011}5012my$refs= git_get_references();50135014my@commitlist= parse_commits($hash,101, (100*$page));50155016my$paging_nav= format_paging_nav('log',$hash,$head,$page,$#commitlist>=100);50175018 git_header_html();5019 git_print_page_nav('log','',$hash,undef,undef,$paging_nav);50205021if(!@commitlist) {5022my%co= parse_commit($hash);50235024 git_print_header_div('summary',$project);5025print"<div class=\"page_body\"> Last change$co{'age_string'}.<br/><br/></div>\n";5026}5027my$to= ($#commitlist>=99) ? (99) : ($#commitlist);5028for(my$i=0;$i<=$to;$i++) {5029my%co= %{$commitlist[$i]};5030next if!%co;5031my$commit=$co{'id'};5032my$ref= format_ref_marker($refs,$commit);5033my%ad= parse_date($co{'author_epoch'});5034 git_print_header_div('commit',5035"<span class=\"age\">$co{'age_string'}</span>".5036 esc_html($co{'title'}) .$ref,5037$commit);5038print"<div class=\"title_text\">\n".5039"<div class=\"log_link\">\n".5040$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .5041" | ".5042$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .5043" | ".5044$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .5045"<br/>\n".5046"</div>\n".5047"<i>". esc_html($co{'author_name'}) ." [$ad{'rfc2822'}]</i><br/>\n".5048"</div>\n";50495050print"<div class=\"log_body\">\n";5051 git_print_log($co{'comment'}, -final_empty_line=>1);5052print"</div>\n";5053}5054if($#commitlist>=100) {5055print"<div class=\"page_nav\">\n";5056print$cgi->a({-href => href(-replay=>1, page=>$page+1),5057-accesskey =>"n", -title =>"Alt-n"},"next");5058print"</div>\n";5059}5060 git_footer_html();5061}50625063sub git_commit {5064$hash||=$hash_base||"HEAD";5065my%co= parse_commit($hash)5066or die_error(404,"Unknown commit object");5067my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5068my%cd= parse_date($co{'committer_epoch'},$co{'committer_tz'});50695070my$parent=$co{'parent'};5071my$parents=$co{'parents'};# listref50725073# we need to prepare $formats_nav before any parameter munging5074my$formats_nav;5075if(!defined$parent) {5076# --root commitdiff5077$formats_nav.='(initial)';5078}elsif(@$parents==1) {5079# single parent commit5080$formats_nav.=5081'(parent: '.5082$cgi->a({-href => href(action=>"commit",5083 hash=>$parent)},5084 esc_html(substr($parent,0,7))) .5085')';5086}else{5087# merge commit5088$formats_nav.=5089'(merge: '.5090join(' ',map{5091$cgi->a({-href => href(action=>"commit",5092 hash=>$_)},5093 esc_html(substr($_,0,7)));5094}@$parents) .5095')';5096}50975098if(!defined$parent) {5099$parent="--root";5100}5101my@difftree;5102open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5103@diff_opts,5104(@$parents<=1?$parent:'-c'),5105$hash,"--"5106or die_error(500,"Open git-diff-tree failed");5107@difftree=map{chomp;$_} <$fd>;5108close$fdor die_error(404,"Reading git-diff-tree failed");51095110# non-textual hash id's can be cached5111my$expires;5112if($hash=~m/^[0-9a-fA-F]{40}$/) {5113$expires="+1d";5114}5115my$refs= git_get_references();5116my$ref= format_ref_marker($refs,$co{'id'});51175118 git_header_html(undef,$expires);5119 git_print_page_nav('commit','',5120$hash,$co{'tree'},$hash,5121$formats_nav);51225123if(defined$co{'parent'}) {5124 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5125}else{5126 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5127}5128print"<div class=\"title_text\">\n".5129"<table class=\"object_header\">\n";5130print"<tr><td>author</td><td>". esc_html($co{'author'}) ."</td></tr>\n".5131"<tr>".5132"<td></td><td>$ad{'rfc2822'}";5133if($ad{'hour_local'} <6) {5134printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",5135$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});5136}else{5137printf(" (%02d:%02d%s)",5138$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});5139}5140print"</td>".5141"</tr>\n";5142print"<tr><td>committer</td><td>". esc_html($co{'committer'}) ."</td></tr>\n";5143print"<tr><td></td><td>$cd{'rfc2822'}".5144sprintf(" (%02d:%02d%s)",$cd{'hour_local'},$cd{'minute_local'},$cd{'tz_local'}) .5145"</td></tr>\n";5146print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";5147print"<tr>".5148"<td>tree</td>".5149"<td class=\"sha1\">".5150$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),5151class=>"list"},$co{'tree'}) .5152"</td>".5153"<td class=\"link\">".5154$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},5155"tree");5156my$snapshot_links= format_snapshot_links($hash);5157if(defined$snapshot_links) {5158print" | ".$snapshot_links;5159}5160print"</td>".5161"</tr>\n";51625163foreachmy$par(@$parents) {5164print"<tr>".5165"<td>parent</td>".5166"<td class=\"sha1\">".5167$cgi->a({-href => href(action=>"commit", hash=>$par),5168class=>"list"},$par) .5169"</td>".5170"<td class=\"link\">".5171$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .5172" | ".5173$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .5174"</td>".5175"</tr>\n";5176}5177print"</table>".5178"</div>\n";51795180print"<div class=\"page_body\">\n";5181 git_print_log($co{'comment'});5182print"</div>\n";51835184 git_difftree_body(\@difftree,$hash,@$parents);51855186 git_footer_html();5187}51885189sub git_object {5190# object is defined by:5191# - hash or hash_base alone5192# - hash_base and file_name5193my$type;51945195# - hash or hash_base alone5196if($hash|| ($hash_base&& !defined$file_name)) {5197my$object_id=$hash||$hash_base;51985199open my$fd,"-|", quote_command(5200 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'5201or die_error(404,"Object does not exist");5202$type= <$fd>;5203chomp$type;5204close$fd5205or die_error(404,"Object does not exist");52065207# - hash_base and file_name5208}elsif($hash_base&&defined$file_name) {5209$file_name=~ s,/+$,,;52105211system(git_cmd(),"cat-file",'-e',$hash_base) ==05212or die_error(404,"Base object does not exist");52135214# here errors should not hapen5215open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name5216or die_error(500,"Open git-ls-tree failed");5217my$line= <$fd>;5218close$fd;52195220#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'5221unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {5222 die_error(404,"File or directory for given base does not exist");5223}5224$type=$2;5225$hash=$3;5226}else{5227 die_error(400,"Not enough information to find object");5228}52295230print$cgi->redirect(-uri => href(action=>$type, -full=>1,5231 hash=>$hash, hash_base=>$hash_base,5232 file_name=>$file_name),5233-status =>'302 Found');5234}52355236sub git_blobdiff {5237my$format=shift||'html';52385239my$fd;5240my@difftree;5241my%diffinfo;5242my$expires;52435244# preparing $fd and %diffinfo for git_patchset_body5245# new style URI5246if(defined$hash_base&&defined$hash_parent_base) {5247if(defined$file_name) {5248# read raw output5249open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5250$hash_parent_base,$hash_base,5251"--", (defined$file_parent?$file_parent: ()),$file_name5252or die_error(500,"Open git-diff-tree failed");5253@difftree=map{chomp;$_} <$fd>;5254close$fd5255or die_error(404,"Reading git-diff-tree failed");5256@difftree5257or die_error(404,"Blob diff not found");52585259}elsif(defined$hash&&5260$hash=~/[0-9a-fA-F]{40}/) {5261# try to find filename from $hash52625263# read filtered raw output5264open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5265$hash_parent_base,$hash_base,"--"5266or die_error(500,"Open git-diff-tree failed");5267@difftree=5268# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5269# $hash == to_id5270grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5271map{chomp;$_} <$fd>;5272close$fd5273or die_error(404,"Reading git-diff-tree failed");5274@difftree5275or die_error(404,"Blob diff not found");52765277}else{5278 die_error(400,"Missing one of the blob diff parameters");5279}52805281if(@difftree>1) {5282 die_error(400,"Ambiguous blob diff specification");5283}52845285%diffinfo= parse_difftree_raw_line($difftree[0]);5286$file_parent||=$diffinfo{'from_file'} ||$file_name;5287$file_name||=$diffinfo{'to_file'};52885289$hash_parent||=$diffinfo{'from_id'};5290$hash||=$diffinfo{'to_id'};52915292# non-textual hash id's can be cached5293if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5294$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5295$expires='+1d';5296}52975298# open patch output5299open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5300'-p', ($formateq'html'?"--full-index": ()),5301$hash_parent_base,$hash_base,5302"--", (defined$file_parent?$file_parent: ()),$file_name5303or die_error(500,"Open git-diff-tree failed");5304}53055306# old/legacy style URI -- not generated anymore since 1.4.3.5307if(!%diffinfo) {5308 die_error('404 Not Found',"Missing one of the blob diff parameters")5309}53105311# header5312if($formateq'html') {5313my$formats_nav=5314$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5315"raw");5316 git_header_html(undef,$expires);5317if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5318 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5319 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5320}else{5321print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5322print"<div class=\"title\">$hashvs$hash_parent</div>\n";5323}5324if(defined$file_name) {5325 git_print_page_path($file_name,"blob",$hash_base);5326}else{5327print"<div class=\"page_path\"></div>\n";5328}53295330}elsif($formateq'plain') {5331print$cgi->header(5332-type =>'text/plain',5333-charset =>'utf-8',5334-expires =>$expires,5335-content_disposition =>'inline; filename="'."$file_name".'.patch"');53365337print"X-Git-Url: ".$cgi->self_url() ."\n\n";53385339}else{5340 die_error(400,"Unknown blobdiff format");5341}53425343# patch5344if($formateq'html') {5345print"<div class=\"page_body\">\n";53465347 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5348close$fd;53495350print"</div>\n";# class="page_body"5351 git_footer_html();53525353}else{5354while(my$line= <$fd>) {5355$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5356$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;53575358print$line;53595360last if$line=~m!^\+\+\+!;5361}5362local$/=undef;5363print<$fd>;5364close$fd;5365}5366}53675368sub git_blobdiff_plain {5369 git_blobdiff('plain');5370}53715372sub git_commitdiff {5373my$format=shift||'html';5374$hash||=$hash_base||"HEAD";5375my%co= parse_commit($hash)5376or die_error(404,"Unknown commit object");53775378# choose format for commitdiff for merge5379if(!defined$hash_parent&& @{$co{'parents'}} >1) {5380$hash_parent='--cc';5381}5382# we need to prepare $formats_nav before almost any parameter munging5383my$formats_nav;5384if($formateq'html') {5385$formats_nav=5386$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},5387"raw");53885389if(defined$hash_parent&&5390$hash_parentne'-c'&&$hash_parentne'--cc') {5391# commitdiff with two commits given5392my$hash_parent_short=$hash_parent;5393if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {5394$hash_parent_short=substr($hash_parent,0,7);5395}5396$formats_nav.=5397' (from';5398for(my$i=0;$i< @{$co{'parents'}};$i++) {5399if($co{'parents'}[$i]eq$hash_parent) {5400$formats_nav.=' parent '. ($i+1);5401last;5402}5403}5404$formats_nav.=': '.5405$cgi->a({-href => href(action=>"commitdiff",5406 hash=>$hash_parent)},5407 esc_html($hash_parent_short)) .5408')';5409}elsif(!$co{'parent'}) {5410# --root commitdiff5411$formats_nav.=' (initial)';5412}elsif(scalar@{$co{'parents'}} ==1) {5413# single parent commit5414$formats_nav.=5415' (parent: '.5416$cgi->a({-href => href(action=>"commitdiff",5417 hash=>$co{'parent'})},5418 esc_html(substr($co{'parent'},0,7))) .5419')';5420}else{5421# merge commit5422if($hash_parenteq'--cc') {5423$formats_nav.=' | '.5424$cgi->a({-href => href(action=>"commitdiff",5425 hash=>$hash, hash_parent=>'-c')},5426'combined');5427}else{# $hash_parent eq '-c'5428$formats_nav.=' | '.5429$cgi->a({-href => href(action=>"commitdiff",5430 hash=>$hash, hash_parent=>'--cc')},5431'compact');5432}5433$formats_nav.=5434' (merge: '.5435join(' ',map{5436$cgi->a({-href => href(action=>"commitdiff",5437 hash=>$_)},5438 esc_html(substr($_,0,7)));5439} @{$co{'parents'}} ) .5440')';5441}5442}54435444my$hash_parent_param=$hash_parent;5445if(!defined$hash_parent_param) {5446# --cc for multiple parents, --root for parentless5447$hash_parent_param=5448@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';5449}54505451# read commitdiff5452my$fd;5453my@difftree;5454if($formateq'html') {5455open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5456"--no-commit-id","--patch-with-raw","--full-index",5457$hash_parent_param,$hash,"--"5458or die_error(500,"Open git-diff-tree failed");54595460while(my$line= <$fd>) {5461chomp$line;5462# empty line ends raw part of diff-tree output5463last unless$line;5464push@difftree,scalar parse_difftree_raw_line($line);5465}54665467}elsif($formateq'plain') {5468open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5469'-p',$hash_parent_param,$hash,"--"5470or die_error(500,"Open git-diff-tree failed");54715472}else{5473 die_error(400,"Unknown commitdiff format");5474}54755476# non-textual hash id's can be cached5477my$expires;5478if($hash=~m/^[0-9a-fA-F]{40}$/) {5479$expires="+1d";5480}54815482# write commit message5483if($formateq'html') {5484my$refs= git_get_references();5485my$ref= format_ref_marker($refs,$co{'id'});54865487 git_header_html(undef,$expires);5488 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);5489 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);5490 git_print_authorship(\%co);5491print"<div class=\"page_body\">\n";5492if(@{$co{'comment'}} >1) {5493print"<div class=\"log\">\n";5494 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);5495print"</div>\n";# class="log"5496}54975498}elsif($formateq'plain') {5499my$refs= git_get_references("tags");5500my$tagname= git_get_rev_name_tags($hash);5501my$filename= basename($project) ."-$hash.patch";55025503print$cgi->header(5504-type =>'text/plain',5505-charset =>'utf-8',5506-expires =>$expires,5507-content_disposition =>'inline; filename="'."$filename".'"');5508my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5509print"From: ". to_utf8($co{'author'}) ."\n";5510print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";5511print"Subject: ". to_utf8($co{'title'}) ."\n";55125513print"X-Git-Tag:$tagname\n"if$tagname;5514print"X-Git-Url: ".$cgi->self_url() ."\n\n";55155516foreachmy$line(@{$co{'comment'}}) {5517print to_utf8($line) ."\n";5518}5519print"---\n\n";5520}55215522# write patch5523if($formateq'html') {5524my$use_parents= !defined$hash_parent||5525$hash_parenteq'-c'||$hash_parenteq'--cc';5526 git_difftree_body(\@difftree,$hash,5527$use_parents? @{$co{'parents'}} :$hash_parent);5528print"<br/>\n";55295530 git_patchset_body($fd, \@difftree,$hash,5531$use_parents? @{$co{'parents'}} :$hash_parent);5532close$fd;5533print"</div>\n";# class="page_body"5534 git_footer_html();55355536}elsif($formateq'plain') {5537local$/=undef;5538print<$fd>;5539close$fd5540or print"Reading git-diff-tree failed\n";5541}5542}55435544sub git_commitdiff_plain {5545 git_commitdiff('plain');5546}55475548sub git_history {5549if(!defined$hash_base) {5550$hash_base= git_get_head_hash($project);5551}5552if(!defined$page) {5553$page=0;5554}5555my$ftype;5556my%co= parse_commit($hash_base)5557or die_error(404,"Unknown commit object");55585559my$refs= git_get_references();5560my$limit=sprintf("--max-count=%i", (100* ($page+1)));55615562my@commitlist= parse_commits($hash_base,101, (100*$page),5563$file_name,"--full-history")5564or die_error(404,"No such file or directory on given branch");55655566if(!defined$hash&&defined$file_name) {5567# some commits could have deleted file in question,5568# and not have it in tree, but one of them has to have it5569for(my$i=0;$i<=@commitlist;$i++) {5570$hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5571last ifdefined$hash;5572}5573}5574if(defined$hash) {5575$ftype= git_get_type($hash);5576}5577if(!defined$ftype) {5578 die_error(500,"Unknown type of object");5579}55805581my$paging_nav='';5582if($page>0) {5583$paging_nav.=5584$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,5585 file_name=>$file_name)},5586"first");5587$paging_nav.=" ⋅ ".5588$cgi->a({-href => href(-replay=>1, page=>$page-1),5589-accesskey =>"p", -title =>"Alt-p"},"prev");5590}else{5591$paging_nav.="first";5592$paging_nav.=" ⋅ prev";5593}5594my$next_link='';5595if($#commitlist>=100) {5596$next_link=5597$cgi->a({-href => href(-replay=>1, page=>$page+1),5598-accesskey =>"n", -title =>"Alt-n"},"next");5599$paging_nav.=" ⋅$next_link";5600}else{5601$paging_nav.=" ⋅ next";5602}56035604 git_header_html();5605 git_print_page_nav('history','',$hash_base,$co{'tree'},$hash_base,$paging_nav);5606 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5607 git_print_page_path($file_name,$ftype,$hash_base);56085609 git_history_body(\@commitlist,0,99,5610$refs,$hash_base,$ftype,$next_link);56115612 git_footer_html();5613}56145615sub git_search {5616 gitweb_check_feature('search')or die_error(403,"Search is disabled");5617if(!defined$searchtext) {5618 die_error(400,"Text field is empty");5619}5620if(!defined$hash) {5621$hash= git_get_head_hash($project);5622}5623my%co= parse_commit($hash);5624if(!%co) {5625 die_error(404,"Unknown commit object");5626}5627if(!defined$page) {5628$page=0;5629}56305631$searchtype||='commit';5632if($searchtypeeq'pickaxe') {5633# pickaxe may take all resources of your box and run for several minutes5634# with every query - so decide by yourself how public you make this feature5635 gitweb_check_feature('pickaxe')5636or die_error(403,"Pickaxe is disabled");5637}5638if($searchtypeeq'grep') {5639 gitweb_check_feature('grep')5640or die_error(403,"Grep is disabled");5641}56425643 git_header_html();56445645if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {5646my$greptype;5647if($searchtypeeq'commit') {5648$greptype="--grep=";5649}elsif($searchtypeeq'author') {5650$greptype="--author=";5651}elsif($searchtypeeq'committer') {5652$greptype="--committer=";5653}5654$greptype.=$searchtext;5655my@commitlist= parse_commits($hash,101, (100*$page),undef,5656$greptype,'--regexp-ignore-case',5657$search_use_regexp?'--extended-regexp':'--fixed-strings');56585659my$paging_nav='';5660if($page>0) {5661$paging_nav.=5662$cgi->a({-href => href(action=>"search", hash=>$hash,5663 searchtext=>$searchtext,5664 searchtype=>$searchtype)},5665"first");5666$paging_nav.=" ⋅ ".5667$cgi->a({-href => href(-replay=>1, page=>$page-1),5668-accesskey =>"p", -title =>"Alt-p"},"prev");5669}else{5670$paging_nav.="first";5671$paging_nav.=" ⋅ prev";5672}5673my$next_link='';5674if($#commitlist>=100) {5675$next_link=5676$cgi->a({-href => href(-replay=>1, page=>$page+1),5677-accesskey =>"n", -title =>"Alt-n"},"next");5678$paging_nav.=" ⋅$next_link";5679}else{5680$paging_nav.=" ⋅ next";5681}56825683if($#commitlist>=100) {5684}56855686 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);5687 git_print_header_div('commit', esc_html($co{'title'}),$hash);5688 git_search_grep_body(\@commitlist,0,99,$next_link);5689}56905691if($searchtypeeq'pickaxe') {5692 git_print_page_nav('','',$hash,$co{'tree'},$hash);5693 git_print_header_div('commit', esc_html($co{'title'}),$hash);56945695print"<table class=\"pickaxe search\">\n";5696my$alternate=1;5697$/="\n";5698open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,5699'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",5700($search_use_regexp?'--pickaxe-regex': ());5701undef%co;5702my@files;5703while(my$line= <$fd>) {5704chomp$line;5705next unless$line;57065707my%set= parse_difftree_raw_line($line);5708if(defined$set{'commit'}) {5709# finish previous commit5710if(%co) {5711print"</td>\n".5712"<td class=\"link\">".5713$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5714" | ".5715$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5716print"</td>\n".5717"</tr>\n";5718}57195720if($alternate) {5721print"<tr class=\"dark\">\n";5722}else{5723print"<tr class=\"light\">\n";5724}5725$alternate^=1;5726%co= parse_commit($set{'commit'});5727my$author= chop_and_escape_str($co{'author_name'},15,5);5728print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5729"<td><i>$author</i></td>\n".5730"<td>".5731$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),5732-class=>"list subject"},5733 chop_and_escape_str($co{'title'},50) ."<br/>");5734}elsif(defined$set{'to_id'}) {5735next if($set{'to_id'} =~m/^0{40}$/);57365737print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},5738 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),5739-class=>"list"},5740"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .5741"<br/>\n";5742}5743}5744close$fd;57455746# finish last commit (warning: repetition!)5747if(%co) {5748print"</td>\n".5749"<td class=\"link\">".5750$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5751" | ".5752$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5753print"</td>\n".5754"</tr>\n";5755}57565757print"</table>\n";5758}57595760if($searchtypeeq'grep') {5761 git_print_page_nav('','',$hash,$co{'tree'},$hash);5762 git_print_header_div('commit', esc_html($co{'title'}),$hash);57635764print"<table class=\"grep_search\">\n";5765my$alternate=1;5766my$matches=0;5767$/="\n";5768open my$fd,"-|", git_cmd(),'grep','-n',5769$search_use_regexp? ('-E','-i') :'-F',5770$searchtext,$co{'tree'};5771my$lastfile='';5772while(my$line= <$fd>) {5773chomp$line;5774my($file,$lno,$ltext,$binary);5775last if($matches++>1000);5776if($line=~/^Binary file (.+) matches$/) {5777$file=$1;5778$binary=1;5779}else{5780(undef,$file,$lno,$ltext) =split(/:/,$line,4);5781}5782if($filene$lastfile) {5783$lastfileand print"</td></tr>\n";5784if($alternate++) {5785print"<tr class=\"dark\">\n";5786}else{5787print"<tr class=\"light\">\n";5788}5789print"<td class=\"list\">".5790$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5791 file_name=>"$file"),5792-class=>"list"}, esc_path($file));5793print"</td><td>\n";5794$lastfile=$file;5795}5796if($binary) {5797print"<div class=\"binary\">Binary file</div>\n";5798}else{5799$ltext= untabify($ltext);5800if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {5801$ltext= esc_html($1, -nbsp=>1);5802$ltext.='<span class="match">';5803$ltext.= esc_html($2, -nbsp=>1);5804$ltext.='</span>';5805$ltext.= esc_html($3, -nbsp=>1);5806}else{5807$ltext= esc_html($ltext, -nbsp=>1);5808}5809print"<div class=\"pre\">".5810$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5811 file_name=>"$file").'#l'.$lno,5812-class=>"linenr"},sprintf('%4i',$lno))5813.' '.$ltext."</div>\n";5814}5815}5816if($lastfile) {5817print"</td></tr>\n";5818if($matches>1000) {5819print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";5820}5821}else{5822print"<div class=\"diff nodifferences\">No matches found</div>\n";5823}5824close$fd;58255826print"</table>\n";5827}5828 git_footer_html();5829}58305831sub git_search_help {5832 git_header_html();5833 git_print_page_nav('','',$hash,$hash,$hash);5834print<<EOT;5835<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without5836regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,5837the pattern entered is recognized as the POSIX extended5838<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case5839insensitive).</p>5840<dl>5841<dt><b>commit</b></dt>5842<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>5843EOT5844my$have_grep= gitweb_check_feature('grep');5845if($have_grep) {5846print<<EOT;5847<dt><b>grep</b></dt>5848<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing5849 a different one) are searched for the given pattern. On large trees, this search can take5850a while and put some strain on the server, so please use it with some consideration. Note that5851due to git-grep peculiarity, currently if regexp mode is turned off, the matches are5852case-sensitive.</dd>5853EOT5854}5855print<<EOT;5856<dt><b>author</b></dt>5857<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>5858<dt><b>committer</b></dt>5859<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>5860EOT5861my$have_pickaxe= gitweb_check_feature('pickaxe');5862if($have_pickaxe) {5863print<<EOT;5864<dt><b>pickaxe</b></dt>5865<dd>All commits that caused the string to appear or disappear from any file (changes that5866added, removed or "modified" the string) will be listed. This search can take a while and5867takes a lot of strain on the server, so please use it wisely. Note that since you may be5868interested even in changes just changing the case as well, this search is case sensitive.</dd>5869EOT5870}5871print"</dl>\n";5872 git_footer_html();5873}58745875sub git_shortlog {5876my$head= git_get_head_hash($project);5877if(!defined$hash) {5878$hash=$head;5879}5880if(!defined$page) {5881$page=0;5882}5883my$refs= git_get_references();58845885my$commit_hash=$hash;5886if(defined$hash_parent) {5887$commit_hash="$hash_parent..$hash";5888}5889my@commitlist= parse_commits($commit_hash,101, (100*$page));58905891my$paging_nav= format_paging_nav('shortlog',$hash,$head,$page,$#commitlist>=100);5892my$next_link='';5893if($#commitlist>=100) {5894$next_link=5895$cgi->a({-href => href(-replay=>1, page=>$page+1),5896-accesskey =>"n", -title =>"Alt-n"},"next");5897}58985899 git_header_html();5900 git_print_page_nav('shortlog','',$hash,$hash,$hash,$paging_nav);5901 git_print_header_div('summary',$project);59025903 git_shortlog_body(\@commitlist,0,99,$refs,$next_link);59045905 git_footer_html();5906}59075908## ......................................................................5909## feeds (RSS, Atom; OPML)59105911sub git_feed {5912my$format=shift||'atom';5913my$have_blame= gitweb_check_feature('blame');59145915# Atom: http://www.atomenabled.org/developers/syndication/5916# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ5917if($formatne'rss'&&$formatne'atom') {5918 die_error(400,"Unknown web feed format");5919}59205921# log/feed of current (HEAD) branch, log of given branch, history of file/directory5922my$head=$hash||'HEAD';5923my@commitlist= parse_commits($head,150,0,$file_name);59245925my%latest_commit;5926my%latest_date;5927my$content_type="application/$format+xml";5928if(defined$cgi->http('HTTP_ACCEPT') &&5929$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {5930# browser (feed reader) prefers text/xml5931$content_type='text/xml';5932}5933if(defined($commitlist[0])) {5934%latest_commit= %{$commitlist[0]};5935%latest_date= parse_date($latest_commit{'author_epoch'});5936print$cgi->header(5937-type =>$content_type,5938-charset =>'utf-8',5939-last_modified =>$latest_date{'rfc2822'});5940}else{5941print$cgi->header(5942-type =>$content_type,5943-charset =>'utf-8');5944}59455946# Optimization: skip generating the body if client asks only5947# for Last-Modified date.5948return if($cgi->request_method()eq'HEAD');59495950# header variables5951my$title="$site_name-$project/$action";5952my$feed_type='log';5953if(defined$hash) {5954$title.=" - '$hash'";5955$feed_type='branch log';5956if(defined$file_name) {5957$title.=" ::$file_name";5958$feed_type='history';5959}5960}elsif(defined$file_name) {5961$title.=" -$file_name";5962$feed_type='history';5963}5964$title.="$feed_type";5965my$descr= git_get_project_description($project);5966if(defined$descr) {5967$descr= esc_html($descr);5968}else{5969$descr="$project".5970($formateq'rss'?'RSS':'Atom') .5971" feed";5972}5973my$owner= git_get_project_owner($project);5974$owner= esc_html($owner);59755976#header5977my$alt_url;5978if(defined$file_name) {5979$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);5980}elsif(defined$hash) {5981$alt_url= href(-full=>1, action=>"log", hash=>$hash);5982}else{5983$alt_url= href(-full=>1, action=>"summary");5984}5985print qq!<?xml version="1.0" encoding="utf-8"?>\n!;5986if($formateq'rss') {5987print<<XML;5988<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">5989<channel>5990XML5991print"<title>$title</title>\n".5992"<link>$alt_url</link>\n".5993"<description>$descr</description>\n".5994"<language>en</language>\n";5995}elsif($formateq'atom') {5996print<<XML;5997<feed xmlns="http://www.w3.org/2005/Atom">5998XML5999print"<title>$title</title>\n".6000"<subtitle>$descr</subtitle>\n".6001'<link rel="alternate" type="text/html" href="'.6002$alt_url.'" />'."\n".6003'<link rel="self" type="'.$content_type.'" href="'.6004$cgi->self_url() .'" />'."\n".6005"<id>". href(-full=>1) ."</id>\n".6006# use project owner for feed author6007"<author><name>$owner</name></author>\n";6008if(defined$favicon) {6009print"<icon>". esc_url($favicon) ."</icon>\n";6010}6011if(defined$logo_url) {6012# not twice as wide as tall: 72 x 27 pixels6013print"<logo>". esc_url($logo) ."</logo>\n";6014}6015if(!%latest_date) {6016# dummy date to keep the feed valid until commits trickle in:6017print"<updated>1970-01-01T00:00:00Z</updated>\n";6018}else{6019print"<updated>$latest_date{'iso-8601'}</updated>\n";6020}6021}60226023# contents6024for(my$i=0;$i<=$#commitlist;$i++) {6025my%co= %{$commitlist[$i]};6026my$commit=$co{'id'};6027# we read 150, we always show 30 and the ones more recent than 48 hours6028if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6029last;6030}6031my%cd= parse_date($co{'author_epoch'});60326033# get list of changed files6034open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6035$co{'parent'} ||"--root",6036$co{'id'},"--", (defined$file_name?$file_name: ())6037ornext;6038my@difftree=map{chomp;$_} <$fd>;6039close$fd6040ornext;60416042# print element (entry, item)6043my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6044if($formateq'rss') {6045print"<item>\n".6046"<title>". esc_html($co{'title'}) ."</title>\n".6047"<author>". esc_html($co{'author'}) ."</author>\n".6048"<pubDate>$cd{'rfc2822'}</pubDate>\n".6049"<guid isPermaLink=\"true\">$co_url</guid>\n".6050"<link>$co_url</link>\n".6051"<description>". esc_html($co{'title'}) ."</description>\n".6052"<content:encoded>".6053"<![CDATA[\n";6054}elsif($formateq'atom') {6055print"<entry>\n".6056"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6057"<updated>$cd{'iso-8601'}</updated>\n".6058"<author>\n".6059" <name>". esc_html($co{'author_name'}) ."</name>\n";6060if($co{'author_email'}) {6061print" <email>". esc_html($co{'author_email'}) ."</email>\n";6062}6063print"</author>\n".6064# use committer for contributor6065"<contributor>\n".6066" <name>". esc_html($co{'committer_name'}) ."</name>\n";6067if($co{'committer_email'}) {6068print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6069}6070print"</contributor>\n".6071"<published>$cd{'iso-8601'}</published>\n".6072"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6073"<id>$co_url</id>\n".6074"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6075"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6076}6077my$comment=$co{'comment'};6078print"<pre>\n";6079foreachmy$line(@$comment) {6080$line= esc_html($line);6081print"$line\n";6082}6083print"</pre><ul>\n";6084foreachmy$difftree_line(@difftree) {6085my%difftree= parse_difftree_raw_line($difftree_line);6086next if!$difftree{'from_id'};60876088my$file=$difftree{'file'} ||$difftree{'to_file'};60896090print"<li>".6091"[".6092$cgi->a({-href => href(-full=>1, action=>"blobdiff",6093 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6094 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6095 file_name=>$file, file_parent=>$difftree{'from_file'}),6096-title =>"diff"},'D');6097if($have_blame) {6098print$cgi->a({-href => href(-full=>1, action=>"blame",6099 file_name=>$file, hash_base=>$commit),6100-title =>"blame"},'B');6101}6102# if this is not a feed of a file history6103if(!defined$file_name||$file_namene$file) {6104print$cgi->a({-href => href(-full=>1, action=>"history",6105 file_name=>$file, hash=>$commit),6106-title =>"history"},'H');6107}6108$file= esc_path($file);6109print"] ".6110"$file</li>\n";6111}6112if($formateq'rss') {6113print"</ul>]]>\n".6114"</content:encoded>\n".6115"</item>\n";6116}elsif($formateq'atom') {6117print"</ul>\n</div>\n".6118"</content>\n".6119"</entry>\n";6120}6121}61226123# end of feed6124if($formateq'rss') {6125print"</channel>\n</rss>\n";6126}elsif($formateq'atom') {6127print"</feed>\n";6128}6129}61306131sub git_rss {6132 git_feed('rss');6133}61346135sub git_atom {6136 git_feed('atom');6137}61386139sub git_opml {6140my@list= git_get_projects_list();61416142print$cgi->header(-type =>'text/xml', -charset =>'utf-8');6143print<<XML;6144<?xml version="1.0" encoding="utf-8"?>6145<opml version="1.0">6146<head>6147 <title>$site_nameOPML Export</title>6148</head>6149<body>6150<outline text="git RSS feeds">6151XML61526153foreachmy$pr(@list) {6154my%proj=%$pr;6155my$head= git_get_head_hash($proj{'path'});6156if(!defined$head) {6157next;6158}6159$git_dir="$projectroot/$proj{'path'}";6160my%co= parse_commit($head);6161if(!%co) {6162next;6163}61646165my$path= esc_html(chop_str($proj{'path'},25,5));6166my$rss="$my_url?p=$proj{'path'};a=rss";6167my$html="$my_url?p=$proj{'path'};a=summary";6168print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";6169}6170print<<XML;6171</outline>6172</body>6173</opml>6174XML6175}