Patchwork D9862: rust: Exclude empty node prefixes

login
register
mail settings
Submitter phabricator
Date Jan. 25, 2021, 9:13 p.m.
Message ID <differential-rev-PHID-DREV-6shdocgd6xx3xyol5fli-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48173/
State Superseded
Headers show

Comments

phabricator - Jan. 25, 2021, 9:13 p.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We presumably don’t want `--rev ""` to select every single revision,
  even though the empty string is a prefix of all strings.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/hg-core/src/revlog/node.rs

CHANGE DETAILS




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

Patch

diff --git a/rust/hg-core/src/revlog/node.rs b/rust/hg-core/src/revlog/node.rs
--- a/rust/hg-core/src/revlog/node.rs
+++ b/rust/hg-core/src/revlog/node.rs
@@ -159,7 +159,7 @@ 
     pub fn from_hex(hex: impl AsRef<[u8]>) -> Result<Self, FromHexError> {
         let hex = hex.as_ref();
         let len = hex.len();
-        if len > NODE_NYBBLES_LENGTH {
+        if len > NODE_NYBBLES_LENGTH || len == 0 {
             return Err(FromHexError);
         }
 
@@ -200,10 +200,6 @@ 
         }
     }
 
-    pub fn is_empty(&self) -> bool {
-        self.len() == 0
-    }
-
     pub fn is_prefix_of(&self, node: &Node) -> bool {
         if self.is_odd {
             let buf = self.buf;