1#!/usr/bin/perl 2 3# gitweb - simple web interface to track changes in git repositories 4# 5# (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org> 6# (C) 2005, Christian Gierke 7# 8# This program is licensed under the GPLv2 9 10use strict; 11use warnings; 12use CGI qw(:standard :escapeHTML -nosticky); 13use CGI::Util qw(unescape); 14use CGI::Carp qw(fatalsToBrowser); 15use Encode; 16use Fcntl ':mode'; 17use File::Find qw(); 18use File::Basename qw(basename); 19binmode STDOUT,':utf8'; 20 21BEGIN{ 22 CGI->compile()if$ENV{'MOD_PERL'}; 23} 24 25our$cgi= new CGI; 26our$version="++GIT_VERSION++"; 27our$my_url=$cgi->url(); 28our$my_uri=$cgi->url(-absolute =>1); 29 30# if we're called with PATH_INFO, we have to strip that 31# from the URL to find our real URL 32if(my$path_info=$ENV{"PATH_INFO"}) { 33$my_url=~ s,\Q$path_info\E$,,; 34$my_uri=~ s,\Q$path_info\E$,,; 35} 36 37# core git executable to use 38# this can just be "git" if your webserver has a sensible PATH 39our$GIT="++GIT_BINDIR++/git"; 40 41# absolute fs-path which will be prepended to the project path 42#our $projectroot = "/pub/scm"; 43our$projectroot="++GITWEB_PROJECTROOT++"; 44 45# fs traversing limit for getting project list 46# the number is relative to the projectroot 47our$project_maxdepth="++GITWEB_PROJECT_MAXDEPTH++"; 48 49# target of the home link on top of all pages 50our$home_link=$my_uri||"/"; 51 52# string of the home link on top of all pages 53our$home_link_str="++GITWEB_HOME_LINK_STR++"; 54 55# name of your site or organization to appear in page titles 56# replace this with something more descriptive for clearer bookmarks 57our$site_name="++GITWEB_SITENAME++" 58|| ($ENV{'SERVER_NAME'} ||"Untitled") ." Git"; 59 60# filename of html text to include at top of each page 61our$site_header="++GITWEB_SITE_HEADER++"; 62# html text to include at home page 63our$home_text="++GITWEB_HOMETEXT++"; 64# filename of html text to include at bottom of each page 65our$site_footer="++GITWEB_SITE_FOOTER++"; 66 67# URI of stylesheets 68our@stylesheets= ("++GITWEB_CSS++"); 69# URI of a single stylesheet, which can be overridden in GITWEB_CONFIG. 70our$stylesheet=undef; 71# URI of GIT logo (72x27 size) 72our$logo="++GITWEB_LOGO++"; 73# URI of GIT favicon, assumed to be image/png type 74our$favicon="++GITWEB_FAVICON++"; 75 76# URI and label (title) of GIT logo link 77#our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; 78#our $logo_label = "git documentation"; 79our$logo_url="http://git.or.cz/"; 80our$logo_label="git homepage"; 81 82# source of projects list 83our$projects_list="++GITWEB_LIST++"; 84 85# the width (in characters) of the projects list "Description" column 86our$projects_list_description_width=25; 87 88# default order of projects list 89# valid values are none, project, descr, owner, and age 90our$default_projects_order="project"; 91 92# show repository only if this file exists 93# (only effective if this variable evaluates to true) 94our$export_ok="++GITWEB_EXPORT_OK++"; 95 96# only allow viewing of repositories also shown on the overview page 97our$strict_export="++GITWEB_STRICT_EXPORT++"; 98 99# list of git base URLs used for URL to where fetch project from, 100# i.e. full URL is "$git_base_url/$project" 101our@git_base_url_list=grep{$_ne''} ("++GITWEB_BASE_URL++"); 102 103# default blob_plain mimetype and default charset for text/plain blob 104our$default_blob_plain_mimetype='text/plain'; 105our$default_text_plain_charset=undef; 106 107# file to use for guessing MIME types before trying /etc/mime.types 108# (relative to the current git repository) 109our$mimetypes_file=undef; 110 111# assume this charset if line contains non-UTF-8 characters; 112# it should be valid encoding (see Encoding::Supported(3pm) for list), 113# for which encoding all byte sequences are valid, for example 114# 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it 115# could be even 'utf-8' for the old behavior) 116our$fallback_encoding='latin1'; 117 118# rename detection options for git-diff and git-diff-tree 119# - default is '-M', with the cost proportional to 120# (number of removed files) * (number of new files). 121# - more costly is '-C' (which implies '-M'), with the cost proportional to 122# (number of changed files + number of removed files) * (number of new files) 123# - even more costly is '-C', '--find-copies-harder' with cost 124# (number of files in the original tree) * (number of new files) 125# - one might want to include '-B' option, e.g. '-B', '-M' 126our@diff_opts= ('-M');# taken from git_commit 127 128# information about snapshot formats that gitweb is capable of serving 129our%known_snapshot_formats= ( 130# name => { 131# 'display' => display name, 132# 'type' => mime type, 133# 'suffix' => filename suffix, 134# 'format' => --format for git-archive, 135# 'compressor' => [compressor command and arguments] 136# (array reference, optional)} 137# 138'tgz'=> { 139'display'=>'tar.gz', 140'type'=>'application/x-gzip', 141'suffix'=>'.tar.gz', 142'format'=>'tar', 143'compressor'=> ['gzip']}, 144 145'tbz2'=> { 146'display'=>'tar.bz2', 147'type'=>'application/x-bzip2', 148'suffix'=>'.tar.bz2', 149'format'=>'tar', 150'compressor'=> ['bzip2']}, 151 152'zip'=> { 153'display'=>'zip', 154'type'=>'application/x-zip', 155'suffix'=>'.zip', 156'format'=>'zip'}, 157); 158 159# Aliases so we understand old gitweb.snapshot values in repository 160# configuration. 161our%known_snapshot_format_aliases= ( 162'gzip'=>'tgz', 163'bzip2'=>'tbz2', 164 165# backward compatibility: legacy gitweb config support 166'x-gzip'=>undef,'gz'=>undef, 167'x-bzip2'=>undef,'bz2'=>undef, 168'x-zip'=>undef,''=>undef, 169); 170 171# You define site-wide feature defaults here; override them with 172# $GITWEB_CONFIG as necessary. 173our%feature= ( 174# feature => { 175# 'sub' => feature-sub (subroutine), 176# 'override' => allow-override (boolean), 177# 'default' => [ default options...] (array reference)} 178# 179# if feature is overridable (it means that allow-override has true value), 180# then feature-sub will be called with default options as parameters; 181# return value of feature-sub indicates if to enable specified feature 182# 183# if there is no 'sub' key (no feature-sub), then feature cannot be 184# overriden 185# 186# use gitweb_check_feature(<feature>) to check if <feature> is enabled 187 188# Enable the 'blame' blob view, showing the last commit that modified 189# each line in the file. This can be very CPU-intensive. 190 191# To enable system wide have in $GITWEB_CONFIG 192# $feature{'blame'}{'default'} = [1]; 193# To have project specific config enable override in $GITWEB_CONFIG 194# $feature{'blame'}{'override'} = 1; 195# and in project config gitweb.blame = 0|1; 196'blame'=> { 197'sub'=> \&feature_blame, 198'override'=>0, 199'default'=> [0]}, 200 201# Enable the 'snapshot' link, providing a compressed archive of any 202# tree. This can potentially generate high traffic if you have large 203# project. 204 205# Value is a list of formats defined in %known_snapshot_formats that 206# you wish to offer. 207# To disable system wide have in $GITWEB_CONFIG 208# $feature{'snapshot'}{'default'} = []; 209# To have project specific config enable override in $GITWEB_CONFIG 210# $feature{'snapshot'}{'override'} = 1; 211# and in project config, a comma-separated list of formats or "none" 212# to disable. Example: gitweb.snapshot = tbz2,zip; 213'snapshot'=> { 214'sub'=> \&feature_snapshot, 215'override'=>0, 216'default'=> ['tgz']}, 217 218# Enable text search, which will list the commits which match author, 219# committer or commit text to a given string. Enabled by default. 220# Project specific override is not supported. 221'search'=> { 222'override'=>0, 223'default'=> [1]}, 224 225# Enable grep search, which will list the files in currently selected 226# tree containing the given string. Enabled by default. This can be 227# potentially CPU-intensive, of course. 228 229# To enable system wide have in $GITWEB_CONFIG 230# $feature{'grep'}{'default'} = [1]; 231# To have project specific config enable override in $GITWEB_CONFIG 232# $feature{'grep'}{'override'} = 1; 233# and in project config gitweb.grep = 0|1; 234'grep'=> { 235'override'=>0, 236'default'=> [1]}, 237 238# Enable the pickaxe search, which will list the commits that modified 239# a given string in a file. This can be practical and quite faster 240# alternative to 'blame', but still potentially CPU-intensive. 241 242# To enable system wide have in $GITWEB_CONFIG 243# $feature{'pickaxe'}{'default'} = [1]; 244# To have project specific config enable override in $GITWEB_CONFIG 245# $feature{'pickaxe'}{'override'} = 1; 246# and in project config gitweb.pickaxe = 0|1; 247'pickaxe'=> { 248'sub'=> \&feature_pickaxe, 249'override'=>0, 250'default'=> [1]}, 251 252# Make gitweb use an alternative format of the URLs which can be 253# more readable and natural-looking: project name is embedded 254# directly in the path and the query string contains other 255# auxiliary information. All gitweb installations recognize 256# URL in either format; this configures in which formats gitweb 257# generates links. 258 259# To enable system wide have in $GITWEB_CONFIG 260# $feature{'pathinfo'}{'default'} = [1]; 261# Project specific override is not supported. 262 263# Note that you will need to change the default location of CSS, 264# favicon, logo and possibly other files to an absolute URL. Also, 265# if gitweb.cgi serves as your indexfile, you will need to force 266# $my_uri to contain the script name in your $GITWEB_CONFIG. 267'pathinfo'=> { 268'override'=>0, 269'default'=> [0]}, 270 271# Make gitweb consider projects in project root subdirectories 272# to be forks of existing projects. Given project $projname.git, 273# projects matching $projname/*.git will not be shown in the main 274# projects list, instead a '+' mark will be added to $projname 275# there and a 'forks' view will be enabled for the project, listing 276# all the forks. If project list is taken from a file, forks have 277# to be listed after the main project. 278 279# To enable system wide have in $GITWEB_CONFIG 280# $feature{'forks'}{'default'} = [1]; 281# Project specific override is not supported. 282'forks'=> { 283'override'=>0, 284'default'=> [0]}, 285 286# Insert custom links to the action bar of all project pages. 287# This enables you mainly to link to third-party scripts integrating 288# into gitweb; e.g. git-browser for graphical history representation 289# or custom web-based repository administration interface. 290 291# The 'default' value consists of a list of triplets in the form 292# (label, link, position) where position is the label after which 293# to inster the link and link is a format string where %n expands 294# to the project name, %f to the project path within the filesystem, 295# %h to the current hash (h gitweb parameter) and %b to the current 296# hash base (hb gitweb parameter). 297 298# To enable system wide have in $GITWEB_CONFIG e.g. 299# $feature{'actions'}{'default'} = [('graphiclog', 300# '/git-browser/by-commit.html?r=%n', 'summary')]; 301# Project specific override is not supported. 302'actions'=> { 303'override'=>0, 304'default'=> []}, 305 306# Allow gitweb scan project content tags described in ctags/ 307# of project repository, and display the popular Web 2.0-ish 308# "tag cloud" near the project list. Note that this is something 309# COMPLETELY different from the normal Git tags. 310 311# gitweb by itself can show existing tags, but it does not handle 312# tagging itself; you need an external application for that. 313# For an example script, check Girocco's cgi/tagproj.cgi. 314# You may want to install the HTML::TagCloud Perl module to get 315# a pretty tag cloud instead of just a list of tags. 316 317# To enable system wide have in $GITWEB_CONFIG 318# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 319# Project specific override is not supported. 320'ctags'=> { 321'override'=>0, 322'default'=> [0]}, 323); 324 325sub gitweb_check_feature { 326my($name) =@_; 327return unlessexists$feature{$name}; 328my($sub,$override,@defaults) = ( 329$feature{$name}{'sub'}, 330$feature{$name}{'override'}, 331@{$feature{$name}{'default'}}); 332if(!$override) {return@defaults; } 333if(!defined$sub) { 334warn"feature$nameis not overrideable"; 335return@defaults; 336} 337return$sub->(@defaults); 338} 339 340sub feature_blame { 341my($val) = git_get_project_config('blame','--bool'); 342 343if($valeq'true') { 344return1; 345}elsif($valeq'false') { 346return0; 347} 348 349return$_[0]; 350} 351 352sub feature_snapshot { 353my(@fmts) =@_; 354 355my($val) = git_get_project_config('snapshot'); 356 357if($val) { 358@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 359} 360 361return@fmts; 362} 363 364sub feature_grep { 365my($val) = git_get_project_config('grep','--bool'); 366 367if($valeq'true') { 368return(1); 369}elsif($valeq'false') { 370return(0); 371} 372 373return($_[0]); 374} 375 376sub feature_pickaxe { 377my($val) = git_get_project_config('pickaxe','--bool'); 378 379if($valeq'true') { 380return(1); 381}elsif($valeq'false') { 382return(0); 383} 384 385return($_[0]); 386} 387 388# checking HEAD file with -e is fragile if the repository was 389# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 390# and then pruned. 391sub check_head_link { 392my($dir) =@_; 393my$headfile="$dir/HEAD"; 394return((-e $headfile) || 395(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 396} 397 398sub check_export_ok { 399my($dir) =@_; 400return(check_head_link($dir) && 401(!$export_ok|| -e "$dir/$export_ok")); 402} 403 404# process alternate names for backward compatibility 405# filter out unsupported (unknown) snapshot formats 406sub filter_snapshot_fmts { 407my@fmts=@_; 408 409@fmts=map{ 410exists$known_snapshot_format_aliases{$_} ? 411$known_snapshot_format_aliases{$_} :$_}@fmts; 412@fmts=grep(exists$known_snapshot_formats{$_},@fmts); 413 414} 415 416our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 417if(-e $GITWEB_CONFIG) { 418do$GITWEB_CONFIG; 419}else{ 420our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 421do$GITWEB_CONFIG_SYSTEMif-e $GITWEB_CONFIG_SYSTEM; 422} 423 424# version of the core git binary 425our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 426 427$projects_list||=$projectroot; 428 429# ====================================================================== 430# input validation and dispatch 431our$action=$cgi->param('a'); 432if(defined$action) { 433if($action=~m/[^0-9a-zA-Z\.\-_]/) { 434 die_error(400,"Invalid action parameter"); 435} 436} 437 438# parameters which are pathnames 439our$project=$cgi->param('p'); 440if(defined$project) { 441if(!validate_pathname($project) || 442!(-d "$projectroot/$project") || 443!check_head_link("$projectroot/$project") || 444($export_ok&& !(-e "$projectroot/$project/$export_ok")) || 445($strict_export&& !project_in_list($project))) { 446undef$project; 447 die_error(404,"No such project"); 448} 449} 450 451our$file_name=$cgi->param('f'); 452if(defined$file_name) { 453if(!validate_pathname($file_name)) { 454 die_error(400,"Invalid file parameter"); 455} 456} 457 458our$file_parent=$cgi->param('fp'); 459if(defined$file_parent) { 460if(!validate_pathname($file_parent)) { 461 die_error(400,"Invalid file parent parameter"); 462} 463} 464 465# parameters which are refnames 466our$hash=$cgi->param('h'); 467if(defined$hash) { 468if(!validate_refname($hash)) { 469 die_error(400,"Invalid hash parameter"); 470} 471} 472 473our$hash_parent=$cgi->param('hp'); 474if(defined$hash_parent) { 475if(!validate_refname($hash_parent)) { 476 die_error(400,"Invalid hash parent parameter"); 477} 478} 479 480our$hash_base=$cgi->param('hb'); 481if(defined$hash_base) { 482if(!validate_refname($hash_base)) { 483 die_error(400,"Invalid hash base parameter"); 484} 485} 486 487my%allowed_options= ( 488"--no-merges"=> [qw(rss atom log shortlog history)], 489); 490 491our@extra_options=$cgi->param('opt'); 492if(defined@extra_options) { 493foreachmy$opt(@extra_options) { 494if(not exists$allowed_options{$opt}) { 495 die_error(400,"Invalid option parameter"); 496} 497if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 498 die_error(400,"Invalid option parameter for this action"); 499} 500} 501} 502 503our$hash_parent_base=$cgi->param('hpb'); 504if(defined$hash_parent_base) { 505if(!validate_refname($hash_parent_base)) { 506 die_error(400,"Invalid hash parent base parameter"); 507} 508} 509 510# other parameters 511our$page=$cgi->param('pg'); 512if(defined$page) { 513if($page=~m/[^0-9]/) { 514 die_error(400,"Invalid page parameter"); 515} 516} 517 518our$searchtype=$cgi->param('st'); 519if(defined$searchtype) { 520if($searchtype=~m/[^a-z]/) { 521 die_error(400,"Invalid searchtype parameter"); 522} 523} 524 525our$search_use_regexp=$cgi->param('sr'); 526 527our$searchtext=$cgi->param('s'); 528our$search_regexp; 529if(defined$searchtext) { 530if(length($searchtext) <2) { 531 die_error(403,"At least two characters are required for search parameter"); 532} 533$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 534} 535 536# now read PATH_INFO and use it as alternative to parameters 537sub evaluate_path_info { 538return ifdefined$project; 539my$path_info=$ENV{"PATH_INFO"}; 540return if!$path_info; 541$path_info=~ s,^/+,,; 542return if!$path_info; 543# find which part of PATH_INFO is project 544$project=$path_info; 545$project=~ s,/+$,,; 546while($project&& !check_head_link("$projectroot/$project")) { 547$project=~ s,/*[^/]*$,,; 548} 549# validate project 550$project= validate_pathname($project); 551if(!$project|| 552($export_ok&& !-e "$projectroot/$project/$export_ok") || 553($strict_export&& !project_in_list($project))) { 554undef$project; 555return; 556} 557# do not change any parameters if an action is given using the query string 558return if$action; 559$path_info=~ s,^\Q$project\E/*,,; 560my($refname,$pathname) =split(/:/,$path_info,2); 561if(defined$pathname) { 562# we got "project.git/branch:filename" or "project.git/branch:dir/" 563# we could use git_get_type(branch:pathname), but it needs $git_dir 564$pathname=~ s,^/+,,; 565if(!$pathname||substr($pathname, -1)eq"/") { 566$action||="tree"; 567$pathname=~ s,/$,,; 568}else{ 569$action||="blob_plain"; 570} 571$hash_base||= validate_refname($refname); 572$file_name||= validate_pathname($pathname); 573}elsif(defined$refname) { 574# we got "project.git/branch" 575$action||="shortlog"; 576$hash||= validate_refname($refname); 577} 578} 579evaluate_path_info(); 580 581# path to the current git repository 582our$git_dir; 583$git_dir="$projectroot/$project"if$project; 584 585# dispatch 586my%actions= ( 587"blame"=> \&git_blame, 588"blobdiff"=> \&git_blobdiff, 589"blobdiff_plain"=> \&git_blobdiff_plain, 590"blob"=> \&git_blob, 591"blob_plain"=> \&git_blob_plain, 592"commitdiff"=> \&git_commitdiff, 593"commitdiff_plain"=> \&git_commitdiff_plain, 594"commit"=> \&git_commit, 595"forks"=> \&git_forks, 596"heads"=> \&git_heads, 597"history"=> \&git_history, 598"log"=> \&git_log, 599"rss"=> \&git_rss, 600"atom"=> \&git_atom, 601"search"=> \&git_search, 602"search_help"=> \&git_search_help, 603"shortlog"=> \&git_shortlog, 604"summary"=> \&git_summary, 605"tag"=> \&git_tag, 606"tags"=> \&git_tags, 607"tree"=> \&git_tree, 608"snapshot"=> \&git_snapshot, 609"object"=> \&git_object, 610# those below don't need $project 611"opml"=> \&git_opml, 612"project_list"=> \&git_project_list, 613"project_index"=> \&git_project_index, 614); 615 616if(!defined$action) { 617if(defined$hash) { 618$action= git_get_type($hash); 619}elsif(defined$hash_base&&defined$file_name) { 620$action= git_get_type("$hash_base:$file_name"); 621}elsif(defined$project) { 622$action='summary'; 623}else{ 624$action='project_list'; 625} 626} 627if(!defined($actions{$action})) { 628 die_error(400,"Unknown action"); 629} 630if($action!~m/^(opml|project_list|project_index)$/&& 631!$project) { 632 die_error(400,"Project needed"); 633} 634$actions{$action}->(); 635exit; 636 637## ====================================================================== 638## action links 639 640sub href (%) { 641my%params=@_; 642# default is to use -absolute url() i.e. $my_uri 643my$href=$params{-full} ?$my_url:$my_uri; 644 645# XXX: Warning: If you touch this, check the search form for updating, 646# too. 647 648my@mapping= ( 649 project =>"p", 650 action =>"a", 651 file_name =>"f", 652 file_parent =>"fp", 653 hash =>"h", 654 hash_parent =>"hp", 655 hash_base =>"hb", 656 hash_parent_base =>"hpb", 657 page =>"pg", 658 order =>"o", 659 searchtext =>"s", 660 searchtype =>"st", 661 snapshot_format =>"sf", 662 extra_options =>"opt", 663 search_use_regexp =>"sr", 664); 665my%mapping=@mapping; 666 667$params{'project'} =$projectunlessexists$params{'project'}; 668 669if($params{-replay}) { 670while(my($name,$symbol) =each%mapping) { 671if(!exists$params{$name}) { 672# to allow for multivalued params we use arrayref form 673$params{$name} = [$cgi->param($symbol) ]; 674} 675} 676} 677 678my($use_pathinfo) = gitweb_check_feature('pathinfo'); 679if($use_pathinfo) { 680# use PATH_INFO for project name 681$href.="/".esc_url($params{'project'})ifdefined$params{'project'}; 682delete$params{'project'}; 683 684# Summary just uses the project path URL 685if(defined$params{'action'} &&$params{'action'}eq'summary') { 686delete$params{'action'}; 687} 688} 689 690# now encode the parameters explicitly 691my@result= (); 692for(my$i=0;$i<@mapping;$i+=2) { 693my($name,$symbol) = ($mapping[$i],$mapping[$i+1]); 694if(defined$params{$name}) { 695if(ref($params{$name})eq"ARRAY") { 696foreachmy$par(@{$params{$name}}) { 697push@result,$symbol."=". esc_param($par); 698} 699}else{ 700push@result,$symbol."=". esc_param($params{$name}); 701} 702} 703} 704$href.="?".join(';',@result)ifscalar@result; 705 706return$href; 707} 708 709 710## ====================================================================== 711## validation, quoting/unquoting and escaping 712 713sub validate_pathname { 714my$input=shift||returnundef; 715 716# no '.' or '..' as elements of path, i.e. no '.' nor '..' 717# at the beginning, at the end, and between slashes. 718# also this catches doubled slashes 719if($input=~m!(^|/)(|\.|\.\.)(/|$)!) { 720returnundef; 721} 722# no null characters 723if($input=~m!\0!) { 724returnundef; 725} 726return$input; 727} 728 729sub validate_refname { 730my$input=shift||returnundef; 731 732# textual hashes are O.K. 733if($input=~m/^[0-9a-fA-F]{40}$/) { 734return$input; 735} 736# it must be correct pathname 737$input= validate_pathname($input) 738orreturnundef; 739# restrictions on ref name according to git-check-ref-format 740if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) { 741returnundef; 742} 743return$input; 744} 745 746# decode sequences of octets in utf8 into Perl's internal form, 747# which is utf-8 with utf8 flag set if needed. gitweb writes out 748# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning 749sub to_utf8 { 750my$str=shift; 751if(utf8::valid($str)) { 752 utf8::decode($str); 753return$str; 754}else{ 755return decode($fallback_encoding,$str, Encode::FB_DEFAULT); 756} 757} 758 759# quote unsafe chars, but keep the slash, even when it's not 760# correct, but quoted slashes look too horrible in bookmarks 761sub esc_param { 762my$str=shift; 763$str=~s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X",ord($1))/eg; 764$str=~s/\+/%2B/g; 765$str=~s/ /\+/g; 766return$str; 767} 768 769# quote unsafe chars in whole URL, so some charactrs cannot be quoted 770sub esc_url { 771my$str=shift; 772$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X",ord($1))/eg; 773$str=~s/\+/%2B/g; 774$str=~s/ /\+/g; 775return$str; 776} 777 778# replace invalid utf8 character with SUBSTITUTION sequence 779sub esc_html ($;%) { 780my$str=shift; 781my%opts=@_; 782 783$str= to_utf8($str); 784$str=$cgi->escapeHTML($str); 785if($opts{'-nbsp'}) { 786$str=~s/ / /g; 787} 788$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg; 789return$str; 790} 791 792# quote control characters and escape filename to HTML 793sub esc_path { 794my$str=shift; 795my%opts=@_; 796 797$str= to_utf8($str); 798$str=$cgi->escapeHTML($str); 799if($opts{'-nbsp'}) { 800$str=~s/ / /g; 801} 802$str=~ s|([[:cntrl:]])|quot_cec($1)|eg; 803return$str; 804} 805 806# Make control characters "printable", using character escape codes (CEC) 807sub quot_cec { 808my$cntrl=shift; 809my%opts=@_; 810my%es= (# character escape codes, aka escape sequences 811"\t"=>'\t',# tab (HT) 812"\n"=>'\n',# line feed (LF) 813"\r"=>'\r',# carrige return (CR) 814"\f"=>'\f',# form feed (FF) 815"\b"=>'\b',# backspace (BS) 816"\a"=>'\a',# alarm (bell) (BEL) 817"\e"=>'\e',# escape (ESC) 818"\013"=>'\v',# vertical tab (VT) 819"\000"=>'\0',# nul character (NUL) 820); 821my$chr= ( (exists$es{$cntrl}) 822?$es{$cntrl} 823:sprintf('\%2x',ord($cntrl)) ); 824if($opts{-nohtml}) { 825return$chr; 826}else{ 827return"<span class=\"cntrl\">$chr</span>"; 828} 829} 830 831# Alternatively use unicode control pictures codepoints, 832# Unicode "printable representation" (PR) 833sub quot_upr { 834my$cntrl=shift; 835my%opts=@_; 836 837my$chr=sprintf('&#%04d;',0x2400+ord($cntrl)); 838if($opts{-nohtml}) { 839return$chr; 840}else{ 841return"<span class=\"cntrl\">$chr</span>"; 842} 843} 844 845# git may return quoted and escaped filenames 846sub unquote { 847my$str=shift; 848 849sub unq { 850my$seq=shift; 851my%es= (# character escape codes, aka escape sequences 852't'=>"\t",# tab (HT, TAB) 853'n'=>"\n",# newline (NL) 854'r'=>"\r",# return (CR) 855'f'=>"\f",# form feed (FF) 856'b'=>"\b",# backspace (BS) 857'a'=>"\a",# alarm (bell) (BEL) 858'e'=>"\e",# escape (ESC) 859'v'=>"\013",# vertical tab (VT) 860); 861 862if($seq=~m/^[0-7]{1,3}$/) { 863# octal char sequence 864returnchr(oct($seq)); 865}elsif(exists$es{$seq}) { 866# C escape sequence, aka character escape code 867return$es{$seq}; 868} 869# quoted ordinary character 870return$seq; 871} 872 873if($str=~m/^"(.*)"$/) { 874# needs unquoting 875$str=$1; 876$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg; 877} 878return$str; 879} 880 881# escape tabs (convert tabs to spaces) 882sub untabify { 883my$line=shift; 884 885while((my$pos=index($line,"\t")) != -1) { 886if(my$count= (8- ($pos%8))) { 887my$spaces=' ' x $count; 888$line=~s/\t/$spaces/; 889} 890} 891 892return$line; 893} 894 895sub project_in_list { 896my$project=shift; 897my@list= git_get_projects_list(); 898return@list&&scalar(grep{$_->{'path'}eq$project}@list); 899} 900 901## ---------------------------------------------------------------------- 902## HTML aware string manipulation 903 904# Try to chop given string on a word boundary between position 905# $len and $len+$add_len. If there is no word boundary there, 906# chop at $len+$add_len. Do not chop if chopped part plus ellipsis 907# (marking chopped part) would be longer than given string. 908sub chop_str { 909my$str=shift; 910my$len=shift; 911my$add_len=shift||10; 912my$where=shift||'right';# 'left' | 'center' | 'right' 913 914# Make sure perl knows it is utf8 encoded so we don't 915# cut in the middle of a utf8 multibyte char. 916$str= to_utf8($str); 917 918# allow only $len chars, but don't cut a word if it would fit in $add_len 919# if it doesn't fit, cut it if it's still longer than the dots we would add 920# remove chopped character entities entirely 921 922# when chopping in the middle, distribute $len into left and right part 923# return early if chopping wouldn't make string shorter 924if($whereeq'center') { 925return$strif($len+5>=length($str));# filler is length 5 926$len=int($len/2); 927}else{ 928return$strif($len+4>=length($str));# filler is length 4 929} 930 931# regexps: ending and beginning with word part up to $add_len 932my$endre=qr/.{$len}\w{0,$add_len}/; 933my$begre=qr/\w{0,$add_len}.{$len}/; 934 935if($whereeq'left') { 936$str=~m/^(.*?)($begre)$/; 937my($lead,$body) = ($1,$2); 938if(length($lead) >4) { 939$body=~s/^[^;]*;//if($lead=~m/&[^;]*$/); 940$lead=" ..."; 941} 942return"$lead$body"; 943 944}elsif($whereeq'center') { 945$str=~m/^($endre)(.*)$/; 946my($left,$str) = ($1,$2); 947$str=~m/^(.*?)($begre)$/; 948my($mid,$right) = ($1,$2); 949if(length($mid) >5) { 950$left=~s/&[^;]*$//; 951$right=~s/^[^;]*;//if($mid=~m/&[^;]*$/); 952$mid=" ... "; 953} 954return"$left$mid$right"; 955 956}else{ 957$str=~m/^($endre)(.*)$/; 958my$body=$1; 959my$tail=$2; 960if(length($tail) >4) { 961$body=~s/&[^;]*$//; 962$tail="... "; 963} 964return"$body$tail"; 965} 966} 967 968# takes the same arguments as chop_str, but also wraps a <span> around the 969# result with a title attribute if it does get chopped. Additionally, the 970# string is HTML-escaped. 971sub chop_and_escape_str { 972my($str) =@_; 973 974my$chopped= chop_str(@_); 975if($choppedeq$str) { 976return esc_html($chopped); 977}else{ 978$str=~s/([[:cntrl:]])/?/g; 979return$cgi->span({-title=>$str}, esc_html($chopped)); 980} 981} 982 983## ---------------------------------------------------------------------- 984## functions returning short strings 985 986# CSS class for given age value (in seconds) 987sub age_class { 988my$age=shift; 989 990if(!defined$age) { 991return"noage"; 992}elsif($age<60*60*2) { 993return"age0"; 994}elsif($age<60*60*24*2) { 995return"age1"; 996}else{ 997return"age2"; 998} 999}10001001# convert age in seconds to "nn units ago" string1002sub age_string {1003my$age=shift;1004my$age_str;10051006if($age>60*60*24*365*2) {1007$age_str= (int$age/60/60/24/365);1008$age_str.=" years ago";1009}elsif($age>60*60*24*(365/12)*2) {1010$age_str=int$age/60/60/24/(365/12);1011$age_str.=" months ago";1012}elsif($age>60*60*24*7*2) {1013$age_str=int$age/60/60/24/7;1014$age_str.=" weeks ago";1015}elsif($age>60*60*24*2) {1016$age_str=int$age/60/60/24;1017$age_str.=" days ago";1018}elsif($age>60*60*2) {1019$age_str=int$age/60/60;1020$age_str.=" hours ago";1021}elsif($age>60*2) {1022$age_str=int$age/60;1023$age_str.=" min ago";1024}elsif($age>2) {1025$age_str=int$age;1026$age_str.=" sec ago";1027}else{1028$age_str.=" right now";1029}1030return$age_str;1031}10321033useconstant{1034 S_IFINVALID =>0030000,1035 S_IFGITLINK =>0160000,1036};10371038# submodule/subproject, a commit object reference1039sub S_ISGITLINK($) {1040my$mode=shift;10411042return(($mode& S_IFMT) == S_IFGITLINK)1043}10441045# convert file mode in octal to symbolic file mode string1046sub mode_str {1047my$mode=oct shift;10481049if(S_ISGITLINK($mode)) {1050return'm---------';1051}elsif(S_ISDIR($mode& S_IFMT)) {1052return'drwxr-xr-x';1053}elsif(S_ISLNK($mode)) {1054return'lrwxrwxrwx';1055}elsif(S_ISREG($mode)) {1056# git cares only about the executable bit1057if($mode& S_IXUSR) {1058return'-rwxr-xr-x';1059}else{1060return'-rw-r--r--';1061};1062}else{1063return'----------';1064}1065}10661067# convert file mode in octal to file type string1068sub file_type {1069my$mode=shift;10701071if($mode!~m/^[0-7]+$/) {1072return$mode;1073}else{1074$mode=oct$mode;1075}10761077if(S_ISGITLINK($mode)) {1078return"submodule";1079}elsif(S_ISDIR($mode& S_IFMT)) {1080return"directory";1081}elsif(S_ISLNK($mode)) {1082return"symlink";1083}elsif(S_ISREG($mode)) {1084return"file";1085}else{1086return"unknown";1087}1088}10891090# convert file mode in octal to file type description string1091sub file_type_long {1092my$mode=shift;10931094if($mode!~m/^[0-7]+$/) {1095return$mode;1096}else{1097$mode=oct$mode;1098}10991100if(S_ISGITLINK($mode)) {1101return"submodule";1102}elsif(S_ISDIR($mode& S_IFMT)) {1103return"directory";1104}elsif(S_ISLNK($mode)) {1105return"symlink";1106}elsif(S_ISREG($mode)) {1107if($mode& S_IXUSR) {1108return"executable";1109}else{1110return"file";1111};1112}else{1113return"unknown";1114}1115}111611171118## ----------------------------------------------------------------------1119## functions returning short HTML fragments, or transforming HTML fragments1120## which don't belong to other sections11211122# format line of commit message.1123sub format_log_line_html {1124my$line=shift;11251126$line= esc_html($line, -nbsp=>1);1127if($line=~m/([0-9a-fA-F]{8,40})/) {1128my$hash_text=$1;1129my$link=1130$cgi->a({-href => href(action=>"object", hash=>$hash_text),1131-class=>"text"},$hash_text);1132$line=~s/$hash_text/$link/;1133}1134return$line;1135}11361137# format marker of refs pointing to given object11381139# the destination action is chosen based on object type and current context:1140# - for annotated tags, we choose the tag view unless it's the current view1141# already, in which case we go to shortlog view1142# - for other refs, we keep the current view if we're in history, shortlog or1143# log view, and select shortlog otherwise1144sub format_ref_marker {1145my($refs,$id) =@_;1146my$markers='';11471148if(defined$refs->{$id}) {1149foreachmy$ref(@{$refs->{$id}}) {1150# this code exploits the fact that non-lightweight tags are the1151# only indirect objects, and that they are the only objects for which1152# we want to use tag instead of shortlog as action1153my($type,$name) =qw();1154my$indirect= ($ref=~s/\^\{\}$//);1155# e.g. tags/v2.6.11 or heads/next1156if($ref=~m!^(.*?)s?/(.*)$!) {1157$type=$1;1158$name=$2;1159}else{1160$type="ref";1161$name=$ref;1162}11631164my$class=$type;1165$class.=" indirect"if$indirect;11661167my$dest_action="shortlog";11681169if($indirect) {1170$dest_action="tag"unless$actioneq"tag";1171}elsif($action=~/^(history|(short)?log)$/) {1172$dest_action=$action;1173}11741175my$dest="";1176$dest.="refs/"unless$ref=~ m!^refs/!;1177$dest.=$ref;11781179my$link=$cgi->a({1180-href => href(1181 action=>$dest_action,1182 hash=>$dest1183)},$name);11841185$markers.=" <span class=\"$class\"title=\"$ref\">".1186$link."</span>";1187}1188}11891190if($markers) {1191return' <span class="refs">'.$markers.'</span>';1192}else{1193return"";1194}1195}11961197# format, perhaps shortened and with markers, title line1198sub format_subject_html {1199my($long,$short,$href,$extra) =@_;1200$extra=''unlessdefined($extra);12011202if(length($short) <length($long)) {1203return$cgi->a({-href =>$href, -class=>"list subject",1204-title => to_utf8($long)},1205 esc_html($short) .$extra);1206}else{1207return$cgi->a({-href =>$href, -class=>"list subject"},1208 esc_html($long) .$extra);1209}1210}12111212# format git diff header line, i.e. "diff --(git|combined|cc) ..."1213sub format_git_diff_header_line {1214my$line=shift;1215my$diffinfo=shift;1216my($from,$to) =@_;12171218if($diffinfo->{'nparents'}) {1219# combined diff1220$line=~s!^(diff (.*?) )"?.*$!$1!;1221if($to->{'href'}) {1222$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1223 esc_path($to->{'file'}));1224}else{# file was deleted (no href)1225$line.= esc_path($to->{'file'});1226}1227}else{1228# "ordinary" diff1229$line=~s!^(diff (.*?) )"?a/.*$!$1!;1230if($from->{'href'}) {1231$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1232'a/'. esc_path($from->{'file'}));1233}else{# file was added (no href)1234$line.='a/'. esc_path($from->{'file'});1235}1236$line.=' ';1237if($to->{'href'}) {1238$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1239'b/'. esc_path($to->{'file'}));1240}else{# file was deleted1241$line.='b/'. esc_path($to->{'file'});1242}1243}12441245return"<div class=\"diff header\">$line</div>\n";1246}12471248# format extended diff header line, before patch itself1249sub format_extended_diff_header_line {1250my$line=shift;1251my$diffinfo=shift;1252my($from,$to) =@_;12531254# match <path>1255if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1256$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1257 esc_path($from->{'file'}));1258}1259if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1260$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1261 esc_path($to->{'file'}));1262}1263# match single <mode>1264if($line=~m/\s(\d{6})$/) {1265$line.='<span class="info"> ('.1266 file_type_long($1) .1267')</span>';1268}1269# match <hash>1270if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1271# can match only for combined diff1272$line='index ';1273for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1274if($from->{'href'}[$i]) {1275$line.=$cgi->a({-href=>$from->{'href'}[$i],1276-class=>"hash"},1277substr($diffinfo->{'from_id'}[$i],0,7));1278}else{1279$line.='0' x 7;1280}1281# separator1282$line.=','if($i<$diffinfo->{'nparents'} -1);1283}1284$line.='..';1285if($to->{'href'}) {1286$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1287substr($diffinfo->{'to_id'},0,7));1288}else{1289$line.='0' x 7;1290}12911292}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1293# can match only for ordinary diff1294my($from_link,$to_link);1295if($from->{'href'}) {1296$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1297substr($diffinfo->{'from_id'},0,7));1298}else{1299$from_link='0' x 7;1300}1301if($to->{'href'}) {1302$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1303substr($diffinfo->{'to_id'},0,7));1304}else{1305$to_link='0' x 7;1306}1307my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1308$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1309}13101311return$line."<br/>\n";1312}13131314# format from-file/to-file diff header1315sub format_diff_from_to_header {1316my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1317my$line;1318my$result='';13191320$line=$from_line;1321#assert($line =~ m/^---/) if DEBUG;1322# no extra formatting for "^--- /dev/null"1323if(!$diffinfo->{'nparents'}) {1324# ordinary (single parent) diff1325if($line=~m!^--- "?a/!) {1326if($from->{'href'}) {1327$line='--- a/'.1328$cgi->a({-href=>$from->{'href'}, -class=>"path"},1329 esc_path($from->{'file'}));1330}else{1331$line='--- a/'.1332 esc_path($from->{'file'});1333}1334}1335$result.= qq!<div class="diff from_file">$line</div>\n!;13361337}else{1338# combined diff (merge commit)1339for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1340if($from->{'href'}[$i]) {1341$line='--- '.1342$cgi->a({-href=>href(action=>"blobdiff",1343 hash_parent=>$diffinfo->{'from_id'}[$i],1344 hash_parent_base=>$parents[$i],1345 file_parent=>$from->{'file'}[$i],1346 hash=>$diffinfo->{'to_id'},1347 hash_base=>$hash,1348 file_name=>$to->{'file'}),1349-class=>"path",1350-title=>"diff". ($i+1)},1351$i+1) .1352'/'.1353$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1354 esc_path($from->{'file'}[$i]));1355}else{1356$line='--- /dev/null';1357}1358$result.= qq!<div class="diff from_file">$line</div>\n!;1359}1360}13611362$line=$to_line;1363#assert($line =~ m/^\+\+\+/) if DEBUG;1364# no extra formatting for "^+++ /dev/null"1365if($line=~m!^\+\+\+ "?b/!) {1366if($to->{'href'}) {1367$line='+++ b/'.1368$cgi->a({-href=>$to->{'href'}, -class=>"path"},1369 esc_path($to->{'file'}));1370}else{1371$line='+++ b/'.1372 esc_path($to->{'file'});1373}1374}1375$result.= qq!<div class="diff to_file">$line</div>\n!;13761377return$result;1378}13791380# create note for patch simplified by combined diff1381sub format_diff_cc_simplified {1382my($diffinfo,@parents) =@_;1383my$result='';13841385$result.="<div class=\"diff header\">".1386"diff --cc ";1387if(!is_deleted($diffinfo)) {1388$result.=$cgi->a({-href => href(action=>"blob",1389 hash_base=>$hash,1390 hash=>$diffinfo->{'to_id'},1391 file_name=>$diffinfo->{'to_file'}),1392-class=>"path"},1393 esc_path($diffinfo->{'to_file'}));1394}else{1395$result.= esc_path($diffinfo->{'to_file'});1396}1397$result.="</div>\n".# class="diff header"1398"<div class=\"diff nodifferences\">".1399"Simple merge".1400"</div>\n";# class="diff nodifferences"14011402return$result;1403}14041405# format patch (diff) line (not to be used for diff headers)1406sub format_diff_line {1407my$line=shift;1408my($from,$to) =@_;1409my$diff_class="";14101411chomp$line;14121413if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1414# combined diff1415my$prefix=substr($line,0,scalar@{$from->{'href'}});1416if($line=~m/^\@{3}/) {1417$diff_class=" chunk_header";1418}elsif($line=~m/^\\/) {1419$diff_class=" incomplete";1420}elsif($prefix=~tr/+/+/) {1421$diff_class=" add";1422}elsif($prefix=~tr/-/-/) {1423$diff_class=" rem";1424}1425}else{1426# assume ordinary diff1427my$char=substr($line,0,1);1428if($chareq'+') {1429$diff_class=" add";1430}elsif($chareq'-') {1431$diff_class=" rem";1432}elsif($chareq'@') {1433$diff_class=" chunk_header";1434}elsif($chareq"\\") {1435$diff_class=" incomplete";1436}1437}1438$line= untabify($line);1439if($from&&$to&&$line=~m/^\@{2} /) {1440my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1441$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;14421443$from_lines=0unlessdefined$from_lines;1444$to_lines=0unlessdefined$to_lines;14451446if($from->{'href'}) {1447$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1448-class=>"list"},$from_text);1449}1450if($to->{'href'}) {1451$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1452-class=>"list"},$to_text);1453}1454$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1455"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1456return"<div class=\"diff$diff_class\">$line</div>\n";1457}elsif($from&&$to&&$line=~m/^\@{3}/) {1458my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1459my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);14601461@from_text=split(' ',$ranges);1462for(my$i=0;$i<@from_text; ++$i) {1463($from_start[$i],$from_nlines[$i]) =1464(split(',',substr($from_text[$i],1)),0);1465}14661467$to_text=pop@from_text;1468$to_start=pop@from_start;1469$to_nlines=pop@from_nlines;14701471$line="<span class=\"chunk_info\">$prefix";1472for(my$i=0;$i<@from_text; ++$i) {1473if($from->{'href'}[$i]) {1474$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1475-class=>"list"},$from_text[$i]);1476}else{1477$line.=$from_text[$i];1478}1479$line.=" ";1480}1481if($to->{'href'}) {1482$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1483-class=>"list"},$to_text);1484}else{1485$line.=$to_text;1486}1487$line.="$prefix</span>".1488"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1489return"<div class=\"diff$diff_class\">$line</div>\n";1490}1491return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1492}14931494# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1495# linked. Pass the hash of the tree/commit to snapshot.1496sub format_snapshot_links {1497my($hash) =@_;1498my@snapshot_fmts= gitweb_check_feature('snapshot');1499@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts);1500my$num_fmts=@snapshot_fmts;1501if($num_fmts>1) {1502# A parenthesized list of links bearing format names.1503# e.g. "snapshot (_tar.gz_ _zip_)"1504return"snapshot (".join(' ',map1505$cgi->a({1506-href => href(1507 action=>"snapshot",1508 hash=>$hash,1509 snapshot_format=>$_1510)1511},$known_snapshot_formats{$_}{'display'})1512,@snapshot_fmts) .")";1513}elsif($num_fmts==1) {1514# A single "snapshot" link whose tooltip bears the format name.1515# i.e. "_snapshot_"1516my($fmt) =@snapshot_fmts;1517return1518$cgi->a({1519-href => href(1520 action=>"snapshot",1521 hash=>$hash,1522 snapshot_format=>$fmt1523),1524-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"1525},"snapshot");1526}else{# $num_fmts == 01527returnundef;1528}1529}15301531## ......................................................................1532## functions returning values to be passed, perhaps after some1533## transformation, to other functions; e.g. returning arguments to href()15341535# returns hash to be passed to href to generate gitweb URL1536# in -title key it returns description of link1537sub get_feed_info {1538my$format=shift||'Atom';1539my%res= (action =>lc($format));15401541# feed links are possible only for project views1542return unless(defined$project);1543# some views should link to OPML, or to generic project feed,1544# or don't have specific feed yet (so they should use generic)1545return if($action=~/^(?:tags|heads|forks|tag|search)$/x);15461547my$branch;1548# branches refs uses 'refs/heads/' prefix (fullname) to differentiate1549# from tag links; this also makes possible to detect branch links1550if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||1551(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {1552$branch=$1;1553}1554# find log type for feed description (title)1555my$type='log';1556if(defined$file_name) {1557$type="history of$file_name";1558$type.="/"if($actioneq'tree');1559$type.=" on '$branch'"if(defined$branch);1560}else{1561$type="log of$branch"if(defined$branch);1562}15631564$res{-title} =$type;1565$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);1566$res{'file_name'} =$file_name;15671568return%res;1569}15701571## ----------------------------------------------------------------------1572## git utility subroutines, invoking git commands15731574# returns path to the core git executable and the --git-dir parameter as list1575sub git_cmd {1576return$GIT,'--git-dir='.$git_dir;1577}15781579# quote the given arguments for passing them to the shell1580# quote_command("command", "arg 1", "arg with ' and ! characters")1581# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"1582# Try to avoid using this function wherever possible.1583sub quote_command {1584returnjoin(' ',1585map( {my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_));1586}15871588# get HEAD ref of given project as hash1589sub git_get_head_hash {1590my$project=shift;1591my$o_git_dir=$git_dir;1592my$retval=undef;1593$git_dir="$projectroot/$project";1594if(open my$fd,"-|", git_cmd(),"rev-parse","--verify","HEAD") {1595my$head= <$fd>;1596close$fd;1597if(defined$head&&$head=~/^([0-9a-fA-F]{40})$/) {1598$retval=$1;1599}1600}1601if(defined$o_git_dir) {1602$git_dir=$o_git_dir;1603}1604return$retval;1605}16061607# get type of given object1608sub git_get_type {1609my$hash=shift;16101611open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;1612my$type= <$fd>;1613close$fdorreturn;1614chomp$type;1615return$type;1616}16171618# repository configuration1619our$config_file='';1620our%config;16211622# store multiple values for single key as anonymous array reference1623# single values stored directly in the hash, not as [ <value> ]1624sub hash_set_multi {1625my($hash,$key,$value) =@_;16261627if(!exists$hash->{$key}) {1628$hash->{$key} =$value;1629}elsif(!ref$hash->{$key}) {1630$hash->{$key} = [$hash->{$key},$value];1631}else{1632push@{$hash->{$key}},$value;1633}1634}16351636# return hash of git project configuration1637# optionally limited to some section, e.g. 'gitweb'1638sub git_parse_project_config {1639my$section_regexp=shift;1640my%config;16411642local$/="\0";16431644open my$fh,"-|", git_cmd(),"config",'-z','-l',1645orreturn;16461647while(my$keyval= <$fh>) {1648chomp$keyval;1649my($key,$value) =split(/\n/,$keyval,2);16501651 hash_set_multi(\%config,$key,$value)1652if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);1653}1654close$fh;16551656return%config;1657}16581659# convert config value to boolean, 'true' or 'false'1660# no value, number > 0, 'true' and 'yes' values are true1661# rest of values are treated as false (never as error)1662sub config_to_bool {1663my$val=shift;16641665# strip leading and trailing whitespace1666$val=~s/^\s+//;1667$val=~s/\s+$//;16681669return(!defined$val||# section.key1670($val=~/^\d+$/&&$val) ||# section.key = 11671($val=~/^(?:true|yes)$/i));# section.key = true1672}16731674# convert config value to simple decimal number1675# an optional value suffix of 'k', 'm', or 'g' will cause the value1676# to be multiplied by 1024, 1048576, or 10737418241677sub config_to_int {1678my$val=shift;16791680# strip leading and trailing whitespace1681$val=~s/^\s+//;1682$val=~s/\s+$//;16831684if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {1685$unit=lc($unit);1686# unknown unit is treated as 11687return$num* ($uniteq'g'?1073741824:1688$uniteq'm'?1048576:1689$uniteq'k'?1024:1);1690}1691return$val;1692}16931694# convert config value to array reference, if needed1695sub config_to_multi {1696my$val=shift;16971698returnref($val) ?$val: (defined($val) ? [$val] : []);1699}17001701sub git_get_project_config {1702my($key,$type) =@_;17031704# key sanity check1705return unless($key);1706$key=~s/^gitweb\.//;1707return if($key=~m/\W/);17081709# type sanity check1710if(defined$type) {1711$type=~s/^--//;1712$type=undef1713unless($typeeq'bool'||$typeeq'int');1714}17151716# get config1717if(!defined$config_file||1718$config_filene"$git_dir/config") {1719%config= git_parse_project_config('gitweb');1720$config_file="$git_dir/config";1721}17221723# ensure given type1724if(!defined$type) {1725return$config{"gitweb.$key"};1726}elsif($typeeq'bool') {1727# backward compatibility: 'git config --bool' returns true/false1728return config_to_bool($config{"gitweb.$key"}) ?'true':'false';1729}elsif($typeeq'int') {1730return config_to_int($config{"gitweb.$key"});1731}1732return$config{"gitweb.$key"};1733}17341735# get hash of given path at given ref1736sub git_get_hash_by_path {1737my$base=shift;1738my$path=shift||returnundef;1739my$type=shift;17401741$path=~ s,/+$,,;17421743open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path1744or die_error(500,"Open git-ls-tree failed");1745my$line= <$fd>;1746close$fdorreturnundef;17471748if(!defined$line) {1749# there is no tree or hash given by $path at $base1750returnundef;1751}17521753#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'1754$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;1755if(defined$type&&$typene$2) {1756# type doesn't match1757returnundef;1758}1759return$3;1760}17611762# get path of entry with given hash at given tree-ish (ref)1763# used to get 'from' filename for combined diff (merge commit) for renames1764sub git_get_path_by_hash {1765my$base=shift||return;1766my$hash=shift||return;17671768local$/="\0";17691770open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base1771orreturnundef;1772while(my$line= <$fd>) {1773chomp$line;17741775#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'1776#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'1777if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {1778close$fd;1779return$1;1780}1781}1782close$fd;1783returnundef;1784}17851786## ......................................................................1787## git utility functions, directly accessing git repository17881789sub git_get_project_description {1790my$path=shift;17911792$git_dir="$projectroot/$path";1793open my$fd,"$git_dir/description"1794orreturn git_get_project_config('description');1795my$descr= <$fd>;1796close$fd;1797if(defined$descr) {1798chomp$descr;1799}1800return$descr;1801}18021803sub git_get_project_ctags {1804my$path=shift;1805my$ctags= {};18061807$git_dir="$projectroot/$path";1808unless(opendir D,"$git_dir/ctags") {1809return$ctags;1810}1811foreach(grep{ -f $_}map{"$git_dir/ctags/$_"}readdir(D)) {1812open CT,$_ornext;1813my$val= <CT>;1814chomp$val;1815close CT;1816my$ctag=$_;$ctag=~ s#.*/##;1817$ctags->{$ctag} =$val;1818}1819closedir D;1820$ctags;1821}18221823sub git_populate_project_tagcloud {1824my$ctags=shift;18251826# First, merge different-cased tags; tags vote on casing1827my%ctags_lc;1828foreach(keys%$ctags) {1829$ctags_lc{lc$_}->{count} +=$ctags->{$_};1830if(not$ctags_lc{lc$_}->{topcount}1831or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {1832$ctags_lc{lc$_}->{topcount} =$ctags->{$_};1833$ctags_lc{lc$_}->{topname} =$_;1834}1835}18361837my$cloud;1838if(eval{require HTML::TagCloud;1; }) {1839$cloud= HTML::TagCloud->new;1840foreach(sort keys%ctags_lc) {1841# Pad the title with spaces so that the cloud looks1842# less crammed.1843my$title=$ctags_lc{$_}->{topname};1844$title=~s/ / /g;1845$title=~s/^/ /g;1846$title=~s/$/ /g;1847$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});1848}1849}else{1850$cloud= \%ctags_lc;1851}1852$cloud;1853}18541855sub git_show_project_tagcloud {1856my($cloud,$count) =@_;1857print STDERR ref($cloud)."..\n";1858if(ref$cloudeq'HTML::TagCloud') {1859return$cloud->html_and_css($count);1860}else{1861my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;1862return'<p align="center">'.join(', ',map{1863"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"1864}splice(@tags,0,$count)) .'</p>';1865}1866}18671868sub git_get_project_url_list {1869my$path=shift;18701871$git_dir="$projectroot/$path";1872open my$fd,"$git_dir/cloneurl"1873orreturnwantarray?1874@{ config_to_multi(git_get_project_config('url')) } :1875 config_to_multi(git_get_project_config('url'));1876my@git_project_url_list=map{chomp;$_} <$fd>;1877close$fd;18781879returnwantarray?@git_project_url_list: \@git_project_url_list;1880}18811882sub git_get_projects_list {1883my($filter) =@_;1884my@list;18851886$filter||='';1887$filter=~s/\.git$//;18881889my($check_forks) = gitweb_check_feature('forks');18901891if(-d $projects_list) {1892# search in directory1893my$dir=$projects_list. ($filter?"/$filter":'');1894# remove the trailing "/"1895$dir=~s!/+$!!;1896my$pfxlen=length("$dir");1897my$pfxdepth= ($dir=~tr!/!!);18981899 File::Find::find({1900 follow_fast =>1,# follow symbolic links1901 follow_skip =>2,# ignore duplicates1902 dangling_symlinks =>0,# ignore dangling symlinks, silently1903 wanted =>sub{1904# skip project-list toplevel, if we get it.1905return if(m!^[/.]$!);1906# only directories can be git repositories1907return unless(-d $_);1908# don't traverse too deep (Find is super slow on os x)1909if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {1910$File::Find::prune =1;1911return;1912}19131914my$subdir=substr($File::Find::name,$pfxlen+1);1915# we check related file in $projectroot1916if(check_export_ok("$projectroot/$filter/$subdir")) {1917push@list, { path => ($filter?"$filter/":'') .$subdir};1918$File::Find::prune =1;1919}1920},1921},"$dir");19221923}elsif(-f $projects_list) {1924# read from file(url-encoded):1925# 'git%2Fgit.git Linus+Torvalds'1926# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'1927# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'1928my%paths;1929open my($fd),$projects_listorreturn;1930 PROJECT:1931while(my$line= <$fd>) {1932chomp$line;1933my($path,$owner) =split' ',$line;1934$path= unescape($path);1935$owner= unescape($owner);1936if(!defined$path) {1937next;1938}1939if($filterne'') {1940# looking for forks;1941my$pfx=substr($path,0,length($filter));1942if($pfxne$filter) {1943next PROJECT;1944}1945my$sfx=substr($path,length($filter));1946if($sfx!~/^\/.*\.git$/) {1947next PROJECT;1948}1949}elsif($check_forks) {1950 PATH:1951foreachmy$filter(keys%paths) {1952# looking for forks;1953my$pfx=substr($path,0,length($filter));1954if($pfxne$filter) {1955next PATH;1956}1957my$sfx=substr($path,length($filter));1958if($sfx!~/^\/.*\.git$/) {1959next PATH;1960}1961# is a fork, don't include it in1962# the list1963next PROJECT;1964}1965}1966if(check_export_ok("$projectroot/$path")) {1967my$pr= {1968 path =>$path,1969 owner => to_utf8($owner),1970};1971push@list,$pr;1972(my$forks_path=$path) =~s/\.git$//;1973$paths{$forks_path}++;1974}1975}1976close$fd;1977}1978return@list;1979}19801981our$gitweb_project_owner=undef;1982sub git_get_project_list_from_file {19831984return if(defined$gitweb_project_owner);19851986$gitweb_project_owner= {};1987# read from file (url-encoded):1988# 'git%2Fgit.git Linus+Torvalds'1989# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'1990# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'1991if(-f $projects_list) {1992open(my$fd,$projects_list);1993while(my$line= <$fd>) {1994chomp$line;1995my($pr,$ow) =split' ',$line;1996$pr= unescape($pr);1997$ow= unescape($ow);1998$gitweb_project_owner->{$pr} = to_utf8($ow);1999}2000close$fd;2001}2002}20032004sub git_get_project_owner {2005my$project=shift;2006my$owner;20072008returnundefunless$project;2009$git_dir="$projectroot/$project";20102011if(!defined$gitweb_project_owner) {2012 git_get_project_list_from_file();2013}20142015if(exists$gitweb_project_owner->{$project}) {2016$owner=$gitweb_project_owner->{$project};2017}2018if(!defined$owner){2019$owner= git_get_project_config('owner');2020}2021if(!defined$owner) {2022$owner= get_file_owner("$git_dir");2023}20242025return$owner;2026}20272028sub git_get_last_activity {2029my($path) =@_;2030my$fd;20312032$git_dir="$projectroot/$path";2033open($fd,"-|", git_cmd(),'for-each-ref',2034'--format=%(committer)',2035'--sort=-committerdate',2036'--count=1',2037'refs/heads')orreturn;2038my$most_recent= <$fd>;2039close$fdorreturn;2040if(defined$most_recent&&2041$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2042my$timestamp=$1;2043my$age=time-$timestamp;2044return($age, age_string($age));2045}2046return(undef,undef);2047}20482049sub git_get_references {2050my$type=shift||"";2051my%refs;2052# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112053# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2054open my$fd,"-|", git_cmd(),"show-ref","--dereference",2055($type? ("--","refs/$type") : ())# use -- <pattern> if $type2056orreturn;20572058while(my$line= <$fd>) {2059chomp$line;2060if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2061if(defined$refs{$1}) {2062push@{$refs{$1}},$2;2063}else{2064$refs{$1} = [$2];2065}2066}2067}2068close$fdorreturn;2069return \%refs;2070}20712072sub git_get_rev_name_tags {2073my$hash=shift||returnundef;20742075open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2076orreturn;2077my$name_rev= <$fd>;2078close$fd;20792080if($name_rev=~ m|^$hash tags/(.*)$|) {2081return$1;2082}else{2083# catches also '$hash undefined' output2084returnundef;2085}2086}20872088## ----------------------------------------------------------------------2089## parse to hash functions20902091sub parse_date {2092my$epoch=shift;2093my$tz=shift||"-0000";20942095my%date;2096my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2097my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2098my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2099$date{'hour'} =$hour;2100$date{'minute'} =$min;2101$date{'mday'} =$mday;2102$date{'day'} =$days[$wday];2103$date{'month'} =$months[$mon];2104$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2105$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2106$date{'mday-time'} =sprintf"%d%s%02d:%02d",2107$mday,$months[$mon],$hour,$min;2108$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",21091900+$year,1+$mon,$mday,$hour,$min,$sec;21102111$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2112my$local=$epoch+ ((int$1+ ($2/60)) *3600);2113($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2114$date{'hour_local'} =$hour;2115$date{'minute_local'} =$min;2116$date{'tz_local'} =$tz;2117$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",21181900+$year,$mon+1,$mday,2119$hour,$min,$sec,$tz);2120return%date;2121}21222123sub parse_tag {2124my$tag_id=shift;2125my%tag;2126my@comment;21272128open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2129$tag{'id'} =$tag_id;2130while(my$line= <$fd>) {2131chomp$line;2132if($line=~m/^object ([0-9a-fA-F]{40})$/) {2133$tag{'object'} =$1;2134}elsif($line=~m/^type (.+)$/) {2135$tag{'type'} =$1;2136}elsif($line=~m/^tag (.+)$/) {2137$tag{'name'} =$1;2138}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2139$tag{'author'} =$1;2140$tag{'epoch'} =$2;2141$tag{'tz'} =$3;2142}elsif($line=~m/--BEGIN/) {2143push@comment,$line;2144last;2145}elsif($lineeq"") {2146last;2147}2148}2149push@comment, <$fd>;2150$tag{'comment'} = \@comment;2151close$fdorreturn;2152if(!defined$tag{'name'}) {2153return2154};2155return%tag2156}21572158sub parse_commit_text {2159my($commit_text,$withparents) =@_;2160my@commit_lines=split'\n',$commit_text;2161my%co;21622163pop@commit_lines;# Remove '\0'21642165if(!@commit_lines) {2166return;2167}21682169my$header=shift@commit_lines;2170if($header!~m/^[0-9a-fA-F]{40}/) {2171return;2172}2173($co{'id'},my@parents) =split' ',$header;2174while(my$line=shift@commit_lines) {2175last if$lineeq"\n";2176if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2177$co{'tree'} =$1;2178}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2179push@parents,$1;2180}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2181$co{'author'} =$1;2182$co{'author_epoch'} =$2;2183$co{'author_tz'} =$3;2184if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2185$co{'author_name'} =$1;2186$co{'author_email'} =$2;2187}else{2188$co{'author_name'} =$co{'author'};2189}2190}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2191$co{'committer'} =$1;2192$co{'committer_epoch'} =$2;2193$co{'committer_tz'} =$3;2194$co{'committer_name'} =$co{'committer'};2195if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2196$co{'committer_name'} =$1;2197$co{'committer_email'} =$2;2198}else{2199$co{'committer_name'} =$co{'committer'};2200}2201}2202}2203if(!defined$co{'tree'}) {2204return;2205};2206$co{'parents'} = \@parents;2207$co{'parent'} =$parents[0];22082209foreachmy$title(@commit_lines) {2210$title=~s/^ //;2211if($titlene"") {2212$co{'title'} = chop_str($title,80,5);2213# remove leading stuff of merges to make the interesting part visible2214if(length($title) >50) {2215$title=~s/^Automatic //;2216$title=~s/^merge (of|with) /Merge ... /i;2217if(length($title) >50) {2218$title=~s/(http|rsync):\/\///;2219}2220if(length($title) >50) {2221$title=~s/(master|www|rsync)\.//;2222}2223if(length($title) >50) {2224$title=~s/kernel.org:?//;2225}2226if(length($title) >50) {2227$title=~s/\/pub\/scm//;2228}2229}2230$co{'title_short'} = chop_str($title,50,5);2231last;2232}2233}2234if(!defined$co{'title'} ||$co{'title'}eq"") {2235$co{'title'} =$co{'title_short'} ='(no commit message)';2236}2237# remove added spaces2238foreachmy$line(@commit_lines) {2239$line=~s/^ //;2240}2241$co{'comment'} = \@commit_lines;22422243my$age=time-$co{'committer_epoch'};2244$co{'age'} =$age;2245$co{'age_string'} = age_string($age);2246my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2247if($age>60*60*24*7*2) {2248$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2249$co{'age_string_age'} =$co{'age_string'};2250}else{2251$co{'age_string_date'} =$co{'age_string'};2252$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2253}2254return%co;2255}22562257sub parse_commit {2258my($commit_id) =@_;2259my%co;22602261local$/="\0";22622263open my$fd,"-|", git_cmd(),"rev-list",2264"--parents",2265"--header",2266"--max-count=1",2267$commit_id,2268"--",2269or die_error(500,"Open git-rev-list failed");2270%co= parse_commit_text(<$fd>,1);2271close$fd;22722273return%co;2274}22752276sub parse_commits {2277my($commit_id,$maxcount,$skip,$filename,@args) =@_;2278my@cos;22792280$maxcount||=1;2281$skip||=0;22822283local$/="\0";22842285open my$fd,"-|", git_cmd(),"rev-list",2286"--header",2287@args,2288("--max-count=".$maxcount),2289("--skip=".$skip),2290@extra_options,2291$commit_id,2292"--",2293($filename? ($filename) : ())2294or die_error(500,"Open git-rev-list failed");2295while(my$line= <$fd>) {2296my%co= parse_commit_text($line);2297push@cos, \%co;2298}2299close$fd;23002301returnwantarray?@cos: \@cos;2302}23032304# parse line of git-diff-tree "raw" output2305sub parse_difftree_raw_line {2306my$line=shift;2307my%res;23082309# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2310# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2311if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2312$res{'from_mode'} =$1;2313$res{'to_mode'} =$2;2314$res{'from_id'} =$3;2315$res{'to_id'} =$4;2316$res{'status'} =$5;2317$res{'similarity'} =$6;2318if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2319($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2320}else{2321$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2322}2323}2324# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2325# combined diff (for merge commit)2326elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2327$res{'nparents'} =length($1);2328$res{'from_mode'} = [split(' ',$2) ];2329$res{'to_mode'} =pop@{$res{'from_mode'}};2330$res{'from_id'} = [split(' ',$3) ];2331$res{'to_id'} =pop@{$res{'from_id'}};2332$res{'status'} = [split('',$4) ];2333$res{'to_file'} = unquote($5);2334}2335# 'c512b523472485aef4fff9e57b229d9d243c967f'2336elsif($line=~m/^([0-9a-fA-F]{40})$/) {2337$res{'commit'} =$1;2338}23392340returnwantarray?%res: \%res;2341}23422343# wrapper: return parsed line of git-diff-tree "raw" output2344# (the argument might be raw line, or parsed info)2345sub parsed_difftree_line {2346my$line_or_ref=shift;23472348if(ref($line_or_ref)eq"HASH") {2349# pre-parsed (or generated by hand)2350return$line_or_ref;2351}else{2352return parse_difftree_raw_line($line_or_ref);2353}2354}23552356# parse line of git-ls-tree output2357sub parse_ls_tree_line ($;%) {2358my$line=shift;2359my%opts=@_;2360my%res;23612362#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2363$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;23642365$res{'mode'} =$1;2366$res{'type'} =$2;2367$res{'hash'} =$3;2368if($opts{'-z'}) {2369$res{'name'} =$4;2370}else{2371$res{'name'} = unquote($4);2372}23732374returnwantarray?%res: \%res;2375}23762377# generates _two_ hashes, references to which are passed as 2 and 3 argument2378sub parse_from_to_diffinfo {2379my($diffinfo,$from,$to,@parents) =@_;23802381if($diffinfo->{'nparents'}) {2382# combined diff2383$from->{'file'} = [];2384$from->{'href'} = [];2385 fill_from_file_info($diffinfo,@parents)2386unlessexists$diffinfo->{'from_file'};2387for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2388$from->{'file'}[$i] =2389defined$diffinfo->{'from_file'}[$i] ?2390$diffinfo->{'from_file'}[$i] :2391$diffinfo->{'to_file'};2392if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2393$from->{'href'}[$i] = href(action=>"blob",2394 hash_base=>$parents[$i],2395 hash=>$diffinfo->{'from_id'}[$i],2396 file_name=>$from->{'file'}[$i]);2397}else{2398$from->{'href'}[$i] =undef;2399}2400}2401}else{2402# ordinary (not combined) diff2403$from->{'file'} =$diffinfo->{'from_file'};2404if($diffinfo->{'status'}ne"A") {# not new (added) file2405$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2406 hash=>$diffinfo->{'from_id'},2407 file_name=>$from->{'file'});2408}else{2409delete$from->{'href'};2410}2411}24122413$to->{'file'} =$diffinfo->{'to_file'};2414if(!is_deleted($diffinfo)) {# file exists in result2415$to->{'href'} = href(action=>"blob", hash_base=>$hash,2416 hash=>$diffinfo->{'to_id'},2417 file_name=>$to->{'file'});2418}else{2419delete$to->{'href'};2420}2421}24222423## ......................................................................2424## parse to array of hashes functions24252426sub git_get_heads_list {2427my$limit=shift;2428my@headslist;24292430open my$fd,'-|', git_cmd(),'for-each-ref',2431($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2432'--format=%(objectname) %(refname) %(subject)%00%(committer)',2433'refs/heads'2434orreturn;2435while(my$line= <$fd>) {2436my%ref_item;24372438chomp$line;2439my($refinfo,$committerinfo) =split(/\0/,$line);2440my($hash,$name,$title) =split(' ',$refinfo,3);2441my($committer,$epoch,$tz) =2442($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2443$ref_item{'fullname'} =$name;2444$name=~s!^refs/heads/!!;24452446$ref_item{'name'} =$name;2447$ref_item{'id'} =$hash;2448$ref_item{'title'} =$title||'(no commit message)';2449$ref_item{'epoch'} =$epoch;2450if($epoch) {2451$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2452}else{2453$ref_item{'age'} ="unknown";2454}24552456push@headslist, \%ref_item;2457}2458close$fd;24592460returnwantarray?@headslist: \@headslist;2461}24622463sub git_get_tags_list {2464my$limit=shift;2465my@tagslist;24662467open my$fd,'-|', git_cmd(),'for-each-ref',2468($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',2469'--format=%(objectname) %(objecttype) %(refname) '.2470'%(*objectname) %(*objecttype) %(subject)%00%(creator)',2471'refs/tags'2472orreturn;2473while(my$line= <$fd>) {2474my%ref_item;24752476chomp$line;2477my($refinfo,$creatorinfo) =split(/\0/,$line);2478my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);2479my($creator,$epoch,$tz) =2480($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);2481$ref_item{'fullname'} =$name;2482$name=~s!^refs/tags/!!;24832484$ref_item{'type'} =$type;2485$ref_item{'id'} =$id;2486$ref_item{'name'} =$name;2487if($typeeq"tag") {2488$ref_item{'subject'} =$title;2489$ref_item{'reftype'} =$reftype;2490$ref_item{'refid'} =$refid;2491}else{2492$ref_item{'reftype'} =$type;2493$ref_item{'refid'} =$id;2494}24952496if($typeeq"tag"||$typeeq"commit") {2497$ref_item{'epoch'} =$epoch;2498if($epoch) {2499$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2500}else{2501$ref_item{'age'} ="unknown";2502}2503}25042505push@tagslist, \%ref_item;2506}2507close$fd;25082509returnwantarray?@tagslist: \@tagslist;2510}25112512## ----------------------------------------------------------------------2513## filesystem-related functions25142515sub get_file_owner {2516my$path=shift;25172518my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);2519my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);2520if(!defined$gcos) {2521returnundef;2522}2523my$owner=$gcos;2524$owner=~s/[,;].*$//;2525return to_utf8($owner);2526}25272528## ......................................................................2529## mimetype related functions25302531sub mimetype_guess_file {2532my$filename=shift;2533my$mimemap=shift;2534-r $mimemaporreturnundef;25352536my%mimemap;2537open(MIME,$mimemap)orreturnundef;2538while(<MIME>) {2539next ifm/^#/;# skip comments2540my($mime,$exts) =split(/\t+/);2541if(defined$exts) {2542my@exts=split(/\s+/,$exts);2543foreachmy$ext(@exts) {2544$mimemap{$ext} =$mime;2545}2546}2547}2548close(MIME);25492550$filename=~/\.([^.]*)$/;2551return$mimemap{$1};2552}25532554sub mimetype_guess {2555my$filename=shift;2556my$mime;2557$filename=~/\./orreturnundef;25582559if($mimetypes_file) {2560my$file=$mimetypes_file;2561if($file!~m!^/!) {# if it is relative path2562# it is relative to project2563$file="$projectroot/$project/$file";2564}2565$mime= mimetype_guess_file($filename,$file);2566}2567$mime||= mimetype_guess_file($filename,'/etc/mime.types');2568return$mime;2569}25702571sub blob_mimetype {2572my$fd=shift;2573my$filename=shift;25742575if($filename) {2576my$mime= mimetype_guess($filename);2577$mimeandreturn$mime;2578}25792580# just in case2581return$default_blob_plain_mimetypeunless$fd;25822583if(-T $fd) {2584return'text/plain';2585}elsif(!$filename) {2586return'application/octet-stream';2587}elsif($filename=~m/\.png$/i) {2588return'image/png';2589}elsif($filename=~m/\.gif$/i) {2590return'image/gif';2591}elsif($filename=~m/\.jpe?g$/i) {2592return'image/jpeg';2593}else{2594return'application/octet-stream';2595}2596}25972598sub blob_contenttype {2599my($fd,$file_name,$type) =@_;26002601$type||= blob_mimetype($fd,$file_name);2602if($typeeq'text/plain'&&defined$default_text_plain_charset) {2603$type.="; charset=$default_text_plain_charset";2604}26052606return$type;2607}26082609## ======================================================================2610## functions printing HTML: header, footer, error page26112612sub git_header_html {2613my$status=shift||"200 OK";2614my$expires=shift;26152616my$title="$site_name";2617if(defined$project) {2618$title.=" - ". to_utf8($project);2619if(defined$action) {2620$title.="/$action";2621if(defined$file_name) {2622$title.=" - ". esc_path($file_name);2623if($actioneq"tree"&&$file_name!~ m|/$|) {2624$title.="/";2625}2626}2627}2628}2629my$content_type;2630# require explicit support from the UA if we are to send the page as2631# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.2632# we have to do this because MSIE sometimes globs '*/*', pretending to2633# support xhtml+xml but choking when it gets what it asked for.2634if(defined$cgi->http('HTTP_ACCEPT') &&2635$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&2636$cgi->Accept('application/xhtml+xml') !=0) {2637$content_type='application/xhtml+xml';2638}else{2639$content_type='text/html';2640}2641print$cgi->header(-type=>$content_type, -charset =>'utf-8',2642-status=>$status, -expires =>$expires);2643my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';2644print<<EOF;2645<?xml version="1.0" encoding="utf-8"?>2646<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">2647<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">2648<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->2649<!-- git core binaries version$git_version-->2650<head>2651<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>2652<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>2653<meta name="robots" content="index, nofollow"/>2654<title>$title</title>2655EOF2656# print out each stylesheet that exist2657if(defined$stylesheet) {2658#provides backwards capability for those people who define style sheet in a config file2659print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";2660}else{2661foreachmy$stylesheet(@stylesheets) {2662next unless$stylesheet;2663print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";2664}2665}2666if(defined$project) {2667my%href_params= get_feed_info();2668if(!exists$href_params{'-title'}) {2669$href_params{'-title'} ='log';2670}26712672foreachmy$formatqw(RSS Atom){2673my$type=lc($format);2674my%link_attr= (2675'-rel'=>'alternate',2676'-title'=>"$project-$href_params{'-title'} -$formatfeed",2677'-type'=>"application/$type+xml"2678);26792680$href_params{'action'} =$type;2681$link_attr{'-href'} = href(%href_params);2682print"<link ".2683"rel=\"$link_attr{'-rel'}\"".2684"title=\"$link_attr{'-title'}\"".2685"href=\"$link_attr{'-href'}\"".2686"type=\"$link_attr{'-type'}\"".2687"/>\n";26882689$href_params{'extra_options'} ='--no-merges';2690$link_attr{'-href'} = href(%href_params);2691$link_attr{'-title'} .=' (no merges)';2692print"<link ".2693"rel=\"$link_attr{'-rel'}\"".2694"title=\"$link_attr{'-title'}\"".2695"href=\"$link_attr{'-href'}\"".2696"type=\"$link_attr{'-type'}\"".2697"/>\n";2698}26992700}else{2701printf('<link rel="alternate" title="%sprojects list" '.2702'href="%s" type="text/plain; charset=utf-8" />'."\n",2703$site_name, href(project=>undef, action=>"project_index"));2704printf('<link rel="alternate" title="%sprojects feeds" '.2705'href="%s" type="text/x-opml" />'."\n",2706$site_name, href(project=>undef, action=>"opml"));2707}2708if(defined$favicon) {2709printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);2710}27112712print"</head>\n".2713"<body>\n";27142715if(-f $site_header) {2716open(my$fd,$site_header);2717print<$fd>;2718close$fd;2719}27202721print"<div class=\"page_header\">\n".2722$cgi->a({-href => esc_url($logo_url),2723-title =>$logo_label},2724qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));2725print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";2726if(defined$project) {2727print$cgi->a({-href => href(action=>"summary")}, esc_html($project));2728if(defined$action) {2729print" /$action";2730}2731print"\n";2732}2733print"</div>\n";27342735my($have_search) = gitweb_check_feature('search');2736if(defined$project&&$have_search) {2737if(!defined$searchtext) {2738$searchtext="";2739}2740my$search_hash;2741if(defined$hash_base) {2742$search_hash=$hash_base;2743}elsif(defined$hash) {2744$search_hash=$hash;2745}else{2746$search_hash="HEAD";2747}2748my$action=$my_uri;2749my($use_pathinfo) = gitweb_check_feature('pathinfo');2750if($use_pathinfo) {2751$action.="/".esc_url($project);2752}2753print$cgi->startform(-method=>"get", -action =>$action) .2754"<div class=\"search\">\n".2755(!$use_pathinfo&&2756$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .2757$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".2758$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".2759$cgi->popup_menu(-name =>'st', -default=>'commit',2760-values=> ['commit','grep','author','committer','pickaxe']) .2761$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .2762" search:\n",2763$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".2764"<span title=\"Extended regular expression\">".2765$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',2766-checked =>$search_use_regexp) .2767"</span>".2768"</div>".2769$cgi->end_form() ."\n";2770}2771}27722773sub git_footer_html {2774my$feed_class='rss_logo';27752776print"<div class=\"page_footer\">\n";2777if(defined$project) {2778my$descr= git_get_project_description($project);2779if(defined$descr) {2780print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";2781}27822783my%href_params= get_feed_info();2784if(!%href_params) {2785$feed_class.=' generic';2786}2787$href_params{'-title'} ||='log';27882789foreachmy$formatqw(RSS Atom){2790$href_params{'action'} =lc($format);2791print$cgi->a({-href => href(%href_params),2792-title =>"$href_params{'-title'}$formatfeed",2793-class=>$feed_class},$format)."\n";2794}27952796}else{2797print$cgi->a({-href => href(project=>undef, action=>"opml"),2798-class=>$feed_class},"OPML") ." ";2799print$cgi->a({-href => href(project=>undef, action=>"project_index"),2800-class=>$feed_class},"TXT") ."\n";2801}2802print"</div>\n";# class="page_footer"28032804if(-f $site_footer) {2805open(my$fd,$site_footer);2806print<$fd>;2807close$fd;2808}28092810print"</body>\n".2811"</html>";2812}28132814# die_error(<http_status_code>, <error_message>)2815# Example: die_error(404, 'Hash not found')2816# By convention, use the following status codes (as defined in RFC 2616):2817# 400: Invalid or missing CGI parameters, or2818# requested object exists but has wrong type.2819# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on2820# this server or project.2821# 404: Requested object/revision/project doesn't exist.2822# 500: The server isn't configured properly, or2823# an internal error occurred (e.g. failed assertions caused by bugs), or2824# an unknown error occurred (e.g. the git binary died unexpectedly).2825sub die_error {2826my$status=shift||500;2827my$error=shift||"Internal server error";28282829my%http_responses= (400=>'400 Bad Request',2830403=>'403 Forbidden',2831404=>'404 Not Found',2832500=>'500 Internal Server Error');2833 git_header_html($http_responses{$status});2834print<<EOF;2835<div class="page_body">2836<br /><br />2837$status-$error2838<br />2839</div>2840EOF2841 git_footer_html();2842exit;2843}28442845## ----------------------------------------------------------------------2846## functions printing or outputting HTML: navigation28472848sub git_print_page_nav {2849my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;2850$extra=''if!defined$extra;# pager or formats28512852my@navs=qw(summary shortlog log commit commitdiff tree);2853if($suppress) {2854@navs=grep{$_ne$suppress}@navs;2855}28562857my%arg=map{$_=> {action=>$_} }@navs;2858if(defined$head) {2859for(qw(commit commitdiff)) {2860$arg{$_}{'hash'} =$head;2861}2862if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {2863for(qw(shortlog log)) {2864$arg{$_}{'hash'} =$head;2865}2866}2867}28682869$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;2870$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;28712872my@actions= gitweb_check_feature('actions');2873while(@actions) {2874my($label,$link,$pos) = (shift(@actions),shift(@actions),shift(@actions));2875@navs=map{$_eq$pos? ($_,$label) :$_}@navs;2876# munch munch2877$link=~ s#%n#$project#g;2878$link=~ s#%f#$git_dir#g;2879$treehead?$link=~ s#%h#$treehead#g : $link =~ s#%h##g;2880$treebase?$link=~ s#%b#$treebase#g : $link =~ s#%b##g;2881$arg{$label}{'_href'} =$link;2882}28832884print"<div class=\"page_nav\">\n".2885(join" | ",2886map{$_eq$current?2887$_:$cgi->a({-href => ($arg{$_}{_href} ?$arg{$_}{_href} : href(%{$arg{$_}}))},"$_")2888}@navs);2889print"<br/>\n$extra<br/>\n".2890"</div>\n";2891}28922893sub format_paging_nav {2894my($action,$hash,$head,$page,$has_next_link) =@_;2895my$paging_nav;289628972898if($hashne$head||$page) {2899$paging_nav.=$cgi->a({-href => href(action=>$action)},"HEAD");2900}else{2901$paging_nav.="HEAD";2902}29032904if($page>0) {2905$paging_nav.=" ⋅ ".2906$cgi->a({-href => href(-replay=>1, page=>$page-1),2907-accesskey =>"p", -title =>"Alt-p"},"prev");2908}else{2909$paging_nav.=" ⋅ prev";2910}29112912if($has_next_link) {2913$paging_nav.=" ⋅ ".2914$cgi->a({-href => href(-replay=>1, page=>$page+1),2915-accesskey =>"n", -title =>"Alt-n"},"next");2916}else{2917$paging_nav.=" ⋅ next";2918}29192920return$paging_nav;2921}29222923## ......................................................................2924## functions printing or outputting HTML: div29252926sub git_print_header_div {2927my($action,$title,$hash,$hash_base) =@_;2928my%args= ();29292930$args{'action'} =$action;2931$args{'hash'} =$hashif$hash;2932$args{'hash_base'} =$hash_baseif$hash_base;29332934print"<div class=\"header\">\n".2935$cgi->a({-href => href(%args), -class=>"title"},2936$title?$title:$action) .2937"\n</div>\n";2938}29392940#sub git_print_authorship (\%) {2941sub git_print_authorship {2942my$co=shift;29432944my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});2945print"<div class=\"author_date\">".2946 esc_html($co->{'author_name'}) .2947" [$ad{'rfc2822'}";2948if($ad{'hour_local'} <6) {2949printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",2950$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});2951}else{2952printf(" (%02d:%02d%s)",2953$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});2954}2955print"]</div>\n";2956}29572958sub git_print_page_path {2959my$name=shift;2960my$type=shift;2961my$hb=shift;296229632964print"<div class=\"page_path\">";2965print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),2966-title =>'tree root'}, to_utf8("[$project]"));2967print" / ";2968if(defined$name) {2969my@dirname=split'/',$name;2970my$basename=pop@dirname;2971my$fullname='';29722973foreachmy$dir(@dirname) {2974$fullname.= ($fullname?'/':'') .$dir;2975print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,2976 hash_base=>$hb),2977-title =>$fullname}, esc_path($dir));2978print" / ";2979}2980if(defined$type&&$typeeq'blob') {2981print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,2982 hash_base=>$hb),2983-title =>$name}, esc_path($basename));2984}elsif(defined$type&&$typeeq'tree') {2985print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,2986 hash_base=>$hb),2987-title =>$name}, esc_path($basename));2988print" / ";2989}else{2990print esc_path($basename);2991}2992}2993print"<br/></div>\n";2994}29952996# sub git_print_log (\@;%) {2997sub git_print_log ($;%) {2998my$log=shift;2999my%opts=@_;30003001if($opts{'-remove_title'}) {3002# remove title, i.e. first line of log3003shift@$log;3004}3005# remove leading empty lines3006while(defined$log->[0] &&$log->[0]eq"") {3007shift@$log;3008}30093010# print log3011my$signoff=0;3012my$empty=0;3013foreachmy$line(@$log) {3014if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {3015$signoff=1;3016$empty=0;3017if(!$opts{'-remove_signoff'}) {3018print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";3019next;3020}else{3021# remove signoff lines3022next;3023}3024}else{3025$signoff=0;3026}30273028# print only one empty line3029# do not print empty line after signoff3030if($lineeq"") {3031next if($empty||$signoff);3032$empty=1;3033}else{3034$empty=0;3035}30363037print format_log_line_html($line) ."<br/>\n";3038}30393040if($opts{'-final_empty_line'}) {3041# end with single empty line3042print"<br/>\n"unless$empty;3043}3044}30453046# return link target (what link points to)3047sub git_get_link_target {3048my$hash=shift;3049my$link_target;30503051# read link3052open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3053orreturn;3054{3055local$/;3056$link_target= <$fd>;3057}3058close$fd3059orreturn;30603061return$link_target;3062}30633064# given link target, and the directory (basedir) the link is in,3065# return target of link relative to top directory (top tree);3066# return undef if it is not possible (including absolute links).3067sub normalize_link_target {3068my($link_target,$basedir,$hash_base) =@_;30693070# we can normalize symlink target only if $hash_base is provided3071return unless$hash_base;30723073# absolute symlinks (beginning with '/') cannot be normalized3074return if(substr($link_target,0,1)eq'/');30753076# normalize link target to path from top (root) tree (dir)3077my$path;3078if($basedir) {3079$path=$basedir.'/'.$link_target;3080}else{3081# we are in top (root) tree (dir)3082$path=$link_target;3083}30843085# remove //, /./, and /../3086my@path_parts;3087foreachmy$part(split('/',$path)) {3088# discard '.' and ''3089next if(!$part||$parteq'.');3090# handle '..'3091if($parteq'..') {3092if(@path_parts) {3093pop@path_parts;3094}else{3095# link leads outside repository (outside top dir)3096return;3097}3098}else{3099push@path_parts,$part;3100}3101}3102$path=join('/',@path_parts);31033104return$path;3105}31063107# print tree entry (row of git_tree), but without encompassing <tr> element3108sub git_print_tree_entry {3109my($t,$basedir,$hash_base,$have_blame) =@_;31103111my%base_key= ();3112$base_key{'hash_base'} =$hash_baseifdefined$hash_base;31133114# The format of a table row is: mode list link. Where mode is3115# the mode of the entry, list is the name of the entry, an href,3116# and link is the action links of the entry.31173118print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3119if($t->{'type'}eq"blob") {3120print"<td class=\"list\">".3121$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3122 file_name=>"$basedir$t->{'name'}",%base_key),3123-class=>"list"}, esc_path($t->{'name'}));3124if(S_ISLNK(oct$t->{'mode'})) {3125my$link_target= git_get_link_target($t->{'hash'});3126if($link_target) {3127my$norm_target= normalize_link_target($link_target,$basedir,$hash_base);3128if(defined$norm_target) {3129print" -> ".3130$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3131 file_name=>$norm_target),3132-title =>$norm_target}, esc_path($link_target));3133}else{3134print" -> ". esc_path($link_target);3135}3136}3137}3138print"</td>\n";3139print"<td class=\"link\">";3140print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3141 file_name=>"$basedir$t->{'name'}",%base_key)},3142"blob");3143if($have_blame) {3144print" | ".3145$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3146 file_name=>"$basedir$t->{'name'}",%base_key)},3147"blame");3148}3149if(defined$hash_base) {3150print" | ".3151$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3152 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3153"history");3154}3155print" | ".3156$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3157 file_name=>"$basedir$t->{'name'}")},3158"raw");3159print"</td>\n";31603161}elsif($t->{'type'}eq"tree") {3162print"<td class=\"list\">";3163print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3164 file_name=>"$basedir$t->{'name'}",%base_key)},3165 esc_path($t->{'name'}));3166print"</td>\n";3167print"<td class=\"link\">";3168print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3169 file_name=>"$basedir$t->{'name'}",%base_key)},3170"tree");3171if(defined$hash_base) {3172print" | ".3173$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3174 file_name=>"$basedir$t->{'name'}")},3175"history");3176}3177print"</td>\n";3178}else{3179# unknown object: we can only present history for it3180# (this includes 'commit' object, i.e. submodule support)3181print"<td class=\"list\">".3182 esc_path($t->{'name'}) .3183"</td>\n";3184print"<td class=\"link\">";3185if(defined$hash_base) {3186print$cgi->a({-href => href(action=>"history",3187 hash_base=>$hash_base,3188 file_name=>"$basedir$t->{'name'}")},3189"history");3190}3191print"</td>\n";3192}3193}31943195## ......................................................................3196## functions printing large fragments of HTML31973198# get pre-image filenames for merge (combined) diff3199sub fill_from_file_info {3200my($diff,@parents) =@_;32013202$diff->{'from_file'} = [ ];3203$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3204for(my$i=0;$i<$diff->{'nparents'};$i++) {3205if($diff->{'status'}[$i]eq'R'||3206$diff->{'status'}[$i]eq'C') {3207$diff->{'from_file'}[$i] =3208 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3209}3210}32113212return$diff;3213}32143215# is current raw difftree line of file deletion3216sub is_deleted {3217my$diffinfo=shift;32183219return$diffinfo->{'to_id'}eq('0' x 40);3220}32213222# does patch correspond to [previous] difftree raw line3223# $diffinfo - hashref of parsed raw diff format3224# $patchinfo - hashref of parsed patch diff format3225# (the same keys as in $diffinfo)3226sub is_patch_split {3227my($diffinfo,$patchinfo) =@_;32283229returndefined$diffinfo&&defined$patchinfo3230&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3231}323232333234sub git_difftree_body {3235my($difftree,$hash,@parents) =@_;3236my($parent) =$parents[0];3237my($have_blame) = gitweb_check_feature('blame');3238print"<div class=\"list_head\">\n";3239if($#{$difftree} >10) {3240print(($#{$difftree} +1) ." files changed:\n");3241}3242print"</div>\n";32433244print"<table class=\"".3245(@parents>1?"combined ":"") .3246"diff_tree\">\n";32473248# header only for combined diff in 'commitdiff' view3249my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3250if($has_header) {3251# table header3252print"<thead><tr>\n".3253"<th></th><th></th>\n";# filename, patchN link3254for(my$i=0;$i<@parents;$i++) {3255my$par=$parents[$i];3256print"<th>".3257$cgi->a({-href => href(action=>"commitdiff",3258 hash=>$hash, hash_parent=>$par),3259-title =>'commitdiff to parent number '.3260($i+1) .': '.substr($par,0,7)},3261$i+1) .3262" </th>\n";3263}3264print"</tr></thead>\n<tbody>\n";3265}32663267my$alternate=1;3268my$patchno=0;3269foreachmy$line(@{$difftree}) {3270my$diff= parsed_difftree_line($line);32713272if($alternate) {3273print"<tr class=\"dark\">\n";3274}else{3275print"<tr class=\"light\">\n";3276}3277$alternate^=1;32783279if(exists$diff->{'nparents'}) {# combined diff32803281 fill_from_file_info($diff,@parents)3282unlessexists$diff->{'from_file'};32833284if(!is_deleted($diff)) {3285# file exists in the result (child) commit3286print"<td>".3287$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3288 file_name=>$diff->{'to_file'},3289 hash_base=>$hash),3290-class=>"list"}, esc_path($diff->{'to_file'})) .3291"</td>\n";3292}else{3293print"<td>".3294 esc_path($diff->{'to_file'}) .3295"</td>\n";3296}32973298if($actioneq'commitdiff') {3299# link to patch3300$patchno++;3301print"<td class=\"link\">".3302$cgi->a({-href =>"#patch$patchno"},"patch") .3303" | ".3304"</td>\n";3305}33063307my$has_history=0;3308my$not_deleted=0;3309for(my$i=0;$i<$diff->{'nparents'};$i++) {3310my$hash_parent=$parents[$i];3311my$from_hash=$diff->{'from_id'}[$i];3312my$from_path=$diff->{'from_file'}[$i];3313my$status=$diff->{'status'}[$i];33143315$has_history||= ($statusne'A');3316$not_deleted||= ($statusne'D');33173318if($statuseq'A') {3319print"<td class=\"link\"align=\"right\"> | </td>\n";3320}elsif($statuseq'D') {3321print"<td class=\"link\">".3322$cgi->a({-href => href(action=>"blob",3323 hash_base=>$hash,3324 hash=>$from_hash,3325 file_name=>$from_path)},3326"blob". ($i+1)) .3327" | </td>\n";3328}else{3329if($diff->{'to_id'}eq$from_hash) {3330print"<td class=\"link nochange\">";3331}else{3332print"<td class=\"link\">";3333}3334print$cgi->a({-href => href(action=>"blobdiff",3335 hash=>$diff->{'to_id'},3336 hash_parent=>$from_hash,3337 hash_base=>$hash,3338 hash_parent_base=>$hash_parent,3339 file_name=>$diff->{'to_file'},3340 file_parent=>$from_path)},3341"diff". ($i+1)) .3342" | </td>\n";3343}3344}33453346print"<td class=\"link\">";3347if($not_deleted) {3348print$cgi->a({-href => href(action=>"blob",3349 hash=>$diff->{'to_id'},3350 file_name=>$diff->{'to_file'},3351 hash_base=>$hash)},3352"blob");3353print" | "if($has_history);3354}3355if($has_history) {3356print$cgi->a({-href => href(action=>"history",3357 file_name=>$diff->{'to_file'},3358 hash_base=>$hash)},3359"history");3360}3361print"</td>\n";33623363print"</tr>\n";3364next;# instead of 'else' clause, to avoid extra indent3365}3366# else ordinary diff33673368my($to_mode_oct,$to_mode_str,$to_file_type);3369my($from_mode_oct,$from_mode_str,$from_file_type);3370if($diff->{'to_mode'}ne('0' x 6)) {3371$to_mode_oct=oct$diff->{'to_mode'};3372if(S_ISREG($to_mode_oct)) {# only for regular file3373$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits3374}3375$to_file_type= file_type($diff->{'to_mode'});3376}3377if($diff->{'from_mode'}ne('0' x 6)) {3378$from_mode_oct=oct$diff->{'from_mode'};3379if(S_ISREG($to_mode_oct)) {# only for regular file3380$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits3381}3382$from_file_type= file_type($diff->{'from_mode'});3383}33843385if($diff->{'status'}eq"A") {# created3386my$mode_chng="<span class=\"file_status new\">[new$to_file_type";3387$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;3388$mode_chng.="]</span>";3389print"<td>";3390print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3391 hash_base=>$hash, file_name=>$diff->{'file'}),3392-class=>"list"}, esc_path($diff->{'file'}));3393print"</td>\n";3394print"<td>$mode_chng</td>\n";3395print"<td class=\"link\">";3396if($actioneq'commitdiff') {3397# link to patch3398$patchno++;3399print$cgi->a({-href =>"#patch$patchno"},"patch");3400print" | ";3401}3402print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3403 hash_base=>$hash, file_name=>$diff->{'file'})},3404"blob");3405print"</td>\n";34063407}elsif($diff->{'status'}eq"D") {# deleted3408my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";3409print"<td>";3410print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3411 hash_base=>$parent, file_name=>$diff->{'file'}),3412-class=>"list"}, esc_path($diff->{'file'}));3413print"</td>\n";3414print"<td>$mode_chng</td>\n";3415print"<td class=\"link\">";3416if($actioneq'commitdiff') {3417# link to patch3418$patchno++;3419print$cgi->a({-href =>"#patch$patchno"},"patch");3420print" | ";3421}3422print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3423 hash_base=>$parent, file_name=>$diff->{'file'})},3424"blob") ." | ";3425if($have_blame) {3426print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,3427 file_name=>$diff->{'file'})},3428"blame") ." | ";3429}3430print$cgi->a({-href => href(action=>"history", hash_base=>$parent,3431 file_name=>$diff->{'file'})},3432"history");3433print"</td>\n";34343435}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed3436my$mode_chnge="";3437if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3438$mode_chnge="<span class=\"file_status mode_chnge\">[changed";3439if($from_file_typene$to_file_type) {3440$mode_chnge.=" from$from_file_typeto$to_file_type";3441}3442if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {3443if($from_mode_str&&$to_mode_str) {3444$mode_chnge.=" mode:$from_mode_str->$to_mode_str";3445}elsif($to_mode_str) {3446$mode_chnge.=" mode:$to_mode_str";3447}3448}3449$mode_chnge.="]</span>\n";3450}3451print"<td>";3452print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3453 hash_base=>$hash, file_name=>$diff->{'file'}),3454-class=>"list"}, esc_path($diff->{'file'}));3455print"</td>\n";3456print"<td>$mode_chnge</td>\n";3457print"<td class=\"link\">";3458if($actioneq'commitdiff') {3459# link to patch3460$patchno++;3461print$cgi->a({-href =>"#patch$patchno"},"patch") .3462" | ";3463}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3464# "commit" view and modified file (not onlu mode changed)3465print$cgi->a({-href => href(action=>"blobdiff",3466 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3467 hash_base=>$hash, hash_parent_base=>$parent,3468 file_name=>$diff->{'file'})},3469"diff") .3470" | ";3471}3472print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3473 hash_base=>$hash, file_name=>$diff->{'file'})},3474"blob") ." | ";3475if($have_blame) {3476print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3477 file_name=>$diff->{'file'})},3478"blame") ." | ";3479}3480print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3481 file_name=>$diff->{'file'})},3482"history");3483print"</td>\n";34843485}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied3486my%status_name= ('R'=>'moved','C'=>'copied');3487my$nstatus=$status_name{$diff->{'status'}};3488my$mode_chng="";3489if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3490# mode also for directories, so we cannot use $to_mode_str3491$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);3492}3493print"<td>".3494$cgi->a({-href => href(action=>"blob", hash_base=>$hash,3495 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),3496-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".3497"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".3498$cgi->a({-href => href(action=>"blob", hash_base=>$parent,3499 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),3500-class=>"list"}, esc_path($diff->{'from_file'})) .3501" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".3502"<td class=\"link\">";3503if($actioneq'commitdiff') {3504# link to patch3505$patchno++;3506print$cgi->a({-href =>"#patch$patchno"},"patch") .3507" | ";3508}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3509# "commit" view and modified file (not only pure rename or copy)3510print$cgi->a({-href => href(action=>"blobdiff",3511 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3512 hash_base=>$hash, hash_parent_base=>$parent,3513 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},3514"diff") .3515" | ";3516}3517print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3518 hash_base=>$parent, file_name=>$diff->{'to_file'})},3519"blob") ." | ";3520if($have_blame) {3521print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3522 file_name=>$diff->{'to_file'})},3523"blame") ." | ";3524}3525print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3526 file_name=>$diff->{'to_file'})},3527"history");3528print"</td>\n";35293530}# we should not encounter Unmerged (U) or Unknown (X) status3531print"</tr>\n";3532}3533print"</tbody>"if$has_header;3534print"</table>\n";3535}35363537sub git_patchset_body {3538my($fd,$difftree,$hash,@hash_parents) =@_;3539my($hash_parent) =$hash_parents[0];35403541my$is_combined= (@hash_parents>1);3542my$patch_idx=0;3543my$patch_number=0;3544my$patch_line;3545my$diffinfo;3546my$to_name;3547my(%from,%to);35483549print"<div class=\"patchset\">\n";35503551# skip to first patch3552while($patch_line= <$fd>) {3553chomp$patch_line;35543555last if($patch_line=~m/^diff /);3556}35573558 PATCH:3559while($patch_line) {35603561# parse "git diff" header line3562if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {3563# $1 is from_name, which we do not use3564$to_name= unquote($2);3565$to_name=~s!^b/!!;3566}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {3567# $1 is 'cc' or 'combined', which we do not use3568$to_name= unquote($2);3569}else{3570$to_name=undef;3571}35723573# check if current patch belong to current raw line3574# and parse raw git-diff line if needed3575if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {3576# this is continuation of a split patch3577print"<div class=\"patch cont\">\n";3578}else{3579# advance raw git-diff output if needed3580$patch_idx++ifdefined$diffinfo;35813582# read and prepare patch information3583$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);35843585# compact combined diff output can have some patches skipped3586# find which patch (using pathname of result) we are at now;3587if($is_combined) {3588while($to_namene$diffinfo->{'to_file'}) {3589print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".3590 format_diff_cc_simplified($diffinfo,@hash_parents) .3591"</div>\n";# class="patch"35923593$patch_idx++;3594$patch_number++;35953596last if$patch_idx>$#$difftree;3597$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);3598}3599}36003601# modifies %from, %to hashes3602 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);36033604# this is first patch for raw difftree line with $patch_idx index3605# we index @$difftree array from 0, but number patches from 13606print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";3607}36083609# git diff header3610#assert($patch_line =~ m/^diff /) if DEBUG;3611#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed3612$patch_number++;3613# print "git diff" header3614print format_git_diff_header_line($patch_line,$diffinfo,3615 \%from, \%to);36163617# print extended diff header3618print"<div class=\"diff extended_header\">\n";3619 EXTENDED_HEADER:3620while($patch_line= <$fd>) {3621chomp$patch_line;36223623last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);36243625print format_extended_diff_header_line($patch_line,$diffinfo,3626 \%from, \%to);3627}3628print"</div>\n";# class="diff extended_header"36293630# from-file/to-file diff header3631if(!$patch_line) {3632print"</div>\n";# class="patch"3633last PATCH;3634}3635next PATCH if($patch_line=~m/^diff /);3636#assert($patch_line =~ m/^---/) if DEBUG;36373638my$last_patch_line=$patch_line;3639$patch_line= <$fd>;3640chomp$patch_line;3641#assert($patch_line =~ m/^\+\+\+/) if DEBUG;36423643print format_diff_from_to_header($last_patch_line,$patch_line,3644$diffinfo, \%from, \%to,3645@hash_parents);36463647# the patch itself3648 LINE:3649while($patch_line= <$fd>) {3650chomp$patch_line;36513652next PATCH if($patch_line=~m/^diff /);36533654print format_diff_line($patch_line, \%from, \%to);3655}36563657}continue{3658print"</div>\n";# class="patch"3659}36603661# for compact combined (--cc) format, with chunk and patch simpliciaction3662# patchset might be empty, but there might be unprocessed raw lines3663for(++$patch_idxif$patch_number>0;3664$patch_idx<@$difftree;3665++$patch_idx) {3666# read and prepare patch information3667$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);36683669# generate anchor for "patch" links in difftree / whatchanged part3670print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".3671 format_diff_cc_simplified($diffinfo,@hash_parents) .3672"</div>\n";# class="patch"36733674$patch_number++;3675}36763677if($patch_number==0) {3678if(@hash_parents>1) {3679print"<div class=\"diff nodifferences\">Trivial merge</div>\n";3680}else{3681print"<div class=\"diff nodifferences\">No differences found</div>\n";3682}3683}36843685print"</div>\n";# class="patchset"3686}36873688# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36893690# fills project list info (age, description, owner, forks) for each3691# project in the list, removing invalid projects from returned list3692# NOTE: modifies $projlist, but does not remove entries from it3693sub fill_project_list_info {3694my($projlist,$check_forks) =@_;3695my@projects;36963697my$show_ctags= gitweb_check_feature('ctags');3698 PROJECT:3699foreachmy$pr(@$projlist) {3700my(@activity) = git_get_last_activity($pr->{'path'});3701unless(@activity) {3702next PROJECT;3703}3704($pr->{'age'},$pr->{'age_string'}) =@activity;3705if(!defined$pr->{'descr'}) {3706my$descr= git_get_project_description($pr->{'path'}) ||"";3707$descr= to_utf8($descr);3708$pr->{'descr_long'} =$descr;3709$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);3710}3711if(!defined$pr->{'owner'}) {3712$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";3713}3714if($check_forks) {3715my$pname=$pr->{'path'};3716if(($pname=~s/\.git$//) &&3717($pname!~/\/$/) &&3718(-d "$projectroot/$pname")) {3719$pr->{'forks'} ="-d$projectroot/$pname";3720}else{3721$pr->{'forks'} =0;3722}3723}3724$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});3725push@projects,$pr;3726}37273728return@projects;3729}37303731# print 'sort by' <th> element, generating 'sort by $name' replay link3732# if that order is not selected3733sub print_sort_th {3734my($name,$order,$header) =@_;3735$header||=ucfirst($name);37363737if($ordereq$name) {3738print"<th>$header</th>\n";3739}else{3740print"<th>".3741$cgi->a({-href => href(-replay=>1, order=>$name),3742-class=>"header"},$header) .3743"</th>\n";3744}3745}37463747sub git_project_list_body {3748# actually uses global variable $project3749my($projlist,$order,$from,$to,$extra,$no_header) =@_;37503751my($check_forks) = gitweb_check_feature('forks');3752my@projects= fill_project_list_info($projlist,$check_forks);37533754$order||=$default_projects_order;3755$from=0unlessdefined$from;3756$to=$#projectsif(!defined$to||$#projects<$to);37573758my%order_info= (3759 project => { key =>'path', type =>'str'},3760 descr => { key =>'descr_long', type =>'str'},3761 owner => { key =>'owner', type =>'str'},3762 age => { key =>'age', type =>'num'}3763);3764my$oi=$order_info{$order};3765if($oi->{'type'}eq'str') {3766@projects=sort{$a->{$oi->{'key'}}cmp$b->{$oi->{'key'}}}@projects;3767}else{3768@projects=sort{$a->{$oi->{'key'}} <=>$b->{$oi->{'key'}}}@projects;3769}37703771my$show_ctags= gitweb_check_feature('ctags');3772if($show_ctags) {3773my%ctags;3774foreachmy$p(@projects) {3775foreachmy$ct(keys%{$p->{'ctags'}}) {3776$ctags{$ct} +=$p->{'ctags'}->{$ct};3777}3778}3779my$cloud= git_populate_project_tagcloud(\%ctags);3780print git_show_project_tagcloud($cloud,64);3781}37823783print"<table class=\"project_list\">\n";3784unless($no_header) {3785print"<tr>\n";3786if($check_forks) {3787print"<th></th>\n";3788}3789 print_sort_th('project',$order,'Project');3790 print_sort_th('descr',$order,'Description');3791 print_sort_th('owner',$order,'Owner');3792 print_sort_th('age',$order,'Last Change');3793print"<th></th>\n".# for links3794"</tr>\n";3795}3796my$alternate=1;3797my$tagfilter=$cgi->param('by_tag');3798for(my$i=$from;$i<=$to;$i++) {3799my$pr=$projects[$i];38003801next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};3802next if$searchtextand not$pr->{'path'} =~/$searchtext/3803and not$pr->{'descr_long'} =~/$searchtext/;3804# Weed out forks or non-matching entries of search3805if($check_forks) {3806my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;3807$forkbase="^$forkbase"if$forkbase;3808next ifnot$searchtextand not$tagfilterand$show_ctags3809and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe3810}38113812if($alternate) {3813print"<tr class=\"dark\">\n";3814}else{3815print"<tr class=\"light\">\n";3816}3817$alternate^=1;3818if($check_forks) {3819print"<td>";3820if($pr->{'forks'}) {3821print"<!--$pr->{'forks'} -->\n";3822print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");3823}3824print"</td>\n";3825}3826print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),3827-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".3828"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),3829-class=>"list", -title =>$pr->{'descr_long'}},3830 esc_html($pr->{'descr'})) ."</td>\n".3831"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";3832print"<td class=\"". age_class($pr->{'age'}) ."\">".3833(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".3834"<td class=\"link\">".3835$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".3836$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".3837$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".3838$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .3839($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .3840"</td>\n".3841"</tr>\n";3842}3843if(defined$extra) {3844print"<tr>\n";3845if($check_forks) {3846print"<td></td>\n";3847}3848print"<td colspan=\"5\">$extra</td>\n".3849"</tr>\n";3850}3851print"</table>\n";3852}38533854sub git_shortlog_body {3855# uses global variable $project3856my($commitlist,$from,$to,$refs,$extra) =@_;38573858$from=0unlessdefined$from;3859$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);38603861print"<table class=\"shortlog\">\n";3862my$alternate=1;3863for(my$i=$from;$i<=$to;$i++) {3864my%co= %{$commitlist->[$i]};3865my$commit=$co{'id'};3866my$ref= format_ref_marker($refs,$commit);3867if($alternate) {3868print"<tr class=\"dark\">\n";3869}else{3870print"<tr class=\"light\">\n";3871}3872$alternate^=1;3873my$author= chop_and_escape_str($co{'author_name'},10);3874# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .3875print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".3876"<td><i>".$author."</i></td>\n".3877"<td>";3878print format_subject_html($co{'title'},$co{'title_short'},3879 href(action=>"commit", hash=>$commit),$ref);3880print"</td>\n".3881"<td class=\"link\">".3882$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".3883$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".3884$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");3885my$snapshot_links= format_snapshot_links($commit);3886if(defined$snapshot_links) {3887print" | ".$snapshot_links;3888}3889print"</td>\n".3890"</tr>\n";3891}3892if(defined$extra) {3893print"<tr>\n".3894"<td colspan=\"4\">$extra</td>\n".3895"</tr>\n";3896}3897print"</table>\n";3898}38993900sub git_history_body {3901# Warning: assumes constant type (blob or tree) during history3902my($commitlist,$from,$to,$refs,$hash_base,$ftype,$extra) =@_;39033904$from=0unlessdefined$from;3905$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});39063907print"<table class=\"history\">\n";3908my$alternate=1;3909for(my$i=$from;$i<=$to;$i++) {3910my%co= %{$commitlist->[$i]};3911if(!%co) {3912next;3913}3914my$commit=$co{'id'};39153916my$ref= format_ref_marker($refs,$commit);39173918if($alternate) {3919print"<tr class=\"dark\">\n";3920}else{3921print"<tr class=\"light\">\n";3922}3923$alternate^=1;3924# shortlog uses chop_str($co{'author_name'}, 10)3925my$author= chop_and_escape_str($co{'author_name'},15,3);3926print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".3927"<td><i>".$author."</i></td>\n".3928"<td>";3929# originally git_history used chop_str($co{'title'}, 50)3930print format_subject_html($co{'title'},$co{'title_short'},3931 href(action=>"commit", hash=>$commit),$ref);3932print"</td>\n".3933"<td class=\"link\">".3934$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".3935$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");39363937if($ftypeeq'blob') {3938my$blob_current= git_get_hash_by_path($hash_base,$file_name);3939my$blob_parent= git_get_hash_by_path($commit,$file_name);3940if(defined$blob_current&&defined$blob_parent&&3941$blob_currentne$blob_parent) {3942print" | ".3943$cgi->a({-href => href(action=>"blobdiff",3944 hash=>$blob_current, hash_parent=>$blob_parent,3945 hash_base=>$hash_base, hash_parent_base=>$commit,3946 file_name=>$file_name)},3947"diff to current");3948}3949}3950print"</td>\n".3951"</tr>\n";3952}3953if(defined$extra) {3954print"<tr>\n".3955"<td colspan=\"4\">$extra</td>\n".3956"</tr>\n";3957}3958print"</table>\n";3959}39603961sub git_tags_body {3962# uses global variable $project3963my($taglist,$from,$to,$extra) =@_;3964$from=0unlessdefined$from;3965$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);39663967print"<table class=\"tags\">\n";3968my$alternate=1;3969for(my$i=$from;$i<=$to;$i++) {3970my$entry=$taglist->[$i];3971my%tag=%$entry;3972my$comment=$tag{'subject'};3973my$comment_short;3974if(defined$comment) {3975$comment_short= chop_str($comment,30,5);3976}3977if($alternate) {3978print"<tr class=\"dark\">\n";3979}else{3980print"<tr class=\"light\">\n";3981}3982$alternate^=1;3983if(defined$tag{'age'}) {3984print"<td><i>$tag{'age'}</i></td>\n";3985}else{3986print"<td></td>\n";3987}3988print"<td>".3989$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),3990-class=>"list name"}, esc_html($tag{'name'})) .3991"</td>\n".3992"<td>";3993if(defined$comment) {3994print format_subject_html($comment,$comment_short,3995 href(action=>"tag", hash=>$tag{'id'}));3996}3997print"</td>\n".3998"<td class=\"selflink\">";3999if($tag{'type'}eq"tag") {4000print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");4001}else{4002print" ";4003}4004print"</td>\n".4005"<td class=\"link\">"." | ".4006$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});4007if($tag{'reftype'}eq"commit") {4008print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .4009" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");4010}elsif($tag{'reftype'}eq"blob") {4011print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");4012}4013print"</td>\n".4014"</tr>";4015}4016if(defined$extra) {4017print"<tr>\n".4018"<td colspan=\"5\">$extra</td>\n".4019"</tr>\n";4020}4021print"</table>\n";4022}40234024sub git_heads_body {4025# uses global variable $project4026my($headlist,$head,$from,$to,$extra) =@_;4027$from=0unlessdefined$from;4028$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);40294030print"<table class=\"heads\">\n";4031my$alternate=1;4032for(my$i=$from;$i<=$to;$i++) {4033my$entry=$headlist->[$i];4034my%ref=%$entry;4035my$curr=$ref{'id'}eq$head;4036if($alternate) {4037print"<tr class=\"dark\">\n";4038}else{4039print"<tr class=\"light\">\n";4040}4041$alternate^=1;4042print"<td><i>$ref{'age'}</i></td>\n".4043($curr?"<td class=\"current_head\">":"<td>") .4044$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4045-class=>"list name"},esc_html($ref{'name'})) .4046"</td>\n".4047"<td class=\"link\">".4048$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4049$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4050$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4051"</td>\n".4052"</tr>";4053}4054if(defined$extra) {4055print"<tr>\n".4056"<td colspan=\"3\">$extra</td>\n".4057"</tr>\n";4058}4059print"</table>\n";4060}40614062sub git_search_grep_body {4063my($commitlist,$from,$to,$extra) =@_;4064$from=0unlessdefined$from;4065$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);40664067print"<table class=\"commit_search\">\n";4068my$alternate=1;4069for(my$i=$from;$i<=$to;$i++) {4070my%co= %{$commitlist->[$i]};4071if(!%co) {4072next;4073}4074my$commit=$co{'id'};4075if($alternate) {4076print"<tr class=\"dark\">\n";4077}else{4078print"<tr class=\"light\">\n";4079}4080$alternate^=1;4081my$author= chop_and_escape_str($co{'author_name'},15,5);4082print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4083"<td><i>".$author."</i></td>\n".4084"<td>".4085$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4086-class=>"list subject"},4087 chop_and_escape_str($co{'title'},50) ."<br/>");4088my$comment=$co{'comment'};4089foreachmy$line(@$comment) {4090if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4091my($lead,$match,$trail) = ($1,$2,$3);4092$match= chop_str($match,70,5,'center');4093my$contextlen=int((80-length($match))/2);4094$contextlen=30if($contextlen>30);4095$lead= chop_str($lead,$contextlen,10,'left');4096$trail= chop_str($trail,$contextlen,10,'right');40974098$lead= esc_html($lead);4099$match= esc_html($match);4100$trail= esc_html($trail);41014102print"$lead<span class=\"match\">$match</span>$trail<br />";4103}4104}4105print"</td>\n".4106"<td class=\"link\">".4107$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4108" | ".4109$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4110" | ".4111$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4112print"</td>\n".4113"</tr>\n";4114}4115if(defined$extra) {4116print"<tr>\n".4117"<td colspan=\"3\">$extra</td>\n".4118"</tr>\n";4119}4120print"</table>\n";4121}41224123## ======================================================================4124## ======================================================================4125## actions41264127sub git_project_list {4128my$order=$cgi->param('o');4129if(defined$order&&$order!~m/none|project|descr|owner|age/) {4130 die_error(400,"Unknown order parameter");4131}41324133my@list= git_get_projects_list();4134if(!@list) {4135 die_error(404,"No projects found");4136}41374138 git_header_html();4139if(-f $home_text) {4140print"<div class=\"index_include\">\n";4141open(my$fd,$home_text);4142print<$fd>;4143close$fd;4144print"</div>\n";4145}4146print$cgi->startform(-method=>"get") .4147"<p class=\"projsearch\">Search:\n".4148$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4149"</p>".4150$cgi->end_form() ."\n";4151 git_project_list_body(\@list,$order);4152 git_footer_html();4153}41544155sub git_forks {4156my$order=$cgi->param('o');4157if(defined$order&&$order!~m/none|project|descr|owner|age/) {4158 die_error(400,"Unknown order parameter");4159}41604161my@list= git_get_projects_list($project);4162if(!@list) {4163 die_error(404,"No forks found");4164}41654166 git_header_html();4167 git_print_page_nav('','');4168 git_print_header_div('summary',"$projectforks");4169 git_project_list_body(\@list,$order);4170 git_footer_html();4171}41724173sub git_project_index {4174my@projects= git_get_projects_list($project);41754176print$cgi->header(4177-type =>'text/plain',4178-charset =>'utf-8',4179-content_disposition =>'inline; filename="index.aux"');41804181foreachmy$pr(@projects) {4182if(!exists$pr->{'owner'}) {4183$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4184}41854186my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4187# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4188$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4189$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4190$path=~s/ /\+/g;4191$owner=~s/ /\+/g;41924193print"$path$owner\n";4194}4195}41964197sub git_summary {4198my$descr= git_get_project_description($project) ||"none";4199my%co= parse_commit("HEAD");4200my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4201my$head=$co{'id'};42024203my$owner= git_get_project_owner($project);42044205my$refs= git_get_references();4206# These get_*_list functions return one more to allow us to see if4207# there are more ...4208my@taglist= git_get_tags_list(16);4209my@headlist= git_get_heads_list(16);4210my@forklist;4211my($check_forks) = gitweb_check_feature('forks');42124213if($check_forks) {4214@forklist= git_get_projects_list($project);4215}42164217 git_header_html();4218 git_print_page_nav('summary','',$head);42194220print"<div class=\"title\"> </div>\n";4221print"<table class=\"projects_list\">\n".4222"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4223"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4224if(defined$cd{'rfc2822'}) {4225print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4226}42274228# use per project git URL list in $projectroot/$project/cloneurl4229# or make project git URL from git base URL and project name4230my$url_tag="URL";4231my@url_list= git_get_project_url_list($project);4232@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4233foreachmy$git_url(@url_list) {4234next unless$git_url;4235print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4236$url_tag="";4237}42384239# Tag cloud4240my$show_ctags= (gitweb_check_feature('ctags'))[0];4241if($show_ctags) {4242my$ctags= git_get_project_ctags($project);4243my$cloud= git_populate_project_tagcloud($ctags);4244print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4245print"</td>\n<td>"unless%$ctags;4246print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4247print"</td>\n<td>"if%$ctags;4248print git_show_project_tagcloud($cloud,48);4249print"</td></tr>";4250}42514252print"</table>\n";42534254if(-s "$projectroot/$project/README.html") {4255if(open my$fd,"$projectroot/$project/README.html") {4256print"<div class=\"title\">readme</div>\n".4257"<div class=\"readme\">\n";4258print$_while(<$fd>);4259print"\n</div>\n";# class="readme"4260close$fd;4261}4262}42634264# we need to request one more than 16 (0..15) to check if4265# those 16 are all4266my@commitlist=$head? parse_commits($head,17) : ();4267if(@commitlist) {4268 git_print_header_div('shortlog');4269 git_shortlog_body(\@commitlist,0,15,$refs,4270$#commitlist<=15?undef:4271$cgi->a({-href => href(action=>"shortlog")},"..."));4272}42734274if(@taglist) {4275 git_print_header_div('tags');4276 git_tags_body(\@taglist,0,15,4277$#taglist<=15?undef:4278$cgi->a({-href => href(action=>"tags")},"..."));4279}42804281if(@headlist) {4282 git_print_header_div('heads');4283 git_heads_body(\@headlist,$head,0,15,4284$#headlist<=15?undef:4285$cgi->a({-href => href(action=>"heads")},"..."));4286}42874288if(@forklist) {4289 git_print_header_div('forks');4290 git_project_list_body(\@forklist,'age',0,15,4291$#forklist<=15?undef:4292$cgi->a({-href => href(action=>"forks")},"..."),4293'no_header');4294}42954296 git_footer_html();4297}42984299sub git_tag {4300my$head= git_get_head_hash($project);4301 git_header_html();4302 git_print_page_nav('','',$head,undef,$head);4303my%tag= parse_tag($hash);43044305if(!%tag) {4306 die_error(404,"Unknown tag object");4307}43084309 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4310print"<div class=\"title_text\">\n".4311"<table class=\"object_header\">\n".4312"<tr>\n".4313"<td>object</td>\n".4314"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4315$tag{'object'}) ."</td>\n".4316"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4317$tag{'type'}) ."</td>\n".4318"</tr>\n";4319if(defined($tag{'author'})) {4320my%ad= parse_date($tag{'epoch'},$tag{'tz'});4321print"<tr><td>author</td><td>". esc_html($tag{'author'}) ."</td></tr>\n";4322print"<tr><td></td><td>".$ad{'rfc2822'} .4323sprintf(" (%02d:%02d%s)",$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'}) .4324"</td></tr>\n";4325}4326print"</table>\n\n".4327"</div>\n";4328print"<div class=\"page_body\">";4329my$comment=$tag{'comment'};4330foreachmy$line(@$comment) {4331chomp$line;4332print esc_html($line, -nbsp=>1) ."<br/>\n";4333}4334print"</div>\n";4335 git_footer_html();4336}43374338sub git_blame {4339my$fd;4340my$ftype;43414342 gitweb_check_feature('blame')4343or die_error(403,"Blame view not allowed");43444345 die_error(400,"No file name given")unless$file_name;4346$hash_base||= git_get_head_hash($project);4347 die_error(404,"Couldn't find base commit")unless($hash_base);4348my%co= parse_commit($hash_base)4349or die_error(404,"Commit not found");4350if(!defined$hash) {4351$hash= git_get_hash_by_path($hash_base,$file_name,"blob")4352or die_error(404,"Error looking up file");4353}4354$ftype= git_get_type($hash);4355if($ftype!~"blob") {4356 die_error(400,"Object is not a blob");4357}4358open($fd,"-|", git_cmd(),"blame",'-p','--',4359$file_name,$hash_base)4360or die_error(500,"Open git-blame failed");4361 git_header_html();4362my$formats_nav=4363$cgi->a({-href => href(action=>"blob", -replay=>1)},4364"blob") .4365" | ".4366$cgi->a({-href => href(action=>"history", -replay=>1)},4367"history") .4368" | ".4369$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},4370"HEAD");4371 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4372 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4373 git_print_page_path($file_name,$ftype,$hash_base);4374my@rev_color= (qw(light2 dark2));4375my$num_colors=scalar(@rev_color);4376my$current_color=0;4377my$last_rev;4378print<<HTML;4379<div class="page_body">4380<table class="blame">4381<tr><th>Commit</th><th>Line</th><th>Data</th></tr>4382HTML4383my%metainfo= ();4384while(1) {4385$_= <$fd>;4386last unlessdefined$_;4387my($full_rev,$orig_lineno,$lineno,$group_size) =4388/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;4389if(!exists$metainfo{$full_rev}) {4390$metainfo{$full_rev} = {};4391}4392my$meta=$metainfo{$full_rev};4393while(<$fd>) {4394last if(s/^\t//);4395if(/^(\S+) (.*)$/) {4396$meta->{$1} =$2;4397}4398}4399my$data=$_;4400chomp$data;4401my$rev=substr($full_rev,0,8);4402my$author=$meta->{'author'};4403my%date= parse_date($meta->{'author-time'},4404$meta->{'author-tz'});4405my$date=$date{'iso-tz'};4406if($group_size) {4407$current_color= ++$current_color%$num_colors;4408}4409print"<tr class=\"$rev_color[$current_color]\">\n";4410if($group_size) {4411print"<td class=\"sha1\"";4412print" title=\"". esc_html($author) .",$date\"";4413print" rowspan=\"$group_size\""if($group_size>1);4414print">";4415print$cgi->a({-href => href(action=>"commit",4416 hash=>$full_rev,4417 file_name=>$file_name)},4418 esc_html($rev));4419print"</td>\n";4420}4421open(my$dd,"-|", git_cmd(),"rev-parse","$full_rev^")4422or die_error(500,"Open git-rev-parse failed");4423my$parent_commit= <$dd>;4424close$dd;4425chomp($parent_commit);4426my$blamed= href(action =>'blame',4427 file_name =>$meta->{'filename'},4428 hash_base =>$parent_commit);4429print"<td class=\"linenr\">";4430print$cgi->a({ -href =>"$blamed#l$orig_lineno",4431-id =>"l$lineno",4432-class=>"linenr"},4433 esc_html($lineno));4434print"</td>";4435print"<td class=\"pre\">". esc_html($data) ."</td>\n";4436print"</tr>\n";4437}4438print"</table>\n";4439print"</div>";4440close$fd4441or print"Reading blob failed\n";4442 git_footer_html();4443}44444445sub git_tags {4446my$head= git_get_head_hash($project);4447 git_header_html();4448 git_print_page_nav('','',$head,undef,$head);4449 git_print_header_div('summary',$project);44504451my@tagslist= git_get_tags_list();4452if(@tagslist) {4453 git_tags_body(\@tagslist);4454}4455 git_footer_html();4456}44574458sub git_heads {4459my$head= git_get_head_hash($project);4460 git_header_html();4461 git_print_page_nav('','',$head,undef,$head);4462 git_print_header_div('summary',$project);44634464my@headslist= git_get_heads_list();4465if(@headslist) {4466 git_heads_body(\@headslist,$head);4467}4468 git_footer_html();4469}44704471sub git_blob_plain {4472my$type=shift;4473my$expires;44744475if(!defined$hash) {4476if(defined$file_name) {4477my$base=$hash_base|| git_get_head_hash($project);4478$hash= git_get_hash_by_path($base,$file_name,"blob")4479or die_error(404,"Cannot find file");4480}else{4481 die_error(400,"No file name defined");4482}4483}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4484# blobs defined by non-textual hash id's can be cached4485$expires="+1d";4486}44874488open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4489or die_error(500,"Open git-cat-file blob '$hash' failed");44904491# content-type (can include charset)4492$type= blob_contenttype($fd,$file_name,$type);44934494# "save as" filename, even when no $file_name is given4495my$save_as="$hash";4496if(defined$file_name) {4497$save_as=$file_name;4498}elsif($type=~m/^text\//) {4499$save_as.='.txt';4500}45014502print$cgi->header(4503-type =>$type,4504-expires =>$expires,4505-content_disposition =>'inline; filename="'.$save_as.'"');4506undef$/;4507binmode STDOUT,':raw';4508print<$fd>;4509binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi4510$/="\n";4511close$fd;4512}45134514sub git_blob {4515my$expires;45164517if(!defined$hash) {4518if(defined$file_name) {4519my$base=$hash_base|| git_get_head_hash($project);4520$hash= git_get_hash_by_path($base,$file_name,"blob")4521or die_error(404,"Cannot find file");4522}else{4523 die_error(400,"No file name defined");4524}4525}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4526# blobs defined by non-textual hash id's can be cached4527$expires="+1d";4528}45294530my($have_blame) = gitweb_check_feature('blame');4531open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4532or die_error(500,"Couldn't cat$file_name,$hash");4533my$mimetype= blob_mimetype($fd,$file_name);4534if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {4535close$fd;4536return git_blob_plain($mimetype);4537}4538# we can have blame only for text/* mimetype4539$have_blame&&= ($mimetype=~m!^text/!);45404541 git_header_html(undef,$expires);4542my$formats_nav='';4543if(defined$hash_base&& (my%co= parse_commit($hash_base))) {4544if(defined$file_name) {4545if($have_blame) {4546$formats_nav.=4547$cgi->a({-href => href(action=>"blame", -replay=>1)},4548"blame") .4549" | ";4550}4551$formats_nav.=4552$cgi->a({-href => href(action=>"history", -replay=>1)},4553"history") .4554" | ".4555$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},4556"raw") .4557" | ".4558$cgi->a({-href => href(action=>"blob",4559 hash_base=>"HEAD", file_name=>$file_name)},4560"HEAD");4561}else{4562$formats_nav.=4563$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},4564"raw");4565}4566 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4567 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4568}else{4569print"<div class=\"page_nav\">\n".4570"<br/><br/></div>\n".4571"<div class=\"title\">$hash</div>\n";4572}4573 git_print_page_path($file_name,"blob",$hash_base);4574print"<div class=\"page_body\">\n";4575if($mimetype=~m!^image/!) {4576print qq!<img type="$mimetype"!;4577if($file_name) {4578print qq! alt="$file_name" title="$file_name"!;4579}4580print qq! src="! .4581 href(action=>"blob_plain", hash=>$hash,4582 hash_base=>$hash_base, file_name=>$file_name) .4583 qq!"/>\n!;4584}else{4585my$nr;4586while(my$line= <$fd>) {4587chomp$line;4588$nr++;4589$line= untabify($line);4590printf"<div class=\"pre\"><a id=\"l%i\"href=\"#l%i\"class=\"linenr\">%4i</a>%s</div>\n",4591$nr,$nr,$nr, esc_html($line, -nbsp=>1);4592}4593}4594close$fd4595or print"Reading blob failed.\n";4596print"</div>";4597 git_footer_html();4598}45994600sub git_tree {4601if(!defined$hash_base) {4602$hash_base="HEAD";4603}4604if(!defined$hash) {4605if(defined$file_name) {4606$hash= git_get_hash_by_path($hash_base,$file_name,"tree");4607}else{4608$hash=$hash_base;4609}4610}4611 die_error(404,"No such tree")unlessdefined($hash);4612$/="\0";4613open my$fd,"-|", git_cmd(),"ls-tree",'-z',$hash4614or die_error(500,"Open git-ls-tree failed");4615my@entries=map{chomp;$_} <$fd>;4616close$fdor die_error(404,"Reading tree failed");4617$/="\n";46184619my$refs= git_get_references();4620my$ref= format_ref_marker($refs,$hash_base);4621 git_header_html();4622my$basedir='';4623my($have_blame) = gitweb_check_feature('blame');4624if(defined$hash_base&& (my%co= parse_commit($hash_base))) {4625my@views_nav= ();4626if(defined$file_name) {4627push@views_nav,4628$cgi->a({-href => href(action=>"history", -replay=>1)},4629"history"),4630$cgi->a({-href => href(action=>"tree",4631 hash_base=>"HEAD", file_name=>$file_name)},4632"HEAD"),4633}4634my$snapshot_links= format_snapshot_links($hash);4635if(defined$snapshot_links) {4636# FIXME: Should be available when we have no hash base as well.4637push@views_nav,$snapshot_links;4638}4639 git_print_page_nav('tree','',$hash_base,undef,undef,join(' | ',@views_nav));4640 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);4641}else{4642undef$hash_base;4643print"<div class=\"page_nav\">\n";4644print"<br/><br/></div>\n";4645print"<div class=\"title\">$hash</div>\n";4646}4647if(defined$file_name) {4648$basedir=$file_name;4649if($basedirne''&&substr($basedir, -1)ne'/') {4650$basedir.='/';4651}4652 git_print_page_path($file_name,'tree',$hash_base);4653}4654print"<div class=\"page_body\">\n";4655print"<table class=\"tree\">\n";4656my$alternate=1;4657# '..' (top directory) link if possible4658if(defined$hash_base&&4659defined$file_name&&$file_name=~m![^/]+$!) {4660if($alternate) {4661print"<tr class=\"dark\">\n";4662}else{4663print"<tr class=\"light\">\n";4664}4665$alternate^=1;46664667my$up=$file_name;4668$up=~s!/?[^/]+$!!;4669undef$upunless$up;4670# based on git_print_tree_entry4671print'<td class="mode">'. mode_str('040000') ."</td>\n";4672print'<td class="list">';4673print$cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,4674 file_name=>$up)},4675"..");4676print"</td>\n";4677print"<td class=\"link\"></td>\n";46784679print"</tr>\n";4680}4681foreachmy$line(@entries) {4682my%t= parse_ls_tree_line($line, -z =>1);46834684if($alternate) {4685print"<tr class=\"dark\">\n";4686}else{4687print"<tr class=\"light\">\n";4688}4689$alternate^=1;46904691 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);46924693print"</tr>\n";4694}4695print"</table>\n".4696"</div>";4697 git_footer_html();4698}46994700sub git_snapshot {4701my@supported_fmts= gitweb_check_feature('snapshot');4702@supported_fmts= filter_snapshot_fmts(@supported_fmts);47034704my$format=$cgi->param('sf');4705if(!@supported_fmts) {4706 die_error(403,"Snapshots not allowed");4707}4708# default to first supported snapshot format4709$format||=$supported_fmts[0];4710if($format!~m/^[a-z0-9]+$/) {4711 die_error(400,"Invalid snapshot format parameter");4712}elsif(!exists($known_snapshot_formats{$format})) {4713 die_error(400,"Unknown snapshot format");4714}elsif(!grep($_eq$format,@supported_fmts)) {4715 die_error(403,"Unsupported snapshot format");4716}47174718if(!defined$hash) {4719$hash= git_get_head_hash($project);4720}47214722my$name=$project;4723$name=~ s,([^/])/*\.git$,$1,;4724$name= basename($name);4725my$filename= to_utf8($name);4726$name=~s/\047/\047\\\047\047/g;4727my$cmd;4728$filename.="-$hash$known_snapshot_formats{$format}{'suffix'}";4729$cmd= quote_command(4730 git_cmd(),'archive',4731"--format=$known_snapshot_formats{$format}{'format'}",4732"--prefix=$name/",$hash);4733if(exists$known_snapshot_formats{$format}{'compressor'}) {4734$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});4735}47364737print$cgi->header(4738-type =>$known_snapshot_formats{$format}{'type'},4739-content_disposition =>'inline; filename="'."$filename".'"',4740-status =>'200 OK');47414742open my$fd,"-|",$cmd4743or die_error(500,"Execute git-archive failed");4744binmode STDOUT,':raw';4745print<$fd>;4746binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi4747close$fd;4748}47494750sub git_log {4751my$head= git_get_head_hash($project);4752if(!defined$hash) {4753$hash=$head;4754}4755if(!defined$page) {4756$page=0;4757}4758my$refs= git_get_references();47594760my@commitlist= parse_commits($hash,101, (100*$page));47614762my$paging_nav= format_paging_nav('log',$hash,$head,$page,$#commitlist>=100);47634764 git_header_html();4765 git_print_page_nav('log','',$hash,undef,undef,$paging_nav);47664767if(!@commitlist) {4768my%co= parse_commit($hash);47694770 git_print_header_div('summary',$project);4771print"<div class=\"page_body\"> Last change$co{'age_string'}.<br/><br/></div>\n";4772}4773my$to= ($#commitlist>=99) ? (99) : ($#commitlist);4774for(my$i=0;$i<=$to;$i++) {4775my%co= %{$commitlist[$i]};4776next if!%co;4777my$commit=$co{'id'};4778my$ref= format_ref_marker($refs,$commit);4779my%ad= parse_date($co{'author_epoch'});4780 git_print_header_div('commit',4781"<span class=\"age\">$co{'age_string'}</span>".4782 esc_html($co{'title'}) .$ref,4783$commit);4784print"<div class=\"title_text\">\n".4785"<div class=\"log_link\">\n".4786$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .4787" | ".4788$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .4789" | ".4790$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .4791"<br/>\n".4792"</div>\n".4793"<i>". esc_html($co{'author_name'}) ." [$ad{'rfc2822'}]</i><br/>\n".4794"</div>\n";47954796print"<div class=\"log_body\">\n";4797 git_print_log($co{'comment'}, -final_empty_line=>1);4798print"</div>\n";4799}4800if($#commitlist>=100) {4801print"<div class=\"page_nav\">\n";4802print$cgi->a({-href => href(-replay=>1, page=>$page+1),4803-accesskey =>"n", -title =>"Alt-n"},"next");4804print"</div>\n";4805}4806 git_footer_html();4807}48084809sub git_commit {4810$hash||=$hash_base||"HEAD";4811my%co= parse_commit($hash)4812or die_error(404,"Unknown commit object");4813my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});4814my%cd= parse_date($co{'committer_epoch'},$co{'committer_tz'});48154816my$parent=$co{'parent'};4817my$parents=$co{'parents'};# listref48184819# we need to prepare $formats_nav before any parameter munging4820my$formats_nav;4821if(!defined$parent) {4822# --root commitdiff4823$formats_nav.='(initial)';4824}elsif(@$parents==1) {4825# single parent commit4826$formats_nav.=4827'(parent: '.4828$cgi->a({-href => href(action=>"commit",4829 hash=>$parent)},4830 esc_html(substr($parent,0,7))) .4831')';4832}else{4833# merge commit4834$formats_nav.=4835'(merge: '.4836join(' ',map{4837$cgi->a({-href => href(action=>"commit",4838 hash=>$_)},4839 esc_html(substr($_,0,7)));4840}@$parents) .4841')';4842}48434844if(!defined$parent) {4845$parent="--root";4846}4847my@difftree;4848open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",4849@diff_opts,4850(@$parents<=1?$parent:'-c'),4851$hash,"--"4852or die_error(500,"Open git-diff-tree failed");4853@difftree=map{chomp;$_} <$fd>;4854close$fdor die_error(404,"Reading git-diff-tree failed");48554856# non-textual hash id's can be cached4857my$expires;4858if($hash=~m/^[0-9a-fA-F]{40}$/) {4859$expires="+1d";4860}4861my$refs= git_get_references();4862my$ref= format_ref_marker($refs,$co{'id'});48634864 git_header_html(undef,$expires);4865 git_print_page_nav('commit','',4866$hash,$co{'tree'},$hash,4867$formats_nav);48684869if(defined$co{'parent'}) {4870 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);4871}else{4872 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);4873}4874print"<div class=\"title_text\">\n".4875"<table class=\"object_header\">\n";4876print"<tr><td>author</td><td>". esc_html($co{'author'}) ."</td></tr>\n".4877"<tr>".4878"<td></td><td>$ad{'rfc2822'}";4879if($ad{'hour_local'} <6) {4880printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",4881$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});4882}else{4883printf(" (%02d:%02d%s)",4884$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});4885}4886print"</td>".4887"</tr>\n";4888print"<tr><td>committer</td><td>". esc_html($co{'committer'}) ."</td></tr>\n";4889print"<tr><td></td><td>$cd{'rfc2822'}".4890sprintf(" (%02d:%02d%s)",$cd{'hour_local'},$cd{'minute_local'},$cd{'tz_local'}) .4891"</td></tr>\n";4892print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";4893print"<tr>".4894"<td>tree</td>".4895"<td class=\"sha1\">".4896$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),4897class=>"list"},$co{'tree'}) .4898"</td>".4899"<td class=\"link\">".4900$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},4901"tree");4902my$snapshot_links= format_snapshot_links($hash);4903if(defined$snapshot_links) {4904print" | ".$snapshot_links;4905}4906print"</td>".4907"</tr>\n";49084909foreachmy$par(@$parents) {4910print"<tr>".4911"<td>parent</td>".4912"<td class=\"sha1\">".4913$cgi->a({-href => href(action=>"commit", hash=>$par),4914class=>"list"},$par) .4915"</td>".4916"<td class=\"link\">".4917$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .4918" | ".4919$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .4920"</td>".4921"</tr>\n";4922}4923print"</table>".4924"</div>\n";49254926print"<div class=\"page_body\">\n";4927 git_print_log($co{'comment'});4928print"</div>\n";49294930 git_difftree_body(\@difftree,$hash,@$parents);49314932 git_footer_html();4933}49344935sub git_object {4936# object is defined by:4937# - hash or hash_base alone4938# - hash_base and file_name4939my$type;49404941# - hash or hash_base alone4942if($hash|| ($hash_base&& !defined$file_name)) {4943my$object_id=$hash||$hash_base;49444945open my$fd,"-|", quote_command(4946 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'4947or die_error(404,"Object does not exist");4948$type= <$fd>;4949chomp$type;4950close$fd4951or die_error(404,"Object does not exist");49524953# - hash_base and file_name4954}elsif($hash_base&&defined$file_name) {4955$file_name=~ s,/+$,,;49564957system(git_cmd(),"cat-file",'-e',$hash_base) ==04958or die_error(404,"Base object does not exist");49594960# here errors should not hapen4961open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name4962or die_error(500,"Open git-ls-tree failed");4963my$line= <$fd>;4964close$fd;49654966#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'4967unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {4968 die_error(404,"File or directory for given base does not exist");4969}4970$type=$2;4971$hash=$3;4972}else{4973 die_error(400,"Not enough information to find object");4974}49754976print$cgi->redirect(-uri => href(action=>$type, -full=>1,4977 hash=>$hash, hash_base=>$hash_base,4978 file_name=>$file_name),4979-status =>'302 Found');4980}49814982sub git_blobdiff {4983my$format=shift||'html';49844985my$fd;4986my@difftree;4987my%diffinfo;4988my$expires;49894990# preparing $fd and %diffinfo for git_patchset_body4991# new style URI4992if(defined$hash_base&&defined$hash_parent_base) {4993if(defined$file_name) {4994# read raw output4995open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,4996$hash_parent_base,$hash_base,4997"--", (defined$file_parent?$file_parent: ()),$file_name4998or die_error(500,"Open git-diff-tree failed");4999@difftree=map{chomp;$_} <$fd>;5000close$fd5001or die_error(404,"Reading git-diff-tree failed");5002@difftree5003or die_error(404,"Blob diff not found");50045005}elsif(defined$hash&&5006$hash=~/[0-9a-fA-F]{40}/) {5007# try to find filename from $hash50085009# read filtered raw output5010open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5011$hash_parent_base,$hash_base,"--"5012or die_error(500,"Open git-diff-tree failed");5013@difftree=5014# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'5015# $hash == to_id5016grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}5017map{chomp;$_} <$fd>;5018close$fd5019or die_error(404,"Reading git-diff-tree failed");5020@difftree5021or die_error(404,"Blob diff not found");50225023}else{5024 die_error(400,"Missing one of the blob diff parameters");5025}50265027if(@difftree>1) {5028 die_error(400,"Ambiguous blob diff specification");5029}50305031%diffinfo= parse_difftree_raw_line($difftree[0]);5032$file_parent||=$diffinfo{'from_file'} ||$file_name;5033$file_name||=$diffinfo{'to_file'};50345035$hash_parent||=$diffinfo{'from_id'};5036$hash||=$diffinfo{'to_id'};50375038# non-textual hash id's can be cached5039if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5040$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5041$expires='+1d';5042}50435044# open patch output5045open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5046'-p', ($formateq'html'?"--full-index": ()),5047$hash_parent_base,$hash_base,5048"--", (defined$file_parent?$file_parent: ()),$file_name5049or die_error(500,"Open git-diff-tree failed");5050}50515052# old/legacy style URI5053if(!%diffinfo&&# if new style URI failed5054defined$hash&&defined$hash_parent) {5055# fake git-diff-tree raw output5056$diffinfo{'from_mode'} =$diffinfo{'to_mode'} ="blob";5057$diffinfo{'from_id'} =$hash_parent;5058$diffinfo{'to_id'} =$hash;5059if(defined$file_name) {5060if(defined$file_parent) {5061$diffinfo{'status'} ='2';5062$diffinfo{'from_file'} =$file_parent;5063$diffinfo{'to_file'} =$file_name;5064}else{# assume not renamed5065$diffinfo{'status'} ='1';5066$diffinfo{'from_file'} =$file_name;5067$diffinfo{'to_file'} =$file_name;5068}5069}else{# no filename given5070$diffinfo{'status'} ='2';5071$diffinfo{'from_file'} =$hash_parent;5072$diffinfo{'to_file'} =$hash;5073}50745075# non-textual hash id's can be cached5076if($hash=~m/^[0-9a-fA-F]{40}$/&&5077$hash_parent=~m/^[0-9a-fA-F]{40}$/) {5078$expires='+1d';5079}50805081# open patch output5082open$fd,"-|", git_cmd(),"diff",@diff_opts,5083'-p', ($formateq'html'?"--full-index": ()),5084$hash_parent,$hash,"--"5085or die_error(500,"Open git-diff failed");5086}else{5087 die_error(400,"Missing one of the blob diff parameters")5088unless%diffinfo;5089}50905091# header5092if($formateq'html') {5093my$formats_nav=5094$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5095"raw");5096 git_header_html(undef,$expires);5097if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5098 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5099 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5100}else{5101print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5102print"<div class=\"title\">$hashvs$hash_parent</div>\n";5103}5104if(defined$file_name) {5105 git_print_page_path($file_name,"blob",$hash_base);5106}else{5107print"<div class=\"page_path\"></div>\n";5108}51095110}elsif($formateq'plain') {5111print$cgi->header(5112-type =>'text/plain',5113-charset =>'utf-8',5114-expires =>$expires,5115-content_disposition =>'inline; filename="'."$file_name".'.patch"');51165117print"X-Git-Url: ".$cgi->self_url() ."\n\n";51185119}else{5120 die_error(400,"Unknown blobdiff format");5121}51225123# patch5124if($formateq'html') {5125print"<div class=\"page_body\">\n";51265127 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5128close$fd;51295130print"</div>\n";# class="page_body"5131 git_footer_html();51325133}else{5134while(my$line= <$fd>) {5135$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5136$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;51375138print$line;51395140last if$line=~m!^\+\+\+!;5141}5142local$/=undef;5143print<$fd>;5144close$fd;5145}5146}51475148sub git_blobdiff_plain {5149 git_blobdiff('plain');5150}51515152sub git_commitdiff {5153my$format=shift||'html';5154$hash||=$hash_base||"HEAD";5155my%co= parse_commit($hash)5156or die_error(404,"Unknown commit object");51575158# choose format for commitdiff for merge5159if(!defined$hash_parent&& @{$co{'parents'}} >1) {5160$hash_parent='--cc';5161}5162# we need to prepare $formats_nav before almost any parameter munging5163my$formats_nav;5164if($formateq'html') {5165$formats_nav=5166$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},5167"raw");51685169if(defined$hash_parent&&5170$hash_parentne'-c'&&$hash_parentne'--cc') {5171# commitdiff with two commits given5172my$hash_parent_short=$hash_parent;5173if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {5174$hash_parent_short=substr($hash_parent,0,7);5175}5176$formats_nav.=5177' (from';5178for(my$i=0;$i< @{$co{'parents'}};$i++) {5179if($co{'parents'}[$i]eq$hash_parent) {5180$formats_nav.=' parent '. ($i+1);5181last;5182}5183}5184$formats_nav.=': '.5185$cgi->a({-href => href(action=>"commitdiff",5186 hash=>$hash_parent)},5187 esc_html($hash_parent_short)) .5188')';5189}elsif(!$co{'parent'}) {5190# --root commitdiff5191$formats_nav.=' (initial)';5192}elsif(scalar@{$co{'parents'}} ==1) {5193# single parent commit5194$formats_nav.=5195' (parent: '.5196$cgi->a({-href => href(action=>"commitdiff",5197 hash=>$co{'parent'})},5198 esc_html(substr($co{'parent'},0,7))) .5199')';5200}else{5201# merge commit5202if($hash_parenteq'--cc') {5203$formats_nav.=' | '.5204$cgi->a({-href => href(action=>"commitdiff",5205 hash=>$hash, hash_parent=>'-c')},5206'combined');5207}else{# $hash_parent eq '-c'5208$formats_nav.=' | '.5209$cgi->a({-href => href(action=>"commitdiff",5210 hash=>$hash, hash_parent=>'--cc')},5211'compact');5212}5213$formats_nav.=5214' (merge: '.5215join(' ',map{5216$cgi->a({-href => href(action=>"commitdiff",5217 hash=>$_)},5218 esc_html(substr($_,0,7)));5219} @{$co{'parents'}} ) .5220')';5221}5222}52235224my$hash_parent_param=$hash_parent;5225if(!defined$hash_parent_param) {5226# --cc for multiple parents, --root for parentless5227$hash_parent_param=5228@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';5229}52305231# read commitdiff5232my$fd;5233my@difftree;5234if($formateq'html') {5235open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5236"--no-commit-id","--patch-with-raw","--full-index",5237$hash_parent_param,$hash,"--"5238or die_error(500,"Open git-diff-tree failed");52395240while(my$line= <$fd>) {5241chomp$line;5242# empty line ends raw part of diff-tree output5243last unless$line;5244push@difftree,scalar parse_difftree_raw_line($line);5245}52465247}elsif($formateq'plain') {5248open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5249'-p',$hash_parent_param,$hash,"--"5250or die_error(500,"Open git-diff-tree failed");52515252}else{5253 die_error(400,"Unknown commitdiff format");5254}52555256# non-textual hash id's can be cached5257my$expires;5258if($hash=~m/^[0-9a-fA-F]{40}$/) {5259$expires="+1d";5260}52615262# write commit message5263if($formateq'html') {5264my$refs= git_get_references();5265my$ref= format_ref_marker($refs,$co{'id'});52665267 git_header_html(undef,$expires);5268 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);5269 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);5270 git_print_authorship(\%co);5271print"<div class=\"page_body\">\n";5272if(@{$co{'comment'}} >1) {5273print"<div class=\"log\">\n";5274 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);5275print"</div>\n";# class="log"5276}52775278}elsif($formateq'plain') {5279my$refs= git_get_references("tags");5280my$tagname= git_get_rev_name_tags($hash);5281my$filename= basename($project) ."-$hash.patch";52825283print$cgi->header(5284-type =>'text/plain',5285-charset =>'utf-8',5286-expires =>$expires,5287-content_disposition =>'inline; filename="'."$filename".'"');5288my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5289print"From: ". to_utf8($co{'author'}) ."\n";5290print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";5291print"Subject: ". to_utf8($co{'title'}) ."\n";52925293print"X-Git-Tag:$tagname\n"if$tagname;5294print"X-Git-Url: ".$cgi->self_url() ."\n\n";52955296foreachmy$line(@{$co{'comment'}}) {5297print to_utf8($line) ."\n";5298}5299print"---\n\n";5300}53015302# write patch5303if($formateq'html') {5304my$use_parents= !defined$hash_parent||5305$hash_parenteq'-c'||$hash_parenteq'--cc';5306 git_difftree_body(\@difftree,$hash,5307$use_parents? @{$co{'parents'}} :$hash_parent);5308print"<br/>\n";53095310 git_patchset_body($fd, \@difftree,$hash,5311$use_parents? @{$co{'parents'}} :$hash_parent);5312close$fd;5313print"</div>\n";# class="page_body"5314 git_footer_html();53155316}elsif($formateq'plain') {5317local$/=undef;5318print<$fd>;5319close$fd5320or print"Reading git-diff-tree failed\n";5321}5322}53235324sub git_commitdiff_plain {5325 git_commitdiff('plain');5326}53275328sub git_history {5329if(!defined$hash_base) {5330$hash_base= git_get_head_hash($project);5331}5332if(!defined$page) {5333$page=0;5334}5335my$ftype;5336my%co= parse_commit($hash_base)5337or die_error(404,"Unknown commit object");53385339my$refs= git_get_references();5340my$limit=sprintf("--max-count=%i", (100* ($page+1)));53415342my@commitlist= parse_commits($hash_base,101, (100*$page),5343$file_name,"--full-history")5344or die_error(404,"No such file or directory on given branch");53455346if(!defined$hash&&defined$file_name) {5347# some commits could have deleted file in question,5348# and not have it in tree, but one of them has to have it5349for(my$i=0;$i<=@commitlist;$i++) {5350$hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5351last ifdefined$hash;5352}5353}5354if(defined$hash) {5355$ftype= git_get_type($hash);5356}5357if(!defined$ftype) {5358 die_error(500,"Unknown type of object");5359}53605361my$paging_nav='';5362if($page>0) {5363$paging_nav.=5364$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,5365 file_name=>$file_name)},5366"first");5367$paging_nav.=" ⋅ ".5368$cgi->a({-href => href(-replay=>1, page=>$page-1),5369-accesskey =>"p", -title =>"Alt-p"},"prev");5370}else{5371$paging_nav.="first";5372$paging_nav.=" ⋅ prev";5373}5374my$next_link='';5375if($#commitlist>=100) {5376$next_link=5377$cgi->a({-href => href(-replay=>1, page=>$page+1),5378-accesskey =>"n", -title =>"Alt-n"},"next");5379$paging_nav.=" ⋅$next_link";5380}else{5381$paging_nav.=" ⋅ next";5382}53835384 git_header_html();5385 git_print_page_nav('history','',$hash_base,$co{'tree'},$hash_base,$paging_nav);5386 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5387 git_print_page_path($file_name,$ftype,$hash_base);53885389 git_history_body(\@commitlist,0,99,5390$refs,$hash_base,$ftype,$next_link);53915392 git_footer_html();5393}53945395sub git_search {5396 gitweb_check_feature('search')or die_error(403,"Search is disabled");5397if(!defined$searchtext) {5398 die_error(400,"Text field is empty");5399}5400if(!defined$hash) {5401$hash= git_get_head_hash($project);5402}5403my%co= parse_commit($hash);5404if(!%co) {5405 die_error(404,"Unknown commit object");5406}5407if(!defined$page) {5408$page=0;5409}54105411$searchtype||='commit';5412if($searchtypeeq'pickaxe') {5413# pickaxe may take all resources of your box and run for several minutes5414# with every query - so decide by yourself how public you make this feature5415 gitweb_check_feature('pickaxe')5416or die_error(403,"Pickaxe is disabled");5417}5418if($searchtypeeq'grep') {5419 gitweb_check_feature('grep')5420or die_error(403,"Grep is disabled");5421}54225423 git_header_html();54245425if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {5426my$greptype;5427if($searchtypeeq'commit') {5428$greptype="--grep=";5429}elsif($searchtypeeq'author') {5430$greptype="--author=";5431}elsif($searchtypeeq'committer') {5432$greptype="--committer=";5433}5434$greptype.=$searchtext;5435my@commitlist= parse_commits($hash,101, (100*$page),undef,5436$greptype,'--regexp-ignore-case',5437$search_use_regexp?'--extended-regexp':'--fixed-strings');54385439my$paging_nav='';5440if($page>0) {5441$paging_nav.=5442$cgi->a({-href => href(action=>"search", hash=>$hash,5443 searchtext=>$searchtext,5444 searchtype=>$searchtype)},5445"first");5446$paging_nav.=" ⋅ ".5447$cgi->a({-href => href(-replay=>1, page=>$page-1),5448-accesskey =>"p", -title =>"Alt-p"},"prev");5449}else{5450$paging_nav.="first";5451$paging_nav.=" ⋅ prev";5452}5453my$next_link='';5454if($#commitlist>=100) {5455$next_link=5456$cgi->a({-href => href(-replay=>1, page=>$page+1),5457-accesskey =>"n", -title =>"Alt-n"},"next");5458$paging_nav.=" ⋅$next_link";5459}else{5460$paging_nav.=" ⋅ next";5461}54625463if($#commitlist>=100) {5464}54655466 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);5467 git_print_header_div('commit', esc_html($co{'title'}),$hash);5468 git_search_grep_body(\@commitlist,0,99,$next_link);5469}54705471if($searchtypeeq'pickaxe') {5472 git_print_page_nav('','',$hash,$co{'tree'},$hash);5473 git_print_header_div('commit', esc_html($co{'title'}),$hash);54745475print"<table class=\"pickaxe search\">\n";5476my$alternate=1;5477$/="\n";5478open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,5479'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",5480($search_use_regexp?'--pickaxe-regex': ());5481undef%co;5482my@files;5483while(my$line= <$fd>) {5484chomp$line;5485next unless$line;54865487my%set= parse_difftree_raw_line($line);5488if(defined$set{'commit'}) {5489# finish previous commit5490if(%co) {5491print"</td>\n".5492"<td class=\"link\">".5493$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5494" | ".5495$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5496print"</td>\n".5497"</tr>\n";5498}54995500if($alternate) {5501print"<tr class=\"dark\">\n";5502}else{5503print"<tr class=\"light\">\n";5504}5505$alternate^=1;5506%co= parse_commit($set{'commit'});5507my$author= chop_and_escape_str($co{'author_name'},15,5);5508print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5509"<td><i>$author</i></td>\n".5510"<td>".5511$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),5512-class=>"list subject"},5513 chop_and_escape_str($co{'title'},50) ."<br/>");5514}elsif(defined$set{'to_id'}) {5515next if($set{'to_id'} =~m/^0{40}$/);55165517print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},5518 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),5519-class=>"list"},5520"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .5521"<br/>\n";5522}5523}5524close$fd;55255526# finish last commit (warning: repetition!)5527if(%co) {5528print"</td>\n".5529"<td class=\"link\">".5530$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5531" | ".5532$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5533print"</td>\n".5534"</tr>\n";5535}55365537print"</table>\n";5538}55395540if($searchtypeeq'grep') {5541 git_print_page_nav('','',$hash,$co{'tree'},$hash);5542 git_print_header_div('commit', esc_html($co{'title'}),$hash);55435544print"<table class=\"grep_search\">\n";5545my$alternate=1;5546my$matches=0;5547$/="\n";5548open my$fd,"-|", git_cmd(),'grep','-n',5549$search_use_regexp? ('-E','-i') :'-F',5550$searchtext,$co{'tree'};5551my$lastfile='';5552while(my$line= <$fd>) {5553chomp$line;5554my($file,$lno,$ltext,$binary);5555last if($matches++>1000);5556if($line=~/^Binary file (.+) matches$/) {5557$file=$1;5558$binary=1;5559}else{5560(undef,$file,$lno,$ltext) =split(/:/,$line,4);5561}5562if($filene$lastfile) {5563$lastfileand print"</td></tr>\n";5564if($alternate++) {5565print"<tr class=\"dark\">\n";5566}else{5567print"<tr class=\"light\">\n";5568}5569print"<td class=\"list\">".5570$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5571 file_name=>"$file"),5572-class=>"list"}, esc_path($file));5573print"</td><td>\n";5574$lastfile=$file;5575}5576if($binary) {5577print"<div class=\"binary\">Binary file</div>\n";5578}else{5579$ltext= untabify($ltext);5580if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {5581$ltext= esc_html($1, -nbsp=>1);5582$ltext.='<span class="match">';5583$ltext.= esc_html($2, -nbsp=>1);5584$ltext.='</span>';5585$ltext.= esc_html($3, -nbsp=>1);5586}else{5587$ltext= esc_html($ltext, -nbsp=>1);5588}5589print"<div class=\"pre\">".5590$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5591 file_name=>"$file").'#l'.$lno,5592-class=>"linenr"},sprintf('%4i',$lno))5593.' '.$ltext."</div>\n";5594}5595}5596if($lastfile) {5597print"</td></tr>\n";5598if($matches>1000) {5599print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";5600}5601}else{5602print"<div class=\"diff nodifferences\">No matches found</div>\n";5603}5604close$fd;56055606print"</table>\n";5607}5608 git_footer_html();5609}56105611sub git_search_help {5612 git_header_html();5613 git_print_page_nav('','',$hash,$hash,$hash);5614print<<EOT;5615<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without5616regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,5617the pattern entered is recognized as the POSIX extended5618<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case5619insensitive).</p>5620<dl>5621<dt><b>commit</b></dt>5622<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>5623EOT5624my($have_grep) = gitweb_check_feature('grep');5625if($have_grep) {5626print<<EOT;5627<dt><b>grep</b></dt>5628<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing5629 a different one) are searched for the given pattern. On large trees, this search can take5630a while and put some strain on the server, so please use it with some consideration. Note that5631due to git-grep peculiarity, currently if regexp mode is turned off, the matches are5632case-sensitive.</dd>5633EOT5634}5635print<<EOT;5636<dt><b>author</b></dt>5637<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>5638<dt><b>committer</b></dt>5639<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>5640EOT5641my($have_pickaxe) = gitweb_check_feature('pickaxe');5642if($have_pickaxe) {5643print<<EOT;5644<dt><b>pickaxe</b></dt>5645<dd>All commits that caused the string to appear or disappear from any file (changes that5646added, removed or "modified" the string) will be listed. This search can take a while and5647takes a lot of strain on the server, so please use it wisely. Note that since you may be5648interested even in changes just changing the case as well, this search is case sensitive.</dd>5649EOT5650}5651print"</dl>\n";5652 git_footer_html();5653}56545655sub git_shortlog {5656my$head= git_get_head_hash($project);5657if(!defined$hash) {5658$hash=$head;5659}5660if(!defined$page) {5661$page=0;5662}5663my$refs= git_get_references();56645665my$commit_hash=$hash;5666if(defined$hash_parent) {5667$commit_hash="$hash_parent..$hash";5668}5669my@commitlist= parse_commits($commit_hash,101, (100*$page));56705671my$paging_nav= format_paging_nav('shortlog',$hash,$head,$page,$#commitlist>=100);5672my$next_link='';5673if($#commitlist>=100) {5674$next_link=5675$cgi->a({-href => href(-replay=>1, page=>$page+1),5676-accesskey =>"n", -title =>"Alt-n"},"next");5677}56785679 git_header_html();5680 git_print_page_nav('shortlog','',$hash,$hash,$hash,$paging_nav);5681 git_print_header_div('summary',$project);56825683 git_shortlog_body(\@commitlist,0,99,$refs,$next_link);56845685 git_footer_html();5686}56875688## ......................................................................5689## feeds (RSS, Atom; OPML)56905691sub git_feed {5692my$format=shift||'atom';5693my($have_blame) = gitweb_check_feature('blame');56945695# Atom: http://www.atomenabled.org/developers/syndication/5696# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ5697if($formatne'rss'&&$formatne'atom') {5698 die_error(400,"Unknown web feed format");5699}57005701# log/feed of current (HEAD) branch, log of given branch, history of file/directory5702my$head=$hash||'HEAD';5703my@commitlist= parse_commits($head,150,0,$file_name);57045705my%latest_commit;5706my%latest_date;5707my$content_type="application/$format+xml";5708if(defined$cgi->http('HTTP_ACCEPT') &&5709$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {5710# browser (feed reader) prefers text/xml5711$content_type='text/xml';5712}5713if(defined($commitlist[0])) {5714%latest_commit= %{$commitlist[0]};5715%latest_date= parse_date($latest_commit{'author_epoch'});5716print$cgi->header(5717-type =>$content_type,5718-charset =>'utf-8',5719-last_modified =>$latest_date{'rfc2822'});5720}else{5721print$cgi->header(5722-type =>$content_type,5723-charset =>'utf-8');5724}57255726# Optimization: skip generating the body if client asks only5727# for Last-Modified date.5728return if($cgi->request_method()eq'HEAD');57295730# header variables5731my$title="$site_name-$project/$action";5732my$feed_type='log';5733if(defined$hash) {5734$title.=" - '$hash'";5735$feed_type='branch log';5736if(defined$file_name) {5737$title.=" ::$file_name";5738$feed_type='history';5739}5740}elsif(defined$file_name) {5741$title.=" -$file_name";5742$feed_type='history';5743}5744$title.="$feed_type";5745my$descr= git_get_project_description($project);5746if(defined$descr) {5747$descr= esc_html($descr);5748}else{5749$descr="$project".5750($formateq'rss'?'RSS':'Atom') .5751" feed";5752}5753my$owner= git_get_project_owner($project);5754$owner= esc_html($owner);57555756#header5757my$alt_url;5758if(defined$file_name) {5759$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);5760}elsif(defined$hash) {5761$alt_url= href(-full=>1, action=>"log", hash=>$hash);5762}else{5763$alt_url= href(-full=>1, action=>"summary");5764}5765print qq!<?xml version="1.0" encoding="utf-8"?>\n!;5766if($formateq'rss') {5767print<<XML;5768<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">5769<channel>5770XML5771print"<title>$title</title>\n".5772"<link>$alt_url</link>\n".5773"<description>$descr</description>\n".5774"<language>en</language>\n";5775}elsif($formateq'atom') {5776print<<XML;5777<feed xmlns="http://www.w3.org/2005/Atom">5778XML5779print"<title>$title</title>\n".5780"<subtitle>$descr</subtitle>\n".5781'<link rel="alternate" type="text/html" href="'.5782$alt_url.'" />'."\n".5783'<link rel="self" type="'.$content_type.'" href="'.5784$cgi->self_url() .'" />'."\n".5785"<id>". href(-full=>1) ."</id>\n".5786# use project owner for feed author5787"<author><name>$owner</name></author>\n";5788if(defined$favicon) {5789print"<icon>". esc_url($favicon) ."</icon>\n";5790}5791if(defined$logo_url) {5792# not twice as wide as tall: 72 x 27 pixels5793print"<logo>". esc_url($logo) ."</logo>\n";5794}5795if(!%latest_date) {5796# dummy date to keep the feed valid until commits trickle in:5797print"<updated>1970-01-01T00:00:00Z</updated>\n";5798}else{5799print"<updated>$latest_date{'iso-8601'}</updated>\n";5800}5801}58025803# contents5804for(my$i=0;$i<=$#commitlist;$i++) {5805my%co= %{$commitlist[$i]};5806my$commit=$co{'id'};5807# we read 150, we always show 30 and the ones more recent than 48 hours5808if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {5809last;5810}5811my%cd= parse_date($co{'author_epoch'});58125813# get list of changed files5814open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5815$co{'parent'} ||"--root",5816$co{'id'},"--", (defined$file_name?$file_name: ())5817ornext;5818my@difftree=map{chomp;$_} <$fd>;5819close$fd5820ornext;58215822# print element (entry, item)5823my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);5824if($formateq'rss') {5825print"<item>\n".5826"<title>". esc_html($co{'title'}) ."</title>\n".5827"<author>". esc_html($co{'author'}) ."</author>\n".5828"<pubDate>$cd{'rfc2822'}</pubDate>\n".5829"<guid isPermaLink=\"true\">$co_url</guid>\n".5830"<link>$co_url</link>\n".5831"<description>". esc_html($co{'title'}) ."</description>\n".5832"<content:encoded>".5833"<![CDATA[\n";5834}elsif($formateq'atom') {5835print"<entry>\n".5836"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".5837"<updated>$cd{'iso-8601'}</updated>\n".5838"<author>\n".5839" <name>". esc_html($co{'author_name'}) ."</name>\n";5840if($co{'author_email'}) {5841print" <email>". esc_html($co{'author_email'}) ."</email>\n";5842}5843print"</author>\n".5844# use committer for contributor5845"<contributor>\n".5846" <name>". esc_html($co{'committer_name'}) ."</name>\n";5847if($co{'committer_email'}) {5848print" <email>". esc_html($co{'committer_email'}) ."</email>\n";5849}5850print"</contributor>\n".5851"<published>$cd{'iso-8601'}</published>\n".5852"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".5853"<id>$co_url</id>\n".5854"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".5855"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";5856}5857my$comment=$co{'comment'};5858print"<pre>\n";5859foreachmy$line(@$comment) {5860$line= esc_html($line);5861print"$line\n";5862}5863print"</pre><ul>\n";5864foreachmy$difftree_line(@difftree) {5865my%difftree= parse_difftree_raw_line($difftree_line);5866next if!$difftree{'from_id'};58675868my$file=$difftree{'file'} ||$difftree{'to_file'};58695870print"<li>".5871"[".5872$cgi->a({-href => href(-full=>1, action=>"blobdiff",5873 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},5874 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},5875 file_name=>$file, file_parent=>$difftree{'from_file'}),5876-title =>"diff"},'D');5877if($have_blame) {5878print$cgi->a({-href => href(-full=>1, action=>"blame",5879 file_name=>$file, hash_base=>$commit),5880-title =>"blame"},'B');5881}5882# if this is not a feed of a file history5883if(!defined$file_name||$file_namene$file) {5884print$cgi->a({-href => href(-full=>1, action=>"history",5885 file_name=>$file, hash=>$commit),5886-title =>"history"},'H');5887}5888$file= esc_path($file);5889print"] ".5890"$file</li>\n";5891}5892if($formateq'rss') {5893print"</ul>]]>\n".5894"</content:encoded>\n".5895"</item>\n";5896}elsif($formateq'atom') {5897print"</ul>\n</div>\n".5898"</content>\n".5899"</entry>\n";5900}5901}59025903# end of feed5904if($formateq'rss') {5905print"</channel>\n</rss>\n";5906}elsif($formateq'atom') {5907print"</feed>\n";5908}5909}59105911sub git_rss {5912 git_feed('rss');5913}59145915sub git_atom {5916 git_feed('atom');5917}59185919sub git_opml {5920my@list= git_get_projects_list();59215922print$cgi->header(-type =>'text/xml', -charset =>'utf-8');5923print<<XML;5924<?xml version="1.0" encoding="utf-8"?>5925<opml version="1.0">5926<head>5927 <title>$site_nameOPML Export</title>5928</head>5929<body>5930<outline text="git RSS feeds">5931XML59325933foreachmy$pr(@list) {5934my%proj=%$pr;5935my$head= git_get_head_hash($proj{'path'});5936if(!defined$head) {5937next;5938}5939$git_dir="$projectroot/$proj{'path'}";5940my%co= parse_commit($head);5941if(!%co) {5942next;5943}59445945my$path= esc_html(chop_str($proj{'path'},25,5));5946my$rss="$my_url?p=$proj{'path'};a=rss";5947my$html="$my_url?p=$proj{'path'};a=summary";5948print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";5949}5950print<<XML;5951</outline>5952</body>5953</opml>5954XML5955}