aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/src/sh.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 00:26:36 +0000
committertv <tv@krebsco.de>2026-12-01 00:26:36 +0000
commit5df6e41e05b9449a964467bc11a9d7fce2d802ec (patch)
treede72c779f03f7cb55ce083d527fc479245d0c8ef /pkgs/populate/src/sh.rs
parent85afc649ffeea7c92027f57e0a1bdec27d9bc8c9 (diff)
populate: skip symlink and git sources with nothing to do
Each command on a remote target costs about three round trips, so the bench's 30 symlink and 20 git sources took about 4.5 of a no-op run's 7.2 s with 30 ms to the target, with one command each. The command after taking the lock that lists file sources, now the probe (probe.rs), also finds out what's at the target paths of symlink sources, the symlink, if any, and of git sources with a commit as ref and without fetchAlways: if git_problems finds nothing wrong with the work tree, which keeps guarding every Git command, its HEAD, its origin's URL, and what git status --ignored and git submodule status print. A symlink source whose symlink points to the target already runs nothing. So does a git source whose work tree has the commit checked out, the source's URL, nothing modified, untracked, or ignored, and its submodules at their commits; the flakes step takes it for checked, as after the git script. Not where the flakes step rewrites a lock file in place. The scenario symlink-git-skip checks that an unchanged symlink stays the same file, which ln would replace, and that a symlink pointing elsewhere, a modified file, an untracked one, and another commit make them deliver again.
Diffstat (limited to 'pkgs/populate/src/sh.rs')
-rw-r--r--pkgs/populate/src/sh.rs64
1 files changed, 64 insertions, 0 deletions
diff --git a/pkgs/populate/src/sh.rs b/pkgs/populate/src/sh.rs
index f29b1f1..dc44854 100644
--- a/pkgs/populate/src/sh.rs
+++ b/pkgs/populate/src/sh.rs
@@ -344,6 +344,70 @@ fi
"#
}
+/// probe KIND PATH...: prints, for each pair of KIND and PATH, what
+/// probe::Target takes from it: P and PATH, then, for KIND F, an entry like
+/// listings prints for each thing at and below PATH, for L, if PATH is a
+/// symlink, L and its target, and for G, if PATH is a directory with a .git
+/// directory that git_problems finds nothing wrong with, C, H and HEAD, U and
+/// the origin's URL, D and what git status prints for anything modified,
+/// untracked, or ignored, and, with submodules, M and what git submodule
+/// status prints for them, and S and an exit status, all separated by NULs.
+/// Git runs like the git script runs it, without hooks and file system
+/// monitors, and without writing the index.
+pub fn probe() -> String {
+ GIT_PROBLEMS.to_string()
+ + r#"
+git() {
+ command git -c core.hooksPath=/dev/null -c core.fsmonitor=false \
+ --no-optional-locks "$@"
+}
+while test $# -gt 1; do
+ kind=$1 path=$2
+ shift 2
+ printf 'P\0%s\0' "$path"
+ status=0
+ case $kind in
+ F)
+ if ! find "$path" -printf 'E\0%M\0%s\0%T@\0%P\0%l\0' 2>/dev/null; then
+ status=1
+ fi
+ ;;
+ L)
+ if test -L "$path"; then
+ printf 'L\0%s\0' "$(readlink "$path")"
+ fi
+ ;;
+ G)
+ if ! test -L "$path" && test -d "$path" &&
+ ! test -L "$path"/.git && test -d "$path"/.git &&
+ problems=$(git_problems "$path") && test -z "$problems"
+ then
+ printf 'C\0\0'
+ printf 'H\0%s\0' "$(git -C "$path" rev-parse --verify --quiet HEAD)"
+ printf 'U\0%s\0' "$(git -C "$path" config remote.origin.url)"
+ # Captured first: printf doesn't fail if what it prints did.
+ if dirty=$(git -C "$path" status --porcelain --ignored \
+ --untracked-files=all)
+ then
+ printf 'D\0%s\0' "$dirty"
+ else
+ status=1
+ fi
+ if test -e "$path"/.gitmodules; then
+ if submodules=$(git -C "$path" submodule status --recursive); then
+ printf 'M\0%s\0' "$submodules"
+ else
+ status=1
+ fi
+ fi
+ fi
+ ;;
+ esac
+ printf 'S\0%s\0' "$status"
+done
+"#
+}
+
/// listings PATH...: prints, for each PATH, P and PATH, an entry for each
/// thing at and below PATH, with E, mode, size, modification time in
/// seconds since the epoch, path relative to PATH, and symlink target,
[cgit] Unable to lock slot /tmp/cgit/cc200000.lock: Permission denied (13)