Add some topographical sorting stuff
Summary: I need this to be able to apply dependencies in a working order for arc patch (T479). I feel like the names are wonky here so I appreciate suggestions. Also maybe more test cases?
Test Plan: ran unit tests
Reviewers: epriestley
Reviewed By: epriestley
CC: Korvin, epriestley, aran
Differential Revision: https://secure.phabricator.com/D7315