Mercurial > public > mercurial-scm > hg
annotate rust/hg-core/src/operations/debugdata.rs @ 49087:bfc117647c71
rust-revlog: move check for nodemap requirement to caller
It's good for both making `Revlog` testable and reusable to have it
not depend on the higher-level `Repo` type. This patch is one step in
towards that. Additionally, this change in particular gives the
callers more control over when to use a nodemap.
Differential Revision: https://phab.mercurial-scm.org/D12546
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 12 Apr 2022 11:40:37 -0700 |
parents | f2f57724d4eb |
children | 399439c12223 |
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); |
bfc117647c71
rust-revlog: move check for nodemap requirement to caller
Martin von Zweigbergk <martinvonz@google.com>
parents:
48541
diff
changeset
|
32 let revlog = Revlog::open(repo, index_file, None, use_nodemap)?; |
46433
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
46431
diff
changeset
|
33 let rev = |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
46431
diff
changeset
|
34 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
|
35 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
|
36 Ok(data.into_owned()) |
45527
b56df13a0450
hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
37 } |