]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
add --patch-apply command 4350/head
authorYann Collet <cyan@fb.com>
Tue, 25 Mar 2025 21:23:14 +0000 (14:23 -0700)
committerYann Collet <cyan@fb.com>
Tue, 25 Mar 2025 21:50:39 +0000 (14:50 -0700)
as an equivalent for `-d --patch-from`.
Requested by @sergeevabc in #2173.

programs/zstdcli.c
tests/playTests.sh

index 4fed04e1347e59237394311460cadabd30236a2d..b9f961c165418b6cf3525cb4348d54b82a1506bf 100644 (file)
@@ -230,7 +230,8 @@ static void usageAdvanced(const char* programName)
 #endif
     DISPLAYOUT("  --adapt                       Dynamically adapt compression level to I/O conditions.\n");
     DISPLAYOUT("  --long[=#]                    Enable long distance matching with window log #. [Default: %u]\n", g_defaultMaxWindowLog);
-    DISPLAYOUT("  --patch-from=REF              Use REF as the reference point for Zstandard's diff engine. \n\n");
+    DISPLAYOUT("  --patch-from=REF              Use REF as the reference point for Zstandard's diff engine. \n");
+    DISPLAYOUT("  --patch-apply                 Equivalent for `-d --patch-from` \n\n");
 # ifdef ZSTD_MULTITHREAD
     DISPLAYOUT("  -T#                           Spawn # compression threads. [Default: 1; pass 0 for core count.]\n");
     DISPLAYOUT("  --single-thread               Share a single thread for I/O and compression (slightly different than `-T1`).\n");
@@ -1124,6 +1125,7 @@ int main(int argCount, const char* argv[])
                 if (longCommandWArg(&argument, "--trace")) { char const* traceFile; NEXT_FIELD(traceFile); TRACE_enable(traceFile); continue; }
 #endif
                 if (longCommandWArg(&argument, "--patch-from")) { NEXT_FIELD(patchFromDictFileName); ultra = 1; continue; }
+                if (longCommandWArg(&argument, "--patch-apply")) { operation=zom_decompress; NEXT_FIELD(patchFromDictFileName); memLimit= 1U << ZSTD_WINDOWLOG_MAX; continue; }
                 if (longCommandWArg(&argument, "--long")) {
                     unsigned ldmWindowLog = 0;
                     ldmFlag = 1;
index 15f6e7761836b81c14f55822922b03dc708baeb6..486b395eb53d18d02ee3aa83510459104aaa2c1b 100755 (executable)
@@ -1777,11 +1777,15 @@ datagen -g1000 -P10 > tmp_patch
 zstd --patch-from=tmp_dict tmp_patch -o tmp_patch_diff
 zstd -d --patch-from=tmp_dict tmp_patch_diff -o tmp_patch_recon
 $DIFF -s tmp_patch_recon tmp_patch
+zstd -f --patch-apply=tmp_dict tmp_patch_diff -o tmp_patch_recon
+$DIFF -s tmp_patch_recon tmp_patch
 
 println "\n===> alternate syntax: patch-from origin"
 zstd -f --patch-from tmp_dict tmp_patch -o tmp_patch_diff
 zstd -df --patch-from tmp_dict tmp_patch_diff -o tmp_patch_recon
 $DIFF -s tmp_patch_recon tmp_patch
+zstd -f --patch-apply tmp_dict tmp_patch_diff -o tmp_patch_recon
+$DIFF -s tmp_patch_recon tmp_patch
 rm -rf tmp_*
 
 println "\n===> patch-from recursive tests"