{"thread":{"id":"21429","subject":"[PATCH 1/2] t/gitweb-lib.sh: Split gitweb output into headers and body","startedAt":"2009-10-29T22:07:40Z","lastAt":"2009-10-30T20:07:06Z","messageCount":4,"participants":["Jakub Narebski","Mark Rada"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"126339","messageId":"1256854062-25496-1-git-send-email-jnareb@gmail.com","threadId":"21429","inReplyTo":null,"subject":"[PATCH 0/2] gitweb: Smarter snapshot names","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-10-29T22:07:40Z","receivedAt":"2009-10-29T22:07:40Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"This series is proposed proposed replacement for a single top commit\nin 'mr/gitweb-snapshot' branch, which was merged into pu.\n\nThose two patches are meant to replace the following commit:\nb411a7a (gitweb: append short hash ids to snapshot files, 2009-09-26)\n\nJakub Narebski (1):\n  t/gitweb-lib.sh: Split gitweb output into headers and body\n\nMark Rada (1):\n  gitweb: Smarter snapshot names\n  (formerly: gitweb: append short hash ids to snapshot files)\n\nTable of contents:\n~~~~~~~~~~~~~~~~~~\n [PATCH 1/2] t/gitweb-lib.sh: Split gitweb output into headers and body\n [RFC/PATCH v6 2/2] gitweb: Smarter snapshot names\n\n gitweb/gitweb.perl                        |   76 +++++++++++++++----\n t/gitweb-lib.sh                           |    6 ++-\n t/t9502-gitweb-standalone-parse-output.sh |  112 +++++++++++++++++++++++++++++\n 3 files changed, 177 insertions(+), 17 deletions(-)\n create mode 100755 t/t9502-gitweb-standalone-parse-output.sh\n\n-- \nJakub Narebski\nPoland\n"},{"id":"126337","messageId":"1256854062-25496-2-git-send-email-jnareb@gmail.com","threadId":"21429","inReplyTo":"1256854062-25496-1-git-send-email-jnareb@gmail.com","subject":"[PATCH 1/2] t/gitweb-lib.sh: Split gitweb output into headers and body","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-10-29T22:07:41Z","receivedAt":"2009-10-29T22:07:41Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Save HTTP headers into gitweb.headers, and the body of message into\ngitweb.body in gitweb_run()\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nI hope that this use of sed is portable enough.\n\nPlease take into account that HTTP headers part contains at least one\nline: HTTP status.\n\n t/gitweb-lib.sh |    6 +++++-\n 1 files changed, 5 insertions(+), 1 deletions(-)\n\ndiff --git a/t/gitweb-lib.sh b/t/gitweb-lib.sh\nindex 8452532..32b841d\n--- a/t/gitweb-lib.sh\n+++ b/t/gitweb-lib.sh\n@@ -52,10 +52,14 @@ gitweb_run () {\n \trm -f gitweb.log &&\n \tperl -- \"$SCRIPT_NAME\" \\\n \t\t>gitweb.output 2>gitweb.log &&\n+\tsed -e   '/^\\r$/q' <gitweb.output >gitweb.headers &&\n+\tsed -e '1,/^\\r$/d' <gitweb.output >gitweb.body    &&\n \tif grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else true; fi\n \n \t# gitweb.log is left for debugging\n-\t# gitweb.output is used to parse http output\n+\t# gitweb.output is used to parse HTTP output\n+\t# gitweb.headers contains only HTTP headers\n+\t# gitweb.body contains body of message, without headers\n }\n \n . ./test-lib.sh\n-- \n1.6.5\n"},{"id":"126338","messageId":"1256854062-25496-3-git-send-email-jnareb@gmail.com","threadId":"21429","inReplyTo":"1256854062-25496-2-git-send-email-jnareb@gmail.com","subject":"[RFC/PATCH v6 2/2] gitweb: Smarter snapshot names","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-10-29T22:07:42Z","receivedAt":"2009-10-29T22:07:42Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"From: Mark Rada <marada@uwaterloo.ca>\n\nTeach gitweb how to produce nicer snapshot names by only using the\nshort hash id.  If clients make requests using a tree-ish that is not\na partial or full SHA-1 hash, then the short hash will also be appended\nto whatever they asked for.  If clients request snapshot of a tag\n(which means that $hash ('h') parameter has 'refs/tags/' prefix),\nuse only tag name.\n\nThis also includes tests cases for t9502-gitweb-standalone-parse-output.\n\nSigned-off-by: Mark Rada <marada@uwaterloo.ca>\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nThis is currently an RFC because commit message does not describe\nchanges completely.  Among others it doesn't describe current rules.\nAlso tests could be better described.\n\nChanges since v5 (by Mark Rada):\n- put common parts of git_get_full_hash and git_get_short_hash \n  into git_get_hash, do not do double verification\n- separate finding snapshot name and prefix in snapshot_name()\n  subroutine, more smarts for snapshot name\n- improved tests (use 'tar' snapshot format, testing new smarts,\n  testing prefix)\n\n gitweb/gitweb.perl                        |   76 +++++++++++++++----\n t/t9502-gitweb-standalone-parse-output.sh |  112 +++++++++++++++++++++++++++++\n 2 files changed, 172 insertions(+), 16 deletions(-)\n create mode 100755 t/t9502-gitweb-standalone-parse-output.sh\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 8d4a2ae..d8dfd95 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -1983,16 +1983,27 @@ sub quote_command {\n \n # get HEAD ref of given project as hash\n sub git_get_head_hash {\n-\tmy $project = shift;\n+\treturn git_get_full_hash(shift, 'HEAD');\n+}\n+\n+sub git_get_full_hash {\n+\treturn git_get_hash(@_);\n+}\n+\n+sub git_get_short_hash {\n+\treturn git_get_hash(@_, '--short=7');\n+}\n+\n+sub git_get_hash {\n+\tmy ($project, $hash, @options) = @_;\n \tmy $o_git_dir = $git_dir;\n \tmy $retval = undef;\n \t$git_dir = \"$projectroot/$project\";\n-\tif (open my $fd, \"-|\", git_cmd(), \"rev-parse\", \"--verify\", \"HEAD\") {\n-\t\tmy $head = <$fd>;\n+\tif (open my $fd, '-|', git_cmd(), 'rev-parse',\n+\t    '--verify', '-q', @options, $hash) {\n+\t\t$retval = <$fd>;\n+\t\tchomp $retval if defined $retval;\n \t\tclose $fd;\n-\t\tif (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {\n-\t\t\t$retval = $1;\n-\t\t}\n \t}\n \tif (defined $o_git_dir) {\n \t\t$git_dir = $o_git_dir;\n@@ -5179,6 +5190,43 @@ sub git_tree {\n \tgit_footer_html();\n }\n \n+sub snapshot_name {\n+\tmy ($project, $hash) = @_;\n+\n+\t# path/to/project.git  -> project\n+\t# path/to/project/.git -> project\n+\tmy $name = to_utf8($project);\n+\t$name =~ s,([^/])/*\\.git$,$1,;\n+\t$name = basename($name);\n+\t# sanitize name\n+\t$name =~ s/[[:cntrl:]]/?/g;\n+\n+\tmy $ver = $hash;\n+\tif ($hash =~ /^[0-9a-fA-F]+$/) {\n+\t\t# shorten SHA-1 hash\n+\t\tmy $full_hash = git_get_full_hash($project, $hash);\n+\t\tif ($full_hash =~ /^$hash/ && length($hash) > 7) {\n+\t\t\t$ver = git_get_short_hash($project, $hash);\n+\t\t}\n+\t} elsif ($hash =~ m!^refs/tags/(.*)$!) {\n+\t\t# tags don't need shortened SHA-1 hash\n+\t\t$ver = $1;\n+\t} else {\n+\t\t# branches and other need shortened SHA-1 hash\n+\t\tif ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {\n+\t\t\t$ver = $1;\n+\t\t}\n+\t\t$ver .= '-' . git_get_short_hash($project, $hash);\n+\t}\n+\t# in case of hierarchical branch names\n+\t$ver =~ s!/!.!g;\n+\n+\t# name = project-version_string\n+\t$name = \"$name-$ver\";\n+\n+\treturn wantarray ? ($name, $name) : $name;\n+}\n+\n sub git_snapshot {\n \tmy $format = $input_params{'snapshot_format'};\n \tif (!@snapshot_fmts) {\n@@ -5203,24 +5251,20 @@ sub git_snapshot {\n \t\tdie_error(400, 'Object is not a tree-ish');\n \t}\n \n-\tmy $name = $project;\n-\t$name =~ s,([^/])/*\\.git$,$1,;\n-\t$name = basename($name);\n-\tmy $filename = to_utf8($name);\n-\t$name =~ s/\\047/\\047\\\\\\047\\047/g;\n-\tmy $cmd;\n-\t$filename .= \"-$hash$known_snapshot_formats{$format}{'suffix'}\";\n-\t$cmd = quote_command(\n+\tmy ($name, $prefix) = snapshot_name($project, $hash);\n+\tmy $filename = \"$name$known_snapshot_formats{$format}{'suffix'}\";\n+\tmy $cmd = quote_command(\n \t\tgit_cmd(), 'archive',\n \t\t\"--format=$known_snapshot_formats{$format}{'format'}\",\n-\t\t\"--prefix=$name/\", $hash);\n+\t\t\"--prefix=$prefix/\", $hash);\n \tif (exists $known_snapshot_formats{$format}{'compressor'}) {\n \t\t$cmd .= ' | ' . quote_command(@{$known_snapshot_formats{$format}{'compressor'}});\n \t}\n \n+\t$filename =~ s/([\"\\\\])/\\\\$1/g;\n \tprint $cgi->header(\n \t\t-type => $known_snapshot_formats{$format}{'type'},\n-\t\t-content_disposition => 'inline; filename=\"' . \"$filename\" . '\"',\n+\t\t-content_disposition => 'inline; filename=\"' . $filename . '\"',\n \t\t-status => '200 OK');\n \n \topen my $fd, \"-|\", $cmd\ndiff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh\nnew file mode 100755\nindex 0000000..fbf4e26\n--- /dev/null\n+++ b/t/t9502-gitweb-standalone-parse-output.sh\n@@ -0,0 +1,112 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2009 Mark Rada\n+#\n+\n+test_description='gitweb as standalone script (parsing script output).\n+\n+This test runs gitweb (git web interface) as a CGI script from the\n+commandline, and checks that it produces the correct output, either\n+in the HTTP header or the actual script output.'\n+\n+\n+. ./gitweb-lib.sh\n+\n+# ----------------------------------------------------------------------\n+# snapshot file name\n+\n+cat >>gitweb_config.perl <<\\EOF\n+\n+$known_snapshot_formats{'tar'} = {\n+\t'display' => 'tar',\n+\t'type' => 'application/x-tar',\n+\t'suffix' => '.tar',\n+\t'format' => 'tar',\n+};\n+\n+$feature{'snapshot'}{'default'} = ['tar'];\n+EOF\n+\n+test_expect_success setup '\n+\ttest_commit first foo &&\n+\tgit branch xx/test &&\n+\tFULL_ID=$(git rev-parse --verify HEAD) &&\n+\tSHORT_ID=$(git rev-parse --verify --short=7 HEAD)\n+'\n+test_debug '\n+\techo \"FULL_ID  = $FULL_ID\"\n+\techo \"SHORT_ID = $SHORT_ID\"\n+'\n+\n+test_expect_success 'snapshots: give full hash' '\n+\tgitweb_run \"p=.git;a=snapshot;h=$FULL_ID;sf=tar\" &&\n+\tgrep \".git-$SHORT_ID.tar\" gitweb.headers\n+'\n+test_debug 'cat gitweb.headers'\n+test_debug 'cat gitweb.log'\n+\n+test_expect_success 'snapshots: give short hash' '\n+\tgitweb_run \"p=.git;a=snapshot;h=$SHORT_ID;sf=tar\" &&\n+\tgrep \".git-$SHORT_ID.tar\" gitweb.headers\n+'\n+test_debug 'cat gitweb.headers'\n+\n+test_expect_success 'snapshots: give almost full hash' '\n+\tID=$(git rev-parse --short=30 HEAD) &&\n+\tgitweb_run \"p=.git;a=snapshot;h=$ID;sf=tar\" &&\n+\tgrep \".git-$SHORT_ID.tar\" gitweb.headers\n+'\n+test_debug 'cat gitweb.headers'\n+\n+test_expect_success 'snapshots: give HEAD' '\n+\tgitweb_run \"p=.git;a=snapshot;h=HEAD;sf=tar\" &&\n+\tgrep \".git-HEAD-$SHORT_ID.tar\" gitweb.headers\n+'\n+test_debug 'cat gitweb.headers'\n+\n+test_expect_success 'snapshots: give short branch name' '\n+\tgitweb_run \"p=.git;a=snapshot;h=master;sf=tar\" &&\n+\tID=$(git rev-parse --verify --short=7 master) &&\n+\tgrep \".git-master-$ID.tar\" gitweb.headers\n+'\n+test_debug 'cat gitweb.headers'\n+\n+test_expect_success 'snapshots: give short tag name' '\n+\tgitweb_run \"p=.git;a=snapshot;h=first;sf=tar\" &&\n+\tID=$(git rev-parse --verify --short=7 first) &&\n+\tgrep \".git-first-$ID.tar\" gitweb.headers\n+'\n+test_debug 'cat gitweb.headers'\n+\n+test_expect_success 'snapshots: give full branch name' '\n+\tgitweb_run \"p=.git;a=snapshot;h=refs/heads/master;sf=tar\" &&\n+\tID=$(git rev-parse --verify --short=7 master) &&\n+\tgrep \".git-master-$ID.tar\" gitweb.headers\n+'\n+test_debug 'cat gitweb.headers'\n+\n+test_expect_success 'snapshots: give full tag name' '\n+\tgitweb_run \"p=.git;a=snapshot;h=refs/tags/first;sf=tar\" &&\n+\tgrep \".git-first.tar\" gitweb.headers\n+'\n+test_debug 'cat gitweb.headers'\n+\n+test_expect_success 'snapshots: give hierarchical branch name' '\n+\tgitweb_run \"p=.git;a=snapshot;h=xx/test;sf=tar\" &&\n+\tgrep -v \"filename=.*/\" gitweb.headers\n+'\n+test_debug 'cat gitweb.headers'\n+\n+cat >expected <<EOF\n+.git-HEAD-$SHORT_ID/\n+.git-HEAD-$SHORT_ID/foo\n+EOF\n+test_expect_success 'snapshots: check prefix' '\n+\tgitweb_run \"p=.git;a=snapshot;h=HEAD;sf=tar\" &&\n+\tgrep \".git-HEAD-$SHORT_ID.tar\" gitweb.headers &&\n+\t\"$TAR\" tf gitweb.body >actual &&\n+\ttest_cmp expected actual\n+'\n+test_debug 'cat gitweb.headers'\n+\n+test_done\n-- \n1.6.5\n"},{"id":"126424","messageId":"4AEB476A.7030306@mailservices.uwaterloo.ca","threadId":"21429","inReplyTo":"1256854062-25496-3-git-send-email-jnareb@gmail.com","subject":"Re: [RFC/PATCH v6 2/2] gitweb: Smarter snapshot names","fromName":"Mark Rada","fromEmail":"marada@uwaterloo.ca","sentAt":"2009-10-30T20:07:06Z","receivedAt":"2009-10-30T20:07:06Z","isPatch":true,"sender":{"key":"marada@uwaterloo.ca","avatar":"https://avatars.githubusercontent.com/u/38430?v=4"},"body":"Hmm, I guess I was taking too long? Fair enough.\n\nI've had more to do this academic term than I thought.\nThank you for getting this done.\n\n\n--\nMark Rada (ferrous26)\nmarada@uwaterloo.ca\n\n\nOn 09-10-29 6:07 PM, Jakub Narebski wrote:\n> From: Mark Rada <marada@uwaterloo.ca>\n> \n> Teach gitweb how to produce nicer snapshot names by only using the\n> short hash id.  If clients make requests using a tree-ish that is not\n> a partial or full SHA-1 hash, then the short hash will also be appended\n> to whatever they asked for.  If clients request snapshot of a tag\n> (which means that $hash ('h') parameter has 'refs/tags/' prefix),\n> use only tag name.\n> \n> This also includes tests cases for t9502-gitweb-standalone-parse-output.\n> \n> Signed-off-by: Mark Rada <marada@uwaterloo.ca>\n> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n> Signed-off-by: Jakub Narebski <jnareb@gmail.com>\n> ---\n> This is currently an RFC because commit message does not describe\n> changes completely.  Among others it doesn't describe current rules.\n> Also tests could be better described.\n> \n> Changes since v5 (by Mark Rada):\n> - put common parts of git_get_full_hash and git_get_short_hash \n>   into git_get_hash, do not do double verification\n> - separate finding snapshot name and prefix in snapshot_name()\n>   subroutine, more smarts for snapshot name\n> - improved tests (use 'tar' snapshot format, testing new smarts,\n>   testing prefix)\n> \n>  gitweb/gitweb.perl                        |   76 +++++++++++++++----\n>  t/t9502-gitweb-standalone-parse-output.sh |  112 +++++++++++++++++++++++++++++\n>  2 files changed, 172 insertions(+), 16 deletions(-)\n>  create mode 100755 t/t9502-gitweb-standalone-parse-output.sh\n> \n> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n> index 8d4a2ae..d8dfd95 100755\n> --- a/gitweb/gitweb.perl\n> +++ b/gitweb/gitweb.perl\n> @@ -1983,16 +1983,27 @@ sub quote_command {\n>  \n>  # get HEAD ref of given project as hash\n>  sub git_get_head_hash {\n> -\tmy $project = shift;\n> +\treturn git_get_full_hash(shift, 'HEAD');\n> +}\n> +\n> +sub git_get_full_hash {\n> +\treturn git_get_hash(@_);\n> +}\n> +\n> +sub git_get_short_hash {\n> +\treturn git_get_hash(@_, '--short=7');\n> +}\n> +\n> +sub git_get_hash {\n> +\tmy ($project, $hash, @options) = @_;\n>  \tmy $o_git_dir = $git_dir;\n>  \tmy $retval = undef;\n>  \t$git_dir = \"$projectroot/$project\";\n> -\tif (open my $fd, \"-|\", git_cmd(), \"rev-parse\", \"--verify\", \"HEAD\") {\n> -\t\tmy $head = <$fd>;\n> +\tif (open my $fd, '-|', git_cmd(), 'rev-parse',\n> +\t    '--verify', '-q', @options, $hash) {\n> +\t\t$retval = <$fd>;\n> +\t\tchomp $retval if defined $retval;\n>  \t\tclose $fd;\n> -\t\tif (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {\n> -\t\t\t$retval = $1;\n> -\t\t}\n>  \t}\n>  \tif (defined $o_git_dir) {\n>  \t\t$git_dir = $o_git_dir;\n> @@ -5179,6 +5190,43 @@ sub git_tree {\n>  \tgit_footer_html();\n>  }\n>  \n> +sub snapshot_name {\n> +\tmy ($project, $hash) = @_;\n> +\n> +\t# path/to/project.git  -> project\n> +\t# path/to/project/.git -> project\n> +\tmy $name = to_utf8($project);\n> +\t$name =~ s,([^/])/*\\.git$,$1,;\n> +\t$name = basename($name);\n> +\t# sanitize name\n> +\t$name =~ s/[[:cntrl:]]/?/g;\n> +\n> +\tmy $ver = $hash;\n> +\tif ($hash =~ /^[0-9a-fA-F]+$/) {\n> +\t\t# shorten SHA-1 hash\n> +\t\tmy $full_hash = git_get_full_hash($project, $hash);\n> +\t\tif ($full_hash =~ /^$hash/ && length($hash) > 7) {\n> +\t\t\t$ver = git_get_short_hash($project, $hash);\n> +\t\t}\n> +\t} elsif ($hash =~ m!^refs/tags/(.*)$!) {\n> +\t\t# tags don't need shortened SHA-1 hash\n> +\t\t$ver = $1;\n> +\t} else {\n> +\t\t# branches and other need shortened SHA-1 hash\n> +\t\tif ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {\n> +\t\t\t$ver = $1;\n> +\t\t}\n> +\t\t$ver .= '-' . git_get_short_hash($project, $hash);\n> +\t}\n> +\t# in case of hierarchical branch names\n> +\t$ver =~ s!/!.!g;\n> +\n> +\t# name = project-version_string\n> +\t$name = \"$name-$ver\";\n> +\n> +\treturn wantarray ? ($name, $name) : $name;\n> +}\n> +\n>  sub git_snapshot {\n>  \tmy $format = $input_params{'snapshot_format'};\n>  \tif (!@snapshot_fmts) {\n> @@ -5203,24 +5251,20 @@ sub git_snapshot {\n>  \t\tdie_error(400, 'Object is not a tree-ish');\n>  \t}\n>  \n> -\tmy $name = $project;\n> -\t$name =~ s,([^/])/*\\.git$,$1,;\n> -\t$name = basename($name);\n> -\tmy $filename = to_utf8($name);\n> -\t$name =~ s/\\047/\\047\\\\\\047\\047/g;\n> -\tmy $cmd;\n> -\t$filename .= \"-$hash$known_snapshot_formats{$format}{'suffix'}\";\n> -\t$cmd = quote_command(\n> +\tmy ($name, $prefix) = snapshot_name($project, $hash);\n> +\tmy $filename = \"$name$known_snapshot_formats{$format}{'suffix'}\";\n> +\tmy $cmd = quote_command(\n>  \t\tgit_cmd(), 'archive',\n>  \t\t\"--format=$known_snapshot_formats{$format}{'format'}\",\n> -\t\t\"--prefix=$name/\", $hash);\n> +\t\t\"--prefix=$prefix/\", $hash);\n>  \tif (exists $known_snapshot_formats{$format}{'compressor'}) {\n>  \t\t$cmd .= ' | ' . quote_command(@{$known_snapshot_formats{$format}{'compressor'}});\n>  \t}\n>  \n> +\t$filename =~ s/([\"\\\\])/\\\\$1/g;\n>  \tprint $cgi->header(\n>  \t\t-type => $known_snapshot_formats{$format}{'type'},\n> -\t\t-content_disposition => 'inline; filename=\"' . \"$filename\" . '\"',\n> +\t\t-content_disposition => 'inline; filename=\"' . $filename . '\"',\n>  \t\t-status => '200 OK');\n>  \n>  \topen my $fd, \"-|\", $cmd\n> diff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh\n> new file mode 100755\n> index 0000000..fbf4e26\n> --- /dev/null\n> +++ b/t/t9502-gitweb-standalone-parse-output.sh\n> @@ -0,0 +1,112 @@\n> +#!/bin/sh\n> +#\n> +# Copyright (c) 2009 Mark Rada\n> +#\n> +\n> +test_description='gitweb as standalone script (parsing script output).\n> +\n> +This test runs gitweb (git web interface) as a CGI script from the\n> +commandline, and checks that it produces the correct output, either\n> +in the HTTP header or the actual script output.'\n> +\n> +\n> +. ./gitweb-lib.sh\n> +\n> +# ----------------------------------------------------------------------\n> +# snapshot file name\n> +\n> +cat >>gitweb_config.perl <<\\EOF\n> +\n> +$known_snapshot_formats{'tar'} = {\n> +\t'display' => 'tar',\n> +\t'type' => 'application/x-tar',\n> +\t'suffix' => '.tar',\n> +\t'format' => 'tar',\n> +};\n> +\n> +$feature{'snapshot'}{'default'} = ['tar'];\n> +EOF\n> +\n> +test_expect_success setup '\n> +\ttest_commit first foo &&\n> +\tgit branch xx/test &&\n> +\tFULL_ID=$(git rev-parse --verify HEAD) &&\n> +\tSHORT_ID=$(git rev-parse --verify --short=7 HEAD)\n> +'\n> +test_debug '\n> +\techo \"FULL_ID  = $FULL_ID\"\n> +\techo \"SHORT_ID = $SHORT_ID\"\n> +'\n> +\n> +test_expect_success 'snapshots: give full hash' '\n> +\tgitweb_run \"p=.git;a=snapshot;h=$FULL_ID;sf=tar\" &&\n> +\tgrep \".git-$SHORT_ID.tar\" gitweb.headers\n> +'\n> +test_debug 'cat gitweb.headers'\n> +test_debug 'cat gitweb.log'\n> +\n> +test_expect_success 'snapshots: give short hash' '\n> +\tgitweb_run \"p=.git;a=snapshot;h=$SHORT_ID;sf=tar\" &&\n> +\tgrep \".git-$SHORT_ID.tar\" gitweb.headers\n> +'\n> +test_debug 'cat gitweb.headers'\n> +\n> +test_expect_success 'snapshots: give almost full hash' '\n> +\tID=$(git rev-parse --short=30 HEAD) &&\n> +\tgitweb_run \"p=.git;a=snapshot;h=$ID;sf=tar\" &&\n> +\tgrep \".git-$SHORT_ID.tar\" gitweb.headers\n> +'\n> +test_debug 'cat gitweb.headers'\n> +\n> +test_expect_success 'snapshots: give HEAD' '\n> +\tgitweb_run \"p=.git;a=snapshot;h=HEAD;sf=tar\" &&\n> +\tgrep \".git-HEAD-$SHORT_ID.tar\" gitweb.headers\n> +'\n> +test_debug 'cat gitweb.headers'\n> +\n> +test_expect_success 'snapshots: give short branch name' '\n> +\tgitweb_run \"p=.git;a=snapshot;h=master;sf=tar\" &&\n> +\tID=$(git rev-parse --verify --short=7 master) &&\n> +\tgrep \".git-master-$ID.tar\" gitweb.headers\n> +'\n> +test_debug 'cat gitweb.headers'\n> +\n> +test_expect_success 'snapshots: give short tag name' '\n> +\tgitweb_run \"p=.git;a=snapshot;h=first;sf=tar\" &&\n> +\tID=$(git rev-parse --verify --short=7 first) &&\n> +\tgrep \".git-first-$ID.tar\" gitweb.headers\n> +'\n> +test_debug 'cat gitweb.headers'\n> +\n> +test_expect_success 'snapshots: give full branch name' '\n> +\tgitweb_run \"p=.git;a=snapshot;h=refs/heads/master;sf=tar\" &&\n> +\tID=$(git rev-parse --verify --short=7 master) &&\n> +\tgrep \".git-master-$ID.tar\" gitweb.headers\n> +'\n> +test_debug 'cat gitweb.headers'\n> +\n> +test_expect_success 'snapshots: give full tag name' '\n> +\tgitweb_run \"p=.git;a=snapshot;h=refs/tags/first;sf=tar\" &&\n> +\tgrep \".git-first.tar\" gitweb.headers\n> +'\n> +test_debug 'cat gitweb.headers'\n> +\n> +test_expect_success 'snapshots: give hierarchical branch name' '\n> +\tgitweb_run \"p=.git;a=snapshot;h=xx/test;sf=tar\" &&\n> +\tgrep -v \"filename=.*/\" gitweb.headers\n> +'\n> +test_debug 'cat gitweb.headers'\n> +\n> +cat >expected <<EOF\n> +.git-HEAD-$SHORT_ID/\n> +.git-HEAD-$SHORT_ID/foo\n> +EOF\n> +test_expect_success 'snapshots: check prefix' '\n> +\tgitweb_run \"p=.git;a=snapshot;h=HEAD;sf=tar\" &&\n> +\tgrep \".git-HEAD-$SHORT_ID.tar\" gitweb.headers &&\n> +\t\"$TAR\" tf gitweb.body >actual &&\n> +\ttest_cmp expected actual\n> +'\n> +test_debug 'cat gitweb.headers'\n> +\n> +test_done\n"}]}