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# Allow gitweb scan project content tags described in ctags/ 287# of project repository, and display the popular Web 2.0-ish 288# "tag cloud" near the project list. Note that this is something 289# COMPLETELY different from the normal Git tags. 290 291# gitweb by itself can show existing tags, but it does not handle 292# tagging itself; you need an external application for that. 293# For an example script, check Girocco's cgi/tagproj.cgi. 294# You may want to install the HTML::TagCloud Perl module to get 295# a pretty tag cloud instead of just a list of tags. 296 297# To enable system wide have in $GITWEB_CONFIG 298# $feature{'ctags'}{'default'} = ['path_to_tag_script']; 299# Project specific override is not supported. 300'ctags'=> { 301'override'=>0, 302'default'=> [0]}, 303); 304 305sub gitweb_check_feature { 306my($name) =@_; 307return unlessexists$feature{$name}; 308my($sub,$override,@defaults) = ( 309$feature{$name}{'sub'}, 310$feature{$name}{'override'}, 311@{$feature{$name}{'default'}}); 312if(!$override) {return@defaults; } 313if(!defined$sub) { 314warn"feature$nameis not overrideable"; 315return@defaults; 316} 317return$sub->(@defaults); 318} 319 320sub feature_blame { 321my($val) = git_get_project_config('blame','--bool'); 322 323if($valeq'true') { 324return1; 325}elsif($valeq'false') { 326return0; 327} 328 329return$_[0]; 330} 331 332sub feature_snapshot { 333my(@fmts) =@_; 334 335my($val) = git_get_project_config('snapshot'); 336 337if($val) { 338@fmts= ($valeq'none'? () :split/\s*[,\s]\s*/,$val); 339} 340 341return@fmts; 342} 343 344sub feature_grep { 345my($val) = git_get_project_config('grep','--bool'); 346 347if($valeq'true') { 348return(1); 349}elsif($valeq'false') { 350return(0); 351} 352 353return($_[0]); 354} 355 356sub feature_pickaxe { 357my($val) = git_get_project_config('pickaxe','--bool'); 358 359if($valeq'true') { 360return(1); 361}elsif($valeq'false') { 362return(0); 363} 364 365return($_[0]); 366} 367 368# checking HEAD file with -e is fragile if the repository was 369# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed 370# and then pruned. 371sub check_head_link { 372my($dir) =@_; 373my$headfile="$dir/HEAD"; 374return((-e $headfile) || 375(-l $headfile&&readlink($headfile) =~/^refs\/heads\//)); 376} 377 378sub check_export_ok { 379my($dir) =@_; 380return(check_head_link($dir) && 381(!$export_ok|| -e "$dir/$export_ok")); 382} 383 384# process alternate names for backward compatibility 385# filter out unsupported (unknown) snapshot formats 386sub filter_snapshot_fmts { 387my@fmts=@_; 388 389@fmts=map{ 390exists$known_snapshot_format_aliases{$_} ? 391$known_snapshot_format_aliases{$_} :$_}@fmts; 392@fmts=grep(exists$known_snapshot_formats{$_},@fmts); 393 394} 395 396our$GITWEB_CONFIG=$ENV{'GITWEB_CONFIG'} ||"++GITWEB_CONFIG++"; 397if(-e $GITWEB_CONFIG) { 398do$GITWEB_CONFIG; 399}else{ 400our$GITWEB_CONFIG_SYSTEM=$ENV{'GITWEB_CONFIG_SYSTEM'} ||"++GITWEB_CONFIG_SYSTEM++"; 401do$GITWEB_CONFIG_SYSTEMif-e $GITWEB_CONFIG_SYSTEM; 402} 403 404# version of the core git binary 405our$git_version=qx("$GIT" --version)=~m/git version (.*)$/?$1:"unknown"; 406 407$projects_list||=$projectroot; 408 409# ====================================================================== 410# input validation and dispatch 411our$action=$cgi->param('a'); 412if(defined$action) { 413if($action=~m/[^0-9a-zA-Z\.\-_]/) { 414 die_error(400,"Invalid action parameter"); 415} 416} 417 418# parameters which are pathnames 419our$project=$cgi->param('p'); 420if(defined$project) { 421if(!validate_pathname($project) || 422!(-d "$projectroot/$project") || 423!check_head_link("$projectroot/$project") || 424($export_ok&& !(-e "$projectroot/$project/$export_ok")) || 425($strict_export&& !project_in_list($project))) { 426undef$project; 427 die_error(404,"No such project"); 428} 429} 430 431our$file_name=$cgi->param('f'); 432if(defined$file_name) { 433if(!validate_pathname($file_name)) { 434 die_error(400,"Invalid file parameter"); 435} 436} 437 438our$file_parent=$cgi->param('fp'); 439if(defined$file_parent) { 440if(!validate_pathname($file_parent)) { 441 die_error(400,"Invalid file parent parameter"); 442} 443} 444 445# parameters which are refnames 446our$hash=$cgi->param('h'); 447if(defined$hash) { 448if(!validate_refname($hash)) { 449 die_error(400,"Invalid hash parameter"); 450} 451} 452 453our$hash_parent=$cgi->param('hp'); 454if(defined$hash_parent) { 455if(!validate_refname($hash_parent)) { 456 die_error(400,"Invalid hash parent parameter"); 457} 458} 459 460our$hash_base=$cgi->param('hb'); 461if(defined$hash_base) { 462if(!validate_refname($hash_base)) { 463 die_error(400,"Invalid hash base parameter"); 464} 465} 466 467my%allowed_options= ( 468"--no-merges"=> [qw(rss atom log shortlog history)], 469); 470 471our@extra_options=$cgi->param('opt'); 472if(defined@extra_options) { 473foreachmy$opt(@extra_options) { 474if(not exists$allowed_options{$opt}) { 475 die_error(400,"Invalid option parameter"); 476} 477if(not grep(/^$action$/, @{$allowed_options{$opt}})) { 478 die_error(400,"Invalid option parameter for this action"); 479} 480} 481} 482 483our$hash_parent_base=$cgi->param('hpb'); 484if(defined$hash_parent_base) { 485if(!validate_refname($hash_parent_base)) { 486 die_error(400,"Invalid hash parent base parameter"); 487} 488} 489 490# other parameters 491our$page=$cgi->param('pg'); 492if(defined$page) { 493if($page=~m/[^0-9]/) { 494 die_error(400,"Invalid page parameter"); 495} 496} 497 498our$searchtype=$cgi->param('st'); 499if(defined$searchtype) { 500if($searchtype=~m/[^a-z]/) { 501 die_error(400,"Invalid searchtype parameter"); 502} 503} 504 505our$search_use_regexp=$cgi->param('sr'); 506 507our$searchtext=$cgi->param('s'); 508our$search_regexp; 509if(defined$searchtext) { 510if(length($searchtext) <2) { 511 die_error(403,"At least two characters are required for search parameter"); 512} 513$search_regexp=$search_use_regexp?$searchtext:quotemeta$searchtext; 514} 515 516# now read PATH_INFO and use it as alternative to parameters 517sub evaluate_path_info { 518return ifdefined$project; 519my$path_info=$ENV{"PATH_INFO"}; 520return if!$path_info; 521$path_info=~ s,^/+,,; 522return if!$path_info; 523# find which part of PATH_INFO is project 524$project=$path_info; 525$project=~ s,/+$,,; 526while($project&& !check_head_link("$projectroot/$project")) { 527$project=~ s,/*[^/]*$,,; 528} 529# validate project 530$project= validate_pathname($project); 531if(!$project|| 532($export_ok&& !-e "$projectroot/$project/$export_ok") || 533($strict_export&& !project_in_list($project))) { 534undef$project; 535return; 536} 537# do not change any parameters if an action is given using the query string 538return if$action; 539$path_info=~ s,^\Q$project\E/*,,; 540my($refname,$pathname) =split(/:/,$path_info,2); 541if(defined$pathname) { 542# we got "project.git/branch:filename" or "project.git/branch:dir/" 543# we could use git_get_type(branch:pathname), but it needs $git_dir 544$pathname=~ s,^/+,,; 545if(!$pathname||substr($pathname, -1)eq"/") { 546$action||="tree"; 547$pathname=~ s,/$,,; 548}else{ 549$action||="blob_plain"; 550} 551$hash_base||= validate_refname($refname); 552$file_name||= validate_pathname($pathname); 553}elsif(defined$refname) { 554# we got "project.git/branch" 555$action||="shortlog"; 556$hash||= validate_refname($refname); 557} 558} 559evaluate_path_info(); 560 561# path to the current git repository 562our$git_dir; 563$git_dir="$projectroot/$project"if$project; 564 565# dispatch 566my%actions= ( 567"blame"=> \&git_blame, 568"blobdiff"=> \&git_blobdiff, 569"blobdiff_plain"=> \&git_blobdiff_plain, 570"blob"=> \&git_blob, 571"blob_plain"=> \&git_blob_plain, 572"commitdiff"=> \&git_commitdiff, 573"commitdiff_plain"=> \&git_commitdiff_plain, 574"commit"=> \&git_commit, 575"forks"=> \&git_forks, 576"heads"=> \&git_heads, 577"history"=> \&git_history, 578"log"=> \&git_log, 579"rss"=> \&git_rss, 580"atom"=> \&git_atom, 581"search"=> \&git_search, 582"search_help"=> \&git_search_help, 583"shortlog"=> \&git_shortlog, 584"summary"=> \&git_summary, 585"tag"=> \&git_tag, 586"tags"=> \&git_tags, 587"tree"=> \&git_tree, 588"snapshot"=> \&git_snapshot, 589"object"=> \&git_object, 590# those below don't need $project 591"opml"=> \&git_opml, 592"project_list"=> \&git_project_list, 593"project_index"=> \&git_project_index, 594); 595 596if(!defined$action) { 597if(defined$hash) { 598$action= git_get_type($hash); 599}elsif(defined$hash_base&&defined$file_name) { 600$action= git_get_type("$hash_base:$file_name"); 601}elsif(defined$project) { 602$action='summary'; 603}else{ 604$action='project_list'; 605} 606} 607if(!defined($actions{$action})) { 608 die_error(400,"Unknown action"); 609} 610if($action!~m/^(opml|project_list|project_index)$/&& 611!$project) { 612 die_error(400,"Project needed"); 613} 614$actions{$action}->(); 615exit; 616 617## ====================================================================== 618## action links 619 620sub href (%) { 621my%params=@_; 622# default is to use -absolute url() i.e. $my_uri 623my$href=$params{-full} ?$my_url:$my_uri; 624 625# XXX: Warning: If you touch this, check the search form for updating, 626# too. 627 628my@mapping= ( 629 project =>"p", 630 action =>"a", 631 file_name =>"f", 632 file_parent =>"fp", 633 hash =>"h", 634 hash_parent =>"hp", 635 hash_base =>"hb", 636 hash_parent_base =>"hpb", 637 page =>"pg", 638 order =>"o", 639 searchtext =>"s", 640 searchtype =>"st", 641 snapshot_format =>"sf", 642 extra_options =>"opt", 643 search_use_regexp =>"sr", 644); 645my%mapping=@mapping; 646 647$params{'project'} =$projectunlessexists$params{'project'}; 648 649if($params{-replay}) { 650while(my($name,$symbol) =each%mapping) { 651if(!exists$params{$name}) { 652# to allow for multivalued params we use arrayref form 653$params{$name} = [$cgi->param($symbol) ]; 654} 655} 656} 657 658my($use_pathinfo) = gitweb_check_feature('pathinfo'); 659if($use_pathinfo) { 660# use PATH_INFO for project name 661$href.="/".esc_url($params{'project'})ifdefined$params{'project'}; 662delete$params{'project'}; 663 664# Summary just uses the project path URL 665if(defined$params{'action'} &&$params{'action'}eq'summary') { 666delete$params{'action'}; 667} 668} 669 670# now encode the parameters explicitly 671my@result= (); 672for(my$i=0;$i<@mapping;$i+=2) { 673my($name,$symbol) = ($mapping[$i],$mapping[$i+1]); 674if(defined$params{$name}) { 675if(ref($params{$name})eq"ARRAY") { 676foreachmy$par(@{$params{$name}}) { 677push@result,$symbol."=". esc_param($par); 678} 679}else{ 680push@result,$symbol."=". esc_param($params{$name}); 681} 682} 683} 684$href.="?".join(';',@result)ifscalar@result; 685 686return$href; 687} 688 689 690## ====================================================================== 691## validation, quoting/unquoting and escaping 692 693sub validate_pathname { 694my$input=shift||returnundef; 695 696# no '.' or '..' as elements of path, i.e. no '.' nor '..' 697# at the beginning, at the end, and between slashes. 698# also this catches doubled slashes 699if($input=~m!(^|/)(|\.|\.\.)(/|$)!) { 700returnundef; 701} 702# no null characters 703if($input=~m!\0!) { 704returnundef; 705} 706return$input; 707} 708 709sub validate_refname { 710my$input=shift||returnundef; 711 712# textual hashes are O.K. 713if($input=~m/^[0-9a-fA-F]{40}$/) { 714return$input; 715} 716# it must be correct pathname 717$input= validate_pathname($input) 718orreturnundef; 719# restrictions on ref name according to git-check-ref-format 720if($input=~m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) { 721returnundef; 722} 723return$input; 724} 725 726# decode sequences of octets in utf8 into Perl's internal form, 727# which is utf-8 with utf8 flag set if needed. gitweb writes out 728# in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning 729sub to_utf8 { 730my$str=shift; 731if(utf8::valid($str)) { 732 utf8::decode($str); 733return$str; 734}else{ 735return decode($fallback_encoding,$str, Encode::FB_DEFAULT); 736} 737} 738 739# quote unsafe chars, but keep the slash, even when it's not 740# correct, but quoted slashes look too horrible in bookmarks 741sub esc_param { 742my$str=shift; 743$str=~s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X",ord($1))/eg; 744$str=~s/\+/%2B/g; 745$str=~s/ /\+/g; 746return$str; 747} 748 749# quote unsafe chars in whole URL, so some charactrs cannot be quoted 750sub esc_url { 751my$str=shift; 752$str=~s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X",ord($1))/eg; 753$str=~s/\+/%2B/g; 754$str=~s/ /\+/g; 755return$str; 756} 757 758# replace invalid utf8 character with SUBSTITUTION sequence 759sub esc_html ($;%) { 760my$str=shift; 761my%opts=@_; 762 763$str= to_utf8($str); 764$str=$cgi->escapeHTML($str); 765if($opts{'-nbsp'}) { 766$str=~s/ / /g; 767} 768$str=~ s|([[:cntrl:]])|(($1ne"\t") ? quot_cec($1) :$1)|eg; 769return$str; 770} 771 772# quote control characters and escape filename to HTML 773sub esc_path { 774my$str=shift; 775my%opts=@_; 776 777$str= to_utf8($str); 778$str=$cgi->escapeHTML($str); 779if($opts{'-nbsp'}) { 780$str=~s/ / /g; 781} 782$str=~ s|([[:cntrl:]])|quot_cec($1)|eg; 783return$str; 784} 785 786# Make control characters "printable", using character escape codes (CEC) 787sub quot_cec { 788my$cntrl=shift; 789my%opts=@_; 790my%es= (# character escape codes, aka escape sequences 791"\t"=>'\t',# tab (HT) 792"\n"=>'\n',# line feed (LF) 793"\r"=>'\r',# carrige return (CR) 794"\f"=>'\f',# form feed (FF) 795"\b"=>'\b',# backspace (BS) 796"\a"=>'\a',# alarm (bell) (BEL) 797"\e"=>'\e',# escape (ESC) 798"\013"=>'\v',# vertical tab (VT) 799"\000"=>'\0',# nul character (NUL) 800); 801my$chr= ( (exists$es{$cntrl}) 802?$es{$cntrl} 803:sprintf('\%2x',ord($cntrl)) ); 804if($opts{-nohtml}) { 805return$chr; 806}else{ 807return"<span class=\"cntrl\">$chr</span>"; 808} 809} 810 811# Alternatively use unicode control pictures codepoints, 812# Unicode "printable representation" (PR) 813sub quot_upr { 814my$cntrl=shift; 815my%opts=@_; 816 817my$chr=sprintf('&#%04d;',0x2400+ord($cntrl)); 818if($opts{-nohtml}) { 819return$chr; 820}else{ 821return"<span class=\"cntrl\">$chr</span>"; 822} 823} 824 825# git may return quoted and escaped filenames 826sub unquote { 827my$str=shift; 828 829sub unq { 830my$seq=shift; 831my%es= (# character escape codes, aka escape sequences 832't'=>"\t",# tab (HT, TAB) 833'n'=>"\n",# newline (NL) 834'r'=>"\r",# return (CR) 835'f'=>"\f",# form feed (FF) 836'b'=>"\b",# backspace (BS) 837'a'=>"\a",# alarm (bell) (BEL) 838'e'=>"\e",# escape (ESC) 839'v'=>"\013",# vertical tab (VT) 840); 841 842if($seq=~m/^[0-7]{1,3}$/) { 843# octal char sequence 844returnchr(oct($seq)); 845}elsif(exists$es{$seq}) { 846# C escape sequence, aka character escape code 847return$es{$seq}; 848} 849# quoted ordinary character 850return$seq; 851} 852 853if($str=~m/^"(.*)"$/) { 854# needs unquoting 855$str=$1; 856$str=~s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg; 857} 858return$str; 859} 860 861# escape tabs (convert tabs to spaces) 862sub untabify { 863my$line=shift; 864 865while((my$pos=index($line,"\t")) != -1) { 866if(my$count= (8- ($pos%8))) { 867my$spaces=' ' x $count; 868$line=~s/\t/$spaces/; 869} 870} 871 872return$line; 873} 874 875sub project_in_list { 876my$project=shift; 877my@list= git_get_projects_list(); 878return@list&&scalar(grep{$_->{'path'}eq$project}@list); 879} 880 881## ---------------------------------------------------------------------- 882## HTML aware string manipulation 883 884# Try to chop given string on a word boundary between position 885# $len and $len+$add_len. If there is no word boundary there, 886# chop at $len+$add_len. Do not chop if chopped part plus ellipsis 887# (marking chopped part) would be longer than given string. 888sub chop_str { 889my$str=shift; 890my$len=shift; 891my$add_len=shift||10; 892my$where=shift||'right';# 'left' | 'center' | 'right' 893 894# Make sure perl knows it is utf8 encoded so we don't 895# cut in the middle of a utf8 multibyte char. 896$str= to_utf8($str); 897 898# allow only $len chars, but don't cut a word if it would fit in $add_len 899# if it doesn't fit, cut it if it's still longer than the dots we would add 900# remove chopped character entities entirely 901 902# when chopping in the middle, distribute $len into left and right part 903# return early if chopping wouldn't make string shorter 904if($whereeq'center') { 905return$strif($len+5>=length($str));# filler is length 5 906$len=int($len/2); 907}else{ 908return$strif($len+4>=length($str));# filler is length 4 909} 910 911# regexps: ending and beginning with word part up to $add_len 912my$endre=qr/.{$len}\w{0,$add_len}/; 913my$begre=qr/\w{0,$add_len}.{$len}/; 914 915if($whereeq'left') { 916$str=~m/^(.*?)($begre)$/; 917my($lead,$body) = ($1,$2); 918if(length($lead) >4) { 919$body=~s/^[^;]*;//if($lead=~m/&[^;]*$/); 920$lead=" ..."; 921} 922return"$lead$body"; 923 924}elsif($whereeq'center') { 925$str=~m/^($endre)(.*)$/; 926my($left,$str) = ($1,$2); 927$str=~m/^(.*?)($begre)$/; 928my($mid,$right) = ($1,$2); 929if(length($mid) >5) { 930$left=~s/&[^;]*$//; 931$right=~s/^[^;]*;//if($mid=~m/&[^;]*$/); 932$mid=" ... "; 933} 934return"$left$mid$right"; 935 936}else{ 937$str=~m/^($endre)(.*)$/; 938my$body=$1; 939my$tail=$2; 940if(length($tail) >4) { 941$body=~s/&[^;]*$//; 942$tail="... "; 943} 944return"$body$tail"; 945} 946} 947 948# takes the same arguments as chop_str, but also wraps a <span> around the 949# result with a title attribute if it does get chopped. Additionally, the 950# string is HTML-escaped. 951sub chop_and_escape_str { 952my($str) =@_; 953 954my$chopped= chop_str(@_); 955if($choppedeq$str) { 956return esc_html($chopped); 957}else{ 958$str=~s/([[:cntrl:]])/?/g; 959return$cgi->span({-title=>$str}, esc_html($chopped)); 960} 961} 962 963## ---------------------------------------------------------------------- 964## functions returning short strings 965 966# CSS class for given age value (in seconds) 967sub age_class { 968my$age=shift; 969 970if(!defined$age) { 971return"noage"; 972}elsif($age<60*60*2) { 973return"age0"; 974}elsif($age<60*60*24*2) { 975return"age1"; 976}else{ 977return"age2"; 978} 979} 980 981# convert age in seconds to "nn units ago" string 982sub age_string { 983my$age=shift; 984my$age_str; 985 986if($age>60*60*24*365*2) { 987$age_str= (int$age/60/60/24/365); 988$age_str.=" years ago"; 989}elsif($age>60*60*24*(365/12)*2) { 990$age_str=int$age/60/60/24/(365/12); 991$age_str.=" months ago"; 992}elsif($age>60*60*24*7*2) { 993$age_str=int$age/60/60/24/7; 994$age_str.=" weeks ago"; 995}elsif($age>60*60*24*2) { 996$age_str=int$age/60/60/24; 997$age_str.=" days ago"; 998}elsif($age>60*60*2) { 999$age_str=int$age/60/60;1000$age_str.=" hours ago";1001}elsif($age>60*2) {1002$age_str=int$age/60;1003$age_str.=" min ago";1004}elsif($age>2) {1005$age_str=int$age;1006$age_str.=" sec ago";1007}else{1008$age_str.=" right now";1009}1010return$age_str;1011}10121013useconstant{1014 S_IFINVALID =>0030000,1015 S_IFGITLINK =>0160000,1016};10171018# submodule/subproject, a commit object reference1019sub S_ISGITLINK($) {1020my$mode=shift;10211022return(($mode& S_IFMT) == S_IFGITLINK)1023}10241025# convert file mode in octal to symbolic file mode string1026sub mode_str {1027my$mode=oct shift;10281029if(S_ISGITLINK($mode)) {1030return'm---------';1031}elsif(S_ISDIR($mode& S_IFMT)) {1032return'drwxr-xr-x';1033}elsif(S_ISLNK($mode)) {1034return'lrwxrwxrwx';1035}elsif(S_ISREG($mode)) {1036# git cares only about the executable bit1037if($mode& S_IXUSR) {1038return'-rwxr-xr-x';1039}else{1040return'-rw-r--r--';1041};1042}else{1043return'----------';1044}1045}10461047# convert file mode in octal to file type string1048sub file_type {1049my$mode=shift;10501051if($mode!~m/^[0-7]+$/) {1052return$mode;1053}else{1054$mode=oct$mode;1055}10561057if(S_ISGITLINK($mode)) {1058return"submodule";1059}elsif(S_ISDIR($mode& S_IFMT)) {1060return"directory";1061}elsif(S_ISLNK($mode)) {1062return"symlink";1063}elsif(S_ISREG($mode)) {1064return"file";1065}else{1066return"unknown";1067}1068}10691070# convert file mode in octal to file type description string1071sub file_type_long {1072my$mode=shift;10731074if($mode!~m/^[0-7]+$/) {1075return$mode;1076}else{1077$mode=oct$mode;1078}10791080if(S_ISGITLINK($mode)) {1081return"submodule";1082}elsif(S_ISDIR($mode& S_IFMT)) {1083return"directory";1084}elsif(S_ISLNK($mode)) {1085return"symlink";1086}elsif(S_ISREG($mode)) {1087if($mode& S_IXUSR) {1088return"executable";1089}else{1090return"file";1091};1092}else{1093return"unknown";1094}1095}109610971098## ----------------------------------------------------------------------1099## functions returning short HTML fragments, or transforming HTML fragments1100## which don't belong to other sections11011102# format line of commit message.1103sub format_log_line_html {1104my$line=shift;11051106$line= esc_html($line, -nbsp=>1);1107if($line=~m/([0-9a-fA-F]{8,40})/) {1108my$hash_text=$1;1109my$link=1110$cgi->a({-href => href(action=>"object", hash=>$hash_text),1111-class=>"text"},$hash_text);1112$line=~s/$hash_text/$link/;1113}1114return$line;1115}11161117# format marker of refs pointing to given object11181119# the destination action is chosen based on object type and current context:1120# - for annotated tags, we choose the tag view unless it's the current view1121# already, in which case we go to shortlog view1122# - for other refs, we keep the current view if we're in history, shortlog or1123# log view, and select shortlog otherwise1124sub format_ref_marker {1125my($refs,$id) =@_;1126my$markers='';11271128if(defined$refs->{$id}) {1129foreachmy$ref(@{$refs->{$id}}) {1130# this code exploits the fact that non-lightweight tags are the1131# only indirect objects, and that they are the only objects for which1132# we want to use tag instead of shortlog as action1133my($type,$name) =qw();1134my$indirect= ($ref=~s/\^\{\}$//);1135# e.g. tags/v2.6.11 or heads/next1136if($ref=~m!^(.*?)s?/(.*)$!) {1137$type=$1;1138$name=$2;1139}else{1140$type="ref";1141$name=$ref;1142}11431144my$class=$type;1145$class.=" indirect"if$indirect;11461147my$dest_action="shortlog";11481149if($indirect) {1150$dest_action="tag"unless$actioneq"tag";1151}elsif($action=~/^(history|(short)?log)$/) {1152$dest_action=$action;1153}11541155my$dest="";1156$dest.="refs/"unless$ref=~ m!^refs/!;1157$dest.=$ref;11581159my$link=$cgi->a({1160-href => href(1161 action=>$dest_action,1162 hash=>$dest1163)},$name);11641165$markers.=" <span class=\"$class\"title=\"$ref\">".1166$link."</span>";1167}1168}11691170if($markers) {1171return' <span class="refs">'.$markers.'</span>';1172}else{1173return"";1174}1175}11761177# format, perhaps shortened and with markers, title line1178sub format_subject_html {1179my($long,$short,$href,$extra) =@_;1180$extra=''unlessdefined($extra);11811182if(length($short) <length($long)) {1183return$cgi->a({-href =>$href, -class=>"list subject",1184-title => to_utf8($long)},1185 esc_html($short) .$extra);1186}else{1187return$cgi->a({-href =>$href, -class=>"list subject"},1188 esc_html($long) .$extra);1189}1190}11911192# format git diff header line, i.e. "diff --(git|combined|cc) ..."1193sub format_git_diff_header_line {1194my$line=shift;1195my$diffinfo=shift;1196my($from,$to) =@_;11971198if($diffinfo->{'nparents'}) {1199# combined diff1200$line=~s!^(diff (.*?) )"?.*$!$1!;1201if($to->{'href'}) {1202$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1203 esc_path($to->{'file'}));1204}else{# file was deleted (no href)1205$line.= esc_path($to->{'file'});1206}1207}else{1208# "ordinary" diff1209$line=~s!^(diff (.*?) )"?a/.*$!$1!;1210if($from->{'href'}) {1211$line.=$cgi->a({-href =>$from->{'href'}, -class=>"path"},1212'a/'. esc_path($from->{'file'}));1213}else{# file was added (no href)1214$line.='a/'. esc_path($from->{'file'});1215}1216$line.=' ';1217if($to->{'href'}) {1218$line.=$cgi->a({-href =>$to->{'href'}, -class=>"path"},1219'b/'. esc_path($to->{'file'}));1220}else{# file was deleted1221$line.='b/'. esc_path($to->{'file'});1222}1223}12241225return"<div class=\"diff header\">$line</div>\n";1226}12271228# format extended diff header line, before patch itself1229sub format_extended_diff_header_line {1230my$line=shift;1231my$diffinfo=shift;1232my($from,$to) =@_;12331234# match <path>1235if($line=~s!^((copy|rename) from ).*$!$1!&&$from->{'href'}) {1236$line.=$cgi->a({-href=>$from->{'href'}, -class=>"path"},1237 esc_path($from->{'file'}));1238}1239if($line=~s!^((copy|rename) to ).*$!$1!&&$to->{'href'}) {1240$line.=$cgi->a({-href=>$to->{'href'}, -class=>"path"},1241 esc_path($to->{'file'}));1242}1243# match single <mode>1244if($line=~m/\s(\d{6})$/) {1245$line.='<span class="info"> ('.1246 file_type_long($1) .1247')</span>';1248}1249# match <hash>1250if($line=~m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {1251# can match only for combined diff1252$line='index ';1253for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1254if($from->{'href'}[$i]) {1255$line.=$cgi->a({-href=>$from->{'href'}[$i],1256-class=>"hash"},1257substr($diffinfo->{'from_id'}[$i],0,7));1258}else{1259$line.='0' x 7;1260}1261# separator1262$line.=','if($i<$diffinfo->{'nparents'} -1);1263}1264$line.='..';1265if($to->{'href'}) {1266$line.=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1267substr($diffinfo->{'to_id'},0,7));1268}else{1269$line.='0' x 7;1270}12711272}elsif($line=~m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {1273# can match only for ordinary diff1274my($from_link,$to_link);1275if($from->{'href'}) {1276$from_link=$cgi->a({-href=>$from->{'href'}, -class=>"hash"},1277substr($diffinfo->{'from_id'},0,7));1278}else{1279$from_link='0' x 7;1280}1281if($to->{'href'}) {1282$to_link=$cgi->a({-href=>$to->{'href'}, -class=>"hash"},1283substr($diffinfo->{'to_id'},0,7));1284}else{1285$to_link='0' x 7;1286}1287my($from_id,$to_id) = ($diffinfo->{'from_id'},$diffinfo->{'to_id'});1288$line=~s!$from_id\.\.$to_id!$from_link..$to_link!;1289}12901291return$line."<br/>\n";1292}12931294# format from-file/to-file diff header1295sub format_diff_from_to_header {1296my($from_line,$to_line,$diffinfo,$from,$to,@parents) =@_;1297my$line;1298my$result='';12991300$line=$from_line;1301#assert($line =~ m/^---/) if DEBUG;1302# no extra formatting for "^--- /dev/null"1303if(!$diffinfo->{'nparents'}) {1304# ordinary (single parent) diff1305if($line=~m!^--- "?a/!) {1306if($from->{'href'}) {1307$line='--- a/'.1308$cgi->a({-href=>$from->{'href'}, -class=>"path"},1309 esc_path($from->{'file'}));1310}else{1311$line='--- a/'.1312 esc_path($from->{'file'});1313}1314}1315$result.= qq!<div class="diff from_file">$line</div>\n!;13161317}else{1318# combined diff (merge commit)1319for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {1320if($from->{'href'}[$i]) {1321$line='--- '.1322$cgi->a({-href=>href(action=>"blobdiff",1323 hash_parent=>$diffinfo->{'from_id'}[$i],1324 hash_parent_base=>$parents[$i],1325 file_parent=>$from->{'file'}[$i],1326 hash=>$diffinfo->{'to_id'},1327 hash_base=>$hash,1328 file_name=>$to->{'file'}),1329-class=>"path",1330-title=>"diff". ($i+1)},1331$i+1) .1332'/'.1333$cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},1334 esc_path($from->{'file'}[$i]));1335}else{1336$line='--- /dev/null';1337}1338$result.= qq!<div class="diff from_file">$line</div>\n!;1339}1340}13411342$line=$to_line;1343#assert($line =~ m/^\+\+\+/) if DEBUG;1344# no extra formatting for "^+++ /dev/null"1345if($line=~m!^\+\+\+ "?b/!) {1346if($to->{'href'}) {1347$line='+++ b/'.1348$cgi->a({-href=>$to->{'href'}, -class=>"path"},1349 esc_path($to->{'file'}));1350}else{1351$line='+++ b/'.1352 esc_path($to->{'file'});1353}1354}1355$result.= qq!<div class="diff to_file">$line</div>\n!;13561357return$result;1358}13591360# create note for patch simplified by combined diff1361sub format_diff_cc_simplified {1362my($diffinfo,@parents) =@_;1363my$result='';13641365$result.="<div class=\"diff header\">".1366"diff --cc ";1367if(!is_deleted($diffinfo)) {1368$result.=$cgi->a({-href => href(action=>"blob",1369 hash_base=>$hash,1370 hash=>$diffinfo->{'to_id'},1371 file_name=>$diffinfo->{'to_file'}),1372-class=>"path"},1373 esc_path($diffinfo->{'to_file'}));1374}else{1375$result.= esc_path($diffinfo->{'to_file'});1376}1377$result.="</div>\n".# class="diff header"1378"<div class=\"diff nodifferences\">".1379"Simple merge".1380"</div>\n";# class="diff nodifferences"13811382return$result;1383}13841385# format patch (diff) line (not to be used for diff headers)1386sub format_diff_line {1387my$line=shift;1388my($from,$to) =@_;1389my$diff_class="";13901391chomp$line;13921393if($from&&$to&&ref($from->{'href'})eq"ARRAY") {1394# combined diff1395my$prefix=substr($line,0,scalar@{$from->{'href'}});1396if($line=~m/^\@{3}/) {1397$diff_class=" chunk_header";1398}elsif($line=~m/^\\/) {1399$diff_class=" incomplete";1400}elsif($prefix=~tr/+/+/) {1401$diff_class=" add";1402}elsif($prefix=~tr/-/-/) {1403$diff_class=" rem";1404}1405}else{1406# assume ordinary diff1407my$char=substr($line,0,1);1408if($chareq'+') {1409$diff_class=" add";1410}elsif($chareq'-') {1411$diff_class=" rem";1412}elsif($chareq'@') {1413$diff_class=" chunk_header";1414}elsif($chareq"\\") {1415$diff_class=" incomplete";1416}1417}1418$line= untabify($line);1419if($from&&$to&&$line=~m/^\@{2} /) {1420my($from_text,$from_start,$from_lines,$to_text,$to_start,$to_lines,$section) =1421$line=~m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;14221423$from_lines=0unlessdefined$from_lines;1424$to_lines=0unlessdefined$to_lines;14251426if($from->{'href'}) {1427$from_text=$cgi->a({-href=>"$from->{'href'}#l$from_start",1428-class=>"list"},$from_text);1429}1430if($to->{'href'}) {1431$to_text=$cgi->a({-href=>"$to->{'href'}#l$to_start",1432-class=>"list"},$to_text);1433}1434$line="<span class=\"chunk_info\">@@$from_text$to_text@@</span>".1435"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1436return"<div class=\"diff$diff_class\">$line</div>\n";1437}elsif($from&&$to&&$line=~m/^\@{3}/) {1438my($prefix,$ranges,$section) =$line=~m/^(\@+) (.*?) \@+(.*)$/;1439my(@from_text,@from_start,@from_nlines,$to_text,$to_start,$to_nlines);14401441@from_text=split(' ',$ranges);1442for(my$i=0;$i<@from_text; ++$i) {1443($from_start[$i],$from_nlines[$i]) =1444(split(',',substr($from_text[$i],1)),0);1445}14461447$to_text=pop@from_text;1448$to_start=pop@from_start;1449$to_nlines=pop@from_nlines;14501451$line="<span class=\"chunk_info\">$prefix";1452for(my$i=0;$i<@from_text; ++$i) {1453if($from->{'href'}[$i]) {1454$line.=$cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",1455-class=>"list"},$from_text[$i]);1456}else{1457$line.=$from_text[$i];1458}1459$line.=" ";1460}1461if($to->{'href'}) {1462$line.=$cgi->a({-href=>"$to->{'href'}#l$to_start",1463-class=>"list"},$to_text);1464}else{1465$line.=$to_text;1466}1467$line.="$prefix</span>".1468"<span class=\"section\">". esc_html($section, -nbsp=>1) ."</span>";1469return"<div class=\"diff$diff_class\">$line</div>\n";1470}1471return"<div class=\"diff$diff_class\">". esc_html($line, -nbsp=>1) ."</div>\n";1472}14731474# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",1475# linked. Pass the hash of the tree/commit to snapshot.1476sub format_snapshot_links {1477my($hash) =@_;1478my@snapshot_fmts= gitweb_check_feature('snapshot');1479@snapshot_fmts= filter_snapshot_fmts(@snapshot_fmts);1480my$num_fmts=@snapshot_fmts;1481if($num_fmts>1) {1482# A parenthesized list of links bearing format names.1483# e.g. "snapshot (_tar.gz_ _zip_)"1484return"snapshot (".join(' ',map1485$cgi->a({1486-href => href(1487 action=>"snapshot",1488 hash=>$hash,1489 snapshot_format=>$_1490)1491},$known_snapshot_formats{$_}{'display'})1492,@snapshot_fmts) .")";1493}elsif($num_fmts==1) {1494# A single "snapshot" link whose tooltip bears the format name.1495# i.e. "_snapshot_"1496my($fmt) =@snapshot_fmts;1497return1498$cgi->a({1499-href => href(1500 action=>"snapshot",1501 hash=>$hash,1502 snapshot_format=>$fmt1503),1504-title =>"in format:$known_snapshot_formats{$fmt}{'display'}"1505},"snapshot");1506}else{# $num_fmts == 01507returnundef;1508}1509}15101511## ......................................................................1512## functions returning values to be passed, perhaps after some1513## transformation, to other functions; e.g. returning arguments to href()15141515# returns hash to be passed to href to generate gitweb URL1516# in -title key it returns description of link1517sub get_feed_info {1518my$format=shift||'Atom';1519my%res= (action =>lc($format));15201521# feed links are possible only for project views1522return unless(defined$project);1523# some views should link to OPML, or to generic project feed,1524# or don't have specific feed yet (so they should use generic)1525return if($action=~/^(?:tags|heads|forks|tag|search)$/x);15261527my$branch;1528# branches refs uses 'refs/heads/' prefix (fullname) to differentiate1529# from tag links; this also makes possible to detect branch links1530if((defined$hash_base&&$hash_base=~m!^refs/heads/(.*)$!) ||1531(defined$hash&&$hash=~m!^refs/heads/(.*)$!)) {1532$branch=$1;1533}1534# find log type for feed description (title)1535my$type='log';1536if(defined$file_name) {1537$type="history of$file_name";1538$type.="/"if($actioneq'tree');1539$type.=" on '$branch'"if(defined$branch);1540}else{1541$type="log of$branch"if(defined$branch);1542}15431544$res{-title} =$type;1545$res{'hash'} = (defined$branch?"refs/heads/$branch":undef);1546$res{'file_name'} =$file_name;15471548return%res;1549}15501551## ----------------------------------------------------------------------1552## git utility subroutines, invoking git commands15531554# returns path to the core git executable and the --git-dir parameter as list1555sub git_cmd {1556return$GIT,'--git-dir='.$git_dir;1557}15581559# quote the given arguments for passing them to the shell1560# quote_command("command", "arg 1", "arg with ' and ! characters")1561# => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"1562# Try to avoid using this function wherever possible.1563sub quote_command {1564returnjoin(' ',1565map( {my$a=$_;$a=~s/(['!])/'\\$1'/g;"'$a'"}@_));1566}15671568# get HEAD ref of given project as hash1569sub git_get_head_hash {1570my$project=shift;1571my$o_git_dir=$git_dir;1572my$retval=undef;1573$git_dir="$projectroot/$project";1574if(open my$fd,"-|", git_cmd(),"rev-parse","--verify","HEAD") {1575my$head= <$fd>;1576close$fd;1577if(defined$head&&$head=~/^([0-9a-fA-F]{40})$/) {1578$retval=$1;1579}1580}1581if(defined$o_git_dir) {1582$git_dir=$o_git_dir;1583}1584return$retval;1585}15861587# get type of given object1588sub git_get_type {1589my$hash=shift;15901591open my$fd,"-|", git_cmd(),"cat-file",'-t',$hashorreturn;1592my$type= <$fd>;1593close$fdorreturn;1594chomp$type;1595return$type;1596}15971598# repository configuration1599our$config_file='';1600our%config;16011602# store multiple values for single key as anonymous array reference1603# single values stored directly in the hash, not as [ <value> ]1604sub hash_set_multi {1605my($hash,$key,$value) =@_;16061607if(!exists$hash->{$key}) {1608$hash->{$key} =$value;1609}elsif(!ref$hash->{$key}) {1610$hash->{$key} = [$hash->{$key},$value];1611}else{1612push@{$hash->{$key}},$value;1613}1614}16151616# return hash of git project configuration1617# optionally limited to some section, e.g. 'gitweb'1618sub git_parse_project_config {1619my$section_regexp=shift;1620my%config;16211622local$/="\0";16231624open my$fh,"-|", git_cmd(),"config",'-z','-l',1625orreturn;16261627while(my$keyval= <$fh>) {1628chomp$keyval;1629my($key,$value) =split(/\n/,$keyval,2);16301631 hash_set_multi(\%config,$key,$value)1632if(!defined$section_regexp||$key=~/^(?:$section_regexp)\./o);1633}1634close$fh;16351636return%config;1637}16381639# convert config value to boolean, 'true' or 'false'1640# no value, number > 0, 'true' and 'yes' values are true1641# rest of values are treated as false (never as error)1642sub config_to_bool {1643my$val=shift;16441645# strip leading and trailing whitespace1646$val=~s/^\s+//;1647$val=~s/\s+$//;16481649return(!defined$val||# section.key1650($val=~/^\d+$/&&$val) ||# section.key = 11651($val=~/^(?:true|yes)$/i));# section.key = true1652}16531654# convert config value to simple decimal number1655# an optional value suffix of 'k', 'm', or 'g' will cause the value1656# to be multiplied by 1024, 1048576, or 10737418241657sub config_to_int {1658my$val=shift;16591660# strip leading and trailing whitespace1661$val=~s/^\s+//;1662$val=~s/\s+$//;16631664if(my($num,$unit) = ($val=~/^([0-9]*)([kmg])$/i)) {1665$unit=lc($unit);1666# unknown unit is treated as 11667return$num* ($uniteq'g'?1073741824:1668$uniteq'm'?1048576:1669$uniteq'k'?1024:1);1670}1671return$val;1672}16731674# convert config value to array reference, if needed1675sub config_to_multi {1676my$val=shift;16771678returnref($val) ?$val: (defined($val) ? [$val] : []);1679}16801681sub git_get_project_config {1682my($key,$type) =@_;16831684# key sanity check1685return unless($key);1686$key=~s/^gitweb\.//;1687return if($key=~m/\W/);16881689# type sanity check1690if(defined$type) {1691$type=~s/^--//;1692$type=undef1693unless($typeeq'bool'||$typeeq'int');1694}16951696# get config1697if(!defined$config_file||1698$config_filene"$git_dir/config") {1699%config= git_parse_project_config('gitweb');1700$config_file="$git_dir/config";1701}17021703# ensure given type1704if(!defined$type) {1705return$config{"gitweb.$key"};1706}elsif($typeeq'bool') {1707# backward compatibility: 'git config --bool' returns true/false1708return config_to_bool($config{"gitweb.$key"}) ?'true':'false';1709}elsif($typeeq'int') {1710return config_to_int($config{"gitweb.$key"});1711}1712return$config{"gitweb.$key"};1713}17141715# get hash of given path at given ref1716sub git_get_hash_by_path {1717my$base=shift;1718my$path=shift||returnundef;1719my$type=shift;17201721$path=~ s,/+$,,;17221723open my$fd,"-|", git_cmd(),"ls-tree",$base,"--",$path1724or die_error(500,"Open git-ls-tree failed");1725my$line= <$fd>;1726close$fdorreturnundef;17271728if(!defined$line) {1729# there is no tree or hash given by $path at $base1730returnundef;1731}17321733#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'1734$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;1735if(defined$type&&$typene$2) {1736# type doesn't match1737returnundef;1738}1739return$3;1740}17411742# get path of entry with given hash at given tree-ish (ref)1743# used to get 'from' filename for combined diff (merge commit) for renames1744sub git_get_path_by_hash {1745my$base=shift||return;1746my$hash=shift||return;17471748local$/="\0";17491750open my$fd,"-|", git_cmd(),"ls-tree",'-r','-t','-z',$base1751orreturnundef;1752while(my$line= <$fd>) {1753chomp$line;17541755#'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'1756#'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'1757if($line=~m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {1758close$fd;1759return$1;1760}1761}1762close$fd;1763returnundef;1764}17651766## ......................................................................1767## git utility functions, directly accessing git repository17681769sub git_get_project_description {1770my$path=shift;17711772$git_dir="$projectroot/$path";1773open my$fd,"$git_dir/description"1774orreturn git_get_project_config('description');1775my$descr= <$fd>;1776close$fd;1777if(defined$descr) {1778chomp$descr;1779}1780return$descr;1781}17821783sub git_get_project_ctags {1784my$path=shift;1785my$ctags= {};17861787$git_dir="$projectroot/$path";1788foreach(<$git_dir/ctags/*>) {1789open CT,$_ornext;1790my$val= <CT>;1791chomp$val;1792close CT;1793my$ctag=$_;$ctag=~ s#.*/##;1794$ctags->{$ctag} =$val;1795}1796$ctags;1797}17981799sub git_populate_project_tagcloud {1800my$ctags=shift;18011802# First, merge different-cased tags; tags vote on casing1803my%ctags_lc;1804foreach(keys%$ctags) {1805$ctags_lc{lc$_}->{count} +=$ctags->{$_};1806if(not$ctags_lc{lc$_}->{topcount}1807or$ctags_lc{lc$_}->{topcount} <$ctags->{$_}) {1808$ctags_lc{lc$_}->{topcount} =$ctags->{$_};1809$ctags_lc{lc$_}->{topname} =$_;1810}1811}18121813my$cloud;1814if(eval{require HTML::TagCloud;1; }) {1815$cloud= HTML::TagCloud->new;1816foreach(sort keys%ctags_lc) {1817# Pad the title with spaces so that the cloud looks1818# less crammed.1819my$title=$ctags_lc{$_}->{topname};1820$title=~s/ / /g;1821$title=~s/^/ /g;1822$title=~s/$/ /g;1823$cloud->add($title,$home_link."?by_tag=".$_,$ctags_lc{$_}->{count});1824}1825}else{1826$cloud= \%ctags_lc;1827}1828$cloud;1829}18301831sub git_show_project_tagcloud {1832my($cloud,$count) =@_;1833print STDERR ref($cloud)."..\n";1834if(ref$cloudeq'HTML::TagCloud') {1835return$cloud->html_and_css($count);1836}else{1837my@tags=sort{$cloud->{$a}->{count} <=>$cloud->{$b}->{count} }keys%$cloud;1838return'<p align="center">'.join(', ',map{1839"<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"1840}splice(@tags,0,$count)) .'</p>';1841}1842}18431844sub git_get_project_url_list {1845my$path=shift;18461847$git_dir="$projectroot/$path";1848open my$fd,"$git_dir/cloneurl"1849orreturnwantarray?1850@{ config_to_multi(git_get_project_config('url')) } :1851 config_to_multi(git_get_project_config('url'));1852my@git_project_url_list=map{chomp;$_} <$fd>;1853close$fd;18541855returnwantarray?@git_project_url_list: \@git_project_url_list;1856}18571858sub git_get_projects_list {1859my($filter) =@_;1860my@list;18611862$filter||='';1863$filter=~s/\.git$//;18641865my($check_forks) = gitweb_check_feature('forks');18661867if(-d $projects_list) {1868# search in directory1869my$dir=$projects_list. ($filter?"/$filter":'');1870# remove the trailing "/"1871$dir=~s!/+$!!;1872my$pfxlen=length("$dir");1873my$pfxdepth= ($dir=~tr!/!!);18741875 File::Find::find({1876 follow_fast =>1,# follow symbolic links1877 follow_skip =>2,# ignore duplicates1878 dangling_symlinks =>0,# ignore dangling symlinks, silently1879 wanted =>sub{1880# skip project-list toplevel, if we get it.1881return if(m!^[/.]$!);1882# only directories can be git repositories1883return unless(-d $_);1884# don't traverse too deep (Find is super slow on os x)1885if(($File::Find::name =~tr!/!!) -$pfxdepth>$project_maxdepth) {1886$File::Find::prune =1;1887return;1888}18891890my$subdir=substr($File::Find::name,$pfxlen+1);1891# we check related file in $projectroot1892if(check_export_ok("$projectroot/$filter/$subdir")) {1893push@list, { path => ($filter?"$filter/":'') .$subdir};1894$File::Find::prune =1;1895}1896},1897},"$dir");18981899}elsif(-f $projects_list) {1900# read from file(url-encoded):1901# 'git%2Fgit.git Linus+Torvalds'1902# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'1903# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'1904my%paths;1905open my($fd),$projects_listorreturn;1906 PROJECT:1907while(my$line= <$fd>) {1908chomp$line;1909my($path,$owner) =split' ',$line;1910$path= unescape($path);1911$owner= unescape($owner);1912if(!defined$path) {1913next;1914}1915if($filterne'') {1916# looking for forks;1917my$pfx=substr($path,0,length($filter));1918if($pfxne$filter) {1919next PROJECT;1920}1921my$sfx=substr($path,length($filter));1922if($sfx!~/^\/.*\.git$/) {1923next PROJECT;1924}1925}elsif($check_forks) {1926 PATH:1927foreachmy$filter(keys%paths) {1928# looking for forks;1929my$pfx=substr($path,0,length($filter));1930if($pfxne$filter) {1931next PATH;1932}1933my$sfx=substr($path,length($filter));1934if($sfx!~/^\/.*\.git$/) {1935next PATH;1936}1937# is a fork, don't include it in1938# the list1939next PROJECT;1940}1941}1942if(check_export_ok("$projectroot/$path")) {1943my$pr= {1944 path =>$path,1945 owner => to_utf8($owner),1946};1947push@list,$pr;1948(my$forks_path=$path) =~s/\.git$//;1949$paths{$forks_path}++;1950}1951}1952close$fd;1953}1954return@list;1955}19561957our$gitweb_project_owner=undef;1958sub git_get_project_list_from_file {19591960return if(defined$gitweb_project_owner);19611962$gitweb_project_owner= {};1963# read from file (url-encoded):1964# 'git%2Fgit.git Linus+Torvalds'1965# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'1966# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'1967if(-f $projects_list) {1968open(my$fd,$projects_list);1969while(my$line= <$fd>) {1970chomp$line;1971my($pr,$ow) =split' ',$line;1972$pr= unescape($pr);1973$ow= unescape($ow);1974$gitweb_project_owner->{$pr} = to_utf8($ow);1975}1976close$fd;1977}1978}19791980sub git_get_project_owner {1981my$project=shift;1982my$owner;19831984returnundefunless$project;1985$git_dir="$projectroot/$project";19861987if(!defined$gitweb_project_owner) {1988 git_get_project_list_from_file();1989}19901991if(exists$gitweb_project_owner->{$project}) {1992$owner=$gitweb_project_owner->{$project};1993}1994if(!defined$owner){1995$owner= git_get_project_config('owner');1996}1997if(!defined$owner) {1998$owner= get_file_owner("$git_dir");1999}20002001return$owner;2002}20032004sub git_get_last_activity {2005my($path) =@_;2006my$fd;20072008$git_dir="$projectroot/$path";2009open($fd,"-|", git_cmd(),'for-each-ref',2010'--format=%(committer)',2011'--sort=-committerdate',2012'--count=1',2013'refs/heads')orreturn;2014my$most_recent= <$fd>;2015close$fdorreturn;2016if(defined$most_recent&&2017$most_recent=~/ (\d+) [-+][01]\d\d\d$/) {2018my$timestamp=$1;2019my$age=time-$timestamp;2020return($age, age_string($age));2021}2022return(undef,undef);2023}20242025sub git_get_references {2026my$type=shift||"";2027my%refs;2028# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.112029# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}2030open my$fd,"-|", git_cmd(),"show-ref","--dereference",2031($type? ("--","refs/$type") : ())# use -- <pattern> if $type2032orreturn;20332034while(my$line= <$fd>) {2035chomp$line;2036if($line=~m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {2037if(defined$refs{$1}) {2038push@{$refs{$1}},$2;2039}else{2040$refs{$1} = [$2];2041}2042}2043}2044close$fdorreturn;2045return \%refs;2046}20472048sub git_get_rev_name_tags {2049my$hash=shift||returnundef;20502051open my$fd,"-|", git_cmd(),"name-rev","--tags",$hash2052orreturn;2053my$name_rev= <$fd>;2054close$fd;20552056if($name_rev=~ m|^$hash tags/(.*)$|) {2057return$1;2058}else{2059# catches also '$hash undefined' output2060returnundef;2061}2062}20632064## ----------------------------------------------------------------------2065## parse to hash functions20662067sub parse_date {2068my$epoch=shift;2069my$tz=shift||"-0000";20702071my%date;2072my@months= ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");2073my@days= ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");2074my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($epoch);2075$date{'hour'} =$hour;2076$date{'minute'} =$min;2077$date{'mday'} =$mday;2078$date{'day'} =$days[$wday];2079$date{'month'} =$months[$mon];2080$date{'rfc2822'} =sprintf"%s,%d%s%4d%02d:%02d:%02d+0000",2081$days[$wday],$mday,$months[$mon],1900+$year,$hour,$min,$sec;2082$date{'mday-time'} =sprintf"%d%s%02d:%02d",2083$mday,$months[$mon],$hour,$min;2084$date{'iso-8601'} =sprintf"%04d-%02d-%02dT%02d:%02d:%02dZ",20851900+$year,1+$mon,$mday,$hour,$min,$sec;20862087$tz=~m/^([+\-][0-9][0-9])([0-9][0-9])$/;2088my$local=$epoch+ ((int$1+ ($2/60)) *3600);2089($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($local);2090$date{'hour_local'} =$hour;2091$date{'minute_local'} =$min;2092$date{'tz_local'} =$tz;2093$date{'iso-tz'} =sprintf("%04d-%02d-%02d%02d:%02d:%02d%s",20941900+$year,$mon+1,$mday,2095$hour,$min,$sec,$tz);2096return%date;2097}20982099sub parse_tag {2100my$tag_id=shift;2101my%tag;2102my@comment;21032104open my$fd,"-|", git_cmd(),"cat-file","tag",$tag_idorreturn;2105$tag{'id'} =$tag_id;2106while(my$line= <$fd>) {2107chomp$line;2108if($line=~m/^object ([0-9a-fA-F]{40})$/) {2109$tag{'object'} =$1;2110}elsif($line=~m/^type (.+)$/) {2111$tag{'type'} =$1;2112}elsif($line=~m/^tag (.+)$/) {2113$tag{'name'} =$1;2114}elsif($line=~m/^tagger (.*) ([0-9]+) (.*)$/) {2115$tag{'author'} =$1;2116$tag{'epoch'} =$2;2117$tag{'tz'} =$3;2118}elsif($line=~m/--BEGIN/) {2119push@comment,$line;2120last;2121}elsif($lineeq"") {2122last;2123}2124}2125push@comment, <$fd>;2126$tag{'comment'} = \@comment;2127close$fdorreturn;2128if(!defined$tag{'name'}) {2129return2130};2131return%tag2132}21332134sub parse_commit_text {2135my($commit_text,$withparents) =@_;2136my@commit_lines=split'\n',$commit_text;2137my%co;21382139pop@commit_lines;# Remove '\0'21402141if(!@commit_lines) {2142return;2143}21442145my$header=shift@commit_lines;2146if($header!~m/^[0-9a-fA-F]{40}/) {2147return;2148}2149($co{'id'},my@parents) =split' ',$header;2150while(my$line=shift@commit_lines) {2151last if$lineeq"\n";2152if($line=~m/^tree ([0-9a-fA-F]{40})$/) {2153$co{'tree'} =$1;2154}elsif((!defined$withparents) && ($line=~m/^parent ([0-9a-fA-F]{40})$/)) {2155push@parents,$1;2156}elsif($line=~m/^author (.*) ([0-9]+) (.*)$/) {2157$co{'author'} =$1;2158$co{'author_epoch'} =$2;2159$co{'author_tz'} =$3;2160if($co{'author'} =~m/^([^<]+) <([^>]*)>/) {2161$co{'author_name'} =$1;2162$co{'author_email'} =$2;2163}else{2164$co{'author_name'} =$co{'author'};2165}2166}elsif($line=~m/^committer (.*) ([0-9]+) (.*)$/) {2167$co{'committer'} =$1;2168$co{'committer_epoch'} =$2;2169$co{'committer_tz'} =$3;2170$co{'committer_name'} =$co{'committer'};2171if($co{'committer'} =~m/^([^<]+) <([^>]*)>/) {2172$co{'committer_name'} =$1;2173$co{'committer_email'} =$2;2174}else{2175$co{'committer_name'} =$co{'committer'};2176}2177}2178}2179if(!defined$co{'tree'}) {2180return;2181};2182$co{'parents'} = \@parents;2183$co{'parent'} =$parents[0];21842185foreachmy$title(@commit_lines) {2186$title=~s/^ //;2187if($titlene"") {2188$co{'title'} = chop_str($title,80,5);2189# remove leading stuff of merges to make the interesting part visible2190if(length($title) >50) {2191$title=~s/^Automatic //;2192$title=~s/^merge (of|with) /Merge ... /i;2193if(length($title) >50) {2194$title=~s/(http|rsync):\/\///;2195}2196if(length($title) >50) {2197$title=~s/(master|www|rsync)\.//;2198}2199if(length($title) >50) {2200$title=~s/kernel.org:?//;2201}2202if(length($title) >50) {2203$title=~s/\/pub\/scm//;2204}2205}2206$co{'title_short'} = chop_str($title,50,5);2207last;2208}2209}2210if(!defined$co{'title'} ||$co{'title'}eq"") {2211$co{'title'} =$co{'title_short'} ='(no commit message)';2212}2213# remove added spaces2214foreachmy$line(@commit_lines) {2215$line=~s/^ //;2216}2217$co{'comment'} = \@commit_lines;22182219my$age=time-$co{'committer_epoch'};2220$co{'age'} =$age;2221$co{'age_string'} = age_string($age);2222my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =gmtime($co{'committer_epoch'});2223if($age>60*60*24*7*2) {2224$co{'age_string_date'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2225$co{'age_string_age'} =$co{'age_string'};2226}else{2227$co{'age_string_date'} =$co{'age_string'};2228$co{'age_string_age'} =sprintf"%4i-%02u-%02i",1900+$year,$mon+1,$mday;2229}2230return%co;2231}22322233sub parse_commit {2234my($commit_id) =@_;2235my%co;22362237local$/="\0";22382239open my$fd,"-|", git_cmd(),"rev-list",2240"--parents",2241"--header",2242"--max-count=1",2243$commit_id,2244"--",2245or die_error(500,"Open git-rev-list failed");2246%co= parse_commit_text(<$fd>,1);2247close$fd;22482249return%co;2250}22512252sub parse_commits {2253my($commit_id,$maxcount,$skip,$filename,@args) =@_;2254my@cos;22552256$maxcount||=1;2257$skip||=0;22582259local$/="\0";22602261open my$fd,"-|", git_cmd(),"rev-list",2262"--header",2263@args,2264("--max-count=".$maxcount),2265("--skip=".$skip),2266@extra_options,2267$commit_id,2268"--",2269($filename? ($filename) : ())2270or die_error(500,"Open git-rev-list failed");2271while(my$line= <$fd>) {2272my%co= parse_commit_text($line);2273push@cos, \%co;2274}2275close$fd;22762277returnwantarray?@cos: \@cos;2278}22792280# parse line of git-diff-tree "raw" output2281sub parse_difftree_raw_line {2282my$line=shift;2283my%res;22842285# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'2286# ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'2287if($line=~m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {2288$res{'from_mode'} =$1;2289$res{'to_mode'} =$2;2290$res{'from_id'} =$3;2291$res{'to_id'} =$4;2292$res{'status'} =$5;2293$res{'similarity'} =$6;2294if($res{'status'}eq'R'||$res{'status'}eq'C') {# renamed or copied2295($res{'from_file'},$res{'to_file'}) =map{ unquote($_) }split("\t",$7);2296}else{2297$res{'from_file'} =$res{'to_file'} =$res{'file'} = unquote($7);2298}2299}2300# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'2301# combined diff (for merge commit)2302elsif($line=~s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {2303$res{'nparents'} =length($1);2304$res{'from_mode'} = [split(' ',$2) ];2305$res{'to_mode'} =pop@{$res{'from_mode'}};2306$res{'from_id'} = [split(' ',$3) ];2307$res{'to_id'} =pop@{$res{'from_id'}};2308$res{'status'} = [split('',$4) ];2309$res{'to_file'} = unquote($5);2310}2311# 'c512b523472485aef4fff9e57b229d9d243c967f'2312elsif($line=~m/^([0-9a-fA-F]{40})$/) {2313$res{'commit'} =$1;2314}23152316returnwantarray?%res: \%res;2317}23182319# wrapper: return parsed line of git-diff-tree "raw" output2320# (the argument might be raw line, or parsed info)2321sub parsed_difftree_line {2322my$line_or_ref=shift;23232324if(ref($line_or_ref)eq"HASH") {2325# pre-parsed (or generated by hand)2326return$line_or_ref;2327}else{2328return parse_difftree_raw_line($line_or_ref);2329}2330}23312332# parse line of git-ls-tree output2333sub parse_ls_tree_line ($;%) {2334my$line=shift;2335my%opts=@_;2336my%res;23372338#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'2339$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;23402341$res{'mode'} =$1;2342$res{'type'} =$2;2343$res{'hash'} =$3;2344if($opts{'-z'}) {2345$res{'name'} =$4;2346}else{2347$res{'name'} = unquote($4);2348}23492350returnwantarray?%res: \%res;2351}23522353# generates _two_ hashes, references to which are passed as 2 and 3 argument2354sub parse_from_to_diffinfo {2355my($diffinfo,$from,$to,@parents) =@_;23562357if($diffinfo->{'nparents'}) {2358# combined diff2359$from->{'file'} = [];2360$from->{'href'} = [];2361 fill_from_file_info($diffinfo,@parents)2362unlessexists$diffinfo->{'from_file'};2363for(my$i=0;$i<$diffinfo->{'nparents'};$i++) {2364$from->{'file'}[$i] =2365defined$diffinfo->{'from_file'}[$i] ?2366$diffinfo->{'from_file'}[$i] :2367$diffinfo->{'to_file'};2368if($diffinfo->{'status'}[$i]ne"A") {# not new (added) file2369$from->{'href'}[$i] = href(action=>"blob",2370 hash_base=>$parents[$i],2371 hash=>$diffinfo->{'from_id'}[$i],2372 file_name=>$from->{'file'}[$i]);2373}else{2374$from->{'href'}[$i] =undef;2375}2376}2377}else{2378# ordinary (not combined) diff2379$from->{'file'} =$diffinfo->{'from_file'};2380if($diffinfo->{'status'}ne"A") {# not new (added) file2381$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,2382 hash=>$diffinfo->{'from_id'},2383 file_name=>$from->{'file'});2384}else{2385delete$from->{'href'};2386}2387}23882389$to->{'file'} =$diffinfo->{'to_file'};2390if(!is_deleted($diffinfo)) {# file exists in result2391$to->{'href'} = href(action=>"blob", hash_base=>$hash,2392 hash=>$diffinfo->{'to_id'},2393 file_name=>$to->{'file'});2394}else{2395delete$to->{'href'};2396}2397}23982399## ......................................................................2400## parse to array of hashes functions24012402sub git_get_heads_list {2403my$limit=shift;2404my@headslist;24052406open my$fd,'-|', git_cmd(),'for-each-ref',2407($limit?'--count='.($limit+1) : ()),'--sort=-committerdate',2408'--format=%(objectname) %(refname) %(subject)%00%(committer)',2409'refs/heads'2410orreturn;2411while(my$line= <$fd>) {2412my%ref_item;24132414chomp$line;2415my($refinfo,$committerinfo) =split(/\0/,$line);2416my($hash,$name,$title) =split(' ',$refinfo,3);2417my($committer,$epoch,$tz) =2418($committerinfo=~/^(.*) ([0-9]+) (.*)$/);2419$ref_item{'fullname'} =$name;2420$name=~s!^refs/heads/!!;24212422$ref_item{'name'} =$name;2423$ref_item{'id'} =$hash;2424$ref_item{'title'} =$title||'(no commit message)';2425$ref_item{'epoch'} =$epoch;2426if($epoch) {2427$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2428}else{2429$ref_item{'age'} ="unknown";2430}24312432push@headslist, \%ref_item;2433}2434close$fd;24352436returnwantarray?@headslist: \@headslist;2437}24382439sub git_get_tags_list {2440my$limit=shift;2441my@tagslist;24422443open my$fd,'-|', git_cmd(),'for-each-ref',2444($limit?'--count='.($limit+1) : ()),'--sort=-creatordate',2445'--format=%(objectname) %(objecttype) %(refname) '.2446'%(*objectname) %(*objecttype) %(subject)%00%(creator)',2447'refs/tags'2448orreturn;2449while(my$line= <$fd>) {2450my%ref_item;24512452chomp$line;2453my($refinfo,$creatorinfo) =split(/\0/,$line);2454my($id,$type,$name,$refid,$reftype,$title) =split(' ',$refinfo,6);2455my($creator,$epoch,$tz) =2456($creatorinfo=~/^(.*) ([0-9]+) (.*)$/);2457$ref_item{'fullname'} =$name;2458$name=~s!^refs/tags/!!;24592460$ref_item{'type'} =$type;2461$ref_item{'id'} =$id;2462$ref_item{'name'} =$name;2463if($typeeq"tag") {2464$ref_item{'subject'} =$title;2465$ref_item{'reftype'} =$reftype;2466$ref_item{'refid'} =$refid;2467}else{2468$ref_item{'reftype'} =$type;2469$ref_item{'refid'} =$id;2470}24712472if($typeeq"tag"||$typeeq"commit") {2473$ref_item{'epoch'} =$epoch;2474if($epoch) {2475$ref_item{'age'} = age_string(time-$ref_item{'epoch'});2476}else{2477$ref_item{'age'} ="unknown";2478}2479}24802481push@tagslist, \%ref_item;2482}2483close$fd;24842485returnwantarray?@tagslist: \@tagslist;2486}24872488## ----------------------------------------------------------------------2489## filesystem-related functions24902491sub get_file_owner {2492my$path=shift;24932494my($dev,$ino,$mode,$nlink,$st_uid,$st_gid,$rdev,$size) =stat($path);2495my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =getpwuid($st_uid);2496if(!defined$gcos) {2497returnundef;2498}2499my$owner=$gcos;2500$owner=~s/[,;].*$//;2501return to_utf8($owner);2502}25032504## ......................................................................2505## mimetype related functions25062507sub mimetype_guess_file {2508my$filename=shift;2509my$mimemap=shift;2510-r $mimemaporreturnundef;25112512my%mimemap;2513open(MIME,$mimemap)orreturnundef;2514while(<MIME>) {2515next ifm/^#/;# skip comments2516my($mime,$exts) =split(/\t+/);2517if(defined$exts) {2518my@exts=split(/\s+/,$exts);2519foreachmy$ext(@exts) {2520$mimemap{$ext} =$mime;2521}2522}2523}2524close(MIME);25252526$filename=~/\.([^.]*)$/;2527return$mimemap{$1};2528}25292530sub mimetype_guess {2531my$filename=shift;2532my$mime;2533$filename=~/\./orreturnundef;25342535if($mimetypes_file) {2536my$file=$mimetypes_file;2537if($file!~m!^/!) {# if it is relative path2538# it is relative to project2539$file="$projectroot/$project/$file";2540}2541$mime= mimetype_guess_file($filename,$file);2542}2543$mime||= mimetype_guess_file($filename,'/etc/mime.types');2544return$mime;2545}25462547sub blob_mimetype {2548my$fd=shift;2549my$filename=shift;25502551if($filename) {2552my$mime= mimetype_guess($filename);2553$mimeandreturn$mime;2554}25552556# just in case2557return$default_blob_plain_mimetypeunless$fd;25582559if(-T $fd) {2560return'text/plain';2561}elsif(!$filename) {2562return'application/octet-stream';2563}elsif($filename=~m/\.png$/i) {2564return'image/png';2565}elsif($filename=~m/\.gif$/i) {2566return'image/gif';2567}elsif($filename=~m/\.jpe?g$/i) {2568return'image/jpeg';2569}else{2570return'application/octet-stream';2571}2572}25732574sub blob_contenttype {2575my($fd,$file_name,$type) =@_;25762577$type||= blob_mimetype($fd,$file_name);2578if($typeeq'text/plain'&&defined$default_text_plain_charset) {2579$type.="; charset=$default_text_plain_charset";2580}25812582return$type;2583}25842585## ======================================================================2586## functions printing HTML: header, footer, error page25872588sub git_header_html {2589my$status=shift||"200 OK";2590my$expires=shift;25912592my$title="$site_name";2593if(defined$project) {2594$title.=" - ". to_utf8($project);2595if(defined$action) {2596$title.="/$action";2597if(defined$file_name) {2598$title.=" - ". esc_path($file_name);2599if($actioneq"tree"&&$file_name!~ m|/$|) {2600$title.="/";2601}2602}2603}2604}2605my$content_type;2606# require explicit support from the UA if we are to send the page as2607# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.2608# we have to do this because MSIE sometimes globs '*/*', pretending to2609# support xhtml+xml but choking when it gets what it asked for.2610if(defined$cgi->http('HTTP_ACCEPT') &&2611$cgi->http('HTTP_ACCEPT') =~m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&2612$cgi->Accept('application/xhtml+xml') !=0) {2613$content_type='application/xhtml+xml';2614}else{2615$content_type='text/html';2616}2617print$cgi->header(-type=>$content_type, -charset =>'utf-8',2618-status=>$status, -expires =>$expires);2619my$mod_perl_version=$ENV{'MOD_PERL'} ?"$ENV{'MOD_PERL'}":'';2620print<<EOF;2621<?xml version="1.0" encoding="utf-8"?>2622<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">2623<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">2624<!-- git web interface version$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->2625<!-- git core binaries version$git_version-->2626<head>2627<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>2628<meta name="generator" content="gitweb/$versiongit/$git_version$mod_perl_version"/>2629<meta name="robots" content="index, nofollow"/>2630<title>$title</title>2631EOF2632# print out each stylesheet that exist2633if(defined$stylesheet) {2634#provides backwards capability for those people who define style sheet in a config file2635print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";2636}else{2637foreachmy$stylesheet(@stylesheets) {2638next unless$stylesheet;2639print'<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";2640}2641}2642if(defined$project) {2643my%href_params= get_feed_info();2644if(!exists$href_params{'-title'}) {2645$href_params{'-title'} ='log';2646}26472648foreachmy$formatqw(RSS Atom){2649my$type=lc($format);2650my%link_attr= (2651'-rel'=>'alternate',2652'-title'=>"$project-$href_params{'-title'} -$formatfeed",2653'-type'=>"application/$type+xml"2654);26552656$href_params{'action'} =$type;2657$link_attr{'-href'} = href(%href_params);2658print"<link ".2659"rel=\"$link_attr{'-rel'}\"".2660"title=\"$link_attr{'-title'}\"".2661"href=\"$link_attr{'-href'}\"".2662"type=\"$link_attr{'-type'}\"".2663"/>\n";26642665$href_params{'extra_options'} ='--no-merges';2666$link_attr{'-href'} = href(%href_params);2667$link_attr{'-title'} .=' (no merges)';2668print"<link ".2669"rel=\"$link_attr{'-rel'}\"".2670"title=\"$link_attr{'-title'}\"".2671"href=\"$link_attr{'-href'}\"".2672"type=\"$link_attr{'-type'}\"".2673"/>\n";2674}26752676}else{2677printf('<link rel="alternate" title="%sprojects list" '.2678'href="%s" type="text/plain; charset=utf-8" />'."\n",2679$site_name, href(project=>undef, action=>"project_index"));2680printf('<link rel="alternate" title="%sprojects feeds" '.2681'href="%s" type="text/x-opml" />'."\n",2682$site_name, href(project=>undef, action=>"opml"));2683}2684if(defined$favicon) {2685printqq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);2686}26872688print"</head>\n".2689"<body>\n";26902691if(-f $site_header) {2692open(my$fd,$site_header);2693print<$fd>;2694close$fd;2695}26962697print"<div class=\"page_header\">\n".2698$cgi->a({-href => esc_url($logo_url),2699-title =>$logo_label},2700qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));2701print$cgi->a({-href => esc_url($home_link)},$home_link_str) ." / ";2702if(defined$project) {2703print$cgi->a({-href => href(action=>"summary")}, esc_html($project));2704if(defined$action) {2705print" /$action";2706}2707print"\n";2708}2709print"</div>\n";27102711my($have_search) = gitweb_check_feature('search');2712if(defined$project&&$have_search) {2713if(!defined$searchtext) {2714$searchtext="";2715}2716my$search_hash;2717if(defined$hash_base) {2718$search_hash=$hash_base;2719}elsif(defined$hash) {2720$search_hash=$hash;2721}else{2722$search_hash="HEAD";2723}2724my$action=$my_uri;2725my($use_pathinfo) = gitweb_check_feature('pathinfo');2726if($use_pathinfo) {2727$action.="/".esc_url($project);2728}2729print$cgi->startform(-method=>"get", -action =>$action) .2730"<div class=\"search\">\n".2731(!$use_pathinfo&&2732$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) ."\n") .2733$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) ."\n".2734$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) ."\n".2735$cgi->popup_menu(-name =>'st', -default=>'commit',2736-values=> ['commit','grep','author','committer','pickaxe']) .2737$cgi->sup($cgi->a({-href => href(action=>"search_help")},"?")) .2738" search:\n",2739$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".2740"<span title=\"Extended regular expression\">".2741$cgi->checkbox(-name =>'sr', -value =>1, -label =>'re',2742-checked =>$search_use_regexp) .2743"</span>".2744"</div>".2745$cgi->end_form() ."\n";2746}2747}27482749sub git_footer_html {2750my$feed_class='rss_logo';27512752print"<div class=\"page_footer\">\n";2753if(defined$project) {2754my$descr= git_get_project_description($project);2755if(defined$descr) {2756print"<div class=\"page_footer_text\">". esc_html($descr) ."</div>\n";2757}27582759my%href_params= get_feed_info();2760if(!%href_params) {2761$feed_class.=' generic';2762}2763$href_params{'-title'} ||='log';27642765foreachmy$formatqw(RSS Atom){2766$href_params{'action'} =lc($format);2767print$cgi->a({-href => href(%href_params),2768-title =>"$href_params{'-title'}$formatfeed",2769-class=>$feed_class},$format)."\n";2770}27712772}else{2773print$cgi->a({-href => href(project=>undef, action=>"opml"),2774-class=>$feed_class},"OPML") ." ";2775print$cgi->a({-href => href(project=>undef, action=>"project_index"),2776-class=>$feed_class},"TXT") ."\n";2777}2778print"</div>\n";# class="page_footer"27792780if(-f $site_footer) {2781open(my$fd,$site_footer);2782print<$fd>;2783close$fd;2784}27852786print"</body>\n".2787"</html>";2788}27892790# die_error(<http_status_code>, <error_message>)2791# Example: die_error(404, 'Hash not found')2792# By convention, use the following status codes (as defined in RFC 2616):2793# 400: Invalid or missing CGI parameters, or2794# requested object exists but has wrong type.2795# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on2796# this server or project.2797# 404: Requested object/revision/project doesn't exist.2798# 500: The server isn't configured properly, or2799# an internal error occurred (e.g. failed assertions caused by bugs), or2800# an unknown error occurred (e.g. the git binary died unexpectedly).2801sub die_error {2802my$status=shift||500;2803my$error=shift||"Internal server error";28042805my%http_responses= (400=>'400 Bad Request',2806403=>'403 Forbidden',2807404=>'404 Not Found',2808500=>'500 Internal Server Error');2809 git_header_html($http_responses{$status});2810print<<EOF;2811<div class="page_body">2812<br /><br />2813$status-$error2814<br />2815</div>2816EOF2817 git_footer_html();2818exit;2819}28202821## ----------------------------------------------------------------------2822## functions printing or outputting HTML: navigation28232824sub git_print_page_nav {2825my($current,$suppress,$head,$treehead,$treebase,$extra) =@_;2826$extra=''if!defined$extra;# pager or formats28272828my@navs=qw(summary shortlog log commit commitdiff tree);2829if($suppress) {2830@navs=grep{$_ne$suppress}@navs;2831}28322833my%arg=map{$_=> {action=>$_} }@navs;2834if(defined$head) {2835for(qw(commit commitdiff)) {2836$arg{$_}{'hash'} =$head;2837}2838if($current=~m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {2839for(qw(shortlog log)) {2840$arg{$_}{'hash'} =$head;2841}2842}2843}2844$arg{'tree'}{'hash'} =$treeheadifdefined$treehead;2845$arg{'tree'}{'hash_base'} =$treebaseifdefined$treebase;28462847print"<div class=\"page_nav\">\n".2848(join" | ",2849map{$_eq$current?2850$_:$cgi->a({-href => href(%{$arg{$_}})},"$_")2851}@navs);2852print"<br/>\n$extra<br/>\n".2853"</div>\n";2854}28552856sub format_paging_nav {2857my($action,$hash,$head,$page,$has_next_link) =@_;2858my$paging_nav;285928602861if($hashne$head||$page) {2862$paging_nav.=$cgi->a({-href => href(action=>$action)},"HEAD");2863}else{2864$paging_nav.="HEAD";2865}28662867if($page>0) {2868$paging_nav.=" ⋅ ".2869$cgi->a({-href => href(-replay=>1, page=>$page-1),2870-accesskey =>"p", -title =>"Alt-p"},"prev");2871}else{2872$paging_nav.=" ⋅ prev";2873}28742875if($has_next_link) {2876$paging_nav.=" ⋅ ".2877$cgi->a({-href => href(-replay=>1, page=>$page+1),2878-accesskey =>"n", -title =>"Alt-n"},"next");2879}else{2880$paging_nav.=" ⋅ next";2881}28822883return$paging_nav;2884}28852886## ......................................................................2887## functions printing or outputting HTML: div28882889sub git_print_header_div {2890my($action,$title,$hash,$hash_base) =@_;2891my%args= ();28922893$args{'action'} =$action;2894$args{'hash'} =$hashif$hash;2895$args{'hash_base'} =$hash_baseif$hash_base;28962897print"<div class=\"header\">\n".2898$cgi->a({-href => href(%args), -class=>"title"},2899$title?$title:$action) .2900"\n</div>\n";2901}29022903#sub git_print_authorship (\%) {2904sub git_print_authorship {2905my$co=shift;29062907my%ad= parse_date($co->{'author_epoch'},$co->{'author_tz'});2908print"<div class=\"author_date\">".2909 esc_html($co->{'author_name'}) .2910" [$ad{'rfc2822'}";2911if($ad{'hour_local'} <6) {2912printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",2913$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});2914}else{2915printf(" (%02d:%02d%s)",2916$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});2917}2918print"]</div>\n";2919}29202921sub git_print_page_path {2922my$name=shift;2923my$type=shift;2924my$hb=shift;292529262927print"<div class=\"page_path\">";2928print$cgi->a({-href => href(action=>"tree", hash_base=>$hb),2929-title =>'tree root'}, to_utf8("[$project]"));2930print" / ";2931if(defined$name) {2932my@dirname=split'/',$name;2933my$basename=pop@dirname;2934my$fullname='';29352936foreachmy$dir(@dirname) {2937$fullname.= ($fullname?'/':'') .$dir;2938print$cgi->a({-href => href(action=>"tree", file_name=>$fullname,2939 hash_base=>$hb),2940-title =>$fullname}, esc_path($dir));2941print" / ";2942}2943if(defined$type&&$typeeq'blob') {2944print$cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,2945 hash_base=>$hb),2946-title =>$name}, esc_path($basename));2947}elsif(defined$type&&$typeeq'tree') {2948print$cgi->a({-href => href(action=>"tree", file_name=>$file_name,2949 hash_base=>$hb),2950-title =>$name}, esc_path($basename));2951print" / ";2952}else{2953print esc_path($basename);2954}2955}2956print"<br/></div>\n";2957}29582959# sub git_print_log (\@;%) {2960sub git_print_log ($;%) {2961my$log=shift;2962my%opts=@_;29632964if($opts{'-remove_title'}) {2965# remove title, i.e. first line of log2966shift@$log;2967}2968# remove leading empty lines2969while(defined$log->[0] &&$log->[0]eq"") {2970shift@$log;2971}29722973# print log2974my$signoff=0;2975my$empty=0;2976foreachmy$line(@$log) {2977if($line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {2978$signoff=1;2979$empty=0;2980if(!$opts{'-remove_signoff'}) {2981print"<span class=\"signoff\">". esc_html($line) ."</span><br/>\n";2982next;2983}else{2984# remove signoff lines2985next;2986}2987}else{2988$signoff=0;2989}29902991# print only one empty line2992# do not print empty line after signoff2993if($lineeq"") {2994next if($empty||$signoff);2995$empty=1;2996}else{2997$empty=0;2998}29993000print format_log_line_html($line) ."<br/>\n";3001}30023003if($opts{'-final_empty_line'}) {3004# end with single empty line3005print"<br/>\n"unless$empty;3006}3007}30083009# return link target (what link points to)3010sub git_get_link_target {3011my$hash=shift;3012my$link_target;30133014# read link3015open my$fd,"-|", git_cmd(),"cat-file","blob",$hash3016orreturn;3017{3018local$/;3019$link_target= <$fd>;3020}3021close$fd3022orreturn;30233024return$link_target;3025}30263027# given link target, and the directory (basedir) the link is in,3028# return target of link relative to top directory (top tree);3029# return undef if it is not possible (including absolute links).3030sub normalize_link_target {3031my($link_target,$basedir,$hash_base) =@_;30323033# we can normalize symlink target only if $hash_base is provided3034return unless$hash_base;30353036# absolute symlinks (beginning with '/') cannot be normalized3037return if(substr($link_target,0,1)eq'/');30383039# normalize link target to path from top (root) tree (dir)3040my$path;3041if($basedir) {3042$path=$basedir.'/'.$link_target;3043}else{3044# we are in top (root) tree (dir)3045$path=$link_target;3046}30473048# remove //, /./, and /../3049my@path_parts;3050foreachmy$part(split('/',$path)) {3051# discard '.' and ''3052next if(!$part||$parteq'.');3053# handle '..'3054if($parteq'..') {3055if(@path_parts) {3056pop@path_parts;3057}else{3058# link leads outside repository (outside top dir)3059return;3060}3061}else{3062push@path_parts,$part;3063}3064}3065$path=join('/',@path_parts);30663067return$path;3068}30693070# print tree entry (row of git_tree), but without encompassing <tr> element3071sub git_print_tree_entry {3072my($t,$basedir,$hash_base,$have_blame) =@_;30733074my%base_key= ();3075$base_key{'hash_base'} =$hash_baseifdefined$hash_base;30763077# The format of a table row is: mode list link. Where mode is3078# the mode of the entry, list is the name of the entry, an href,3079# and link is the action links of the entry.30803081print"<td class=\"mode\">". mode_str($t->{'mode'}) ."</td>\n";3082if($t->{'type'}eq"blob") {3083print"<td class=\"list\">".3084$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3085 file_name=>"$basedir$t->{'name'}",%base_key),3086-class=>"list"}, esc_path($t->{'name'}));3087if(S_ISLNK(oct$t->{'mode'})) {3088my$link_target= git_get_link_target($t->{'hash'});3089if($link_target) {3090my$norm_target= normalize_link_target($link_target,$basedir,$hash_base);3091if(defined$norm_target) {3092print" -> ".3093$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,3094 file_name=>$norm_target),3095-title =>$norm_target}, esc_path($link_target));3096}else{3097print" -> ". esc_path($link_target);3098}3099}3100}3101print"</td>\n";3102print"<td class=\"link\">";3103print$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},3104 file_name=>"$basedir$t->{'name'}",%base_key)},3105"blob");3106if($have_blame) {3107print" | ".3108$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},3109 file_name=>"$basedir$t->{'name'}",%base_key)},3110"blame");3111}3112if(defined$hash_base) {3113print" | ".3114$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3115 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},3116"history");3117}3118print" | ".3119$cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,3120 file_name=>"$basedir$t->{'name'}")},3121"raw");3122print"</td>\n";31233124}elsif($t->{'type'}eq"tree") {3125print"<td class=\"list\">";3126print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3127 file_name=>"$basedir$t->{'name'}",%base_key)},3128 esc_path($t->{'name'}));3129print"</td>\n";3130print"<td class=\"link\">";3131print$cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},3132 file_name=>"$basedir$t->{'name'}",%base_key)},3133"tree");3134if(defined$hash_base) {3135print" | ".3136$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,3137 file_name=>"$basedir$t->{'name'}")},3138"history");3139}3140print"</td>\n";3141}else{3142# unknown object: we can only present history for it3143# (this includes 'commit' object, i.e. submodule support)3144print"<td class=\"list\">".3145 esc_path($t->{'name'}) .3146"</td>\n";3147print"<td class=\"link\">";3148if(defined$hash_base) {3149print$cgi->a({-href => href(action=>"history",3150 hash_base=>$hash_base,3151 file_name=>"$basedir$t->{'name'}")},3152"history");3153}3154print"</td>\n";3155}3156}31573158## ......................................................................3159## functions printing large fragments of HTML31603161# get pre-image filenames for merge (combined) diff3162sub fill_from_file_info {3163my($diff,@parents) =@_;31643165$diff->{'from_file'} = [ ];3166$diff->{'from_file'}[$diff->{'nparents'} -1] =undef;3167for(my$i=0;$i<$diff->{'nparents'};$i++) {3168if($diff->{'status'}[$i]eq'R'||3169$diff->{'status'}[$i]eq'C') {3170$diff->{'from_file'}[$i] =3171 git_get_path_by_hash($parents[$i],$diff->{'from_id'}[$i]);3172}3173}31743175return$diff;3176}31773178# is current raw difftree line of file deletion3179sub is_deleted {3180my$diffinfo=shift;31813182return$diffinfo->{'to_id'}eq('0' x 40);3183}31843185# does patch correspond to [previous] difftree raw line3186# $diffinfo - hashref of parsed raw diff format3187# $patchinfo - hashref of parsed patch diff format3188# (the same keys as in $diffinfo)3189sub is_patch_split {3190my($diffinfo,$patchinfo) =@_;31913192returndefined$diffinfo&&defined$patchinfo3193&&$diffinfo->{'to_file'}eq$patchinfo->{'to_file'};3194}319531963197sub git_difftree_body {3198my($difftree,$hash,@parents) =@_;3199my($parent) =$parents[0];3200my($have_blame) = gitweb_check_feature('blame');3201print"<div class=\"list_head\">\n";3202if($#{$difftree} >10) {3203print(($#{$difftree} +1) ." files changed:\n");3204}3205print"</div>\n";32063207print"<table class=\"".3208(@parents>1?"combined ":"") .3209"diff_tree\">\n";32103211# header only for combined diff in 'commitdiff' view3212my$has_header=@$difftree&&@parents>1&&$actioneq'commitdiff';3213if($has_header) {3214# table header3215print"<thead><tr>\n".3216"<th></th><th></th>\n";# filename, patchN link3217for(my$i=0;$i<@parents;$i++) {3218my$par=$parents[$i];3219print"<th>".3220$cgi->a({-href => href(action=>"commitdiff",3221 hash=>$hash, hash_parent=>$par),3222-title =>'commitdiff to parent number '.3223($i+1) .': '.substr($par,0,7)},3224$i+1) .3225" </th>\n";3226}3227print"</tr></thead>\n<tbody>\n";3228}32293230my$alternate=1;3231my$patchno=0;3232foreachmy$line(@{$difftree}) {3233my$diff= parsed_difftree_line($line);32343235if($alternate) {3236print"<tr class=\"dark\">\n";3237}else{3238print"<tr class=\"light\">\n";3239}3240$alternate^=1;32413242if(exists$diff->{'nparents'}) {# combined diff32433244 fill_from_file_info($diff,@parents)3245unlessexists$diff->{'from_file'};32463247if(!is_deleted($diff)) {3248# file exists in the result (child) commit3249print"<td>".3250$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3251 file_name=>$diff->{'to_file'},3252 hash_base=>$hash),3253-class=>"list"}, esc_path($diff->{'to_file'})) .3254"</td>\n";3255}else{3256print"<td>".3257 esc_path($diff->{'to_file'}) .3258"</td>\n";3259}32603261if($actioneq'commitdiff') {3262# link to patch3263$patchno++;3264print"<td class=\"link\">".3265$cgi->a({-href =>"#patch$patchno"},"patch") .3266" | ".3267"</td>\n";3268}32693270my$has_history=0;3271my$not_deleted=0;3272for(my$i=0;$i<$diff->{'nparents'};$i++) {3273my$hash_parent=$parents[$i];3274my$from_hash=$diff->{'from_id'}[$i];3275my$from_path=$diff->{'from_file'}[$i];3276my$status=$diff->{'status'}[$i];32773278$has_history||= ($statusne'A');3279$not_deleted||= ($statusne'D');32803281if($statuseq'A') {3282print"<td class=\"link\"align=\"right\"> | </td>\n";3283}elsif($statuseq'D') {3284print"<td class=\"link\">".3285$cgi->a({-href => href(action=>"blob",3286 hash_base=>$hash,3287 hash=>$from_hash,3288 file_name=>$from_path)},3289"blob". ($i+1)) .3290" | </td>\n";3291}else{3292if($diff->{'to_id'}eq$from_hash) {3293print"<td class=\"link nochange\">";3294}else{3295print"<td class=\"link\">";3296}3297print$cgi->a({-href => href(action=>"blobdiff",3298 hash=>$diff->{'to_id'},3299 hash_parent=>$from_hash,3300 hash_base=>$hash,3301 hash_parent_base=>$hash_parent,3302 file_name=>$diff->{'to_file'},3303 file_parent=>$from_path)},3304"diff". ($i+1)) .3305" | </td>\n";3306}3307}33083309print"<td class=\"link\">";3310if($not_deleted) {3311print$cgi->a({-href => href(action=>"blob",3312 hash=>$diff->{'to_id'},3313 file_name=>$diff->{'to_file'},3314 hash_base=>$hash)},3315"blob");3316print" | "if($has_history);3317}3318if($has_history) {3319print$cgi->a({-href => href(action=>"history",3320 file_name=>$diff->{'to_file'},3321 hash_base=>$hash)},3322"history");3323}3324print"</td>\n";33253326print"</tr>\n";3327next;# instead of 'else' clause, to avoid extra indent3328}3329# else ordinary diff33303331my($to_mode_oct,$to_mode_str,$to_file_type);3332my($from_mode_oct,$from_mode_str,$from_file_type);3333if($diff->{'to_mode'}ne('0' x 6)) {3334$to_mode_oct=oct$diff->{'to_mode'};3335if(S_ISREG($to_mode_oct)) {# only for regular file3336$to_mode_str=sprintf("%04o",$to_mode_oct&0777);# permission bits3337}3338$to_file_type= file_type($diff->{'to_mode'});3339}3340if($diff->{'from_mode'}ne('0' x 6)) {3341$from_mode_oct=oct$diff->{'from_mode'};3342if(S_ISREG($to_mode_oct)) {# only for regular file3343$from_mode_str=sprintf("%04o",$from_mode_oct&0777);# permission bits3344}3345$from_file_type= file_type($diff->{'from_mode'});3346}33473348if($diff->{'status'}eq"A") {# created3349my$mode_chng="<span class=\"file_status new\">[new$to_file_type";3350$mode_chng.=" with mode:$to_mode_str"if$to_mode_str;3351$mode_chng.="]</span>";3352print"<td>";3353print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3354 hash_base=>$hash, file_name=>$diff->{'file'}),3355-class=>"list"}, esc_path($diff->{'file'}));3356print"</td>\n";3357print"<td>$mode_chng</td>\n";3358print"<td class=\"link\">";3359if($actioneq'commitdiff') {3360# link to patch3361$patchno++;3362print$cgi->a({-href =>"#patch$patchno"},"patch");3363print" | ";3364}3365print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3366 hash_base=>$hash, file_name=>$diff->{'file'})},3367"blob");3368print"</td>\n";33693370}elsif($diff->{'status'}eq"D") {# deleted3371my$mode_chng="<span class=\"file_status deleted\">[deleted$from_file_type]</span>";3372print"<td>";3373print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3374 hash_base=>$parent, file_name=>$diff->{'file'}),3375-class=>"list"}, esc_path($diff->{'file'}));3376print"</td>\n";3377print"<td>$mode_chng</td>\n";3378print"<td class=\"link\">";3379if($actioneq'commitdiff') {3380# link to patch3381$patchno++;3382print$cgi->a({-href =>"#patch$patchno"},"patch");3383print" | ";3384}3385print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},3386 hash_base=>$parent, file_name=>$diff->{'file'})},3387"blob") ." | ";3388if($have_blame) {3389print$cgi->a({-href => href(action=>"blame", hash_base=>$parent,3390 file_name=>$diff->{'file'})},3391"blame") ." | ";3392}3393print$cgi->a({-href => href(action=>"history", hash_base=>$parent,3394 file_name=>$diff->{'file'})},3395"history");3396print"</td>\n";33973398}elsif($diff->{'status'}eq"M"||$diff->{'status'}eq"T") {# modified, or type changed3399my$mode_chnge="";3400if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3401$mode_chnge="<span class=\"file_status mode_chnge\">[changed";3402if($from_file_typene$to_file_type) {3403$mode_chnge.=" from$from_file_typeto$to_file_type";3404}3405if(($from_mode_oct&0777) != ($to_mode_oct&0777)) {3406if($from_mode_str&&$to_mode_str) {3407$mode_chnge.=" mode:$from_mode_str->$to_mode_str";3408}elsif($to_mode_str) {3409$mode_chnge.=" mode:$to_mode_str";3410}3411}3412$mode_chnge.="]</span>\n";3413}3414print"<td>";3415print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3416 hash_base=>$hash, file_name=>$diff->{'file'}),3417-class=>"list"}, esc_path($diff->{'file'}));3418print"</td>\n";3419print"<td>$mode_chnge</td>\n";3420print"<td class=\"link\">";3421if($actioneq'commitdiff') {3422# link to patch3423$patchno++;3424print$cgi->a({-href =>"#patch$patchno"},"patch") .3425" | ";3426}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3427# "commit" view and modified file (not onlu mode changed)3428print$cgi->a({-href => href(action=>"blobdiff",3429 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3430 hash_base=>$hash, hash_parent_base=>$parent,3431 file_name=>$diff->{'file'})},3432"diff") .3433" | ";3434}3435print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3436 hash_base=>$hash, file_name=>$diff->{'file'})},3437"blob") ." | ";3438if($have_blame) {3439print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3440 file_name=>$diff->{'file'})},3441"blame") ." | ";3442}3443print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3444 file_name=>$diff->{'file'})},3445"history");3446print"</td>\n";34473448}elsif($diff->{'status'}eq"R"||$diff->{'status'}eq"C") {# renamed or copied3449my%status_name= ('R'=>'moved','C'=>'copied');3450my$nstatus=$status_name{$diff->{'status'}};3451my$mode_chng="";3452if($diff->{'from_mode'} !=$diff->{'to_mode'}) {3453# mode also for directories, so we cannot use $to_mode_str3454$mode_chng=sprintf(", mode:%04o",$to_mode_oct&0777);3455}3456print"<td>".3457$cgi->a({-href => href(action=>"blob", hash_base=>$hash,3458 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),3459-class=>"list"}, esc_path($diff->{'to_file'})) ."</td>\n".3460"<td><span class=\"file_status$nstatus\">[$nstatusfrom ".3461$cgi->a({-href => href(action=>"blob", hash_base=>$parent,3462 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),3463-class=>"list"}, esc_path($diff->{'from_file'})) .3464" with ". (int$diff->{'similarity'}) ."% similarity$mode_chng]</span></td>\n".3465"<td class=\"link\">";3466if($actioneq'commitdiff') {3467# link to patch3468$patchno++;3469print$cgi->a({-href =>"#patch$patchno"},"patch") .3470" | ";3471}elsif($diff->{'to_id'}ne$diff->{'from_id'}) {3472# "commit" view and modified file (not only pure rename or copy)3473print$cgi->a({-href => href(action=>"blobdiff",3474 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},3475 hash_base=>$hash, hash_parent_base=>$parent,3476 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},3477"diff") .3478" | ";3479}3480print$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},3481 hash_base=>$parent, file_name=>$diff->{'to_file'})},3482"blob") ." | ";3483if($have_blame) {3484print$cgi->a({-href => href(action=>"blame", hash_base=>$hash,3485 file_name=>$diff->{'to_file'})},3486"blame") ." | ";3487}3488print$cgi->a({-href => href(action=>"history", hash_base=>$hash,3489 file_name=>$diff->{'to_file'})},3490"history");3491print"</td>\n";34923493}# we should not encounter Unmerged (U) or Unknown (X) status3494print"</tr>\n";3495}3496print"</tbody>"if$has_header;3497print"</table>\n";3498}34993500sub git_patchset_body {3501my($fd,$difftree,$hash,@hash_parents) =@_;3502my($hash_parent) =$hash_parents[0];35033504my$is_combined= (@hash_parents>1);3505my$patch_idx=0;3506my$patch_number=0;3507my$patch_line;3508my$diffinfo;3509my$to_name;3510my(%from,%to);35113512print"<div class=\"patchset\">\n";35133514# skip to first patch3515while($patch_line= <$fd>) {3516chomp$patch_line;35173518last if($patch_line=~m/^diff /);3519}35203521 PATCH:3522while($patch_line) {35233524# parse "git diff" header line3525if($patch_line=~m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {3526# $1 is from_name, which we do not use3527$to_name= unquote($2);3528$to_name=~s!^b/!!;3529}elsif($patch_line=~m/^diff --(cc|combined) ("?.*"?)$/) {3530# $1 is 'cc' or 'combined', which we do not use3531$to_name= unquote($2);3532}else{3533$to_name=undef;3534}35353536# check if current patch belong to current raw line3537# and parse raw git-diff line if needed3538if(is_patch_split($diffinfo, {'to_file'=>$to_name})) {3539# this is continuation of a split patch3540print"<div class=\"patch cont\">\n";3541}else{3542# advance raw git-diff output if needed3543$patch_idx++ifdefined$diffinfo;35443545# read and prepare patch information3546$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);35473548# compact combined diff output can have some patches skipped3549# find which patch (using pathname of result) we are at now;3550if($is_combined) {3551while($to_namene$diffinfo->{'to_file'}) {3552print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".3553 format_diff_cc_simplified($diffinfo,@hash_parents) .3554"</div>\n";# class="patch"35553556$patch_idx++;3557$patch_number++;35583559last if$patch_idx>$#$difftree;3560$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);3561}3562}35633564# modifies %from, %to hashes3565 parse_from_to_diffinfo($diffinfo, \%from, \%to,@hash_parents);35663567# this is first patch for raw difftree line with $patch_idx index3568# we index @$difftree array from 0, but number patches from 13569print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n";3570}35713572# git diff header3573#assert($patch_line =~ m/^diff /) if DEBUG;3574#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed3575$patch_number++;3576# print "git diff" header3577print format_git_diff_header_line($patch_line,$diffinfo,3578 \%from, \%to);35793580# print extended diff header3581print"<div class=\"diff extended_header\">\n";3582 EXTENDED_HEADER:3583while($patch_line= <$fd>) {3584chomp$patch_line;35853586last EXTENDED_HEADER if($patch_line=~m/^--- |^diff /);35873588print format_extended_diff_header_line($patch_line,$diffinfo,3589 \%from, \%to);3590}3591print"</div>\n";# class="diff extended_header"35923593# from-file/to-file diff header3594if(!$patch_line) {3595print"</div>\n";# class="patch"3596last PATCH;3597}3598next PATCH if($patch_line=~m/^diff /);3599#assert($patch_line =~ m/^---/) if DEBUG;36003601my$last_patch_line=$patch_line;3602$patch_line= <$fd>;3603chomp$patch_line;3604#assert($patch_line =~ m/^\+\+\+/) if DEBUG;36053606print format_diff_from_to_header($last_patch_line,$patch_line,3607$diffinfo, \%from, \%to,3608@hash_parents);36093610# the patch itself3611 LINE:3612while($patch_line= <$fd>) {3613chomp$patch_line;36143615next PATCH if($patch_line=~m/^diff /);36163617print format_diff_line($patch_line, \%from, \%to);3618}36193620}continue{3621print"</div>\n";# class="patch"3622}36233624# for compact combined (--cc) format, with chunk and patch simpliciaction3625# patchset might be empty, but there might be unprocessed raw lines3626for(++$patch_idxif$patch_number>0;3627$patch_idx<@$difftree;3628++$patch_idx) {3629# read and prepare patch information3630$diffinfo= parsed_difftree_line($difftree->[$patch_idx]);36313632# generate anchor for "patch" links in difftree / whatchanged part3633print"<div class=\"patch\"id=\"patch". ($patch_idx+1) ."\">\n".3634 format_diff_cc_simplified($diffinfo,@hash_parents) .3635"</div>\n";# class="patch"36363637$patch_number++;3638}36393640if($patch_number==0) {3641if(@hash_parents>1) {3642print"<div class=\"diff nodifferences\">Trivial merge</div>\n";3643}else{3644print"<div class=\"diff nodifferences\">No differences found</div>\n";3645}3646}36473648print"</div>\n";# class="patchset"3649}36503651# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36523653# fills project list info (age, description, owner, forks) for each3654# project in the list, removing invalid projects from returned list3655# NOTE: modifies $projlist, but does not remove entries from it3656sub fill_project_list_info {3657my($projlist,$check_forks) =@_;3658my@projects;36593660my$show_ctags= gitweb_check_feature('ctags');3661 PROJECT:3662foreachmy$pr(@$projlist) {3663my(@activity) = git_get_last_activity($pr->{'path'});3664unless(@activity) {3665next PROJECT;3666}3667($pr->{'age'},$pr->{'age_string'}) =@activity;3668if(!defined$pr->{'descr'}) {3669my$descr= git_get_project_description($pr->{'path'}) ||"";3670$descr= to_utf8($descr);3671$pr->{'descr_long'} =$descr;3672$pr->{'descr'} = chop_str($descr,$projects_list_description_width,5);3673}3674if(!defined$pr->{'owner'}) {3675$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") ||"";3676}3677if($check_forks) {3678my$pname=$pr->{'path'};3679if(($pname=~s/\.git$//) &&3680($pname!~/\/$/) &&3681(-d "$projectroot/$pname")) {3682$pr->{'forks'} ="-d$projectroot/$pname";3683}else{3684$pr->{'forks'} =0;3685}3686}3687$show_ctagsand$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});3688push@projects,$pr;3689}36903691return@projects;3692}36933694# print 'sort by' <th> element, either sorting by $key if $name eq $order3695# (changing $list), or generating 'sort by $name' replay link otherwise3696sub print_sort_th {3697my($str_sort,$name,$order,$key,$header,$list) =@_;3698$key||=$name;3699$header||=ucfirst($name);37003701if($ordereq$name) {3702if($str_sort) {3703@$list=sort{$a->{$key}cmp$b->{$key}}@$list;3704}else{3705@$list=sort{$a->{$key} <=>$b->{$key}}@$list;3706}3707print"<th>$header</th>\n";3708}else{3709print"<th>".3710$cgi->a({-href => href(-replay=>1, order=>$name),3711-class=>"header"},$header) .3712"</th>\n";3713}3714}37153716sub print_sort_th_str {3717 print_sort_th(1,@_);3718}37193720sub print_sort_th_num {3721 print_sort_th(0,@_);3722}37233724sub git_project_list_body {3725# actually uses global variable $project3726my($projlist,$order,$from,$to,$extra,$no_header) =@_;37273728my($check_forks) = gitweb_check_feature('forks');3729my@projects= fill_project_list_info($projlist,$check_forks);37303731$order||=$default_projects_order;3732$from=0unlessdefined$from;3733$to=$#projectsif(!defined$to||$#projects<$to);37343735my$show_ctags= gitweb_check_feature('ctags');3736if($show_ctags) {3737my%ctags;3738foreachmy$p(@projects) {3739foreachmy$ct(keys%{$p->{'ctags'}}) {3740$ctags{$ct} +=$p->{'ctags'}->{$ct};3741}3742}3743my$cloud= git_populate_project_tagcloud(\%ctags);3744print git_show_project_tagcloud($cloud,64);3745}37463747print"<table class=\"project_list\">\n";3748unless($no_header) {3749print"<tr>\n";3750if($check_forks) {3751print"<th></th>\n";3752}3753 print_sort_th_str('project',$order,'path',3754'Project', \@projects);3755 print_sort_th_str('descr',$order,'descr_long',3756'Description', \@projects);3757 print_sort_th_str('owner',$order,'owner',3758'Owner', \@projects);3759 print_sort_th_num('age',$order,'age',3760'Last Change', \@projects);3761print"<th></th>\n".# for links3762"</tr>\n";3763}3764my$alternate=1;3765my$tagfilter=$cgi->param('by_tag');3766for(my$i=$from;$i<=$to;$i++) {3767my$pr=$projects[$i];37683769next if$tagfilterand$show_ctagsand not grep{lc$_eq lc$tagfilter}keys%{$pr->{'ctags'}};3770next if$searchtextand not$pr->{'path'} =~/$searchtext/3771and not$pr->{'descr_long'} =~/$searchtext/;3772# Weed out forks or non-matching entries of search3773if($check_forks) {3774my$forkbase=$project;$forkbase||='';$forkbase=~ s#\.git$#/#;3775$forkbase="^$forkbase"if$forkbase;3776next ifnot$searchtextand not$tagfilterand$show_ctags3777and$pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe3778}37793780if($alternate) {3781print"<tr class=\"dark\">\n";3782}else{3783print"<tr class=\"light\">\n";3784}3785$alternate^=1;3786if($check_forks) {3787print"<td>";3788if($pr->{'forks'}) {3789print"<!--$pr->{'forks'} -->\n";3790print$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"+");3791}3792print"</td>\n";3793}3794print"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),3795-class=>"list"}, esc_html($pr->{'path'})) ."</td>\n".3796"<td>".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),3797-class=>"list", -title =>$pr->{'descr_long'}},3798 esc_html($pr->{'descr'})) ."</td>\n".3799"<td><i>". chop_and_escape_str($pr->{'owner'},15) ."</i></td>\n";3800print"<td class=\"". age_class($pr->{'age'}) ."\">".3801(defined$pr->{'age_string'} ?$pr->{'age_string'} :"No commits") ."</td>\n".3802"<td class=\"link\">".3803$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")},"summary") ." | ".3804$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")},"shortlog") ." | ".3805$cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")},"log") ." | ".3806$cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")},"tree") .3807($pr->{'forks'} ?" | ".$cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")},"forks") :'') .3808"</td>\n".3809"</tr>\n";3810}3811if(defined$extra) {3812print"<tr>\n";3813if($check_forks) {3814print"<td></td>\n";3815}3816print"<td colspan=\"5\">$extra</td>\n".3817"</tr>\n";3818}3819print"</table>\n";3820}38213822sub git_shortlog_body {3823# uses global variable $project3824my($commitlist,$from,$to,$refs,$extra) =@_;38253826$from=0unlessdefined$from;3827$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);38283829print"<table class=\"shortlog\">\n";3830my$alternate=1;3831for(my$i=$from;$i<=$to;$i++) {3832my%co= %{$commitlist->[$i]};3833my$commit=$co{'id'};3834my$ref= format_ref_marker($refs,$commit);3835if($alternate) {3836print"<tr class=\"dark\">\n";3837}else{3838print"<tr class=\"light\">\n";3839}3840$alternate^=1;3841my$author= chop_and_escape_str($co{'author_name'},10);3842# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .3843print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".3844"<td><i>".$author."</i></td>\n".3845"<td>";3846print format_subject_html($co{'title'},$co{'title_short'},3847 href(action=>"commit", hash=>$commit),$ref);3848print"</td>\n".3849"<td class=\"link\">".3850$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") ." | ".3851$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") ." | ".3852$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree");3853my$snapshot_links= format_snapshot_links($commit);3854if(defined$snapshot_links) {3855print" | ".$snapshot_links;3856}3857print"</td>\n".3858"</tr>\n";3859}3860if(defined$extra) {3861print"<tr>\n".3862"<td colspan=\"4\">$extra</td>\n".3863"</tr>\n";3864}3865print"</table>\n";3866}38673868sub git_history_body {3869# Warning: assumes constant type (blob or tree) during history3870my($commitlist,$from,$to,$refs,$hash_base,$ftype,$extra) =@_;38713872$from=0unlessdefined$from;3873$to=$#{$commitlist}unless(defined$to&&$to<=$#{$commitlist});38743875print"<table class=\"history\">\n";3876my$alternate=1;3877for(my$i=$from;$i<=$to;$i++) {3878my%co= %{$commitlist->[$i]};3879if(!%co) {3880next;3881}3882my$commit=$co{'id'};38833884my$ref= format_ref_marker($refs,$commit);38853886if($alternate) {3887print"<tr class=\"dark\">\n";3888}else{3889print"<tr class=\"light\">\n";3890}3891$alternate^=1;3892# shortlog uses chop_str($co{'author_name'}, 10)3893my$author= chop_and_escape_str($co{'author_name'},15,3);3894print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".3895"<td><i>".$author."</i></td>\n".3896"<td>";3897# originally git_history used chop_str($co{'title'}, 50)3898print format_subject_html($co{'title'},$co{'title_short'},3899 href(action=>"commit", hash=>$commit),$ref);3900print"</td>\n".3901"<td class=\"link\">".3902$cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)},$ftype) ." | ".3903$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff");39043905if($ftypeeq'blob') {3906my$blob_current= git_get_hash_by_path($hash_base,$file_name);3907my$blob_parent= git_get_hash_by_path($commit,$file_name);3908if(defined$blob_current&&defined$blob_parent&&3909$blob_currentne$blob_parent) {3910print" | ".3911$cgi->a({-href => href(action=>"blobdiff",3912 hash=>$blob_current, hash_parent=>$blob_parent,3913 hash_base=>$hash_base, hash_parent_base=>$commit,3914 file_name=>$file_name)},3915"diff to current");3916}3917}3918print"</td>\n".3919"</tr>\n";3920}3921if(defined$extra) {3922print"<tr>\n".3923"<td colspan=\"4\">$extra</td>\n".3924"</tr>\n";3925}3926print"</table>\n";3927}39283929sub git_tags_body {3930# uses global variable $project3931my($taglist,$from,$to,$extra) =@_;3932$from=0unlessdefined$from;3933$to=$#{$taglist}if(!defined$to||$#{$taglist} <$to);39343935print"<table class=\"tags\">\n";3936my$alternate=1;3937for(my$i=$from;$i<=$to;$i++) {3938my$entry=$taglist->[$i];3939my%tag=%$entry;3940my$comment=$tag{'subject'};3941my$comment_short;3942if(defined$comment) {3943$comment_short= chop_str($comment,30,5);3944}3945if($alternate) {3946print"<tr class=\"dark\">\n";3947}else{3948print"<tr class=\"light\">\n";3949}3950$alternate^=1;3951if(defined$tag{'age'}) {3952print"<td><i>$tag{'age'}</i></td>\n";3953}else{3954print"<td></td>\n";3955}3956print"<td>".3957$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),3958-class=>"list name"}, esc_html($tag{'name'})) .3959"</td>\n".3960"<td>";3961if(defined$comment) {3962print format_subject_html($comment,$comment_short,3963 href(action=>"tag", hash=>$tag{'id'}));3964}3965print"</td>\n".3966"<td class=\"selflink\">";3967if($tag{'type'}eq"tag") {3968print$cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})},"tag");3969}else{3970print" ";3971}3972print"</td>\n".3973"<td class=\"link\">"." | ".3974$cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})},$tag{'reftype'});3975if($tag{'reftype'}eq"commit") {3976print" | ".$cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})},"shortlog") .3977" | ".$cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})},"log");3978}elsif($tag{'reftype'}eq"blob") {3979print" | ".$cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})},"raw");3980}3981print"</td>\n".3982"</tr>";3983}3984if(defined$extra) {3985print"<tr>\n".3986"<td colspan=\"5\">$extra</td>\n".3987"</tr>\n";3988}3989print"</table>\n";3990}39913992sub git_heads_body {3993# uses global variable $project3994my($headlist,$head,$from,$to,$extra) =@_;3995$from=0unlessdefined$from;3996$to=$#{$headlist}if(!defined$to||$#{$headlist} <$to);39973998print"<table class=\"heads\">\n";3999my$alternate=1;4000for(my$i=$from;$i<=$to;$i++) {4001my$entry=$headlist->[$i];4002my%ref=%$entry;4003my$curr=$ref{'id'}eq$head;4004if($alternate) {4005print"<tr class=\"dark\">\n";4006}else{4007print"<tr class=\"light\">\n";4008}4009$alternate^=1;4010print"<td><i>$ref{'age'}</i></td>\n".4011($curr?"<td class=\"current_head\">":"<td>") .4012$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),4013-class=>"list name"},esc_html($ref{'name'})) .4014"</td>\n".4015"<td class=\"link\">".4016$cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})},"shortlog") ." | ".4017$cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})},"log") ." | ".4018$cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})},"tree") .4019"</td>\n".4020"</tr>";4021}4022if(defined$extra) {4023print"<tr>\n".4024"<td colspan=\"3\">$extra</td>\n".4025"</tr>\n";4026}4027print"</table>\n";4028}40294030sub git_search_grep_body {4031my($commitlist,$from,$to,$extra) =@_;4032$from=0unlessdefined$from;4033$to=$#{$commitlist}if(!defined$to||$#{$commitlist} <$to);40344035print"<table class=\"commit_search\">\n";4036my$alternate=1;4037for(my$i=$from;$i<=$to;$i++) {4038my%co= %{$commitlist->[$i]};4039if(!%co) {4040next;4041}4042my$commit=$co{'id'};4043if($alternate) {4044print"<tr class=\"dark\">\n";4045}else{4046print"<tr class=\"light\">\n";4047}4048$alternate^=1;4049my$author= chop_and_escape_str($co{'author_name'},15,5);4050print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".4051"<td><i>".$author."</i></td>\n".4052"<td>".4053$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),4054-class=>"list subject"},4055 chop_and_escape_str($co{'title'},50) ."<br/>");4056my$comment=$co{'comment'};4057foreachmy$line(@$comment) {4058if($line=~m/^(.*?)($search_regexp)(.*)$/i) {4059my($lead,$match,$trail) = ($1,$2,$3);4060$match= chop_str($match,70,5,'center');4061my$contextlen=int((80-length($match))/2);4062$contextlen=30if($contextlen>30);4063$lead= chop_str($lead,$contextlen,10,'left');4064$trail= chop_str($trail,$contextlen,10,'right');40654066$lead= esc_html($lead);4067$match= esc_html($match);4068$trail= esc_html($trail);40694070print"$lead<span class=\"match\">$match</span>$trail<br />";4071}4072}4073print"</td>\n".4074"<td class=\"link\">".4075$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .4076" | ".4077$cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})},"commitdiff") .4078" | ".4079$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");4080print"</td>\n".4081"</tr>\n";4082}4083if(defined$extra) {4084print"<tr>\n".4085"<td colspan=\"3\">$extra</td>\n".4086"</tr>\n";4087}4088print"</table>\n";4089}40904091## ======================================================================4092## ======================================================================4093## actions40944095sub git_project_list {4096my$order=$cgi->param('o');4097if(defined$order&&$order!~m/none|project|descr|owner|age/) {4098 die_error(400,"Unknown order parameter");4099}41004101my@list= git_get_projects_list();4102if(!@list) {4103 die_error(404,"No projects found");4104}41054106 git_header_html();4107if(-f $home_text) {4108print"<div class=\"index_include\">\n";4109open(my$fd,$home_text);4110print<$fd>;4111close$fd;4112print"</div>\n";4113}4114print$cgi->startform(-method=>"get") .4115"<p class=\"projsearch\">Search:\n".4116$cgi->textfield(-name =>"s", -value =>$searchtext) ."\n".4117"</p>".4118$cgi->end_form() ."\n";4119 git_project_list_body(\@list,$order);4120 git_footer_html();4121}41224123sub git_forks {4124my$order=$cgi->param('o');4125if(defined$order&&$order!~m/none|project|descr|owner|age/) {4126 die_error(400,"Unknown order parameter");4127}41284129my@list= git_get_projects_list($project);4130if(!@list) {4131 die_error(404,"No forks found");4132}41334134 git_header_html();4135 git_print_page_nav('','');4136 git_print_header_div('summary',"$projectforks");4137 git_project_list_body(\@list,$order);4138 git_footer_html();4139}41404141sub git_project_index {4142my@projects= git_get_projects_list($project);41434144print$cgi->header(4145-type =>'text/plain',4146-charset =>'utf-8',4147-content_disposition =>'inline; filename="index.aux"');41484149foreachmy$pr(@projects) {4150if(!exists$pr->{'owner'}) {4151$pr->{'owner'} = git_get_project_owner("$pr->{'path'}");4152}41534154my($path,$owner) = ($pr->{'path'},$pr->{'owner'});4155# quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '4156$path=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4157$owner=~s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X",ord($1))/eg;4158$path=~s/ /\+/g;4159$owner=~s/ /\+/g;41604161print"$path$owner\n";4162}4163}41644165sub git_summary {4166my$descr= git_get_project_description($project) ||"none";4167my%co= parse_commit("HEAD");4168my%cd=%co? parse_date($co{'committer_epoch'},$co{'committer_tz'}) : ();4169my$head=$co{'id'};41704171my$owner= git_get_project_owner($project);41724173my$refs= git_get_references();4174# These get_*_list functions return one more to allow us to see if4175# there are more ...4176my@taglist= git_get_tags_list(16);4177my@headlist= git_get_heads_list(16);4178my@forklist;4179my($check_forks) = gitweb_check_feature('forks');41804181if($check_forks) {4182@forklist= git_get_projects_list($project);4183}41844185 git_header_html();4186 git_print_page_nav('summary','',$head);41874188print"<div class=\"title\"> </div>\n";4189print"<table class=\"projects_list\">\n".4190"<tr id=\"metadata_desc\"><td>description</td><td>". esc_html($descr) ."</td></tr>\n".4191"<tr id=\"metadata_owner\"><td>owner</td><td>". esc_html($owner) ."</td></tr>\n";4192if(defined$cd{'rfc2822'}) {4193print"<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";4194}41954196# use per project git URL list in $projectroot/$project/cloneurl4197# or make project git URL from git base URL and project name4198my$url_tag="URL";4199my@url_list= git_get_project_url_list($project);4200@url_list=map{"$_/$project"}@git_base_url_listunless@url_list;4201foreachmy$git_url(@url_list) {4202next unless$git_url;4203print"<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";4204$url_tag="";4205}42064207# Tag cloud4208my$show_ctags= (gitweb_check_feature('ctags'))[0];4209if($show_ctags) {4210my$ctags= git_get_project_ctags($project);4211my$cloud= git_populate_project_tagcloud($ctags);4212print"<tr id=\"metadata_ctags\"><td>Content tags:<br />";4213print"</td>\n<td>"unless%$ctags;4214print"<form action=\"$show_ctags\"method=\"post\"><input type=\"hidden\"name=\"p\"value=\"$project\"/>Add: <input type=\"text\"name=\"t\"size=\"8\"/></form>";4215print"</td>\n<td>"if%$ctags;4216print git_show_project_tagcloud($cloud,48);4217print"</td></tr>";4218}42194220print"</table>\n";42214222if(-s "$projectroot/$project/README.html") {4223if(open my$fd,"$projectroot/$project/README.html") {4224print"<div class=\"title\">readme</div>\n".4225"<div class=\"readme\">\n";4226print$_while(<$fd>);4227print"\n</div>\n";# class="readme"4228close$fd;4229}4230}42314232# we need to request one more than 16 (0..15) to check if4233# those 16 are all4234my@commitlist=$head? parse_commits($head,17) : ();4235if(@commitlist) {4236 git_print_header_div('shortlog');4237 git_shortlog_body(\@commitlist,0,15,$refs,4238$#commitlist<=15?undef:4239$cgi->a({-href => href(action=>"shortlog")},"..."));4240}42414242if(@taglist) {4243 git_print_header_div('tags');4244 git_tags_body(\@taglist,0,15,4245$#taglist<=15?undef:4246$cgi->a({-href => href(action=>"tags")},"..."));4247}42484249if(@headlist) {4250 git_print_header_div('heads');4251 git_heads_body(\@headlist,$head,0,15,4252$#headlist<=15?undef:4253$cgi->a({-href => href(action=>"heads")},"..."));4254}42554256if(@forklist) {4257 git_print_header_div('forks');4258 git_project_list_body(\@forklist,undef,0,15,4259$#forklist<=15?undef:4260$cgi->a({-href => href(action=>"forks")},"..."),4261'noheader');4262}42634264 git_footer_html();4265}42664267sub git_tag {4268my$head= git_get_head_hash($project);4269 git_header_html();4270 git_print_page_nav('','',$head,undef,$head);4271my%tag= parse_tag($hash);42724273if(!%tag) {4274 die_error(404,"Unknown tag object");4275}42764277 git_print_header_div('commit', esc_html($tag{'name'}),$hash);4278print"<div class=\"title_text\">\n".4279"<table class=\"object_header\">\n".4280"<tr>\n".4281"<td>object</td>\n".4282"<td>".$cgi->a({-class=>"list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4283$tag{'object'}) ."</td>\n".4284"<td class=\"link\">".$cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},4285$tag{'type'}) ."</td>\n".4286"</tr>\n";4287if(defined($tag{'author'})) {4288my%ad= parse_date($tag{'epoch'},$tag{'tz'});4289print"<tr><td>author</td><td>". esc_html($tag{'author'}) ."</td></tr>\n";4290print"<tr><td></td><td>".$ad{'rfc2822'} .4291sprintf(" (%02d:%02d%s)",$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'}) .4292"</td></tr>\n";4293}4294print"</table>\n\n".4295"</div>\n";4296print"<div class=\"page_body\">";4297my$comment=$tag{'comment'};4298foreachmy$line(@$comment) {4299chomp$line;4300print esc_html($line, -nbsp=>1) ."<br/>\n";4301}4302print"</div>\n";4303 git_footer_html();4304}43054306sub git_blame {4307my$fd;4308my$ftype;43094310 gitweb_check_feature('blame')4311or die_error(403,"Blame view not allowed");43124313 die_error(400,"No file name given")unless$file_name;4314$hash_base||= git_get_head_hash($project);4315 die_error(404,"Couldn't find base commit")unless($hash_base);4316my%co= parse_commit($hash_base)4317or die_error(404,"Commit not found");4318if(!defined$hash) {4319$hash= git_get_hash_by_path($hash_base,$file_name,"blob")4320or die_error(404,"Error looking up file");4321}4322$ftype= git_get_type($hash);4323if($ftype!~"blob") {4324 die_error(400,"Object is not a blob");4325}4326open($fd,"-|", git_cmd(),"blame",'-p','--',4327$file_name,$hash_base)4328or die_error(500,"Open git-blame failed");4329 git_header_html();4330my$formats_nav=4331$cgi->a({-href => href(action=>"blob", -replay=>1)},4332"blob") .4333" | ".4334$cgi->a({-href => href(action=>"history", -replay=>1)},4335"history") .4336" | ".4337$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},4338"HEAD");4339 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4340 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4341 git_print_page_path($file_name,$ftype,$hash_base);4342my@rev_color= (qw(light2 dark2));4343my$num_colors=scalar(@rev_color);4344my$current_color=0;4345my$last_rev;4346print<<HTML;4347<div class="page_body">4348<table class="blame">4349<tr><th>Commit</th><th>Line</th><th>Data</th></tr>4350HTML4351my%metainfo= ();4352while(1) {4353$_= <$fd>;4354last unlessdefined$_;4355my($full_rev,$orig_lineno,$lineno,$group_size) =4356/^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;4357if(!exists$metainfo{$full_rev}) {4358$metainfo{$full_rev} = {};4359}4360my$meta=$metainfo{$full_rev};4361while(<$fd>) {4362last if(s/^\t//);4363if(/^(\S+) (.*)$/) {4364$meta->{$1} =$2;4365}4366}4367my$data=$_;4368chomp$data;4369my$rev=substr($full_rev,0,8);4370my$author=$meta->{'author'};4371my%date= parse_date($meta->{'author-time'},4372$meta->{'author-tz'});4373my$date=$date{'iso-tz'};4374if($group_size) {4375$current_color= ++$current_color%$num_colors;4376}4377print"<tr class=\"$rev_color[$current_color]\">\n";4378if($group_size) {4379print"<td class=\"sha1\"";4380print" title=\"". esc_html($author) .",$date\"";4381print" rowspan=\"$group_size\""if($group_size>1);4382print">";4383print$cgi->a({-href => href(action=>"commit",4384 hash=>$full_rev,4385 file_name=>$file_name)},4386 esc_html($rev));4387print"</td>\n";4388}4389open(my$dd,"-|", git_cmd(),"rev-parse","$full_rev^")4390or die_error(500,"Open git-rev-parse failed");4391my$parent_commit= <$dd>;4392close$dd;4393chomp($parent_commit);4394my$blamed= href(action =>'blame',4395 file_name =>$meta->{'filename'},4396 hash_base =>$parent_commit);4397print"<td class=\"linenr\">";4398print$cgi->a({ -href =>"$blamed#l$orig_lineno",4399-id =>"l$lineno",4400-class=>"linenr"},4401 esc_html($lineno));4402print"</td>";4403print"<td class=\"pre\">". esc_html($data) ."</td>\n";4404print"</tr>\n";4405}4406print"</table>\n";4407print"</div>";4408close$fd4409or print"Reading blob failed\n";4410 git_footer_html();4411}44124413sub git_tags {4414my$head= git_get_head_hash($project);4415 git_header_html();4416 git_print_page_nav('','',$head,undef,$head);4417 git_print_header_div('summary',$project);44184419my@tagslist= git_get_tags_list();4420if(@tagslist) {4421 git_tags_body(\@tagslist);4422}4423 git_footer_html();4424}44254426sub git_heads {4427my$head= git_get_head_hash($project);4428 git_header_html();4429 git_print_page_nav('','',$head,undef,$head);4430 git_print_header_div('summary',$project);44314432my@headslist= git_get_heads_list();4433if(@headslist) {4434 git_heads_body(\@headslist,$head);4435}4436 git_footer_html();4437}44384439sub git_blob_plain {4440my$type=shift;4441my$expires;44424443if(!defined$hash) {4444if(defined$file_name) {4445my$base=$hash_base|| git_get_head_hash($project);4446$hash= git_get_hash_by_path($base,$file_name,"blob")4447or die_error(404,"Cannot find file");4448}else{4449 die_error(400,"No file name defined");4450}4451}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4452# blobs defined by non-textual hash id's can be cached4453$expires="+1d";4454}44554456open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4457or die_error(500,"Open git-cat-file blob '$hash' failed");44584459# content-type (can include charset)4460$type= blob_contenttype($fd,$file_name,$type);44614462# "save as" filename, even when no $file_name is given4463my$save_as="$hash";4464if(defined$file_name) {4465$save_as=$file_name;4466}elsif($type=~m/^text\//) {4467$save_as.='.txt';4468}44694470print$cgi->header(4471-type =>$type,4472-expires =>$expires,4473-content_disposition =>'inline; filename="'.$save_as.'"');4474undef$/;4475binmode STDOUT,':raw';4476print<$fd>;4477binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi4478$/="\n";4479close$fd;4480}44814482sub git_blob {4483my$expires;44844485if(!defined$hash) {4486if(defined$file_name) {4487my$base=$hash_base|| git_get_head_hash($project);4488$hash= git_get_hash_by_path($base,$file_name,"blob")4489or die_error(404,"Cannot find file");4490}else{4491 die_error(400,"No file name defined");4492}4493}elsif($hash=~m/^[0-9a-fA-F]{40}$/) {4494# blobs defined by non-textual hash id's can be cached4495$expires="+1d";4496}44974498my($have_blame) = gitweb_check_feature('blame');4499open my$fd,"-|", git_cmd(),"cat-file","blob",$hash4500or die_error(500,"Couldn't cat$file_name,$hash");4501my$mimetype= blob_mimetype($fd,$file_name);4502if($mimetype!~m!^(?:text/|image/(?:gif|png|jpeg)$)!&& -B $fd) {4503close$fd;4504return git_blob_plain($mimetype);4505}4506# we can have blame only for text/* mimetype4507$have_blame&&= ($mimetype=~m!^text/!);45084509 git_header_html(undef,$expires);4510my$formats_nav='';4511if(defined$hash_base&& (my%co= parse_commit($hash_base))) {4512if(defined$file_name) {4513if($have_blame) {4514$formats_nav.=4515$cgi->a({-href => href(action=>"blame", -replay=>1)},4516"blame") .4517" | ";4518}4519$formats_nav.=4520$cgi->a({-href => href(action=>"history", -replay=>1)},4521"history") .4522" | ".4523$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},4524"raw") .4525" | ".4526$cgi->a({-href => href(action=>"blob",4527 hash_base=>"HEAD", file_name=>$file_name)},4528"HEAD");4529}else{4530$formats_nav.=4531$cgi->a({-href => href(action=>"blob_plain", -replay=>1)},4532"raw");4533}4534 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);4535 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);4536}else{4537print"<div class=\"page_nav\">\n".4538"<br/><br/></div>\n".4539"<div class=\"title\">$hash</div>\n";4540}4541 git_print_page_path($file_name,"blob",$hash_base);4542print"<div class=\"page_body\">\n";4543if($mimetype=~m!^image/!) {4544print qq!<img type="$mimetype"!;4545if($file_name) {4546print qq! alt="$file_name" title="$file_name"!;4547}4548print qq! src="! .4549 href(action=>"blob_plain", hash=>$hash,4550 hash_base=>$hash_base, file_name=>$file_name) .4551 qq!"/>\n!;4552}else{4553my$nr;4554while(my$line= <$fd>) {4555chomp$line;4556$nr++;4557$line= untabify($line);4558printf"<div class=\"pre\"><a id=\"l%i\"href=\"#l%i\"class=\"linenr\">%4i</a>%s</div>\n",4559$nr,$nr,$nr, esc_html($line, -nbsp=>1);4560}4561}4562close$fd4563or print"Reading blob failed.\n";4564print"</div>";4565 git_footer_html();4566}45674568sub git_tree {4569if(!defined$hash_base) {4570$hash_base="HEAD";4571}4572if(!defined$hash) {4573if(defined$file_name) {4574$hash= git_get_hash_by_path($hash_base,$file_name,"tree");4575}else{4576$hash=$hash_base;4577}4578}4579 die_error(404,"No such tree")unlessdefined($hash);4580$/="\0";4581open my$fd,"-|", git_cmd(),"ls-tree",'-z',$hash4582or die_error(500,"Open git-ls-tree failed");4583my@entries=map{chomp;$_} <$fd>;4584close$fdor die_error(404,"Reading tree failed");4585$/="\n";45864587my$refs= git_get_references();4588my$ref= format_ref_marker($refs,$hash_base);4589 git_header_html();4590my$basedir='';4591my($have_blame) = gitweb_check_feature('blame');4592if(defined$hash_base&& (my%co= parse_commit($hash_base))) {4593my@views_nav= ();4594if(defined$file_name) {4595push@views_nav,4596$cgi->a({-href => href(action=>"history", -replay=>1)},4597"history"),4598$cgi->a({-href => href(action=>"tree",4599 hash_base=>"HEAD", file_name=>$file_name)},4600"HEAD"),4601}4602my$snapshot_links= format_snapshot_links($hash);4603if(defined$snapshot_links) {4604# FIXME: Should be available when we have no hash base as well.4605push@views_nav,$snapshot_links;4606}4607 git_print_page_nav('tree','',$hash_base,undef,undef,join(' | ',@views_nav));4608 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash_base);4609}else{4610undef$hash_base;4611print"<div class=\"page_nav\">\n";4612print"<br/><br/></div>\n";4613print"<div class=\"title\">$hash</div>\n";4614}4615if(defined$file_name) {4616$basedir=$file_name;4617if($basedirne''&&substr($basedir, -1)ne'/') {4618$basedir.='/';4619}4620 git_print_page_path($file_name,'tree',$hash_base);4621}4622print"<div class=\"page_body\">\n";4623print"<table class=\"tree\">\n";4624my$alternate=1;4625# '..' (top directory) link if possible4626if(defined$hash_base&&4627defined$file_name&&$file_name=~m![^/]+$!) {4628if($alternate) {4629print"<tr class=\"dark\">\n";4630}else{4631print"<tr class=\"light\">\n";4632}4633$alternate^=1;46344635my$up=$file_name;4636$up=~s!/?[^/]+$!!;4637undef$upunless$up;4638# based on git_print_tree_entry4639print'<td class="mode">'. mode_str('040000') ."</td>\n";4640print'<td class="list">';4641print$cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,4642 file_name=>$up)},4643"..");4644print"</td>\n";4645print"<td class=\"link\"></td>\n";46464647print"</tr>\n";4648}4649foreachmy$line(@entries) {4650my%t= parse_ls_tree_line($line, -z =>1);46514652if($alternate) {4653print"<tr class=\"dark\">\n";4654}else{4655print"<tr class=\"light\">\n";4656}4657$alternate^=1;46584659 git_print_tree_entry(\%t,$basedir,$hash_base,$have_blame);46604661print"</tr>\n";4662}4663print"</table>\n".4664"</div>";4665 git_footer_html();4666}46674668sub git_snapshot {4669my@supported_fmts= gitweb_check_feature('snapshot');4670@supported_fmts= filter_snapshot_fmts(@supported_fmts);46714672my$format=$cgi->param('sf');4673if(!@supported_fmts) {4674 die_error(403,"Snapshots not allowed");4675}4676# default to first supported snapshot format4677$format||=$supported_fmts[0];4678if($format!~m/^[a-z0-9]+$/) {4679 die_error(400,"Invalid snapshot format parameter");4680}elsif(!exists($known_snapshot_formats{$format})) {4681 die_error(400,"Unknown snapshot format");4682}elsif(!grep($_eq$format,@supported_fmts)) {4683 die_error(403,"Unsupported snapshot format");4684}46854686if(!defined$hash) {4687$hash= git_get_head_hash($project);4688}46894690my$name=$project;4691$name=~ s,([^/])/*\.git$,$1,;4692$name= basename($name);4693my$filename= to_utf8($name);4694$name=~s/\047/\047\\\047\047/g;4695my$cmd;4696$filename.="-$hash$known_snapshot_formats{$format}{'suffix'}";4697$cmd= quote_command(4698 git_cmd(),'archive',4699"--format=$known_snapshot_formats{$format}{'format'}",4700"--prefix=$name/",$hash);4701if(exists$known_snapshot_formats{$format}{'compressor'}) {4702$cmd.=' | '. quote_command(@{$known_snapshot_formats{$format}{'compressor'}});4703}47044705print$cgi->header(4706-type =>$known_snapshot_formats{$format}{'type'},4707-content_disposition =>'inline; filename="'."$filename".'"',4708-status =>'200 OK');47094710open my$fd,"-|",$cmd4711or die_error(500,"Execute git-archive failed");4712binmode STDOUT,':raw';4713print<$fd>;4714binmode STDOUT,':utf8';# as set at the beginning of gitweb.cgi4715close$fd;4716}47174718sub git_log {4719my$head= git_get_head_hash($project);4720if(!defined$hash) {4721$hash=$head;4722}4723if(!defined$page) {4724$page=0;4725}4726my$refs= git_get_references();47274728my@commitlist= parse_commits($hash,101, (100*$page));47294730my$paging_nav= format_paging_nav('log',$hash,$head,$page,$#commitlist>=100);47314732 git_header_html();4733 git_print_page_nav('log','',$hash,undef,undef,$paging_nav);47344735if(!@commitlist) {4736my%co= parse_commit($hash);47374738 git_print_header_div('summary',$project);4739print"<div class=\"page_body\"> Last change$co{'age_string'}.<br/><br/></div>\n";4740}4741my$to= ($#commitlist>=99) ? (99) : ($#commitlist);4742for(my$i=0;$i<=$to;$i++) {4743my%co= %{$commitlist[$i]};4744next if!%co;4745my$commit=$co{'id'};4746my$ref= format_ref_marker($refs,$commit);4747my%ad= parse_date($co{'author_epoch'});4748 git_print_header_div('commit',4749"<span class=\"age\">$co{'age_string'}</span>".4750 esc_html($co{'title'}) .$ref,4751$commit);4752print"<div class=\"title_text\">\n".4753"<div class=\"log_link\">\n".4754$cgi->a({-href => href(action=>"commit", hash=>$commit)},"commit") .4755" | ".4756$cgi->a({-href => href(action=>"commitdiff", hash=>$commit)},"commitdiff") .4757" | ".4758$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)},"tree") .4759"<br/>\n".4760"</div>\n".4761"<i>". esc_html($co{'author_name'}) ." [$ad{'rfc2822'}]</i><br/>\n".4762"</div>\n";47634764print"<div class=\"log_body\">\n";4765 git_print_log($co{'comment'}, -final_empty_line=>1);4766print"</div>\n";4767}4768if($#commitlist>=100) {4769print"<div class=\"page_nav\">\n";4770print$cgi->a({-href => href(-replay=>1, page=>$page+1),4771-accesskey =>"n", -title =>"Alt-n"},"next");4772print"</div>\n";4773}4774 git_footer_html();4775}47764777sub git_commit {4778$hash||=$hash_base||"HEAD";4779my%co= parse_commit($hash)4780or die_error(404,"Unknown commit object");4781my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});4782my%cd= parse_date($co{'committer_epoch'},$co{'committer_tz'});47834784my$parent=$co{'parent'};4785my$parents=$co{'parents'};# listref47864787# we need to prepare $formats_nav before any parameter munging4788my$formats_nav;4789if(!defined$parent) {4790# --root commitdiff4791$formats_nav.='(initial)';4792}elsif(@$parents==1) {4793# single parent commit4794$formats_nav.=4795'(parent: '.4796$cgi->a({-href => href(action=>"commit",4797 hash=>$parent)},4798 esc_html(substr($parent,0,7))) .4799')';4800}else{4801# merge commit4802$formats_nav.=4803'(merge: '.4804join(' ',map{4805$cgi->a({-href => href(action=>"commit",4806 hash=>$_)},4807 esc_html(substr($_,0,7)));4808}@$parents) .4809')';4810}48114812if(!defined$parent) {4813$parent="--root";4814}4815my@difftree;4816open my$fd,"-|", git_cmd(),"diff-tree",'-r',"--no-commit-id",4817@diff_opts,4818(@$parents<=1?$parent:'-c'),4819$hash,"--"4820or die_error(500,"Open git-diff-tree failed");4821@difftree=map{chomp;$_} <$fd>;4822close$fdor die_error(404,"Reading git-diff-tree failed");48234824# non-textual hash id's can be cached4825my$expires;4826if($hash=~m/^[0-9a-fA-F]{40}$/) {4827$expires="+1d";4828}4829my$refs= git_get_references();4830my$ref= format_ref_marker($refs,$co{'id'});48314832 git_header_html(undef,$expires);4833 git_print_page_nav('commit','',4834$hash,$co{'tree'},$hash,4835$formats_nav);48364837if(defined$co{'parent'}) {4838 git_print_header_div('commitdiff', esc_html($co{'title'}) .$ref,$hash);4839}else{4840 git_print_header_div('tree', esc_html($co{'title'}) .$ref,$co{'tree'},$hash);4841}4842print"<div class=\"title_text\">\n".4843"<table class=\"object_header\">\n";4844print"<tr><td>author</td><td>". esc_html($co{'author'}) ."</td></tr>\n".4845"<tr>".4846"<td></td><td>$ad{'rfc2822'}";4847if($ad{'hour_local'} <6) {4848printf(" (<span class=\"atnight\">%02d:%02d</span>%s)",4849$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});4850}else{4851printf(" (%02d:%02d%s)",4852$ad{'hour_local'},$ad{'minute_local'},$ad{'tz_local'});4853}4854print"</td>".4855"</tr>\n";4856print"<tr><td>committer</td><td>". esc_html($co{'committer'}) ."</td></tr>\n";4857print"<tr><td></td><td>$cd{'rfc2822'}".4858sprintf(" (%02d:%02d%s)",$cd{'hour_local'},$cd{'minute_local'},$cd{'tz_local'}) .4859"</td></tr>\n";4860print"<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";4861print"<tr>".4862"<td>tree</td>".4863"<td class=\"sha1\">".4864$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),4865class=>"list"},$co{'tree'}) .4866"</td>".4867"<td class=\"link\">".4868$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},4869"tree");4870my$snapshot_links= format_snapshot_links($hash);4871if(defined$snapshot_links) {4872print" | ".$snapshot_links;4873}4874print"</td>".4875"</tr>\n";48764877foreachmy$par(@$parents) {4878print"<tr>".4879"<td>parent</td>".4880"<td class=\"sha1\">".4881$cgi->a({-href => href(action=>"commit", hash=>$par),4882class=>"list"},$par) .4883"</td>".4884"<td class=\"link\">".4885$cgi->a({-href => href(action=>"commit", hash=>$par)},"commit") .4886" | ".4887$cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)},"diff") .4888"</td>".4889"</tr>\n";4890}4891print"</table>".4892"</div>\n";48934894print"<div class=\"page_body\">\n";4895 git_print_log($co{'comment'});4896print"</div>\n";48974898 git_difftree_body(\@difftree,$hash,@$parents);48994900 git_footer_html();4901}49024903sub git_object {4904# object is defined by:4905# - hash or hash_base alone4906# - hash_base and file_name4907my$type;49084909# - hash or hash_base alone4910if($hash|| ($hash_base&& !defined$file_name)) {4911my$object_id=$hash||$hash_base;49124913open my$fd,"-|", quote_command(4914 git_cmd(),'cat-file','-t',$object_id) .' 2> /dev/null'4915or die_error(404,"Object does not exist");4916$type= <$fd>;4917chomp$type;4918close$fd4919or die_error(404,"Object does not exist");49204921# - hash_base and file_name4922}elsif($hash_base&&defined$file_name) {4923$file_name=~ s,/+$,,;49244925system(git_cmd(),"cat-file",'-e',$hash_base) ==04926or die_error(404,"Base object does not exist");49274928# here errors should not hapen4929open my$fd,"-|", git_cmd(),"ls-tree",$hash_base,"--",$file_name4930or die_error(500,"Open git-ls-tree failed");4931my$line= <$fd>;4932close$fd;49334934#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'4935unless($line&&$line=~m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {4936 die_error(404,"File or directory for given base does not exist");4937}4938$type=$2;4939$hash=$3;4940}else{4941 die_error(400,"Not enough information to find object");4942}49434944print$cgi->redirect(-uri => href(action=>$type, -full=>1,4945 hash=>$hash, hash_base=>$hash_base,4946 file_name=>$file_name),4947-status =>'302 Found');4948}49494950sub git_blobdiff {4951my$format=shift||'html';49524953my$fd;4954my@difftree;4955my%diffinfo;4956my$expires;49574958# preparing $fd and %diffinfo for git_patchset_body4959# new style URI4960if(defined$hash_base&&defined$hash_parent_base) {4961if(defined$file_name) {4962# read raw output4963open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,4964$hash_parent_base,$hash_base,4965"--", (defined$file_parent?$file_parent: ()),$file_name4966or die_error(500,"Open git-diff-tree failed");4967@difftree=map{chomp;$_} <$fd>;4968close$fd4969or die_error(404,"Reading git-diff-tree failed");4970@difftree4971or die_error(404,"Blob diff not found");49724973}elsif(defined$hash&&4974$hash=~/[0-9a-fA-F]{40}/) {4975# try to find filename from $hash49764977# read filtered raw output4978open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,4979$hash_parent_base,$hash_base,"--"4980or die_error(500,"Open git-diff-tree failed");4981@difftree=4982# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'4983# $hash == to_id4984grep{/^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/}4985map{chomp;$_} <$fd>;4986close$fd4987or die_error(404,"Reading git-diff-tree failed");4988@difftree4989or die_error(404,"Blob diff not found");49904991}else{4992 die_error(400,"Missing one of the blob diff parameters");4993}49944995if(@difftree>1) {4996 die_error(400,"Ambiguous blob diff specification");4997}49984999%diffinfo= parse_difftree_raw_line($difftree[0]);5000$file_parent||=$diffinfo{'from_file'} ||$file_name;5001$file_name||=$diffinfo{'to_file'};50025003$hash_parent||=$diffinfo{'from_id'};5004$hash||=$diffinfo{'to_id'};50055006# non-textual hash id's can be cached5007if($hash_base=~m/^[0-9a-fA-F]{40}$/&&5008$hash_parent_base=~m/^[0-9a-fA-F]{40}$/) {5009$expires='+1d';5010}50115012# open patch output5013open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5014'-p', ($formateq'html'?"--full-index": ()),5015$hash_parent_base,$hash_base,5016"--", (defined$file_parent?$file_parent: ()),$file_name5017or die_error(500,"Open git-diff-tree failed");5018}50195020# old/legacy style URI5021if(!%diffinfo&&# if new style URI failed5022defined$hash&&defined$hash_parent) {5023# fake git-diff-tree raw output5024$diffinfo{'from_mode'} =$diffinfo{'to_mode'} ="blob";5025$diffinfo{'from_id'} =$hash_parent;5026$diffinfo{'to_id'} =$hash;5027if(defined$file_name) {5028if(defined$file_parent) {5029$diffinfo{'status'} ='2';5030$diffinfo{'from_file'} =$file_parent;5031$diffinfo{'to_file'} =$file_name;5032}else{# assume not renamed5033$diffinfo{'status'} ='1';5034$diffinfo{'from_file'} =$file_name;5035$diffinfo{'to_file'} =$file_name;5036}5037}else{# no filename given5038$diffinfo{'status'} ='2';5039$diffinfo{'from_file'} =$hash_parent;5040$diffinfo{'to_file'} =$hash;5041}50425043# non-textual hash id's can be cached5044if($hash=~m/^[0-9a-fA-F]{40}$/&&5045$hash_parent=~m/^[0-9a-fA-F]{40}$/) {5046$expires='+1d';5047}50485049# open patch output5050open$fd,"-|", git_cmd(),"diff",@diff_opts,5051'-p', ($formateq'html'?"--full-index": ()),5052$hash_parent,$hash,"--"5053or die_error(500,"Open git-diff failed");5054}else{5055 die_error(400,"Missing one of the blob diff parameters")5056unless%diffinfo;5057}50585059# header5060if($formateq'html') {5061my$formats_nav=5062$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},5063"raw");5064 git_header_html(undef,$expires);5065if(defined$hash_base&& (my%co= parse_commit($hash_base))) {5066 git_print_page_nav('','',$hash_base,$co{'tree'},$hash_base,$formats_nav);5067 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5068}else{5069print"<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";5070print"<div class=\"title\">$hashvs$hash_parent</div>\n";5071}5072if(defined$file_name) {5073 git_print_page_path($file_name,"blob",$hash_base);5074}else{5075print"<div class=\"page_path\"></div>\n";5076}50775078}elsif($formateq'plain') {5079print$cgi->header(5080-type =>'text/plain',5081-charset =>'utf-8',5082-expires =>$expires,5083-content_disposition =>'inline; filename="'."$file_name".'.patch"');50845085print"X-Git-Url: ".$cgi->self_url() ."\n\n";50865087}else{5088 die_error(400,"Unknown blobdiff format");5089}50905091# patch5092if($formateq'html') {5093print"<div class=\"page_body\">\n";50945095 git_patchset_body($fd, [ \%diffinfo],$hash_base,$hash_parent_base);5096close$fd;50975098print"</div>\n";# class="page_body"5099 git_footer_html();51005101}else{5102while(my$line= <$fd>) {5103$line=~s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;5104$line=~s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;51055106print$line;51075108last if$line=~m!^\+\+\+!;5109}5110local$/=undef;5111print<$fd>;5112close$fd;5113}5114}51155116sub git_blobdiff_plain {5117 git_blobdiff('plain');5118}51195120sub git_commitdiff {5121my$format=shift||'html';5122$hash||=$hash_base||"HEAD";5123my%co= parse_commit($hash)5124or die_error(404,"Unknown commit object");51255126# choose format for commitdiff for merge5127if(!defined$hash_parent&& @{$co{'parents'}} >1) {5128$hash_parent='--cc';5129}5130# we need to prepare $formats_nav before almost any parameter munging5131my$formats_nav;5132if($formateq'html') {5133$formats_nav=5134$cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},5135"raw");51365137if(defined$hash_parent&&5138$hash_parentne'-c'&&$hash_parentne'--cc') {5139# commitdiff with two commits given5140my$hash_parent_short=$hash_parent;5141if($hash_parent=~m/^[0-9a-fA-F]{40}$/) {5142$hash_parent_short=substr($hash_parent,0,7);5143}5144$formats_nav.=5145' (from';5146for(my$i=0;$i< @{$co{'parents'}};$i++) {5147if($co{'parents'}[$i]eq$hash_parent) {5148$formats_nav.=' parent '. ($i+1);5149last;5150}5151}5152$formats_nav.=': '.5153$cgi->a({-href => href(action=>"commitdiff",5154 hash=>$hash_parent)},5155 esc_html($hash_parent_short)) .5156')';5157}elsif(!$co{'parent'}) {5158# --root commitdiff5159$formats_nav.=' (initial)';5160}elsif(scalar@{$co{'parents'}} ==1) {5161# single parent commit5162$formats_nav.=5163' (parent: '.5164$cgi->a({-href => href(action=>"commitdiff",5165 hash=>$co{'parent'})},5166 esc_html(substr($co{'parent'},0,7))) .5167')';5168}else{5169# merge commit5170if($hash_parenteq'--cc') {5171$formats_nav.=' | '.5172$cgi->a({-href => href(action=>"commitdiff",5173 hash=>$hash, hash_parent=>'-c')},5174'combined');5175}else{# $hash_parent eq '-c'5176$formats_nav.=' | '.5177$cgi->a({-href => href(action=>"commitdiff",5178 hash=>$hash, hash_parent=>'--cc')},5179'compact');5180}5181$formats_nav.=5182' (merge: '.5183join(' ',map{5184$cgi->a({-href => href(action=>"commitdiff",5185 hash=>$_)},5186 esc_html(substr($_,0,7)));5187} @{$co{'parents'}} ) .5188')';5189}5190}51915192my$hash_parent_param=$hash_parent;5193if(!defined$hash_parent_param) {5194# --cc for multiple parents, --root for parentless5195$hash_parent_param=5196@{$co{'parents'}} >1?'--cc':$co{'parent'} ||'--root';5197}51985199# read commitdiff5200my$fd;5201my@difftree;5202if($formateq'html') {5203open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5204"--no-commit-id","--patch-with-raw","--full-index",5205$hash_parent_param,$hash,"--"5206or die_error(500,"Open git-diff-tree failed");52075208while(my$line= <$fd>) {5209chomp$line;5210# empty line ends raw part of diff-tree output5211last unless$line;5212push@difftree,scalar parse_difftree_raw_line($line);5213}52145215}elsif($formateq'plain') {5216open$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5217'-p',$hash_parent_param,$hash,"--"5218or die_error(500,"Open git-diff-tree failed");52195220}else{5221 die_error(400,"Unknown commitdiff format");5222}52235224# non-textual hash id's can be cached5225my$expires;5226if($hash=~m/^[0-9a-fA-F]{40}$/) {5227$expires="+1d";5228}52295230# write commit message5231if($formateq'html') {5232my$refs= git_get_references();5233my$ref= format_ref_marker($refs,$co{'id'});52345235 git_header_html(undef,$expires);5236 git_print_page_nav('commitdiff','',$hash,$co{'tree'},$hash,$formats_nav);5237 git_print_header_div('commit', esc_html($co{'title'}) .$ref,$hash);5238 git_print_authorship(\%co);5239print"<div class=\"page_body\">\n";5240if(@{$co{'comment'}} >1) {5241print"<div class=\"log\">\n";5242 git_print_log($co{'comment'}, -final_empty_line=>1, -remove_title =>1);5243print"</div>\n";# class="log"5244}52455246}elsif($formateq'plain') {5247my$refs= git_get_references("tags");5248my$tagname= git_get_rev_name_tags($hash);5249my$filename= basename($project) ."-$hash.patch";52505251print$cgi->header(5252-type =>'text/plain',5253-charset =>'utf-8',5254-expires =>$expires,5255-content_disposition =>'inline; filename="'."$filename".'"');5256my%ad= parse_date($co{'author_epoch'},$co{'author_tz'});5257print"From: ". to_utf8($co{'author'}) ."\n";5258print"Date:$ad{'rfc2822'} ($ad{'tz_local'})\n";5259print"Subject: ". to_utf8($co{'title'}) ."\n";52605261print"X-Git-Tag:$tagname\n"if$tagname;5262print"X-Git-Url: ".$cgi->self_url() ."\n\n";52635264foreachmy$line(@{$co{'comment'}}) {5265print to_utf8($line) ."\n";5266}5267print"---\n\n";5268}52695270# write patch5271if($formateq'html') {5272my$use_parents= !defined$hash_parent||5273$hash_parenteq'-c'||$hash_parenteq'--cc';5274 git_difftree_body(\@difftree,$hash,5275$use_parents? @{$co{'parents'}} :$hash_parent);5276print"<br/>\n";52775278 git_patchset_body($fd, \@difftree,$hash,5279$use_parents? @{$co{'parents'}} :$hash_parent);5280close$fd;5281print"</div>\n";# class="page_body"5282 git_footer_html();52835284}elsif($formateq'plain') {5285local$/=undef;5286print<$fd>;5287close$fd5288or print"Reading git-diff-tree failed\n";5289}5290}52915292sub git_commitdiff_plain {5293 git_commitdiff('plain');5294}52955296sub git_history {5297if(!defined$hash_base) {5298$hash_base= git_get_head_hash($project);5299}5300if(!defined$page) {5301$page=0;5302}5303my$ftype;5304my%co= parse_commit($hash_base)5305or die_error(404,"Unknown commit object");53065307my$refs= git_get_references();5308my$limit=sprintf("--max-count=%i", (100* ($page+1)));53095310my@commitlist= parse_commits($hash_base,101, (100*$page),5311$file_name,"--full-history")5312or die_error(404,"No such file or directory on given branch");53135314if(!defined$hash&&defined$file_name) {5315# some commits could have deleted file in question,5316# and not have it in tree, but one of them has to have it5317for(my$i=0;$i<=@commitlist;$i++) {5318$hash= git_get_hash_by_path($commitlist[$i]{'id'},$file_name);5319last ifdefined$hash;5320}5321}5322if(defined$hash) {5323$ftype= git_get_type($hash);5324}5325if(!defined$ftype) {5326 die_error(500,"Unknown type of object");5327}53285329my$paging_nav='';5330if($page>0) {5331$paging_nav.=5332$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,5333 file_name=>$file_name)},5334"first");5335$paging_nav.=" ⋅ ".5336$cgi->a({-href => href(-replay=>1, page=>$page-1),5337-accesskey =>"p", -title =>"Alt-p"},"prev");5338}else{5339$paging_nav.="first";5340$paging_nav.=" ⋅ prev";5341}5342my$next_link='';5343if($#commitlist>=100) {5344$next_link=5345$cgi->a({-href => href(-replay=>1, page=>$page+1),5346-accesskey =>"n", -title =>"Alt-n"},"next");5347$paging_nav.=" ⋅$next_link";5348}else{5349$paging_nav.=" ⋅ next";5350}53515352 git_header_html();5353 git_print_page_nav('history','',$hash_base,$co{'tree'},$hash_base,$paging_nav);5354 git_print_header_div('commit', esc_html($co{'title'}),$hash_base);5355 git_print_page_path($file_name,$ftype,$hash_base);53565357 git_history_body(\@commitlist,0,99,5358$refs,$hash_base,$ftype,$next_link);53595360 git_footer_html();5361}53625363sub git_search {5364 gitweb_check_feature('search')or die_error(403,"Search is disabled");5365if(!defined$searchtext) {5366 die_error(400,"Text field is empty");5367}5368if(!defined$hash) {5369$hash= git_get_head_hash($project);5370}5371my%co= parse_commit($hash);5372if(!%co) {5373 die_error(404,"Unknown commit object");5374}5375if(!defined$page) {5376$page=0;5377}53785379$searchtype||='commit';5380if($searchtypeeq'pickaxe') {5381# pickaxe may take all resources of your box and run for several minutes5382# with every query - so decide by yourself how public you make this feature5383 gitweb_check_feature('pickaxe')5384or die_error(403,"Pickaxe is disabled");5385}5386if($searchtypeeq'grep') {5387 gitweb_check_feature('grep')5388or die_error(403,"Grep is disabled");5389}53905391 git_header_html();53925393if($searchtypeeq'commit'or$searchtypeeq'author'or$searchtypeeq'committer') {5394my$greptype;5395if($searchtypeeq'commit') {5396$greptype="--grep=";5397}elsif($searchtypeeq'author') {5398$greptype="--author=";5399}elsif($searchtypeeq'committer') {5400$greptype="--committer=";5401}5402$greptype.=$searchtext;5403my@commitlist= parse_commits($hash,101, (100*$page),undef,5404$greptype,'--regexp-ignore-case',5405$search_use_regexp?'--extended-regexp':'--fixed-strings');54065407my$paging_nav='';5408if($page>0) {5409$paging_nav.=5410$cgi->a({-href => href(action=>"search", hash=>$hash,5411 searchtext=>$searchtext,5412 searchtype=>$searchtype)},5413"first");5414$paging_nav.=" ⋅ ".5415$cgi->a({-href => href(-replay=>1, page=>$page-1),5416-accesskey =>"p", -title =>"Alt-p"},"prev");5417}else{5418$paging_nav.="first";5419$paging_nav.=" ⋅ prev";5420}5421my$next_link='';5422if($#commitlist>=100) {5423$next_link=5424$cgi->a({-href => href(-replay=>1, page=>$page+1),5425-accesskey =>"n", -title =>"Alt-n"},"next");5426$paging_nav.=" ⋅$next_link";5427}else{5428$paging_nav.=" ⋅ next";5429}54305431if($#commitlist>=100) {5432}54335434 git_print_page_nav('','',$hash,$co{'tree'},$hash,$paging_nav);5435 git_print_header_div('commit', esc_html($co{'title'}),$hash);5436 git_search_grep_body(\@commitlist,0,99,$next_link);5437}54385439if($searchtypeeq'pickaxe') {5440 git_print_page_nav('','',$hash,$co{'tree'},$hash);5441 git_print_header_div('commit', esc_html($co{'title'}),$hash);54425443print"<table class=\"pickaxe search\">\n";5444my$alternate=1;5445$/="\n";5446open my$fd,'-|', git_cmd(),'--no-pager','log',@diff_opts,5447'--pretty=format:%H','--no-abbrev','--raw',"-S$searchtext",5448($search_use_regexp?'--pickaxe-regex': ());5449undef%co;5450my@files;5451while(my$line= <$fd>) {5452chomp$line;5453next unless$line;54545455my%set= parse_difftree_raw_line($line);5456if(defined$set{'commit'}) {5457# finish previous commit5458if(%co) {5459print"</td>\n".5460"<td class=\"link\">".5461$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5462" | ".5463$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5464print"</td>\n".5465"</tr>\n";5466}54675468if($alternate) {5469print"<tr class=\"dark\">\n";5470}else{5471print"<tr class=\"light\">\n";5472}5473$alternate^=1;5474%co= parse_commit($set{'commit'});5475my$author= chop_and_escape_str($co{'author_name'},15,5);5476print"<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n".5477"<td><i>$author</i></td>\n".5478"<td>".5479$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),5480-class=>"list subject"},5481 chop_and_escape_str($co{'title'},50) ."<br/>");5482}elsif(defined$set{'to_id'}) {5483next if($set{'to_id'} =~m/^0{40}$/);54845485print$cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},5486 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),5487-class=>"list"},5488"<span class=\"match\">". esc_path($set{'file'}) ."</span>") .5489"<br/>\n";5490}5491}5492close$fd;54935494# finish last commit (warning: repetition!)5495if(%co) {5496print"</td>\n".5497"<td class=\"link\">".5498$cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},"commit") .5499" | ".5500$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})},"tree");5501print"</td>\n".5502"</tr>\n";5503}55045505print"</table>\n";5506}55075508if($searchtypeeq'grep') {5509 git_print_page_nav('','',$hash,$co{'tree'},$hash);5510 git_print_header_div('commit', esc_html($co{'title'}),$hash);55115512print"<table class=\"grep_search\">\n";5513my$alternate=1;5514my$matches=0;5515$/="\n";5516open my$fd,"-|", git_cmd(),'grep','-n',5517$search_use_regexp? ('-E','-i') :'-F',5518$searchtext,$co{'tree'};5519my$lastfile='';5520while(my$line= <$fd>) {5521chomp$line;5522my($file,$lno,$ltext,$binary);5523last if($matches++>1000);5524if($line=~/^Binary file (.+) matches$/) {5525$file=$1;5526$binary=1;5527}else{5528(undef,$file,$lno,$ltext) =split(/:/,$line,4);5529}5530if($filene$lastfile) {5531$lastfileand print"</td></tr>\n";5532if($alternate++) {5533print"<tr class=\"dark\">\n";5534}else{5535print"<tr class=\"light\">\n";5536}5537print"<td class=\"list\">".5538$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5539 file_name=>"$file"),5540-class=>"list"}, esc_path($file));5541print"</td><td>\n";5542$lastfile=$file;5543}5544if($binary) {5545print"<div class=\"binary\">Binary file</div>\n";5546}else{5547$ltext= untabify($ltext);5548if($ltext=~m/^(.*)($search_regexp)(.*)$/i) {5549$ltext= esc_html($1, -nbsp=>1);5550$ltext.='<span class="match">';5551$ltext.= esc_html($2, -nbsp=>1);5552$ltext.='</span>';5553$ltext.= esc_html($3, -nbsp=>1);5554}else{5555$ltext= esc_html($ltext, -nbsp=>1);5556}5557print"<div class=\"pre\">".5558$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},5559 file_name=>"$file").'#l'.$lno,5560-class=>"linenr"},sprintf('%4i',$lno))5561.' '.$ltext."</div>\n";5562}5563}5564if($lastfile) {5565print"</td></tr>\n";5566if($matches>1000) {5567print"<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";5568}5569}else{5570print"<div class=\"diff nodifferences\">No matches found</div>\n";5571}5572close$fd;55735574print"</table>\n";5575}5576 git_footer_html();5577}55785579sub git_search_help {5580 git_header_html();5581 git_print_page_nav('','',$hash,$hash,$hash);5582print<<EOT;5583<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without5584regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,5585the pattern entered is recognized as the POSIX extended5586<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case5587insensitive).</p>5588<dl>5589<dt><b>commit</b></dt>5590<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>5591EOT5592my($have_grep) = gitweb_check_feature('grep');5593if($have_grep) {5594print<<EOT;5595<dt><b>grep</b></dt>5596<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing5597 a different one) are searched for the given pattern. On large trees, this search can take5598a while and put some strain on the server, so please use it with some consideration. Note that5599due to git-grep peculiarity, currently if regexp mode is turned off, the matches are5600case-sensitive.</dd>5601EOT5602}5603print<<EOT;5604<dt><b>author</b></dt>5605<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>5606<dt><b>committer</b></dt>5607<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>5608EOT5609my($have_pickaxe) = gitweb_check_feature('pickaxe');5610if($have_pickaxe) {5611print<<EOT;5612<dt><b>pickaxe</b></dt>5613<dd>All commits that caused the string to appear or disappear from any file (changes that5614added, removed or "modified" the string) will be listed. This search can take a while and5615takes a lot of strain on the server, so please use it wisely. Note that since you may be5616interested even in changes just changing the case as well, this search is case sensitive.</dd>5617EOT5618}5619print"</dl>\n";5620 git_footer_html();5621}56225623sub git_shortlog {5624my$head= git_get_head_hash($project);5625if(!defined$hash) {5626$hash=$head;5627}5628if(!defined$page) {5629$page=0;5630}5631my$refs= git_get_references();56325633my$commit_hash=$hash;5634if(defined$hash_parent) {5635$commit_hash="$hash_parent..$hash";5636}5637my@commitlist= parse_commits($commit_hash,101, (100*$page));56385639my$paging_nav= format_paging_nav('shortlog',$hash,$head,$page,$#commitlist>=100);5640my$next_link='';5641if($#commitlist>=100) {5642$next_link=5643$cgi->a({-href => href(-replay=>1, page=>$page+1),5644-accesskey =>"n", -title =>"Alt-n"},"next");5645}56465647 git_header_html();5648 git_print_page_nav('shortlog','',$hash,$hash,$hash,$paging_nav);5649 git_print_header_div('summary',$project);56505651 git_shortlog_body(\@commitlist,0,99,$refs,$next_link);56525653 git_footer_html();5654}56555656## ......................................................................5657## feeds (RSS, Atom; OPML)56585659sub git_feed {5660my$format=shift||'atom';5661my($have_blame) = gitweb_check_feature('blame');56625663# Atom: http://www.atomenabled.org/developers/syndication/5664# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ5665if($formatne'rss'&&$formatne'atom') {5666 die_error(400,"Unknown web feed format");5667}56685669# log/feed of current (HEAD) branch, log of given branch, history of file/directory5670my$head=$hash||'HEAD';5671my@commitlist= parse_commits($head,150,0,$file_name);56725673my%latest_commit;5674my%latest_date;5675my$content_type="application/$format+xml";5676if(defined$cgi->http('HTTP_ACCEPT') &&5677$cgi->Accept('text/xml') >$cgi->Accept($content_type)) {5678# browser (feed reader) prefers text/xml5679$content_type='text/xml';5680}5681if(defined($commitlist[0])) {5682%latest_commit= %{$commitlist[0]};5683%latest_date= parse_date($latest_commit{'author_epoch'});5684print$cgi->header(5685-type =>$content_type,5686-charset =>'utf-8',5687-last_modified =>$latest_date{'rfc2822'});5688}else{5689print$cgi->header(5690-type =>$content_type,5691-charset =>'utf-8');5692}56935694# Optimization: skip generating the body if client asks only5695# for Last-Modified date.5696return if($cgi->request_method()eq'HEAD');56975698# header variables5699my$title="$site_name-$project/$action";5700my$feed_type='log';5701if(defined$hash) {5702$title.=" - '$hash'";5703$feed_type='branch log';5704if(defined$file_name) {5705$title.=" ::$file_name";5706$feed_type='history';5707}5708}elsif(defined$file_name) {5709$title.=" -$file_name";5710$feed_type='history';5711}5712$title.="$feed_type";5713my$descr= git_get_project_description($project);5714if(defined$descr) {5715$descr= esc_html($descr);5716}else{5717$descr="$project".5718($formateq'rss'?'RSS':'Atom') .5719" feed";5720}5721my$owner= git_get_project_owner($project);5722$owner= esc_html($owner);57235724#header5725my$alt_url;5726if(defined$file_name) {5727$alt_url= href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);5728}elsif(defined$hash) {5729$alt_url= href(-full=>1, action=>"log", hash=>$hash);5730}else{5731$alt_url= href(-full=>1, action=>"summary");5732}5733print qq!<?xml version="1.0" encoding="utf-8"?>\n!;5734if($formateq'rss') {5735print<<XML;5736<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">5737<channel>5738XML5739print"<title>$title</title>\n".5740"<link>$alt_url</link>\n".5741"<description>$descr</description>\n".5742"<language>en</language>\n";5743}elsif($formateq'atom') {5744print<<XML;5745<feed xmlns="http://www.w3.org/2005/Atom">5746XML5747print"<title>$title</title>\n".5748"<subtitle>$descr</subtitle>\n".5749'<link rel="alternate" type="text/html" href="'.5750$alt_url.'" />'."\n".5751'<link rel="self" type="'.$content_type.'" href="'.5752$cgi->self_url() .'" />'."\n".5753"<id>". href(-full=>1) ."</id>\n".5754# use project owner for feed author5755"<author><name>$owner</name></author>\n";5756if(defined$favicon) {5757print"<icon>". esc_url($favicon) ."</icon>\n";5758}5759if(defined$logo_url) {5760# not twice as wide as tall: 72 x 27 pixels5761print"<logo>". esc_url($logo) ."</logo>\n";5762}5763if(!%latest_date) {5764# dummy date to keep the feed valid until commits trickle in:5765print"<updated>1970-01-01T00:00:00Z</updated>\n";5766}else{5767print"<updated>$latest_date{'iso-8601'}</updated>\n";5768}5769}57705771# contents5772for(my$i=0;$i<=$#commitlist;$i++) {5773my%co= %{$commitlist[$i]};5774my$commit=$co{'id'};5775# we read 150, we always show 30 and the ones more recent than 48 hours5776if(($i>=20) && ((time-$co{'author_epoch'}) >48*60*60)) {5777last;5778}5779my%cd= parse_date($co{'author_epoch'});57805781# get list of changed files5782open my$fd,"-|", git_cmd(),"diff-tree",'-r',@diff_opts,5783$co{'parent'} ||"--root",5784$co{'id'},"--", (defined$file_name?$file_name: ())5785ornext;5786my@difftree=map{chomp;$_} <$fd>;5787close$fd5788ornext;57895790# print element (entry, item)5791my$co_url= href(-full=>1, action=>"commitdiff", hash=>$commit);5792if($formateq'rss') {5793print"<item>\n".5794"<title>". esc_html($co{'title'}) ."</title>\n".5795"<author>". esc_html($co{'author'}) ."</author>\n".5796"<pubDate>$cd{'rfc2822'}</pubDate>\n".5797"<guid isPermaLink=\"true\">$co_url</guid>\n".5798"<link>$co_url</link>\n".5799"<description>". esc_html($co{'title'}) ."</description>\n".5800"<content:encoded>".5801"<![CDATA[\n";5802}elsif($formateq'atom') {5803print"<entry>\n".5804"<title type=\"html\">". esc_html($co{'title'}) ."</title>\n".5805"<updated>$cd{'iso-8601'}</updated>\n".5806"<author>\n".5807" <name>". esc_html($co{'author_name'}) ."</name>\n";5808if($co{'author_email'}) {5809print" <email>". esc_html($co{'author_email'}) ."</email>\n";5810}5811print"</author>\n".5812# use committer for contributor5813"<contributor>\n".5814" <name>". esc_html($co{'committer_name'}) ."</name>\n";5815if($co{'committer_email'}) {5816print" <email>". esc_html($co{'committer_email'}) ."</email>\n";5817}5818print"</contributor>\n".5819"<published>$cd{'iso-8601'}</published>\n".5820"<link rel=\"alternate\"type=\"text/html\"href=\"$co_url\"/>\n".5821"<id>$co_url</id>\n".5822"<content type=\"xhtml\"xml:base=\"". esc_url($my_url) ."\">\n".5823"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";5824}5825my$comment=$co{'comment'};5826print"<pre>\n";5827foreachmy$line(@$comment) {5828$line= esc_html($line);5829print"$line\n";5830}5831print"</pre><ul>\n";5832foreachmy$difftree_line(@difftree) {5833my%difftree= parse_difftree_raw_line($difftree_line);5834next if!$difftree{'from_id'};58355836my$file=$difftree{'file'} ||$difftree{'to_file'};58375838print"<li>".5839"[".5840$cgi->a({-href => href(-full=>1, action=>"blobdiff",5841 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},5842 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},5843 file_name=>$file, file_parent=>$difftree{'from_file'}),5844-title =>"diff"},'D');5845if($have_blame) {5846print$cgi->a({-href => href(-full=>1, action=>"blame",5847 file_name=>$file, hash_base=>$commit),5848-title =>"blame"},'B');5849}5850# if this is not a feed of a file history5851if(!defined$file_name||$file_namene$file) {5852print$cgi->a({-href => href(-full=>1, action=>"history",5853 file_name=>$file, hash=>$commit),5854-title =>"history"},'H');5855}5856$file= esc_path($file);5857print"] ".5858"$file</li>\n";5859}5860if($formateq'rss') {5861print"</ul>]]>\n".5862"</content:encoded>\n".5863"</item>\n";5864}elsif($formateq'atom') {5865print"</ul>\n</div>\n".5866"</content>\n".5867"</entry>\n";5868}5869}58705871# end of feed5872if($formateq'rss') {5873print"</channel>\n</rss>\n";5874}elsif($formateq'atom') {5875print"</feed>\n";5876}5877}58785879sub git_rss {5880 git_feed('rss');5881}58825883sub git_atom {5884 git_feed('atom');5885}58865887sub git_opml {5888my@list= git_get_projects_list();58895890print$cgi->header(-type =>'text/xml', -charset =>'utf-8');5891print<<XML;5892<?xml version="1.0" encoding="utf-8"?>5893<opml version="1.0">5894<head>5895 <title>$site_nameOPML Export</title>5896</head>5897<body>5898<outline text="git RSS feeds">5899XML59005901foreachmy$pr(@list) {5902my%proj=%$pr;5903my$head= git_get_head_hash($proj{'path'});5904if(!defined$head) {5905next;5906}5907$git_dir="$projectroot/$proj{'path'}";5908my%co= parse_commit($head);5909if(!%co) {5910next;5911}59125913my$path= esc_html(chop_str($proj{'path'},25,5));5914my$rss="$my_url?p=$proj{'path'};a=rss";5915my$html="$my_url?p=$proj{'path'};a=summary";5916print"<outline type=\"rss\"text=\"$path\"title=\"$path\"xmlUrl=\"$rss\"htmlUrl=\"$html\"/>\n";5917}5918print<<XML;5919</outline>5920</body>5921</opml>5922XML5923}