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 33my$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# only allow viewing of repositories also shown on the overview page 99our$strict_export="++GITWEB_STRICT_EXPORT++"; 100 101# list of git base URLs used for URL to where fetch project from, 102# i.e. full URL is "$git_base_url/$project" 103our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 104 105# default blob_plain mimetype and default charset for text/plain blob 106our$default_blob_plain_mimetype='text/plain'; 107our$default_text_plain_charset=undef; 108 109# file to use for guessing MIME types before trying /etc/mime.types 110# (relative to the current git repository) 111our$mimetypes_file=undef; 112 113# assume this charset if line contains non-UTF-8 characters; 114# it should be valid encoding (see Encoding::Supported(3pm) for list), 115# for which encoding all byte sequences are valid, for example 116# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 117# could be even 'utf-8' for the old behavior) 118our$fallback_encoding='latin1'; 119 120# rename detection options for git-diff and git-diff-tree 121# - default is '-M', with the cost proportional to 122# (number of removed files) * (number of new files). 123# - more costly is '-C' (which implies '-M'), with the cost proportional to 124# (number of changed files + number of removed files) * (number of new files) 125# - even more costly is '-C', '--find-copies-harder' with cost 126# (number of files in the original tree) * (number of new files) 127# - one might want to include '-B' option, e.g. '-B', '-M' 128our@diff_opts= ('-M');# taken from git_commit 129 130# information about snapshot formats that gitweb is capable of serving 131our%known_snapshot_formats= ( 132# name => { 133# 'display' => display name, 134# 'type' => mime type, 135# 'suffix' => filename suffix, 136# 'format' => --format for git-archive, 137# 'compressor' => [compressor command and arguments] 138# (array reference, optional)} 139# 140'tgz'=> { 141'display'=>'tar.gz', 142'type'=>'application/x-gzip', 143'suffix'=>'.tar.gz', 144'format'=>'tar', 145'compressor'=> ['gzip']}, 146 147'tbz2'=> { 148'display'=>'tar.bz2', 149'type'=>'application/x-bzip2', 150'suffix'=>'.tar.bz2', 151'format'=>'tar', 152'compressor'=> ['bzip2']}, 153 154'zip'=> { 155'display'=>'zip', 156'type'=>'application/x-zip', 157'suffix'=>'.zip', 158'format'=>'zip'}, 159); 160 161# Aliases so we understand old gitweb.snapshot values in repository 162# configuration. 163our%known_snapshot_format_aliases= ( 164'gzip'=>'tgz', 165'bzip2'=>'tbz2', 166 167# backward compatibility: legacy gitweb config support 168'x-gzip'=>undef,'gz'=>undef, 169'x-bzip2'=>undef,'bz2'=>undef, 170'x-zip'=>undef,''=>undef, 171); 172 173# You define site-wide feature defaults here; override them with 174# $GITWEB_CONFIG as necessary. 175our%feature= ( 176# feature => { 177# 'sub' => feature-sub (subroutine), 178# 'override' => allow-override (boolean), 179# 'default' => [ default options...] (array reference)} 180# 181# if feature is overridable (it means that allow-override has true value), 182# then feature-sub will be called with default options as parameters; 183# return value of feature-sub indicates if to enable specified feature 184# 185# if there is no 'sub' key (no feature-sub), then feature cannot be 186# overriden 187# 188# use gitweb_check_feature(<feature>) to check if <feature> is enabled 189 190# Enable the 'blame' blob view, showing the last commit that modified 191# each line in the file. This can be very CPU-intensive. 192 193# To enable system wide have in $GITWEB_CONFIG 194# $feature{'blame'}{'default'} = [1]; 195# To have project specific config enable override in $GITWEB_CONFIG 196# $feature{'blame'}{'override'} = 1; 197# and in project config gitweb.blame = 0|1; 198'blame'=> { 199'sub'=> \&feature_blame, 200'override'=>0, 201'default'=> [0]}, 202 203# Enable the 'snapshot' link, providing a compressed archive of any 204# tree. This can potentially generate high traffic if you have large 205# project. 206 207# Value is a list of formats defined in %known_snapshot_formats that 208# you wish to offer. 209# To disable system wide have in $GITWEB_CONFIG 210# $feature{'snapshot'}{'default'} = []; 211# To have project specific config enable override in $GITWEB_CONFIG 212# $feature{'snapshot'}{'override'} = 1; 213# and in project config, a comma-separated list of formats or "none" 214# to disable. Example: gitweb.snapshot = tbz2,zip; 215'snapshot'=> { 216'sub'=> \&feature_snapshot, 217'override'=>0, 218'default'=> ['tgz']}, 219 220# Enable text search, which will list the commits which match author, 221# committer or commit text to a given string. Enabled by default. 222# Project specific override is not supported. 223'search'=> { 224'override'=>0, 225'default'=> [1]}, 226 227# Enable grep search, which will list the files in currently selected 228# tree containing the given string. Enabled by default. This can be 229# potentially CPU-intensive, of course. 230 231# To enable system wide have in $GITWEB_CONFIG 232# $feature{'grep'}{'default'} = [1]; 233# To have project specific config enable override in $GITWEB_CONFIG 234# $feature{'grep'}{'override'} = 1; 235# and in project config gitweb.grep = 0|1; 236'grep'=> { 237'override'=>0, 238'default'=> [1]}, 239 240# Enable the pickaxe search, which will list the commits that modified 241# a given string in a file. This can be practical and quite faster 242# alternative to 'blame', but still potentially CPU-intensive. 243 244# To enable system wide have in $GITWEB_CONFIG 245# $feature{'pickaxe'}{'default'} = [1]; 246# To have project specific config enable override in $GITWEB_CONFIG 247# $feature{'pickaxe'}{'override'} = 1; 248# and in project config gitweb.pickaxe = 0|1; 249'pickaxe'=> { 250'sub'=> \&feature_pickaxe, 251'override'=>0, 252'default'=> [1]}, 253 254# Make gitweb use an alternative format of the URLs which can be 255# more readable and natural-looking: project name is embedded 256# directly in the path and the query string contains other 257# auxiliary information. All gitweb installations recognize 258# URL in either format; this configures in which formats gitweb 259# generates links. 260 261# To enable system wide have in $GITWEB_CONFIG 262# $feature{'pathinfo'}{'default'} = [1]; 263# Project specific override is not supported. 264 265# Note that you will need to change the default location of CSS, 266# favicon, logo and possibly other files to an absolute URL. Also, 267# if gitweb.cgi serves as your indexfile, you will need to force 268# $my_uri to contain the script name in your $GITWEB_CONFIG. 269'pathinfo'=> { 270'override'=>0, 271'default'=> [0]}, 272 273# Make gitweb consider projects in project root subdirectories 274# to be forks of existing projects. Given project $projname.git, 275# projects matching $projname/*.git will not be shown in the main 276# projects list, instead a '+' mark will be added to $projname 277# there and a 'forks' view will be enabled for the project, listing 278# all the forks. If project list is taken from a file, forks have 279# to be listed after the main project. 280 281# To enable system wide have in $GITWEB_CONFIG 282# $feature{'forks'}{'default'} = [1]; 283# Project specific override is not supported. 284'forks'=> { 285'override'=>0, 286'default'=> [0]}, 287 288# Insert custom links to the action bar of all project pages. 289# This enables you mainly to link to third-party scripts integrating 290# into gitweb; e.g. git-browser for graphical history representation 291# or custom web-based repository administration interface. 292 293# The 'default' value consists of a list of triplets in the form 294# (label, link, position) where position is the label after which 295# to inster the link and link is a format string where %n expands 296# to the project name, %f to the project path within the filesystem, 297# %h to the current hash (h gitweb parameter) and %b to the current 298# hash base (hb gitweb parameter). 299 300# To enable system wide have in $GITWEB_CONFIG e.g. 301# $feature{'actions'}{'default'} = [('graphiclog', 302# '/git-browser/by-commit.html?r=%n', 'summary')]; 303# Project specific override is not supported. 304'actions'=> { 305'override'=>0, 306'default'=> []}, 307 308# Allow gitweb scan project content tags described in ctags/ 309# of project repository, and display the popular Web 2.0-ish 310# "tag cloud" near the project list. Note that this is something 311# COMPLETELY different from the normal Git tags. 312 313# gitweb by itself can show existing tags, but it does not handle 314# tagging itself; you need an external application for that. 315# For an example script, check Girocco's cgi/tagproj.cgi. 316# You may want to install the HTML::TagCloud Perl module to get 317# a pretty tag cloud instead of just a list of tags. 318 319# To enable system wide have in $GITWEB_CONFIG 320# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 321# Project specific override is not supported. 322'ctags'=> { 323'override'=>0, 324'default'=> [0]}, 325); 326 327sub gitweb_check_feature { 328my($name) =@_; 329return unlessexists$feature{$name}; 330my($sub,$override,@defaults) = ( 331$feature{$name}{'sub'}, 332$feature{$name}{'override'}, 333@{$feature{$name}{'default'}}); 334if(!$override) {return@defaults; } 335if(!defined$sub) { 336warn"feature$nameis not overrideable"; 337return@defaults; 338} 339return$sub->(@defaults); 340} 341 342sub feature_blame { 343my($val) = git_get_project_config('blame','--bool'); 344 345if($valeq'true') { 346return1; 347}elsif($valeq'false') { 348return0; 349} 350 351return$_[0]; 352} 353 354sub feature_snapshot { 355my(@fmts) =@_; 356 357my($val) = git_get_project_config('snapshot'); 358 359if($val) { 360@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 361} 362 363return@fmts; 364} 365 366sub feature_grep { 367my($val) = git_get_project_config('grep','--bool'); 368 369if($valeq'true') { 370return(1); 371}elsif($valeq'false') { 372return(0); 373} 374 375return($_[0]); 376} 377 378sub feature_pickaxe { 379my($val) = git_get_project_config('pickaxe','--bool'); 380 381if($valeq'true') { 382return(1); 383}elsif($valeq'false') { 384return(0); 385} 386 387return($_[0]); 388} 389 390# checking HEAD file with -e is fragile if the repository was 391# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 392# and then pruned. 393sub check_head_link { 394my($dir) =@_; 395my$headfile="$dir/HEAD"; 396return((-e $headfile) || 397(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 398} 399 400sub check_export_ok { 401my($dir) =@_; 402return(check_head_link($dir) && 403(!$export_ok|| -e "$dir/$export_ok")); 404} 405 406# process alternate names for backward compatibility 407# filter out unsupported (unknown) snapshot formats 408sub filter_snapshot_fmts { 409my@fmts=@_; 410 411@fmts=map{ 412exists$known_snapshot_format_aliases{$_} ? 413$known_snapshot_format_aliases{$_} :$_}@fmts; 414@fmts=grep(exists$known_snapshot_formats{$_},@fmts); 415 416} 417 418our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 419if(-e $GITWEB_CONFIG) { 420do$GITWEB_CONFIG; 421}else{ 422our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 423do$GITWEB_CONFIG_SYSTEMif-e $GITWEB_CONFIG_SYSTEM; 424} 425 426# version of the core git binary 427our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 428 429$projects_list||=$projectroot; 430 431# ====================================================================== 432# input validation and dispatch 433 434# input parameters can be collected from a variety of sources (presently, CGI 435# and PATH_INFO), so we define an %input_params hash that collects them all 436# together during validation: this allows subsequent uses (e.g. href()) to be 437# agnostic of the parameter origin 438 439my%input_params= (); 440 441# input parameters are stored with the long parameter name as key. This will 442# also be used in the href subroutine to convert parameters to their CGI 443# equivalent, and since the href() usage is the most frequent one, we store 444# the name -> CGI key mapping here, instead of the reverse. 445# 446# XXX: Warning: If you touch this, check the search form for updating, 447# too. 448 449my@cgi_param_mapping= ( 450 project =>"p", 451 action =>"a", 452 file_name =>"f", 453 file_parent =>"fp", 454 hash =>"h", 455 hash_parent =>"hp", 456 hash_base =>"hb", 457 hash_parent_base =>"hpb", 458 page =>"pg", 459 order =>"o", 460 searchtext =>"s", 461 searchtype =>"st", 462 snapshot_format =>"sf", 463 extra_options =>"opt", 464 search_use_regexp =>"sr", 465); 466my%cgi_param_mapping=@cgi_param_mapping; 467 468# we will also need to know the possible actions, for validation 469my%actions= ( 470"blame"=> \&git_blame, 471"blobdiff"=> \&git_blobdiff, 472"blobdiff_plain"=> \&git_blobdiff_plain, 473"blob"=> \&git_blob, 474"blob_plain"=> \&git_blob_plain, 475"commitdiff"=> \&git_commitdiff, 476"commitdiff_plain"=> \&git_commitdiff_plain, 477"commit"=> \&git_commit, 478"forks"=> \&git_forks, 479"heads"=> \&git_heads, 480"history"=> \&git_history, 481"log"=> \&git_log, 482"rss"=> \&git_rss, 483"atom"=> \&git_atom, 484"search"=> \&git_search, 485"search_help"=> \&git_search_help, 486"shortlog"=> \&git_shortlog, 487"summary"=> \&git_summary, 488"tag"=> \&git_tag, 489"tags"=> \&git_tags, 490"tree"=> \&git_tree, 491"snapshot"=> \&git_snapshot, 492"object"=> \&git_object, 493# those below don't need $project 494"opml"=> \&git_opml, 495"project_list"=> \&git_project_list, 496"project_index"=> \&git_project_index, 497); 498 499# finally, we have the hash of allowed extra_options for the commands that 500# allow them 501my%allowed_options= ( 502"--no-merges"=> [qw(rss atom log shortlog history)], 503); 504 505# fill %input_params with the CGI parameters. All values except for 'opt' 506# should be single values, but opt can be an array. We should probably 507# build an array of parameters that can be multi-valued, but since for the time 508# being it's only this one, we just single it out 509while(my($name,$symbol) =each%cgi_param_mapping) { 510if($symboleq'opt') { 511$input_params{$name} = [$cgi->param($symbol) ]; 512}else{ 513$input_params{$name} =$cgi->param($symbol); 514} 515} 516 517# now read PATH_INFO and update the parameter list for missing parameters 518sub evaluate_path_info { 519return ifdefined$input_params{'project'}; 520return if!$path_info; 521$path_info=~ s,^/+,,; 522return if!$path_info; 523 524# find which part of PATH_INFO is project 525my$project=$path_info; 526$project=~ s,/+$,,; 527while($project&& !check_head_link("$projectroot/$project")) { 528$project=~ s,/*[^/]*$,,; 529} 530return unless$project; 531$input_params{'project'} =$project; 532 533# do not change any parameters if an action is given using the query string 534return if$input_params{'action'}; 535$path_info=~ s,^\Q$project\E/*,,; 536 537# next, check if we have an action 538my$action=$path_info; 539$action=~ s,/.*$,,; 540if(exists$actions{$action}) { 541$path_info=~ s,^$action/*,,; 542$input_params{'action'} =$action; 543} 544 545# list of actions that want hash_base instead of hash, but can have no 546# pathname (f) parameter 547my@wants_base= ( 548'tree', 549'history', 550); 551 552# we want to catch 553# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 554my($parentrefname,$parentpathname,$refname,$pathname) = 555($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/); 556 557# first, analyze the 'current' part 558if(defined$pathname) { 559# we got "branch:filename" or "branch:dir/" 560# we could use git_get_type(branch:pathname), but: 561# - it needs $git_dir 562# - it does a git() call 563# - the convention of terminating directories with a slash 564# makes it superfluous 565# - embedding the action in the PATH_INFO would make it even 566# more superfluous 567$pathname=~ s,^/+,,; 568if(!$pathname||substr($pathname, -1)eq"/") { 569$input_params{'action'} ||="tree"; 570$pathname=~ s,/$,,; 571}else{ 572# the default action depends on whether we had parent info 573# or not 574if($parentrefname) { 575$input_params{'action'} ||="blobdiff_plain"; 576}else{ 577$input_params{'action'} ||="blob_plain"; 578} 579} 580$input_params{'hash_base'} ||=$refname; 581$input_params{'file_name'} ||=$pathname; 582}elsif(defined$refname) { 583# we got "branch". In this case we have to choose if we have to 584# set hash or hash_base. 585# 586# Most of the actions without a pathname only want hash to be 587# set, except for the ones specified in @wants_base that want 588# hash_base instead. It should also be noted that hand-crafted 589# links having 'history' as an action and no pathname or hash 590# set will fail, but that happens regardless of PATH_INFO. 591$input_params{'action'} ||="shortlog"; 592if(grep{$_eq$input_params{'action'} }@wants_base) { 593$input_params{'hash_base'} ||=$refname; 594}else{ 595$input_params{'hash'} ||=$refname; 596} 597} 598 599# next, handle the 'parent' part, if present 600if(defined$parentrefname) { 601# a missing pathspec defaults to the 'current' filename, allowing e.g. 602# someproject/blobdiff/oldrev..newrev:/filename 603if($parentpathname) { 604$parentpathname=~ s,^/+,,; 605$parentpathname=~ s,/$,,; 606$input_params{'file_parent'} ||=$parentpathname; 607}else{ 608$input_params{'file_parent'} ||=$input_params{'file_name'}; 609} 610# we assume that hash_parent_base is wanted if a path was specified, 611# or if the action wants hash_base instead of hash 612if(defined$input_params{'file_parent'} || 613grep{$_eq$input_params{'action'} }@wants_base) { 614$input_params{'hash_parent_base'} ||=$parentrefname; 615}else{ 616$input_params{'hash_parent'} ||=$parentrefname; 617} 618} 619 620# for the snapshot action, we allow URLs in the form 621# $project/snapshot/$hash.ext 622# where .ext determines the snapshot and gets removed from the 623# passed $refname to provide the $hash. 624# 625# To be able to tell that $refname includes the format extension, we 626# require the following two conditions to be satisfied: 627# - the hash input parameter MUST have been set from the $refname part 628# of the URL (i.e. they must be equal) 629# - the snapshot format MUST NOT have been defined already (e.g. from 630# CGI parameter sf) 631# It's also useless to try any matching unless $refname has a dot, 632# so we check for that too 633if(defined$input_params{'action'} && 634$input_params{'action'}eq'snapshot'&& 635defined$refname&&index($refname,'.') != -1&& 636$refnameeq$input_params{'hash'} && 637!defined$input_params{'snapshot_format'}) { 638# We loop over the known snapshot formats, checking for 639# extensions. Allowed extensions are both the defined suffix 640# (which includes the initial dot already) and the snapshot 641# format key itself, with a prepended dot 642while(my($fmt,%opt) =each%known_snapshot_formats) { 643my$hash=$refname; 644my$sfx; 645$hash=~s/(\Q$opt{'suffix'}\E|\Q.$fmt\E)$//; 646next unless$sfx=$1; 647# a valid suffix was found, so set the snapshot format 648# and reset the hash parameter 649$input_params{'snapshot_format'} =$fmt; 650$input_params{'hash'} =$hash; 651# we also set the format suffix to the one requested 652# in the URL: this way a request for e.g. .tgz returns 653# a .tgz instead of a .tar.gz 654$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 655last; 656} 657} 658} 659evaluate_path_info(); 660 661our$action=$input_params{'action'}; 662if(defined$action) { 663if(!validate_action($action)) { 664 die_error(400,"Invalid action parameter"); 665} 666} 667 668# parameters which are pathnames 669our$project=$input_params{'project'}; 670if(defined$project) { 671if(!validate_project($project)) { 672undef$project; 673 die_error(404,"No such project"); 674} 675} 676 677our$file_name=$input_params{'file_name'}; 678if(defined$file_name) { 679if(!validate_pathname($file_name)) { 680 die_error(400,"Invalid file parameter"); 681} 682} 683 684our$file_parent=$input_params{'file_parent'}; 685if(defined$file_parent) { 686if(!validate_pathname($file_parent)) { 687 die_error(400,"Invalid file parent parameter"); 688} 689} 690 691# parameters which are refnames 692our$hash=$input_params{'hash'}; 693if(defined$hash) { 694if(!validate_refname($hash)) { 695 die_error(400,"Invalid hash parameter"); 696} 697} 698 699our$hash_parent=$input_params{'hash_parent'}; 700if(defined$hash_parent) { 701if(!validate_refname($hash_parent)) { 702 die_error(400,"Invalid hash parent parameter"); 703} 704} 705 706our$hash_base=$input_params{'hash_base'}; 707if(defined$hash_base) { 708if(!validate_refname($hash_base)) { 709 die_error(400,"Invalid hash base parameter"); 710} 711} 712 713our@extra_options= @{$input_params{'extra_options'}}; 714# @extra_options is always defined, since it can only be (currently) set from 715# CGI, and $cgi->param() returns the empty array in array context if the param 716# is not set 717foreachmy$opt(@extra_options) { 718if(not exists$allowed_options{$opt}) { 719 die_error(400,"Invalid option parameter"); 720} 721if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 722 die_error(400,"Invalid option parameter for this action"); 723} 724} 725 726our$hash_parent_base=$input_params{'hash_parent_base'}; 727if(defined$hash_parent_base) { 728if(!validate_refname($hash_parent_base)) { 729 die_error(400,"Invalid hash parent base parameter"); 730} 731} 732 733# other parameters 734our$page=$input_params{'page'}; 735if(defined$page) { 736if($page=~m/[^0-9]/) { 737 die_error(400,"Invalid page parameter"); 738} 739} 740 741our$searchtype=$input_params{'searchtype'}; 742if(defined$searchtype) { 743if($searchtype=~m/[^a-z]/) { 744 die_error(400,"Invalid searchtype parameter"); 745} 746} 747 748our$search_use_regexp=$input_params{'search_use_regexp'}; 749 750our$searchtext=$input_params{'searchtext'}; 751our$search_regexp; 752if(defined$searchtext) { 753if(length($searchtext) <2) { 754 die_error(403,"At least two characters are required for search parameter"); 755} 756$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 757} 758 759# path to the current git repository 760our$git_dir; 761$git_dir="$projectroot/$project"if$project; 762 763# list of supported snapshot formats 764our@snapshot_fmts= gitweb_check_feature('snapshot'); 765@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts); 766 767# dispatch 768if(!defined$action) { 769if(defined$hash) { 770$action= git_get_type($hash); 771}elsif(defined$hash_base&&defined$file_name) { 772$action= git_get_type("$hash_base:$file_name"); 773}elsif(defined$project) { 774$action='summary'; 775}else{ 776$action='project_list'; 777} 778} 779if(!defined($actions{$action})) { 780 die_error(400,"Unknown action"); 781} 782if($action!~m/^(opml|project_list|project_index)$/&& 783!$project) { 784 die_error(400,"Project needed"); 785} 786$actions{$action}->(); 787exit; 788 789## ====================================================================== 790## action links 791 792sub href (%) { 793my%params=@_; 794# default is to use -absolute url() i.e. $my_uri 795my$href=$params{-full} ?$my_url:$my_uri; 796 797$params{'project'} =$projectunlessexists$params{'project'}; 798 799if($params{-replay}) { 800while(my($name,$symbol) =each%cgi_param_mapping) { 801if(!exists$params{$name}) { 802$params{$name} =$input_params{$name}; 803} 804} 805} 806 807my($use_pathinfo) = gitweb_check_feature('pathinfo'); 808if($use_pathinfo) { 809# try to put as many parameters as possible in PATH_INFO: 810# - project name 811# - action 812# - hash_parent or hash_parent_base:/file_parent 813# - hash or hash_base:/filename 814# - the snapshot_format as an appropriate suffix 815 816# When the script is the root DirectoryIndex for the domain, 817# $href here would be something like http://gitweb.example.com/ 818# Thus, we strip any trailing / from $href, to spare us double 819# slashes in the final URL 820$href=~ s,/$,,; 821 822# Then add the project name, if present 823$href.="/".esc_url($params{'project'})ifdefined$params{'project'}; 824delete$params{'project'}; 825 826# since we destructively absorb parameters, we keep this 827# boolean that remembers if we're handling a snapshot 828my$is_snapshot=$params{'action'}eq'snapshot'; 829 830# Summary just uses the project path URL, any other action is 831# added to the URL 832if(defined$params{'action'}) { 833$href.="/".esc_url($params{'action'})unless$params{'action'}eq'summary'; 834delete$params{'action'}; 835} 836 837# Next, we put hash_parent_base:/file_parent..hash_base:/file_name, 838# stripping nonexistent or useless pieces 839$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'} 840||$params{'hash_parent'} ||$params{'hash'}); 841if(defined$params{'hash_base'}) { 842if(defined$params{'hash_parent_base'}) { 843$href.= esc_url($params{'hash_parent_base'}); 844# skip the file_parent if it's the same as the file_name 845delete$params{'file_parent'}if$params{'file_parent'}eq$params{'file_name'}; 846if(defined$params{'file_parent'} &&$params{'file_parent'} !~/\.\./) { 847$href.=":/".esc_url($params{'file_parent'}); 848delete$params{'file_parent'}; 849} 850$href.=".."; 851delete$params{'hash_parent'}; 852delete$params{'hash_parent_base'}; 853}elsif(defined$params{'hash_parent'}) { 854$href.= esc_url($params{'hash_parent'}).".."; 855delete$params{'hash_parent'}; 856} 857 858$href.= esc_url($params{'hash_base'}); 859if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) { 860$href.=":/".esc_url($params{'file_name'}); 861delete$params{'file_name'}; 862} 863delete$params{'hash'}; 864delete$params{'hash_base'}; 865}elsif(defined$params{'hash'}) { 866$href.= esc_url($params{'hash'}); 867delete$params{'hash'}; 868} 869 870# If the action was a snapshot, we can absorb the 871# snapshot_format parameter too 872if($is_snapshot) { 873my$fmt=$params{'snapshot_format'}; 874# snapshot_format should always be defined when href() 875# is called, but just in case some code forgets, we 876# fall back to the default 877$fmt||=$snapshot_fmts[0]; 878$href.=$known_snapshot_formats{$fmt}{'suffix'}; 879delete$params{'snapshot_format'}; 880} 881} 882 883# now encode the parameters explicitly 884my@result= (); 885for(my$i=0;$i<@cgi_param_mapping;$i+=2) { 886my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]); 887if(defined$params{$name}) { 888if(ref($params{$name})eq"ARRAY") { 889foreachmy$par(@{$params{$name}}) { 890push@result,$symbol."=". esc_param($par); 891} 892}else{ 893push@result,$symbol."=". esc_param($params{$name}); 894} 895} 896} 897$href.="?".join(';',@result)ifscalar@result; 898 899return$href; 900} 901 902 903## ====================================================================== 904## validation, quoting/unquoting and escaping 905 906sub validate_action { 907my$input=shift||returnundef; 908returnundefunlessexists$actions{$input}; 909return$input; 910} 911 912sub validate_project { 913my$input=shift||returnundef; 914if(!validate_pathname($input) || 915!(-d "$projectroot/$input") || 916!check_head_link("$projectroot/$input") || 917($export_ok&& !(-e "$projectroot/$input/$export_ok")) || 918($strict_export&& !project_in_list($input))) { 919returnundef; 920}else{ 921return$input; 922} 923} 924 925sub validate_pathname { 926my$input=shift||returnundef; 927 928# no '.' or '..' as elements of path, i.e. no '.' nor '..' 929# at the beginning, at the end, and between slashes. 930# also this catches doubled slashes 931if($input=~m!(^|/)(|\.|\.\.)(/|$)!) { 932returnundef; 933} 934# no null characters 935if($input=~m!\0!) { 936returnundef; 937} 938return$input; 939} 940 941sub validate_refname { 942my$input=shift||returnundef; 943 944# textual hashes are O.K. 945if($input=~m/^[0-9a-fA-F]{40}$/) { 946return$input; 947} 948# it must be correct pathname 949$input= validate_pathname($input) 950orreturnundef; 951# restrictions on ref name according to git-check-ref-format 952if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) { 953returnundef; 954} 955return$input; 956} 957 958# decode sequences of octets in utf8 into Perl's internal form, 959# which is utf-8 with utf8 flag set if needed. gitweb writes out 960# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning 961sub to_utf8 { 962my$str=shift; 963if(utf8::valid($str)) { 964 utf8::decode($str); 965return$str; 966}else{ 967return decode($fallback_encoding,$str, Encode::FB_DEFAULT); 968} 969} 970 971# quote unsafe chars, but keep the slash, even when it's not 972# correct, but quoted slashes look too horrible in bookmarks 973sub esc_param { 974my$str=shift; 975$str=~s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X",ord($1))/eg; 976$str=~s/\+/%2B/g; 977$str=~s/ /\+/g; 978return$str; 979} 980 981# quote unsafe chars in whole URL, so some charactrs cannot be quoted 982sub esc_url { 983my$str=shift; 984$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X",ord($1))/eg; 985$str=~s/\+/%2B/g; 986$str=~s/ /\+/g; 987return$str; 988} 989 990# replace invalid utf8 character with SUBSTITUTION sequence 991sub esc_html ($;%) { 992my$str=shift; 993my%opts=@_; 994 995$str= to_utf8($str); 996$str=$cgi->escapeHTML($str); 997if($opts{'-nbsp'}) { 998$str=~s/ / /g; 999}1000$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1001return$str;1002}10031004# quote control characters and escape filename to HTML1005sub esc_path {1006my$str=shift;1007my%opts=@_;10081009$str= to_utf8($str);1010$str=$cgi->escapeHTML($str);1011if($opts{'-nbsp'}) {1012$str=~s/ / /g;1013}1014$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1015return$str;1016}10171018# Make control characters "printable", using character escape codes (CEC)1019sub quot_cec {1020my$cntrl=shift;1021my%opts=@_;1022my%es= (# character escape codes, aka escape sequences1023"\t"=>'\t',# tab (HT)1024"\n"=>'\n',# line feed (LF)1025"\r"=>'\r',# carrige return (CR)1026"\f"=>'\f',# form feed (FF)1027"\b"=>'\b',# backspace (BS)1028"\a"=>'\a',# alarm (bell) (BEL)1029"\e"=>'\e',# escape (ESC)1030"\013"=>'\v',# vertical tab (VT)1031"\000"=>'\0',# nul character (NUL)1032);1033my$chr= ( (exists$es{$cntrl})1034?$es{$cntrl}1035:sprintf('\%2x',ord($cntrl)) );1036if($opts{-nohtml}) {1037return$chr;1038}else{1039return"<span class=\"cntrl\">$chr</span>";1040}1041}10421043# Alternatively use unicode control pictures codepoints,1044# Unicode "printable representation" (PR)1045sub quot_upr {1046my$cntrl=shift;1047my%opts=@_;10481049my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1050if($opts{-nohtml}) {1051return$chr;1052}else{1053return"<span class=\"cntrl\">$chr</span>";1054}1055}10561057# git may return quoted and escaped filenames1058sub unquote {1059my$str=shift;10601061sub unq {1062my$seq=shift;1063my%es= (# character escape codes, aka escape sequences1064't'=>"\t",# tab (HT, TAB)1065'n'=>"\n",# newline (NL)1066'r'=>"\r",# return (CR)1067'f'=>"\f",# form feed (FF)1068'b'=>"\b",# backspace (BS)1069'a'=>"\a",# alarm (bell) (BEL)1070'e'=>"\e",# escape (ESC)1071'v'=>"\013",# vertical tab (VT)1072);10731074if($seq=~m/^[0-7]{1,3}$/) {1075# octal char sequence1076returnchr(oct($seq));1077}elsif(exists$es{$seq}) {1078# C escape sequence, aka character escape code1079return$es{$seq};1080}1081# quoted ordinary character1082return$seq;1083}10841085if($str=~m/^"(.*)"$/) {1086# needs unquoting1087$str=$1;1088$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1089}1090return$str;1091}10921093# escape tabs (convert tabs to spaces)1094sub untabify {1095my$line=shift;10961097while((my$pos=index($line,"\t")) != -1) {1098if(my$count= (8- ($pos%8))) {1099my$spaces=' ' x $count;1100$line=~s/\t/$spaces/;1101}1102}11031104return$line;1105}11061107sub project_in_list {1108my$project=shift;1109my@list= git_get_projects_list();1110return@list&&scalar(grep{$_->{'path'}eq$project}@list);1111}11121113## ----------------------------------------------------------------------1114## HTML aware string manipulation11151116# Try to chop given string on a word boundary between position1117# $len and $len+$add_len. If there is no word boundary there,1118# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1119# (marking chopped part) would be longer than given string.1120sub chop_str {1121my$str=shift;1122my$len=shift;1123my$add_len=shift||10;1124my$where=shift||'right';# 'left' | 'center' | 'right'11251126# Make sure perl knows it is utf8 encoded so we don't1127# cut in the middle of a utf8 multibyte char.1128$str= to_utf8($str);11291130# allow only $len chars, but don't cut a word if it would fit in $add_len1131# if it doesn't fit, cut it if it's still longer than the dots we would add1132# remove chopped character entities entirely11331134# when chopping in the middle, distribute $len into left and right part1135# return early if chopping wouldn't make string shorter1136if($whereeq'center') {1137return$strif($len+5>=length($str));# filler is length 51138$len=int($len/2);1139}else{1140return$strif($len+4>=length($str));# filler is length 41141}11421143# regexps: ending and beginning with word part up to $add_len1144my$endre=qr/.{$len}\w{0,$add_len}/;1145my$begre=qr/\w{0,$add_len}.{$len}/;11461147if($whereeq'left') {1148$str=~m/^(.*?)($begre)$/;1149my($lead,$body) = ($1,$2);1150if(length($lead) >4) {1151$body=~s/^[^;]*;//if($lead=~m/&[^;]*$/);1152$lead=" ...";1153}1154return"$lead$body";11551156}elsif($whereeq'center') {1157$str=~m/^($endre)(.*)$/;1158my($left,$str) = ($1,$2);1159$str=~m/^(.*?)($begre)$/;1160my($mid,$right) = ($1,$2);1161if(length($mid) >5) {1162$left=~s/&[^;]*$//;1163$right=~s/^[^;]*;//if($mid=~m/&[^;]*$/);1164$mid=" ... ";1165}1166return"$left$mid$right";11671168}else{1169$str=~m/^($endre)(.*)$/;1170my$body=$1;1171my$tail=$2;1172if(length($tail) >4) {1173$body=~s/&[^;]*$//;1174$tail="... ";1175}1176return"$body$tail";1177}1178}11791180# takes the same arguments as chop_str, but also wraps a <span> around the1181# result with a title attribute if it does get chopped. Additionally, the1182# string is HTML-escaped.1183sub chop_and_escape_str {1184my($str) =@_;11851186my$chopped= chop_str(@_);1187if($choppedeq$str) {1188return esc_html($chopped);1189}else{1190$str=~s/([[:cntrl:]])/?/g;1191return$cgi->span({-title=>$str}, esc_html($chopped));1192}1193}11941195## ----------------------------------------------------------------------1196## functions returning short strings11971198# CSS class for given age value (in seconds)1199sub age_class {1200my$age=shift;12011202if(!defined$age) {1203return"noage";1204}elsif($age<60*60*2) {1205return"age0";1206}elsif($age<60*60*24*2) {1207return"age1";1208}else{1209return"age2";1210}1211}12121213# convert age in seconds to "nn units ago" string1214sub age_string {1215my$age=shift;1216my$age_str;12171218if($age>60*60*24*365*2) {1219$age_str= (int$age/60/60/24/365);1220$age_str.=" years ago";1221}elsif($age>60*60*24*(365/12)*2) {1222$age_str=int$age/60/60/24/(365/12);1223$age_str.=" months ago";1224}elsif($age>60*60*24*7*2) {1225$age_str=int$age/60/60/24/7;1226$age_str.=" weeks ago";1227}elsif($age>60*60*24*2) {1228$age_str=int$age/60/60/24;1229$age_str.=" days ago";1230}elsif($age>60*60*2) {1231$age_str=int$age/60/60;1232$age_str.=" hours ago";1233}elsif($age>60*2) {1234$age_str=int$age/60;1235$age_str.=" min ago";1236}elsif($age>2) {1237$age_str=int$age;1238$age_str.=" sec ago";1239}else{1240$age_str.=" right now";1241}1242return$age_str;1243}12441245useconstant{1246 S_IFINVALID =>0030000,1247 S_IFGITLINK =>0160000,1248};12491250# submodule/subproject, a commit object reference1251sub S_ISGITLINK($) {1252my$mode=shift;12531254return(($mode& S_IFMT) == S_IFGITLINK)1255}12561257# convert file mode in octal to symbolic file mode string1258sub mode_str {1259my$mode=oct shift;12601261if(S_ISGITLINK($mode)) {1262return'm---------';1263}elsif(S_ISDIR($mode& S_IFMT)) {1264return'drwxr-xr-x';1265}elsif(S_ISLNK($mode)) {1266return'lrwxrwxrwx';1267}elsif(S_ISREG($mode)) {1268# git cares only about the executable bit1269if($mode& S_IXUSR) {1270return'-rwxr-xr-x';1271}else{1272return'-rw-r--r--';1273};1274}else{1275return'----------';1276}1277}12781279# convert file mode in octal to file type string1280sub file_type {1281my$mode=shift;12821283if($mode!~m/^[0-7]+$/) {1284return$mode;1285}else{1286$mode=oct$mode;1287}12881289if(S_ISGITLINK($mode)) {1290return"submodule";1291}elsif(S_ISDIR($mode& S_IFMT)) {1292return"directory";1293}elsif(S_ISLNK($mode)) {1294return"symlink";1295}elsif(S_ISREG($mode)) {1296return"file";1297}else{1298return"unknown";1299}1300}13011302# convert file mode in octal to file type description string1303sub file_type_long {1304my$mode=shift;13051306if($mode!~m/^[0-7]+$/) {1307return$mode;1308}else{1309$mode=oct$mode;1310}13111312if(S_ISGITLINK($mode)) {1313return"submodule";1314}elsif(S_ISDIR($mode& S_IFMT)) {1315return"directory";1316}elsif(S_ISLNK($mode)) {1317return"symlink";1318}elsif(S_ISREG($mode)) {1319if($mode& S_IXUSR) {1320return"executable";1321}else{1322return"file";1323};1324}else{1325return"unknown";1326}1327}132813291330## ----------------------------------------------------------------------1331## functions returning short HTML fragments, or transforming HTML fragments1332## which don't belong to other sections13331334# format line of commit message.1335sub format_log_line_html {1336my$line=shift;13371338$line= esc_html($line, -nbsp=>1);1339if($line=~m/([0-9a-fA-F]{8,40})/) {1340my$hash_text=$1;1341my$link=1342$cgi->a({-href => href(action=>"object", hash=>$hash_text),1343-class=>"text"},$hash_text);1344$line=~s/$hash_text/$link/;1345}1346return$line;1347}13481349# format marker of refs pointing to given object13501351# the destination action is chosen based on object type and current context:1352# - for annotated tags, we choose the tag view unless it's the current view1353# already, in which case we go to shortlog view1354# - for other refs, we keep the current view if we're in history, shortlog or1355# log view, and select shortlog otherwise1356sub format_ref_marker {1357my($refs,$id) =@_;1358my$markers='';13591360if(defined$refs->{$id}) {1361foreachmy$ref(@{$refs->{$id}}) {1362# this code exploits the fact that non-lightweight tags are the1363# only indirect objects, and that they are the only objects for which1364# we want to use tag instead of shortlog as action1365my($type,$name) =qw();1366my$indirect= ($ref=~s/\^\{\}$//);1367# e.g. tags/v2.6.11 or heads/next1368if($ref=~m!^(.*?)s?/(.*)$!) {1369$type=$1;1370$name=$2;1371}else{1372$type="ref";1373$name=$ref;1374}13751376my$class=$type;1377$class.=" indirect"if$indirect;13781379my$dest_action="shortlog";13801381if($indirect) {1382$dest_action="tag"unless$actioneq"tag";1383}elsif($action=~/^(history|(short)?log)$/) {1384$dest_action=$action;1385}13861387my$dest="";1388$dest.="refs/"unless$ref=~ m!^refs/!;1389$dest.=$ref;13901391my$link=$cgi->a({1392-href => href(1393 action=>$dest_action,1394 hash=>$dest1395)},$name);13961397$markers.=" <span class=\"$class\"title=\"$ref\">".1398$link."</span>";1399}1400}14011402if($markers) {1403return' <span class="refs">'.$markers.'</span>';1404}else{1405return"";1406}1407}14081409# format, perhaps shortened and with markers, title line1410sub format_subject_html {1411my($long,$short,$href,$extra) =@_;1412$extra=''unlessdefined($extra);14131414if(length($short) <length($long)) {1415return$cgi->a({-href =>$href, -class=>"list subject",1416-title => to_utf8($long)},1417 esc_html($short) .$extra);1418}else{1419return$cgi->a({-href =>$href, -class=>"list subject"},1420 esc_html($long) .$extra);1421}1422}14231424# format git diff header line, i.e. "diff --(git|combined|cc) ..."1425sub format_git_diff_header_line {1426my$line=shift;1427my$diffinfo=shift;1428my($from,$to) =@_;14291430if($diffinfo->{'nparents'}) {1431# combined diff1432$line=~s!^(diff (.*?) )"?.*$!$1!;1433if($to->{'href'}) {1434$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1435 esc_path($to->{'file'}));1436}else{# file was deleted (no href)1437$line.= esc_path($to->{'file'});1438}1439}else{1440# "ordinary" diff1441$line=~s!^(diff (.*?) )"?a/.*$!$1!;1442if($from->{'href'}) {1443$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1444'a/'. esc_path($from->{'file'}));1445}else{# file was added (no href)1446$line.='a/'. esc_path($from->{'file'});1447}1448$line.=' ';1449if($to->{'href'}) {1450$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1451'b/'. esc_path($to->{'file'}));1452}else{# file was deleted1453$line.='b/'. esc_path($to->{'file'});1454}1455}14561457return"<div class=\"diff header\">$line</div>\n";1458}14591460# format extended diff header line, before patch itself1461sub format_extended_diff_header_line {1462my$line=shift;1463my$diffinfo=shift;1464my($from,$to) =@_;14651466# match <path>1467if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1468$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1469 esc_path($from->{'file'}));1470}1471if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1472$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1473 esc_path($to->{'file'}));1474}1475# match single <mode>1476if($line=~m/\s(\d{6})$/) {1477$line.='<span class="info"> ('.1478 file_type_long($1) .1479')</span>';1480}1481# match <hash>1482if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1483# can match only for combined diff1484$line='index ';1485for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1486if($from->{'href'}[$i]) {1487$line.=$cgi->a({-href=>$from->{'href'}[$i],1488-class=>"hash"},1489substr($diffinfo->{'from_id'}[$i],0,7));1490}else{1491$line.='0' x 7;1492}1493# separator1494$line.=','if($i<$diffinfo->{'nparents'} -1);1495}1496$line.='..';1497if($to->{'href'}) {1498$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1499substr($diffinfo->{'to_id'},0,7));1500}else{1501$line.='0' x 7;1502}15031504}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1505# can match only for ordinary diff1506my($from_link,$to_link);1507if($from->{'href'}) {1508$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1509substr($diffinfo->{'from_id'},0,7));1510}else{1511$from_link='0' x 7;1512}1513if($to->{'href'}) {1514$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1515substr($diffinfo->{'to_id'},0,7));1516}else{1517$to_link='0' x 7;1518}1519my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1520$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1521}15221523return$line."<br/>\n";1524}15251526# format from-file/to-file diff header1527sub format_diff_from_to_header {1528my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1529my$line;1530my$result='';15311532$line=$from_line;1533#assert($line =~ m/^---/) if DEBUG;1534# no extra formatting for "^--- /dev/null"1535if(!$diffinfo->{'nparents'}) {1536# ordinary (single parent) diff1537if($line=~m!^--- "?a/!) {1538if($from->{'href'}) {1539$line='--- a/'.1540$cgi->a({-href=>$from->{'href'}, -class=>"path"},1541 esc_path($from->{'file'}));1542}else{1543$line='--- a/'.1544 esc_path($from->{'file'});1545}1546}1547$result.= qq!<div class="diff from_file">$line</div>\n!;15481549}else{1550# combined diff (merge commit)1551for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1552if($from->{'href'}[$i]) {1553$line='--- '.1554$cgi->a({-href=>href(action=>"blobdiff",1555 hash_parent=>$diffinfo->{'from_id'}[$i],1556 hash_parent_base=>$parents[$i],1557 file_parent=>$from->{'file'}[$i],1558 hash=>$diffinfo->{'to_id'},1559 hash_base=>$hash,1560 file_name=>$to->{'file'}),1561-class=>"path",1562-title=>"diff". ($i+1)},1563$i+1) .1564'/'.1565$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1566 esc_path($from->{'file'}[$i]));1567}else{1568$line='--- /dev/null';1569}1570$result.= qq!<div class="diff from_file">$line</div>\n!;1571}1572}15731574$line=$to_line;1575#assert($line =~ m/^\+\+\+/) if DEBUG;1576# no extra formatting for "^+++ /dev/null"1577if($line=~m!^\+\+\+ "?b/!) {1578if($to->{'href'}) {1579$line='+++ b/'.1580$cgi->a({-href=>$to->{'href'}, -class=>"path"},1581 esc_path($to->{'file'}));1582}else{1583$line='+++ b/'.1584 esc_path($to->{'file'});1585}1586}1587$result.= qq!<div class="diff to_file">$line</div>\n!;15881589return$result;1590}15911592# create note for patch simplified by combined diff1593sub format_diff_cc_simplified {1594my($diffinfo,@parents) =@_;1595my$result='';15961597$result.="<div class=\"diff header\">".1598"diff --cc ";1599if(!is_deleted($diffinfo)) {1600$result.=$cgi->a({-href => href(action=>"blob",1601 hash_base=>$hash,1602 hash=>$diffinfo->{'to_id'},1603 file_name=>$diffinfo->{'to_file'}),1604-class=>"path"},1605 esc_path($diffinfo->{'to_file'}));1606}else{1607$result.= esc_path($diffinfo->{'to_file'});1608}1609$result.="</div>\n".# class="diff header"1610"<div class=\"diff nodifferences\">".1611"Simple merge".1612"</div>\n";# class="diff nodifferences"16131614return$result;1615}16161617# format patch (diff) line (not to be used for diff headers)1618sub format_diff_line {1619my$line=shift;1620my($from,$to) =@_;1621my$diff_class="";16221623chomp$line;16241625if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1626# combined diff1627my$prefix=substr($line,0,scalar@{$from->{'href'}});1628if($line=~m/^\@{3}/) {1629$diff_class=" chunk_header";1630}elsif($line=~m/^\\/) {1631$diff_class=" incomplete";1632}elsif($prefix=~tr/+/+/) {1633$diff_class=" add";1634}elsif($prefix=~tr/-/-/) {1635$diff_class=" rem";1636}1637}else{1638# assume ordinary diff1639my$char=substr($line,0,1);1640if($chareq'+') {1641$diff_class=" add";1642}elsif($chareq'-') {1643$diff_class=" rem";1644}elsif($chareq'@') {1645$diff_class=" chunk_header";1646}elsif($chareq"\\") {1647$diff_class=" incomplete";1648}1649}1650$line= untabify($line);1651if($from&&$to&&$line=~m/^\@{2} /) {1652my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1653$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;16541655$from_lines=0unlessdefined$from_lines;1656$to_lines=0unlessdefined$to_lines;16571658if($from->{'href'}) {1659$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1660-class=>"list"},$from_text);1661}1662if($to->{'href'}) {1663$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1664-class=>"list"},$to_text);1665}1666$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1667"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1668return"<div class=\"diff$diff_class\">$line</div>\n";1669}elsif($from&&$to&&$line=~m/^\@{3}/) {1670my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1671my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);16721673@from_text=split(' ',$ranges);1674for(my$i=0;$i<@from_text; ++$i) {1675($from_start[$i],$from_nlines[$i]) =1676(split(',',substr($from_text[$i],1)),0);1677}16781679$to_text=pop@from_text;1680$to_start=pop@from_start;1681$to_nlines=pop@from_nlines;16821683$line="<span class=\"chunk_info\">$prefix";1684for(my$i=0;$i<@from_text; ++$i) {1685if($from->{'href'}[$i]) {1686$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1687-class=>"list"},$from_text[$i]);1688}else{1689$line.=$from_text[$i];1690}1691$line.=" ";1692}1693if($to->{'href'}) {1694$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1695-class=>"list"},$to_text);1696}else{1697$line.=$to_text;1698}1699$line.="$prefix</span>".1700"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1701return"<div class=\"diff$diff_class\">$line</div>\n";1702}1703return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1704}17051706# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1707# linked. Pass the hash of the tree/commit to snapshot.1708sub format_snapshot_links {1709my($hash) =@_;1710my$num_fmts=@snapshot_fmts;1711if($num_fmts>1) {1712# A parenthesized list of links bearing format names.1713# e.g. "snapshot (_tar.gz_ _zip_)"1714return"snapshot (".join(' ',map1715$cgi->a({1716-href => href(1717 action=>"snapshot",1718 hash=>$hash,1719 snapshot_format=>$_1720)1721},$known_snapshot_formats{$_}{'display'})1722,@snapshot_fmts) .")";1723}elsif($num_fmts==1) {1724# A single "snapshot" link whose tooltip bears the format name.1725# i.e. "_snapshot_"1726my($fmt) =@snapshot_fmts;1727return1728$cgi->a({1729-href => href(1730 action=>"snapshot",1731 hash=>$hash,1732 snapshot_format=>$fmt1733),1734-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"1735},"snapshot");1736}else{# $num_fmts == 01737returnundef;1738}1739}17401741## ......................................................................1742## functions returning values to be passed, perhaps after some1743## transformation, to other functions; e.g. returning arguments to href()17441745# returns hash to be passed to href to generate gitweb URL1746# in -title key it returns description of link1747sub get_feed_info {1748my$format=shift||'Atom';1749my%res= (action =>lc($format));17501751# feed links are possible only for project views1752return unless(defined$project);1753# some views should link to OPML, or to generic project feed,1754# or don't have specific feed yet (so they should use generic)1755return if($action=~/^(?:tags|heads|forks|tag|search)$/x);17561757my$branch;1758# branches refs uses 'refs/heads/' prefix (fullname) to differentiate1759# from tag links; this also makes possible to detect branch links1760if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||1761(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {1762$branch=$1;1763}1764# find log type for feed description (title)1765my$type='log';1766if(defined$file_name) {1767$type="history of$file_name";1768$type.="/"if($actioneq'tree');1769$type.=" on '$branch'"if(defined$branch);1770}else{1771$type="log of$branch"if(defined$branch);1772}17731774$res{-title} =$type;1775$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);1776$res{'file_name'} =$file_name;17771778return%res;1779}17801781## ----------------------------------------------------------------------1782## git utility subroutines, invoking git commands17831784# returns path to the core git executable and the --git-dir parameter as list1785sub git_cmd {1786return$GIT,'--git-dir='.$git_dir;1787}17881789# quote the given arguments for passing them to the shell1790# quote_command("command", "arg 1", "arg with ' and ! characters")1791# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"1792# Try to avoid using this function wherever possible.1793sub quote_command {1794returnjoin(' ',1795map( {my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_));1796}17971798# get HEAD ref of given project as hash1799sub git_get_head_hash {1800my$project=shift;1801my$o_git_dir=$git_dir;1802my$retval=undef;1803$git_dir="$projectroot/$project";1804if(open my$fd,"-|", git_cmd(),"rev-parse","--verify","HEAD") {1805my$head= <$fd>;1806close$fd;1807if(defined$head&&$head=~/^([0-9a-fA-F]{40})$/) {1808$retval=$1;1809}1810}1811if(defined$o_git_dir) {1812$git_dir=$o_git_dir;1813}1814return$retval;1815}18161817# get type of given object1818sub git_get_type {1819my$hash=shift;18201821open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;1822my$type= <$fd>;1823close$fdorreturn;1824chomp$type;1825return$type;1826}18271828# repository configuration1829our$config_file='';1830our%config;18311832# store multiple values for single key as anonymous array reference1833# single values stored directly in the hash, not as [ <value> ]1834sub hash_set_multi {1835my($hash,$key,$value) =@_;18361837if(!exists$hash->{$key}) {1838$hash->{$key} =$value;1839}elsif(!ref$hash->{$key}) {1840$hash->{$key} = [$hash->{$key},$value];1841}else{1842push@{$hash->{$key}},$value;1843}1844}18451846# return hash of git project configuration1847# optionally limited to some section, e.g. 'gitweb'1848sub git_parse_project_config {1849my$section_regexp=shift;1850my%config;18511852local$/="\0";18531854open my$fh,"-|", git_cmd(),"config",'-z','-l',1855orreturn;18561857while(my$keyval= <$fh>) {1858chomp$keyval;1859my($key,$value) =split(/\n/,$keyval,2);18601861 hash_set_multi(\%config,$key,$value)1862if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);1863}1864close$fh;18651866return%config;1867}18681869# convert config value to boolean, 'true' or 'false'1870# no value, number > 0, 'true' and 'yes' values are true1871# rest of values are treated as false (never as error)1872sub config_to_bool {1873my$val=shift;18741875# strip leading and trailing whitespace1876$val=~s/^\s+//;1877$val=~s/\s+$//;18781879return(!defined$val||# section.key1880($val=~/^\d+$/&&$val) ||# section.key = 11881($val=~/^(?:true|yes)$/i));# section.key = true1882}18831884# convert config value to simple decimal number1885# an optional value suffix of 'k', 'm', or 'g' will cause the value1886# to be multiplied by 1024, 1048576, or 10737418241887sub config_to_int {1888my$val=shift;18891890# strip leading and trailing whitespace1891$val=~s/^\s+//;1892$val=~s/\s+$//;18931894if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {1895$unit=lc($unit);1896# unknown unit is treated as 11897return$num* ($uniteq'g'?1073741824:1898$uniteq'm'?1048576:1899$uniteq'k'?1024:1);1900}1901return$val;1902}19031904# convert config value to array reference, if needed1905sub config_to_multi {1906my$val=shift;19071908returnref($val) ?$val: (defined($val) ? [$val] : []);1909}19101911sub git_get_project_config {1912my($key,$type) =@_;19131914# key sanity check1915return unless($key);1916$key=~s/^gitweb\.//;1917return if($key=~m/\W/);19181919# type sanity check1920if(defined$type) {1921$type=~s/^--//;1922$type=undef1923unless($typeeq'bool'||$typeeq'int');1924}19251926# get config1927if(!defined$config_file||1928$config_filene"$git_dir/config") {1929%config= git_parse_project_config('gitweb');1930$config_file="$git_dir/config";1931}19321933# ensure given type1934if(!defined$type) {1935return$config{"gitweb.$key"};1936}elsif($typeeq'bool') {1937# backward compatibility: 'git config --bool' returns true/false1938return config_to_bool($config{"gitweb.$key"}) ?'true':'false';1939}elsif($typeeq'int') {1940return config_to_int($config{"gitweb.$key"});1941}1942return$config{"gitweb.$key"};1943}19441945# get hash of given path at given ref1946sub git_get_hash_by_path {1947my$base=shift;1948my$path=shift||returnundef;1949my$type=shift;19501951$path=~ s,/+$,,;19521953open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path1954or die_error(500,"Open git-ls-tree failed");1955my$line= <$fd>;1956close$fdorreturnundef;19571958if(!defined$line) {1959# there is no tree or hash given by $path at $base1960returnundef;1961}19621963#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'1964$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;1965if(defined$type&&$typene$2) {1966# type doesn't match1967returnundef;1968}1969return$3;1970}19711972# get path of entry with given hash at given tree-ish (ref)1973# used to get 'from' filename for combined diff (merge commit) for renames1974sub git_get_path_by_hash {1975my$base=shift||return;1976my$hash=shift||return;19771978local$/="\0";19791980open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base1981orreturnundef;1982while(my$line= <$fd>) {1983chomp$line;19841985#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'1986#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'1987if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {1988close$fd;1989return$1;1990}1991}1992close$fd;1993returnundef;1994}19951996## ......................................................................1997## git utility functions, directly accessing git repository19981999sub git_get_project_description {2000my$path=shift;20012002$git_dir="$projectroot/$path";2003open my$fd,"$git_dir/description"2004orreturn git_get_project_config('description');2005my$descr= <$fd>;2006close$fd;2007if(defined$descr) {2008chomp$descr;2009}2010return$descr;2011}20122013sub git_get_project_ctags {2014my$path=shift;2015my$ctags= {};20162017$git_dir="$projectroot/$path";2018foreach(<$git_dir/ctags/*>) {2019open CT,$_ornext;2020my$val= <CT>;2021chomp$val;2022close CT;2023my$ctag=$_;$ctag=~ s#.*/##;2024$ctags->{$ctag} =$val;2025}2026$ctags;2027}20282029sub git_populate_project_tagcloud {2030my$ctags=shift;20312032# First, merge different-cased tags; tags vote on casing2033my%ctags_lc;2034foreach(keys%$ctags) {2035$ctags_lc{lc$_}->{count} +=$ctags->{$_};2036if(not$ctags_lc{lc$_}->{topcount}2037or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2038$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2039$ctags_lc{lc$_}->{topname} =$_;2040}2041}20422043my$cloud;2044if(eval{require HTML::TagCloud;1; }) {2045$cloud= HTML::TagCloud->new;2046foreach(sort keys%ctags_lc) {2047# Pad the title with spaces so that the cloud looks2048# less crammed.2049my$title=$ctags_lc{$_}->{topname};2050$title=~s/ / /g;2051$title=~s/^/ /g;2052$title=~s/$/ /g;2053$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2054}2055}else{2056$cloud= \%ctags_lc;2057}2058$cloud;2059}20602061sub git_show_project_tagcloud {2062my($cloud,$count) =@_;2063print STDERR ref($cloud)."..\n";2064if(ref$cloudeq'HTML::TagCloud') {2065return$cloud->html_and_css($count);2066}else{2067my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2068return'<p align="center">'.join(', ',map{2069"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"2070}splice(@tags,0,$count)) .'</p>';2071}2072}20732074sub git_get_project_url_list {2075my$path=shift;20762077$git_dir="$projectroot/$path";2078open my$fd,"$git_dir/cloneurl"2079orreturnwantarray?2080@{ config_to_multi(git_get_project_config('url')) } :2081 config_to_multi(git_get_project_config('url'));2082my@git_project_url_list=map{chomp;$_} <$fd>;2083close$fd;20842085returnwantarray?@git_project_url_list: \@git_project_url_list;2086}20872088sub git_get_projects_list {2089my($filter) =@_;2090my@list;20912092$filter||='';2093$filter=~s/\.git$//;20942095my($check_forks) = gitweb_check_feature('forks');20962097if(-d $projects_list) {2098# search in directory2099my$dir=$projects_list. ($filter?"/$filter":'');2100# remove the trailing "/"2101$dir=~s!/+$!!;2102my$pfxlen=length("$dir");2103my$pfxdepth= ($dir=~tr!/!!);21042105 File::Find::find({2106 follow_fast =>1,# follow symbolic links2107 follow_skip =>2,# ignore duplicates2108 dangling_symlinks =>0,# ignore dangling symlinks, silently2109 wanted =>sub{2110# skip project-list toplevel, if we get it.2111return if(m!^[/.]$!);2112# only directories can be git repositories2113return unless(-d $_);2114# don't traverse too deep (Find is super slow on os x)2115if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2116$File::Find::prune =1;2117return;2118}21192120my$subdir=substr($File::Find::name,$pfxlen+1);2121# we check related file in $projectroot2122if(check_export_ok("$projectroot/$filter/$subdir")) {2123push@list, { path => ($filter?"$filter/":'') .$subdir};2124$File::Find::prune =1;2125}2126},2127},"$dir");21282129}elsif(-f $projects_list) {2130# read from file(url-encoded):2131# 'git%2Fgit.git Linus+Torvalds'2132# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2133# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2134my%paths;2135open my($fd),$projects_listorreturn;2136 PROJECT:2137while(my$line= <$fd>) {2138chomp$line;2139my($path,$owner) =split' ',$line;2140$path= unescape($path);2141$owner= unescape($owner);2142if(!defined$path) {2143next;2144}2145if($filterne'') {2146# looking for forks;2147my$pfx=substr($path,0,length($filter));2148if($pfxne$filter) {2149next PROJECT;2150}2151my$sfx=substr($path,length($filter));2152if($sfx!~/^\/.*\.git$/) {2153next PROJECT;2154}2155}elsif($check_forks) {2156 PATH:2157foreachmy$filter(keys%paths) {2158# looking for forks;2159my$pfx=substr($path,0,length($filter));2160if($pfxne$filter) {2161next PATH;2162}2163my$sfx=substr($path,length($filter));2164if($sfx!~/^\/.*\.git$/) {2165next PATH;2166}2167# is a fork, don't include it in2168# the list2169next PROJECT;2170}2171}2172if(check_export_ok("$projectroot/$path")) {2173my$pr= {2174 path =>$path,2175 owner => to_utf8($owner),2176};2177push@list,$pr;2178(my$forks_path=$path) =~s/\.git$//;2179$paths{$forks_path}++;2180}2181}2182close$fd;2183}2184return@list;2185}21862187our$gitweb_project_owner=undef;2188sub git_get_project_list_from_file {21892190return if(defined$gitweb_project_owner);21912192$gitweb_project_owner= {};2193# read from file (url-encoded):2194# 'git%2Fgit.git Linus+Torvalds'2195# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2196# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2197if(-f $projects_list) {2198open(my$fd,$projects_list);2199while(my$line= <$fd>) {2200chomp$line;2201my($pr,$ow) =split' ',$line;2202$pr= unescape($pr);2203$ow= unescape($ow);2204$gitweb_project_owner->{$pr} = to_utf8($ow);2205}2206close$fd;2207}2208}22092210sub git_get_project_owner {2211my$project=shift;2212my$owner;22132214returnundefunless$project;2215$git_dir="$projectroot/$project";22162217if(!defined$gitweb_project_owner) {2218 git_get_project_list_from_file();2219}22202221if(exists$gitweb_project_owner->{$project}) {2222$owner=$gitweb_project_owner->{$project};2223}2224if(!defined$owner){2225$owner= git_get_project_config('owner');2226}2227if(!defined$owner) {2228$owner= get_file_owner("$git_dir");2229}22302231return$owner;2232}22332234sub git_get_last_activity {2235my($path) =@_;2236my$fd;22372238$git_dir="$projectroot/$path";2239open($fd,"-|", git_cmd(),'for-each-ref',2240'--format=%(committer)',2241'--sort=-committerdate',2242'--count=1',2243'refs/heads')orreturn;2244my$most_recent= <$fd>;2245close$fdorreturn;2246if(defined$most_recent&&2247$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2248my$timestamp=$1;2249my$age=time-$timestamp;2250return($age, age_string($age));2251}2252return(undef,undef);2253}22542255sub git_get_references {2256my$type=shift||"";2257my%refs;2258# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112259# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2260open my$fd,"-|", git_cmd(),"show-ref","--dereference",2261($type? ("--","refs/$type") : ())# use -- <pattern> if $type2262orreturn;22632264while(my$line= <$fd>) {2265chomp$line;2266if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2267if(defined$refs{$1}) {2268push@{$refs{$1}},$2;2269}else{2270$refs{$1} = [$2];2271}2272}2273}2274close$fdorreturn;2275return \%refs;2276}22772278sub git_get_rev_name_tags {2279my$hash=shift||returnundef;22802281open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2282orreturn;2283my$name_rev= <$fd>;2284close$fd;22852286if($name_rev=~ m|^$hash tags/(.*)$|) {2287return$1;2288}else{2289# catches also '$hash undefined' output2290returnundef;2291}2292}22932294## ----------------------------------------------------------------------2295## parse to hash functions22962297sub parse_date {2298my$epoch=shift;2299my$tz=shift||"-0000";23002301my%date;2302my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2303my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2304my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2305$date{'hour'} =$hour;2306$date{'minute'} =$min;2307$date{'mday'} =$mday;2308$date{'day'} =$days[$wday];2309$date{'month'} =$months[$mon];2310$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2311$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2312$date{'mday-time'} =sprintf"%d%s%02d:%02d",2313$mday,$months[$mon],$hour,$min;2314$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",23151900+$year,1+$mon,$mday,$hour,$min,$sec;23162317$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2318my$local=$epoch+ ((int$1+ ($2/60)) *3600);2319($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2320$date{'hour_local'} =$hour;2321$date{'minute_local'} =$min;2322$date{'tz_local'} =$tz;2323$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",23241900+$year,$mon+1,$mday,2325$hour,$min,$sec,$tz);2326return%date;2327}23282329sub parse_tag {2330my$tag_id=shift;2331my%tag;2332my@comment;23332334open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2335$tag{'id'} =$tag_id;2336while(my$line= <$fd>) {2337chomp$line;2338if($line=~m/^object ([0-9a-fA-F]{40})$/) {2339$tag{'object'} =$1;2340}elsif($line=~m/^type (.+)$/) {2341$tag{'type'} =$1;2342}elsif($line=~m/^tag (.+)$/) {2343$tag{'name'} =$1;2344}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2345$tag{'author'} =$1;2346$tag{'epoch'} =$2;2347$tag{'tz'} =$3;2348}elsif($line=~m/--BEGIN/) {2349push@comment,$line;2350last;2351}elsif($lineeq"") {2352last;2353}2354}2355push@comment, <$fd>;2356$tag{'comment'} = \@comment;2357close$fdorreturn;2358if(!defined$tag{'name'}) {2359return2360};2361return%tag2362}23632364sub parse_commit_text {2365my($commit_text,$withparents) =@_;2366my@commit_lines=split'\n',$commit_text;2367my%co;23682369pop@commit_lines;# Remove '\0'23702371if(!@commit_lines) {2372return;2373}23742375my$header=shift@commit_lines;2376if($header!~m/^[0-9a-fA-F]{40}/) {2377return;2378}2379($co{'id'},my@parents) =split' ',$header;2380while(my$line=shift@commit_lines) {2381last if$lineeq"\n";2382if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2383$co{'tree'} =$1;2384}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2385push@parents,$1;2386}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2387$co{'author'} =$1;2388$co{'author_epoch'} =$2;2389$co{'author_tz'} =$3;2390if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2391$co{'author_name'} =$1;2392$co{'author_email'} =$2;2393}else{2394$co{'author_name'} =$co{'author'};2395}2396}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2397$co{'committer'} =$1;2398$co{'committer_epoch'} =$2;2399$co{'committer_tz'} =$3;2400$co{'committer_name'} =$co{'committer'};2401if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2402$co{'committer_name'} =$1;2403$co{'committer_email'} =$2;2404}else{2405$co{'committer_name'} =$co{'committer'};2406}2407}2408}2409if(!defined$co{'tree'}) {2410return;2411};2412$co{'parents'} = \@parents;2413$co{'parent'} =$parents[0];24142415foreachmy$title(@commit_lines) {2416$title=~s/^ //;2417if($titlene"") {2418$co{'title'} = chop_str($title,80,5);2419# remove leading stuff of merges to make the interesting part visible2420if(length($title) >50) {2421$title=~s/^Automatic //;2422$title=~s/^merge (of|with) /Merge ... /i;2423if(length($title) >50) {2424$title=~s/(http|rsync):\/\///;2425}2426if(length($title) >50) {2427$title=~s/(master|www|rsync)\.//;2428}2429if(length($title) >50) {2430$title=~s/kernel.org:?//;2431}2432if(length($title) >50) {2433$title=~s/\/pub\/scm//;2434}2435}2436$co{'title_short'} = chop_str($title,50,5);2437last;2438}2439}2440if(!defined$co{'title'} ||$co{'title'}eq"") {2441$co{'title'} =$co{'title_short'} ='(no commit message)';2442}2443# remove added spaces2444foreachmy$line(@commit_lines) {2445$line=~s/^ //;2446}2447$co{'comment'} = \@commit_lines;24482449my$age=time-$co{'committer_epoch'};2450$co{'age'} =$age;2451$co{'age_string'} = age_string($age);2452my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2453if($age>60*60*24*7*2) {2454$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2455$co{'age_string_age'} =$co{'age_string'};2456}else{2457$co{'age_string_date'} =$co{'age_string'};2458$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2459}2460return%co;2461}24622463sub parse_commit {2464my($commit_id) =@_;2465my%co;24662467local$/="\0";24682469open my$fd,"-|", git_cmd(),"rev-list",2470"--parents",2471"--header",2472"--max-count=1",2473$commit_id,2474"--",2475or die_error(500,"Open git-rev-list failed");2476%co= parse_commit_text(<$fd>,1);2477close$fd;24782479return%co;2480}24812482sub parse_commits {2483my($commit_id,$maxcount,$skip,$filename,@args) =@_;2484my@cos;24852486$maxcount||=1;2487$skip||=0;24882489local$/="\0";24902491open my$fd,"-|", git_cmd(),"rev-list",2492"--header",2493@args,2494("--max-count=".$maxcount),2495("--skip=".$skip),2496@extra_options,2497$commit_id,2498"--",2499($filename? ($filename) : ())2500or die_error(500,"Open git-rev-list failed");2501while(my$line= <$fd>) {2502my%co= parse_commit_text($line);2503push@cos, \%co;2504}2505close$fd;25062507returnwantarray?@cos: \@cos;2508}25092510# parse line of git-diff-tree "raw" output2511sub parse_difftree_raw_line {2512my$line=shift;2513my%res;25142515# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2516# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2517if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2518$res{'from_mode'} =$1;2519$res{'to_mode'} =$2;2520$res{'from_id'} =$3;2521$res{'to_id'} =$4;2522$res{'status'} =$5;2523$res{'similarity'} =$6;2524if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2525($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2526}else{2527$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2528}2529}2530# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2531# combined diff (for merge commit)2532elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2533$res{'nparents'} =length($1);2534$res{'from_mode'} = [split(' ',$2) ];2535$res{'to_mode'} =pop@{$res{'from_mode'}};2536$res{'from_id'} = [split(' ',$3) ];2537$res{'to_id'} =pop@{$res{'from_id'}};2538$res{'status'} = [split('',$4) ];2539$res{'to_file'} = unquote($5);2540}2541# 'c512b523472485aef4fff9e57b229d9d243c967f'2542elsif($line=~m/^([0-9a-fA-F]{40})$/) {2543$res{'commit'} =$1;2544}25452546returnwantarray?%res: \%res;2547}25482549# wrapper: return parsed line of git-diff-tree "raw" output2550# (the argument might be raw line, or parsed info)2551sub parsed_difftree_line {2552my$line_or_ref=shift;25532554if(ref($line_or_ref)eq"HASH") {2555# pre-parsed (or generated by hand)2556return$line_or_ref;2557}else{2558return parse_difftree_raw_line($line_or_ref);2559}2560}25612562# parse line of git-ls-tree output2563sub parse_ls_tree_line ($;%) {2564my$line=shift;2565my%opts=@_;2566my%res;25672568#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2569$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;25702571$res{'mode'} =$1;2572$res{'type'} =$2;2573$res{'hash'} =$3;2574if($opts{'-z'}) {2575$res{'name'} =$4;2576}else{2577$res{'name'} = unquote($4);2578}25792580returnwantarray?%res: \%res;2581}25822583# generates _two_ hashes, references to which are passed as 2 and 3 argument2584sub parse_from_to_diffinfo {2585my($diffinfo,$from,$to,@parents) =@_;25862587if($diffinfo->{'nparents'}) {2588# combined diff2589$from->{'file'} = [];2590$from->{'href'} = [];2591 fill_from_file_info($diffinfo,@parents)2592unlessexists$diffinfo->{'from_file'};2593for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2594$from->{'file'}[$i] =2595defined$diffinfo->{'from_file'}[$i] ?2596$diffinfo->{'from_file'}[$i] :2597$diffinfo->{'to_file'};2598if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2599$from->{'href'}[$i] = href(action=>"blob",2600 hash_base=>$parents[$i],2601 hash=>$diffinfo->{'from_id'}[$i],2602 file_name=>$from->{'file'}[$i]);2603}else{2604$from->{'href'}[$i] =undef;2605}2606}2607}else{2608# ordinary (not combined) diff2609$from->{'file'} =$diffinfo->{'from_file'};2610if($diffinfo->{'status'}ne"A") {# not new (added) file2611$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2612 hash=>$diffinfo->{'from_id'},2613 file_name=>$from->{'file'});2614}else{2615delete$from->{'href'};2616}2617}26182619$to->{'file'} =$diffinfo->{'to_file'};2620if(!is_deleted($diffinfo)) {# file exists in result2621$to->{'href'} = href(action=>"blob", hash_base=>$hash,2622 hash=>$diffinfo->{'to_id'},2623 file_name=>$to->{'file'});2624}else{2625delete$to->{'href'};2626}2627}26282629## ......................................................................2630## parse to array of hashes functions26312632sub git_get_heads_list {2633my$limit=shift;2634my@headslist;26352636open my$fd,'-|', git_cmd(),'for-each-ref',2637($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2638'--format=%(objectname) %(refname) %(subject)%00%(committer)',2639'refs/heads'2640orreturn;2641while(my$line= <$fd>) {2642my%ref_item;26432644chomp$line;2645my($refinfo,$committerinfo) =split(/\0/,$line);2646my($hash,$name,$title) =split(' ',$refinfo,3);2647my($committer,$epoch,$tz) =2648($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2649$ref_item{'fullname'} =$name;2650$name=~s!^refs/heads/!!;26512652$ref_item{'name'} =$name;2653$ref_item{'id'} =$hash;2654$ref_item{'title'} =$title||'(no commit message)';2655$ref_item{'epoch'} =$epoch;2656if($epoch) {2657$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2658}else{2659$ref_item{'age'} ="unknown";2660}26612662push@headslist, \%ref_item;2663}2664close$fd;26652666returnwantarray?@headslist: \@headslist;2667}26682669sub git_get_tags_list {2670my$limit=shift;2671my@tagslist;26722673open my$fd,'-|', git_cmd(),'for-each-ref',2674($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',2675'--format=%(objectname) %(objecttype) %(refname) '.2676'%(*objectname) %(*objecttype) %(subject)%00%(creator)',2677'refs/tags'2678orreturn;2679while(my$line= <$fd>) {2680my%ref_item;26812682chomp$line;2683my($refinfo,$creatorinfo) =split(/\0/,$line);2684my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);2685my($creator,$epoch,$tz) =2686($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);2687$ref_item{'fullname'} =$name;2688$name=~s!^refs/tags/!!;26892690$ref_item{'type'} =$type;2691$ref_item{'id'} =$id;2692$ref_item{'name'} =$name;2693if($typeeq"tag") {2694$ref_item{'subject'} =$title;2695$ref_item{'reftype'} =$reftype;2696$ref_item{'refid'} =$refid;2697}else{2698$ref_item{'reftype'} =$type;2699$ref_item{'refid'} =$id;2700}27012702if($typeeq"tag"||$typeeq"commit") {2703$ref_item{'epoch'} =$epoch;2704if($epoch) {2705$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2706}else{2707$ref_item{'age'} ="unknown";2708}2709}27102711push@tagslist, \%ref_item;2712}2713close$fd;27142715returnwantarray?@tagslist: \@tagslist;2716}27172718## ----------------------------------------------------------------------2719## filesystem-related functions27202721sub get_file_owner {2722my$path=shift;27232724my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);2725my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);2726if(!defined$gcos) {2727returnundef;2728}2729my$owner=$gcos;2730$owner=~s/[,;].*$//;2731return to_utf8($owner);2732}27332734## ......................................................................2735## mimetype related functions27362737sub mimetype_guess_file {2738my$filename=shift;2739my$mimemap=shift;2740-r $mimemaporreturnundef;27412742my%mimemap;2743open(MIME,$mimemap)orreturnundef;2744while(<MIME>) {2745next ifm/^#/;# skip comments2746my($mime,$exts) =split(/\t+/);2747if(defined$exts) {2748my@exts=split(/\s+/,$exts);2749foreachmy$ext(@exts) {2750$mimemap{$ext} =$mime;2751}2752}2753}2754close(MIME);27552756$filename=~/\.([^.]*)$/;2757return$mimemap{$1};2758}27592760sub mimetype_guess {2761my$filename=shift;2762my$mime;2763$filename=~/\./orreturnundef;27642765if($mimetypes_file) {2766my$file=$mimetypes_file;2767if($file!~m!^/!) {# if it is relative path2768# it is relative to project2769$file="$projectroot/$project/$file";2770}2771$mime= mimetype_guess_file($filename,$file);2772}2773$mime||= mimetype_guess_file($filename,'/etc/mime.types');2774return$mime;2775}27762777sub blob_mimetype {2778my$fd=shift;2779my$filename=shift;27802781if($filename) {2782my$mime= mimetype_guess($filename);2783$mimeandreturn$mime;2784}27852786# just in case2787return$default_blob_plain_mimetypeunless$fd;27882789if(-T $fd) {2790return'text/plain';2791}elsif(!$filename) {2792return'application/octet-stream';2793}elsif($filename=~m/\.png$/i) {2794return'image/png';2795}elsif($filename=~m/\.gif$/i) {2796return'image/gif';2797}elsif($filename=~m/\.jpe?g$/i) {2798return'image/jpeg';2799}else{2800return'application/octet-stream';2801}2802}28032804sub blob_contenttype {2805my($fd,$file_name,$type) =@_;28062807$type||= blob_mimetype($fd,$file_name);2808if($typeeq'text/plain'&&defined$default_text_plain_charset) {2809$type.="; charset=$default_text_plain_charset";2810}28112812return$type;2813}28142815## ======================================================================2816## functions printing HTML: header, footer, error page28172818sub git_header_html {2819my$status=shift||"200 OK";2820my$expires=shift;28212822my$title="$site_name";2823if(defined$project) {2824$title.=" - ". to_utf8($project);2825if(defined$action) {2826$title.="/$action";2827if(defined$file_name) {2828$title.=" - ". esc_path($file_name);2829if($actioneq"tree"&&$file_name!~ m|/$|) {2830$title.="/";2831}2832}2833}2834}2835my$content_type;2836# require explicit support from the UA if we are to send the page as2837# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.2838# we have to do this because MSIE sometimes globs '*/*', pretending to2839# support xhtml+xml but choking when it gets what it asked for.2840if(defined$cgi->http('HTTP_ACCEPT') &&2841$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&2842$cgi->Accept('application/xhtml+xml') !=0) {2843$content_type='application/xhtml+xml';2844}else{2845$content_type='text/html';2846}2847print$cgi->header(-type=>$content_type, -charset =>'utf-8',2848-status=>$status, -expires =>$expires);2849my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';2850print<<EOF;2851<?xml version="1.0" encoding="utf-8"?>2852<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">2853<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">2854<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->2855<!-- git core binaries version$git_version-->2856<head>2857<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>2858<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>2859<meta name="robots" content="index, nofollow"/>2860<title>$title</title>2861EOF2862# print out each stylesheet that exist2863if(defined$stylesheet) {2864#provides backwards capability for those people who define style sheet in a config file2865print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";2866}else{2867foreachmy$stylesheet(@stylesheets) {2868next unless$stylesheet;2869print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";2870}2871}2872if(defined$project) {2873my%href_params= get_feed_info();2874if(!exists$href_params{'-title'}) {2875$href_params{'-title'} ='log';2876}28772878foreachmy$formatqw(RSS Atom){2879my$type=lc($format);2880my%link_attr= (2881'-rel'=>'alternate',2882'-title'=>"$project-$href_params{'-title'} -$formatfeed",2883'-type'=>"application/$type+xml"2884);28852886$href_params{'action'} =$type;2887$link_attr{'-href'} = href(%href_params);2888print"<link ".2889"rel=\"$link_attr{'-rel'}\"".2890"title=\"$link_attr{'-title'}\"".2891"href=\"$link_attr{'-href'}\"".2892"type=\"$link_attr{'-type'}\"".2893"/>\n";28942895$href_params{'extra_options'} ='--no-merges';2896$link_attr{'-href'} = href(%href_params);2897$link_attr{'-title'} .=' (no merges)';2898print"<link ".2899"rel=\"$link_attr{'-rel'}\"".2900"title=\"$link_attr{'-title'}\"".2901"href=\"$link_attr{'-href'}\"".2902"type=\"$link_attr{'-type'}\"".2903"/>\n";2904}29052906}else{2907printf('<link rel="alternate" title="%sprojects list" '.2908'href="%s" type="text/plain; charset=utf-8" />'."\n",2909$site_name, href(project=>undef, action=>"project_index"));2910printf('<link rel="alternate" title="%sprojects feeds" '.2911'href="%s" type="text/x-opml" />'."\n",2912$site_name, href(project=>undef, action=>"opml"));2913}2914if(defined$favicon) {2915printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);2916}29172918print"</head>\n".2919"<body>\n";29202921if(-f $site_header) {2922open(my$fd,$site_header);2923print<$fd>;2924close$fd;2925}29262927print"<div class=\"page_header\">\n".2928$cgi->a({-href => esc_url($logo_url),2929-title =>$logo_label},2930qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));2931print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";2932if(defined$project) {2933print$cgi->a({-href => href(action=>"summary")}, esc_html($project));2934if(defined$action) {2935print" /$action";2936}2937print"\n";2938}2939print"</div>\n";29402941my($have_search) = gitweb_check_feature('search');2942if(defined$project&&$have_search) {2943if(!defined$searchtext) {2944$searchtext="";2945}2946my$search_hash;2947if(defined$hash_base) {2948$search_hash=$hash_base;2949}elsif(defined$hash) {2950$search_hash=$hash;2951}else{2952$search_hash="HEAD";2953}2954my$action=$my_uri;2955my($use_pathinfo) = gitweb_check_feature('pathinfo');2956if($use_pathinfo) {2957$action.="/".esc_url($project);2958}2959print$cgi->startform(-method=>"get", -action =>$action) .2960"<div class=\"search\">\n".2961(!$use_pathinfo&&2962$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .2963$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".2964$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".2965$cgi->popup_menu(-name =>'st', -default=>'commit',2966-values=> ['commit','grep','author','committer','pickaxe']) .2967$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .2968" search:\n",2969$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".2970"<span title=\"Extended regular expression\">".2971$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',2972-checked =>$search_use_regexp) .2973"</span>".2974"</div>".2975$cgi->end_form() ."\n";2976}2977}29782979sub git_footer_html {2980my$feed_class='rss_logo';29812982print"<div class=\"page_footer\">\n";2983if(defined$project) {2984my$descr= git_get_project_description($project);2985if(defined$descr) {2986print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";2987}29882989my%href_params= get_feed_info();2990if(!%href_params) {2991$feed_class.=' generic';2992}2993$href_params{'-title'} ||='log';29942995foreachmy$formatqw(RSS Atom){2996$href_params{'action'} =lc($format);2997print$cgi->a({-href => href(%href_params),2998-title =>"$href_params{'-title'}$formatfeed",2999-class=>$feed_class},$format)."\n";3000}30013002}else{3003print$cgi->a({-href => href(project=>undef, action=>"opml"),3004-class=>$feed_class},"OPML") ." ";3005print$cgi->a({-href => href(project=>undef, action=>"project_index"),3006-class=>$feed_class},"TXT") ."\n";3007}3008print"</div>\n";# class="page_footer"30093010if(-f $site_footer) {3011open(my$fd,$site_footer);3012print<$fd>;3013close$fd;3014}30153016print"</body>\n".3017"</html>";3018}30193020# die_error(<http_status_code>, <error_message>)3021# Example: die_error(404, 'Hash not found')3022# By convention, use the following status codes (as defined in RFC 2616):3023# 400: Invalid or missing CGI parameters, or3024# requested object exists but has wrong type.3025# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3026# this server or project.3027# 404: Requested object/revision/project doesn't exist.3028# 500: The server isn't configured properly, or3029# an internal error occurred (e.g. failed assertions caused by bugs), or3030# an unknown error occurred (e.g. the git binary died unexpectedly).3031sub die_error {3032my$status=shift||500;3033my$error=shift||"Internal server error";30343035my%http_responses= (400=>'400 Bad Request',3036403=>'403 Forbidden',3037404=>'404 Not Found',3038500=>'500 Internal Server Error');3039 git_header_html($http_responses{$status});3040print<<EOF;3041<div class="page_body">3042<br /><br />3043$status-$error3044<br />3045</div>3046EOF3047 git_footer_html();3048exit;3049}30503051## ----------------------------------------------------------------------3052## functions printing or outputting HTML: navigation30533054sub git_print_page_nav {3055my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3056$extra=''if!defined$extra;# pager or formats30573058my@navs=qw(summary shortlog log commit commitdiff tree);3059if($suppress) {3060@navs=grep{$_ne$suppress}@navs;3061}30623063my%arg=map{$_=> {action=>$_} }@navs;3064if(defined$head) {3065for(qw(commit commitdiff)) {3066$arg{$_}{'hash'} =$head;3067}3068if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3069for(qw(shortlog log)) {3070$arg{$_}{'hash'} =$head;3071}3072}3073}30743075$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3076$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;30773078my@actions= gitweb_check_feature('actions');3079while(@actions) {3080my($label,$link,$pos) = (shift(@actions),shift(@actions),shift(@actions));3081@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3082# munch munch3083$link=~ s#%n#$project#g;3084$link=~ s#%f#$git_dir#g;3085$treehead?$link=~ s#%h#$treehead#g : $link =~ s#%h##g;3086$treebase?$link=~ s#%b#$treebase#g : $link =~ s#%b##g;3087$arg{$label}{'_href'} =$link;3088}30893090print"<div class=\"page_nav\">\n".3091(join" | ",3092map{$_eq$current?3093$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3094}@navs);3095print"<br/>\n$extra<br/>\n".3096"</div>\n";3097}30983099sub format_paging_nav {3100my($action,$hash,$head,$page,$has_next_link) =@_;3101my$paging_nav;310231033104if($hashne$head||$page) {3105$paging_nav.=$cgi->a({-href => href(action=>$action)},"HEAD");3106}else{3107$paging_nav.="HEAD";3108}31093110if($page>0) {3111$paging_nav.=" ⋅ ".3112$cgi->a({-href => href(-replay=>1, page=>$page-1),3113-accesskey =>"p", -title =>"Alt-p"},"prev");3114}else{3115$paging_nav.=" ⋅ prev";3116}31173118if($has_next_link) {3119$paging_nav.=" ⋅ ".3120$cgi->a({-href => href(-replay=>1, page=>$page+1),3121-accesskey =>"n", -title =>"Alt-n"},"next");3122}else{3123$paging_nav.=" ⋅ next";3124}31253126return$paging_nav;3127}31283129## ......................................................................3130## functions printing or outputting HTML: div31313132sub git_print_header_div {3133my($action,$title,$hash,$hash_base) =@_;3134my%args= ();31353136$args{'action'} =$action;3137$args{'hash'} =$hashif$hash;3138$args{'hash_base'} =$hash_baseif$hash_base;31393140print"<div class=\"header\">\n".3141$cgi->a({-href => href(%args), -class=>"title"},3142$title?$title:$action) .3143"\n</div>\n";3144}31453146#sub git_print_authorship (\%) {3147sub git_print_authorship {3148my$co=shift;31493150my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3151print"<div class=\"author_date\">".3152 esc_html($co->{'author_name'}) .3153" [$ad{'rfc2822'}";3154if($ad{'hour_local'} <6) {3155printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3156$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});3157}else{3158printf(" (%02d:%02d%s)",3159$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});3160}3161print"]</div>\n";3162}31633164sub git_print_page_path {3165my$name=shift;3166my$type=shift;3167my$hb=shift;316831693170print"<div class=\"page_path\">";3171print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3172-title =>'tree root'}, to_utf8("[$project]"));3173print" / ";3174if(defined$name) {3175my@dirname=split'/',$name;3176my$basename=pop@dirname;3177my$fullname='';31783179foreachmy$dir(@dirname) {3180$fullname.= ($fullname?'/':'') .$dir;3181print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3182 hash_base=>$hb),3183-title =>$fullname}, esc_path($dir));3184print" / ";3185}3186if(defined$type&&$typeeq'blob') {3187print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3188 hash_base=>$hb),3189-title =>$name}, esc_path($basename));3190}elsif(defined$type&&$typeeq'tree') {3191print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3192 hash_base=>$hb),3193-title =>$name}, esc_path($basename));3194print" / ";3195}else{3196print esc_path($basename);3197}3198}3199print"<br/></div>\n";3200}32013202# sub git_print_log (\@;%) {3203sub git_print_log ($;%) {3204my$log=shift;3205my%opts=@_;32063207if($opts{'-remove_title'}) {3208# remove title, i.e. first line of log3209shift@$log;3210}3211# remove leading empty lines3212while(defined$log->[0] &&$log->[0]eq"") {3213shift@$log;3214}32153216# print log3217my$signoff=0;3218my$empty=0;3219foreachmy$line(@$log) {3220if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3221$signoff=1;3222$empty=0;3223if(!$opts{'-remove_signoff'}) {3224print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3225next;3226}else{3227# remove signoff lines3228next;3229}3230}else{3231$signoff=0;3232}32333234# print only one empty line3235# do not print empty line after signoff3236if($lineeq"") {3237next if($empty||$signoff);3238$empty=1;3239}else{3240$empty=0;3241}32423243print format_log_line_html($line) ."<br/>\n";3244}32453246if($opts{'-final_empty_line'}) {3247# end with single empty line3248print"<br/>\n"unless$empty;3249}3250}32513252# return link target (what link points to)3253sub git_get_link_target {3254my$hash=shift;3255my$link_target;32563257# read link3258open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3259orreturn;3260{3261local$/;3262$link_target= <$fd>;3263}3264close$fd3265orreturn;32663267return$link_target;3268}32693270# given link target, and the directory (basedir) the link is in,3271# return target of link relative to top directory (top tree);3272# return undef if it is not possible (including absolute links).3273sub normalize_link_target {3274my($link_target,$basedir,$hash_base) =@_;32753276# we can normalize symlink target only if $hash_base is provided3277return unless$hash_base;32783279# absolute symlinks (beginning with '/') cannot be normalized3280return if(substr($link_target,0,1)eq'/');32813282# normalize link target to path from top (root) tree (dir)3283my$path;3284if($basedir) {3285$path=$basedir.'/'.$link_target;3286}else{3287# we are in top (root) tree (dir)3288$path=$link_target;3289}32903291# remove //, /./, and /../3292my@path_parts;3293foreachmy$part(split('/',$path)) {3294# discard '.' and ''3295next if(!$part||$parteq'.');3296# handle '..'3297if($parteq'..') {3298if(@path_parts) {3299pop@path_parts;3300}else{3301# link leads outside repository (outside top dir)3302return;3303}3304}else{3305push@path_parts,$part;3306}3307}3308$path=join('/',@path_parts);33093310return$path;3311}33123313# print tree entry (row of git_tree), but without encompassing <tr> element3314sub git_print_tree_entry {3315my($t,$basedir,$hash_base,$have_blame) =@_;33163317my%base_key= ();3318$base_key{'hash_base'} =$hash_baseifdefined$hash_base;33193320# The format of a table row is: mode list link. Where mode is3321# the mode of the entry, list is the name of the entry, an href,3322# and link is the action links of the entry.33233324print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3325if($t->{'type'}eq"blob") {3326print"<td class=\"list\">".3327$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3328 file_name=>"$basedir$t->{'name'}",%base_key),3329-class=>"list"}, esc_path($t->{'name'}));3330if(S_ISLNK(oct$t->{'mode'})) {3331my$link_target= git_get_link_target($t->{'hash'});3332if($link_target) {3333my$norm_target= normalize_link_target($link_target,$basedir,$hash_base);3334if(defined$norm_target) {3335print" -> ".3336$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3337 file_name=>$norm_target),3338-title =>$norm_target}, esc_path($link_target));3339}else{3340print" -> ". esc_path($link_target);3341}3342}3343}3344print"</td>\n";3345print"<td class=\"link\">";3346print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3347 file_name=>"$basedir$t->{'name'}",%base_key)},3348"blob");3349if($have_blame) {3350print" | ".3351$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3352 file_name=>"$basedir$t->{'name'}",%base_key)},3353"blame");3354}3355if(defined$hash_base) {3356print" | ".3357$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3358 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3359"history");3360}3361print" | ".3362$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3363 file_name=>"$basedir$t->{'name'}")},3364"raw");3365print"</td>\n";33663367}elsif($t->{'type'}eq"tree") {3368print"<td class=\"list\">";3369print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3370 file_name=>"$basedir$t->{'name'}",%base_key)},3371 esc_path($t->{'name'}));3372print"</td>\n";3373print"<td class=\"link\">";3374print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3375 file_name=>"$basedir$t->{'name'}",%base_key)},3376"tree");3377if(defined$hash_base) {3378print" | ".3379$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3380 file_name=>"$basedir$t->{'name'}")},3381"history");3382}3383print"</td>\n";3384}else{3385# unknown object: we can only present history for it3386# (this includes 'commit' object, i.e. submodule support)3387print"<td class=\"list\">".3388 esc_path($t->{'name'}) .3389"</td>\n";3390print"<td class=\"link\">";3391if(defined$hash_base) {3392print$cgi->a({-href => href(action=>"history",3393 hash_base=>$hash_base,3394 file_name=>"$basedir$t->{'name'}")},3395"history");3396}3397print"</td>\n";3398}3399}34003401## ......................................................................3402## functions printing large fragments of HTML34033404# get pre-image filenames for merge (combined) diff3405sub fill_from_file_info {3406my($diff,@parents) =@_;34073408$diff->{'from_file'} = [ ];3409$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3410for(my$i=0;$i<$diff->{'nparents'};$i++) {3411if($diff->{'status'}[$i]eq'R'||3412$diff->{'status'}[$i]eq'C') {3413$diff->{'from_file'}[$i] =3414 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3415}3416}34173418return$diff;3419}34203421# is current raw difftree line of file deletion3422sub is_deleted {3423my$diffinfo=shift;34243425return$diffinfo->{'to_id'}eq('0' x 40);3426}34273428# does patch correspond to [previous] difftree raw line3429# $diffinfo - hashref of parsed raw diff format3430# $patchinfo - hashref of parsed patch diff format3431# (the same keys as in $diffinfo)3432sub is_patch_split {3433my($diffinfo,$patchinfo) =@_;34343435returndefined$diffinfo&&defined$patchinfo3436&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3437}343834393440sub git_difftree_body {3441my($difftree,$hash,@parents) =@_;3442my($parent) =$parents[0];3443my($have_blame) = gitweb_check_feature('blame');3444print"<div class=\"list_head\">\n";3445if($#{$difftree} >10) {3446print(($#{$difftree} +1) ." files changed:\n");3447}3448print"</div>\n";34493450print"<table class=\"".3451(@parents>1?"combined ":"") .3452"diff_tree\">\n";34533454# header only for combined diff in 'commitdiff' view3455my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3456if($has_header) {3457# table header3458print"<thead><tr>\n".3459"<th></th><th></th>\n";# filename, patchN link3460for(my$i=0;$i<@parents;$i++) {3461my$par=$parents[$i];3462print"<th>".3463$cgi->a({-href => href(action=>"commitdiff",3464 hash=>$hash, hash_parent=>$par),3465-title =>'commitdiff to parent number '.3466($i+1) .': '.substr($par,0,7)},3467$i+1) .3468" </th>\n";3469}3470print"</tr></thead>\n<tbody>\n";3471}34723473my$alternate=1;3474my$patchno=0;3475foreachmy$line(@{$difftree}) {3476my$diff= parsed_difftree_line($line);34773478if($alternate) {3479print"<tr class=\"dark\">\n";3480}else{3481print"<tr class=\"light\">\n";3482}3483$alternate^=1;34843485if(exists$diff->{'nparents'}) {# combined diff34863487 fill_from_file_info($diff,@parents)3488unlessexists$diff->{'from_file'};34893490if(!is_deleted($diff)) {3491# file exists in the result (child) commit3492print"<td>".3493$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3494 file_name=>$diff->{'to_file'},3495 hash_base=>$hash),3496-class=>"list"}, esc_path($diff->{'to_file'})) .3497"</td>\n";3498}else{3499print"<td>".3500 esc_path($diff->{'to_file'}) .3501"</td>\n";3502}35033504if($actioneq'commitdiff') {3505# link to patch3506$patchno++;3507print"<td class=\"link\">".3508$cgi->a({-href =>"#patch$patchno"},"patch") .3509" | ".3510"</td>\n";3511}35123513my$has_history=0;3514my$not_deleted=0;3515for(my$i=0;$i<$diff->{'nparents'};$i++) {3516my$hash_parent=$parents[$i];3517my$from_hash=$diff->{'from_id'}[$i];3518my$from_path=$diff->{'from_file'}[$i];3519my$status=$diff->{'status'}[$i];35203521$has_history||= ($statusne'A');3522$not_deleted||= ($statusne'D');35233524if($statuseq'A') {3525print"<td class=\"link\"align=\"right\"> | </td>\n";3526}elsif($statuseq'D') {3527print"<td class=\"link\">".3528$cgi->a({-href => href(action=>"blob",3529 hash_base=>$hash,3530 hash=>$from_hash,3531 file_name=>$from_path)},3532"blob". ($i+1)) .3533" | </td>\n";3534}else{3535if($diff->{'to_id'}eq$from_hash) {3536print"<td class=\"link nochange\">";3537}else{3538print"<td class=\"link\">";3539}3540print$cgi->a({-href => href(action=>"blobdiff",3541 hash=>$diff->{'to_id'},3542 hash_parent=>$from_hash,3543 hash_base=>$hash,3544 hash_parent_base=>$hash_parent,3545 file_name=>$diff->{'to_file'},3546 file_parent=>$from_path)},3547"diff". ($i+1)) .3548" | </td>\n";3549}3550}35513552print"<td class=\"link\">";3553if($not_deleted) {3554print$cgi->a({-href => href(action=>"blob",3555 hash=>$diff->{'to_id'},3556 file_name=>$diff->{'to_file'},3557 hash_base=>$hash)},3558"blob");3559print" | "if($has_history);3560}3561if($has_history) {3562print$cgi->a({-href => href(action=>"history",3563 file_name=>$diff->{'to_file'},3564 hash_base=>$hash)},3565"history");3566}3567print"</td>\n";35683569print"</tr>\n";3570next;# instead of 'else' clause, to avoid extra indent3571}3572# else ordinary diff35733574my($to_mode_oct,$to_mode_str,$to_file_type);3575my($from_mode_oct,$from_mode_str,$from_file_type);3576if($diff->{'to_mode'}ne('0' x 6)) {3577$to_mode_oct=oct$diff->{'to_mode'};3578if(S_ISREG($to_mode_oct)) {# only for regular file3579$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits3580}3581$to_file_type= file_type($diff->{'to_mode'});3582}3583if($diff->{'from_mode'}ne('0' x 6)) {3584$from_mode_oct=oct$diff->{'from_mode'};3585if(S_ISREG($to_mode_oct)) {# only for regular file3586$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits3587}3588$from_file_type= file_type($diff->{'from_mode'});3589}35903591if($diff->{'status'}eq"A") {# created3592my$mode_chng="<span class=\"file_status new\">[new$to_file_type";3593$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;3594$mode_chng.="]</span>";3595print"<td>";3596print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3597 hash_base=>$hash, file_name=>$diff->{'file'}),3598-class=>"list"}, esc_path($diff->{'file'}));3599print"</td>\n";3600print"<td>$mode_chng</td>\n";3601print"<td class=\"link\">";3602if($actioneq'commitdiff') {3603# link to patch3604$patchno++;3605print$cgi->a({-href =>"#patch$patchno"},"patch");3606print" | ";3607}3608print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3609 hash_base=>$hash, file_name=>$diff->{'file'})},3610"blob");3611print"</td>\n";36123613}elsif($diff->{'status'}eq"D") {# deleted3614my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";3615print"<td>";3616print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3617 hash_base=>$parent, file_name=>$diff->{'file'}),3618-class=>"list"}, esc_path($diff->{'file'}));3619print"</td>\n";3620print"<td>$mode_chng</td>\n";3621print"<td class=\"link\">";3622if($actioneq'commitdiff') {3623# link to patch3624$patchno++;3625print$cgi->a({-href =>"#patch$patchno"},"patch");3626print" | ";3627}3628print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3629 hash_base=>$parent, file_name=>$diff->{'file'})},3630"blob") ." | ";3631if($have_blame) {3632print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,3633 file_name=>$diff->{'file'})},3634"blame") ." | ";3635}3636print$cgi->a({-href => href(action=>"history", hash_base=>$parent,3637 file_name=>$diff->{'file'})},3638"history");3639print"</td>\n";36403641}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed3642my$mode_chnge="";3643if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3644$mode_chnge="<span class=\"file_status mode_chnge\">[changed";3645if($from_file_typene$to_file_type) {3646$mode_chnge.=" from$from_file_typeto$to_file_type";3647}3648if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {3649if($from_mode_str&&$to_mode_str) {3650$mode_chnge.=" mode:$from_mode_str->$to_mode_str";3651}elsif($to_mode_str) {3652$mode_chnge.=" mode:$to_mode_str";3653}3654}3655$mode_chnge.="]</span>\n";3656}3657print"<td>";3658print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3659 hash_base=>$hash, file_name=>$diff->{'file'}),3660-class=>"list"}, esc_path($diff->{'file'}));3661print"</td>\n";3662print"<td>$mode_chnge</td>\n";3663print"<td class=\"link\">";3664if($actioneq'commitdiff') {3665# link to patch3666$patchno++;3667print$cgi->a({-href =>"#patch$patchno"},"patch") .3668" | ";3669}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3670# "commit" view and modified file (not onlu mode changed)3671print$cgi->a({-href => href(action=>"blobdiff",3672 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3673 hash_base=>$hash, hash_parent_base=>$parent,3674 file_name=>$diff->{'file'})},3675"diff") .3676" | ";3677}3678print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3679 hash_base=>$hash, file_name=>$diff->{'file'})},3680"blob") ." | ";3681if($have_blame) {3682print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3683 file_name=>$diff->{'file'})},3684"blame") ." | ";3685}3686print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3687 file_name=>$diff->{'file'})},3688"history");3689print"</td>\n";36903691}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied3692my%status_name= ('R'=>'moved','C'=>'copied');3693my$nstatus=$status_name{$diff->{'status'}};3694my$mode_chng="";3695if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3696# mode also for directories, so we cannot use $to_mode_str3697$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);3698}3699print"<td>".3700$cgi->a({-href => href(action=>"blob", hash_base=>$hash,3701 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),3702-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".3703"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".3704$cgi->a({-href => href(action=>"blob", hash_base=>$parent,3705 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),3706-class=>"list"}, esc_path($diff->{'from_file'})) .3707" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".3708"<td class=\"link\">";3709if($actioneq'commitdiff') {3710# link to patch3711$patchno++;3712print$cgi->a({-href =>"#patch$patchno"},"patch") .3713" | ";3714}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3715# "commit" view and modified file (not only pure rename or copy)3716print$cgi->a({-href => href(action=>"blobdiff",3717 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3718 hash_base=>$hash, hash_parent_base=>$parent,3719 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},3720"diff") .3721" | ";3722}3723print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3724 hash_base=>$parent, file_name=>$diff->{'to_file'})},3725"blob") ." | ";3726if($have_blame) {3727print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3728 file_name=>$diff->{'to_file'})},3729"blame") ." | ";3730}3731print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3732 file_name=>$diff->{'to_file'})},3733"history");3734print"</td>\n";37353736}# we should not encounter Unmerged (U) or Unknown (X) status3737print"</tr>\n";3738}3739print"</tbody>"if$has_header;3740print"</table>\n";3741}37423743sub git_patchset_body {3744my($fd,$difftree,$hash,@hash_parents) =@_;3745my($hash_parent) =$hash_parents[0];37463747my$is_combined= (@hash_parents>1);3748my$patch_idx=0;3749my$patch_number=0;3750my$patch_line;3751my$diffinfo;3752my$to_name;3753my(%from,%to);37543755print"<div class=\"patchset\">\n";37563757# skip to first patch3758while($patch_line= <$fd>) {3759chomp$patch_line;37603761last if($patch_line=~m/^diff /);3762}37633764 PATCH:3765while($patch_line) {37663767# parse "git diff" header line3768if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {3769# $1 is from_name, which we do not use3770$to_name= unquote($2);3771$to_name=~s!^b/!!;3772}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {3773# $1 is 'cc' or 'combined', which we do not use3774$to_name= unquote($2);3775}else{3776$to_name=undef;3777}37783779# check if current patch belong to current raw line3780# and parse raw git-diff line if needed3781if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {3782# this is continuation of a split patch3783print"<div class=\"patch cont\">\n";3784}else{3785# advance raw git-diff output if needed3786$patch_idx++ifdefined$diffinfo;37873788# read and prepare patch information3789$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);37903791# compact combined diff output can have some patches skipped3792# find which patch (using pathname of result) we are at now;3793if($is_combined) {3794while($to_namene$diffinfo->{'to_file'}) {3795print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".3796 format_diff_cc_simplified($diffinfo,@hash_parents) .3797"</div>\n";# class="patch"37983799$patch_idx++;3800$patch_number++;38013802last if$patch_idx>$#$difftree;3803$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);3804}3805}38063807# modifies %from, %to hashes3808 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);38093810# this is first patch for raw difftree line with $patch_idx index3811# we index @$difftree array from 0, but number patches from 13812print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";3813}38143815# git diff header3816#assert($patch_line =~ m/^diff /) if DEBUG;3817#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed3818$patch_number++;3819# print "git diff" header3820print format_git_diff_header_line($patch_line,$diffinfo,3821 \%from, \%to);38223823# print extended diff header3824print"<div class=\"diff extended_header\">\n";3825 EXTENDED_HEADER:3826while($patch_line= <$fd>) {3827chomp$patch_line;38283829last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);38303831print format_extended_diff_header_line($patch_line,$diffinfo,3832 \%from, \%to);3833}3834print"</div>\n";# class="diff extended_header"38353836# from-file/to-file diff header3837if(!$patch_line) {3838print"</div>\n";# class="patch"3839last PATCH;3840}3841next PATCH if($patch_line=~m/^diff /);3842#assert($patch_line =~ m/^---/) if DEBUG;38433844my$last_patch_line=$patch_line;3845$patch_line= <$fd>;3846chomp$patch_line;3847#assert($patch_line =~ m/^\+\+\+/) if DEBUG;38483849print format_diff_from_to_header($last_patch_line,$patch_line,3850$diffinfo, \%from, \%to,3851@hash_parents);38523853# the patch itself3854 LINE:3855while($patch_line= <$fd>) {3856chomp$patch_line;38573858next PATCH if($patch_line=~m/^diff /);38593860print format_diff_line($patch_line, \%from, \%to);3861}38623863}continue{3864print"</div>\n";# class="patch"3865}38663867# for compact combined (--cc) format, with chunk and patch simpliciaction3868# patchset might be empty, but there might be unprocessed raw lines3869for(++$patch_idxif$patch_number>0;3870$patch_idx<@$difftree;3871++$patch_idx) {3872# read and prepare patch information3873$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);38743875# generate anchor for "patch" links in difftree / whatchanged part3876print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".3877 format_diff_cc_simplified($diffinfo,@hash_parents) .3878"</div>\n";# class="patch"38793880$patch_number++;3881}38823883if($patch_number==0) {3884if(@hash_parents>1) {3885print"<div class=\"diff nodifferences\">Trivial merge</div>\n";3886}else{3887print"<div class=\"diff nodifferences\">No differences found</div>\n";3888}3889}38903891print"</div>\n";# class="patchset"3892}38933894# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38953896# fills project list info (age, description, owner, forks) for each3897# project in the list, removing invalid projects from returned list3898# NOTE: modifies $projlist, but does not remove entries from it3899sub fill_project_list_info {3900my($projlist,$check_forks) =@_;3901my@projects;39023903my$show_ctags= gitweb_check_feature('ctags');3904 PROJECT:3905foreachmy$pr(@$projlist) {3906my(@activity) = git_get_last_activity($pr->{'path'});3907unless(@activity) {3908next PROJECT;3909}3910($pr->{'age'},$pr->{'age_string'}) =@activity;3911if(!defined$pr->{'descr'}) {3912my$descr= git_get_project_description($pr->{'path'}) ||"";3913$descr= to_utf8($descr);3914$pr->{'descr_long'} =$descr;3915$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);3916}3917if(!defined$pr->{'owner'}) {3918$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";3919}3920if($check_forks) {3921my$pname=$pr->{'path'};3922if(($pname=~s/\.git$//) &&3923($pname!~/\/$/) &&3924(-d "$projectroot/$pname")) {3925$pr->{'forks'} ="-d$projectroot/$pname";3926}else{3927$pr->{'forks'} =0;3928}3929}3930$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});3931push@projects,$pr;3932}39333934return@projects;3935}39363937# print 'sort by' <th> element, generating 'sort by $name' replay link3938# if that order is not selected3939sub print_sort_th {3940my($name,$order,$header) =@_;3941$header||=ucfirst($name);39423943if($ordereq$name) {3944print"<th>$header</th>\n";3945}else{3946print"<th>".3947$cgi->a({-href => href(-replay=>1, order=>$name),3948-class=>"header"},$header) .3949"</th>\n";3950}3951}39523953sub git_project_list_body {3954# actually uses global variable $project3955my($projlist,$order,$from,$to,$extra,$no_header) =@_;39563957my($check_forks) = gitweb_check_feature('forks');3958my@projects= fill_project_list_info($projlist,$check_forks);39593960$order||=$default_projects_order;3961$from=0unlessdefined$from;3962$to=$#projectsif(!defined$to||$#projects<$to);39633964my%order_info= (3965 project => { key =>'path', type =>'str'},3966 descr => { key =>'descr_long', type =>'str'},3967 owner => { key =>'owner', type =>'str'},3968 age => { key =>'age', type =>'num'}3969);3970my$oi=$order_info{$order};3971if($oi->{'type'}eq'str') {3972@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;3973}else{3974@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;3975}39763977my$show_ctags= gitweb_check_feature('ctags');3978if($show_ctags) {3979my%ctags;3980foreachmy$p(@projects) {3981foreachmy$ct(keys%{$p->{'ctags'}}) {3982$ctags{$ct} +=$p->{'ctags'}->{$ct};3983}3984}3985my$cloud= git_populate_project_tagcloud(\%ctags);3986print git_show_project_tagcloud($cloud,64);3987}39883989print"<table class=\"project_list\">\n";3990unless($no_header) {3991print"<tr>\n";3992if($check_forks) {3993print"<th></th>\n";3994}3995 print_sort_th('project',$order,'Project');3996 print_sort_th('descr',$order,'Description');3997 print_sort_th('owner',$order,'Owner');3998 print_sort_th('age',$order,'Last Change');3999print"<th></th>\n".# for links4000"</tr>\n";4001}4002my$alternate=1;4003my$tagfilter=$cgi->param('by_tag');4004for(my$i=$from;$i<=$to;$i++) {4005my$pr=$projects[$i];40064007next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4008next if$searchtextand not$pr->{'path'} =~/$searchtext/4009and not$pr->{'descr_long'} =~/$searchtext/;4010# Weed out forks or non-matching entries of search4011if($check_forks) {4012my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4013$forkbase="^$forkbase"if$forkbase;4014next ifnot$searchtextand not$tagfilterand$show_ctags4015and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4016}40174018if($alternate) {4019print"<tr class=\"dark\">\n";4020}else{4021print"<tr class=\"light\">\n";4022}4023$alternate^=1;4024if($check_forks) {4025print"<td>";4026if($pr->{'forks'}) {4027print"<!--$pr->{'forks'} -->\n";4028print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4029}4030print"</td>\n";4031}4032print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4033-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4034"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4035-class=>"list", -title =>$pr->{'descr_long'}},4036 esc_html($pr->{'descr'})) ."</td>\n".4037"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4038print"<td class=\"". age_class($pr->{'age'}) ."\">".4039(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4040"<td class=\"link\">".4041$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4042$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4043$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4044$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4045($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4046"</td>\n".4047"</tr>\n";4048}4049if(defined$extra) {4050print"<tr>\n";4051if($check_forks) {4052print"<td></td>\n";4053}4054print"<td colspan=\"5\">$extra</td>\n".4055"</tr>\n";4056}4057print"</table>\n";4058}40594060sub git_shortlog_body {4061# uses global variable $project4062my($commitlist,$from,$to,$refs,$extra) =@_;40634064$from=0unlessdefined$from;4065$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);40664067print"<table class=\"shortlog\">\n";4068my$alternate=1;4069for(my$i=$from;$i<=$to;$i++) {4070my%co= %{$commitlist->[$i]};4071my$commit=$co{'id'};4072my$ref= format_ref_marker($refs,$commit);4073if($alternate) {4074print"<tr class=\"dark\">\n";4075}else{4076print"<tr class=\"light\">\n";4077}4078$alternate^=1;4079my$author= chop_and_escape_str($co{'author_name'},10);4080# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4081print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4082"<td><i>".$author."</i></td>\n".4083"<td>";4084print format_subject_html($co{'title'},$co{'title_short'},4085 href(action=>"commit", hash=>$commit),$ref);4086print"</td>\n".4087"<td class=\"link\">".4088$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4089$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4090$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4091my$snapshot_links= format_snapshot_links($commit);4092if(defined$snapshot_links) {4093print" | ".$snapshot_links;4094}4095print"</td>\n".4096"</tr>\n";4097}4098if(defined$extra) {4099print"<tr>\n".4100"<td colspan=\"4\">$extra</td>\n".4101"</tr>\n";4102}4103print"</table>\n";4104}41054106sub git_history_body {4107# Warning: assumes constant type (blob or tree) during history4108my($commitlist,$from,$to,$refs,$hash_base,$ftype,$extra) =@_;41094110$from=0unlessdefined$from;4111$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});41124113print"<table class=\"history\">\n";4114my$alternate=1;4115for(my$i=$from;$i<=$to;$i++) {4116my%co= %{$commitlist->[$i]};4117if(!%co) {4118next;4119}4120my$commit=$co{'id'};41214122my$ref= format_ref_marker($refs,$commit);41234124if($alternate) {4125print"<tr class=\"dark\">\n";4126}else{4127print"<tr class=\"light\">\n";4128}4129$alternate^=1;4130# shortlog uses chop_str($co{'author_name'}, 10)4131my$author= chop_and_escape_str($co{'author_name'},15,3);4132print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4133"<td><i>".$author."</i></td>\n".4134"<td>";4135# originally git_history used chop_str($co{'title'}, 50)4136print format_subject_html($co{'title'},$co{'title_short'},4137 href(action=>"commit", hash=>$commit),$ref);4138print"</td>\n".4139"<td class=\"link\">".4140$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4141$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");41424143if($ftypeeq'blob') {4144my$blob_current= git_get_hash_by_path($hash_base,$file_name);4145my$blob_parent= git_get_hash_by_path($commit,$file_name);4146if(defined$blob_current&&defined$blob_parent&&4147$blob_currentne$blob_parent) {4148print" | ".4149$cgi->a({-href => href(action=>"blobdiff",4150 hash=>$blob_current, hash_parent=>$blob_parent,4151 hash_base=>$hash_base, hash_parent_base=>$commit,4152 file_name=>$file_name)},4153"diff to current");4154}4155}4156print"</td>\n".4157"</tr>\n";4158}4159if(defined$extra) {4160print"<tr>\n".4161"<td colspan=\"4\">$extra</td>\n".4162"</tr>\n";4163}4164print"</table>\n";4165}41664167sub git_tags_body {4168# uses global variable $project4169my($taglist,$from,$to,$extra) =@_;4170$from=0unlessdefined$from;4171$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);41724173print"<table class=\"tags\">\n";4174my$alternate=1;4175for(my$i=$from;$i<=$to;$i++) {4176my$entry=$taglist->[$i];4177my%tag=%$entry;4178my$comment=$tag{'subject'};4179my$comment_short;4180if(defined$comment) {4181$comment_short= chop_str($comment,30,5);4182}4183if($alternate) {4184print"<tr class=\"dark\">\n";4185}else{4186print"<tr class=\"light\">\n";4187}4188$alternate^=1;4189if(defined$tag{'age'}) {4190print"<td><i>$tag{'age'}</i></td>\n";4191}else{4192print"<td></td>\n";4193}4194print"<td>".4195$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4196-class=>"list name"}, esc_html($tag{'name'})) .4197"</td>\n".4198"<td>";4199if(defined$comment) {4200print format_subject_html($comment,$comment_short,4201 href(action=>"tag", hash=>$tag{'id'}));4202}4203print"</td>\n".4204"<td class=\"selflink\">";4205if($tag{'type'}eq"tag") {4206print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4207}else{4208print" ";4209}4210print"</td>\n".4211"<td class=\"link\">"." | ".4212$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4213if($tag{'reftype'}eq"commit") {4214print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4215" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4216}elsif($tag{'reftype'}eq"blob") {4217print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4218}4219print"</td>\n".4220"</tr>";4221}4222if(defined$extra) {4223print"<tr>\n".4224"<td colspan=\"5\">$extra</td>\n".4225"</tr>\n";4226}4227print"</table>\n";4228}42294230sub git_heads_body {4231# uses global variable $project4232my($headlist,$head,$from,$to,$extra) =@_;4233$from=0unlessdefined$from;4234$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);42354236print"<table class=\"heads\">\n";4237my$alternate=1;4238for(my$i=$from;$i<=$to;$i++) {4239my$entry=$headlist->[$i];4240my%ref=%$entry;4241my$curr=$ref{'id'}eq$head;4242if($alternate) {4243print"<tr class=\"dark\">\n";4244}else{4245print"<tr class=\"light\">\n";4246}4247$alternate^=1;4248print"<td><i>$ref{'age'}</i></td>\n".4249($curr?"<td class=\"current_head\">":"<td>") .4250$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4251-class=>"list name"},esc_html($ref{'name'})) .4252"</td>\n".4253"<td class=\"link\">".4254$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4255$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4256$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4257"</td>\n".4258"</tr>";4259}4260if(defined$extra) {4261print"<tr>\n".4262"<td colspan=\"3\">$extra</td>\n".4263"</tr>\n";4264}4265print"</table>\n";4266}42674268sub git_search_grep_body {4269my($commitlist,$from,$to,$extra) =@_;4270$from=0unlessdefined$from;4271$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);42724273print"<table class=\"commit_search\">\n";4274my$alternate=1;4275for(my$i=$from;$i<=$to;$i++) {4276my%co= %{$commitlist->[$i]};4277if(!%co) {4278next;4279}4280my$commit=$co{'id'};4281if($alternate) {4282print"<tr class=\"dark\">\n";4283}else{4284print"<tr class=\"light\">\n";4285}4286$alternate^=1;4287my$author= chop_and_escape_str($co{'author_name'},15,5);4288print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4289"<td><i>".$author."</i></td>\n".4290"<td>".4291$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4292-class=>"list subject"},4293 chop_and_escape_str($co{'title'},50) ."<br/>");4294my$comment=$co{'comment'};4295foreachmy$line(@$comment) {4296if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4297my($lead,$match,$trail) = ($1,$2,$3);4298$match= chop_str($match,70,5,'center');4299my$contextlen=int((80-length($match))/2);4300$contextlen=30if($contextlen>30);4301$lead= chop_str($lead,$contextlen,10,'left');4302$trail= chop_str($trail,$contextlen,10,'right');43034304$lead= esc_html($lead);4305$match= esc_html($match);4306$trail= esc_html($trail);43074308print"$lead<span class=\"match\">$match</span>$trail<br />";4309}4310}4311print"</td>\n".4312"<td class=\"link\">".4313$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4314" | ".4315$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4316" | ".4317$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4318print"</td>\n".4319"</tr>\n";4320}4321if(defined$extra) {4322print"<tr>\n".4323"<td colspan=\"3\">$extra</td>\n".4324"</tr>\n";4325}4326print"</table>\n";4327}43284329## ======================================================================4330## ======================================================================4331## actions43324333sub git_project_list {4334my$order=$input_params{'order'};4335if(defined$order&&$order!~m/none|project|descr|owner|age/) {4336 die_error(400,"Unknown order parameter");4337}43384339my@list= git_get_projects_list();4340if(!@list) {4341 die_error(404,"No projects found");4342}43434344 git_header_html();4345if(-f $home_text) {4346print"<div class=\"index_include\">\n";4347open(my$fd,$home_text);4348print<$fd>;4349close$fd;4350print"</div>\n";4351}4352print$cgi->startform(-method=>"get") .4353"<p class=\"projsearch\">Search:\n".4354$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4355"</p>".4356$cgi->end_form() ."\n";4357 git_project_list_body(\@list,$order);4358 git_footer_html();4359}43604361sub git_forks {4362my$order=$input_params{'order'};4363if(defined$order&&$order!~m/none|project|descr|owner|age/) {4364 die_error(400,"Unknown order parameter");4365}43664367my@list= git_get_projects_list($project);4368if(!@list) {4369 die_error(404,"No forks found");4370}43714372 git_header_html();4373 git_print_page_nav('','');4374 git_print_header_div('summary',"$projectforks");4375 git_project_list_body(\@list,$order);4376 git_footer_html();4377}43784379sub git_project_index {4380my@projects= git_get_projects_list($project);43814382print$cgi->header(4383-type =>'text/plain',4384-charset =>'utf-8',4385-content_disposition =>'inline; filename="index.aux"');43864387foreachmy$pr(@projects) {4388if(!exists$pr->{'owner'}) {4389$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4390}43914392my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4393# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4394$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4395$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4396$path=~s/ /\+/g;4397$owner=~s/ /\+/g;43984399print"$path$owner\n";4400}4401}44024403sub git_summary {4404my$descr= git_get_project_description($project) ||"none";4405my%co= parse_commit("HEAD");4406my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4407my$head=$co{'id'};44084409my$owner= git_get_project_owner($project);44104411my$refs= git_get_references();4412# These get_*_list functions return one more to allow us to see if4413# there are more ...4414my@taglist= git_get_tags_list(16);4415my@headlist= git_get_heads_list(16);4416my@forklist;4417my($check_forks) = gitweb_check_feature('forks');44184419if($check_forks) {4420@forklist= git_get_projects_list($project);4421}44224423 git_header_html();4424 git_print_page_nav('summary','',$head);44254426print"<div class=\"title\"> </div>\n";4427print"<table class=\"projects_list\">\n".4428"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4429"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4430if(defined$cd{'rfc2822'}) {4431print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4432}44334434# use per project git URL list in $projectroot/$project/cloneurl4435# or make project git URL from git base URL and project name4436my$url_tag="URL";4437my@url_list= git_get_project_url_list($project);4438@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4439foreachmy$git_url(@url_list) {4440next unless$git_url;4441print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4442$url_tag="";4443}44444445# Tag cloud4446my$show_ctags= (gitweb_check_feature('ctags'))[0];4447if($show_ctags) {4448my$ctags= git_get_project_ctags($project);4449my$cloud= git_populate_project_tagcloud($ctags);4450print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4451print"</td>\n<td>"unless%$ctags;4452print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4453print"</td>\n<td>"if%$ctags;4454print git_show_project_tagcloud($cloud,48);4455print"</td></tr>";4456}44574458print"</table>\n";44594460if(-s "$projectroot/$project/README.html") {4461if(open my$fd,"$projectroot/$project/README.html") {4462print"<div class=\"title\">readme</div>\n".4463"<div class=\"readme\">\n";4464print$_while(<$fd>);4465print"\n</div>\n";# class="readme"4466close$fd;4467}4468}44694470# we need to request one more than 16 (0..15) to check if4471# those 16 are all4472my@commitlist=$head? parse_commits($head,17) : ();4473if(@commitlist) {4474 git_print_header_div('shortlog');4475 git_shortlog_body(\@commitlist,0,15,$refs,4476$#commitlist<=15?undef:4477$cgi->a({-href => href(action=>"shortlog")},"..."));4478}44794480if(@taglist) {4481 git_print_header_div('tags');4482 git_tags_body(\@taglist,0,15,4483$#taglist<=15?undef:4484$cgi->a({-href => href(action=>"tags")},"..."));4485}44864487if(@headlist) {4488 git_print_header_div('heads');4489 git_heads_body(\@headlist,$head,0,15,4490$#headlist<=15?undef:4491$cgi->a({-href => href(action=>"heads")},"..."));4492}44934494if(@forklist) {4495 git_print_header_div('forks');4496 git_project_list_body(\@forklist,'age',0,15,4497$#forklist<=15?undef:4498$cgi->a({-href => href(action=>"forks")},"..."),4499'no_header');4500}45014502 git_footer_html();4503}45044505sub git_tag {4506my$head= git_get_head_hash($project);4507 git_header_html();4508 git_print_page_nav('','',$head,undef,$head);4509my%tag= parse_tag($hash);45104511if(!%tag) {4512 die_error(404,"Unknown tag object");4513}45144515 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4516print"<div class=\"title_text\">\n".4517"<table class=\"object_header\">\n".4518"<tr>\n".4519"<td>object</td>\n".4520"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4521$tag{'object'}) ."</td>\n".4522"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4523$tag{'type'}) ."</td>\n".4524"</tr>\n";4525if(defined($tag{'author'})) {4526my%ad= parse_date($tag{'epoch'},$tag{'tz'});4527print"<tr><td>author</td><td>". esc_html($tag{'author'}) ."</td></tr>\n";4528print"<tr><td></td><td>".$ad{'rfc2822'} .4529sprintf(" (%02d:%02d%s)",$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'}) .4530"</td></tr>\n";4531}4532print"</table>\n\n".4533"</div>\n";4534print"<div class=\"page_body\">";4535my$comment=$tag{'comment'};4536foreachmy$line(@$comment) {4537chomp$line;4538print esc_html($line, -nbsp=>1) ."<br/>\n";4539}4540print"</div>\n";4541 git_footer_html();4542}45434544sub git_blame {4545my$fd;4546my$ftype;45474548 gitweb_check_feature('blame')4549or die_error(403,"Blame view not allowed");45504551 die_error(400,"No file name given")unless$file_name;4552$hash_base||= git_get_head_hash($project);4553 die_error(404,"Couldn't find base commit")unless($hash_base);4554my%co= parse_commit($hash_base)4555or die_error(404,"Commit not found");4556if(!defined$hash) {4557$hash= git_get_hash_by_path($hash_base,$file_name,"blob")4558or die_error(404,"Error looking up file");4559}4560$ftype= git_get_type($hash);4561if($ftype!~"blob") {4562 die_error(400,"Object is not a blob");4563}4564open($fd,"-|", git_cmd(),"blame",'-p','--',4565$file_name,$hash_base)4566or die_error(500,"Open git-blame failed");4567 git_header_html();4568my$formats_nav=4569$cgi->a({-href => href(action=>"blob", -replay=>1)},4570"blob") .4571" | ".4572$cgi->a({-href => href(action=>"history", -replay=>1)},4573"history") .4574" | ".4575$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},4576"HEAD");4577 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4578 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4579 git_print_page_path($file_name,$ftype,$hash_base);4580my@rev_color= (qw(light2 dark2));4581my$num_colors=scalar(@rev_color);4582my$current_color=0;4583my$last_rev;4584print<<HTML;4585<div class="page_body">4586<table class="blame">4587<tr><th>Commit</th><th>Line</th><th>Data</th></tr>4588HTML4589my%metainfo= ();4590while(1) {4591$_= <$fd>;4592last unlessdefined$_;4593my($full_rev,$orig_lineno,$lineno,$group_size) =4594/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;4595if(!exists$metainfo{$full_rev}) {4596$metainfo{$full_rev} = {};4597}4598my$meta=$metainfo{$full_rev};4599while(<$fd>) {4600last if(s/^\t//);4601if(/^(\S+) (.*)$/) {4602$meta->{$1} =$2;4603}4604}4605my$data=$_;4606chomp$data;4607my$rev=substr($full_rev,0,8);4608my$author=$meta->{'author'};4609my%date= parse_date($meta->{'author-time'},4610$meta->{'author-tz'});4611my$date=$date{'iso-tz'};4612if($group_size) {4613$current_color= ++$current_color%$num_colors;4614}4615print"<tr class=\"$rev_color[$current_color]\">\n";4616if($group_size) {4617print"<td class=\"sha1\"";4618print" title=\"". esc_html($author) .",$date\"";4619print" rowspan=\"$group_size\""if($group_size>1);4620print">";4621print$cgi->a({-href => href(action=>"commit",4622 hash=>$full_rev,4623 file_name=>$file_name)},4624 esc_html($rev));4625print"</td>\n";4626}4627open(my$dd,"-|", git_cmd(),"rev-parse","$full_rev^")4628or die_error(500,"Open git-rev-parse failed");4629my$parent_commit= <$dd>;4630close$dd;4631chomp($parent_commit);4632my$blamed= href(action =>'blame',4633 file_name =>$meta->{'filename'},4634 hash_base =>$parent_commit);4635print"<td class=\"linenr\">";4636print$cgi->a({ -href =>"$blamed#l$orig_lineno",4637-id =>"l$lineno",4638-class=>"linenr"},4639 esc_html($lineno));4640print"</td>";4641print"<td class=\"pre\">". esc_html($data) ."</td>\n";4642print"</tr>\n";4643}4644print"</table>\n";4645print"</div>";4646close$fd4647or print"Reading blob failed\n";4648 git_footer_html();4649}46504651sub git_tags {4652my$head= git_get_head_hash($project);4653 git_header_html();4654 git_print_page_nav('','',$head,undef,$head);4655 git_print_header_div('summary',$project);46564657my@tagslist= git_get_tags_list();4658if(@tagslist) {4659 git_tags_body(\@tagslist);4660}4661 git_footer_html();4662}46634664sub git_heads {4665my$head= git_get_head_hash($project);4666 git_header_html();4667 git_print_page_nav('','',$head,undef,$head);4668 git_print_header_div('summary',$project);46694670my@headslist= git_get_heads_list();4671if(@headslist) {4672 git_heads_body(\@headslist,$head);4673}4674 git_footer_html();4675}46764677sub git_blob_plain {4678my$type=shift;4679my$expires;46804681if(!defined$hash) {4682if(defined$file_name) {4683my$base=$hash_base|| git_get_head_hash($project);4684$hash= git_get_hash_by_path($base,$file_name,"blob")4685or die_error(404,"Cannot find file");4686}else{4687 die_error(400,"No file name defined");4688}4689}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4690# blobs defined by non-textual hash id's can be cached4691$expires="+1d";4692}46934694open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4695or die_error(500,"Open git-cat-file blob '$hash' failed");46964697# content-type (can include charset)4698$type= blob_contenttype($fd,$file_name,$type);46994700# "save as" filename, even when no $file_name is given4701my$save_as="$hash";4702if(defined$file_name) {4703$save_as=$file_name;4704}elsif($type=~m/^text\//) {4705$save_as.='.txt';4706}47074708print$cgi->header(4709-type =>$type,4710-expires =>$expires,4711-content_disposition =>'inline; filename="'.$save_as.'"');4712undef$/;4713binmode STDOUT,':raw';4714print<$fd>;4715binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi4716$/="\n";4717close$fd;4718}47194720sub git_blob {4721my$expires;47224723if(!defined$hash) {4724if(defined$file_name) {4725my$base=$hash_base|| git_get_head_hash($project);4726$hash= git_get_hash_by_path($base,$file_name,"blob")4727or die_error(404,"Cannot find file");4728}else{4729 die_error(400,"No file name defined");4730}4731}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4732# blobs defined by non-textual hash id's can be cached4733$expires="+1d";4734}47354736my($have_blame) = gitweb_check_feature('blame');4737open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4738or die_error(500,"Couldn't cat$file_name,$hash");4739my$mimetype= blob_mimetype($fd,$file_name);4740if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {4741close$fd;4742return git_blob_plain($mimetype);4743}4744# we can have blame only for text/* mimetype4745$have_blame&&= ($mimetype=~m!^text/!);47464747 git_header_html(undef,$expires);4748my$formats_nav='';4749if(defined$hash_base&& (my%co= parse_commit($hash_base))) {4750if(defined$file_name) {4751if($have_blame) {4752$formats_nav.=4753$cgi->a({-href => href(action=>"blame", -replay=>1)},4754"blame") .4755" | ";4756}4757$formats_nav.=4758$cgi->a({-href => href(action=>"history", -replay=>1)},4759"history") .4760" | ".4761$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},4762"raw") .4763" | ".4764$cgi->a({-href => href(action=>"blob",4765 hash_base=>"HEAD", file_name=>$file_name)},4766"HEAD");4767}else{4768$formats_nav.=4769$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},4770"raw");4771}4772 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4773 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4774}else{4775print"<div class=\"page_nav\">\n".4776"<br/><br/></div>\n".4777"<div class=\"title\">$hash</div>\n";4778}4779 git_print_page_path($file_name,"blob",$hash_base);4780print"<div class=\"page_body\">\n";4781if($mimetype=~m!^image/!) {4782print qq!<img type="$mimetype"!;4783if($file_name) {4784print qq! alt="$file_name" title="$file_name"!;4785}4786print qq! src="! .4787 href(action=>"blob_plain", hash=>$hash,4788 hash_base=>$hash_base, file_name=>$file_name) .4789 qq!"/>\n!;4790}else{4791my$nr;4792while(my$line= <$fd>) {4793chomp$line;4794$nr++;4795$line= untabify($line);4796printf"<div class=\"pre\"><a id=\"l%i\"href=\"#l%i\"class=\"linenr\">%4i</a>%s</div>\n",4797$nr,$nr,$nr, esc_html($line, -nbsp=>1);4798}4799}4800close$fd4801or print"Reading blob failed.\n";4802print"</div>";4803 git_footer_html();4804}48054806sub git_tree {4807if(!defined$hash_base) {4808$hash_base="HEAD";4809}4810if(!defined$hash) {4811if(defined$file_name) {4812$hash= git_get_hash_by_path($hash_base,$file_name,"tree");4813}else{4814$hash=$hash_base;4815}4816}4817 die_error(404,"No such tree")unlessdefined($hash);4818$/="\0";4819open my$fd,"-|", git_cmd(),"ls-tree",'-z',$hash4820or die_error(500,"Open git-ls-tree failed");4821my@entries=map{chomp;$_} <$fd>;4822close$fdor die_error(404,"Reading tree failed");4823$/="\n";48244825my$refs= git_get_references();4826my$ref= format_ref_marker($refs,$hash_base);4827 git_header_html();4828my$basedir='';4829my($have_blame) = gitweb_check_feature('blame');4830if(defined$hash_base&& (my%co= parse_commit($hash_base))) {4831my@views_nav= ();4832if(defined$file_name) {4833push@views_nav,4834$cgi->a({-href => href(action=>"history", -replay=>1)},4835"history"),4836$cgi->a({-href => href(action=>"tree",4837 hash_base=>"HEAD", file_name=>$file_name)},4838"HEAD"),4839}4840my$snapshot_links= format_snapshot_links($hash);4841if(defined$snapshot_links) {4842# FIXME: Should be available when we have no hash base as well.4843push@views_nav,$snapshot_links;4844}4845 git_print_page_nav('tree','',$hash_base,undef,undef,join(' | ',@views_nav));4846 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);4847}else{4848undef$hash_base;4849print"<div class=\"page_nav\">\n";4850print"<br/><br/></div>\n";4851print"<div class=\"title\">$hash</div>\n";4852}4853if(defined$file_name) {4854$basedir=$file_name;4855if($basedirne''&&substr($basedir, -1)ne'/') {4856$basedir.='/';4857}4858 git_print_page_path($file_name,'tree',$hash_base);4859}4860print"<div class=\"page_body\">\n";4861print"<table class=\"tree\">\n";4862my$alternate=1;4863# '..' (top directory) link if possible4864if(defined$hash_base&&4865defined$file_name&&$file_name=~m![^/]+$!) {4866if($alternate) {4867print"<tr class=\"dark\">\n";4868}else{4869print"<tr class=\"light\">\n";4870}4871$alternate^=1;48724873my$up=$file_name;4874$up=~s!/?[^/]+$!!;4875undef$upunless$up;4876# based on git_print_tree_entry4877print'<td class="mode">'. mode_str('040000') ."</td>\n";4878print'<td class="list">';4879print$cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,4880 file_name=>$up)},4881"..");4882print"</td>\n";4883print"<td class=\"link\"></td>\n";48844885print"</tr>\n";4886}4887foreachmy$line(@entries) {4888my%t= parse_ls_tree_line($line, -z =>1);48894890if($alternate) {4891print"<tr class=\"dark\">\n";4892}else{4893print"<tr class=\"light\">\n";4894}4895$alternate^=1;48964897 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);48984899print"</tr>\n";4900}4901print"</table>\n".4902"</div>";4903 git_footer_html();4904}49054906sub git_snapshot {4907my$format=$input_params{'snapshot_format'};4908if(!@snapshot_fmts) {4909 die_error(403,"Snapshots not allowed");4910}4911# default to first supported snapshot format4912$format||=$snapshot_fmts[0];4913if($format!~m/^[a-z0-9]+$/) {4914 die_error(400,"Invalid snapshot format parameter");4915}elsif(!exists($known_snapshot_formats{$format})) {4916 die_error(400,"Unknown snapshot format");4917}elsif(!grep($_eq$format,@snapshot_fmts)) {4918 die_error(403,"Unsupported snapshot format");4919}49204921if(!defined$hash) {4922$hash= git_get_head_hash($project);4923}49244925my$name=$project;4926$name=~ s,([^/])/*\.git$,$1,;4927$name= basename($name);4928my$filename= to_utf8($name);4929$name=~s/\047/\047\\\047\047/g;4930my$cmd;4931$filename.="-$hash$known_snapshot_formats{$format}{'suffix'}";4932$cmd= quote_command(4933 git_cmd(),'archive',4934"--format=$known_snapshot_formats{$format}{'format'}",4935"--prefix=$name/",$hash);4936if(exists$known_snapshot_formats{$format}{'compressor'}) {4937$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});4938}49394940print$cgi->header(4941-type =>$known_snapshot_formats{$format}{'type'},4942-content_disposition =>'inline; filename="'."$filename".'"',4943-status =>'200 OK');49444945open my$fd,"-|",$cmd4946or die_error(500,"Execute git-archive failed");4947binmode STDOUT,':raw';4948print<$fd>;4949binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi4950close$fd;4951}49524953sub git_log {4954my$head= git_get_head_hash($project);4955if(!defined$hash) {4956$hash=$head;4957}4958if(!defined$page) {4959$page=0;4960}4961my$refs= git_get_references();49624963my@commitlist= parse_commits($hash,101, (100*$page));49644965my$paging_nav= format_paging_nav('log',$hash,$head,$page,$#commitlist>=100);49664967 git_header_html();4968 git_print_page_nav('log','',$hash,undef,undef,$paging_nav);49694970if(!@commitlist) {4971my%co= parse_commit($hash);49724973 git_print_header_div('summary',$project);4974print"<div class=\"page_body\"> Last change$co{'age_string'}.<br/><br/></div>\n";4975}4976my$to= ($#commitlist>=99) ? (99) : ($#commitlist);4977for(my$i=0;$i<=$to;$i++) {4978my%co= %{$commitlist[$i]};4979next if!%co;4980my$commit=$co{'id'};4981my$ref= format_ref_marker($refs,$commit);4982my%ad= parse_date($co{'author_epoch'});4983 git_print_header_div('commit',4984"<span class=\"age\">$co{'age_string'}</span>".4985 esc_html($co{'title'}) .$ref,4986$commit);4987print"<div class=\"title_text\">\n".4988"<div class=\"log_link\">\n".4989$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .4990" | ".4991$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .4992" | ".4993$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .4994"<br/>\n".4995"</div>\n".4996"<i>". esc_html($co{'author_name'}) ." [$ad{'rfc2822'}]</i><br/>\n".4997"</div>\n";49984999print"<div class=\"log_body\">\n";5000 git_print_log($co{'comment'}, -final_empty_line=>1);5001print"</div>\n";5002}5003if($#commitlist>=100) {5004print"<div class=\"page_nav\">\n";5005print$cgi->a({-href => href(-replay=>1, page=>$page+1),5006-accesskey =>"n", -title =>"Alt-n"},"next");5007print"</div>\n";5008}5009 git_footer_html();5010}50115012sub git_commit {5013$hash||=$hash_base||"HEAD";5014my%co= parse_commit($hash)5015or die_error(404,"Unknown commit object");5016my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5017my%cd= parse_date($co{'committer_epoch'},$co{'committer_tz'});50185019my$parent=$co{'parent'};5020my$parents=$co{'parents'};# listref50215022# we need to prepare $formats_nav before any parameter munging5023my$formats_nav;5024if(!defined$parent) {5025# --root commitdiff5026$formats_nav.='(initial)';5027}elsif(@$parents==1) {5028# single parent commit5029$formats_nav.=5030'(parent: '.5031$cgi->a({-href => href(action=>"commit",5032 hash=>$parent)},5033 esc_html(substr($parent,0,7))) .5034')';5035}else{5036# merge commit5037$formats_nav.=5038'(merge: '.5039join(' ',map{5040$cgi->a({-href => href(action=>"commit",5041 hash=>$_)},5042 esc_html(substr($_,0,7)));5043}@$parents) .5044')';5045}50465047if(!defined$parent) {5048$parent="--root";5049}5050my@difftree;5051open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5052@diff_opts,5053(@$parents<=1?$parent:'-c'),5054$hash,"--"5055or die_error(500,"Open git-diff-tree failed");5056@difftree=map{chomp;$_} <$fd>;5057close$fdor die_error(404,"Reading git-diff-tree failed");50585059# non-textual hash id's can be cached5060my$expires;5061if($hash=~m/^[0-9a-fA-F]{40}$/) {5062$expires="+1d";5063}5064my$refs= git_get_references();5065my$ref= format_ref_marker($refs,$co{'id'});50665067 git_header_html(undef,$expires);5068 git_print_page_nav('commit','',5069$hash,$co{'tree'},$hash,5070$formats_nav);50715072if(defined$co{'parent'}) {5073 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5074}else{5075 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5076}5077print"<div class=\"title_text\">\n".5078"<table class=\"object_header\">\n";5079print"<tr><td>author</td><td>". esc_html($co{'author'}) ."</td></tr>\n".5080"<tr>".5081"<td></td><td>$ad{'rfc2822'}";5082if($ad{'hour_local'} <6) {5083printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",5084$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});5085}else{5086printf(" (%02d:%02d%s)",5087$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});5088}5089print"</td>".5090"</tr>\n";5091print"<tr><td>committer</td><td>". esc_html($co{'committer'}) ."</td></tr>\n";5092print"<tr><td></td><td>$cd{'rfc2822'}".5093sprintf(" (%02d:%02d%s)",$cd{'hour_local'},$cd{'minute_local'},$cd{'tz_local'}) .5094"</td></tr>\n";5095print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";5096print"<tr>".5097"<td>tree</td>".5098"<td class=\"sha1\">".5099$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),5100class=>"list"},$co{'tree'}) .5101"</td>".5102"<td class=\"link\">".5103$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},5104"tree");5105my$snapshot_links= format_snapshot_links($hash);5106if(defined$snapshot_links) {5107print" | ".$snapshot_links;5108}5109print"</td>".5110"</tr>\n";51115112foreachmy$par(@$parents) {5113print"<tr>".5114"<td>parent</td>".5115"<td class=\"sha1\">".5116$cgi->a({-href => href(action=>"commit", hash=>$par),5117class=>"list"},$par) .5118"</td>".5119"<td class=\"link\">".5120$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .5121" | ".5122$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .5123"</td>".5124"</tr>\n";5125}5126print"</table>".5127"</div>\n";51285129print"<div class=\"page_body\">\n";5130 git_print_log($co{'comment'});5131print"</div>\n";51325133 git_difftree_body(\@difftree,$hash,@$parents);51345135 git_footer_html();5136}51375138sub git_object {5139# object is defined by:5140# - hash or hash_base alone5141# - hash_base and file_name5142my$type;51435144# - hash or hash_base alone5145if($hash|| ($hash_base&& !defined$file_name)) {5146my$object_id=$hash||$hash_base;51475148open my$fd,"-|", quote_command(5149 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'5150or die_error(404,"Object does not exist");5151$type= <$fd>;5152chomp$type;5153close$fd5154or die_error(404,"Object does not exist");51555156# - hash_base and file_name5157}elsif($hash_base&&defined$file_name) {5158$file_name=~ s,/+$,,;51595160system(git_cmd(),"cat-file",'-e',$hash_base) ==05161or die_error(404,"Base object does not exist");51625163# here errors should not hapen5164open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name5165or die_error(500,"Open git-ls-tree failed");5166my$line= <$fd>;5167close$fd;51685169#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'5170unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {5171 die_error(404,"File or directory for given base does not exist");5172}5173$type=$2;5174$hash=$3;5175}else{5176 die_error(400,"Not enough information to find object");5177}51785179print$cgi->redirect(-uri => href(action=>$type, -full=>1,5180 hash=>$hash, hash_base=>$hash_base,5181 file_name=>$file_name),5182-status =>'302 Found');5183}51845185sub git_blobdiff {5186my$format=shift||'html';51875188my$fd;5189my@difftree;5190my%diffinfo;5191my$expires;51925193# preparing $fd and %diffinfo for git_patchset_body5194# new style URI5195if(defined$hash_base&&defined$hash_parent_base) {5196if(defined$file_name) {5197# read raw output5198open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5199$hash_parent_base,$hash_base,5200"--", (defined$file_parent?$file_parent: ()),$file_name5201or die_error(500,"Open git-diff-tree failed");5202@difftree=map{chomp;$_} <$fd>;5203close$fd5204or die_error(404,"Reading git-diff-tree failed");5205@difftree5206or die_error(404,"Blob diff not found");52075208}elsif(defined$hash&&5209$hash=~/[0-9a-fA-F]{40}/) {5210# try to find filename from $hash52115212# read filtered raw output5213open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5214$hash_parent_base,$hash_base,"--"5215or die_error(500,"Open git-diff-tree failed");5216@difftree=5217# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5218# $hash == to_id5219grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5220map{chomp;$_} <$fd>;5221close$fd5222or die_error(404,"Reading git-diff-tree failed");5223@difftree5224or die_error(404,"Blob diff not found");52255226}else{5227 die_error(400,"Missing one of the blob diff parameters");5228}52295230if(@difftree>1) {5231 die_error(400,"Ambiguous blob diff specification");5232}52335234%diffinfo= parse_difftree_raw_line($difftree[0]);5235$file_parent||=$diffinfo{'from_file'} ||$file_name;5236$file_name||=$diffinfo{'to_file'};52375238$hash_parent||=$diffinfo{'from_id'};5239$hash||=$diffinfo{'to_id'};52405241# non-textual hash id's can be cached5242if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5243$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5244$expires='+1d';5245}52465247# open patch output5248open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5249'-p', ($formateq'html'?"--full-index": ()),5250$hash_parent_base,$hash_base,5251"--", (defined$file_parent?$file_parent: ()),$file_name5252or die_error(500,"Open git-diff-tree failed");5253}52545255# old/legacy style URI5256if(!%diffinfo&&# if new style URI failed5257defined$hash&&defined$hash_parent) {5258# fake git-diff-tree raw output5259$diffinfo{'from_mode'} =$diffinfo{'to_mode'} ="blob";5260$diffinfo{'from_id'} =$hash_parent;5261$diffinfo{'to_id'} =$hash;5262if(defined$file_name) {5263if(defined$file_parent) {5264$diffinfo{'status'} ='2';5265$diffinfo{'from_file'} =$file_parent;5266$diffinfo{'to_file'} =$file_name;5267}else{# assume not renamed5268$diffinfo{'status'} ='1';5269$diffinfo{'from_file'} =$file_name;5270$diffinfo{'to_file'} =$file_name;5271}5272}else{# no filename given5273$diffinfo{'status'} ='2';5274$diffinfo{'from_file'} =$hash_parent;5275$diffinfo{'to_file'} =$hash;5276}52775278# non-textual hash id's can be cached5279if($hash=~m/^[0-9a-fA-F]{40}$/&&5280$hash_parent=~m/^[0-9a-fA-F]{40}$/) {5281$expires='+1d';5282}52835284# open patch output5285open$fd,"-|", git_cmd(),"diff",@diff_opts,5286'-p', ($formateq'html'?"--full-index": ()),5287$hash_parent,$hash,"--"5288or die_error(500,"Open git-diff failed");5289}else{5290 die_error(400,"Missing one of the blob diff parameters")5291unless%diffinfo;5292}52935294# header5295if($formateq'html') {5296my$formats_nav=5297$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5298"raw");5299 git_header_html(undef,$expires);5300if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5301 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5302 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5303}else{5304print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5305print"<div class=\"title\">$hashvs$hash_parent</div>\n";5306}5307if(defined$file_name) {5308 git_print_page_path($file_name,"blob",$hash_base);5309}else{5310print"<div class=\"page_path\"></div>\n";5311}53125313}elsif($formateq'plain') {5314print$cgi->header(5315-type =>'text/plain',5316-charset =>'utf-8',5317-expires =>$expires,5318-content_disposition =>'inline; filename="'."$file_name".'.patch"');53195320print"X-Git-Url: ".$cgi->self_url() ."\n\n";53215322}else{5323 die_error(400,"Unknown blobdiff format");5324}53255326# patch5327if($formateq'html') {5328print"<div class=\"page_body\">\n";53295330 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5331close$fd;53325333print"</div>\n";# class="page_body"5334 git_footer_html();53355336}else{5337while(my$line= <$fd>) {5338$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5339$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;53405341print$line;53425343last if$line=~m!^\+\+\+!;5344}5345local$/=undef;5346print<$fd>;5347close$fd;5348}5349}53505351sub git_blobdiff_plain {5352 git_blobdiff('plain');5353}53545355sub git_commitdiff {5356my$format=shift||'html';5357$hash||=$hash_base||"HEAD";5358my%co= parse_commit($hash)5359or die_error(404,"Unknown commit object");53605361# choose format for commitdiff for merge5362if(!defined$hash_parent&& @{$co{'parents'}} >1) {5363$hash_parent='--cc';5364}5365# we need to prepare $formats_nav before almost any parameter munging5366my$formats_nav;5367if($formateq'html') {5368$formats_nav=5369$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},5370"raw");53715372if(defined$hash_parent&&5373$hash_parentne'-c'&&$hash_parentne'--cc') {5374# commitdiff with two commits given5375my$hash_parent_short=$hash_parent;5376if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {5377$hash_parent_short=substr($hash_parent,0,7);5378}5379$formats_nav.=5380' (from';5381for(my$i=0;$i< @{$co{'parents'}};$i++) {5382if($co{'parents'}[$i]eq$hash_parent) {5383$formats_nav.=' parent '. ($i+1);5384last;5385}5386}5387$formats_nav.=': '.5388$cgi->a({-href => href(action=>"commitdiff",5389 hash=>$hash_parent)},5390 esc_html($hash_parent_short)) .5391')';5392}elsif(!$co{'parent'}) {5393# --root commitdiff5394$formats_nav.=' (initial)';5395}elsif(scalar@{$co{'parents'}} ==1) {5396# single parent commit5397$formats_nav.=5398' (parent: '.5399$cgi->a({-href => href(action=>"commitdiff",5400 hash=>$co{'parent'})},5401 esc_html(substr($co{'parent'},0,7))) .5402')';5403}else{5404# merge commit5405if($hash_parenteq'--cc') {5406$formats_nav.=' | '.5407$cgi->a({-href => href(action=>"commitdiff",5408 hash=>$hash, hash_parent=>'-c')},5409'combined');5410}else{# $hash_parent eq '-c'5411$formats_nav.=' | '.5412$cgi->a({-href => href(action=>"commitdiff",5413 hash=>$hash, hash_parent=>'--cc')},5414'compact');5415}5416$formats_nav.=5417' (merge: '.5418join(' ',map{5419$cgi->a({-href => href(action=>"commitdiff",5420 hash=>$_)},5421 esc_html(substr($_,0,7)));5422} @{$co{'parents'}} ) .5423')';5424}5425}54265427my$hash_parent_param=$hash_parent;5428if(!defined$hash_parent_param) {5429# --cc for multiple parents, --root for parentless5430$hash_parent_param=5431@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';5432}54335434# read commitdiff5435my$fd;5436my@difftree;5437if($formateq'html') {5438open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5439"--no-commit-id","--patch-with-raw","--full-index",5440$hash_parent_param,$hash,"--"5441or die_error(500,"Open git-diff-tree failed");54425443while(my$line= <$fd>) {5444chomp$line;5445# empty line ends raw part of diff-tree output5446last unless$line;5447push@difftree,scalar parse_difftree_raw_line($line);5448}54495450}elsif($formateq'plain') {5451open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5452'-p',$hash_parent_param,$hash,"--"5453or die_error(500,"Open git-diff-tree failed");54545455}else{5456 die_error(400,"Unknown commitdiff format");5457}54585459# non-textual hash id's can be cached5460my$expires;5461if($hash=~m/^[0-9a-fA-F]{40}$/) {5462$expires="+1d";5463}54645465# write commit message5466if($formateq'html') {5467my$refs= git_get_references();5468my$ref= format_ref_marker($refs,$co{'id'});54695470 git_header_html(undef,$expires);5471 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);5472 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);5473 git_print_authorship(\%co);5474print"<div class=\"page_body\">\n";5475if(@{$co{'comment'}} >1) {5476print"<div class=\"log\">\n";5477 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);5478print"</div>\n";# class="log"5479}54805481}elsif($formateq'plain') {5482my$refs= git_get_references("tags");5483my$tagname= git_get_rev_name_tags($hash);5484my$filename= basename($project) ."-$hash.patch";54855486print$cgi->header(5487-type =>'text/plain',5488-charset =>'utf-8',5489-expires =>$expires,5490-content_disposition =>'inline; filename="'."$filename".'"');5491my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5492print"From: ". to_utf8($co{'author'}) ."\n";5493print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";5494print"Subject: ". to_utf8($co{'title'}) ."\n";54955496print"X-Git-Tag:$tagname\n"if$tagname;5497print"X-Git-Url: ".$cgi->self_url() ."\n\n";54985499foreachmy$line(@{$co{'comment'}}) {5500print to_utf8($line) ."\n";5501}5502print"---\n\n";5503}55045505# write patch5506if($formateq'html') {5507my$use_parents= !defined$hash_parent||5508$hash_parenteq'-c'||$hash_parenteq'--cc';5509 git_difftree_body(\@difftree,$hash,5510$use_parents? @{$co{'parents'}} :$hash_parent);5511print"<br/>\n";55125513 git_patchset_body($fd, \@difftree,$hash,5514$use_parents? @{$co{'parents'}} :$hash_parent);5515close$fd;5516print"</div>\n";# class="page_body"5517 git_footer_html();55185519}elsif($formateq'plain') {5520local$/=undef;5521print<$fd>;5522close$fd5523or print"Reading git-diff-tree failed\n";5524}5525}55265527sub git_commitdiff_plain {5528 git_commitdiff('plain');5529}55305531sub git_history {5532if(!defined$hash_base) {5533$hash_base= git_get_head_hash($project);5534}5535if(!defined$page) {5536$page=0;5537}5538my$ftype;5539my%co= parse_commit($hash_base)5540or die_error(404,"Unknown commit object");55415542my$refs= git_get_references();5543my$limit=sprintf("--max-count=%i", (100* ($page+1)));55445545my@commitlist= parse_commits($hash_base,101, (100*$page),5546$file_name,"--full-history")5547or die_error(404,"No such file or directory on given branch");55485549if(!defined$hash&&defined$file_name) {5550# some commits could have deleted file in question,5551# and not have it in tree, but one of them has to have it5552for(my$i=0;$i<=@commitlist;$i++) {5553$hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5554last ifdefined$hash;5555}5556}5557if(defined$hash) {5558$ftype= git_get_type($hash);5559}5560if(!defined$ftype) {5561 die_error(500,"Unknown type of object");5562}55635564my$paging_nav='';5565if($page>0) {5566$paging_nav.=5567$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,5568 file_name=>$file_name)},5569"first");5570$paging_nav.=" ⋅ ".5571$cgi->a({-href => href(-replay=>1, page=>$page-1),5572-accesskey =>"p", -title =>"Alt-p"},"prev");5573}else{5574$paging_nav.="first";5575$paging_nav.=" ⋅ prev";5576}5577my$next_link='';5578if($#commitlist>=100) {5579$next_link=5580$cgi->a({-href => href(-replay=>1, page=>$page+1),5581-accesskey =>"n", -title =>"Alt-n"},"next");5582$paging_nav.=" ⋅$next_link";5583}else{5584$paging_nav.=" ⋅ next";5585}55865587 git_header_html();5588 git_print_page_nav('history','',$hash_base,$co{'tree'},$hash_base,$paging_nav);5589 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5590 git_print_page_path($file_name,$ftype,$hash_base);55915592 git_history_body(\@commitlist,0,99,5593$refs,$hash_base,$ftype,$next_link);55945595 git_footer_html();5596}55975598sub git_search {5599 gitweb_check_feature('search')or die_error(403,"Search is disabled");5600if(!defined$searchtext) {5601 die_error(400,"Text field is empty");5602}5603if(!defined$hash) {5604$hash= git_get_head_hash($project);5605}5606my%co= parse_commit($hash);5607if(!%co) {5608 die_error(404,"Unknown commit object");5609}5610if(!defined$page) {5611$page=0;5612}56135614$searchtype||='commit';5615if($searchtypeeq'pickaxe') {5616# pickaxe may take all resources of your box and run for several minutes5617# with every query - so decide by yourself how public you make this feature5618 gitweb_check_feature('pickaxe')5619or die_error(403,"Pickaxe is disabled");5620}5621if($searchtypeeq'grep') {5622 gitweb_check_feature('grep')5623or die_error(403,"Grep is disabled");5624}56255626 git_header_html();56275628if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {5629my$greptype;5630if($searchtypeeq'commit') {5631$greptype="--grep=";5632}elsif($searchtypeeq'author') {5633$greptype="--author=";5634}elsif($searchtypeeq'committer') {5635$greptype="--committer=";5636}5637$greptype.=$searchtext;5638my@commitlist= parse_commits($hash,101, (100*$page),undef,5639$greptype,'--regexp-ignore-case',5640$search_use_regexp?'--extended-regexp':'--fixed-strings');56415642my$paging_nav='';5643if($page>0) {5644$paging_nav.=5645$cgi->a({-href => href(action=>"search", hash=>$hash,5646 searchtext=>$searchtext,5647 searchtype=>$searchtype)},5648"first");5649$paging_nav.=" ⋅ ".5650$cgi->a({-href => href(-replay=>1, page=>$page-1),5651-accesskey =>"p", -title =>"Alt-p"},"prev");5652}else{5653$paging_nav.="first";5654$paging_nav.=" ⋅ prev";5655}5656my$next_link='';5657if($#commitlist>=100) {5658$next_link=5659$cgi->a({-href => href(-replay=>1, page=>$page+1),5660-accesskey =>"n", -title =>"Alt-n"},"next");5661$paging_nav.=" ⋅$next_link";5662}else{5663$paging_nav.=" ⋅ next";5664}56655666if($#commitlist>=100) {5667}56685669 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);5670 git_print_header_div('commit', esc_html($co{'title'}),$hash);5671 git_search_grep_body(\@commitlist,0,99,$next_link);5672}56735674if($searchtypeeq'pickaxe') {5675 git_print_page_nav('','',$hash,$co{'tree'},$hash);5676 git_print_header_div('commit', esc_html($co{'title'}),$hash);56775678print"<table class=\"pickaxe search\">\n";5679my$alternate=1;5680$/="\n";5681open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,5682'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",5683($search_use_regexp?'--pickaxe-regex': ());5684undef%co;5685my@files;5686while(my$line= <$fd>) {5687chomp$line;5688next unless$line;56895690my%set= parse_difftree_raw_line($line);5691if(defined$set{'commit'}) {5692# finish previous commit5693if(%co) {5694print"</td>\n".5695"<td class=\"link\">".5696$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5697" | ".5698$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5699print"</td>\n".5700"</tr>\n";5701}57025703if($alternate) {5704print"<tr class=\"dark\">\n";5705}else{5706print"<tr class=\"light\">\n";5707}5708$alternate^=1;5709%co= parse_commit($set{'commit'});5710my$author= chop_and_escape_str($co{'author_name'},15,5);5711print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5712"<td><i>$author</i></td>\n".5713"<td>".5714$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),5715-class=>"list subject"},5716 chop_and_escape_str($co{'title'},50) ."<br/>");5717}elsif(defined$set{'to_id'}) {5718next if($set{'to_id'} =~m/^0{40}$/);57195720print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},5721 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),5722-class=>"list"},5723"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .5724"<br/>\n";5725}5726}5727close$fd;57285729# finish last commit (warning: repetition!)5730if(%co) {5731print"</td>\n".5732"<td class=\"link\">".5733$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5734" | ".5735$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5736print"</td>\n".5737"</tr>\n";5738}57395740print"</table>\n";5741}57425743if($searchtypeeq'grep') {5744 git_print_page_nav('','',$hash,$co{'tree'},$hash);5745 git_print_header_div('commit', esc_html($co{'title'}),$hash);57465747print"<table class=\"grep_search\">\n";5748my$alternate=1;5749my$matches=0;5750$/="\n";5751open my$fd,"-|", git_cmd(),'grep','-n',5752$search_use_regexp? ('-E','-i') :'-F',5753$searchtext,$co{'tree'};5754my$lastfile='';5755while(my$line= <$fd>) {5756chomp$line;5757my($file,$lno,$ltext,$binary);5758last if($matches++>1000);5759if($line=~/^Binary file (.+) matches$/) {5760$file=$1;5761$binary=1;5762}else{5763(undef,$file,$lno,$ltext) =split(/:/,$line,4);5764}5765if($filene$lastfile) {5766$lastfileand print"</td></tr>\n";5767if($alternate++) {5768print"<tr class=\"dark\">\n";5769}else{5770print"<tr class=\"light\">\n";5771}5772print"<td class=\"list\">".5773$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5774 file_name=>"$file"),5775-class=>"list"}, esc_path($file));5776print"</td><td>\n";5777$lastfile=$file;5778}5779if($binary) {5780print"<div class=\"binary\">Binary file</div>\n";5781}else{5782$ltext= untabify($ltext);5783if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {5784$ltext= esc_html($1, -nbsp=>1);5785$ltext.='<span class="match">';5786$ltext.= esc_html($2, -nbsp=>1);5787$ltext.='</span>';5788$ltext.= esc_html($3, -nbsp=>1);5789}else{5790$ltext= esc_html($ltext, -nbsp=>1);5791}5792print"<div class=\"pre\">".5793$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5794 file_name=>"$file").'#l'.$lno,5795-class=>"linenr"},sprintf('%4i',$lno))5796.' '.$ltext."</div>\n";5797}5798}5799if($lastfile) {5800print"</td></tr>\n";5801if($matches>1000) {5802print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";5803}5804}else{5805print"<div class=\"diff nodifferences\">No matches found</div>\n";5806}5807close$fd;58085809print"</table>\n";5810}5811 git_footer_html();5812}58135814sub git_search_help {5815 git_header_html();5816 git_print_page_nav('','',$hash,$hash,$hash);5817print<<EOT;5818<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without5819regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,5820the pattern entered is recognized as the POSIX extended5821<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case5822insensitive).</p>5823<dl>5824<dt><b>commit</b></dt>5825<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>5826EOT5827my($have_grep) = gitweb_check_feature('grep');5828if($have_grep) {5829print<<EOT;5830<dt><b>grep</b></dt>5831<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing5832 a different one) are searched for the given pattern. On large trees, this search can take5833a while and put some strain on the server, so please use it with some consideration. Note that5834due to git-grep peculiarity, currently if regexp mode is turned off, the matches are5835case-sensitive.</dd>5836EOT5837}5838print<<EOT;5839<dt><b>author</b></dt>5840<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>5841<dt><b>committer</b></dt>5842<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>5843EOT5844my($have_pickaxe) = gitweb_check_feature('pickaxe');5845if($have_pickaxe) {5846print<<EOT;5847<dt><b>pickaxe</b></dt>5848<dd>All commits that caused the string to appear or disappear from any file (changes that5849added, removed or "modified" the string) will be listed. This search can take a while and5850takes a lot of strain on the server, so please use it wisely. Note that since you may be5851interested even in changes just changing the case as well, this search is case sensitive.</dd>5852EOT5853}5854print"</dl>\n";5855 git_footer_html();5856}58575858sub git_shortlog {5859my$head= git_get_head_hash($project);5860if(!defined$hash) {5861$hash=$head;5862}5863if(!defined$page) {5864$page=0;5865}5866my$refs= git_get_references();58675868my$commit_hash=$hash;5869if(defined$hash_parent) {5870$commit_hash="$hash_parent..$hash";5871}5872my@commitlist= parse_commits($commit_hash,101, (100*$page));58735874my$paging_nav= format_paging_nav('shortlog',$hash,$head,$page,$#commitlist>=100);5875my$next_link='';5876if($#commitlist>=100) {5877$next_link=5878$cgi->a({-href => href(-replay=>1, page=>$page+1),5879-accesskey =>"n", -title =>"Alt-n"},"next");5880}58815882 git_header_html();5883 git_print_page_nav('shortlog','',$hash,$hash,$hash,$paging_nav);5884 git_print_header_div('summary',$project);58855886 git_shortlog_body(\@commitlist,0,99,$refs,$next_link);58875888 git_footer_html();5889}58905891## ......................................................................5892## feeds (RSS, Atom; OPML)58935894sub git_feed {5895my$format=shift||'atom';5896my($have_blame) = gitweb_check_feature('blame');58975898# Atom: http://www.atomenabled.org/developers/syndication/5899# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ5900if($formatne'rss'&&$formatne'atom') {5901 die_error(400,"Unknown web feed format");5902}59035904# log/feed of current (HEAD) branch, log of given branch, history of file/directory5905my$head=$hash||'HEAD';5906my@commitlist= parse_commits($head,150,0,$file_name);59075908my%latest_commit;5909my%latest_date;5910my$content_type="application/$format+xml";5911if(defined$cgi->http('HTTP_ACCEPT') &&5912$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {5913# browser (feed reader) prefers text/xml5914$content_type='text/xml';5915}5916if(defined($commitlist[0])) {5917%latest_commit= %{$commitlist[0]};5918%latest_date= parse_date($latest_commit{'author_epoch'});5919print$cgi->header(5920-type =>$content_type,5921-charset =>'utf-8',5922-last_modified =>$latest_date{'rfc2822'});5923}else{5924print$cgi->header(5925-type =>$content_type,5926-charset =>'utf-8');5927}59285929# Optimization: skip generating the body if client asks only5930# for Last-Modified date.5931return if($cgi->request_method()eq'HEAD');59325933# header variables5934my$title="$site_name-$project/$action";5935my$feed_type='log';5936if(defined$hash) {5937$title.=" - '$hash'";5938$feed_type='branch log';5939if(defined$file_name) {5940$title.=" ::$file_name";5941$feed_type='history';5942}5943}elsif(defined$file_name) {5944$title.=" -$file_name";5945$feed_type='history';5946}5947$title.="$feed_type";5948my$descr= git_get_project_description($project);5949if(defined$descr) {5950$descr= esc_html($descr);5951}else{5952$descr="$project".5953($formateq'rss'?'RSS':'Atom') .5954" feed";5955}5956my$owner= git_get_project_owner($project);5957$owner= esc_html($owner);59585959#header5960my$alt_url;5961if(defined$file_name) {5962$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);5963}elsif(defined$hash) {5964$alt_url= href(-full=>1, action=>"log", hash=>$hash);5965}else{5966$alt_url= href(-full=>1, action=>"summary");5967}5968print qq!<?xml version="1.0" encoding="utf-8"?>\n!;5969if($formateq'rss') {5970print<<XML;5971<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">5972<channel>5973XML5974print"<title>$title</title>\n".5975"<link>$alt_url</link>\n".5976"<description>$descr</description>\n".5977"<language>en</language>\n";5978}elsif($formateq'atom') {5979print<<XML;5980<feed xmlns="http://www.w3.org/2005/Atom">5981XML5982print"<title>$title</title>\n".5983"<subtitle>$descr</subtitle>\n".5984'<link rel="alternate" type="text/html" href="'.5985$alt_url.'" />'."\n".5986'<link rel="self" type="'.$content_type.'" href="'.5987$cgi->self_url() .'" />'."\n".5988"<id>". href(-full=>1) ."</id>\n".5989# use project owner for feed author5990"<author><name>$owner</name></author>\n";5991if(defined$favicon) {5992print"<icon>". esc_url($favicon) ."</icon>\n";5993}5994if(defined$logo_url) {5995# not twice as wide as tall: 72 x 27 pixels5996print"<logo>". esc_url($logo) ."</logo>\n";5997}5998if(!%latest_date) {5999# dummy date to keep the feed valid until commits trickle in:6000print"<updated>1970-01-01T00:00:00Z</updated>\n";6001}else{6002print"<updated>$latest_date{'iso-8601'}</updated>\n";6003}6004}60056006# contents6007for(my$i=0;$i<=$#commitlist;$i++) {6008my%co= %{$commitlist[$i]};6009my$commit=$co{'id'};6010# we read 150, we always show 30 and the ones more recent than 48 hours6011if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6012last;6013}6014my%cd= parse_date($co{'author_epoch'});60156016# get list of changed files6017open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6018$co{'parent'} ||"--root",6019$co{'id'},"--", (defined$file_name?$file_name: ())6020ornext;6021my@difftree=map{chomp;$_} <$fd>;6022close$fd6023ornext;60246025# print element (entry, item)6026my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6027if($formateq'rss') {6028print"<item>\n".6029"<title>". esc_html($co{'title'}) ."</title>\n".6030"<author>". esc_html($co{'author'}) ."</author>\n".6031"<pubDate>$cd{'rfc2822'}</pubDate>\n".6032"<guid isPermaLink=\"true\">$co_url</guid>\n".6033"<link>$co_url</link>\n".6034"<description>". esc_html($co{'title'}) ."</description>\n".6035"<content:encoded>".6036"<![CDATA[\n";6037}elsif($formateq'atom') {6038print"<entry>\n".6039"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6040"<updated>$cd{'iso-8601'}</updated>\n".6041"<author>\n".6042" <name>". esc_html($co{'author_name'}) ."</name>\n";6043if($co{'author_email'}) {6044print" <email>". esc_html($co{'author_email'}) ."</email>\n";6045}6046print"</author>\n".6047# use committer for contributor6048"<contributor>\n".6049" <name>". esc_html($co{'committer_name'}) ."</name>\n";6050if($co{'committer_email'}) {6051print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6052}6053print"</contributor>\n".6054"<published>$cd{'iso-8601'}</published>\n".6055"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6056"<id>$co_url</id>\n".6057"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6058"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6059}6060my$comment=$co{'comment'};6061print"<pre>\n";6062foreachmy$line(@$comment) {6063$line= esc_html($line);6064print"$line\n";6065}6066print"</pre><ul>\n";6067foreachmy$difftree_line(@difftree) {6068my%difftree= parse_difftree_raw_line($difftree_line);6069next if!$difftree{'from_id'};60706071my$file=$difftree{'file'} ||$difftree{'to_file'};60726073print"<li>".6074"[".6075$cgi->a({-href => href(-full=>1, action=>"blobdiff",6076 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6077 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6078 file_name=>$file, file_parent=>$difftree{'from_file'}),6079-title =>"diff"},'D');6080if($have_blame) {6081print$cgi->a({-href => href(-full=>1, action=>"blame",6082 file_name=>$file, hash_base=>$commit),6083-title =>"blame"},'B');6084}6085# if this is not a feed of a file history6086if(!defined$file_name||$file_namene$file) {6087print$cgi->a({-href => href(-full=>1, action=>"history",6088 file_name=>$file, hash=>$commit),6089-title =>"history"},'H');6090}6091$file= esc_path($file);6092print"] ".6093"$file</li>\n";6094}6095if($formateq'rss') {6096print"</ul>]]>\n".6097"</content:encoded>\n".6098"</item>\n";6099}elsif($formateq'atom') {6100print"</ul>\n</div>\n".6101"</content>\n".6102"</entry>\n";6103}6104}61056106# end of feed6107if($formateq'rss') {6108print"</channel>\n</rss>\n";6109}elsif($formateq'atom') {6110print"</feed>\n";6111}6112}61136114sub git_rss {6115 git_feed('rss');6116}61176118sub git_atom {6119 git_feed('atom');6120}61216122sub git_opml {6123my@list= git_get_projects_list();61246125print$cgi->header(-type =>'text/xml', -charset =>'utf-8');6126print<<XML;6127<?xml version="1.0" encoding="utf-8"?>6128<opml version="1.0">6129<head>6130 <title>$site_nameOPML Export</title>6131</head>6132<body>6133<outline text="git RSS feeds">6134XML61356136foreachmy$pr(@list) {6137my%proj=%$pr;6138my$head= git_get_head_hash($proj{'path'});6139if(!defined$head) {6140next;6141}6142$git_dir="$projectroot/$proj{'path'}";6143my%co= parse_commit($head);6144if(!%co) {6145next;6146}61476148my$path= esc_html(chop_str($proj{'path'},25,5));6149my$rss="$my_url?p=$proj{'path'};a=rss";6150my$html="$my_url?p=$proj{'path'};a=summary";6151print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";6152}6153print<<XML;6154</outline>6155</body>6156</opml>6157XML6158}