Skip to content

Conversation

@chimes-of-freedom
Copy link
Contributor

功能描述

参照 Git 为 libra 的 branch 命令实现 --contains / --no-contains(别名 --with / --without)参数,可在列出分支时过滤出包含/不包含指定提交的分支。

  1. 对于 --contains 指定的提交,要求过滤出其 tip commit 的祖先提交包含该提交的分支;
  2. 对于 --no-contians 制定的提交,要求过滤出其 tip commit 的祖先提交不包含该提交的分支;
  3. 对于指定多个 --contains--no-contians 的情形,要求过滤出 至少满足一个 --contains 条件且满足所有 --no-contains 条件 的分支。

实现方案

以下实现均在 src/command/branch.rs 中定义。

  1. 定义 --contains--no-contains 参数。
  2. 修改 list_branches() 函数签名,增加 commits_containscommits_no_contains 参数,同步修改所有调用处代码。
  3. 重构 list_branches() 中处理 本地分支和远程分支的部分,使之仅仅是得到 local_branchesremote_branches 两个 Vec,并在函数末尾增加打印非空 Vec 的逻辑。
  4. 定义 commit_contains(),检查给定的 branch 是否包含给定 commits 中至少一个:遍历 commits,对于每一个目标提交,对 branch 的 tip commit 进行 BFS 以确认 branch 是否包含目标提交,一旦找到一个目标提交被 branch 包含则返回 true,否则返回 false(包括 commits 为空时)。
  5. 定义 filter_branches() 实现对给定 branches 的过滤:便利 branches,对于每个 branch 调用 2 次 commit_contains() 分别检查是否包含 --contains--no-contains 指定的一系列提交之一,进而判断是否保留该分支,最后通过 retain() 过滤 branches
  6. list_branches() 得到 local_branchesremote_branches 后、打印分支集之前插入对 filter_branches() 的调用,对本地分支集和远程分支集分别进行过滤。

测试方案

以下测试均在 tests/command/branch_test.rs::test_branch_contains_commit_filter() 中定义。

  1. 创建如下的测试提交图:
master:  base ← m1 ← m2
           ↖
dev:        d1 ← d2
  1. 设计测试用例,覆盖如下参数组合:
    1. 单一选项,每个选项只指定 1 次;
    2. 组合选项,每个选项只指定 1 次;
    3. 组合选项,每个选项指定多次。
  2. 对于每个测试用例,直接调用 filter_branches() 以便检查测试结果。

测试结果

  • 通过 cargo clippy --all-targets --all-features -- -D warnings 检查。
  • 通过 cargo +nightly fmt --all --check 检查。
  • 通过 cargo test 检查。
  • cargo build / cargo buckal build / buck2 run //:libra 成功。

Copilot AI review requested due to automatic review settings February 7, 2026 09:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends Libra’s branch command with Git-like branch filtering capabilities by adding --contains / --no-contains (aliases --with / --without), enabling listing branches based on commit reachability from each branch tip.

Changes:

  • Add CLI flags and listing logic to filter local/remote branches by whether they contain specified commits.
  • Introduce reusable filtering helpers (filter_branches, commit_contains) and add an integration test covering key flag combinations.
  • Update multiple tests/call sites for the new BranchArgs fields and the new list_branches signature; refresh README and Cargo.lock.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/command/branch.rs Adds --contains/--no-contains args, updates listing flow, and implements commit-reachability filtering.
tests/command/branch_test.rs Adds a comprehensive integration test for the new branch filtering behavior.
tests/command/checkout_test.rs Updates call site for the new list_branches(mode, contains, no_contains) signature.
tests/command/reset_test.rs Extends BranchArgs construction with new contains/no_contains fields.
tests/command/mod.rs Re-exports filter_branches for integration tests.
tests/command/show_test.rs Minor CLI invocation refactor (args([...])).
tests/command/remote_test.rs Minor string formatting simplification in branch lookup.
tests/command/init_test.rs Simplifies error mapping using io::Error::other.
tests/command/index_pack_test.rs Minor iterator/refactor improvements in parsing helpers and path reads.
src/internal/ai/agent/chat.rs Simplifies test-side pattern matching for user message handling.
README.md Marks --contains as supported in Libra in the compatibility table.
Cargo.lock Large dependency lockfile refresh accompanying the change.

@genedna
Copy link
Member

genedna commented Feb 7, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5be226ee8e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI review requested due to automatic review settings February 8, 2026 06:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings February 8, 2026 07:32
…ranch`

- implement `--contains` / `--no-contains` (aliases: `--with` / `--without`)
- add unit tests
- run fmt and clippy

Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
…filter

Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
…tains entry

Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
… an error

Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
Copilot AI review requested due to automatic review settings February 8, 2026 14:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.

- Remove `default_value="true"` from `--list` flag
- Replace panic with default branch listing behavior when no arguments provided
- Aligns with Git behavior: `libra branch` now lists local branches by default

Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
Copilot AI review requested due to automatic review settings February 9, 2026 02:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.

Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
…parsing

Signed-off-by: chimes-of-freedom <yaoshunyu@whu.edu.cn>
@chimes-of-freedom
Copy link
Contributor Author

@genedna 您好,GitHub 的自动检查似乎有问题,buck2 build //:libra 无法通过,但我在本地能成功编译。麻烦您手动编译一下。谢谢!

@genedna genedna merged commit f5eab37 into web3infra-foundation:main Feb 10, 2026
18 of 20 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.

2 participants