dcb0fb74c5
- Add advertise_refs functionality for Git protocol communication - Implement archive service with TAR/ZIP format support and streaming - Create blame service for Git file annotation with line tracking - Add branch management including create, delete, rename and compare operations - Implement merge checking with conflict detection and fast-forward handling - Add cherry-pick functionality for applying commits between branches - Integrate gix library for Git repository operations and object handling - Add comprehensive test suite covering all Git operations - Implement proper error handling and repository validation - Add pagination support for large result sets - Create protobuf definitions for all Git operations and data structures - Add build system for gRPC code generation and dependency management
77 lines
2.8 KiB
Rust
77 lines
2.8 KiB
Rust
use crate::bare::GitBare;
|
|
use crate::error::{GitError, GitResult};
|
|
use crate::pb::{Commit, GetCommitRequest, object_selector};
|
|
|
|
impl GitBare {
|
|
pub fn get_commit(&self, request: GetCommitRequest) -> GitResult<Commit> {
|
|
let repo = self.gix_repo()?;
|
|
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".into(),
|
|
};
|
|
let id = repo.rev_parse_single(revision.as_str())?;
|
|
let commit = id
|
|
.object()?
|
|
.try_into_commit()
|
|
.map_err(|e| GitError::Gix(e.to_string()))?;
|
|
let hex = commit.id.to_string();
|
|
let tree_hex = commit.tree_id()?.to_string();
|
|
let message = commit.message_raw()?.to_string();
|
|
let (subject, body) = message
|
|
.split_once('\n')
|
|
.map(|(s, b)| (s.to_string(), b.trim_start_matches('\n').to_string()))
|
|
.unwrap_or_else(|| (message.clone(), String::new()));
|
|
let author_sig = commit.author().ok();
|
|
let committer_sig = commit.committer().ok();
|
|
Ok(Commit {
|
|
oid: Some(self.oid_to_pb(hex.clone())),
|
|
abbreviated_oid: commit
|
|
.short_id()
|
|
.map(|s| s.to_string())
|
|
.unwrap_or_else(|_| hex.chars().take(7).collect()),
|
|
parent_oids: commit
|
|
.parent_ids()
|
|
.map(|p| self.oid_to_pb(p.to_string()))
|
|
.collect(),
|
|
tree_oid: Some(self.oid_to_pb(tree_hex)),
|
|
author: author_sig.as_ref().map(gix_sig_to_pb),
|
|
committer: committer_sig.as_ref().map(gix_sig_to_pb),
|
|
subject,
|
|
body,
|
|
message,
|
|
trailers: Vec::new(),
|
|
signature: None,
|
|
stats: None,
|
|
authored_at: author_sig.as_ref().map(|s| prost_types::Timestamp {
|
|
seconds: s.seconds(),
|
|
nanos: 0,
|
|
}),
|
|
committed_at: committer_sig.as_ref().map(|s| prost_types::Timestamp {
|
|
seconds: s.seconds(),
|
|
nanos: 0,
|
|
}),
|
|
raw: if request.include_raw {
|
|
commit.data.clone()
|
|
} else {
|
|
Vec::new()
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|
|
pub(crate) fn gix_sig_to_pb(sig: &gix::actor::SignatureRef<'_>) -> crate::pb::Signature {
|
|
let time = sig.time().ok();
|
|
crate::pb::Signature {
|
|
identity: Some(crate::pb::Identity {
|
|
name: sig.name.to_string(),
|
|
email: sig.email.to_string(),
|
|
}),
|
|
when: Some(prost_types::Timestamp {
|
|
seconds: sig.seconds(),
|
|
nanos: 0,
|
|
}),
|
|
timezone_offset: time.map(|t| t.offset / 60).unwrap_or(0),
|
|
}
|
|
}
|