Files
gitks/tree/mod.rs
T
zhenyi 737e934043 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
2026-06-04 13:47:46 +08:00

51 lines
1.5 KiB
Rust

pub mod find_files;
pub mod get_file_metadata;
pub mod get_tree;
pub mod list_tree;
use crate::bare::GitBare;
use crate::pb::{self, RecentCommit, object_selector};
pub(crate) fn resolve_revision(sel: &Option<pb::ObjectSelector>) -> String {
match sel.as_ref().and_then(|s| s.selector.as_ref()) {
Some(object_selector::Selector::Oid(oid)) => oid.hex.clone(),
Some(object_selector::Selector::Revision(name)) => name.revision.clone(),
None => "HEAD".into(),
}
}
pub(crate) fn recent_commit(gb: &GitBare, revision: &str, path: &str) -> Option<RecentCommit> {
let output = std::process::Command::new("git")
.args([
"--git-dir",
&gb.bare_dir.to_string_lossy(),
"log",
"-1",
"--format=%H %s %at",
revision,
"--",
path,
])
.output()
.ok()?;
if !output.status.success() {
return None;
}
let line = String::from_utf8_lossy(&output.stdout).trim().to_string();
if line.is_empty() {
return None;
}
let (hex, rest) = line.split_once(' ')?;
let (subject, ts_str) = rest.rsplit_once(' ')?;
let ts: i64 = ts_str.parse().ok()?;
Some(RecentCommit {
oid: Some(gb.oid_to_pb(hex)),
subject: subject.to_string(),
committed_timestamp: ts,
})
}
pub(crate) fn is_lfs_pointer(data: &[u8]) -> bool {
data.starts_with(b"version https://git-lfs.github.com/spec/v1")
}