Skip to content

Commit

Permalink
revsets: support resolving revision numbers in Rust
Browse files Browse the repository at this point in the history
Summary:
I wasn't planning on doing this, but I realized that Rust returns the wrong commit when a revnum looks like a valid hash prefix.

This will make it easier to turn on Rust checkout in existing tests. Previously I was updating revnum usage in "update" commands to use the "desc(...)" revset, but that isn't ideal since it won't actually use the Rust checkout.

Reviewed By: sggutier

Differential Revision: D54037554

fbshipit-source-id: 8755733f912728916f3c5a959efdb21ddc1b873b
  • Loading branch information
muirdm authored and facebook-github-bot committed Mar 4, 2024
1 parent c58dab2 commit 84ad0bb
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions eden/scm/lib/config/loader/src/builtin_static/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ repackfactor=3
timeout=600
color=auto
paginate=true
ignorerevnum=True
[checkout]
resumable=true
Expand Down
1 change: 1 addition & 0 deletions eden/scm/lib/revsets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async-runtime = { version = "0.1.0", path = "../async-runtime" }
configmodel = { version = "0.1.0", path = "../config/model" }
dag = { version = "0.1.0", path = "../dag" }
edenapi = { version = "0.1.0", path = "../edenapi" }
hgplain = { version = "0.1.0", path = "../util/hgplain" }
metalog = { version = "0.1.0", path = "../metalog" }
refencode = { version = "0.1.0", path = "../refencode" }
thiserror = "1.0.49"
Expand Down
1 change: 1 addition & 0 deletions eden/scm/lib/revsets/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ rust_library(
"//eden/scm/lib/refencode:refencode",
"//eden/scm/lib/treestate:treestate",
"//eden/scm/lib/types:types",
"//eden/scm/lib/util/hgplain:hgplain",
],
)
43 changes: 36 additions & 7 deletions eden/scm/lib/revsets/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ use anyhow::anyhow;
use anyhow::bail;
use anyhow::Context;
use anyhow::Result;
use async_runtime::block_on;
use configmodel::Config;
use configmodel::ConfigExt;
use dag::ops::IdConvert;
use dag::DagAlgorithm;
use dag::Id;
use dag::Vertex;
use edenapi::EdenApi;
use metalog::MetaLog;
use refencode::decode_bookmarks;
use refencode::decode_remotenames;
use treestate::treestate::TreeState;
use types::hgid::NULL_ID;
use types::hgid::WDIR_ID;
use types::hgid::WDIR_REV;
use types::HgId;

use crate::errors::RevsetLookupError;
Expand Down Expand Up @@ -56,6 +61,7 @@ pub fn resolve_single(
let fns = [
resolve_special,
resolve_dot,
resolve_revnum,
resolve_bookmark,
resolve_hash_prefix,
];
Expand All @@ -78,15 +84,13 @@ fn resolve_special(args: &LookupArgs) -> Result<Option<HgId>> {
}

if let Some(tip) = args.metalog.get(args.change_id)? {
if async_runtime::block_on(async {
args.id_map.contains_vertex_name(&tip.clone().into()).await
})? {
if block_on(async { args.id_map.contains_vertex_name(&tip.clone().into()).await })? {
return Ok(Some(HgId::from_slice(&tip).context("metalog tip")?));
}
}

Ok(Some(
async_runtime::block_on(async { args.dag.all().await?.first().await })?
block_on(async { args.dag.all().await?.first().await })?
.map_or_else(|| Ok(NULL_ID), |v| HgId::from_slice(v.as_ref()))?,
))
}
Expand Down Expand Up @@ -131,7 +135,7 @@ fn resolve_hash_prefix(args: &LookupArgs) -> Result<Option<HgId>> {
}
};

if async_runtime::block_on(async {
if block_on(async {
args.id_map
.contains_vertex_name(&Vertex::copy_from(hgid.as_ref()))
.await
Expand All @@ -143,7 +147,7 @@ fn resolve_hash_prefix(args: &LookupArgs) -> Result<Option<HgId>> {
}

fn local_hash_prefix_lookup(args: &LookupArgs) -> Result<Option<HgId>> {
let hgids = async_runtime::block_on(async {
let hgids = block_on(async {
args.id_map
.vertexes_by_hex_prefix(args.change_id.as_bytes(), 5)
.await
Expand All @@ -165,7 +169,7 @@ fn remote_hash_prefix_lookup(args: &LookupArgs) -> Result<Option<HgId>> {
None => return Ok(None),
};

let mut response = async_runtime::block_on(async {
let mut response = block_on(async {
edenapi
.hash_prefixes_lookup(vec![args.change_id.to_string()])
.await
Expand Down Expand Up @@ -233,3 +237,28 @@ fn metalog_bookmarks(
Ok(decoder(raw_bookmarks.as_slice())
.map_err(|err| RevsetLookupError::BookmarkDecodeError(bookmark_type.to_owned(), err))?)
}

fn resolve_revnum(args: &LookupArgs) -> Result<Option<HgId>> {
if !hgplain::is_plain(None) && args.config.get_or_default("ui", "ignorerevnum")? {
return Ok(None);
}

let rev: i64 = match args.change_id.parse() {
Err(_) => return Ok(None),
Ok(rev) => rev,
};

match rev {
-1 => Ok(Some(NULL_ID)),
WDIR_REV => Ok(Some(WDIR_ID)),
rev => {
let name = block_on(async { args.id_map.vertex_name(Id(rev as u64)).await })?;
Ok(Some(HgId::from_byte_array(
name.0
.into_vec()
.try_into()
.map_err(|v| anyhow!("unexpected vertex name length: {:?}", v))?,
)))
}
}
}
1 change: 0 additions & 1 deletion eden/scm/sapling/configitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ def getitemregister(configtable):
coreconfigitem("ui", "gitignore", default=True)
coreconfigitem("ui", "graphnodetemplate", default=None)
coreconfigitem("ui", "http2debuglevel", default=None)
coreconfigitem("ui", "ignorerevnum", default=True)
coreconfigitem("ui", "interactive", default=None)
coreconfigitem("ui", "interface", default=None)
coreconfigitem("ui", "interface.chunkselector", default=None)
Expand Down
1 change: 1 addition & 0 deletions eden/scm/tests/test-hgrc.t
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ make sure global options given on the cmdline take precedence
ui.timeout=600
ui.color=auto
ui.paginate=true
ui.ignorerevnum=True
ui.verbose=false
ui.debug=false
ui.quiet=true
Expand Down
1 change: 1 addition & 0 deletions eden/scm/tests/test-shelve.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

$ configure modernclient
$ setconfig devel.segmented-changelog-rev-compat=true
$ setconfig checkout.use-rust=true

$ cat >> $HGRCPATH << 'EOF'
> [extensions]
Expand Down

0 comments on commit 84ad0bb

Please sign in to comment.