Move the package loop into register_reverses

By moving the package loop inside register_reverses, it will be
invoked a lot less (reducing the overhead of invoking functions).

Signed-off-by: Niels Thykier <niels@thykier.net>
master
Niels Thykier 12 years ago
parent 5c1391da4f
commit 0aa2546956

@ -566,8 +566,7 @@ class Britney(object):
packages[pkg] = dpkg packages[pkg] = dpkg
# loop again on the list of packages to register reverse dependencies and conflicts # loop again on the list of packages to register reverse dependencies and conflicts
for pkg in packages: register_reverses(packages, provides, check_doubles=False)
register_reverses(pkg, packages, provides, check_doubles=False)
# return a tuple with the list of real and virtual packages # return a tuple with the list of real and virtual packages
return (packages, provides) return (packages, provides)
@ -1988,10 +1987,12 @@ class Britney(object):
affected.update(self.get_reverse_tree(binary, parch, 'testing')) affected.update(self.get_reverse_tree(binary, parch, 'testing'))
# register reverse dependencies and conflicts for the new binary packages # register reverse dependencies and conflicts for the new binary packages
for p in source[BINARIES]: if item.architecture == 'source':
binary, parch = p.split("/") pkg_iter = (p.split("/")[0] for p in source[BINARIES])
if item.architecture not in ['source', parch]: continue else:
register_reverses(binary, binaries[parch][0] , binaries[parch][1]) ext = "/" + item.architecture
pkg_iter = (p.split("/")[0] for p in source[BINARIES] if p.endswith(ext))
register_reverses(binaries[parch][0], binaries[parch][1], iterator=pkg_iter)
# add/update the source package # add/update the source package
if item.architecture == 'source': if item.architecture == 'source':

@ -163,44 +163,55 @@ def old_libraries_format(libs):
def register_reverses(pkg, packages, provides, check_doubles=True, def register_reverses(packages, provides, check_doubles=True, iterator=None,
parse_depends=apt_pkg.parse_depends, parse_depends=apt_pkg.parse_depends,
DEPENDS=DEPENDS, CONFLICTS=CONFLICTS,
RDEPENDS=RDEPENDS, RCONFLICTS=RCONFLICTS): RDEPENDS=RDEPENDS, RCONFLICTS=RCONFLICTS):
"""Register reverse dependencies and conflicts for the specified package """Register reverse dependencies and conflicts for a given
sequence of packages
This method registers the reverse dependencies and conflicts for This method registers the reverse dependencies and conflicts for a
a given package using `packages` as the list of packages and `provides` given sequence of packages. "packages" is a table of real
as the list of virtual packages. packages and "provides" is a table of virtual packages.
iterator is the sequence of packages for which the reverse
relations should be updated.
The "X=X" parameters are optimizations to avoid "load global" in The "X=X" parameters are optimizations to avoid "load global" in
the loops. the loops.
""" """
# register the list of the dependencies for the depending packages if iterator is None:
dependencies = [] iterator = packages.iterkeys()
if packages[pkg][DEPENDS]: else:
dependencies.extend(parse_depends(packages[pkg][DEPENDS], False)) iterator = ifilter_only(packages, iterator)
# go through the list
for p in dependencies: for pkg in iterator:
for a in p: # register the list of the dependencies for the depending packages
# register real packages dependencies = []
if a[0] in packages and (not check_doubles or pkg not in packages[a[0]][RDEPENDS]): if packages[pkg][DEPENDS]:
packages[a[0]][RDEPENDS].append(pkg) dependencies.extend(parse_depends(packages[pkg][DEPENDS], False))
# also register packages which provide the package (if any) # go through the list
if a[0] in provides: for p in dependencies:
for i in provides.get(a[0]):
if i not in packages: continue
if not check_doubles or pkg not in packages[i][RDEPENDS]:
packages[i][RDEPENDS].append(pkg)
# register the list of the conflicts for the conflicting packages
if packages[pkg][CONFLICTS]:
for p in parse_depends(packages[pkg][CONFLICTS], False):
for a in p: for a in p:
# register real packages # register real packages
if a[0] in packages and (not check_doubles or pkg not in packages[a[0]][RCONFLICTS]): if a[0] in packages and (not check_doubles or pkg not in packages[a[0]][RDEPENDS]):
packages[a[0]][RCONFLICTS].append(pkg) packages[a[0]][RDEPENDS].append(pkg)
# also register packages which provide the package (if any) # also register packages which provide the package (if any)
if a[0] in provides: if a[0] in provides:
for i in provides[a[0]]: for i in provides[a[0]]:
if i not in packages: continue if i not in packages: continue
if not check_doubles or pkg not in packages[i][RCONFLICTS]: if not check_doubles or pkg not in packages[i][RDEPENDS]:
packages[i][RCONFLICTS].append(pkg) packages[i][RDEPENDS].append(pkg)
# register the list of the conflicts for the conflicting packages
if packages[pkg][CONFLICTS]:
for p in parse_depends(packages[pkg][CONFLICTS], False):
for a in p:
# register real packages
if a[0] in packages and (not check_doubles or pkg not in packages[a[0]][RCONFLICTS]):
packages[a[0]][RCONFLICTS].append(pkg)
# also register packages which provide the package (if any)
if a[0] in provides:
for i in provides[a[0]]:
if i not in packages: continue
if not check_doubles or pkg not in packages[i][RCONFLICTS]:
packages[i][RCONFLICTS].append(pkg)

Loading…
Cancel
Save