Metadata: search groups breadth-first when building metadata

This makes category negation consistent, and also makes it work like
it did in Bcfg2 1.2