From 69c94caa015ea3526676fc9166100250bf5052d7 Mon Sep 17 00:00:00 2001
From: Ivo De Decker <ivodd@debian.org>
Date: Wed, 9 Jan 2019 00:49:52 +0000
Subject: [PATCH] Add source_name return value to compute_groups

When the item is a single binary cruft removal, the source name is different
from the package. compute_groups has this info anyway, so just pass it on as a
returm value.

Signed-off-by: Ivo De Decker <ivodd@debian.org>
---
 britney.py            |  2 +-
 britney2/migration.py | 13 +++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/britney.py b/britney.py
index bc1fb99..5247fc6 100755
--- a/britney.py
+++ b/britney.py
@@ -1441,7 +1441,7 @@ class Britney(object):
 
         for y in sorted((y for y in packages), key=attrgetter('uvname')):
             try:
-                updates, rms, _ = mm.compute_groups(y)
+                _, updates, rms, _ = mm.compute_groups(y)
                 result = (y, frozenset(updates), frozenset(rms))
                 group_info[y] = result
             except MigrationConstraintException as e:
diff --git a/britney2/migration.py b/britney2/migration.py
index e660bdf..fa5c658 100644
--- a/britney2/migration.py
+++ b/britney2/migration.py
@@ -109,6 +109,7 @@ class MigrationManager(object):
         else:
             assert source_name in binaries_t[item.architecture]
             pkg_id = binaries_t[item.architecture][source_name].pkg_id
+            source_name = binaries_t[item.architecture][source_name].source
             rms = {pkg_id}
             smoothbins = set()
 
@@ -156,7 +157,7 @@ class MigrationManager(object):
 
                 adds.add(pkg_id)
 
-        return (adds, rms, smoothbins)
+        return (source_name, adds, rms, smoothbins)
 
     def _compute_removals(self, item, allow_smooth_updates, removals):
         pkg_universe = self.pkg_universe
@@ -241,18 +242,18 @@ class MigrationManager(object):
         pkg_universe = self.pkg_universe
         transaction = self.current_transaction
 
-        updates, rms, _ = self.compute_groups(item, removals=removals)
+        source_name, updates, rms, _ = self.compute_groups(item, removals=removals)
 
         # Handle the source package
         if item.architecture == 'source':
             sources_t = target_suite.sources
-            undo['sources'][item.package] = sources_t.get(item.package)
+            undo['sources'][source_name] = sources_t.get(source_name)
 
             # add/update the source package
             if item.is_removal:
-                del sources_t[item.package]
+                del sources_t[source_name]
             else:
-                sources_t[item.package] = source_suite.sources[item.package]
+                sources_t[source_name] = source_suite.sources[source_name]
 
         eqv_set = compute_eqv_set(pkg_universe, updates, rms)
 
@@ -369,7 +370,7 @@ class MigrationManager(object):
             affected_direct = set()
             affected_all = set()
             for item in items:
-                _, rms, _ = self.compute_groups(item, allow_smooth_updates=False)
+                _, _, rms, _ = self.compute_groups(item, allow_smooth_updates=False)
                 removals.update(rms)
                 affected_architectures.add(item.architecture)