git-ents.gitmain
⌘K
foforge
commit 0d879da
refactor: hoist the zero-oid constant and drop dead tagline()

The all-zero push oid was duplicated three times; it now lives as git_ents::ZERO_OID. tagline() had no callers.

removes: git_ents::tagline() Assisted-by: Claude:claude-opus-4-8

Joseph D. Carpinelli · 1 month ago

Reviews

No reviews of this commit yet — record a verdict below.

Start a review

verdict

crates/git-ents-server/src/checks.rs @@ -260,7 +260,6 @@ /// the `refs/meta/*` control refs (auth, the check set itself) are skipped — the /// checks gate ordinary content, not the trust plumbing. fn parse_updates(input: &str) -> Vec<Update<'_>> { - const ZERO: &str = "0000000000000000000000000000000000000000"; input .lines() .filter_map(|line| { @@ -268,7 +267,7 @@ let _old = fields.next()?; let new = fields.next()?; let ref_name = fields.next()?; - if new == ZERO || ref_name.starts_with("refs/meta/") { + if new == git_ents::ZERO_OID || ref_name.starts_with("refs/meta/") { None } else { Some(Update { new, ref_name })
crates/git-ents/src/lib.rs @@ -3,14 +3,7 @@ pub mod checks; pub mod signers; -/// Returns the tagline describing what the ents do. -/// -/// # Examples -/// -/// ``` -/// assert_eq!(git_ents::tagline(), "Helpful guardians of your git trees."); -/// ``` -#[must_use] -pub fn tagline() -> &'static str { - "Helpful guardians of your git trees." -} +/// The all-zero object id git uses for a created or deleted ref in a push +/// (`<old> <new> <ref>` lines): a zero `<old>` is a create, a zero `<new>` a +/// delete. +pub const ZERO_OID: &str = "0000000000000000000000000000000000000000";
crates/git-ents/src/main.rs @@ -460,8 +460,10 @@ /// `--force-if-includes`, makes the update a clean compare-and-swap: it is /// rejected rather than clobbering a set someone changed since the fetch. fn push_auth(remote: &str, expected: Option<&str>) -> Result<(), String> { - const ZERO: &str = "0000000000000000000000000000000000000000"; - let lease = format!("--force-with-lease={AUTH_REF}:{}", expected.unwrap_or(ZERO)); + let lease = format!( + "--force-with-lease={AUTH_REF}:{}", + expected.unwrap_or(git_ents::ZERO_OID) + ); git_run(&["push", "--force-if-includes", &lease, remote, AUTH_REF]) } @@ -485,10 +487,9 @@ /// config. As with the signer set, the update is a compare-and-swap against /// `expected` so a set someone changed since the fetch is not clobbered. fn push_checks(remote: &str, expected: Option<&str>) -> Result<(), String> { - const ZERO: &str = "0000000000000000000000000000000000000000"; let lease = format!( "--force-with-lease={CHECKS_REF}:{}", - expected.unwrap_or(ZERO) + expected.unwrap_or(git_ents::ZERO_OID) ); git_run(&["push", "--force-if-includes", &lease, remote, CHECKS_REF]) }