9a0c26e5f6
- Add voting mechanism with term tracking and vote persistence - Implement election triggering logic with majority vote counting - Add primary/replica role transition handling with state management - Integrate health check failure detection for automatic elections - Refactor actor messaging system for distributed coordination - Update repository registration to query cluster for existing primary - Add broadcast mechanism for role change notifications - Implement proper term comparison and duplicate request filtering - Upgrade dependency versions including tokio-util for async utilities - Optimize code formatting and line wrapping for improved readability - Remove redundant blank lines and improve code structure consistency - Enhance error logging and trace information for debugging purposes
92 lines
2.9 KiB
Rust
92 lines
2.9 KiB
Rust
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)
|
|
}
|
|
}
|