1#!/usr/bin/perl 2 3# gitweb - simple web interface to track changes in git repositories 4# 5# (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org> 6# (C) 2005, Christian Gierke 7# 8# This program is licensed under the GPLv2 9 10use5.008; 11use strict; 12use warnings; 13use CGI qw(:standard :escapeHTML -nosticky); 14use CGI::Util qw(unescape); 15use CGI::Carp qw(fatalsToBrowser set_message); 16use Encode; 17use Fcntl ':mode'; 18use File::Find qw(); 19use File::Basename qw(basename); 20use Time::HiRes qw(gettimeofday tv_interval); 21binmode STDOUT,':utf8'; 22 23our$t0= [ gettimeofday() ]; 24our$number_of_git_cmds=0; 25 26BEGIN{ 27 CGI->compile()if$ENV{'MOD_PERL'}; 28} 29 30our$version="++GIT_VERSION++"; 31 32our($my_url,$my_uri,$base_url,$path_info,$home_link); 33sub evaluate_uri { 34our$cgi; 35 36our$my_url=$cgi->url(); 37our$my_uri=$cgi->url(-absolute =>1); 38 39# Base URL for relative URLs in gitweb ($logo, $favicon, ...), 40# needed and used only for URLs with nonempty PATH_INFO 41our$base_url=$my_url; 42 43# When the script is used as DirectoryIndex, the URL does not contain the name 44# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we 45# have to do it ourselves. We make $path_info global because it's also used 46# later on. 47# 48# Another issue with the script being the DirectoryIndex is that the resulting 49# $my_url data is not the full script URL: this is good, because we want 50# generated links to keep implying the script name if it wasn't explicitly 51# indicated in the URL we're handling, but it means that $my_url cannot be used 52# as base URL. 53# Therefore, if we needed to strip PATH_INFO, then we know that we have 54# to build the base URL ourselves: 55our$path_info=$ENV{"PATH_INFO"}; 56if($path_info) { 57if($my_url=~ s,\Q$path_info\E$,, && 58$my_uri=~ s,\Q$path_info\E$,, && 59defined$ENV{'SCRIPT_NAME'}) { 60$base_url=$cgi->url(-base =>1) .$ENV{'SCRIPT_NAME'}; 61} 62} 63 64# target of the home link on top of all pages 65our$home_link=$my_uri||"/"; 66} 67 68# core git executable to use 69# this can just be "git" if your webserver has a sensible PATH 70our$GIT="++GIT_BINDIR++/git"; 71 72# absolute fs-path which will be prepended to the project path 73#our $projectroot = "/pub/scm"; 74our$projectroot="++GITWEB_PROJECTROOT++"; 75 76# fs traversing limit for getting project list 77# the number is relative to the projectroot 78our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 79 80# string of the home link on top of all pages 81our$home_link_str="++GITWEB_HOME_LINK_STR++"; 82 83# name of your site or organization to appear in page titles 84# replace this with something more descriptive for clearer bookmarks 85our$site_name="++GITWEB_SITENAME++" 86|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 87 88# filename of html text to include at top of each page 89our$site_header="++GITWEB_SITE_HEADER++"; 90# html text to include at home page 91our$home_text="++GITWEB_HOMETEXT++"; 92# filename of html text to include at bottom of each page 93our$site_footer="++GITWEB_SITE_FOOTER++"; 94 95# URI of stylesheets 96our@stylesheets= ("++GITWEB_CSS++"); 97# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 98our$stylesheet=undef; 99# URI of GIT logo (72x27 size) 100our$logo="++GITWEB_LOGO++"; 101# URI of GIT favicon, assumed to be image/png type 102our$favicon="++GITWEB_FAVICON++"; 103# URI of gitweb.js (JavaScript code for gitweb) 104our$javascript="++GITWEB_JS++"; 105 106# URI and label (title) of GIT logo link 107#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 108#our $logo_label = "git documentation"; 109our$logo_url="http://git-scm.com/"; 110our$logo_label="git homepage"; 111 112# source of projects list 113our$projects_list="++GITWEB_LIST++"; 114 115# the width (in characters) of the projects list "Description" column 116our$projects_list_description_width=25; 117 118# default order of projects list 119# valid values are none, project, descr, owner, and age 120our$default_projects_order="project"; 121 122# show repository only if this file exists 123# (only effective if this variable evaluates to true) 124our$export_ok="++GITWEB_EXPORT_OK++"; 125 126# show repository only if this subroutine returns true 127# when given the path to the project, for example: 128# sub { return -e "$_[0]/git-daemon-export-ok"; } 129our$export_auth_hook=undef; 130 131# only allow viewing of repositories also shown on the overview page 132our$strict_export="++GITWEB_STRICT_EXPORT++"; 133 134# list of git base URLs used for URL to where fetch project from, 135# i.e. full URL is "$git_base_url/$project" 136our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 137 138# default blob_plain mimetype and default charset for text/plain blob 139our$default_blob_plain_mimetype='text/plain'; 140our$default_text_plain_charset=undef; 141 142# file to use for guessing MIME types before trying /etc/mime.types 143# (relative to the current git repository) 144our$mimetypes_file=undef; 145 146# assume this charset if line contains non-UTF-8 characters; 147# it should be valid encoding (see Encoding::Supported(3pm) for list), 148# for which encoding all byte sequences are valid, for example 149# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 150# could be even 'utf-8' for the old behavior) 151our$fallback_encoding='latin1'; 152 153# rename detection options for git-diff and git-diff-tree 154# - default is '-M', with the cost proportional to 155# (number of removed files) * (number of new files). 156# - more costly is '-C' (which implies '-M'), with the cost proportional to 157# (number of changed files + number of removed files) * (number of new files) 158# - even more costly is '-C', '--find-copies-harder' with cost 159# (number of files in the original tree) * (number of new files) 160# - one might want to include '-B' option, e.g. '-B', '-M' 161our@diff_opts= ('-M');# taken from git_commit 162 163# Disables features that would allow repository owners to inject script into 164# the gitweb domain. 165our$prevent_xss=0; 166 167# Path to the highlight executable to use (must be the one from 168# http://www.andre-simon.de due to assumptions about parameters and output). 169# Useful if highlight is not installed on your webserver's PATH. 170# [Default: highlight] 171our$highlight_bin="++HIGHLIGHT_BIN++"; 172 173# information about snapshot formats that gitweb is capable of serving 174our%known_snapshot_formats= ( 175# name => { 176# 'display' => display name, 177# 'type' => mime type, 178# 'suffix' => filename suffix, 179# 'format' => --format for git-archive, 180# 'compressor' => [compressor command and arguments] 181# (array reference, optional) 182# 'disabled' => boolean (optional)} 183# 184'tgz'=> { 185'display'=>'tar.gz', 186'type'=>'application/x-gzip', 187'suffix'=>'.tar.gz', 188'format'=>'tar', 189'compressor'=> ['gzip','-n']}, 190 191'tbz2'=> { 192'display'=>'tar.bz2', 193'type'=>'application/x-bzip2', 194'suffix'=>'.tar.bz2', 195'format'=>'tar', 196'compressor'=> ['bzip2']}, 197 198'txz'=> { 199'display'=>'tar.xz', 200'type'=>'application/x-xz', 201'suffix'=>'.tar.xz', 202'format'=>'tar', 203'compressor'=> ['xz'], 204'disabled'=>1}, 205 206'zip'=> { 207'display'=>'zip', 208'type'=>'application/x-zip', 209'suffix'=>'.zip', 210'format'=>'zip'}, 211); 212 213# Aliases so we understand old gitweb.snapshot values in repository 214# configuration. 215our%known_snapshot_format_aliases= ( 216'gzip'=>'tgz', 217'bzip2'=>'tbz2', 218'xz'=>'txz', 219 220# backward compatibility: legacy gitweb config support 221'x-gzip'=>undef,'gz'=>undef, 222'x-bzip2'=>undef,'bz2'=>undef, 223'x-zip'=>undef,''=>undef, 224); 225 226# Pixel sizes for icons and avatars. If the default font sizes or lineheights 227# are changed, it may be appropriate to change these values too via 228# $GITWEB_CONFIG. 229our%avatar_size= ( 230'default'=>16, 231'double'=>32 232); 233 234# Used to set the maximum load that we will still respond to gitweb queries. 235# If server load exceed this value then return "503 server busy" error. 236# If gitweb cannot determined server load, it is taken to be 0. 237# Leave it undefined (or set to 'undef') to turn off load checking. 238our$maxload=300; 239 240# configuration for 'highlight' (http://www.andre-simon.de/) 241# match by basename 242our%highlight_basename= ( 243#'Program' => 'py', 244#'Library' => 'py', 245'SConstruct'=>'py',# SCons equivalent of Makefile 246'Makefile'=>'make', 247); 248# match by extension 249our%highlight_ext= ( 250# main extensions, defining name of syntax; 251# see files in /usr/share/highlight/langDefs/ directory 252map{$_=>$_} 253qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl sql make), 254# alternate extensions, see /etc/highlight/filetypes.conf 255'h'=>'c', 256map{$_=>'sh'}qw(bash zsh ksh), 257map{$_=>'cpp'}qw(cxx c++ cc), 258map{$_=>'php'}qw(php3 php4 php5 phps), 259map{$_=>'pl'}qw(perl pm),# perhaps also 'cgi' 260map{$_=>'make'}qw(mak mk), 261map{$_=>'xml'}qw(xhtml html htm), 262); 263 264# You define site-wide feature defaults here; override them with 265# $GITWEB_CONFIG as necessary. 266our%feature= ( 267# feature => { 268# 'sub' => feature-sub (subroutine), 269# 'override' => allow-override (boolean), 270# 'default' => [ default options...] (array reference)} 271# 272# if feature is overridable (it means that allow-override has true value), 273# then feature-sub will be called with default options as parameters; 274# return value of feature-sub indicates if to enable specified feature 275# 276# if there is no 'sub' key (no feature-sub), then feature cannot be 277# overridden 278# 279# use gitweb_get_feature(<feature>) to retrieve the <feature> value 280# (an array) or gitweb_check_feature(<feature>) to check if <feature> 281# is enabled 282 283# Enable the 'blame' blob view, showing the last commit that modified 284# each line in the file. This can be very CPU-intensive. 285 286# To enable system wide have in $GITWEB_CONFIG 287# $feature{'blame'}{'default'} = [1]; 288# To have project specific config enable override in $GITWEB_CONFIG 289# $feature{'blame'}{'override'} = 1; 290# and in project config gitweb.blame = 0|1; 291'blame'=> { 292'sub'=>sub{ feature_bool('blame',@_) }, 293'override'=>0, 294'default'=> [0]}, 295 296# Enable the 'snapshot' link, providing a compressed archive of any 297# tree. This can potentially generate high traffic if you have large 298# project. 299 300# Value is a list of formats defined in %known_snapshot_formats that 301# you wish to offer. 302# To disable system wide have in $GITWEB_CONFIG 303# $feature{'snapshot'}{'default'} = []; 304# To have project specific config enable override in $GITWEB_CONFIG 305# $feature{'snapshot'}{'override'} = 1; 306# and in project config, a comma-separated list of formats or "none" 307# to disable. Example: gitweb.snapshot = tbz2,zip; 308'snapshot'=> { 309'sub'=> \&feature_snapshot, 310'override'=>0, 311'default'=> ['tgz']}, 312 313# Enable text search, which will list the commits which match author, 314# committer or commit text to a given string. Enabled by default. 315# Project specific override is not supported. 316# 317# Note that this controls all search features, which means that if 318# it is disabled, then 'grep' and 'pickaxe' search would also be 319# disabled. 320'search'=> { 321'override'=>0, 322'default'=> [1]}, 323 324# Enable grep search, which will list the files in currently selected 325# tree containing the given string. Enabled by default. This can be 326# potentially CPU-intensive, of course. 327# Note that you need to have 'search' feature enabled too. 328 329# To enable system wide have in $GITWEB_CONFIG 330# $feature{'grep'}{'default'} = [1]; 331# To have project specific config enable override in $GITWEB_CONFIG 332# $feature{'grep'}{'override'} = 1; 333# and in project config gitweb.grep = 0|1; 334'grep'=> { 335'sub'=>sub{ feature_bool('grep',@_) }, 336'override'=>0, 337'default'=> [1]}, 338 339# Enable the pickaxe search, which will list the commits that modified 340# a given string in a file. This can be practical and quite faster 341# alternative to 'blame', but still potentially CPU-intensive. 342# Note that you need to have 'search' feature enabled too. 343 344# To enable system wide have in $GITWEB_CONFIG 345# $feature{'pickaxe'}{'default'} = [1]; 346# To have project specific config enable override in $GITWEB_CONFIG 347# $feature{'pickaxe'}{'override'} = 1; 348# and in project config gitweb.pickaxe = 0|1; 349'pickaxe'=> { 350'sub'=>sub{ feature_bool('pickaxe',@_) }, 351'override'=>0, 352'default'=> [1]}, 353 354# Enable showing size of blobs in a 'tree' view, in a separate 355# column, similar to what 'ls -l' does. This cost a bit of IO. 356 357# To disable system wide have in $GITWEB_CONFIG 358# $feature{'show-sizes'}{'default'} = [0]; 359# To have project specific config enable override in $GITWEB_CONFIG 360# $feature{'show-sizes'}{'override'} = 1; 361# and in project config gitweb.showsizes = 0|1; 362'show-sizes'=> { 363'sub'=>sub{ feature_bool('showsizes',@_) }, 364'override'=>0, 365'default'=> [1]}, 366 367# Make gitweb use an alternative format of the URLs which can be 368# more readable and natural-looking: project name is embedded 369# directly in the path and the query string contains other 370# auxiliary information. All gitweb installations recognize 371# URL in either format; this configures in which formats gitweb 372# generates links. 373 374# To enable system wide have in $GITWEB_CONFIG 375# $feature{'pathinfo'}{'default'} = [1]; 376# Project specific override is not supported. 377 378# Note that you will need to change the default location of CSS, 379# favicon, logo and possibly other files to an absolute URL. Also, 380# if gitweb.cgi serves as your indexfile, you will need to force 381# $my_uri to contain the script name in your $GITWEB_CONFIG. 382'pathinfo'=> { 383'override'=>0, 384'default'=> [0]}, 385 386# Make gitweb consider projects in project root subdirectories 387# to be forks of existing projects. Given project $projname.git, 388# projects matching $projname/*.git will not be shown in the main 389# projects list, instead a '+' mark will be added to $projname 390# there and a 'forks' view will be enabled for the project, listing 391# all the forks. If project list is taken from a file, forks have 392# to be listed after the main project. 393 394# To enable system wide have in $GITWEB_CONFIG 395# $feature{'forks'}{'default'} = [1]; 396# Project specific override is not supported. 397'forks'=> { 398'override'=>0, 399'default'=> [0]}, 400 401# Insert custom links to the action bar of all project pages. 402# This enables you mainly to link to third-party scripts integrating 403# into gitweb; e.g. git-browser for graphical history representation 404# or custom web-based repository administration interface. 405 406# The 'default' value consists of a list of triplets in the form 407# (label, link, position) where position is the label after which 408# to insert the link and link is a format string where %n expands 409# to the project name, %f to the project path within the filesystem, 410# %h to the current hash (h gitweb parameter) and %b to the current 411# hash base (hb gitweb parameter); %% expands to %. 412 413# To enable system wide have in $GITWEB_CONFIG e.g. 414# $feature{'actions'}{'default'} = [('graphiclog', 415# '/git-browser/by-commit.html?r=%n', 'summary')]; 416# Project specific override is not supported. 417'actions'=> { 418'override'=>0, 419'default'=> []}, 420 421# Allow gitweb scan project content tags described in ctags/ 422# of project repository, and display the popular Web 2.0-ish 423# "tag cloud" near the project list. Note that this is something 424# COMPLETELY different from the normal Git tags. 425 426# gitweb by itself can show existing tags, but it does not handle 427# tagging itself; you need an external application for that. 428# For an example script, check Girocco's cgi/tagproj.cgi. 429# You may want to install the HTML::TagCloud Perl module to get 430# a pretty tag cloud instead of just a list of tags. 431 432# To enable system wide have in $GITWEB_CONFIG 433# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 434# Project specific override is not supported. 435'ctags'=> { 436'override'=>0, 437'default'=> [0]}, 438 439# The maximum number of patches in a patchset generated in patch 440# view. Set this to 0 or undef to disable patch view, or to a 441# negative number to remove any limit. 442 443# To disable system wide have in $GITWEB_CONFIG 444# $feature{'patches'}{'default'} = [0]; 445# To have project specific config enable override in $GITWEB_CONFIG 446# $feature{'patches'}{'override'} = 1; 447# and in project config gitweb.patches = 0|n; 448# where n is the maximum number of patches allowed in a patchset. 449'patches'=> { 450'sub'=> \&feature_patches, 451'override'=>0, 452'default'=> [16]}, 453 454# Avatar support. When this feature is enabled, views such as 455# shortlog or commit will display an avatar associated with 456# the email of the committer(s) and/or author(s). 457 458# Currently available providers are gravatar and picon. 459# If an unknown provider is specified, the feature is disabled. 460 461# Gravatar depends on Digest::MD5. 462# Picon currently relies on the indiana.edu database. 463 464# To enable system wide have in $GITWEB_CONFIG 465# $feature{'avatar'}{'default'} = ['<provider>']; 466# where <provider> is either gravatar or picon. 467# To have project specific config enable override in $GITWEB_CONFIG 468# $feature{'avatar'}{'override'} = 1; 469# and in project config gitweb.avatar = <provider>; 470'avatar'=> { 471'sub'=> \&feature_avatar, 472'override'=>0, 473'default'=> ['']}, 474 475# Enable displaying how much time and how many git commands 476# it took to generate and display page. Disabled by default. 477# Project specific override is not supported. 478'timed'=> { 479'override'=>0, 480'default'=> [0]}, 481 482# Enable turning some links into links to actions which require 483# JavaScript to run (like 'blame_incremental'). Not enabled by 484# default. Project specific override is currently not supported. 485'javascript-actions'=> { 486'override'=>0, 487'default'=> [0]}, 488 489# Syntax highlighting support. This is based on Daniel Svensson's 490# and Sham Chukoury's work in gitweb-xmms2.git. 491# It requires the 'highlight' program present in $PATH, 492# and therefore is disabled by default. 493 494# To enable system wide have in $GITWEB_CONFIG 495# $feature{'highlight'}{'default'} = [1]; 496 497'highlight'=> { 498'sub'=>sub{ feature_bool('highlight',@_) }, 499'override'=>0, 500'default'=> [0]}, 501 502# Enable displaying of remote heads in the heads list 503 504# To enable system wide have in $GITWEB_CONFIG 505# $feature{'remote_heads'}{'default'} = [1]; 506# To have project specific config enable override in $GITWEB_CONFIG 507# $feature{'remote_heads'}{'override'} = 1; 508# and in project config gitweb.remote_heads = 0|1; 509'remote_heads'=> { 510'sub'=>sub{ feature_bool('remote_heads',@_) }, 511'override'=>0, 512'default'=> [0]}, 513); 514 515sub gitweb_get_feature { 516my($name) =@_; 517return unlessexists$feature{$name}; 518my($sub,$override,@defaults) = ( 519$feature{$name}{'sub'}, 520$feature{$name}{'override'}, 521@{$feature{$name}{'default'}}); 522# project specific override is possible only if we have project 523our$git_dir;# global variable, declared later 524if(!$override|| !defined$git_dir) { 525return@defaults; 526} 527if(!defined$sub) { 528warn"feature$nameis not overridable"; 529return@defaults; 530} 531return$sub->(@defaults); 532} 533 534# A wrapper to check if a given feature is enabled. 535# With this, you can say 536# 537# my $bool_feat = gitweb_check_feature('bool_feat'); 538# gitweb_check_feature('bool_feat') or somecode; 539# 540# instead of 541# 542# my ($bool_feat) = gitweb_get_feature('bool_feat'); 543# (gitweb_get_feature('bool_feat'))[0] or somecode; 544# 545sub gitweb_check_feature { 546return(gitweb_get_feature(@_))[0]; 547} 548 549 550sub feature_bool { 551my$key=shift; 552my($val) = git_get_project_config($key,'--bool'); 553 554if(!defined$val) { 555return($_[0]); 556}elsif($valeq'true') { 557return(1); 558}elsif($valeq'false') { 559return(0); 560} 561} 562 563sub feature_snapshot { 564my(@fmts) =@_; 565 566my($val) = git_get_project_config('snapshot'); 567 568if($val) { 569@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 570} 571 572return@fmts; 573} 574 575sub feature_patches { 576my@val= (git_get_project_config('patches','--int')); 577 578if(@val) { 579return@val; 580} 581 582return($_[0]); 583} 584 585sub feature_avatar { 586my@val= (git_get_project_config('avatar')); 587 588return@val?@val:@_; 589} 590 591# checking HEAD file with -e is fragile if the repository was 592# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 593# and then pruned. 594sub check_head_link { 595my($dir) =@_; 596my$headfile="$dir/HEAD"; 597return((-e $headfile) || 598(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 599} 600 601sub check_export_ok { 602my($dir) =@_; 603return(check_head_link($dir) && 604(!$export_ok|| -e "$dir/$export_ok") && 605(!$export_auth_hook||$export_auth_hook->($dir))); 606} 607 608# process alternate names for backward compatibility 609# filter out unsupported (unknown) snapshot formats 610sub filter_snapshot_fmts { 611my@fmts=@_; 612 613@fmts=map{ 614exists$known_snapshot_format_aliases{$_} ? 615$known_snapshot_format_aliases{$_} :$_}@fmts; 616@fmts=grep{ 617exists$known_snapshot_formats{$_} && 618!$known_snapshot_formats{$_}{'disabled'}}@fmts; 619} 620 621# If it is set to code reference, it is code that it is to be run once per 622# request, allowing updating configurations that change with each request, 623# while running other code in config file only once. 624# 625# Otherwise, if it is false then gitweb would process config file only once; 626# if it is true then gitweb config would be run for each request. 627our$per_request_config=1; 628 629our($GITWEB_CONFIG,$GITWEB_CONFIG_SYSTEM); 630sub evaluate_gitweb_config { 631our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 632our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 633# die if there are errors parsing config file 634if(-e $GITWEB_CONFIG) { 635do$GITWEB_CONFIG; 636die$@if$@; 637}elsif(-e $GITWEB_CONFIG_SYSTEM) { 638do$GITWEB_CONFIG_SYSTEM; 639die$@if$@; 640} 641} 642 643# Get loadavg of system, to compare against $maxload. 644# Currently it requires '/proc/loadavg' present to get loadavg; 645# if it is not present it returns 0, which means no load checking. 646sub get_loadavg { 647if( -e '/proc/loadavg'){ 648open my$fd,'<','/proc/loadavg' 649orreturn0; 650my@load=split(/\s+/,scalar<$fd>); 651close$fd; 652 653# The first three columns measure CPU and IO utilization of the last one, 654# five, and 10 minute periods. The fourth column shows the number of 655# currently running processes and the total number of processes in the m/n 656# format. The last column displays the last process ID used. 657return$load[0] ||0; 658} 659# additional checks for load average should go here for things that don't export 660# /proc/loadavg 661 662return0; 663} 664 665# version of the core git binary 666our$git_version; 667sub evaluate_git_version { 668our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 669$number_of_git_cmds++; 670} 671 672sub check_loadavg { 673if(defined$maxload&& get_loadavg() >$maxload) { 674 die_error(503,"The load average on the server is too high"); 675} 676} 677 678# ====================================================================== 679# input validation and dispatch 680 681# input parameters can be collected from a variety of sources (presently, CGI 682# and PATH_INFO), so we define an %input_params hash that collects them all 683# together during validation: this allows subsequent uses (e.g. href()) to be 684# agnostic of the parameter origin 685 686our%input_params= (); 687 688# input parameters are stored with the long parameter name as key. This will 689# also be used in the href subroutine to convert parameters to their CGI 690# equivalent, and since the href() usage is the most frequent one, we store 691# the name -> CGI key mapping here, instead of the reverse. 692# 693# XXX: Warning: If you touch this, check the search form for updating, 694# too. 695 696our@cgi_param_mapping= ( 697 project =>"p", 698 action =>"a", 699 file_name =>"f", 700 file_parent =>"fp", 701 hash =>"h", 702 hash_parent =>"hp", 703 hash_base =>"hb", 704 hash_parent_base =>"hpb", 705 page =>"pg", 706 order =>"o", 707 searchtext =>"s", 708 searchtype =>"st", 709 snapshot_format =>"sf", 710 extra_options =>"opt", 711 search_use_regexp =>"sr", 712# this must be last entry (for manipulation from JavaScript) 713 javascript =>"js" 714); 715our%cgi_param_mapping=@cgi_param_mapping; 716 717# we will also need to know the possible actions, for validation 718our%actions= ( 719"blame"=> \&git_blame, 720"blame_incremental"=> \&git_blame_incremental, 721"blame_data"=> \&git_blame_data, 722"blobdiff"=> \&git_blobdiff, 723"blobdiff_plain"=> \&git_blobdiff_plain, 724"blob"=> \&git_blob, 725"blob_plain"=> \&git_blob_plain, 726"commitdiff"=> \&git_commitdiff, 727"commitdiff_plain"=> \&git_commitdiff_plain, 728"commit"=> \&git_commit, 729"forks"=> \&git_forks, 730"heads"=> \&git_heads, 731"history"=> \&git_history, 732"log"=> \&git_log, 733"patch"=> \&git_patch, 734"patches"=> \&git_patches, 735"remotes"=> \&git_remotes, 736"rss"=> \&git_rss, 737"atom"=> \&git_atom, 738"search"=> \&git_search, 739"search_help"=> \&git_search_help, 740"shortlog"=> \&git_shortlog, 741"summary"=> \&git_summary, 742"tag"=> \&git_tag, 743"tags"=> \&git_tags, 744"tree"=> \&git_tree, 745"snapshot"=> \&git_snapshot, 746"object"=> \&git_object, 747# those below don't need $project 748"opml"=> \&git_opml, 749"project_list"=> \&git_project_list, 750"project_index"=> \&git_project_index, 751); 752 753# finally, we have the hash of allowed extra_options for the commands that 754# allow them 755our%allowed_options= ( 756"--no-merges"=> [qw(rss atom log shortlog history)], 757); 758 759# fill %input_params with the CGI parameters. All values except for 'opt' 760# should be single values, but opt can be an array. We should probably 761# build an array of parameters that can be multi-valued, but since for the time 762# being it's only this one, we just single it out 763sub evaluate_query_params { 764our$cgi; 765 766while(my($name,$symbol) =each%cgi_param_mapping) { 767if($symboleq'opt') { 768$input_params{$name} = [$cgi->param($symbol) ]; 769}else{ 770$input_params{$name} =$cgi->param($symbol); 771} 772} 773} 774 775# now read PATH_INFO and update the parameter list for missing parameters 776sub evaluate_path_info { 777return ifdefined$input_params{'project'}; 778return if!$path_info; 779$path_info=~ s,^/+,,; 780return if!$path_info; 781 782# find which part of PATH_INFO is project 783my$project=$path_info; 784$project=~ s,/+$,,; 785while($project&& !check_head_link("$projectroot/$project")) { 786$project=~ s,/*[^/]*$,,; 787} 788return unless$project; 789$input_params{'project'} =$project; 790 791# do not change any parameters if an action is given using the query string 792return if$input_params{'action'}; 793$path_info=~ s,^\Q$project\E/*,,; 794 795# next, check if we have an action 796my$action=$path_info; 797$action=~ s,/.*$,,; 798if(exists$actions{$action}) { 799$path_info=~ s,^$action/*,,; 800$input_params{'action'} =$action; 801} 802 803# list of actions that want hash_base instead of hash, but can have no 804# pathname (f) parameter 805my@wants_base= ( 806'tree', 807'history', 808); 809 810# we want to catch, among others 811# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name] 812my($parentrefname,$parentpathname,$refname,$pathname) = 813($path_info=~/^(?:(.+?)(?::(.+))?\.\.)?([^:]+?)?(?::(.+))?$/); 814 815# first, analyze the 'current' part 816if(defined$pathname) { 817# we got "branch:filename" or "branch:dir/" 818# we could use git_get_type(branch:pathname), but: 819# - it needs $git_dir 820# - it does a git() call 821# - the convention of terminating directories with a slash 822# makes it superfluous 823# - embedding the action in the PATH_INFO would make it even 824# more superfluous 825$pathname=~ s,^/+,,; 826if(!$pathname||substr($pathname, -1)eq"/") { 827$input_params{'action'} ||="tree"; 828$pathname=~ s,/$,,; 829}else{ 830# the default action depends on whether we had parent info 831# or not 832if($parentrefname) { 833$input_params{'action'} ||="blobdiff_plain"; 834}else{ 835$input_params{'action'} ||="blob_plain"; 836} 837} 838$input_params{'hash_base'} ||=$refname; 839$input_params{'file_name'} ||=$pathname; 840}elsif(defined$refname) { 841# we got "branch". In this case we have to choose if we have to 842# set hash or hash_base. 843# 844# Most of the actions without a pathname only want hash to be 845# set, except for the ones specified in @wants_base that want 846# hash_base instead. It should also be noted that hand-crafted 847# links having 'history' as an action and no pathname or hash 848# set will fail, but that happens regardless of PATH_INFO. 849if(defined$parentrefname) { 850# if there is parent let the default be 'shortlog' action 851# (for http://git.example.com/repo.git/A..B links); if there 852# is no parent, dispatch will detect type of object and set 853# action appropriately if required (if action is not set) 854$input_params{'action'} ||="shortlog"; 855} 856if($input_params{'action'} && 857grep{$_eq$input_params{'action'} }@wants_base) { 858$input_params{'hash_base'} ||=$refname; 859}else{ 860$input_params{'hash'} ||=$refname; 861} 862} 863 864# next, handle the 'parent' part, if present 865if(defined$parentrefname) { 866# a missing pathspec defaults to the 'current' filename, allowing e.g. 867# someproject/blobdiff/oldrev..newrev:/filename 868if($parentpathname) { 869$parentpathname=~ s,^/+,,; 870$parentpathname=~ s,/$,,; 871$input_params{'file_parent'} ||=$parentpathname; 872}else{ 873$input_params{'file_parent'} ||=$input_params{'file_name'}; 874} 875# we assume that hash_parent_base is wanted if a path was specified, 876# or if the action wants hash_base instead of hash 877if(defined$input_params{'file_parent'} || 878grep{$_eq$input_params{'action'} }@wants_base) { 879$input_params{'hash_parent_base'} ||=$parentrefname; 880}else{ 881$input_params{'hash_parent'} ||=$parentrefname; 882} 883} 884 885# for the snapshot action, we allow URLs in the form 886# $project/snapshot/$hash.ext 887# where .ext determines the snapshot and gets removed from the 888# passed $refname to provide the $hash. 889# 890# To be able to tell that $refname includes the format extension, we 891# require the following two conditions to be satisfied: 892# - the hash input parameter MUST have been set from the $refname part 893# of the URL (i.e. they must be equal) 894# - the snapshot format MUST NOT have been defined already (e.g. from 895# CGI parameter sf) 896# It's also useless to try any matching unless $refname has a dot, 897# so we check for that too 898if(defined$input_params{'action'} && 899$input_params{'action'}eq'snapshot'&& 900defined$refname&&index($refname,'.') != -1&& 901$refnameeq$input_params{'hash'} && 902!defined$input_params{'snapshot_format'}) { 903# We loop over the known snapshot formats, checking for 904# extensions. Allowed extensions are both the defined suffix 905# (which includes the initial dot already) and the snapshot 906# format key itself, with a prepended dot 907while(my($fmt,$opt) =each%known_snapshot_formats) { 908my$hash=$refname; 909unless($hash=~s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { 910next; 911} 912my$sfx=$1; 913# a valid suffix was found, so set the snapshot format 914# and reset the hash parameter 915$input_params{'snapshot_format'} =$fmt; 916$input_params{'hash'} =$hash; 917# we also set the format suffix to the one requested 918# in the URL: this way a request for e.g. .tgz returns 919# a .tgz instead of a .tar.gz 920$known_snapshot_formats{$fmt}{'suffix'} =$sfx; 921last; 922} 923} 924} 925 926our($action,$project,$file_name,$file_parent,$hash,$hash_parent,$hash_base, 927$hash_parent_base,@extra_options,$page,$searchtype,$search_use_regexp, 928$searchtext,$search_regexp); 929sub evaluate_and_validate_params { 930our$action=$input_params{'action'}; 931if(defined$action) { 932if(!validate_action($action)) { 933 die_error(400,"Invalid action parameter"); 934} 935} 936 937# parameters which are pathnames 938our$project=$input_params{'project'}; 939if(defined$project) { 940if(!validate_project($project)) { 941undef$project; 942 die_error(404,"No such project"); 943} 944} 945 946our$file_name=$input_params{'file_name'}; 947if(defined$file_name) { 948if(!validate_pathname($file_name)) { 949 die_error(400,"Invalid file parameter"); 950} 951} 952 953our$file_parent=$input_params{'file_parent'}; 954if(defined$file_parent) { 955if(!validate_pathname($file_parent)) { 956 die_error(400,"Invalid file parent parameter"); 957} 958} 959 960# parameters which are refnames 961our$hash=$input_params{'hash'}; 962if(defined$hash) { 963if(!validate_refname($hash)) { 964 die_error(400,"Invalid hash parameter"); 965} 966} 967 968our$hash_parent=$input_params{'hash_parent'}; 969if(defined$hash_parent) { 970if(!validate_refname($hash_parent)) { 971 die_error(400,"Invalid hash parent parameter"); 972} 973} 974 975our$hash_base=$input_params{'hash_base'}; 976if(defined$hash_base) { 977if(!validate_refname($hash_base)) { 978 die_error(400,"Invalid hash base parameter"); 979} 980} 981 982our@extra_options= @{$input_params{'extra_options'}}; 983# @extra_options is always defined, since it can only be (currently) set from 984# CGI, and $cgi->param() returns the empty array in array context if the param 985# is not set 986foreachmy$opt(@extra_options) { 987if(not exists$allowed_options{$opt}) { 988 die_error(400,"Invalid option parameter"); 989} 990if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 991 die_error(400,"Invalid option parameter for this action"); 992} 993} 994 995our$hash_parent_base=$input_params{'hash_parent_base'}; 996if(defined$hash_parent_base) { 997if(!validate_refname($hash_parent_base)) { 998 die_error(400,"Invalid hash parent base parameter"); 999}1000}10011002# other parameters1003our$page=$input_params{'page'};1004if(defined$page) {1005if($page=~m/[^0-9]/) {1006 die_error(400,"Invalid page parameter");1007}1008}10091010our$searchtype=$input_params{'searchtype'};1011if(defined$searchtype) {1012if($searchtype=~m/[^a-z]/) {1013 die_error(400,"Invalid searchtype parameter");1014}1015}10161017our$search_use_regexp=$input_params{'search_use_regexp'};10181019our$searchtext=$input_params{'searchtext'};1020our$search_regexp;1021if(defined$searchtext) {1022if(length($searchtext) <2) {1023 die_error(403,"At least two characters are required for search parameter");1024}1025$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext;1026}1027}10281029# path to the current git repository1030our$git_dir;1031sub evaluate_git_dir {1032our$git_dir="$projectroot/$project"if$project;1033}10341035our(@snapshot_fmts,$git_avatar);1036sub configure_gitweb_features {1037# list of supported snapshot formats1038our@snapshot_fmts= gitweb_get_feature('snapshot');1039@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts);10401041# check that the avatar feature is set to a known provider name,1042# and for each provider check if the dependencies are satisfied.1043# if the provider name is invalid or the dependencies are not met,1044# reset $git_avatar to the empty string.1045our($git_avatar) = gitweb_get_feature('avatar');1046if($git_avatareq'gravatar') {1047$git_avatar=''unless(eval{require Digest::MD5;1; });1048}elsif($git_avatareq'picon') {1049# no dependencies1050}else{1051$git_avatar='';1052}1053}10541055# custom error handler: 'die <message>' is Internal Server Error1056sub handle_errors_html {1057my$msg=shift;# it is already HTML escaped10581059# to avoid infinite loop where error occurs in die_error,1060# change handler to default handler, disabling handle_errors_html1061 set_message("Error occured when inside die_error:\n$msg");10621063# you cannot jump out of die_error when called as error handler;1064# the subroutine set via CGI::Carp::set_message is called _after_1065# HTTP headers are already written, so it cannot write them itself1066 die_error(undef,undef,$msg, -error_handler =>1, -no_http_header =>1);1067}1068set_message(\&handle_errors_html);10691070# dispatch1071sub dispatch {1072if(!defined$action) {1073if(defined$hash) {1074$action= git_get_type($hash);1075}elsif(defined$hash_base&&defined$file_name) {1076$action= git_get_type("$hash_base:$file_name");1077}elsif(defined$project) {1078$action='summary';1079}else{1080$action='project_list';1081}1082}1083if(!defined($actions{$action})) {1084 die_error(400,"Unknown action");1085}1086if($action!~m/^(?:opml|project_list|project_index)$/&&1087!$project) {1088 die_error(400,"Project needed");1089}1090$actions{$action}->();1091}10921093sub reset_timer {1094our$t0= [ gettimeofday() ]1095ifdefined$t0;1096our$number_of_git_cmds=0;1097}10981099our$first_request=1;1100sub run_request {1101 reset_timer();11021103 evaluate_uri();1104if($first_request) {1105 evaluate_gitweb_config();1106 evaluate_git_version();1107}1108if($per_request_config) {1109if(ref($per_request_config)eq'CODE') {1110$per_request_config->();1111}elsif(!$first_request) {1112 evaluate_gitweb_config();1113}1114}1115 check_loadavg();11161117# $projectroot and $projects_list might be set in gitweb config file1118$projects_list||=$projectroot;11191120 evaluate_query_params();1121 evaluate_path_info();1122 evaluate_and_validate_params();1123 evaluate_git_dir();11241125 configure_gitweb_features();11261127 dispatch();1128}11291130our$is_last_request=sub{1};1131our($pre_dispatch_hook,$post_dispatch_hook,$pre_listen_hook);1132our$CGI='CGI';1133our$cgi;1134sub configure_as_fcgi {1135require CGI::Fast;1136our$CGI='CGI::Fast';11371138my$request_number=0;1139# let each child service 100 requests1140our$is_last_request=sub{ ++$request_number>100};1141}1142sub evaluate_argv {1143my$script_name=$ENV{'SCRIPT_NAME'} ||$ENV{'SCRIPT_FILENAME'} || __FILE__;1144 configure_as_fcgi()1145if$script_name=~/\.fcgi$/;11461147return unless(@ARGV);11481149require Getopt::Long;1150 Getopt::Long::GetOptions(1151'fastcgi|fcgi|f'=> \&configure_as_fcgi,1152'nproc|n=i'=>sub{1153my($arg,$val) =@_;1154return unlesseval{require FCGI::ProcManager;1; };1155my$proc_manager= FCGI::ProcManager->new({1156 n_processes =>$val,1157});1158our$pre_listen_hook=sub{$proc_manager->pm_manage() };1159our$pre_dispatch_hook=sub{$proc_manager->pm_pre_dispatch() };1160our$post_dispatch_hook=sub{$proc_manager->pm_post_dispatch() };1161},1162);1163}11641165sub run {1166 evaluate_argv();11671168$first_request=1;1169$pre_listen_hook->()1170if$pre_listen_hook;11711172 REQUEST:1173while($cgi=$CGI->new()) {1174$pre_dispatch_hook->()1175if$pre_dispatch_hook;11761177 run_request();11781179$post_dispatch_hook->()1180if$post_dispatch_hook;1181$first_request=0;11821183last REQUEST if($is_last_request->());1184}11851186 DONE_GITWEB:11871;1188}11891190run();11911192if(defined caller) {1193# wrapped in a subroutine processing requests,1194# e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI1195return;1196}else{1197# pure CGI script, serving single request1198exit;1199}12001201## ======================================================================1202## action links12031204# possible values of extra options1205# -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)1206# -replay => 1 - start from a current view (replay with modifications)1207# -path_info => 0|1 - don't use/use path_info URL (if possible)1208# -anchor => ANCHOR - add #ANCHOR to end of URL, implies -replay if used alone1209sub href {1210my%params=@_;1211# default is to use -absolute url() i.e. $my_uri1212my$href=$params{-full} ?$my_url:$my_uri;12131214# implicit -replay, must be first of implicit params1215$params{-replay} =1if(keys%params==1&&$params{-anchor});12161217$params{'project'} =$projectunlessexists$params{'project'};12181219if($params{-replay}) {1220while(my($name,$symbol) =each%cgi_param_mapping) {1221if(!exists$params{$name}) {1222$params{$name} =$input_params{$name};1223}1224}1225}12261227my$use_pathinfo= gitweb_check_feature('pathinfo');1228if(defined$params{'project'} &&1229(exists$params{-path_info} ?$params{-path_info} :$use_pathinfo)) {1230# try to put as many parameters as possible in PATH_INFO:1231# - project name1232# - action1233# - hash_parent or hash_parent_base:/file_parent1234# - hash or hash_base:/filename1235# - the snapshot_format as an appropriate suffix12361237# When the script is the root DirectoryIndex for the domain,1238# $href here would be something like http://gitweb.example.com/1239# Thus, we strip any trailing / from $href, to spare us double1240# slashes in the final URL1241$href=~ s,/$,,;12421243# Then add the project name, if present1244$href.="/".esc_path_info($params{'project'});1245delete$params{'project'};12461247# since we destructively absorb parameters, we keep this1248# boolean that remembers if we're handling a snapshot1249my$is_snapshot=$params{'action'}eq'snapshot';12501251# Summary just uses the project path URL, any other action is1252# added to the URL1253if(defined$params{'action'}) {1254$href.="/".esc_path_info($params{'action'})1255unless$params{'action'}eq'summary';1256delete$params{'action'};1257}12581259# Next, we put hash_parent_base:/file_parent..hash_base:/file_name,1260# stripping nonexistent or useless pieces1261$href.="/"if($params{'hash_base'} ||$params{'hash_parent_base'}1262||$params{'hash_parent'} ||$params{'hash'});1263if(defined$params{'hash_base'}) {1264if(defined$params{'hash_parent_base'}) {1265$href.= esc_path_info($params{'hash_parent_base'});1266# skip the file_parent if it's the same as the file_name1267if(defined$params{'file_parent'}) {1268if(defined$params{'file_name'} &&$params{'file_parent'}eq$params{'file_name'}) {1269delete$params{'file_parent'};1270}elsif($params{'file_parent'} !~/\.\./) {1271$href.=":/".esc_path_info($params{'file_parent'});1272delete$params{'file_parent'};1273}1274}1275$href.="..";1276delete$params{'hash_parent'};1277delete$params{'hash_parent_base'};1278}elsif(defined$params{'hash_parent'}) {1279$href.= esc_path_info($params{'hash_parent'})."..";1280delete$params{'hash_parent'};1281}12821283$href.= esc_path_info($params{'hash_base'});1284if(defined$params{'file_name'} &&$params{'file_name'} !~/\.\./) {1285$href.=":/".esc_path_info($params{'file_name'});1286delete$params{'file_name'};1287}1288delete$params{'hash'};1289delete$params{'hash_base'};1290}elsif(defined$params{'hash'}) {1291$href.= esc_path_info($params{'hash'});1292delete$params{'hash'};1293}12941295# If the action was a snapshot, we can absorb the1296# snapshot_format parameter too1297if($is_snapshot) {1298my$fmt=$params{'snapshot_format'};1299# snapshot_format should always be defined when href()1300# is called, but just in case some code forgets, we1301# fall back to the default1302$fmt||=$snapshot_fmts[0];1303$href.=$known_snapshot_formats{$fmt}{'suffix'};1304delete$params{'snapshot_format'};1305}1306}13071308# now encode the parameters explicitly1309my@result= ();1310for(my$i=0;$i<@cgi_param_mapping;$i+=2) {1311my($name,$symbol) = ($cgi_param_mapping[$i],$cgi_param_mapping[$i+1]);1312if(defined$params{$name}) {1313if(ref($params{$name})eq"ARRAY") {1314foreachmy$par(@{$params{$name}}) {1315push@result,$symbol."=". esc_param($par);1316}1317}else{1318push@result,$symbol."=". esc_param($params{$name});1319}1320}1321}1322$href.="?".join(';',@result)ifscalar@result;13231324# final transformation: trailing spaces must be escaped (URI-encoded)1325$href=~s/(\s+)$/CGI::escape($1)/e;13261327if($params{-anchor}) {1328$href.="#".esc_param($params{-anchor});1329}13301331return$href;1332}133313341335## ======================================================================1336## validation, quoting/unquoting and escaping13371338sub validate_action {1339my$input=shift||returnundef;1340returnundefunlessexists$actions{$input};1341return$input;1342}13431344sub validate_project {1345my$input=shift||returnundef;1346if(!validate_pathname($input) ||1347!(-d "$projectroot/$input") ||1348!check_export_ok("$projectroot/$input") ||1349($strict_export&& !project_in_list($input))) {1350returnundef;1351}else{1352return$input;1353}1354}13551356sub validate_pathname {1357my$input=shift||returnundef;13581359# no '.' or '..' as elements of path, i.e. no '.' nor '..'1360# at the beginning, at the end, and between slashes.1361# also this catches doubled slashes1362if($input=~m!(^|/)(|\.|\.\.)(/|$)!) {1363returnundef;1364}1365# no null characters1366if($input=~m!\0!) {1367returnundef;1368}1369return$input;1370}13711372sub validate_refname {1373my$input=shift||returnundef;13741375# textual hashes are O.K.1376if($input=~m/^[0-9a-fA-F]{40}$/) {1377return$input;1378}1379# it must be correct pathname1380$input= validate_pathname($input)1381orreturnundef;1382# restrictions on ref name according to git-check-ref-format1383if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {1384returnundef;1385}1386return$input;1387}13881389# decode sequences of octets in utf8 into Perl's internal form,1390# which is utf-8 with utf8 flag set if needed. gitweb writes out1391# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning1392sub to_utf8 {1393my$str=shift;1394returnundefunlessdefined$str;1395if(utf8::valid($str)) {1396 utf8::decode($str);1397return$str;1398}else{1399return decode($fallback_encoding,$str, Encode::FB_DEFAULT);1400}1401}14021403# quote unsafe chars, but keep the slash, even when it's not1404# correct, but quoted slashes look too horrible in bookmarks1405sub esc_param {1406my$str=shift;1407returnundefunlessdefined$str;1408$str=~s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;1409$str=~s/ /\+/g;1410return$str;1411}14121413# the quoting rules for path_info fragment are slightly different1414sub esc_path_info {1415my$str=shift;1416returnundefunlessdefined$str;14171418# path_info doesn't treat '+' as space (specially), but '?' must be escaped1419$str=~s/([^A-Za-z0-9\-_.~();\/;:@&= +]+)/CGI::escape($1)/eg;14201421return$str;1422}14231424# quote unsafe chars in whole URL, so some characters cannot be quoted1425sub esc_url {1426my$str=shift;1427returnundefunlessdefined$str;1428$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg;1429$str=~s/ /\+/g;1430return$str;1431}14321433# quote unsafe characters in HTML attributes1434sub esc_attr {14351436# for XHTML conformance escaping '"' to '"' is not enough1437return esc_html(@_);1438}14391440# replace invalid utf8 character with SUBSTITUTION sequence1441sub esc_html {1442my$str=shift;1443my%opts=@_;14441445returnundefunlessdefined$str;14461447$str= to_utf8($str);1448$str=$cgi->escapeHTML($str);1449if($opts{'-nbsp'}) {1450$str=~s/ / /g;1451}1452$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg;1453return$str;1454}14551456# quote control characters and escape filename to HTML1457sub esc_path {1458my$str=shift;1459my%opts=@_;14601461returnundefunlessdefined$str;14621463$str= to_utf8($str);1464$str=$cgi->escapeHTML($str);1465if($opts{'-nbsp'}) {1466$str=~s/ / /g;1467}1468$str=~ s|([[:cntrl:]])|quot_cec($1)|eg;1469return$str;1470}14711472# Make control characters "printable", using character escape codes (CEC)1473sub quot_cec {1474my$cntrl=shift;1475my%opts=@_;1476my%es= (# character escape codes, aka escape sequences1477"\t"=>'\t',# tab (HT)1478"\n"=>'\n',# line feed (LF)1479"\r"=>'\r',# carrige return (CR)1480"\f"=>'\f',# form feed (FF)1481"\b"=>'\b',# backspace (BS)1482"\a"=>'\a',# alarm (bell) (BEL)1483"\e"=>'\e',# escape (ESC)1484"\013"=>'\v',# vertical tab (VT)1485"\000"=>'\0',# nul character (NUL)1486);1487my$chr= ( (exists$es{$cntrl})1488?$es{$cntrl}1489:sprintf('\%2x',ord($cntrl)) );1490if($opts{-nohtml}) {1491return$chr;1492}else{1493return"<span class=\"cntrl\">$chr</span>";1494}1495}14961497# Alternatively use unicode control pictures codepoints,1498# Unicode "printable representation" (PR)1499sub quot_upr {1500my$cntrl=shift;1501my%opts=@_;15021503my$chr=sprintf('&#%04d;',0x2400+ord($cntrl));1504if($opts{-nohtml}) {1505return$chr;1506}else{1507return"<span class=\"cntrl\">$chr</span>";1508}1509}15101511# git may return quoted and escaped filenames1512sub unquote {1513my$str=shift;15141515sub unq {1516my$seq=shift;1517my%es= (# character escape codes, aka escape sequences1518't'=>"\t",# tab (HT, TAB)1519'n'=>"\n",# newline (NL)1520'r'=>"\r",# return (CR)1521'f'=>"\f",# form feed (FF)1522'b'=>"\b",# backspace (BS)1523'a'=>"\a",# alarm (bell) (BEL)1524'e'=>"\e",# escape (ESC)1525'v'=>"\013",# vertical tab (VT)1526);15271528if($seq=~m/^[0-7]{1,3}$/) {1529# octal char sequence1530returnchr(oct($seq));1531}elsif(exists$es{$seq}) {1532# C escape sequence, aka character escape code1533return$es{$seq};1534}1535# quoted ordinary character1536return$seq;1537}15381539if($str=~m/^"(.*)"$/) {1540# needs unquoting1541$str=$1;1542$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;1543}1544return$str;1545}15461547# escape tabs (convert tabs to spaces)1548sub untabify {1549my$line=shift;15501551while((my$pos=index($line,"\t")) != -1) {1552if(my$count= (8- ($pos%8))) {1553my$spaces=' ' x $count;1554$line=~s/\t/$spaces/;1555}1556}15571558return$line;1559}15601561sub project_in_list {1562my$project=shift;1563my@list= git_get_projects_list();1564return@list&&scalar(grep{$_->{'path'}eq$project}@list);1565}15661567## ----------------------------------------------------------------------1568## HTML aware string manipulation15691570# Try to chop given string on a word boundary between position1571# $len and $len+$add_len. If there is no word boundary there,1572# chop at $len+$add_len. Do not chop if chopped part plus ellipsis1573# (marking chopped part) would be longer than given string.1574sub chop_str {1575my$str=shift;1576my$len=shift;1577my$add_len=shift||10;1578my$where=shift||'right';# 'left' | 'center' | 'right'15791580# Make sure perl knows it is utf8 encoded so we don't1581# cut in the middle of a utf8 multibyte char.1582$str= to_utf8($str);15831584# allow only $len chars, but don't cut a word if it would fit in $add_len1585# if it doesn't fit, cut it if it's still longer than the dots we would add1586# remove chopped character entities entirely15871588# when chopping in the middle, distribute $len into left and right part1589# return early if chopping wouldn't make string shorter1590if($whereeq'center') {1591return$strif($len+5>=length($str));# filler is length 51592$len=int($len/2);1593}else{1594return$strif($len+4>=length($str));# filler is length 41595}15961597# regexps: ending and beginning with word part up to $add_len1598my$endre=qr/.{$len}\w{0,$add_len}/;1599my$begre=qr/\w{0,$add_len}.{$len}/;16001601if($whereeq'left') {1602$str=~m/^(.*?)($begre)$/;1603my($lead,$body) = ($1,$2);1604if(length($lead) >4) {1605$lead=" ...";1606}1607return"$lead$body";16081609}elsif($whereeq'center') {1610$str=~m/^($endre)(.*)$/;1611my($left,$str) = ($1,$2);1612$str=~m/^(.*?)($begre)$/;1613my($mid,$right) = ($1,$2);1614if(length($mid) >5) {1615$mid=" ... ";1616}1617return"$left$mid$right";16181619}else{1620$str=~m/^($endre)(.*)$/;1621my$body=$1;1622my$tail=$2;1623if(length($tail) >4) {1624$tail="... ";1625}1626return"$body$tail";1627}1628}16291630# takes the same arguments as chop_str, but also wraps a <span> around the1631# result with a title attribute if it does get chopped. Additionally, the1632# string is HTML-escaped.1633sub chop_and_escape_str {1634my($str) =@_;16351636my$chopped= chop_str(@_);1637if($choppedeq$str) {1638return esc_html($chopped);1639}else{1640$str=~s/[[:cntrl:]]/?/g;1641return$cgi->span({-title=>$str}, esc_html($chopped));1642}1643}16441645## ----------------------------------------------------------------------1646## functions returning short strings16471648# CSS class for given age value (in seconds)1649sub age_class {1650my$age=shift;16511652if(!defined$age) {1653return"noage";1654}elsif($age<60*60*2) {1655return"age0";1656}elsif($age<60*60*24*2) {1657return"age1";1658}else{1659return"age2";1660}1661}16621663# convert age in seconds to "nn units ago" string1664sub age_string {1665my$age=shift;1666my$age_str;16671668if($age>60*60*24*365*2) {1669$age_str= (int$age/60/60/24/365);1670$age_str.=" years ago";1671}elsif($age>60*60*24*(365/12)*2) {1672$age_str=int$age/60/60/24/(365/12);1673$age_str.=" months ago";1674}elsif($age>60*60*24*7*2) {1675$age_str=int$age/60/60/24/7;1676$age_str.=" weeks ago";1677}elsif($age>60*60*24*2) {1678$age_str=int$age/60/60/24;1679$age_str.=" days ago";1680}elsif($age>60*60*2) {1681$age_str=int$age/60/60;1682$age_str.=" hours ago";1683}elsif($age>60*2) {1684$age_str=int$age/60;1685$age_str.=" min ago";1686}elsif($age>2) {1687$age_str=int$age;1688$age_str.=" sec ago";1689}else{1690$age_str.=" right now";1691}1692return$age_str;1693}16941695useconstant{1696 S_IFINVALID =>0030000,1697 S_IFGITLINK =>0160000,1698};16991700# submodule/subproject, a commit object reference1701sub S_ISGITLINK {1702my$mode=shift;17031704return(($mode& S_IFMT) == S_IFGITLINK)1705}17061707# convert file mode in octal to symbolic file mode string1708sub mode_str {1709my$mode=oct shift;17101711if(S_ISGITLINK($mode)) {1712return'm---------';1713}elsif(S_ISDIR($mode& S_IFMT)) {1714return'drwxr-xr-x';1715}elsif(S_ISLNK($mode)) {1716return'lrwxrwxrwx';1717}elsif(S_ISREG($mode)) {1718# git cares only about the executable bit1719if($mode& S_IXUSR) {1720return'-rwxr-xr-x';1721}else{1722return'-rw-r--r--';1723};1724}else{1725return'----------';1726}1727}17281729# convert file mode in octal to file type string1730sub file_type {1731my$mode=shift;17321733if($mode!~m/^[0-7]+$/) {1734return$mode;1735}else{1736$mode=oct$mode;1737}17381739if(S_ISGITLINK($mode)) {1740return"submodule";1741}elsif(S_ISDIR($mode& S_IFMT)) {1742return"directory";1743}elsif(S_ISLNK($mode)) {1744return"symlink";1745}elsif(S_ISREG($mode)) {1746return"file";1747}else{1748return"unknown";1749}1750}17511752# convert file mode in octal to file type description string1753sub file_type_long {1754my$mode=shift;17551756if($mode!~m/^[0-7]+$/) {1757return$mode;1758}else{1759$mode=oct$mode;1760}17611762if(S_ISGITLINK($mode)) {1763return"submodule";1764}elsif(S_ISDIR($mode& S_IFMT)) {1765return"directory";1766}elsif(S_ISLNK($mode)) {1767return"symlink";1768}elsif(S_ISREG($mode)) {1769if($mode& S_IXUSR) {1770return"executable";1771}else{1772return"file";1773};1774}else{1775return"unknown";1776}1777}177817791780## ----------------------------------------------------------------------1781## functions returning short HTML fragments, or transforming HTML fragments1782## which don't belong to other sections17831784# format line of commit message.1785sub format_log_line_html {1786my$line=shift;17871788$line= esc_html($line, -nbsp=>1);1789$line=~ s{\b([0-9a-fA-F]{8,40})\b}{1790$cgi->a({-href => href(action=>"object", hash=>$1),1791-class=>"text"},$1);1792}eg;17931794return$line;1795}17961797# format marker of refs pointing to given object17981799# the destination action is chosen based on object type and current context:1800# - for annotated tags, we choose the tag view unless it's the current view1801# already, in which case we go to shortlog view1802# - for other refs, we keep the current view if we're in history, shortlog or1803# log view, and select shortlog otherwise1804sub format_ref_marker {1805my($refs,$id) =@_;1806my$markers='';18071808if(defined$refs->{$id}) {1809foreachmy$ref(@{$refs->{$id}}) {1810# this code exploits the fact that non-lightweight tags are the1811# only indirect objects, and that they are the only objects for which1812# we want to use tag instead of shortlog as action1813my($type,$name) =qw();1814my$indirect= ($ref=~s/\^\{\}$//);1815# e.g. tags/v2.6.11 or heads/next1816if($ref=~m!^(.*?)s?/(.*)$!) {1817$type=$1;1818$name=$2;1819}else{1820$type="ref";1821$name=$ref;1822}18231824my$class=$type;1825$class.=" indirect"if$indirect;18261827my$dest_action="shortlog";18281829if($indirect) {1830$dest_action="tag"unless$actioneq"tag";1831}elsif($action=~/^(history|(short)?log)$/) {1832$dest_action=$action;1833}18341835my$dest="";1836$dest.="refs/"unless$ref=~ m!^refs/!;1837$dest.=$ref;18381839my$link=$cgi->a({1840-href => href(1841 action=>$dest_action,1842 hash=>$dest1843)},$name);18441845$markers.=" <span class=\"".esc_attr($class)."\"title=\"".esc_attr($ref)."\">".1846$link."</span>";1847}1848}18491850if($markers) {1851return' <span class="refs">'.$markers.'</span>';1852}else{1853return"";1854}1855}18561857# format, perhaps shortened and with markers, title line1858sub format_subject_html {1859my($long,$short,$href,$extra) =@_;1860$extra=''unlessdefined($extra);18611862if(length($short) <length($long)) {1863$long=~s/[[:cntrl:]]/?/g;1864return$cgi->a({-href =>$href, -class=>"list subject",1865-title => to_utf8($long)},1866 esc_html($short)) .$extra;1867}else{1868return$cgi->a({-href =>$href, -class=>"list subject"},1869 esc_html($long)) .$extra;1870}1871}18721873# Rather than recomputing the url for an email multiple times, we cache it1874# after the first hit. This gives a visible benefit in views where the avatar1875# for the same email is used repeatedly (e.g. shortlog).1876# The cache is shared by all avatar engines (currently gravatar only), which1877# are free to use it as preferred. Since only one avatar engine is used for any1878# given page, there's no risk for cache conflicts.1879our%avatar_cache= ();18801881# Compute the picon url for a given email, by using the picon search service over at1882# http://www.cs.indiana.edu/picons/search.html1883sub picon_url {1884my$email=lc shift;1885if(!$avatar_cache{$email}) {1886my($user,$domain) =split('@',$email);1887$avatar_cache{$email} =1888"http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/".1889"$domain/$user/".1890"users+domains+unknown/up/single";1891}1892return$avatar_cache{$email};1893}18941895# Compute the gravatar url for a given email, if it's not in the cache already.1896# Gravatar stores only the part of the URL before the size, since that's the1897# one computationally more expensive. This also allows reuse of the cache for1898# different sizes (for this particular engine).1899sub gravatar_url {1900my$email=lc shift;1901my$size=shift;1902$avatar_cache{$email} ||=1903"http://www.gravatar.com/avatar/".1904 Digest::MD5::md5_hex($email) ."?s=";1905return$avatar_cache{$email} .$size;1906}19071908# Insert an avatar for the given $email at the given $size if the feature1909# is enabled.1910sub git_get_avatar {1911my($email,%opts) =@_;1912my$pre_white= ($opts{-pad_before} ?" ":"");1913my$post_white= ($opts{-pad_after} ?" ":"");1914$opts{-size} ||='default';1915my$size=$avatar_size{$opts{-size}} ||$avatar_size{'default'};1916my$url="";1917if($git_avatareq'gravatar') {1918$url= gravatar_url($email,$size);1919}elsif($git_avatareq'picon') {1920$url= picon_url($email);1921}1922# Other providers can be added by extending the if chain, defining $url1923# as needed. If no variant puts something in $url, we assume avatars1924# are completely disabled/unavailable.1925if($url) {1926return$pre_white.1927"<img width=\"$size\"".1928"class=\"avatar\"".1929"src=\"".esc_url($url)."\"".1930"alt=\"\"".1931"/>".$post_white;1932}else{1933return"";1934}1935}19361937sub format_search_author {1938my($author,$searchtype,$displaytext) =@_;1939my$have_search= gitweb_check_feature('search');19401941if($have_search) {1942my$performed="";1943if($searchtypeeq'author') {1944$performed="authored";1945}elsif($searchtypeeq'committer') {1946$performed="committed";1947}19481949return$cgi->a({-href => href(action=>"search", hash=>$hash,1950 searchtext=>$author,1951 searchtype=>$searchtype),class=>"list",1952 title=>"Search for commits$performedby$author"},1953$displaytext);19541955}else{1956return$displaytext;1957}1958}19591960# format the author name of the given commit with the given tag1961# the author name is chopped and escaped according to the other1962# optional parameters (see chop_str).1963sub format_author_html {1964my$tag=shift;1965my$co=shift;1966my$author= chop_and_escape_str($co->{'author_name'},@_);1967return"<$tagclass=\"author\">".1968 format_search_author($co->{'author_name'},"author",1969 git_get_avatar($co->{'author_email'}, -pad_after =>1) .1970$author) .1971"</$tag>";1972}19731974# format git diff header line, i.e. "diff --(git|combined|cc) ..."1975sub format_git_diff_header_line {1976my$line=shift;1977my$diffinfo=shift;1978my($from,$to) =@_;19791980if($diffinfo->{'nparents'}) {1981# combined diff1982$line=~s!^(diff (.*?) )"?.*$!$1!;1983if($to->{'href'}) {1984$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1985 esc_path($to->{'file'}));1986}else{# file was deleted (no href)1987$line.= esc_path($to->{'file'});1988}1989}else{1990# "ordinary" diff1991$line=~s!^(diff (.*?) )"?a/.*$!$1!;1992if($from->{'href'}) {1993$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1994'a/'. esc_path($from->{'file'}));1995}else{# file was added (no href)1996$line.='a/'. esc_path($from->{'file'});1997}1998$line.=' ';1999if($to->{'href'}) {2000$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},2001'b/'. esc_path($to->{'file'}));2002}else{# file was deleted2003$line.='b/'. esc_path($to->{'file'});2004}2005}20062007return"<div class=\"diff header\">$line</div>\n";2008}20092010# format extended diff header line, before patch itself2011sub format_extended_diff_header_line {2012my$line=shift;2013my$diffinfo=shift;2014my($from,$to) =@_;20152016# match <path>2017if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {2018$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},2019 esc_path($from->{'file'}));2020}2021if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {2022$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},2023 esc_path($to->{'file'}));2024}2025# match single <mode>2026if($line=~m/\s(\d{6})$/) {2027$line.='<span class="info"> ('.2028 file_type_long($1) .2029')</span>';2030}2031# match <hash>2032if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {2033# can match only for combined diff2034$line='index ';2035for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2036if($from->{'href'}[$i]) {2037$line.=$cgi->a({-href=>$from->{'href'}[$i],2038-class=>"hash"},2039substr($diffinfo->{'from_id'}[$i],0,7));2040}else{2041$line.='0' x 7;2042}2043# separator2044$line.=','if($i<$diffinfo->{'nparents'} -1);2045}2046$line.='..';2047if($to->{'href'}) {2048$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2049substr($diffinfo->{'to_id'},0,7));2050}else{2051$line.='0' x 7;2052}20532054}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {2055# can match only for ordinary diff2056my($from_link,$to_link);2057if($from->{'href'}) {2058$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},2059substr($diffinfo->{'from_id'},0,7));2060}else{2061$from_link='0' x 7;2062}2063if($to->{'href'}) {2064$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},2065substr($diffinfo->{'to_id'},0,7));2066}else{2067$to_link='0' x 7;2068}2069my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});2070$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;2071}20722073return$line."<br/>\n";2074}20752076# format from-file/to-file diff header2077sub format_diff_from_to_header {2078my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;2079my$line;2080my$result='';20812082$line=$from_line;2083#assert($line =~ m/^---/) if DEBUG;2084# no extra formatting for "^--- /dev/null"2085if(!$diffinfo->{'nparents'}) {2086# ordinary (single parent) diff2087if($line=~m!^--- "?a/!) {2088if($from->{'href'}) {2089$line='--- a/'.2090$cgi->a({-href=>$from->{'href'}, -class=>"path"},2091 esc_path($from->{'file'}));2092}else{2093$line='--- a/'.2094 esc_path($from->{'file'});2095}2096}2097$result.= qq!<div class="diff from_file">$line</div>\n!;20982099}else{2100# combined diff (merge commit)2101for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2102if($from->{'href'}[$i]) {2103$line='--- '.2104$cgi->a({-href=>href(action=>"blobdiff",2105 hash_parent=>$diffinfo->{'from_id'}[$i],2106 hash_parent_base=>$parents[$i],2107 file_parent=>$from->{'file'}[$i],2108 hash=>$diffinfo->{'to_id'},2109 hash_base=>$hash,2110 file_name=>$to->{'file'}),2111-class=>"path",2112-title=>"diff". ($i+1)},2113$i+1) .2114'/'.2115$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},2116 esc_path($from->{'file'}[$i]));2117}else{2118$line='--- /dev/null';2119}2120$result.= qq!<div class="diff from_file">$line</div>\n!;2121}2122}21232124$line=$to_line;2125#assert($line =~ m/^\+\+\+/) if DEBUG;2126# no extra formatting for "^+++ /dev/null"2127if($line=~m!^\+\+\+ "?b/!) {2128if($to->{'href'}) {2129$line='+++ b/'.2130$cgi->a({-href=>$to->{'href'}, -class=>"path"},2131 esc_path($to->{'file'}));2132}else{2133$line='+++ b/'.2134 esc_path($to->{'file'});2135}2136}2137$result.= qq!<div class="diff to_file">$line</div>\n!;21382139return$result;2140}21412142# create note for patch simplified by combined diff2143sub format_diff_cc_simplified {2144my($diffinfo,@parents) =@_;2145my$result='';21462147$result.="<div class=\"diff header\">".2148"diff --cc ";2149if(!is_deleted($diffinfo)) {2150$result.=$cgi->a({-href => href(action=>"blob",2151 hash_base=>$hash,2152 hash=>$diffinfo->{'to_id'},2153 file_name=>$diffinfo->{'to_file'}),2154-class=>"path"},2155 esc_path($diffinfo->{'to_file'}));2156}else{2157$result.= esc_path($diffinfo->{'to_file'});2158}2159$result.="</div>\n".# class="diff header"2160"<div class=\"diff nodifferences\">".2161"Simple merge".2162"</div>\n";# class="diff nodifferences"21632164return$result;2165}21662167# format patch (diff) line (not to be used for diff headers)2168sub format_diff_line {2169my$line=shift;2170my($from,$to) =@_;2171my$diff_class="";21722173chomp$line;21742175if($from&&$to&&ref($from->{'href'})eq"ARRAY") {2176# combined diff2177my$prefix=substr($line,0,scalar@{$from->{'href'}});2178if($line=~m/^\@{3}/) {2179$diff_class=" chunk_header";2180}elsif($line=~m/^\\/) {2181$diff_class=" incomplete";2182}elsif($prefix=~tr/+/+/) {2183$diff_class=" add";2184}elsif($prefix=~tr/-/-/) {2185$diff_class=" rem";2186}2187}else{2188# assume ordinary diff2189my$char=substr($line,0,1);2190if($chareq'+') {2191$diff_class=" add";2192}elsif($chareq'-') {2193$diff_class=" rem";2194}elsif($chareq'@') {2195$diff_class=" chunk_header";2196}elsif($chareq"\\") {2197$diff_class=" incomplete";2198}2199}2200$line= untabify($line);2201if($from&&$to&&$line=~m/^\@{2} /) {2202my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =2203$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;22042205$from_lines=0unlessdefined$from_lines;2206$to_lines=0unlessdefined$to_lines;22072208if($from->{'href'}) {2209$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",2210-class=>"list"},$from_text);2211}2212if($to->{'href'}) {2213$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",2214-class=>"list"},$to_text);2215}2216$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".2217"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2218return"<div class=\"diff$diff_class\">$line</div>\n";2219}elsif($from&&$to&&$line=~m/^\@{3}/) {2220my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;2221my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);22222223@from_text=split(' ',$ranges);2224for(my$i=0;$i<@from_text; ++$i) {2225($from_start[$i],$from_nlines[$i]) =2226(split(',',substr($from_text[$i],1)),0);2227}22282229$to_text=pop@from_text;2230$to_start=pop@from_start;2231$to_nlines=pop@from_nlines;22322233$line="<span class=\"chunk_info\">$prefix";2234for(my$i=0;$i<@from_text; ++$i) {2235if($from->{'href'}[$i]) {2236$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",2237-class=>"list"},$from_text[$i]);2238}else{2239$line.=$from_text[$i];2240}2241$line.=" ";2242}2243if($to->{'href'}) {2244$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",2245-class=>"list"},$to_text);2246}else{2247$line.=$to_text;2248}2249$line.="$prefix</span>".2250"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";2251return"<div class=\"diff$diff_class\">$line</div>\n";2252}2253return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";2254}22552256# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",2257# linked. Pass the hash of the tree/commit to snapshot.2258sub format_snapshot_links {2259my($hash) =@_;2260my$num_fmts=@snapshot_fmts;2261if($num_fmts>1) {2262# A parenthesized list of links bearing format names.2263# e.g. "snapshot (_tar.gz_ _zip_)"2264return"snapshot (".join(' ',map2265$cgi->a({2266-href => href(2267 action=>"snapshot",2268 hash=>$hash,2269 snapshot_format=>$_2270)2271},$known_snapshot_formats{$_}{'display'})2272,@snapshot_fmts) .")";2273}elsif($num_fmts==1) {2274# A single "snapshot" link whose tooltip bears the format name.2275# i.e. "_snapshot_"2276my($fmt) =@snapshot_fmts;2277return2278$cgi->a({2279-href => href(2280 action=>"snapshot",2281 hash=>$hash,2282 snapshot_format=>$fmt2283),2284-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"2285},"snapshot");2286}else{# $num_fmts == 02287returnundef;2288}2289}22902291## ......................................................................2292## functions returning values to be passed, perhaps after some2293## transformation, to other functions; e.g. returning arguments to href()22942295# returns hash to be passed to href to generate gitweb URL2296# in -title key it returns description of link2297sub get_feed_info {2298my$format=shift||'Atom';2299my%res= (action =>lc($format));23002301# feed links are possible only for project views2302return unless(defined$project);2303# some views should link to OPML, or to generic project feed,2304# or don't have specific feed yet (so they should use generic)2305return if($action=~/^(?:tags|heads|forks|tag|search)$/x);23062307my$branch;2308# branches refs uses 'refs/heads/' prefix (fullname) to differentiate2309# from tag links; this also makes possible to detect branch links2310if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||2311(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {2312$branch=$1;2313}2314# find log type for feed description (title)2315my$type='log';2316if(defined$file_name) {2317$type="history of$file_name";2318$type.="/"if($actioneq'tree');2319$type.=" on '$branch'"if(defined$branch);2320}else{2321$type="log of$branch"if(defined$branch);2322}23232324$res{-title} =$type;2325$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);2326$res{'file_name'} =$file_name;23272328return%res;2329}23302331## ----------------------------------------------------------------------2332## git utility subroutines, invoking git commands23332334# returns path to the core git executable and the --git-dir parameter as list2335sub git_cmd {2336$number_of_git_cmds++;2337return$GIT,'--git-dir='.$git_dir;2338}23392340# quote the given arguments for passing them to the shell2341# quote_command("command", "arg 1", "arg with ' and ! characters")2342# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"2343# Try to avoid using this function wherever possible.2344sub quote_command {2345returnjoin(' ',2346map{my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_);2347}23482349# get HEAD ref of given project as hash2350sub git_get_head_hash {2351return git_get_full_hash(shift,'HEAD');2352}23532354sub git_get_full_hash {2355return git_get_hash(@_);2356}23572358sub git_get_short_hash {2359return git_get_hash(@_,'--short=7');2360}23612362sub git_get_hash {2363my($project,$hash,@options) =@_;2364my$o_git_dir=$git_dir;2365my$retval=undef;2366$git_dir="$projectroot/$project";2367if(open my$fd,'-|', git_cmd(),'rev-parse',2368'--verify','-q',@options,$hash) {2369$retval= <$fd>;2370chomp$retvalifdefined$retval;2371close$fd;2372}2373if(defined$o_git_dir) {2374$git_dir=$o_git_dir;2375}2376return$retval;2377}23782379# get type of given object2380sub git_get_type {2381my$hash=shift;23822383open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;2384my$type= <$fd>;2385close$fdorreturn;2386chomp$type;2387return$type;2388}23892390# repository configuration2391our$config_file='';2392our%config;23932394# store multiple values for single key as anonymous array reference2395# single values stored directly in the hash, not as [ <value> ]2396sub hash_set_multi {2397my($hash,$key,$value) =@_;23982399if(!exists$hash->{$key}) {2400$hash->{$key} =$value;2401}elsif(!ref$hash->{$key}) {2402$hash->{$key} = [$hash->{$key},$value];2403}else{2404push@{$hash->{$key}},$value;2405}2406}24072408# return hash of git project configuration2409# optionally limited to some section, e.g. 'gitweb'2410sub git_parse_project_config {2411my$section_regexp=shift;2412my%config;24132414local$/="\0";24152416open my$fh,"-|", git_cmd(),"config",'-z','-l',2417orreturn;24182419while(my$keyval= <$fh>) {2420chomp$keyval;2421my($key,$value) =split(/\n/,$keyval,2);24222423 hash_set_multi(\%config,$key,$value)2424if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);2425}2426close$fh;24272428return%config;2429}24302431# convert config value to boolean: 'true' or 'false'2432# no value, number > 0, 'true' and 'yes' values are true2433# rest of values are treated as false (never as error)2434sub config_to_bool {2435my$val=shift;24362437return1if!defined$val;# section.key24382439# strip leading and trailing whitespace2440$val=~s/^\s+//;2441$val=~s/\s+$//;24422443return(($val=~/^\d+$/&&$val) ||# section.key = 12444($val=~/^(?:true|yes)$/i));# section.key = true2445}24462447# convert config value to simple decimal number2448# an optional value suffix of 'k', 'm', or 'g' will cause the value2449# to be multiplied by 1024, 1048576, or 10737418242450sub config_to_int {2451my$val=shift;24522453# strip leading and trailing whitespace2454$val=~s/^\s+//;2455$val=~s/\s+$//;24562457if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {2458$unit=lc($unit);2459# unknown unit is treated as 12460return$num* ($uniteq'g'?1073741824:2461$uniteq'm'?1048576:2462$uniteq'k'?1024:1);2463}2464return$val;2465}24662467# convert config value to array reference, if needed2468sub config_to_multi {2469my$val=shift;24702471returnref($val) ?$val: (defined($val) ? [$val] : []);2472}24732474sub git_get_project_config {2475my($key,$type) =@_;24762477return unlessdefined$git_dir;24782479# key sanity check2480return unless($key);2481$key=~s/^gitweb\.//;2482return if($key=~m/\W/);24832484# type sanity check2485if(defined$type) {2486$type=~s/^--//;2487$type=undef2488unless($typeeq'bool'||$typeeq'int');2489}24902491# get config2492if(!defined$config_file||2493$config_filene"$git_dir/config") {2494%config= git_parse_project_config('gitweb');2495$config_file="$git_dir/config";2496}24972498# check if config variable (key) exists2499return unlessexists$config{"gitweb.$key"};25002501# ensure given type2502if(!defined$type) {2503return$config{"gitweb.$key"};2504}elsif($typeeq'bool') {2505# backward compatibility: 'git config --bool' returns true/false2506return config_to_bool($config{"gitweb.$key"}) ?'true':'false';2507}elsif($typeeq'int') {2508return config_to_int($config{"gitweb.$key"});2509}2510return$config{"gitweb.$key"};2511}25122513# get hash of given path at given ref2514sub git_get_hash_by_path {2515my$base=shift;2516my$path=shift||returnundef;2517my$type=shift;25182519$path=~ s,/+$,,;25202521open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path2522or die_error(500,"Open git-ls-tree failed");2523my$line= <$fd>;2524close$fdorreturnundef;25252526if(!defined$line) {2527# there is no tree or hash given by $path at $base2528returnundef;2529}25302531#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2532$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;2533if(defined$type&&$typene$2) {2534# type doesn't match2535returnundef;2536}2537return$3;2538}25392540# get path of entry with given hash at given tree-ish (ref)2541# used to get 'from' filename for combined diff (merge commit) for renames2542sub git_get_path_by_hash {2543my$base=shift||return;2544my$hash=shift||return;25452546local$/="\0";25472548open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base2549orreturnundef;2550while(my$line= <$fd>) {2551chomp$line;25522553#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'2554#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'2555if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {2556close$fd;2557return$1;2558}2559}2560close$fd;2561returnundef;2562}25632564## ......................................................................2565## git utility functions, directly accessing git repository25662567sub git_get_project_description {2568my$path=shift;25692570$git_dir="$projectroot/$path";2571open my$fd,'<',"$git_dir/description"2572orreturn git_get_project_config('description');2573my$descr= <$fd>;2574close$fd;2575if(defined$descr) {2576chomp$descr;2577}2578return$descr;2579}25802581sub git_get_project_ctags {2582my$path=shift;2583my$ctags= {};25842585$git_dir="$projectroot/$path";2586opendir my$dh,"$git_dir/ctags"2587orreturn$ctags;2588foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir($dh)) {2589open my$ct,'<',$_ornext;2590my$val= <$ct>;2591chomp$val;2592close$ct;2593my$ctag=$_;$ctag=~ s#.*/##;2594$ctags->{$ctag} =$val;2595}2596closedir$dh;2597$ctags;2598}25992600sub git_populate_project_tagcloud {2601my$ctags=shift;26022603# First, merge different-cased tags; tags vote on casing2604my%ctags_lc;2605foreach(keys%$ctags) {2606$ctags_lc{lc$_}->{count} +=$ctags->{$_};2607if(not$ctags_lc{lc$_}->{topcount}2608or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {2609$ctags_lc{lc$_}->{topcount} =$ctags->{$_};2610$ctags_lc{lc$_}->{topname} =$_;2611}2612}26132614my$cloud;2615if(eval{require HTML::TagCloud;1; }) {2616$cloud= HTML::TagCloud->new;2617foreach(sort keys%ctags_lc) {2618# Pad the title with spaces so that the cloud looks2619# less crammed.2620my$title=$ctags_lc{$_}->{topname};2621$title=~s/ / /g;2622$title=~s/^/ /g;2623$title=~s/$/ /g;2624$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});2625}2626}else{2627$cloud= \%ctags_lc;2628}2629$cloud;2630}26312632sub git_show_project_tagcloud {2633my($cloud,$count) =@_;2634print STDERR ref($cloud)."..\n";2635if(ref$cloudeq'HTML::TagCloud') {2636return$cloud->html_and_css($count);2637}else{2638my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;2639return'<p align="center">'.join(', ',map{2640$cgi->a({-href=>"$home_link?by_tag=$_"},$cloud->{$_}->{topname})2641}splice(@tags,0,$count)) .'</p>';2642}2643}26442645sub git_get_project_url_list {2646my$path=shift;26472648$git_dir="$projectroot/$path";2649open my$fd,'<',"$git_dir/cloneurl"2650orreturnwantarray?2651@{ config_to_multi(git_get_project_config('url')) } :2652 config_to_multi(git_get_project_config('url'));2653my@git_project_url_list=map{chomp;$_} <$fd>;2654close$fd;26552656returnwantarray?@git_project_url_list: \@git_project_url_list;2657}26582659sub git_get_projects_list {2660my($filter) =@_;2661my@list;26622663$filter||='';2664$filter=~s/\.git$//;26652666my$check_forks= gitweb_check_feature('forks');26672668if(-d $projects_list) {2669# search in directory2670my$dir=$projects_list. ($filter?"/$filter":'');2671# remove the trailing "/"2672$dir=~s!/+$!!;2673my$pfxlen=length("$dir");2674my$pfxdepth= ($dir=~tr!/!!);26752676 File::Find::find({2677 follow_fast =>1,# follow symbolic links2678 follow_skip =>2,# ignore duplicates2679 dangling_symlinks =>0,# ignore dangling symlinks, silently2680 wanted =>sub{2681# global variables2682our$project_maxdepth;2683our$projectroot;2684# skip project-list toplevel, if we get it.2685return if(m!^[/.]$!);2686# only directories can be git repositories2687return unless(-d $_);2688# don't traverse too deep (Find is super slow on os x)2689if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {2690$File::Find::prune =1;2691return;2692}26932694my$subdir=substr($File::Find::name,$pfxlen+1);2695# we check related file in $projectroot2696my$path= ($filter?"$filter/":'') .$subdir;2697if(check_export_ok("$projectroot/$path")) {2698push@list, { path =>$path};2699$File::Find::prune =1;2700}2701},2702},"$dir");27032704}elsif(-f $projects_list) {2705# read from file(url-encoded):2706# 'git%2Fgit.git Linus+Torvalds'2707# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2708# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2709my%paths;2710open my$fd,'<',$projects_listorreturn;2711 PROJECT:2712while(my$line= <$fd>) {2713chomp$line;2714my($path,$owner) =split' ',$line;2715$path= unescape($path);2716$owner= unescape($owner);2717if(!defined$path) {2718next;2719}2720if($filterne'') {2721# looking for forks;2722my$pfx=substr($path,0,length($filter));2723if($pfxne$filter) {2724next PROJECT;2725}2726my$sfx=substr($path,length($filter));2727if($sfx!~/^\/.*\.git$/) {2728next PROJECT;2729}2730}elsif($check_forks) {2731 PATH:2732foreachmy$filter(keys%paths) {2733# looking for forks;2734my$pfx=substr($path,0,length($filter));2735if($pfxne$filter) {2736next PATH;2737}2738my$sfx=substr($path,length($filter));2739if($sfx!~/^\/.*\.git$/) {2740next PATH;2741}2742# is a fork, don't include it in2743# the list2744next PROJECT;2745}2746}2747if(check_export_ok("$projectroot/$path")) {2748my$pr= {2749 path =>$path,2750 owner => to_utf8($owner),2751};2752push@list,$pr;2753(my$forks_path=$path) =~s/\.git$//;2754$paths{$forks_path}++;2755}2756}2757close$fd;2758}2759return@list;2760}27612762our$gitweb_project_owner=undef;2763sub git_get_project_list_from_file {27642765return if(defined$gitweb_project_owner);27662767$gitweb_project_owner= {};2768# read from file (url-encoded):2769# 'git%2Fgit.git Linus+Torvalds'2770# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'2771# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'2772if(-f $projects_list) {2773open(my$fd,'<',$projects_list);2774while(my$line= <$fd>) {2775chomp$line;2776my($pr,$ow) =split' ',$line;2777$pr= unescape($pr);2778$ow= unescape($ow);2779$gitweb_project_owner->{$pr} = to_utf8($ow);2780}2781close$fd;2782}2783}27842785sub git_get_project_owner {2786my$project=shift;2787my$owner;27882789returnundefunless$project;2790$git_dir="$projectroot/$project";27912792if(!defined$gitweb_project_owner) {2793 git_get_project_list_from_file();2794}27952796if(exists$gitweb_project_owner->{$project}) {2797$owner=$gitweb_project_owner->{$project};2798}2799if(!defined$owner){2800$owner= git_get_project_config('owner');2801}2802if(!defined$owner) {2803$owner= get_file_owner("$git_dir");2804}28052806return$owner;2807}28082809sub git_get_last_activity {2810my($path) =@_;2811my$fd;28122813$git_dir="$projectroot/$path";2814open($fd,"-|", git_cmd(),'for-each-ref',2815'--format=%(committer)',2816'--sort=-committerdate',2817'--count=1',2818'refs/heads')orreturn;2819my$most_recent= <$fd>;2820close$fdorreturn;2821if(defined$most_recent&&2822$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2823my$timestamp=$1;2824my$age=time-$timestamp;2825return($age, age_string($age));2826}2827return(undef,undef);2828}28292830# Implementation note: when a single remote is wanted, we cannot use 'git2831# remote show -n' because that command always work (assuming it's a remote URL2832# if it's not defined), and we cannot use 'git remote show' because that would2833# try to make a network roundtrip. So the only way to find if that particular2834# remote is defined is to walk the list provided by 'git remote -v' and stop if2835# and when we find what we want.2836sub git_get_remotes_list {2837my$wanted=shift;2838my%remotes= ();28392840open my$fd,'-|', git_cmd(),'remote','-v';2841return unless$fd;2842while(my$remote= <$fd>) {2843chomp$remote;2844$remote=~s!\t(.*?)\s+\((\w+)\)$!!;2845next if$wantedand not$remoteeq$wanted;2846my($url,$key) = ($1,$2);28472848$remotes{$remote} ||= {'heads'=> () };2849$remotes{$remote}{$key} =$url;2850}2851close$fdorreturn;2852returnwantarray?%remotes: \%remotes;2853}28542855# Takes a hash of remotes as first parameter and fills it by adding the2856# available remote heads for each of the indicated remotes.2857sub fill_remote_heads {2858my$remotes=shift;2859my@heads=map{"remotes/$_"}keys%$remotes;2860my@remoteheads= git_get_heads_list(undef,@heads);2861foreachmy$remote(keys%$remotes) {2862$remotes->{$remote}{'heads'} = [grep{2863$_->{'name'} =~s!^$remote/!!2864}@remoteheads];2865}2866}28672868sub git_get_references {2869my$type=shift||"";2870my%refs;2871# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112872# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2873open my$fd,"-|", git_cmd(),"show-ref","--dereference",2874($type? ("--","refs/$type") : ())# use -- <pattern> if $type2875orreturn;28762877while(my$line= <$fd>) {2878chomp$line;2879if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2880if(defined$refs{$1}) {2881push@{$refs{$1}},$2;2882}else{2883$refs{$1} = [$2];2884}2885}2886}2887close$fdorreturn;2888return \%refs;2889}28902891sub git_get_rev_name_tags {2892my$hash=shift||returnundef;28932894open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2895orreturn;2896my$name_rev= <$fd>;2897close$fd;28982899if($name_rev=~ m|^$hash tags/(.*)$|) {2900return$1;2901}else{2902# catches also '$hash undefined' output2903returnundef;2904}2905}29062907## ----------------------------------------------------------------------2908## parse to hash functions29092910sub parse_date {2911my$epoch=shift;2912my$tz=shift||"-0000";29132914my%date;2915my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2916my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2917my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2918$date{'hour'} =$hour;2919$date{'minute'} =$min;2920$date{'mday'} =$mday;2921$date{'day'} =$days[$wday];2922$date{'month'} =$months[$mon];2923$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2924$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2925$date{'mday-time'} =sprintf"%d%s%02d:%02d",2926$mday,$months[$mon],$hour,$min;2927$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",29281900+$year,1+$mon,$mday,$hour,$min,$sec;29292930my($tz_sign,$tz_hour,$tz_min) =2931($tz=~m/^([-+])(\d\d)(\d\d)$/);2932$tz_sign= ($tz_signeq'-'? -1: +1);2933my$local=$epoch+$tz_sign*((($tz_hour*60) +$tz_min)*60);2934($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2935$date{'hour_local'} =$hour;2936$date{'minute_local'} =$min;2937$date{'tz_local'} =$tz;2938$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",29391900+$year,$mon+1,$mday,2940$hour,$min,$sec,$tz);2941return%date;2942}29432944sub parse_tag {2945my$tag_id=shift;2946my%tag;2947my@comment;29482949open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2950$tag{'id'} =$tag_id;2951while(my$line= <$fd>) {2952chomp$line;2953if($line=~m/^object ([0-9a-fA-F]{40})$/) {2954$tag{'object'} =$1;2955}elsif($line=~m/^type (.+)$/) {2956$tag{'type'} =$1;2957}elsif($line=~m/^tag (.+)$/) {2958$tag{'name'} =$1;2959}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2960$tag{'author'} =$1;2961$tag{'author_epoch'} =$2;2962$tag{'author_tz'} =$3;2963if($tag{'author'} =~m/^([^<]+) <([^>]*)>/) {2964$tag{'author_name'} =$1;2965$tag{'author_email'} =$2;2966}else{2967$tag{'author_name'} =$tag{'author'};2968}2969}elsif($line=~m/--BEGIN/) {2970push@comment,$line;2971last;2972}elsif($lineeq"") {2973last;2974}2975}2976push@comment, <$fd>;2977$tag{'comment'} = \@comment;2978close$fdorreturn;2979if(!defined$tag{'name'}) {2980return2981};2982return%tag2983}29842985sub parse_commit_text {2986my($commit_text,$withparents) =@_;2987my@commit_lines=split'\n',$commit_text;2988my%co;29892990pop@commit_lines;# Remove '\0'29912992if(!@commit_lines) {2993return;2994}29952996my$header=shift@commit_lines;2997if($header!~m/^[0-9a-fA-F]{40}/) {2998return;2999}3000($co{'id'},my@parents) =split' ',$header;3001while(my$line=shift@commit_lines) {3002last if$lineeq"\n";3003if($line=~m/^tree ([0-9a-fA-F]{40})$/) {3004$co{'tree'} =$1;3005}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {3006push@parents,$1;3007}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {3008$co{'author'} = to_utf8($1);3009$co{'author_epoch'} =$2;3010$co{'author_tz'} =$3;3011if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {3012$co{'author_name'} =$1;3013$co{'author_email'} =$2;3014}else{3015$co{'author_name'} =$co{'author'};3016}3017}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {3018$co{'committer'} = to_utf8($1);3019$co{'committer_epoch'} =$2;3020$co{'committer_tz'} =$3;3021if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {3022$co{'committer_name'} =$1;3023$co{'committer_email'} =$2;3024}else{3025$co{'committer_name'} =$co{'committer'};3026}3027}3028}3029if(!defined$co{'tree'}) {3030return;3031};3032$co{'parents'} = \@parents;3033$co{'parent'} =$parents[0];30343035foreachmy$title(@commit_lines) {3036$title=~s/^ //;3037if($titlene"") {3038$co{'title'} = chop_str($title,80,5);3039# remove leading stuff of merges to make the interesting part visible3040if(length($title) >50) {3041$title=~s/^Automatic //;3042$title=~s/^merge (of|with) /Merge ... /i;3043if(length($title) >50) {3044$title=~s/(http|rsync):\/\///;3045}3046if(length($title) >50) {3047$title=~s/(master|www|rsync)\.//;3048}3049if(length($title) >50) {3050$title=~s/kernel.org:?//;3051}3052if(length($title) >50) {3053$title=~s/\/pub\/scm//;3054}3055}3056$co{'title_short'} = chop_str($title,50,5);3057last;3058}3059}3060if(!defined$co{'title'} ||$co{'title'}eq"") {3061$co{'title'} =$co{'title_short'} ='(no commit message)';3062}3063# remove added spaces3064foreachmy$line(@commit_lines) {3065$line=~s/^ //;3066}3067$co{'comment'} = \@commit_lines;30683069my$age=time-$co{'committer_epoch'};3070$co{'age'} =$age;3071$co{'age_string'} = age_string($age);3072my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});3073if($age>60*60*24*7*2) {3074$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;3075$co{'age_string_age'} =$co{'age_string'};3076}else{3077$co{'age_string_date'} =$co{'age_string'};3078$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;3079}3080return%co;3081}30823083sub parse_commit {3084my($commit_id) =@_;3085my%co;30863087local$/="\0";30883089open my$fd,"-|", git_cmd(),"rev-list",3090"--parents",3091"--header",3092"--max-count=1",3093$commit_id,3094"--",3095or die_error(500,"Open git-rev-list failed");3096%co= parse_commit_text(<$fd>,1);3097close$fd;30983099return%co;3100}31013102sub parse_commits {3103my($commit_id,$maxcount,$skip,$filename,@args) =@_;3104my@cos;31053106$maxcount||=1;3107$skip||=0;31083109local$/="\0";31103111open my$fd,"-|", git_cmd(),"rev-list",3112"--header",3113@args,3114("--max-count=".$maxcount),3115("--skip=".$skip),3116@extra_options,3117$commit_id,3118"--",3119($filename? ($filename) : ())3120or die_error(500,"Open git-rev-list failed");3121while(my$line= <$fd>) {3122my%co= parse_commit_text($line);3123push@cos, \%co;3124}3125close$fd;31263127returnwantarray?@cos: \@cos;3128}31293130# parse line of git-diff-tree "raw" output3131sub parse_difftree_raw_line {3132my$line=shift;3133my%res;31343135# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'3136# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'3137if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {3138$res{'from_mode'} =$1;3139$res{'to_mode'} =$2;3140$res{'from_id'} =$3;3141$res{'to_id'} =$4;3142$res{'status'} =$5;3143$res{'similarity'} =$6;3144if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied3145($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);3146}else{3147$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);3148}3149}3150# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'3151# combined diff (for merge commit)3152elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {3153$res{'nparents'} =length($1);3154$res{'from_mode'} = [split(' ',$2) ];3155$res{'to_mode'} =pop@{$res{'from_mode'}};3156$res{'from_id'} = [split(' ',$3) ];3157$res{'to_id'} =pop@{$res{'from_id'}};3158$res{'status'} = [split('',$4) ];3159$res{'to_file'} = unquote($5);3160}3161# 'c512b523472485aef4fff9e57b229d9d243c967f'3162elsif($line=~m/^([0-9a-fA-F]{40})$/) {3163$res{'commit'} =$1;3164}31653166returnwantarray?%res: \%res;3167}31683169# wrapper: return parsed line of git-diff-tree "raw" output3170# (the argument might be raw line, or parsed info)3171sub parsed_difftree_line {3172my$line_or_ref=shift;31733174if(ref($line_or_ref)eq"HASH") {3175# pre-parsed (or generated by hand)3176return$line_or_ref;3177}else{3178return parse_difftree_raw_line($line_or_ref);3179}3180}31813182# parse line of git-ls-tree output3183sub parse_ls_tree_line {3184my$line=shift;3185my%opts=@_;3186my%res;31873188if($opts{'-l'}) {3189#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'3190$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;31913192$res{'mode'} =$1;3193$res{'type'} =$2;3194$res{'hash'} =$3;3195$res{'size'} =$4;3196if($opts{'-z'}) {3197$res{'name'} =$5;3198}else{3199$res{'name'} = unquote($5);3200}3201}else{3202#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'3203$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;32043205$res{'mode'} =$1;3206$res{'type'} =$2;3207$res{'hash'} =$3;3208if($opts{'-z'}) {3209$res{'name'} =$4;3210}else{3211$res{'name'} = unquote($4);3212}3213}32143215returnwantarray?%res: \%res;3216}32173218# generates _two_ hashes, references to which are passed as 2 and 3 argument3219sub parse_from_to_diffinfo {3220my($diffinfo,$from,$to,@parents) =@_;32213222if($diffinfo->{'nparents'}) {3223# combined diff3224$from->{'file'} = [];3225$from->{'href'} = [];3226 fill_from_file_info($diffinfo,@parents)3227unlessexists$diffinfo->{'from_file'};3228for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {3229$from->{'file'}[$i] =3230defined$diffinfo->{'from_file'}[$i] ?3231$diffinfo->{'from_file'}[$i] :3232$diffinfo->{'to_file'};3233if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file3234$from->{'href'}[$i] = href(action=>"blob",3235 hash_base=>$parents[$i],3236 hash=>$diffinfo->{'from_id'}[$i],3237 file_name=>$from->{'file'}[$i]);3238}else{3239$from->{'href'}[$i] =undef;3240}3241}3242}else{3243# ordinary (not combined) diff3244$from->{'file'} =$diffinfo->{'from_file'};3245if($diffinfo->{'status'}ne"A") {# not new (added) file3246$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,3247 hash=>$diffinfo->{'from_id'},3248 file_name=>$from->{'file'});3249}else{3250delete$from->{'href'};3251}3252}32533254$to->{'file'} =$diffinfo->{'to_file'};3255if(!is_deleted($diffinfo)) {# file exists in result3256$to->{'href'} = href(action=>"blob", hash_base=>$hash,3257 hash=>$diffinfo->{'to_id'},3258 file_name=>$to->{'file'});3259}else{3260delete$to->{'href'};3261}3262}32633264## ......................................................................3265## parse to array of hashes functions32663267sub git_get_heads_list {3268my($limit,@classes) =@_;3269@classes= ('heads')unless@classes;3270my@patterns=map{"refs/$_"}@classes;3271my@headslist;32723273open my$fd,'-|', git_cmd(),'for-each-ref',3274($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',3275'--format=%(objectname) %(refname) %(subject)%00%(committer)',3276@patterns3277orreturn;3278while(my$line= <$fd>) {3279my%ref_item;32803281chomp$line;3282my($refinfo,$committerinfo) =split(/\0/,$line);3283my($hash,$name,$title) =split(' ',$refinfo,3);3284my($committer,$epoch,$tz) =3285($committerinfo=~/^(.*) ([0-9]+) (.*)$/);3286$ref_item{'fullname'} =$name;3287$name=~s!^refs/(?:head|remote)s/!!;32883289$ref_item{'name'} =$name;3290$ref_item{'id'} =$hash;3291$ref_item{'title'} =$title||'(no commit message)';3292$ref_item{'epoch'} =$epoch;3293if($epoch) {3294$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3295}else{3296$ref_item{'age'} ="unknown";3297}32983299push@headslist, \%ref_item;3300}3301close$fd;33023303returnwantarray?@headslist: \@headslist;3304}33053306sub git_get_tags_list {3307my$limit=shift;3308my@tagslist;33093310open my$fd,'-|', git_cmd(),'for-each-ref',3311($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',3312'--format=%(objectname) %(objecttype) %(refname) '.3313'%(*objectname) %(*objecttype) %(subject)%00%(creator)',3314'refs/tags'3315orreturn;3316while(my$line= <$fd>) {3317my%ref_item;33183319chomp$line;3320my($refinfo,$creatorinfo) =split(/\0/,$line);3321my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);3322my($creator,$epoch,$tz) =3323($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);3324$ref_item{'fullname'} =$name;3325$name=~s!^refs/tags/!!;33263327$ref_item{'type'} =$type;3328$ref_item{'id'} =$id;3329$ref_item{'name'} =$name;3330if($typeeq"tag") {3331$ref_item{'subject'} =$title;3332$ref_item{'reftype'} =$reftype;3333$ref_item{'refid'} =$refid;3334}else{3335$ref_item{'reftype'} =$type;3336$ref_item{'refid'} =$id;3337}33383339if($typeeq"tag"||$typeeq"commit") {3340$ref_item{'epoch'} =$epoch;3341if($epoch) {3342$ref_item{'age'} = age_string(time-$ref_item{'epoch'});3343}else{3344$ref_item{'age'} ="unknown";3345}3346}33473348push@tagslist, \%ref_item;3349}3350close$fd;33513352returnwantarray?@tagslist: \@tagslist;3353}33543355## ----------------------------------------------------------------------3356## filesystem-related functions33573358sub get_file_owner {3359my$path=shift;33603361my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);3362my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);3363if(!defined$gcos) {3364returnundef;3365}3366my$owner=$gcos;3367$owner=~s/[,;].*$//;3368return to_utf8($owner);3369}33703371# assume that file exists3372sub insert_file {3373my$filename=shift;33743375open my$fd,'<',$filename;3376print map{ to_utf8($_) } <$fd>;3377close$fd;3378}33793380## ......................................................................3381## mimetype related functions33823383sub mimetype_guess_file {3384my$filename=shift;3385my$mimemap=shift;3386-r $mimemaporreturnundef;33873388my%mimemap;3389open(my$mh,'<',$mimemap)orreturnundef;3390while(<$mh>) {3391next ifm/^#/;# skip comments3392my($mimetype,$exts) =split(/\t+/);3393if(defined$exts) {3394my@exts=split(/\s+/,$exts);3395foreachmy$ext(@exts) {3396$mimemap{$ext} =$mimetype;3397}3398}3399}3400close($mh);34013402$filename=~/\.([^.]*)$/;3403return$mimemap{$1};3404}34053406sub mimetype_guess {3407my$filename=shift;3408my$mime;3409$filename=~/\./orreturnundef;34103411if($mimetypes_file) {3412my$file=$mimetypes_file;3413if($file!~m!^/!) {# if it is relative path3414# it is relative to project3415$file="$projectroot/$project/$file";3416}3417$mime= mimetype_guess_file($filename,$file);3418}3419$mime||= mimetype_guess_file($filename,'/etc/mime.types');3420return$mime;3421}34223423sub blob_mimetype {3424my$fd=shift;3425my$filename=shift;34263427if($filename) {3428my$mime= mimetype_guess($filename);3429$mimeandreturn$mime;3430}34313432# just in case3433return$default_blob_plain_mimetypeunless$fd;34343435if(-T $fd) {3436return'text/plain';3437}elsif(!$filename) {3438return'application/octet-stream';3439}elsif($filename=~m/\.png$/i) {3440return'image/png';3441}elsif($filename=~m/\.gif$/i) {3442return'image/gif';3443}elsif($filename=~m/\.jpe?g$/i) {3444return'image/jpeg';3445}else{3446return'application/octet-stream';3447}3448}34493450sub blob_contenttype {3451my($fd,$file_name,$type) =@_;34523453$type||= blob_mimetype($fd,$file_name);3454if($typeeq'text/plain'&&defined$default_text_plain_charset) {3455$type.="; charset=$default_text_plain_charset";3456}34573458return$type;3459}34603461# guess file syntax for syntax highlighting; return undef if no highlighting3462# the name of syntax can (in the future) depend on syntax highlighter used3463sub guess_file_syntax {3464my($highlight,$mimetype,$file_name) =@_;3465returnundefunless($highlight&&defined$file_name);3466my$basename= basename($file_name,'.in');3467return$highlight_basename{$basename}3468ifexists$highlight_basename{$basename};34693470$basename=~/\.([^.]*)$/;3471my$ext=$1orreturnundef;3472return$highlight_ext{$ext}3473ifexists$highlight_ext{$ext};34743475returnundef;3476}34773478# run highlighter and return FD of its output,3479# or return original FD if no highlighting3480sub run_highlighter {3481my($fd,$highlight,$syntax) =@_;3482return$fdunless($highlight&&defined$syntax);34833484close$fd;3485open$fd, quote_command(git_cmd(),"cat-file","blob",$hash)." | ".3486 quote_command($highlight_bin).3487" --replace-tabs=8 --fragment --syntax$syntax|"3488or die_error(500,"Couldn't open file or run syntax highlighter");3489return$fd;3490}34913492## ======================================================================3493## functions printing HTML: header, footer, error page34943495sub get_page_title {3496my$title= to_utf8($site_name);34973498return$titleunless(defined$project);3499$title.=" - ". to_utf8($project);35003501return$titleunless(defined$action);3502$title.="/$action";# $action is US-ASCII (7bit ASCII)35033504return$titleunless(defined$file_name);3505$title.=" - ". esc_path($file_name);3506if($actioneq"tree"&&$file_name!~ m|/$|) {3507$title.="/";3508}35093510return$title;3511}35123513sub print_feed_meta {3514if(defined$project) {3515my%href_params= get_feed_info();3516if(!exists$href_params{'-title'}) {3517$href_params{'-title'} ='log';3518}35193520foreachmy$format(qw(RSS Atom)) {3521my$type=lc($format);3522my%link_attr= (3523'-rel'=>'alternate',3524'-title'=> esc_attr("$project-$href_params{'-title'} -$formatfeed"),3525'-type'=>"application/$type+xml"3526);35273528$href_params{'action'} =$type;3529$link_attr{'-href'} = href(%href_params);3530print"<link ".3531"rel=\"$link_attr{'-rel'}\"".3532"title=\"$link_attr{'-title'}\"".3533"href=\"$link_attr{'-href'}\"".3534"type=\"$link_attr{'-type'}\"".3535"/>\n";35363537$href_params{'extra_options'} ='--no-merges';3538$link_attr{'-href'} = href(%href_params);3539$link_attr{'-title'} .=' (no merges)';3540print"<link ".3541"rel=\"$link_attr{'-rel'}\"".3542"title=\"$link_attr{'-title'}\"".3543"href=\"$link_attr{'-href'}\"".3544"type=\"$link_attr{'-type'}\"".3545"/>\n";3546}35473548}else{3549printf('<link rel="alternate" title="%sprojects list" '.3550'href="%s" type="text/plain; charset=utf-8" />'."\n",3551 esc_attr($site_name), href(project=>undef, action=>"project_index"));3552printf('<link rel="alternate" title="%sprojects feeds" '.3553'href="%s" type="text/x-opml" />'."\n",3554 esc_attr($site_name), href(project=>undef, action=>"opml"));3555}3556}35573558sub git_header_html {3559my$status=shift||"200 OK";3560my$expires=shift;3561my%opts=@_;35623563my$title= get_page_title();3564my$content_type;3565# require explicit support from the UA if we are to send the page as3566# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.3567# we have to do this because MSIE sometimes globs '*/*', pretending to3568# support xhtml+xml but choking when it gets what it asked for.3569if(defined$cgi->http('HTTP_ACCEPT') &&3570$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&3571$cgi->Accept('application/xhtml+xml') !=0) {3572$content_type='application/xhtml+xml';3573}else{3574$content_type='text/html';3575}3576print$cgi->header(-type=>$content_type, -charset =>'utf-8',3577-status=>$status, -expires =>$expires)3578unless($opts{'-no_http_header'});3579my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';3580print<<EOF;3581<?xml version="1.0" encoding="utf-8"?>3582<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">3583<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">3584<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->3585<!-- git core binaries version$git_version-->3586<head>3587<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>3588<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>3589<meta name="robots" content="index, nofollow"/>3590<title>$title</title>3591EOF3592# the stylesheet, favicon etc urls won't work correctly with path_info3593# unless we set the appropriate base URL3594if($ENV{'PATH_INFO'}) {3595print"<base href=\"".esc_url($base_url)."\"/>\n";3596}3597# print out each stylesheet that exist, providing backwards capability3598# for those people who defined $stylesheet in a config file3599if(defined$stylesheet) {3600print'<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";3601}else{3602foreachmy$stylesheet(@stylesheets) {3603next unless$stylesheet;3604print'<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";3605}3606}3607 print_feed_meta()3608if($statuseq'200 OK');3609if(defined$favicon) {3610printqq(<link rel="shortcut icon" href=").esc_url($favicon).qq(" type="image/png" />\n);3611}36123613print"</head>\n".3614"<body>\n";36153616if(defined$site_header&& -f $site_header) {3617 insert_file($site_header);3618}36193620print"<div class=\"page_header\">\n";3621if(defined$logo) {3622print$cgi->a({-href => esc_url($logo_url),3623-title =>$logo_label},3624$cgi->img({-src => esc_url($logo),3625-width =>72, -height =>27,3626-alt =>"git",3627-class=>"logo"}));3628}3629print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";3630if(defined$project) {3631print$cgi->a({-href => href(action=>"summary")}, esc_html($project));3632if(defined$action) {3633my$action_print=$action;3634if(defined$opts{-action_extra}) {3635$action_print=$cgi->a({-href => href(action=>$action)},3636$action);3637}3638print" /$action_print";3639}3640if(defined$opts{-action_extra}) {3641print" /$opts{-action_extra}";3642}3643print"\n";3644}3645print"</div>\n";36463647my$have_search= gitweb_check_feature('search');3648if(defined$project&&$have_search) {3649if(!defined$searchtext) {3650$searchtext="";3651}3652my$search_hash;3653if(defined$hash_base) {3654$search_hash=$hash_base;3655}elsif(defined$hash) {3656$search_hash=$hash;3657}else{3658$search_hash="HEAD";3659}3660my$action=$my_uri;3661my$use_pathinfo= gitweb_check_feature('pathinfo');3662if($use_pathinfo) {3663$action.="/".esc_url($project);3664}3665print$cgi->startform(-method=>"get", -action =>$action) .3666"<div class=\"search\">\n".3667(!$use_pathinfo&&3668$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .3669$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".3670$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".3671$cgi->popup_menu(-name =>'st', -default=>'commit',3672-values=> ['commit','grep','author','committer','pickaxe']) .3673$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .3674" search:\n",3675$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".3676"<span title=\"Extended regular expression\">".3677$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',3678-checked =>$search_use_regexp) .3679"</span>".3680"</div>".3681$cgi->end_form() ."\n";3682}3683}36843685sub git_footer_html {3686my$feed_class='rss_logo';36873688print"<div class=\"page_footer\">\n";3689if(defined$project) {3690my$descr= git_get_project_description($project);3691if(defined$descr) {3692print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";3693}36943695my%href_params= get_feed_info();3696if(!%href_params) {3697$feed_class.=' generic';3698}3699$href_params{'-title'} ||='log';37003701foreachmy$format(qw(RSS Atom)) {3702$href_params{'action'} =lc($format);3703print$cgi->a({-href => href(%href_params),3704-title =>"$href_params{'-title'}$formatfeed",3705-class=>$feed_class},$format)."\n";3706}37073708}else{3709print$cgi->a({-href => href(project=>undef, action=>"opml"),3710-class=>$feed_class},"OPML") ." ";3711print$cgi->a({-href => href(project=>undef, action=>"project_index"),3712-class=>$feed_class},"TXT") ."\n";3713}3714print"</div>\n";# class="page_footer"37153716if(defined$t0&& gitweb_check_feature('timed')) {3717print"<div id=\"generating_info\">\n";3718print'This page took '.3719'<span id="generating_time" class="time_span">'.3720 tv_interval($t0, [ gettimeofday() ]).3721' seconds </span>'.3722' and '.3723'<span id="generating_cmd">'.3724$number_of_git_cmds.3725'</span> git commands '.3726" to generate.\n";3727print"</div>\n";# class="page_footer"3728}37293730if(defined$site_footer&& -f $site_footer) {3731 insert_file($site_footer);3732}37333734print qq!<script type="text/javascript" src="!.esc_url($javascript).qq!"></script>\n!;3735if(defined$action&&3736$actioneq'blame_incremental') {3737print qq!<script type="text/javascript">\n!.3738 qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.3739 qq!"!. href() .qq!");\n!.3740 qq!</script>\n!;3741}elsif(gitweb_check_feature('javascript-actions')) {3742print qq!<script type="text/javascript">\n!.3743 qq!window.onload = fixLinks;\n!.3744 qq!</script>\n!;3745}37463747print"</body>\n".3748"</html>";3749}37503751# die_error(<http_status_code>, <error_message>[, <detailed_html_description>])3752# Example: die_error(404, 'Hash not found')3753# By convention, use the following status codes (as defined in RFC 2616):3754# 400: Invalid or missing CGI parameters, or3755# requested object exists but has wrong type.3756# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on3757# this server or project.3758# 404: Requested object/revision/project doesn't exist.3759# 500: The server isn't configured properly, or3760# an internal error occurred (e.g. failed assertions caused by bugs), or3761# an unknown error occurred (e.g. the git binary died unexpectedly).3762# 503: The server is currently unavailable (because it is overloaded,3763# or down for maintenance). Generally, this is a temporary state.3764sub die_error {3765my$status=shift||500;3766my$error= esc_html(shift) ||"Internal Server Error";3767my$extra=shift;3768my%opts=@_;37693770my%http_responses= (3771400=>'400 Bad Request',3772403=>'403 Forbidden',3773404=>'404 Not Found',3774500=>'500 Internal Server Error',3775503=>'503 Service Unavailable',3776);3777 git_header_html($http_responses{$status},undef,%opts);3778print<<EOF;3779<div class="page_body">3780<br /><br />3781$status-$error3782<br />3783EOF3784if(defined$extra) {3785print"<hr />\n".3786"$extra\n";3787}3788print"</div>\n";37893790 git_footer_html();3791goto DONE_GITWEB3792unless($opts{'-error_handler'});3793}37943795## ----------------------------------------------------------------------3796## functions printing or outputting HTML: navigation37973798sub git_print_page_nav {3799my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;3800$extra=''if!defined$extra;# pager or formats38013802my@navs=qw(summary shortlog log commit commitdiff tree);3803if($suppress) {3804@navs=grep{$_ne$suppress}@navs;3805}38063807my%arg=map{$_=> {action=>$_} }@navs;3808if(defined$head) {3809for(qw(commit commitdiff)) {3810$arg{$_}{'hash'} =$head;3811}3812if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {3813for(qw(shortlog log)) {3814$arg{$_}{'hash'} =$head;3815}3816}3817}38183819$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;3820$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;38213822my@actions= gitweb_get_feature('actions');3823my%repl= (3824'%'=>'%',3825'n'=>$project,# project name3826'f'=>$git_dir,# project path within filesystem3827'h'=>$treehead||'',# current hash ('h' parameter)3828'b'=>$treebase||'',# hash base ('hb' parameter)3829);3830while(@actions) {3831my($label,$link,$pos) =splice(@actions,0,3);3832# insert3833@navs=map{$_eq$pos? ($_,$label) :$_}@navs;3834# munch munch3835$link=~s/%([%nfhb])/$repl{$1}/g;3836$arg{$label}{'_href'} =$link;3837}38383839print"<div class=\"page_nav\">\n".3840(join" | ",3841map{$_eq$current?3842$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")3843}@navs);3844print"<br/>\n$extra<br/>\n".3845"</div>\n";3846}38473848# returns a submenu for the nagivation of the refs views (tags, heads,3849# remotes) with the current view disabled and the remotes view only3850# available if the feature is enabled3851sub format_ref_views {3852my($current) =@_;3853my@ref_views=qw{tags heads};3854push@ref_views,'remotes'if gitweb_check_feature('remote_heads');3855returnjoin" | ",map{3856$_eq$current?$_:3857$cgi->a({-href => href(action=>$_)},$_)3858}@ref_views3859}38603861sub format_paging_nav {3862my($action,$page,$has_next_link) =@_;3863my$paging_nav;386438653866if($page>0) {3867$paging_nav.=3868$cgi->a({-href => href(-replay=>1, page=>undef)},"first") .3869" ⋅ ".3870$cgi->a({-href => href(-replay=>1, page=>$page-1),3871-accesskey =>"p", -title =>"Alt-p"},"prev");3872}else{3873$paging_nav.="first ⋅ prev";3874}38753876if($has_next_link) {3877$paging_nav.=" ⋅ ".3878$cgi->a({-href => href(-replay=>1, page=>$page+1),3879-accesskey =>"n", -title =>"Alt-n"},"next");3880}else{3881$paging_nav.=" ⋅ next";3882}38833884return$paging_nav;3885}38863887## ......................................................................3888## functions printing or outputting HTML: div38893890sub git_print_header_div {3891my($action,$title,$hash,$hash_base) =@_;3892my%args= ();38933894$args{'action'} =$action;3895$args{'hash'} =$hashif$hash;3896$args{'hash_base'} =$hash_baseif$hash_base;38973898print"<div class=\"header\">\n".3899$cgi->a({-href => href(%args), -class=>"title"},3900$title?$title:$action) .3901"\n</div>\n";3902}39033904sub format_repo_url {3905my($name,$url) =@_;3906return"<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";3907}39083909# Group output by placing it in a DIV element and adding a header.3910# Options for start_div() can be provided by passing a hash reference as the3911# first parameter to the function.3912# Options to git_print_header_div() can be provided by passing an array3913# reference. This must follow the options to start_div if they are present.3914# The content can be a scalar, which is output as-is, a scalar reference, which3915# is output after html escaping, an IO handle passed either as *handle or3916# *handle{IO}, or a function reference. In the latter case all following3917# parameters will be taken as argument to the content function call.3918sub git_print_section {3919my($div_args,$header_args,$content);3920my$arg=shift;3921if(ref($arg)eq'HASH') {3922$div_args=$arg;3923$arg=shift;3924}3925if(ref($arg)eq'ARRAY') {3926$header_args=$arg;3927$arg=shift;3928}3929$content=$arg;39303931print$cgi->start_div($div_args);3932 git_print_header_div(@$header_args);39333934if(ref($content)eq'CODE') {3935$content->(@_);3936}elsif(ref($content)eq'SCALAR') {3937print esc_html($$content);3938}elsif(ref($content)eq'GLOB'or ref($content)eq'IO::Handle') {3939print<$content>;3940}elsif(!ref($content) &&defined($content)) {3941print$content;3942}39433944print$cgi->end_div;3945}39463947sub print_local_time {3948print format_local_time(@_);3949}39503951sub format_local_time {3952my$localtime='';3953my%date=@_;3954if($date{'hour_local'} <6) {3955$localtime.=sprintf(" (<span class=\"atnight\">%02d:%02d</span>%s)",3956$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3957}else{3958$localtime.=sprintf(" (%02d:%02d%s)",3959$date{'hour_local'},$date{'minute_local'},$date{'tz_local'});3960}39613962return$localtime;3963}39643965# Outputs the author name and date in long form3966sub git_print_authorship {3967my$co=shift;3968my%opts=@_;3969my$tag=$opts{-tag} ||'div';3970my$author=$co->{'author_name'};39713972my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});3973print"<$tagclass=\"author_date\">".3974 format_search_author($author,"author", esc_html($author)) .3975" [$ad{'rfc2822'}";3976 print_local_time(%ad)if($opts{-localtime});3977print"]". git_get_avatar($co->{'author_email'}, -pad_before =>1)3978."</$tag>\n";3979}39803981# Outputs table rows containing the full author or committer information,3982# in the format expected for 'commit' view (& similar).3983# Parameters are a commit hash reference, followed by the list of people3984# to output information for. If the list is empty it defaults to both3985# author and committer.3986sub git_print_authorship_rows {3987my$co=shift;3988# too bad we can't use @people = @_ || ('author', 'committer')3989my@people=@_;3990@people= ('author','committer')unless@people;3991foreachmy$who(@people) {3992my%wd= parse_date($co->{"${who}_epoch"},$co->{"${who}_tz"});3993print"<tr><td>$who</td><td>".3994 format_search_author($co->{"${who}_name"},$who,3995 esc_html($co->{"${who}_name"})) ." ".3996 format_search_author($co->{"${who}_email"},$who,3997 esc_html("<".$co->{"${who}_email"} .">")) .3998"</td><td rowspan=\"2\">".3999 git_get_avatar($co->{"${who}_email"}, -size =>'double') .4000"</td></tr>\n".4001"<tr>".4002"<td></td><td>$wd{'rfc2822'}";4003 print_local_time(%wd);4004print"</td>".4005"</tr>\n";4006}4007}40084009sub git_print_page_path {4010my$name=shift;4011my$type=shift;4012my$hb=shift;401340144015print"<div class=\"page_path\">";4016print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),4017-title =>'tree root'}, to_utf8("[$project]"));4018print" / ";4019if(defined$name) {4020my@dirname=split'/',$name;4021my$basename=pop@dirname;4022my$fullname='';40234024foreachmy$dir(@dirname) {4025$fullname.= ($fullname?'/':'') .$dir;4026print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,4027 hash_base=>$hb),4028-title =>$fullname}, esc_path($dir));4029print" / ";4030}4031if(defined$type&&$typeeq'blob') {4032print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,4033 hash_base=>$hb),4034-title =>$name}, esc_path($basename));4035}elsif(defined$type&&$typeeq'tree') {4036print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,4037 hash_base=>$hb),4038-title =>$name}, esc_path($basename));4039print" / ";4040}else{4041print esc_path($basename);4042}4043}4044print"<br/></div>\n";4045}40464047sub git_print_log {4048my$log=shift;4049my%opts=@_;40504051if($opts{'-remove_title'}) {4052# remove title, i.e. first line of log4053shift@$log;4054}4055# remove leading empty lines4056while(defined$log->[0] &&$log->[0]eq"") {4057shift@$log;4058}40594060# print log4061my$signoff=0;4062my$empty=0;4063foreachmy$line(@$log) {4064if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {4065$signoff=1;4066$empty=0;4067if(!$opts{'-remove_signoff'}) {4068print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";4069next;4070}else{4071# remove signoff lines4072next;4073}4074}else{4075$signoff=0;4076}40774078# print only one empty line4079# do not print empty line after signoff4080if($lineeq"") {4081next if($empty||$signoff);4082$empty=1;4083}else{4084$empty=0;4085}40864087print format_log_line_html($line) ."<br/>\n";4088}40894090if($opts{'-final_empty_line'}) {4091# end with single empty line4092print"<br/>\n"unless$empty;4093}4094}40954096# return link target (what link points to)4097sub git_get_link_target {4098my$hash=shift;4099my$link_target;41004101# read link4102open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4103orreturn;4104{4105local$/=undef;4106$link_target= <$fd>;4107}4108close$fd4109orreturn;41104111return$link_target;4112}41134114# given link target, and the directory (basedir) the link is in,4115# return target of link relative to top directory (top tree);4116# return undef if it is not possible (including absolute links).4117sub normalize_link_target {4118my($link_target,$basedir) =@_;41194120# absolute symlinks (beginning with '/') cannot be normalized4121return if(substr($link_target,0,1)eq'/');41224123# normalize link target to path from top (root) tree (dir)4124my$path;4125if($basedir) {4126$path=$basedir.'/'.$link_target;4127}else{4128# we are in top (root) tree (dir)4129$path=$link_target;4130}41314132# remove //, /./, and /../4133my@path_parts;4134foreachmy$part(split('/',$path)) {4135# discard '.' and ''4136next if(!$part||$parteq'.');4137# handle '..'4138if($parteq'..') {4139if(@path_parts) {4140pop@path_parts;4141}else{4142# link leads outside repository (outside top dir)4143return;4144}4145}else{4146push@path_parts,$part;4147}4148}4149$path=join('/',@path_parts);41504151return$path;4152}41534154# print tree entry (row of git_tree), but without encompassing <tr> element4155sub git_print_tree_entry {4156my($t,$basedir,$hash_base,$have_blame) =@_;41574158my%base_key= ();4159$base_key{'hash_base'} =$hash_baseifdefined$hash_base;41604161# The format of a table row is: mode list link. Where mode is4162# the mode of the entry, list is the name of the entry, an href,4163# and link is the action links of the entry.41644165print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";4166if(exists$t->{'size'}) {4167print"<td class=\"size\">$t->{'size'}</td>\n";4168}4169if($t->{'type'}eq"blob") {4170print"<td class=\"list\">".4171$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4172 file_name=>"$basedir$t->{'name'}",%base_key),4173-class=>"list"}, esc_path($t->{'name'}));4174if(S_ISLNK(oct$t->{'mode'})) {4175my$link_target= git_get_link_target($t->{'hash'});4176if($link_target) {4177my$norm_target= normalize_link_target($link_target,$basedir);4178if(defined$norm_target) {4179print" -> ".4180$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,4181 file_name=>$norm_target),4182-title =>$norm_target}, esc_path($link_target));4183}else{4184print" -> ". esc_path($link_target);4185}4186}4187}4188print"</td>\n";4189print"<td class=\"link\">";4190print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},4191 file_name=>"$basedir$t->{'name'}",%base_key)},4192"blob");4193if($have_blame) {4194print" | ".4195$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},4196 file_name=>"$basedir$t->{'name'}",%base_key)},4197"blame");4198}4199if(defined$hash_base) {4200print" | ".4201$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,4202 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},4203"history");4204}4205print" | ".4206$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,4207 file_name=>"$basedir$t->{'name'}")},4208"raw");4209print"</td>\n";42104211}elsif($t->{'type'}eq"tree") {4212print"<td class=\"list\">";4213print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},4214 file_name=>"$basedir$t->{'name'}",4215%base_key)},4216 esc_path($t->{'name'}));4217print"</td>\n";4218print"<td class=\"link\">";4219print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},4220 file_name=>"$basedir$t->{'name'}",4221%base_key)},4222"tree");4223if(defined$hash_base) {4224print" | ".4225$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,4226 file_name=>"$basedir$t->{'name'}")},4227"history");4228}4229print"</td>\n";4230}else{4231# unknown object: we can only present history for it4232# (this includes 'commit' object, i.e. submodule support)4233print"<td class=\"list\">".4234 esc_path($t->{'name'}) .4235"</td>\n";4236print"<td class=\"link\">";4237if(defined$hash_base) {4238print$cgi->a({-href => href(action=>"history",4239 hash_base=>$hash_base,4240 file_name=>"$basedir$t->{'name'}")},4241"history");4242}4243print"</td>\n";4244}4245}42464247## ......................................................................4248## functions printing large fragments of HTML42494250# get pre-image filenames for merge (combined) diff4251sub fill_from_file_info {4252my($diff,@parents) =@_;42534254$diff->{'from_file'} = [ ];4255$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;4256for(my$i=0;$i<$diff->{'nparents'};$i++) {4257if($diff->{'status'}[$i]eq'R'||4258$diff->{'status'}[$i]eq'C') {4259$diff->{'from_file'}[$i] =4260 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);4261}4262}42634264return$diff;4265}42664267# is current raw difftree line of file deletion4268sub is_deleted {4269my$diffinfo=shift;42704271return$diffinfo->{'to_id'}eq('0' x 40);4272}42734274# does patch correspond to [previous] difftree raw line4275# $diffinfo - hashref of parsed raw diff format4276# $patchinfo - hashref of parsed patch diff format4277# (the same keys as in $diffinfo)4278sub is_patch_split {4279my($diffinfo,$patchinfo) =@_;42804281returndefined$diffinfo&&defined$patchinfo4282&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};4283}428442854286sub git_difftree_body {4287my($difftree,$hash,@parents) =@_;4288my($parent) =$parents[0];4289my$have_blame= gitweb_check_feature('blame');4290print"<div class=\"list_head\">\n";4291if($#{$difftree} >10) {4292print(($#{$difftree} +1) ." files changed:\n");4293}4294print"</div>\n";42954296print"<table class=\"".4297(@parents>1?"combined ":"") .4298"diff_tree\">\n";42994300# header only for combined diff in 'commitdiff' view4301my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';4302if($has_header) {4303# table header4304print"<thead><tr>\n".4305"<th></th><th></th>\n";# filename, patchN link4306for(my$i=0;$i<@parents;$i++) {4307my$par=$parents[$i];4308print"<th>".4309$cgi->a({-href => href(action=>"commitdiff",4310 hash=>$hash, hash_parent=>$par),4311-title =>'commitdiff to parent number '.4312($i+1) .': '.substr($par,0,7)},4313$i+1) .4314" </th>\n";4315}4316print"</tr></thead>\n<tbody>\n";4317}43184319my$alternate=1;4320my$patchno=0;4321foreachmy$line(@{$difftree}) {4322my$diff= parsed_difftree_line($line);43234324if($alternate) {4325print"<tr class=\"dark\">\n";4326}else{4327print"<tr class=\"light\">\n";4328}4329$alternate^=1;43304331if(exists$diff->{'nparents'}) {# combined diff43324333 fill_from_file_info($diff,@parents)4334unlessexists$diff->{'from_file'};43354336if(!is_deleted($diff)) {4337# file exists in the result (child) commit4338print"<td>".4339$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4340 file_name=>$diff->{'to_file'},4341 hash_base=>$hash),4342-class=>"list"}, esc_path($diff->{'to_file'})) .4343"</td>\n";4344}else{4345print"<td>".4346 esc_path($diff->{'to_file'}) .4347"</td>\n";4348}43494350if($actioneq'commitdiff') {4351# link to patch4352$patchno++;4353print"<td class=\"link\">".4354$cgi->a({-href => href(-anchor=>"patch$patchno")},4355"patch") .4356" | ".4357"</td>\n";4358}43594360my$has_history=0;4361my$not_deleted=0;4362for(my$i=0;$i<$diff->{'nparents'};$i++) {4363my$hash_parent=$parents[$i];4364my$from_hash=$diff->{'from_id'}[$i];4365my$from_path=$diff->{'from_file'}[$i];4366my$status=$diff->{'status'}[$i];43674368$has_history||= ($statusne'A');4369$not_deleted||= ($statusne'D');43704371if($statuseq'A') {4372print"<td class=\"link\"align=\"right\"> | </td>\n";4373}elsif($statuseq'D') {4374print"<td class=\"link\">".4375$cgi->a({-href => href(action=>"blob",4376 hash_base=>$hash,4377 hash=>$from_hash,4378 file_name=>$from_path)},4379"blob". ($i+1)) .4380" | </td>\n";4381}else{4382if($diff->{'to_id'}eq$from_hash) {4383print"<td class=\"link nochange\">";4384}else{4385print"<td class=\"link\">";4386}4387print$cgi->a({-href => href(action=>"blobdiff",4388 hash=>$diff->{'to_id'},4389 hash_parent=>$from_hash,4390 hash_base=>$hash,4391 hash_parent_base=>$hash_parent,4392 file_name=>$diff->{'to_file'},4393 file_parent=>$from_path)},4394"diff". ($i+1)) .4395" | </td>\n";4396}4397}43984399print"<td class=\"link\">";4400if($not_deleted) {4401print$cgi->a({-href => href(action=>"blob",4402 hash=>$diff->{'to_id'},4403 file_name=>$diff->{'to_file'},4404 hash_base=>$hash)},4405"blob");4406print" | "if($has_history);4407}4408if($has_history) {4409print$cgi->a({-href => href(action=>"history",4410 file_name=>$diff->{'to_file'},4411 hash_base=>$hash)},4412"history");4413}4414print"</td>\n";44154416print"</tr>\n";4417next;# instead of 'else' clause, to avoid extra indent4418}4419# else ordinary diff44204421my($to_mode_oct,$to_mode_str,$to_file_type);4422my($from_mode_oct,$from_mode_str,$from_file_type);4423if($diff->{'to_mode'}ne('0' x 6)) {4424$to_mode_oct=oct$diff->{'to_mode'};4425if(S_ISREG($to_mode_oct)) {# only for regular file4426$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits4427}4428$to_file_type= file_type($diff->{'to_mode'});4429}4430if($diff->{'from_mode'}ne('0' x 6)) {4431$from_mode_oct=oct$diff->{'from_mode'};4432if(S_ISREG($from_mode_oct)) {# only for regular file4433$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits4434}4435$from_file_type= file_type($diff->{'from_mode'});4436}44374438if($diff->{'status'}eq"A") {# created4439my$mode_chng="<span class=\"file_status new\">[new$to_file_type";4440$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;4441$mode_chng.="]</span>";4442print"<td>";4443print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4444 hash_base=>$hash, file_name=>$diff->{'file'}),4445-class=>"list"}, esc_path($diff->{'file'}));4446print"</td>\n";4447print"<td>$mode_chng</td>\n";4448print"<td class=\"link\">";4449if($actioneq'commitdiff') {4450# link to patch4451$patchno++;4452print$cgi->a({-href => href(-anchor=>"patch$patchno")},4453"patch") .4454" | ";4455}4456print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4457 hash_base=>$hash, file_name=>$diff->{'file'})},4458"blob");4459print"</td>\n";44604461}elsif($diff->{'status'}eq"D") {# deleted4462my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";4463print"<td>";4464print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4465 hash_base=>$parent, file_name=>$diff->{'file'}),4466-class=>"list"}, esc_path($diff->{'file'}));4467print"</td>\n";4468print"<td>$mode_chng</td>\n";4469print"<td class=\"link\">";4470if($actioneq'commitdiff') {4471# link to patch4472$patchno++;4473print$cgi->a({-href => href(-anchor=>"patch$patchno")},4474"patch") .4475" | ";4476}4477print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},4478 hash_base=>$parent, file_name=>$diff->{'file'})},4479"blob") ." | ";4480if($have_blame) {4481print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,4482 file_name=>$diff->{'file'})},4483"blame") ." | ";4484}4485print$cgi->a({-href => href(action=>"history", hash_base=>$parent,4486 file_name=>$diff->{'file'})},4487"history");4488print"</td>\n";44894490}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed4491my$mode_chnge="";4492if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4493$mode_chnge="<span class=\"file_status mode_chnge\">[changed";4494if($from_file_typene$to_file_type) {4495$mode_chnge.=" from$from_file_typeto$to_file_type";4496}4497if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {4498if($from_mode_str&&$to_mode_str) {4499$mode_chnge.=" mode:$from_mode_str->$to_mode_str";4500}elsif($to_mode_str) {4501$mode_chnge.=" mode:$to_mode_str";4502}4503}4504$mode_chnge.="]</span>\n";4505}4506print"<td>";4507print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4508 hash_base=>$hash, file_name=>$diff->{'file'}),4509-class=>"list"}, esc_path($diff->{'file'}));4510print"</td>\n";4511print"<td>$mode_chnge</td>\n";4512print"<td class=\"link\">";4513if($actioneq'commitdiff') {4514# link to patch4515$patchno++;4516print$cgi->a({-href => href(-anchor=>"patch$patchno")},4517"patch") .4518" | ";4519}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4520# "commit" view and modified file (not onlu mode changed)4521print$cgi->a({-href => href(action=>"blobdiff",4522 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4523 hash_base=>$hash, hash_parent_base=>$parent,4524 file_name=>$diff->{'file'})},4525"diff") .4526" | ";4527}4528print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4529 hash_base=>$hash, file_name=>$diff->{'file'})},4530"blob") ." | ";4531if($have_blame) {4532print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4533 file_name=>$diff->{'file'})},4534"blame") ." | ";4535}4536print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4537 file_name=>$diff->{'file'})},4538"history");4539print"</td>\n";45404541}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied4542my%status_name= ('R'=>'moved','C'=>'copied');4543my$nstatus=$status_name{$diff->{'status'}};4544my$mode_chng="";4545if($diff->{'from_mode'} !=$diff->{'to_mode'}) {4546# mode also for directories, so we cannot use $to_mode_str4547$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);4548}4549print"<td>".4550$cgi->a({-href => href(action=>"blob", hash_base=>$hash,4551 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),4552-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".4553"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".4554$cgi->a({-href => href(action=>"blob", hash_base=>$parent,4555 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),4556-class=>"list"}, esc_path($diff->{'from_file'})) .4557" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".4558"<td class=\"link\">";4559if($actioneq'commitdiff') {4560# link to patch4561$patchno++;4562print$cgi->a({-href => href(-anchor=>"patch$patchno")},4563"patch") .4564" | ";4565}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {4566# "commit" view and modified file (not only pure rename or copy)4567print$cgi->a({-href => href(action=>"blobdiff",4568 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},4569 hash_base=>$hash, hash_parent_base=>$parent,4570 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},4571"diff") .4572" | ";4573}4574print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},4575 hash_base=>$parent, file_name=>$diff->{'to_file'})},4576"blob") ." | ";4577if($have_blame) {4578print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,4579 file_name=>$diff->{'to_file'})},4580"blame") ." | ";4581}4582print$cgi->a({-href => href(action=>"history", hash_base=>$hash,4583 file_name=>$diff->{'to_file'})},4584"history");4585print"</td>\n";45864587}# we should not encounter Unmerged (U) or Unknown (X) status4588print"</tr>\n";4589}4590print"</tbody>"if$has_header;4591print"</table>\n";4592}45934594sub git_patchset_body {4595my($fd,$difftree,$hash,@hash_parents) =@_;4596my($hash_parent) =$hash_parents[0];45974598my$is_combined= (@hash_parents>1);4599my$patch_idx=0;4600my$patch_number=0;4601my$patch_line;4602my$diffinfo;4603my$to_name;4604my(%from,%to);46054606print"<div class=\"patchset\">\n";46074608# skip to first patch4609while($patch_line= <$fd>) {4610chomp$patch_line;46114612last if($patch_line=~m/^diff /);4613}46144615 PATCH:4616while($patch_line) {46174618# parse "git diff" header line4619if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {4620# $1 is from_name, which we do not use4621$to_name= unquote($2);4622$to_name=~s!^b/!!;4623}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {4624# $1 is 'cc' or 'combined', which we do not use4625$to_name= unquote($2);4626}else{4627$to_name=undef;4628}46294630# check if current patch belong to current raw line4631# and parse raw git-diff line if needed4632if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {4633# this is continuation of a split patch4634print"<div class=\"patch cont\">\n";4635}else{4636# advance raw git-diff output if needed4637$patch_idx++ifdefined$diffinfo;46384639# read and prepare patch information4640$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);46414642# compact combined diff output can have some patches skipped4643# find which patch (using pathname of result) we are at now;4644if($is_combined) {4645while($to_namene$diffinfo->{'to_file'}) {4646print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4647 format_diff_cc_simplified($diffinfo,@hash_parents) .4648"</div>\n";# class="patch"46494650$patch_idx++;4651$patch_number++;46524653last if$patch_idx>$#$difftree;4654$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);4655}4656}46574658# modifies %from, %to hashes4659 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);46604661# this is first patch for raw difftree line with $patch_idx index4662# we index @$difftree array from 0, but number patches from 14663print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";4664}46654666# git diff header4667#assert($patch_line =~ m/^diff /) if DEBUG;4668#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed4669$patch_number++;4670# print "git diff" header4671print format_git_diff_header_line($patch_line,$diffinfo,4672 \%from, \%to);46734674# print extended diff header4675print"<div class=\"diff extended_header\">\n";4676 EXTENDED_HEADER:4677while($patch_line= <$fd>) {4678chomp$patch_line;46794680last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);46814682print format_extended_diff_header_line($patch_line,$diffinfo,4683 \%from, \%to);4684}4685print"</div>\n";# class="diff extended_header"46864687# from-file/to-file diff header4688if(!$patch_line) {4689print"</div>\n";# class="patch"4690last PATCH;4691}4692next PATCH if($patch_line=~m/^diff /);4693#assert($patch_line =~ m/^---/) if DEBUG;46944695my$last_patch_line=$patch_line;4696$patch_line= <$fd>;4697chomp$patch_line;4698#assert($patch_line =~ m/^\+\+\+/) if DEBUG;46994700print format_diff_from_to_header($last_patch_line,$patch_line,4701$diffinfo, \%from, \%to,4702@hash_parents);47034704# the patch itself4705 LINE:4706while($patch_line= <$fd>) {4707chomp$patch_line;47084709next PATCH if($patch_line=~m/^diff /);47104711print format_diff_line($patch_line, \%from, \%to);4712}47134714}continue{4715print"</div>\n";# class="patch"4716}47174718# for compact combined (--cc) format, with chunk and patch simplification4719# the patchset might be empty, but there might be unprocessed raw lines4720for(++$patch_idxif$patch_number>0;4721$patch_idx<@$difftree;4722++$patch_idx) {4723# read and prepare patch information4724$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);47254726# generate anchor for "patch" links in difftree / whatchanged part4727print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".4728 format_diff_cc_simplified($diffinfo,@hash_parents) .4729"</div>\n";# class="patch"47304731$patch_number++;4732}47334734if($patch_number==0) {4735if(@hash_parents>1) {4736print"<div class=\"diff nodifferences\">Trivial merge</div>\n";4737}else{4738print"<div class=\"diff nodifferences\">No differences found</div>\n";4739}4740}47414742print"</div>\n";# class="patchset"4743}47444745# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .47464747# fills project list info (age, description, owner, forks) for each4748# project in the list, removing invalid projects from returned list4749# NOTE: modifies $projlist, but does not remove entries from it4750sub fill_project_list_info {4751my($projlist,$check_forks) =@_;4752my@projects;47534754my$show_ctags= gitweb_check_feature('ctags');4755 PROJECT:4756foreachmy$pr(@$projlist) {4757my(@activity) = git_get_last_activity($pr->{'path'});4758unless(@activity) {4759next PROJECT;4760}4761($pr->{'age'},$pr->{'age_string'}) =@activity;4762if(!defined$pr->{'descr'}) {4763my$descr= git_get_project_description($pr->{'path'}) ||"";4764$descr= to_utf8($descr);4765$pr->{'descr_long'} =$descr;4766$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);4767}4768if(!defined$pr->{'owner'}) {4769$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";4770}4771if($check_forks) {4772my$pname=$pr->{'path'};4773if(($pname=~s/\.git$//) &&4774($pname!~/\/$/) &&4775(-d "$projectroot/$pname")) {4776$pr->{'forks'} ="-d$projectroot/$pname";4777}else{4778$pr->{'forks'} =0;4779}4780}4781$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});4782push@projects,$pr;4783}47844785return@projects;4786}47874788# print 'sort by' <th> element, generating 'sort by $name' replay link4789# if that order is not selected4790sub print_sort_th {4791print format_sort_th(@_);4792}47934794sub format_sort_th {4795my($name,$order,$header) =@_;4796my$sort_th="";4797$header||=ucfirst($name);47984799if($ordereq$name) {4800$sort_th.="<th>$header</th>\n";4801}else{4802$sort_th.="<th>".4803$cgi->a({-href => href(-replay=>1, order=>$name),4804-class=>"header"},$header) .4805"</th>\n";4806}48074808return$sort_th;4809}48104811sub git_project_list_body {4812# actually uses global variable $project4813my($projlist,$order,$from,$to,$extra,$no_header) =@_;48144815my$check_forks= gitweb_check_feature('forks');4816my@projects= fill_project_list_info($projlist,$check_forks);48174818$order||=$default_projects_order;4819$from=0unlessdefined$from;4820$to=$#projectsif(!defined$to||$#projects<$to);48214822my%order_info= (4823 project => { key =>'path', type =>'str'},4824 descr => { key =>'descr_long', type =>'str'},4825 owner => { key =>'owner', type =>'str'},4826 age => { key =>'age', type =>'num'}4827);4828my$oi=$order_info{$order};4829if($oi->{'type'}eq'str') {4830@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;4831}else{4832@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;4833}48344835my$show_ctags= gitweb_check_feature('ctags');4836if($show_ctags) {4837my%ctags;4838foreachmy$p(@projects) {4839foreachmy$ct(keys%{$p->{'ctags'}}) {4840$ctags{$ct} +=$p->{'ctags'}->{$ct};4841}4842}4843my$cloud= git_populate_project_tagcloud(\%ctags);4844print git_show_project_tagcloud($cloud,64);4845}48464847print"<table class=\"project_list\">\n";4848unless($no_header) {4849print"<tr>\n";4850if($check_forks) {4851print"<th></th>\n";4852}4853 print_sort_th('project',$order,'Project');4854 print_sort_th('descr',$order,'Description');4855 print_sort_th('owner',$order,'Owner');4856 print_sort_th('age',$order,'Last Change');4857print"<th></th>\n".# for links4858"</tr>\n";4859}4860my$alternate=1;4861my$tagfilter=$cgi->param('by_tag');4862for(my$i=$from;$i<=$to;$i++) {4863my$pr=$projects[$i];48644865next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};4866next if$searchtextand not$pr->{'path'} =~/$searchtext/4867and not$pr->{'descr_long'} =~/$searchtext/;4868# Weed out forks or non-matching entries of search4869if($check_forks) {4870my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;4871$forkbase="^$forkbase"if$forkbase;4872next ifnot$searchtextand not$tagfilterand$show_ctags4873and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe4874}48754876if($alternate) {4877print"<tr class=\"dark\">\n";4878}else{4879print"<tr class=\"light\">\n";4880}4881$alternate^=1;4882if($check_forks) {4883print"<td>";4884if($pr->{'forks'}) {4885print"<!--$pr->{'forks'} -->\n";4886print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");4887}4888print"</td>\n";4889}4890print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4891-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".4892"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),4893-class=>"list", -title =>$pr->{'descr_long'}},4894 esc_html($pr->{'descr'})) ."</td>\n".4895"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";4896print"<td class=\"". age_class($pr->{'age'}) ."\">".4897(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".4898"<td class=\"link\">".4899$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".4900$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".4901$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".4902$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .4903($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .4904"</td>\n".4905"</tr>\n";4906}4907if(defined$extra) {4908print"<tr>\n";4909if($check_forks) {4910print"<td></td>\n";4911}4912print"<td colspan=\"5\">$extra</td>\n".4913"</tr>\n";4914}4915print"</table>\n";4916}49174918sub git_log_body {4919# uses global variable $project4920my($commitlist,$from,$to,$refs,$extra) =@_;49214922$from=0unlessdefined$from;4923$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);49244925for(my$i=0;$i<=$to;$i++) {4926my%co= %{$commitlist->[$i]};4927next if!%co;4928my$commit=$co{'id'};4929my$ref= format_ref_marker($refs,$commit);4930 git_print_header_div('commit',4931"<span class=\"age\">$co{'age_string'}</span>".4932 esc_html($co{'title'}) .$ref,4933$commit);4934print"<div class=\"title_text\">\n".4935"<div class=\"log_link\">\n".4936$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .4937" | ".4938$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .4939" | ".4940$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .4941"<br/>\n".4942"</div>\n";4943 git_print_authorship(\%co, -tag =>'span');4944print"<br/>\n</div>\n";49454946print"<div class=\"log_body\">\n";4947 git_print_log($co{'comment'}, -final_empty_line=>1);4948print"</div>\n";4949}4950if($extra) {4951print"<div class=\"page_nav\">\n";4952print"$extra\n";4953print"</div>\n";4954}4955}49564957sub git_shortlog_body {4958# uses global variable $project4959my($commitlist,$from,$to,$refs,$extra) =@_;49604961$from=0unlessdefined$from;4962$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);49634964print"<table class=\"shortlog\">\n";4965my$alternate=1;4966for(my$i=$from;$i<=$to;$i++) {4967my%co= %{$commitlist->[$i]};4968my$commit=$co{'id'};4969my$ref= format_ref_marker($refs,$commit);4970if($alternate) {4971print"<tr class=\"dark\">\n";4972}else{4973print"<tr class=\"light\">\n";4974}4975$alternate^=1;4976# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .4977print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4978 format_author_html('td', \%co,10) ."<td>";4979print format_subject_html($co{'title'},$co{'title_short'},4980 href(action=>"commit", hash=>$commit),$ref);4981print"</td>\n".4982"<td class=\"link\">".4983$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".4984$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".4985$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");4986my$snapshot_links= format_snapshot_links($commit);4987if(defined$snapshot_links) {4988print" | ".$snapshot_links;4989}4990print"</td>\n".4991"</tr>\n";4992}4993if(defined$extra) {4994print"<tr>\n".4995"<td colspan=\"4\">$extra</td>\n".4996"</tr>\n";4997}4998print"</table>\n";4999}50005001sub git_history_body {5002# Warning: assumes constant type (blob or tree) during history5003my($commitlist,$from,$to,$refs,$extra,5004$file_name,$file_hash,$ftype) =@_;50055006$from=0unlessdefined$from;5007$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});50085009print"<table class=\"history\">\n";5010my$alternate=1;5011for(my$i=$from;$i<=$to;$i++) {5012my%co= %{$commitlist->[$i]};5013if(!%co) {5014next;5015}5016my$commit=$co{'id'};50175018my$ref= format_ref_marker($refs,$commit);50195020if($alternate) {5021print"<tr class=\"dark\">\n";5022}else{5023print"<tr class=\"light\">\n";5024}5025$alternate^=1;5026print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5027# shortlog: format_author_html('td', \%co, 10)5028 format_author_html('td', \%co,15,3) ."<td>";5029# originally git_history used chop_str($co{'title'}, 50)5030print format_subject_html($co{'title'},$co{'title_short'},5031 href(action=>"commit", hash=>$commit),$ref);5032print"</td>\n".5033"<td class=\"link\">".5034$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".5035$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");50365037if($ftypeeq'blob') {5038my$blob_current=$file_hash;5039my$blob_parent= git_get_hash_by_path($commit,$file_name);5040if(defined$blob_current&&defined$blob_parent&&5041$blob_currentne$blob_parent) {5042print" | ".5043$cgi->a({-href => href(action=>"blobdiff",5044 hash=>$blob_current, hash_parent=>$blob_parent,5045 hash_base=>$hash_base, hash_parent_base=>$commit,5046 file_name=>$file_name)},5047"diff to current");5048}5049}5050print"</td>\n".5051"</tr>\n";5052}5053if(defined$extra) {5054print"<tr>\n".5055"<td colspan=\"4\">$extra</td>\n".5056"</tr>\n";5057}5058print"</table>\n";5059}50605061sub git_tags_body {5062# uses global variable $project5063my($taglist,$from,$to,$extra) =@_;5064$from=0unlessdefined$from;5065$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);50665067print"<table class=\"tags\">\n";5068my$alternate=1;5069for(my$i=$from;$i<=$to;$i++) {5070my$entry=$taglist->[$i];5071my%tag=%$entry;5072my$comment=$tag{'subject'};5073my$comment_short;5074if(defined$comment) {5075$comment_short= chop_str($comment,30,5);5076}5077if($alternate) {5078print"<tr class=\"dark\">\n";5079}else{5080print"<tr class=\"light\">\n";5081}5082$alternate^=1;5083if(defined$tag{'age'}) {5084print"<td><i>$tag{'age'}</i></td>\n";5085}else{5086print"<td></td>\n";5087}5088print"<td>".5089$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),5090-class=>"list name"}, esc_html($tag{'name'})) .5091"</td>\n".5092"<td>";5093if(defined$comment) {5094print format_subject_html($comment,$comment_short,5095 href(action=>"tag", hash=>$tag{'id'}));5096}5097print"</td>\n".5098"<td class=\"selflink\">";5099if($tag{'type'}eq"tag") {5100print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");5101}else{5102print" ";5103}5104print"</td>\n".5105"<td class=\"link\">"." | ".5106$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});5107if($tag{'reftype'}eq"commit") {5108print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .5109" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");5110}elsif($tag{'reftype'}eq"blob") {5111print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");5112}5113print"</td>\n".5114"</tr>";5115}5116if(defined$extra) {5117print"<tr>\n".5118"<td colspan=\"5\">$extra</td>\n".5119"</tr>\n";5120}5121print"</table>\n";5122}51235124sub git_heads_body {5125# uses global variable $project5126my($headlist,$head,$from,$to,$extra) =@_;5127$from=0unlessdefined$from;5128$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);51295130print"<table class=\"heads\">\n";5131my$alternate=1;5132for(my$i=$from;$i<=$to;$i++) {5133my$entry=$headlist->[$i];5134my%ref=%$entry;5135my$curr=$ref{'id'}eq$head;5136if($alternate) {5137print"<tr class=\"dark\">\n";5138}else{5139print"<tr class=\"light\">\n";5140}5141$alternate^=1;5142print"<td><i>$ref{'age'}</i></td>\n".5143($curr?"<td class=\"current_head\">":"<td>") .5144$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),5145-class=>"list name"},esc_html($ref{'name'})) .5146"</td>\n".5147"<td class=\"link\">".5148$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".5149$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".5150$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'fullname'})},"tree") .5151"</td>\n".5152"</tr>";5153}5154if(defined$extra) {5155print"<tr>\n".5156"<td colspan=\"3\">$extra</td>\n".5157"</tr>\n";5158}5159print"</table>\n";5160}51615162# Display a single remote block5163sub git_remote_block {5164my($remote,$rdata,$limit,$head) =@_;51655166my$heads=$rdata->{'heads'};5167my$fetch=$rdata->{'fetch'};5168my$push=$rdata->{'push'};51695170my$urls_table="<table class=\"projects_list\">\n";51715172if(defined$fetch) {5173if($fetcheq$push) {5174$urls_table.= format_repo_url("URL",$fetch);5175}else{5176$urls_table.= format_repo_url("Fetch URL",$fetch);5177$urls_table.= format_repo_url("Push URL",$push)ifdefined$push;5178}5179}elsif(defined$push) {5180$urls_table.= format_repo_url("Push URL",$push);5181}else{5182$urls_table.= format_repo_url("","No remote URL");5183}51845185$urls_table.="</table>\n";51865187my$dots;5188if(defined$limit&&$limit<@$heads) {5189$dots=$cgi->a({-href => href(action=>"remotes", hash=>$remote)},"...");5190}51915192print$urls_table;5193 git_heads_body($heads,$head,0,$limit,$dots);5194}51955196# Display a list of remote names with the respective fetch and push URLs5197sub git_remotes_list {5198my($remotedata,$limit) =@_;5199print"<table class=\"heads\">\n";5200my$alternate=1;5201my@remotes=sort keys%$remotedata;52025203my$limited=$limit&&$limit<@remotes;52045205$#remotes=$limit-1if$limited;52065207while(my$remote=shift@remotes) {5208my$rdata=$remotedata->{$remote};5209my$fetch=$rdata->{'fetch'};5210my$push=$rdata->{'push'};5211if($alternate) {5212print"<tr class=\"dark\">\n";5213}else{5214print"<tr class=\"light\">\n";5215}5216$alternate^=1;5217print"<td>".5218$cgi->a({-href=> href(action=>'remotes', hash=>$remote),5219-class=>"list name"},esc_html($remote)) .5220"</td>";5221print"<td class=\"link\">".5222(defined$fetch?$cgi->a({-href=>$fetch},"fetch") :"fetch") .5223" | ".5224(defined$push?$cgi->a({-href=>$push},"push") :"push") .5225"</td>";52265227print"</tr>\n";5228}52295230if($limited) {5231print"<tr>\n".5232"<td colspan=\"3\">".5233$cgi->a({-href => href(action=>"remotes")},"...") .5234"</td>\n"."</tr>\n";5235}52365237print"</table>";5238}52395240# Display remote heads grouped by remote, unless there are too many5241# remotes, in which case we only display the remote names5242sub git_remotes_body {5243my($remotedata,$limit,$head) =@_;5244if($limitand$limit<keys%$remotedata) {5245 git_remotes_list($remotedata,$limit);5246}else{5247 fill_remote_heads($remotedata);5248while(my($remote,$rdata) =each%$remotedata) {5249 git_print_section({-class=>"remote", -id=>$remote},5250["remotes",$remote,$remote],sub{5251 git_remote_block($remote,$rdata,$limit,$head);5252});5253}5254}5255}52565257sub git_search_message {5258my%co=@_;52595260my$greptype;5261if($searchtypeeq'commit') {5262$greptype="--grep=";5263}elsif($searchtypeeq'author') {5264$greptype="--author=";5265}elsif($searchtypeeq'committer') {5266$greptype="--committer=";5267}5268$greptype.=$searchtext;5269my@commitlist= parse_commits($hash,101, (100*$page),undef,5270$greptype,'--regexp-ignore-case',5271$search_use_regexp?'--extended-regexp':'--fixed-strings');52725273my$paging_nav='';5274if($page>0) {5275$paging_nav.=5276$cgi->a({-href => href(-replay=>1, page=>undef)},5277"first") .5278" ⋅ ".5279$cgi->a({-href => href(-replay=>1, page=>$page-1),5280-accesskey =>"p", -title =>"Alt-p"},"prev");5281}else{5282$paging_nav.="first ⋅ prev";5283}5284my$next_link='';5285if($#commitlist>=100) {5286$next_link=5287$cgi->a({-href => href(-replay=>1, page=>$page+1),5288-accesskey =>"n", -title =>"Alt-n"},"next");5289$paging_nav.=" ⋅$next_link";5290}else{5291$paging_nav.=" ⋅ next";5292}52935294 git_header_html();52955296 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);5297 git_print_header_div('commit', esc_html($co{'title'}),$hash);5298if($page==0&& !@commitlist) {5299print"<p>No match.</p>\n";5300}else{5301 git_search_grep_body(\@commitlist,0,99,$next_link);5302}53035304 git_footer_html();5305}53065307sub git_search_changes {5308my%co=@_;53095310local$/="\n";5311open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,5312'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",5313($search_use_regexp?'--pickaxe-regex': ())5314or die_error(500,"Open git-log failed");53155316 git_header_html();53175318 git_print_page_nav('','',$hash,$co{'tree'},$hash);5319 git_print_header_div('commit', esc_html($co{'title'}),$hash);53205321print"<table class=\"pickaxe search\">\n";5322my$alternate=1;5323undef%co;5324my@files;5325while(my$line= <$fd>) {5326chomp$line;5327next unless$line;53285329my%set= parse_difftree_raw_line($line);5330if(defined$set{'commit'}) {5331# finish previous commit5332if(%co) {5333print"</td>\n".5334"<td class=\"link\">".5335$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},5336"commit") .5337" | ".5338$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'},5339 hash_base=>$co{'id'})},5340"tree") .5341"</td>\n".5342"</tr>\n";5343}53445345if($alternate) {5346print"<tr class=\"dark\">\n";5347}else{5348print"<tr class=\"light\">\n";5349}5350$alternate^=1;5351%co= parse_commit($set{'commit'});5352my$author= chop_and_escape_str($co{'author_name'},15,5);5353print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5354"<td><i>$author</i></td>\n".5355"<td>".5356$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),5357-class=>"list subject"},5358 chop_and_escape_str($co{'title'},50) ."<br/>");5359}elsif(defined$set{'to_id'}) {5360next if($set{'to_id'} =~m/^0{40}$/);53615362print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},5363 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),5364-class=>"list"},5365"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .5366"<br/>\n";5367}5368}5369close$fd;53705371# finish last commit (warning: repetition!)5372if(%co) {5373print"</td>\n".5374"<td class=\"link\">".5375$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},5376"commit") .5377" | ".5378$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'},5379 hash_base=>$co{'id'})},5380"tree") .5381"</td>\n".5382"</tr>\n";5383}53845385print"</table>\n";53865387 git_footer_html();5388}53895390sub git_search_files {5391my%co=@_;53925393local$/="\n";5394open my$fd,"-|", git_cmd(),'grep','-n',5395$search_use_regexp? ('-E','-i') :'-F',5396$searchtext,$co{'tree'}5397or die_error(500,"Open git-grep failed");53985399 git_header_html();54005401 git_print_page_nav('','',$hash,$co{'tree'},$hash);5402 git_print_header_div('commit', esc_html($co{'title'}),$hash);54035404print"<table class=\"grep_search\">\n";5405my$alternate=1;5406my$matches=0;5407my$lastfile='';5408while(my$line= <$fd>) {5409chomp$line;5410my($file,$lno,$ltext,$binary);5411last if($matches++>1000);5412if($line=~/^Binary file (.+) matches$/) {5413$file=$1;5414$binary=1;5415}else{5416(undef,$file,$lno,$ltext) =split(/:/,$line,4);5417}5418if($filene$lastfile) {5419$lastfileand print"</td></tr>\n";5420if($alternate++) {5421print"<tr class=\"dark\">\n";5422}else{5423print"<tr class=\"light\">\n";5424}5425print"<td class=\"list\">".5426$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5427 file_name=>"$file"),5428-class=>"list"}, esc_path($file));5429print"</td><td>\n";5430$lastfile=$file;5431}5432if($binary) {5433print"<div class=\"binary\">Binary file</div>\n";5434}else{5435$ltext= untabify($ltext);5436if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {5437$ltext= esc_html($1, -nbsp=>1);5438$ltext.='<span class="match">';5439$ltext.= esc_html($2, -nbsp=>1);5440$ltext.='</span>';5441$ltext.= esc_html($3, -nbsp=>1);5442}else{5443$ltext= esc_html($ltext, -nbsp=>1);5444}5445print"<div class=\"pre\">".5446$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5447 file_name=>"$file").'#l'.$lno,5448-class=>"linenr"},sprintf('%4i',$lno))5449.' '.$ltext."</div>\n";5450}5451}5452if($lastfile) {5453print"</td></tr>\n";5454if($matches>1000) {5455print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";5456}5457}else{5458print"<div class=\"diff nodifferences\">No matches found</div>\n";5459}5460close$fd;54615462print"</table>\n";54635464 git_footer_html();5465}54665467sub git_search_grep_body {5468my($commitlist,$from,$to,$extra) =@_;5469$from=0unlessdefined$from;5470$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);54715472print"<table class=\"commit_search\">\n";5473my$alternate=1;5474for(my$i=$from;$i<=$to;$i++) {5475my%co= %{$commitlist->[$i]};5476if(!%co) {5477next;5478}5479my$commit=$co{'id'};5480if($alternate) {5481print"<tr class=\"dark\">\n";5482}else{5483print"<tr class=\"light\">\n";5484}5485$alternate^=1;5486print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5487 format_author_html('td', \%co,15,5) .5488"<td>".5489$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),5490-class=>"list subject"},5491 chop_and_escape_str($co{'title'},50) ."<br/>");5492my$comment=$co{'comment'};5493foreachmy$line(@$comment) {5494if($line=~m/^(.*?)($search_regexp)(.*)$/i) {5495my($lead,$match,$trail) = ($1,$2,$3);5496$match= chop_str($match,70,5,'center');5497my$contextlen=int((80-length($match))/2);5498$contextlen=30if($contextlen>30);5499$lead= chop_str($lead,$contextlen,10,'left');5500$trail= chop_str($trail,$contextlen,10,'right');55015502$lead= esc_html($lead);5503$match= esc_html($match);5504$trail= esc_html($trail);55055506print"$lead<span class=\"match\">$match</span>$trail<br />";5507}5508}5509print"</td>\n".5510"<td class=\"link\">".5511$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5512" | ".5513$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .5514" | ".5515$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5516print"</td>\n".5517"</tr>\n";5518}5519if(defined$extra) {5520print"<tr>\n".5521"<td colspan=\"3\">$extra</td>\n".5522"</tr>\n";5523}5524print"</table>\n";5525}55265527## ======================================================================5528## ======================================================================5529## actions55305531sub git_project_list {5532my$order=$input_params{'order'};5533if(defined$order&&$order!~m/none|project|descr|owner|age/) {5534 die_error(400,"Unknown order parameter");5535}55365537my@list= git_get_projects_list();5538if(!@list) {5539 die_error(404,"No projects found");5540}55415542 git_header_html();5543if(defined$home_text&& -f $home_text) {5544print"<div class=\"index_include\">\n";5545 insert_file($home_text);5546print"</div>\n";5547}5548print$cgi->startform(-method=>"get") .5549"<p class=\"projsearch\">Search:\n".5550$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".5551"</p>".5552$cgi->end_form() ."\n";5553 git_project_list_body(\@list,$order);5554 git_footer_html();5555}55565557sub git_forks {5558my$order=$input_params{'order'};5559if(defined$order&&$order!~m/none|project|descr|owner|age/) {5560 die_error(400,"Unknown order parameter");5561}55625563my@list= git_get_projects_list($project);5564if(!@list) {5565 die_error(404,"No forks found");5566}55675568 git_header_html();5569 git_print_page_nav('','');5570 git_print_header_div('summary',"$projectforks");5571 git_project_list_body(\@list,$order);5572 git_footer_html();5573}55745575sub git_project_index {5576my@projects= git_get_projects_list($project);55775578print$cgi->header(5579-type =>'text/plain',5580-charset =>'utf-8',5581-content_disposition =>'inline; filename="index.aux"');55825583foreachmy$pr(@projects) {5584if(!exists$pr->{'owner'}) {5585$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");5586}55875588my($path,$owner) = ($pr->{'path'},$pr->{'owner'});5589# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '5590$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;5591$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;5592$path=~s/ /\+/g;5593$owner=~s/ /\+/g;55945595print"$path$owner\n";5596}5597}55985599sub git_summary {5600my$descr= git_get_project_description($project) ||"none";5601my%co= parse_commit("HEAD");5602my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();5603my$head=$co{'id'};5604my$remote_heads= gitweb_check_feature('remote_heads');56055606my$owner= git_get_project_owner($project);56075608my$refs= git_get_references();5609# These get_*_list functions return one more to allow us to see if5610# there are more ...5611my@taglist= git_get_tags_list(16);5612my@headlist= git_get_heads_list(16);5613my%remotedata=$remote_heads? git_get_remotes_list() : ();5614my@forklist;5615my$check_forks= gitweb_check_feature('forks');56165617if($check_forks) {5618@forklist= git_get_projects_list($project);5619}56205621 git_header_html();5622 git_print_page_nav('summary','',$head);56235624print"<div class=\"title\"> </div>\n";5625print"<table class=\"projects_list\">\n".5626"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".5627"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";5628if(defined$cd{'rfc2822'}) {5629print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";5630}56315632# use per project git URL list in $projectroot/$project/cloneurl5633# or make project git URL from git base URL and project name5634my$url_tag="URL";5635my@url_list= git_get_project_url_list($project);5636@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;5637foreachmy$git_url(@url_list) {5638next unless$git_url;5639print format_repo_url($url_tag,$git_url);5640$url_tag="";5641}56425643# Tag cloud5644my$show_ctags= gitweb_check_feature('ctags');5645if($show_ctags) {5646my$ctags= git_get_project_ctags($project);5647my$cloud= git_populate_project_tagcloud($ctags);5648print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";5649print"</td>\n<td>"unless%$ctags;5650print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";5651print"</td>\n<td>"if%$ctags;5652print git_show_project_tagcloud($cloud,48);5653print"</td></tr>";5654}56555656print"</table>\n";56575658# If XSS prevention is on, we don't include README.html.5659# TODO: Allow a readme in some safe format.5660if(!$prevent_xss&& -s "$projectroot/$project/README.html") {5661print"<div class=\"title\">readme</div>\n".5662"<div class=\"readme\">\n";5663 insert_file("$projectroot/$project/README.html");5664print"\n</div>\n";# class="readme"5665}56665667# we need to request one more than 16 (0..15) to check if5668# those 16 are all5669my@commitlist=$head? parse_commits($head,17) : ();5670if(@commitlist) {5671 git_print_header_div('shortlog');5672 git_shortlog_body(\@commitlist,0,15,$refs,5673$#commitlist<=15?undef:5674$cgi->a({-href => href(action=>"shortlog")},"..."));5675}56765677if(@taglist) {5678 git_print_header_div('tags');5679 git_tags_body(\@taglist,0,15,5680$#taglist<=15?undef:5681$cgi->a({-href => href(action=>"tags")},"..."));5682}56835684if(@headlist) {5685 git_print_header_div('heads');5686 git_heads_body(\@headlist,$head,0,15,5687$#headlist<=15?undef:5688$cgi->a({-href => href(action=>"heads")},"..."));5689}56905691if(%remotedata) {5692 git_print_header_div('remotes');5693 git_remotes_body(\%remotedata,15,$head);5694}56955696if(@forklist) {5697 git_print_header_div('forks');5698 git_project_list_body(\@forklist,'age',0,15,5699$#forklist<=15?undef:5700$cgi->a({-href => href(action=>"forks")},"..."),5701'no_header');5702}57035704 git_footer_html();5705}57065707sub git_tag {5708my%tag= parse_tag($hash);57095710if(!%tag) {5711 die_error(404,"Unknown tag object");5712}57135714my$head= git_get_head_hash($project);5715 git_header_html();5716 git_print_page_nav('','',$head,undef,$head);5717 git_print_header_div('commit', esc_html($tag{'name'}),$hash);5718print"<div class=\"title_text\">\n".5719"<table class=\"object_header\">\n".5720"<tr>\n".5721"<td>object</td>\n".5722"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},5723$tag{'object'}) ."</td>\n".5724"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},5725$tag{'type'}) ."</td>\n".5726"</tr>\n";5727if(defined($tag{'author'})) {5728 git_print_authorship_rows(\%tag,'author');5729}5730print"</table>\n\n".5731"</div>\n";5732print"<div class=\"page_body\">";5733my$comment=$tag{'comment'};5734foreachmy$line(@$comment) {5735chomp$line;5736print esc_html($line, -nbsp=>1) ."<br/>\n";5737}5738print"</div>\n";5739 git_footer_html();5740}57415742sub git_blame_common {5743my$format=shift||'porcelain';5744if($formateq'porcelain'&&$cgi->param('js')) {5745$format='incremental';5746$action='blame_incremental';# for page title etc5747}57485749# permissions5750 gitweb_check_feature('blame')5751or die_error(403,"Blame view not allowed");57525753# error checking5754 die_error(400,"No file name given")unless$file_name;5755$hash_base||= git_get_head_hash($project);5756 die_error(404,"Couldn't find base commit")unless$hash_base;5757my%co= parse_commit($hash_base)5758or die_error(404,"Commit not found");5759my$ftype="blob";5760if(!defined$hash) {5761$hash= git_get_hash_by_path($hash_base,$file_name,"blob")5762or die_error(404,"Error looking up file");5763}else{5764$ftype= git_get_type($hash);5765if($ftype!~"blob") {5766 die_error(400,"Object is not a blob");5767}5768}57695770my$fd;5771if($formateq'incremental') {5772# get file contents (as base)5773open$fd,"-|", git_cmd(),'cat-file','blob',$hash5774or die_error(500,"Open git-cat-file failed");5775}elsif($formateq'data') {5776# run git-blame --incremental5777open$fd,"-|", git_cmd(),"blame","--incremental",5778$hash_base,"--",$file_name5779or die_error(500,"Open git-blame --incremental failed");5780}else{5781# run git-blame --porcelain5782open$fd,"-|", git_cmd(),"blame",'-p',5783$hash_base,'--',$file_name5784or die_error(500,"Open git-blame --porcelain failed");5785}57865787# incremental blame data returns early5788if($formateq'data') {5789print$cgi->header(5790-type=>"text/plain", -charset =>"utf-8",5791-status=>"200 OK");5792local$| =1;# output autoflush5793printwhile<$fd>;5794close$fd5795or print"ERROR$!\n";57965797print'END';5798if(defined$t0&& gitweb_check_feature('timed')) {5799print' '.5800 tv_interval($t0, [ gettimeofday() ]).5801' '.$number_of_git_cmds;5802}5803print"\n";58045805return;5806}58075808# page header5809 git_header_html();5810my$formats_nav=5811$cgi->a({-href => href(action=>"blob", -replay=>1)},5812"blob") .5813" | ";5814if($formateq'incremental') {5815$formats_nav.=5816$cgi->a({-href => href(action=>"blame", javascript=>0, -replay=>1)},5817"blame") ." (non-incremental)";5818}else{5819$formats_nav.=5820$cgi->a({-href => href(action=>"blame_incremental", -replay=>1)},5821"blame") ." (incremental)";5822}5823$formats_nav.=5824" | ".5825$cgi->a({-href => href(action=>"history", -replay=>1)},5826"history") .5827" | ".5828$cgi->a({-href => href(action=>$action, file_name=>$file_name)},5829"HEAD");5830 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5831 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5832 git_print_page_path($file_name,$ftype,$hash_base);58335834# page body5835if($formateq'incremental') {5836print"<noscript>\n<div class=\"error\"><center><b>\n".5837"This page requires JavaScript to run.\nUse ".5838$cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},5839'this page').5840" instead.\n".5841"</b></center></div>\n</noscript>\n";58425843print qq!<div id="progress_bar" style="width: 100%; background-color: yellow"></div>\n!;5844}58455846print qq!<div class="page_body">\n!;5847print qq!<div id="progress_info">.../ ...</div>\n!5848if($formateq'incremental');5849print qq!<table id="blame_table"class="blame" width="100%">\n!.5850#qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.5851 qq!<thead>\n!.5852 qq!<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n!.5853 qq!</thead>\n!.5854 qq!<tbody>\n!;58555856my@rev_color=qw(light dark);5857my$num_colors=scalar(@rev_color);5858my$current_color=0;58595860if($formateq'incremental') {5861my$color_class=$rev_color[$current_color];58625863#contents of a file5864my$linenr=0;5865 LINE:5866while(my$line= <$fd>) {5867chomp$line;5868$linenr++;58695870print qq!<tr id="l$linenr"class="$color_class">!.5871 qq!<td class="sha1"><a href=""> </a></td>!.5872 qq!<td class="linenr">!.5873 qq!<a class="linenr" href="">$linenr</a></td>!;5874print qq!<td class="pre">! . esc_html($line) ."</td>\n";5875print qq!</tr>\n!;5876}58775878}else{# porcelain, i.e. ordinary blame5879my%metainfo= ();# saves information about commits58805881# blame data5882 LINE:5883while(my$line= <$fd>) {5884chomp$line;5885# the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]5886# no <lines in group> for subsequent lines in group of lines5887my($full_rev,$orig_lineno,$lineno,$group_size) =5888($line=~/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);5889if(!exists$metainfo{$full_rev}) {5890$metainfo{$full_rev} = {'nprevious'=>0};5891}5892my$meta=$metainfo{$full_rev};5893my$data;5894while($data= <$fd>) {5895chomp$data;5896last if($data=~s/^\t//);# contents of line5897if($data=~/^(\S+)(?: (.*))?$/) {5898$meta->{$1} =$2unlessexists$meta->{$1};5899}5900if($data=~/^previous /) {5901$meta->{'nprevious'}++;5902}5903}5904my$short_rev=substr($full_rev,0,8);5905my$author=$meta->{'author'};5906my%date=5907 parse_date($meta->{'author-time'},$meta->{'author-tz'});5908my$date=$date{'iso-tz'};5909if($group_size) {5910$current_color= ($current_color+1) %$num_colors;5911}5912my$tr_class=$rev_color[$current_color];5913$tr_class.=' boundary'if(exists$meta->{'boundary'});5914$tr_class.=' no-previous'if($meta->{'nprevious'} ==0);5915$tr_class.=' multiple-previous'if($meta->{'nprevious'} >1);5916print"<tr id=\"l$lineno\"class=\"$tr_class\">\n";5917if($group_size) {5918print"<td class=\"sha1\"";5919print" title=\"". esc_html($author) .",$date\"";5920print" rowspan=\"$group_size\""if($group_size>1);5921print">";5922print$cgi->a({-href => href(action=>"commit",5923 hash=>$full_rev,5924 file_name=>$file_name)},5925 esc_html($short_rev));5926if($group_size>=2) {5927my@author_initials= ($author=~/\b([[:upper:]])\B/g);5928if(@author_initials) {5929print"<br />".5930 esc_html(join('',@author_initials));5931# or join('.', ...)5932}5933}5934print"</td>\n";5935}5936# 'previous' <sha1 of parent commit> <filename at commit>5937if(exists$meta->{'previous'} &&5938$meta->{'previous'} =~/^([a-fA-F0-9]{40}) (.*)$/) {5939$meta->{'parent'} =$1;5940$meta->{'file_parent'} = unquote($2);5941}5942my$linenr_commit=5943exists($meta->{'parent'}) ?5944$meta->{'parent'} :$full_rev;5945my$linenr_filename=5946exists($meta->{'file_parent'}) ?5947$meta->{'file_parent'} : unquote($meta->{'filename'});5948my$blamed= href(action =>'blame',5949 file_name =>$linenr_filename,5950 hash_base =>$linenr_commit);5951print"<td class=\"linenr\">";5952print$cgi->a({ -href =>"$blamed#l$orig_lineno",5953-class=>"linenr"},5954 esc_html($lineno));5955print"</td>";5956print"<td class=\"pre\">". esc_html($data) ."</td>\n";5957print"</tr>\n";5958}# end while59595960}59615962# footer5963print"</tbody>\n".5964"</table>\n";# class="blame"5965print"</div>\n";# class="blame_body"5966close$fd5967or print"Reading blob failed\n";59685969 git_footer_html();5970}59715972sub git_blame {5973 git_blame_common();5974}59755976sub git_blame_incremental {5977 git_blame_common('incremental');5978}59795980sub git_blame_data {5981 git_blame_common('data');5982}59835984sub git_tags {5985my$head= git_get_head_hash($project);5986 git_header_html();5987 git_print_page_nav('','',$head,undef,$head,format_ref_views('tags'));5988 git_print_header_div('summary',$project);59895990my@tagslist= git_get_tags_list();5991if(@tagslist) {5992 git_tags_body(\@tagslist);5993}5994 git_footer_html();5995}59965997sub git_heads {5998my$head= git_get_head_hash($project);5999 git_header_html();6000 git_print_page_nav('','',$head,undef,$head,format_ref_views('heads'));6001 git_print_header_div('summary',$project);60026003my@headslist= git_get_heads_list();6004if(@headslist) {6005 git_heads_body(\@headslist,$head);6006}6007 git_footer_html();6008}60096010# used both for single remote view and for list of all the remotes6011sub git_remotes {6012 gitweb_check_feature('remote_heads')6013or die_error(403,"Remote heads view is disabled");60146015my$head= git_get_head_hash($project);6016my$remote=$input_params{'hash'};60176018my$remotedata= git_get_remotes_list($remote);6019 die_error(500,"Unable to get remote information")unlessdefined$remotedata;60206021unless(%$remotedata) {6022 die_error(404,defined$remote?6023"Remote$remotenot found":6024"No remotes found");6025}60266027 git_header_html(undef,undef, -action_extra =>$remote);6028 git_print_page_nav('','',$head,undef,$head,6029 format_ref_views($remote?'':'remotes'));60306031 fill_remote_heads($remotedata);6032if(defined$remote) {6033 git_print_header_div('remotes',"$remoteremote for$project");6034 git_remote_block($remote,$remotedata->{$remote},undef,$head);6035}else{6036 git_print_header_div('summary',"$projectremotes");6037 git_remotes_body($remotedata,undef,$head);6038}60396040 git_footer_html();6041}60426043sub git_blob_plain {6044my$type=shift;6045my$expires;60466047if(!defined$hash) {6048if(defined$file_name) {6049my$base=$hash_base|| git_get_head_hash($project);6050$hash= git_get_hash_by_path($base,$file_name,"blob")6051or die_error(404,"Cannot find file");6052}else{6053 die_error(400,"No file name defined");6054}6055}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {6056# blobs defined by non-textual hash id's can be cached6057$expires="+1d";6058}60596060open my$fd,"-|", git_cmd(),"cat-file","blob",$hash6061or die_error(500,"Open git-cat-file blob '$hash' failed");60626063# content-type (can include charset)6064$type= blob_contenttype($fd,$file_name,$type);60656066# "save as" filename, even when no $file_name is given6067my$save_as="$hash";6068if(defined$file_name) {6069$save_as=$file_name;6070}elsif($type=~m/^text\//) {6071$save_as.='.txt';6072}60736074# With XSS prevention on, blobs of all types except a few known safe6075# ones are served with "Content-Disposition: attachment" to make sure6076# they don't run in our security domain. For certain image types,6077# blob view writes an <img> tag referring to blob_plain view, and we6078# want to be sure not to break that by serving the image as an6079# attachment (though Firefox 3 doesn't seem to care).6080my$sandbox=$prevent_xss&&6081$type!~m!^(?:text/plain|image/(?:gif|png|jpeg))$!;60826083print$cgi->header(6084-type =>$type,6085-expires =>$expires,6086-content_disposition =>6087($sandbox?'attachment':'inline')6088.'; filename="'.$save_as.'"');6089local$/=undef;6090binmode STDOUT,':raw';6091print<$fd>;6092binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi6093close$fd;6094}60956096sub git_blob {6097my$expires;60986099if(!defined$hash) {6100if(defined$file_name) {6101my$base=$hash_base|| git_get_head_hash($project);6102$hash= git_get_hash_by_path($base,$file_name,"blob")6103or die_error(404,"Cannot find file");6104}else{6105 die_error(400,"No file name defined");6106}6107}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {6108# blobs defined by non-textual hash id's can be cached6109$expires="+1d";6110}61116112my$have_blame= gitweb_check_feature('blame');6113open my$fd,"-|", git_cmd(),"cat-file","blob",$hash6114or die_error(500,"Couldn't cat$file_name,$hash");6115my$mimetype= blob_mimetype($fd,$file_name);6116# use 'blob_plain' (aka 'raw') view for files that cannot be displayed6117if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {6118close$fd;6119return git_blob_plain($mimetype);6120}6121# we can have blame only for text/* mimetype6122$have_blame&&= ($mimetype=~m!^text/!);61236124my$highlight= gitweb_check_feature('highlight');6125my$syntax= guess_file_syntax($highlight,$mimetype,$file_name);6126$fd= run_highlighter($fd,$highlight,$syntax)6127if$syntax;61286129 git_header_html(undef,$expires);6130my$formats_nav='';6131if(defined$hash_base&& (my%co= parse_commit($hash_base))) {6132if(defined$file_name) {6133if($have_blame) {6134$formats_nav.=6135$cgi->a({-href => href(action=>"blame", -replay=>1)},6136"blame") .6137" | ";6138}6139$formats_nav.=6140$cgi->a({-href => href(action=>"history", -replay=>1)},6141"history") .6142" | ".6143$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},6144"raw") .6145" | ".6146$cgi->a({-href => href(action=>"blob",6147 hash_base=>"HEAD", file_name=>$file_name)},6148"HEAD");6149}else{6150$formats_nav.=6151$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},6152"raw");6153}6154 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);6155 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);6156}else{6157print"<div class=\"page_nav\">\n".6158"<br/><br/></div>\n".6159"<div class=\"title\">".esc_html($hash)."</div>\n";6160}6161 git_print_page_path($file_name,"blob",$hash_base);6162print"<div class=\"page_body\">\n";6163if($mimetype=~m!^image/!) {6164print qq!<img type="!.esc_attr($mimetype).qq!"!;6165if($file_name) {6166print qq! alt="!.esc_attr($file_name).qq!" title="!.esc_attr($file_name).qq!"!;6167}6168print qq! src="! .6169 href(action=>"blob_plain", hash=>$hash,6170 hash_base=>$hash_base, file_name=>$file_name) .6171 qq!"/>\n!;6172}else{6173my$nr;6174while(my$line= <$fd>) {6175chomp$line;6176$nr++;6177$line= untabify($line);6178printf qq!<div class="pre"><a id="l%i" href="%s#l%i"class="linenr">%4i</a> %s</div>\n!,6179$nr, esc_attr(href(-replay =>1)),$nr,$nr,$syntax?$line: esc_html($line, -nbsp=>1);6180}6181}6182close$fd6183or print"Reading blob failed.\n";6184print"</div>";6185 git_footer_html();6186}61876188sub git_tree {6189if(!defined$hash_base) {6190$hash_base="HEAD";6191}6192if(!defined$hash) {6193if(defined$file_name) {6194$hash= git_get_hash_by_path($hash_base,$file_name,"tree");6195}else{6196$hash=$hash_base;6197}6198}6199 die_error(404,"No such tree")unlessdefined($hash);62006201my$show_sizes= gitweb_check_feature('show-sizes');6202my$have_blame= gitweb_check_feature('blame');62036204my@entries= ();6205{6206local$/="\0";6207open my$fd,"-|", git_cmd(),"ls-tree",'-z',6208($show_sizes?'-l': ()),@extra_options,$hash6209or die_error(500,"Open git-ls-tree failed");6210@entries=map{chomp;$_} <$fd>;6211close$fd6212or die_error(404,"Reading tree failed");6213}62146215my$refs= git_get_references();6216my$ref= format_ref_marker($refs,$hash_base);6217 git_header_html();6218my$basedir='';6219if(defined$hash_base&& (my%co= parse_commit($hash_base))) {6220my@views_nav= ();6221if(defined$file_name) {6222push@views_nav,6223$cgi->a({-href => href(action=>"history", -replay=>1)},6224"history"),6225$cgi->a({-href => href(action=>"tree",6226 hash_base=>"HEAD", file_name=>$file_name)},6227"HEAD"),6228}6229my$snapshot_links= format_snapshot_links($hash);6230if(defined$snapshot_links) {6231# FIXME: Should be available when we have no hash base as well.6232push@views_nav,$snapshot_links;6233}6234 git_print_page_nav('tree','',$hash_base,undef,undef,6235join(' | ',@views_nav));6236 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);6237}else{6238undef$hash_base;6239print"<div class=\"page_nav\">\n";6240print"<br/><br/></div>\n";6241print"<div class=\"title\">".esc_html($hash)."</div>\n";6242}6243if(defined$file_name) {6244$basedir=$file_name;6245if($basedirne''&&substr($basedir, -1)ne'/') {6246$basedir.='/';6247}6248 git_print_page_path($file_name,'tree',$hash_base);6249}6250print"<div class=\"page_body\">\n";6251print"<table class=\"tree\">\n";6252my$alternate=1;6253# '..' (top directory) link if possible6254if(defined$hash_base&&6255defined$file_name&&$file_name=~m![^/]+$!) {6256if($alternate) {6257print"<tr class=\"dark\">\n";6258}else{6259print"<tr class=\"light\">\n";6260}6261$alternate^=1;62626263my$up=$file_name;6264$up=~s!/?[^/]+$!!;6265undef$upunless$up;6266# based on git_print_tree_entry6267print'<td class="mode">'. mode_str('040000') ."</td>\n";6268print'<td class="size"> </td>'."\n"if$show_sizes;6269print'<td class="list">';6270print$cgi->a({-href => href(action=>"tree",6271 hash_base=>$hash_base,6272 file_name=>$up)},6273"..");6274print"</td>\n";6275print"<td class=\"link\"></td>\n";62766277print"</tr>\n";6278}6279foreachmy$line(@entries) {6280my%t= parse_ls_tree_line($line, -z =>1, -l =>$show_sizes);62816282if($alternate) {6283print"<tr class=\"dark\">\n";6284}else{6285print"<tr class=\"light\">\n";6286}6287$alternate^=1;62886289 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);62906291print"</tr>\n";6292}6293print"</table>\n".6294"</div>";6295 git_footer_html();6296}62976298sub snapshot_name {6299my($project,$hash) =@_;63006301# path/to/project.git -> project6302# path/to/project/.git -> project6303my$name= to_utf8($project);6304$name=~ s,([^/])/*\.git$,$1,;6305$name= basename($name);6306# sanitize name6307$name=~s/[[:cntrl:]]/?/g;63086309my$ver=$hash;6310if($hash=~/^[0-9a-fA-F]+$/) {6311# shorten SHA-1 hash6312my$full_hash= git_get_full_hash($project,$hash);6313if($full_hash=~/^$hash/&&length($hash) >7) {6314$ver= git_get_short_hash($project,$hash);6315}6316}elsif($hash=~m!^refs/tags/(.*)$!) {6317# tags don't need shortened SHA-1 hash6318$ver=$1;6319}else{6320# branches and other need shortened SHA-1 hash6321if($hash=~m!^refs/(?:heads|remotes)/(.*)$!) {6322$ver=$1;6323}6324$ver.='-'. git_get_short_hash($project,$hash);6325}6326# in case of hierarchical branch names6327$ver=~s!/!.!g;63286329# name = project-version_string6330$name="$name-$ver";63316332returnwantarray? ($name,$name) :$name;6333}63346335sub git_snapshot {6336my$format=$input_params{'snapshot_format'};6337if(!@snapshot_fmts) {6338 die_error(403,"Snapshots not allowed");6339}6340# default to first supported snapshot format6341$format||=$snapshot_fmts[0];6342if($format!~m/^[a-z0-9]+$/) {6343 die_error(400,"Invalid snapshot format parameter");6344}elsif(!exists($known_snapshot_formats{$format})) {6345 die_error(400,"Unknown snapshot format");6346}elsif($known_snapshot_formats{$format}{'disabled'}) {6347 die_error(403,"Snapshot format not allowed");6348}elsif(!grep($_eq$format,@snapshot_fmts)) {6349 die_error(403,"Unsupported snapshot format");6350}63516352my$type= git_get_type("$hash^{}");6353if(!$type) {6354 die_error(404,'Object does not exist');6355}elsif($typeeq'blob') {6356 die_error(400,'Object is not a tree-ish');6357}63586359my($name,$prefix) = snapshot_name($project,$hash);6360my$filename="$name$known_snapshot_formats{$format}{'suffix'}";6361my$cmd= quote_command(6362 git_cmd(),'archive',6363"--format=$known_snapshot_formats{$format}{'format'}",6364"--prefix=$prefix/",$hash);6365if(exists$known_snapshot_formats{$format}{'compressor'}) {6366$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});6367}63686369$filename=~s/(["\\])/\\$1/g;6370print$cgi->header(6371-type =>$known_snapshot_formats{$format}{'type'},6372-content_disposition =>'inline; filename="'.$filename.'"',6373-status =>'200 OK');63746375open my$fd,"-|",$cmd6376or die_error(500,"Execute git-archive failed");6377binmode STDOUT,':raw';6378print<$fd>;6379binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi6380close$fd;6381}63826383sub git_log_generic {6384my($fmt_name,$body_subr,$base,$parent,$file_name,$file_hash) =@_;63856386my$head= git_get_head_hash($project);6387if(!defined$base) {6388$base=$head;6389}6390if(!defined$page) {6391$page=0;6392}6393my$refs= git_get_references();63946395my$commit_hash=$base;6396if(defined$parent) {6397$commit_hash="$parent..$base";6398}6399my@commitlist=6400 parse_commits($commit_hash,101, (100*$page),6401defined$file_name? ($file_name,"--full-history") : ());64026403my$ftype;6404if(!defined$file_hash&&defined$file_name) {6405# some commits could have deleted file in question,6406# and not have it in tree, but one of them has to have it6407for(my$i=0;$i<@commitlist;$i++) {6408$file_hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);6409last ifdefined$file_hash;6410}6411}6412if(defined$file_hash) {6413$ftype= git_get_type($file_hash);6414}6415if(defined$file_name&& !defined$ftype) {6416 die_error(500,"Unknown type of object");6417}6418my%co;6419if(defined$file_name) {6420%co= parse_commit($base)6421or die_error(404,"Unknown commit object");6422}642364246425my$paging_nav= format_paging_nav($fmt_name,$page,$#commitlist>=100);6426my$next_link='';6427if($#commitlist>=100) {6428$next_link=6429$cgi->a({-href => href(-replay=>1, page=>$page+1),6430-accesskey =>"n", -title =>"Alt-n"},"next");6431}6432my$patch_max= gitweb_get_feature('patches');6433if($patch_max&& !defined$file_name) {6434if($patch_max<0||@commitlist<=$patch_max) {6435$paging_nav.=" ⋅ ".6436$cgi->a({-href => href(action=>"patches", -replay=>1)},6437"patches");6438}6439}64406441 git_header_html();6442 git_print_page_nav($fmt_name,'',$hash,$hash,$hash,$paging_nav);6443if(defined$file_name) {6444 git_print_header_div('commit', esc_html($co{'title'}),$base);6445}else{6446 git_print_header_div('summary',$project)6447}6448 git_print_page_path($file_name,$ftype,$hash_base)6449if(defined$file_name);64506451$body_subr->(\@commitlist,0,99,$refs,$next_link,6452$file_name,$file_hash,$ftype);64536454 git_footer_html();6455}64566457sub git_log {6458 git_log_generic('log', \&git_log_body,6459$hash,$hash_parent);6460}64616462sub git_commit {6463$hash||=$hash_base||"HEAD";6464my%co= parse_commit($hash)6465or die_error(404,"Unknown commit object");64666467my$parent=$co{'parent'};6468my$parents=$co{'parents'};# listref64696470# we need to prepare $formats_nav before any parameter munging6471my$formats_nav;6472if(!defined$parent) {6473# --root commitdiff6474$formats_nav.='(initial)';6475}elsif(@$parents==1) {6476# single parent commit6477$formats_nav.=6478'(parent: '.6479$cgi->a({-href => href(action=>"commit",6480 hash=>$parent)},6481 esc_html(substr($parent,0,7))) .6482')';6483}else{6484# merge commit6485$formats_nav.=6486'(merge: '.6487join(' ',map{6488$cgi->a({-href => href(action=>"commit",6489 hash=>$_)},6490 esc_html(substr($_,0,7)));6491}@$parents) .6492')';6493}6494if(gitweb_check_feature('patches') &&@$parents<=1) {6495$formats_nav.=" | ".6496$cgi->a({-href => href(action=>"patch", -replay=>1)},6497"patch");6498}64996500if(!defined$parent) {6501$parent="--root";6502}6503my@difftree;6504open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",6505@diff_opts,6506(@$parents<=1?$parent:'-c'),6507$hash,"--"6508or die_error(500,"Open git-diff-tree failed");6509@difftree=map{chomp;$_} <$fd>;6510close$fdor die_error(404,"Reading git-diff-tree failed");65116512# non-textual hash id's can be cached6513my$expires;6514if($hash=~m/^[0-9a-fA-F]{40}$/) {6515$expires="+1d";6516}6517my$refs= git_get_references();6518my$ref= format_ref_marker($refs,$co{'id'});65196520 git_header_html(undef,$expires);6521 git_print_page_nav('commit','',6522$hash,$co{'tree'},$hash,6523$formats_nav);65246525if(defined$co{'parent'}) {6526 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);6527}else{6528 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);6529}6530print"<div class=\"title_text\">\n".6531"<table class=\"object_header\">\n";6532 git_print_authorship_rows(\%co);6533print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";6534print"<tr>".6535"<td>tree</td>".6536"<td class=\"sha1\">".6537$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),6538class=>"list"},$co{'tree'}) .6539"</td>".6540"<td class=\"link\">".6541$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},6542"tree");6543my$snapshot_links= format_snapshot_links($hash);6544if(defined$snapshot_links) {6545print" | ".$snapshot_links;6546}6547print"</td>".6548"</tr>\n";65496550foreachmy$par(@$parents) {6551print"<tr>".6552"<td>parent</td>".6553"<td class=\"sha1\">".6554$cgi->a({-href => href(action=>"commit", hash=>$par),6555class=>"list"},$par) .6556"</td>".6557"<td class=\"link\">".6558$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .6559" | ".6560$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .6561"</td>".6562"</tr>\n";6563}6564print"</table>".6565"</div>\n";65666567print"<div class=\"page_body\">\n";6568 git_print_log($co{'comment'});6569print"</div>\n";65706571 git_difftree_body(\@difftree,$hash,@$parents);65726573 git_footer_html();6574}65756576sub git_object {6577# object is defined by:6578# - hash or hash_base alone6579# - hash_base and file_name6580my$type;65816582# - hash or hash_base alone6583if($hash|| ($hash_base&& !defined$file_name)) {6584my$object_id=$hash||$hash_base;65856586open my$fd,"-|", quote_command(6587 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'6588or die_error(404,"Object does not exist");6589$type= <$fd>;6590chomp$type;6591close$fd6592or die_error(404,"Object does not exist");65936594# - hash_base and file_name6595}elsif($hash_base&&defined$file_name) {6596$file_name=~ s,/+$,,;65976598system(git_cmd(),"cat-file",'-e',$hash_base) ==06599or die_error(404,"Base object does not exist");66006601# here errors should not hapen6602open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name6603or die_error(500,"Open git-ls-tree failed");6604my$line= <$fd>;6605close$fd;66066607#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'6608unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {6609 die_error(404,"File or directory for given base does not exist");6610}6611$type=$2;6612$hash=$3;6613}else{6614 die_error(400,"Not enough information to find object");6615}66166617print$cgi->redirect(-uri => href(action=>$type, -full=>1,6618 hash=>$hash, hash_base=>$hash_base,6619 file_name=>$file_name),6620-status =>'302 Found');6621}66226623sub git_blobdiff {6624my$format=shift||'html';66256626my$fd;6627my@difftree;6628my%diffinfo;6629my$expires;66306631# preparing $fd and %diffinfo for git_patchset_body6632# new style URI6633if(defined$hash_base&&defined$hash_parent_base) {6634if(defined$file_name) {6635# read raw output6636open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6637$hash_parent_base,$hash_base,6638"--", (defined$file_parent?$file_parent: ()),$file_name6639or die_error(500,"Open git-diff-tree failed");6640@difftree=map{chomp;$_} <$fd>;6641close$fd6642or die_error(404,"Reading git-diff-tree failed");6643@difftree6644or die_error(404,"Blob diff not found");66456646}elsif(defined$hash&&6647$hash=~/[0-9a-fA-F]{40}/) {6648# try to find filename from $hash66496650# read filtered raw output6651open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6652$hash_parent_base,$hash_base,"--"6653or die_error(500,"Open git-diff-tree failed");6654@difftree=6655# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'6656# $hash == to_id6657grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}6658map{chomp;$_} <$fd>;6659close$fd6660or die_error(404,"Reading git-diff-tree failed");6661@difftree6662or die_error(404,"Blob diff not found");66636664}else{6665 die_error(400,"Missing one of the blob diff parameters");6666}66676668if(@difftree>1) {6669 die_error(400,"Ambiguous blob diff specification");6670}66716672%diffinfo= parse_difftree_raw_line($difftree[0]);6673$file_parent||=$diffinfo{'from_file'} ||$file_name;6674$file_name||=$diffinfo{'to_file'};66756676$hash_parent||=$diffinfo{'from_id'};6677$hash||=$diffinfo{'to_id'};66786679# non-textual hash id's can be cached6680if($hash_base=~m/^[0-9a-fA-F]{40}$/&&6681$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {6682$expires='+1d';6683}66846685# open patch output6686open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6687'-p', ($formateq'html'?"--full-index": ()),6688$hash_parent_base,$hash_base,6689"--", (defined$file_parent?$file_parent: ()),$file_name6690or die_error(500,"Open git-diff-tree failed");6691}66926693# old/legacy style URI -- not generated anymore since 1.4.3.6694if(!%diffinfo) {6695 die_error('404 Not Found',"Missing one of the blob diff parameters")6696}66976698# header6699if($formateq'html') {6700my$formats_nav=6701$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},6702"raw");6703 git_header_html(undef,$expires);6704if(defined$hash_base&& (my%co= parse_commit($hash_base))) {6705 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);6706 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);6707}else{6708print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";6709print"<div class=\"title\">".esc_html("$hashvs$hash_parent")."</div>\n";6710}6711if(defined$file_name) {6712 git_print_page_path($file_name,"blob",$hash_base);6713}else{6714print"<div class=\"page_path\"></div>\n";6715}67166717}elsif($formateq'plain') {6718print$cgi->header(6719-type =>'text/plain',6720-charset =>'utf-8',6721-expires =>$expires,6722-content_disposition =>'inline; filename="'."$file_name".'.patch"');67236724print"X-Git-Url: ".$cgi->self_url() ."\n\n";67256726}else{6727 die_error(400,"Unknown blobdiff format");6728}67296730# patch6731if($formateq'html') {6732print"<div class=\"page_body\">\n";67336734 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);6735close$fd;67366737print"</div>\n";# class="page_body"6738 git_footer_html();67396740}else{6741while(my$line= <$fd>) {6742$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;6743$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;67446745print$line;67466747last if$line=~m!^\+\+\+!;6748}6749local$/=undef;6750print<$fd>;6751close$fd;6752}6753}67546755sub git_blobdiff_plain {6756 git_blobdiff('plain');6757}67586759sub git_commitdiff {6760my%params=@_;6761my$format=$params{-format} ||'html';67626763my($patch_max) = gitweb_get_feature('patches');6764if($formateq'patch') {6765 die_error(403,"Patch view not allowed")unless$patch_max;6766}67676768$hash||=$hash_base||"HEAD";6769my%co= parse_commit($hash)6770or die_error(404,"Unknown commit object");67716772# choose format for commitdiff for merge6773if(!defined$hash_parent&& @{$co{'parents'}} >1) {6774$hash_parent='--cc';6775}6776# we need to prepare $formats_nav before almost any parameter munging6777my$formats_nav;6778if($formateq'html') {6779$formats_nav=6780$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},6781"raw");6782if($patch_max&& @{$co{'parents'}} <=1) {6783$formats_nav.=" | ".6784$cgi->a({-href => href(action=>"patch", -replay=>1)},6785"patch");6786}67876788if(defined$hash_parent&&6789$hash_parentne'-c'&&$hash_parentne'--cc') {6790# commitdiff with two commits given6791my$hash_parent_short=$hash_parent;6792if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {6793$hash_parent_short=substr($hash_parent,0,7);6794}6795$formats_nav.=6796' (from';6797for(my$i=0;$i< @{$co{'parents'}};$i++) {6798if($co{'parents'}[$i]eq$hash_parent) {6799$formats_nav.=' parent '. ($i+1);6800last;6801}6802}6803$formats_nav.=': '.6804$cgi->a({-href => href(action=>"commitdiff",6805 hash=>$hash_parent)},6806 esc_html($hash_parent_short)) .6807')';6808}elsif(!$co{'parent'}) {6809# --root commitdiff6810$formats_nav.=' (initial)';6811}elsif(scalar@{$co{'parents'}} ==1) {6812# single parent commit6813$formats_nav.=6814' (parent: '.6815$cgi->a({-href => href(action=>"commitdiff",6816 hash=>$co{'parent'})},6817 esc_html(substr($co{'parent'},0,7))) .6818')';6819}else{6820# merge commit6821if($hash_parenteq'--cc') {6822$formats_nav.=' | '.6823$cgi->a({-href => href(action=>"commitdiff",6824 hash=>$hash, hash_parent=>'-c')},6825'combined');6826}else{# $hash_parent eq '-c'6827$formats_nav.=' | '.6828$cgi->a({-href => href(action=>"commitdiff",6829 hash=>$hash, hash_parent=>'--cc')},6830'compact');6831}6832$formats_nav.=6833' (merge: '.6834join(' ',map{6835$cgi->a({-href => href(action=>"commitdiff",6836 hash=>$_)},6837 esc_html(substr($_,0,7)));6838} @{$co{'parents'}} ) .6839')';6840}6841}68426843my$hash_parent_param=$hash_parent;6844if(!defined$hash_parent_param) {6845# --cc for multiple parents, --root for parentless6846$hash_parent_param=6847@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';6848}68496850# read commitdiff6851my$fd;6852my@difftree;6853if($formateq'html') {6854open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6855"--no-commit-id","--patch-with-raw","--full-index",6856$hash_parent_param,$hash,"--"6857or die_error(500,"Open git-diff-tree failed");68586859while(my$line= <$fd>) {6860chomp$line;6861# empty line ends raw part of diff-tree output6862last unless$line;6863push@difftree,scalar parse_difftree_raw_line($line);6864}68656866}elsif($formateq'plain') {6867open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,6868'-p',$hash_parent_param,$hash,"--"6869or die_error(500,"Open git-diff-tree failed");6870}elsif($formateq'patch') {6871# For commit ranges, we limit the output to the number of6872# patches specified in the 'patches' feature.6873# For single commits, we limit the output to a single patch,6874# diverging from the git-format-patch default.6875my@commit_spec= ();6876if($hash_parent) {6877if($patch_max>0) {6878push@commit_spec,"-$patch_max";6879}6880push@commit_spec,'-n',"$hash_parent..$hash";6881}else{6882if($params{-single}) {6883push@commit_spec,'-1';6884}else{6885if($patch_max>0) {6886push@commit_spec,"-$patch_max";6887}6888push@commit_spec,"-n";6889}6890push@commit_spec,'--root',$hash;6891}6892open$fd,"-|", git_cmd(),"format-patch",@diff_opts,6893'--encoding=utf8','--stdout',@commit_spec6894or die_error(500,"Open git-format-patch failed");6895}else{6896 die_error(400,"Unknown commitdiff format");6897}68986899# non-textual hash id's can be cached6900my$expires;6901if($hash=~m/^[0-9a-fA-F]{40}$/) {6902$expires="+1d";6903}69046905# write commit message6906if($formateq'html') {6907my$refs= git_get_references();6908my$ref= format_ref_marker($refs,$co{'id'});69096910 git_header_html(undef,$expires);6911 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);6912 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);6913print"<div class=\"title_text\">\n".6914"<table class=\"object_header\">\n";6915 git_print_authorship_rows(\%co);6916print"</table>".6917"</div>\n";6918print"<div class=\"page_body\">\n";6919if(@{$co{'comment'}} >1) {6920print"<div class=\"log\">\n";6921 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);6922print"</div>\n";# class="log"6923}69246925}elsif($formateq'plain') {6926my$refs= git_get_references("tags");6927my$tagname= git_get_rev_name_tags($hash);6928my$filename= basename($project) ."-$hash.patch";69296930print$cgi->header(6931-type =>'text/plain',6932-charset =>'utf-8',6933-expires =>$expires,6934-content_disposition =>'inline; filename="'."$filename".'"');6935my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});6936print"From: ". to_utf8($co{'author'}) ."\n";6937print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";6938print"Subject: ". to_utf8($co{'title'}) ."\n";69396940print"X-Git-Tag:$tagname\n"if$tagname;6941print"X-Git-Url: ".$cgi->self_url() ."\n\n";69426943foreachmy$line(@{$co{'comment'}}) {6944print to_utf8($line) ."\n";6945}6946print"---\n\n";6947}elsif($formateq'patch') {6948my$filename= basename($project) ."-$hash.patch";69496950print$cgi->header(6951-type =>'text/plain',6952-charset =>'utf-8',6953-expires =>$expires,6954-content_disposition =>'inline; filename="'."$filename".'"');6955}69566957# write patch6958if($formateq'html') {6959my$use_parents= !defined$hash_parent||6960$hash_parenteq'-c'||$hash_parenteq'--cc';6961 git_difftree_body(\@difftree,$hash,6962$use_parents? @{$co{'parents'}} :$hash_parent);6963print"<br/>\n";69646965 git_patchset_body($fd, \@difftree,$hash,6966$use_parents? @{$co{'parents'}} :$hash_parent);6967close$fd;6968print"</div>\n";# class="page_body"6969 git_footer_html();69706971}elsif($formateq'plain') {6972local$/=undef;6973print<$fd>;6974close$fd6975or print"Reading git-diff-tree failed\n";6976}elsif($formateq'patch') {6977local$/=undef;6978print<$fd>;6979close$fd6980or print"Reading git-format-patch failed\n";6981}6982}69836984sub git_commitdiff_plain {6985 git_commitdiff(-format =>'plain');6986}69876988# format-patch-style patches6989sub git_patch {6990 git_commitdiff(-format =>'patch', -single =>1);6991}69926993sub git_patches {6994 git_commitdiff(-format =>'patch');6995}69966997sub git_history {6998 git_log_generic('history', \&git_history_body,6999$hash_base,$hash_parent_base,7000$file_name,$hash);7001}70027003sub git_search {7004$searchtype||='commit';70057006# check if appropriate features are enabled7007 gitweb_check_feature('search')7008or die_error(403,"Search is disabled");7009if($searchtypeeq'pickaxe') {7010# pickaxe may take all resources of your box and run for several minutes7011# with every query - so decide by yourself how public you make this feature7012 gitweb_check_feature('pickaxe')7013or die_error(403,"Pickaxe search is disabled");7014}7015if($searchtypeeq'grep') {7016# grep search might be potentially CPU-intensive, too7017 gitweb_check_feature('grep')7018or die_error(403,"Grep search is disabled");7019}70207021if(!defined$searchtext) {7022 die_error(400,"Text field is empty");7023}7024if(!defined$hash) {7025$hash= git_get_head_hash($project);7026}7027my%co= parse_commit($hash);7028if(!%co) {7029 die_error(404,"Unknown commit object");7030}7031if(!defined$page) {7032$page=0;7033}70347035if($searchtypeeq'commit'||7036$searchtypeeq'author'||7037$searchtypeeq'committer') {7038 git_search_message(%co);7039}elsif($searchtypeeq'pickaxe') {7040 git_search_changes(%co);7041}elsif($searchtypeeq'grep') {7042 git_search_files(%co);7043}else{7044 die_error(400,"Unknown search type");7045}7046}70477048sub git_search_help {7049 git_header_html();7050 git_print_page_nav('','',$hash,$hash,$hash);7051print<<EOT;7052<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without7053regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,7054the pattern entered is recognized as the POSIX extended7055<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case7056insensitive).</p>7057<dl>7058<dt><b>commit</b></dt>7059<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>7060EOT7061my$have_grep= gitweb_check_feature('grep');7062if($have_grep) {7063print<<EOT;7064<dt><b>grep</b></dt>7065<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing7066 a different one) are searched for the given pattern. On large trees, this search can take7067a while and put some strain on the server, so please use it with some consideration. Note that7068due to git-grep peculiarity, currently if regexp mode is turned off, the matches are7069case-sensitive.</dd>7070EOT7071}7072print<<EOT;7073<dt><b>author</b></dt>7074<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>7075<dt><b>committer</b></dt>7076<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>7077EOT7078my$have_pickaxe= gitweb_check_feature('pickaxe');7079if($have_pickaxe) {7080print<<EOT;7081<dt><b>pickaxe</b></dt>7082<dd>All commits that caused the string to appear or disappear from any file (changes that7083added, removed or "modified" the string) will be listed. This search can take a while and7084takes a lot of strain on the server, so please use it wisely. Note that since you may be7085interested even in changes just changing the case as well, this search is case sensitive.</dd>7086EOT7087}7088print"</dl>\n";7089 git_footer_html();7090}70917092sub git_shortlog {7093 git_log_generic('shortlog', \&git_shortlog_body,7094$hash,$hash_parent);7095}70967097## ......................................................................7098## feeds (RSS, Atom; OPML)70997100sub git_feed {7101my$format=shift||'atom';7102my$have_blame= gitweb_check_feature('blame');71037104# Atom: http://www.atomenabled.org/developers/syndication/7105# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ7106if($formatne'rss'&&$formatne'atom') {7107 die_error(400,"Unknown web feed format");7108}71097110# log/feed of current (HEAD) branch, log of given branch, history of file/directory7111my$head=$hash||'HEAD';7112my@commitlist= parse_commits($head,150,0,$file_name);71137114my%latest_commit;7115my%latest_date;7116my$content_type="application/$format+xml";7117if(defined$cgi->http('HTTP_ACCEPT') &&7118$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {7119# browser (feed reader) prefers text/xml7120$content_type='text/xml';7121}7122if(defined($commitlist[0])) {7123%latest_commit= %{$commitlist[0]};7124my$latest_epoch=$latest_commit{'committer_epoch'};7125%latest_date= parse_date($latest_epoch,$latest_commit{'comitter_tz'});7126my$if_modified=$cgi->http('IF_MODIFIED_SINCE');7127if(defined$if_modified) {7128my$since;7129if(eval{require HTTP::Date;1; }) {7130$since= HTTP::Date::str2time($if_modified);7131}elsif(eval{require Time::ParseDate;1; }) {7132$since= Time::ParseDate::parsedate($if_modified, GMT =>1);7133}7134if(defined$since&&$latest_epoch<=$since) {7135print$cgi->header(7136-type =>$content_type,7137-charset =>'utf-8',7138-last_modified =>$latest_date{'rfc2822'},7139-status =>'304 Not Modified');7140return;7141}7142}7143print$cgi->header(7144-type =>$content_type,7145-charset =>'utf-8',7146-last_modified =>$latest_date{'rfc2822'});7147}else{7148print$cgi->header(7149-type =>$content_type,7150-charset =>'utf-8');7151}71527153# Optimization: skip generating the body if client asks only7154# for Last-Modified date.7155return if($cgi->request_method()eq'HEAD');71567157# header variables7158my$title="$site_name-$project/$action";7159my$feed_type='log';7160if(defined$hash) {7161$title.=" - '$hash'";7162$feed_type='branch log';7163if(defined$file_name) {7164$title.=" ::$file_name";7165$feed_type='history';7166}7167}elsif(defined$file_name) {7168$title.=" -$file_name";7169$feed_type='history';7170}7171$title.="$feed_type";7172my$descr= git_get_project_description($project);7173if(defined$descr) {7174$descr= esc_html($descr);7175}else{7176$descr="$project".7177($formateq'rss'?'RSS':'Atom') .7178" feed";7179}7180my$owner= git_get_project_owner($project);7181$owner= esc_html($owner);71827183#header7184my$alt_url;7185if(defined$file_name) {7186$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);7187}elsif(defined$hash) {7188$alt_url= href(-full=>1, action=>"log", hash=>$hash);7189}else{7190$alt_url= href(-full=>1, action=>"summary");7191}7192print qq!<?xml version="1.0" encoding="utf-8"?>\n!;7193if($formateq'rss') {7194print<<XML;7195<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">7196<channel>7197XML7198print"<title>$title</title>\n".7199"<link>$alt_url</link>\n".7200"<description>$descr</description>\n".7201"<language>en</language>\n".7202# project owner is responsible for 'editorial' content7203"<managingEditor>$owner</managingEditor>\n";7204if(defined$logo||defined$favicon) {7205# prefer the logo to the favicon, since RSS7206# doesn't allow both7207my$img= esc_url($logo||$favicon);7208print"<image>\n".7209"<url>$img</url>\n".7210"<title>$title</title>\n".7211"<link>$alt_url</link>\n".7212"</image>\n";7213}7214if(%latest_date) {7215print"<pubDate>$latest_date{'rfc2822'}</pubDate>\n";7216print"<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";7217}7218print"<generator>gitweb v.$version/$git_version</generator>\n";7219}elsif($formateq'atom') {7220print<<XML;7221<feed xmlns="http://www.w3.org/2005/Atom">7222XML7223print"<title>$title</title>\n".7224"<subtitle>$descr</subtitle>\n".7225'<link rel="alternate" type="text/html" href="'.7226$alt_url.'" />'."\n".7227'<link rel="self" type="'.$content_type.'" href="'.7228$cgi->self_url() .'" />'."\n".7229"<id>". href(-full=>1) ."</id>\n".7230# use project owner for feed author7231"<author><name>$owner</name></author>\n";7232if(defined$favicon) {7233print"<icon>". esc_url($favicon) ."</icon>\n";7234}7235if(defined$logo) {7236# not twice as wide as tall: 72 x 27 pixels7237print"<logo>". esc_url($logo) ."</logo>\n";7238}7239if(!%latest_date) {7240# dummy date to keep the feed valid until commits trickle in:7241print"<updated>1970-01-01T00:00:00Z</updated>\n";7242}else{7243print"<updated>$latest_date{'iso-8601'}</updated>\n";7244}7245print"<generator version='$version/$git_version'>gitweb</generator>\n";7246}72477248# contents7249for(my$i=0;$i<=$#commitlist;$i++) {7250my%co= %{$commitlist[$i]};7251my$commit=$co{'id'};7252# we read 150, we always show 30 and the ones more recent than 48 hours7253if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {7254last;7255}7256my%cd= parse_date($co{'author_epoch'},$co{'author_tz'});72577258# get list of changed files7259open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,7260$co{'parent'} ||"--root",7261$co{'id'},"--", (defined$file_name?$file_name: ())7262ornext;7263my@difftree=map{chomp;$_} <$fd>;7264close$fd7265ornext;72667267# print element (entry, item)7268my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);7269if($formateq'rss') {7270print"<item>\n".7271"<title>". esc_html($co{'title'}) ."</title>\n".7272"<author>". esc_html($co{'author'}) ."</author>\n".7273"<pubDate>$cd{'rfc2822'}</pubDate>\n".7274"<guid isPermaLink=\"true\">$co_url</guid>\n".7275"<link>$co_url</link>\n".7276"<description>". esc_html($co{'title'}) ."</description>\n".7277"<content:encoded>".7278"<![CDATA[\n";7279}elsif($formateq'atom') {7280print"<entry>\n".7281"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".7282"<updated>$cd{'iso-8601'}</updated>\n".7283"<author>\n".7284" <name>". esc_html($co{'author_name'}) ."</name>\n";7285if($co{'author_email'}) {7286print" <email>". esc_html($co{'author_email'}) ."</email>\n";7287}7288print"</author>\n".7289# use committer for contributor7290"<contributor>\n".7291" <name>". esc_html($co{'committer_name'}) ."</name>\n";7292if($co{'committer_email'}) {7293print" <email>". esc_html($co{'committer_email'}) ."</email>\n";7294}7295print"</contributor>\n".7296"<published>$cd{'iso-8601'}</published>\n".7297"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".7298"<id>$co_url</id>\n".7299"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".7300"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";7301}7302my$comment=$co{'comment'};7303print"<pre>\n";7304foreachmy$line(@$comment) {7305$line= esc_html($line);7306print"$line\n";7307}7308print"</pre><ul>\n";7309foreachmy$difftree_line(@difftree) {7310my%difftree= parse_difftree_raw_line($difftree_line);7311next if!$difftree{'from_id'};73127313my$file=$difftree{'file'} ||$difftree{'to_file'};73147315print"<li>".7316"[".7317$cgi->a({-href => href(-full=>1, action=>"blobdiff",7318 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},7319 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},7320 file_name=>$file, file_parent=>$difftree{'from_file'}),7321-title =>"diff"},'D');7322if($have_blame) {7323print$cgi->a({-href => href(-full=>1, action=>"blame",7324 file_name=>$file, hash_base=>$commit),7325-title =>"blame"},'B');7326}7327# if this is not a feed of a file history7328if(!defined$file_name||$file_namene$file) {7329print$cgi->a({-href => href(-full=>1, action=>"history",7330 file_name=>$file, hash=>$commit),7331-title =>"history"},'H');7332}7333$file= esc_path($file);7334print"] ".7335"$file</li>\n";7336}7337if($formateq'rss') {7338print"</ul>]]>\n".7339"</content:encoded>\n".7340"</item>\n";7341}elsif($formateq'atom') {7342print"</ul>\n</div>\n".7343"</content>\n".7344"</entry>\n";7345}7346}73477348# end of feed7349if($formateq'rss') {7350print"</channel>\n</rss>\n";7351}elsif($formateq'atom') {7352print"</feed>\n";7353}7354}73557356sub git_rss {7357 git_feed('rss');7358}73597360sub git_atom {7361 git_feed('atom');7362}73637364sub git_opml {7365my@list= git_get_projects_list();73667367print$cgi->header(7368-type =>'text/xml',7369-charset =>'utf-8',7370-content_disposition =>'inline; filename="opml.xml"');73717372print<<XML;7373<?xml version="1.0" encoding="utf-8"?>7374<opml version="1.0">7375<head>7376 <title>$site_nameOPML Export</title>7377</head>7378<body>7379<outline text="git RSS feeds">7380XML73817382foreachmy$pr(@list) {7383my%proj=%$pr;7384my$head= git_get_head_hash($proj{'path'});7385if(!defined$head) {7386next;7387}7388$git_dir="$projectroot/$proj{'path'}";7389my%co= parse_commit($head);7390if(!%co) {7391next;7392}73937394my$path= esc_html(chop_str($proj{'path'},25,5));7395my$rss= href('project'=>$proj{'path'},'action'=>'rss', -full =>1);7396my$html= href('project'=>$proj{'path'},'action'=>'summary', -full =>1);7397print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";7398}7399print<<XML;7400</outline>7401</body>7402</opml>7403XML7404}