Mercurial > public > mercurial-scm > hg-stable
annotate rust/hg-core/src/operations/debugdata.rs @ 52769:1b7a57a5b47a
rust: add safe bindings to bdiff.c
I wrote C FFI bindings manually rather than using a bindgen build step because
there are only 2 structs and 3 functions and they're not going to change.
Note that the relative path in build.rs means that cargo publish will no longer
work. If in the future we want to publish to crates.io, we would probably need
to add a Makefile step that copies bdiff sources into the hg-core crate.
author | Mitchell Kember <mkember@janestreet.com> |
---|---|
date | Wed, 18 Dec 2024 10:35:01 -0500 |
parents | a3fa37bdb7ec |
children |
rev | line source |
---|---|
45533
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 |
51905
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
8 use crate::errors::HgError; |
52308
bd8081e9fd62
rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52286
diff
changeset
|
9 use crate::exit_codes; |
46167
8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents:
46136
diff
changeset
|
10 use crate::repo::Repo; |
52286
039b7caeb4d9
rust-revlog: introduce an `options` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51905
diff
changeset
|
11 use crate::revlog::options::default_revlog_options; |
52308
bd8081e9fd62
rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52286
diff
changeset
|
12 use crate::revlog::{Revlog, RevlogError, RevlogType}; |
45533
b56df13a0450
hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
13 |
b56df13a0450
hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
14 /// Dump the contents data of a revision. |
46136
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46037
diff
changeset
|
15 pub fn debug_data( |
46167
8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents:
46136
diff
changeset
|
16 repo: &Repo, |
46501
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
46499
diff
changeset
|
17 revset: &str, |
51905
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
18 kind: RevlogType, |
46505
b274aa2f20fd
rust: remove three enums that were identical to `RevlogError`
Simon Sapin <simon.sapin@octobus.net>
parents:
46503
diff
changeset
|
19 ) -> Result<Vec<u8>, RevlogError> { |
46136
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46037
diff
changeset
|
20 let index_file = match kind { |
51905
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
21 RevlogType::Changelog => "00changelog.i", |
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
22 RevlogType::Manifestlog => "00manifest.i", |
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
23 _ => { |
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
24 return Err(RevlogError::Other(HgError::abort( |
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
25 format!("invalid revlog type {}", kind), |
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
26 exit_codes::ABORT, |
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
27 None, |
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
28 ))) |
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
29 } |
46136
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46037
diff
changeset
|
30 }; |
51212
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
31 let revlog = Revlog::open( |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
32 &repo.store_vfs(), |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
33 index_file, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
34 None, |
52286
039b7caeb4d9
rust-revlog: introduce an `options` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51905
diff
changeset
|
35 default_revlog_options( |
039b7caeb4d9
rust-revlog: introduce an `options` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51905
diff
changeset
|
36 repo.config(), |
039b7caeb4d9
rust-revlog: introduce an `options` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51905
diff
changeset
|
37 repo.requirements(), |
039b7caeb4d9
rust-revlog: introduce an `options` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51905
diff
changeset
|
38 RevlogType::Changelog, |
039b7caeb4d9
rust-revlog: introduce an `options` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51905
diff
changeset
|
39 )?, |
51212
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
40 )?; |
46501
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
46499
diff
changeset
|
41 let rev = |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
46499
diff
changeset
|
42 crate::revset::resolve_rev_number_or_hex_prefix(revset, &revlog)?; |
52326
a3fa37bdb7ec
rust: normalize `_for_unchecked_rev` naming among revlogs and the index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52308
diff
changeset
|
43 let data = revlog.get_data(rev)?; |
48570
f2f57724d4eb
rhg: Add RevlogEntry::data that does delta resolution
Simon Sapin <simon.sapin@octobus.net>
parents:
46505
diff
changeset
|
44 Ok(data.into_owned()) |
45533
b56df13a0450
hg-core: define a `DebugData` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
45 } |