From 1f520269deb8f582c64b8ac990544f6e5c7a9ba7 Mon Sep 17 00:00:00 2001
From: Steve Langasek <steve.langasek@canonical.com>
Date: Tue, 5 Oct 2021 13:21:44 -0700
Subject: [PATCH] Iterate over binary packages from a source package before
 iterating over hints

The existing code attempts to "short circuit" processing of binaries in
unstable by first checking if the package is subject to a removal hint.

This is invalid in Ubuntu for two reasons:
- we do not use removal hints for removing packages from the release pocket
- there are 11,000 hints in Ubuntu (due to force-reset-test) - searching all
  hints is time-consuming and not a short-circuit at all.

Reorder the code so we only scan the hints if there's otherwise an
indication of something to do.
---
 britney2/excusefinder.py | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/britney2/excusefinder.py b/britney2/excusefinder.py
index 75b7497..2b2b2ec 100644
--- a/britney2/excusefinder.py
+++ b/britney2/excusefinder.py
@@ -97,18 +97,6 @@ class ExcuseFinder(object):
         source_u.section and excuse.set_section(source_u.section)
         excuse.set_distribution(self.options.distribution)
 
-        # if there is a `remove' hint and the requested version is the same as the
-        # version in testing, then stop here and return False
-        # (as a side effect, a removal may generate such excuses for both the source
-        # package and its binary packages on each architecture)
-        for hint in self.hints.search('remove', package=src, version=source_t.version):
-            excuse.add_hint(hint)
-            excuse.policy_verdict = PolicyVerdict.REJECTED_PERMANENTLY
-            excuse.add_verdict_info(excuse.policy_verdict, "Removal request by %s" % (hint.user))
-            excuse.add_verdict_info(excuse.policy_verdict, "Trying to remove package, not update it")
-            self.excuses[excuse.name] = excuse
-            return False
-
         # the starting point is that there is nothing wrong and nothing worth doing
         anywrongver = False
         anyworthdoing = False
@@ -249,6 +237,19 @@ class ExcuseFinder(object):
             # nothing worth doing, we don't add an excuse to the list, we just return false
             return False
 
+        # if there is a `remove' hint and the requested version is the same as the
+        # version in testing, then stop here and return False
+        # (as a side effect, a removal may generate such excuses for both the source
+        # package and its binary packages on each architecture)
+        for hint in self.hints.search('remove', package=src, version=source_t.version):
+            excuse = Excuse(item)
+            excuse.add_hint(hint)
+            excuse.policy_verdict = PolicyVerdict.REJECTED_PERMANENTLY
+            excuse.add_verdict_info(excuse.policy_verdict, "Removal request by %s" % (hint.user))
+            excuse.add_verdict_info(excuse.policy_verdict, "Trying to remove package, not update it")
+            self.excuses[excuse.name] = excuse
+            return False
+
         # there is something worth doing
         # we assume that this package will be ok, if not invalidated below
         excuse.policy_verdict = PolicyVerdict.PASS