Mercurial > hg
view rust/hg-core/src/revset.rs @ 47093:787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
This changeset starts a series that adds an experiment to make status faster
by changing the dirstate (first only in memory and later also on disk) to
be shaped as a tree matching the directory structure, instead of the current
flat collection of entries. The status algorithm can then traverse this tree
dirstate at the same time as it traverses the filesystem.
We (Octobus) have made prototypes that show promising results but are prone
to bitrot. We would like to start upstreaming some experimental Rust code that
goes in this direction, but to avoid disrupting users it should only be
enabled by some run-time opt-in while keeping the existing dirstate structure
and status algorithm as-is.
The `DirstateMap` type and `status` function look like the appropriate
boundary. This adds a new trait that abstracts everything Python bindings need
and makes those bindings go through a `dyn` trait object. Later we’ll have two
implementations of this trait, and the same bindings can use either.
Differential Revision: https://phab.mercurial-scm.org/D10362
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Tue, 30 Mar 2021 14:15:23 +0200 |
parents | e8ae91b1a63d |
children | 21d25e9ee58e |
line wrap: on
line source
//! The revset query language //! //! <https://www.mercurial-scm.org/repo/hg/help/revsets> use crate::errors::HgError; use crate::repo::Repo; use crate::revlog::changelog::Changelog; use crate::revlog::revlog::{Revlog, RevlogError}; use crate::revlog::NodePrefix; use crate::revlog::{Revision, NULL_REVISION, WORKING_DIRECTORY_HEX}; use crate::Node; /// Resolve a query string into a single revision. /// /// Only some of the revset language is implemented yet. pub fn resolve_single( input: &str, repo: &Repo, ) -> Result<Revision, RevlogError> { let changelog = Changelog::open(repo)?; match resolve_rev_number_or_hex_prefix(input, &changelog.revlog) { Err(RevlogError::InvalidRevision) => {} // Try other syntax result => return result, } if input == "null" { return Ok(NULL_REVISION); } // TODO: support for the rest of the language here. Err( HgError::unsupported(format!("cannot parse revset '{}'", input)) .into(), ) } /// Resolve the small subset of the language suitable for revlogs other than /// the changelog, such as in `hg debugdata --manifest` CLI argument. /// /// * A non-negative decimal integer for a revision number, or /// * An hexadecimal string, for the unique node ID that starts with this /// prefix pub fn resolve_rev_number_or_hex_prefix( input: &str, revlog: &Revlog, ) -> Result<Revision, RevlogError> { if let Ok(integer) = input.parse::<i32>() { if integer >= 0 && revlog.has_rev(integer) { return Ok(integer); } } if let Ok(prefix) = NodePrefix::from_hex(input) { if prefix.is_prefix_of(&Node::from_hex(WORKING_DIRECTORY_HEX).unwrap()) { return Err(RevlogError::WDirUnsupported); } return revlog.get_node_rev(prefix); } Err(RevlogError::InvalidRevision) }