dcb0fb74c5
- 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
44 lines
1.5 KiB
Rust
44 lines
1.5 KiB
Rust
use crate::bare::GitBare;
|
|
use crate::error::{GitError, GitResult};
|
|
use crate::pb::{GetTreeRequest, ListTreeRequest, Tree};
|
|
|
|
impl GitBare {
|
|
pub fn get_tree(&self, request: GetTreeRequest) -> GitResult<Tree> {
|
|
let entries = self.list_tree(ListTreeRequest {
|
|
repository: request.repository,
|
|
revision: request.revision.clone(),
|
|
path: request.path.clone(),
|
|
recursive: false,
|
|
pagination: None,
|
|
})?;
|
|
let repo = self.gix_repo()?;
|
|
let revision = request
|
|
.revision
|
|
.and_then(|s| s.selector)
|
|
.map(|s| match s {
|
|
crate::pb::object_selector::Selector::Oid(oid) => oid.hex,
|
|
crate::pb::object_selector::Selector::Revision(name) => name.revision,
|
|
})
|
|
.unwrap_or_else(|| "HEAD".into());
|
|
let root = repo
|
|
.rev_parse_single(format!("{}^{{tree}}", revision).as_str())?
|
|
.object()?
|
|
.try_into_tree()
|
|
.map_err(|e| GitError::Gix(e.to_string()))?;
|
|
let tree_hex = if request.path.is_empty() {
|
|
root.id.to_string()
|
|
} else {
|
|
root.lookup_entry_by_path(&request.path)?
|
|
.ok_or_else(|| GitError::NotFound(request.path.clone()))?
|
|
.id()
|
|
.to_string()
|
|
};
|
|
Ok(Tree {
|
|
oid: Some(self.oid_to_pb(tree_hex)),
|
|
path: request.path,
|
|
entries: entries.entries,
|
|
truncated: false,
|
|
})
|
|
}
|
|
}
|