Skip to content

feat(fields): add the {lines} first-class line-count field (#114) - #282

Merged
helly25 merged 1 commit into
mainfrom
feat/lines-field
Jul 6, 2026
Merged

feat(fields): add the {lines} first-class line-count field (#114)#282
helly25 merged 1 commit into
mainfrom
feat/lines-field

Conversation

@helly25

@helly25 helly25 commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Adds a per-text-file line count as a first-class field, the prerequisite for the histograms lines metric (#81).

What

  • {lines} in the field vocabulary: usable as {lines}, -printf '%{lines}', and --template. wc -l style, but also counts a final line with no trailing newline.
  • Empty for a non-regular, unreadable, or binary file (grep/ripgrep's NUL-byte-in-first-8-KiB heuristic), so binaries render nothing rather than a misleading count.

Where

  • xff/content: CountLines (pure; reuses the CollectLineMatches grep line semantics via ForEachLine) + FileLineCount (reads via mbo::file::Artefact, skips binary) - co-located with the line-match logic they share.
  • xff/fields: LinesField reads by path (like {hash}), gated on a regular-file metadata type; registered in the field table + FieldDocs, so --help=fields / man / markdown list it by construction.

Tests

  • Unit: CountLines / FileLineCount (empty, no-trailing-newline, CRLF, binary, unreadable).
  • Render: LinesField (text / no-newline / empty / binary / unreadable / non-regular).
  • CLI: a bashtest driving -printf '%{lines}' end to end.

The aggregate side (sum + distribution across matches) is the histograms work (#81), not part of this field. TODO.md updated accordingly.

A per-text-file line count in the field vocabulary: {lines}, %{lines} in
-printf, and --template - wc -l style but also counting a final unterminated
line. Empty for a non-regular, unreadable, or binary file (grep/ripgrep's
NUL-byte-in-first-8KiB heuristic), so binaries render nothing rather than a
misleading count.

- xff/content: CountLines (pure, reuses the CollectLineMatches grep line
  semantics via ForEachLine) + FileLineCount (reads via mbo::file::Artefact,
  skips binary), next to the line-match logic they share.
- xff/fields: LinesField reads by path (like {hash}), gated on a regular-file
  metadata type; registered in the field table + FieldDocs (so --help=fields,
  man, and markdown list it by construction).
- Tests: CountLines/FileLineCount unit tests, LinesField render tests
  (text/no-newline/empty/binary/unreadable/non-regular), and a CLI bashtest
  driving -printf %{lines} end to end.

The aggregate side (sum + distribution across matches) is the histograms
work (#81), not part of this field.
@helly25
helly25 enabled auto-merge (squash) July 6, 2026 23:06
@helly25
helly25 merged commit 89e2f82 into main Jul 6, 2026
8 checks passed
@helly25
helly25 deleted the feat/lines-field branch July 6, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant