737e934043
- Added RecentCommit message definition with oid, subject and timestamp fields - Extended TreeEntry, Tree, and FileMetadata messages with is_lfs and recent_commit fields - Updated get_file_metadata function to include recent commit information - Added tree module import and recent_commit lookup functionality - Updated protobuf definitions to include new metadata fields - Enhanced file metadata response with LFS status and commit history
43 lines
1.6 KiB
Rust
43 lines
1.6 KiB
Rust
use gix::object::tree::EntryKind;
|
|
|
|
use crate::bare::GitBare;
|
|
use crate::error::{GitError, GitResult};
|
|
use crate::pb::{FileMetadata, GetFileMetadataRequest, ObjectType, object_selector};
|
|
use crate::tree;
|
|
|
|
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;
|
|
let rc = tree::recent_commit(self, &revision, &request.path);
|
|
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,
|
|
is_lfs: false,
|
|
recent_commit: rc,
|
|
})
|
|
}
|
|
}
|