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# Base URL for relative URLs in gitweb ($logo, $favicon, ...), 31# needed and used only for URLs with nonempty PATH_INFO 32our$base_url=$my_url; 33 34# When the script is used as DirectoryIndex, the URL does not contain the name 35# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we 36# have to do it ourselves. We make $path_info global because it's also used 37# later on. 38# 39# Another issue with the script being the DirectoryIndex is that the resulting 40# $my_url data is not the full script URL: this is good, because we want 41# generated links to keep implying the script name if it wasn't explicitly 42# indicated in the URL we're handling, but it means that $my_url cannot be used 43# as base URL. 44# Therefore, if we needed to strip PATH_INFO, then we know that we have 45# to build the base URL ourselves: 46our$path_info=$ENV{"PATH_INFO"}; 47if($path_info) { 48if($my_url=~ s,\Q$path_info\E$,, && 49$my_uri=~ s,\Q$path_info\E$,, && 50defined$ENV{'SCRIPT_NAME'}) { 51$base_url=$cgi->url(-base =>1) .$ENV{'SCRIPT_NAME'}; 52} 53} 54 55# core git executable to use 56# this can just be "git" if your webserver has a sensible PATH 57our$GIT="++GIT_BINDIR++/git"; 58 59# absolute fs-path which will be prepended to the project path 60#our $projectroot = "/pub/scm"; 61our$projectroot="++GITWEB_PROJECTROOT++"; 62 63# fs traversing limit for getting project list 64# the number is relative to the projectroot 65our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 66 67# target of the home link on top of all pages 68our$home_link=$my_uri||"/"; 69 70# string of the home link on top of all pages 71our$home_link_str="++GITWEB_HOME_LINK_STR++"; 72 73# name of your site or organization to appear in page titles 74# replace this with something more descriptive for clearer bookmarks 75our$site_name="++GITWEB_SITENAME++" 76|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 77 78# filename of html text to include at top of each page 79our$site_header="++GITWEB_SITE_HEADER++"; 80# html text to include at home page 81our$home_text="++GITWEB_HOMETEXT++"; 82# filename of html text to include at bottom of each page 83our$site_footer="++GITWEB_SITE_FOOTER++"; 84 85# URI of stylesheets 86our@stylesheets= ("++GITWEB_CSS++"); 87# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 88our$stylesheet=undef; 89# URI of GIT logo (72x27 size) 90our$logo="++GITWEB_LOGO++"; 91# URI of GIT favicon, assumed to be image/png type 92our$favicon="++GITWEB_FAVICON++"; 93 94# URI and label (title) of GIT logo link 95#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 96#our $logo_label = "git documentation"; 97our$logo_url="http://git.or.cz/"; 98our$logo_label="git homepage"; 99 100# source of projects list 101our$projects_list="++GITWEB_LIST++"; 102 103# the width (in characters) of the projects list "Description" column 104our$projects_list_description_width=25; 105 106# default order of projects list 107# valid values are none, project, descr, owner, and age 108our$default_projects_order="project"; 109 110# show repository only if this file exists 111# (only effective if this variable evaluates to true) 112our$export_ok="++GITWEB_EXPORT_OK++"; 113 114# show repository only if this subroutine returns true 115# when given the path to the project, for example: 116# sub { return -e "$_[0]/git-daemon-export-ok"; } 117our$export_auth_hook=undef; 118 119# only allow viewing of repositories also shown on the overview page 120our$strict_export="++GITWEB_STRICT_EXPORT++"; 121 122# list of git base URLs used for URL to where fetch project from, 123# i.e. full URL is "$git_base_url/$project" 124our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 125 126# default blob_plain mimetype and default charset for text/plain blob 127our$default_blob_plain_mimetype='text/plain'; 128our$default_text_plain_charset=undef; 129 130# file to use for guessing MIME types before trying /etc/mime.types 131# (relative to the current git repository) 132our$mimetypes_file=undef; 133 134# assume this charset if line contains non-UTF-8 characters; 135# it should be valid encoding (see Encoding::Supported(3pm) for list), 136# for which encoding all byte sequences are valid, for example 137# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 138# could be even 'utf-8' for the old behavior) 139our$fallback_encoding='latin1'; 140 141# rename detection options for git-diff and git-diff-tree 142# - default is '-M', with the cost proportional to 143# (number of removed files) * (number of new files). 144# - more costly is '-C' (which implies '-M'), with the cost proportional to 145# (number of changed files + number of removed files) * (number of new files) 146# - even more costly is '-C', '--find-copies-harder' with cost 147# (number of files in the original tree) * (number of new files) 148# - one might want to include '-B' option, e.g. '-B', '-M' 149our@diff_opts= ('-M');# taken from git_commit 150 151# Disables features that would allow repository owners to inject script into 152# the gitweb domain. 153our$prevent_xss=0; 154 155# information about snapshot formats that gitweb is capable of serving 156our%known_snapshot_formats= ( 157# name => { 158# 'display' => display name, 159# 'type' => mime type, 160# 'suffix' => filename suffix, 161# 'format' => --format for git-archive, 162# 'compressor' => [compressor command and arguments] 163# (array reference, optional)} 164# 165'tgz'=> { 166'display'=>'tar.gz', 167'type'=>'application/x-gzip', 168'suffix'=>'.tar.gz', 169'format'=>'tar', 170'compressor'=> ['gzip']}, 171 172'tbz2'=> { 173'display'=>'tar.bz2', 174'type'=>'application/x-bzip2', 175'suffix'=>'.tar.bz2', 176'format'=>'tar', 177'compressor'=> ['bzip2']}, 178 179'zip'=> { 180'display'=>'zip', 181'type'=>'application/x-zip', 182'suffix'=>'.zip', 183'format'=>'zip'}, 184); 185 186# Aliases so we understand old gitweb.snapshot values in repository 187# configuration. 188our%known_snapshot_format_aliases= ( 189'gzip'=>'tgz', 190'bzip2'=>'tbz2', 191 192# backward compatibility: legacy gitweb config support 193'x-gzip'=>undef,'gz'=>undef, 194'x-bzip2'=>undef,'bz2'=>undef, 195'x-zip'=>undef,''=>undef, 196); 197 198# You define site-wide feature defaults here; override them with 199# $GITWEB_CONFIG as necessary. 200our%feature= ( 201# feature => { 202# 'sub' => feature-sub (subroutine), 203# 'override' => allow-override (boolean), 204# 'default' => [ default options...] (array reference)} 205# 206# if feature is overridable (it means that allow-override has true value), 207# then feature-sub will be called with default options as parameters; 208# return value of feature-sub indicates if to enable specified feature 209# 210# if there is no 'sub' key (no feature-sub), then feature cannot be 211# overriden 212# 213# use gitweb_get_feature(<feature>) to retrieve the <feature> value 214# (an array) or gitweb_check_feature(<feature>) to check if <feature> 215# is enabled 216 217# Enable the 'blame' blob view, showing the last commit that modified 218# each line in the file. This can be very CPU-intensive. 219 220# To enable system wide have in $GITWEB_CONFIG 221# $feature{'blame'}{'default'} = [1]; 222# To have project specific config enable override in $GITWEB_CONFIG 223# $feature{'blame'}{'override'} = 1; 224# and in project config gitweb.blame = 0|1; 225'blame'=> { 226'sub'=>sub{ feature_bool('blame',@_) }, 227'override'=>0, 228'default'=> [0]}, 229 230# Enable the 'snapshot' link, providing a compressed archive of any 231# tree. This can potentially generate high traffic if you have large 232# project. 233 234# Value is a list of formats defined in %known_snapshot_formats that 235# you wish to offer. 236# To disable system wide have in $GITWEB_CONFIG 237# $feature{'snapshot'}{'default'} = []; 238# To have project specific config enable override in $GITWEB_CONFIG 239# $feature{'snapshot'}{'override'} = 1; 240# and in project config, a comma-separated list of formats or "none" 241# to disable. Example: gitweb.snapshot = tbz2,zip; 242'snapshot'=> { 243'sub'=> \&feature_snapshot, 244'override'=>0, 245'default'=> ['tgz']}, 246 247# Enable text search, which will list the commits which match author, 248# committer or commit text to a given string. Enabled by default. 249# Project specific override is not supported. 250'search'=> { 251'override'=>0, 252'default'=> [1]}, 253 254# Enable grep search, which will list the files in currently selected 255# tree containing the given string. Enabled by default. This can be 256# potentially CPU-intensive, of course. 257 258# To enable system wide have in $GITWEB_CONFIG 259# $feature{'grep'}{'default'} = [1]; 260# To have project specific config enable override in $GITWEB_CONFIG 261# $feature{'grep'}{'override'} = 1; 262# and in project config gitweb.grep = 0|1; 263'grep'=> { 264'sub'=>sub{ feature_bool('grep',@_) }, 265'override'=>0, 266'default'=> [1]}, 267 268# Enable the pickaxe search, which will list the commits that modified 269# a given string in a file. This can be practical and quite faster 270# alternative to 'blame', but still potentially CPU-intensive. 271 272# To enable system wide have in $GITWEB_CONFIG 273# $feature{'pickaxe'}{'default'} = [1]; 274# To have project specific config enable override in $GITWEB_CONFIG 275# $feature{'pickaxe'}{'override'} = 1; 276# and in project config gitweb.pickaxe = 0|1; 277'pickaxe'=> { 278'sub'=>sub{ feature_bool('pickaxe',@_) }, 279'override'=>0, 280'default'=> [1]}, 281 282# Make gitweb use an alternative format of the URLs which can be 283# more readable and natural-looking: project name is embedded 284# directly in the path and the query string contains other 285# auxiliary information. All gitweb installations recognize 286# URL in either format; this configures in which formats gitweb 287# generates links. 288 289# To enable system wide have in $GITWEB_CONFIG 290# $feature{'pathinfo'}{'default'} = [1]; 291# Project specific override is not supported. 292 293# Note that you will need to change the default location of CSS, 294# favicon, logo and possibly other files to an absolute URL. Also, 295# if gitweb.cgi serves as your indexfile, you will need to force 296# $my_uri to contain the script name in your $GITWEB_CONFIG. 297'pathinfo'=> { 298'override'=>0, 299'default'=> [0]}, 300 301# Make gitweb consider projects in project root subdirectories 302# to be forks of existing projects. Given project $projname.git, 303# projects matching $projname/*.git will not be shown in the main 304# projects list, instead a '+' mark will be added to $projname 305# there and a 'forks' view will be enabled for the project, listing 306# all the forks. If project list is taken from a file, forks have 307# to be listed after the main project. 308 309# To enable system wide have in $GITWEB_CONFIG 310# $feature{'forks'}{'default'} = [1]; 311# Project specific override is not supported. 312'forks'=> { 313'override'=>0, 314'default'=> [0]}, 315 316# Insert custom links to the action bar of all project pages. 317# This enables you mainly to link to third-party scripts integrating 318# into gitweb; e.g. git-browser for graphical history representation 319# or custom web-based repository administration interface. 320 321# The 'default' value consists of a list of triplets in the form 322# (label, link, position) where position is the label after which 323# to insert the link and link is a format string where %n expands 324# to the project name, %f to the project path within the filesystem, 325# %h to the current hash (h gitweb parameter) and %b to the current 326# hash base (hb gitweb parameter); %% expands to %. 327 328# To enable system wide have in $GITWEB_CONFIG e.g. 329# $feature{'actions'}{'default'} = [('graphiclog', 330# '/git-browser/by-commit.html?r=%n', 'summary')]; 331# Project specific override is not supported. 332'actions'=> { 333'override'=>0, 334'default'=> []}, 335 336# Allow gitweb scan project content tags described in ctags/ 337# of project repository, and display the popular Web 2.0-ish 338# "tag cloud" near the project list. Note that this is something 339# COMPLETELY different from the normal Git tags. 340 341# gitweb by itself can show existing tags, but it does not handle 342# tagging itself; you need an external application for that. 343# For an example script, check Girocco's cgi/tagproj.cgi. 344# You may want to install the HTML::TagCloud Perl module to get 345# a pretty tag cloud instead of just a list of tags. 346 347# To enable system wide have in $GITWEB_CONFIG 348# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 349# Project specific override is not supported. 350'ctags'=> { 351'override'=>0, 352'default'=> [0]}, 353 354# The maximum number of patches in a patchset generated in patch 355# view. Set this to 0 or undef to disable patch view, or to a 356# negative number to remove any limit. 357 358# To disable system wide have in $GITWEB_CONFIG 359# $feature{'patches'}{'default'} = [0]; 360# To have project specific config enable override in $GITWEB_CONFIG 361# $feature{'patches'}{'override'} = 1; 362# and in project config gitweb.patches = 0|n; 363# where n is the maximum number of patches allowed in a patchset. 364'patches'=> { 365'sub'=> \&feature_patches, 366'override'=>0, 367'default'=> [16]}, 368); 369 370sub gitweb_get_feature { 371my($name) =@_; 372return unlessexists$feature{$name}; 373my($sub,$override,@defaults) = ( 374$feature{$name}{'sub'}, 375$feature{$name}{'override'}, 376@{$feature{$name}{'default'}}); 377if(!$override) {return@defaults; } 378if(!defined$sub) { 379warn"feature$nameis not overrideable"; 380return@defaults; 381} 382return$sub->(@defaults); 383} 384 385# A wrapper to check if a given feature is enabled. 386# With this, you can say 387# 388# my $bool_feat = gitweb_check_feature('bool_feat'); 389# gitweb_check_feature('bool_feat') or somecode; 390# 391# instead of 392# 393# my ($bool_feat) = gitweb_get_feature('bool_feat'); 394# (gitweb_get_feature('bool_feat'))[0] or somecode; 395# 396sub gitweb_check_feature { 397return(gitweb_get_feature(@_))[0]; 398} 399 400 401sub feature_bool { 402my$key=shift; 403my($val) = git_get_project_config($key,'--bool'); 404 405if(!defined$val) { 406return($_[0]); 407}elsif($valeq'true') { 408return(1); 409}elsif($valeq'false') { 410return(0); 411} 412} 413 414sub feature_snapshot { 415my(@fmts) =@_; 416 417my($val) = git_get_project_config('snapshot'); 418 419if($val) { 420@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 421} 422 423return@fmts; 424} 425 426sub feature_patches { 427my@val= (git_get_project_config('patches','--int')); 428 429if(@val) { 430return@val; 431} 432 433return($_[0]); 434} 435 436# checking HEAD file with -e is fragile if the repository was 437# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 438# and then pruned. 439sub check_head_link { 440my($dir) =@_; 441my$headfile="$dir/HEAD"; 442return((-e $headfile) || 443(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 444} 445 446sub check_export_ok { 447my($dir) =@_; 448return(check_head_link($dir) && 449(!$export_ok|| -e "$dir/$export_ok") && 450(!$export_auth_hook||$export_auth_hook->($dir))); 451} 452 453# process alternate names for backward compatibility 454# filter out unsupported (unknown) snapshot formats 455sub filter_snapshot_fmts { 456my@fmts=@_; 457 458@fmts=map{ 459exists$known_snapshot_format_aliases{$_} ? 460$known_snapshot_format_aliases{$_} :$_}@fmts; 461@fmts=grep{ 462exists$known_snapshot_formats{$_} }@fmts; 463} 464 465our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 466if(-e $GITWEB_CONFIG) { 467do$GITWEB_CONFIG; 468}else{ 469our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 470do$GITWEB_CONFIG_SYSTEMif-e $GITWEB_CONFIG_SYSTEM; 471} 472 473# version of the core git binary 474our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 475 476$projects_list||=$projectroot; 477 478# ====================================================================== 479# input validation and dispatch 480 481# input parameters can be collected from a variety of sources (presently, CGI 482# and PATH_INFO), so we define an %input_params hash that collects them all 483# together during validation: this allows subsequent uses (e.g. href()) to be 484# agnostic of the parameter origin 485 486our%input_params= (); 487 488# input parameters are stored with the long parameter name as key. This will 489# also be used in the href subroutine to convert parameters to their CGI 490# equivalent, and since the href() usage is the most frequent one, we store 491# the name -> CGI key mapping here, instead of the reverse. 492# 493# XXX: Warning: If you touch this, check the search form for updating, 494# too. 495 496our@cgi_param_mapping= ( 497 project =>"p", 498 action =>"a", 499 file_name =>"f", 500 file_parent =>"fp", 501 hash =>"h", 502 hash_parent =>"hp", 503 hash_base =>"hb", 504 hash_parent_base =>"hpb", 505 page =>"pg", 506 order =>"o", 507 searchtext =>"s", 508 searchtype =>"st", 509 snapshot_format =>"sf", 510 extra_options =>"opt", 511 search_use_regexp =>"sr", 512); 513our%cgi_param_mapping=@cgi_param_mapping; 514 515# we will also need to know the possible actions, for validation 516our%actions= ( 517"blame"=> \&git_blame, 518"blobdiff"=> \&git_blobdiff, 519"blobdiff_plain"=> \&git_blobdiff_plain, 520"blob"=> \&git_blob, 521"blob_plain"=> \&git_blob_plain, 522"commitdiff"=> \&git_commitdiff, 523"commitdiff_plain"=> \&git_commitdiff_plain, 524"commit"=> \&git_commit, 525"forks"=> \&git_forks, 526"heads"=> \&git_heads, 527"history"=> \&git_history, 528"log"=> \&git_log, 529"patch"=> \&git_patch, 530"patches"=> \&git_patches, 531"rss"=> \&git_rss, 532"atom"=> \&git_atom, 533"search"=> \&git_search, 534"search_help"=> \&git_search_help, 535"shortlog"=> \&git_shortlog, 536"summary"=> \&git_summary, 537"tag"=> \&git_tag, 538"tags"=> \&git_tags, 539"tree"=> \&git_tree, 540"snapshot"=> \&git_snapshot, 541"object"=> \&git_object, 542# those below don't need $project 543"opml"=> \&git_opml, 544"project_list"=> \&git_project_list, 545"project_index"=> \&git_project_index, 546); 547 548# finally, we have the hash of allowed extra_options for the commands that 549# allow them 550our%allowed_options= ( 551"--no-merges"=> [qw(rss atom log shortlog history)], 552); 553 554# fill %input_params with the CGI parameters. All values except for 'opt' 555# should be single values, but opt can be an array. We should probably 556# build an array of parameters that can be multi-valued, but since for the time 557# being it's only this one, we just single it out 558while(my($name,$symbol) =each%cgi_param_mapping) { 559if($symboleq'opt') { 560$input_params{$name} = [$cgi->param($symbol) ]; 561}else{ 562$input_params{$name} =$cgi->param($symbol); 563} 564} 565 566# now read PATH_INFO and update the parameter list for missing parameters 567sub evaluate_path_info { 568return ifdefined$input_params{'project'}; 569return if!$path_info; 570$path_info=~ s,^/+,,; 571return if!$path_info; 572 573# find which part of PATH_INFO is project 574my$project=$path_info; 575$project=~ s,/+$,,; 576while($project&& !check_head_link("$projectroot/$project")) { 577$project=~ s,/*[^/]*$,,; 578} 579return unless$project; 580$input_params{'project'} =$project; 581 582# do not change any parameters if an action is given using the query string 583return if$input_params{'action'}; 584$path_info=~ s,^\Q$project\E/*,,; 585 586# next, check if we have an action 587my$action=$path_info; 588$action=~ s,/.*$,,; 589if(exists$actions{$action}) { 590$path_info=~ s,^$action/*,,; 591$input_params{'action'} =$action; 592} 593 594# list of actions that want hash_base instead of hash, but can have no 595# pathname (f) parameter 596my@wants_base= ( 597'tree', 598'history', 599); 600 601# we want to catch 602# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 603my($parentrefname,$parentpathname,$refname,$pathname) = 604($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/); 605 606# first, analyze the 'current' part 607if(defined$pathname) { 608# we got "branch:filename" or "branch:dir/" 609# we could use git_get_type(branch:pathname), but: 610# - it needs $git_dir 611# - it does a git() call 612# - the convention of terminating directories with a slash 613# makes it superfluous 614# - embedding the action in the PATH_INFO would make it even 615# more superfluous 616$pathname=~ s,^/+,,; 617if(!$pathname||substr($pathname, -1)eq"/") { 618$input_params{'action'} ||="tree"; 619$pathname=~ s,/$,,; 620}else{ 621# the default action depends on whether we had parent info 622# or not 623if($parentrefname) { 624$input_params{'action'} ||="blobdiff_plain"; 625}else{ 626$input_params{'action'} ||="blob_plain"; 627} 628} 629$input_params{'hash_base'} ||=$refname; 630$input_params{'file_name'} ||=$pathname; 631}elsif(defined$refname) { 632# we got "branch". In this case we have to choose if we have to 633# set hash or hash_base. 634# 635# Most of the actions without a pathname only want hash to be 636# set, except for the ones specified in @wants_base that want 637# hash_base instead. It should also be noted that hand-crafted 638# links having 'history' as an action and no pathname or hash 639# set will fail, but that happens regardless of PATH_INFO. 640$input_params{'action'} ||="shortlog"; 641if(grep{$_eq$input_params{'action'} }@wants_base) { 642$input_params{'hash_base'} ||=$refname; 643}else{ 644$input_params{'hash'} ||=$refname; 645} 646} 647 648# next, handle the 'parent' part, if present 649if(defined$parentrefname) { 650# a missing pathspec defaults to the 'current' filename, allowing e.g. 651# someproject/blobdiff/oldrev..newrev:/filename 652if($parentpathname) { 653$parentpathname=~ s,^/+,,; 654$parentpathname=~ s,/$,,; 655$input_params{'file_parent'} ||=$parentpathname; 656}else{ 657$input_params{'file_parent'} ||=$input_params{'file_name'}; 658} 659# we assume that hash_parent_base is wanted if a path was specified, 660# or if the action wants hash_base instead of hash 661if(defined$input_params{'file_parent'} || 662grep{$_eq$input_params{'action'} }@wants_base) { 663$input_params{'hash_parent_base'} ||=$parentrefname; 664}else{ 665$input_params{'hash_parent'} ||=$parentrefname; 666} 667} 668 669# for the snapshot action, we allow URLs in the form 670# $project/snapshot/$hash.ext 671# where .ext determines the snapshot and gets removed from the 672# passed $refname to provide the $hash. 673# 674# To be able to tell that $refname includes the format extension, we 675# require the following two conditions to be satisfied: 676# - the hash input parameter MUST have been set from the $refname part 677# of the URL (i.e. they must be equal) 678# - the snapshot format MUST NOT have been defined already (e.g. from 679# CGI parameter sf) 680# It's also useless to try any matching unless $refname has a dot, 681# so we check for that too 682if(defined$input_params{'action'} && 683$input_params{'action'}eq'snapshot'&& 684defined$refname&&index($refname,'.') != -1&& 685$refnameeq$input_params{'hash'} && 686!defined$input_params{'snapshot_format'}) { 687# We loop over the known snapshot formats, checking for 688# extensions. Allowed extensions are both the defined suffix 689# (which includes the initial dot already) and the snapshot 690# format key itself, with a prepended dot 691while(my($fmt,$opt) =each%known_snapshot_formats) { 692my$hash=$refname; 693unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 694next; 695} 696my$sfx=$1; 697# a valid suffix was found, so set the snapshot format 698# and reset the hash parameter 699$input_params{'snapshot_format'} =$fmt; 700$input_params{'hash'} =$hash; 701# we also set the format suffix to the one requested 702# in the URL: this way a request for e.g. .tgz returns 703# a .tgz instead of a .tar.gz 704$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 705last; 706} 707} 708} 709evaluate_path_info(); 710 711our$action=$input_params{'action'}; 712if(defined$action) { 713if(!validate_action($action)) { 714 die_error(400,"Invalid action parameter"); 715} 716} 717 718# parameters which are pathnames 719our$project=$input_params{'project'}; 720if(defined$project) { 721if(!validate_project($project)) { 722undef$project; 723 die_error(404,"No such project"); 724} 725} 726 727our$file_name=$input_params{'file_name'}; 728if(defined$file_name) { 729if(!validate_pathname($file_name)) { 730 die_error(400,"Invalid file parameter"); 731} 732} 733 734our$file_parent=$input_params{'file_parent'}; 735if(defined$file_parent) { 736if(!validate_pathname($file_parent)) { 737 die_error(400,"Invalid file parent parameter"); 738} 739} 740 741# parameters which are refnames 742our$hash=$input_params{'hash'}; 743if(defined$hash) { 744if(!validate_refname($hash)) { 745 die_error(400,"Invalid hash parameter"); 746} 747} 748 749our$hash_parent=$input_params{'hash_parent'}; 750if(defined$hash_parent) { 751if(!validate_refname($hash_parent)) { 752 die_error(400,"Invalid hash parent parameter"); 753} 754} 755 756our$hash_base=$input_params{'hash_base'}; 757if(defined$hash_base) { 758if(!validate_refname($hash_base)) { 759 die_error(400,"Invalid hash base parameter"); 760} 761} 762 763our@extra_options= @{$input_params{'extra_options'}}; 764# @extra_options is always defined, since it can only be (currently) set from 765# CGI, and $cgi->param() returns the empty array in array context if the param 766# is not set 767foreachmy$opt(@extra_options) { 768if(not exists$allowed_options{$opt}) { 769 die_error(400,"Invalid option parameter"); 770} 771if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 772 die_error(400,"Invalid option parameter for this action"); 773} 774} 775 776our$hash_parent_base=$input_params{'hash_parent_base'}; 777if(defined$hash_parent_base) { 778if(!validate_refname($hash_parent_base)) { 779 die_error(400,"Invalid hash parent base parameter"); 780} 781} 782 783# other parameters 784our$page=$input_params{'page'}; 785if(defined$page) { 786if($page=~m/[^0-9]/) { 787 die_error(400,"Invalid page parameter"); 788} 789} 790 791our$searchtype=$input_params{'searchtype'}; 792if(defined$searchtype) { 793if($searchtype=~m/[^a-z]/) { 794 die_error(400,"Invalid searchtype parameter"); 795} 796} 797 798our$search_use_regexp=$input_params{'search_use_regexp'}; 799 800our$searchtext=$input_params{'searchtext'}; 801our$search_regexp; 802if(defined$searchtext) { 803if(length($searchtext) <2) { 804 die_error(403,"At least two characters are required for search parameter"); 805} 806$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 807} 808 809# path to the current git repository 810our$git_dir; 811$git_dir="$projectroot/$project"if$project; 812 813# list of supported snapshot formats 814our@snapshot_fmts= gitweb_get_feature('snapshot'); 815@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts); 816 817# dispatch 818if(!defined$action) { 819if(defined$hash) { 820$action= git_get_type($hash); 821}elsif(defined$hash_base&&defined$file_name) { 822$action= git_get_type("$hash_base:$file_name"); 823}elsif(defined$project) { 824$action='summary'; 825}else{ 826$action='project_list'; 827} 828} 829if(!defined($actions{$action})) { 830 die_error(400,"Unknown action"); 831} 832if($action!~m/^(?:opml|project_list|project_index)$/&& 833!$project) { 834 die_error(400,"Project needed"); 835} 836$actions{$action}->(); 837exit; 838 839## ====================================================================== 840## action links 841 842sub href { 843my%params=@_; 844# default is to use -absolute url() i.e. $my_uri 845my$href=$params{-full} ?$my_url:$my_uri; 846 847$params{'project'} =$projectunlessexists$params{'project'}; 848 849if($params{-replay}) { 850while(my($name,$symbol) =each%cgi_param_mapping) { 851if(!exists$params{$name}) { 852$params{$name} =$input_params{$name}; 853} 854} 855} 856 857my$use_pathinfo= gitweb_check_feature('pathinfo'); 858if($use_pathinfoand defined$params{'project'}) { 859# try to put as many parameters as possible in PATH_INFO: 860# - project name 861# - action 862# - hash_parent or hash_parent_base:/file_parent 863# - hash or hash_base:/filename 864# - the snapshot_format as an appropriate suffix 865 866# When the script is the root DirectoryIndex for the domain, 867# $href here would be something like http://gitweb.example.com/ 868# Thus, we strip any trailing / from $href, to spare us double 869# slashes in the final URL 870$href=~ s,/$,,; 871 872# Then add the project name, if present 873$href.="/".esc_url($params{'project'}); 874delete$params{'project'}; 875 876# since we destructively absorb parameters, we keep this 877# boolean that remembers if we're handling a snapshot 878my$is_snapshot=$params{'action'}eq'snapshot'; 879 880# Summary just uses the project path URL, any other action is 881# added to the URL 882if(defined$params{'action'}) { 883$href.="/".esc_url($params{'action'})unless$params{'action'}eq'summary'; 884delete$params{'action'}; 885} 886 887# Next, we put hash_parent_base:/file_parent..hash_base:/file_name, 888# stripping nonexistent or useless pieces 889$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'} 890||$params{'hash_parent'} ||$params{'hash'}); 891if(defined$params{'hash_base'}) { 892if(defined$params{'hash_parent_base'}) { 893$href.= esc_url($params{'hash_parent_base'}); 894# skip the file_parent if it's the same as the file_name 895delete$params{'file_parent'}if$params{'file_parent'}eq$params{'file_name'}; 896if(defined$params{'file_parent'} &&$params{'file_parent'} !~/\.\./) { 897$href.=":/".esc_url($params{'file_parent'}); 898delete$params{'file_parent'}; 899} 900$href.=".."; 901delete$params{'hash_parent'}; 902delete$params{'hash_parent_base'}; 903}elsif(defined$params{'hash_parent'}) { 904$href.= esc_url($params{'hash_parent'}).".."; 905delete$params{'hash_parent'}; 906} 907 908$href.= esc_url($params{'hash_base'}); 909if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) { 910$href.=":/".esc_url($params{'file_name'}); 911delete$params{'file_name'}; 912} 913delete$params{'hash'}; 914delete$params{'hash_base'}; 915}elsif(defined$params{'hash'}) { 916$href.= esc_url($params{'hash'}); 917delete$params{'hash'}; 918} 919 920# If the action was a snapshot, we can absorb the 921# snapshot_format parameter too 922if($is_snapshot) { 923my$fmt=$params{'snapshot_format'}; 924# snapshot_format should always be defined when href() 925# is called, but just in case some code forgets, we 926# fall back to the default 927$fmt||=$snapshot_fmts[0]; 928$href.=$known_snapshot_formats{$fmt}{'suffix'}; 929delete$params{'snapshot_format'}; 930} 931} 932 933# now encode the parameters explicitly 934my@result= (); 935for(my$i=0;$i<@cgi_param_mapping;$i+=2) { 936my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]); 937if(defined$params{$name}) { 938if(ref($params{$name})eq"ARRAY") { 939foreachmy$par(@{$params{$name}}) { 940push@result,$symbol."=". esc_param($par); 941} 942}else{ 943push@result,$symbol."=". esc_param($params{$name}); 944} 945} 946} 947$href.="?".join(';',@result)ifscalar@result; 948 949return$href; 950} 951 952 953## ====================================================================== 954## validation, quoting/unquoting and escaping 955 956sub validate_action { 957my$input=shift||returnundef; 958returnundefunlessexists$actions{$input}; 959return$input; 960} 961 962sub validate_project { 963my$input=shift||returnundef; 964if(!validate_pathname($input) || 965!(-d "$projectroot/$input") || 966!check_export_ok("$projectroot/$input") || 967($strict_export&& !project_in_list($input))) { 968returnundef; 969}else{ 970return$input; 971} 972} 973 974sub validate_pathname { 975my$input=shift||returnundef; 976 977# no '.' or '..' as elements of path, i.e. no '.' nor '..' 978# at the beginning, at the end, and between slashes. 979# also this catches doubled slashes 980if($input=~m!(^|/)(|\.|\.\.)(/|$)!) { 981returnundef; 982} 983# no null characters 984if($input=~m!\0!) { 985returnundef; 986} 987return$input; 988} 989 990sub validate_refname { 991my$input=shift||returnundef; 992 993# textual hashes are O.K. 994if($input=~m/^[0-9a-fA-F]{40}$/) { 995return$input; 996} 997# it must be correct pathname 998$input= validate_pathname($input) 999orreturnundef;1000# restrictions on ref name according to git-check-ref-format1001if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1002returnundef;1003}1004return$input;1005}10061007# decode sequences of octets in utf8 into Perl's internal form,1008# which is utf-8 with utf8 flag set if needed. gitweb writes out1009# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1010sub to_utf8 {1011my$str=shift;1012if(utf8::valid($str)) {1013 utf8::decode($str);1014return$str;1015}else{1016return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1017}1018}10191020# quote unsafe chars, but keep the slash, even when it's not1021# correct, but quoted slashes look too horrible in bookmarks1022sub esc_param {1023my$str=shift;1024$str=~s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X",ord($1))/eg;1025$str=~s/\+/%2B/g;1026$str=~s/ /\+/g;1027return$str;1028}10291030# quote unsafe chars in whole URL, so some charactrs cannot be quoted1031sub esc_url {1032my$str=shift;1033$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X",ord($1))/eg;1034$str=~s/\+/%2B/g;1035$str=~s/ /\+/g;1036return$str;1037}10381039# replace invalid utf8 character with SUBSTITUTION sequence1040sub esc_html {1041my$str=shift;1042my%opts=@_;10431044$str= to_utf8($str);1045$str=$cgi->escapeHTML($str);1046if($opts{'-nbsp'}) {1047$str=~s/ / /g;1048}1049$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1050return$str;1051}10521053# quote control characters and escape filename to HTML1054sub esc_path {1055my$str=shift;1056my%opts=@_;10571058$str= to_utf8($str);1059$str=$cgi->escapeHTML($str);1060if($opts{'-nbsp'}) {1061$str=~s/ / /g;1062}1063$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1064return$str;1065}10661067# Make control characters "printable", using character escape codes (CEC)1068sub quot_cec {1069my$cntrl=shift;1070my%opts=@_;1071my%es= (# character escape codes, aka escape sequences1072"\t"=>'\t',# tab (HT)1073"\n"=>'\n',# line feed (LF)1074"\r"=>'\r',# carrige return (CR)1075"\f"=>'\f',# form feed (FF)1076"\b"=>'\b',# backspace (BS)1077"\a"=>'\a',# alarm (bell) (BEL)1078"\e"=>'\e',# escape (ESC)1079"\013"=>'\v',# vertical tab (VT)1080"\000"=>'\0',# nul character (NUL)1081);1082my$chr= ( (exists$es{$cntrl})1083?$es{$cntrl}1084:sprintf('\%2x',ord($cntrl)) );1085if($opts{-nohtml}) {1086return$chr;1087}else{1088return"<span class=\"cntrl\">$chr</span>";1089}1090}10911092# Alternatively use unicode control pictures codepoints,1093# Unicode "printable representation" (PR)1094sub quot_upr {1095my$cntrl=shift;1096my%opts=@_;10971098my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1099if($opts{-nohtml}) {1100return$chr;1101}else{1102return"<span class=\"cntrl\">$chr</span>";1103}1104}11051106# git may return quoted and escaped filenames1107sub unquote {1108my$str=shift;11091110sub unq {1111my$seq=shift;1112my%es= (# character escape codes, aka escape sequences1113't'=>"\t",# tab (HT, TAB)1114'n'=>"\n",# newline (NL)1115'r'=>"\r",# return (CR)1116'f'=>"\f",# form feed (FF)1117'b'=>"\b",# backspace (BS)1118'a'=>"\a",# alarm (bell) (BEL)1119'e'=>"\e",# escape (ESC)1120'v'=>"\013",# vertical tab (VT)1121);11221123if($seq=~m/^[0-7]{1,3}$/) {1124# octal char sequence1125returnchr(oct($seq));1126}elsif(exists$es{$seq}) {1127# C escape sequence, aka character escape code1128return$es{$seq};1129}1130# quoted ordinary character1131return$seq;1132}11331134if($str=~m/^"(.*)"$/) {1135# needs unquoting1136$str=$1;1137$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1138}1139return$str;1140}11411142# escape tabs (convert tabs to spaces)1143sub untabify {1144my$line=shift;11451146while((my$pos=index($line,"\t")) != -1) {1147if(my$count= (8- ($pos%8))) {1148my$spaces=' ' x $count;1149$line=~s/\t/$spaces/;1150}1151}11521153return$line;1154}11551156sub project_in_list {1157my$project=shift;1158my@list= git_get_projects_list();1159return@list&&scalar(grep{$_->{'path'}eq$project}@list);1160}11611162## ----------------------------------------------------------------------1163## HTML aware string manipulation11641165# Try to chop given string on a word boundary between position1166# $len and $len+$add_len. If there is no word boundary there,1167# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1168# (marking chopped part) would be longer than given string.1169sub chop_str {1170my$str=shift;1171my$len=shift;1172my$add_len=shift||10;1173my$where=shift||'right';# 'left' | 'center' | 'right'11741175# Make sure perl knows it is utf8 encoded so we don't1176# cut in the middle of a utf8 multibyte char.1177$str= to_utf8($str);11781179# allow only $len chars, but don't cut a word if it would fit in $add_len1180# if it doesn't fit, cut it if it's still longer than the dots we would add1181# remove chopped character entities entirely11821183# when chopping in the middle, distribute $len into left and right part1184# return early if chopping wouldn't make string shorter1185if($whereeq'center') {1186return$strif($len+5>=length($str));# filler is length 51187$len=int($len/2);1188}else{1189return$strif($len+4>=length($str));# filler is length 41190}11911192# regexps: ending and beginning with word part up to $add_len1193my$endre=qr/.{$len}\w{0,$add_len}/;1194my$begre=qr/\w{0,$add_len}.{$len}/;11951196if($whereeq'left') {1197$str=~m/^(.*?)($begre)$/;1198my($lead,$body) = ($1,$2);1199if(length($lead) >4) {1200$body=~s/^[^;]*;//if($lead=~m/&[^;]*$/);1201$lead=" ...";1202}1203return"$lead$body";12041205}elsif($whereeq'center') {1206$str=~m/^($endre)(.*)$/;1207my($left,$str) = ($1,$2);1208$str=~m/^(.*?)($begre)$/;1209my($mid,$right) = ($1,$2);1210if(length($mid) >5) {1211$left=~s/&[^;]*$//;1212$right=~s/^[^;]*;//if($mid=~m/&[^;]*$/);1213$mid=" ... ";1214}1215return"$left$mid$right";12161217}else{1218$str=~m/^($endre)(.*)$/;1219my$body=$1;1220my$tail=$2;1221if(length($tail) >4) {1222$body=~s/&[^;]*$//;1223$tail="... ";1224}1225return"$body$tail";1226}1227}12281229# takes the same arguments as chop_str, but also wraps a <span> around the1230# result with a title attribute if it does get chopped. Additionally, the1231# string is HTML-escaped.1232sub chop_and_escape_str {1233my($str) =@_;12341235my$chopped= chop_str(@_);1236if($choppedeq$str) {1237return esc_html($chopped);1238}else{1239$str=~s/[[:cntrl:]]/?/g;1240return$cgi->span({-title=>$str}, esc_html($chopped));1241}1242}12431244## ----------------------------------------------------------------------1245## functions returning short strings12461247# CSS class for given age value (in seconds)1248sub age_class {1249my$age=shift;12501251if(!defined$age) {1252return"noage";1253}elsif($age<60*60*2) {1254return"age0";1255}elsif($age<60*60*24*2) {1256return"age1";1257}else{1258return"age2";1259}1260}12611262# convert age in seconds to "nn units ago" string1263sub age_string {1264my$age=shift;1265my$age_str;12661267if($age>60*60*24*365*2) {1268$age_str= (int$age/60/60/24/365);1269$age_str.=" years ago";1270}elsif($age>60*60*24*(365/12)*2) {1271$age_str=int$age/60/60/24/(365/12);1272$age_str.=" months ago";1273}elsif($age>60*60*24*7*2) {1274$age_str=int$age/60/60/24/7;1275$age_str.=" weeks ago";1276}elsif($age>60*60*24*2) {1277$age_str=int$age/60/60/24;1278$age_str.=" days ago";1279}elsif($age>60*60*2) {1280$age_str=int$age/60/60;1281$age_str.=" hours ago";1282}elsif($age>60*2) {1283$age_str=int$age/60;1284$age_str.=" min ago";1285}elsif($age>2) {1286$age_str=int$age;1287$age_str.=" sec ago";1288}else{1289$age_str.=" right now";1290}1291return$age_str;1292}12931294useconstant{1295 S_IFINVALID =>0030000,1296 S_IFGITLINK =>0160000,1297};12981299# submodule/subproject, a commit object reference1300sub S_ISGITLINK {1301my$mode=shift;13021303return(($mode& S_IFMT) == S_IFGITLINK)1304}13051306# convert file mode in octal to symbolic file mode string1307sub mode_str {1308my$mode=oct shift;13091310if(S_ISGITLINK($mode)) {1311return'm---------';1312}elsif(S_ISDIR($mode& S_IFMT)) {1313return'drwxr-xr-x';1314}elsif(S_ISLNK($mode)) {1315return'lrwxrwxrwx';1316}elsif(S_ISREG($mode)) {1317# git cares only about the executable bit1318if($mode& S_IXUSR) {1319return'-rwxr-xr-x';1320}else{1321return'-rw-r--r--';1322};1323}else{1324return'----------';1325}1326}13271328# convert file mode in octal to file type string1329sub file_type {1330my$mode=shift;13311332if($mode!~m/^[0-7]+$/) {1333return$mode;1334}else{1335$mode=oct$mode;1336}13371338if(S_ISGITLINK($mode)) {1339return"submodule";1340}elsif(S_ISDIR($mode& S_IFMT)) {1341return"directory";1342}elsif(S_ISLNK($mode)) {1343return"symlink";1344}elsif(S_ISREG($mode)) {1345return"file";1346}else{1347return"unknown";1348}1349}13501351# convert file mode in octal to file type description string1352sub file_type_long {1353my$mode=shift;13541355if($mode!~m/^[0-7]+$/) {1356return$mode;1357}else{1358$mode=oct$mode;1359}13601361if(S_ISGITLINK($mode)) {1362return"submodule";1363}elsif(S_ISDIR($mode& S_IFMT)) {1364return"directory";1365}elsif(S_ISLNK($mode)) {1366return"symlink";1367}elsif(S_ISREG($mode)) {1368if($mode& S_IXUSR) {1369return"executable";1370}else{1371return"file";1372};1373}else{1374return"unknown";1375}1376}137713781379## ----------------------------------------------------------------------1380## functions returning short HTML fragments, or transforming HTML fragments1381## which don't belong to other sections13821383# format line of commit message.1384sub format_log_line_html {1385my$line=shift;13861387$line= esc_html($line, -nbsp=>1);1388$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1389$cgi->a({-href => href(action=>"object", hash=>$1),1390-class=>"text"},$1);1391}eg;13921393return$line;1394}13951396# format marker of refs pointing to given object13971398# the destination action is chosen based on object type and current context:1399# - for annotated tags, we choose the tag view unless it's the current view1400# already, in which case we go to shortlog view1401# - for other refs, we keep the current view if we're in history, shortlog or1402# log view, and select shortlog otherwise1403sub format_ref_marker {1404my($refs,$id) =@_;1405my$markers='';14061407if(defined$refs->{$id}) {1408foreachmy$ref(@{$refs->{$id}}) {1409# this code exploits the fact that non-lightweight tags are the1410# only indirect objects, and that they are the only objects for which1411# we want to use tag instead of shortlog as action1412my($type,$name) =qw();1413my$indirect= ($ref=~s/\^\{\}$//);1414# e.g. tags/v2.6.11 or heads/next1415if($ref=~m!^(.*?)s?/(.*)$!) {1416$type=$1;1417$name=$2;1418}else{1419$type="ref";1420$name=$ref;1421}14221423my$class=$type;1424$class.=" indirect"if$indirect;14251426my$dest_action="shortlog";14271428if($indirect) {1429$dest_action="tag"unless$actioneq"tag";1430}elsif($action=~/^(history|(short)?log)$/) {1431$dest_action=$action;1432}14331434my$dest="";1435$dest.="refs/"unless$ref=~ m!^refs/!;1436$dest.=$ref;14371438my$link=$cgi->a({1439-href => href(1440 action=>$dest_action,1441 hash=>$dest1442)},$name);14431444$markers.=" <span class=\"$class\"title=\"$ref\">".1445$link."</span>";1446}1447}14481449if($markers) {1450return' <span class="refs">'.$markers.'</span>';1451}else{1452return"";1453}1454}14551456# format, perhaps shortened and with markers, title line1457sub format_subject_html {1458my($long,$short,$href,$extra) =@_;1459$extra=''unlessdefined($extra);14601461if(length($short) <length($long)) {1462$long=~s/[[:cntrl:]]/?/g;1463return$cgi->a({-href =>$href, -class=>"list subject",1464-title => to_utf8($long)},1465 esc_html($short) .$extra);1466}else{1467return$cgi->a({-href =>$href, -class=>"list subject"},1468 esc_html($long) .$extra);1469}1470}14711472# format the author name of the given commit with the given tag1473# the author name is chopped and escaped according to the other1474# optional parameters (see chop_str).1475sub format_author_html {1476my$tag=shift;1477my$co=shift;1478my$author= chop_and_escape_str($co->{'author_name'},@_);1479return"<$tagclass=\"author\">".$author."</$tag>";1480}14811482# format git diff header line, i.e. "diff --(git|combined|cc) ..."1483sub format_git_diff_header_line {1484my$line=shift;1485my$diffinfo=shift;1486my($from,$to) =@_;14871488if($diffinfo->{'nparents'}) {1489# combined diff1490$line=~s!^(diff (.*?) )"?.*$!$1!;1491if($to->{'href'}) {1492$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1493 esc_path($to->{'file'}));1494}else{# file was deleted (no href)1495$line.= esc_path($to->{'file'});1496}1497}else{1498# "ordinary" diff1499$line=~s!^(diff (.*?) )"?a/.*$!$1!;1500if($from->{'href'}) {1501$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1502'a/'. esc_path($from->{'file'}));1503}else{# file was added (no href)1504$line.='a/'. esc_path($from->{'file'});1505}1506$line.=' ';1507if($to->{'href'}) {1508$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1509'b/'. esc_path($to->{'file'}));1510}else{# file was deleted1511$line.='b/'. esc_path($to->{'file'});1512}1513}15141515return"<div class=\"diff header\">$line</div>\n";1516}15171518# format extended diff header line, before patch itself1519sub format_extended_diff_header_line {1520my$line=shift;1521my$diffinfo=shift;1522my($from,$to) =@_;15231524# match <path>1525if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1526$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1527 esc_path($from->{'file'}));1528}1529if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1530$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1531 esc_path($to->{'file'}));1532}1533# match single <mode>1534if($line=~m/\s(\d{6})$/) {1535$line.='<span class="info"> ('.1536 file_type_long($1) .1537')</span>';1538}1539# match <hash>1540if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1541# can match only for combined diff1542$line='index ';1543for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1544if($from->{'href'}[$i]) {1545$line.=$cgi->a({-href=>$from->{'href'}[$i],1546-class=>"hash"},1547substr($diffinfo->{'from_id'}[$i],0,7));1548}else{1549$line.='0' x 7;1550}1551# separator1552$line.=','if($i<$diffinfo->{'nparents'} -1);1553}1554$line.='..';1555if($to->{'href'}) {1556$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1557substr($diffinfo->{'to_id'},0,7));1558}else{1559$line.='0' x 7;1560}15611562}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1563# can match only for ordinary diff1564my($from_link,$to_link);1565if($from->{'href'}) {1566$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1567substr($diffinfo->{'from_id'},0,7));1568}else{1569$from_link='0' x 7;1570}1571if($to->{'href'}) {1572$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1573substr($diffinfo->{'to_id'},0,7));1574}else{1575$to_link='0' x 7;1576}1577my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1578$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1579}15801581return$line."<br/>\n";1582}15831584# format from-file/to-file diff header1585sub format_diff_from_to_header {1586my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1587my$line;1588my$result='';15891590$line=$from_line;1591#assert($line =~ m/^---/) if DEBUG;1592# no extra formatting for "^--- /dev/null"1593if(!$diffinfo->{'nparents'}) {1594# ordinary (single parent) diff1595if($line=~m!^--- "?a/!) {1596if($from->{'href'}) {1597$line='--- a/'.1598$cgi->a({-href=>$from->{'href'}, -class=>"path"},1599 esc_path($from->{'file'}));1600}else{1601$line='--- a/'.1602 esc_path($from->{'file'});1603}1604}1605$result.= qq!<div class="diff from_file">$line</div>\n!;16061607}else{1608# combined diff (merge commit)1609for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1610if($from->{'href'}[$i]) {1611$line='--- '.1612$cgi->a({-href=>href(action=>"blobdiff",1613 hash_parent=>$diffinfo->{'from_id'}[$i],1614 hash_parent_base=>$parents[$i],1615 file_parent=>$from->{'file'}[$i],1616 hash=>$diffinfo->{'to_id'},1617 hash_base=>$hash,1618 file_name=>$to->{'file'}),1619-class=>"path",1620-title=>"diff". ($i+1)},1621$i+1) .1622'/'.1623$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1624 esc_path($from->{'file'}[$i]));1625}else{1626$line='--- /dev/null';1627}1628$result.= qq!<div class="diff from_file">$line</div>\n!;1629}1630}16311632$line=$to_line;1633#assert($line =~ m/^\+\+\+/) if DEBUG;1634# no extra formatting for "^+++ /dev/null"1635if($line=~m!^\+\+\+ "?b/!) {1636if($to->{'href'}) {1637$line='+++ b/'.1638$cgi->a({-href=>$to->{'href'}, -class=>"path"},1639 esc_path($to->{'file'}));1640}else{1641$line='+++ b/'.1642 esc_path($to->{'file'});1643}1644}1645$result.= qq!<div class="diff to_file">$line</div>\n!;16461647return$result;1648}16491650# create note for patch simplified by combined diff1651sub format_diff_cc_simplified {1652my($diffinfo,@parents) =@_;1653my$result='';16541655$result.="<div class=\"diff header\">".1656"diff --cc ";1657if(!is_deleted($diffinfo)) {1658$result.=$cgi->a({-href => href(action=>"blob",1659 hash_base=>$hash,1660 hash=>$diffinfo->{'to_id'},1661 file_name=>$diffinfo->{'to_file'}),1662-class=>"path"},1663 esc_path($diffinfo->{'to_file'}));1664}else{1665$result.= esc_path($diffinfo->{'to_file'});1666}1667$result.="</div>\n".# class="diff header"1668"<div class=\"diff nodifferences\">".1669"Simple merge".1670"</div>\n";# class="diff nodifferences"16711672return$result;1673}16741675# format patch (diff) line (not to be used for diff headers)1676sub format_diff_line {1677my$line=shift;1678my($from,$to) =@_;1679my$diff_class="";16801681chomp$line;16821683if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1684# combined diff1685my$prefix=substr($line,0,scalar@{$from->{'href'}});1686if($line=~m/^\@{3}/) {1687$diff_class=" chunk_header";1688}elsif($line=~m/^\\/) {1689$diff_class=" incomplete";1690}elsif($prefix=~tr/+/+/) {1691$diff_class=" add";1692}elsif($prefix=~tr/-/-/) {1693$diff_class=" rem";1694}1695}else{1696# assume ordinary diff1697my$char=substr($line,0,1);1698if($chareq'+') {1699$diff_class=" add";1700}elsif($chareq'-') {1701$diff_class=" rem";1702}elsif($chareq'@') {1703$diff_class=" chunk_header";1704}elsif($chareq"\\") {1705$diff_class=" incomplete";1706}1707}1708$line= untabify($line);1709if($from&&$to&&$line=~m/^\@{2} /) {1710my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1711$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;17121713$from_lines=0unlessdefined$from_lines;1714$to_lines=0unlessdefined$to_lines;17151716if($from->{'href'}) {1717$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1718-class=>"list"},$from_text);1719}1720if($to->{'href'}) {1721$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1722-class=>"list"},$to_text);1723}1724$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1725"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1726return"<div class=\"diff$diff_class\">$line</div>\n";1727}elsif($from&&$to&&$line=~m/^\@{3}/) {1728my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1729my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);17301731@from_text=split(' ',$ranges);1732for(my$i=0;$i<@from_text; ++$i) {1733($from_start[$i],$from_nlines[$i]) =1734(split(',',substr($from_text[$i],1)),0);1735}17361737$to_text=pop@from_text;1738$to_start=pop@from_start;1739$to_nlines=pop@from_nlines;17401741$line="<span class=\"chunk_info\">$prefix";1742for(my$i=0;$i<@from_text; ++$i) {1743if($from->{'href'}[$i]) {1744$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1745-class=>"list"},$from_text[$i]);1746}else{1747$line.=$from_text[$i];1748}1749$line.=" ";1750}1751if($to->{'href'}) {1752$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1753-class=>"list"},$to_text);1754}else{1755$line.=$to_text;1756}1757$line.="$prefix</span>".1758"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1759return"<div class=\"diff$diff_class\">$line</div>\n";1760}1761return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1762}17631764# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1765# linked. Pass the hash of the tree/commit to snapshot.1766sub format_snapshot_links {1767my($hash) =@_;1768my$num_fmts=@snapshot_fmts;1769if($num_fmts>1) {1770# A parenthesized list of links bearing format names.1771# e.g. "snapshot (_tar.gz_ _zip_)"1772return"snapshot (".join(' ',map1773$cgi->a({1774-href => href(1775 action=>"snapshot",1776 hash=>$hash,1777 snapshot_format=>$_1778)1779},$known_snapshot_formats{$_}{'display'})1780,@snapshot_fmts) .")";1781}elsif($num_fmts==1) {1782# A single "snapshot" link whose tooltip bears the format name.1783# i.e. "_snapshot_"1784my($fmt) =@snapshot_fmts;1785return1786$cgi->a({1787-href => href(1788 action=>"snapshot",1789 hash=>$hash,1790 snapshot_format=>$fmt1791),1792-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"1793},"snapshot");1794}else{# $num_fmts == 01795returnundef;1796}1797}17981799## ......................................................................1800## functions returning values to be passed, perhaps after some1801## transformation, to other functions; e.g. returning arguments to href()18021803# returns hash to be passed to href to generate gitweb URL1804# in -title key it returns description of link1805sub get_feed_info {1806my$format=shift||'Atom';1807my%res= (action =>lc($format));18081809# feed links are possible only for project views1810return unless(defined$project);1811# some views should link to OPML, or to generic project feed,1812# or don't have specific feed yet (so they should use generic)1813return if($action=~/^(?:tags|heads|forks|tag|search)$/x);18141815my$branch;1816# branches refs uses 'refs/heads/' prefix (fullname) to differentiate1817# from tag links; this also makes possible to detect branch links1818if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||1819(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {1820$branch=$1;1821}1822# find log type for feed description (title)1823my$type='log';1824if(defined$file_name) {1825$type="history of$file_name";1826$type.="/"if($actioneq'tree');1827$type.=" on '$branch'"if(defined$branch);1828}else{1829$type="log of$branch"if(defined$branch);1830}18311832$res{-title} =$type;1833$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);1834$res{'file_name'} =$file_name;18351836return%res;1837}18381839## ----------------------------------------------------------------------1840## git utility subroutines, invoking git commands18411842# returns path to the core git executable and the --git-dir parameter as list1843sub git_cmd {1844return$GIT,'--git-dir='.$git_dir;1845}18461847# quote the given arguments for passing them to the shell1848# quote_command("command", "arg 1", "arg with ' and ! characters")1849# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"1850# Try to avoid using this function wherever possible.1851sub quote_command {1852returnjoin(' ',1853map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);1854}18551856# get HEAD ref of given project as hash1857sub git_get_head_hash {1858my$project=shift;1859my$o_git_dir=$git_dir;1860my$retval=undef;1861$git_dir="$projectroot/$project";1862if(open my$fd,"-|", git_cmd(),"rev-parse","--verify","HEAD") {1863my$head= <$fd>;1864close$fd;1865if(defined$head&&$head=~/^([0-9a-fA-F]{40})$/) {1866$retval=$1;1867}1868}1869if(defined$o_git_dir) {1870$git_dir=$o_git_dir;1871}1872return$retval;1873}18741875# get type of given object1876sub git_get_type {1877my$hash=shift;18781879open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;1880my$type= <$fd>;1881close$fdorreturn;1882chomp$type;1883return$type;1884}18851886# repository configuration1887our$config_file='';1888our%config;18891890# store multiple values for single key as anonymous array reference1891# single values stored directly in the hash, not as [ <value> ]1892sub hash_set_multi {1893my($hash,$key,$value) =@_;18941895if(!exists$hash->{$key}) {1896$hash->{$key} =$value;1897}elsif(!ref$hash->{$key}) {1898$hash->{$key} = [$hash->{$key},$value];1899}else{1900push@{$hash->{$key}},$value;1901}1902}19031904# return hash of git project configuration1905# optionally limited to some section, e.g. 'gitweb'1906sub git_parse_project_config {1907my$section_regexp=shift;1908my%config;19091910local$/="\0";19111912open my$fh,"-|", git_cmd(),"config",'-z','-l',1913orreturn;19141915while(my$keyval= <$fh>) {1916chomp$keyval;1917my($key,$value) =split(/\n/,$keyval,2);19181919 hash_set_multi(\%config,$key,$value)1920if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);1921}1922close$fh;19231924return%config;1925}19261927# convert config value to boolean: 'true' or 'false'1928# no value, number > 0, 'true' and 'yes' values are true1929# rest of values are treated as false (never as error)1930sub config_to_bool {1931my$val=shift;19321933return1if!defined$val;# section.key19341935# strip leading and trailing whitespace1936$val=~s/^\s+//;1937$val=~s/\s+$//;19381939return(($val=~/^\d+$/&&$val) ||# section.key = 11940($val=~/^(?:true|yes)$/i));# section.key = true1941}19421943# convert config value to simple decimal number1944# an optional value suffix of 'k', 'm', or 'g' will cause the value1945# to be multiplied by 1024, 1048576, or 10737418241946sub config_to_int {1947my$val=shift;19481949# strip leading and trailing whitespace1950$val=~s/^\s+//;1951$val=~s/\s+$//;19521953if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {1954$unit=lc($unit);1955# unknown unit is treated as 11956return$num* ($uniteq'g'?1073741824:1957$uniteq'm'?1048576:1958$uniteq'k'?1024:1);1959}1960return$val;1961}19621963# convert config value to array reference, if needed1964sub config_to_multi {1965my$val=shift;19661967returnref($val) ?$val: (defined($val) ? [$val] : []);1968}19691970sub git_get_project_config {1971my($key,$type) =@_;19721973# key sanity check1974return unless($key);1975$key=~s/^gitweb\.//;1976return if($key=~m/\W/);19771978# type sanity check1979if(defined$type) {1980$type=~s/^--//;1981$type=undef1982unless($typeeq'bool'||$typeeq'int');1983}19841985# get config1986if(!defined$config_file||1987$config_filene"$git_dir/config") {1988%config= git_parse_project_config('gitweb');1989$config_file="$git_dir/config";1990}19911992# check if config variable (key) exists1993return unlessexists$config{"gitweb.$key"};19941995# ensure given type1996if(!defined$type) {1997return$config{"gitweb.$key"};1998}elsif($typeeq'bool') {1999# backward compatibility: 'git config --bool' returns true/false2000return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2001}elsif($typeeq'int') {2002return config_to_int($config{"gitweb.$key"});2003}2004return$config{"gitweb.$key"};2005}20062007# get hash of given path at given ref2008sub git_get_hash_by_path {2009my$base=shift;2010my$path=shift||returnundef;2011my$type=shift;20122013$path=~ s,/+$,,;20142015open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2016or die_error(500,"Open git-ls-tree failed");2017my$line= <$fd>;2018close$fdorreturnundef;20192020if(!defined$line) {2021# there is no tree or hash given by $path at $base2022returnundef;2023}20242025#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2026$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2027if(defined$type&&$typene$2) {2028# type doesn't match2029returnundef;2030}2031return$3;2032}20332034# get path of entry with given hash at given tree-ish (ref)2035# used to get 'from' filename for combined diff (merge commit) for renames2036sub git_get_path_by_hash {2037my$base=shift||return;2038my$hash=shift||return;20392040local$/="\0";20412042open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2043orreturnundef;2044while(my$line= <$fd>) {2045chomp$line;20462047#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2048#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2049if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2050close$fd;2051return$1;2052}2053}2054close$fd;2055returnundef;2056}20572058## ......................................................................2059## git utility functions, directly accessing git repository20602061sub git_get_project_description {2062my$path=shift;20632064$git_dir="$projectroot/$path";2065open my$fd,'<',"$git_dir/description"2066orreturn git_get_project_config('description');2067my$descr= <$fd>;2068close$fd;2069if(defined$descr) {2070chomp$descr;2071}2072return$descr;2073}20742075sub git_get_project_ctags {2076my$path=shift;2077my$ctags= {};20782079$git_dir="$projectroot/$path";2080opendir my$dh,"$git_dir/ctags"2081orreturn$ctags;2082foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2083open my$ct,'<',$_ornext;2084my$val= <$ct>;2085chomp$val;2086close$ct;2087my$ctag=$_;$ctag=~ s#.*/##;2088$ctags->{$ctag} =$val;2089}2090closedir$dh;2091$ctags;2092}20932094sub git_populate_project_tagcloud {2095my$ctags=shift;20962097# First, merge different-cased tags; tags vote on casing2098my%ctags_lc;2099foreach(keys%$ctags) {2100$ctags_lc{lc$_}->{count} +=$ctags->{$_};2101if(not$ctags_lc{lc$_}->{topcount}2102or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2103$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2104$ctags_lc{lc$_}->{topname} =$_;2105}2106}21072108my$cloud;2109if(eval{require HTML::TagCloud;1; }) {2110$cloud= HTML::TagCloud->new;2111foreach(sort keys%ctags_lc) {2112# Pad the title with spaces so that the cloud looks2113# less crammed.2114my$title=$ctags_lc{$_}->{topname};2115$title=~s/ / /g;2116$title=~s/^/ /g;2117$title=~s/$/ /g;2118$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2119}2120}else{2121$cloud= \%ctags_lc;2122}2123$cloud;2124}21252126sub git_show_project_tagcloud {2127my($cloud,$count) =@_;2128print STDERR ref($cloud)."..\n";2129if(ref$cloudeq'HTML::TagCloud') {2130return$cloud->html_and_css($count);2131}else{2132my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2133return'<p align="center">'.join(', ',map{2134"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"2135}splice(@tags,0,$count)) .'</p>';2136}2137}21382139sub git_get_project_url_list {2140my$path=shift;21412142$git_dir="$projectroot/$path";2143open my$fd,'<',"$git_dir/cloneurl"2144orreturnwantarray?2145@{ config_to_multi(git_get_project_config('url')) } :2146 config_to_multi(git_get_project_config('url'));2147my@git_project_url_list=map{chomp;$_} <$fd>;2148close$fd;21492150returnwantarray?@git_project_url_list: \@git_project_url_list;2151}21522153sub git_get_projects_list {2154my($filter) =@_;2155my@list;21562157$filter||='';2158$filter=~s/\.git$//;21592160my$check_forks= gitweb_check_feature('forks');21612162if(-d $projects_list) {2163# search in directory2164my$dir=$projects_list. ($filter?"/$filter":'');2165# remove the trailing "/"2166$dir=~s!/+$!!;2167my$pfxlen=length("$dir");2168my$pfxdepth= ($dir=~tr!/!!);21692170 File::Find::find({2171 follow_fast =>1,# follow symbolic links2172 follow_skip =>2,# ignore duplicates2173 dangling_symlinks =>0,# ignore dangling symlinks, silently2174 wanted =>sub{2175# skip project-list toplevel, if we get it.2176return if(m!^[/.]$!);2177# only directories can be git repositories2178return unless(-d $_);2179# don't traverse too deep (Find is super slow on os x)2180if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2181$File::Find::prune =1;2182return;2183}21842185my$subdir=substr($File::Find::name,$pfxlen+1);2186# we check related file in $projectroot2187my$path= ($filter?"$filter/":'') .$subdir;2188if(check_export_ok("$projectroot/$path")) {2189push@list, { path =>$path};2190$File::Find::prune =1;2191}2192},2193},"$dir");21942195}elsif(-f $projects_list) {2196# read from file(url-encoded):2197# 'git%2Fgit.git Linus+Torvalds'2198# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2199# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2200my%paths;2201open my$fd,'<',$projects_listorreturn;2202 PROJECT:2203while(my$line= <$fd>) {2204chomp$line;2205my($path,$owner) =split' ',$line;2206$path= unescape($path);2207$owner= unescape($owner);2208if(!defined$path) {2209next;2210}2211if($filterne'') {2212# looking for forks;2213my$pfx=substr($path,0,length($filter));2214if($pfxne$filter) {2215next PROJECT;2216}2217my$sfx=substr($path,length($filter));2218if($sfx!~/^\/.*\.git$/) {2219next PROJECT;2220}2221}elsif($check_forks) {2222 PATH:2223foreachmy$filter(keys%paths) {2224# looking for forks;2225my$pfx=substr($path,0,length($filter));2226if($pfxne$filter) {2227next PATH;2228}2229my$sfx=substr($path,length($filter));2230if($sfx!~/^\/.*\.git$/) {2231next PATH;2232}2233# is a fork, don't include it in2234# the list2235next PROJECT;2236}2237}2238if(check_export_ok("$projectroot/$path")) {2239my$pr= {2240 path =>$path,2241 owner => to_utf8($owner),2242};2243push@list,$pr;2244(my$forks_path=$path) =~s/\.git$//;2245$paths{$forks_path}++;2246}2247}2248close$fd;2249}2250return@list;2251}22522253our$gitweb_project_owner=undef;2254sub git_get_project_list_from_file {22552256return if(defined$gitweb_project_owner);22572258$gitweb_project_owner= {};2259# read from file (url-encoded):2260# 'git%2Fgit.git Linus+Torvalds'2261# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2262# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2263if(-f $projects_list) {2264open(my$fd,'<',$projects_list);2265while(my$line= <$fd>) {2266chomp$line;2267my($pr,$ow) =split' ',$line;2268$pr= unescape($pr);2269$ow= unescape($ow);2270$gitweb_project_owner->{$pr} = to_utf8($ow);2271}2272close$fd;2273}2274}22752276sub git_get_project_owner {2277my$project=shift;2278my$owner;22792280returnundefunless$project;2281$git_dir="$projectroot/$project";22822283if(!defined$gitweb_project_owner) {2284 git_get_project_list_from_file();2285}22862287if(exists$gitweb_project_owner->{$project}) {2288$owner=$gitweb_project_owner->{$project};2289}2290if(!defined$owner){2291$owner= git_get_project_config('owner');2292}2293if(!defined$owner) {2294$owner= get_file_owner("$git_dir");2295}22962297return$owner;2298}22992300sub git_get_last_activity {2301my($path) =@_;2302my$fd;23032304$git_dir="$projectroot/$path";2305open($fd,"-|", git_cmd(),'for-each-ref',2306'--format=%(committer)',2307'--sort=-committerdate',2308'--count=1',2309'refs/heads')orreturn;2310my$most_recent= <$fd>;2311close$fdorreturn;2312if(defined$most_recent&&2313$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2314my$timestamp=$1;2315my$age=time-$timestamp;2316return($age, age_string($age));2317}2318return(undef,undef);2319}23202321sub git_get_references {2322my$type=shift||"";2323my%refs;2324# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112325# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2326open my$fd,"-|", git_cmd(),"show-ref","--dereference",2327($type? ("--","refs/$type") : ())# use -- <pattern> if $type2328orreturn;23292330while(my$line= <$fd>) {2331chomp$line;2332if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2333if(defined$refs{$1}) {2334push@{$refs{$1}},$2;2335}else{2336$refs{$1} = [$2];2337}2338}2339}2340close$fdorreturn;2341return \%refs;2342}23432344sub git_get_rev_name_tags {2345my$hash=shift||returnundef;23462347open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2348orreturn;2349my$name_rev= <$fd>;2350close$fd;23512352if($name_rev=~ m|^$hash tags/(.*)$|) {2353return$1;2354}else{2355# catches also '$hash undefined' output2356returnundef;2357}2358}23592360## ----------------------------------------------------------------------2361## parse to hash functions23622363sub parse_date {2364my$epoch=shift;2365my$tz=shift||"-0000";23662367my%date;2368my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2369my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2370my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2371$date{'hour'} =$hour;2372$date{'minute'} =$min;2373$date{'mday'} =$mday;2374$date{'day'} =$days[$wday];2375$date{'month'} =$months[$mon];2376$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2377$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2378$date{'mday-time'} =sprintf"%d%s%02d:%02d",2379$mday,$months[$mon],$hour,$min;2380$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",23811900+$year,1+$mon,$mday,$hour,$min,$sec;23822383$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2384my$local=$epoch+ ((int$1+ ($2/60)) *3600);2385($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2386$date{'hour_local'} =$hour;2387$date{'minute_local'} =$min;2388$date{'tz_local'} =$tz;2389$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",23901900+$year,$mon+1,$mday,2391$hour,$min,$sec,$tz);2392return%date;2393}23942395sub parse_tag {2396my$tag_id=shift;2397my%tag;2398my@comment;23992400open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2401$tag{'id'} =$tag_id;2402while(my$line= <$fd>) {2403chomp$line;2404if($line=~m/^object ([0-9a-fA-F]{40})$/) {2405$tag{'object'} =$1;2406}elsif($line=~m/^type (.+)$/) {2407$tag{'type'} =$1;2408}elsif($line=~m/^tag (.+)$/) {2409$tag{'name'} =$1;2410}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2411$tag{'author'} =$1;2412$tag{'epoch'} =$2;2413$tag{'tz'} =$3;2414}elsif($line=~m/--BEGIN/) {2415push@comment,$line;2416last;2417}elsif($lineeq"") {2418last;2419}2420}2421push@comment, <$fd>;2422$tag{'comment'} = \@comment;2423close$fdorreturn;2424if(!defined$tag{'name'}) {2425return2426};2427return%tag2428}24292430sub parse_commit_text {2431my($commit_text,$withparents) =@_;2432my@commit_lines=split'\n',$commit_text;2433my%co;24342435pop@commit_lines;# Remove '\0'24362437if(!@commit_lines) {2438return;2439}24402441my$header=shift@commit_lines;2442if($header!~m/^[0-9a-fA-F]{40}/) {2443return;2444}2445($co{'id'},my@parents) =split' ',$header;2446while(my$line=shift@commit_lines) {2447last if$lineeq"\n";2448if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2449$co{'tree'} =$1;2450}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2451push@parents,$1;2452}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2453$co{'author'} =$1;2454$co{'author_epoch'} =$2;2455$co{'author_tz'} =$3;2456if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2457$co{'author_name'} =$1;2458$co{'author_email'} =$2;2459}else{2460$co{'author_name'} =$co{'author'};2461}2462}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2463$co{'committer'} =$1;2464$co{'committer_epoch'} =$2;2465$co{'committer_tz'} =$3;2466$co{'committer_name'} =$co{'committer'};2467if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2468$co{'committer_name'} =$1;2469$co{'committer_email'} =$2;2470}else{2471$co{'committer_name'} =$co{'committer'};2472}2473}2474}2475if(!defined$co{'tree'}) {2476return;2477};2478$co{'parents'} = \@parents;2479$co{'parent'} =$parents[0];24802481foreachmy$title(@commit_lines) {2482$title=~s/^ //;2483if($titlene"") {2484$co{'title'} = chop_str($title,80,5);2485# remove leading stuff of merges to make the interesting part visible2486if(length($title) >50) {2487$title=~s/^Automatic //;2488$title=~s/^merge (of|with) /Merge ... /i;2489if(length($title) >50) {2490$title=~s/(http|rsync):\/\///;2491}2492if(length($title) >50) {2493$title=~s/(master|www|rsync)\.//;2494}2495if(length($title) >50) {2496$title=~s/kernel.org:?//;2497}2498if(length($title) >50) {2499$title=~s/\/pub\/scm//;2500}2501}2502$co{'title_short'} = chop_str($title,50,5);2503last;2504}2505}2506if(!defined$co{'title'} ||$co{'title'}eq"") {2507$co{'title'} =$co{'title_short'} ='(no commit message)';2508}2509# remove added spaces2510foreachmy$line(@commit_lines) {2511$line=~s/^ //;2512}2513$co{'comment'} = \@commit_lines;25142515my$age=time-$co{'committer_epoch'};2516$co{'age'} =$age;2517$co{'age_string'} = age_string($age);2518my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2519if($age>60*60*24*7*2) {2520$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2521$co{'age_string_age'} =$co{'age_string'};2522}else{2523$co{'age_string_date'} =$co{'age_string'};2524$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2525}2526return%co;2527}25282529sub parse_commit {2530my($commit_id) =@_;2531my%co;25322533local$/="\0";25342535open my$fd,"-|", git_cmd(),"rev-list",2536"--parents",2537"--header",2538"--max-count=1",2539$commit_id,2540"--",2541or die_error(500,"Open git-rev-list failed");2542%co= parse_commit_text(<$fd>,1);2543close$fd;25442545return%co;2546}25472548sub parse_commits {2549my($commit_id,$maxcount,$skip,$filename,@args) =@_;2550my@cos;25512552$maxcount||=1;2553$skip||=0;25542555local$/="\0";25562557open my$fd,"-|", git_cmd(),"rev-list",2558"--header",2559@args,2560("--max-count=".$maxcount),2561("--skip=".$skip),2562@extra_options,2563$commit_id,2564"--",2565($filename? ($filename) : ())2566or die_error(500,"Open git-rev-list failed");2567while(my$line= <$fd>) {2568my%co= parse_commit_text($line);2569push@cos, \%co;2570}2571close$fd;25722573returnwantarray?@cos: \@cos;2574}25752576# parse line of git-diff-tree "raw" output2577sub parse_difftree_raw_line {2578my$line=shift;2579my%res;25802581# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2582# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2583if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2584$res{'from_mode'} =$1;2585$res{'to_mode'} =$2;2586$res{'from_id'} =$3;2587$res{'to_id'} =$4;2588$res{'status'} =$5;2589$res{'similarity'} =$6;2590if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2591($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2592}else{2593$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2594}2595}2596# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2597# combined diff (for merge commit)2598elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2599$res{'nparents'} =length($1);2600$res{'from_mode'} = [split(' ',$2) ];2601$res{'to_mode'} =pop@{$res{'from_mode'}};2602$res{'from_id'} = [split(' ',$3) ];2603$res{'to_id'} =pop@{$res{'from_id'}};2604$res{'status'} = [split('',$4) ];2605$res{'to_file'} = unquote($5);2606}2607# 'c512b523472485aef4fff9e57b229d9d243c967f'2608elsif($line=~m/^([0-9a-fA-F]{40})$/) {2609$res{'commit'} =$1;2610}26112612returnwantarray?%res: \%res;2613}26142615# wrapper: return parsed line of git-diff-tree "raw" output2616# (the argument might be raw line, or parsed info)2617sub parsed_difftree_line {2618my$line_or_ref=shift;26192620if(ref($line_or_ref)eq"HASH") {2621# pre-parsed (or generated by hand)2622return$line_or_ref;2623}else{2624return parse_difftree_raw_line($line_or_ref);2625}2626}26272628# parse line of git-ls-tree output2629sub parse_ls_tree_line {2630my$line=shift;2631my%opts=@_;2632my%res;26332634#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2635$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;26362637$res{'mode'} =$1;2638$res{'type'} =$2;2639$res{'hash'} =$3;2640if($opts{'-z'}) {2641$res{'name'} =$4;2642}else{2643$res{'name'} = unquote($4);2644}26452646returnwantarray?%res: \%res;2647}26482649# generates _two_ hashes, references to which are passed as 2 and 3 argument2650sub parse_from_to_diffinfo {2651my($diffinfo,$from,$to,@parents) =@_;26522653if($diffinfo->{'nparents'}) {2654# combined diff2655$from->{'file'} = [];2656$from->{'href'} = [];2657 fill_from_file_info($diffinfo,@parents)2658unlessexists$diffinfo->{'from_file'};2659for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2660$from->{'file'}[$i] =2661defined$diffinfo->{'from_file'}[$i] ?2662$diffinfo->{'from_file'}[$i] :2663$diffinfo->{'to_file'};2664if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2665$from->{'href'}[$i] = href(action=>"blob",2666 hash_base=>$parents[$i],2667 hash=>$diffinfo->{'from_id'}[$i],2668 file_name=>$from->{'file'}[$i]);2669}else{2670$from->{'href'}[$i] =undef;2671}2672}2673}else{2674# ordinary (not combined) diff2675$from->{'file'} =$diffinfo->{'from_file'};2676if($diffinfo->{'status'}ne"A") {# not new (added) file2677$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2678 hash=>$diffinfo->{'from_id'},2679 file_name=>$from->{'file'});2680}else{2681delete$from->{'href'};2682}2683}26842685$to->{'file'} =$diffinfo->{'to_file'};2686if(!is_deleted($diffinfo)) {# file exists in result2687$to->{'href'} = href(action=>"blob", hash_base=>$hash,2688 hash=>$diffinfo->{'to_id'},2689 file_name=>$to->{'file'});2690}else{2691delete$to->{'href'};2692}2693}26942695## ......................................................................2696## parse to array of hashes functions26972698sub git_get_heads_list {2699my$limit=shift;2700my@headslist;27012702open my$fd,'-|', git_cmd(),'for-each-ref',2703($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2704'--format=%(objectname) %(refname) %(subject)%00%(committer)',2705'refs/heads'2706orreturn;2707while(my$line= <$fd>) {2708my%ref_item;27092710chomp$line;2711my($refinfo,$committerinfo) =split(/\0/,$line);2712my($hash,$name,$title) =split(' ',$refinfo,3);2713my($committer,$epoch,$tz) =2714($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2715$ref_item{'fullname'} =$name;2716$name=~s!^refs/heads/!!;27172718$ref_item{'name'} =$name;2719$ref_item{'id'} =$hash;2720$ref_item{'title'} =$title||'(no commit message)';2721$ref_item{'epoch'} =$epoch;2722if($epoch) {2723$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2724}else{2725$ref_item{'age'} ="unknown";2726}27272728push@headslist, \%ref_item;2729}2730close$fd;27312732returnwantarray?@headslist: \@headslist;2733}27342735sub git_get_tags_list {2736my$limit=shift;2737my@tagslist;27382739open my$fd,'-|', git_cmd(),'for-each-ref',2740($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',2741'--format=%(objectname) %(objecttype) %(refname) '.2742'%(*objectname) %(*objecttype) %(subject)%00%(creator)',2743'refs/tags'2744orreturn;2745while(my$line= <$fd>) {2746my%ref_item;27472748chomp$line;2749my($refinfo,$creatorinfo) =split(/\0/,$line);2750my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);2751my($creator,$epoch,$tz) =2752($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);2753$ref_item{'fullname'} =$name;2754$name=~s!^refs/tags/!!;27552756$ref_item{'type'} =$type;2757$ref_item{'id'} =$id;2758$ref_item{'name'} =$name;2759if($typeeq"tag") {2760$ref_item{'subject'} =$title;2761$ref_item{'reftype'} =$reftype;2762$ref_item{'refid'} =$refid;2763}else{2764$ref_item{'reftype'} =$type;2765$ref_item{'refid'} =$id;2766}27672768if($typeeq"tag"||$typeeq"commit") {2769$ref_item{'epoch'} =$epoch;2770if($epoch) {2771$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2772}else{2773$ref_item{'age'} ="unknown";2774}2775}27762777push@tagslist, \%ref_item;2778}2779close$fd;27802781returnwantarray?@tagslist: \@tagslist;2782}27832784## ----------------------------------------------------------------------2785## filesystem-related functions27862787sub get_file_owner {2788my$path=shift;27892790my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);2791my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);2792if(!defined$gcos) {2793returnundef;2794}2795my$owner=$gcos;2796$owner=~s/[,;].*$//;2797return to_utf8($owner);2798}27992800# assume that file exists2801sub insert_file {2802my$filename=shift;28032804open my$fd,'<',$filename;2805print map{ to_utf8($_) } <$fd>;2806close$fd;2807}28082809## ......................................................................2810## mimetype related functions28112812sub mimetype_guess_file {2813my$filename=shift;2814my$mimemap=shift;2815-r $mimemaporreturnundef;28162817my%mimemap;2818open(my$mh,'<',$mimemap)orreturnundef;2819while(<$mh>) {2820next ifm/^#/;# skip comments2821my($mimetype,$exts) =split(/\t+/);2822if(defined$exts) {2823my@exts=split(/\s+/,$exts);2824foreachmy$ext(@exts) {2825$mimemap{$ext} =$mimetype;2826}2827}2828}2829close($mh);28302831$filename=~/\.([^.]*)$/;2832return$mimemap{$1};2833}28342835sub mimetype_guess {2836my$filename=shift;2837my$mime;2838$filename=~/\./orreturnundef;28392840if($mimetypes_file) {2841my$file=$mimetypes_file;2842if($file!~m!^/!) {# if it is relative path2843# it is relative to project2844$file="$projectroot/$project/$file";2845}2846$mime= mimetype_guess_file($filename,$file);2847}2848$mime||= mimetype_guess_file($filename,'/etc/mime.types');2849return$mime;2850}28512852sub blob_mimetype {2853my$fd=shift;2854my$filename=shift;28552856if($filename) {2857my$mime= mimetype_guess($filename);2858$mimeandreturn$mime;2859}28602861# just in case2862return$default_blob_plain_mimetypeunless$fd;28632864if(-T $fd) {2865return'text/plain';2866}elsif(!$filename) {2867return'application/octet-stream';2868}elsif($filename=~m/\.png$/i) {2869return'image/png';2870}elsif($filename=~m/\.gif$/i) {2871return'image/gif';2872}elsif($filename=~m/\.jpe?g$/i) {2873return'image/jpeg';2874}else{2875return'application/octet-stream';2876}2877}28782879sub blob_contenttype {2880my($fd,$file_name,$type) =@_;28812882$type||= blob_mimetype($fd,$file_name);2883if($typeeq'text/plain'&&defined$default_text_plain_charset) {2884$type.="; charset=$default_text_plain_charset";2885}28862887return$type;2888}28892890## ======================================================================2891## functions printing HTML: header, footer, error page28922893sub git_header_html {2894my$status=shift||"200 OK";2895my$expires=shift;28962897my$title="$site_name";2898if(defined$project) {2899$title.=" - ". to_utf8($project);2900if(defined$action) {2901$title.="/$action";2902if(defined$file_name) {2903$title.=" - ". esc_path($file_name);2904if($actioneq"tree"&&$file_name!~ m|/$|) {2905$title.="/";2906}2907}2908}2909}2910my$content_type;2911# require explicit support from the UA if we are to send the page as2912# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.2913# we have to do this because MSIE sometimes globs '*/*', pretending to2914# support xhtml+xml but choking when it gets what it asked for.2915if(defined$cgi->http('HTTP_ACCEPT') &&2916$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&2917$cgi->Accept('application/xhtml+xml') !=0) {2918$content_type='application/xhtml+xml';2919}else{2920$content_type='text/html';2921}2922print$cgi->header(-type=>$content_type, -charset =>'utf-8',2923-status=>$status, -expires =>$expires);2924my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';2925print<<EOF;2926<?xml version="1.0" encoding="utf-8"?>2927<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">2928<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">2929<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->2930<!-- git core binaries version$git_version-->2931<head>2932<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>2933<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>2934<meta name="robots" content="index, nofollow"/>2935<title>$title</title>2936EOF2937# the stylesheet, favicon etc urls won't work correctly with path_info2938# unless we set the appropriate base URL2939if($ENV{'PATH_INFO'}) {2940print"<base href=\"".esc_url($base_url)."\"/>\n";2941}2942# print out each stylesheet that exist, providing backwards capability2943# for those people who defined $stylesheet in a config file2944if(defined$stylesheet) {2945print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";2946}else{2947foreachmy$stylesheet(@stylesheets) {2948next unless$stylesheet;2949print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";2950}2951}2952if(defined$project) {2953my%href_params= get_feed_info();2954if(!exists$href_params{'-title'}) {2955$href_params{'-title'} ='log';2956}29572958foreachmy$formatqw(RSS Atom){2959my$type=lc($format);2960my%link_attr= (2961'-rel'=>'alternate',2962'-title'=>"$project-$href_params{'-title'} -$formatfeed",2963'-type'=>"application/$type+xml"2964);29652966$href_params{'action'} =$type;2967$link_attr{'-href'} = href(%href_params);2968print"<link ".2969"rel=\"$link_attr{'-rel'}\"".2970"title=\"$link_attr{'-title'}\"".2971"href=\"$link_attr{'-href'}\"".2972"type=\"$link_attr{'-type'}\"".2973"/>\n";29742975$href_params{'extra_options'} ='--no-merges';2976$link_attr{'-href'} = href(%href_params);2977$link_attr{'-title'} .=' (no merges)';2978print"<link ".2979"rel=\"$link_attr{'-rel'}\"".2980"title=\"$link_attr{'-title'}\"".2981"href=\"$link_attr{'-href'}\"".2982"type=\"$link_attr{'-type'}\"".2983"/>\n";2984}29852986}else{2987printf('<link rel="alternate" title="%sprojects list" '.2988'href="%s" type="text/plain; charset=utf-8" />'."\n",2989$site_name, href(project=>undef, action=>"project_index"));2990printf('<link rel="alternate" title="%sprojects feeds" '.2991'href="%s" type="text/x-opml" />'."\n",2992$site_name, href(project=>undef, action=>"opml"));2993}2994if(defined$favicon) {2995printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);2996}29972998print"</head>\n".2999"<body>\n";30003001if(-f $site_header) {3002 insert_file($site_header);3003}30043005print"<div class=\"page_header\">\n".3006$cgi->a({-href => esc_url($logo_url),3007-title =>$logo_label},3008qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));3009print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3010if(defined$project) {3011print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3012if(defined$action) {3013print" /$action";3014}3015print"\n";3016}3017print"</div>\n";30183019my$have_search= gitweb_check_feature('search');3020if(defined$project&&$have_search) {3021if(!defined$searchtext) {3022$searchtext="";3023}3024my$search_hash;3025if(defined$hash_base) {3026$search_hash=$hash_base;3027}elsif(defined$hash) {3028$search_hash=$hash;3029}else{3030$search_hash="HEAD";3031}3032my$action=$my_uri;3033my$use_pathinfo= gitweb_check_feature('pathinfo');3034if($use_pathinfo) {3035$action.="/".esc_url($project);3036}3037print$cgi->startform(-method=>"get", -action =>$action) .3038"<div class=\"search\">\n".3039(!$use_pathinfo&&3040$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3041$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3042$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3043$cgi->popup_menu(-name =>'st', -default=>'commit',3044-values=> ['commit','grep','author','committer','pickaxe']) .3045$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3046" search:\n",3047$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3048"<span title=\"Extended regular expression\">".3049$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3050-checked =>$search_use_regexp) .3051"</span>".3052"</div>".3053$cgi->end_form() ."\n";3054}3055}30563057sub git_footer_html {3058my$feed_class='rss_logo';30593060print"<div class=\"page_footer\">\n";3061if(defined$project) {3062my$descr= git_get_project_description($project);3063if(defined$descr) {3064print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3065}30663067my%href_params= get_feed_info();3068if(!%href_params) {3069$feed_class.=' generic';3070}3071$href_params{'-title'} ||='log';30723073foreachmy$formatqw(RSS Atom){3074$href_params{'action'} =lc($format);3075print$cgi->a({-href => href(%href_params),3076-title =>"$href_params{'-title'}$formatfeed",3077-class=>$feed_class},$format)."\n";3078}30793080}else{3081print$cgi->a({-href => href(project=>undef, action=>"opml"),3082-class=>$feed_class},"OPML") ." ";3083print$cgi->a({-href => href(project=>undef, action=>"project_index"),3084-class=>$feed_class},"TXT") ."\n";3085}3086print"</div>\n";# class="page_footer"30873088if(-f $site_footer) {3089 insert_file($site_footer);3090}30913092print"</body>\n".3093"</html>";3094}30953096# die_error(<http_status_code>, <error_message>)3097# Example: die_error(404, 'Hash not found')3098# By convention, use the following status codes (as defined in RFC 2616):3099# 400: Invalid or missing CGI parameters, or3100# requested object exists but has wrong type.3101# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3102# this server or project.3103# 404: Requested object/revision/project doesn't exist.3104# 500: The server isn't configured properly, or3105# an internal error occurred (e.g. failed assertions caused by bugs), or3106# an unknown error occurred (e.g. the git binary died unexpectedly).3107sub die_error {3108my$status=shift||500;3109my$error=shift||"Internal server error";31103111my%http_responses= (400=>'400 Bad Request',3112403=>'403 Forbidden',3113404=>'404 Not Found',3114500=>'500 Internal Server Error');3115 git_header_html($http_responses{$status});3116print<<EOF;3117<div class="page_body">3118<br /><br />3119$status-$error3120<br />3121</div>3122EOF3123 git_footer_html();3124exit;3125}31263127## ----------------------------------------------------------------------3128## functions printing or outputting HTML: navigation31293130sub git_print_page_nav {3131my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3132$extra=''if!defined$extra;# pager or formats31333134my@navs=qw(summary shortlog log commit commitdiff tree);3135if($suppress) {3136@navs=grep{$_ne$suppress}@navs;3137}31383139my%arg=map{$_=> {action=>$_} }@navs;3140if(defined$head) {3141for(qw(commit commitdiff)) {3142$arg{$_}{'hash'} =$head;3143}3144if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3145for(qw(shortlog log)) {3146$arg{$_}{'hash'} =$head;3147}3148}3149}31503151$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3152$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;31533154my@actions= gitweb_get_feature('actions');3155my%repl= (3156'%'=>'%',3157'n'=>$project,# project name3158'f'=>$git_dir,# project path within filesystem3159'h'=>$treehead||'',# current hash ('h' parameter)3160'b'=>$treebase||'',# hash base ('hb' parameter)3161);3162while(@actions) {3163my($label,$link,$pos) =splice(@actions,0,3);3164# insert3165@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3166# munch munch3167$link=~s/%([%nfhb])/$repl{$1}/g;3168$arg{$label}{'_href'} =$link;3169}31703171print"<div class=\"page_nav\">\n".3172(join" | ",3173map{$_eq$current?3174$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3175}@navs);3176print"<br/>\n$extra<br/>\n".3177"</div>\n";3178}31793180sub format_paging_nav {3181my($action,$hash,$head,$page,$has_next_link) =@_;3182my$paging_nav;318331843185if($hashne$head||$page) {3186$paging_nav.=$cgi->a({-href => href(action=>$action)},"HEAD");3187}else{3188$paging_nav.="HEAD";3189}31903191if($page>0) {3192$paging_nav.=" ⋅ ".3193$cgi->a({-href => href(-replay=>1, page=>$page-1),3194-accesskey =>"p", -title =>"Alt-p"},"prev");3195}else{3196$paging_nav.=" ⋅ prev";3197}31983199if($has_next_link) {3200$paging_nav.=" ⋅ ".3201$cgi->a({-href => href(-replay=>1, page=>$page+1),3202-accesskey =>"n", -title =>"Alt-n"},"next");3203}else{3204$paging_nav.=" ⋅ next";3205}32063207return$paging_nav;3208}32093210## ......................................................................3211## functions printing or outputting HTML: div32123213sub git_print_header_div {3214my($action,$title,$hash,$hash_base) =@_;3215my%args= ();32163217$args{'action'} =$action;3218$args{'hash'} =$hashif$hash;3219$args{'hash_base'} =$hash_baseif$hash_base;32203221print"<div class=\"header\">\n".3222$cgi->a({-href => href(%args), -class=>"title"},3223$title?$title:$action) .3224"\n</div>\n";3225}32263227sub print_local_time {3228my%date=@_;3229if($date{'hour_local'} <6) {3230printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3231$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3232}else{3233printf(" (%02d:%02d%s)",3234$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3235}3236}32373238# Outputs the author name and date in long form3239sub git_print_authorship {3240my$co=shift;3241my%opts=@_;3242my$tag=$opts{-tag} ||'div';32433244my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3245print"<$tagclass=\"author_date\">".3246 esc_html($co->{'author_name'}) .3247" [$ad{'rfc2822'}";3248 print_local_time(%ad)if($opts{-localtime});3249print"]</$tag>\n";3250}32513252# Outputs table rows containing the full author or committer information,3253# in the format expected for 'commit' view (& similia).3254# Parameters are a commit hash reference, followed by the list of people3255# to output information for. If the list is empty it defalts to both3256# author and committer.3257sub git_print_authorship_rows {3258my$co=shift;3259# too bad we can't use @people = @_ || ('author', 'committer')3260my@people=@_;3261@people= ('author','committer')unless@people;3262foreachmy$who(@people) {3263my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});3264print"<tr><td>$who</td><td>". esc_html($co->{$who}) ."</td></tr>\n".3265"<tr>".3266"<td></td><td>$wd{'rfc2822'}";3267 print_local_time(%wd);3268print"</td>".3269"</tr>\n";3270}3271}32723273sub git_print_page_path {3274my$name=shift;3275my$type=shift;3276my$hb=shift;327732783279print"<div class=\"page_path\">";3280print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),3281-title =>'tree root'}, to_utf8("[$project]"));3282print" / ";3283if(defined$name) {3284my@dirname=split'/',$name;3285my$basename=pop@dirname;3286my$fullname='';32873288foreachmy$dir(@dirname) {3289$fullname.= ($fullname?'/':'') .$dir;3290print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,3291 hash_base=>$hb),3292-title =>$fullname}, esc_path($dir));3293print" / ";3294}3295if(defined$type&&$typeeq'blob') {3296print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,3297 hash_base=>$hb),3298-title =>$name}, esc_path($basename));3299}elsif(defined$type&&$typeeq'tree') {3300print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,3301 hash_base=>$hb),3302-title =>$name}, esc_path($basename));3303print" / ";3304}else{3305print esc_path($basename);3306}3307}3308print"<br/></div>\n";3309}33103311sub git_print_log {3312my$log=shift;3313my%opts=@_;33143315if($opts{'-remove_title'}) {3316# remove title, i.e. first line of log3317shift@$log;3318}3319# remove leading empty lines3320while(defined$log->[0] &&$log->[0]eq"") {3321shift@$log;3322}33233324# print log3325my$signoff=0;3326my$empty=0;3327foreachmy$line(@$log) {3328if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3329$signoff=1;3330$empty=0;3331if(!$opts{'-remove_signoff'}) {3332print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3333next;3334}else{3335# remove signoff lines3336next;3337}3338}else{3339$signoff=0;3340}33413342# print only one empty line3343# do not print empty line after signoff3344if($lineeq"") {3345next if($empty||$signoff);3346$empty=1;3347}else{3348$empty=0;3349}33503351print format_log_line_html($line) ."<br/>\n";3352}33533354if($opts{'-final_empty_line'}) {3355# end with single empty line3356print"<br/>\n"unless$empty;3357}3358}33593360# return link target (what link points to)3361sub git_get_link_target {3362my$hash=shift;3363my$link_target;33643365# read link3366open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3367orreturn;3368{3369local$/=undef;3370$link_target= <$fd>;3371}3372close$fd3373orreturn;33743375return$link_target;3376}33773378# given link target, and the directory (basedir) the link is in,3379# return target of link relative to top directory (top tree);3380# return undef if it is not possible (including absolute links).3381sub normalize_link_target {3382my($link_target,$basedir) =@_;33833384# absolute symlinks (beginning with '/') cannot be normalized3385return if(substr($link_target,0,1)eq'/');33863387# normalize link target to path from top (root) tree (dir)3388my$path;3389if($basedir) {3390$path=$basedir.'/'.$link_target;3391}else{3392# we are in top (root) tree (dir)3393$path=$link_target;3394}33953396# remove //, /./, and /../3397my@path_parts;3398foreachmy$part(split('/',$path)) {3399# discard '.' and ''3400next if(!$part||$parteq'.');3401# handle '..'3402if($parteq'..') {3403if(@path_parts) {3404pop@path_parts;3405}else{3406# link leads outside repository (outside top dir)3407return;3408}3409}else{3410push@path_parts,$part;3411}3412}3413$path=join('/',@path_parts);34143415return$path;3416}34173418# print tree entry (row of git_tree), but without encompassing <tr> element3419sub git_print_tree_entry {3420my($t,$basedir,$hash_base,$have_blame) =@_;34213422my%base_key= ();3423$base_key{'hash_base'} =$hash_baseifdefined$hash_base;34243425# The format of a table row is: mode list link. Where mode is3426# the mode of the entry, list is the name of the entry, an href,3427# and link is the action links of the entry.34283429print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3430if($t->{'type'}eq"blob") {3431print"<td class=\"list\">".3432$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3433 file_name=>"$basedir$t->{'name'}",%base_key),3434-class=>"list"}, esc_path($t->{'name'}));3435if(S_ISLNK(oct$t->{'mode'})) {3436my$link_target= git_get_link_target($t->{'hash'});3437if($link_target) {3438my$norm_target= normalize_link_target($link_target,$basedir);3439if(defined$norm_target) {3440print" -> ".3441$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3442 file_name=>$norm_target),3443-title =>$norm_target}, esc_path($link_target));3444}else{3445print" -> ". esc_path($link_target);3446}3447}3448}3449print"</td>\n";3450print"<td class=\"link\">";3451print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3452 file_name=>"$basedir$t->{'name'}",%base_key)},3453"blob");3454if($have_blame) {3455print" | ".3456$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3457 file_name=>"$basedir$t->{'name'}",%base_key)},3458"blame");3459}3460if(defined$hash_base) {3461print" | ".3462$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3463 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3464"history");3465}3466print" | ".3467$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3468 file_name=>"$basedir$t->{'name'}")},3469"raw");3470print"</td>\n";34713472}elsif($t->{'type'}eq"tree") {3473print"<td class=\"list\">";3474print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3475 file_name=>"$basedir$t->{'name'}",%base_key)},3476 esc_path($t->{'name'}));3477print"</td>\n";3478print"<td class=\"link\">";3479print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3480 file_name=>"$basedir$t->{'name'}",%base_key)},3481"tree");3482if(defined$hash_base) {3483print" | ".3484$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3485 file_name=>"$basedir$t->{'name'}")},3486"history");3487}3488print"</td>\n";3489}else{3490# unknown object: we can only present history for it3491# (this includes 'commit' object, i.e. submodule support)3492print"<td class=\"list\">".3493 esc_path($t->{'name'}) .3494"</td>\n";3495print"<td class=\"link\">";3496if(defined$hash_base) {3497print$cgi->a({-href => href(action=>"history",3498 hash_base=>$hash_base,3499 file_name=>"$basedir$t->{'name'}")},3500"history");3501}3502print"</td>\n";3503}3504}35053506## ......................................................................3507## functions printing large fragments of HTML35083509# get pre-image filenames for merge (combined) diff3510sub fill_from_file_info {3511my($diff,@parents) =@_;35123513$diff->{'from_file'} = [ ];3514$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3515for(my$i=0;$i<$diff->{'nparents'};$i++) {3516if($diff->{'status'}[$i]eq'R'||3517$diff->{'status'}[$i]eq'C') {3518$diff->{'from_file'}[$i] =3519 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3520}3521}35223523return$diff;3524}35253526# is current raw difftree line of file deletion3527sub is_deleted {3528my$diffinfo=shift;35293530return$diffinfo->{'to_id'}eq('0' x 40);3531}35323533# does patch correspond to [previous] difftree raw line3534# $diffinfo - hashref of parsed raw diff format3535# $patchinfo - hashref of parsed patch diff format3536# (the same keys as in $diffinfo)3537sub is_patch_split {3538my($diffinfo,$patchinfo) =@_;35393540returndefined$diffinfo&&defined$patchinfo3541&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3542}354335443545sub git_difftree_body {3546my($difftree,$hash,@parents) =@_;3547my($parent) =$parents[0];3548my$have_blame= gitweb_check_feature('blame');3549print"<div class=\"list_head\">\n";3550if($#{$difftree} >10) {3551print(($#{$difftree} +1) ." files changed:\n");3552}3553print"</div>\n";35543555print"<table class=\"".3556(@parents>1?"combined ":"") .3557"diff_tree\">\n";35583559# header only for combined diff in 'commitdiff' view3560my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3561if($has_header) {3562# table header3563print"<thead><tr>\n".3564"<th></th><th></th>\n";# filename, patchN link3565for(my$i=0;$i<@parents;$i++) {3566my$par=$parents[$i];3567print"<th>".3568$cgi->a({-href => href(action=>"commitdiff",3569 hash=>$hash, hash_parent=>$par),3570-title =>'commitdiff to parent number '.3571($i+1) .': '.substr($par,0,7)},3572$i+1) .3573" </th>\n";3574}3575print"</tr></thead>\n<tbody>\n";3576}35773578my$alternate=1;3579my$patchno=0;3580foreachmy$line(@{$difftree}) {3581my$diff= parsed_difftree_line($line);35823583if($alternate) {3584print"<tr class=\"dark\">\n";3585}else{3586print"<tr class=\"light\">\n";3587}3588$alternate^=1;35893590if(exists$diff->{'nparents'}) {# combined diff35913592 fill_from_file_info($diff,@parents)3593unlessexists$diff->{'from_file'};35943595if(!is_deleted($diff)) {3596# file exists in the result (child) commit3597print"<td>".3598$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3599 file_name=>$diff->{'to_file'},3600 hash_base=>$hash),3601-class=>"list"}, esc_path($diff->{'to_file'})) .3602"</td>\n";3603}else{3604print"<td>".3605 esc_path($diff->{'to_file'}) .3606"</td>\n";3607}36083609if($actioneq'commitdiff') {3610# link to patch3611$patchno++;3612print"<td class=\"link\">".3613$cgi->a({-href =>"#patch$patchno"},"patch") .3614" | ".3615"</td>\n";3616}36173618my$has_history=0;3619my$not_deleted=0;3620for(my$i=0;$i<$diff->{'nparents'};$i++) {3621my$hash_parent=$parents[$i];3622my$from_hash=$diff->{'from_id'}[$i];3623my$from_path=$diff->{'from_file'}[$i];3624my$status=$diff->{'status'}[$i];36253626$has_history||= ($statusne'A');3627$not_deleted||= ($statusne'D');36283629if($statuseq'A') {3630print"<td class=\"link\"align=\"right\"> | </td>\n";3631}elsif($statuseq'D') {3632print"<td class=\"link\">".3633$cgi->a({-href => href(action=>"blob",3634 hash_base=>$hash,3635 hash=>$from_hash,3636 file_name=>$from_path)},3637"blob". ($i+1)) .3638" | </td>\n";3639}else{3640if($diff->{'to_id'}eq$from_hash) {3641print"<td class=\"link nochange\">";3642}else{3643print"<td class=\"link\">";3644}3645print$cgi->a({-href => href(action=>"blobdiff",3646 hash=>$diff->{'to_id'},3647 hash_parent=>$from_hash,3648 hash_base=>$hash,3649 hash_parent_base=>$hash_parent,3650 file_name=>$diff->{'to_file'},3651 file_parent=>$from_path)},3652"diff". ($i+1)) .3653" | </td>\n";3654}3655}36563657print"<td class=\"link\">";3658if($not_deleted) {3659print$cgi->a({-href => href(action=>"blob",3660 hash=>$diff->{'to_id'},3661 file_name=>$diff->{'to_file'},3662 hash_base=>$hash)},3663"blob");3664print" | "if($has_history);3665}3666if($has_history) {3667print$cgi->a({-href => href(action=>"history",3668 file_name=>$diff->{'to_file'},3669 hash_base=>$hash)},3670"history");3671}3672print"</td>\n";36733674print"</tr>\n";3675next;# instead of 'else' clause, to avoid extra indent3676}3677# else ordinary diff36783679my($to_mode_oct,$to_mode_str,$to_file_type);3680my($from_mode_oct,$from_mode_str,$from_file_type);3681if($diff->{'to_mode'}ne('0' x 6)) {3682$to_mode_oct=oct$diff->{'to_mode'};3683if(S_ISREG($to_mode_oct)) {# only for regular file3684$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits3685}3686$to_file_type= file_type($diff->{'to_mode'});3687}3688if($diff->{'from_mode'}ne('0' x 6)) {3689$from_mode_oct=oct$diff->{'from_mode'};3690if(S_ISREG($to_mode_oct)) {# only for regular file3691$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits3692}3693$from_file_type= file_type($diff->{'from_mode'});3694}36953696if($diff->{'status'}eq"A") {# created3697my$mode_chng="<span class=\"file_status new\">[new$to_file_type";3698$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;3699$mode_chng.="]</span>";3700print"<td>";3701print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3702 hash_base=>$hash, file_name=>$diff->{'file'}),3703-class=>"list"}, esc_path($diff->{'file'}));3704print"</td>\n";3705print"<td>$mode_chng</td>\n";3706print"<td class=\"link\">";3707if($actioneq'commitdiff') {3708# link to patch3709$patchno++;3710print$cgi->a({-href =>"#patch$patchno"},"patch");3711print" | ";3712}3713print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3714 hash_base=>$hash, file_name=>$diff->{'file'})},3715"blob");3716print"</td>\n";37173718}elsif($diff->{'status'}eq"D") {# deleted3719my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";3720print"<td>";3721print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3722 hash_base=>$parent, file_name=>$diff->{'file'}),3723-class=>"list"}, esc_path($diff->{'file'}));3724print"</td>\n";3725print"<td>$mode_chng</td>\n";3726print"<td class=\"link\">";3727if($actioneq'commitdiff') {3728# link to patch3729$patchno++;3730print$cgi->a({-href =>"#patch$patchno"},"patch");3731print" | ";3732}3733print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3734 hash_base=>$parent, file_name=>$diff->{'file'})},3735"blob") ." | ";3736if($have_blame) {3737print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,3738 file_name=>$diff->{'file'})},3739"blame") ." | ";3740}3741print$cgi->a({-href => href(action=>"history", hash_base=>$parent,3742 file_name=>$diff->{'file'})},3743"history");3744print"</td>\n";37453746}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed3747my$mode_chnge="";3748if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3749$mode_chnge="<span class=\"file_status mode_chnge\">[changed";3750if($from_file_typene$to_file_type) {3751$mode_chnge.=" from$from_file_typeto$to_file_type";3752}3753if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {3754if($from_mode_str&&$to_mode_str) {3755$mode_chnge.=" mode:$from_mode_str->$to_mode_str";3756}elsif($to_mode_str) {3757$mode_chnge.=" mode:$to_mode_str";3758}3759}3760$mode_chnge.="]</span>\n";3761}3762print"<td>";3763print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3764 hash_base=>$hash, file_name=>$diff->{'file'}),3765-class=>"list"}, esc_path($diff->{'file'}));3766print"</td>\n";3767print"<td>$mode_chnge</td>\n";3768print"<td class=\"link\">";3769if($actioneq'commitdiff') {3770# link to patch3771$patchno++;3772print$cgi->a({-href =>"#patch$patchno"},"patch") .3773" | ";3774}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3775# "commit" view and modified file (not onlu mode changed)3776print$cgi->a({-href => href(action=>"blobdiff",3777 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3778 hash_base=>$hash, hash_parent_base=>$parent,3779 file_name=>$diff->{'file'})},3780"diff") .3781" | ";3782}3783print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3784 hash_base=>$hash, file_name=>$diff->{'file'})},3785"blob") ." | ";3786if($have_blame) {3787print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3788 file_name=>$diff->{'file'})},3789"blame") ." | ";3790}3791print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3792 file_name=>$diff->{'file'})},3793"history");3794print"</td>\n";37953796}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied3797my%status_name= ('R'=>'moved','C'=>'copied');3798my$nstatus=$status_name{$diff->{'status'}};3799my$mode_chng="";3800if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3801# mode also for directories, so we cannot use $to_mode_str3802$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);3803}3804print"<td>".3805$cgi->a({-href => href(action=>"blob", hash_base=>$hash,3806 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),3807-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".3808"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".3809$cgi->a({-href => href(action=>"blob", hash_base=>$parent,3810 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),3811-class=>"list"}, esc_path($diff->{'from_file'})) .3812" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".3813"<td class=\"link\">";3814if($actioneq'commitdiff') {3815# link to patch3816$patchno++;3817print$cgi->a({-href =>"#patch$patchno"},"patch") .3818" | ";3819}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3820# "commit" view and modified file (not only pure rename or copy)3821print$cgi->a({-href => href(action=>"blobdiff",3822 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3823 hash_base=>$hash, hash_parent_base=>$parent,3824 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},3825"diff") .3826" | ";3827}3828print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3829 hash_base=>$parent, file_name=>$diff->{'to_file'})},3830"blob") ." | ";3831if($have_blame) {3832print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3833 file_name=>$diff->{'to_file'})},3834"blame") ." | ";3835}3836print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3837 file_name=>$diff->{'to_file'})},3838"history");3839print"</td>\n";38403841}# we should not encounter Unmerged (U) or Unknown (X) status3842print"</tr>\n";3843}3844print"</tbody>"if$has_header;3845print"</table>\n";3846}38473848sub git_patchset_body {3849my($fd,$difftree,$hash,@hash_parents) =@_;3850my($hash_parent) =$hash_parents[0];38513852my$is_combined= (@hash_parents>1);3853my$patch_idx=0;3854my$patch_number=0;3855my$patch_line;3856my$diffinfo;3857my$to_name;3858my(%from,%to);38593860print"<div class=\"patchset\">\n";38613862# skip to first patch3863while($patch_line= <$fd>) {3864chomp$patch_line;38653866last if($patch_line=~m/^diff /);3867}38683869 PATCH:3870while($patch_line) {38713872# parse "git diff" header line3873if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {3874# $1 is from_name, which we do not use3875$to_name= unquote($2);3876$to_name=~s!^b/!!;3877}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {3878# $1 is 'cc' or 'combined', which we do not use3879$to_name= unquote($2);3880}else{3881$to_name=undef;3882}38833884# check if current patch belong to current raw line3885# and parse raw git-diff line if needed3886if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {3887# this is continuation of a split patch3888print"<div class=\"patch cont\">\n";3889}else{3890# advance raw git-diff output if needed3891$patch_idx++ifdefined$diffinfo;38923893# read and prepare patch information3894$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);38953896# compact combined diff output can have some patches skipped3897# find which patch (using pathname of result) we are at now;3898if($is_combined) {3899while($to_namene$diffinfo->{'to_file'}) {3900print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".3901 format_diff_cc_simplified($diffinfo,@hash_parents) .3902"</div>\n";# class="patch"39033904$patch_idx++;3905$patch_number++;39063907last if$patch_idx>$#$difftree;3908$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);3909}3910}39113912# modifies %from, %to hashes3913 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);39143915# this is first patch for raw difftree line with $patch_idx index3916# we index @$difftree array from 0, but number patches from 13917print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";3918}39193920# git diff header3921#assert($patch_line =~ m/^diff /) if DEBUG;3922#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed3923$patch_number++;3924# print "git diff" header3925print format_git_diff_header_line($patch_line,$diffinfo,3926 \%from, \%to);39273928# print extended diff header3929print"<div class=\"diff extended_header\">\n";3930 EXTENDED_HEADER:3931while($patch_line= <$fd>) {3932chomp$patch_line;39333934last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);39353936print format_extended_diff_header_line($patch_line,$diffinfo,3937 \%from, \%to);3938}3939print"</div>\n";# class="diff extended_header"39403941# from-file/to-file diff header3942if(!$patch_line) {3943print"</div>\n";# class="patch"3944last PATCH;3945}3946next PATCH if($patch_line=~m/^diff /);3947#assert($patch_line =~ m/^---/) if DEBUG;39483949my$last_patch_line=$patch_line;3950$patch_line= <$fd>;3951chomp$patch_line;3952#assert($patch_line =~ m/^\+\+\+/) if DEBUG;39533954print format_diff_from_to_header($last_patch_line,$patch_line,3955$diffinfo, \%from, \%to,3956@hash_parents);39573958# the patch itself3959 LINE:3960while($patch_line= <$fd>) {3961chomp$patch_line;39623963next PATCH if($patch_line=~m/^diff /);39643965print format_diff_line($patch_line, \%from, \%to);3966}39673968}continue{3969print"</div>\n";# class="patch"3970}39713972# for compact combined (--cc) format, with chunk and patch simpliciaction3973# patchset might be empty, but there might be unprocessed raw lines3974for(++$patch_idxif$patch_number>0;3975$patch_idx<@$difftree;3976++$patch_idx) {3977# read and prepare patch information3978$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);39793980# generate anchor for "patch" links in difftree / whatchanged part3981print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".3982 format_diff_cc_simplified($diffinfo,@hash_parents) .3983"</div>\n";# class="patch"39843985$patch_number++;3986}39873988if($patch_number==0) {3989if(@hash_parents>1) {3990print"<div class=\"diff nodifferences\">Trivial merge</div>\n";3991}else{3992print"<div class=\"diff nodifferences\">No differences found</div>\n";3993}3994}39953996print"</div>\n";# class="patchset"3997}39983999# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40004001# fills project list info (age, description, owner, forks) for each4002# project in the list, removing invalid projects from returned list4003# NOTE: modifies $projlist, but does not remove entries from it4004sub fill_project_list_info {4005my($projlist,$check_forks) =@_;4006my@projects;40074008my$show_ctags= gitweb_check_feature('ctags');4009 PROJECT:4010foreachmy$pr(@$projlist) {4011my(@activity) = git_get_last_activity($pr->{'path'});4012unless(@activity) {4013next PROJECT;4014}4015($pr->{'age'},$pr->{'age_string'}) =@activity;4016if(!defined$pr->{'descr'}) {4017my$descr= git_get_project_description($pr->{'path'}) ||"";4018$descr= to_utf8($descr);4019$pr->{'descr_long'} =$descr;4020$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4021}4022if(!defined$pr->{'owner'}) {4023$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4024}4025if($check_forks) {4026my$pname=$pr->{'path'};4027if(($pname=~s/\.git$//) &&4028($pname!~/\/$/) &&4029(-d "$projectroot/$pname")) {4030$pr->{'forks'} ="-d$projectroot/$pname";4031}else{4032$pr->{'forks'} =0;4033}4034}4035$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4036push@projects,$pr;4037}40384039return@projects;4040}40414042# print 'sort by' <th> element, generating 'sort by $name' replay link4043# if that order is not selected4044sub print_sort_th {4045my($name,$order,$header) =@_;4046$header||=ucfirst($name);40474048if($ordereq$name) {4049print"<th>$header</th>\n";4050}else{4051print"<th>".4052$cgi->a({-href => href(-replay=>1, order=>$name),4053-class=>"header"},$header) .4054"</th>\n";4055}4056}40574058sub git_project_list_body {4059# actually uses global variable $project4060my($projlist,$order,$from,$to,$extra,$no_header) =@_;40614062my$check_forks= gitweb_check_feature('forks');4063my@projects= fill_project_list_info($projlist,$check_forks);40644065$order||=$default_projects_order;4066$from=0unlessdefined$from;4067$to=$#projectsif(!defined$to||$#projects<$to);40684069my%order_info= (4070 project => { key =>'path', type =>'str'},4071 descr => { key =>'descr_long', type =>'str'},4072 owner => { key =>'owner', type =>'str'},4073 age => { key =>'age', type =>'num'}4074);4075my$oi=$order_info{$order};4076if($oi->{'type'}eq'str') {4077@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4078}else{4079@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4080}40814082my$show_ctags= gitweb_check_feature('ctags');4083if($show_ctags) {4084my%ctags;4085foreachmy$p(@projects) {4086foreachmy$ct(keys%{$p->{'ctags'}}) {4087$ctags{$ct} +=$p->{'ctags'}->{$ct};4088}4089}4090my$cloud= git_populate_project_tagcloud(\%ctags);4091print git_show_project_tagcloud($cloud,64);4092}40934094print"<table class=\"project_list\">\n";4095unless($no_header) {4096print"<tr>\n";4097if($check_forks) {4098print"<th></th>\n";4099}4100 print_sort_th('project',$order,'Project');4101 print_sort_th('descr',$order,'Description');4102 print_sort_th('owner',$order,'Owner');4103 print_sort_th('age',$order,'Last Change');4104print"<th></th>\n".# for links4105"</tr>\n";4106}4107my$alternate=1;4108my$tagfilter=$cgi->param('by_tag');4109for(my$i=$from;$i<=$to;$i++) {4110my$pr=$projects[$i];41114112next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4113next if$searchtextand not$pr->{'path'} =~/$searchtext/4114and not$pr->{'descr_long'} =~/$searchtext/;4115# Weed out forks or non-matching entries of search4116if($check_forks) {4117my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4118$forkbase="^$forkbase"if$forkbase;4119next ifnot$searchtextand not$tagfilterand$show_ctags4120and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4121}41224123if($alternate) {4124print"<tr class=\"dark\">\n";4125}else{4126print"<tr class=\"light\">\n";4127}4128$alternate^=1;4129if($check_forks) {4130print"<td>";4131if($pr->{'forks'}) {4132print"<!--$pr->{'forks'} -->\n";4133print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4134}4135print"</td>\n";4136}4137print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4138-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4139"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4140-class=>"list", -title =>$pr->{'descr_long'}},4141 esc_html($pr->{'descr'})) ."</td>\n".4142"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4143print"<td class=\"". age_class($pr->{'age'}) ."\">".4144(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4145"<td class=\"link\">".4146$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4147$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4148$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4149$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4150($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4151"</td>\n".4152"</tr>\n";4153}4154if(defined$extra) {4155print"<tr>\n";4156if($check_forks) {4157print"<td></td>\n";4158}4159print"<td colspan=\"5\">$extra</td>\n".4160"</tr>\n";4161}4162print"</table>\n";4163}41644165sub git_shortlog_body {4166# uses global variable $project4167my($commitlist,$from,$to,$refs,$extra) =@_;41684169$from=0unlessdefined$from;4170$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);41714172print"<table class=\"shortlog\">\n";4173my$alternate=1;4174for(my$i=$from;$i<=$to;$i++) {4175my%co= %{$commitlist->[$i]};4176my$commit=$co{'id'};4177my$ref= format_ref_marker($refs,$commit);4178if($alternate) {4179print"<tr class=\"dark\">\n";4180}else{4181print"<tr class=\"light\">\n";4182}4183$alternate^=1;4184# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4185print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4186 format_author_html('td', \%co,10) ."<td>";4187print format_subject_html($co{'title'},$co{'title_short'},4188 href(action=>"commit", hash=>$commit),$ref);4189print"</td>\n".4190"<td class=\"link\">".4191$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4192$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4193$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4194my$snapshot_links= format_snapshot_links($commit);4195if(defined$snapshot_links) {4196print" | ".$snapshot_links;4197}4198print"</td>\n".4199"</tr>\n";4200}4201if(defined$extra) {4202print"<tr>\n".4203"<td colspan=\"4\">$extra</td>\n".4204"</tr>\n";4205}4206print"</table>\n";4207}42084209sub git_history_body {4210# Warning: assumes constant type (blob or tree) during history4211my($commitlist,$from,$to,$refs,$hash_base,$ftype,$extra) =@_;42124213$from=0unlessdefined$from;4214$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});42154216print"<table class=\"history\">\n";4217my$alternate=1;4218for(my$i=$from;$i<=$to;$i++) {4219my%co= %{$commitlist->[$i]};4220if(!%co) {4221next;4222}4223my$commit=$co{'id'};42244225my$ref= format_ref_marker($refs,$commit);42264227if($alternate) {4228print"<tr class=\"dark\">\n";4229}else{4230print"<tr class=\"light\">\n";4231}4232$alternate^=1;4233print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4234# shortlog: format_author_html('td', \%co, 10)4235 format_author_html('td', \%co,15,3) ."<td>";4236# originally git_history used chop_str($co{'title'}, 50)4237print format_subject_html($co{'title'},$co{'title_short'},4238 href(action=>"commit", hash=>$commit),$ref);4239print"</td>\n".4240"<td class=\"link\">".4241$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".4242$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");42434244if($ftypeeq'blob') {4245my$blob_current= git_get_hash_by_path($hash_base,$file_name);4246my$blob_parent= git_get_hash_by_path($commit,$file_name);4247if(defined$blob_current&&defined$blob_parent&&4248$blob_currentne$blob_parent) {4249print" | ".4250$cgi->a({-href => href(action=>"blobdiff",4251 hash=>$blob_current, hash_parent=>$blob_parent,4252 hash_base=>$hash_base, hash_parent_base=>$commit,4253 file_name=>$file_name)},4254"diff to current");4255}4256}4257print"</td>\n".4258"</tr>\n";4259}4260if(defined$extra) {4261print"<tr>\n".4262"<td colspan=\"4\">$extra</td>\n".4263"</tr>\n";4264}4265print"</table>\n";4266}42674268sub git_tags_body {4269# uses global variable $project4270my($taglist,$from,$to,$extra) =@_;4271$from=0unlessdefined$from;4272$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);42734274print"<table class=\"tags\">\n";4275my$alternate=1;4276for(my$i=$from;$i<=$to;$i++) {4277my$entry=$taglist->[$i];4278my%tag=%$entry;4279my$comment=$tag{'subject'};4280my$comment_short;4281if(defined$comment) {4282$comment_short= chop_str($comment,30,5);4283}4284if($alternate) {4285print"<tr class=\"dark\">\n";4286}else{4287print"<tr class=\"light\">\n";4288}4289$alternate^=1;4290if(defined$tag{'age'}) {4291print"<td><i>$tag{'age'}</i></td>\n";4292}else{4293print"<td></td>\n";4294}4295print"<td>".4296$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),4297-class=>"list name"}, esc_html($tag{'name'})) .4298"</td>\n".4299"<td>";4300if(defined$comment) {4301print format_subject_html($comment,$comment_short,4302 href(action=>"tag", hash=>$tag{'id'}));4303}4304print"</td>\n".4305"<td class=\"selflink\">";4306if($tag{'type'}eq"tag") {4307print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4308}else{4309print" ";4310}4311print"</td>\n".4312"<td class=\"link\">"." | ".4313$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4314if($tag{'reftype'}eq"commit") {4315print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4316" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4317}elsif($tag{'reftype'}eq"blob") {4318print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4319}4320print"</td>\n".4321"</tr>";4322}4323if(defined$extra) {4324print"<tr>\n".4325"<td colspan=\"5\">$extra</td>\n".4326"</tr>\n";4327}4328print"</table>\n";4329}43304331sub git_heads_body {4332# uses global variable $project4333my($headlist,$head,$from,$to,$extra) =@_;4334$from=0unlessdefined$from;4335$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);43364337print"<table class=\"heads\">\n";4338my$alternate=1;4339for(my$i=$from;$i<=$to;$i++) {4340my$entry=$headlist->[$i];4341my%ref=%$entry;4342my$curr=$ref{'id'}eq$head;4343if($alternate) {4344print"<tr class=\"dark\">\n";4345}else{4346print"<tr class=\"light\">\n";4347}4348$alternate^=1;4349print"<td><i>$ref{'age'}</i></td>\n".4350($curr?"<td class=\"current_head\">":"<td>") .4351$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4352-class=>"list name"},esc_html($ref{'name'})) .4353"</td>\n".4354"<td class=\"link\">".4355$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4356$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4357$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4358"</td>\n".4359"</tr>";4360}4361if(defined$extra) {4362print"<tr>\n".4363"<td colspan=\"3\">$extra</td>\n".4364"</tr>\n";4365}4366print"</table>\n";4367}43684369sub git_search_grep_body {4370my($commitlist,$from,$to,$extra) =@_;4371$from=0unlessdefined$from;4372$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);43734374print"<table class=\"commit_search\">\n";4375my$alternate=1;4376for(my$i=$from;$i<=$to;$i++) {4377my%co= %{$commitlist->[$i]};4378if(!%co) {4379next;4380}4381my$commit=$co{'id'};4382if($alternate) {4383print"<tr class=\"dark\">\n";4384}else{4385print"<tr class=\"light\">\n";4386}4387$alternate^=1;4388print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4389 format_author_html('td', \%co,15,5) .4390"<td>".4391$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4392-class=>"list subject"},4393 chop_and_escape_str($co{'title'},50) ."<br/>");4394my$comment=$co{'comment'};4395foreachmy$line(@$comment) {4396if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4397my($lead,$match,$trail) = ($1,$2,$3);4398$match= chop_str($match,70,5,'center');4399my$contextlen=int((80-length($match))/2);4400$contextlen=30if($contextlen>30);4401$lead= chop_str($lead,$contextlen,10,'left');4402$trail= chop_str($trail,$contextlen,10,'right');44034404$lead= esc_html($lead);4405$match= esc_html($match);4406$trail= esc_html($trail);44074408print"$lead<span class=\"match\">$match</span>$trail<br />";4409}4410}4411print"</td>\n".4412"<td class=\"link\">".4413$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4414" | ".4415$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4416" | ".4417$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4418print"</td>\n".4419"</tr>\n";4420}4421if(defined$extra) {4422print"<tr>\n".4423"<td colspan=\"3\">$extra</td>\n".4424"</tr>\n";4425}4426print"</table>\n";4427}44284429## ======================================================================4430## ======================================================================4431## actions44324433sub git_project_list {4434my$order=$input_params{'order'};4435if(defined$order&&$order!~m/none|project|descr|owner|age/) {4436 die_error(400,"Unknown order parameter");4437}44384439my@list= git_get_projects_list();4440if(!@list) {4441 die_error(404,"No projects found");4442}44434444 git_header_html();4445if(-f $home_text) {4446print"<div class=\"index_include\">\n";4447 insert_file($home_text);4448print"</div>\n";4449}4450print$cgi->startform(-method=>"get") .4451"<p class=\"projsearch\">Search:\n".4452$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4453"</p>".4454$cgi->end_form() ."\n";4455 git_project_list_body(\@list,$order);4456 git_footer_html();4457}44584459sub git_forks {4460my$order=$input_params{'order'};4461if(defined$order&&$order!~m/none|project|descr|owner|age/) {4462 die_error(400,"Unknown order parameter");4463}44644465my@list= git_get_projects_list($project);4466if(!@list) {4467 die_error(404,"No forks found");4468}44694470 git_header_html();4471 git_print_page_nav('','');4472 git_print_header_div('summary',"$projectforks");4473 git_project_list_body(\@list,$order);4474 git_footer_html();4475}44764477sub git_project_index {4478my@projects= git_get_projects_list($project);44794480print$cgi->header(4481-type =>'text/plain',4482-charset =>'utf-8',4483-content_disposition =>'inline; filename="index.aux"');44844485foreachmy$pr(@projects) {4486if(!exists$pr->{'owner'}) {4487$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4488}44894490my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4491# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4492$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4493$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4494$path=~s/ /\+/g;4495$owner=~s/ /\+/g;44964497print"$path$owner\n";4498}4499}45004501sub git_summary {4502my$descr= git_get_project_description($project) ||"none";4503my%co= parse_commit("HEAD");4504my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4505my$head=$co{'id'};45064507my$owner= git_get_project_owner($project);45084509my$refs= git_get_references();4510# These get_*_list functions return one more to allow us to see if4511# there are more ...4512my@taglist= git_get_tags_list(16);4513my@headlist= git_get_heads_list(16);4514my@forklist;4515my$check_forks= gitweb_check_feature('forks');45164517if($check_forks) {4518@forklist= git_get_projects_list($project);4519}45204521 git_header_html();4522 git_print_page_nav('summary','',$head);45234524print"<div class=\"title\"> </div>\n";4525print"<table class=\"projects_list\">\n".4526"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4527"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4528if(defined$cd{'rfc2822'}) {4529print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4530}45314532# use per project git URL list in $projectroot/$project/cloneurl4533# or make project git URL from git base URL and project name4534my$url_tag="URL";4535my@url_list= git_get_project_url_list($project);4536@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4537foreachmy$git_url(@url_list) {4538next unless$git_url;4539print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4540$url_tag="";4541}45424543# Tag cloud4544my$show_ctags= gitweb_check_feature('ctags');4545if($show_ctags) {4546my$ctags= git_get_project_ctags($project);4547my$cloud= git_populate_project_tagcloud($ctags);4548print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4549print"</td>\n<td>"unless%$ctags;4550print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4551print"</td>\n<td>"if%$ctags;4552print git_show_project_tagcloud($cloud,48);4553print"</td></tr>";4554}45554556print"</table>\n";45574558# If XSS prevention is on, we don't include README.html.4559# TODO: Allow a readme in some safe format.4560if(!$prevent_xss&& -s "$projectroot/$project/README.html") {4561print"<div class=\"title\">readme</div>\n".4562"<div class=\"readme\">\n";4563 insert_file("$projectroot/$project/README.html");4564print"\n</div>\n";# class="readme"4565}45664567# we need to request one more than 16 (0..15) to check if4568# those 16 are all4569my@commitlist=$head? parse_commits($head,17) : ();4570if(@commitlist) {4571 git_print_header_div('shortlog');4572 git_shortlog_body(\@commitlist,0,15,$refs,4573$#commitlist<=15?undef:4574$cgi->a({-href => href(action=>"shortlog")},"..."));4575}45764577if(@taglist) {4578 git_print_header_div('tags');4579 git_tags_body(\@taglist,0,15,4580$#taglist<=15?undef:4581$cgi->a({-href => href(action=>"tags")},"..."));4582}45834584if(@headlist) {4585 git_print_header_div('heads');4586 git_heads_body(\@headlist,$head,0,15,4587$#headlist<=15?undef:4588$cgi->a({-href => href(action=>"heads")},"..."));4589}45904591if(@forklist) {4592 git_print_header_div('forks');4593 git_project_list_body(\@forklist,'age',0,15,4594$#forklist<=15?undef:4595$cgi->a({-href => href(action=>"forks")},"..."),4596'no_header');4597}45984599 git_footer_html();4600}46014602sub git_tag {4603my$head= git_get_head_hash($project);4604 git_header_html();4605 git_print_page_nav('','',$head,undef,$head);4606my%tag= parse_tag($hash);46074608if(!%tag) {4609 die_error(404,"Unknown tag object");4610}46114612 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4613print"<div class=\"title_text\">\n".4614"<table class=\"object_header\">\n".4615"<tr>\n".4616"<td>object</td>\n".4617"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4618$tag{'object'}) ."</td>\n".4619"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4620$tag{'type'}) ."</td>\n".4621"</tr>\n";4622if(defined($tag{'author'})) {4623my%ad= parse_date($tag{'epoch'},$tag{'tz'});4624print"<tr><td>author</td><td>". esc_html($tag{'author'}) ."</td></tr>\n";4625print"<tr><td></td><td>".$ad{'rfc2822'} .4626sprintf(" (%02d:%02d%s)",$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'}) .4627"</td></tr>\n";4628}4629print"</table>\n\n".4630"</div>\n";4631print"<div class=\"page_body\">";4632my$comment=$tag{'comment'};4633foreachmy$line(@$comment) {4634chomp$line;4635print esc_html($line, -nbsp=>1) ."<br/>\n";4636}4637print"</div>\n";4638 git_footer_html();4639}46404641sub git_blame {4642# permissions4643 gitweb_check_feature('blame')4644or die_error(403,"Blame view not allowed");46454646# error checking4647 die_error(400,"No file name given")unless$file_name;4648$hash_base||= git_get_head_hash($project);4649 die_error(404,"Couldn't find base commit")unless$hash_base;4650my%co= parse_commit($hash_base)4651or die_error(404,"Commit not found");4652my$ftype="blob";4653if(!defined$hash) {4654$hash= git_get_hash_by_path($hash_base,$file_name,"blob")4655or die_error(404,"Error looking up file");4656}else{4657$ftype= git_get_type($hash);4658if($ftype!~"blob") {4659 die_error(400,"Object is not a blob");4660}4661}46624663# run git-blame --porcelain4664open my$fd,"-|", git_cmd(),"blame",'-p',4665$hash_base,'--',$file_name4666or die_error(500,"Open git-blame failed");46674668# page header4669 git_header_html();4670my$formats_nav=4671$cgi->a({-href => href(action=>"blob", -replay=>1)},4672"blob") .4673" | ".4674$cgi->a({-href => href(action=>"history", -replay=>1)},4675"history") .4676" | ".4677$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},4678"HEAD");4679 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4680 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4681 git_print_page_path($file_name,$ftype,$hash_base);46824683# page body4684my@rev_color=qw(light2 dark2);4685my$num_colors=scalar(@rev_color);4686my$current_color=0;4687my%metainfo= ();46884689print<<HTML;4690<div class="page_body">4691<table class="blame">4692<tr><th>Commit</th><th>Line</th><th>Data</th></tr>4693HTML4694 LINE:4695while(my$line= <$fd>) {4696chomp$line;4697# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]4698# no <lines in group> for subsequent lines in group of lines4699my($full_rev,$orig_lineno,$lineno,$group_size) =4700($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);4701if(!exists$metainfo{$full_rev}) {4702$metainfo{$full_rev} = {};4703}4704my$meta=$metainfo{$full_rev};4705my$data;4706while($data= <$fd>) {4707chomp$data;4708last if($data=~s/^\t//);# contents of line4709if($data=~/^(\S+) (.*)$/) {4710$meta->{$1} =$2;4711}4712}4713my$short_rev=substr($full_rev,0,8);4714my$author=$meta->{'author'};4715my%date=4716 parse_date($meta->{'author-time'},$meta->{'author-tz'});4717my$date=$date{'iso-tz'};4718if($group_size) {4719$current_color= ($current_color+1) %$num_colors;4720}4721print"<tr id=\"l$lineno\"class=\"$rev_color[$current_color]\">\n";4722if($group_size) {4723print"<td class=\"sha1\"";4724print" title=\"". esc_html($author) .",$date\"";4725print" rowspan=\"$group_size\""if($group_size>1);4726print">";4727print$cgi->a({-href => href(action=>"commit",4728 hash=>$full_rev,4729 file_name=>$file_name)},4730 esc_html($short_rev));4731print"</td>\n";4732}4733my$parent_commit;4734if(!exists$meta->{'parent'}) {4735open(my$dd,"-|", git_cmd(),"rev-parse","$full_rev^")4736or die_error(500,"Open git-rev-parse failed");4737$parent_commit= <$dd>;4738close$dd;4739chomp($parent_commit);4740$meta->{'parent'} =$parent_commit;4741}else{4742$parent_commit=$meta->{'parent'};4743}4744my$blamed= href(action =>'blame',4745 file_name =>$meta->{'filename'},4746 hash_base =>$parent_commit);4747print"<td class=\"linenr\">";4748print$cgi->a({ -href =>"$blamed#l$orig_lineno",4749-class=>"linenr"},4750 esc_html($lineno));4751print"</td>";4752print"<td class=\"pre\">". esc_html($data) ."</td>\n";4753print"</tr>\n";4754}4755print"</table>\n";4756print"</div>";4757close$fd4758or print"Reading blob failed\n";47594760# page footer4761 git_footer_html();4762}47634764sub git_tags {4765my$head= git_get_head_hash($project);4766 git_header_html();4767 git_print_page_nav('','',$head,undef,$head);4768 git_print_header_div('summary',$project);47694770my@tagslist= git_get_tags_list();4771if(@tagslist) {4772 git_tags_body(\@tagslist);4773}4774 git_footer_html();4775}47764777sub git_heads {4778my$head= git_get_head_hash($project);4779 git_header_html();4780 git_print_page_nav('','',$head,undef,$head);4781 git_print_header_div('summary',$project);47824783my@headslist= git_get_heads_list();4784if(@headslist) {4785 git_heads_body(\@headslist,$head);4786}4787 git_footer_html();4788}47894790sub git_blob_plain {4791my$type=shift;4792my$expires;47934794if(!defined$hash) {4795if(defined$file_name) {4796my$base=$hash_base|| git_get_head_hash($project);4797$hash= git_get_hash_by_path($base,$file_name,"blob")4798or die_error(404,"Cannot find file");4799}else{4800 die_error(400,"No file name defined");4801}4802}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4803# blobs defined by non-textual hash id's can be cached4804$expires="+1d";4805}48064807open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4808or die_error(500,"Open git-cat-file blob '$hash' failed");48094810# content-type (can include charset)4811$type= blob_contenttype($fd,$file_name,$type);48124813# "save as" filename, even when no $file_name is given4814my$save_as="$hash";4815if(defined$file_name) {4816$save_as=$file_name;4817}elsif($type=~m/^text\//) {4818$save_as.='.txt';4819}48204821# With XSS prevention on, blobs of all types except a few known safe4822# ones are served with "Content-Disposition: attachment" to make sure4823# they don't run in our security domain. For certain image types,4824# blob view writes an <img> tag referring to blob_plain view, and we4825# want to be sure not to break that by serving the image as an4826# attachment (though Firefox 3 doesn't seem to care).4827my$sandbox=$prevent_xss&&4828$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;48294830print$cgi->header(4831-type =>$type,4832-expires =>$expires,4833-content_disposition =>4834($sandbox?'attachment':'inline')4835.'; filename="'.$save_as.'"');4836local$/=undef;4837binmode STDOUT,':raw';4838print<$fd>;4839binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi4840close$fd;4841}48424843sub git_blob {4844my$expires;48454846if(!defined$hash) {4847if(defined$file_name) {4848my$base=$hash_base|| git_get_head_hash($project);4849$hash= git_get_hash_by_path($base,$file_name,"blob")4850or die_error(404,"Cannot find file");4851}else{4852 die_error(400,"No file name defined");4853}4854}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4855# blobs defined by non-textual hash id's can be cached4856$expires="+1d";4857}48584859my$have_blame= gitweb_check_feature('blame');4860open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4861or die_error(500,"Couldn't cat$file_name,$hash");4862my$mimetype= blob_mimetype($fd,$file_name);4863if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {4864close$fd;4865return git_blob_plain($mimetype);4866}4867# we can have blame only for text/* mimetype4868$have_blame&&= ($mimetype=~m!^text/!);48694870 git_header_html(undef,$expires);4871my$formats_nav='';4872if(defined$hash_base&& (my%co= parse_commit($hash_base))) {4873if(defined$file_name) {4874if($have_blame) {4875$formats_nav.=4876$cgi->a({-href => href(action=>"blame", -replay=>1)},4877"blame") .4878" | ";4879}4880$formats_nav.=4881$cgi->a({-href => href(action=>"history", -replay=>1)},4882"history") .4883" | ".4884$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},4885"raw") .4886" | ".4887$cgi->a({-href => href(action=>"blob",4888 hash_base=>"HEAD", file_name=>$file_name)},4889"HEAD");4890}else{4891$formats_nav.=4892$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},4893"raw");4894}4895 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4896 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4897}else{4898print"<div class=\"page_nav\">\n".4899"<br/><br/></div>\n".4900"<div class=\"title\">$hash</div>\n";4901}4902 git_print_page_path($file_name,"blob",$hash_base);4903print"<div class=\"page_body\">\n";4904if($mimetype=~m!^image/!) {4905print qq!<img type="$mimetype"!;4906if($file_name) {4907print qq! alt="$file_name" title="$file_name"!;4908}4909print qq! src="! .4910 href(action=>"blob_plain", hash=>$hash,4911 hash_base=>$hash_base, file_name=>$file_name) .4912 qq!"/>\n!;4913}else{4914my$nr;4915while(my$line= <$fd>) {4916chomp$line;4917$nr++;4918$line= untabify($line);4919printf"<div class=\"pre\"><a id=\"l%i\"href=\"#l%i\"class=\"linenr\">%4i</a>%s</div>\n",4920$nr,$nr,$nr, esc_html($line, -nbsp=>1);4921}4922}4923close$fd4924or print"Reading blob failed.\n";4925print"</div>";4926 git_footer_html();4927}49284929sub git_tree {4930if(!defined$hash_base) {4931$hash_base="HEAD";4932}4933if(!defined$hash) {4934if(defined$file_name) {4935$hash= git_get_hash_by_path($hash_base,$file_name,"tree");4936}else{4937$hash=$hash_base;4938}4939}4940 die_error(404,"No such tree")unlessdefined($hash);49414942my@entries= ();4943{4944local$/="\0";4945open my$fd,"-|", git_cmd(),"ls-tree",'-z',$hash4946or die_error(500,"Open git-ls-tree failed");4947@entries=map{chomp;$_} <$fd>;4948close$fd4949or die_error(404,"Reading tree failed");4950}49514952my$refs= git_get_references();4953my$ref= format_ref_marker($refs,$hash_base);4954 git_header_html();4955my$basedir='';4956my$have_blame= gitweb_check_feature('blame');4957if(defined$hash_base&& (my%co= parse_commit($hash_base))) {4958my@views_nav= ();4959if(defined$file_name) {4960push@views_nav,4961$cgi->a({-href => href(action=>"history", -replay=>1)},4962"history"),4963$cgi->a({-href => href(action=>"tree",4964 hash_base=>"HEAD", file_name=>$file_name)},4965"HEAD"),4966}4967my$snapshot_links= format_snapshot_links($hash);4968if(defined$snapshot_links) {4969# FIXME: Should be available when we have no hash base as well.4970push@views_nav,$snapshot_links;4971}4972 git_print_page_nav('tree','',$hash_base,undef,undef,join(' | ',@views_nav));4973 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);4974}else{4975undef$hash_base;4976print"<div class=\"page_nav\">\n";4977print"<br/><br/></div>\n";4978print"<div class=\"title\">$hash</div>\n";4979}4980if(defined$file_name) {4981$basedir=$file_name;4982if($basedirne''&&substr($basedir, -1)ne'/') {4983$basedir.='/';4984}4985 git_print_page_path($file_name,'tree',$hash_base);4986}4987print"<div class=\"page_body\">\n";4988print"<table class=\"tree\">\n";4989my$alternate=1;4990# '..' (top directory) link if possible4991if(defined$hash_base&&4992defined$file_name&&$file_name=~m![^/]+$!) {4993if($alternate) {4994print"<tr class=\"dark\">\n";4995}else{4996print"<tr class=\"light\">\n";4997}4998$alternate^=1;49995000my$up=$file_name;5001$up=~s!/?[^/]+$!!;5002undef$upunless$up;5003# based on git_print_tree_entry5004print'<td class="mode">'. mode_str('040000') ."</td>\n";5005print'<td class="list">';5006print$cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,5007 file_name=>$up)},5008"..");5009print"</td>\n";5010print"<td class=\"link\"></td>\n";50115012print"</tr>\n";5013}5014foreachmy$line(@entries) {5015my%t= parse_ls_tree_line($line, -z =>1);50165017if($alternate) {5018print"<tr class=\"dark\">\n";5019}else{5020print"<tr class=\"light\">\n";5021}5022$alternate^=1;50235024 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);50255026print"</tr>\n";5027}5028print"</table>\n".5029"</div>";5030 git_footer_html();5031}50325033sub git_snapshot {5034my$format=$input_params{'snapshot_format'};5035if(!@snapshot_fmts) {5036 die_error(403,"Snapshots not allowed");5037}5038# default to first supported snapshot format5039$format||=$snapshot_fmts[0];5040if($format!~m/^[a-z0-9]+$/) {5041 die_error(400,"Invalid snapshot format parameter");5042}elsif(!exists($known_snapshot_formats{$format})) {5043 die_error(400,"Unknown snapshot format");5044}elsif(!grep($_eq$format,@snapshot_fmts)) {5045 die_error(403,"Unsupported snapshot format");5046}50475048if(!defined$hash) {5049$hash= git_get_head_hash($project);5050}50515052my$name=$project;5053$name=~ s,([^/])/*\.git$,$1,;5054$name= basename($name);5055my$filename= to_utf8($name);5056$name=~s/\047/\047\\\047\047/g;5057my$cmd;5058$filename.="-$hash$known_snapshot_formats{$format}{'suffix'}";5059$cmd= quote_command(5060 git_cmd(),'archive',5061"--format=$known_snapshot_formats{$format}{'format'}",5062"--prefix=$name/",$hash);5063if(exists$known_snapshot_formats{$format}{'compressor'}) {5064$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});5065}50665067print$cgi->header(5068-type =>$known_snapshot_formats{$format}{'type'},5069-content_disposition =>'inline; filename="'."$filename".'"',5070-status =>'200 OK');50715072open my$fd,"-|",$cmd5073or die_error(500,"Execute git-archive failed");5074binmode STDOUT,':raw';5075print<$fd>;5076binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi5077close$fd;5078}50795080sub git_log {5081my$head= git_get_head_hash($project);5082if(!defined$hash) {5083$hash=$head;5084}5085if(!defined$page) {5086$page=0;5087}5088my$refs= git_get_references();50895090my@commitlist= parse_commits($hash,101, (100*$page));50915092my$paging_nav= format_paging_nav('log',$hash,$head,$page,$#commitlist>=100);50935094my($patch_max) = gitweb_get_feature('patches');5095if($patch_max) {5096if($patch_max<0||@commitlist<=$patch_max) {5097$paging_nav.=" ⋅ ".5098$cgi->a({-href => href(action=>"patches", -replay=>1)},5099"patches");5100}5101}51025103 git_header_html();5104 git_print_page_nav('log','',$hash,undef,undef,$paging_nav);51055106if(!@commitlist) {5107my%co= parse_commit($hash);51085109 git_print_header_div('summary',$project);5110print"<div class=\"page_body\"> Last change$co{'age_string'}.<br/><br/></div>\n";5111}5112my$to= ($#commitlist>=99) ? (99) : ($#commitlist);5113for(my$i=0;$i<=$to;$i++) {5114my%co= %{$commitlist[$i]};5115next if!%co;5116my$commit=$co{'id'};5117my$ref= format_ref_marker($refs,$commit);5118my%ad= parse_date($co{'author_epoch'});5119 git_print_header_div('commit',5120"<span class=\"age\">$co{'age_string'}</span>".5121 esc_html($co{'title'}) .$ref,5122$commit);5123print"<div class=\"title_text\">\n".5124"<div class=\"log_link\">\n".5125$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .5126" | ".5127$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .5128" | ".5129$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .5130"<br/>\n".5131"</div>\n";5132 git_print_authorship(\%co, -tag =>'span');5133print"<br/>\n</div>\n";51345135print"<div class=\"log_body\">\n";5136 git_print_log($co{'comment'}, -final_empty_line=>1);5137print"</div>\n";5138}5139if($#commitlist>=100) {5140print"<div class=\"page_nav\">\n";5141print$cgi->a({-href => href(-replay=>1, page=>$page+1),5142-accesskey =>"n", -title =>"Alt-n"},"next");5143print"</div>\n";5144}5145 git_footer_html();5146}51475148sub git_commit {5149$hash||=$hash_base||"HEAD";5150my%co= parse_commit($hash)5151or die_error(404,"Unknown commit object");51525153my$parent=$co{'parent'};5154my$parents=$co{'parents'};# listref51555156# we need to prepare $formats_nav before any parameter munging5157my$formats_nav;5158if(!defined$parent) {5159# --root commitdiff5160$formats_nav.='(initial)';5161}elsif(@$parents==1) {5162# single parent commit5163$formats_nav.=5164'(parent: '.5165$cgi->a({-href => href(action=>"commit",5166 hash=>$parent)},5167 esc_html(substr($parent,0,7))) .5168')';5169}else{5170# merge commit5171$formats_nav.=5172'(merge: '.5173join(' ',map{5174$cgi->a({-href => href(action=>"commit",5175 hash=>$_)},5176 esc_html(substr($_,0,7)));5177}@$parents) .5178')';5179}5180if(gitweb_check_feature('patches')) {5181$formats_nav.=" | ".5182$cgi->a({-href => href(action=>"patch", -replay=>1)},5183"patch");5184}51855186if(!defined$parent) {5187$parent="--root";5188}5189my@difftree;5190open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",5191@diff_opts,5192(@$parents<=1?$parent:'-c'),5193$hash,"--"5194or die_error(500,"Open git-diff-tree failed");5195@difftree=map{chomp;$_} <$fd>;5196close$fdor die_error(404,"Reading git-diff-tree failed");51975198# non-textual hash id's can be cached5199my$expires;5200if($hash=~m/^[0-9a-fA-F]{40}$/) {5201$expires="+1d";5202}5203my$refs= git_get_references();5204my$ref= format_ref_marker($refs,$co{'id'});52055206 git_header_html(undef,$expires);5207 git_print_page_nav('commit','',5208$hash,$co{'tree'},$hash,5209$formats_nav);52105211if(defined$co{'parent'}) {5212 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);5213}else{5214 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);5215}5216print"<div class=\"title_text\">\n".5217"<table class=\"object_header\">\n";5218 git_print_authorship_rows(\%co);5219print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";5220print"<tr>".5221"<td>tree</td>".5222"<td class=\"sha1\">".5223$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),5224class=>"list"},$co{'tree'}) .5225"</td>".5226"<td class=\"link\">".5227$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},5228"tree");5229my$snapshot_links= format_snapshot_links($hash);5230if(defined$snapshot_links) {5231print" | ".$snapshot_links;5232}5233print"</td>".5234"</tr>\n";52355236foreachmy$par(@$parents) {5237print"<tr>".5238"<td>parent</td>".5239"<td class=\"sha1\">".5240$cgi->a({-href => href(action=>"commit", hash=>$par),5241class=>"list"},$par) .5242"</td>".5243"<td class=\"link\">".5244$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .5245" | ".5246$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .5247"</td>".5248"</tr>\n";5249}5250print"</table>".5251"</div>\n";52525253print"<div class=\"page_body\">\n";5254 git_print_log($co{'comment'});5255print"</div>\n";52565257 git_difftree_body(\@difftree,$hash,@$parents);52585259 git_footer_html();5260}52615262sub git_object {5263# object is defined by:5264# - hash or hash_base alone5265# - hash_base and file_name5266my$type;52675268# - hash or hash_base alone5269if($hash|| ($hash_base&& !defined$file_name)) {5270my$object_id=$hash||$hash_base;52715272open my$fd,"-|", quote_command(5273 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'5274or die_error(404,"Object does not exist");5275$type= <$fd>;5276chomp$type;5277close$fd5278or die_error(404,"Object does not exist");52795280# - hash_base and file_name5281}elsif($hash_base&&defined$file_name) {5282$file_name=~ s,/+$,,;52835284system(git_cmd(),"cat-file",'-e',$hash_base) ==05285or die_error(404,"Base object does not exist");52865287# here errors should not hapen5288open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name5289or die_error(500,"Open git-ls-tree failed");5290my$line= <$fd>;5291close$fd;52925293#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'5294unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {5295 die_error(404,"File or directory for given base does not exist");5296}5297$type=$2;5298$hash=$3;5299}else{5300 die_error(400,"Not enough information to find object");5301}53025303print$cgi->redirect(-uri => href(action=>$type, -full=>1,5304 hash=>$hash, hash_base=>$hash_base,5305 file_name=>$file_name),5306-status =>'302 Found');5307}53085309sub git_blobdiff {5310my$format=shift||'html';53115312my$fd;5313my@difftree;5314my%diffinfo;5315my$expires;53165317# preparing $fd and %diffinfo for git_patchset_body5318# new style URI5319if(defined$hash_base&&defined$hash_parent_base) {5320if(defined$file_name) {5321# read raw output5322open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5323$hash_parent_base,$hash_base,5324"--", (defined$file_parent?$file_parent: ()),$file_name5325or die_error(500,"Open git-diff-tree failed");5326@difftree=map{chomp;$_} <$fd>;5327close$fd5328or die_error(404,"Reading git-diff-tree failed");5329@difftree5330or die_error(404,"Blob diff not found");53315332}elsif(defined$hash&&5333$hash=~/[0-9a-fA-F]{40}/) {5334# try to find filename from $hash53355336# read filtered raw output5337open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5338$hash_parent_base,$hash_base,"--"5339or die_error(500,"Open git-diff-tree failed");5340@difftree=5341# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5342# $hash == to_id5343grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5344map{chomp;$_} <$fd>;5345close$fd5346or die_error(404,"Reading git-diff-tree failed");5347@difftree5348or die_error(404,"Blob diff not found");53495350}else{5351 die_error(400,"Missing one of the blob diff parameters");5352}53535354if(@difftree>1) {5355 die_error(400,"Ambiguous blob diff specification");5356}53575358%diffinfo= parse_difftree_raw_line($difftree[0]);5359$file_parent||=$diffinfo{'from_file'} ||$file_name;5360$file_name||=$diffinfo{'to_file'};53615362$hash_parent||=$diffinfo{'from_id'};5363$hash||=$diffinfo{'to_id'};53645365# non-textual hash id's can be cached5366if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5367$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5368$expires='+1d';5369}53705371# open patch output5372open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5373'-p', ($formateq'html'?"--full-index": ()),5374$hash_parent_base,$hash_base,5375"--", (defined$file_parent?$file_parent: ()),$file_name5376or die_error(500,"Open git-diff-tree failed");5377}53785379# old/legacy style URI -- not generated anymore since 1.4.3.5380if(!%diffinfo) {5381 die_error('404 Not Found',"Missing one of the blob diff parameters")5382}53835384# header5385if($formateq'html') {5386my$formats_nav=5387$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5388"raw");5389 git_header_html(undef,$expires);5390if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5391 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5392 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5393}else{5394print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5395print"<div class=\"title\">$hashvs$hash_parent</div>\n";5396}5397if(defined$file_name) {5398 git_print_page_path($file_name,"blob",$hash_base);5399}else{5400print"<div class=\"page_path\"></div>\n";5401}54025403}elsif($formateq'plain') {5404print$cgi->header(5405-type =>'text/plain',5406-charset =>'utf-8',5407-expires =>$expires,5408-content_disposition =>'inline; filename="'."$file_name".'.patch"');54095410print"X-Git-Url: ".$cgi->self_url() ."\n\n";54115412}else{5413 die_error(400,"Unknown blobdiff format");5414}54155416# patch5417if($formateq'html') {5418print"<div class=\"page_body\">\n";54195420 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5421close$fd;54225423print"</div>\n";# class="page_body"5424 git_footer_html();54255426}else{5427while(my$line= <$fd>) {5428$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5429$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;54305431print$line;54325433last if$line=~m!^\+\+\+!;5434}5435local$/=undef;5436print<$fd>;5437close$fd;5438}5439}54405441sub git_blobdiff_plain {5442 git_blobdiff('plain');5443}54445445sub git_commitdiff {5446my%params=@_;5447my$format=$params{-format} ||'html';54485449my($patch_max) = gitweb_get_feature('patches');5450if($formateq'patch') {5451 die_error(403,"Patch view not allowed")unless$patch_max;5452}54535454$hash||=$hash_base||"HEAD";5455my%co= parse_commit($hash)5456or die_error(404,"Unknown commit object");54575458# choose format for commitdiff for merge5459if(!defined$hash_parent&& @{$co{'parents'}} >1) {5460$hash_parent='--cc';5461}5462# we need to prepare $formats_nav before almost any parameter munging5463my$formats_nav;5464if($formateq'html') {5465$formats_nav=5466$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},5467"raw");5468if($patch_max) {5469$formats_nav.=" | ".5470$cgi->a({-href => href(action=>"patch", -replay=>1)},5471"patch");5472}54735474if(defined$hash_parent&&5475$hash_parentne'-c'&&$hash_parentne'--cc') {5476# commitdiff with two commits given5477my$hash_parent_short=$hash_parent;5478if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {5479$hash_parent_short=substr($hash_parent,0,7);5480}5481$formats_nav.=5482' (from';5483for(my$i=0;$i< @{$co{'parents'}};$i++) {5484if($co{'parents'}[$i]eq$hash_parent) {5485$formats_nav.=' parent '. ($i+1);5486last;5487}5488}5489$formats_nav.=': '.5490$cgi->a({-href => href(action=>"commitdiff",5491 hash=>$hash_parent)},5492 esc_html($hash_parent_short)) .5493')';5494}elsif(!$co{'parent'}) {5495# --root commitdiff5496$formats_nav.=' (initial)';5497}elsif(scalar@{$co{'parents'}} ==1) {5498# single parent commit5499$formats_nav.=5500' (parent: '.5501$cgi->a({-href => href(action=>"commitdiff",5502 hash=>$co{'parent'})},5503 esc_html(substr($co{'parent'},0,7))) .5504')';5505}else{5506# merge commit5507if($hash_parenteq'--cc') {5508$formats_nav.=' | '.5509$cgi->a({-href => href(action=>"commitdiff",5510 hash=>$hash, hash_parent=>'-c')},5511'combined');5512}else{# $hash_parent eq '-c'5513$formats_nav.=' | '.5514$cgi->a({-href => href(action=>"commitdiff",5515 hash=>$hash, hash_parent=>'--cc')},5516'compact');5517}5518$formats_nav.=5519' (merge: '.5520join(' ',map{5521$cgi->a({-href => href(action=>"commitdiff",5522 hash=>$_)},5523 esc_html(substr($_,0,7)));5524} @{$co{'parents'}} ) .5525')';5526}5527}55285529my$hash_parent_param=$hash_parent;5530if(!defined$hash_parent_param) {5531# --cc for multiple parents, --root for parentless5532$hash_parent_param=5533@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';5534}55355536# read commitdiff5537my$fd;5538my@difftree;5539if($formateq'html') {5540open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5541"--no-commit-id","--patch-with-raw","--full-index",5542$hash_parent_param,$hash,"--"5543or die_error(500,"Open git-diff-tree failed");55445545while(my$line= <$fd>) {5546chomp$line;5547# empty line ends raw part of diff-tree output5548last unless$line;5549push@difftree,scalar parse_difftree_raw_line($line);5550}55515552}elsif($formateq'plain') {5553open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5554'-p',$hash_parent_param,$hash,"--"5555or die_error(500,"Open git-diff-tree failed");5556}elsif($formateq'patch') {5557# For commit ranges, we limit the output to the number of5558# patches specified in the 'patches' feature.5559# For single commits, we limit the output to a single patch,5560# diverging from the git-format-patch default.5561my@commit_spec= ();5562if($hash_parent) {5563if($patch_max>0) {5564push@commit_spec,"-$patch_max";5565}5566push@commit_spec,'-n',"$hash_parent..$hash";5567}else{5568if($params{-single}) {5569push@commit_spec,'-1';5570}else{5571if($patch_max>0) {5572push@commit_spec,"-$patch_max";5573}5574push@commit_spec,"-n";5575}5576push@commit_spec,'--root',$hash;5577}5578open$fd,"-|", git_cmd(),"format-patch",'--encoding=utf8',5579'--stdout',@commit_spec5580or die_error(500,"Open git-format-patch failed");5581}else{5582 die_error(400,"Unknown commitdiff format");5583}55845585# non-textual hash id's can be cached5586my$expires;5587if($hash=~m/^[0-9a-fA-F]{40}$/) {5588$expires="+1d";5589}55905591# write commit message5592if($formateq'html') {5593my$refs= git_get_references();5594my$ref= format_ref_marker($refs,$co{'id'});55955596 git_header_html(undef,$expires);5597 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);5598 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);5599 git_print_authorship(\%co, -localtime=>1);5600print"<div class=\"page_body\">\n";5601if(@{$co{'comment'}} >1) {5602print"<div class=\"log\">\n";5603 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);5604print"</div>\n";# class="log"5605}56065607}elsif($formateq'plain') {5608my$refs= git_get_references("tags");5609my$tagname= git_get_rev_name_tags($hash);5610my$filename= basename($project) ."-$hash.patch";56115612print$cgi->header(5613-type =>'text/plain',5614-charset =>'utf-8',5615-expires =>$expires,5616-content_disposition =>'inline; filename="'."$filename".'"');5617my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5618print"From: ". to_utf8($co{'author'}) ."\n";5619print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";5620print"Subject: ". to_utf8($co{'title'}) ."\n";56215622print"X-Git-Tag:$tagname\n"if$tagname;5623print"X-Git-Url: ".$cgi->self_url() ."\n\n";56245625foreachmy$line(@{$co{'comment'}}) {5626print to_utf8($line) ."\n";5627}5628print"---\n\n";5629}elsif($formateq'patch') {5630my$filename= basename($project) ."-$hash.patch";56315632print$cgi->header(5633-type =>'text/plain',5634-charset =>'utf-8',5635-expires =>$expires,5636-content_disposition =>'inline; filename="'."$filename".'"');5637}56385639# write patch5640if($formateq'html') {5641my$use_parents= !defined$hash_parent||5642$hash_parenteq'-c'||$hash_parenteq'--cc';5643 git_difftree_body(\@difftree,$hash,5644$use_parents? @{$co{'parents'}} :$hash_parent);5645print"<br/>\n";56465647 git_patchset_body($fd, \@difftree,$hash,5648$use_parents? @{$co{'parents'}} :$hash_parent);5649close$fd;5650print"</div>\n";# class="page_body"5651 git_footer_html();56525653}elsif($formateq'plain') {5654local$/=undef;5655print<$fd>;5656close$fd5657or print"Reading git-diff-tree failed\n";5658}elsif($formateq'patch') {5659local$/=undef;5660print<$fd>;5661close$fd5662or print"Reading git-format-patch failed\n";5663}5664}56655666sub git_commitdiff_plain {5667 git_commitdiff(-format =>'plain');5668}56695670# format-patch-style patches5671sub git_patch {5672 git_commitdiff(-format =>'patch', -single=>1);5673}56745675sub git_patches {5676 git_commitdiff(-format =>'patch');5677}56785679sub git_history {5680if(!defined$hash_base) {5681$hash_base= git_get_head_hash($project);5682}5683if(!defined$page) {5684$page=0;5685}5686my$ftype;5687my%co= parse_commit($hash_base)5688or die_error(404,"Unknown commit object");56895690my$refs= git_get_references();5691my$limit=sprintf("--max-count=%i", (100* ($page+1)));56925693my@commitlist= parse_commits($hash_base,101, (100*$page),5694$file_name,"--full-history")5695or die_error(404,"No such file or directory on given branch");56965697if(!defined$hash&&defined$file_name) {5698# some commits could have deleted file in question,5699# and not have it in tree, but one of them has to have it5700for(my$i=0;$i<=@commitlist;$i++) {5701$hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5702last ifdefined$hash;5703}5704}5705if(defined$hash) {5706$ftype= git_get_type($hash);5707}5708if(!defined$ftype) {5709 die_error(500,"Unknown type of object");5710}57115712my$paging_nav='';5713if($page>0) {5714$paging_nav.=5715$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,5716 file_name=>$file_name)},5717"first");5718$paging_nav.=" ⋅ ".5719$cgi->a({-href => href(-replay=>1, page=>$page-1),5720-accesskey =>"p", -title =>"Alt-p"},"prev");5721}else{5722$paging_nav.="first";5723$paging_nav.=" ⋅ prev";5724}5725my$next_link='';5726if($#commitlist>=100) {5727$next_link=5728$cgi->a({-href => href(-replay=>1, page=>$page+1),5729-accesskey =>"n", -title =>"Alt-n"},"next");5730$paging_nav.=" ⋅$next_link";5731}else{5732$paging_nav.=" ⋅ next";5733}57345735 git_header_html();5736 git_print_page_nav('history','',$hash_base,$co{'tree'},$hash_base,$paging_nav);5737 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5738 git_print_page_path($file_name,$ftype,$hash_base);57395740 git_history_body(\@commitlist,0,99,5741$refs,$hash_base,$ftype,$next_link);57425743 git_footer_html();5744}57455746sub git_search {5747 gitweb_check_feature('search')or die_error(403,"Search is disabled");5748if(!defined$searchtext) {5749 die_error(400,"Text field is empty");5750}5751if(!defined$hash) {5752$hash= git_get_head_hash($project);5753}5754my%co= parse_commit($hash);5755if(!%co) {5756 die_error(404,"Unknown commit object");5757}5758if(!defined$page) {5759$page=0;5760}57615762$searchtype||='commit';5763if($searchtypeeq'pickaxe') {5764# pickaxe may take all resources of your box and run for several minutes5765# with every query - so decide by yourself how public you make this feature5766 gitweb_check_feature('pickaxe')5767or die_error(403,"Pickaxe is disabled");5768}5769if($searchtypeeq'grep') {5770 gitweb_check_feature('grep')5771or die_error(403,"Grep is disabled");5772}57735774 git_header_html();57755776if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {5777my$greptype;5778if($searchtypeeq'commit') {5779$greptype="--grep=";5780}elsif($searchtypeeq'author') {5781$greptype="--author=";5782}elsif($searchtypeeq'committer') {5783$greptype="--committer=";5784}5785$greptype.=$searchtext;5786my@commitlist= parse_commits($hash,101, (100*$page),undef,5787$greptype,'--regexp-ignore-case',5788$search_use_regexp?'--extended-regexp':'--fixed-strings');57895790my$paging_nav='';5791if($page>0) {5792$paging_nav.=5793$cgi->a({-href => href(action=>"search", hash=>$hash,5794 searchtext=>$searchtext,5795 searchtype=>$searchtype)},5796"first");5797$paging_nav.=" ⋅ ".5798$cgi->a({-href => href(-replay=>1, page=>$page-1),5799-accesskey =>"p", -title =>"Alt-p"},"prev");5800}else{5801$paging_nav.="first";5802$paging_nav.=" ⋅ prev";5803}5804my$next_link='';5805if($#commitlist>=100) {5806$next_link=5807$cgi->a({-href => href(-replay=>1, page=>$page+1),5808-accesskey =>"n", -title =>"Alt-n"},"next");5809$paging_nav.=" ⋅$next_link";5810}else{5811$paging_nav.=" ⋅ next";5812}58135814if($#commitlist>=100) {5815}58165817 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);5818 git_print_header_div('commit', esc_html($co{'title'}),$hash);5819 git_search_grep_body(\@commitlist,0,99,$next_link);5820}58215822if($searchtypeeq'pickaxe') {5823 git_print_page_nav('','',$hash,$co{'tree'},$hash);5824 git_print_header_div('commit', esc_html($co{'title'}),$hash);58255826print"<table class=\"pickaxe search\">\n";5827my$alternate=1;5828local$/="\n";5829open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,5830'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",5831($search_use_regexp?'--pickaxe-regex': ());5832undef%co;5833my@files;5834while(my$line= <$fd>) {5835chomp$line;5836next unless$line;58375838my%set= parse_difftree_raw_line($line);5839if(defined$set{'commit'}) {5840# finish previous commit5841if(%co) {5842print"</td>\n".5843"<td class=\"link\">".5844$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5845" | ".5846$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5847print"</td>\n".5848"</tr>\n";5849}58505851if($alternate) {5852print"<tr class=\"dark\">\n";5853}else{5854print"<tr class=\"light\">\n";5855}5856$alternate^=1;5857%co= parse_commit($set{'commit'});5858my$author= chop_and_escape_str($co{'author_name'},15,5);5859print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5860"<td><i>$author</i></td>\n".5861"<td>".5862$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),5863-class=>"list subject"},5864 chop_and_escape_str($co{'title'},50) ."<br/>");5865}elsif(defined$set{'to_id'}) {5866next if($set{'to_id'} =~m/^0{40}$/);58675868print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},5869 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),5870-class=>"list"},5871"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .5872"<br/>\n";5873}5874}5875close$fd;58765877# finish last commit (warning: repetition!)5878if(%co) {5879print"</td>\n".5880"<td class=\"link\">".5881$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5882" | ".5883$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5884print"</td>\n".5885"</tr>\n";5886}58875888print"</table>\n";5889}58905891if($searchtypeeq'grep') {5892 git_print_page_nav('','',$hash,$co{'tree'},$hash);5893 git_print_header_div('commit', esc_html($co{'title'}),$hash);58945895print"<table class=\"grep_search\">\n";5896my$alternate=1;5897my$matches=0;5898local$/="\n";5899open my$fd,"-|", git_cmd(),'grep','-n',5900$search_use_regexp? ('-E','-i') :'-F',5901$searchtext,$co{'tree'};5902my$lastfile='';5903while(my$line= <$fd>) {5904chomp$line;5905my($file,$lno,$ltext,$binary);5906last if($matches++>1000);5907if($line=~/^Binary file (.+) matches$/) {5908$file=$1;5909$binary=1;5910}else{5911(undef,$file,$lno,$ltext) =split(/:/,$line,4);5912}5913if($filene$lastfile) {5914$lastfileand print"</td></tr>\n";5915if($alternate++) {5916print"<tr class=\"dark\">\n";5917}else{5918print"<tr class=\"light\">\n";5919}5920print"<td class=\"list\">".5921$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5922 file_name=>"$file"),5923-class=>"list"}, esc_path($file));5924print"</td><td>\n";5925$lastfile=$file;5926}5927if($binary) {5928print"<div class=\"binary\">Binary file</div>\n";5929}else{5930$ltext= untabify($ltext);5931if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {5932$ltext= esc_html($1, -nbsp=>1);5933$ltext.='<span class="match">';5934$ltext.= esc_html($2, -nbsp=>1);5935$ltext.='</span>';5936$ltext.= esc_html($3, -nbsp=>1);5937}else{5938$ltext= esc_html($ltext, -nbsp=>1);5939}5940print"<div class=\"pre\">".5941$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5942 file_name=>"$file").'#l'.$lno,5943-class=>"linenr"},sprintf('%4i',$lno))5944.' '.$ltext."</div>\n";5945}5946}5947if($lastfile) {5948print"</td></tr>\n";5949if($matches>1000) {5950print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";5951}5952}else{5953print"<div class=\"diff nodifferences\">No matches found</div>\n";5954}5955close$fd;59565957print"</table>\n";5958}5959 git_footer_html();5960}59615962sub git_search_help {5963 git_header_html();5964 git_print_page_nav('','',$hash,$hash,$hash);5965print<<EOT;5966<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without5967regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,5968the pattern entered is recognized as the POSIX extended5969<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case5970insensitive).</p>5971<dl>5972<dt><b>commit</b></dt>5973<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>5974EOT5975my$have_grep= gitweb_check_feature('grep');5976if($have_grep) {5977print<<EOT;5978<dt><b>grep</b></dt>5979<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing5980 a different one) are searched for the given pattern. On large trees, this search can take5981a while and put some strain on the server, so please use it with some consideration. Note that5982due to git-grep peculiarity, currently if regexp mode is turned off, the matches are5983case-sensitive.</dd>5984EOT5985}5986print<<EOT;5987<dt><b>author</b></dt>5988<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>5989<dt><b>committer</b></dt>5990<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>5991EOT5992my$have_pickaxe= gitweb_check_feature('pickaxe');5993if($have_pickaxe) {5994print<<EOT;5995<dt><b>pickaxe</b></dt>5996<dd>All commits that caused the string to appear or disappear from any file (changes that5997added, removed or "modified" the string) will be listed. This search can take a while and5998takes a lot of strain on the server, so please use it wisely. Note that since you may be5999interested even in changes just changing the case as well, this search is case sensitive.</dd>6000EOT6001}6002print"</dl>\n";6003 git_footer_html();6004}60056006sub git_shortlog {6007my$head= git_get_head_hash($project);6008if(!defined$hash) {6009$hash=$head;6010}6011if(!defined$page) {6012$page=0;6013}6014my$refs= git_get_references();60156016my$commit_hash=$hash;6017if(defined$hash_parent) {6018$commit_hash="$hash_parent..$hash";6019}6020my@commitlist= parse_commits($commit_hash,101, (100*$page));60216022my$paging_nav= format_paging_nav('shortlog',$hash,$head,$page,$#commitlist>=100);6023my$next_link='';6024if($#commitlist>=100) {6025$next_link=6026$cgi->a({-href => href(-replay=>1, page=>$page+1),6027-accesskey =>"n", -title =>"Alt-n"},"next");6028}6029my$patch_max= gitweb_check_feature('patches');6030if($patch_max) {6031if($patch_max<0||@commitlist<=$patch_max) {6032$paging_nav.=" ⋅ ".6033$cgi->a({-href => href(action=>"patches", -replay=>1)},6034"patches");6035}6036}60376038 git_header_html();6039 git_print_page_nav('shortlog','',$hash,$hash,$hash,$paging_nav);6040 git_print_header_div('summary',$project);60416042 git_shortlog_body(\@commitlist,0,99,$refs,$next_link);60436044 git_footer_html();6045}60466047## ......................................................................6048## feeds (RSS, Atom; OPML)60496050sub git_feed {6051my$format=shift||'atom';6052my$have_blame= gitweb_check_feature('blame');60536054# Atom: http://www.atomenabled.org/developers/syndication/6055# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ6056if($formatne'rss'&&$formatne'atom') {6057 die_error(400,"Unknown web feed format");6058}60596060# log/feed of current (HEAD) branch, log of given branch, history of file/directory6061my$head=$hash||'HEAD';6062my@commitlist= parse_commits($head,150,0,$file_name);60636064my%latest_commit;6065my%latest_date;6066my$content_type="application/$format+xml";6067if(defined$cgi->http('HTTP_ACCEPT') &&6068$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {6069# browser (feed reader) prefers text/xml6070$content_type='text/xml';6071}6072if(defined($commitlist[0])) {6073%latest_commit= %{$commitlist[0]};6074my$latest_epoch=$latest_commit{'committer_epoch'};6075%latest_date= parse_date($latest_epoch);6076my$if_modified=$cgi->http('IF_MODIFIED_SINCE');6077if(defined$if_modified) {6078my$since;6079if(eval{require HTTP::Date;1; }) {6080$since= HTTP::Date::str2time($if_modified);6081}elsif(eval{require Time::ParseDate;1; }) {6082$since= Time::ParseDate::parsedate($if_modified, GMT =>1);6083}6084if(defined$since&&$latest_epoch<=$since) {6085print$cgi->header(6086-type =>$content_type,6087-charset =>'utf-8',6088-last_modified =>$latest_date{'rfc2822'},6089-status =>'304 Not Modified');6090return;6091}6092}6093print$cgi->header(6094-type =>$content_type,6095-charset =>'utf-8',6096-last_modified =>$latest_date{'rfc2822'});6097}else{6098print$cgi->header(6099-type =>$content_type,6100-charset =>'utf-8');6101}61026103# Optimization: skip generating the body if client asks only6104# for Last-Modified date.6105return if($cgi->request_method()eq'HEAD');61066107# header variables6108my$title="$site_name-$project/$action";6109my$feed_type='log';6110if(defined$hash) {6111$title.=" - '$hash'";6112$feed_type='branch log';6113if(defined$file_name) {6114$title.=" ::$file_name";6115$feed_type='history';6116}6117}elsif(defined$file_name) {6118$title.=" -$file_name";6119$feed_type='history';6120}6121$title.="$feed_type";6122my$descr= git_get_project_description($project);6123if(defined$descr) {6124$descr= esc_html($descr);6125}else{6126$descr="$project".6127($formateq'rss'?'RSS':'Atom') .6128" feed";6129}6130my$owner= git_get_project_owner($project);6131$owner= esc_html($owner);61326133#header6134my$alt_url;6135if(defined$file_name) {6136$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);6137}elsif(defined$hash) {6138$alt_url= href(-full=>1, action=>"log", hash=>$hash);6139}else{6140$alt_url= href(-full=>1, action=>"summary");6141}6142print qq!<?xml version="1.0" encoding="utf-8"?>\n!;6143if($formateq'rss') {6144print<<XML;6145<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">6146<channel>6147XML6148print"<title>$title</title>\n".6149"<link>$alt_url</link>\n".6150"<description>$descr</description>\n".6151"<language>en</language>\n".6152# project owner is responsible for 'editorial' content6153"<managingEditor>$owner</managingEditor>\n";6154if(defined$logo||defined$favicon) {6155# prefer the logo to the favicon, since RSS6156# doesn't allow both6157my$img= esc_url($logo||$favicon);6158print"<image>\n".6159"<url>$img</url>\n".6160"<title>$title</title>\n".6161"<link>$alt_url</link>\n".6162"</image>\n";6163}6164if(%latest_date) {6165print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";6166print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";6167}6168print"<generator>gitweb v.$version/$git_version</generator>\n";6169}elsif($formateq'atom') {6170print<<XML;6171<feed xmlns="http://www.w3.org/2005/Atom">6172XML6173print"<title>$title</title>\n".6174"<subtitle>$descr</subtitle>\n".6175'<link rel="alternate" type="text/html" href="'.6176$alt_url.'" />'."\n".6177'<link rel="self" type="'.$content_type.'" href="'.6178$cgi->self_url() .'" />'."\n".6179"<id>". href(-full=>1) ."</id>\n".6180# use project owner for feed author6181"<author><name>$owner</name></author>\n";6182if(defined$favicon) {6183print"<icon>". esc_url($favicon) ."</icon>\n";6184}6185if(defined$logo_url) {6186# not twice as wide as tall: 72 x 27 pixels6187print"<logo>". esc_url($logo) ."</logo>\n";6188}6189if(!%latest_date) {6190# dummy date to keep the feed valid until commits trickle in:6191print"<updated>1970-01-01T00:00:00Z</updated>\n";6192}else{6193print"<updated>$latest_date{'iso-8601'}</updated>\n";6194}6195print"<generator version='$version/$git_version'>gitweb</generator>\n";6196}61976198# contents6199for(my$i=0;$i<=$#commitlist;$i++) {6200my%co= %{$commitlist[$i]};6201my$commit=$co{'id'};6202# we read 150, we always show 30 and the ones more recent than 48 hours6203if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {6204last;6205}6206my%cd= parse_date($co{'author_epoch'});62076208# get list of changed files6209open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6210$co{'parent'} ||"--root",6211$co{'id'},"--", (defined$file_name?$file_name: ())6212ornext;6213my@difftree=map{chomp;$_} <$fd>;6214close$fd6215ornext;62166217# print element (entry, item)6218my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);6219if($formateq'rss') {6220print"<item>\n".6221"<title>". esc_html($co{'title'}) ."</title>\n".6222"<author>". esc_html($co{'author'}) ."</author>\n".6223"<pubDate>$cd{'rfc2822'}</pubDate>\n".6224"<guid isPermaLink=\"true\">$co_url</guid>\n".6225"<link>$co_url</link>\n".6226"<description>". esc_html($co{'title'}) ."</description>\n".6227"<content:encoded>".6228"<![CDATA[\n";6229}elsif($formateq'atom') {6230print"<entry>\n".6231"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".6232"<updated>$cd{'iso-8601'}</updated>\n".6233"<author>\n".6234" <name>". esc_html($co{'author_name'}) ."</name>\n";6235if($co{'author_email'}) {6236print" <email>". esc_html($co{'author_email'}) ."</email>\n";6237}6238print"</author>\n".6239# use committer for contributor6240"<contributor>\n".6241" <name>". esc_html($co{'committer_name'}) ."</name>\n";6242if($co{'committer_email'}) {6243print" <email>". esc_html($co{'committer_email'}) ."</email>\n";6244}6245print"</contributor>\n".6246"<published>$cd{'iso-8601'}</published>\n".6247"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".6248"<id>$co_url</id>\n".6249"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".6250"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";6251}6252my$comment=$co{'comment'};6253print"<pre>\n";6254foreachmy$line(@$comment) {6255$line= esc_html($line);6256print"$line\n";6257}6258print"</pre><ul>\n";6259foreachmy$difftree_line(@difftree) {6260my%difftree= parse_difftree_raw_line($difftree_line);6261next if!$difftree{'from_id'};62626263my$file=$difftree{'file'} ||$difftree{'to_file'};62646265print"<li>".6266"[".6267$cgi->a({-href => href(-full=>1, action=>"blobdiff",6268 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},6269 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},6270 file_name=>$file, file_parent=>$difftree{'from_file'}),6271-title =>"diff"},'D');6272if($have_blame) {6273print$cgi->a({-href => href(-full=>1, action=>"blame",6274 file_name=>$file, hash_base=>$commit),6275-title =>"blame"},'B');6276}6277# if this is not a feed of a file history6278if(!defined$file_name||$file_namene$file) {6279print$cgi->a({-href => href(-full=>1, action=>"history",6280 file_name=>$file, hash=>$commit),6281-title =>"history"},'H');6282}6283$file= esc_path($file);6284print"] ".6285"$file</li>\n";6286}6287if($formateq'rss') {6288print"</ul>]]>\n".6289"</content:encoded>\n".6290"</item>\n";6291}elsif($formateq'atom') {6292print"</ul>\n</div>\n".6293"</content>\n".6294"</entry>\n";6295}6296}62976298# end of feed6299if($formateq'rss') {6300print"</channel>\n</rss>\n";6301}elsif($formateq'atom') {6302print"</feed>\n";6303}6304}63056306sub git_rss {6307 git_feed('rss');6308}63096310sub git_atom {6311 git_feed('atom');6312}63136314sub git_opml {6315my@list= git_get_projects_list();63166317print$cgi->header(6318-type =>'text/xml',6319-charset =>'utf-8',6320-content_disposition =>'inline; filename="opml.xml"');63216322print<<XML;6323<?xml version="1.0" encoding="utf-8"?>6324<opml version="1.0">6325<head>6326 <title>$site_nameOPML Export</title>6327</head>6328<body>6329<outline text="git RSS feeds">6330XML63316332foreachmy$pr(@list) {6333my%proj=%$pr;6334my$head= git_get_head_hash($proj{'path'});6335if(!defined$head) {6336next;6337}6338$git_dir="$projectroot/$proj{'path'}";6339my%co= parse_commit($head);6340if(!%co) {6341next;6342}63436344my$path= esc_html(chop_str($proj{'path'},25,5));6345my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);6346my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);6347print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";6348}6349print<<XML;6350</outline>6351</body>6352</opml>6353XML6354}