From 312ddd4936f09ae27a180ca495cacf2c06faf33e Mon Sep 17 00:00:00 2001 From: dev Date: Sat, 14 Nov 2026 01:05:08 +0000 Subject: 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. --- test/need.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'test/need.c') diff --git a/test/need.c b/test/need.c index f831111..013674e 100644 --- a/test/need.c +++ b/test/need.c @@ -1,18 +1,13 @@ -/* need.c - What a ref costs beyond what the rule said - which is only ever the case - * for refs outside refs/heads and refs/tags. There is no second list in the - * policy that can raise the price of a ref behind the operator's back. - * - * Part of the direct suite: this links the library, not the command - * line. test/run.sh is the other half, and drives the program the way git does. - */ +// What a ref costs beyond what the rule said - only ever refs outside +// refs/heads and refs/tags. #include "test.h" static void test_need_for(void) { char raised[64]; - /* A branch or a tag costs exactly what the rule said: there is no list - * elsewhere in the file that can raise the price of one. */ + // A branch or a tag costs exactly what the rule said: there is no list * + // elsewhere in the file that can raise the price of one. CHECK_INT(authz_need_for("refs/heads/dev", LV_WRITE, raised, sizeof(raised)), LV_WRITE); CHECK_STR(raised, ""); @@ -23,8 +18,8 @@ static void test_need_for(void) CHECK_INT(authz_need_for("refs/heads/feature/x", LV_FORCE, raised, sizeof(raised)), LV_FORCE); - /* Anything outside refs/heads and refs/tags is for maintainers, whatever a - * rule appears to grant about it. */ + // Anything outside refs/heads and refs/tags is for maintainers, whatever a * + // rule appears to grant about it. CHECK_INT(authz_need_for("refs/pull/1/head", LV_WRITE, raised, sizeof(raised)), LV_ADMIN); CHECK_STR(raised, "neither a branch nor a tag"); @@ -34,7 +29,7 @@ static void test_need_for(void) LV_ADMIN); CHECK_INT(authz_need_for("refs/notes/x", LV_ADMIN, raised, sizeof(raised)), LV_ADMIN); - CHECK_STR(raised, ""); /* admin is already the top */ + CHECK_STR(raised, ""); // admin is already the top } int main(void) -- cgit v1.2.3