此 PR 完成了 r2cn 测试任务 #1197,新增 -p / --patch 参数到 libra log 命令。#1375
Conversation
Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull Request Overview
This PR implements the -p/--patch parameter for the libra log command to display diffs for each commit, similar to Git's git log -p functionality. It also fixes a bug where the executable binary itself was being added to the staging area when using libra add -A or libra add ..
- Added
-p/--patchflag to show commit diffs with optional file path filtering - Implemented diff generation logic that reuses existing
generate_difffunctionality - Fixed
libra addto exclude the running executable from staging when adding all files
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| libra/src/command/log.rs | Adds patch parameter and diff generation logic for log command |
| libra/src/command/add.rs | Fixes bug preventing executable from being added to staging area |
| libra/tests/command/log_test.rs | Updates test to use clap parser for LogArgs construction |
| aria/contents/docs/libra/command/log/index.mdx | Documents the new -p/--patch parameter |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| let read_content = |file: &PathBuf, hash: &SHA1| { | ||
| match load_object::<Blob>(hash) { | ||
| Ok(blob) => blob.data, | ||
| Err(_) => { | ||
| let file = util::to_workdir_path(file); | ||
| std::fs::read(&file).unwrap() | ||
| } | ||
| } | ||
| }; |
There was a problem hiding this comment.
[nitpick] The closure captures variables from the outer scope and has complex error handling. Consider extracting this into a separate function for better readability and testability.
| let read_content = |file: &PathBuf, hash: &SHA1| { | |
| match load_object::<Blob>(hash) { | |
| Ok(blob) => blob.data, | |
| Err(_) => { | |
| let file = util::to_workdir_path(file); | |
| std::fs::read(&file).unwrap() | |
| } | |
| } | |
| }; | |
| // Use the read_content function instead of a closure | |
| fn read_content(file: &PathBuf, hash: &SHA1) -> Vec<u8> { | |
| match load_object::<Blob>(hash) { | |
| Ok(blob) => blob.data, | |
| Err(_) => { | |
| let file = util::to_workdir_path(file); | |
| std::fs::read(&file).unwrap() | |
| } | |
| } | |
| } |
…or the -p parameter Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
…rs on windows Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
|
@231220075 请联系genedna@qq.com 讨论实习任务的方向,任务列表可以在https://r2cn.dev/docs/r2cn/projects 找到 |
diff 生成逻辑复用 generate_diff ,根据 pathspec 过滤文件。
修复了 libra add -A / . 把可执行文件本身加入暂存区的 bug ,使用当前可执行文件的路径进行过滤。