Skip to content

wslc: consolidate size formatting on FormatHumanReadableSize - #41429

Merged
ggarzia-MSFT merged 2 commits into
masterfrom
user/ggarzia/consolidate-size-formatting
Aug 25, 2026
Merged

ggarzia-MSFT merged 2 commits into
masterfrom
user/ggarzia/consolidate-size-formatting

Conversation

@ggarzia-MSFT

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

Consolidates the three size-formatting helpers in wsl::windows::common::string down to one. FormatStorageSize and FormatBytes are removed; FormatHumanReadableSize gains an optional StorageSizeUnit so it can render binary units:

std::wstring FormatHumanReadableSize(uint64_t Bytes, uint32_t Precision = 3, StorageSizeUnit Unit = StorageSizeUnit::Decimal);

This also brings several call sites into line with docker. ParseStorageSize and StorageSizeUnit are unchanged.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

The three "Total reclaimed space" messages previously disagreed (image/container used FormatBytes, volume used FormatHumanReadableSize); all now use precision 4. image ls and volume prune output is unchanged.

Two smaller corrections fall out: the decimal table uses lowercase kB per go-units' decimapAbbrs, and the binary table extends to YiB to match binaryAbbrs.

ParseStorageSize's suffix map is "kmgtp", so anything formatting to EB/EiB or 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

  • Full build, 0 errors; clang-format v19.1.5 clean across all 7 changed files.
  • StringUnitTests 11/11. FormatStorageSize_UsesRequestedPrecision is replaced by FormatHumanReadableSize_SupportsBinaryUnits; both round-trip tests re-expressed against the new signature.
  • *WSLCCLI* 415/415.

Copilot AI lite review requested due to automatic review settings August 24, 2026 22:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (decimal kB, binary through YiB).
  • Updates wslc call sites (progress reporting and prune “reclaimed space” messaging) to use consistent significant-digit precision.
  • Updates/rewrites StringUnitTests to 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
ggarzia-MSFT marked this pull request as ready for review August 24, 2026 22:29
@ggarzia-MSFT
ggarzia-MSFT requested review from a team as code owners August 24, 2026 22:29
Copilot AI review requested due to automatic review settings August 24, 2026 22:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@ggarzia-MSFT
ggarzia-MSFT merged commit 39551c5 into master Aug 25, 2026
12 checks passed
@ggarzia-MSFT
ggarzia-MSFT deleted the user/ggarzia/consolidate-size-formatting branch August 25, 2026 18:20
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.

3 participants