sync: Introduce git checkout levels

If a repo manifest is updated so that project B is placed within a
project A, and if project A had content in new B's location in the old
checkout, then repo sync could break depending on checkout order, since
B can't be checked out before A.

This change introduces checkout levels which enforces right sequence of
checkouts while still allowing for parallel checkout. In an example
above, A will always be checked out first before B.

BUG=b:325119758
TEST=./run_tests, manual sync on ChromeOS repository

Change-Id: Ib3b5e4d2639ca56620a1e4c6bf76d7b1ab805250
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/410421
Tested-by: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Greg Edelston <gredelston@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
Josip Sokcevic
2024-02-22 16:38:00 -08:00
committed by LUCI
parent 97ca50f5f9
commit 5554572f02
2 changed files with 81 additions and 9 deletions

View File

@ -304,6 +304,32 @@ class LocalSyncState(unittest.TestCase):
self.assertEqual(self.state.GetFetchTime(projA), 5)
class SafeCheckoutOrder(unittest.TestCase):
def test_no_nested(self):
p_f = mock.MagicMock(relpath="f")
p_foo = mock.MagicMock(relpath="foo")
out = sync._SafeCheckoutOrder([p_f, p_foo])
self.assertEqual(out, [[p_f, p_foo]])
def test_basic_nested(self):
p_foo = p_foo = mock.MagicMock(relpath="foo")
p_foo_bar = mock.MagicMock(relpath="foo/bar")
out = sync._SafeCheckoutOrder([p_foo, p_foo_bar])
self.assertEqual(out, [[p_foo], [p_foo_bar]])
def test_complex_nested(self):
p_foo = mock.MagicMock(relpath="foo")
p_foo_bar = mock.MagicMock(relpath="foo/bar")
p_foo_bar_baz_baq = mock.MagicMock(relpath="foo/bar/baz/baq")
p_bar = mock.MagicMock(relpath="bar")
out = sync._SafeCheckoutOrder(
[p_foo_bar_baz_baq, p_foo, p_foo_bar, p_bar]
)
self.assertEqual(
out, [[p_bar, p_foo], [p_foo_bar], [p_foo_bar_baz_baq]]
)
class GetPreciousObjectsState(unittest.TestCase):
"""Tests for _GetPreciousObjectsState."""