summaryrefslogtreecommitdiffstats
path: root/build/relpath.awk
diff options
context:
space:
mode:
authordev <dev@example>2026-11-14 01:05:08 +0000
committerdev <dev@example>2026-11-14 01:05:08 +0000
commit312ddd4936f09ae27a180ca495cacf2c06faf33e (patch)
tree2fa46ab568ad55f7e8fb844c3447b1d296b2e340 /build/relpath.awk
parente737f3d560de2b8172e6dd83901bc1359283303c (diff)
downloadaccess-control-312ddd4936f09ae27a180ca495cacf2c06faf33e.tar.gz
access-control-312ddd4936f09ae27a180ca495cacf2c06faf33e.zip
Comments: cut to what the code cannot say
The comments had grown into essays. A file header explaining why the file exists, then a paragraph above each function restating what the next eight lines do, then a paragraph above that one explaining why that matters. The reader gets no further than the first paragraph, and the second is the one that goes stale: it describes code that has since changed, and nothing fails when it does. Cut by about half. What is left is the three things a comment can do that code cannot: say why the constraint exists (no regex because a hook must not depend on what might be missing at 3am), say what is not obvious from the shape (a bare ref name is a branch, never a tag; the seventh field of /etc/passwd is the shell), and say where it hurts (the NULL in an execvp array, the mode and owner that have to survive an atomic rewrite, the child that must not keep the hook's stdin). Block comments became // lines, which is also what the other C trees here use, and the file headers went to two or three lines. Section banners stayed: they are navigation, not prose. Behaviour is unchanged and the suites prove it: 171 direct checks, 162 behavioural, clean under -Werror and under ASan/UBSan.
Diffstat (limited to 'build/relpath.awk')
-rw-r--r--build/relpath.awk22
1 files changed, 8 insertions, 14 deletions
diff --git a/build/relpath.awk b/build/relpath.awk
index ea5ca99..10651d0 100644
--- a/build/relpath.awk
+++ b/build/relpath.awk
@@ -1,16 +1,10 @@
-# relpath.awk - the path from one directory to one file, relative to the
-# directory. Used by `make install' for the hook symlink:
+# The path from one directory to one file, relative to the directory; used by
+# `make install' for the hook symlink. A relative link survives a staged install,
+# an unpacked prefix, or an image built somewhere else; an absolute one points at
+# whatever lives at that path on the machine reading it.
#
-# awk -v from=/usr/local/share/git-host/hooks -v to=/usr/local/bin/git-authz \
-# -f build/relpath.awk -> ../../../bin/git-authz
-#
-# A relative link survives being moved: a staged install under DESTDIR, an
-# unpacked prefix, a container image built somewhere else. An absolute one
-# points at whatever happens to live at that path on the machine reading it,
-# which during a staged install is the wrong answer and after a failed one is a
-# broken link nothing explains.
-#
-# POSIX awk, so busybox awk and mawk and gawk all agree.
+# POSIX awk: busybox awk, mawk and gawk all agree on it.
+
function split_path(p, out, n, parts, i, depth) {
n = split(p, parts, "/")
@@ -43,8 +37,8 @@ BEGIN {
while (common < nf && common < nt && f[common + 1] == t[common + 1])
common++
- # Anything above a ".." we could not resolve has to be answered with an
- # absolute path: there is no relative route into a directory we cannot name.
+ # No relative route into a directory we cannot name.
+
if ((nf > common && f[common + 1] == "..") ||
(nt > common && t[common + 1] == "..")) {
print to