Patchwork D12608: node: manually implement Debug

login
register
mail settings
Submitter phabricator
Date May 5, 2022, 6:51 p.m.
Message ID <differential-rev-PHID-DREV-l4w4urdjxx3tqu3zrbyl-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50960/
State New
Headers show

Comments

phabricator - May 5, 2022, 6:51 p.m.
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

Patch

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],