Skip to content

Fix --line-range from the end skipping later absolute ranges - #4097

Open
Huang-404-Q wants to merge 2 commits into
sharkdp:masterfrom
Huang-404-Q:fix/line-range-from-end-then-absolute
Open

Huang-404-Q wants to merge 2 commits into
sharkdp:masterfrom
Huang-404-Q:fix/line-range-from-end-then-absolute

Conversation

@Huang-404-Q

Copy link
Copy Markdown

LineRanges::check returned AfterLastRange as soon as a line was past the from-end cutoff, without considering a larger absolute upper bound from another range. controller.rs then stopped reading, so a later absolute --line-range was never printed.

For a 10-line file:

bat multiline.txt --line-range=:-2 --line-range=10:10

before this change prints lines 1-8 and drops line 10. Ranges should be unioned, so line 10 must be printed as well.

The fix makes largest_absolute_upper_bound optional. The early exit still applies when there is no absolute upper bound (pure from-end ranges), but is skipped when a later line is still covered by an absolute range.

Tests

Added line_range_offset_from_end_and_later_absolute_range to tests/integration_tests.rs.

Verified with cargo +1.95.0-x86_64-pc-windows-gnu test --locked --test integration_tests:

  • before: test fails, output is missing line 10
  • after: test passes; all line-range unit and integration tests pass

RangeCheck::AfterLastRange stopped the read loop as soon as a line was
past the from-end cutoff, even when another range had a larger absolute
upper bound. Keep that early exit only when no absolute upper bound
extends past the cutoff.

Signed-off-by: huang <13165998033@163.com>
@Huang-404-Q

Copy link
Copy Markdown
Author

The i686-unknown-linux-gnu failure is in no_args_doesnt_break, which panics in wait-timeout-0.2.1/src/unix.rs:55 while spawning/waiting for the process. It does not touch line ranges; the line-range unit and integration tests passed (265 passed, 1 failed). This looks like the known 32-bit wait-timeout flake. The changelog entry has been added in 787e588.

@Huang-404-Q

Copy link
Copy Markdown
Author

The rerun failed identically: no_args_doesnt_break panics in wait-timeout again (265 passed, 1 failed). The line-range tests pass on this target as well, so this is the same environment-specific wait-timeout flake rather than a regression from this change.

This branch has not been deployed

No deployments
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