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# Modified by Andrew Lorimer, 2019 9# 10# This program is licensed under the GPLv2 11 12use5.008; 13use strict; 14use warnings; 15# handle ACL in file access tests 16use filetest 'access'; 17use HTML::Entities; 18use Pandoc; 19use Text::Markdown qw(markdown); 20use CGI qw(:standard :escapeHTML -nosticky); 21use CGI::Util qw(unescape); 22#use CGI::Carp qw(fatalsToBrowser set_message); # debugging only 23use CGI::Carp qw(set_message);# production 24use Encode; 25use Fcntl ':mode'; 26use File::Find qw(); 27use File::Basename qw(basename); 28use Time::HiRes qw(gettimeofday tv_interval); 29use Digest::MD5 qw(md5_hex); 30 31binmode STDOUT,':utf8'; 32 33if(!defined($CGI::VERSION) ||$CGI::VERSION <4.08) { 34eval'sub CGI::multi_param { CGI::param(@_) }' 35} 36 37our$t0= [ gettimeofday() ]; 38our$number_of_git_cmds=0; 39 40BEGIN{ 41 CGI->compile()if$ENV{'MOD_PERL'}; 42} 43 44our$version="++GIT_VERSION++"; 45 46our($my_url,$my_uri,$base_url,$path_info,$home_link); 47sub evaluate_uri { 48our$cgi; 49 50our$my_url=$cgi->url(); 51our$my_uri=$cgi->url(-absolute =>1); 52 53# Base URL for relative URLs in gitweb ($logo, $favicon, ...), 54# needed and used only for URLs with nonempty PATH_INFO 55our$base_url=$my_url; 56 57# When the script is used as DirectoryIndex, the URL does not contain the name 58# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we 59# have to do it ourselves. We make $path_info global because it's also used 60# later on. 61# 62# Another issue with the script being the DirectoryIndex is that the resulting 63# $my_url data is not the full script URL: this is good, because we want 64# generated links to keep implying the script name if it wasn't explicitly 65# indicated in the URL we're handling, but it means that $my_url cannot be used 66# as base URL. 67# Therefore, if we needed to strip PATH_INFO, then we know that we have 68# to build the base URL ourselves: 69our$path_info= decode_utf8($ENV{"PATH_INFO"}); 70if($path_info) { 71# $path_info has already been URL-decoded by the web server, but 72# $my_url and $my_uri have not. URL-decode them so we can properly 73# strip $path_info. 74$my_url= unescape($my_url); 75$my_uri= unescape($my_uri); 76if($my_url=~ s,\Q$path_info\E$,, && 77$my_uri=~ s,\Q$path_info\E$,, && 78defined$ENV{'SCRIPT_NAME'}) { 79$base_url=$cgi->url(-base =>1) .$ENV{'SCRIPT_NAME'}; 80} 81} 82 83# target of the home link on top of all pages 84our$home_link=$my_uri||"/"; 85} 86 87# core git executable to use 88# this can just be "git" if your webserver has a sensible PATH 89our$GIT="++GIT_BINDIR++/git"; 90 91# executable path to Pandoc executable for rendering readme files etc 92our$PANDOC="pandoc"; 93 94# absolute fs-path which will be prepended to the project path 95#our $projectroot = "/pub/scm"; 96our$projectroot="++GITWEB_PROJECTROOT++"; 97 98# fs traversing limit for getting project list 99# the number is relative to the projectroot 100our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 101 102# string of the home link on top of all pages 103our$home_link_str="++GITWEB_HOME_LINK_STR++"; 104 105# extra breadcrumbs preceding the home link 106our@extra_breadcrumbs= (); 107 108# name of your site or organization to appear in page titles 109# replace this with something more descriptive for clearer bookmarks 110our$site_name="++GITWEB_SITENAME++" 111|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 112 113# html snippet to include in the <head> section of each page 114our$site_html_head_string="++GITWEB_SITE_HTML_HEAD_STRING++"; 115# filename of html text to include at top of each page 116our$site_header="++GITWEB_SITE_HEADER++"; 117# html text to include at home page 118our$home_text="++GITWEB_HOMETEXT++"; 119# filename of html text to include at bottom of each page 120our$site_footer="++GITWEB_SITE_FOOTER++"; 121 122# Whether to show table header row on index page 123our$index_header=1; 124 125# URI of stylesheets 126our@stylesheets= ("++GITWEB_CSS++"); 127# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 128our$stylesheet=undef; 129# URI of GIT logo (72x27 size) 130our$logo="++GITWEB_LOGO++"; 131# URI of GIT favicon, assumed to be image/png type 132our$favicon="++GITWEB_FAVICON++"; 133# URI of gitweb.js (JavaScript code for gitweb) 134our$javascript="++GITWEB_JS++"; 135 136# URI and label (title) of GIT logo link 137#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 138#our $logo_label = "git documentation"; 139our$logo_url="http://git-scm.com/"; 140our$logo_label="git homepage"; 141 142# source of projects list 143our$projects_list="++GITWEB_LIST++"; 144 145# the width (in characters) of the projects list "Description" column 146our$projects_list_description_width=25; 147 148# group projects by category on the projects list 149# (enabled if this variable evaluates to true) 150our$projects_list_group_categories=0; 151 152# default category if none specified 153# (leave the empty string for no category) 154our$project_list_default_category=""; 155 156# default order of projects list 157# valid values are none, project, descr, owner, and age 158our$default_projects_order="project"; 159 160# show table header row for projects list on index page 161our$projects_table_headers=1; 162 163# show repository only if this file exists 164# (only effective if this variable evaluates to true) 165our$export_ok="++GITWEB_EXPORT_OK++"; 166 167# don't generate age column on the projects list page 168our$omit_age_column=0; 169 170# don't generate information about owners of repositories 171our$omit_owner=0; 172 173# Hide links to each repo's pages in the index 174our$omit_shortcuts=0; 175 176# Hide .git extension in index table 177our$omit_git_extension=0; 178 179# show repository only if this subroutine returns true 180# when given the path to the project, for example: 181# sub { return -e "$_[0]/git-daemon-export-ok"; } 182our$export_auth_hook=undef; 183 184# only allow viewing of repositories also shown on the overview page 185our$strict_export="++GITWEB_STRICT_EXPORT++"; 186 187# list of git base URLs used for URL to where fetch project from, 188# i.e. full URL is "$git_base_url/$project" 189our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 190 191# default blob_plain mimetype and default charset for text/plain blob 192our$default_blob_plain_mimetype='text/plain'; 193our$default_text_plain_charset=undef; 194 195# file to use for guessing MIME types before trying /etc/mime.types 196# (relative to the current git repository) 197our$mimetypes_file=undef; 198 199# assume this charset if line contains non-UTF-8 characters; 200# it should be valid encoding (see Encoding::Supported(3pm) for list), 201# for which encoding all byte sequences are valid, for example 202# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 203# could be even 'utf-8' for the old behavior) 204our$fallback_encoding='latin1'; 205 206# number of characters to truncate commit hashes to 207# Added by Andrew Lorimer, October 2019 208our$hash_char=7; 209 210# whether to show OPML feed link on homepage 211# Added by Andrew Lorimer, October 2019 212our$opml=1; 213 214# whether to show TXT link on homepage 215# Added by Andrew Lorimer, October 2019 216our$txt=1; 217 218# rename detection options for git-diff and git-diff-tree 219# - default is '-M', with the cost proportional to 220# (number of removed files) * (number of new files). 221# - more costly is '-C' (which implies '-M'), with the cost proportional to 222# (number of changed files + number of removed files) * (number of new files) 223# - even more costly is '-C', '--find-copies-harder' with cost 224# (number of files in the original tree) * (number of new files) 225# - one might want to include '-B' option, e.g. '-B', '-M' 226our@diff_opts= ('-M');# taken from git_commit 227 228# Disables features that would allow repository owners to inject script into 229# the gitweb domain. 230our$prevent_xss=0; 231 232# Path to the highlight executable to use (must be the one from 233# http://www.andre-simon.de due to assumptions about parameters and output). 234# Useful if highlight is not installed on your webserver's PATH. 235# [Default: highlight] 236our$highlight_bin="++HIGHLIGHT_BIN++"; 237 238# information about snapshot formats that gitweb is capable of serving 239our%known_snapshot_formats= ( 240# name => { 241# 'display' => display name, 242# 'type' => mime type, 243# 'suffix' => filename suffix, 244# 'format' => --format for git-archive, 245# 'compressor' => [compressor command and arguments] 246# (array reference, optional) 247# 'disabled' => boolean (optional)} 248# 249'tgz'=> { 250'display'=>'tar.gz', 251'type'=>'application/x-gzip', 252'suffix'=>'.tar.gz', 253'format'=>'tar', 254'compressor'=> ['gzip','-n']}, 255 256'tbz2'=> { 257'display'=>'tar.bz2', 258'type'=>'application/x-bzip2', 259'suffix'=>'.tar.bz2', 260'format'=>'tar', 261'compressor'=> ['bzip2']}, 262 263'txz'=> { 264'display'=>'tar.xz', 265'type'=>'application/x-xz', 266'suffix'=>'.tar.xz', 267'format'=>'tar', 268'compressor'=> ['xz'], 269'disabled'=>1}, 270 271'zip'=> { 272'display'=>'zip', 273'type'=>'application/x-zip', 274'suffix'=>'.zip', 275'format'=>'zip'}, 276); 277 278# Aliases so we understand old gitweb.snapshot values in repository 279# configuration. 280our%known_snapshot_format_aliases= ( 281'gzip'=>'tgz', 282'bzip2'=>'tbz2', 283'xz'=>'txz', 284 285# backward compatibility: legacy gitweb config support 286'x-gzip'=>undef,'gz'=>undef, 287'x-bzip2'=>undef,'bz2'=>undef, 288'x-zip'=>undef,''=>undef, 289); 290 291# Pixel sizes for icons and avatars. If the default font sizes or lineheights 292# are changed, it may be appropriate to change these values too via 293# $GITWEB_CONFIG. 294our%avatar_size= ( 295'default'=>16, 296'double'=>32 297); 298 299# Used to set the maximum load that we will still respond to gitweb queries. 300# If server load exceed this value then return "503 server busy" error. 301# If gitweb cannot determined server load, it is taken to be 0. 302# Leave it undefined (or set to 'undef') to turn off load checking. 303our$maxload=300; 304 305# configuration for 'highlight' (http://www.andre-simon.de/) 306# match by basename 307our%highlight_basename= ( 308#'Program' => 'py', 309#'Library' => 'py', 310'SConstruct'=>'py',# SCons equivalent of Makefile 311'Makefile'=>'make', 312); 313# match by extension 314our%highlight_ext= ( 315# main extensions, defining name of syntax; 316# see files in /usr/share/highlight/langDefs/ directory 317(map{$_=>$_}qw(py rb java css js tex bib xml awk bat ini spec tcl sql)), 318# alternate extensions, see /etc/highlight/filetypes.conf 319(map{$_=>'c'}qw(c h)), 320(map{$_=>'sh'}qw(sh bash zsh ksh)), 321(map{$_=>'cpp'}qw(cpp cxx c++ cc)), 322(map{$_=>'php'}qw(php php3 php4 php5 phps)), 323(map{$_=>'pl'}qw(pl perl pm)),# perhaps also 'cgi' 324(map{$_=>'make'}qw(make mak mk)), 325(map{$_=>'xml'}qw(xml xhtml html htm)), 326(map{$_=>'markdown'}qw(md markdown)) 327); 328 329# You define site-wide feature defaults here; override them with 330# $GITWEB_CONFIG as necessary. 331our%feature= ( 332# feature => { 333# 'sub' => feature-sub (subroutine), 334# 'override' => allow-override (boolean), 335# 'default' => [ default options...] (array reference)} 336# 337# if feature is overridable (it means that allow-override has true value), 338# then feature-sub will be called with default options as parameters; 339# return value of feature-sub indicates if to enable specified feature 340# 341# if there is no 'sub' key (no feature-sub), then feature cannot be 342# overridden 343# 344# use gitweb_get_feature(<feature>) to retrieve the <feature> value 345# (an array) or gitweb_check_feature(<feature>) to check if <feature> 346# is enabled 347 348# Enable the 'blame' blob view, showing the last commit that modified 349# each line in the file. This can be very CPU-intensive. 350 351# To enable system wide have in $GITWEB_CONFIG 352# $feature{'blame'}{'default'} = [1]; 353# To have project specific config enable override in $GITWEB_CONFIG 354# $feature{'blame'}{'override'} = 1; 355# and in project config gitweb.blame = 0|1; 356'blame'=> { 357'sub'=>sub{ feature_bool('blame',@_) }, 358'override'=>0, 359'default'=> [0]}, 360 361# Regex filter for paths (files and directories) to display in the 362# tree view. Currently this only affects the files listed in the tree, 363# and files that do not match this regex can still be accessed through 364# the full URL. This value can be overriden for individual projects. 365# Note that double-escaping is necessary for backslashes (i.e. to match 366# a literal full stop, use `\\.`). 367'tree_filter'=> { 368'sub'=> \&feature_tree_filter, 369'override'=>0, 370'default'=> [".*"]}, 371 372# Enable the 'snapshot' link, providing a compressed archive of any 373# tree. This can potentially generate high traffic if you have large 374# project. 375 376# Value is a list of formats defined in %known_snapshot_formats that 377# you wish to offer. 378# To disable system wide have in $GITWEB_CONFIG 379# $feature{'snapshot'}{'default'} = []; 380# To have project specific config enable override in $GITWEB_CONFIG 381# $feature{'snapshot'}{'override'} = 1; 382# and in project config, a comma-separated list of formats or "none" 383# to disable. Example: gitweb.snapshot = tbz2,zip; 384'snapshot'=> { 385'sub'=> \&feature_snapshot, 386'override'=>0, 387'default'=> ['tgz']}, 388 389# Enable text search, which will list the commits which match author, 390# committer or commit text to a given string. Enabled by default. 391# Project specific override is not supported. 392# 393# Note that this controls all search features, which means that if 394# it is disabled, then 'grep' and 'pickaxe' search would also be 395# disabled. 396'search'=> { 397'override'=>0, 398'default'=> [1]}, 399 400# Enable grep search, which will list the files in currently selected 401# tree containing the given string. Enabled by default. This can be 402# potentially CPU-intensive, of course. 403# Note that you need to have 'search' feature enabled too. 404 405# To enable system wide have in $GITWEB_CONFIG 406# $feature{'grep'}{'default'} = [1]; 407# To have project specific config enable override in $GITWEB_CONFIG 408# $feature{'grep'}{'override'} = 1; 409# and in project config gitweb.grep = 0|1; 410'grep'=> { 411'sub'=>sub{ feature_bool('grep',@_) }, 412'override'=>0, 413'default'=> [1]}, 414 415# Enable the pickaxe search, which will list the commits that modified 416# a given string in a file. This can be practical and quite faster 417# alternative to 'blame', but still potentially CPU-intensive. 418# Note that you need to have 'search' feature enabled too. 419 420# To enable system wide have in $GITWEB_CONFIG 421# $feature{'pickaxe'}{'default'} = [1]; 422# To have project specific config enable override in $GITWEB_CONFIG 423# $feature{'pickaxe'}{'override'} = 1; 424# and in project config gitweb.pickaxe = 0|1; 425'pickaxe'=> { 426'sub'=>sub{ feature_bool('pickaxe',@_) }, 427'override'=>0, 428'default'=> [1]}, 429 430# Enable showing size of blobs in a 'tree' view, in a separate 431# column, similar to what 'ls -l' does. This cost a bit of IO. 432 433# To disable system wide have in $GITWEB_CONFIG 434# $feature{'show-sizes'}{'default'} = [0]; 435# To have project specific config enable override in $GITWEB_CONFIG 436# $feature{'show-sizes'}{'override'} = 1; 437# and in project config gitweb.showsizes = 0|1; 438'show-sizes'=> { 439'sub'=>sub{ feature_bool('showsizes',@_) }, 440'override'=>0, 441'default'=> [1]}, 442 443# Make gitweb use an alternative format of the URLs which can be 444# more readable and natural-looking: project name is embedded 445# directly in the path and the query string contains other 446# auxiliary information. All gitweb installations recognize 447# URL in either format; this configures in which formats gitweb 448# generates links. 449 450# To enable system wide have in $GITWEB_CONFIG 451# $feature{'pathinfo'}{'default'} = [1]; 452# Project specific override is not supported. 453 454# Note that you will need to change the default location of CSS, 455# favicon, logo and possibly other files to an absolute URL. Also, 456# if gitweb.cgi serves as your indexfile, you will need to force 457# $my_uri to contain the script name in your $GITWEB_CONFIG. 458'pathinfo'=> { 459'override'=>0, 460'default'=> [0]}, 461 462# Make gitweb consider projects in project root subdirectories 463# to be forks of existing projects. Given project $projname.git, 464# projects matching $projname/*.git will not be shown in the main 465# projects list, instead a '+' mark will be added to $projname 466# there and a 'forks' view will be enabled for the project, listing 467# all the forks. If project list is taken from a file, forks have 468# to be listed after the main project. 469 470# To enable system wide have in $GITWEB_CONFIG 471# $feature{'forks'}{'default'} = [1]; 472# Project specific override is not supported. 473'forks'=> { 474'override'=>0, 475'default'=> [0]}, 476 477# Insert custom links to the action bar of all project pages. 478# This enables you mainly to link to third-party scripts integrating 479# into gitweb; e.g. git-browser for graphical history representation 480# or custom web-based repository administration interface. 481 482# The 'default' value consists of a list of triplets in the form 483# (label, link, position) where position is the label after which 484# to insert the link and link is a format string where %n expands 485# to the project name, %f to the project path within the filesystem, 486# %h to the current hash (h gitweb parameter) and %b to the current 487# hash base (hb gitweb parameter); %% expands to %. 488 489# To enable system wide have in $GITWEB_CONFIG e.g. 490# $feature{'actions'}{'default'} = [('graphiclog', 491# '/git-browser/by-commit.html?r=%n', 'summary')]; 492# Project specific override is not supported. 493'actions'=> { 494'override'=>0, 495'default'=> []}, 496 497# Allow gitweb scan project content tags of project repository, 498# and display the popular Web 2.0-ish "tag cloud" near the projects 499# list. Note that this is something COMPLETELY different from the 500# normal Git tags. 501 502# gitweb by itself can show existing tags, but it does not handle 503# tagging itself; you need to do it externally, outside gitweb. 504# The format is described in git_get_project_ctags() subroutine. 505# You may want to install the HTML::TagCloud Perl module to get 506# a pretty tag cloud instead of just a list of tags. 507 508# To enable system wide have in $GITWEB_CONFIG 509# $feature{'ctags'}{'default'} = [1]; 510# Project specific override is not supported. 511 512# In the future whether ctags editing is enabled might depend 513# on the value, but using 1 should always mean no editing of ctags. 514'ctags'=> { 515'override'=>0, 516'default'=> [0]}, 517 518# The maximum number of patches in a patchset generated in patch 519# view. Set this to 0 or undef to disable patch view, or to a 520# negative number to remove any limit. 521 522# To disable system wide have in $GITWEB_CONFIG 523# $feature{'patches'}{'default'} = [0]; 524# To have project specific config enable override in $GITWEB_CONFIG 525# $feature{'patches'}{'override'} = 1; 526# and in project config gitweb.patches = 0|n; 527# where n is the maximum number of patches allowed in a patchset. 528'patches'=> { 529'sub'=> \&feature_patches, 530'override'=>0, 531'default'=> [16]}, 532 533# Avatar support. When this feature is enabled, views such as 534# shortlog or commit will display an avatar associated with 535# the email of the committer(s) and/or author(s). 536 537# Currently available providers are gravatar and picon. 538# If an unknown provider is specified, the feature is disabled. 539 540# Picon currently relies on the indiana.edu database. 541 542# To enable system wide have in $GITWEB_CONFIG 543# $feature{'avatar'}{'default'} = ['<provider>']; 544# where <provider> is either gravatar or picon. 545# To have project specific config enable override in $GITWEB_CONFIG 546# $feature{'avatar'}{'override'} = 1; 547# and in project config gitweb.avatar = <provider>; 548'avatar'=> { 549'sub'=> \&feature_avatar, 550'override'=>0, 551'default'=> ['']}, 552 553# Enable displaying how much time and how many git commands 554# it took to generate and display page. Disabled by default. 555# Project specific override is not supported. 556'timed'=> { 557'override'=>0, 558'default'=> [0]}, 559 560# Enable turning some links into links to actions which require 561# JavaScript to run (like 'blame_incremental'). Not enabled by 562# default. Project specific override is currently not supported. 563'javascript-actions'=> { 564'override'=>0, 565'default'=> [0]}, 566 567# Enable and configure ability to change common timezone for dates 568# in gitweb output via JavaScript. Enabled by default. 569# Project specific override is not supported. 570'javascript-timezone'=> { 571'override'=>0, 572'default'=> [ 573'local',# default timezone: 'utc', 'local', or '(-|+)HHMM' format, 574# or undef to turn off this feature 575'gitweb_tz',# name of cookie where to store selected timezone 576'datetime',# CSS class used to mark up dates for manipulation 577]}, 578 579# Syntax highlighting support. This is based on Daniel Svensson's 580# and Sham Chukoury's work in gitweb-xmms2.git. 581# It requires the 'highlight' program present in $PATH, 582# and therefore is disabled by default. 583 584# To enable system wide have in $GITWEB_CONFIG 585# $feature{'highlight'}{'default'} = [1]; 586 587'highlight'=> { 588'sub'=>sub{ feature_bool('highlight',@_) }, 589'override'=>0, 590'default'=> [0]}, 591 592# Enable displaying of remote heads in the heads list 593 594# To enable system wide have in $GITWEB_CONFIG 595# $feature{'remote_heads'}{'default'} = [1]; 596# To have project specific config enable override in $GITWEB_CONFIG 597# $feature{'remote_heads'}{'override'} = 1; 598# and in project config gitweb.remoteheads = 0|1; 599'remote_heads'=> { 600'sub'=>sub{ feature_bool('remote_heads',@_) }, 601'override'=>0, 602'default'=> [0]}, 603 604# Enable showing branches under other refs in addition to heads 605 606# To set system wide extra branch refs have in $GITWEB_CONFIG 607# $feature{'extra-branch-refs'}{'default'} = ['dirs', 'of', 'choice']; 608# To have project specific config enable override in $GITWEB_CONFIG 609# $feature{'extra-branch-refs'}{'override'} = 1; 610# and in project config gitweb.extrabranchrefs = dirs of choice 611# Every directory is separated with whitespace. 612 613'extra-branch-refs'=> { 614'sub'=> \&feature_extra_branch_refs, 615'override'=>0, 616'default'=> []}, 617 618# Enable or disable RSS feed 619# Added by Andrew Lorimer, October 2019 620 621'rss'=> { 622'sub'=> \&feature_bool, 623'override'=>0, 624'default'=> [1]}, 625 626# Enable or disable Atom feed 627# Added by Andrew Lorimer, October 2019 628 629'atom'=> { 630'sub'=> \&feature_bool, 631'override'=>0, 632'default'=> [1]}, 633 634 635# Enable or disable the shortlog view 636# Added by Andrew Lorimer, November 2019 637'shortlog'=> { 638'sub'=> \&feature_bool, 639'override'=>0, 640'default'=> [1]}, 641 642# Show author name for every commit in main commit list 643# Added by Andrew Lorimer, January 2020 644'summary_omit_author'=> { 645'sub'=> \&feature_bool, 646'override'=>0, 647'default'=> [1]}, 648); 649 650sub gitweb_get_feature { 651my($name) =@_; 652return unlessexists$feature{$name}; 653my($sub,$override,@defaults) = ( 654$feature{$name}{'sub'}, 655$feature{$name}{'override'}, 656@{$feature{$name}{'default'}}); 657# project specific override is possible only if we have project 658our$git_dir;# global variable, declared later 659if(!$override|| !defined$git_dir) { 660return@defaults; 661} 662if(!defined$sub) { 663warn"feature$nameis not overridable"; 664return@defaults; 665} 666return$sub->(@defaults); 667} 668 669# A wrapper to check if a given feature is enabled. 670# With this, you can say 671# 672# my $bool_feat = gitweb_check_feature('bool_feat'); 673# gitweb_check_feature('bool_feat') or somecode; 674# 675# instead of 676# 677# my ($bool_feat) = gitweb_get_feature('bool_feat'); 678# (gitweb_get_feature('bool_feat'))[0] or somecode; 679# 680sub gitweb_check_feature { 681return(gitweb_get_feature(@_))[0]; 682} 683 684 685sub feature_bool { 686my$key=shift; 687my($val) = git_get_project_config($key,'--bool'); 688 689if(!defined$val) { 690return($_[0]); 691}elsif($valeq'true') { 692return(1); 693}elsif($valeq'false') { 694return(0); 695} 696} 697 698sub feature_tree_filter { 699my@pattern_global=shift; 700my@pattern_project= git_get_project_config('tree_filter'); 701return(scalar(@pattern_project) >0?$pattern_project[0] :$pattern_global[0]); 702} 703 704sub feature_snapshot { 705my(@fmts) =@_; 706 707my($val) = git_get_project_config('snapshot'); 708 709if($val) { 710@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 711} 712 713return@fmts; 714} 715 716sub feature_patches { 717my@val= (git_get_project_config('patches','--int')); 718 719if(@val) { 720return@val; 721} 722 723return($_[0]); 724} 725 726sub feature_avatar { 727my@val= (git_get_project_config('avatar')); 728 729return@val?@val:@_; 730} 731 732sub feature_extra_branch_refs { 733my(@branch_refs) =@_; 734my$values= git_get_project_config('extrabranchrefs'); 735 736if($values) { 737$values= config_to_multi ($values); 738@branch_refs= (); 739foreachmy$value(@{$values}) { 740push@branch_refs,split/\s+/,$value; 741} 742} 743 744return@branch_refs; 745} 746 747# checking HEAD file with -e is fragile if the repository was 748# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 749# and then pruned. 750sub check_head_link { 751my($dir) =@_; 752my$headfile="$dir/HEAD"; 753return((-e $headfile) || 754(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 755} 756 757sub check_export_ok { 758my($dir) =@_; 759return(check_head_link($dir) && 760(!$export_ok|| -e "$dir/$export_ok") && 761(!$export_auth_hook||$export_auth_hook->($dir))); 762} 763 764# process alternate names for backward compatibility 765# filter out unsupported (unknown) snapshot formats 766sub filter_snapshot_fmts { 767my@fmts=@_; 768 769@fmts=map{ 770exists$known_snapshot_format_aliases{$_} ? 771$known_snapshot_format_aliases{$_} :$_}@fmts; 772@fmts=grep{ 773exists$known_snapshot_formats{$_} && 774!$known_snapshot_formats{$_}{'disabled'}}@fmts; 775} 776 777sub filter_and_validate_refs { 778my@refs=@_; 779my%unique_refs= (); 780 781foreachmy$ref(@refs) { 782 die_error(500,"Invalid ref '$ref' in 'extra-branch-refs' feature")unless(is_valid_ref_format($ref)); 783# 'heads' are added implicitly in get_branch_refs(). 784$unique_refs{$ref} =1if($refne'heads'); 785} 786returnsort keys%unique_refs; 787} 788 789# If it is set to code reference, it is code that it is to be run once per 790# request, allowing updating configurations that change with each request, 791# while running other code in config file only once. 792# 793# Otherwise, if it is false then gitweb would process config file only once; 794# if it is true then gitweb config would be run for each request. 795our$per_request_config=1; 796 797# read and parse gitweb config file given by its parameter. 798# returns true on success, false on recoverable error, allowing 799# to chain this subroutine, using first file that exists. 800# dies on errors during parsing config file, as it is unrecoverable. 801sub read_config_file { 802my$filename=shift; 803return unlessdefined$filename; 804# die if there are errors parsing config file 805if(-e $filename) { 806do$filename; 807die$@if$@; 808return1; 809} 810return; 811} 812 813our($GITWEB_CONFIG,$GITWEB_CONFIG_SYSTEM,$GITWEB_CONFIG_COMMON); 814sub evaluate_gitweb_config { 815our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 816our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 817our$GITWEB_CONFIG_COMMON=$ENV{'GITWEB_CONFIG_COMMON'} ||"++GITWEB_CONFIG_COMMON++"; 818 819# Protect against duplications of file names, to not read config twice. 820# Only one of $GITWEB_CONFIG and $GITWEB_CONFIG_SYSTEM is used, so 821# there possibility of duplication of filename there doesn't matter. 822$GITWEB_CONFIG=""if($GITWEB_CONFIGeq$GITWEB_CONFIG_COMMON); 823$GITWEB_CONFIG_SYSTEM=""if($GITWEB_CONFIG_SYSTEMeq$GITWEB_CONFIG_COMMON); 824 825# Common system-wide settings for convenience. 826# Those settings can be ovverriden by GITWEB_CONFIG or GITWEB_CONFIG_SYSTEM. 827 read_config_file($GITWEB_CONFIG_COMMON); 828 829# Use first config file that exists. This means use the per-instance 830# GITWEB_CONFIG if exists, otherwise use GITWEB_SYSTEM_CONFIG. 831 read_config_file($GITWEB_CONFIG)andreturn; 832 read_config_file($GITWEB_CONFIG_SYSTEM); 833} 834 835# Get loadavg of system, to compare against $maxload. 836# Currently it requires '/proc/loadavg' present to get loadavg; 837# if it is not present it returns 0, which means no load checking. 838sub get_loadavg { 839if( -e '/proc/loadavg'){ 840open my$fd,'<','/proc/loadavg' 841orreturn0; 842my@load=split(/\s+/,scalar<$fd>); 843close$fd; 844 845# The first three columns measure CPU and IO utilization of the last one, 846# five, and 10 minute periods. The fourth column shows the number of 847# currently running processes and the total number of processes in the m/n 848# format. The last column displays the last process ID used. 849return$load[0] ||0; 850} 851# additional checks for load average should go here for things that don't export 852# /proc/loadavg 853 854return0; 855} 856 857# version of the core git binary 858our$git_version; 859sub evaluate_git_version { 860our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 861$number_of_git_cmds++; 862} 863 864sub check_loadavg { 865if(defined$maxload&& get_loadavg() >$maxload) { 866 die_error(503,"The load average on the server is too high"); 867} 868} 869 870# ====================================================================== 871# input validation and dispatch 872 873# Various hash size-related values. 874my$sha1_len=40; 875my$sha256_extra_len=24; 876my$sha256_len=$sha1_len+$sha256_extra_len; 877 878# A regex matching $len hex characters. $len may be a range (e.g. 7,64). 879sub oid_nlen_regex { 880my$len=shift; 881my$hchr=qr/[0-9a-fA-F]/; 882returnqr/(?:(?:$hchr){$len})/; 883} 884 885# A regex matching two sets of $nlen hex characters, prefixed by the literal 886# string $prefix and with the literal string $infix between them. 887sub oid_nlen_prefix_infix_regex { 888my$nlen=shift; 889my$prefix=shift; 890my$infix=shift; 891 892my$rx= oid_nlen_regex($nlen); 893 894returnqr/^\Q$prefix\E$rx\Q$infix\E$rx$/; 895} 896 897# A regex matching a valid object ID. 898our$oid_regex; 899{ 900my$x= oid_nlen_regex($sha1_len); 901my$y= oid_nlen_regex($sha256_extra_len); 902$oid_regex=qr/(?:$x(?:$y)?)/; 903} 904 905# input parameters can be collected from a variety of sources (presently, CGI 906# and PATH_INFO), so we define an %input_params hash that collects them all 907# together during validation: this allows subsequent uses (e.g. href()) to be 908# agnostic of the parameter origin 909 910our%input_params= (); 911 912# input parameters are stored with the long parameter name as key. This will 913# also be used in the href subroutine to convert parameters to their CGI 914# equivalent, and since the href() usage is the most frequent one, we store 915# the name -> CGI key mapping here, instead of the reverse. 916# 917# XXX: Warning: If you touch this, check the search form for updating, 918# too. 919 920our@cgi_param_mapping= ( 921 project =>"p", 922 action =>"a", 923 file_name =>"f", 924 file_parent =>"fp", 925 hash =>"h", 926 hash_parent =>"hp", 927 hash_base =>"hb", 928 hash_parent_base =>"hpb", 929 page =>"pg", 930 order =>"o", 931 searchtext =>"s", 932 searchtype =>"st", 933 snapshot_format =>"sf", 934 extra_options =>"opt", 935 search_use_regexp =>"sr", 936 ctag =>"by_tag", 937 diff_style =>"ds", 938 project_filter =>"pf", 939# this must be last entry (for manipulation from JavaScript) 940 javascript =>"js" 941); 942our%cgi_param_mapping=@cgi_param_mapping; 943 944# we will also need to know the possible actions, for validation 945our%actions= ( 946"blame"=> \&git_blame, 947"blame_incremental"=> \&git_blame_incremental, 948"blame_data"=> \&git_blame_data, 949"blobdiff"=> \&git_blobdiff, 950"blobdiff_plain"=> \&git_blobdiff_plain, 951"blob"=> \&git_blob, 952"blob_plain"=> \&git_blob_plain, 953"diff"=> \&git_diff, 954"diff_plain"=> \&git_diff_plain, 955"commit"=> \&git_commit, 956"forks"=> \&git_forks, 957"heads"=> \&git_heads, 958"history"=> \&git_history, 959"log"=> \&git_log, 960"patch"=> \&git_patch, 961"patches"=> \&git_patches, 962"remotes"=> \&git_remotes, 963"rss"=> \&git_rss, 964"atom"=> \&git_atom, 965"search"=> \&git_search, 966"search_help"=> \&git_search_help, 967"shortlog"=> \&git_shortlog, 968"summary"=> \&git_summary, 969"tag"=> \&git_tag, 970"tags"=> \&git_tags, 971"tree"=> \&git_tree, 972"snapshot"=> \&git_snapshot, 973"object"=> \&git_object, 974# those below don't need $project 975"opml"=> \&git_opml, 976"project_list"=> \&git_project_list, 977"project_index"=> \&git_project_index, 978); 979 980# finally, we have the hash of allowed extra_options for the commands that 981# allow them 982our%allowed_options= ( 983"--no-merges"=> [qw(rss atom log shortlog history)], 984); 985 986# fill %input_params with the CGI parameters. All values except for 'opt' 987# should be single values, but opt can be an array. We should probably 988# build an array of parameters that can be multi-valued, but since for the time 989# being it's only this one, we just single it out 990sub evaluate_query_params { 991our$cgi; 992 993while(my($name,$symbol) =each%cgi_param_mapping) { 994if($symboleq'opt') { 995$input_params{$name} = [map{ decode_utf8($_) }$cgi->multi_param($symbol) ]; 996}else{ 997$input_params{$name} = decode_utf8($cgi->param($symbol)); 998} 999}1000}10011002# now read PATH_INFO and update the parameter list for missing parameters1003sub evaluate_path_info {1004return ifdefined$input_params{'project'};1005return if!$path_info;1006$path_info=~ s,^/+,,;1007return if!$path_info;10081009# find which part of PATH_INFO is project1010my$project=$path_info;1011$project=~ s,/+$,,;1012while($project&& !check_head_link("$projectroot/$project")) {1013$project=~ s,/*[^/]*$,,;1014}1015if(!$project) {1016 die_error(404,"Project$path_infonot found");1017}1018$input_params{'project'} =$project;10191020# do not change any parameters if an action is given using the query string1021return if$input_params{'action'};1022$path_info=~ s,^\Q$project\E/*,,;10231024# next, check if we have an action1025my$action=$path_info;1026$action=~ s,/.*$,,;1027if(exists$actions{$action}) {1028$path_info=~ s,^$action/*,,;1029$input_params{'action'} =$action;1030}10311032# list of actions that want hash_base instead of hash, but can have no1033# pathname (f) parameter1034my@wants_base= (1035'tree',1036'history',1037);10381039# we want to catch, among others1040# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]1041my($parentrefname,$parentpathname,$refname,$pathname) =1042($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?([^:]+?)?(?::(.+))?$/);10431044# first, analyze the 'current' part1045if(defined$pathname) {1046# we got "branch:filename" or "branch:dir/"1047# we could use git_get_type(branch:pathname), but:1048# - it needs $git_dir1049# - it does a git() call1050# - the convention of terminating directories with a slash1051# makes it superfluous1052# - embedding the action in the PATH_INFO would make it even1053# more superfluous1054$pathname=~ s,^/+,,;1055if(!$pathname||substr($pathname, -1)eq"/") {1056$input_params{'action'} ||="tree";1057$pathname=~ s,/$,,;1058}else{1059# the default action depends on whether we had parent info1060# or not1061if($parentrefname) {1062$input_params{'action'} ||="blobdiff_plain";1063}else{1064$input_params{'action'} ||="blob_plain";1065}1066}1067$input_params{'hash_base'} ||=$refname;1068$input_params{'file_name'} ||=$pathname;1069}elsif(defined$refname) {1070# we got "branch". In this case we have to choose if we have to1071# set hash or hash_base.1072#1073# Most of the actions without a pathname only want hash to be1074# set, except for the ones specified in @wants_base that want1075# hash_base instead. It should also be noted that hand-crafted1076# links having 'history' as an action and no pathname or hash1077# set will fail, but that happens regardless of PATH_INFO.1078if(defined$parentrefname) {1079# if there is parent let the default be 'shortlog' action1080# (for http://git.example.com/repo.git/A..B links); if there1081# is no parent, dispatch will detect type of object and set1082# action appropriately if required (if action is not set)1083$input_params{'action'} ||="shortlog";1084}1085if($input_params{'action'} &&1086grep{$_eq$input_params{'action'} }@wants_base) {1087$input_params{'hash_base'} ||=$refname;1088}else{1089$input_params{'hash'} ||=$refname;1090}1091}10921093# next, handle the 'parent' part, if present1094if(defined$parentrefname) {1095# a missing pathspec defaults to the 'current' filename, allowing e.g.1096# someproject/blobdiff/oldrev..newrev:/filename1097if($parentpathname) {1098$parentpathname=~ s,^/+,,;1099$parentpathname=~ s,/$,,;1100$input_params{'file_parent'} ||=$parentpathname;1101}else{1102$input_params{'file_parent'} ||=$input_params{'file_name'};1103}1104# we assume that hash_parent_base is wanted if a path was specified,1105# or if the action wants hash_base instead of hash1106if(defined$input_params{'file_parent'} ||1107grep{$_eq$input_params{'action'} }@wants_base) {1108$input_params{'hash_parent_base'} ||=$parentrefname;1109}else{1110$input_params{'hash_parent'} ||=$parentrefname;1111}1112}11131114# for the snapshot action, we allow URLs in the form1115# $project/snapshot/$hash.ext1116# where .ext determines the snapshot and gets removed from the1117# passed $refname to provide the $hash.1118#1119# To be able to tell that $refname includes the format extension, we1120# require the following two conditions to be satisfied:1121# - the hash input parameter MUST have been set from the $refname part1122# of the URL (i.e. they must be equal)1123# - the snapshot format MUST NOT have been defined already (e.g. from1124# CGI parameter sf)1125# It's also useless to try any matching unless $refname has a dot,1126# so we check for that too1127if(defined$input_params{'action'} &&1128$input_params{'action'}eq'snapshot'&&1129defined$refname&&index($refname,'.') != -1&&1130$refnameeq$input_params{'hash'} &&1131!defined$input_params{'snapshot_format'}) {1132# We loop over the known snapshot formats, checking for1133# extensions. Allowed extensions are both the defined suffix1134# (which includes the initial dot already) and the snapshot1135# format key itself, with a prepended dot1136while(my($fmt,$opt) =each%known_snapshot_formats) {1137my$hash=$refname;1138unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {1139next;1140}1141my$sfx=$1;1142# a valid suffix was found, so set the snapshot format1143# and reset the hash parameter1144$input_params{'snapshot_format'} =$fmt;1145$input_params{'hash'} =$hash;1146# we also set the format suffix to the one requested1147# in the URL: this way a request for e.g. .tgz returns1148# a .tgz instead of a .tar.gz1149$known_snapshot_formats{$fmt}{'suffix'} =$sfx;1150last;1151}1152}1153}11541155our($action,$project,$file_name,$file_parent,$hash,$hash_parent,$hash_base,1156$hash_parent_base,@extra_options,$page,$searchtype,$search_use_regexp,1157$searchtext,$search_regexp,$project_filter);1158sub evaluate_and_validate_params {1159our$action=$input_params{'action'};1160if(defined$action) {1161if(!is_valid_action($action)) {1162 die_error(400,"Invalid action parameter");1163}1164}11651166# parameters which are pathnames1167our$project=$input_params{'project'};1168if(defined$project) {1169if(!is_valid_project($project)) {1170undef$project;1171 die_error(404,"No such project");1172}1173}11741175our$project_filter=$input_params{'project_filter'};1176if(defined$project_filter) {1177if(!is_valid_pathname($project_filter)) {1178 die_error(404,"Invalid project_filter parameter");1179}1180}11811182our$file_name=$input_params{'file_name'};1183if(defined$file_name) {1184if(!is_valid_pathname($file_name)) {1185 die_error(400,"Invalid file parameter");1186}1187}11881189our$file_parent=$input_params{'file_parent'};1190if(defined$file_parent) {1191if(!is_valid_pathname($file_parent)) {1192 die_error(400,"Invalid file parent parameter");1193}1194}11951196# parameters which are refnames1197our$hash=$input_params{'hash'};1198if(defined$hash) {1199if(!is_valid_refname($hash)) {1200 die_error(400,"Invalid hash parameter");1201}1202}12031204our$hash_parent=$input_params{'hash_parent'};1205if(defined$hash_parent) {1206if(!is_valid_refname($hash_parent)) {1207 die_error(400,"Invalid hash parent parameter");1208}1209}12101211our$hash_base=$input_params{'hash_base'};1212if(defined$hash_base) {1213if(!is_valid_refname($hash_base)) {1214 die_error(400,"Invalid hash base parameter");1215}1216}12171218our@extra_options= @{$input_params{'extra_options'}};1219# @extra_options is always defined, since it can only be (currently) set from1220# CGI, and $cgi->param() returns the empty array in array context if the param1221# is not set1222foreachmy$opt(@extra_options) {1223if(not exists$allowed_options{$opt}) {1224 die_error(400,"Invalid option parameter");1225}1226if(not grep(/^$action$/, @{$allowed_options{$opt}})) {1227 die_error(400,"Invalid option parameter for this action");1228}1229}12301231our$hash_parent_base=$input_params{'hash_parent_base'};1232if(defined$hash_parent_base) {1233if(!is_valid_refname($hash_parent_base)) {1234 die_error(400,"Invalid hash parent base parameter");1235}1236}12371238# other parameters1239our$page=$input_params{'page'};1240if(defined$page) {1241if($page=~m/[^0-9]/) {1242 die_error(400,"Invalid page parameter");1243}1244}12451246our$searchtype=$input_params{'searchtype'};1247if(defined$searchtype) {1248if($searchtype=~m/[^a-z]/) {1249 die_error(400,"Invalid searchtype parameter");1250}1251}12521253our$search_use_regexp=$input_params{'search_use_regexp'};12541255our$searchtext=$input_params{'searchtext'};1256our$search_regexp=undef;1257if(defined$searchtext) {1258if(length($searchtext) <2) {1259 die_error(403,"At least two characters are required for search parameter");1260}1261if($search_use_regexp) {1262$search_regexp=$searchtext;1263if(!eval{qr/$search_regexp/;1; }) {1264(my$error=$@) =~s/ at \S+ line \d+.*\n?//;1265 die_error(400,"Invalid search regexp '$search_regexp'",1266 esc_html($error));1267}1268}else{1269$search_regexp=quotemeta$searchtext;1270}1271}1272}12731274# path to the current git repository1275our$git_dir;1276sub evaluate_git_dir {1277our$git_dir="$projectroot/$project"if$project;1278}12791280our(@snapshot_fmts,$git_avatar,@extra_branch_refs);1281sub configure_gitweb_features {1282# list of supported snapshot formats1283our@snapshot_fmts= gitweb_get_feature('snapshot');1284@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts);12851286our($git_avatar) = gitweb_get_feature('avatar');1287$git_avatar=''unless$git_avatar=~/^(?:gravatar|picon)$/s;12881289our@extra_branch_refs= gitweb_get_feature('extra-branch-refs');1290@extra_branch_refs= filter_and_validate_refs (@extra_branch_refs);1291}12921293sub get_branch_refs {1294return('heads',@extra_branch_refs);1295}12961297# custom error handler: 'die <message>' is Internal Server Error1298sub handle_errors_html {1299my$msg=shift;# it is already HTML escaped13001301# to avoid infinite loop where error occurs in die_error,1302# change handler to default handler, disabling handle_errors_html1303 set_message("Error occurred when inside die_error:\n$msg");13041305# you cannot jump out of die_error when called as error handler;1306# the subroutine set via CGI::Carp::set_message is called _after_1307# HTTP headers are already written, so it cannot write them itself1308 die_error(undef,undef,$msg, -error_handler =>1, -no_http_header =>1);1309}1310set_message(\&handle_errors_html);13111312# dispatch1313sub dispatch {1314if(!defined$action) {1315if(defined$hash) {1316$action= git_get_type($hash);1317$actionor die_error(404,"Object does not exist");1318}elsif(defined$hash_base&&defined$file_name) {1319$action= git_get_type("$hash_base:$file_name");1320$actionor die_error(404,"File or directory does not exist");1321}elsif(defined$project) {1322$action='summary';1323}else{1324$action='project_list';1325}1326}1327if(!defined($actions{$action})) {1328 die_error(400,"Unknown action");1329}1330if($action!~m/^(?:opml|project_list|project_index)$/&&1331!$project) {1332 die_error(400,"Project needed");1333}1334$actions{$action}->();1335}13361337sub reset_timer {1338our$t0= [ gettimeofday() ]1339ifdefined$t0;1340our$number_of_git_cmds=0;1341}13421343our$first_request=1;1344sub run_request {1345 reset_timer();13461347 evaluate_uri();1348if($first_request) {1349 evaluate_gitweb_config();1350 evaluate_git_version();1351}1352if($per_request_config) {1353if(ref($per_request_config)eq'CODE') {1354$per_request_config->();1355}elsif(!$first_request) {1356 evaluate_gitweb_config();1357}1358}1359 check_loadavg();13601361# $projectroot and $projects_list might be set in gitweb config file1362$projects_list||=$projectroot;1363 evaluate_git_dir();13641365 evaluate_query_params();1366 evaluate_path_info();1367 evaluate_and_validate_params();13681369 configure_gitweb_features();13701371 dispatch();1372}13731374our$is_last_request=sub{1};1375our($pre_dispatch_hook,$post_dispatch_hook,$pre_listen_hook);1376our$CGI='CGI';1377our$cgi;1378sub configure_as_fcgi {1379require CGI::Fast;1380our$CGI='CGI::Fast';13811382my$request_number=0;1383# let each child service 100 requests1384our$is_last_request=sub{ ++$request_number>100};1385}1386sub evaluate_argv {1387my$script_name=$ENV{'SCRIPT_NAME'} ||$ENV{'SCRIPT_FILENAME'} || __FILE__;1388 configure_as_fcgi()1389if$script_name=~/\.fcgi$/;13901391return unless(@ARGV);13921393require Getopt::Long;1394 Getopt::Long::GetOptions(1395'fastcgi|fcgi|f'=> \&configure_as_fcgi,1396'nproc|n=i'=>sub{1397my($arg,$val) =@_;1398return unlesseval{require FCGI::ProcManager;1; };1399my$proc_manager= FCGI::ProcManager->new({1400 n_processes =>$val,1401});1402our$pre_listen_hook=sub{$proc_manager->pm_manage() };1403our$pre_dispatch_hook=sub{$proc_manager->pm_pre_dispatch() };1404our$post_dispatch_hook=sub{$proc_manager->pm_post_dispatch() };1405},1406);1407}14081409sub run {1410 evaluate_argv();14111412$first_request=1;1413$pre_listen_hook->()1414if$pre_listen_hook;14151416 REQUEST:1417while($cgi=$CGI->new()) {1418$pre_dispatch_hook->()1419if$pre_dispatch_hook;14201421 run_request();14221423$post_dispatch_hook->()1424if$post_dispatch_hook;1425$first_request=0;14261427last REQUEST if($is_last_request->());1428}14291430 DONE_GITWEB:14311;1432}14331434run();14351436if(defined caller) {1437# wrapped in a subroutine processing requests,1438# e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI1439return;1440}else{1441# pure CGI script, serving single request1442exit;1443}14441445## ======================================================================1446## action links14471448# possible values of extra options1449# -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)1450# -replay => 1 - start from a current view (replay with modifications)1451# -path_info => 0|1 - don't use/use path_info URL (if possible)1452# -anchor => ANCHOR - add #ANCHOR to end of URL, implies -replay if used alone1453sub href {1454my%params=@_;1455# default is to use -absolute url() i.e. $my_uri1456my$href=$params{-full} ?$my_url:$my_uri;14571458# implicit -replay, must be first of implicit params1459$params{-replay} =1if(keys%params==1&&$params{-anchor});14601461$params{'project'} =$projectunlessexists$params{'project'};14621463if($params{-replay}) {1464while(my($name,$symbol) =each%cgi_param_mapping) {1465if(!exists$params{$name}) {1466$params{$name} =$input_params{$name};1467}1468}1469}14701471my$use_pathinfo= gitweb_check_feature('pathinfo');1472if(defined$params{'project'} &&1473(exists$params{-path_info} ?$params{-path_info} :$use_pathinfo)) {1474# try to put as many parameters as possible in PATH_INFO:1475# - project name1476# - action1477# - hash_parent or hash_parent_base:/file_parent1478# - hash or hash_base:/filename1479# - the snapshot_format as an appropriate suffix14801481# When the script is the root DirectoryIndex for the domain,1482# $href here would be something like http://gitweb.example.com/1483# Thus, we strip any trailing / from $href, to spare us double1484# slashes in the final URL1485$href=~ s,/$,,;14861487# Then add the project name, if present1488$href.="/".esc_path_info($params{'project'});1489delete$params{'project'};14901491# since we destructively absorb parameters, we keep this1492# boolean that remembers if we're handling a snapshot1493my$is_snapshot=$params{'action'}eq'snapshot';14941495# Summary just uses the project path URL, any other action is1496# added to the URL1497if(defined$params{'action'}) {1498$href.="/".esc_path_info($params{'action'})1499unless$params{'action'}eq'summary';1500delete$params{'action'};1501}15021503# Next, we put hash_parent_base:/file_parent..hash_base:/file_name,1504# stripping nonexistent or useless pieces1505$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'}1506||$params{'hash_parent'} ||$params{'hash'});1507if(defined$params{'hash_base'}) {1508if(defined$params{'hash_parent_base'}) {1509$href.= esc_path_info($params{'hash_parent_base'});1510# skip the file_parent if it's the same as the file_name1511if(defined$params{'file_parent'}) {1512if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) {1513delete$params{'file_parent'};1514}elsif($params{'file_parent'} !~/\.\./) {1515$href.=":/".esc_path_info($params{'file_parent'});1516delete$params{'file_parent'};1517}1518}1519$href.="..";1520delete$params{'hash_parent'};1521delete$params{'hash_parent_base'};1522}elsif(defined$params{'hash_parent'}) {1523$href.= esc_path_info($params{'hash_parent'})."..";1524delete$params{'hash_parent'};1525}15261527$href.= esc_path_info($params{'hash_base'});1528if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) {1529$href.=":/".esc_path_info($params{'file_name'});1530delete$params{'file_name'};1531}1532delete$params{'hash'};1533delete$params{'hash_base'};1534}elsif(defined$params{'hash'}) {1535$href.= esc_path_info($params{'hash'});1536delete$params{'hash'};1537}15381539# If the action was a snapshot, we can absorb the1540# snapshot_format parameter too1541if($is_snapshot) {1542my$fmt=$params{'snapshot_format'};1543# snapshot_format should always be defined when href()1544# is called, but just in case some code forgets, we1545# fall back to the default1546$fmt||=$snapshot_fmts[0];1547$href.=$known_snapshot_formats{$fmt}{'suffix'};1548delete$params{'snapshot_format'};1549}1550}15511552# now encode the parameters explicitly1553my@result= ();1554for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1555my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1556if(defined$params{$name}) {1557if(ref($params{$name})eq"ARRAY") {1558foreachmy$par(@{$params{$name}}) {1559push@result,$symbol."=". esc_param($par);1560}1561}else{1562push@result,$symbol."=". esc_param($params{$name});1563}1564}1565}1566$href.="?".join(';',@result)ifscalar@result;15671568# final transformation: trailing spaces must be escaped (URI-encoded)1569$href=~s/(\s+)$/CGI::escape($1)/e;15701571if($params{-anchor}) {1572$href.="#".esc_param($params{-anchor});1573}15741575return$href;1576}157715781579## ======================================================================1580## validation, quoting/unquoting and escaping15811582sub is_valid_action {1583my$input=shift;1584returnundefunlessexists$actions{$input};1585return1;1586}15871588sub is_valid_project {1589my$input=shift;15901591return unlessdefined$input;1592if(!is_valid_pathname($input) ||1593!(-d "$projectroot/$input") ||1594!check_export_ok("$projectroot/$input") ||1595($strict_export&& !project_in_list($input))) {1596returnundef;1597}else{1598return1;1599}1600}16011602sub is_valid_pathname {1603my$input=shift;16041605returnundefunlessdefined$input;1606# no '.' or '..' as elements of path, i.e. no '.' or '..'1607# at the beginning, at the end, and between slashes.1608# also this catches doubled slashes1609if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1610returnundef;1611}1612# no null characters1613if($input=~m!\0!) {1614returnundef;1615}1616return1;1617}16181619sub is_valid_ref_format {1620my$input=shift;16211622returnundefunlessdefined$input;1623# restrictions on ref name according to git-check-ref-format1624if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1625returnundef;1626}1627return1;1628}16291630sub is_valid_refname {1631my$input=shift;16321633returnundefunlessdefined$input;1634# textual hashes are O.K.1635if($input=~m/^$oid_regex$/) {1636return1;1637}1638# it must be correct pathname1639 is_valid_pathname($input)orreturnundef;1640# check git-check-ref-format restrictions1641 is_valid_ref_format($input)orreturnundef;1642return1;1643}16441645# decode sequences of octets in utf8 into Perl's internal form,1646# which is utf-8 with utf8 flag set if needed. gitweb writes out1647# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1648sub to_utf8 {1649my$str=shift;1650returnundefunlessdefined$str;16511652if(utf8::is_utf8($str) || utf8::decode($str)) {1653return$str;1654}else{1655return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1656}1657}16581659# quote unsafe chars, but keep the slash, even when it's not1660# correct, but quoted slashes look too horrible in bookmarks1661sub esc_param {1662my$str=shift;1663returnundefunlessdefined$str;1664$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1665$str=~s/ /\+/g;1666return$str;1667}16681669# the quoting rules for path_info fragment are slightly different1670sub esc_path_info {1671my$str=shift;1672returnundefunlessdefined$str;16731674# path_info doesn't treat '+' as space (specially), but '?' must be escaped1675$str=~s/([^A-Za-z0-9\-_.~();\/;:@&= +]+)/CGI::escape($1)/eg;16761677return$str;1678}16791680# quote unsafe chars in whole URL, so some characters cannot be quoted1681sub esc_url {1682my$str=shift;1683returnundefunlessdefined$str;1684$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg;1685$str=~s/ /\+/g;1686return$str;1687}16881689# quote unsafe characters in HTML attributes1690sub esc_attr {16911692# for XHTML conformance escaping '"' to '"' is not enough1693return esc_html(@_);1694}16951696# replace invalid utf8 character with SUBSTITUTION sequence1697sub esc_html {1698my$str=shift;1699my%opts=@_;17001701returnundefunlessdefined$str;17021703$str= to_utf8($str);1704$str=$cgi->escapeHTML($str);1705if($opts{'-nbsp'}) {1706$str=~s/ / /g;1707}1708$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1709return$str;1710}17111712# quote control characters and escape filename to HTML1713sub esc_path {1714my$str=shift;1715my%opts=@_;17161717returnundefunlessdefined$str;17181719$str= to_utf8($str);1720$str=$cgi->escapeHTML($str);1721if($opts{'-nbsp'}) {1722$str=~s/ / /g;1723}1724$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1725return$str;1726}17271728# Sanitize for use in XHTML + application/xml+xhtml (valid XML 1.0)1729sub sanitize {1730my$str=shift;17311732returnundefunlessdefined$str;17331734$str= to_utf8($str);1735$str=~ s|([[:cntrl:]])|(index("\t\n\r",$1) != -1?$1: quot_cec($1))|eg;1736return$str;1737}17381739# Make control characters "printable", using character escape codes (CEC)1740sub quot_cec {1741my$cntrl=shift;1742my%opts=@_;1743my%es= (# character escape codes, aka escape sequences1744"\t"=>'\t',# tab (HT)1745"\n"=>'\n',# line feed (LF)1746"\r"=>'\r',# carrige return (CR)1747"\f"=>'\f',# form feed (FF)1748"\b"=>'\b',# backspace (BS)1749"\a"=>'\a',# alarm (bell) (BEL)1750"\e"=>'\e',# escape (ESC)1751"\013"=>'\v',# vertical tab (VT)1752"\000"=>'\0',# nul character (NUL)1753);1754my$chr= ( (exists$es{$cntrl})1755?$es{$cntrl}1756:sprintf('\%2x',ord($cntrl)) );1757if($opts{-nohtml}) {1758return$chr;1759}else{1760return"<span class=\"cntrl\">$chr</span>";1761}1762}17631764# Alternatively use unicode control pictures codepoints,1765# Unicode "printable representation" (PR)1766sub quot_upr {1767my$cntrl=shift;1768my%opts=@_;17691770my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1771if($opts{-nohtml}) {1772return$chr;1773}else{1774return"<span class=\"cntrl\">$chr</span>";1775}1776}17771778# git may return quoted and escaped filenames1779sub unquote {1780my$str=shift;17811782sub unq {1783my$seq=shift;1784my%es= (# character escape codes, aka escape sequences1785't'=>"\t",# tab (HT, TAB)1786'n'=>"\n",# newline (NL)1787'r'=>"\r",# return (CR)1788'f'=>"\f",# form feed (FF)1789'b'=>"\b",# backspace (BS)1790'a'=>"\a",# alarm (bell) (BEL)1791'e'=>"\e",# escape (ESC)1792'v'=>"\013",# vertical tab (VT)1793);17941795if($seq=~m/^[0-7]{1,3}$/) {1796# octal char sequence1797returnchr(oct($seq));1798}elsif(exists$es{$seq}) {1799# C escape sequence, aka character escape code1800return$es{$seq};1801}1802# quoted ordinary character1803return$seq;1804}18051806if($str=~m/^"(.*)"$/) {1807# needs unquoting1808$str=$1;1809$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1810}1811return$str;1812}18131814# escape tabs (convert tabs to spaces)1815sub untabify {1816my$line=shift;18171818while((my$pos=index($line,"\t")) != -1) {1819if(my$count= (8- ($pos%8))) {1820my$spaces=' ' x $count;1821$line=~s/\t/$spaces/;1822}1823}18241825return$line;1826}18271828sub project_in_list {1829my$project=shift;1830my@list= git_get_projects_list();1831return@list&&scalar(grep{$_->{'path'}eq$project}@list);1832}18331834## ----------------------------------------------------------------------1835## HTML aware string manipulation18361837# Try to chop given string on a word boundary between position1838# $len and $len+$add_len. If there is no word boundary there,1839# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1840# (marking chopped part) would be longer than given string.1841sub chop_str {1842my$str=shift;1843my$len=shift;1844my$add_len=shift||10;1845my$where=shift||'right';# 'left' | 'center' | 'right'18461847# Make sure perl knows it is utf8 encoded so we don't1848# cut in the middle of a utf8 multibyte char.1849$str= to_utf8($str);18501851# allow only $len chars, but don't cut a word if it would fit in $add_len1852# if it doesn't fit, cut it if it's still longer than the dots we would add1853# remove chopped character entities entirely18541855# when chopping in the middle, distribute $len into left and right part1856# return early if chopping wouldn't make string shorter1857if($whereeq'center') {1858return$strif($len+5>=length($str));# filler is length 51859$len=int($len/2);1860}else{1861return$strif($len+4>=length($str));# filler is length 41862}18631864# regexps: ending and beginning with word part up to $add_len1865my$endre=qr/.{$len}\w{0,$add_len}/;1866my$begre=qr/\w{0,$add_len}.{$len}/;18671868if($whereeq'left') {1869$str=~m/^(.*?)($begre)$/;1870my($lead,$body) = ($1,$2);1871if(length($lead) >4) {1872$lead=" ...";1873}1874return"$lead$body";18751876}elsif($whereeq'center') {1877$str=~m/^($endre)(.*)$/;1878my($left,$str) = ($1,$2);1879$str=~m/^(.*?)($begre)$/;1880my($mid,$right) = ($1,$2);1881if(length($mid) >5) {1882$mid=" ... ";1883}1884return"$left$mid$right";18851886}else{1887$str=~m/^($endre)(.*)$/;1888my$body=$1;1889my$tail=$2;1890if(length($tail) >4) {1891$tail="... ";1892}1893return"$body$tail";1894}1895}18961897# takes the same arguments as chop_str, but also wraps a <span> around the1898# result with a title attribute if it does get chopped. Additionally, the1899# string is HTML-escaped.1900sub chop_and_escape_str {1901my($str) =@_;19021903my$chopped= chop_str(@_);1904$str= to_utf8($str);1905if($choppedeq$str) {1906return esc_html($chopped);1907}else{1908$str=~s/[[:cntrl:]]/?/g;1909return$cgi->span({-title=>$str}, esc_html($chopped));1910}1911}19121913# Highlight selected fragments of string, using given CSS class,1914# and escape HTML. It is assumed that fragments do not overlap.1915# Regions are passed as list of pairs (array references).1916#1917# Example: esc_html_hl_regions("foobar", "mark", [ 0, 3 ]) returns1918# '<span class="mark">foo</span>bar'1919sub esc_html_hl_regions {1920my($str,$css_class,@sel) =@_;1921my%opts=grep{ref($_)ne'ARRAY'}@sel;1922@sel=grep{ref($_)eq'ARRAY'}@sel;1923return esc_html($str,%opts)unless@sel;19241925my$out='';1926my$pos=0;19271928formy$s(@sel) {1929my($begin,$end) =@$s;19301931# Don't create empty <span> elements.1932next if$end<=$begin;19331934my$escaped= esc_html(substr($str,$begin,$end-$begin),1935%opts);19361937$out.= esc_html(substr($str,$pos,$begin-$pos),%opts)1938if($begin-$pos>0);1939$out.=$cgi->span({-class=>$css_class},$escaped);19401941$pos=$end;1942}1943$out.= esc_html(substr($str,$pos),%opts)1944if($pos<length($str));19451946return$out;1947}19481949# return positions of beginning and end of each match1950sub matchpos_list {1951my($str,$regexp) =@_;1952return unless(defined$str&&defined$regexp);19531954my@matches;1955while($str=~/$regexp/g) {1956push@matches, [$-[0],$+[0]];1957}1958return@matches;1959}19601961# highlight match (if any), and escape HTML1962sub esc_html_match_hl {1963my($str,$regexp) =@_;1964return esc_html($str)unlessdefined$regexp;19651966my@matches= matchpos_list($str,$regexp);1967return esc_html($str)unless@matches;19681969return esc_html_hl_regions($str,'match',@matches);1970}197119721973# highlight match (if any) of shortened string, and escape HTML1974sub esc_html_match_hl_chopped {1975my($str,$chopped,$regexp) =@_;1976return esc_html_match_hl($str,$regexp)unlessdefined$chopped;19771978my@matches= matchpos_list($str,$regexp);1979return esc_html($chopped)unless@matches;19801981# filter matches so that we mark chopped string1982my$tail="... ";# see chop_str1983unless($chopped=~s/\Q$tail\E$//) {1984$tail='';1985}1986my$chop_len=length($chopped);1987my$tail_len=length($tail);1988my@filtered;19891990formy$m(@matches) {1991if($m->[0] >$chop_len) {1992push@filtered, [$chop_len,$chop_len+$tail_len]if($tail_len>0);1993last;1994}elsif($m->[1] >$chop_len) {1995push@filtered, [$m->[0],$chop_len+$tail_len];1996last;1997}1998push@filtered,$m;1999}20002001return esc_html_hl_regions($chopped.$tail,'match',@filtered);2002}20032004## ----------------------------------------------------------------------2005## functions returning short strings20062007# CSS class for given age value (in seconds)2008sub age_class {2009my$age=shift;20102011if(!defined$age) {2012return"noage";2013}elsif($age<60*60*2) {2014return"age0";2015}elsif($age<60*60*24*2) {2016return"age1";2017}else{2018return"age2";2019}2020}20212022# convert age in seconds to "nn units ago" string2023sub age_string {2024my$age=shift;2025my$age_str;20262027if($age>60*60*24*365*2) {2028$age_str= (int$age/60/60/24/365);2029$age_str.=" years ago";2030}elsif($age>60*60*24*(365/12)*2) {2031$age_str=int$age/60/60/24/(365/12);2032$age_str.=" months ago";2033}elsif($age>60*60*24*7*2) {2034$age_str=int$age/60/60/24/7;2035$age_str.=" weeks ago";2036}elsif($age>60*60*24*2) {2037$age_str=int$age/60/60/24;2038$age_str.=" days ago";2039}elsif($age>60*60*2) {2040$age_str=int$age/60/60;2041$age_str.=" hours ago";2042}elsif($age>60*2) {2043$age_str=int$age/60;2044$age_str.=" min ago";2045}elsif($age>2) {2046$age_str=int$age;2047$age_str.=" sec ago";2048}else{2049$age_str.=" right now";2050}2051return$age_str;2052}20532054useconstant{2055 S_IFINVALID =>0030000,2056 S_IFGITLINK =>0160000,2057};20582059# submodule/subproject, a commit object reference2060sub S_ISGITLINK {2061my$mode=shift;20622063return(($mode& S_IFMT) == S_IFGITLINK)2064}20652066# convert file mode in octal to symbolic file mode string2067sub mode_str {2068my$mode=oct shift;20692070if(S_ISGITLINK($mode)) {2071return'm---------';2072}elsif(S_ISDIR($mode& S_IFMT)) {2073return'drwxr-xr-x';2074}elsif(S_ISLNK($mode)) {2075return'lrwxrwxrwx';2076}elsif(S_ISREG($mode)) {2077# git cares only about the executable bit2078if($mode& S_IXUSR) {2079return'-rwxr-xr-x';2080}else{2081return'-rw-r--r--';2082};2083}else{2084return'----------';2085}2086}20872088# convert file mode in octal to file type string2089sub file_type {2090my$mode=shift;20912092if($mode!~m/^[0-7]+$/) {2093return$mode;2094}else{2095$mode=oct$mode;2096}20972098if(S_ISGITLINK($mode)) {2099return"submodule";2100}elsif(S_ISDIR($mode& S_IFMT)) {2101return"directory";2102}elsif(S_ISLNK($mode)) {2103return"symlink";2104}elsif(S_ISREG($mode)) {2105return"file";2106}else{2107return"unknown";2108}2109}21102111# convert file mode in octal to file type description string2112sub file_type_long {2113my$mode=shift;21142115if($mode!~m/^[0-7]+$/) {2116return$mode;2117}else{2118$mode=oct$mode;2119}21202121if(S_ISGITLINK($mode)) {2122return"submodule";2123}elsif(S_ISDIR($mode& S_IFMT)) {2124return"directory";2125}elsif(S_ISLNK($mode)) {2126return"symlink";2127}elsif(S_ISREG($mode)) {2128if($mode& S_IXUSR) {2129return"executable";2130}else{2131return"file";2132};2133}else{2134return"unknown";2135}2136}213721382139## ----------------------------------------------------------------------2140## functions returning short HTML fragments, or transforming HTML fragments2141## which don't belong to other sections21422143# format line of commit message.2144sub format_log_line_html {2145my$line=shift;21462147# Potentially abbreviated OID.2148my$regex= oid_nlen_regex("7,64");21492150$line= esc_html($line);2151$line=~ s{2152\b2153(2154# The output of "git describe", e.g. v2.10.0-297-gf6727b02155# or hadoop-20160921-113441-20-g094fb7d2156(?<!-)# see strbuf_check_tag_ref(). Tags can't start with -2157[A-Za-z0-9.-]+2158(?!\.)# refs can't end with ".", see check_refname_format()2159-g$regex2160|2161# Just a normal looking Git SHA12162$regex2163)2164\b2165}{2166$cgi->a({-href => href(action=>"object", hash=>$1),2167-class=>"text"},$1);2168}egx;21692170return$line;2171}21722173# format marker of refs pointing to given object21742175# the destination action is chosen based on object type and current context:2176# - for annotated tags, we choose the tag view unless it's the current view2177# already, in which case we go to shortlog view2178# - for other refs, we keep the current view if we're in history, shortlog or2179# log view, and select shortlog otherwise2180sub format_ref_marker {2181my($refs,$id) =@_;2182my$markers='';21832184if(defined$refs->{$id}) {2185foreachmy$ref(@{$refs->{$id}}) {2186# this code exploits the fact that non-lightweight tags are the2187# only indirect objects, and that they are the only objects for which2188# we want to use tag instead of shortlog as action2189my($type,$name) =qw();2190my$indirect= ($ref=~s/\^\{\}$//);2191# e.g. tags/v2.6.11 or heads/next2192if($ref=~m!^(.*?)s?/(.*)$!) {2193$type=$1;2194$name=$2;2195}else{2196$type="ref";2197$name=$ref;2198}21992200my$class=$type;2201$class.=" indirect"if$indirect;22022203my$dest_action="shortlog";2204my$dest="";2205$dest.="refs/"unless$ref=~ m!^refs/!;2206$dest.=$ref;22072208if($indirect) {2209$dest_action="tag"unless$actioneq"tag";2210$markers.=$cgi->a({2211-href => href(2212 action=>$dest_action,2213 hash=>$dest2214)},'<span class="'. esc_attr($class)2215.'" title="'. esc_attr($ref) .'"><svg width="14" height="14" '2216.'xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">'2217.'<use xlink:href="#tagicon" /></svg>'. esc_html($name) .'</span>');2218}elsif($action=~/^(history|(short)?log)$/) {2219$dest_action=$action;2220$markers.=$cgi->a({2221-href => href(2222 action=>$dest_action,2223 hash=>$dest2224)},'<span class="'. esc_attr($class)2225.'" title="'. esc_attr($ref) .'"><svg width="14" height="14" '2226.'xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">'2227.'<use xlink:href="#reficon" /></svg>'. esc_html($name) .'</span>');2228}2229223022312232}2233}22342235if($markers) {2236return' <span class="refs">'.$markers.'</span>';2237}else{2238return"";2239}2240}22412242# format, perhaps shortened and with markers, title line2243sub format_subject_html {2244my($long,$short,$href,$extra) =@_;2245$extra=''unlessdefined($extra);22462247if(length($short) <length($long)) {2248$long=~s/[[:cntrl:]]/?/g;2249return$cgi->a({-href =>$href, -class=>"list subject",2250-title => to_utf8($long)},2251 esc_html($short)) .$extra;2252}else{2253return$cgi->a({-href =>$href, -class=>"list subject"},2254 esc_html($long)) .$extra;2255}2256}22572258# Rather than recomputing the url for an email multiple times, we cache it2259# after the first hit. This gives a visible benefit in views where the avatar2260# for the same email is used repeatedly (e.g. shortlog).2261# The cache is shared by all avatar engines (currently gravatar only), which2262# are free to use it as preferred. Since only one avatar engine is used for any2263# given page, there's no risk for cache conflicts.2264our%avatar_cache= ();22652266# Compute the picon url for a given email, by using the picon search service over at2267# http://www.cs.indiana.edu/picons/search.html2268sub picon_url {2269my$email=lc shift;2270if(!$avatar_cache{$email}) {2271my($user,$domain) =split('@',$email);2272$avatar_cache{$email} =2273"//www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".2274"$domain/$user/".2275"users+domains+unknown/up/single";2276}2277return$avatar_cache{$email};2278}22792280# Compute the gravatar url for a given email, if it's not in the cache already.2281# Gravatar stores only the part of the URL before the size, since that's the2282# one computationally more expensive. This also allows reuse of the cache for2283# different sizes (for this particular engine).2284sub gravatar_url {2285my$email=lc shift;2286my$size=shift;2287$avatar_cache{$email} ||=2288"//www.gravatar.com/avatar/".2289 md5_hex($email) ."?s=";2290return$avatar_cache{$email} .$size;2291}22922293# Insert an avatar for the given $email at the given $size if the feature2294# is enabled.2295sub git_get_avatar {2296my($email,%opts) =@_;2297my$pre_white= ($opts{-pad_before} ?" ":"");2298my$post_white= ($opts{-pad_after} ?" ":"");2299$opts{-size} ||='default';2300my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};2301my$url="";2302if($git_avatareq'gravatar') {2303$url= gravatar_url($email,$size);2304}elsif($git_avatareq'picon') {2305$url= picon_url($email);2306}2307# Other providers can be added by extending the if chain, defining $url2308# as needed. If no variant puts something in $url, we assume avatars2309# are completely disabled/unavailable.2310if($url) {2311return$pre_white.2312"<img width=\"$size\"".2313"class=\"avatar\"".2314"src=\"".esc_url($url)."\"".2315"alt=\"\"".2316"/>".$post_white;2317}else{2318return"";2319}2320}23212322sub format_search_author {2323my($author,$searchtype,$displaytext) =@_;2324my$have_search= gitweb_check_feature('search');23252326if($have_search) {2327my$performed="";2328if($searchtypeeq'author') {2329$performed="authored";2330}elsif($searchtypeeq'committer') {2331$performed="committed";2332}23332334return$cgi->a({-href => href(action=>"search", hash=>$hash,2335 searchtext=>$author,2336 searchtype=>$searchtype),class=>"list",2337 title=>"Search for commits$performedby$author"},2338$displaytext);23392340}else{2341return$displaytext;2342}2343}23442345# format the author name of the given commit with the given tag2346# the author name is chopped and escaped according to the other2347# optional parameters (see chop_str).2348sub format_author_html {2349if(not gitweb_check_feature('summary_omit_author')) {2350my$tag=shift;2351my$co=shift;2352my$author= chop_and_escape_str($co->{'author_name'},@_);2353return"<$tagclass=\"author\">".2354 format_search_author($co->{'author_name'},"author",2355 git_get_avatar($co->{'author_email'}, -pad_after =>1) .2356$author) .2357"</$tag>";2358}else{2359return"";2360}2361}23622363# format git diff header line, i.e. "diff --(git|combined|cc) ..."2364sub format_git_diff_header_line {2365my$line=shift;2366my$diffinfo=shift;2367my($from,$to) =@_;23682369if($diffinfo->{'nparents'}) {2370# combined diff2371$line=~s!^(diff (.*?) )"?.*$!$1!;2372if($to->{'href'}) {2373$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},2374 esc_path($to->{'file'}));2375}else{# file was deleted (no href)2376$line.= esc_path($to->{'file'});2377}2378}else{2379# "ordinary" diff2380$line=~s!^(diff (.*?) )"?a/.*$!$1!;2381if($from->{'href'}) {2382$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},2383'a/'. esc_path($from->{'file'}));2384}else{# file was added (no href)2385$line.='a/'. esc_path($from->{'file'});2386}2387$line.=' ';2388if($to->{'href'}) {2389$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},2390'b/'. esc_path($to->{'file'}));2391}else{# file was deleted2392$line.='b/'. esc_path($to->{'file'});2393}2394}23952396return"<div class=\"diff header\">$line</div>\n";2397}23982399# format extended diff header line, before patch itself2400sub format_extended_diff_header_line {2401my$line=shift;2402my$diffinfo=shift;2403my($from,$to) =@_;24042405# match <path>2406if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {2407$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},2408 esc_path($from->{'file'}));2409}2410if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {2411$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},2412 esc_path($to->{'file'}));2413}2414# match single <mode>2415if($line=~m/\s(\d{6})$/) {2416$line.='<span class="info"> ('.2417 file_type_long($1) .2418')</span>';2419}2420# match <hash>2421if($line=~ oid_nlen_prefix_infix_regex($sha1_len,"index ",",") |2422$line=~ oid_nlen_prefix_infix_regex($sha256_len,"index ",",")) {2423# can match only for combined diff2424$line='index ';2425for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2426if($from->{'href'}[$i]) {2427$line.=$cgi->a({-href=>$from->{'href'}[$i],2428-class=>"hash"},2429substr($diffinfo->{'from_id'}[$i],0,7));2430}else{2431$line.='0' x 7;2432}2433# separator2434$line.=','if($i<$diffinfo->{'nparents'} -1);2435}2436$line.='..';2437if($to->{'href'}) {2438$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2439substr($diffinfo->{'to_id'},0,7));2440}else{2441$line.='0' x 7;2442}24432444}elsif($line=~ oid_nlen_prefix_infix_regex($sha1_len,"index ","..") |2445$line=~ oid_nlen_prefix_infix_regex($sha256_len,"index ","..")) {2446# can match only for ordinary diff2447my($from_link,$to_link);2448if($from->{'href'}) {2449$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},2450substr($diffinfo->{'from_id'},0,7));2451}else{2452$from_link='0' x 7;2453}2454if($to->{'href'}) {2455$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2456substr($diffinfo->{'to_id'},0,7));2457}else{2458$to_link='0' x 7;2459}2460my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});2461$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;2462}24632464return$line."<br/>\n";2465}24662467# format from-file/to-file diff header2468sub format_diff_from_to_header {2469my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;2470my$line;2471my$result='';24722473$line=$from_line;2474#assert($line =~ m/^---/) if DEBUG;2475# no extra formatting for "^--- /dev/null"2476if(!$diffinfo->{'nparents'}) {2477# ordinary (single parent) diff2478if($line=~m!^--- "?a/!) {2479if($from->{'href'}) {2480$line='--- a/'.2481$cgi->a({-href=>$from->{'href'}, -class=>"path"},2482 esc_path($from->{'file'}));2483}else{2484$line='--- a/'.2485 esc_path($from->{'file'});2486}2487}2488$result.= qq!<div class="diff from_file">$line</div>\n!;24892490}else{2491# combined diff (merge commit)2492for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2493if($from->{'href'}[$i]) {2494$line='--- '.2495$cgi->a({-href=>href(action=>"blobdiff",2496 hash_parent=>$diffinfo->{'from_id'}[$i],2497 hash_parent_base=>$parents[$i],2498 file_parent=>$from->{'file'}[$i],2499 hash=>$diffinfo->{'to_id'},2500 hash_base=>$hash,2501 file_name=>$to->{'file'}),2502-class=>"path",2503-title=>"diff". ($i+1)},2504$i+1) .2505'/'.2506$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},2507 esc_path($from->{'file'}[$i]));2508}else{2509$line='--- /dev/null';2510}2511$result.= qq!<div class="diff from_file">$line</div>\n!;2512}2513}25142515$line=$to_line;2516#assert($line =~ m/^\+\+\+/) if DEBUG;2517# no extra formatting for "^+++ /dev/null"2518if($line=~m!^\+\+\+ "?b/!) {2519if($to->{'href'}) {2520$line='+++ b/'.2521$cgi->a({-href=>$to->{'href'}, -class=>"path"},2522 esc_path($to->{'file'}));2523}else{2524$line='+++ b/'.2525 esc_path($to->{'file'});2526}2527}2528$result.= qq!<div class="diff to_file">$line</div>\n!;25292530return$result;2531}25322533# create note for patch simplified by combined diff2534sub format_diff_cc_simplified {2535my($diffinfo,@parents) =@_;2536my$result='';25372538$result.="<div class=\"diff header\">".2539"diff --cc ";2540if(!is_deleted($diffinfo)) {2541$result.=$cgi->a({-href => href(action=>"blob",2542 hash_base=>$hash,2543 hash=>$diffinfo->{'to_id'},2544 file_name=>$diffinfo->{'to_file'}),2545-class=>"path"},2546 esc_path($diffinfo->{'to_file'}));2547}else{2548$result.= esc_path($diffinfo->{'to_file'});2549}2550$result.="</div>\n".# class="diff header"2551"<div class=\"diff nodifferences\">".2552"Simple merge".2553"</div>\n";# class="diff nodifferences"25542555return$result;2556}25572558sub diff_line_class {2559my($line,$from,$to) =@_;25602561# ordinary diff2562my$num_sign=1;2563# combined diff2564if($from&&$to&&ref($from->{'href'})eq"ARRAY") {2565$num_sign=scalar@{$from->{'href'}};2566}25672568my@diff_line_classifier= (2569{ regexp =>qr/^\@\@{$num_sign} /,class=>"chunk_header"},2570{ regexp =>qr/^\\/,class=>"incomplete"},2571{ regexp =>qr/^ {$num_sign}/,class=>"ctx"},2572# classifier for context must come before classifier add/rem,2573# or we would have to use more complicated regexp, for example2574# qr/(?= {0,$m}\+)[+ ]{$num_sign}/, where $m = $num_sign - 1;2575{ regexp =>qr/^[+ ]{$num_sign}/,class=>"add"},2576{ regexp =>qr/^[- ]{$num_sign}/,class=>"rem"},2577);2578formy$clsfy(@diff_line_classifier) {2579return$clsfy->{'class'}2580if($line=~$clsfy->{'regexp'});2581}25822583# fallback2584return"";2585}25862587# assumes that $from and $to are defined and correctly filled,2588# and that $line holds a line of chunk header for unified diff2589sub format_unidiff_chunk_header {2590my($line,$from,$to) =@_;25912592my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =2593$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;25942595$from_lines=0unlessdefined$from_lines;2596$to_lines=0unlessdefined$to_lines;25972598if($from->{'href'}) {2599$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",2600-class=>"list"},$from_text);2601}2602if($to->{'href'}) {2603$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",2604-class=>"list"},$to_text);2605}2606$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".2607"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2608return$line;2609}26102611# assumes that $from and $to are defined and correctly filled,2612# and that $line holds a line of chunk header for combined diff2613sub format_cc_diff_chunk_header {2614my($line,$from,$to) =@_;26152616my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;2617my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);26182619@from_text=split(' ',$ranges);2620for(my$i=0;$i<@from_text; ++$i) {2621($from_start[$i],$from_nlines[$i]) =2622(split(',',substr($from_text[$i],1)),0);2623}26242625$to_text=pop@from_text;2626$to_start=pop@from_start;2627$to_nlines=pop@from_nlines;26282629$line="<span class=\"chunk_info\">$prefix";2630for(my$i=0;$i<@from_text; ++$i) {2631if($from->{'href'}[$i]) {2632$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",2633-class=>"list"},$from_text[$i]);2634}else{2635$line.=$from_text[$i];2636}2637$line.=" ";2638}2639if($to->{'href'}) {2640$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",2641-class=>"list"},$to_text);2642}else{2643$line.=$to_text;2644}2645$line.="$prefix</span>".2646"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2647return$line;2648}26492650# process patch (diff) line (not to be used for diff headers),2651# returning HTML-formatted (but not wrapped) line.2652# If the line is passed as a reference, it is treated as HTML and not2653# esc_html()'ed.2654sub format_diff_line {2655my($line,$diff_class,$from,$to) =@_;26562657if(ref($line)) {2658$line=$$line;2659}else{2660chomp$line;2661$line= untabify($line);26622663if($from&&$to&&$line=~m/^\@{2} /) {2664$line= format_unidiff_chunk_header($line,$from,$to);2665}elsif($from&&$to&&$line=~m/^\@{3}/) {2666$line= format_cc_diff_chunk_header($line,$from,$to);2667}else{2668$line= esc_html($line, -nbsp=>1);2669}2670}26712672my$diff_classes="diff";2673$diff_classes.="$diff_class"if($diff_class);2674$line="<div class=\"$diff_classes\">$line</div>\n";26752676return$line;2677}26782679# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",2680# linked. Pass the hash of the tree/commit to snapshot.2681sub format_snapshot_links {2682my($hash) =@_;2683my$num_fmts=@snapshot_fmts;2684if($num_fmts>1) {2685# A parenthesized list of links bearing format names.2686# e.g. "snapshot (_tar.gz_ _zip_)"2687return"snapshot (".join(' ',map2688$cgi->a({2689-href => href(2690 action=>"snapshot",2691 hash=>$hash,2692 snapshot_format=>$_2693)2694},$known_snapshot_formats{$_}{'display'})2695,@snapshot_fmts) .")";2696}elsif($num_fmts==1) {2697# A single "snapshot" link whose tooltip bears the format name.2698# i.e. "_snapshot_"2699my($fmt) =@snapshot_fmts;2700return2701$cgi->a({2702-href => href(2703 action=>"snapshot",2704 hash=>$hash,2705 snapshot_format=>$fmt2706),2707-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"2708},"snapshot");2709}else{# $num_fmts == 02710returnundef;2711}2712}27132714## ......................................................................2715## functions returning values to be passed, perhaps after some2716## transformation, to other functions; e.g. returning arguments to href()27172718# returns hash to be passed to href to generate gitweb URL2719# in -title key it returns description of link2720sub get_feed_info {2721my$format=shift||'Atom';2722my%res= (action =>lc($format));2723my$matched_ref=0;27242725# feed links are possible only for project views2726return unless(defined$project);2727# some views should link to OPML, or to generic project feed,2728# or don't have specific feed yet (so they should use generic)2729return if(!$action||$action=~/^(?:tags|heads|forks|tag|search)$/x);27302731my$branch=undef;2732# branches refs uses 'refs/' + $get_branch_refs()[x] + '/' prefix2733# (fullname) to differentiate from tag links; this also makes2734# possible to detect branch links2735formy$ref(get_branch_refs()) {2736if((defined$hash_base&&$hash_base=~m!^refs/\Q$ref\E/(.*)$!) ||2737(defined$hash&&$hash=~m!^refs/\Q$ref\E/(.*)$!)) {2738$branch=$1;2739$matched_ref=$ref;2740last;2741}2742}2743# find log type for feed description (title)2744my$type='log';2745if(defined$file_name) {2746$type="history of$file_name";2747$type.="/"if($actioneq'tree');2748$type.=" on '$branch'"if(defined$branch);2749}else{2750$type="log of$branch"if(defined$branch);2751}27522753$res{-title} =$type;2754$res{'hash'} = (defined$branch?"refs/$matched_ref/$branch":undef);2755$res{'file_name'} =$file_name;27562757return%res;2758}27592760## ----------------------------------------------------------------------2761## git utility subroutines, invoking git commands27622763# returns path to the core git executable and the --git-dir parameter as list2764sub git_cmd {2765$number_of_git_cmds++;2766 evaluate_git_dir();2767return$GIT,'--git-dir='.$git_dir;2768}27692770# quote the given arguments for passing them to the shell2771# quote_command("command", "arg 1", "arg with ' and ! characters")2772# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2773# Try to avoid using this function wherever possible.2774sub quote_command {2775returnjoin(' ',2776map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2777}27782779# get HEAD ref of given project as hash2780sub git_get_head_hash {2781return git_get_full_hash(shift,'HEAD');2782}27832784sub git_get_full_hash {2785return git_get_hash(@_);2786}27872788sub git_get_short_hash {2789return git_get_hash(@_,'--short=7');2790}27912792sub git_get_hash {2793my($project,$hash,@options) =@_;2794my$o_git_dir=$git_dir;2795my$retval=undef;2796$git_dir="$projectroot/$project";2797if(open my$fd,'-|', git_cmd(),'rev-parse',2798'--verify','-q',@options,$hash) {2799$retval= <$fd>;2800chomp$retvalifdefined$retval;2801close$fd;2802}2803if(defined$o_git_dir) {2804$git_dir=$o_git_dir;2805}2806return$retval;2807}28082809# get type of given object2810sub git_get_type {2811my$hash=shift;28122813open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2814my$type= <$fd>;2815close$fdorreturn;2816chomp$type;2817return$type;2818}28192820# repository configuration2821our$config_file='';2822our%config;28232824# store multiple values for single key as anonymous array reference2825# single values stored directly in the hash, not as [ <value> ]2826sub hash_set_multi {2827my($hash,$key,$value) =@_;28282829if(!exists$hash->{$key}) {2830$hash->{$key} =$value;2831}elsif(!ref$hash->{$key}) {2832$hash->{$key} = [$hash->{$key},$value];2833}else{2834push@{$hash->{$key}},$value;2835}2836}28372838# return hash of git project configuration2839# optionally limited to some section, e.g. 'gitweb'2840sub git_parse_project_config {2841my$section_regexp=shift;2842my%config;28432844local$/="\0";28452846open my$fh,"-|", git_cmd(),"config",'-z','-l',2847orreturn;28482849while(my$keyval= <$fh>) {2850chomp$keyval;2851my($key,$value) =split(/\n/,$keyval,2);28522853 hash_set_multi(\%config,$key,$value)2854if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2855}2856close$fh;28572858return%config;2859}28602861# convert config value to boolean: 'true' or 'false'2862# no value, number > 0, 'true' and 'yes' values are true2863# rest of values are treated as false (never as error)2864sub config_to_bool {2865my$val=shift;28662867return1if!defined$val;# section.key28682869# strip leading and trailing whitespace2870$val=~s/^\s+//;2871$val=~s/\s+$//;28722873return(($val=~/^\d+$/&&$val) ||# section.key = 12874($val=~/^(?:true|yes)$/i));# section.key = true2875}28762877# convert config value to simple decimal number2878# an optional value suffix of 'k', 'm', or 'g' will cause the value2879# to be multiplied by 1024, 1048576, or 10737418242880sub config_to_int {2881my$val=shift;28822883# strip leading and trailing whitespace2884$val=~s/^\s+//;2885$val=~s/\s+$//;28862887if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2888$unit=lc($unit);2889# unknown unit is treated as 12890return$num* ($uniteq'g'?1073741824:2891$uniteq'm'?1048576:2892$uniteq'k'?1024:1);2893}2894return$val;2895}28962897# convert config value to array reference, if needed2898sub config_to_multi {2899my$val=shift;29002901returnref($val) ?$val: (defined($val) ? [$val] : []);2902}29032904sub git_get_project_config {2905my($key,$type) =@_;29062907return unlessdefined$git_dir;29082909# key sanity check2910return unless($key);2911# only subsection, if exists, is case sensitive,2912# and not lowercased by 'git config -z -l'2913if(my($hi,$mi,$lo) = ($key=~/^([^.]*)\.(.*)\.([^.]*)$/)) {2914$lo=~s/_//g;2915$key=join(".",lc($hi),$mi,lc($lo));2916return if($lo=~/\W/||$hi=~/\W/);2917}else{2918$key=lc($key);2919$key=~s/_//g;2920return if($key=~/\W/);2921}2922$key=~s/^gitweb\.//;29232924# type sanity check2925if(defined$type) {2926$type=~s/^--//;2927$type=undef2928unless($typeeq'bool'||$typeeq'int');2929}29302931# get config2932if(!defined$config_file||2933$config_filene"$git_dir/config") {2934%config= git_parse_project_config('gitweb');2935$config_file="$git_dir/config";2936}29372938# check if config variable (key) exists2939return unlessexists$config{"gitweb.$key"};29402941# ensure given type2942if(!defined$type) {2943return$config{"gitweb.$key"};2944}elsif($typeeq'bool') {2945# backward compatibility: 'git config --bool' returns true/false2946return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2947}elsif($typeeq'int') {2948return config_to_int($config{"gitweb.$key"});2949}2950return$config{"gitweb.$key"};2951}29522953# get hash of given path at given ref2954sub git_get_hash_by_path {2955my$base=shift;2956my$path=shift||returnundef;2957my$type=shift;29582959$path=~ s,/+$,,;29602961open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2962or die_error(500,"Open git-ls-tree failed");2963my$line= <$fd>;2964close$fdorreturnundef;29652966if(!defined$line) {2967# there is no tree or hash given by $path at $base2968returnundef;2969}29702971#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2972$line=~m/^([0-9]+) (.+) ($oid_regex)\t/;2973if(defined$type&&$typene$2) {2974# type doesn't match2975returnundef;2976}2977return$3;2978}29792980# get path of entry with given hash at given tree-ish (ref)2981# used to get 'from' filename for combined diff (merge commit) for renames2982sub git_get_path_by_hash {2983my$base=shift||return;2984my$hash=shift||return;29852986local$/="\0";29872988open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2989orreturnundef;2990while(my$line= <$fd>) {2991chomp$line;29922993#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2994#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2995if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2996close$fd;2997return$1;2998}2999}3000close$fd;3001returnundef;3002}30033004## ......................................................................3005## git utility functions, directly accessing git repository30063007# get the value of config variable either from file named as the variable3008# itself in the repository ($GIT_DIR/$name file), or from gitweb.$name3009# configuration variable in the repository config file.3010sub git_get_file_or_project_config {3011my($path,$name) =@_;30123013$git_dir="$projectroot/$path";3014open my$fd,'<',"$git_dir/$name"3015orreturn git_get_project_config($name);3016my$conf= <$fd>;3017close$fd;3018if(defined$conf) {3019chomp$conf;3020}3021return$conf;3022}30233024sub git_get_project_description {3025my$path=shift;3026return git_get_file_or_project_config($path,'description');3027}30283029sub git_get_project_category {3030my$path=shift;3031return git_get_file_or_project_config($path,'category');3032}303330343035# supported formats:3036# * $GIT_DIR/ctags/<tagname> file (in 'ctags' subdirectory)3037# - if its contents is a number, use it as tag weight,3038# - otherwise add a tag with weight 13039# * $GIT_DIR/ctags file, each line is a tag (with weight 1)3040# the same value multiple times increases tag weight3041# * `gitweb.ctag' multi-valued repo config variable3042sub git_get_project_ctags {3043my$project=shift;3044my$ctags= {};30453046$git_dir="$projectroot/$project";3047if(opendir my$dh,"$git_dir/ctags") {3048my@files=grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh);3049foreachmy$tagfile(@files) {3050open my$ct,'<',$tagfile3051ornext;3052my$val= <$ct>;3053chomp$valif$val;3054close$ct;30553056(my$ctag=$tagfile) =~ s#.*/##;3057if($val=~/^\d+$/) {3058$ctags->{$ctag} =$val;3059}else{3060$ctags->{$ctag} =1;3061}3062}3063closedir$dh;30643065}elsif(open my$fh,'<',"$git_dir/ctags") {3066while(my$line= <$fh>) {3067chomp$line;3068$ctags->{$line}++if$line;3069}3070close$fh;30713072}else{3073my$taglist= config_to_multi(git_get_project_config('ctag'));3074foreachmy$tag(@$taglist) {3075$ctags->{$tag}++;3076}3077}30783079return$ctags;3080}30813082# return hash, where keys are content tags ('ctags'),3083# and values are sum of weights of given tag in every project3084sub git_gather_all_ctags {3085my$projects=shift;3086my$ctags= {};30873088foreachmy$p(@$projects) {3089foreachmy$ct(keys%{$p->{'ctags'}}) {3090$ctags->{$ct} +=$p->{'ctags'}->{$ct};3091}3092}30933094return$ctags;3095}30963097sub git_populate_project_tagcloud {3098my$ctags=shift;30993100# First, merge different-cased tags; tags vote on casing3101my%ctags_lc;3102foreach(keys%$ctags) {3103$ctags_lc{lc$_}->{count} +=$ctags->{$_};3104if(not$ctags_lc{lc$_}->{topcount}3105or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {3106$ctags_lc{lc$_}->{topcount} =$ctags->{$_};3107$ctags_lc{lc$_}->{topname} =$_;3108}3109}31103111my$cloud;3112my$matched=$input_params{'ctag'};3113if(eval{require HTML::TagCloud;1; }) {3114$cloud= HTML::TagCloud->new;3115foreachmy$ctag(sort keys%ctags_lc) {3116# Pad the title with spaces so that the cloud looks3117# less crammed.3118my$title= esc_html($ctags_lc{$ctag}->{topname});3119$title=~s/ / /g;3120$title=~s/^/ /g;3121$title=~s/$/ /g;3122if(defined$matched&&$matchedeq$ctag) {3123$title=qq(<span class="match">$title</span>);3124}3125$cloud->add($title, href(project=>undef, ctag=>$ctag),3126$ctags_lc{$ctag}->{count});3127}3128}else{3129$cloud= {};3130foreachmy$ctag(keys%ctags_lc) {3131my$title= esc_html($ctags_lc{$ctag}->{topname}, -nbsp=>1);3132if(defined$matched&&$matchedeq$ctag) {3133$title=qq(<span class="match">$title</span>);3134}3135$cloud->{$ctag}{count} =$ctags_lc{$ctag}->{count};3136$cloud->{$ctag}{ctag} =3137$cgi->a({-href=>href(project=>undef, ctag=>$ctag)},$title);3138}3139}3140return$cloud;3141}31423143sub git_show_project_tagcloud {3144my($cloud,$count) =@_;3145if(ref$cloudeq'HTML::TagCloud') {3146return$cloud->html_and_css($count);3147}else{3148my@tags=sort{$cloud->{$a}->{'count'} <=>$cloud->{$b}->{'count'} }keys%$cloud;3149return3150'<div id="htmltagcloud"'.($project?'':' align="center"').'>'.3151join(', ',map{3152$cloud->{$_}->{'ctag'}3153}splice(@tags,0,$count)) .3154'</div>';3155}3156}31573158sub git_get_project_url_list {3159my$path=shift;31603161$git_dir="$projectroot/$path";3162open my$fd,'<',"$git_dir/cloneurl"3163orreturnwantarray?3164@{ config_to_multi(git_get_project_config('url')) } :3165 config_to_multi(git_get_project_config('url'));3166my@git_project_url_list=map{chomp;$_} <$fd>;3167close$fd;31683169returnwantarray?@git_project_url_list: \@git_project_url_list;3170}31713172sub git_get_projects_list {3173my$filter=shift||'';3174my$paranoid=shift;3175my@list;31763177if(-d $projects_list) {3178# search in directory3179my$dir=$projects_list;3180# remove the trailing "/"3181$dir=~s!/+$!!;3182my$pfxlen=length("$dir");3183my$pfxdepth= ($dir=~tr!/!!);3184# when filtering, search only given subdirectory3185if($filter&& !$paranoid) {3186$dir.="/$filter";3187$dir=~s!/+$!!;3188}31893190 File::Find::find({3191 follow_fast =>1,# follow symbolic links3192 follow_skip =>2,# ignore duplicates3193 dangling_symlinks =>0,# ignore dangling symlinks, silently3194 wanted =>sub{3195# global variables3196our$project_maxdepth;3197our$projectroot;3198# skip project-list toplevel, if we get it.3199return if(m!^[/.]$!);3200# only directories can be git repositories3201return unless(-d $_);3202# need search permission3203return unless(-x $_);3204# don't traverse too deep (Find is super slow on os x)3205# $project_maxdepth excludes depth of $projectroot3206if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {3207$File::Find::prune =1;3208return;3209}32103211my$path=substr($File::Find::name,$pfxlen+1);3212# paranoidly only filter here3213if($paranoid&&$filter&&$path!~m!^\Q$filter\E/!) {3214next;3215}3216# we check related file in $projectroot3217if(check_export_ok("$projectroot/$path")) {3218push@list, { path =>$path};3219$File::Find::prune =1;3220}3221},3222},"$dir");32233224}elsif(-f $projects_list) {3225# read from file(url-encoded):3226# 'git%2Fgit.git Linus+Torvalds'3227# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'3228# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'3229open my$fd,'<',$projects_listorreturn;3230 PROJECT:3231while(my$line= <$fd>) {3232chomp$line;3233my($path,$owner) =split' ',$line;3234$path= unescape($path);3235$owner= unescape($owner);3236if(!defined$path) {3237next;3238}3239# if $filter is rpovided, check if $path begins with $filter3240if($filter&&$path!~m!^\Q$filter\E/!) {3241next;3242}3243if(check_export_ok("$projectroot/$path")) {3244my$pr= {3245 path =>$path3246};3247if($owner) {3248$pr->{'owner'} = to_utf8($owner);3249}3250push@list,$pr;3251}3252}3253close$fd;3254}3255return@list;3256}32573258# written with help of Tree::Trie module (Perl Artistic License, GPL compatible)3259# as side effects it sets 'forks' field to list of forks for forked projects3260sub filter_forks_from_projects_list {3261my$projects=shift;32623263my%trie;# prefix tree of directories (path components)3264# generate trie out of those directories that might contain forks3265foreachmy$pr(@$projects) {3266my$path=$pr->{'path'};3267$path=~s/\.git$//;# forks of 'repo.git' are in 'repo/' directory3268next if($path=~m!/$!);# skip non-bare repositories, e.g. 'repo/.git'3269next unless($path);# skip '.git' repository: tests, git-instaweb3270next unless(-d "$projectroot/$path");# containing directory exists3271$pr->{'forks'} = [];# there can be 0 or more forks of project32723273# add to trie3274my@dirs=split('/',$path);3275# walk the trie, until either runs out of components or out of trie3276my$ref= \%trie;3277while(scalar@dirs&&3278exists($ref->{$dirs[0]})) {3279$ref=$ref->{shift@dirs};3280}3281# create rest of trie structure from rest of components3282foreachmy$dir(@dirs) {3283$ref=$ref->{$dir} = {};3284}3285# create end marker, store $pr as a data3286$ref->{''} =$prif(!exists$ref->{''});3287}32883289# filter out forks, by finding shortest prefix match for paths3290my@filtered;3291 PROJECT:3292foreachmy$pr(@$projects) {3293# trie lookup3294my$ref= \%trie;3295 DIR:3296foreachmy$dir(split('/',$pr->{'path'})) {3297if(exists$ref->{''}) {3298# found [shortest] prefix, is a fork - skip it3299push@{$ref->{''}{'forks'}},$pr;3300next PROJECT;3301}3302if(!exists$ref->{$dir}) {3303# not in trie, cannot have prefix, not a fork3304push@filtered,$pr;3305next PROJECT;3306}3307# If the dir is there, we just walk one step down the trie.3308$ref=$ref->{$dir};3309}3310# we ran out of trie3311# (shouldn't happen: it's either no match, or end marker)3312push@filtered,$pr;3313}33143315return@filtered;3316}33173318# note: fill_project_list_info must be run first,3319# for 'descr_long' and 'ctags' to be filled3320sub search_projects_list {3321my($projlist,%opts) =@_;3322my$tagfilter=$opts{'tagfilter'};3323my$search_re=$opts{'search_regexp'};33243325return@$projlist3326unless($tagfilter||$search_re);33273328# searching projects require filling to be run before it;3329 fill_project_list_info($projlist,3330$tagfilter?'ctags': (),3331$search_re? ('path','descr') : ());3332my@projects;3333 PROJECT:3334foreachmy$pr(@$projlist) {33353336if($tagfilter) {3337next unlessref($pr->{'ctags'})eq'HASH';3338next unless3339grep{lc($_)eq lc($tagfilter) }keys%{$pr->{'ctags'}};3340}33413342if($search_re) {3343next unless3344$pr->{'path'} =~/$search_re/||3345$pr->{'descr_long'} =~/$search_re/;3346}33473348push@projects,$pr;3349}33503351return@projects;3352}33533354our$gitweb_project_owner=undef;3355sub git_get_project_list_from_file {33563357return if(defined$gitweb_project_owner);33583359$gitweb_project_owner= {};3360# read from file (url-encoded):3361# 'git%2Fgit.git Linus+Torvalds'3362# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'3363# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'3364if(-f $projects_list) {3365open(my$fd,'<',$projects_list);3366while(my$line= <$fd>) {3367chomp$line;3368my($pr,$ow) =split' ',$line;3369$pr= unescape($pr);3370$ow= unescape($ow);3371$gitweb_project_owner->{$pr} = to_utf8($ow);3372}3373close$fd;3374}3375}33763377sub git_get_project_owner {3378my$project=shift;3379my$owner;33803381returnundefunless$project;3382$git_dir="$projectroot/$project";33833384if(!defined$gitweb_project_owner) {3385 git_get_project_list_from_file();3386}33873388if(exists$gitweb_project_owner->{$project}) {3389$owner=$gitweb_project_owner->{$project};3390}3391if(!defined$owner){3392$owner= git_get_project_config('owner');3393}3394if(!defined$owner) {3395$owner= get_file_owner("$git_dir");3396}33973398return$owner;3399}34003401sub git_get_last_activity {3402my($path) =@_;3403my$fd;34043405$git_dir="$projectroot/$path";3406open($fd,"-|", git_cmd(),'for-each-ref',3407'--format=%(committer)',3408'--sort=-committerdate',3409'--count=1',3410map{"refs/$_"} get_branch_refs ())orreturn;3411my$most_recent= <$fd>;3412close$fdorreturn;3413if(defined$most_recent&&3414$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {3415my$timestamp=$1;3416my$age=time-$timestamp;3417return($age, age_string($age));3418}3419return(undef,undef);3420}34213422# Implementation note: when a single remote is wanted, we cannot use 'git3423# remote show -n' because that command always work (assuming it's a remote URL3424# if it's not defined), and we cannot use 'git remote show' because that would3425# try to make a network roundtrip. So the only way to find if that particular3426# remote is defined is to walk the list provided by 'git remote -v' and stop if3427# and when we find what we want.3428sub git_get_remotes_list {3429my$wanted=shift;3430my%remotes= ();34313432open my$fd,'-|', git_cmd(),'remote','-v';3433return unless$fd;3434while(my$remote= <$fd>) {3435chomp$remote;3436$remote=~s!\t(.*?)\s+\((\w+)\)$!!;3437next if$wantedand not$remoteeq$wanted;3438my($url,$key) = ($1,$2);34393440$remotes{$remote} ||= {'heads'=> () };3441$remotes{$remote}{$key} =$url;3442}3443close$fdorreturn;3444returnwantarray?%remotes: \%remotes;3445}34463447# Takes a hash of remotes as first parameter and fills it by adding the3448# available remote heads for each of the indicated remotes.3449sub fill_remote_heads {3450my$remotes=shift;3451my@heads=map{"remotes/$_"}keys%$remotes;3452my@remoteheads= git_get_heads_list(undef,@heads);3453foreachmy$remote(keys%$remotes) {3454$remotes->{$remote}{'heads'} = [grep{3455$_->{'name'} =~s!^$remote/!!3456}@remoteheads];3457}3458}34593460sub git_get_references {3461my$type=shift||"";3462my%refs;3463# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.113464# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}3465open my$fd,"-|", git_cmd(),"show-ref","--dereference",3466($type? ("--","refs/$type") : ())# use -- <pattern> if $type3467orreturn;34683469while(my$line= <$fd>) {3470chomp$line;3471if($line=~m!^($oid_regex)\srefs/($type.*)$!) {3472if(defined$refs{$1}) {3473push@{$refs{$1}},$2;3474}else{3475$refs{$1} = [$2];3476}3477}3478}3479close$fdorreturn;3480return \%refs;3481}34823483sub git_get_rev_name_tags {3484my$hash=shift||returnundef;34853486open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash3487orreturn;3488my$name_rev= <$fd>;3489close$fd;34903491if($name_rev=~ m|^$hash tags/(.*)$|) {3492return$1;3493}else{3494# catches also '$hash undefined' output3495returnundef;3496}3497}34983499## ----------------------------------------------------------------------3500## parse to hash functions35013502sub parse_date {3503my$epoch=shift;3504my$tz=shift||"-0000";35053506my%date;3507my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");3508my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");3509my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);3510$date{'hour'} =$hour;3511$date{'minute'} =$min;3512$date{'mday'} =$mday;3513$date{'day'} =$days[$wday];3514$date{'month'} =$months[$mon];3515$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",3516$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;3517$date{'mday-time'} =sprintf"%d%s%02d:%02d",3518$mday,$months[$mon],$hour,$min;3519$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",35201900+$year,1+$mon,$mday,$hour,$min,$sec;35213522my($tz_sign,$tz_hour,$tz_min) =3523($tz=~m/^([-+])(\d\d)(\d\d)$/);3524$tz_sign= ($tz_signeq'-'? -1: +1);3525my$local=$epoch+$tz_sign*((($tz_hour*60) +$tz_min)*60);3526($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);3527$date{'hour_local'} =$hour;3528$date{'minute_local'} =$min;3529$date{'tz_local'} =$tz;3530$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",35311900+$year,$mon+1,$mday,3532$hour,$min,$sec,$tz);3533return%date;3534}35353536sub parse_tag {3537my$tag_id=shift;3538my%tag;3539my@comment;35403541open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;3542$tag{'id'} =$tag_id;3543while(my$line= <$fd>) {3544chomp$line;3545if($line=~m/^object ($oid_regex)$/) {3546$tag{'object'} =$1;3547}elsif($line=~m/^type (.+)$/) {3548$tag{'type'} =$1;3549}elsif($line=~m/^tag (.+)$/) {3550$tag{'name'} =$1;3551}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {3552$tag{'author'} =$1;3553$tag{'author_epoch'} =$2;3554$tag{'author_tz'} =$3;3555if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {3556$tag{'author_name'} =$1;3557$tag{'author_email'} =$2;3558}else{3559$tag{'author_name'} =$tag{'author'};3560}3561}elsif($line=~m/--BEGIN/) {3562push@comment,$line;3563last;3564}elsif($lineeq"") {3565last;3566}3567}3568push@comment, <$fd>;3569$tag{'comment'} = \@comment;3570close$fdorreturn;3571if(!defined$tag{'name'}) {3572return3573};3574return%tag3575}35763577sub parse_commit_text {3578my($commit_text,$withparents) =@_;3579my@commit_lines=split'\n',$commit_text;3580my%co;35813582pop@commit_lines;# Remove '\0'35833584if(!@commit_lines) {3585return;3586}35873588my$header=shift@commit_lines;3589if($header!~m/^$oid_regex/) {3590return;3591}3592($co{'id'},my@parents) =split' ',$header;3593while(my$line=shift@commit_lines) {3594last if$lineeq"\n";3595if($line=~m/^tree ($oid_regex)$/) {3596$co{'tree'} =$1;3597}elsif((!defined$withparents) && ($line=~m/^parent ($oid_regex)$/)) {3598push@parents,$1;3599}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {3600$co{'author'} = to_utf8($1);3601$co{'author_epoch'} =$2;3602$co{'author_tz'} =$3;3603if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {3604$co{'author_name'} =$1;3605$co{'author_email'} =$2;3606}else{3607$co{'author_name'} =$co{'author'};3608}3609}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {3610$co{'committer'} = to_utf8($1);3611$co{'committer_epoch'} =$2;3612$co{'committer_tz'} =$3;3613if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {3614$co{'committer_name'} =$1;3615$co{'committer_email'} =$2;3616}else{3617$co{'committer_name'} =$co{'committer'};3618}3619}3620}3621if(!defined$co{'tree'}) {3622return;3623};3624$co{'parents'} = \@parents;3625$co{'parent'} =$parents[0];36263627foreachmy$title(@commit_lines) {3628$title=~s/^ //;3629if($titlene"") {3630$co{'title'} =$title;3631# remove leading stuff of merges to make the interesting part visible3632if(length($title) >50) {3633$title=~s/^Automatic //;3634$title=~s/^merge (of|with) /Merge ... /i;3635if(length($title) >50) {3636$title=~s/(http|rsync):\/\///;3637}3638if(length($title) >50) {3639$title=~s/(master|www|rsync)\.//;3640}3641if(length($title) >50) {3642$title=~s/kernel.org:?//;3643}3644if(length($title) >50) {3645$title=~s/\/pub\/scm//;3646}3647}3648$co{'title_short'} = chop_str($title,50,5);3649last;3650}3651}3652if(!defined$co{'title'} ||$co{'title'}eq"") {3653$co{'title'} =$co{'title_short'} ='(no commit message)';3654}3655# remove added spaces3656foreachmy$line(@commit_lines) {3657$line=~s/\s\s+//;3658$line=~s/\n+$//;3659}3660$co{'comment'} = \@commit_lines;36613662my$age=time-$co{'committer_epoch'};3663$co{'age'} =$age;3664$co{'age_string'} = age_string($age);3665my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});3666if($age>60*60*24*7*2) {3667$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;3668$co{'age_string_age'} =$co{'age_string'};3669}else{3670$co{'age_string_date'} =$co{'age_string'};3671$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;3672}3673return%co;3674}36753676sub parse_commit {3677my($commit_id) =@_;3678my%co;36793680local$/="\0";36813682open my$fd,"-|", git_cmd(),"rev-list",3683"--parents",3684"--header",3685"--max-count=1",3686$commit_id,3687"--",3688or die_error(500,"Open git-rev-list failed");3689%co= parse_commit_text(<$fd>,1);3690close$fd;36913692return%co;3693}36943695sub parse_commits {3696my($commit_id,$maxcount,$skip,$filename,@args) =@_;3697my@cos;36983699$maxcount||=1;3700$skip||=0;37013702local$/="\0";37033704open my$fd,"-|", git_cmd(),"rev-list",3705"--header",3706@args,3707("--max-count=".$maxcount),3708("--skip=".$skip),3709@extra_options,3710$commit_id,3711"--",3712($filename? ($filename) : ())3713or die_error(500,"Open git-rev-list failed");3714while(my$line= <$fd>) {3715my%co= parse_commit_text($line);3716push@cos, \%co;3717}3718close$fd;37193720returnwantarray?@cos: \@cos;3721}37223723# parse line of git-diff-tree "raw" output3724sub parse_difftree_raw_line {3725my$line=shift;3726my%res;37273728# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'3729# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'3730if($line=~m/^:([0-7]{6}) ([0-7]{6}) ($oid_regex) ($oid_regex) (.)([0-9]{0,3})\t(.*)$/) {3731$res{'from_mode'} =$1;3732$res{'to_mode'} =$2;3733$res{'from_id'} =$3;3734$res{'to_id'} =$4;3735$res{'status'} =$5;3736$res{'similarity'} =$6;3737if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied3738($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);3739}else{3740$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);3741}3742}3743# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'3744# combined diff (for merge commit)3745elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:$oid_regex )+)([a-zA-Z]+)\t(.*)$//) {3746$res{'nparents'} =length($1);3747$res{'from_mode'} = [split(' ',$2) ];3748$res{'to_mode'} =pop@{$res{'from_mode'}};3749$res{'from_id'} = [split(' ',$3) ];3750$res{'to_id'} =pop@{$res{'from_id'}};3751$res{'status'} = [split('',$4) ];3752$res{'to_file'} = unquote($5);3753}3754# 'c512b523472485aef4fff9e57b229d9d243c967f'3755elsif($line=~m/^($oid_regex)$/) {3756$res{'commit'} =$1;3757}37583759returnwantarray?%res: \%res;3760}37613762# wrapper: return parsed line of git-diff-tree "raw" output3763# (the argument might be raw line, or parsed info)3764sub parsed_difftree_line {3765my$line_or_ref=shift;37663767if(ref($line_or_ref)eq"HASH") {3768# pre-parsed (or generated by hand)3769return$line_or_ref;3770}else{3771return parse_difftree_raw_line($line_or_ref);3772}3773}37743775# parse line of git-ls-tree output3776sub parse_ls_tree_line {3777my$line=shift;3778my%opts=@_;3779my%res;37803781if($opts{'-l'}) {3782#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'3783$line=~m/^([0-9]+) (.+) ($oid_regex) +(-|[0-9]+)\t(.+)$/s;37843785$res{'mode'} =$1;3786$res{'type'} =$2;3787$res{'hash'} =$3;3788$res{'size'} =$4;3789if($opts{'-z'}) {3790$res{'name'} =$5;3791}else{3792$res{'name'} = unquote($5);3793}3794}else{3795#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'3796$line=~m/^([0-9]+) (.+) ($oid_regex)\t(.+)$/s;37973798$res{'mode'} =$1;3799$res{'type'} =$2;3800$res{'hash'} =$3;3801if($opts{'-z'}) {3802$res{'name'} =$4;3803}else{3804$res{'name'} = unquote($4);3805}3806}38073808returnwantarray?%res: \%res;3809}38103811# generates _two_ hashes, references to which are passed as 2 and 3 argument3812sub parse_from_to_diffinfo {3813my($diffinfo,$from,$to,@parents) =@_;38143815if($diffinfo->{'nparents'}) {3816# combined diff3817$from->{'file'} = [];3818$from->{'href'} = [];3819 fill_from_file_info($diffinfo,@parents)3820unlessexists$diffinfo->{'from_file'};3821for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {3822$from->{'file'}[$i] =3823defined$diffinfo->{'from_file'}[$i] ?3824$diffinfo->{'from_file'}[$i] :3825$diffinfo->{'to_file'};3826if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file3827$from->{'href'}[$i] = href(action=>"blob",3828 hash_base=>$parents[$i],3829 hash=>$diffinfo->{'from_id'}[$i],3830 file_name=>$from->{'file'}[$i]);3831}else{3832$from->{'href'}[$i] =undef;3833}3834}3835}else{3836# ordinary (not combined) diff3837$from->{'file'} =$diffinfo->{'from_file'};3838if($diffinfo->{'status'}ne"A") {# not new (added) file3839$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,3840 hash=>$diffinfo->{'from_id'},3841 file_name=>$from->{'file'});3842}else{3843delete$from->{'href'};3844}3845}38463847$to->{'file'} =$diffinfo->{'to_file'};3848if(!is_deleted($diffinfo)) {# file exists in result3849$to->{'href'} = href(action=>"blob", hash_base=>$hash,3850 hash=>$diffinfo->{'to_id'},3851 file_name=>$to->{'file'});3852}else{3853delete$to->{'href'};3854}3855}38563857## ......................................................................3858## parse to array of hashes functions38593860sub git_get_heads_list {3861my($limit,@classes) =@_;3862@classes= get_branch_refs()unless@classes;3863my@patterns=map{"refs/$_"}@classes;3864my@headslist;38653866open my$fd,'-|', git_cmd(),'for-each-ref',3867($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',3868'--format=%(objectname) %(refname) %(subject)%00%(committer)',3869@patterns3870orreturn;3871while(my$line= <$fd>) {3872my%ref_item;38733874chomp$line;3875my($refinfo,$committerinfo) =split(/\0/,$line);3876my($hash,$name,$title) =split(' ',$refinfo,3);3877my($committer,$epoch,$tz) =3878($committerinfo=~/^(.*) ([0-9]+) (.*)$/);3879$ref_item{'fullname'} =$name;3880my$strip_refs=join'|',map{quotemeta} get_branch_refs();3881$name=~s!^refs/($strip_refs|remotes)/!!;3882$ref_item{'name'} =$name;3883# for refs neither in 'heads' nor 'remotes' we want to3884# show their ref dir3885my$ref_dir= (defined$1) ?$1:'';3886if($ref_dirne''and$ref_dirne'heads'and$ref_dirne'remotes') {3887$ref_item{'name'} .=' ('.$ref_dir.')';3888}38893890$ref_item{'id'} =$hash;3891$ref_item{'title'} =$title||'(no commit message)';3892$ref_item{'epoch'} =$epoch;3893if($epoch) {3894$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3895}else{3896$ref_item{'age'} ="unknown";3897}38983899push@headslist, \%ref_item;3900}3901close$fd;39023903returnwantarray?@headslist: \@headslist;3904}39053906sub git_get_tags_list {3907my$limit=shift;3908my@tagslist;39093910open my$fd,'-|', git_cmd(),'for-each-ref',3911($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',3912'--format=%(objectname) %(objecttype) %(refname) '.3913'%(*objectname) %(*objecttype) %(subject)%00%(creator)',3914'refs/tags'3915orreturn;3916while(my$line= <$fd>) {3917my%ref_item;39183919chomp$line;3920my($refinfo,$creatorinfo) =split(/\0/,$line);3921my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);3922my($creator,$epoch,$tz) =3923($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);3924$ref_item{'fullname'} =$name;3925$name=~s!^refs/tags/!!;39263927$ref_item{'type'} =$type;3928$ref_item{'id'} =$id;3929$ref_item{'name'} =$name;3930if($typeeq"tag") {3931$ref_item{'subject'} =$title;3932$ref_item{'reftype'} =$reftype;3933$ref_item{'refid'} =$refid;3934}else{3935$ref_item{'reftype'} =$type;3936$ref_item{'refid'} =$id;3937}39383939if($typeeq"tag"||$typeeq"commit") {3940$ref_item{'epoch'} =$epoch;3941if($epoch) {3942$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3943}else{3944$ref_item{'age'} ="unknown";3945}3946}39473948push@tagslist, \%ref_item;3949}3950close$fd;39513952returnwantarray?@tagslist: \@tagslist;3953}39543955## ----------------------------------------------------------------------3956## filesystem-related functions39573958sub get_file_owner {3959my$path=shift;39603961my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);3962my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);3963if(!defined$gcos) {3964returnundef;3965}3966my$owner=$gcos;3967$owner=~s/[,;].*$//;3968return to_utf8($owner);3969}39703971# assume that file exists3972sub insert_file {3973my$filename=shift;39743975open my$fd,'<',$filename;3976print map{ to_utf8($_) } <$fd>;3977close$fd;3978}39793980# Check if a file should be displayed3981sub check_tree_filter {3982my$filename=shift;3983my@treefilter_pattern= gitweb_get_feature('tree_filter');3984return$filename=~/$treefilter_pattern[0]/;3985}39863987## ......................................................................3988## mimetype related functions39893990sub mimetype_guess_file {3991my$filename=shift;3992my$mimemap=shift;3993-r $mimemaporreturnundef;39943995my%mimemap;3996open(my$mh,'<',$mimemap)orreturnundef;3997while(<$mh>) {3998next ifm/^#/;# skip comments3999my($mimetype,@exts) =split(/\s+/);4000foreachmy$ext(@exts) {4001$mimemap{$ext} =$mimetype;4002}4003}4004close($mh);40054006$filename=~/\.([^.]*)$/;4007return$mimemap{$1};4008}40094010sub mimetype_guess {4011my$filename=shift;4012my$mime;4013$filename=~/\./orreturnundef;40144015if($mimetypes_file) {4016my$file=$mimetypes_file;4017if($file!~m!^/!) {# if it is relative path4018# it is relative to project4019$file="$projectroot/$project/$file";4020}4021$mime= mimetype_guess_file($filename,$file);4022}4023$mime||= mimetype_guess_file($filename,'/etc/mime.types');4024return$mime;4025}40264027sub blob_mimetype {4028my$fd=shift;4029my$filename=shift;40304031if($filename) {4032my$mime= mimetype_guess($filename);4033$mimeandreturn$mime;4034}40354036# just in case4037return$default_blob_plain_mimetypeunless$fd;40384039if(-T $fd) {4040return'text/plain';4041}elsif(!$filename) {4042return'application/octet-stream';4043}elsif($filename=~m/\.png$/i) {4044return'image/png';4045}elsif($filename=~m/\.gif$/i) {4046return'image/gif';4047}elsif($filename=~m/\.jpe?g$/i) {4048return'image/jpeg';4049}else{4050return'application/octet-stream';4051}4052}40534054sub blob_contenttype {4055my($fd,$file_name,$type) =@_;40564057$type||= blob_mimetype($fd,$file_name);4058if($typeeq'text/plain'&&defined$default_text_plain_charset) {4059$type.="; charset=$default_text_plain_charset";4060}40614062return$type;4063}40644065# guess file syntax for syntax highlighting; return undef if no highlighting4066# the name of syntax can (in the future) depend on syntax highlighter used4067sub guess_file_syntax {4068my($highlight,$file_name) =@_;4069returnundefunless($highlight&&defined$file_name);4070my$basename= basename($file_name,'.in');4071return$highlight_basename{$basename}4072ifexists$highlight_basename{$basename};40734074$basename=~/\.([^.]*)$/;4075my$ext=$1orreturnundef;4076return$highlight_ext{$ext}4077ifexists$highlight_ext{$ext};40784079returnundef;4080}40814082# run highlighter and return FD of its output,4083# or return original FD if no highlighting4084sub run_highlighter {4085my($fd,$highlight,$syntax) =@_;4086return$fdunless($highlight);40874088close$fd;4089my$syntax_arg= (defined$syntax) ?"--syntax$syntax":"--force";4090open$fd, quote_command(git_cmd(),"cat-file","blob",$hash)." | ".4091 quote_command($^X,'-CO','-MEncode=decode,FB_DEFAULT','-pse',4092'$_= decode($fe,$_, FB_DEFAULT) if !utf8::decode($_);',4093'--',"-fe=$fallback_encoding")." | ".4094 quote_command($highlight_bin).4095" --replace-tabs=8 --fragment$syntax_arg|"4096or die_error(500,"Couldn't open file or run syntax highlighter");4097return$fd;4098}40994100## ======================================================================4101## functions printing HTML: header, footer, error page41024103sub get_page_title {4104my$title= to_utf8($site_name);41054106unless(defined$project) {4107if(defined$project_filter) {4108$title.=" - projects in '". esc_path($project_filter) ."'";4109}4110return$title;4111}4112$title.=" - ". to_utf8($project);41134114return$titleunless(defined$action);4115$title.="/$action";# $action is US-ASCII (7bit ASCII)41164117return$titleunless(defined$file_name);4118$title.=" - ". esc_path($file_name);4119if($actioneq"tree"&&$file_name!~ m|/$|) {4120$title.="/";4121}41224123return$title;4124}41254126sub get_content_type_html {4127# require explicit support from the UA if we are to send the page as4128# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.4129# we have to do this because MSIE sometimes globs '*/*', pretending to4130# support xhtml+xml but choking when it gets what it asked for.4131if(defined$cgi->http('HTTP_ACCEPT') &&4132$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&4133$cgi->Accept('application/xhtml+xml') !=0) {4134return'application/xhtml+xml';4135}else{4136return'text/html';4137}4138}41394140sub print_feed_meta {4141if(defined$project) {4142my%href_params= get_feed_info();4143if(!exists$href_params{'-title'}) {4144$href_params{'-title'} ='log';4145}41464147foreachmy$format(qw("RSS Atom")) {4148if(gitweb_check_feature($format)) {4149 print_feed_links($format,%href_params);4150}4151}41524153}else{4154printf('<link rel="alternate" title="%sprojects list" '.4155'href="%s" type="text/plain; charset=utf-8" />'."\n",4156 esc_attr($site_name), href(project=>undef, action=>"project_index"));4157printf('<link rel="alternate" title="%sprojects feeds" '.4158'href="%s" type="text/x-opml" />'."\n",4159 esc_attr($site_name), href(project=>undef, action=>"opml"));4160}4161}41624163sub print_feed_links {41644165my($format,%href_params) =@_;41664167my$type=lc($format);4168my%link_attr= (4169'-rel'=>'alternate',4170'-title'=> esc_attr("$project-$href_params{'-title'} -$formatfeed"),4171'-type'=>"application/$type+xml"4172);41734174$href_params{'extra_options'} =undef;4175$href_params{'action'} =$type;4176$link_attr{'-href'} = href(%href_params);4177print"<link ".4178"rel=\"$link_attr{'-rel'}\"".4179"title=\"$link_attr{'-title'}\"".4180"href=\"$link_attr{'-href'}\"".4181"type=\"$link_attr{'-type'}\"".4182"/>\n";41834184$href_params{'extra_options'} ='--no-merges';4185$link_attr{'-href'} = href(%href_params);4186$link_attr{'-title'} .=' (no merges)';4187print"<link ".4188"rel=\"$link_attr{'-rel'}\"".4189"title=\"$link_attr{'-title'}\"".4190"href=\"$link_attr{'-href'}\"".4191"type=\"$link_attr{'-type'}\"".4192"/>\n";41934194}41954196sub print_header_links {4197my$status=shift;41984199# print out each stylesheet that exist, providing backwards capability4200# for those people who defined $stylesheet in a config file4201if(defined$stylesheet) {4202print'<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";4203}else{4204foreachmy$stylesheet(@stylesheets) {4205next unless$stylesheet;4206print'<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";4207}4208}4209 print_feed_meta()4210if($statuseq'200 OK');4211if(defined$favicon) {4212printqq(<link rel="shortcut icon" href=").esc_url($favicon).qq(" type="image/png" />\n);4213}4214}42154216sub print_nav_breadcrumbs_path {4217my$dirprefix=undef;4218while(my$part=shift) {4219$dirprefix.="/"ifdefined$dirprefix;4220$dirprefix.=$part;4221print$cgi->a({-href => href(project =>undef,4222 project_filter =>$dirprefix,4223 action =>"project_list")},4224 esc_html($part)) ." / ";4225}4226}42274228sub print_nav_breadcrumbs {4229my%opts=@_;42304231# Modified by Andrew Lorimer, October 20194232# Do not show trailing slash in breadcrumb for last item4233#my @crumbs = (@extra_breadcrumbs, [ $home_link_str => $home_link ]);4234#for my $i (0 .. (length @crumbs - 1)) {4235# print $cgi->a({-href => esc_url($crumbs[$i]->[1])}, $crumbs[$i]->[0]);4236# if ($i != $#crumbs) {4237# print " / ";4238# }4239#}4240my@base_links= ();4241formy$crumb(@extra_breadcrumbs, [$home_link_str=>$home_link]) {4242if(defined$crumb&&length$crumb&&$crumbne"") {4243push(@base_links,$cgi->a({-href => esc_url($crumb->[1])},$crumb->[0]));4244}4245}4246print join(" / ",@base_links);4247if(defined$project) {4248print" / ";4249my@dirname=split'/',$project;4250my$projectbasename=pop@dirname;4251 print_nav_breadcrumbs_path(@dirname);4252print$cgi->a({-href => href(action=>"summary")}, esc_html($projectbasename));4253if(defined$action&&$actionne"summary") {4254$action=~s/_/ /;4255if($actioneq"blob") {4256$action=$file_name;4257}4258my$action_print=$action;4259if(defined$opts{-action_extra}) {4260$action_print=$cgi->a({-href => href(action=>$action)},4261$action);4262}4263print" /$action_print";4264}4265if(defined$opts{-action_extra}) {4266print" /$opts{-action_extra}";4267}4268print"\n";4269}elsif(defined$project_filter) {4270 print_nav_breadcrumbs_path(split'/',$project_filter);4271}4272}42734274sub print_search_form {4275if(!defined$searchtext) {4276$searchtext="";4277}4278my$search_hash;4279if(defined$hash_base) {4280$search_hash=$hash_base;4281}elsif(defined$hash) {4282$search_hash=$hash;4283}else{4284$search_hash="HEAD";4285}4286my$action=$my_uri;4287my$use_pathinfo= gitweb_check_feature('pathinfo');4288if($use_pathinfo) {4289$action.="/".esc_url($project);4290}4291print"<div class=\"search\">";4292print$cgi->start_form(-method=>"get", -action =>$action) .4293(!$use_pathinfo&&4294$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .4295$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".4296$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".4297$cgi->popup_menu(-name =>'st', -default=>'commit',4298-values=> ['commit','grep','author','committer','pickaxe']) .4299" ".$cgi->a({-href => href(action=>"search_help"),4300-title =>"search help"},"?"),4301$cgi->textfield(-name =>"s", -value =>$searchtext, -override =>1, -placeholder =>"search ".$project) ."\n".4302"<span title=\"Extended regular expression\">".4303$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',4304-checked =>$search_use_regexp) .4305"</span>".4306$cgi->end_form() ."\n";4307print"</div>";4308}43094310sub git_header_html {4311my$status=shift||"200 OK";4312my$expires=shift;4313my%opts=@_;43144315my$title= get_page_title();4316my$content_type= get_content_type_html();4317print$cgi->header(-type=>$content_type, -charset =>'utf-8',4318-status=>$status, -expires =>$expires)4319unless($opts{'-no_http_header'});4320my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';4321print<<EOF;4322<?xml version="1.0" encoding="utf-8"?>4323<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">4324<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">4325<!-- gitweb$version, originally (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->4326<!-- modified by Andrew Lorimer, 2019 (see <https://git.lorimer.id.au>) -->4327<!-- git core binaries version$git_version-->4328<head>4329<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>4330<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>4331<meta name="robots" content="index, nofollow"/>4332<meta name="viewport" content="width=device-width, initial-scale=1" />4333<title>$title</title>4334EOF4335# the stylesheet, favicon etc urls won't work correctly with path_info4336# unless we set the appropriate base URL4337if($ENV{'PATH_INFO'}) {4338print"<base href=\"".esc_url($base_url)."\"/>\n";4339}4340 print_header_links($status);43414342if(defined$site_html_head_string) {4343print to_utf8($site_html_head_string);4344}43454346print"</head>\n".4347'<body>4348 <svg>4349 <symbol width="14" height="14" viewBox="0 0 384 512" id="reficon" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="code-branch" class="svg-inline--fa fa-code-branch fa-w-12" role="img" xmlns="http://www.w3.org/2000/svg">4350 <path fill="currentColor" d="M384 144c0-44.2-35.8-80-80-80s-80 35.8-80 80c0 36.4 24.3 67.1 57.5 76.8-.6 16.1-4.2 28.5-11 36.9-15.4 19.2-49.3 22.4-85.2 25.7-28.2 2.6-57.4 5.4-81.3 16.9v-144c32.5-10.2 56-40.5 56-76.3 0-44.2-35.8-80-80-80S0 35.8 0 80c0 35.8 23.5 66.1 56 76.3v199.3C23.5 365.9 0 396.2 0 432c0 44.2 35.8 80 80 80s80-35.8 80-80c0-34-21.2-63.1-51.2-74.6 3.1-5.2 7.8-9.8 14.9-13.4 16.2-8.2 40.4-10.4 66.1-12.8 42.2-3.9 90-8.4 118.2-43.4 14-17.4 21.1-39.8 21.6-67.9 31.6-10.8 54.4-40.7 54.4-75.9zM80 64c8.8 0 16 7.2 16 16s-7.2 16-16 16-16-7.2-16-16 7.2-16 16-16zm0 384c-8.8 0-16-7.2-16-16s7.2-16 16-16 16 7.2 16 16-7.2 16-16 16zm224-320c8.8 0 16 7.2 16 16s-7.2 16-16 16-16-7.2-16-16 7.2-16 16-16z"></path>4351 </symbol>4352 <symbol width="14" height="14" viewBox="0 0 448 512" id="copyicon" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="copy" class="svg-inline--fa fa-copy fa-w-12" role="img" xmlns="http://www.w3.org/2000/svg">4353 <path d="M320 448v40c0 13.255-10.745 24-24 24H24c-13.255 0-24-10.745-24-24V120c0-13.255 10.745-24 24-24h72v296c0 30.879 25.121 56 56 56h168zm0-344V0H152c-13.255 0-24 10.745-24 24v368c0 13.255 10.745 24 24 24h272c13.255 0 24-10.745 24-24V128H344c-13.2 0-24-10.8-24-24zm120.971-31.029L375.029 7.029A24 24 0 0 0 358.059 0H352v96h96v-6.059a24 24 0 0 0-7.029-16.97z"></path>4354 </symbol>4355 <symbol width="14" height="14" viewBox="0 0 512 512" id="foldericon" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="folder" class="svg-inline--fa fa-folder fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg">4356 <path d="M464 128H272l-64-64H48C21.49 64 0 85.49 0 112v288c0 26.51 21.49 48 48 48h416c26.51 0 48-21.49 48-48V176c0-26.51-21.49-48-48-48z"></path>4357 </symbol>4358 <symbol width="14" height="14" viewBox="0 0 512 512" id="tagicon" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="tag" class="svg-inline--fa fa-tag fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg">4359 <path d="M0 252.118V48C0 21.49 21.49 0 48 0h204.118a48 48 0 0 1 33.941 14.059l211.882 211.882c18.745 18.745 18.745 49.137 0 67.882L293.823 497.941c-18.745 18.745-49.137 18.745-67.882 0L14.059 286.059A48 48 0 0 1 0 252.118zM112 64c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48z"></path>4360 </symbol>4361 <symbol width="14" height="14" viewBox="0 0 320 512" id="parenticon" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="level-up-alt" class="svg-inline--fa fa-level-up-alt fa-w-10" role="img" xmlns="http://www.w3.org/2000/svg">4362 <path d="M313.553 119.669L209.587 7.666c-9.485-10.214-25.676-10.229-35.174 0L70.438 119.669C56.232 134.969 67.062 160 88.025 160H152v272H68.024a11.996 11.996 0 0 0-8.485 3.515l-56 56C-4.021 499.074 1.333 512 12.024 512H208c13.255 0 24-10.745 24-24V160h63.966c20.878 0 31.851-24.969 17.587-40.331z"></path>4363 </symbol>4364 </svg>4365 ';43664367if(defined$site_header&& -f $site_header) {4368 insert_file($site_header);4369}43704371print"<div class=\"breadcrumb\">\n";43724373# Modified by Andrew Lorimer, October 20194374# Do not print logo if the image source is empty4375if(defined$logo&&$logone"") {4376print$cgi->a({-href => esc_url($logo_url),4377-title =>$logo_label},4378$cgi->img({-src => esc_url($logo),4379-width =>72, -height =>27,4380-alt =>"git",4381-class=>"logo"}));4382}4383 print_nav_breadcrumbs(%opts);4384print"</div>\n";4385}43864387sub git_footer_html {4388my$feed_class='rss_logo';43894390print"<footer>\n";4391if(defined$project) {4392my%href_params= get_feed_info();4393if(!%href_params) {4394$feed_class.=' generic';4395}4396$href_params{'-title'} ||='log';43974398if(gitweb_check_feature("rss")) {4399$href_params{'action'} ="rss";4400print$cgi->a({-href => href(%href_params),4401-title =>"$href_params{'-title'} RSS feed",4402-class=>$feed_class},"RSS")."\n";4403}4404if(gitweb_check_feature("atom")) {4405$href_params{'action'} ="atom";4406print$cgi->a({-href => href(%href_params),4407-title =>"$href_params{'-title'} Atom feed",4408-class=>$feed_class},"Atom")."\n";4409}44104411}else{4412if($opml) {4413print$cgi->a({-href => href(project=>undef, action=>"opml",4414 project_filter =>$project_filter),4415-class=>$feed_class},"OPML") ." ";4416}4417if($txt) {4418print$cgi->a({-href => href(project=>undef, action=>"project_index",4419 project_filter =>$project_filter),4420-class=>$feed_class},"TXT") ."\n";4421}4422}4423if(defined$t0&& gitweb_check_feature('timed')) {4424print"<div id=\"generating_info\">\n";4425print'This page took '.4426'<span id="generating_time" class="time_span">'.4427 tv_interval($t0, [ gettimeofday() ]).4428' s</span>'.4429' and '.4430'<span id="generating_cmd">'.4431$number_of_git_cmds.4432' git commands </span>'.4433" to generate.\n";4434print"</div>\n";# class="page_footer"4435}44364437if(defined$site_footer&& -f $site_footer) {4438 insert_file($site_footer);4439}4440print"</footer>\n";444144424443print qq!<script type="text/javascript" src="!.esc_url($javascript).qq!"></script>\n!;4444if(defined$action&&4445$actioneq'blame_incremental') {4446print qq!<script type="text/javascript">\n!.4447 qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.4448 qq!"!. href() .qq!");\n!.4449 qq!</script>\n!;4450}else{4451my($jstimezone,$tz_cookie,$datetime_class) =4452 gitweb_get_feature('javascript-timezone');44534454print qq!<script type="text/javascript">\n!.4455 qq!window.onload = function () {\n!;4456if(gitweb_check_feature('javascript-actions')) {4457print qq! fixLinks();\n!;4458}4459if($jstimezone&&$tz_cookie&&$datetime_class) {4460print qq! var tz_cookie = { name:'$tz_cookie', expires:14, path:'/'};\n!.# in days4461 qq! onloadTZSetup('$jstimezone', tz_cookie,'$datetime_class');\n!;4462}4463print qq!};\n!.4464 qq!</script>\n!;4465}44664467print"</body>\n".4468"</html>";4469}44704471# die_error(<http_status_code>, <error_message>[, <detailed_html_description>])4472# Example: die_error(404, 'Hash not found')4473# By convention, use the following status codes (as defined in RFC 2616):4474# 400: Invalid or missing CGI parameters, or4475# requested object exists but has wrong type.4476# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on4477# this server or project.4478# 404: Requested object/revision/project doesn't exist.4479# 500: The server isn't configured properly, or4480# an internal error occurred (e.g. failed assertions caused by bugs), or4481# an unknown error occurred (e.g. the git binary died unexpectedly).4482# 503: The server is currently unavailable (because it is overloaded,4483# or down for maintenance). Generally, this is a temporary state.4484sub die_error {4485my$status=shift||500;4486my$error= esc_html(shift) ||"Internal Server Error";4487my$extra=shift;4488my%opts=@_;44894490my%http_responses= (4491400=>'400 Bad Request',4492403=>'403 Forbidden',4493404=>'404 Not Found',4494500=>'500 Internal Server Error',4495503=>'503 Service Unavailable',4496);4497 git_header_html($http_responses{$status},undef,%opts);44984499print<<EOF;4500<br /><br />4501<h1 id="error-code" class="$status">$status</h1>4502<p id="error-msg" class="$status">$error</p>4503<p id="error-link" class="$status"><a href="$base_url">go home</a></p>4504EOF4505if(defined$extra) {4506print"<hr />\n".4507"$extra\n";4508}45094510 git_footer_html();4511die"$status-$error"4512unless($opts{'-error_handler'});4513}45144515## ----------------------------------------------------------------------4516## functions printing or outputting HTML: navigation45174518sub git_print_page_nav {4519my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;4520$extra=''if!defined$extra;# pager or formats45214522# Check if shortlog should be added to breadcrumb4523# Added by Andrew Lorimer, November 20194524my@navs=qw(summary log commit diff tree);4525if(gitweb_check_feature("shortlog")) {4526@navs=qw(summary shortlog log commit diff tree);4527}4528if($suppress) {4529@navs=grep{$_ne$suppress}@navs;4530}45314532my%arg=map{$_=> {action=>$_} }@navs;4533if(defined$head) {4534for(qw(commit diff)) {4535$arg{$_}{'hash'} =$head;4536}4537if($current=~m/^(tree | log | shortlog | commit | diff | search)$/x) {4538for(qw(shortlog log)) {4539$arg{$_}{'hash'} =$head;4540}4541}4542}45434544$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;4545$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;45464547my@actions= gitweb_get_feature('actions');4548my%repl= (4549'%'=>'%',4550'n'=>$project,# project name4551'f'=>$git_dir,# project path within filesystem4552'h'=>$treehead||'',# current hash ('h' parameter)4553'b'=>$treebase||'',# hash base ('hb' parameter)4554);4555while(@actions) {4556my($label,$link,$pos) =splice(@actions,0,3);4557# insert4558@navs=map{$_eq$pos? ($_,$label) :$_}@navs;4559# munch munch4560$link=~s/%([%nfhb])/$repl{$1}/g;4561$arg{$label}{'_href'} =$link;4562}45634564print"<header>";4565print"<nav>\n".4566(join" | ",4567map{$_eq$current?4568$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")4569}@navs);4570print"<br/>\n$extra<br/>\n"if($extra);4571print"</nav>\n";45724573my$have_search= gitweb_check_feature('search');4574if(defined$project&&$have_search) {4575 print_search_form();4576}4577print"</header>";4578}45794580# returns a submenu for the navigation of the refs views (tags, heads,4581# remotes) with the current view disabled and the remotes view only4582# available if the feature is enabled4583sub format_ref_views {4584my($current) =@_;4585my@ref_views=qw{tags heads};4586push@ref_views,'remotes'if gitweb_check_feature('remote_heads');4587returnjoin" | ",map{4588$_eq$current?$_:4589$cgi->a({-href => href(action=>$_)},$_)4590}@ref_views4591}45924593sub format_paging_nav {4594my($action,$page,$has_next_link) =@_;4595my$paging_nav;459645974598if($page>0) {4599$paging_nav.=4600$cgi->a({-href => href(-replay=>1, page=>undef)},"first") .4601" ⋅ ".4602$cgi->a({-href => href(-replay=>1, page=>$page-1),4603-accesskey =>"p", -title =>"Alt-p"},"prev");4604}else{4605$paging_nav.="first ⋅ prev";4606}46074608if($has_next_link) {4609$paging_nav.=" ⋅ ".4610$cgi->a({-href => href(-replay=>1, page=>$page+1),4611-accesskey =>"n", -title =>"Alt-n"},"next");4612}else{4613$paging_nav.=" ⋅ next";4614}46154616return$paging_nav;4617}46184619## ......................................................................4620## functions printing or outputting HTML: div46214622sub git_print_header_div {4623my($action,$title,$refstr,$hash,$hash_base) =@_;4624my%args= ();46254626$args{'action'} =$action;4627$args{'hash'} =$hashif$hash;4628$args{'hash_base'} =$hash_baseif$hash_base;46294630if(defined$title&&length$title) {4631print"<div class=\"header\">\n".4632$cgi->a({-href => href(%args), -class=>"title"},4633$title?$title:$action) .4634"\n</div>\n";4635}4636}46374638sub format_repo_url {4639my($name,$url) =@_;4640return"<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";4641}46424643# Group output by placing it in a DIV element and adding a header.4644# Options for start_div() can be provided by passing a hash reference as the4645# first parameter to the function.4646# Options to git_print_header_div() can be provided by passing an array4647# reference. This must follow the options to start_div if they are present.4648# The content can be a scalar, which is output as-is, a scalar reference, which4649# is output after html escaping, an IO handle passed either as *handle or4650# *handle{IO}, or a function reference. In the latter case all following4651# parameters will be taken as argument to the content function call.4652sub git_print_section {4653my($div_args,$header_args,$content);4654my$arg=shift;4655if(ref($arg)eq'HASH') {4656$div_args=$arg;4657$arg=shift;4658}4659if(ref($arg)eq'ARRAY') {4660$header_args=$arg;4661$arg=shift;4662}4663$content=$arg;46644665print$cgi->start_div($div_args);4666 git_print_header_div(@$header_args);46674668if(ref($content)eq'CODE') {4669$content->(@_);4670}elsif(ref($content)eq'SCALAR') {4671print esc_html($$content);4672}elsif(ref($content)eq'GLOB'or ref($content)eq'IO::Handle') {4673print<$content>;4674}elsif(!ref($content) &&defined($content)) {4675print$content;4676}46774678print$cgi->end_div;4679}46804681sub format_timestamp_html {4682my$date=shift;4683my$strtime=$date->{'rfc2822'};46844685my(undef,undef,$datetime_class) =4686 gitweb_get_feature('javascript-timezone');4687if($datetime_class) {4688$strtime= qq!<span class="$datetime_class">$strtime</span>!;4689}46904691my$localtime_format='(%02d:%02d%s)';4692if($date->{'hour_local'} <6) {4693$localtime_format='(<span class="atnight">%02d:%02d</span>%s)';4694}4695$strtime.=' '.4696sprintf($localtime_format,4697$date->{'hour_local'},$date->{'minute_local'},$date->{'tz_local'});46984699return$strtime;4700}47014702# Outputs the author name and date in long form4703sub git_print_authorship {4704my$co=shift;4705my%opts=@_;4706my$tag=$opts{-tag} ||'div';4707my$author=$co->{'author_name'};47084709my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});4710print("<$tagclass=\"author\">");4711print(git_get_avatar($co->{'author_email'}, -pad_before =>1));4712print(format_search_author($author,"author", esc_html($author)));4713print("</$tag>\n");4714print("<$tagclass=\"age\">");4715print(format_timestamp_html(\%ad));4716print("</$tag>\n");4717}47184719# Outputs table rows containing the full author or committer information,4720# in the format expected for 'commit' view (& similar).4721# Parameters are a commit hash reference, followed by the list of people4722# to output information for. If the list is empty it defaults to both4723# author and committer.4724sub git_print_authorship_rows {4725my$co=shift;4726# too bad we can't use @people = @_ || ('author', 'committer')4727my@people=@_;4728@people= ('author','committer')unless@people;4729foreachmy$who(@people) {4730my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});4731print"<tr><th rowspan=\"2\"class=\"$who\">$who</th><td>".4732 format_search_author($co->{"${who}_name"},$who,4733 esc_html($co->{"${who}_name"})) ." ".4734 format_search_author($co->{"${who}_email"},$who,4735 esc_html("<".$co->{"${who}_email"} .">")) .4736"</td></tr><tr>";4737if($git_avatar) {4738print"<td rowspan=\"2\">"4739. git_get_avatar($co->{"${who}_email"}, -size =>'double')4740."</td>";4741}4742print"\n<td>".4743 format_timestamp_html(\%wd) .4744"</td>".4745"</tr>\n";4746}4747}47484749sub git_print_page_path {4750my$name=shift;4751my$type=shift;4752my$hb=shift;4753my$noprint=shift;475447554756my$output=$cgi->a({-href => href(action=>"tree", hash_base=>$hb),4757-title =>'tree root'}, to_utf8("[$project]"));4758$output.=" / ";4759if(defined$name) {4760my@dirname=split'/',$name;4761my$basename=pop@dirname;4762my$fullname='';47634764foreachmy$dir(@dirname) {4765$fullname.= ($fullname?'/':'') .$dir;4766$output.=$cgi->a({-href => href(action=>"tree", file_name=>$fullname,4767 hash_base=>$hb),4768-title =>$fullname}, esc_path($dir));4769$output.=" / ";4770}4771if(defined$type&&$typeeq'blob') {4772$output.=$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,4773 hash_base=>$hb),4774-title =>$name}, esc_path($basename));4775}elsif(defined$type&&$typeeq'tree') {4776$output.=$cgi->a({-href => href(action=>"tree", file_name=>$file_name,4777 hash_base=>$hb),4778-title =>$name}, esc_path($basename));4779$output.=" / ";4780}else{4781$output.= esc_path($basename);4782}4783}4784$output.="<br/>\n";4785unless($noprint) {4786print$output;4787}4788return$output;4789}479047914792sub git_path_header {4793my$name=shift;4794my$type=shift;4795my$hb=shift;4796my$noprint=shift;4797my$title=shift;4798my$ref=shift;4799my$hash=shift;48004801my$output="";4802if(defined$name) {4803my@dirname=split'/',$name;4804my$basename=pop@dirname;4805my$fullname='';48064807foreachmy$dir(@dirname) {4808$fullname.= ($fullname?'/':'') .$dir;4809$output.=$cgi->a({-href => href(action=>"tree", file_name=>$fullname,4810 hash_base=>$hb),4811-title =>$fullname, -class=>"title"}, esc_path($dir));4812$output.=" / ";4813}4814if(defined$type&&$typeeq'blob') {4815$output.=$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,4816 hash_base=>$hb),4817-title =>$name, -class=>"title"}, esc_path($basename));4818}elsif(defined$type&&$typeeq'tree') {4819$output.=$cgi->a({-href => href(action=>"tree", file_name=>$file_name,4820 hash_base=>$hb),4821-title =>$name, -class=>"title"}, esc_path($basename));4822$output.=" / ";4823}else{4824$output.= esc_path($basename);4825}4826}48274828$output.="<span class=\"tree_commit_info\">on commit "4829.$cgi->a({-href => href(action =>'commit', hash =>$ref)},"$title(".substr($hash,0,$hash_char) .")")4830."</span>";4831unless($noprint) {4832print$output;4833}4834return$output;4835}483648374838# Print the log output for a single commit4839sub git_print_log {4840my$log=shift;4841my%opts=@_;48424843if($opts{'-remove_title'}) {4844# remove title, i.e. first line of log4845shift@$log;4846}4847# remove leading empty lines4848while(defined$log->[0] &&$log->[0]eq"") {4849shift@$log;4850}48514852# print log4853my$skip_blank_line=0;4854foreachmy$line(@$log) {4855if($line=~m/^\s*([A-Z][-A-Za-z]*-[Bb]y|C[Cc]): /) {4856if(!$opts{'-remove_signoff'}) {4857print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";4858$skip_blank_line=1;4859}4860next;4861}48624863if($line=~ m,\s*([a-z]*link): (https?://\S+),i) {4864if(!$opts{'-remove_signoff'}) {4865print"<span class=\"signoff\">". esc_html($1) .": ".4866"<a href=\"". esc_html($2) ."\">". esc_html($2) ."</a>".4867"</span><br/>\n";4868$skip_blank_line=1;4869}4870next;4871}48724873# print only one empty line4874# do not print empty line after signoff4875if($lineeq"") {4876next if($skip_blank_line);4877$skip_blank_line=1;4878}else{4879$skip_blank_line=0;4880}48814882print format_log_line_html($line) ."<br/>\n";4883}48844885if($opts{'-final_empty_line'}) {4886# end with single empty line4887print"<br/>\n"unless$skip_blank_line;4888}4889}48904891# return link target (what link points to)4892sub git_get_link_target {4893my$hash=shift;4894my$link_target;48954896# read link4897open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4898orreturn;4899{4900local$/=undef;4901$link_target= <$fd>;4902}4903close$fd4904orreturn;49054906return$link_target;4907}49084909# given link target, and the directory (basedir) the link is in,4910# return target of link relative to top directory (top tree);4911# return undef if it is not possible (including absolute links).4912sub normalize_link_target {4913my($link_target,$basedir) =@_;49144915# absolute symlinks (beginning with '/') cannot be normalized4916return if(substr($link_target,0,1)eq'/');49174918# normalize link target to path from top (root) tree (dir)4919my$path;4920if($basedir) {4921$path=$basedir.'/'.$link_target;4922}else{4923# we are in top (root) tree (dir)4924$path=$link_target;4925}49264927# remove //, /./, and /../4928my@path_parts;4929foreachmy$part(split('/',$path)) {4930# discard '.' and ''4931next if(!$part||$parteq'.');4932# handle '..'4933if($parteq'..') {4934if(@path_parts) {4935pop@path_parts;4936}else{4937# link leads outside repository (outside top dir)4938return;4939}4940}else{4941push@path_parts,$part;4942}4943}4944$path=join('/',@path_parts);49454946return$path;4947}49484949# print tree entry (row of git_tree), but without encompassing <tr> element4950sub git_print_tree_entry {4951my($t,$basedir,$hash_base,$have_blame) =@_;49524953my%base_key= ();4954$base_key{'hash_base'} =$hash_baseifdefined$hash_base;49554956# The format of a table row is: mode list link. Where mode is4957# the mode of the entry, list is the name of the entry, an href,4958# and link is the action links of the entry.49594960print"<td class=\"mode\">";4961if(S_ISDIR(oct$t->{'mode'} & S_IFMT)) {4962print'<svg width="14" height="14" '4963.'xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">'4964.'<use xlink:href="#foldericon" /></svg>';4965}4966print mode_str($t->{'mode'}) ."</td>\n";4967if(exists$t->{'size'}) {4968print"<td class=\"size\">$t->{'size'}</td>\n";4969}4970if($t->{'type'}eq"blob") {4971print"<td class=\"list\">".4972$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4973 file_name=>"$basedir$t->{'name'}",%base_key),4974-class=>"list"}, esc_path($t->{'name'}));4975if(S_ISLNK(oct$t->{'mode'})) {4976my$link_target= git_get_link_target($t->{'hash'});4977if($link_target) {4978my$norm_target= normalize_link_target($link_target,$basedir);4979if(defined$norm_target) {4980print" -> ".4981$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,4982 file_name=>$norm_target),4983-title =>$norm_target}, esc_path($link_target));4984}else{4985print" -> ". esc_path($link_target);4986}4987}4988}4989print"</td>\n";4990print"<td class=\"link\">";4991print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4992 file_name=>"$basedir$t->{'name'}",%base_key)},4993"blob");4994if($have_blame) {4995print" | ".4996$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},4997 file_name=>"$basedir$t->{'name'}",%base_key)},4998"blame");4999}5000if(defined$hash_base) {5001print" | ".5002$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,5003 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},5004"history");5005}5006print" | ".5007$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,5008 file_name=>"$basedir$t->{'name'}")},5009"raw");5010print"</td>\n";50115012}elsif($t->{'type'}eq"tree") {5013print"<td class=\"list\">";5014print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},5015 file_name=>"$basedir$t->{'name'}",5016%base_key)},5017 esc_path($t->{'name'}));5018print"</td>\n";5019print"<td class=\"link\">";5020print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},5021 file_name=>"$basedir$t->{'name'}",5022%base_key)},5023"tree");5024if(defined$hash_base) {5025print" | ".5026$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,5027 file_name=>"$basedir$t->{'name'}")},5028"history");5029}5030print"</td>\n";5031}else{5032# unknown object: we can only present history for it5033# (this includes 'commit' object, i.e. submodule support)5034print"<td class=\"list\">".5035 esc_path($t->{'name'}) .5036"</td>\n";5037print"<td class=\"link\">";5038if(defined$hash_base) {5039print$cgi->a({-href => href(action=>"history",5040 hash_base=>$hash_base,5041 file_name=>"$basedir$t->{'name'}")},5042"history");5043}5044print"</td>\n";5045}5046}50475048## ......................................................................5049## functions printing large fragments of HTML50505051# get pre-image filenames for merge (combined) diff5052sub fill_from_file_info {5053my($diff,@parents) =@_;50545055$diff->{'from_file'} = [ ];5056$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;5057for(my$i=0;$i<$diff->{'nparents'};$i++) {5058if($diff->{'status'}[$i]eq'R'||5059$diff->{'status'}[$i]eq'C') {5060$diff->{'from_file'}[$i] =5061 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);5062}5063}50645065return$diff;5066}50675068# is current raw difftree line of file deletion5069sub is_deleted {5070my$diffinfo=shift;50715072return$diffinfo->{'to_id'}eq('0' x 40) ||$diffinfo->{'to_id'}eq('0' x 64);5073}50745075# does patch correspond to [previous] difftree raw line5076# $diffinfo - hashref of parsed raw diff format5077# $patchinfo - hashref of parsed patch diff format5078# (the same keys as in $diffinfo)5079sub is_patch_split {5080my($diffinfo,$patchinfo) =@_;50815082returndefined$diffinfo&&defined$patchinfo5083&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};5084}508550865087sub git_difftree_body {5088my($difftree,$hash,@parents) =@_;5089my($parent) =$parents[0];5090my$have_blame= gitweb_check_feature('blame');5091if($#{$difftree} >10) {5092print"<div class=\"list_head\">\n";5093print(($#{$difftree} +1) ." files changed:\n");5094print"</div>\n";5095}50965097print"<table class=\"".5098(@parents>1?"combined ":"") .5099"diff_tree\">\n";51005101# header only for combined diff in 'diff' view5102my$has_header=@$difftree&&@parents>1&&$actioneq'diff';5103if($has_header) {5104# table header5105print"<thead><tr>\n".5106"<th></th><th></th>\n";# filename, patchN link5107for(my$i=0;$i<@parents;$i++) {5108my$par=$parents[$i];5109print"<th>".5110$cgi->a({-href => href(action=>"diff",5111 hash=>$hash, hash_parent=>$par),5112-title =>'diff to parent number '.5113($i+1) .': '.substr($par,0,7)},5114$i+1) .5115" </th>\n";5116}5117print"</tr></thead>\n<tbody>\n";5118}51195120my$alternate=1;5121my$patchno=0;5122foreachmy$line(@{$difftree}) {5123my$diff= parsed_difftree_line($line);51245125if($alternate) {5126print"<tr class=\"dark\">\n";5127}else{5128print"<tr class=\"light\">\n";5129}5130$alternate^=1;51315132if(exists$diff->{'nparents'}) {# combined diff51335134 fill_from_file_info($diff,@parents)5135unlessexists$diff->{'from_file'};51365137if(!is_deleted($diff)) {5138# file exists in the result (child) commit5139print"<td>".5140$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},5141 file_name=>$diff->{'to_file'},5142 hash_base=>$hash),5143-class=>"list"}, esc_path($diff->{'to_file'})) .5144"</td>\n";5145}else{5146print"<td>".5147 esc_path($diff->{'to_file'}) .5148"</td>\n";5149}51505151if($actioneq'diff') {5152# link to patch5153$patchno++;5154print"<td class=\"link\">".5155$cgi->a({-href => href(-anchor=>"patch$patchno")},5156"patch") .5157" | ".5158"</td>\n";5159}51605161my$has_history=0;5162my$not_deleted=0;5163for(my$i=0;$i<$diff->{'nparents'};$i++) {5164my$hash_parent=$parents[$i];5165my$from_hash=$diff->{'from_id'}[$i];5166my$from_path=$diff->{'from_file'}[$i];5167my$status=$diff->{'status'}[$i];51685169$has_history||= ($statusne'A');5170$not_deleted||= ($statusne'D');51715172if($statuseq'A') {5173print"<td class=\"link\"align=\"right\"> | </td>\n";5174}elsif($statuseq'D') {5175print"<td class=\"link\">".5176$cgi->a({-href => href(action=>"blob",5177 hash_base=>$hash,5178 hash=>$from_hash,5179 file_name=>$from_path)},5180"blob". ($i+1)) .5181" | </td>\n";5182}else{5183if($diff->{'to_id'}eq$from_hash) {5184print"<td class=\"link nochange\">";5185}else{5186print"<td class=\"link\">";5187}5188print$cgi->a({-href => href(action=>"blobdiff",5189 hash=>$diff->{'to_id'},5190 hash_parent=>$from_hash,5191 hash_base=>$hash,5192 hash_parent_base=>$hash_parent,5193 file_name=>$diff->{'to_file'},5194 file_parent=>$from_path)},5195"diff". ($i+1)) .5196" | </td>\n";5197}5198}51995200print"<td class=\"link\">";5201if($not_deleted) {5202print$cgi->a({-href => href(action=>"blob",5203 hash=>$diff->{'to_id'},5204 file_name=>$diff->{'to_file'},5205 hash_base=>$hash)},5206"blob");5207print" | "if($has_history);5208}5209if($has_history) {5210print$cgi->a({-href => href(action=>"history",5211 file_name=>$diff->{'to_file'},5212 hash_base=>$hash)},5213"history");5214}5215print"</td>\n";52165217print"</tr>\n";5218next;# instead of 'else' clause, to avoid extra indent5219}5220# else ordinary diff52215222my($to_mode_oct,$to_mode_str,$to_file_type);5223my($from_mode_oct,$from_mode_str,$from_file_type);5224if($diff->{'to_mode'}ne('0' x 6)) {5225$to_mode_oct=oct$diff->{'to_mode'};5226if(S_ISREG($to_mode_oct)) {# only for regular file5227$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits5228}5229$to_file_type= file_type($diff->{'to_mode'});5230}5231if($diff->{'from_mode'}ne('0' x 6)) {5232$from_mode_oct=oct$diff->{'from_mode'};5233if(S_ISREG($from_mode_oct)) {# only for regular file5234$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits5235}5236$from_file_type= file_type($diff->{'from_mode'});5237}52385239if($diff->{'status'}eq"A") {# created5240my$mode_chng="<span class=\"file_status new\">[new$to_file_type";5241$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;5242$mode_chng.="]</span>";5243print"<td>";5244print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},5245 hash_base=>$hash, file_name=>$diff->{'file'}),5246-class=>"list"}, esc_path($diff->{'file'}));5247print"</td>\n";5248print"<td>$mode_chng</td>\n";5249print"<td class=\"link\">";5250if($actioneq'diff') {5251# link to patch5252$patchno++;5253print$cgi->a({-href => href(-anchor=>"patch$patchno")},5254"patch") .5255" | ";5256}5257print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},5258 hash_base=>$hash, file_name=>$diff->{'file'})},5259"blob");5260print"</td>\n";52615262}elsif($diff->{'status'}eq"D") {# deleted5263my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";5264print"<td>";5265print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},5266 hash_base=>$parent, file_name=>$diff->{'file'}),5267-class=>"list"}, esc_path($diff->{'file'}));5268print"</td>\n";5269print"<td>$mode_chng</td>\n";5270print"<td class=\"link\">";5271if($actioneq'diff') {5272# link to patch5273$patchno++;5274print$cgi->a({-href => href(-anchor=>"patch$patchno")},5275"patch") .5276" | ";5277}5278print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},5279 hash_base=>$parent, file_name=>$diff->{'file'})},5280"blob") ." | ";5281if($have_blame) {5282print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,5283 file_name=>$diff->{'file'})},5284"blame") ." | ";5285}5286print$cgi->a({-href => href(action=>"history", hash_base=>$parent,5287 file_name=>$diff->{'file'})},5288"history");5289print"</td>\n";52905291}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed5292my$mode_chnge="";5293if($diff->{'from_mode'} !=$diff->{'to_mode'}) {5294$mode_chnge="<span class=\"file_status mode_chnge\">[changed";5295if($from_file_typene$to_file_type) {5296$mode_chnge.=" from$from_file_typeto$to_file_type";5297}5298if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {5299if($from_mode_str&&$to_mode_str) {5300$mode_chnge.=" mode:$from_mode_str->$to_mode_str";5301}elsif($to_mode_str) {5302$mode_chnge.=" mode:$to_mode_str";5303}5304}5305$mode_chnge.="]</span>\n";5306}5307print"<td>";5308print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},5309 hash_base=>$hash, file_name=>$diff->{'file'}),5310-class=>"list"}, esc_path($diff->{'file'}));5311print"</td>\n";5312print"<td>$mode_chnge</td>\n";5313print"<td class=\"link\">";5314if($actioneq'diff') {5315# link to patch5316$patchno++;5317print$cgi->a({-href => href(-anchor=>"patch$patchno")},5318"patch") .5319" | ";5320}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {5321# "commit" view and modified file (not onlu mode changed)5322print$cgi->a({-href => href(action=>"blobdiff",5323 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},5324 hash_base=>$hash, hash_parent_base=>$parent,5325 file_name=>$diff->{'file'})},5326"diff") .5327" | ";5328}5329print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},5330 hash_base=>$hash, file_name=>$diff->{'file'})},5331"blob") ." | ";5332if($have_blame) {5333print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,5334 file_name=>$diff->{'file'})},5335"blame") ." | ";5336}5337print$cgi->a({-href => href(action=>"history", hash_base=>$hash,5338 file_name=>$diff->{'file'})},5339"history");5340print"</td>\n";53415342}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied5343my%status_name= ('R'=>'moved','C'=>'copied');5344my$nstatus=$status_name{$diff->{'status'}};5345my$mode_chng="";5346if($diff->{'from_mode'} !=$diff->{'to_mode'}) {5347# mode also for directories, so we cannot use $to_mode_str5348$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);5349}5350print"<td>".5351$cgi->a({-href => href(action=>"blob", hash_base=>$hash,5352 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),5353-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".5354"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".5355$cgi->a({-href => href(action=>"blob", hash_base=>$parent,5356 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),5357-class=>"list"}, esc_path($diff->{'from_file'})) .5358" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".5359"<td class=\"link\">";5360if($actioneq'diff') {5361# link to patch5362$patchno++;5363print$cgi->a({-href => href(-anchor=>"patch$patchno")},5364"patch") .5365" | ";5366}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {5367# "commit" view and modified file (not only pure rename or copy)5368print$cgi->a({-href => href(action=>"blobdiff",5369 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},5370 hash_base=>$hash, hash_parent_base=>$parent,5371 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},5372"diff") .5373" | ";5374}5375print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},5376 hash_base=>$parent, file_name=>$diff->{'to_file'})},5377"blob") ." | ";5378if($have_blame) {5379print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,5380 file_name=>$diff->{'to_file'})},5381"blame") ." | ";5382}5383print$cgi->a({-href => href(action=>"history", hash_base=>$hash,5384 file_name=>$diff->{'to_file'})},5385"history");5386print"</td>\n";53875388}# we should not encounter Unmerged (U) or Unknown (X) status5389print"</tr>\n";5390}5391print"</tbody>"if$has_header;5392print"</table>\n";5393}53945395# Print context lines and then rem/add lines in a side-by-side manner.5396sub print_sidebyside_diff_lines {5397my($ctx,$rem,$add) =@_;53985399# print context block before add/rem block5400if(@$ctx) {5401print join'',5402'<div class="chunk_block ctx">',5403'<div class="old">',5404@$ctx,5405'</div>',5406'<div class="new">',5407@$ctx,5408'</div>',5409'</div>';5410}54115412if(!@$add) {5413# pure removal5414print join'',5415'<div class="chunk_block rem">',5416'<div class="old">',5417@$rem,5418'</div>',5419'</div>';5420}elsif(!@$rem) {5421# pure addition5422print join'',5423'<div class="chunk_block add">',5424'<div class="new">',5425@$add,5426'</div>',5427'</div>';5428}else{5429print join'',5430'<div class="chunk_block chg">',5431'<div class="old">',5432@$rem,5433'</div>',5434'<div class="new">',5435@$add,5436'</div>',5437'</div>';5438}5439}54405441# Print context lines and then rem/add lines in inline manner.5442sub print_inline_diff_lines {5443my($ctx,$rem,$add) =@_;54445445print@$ctx,@$rem,@$add;5446}54475448# Format removed and added line, mark changed part and HTML-format them.5449# Implementation is based on contrib/diff-highlight5450sub format_rem_add_lines_pair {5451my($rem,$add,$num_parents) =@_;54525453# We need to untabify lines before split()'ing them;5454# otherwise offsets would be invalid.5455chomp$rem;5456chomp$add;5457$rem= untabify($rem);5458$add= untabify($add);54595460my@rem=split(//,$rem);5461my@add=split(//,$add);5462my($esc_rem,$esc_add);5463# Ignore leading +/- characters for each parent.5464my($prefix_len,$suffix_len) = ($num_parents,0);5465my($prefix_has_nonspace,$suffix_has_nonspace);54665467my$shorter= (@rem<@add) ?@rem:@add;5468while($prefix_len<$shorter) {5469last if($rem[$prefix_len]ne$add[$prefix_len]);54705471$prefix_has_nonspace=1if($rem[$prefix_len] !~/\s/);5472$prefix_len++;5473}54745475while($prefix_len+$suffix_len<$shorter) {5476last if($rem[-1-$suffix_len]ne$add[-1-$suffix_len]);54775478$suffix_has_nonspace=1if($rem[-1-$suffix_len] !~/\s/);5479$suffix_len++;5480}54815482# Mark lines that are different from each other, but have some common5483# part that isn't whitespace. If lines are completely different, don't5484# mark them because that would make output unreadable, especially if5485# diff consists of multiple lines.5486if($prefix_has_nonspace||$suffix_has_nonspace) {5487$esc_rem= esc_html_hl_regions($rem,'marked',5488[$prefix_len,@rem-$suffix_len], -nbsp=>1);5489$esc_add= esc_html_hl_regions($add,'marked',5490[$prefix_len,@add-$suffix_len], -nbsp=>1);5491}else{5492$esc_rem= esc_html($rem, -nbsp=>1);5493$esc_add= esc_html($add, -nbsp=>1);5494}54955496return format_diff_line(\$esc_rem,'rem'),5497 format_diff_line(\$esc_add,'add');5498}54995500# HTML-format diff context, removed and added lines.5501sub format_ctx_rem_add_lines {5502my($ctx,$rem,$add,$num_parents) =@_;5503my(@new_ctx,@new_rem,@new_add);5504my$can_highlight=0;5505my$is_combined= ($num_parents>1);55065507# Highlight if every removed line has a corresponding added line.5508if(@$add>0&&@$add==@$rem) {5509$can_highlight=1;55105511# Highlight lines in combined diff only if the chunk contains5512# diff between the same version, e.g.5513#5514# - a5515# - b5516# + c5517# + d5518#5519# Otherwise the highlightling would be confusing.5520if($is_combined) {5521for(my$i=0;$i<@$add;$i++) {5522my$prefix_rem=substr($rem->[$i],0,$num_parents);5523my$prefix_add=substr($add->[$i],0,$num_parents);55245525$prefix_rem=~s/-/+/g;55265527if($prefix_remne$prefix_add) {5528$can_highlight=0;5529last;5530}5531}5532}5533}55345535if($can_highlight) {5536for(my$i=0;$i<@$add;$i++) {5537my($line_rem,$line_add) = format_rem_add_lines_pair(5538$rem->[$i],$add->[$i],$num_parents);5539push@new_rem,$line_rem;5540push@new_add,$line_add;5541}5542}else{5543@new_rem=map{ format_diff_line($_,'rem') }@$rem;5544@new_add=map{ format_diff_line($_,'add') }@$add;5545}55465547@new_ctx=map{ format_diff_line($_,'ctx') }@$ctx;55485549return(\@new_ctx, \@new_rem, \@new_add);5550}55515552# Print context lines and then rem/add lines.5553sub print_diff_lines {5554my($ctx,$rem,$add,$diff_style,$num_parents) =@_;5555my$is_combined=$num_parents>1;55565557($ctx,$rem,$add) = format_ctx_rem_add_lines($ctx,$rem,$add,5558$num_parents);55595560if($diff_styleeq'sidebyside'&& !$is_combined) {5561 print_sidebyside_diff_lines($ctx,$rem,$add);5562}else{5563# default 'inline' style and unknown styles5564 print_inline_diff_lines($ctx,$rem,$add);5565}5566}55675568sub print_diff_chunk {5569my($diff_style,$num_parents,$from,$to,@chunk) =@_;5570my(@ctx,@rem,@add);55715572# The class of the previous line.5573my$prev_class='';55745575return unless@chunk;55765577# incomplete last line might be among removed or added lines,5578# or both, or among context lines: find which5579for(my$i=1;$i<@chunk;$i++) {5580if($chunk[$i][0]eq'incomplete') {5581$chunk[$i][0] =$chunk[$i-1][0];5582}5583}55845585# guardian5586push@chunk, ["",""];55875588foreachmy$line_info(@chunk) {5589my($class,$line) =@$line_info;55905591# print chunk headers5592if($class&&$classeq'chunk_header') {5593print format_diff_line($line,$class,$from,$to);5594next;5595}55965597## print from accumulator when have some add/rem lines or end5598# of chunk (flush context lines), or when have add and rem5599# lines and new block is reached (otherwise add/rem lines could5600# be reordered)5601if(!$class|| ((@rem||@add) &&$classeq'ctx') ||5602(@rem&&@add&&$classne$prev_class)) {5603 print_diff_lines(\@ctx, \@rem, \@add,5604$diff_style,$num_parents);5605@ctx=@rem=@add= ();5606}56075608## adding lines to accumulator5609# guardian value5610last unless$line;5611# rem, add or change5612if($classeq'rem') {5613push@rem,$line;5614}elsif($classeq'add') {5615push@add,$line;5616}5617# context line5618if($classeq'ctx') {5619push@ctx,$line;5620}56215622$prev_class=$class;5623}5624}56255626sub git_patchset_body {5627my($fd,$diff_style,$difftree,$hash,@hash_parents) =@_;5628my($hash_parent) =$hash_parents[0];56295630my$is_combined= (@hash_parents>1);5631my$patch_idx=0;5632my$patch_number=0;5633my$patch_line;5634my$diffinfo;5635my$to_name;5636my(%from,%to);5637my@chunk;# for side-by-side diff56385639print"<div class=\"patchset\">\n";56405641# skip to first patch5642while($patch_line= <$fd>) {5643chomp$patch_line;56445645last if($patch_line=~m/^diff /);5646}56475648 PATCH:5649while($patch_line) {56505651# parse "git diff" header line5652if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {5653# $1 is from_name, which we do not use5654$to_name= unquote($2);5655$to_name=~s!^b/!!;5656}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {5657# $1 is 'cc' or 'combined', which we do not use5658$to_name= unquote($2);5659}else{5660$to_name=undef;5661}56625663# check if current patch belong to current raw line5664# and parse raw git-diff line if needed5665if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {5666# this is continuation of a split patch5667print"<div class=\"patch cont\">\n";5668}else{5669# advance raw git-diff output if needed5670$patch_idx++ifdefined$diffinfo;56715672# read and prepare patch information5673$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);56745675# compact combined diff output can have some patches skipped5676# find which patch (using pathname of result) we are at now;5677if($is_combined) {5678while($to_namene$diffinfo->{'to_file'}) {5679print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".5680 format_diff_cc_simplified($diffinfo,@hash_parents) .5681"</div>\n";# class="patch"56825683$patch_idx++;5684$patch_number++;56855686last if$patch_idx>$#$difftree;5687$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);5688}5689}56905691# modifies %from, %to hashes5692 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);56935694# this is first patch for raw difftree line with $patch_idx index5695# we index @$difftree array from 0, but number patches from 15696print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";5697}56985699# git diff header5700#assert($patch_line =~ m/^diff /) if DEBUG;5701#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed5702$patch_number++;5703# print "git diff" header5704print format_git_diff_header_line($patch_line,$diffinfo,5705 \%from, \%to);57065707# print extended diff header5708print"<div class=\"diff extended_header\">\n";5709 EXTENDED_HEADER:5710while($patch_line= <$fd>) {5711chomp$patch_line;57125713last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);57145715print format_extended_diff_header_line($patch_line,$diffinfo,5716 \%from, \%to);5717}5718print"</div>\n";# class="diff extended_header"57195720# from-file/to-file diff header5721if(!$patch_line) {5722print"</div>\n";# class="patch"5723last PATCH;5724}5725next PATCH if($patch_line=~m/^diff /);5726#assert($patch_line =~ m/^---/) if DEBUG;57275728my$last_patch_line=$patch_line;5729$patch_line= <$fd>;5730chomp$patch_line;5731#assert($patch_line =~ m/^\+\+\+/) if DEBUG;57325733print format_diff_from_to_header($last_patch_line,$patch_line,5734$diffinfo, \%from, \%to,5735@hash_parents);57365737# the patch itself5738 LINE:5739while($patch_line= <$fd>) {5740chomp$patch_line;57415742next PATCH if($patch_line=~m/^diff /);57435744my$class= diff_line_class($patch_line, \%from, \%to);57455746if($classeq'chunk_header') {5747 print_diff_chunk($diff_style,scalar@hash_parents, \%from, \%to,@chunk);5748@chunk= ();5749}57505751push@chunk, [$class,$patch_line];5752}57535754}continue{5755if(@chunk) {5756 print_diff_chunk($diff_style,scalar@hash_parents, \%from, \%to,@chunk);5757@chunk= ();5758}5759print"</div>\n";# class="patch"5760}57615762# for compact combined (--cc) format, with chunk and patch simplification5763# the patchset might be empty, but there might be unprocessed raw lines5764for(++$patch_idxif$patch_number>0;5765$patch_idx<@$difftree;5766++$patch_idx) {5767# read and prepare patch information5768$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);57695770# generate anchor for "patch" links in difftree / whatchanged part5771print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".5772 format_diff_cc_simplified($diffinfo,@hash_parents) .5773"</div>\n";# class="patch"57745775$patch_number++;5776}57775778if($patch_number==0) {5779if(@hash_parents>1) {5780print"<div class=\"diff nodifferences\">Trivial merge</div>\n";5781}else{5782print"<div class=\"diff nodifferences\">No differences found</div>\n";5783}5784}57855786print"</div>\n";# class="patchset"5787}57885789# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .57905791sub git_project_search_form {5792my($searchtext,$search_use_regexp) =@_;57935794my$limit='';5795if($project_filter) {5796$limit=" in '$project_filter/'";5797}57985799print"<div class=\"projsearch\">\n";5800print$cgi->start_form(-method=>'get', -action =>$my_uri) .5801$cgi->hidden(-name =>'a', -value =>'project_list') ."\n";5802print$cgi->hidden(-name =>'pf', -value =>$project_filter)."\n"5803if(defined$project_filter);5804print$cgi->textfield(-name =>'s', -value =>$searchtext,5805-title =>"Search project by name and description$limit",5806-size =>60,5807-placeholder =>"search repos") ."\n".5808$cgi->submit(-name =>'btnS', -value =>'search') .5809"<span title=\"Extended regular expression\">".5810$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',5811-checked =>$search_use_regexp) .5812"</span>\n".5813$cgi->end_form() ."\n".5814$cgi->a({-href => href(project =>undef, searchtext =>undef,5815 project_filter =>$project_filter)},5816 esc_html("List all projects$limit")) ."<br />\n";5817print"</div>\n";5818}58195820# entry for given @keys needs filling if at least one of keys in list5821# is not present in %$project_info5822sub project_info_needs_filling {5823my($project_info,@keys) =@_;58245825# return List::MoreUtils::any { !exists $project_info->{$_} } @keys;5826foreachmy$key(@keys) {5827if(!exists$project_info->{$key}) {5828return1;5829}5830}5831return;5832}58335834# fills project list info (age, description, owner, category, forks, etc.)5835# for each project in the list, removing invalid projects from5836# returned list, or fill only specified info.5837#5838# Invalid projects are removed from the returned list if and only if you5839# ask 'age' or 'age_string' to be filled, because they are the only fields5840# that run unconditionally git command that requires repository, and5841# therefore do always check if project repository is invalid.5842#5843# USAGE:5844# * fill_project_list_info(\@project_list, 'descr_long', 'ctags')5845# ensures that 'descr_long' and 'ctags' fields are filled5846# * @project_list = fill_project_list_info(\@project_list)5847# ensures that all fields are filled (and invalid projects removed)5848#5849# NOTE: modifies $projlist, but does not remove entries from it5850sub fill_project_list_info {5851my($projlist,@wanted_keys) =@_;5852my@projects;5853my$filter_set=sub{return@_; };5854if(@wanted_keys) {5855my%wanted_keys=map{$_=>1}@wanted_keys;5856$filter_set=sub{returngrep{$wanted_keys{$_} }@_; };5857}58585859my$show_ctags= gitweb_check_feature('ctags');5860 PROJECT:5861foreachmy$pr(@$projlist) {5862if(project_info_needs_filling($pr,$filter_set->('age','age_string'))) {5863my(@activity) = git_get_last_activity($pr->{'path'});5864unless(@activity) {5865next PROJECT;5866}5867($pr->{'age'},$pr->{'age_string'}) =@activity;5868}5869if(project_info_needs_filling($pr,$filter_set->('descr','descr_long'))) {5870my$descr= git_get_project_description($pr->{'path'}) ||"";5871$descr= to_utf8($descr);5872$pr->{'descr_long'} =$descr;5873$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);5874}5875if(project_info_needs_filling($pr,$filter_set->('owner'))) {5876$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";5877}5878if($show_ctags&&5879 project_info_needs_filling($pr,$filter_set->('ctags'))) {5880$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});5881}5882if($projects_list_group_categories&&5883 project_info_needs_filling($pr,$filter_set->('category'))) {5884my$cat= git_get_project_category($pr->{'path'}) ||5885$project_list_default_category;5886$pr->{'category'} = to_utf8($cat);5887}58885889push@projects,$pr;5890}58915892return@projects;5893}58945895sub sort_projects_list {5896my($projlist,$order) =@_;58975898sub order_str {5899my$key=shift;5900return sub{$a->{$key}cmp$b->{$key} };5901}59025903sub order_num_then_undef {5904my$key=shift;5905return sub{5906defined$a->{$key} ?5907(defined$b->{$key} ?$a->{$key} <=>$b->{$key} : -1) :5908(defined$b->{$key} ?1:0)5909};5910}59115912my%orderings= (5913 project => order_str('path'),5914 descr => order_str('descr_long'),5915 owner => order_str('owner'),5916 age => order_num_then_undef('age'),5917);59185919my$ordering=$orderings{$order};5920returndefined$ordering?sort$ordering @$projlist:@$projlist;5921}59225923# returns a hash of categories, containing the list of project5924# belonging to each category5925sub build_projlist_by_category {5926my($projlist,$from,$to) =@_;5927my%categories;59285929$from=0unlessdefined$from;5930$to=$#$projlistif(!defined$to||$#$projlist<$to);59315932for(my$i=$from;$i<=$to;$i++) {5933my$pr=$projlist->[$i];5934push@{$categories{$pr->{'category'} }},$pr;5935}59365937returnwantarray?%categories: \%categories;5938}59395940# print 'sort by' <th> element, generating 'sort by $name' replay link5941# if that order is not selected5942sub print_sort_th {5943print format_sort_th(@_);5944}59455946sub format_sort_th {5947my($name,$order,$header) =@_;5948my$sort_th="";5949$header||=ucfirst($name);59505951if($ordereq$name) {5952$sort_th.="<th>$header</th>\n";5953}else{5954$sort_th.="<th>".5955$cgi->a({-href => href(-replay=>1, order=>$name),5956-class=>"header"},$header) .5957"</th>\n";5958}59595960return$sort_th;5961}59625963sub git_project_list_rows {5964my($projlist,$from,$to,$check_forks) =@_;59655966$from=0unlessdefined$from;5967$to=$#$projlistif(!defined$to||$#$projlist<$to);59685969my$alternate=1;5970for(my$i=$from;$i<=$to;$i++) {5971my$pr=$projlist->[$i];59725973if($alternate) {5974print"<tr class=\"dark\">\n";5975}else{5976print"<tr class=\"light\">\n";5977}5978$alternate^=1;59795980if($check_forks) {5981print"<td>";5982if($pr->{'forks'}) {5983my$nforks=scalar@{$pr->{'forks'}};5984if($nforks>0) {5985print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks"),5986-title =>"$nforksforks"},"+");5987}else{5988print$cgi->span({-title =>"$nforksforks"},"+");5989}5990}5991print"</td>\n";5992}59935994# Added by Andrew Lorimer, October 20195995# Optionally remove ".git" extension in table5996my$prname= esc_html_match_hl($pr->{'path'},$search_regexp);5997if($omit_git_extension) {5998$prname=~s/\.git//;5999}60006001print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),6002-class=>"list"},$prname) .6003"</td>\n".6004"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),6005-class=>"list",6006-title =>$pr->{'descr_long'}},6007$search_regexp6008? esc_html_match_hl_chopped($pr->{'descr_long'},6009$pr->{'descr'},$search_regexp)6010: esc_html($pr->{'descr'})) .6011"</td>\n";60126013unless($omit_owner) {6014print"<td>". chop_and_escape_str($pr->{'owner'},15) ."</td>\n";6015}60166017# Modified by Andrew Lorimer, October 20196018# Link date field to latest commit6019unless($omit_age_column) {6020print"<td class=\"". age_class($pr->{'age'}) ."\">".6021(defined$pr->{'age_string'} ?$cgi->a({-href => href(project=>$pr->{'path'},6022 action=>"commit"), -class=>"list"},$pr->{'age_string'}) :"No commits") ."</td>\n";6023}60246025# Added by Andrew Lorimer, October 20196026# Optionally hide repo-specific page shortcuts in project list6027unless($omit_shortcuts) {6028print"<td class=\"link\">".6029$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".6030$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".6031$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".6032$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .6033($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .6034"</td>\n";6035}6036print"</tr>\n";6037}6038}60396040sub git_project_list_body {6041# actually uses global variable $project6042my($projlist,$order,$from,$to,$extra,$no_header) =@_;6043my@projects=@$projlist;60446045my$check_forks= gitweb_check_feature('forks');6046my$show_ctags= gitweb_check_feature('ctags');6047my$tagfilter=$show_ctags?$input_params{'ctag'} :undef;6048$check_forks=undef6049if($tagfilter||$search_regexp);60506051# filtering out forks before filling info allows to do less work6052@projects= filter_forks_from_projects_list(\@projects)6053if($check_forks);6054# search_projects_list pre-fills required info6055@projects= search_projects_list(\@projects,6056'search_regexp'=>$search_regexp,6057'tagfilter'=>$tagfilter)6058if($tagfilter||$search_regexp);6059# fill the rest6060my@all_fields= ('descr','descr_long','ctags','category');6061push@all_fields, ('age','age_string')unless($omit_age_column);6062push@all_fields,'owner'unless($omit_owner);6063@projects= fill_project_list_info(\@projects,@all_fields);60646065$order||=$default_projects_order;6066$from=0unlessdefined$from;6067$to=$#projectsif(!defined$to||$#projects<$to);60686069# short circuit6070if($from>$to) {6071print"<center>\n".6072"<b>No such projects found</b><br />\n".6073"Click ".$cgi->a({-href=>href(project=>undef)},"here")." to view all projects<br />\n".6074"</center>\n<br />\n";6075return;6076}60776078@projects= sort_projects_list(\@projects,$order);60796080if($show_ctags) {6081my$ctags= git_gather_all_ctags(\@projects);6082my$cloud= git_populate_project_tagcloud($ctags);6083print git_show_project_tagcloud($cloud,64);6084}60856086print"<table class=\"project_list\">\n";6087unless($no_header||not$index_header) {6088print"<tr>\n";6089if($check_forks) {6090print"<th></th>\n";6091}6092 print_sort_th('project',$order,'Project');6093 print_sort_th('descr',$order,'Description');6094 print_sort_th('owner',$order,'Owner')unless$omit_owner;6095 print_sort_th('age',$order,'Last Change')unless$omit_age_column;6096print"<th></th>\n".# for links6097"</tr>\n";6098}60996100if($projects_list_group_categories) {6101# only display categories with projects in the $from-$to window6102@projects=sort{$a->{'category'}cmp$b->{'category'}}@projects[$from..$to];6103my%categories= build_projlist_by_category(\@projects,$from,$to);6104foreachmy$cat(sort keys%categories) {6105unless($cateq"") {6106print"<tr>\n";6107if($check_forks) {6108print"<td></td>\n";6109}6110print"<td class=\"category\"colspan=\"5\">".esc_html($cat)."</td>\n";6111print"</tr>\n";6112}61136114 git_project_list_rows($categories{$cat},undef,undef,$check_forks);6115}6116}else{6117 git_project_list_rows(\@projects,$from,$to,$check_forks);6118}61196120if(defined$extra) {6121print"<tr>\n";6122if($check_forks) {6123print"<td></td>\n";6124}6125print"<td colspan=\"5\">$extra</td>\n".6126"</tr>\n";6127}6128print"</table>\n";6129}61306131sub git_log_body {6132# uses global variable $project6133my($commitlist,$from,$to,$refs,$extra) =@_;61346135if(not defined$from) {6136my$from=0;6137}6138$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);61396140for(my$i=0;$i<=$to;$i++) {6141my%co= %{$commitlist->[$i]};6142next if!%co;6143my$commit=$co{'id'};6144my$ref= format_ref_marker($refs,$commit);61456146print("<div class=\"log_commit\">\n");6147print"<div class=\"log_link\">\n".6148$cgi->a({-href => href(action=>"diff", hash=>$commit)},"diff") .6149" | ".6150$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .6151"<br/>\n".6152"</div>\n";6153print("<span class=\"commit_title\">");6154print format_subject_html($co{'title'},$co{'title_short'},6155 href(action=>"commit", hash=>$commit),$ref);6156print("</span>");6157 git_print_authorship(\%co, -tag =>'span');6158print("<p class=\"commit_message\">");6159 git_print_log($co{'comment'}, -final_empty_line=>1);6160print("</p>");6161# print "<br/>\n</div>\n";61626163#print "<div class=\"log_body\">\n";6164#git_print_log($co{'comment'}, -final_empty_line=> 1);6165#print "</div>\n";6166print("</div>");6167}6168if($extra) {6169print"<nav>\n";6170print"$extra\n";6171print"</nav>\n";6172}6173}61746175sub git_shortlog_body {6176# uses global variable $project6177my($commitlist,$from,$to,$refs,$extra) =@_;61786179if(not defined$from) {6180my$from=0;6181}6182$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);61836184print"<h3>Commits</h3>";6185print"<table class=\"shortlog\">\n";6186for(my$i=$from;$i<=$to;$i++) {6187my%co= %{$commitlist->[$i]};6188my$commit=$co{'id'};6189my$ref= format_ref_marker($refs,$commit);6190print("<tr>");6191print"<td class=\"age\"title=\"$co{'age_string_age'}\">$co{'age_string_date'}</td>\n".6192"<td class=\"separator\">•</td>".6193 format_author_html('td', \%co,10) ."<td>";6194print format_subject_html($co{'title'},$co{'title_short'},6195 href(action=>"commit", hash=>$commit),$ref);6196print"</td>\n".6197"<td class=\"link\">".6198$cgi->a({-href => href(action=>"diff", hash=>$commit)},"diff") ." | ".6199$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");6200my$snapshot_links= format_snapshot_links($commit);6201if(defined$snapshot_links) {6202print" | ".$snapshot_links;6203}6204print"</td>\n".6205"</tr>\n";6206}6207if(defined$extra) {6208print"<tr>\n".6209"<td colspan=\"4\">$extra</td>\n".6210"</tr>\n";6211}6212print"</table>\n";6213}62146215sub git_history_body {6216# Warning: assumes constant type (blob or tree) during history6217my($commitlist,$from,$to,$refs,$extra,6218$file_name,$file_hash,$ftype) =@_;62196220$from=0unlessdefined$from;6221$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});62226223print"<table class=\"history\">\n";6224my$alternate=1;6225for(my$i=$from;$i<=$to;$i++) {6226my%co= %{$commitlist->[$i]};6227if(!%co) {6228next;6229}6230my$commit=$co{'id'};62316232my$ref= format_ref_marker($refs,$commit);62336234if($alternate) {6235print"<tr class=\"dark\">\n";6236}else{6237print"<tr class=\"light\">\n";6238}6239$alternate^=1;6240print"<td title=\"$co{'age_string_age'}\">$co{'age_string_date'}</td>\n".6241# shortlog: format_author_html('td', \%co, 10)6242 format_author_html('td', \%co,15,3) ."<td>";6243# originally git_history used chop_str($co{'title'}, 50)6244print format_subject_html($co{'title'},$co{'title_short'},6245 href(action=>"commit", hash=>$commit),$ref);6246print"</td>\n".6247"<td class=\"link\">".6248$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".6249$cgi->a({-href => href(action=>"diff", hash=>$commit)},"diff");62506251if($ftypeeq'blob') {6252print" | ".6253$cgi->a({-href => href(action=>"blob_plain", hash_base=>$commit, file_name=>$file_name)},"raw");62546255my$blob_current=$file_hash;6256my$blob_parent= git_get_hash_by_path($commit,$file_name);6257if(defined$blob_current&&defined$blob_parent&&6258$blob_currentne$blob_parent) {6259print" | ".6260$cgi->a({-href => href(action=>"blobdiff",6261 hash=>$blob_current, hash_parent=>$blob_parent,6262 hash_base=>$hash_base, hash_parent_base=>$commit,6263 file_name=>$file_name)},6264"diff to current");6265}6266}6267print"</td>\n".6268"</tr>\n";6269}6270if(defined$extra) {6271print"<tr>\n".6272"<td colspan=\"4\">$extra</td>\n".6273"</tr>\n";6274}6275print"</table>\n";6276}62776278sub git_tags_body {6279# uses global variable $project6280my($taglist,$from,$to,$extra) =@_;6281$from=0unlessdefined$from;6282$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);62836284print"<h3>Tags</h3>";6285print"<table class=\"tags\">\n";6286my$alternate=1;6287for(my$i=$from;$i<=$to;$i++) {6288my$entry=$taglist->[$i];6289my%tag=%$entry;6290my$comment=$tag{'subject'};6291my$comment_short;6292if(defined$comment) {6293$comment_short= chop_str($comment,30,5);6294}6295if($alternate) {6296print"<tr class=\"dark\">\n";6297}else{6298print"<tr class=\"light\">\n";6299}6300$alternate^=1;6301if(defined$tag{'age'}) {6302print"<td>$tag{'age'}</td>\n";6303}else{6304print"<td></td>\n";6305}6306print"<td>".6307$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),6308-class=>"list name"}, esc_html($tag{'name'})) .6309"</td>\n".6310"<td>";6311if(defined$comment) {6312print format_subject_html($comment,$comment_short,6313 href(action=>"tag", hash=>$tag{'id'}));6314}6315print"</td>\n".6316"<td class=\"selflink\">";6317if($tag{'type'}eq"tag") {6318print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");6319}else{6320print" ";6321}6322print"</td>\n".6323"<td class=\"link\">"." | ".6324$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});6325if($tag{'reftype'}eq"commit") {6326print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .6327" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");6328}elsif($tag{'reftype'}eq"blob") {6329print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");6330}6331print"</td>\n".6332"</tr>";6333}6334if(defined$extra) {6335print"<tr>\n".6336"<td colspan=\"5\">$extra</td>\n".6337"</tr>\n";6338}6339print"</table>\n";6340}63416342sub git_heads_body {6343# uses global variable $project6344my($headlist,$head_at,$from,$to,$extra) =@_;6345$from=0unlessdefined$from;6346$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);63476348print"<h3>Branches</h3>";6349print"<table class=\"heads\">\n";6350my$alternate=1;6351for(my$i=$from;$i<=$to;$i++) {6352my$entry=$headlist->[$i];6353my%ref=%$entry;6354my$curr=defined$head_at&&$ref{'id'}eq$head_at;6355if($alternate) {6356print"<tr class=\"dark\">\n";6357}else{6358print"<tr class=\"light\">\n";6359}6360$alternate^=1;6361print"<td>$ref{'age'}</td>\n".6362($curr?"<td class=\"current_head\">":"<td>") .6363$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),6364-class=>"list name"},esc_html($ref{'name'})) .6365"</td>\n".6366"<td class=\"link\">".6367$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".6368$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".6369$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'fullname'})},"tree") .6370"</td>\n".6371"</tr>";6372}6373if(defined$extra&&$extra!="") {6374print"<tr>\n".6375"<td colspan=\"3\">$extra</td>\n".6376"</tr>\n";6377}6378print"</table>\n";6379}63806381# Display a single remote block6382sub git_remote_block {6383my($remote,$rdata,$limit,$head) =@_;63846385my$heads=$rdata->{'heads'};6386my$fetch=$rdata->{'fetch'};6387my$push=$rdata->{'push'};63886389my$urls_table="<table class=\"projects_list\">\n";63906391if(defined$fetch) {6392if($fetcheq$push) {6393$urls_table.= format_repo_url("URL",$fetch);6394}else{6395$urls_table.= format_repo_url("Fetch URL",$fetch);6396$urls_table.= format_repo_url("Push URL",$push)ifdefined$push;6397}6398}elsif(defined$push) {6399$urls_table.= format_repo_url("Push URL",$push);6400}else{6401$urls_table.= format_repo_url("","No remote URL");6402}64036404$urls_table.="</table>\n";64056406my$dots;6407if(defined$limit&&$limit<@$heads) {6408$dots=$cgi->a({-href => href(action=>"remotes", hash=>$remote)},"show all remotes");6409}64106411print$urls_table;6412 git_heads_body($heads,$head,0,$limit,$dots);6413}64146415# Display a list of remote names with the respective fetch and push URLs6416sub git_remotes_list {6417my($remotedata,$limit) =@_;6418print"<table class=\"heads\">\n";6419my$alternate=1;6420my@remotes=sort keys%$remotedata;64216422my$limited=$limit&&$limit<@remotes;64236424$#remotes=$limit-1if$limited;64256426while(my$remote=shift@remotes) {6427my$rdata=$remotedata->{$remote};6428my$fetch=$rdata->{'fetch'};6429my$push=$rdata->{'push'};6430if($alternate) {6431print"<tr class=\"dark\">\n";6432}else{6433print"<tr class=\"light\">\n";6434}6435$alternate^=1;6436print"<td>".6437$cgi->a({-href=> href(action=>'remotes', hash=>$remote),6438-class=>"list name"},esc_html($remote)) .6439"</td>";6440print"<td class=\"link\">".6441(defined$fetch?$cgi->a({-href=>$fetch},"fetch") :"fetch") .6442" | ".6443(defined$push?$cgi->a({-href=>$push},"push") :"push") .6444"</td>";64456446print"</tr>\n";6447}64486449if($limited) {6450print"<tr>\n".6451"<td colspan=\"3\">".6452$cgi->a({-href => href(action=>"remotes")},"show all remotes") .6453"</td>\n"."</tr>\n";6454}64556456print"</table>";6457}64586459# Display remote heads grouped by remote, unless there are too many6460# remotes, in which case we only display the remote names6461sub git_remotes_body {6462my($remotedata,$limit,$head) =@_;6463if($limitand$limit<keys%$remotedata) {6464 git_remotes_list($remotedata,$limit);6465}else{6466 fill_remote_heads($remotedata);6467while(my($remote,$rdata) =each%$remotedata) {6468 git_print_section({-class=>"remote", -id=>$remote},6469["remotes",$remote,$remote],sub{6470 git_remote_block($remote,$rdata,$limit,$head);6471});6472}6473}6474}64756476sub git_search_message {6477my%co=@_;64786479my$greptype;6480if($searchtypeeq'commit') {6481$greptype="--grep=";6482}elsif($searchtypeeq'author') {6483$greptype="--author=";6484}elsif($searchtypeeq'committer') {6485$greptype="--committer=";6486}6487$greptype.=$searchtext;6488my@commitlist= parse_commits($hash,101, (100*$page),undef,6489$greptype,'--regexp-ignore-case',6490$search_use_regexp?'--extended-regexp':'--fixed-strings');64916492my$paging_nav='';6493if($page>0) {6494$paging_nav.=6495$cgi->a({-href => href(-replay=>1, page=>undef)},6496"first") .6497" ⋅ ".6498$cgi->a({-href => href(-replay=>1, page=>$page-1),6499-accesskey =>"p", -title =>"Alt-p"},"prev");6500}else{6501$paging_nav.="first ⋅ prev";6502}6503my$next_link='';6504if($#commitlist>=100) {6505$next_link=6506$cgi->a({-href => href(-replay=>1, page=>$page+1),6507-accesskey =>"n", -title =>"Alt-n"},"next");6508$paging_nav.=" ⋅$next_link";6509}else{6510$paging_nav.=" ⋅ next";6511}65126513 git_header_html();65146515 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);6516 git_print_header_div('commit', esc_html($co{'title'}),$hash);6517if($page==0&& !@commitlist) {6518print"<p>No match.</p>\n";6519}else{6520 git_search_grep_body(\@commitlist,0,99,$next_link);6521}65226523 git_footer_html();6524}65256526sub git_search_changes {6527my%co=@_;65286529local$/="\n";6530open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,6531'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",6532($search_use_regexp?'--pickaxe-regex': ())6533or die_error(500,"Open git-log failed");65346535 git_header_html();65366537 git_print_page_nav('','',$hash,$co{'tree'},$hash);6538 git_print_header_div('commit', esc_html($co{'title'}),$hash);65396540print"<table class=\"pickaxe search\">\n";6541my$alternate=1;6542undef%co;6543my@files;6544while(my$line= <$fd>) {6545chomp$line;6546next unless$line;65476548my%set= parse_difftree_raw_line($line);6549if(defined$set{'commit'}) {6550# finish previous commit6551if(%co) {6552print"</td>\n".6553"<td class=\"link\">".6554$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},6555"commit") .6556" | ".6557$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'},6558 hash_base=>$co{'id'})},6559"tree") .6560"</td>\n".6561"</tr>\n";6562}65636564if($alternate) {6565print"<tr class=\"dark\">\n";6566}else{6567print"<tr class=\"light\">\n";6568}6569$alternate^=1;6570%co= parse_commit($set{'commit'});6571my$author= chop_and_escape_str($co{'author_name'},15,5);6572print"<td title=\"$co{'age_string_age'}\">$co{'age_string_date'}</td>\n".6573"<td>$author</td>\n".6574"<td>".6575$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6576-class=>"list subject"},6577 chop_and_escape_str($co{'title'},50) ."<br/>");6578}elsif(defined$set{'to_id'}) {6579next if is_deleted(\%set);65806581print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},6582 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),6583-class=>"list"},6584"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .6585"<br/>\n";6586}6587}6588close$fd;65896590# finish last commit (warning: repetition!)6591if(%co) {6592print"</td>\n".6593"<td class=\"link\">".6594$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},6595"commit") .6596" | ".6597$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'},6598 hash_base=>$co{'id'})},6599"tree") .6600"</td>\n".6601"</tr>\n";6602}66036604print"</table>\n";66056606 git_footer_html();6607}66086609sub git_search_files {6610my%co=@_;66116612local$/="\n";6613open my$fd,"-|", git_cmd(),'grep','-n','-z',6614$search_use_regexp? ('-E','-i') :'-F',6615$searchtext,$co{'tree'}6616or die_error(500,"Open git-grep failed");66176618 git_header_html();66196620 git_print_page_nav('','',$hash,$co{'tree'},$hash);6621 git_print_header_div('commit', esc_html($co{'title'}),$hash);66226623print"<table class=\"grep_search\">\n";6624my$alternate=1;6625my$matches=0;6626my$lastfile='';6627my$file_href;6628my$in_table=0;6629while(my$line= <$fd>) {6630chomp$line;6631my($file,$lno,$ltext,$binary);6632if($line=~/^Binary file (.+) matches$/) {6633$file=$1;6634$binary=1;6635}else{6636($file,$lno,$ltext) =split(/\0/,$line,3);6637$file=~s/^$co{'tree'}://;6638}6639if($filene$lastfile) {6640if($in_table) {6641print"\t\t</table>\n\t</td>\n</tr>\n";6642$in_table=0;6643}6644if($alternate++) {6645print"<tr class=\"dark\">\n";6646}else{6647print"<tr class=\"light\">\n";6648}6649$file_href= href(action=>"blob", hash_base=>$co{'id'},6650 file_name=>$file);6651print"\t<td class=\"list\">".6652$cgi->a({-href =>$file_href, -class=>"list"}, esc_path($file));6653print"\t</td>\n";6654print"\t<td>\n\t\t<table class=\"grep_lines\">\n";6655$in_table=1;6656$lastfile=$file;6657}6658last if($matches++>1000);6659if($binary) {6660print"\t\t\t<tr>\n\t\t\t\t<td colspan=\"2\"class=\"binary\">Binary file</td>\n\t\t\t</tr>\n";6661}else{6662$ltext= untabify($ltext);6663if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {6664$ltext= esc_html($1, -nbsp=>1);6665$ltext.='<span class="match">';6666$ltext.= esc_html($2, -nbsp=>1);6667$ltext.='</span>';6668$ltext.= esc_html($3, -nbsp=>1);6669}else{6670$ltext= esc_html($ltext, -nbsp=>1);6671}6672print"\t\t\t<tr>\n\t\t\t\t<td>\n\t\t\t\t\t"6673.$cgi->a({-href =>$file_href.'#l'.$lno,6674-class=>"linenr"},sprintf('%4i',$lno)) ."\n\t\t\t\t</td>\n";6675print"\t\t\t\t<td>\n\t\t\t\t\t<pre>$ltext</pre>\n\t\t\t\t</td>\n\t\t\t</tr>\n";6676}6677}6678if($lastfile) {6679if($matches>1000) {6680print"<td colspan=\"3\"><div class=\"diff nodifferences\">Too many matches, listing trimmed</div></td>\n";6681}6682print"</tr>\n</table>\n";6683}else{6684print"<tr><td colspan=\"3\"><div class=\"diff nodifferences\">No matches found</div></td>\n";6685$in_table=0;6686}6687close$fd;66886689if($in_table) {6690print"\t\t</table>\n\t</td>\n";6691$in_table=0;6692}66936694 git_footer_html();6695}66966697sub git_search_grep_body {6698my($commitlist,$from,$to,$extra) =@_;6699$from=0unlessdefined$from;6700$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);67016702print"<table class=\"commit_search\">\n";6703my$alternate=1;6704for(my$i=$from;$i<=$to;$i++) {6705my%co= %{$commitlist->[$i]};6706if(!%co) {6707next;6708}6709my$commit=$co{'id'};6710if($alternate) {6711print"<tr class=\"dark\">\n";6712}else{6713print"<tr class=\"light\">\n";6714}6715$alternate^=1;6716print"<td title=\"$co{'age_string_age'}\">$co{'age_string_date'}</td>\n".6717 format_author_html('td', \%co,15,5) .6718"<td>".6719$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),6720-class=>"list subject"},6721 chop_and_escape_str($co{'title'},50) ."<br/>");6722my$comment=$co{'comment'};6723foreachmy$line(@$comment) {6724if($line=~m/^(.*?)($search_regexp)(.*)$/i) {6725my($lead,$match,$trail) = ($1,$2,$3);6726$match= chop_str($match,70,5,'center');6727my$contextlen=int((80-length($match))/2);6728$contextlen=30if($contextlen>30);6729$lead= chop_str($lead,$contextlen,10,'left');6730$trail= chop_str($trail,$contextlen,10,'right');67316732$lead= esc_html($lead);6733$match= esc_html($match);6734$trail= esc_html($trail);67356736print"$lead<span class=\"match\">$match</span>$trail<br />";6737}6738}6739print"</td>\n".6740"<td class=\"link\">".6741$cgi->a({-href => href(action=>"diff", hash=>$co{'id'})},"diff") .6742" | ".6743$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");6744print"</td>\n".6745"</tr>\n";6746}6747if(defined$extra&&$extra!="") {6748print"<tr>\n".6749"<td colspan=\"3\">$extra</td>\n".6750"</tr>\n";6751}6752print"</table>\n";6753}67546755## ======================================================================6756## ======================================================================6757## actions67586759sub git_project_list {6760my$order=$input_params{'order'};6761if(defined$order&&$order!~m/none|project|descr|owner|age/) {6762 die_error(400,"Unknown order parameter");6763}67646765my@list= git_get_projects_list($project_filter,$strict_export);6766if(!@list) {6767 die_error(404,"No projects found");6768}67696770 git_header_html();6771if(defined$home_text&& -f $home_text) {6772print"<div class=\"index_include\">\n";6773 insert_file($home_text);6774print"</div>\n";6775}67766777 git_project_search_form($searchtext,$search_use_regexp);6778 git_project_list_body(\@list,$order);6779 git_footer_html();6780}67816782sub git_forks {6783my$order=$input_params{'order'};6784if(defined$order&&$order!~m/none|project|descr|owner|age/) {6785 die_error(400,"Unknown order parameter");6786}67876788my$filter=$project;6789$filter=~s/\.git$//;6790my@list= git_get_projects_list($filter);6791if(!@list) {6792 die_error(404,"No forks found");6793}67946795 git_header_html();6796 git_print_page_nav('','');6797 git_print_header_div('summary',"$projectforks");6798 git_project_list_body(\@list,$order);6799 git_footer_html();6800}68016802sub git_project_index {6803my@projects= git_get_projects_list($project_filter,$strict_export);6804if(!@projects) {6805 die_error(404,"No projects found");6806}68076808print$cgi->header(6809-type =>'text/plain',6810-charset =>'utf-8',6811-content_disposition =>'inline; filename="index.aux"');68126813foreachmy$pr(@projects) {6814if(!exists$pr->{'owner'}) {6815$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");6816}68176818my($path,$owner) = ($pr->{'path'},$pr->{'owner'});6819# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '6820$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;6821$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;6822$path=~s/ /\+/g;6823$owner=~s/ /\+/g;68246825print"$path$owner\n";6826}6827}68286829sub git_summary {6830my$descr= git_get_project_description($project) ||"none";6831my%co= parse_commit("HEAD");6832my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();6833my$head=$co{'id'};6834my$remote_heads= gitweb_check_feature('remote_heads');68356836my$owner= git_get_project_owner($project);68376838my$refs= git_get_references();6839# These get_*_list functions return one more to allow us to see if6840# there are more ...6841my@taglist= git_get_tags_list(16);6842my@headlist= git_get_heads_list(16);6843my%remotedata=$remote_heads? git_get_remotes_list() : ();6844my@forklist;6845my$check_forks= gitweb_check_feature('forks');68466847if($check_forks) {6848# find forks of a project6849my$filter=$project;6850$filter=~s/\.git$//;6851@forklist= git_get_projects_list($filter);6852# filter out forks of forks6853@forklist= filter_forks_from_projects_list(\@forklist)6854if(@forklist);6855}68566857 git_header_html();6858 git_print_page_nav('summary','',$head);68596860print"<table class=\"projects_list\">\n".6861"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n";6862if($ownerand not$omit_owner) {6863print"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";6864}6865if(defined$cd{'rfc2822'}) {6866print"<tr id=\"metadata_lchange\"><td>last change</td>".6867"<td>".format_timestamp_html(\%cd)."</td></tr>\n";6868}68696870# use per project git URL list in $projectroot/$project/cloneurl6871# or make project git URL from git base URL and project name6872my$url_tag="URL";6873my@url_list= git_get_project_url_list($project);6874@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;6875foreachmy$git_url(@url_list) {6876next unless$git_url;6877print format_repo_url($url_tag,$git_url);6878$url_tag="";6879}68806881# Tag cloud6882my$show_ctags= gitweb_check_feature('ctags');6883if($show_ctags) {6884my$ctags= git_get_project_ctags($project);6885if(%$ctags) {6886# without ability to add tags, don't show if there are none6887my$cloud= git_populate_project_tagcloud($ctags);6888print"<tr id=\"metadata_ctags\">".6889"<td>content tags</td>".6890"<td>".git_show_project_tagcloud($cloud,48)."</td>".6891"</tr>\n";6892}6893}68946895print"</table>\n";68966897# If XSS prevention is on, we don't include README.html.6898# TODO: Allow a readme in some safe format.6899if(!$prevent_xss) {6900open my$fd,"-|", git_cmd(),"ls-tree","master","--name-only"6901or die_error(500,"Error checking ls_tree for readme");6902my@readme_files=map{chomp;$_} <$fd>;6903close$fd6904or die_error(500,"Error checking ls_tree for readme");6905if(@readme_files) {6906$hash_base||= git_get_head_hash($project);6907foreachmy$readme_file(@readme_files) {6908if($readme_file=~/^readme($|.+)/i&& check_tree_filter($readme_file)) {6909my$hash= git_get_hash_by_path($hash_base,$readme_file)6910or die_error(500,"Error getting hash for readme file$readme_file");6911print"<div class=\"title readme-title\">$readme_file<nav class=\"formats_nav\">";6912print$cgi->a({-href => href(action=>"blob", hash=>$hash)},"source") ." | ";6913print$cgi->a({-href => href(action=>"blob_plain", hash=>$hash)},"raw");6914print"</nav>";6915print"</div>\n".6916"<div class=\"readme\">\n";6917open my$fd,"-|", git_cmd(),"cat-file","blob",$hash6918or die_error(500,"Cat of readme '$hash' failed");6919my$filecontents="";6920while(my$line= <$fd>) {6921$filecontents.=$line;6922}69236924# Process markdown if necessary6925if($readme_file=~/\.md$/i&& check_pandoc()) {6926#$filecontents = pandoc->parse('markdown' => $filecontents)->to_html;6927$filecontents= markdown($filecontents);;6928print($filecontents);6929}6930else{6931print($cgi->escapeHTML($filecontents));6932}69336934close$fd6935or die_error(500,"Error processing readme file$hash");6936print"\n</div>\n";# class="readme"6937last;6938}6939}6940}6941}69426943# we need to request one more than 16 (0..15) to check if6944# those 16 are all6945my@commitlist=$head? parse_commits($head,17) : ();6946if(@commitlist) {6947 git_print_header_div('shortlog');6948 git_shortlog_body(\@commitlist,0,15,$refs,6949$#commitlist<=15?undef:6950$cgi->a({-href => href(action=>"shortlog")},"show all commits"));6951}69526953if(@taglist) {6954 git_print_header_div('tags');6955 git_tags_body(\@taglist,0,15,6956$#taglist<=15?undef:6957$cgi->a({-href => href(action=>"tags")},"show all tags"));6958}69596960if(@headlist) {6961 git_print_header_div('heads');6962 git_heads_body(\@headlist,$head,0,15,6963$#headlist<=15?undef:6964$cgi->a({-href => href(action=>"heads")},"show all branches"));6965}69666967if(%remotedata) {6968 git_print_header_div('remotes');6969 git_remotes_body(\%remotedata,15,$head);6970}69716972if(@forklist) {6973 git_print_header_div('forks');6974 git_project_list_body(\@forklist,'age',0,15,6975$#forklist<=15?undef:6976$cgi->a({-href => href(action=>"forks")},"show all forks"),6977'no_header');6978}69796980 git_footer_html();6981}698269836984# Check if Pandoc module is installed, and import it if it is available.6985# This is a bit hacky, but Pandoc rendering is considered an "optional" 6986# feature, so we need to make sure no errors are thrown if it's not available.6987# Added by Andrew Lorimer, October 201969886989sub check_pandoc {6990eval"use Pandoc; 1"orreturn0;6991return1;6992}69936994sub git_tag {6995my%tag= parse_tag($hash);69966997if(!%tag) {6998 die_error(404,"Unknown tag object");6999}70007001my$head= git_get_head_hash($project);7002 git_header_html();7003 git_print_page_nav('','',$head,undef,$head);7004 git_print_header_div('commit', esc_html($tag{'name'}),$hash);7005print"<div class=\"title_text\">\n".7006"<table class=\"object_header\">\n".7007"<tr>\n".7008"<td>object</td>\n".7009"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},7010$tag{'object'}) ."</td>\n".7011"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},7012$tag{'type'}) ."</td>\n".7013"</tr>\n";7014if(defined($tag{'author'})) {7015 git_print_authorship_rows(\%tag,'author');7016}7017print"</table>\n\n".7018"</div>\n";7019print"<main>";7020my$comment=$tag{'comment'};7021foreachmy$line(@$comment) {7022chomp$line;7023print esc_html($line, -nbsp=>1) ."\n";7024}7025print"</main>\n";7026 git_footer_html();7027}70287029sub git_blame_common {7030my$format=shift||'porcelain';7031if($formateq'porcelain'&&$input_params{'javascript'}) {7032$format='incremental';7033$action='blame_incremental';# for page title etc7034}70357036# permissions7037 gitweb_check_feature('blame')7038or die_error(403,"Blame view not allowed");70397040# error checking7041 die_error(400,"No file name given")unless$file_name;7042$hash_base||= git_get_head_hash($project);7043 die_error(404,"Couldn't find base commit")unless$hash_base;7044my%co= parse_commit($hash_base)7045or die_error(404,"Commit not found");7046my$ftype="blob";7047if(!defined$hash) {7048$hash= git_get_hash_by_path($hash_base,$file_name,"blob")7049or die_error(404,"Error looking up file");7050}else{7051$ftype= git_get_type($hash);7052if($ftype!~"blob") {7053 die_error(400,"Object is not a blob");7054}7055}70567057my$fd;7058if($formateq'incremental') {7059# get file contents (as base)7060open$fd,"-|", git_cmd(),'cat-file','blob',$hash7061or die_error(500,"Open git-cat-file failed");7062}elsif($formateq'data') {7063# run git-blame --incremental7064open$fd,"-|", git_cmd(),"blame","--incremental",7065$hash_base,"--",$file_name7066or die_error(500,"Open git-blame --incremental failed");7067}else{7068# run git-blame --porcelain7069open$fd,"-|", git_cmd(),"blame",'-p',7070$hash_base,'--',$file_name7071or die_error(500,"Open git-blame --porcelain failed");7072}7073binmode$fd,':utf8';70747075# incremental blame data returns early7076if($formateq'data') {7077print$cgi->header(7078-type=>"text/plain", -charset =>"utf-8",7079-status=>"200 OK");7080local$| =1;# output autoflush7081while(my$line= <$fd>) {7082print to_utf8($line);7083}7084close$fd7085or print"ERROR$!\n";70867087print'END';7088if(defined$t0&& gitweb_check_feature('timed')) {7089print' '.7090 tv_interval($t0, [ gettimeofday() ]).7091' '.$number_of_git_cmds;7092}7093print"\n";70947095return;7096}70977098# page header7099 git_header_html();7100my$formats_nav=7101$cgi->a({-href => href(action=>"blob", -replay=>1)},7102"blob") .7103" | ";7104if($formateq'incremental') {7105$formats_nav.=7106$cgi->a({-href => href(action=>"blame", javascript=>0, -replay=>1)},7107"blame") ." (non-incremental)";7108}else{7109$formats_nav.=7110$cgi->a({-href => href(action=>"blame_incremental", -replay=>1)},7111"blame") ." (incremental)";7112}7113$formats_nav.=7114" | ".7115$cgi->a({-href => href(action=>"history", -replay=>1)},7116"history") .7117" | ".7118$cgi->a({-href => href(action=>$action, file_name=>$file_name)},7119"HEAD");7120 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);7121 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);7122 git_print_page_path($file_name,$ftype,$hash_base);71237124# page body7125if($formateq'incremental') {7126print"<noscript>\n<div class=\"error\"><center><b>\n".7127"This page requires JavaScript to run.\nUse ".7128$cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},7129'this page').7130" instead.\n".7131"</b></center></div>\n</noscript>\n";71327133print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!;7134}71357136print qq!<div id="progress_info">.../ ...</div>\n!7137if($formateq'incremental');7138print qq!<table id="blame_table"class="blame" width="100%">\n!.7139#qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.7140 qq!<thead>\n!.7141 qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!.7142 qq!</thead>\n!.7143 qq!<tbody>\n!;71447145my@rev_color=qw(light dark);7146my$num_colors=scalar(@rev_color);7147my$current_color=0;71487149if($formateq'incremental') {7150my$color_class=$rev_color[$current_color];71517152#contents of a file7153my$linenr=0;7154 LINE:7155while(my$line= <$fd>) {7156chomp$line;7157$linenr++;71587159print qq!<tr id="l$linenr"class="$color_class">!.7160 qq!<td class="sha1"><a href=""> </a></td>!.7161 qq!<td class="linenr">!.7162 qq!<a class="linenr" href="">$linenr</a></td>!;7163print qq!<td class="pre">! . esc_html($line) ."</td>\n";7164print qq!</tr>\n!;7165}71667167}else{# porcelain, i.e. ordinary blame7168my%metainfo= ();# saves information about commits71697170# blame data7171 LINE:7172while(my$line= <$fd>) {7173chomp$line;7174# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]7175# no <lines in group> for subsequent lines in group of lines7176my($full_rev,$orig_lineno,$lineno,$group_size) =7177($line=~/^($oid_regex) (\d+) (\d+)(?: (\d+))?$/);7178if(!exists$metainfo{$full_rev}) {7179$metainfo{$full_rev} = {'nprevious'=>0};7180}7181my$meta=$metainfo{$full_rev};7182my$data;7183while($data= <$fd>) {7184chomp$data;7185last if($data=~s/^\t//);# contents of line7186if($data=~/^(\S+)(?: (.*))?$/) {7187$meta->{$1} =$2unlessexists$meta->{$1};7188}7189if($data=~/^previous /) {7190$meta->{'nprevious'}++;7191}7192}7193my$short_rev=substr($full_rev,0,8);7194my$author=$meta->{'author'};7195my%date=7196 parse_date($meta->{'author-time'},$meta->{'author-tz'});7197my$date=$date{'iso-tz'};7198if($group_size) {7199$current_color= ($current_color+1) %$num_colors;7200}7201my$tr_class=$rev_color[$current_color];7202$tr_class.=' boundary'if(exists$meta->{'boundary'});7203$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);7204$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);7205print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";7206if($group_size) {7207print"<td class=\"sha1\"";7208print" title=\"". esc_html($author) .",$date\"";7209print" rowspan=\"$group_size\""if($group_size>1);7210print">";7211print$cgi->a({-href => href(action=>"commit",7212 hash=>$full_rev,7213 file_name=>$file_name)},7214 esc_html($short_rev));7215if($group_size>=2) {7216my@author_initials= ($author=~/\b([[:upper:]])\B/g);7217if(@author_initials) {7218print"<br />".7219 esc_html(join('',@author_initials));7220# or join('.', ...)7221}7222}7223print"</td>\n";7224}7225# 'previous' <sha1 of parent commit> <filename at commit>7226if(exists$meta->{'previous'} &&7227$meta->{'previous'} =~/^($oid_regex) (.*)$/) {7228$meta->{'parent'} =$1;7229$meta->{'file_parent'} = unquote($2);7230}7231my$linenr_commit=7232exists($meta->{'parent'}) ?7233$meta->{'parent'} :$full_rev;7234my$linenr_filename=7235exists($meta->{'file_parent'}) ?7236$meta->{'file_parent'} : unquote($meta->{'filename'});7237my$blamed= href(action =>'blame',7238 file_name =>$linenr_filename,7239 hash_base =>$linenr_commit);7240print"<td class=\"linenr\">";7241print$cgi->a({ -href =>"$blamed#l$orig_lineno",7242-class=>"linenr"},7243 esc_html($lineno));7244print"</td>";7245print"<td class=\"pre\">". esc_html($data) ."</td>\n";7246print"</tr>\n";7247}# end while72487249}72507251# footer7252print"</tbody>\n".7253"</table>\n";# class="blame"7254print"</div>\n";# class="blame_body"7255close$fd7256or print"Reading blob failed\n";72577258 git_footer_html();7259}72607261sub git_blame {7262 git_blame_common();7263}72647265sub git_blame_incremental {7266 git_blame_common('incremental');7267}72687269sub git_blame_data {7270 git_blame_common('data');7271}72727273sub git_tags {7274my$head= git_get_head_hash($project);7275 git_header_html();7276 git_print_page_nav('','',$head,undef,$head,format_ref_views('tags'));7277 git_print_header_div('summary',$project);72787279my@tagslist= git_get_tags_list();7280if(@tagslist) {7281 git_tags_body(\@tagslist);7282}7283 git_footer_html();7284}72857286sub git_heads {7287my$head= git_get_head_hash($project);7288 git_header_html();7289 git_print_page_nav('','',$head,undef,$head,format_ref_views('heads'));7290 git_print_header_div('summary',$project);72917292my@headslist= git_get_heads_list();7293if(@headslist) {7294 git_heads_body(\@headslist,$head);7295}7296 git_footer_html();7297}72987299# used both for single remote view and for list of all the remotes7300sub git_remotes {7301 gitweb_check_feature('remote_heads')7302or die_error(403,"Remote heads view is disabled");73037304my$head= git_get_head_hash($project);7305my$remote=$input_params{'hash'};73067307my$remotedata= git_get_remotes_list($remote);7308 die_error(500,"Unable to get remote information")unlessdefined$remotedata;73097310unless(%$remotedata) {7311 die_error(404,defined$remote?7312"Remote$remotenot found":7313"No remotes found");7314}73157316 git_header_html(undef,undef, -action_extra =>$remote);7317 git_print_page_nav('','',$head,undef,$head,7318 format_ref_views($remote?'':'remotes'));73197320 fill_remote_heads($remotedata);7321if(defined$remote) {7322 git_print_header_div('remotes',"$remoteremote for$project");7323 git_remote_block($remote,$remotedata->{$remote},undef,$head);7324}else{7325 git_print_header_div('summary',"$projectremotes");7326 git_remotes_body($remotedata,undef,$head);7327}73287329 git_footer_html();7330}73317332sub git_blob_plain {7333my$type=shift;7334my$expires;73357336my$base=$hash_base|| git_get_head_hash($project);7337if(!defined$hash) {7338if(defined$file_name) {7339$hash= git_get_hash_by_path($base,$file_name,"blob")7340or die_error(404,"Cannot find file");7341}else{7342 die_error(400,"No file name defined");7343}7344}elsif($hash=~m/^$oid_regex$/) {7345$file_name= git_get_path_by_hash($base,$hash);7346# blobs defined by non-textual hash id's can be cached7347$expires="+1d";7348}7349if(! check_tree_filter($file_name)) {7350 die_error(403,"Access denied ($file_name)");7351}73527353open my$fd,"-|", git_cmd(),"cat-file","blob",$hash7354or die_error(500,"Open git-cat-file blob '$hash' failed");73557356# content-type (can include charset)7357$type= blob_contenttype($fd,$file_name,$type);73587359# "save as" filename, even when no $file_name is given7360my$save_as="$hash";7361if(defined$file_name) {7362$save_as=$file_name;7363}elsif($type=~m/^text\//) {7364$save_as.='.txt';7365}73667367# With XSS prevention on, blobs of all types except a few known safe7368# ones are served with "Content-Disposition: attachment" to make sure7369# they don't run in our security domain. For certain image types,7370# blob view writes an <img> tag referring to blob_plain view, and we7371# want to be sure not to break that by serving the image as an7372# attachment (though Firefox 3 doesn't seem to care).7373my$sandbox=$prevent_xss&&7374$type!~m!^(?:text/[a-z]+|image/(?:gif|png|jpeg))(?:[ ;]|$)!;73757376# serve text/* as text/plain7377if($prevent_xss&&7378($type=~m!^text/[a-z]+\b(.*)$!||7379($type=~m!^[a-z]+/[a-z]\+xml\b(.*)$!&& -T $fd))) {7380my$rest=$1;7381$rest=defined$rest?$rest:'';7382$type="text/plain$rest";7383}73847385print$cgi->header(7386-type =>$type,7387-expires =>$expires,7388-content_disposition =>7389($sandbox?'attachment':'inline')7390.'; filename="'.$save_as.'"');7391local$/=undef;7392binmode STDOUT,':raw';7393print<$fd>;7394binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi7395close$fd;7396}73977398sub git_blob {7399my$expires;74007401my$base=$hash_base|| git_get_head_hash($project);7402if(!defined$hash) {7403if(defined$file_name) {7404$hash= git_get_hash_by_path($base,$file_name,"blob")7405or die_error(404,"Cannot find file");7406}else{7407 die_error(400,"No file name defined");7408}7409}elsif($hash=~m/^$oid_regex$/) {7410$file_name= git_get_path_by_hash($base,$hash);7411# blobs defined by non-textual hash id's can be cached7412$expires="+1d";7413}7414if(! check_tree_filter($file_name)) {7415 die_error(403,"Access denied ($file_name)");7416}74177418my$have_blame= gitweb_check_feature('blame');7419open my$fd,"-|", git_cmd(),"cat-file","blob",$hash7420or die_error(500,"Couldn't cat$file_name,$hash");7421my$mimetype= blob_mimetype($fd,$file_name);7422# use 'blob_plain' (aka 'raw') view for files that cannot be displayed7423if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {7424close$fd;7425return git_blob_plain($mimetype);7426}7427# we can have blame only for text/* mimetype7428$have_blame&&= ($mimetype=~m!^text/!);74297430my$highlight= gitweb_check_feature('highlight');7431my$syntax= guess_file_syntax($highlight,$file_name);7432$fd= run_highlighter($fd,$highlight,$syntax);74337434 git_header_html(undef,$expires);7435my$formats_nav='';7436if(defined$hash_base&& (my%co= parse_commit($hash_base))) {7437if(defined$file_name) {7438if($have_blame) {7439$formats_nav.=7440$cgi->a({-href => href(action=>"blame", -replay=>1)},7441"blame") .7442" | ";7443}7444$formats_nav.=7445$cgi->a({-href => href(action=>"history", -replay=>1)},7446"history") .7447" | ".7448$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},7449"raw") .7450" | ".7451$cgi->a({-href => href(action=>"blob",7452 hash_base=>"HEAD", file_name=>$file_name)},7453"HEAD");7454}else{7455$formats_nav.=7456$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},7457"raw");7458}7459 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base);7460print"<div class=\"header\">\n";7461print git_path_header($file_name,"blob",$hash_base,1, esc_html($co{'title'}),$co{'id'},$co{'id'});7462print"</div>"7463}else{7464print"<nav>\n".7465"</nav>\n".7466"<div class=\"title\">".esc_html($hash)."</div>\n";7467}7468print"<nav class=\"formats_nav\">".$formats_nav."</nav>";74697470if($mimetype=~m!^image/!) {7471my$img_src= href(action=>"blob_plain", hash=>$hash,7472 hash_base=>$hash_base, file_name=>$file_name);7473print qq!<a href="$img_src"><img class="blob" type="!.esc_attr($mimetype).qq!"!;7474if($file_name) {7475print qq! alt="!.esc_attr($file_name).qq!" title="!.esc_attr($file_name).qq!"!;7476}7477print qq! src="! .$img_src. qq!"/></a>\n!;7478}else{7479my$nr;7480print"<pre class=\"tree_lines\">";7481while(my$line= <$fd>) {7482chomp$line;7483$nr++;7484# $line = untabify($line);7485printf qq!<span class="tree_line"><a id="l%i" href="%s#l%i"class="linenr">%4i</a><code>%s</code></span>\n!,7486$nr, esc_attr(href(-replay =>1)),$nr,$nr,7487$highlight? sanitize($line) : esc_html($line, -nbsp=>1);7488}7489print"</pre>";7490}7491close$fd7492or print"Reading blob failed.\n";7493 git_footer_html();7494}74957496sub git_tree {7497if(!defined$hash_base) {7498$hash_base="HEAD";7499}7500if(!defined$hash) {7501if(defined$file_name) {7502$hash= git_get_hash_by_path($hash_base,$file_name,"tree");7503}else{7504$hash=$hash_base;7505}7506}7507 die_error(404,"No such tree")unlessdefined($hash);75087509my$show_sizes= gitweb_check_feature('show-sizes');7510my$have_blame= gitweb_check_feature('blame');75117512my@entries= ();7513{7514local$/="\0";7515open my$fd,"-|", git_cmd(),"ls-tree",'-z',7516($show_sizes?'-l': ()),@extra_options,$hash7517or die_error(500,"Open git-ls-tree failed");7518@entries=map{chomp;$_} <$fd>;7519close$fd7520or die_error(404,"Reading tree failed");7521}75227523my$refs= git_get_references();7524my$ref= format_ref_marker($refs,$hash_base);7525 git_header_html();7526my$basedir='';7527if(defined$hash_base&& (my%co= parse_commit($hash_base))) {7528my@views_nav= ();7529if(defined$file_name) {7530push@views_nav,7531$cgi->a({-href => href(action=>"history", -replay=>1)},7532"history"),7533$cgi->a({-href => href(action=>"tree",7534 hash_base=>"HEAD", file_name=>$file_name)},7535"HEAD"),7536}7537my$snapshot_links= format_snapshot_links($hash);7538if(defined$snapshot_links) {7539# FIXME: Should be available when we have no hash base as well.7540push@views_nav,$snapshot_links;7541}7542 git_print_page_nav('tree','',$hash_base,undef,undef);7543if(scalar(@views_nav) >0) {7544print"<nav class=\"formats_nav\">".join(' | ',@views_nav) ."</nav>";7545}7546unless($hash_baseeq"HEAD") {7547 git_print_header_div('commit', esc_html($co{'title'}),$ref,$hash_base);7548}7549}else{7550undef$hash_base;7551print"<nav>\n";7552print"</nav>".esc_html($hash)."</div>\n";7553}7554if(defined$file_name) {7555$basedir=$file_name;7556if($basedirne''&&substr($basedir, -1)ne'/') {7557$basedir.='/';7558}7559 git_print_page_path($file_name,'tree',$hash_base);7560}7561print"<table class=\"tree\">\n";7562# '..' (top directory) link if possible7563if(defined$hash_base&&7564defined$file_name&&$file_name=~m![^/]+$!) {7565print"<tr>\n";7566my$up=$file_name;7567#$up =~ s!/?[^/]+$!!;7568$up=~s/.(?<=(\/|^.))[^\/]*\/?$//;7569#if ($up eq "") {7570# $hash_base .= ":";7571#}7572# based on git_print_tree_entry7573print'<td class="mode">';7574print'<svg width="14" height="14" '7575.'xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">'7576.'<use xlink:href="#parenticon" /></svg>';7577print mode_str('040000') ."</td>\n";7578print'<td class="size"> </td>'."\n"if$show_sizes;7579print'<td class="list">';7580print$cgi->a({-href => href(action=>"tree",7581 hash_base=>$hash_base,7582 file_name=>$up)},7583"parent (dest:$up; base:$hash_base)");7584print"</td>\n";7585print"<td class=\"link\"></td>\n";75867587print"</tr>\n";7588}7589foreachmy$line(@entries) {7590my$t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);7591if(check_tree_filter($t->{'name'})) {7592print"<tr>\n";7593 git_print_tree_entry($t,$basedir,$hash_base,$have_blame);7594print"</tr>\n";7595}7596}7597print"</table>\n";7598 git_footer_html();7599}76007601sub sanitize_for_filename {7602my$name=shift;76037604$name=~s!/!-!g;7605$name=~s/[^[:alnum:]_.-]//g;76067607return$name;7608}76097610sub snapshot_name {7611my($project,$hash) =@_;76127613# path/to/project.git -> project7614# path/to/project/.git -> project7615my$name= to_utf8($project);7616$name=~ s,([^/])/*\.git$,$1,;7617$name= sanitize_for_filename(basename($name));76187619my$ver=$hash;7620if($hash=~/^[0-9a-fA-F]+$/) {7621# shorten SHA-1 hash7622my$full_hash= git_get_full_hash($project,$hash);7623if($full_hash=~/^$hash/&&length($hash) >7) {7624$ver= git_get_short_hash($project,$hash);7625}7626}elsif($hash=~m!^refs/tags/(.*)$!) {7627# tags don't need shortened SHA-1 hash7628$ver=$1;7629}else{7630# branches and other need shortened SHA-1 hash7631my$strip_refs=join'|',map{quotemeta} get_branch_refs();7632if($hash=~m!^refs/($strip_refs|remotes)/(.*)$!) {7633my$ref_dir= (defined$1) ?$1:'';7634$ver=$2;76357636$ref_dir= sanitize_for_filename($ref_dir);7637# for refs neither in heads nor remotes we want to7638# add a ref dir to archive name7639if($ref_dirne''and$ref_dirne'heads'and$ref_dirne'remotes') {7640$ver=$ref_dir.'-'.$ver;7641}7642}7643$ver.='-'. git_get_short_hash($project,$hash);7644}7645# special case of sanitization for filename - we change7646# slashes to dots instead of dashes7647# in case of hierarchical branch names7648$ver=~s!/!.!g;7649$ver=~s/[^[:alnum:]_.-]//g;76507651# name = project-version_string7652$name="$name-$ver";76537654returnwantarray? ($name,$name) :$name;7655}76567657sub exit_if_unmodified_since {7658my($latest_epoch) =@_;7659our$cgi;76607661my$if_modified=$cgi->http('IF_MODIFIED_SINCE');7662if(defined$if_modified) {7663my$since;7664if(eval{require HTTP::Date;1; }) {7665$since= HTTP::Date::str2time($if_modified);7666}elsif(eval{require Time::ParseDate;1; }) {7667$since= Time::ParseDate::parsedate($if_modified, GMT =>1);7668}7669if(defined$since&&$latest_epoch<=$since) {7670my%latest_date= parse_date($latest_epoch);7671print$cgi->header(7672-last_modified =>$latest_date{'rfc2822'},7673-status =>'304 Not Modified');7674goto DONE_GITWEB;7675}7676}7677}76787679sub git_snapshot {7680my$format=$input_params{'snapshot_format'};7681if(!@snapshot_fmts) {7682 die_error(403,"Snapshots not allowed");7683}7684# default to first supported snapshot format7685$format||=$snapshot_fmts[0];7686if($format!~m/^[a-z0-9]+$/) {7687 die_error(400,"Invalid snapshot format parameter");7688}elsif(!exists($known_snapshot_formats{$format})) {7689 die_error(400,"Unknown snapshot format");7690}elsif($known_snapshot_formats{$format}{'disabled'}) {7691 die_error(403,"Snapshot format not allowed");7692}elsif(!grep($_eq$format,@snapshot_fmts)) {7693 die_error(403,"Unsupported snapshot format");7694}76957696my$type= git_get_type("$hash^{}");7697if(!$type) {7698 die_error(404,'Object does not exist');7699}elsif($typeeq'blob') {7700 die_error(400,'Object is not a tree-ish');7701}77027703my($name,$prefix) = snapshot_name($project,$hash);7704my$filename="$name$known_snapshot_formats{$format}{'suffix'}";77057706my%co= parse_commit($hash);7707 exit_if_unmodified_since($co{'committer_epoch'})if%co;77087709my$cmd= quote_command(7710 git_cmd(),'archive',7711"--format=$known_snapshot_formats{$format}{'format'}",7712"--prefix=$prefix/",$hash);7713if(exists$known_snapshot_formats{$format}{'compressor'}) {7714$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});7715}77167717$filename=~s/(["\\])/\\$1/g;7718my%latest_date;7719if(%co) {7720%latest_date= parse_date($co{'committer_epoch'},$co{'committer_tz'});7721}77227723print$cgi->header(7724-type =>$known_snapshot_formats{$format}{'type'},7725-content_disposition =>'inline; filename="'.$filename.'"',7726%co? (-last_modified =>$latest_date{'rfc2822'}) : (),7727-status =>'200 OK');77287729open my$fd,"-|",$cmd7730or die_error(500,"Execute git-archive failed");7731binmode STDOUT,':raw';7732print<$fd>;7733binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi7734close$fd;7735}77367737sub git_log_generic {7738my($fmt_name,$body_subr,$base,$parent,$file_name,$file_hash) =@_;77397740my$head= git_get_head_hash($project);7741if(!defined$base) {7742$base=$head;7743}7744if(!defined$page) {7745$page=0;7746}7747my$refs= git_get_references();77487749my$commit_hash=$base;7750if(defined$parent) {7751$commit_hash="$parent..$base";7752}7753my@commitlist=7754 parse_commits($commit_hash,101, (100*$page),7755defined$file_name? ($file_name,"--full-history") : ());77567757my$ftype;7758if(!defined$file_hash&&defined$file_name) {7759# some commits could have deleted file in question,7760# and not have it in tree, but one of them has to have it7761for(my$i=0;$i<@commitlist;$i++) {7762$file_hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);7763last ifdefined$file_hash;7764}7765}7766if(defined$file_hash) {7767$ftype= git_get_type($file_hash);7768}7769if(defined$file_name&& !defined$ftype) {7770 die_error(500,"Unknown type of object");7771}7772my%co;7773if(defined$file_name) {7774%co= parse_commit($base)7775or die_error(404,"Unknown commit object");7776}777777787779my$paging_nav= format_paging_nav($fmt_name,$page,$#commitlist>=100);7780my$next_link='';7781if($#commitlist>=100) {7782$next_link=7783$cgi->a({-href => href(-replay=>1, page=>$page+1),7784-accesskey =>"n", -title =>"Alt-n"},"next");7785}7786my$patch_max= gitweb_get_feature('patches');7787if($patch_max&& !defined$file_name) {7788if($patch_max<0||@commitlist<=$patch_max) {7789$paging_nav.=" ⋅ ".7790$cgi->a({-href => href(action=>"patches", -replay=>1)},7791"patches");7792}7793}77947795 git_header_html();7796 git_print_page_nav($fmt_name,'',$hash,$hash,$hash,$paging_nav);7797if(defined$file_name) {7798 git_print_header_div('commit', esc_html($co{'title'}),$base);7799}else{7800 git_print_header_div('summary',$project)7801}7802 git_print_page_path($file_name,$ftype,$hash_base)7803if(defined$file_name);78047805$body_subr->(\@commitlist,0,99,$refs,$next_link,7806$file_name,$file_hash,$ftype);78077808 git_footer_html();7809}78107811sub git_log {7812 git_log_generic('log', \&git_log_body,7813$hash,$hash_parent);7814}78157816sub git_commit {7817$hash||=$hash_base||"HEAD";7818my%co= parse_commit($hash)7819or die_error(404,"Unknown commit object");78207821my$parent=$co{'parent'};7822my$parents=$co{'parents'};# listref78237824# we need to prepare $formats_nav before any parameter munging7825my$formats_nav;7826if(!defined$parent) {7827# --root diff7828$formats_nav.='(initial)';7829}elsif(@$parents==1) {7830# single parent commit7831$formats_nav.=7832'(parent: '.7833$cgi->a({-href => href(action=>"commit",7834 hash=>$parent)},7835 esc_html(substr($parent,0,$hash_char))) .7836')';7837}else{7838# merge commit7839$formats_nav.=7840'(merge: '.7841join(' ',map{7842$cgi->a({-href => href(action=>"commit",7843 hash=>$_)},7844 esc_html(substr($_,0,$hash_char)));7845}@$parents) .7846')';7847}7848if(gitweb_check_feature('patches') &&@$parents<=1) {7849$formats_nav.=" | ".7850$cgi->a({-href => href(action=>"patch", -replay=>1)},7851"patch");7852}78537854if(!defined$parent) {7855$parent="--root";7856}7857my@difftree;7858open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",7859@diff_opts,7860(@$parents<=1?$parent:'-c'),7861$hash,"--"7862or die_error(500,"Open git-diff-tree failed");7863@difftree=map{chomp;$_} <$fd>;7864close$fdor die_error(404,"Reading git-diff-tree failed");78657866# non-textual hash id's can be cached7867my$expires;7868if($hash=~m/^$oid_regex$/) {7869$expires="+1d";7870}7871my$refs= git_get_references();7872my$ref= format_ref_marker($refs,$co{'id'});78737874 git_header_html(undef,$expires);7875 git_print_page_nav('commit','',7876$hash,$co{'tree'},$hash);78777878if(defined$co{'parent'}) {7879 git_print_header_div('diff', esc_html($co{'title'}),$ref,$hash);7880}else{7881 git_print_header_div('tree', esc_html($co{'title'}),$ref,$co{'tree'},$hash);7882}7883print"<div class=\"title_text\">\n".7884"<table class=\"object_header\">\n";7885 git_print_authorship_rows(\%co);7886print"<tr><th>commit</th><td class=\"sha1\">". truncate_hash($co{'id'})7887."</td></tr>\n";7888print"<tr>".7889"<th>tree</th>".7890"<td class=\"sha1\">".7891 truncate_hash($co{'tree'},"tree_hash", href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)) .7892" (".$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},7893"tree");7894my$snapshot_links= format_snapshot_links($hash);7895if(defined$snapshot_links) {7896print" | ".$snapshot_links;7897}7898print")</td>".7899"</tr>\n";79007901foreachmy$par(@$parents) {7902print"<tr>".7903"<th>parent</th>".7904"<td class=\"sha1\">".7905 truncate_hash($par,"parent_hash", href(action=>"commit", hash=>$par)) .7906" (".7907$cgi->a({-href => href(action=>"diff", hash=>$hash, hash_parent=>$par)},"diff") .7908")</td>".7909"</tr>\n";7910}7911print"</table>".7912"</div>\n";7913print"<nav class=\"formats_nav\">$formats_nav</nav>";79147915 git_difftree_body(\@difftree,$hash,@$parents);79167917 git_footer_html();7918}79197920sub truncate_hash {7921# Truncate an SHA1 hash into HTML code tags & add link7922my($value,$elem_id,$href) =@_;7923my$truncated= (defined$elem_id?"<span id=\"$elem_id\">":"<span>");7924my$span_content="<code>". esc_html(substr($value,0,$hash_char))7925."</code><code class=\"ellipsis\">...</code><code class=\"spoiler\">"7926. esc_html(substr($value,$hash_char+1))7927."</code>";7928if(defined$href) {7929$truncated.=$cgi->a({-href =>$href, -class=>"list"},$span_content);7930}else{7931$truncated.=$span_content;7932}7933$truncated.= (defined$elem_id? copy_svg($elem_id) :"") ."</span>";7934return$truncated;7935}79367937sub copy_svg {7938# Return an HTML string containing an SVG button to copy the content of 7939# an element to the clipboard.7940my($elem_id) =@_;7941return"<svg width=\"14\"height=\"14\"xmlns=\"http://www.w3.org/2000/svg\""7942."xmlns:xlink=\"http://www.w3.org/1999/xlink\"class=\"copyicon\""7943."onclick=\"clipboardCopy('$elem_id');\">"7944."<title>copy hash to clipboard</title>"7945."<use xlink:href=\"#copyicon\"/></svg>";7946}79477948sub git_object {7949# object is defined by:7950# - hash or hash_base alone7951# - hash_base and file_name7952my$type;79537954# - hash or hash_base alone7955if($hash|| ($hash_base&& !defined$file_name)) {7956my$object_id=$hash||$hash_base;79577958open my$fd,"-|", quote_command(7959 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'7960or die_error(404,"Object does not exist");7961$type= <$fd>;7962defined$type&&chomp$type;7963close$fd7964or die_error(404,"Object does not exist");79657966# - hash_base and file_name7967}elsif($hash_base&&defined$file_name) {7968$file_name=~ s,/+$,,;79697970system(git_cmd(),"cat-file",'-e',$hash_base) ==07971or die_error(404,"Base object does not exist");79727973# here errors should not happen7974open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name7975or die_error(500,"Open git-ls-tree failed");7976my$line= <$fd>;7977close$fd;79787979#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'7980unless($line&&$line=~m/^([0-9]+) (.+) ($oid_regex)\t/) {7981 die_error(404,"File or directory for given base does not exist");7982}7983$type=$2;7984$hash=$3;7985}else{7986 die_error(400,"Not enough information to find object");7987}79887989print$cgi->redirect(-uri => href(action=>$type, -full=>1,7990 hash=>$hash, hash_base=>$hash_base,7991 file_name=>$file_name),7992-status =>'302 Found');7993}79947995sub git_blobdiff {7996my$format=shift||'html';7997my$diff_style=$input_params{'diff_style'} ||'inline';79987999my$fd;8000my@difftree;8001my%diffinfo;8002my$expires;80038004# preparing $fd and %diffinfo for git_patchset_body8005# new style URI8006if(defined$hash_base&&defined$hash_parent_base) {8007if(defined$file_name) {8008# read raw output8009open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,8010$hash_parent_base,$hash_base,8011"--", (defined$file_parent?$file_parent: ()),$file_name8012or die_error(500,"Open git-diff-tree failed");8013@difftree=map{chomp;$_} <$fd>;8014close$fd8015or die_error(404,"Reading git-diff-tree failed");8016@difftree8017or die_error(404,"Blob diff not found");80188019}elsif(defined$hash&&8020$hash=~$oid_regex) {8021# try to find filename from $hash80228023# read filtered raw output8024open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,8025$hash_parent_base,$hash_base,"--"8026or die_error(500,"Open git-diff-tree failed");8027@difftree=8028# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'8029# $hash == to_id8030grep{/^:[0-7]{6} [0-7]{6} $oid_regex $hash/}8031map{chomp;$_} <$fd>;8032close$fd8033or die_error(404,"Reading git-diff-tree failed");8034@difftree8035or die_error(404,"Blob diff not found");80368037}else{8038 die_error(400,"Missing one of the blob diff parameters");8039}80408041if(@difftree>1) {8042 die_error(400,"Ambiguous blob diff specification");8043}80448045%diffinfo= parse_difftree_raw_line($difftree[0]);8046$file_parent||=$diffinfo{'from_file'} ||$file_name;8047$file_name||=$diffinfo{'to_file'};80488049$hash_parent||=$diffinfo{'from_id'};8050$hash||=$diffinfo{'to_id'};80518052# non-textual hash id's can be cached8053if($hash_base=~m/^$oid_regex$/&&8054$hash_parent_base=~m/^$oid_regex$/) {8055$expires='+1d';8056}80578058# open patch output8059open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,8060'-p', ($formateq'html'?"--full-index": ()),8061$hash_parent_base,$hash_base,8062"--", (defined$file_parent?$file_parent: ()),$file_name8063or die_error(500,"Open git-diff-tree failed");8064}80658066# old/legacy style URI -- not generated anymore since 1.4.3.8067if(!%diffinfo) {8068 die_error('404 Not Found',"Missing one of the blob diff parameters")8069}80708071# header8072if($formateq'html') {8073my$formats_nav=8074$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},8075"raw");8076$formats_nav.= diff_style_nav($diff_style);8077 git_header_html(undef,$expires);8078if(defined$hash_base&& (my%co= parse_commit($hash_base))) {8079 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base);8080 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);8081}else{8082print"<div class=\"title\">".esc_html("$hashvs$hash_parent")."</div>\n";8083}8084if(defined$file_name) {8085 git_print_page_path($file_name,"blob",$hash_base);8086}else{8087print"<div class=\"page_path\"></div>\n";8088}80898090}elsif($formateq'plain') {8091print$cgi->header(8092-type =>'text/plain',8093-charset =>'utf-8',8094-expires =>$expires,8095-content_disposition =>'inline; filename="'."$file_name".'.patch"');80968097print"X-Git-Url: ".$cgi->self_url() ."\n\n";80988099}else{8100 die_error(400,"Unknown blobdiff format");8101}81028103# patch8104if($formateq'html') {8105 git_patchset_body($fd,$diff_style,8106[ \%diffinfo],$hash_base,$hash_parent_base);8107close$fd;81088109 git_footer_html();81108111}else{8112while(my$line= <$fd>) {8113$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;8114$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;81158116print$line;81178118last if$line=~m!^\+\+\+!;8119}8120local$/=undef;8121print<$fd>;8122close$fd;8123}8124}81258126sub git_blobdiff_plain {8127 git_blobdiff('plain');8128}81298130# assumes that it is added as later part of already existing navigation,8131# so it returns "| foo | bar" rather than just "foo | bar"8132sub diff_style_nav {8133my($diff_style,$is_combined) =@_;8134$diff_style||='inline';81358136return""if($is_combined);81378138my@styles= (inline =>'inline','sidebyside'=>'side by side');8139my%styles=@styles;8140@styles=8141@styles[map{$_*2}0..$#styles/2];81428143returnjoin'',8144map{" | ".$_}8145map{8146$_eq$diff_style?$styles{$_} :8147$cgi->a({-href => href(-replay=>1, diff_style =>$_)},$styles{$_})8148}@styles;8149}81508151sub git_diff {8152my%params=@_;8153my$format=$params{-format} ||'html';8154my$diff_style=$input_params{'diff_style'} ||'inline';81558156my($patch_max) = gitweb_get_feature('patches');8157if($formateq'patch') {8158 die_error(403,"Patch view not allowed")unless$patch_max;8159}81608161$hash||=$hash_base||"HEAD";8162my%co= parse_commit($hash)8163or die_error(404,"Unknown commit object");81648165# choose format for diff for merge8166if(!defined$hash_parent&& @{$co{'parents'}} >1) {8167$hash_parent='--cc';8168}8169# we need to prepare $formats_nav before almost any parameter munging8170my$formats_nav;8171if($formateq'html') {8172$formats_nav=8173$cgi->a({-href => href(action=>"diff_plain", -replay=>1)},8174"raw");8175if($patch_max&& @{$co{'parents'}} <=1) {8176$formats_nav.=" | ".8177$cgi->a({-href => href(action=>"patch", -replay=>1)},8178"patch");8179}8180$formats_nav.= diff_style_nav($diff_style, @{$co{'parents'}} >1);81818182if(defined$hash_parent&&8183$hash_parentne'-c'&&$hash_parentne'--cc') {8184# diff with two commits given8185my$hash_parent_short=$hash_parent;8186if($hash_parent=~m/^$oid_regex$/) {8187$hash_parent_short=substr($hash_parent,0,7);8188}8189$formats_nav.=8190' (from';8191for(my$i=0;$i< @{$co{'parents'}};$i++) {8192if($co{'parents'}[$i]eq$hash_parent) {8193$formats_nav.=' parent '. ($i+1);8194last;8195}8196}8197$formats_nav.=': '.8198$cgi->a({-href => href(-replay=>1,8199 hash=>$hash_parent, hash_base=>undef)},8200 esc_html($hash_parent_short)) .8201')';8202}elsif(!$co{'parent'}) {8203# --root diff8204$formats_nav.=' (initial)';8205}elsif(scalar@{$co{'parents'}} ==1) {8206# single parent commit8207$formats_nav.=8208' (parent: '.8209$cgi->a({-href => href(-replay=>1,8210 hash=>$co{'parent'}, hash_base=>undef)},8211 esc_html(substr($co{'parent'},0,7))) .8212')';8213}else{8214# merge commit8215if($hash_parenteq'--cc') {8216$formats_nav.=' | '.8217$cgi->a({-href => href(-replay=>1,8218 hash=>$hash, hash_parent=>'-c')},8219'combined');8220}else{# $hash_parent eq '-c'8221$formats_nav.=' | '.8222$cgi->a({-href => href(-replay=>1,8223 hash=>$hash, hash_parent=>'--cc')},8224'compact');8225}8226$formats_nav.=8227' (merge: '.8228join(' ',map{8229$cgi->a({-href => href(-replay=>1,8230 hash=>$_, hash_base=>undef)},8231 esc_html(substr($_,0,7)));8232} @{$co{'parents'}} ) .8233')';8234}8235}82368237my$hash_parent_param=$hash_parent;8238if(!defined$hash_parent_param) {8239# --cc for multiple parents, --root for parentless8240$hash_parent_param=8241@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';8242}82438244# read diff8245my$fd;8246my@difftree;8247if($formateq'html') {8248open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,8249"--no-commit-id","--patch-with-raw","--full-index",8250$hash_parent_param,$hash,"--"8251or die_error(500,"Open git-diff-tree failed");82528253while(my$line= <$fd>) {8254chomp$line;8255# empty line ends raw part of diff-tree output8256last unless$line;8257push@difftree,scalar parse_difftree_raw_line($line);8258}82598260}elsif($formateq'plain') {8261open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,8262'-p',$hash_parent_param,$hash,"--"8263or die_error(500,"Open git-diff-tree failed");8264}elsif($formateq'patch') {8265# For commit ranges, we limit the output to the number of8266# patches specified in the 'patches' feature.8267# For single commits, we limit the output to a single patch,8268# diverging from the git-format-patch default.8269my@commit_spec= ();8270if($hash_parent) {8271if($patch_max>0) {8272push@commit_spec,"-$patch_max";8273}8274push@commit_spec,'-n',"$hash_parent..$hash";8275}else{8276if($params{-single}) {8277push@commit_spec,'-1';8278}else{8279if($patch_max>0) {8280push@commit_spec,"-$patch_max";8281}8282push@commit_spec,"-n";8283}8284push@commit_spec,'--root',$hash;8285}8286open$fd,"-|", git_cmd(),"format-patch",@diff_opts,8287'--encoding=utf8','--stdout',@commit_spec8288or die_error(500,"Open git-format-patch failed");8289}else{8290 die_error(400,"Unknown diff format");8291}82928293# non-textual hash id's can be cached8294my$expires;8295if($hash=~m/^$oid_regex$/) {8296$expires="+1d";8297}82988299# write commit message8300if($formateq'html') {8301my$refs= git_get_references();8302my$ref= format_ref_marker($refs,$co{'id'});83038304 git_header_html(undef,$expires);8305 git_print_page_nav('diff','',$hash,$co{'tree'},$hash);8306 git_print_header_div('commit', esc_html($co{'title'}),$ref,$hash);8307print"<div class=\"title_text\">\n".8308"<table class=\"object_header\">\n";8309 git_print_authorship_rows(\%co);8310print"</table>".8311"</div>\n";8312if(@{$co{'comment'}} >1) {8313print"<div class=\"log\">\n";8314 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);8315print"</div>\n";# class="log"8316}83178318}elsif($formateq'plain') {8319my$refs= git_get_references("tags");8320my$tagname= git_get_rev_name_tags($hash);8321my$filename= basename($project) ."-$hash.patch";83228323print$cgi->header(8324-type =>'text/plain',8325-charset =>'utf-8',8326-expires =>$expires,8327-content_disposition =>'inline; filename="'."$filename".'"');8328my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});8329print"From: ". to_utf8($co{'author'}) ."\n";8330print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";8331print"Subject: ". to_utf8($co{'title'}) ."\n";83328333print"X-Git-Tag:$tagname\n"if$tagname;8334print"X-Git-Url: ".$cgi->self_url() ."\n\n";83358336foreachmy$line(@{$co{'comment'}}) {8337print to_utf8($line) ."\n";8338}8339print"---\n\n";8340}elsif($formateq'patch') {8341my$filename= basename($project) ."-$hash.patch";83428343print$cgi->header(8344-type =>'text/plain',8345-charset =>'utf-8',8346-expires =>$expires,8347-content_disposition =>'inline; filename="'."$filename".'"');8348}83498350# write patch8351if($formateq'html') {8352my$use_parents= !defined$hash_parent||8353$hash_parenteq'-c'||$hash_parenteq'--cc';8354 git_difftree_body(\@difftree,$hash,8355$use_parents? @{$co{'parents'}} :$hash_parent);8356print"<nav class=\"formats_nav\">$formats_nav</nav>";83578358 git_patchset_body($fd,$diff_style,8359 \@difftree,$hash,8360$use_parents? @{$co{'parents'}} :$hash_parent);8361close$fd;8362 git_footer_html();83638364}elsif($formateq'plain') {8365local$/=undef;8366print<$fd>;8367close$fd8368or print"Reading git-diff-tree failed\n";8369}elsif($formateq'patch') {8370local$/=undef;8371print<$fd>;8372close$fd8373or print"Reading git-format-patch failed\n";8374}8375}83768377sub git_diff_plain {8378 git_diff(-format =>'plain');8379}83808381# format-patch-style patches8382sub git_patch {8383 git_diff(-format =>'patch', -single =>1);8384}83858386sub git_patches {8387 git_diff(-format =>'patch');8388}83898390sub git_history {8391 git_log_generic('history', \&git_history_body,8392$hash_base,$hash_parent_base,8393$file_name,$hash);8394}83958396sub git_search {8397$searchtype||='commit';83988399# check if appropriate features are enabled8400 gitweb_check_feature('search')8401or die_error(403,"Search is disabled");8402if($searchtypeeq'pickaxe') {8403# pickaxe may take all resources of your box and run for several minutes8404# with every query - so decide by yourself how public you make this feature8405 gitweb_check_feature('pickaxe')8406or die_error(403,"Pickaxe search is disabled");8407}8408if($searchtypeeq'grep') {8409# grep search might be potentially CPU-intensive, too8410 gitweb_check_feature('grep')8411or die_error(403,"Grep search is disabled");8412}84138414if(!defined$searchtext) {8415 die_error(400,"Text field is empty");8416}8417if(!defined$hash) {8418$hash= git_get_head_hash($project);8419}8420my%co= parse_commit($hash);8421if(!%co) {8422 die_error(404,"Unknown commit object");8423}8424if(!defined$page) {8425$page=0;8426}84278428if($searchtypeeq'commit'||8429$searchtypeeq'author'||8430$searchtypeeq'committer') {8431 git_search_message(%co);8432}elsif($searchtypeeq'pickaxe') {8433 git_search_changes(%co);8434}elsif($searchtypeeq'grep') {8435 git_search_files(%co);8436}else{8437 die_error(400,"Unknown search type");8438}8439}84408441sub git_search_help {8442 git_header_html();8443 git_print_page_nav('','',$hash,$hash,$hash);8444print<<EOT;8445<p>By default, the search string is matched exactly (but without regard to case, unless 8446<em>pickaxe</em> is selected). However, when you check the <em>re</em> checkbox,8447the pattern is interpreted as a POSIX extended8448<a href="https://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case8449insensitive).</p>8450<h3>Search options</h3>8451<dl>8452<dt><b>commit</b></dt>8453<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>8454EOT8455my$have_grep= gitweb_check_feature('grep');8456if($have_grep) {8457print<<EOT;8458<dt><b>grep</b></dt>8459<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing a different one) 8460are searched for the given pattern. On large trees, this search can take8461a while and put some strain on the server, so please use it with some consideration. Note that8462due to a git-grep peculiarity, currently if regex mode is turned off, the matches are8463case-sensitive.</dd>8464EOT8465}8466print<<EOT;8467<dt><b>author</b></dt>8468<dd>Name and email of the author and date of the patch will be scanned for the given pattern.</dd>8469<dt><b>committer</b></dt>8470<dd>Name and email of the committer and date of commit will be scanned for the given pattern.</dd>8471EOT8472my$have_pickaxe= gitweb_check_feature('pickaxe');8473if($have_pickaxe) {8474print<<EOT;8475<dt><b>pickaxe</b></dt>8476<dd>All commits that caused the string to appear or disappear from any file (changes that8477added, removed or "modified" the string) will be listed. This search can take a while and8478takes a lot of strain on the server, so please use it wisely. Note that since you may be8479interested even in changes just changing the case as well, this search is case sensitive.</dd>8480EOT8481}8482print"</dl>\n";8483 git_footer_html();8484}84858486sub git_shortlog {8487 git_log_generic('shortlog', \&git_shortlog_body,8488$hash,$hash_parent);8489}84908491## ......................................................................8492## feeds (RSS, Atom; OPML)84938494sub git_feed {8495my$format=shift||'atom';8496my$have_blame= gitweb_check_feature('blame');84978498# Atom: http://www.atomenabled.org/developers/syndication/8499# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ8500if($formatne'rss'&&$formatne'atom') {8501 die_error(400,"Unknown web feed format");8502}8503if(not gitweb_check_feature($format)) {8504 die_error(403,"Feed disabled");8505}85068507# log/feed of current (HEAD) branch, log of given branch, history of file/directory8508my$head=$hash||'HEAD';8509my@commitlist= parse_commits($head,150,0,$file_name);85108511my%latest_commit;8512my%latest_date;8513my$content_type="application/$format+xml";8514if(defined$cgi->http('HTTP_ACCEPT') &&8515$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {8516# browser (feed reader) prefers text/xml8517$content_type='text/xml';8518}8519if(defined($commitlist[0])) {8520%latest_commit= %{$commitlist[0]};8521my$latest_epoch=$latest_commit{'committer_epoch'};8522 exit_if_unmodified_since($latest_epoch);8523%latest_date= parse_date($latest_epoch,$latest_commit{'committer_tz'});8524}8525print$cgi->header(8526-type =>$content_type,8527-charset =>'utf-8',8528%latest_date? (-last_modified =>$latest_date{'rfc2822'}) : (),8529-status =>'200 OK');85308531# Optimization: skip generating the body if client asks only8532# for Last-Modified date.8533return if($cgi->request_method()eq'HEAD');85348535# header variables8536my$title="$site_name-$project/$action";8537my$feed_type='log';8538if(defined$hash) {8539$title.=" - '$hash'";8540$feed_type='branch log';8541if(defined$file_name) {8542$title.=" ::$file_name";8543$feed_type='history';8544}8545}elsif(defined$file_name) {8546$title.=" -$file_name";8547$feed_type='history';8548}8549$title.="$feed_type";8550$title= esc_html($title);8551my$descr= git_get_project_description($project);8552if(defined$descr) {8553$descr= esc_html($descr);8554}else{8555$descr= ($formateq'rss'?'RSS':'Atom') .8556" feed of$project";8557}8558my$owner= git_get_project_owner($project);8559$owner= esc_html($owner);85608561#header8562my$alt_url;8563if(defined$file_name) {8564$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);8565}elsif(defined$hash) {8566$alt_url= href(-full=>1, action=>"log", hash=>$hash);8567}else{8568$alt_url= href(-full=>1, action=>"summary");8569}8570print qq!<?xml version="1.0" encoding="utf-8"?>\n!;8571if($formateq'rss') {8572print<<XML;8573<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">8574<channel>8575XML8576print"<title>$title</title>\n".8577"<link>$alt_url</link>\n".8578"<description>$descr</description>\n".8579"<language>en</language>\n".8580# project owner is responsible for 'editorial' content8581"<managingEditor>$owner</managingEditor>\n";8582if(defined$logo||defined$favicon) {8583# prefer the logo to the favicon, since RSS8584# doesn't allow both8585my$img= esc_url($logo||$favicon);8586print"<image>\n".8587"<url>$img</url>\n".8588"<title>$title</title>\n".8589"<link>$alt_url</link>\n".8590"</image>\n";8591}8592if(%latest_date) {8593print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";8594print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";8595}8596print"<generator>gitweb v.$version/$git_version</generator>\n";8597}elsif($formateq'atom') {8598print<<XML;8599<feed xmlns="http://www.w3.org/2005/Atom">8600XML8601print"<title>$title</title>\n".8602"<subtitle>$descr</subtitle>\n".8603'<link rel="alternate" type="text/html" href="'.8604$alt_url.'" />'."\n".8605'<link rel="self" type="'.$content_type.'" href="'.8606$cgi->self_url() .'" />'."\n".8607"<id>". href(-full=>1) ."</id>\n".8608# use project owner for feed author8609"<author><name>$owner</name></author>\n";8610if(defined$favicon) {8611print"<icon>". esc_url($favicon) ."</icon>\n";8612}8613if(defined$logo) {8614# not twice as wide as tall: 72 x 27 pixels8615print"<logo>". esc_url($logo) ."</logo>\n";8616}8617if(!%latest_date) {8618# dummy date to keep the feed valid until commits trickle in:8619print"<updated>1970-01-01T00:00:00Z</updated>\n";8620}else{8621print"<updated>$latest_date{'iso-8601'}</updated>\n";8622}8623print"<generator version='$version/$git_version'>gitweb</generator>\n";8624}86258626# contents8627for(my$i=0;$i<=$#commitlist;$i++) {8628my%co= %{$commitlist[$i]};8629my$commit=$co{'id'};8630# we read 150, we always show 30 and the ones more recent than 48 hours8631if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {8632last;8633}8634my%cd= parse_date($co{'author_epoch'},$co{'author_tz'});86358636# get list of changed files8637open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,8638$co{'parent'} ||"--root",8639$co{'id'},"--", (defined$file_name?$file_name: ())8640ornext;8641my@difftree=map{chomp;$_} <$fd>;8642close$fd8643ornext;86448645# print element (entry, item)8646my$co_url= href(-full=>1, action=>"diff", hash=>$commit);8647if($formateq'rss') {8648print"<item>\n".8649"<title>". esc_html($co{'title'}) ."</title>\n".8650"<author>". esc_html($co{'author'}) ."</author>\n".8651"<pubDate>$cd{'rfc2822'}</pubDate>\n".8652"<guid isPermaLink=\"true\">$co_url</guid>\n".8653"<link>$co_url</link>\n".8654"<description>". esc_html($co{'title'}) ."</description>\n".8655"<content:encoded>".8656"<![CDATA[\n";8657}elsif($formateq'atom') {8658print"<entry>\n".8659"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".8660"<updated>$cd{'iso-8601'}</updated>\n".8661"<author>\n".8662" <name>". esc_html($co{'author_name'}) ."</name>\n";8663if($co{'author_email'}) {8664print" <email>". esc_html($co{'author_email'}) ."</email>\n";8665}8666print"</author>\n".8667# use committer for contributor8668"<contributor>\n".8669" <name>". esc_html($co{'committer_name'}) ."</name>\n";8670if($co{'committer_email'}) {8671print" <email>". esc_html($co{'committer_email'}) ."</email>\n";8672}8673print"</contributor>\n".8674"<published>$cd{'iso-8601'}</published>\n".8675"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".8676"<id>$co_url</id>\n".8677"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".8678"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";8679}8680my$comment=$co{'comment'};8681print"<pre>\n";8682foreachmy$line(@$comment) {8683$line= esc_html($line);8684print"$line\n";8685}8686print"</pre><ul>\n";8687foreachmy$difftree_line(@difftree) {8688my%difftree= parse_difftree_raw_line($difftree_line);8689next if!$difftree{'from_id'};86908691my$file=$difftree{'file'} ||$difftree{'to_file'};86928693print"<li>".8694"[".8695$cgi->a({-href => href(-full=>1, action=>"blobdiff",8696 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},8697 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},8698 file_name=>$file, file_parent=>$difftree{'from_file'}),8699-title =>"diff"},'D');8700if($have_blame) {8701print$cgi->a({-href => href(-full=>1, action=>"blame",8702 file_name=>$file, hash_base=>$commit),8703-title =>"blame"},'B');8704}8705# if this is not a feed of a file history8706if(!defined$file_name||$file_namene$file) {8707print$cgi->a({-href => href(-full=>1, action=>"history",8708 file_name=>$file, hash=>$commit),8709-title =>"history"},'H');8710}8711$file= esc_path($file);8712print"] ".8713"$file</li>\n";8714}8715if($formateq'rss') {8716print"</ul>]]>\n".8717"</content:encoded>\n".8718"</item>\n";8719}elsif($formateq'atom') {8720print"</ul>\n</div>\n".8721"</content>\n".8722"</entry>\n";8723}8724}87258726# end of feed8727if($formateq'rss') {8728print"</channel>\n</rss>\n";8729}elsif($formateq'atom') {8730print"</feed>\n";8731}8732}87338734sub git_rss {8735 git_feed('rss');8736}87378738sub git_atom {8739 git_feed('atom');8740}87418742sub git_opml {8743my@list= git_get_projects_list($project_filter,$strict_export);8744if(!@list) {8745 die_error(404,"No projects found");8746}87478748print$cgi->header(8749-type =>'text/xml',8750-charset =>'utf-8',8751-content_disposition =>'inline; filename="opml.xml"');87528753my$title= esc_html($site_name);8754my$filter=" within subdirectory ";8755if(defined$project_filter) {8756$filter.= esc_html($project_filter);8757}else{8758$filter="";8759}8760print<<XML;8761<?xml version="1.0" encoding="utf-8"?>8762<opml version="1.0">8763<head>8764 <title>$titleOPML Export$filter</title>8765</head>8766<body>8767<outline text="git RSS feeds">8768XML87698770foreachmy$pr(@list) {8771my%proj=%$pr;8772my$head= git_get_head_hash($proj{'path'});8773if(!defined$head) {8774next;8775}8776$git_dir="$projectroot/$proj{'path'}";8777my%co= parse_commit($head);8778if(!%co) {8779next;8780}87818782my$path= esc_html(chop_str($proj{'path'},25,5));8783my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);8784my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);8785print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";8786}8787print<<XML;8788</outline>8789</body>8790</opml>8791XML8792}