comparison rust/hg-core/src/revlog/node.rs @ 46429:e61c2dc6e1c2

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
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 25 Jan 2021 12:31:40 +0100
parents 5893706af3de
children 645ee7225fab
comparison
equal deleted inserted replaced
46428:5893706af3de 46429:e61c2dc6e1c2
158 /// To be used in FFI and I/O only, in order to facilitate future 158 /// To be used in FFI and I/O only, in order to facilitate future
159 /// changes of hash format. 159 /// changes of hash format.
160 pub fn from_hex(hex: impl AsRef<[u8]>) -> Result<Self, FromHexError> { 160 pub fn from_hex(hex: impl AsRef<[u8]>) -> Result<Self, FromHexError> {
161 let hex = hex.as_ref(); 161 let hex = hex.as_ref();
162 let len = hex.len(); 162 let len = hex.len();
163 if len > NODE_NYBBLES_LENGTH { 163 if len > NODE_NYBBLES_LENGTH || len == 0 {
164 return Err(FromHexError); 164 return Err(FromHexError);
165 } 165 }
166 166
167 let is_odd = len % 2 == 1; 167 let is_odd = len % 2 == 1;
168 let even_part = if is_odd { &hex[..len - 1] } else { hex }; 168 let even_part = if is_odd { &hex[..len - 1] } else { hex };
197 if self.is_odd { 197 if self.is_odd {
198 self.buf.len() * 2 - 1 198 self.buf.len() * 2 - 1
199 } else { 199 } else {
200 self.buf.len() * 2 200 self.buf.len() * 2
201 } 201 }
202 }
203
204 pub fn is_empty(&self) -> bool {
205 self.len() == 0
206 } 202 }
207 203
208 pub fn is_prefix_of(&self, node: &Node) -> bool { 204 pub fn is_prefix_of(&self, node: &Node) -> bool {
209 if self.is_odd { 205 if self.is_odd {
210 let buf = self.buf; 206 let buf = self.buf;