mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-10-21 12:48:28 +00:00
git_superproject: resolve one negotiation ref directly
The superproject only needs one branch tip or HEAD OID. Resolve that ref with one quiet rev-parse instead of constructing GitRefs, which loads the entire namespace and resolves HEAD in two or three processes on older clients. Bug: 553599402 Change-Id: I162d1133ebd1941e9de5aca43929fd5af17386ef Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/623906 Tested-by: Gavin Mak <gavinmak@google.com> Reviewed-by: Brian Gan <brgan@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com>
This commit is contained in:
1 parent
d88ce8d952
commit
ba8ddf396c
2 files changed
+44
-7
No files matched your search
@@ -542,14 +542,15 @@ class SuperprojectTestCase(unittest.TestCase):
|
||||
with mock.patch(
|
||||
"git_superproject.GitCommand", autospec=True
|
||||
) as mock_git_command:
|
||||
with mock.patch(
|
||||
"git_superproject.GitRefs.get", autospec=True
|
||||
) as mock_git_refs:
|
||||
with mock.patch.object(
|
||||
self._superproject, "_GetRef"
|
||||
) as get_ref:
|
||||
instance = mock_git_command.return_value
|
||||
instance.Wait.return_value = 0
|
||||
mock_git_refs.side_effect = ["", "1234"]
|
||||
get_ref.side_effect = ["", "1234"]
|
||||
|
||||
self.assertTrue(self._superproject._Fetch())
|
||||
get_ref.assert_called_with("refs/heads/main")
|
||||
self.assertEqual(
|
||||
# TODO: Once we require Python 3.8+,
|
||||
# use 'mock_git_command.call_args.args'.
|
||||
@@ -572,6 +573,7 @@ class SuperprojectTestCase(unittest.TestCase):
|
||||
|
||||
# If branch for revision exists, set as --negotiation-tip.
|
||||
self.assertTrue(self._superproject._Fetch())
|
||||
get_ref.assert_called_with("refs/heads/main")
|
||||
self.assertEqual(
|
||||
# TODO: Once we require Python 3.8+,
|
||||
# use 'mock_git_command.call_args.args'.
|
||||
@@ -593,3 +595,21 @@ class SuperprojectTestCase(unittest.TestCase):
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
def test_GetRef_resolves_only_the_requested_ref(self) -> None:
|
||||
command = mock.MagicMock(stdout="1234\n")
|
||||
command.Wait.return_value = 0
|
||||
with mock.patch(
|
||||
"git_superproject.GitCommand", return_value=command
|
||||
) as git_command:
|
||||
self.assertEqual("1234", self._superproject._GetRef("HEAD"))
|
||||
|
||||
git_command.assert_called_once_with(
|
||||
None,
|
||||
["rev-parse", "--verify", "--quiet", "HEAD"],
|
||||
gitdir=self._superproject._work_git,
|
||||
bare=True,
|
||||
capture_stdout=True,
|
||||
capture_stderr=True,
|
||||
log_as_error=False,
|
||||
)
|
||||
Reference in new issue
Block a user