Files
gitks/tree/find_files.rs
T
zhenyi cc202d6d1f feat(server): add tracing spans and caching to archive and blame services
- Add tracing spans with repo labels for archive and blame operations
- Implement caching for archive list entries when using OID selectors
- Implement caching for blame operations when using OID selectors
- Add detailed
2026-06-04 15:33:16 +08:00

61 lines
2.3 KiB
Rust

use crate::bare::GitBare;
use crate::error::GitResult;
use crate::paginate;
use crate::pb::{
FileMetadata, FindFilesRequest, FindFilesResponse, ListTreeRequest, ObjectType, tree_entry,
};
impl GitBare {
pub fn find_files(&self, request: FindFilesRequest) -> GitResult<FindFilesResponse> {
let revision = request.revision.clone();
let root = if request.pathspec.is_empty() {
vec![String::new()]
} else {
request.pathspec.clone()
};
let mut files = Vec::new();
for pathspec in root {
let response = self.list_tree(ListTreeRequest {
repository: request.repository.clone(),
revision: revision.clone(),
path: pathspec,
recursive: true,
pagination: None,
})?;
for entry in response.entries {
if !request.pattern.is_empty() && !entry.path.contains(&request.pattern) {
continue;
}
let object_type = match tree_entry::EntryType::try_from(entry.r#type)
.unwrap_or(tree_entry::EntryType::TreeEntryTypeUnspecified)
{
tree_entry::EntryType::TreeEntryTypeTree => ObjectType::Tree,
tree_entry::EntryType::TreeEntryTypeCommit => ObjectType::Commit,
tree_entry::EntryType::TreeEntryTypeUnspecified => ObjectType::Unspecified,
_ => ObjectType::Blob,
} as i32;
// recent_commit is NOT computed here to avoid N subprocess calls.
// Use get_file_metadata for per-file commit info.
files.push(FileMetadata {
path: entry.path,
oid: entry.oid,
mode: entry.mode,
size: entry.size,
r#type: object_type,
binary: false,
is_lfs: false,
recent_commit: None,
});
}
}
files.sort_by(|a, b| a.path.cmp(&b.path));
let (files, page_info) = paginate::paginate(&files, request.pagination.as_ref());
Ok(FindFilesResponse {
files,
page_info: Some(page_info),
})
}
}