feat(api): extend commit and diff services with new functionality
- Add FindCommit, ListCommitsByOid, CommitIsAncestor RPCs to CommitService - Add CheckObjectsExist, CommitsByMessage, GetCommitStats RPCs to CommitService - Add LastCommitForPath, CountCommits, CountDivergingCommits RPCs to CommitService - Add RawDiff, RawPatch, FindChangedPaths RPCs to DiffService - Add FindMergeBase, WriteRef, SearchFilesByContent RPCs to RepositoryService - Add SearchFilesByName, ObjectsSize, RepositorySize RPCs to RepositoryService - Add FindLicense, OptimizeRepository, GetRawChanges RPCs to RepositoryService - Add FetchRemote, CreateRepositoryFromURL RPCs to RepositoryService - Implement server handlers for all new RPC methods - Add new modules for commit counting, finding, and querying features - Add new modules for diff changed paths and raw operations - Add new modules for refs and remote operations - Remove unnecessary comments from various source files - Update proto definitions with new message types and service methods
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
use crate::bare::GitBare;
|
||||
use crate::error::{GitError, GitResult};
|
||||
use crate::pb::*;
|
||||
|
||||
impl GitBare {
|
||||
/// Find a single commit by revision.
|
||||
pub fn find_commit(&self, request: FindCommitRequest) -> GitResult<Commit> {
|
||||
let revision = match request.revision.and_then(|s| s.selector) {
|
||||
Some(object_selector::Selector::Oid(oid)) => oid.hex,
|
||||
Some(object_selector::Selector::Revision(name)) => name.revision,
|
||||
None => "HEAD".to_string(),
|
||||
};
|
||||
crate::sanitize::validate_revision(&revision)?;
|
||||
|
||||
let repo = self.gix_repo()?;
|
||||
let oid = repo.rev_parse_single(revision.as_str())
|
||||
.map_err(|e| GitError::Gix(e.to_string()))?;
|
||||
let commit = oid.object()
|
||||
.map_err(|e| GitError::Gix(e.to_string()))?
|
||||
.try_into_commit()
|
||||
.map_err(|e| GitError::Gix(format!("not a commit: {e}")))?;
|
||||
|
||||
Ok(crate::commit::get_commit::commit_to_pb(self, &commit, request.include_stats))
|
||||
}
|
||||
|
||||
/// Batch lookup commits by OID list.
|
||||
pub fn list_commits_by_oid(&self, request: ListCommitsByOidRequest) -> GitResult<ListCommitsByOidResponse> {
|
||||
let repo = self.gix_repo()?;
|
||||
let mut commits = Vec::new();
|
||||
|
||||
for oid_bytes in &request.oids {
|
||||
let hex: String = oid_bytes.iter().map(|b| format!("{b:02x}")).collect();
|
||||
if let Ok(oid) = gix::ObjectId::from_hex(hex.as_bytes()) {
|
||||
if let Ok(obj) = repo.find_object(oid) {
|
||||
if let Ok(commit) = obj.try_into_commit() {
|
||||
commits.push(crate::commit::get_commit::commit_to_pb(self, &commit, request.include_stats));
|
||||
}
|
||||
}
|
||||
}
|
||||
if commits.len() >= 100 { break; }
|
||||
}
|
||||
|
||||
Ok(ListCommitsByOidResponse { commits })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user