fix: show microsecond precision in borg diff when timestamps differ only at sub-second level (fixes #9147)#9561
Conversation
… display Add format_timestamp_pair() function that intelligently formats two timestamps for diff output. When timestamps are equal at second resolution but differ at the microsecond level (common on FreeBSD/NetBSD), microsecond precision is used to show the difference. Otherwise, second-precision format is used to match existing behavior. Includes 3 comprehensive unit tests covering: 1. Timestamps differing at second level (no microseconds shown) 2. Timestamps identical at second level but different at microsecond level (microseconds shown) 3. Completely identical timestamps (no microseconds shown) Fixes issue borgbackup#9147 where diff output showed confusing identical timestamps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…econd timestamp diffs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
BSD may produce a POSIX-valid sub-second ctime change on b/hardlink when a previously hard-linked path is recreated as a new inode. The test now accepts this BSD behavior while still verifying no content/mode/mtime changes. Fixes borgbackup#9147 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks for the PR! That variable formatting is a mixed blessing:
Can you fix the linting issues, so the BSD tests are not cancelled? |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Thanks for the review! Regarding variable formatting: noted — the trade-off is real. The current implementation only switches to microsecond precision in the narrow case where two timestamps are identical at second resolution but differ sub-second, so the output format stays constant for the vast majority of diffs. That said, I'm open to alternative approaches (e.g. always using microsecond precision, or a flag) if you prefer a guaranteed constant format. Fixed the black formatting issues in |
Summary
Fixes #9147 —
borg diffon FreeBSD/NetBSD shows confusing[ctime: Wed, 2025-11-05 17:45:53 +0000 -> Wed, 2025-11-05 17:45:53 +0000]output where both timestamps look identical but actually differ at nanosecond level.format_timestamp_pair(ts1, ts2)inhelpers/time.py: selects second-precision format normally, but upgrades to microsecond precision (%H:%M:%S.%f) when two timestamps appear equal at second resolution but differ at sub-second levelDiffFormatter.format_time()inhelpers/parseformat.pyto useformat_timestamp_pair(), so diff output shows[ctime: ...17:45:53.000123 ... -> ...17:45:53.000456 ...]instead of the confusing identical-looking pairtest_hard_link_deletion_and_replacementon FreeBSD, NetBSD, and OpenBSD (was previously skipped): the test now accepts a POSIX-valid sub-second ctime update on surviving hardlinks while verifying no content/mode/mtime changes occurredRoot cause
On BSD, creating a new file at a previously hard-linked path causes a sub-second ctime update on surviving hard links (POSIX-valid behaviour). The old
format_time()always used second-precision format, so two timestamps like17:45:53.000123and17:45:53.000456both rendered as17:45:53, producing the confusingX -> Xoutput.Test plan
test_format_timestamp_pair_different_seconds— second-precision when timestamps differ by ≥1stest_format_timestamp_pair_same_second_different_microsecond— microsecond-precision for sub-second difftest_format_timestamp_pair_identical— second-precision for identical timestampstest_diff_formatter_format_time_shows_microseconds_when_same_second— full formatter pathtest_diff_formatter_format_time_no_microseconds_for_different_seconds— control casetest_hard_link_deletion_and_replacementon FreeBSD/NetBSD/OpenBSD CI — required before merge