{"thread":{"id":"41671","subject":"[PATCH 2/6] gitweb.perl : added ability to debug requests coming through gitweb interface by adding an option to request URL (also requires server-side envvar \"GITWEB_MAY_DEBUG=yes\")","startedAt":"2016-03-11T13:24:44Z","lastAt":"2016-03-11T13:24:49Z","messageCount":6,"participants":["Jim Klimov"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"280616","messageId":"1457702689-9084-1-git-send-email-jim@jimklimov.com","threadId":"41671","inReplyTo":null,"subject":"[PATCH 1/6] gitweb.perl : added ability to \"git archive\" just certain paths (files or subdirs, not whole repo) via gitweb interface","fromName":"Jim Klimov","fromEmail":"jim@jimklimov.com","sentAt":"2016-03-11T13:24:44Z","receivedAt":"2016-03-11T13:24:44Z","isPatch":true,"sender":{"key":"jim@jimklimov.com","avatar":null},"body":"---\n gitweb/gitweb.perl | 17 +++++++++++++++++\n 1 file changed, 17 insertions(+)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 05d7910..030d429 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -7328,6 +7328,15 @@ sub git_snapshot {\n \t\tdie_error(403, \"Unsupported snapshot format\");\n \t}\n \n+\tif (!defined($hash)) {\n+\t\t$hash=\"\";\n+\t\tif ( $file_name && $file_name =~ /^([^:]*):(.*)$/ ) {\n+\t\t\t$hash = \"$1\";\n+\t\t\t$file_name = \"$2\";\n+\t\t}\n+\t\tif ( $hash eq \"\") { $hash = \"HEAD\"; }\n+\t\tprintf STDERR \"Defaulted hash to '$hash' ('h=' URL argument was missing)\\n\";\n+\t}\n \tmy $type = git_get_type(\"$hash^{}\");\n \tif (!$type) {\n \t\tdie_error(404, 'Object does not exist');\n@@ -7345,6 +7354,14 @@ sub git_snapshot {\n \t\tgit_cmd(), 'archive',\n \t\t\"--format=$known_snapshot_formats{$format}{'format'}\",\n \t\t\"--prefix=$prefix/\", $hash);\n+\tif ($file_name) {\n+\t\t# To fetch several pathnames use space-separation, e.g.\n+\t\t# \"...git-web?p=proj.git;a=snapshot;f=file1%20file2\n+\t\t# To fetch pathnames with spaces, escape them, e.g.\n+\t\t# \"...git-web?p=proj.git;a=snapshot;f=file\\%20name\n+\t\t$cmd .= \" \" . $file_name;\n+\t}\n+\n \tif (exists $known_snapshot_formats{$format}{'compressor'}) {\n \t\t$cmd .= ' | ' . quote_command(@{$known_snapshot_formats{$format}{'compressor'}});\n \t}\n-- \n2.1.4\n"},{"id":"280612","messageId":"1457702689-9084-2-git-send-email-jim@jimklimov.com","threadId":"41671","inReplyTo":"1457702689-9084-1-git-send-email-jim@jimklimov.com","subject":"[PATCH 2/6] gitweb.perl : added ability to debug requests coming through gitweb interface by adding an option to request URL (also requires server-side envvar \"GITWEB_MAY_DEBUG=yes\")","fromName":"Jim Klimov","fromEmail":"jim@jimklimov.com","sentAt":"2016-03-11T13:24:45Z","receivedAt":"2016-03-11T13:24:45Z","isPatch":true,"sender":{"key":"jim@jimklimov.com","avatar":null},"body":"---\n gitweb/gitweb.perl | 26 +++++++++++++++++++++++---\n 1 file changed, 23 insertions(+), 3 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 030d429..c715472 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -74,6 +74,11 @@ sub evaluate_uri {\n \tour $home_link = $my_uri || \"/\";\n }\n \n+# Request parameters\n+our ($action, $project, $DEBUG, $file_name, $file_parent, $hash, $hash_parent, $hash_base,\n+     $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,\n+     $searchtext, $search_regexp, $project_filter);\n+\n # core git executable to use\n # this can just be \"git\" if your webserver has a sensible PATH\n our $GIT = \"++GIT_BINDIR++/git\";\n@@ -803,6 +808,7 @@ our %input_params = ();\n our @cgi_param_mapping = (\n \tproject => \"p\",\n \taction => \"a\",\n+\tdebug => \"debug\",\n \tfile_name => \"f\",\n \tfile_parent => \"fp\",\n \thash => \"h\",\n@@ -1033,9 +1039,6 @@ sub evaluate_path_info {\n \t}\n }\n \n-our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,\n-     $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,\n-     $searchtext, $search_regexp, $project_filter);\n sub evaluate_and_validate_params {\n \tour $action = $input_params{'action'};\n \tif (defined $action) {\n@@ -1053,6 +1056,23 @@ sub evaluate_and_validate_params {\n \t\t}\n \t}\n \n+\tour $DEBUG = $input_params{'debug'};\n+\tif (defined $DEBUG) {\n+\t\tif ( $DEBUG =~ /^([Yy][Ee][Ss]|[Oo][Nn]|1|[Tt][Rr][Uu][Ee])$/ ) {\n+\t\t\tif ( defined($ENV{'GITWEB_MAY_DEBUG'}) && $ENV{'GITWEB_MAY_DEBUG'} eq \"yes\" ) {\n+\t\t\t\t$DEBUG = 1; #true\n+\t\t\t} else {\n+\t\t\t\tprintf STDERR \"Invalid action parameter: DEBUG=$DEBUG was requested but server-side GITWEB_MAY_DEBUG=yes is not set\\n\";\n+\t\t\t\tdie_error(403, \"Invalid action parameter: DEBUG was requested but server-side GITWEB_MAY_DEBUG=yes is not set\");\n+\t\t\t\t$DEBUG = 0; #false\n+\t\t\t}\n+\t\t} else {\n+\t\t\t$DEBUG = 0; #false\n+\t\t}\n+\t} else {\n+\t\t$DEBUG = 0;\t# false\n+\t}\n+\n \tour $project_filter = $input_params{'project_filter'};\n \tif (defined $project_filter) {\n \t\tif (!is_valid_pathname($project_filter)) {\n-- \n2.1.4\n"},{"id":"280617","messageId":"1457702689-9084-3-git-send-email-jim@jimklimov.com","threadId":"41671","inReplyTo":"1457702689-9084-1-git-send-email-jim@jimklimov.com","subject":"[PATCH 3/6] gitweb.perl : added ability to DEBUG progression through \"git archive\"","fromName":"Jim Klimov","fromEmail":"jim@jimklimov.com","sentAt":"2016-03-11T13:24:46Z","receivedAt":"2016-03-11T13:24:46Z","isPatch":true,"sender":{"key":"jim@jimklimov.com","avatar":null},"body":"---\n gitweb/gitweb.perl | 29 +++++++++++++++++++++++++++++\n 1 file changed, 29 insertions(+)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex c715472..fc5b62d 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -891,6 +891,7 @@ sub evaluate_query_params {\n # now read PATH_INFO and update the parameter list for missing parameters\n sub evaluate_path_info {\n \treturn if defined $input_params{'project'};\n+\tprintf STDERR \"path_info='$path_info'\\n\" if $DEBUG;\n \treturn if !$path_info;\n \t$path_info =~ s,^/+,,;\n \treturn if !$path_info;\n@@ -7336,6 +7337,24 @@ sub git_snapshot {\n \tif (!@snapshot_fmts) {\n \t\tdie_error(403, \"Snapshots not allowed\");\n \t}\n+\n+\tif ($DEBUG) {\n+\t\tmy $v; my $i;\n+\t\tprintf STDERR \"path_info='\".$path_info.\"'\\n\";\n+\t\tprintf STDERR \"input_params: { \";\n+\t\tforeach $i (keys (%input_params)) {\n+\t\t\t$v = $input_params{$i};\n+\t\t\tif (defined ($v)) {\n+\t\t\t\tif ($i eq \"extra_options\" ) {\n+\t\t\t\t\tprintf STDERR \"  '$i' => [\".@{$v}.\"] ; \";\n+\t\t\t\t} else {\n+\t\t\t\tprintf STDERR \"  '$i' => '$v' ; \";\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t\tprintf STDERR \"} \\n\";\n+\t}\n+\n \t# default to first supported snapshot format\n \t$format ||= $snapshot_fmts[0];\n \tif ($format !~ m/^[a-z0-9]+$/) {\n@@ -7367,6 +7386,13 @@ sub git_snapshot {\n \tmy ($name, $prefix) = snapshot_name($project, $hash);\n \tmy $filename = \"$name$known_snapshot_formats{$format}{'suffix'}\";\n \n+\tif ($DEBUG) {\n+\t\t# name of the tarball to generate\n+\t\tif (defined $filename)  { printf STDERR \"filename='$filename'\\n\"; }\n+\t\t# value of the 'f=' URL parameter\n+\t\tif (defined $file_name) { printf STDERR \"file_name='$file_name'\\n\"; }\n+\t}\n+\n \tmy %co = parse_commit($hash);\n \texit_if_unmodified_since($co{'committer_epoch'}) if %co;\n \n@@ -7398,12 +7424,15 @@ sub git_snapshot {\n \t\t%co ? (-last_modified => $latest_date{'rfc2822'}) : (),\n \t\t-status => '200 OK');\n \n+\tprintf STDERR \"Starting git-archive: $cmd\\n\" if $DEBUG;\n \topen my $fd, \"-|\", $cmd\n \t\tor die_error(500, \"Execute git-archive failed\");\n+\tprintf STDERR \"Started git-archive...\\n\" if $DEBUG;\n \tbinmode STDOUT, ':raw';\n \tprint <$fd>;\n \tbinmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi\n \tclose $fd;\n+\tprintf STDERR \"Finished posting output of git-archive...\\n\" if $DEBUG;\n }\n \n sub git_log_generic {\n-- \n2.1.4\n"},{"id":"280615","messageId":"1457702689-9084-4-git-send-email-jim@jimklimov.com","threadId":"41671","inReplyTo":"1457702689-9084-1-git-send-email-jim@jimklimov.com","subject":"[PATCH 4/6] gitweb.perl support for snapshots with lists of specified files is now tested","fromName":"Jim Klimov","fromEmail":"jim@jimklimov.com","sentAt":"2016-03-11T13:24:47Z","receivedAt":"2016-03-11T13:24:47Z","isPatch":true,"sender":{"key":"jim@jimklimov.com","avatar":null},"body":"---\n t/t9502-gitweb-standalone-parse-output.sh | 156 ++++++++++++++++++++++++++++--\n 1 file changed, 148 insertions(+), 8 deletions(-)\n\ndiff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh\nindex 0796a43..11a116f 100755\n--- a/t/t9502-gitweb-standalone-parse-output.sh\n+++ b/t/t9502-gitweb-standalone-parse-output.sh\n@@ -27,25 +27,46 @@ $known_snapshot_formats{'tar'} = {\n $feature{'snapshot'}{'default'} = ['tar'];\n EOF\n \n-# Call check_snapshot with the arguments \"<basename> [<prefix>]\"\n+# Call list_snapshot with the argument \"<basename>\"\n #\n # This will check that gitweb HTTP header contains proposed filename\n-# as <basename> with '.tar' suffix added, and that generated tarfile\n-# (gitweb message body) has <prefix> as prefix for al files in tarfile\n+# as <basename> with '.tar' suffix added, and lists its content to\n+# stdout of this routine (in \"tar test\" default listing format)\n #\n-# <prefix> default to <basename>\n-check_snapshot () {\n-\tbasename=$1\n-\tprefix=${2:-\"$1\"}\n+# <prefix> defaults to <basename>\n+#\n+list_snapshot () {\n+\tbasename=\"`echo \"$1\" | sed 's,\\/,\\.,g'`\"\n \techo \"basename=$basename\"\n \tgrep \"filename=.*$basename.tar\" gitweb.headers >/dev/null 2>&1 &&\n-\t\"$TAR\" tf gitweb.body >file_list &&\n+\t\"$TAR\" tf gitweb.body >file_list\n+}\n+\n+#\n+# Call check_snapshot with the arguments \"<basename> [<prefix>]\"\n+#\n+# This uses list_snapshot() above to list the tarfile <basename>.tar received\n+# from gitweb, and that this generated tarfile (gitweb message body) has\n+# <prefix> prepended as prefix for all objects in the tarfile\n+# The tarfile listing is exchanged via the \"file_list\" temporary file\n+#\n+# <prefix> defaults to <basename>\n+#\n+check_snapshot () {\n+\tbasename=\"$1\"\n+\tprefix=${2:-\"$1\"}\n+\tlist_snapshot \"$basename\" &&\n \t! grep -v -e \"^$prefix$\" -e \"^$prefix/\" -e \"^pax_global_header$\" file_list\n }\n \n+# Note: the \"xx/test\" branch only contains file \"foo\"; others land in \"master\"\n+# Call test_commit with the arguments \"<message> [<file> [<contents> [<tag>]]]\"\n test_expect_success setup '\n \ttest_commit first foo &&\n+\tmkdir -p dir1 && test_commit bar dir1/second bar second &&\n \tgit branch xx/test &&\n+\tmkdir -p dir2 && test_commit pif dir2/third pif third &&\n+\ttest_commit wow dir2/\"fourth file\" wow wow &&\n \tFULL_ID=$(git rev-parse --verify HEAD) &&\n \tSHORT_ID=$(git rev-parse --verify --short=7 HEAD)\n '\n@@ -112,6 +133,125 @@ test_expect_success 'snapshot: hierarchical branch name (xx/test)' '\n '\n test_debug 'cat gitweb.headers'\n \n+test_expect_success 'snapshot sanity: have expected content in xx/test branch - do not have /first file in full snapshot' '\n+\trm -f gitweb.body file_list &&\n+\tBRANCH=xx/test &&\n+\tgitweb_run \"p=.git;a=snapshot;h=$BRANCH;sf=tar\" &&\n+\tID=$(git rev-parse --verify --short=7 \"$BRANCH\") &&\n+\tlist_snapshot \".git-$BRANCH-$ID\" &&\n+\t! grep \"first\" file_list\n+'\n+test_debug 'cat gitweb.headers && cat file_list'\n+\n+test_expect_success 'snapshot certain objects: have expected content in master branch - only those under subdir dir2/ and not others' '\n+\trm -f gitweb.body file_list &&\n+\tBRANCH=master &&\n+\tgitweb_run \"p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2\" &&\n+\tID=$(git rev-parse --verify --short=7 \"$BRANCH\") &&\n+\tlist_snapshot \".git-$BRANCH-$ID\" &&\n+\t! grep \"foo\" file_list &&\n+\t! grep \"dir1/second\" file_list &&\n+\tgrep \"dir2/third\" file_list &&\n+\tgrep \"dir2/fourth file\" file_list\n+'\n+test_debug 'cat gitweb.headers && cat file_list'\n+\n+test_expect_success 'snapshot certain objects: have expected content in master branch - subdir name is required in requested nested path (bad path - empty output)' '\n+\trm -f gitweb.body file_list &&\n+\tBRANCH=master &&\n+\tgitweb_run \"p=.git;a=snapshot;h=$BRANCH;sf=tar;f=third\" &&\n+\t[ ! -s gitweb.body ]\n+'\n+test_debug 'cat gitweb.headers && cat file_list'\n+\n+test_expect_success 'snapshot certain objects: have expected content in master branch - correct subdir name is required in requested nested path (bad path - empty output)' '\n+\trm -f gitweb.body file_list &&\n+\tBRANCH=master &&\n+\tgitweb_run \"p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir1/third\" &&\n+\t[ ! -s gitweb.body ]\n+'\n+test_debug 'cat gitweb.headers && cat file_list'\n+\n+test_expect_success 'snapshot certain objects: have expected content in master branch - can request filenames with spaces (backslash + HTML-escape)' '\n+\trm -f gitweb.body file_list &&\n+\tBRANCH=master &&\n+\tgitweb_run \"p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2/fourth\\%20file\" &&\n+\tID=$(git rev-parse --verify --short=7 \"$BRANCH\") &&\n+\tlist_snapshot \".git-$BRANCH-$ID\" &&\n+\t! grep \"foo\" file_list &&\n+\t! grep \"dir1/second\" file_list &&\n+\t! grep \"dir2/third\" file_list &&\n+\tgrep \"dir2/fourth file\" file_list\n+'\n+test_debug 'cat gitweb.headers && cat file_list'\n+\n+test_expect_success 'snapshot certain objects: have expected content in master branch - can request list of filenames separated by HTML-escaped spaces' '\n+\trm -f gitweb.body file_list &&\n+\tBRANCH=master &&\n+\tgitweb_run \"p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir1/second%20dir2/third\" &&\n+\tID=$(git rev-parse --verify --short=7 \"$BRANCH\") &&\n+\tlist_snapshot \".git-$BRANCH-$ID\" &&\n+\t! grep \"foo\" file_list &&\n+\tgrep \"dir1/second\" file_list &&\n+\tgrep \"dir2/third\" file_list &&\n+\t! grep \"dir2/fourth file\" file_list\n+'\n+test_debug 'cat gitweb.headers && cat file_list'\n+\n+test_expect_success 'snapshot certain objects: have expected content in master branch - can request list of filenames separated by HTML-escaped spaces including a filename with spaces (backslash + HTML-escape)' '\n+\trm -f gitweb.body file_list &&\n+\tBRANCH=master &&\n+\tgitweb_run \"p=.git;a=snapshot;h=$BRANCH;sf=tar;f=foo%20dir2/fourth\\%20file%20dir1/second\" &&\n+\tID=$(git rev-parse --verify --short=7 \"$BRANCH\") &&\n+\tlist_snapshot \".git-$BRANCH-$ID\" &&\n+\tgrep \"foo\" file_list &&\n+\tgrep \"dir1/second\" file_list &&\n+\t! grep \"dir2/third\" file_list &&\n+\tgrep \"dir2/fourth file\" file_list\n+'\n+test_debug 'cat gitweb.headers && cat file_list'\n+\n+test_expect_success 'snapshot certain objects: have only expected content in refs/tags/second full tag' '\n+\trm -f gitweb.body file_list &&\n+\tBRANCH=second &&\n+\tgitweb_run \"p=.git;a=snapshot;h=refs/tags/$BRANCH;sf=tar;f=dir1/second\" &&\n+\tlist_snapshot \".git-$BRANCH\" &&\n+\t! grep \"foo\" file_list &&\n+\tgrep \"dir1/second\" file_list &&\n+\t! grep \"dir2/third\" file_list &&\n+\t! grep \"dir2/fourth file\" file_list\n+'\n+test_debug 'cat gitweb.headers && cat file_list'\n+\n+test_expect_success 'snapshot certain objects: have expected content in xx/test branch - request for only absent subdir dir2/ fails (empty output)' '\n+\trm -f gitweb.body file_list &&\n+\tBRANCH=xx/test &&\n+\tgitweb_run \"p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2\" &&\n+        [ ! -s \"gitweb.body\" ]\n+'\n+test_debug 'cat gitweb.headers'\n+\n+test_expect_success 'snapshot certain objects: have expected content in xx/test branch - request for file /foo and absent subdir dir2/ also fails (empty output)' '\n+\trm -f gitweb.body file_list &&\n+\tBRANCH=xx/test &&\n+\tgitweb_run \"p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2%20foo\" &&\n+        [ ! -s \"gitweb.body\" ]\n+'\n+test_debug 'cat gitweb.headers'\n+\n+test_expect_success 'snapshot certain objects: have expected content in xx/test branch - have /foo file (and only it)' '\n+\trm -f gitweb.body file_list &&\n+\tBRANCH=xx/test &&\n+\tgitweb_run \"p=.git;a=snapshot;h=$BRANCH;sf=tar;f=foo\" &&\n+\tID=$(git rev-parse --verify --short=7 \"$BRANCH\") &&\n+\tlist_snapshot \".git-$BRANCH-$ID\" &&\n+\tgrep \"foo\" file_list &&\n+\t! grep \"dir1/second\" file_list &&\n+\t! grep \"dir2/third\" file_list &&\n+\t! grep \"dir2/fourth file\" file_list\n+'\n+test_debug 'cat gitweb.headers && cat file_list'\n+\n # ----------------------------------------------------------------------\n # forks of projects\n \n-- \n2.1.4\n"},{"id":"280613","messageId":"1457702689-9084-5-git-send-email-jim@jimklimov.com","threadId":"41671","inReplyTo":"1457702689-9084-1-git-send-email-jim@jimklimov.com","subject":"[PATCH 5/6] gitweb.perl changed (and tested) to return HTTP-404 when missing objects are requested via snapshot","fromName":"Jim Klimov","fromEmail":"jim@jimklimov.com","sentAt":"2016-03-11T13:24:48Z","receivedAt":"2016-03-11T13:24:48Z","isPatch":true,"sender":{"key":"jim@jimklimov.com","avatar":null},"body":"---\n gitweb/gitweb.perl                        | 62 +++++++++++++++++++++++++------\n t/t9502-gitweb-standalone-parse-output.sh | 24 ++++++------\n 2 files changed, 63 insertions(+), 23 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex fc5b62d..2369ae3 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -7418,20 +7418,60 @@ sub git_snapshot {\n \t\t%latest_date = parse_date($co{'committer_epoch'}, $co{'committer_tz'});\n \t}\n \n-\tprint $cgi->header(\n-\t\t-type => $known_snapshot_formats{$format}{'type'},\n-\t\t-content_disposition => 'inline; filename=\"' . $filename . '\"',\n-\t\t%co ? (-last_modified => $latest_date{'rfc2822'}) : (),\n-\t\t-status => '200 OK');\n-\n \tprintf STDERR \"Starting git-archive: $cmd\\n\" if $DEBUG;\n-\topen my $fd, \"-|\", $cmd\n-\t\tor die_error(500, \"Execute git-archive failed\");\n+\tmy $fd;\n+\tif ( ! open $fd, \"-|\", $cmd ) {\n+\t\tprint $cgi->header(-status => '500 Execute git-archive failed');\n+\t\tdie_error(500, \"Execute git-archive failed\");\n+\t\treturn;\n+\t}\n \tprintf STDERR \"Started git-archive...\\n\" if $DEBUG;\n-\tbinmode STDOUT, ':raw';\n-\tprint <$fd>;\n-\tbinmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi\n+\tmy $tempByte;\n+\tmy $readSize = read ($fd, $tempByte, 1);\n+\tmy $retCode = 200;\n+\tif ( defined $readSize ) {\n+\t\tif ( $readSize > 0 ) {\n+\t\t\tprint $cgi->header(\n+\t\t\t\t-type => $known_snapshot_formats{$format}{'type'},\n+\t\t\t\t-content_disposition => 'inline; filename=\"' . $filename . '\"',\n+\t\t\t\t%co ? (-last_modified => $latest_date{'rfc2822'}) : (),\n+\t\t\t\t-status => '200 OK' );\n+\t\t\tbinmode STDOUT, ':raw';\n+\t\t\tprint $tempByte;\n+\t\t\tif ( ! print <$fd> ) {\n+\t\t\t\t$retCode = 503;\n+\t\t\t}\n+\t\t\tbinmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi\n+\t\t} else {\n+\t\t\t$retCode = 404;\n+\t\t}\n+\t} else {\n+\t\t$readSize = -1;\n+\t\t$retCode = 500;\n+\t}\n+\n \tclose $fd;\n+\tmy $retError = \"\" ;\n+\tif ( ($? >> 8) != 0 ) {\n+\t\t$retCode = 500;\n+\t\tif ( $readSize == 0 ) {\n+\t\t\t# We had empty but not failed read - re-inspect stderr\n+\t\t\t$retError = `$cmd 2>&1`;\n+\t\t\tif ( $retError =~ /did not match any/ ) {\n+\t\t\t\t$retCode = 404;\n+\t\t\t}\n+\t\t}\n+\t}\n+\tif ( $retError ne \"\" ) {\n+\t\t$retError = \"<br/><pre>$retError</pre><br/>\";\n+\t}\n+\n+\tif ( $retCode == 404 ) {\n+\t\tdie_error(404, \"Not Found - maybe requested objects absent in git path?\" . \"$retError\");\n+\t} elsif ( $retCode == 500 ) {\n+\t\tdie_error(500, \"Failed to transmit output from git-archive\" . \"$retError\");\n+\t}\n+\n \tprintf STDERR \"Finished posting output of git-archive...\\n\" if $DEBUG;\n }\n \ndiff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh\nindex 11a116f..a2ae5c4 100755\n--- a/t/t9502-gitweb-standalone-parse-output.sh\n+++ b/t/t9502-gitweb-standalone-parse-output.sh\n@@ -156,21 +156,21 @@ test_expect_success 'snapshot certain objects: have expected content in master b\n '\n test_debug 'cat gitweb.headers && cat file_list'\n \n-test_expect_success 'snapshot certain objects: have expected content in master branch - subdir name is required in requested nested path (bad path - empty output)' '\n+test_expect_success 'snapshot certain objects: have expected content in master branch - subdir name is required in requested nested path (bad path - empty output and/or HTTP-404)' '\n \trm -f gitweb.body file_list &&\n \tBRANCH=master &&\n \tgitweb_run \"p=.git;a=snapshot;h=$BRANCH;sf=tar;f=third\" &&\n-\t[ ! -s gitweb.body ]\n+\t[ ! -s gitweb.body -o -n \"`head -1 gitweb.headers | egrep \"^Status: 404 \"`\" ]\n '\n-test_debug 'cat gitweb.headers && cat file_list'\n+test_debug 'cat gitweb.headers && ls -la gitweb.body file_list || true'\n \n-test_expect_success 'snapshot certain objects: have expected content in master branch - correct subdir name is required in requested nested path (bad path - empty output)' '\n+test_expect_success 'snapshot certain objects: have expected content in master branch - correct subdir name is required in requested nested path (bad path - empty output and/or HTTP-404)' '\n \trm -f gitweb.body file_list &&\n \tBRANCH=master &&\n \tgitweb_run \"p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir1/third\" &&\n-\t[ ! -s gitweb.body ]\n+\t[ ! -s gitweb.body -o -n \"`head -1 gitweb.headers | egrep \"^Status: 404 \"`\" ]\n '\n-test_debug 'cat gitweb.headers && cat file_list'\n+test_debug 'cat gitweb.headers && ls -la gitweb.body file_list || true'\n \n test_expect_success 'snapshot certain objects: have expected content in master branch - can request filenames with spaces (backslash + HTML-escape)' '\n \trm -f gitweb.body file_list &&\n@@ -223,21 +223,21 @@ test_expect_success 'snapshot certain objects: have only expected content in ref\n '\n test_debug 'cat gitweb.headers && cat file_list'\n \n-test_expect_success 'snapshot certain objects: have expected content in xx/test branch - request for only absent subdir dir2/ fails (empty output)' '\n+test_expect_success 'snapshot certain objects: have expected content in xx/test branch - request for only absent subdir dir2/ fails (empty output and/or HTTP-404)' '\n \trm -f gitweb.body file_list &&\n \tBRANCH=xx/test &&\n \tgitweb_run \"p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2\" &&\n-        [ ! -s \"gitweb.body\" ]\n+\t[ ! -s gitweb.body -o -n \"`head -1 gitweb.headers | egrep \"^Status: 404 \"`\" ]\n '\n-test_debug 'cat gitweb.headers'\n+test_debug 'cat gitweb.headers && ls -la gitweb.body file_list || true'\n \n-test_expect_success 'snapshot certain objects: have expected content in xx/test branch - request for file /foo and absent subdir dir2/ also fails (empty output)' '\n+test_expect_success 'snapshot certain objects: have expected content in xx/test branch - request for file /foo and absent subdir dir2/ also fails (empty output and/or HTTP-404)' '\n \trm -f gitweb.body file_list &&\n \tBRANCH=xx/test &&\n \tgitweb_run \"p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2%20foo\" &&\n-        [ ! -s \"gitweb.body\" ]\n+\t[ ! -s gitweb.body -o -n \"`head -1 gitweb.headers | egrep \"^Status: 404 \"`\" ]\n '\n-test_debug 'cat gitweb.headers'\n+test_debug 'cat gitweb.headers && ls -la gitweb.body file_list || true'\n \n test_expect_success 'snapshot certain objects: have expected content in xx/test branch - have /foo file (and only it)' '\n \trm -f gitweb.body file_list &&\n-- \n2.1.4\n"},{"id":"280614","messageId":"1457702689-9084-6-git-send-email-jim@jimklimov.com","threadId":"41671","inReplyTo":"1457702689-9084-1-git-send-email-jim@jimklimov.com","subject":"[PATCH 6/6] gitweb.perl : the optional DEBUG functionality is now unit-tested","fromName":"Jim Klimov","fromEmail":"jim@jimklimov.com","sentAt":"2016-03-11T13:24:49Z","receivedAt":"2016-03-11T13:24:49Z","isPatch":true,"sender":{"key":"jim@jimklimov.com","avatar":null},"body":"---\n t/t9502-gitweb-standalone-parse-output.sh | 35 +++++++++++++++++++++++++++++++\n 1 file changed, 35 insertions(+)\n\ndiff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh\nindex a2ae5c4..4f1ddbf 100755\n--- a/t/t9502-gitweb-standalone-parse-output.sh\n+++ b/t/t9502-gitweb-standalone-parse-output.sh\n@@ -253,6 +253,41 @@ test_expect_success 'snapshot certain objects: have expected content in xx/test\n test_debug 'cat gitweb.headers && cat file_list'\n \n # ----------------------------------------------------------------------\n+# optional debugging in log, if allowed on server and requested by user\n+\n+test_expect_success 'snapshot: debugging logged as forbidden when not defined in server environment' '\n+\trm -f gitweb.body gitweb.log gitweb.headers gitweb.output &&\n+\tgitweb_run \"p=.git;a=snapshot;h=master;sf=tar;debug=yes\" &&\n+\tgrep \"GITWEB_MAY_DEBUG=yes is not set\" < gitweb.log >/dev/null\n+'\n+test_debug 'cat gitweb.headers gitweb.log'\n+\n+test_expect_success 'snapshot: debugging logged as forbidden when not allowed in server environment' '\n+\trm -f gitweb.body gitweb.log gitweb.headers gitweb.output &&\n+\tGITWEB_MAY_DEBUG=xxx && export GITWEB_MAY_DEBUG &&\n+\tgitweb_run \"p=.git;a=snapshot;h=master;sf=tar;debug=yes\" &&\n+\tgrep \"GITWEB_MAY_DEBUG=yes is not set\" < gitweb.log >/dev/null\n+'\n+test_debug 'cat gitweb.headers gitweb.log'\n+\n+test_expect_success 'snapshot: debugging present when allowed in server environment' '\n+\trm -f gitweb.body gitweb.log gitweb.headers gitweb.output &&\n+\tGITWEB_MAY_DEBUG=yes && export GITWEB_MAY_DEBUG &&\n+\tgitweb_run \"p=.git;a=snapshot;h=master;sf=tar;debug=yes\" &&\n+\t! grep \"GITWEB_MAY_DEBUG=yes is not set\" < gitweb.log >/dev/null &&\n+\tgrep \"git-archive\" < gitweb.log >/dev/null\n+'\n+test_debug 'cat gitweb.headers gitweb.log'\n+\n+test_expect_success 'snapshot: debugging absent when not allowed in server environment' '\n+\trm -f gitweb.body gitweb.log gitweb.headers gitweb.output &&\n+\tGITWEB_MAY_DEBUG=xxx && export GITWEB_MAY_DEBUG &&\n+\tgitweb_run \"p=.git;a=snapshot;h=master;sf=tar;debug=yes\" &&\n+\t! grep \"git-archive\" < gitweb.log >/dev/null\n+'\n+test_debug 'cat gitweb.headers gitweb.log'\n+\n+# ----------------------------------------------------------------------\n # forks of projects\n \n test_expect_success 'forks: setup' '\n-- \n2.1.4\n"}]}