It's possible to have a loop in change relationships (whether accidentally
or intentionally). The current method of getting related changes in order
to prune the change cache does not handle that.
This reworks that method to be safe for recursion.
During development, it was observed that the set of relevant changes was
actually a mixture of cache keys (which are objects) and cache references
(which are string representations of the same). This change also refactors
the collection of relevant cache keys into a method which can be tested on
its own to verify we get keys of a consistent type.
Change-Id: Ie76f9b19f10b053f5c72bdaf7be3efc445b53639