1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

treewide: replace manual MiB calculations with renderSize

(cherry picked from commit 584a8e8a00)
This commit is contained in:
Marcel 2025-10-27 01:21:02 +01:00 committed by github-actions[bot]
parent 7d7ca3fe96
commit ebadea0734
3 changed files with 13 additions and 11 deletions

View file

@ -9,6 +9,7 @@
#include "nix/util/users.hh" #include "nix/util/users.hh"
#include "nix/util/fs-sink.hh" #include "nix/util/fs-sink.hh"
#include "nix/util/sync.hh" #include "nix/util/sync.hh"
#include "nix/util/util.hh"
#include <git2/attr.h> #include <git2/attr.h>
#include <git2/blob.h> #include <git2/blob.h>
@ -530,12 +531,12 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
auto act = (Activity *) payload; auto act = (Activity *) payload;
act->result( act->result(
resFetchStatus, resFetchStatus,
fmt("%d/%d objects received, %d/%d deltas indexed, %.1f MiB", fmt("%d/%d objects received, %d/%d deltas indexed, %s",
stats->received_objects, stats->received_objects,
stats->total_objects, stats->total_objects,
stats->indexed_deltas, stats->indexed_deltas,
stats->total_deltas, stats->total_deltas,
stats->received_bytes / (1024.0 * 1024.0))); renderSize(stats->received_bytes)));
return getInterrupted() ? -1 : 0; return getInterrupted() ? -1 : 0;
} }

View file

@ -6,6 +6,7 @@
#include "nix/main/loggers.hh" #include "nix/main/loggers.hh"
#include "nix/main/progress-bar.hh" #include "nix/main/progress-bar.hh"
#include "nix/util/signals.hh" #include "nix/util/signals.hh"
#include "nix/util/util.hh"
#include <algorithm> #include <algorithm>
#include <exception> #include <exception>
@ -64,18 +65,19 @@ void printMissing(ref<Store> store, const MissingPaths & missing, Verbosity lvl)
} }
if (!missing.willSubstitute.empty()) { if (!missing.willSubstitute.empty()) {
const float downloadSizeMiB = missing.downloadSize / (1024.f * 1024.f);
const float narSizeMiB = missing.narSize / (1024.f * 1024.f);
if (missing.willSubstitute.size() == 1) { if (missing.willSubstitute.size() == 1) {
printMsg( printMsg(
lvl, "this path will be fetched (%.2f MiB download, %.2f MiB unpacked):", downloadSizeMiB, narSizeMiB); lvl,
"this path will be fetched (%s download, %s unpacked):",
renderSize(missing.downloadSize),
renderSize(missing.narSize));
} else { } else {
printMsg( printMsg(
lvl, lvl,
"these %d paths will be fetched (%.2f MiB download, %.2f MiB unpacked):", "these %d paths will be fetched (%s download, %s unpacked):",
missing.willSubstitute.size(), missing.willSubstitute.size(),
downloadSizeMiB, renderSize(missing.downloadSize),
narSizeMiB); renderSize(missing.narSize));
} }
std::vector<const StorePath *> willSubstituteSorted = {}; std::vector<const StorePath *> willSubstituteSorted = {};
std::for_each(missing.willSubstitute.begin(), missing.willSubstitute.end(), [&](const StorePath & p) { std::for_each(missing.willSubstitute.begin(), missing.willSubstitute.end(), [&](const StorePath & p) {

View file

@ -5,6 +5,7 @@
#include "nix/util/finally.hh" #include "nix/util/finally.hh"
#include "nix/util/unix-domain-socket.hh" #include "nix/util/unix-domain-socket.hh"
#include "nix/util/signals.hh" #include "nix/util/signals.hh"
#include "nix/util/util.hh"
#include "nix/store/posix-fs-canonicalise.hh" #include "nix/store/posix-fs-canonicalise.hh"
#include "store-config-private.hh" #include "store-config-private.hh"
@ -906,9 +907,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
#endif #endif
; ;
printInfo( printInfo("note: currently hard linking saves %s", renderSize(unsharedSize - actualSize - overhead));
"note: currently hard linking saves %.2f MiB",
((unsharedSize - actualSize - overhead) / (1024.0 * 1024.0)));
} }
/* While we're at it, vacuum the database. */ /* While we're at it, vacuum the database. */