diff options
-rw-r--r-- | cgitrc.5.txt | 9 | ||||
-rwxr-xr-x | tests/setup.sh | 2 | ||||
-rwxr-xr-x | tests/t0107-snapshot.sh | 42 | ||||
-rw-r--r-- | ui-snapshot.c | 7 |
4 files changed, 56 insertions, 4 deletions
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 4ad3e64..33a6a8c 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -407,9 +407,12 @@ side-by-side-diffs:: | |||
407 | snapshots:: | 407 | snapshots:: |
408 | Text which specifies the default set of snapshot formats that cgit | 408 | Text which specifies the default set of snapshot formats that cgit |
409 | generates links for. The value is a space-separated list of zero or | 409 | generates links for. The value is a space-separated list of zero or |
410 | more of the values "tar", "tar.gz", "tar.bz2", "tar.xz", "tar.lz" and | 410 | more of the values "tar", "tar.gz", "tar.bz2", "tar.lz", "tar.xz", |
411 | "zip". The special value "all" enables all snapshot formats. | 411 | "tar.zst" and "zip". The special value "all" enables all snapshot |
412 | Default value: none. | 412 | formats. Default value: none. |
413 | All compressors use default settings. Some settings can be influenced | ||
414 | with environment variables, for example set ZSTD_CLEVEL=10 in web | ||
415 | server environment for higher (but slower) zstd compression. | ||
413 | 416 | ||
414 | source-filter:: | 417 | source-filter:: |
415 | Specifies a command which will be invoked to format plaintext blobs | 418 | Specifies a command which will be invoked to format plaintext blobs |
diff --git a/tests/setup.sh b/tests/setup.sh index 334cca6..5879348 100755 --- a/tests/setup.sh +++ b/tests/setup.sh | |||
@@ -104,7 +104,7 @@ virtual-root=/ | |||
104 | cache-root=$PWD/cache | 104 | cache-root=$PWD/cache |
105 | 105 | ||
106 | cache-size=1021 | 106 | cache-size=1021 |
107 | snapshots=tar.gz tar.bz tar.lz tar.xz zip | 107 | snapshots=tar.gz tar.bz tar.lz tar.xz tar.zst zip |
108 | enable-log-filecount=1 | 108 | enable-log-filecount=1 |
109 | enable-log-linecount=1 | 109 | enable-log-linecount=1 |
110 | summary-log=5 | 110 | summary-log=5 |
diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh index 84995d1..c164d3e 100755 --- a/tests/t0107-snapshot.sh +++ b/tests/t0107-snapshot.sh | |||
@@ -122,6 +122,48 @@ test_expect_success XZ 'verify untarred file-5' ' | |||
122 | test_line_count = 1 master/file-5 | 122 | test_line_count = 1 master/file-5 |
123 | ' | 123 | ' |
124 | 124 | ||
125 | if test -n "$(which zstd 2>/dev/null)"; then | ||
126 | test_set_prereq ZSTD | ||
127 | else | ||
128 | say 'Skipping ZSTD validation tests: zstd not found' | ||
129 | fi | ||
130 | |||
131 | test_expect_success ZSTD 'get foo/snapshot/master.tar.zst' ' | ||
132 | cgit_url "foo/snapshot/master.tar.zst" >tmp | ||
133 | ' | ||
134 | |||
135 | test_expect_success ZSTD 'check html headers' ' | ||
136 | head -n 1 tmp | | ||
137 | grep "Content-Type: application/x-zstd" && | ||
138 | |||
139 | head -n 2 tmp | | ||
140 | grep "Content-Disposition: inline; filename=.master.tar.zst." | ||
141 | ' | ||
142 | |||
143 | test_expect_success ZSTD 'strip off the header lines' ' | ||
144 | strip_headers <tmp >master.tar.zst | ||
145 | ' | ||
146 | |||
147 | test_expect_success ZSTD 'verify zstd format' ' | ||
148 | zstd --test master.tar.zst && | ||
149 | cp master.tar.zst /tmp/. | ||
150 | ' | ||
151 | |||
152 | test_expect_success ZSTD 'untar' ' | ||
153 | rm -rf master && | ||
154 | tar --zstd -xf master.tar.zst | ||
155 | ' | ||
156 | |||
157 | test_expect_success ZSTD 'count files' ' | ||
158 | ls master/ >output && | ||
159 | test_line_count = 5 output | ||
160 | ' | ||
161 | |||
162 | test_expect_success ZSTD 'verify untarred file-5' ' | ||
163 | grep "^5$" master/file-5 && | ||
164 | test_line_count = 1 master/file-5 | ||
165 | ' | ||
166 | |||
125 | test_expect_success 'get foo/snapshot/master.zip' ' | 167 | test_expect_success 'get foo/snapshot/master.zip' ' |
126 | cgit_url "foo/snapshot/master.zip" >tmp | 168 | cgit_url "foo/snapshot/master.zip" >tmp |
127 | ' | 169 | ' |
diff --git a/ui-snapshot.c b/ui-snapshot.c index 92cde42..556d3ed 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -91,6 +91,12 @@ static int write_tar_xz_archive(const char *hex, const char *prefix) | |||
91 | return write_compressed_tar_archive(hex, prefix, argv); | 91 | return write_compressed_tar_archive(hex, prefix, argv); |
92 | } | 92 | } |
93 | 93 | ||
94 | static int write_tar_zstd_archive(const char *hex, const char *prefix) | ||
95 | { | ||
96 | char *argv[] = { "zstd", "-T0", NULL }; | ||
97 | return write_compressed_tar_archive(hex, prefix, argv); | ||
98 | } | ||
99 | |||
94 | const struct cgit_snapshot_format cgit_snapshot_formats[] = { | 100 | const struct cgit_snapshot_format cgit_snapshot_formats[] = { |
95 | /* .tar must remain the 0 index */ | 101 | /* .tar must remain the 0 index */ |
96 | { ".tar", "application/x-tar", write_tar_archive }, | 102 | { ".tar", "application/x-tar", write_tar_archive }, |
@@ -98,6 +104,7 @@ const struct cgit_snapshot_format cgit_snapshot_formats[] = { | |||
98 | { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive }, | 104 | { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive }, |
99 | { ".tar.lz", "application/x-lzip", write_tar_lzip_archive }, | 105 | { ".tar.lz", "application/x-lzip", write_tar_lzip_archive }, |
100 | { ".tar.xz", "application/x-xz", write_tar_xz_archive }, | 106 | { ".tar.xz", "application/x-xz", write_tar_xz_archive }, |
107 | { ".tar.zst", "application/x-zstd", write_tar_zstd_archive }, | ||
101 | { ".zip", "application/x-zip", write_zip_archive }, | 108 | { ".zip", "application/x-zip", write_zip_archive }, |
102 | { NULL } | 109 | { NULL } |
103 | }; | 110 | }; |