feat(libra): Add tagging functionality for objects#1358
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
fc84fef to
db6c810
Compare
db6c810 to
1ee58a5
Compare
1ee58a5 to
1cce015
Compare
71f8940 to
f84576b
Compare
f84576b to
98384ab
Compare
98384ab to
df132ab
Compare
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces comprehensive tag functionality to the libra module, implementing the ability to create, list, delete, and show tag objects. The changes include both lightweight and annotated tag support with proper object serialization and database storage.
- Adds a new
tagcommand to the CLI with support for creating, listing, deleting, and showing tags - Implements improved object parsing for both Tag and Commit objects with better error handling
- Enhances the commit reference resolution system to support tags and remote branches
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| mercury/src/internal/object/tag.rs | Refactored Tag object parsing and added new constructor for tag creation |
| mercury/src/internal/object/commit.rs | Improved Commit object parsing with better error handling and structure |
| mercury/src/errors.rs | Enhanced error messages for InvalidCommit and InvalidTagObject |
| libra/src/internal/tag.rs | New module implementing core tag functionality (create, list, delete, find) |
| libra/src/command/tag.rs | New CLI command implementation for tag operations |
| libra/src/utils/util.rs | Enhanced get_commit_base function to resolve tags, branches, and commit hashes |
| libra/src/cli.rs | Added tag command to CLI parser |
| libra/src/internal/mod.rs | Added tag module to internal modules |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| fn get_size(&self) -> usize { | ||
| todo!() | ||
| self.to_data().map(|data| data.len()).unwrap_or(0) |
There was a problem hiding this comment.
Using unwrap_or(0) masks potential errors in to_data(). Consider returning a Result<usize, GitError> from get_size() or handling the error more explicitly to provide better error information to callers.
| SHA1::from_str(tree_str.to_str().map_err(|e| { | ||
| GitError::InvalidCommit(format!("Invalid UTF-8 in tree SHA: {}", e)) | ||
| })?) | ||
| .map_err(|e| GitError::InvalidCommit(format!("Invalid tree SHA: {}", e)))?, | ||
| ); | ||
| } else if let Some(parent_str) = line.strip_prefix(b"parent ") { | ||
| parent_commit_ids.push( | ||
| SHA1::from_str(parent_str.to_str().map_err(|e| { | ||
| GitError::InvalidCommit(format!("Invalid UTF-8 in parent SHA: {}", e)) |
There was a problem hiding this comment.
The parsing logic creates new error messages for each UTF-8 conversion failure. Consider pre-allocating static error messages or using more efficient error creation to reduce allocations during parsing.
| SHA1::from_str(tree_str.to_str().map_err(|e| { | |
| GitError::InvalidCommit(format!("Invalid UTF-8 in tree SHA: {}", e)) | |
| })?) | |
| .map_err(|e| GitError::InvalidCommit(format!("Invalid tree SHA: {}", e)))?, | |
| ); | |
| } else if let Some(parent_str) = line.strip_prefix(b"parent ") { | |
| parent_commit_ids.push( | |
| SHA1::from_str(parent_str.to_str().map_err(|e| { | |
| GitError::InvalidCommit(format!("Invalid UTF-8 in parent SHA: {}", e)) | |
| SHA1::from_str(tree_str.to_str().map_err(|_| { | |
| GitError::InvalidCommit("Invalid UTF-8 in tree SHA".to_string()) | |
| })?) | |
| .map_err(|e| GitError::InvalidCommit(format!("Invalid tree SHA: {}", e)))?, | |
| ); | |
| } else if let Some(parent_str) = line.strip_prefix(b"parent ") { | |
| parent_commit_ids.push( | |
| SHA1::from_str(parent_str.to_str().map_err(|_| { | |
| GitError::InvalidCommit("Invalid UTF-8 in parent SHA".to_string()) |
| let tag_obj: mercury::internal::object::tag::Tag = | ||
| match crate::command::load_object(&object_id) { | ||
| Ok(obj) => obj, | ||
| Err(e) => return Err(format!("fatal: failed to load tag object: {}", e)), |
There was a problem hiding this comment.
The error message 'fatal: failed to load tag object' doesn't provide specific information about what went wrong. Consider including the tag object hash and the underlying error details to help with debugging.
| let tag_obj: mercury::internal::object::tag::Tag = | |
| match crate::command::load_object(&object_id) { | |
| Ok(obj) => obj, | |
| Err(e) => return Err(format!("fatal: failed to load tag object: {}", e)), | |
| Err(e) => return Err(format!("fatal: failed to load tag object {}: {}", object_id, e)), |
| if object.get_type() == ObjectType::Tag { | ||
| // Access the tag data directly from the object if it is a Tag variant. | ||
| if let tag::TagObject::Tag(tag_object) = &object { | ||
| println!("tag {}", tag_object.tag_name); | ||
| println!("Tagger: {}", tag_object.tagger.to_string().trim()); | ||
| println!("\n{}", tag_object.message); | ||
| } else { | ||
| eprintln!("fatal: object is not a Tag variant"); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| println!("\ncommit {}", commit.id); | ||
| println!("Author: {}", commit.author.to_string().trim()); | ||
| let commit_date = | ||
| chrono::DateTime::from_timestamp(commit.committer.timestamp as i64, 0) | ||
| .unwrap_or(chrono::DateTime::UNIX_EPOCH); | ||
| println!("Date: {}", commit_date.to_rfc2822()); | ||
| println!("\n {}", commit.message.trim()); |
There was a problem hiding this comment.
The logic assumes that if an object is not a Tag type, it should still display commit information. This could lead to confusing output for other object types. Consider adding explicit handling for all object types or warning when the object type is unexpected.
| if object.get_type() == ObjectType::Tag { | |
| // Access the tag data directly from the object if it is a Tag variant. | |
| if let tag::TagObject::Tag(tag_object) = &object { | |
| println!("tag {}", tag_object.tag_name); | |
| println!("Tagger: {}", tag_object.tagger.to_string().trim()); | |
| println!("\n{}", tag_object.message); | |
| } else { | |
| eprintln!("fatal: object is not a Tag variant"); | |
| return; | |
| } | |
| } | |
| println!("\ncommit {}", commit.id); | |
| println!("Author: {}", commit.author.to_string().trim()); | |
| let commit_date = | |
| chrono::DateTime::from_timestamp(commit.committer.timestamp as i64, 0) | |
| .unwrap_or(chrono::DateTime::UNIX_EPOCH); | |
| println!("Date: {}", commit_date.to_rfc2822()); | |
| println!("\n {}", commit.message.trim()); | |
| match object.get_type() { | |
| ObjectType::Tag => { | |
| // Access the tag data directly from the object if it is a Tag variant. | |
| if let tag::TagObject::Tag(tag_object) = &object { | |
| println!("tag {}", tag_object.tag_name); | |
| println!("Tagger: {}", tag_object.tagger.to_string().trim()); | |
| println!("\n{}", tag_object.message); | |
| } else { | |
| eprintln!("fatal: object is not a Tag variant"); | |
| return; | |
| } | |
| println!("\ncommit {}", commit.id); | |
| println!("Author: {}", commit.author.to_string().trim()); | |
| let commit_date = | |
| chrono::DateTime::from_timestamp(commit.committer.timestamp as i64, 0) | |
| .unwrap_or(chrono::DateTime::UNIX_EPOCH); | |
| println!("Date: {}", commit_date.to_rfc2822()); | |
| println!("\n {}", commit.message.trim()); | |
| } | |
| ObjectType::Commit => { | |
| println!("commit {}", commit.id); | |
| println!("Author: {}", commit.author.to_string().trim()); | |
| let commit_date = | |
| chrono::DateTime::from_timestamp(commit.committer.timestamp as i64, 0) | |
| .unwrap_or(chrono::DateTime::UNIX_EPOCH); | |
| println!("Date: {}", commit_date.to_rfc2822()); | |
| println!("\n {}", commit.message.trim()); | |
| } | |
| other => { | |
| eprintln!("fatal: unexpected object type '{:?}' for tag '{}'", other, tag_name); | |
| } | |
| } |
081bd1c to
9d6daff
Compare
6bdaf3d to
3ad12a9
Compare
b69ea04 to
5365a5b
Compare
5365a5b to
c67c3dd
Compare
c67c3dd to
6450a54
Compare
6450a54 to
f2091df
Compare
a6fc838 to
e4121cc
Compare
e4121cc to
005e755
Compare
This commit introduces the ability to add, remove, and list tags on objects within the libra module. It adds a new tag command and the corresponding internal logic for tag management. 此 PR 完成了 r2cn 测试任务 gitmono-dev#1352 Signed-off-by: allure <1550220889@qq.com>
|
@genedna xian现在还是这样的报错,提交很多次也都是这样的问题 |
|
@AllureCurtain , 你先用 #1352 这个 Issue 进行下一步注册,我来研究一下这个问题。 |
|
@genedna 谢谢老师,我现在是研一刚开学,学信网信息还没有更新,我可以过几天再完成后面的注册吗 |
现在注册的话,你可以用录取通知书进行注册,等学信网信息有了以后再进行更新;同时,你可以开始研究目前 r2cn 支持的几个项目,找到你感兴趣的任务方向后邮件 genedna@qq.com 联系我 |


This commit introduces the ability to add, remove, and list tags on objects within the libra module. It adds a new
tagcommand and the corresponding internal logic for tag management.此 PR 完成了 r2cn 测试任务 #1352