annotate rust/hg-core/src/operations/debugdata.rs @ 49175:34decbaf4da3

node: manually implement Debug 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. Differential Revision: https://phab.mercurial-scm.org/D12608
author Augie Fackler <augie@google.com>
date Thu, 05 May 2022 14:47:26 -0400
parents 399439c12223
children 750409505286
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45527
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1 // debugdata.rs
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
2 //
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
3 // Copyright 2020 Antoine Cezar <antoine.cezar@octobus.net>
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
4 //
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
5 // This software may be used and distributed according to the terms of the
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
6 // GNU General Public License version 2 or any later version.
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
7
46167
8a4914397d02 rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents: 46135
diff changeset
8 use crate::repo::Repo;
49087
bfc117647c71 rust-revlog: move check for nodemap requirement to caller
Martin von Zweigbergk <martinvonz@google.com>
parents: 48541
diff changeset
9 use crate::requirements;
45527
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
10 use crate::revlog::revlog::{Revlog, RevlogError};
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
11
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
12 /// Kind of data to debug
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
13 #[derive(Debug, Copy, Clone)]
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
14 pub enum DebugDataKind {
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
15 Changelog,
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
16 Manifest,
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
17 }
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
18
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
19 /// Dump the contents data of a revision.
46135
dca9cb99971c rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents: 46033
diff changeset
20 pub fn debug_data(
46167
8a4914397d02 rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents: 46135
diff changeset
21 repo: &Repo,
46433
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46431
diff changeset
22 revset: &str,
45527
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
23 kind: DebugDataKind,
46437
b274aa2f20fd rust: remove three enums that were identical to `RevlogError`
Simon Sapin <simon.sapin@octobus.net>
parents: 46435
diff changeset
24 ) -> Result<Vec<u8>, RevlogError> {
46135
dca9cb99971c rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents: 46033
diff changeset
25 let index_file = match kind {
46167
8a4914397d02 rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents: 46135
diff changeset
26 DebugDataKind::Changelog => "00changelog.i",
8a4914397d02 rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents: 46135
diff changeset
27 DebugDataKind::Manifest => "00manifest.i",
46135
dca9cb99971c rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents: 46033
diff changeset
28 };
49087
bfc117647c71 rust-revlog: move check for nodemap requirement to caller
Martin von Zweigbergk <martinvonz@google.com>
parents: 48541
diff changeset
29 let use_nodemap = repo
bfc117647c71 rust-revlog: move check for nodemap requirement to caller
Martin von Zweigbergk <martinvonz@google.com>
parents: 48541
diff changeset
30 .requirements()
bfc117647c71 rust-revlog: move check for nodemap requirement to caller
Martin von Zweigbergk <martinvonz@google.com>
parents: 48541
diff changeset
31 .contains(requirements::NODEMAP_REQUIREMENT);
49089
399439c12223 rust-revlog: make unaware of `Repo`
Martin von Zweigbergk <martinvonz@google.com>
parents: 49087
diff changeset
32 let revlog =
399439c12223 rust-revlog: make unaware of `Repo`
Martin von Zweigbergk <martinvonz@google.com>
parents: 49087
diff changeset
33 Revlog::open(&repo.store_vfs(), index_file, None, use_nodemap)?;
46433
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46431
diff changeset
34 let rev =
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46431
diff changeset
35 crate::revset::resolve_rev_number_or_hex_prefix(revset, &revlog)?;
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46431
diff changeset
36 let data = revlog.get_rev_data(rev)?;
48541
f2f57724d4eb rhg: Add RevlogEntry::data that does delta resolution
Simon Sapin <simon.sapin@octobus.net>
parents: 46437
diff changeset
37 Ok(data.into_owned())
45527
b56df13a0450 hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
38 }