From 9e1398b164f55238990907f63dfdef60588d9b24 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 7 Nov 2020 21:23:57 +0100 Subject: Prepare rred binary for external usage Merging patches is a bit of non-trivial code we have for client-side work, but as we support also server-side merging we can export this functionality so that server software can reuse it. Note that this just cleans up and makes rred behave a bit more like all our other binaries by supporting setting configuration at runtime and supporting --help and --version. If you can make due without this, the now advertised functionality is provided already in earlier versions. --- test/integration/test-00-commands-have-help | 6 ++++- test/integration/test-method-rred | 37 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/integration/test-00-commands-have-help b/test/integration/test-00-commands-have-help index 4a0cc64d4..f91238d5d 100755 --- a/test/integration/test-00-commands-have-help +++ b/test/integration/test-00-commands-have-help @@ -49,7 +49,11 @@ for CMD in 'apt-cache' 'apt-cdrom' 'apt-config' \ checkoptions "$cmd" done -for CMD in 'apt-dump-solver' 'apt-internal-solver' 'apt-internal-planner'; do + +rred() { + runapt "${METHODSDIR}/rred" "$@" +} +for CMD in 'apt-dump-solver' 'apt-internal-solver' 'apt-internal-planner' 'rred'; do checkoptions "$(echo "$CMD" | tr -d '-')" done diff --git a/test/integration/test-method-rred b/test/integration/test-method-rred index 5a885e9d2..00b4b7c0b 100755 --- a/test/integration/test-method-rred +++ b/test/integration/test-method-rred @@ -195,3 +195,40 @@ Package: supercoolstuff failrred 'Wrong order of commands' '7d 17d' failrred 'End before start' '7,6d' + +# deal correctly with patch merging +mergepatches() { + testsuccess runapt "${METHODSDIR}/rred" Packages.ed-* + cp -a rootdir/tmp/testsuccess.output patch.ed + testfileequal 'patch.ed' "$1" +} +createpatch() { + echo "$2" +} + +createpatch 'Change dog to cat + kitties' '19c + And a cat! + +Package: extra-kittens +Version: unavailable +Description: fix later +.' > Packages.ed-0 +createpatch 'Remove more stuff and fix later' '23d, +6d' > Packages.ed-1 +createpatch 'Remove (old) dog paragraph' '10,19d' > Packages.ed-2 +mergepatches '11,19c +Package: extra-kittens +Version: unavailable +. +6d' +testrred 'Apply' 'merged patch' "$(cat patch.ed)" 'Package: coolstuff +Version: 0.8.15 +Description: collection of stuff + A lot, too much to iterate all, but at least this: + - stuff + - even more stuff + . + And a cow. + +Package: extra-kittens +Version: unavailable' -- cgit v1.2.3-70-g09d2 From 418f9272606857e312f485778a1ef1b263236463 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 7 Nov 2020 21:39:00 +0100 Subject: Support reading compressed patches in rred direct call modes The acquire system mode does this for a long time already and as it is easy to implement and handy for manual testing as well we can support it in the other modes, too. --- methods/rred.cc | 2 +- test/integration/test-method-rred | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/methods/rred.cc b/methods/rred.cc index b7825721c..0184456bf 100644 --- a/methods/rred.cc +++ b/methods/rred.cc @@ -806,7 +806,7 @@ int main(int argc, const char *argv[]) for (; argi < argmax; ++argi) { FileFd patch; - if (not patch.Open(CmdL.FileList[argi], FileFd::ReadOnly)) + if (not patch.Open(CmdL.FileList[argi], FileFd::ReadOnly, FileFd::Extension)) { _error->DumpErrors(std::cerr); return 1; diff --git a/test/integration/test-method-rred b/test/integration/test-method-rred index 00b4b7c0b..bef1a35e0 100755 --- a/test/integration/test-method-rred +++ b/test/integration/test-method-rred @@ -215,6 +215,9 @@ Description: fix later .' > Packages.ed-0 createpatch 'Remove more stuff and fix later' '23d, 6d' > Packages.ed-1 +testsuccess apthelper cat-file --compress gzip Packages.ed-1 +mv rootdir/tmp/testsuccess.output Packages.ed-1.gz +testsuccess rm Packages.ed-1 createpatch 'Remove (old) dog paragraph' '10,19d' > Packages.ed-2 mergepatches '11,19c Package: extra-kittens -- cgit v1.2.3-70-g09d2 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(-) (limited to 'test') 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-70-g09d2