Add update.sort()

Extracted from identify(). It just does the topological sort of files and
returns it, and detects cycles.