From e5bb443cf58cec23503ad0deeeb06a080053da8a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 7 Nov 2020 22:52:20 +0100 Subject: Support compressed output from rred similar to apt-helper cat-file --- apt-private/private-cmndline.cc | 1 + doc/examples/configure-index | 1 + methods/rred.cc | 36 ++++++++++++++++++++++++++++++++++-- test/integration/test-method-rred | 15 +++++++++++++-- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index b6c5ca90a..588dea06b 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -366,6 +366,7 @@ static bool addArgumentsRred(std::vector &Args, char const * { addArg('t', nullptr, "Rred::T", 0); addArg('f', nullptr, "Rred::F", 0); + addArg('C', "compress", "Rred::Compress",CommandLine::HasArg); return true; } /*}}}*/ diff --git a/doc/examples/configure-index b/doc/examples/configure-index index ee031c8b4..0af923811 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -832,6 +832,7 @@ dir::dpkg::triplettable ""; dir::dpkg::cputable ""; Rred::t ""; Rred::f ""; +Rred::Compress ""; APT::Internal::OpProgress::Absolute ""; APT::Color ""; diff --git a/methods/rred.cc b/methods/rred.cc index 0184456bf..2164cd19e 100644 --- a/methods/rred.cc +++ b/methods/rred.cc @@ -756,6 +756,19 @@ class RredMethod : public aptMethod { } }; +static const APT::Configuration::Compressor *FindCompressor(std::vector const &compressors, std::string const &name) /*{{{*/ +{ + APT::Configuration::Compressor const * compressor = nullptr; + for (auto const & c : compressors) + { + if (compressor != nullptr && c.Cost >= compressor->Cost) + continue; + if (c.Name == name || c.Extension == name || (!c.Extension.empty() && c.Extension.substr(1) == name)) + compressor = &c; + } + return compressor; +} + /*}}}*/ static std::vector GetCommands() { return {{nullptr, nullptr, nullptr}}; @@ -773,6 +786,19 @@ int main(int argc, const char *argv[]) auto const argmax = CmdL.FileSize(); bool const quiet = _config->FindI("quiet", 0) >= 2; + std::string const compressorName = _config->Find("Rred::Compress", ""); + auto const compressors = APT::Configuration::getCompressors(); + APT::Configuration::Compressor const * compressor = nullptr; + if (not compressorName.empty()) + { + compressor = FindCompressor(compressors, compressorName); + if (compressor == nullptr) + { + std::cerr << "E: Could not find compressor: " << compressorName << '\n'; + return 101; + } + } + bool just_diff = false; if (_config->FindB("Rred::T", false)) { @@ -784,12 +810,18 @@ int main(int argc, const char *argv[]) if (not quiet) std::clog << "Patching " << CmdL.FileList[0] << " into " << CmdL.FileList[1] << "\n"; input.Open(CmdL.FileList[0], FileFd::ReadOnly,FileFd::Extension); - output.Open(CmdL.FileList[1], FileFd::WriteOnly | FileFd::Create | FileFd::Empty | FileFd::BufferedWrite, FileFd::Extension); + if (compressor == nullptr) + output.Open(CmdL.FileList[1], FileFd::WriteOnly | FileFd::Create | FileFd::Empty | FileFd::BufferedWrite, FileFd::Extension); + else + output.Open(CmdL.FileList[1], FileFd::WriteOnly | FileFd::Create | FileFd::Empty | FileFd::BufferedWrite, *compressor); argi = 2; } else { - output.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly | FileFd::Create | FileFd::BufferedWrite); + if (compressor == nullptr) + output.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly | FileFd::Create | FileFd::BufferedWrite); + else + output.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly | FileFd::Create | FileFd::BufferedWrite, *compressor); if (_config->FindB("Rred::F", false)) input.OpenDescriptor(STDIN_FILENO, FileFd::ReadOnly); else diff --git a/test/integration/test-method-rred b/test/integration/test-method-rred index bef1a35e0..fcadac146 100755 --- a/test/integration/test-method-rred +++ b/test/integration/test-method-rred @@ -198,9 +198,13 @@ failrred 'End before start' '7,6d' # deal correctly with patch merging mergepatches() { - testsuccess runapt "${METHODSDIR}/rred" Packages.ed-* + local CONTENT="$1" + shift + testsuccess runapt "${METHODSDIR}/rred" Packages.ed-* "$@" cp -a rootdir/tmp/testsuccess.output patch.ed - testfileequal 'patch.ed' "$1" + if [ "$#" = '0' ]; then + testfileequal 'patch.ed' "$CONTENT" + fi } createpatch() { echo "$2" @@ -223,7 +227,14 @@ mergepatches '11,19c Package: extra-kittens Version: unavailable . +6d' -C 'gzip' +mv patch.ed patch.ed.gz +mergepatches '11,19c +Package: extra-kittens +Version: unavailable +. 6d' +testfileequal patch.ed "$(apt-helper cat-file patch.ed.gz)" testrred 'Apply' 'merged patch' "$(cat patch.ed)" 'Package: coolstuff Version: 0.8.15 Description: collection of stuff -- cgit v1.2.3-18-g5258