# HG changeset patch # User Raphaël Gomès # Date 2022-03-29 15:27:36 # Node ID 28a6178a07a20b87df263f152036cbbe3a38cba7 # Parent d9a66d62c604143701bff59599fdeec04a62bb1a rust: add `Debug` trait to a bunch of structs This is useful when... debugging. Right now the output is not in the most readable state it could be, but this is very low effort and is good enough for now. We may want to write a nicer custom debug formatter for some of those structs in the future. Differential Revision: https://phab.mercurial-scm.org/D12523 diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs b/rust/hg-core/src/dirstate_tree/dirstate_map.rs --- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs +++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs @@ -32,6 +32,7 @@ use crate::StatusOptions; /// anymore) is less than this fraction of the total amount of existing data. const ACCEPTABLE_UNREACHABLE_BYTES_RATIO: f32 = 0.5; +#[derive(Debug)] pub struct DirstateMap<'on_disk> { /// Contents of the `.hg/dirstate` file pub(super) on_disk: &'on_disk [u8], @@ -61,21 +62,25 @@ pub(super) type NodeKey<'on_disk> = With /// Similar to `&'tree Cow<'on_disk, HgPath>`, but can also be returned /// for on-disk nodes that don’t actually have a `Cow` to borrow. +#[derive(Debug)] pub(super) enum BorrowedPath<'tree, 'on_disk> { InMemory(&'tree HgPathBuf), OnDisk(&'on_disk HgPath), } +#[derive(Debug)] pub(super) enum ChildNodes<'on_disk> { InMemory(FastHashMap, Node<'on_disk>>), OnDisk(&'on_disk [on_disk::Node]), } +#[derive(Debug)] pub(super) enum ChildNodesRef<'tree, 'on_disk> { InMemory(&'tree FastHashMap, Node<'on_disk>>), OnDisk(&'on_disk [on_disk::Node]), } +#[derive(Debug)] pub(super) enum NodeRef<'tree, 'on_disk> { InMemory(&'tree NodeKey<'on_disk>, &'tree Node<'on_disk>), OnDisk(&'on_disk on_disk::Node), @@ -383,7 +388,7 @@ impl<'tree, 'on_disk> NodeRef<'tree, 'on } /// Represents a file or a directory -#[derive(Default)] +#[derive(Default, Debug)] pub(super) struct Node<'on_disk> { pub(super) data: NodeData, @@ -399,6 +404,7 @@ pub(super) struct Node<'on_disk> { pub(super) tracked_descendants_count: u32, } +#[derive(Debug)] pub(super) enum NodeData { Entry(DirstateEntry), CachedDirectory { mtime: TruncatedTimestamp }, diff --git a/rust/hg-core/src/dirstate_tree/on_disk.rs b/rust/hg-core/src/dirstate_tree/on_disk.rs --- a/rust/hg-core/src/dirstate_tree/on_disk.rs +++ b/rust/hg-core/src/dirstate_tree/on_disk.rs @@ -84,7 +84,7 @@ pub struct TreeMetadata { /// Fields are documented in the *The data file format* /// section of `mercurial/helptext/internals/dirstate-v2.txt` -#[derive(BytesCast)] +#[derive(BytesCast, Debug)] #[repr(C)] pub(super) struct Node { full_path: PathSlice, @@ -124,7 +124,7 @@ bitflags! { } /// Duration since the Unix epoch -#[derive(BytesCast, Copy, Clone)] +#[derive(BytesCast, Copy, Clone, Debug)] #[repr(C)] struct PackedTruncatedTimestamp { truncated_seconds: U32Be, @@ -152,7 +152,7 @@ type PathSize = U16Be; /// Always sorted by ascending `full_path`, to allow binary search. /// Since nodes with the same parent nodes also have the same parent path, /// only the `base_name`s need to be compared during binary search. -#[derive(BytesCast, Copy, Clone)] +#[derive(BytesCast, Copy, Clone, Debug)] #[repr(C)] struct ChildNodes { start: Offset, @@ -160,7 +160,7 @@ struct ChildNodes { } /// A `HgPath` of `len` bytes -#[derive(BytesCast, Copy, Clone)] +#[derive(BytesCast, Copy, Clone, Debug)] #[repr(C)] struct PathSlice { start: Offset,