Jump to…
snowinitial commitqoxwzsukwmkx1mo
Matt W1#!/usr/bin/env bash
Matt W2#
Matt W3# Enforce spec §3 rule 1: "No crate other than `df-store` may depend on `gix`.
Matt W4# Add this to CI as a dependency check."
Matt W5#
Matt W6# The whole value of the RepoStore abstraction is that swapping in a jj-native
Matt W7# backend later touches one crate. That guarantee is worth exactly as much as
Matt W8# this check — the moment a second crate reaches for `gix`, the boundary is
Matt W9# gone and nobody notices until the migration.
Matt W10
Matt W11set -euo pipefail
Matt W12
Matt W13ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
Matt W14FAIL=0
Matt W15
Matt W16echo "==> checking the df-store boundary"
Matt W17
Matt W18# 1. Only df-store may declare gix as a dependency.
Matt W19while IFS= read -r manifest; do
Matt W20 crate="$(basename "$(dirname "$manifest")")"
Matt W21 [[ "$crate" == "df-store" ]] && continue
Matt W22
Matt W23 if grep -qE '^\s*gix\s*[=.]|^\s*gix\s*=\s*\{' "$manifest"; then
Matt W24 echo " FAIL: $crate declares a dependency on gix ($manifest)"
Matt W25 FAIL=1
Matt W26 fi
Matt W27done < <(find "$ROOT/crates" -name Cargo.toml)
Matt W28
Matt W29# 2. Only df-store may name gix in its source.
Matt W30while IFS= read -r file; do
Matt W31 case "$file" in
Matt W32 "$ROOT"/crates/df-store/*) continue ;;
Matt W33 esac
Matt W34 if grep -nE '(^|[^A-Za-z_])gix::|extern crate gix' "$file" >/dev/null 2>&1; then
Matt W35 echo " FAIL: $(realpath --relative-to="$ROOT" "$file") references gix::"
Matt W36 grep -nE '(^|[^A-Za-z_])gix::|extern crate gix' "$file" | head -3 | sed 's/^/ /'
Matt W37 FAIL=1
Matt W38 fi
Matt W39done < <(find "$ROOT/crates" -name '*.rs')
Matt W40
Matt W41# 3. RevId must stay opaque: nothing outside df-store may slice or measure it.
Matt W42# Spec §3 rule 2 — "do not parse it, do not assume it is 40 hex characters,
Matt W43# do not abbreviate it outside df-store."
Matt W44while IFS= read -r file; do
Matt W45 case "$file" in
Matt W46 "$ROOT"/crates/df-store/*) continue ;;
Matt W47 esac
Matt W48 if grep -nE '\.as_str\(\)\s*\[|rev\s*\[\s*\.\.|\.rev\.as_str\(\)\[' "$file" >/dev/null 2>&1; then
Matt W49 echo " FAIL: $(realpath --relative-to="$ROOT" "$file") appears to slice a RevId"
Matt W50 FAIL=1
Matt W51 fi
Matt W52done < <(find "$ROOT/crates" -name '*.rs')
Matt W53
Matt W54if [[ $FAIL -eq 0 ]]; then
Matt W55 echo " ok — gix is confined to df-store, RevId is opaque"
Matt W56else
Matt W57 echo
Matt W58 echo "The storage boundary exists so that moving to a jj-native backend is a"
Matt W59 echo "swap of one implementation rather than a rewrite. Route what you need"
Matt W60 echo "through the RepoStore trait instead."
Matt W61 exit 1
Matt W62fi

62 lines · Shell