Patchwork D9230: rhg: add full node id support for `debugdata` command

login
register
mail settings
Submitter phabricator
Date Oct. 20, 2020, 1:48 p.m.
Message ID <differential-rev-PHID-DREV-4h7ralu3h5a7v2nmfovq-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47496/
State Superseded
Headers show

Comments

phabricator - Oct. 20, 2020, 1:48 p.m.
acezar created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Unlike other later implemented commands `debugdata` only supported revision
  number. This changeset add full node id support for consistency with other
  commands.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9230

AFFECTED FILES
  rust/hg-core/src/operations/debugdata.rs
  tests/test-rhg.t

CHANGE DETAILS




To: acezar, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-rhg.t b/tests/test-rhg.t
--- a/tests/test-rhg.t
+++ b/tests/test-rhg.t
@@ -90,3 +90,12 @@ 
   file1\x00b8e02f6433738021a065f94175c7cd23db5f05be (esc)
   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)
diff --git a/rust/hg-core/src/operations/debugdata.rs b/rust/hg-core/src/operations/debugdata.rs
--- a/rust/hg-core/src/operations/debugdata.rs
+++ b/rust/hg-core/src/operations/debugdata.rs
@@ -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)
     }