9a0c26e5f6
- Add voting mechanism with term tracking and vote persistence - Implement election triggering logic with majority vote counting - Add primary/replica role transition handling with state management - Integrate health check failure detection for automatic elections - Refactor actor messaging system for distributed coordination - Update repository registration to query cluster for existing primary - Add broadcast mechanism for role change notifications - Implement proper term comparison and duplicate request filtering - Upgrade dependency versions including tokio-util for async utilities - Optimize code formatting and line wrapping for improved readability - Remove redundant blank lines and improve code structure consistency - Enhance error logging and trace information for debugging purposes
61 lines
2.0 KiB
Rust
61 lines
2.0 KiB
Rust
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 })
|
|
}
|
|
}
|