summaryrefslogtreecommitdiffstats
path: root/subcmds/sync.py
diff options
context:
space:
mode:
authorJosip Sokcevic <sokcevic@chromium.org>2024-03-07 22:18:58 +0000
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-03-08 17:58:24 +0000
commit46790229fcdb041c414a27035b72cbc0d2e78af6 (patch)
tree67dd6b331edd153680e856b8859d99c634a4995d /subcmds/sync.py
parentedadb25c0270398e9afa3eb0093d6b94aa51c3f4 (diff)
downloadgit-repo-46790229fcdb041c414a27035b72cbc0d2e78af6.tar.gz
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 <sokcevic@google.com> Commit-Queue: Josip Sokcevic <sokcevic@google.com> Reviewed-by: George Engelbrecht <engeg@google.com>
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r--subcmds/sync.py10
1 files changed, 7 insertions, 3 deletions
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]]:
102 102
103 # depth_stack contains a current stack of parent paths. 103 # depth_stack contains a current stack of parent paths.
104 depth_stack = [] 104 depth_stack = []
105 # checkouts are iterated in asc order by relpath. That way, it can easily be 105 # Checkouts are iterated in the hierarchical order. That way, it can easily
106 # determined if the previous checkout is parent of the current checkout. 106 # be determined if the previous checkout is parent of the current checkout.
107 for checkout in sorted(checkouts, key=lambda x: x.relpath): 107 # We are splitting by the path separator so the final result is
108 # hierarchical, and not just lexicographical. For example, if the projects
109 # are: foo, foo/bar, foo-bar, lexicographical order produces foo, foo-bar
110 # and foo/bar, which doesn't work.
111 for checkout in sorted(checkouts, key=lambda x: x.relpath.split("/")):
108 checkout_path = Path(checkout.relpath) 112 checkout_path = Path(checkout.relpath)
109 while depth_stack: 113 while depth_stack:
110 try: 114 try: