summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2021-03-06 15:02:26 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2021-03-06 15:02:26 +0100
commit9bd27033c4786fa89cebc9d090ad2c6e8f47b598 (patch)
tree527b2e6b0049bda7b38ad0cec9a83d0a0a126e68
parent3a7aecd232dfdbcec5dbdc3af16e03479d47d917 (diff)
Allow merging with empty pdiff patches
There isn't a lot of sense in working on empty patches as they change nothing (quite literally), but they can be the result of merging multiple patches and so to not require our users to specifically detect and remove them, we can be nice and just ignore them instead of erroring out.
-rw-r--r--methods/rred.cc6
-rwxr-xr-xtest/integration/test-method-rred5
2 files changed, 8 insertions, 3 deletions
diff --git a/methods/rred.cc b/methods/rred.cc
index f53f05ad5..3453bd3bc 100644
--- a/methods/rred.cc
+++ b/methods/rred.cc
@@ -441,8 +441,12 @@ class Patch {
bool cmdwanted = true;
Change ch(std::numeric_limits<size_t>::max());
- if (f.ReadLine(buffer, sizeof(buffer)) == NULL)
+ if (f.ReadLine(buffer, sizeof(buffer)) == nullptr)
+ {
+ if (f.Eof())
+ return true;
return _error->Error("Reading first line of patchfile %s failed", f.Name().c_str());
+ }
do {
if (h != NULL)
h->Add(buffer);
diff --git a/test/integration/test-method-rred b/test/integration/test-method-rred
index 645b0dfdd..5a42b8417 100755
--- a/test/integration/test-method-rred
+++ b/test/integration/test-method-rred
@@ -146,6 +146,7 @@ testrred 'Multi line change' 'more' '5,7c
- even more good stuff
- bonus good stuff
$(tail -n 12 ./Packages)"
+testrred 'Patch file' 'empty' '' "$(cat ./Packages)"
failrred() {
msgtest 'Failure caused by' "$1"
@@ -161,7 +162,6 @@ failrred 'Bogus content' '<html>
</html>'
# not a problem per-se, but we want our parser to be really strict
-failrred 'Empty patch file' ''
failrred 'Empty line patch file' '
'
failrred 'Empty line before command' '
@@ -222,7 +222,8 @@ createpatch 'Remove more stuff and fix later' '23d,
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
+touch Packages.ed-2 # an empty patch
+createpatch 'Remove (old) dog paragraph' '10,19d' > Packages.ed-3
mergepatches '11,19c
Package: extra-kittens
Version: unavailable