rust: Exclude empty node prefixes
authorSimon Sapin <simon.sapin@octobus.net>
Mon, 25 Jan 2021 12:31:40 +0100
changeset 46497 e61c2dc6e1c2
parent 46496 5893706af3de
child 46498 b84c3d43ff2e
rust: Exclude empty node prefixes We presumably don’t want `--rev ""` to select every single revision, even though the empty string is a prefix of all strings. Differential Revision: https://phab.mercurial-scm.org/D9862
rust/hg-core/src/revlog/node.rs
--- a/rust/hg-core/src/revlog/node.rs	Mon Jan 25 12:28:39 2021 +0100
+++ b/rust/hg-core/src/revlog/node.rs	Mon Jan 25 12:31:40 2021 +0100
@@ -160,7 +160,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);
         }
 
@@ -201,10 +201,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;