Repeatable -r: plain numbers slice filtered output, unit windows intersect; add --context
-r is now repeatable and restrictive: unit specs (l/s/v/r) intersect their database line windows, while plain-number specs index into the filtered output items left after unit windows and --grep, acting as a pure display filter (negatives from the end, single index errors with exit 2, ranges truncate). --context N (default 0) then expands each surviving item GNU grep-style by N surrounding in-window records, free of the grep/plain filters, merging overlaps.
This commit is contained in:
1 parent
de2476c59c
commit
b8d2222905
4 files changed
+359
-29
No files matched your search
@@ -73,6 +73,17 @@ A revision number identifies a *state position between diffs*, not a diff:
|
||||
|
||||
`kanta.rev` exposes the current revision at runtime: the number of change records applied since revision 0, advanced in memory as transactions queue records. Reading it before `open()` raises `DataIntegrityError`. The CLI accepts `rN` range bounds to select records by revision (e.g. `-r r10:r20`): a bound `rN` addresses state N together with the record that produced it — the change record resulting in state N, or, when that change is no longer in the file, the snapshot materializing state N. `-r r5` and `-r r5:r6` therefore show the same record and output state 5, while `-r r5..r6` also includes the next change and outputs state 6. Ranges truncate Python-style instead of erroring: on a rotated file whose leading snapshot holds revision 3, `-r r1:r4` starts at the beginning of the file and shows that snapshot. Snapshot indicator lines show the snapshot's revision.
|
||||
|
||||
## CLI Range Filtering
|
||||
|
||||
`-r` is repeatable and its specs fall into two classes:
|
||||
|
||||
- **Unit specs** — any spec with a letter-prefixed bound (`l`, `s`, `v`, `r`, including mixed forms like `2:s3`) — index into the database file and resolve to a line window. Multiple unit specs intersect restrictively: only the common line range is processed.
|
||||
- **Plain-number specs** — both bounds (or the single index) are plain numbers — index into the *filtered output*: the records left after all unit specs and all `--grep` patterns have been applied. They are a pure display filter and do not affect replay, migrations, or the `-o` output state. Negative values count from the end of the filtered output.
|
||||
|
||||
Like repeated `--grep` patterns (which must all match), repeated ranges are restrictive: `-r r1:r5 -r 0:2` prints only the first two records of those in the revision window, regardless of flag order. Plain ranges truncate Python-style and print nothing when the intersection is empty; a single plain index must exist and fails with exit code 2 otherwise.
|
||||
|
||||
`--context N` (default 0) adds GNU grep-style context as the final step: each printed item is expanded by N surrounding records drawn from the records in the processed range, free of the `--grep` and plain-number filters, with overlapping expansions merged so nearby matches do not duplicate context records.
|
||||
|
||||
## Meta Format Migrations
|
||||
|
||||
The snapshot `k` field carries an integer meta format version (`kanta.structs.META_FORMAT`, currently 1), bumped manually whenever the record-level format around the payloads changes. k1 introduced revision numbers.
|
||||
|
||||
Reference in new issue
Block a user