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,86 @@
|
||||
use crate::bare::GitBare;
|
||||
use crate::error::{GitError, GitResult};
|
||||
use crate::paginate;
|
||||
use crate::pb::{GetCommitRequest, ListCommitsRequest, ListCommitsResponse, object_selector};
|
||||
|
||||
impl GitBare {
|
||||
pub fn list_commits(&self, request: ListCommitsRequest) -> GitResult<ListCommitsResponse> {
|
||||
let revision = match request.revision.clone().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 mut args = vec![
|
||||
"--git-dir".to_string(),
|
||||
self.bare_dir.to_string_lossy().into_owned(),
|
||||
"rev-list".into(),
|
||||
];
|
||||
if request.first_parent {
|
||||
args.push("--first-parent".into());
|
||||
}
|
||||
if request.reverse {
|
||||
args.push("--reverse".into());
|
||||
}
|
||||
if request.max_parents > 0 {
|
||||
args.push(format!("--max-parents={}", request.max_parents));
|
||||
}
|
||||
if request.min_parents > 0 {
|
||||
args.push(format!("--min-parents={}", request.min_parents));
|
||||
}
|
||||
if let Some(since) = request.since.as_ref() {
|
||||
args.push(format!("--since=@{}", since.seconds));
|
||||
}
|
||||
if let Some(until) = request.until.as_ref() {
|
||||
args.push(format!("--until=@{}", until.seconds));
|
||||
}
|
||||
if request.all {
|
||||
args.push("--all".into());
|
||||
} else {
|
||||
args.push(revision);
|
||||
}
|
||||
if !request.path.is_empty() {
|
||||
args.push("--".into());
|
||||
args.push(request.path.clone());
|
||||
}
|
||||
|
||||
let result = duct::cmd("git", &args)
|
||||
.stdout_capture()
|
||||
.stderr_capture()
|
||||
.unchecked()
|
||||
.run()?;
|
||||
if !result.status.success() {
|
||||
return Err(GitError::CommandFailed {
|
||||
status_code: result.status.code(),
|
||||
stderr: String::from_utf8_lossy(&result.stderr).into_owned(),
|
||||
});
|
||||
}
|
||||
|
||||
let ids = String::from_utf8_lossy(&result.stdout)
|
||||
.lines()
|
||||
.map(str::trim)
|
||||
.filter(|line| !line.is_empty())
|
||||
.map(ToOwned::to_owned)
|
||||
.collect::<Vec<_>>();
|
||||
let (page_ids, page_info) = paginate::paginate(&ids, request.pagination.as_ref());
|
||||
|
||||
let mut commits = Vec::with_capacity(page_ids.len());
|
||||
for id in page_ids {
|
||||
commits.push(self.get_commit(GetCommitRequest {
|
||||
repository: request.repository.clone(),
|
||||
revision: Some(crate::pb::ObjectSelector {
|
||||
selector: Some(object_selector::Selector::Revision(crate::pb::ObjectName {
|
||||
revision: id,
|
||||
})),
|
||||
}),
|
||||
include_stats: false,
|
||||
include_raw: false,
|
||||
})?);
|
||||
}
|
||||
|
||||
Ok(ListCommitsResponse {
|
||||
commits,
|
||||
page_info: Some(page_info),
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user