Jump to…
snowinitial commitqoxwzsukwmkx1mo
1#!/usr/bin/env bash
2#
3# Enforce spec §3 rule 1: "No crate other than `df-store` may depend on `gix`.
4# Add this to CI as a dependency check."
5#
6# The whole value of the RepoStore abstraction is that swapping in a jj-native
7# backend later touches one crate. That guarantee is worth exactly as much as
8# this check — the moment a second crate reaches for `gix`, the boundary is
9# gone and nobody notices until the migration.
10
11set -euo pipefail
12
13ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
14FAIL=0
15
16echo "==> checking the df-store boundary"
17
18# 1. Only df-store may declare gix as a dependency.
19while IFS= read -r manifest; do
20 crate="$(basename "$(dirname "$manifest")")"
21 [[ "$crate" == "df-store" ]] && continue
22
23 if grep -qE '^\s*gix\s*[=.]|^\s*gix\s*=\s*\{' "$manifest"; then
24 echo " FAIL: $crate declares a dependency on gix ($manifest)"
25 FAIL=1
26 fi
27done < <(find "$ROOT/crates" -name Cargo.toml)
28
29# 2. Only df-store may name gix in its source.
30while IFS= read -r file; do
31 case "$file" in
32 "$ROOT"/crates/df-store/*) continue ;;
33 esac
34 if grep -nE '(^|[^A-Za-z_])gix::|extern crate gix' "$file" >/dev/null 2>&1; then
35 echo " FAIL: $(realpath --relative-to="$ROOT" "$file") references gix::"
36 grep -nE '(^|[^A-Za-z_])gix::|extern crate gix' "$file" | head -3 | sed 's/^/ /'
37 FAIL=1
38 fi
39done < <(find "$ROOT/crates" -name '*.rs')
40
41# 3. RevId must stay opaque: nothing outside df-store may slice or measure it.
42# Spec §3 rule 2 — "do not parse it, do not assume it is 40 hex characters,
43# do not abbreviate it outside df-store."
44while IFS= read -r file; do
45 case "$file" in
46 "$ROOT"/crates/df-store/*) continue ;;
47 esac
48 if grep -nE '\.as_str\(\)\s*\[|rev\s*\[\s*\.\.|\.rev\.as_str\(\)\[' "$file" >/dev/null 2>&1; then
49 echo " FAIL: $(realpath --relative-to="$ROOT" "$file") appears to slice a RevId"
50 FAIL=1
51 fi
52done < <(find "$ROOT/crates" -name '*.rs')
53
54if [[ $FAIL -eq 0 ]]; then
55 echo " ok — gix is confined to df-store, RevId is opaque"
56else
57 echo
58 echo "The storage boundary exists so that moving to a jj-native backend is a"
59 echo "swap of one implementation rather than a rewrite. Route what you need"
60 echo "through the RepoStore trait instead."
61 exit 1
62fi

62 lines · Shell