feat(tree): add recent commit metadata and LFS support to file metadata

- 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
This commit is contained in:
zhenyi
2026-06-04 13:47:46 +08:00
parent dcb0fb74c5
commit 737e934043
8 changed files with 83 additions and 9 deletions
+7 -6
View File
@@ -2,11 +2,13 @@ use gix::object::tree::EntryKind;
use crate::bare::GitBare;
use crate::error::{GitError, GitResult};
use crate::pb::{Blob, GetBlobRequest, object_selector};
use crate::pb::{Blob, GetBlobRequest};
use crate::tree;
impl GitBare {
pub fn get_blob(&self, request: GetBlobRequest) -> GitResult<Blob> {
let repo = self.gix_repo()?;
let revision = tree::resolve_revision(&request.revision);
let (blob, mode, path) = if let Some(oid) = request.oid.as_ref() {
let id = gix::hash::ObjectId::from_hex(oid.hex.as_bytes())
.map_err(|e| GitError::InvalidOid(e.to_string()))?;
@@ -18,11 +20,6 @@ impl GitBare {
request.path,
)
} else {
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()?
@@ -56,6 +53,8 @@ impl GitBare {
data.truncate(request.max_bytes as usize);
}
let hex = blob.id.to_string();
let lfs = tree::is_lfs_pointer(&data);
let rc = tree::recent_commit(self, &revision, &path);
Ok(Blob {
oid: Some(self.oid_to_pb(hex)),
path,
@@ -65,6 +64,8 @@ impl GitBare {
encoding: String::new(),
truncated,
data,
is_lfs: lfs,
recent_commit: rc,
})
}
}