changeset 45832:57dc78861196

rhg: add full node id support for `debugdata` command Unlike other later implemented commands `debugdata` only supported revision number. This changeset add full node id support for consistency with other commands. Differential Revision: https://phab.mercurial-scm.org/D9230
author Antoine cezar<acezar@chwitlabs.fr>
date Tue, 20 Oct 2020 15:09:08 +0200
parents 976b26bdd0d8
children 88d5abec8f61
files rust/hg-core/src/operations/debugdata.rs tests/test-rhg.t
diffstat 2 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/operations/debugdata.rs	Thu Oct 29 13:54:25 2020 +0100
+++ b/rust/hg-core/src/operations/debugdata.rs	Tue Oct 20 15:09:08 2020 +0200
@@ -92,18 +92,22 @@
     }
 
     pub fn run(&mut self) -> Result<Vec<u8>, DebugDataError> {
-        let rev = self
-            .rev
-            .parse::<Revision>()
-            .or(Err(DebugDataErrorKind::InvalidRevision))?;
-
         let root = find_root::FindRoot::new().run()?;
         let index_file = match self.kind {
             DebugDataKind::Changelog => root.join(".hg/store/00changelog.i"),
             DebugDataKind::Manifest => root.join(".hg/store/00manifest.i"),
         };
         let revlog = Revlog::open(&index_file, None)?;
-        let data = revlog.get_rev_data(rev)?;
+
+        let data = match self.rev.parse::<Revision>() {
+            Ok(rev) => revlog.get_rev_data(rev)?,
+            _ => {
+                let node = hex::decode(&self.rev)
+                    .map_err(|_| DebugDataErrorKind::InvalidRevision)?;
+                let rev = revlog.get_node_rev(&node)?;
+                revlog.get_rev_data(rev)?
+            }
+        };
 
         Ok(data)
     }
--- a/tests/test-rhg.t	Thu Oct 29 13:54:25 2020 +0100
+++ b/tests/test-rhg.t	Tue Oct 20 15:09:08 2020 +0200
@@ -91,6 +91,15 @@
   file2\x005d9299349fc01ddd25d0070d149b124d8f10411e (esc)
   file3\x002661d26c649684b482d10f91960cc3db683c38b4 (esc)
 
+Debuging with full node id
+  $ rhg debugdata -c `hg log -r 0 -T '{node}'`
+  c8e64718e1ca0312eeee0f59d37f8dc612793856
+  test
+  0 0
+  file1
+  
+  commit 1 (no-eol)
+
 Cat files
   $ cd $TESTTMP
   $ rm -rf repository