feat(api): extend commit and diff services with new functionality
- Add FindCommit, ListCommitsByOid, CommitIsAncestor RPCs to CommitService - Add CheckObjectsExist, CommitsByMessage, GetCommitStats RPCs to CommitService - Add LastCommitForPath, CountCommits, CountDivergingCommits RPCs to CommitService - Add RawDiff, RawPatch, FindChangedPaths RPCs to DiffService - Add FindMergeBase, WriteRef, SearchFilesByContent RPCs to RepositoryService - Add SearchFilesByName, ObjectsSize, RepositorySize RPCs to RepositoryService - Add FindLicense, OptimizeRepository, GetRawChanges RPCs to RepositoryService - Add FetchRemote, CreateRepositoryFromURL RPCs to RepositoryService - Implement server handlers for all new RPC methods - Add new modules for commit counting, finding, and querying features - Add new modules for diff changed paths and raw operations - Add new modules for refs and remote operations - Remove unnecessary comments from various source files - Update proto definitions with new message types and service methods
This commit is contained in:
+89
@@ -0,0 +1,89 @@
|
||||
use crate::bare::GitBare;
|
||||
use crate::error::GitResult;
|
||||
use crate::pb::*;
|
||||
|
||||
impl GitBare {
|
||||
/// Stream raw diff output.
|
||||
pub fn raw_diff(&self, request: RawDiffRequest) -> GitResult<Vec<RawDiffResponse>> {
|
||||
let base = &request.base;
|
||||
let head = &request.head;
|
||||
crate::sanitize::validate_revision(base)?;
|
||||
crate::sanitize::validate_revision(head)?;
|
||||
|
||||
let mut args = vec![
|
||||
"--git-dir".to_string(),
|
||||
self.bare_dir.to_string_lossy().into_owned(),
|
||||
"diff".to_string(),
|
||||
];
|
||||
|
||||
// Apply options if present
|
||||
if let Some(ref opts) = request.options {
|
||||
if opts.recursive { args.push("--recursive".to_string()); }
|
||||
if opts.include_binary {
|
||||
args.push("--binary".to_string());
|
||||
} else {
|
||||
args.push("--no-binary".to_string());
|
||||
}
|
||||
for ps in &opts.pathspec {
|
||||
args.push("--".to_string());
|
||||
args.push(ps.clone());
|
||||
}
|
||||
}
|
||||
|
||||
args.push(base.clone());
|
||||
args.push(head.clone());
|
||||
|
||||
let output = std::process::Command::new("git")
|
||||
.args(&args)
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.stderr(std::process::Stdio::piped())
|
||||
.output()
|
||||
.map_err(|e| crate::error::GitError::CommandFailed {
|
||||
status_code: None,
|
||||
stderr: e.to_string(),
|
||||
})?;
|
||||
|
||||
// Chunk the output for streaming
|
||||
const CHUNK_SIZE: usize = 32768;
|
||||
let data = output.stdout;
|
||||
let chunks: Vec<RawDiffResponse> = data
|
||||
.chunks(CHUNK_SIZE)
|
||||
.map(|c| RawDiffResponse { data: c.to_vec() })
|
||||
.collect();
|
||||
|
||||
Ok(chunks)
|
||||
}
|
||||
|
||||
/// Stream raw patch (format-patch) output.
|
||||
pub fn raw_patch(&self, request: RawPatchRequest) -> GitResult<Vec<RawPatchResponse>> {
|
||||
crate::sanitize::validate_revision(&request.base)?;
|
||||
crate::sanitize::validate_revision(&request.head)?;
|
||||
|
||||
let range = format!("{}..{}", request.base, request.head);
|
||||
|
||||
let output = std::process::Command::new("git")
|
||||
.args([
|
||||
"--git-dir",
|
||||
&self.bare_dir.to_string_lossy(),
|
||||
"format-patch",
|
||||
"--stdout",
|
||||
&range,
|
||||
])
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.stderr(std::process::Stdio::piped())
|
||||
.output()
|
||||
.map_err(|e| crate::error::GitError::CommandFailed {
|
||||
status_code: None,
|
||||
stderr: e.to_string(),
|
||||
})?;
|
||||
|
||||
const CHUNK_SIZE: usize = 32768;
|
||||
let data = output.stdout;
|
||||
let chunks: Vec<RawPatchResponse> = data
|
||||
.chunks(CHUNK_SIZE)
|
||||
.map(|c| RawPatchResponse { data: c.to_vec() })
|
||||
.collect();
|
||||
|
||||
Ok(chunks)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user