From patchwork Thu May 5 18:51:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D12608: node: manually implement Debug From: phabricator X-Patchwork-Id: 50960 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Thu, 5 May 2022 18:51:44 +0000 durin42 created this revision. Herald added a reviewer: hg-reviewers. Herald added a subscriber: mercurial-patches. REVISION SUMMARY I got too irritated today with the default Debug implementation of hg::revlog::Node while playing with a new parser. This isn't quite what I wanted, but it wasn't much code and it at least gives you output that's easy to visually compare to a node.hex()ed identifier from the Python side of things. Sadly, this doesn't influence the output in lldb or the VSCode debugger extension that uses lldb under the covers, but it at least means debug prints are a little more useful. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D12608 AFFECTED FILES rust/hg-core/src/revlog/node.rs CHANGE DETAILS To: durin42, #hg-reviewers Cc: mercurial-patches, mercurial-devel diff --git a/rust/hg-core/src/revlog/node.rs b/rust/hg-core/src/revlog/node.rs --- a/rust/hg-core/src/revlog/node.rs +++ b/rust/hg-core/src/revlog/node.rs @@ -53,12 +53,21 @@ /// the size or return an error at runtime. /// /// [`nybbles_len`]: #method.nybbles_len -#[derive(Copy, Clone, Debug, PartialEq, BytesCast, derive_more::From)] +#[derive(Copy, Clone, PartialEq, BytesCast, derive_more::From)] #[repr(transparent)] pub struct Node { data: NodeData, } +impl fmt::Debug for Node { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let n = format!("{:x?}", self.data); + // We're using debug_tuple because it makes the output a little + // more compact without losing data. + f.debug_tuple("Node").field(&n).finish() + } +} + /// The node value for NULL_REVISION pub const NULL_NODE: Node = Node { data: [0; NODE_BYTES_LENGTH],