xz: Fix interaction between preset and custom filter chains.

There was somewhat illogical behavior when --extreme was
specified and mixed with custom filter chains.

Before this commit, "xz -9 --lzma2 -e" was equivalent
to "xz --lzma2". After it is equivalent to "xz -6e"
(all earlier preset options get forgotten when a custom
filter chain is specified and the default preset is 6
to which -e is applied). I find this less illogical.

This also affects the meaning of "xz -9e --lzma2 -7".
Earlier it was equivalent to "xz -7e" (the -e specified
before a custom filter chain wasn't forgotten). Now it
is "xz -7". Note that "xz -7e" still is the same as "xz -e7".

Hopefully very few cared about this in the first place,
so pretty much no one should even notice this change.

Thanks to Conley Moorhous.
This commit is contained in:
Lasse Collin 2013-06-21 21:50:26 +03:00
parent b065984e5a
commit 45edf2966f
1 changed files with 21 additions and 14 deletions

View File

@ -40,12 +40,7 @@ static io_buf out_buf;
static uint32_t filters_count = 0;
/// Number of the preset (0-9)
static uint32_t preset_number = 6;
/// If a preset is used (no custom filter chain) and preset_extreme is true,
/// a significantly slower compression is used to achieve slightly better
/// compression ratio.
static bool preset_extreme = false;
static uint32_t preset_number = LZMA_PRESET_DEFAULT;
/// Integrity check type
static lzma_check check;
@ -63,11 +58,9 @@ coder_set_check(lzma_check new_check)
}
extern void
coder_set_preset(uint32_t new_preset)
static void
forget_filter_chain(void)
{
preset_number = new_preset;
// Setting a preset makes us forget a possibly defined custom
// filter chain.
while (filters_count > 0) {
@ -80,10 +73,21 @@ coder_set_preset(uint32_t new_preset)
}
extern void
coder_set_preset(uint32_t new_preset)
{
preset_number &= ~LZMA_PRESET_LEVEL_MASK;
preset_number |= new_preset;
forget_filter_chain();
return;
}
extern void
coder_set_extreme(void)
{
preset_extreme = true;
preset_number |= LZMA_PRESET_EXTREME;
forget_filter_chain();
return;
}
@ -98,6 +102,12 @@ coder_add_filter(lzma_vli id, void *options)
filters[filters_count].options = options;
++filters_count;
// Setting a custom filter chain makes us forget the preset options.
// This makes a difference if one specifies e.g. "xz -9 --lzma2 -e"
// where the custom filter chain resets the preset level back to
// the default 6, making the example equivalent to "xz -6e".
preset_number = LZMA_PRESET_DEFAULT;
return;
}
@ -134,9 +144,6 @@ coder_set_compression_settings(void)
}
// Get the preset for LZMA1 or LZMA2.
if (preset_extreme)
preset_number |= LZMA_PRESET_EXTREME;
if (lzma_lzma_preset(&opt_lzma, preset_number))
message_bug();