srctree-stage: submodules go into the source set as tracked files

Since ext/src/mcde and the other projects are submodules, `git ls-files` names
each one as a single gitlink -- and pax -rw, given that path, copied the whole
working tree behind it: .git and build output included.  The root copy leaves
the gitlinks out now, and each submodule's tracked files are copied on their
own, so the source set carries the source and nothing else.

refs/ stays out as before: its five submodules are the 11 GB reference
checkouts, and only refs/AGENTS.md is part of a rebuild (the header says why).

Measured on the MacBook-built tree here:
- 7 submodules copied: splinter, krang, sshcrypt, kidstube, CNCL, mikronix,
  mcde (~303 MB together, mcde 286 MB).
- mcde alone: 19,591 files copied == `git -C ext/src/mcde ls-files | wc -l`,
  `find -name .git` = 0.
- sh -n tools/srctree-stage.sh rc=0.
This commit is contained in:
lotherk committed 2026-11-22 11:44:22 +01:00
1 parent 62d9bb9c71
commit ce2d3211e1
1 file changed
+33 -3
+33 -3
View File
@@ -21,7 +21,9 @@
# change that is not committed yet is in the set the running build uses. No
# .git and no build output is carried. refs/ is a set of reference
# checkouts (netbsd, linux, openbsd, 11 GB) and only its AGENTS.md is part of
# the tree a rebuild needs.
# the tree a rebuild needs. A submodule (ext/src/*) is copied the same way:
# its tracked files, no .git, no build output -- git ls-files names it as one
# gitlink and pax would otherwise take the whole working tree behind it.
#
# Refuses a pkgsrc that has local edits, a stale PINS, and distfiles that are
# not complete. ustar limit: pkgsrc patch names longer than 100 characters
@@ -68,11 +70,39 @@ command -v "$PAX" >/dev/null 2>&1 || die "no pax (nbpax, or pax in PATH)"
rm -rf "$DIR"
mkdir -p "$DIR"
# The submodule paths: git ls-files names each one as a single gitlink, and
# pax -rw would copy the whole working tree behind it -- .git and build output
# included. The root copy leaves them out and each submodule's tracked files
# are copied below, so the set carries the source and nothing else.
SUBMODULES=
if [ -f "$TOP/.gitmodules" ]; then
SUBMODULES=$(git -C "$TOP" config --file .gitmodules --get-regexp \
'^submodule\..*\.path$' | awk '{ print $2 }' | sed '/^refs\//d')
fi
# The root repository, tracked files only, from the working tree.
(cd "$TOP" && git ls-files | grep -v '^refs/' ; echo refs/AGENTS.md) |
(cd "$TOP" && "$PAX" -rw -pm "$DIR") \
rootlist=$(mktemp) || die "no mktemp"
trap 'rm -f "$rootlist" "$rootlist.new"' EXIT HUP INT TERM
(cd "$TOP" && git ls-files | grep -v '^refs/' ; echo refs/AGENTS.md) > "$rootlist"
for sub in $SUBMODULES; do
grep -v -F -x "$sub" "$rootlist" > "$rootlist.new"
rc=$?
[ "$rc" -eq 0 ] || [ "$rc" -eq 1 ] ||
die "filtering $sub from the file list failed"
mv "$rootlist.new" "$rootlist"
done
(cd "$TOP" && "$PAX" -rw -pm "$DIR") < "$rootlist" \
|| die "copying the repository into $DIR failed"
# Each submodule: its tracked files, no .git, no build output.
for sub in $SUBMODULES; do
[ -d "$TOP/$sub" ] || die "submodule $sub is not checked out"
mkdir -p "$DIR/$sub"
(cd "$TOP/$sub" && git ls-files) |
(cd "$TOP/$sub" && "$PAX" -rw -pm "$DIR/$sub") \
|| die "copying submodule $sub into $DIR/$sub failed"
done
# pkgsrc: its own repository, pinned, plus what is ours and untracked there
# (AGENTS.md and the recipes of the Makronix packages, tools/ext-sync.sh copies
# them in; git ignores neither). build/ and other ignored work is not carried.