From e757979f1a2afdbe7146066345bb9acd19d3b151 Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 17:09:59 +0000 Subject: comments: say why, not what MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every module-level `//!` header is gone, and the comments that remained either re-explained the line below them or had grown into paragraphs. Density went from one comment line per 6.7 lines of code to one per 10. 827 insertions against 2194 deletions across 86 files. What survived: the invariants (I1-I12), the design cross-references into DESIGN.md, and the notes recording a bug that was found and fixed — those are the comments that carry weight, because they answer a question the code cannot answer about itself. What did not: restating a function signature in prose, and narration of the statement underneath. --- src/pkgver/mod.rs | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'src/pkgver/mod.rs') diff --git a/src/pkgver/mod.rs b/src/pkgver/mod.rs index e968256..bd77a01 100644 --- a/src/pkgver/mod.rs +++ b/src/pkgver/mod.rs @@ -1,12 +1,3 @@ -//! Version comparison and dependency-string parsing. -//! -//! Hand-written rather than bound to libalpm (DESIGN.md §4). The algorithm is -//! the ALPM one and is fully specified: compare epoch numerically, then compare -//! `pkgver` chunk-wise, then `pkgrel` chunk-wise. A chunk is a maximal run of -//! digits or a maximal run of non-digits; non-alphanumeric characters are -//! ignored. A numeric chunk always sorts before an alphabetic chunk, so `1.5` -//! < `1.5a` and `1.1` < `1.a`. - use std::cmp::Ordering; use std::fmt; @@ -127,25 +118,19 @@ fn preceded_by_separator(s: &[u8], k: usize) -> bool { k > 0 && !is_alnum(s[k - 1]) } -/// ALPM's `vercmp`, character-wise. -/// -/// Three rules do all the work, and each one is surprising the first time: +/// ALPM's `vercmp`, character-wise. Three rules do all the work: /// /// 1. A numeric chunk is newer than an alphabetic chunk at the same position, so /// `1.0.1` > `1.0.a`. /// 2. When one string runs out, the other side decides by its *next raw /// character*: a letter there makes the exhausted string newer (`1.0` > -/// `1.0a`, the `1.0rc1 < 1.0` rule), anything else makes it older -/// (`1.0` < `1.0.1`). -/// 3. Separators are not merely skipped. An alphabetic chunk that follows a -/// separator is newer than one glued to the previous chunk, whatever the -/// letters are: `1.0.a` > `1.0z`. Two versions that differ only in where the -/// dot sits are *not* equal, which is the part a chunk-splitting -/// implementation gets wrong. +/// `1.0a`), anything else makes it older (`1.0` < `1.0.1`). +/// 3. An alphabetic chunk following a separator is newer than one glued to the +/// previous chunk, whatever the letters are: `1.0.a` > `1.0z`. Versions +/// differing only in where the dot sits are *not* equal. /// /// The cross-product test in `tests/versions.rs` checks this against pacman's own -/// `vercmp` over ~1100 pairs, which is the only reason anyone can be confident -/// about rule 3. +/// `vercmp` over ~1100 pairs. pub fn vercmp_string(a: &str, b: &str) -> Ordering { let (a, b) = (a.as_bytes(), b.as_bytes()); let (mut i, mut j) = (0usize, 0usize); -- cgit v1.2.3