feat(core): implement Git repository operations with gRPC services
- 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
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
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;
|
||||
files.push(FileMetadata {
|
||||
path: entry.path,
|
||||
oid: entry.oid,
|
||||
mode: entry.mode,
|
||||
size: entry.size,
|
||||
r#type: object_type,
|
||||
binary: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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),
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user