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/norm.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'test/norm.c') diff --git a/test/norm.c b/test/norm.c index acfb6ec..4b8a35a 100644 --- a/test/norm.c +++ b/test/norm.c @@ -1,10 +1,5 @@ -/* norm.c - Refs and repositories have one spelling each internally. This is the file - * that pins "main", "heads/main" and "refs/heads/main" being one branch, and - * a bare name never meaning a tag. - * - * 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. - */ +// One spelling per ref: "main", "heads/main" and "refs/heads/main" are one +// branch, and a bare name is never a tag. #include "test.h" static void test_normalisation(void) @@ -21,7 +16,7 @@ static void test_normalisation(void) CHECK_STR(s, "refs/heads/main"); free(s); s = authz_norm_ref("v1.0"); - CHECK_STR(s, "refs/heads/v1.0"); /* a bare name is never a tag */ + CHECK_STR(s, "refs/heads/v1.0"); // a bare name is never a tag free(s); s = authz_norm_ref("tags/v1.0"); CHECK_STR(s, "refs/tags/v1.0"); @@ -49,7 +44,7 @@ static void test_normalisation(void) CHECK_STR(s, "*"); free(s); s = authz_norm_repo(".git"); - CHECK_STR(s, ".git"); /* a repository called ".git" is not a suffix */ + CHECK_STR(s, ".git"); // a repository called ".git" is not a suffix free(s); CHECK_INT(authz_level_of("write"), LV_WRITE); @@ -66,13 +61,13 @@ static void test_normalisation(void) CHECK(authz_user_pattern_ok("@all")); CHECK(authz_user_pattern_ok("a[bc]d")); CHECK(!authz_user_pattern_ok("")); - CHECK(!authz_user_pattern_ok("a/b")); /* a path is not a user name */ + CHECK(!authz_user_pattern_ok("a/b")); // a path is not a user name CHECK(!authz_user_pattern_ok("a$b")); CHECK(!authz_user_pattern_ok("-x")); CHECK(authz_repo_pattern_ok("team")); CHECK(authz_repo_pattern_ok("*")); CHECK(authz_repo_pattern_ok("team-*")); - CHECK(!authz_repo_pattern_ok("group/team")); /* flat names only */ + CHECK(!authz_repo_pattern_ok("group/team")); // flat names only CHECK(!authz_repo_pattern_ok("")); CHECK(!authz_repo_pattern_ok("a$b")); } -- cgit v1.2.3