diff options
| author | Josip Sokcevic <sokcevic@chromium.org> | 2024-03-07 22:18:58 +0000 |
|---|---|---|
| committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-03-08 17:58:24 +0000 |
| commit | 46790229fcdb041c414a27035b72cbc0d2e78af6 (patch) | |
| tree | 67dd6b331edd153680e856b8859d99c634a4995d /tests | |
| parent | edadb25c0270398e9afa3eb0093d6b94aa51c3f4 (diff) | |
| download | git-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 'tests')
| -rw-r--r-- | tests/test_subcmds_sync.py | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py index 13e23e34..8dde687c 100644 --- a/tests/test_subcmds_sync.py +++ b/tests/test_subcmds_sync.py | |||
| @@ -304,29 +304,54 @@ class LocalSyncState(unittest.TestCase): | |||
| 304 | self.assertEqual(self.state.GetFetchTime(projA), 5) | 304 | self.assertEqual(self.state.GetFetchTime(projA), 5) |
| 305 | 305 | ||
| 306 | 306 | ||
| 307 | class FakeProject: | ||
| 308 | def __init__(self, relpath): | ||
| 309 | self.relpath = relpath | ||
| 310 | |||
| 311 | def __str__(self): | ||
| 312 | return f"project: {self.relpath}" | ||
| 313 | |||
| 314 | def __repr__(self): | ||
| 315 | return str(self) | ||
| 316 | |||
| 317 | |||
| 307 | class SafeCheckoutOrder(unittest.TestCase): | 318 | class SafeCheckoutOrder(unittest.TestCase): |
| 308 | def test_no_nested(self): | 319 | def test_no_nested(self): |
| 309 | p_f = mock.MagicMock(relpath="f") | 320 | p_f = FakeProject("f") |
| 310 | p_foo = mock.MagicMock(relpath="foo") | 321 | p_foo = FakeProject("foo") |
| 311 | out = sync._SafeCheckoutOrder([p_f, p_foo]) | 322 | out = sync._SafeCheckoutOrder([p_f, p_foo]) |
| 312 | self.assertEqual(out, [[p_f, p_foo]]) | 323 | self.assertEqual(out, [[p_f, p_foo]]) |
| 313 | 324 | ||
| 314 | def test_basic_nested(self): | 325 | def test_basic_nested(self): |
| 315 | p_foo = p_foo = mock.MagicMock(relpath="foo") | 326 | p_foo = p_foo = FakeProject("foo") |
| 316 | p_foo_bar = mock.MagicMock(relpath="foo/bar") | 327 | p_foo_bar = FakeProject("foo/bar") |
| 317 | out = sync._SafeCheckoutOrder([p_foo, p_foo_bar]) | 328 | out = sync._SafeCheckoutOrder([p_foo, p_foo_bar]) |
| 318 | self.assertEqual(out, [[p_foo], [p_foo_bar]]) | 329 | self.assertEqual(out, [[p_foo], [p_foo_bar]]) |
| 319 | 330 | ||
| 320 | def test_complex_nested(self): | 331 | def test_complex_nested(self): |
| 321 | p_foo = mock.MagicMock(relpath="foo") | 332 | p_foo = FakeProject("foo") |
| 322 | p_foo_bar = mock.MagicMock(relpath="foo/bar") | 333 | p_foobar = FakeProject("foobar") |
| 323 | p_foo_bar_baz_baq = mock.MagicMock(relpath="foo/bar/baz/baq") | 334 | p_foo_dash_bar = FakeProject("foo-bar") |
| 324 | p_bar = mock.MagicMock(relpath="bar") | 335 | p_foo_bar = FakeProject("foo/bar") |
| 336 | p_foo_bar_baz_baq = FakeProject("foo/bar/baz/baq") | ||
| 337 | p_bar = FakeProject("bar") | ||
| 325 | out = sync._SafeCheckoutOrder( | 338 | out = sync._SafeCheckoutOrder( |
| 326 | [p_foo_bar_baz_baq, p_foo, p_foo_bar, p_bar] | 339 | [ |
| 340 | p_foo_bar_baz_baq, | ||
| 341 | p_foo, | ||
| 342 | p_foobar, | ||
| 343 | p_foo_dash_bar, | ||
| 344 | p_foo_bar, | ||
| 345 | p_bar, | ||
| 346 | ] | ||
| 327 | ) | 347 | ) |
| 328 | self.assertEqual( | 348 | self.assertEqual( |
| 329 | out, [[p_bar, p_foo], [p_foo_bar], [p_foo_bar_baz_baq]] | 349 | out, |
| 350 | [ | ||
| 351 | [p_bar, p_foo, p_foo_dash_bar, p_foobar], | ||
| 352 | [p_foo_bar], | ||
| 353 | [p_foo_bar_baz_baq], | ||
| 354 | ], | ||
| 330 | ) | 355 | ) |
| 331 | 356 | ||
| 332 | 357 | ||
