In particular:
- A string of ASCII digits can be either an integer on a hex prefix
- The NULL node ID should convert to the NULL revision number
Alphare |
hg-reviewers |
In particular:
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
Path | Packages | |||
---|---|---|---|---|
M | rust/hg-core/src/revlog/revlog.rs (5 lines) | |||
M | rust/hg-core/src/revset.rs (8 lines) | |||
M | tests/test-rhg.t (3 lines) |
Status | Author | Revision | |
---|---|---|---|
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin |
use super::node::{NodePrefix, NODE_BYTES_LENGTH, NULL_NODE}; | use super::node::{NodePrefix, NODE_BYTES_LENGTH, NULL_NODE}; | ||||
use super::nodemap; | use super::nodemap; | ||||
use super::nodemap::{NodeMap, NodeMapError}; | use super::nodemap::{NodeMap, NodeMapError}; | ||||
use super::nodemap_docket::NodeMapDocket; | use super::nodemap_docket::NodeMapDocket; | ||||
use super::patch; | use super::patch; | ||||
use crate::errors::HgError; | use crate::errors::HgError; | ||||
use crate::repo::Repo; | use crate::repo::Repo; | ||||
use crate::revlog::Revision; | use crate::revlog::Revision; | ||||
use crate::NULL_REVISION; | |||||
#[derive(derive_more::From)] | #[derive(derive_more::From)] | ||||
pub enum RevlogError { | pub enum RevlogError { | ||||
InvalidRevision, | InvalidRevision, | ||||
/// Working directory is not supported | /// Working directory is not supported | ||||
WDirUnsupported, | WDirUnsupported, | ||||
/// Found more than one entry whose ID match the requested prefix | /// Found more than one entry whose ID match the requested prefix | ||||
AmbiguousPrefix, | AmbiguousPrefix, | ||||
} | } | ||||
/// Return the full data associated to a node. | /// Return the full data associated to a node. | ||||
#[timed] | #[timed] | ||||
pub fn get_node_rev( | pub fn get_node_rev( | ||||
&self, | &self, | ||||
node: NodePrefix, | node: NodePrefix, | ||||
) -> Result<Revision, RevlogError> { | ) -> Result<Revision, RevlogError> { | ||||
if node.is_prefix_of(&NULL_NODE) { | |||||
return Ok(NULL_REVISION); | |||||
} | |||||
if let Some(nodemap) = &self.nodemap { | if let Some(nodemap) = &self.nodemap { | ||||
return nodemap | return nodemap | ||||
.find_bin(&self.index, node)? | .find_bin(&self.index, node)? | ||||
.ok_or(RevlogError::InvalidRevision); | .ok_or(RevlogError::InvalidRevision); | ||||
} | } | ||||
// Fallback to linear scan when a persistent nodemap is not present. | // Fallback to linear scan when a persistent nodemap is not present. | ||||
// This happens when the persistent-nodemap experimental feature is not | // This happens when the persistent-nodemap experimental feature is not |
/// | /// | ||||
/// * A non-negative decimal integer for a revision number, or | /// * A non-negative decimal integer for a revision number, or | ||||
/// * An hexadecimal string, for the unique node ID that starts with this | /// * An hexadecimal string, for the unique node ID that starts with this | ||||
/// prefix | /// prefix | ||||
pub fn resolve_rev_number_or_hex_prefix( | pub fn resolve_rev_number_or_hex_prefix( | ||||
input: &str, | input: &str, | ||||
revlog: &Revlog, | revlog: &Revlog, | ||||
) -> Result<Revision, RevlogError> { | ) -> Result<Revision, RevlogError> { | ||||
// The Python equivalent of this is part of `revsymbol` in | |||||
// `mercurial/scmutil.py` | |||||
if let Ok(integer) = input.parse::<i32>() { | if let Ok(integer) = input.parse::<i32>() { | ||||
if integer >= 0 && revlog.has_rev(integer) { | if integer.to_string() == input | ||||
&& integer >= 0 | |||||
&& revlog.has_rev(integer) | |||||
{ | |||||
return Ok(integer); | return Ok(integer); | ||||
} | } | ||||
} | } | ||||
if let Ok(prefix) = NodePrefix::from_hex(input) { | if let Ok(prefix) = NodePrefix::from_hex(input) { | ||||
if prefix.is_prefix_of(&Node::from_hex(WORKING_DIRECTORY_HEX).unwrap()) | if prefix.is_prefix_of(&Node::from_hex(WORKING_DIRECTORY_HEX).unwrap()) | ||||
{ | { | ||||
return Err(RevlogError::WDirUnsupported); | return Err(RevlogError::WDirUnsupported); | ||||
} | } | ||||
return revlog.get_node_rev(prefix); | return revlog.get_node_rev(prefix); | ||||
} | } | ||||
Err(RevlogError::InvalidRevision) | Err(RevlogError::InvalidRevision) | ||||
} | } |
file-3 | file-3 | ||||
$ $NO_FALLBACK rhg cat -r cf8b83 file-2 | $ $NO_FALLBACK rhg cat -r cf8b83 file-2 | ||||
2 | 2 | ||||
$ $NO_FALLBACK rhg cat -r c file-2 | $ $NO_FALLBACK rhg cat -r c file-2 | ||||
abort: ambiguous revision identifier: c | abort: ambiguous revision identifier: c | ||||
[255] | [255] | ||||
$ $NO_FALLBACK rhg cat -r d file-2 | $ $NO_FALLBACK rhg cat -r d file-2 | ||||
2 | 2 | ||||
$ $NO_FALLBACK rhg cat -r 0000 file-2 | |||||
abort: invalid revision identifier: 0000 | |||||
[255] | |||||
Cat files | Cat files | ||||
$ cd $TESTTMP | $ cd $TESTTMP | ||||
$ rm -rf repository | $ rm -rf repository | ||||
$ hg init repository | $ hg init repository | ||||
$ cd repository | $ cd repository | ||||
$ echo "original content" > original | $ echo "original content" > original | ||||
$ hg add original | $ hg add original |