Skip to main content

Module forwarding

Module forwarding 

Source
Expand description

Starting real Git with unchanged arguments, streams and exit status. What: Start real Git with the caller’s exact arguments, streams and environment. Why: The wrapper adds policy around Git; it must never change what Git receives or what the caller observes from Git.

In TS you’d write (pseudocode):

// spawn(gitPath, args, { stdio: 'inherit', env }) and exit with the child's status.

Enums§

ChildOutcome
What: How a Git child ended. i32 is a signed 32-bit integer, the type of exit codes and signal numbers (siblings u8, i64). Why: A child killed by a signal has no exit code; callers need both cases to report Git’s result faithfully. i32 is what the operating system returns.

Functions§

exit_code
What: Translate a child’s end into this process’s exit code. Why: Git 2.56.0 run-command.c reports a child killed by signal N as 128 + N, which is also what a POSIX shell reports; an exit code passes through.
git_command
What: Build the child command: program, unchanged arguments, added variables. &[OsString] borrows the argument list; &[(OsString, OsString)] borrows name/value pairs. Why: One builder guarantees every real-Git start, forwarded or queried, uses an argument array (no shell string) and inherits the caller’s environment plus only the overlay.
replace_process_with_real_git
What: Become real Git; returns only when Git could not be started. The returned std::io::Error says why the operating system refused. #[cfg(unix)] and #[cfg(not(unix))] each compile one of the two inner blocks. Why: On Unix this process is replaced by Git, which is exact forwarding: same process ID, same streams, same signals, same exit status, and no wrapper process left between the caller and Git. Windows cannot replace a process image; the nearest faithful behaviour there is to wait for Git and exit with its status.
run_real_git
What: Run real Git as a child with inherited stdin, stdout and stderr, and wait. std::io::Result<T> is Result<T, std::io::Error>. Why: Callers that must do work after Git returns (post-commit policies, status notes) need the wrapper process to survive Git. The child shares the caller’s terminal and streams directly; nothing is buffered or copied. This path installs no signal handlers: a signal sent to the wrapper alone does not reach Git, exactly as with the TypeScript wrapper.