gitweb: standarize HTTP status codes
Many error status codes simply default to 403 Forbidden, which is not correct in most cases. This patch makes gitweb return semantically correct status codes. For convenience the die_error function now only takes the status code without reason as first parameter (e.g. 404 instead of "404 Not Found"), and it now defaults to 500 (Internal Server Error), even though the default is not used anywhere. Also documented status code conventions in die_error. Signed-off-by: Lea Wiemann <LeWiemann@gmail.com> Acked-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lea Wiemann committed
Jun 19, 2008 at 22:03 UTC
074afaa0cf69e7d49bc00d969f57893c9ddea748
1 file changed
+105
-106
gitweb/gitweb.perl
+105
-106
@@ -386,7 +386,7 @@ $projects_list ||= $projectroot;
386
our $action = $cgi->param('a');
387
if (defined $action) {
388
if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
389
- die_error(undef, "Invalid action parameter");
389
+ die_error(400, "Invalid action parameter");
390
}
391
}
392
@@ -399,21 +399,21 @@ if (defined $project) {
399
($export_ok && !(-e "$projectroot/$project/$export_ok")) ||
400
($strict_export && !project_in_list($project))) {
401
undef $project;
402
- die_error(undef, "No such project");
402
+ die_error(404, "No such project");
403
}
404
}
405
406
our $file_name = $cgi->param('f');
407
if (defined $file_name) {
408
if (!validate_pathname($file_name)) {
409
- die_error(undef, "Invalid file parameter");
409
+ die_error(400, "Invalid file parameter");
410
}
411
}
412
413
our $file_parent = $cgi->param('fp');
414
if (defined $file_parent) {
415
if (!validate_pathname($file_parent)) {
416
- die_error(undef, "Invalid file parent parameter");
416
+ die_error(400, "Invalid file parent parameter");
417
}
418
}
419
@@ -421,21 +421,21 @@ if (defined $file_parent) {
421
our $hash = $cgi->param('h');
422
if (defined $hash) {
423
if (!validate_refname($hash)) {
424
- die_error(undef, "Invalid hash parameter");
424
+ die_error(400, "Invalid hash parameter");
425
}
426
}
427
428
our $hash_parent = $cgi->param('hp');
429
if (defined $hash_parent) {
430
if (!validate_refname($hash_parent)) {
431
- die_error(undef, "Invalid hash parent parameter");
431
+ die_error(400, "Invalid hash parent parameter");
432
}
433
}
434
435
our $hash_base = $cgi->param('hb');
436
if (defined $hash_base) {
437
if (!validate_refname($hash_base)) {
438
- die_error(undef, "Invalid hash base parameter");
438
+ die_error(400, "Invalid hash base parameter");
439
}
440
}
441
@@ -447,10 +447,10 @@ our @extra_options = $cgi->param('opt');
447
if (defined @extra_options) {
448
foreach my $opt (@extra_options) {
449
if (not exists $allowed_options{$opt}) {
450
- die_error(undef, "Invalid option parameter");
450
+ die_error(400, "Invalid option parameter");
451
}
452
if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
453
- die_error(undef, "Invalid option parameter for this action");
453
+ die_error(400, "Invalid option parameter for this action");
454
}
455
}
456
}
@@ -458,7 +458,7 @@ if (defined @extra_options) {
458
our $hash_parent_base = $cgi->param('hpb');
459
if (defined $hash_parent_base) {
460
if (!validate_refname($hash_parent_base)) {
461
- die_error(undef, "Invalid hash parent base parameter");
461
+ die_error(400, "Invalid hash parent base parameter");
462
}
463
}
464
@@ -466,14 +466,14 @@ if (defined $hash_parent_base) {
466
our $page = $cgi->param('pg');
467
if (defined $page) {
468
if ($page =~ m/[^0-9]/) {
469
- die_error(undef, "Invalid page parameter");
469
+ die_error(400, "Invalid page parameter");
470
}
471
}
472
473
our $searchtype = $cgi->param('st');
474
if (defined $searchtype) {
475
if ($searchtype =~ m/[^a-z]/) {
476
- die_error(undef, "Invalid searchtype parameter");
476
+ die_error(400, "Invalid searchtype parameter");
477
}
478
}
479
@@ -483,7 +483,7 @@ our $searchtext = $cgi->param('s');
483
our $search_regexp;
484
if (defined $searchtext) {
485
if (length($searchtext) < 2) {
486
- die_error(undef, "At least two characters are required for search parameter");
486
+ die_error(403, "At least two characters are required for search parameter");
487
}
488
$search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
489
}
@@ -580,11 +580,11 @@ if (!defined $action) {
580
}
581
}
582
if (!defined($actions{$action})) {
583
- die_error(undef, "Unknown action");
583
+ die_error(400, "Unknown action");
584
}
585
if ($action !~ m/^(opml|project_list|project_index)$/ &&
586
!$project) {
587
- die_error(undef, "Project needed");
587
+ die_error(400, "Project needed");
588
}
589
$actions{$action}->();
590
exit;
@@ -1665,7 +1665,7 @@ sub git_get_hash_by_path {
1665
$path =~ s,/+$,,;
1666
1667
open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
1668
- or die_error(undef, "Open git-ls-tree failed");
1668
+ or die_error(500, "Open git-ls-tree failed");
1669
my $line = <$fd>;
1670
close $fd or return undef;
1671
@@ -2127,7 +2127,7 @@ sub parse_commit {
2127
"--max-count=1",
2128
$commit_id,
2129
"--",
2130
- or die_error(undef, "Open git-rev-list failed");
2130
+ or die_error(500, "Open git-rev-list failed");
2131
%co = parse_commit_text(<$fd>, 1);
2132
close $fd;
2133
@@ -2152,7 +2152,7 @@ sub parse_commits {
2152
$commit_id,
2153
"--",
2154
($filename ? ($filename) : ())
2155
- or die_error(undef, "Open git-rev-list failed");
2155
+ or die_error(500, "Open git-rev-list failed");
2156
while (my $line = <$fd>) {
2157
my %co = parse_commit_text($line);
2158
push @cos, \%co;
@@ -2672,11 +2672,26 @@ sub git_footer_html {
2672
"</html>";
2673
}
2674
2675
+# die_error(<http_status_code>, <error_message>)
2676
+# Example: die_error(404, 'Hash not found')
2677
+# By convention, use the following status codes (as defined in RFC 2616):
2678
+# 400: Invalid or missing CGI parameters, or
2679
+# requested object exists but has wrong type.
2680
+# 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
2681
+# this server or project.
2682
+# 404: Requested object/revision/project doesn't exist.
2683
+# 500: The server isn't configured properly, or
2684
+# an internal error occurred (e.g. failed assertions caused by bugs), or
2685
+# an unknown error occurred (e.g. the git binary died unexpectedly).
2686
sub die_error {
2676
- my $status = shift || "403 Forbidden";
2677
- my $error = shift || "Malformed query, file missing or permission denied";
2678
-
2679
- git_header_html($status);
2687
+ my $status = shift || 500;
2688
+ my $error = shift || "Internal server error";
2689
+
2690
+ my %http_responses = (400 => '400 Bad Request',
2691
+ 403 => '403 Forbidden',
2692
+ 404 => '404 Not Found',
2693
+ 500 => '500 Internal Server Error');
2694
+ git_header_html($http_responses{$status});
2695
print <<EOF;
2696
<div class="page_body">
2697
<br /><br />
@@ -3924,12 +3939,12 @@ sub git_search_grep_body {
3939
sub git_project_list {
3940
my $order = $cgi->param('o');
3941
if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3927
- die_error(undef, "Unknown order parameter");
3942
+ die_error(400, "Unknown order parameter");
3943
}
3944
3945
my @list = git_get_projects_list();
3946
if (!@list) {
3932
- die_error(undef, "No projects found");
3947
+ die_error(404, "No projects found");
3948
}
3949
3950
git_header_html();
@@ -3947,12 +3962,12 @@ sub git_project_list {
3962
sub git_forks {
3963
my $order = $cgi->param('o');
3964
if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3950
- die_error(undef, "Unknown order parameter");
3965
+ die_error(400, "Unknown order parameter");
3966
}
3967
3968
my @list = git_get_projects_list($project);
3969
if (!@list) {
3955
- die_error(undef, "No forks found");
3970
+ die_error(404, "No forks found");
3971
}
3972
3973
git_header_html();
@@ -4081,7 +4096,7 @@ sub git_tag {
4096
my %tag = parse_tag($hash);
4097
4098
if (! %tag) {
4084
- die_error(undef, "Unknown tag object");
4099
+ die_error(404, "Unknown tag object");
4100
}
4101
4102
git_print_header_div('commit', esc_html($tag{'name'}), $hash);
@@ -4117,26 +4132,25 @@ sub git_blame2 {
4132
my $fd;
4133
my $ftype;
4134
4120
- my ($have_blame) = gitweb_check_feature('blame');
4121
- if (!$have_blame) {
4122
- die_error('403 Permission denied', "Permission denied");
4123
- }
4124
- die_error('404 Not Found', "File name not defined") if (!$file_name);
4135
+ gitweb_check_feature('blame')
4136
+ or die_error(403, "Blame view not allowed");
4137
+
4138
+ die_error(400, "No file name given") unless $file_name;
4139
$hash_base ||= git_get_head_hash($project);
4126
- die_error(undef, "Couldn't find base commit") unless ($hash_base);
4140
+ die_error(404, "Couldn't find base commit") unless ($hash_base);
4141
my %co = parse_commit($hash_base)
4128
- or die_error(undef, "Reading commit failed");
4142
+ or die_error(404, "Commit not found");
4143
if (!defined $hash) {
4144
$hash = git_get_hash_by_path($hash_base, $file_name, "blob")
4131
- or die_error(undef, "Error looking up file");
4145
+ or die_error(404, "Error looking up file");
4146
}
4147
$ftype = git_get_type($hash);
4148
if ($ftype !~ "blob") {
4135
- die_error('400 Bad Request', "Object is not a blob");
4149
+ die_error(400, "Object is not a blob");
4150
}
4151
open ($fd, "-|", git_cmd(), "blame", '-p', '--',
4152
$file_name, $hash_base)
4139
- or die_error(undef, "Open git-blame failed");
4153
+ or die_error(500, "Open git-blame failed");
4154
git_header_html();
4155
my $formats_nav =
4156
$cgi->a({-href => href(action=>"blob", -replay=>1)},
@@ -4198,7 +4212,7 @@ HTML
4212
print "</td>\n";
4213
}
4214
open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^")
4201
- or die_error(undef, "Open git-rev-parse failed");
4215
+ or die_error(500, "Open git-rev-parse failed");
4216
my $parent_commit = <$dd>;
4217
close $dd;
4218
chomp($parent_commit);
@@ -4352,9 +4366,9 @@ sub git_blob_plain {
4366
if (defined $file_name) {
4367
my $base = $hash_base || git_get_head_hash($project);
4368
$hash = git_get_hash_by_path($base, $file_name, "blob")
4355
- or die_error(undef, "Error lookup file");
4369
+ or die_error(404, "Cannot find file");
4370
} else {
4357
- die_error(undef, "No file name defined");
4371
+ die_error(400, "No file name defined");
4372
}
4373
} elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4374
# blobs defined by non-textual hash id's can be cached
@@ -4362,7 +4376,7 @@ sub git_blob_plain {
4376
}
4377
4378
open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
4365
- or die_error(undef, "Open git-cat-file blob '$hash' failed");
4379
+ or die_error(500, "Open git-cat-file blob '$hash' failed");
4380
4381
# content-type (can include charset)
4382
$type = blob_contenttype($fd, $file_name, $type);
@@ -4394,9 +4408,9 @@ sub git_blob {
4408
if (defined $file_name) {
4409
my $base = $hash_base || git_get_head_hash($project);
4410
$hash = git_get_hash_by_path($base, $file_name, "blob")
4397
- or die_error(undef, "Error lookup file");
4411
+ or die_error(404, "Cannot find file");
4412
} else {
4399
- die_error(undef, "No file name defined");
4413
+ die_error(400, "No file name defined");
4414
}
4415
} elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4416
# blobs defined by non-textual hash id's can be cached
@@ -4405,7 +4419,7 @@ sub git_blob {
4419
4420
my ($have_blame) = gitweb_check_feature('blame');
4421
open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
4408
- or die_error(undef, "Couldn't cat $file_name, $hash");
4422
+ or die_error(500, "Couldn't cat $file_name, $hash");
4423
my $mimetype = blob_mimetype($fd, $file_name);
4424
if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B $fd) {
4425
close $fd;
@@ -4486,9 +4500,9 @@ sub git_tree {
4500
}
4501
$/ = "\0";
4502
open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
4489
- or die_error(undef, "Open git-ls-tree failed");
4503
+ or die_error(500, "Open git-ls-tree failed");
4504
my @entries = map { chomp; $_ } <$fd>;
4491
- close $fd or die_error(undef, "Reading tree failed");
4505
+ close $fd or die_error(404, "Reading tree failed");
4506
$/ = "\n";
4507
4508
my $refs = git_get_references();
@@ -4578,16 +4592,16 @@ sub git_snapshot {
4592
4593
my $format = $cgi->param('sf');
4594
if (!@supported_fmts) {
4581
- die_error('403 Permission denied', "Permission denied");
4595
+ die_error(403, "Snapshots not allowed");
4596
}
4597
# default to first supported snapshot format
4598
$format ||= $supported_fmts[0];
4599
if ($format !~ m/^[a-z0-9]+$/) {
4586
- die_error(undef, "Invalid snapshot format parameter");
4600
+ die_error(400, "Invalid snapshot format parameter");
4601
} elsif (!exists($known_snapshot_formats{$format})) {
4588
- die_error(undef, "Unknown snapshot format");
4602
+ die_error(400, "Unknown snapshot format");
4603
} elsif (!grep($_ eq $format, @supported_fmts)) {
4590
- die_error(undef, "Unsupported snapshot format");
4604
+ die_error(403, "Unsupported snapshot format");
4605
}
4606
4607
if (!defined $hash) {
@@ -4615,7 +4629,7 @@ sub git_snapshot {
4629
-status => '200 OK');
4630
4631
open my $fd, "-|", $cmd
4618
- or die_error(undef, "Execute git-archive failed");
4632
+ or die_error(500, "Execute git-archive failed");
4633
binmode STDOUT, ':raw';
4634
print <$fd>;
4635
binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
@@ -4683,10 +4697,8 @@ sub git_log {
4697
4698
sub git_commit {
4699
$hash ||= $hash_base || "HEAD";
4686
- my %co = parse_commit($hash);
4687
- if (!%co) {
4688
- die_error(undef, "Unknown commit object");
4689
- }
4700
+ my %co = parse_commit($hash)
4701
+ or die_error(404, "Unknown commit object");
4702
my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
4703
my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
4704
@@ -4726,9 +4738,9 @@ sub git_commit {
4738
@diff_opts,
4739
(@$parents <= 1 ? $parent : '-c'),
4740
$hash, "--"
4729
- or die_error(undef, "Open git-diff-tree failed");
4741
+ or die_error(500, "Open git-diff-tree failed");
4742
@difftree = map { chomp; $_ } <$fd>;
4731
- close $fd or die_error(undef, "Reading git-diff-tree failed");
4743
+ close $fd or die_error(404, "Reading git-diff-tree failed");
4744
4745
# non-textual hash id's can be cached
4746
my $expires;
@@ -4821,33 +4833,33 @@ sub git_object {
4833
4834
open my $fd, "-|", quote_command(
4835
git_cmd(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
4824
- or die_error('404 Not Found', "Object does not exist");
4836
+ or die_error(404, "Object does not exist");
4837
$type = <$fd>;
4838
chomp $type;
4839
close $fd
4828
- or die_error('404 Not Found', "Object does not exist");
4840
+ or die_error(404, "Object does not exist");
4841
4842
# - hash_base and file_name
4843
} elsif ($hash_base && defined $file_name) {
4844
$file_name =~ s,/+$,,;
4845
4846
system(git_cmd(), "cat-file", '-e', $hash_base) == 0
4835
- or die_error('404 Not Found', "Base object does not exist");
4847
+ or die_error(404, "Base object does not exist");
4848
4849
# here errors should not hapen
4850
open my $fd, "-|", git_cmd(), "ls-tree", $hash_base, "--", $file_name
4839
- or die_error(undef, "Open git-ls-tree failed");
4851
+ or die_error(500, "Open git-ls-tree failed");
4852
my $line = <$fd>;
4853
close $fd;
4854
4855
#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4856
unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4845
- die_error('404 Not Found', "File or directory for given base does not exist");
4857
+ die_error(404, "File or directory for given base does not exist");
4858
}
4859
$type = $2;
4860
$hash = $3;
4861
} else {
4850
- die_error('404 Not Found', "Not enough information to find object");
4862
+ die_error(400, "Not enough information to find object");
4863
}
4864
4865
print $cgi->redirect(-uri => href(action=>$type, -full=>1,
@@ -4872,12 +4884,12 @@ sub git_blobdiff {
4884
open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4885
$hash_parent_base, $hash_base,
4886
"--", (defined $file_parent ? $file_parent : ()), $file_name
4875
- or die_error(undef, "Open git-diff-tree failed");
4887
+ or die_error(500, "Open git-diff-tree failed");
4888
@difftree = map { chomp; $_ } <$fd>;
4889
close $fd
4878
- or die_error(undef, "Reading git-diff-tree failed");
4890
+ or die_error(404, "Reading git-diff-tree failed");
4891
@difftree
4880
- or die_error('404 Not Found', "Blob diff not found");
4892
+ or die_error(404, "Blob diff not found");
4893
4894
} elsif (defined $hash &&
4895
$hash =~ /[0-9a-fA-F]{40}/) {
@@ -4886,23 +4898,23 @@ sub git_blobdiff {
4898
# read filtered raw output
4899
open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4900
$hash_parent_base, $hash_base, "--"
4889
- or die_error(undef, "Open git-diff-tree failed");
4901
+ or die_error(500, "Open git-diff-tree failed");
4902
@difftree =
4903
# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4904
# $hash == to_id
4905
grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4906
map { chomp; $_ } <$fd>;
4907
close $fd
4896
- or die_error(undef, "Reading git-diff-tree failed");
4908
+ or die_error(404, "Reading git-diff-tree failed");
4909
@difftree
4898
- or die_error('404 Not Found', "Blob diff not found");
4910
+ or die_error(404, "Blob diff not found");
4911
4912
} else {
4901
- die_error('404 Not Found', "Missing one of the blob diff parameters");
4913
+ die_error(400, "Missing one of the blob diff parameters");
4914
}
4915
4916
if (@difftree > 1) {
4905
- die_error('404 Not Found', "Ambiguous blob diff specification");
4917
+ die_error(400, "Ambiguous blob diff specification");
4918
}
4919
4920
%diffinfo = parse_difftree_raw_line($difftree[0]);
@@ -4923,7 +4935,7 @@ sub git_blobdiff {
4935
'-p', ($format eq 'html' ? "--full-index" : ()),
4936
$hash_parent_base, $hash_base,
4937
"--", (defined $file_parent ? $file_parent : ()), $file_name
4926
- or die_error(undef, "Open git-diff-tree failed");
4938
+ or die_error(500, "Open git-diff-tree failed");
4939
}
4940
4941
# old/legacy style URI
@@ -4959,9 +4971,9 @@ sub git_blobdiff {
4971
open $fd, "-|", git_cmd(), "diff", @diff_opts,
4972
'-p', ($format eq 'html' ? "--full-index" : ()),
4973
$hash_parent, $hash, "--"
4962
- or die_error(undef, "Open git-diff failed");
4974
+ or die_error(500, "Open git-diff failed");
4975
} else {
4964
- die_error('404 Not Found', "Missing one of the blob diff parameters")
4976
+ die_error(400, "Missing one of the blob diff parameters")
4977
unless %diffinfo;
4978
}
4979
@@ -4994,7 +5006,7 @@ sub git_blobdiff {
5006
print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5007
5008
} else {
4997
- die_error(undef, "Unknown blobdiff format");
5009
+ die_error(400, "Unknown blobdiff format");
5010
}
5011
5012
# patch
@@ -5029,10 +5041,8 @@ sub git_blobdiff_plain {
5041
sub git_commitdiff {
5042
my $format = shift || 'html';
5043
$hash ||= $hash_base || "HEAD";
5032
- my %co = parse_commit($hash);
5033
- if (!%co) {
5034
- die_error(undef, "Unknown commit object");
5035
- }
5044
+ my %co = parse_commit($hash)
5045
+ or die_error(404, "Unknown commit object");
5046
5047
# choose format for commitdiff for merge
5048
if (! defined $hash_parent && @{$co{'parents'}} > 1) {
@@ -5114,7 +5124,7 @@ sub git_commitdiff {
5124
open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5125
"--no-commit-id", "--patch-with-raw", "--full-index",
5126
$hash_parent_param, $hash, "--"
5117
- or die_error(undef, "Open git-diff-tree failed");
5127
+ or die_error(500, "Open git-diff-tree failed");
5128
5129
while (my $line = <$fd>) {
5130
chomp $line;
@@ -5126,10 +5136,10 @@ sub git_commitdiff {
5136
} elsif ($format eq 'plain') {
5137
open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5138
'-p', $hash_parent_param, $hash, "--"
5129
- or die_error(undef, "Open git-diff-tree failed");
5139
+ or die_error(500, "Open git-diff-tree failed");
5140
5141
} else {
5132
- die_error(undef, "Unknown commitdiff format");
5142
+ die_error(400, "Unknown commitdiff format");
5143
}
5144
5145
# non-textual hash id's can be cached
@@ -5212,19 +5222,15 @@ sub git_history {
5222
$page = 0;
5223
}
5224
my $ftype;
5215
- my %co = parse_commit($hash_base);
5216
- if (!%co) {
5217
- die_error(undef, "Unknown commit object");
5218
- }
5225
+ my %co = parse_commit($hash_base)
5226
+ or die_error(404, "Unknown commit object");
5227
5228
my $refs = git_get_references();
5229
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5230
5231
my @commitlist = parse_commits($hash_base, 101, (100 * $page),
5224
- $file_name, "--full-history");
5225
- if (!@commitlist) {
5226
- die_error('404 Not Found', "No such file or directory on given branch");
5227
- }
5232
+ $file_name, "--full-history")
5233
+ or die_error(404, "No such file or directory on given branch");
5234
5235
if (!defined $hash && defined $file_name) {
5236
# some commits could have deleted file in question,
@@ -5238,7 +5244,7 @@ sub git_history {
5244
$ftype = git_get_type($hash);
5245
}
5246
if (!defined $ftype) {
5241
- die_error(undef, "Unknown type of object");
5247
+ die_error(500, "Unknown type of object");
5248
}
5249
5250
my $paging_nav = '';
@@ -5276,19 +5282,16 @@ sub git_history {
5282
}
5283
5284
sub git_search {
5279
- my ($have_search) = gitweb_check_feature('search');
5280
- if (!$have_search) {
5281
- die_error('403 Permission denied', "Permission denied");
5282
- }
5285
+ gitweb_check_feature('search') or die_error(403, "Search is disabled");
5286
if (!defined $searchtext) {
5284
- die_error(undef, "Text field empty");
5287
+ die_error(400, "Text field is empty");
5288
}
5289
if (!defined $hash) {
5290
$hash = git_get_head_hash($project);
5291
}
5292
my %co = parse_commit($hash);
5293
if (!%co) {
5291
- die_error(undef, "Unknown commit object");
5294
+ die_error(404, "Unknown commit object");
5295
}
5296
if (!defined $page) {
5297
$page = 0;
@@ -5298,16 +5301,12 @@ sub git_search {
5301
if ($searchtype eq 'pickaxe') {
5302
# pickaxe may take all resources of your box and run for several minutes
5303
# with every query - so decide by yourself how public you make this feature
5301
- my ($have_pickaxe) = gitweb_check_feature('pickaxe');
5302
- if (!$have_pickaxe) {
5303
- die_error('403 Permission denied', "Permission denied");
5304
- }
5304
+ gitweb_check_feature('pickaxe')
5305
+ or die_error(403, "Pickaxe is disabled");
5306
}
5307
if ($searchtype eq 'grep') {
5307
- my ($have_grep) = gitweb_check_feature('grep');
5308
- if (!$have_grep) {
5309
- die_error('403 Permission denied', "Permission denied");
5310
- }
5308
+ gitweb_check_feature('grep')
5309
+ or die_error(403, "Grep is disabled");
5310
}
5311
5312
git_header_html();
@@ -5581,7 +5580,7 @@ sub git_feed {
5580
# Atom: http://www.atomenabled.org/developers/syndication/
5581
# RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5582
if ($format ne 'rss' && $format ne 'atom') {
5584
- die_error(undef, "Unknown web feed format");
5583
+ die_error(400, "Unknown web feed format");
5584
}
5585
5586
# log/feed of current (HEAD) branch, log of given branch, history of file/directory