refactor: improve build dependency pull#1668
Conversation
deepin pr auto review你好!我是CodeGeeX。我已仔细审查了你提供的Git Diff。本次修改的核心是将依赖拉取与解析的逻辑( 整体来看,重构提高了代码的内聚性,消除了重复代码,且单元测试覆盖了核心分支。但在语法逻辑、代码质量和安全性方面,我发现了一些需要改进的地方,以下是详细的审查意见: 1. 语法与逻辑问题 1.1: bool preferRemote = remoteRef && (!localRef || remoteRef->version > localRef->version);
auto &bestRef = preferRemote ? remoteRef : localRef;这里 auto pullRes = pullResolvedRef(*bestRef, repo, module);
if (pullRes) {
return std::move(*bestRef); // 【风险点】
}如果 if (preferRemote && localRef) {
// ...
auto fallbackRes = pullResolvedRef(*localRef, repo, module);此时 改进建议: 避免使用引用指向不同的 bool preferRemote = remoteRef && (!localRef || remoteRef->version > localRef->version);
package::Reference bestRefValue = preferRemote ? std::move(*remoteRef) : std::move(*localRef);
auto pullRes = pullResolvedRef(bestRefValue, repo, module);
if (pullRes) {
return std::move(bestRefValue);
}
if (preferRemote && localRef) {
LogW("failed to pull remote version {}, falling back to local: {}",
bestRefValue.toString(),
pullRes.error().message());
auto fallbackRes = pullResolvedRef(*localRef, repo, module);
if (fallbackRes) {
return std::move(*localRef);
}
return LINGLONG_ERR("failed to pull local fallback version " + localRef->toString(),
fallbackRes);
}
return LINGLONG_ERR("failed to pull version " + bestRefValue.toString(), pullRes);问题 1.2: if (repo.getLayerDir(ref, module)) {
return LINGLONG_OK;
}原注释 改进建议: 如果 2. 代码质量问题 2.1: auto localResult = repo.clearReference(*fuzzyRef, { .forceRemote = false, .fallbackToRemote = false, ... });
// ...
auto remoteResult = repo.clearReference(*fuzzyRef, { .forceRemote = true, .fallbackToRemote = true, ... });而在旧代码 问题 2.2: auto baseRef = detail::pullDependency(this->project->base, this->repo, "binary", !this->buildOptions.skipPullDepend);如果 问题 2.3:头文件中 namespace detail {
// ...
utils::error::Result<package::Reference> pullDependency(...);
} // namespace detail把内部实现细节放到了头文件的 改进建议: 3. 代码性能问题 3.1: auto fuzzyRef = package::FuzzyReference::parse(fuzzyRefStr);而在调用侧(如 auto fuzzyRef = package::FuzzyReference::parse(id);
// ...
auto ref = detail::pullDependency(fuzzyRef->toString(), this->repo, "binary", true);这里先将 改进建议: 修改 utils::error::Result<package::Reference> pullDependency(const package::FuzzyReference &fuzzyRef,
repo::OSTreeRepo &repo,
const std::string &module,
bool useRemote) noexcept;这样在 4. 代码安全问题 4.1:单元测试中的 Mock 绕过了虚函数机制的风险 class MockRepo : public repo::OSTreeRepo
{
// ...
MOCK_METHOD(utils::error::Result<void>,
pull,
(service::Task & taskContext,
const package::ReferenceWithRepo &refRepo,
const std::string &module),
(override, noexcept));
};为了使 Mock 生效,你在
改进建议: 问题 4.2:测试中的硬编码临时目录 std::filesystem::path m_tmpDir{ "/tmp/ll-pull-dep-test" };硬编码 改进建议: 使用系统提供的临时目录生成机制,确保每次运行路径唯一: std::filesystem::path m_tmpDir = std::filesystem::temp_directory_path() / "ll-pull-dep-test-XXXXXX";
// 或者使用 QTemporaryDir总结本次重构方向非常正确,极大地提升了依赖拉取流程的内聚性和可维护性。建议优先修复 1.1 中的引用与移动语义问题,并考虑 3.1 的接口优化以提升性能。关于 4.1 的 virtual 化,如果团队目前接受为了测试而开放虚函数,则可以保留,但长期建议重构为接口依赖。 |
There was a problem hiding this comment.
Code Review
This pull request refactors the dependency pulling logic in linglong_builder.cpp by introducing detail::pullDependency and detail::pullResolvedRef helper functions, making OSTreeRepo methods virtual for mocking, and adding a comprehensive unit test suite. The review feedback suggests improving error propagation by passing the underlying result errors to LINGLONG_ERR when resolution fails, and replacing the hardcoded temporary directory path in the tests with QTemporaryDir to avoid concurrent execution conflicts.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Codecov Report❌ Patch coverage is
... and 4 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Signed-off-by: reddevillg <reddevillg@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengbo11, reddevillg The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
No description provided.