Repository navigation
wslc: consolidate size formatting on FormatHumanReadableSize - #41429
Merged
Merged
Conversation
Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR consolidates WSL’s Windows-side size formatting utilities by removing FormatStorageSize/FormatBytes and extending FormatHumanReadableSize to support both decimal (base 1000) and binary (base 1024) units to better align CLI/progress output with Docker’s go-units behavior.
Changes:
- Replaces the legacy size-formatting helpers with
FormatHumanReadableSize(uint64_t, uint32_t, StorageSizeUnit)and updates the unit tables (decimalkB, binary throughYiB). - Updates wslc call sites (progress reporting and prune “reclaimed space” messaging) to use consistent significant-digit precision.
- Updates/rewrites
StringUnitTeststo validate the new signature, binary unit formatting, and round-trip behavior within parser limits.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/windows/StringUnitTests.cpp | Updates unit tests to validate FormatHumanReadableSize for decimal/binary units and new precision expectations. |
| src/windows/wslcsession/WSLCSession.cpp | Updates build/pull progress byte formatting to use the consolidated formatter with consistent precision. |
| src/windows/wslc/tasks/ImageTasks.cpp | Updates image prune “space reclaimed” output to use the consolidated formatter with consistent precision. |
| src/windows/wslc/tasks/ContainerTasks.cpp | Updates stats JSON formatting and container prune “space reclaimed” output to use the consolidated formatter (but introduces a compile error—see comment). |
| src/windows/wslc/services/ImageProgressCallback.cpp | Updates layer download progress formatting to the consolidated formatter with consistent precision. |
| src/windows/common/string.hpp | Removes old APIs and updates the FormatHumanReadableSize declaration/docs to support binary/decimal units. |
| src/windows/common/string.cpp | Implements binary/decimal unit selection inside FormatHumanReadableSize and removes the old helper implementations. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
ggarzia-MSFT
marked this pull request as ready for review
August 24, 2026 22:29
Co-authored-by: Copilot <[email protected]>
Blue (OneBlue)
approved these changes
Aug 25, 2026
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.
Summary of the Pull Request
Consolidates the three size-formatting helpers in
wsl::windows::common::stringdown to one.FormatStorageSizeandFormatBytesare removed;FormatHumanReadableSizegains an optionalStorageSizeUnitso it can render binary units:This also brings several call sites into line with docker.
ParseStorageSizeandStorageSizeUnitare unchanged.PR Checklist
Detailed Description of the Pull Request / Additional comments
The three "Total reclaimed space" messages previously disagreed (image/container used
FormatBytes, volume usedFormatHumanReadableSize); all now use precision 4.image lsandvolume pruneoutput is unchanged.Two smaller corrections fall out: the decimal table uses lowercase
kBper go-units'decimapAbbrs, and the binary table extends toYiBto matchbinaryAbbrs.ParseStorageSize's suffix map is"kmgtp", so anything formatting toEB/EiBor larger cannot be parsed back. That mirrors go-units and already applied to the decimal path; round-trip tests are scoped below 1 EB accordingly.Validation Steps Performed
clang-formatv19.1.5 clean across all 7 changed files.StringUnitTests11/11.FormatStorageSize_UsesRequestedPrecisionis replaced byFormatHumanReadableSize_SupportsBinaryUnits; both round-trip tests re-expressed against the new signature.*WSLCCLI*415/415.