Hi!
On Fri, 2014-08-29 at 15:13:35 -0700, Dima Kogan wrote:
> Package: libdpkg-perl
> Version: 1.17.9
> Severity: normal
> Here's a patch to add a new function Dpkg::Deps::deps_iterate_flat().
> This is a utility function to iterate through items in a Depends line.
> This was needed for some new sbuild functionality I needed to add to
> support some cross builds.
Yeah, makes sense thanks, I've merged locally a slightly modified
version.
> +sub deps_iterate_flat
> +{
> + my ($deps, $callback) = @_;
> +
> +
> + my %already_visited;
> +
> + # returns true if we should continue. returns false if we should stop
> + # (something went wrong or the callback returned false)
> + my $iterate_level;
> + $iterate_level = sub
> + {
> + foreach my $dep (@_)
> + {
> + # I make sure to break any recursion in the deps data structure
> + return if !defined $dep;
> + my $id = ref($dep) ? refaddr($dep) : "str:$dep";
> + return 1 if $already_visited{$id};
> + $already_visited{$id} = 1;
I've removed the visited tracking, because there should be no recursion
in the dependency data structures returned by deps_parse(), and the
rest of Dpkg::Deps would not handle it anyway, or do you have uses where
there is recursion?
> +
> + if ( defined(ref $dep) && ref($dep) eq 'Dpkg::Deps::Simple' )
I've switched this to simply use $dep->isa() instead.
> + {
> + return undef unless &$callback($dep);
> + }
> + else
> + {
> + return undef unless &$iterate_level($dep->get_deps);
> + }
And removed the undef in the return.
> + }
> + return 1;
> + };
> +
> + return &$iterate_level($deps);
> +}
Thanks,
Guillem
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]