Skip to content

Conversation

@add-uos
Copy link
Contributor

@add-uos add-uos commented Oct 10, 2025

Replaced detailed UFS version parsing (3.0/3.1/4.0) with generic "UFS" identifier when output is non-empty, streamlining interface detection logic.

Log: Streamline UFS interface detection
Task: https://pms.uniontech.com/task-view-382541.html
Change-Id: Ia1a80391d0291e3de69723630ae17029fadd2eb1

Summary by Sourcery

Enhancements:

  • Remove detailed parsing of UFS versions (3.0/3.1/4.0) and always set interface to generic "UFS" when output is non-empty

Replaced detailed UFS version parsing (3.0/3.1/4.0)
with generic "UFS" identifier when output is non-empty,
streamlining interface detection logic.

Log: Streamline UFS interface detection
Task: https://pms.uniontech.com/task-view-382541.html
Change-Id: Ia1a80391d0291e3de69723630ae17029fadd2eb1
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 10, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Streamlines UFS interface detection by replacing detailed version-specific parsing with a generic “UFS” identifier whenever output is non-empty.

Class diagram for updated UFS interface detection logic

classDiagram
    class HWGenerator {
        +void generatorDiskDevice()
        tempMap["Interface"]: string
        tempMap["interface"]: string
    }
    class DeviceStorage {
        +bool setHwinfoInfo(const QMap<QString, QString> &mapInfo)
        m_Interface: string
    }
    HWGenerator --> DeviceStorage: uses
Loading

Flow diagram for simplified UFS interface detection

flowchart TD
    A["Read UFS version output"] --> B{"Is output non-empty?"}
    B -- Yes --> C["Set interface to 'UFS'"]
    B -- No --> D["Do not set interface"]
Loading

File-Level Changes

Change Details Files
Simplify UFS interface assignment in HWGenerator
  • Replaced hardcoded “UFS 3.1” with generic “UFS”
  • Consolidated version checks on process output into a single non-empty condition setting “UFS”
deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp
Streamline UFS detection in DeviceStorage
  • Removed individual checks for 3.1/3.0/4.0 substrings
  • Replaced with a single non-empty output check assigning generic “UFS”
deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link

deepin pr auto review

这段代码的修改主要有以下几点需要关注:

  1. 代码逻辑变更:

    • 原代码中根据读取到的硬件信息("310"、"300"、"400")来设置不同的UFS接口版本("UFS 3.1"、"UFS 3.0"、"UFS 4.0")
    • 修改后简化为只要输出不为空就设置为通用的"UFS"
  2. 存在的问题:

    • 信息丢失:修改后无法区分不同版本的UFS接口,丢失了重要的硬件信息
    • 一致性问题:两个文件中的修改方式不一致(一个直接赋值"UFS",另一个是在特定条件下赋值)
    • 键名不一致:在HWGenerator.cpp中使用了"Interface"和"interface"两种不同的键名
  3. 改进建议:

    // 建议保留版本检测逻辑,但可以优化实现方式
    QString detectUfsVersion(const QString &output) {
        if (output.contains("310", Qt::CaseInsensitive)) {
            return "UFS 3.1";
        } else if (output.contains("300", Qt::CaseInsensitive)) {
            return "UFS 3.0";
        } else if (output.contains("400", Qt::CaseInsensitive)) {
            return "UFS 4.0";
        }
        return "UFS"; // 默认值
    }
    
    // 使用示例
    m_Interface = detectUfsVersion(output);
  4. 性能考虑:

    • 当前实现已经足够高效,字符串操作在Qt中已经过优化
    • 如果需要更高性能,可以考虑使用正则表达式,但对于这种简单的字符串匹配,当前方式更直观
  5. 代码质量改进:

    • 添加错误处理,考虑文件读取失败的情况
    • 统一接口版本的命名规范
    • 添加注释说明版本检测的逻辑
  6. 安全性:

    • 当前代码没有明显的安全问题
    • 建议添加输入验证,确保mapInfo中的数据格式正确
  7. 一致性建议:

    • 统一两个文件中的接口版本检测逻辑
    • 统一键名大小写,建议使用驼峰命名法(如"Interface")
    • 考虑将版本检测逻辑封装为独立的工具函数,避免代码重复

总结:虽然简化版本检测逻辑可能减少了代码量,但丢失了重要的硬件信息。建议保留版本检测功能,同时优化代码结构和实现方式。

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • The change removes detailed UFS version info – consider keeping the numeric version string in a separate field or log for future diagnostics.
  • There’s inconsistent use of map keys 'Interface' vs 'interface' – unify on a single key and extract it to a constant to avoid typos.
  • Both HWGenerator and DeviceStorage now duplicate the same UFS detection logic – consider extracting it into a shared helper to reduce code repetition.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The change removes detailed UFS version info – consider keeping the numeric version string in a separate field or log for future diagnostics.
- There’s inconsistent use of map keys 'Interface' vs 'interface' – unify on a single key and extract it to a constant to avoid typos.
- Both HWGenerator and DeviceStorage now duplicate the same UFS detection logic – consider extracting it into a shared helper to reduce code repetition.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, GongHeng2017, max-lvs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@add-uos
Copy link
Contributor Author

add-uos commented Oct 10, 2025

merge

@add-uos
Copy link
Contributor Author

add-uos commented Oct 10, 2025

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Oct 10, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit a0b7831 into linuxdeepin:develop/eagle Oct 10, 2025
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants