45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
//! Copyright (c) 2022-2026 GitDataAi All rights reserved.
|
|
|
|
use crate::bare::GitBare;
|
|
use crate::error::{GitError, GitResult};
|
|
use crate::pb::{GetPatchRequest, GetPatchResponse};
|
|
use crate::resolve_revision;
|
|
|
|
const MAX_PATCH_BYTES: usize = 64 * 1024 * 1024;
|
|
|
|
impl GitBare {
|
|
pub fn get_patch(&self, request: GetPatchRequest) -> GitResult<Vec<GetPatchResponse>> {
|
|
let base = resolve_revision!(request.base);
|
|
let head = resolve_revision!(request.head);
|
|
let result = duct::cmd(
|
|
"git",
|
|
[
|
|
"--git-dir",
|
|
self.bare_dir.to_string_lossy().as_ref(),
|
|
"diff",
|
|
"--patch",
|
|
&base,
|
|
&head,
|
|
],
|
|
)
|
|
.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(),
|
|
});
|
|
}
|
|
if result.stdout.len() > MAX_PATCH_BYTES {
|
|
return Err(GitError::InvalidArgument(format!(
|
|
"patch output too large (max {MAX_PATCH_BYTES} bytes)"
|
|
)));
|
|
}
|
|
Ok(vec![GetPatchResponse {
|
|
data: result.stdout,
|
|
}])
|
|
}
|
|
}
|