Skip to content

Support finding the latest commit for a file#1583

Merged
benjamin-747 merged 3 commits into
gitmono-dev:mainfrom
231220075:main
Oct 25, 2025
Merged

Support finding the latest commit for a file#1583
benjamin-747 merged 3 commits into
gitmono-dev:mainfrom
231220075:main

Conversation

@231220075

Copy link
Copy Markdown
Contributor

Extend the functionality of the get_latest_commit API to support finding the latest commit for a file

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 the get_latest_commit API to support finding the latest commit for both directories and files. Previously, the function only handled directory paths; now it falls back to file path resolution when a directory is not found.

Key Changes:

  • Restructured the function to try directory lookup first, then fall back to file lookup
  • Added file path parsing logic to extract filename and parent directory
  • Implemented blob item matching in the parent directory's commit map to find file-specific commits

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread ceres/src/api_service/mod.rs Outdated
Comment on lines +143 to +149
let mut matched_commit: Option<git_internal::internal::object::commit::Commit> = None;
for (item, commit_opt) in map.into_iter() {
if item.mode == TreeItemMode::Blob && item.name == file_name {
matched_commit = commit_opt;
break;
}
}

Copilot AI Oct 24, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Replace the manual loop with iterator methods for better readability. Use find_map to directly return the commit: let matched_commit = map.into_iter().find_map(|(item, commit_opt)| if item.mode == TreeItemMode::Blob && item.name == file_name { commit_opt } else { None });

Suggested change
let mut matched_commit: Option<git_internal::internal::object::commit::Commit> = None;
for (item, commit_opt) in map.into_iter() {
if item.mode == TreeItemMode::Blob && item.name == file_name {
matched_commit = commit_opt;
break;
}
}
let matched_commit = map.into_iter().find_map(|(item, commit_opt)| {
if item.mode == TreeItemMode::Blob && item.name == file_name {
commit_opt
} else {
None
}
});

Copilot uses AI. Check for mistakes.
Comment thread ceres/src/api_service/mod.rs Outdated
Comment on lines 134 to 138
let Some(_parent_tree) = self.search_tree_by_path(parent).await? else {
return Err(GitError::CustomError(
"can't find target parent tree under latest commit".to_string(),
));
};

Copilot AI Oct 24, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The _parent_tree variable is retrieved but not used. Since only existence is checked, consider using is_some() instead: if self.search_tree_by_path(parent).await?.is_none() { return Err(...); }

Suggested change
let Some(_parent_tree) = self.search_tree_by_path(parent).await? else {
return Err(GitError::CustomError(
"can't find target parent tree under latest commit".to_string(),
));
};
if self.search_tree_by_path(parent).await?.is_none() {
return Err(GitError::CustomError(
"can't find target parent tree under latest commit".to_string(),
));
}

Copilot uses AI. Check for mistakes.
Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>

fix reviews

Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
@benjamin-747 benjamin-747 added this pull request to the merge queue Oct 25, 2025
Merged via the queue into gitmono-dev:main with commit 61c4479 Oct 25, 2025
7 checks passed
@benjamin-747

Copy link
Copy Markdown
Collaborator

link #1562

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.

3 participants