1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! What:
//! Running real Git against the shadow repository for replay:
//! the shadow selection, an optional private index, bytes on standard input,
//! and the caller's kept global options when a signed rebuild needs them.
//! Why:
//! Every replay step runs in `git --git-dir=<shadow>` so its objects stay in the shadow store
//! until the next migration;
//! one runner keeps the selection in one place.
//!
//! In TS you'd write (pseudocode):
//! ```ts
//! runShadowGit({ gitPath, shadowPath, args, input, environment });
//! ```
/// Shadow selection and the transaction Git runner.
use super::shadow_git::shadow_request;
use super::transaction_git::{GitContext, GitFailure, GitOutput, GitRequest, run_git_checked};
/// `OsString` names environment entries and arguments.
use std::ffi::OsString;
/// `Path`/`PathBuf` are borrowed/owned filesystem paths.
use std::path::{Path, PathBuf};
/// What:
/// Runs one shadow Git command and requires success.
/// Why:
/// Replay cannot continue after a failed `merge-base`, `hash-object` or `read-tree`;
/// the caller maps the failure to `transaction-failed`.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// await runShadowGit({ gitPath, shadowPath, args, input, environment });
/// ```
pub fn run_shadow_checked(
context: &GitContext,
shadow: &Path,
cwd: &Path,
arguments: &[&str],
input: Option<&[u8]>,
index: Option<&Path>,
environment: &[(OsString, OsString)],
) -> Result<GitOutput, GitFailure> {
let mut request: GitRequest = shadow_request(shadow, cwd, arguments);
request.input = input.map(|bytes| { return bytes.to_vec(); });
request.index = index.map(|path| { return path.to_path_buf(); });
request.environment = environment.to_vec();
return run_git_checked(context, &request);
}
/// What:
/// The private index file a replay step edits, named by the replay number.
/// Why:
/// Each replay keeps its own index under the transaction directory, so a later replay never reads an earlier one.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// join(directory, `replay-base-${replay}.index`)
/// ```
pub fn replay_base_index(directory: &Path, replay: u64) -> PathBuf {
return directory.join(format!("replay-base-{replay}.index"));
}
#[cfg(test)]
#[path = "replay_shadow_tests.rs"]
mod tests;