From 46790229fcdb041c414a27035b72cbc0d2e78af6 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Thu, 7 Mar 2024 22:18:58 +0000 Subject: sync: Fix sorting for nested projects The current logic to create checkout layers doesn't work in all cases. For example, let's assume there are three projects: "foo", "foo/bar" and "foo-bar". Sorting lexicographical order is incorrect as foo-bar would be placed between foo and foo/bar, breaking layering logic. Instead, we split filepaths based using path delimiter (always /) and then use lexicographical sort. BUG=b:325119758 TEST=./run_tests, manual sync on chromiumos repository Change-Id: I76924c3cc6ba2bb860d7a3e48406a6bba8f58c10 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/412338 Tested-by: Josip Sokcevic Commit-Queue: Josip Sokcevic Reviewed-by: George Engelbrecht --- subcmds/sync.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'subcmds/sync.py') diff --git a/subcmds/sync.py b/subcmds/sync.py index 7acb6e5b..113e7a67 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -102,9 +102,13 @@ def _SafeCheckoutOrder(checkouts: List[Project]) -> List[List[Project]]: # depth_stack contains a current stack of parent paths. depth_stack = [] - # checkouts are iterated in asc order by relpath. That way, it can easily be - # determined if the previous checkout is parent of the current checkout. - for checkout in sorted(checkouts, key=lambda x: x.relpath): + # Checkouts are iterated in the hierarchical order. That way, it can easily + # be determined if the previous checkout is parent of the current checkout. + # We are splitting by the path separator so the final result is + # hierarchical, and not just lexicographical. For example, if the projects + # are: foo, foo/bar, foo-bar, lexicographical order produces foo, foo-bar + # and foo/bar, which doesn't work. + for checkout in sorted(checkouts, key=lambda x: x.relpath.split("/")): checkout_path = Path(checkout.relpath) while depth_stack: try: -- cgit v1.2.3-54-g00ecf