mirror of
https://github.com/facebook/sapling.git
synced 2025-01-06 04:43:19 +03:00
alias: ignore alias definitions with ":" in name
Summary: Aliases with `:doc` in name are not real commands. Do not treat them as commands. The upstream patch https://phab.mercurial-scm.org/D5087 added other metadata including `:help` and `:category`. We might end up having some in the future so I blacklisted names with `:` in them, not just `:doc`. Reviewed By: chadaustin Differential Revision: D16955596 fbshipit-source-id: b6f3e1129b632e0ba43c800e7e6fdd2b52d3b40c
This commit is contained in:
parent
8de5266806
commit
adbe2b2b32
@ -137,6 +137,9 @@ fn expand_args(
|
||||
// XXX: This duplicates with clidispatch. They should be de-duplicated.
|
||||
for name in cfg.keys("alias") {
|
||||
if let Ok(name) = String::from_utf8(name.to_vec()) {
|
||||
if name.contains(":") {
|
||||
continue;
|
||||
}
|
||||
let is_debug = name.starts_with("debug");
|
||||
let i = command_map.len() as isize;
|
||||
command_map.insert(name, if is_debug { -i } else { i });
|
||||
@ -147,21 +150,28 @@ fn expand_args(
|
||||
expand_prefix(&command_map, args[0].clone()).map_err(|e| map_to_python_err(py, e))?;
|
||||
}
|
||||
|
||||
let lookup = move |name: &str| match (cfg.get("alias", name), cfg.get("defaults", name)) {
|
||||
(None, None) => None,
|
||||
(Some(v), None) => String::from_utf8(v.to_vec()).ok(),
|
||||
(None, Some(v)) => String::from_utf8(v.to_vec())
|
||||
.ok()
|
||||
.map(|v| format!("{} {}", name, v)),
|
||||
(Some(a), Some(d)) => {
|
||||
if let (Ok(a), Ok(d)) = (String::from_utf8(a.to_vec()), String::from_utf8(d.to_vec())) {
|
||||
// XXX: This makes defaults override alias if there are conflicted
|
||||
// flags. The desired behavior is to make alias override defaults.
|
||||
// However, [defaults] is deprecated and is likely only used
|
||||
// by tests. So this might be fine.
|
||||
Some(format!("{} {}", a, d))
|
||||
} else {
|
||||
None
|
||||
let lookup = move |name: &str| {
|
||||
if name.contains(":") {
|
||||
return None;
|
||||
}
|
||||
match (cfg.get("alias", name), cfg.get("defaults", name)) {
|
||||
(None, None) => None,
|
||||
(Some(v), None) => String::from_utf8(v.to_vec()).ok(),
|
||||
(None, Some(v)) => String::from_utf8(v.to_vec())
|
||||
.ok()
|
||||
.map(|v| format!("{} {}", name, v)),
|
||||
(Some(a), Some(d)) => {
|
||||
if let (Ok(a), Ok(d)) =
|
||||
(String::from_utf8(a.to_vec()), String::from_utf8(d.to_vec()))
|
||||
{
|
||||
// XXX: This makes defaults override alias if there are conflicted
|
||||
// flags. The desired behavior is to make alias override defaults.
|
||||
// However, [defaults] is deprecated and is likely only used
|
||||
// by tests. So this might be fine.
|
||||
Some(format!("{} {}", a, d))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -123,6 +123,10 @@ fn command_map<'a>(
|
||||
// allows alias expansion to not behave differently for Rust or Python.
|
||||
for name in cfg.keys("alias") {
|
||||
if let Ok(name) = String::from_utf8(name.to_vec()) {
|
||||
if name.contains(":") {
|
||||
// Not a real command.
|
||||
continue;
|
||||
}
|
||||
let is_debug = name.starts_with("debug");
|
||||
command_map.insert(name, if is_debug { -i } else { i });
|
||||
i = i + 1;
|
||||
@ -180,22 +184,30 @@ pub fn dispatch(command_table: &CommandTable, mut args: Vec<String>, io: &mut IO
|
||||
let config = optional_repo.config();
|
||||
|
||||
// Prepare alias handling.
|
||||
let alias_lookup = |name: &str| match (config.get("alias", name), config.get("defaults", name))
|
||||
{
|
||||
(None, None) => None,
|
||||
(Some(v), None) => String::from_utf8(v.to_vec()).ok(),
|
||||
(None, Some(v)) => String::from_utf8(v.to_vec())
|
||||
.ok()
|
||||
.map(|v| format!("{} {}", name, v)),
|
||||
(Some(a), Some(d)) => {
|
||||
if let (Ok(a), Ok(d)) = (String::from_utf8(a.to_vec()), String::from_utf8(d.to_vec())) {
|
||||
// XXX: This makes defaults override alias if there are conflicted
|
||||
// flags. The desired behavior is to make alias override defaults.
|
||||
// However, [defaults] is deprecated and is likely only used
|
||||
// by tests. So this might be fine.
|
||||
Some(format!("{} {}", a, d))
|
||||
} else {
|
||||
None
|
||||
let alias_lookup = |name: &str| {
|
||||
// [alias] can have "<name>:doc" entries that are not commands. Skip them.
|
||||
if name.contains(":") {
|
||||
return None;
|
||||
}
|
||||
|
||||
match (config.get("alias", name), config.get("defaults", name)) {
|
||||
(None, None) => None,
|
||||
(Some(v), None) => String::from_utf8(v.to_vec()).ok(),
|
||||
(None, Some(v)) => String::from_utf8(v.to_vec())
|
||||
.ok()
|
||||
.map(|v| format!("{} {}", name, v)),
|
||||
(Some(a), Some(d)) => {
|
||||
if let (Ok(a), Ok(d)) =
|
||||
(String::from_utf8(a.to_vec()), String::from_utf8(d.to_vec()))
|
||||
{
|
||||
// XXX: This makes defaults override alias if there are conflicted
|
||||
// flags. The desired behavior is to make alias override defaults.
|
||||
// However, [defaults] is deprecated and is likely only used
|
||||
// by tests. So this might be fine.
|
||||
Some(format!("{} {}", a, d))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -772,6 +772,12 @@ return code of command and shell aliases:
|
||||
|
||||
documented aliases
|
||||
|
||||
$ newrepo
|
||||
$ hg documented:doc
|
||||
unknown command 'documented:doc'
|
||||
(use 'hg help' to get help)
|
||||
[255]
|
||||
|
||||
$ hg help documented
|
||||
[^ ].* (re) (?)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user