diff: add --stats, showing a summary of the differences - #10327
Open
ThomasWaldmann wants to merge 2 commits into
Open
diff: add --stats, showing a summary of the differences#10327ThomasWaldmann wants to merge 2 commits into
ThomasWaldmann wants to merge 2 commits into
Conversation
…ckup#796 borg diff so far only reported per-item changes. Add -s/--stats, printing an aggregated summary after the per-path output: Added items: 23 Removed items: 2 Changed items: 315 Added chunk volume: 53.70 MB Removed chunk volume: 51.10 MB Added/removed items only exist in one of the archives, changed items exist in both but differ. The chunk volumes sum up the size of the content chunks added/removed by all of these items. If the archives were created with different chunker params, borg compares the content byte by byte and cannot tell by how much it changed. Such items contribute no byte counts, so an additional "Items with unknown size changes" line reports how many there are. The text summary goes to the borg.output.stats logger (stderr), like the --stats output of other commands, so stdout stays clean for piping. With --json-lines, the summary is emitted as a final {"stats": {...}} line instead, which is easy to tell apart from the per-path lines. The change filtering that the text and JSON output paths did separately is now done once in reported_changes(), feeding both the output and the stats, so the summary counts exactly what was printed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10327 +/- ##
==========================================
+ Coverage 87.65% 87.72% +0.07%
==========================================
Files 103 103
Lines 18716 18756 +40
Branches 2881 2889 +8
==========================================
+ Hits 16405 16454 +49
+ Misses 1609 1600 -9
Partials 702 702 ☔ View full report in Codecov by Harness. |
test_stats_counts_metadata_only_changes made its metadata-only change with os.chmod(0o700). On Windows, chmod only toggles the read-only bit, so the stored mode did not change and file_touched was not reported as a changed item at all: the test expected 3 changed items, but got 2. Change the file's mtime instead, which is a metadata change borg reports on every platform. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #796.
borg diffso far only reported per-item changes. This adds-s/--stats,printing an aggregated summary after the per-path output:
exist in both archives but differ.
added/removed by all of these items (a modified file contributes both its new
and its old chunk bytes).
--content-onlynarrows the counts the same way it narrows the output.If the archives were created with different chunker params, borg compares the
content byte by byte and cannot tell by how much it changed. Such items
contribute no byte counts, so the totals are not silently misleading — an
additional line reports how many there are:
The text summary goes to the
borg.output.statslogger (stderr), like the--statsoutput of other commands, so stdout stays clean for piping. With--json-lines, the summary is emitted as a final line of its own shapeinstead, so existing per-path parsers are unaffected:
{"stats": {"added_chunk_volume": 242000, "added_items": 2, "changed_items": 1, "removed_chunk_volume": 105000, "removed_items": 2, "unknown_size_items": 0}}The change filtering that the text and JSON output paths each did separately is
now done once in
reported_changes(), feeding both the output and the stats, sothe summary counts exactly what was printed.
Tests cover the text summary, metadata-only changes counting as changed items,
the JSON Lines summary, the unknown-size path, and that nothing is printed
without the flag. The
diffepilog documents all of the above.🤖 Generated with Claude Code