Skip to main content

Module started_as_git

Module started_as_git 

Source
Expand description

The marker every real-Git start carries and the check that stops a wrapper which finds it was started as Git. What: The marker that every start of the real Git carries, and the check that stops a cli-git executable which finds it was started as that Git. Why: Which file the wrapper selected as Git can be a launcher, a link, a copy or another release of the wrapper, and no test of that file can recognise every one of them. What no spelling hides is the start itself: the wrapper that starts “Git” puts its own process number, that process’s birth identity and the way it starts the program (replacing itself or as a child) in the environment of the start. A cli-git executable that finds itself in the very process, or the child, that a wrapper started as Git has been started as Git, whatever stood in between, and stops at once. Anything started further down (a hook, an alias, an editor a real Git started) has another process in between and passes: running git there through an installed wrapper stays legitimate.

In TS you’d write (pseudocode):

// child_process.spawn(realGit, args, { env: { ...env, CLI_GIT_STARTED_AS_GIT: `${process.pid}\x1f${identity}\x1fchild` } });
// if (marker && marker.pid === process.ppid && sameBirth(marker)) { stop('started as Git by a cli-git process'); }

Structs§

ProcessFacts
What: What the check asks of the live process. &dyn Fn(u32) -> Option<String> borrows any function from a process number to its birth identity. Why: A control hands the check made-up numbers and identities; production hands it the process’s own facts.
StartMarker
What: What a marker says, taken apart. u32 is an unsigned 32-bit integer (siblings u64, i32): the type of a Linux process number. String is owned text (sibling &str, a borrowed view). Why: The check compares these three facts with the live process; keeping them in one value lets a test hand the check a marker without touching the real environment.

Enums§

StartMode
What: How the process that starts “Git” starts it. #[derive(...)] generates copying, debug printing and ==. Why: The two ways leave different traces. A replaced process keeps its number, so the started program is the very process the marker names; a child has the starter as its parent. The check looks at the trace its mode leaves and nowhere else.

Constants§

STARTED_AS_GIT_VARIABLE
What: The name of the marker variable. &str is a borrowed text baked into the program (owned sibling: String). Why: Every start of the real Git sets it, and every wrapper start reads it.

Functions§

mark_real_git_start
What: Put the marker in the environment of a real-Git start. &mut Command lends the builder for changing. Why: Every place that starts the real Git calls this, so a wrapper that arrives as Git can tell. Command::env overrides an earlier value of the same name, so a start that replaces the process can override the child marker that the shared builder put there.
marker_of
What: The marker of an environment, if it carries one. Why: The caller’s environment is passed in, never read from the process, so a control sets any value it likes.
marker_value
What: Build the marker value for a start by the process own_pid with birth identity own_identity. &str borrows the identity text; OsString is the owned value an environment holds. Why: One function writes the format and parse_marker reads it, so the two cannot drift apart.
parse_marker
What: Take a marker value apart. Option<StartMarker> is “the marker, or nothing when the text is not one”. Why: A variable some other program set to other text must not stop a wrapper, so anything that is not exactly three fields of the right kinds is no marker.
refusal_text
What: The words a person reads when a cli-git executable stops because it was started as Git. &Path borrows this executable’s path for the message. Why: The message names the executable, the process that started it and how, the Git that process chose when the environment says so, the PATH this process saw, why stopping is right, and every way out.
refusal_when_started_as_git
What: Whether this process was started as Git by a cli-git wrapper, read from the live process, and if so the words to say so. Option<String> is “the message, or nothing when this process was not started as Git”. Why: The executable calls it once, before it plans anything. It reads the parent’s number and, only when the marker’s number matches, one small process file for the birth identity, so an ordinary start costs a variable lookup.
started_as_git
What: Whether the marker names the process this one was started by, in the way its mode says. Why: Replace: the starter replaced itself, so this is that very process (same number, same birth). Child: the starter ran this program as its child, so the starter is this process’s parent. In both a identity the platform can read must agree, so a later process that reuses the number is not taken for the starter. A process further down has another process in between and is not the start.