create_snapshot: improve copy operation by reordering

Sort the copy blocks so consecutive target blocks can be together.

Fix WriteOrderedSnapshots() to go through copy operations
using topological sort and re-order them so we can maximize
copy operations and reduce the replace operations further.

If we detect the cycles in dependency, convert only those blocks
to replace blocks.

Test: create_snapshot on 2 builds before and after, patch size reduced
by 10x (~900MB -> ~90MB).

Bug: 401284556

Change-Id: I4aaa02849164575d1a4dbf1578cdfc1627230c5c
Signed-off-by: Sandeep Dhavale <dhavale@google.com>
2 files changed