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
39 lines
1.4 KiB
Rust
39 lines
1.4 KiB
Rust
use gix::object::tree::EntryKind;
|
|
|
|
use crate::bare::GitBare;
|
|
use crate::error::{GitError, GitResult};
|
|
use crate::pb::{FileMetadata, GetFileMetadataRequest, ObjectType, object_selector};
|
|
|
|
impl GitBare {
|
|
pub fn get_file_metadata(&self, request: GetFileMetadataRequest) -> GitResult<FileMetadata> {
|
|
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 tree = repo
|
|
.rev_parse_single(format!("{}^{{tree}}", revision).as_str())?
|
|
.object()?
|
|
.try_into_tree()
|
|
.map_err(|e| GitError::Gix(e.to_string()))?;
|
|
let entry = tree
|
|
.lookup_entry_by_path(&request.path)?
|
|
.ok_or_else(|| GitError::NotFound(request.path.clone()))?;
|
|
let hex = entry.id().to_string();
|
|
let kind = match entry.mode().kind() {
|
|
EntryKind::Tree => ObjectType::Tree,
|
|
EntryKind::Commit => ObjectType::Commit,
|
|
_ => ObjectType::Blob,
|
|
} as i32;
|
|
Ok(FileMetadata {
|
|
path: request.path,
|
|
oid: Some(self.oid_to_pb(hex)),
|
|
mode: u32::from_str_radix(&format!("{:o}", entry.mode()), 8).unwrap_or(0),
|
|
size: 0,
|
|
r#type: kind,
|
|
binary: false,
|
|
})
|
|
}
|
|
}
|