rhg: add full node id support for `debugdata` command
authorAntoine cezar<acezar@chwitlabs.fr>
Tue, 20 Oct 2020 15:09:08 +0200
changeset 45813 57dc78861196
parent 45812 976b26bdd0d8
child 45814 88d5abec8f61
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
rust/hg-core/src/operations/debugdata.rs
tests/test-rhg.t
--- 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