From 6ff0940a6927deb7cf4023d12dbe1418a8c9e26b Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Thu, 6 Aug 2020 19:15:19 +0200 Subject: [PATCH] Pretty-print binary data in .ccache-input-text files This happens when the i-node cache is enabled. --- src/Hash.cpp | 14 +++++++++++--- src/Hash.hpp | 11 ++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Hash.cpp b/src/Hash.cpp index 78d5e7c47..da65d5830 100644 --- a/src/Hash.cpp +++ b/src/Hash.cpp @@ -71,10 +71,18 @@ Hash::hash(const void* data, size_t size, HashType hash_type) { string_view buffer(static_cast(data), size); hash_buffer(buffer); - add_debug_text(buffer); - if (hash_type == HashType::text) { - add_debug_text("\n"); + + switch (hash_type) { + case HashType::binary: + add_debug_text(Util::format_hex(static_cast(data), size)); + break; + + case HashType::text: + add_debug_text(buffer); + break; } + + add_debug_text("\n"); return *this; } diff --git a/src/Hash.hpp b/src/Hash.hpp index 9c96b5cdf..d2686aff2 100644 --- a/src/Hash.hpp +++ b/src/Hash.hpp @@ -56,9 +56,14 @@ public: // Add bytes to the hash. // - // If hash debugging is enabled, the buffer content is written verbatim to the - // text input file, followed by a newline character if `hash_type` is - // HashType::text. + // If hash debugging is enabled: + // + // - If `hash_type` is `HashType::binary`, the buffer content is written in + // hex format to the text input file. + // - If `hash_type` is `HashType::text`, the buffer content is written + // verbatim to the text input file. + // + // In both cases a newline character is added as well. Hash& hash(const void* data, size_t size, HashType hash_type = HashType::text); -- 2.47.3