Skip to content

Commit 584a8e8

Browse files
committed
treewide: replace manual MiB calculations with renderSize
1 parent f234633 commit 584a8e8

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/libfetchers/git-utils.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "nix/util/users.hh"
1010
#include "nix/util/fs-sink.hh"
1111
#include "nix/util/sync.hh"
12+
#include "nix/util/util.hh"
1213

1314
#include <git2/attr.h>
1415
#include <git2/blob.h>
@@ -530,12 +531,12 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
530531
auto act = (Activity *) payload;
531532
act->result(
532533
resFetchStatus,
533-
fmt("%d/%d objects received, %d/%d deltas indexed, %.1f MiB",
534+
fmt("%d/%d objects received, %d/%d deltas indexed, %s",
534535
stats->received_objects,
535536
stats->total_objects,
536537
stats->indexed_deltas,
537538
stats->total_deltas,
538-
stats->received_bytes / (1024.0 * 1024.0)));
539+
renderSize(stats->received_bytes)));
539540
return getInterrupted() ? -1 : 0;
540541
}
541542

src/libmain/shared.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "nix/main/loggers.hh"
77
#include "nix/main/progress-bar.hh"
88
#include "nix/util/signals.hh"
9+
#include "nix/util/util.hh"
910

1011
#include <algorithm>
1112
#include <exception>
@@ -64,18 +65,19 @@ void printMissing(ref<Store> store, const MissingPaths & missing, Verbosity lvl)
6465
}
6566

6667
if (!missing.willSubstitute.empty()) {
67-
const float downloadSizeMiB = missing.downloadSize / (1024.f * 1024.f);
68-
const float narSizeMiB = missing.narSize / (1024.f * 1024.f);
6968
if (missing.willSubstitute.size() == 1) {
7069
printMsg(
71-
lvl, "this path will be fetched (%.2f MiB download, %.2f MiB unpacked):", downloadSizeMiB, narSizeMiB);
70+
lvl,
71+
"this path will be fetched (%s download, %s unpacked):",
72+
renderSize(missing.downloadSize),
73+
renderSize(missing.narSize));
7274
} else {
7375
printMsg(
7476
lvl,
75-
"these %d paths will be fetched (%.2f MiB download, %.2f MiB unpacked):",
77+
"these %d paths will be fetched (%s download, %s unpacked):",
7678
missing.willSubstitute.size(),
77-
downloadSizeMiB,
78-
narSizeMiB);
79+
renderSize(missing.downloadSize),
80+
renderSize(missing.narSize));
7981
}
8082
std::vector<const StorePath *> willSubstituteSorted = {};
8183
std::for_each(missing.willSubstitute.begin(), missing.willSubstitute.end(), [&](const StorePath & p) {

src/libstore/gc.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "nix/util/finally.hh"
66
#include "nix/util/unix-domain-socket.hh"
77
#include "nix/util/signals.hh"
8+
#include "nix/util/util.hh"
89
#include "nix/store/posix-fs-canonicalise.hh"
910

1011
#include "store-config-private.hh"
@@ -906,9 +907,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
906907
#endif
907908
;
908909

909-
printInfo(
910-
"note: currently hard linking saves %.2f MiB",
911-
((unsharedSize - actualSize - overhead) / (1024.0 * 1024.0)));
910+
printInfo("note: currently hard linking saves %s", renderSize(unsharedSize - actualSize - overhead));
912911
}
913912

914913
/* While we're at it, vacuum the database. */

0 commit comments

Comments
 (0)