interplane.Get Omega
Read in your language

sovereign-intelligence

Front door to Drake Stapleton's sovereign stack.

Brought by drakestapleton

branch main Branches Tags History

sovereign-intelligence / tools / ledger-refresh.sh

35 lines · 1754 bytes Raw Blame History
1#!/bin/sh
2# ledger-refresh.sh CHECKOUTS LEDGER: print the stack ledger (stack/LEDGER.tsv) for every
3# git checkout directly under CHECKOUTS, using LEDGER, the binary built from tools/ledger.om.
4#
5# sh tools/ledger-refresh.sh /path/to/checkouts ./ledger > stack/LEDGER.tsv
6#
7# The file list: each directory under CHECKOUTS that holds a .git, in LC_ALL=C order; in each,
8# the tracked regular files only (git ls-files -s modes 100644 and 100755; symlinks 120000 and
9# submodules 160000 are left out), one "REPO TAB REPO/PATH" line per file. The ledger runs from
10# CHECKOUTS, so the paths are relative to it. A path holding a TAB or a newline cannot be one
11# line of the list: it is skipped, and the number skipped is printed on stderr. The counting
12# itself is done by the Omega program; this script only lists the files.
13set -eu
14[ $# -eq 2 ] || { echo "usage: ledger-refresh.sh CHECKOUTS LEDGER" >&2; exit 2; }
15case $2 in /*) L=$2 ;; *) L=$(pwd)/$2 ;; esac
16cd "$1"
17list=$(mktemp)
18skip=$(mktemp)
19trap 'rm -f "$list" "$skip"' EXIT
20: > "$skip"
21for d in $(LC_ALL=C ls -A | LC_ALL=C sort); do
22 [ -d "$d/.git" ] || continue
23 # NUL-separated records; a newline inside a path becomes \001, then NUL becomes the newline.
24 git -C "$d" ls-files -s -z | tr '\n\000' '\001\n' | LC_ALL=C awk -v r="$d" -v s="$skip" '
25 {
26 t = index($0, "\t"); if (t == 0) next
27 mode = substr($0, 1, 6); path = substr($0, t + 1)
28 if (mode != "100644" && mode != "100755") next
29 if (index(path, "\t") || index(path, "\001")) { print "x" >> s; next }
30 print r "\t" r "/" path
31 }'
32done > "$list"
33n=$(wc -l < "$skip" | tr -d ' ')
34echo "ledger-refresh: $(wc -l < "$list" | tr -d ' ') files listed, $n paths with a TAB or newline skipped" >&2
35"$L" < "$list"