comparison rust/hg-core/src/operations/debugdata.rs @ 46433:4b381dbbf8b7

rhg: centralize parsing of `--rev` CLI arguments This new module will be the place to implement more of the revset language when we do so. Differential Revision: https://phab.mercurial-scm.org/D9873
author Simon Sapin <simon.sapin@octobus.net>
date Tue, 26 Jan 2021 18:31:46 +0100
parents 645ee7225fab
children 3e2d539d0d1a
comparison
equal deleted inserted replaced
46432:18a261b11b20 46433:4b381dbbf8b7
5 // This software may be used and distributed according to the terms of the 5 // This software may be used and distributed according to the terms of the
6 // GNU General Public License version 2 or any later version. 6 // GNU General Public License version 2 or any later version.
7 7
8 use crate::repo::Repo; 8 use crate::repo::Repo;
9 use crate::revlog::revlog::{Revlog, RevlogError}; 9 use crate::revlog::revlog::{Revlog, RevlogError};
10 use crate::revlog::NodePrefix;
11 use crate::revlog::Revision;
12 10
13 /// Kind of data to debug 11 /// Kind of data to debug
14 #[derive(Debug, Copy, Clone)] 12 #[derive(Debug, Copy, Clone)]
15 pub enum DebugDataKind { 13 pub enum DebugDataKind {
16 Changelog, 14 Changelog,
77 } 75 }
78 76
79 /// Dump the contents data of a revision. 77 /// Dump the contents data of a revision.
80 pub fn debug_data( 78 pub fn debug_data(
81 repo: &Repo, 79 repo: &Repo,
82 rev: &str, 80 revset: &str,
83 kind: DebugDataKind, 81 kind: DebugDataKind,
84 ) -> Result<Vec<u8>, DebugDataError> { 82 ) -> Result<Vec<u8>, DebugDataError> {
85 let index_file = match kind { 83 let index_file = match kind {
86 DebugDataKind::Changelog => "00changelog.i", 84 DebugDataKind::Changelog => "00changelog.i",
87 DebugDataKind::Manifest => "00manifest.i", 85 DebugDataKind::Manifest => "00manifest.i",
88 }; 86 };
89 let revlog = Revlog::open(repo, index_file, None)?; 87 let revlog = Revlog::open(repo, index_file, None)?;
90 88 let rev =
91 let data = match rev.parse::<Revision>() { 89 crate::revset::resolve_rev_number_or_hex_prefix(revset, &revlog)?;
92 Ok(rev) => revlog.get_rev_data(rev)?, 90 let data = revlog.get_rev_data(rev)?;
93 _ => {
94 let node = NodePrefix::from_hex(&rev)
95 .map_err(|_| DebugDataErrorKind::InvalidRevision)?;
96 let rev = revlog.get_node_rev(node)?;
97 revlog.get_rev_data(rev)?
98 }
99 };
100
101 Ok(data) 91 Ok(data)
102 } 92 }