revsets: change DAG range operator ,, operator to : (#46)

This commit is contained in:
Martin von Zweigbergk 2021-12-11 23:50:26 -08:00
parent 63c90c04c8
commit 98659a16e1
5 changed files with 38 additions and 38 deletions

View File

@ -168,14 +168,14 @@ o 000000000000 000000000000 1970-01-01 00:00:00.000 +00:00
It's the root commit of every repo. The `root` symbol in the revset matches it.)
There are also operators for getting the parents (`foo~`), children (`foo+`),
ancestors (`,,foo`), descendants (`foo,,`), DAG range (`foo,,bar`, like
ancestors (`:foo`), descendants (`foo:`), DAG range (`foo:bar`, like
`git log --ancestry-path`), range (`foo,,,bar`, like Git's `foo..bar`). There
are also a few more functions, such as `heads(<set>)`, which filters out
revisions in the input set if they're ancestors of other revisions in the set.
Let's define an alias based on that by adding the following to `~/.jjconfig`:
```
[alias]
l = ["log", "-r", "(heads(remote_branches()),,,@),,"]
l = ["log", "-r", "(heads(remote_branches()),,,@):"]
```
The alias lets us run `jj l` to see the commits we have created between public

View File

@ -25,9 +25,9 @@ children_op = { "+" }
// We could use the same rule name for the shared operators if we can
// think of a good name.
ancestors_op = { ",," }
descendants_op = { ",," }
dag_range_op = { ",," }
ancestors_op = { ":" }
descendants_op = { ":" }
dag_range_op = { ":" }
range_op = { ",,," }
union_op = { "|" }

View File

@ -1328,11 +1328,11 @@ mod tests {
// Parse the "children" operator
assert_eq!(parse("@+"), Ok(checkout_symbol.children()));
// Parse the "ancestors" operator
assert_eq!(parse(",,@"), Ok(checkout_symbol.ancestors()));
assert_eq!(parse(":@"), Ok(checkout_symbol.ancestors()));
// Parse the "descendants" operator
assert_eq!(parse("@,,"), Ok(checkout_symbol.descendants()));
assert_eq!(parse("@:"), Ok(checkout_symbol.descendants()));
// Parse the "dag range" operator
assert_eq!(parse("foo,,bar"), Ok(foo_symbol.dag_range_to(&bar_symbol)));
assert_eq!(parse("foo:bar"), Ok(foo_symbol.dag_range_to(&bar_symbol)));
// Parse the "intersection" operator
assert_eq!(parse("foo & bar"), Ok(foo_symbol.intersection(&bar_symbol)));
// Parse the "union" operator
@ -1342,9 +1342,9 @@ mod tests {
// Parentheses are allowed before suffix operators
assert_eq!(parse("(@)~"), Ok(checkout_symbol.parents()));
// Space is allowed around expressions
assert_eq!(parse(" ,,@ "), Ok(checkout_symbol.ancestors()));
assert_eq!(parse(" :@ "), Ok(checkout_symbol.ancestors()));
// Space is not allowed around prefix operators
assert_matches!(parse(" ,, @ "), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse(" : @ "), Err(RevsetParseError::SyntaxError(_)));
// Incomplete parse
assert_matches!(parse("foo | ~"), Err(RevsetParseError::SyntaxError(_)));
// Space is allowed around infix operators and function arguments
@ -1371,17 +1371,17 @@ mod tests {
Ok(foo_symbol.children().children().children())
);
// Parse repeated "ancestors"/"descendants"/"dag range" operators
assert_matches!(parse(",,foo,,"), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse(",,,,foo"), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse("foo,,,,"), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse("foo,,,,bar"), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse(",,foo,,bar"), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse("foo,,bar,,"), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse(":foo:"), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse("::foo"), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse("foo::"), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse("foo::bar"), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse(":foo:bar"), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse("foo:bar:"), Err(RevsetParseError::SyntaxError(_)));
// Parse combinations of "parents"/"children" operators and the range operators.
// The former bind more strongly.
assert_eq!(parse("foo~+"), Ok(foo_symbol.parents().children()));
assert_eq!(parse("foo~,,"), Ok(foo_symbol.parents().descendants()));
assert_eq!(parse(",,foo+"), Ok(foo_symbol.children().ancestors()));
assert_eq!(parse("foo~:"), Ok(foo_symbol.parents().descendants()));
assert_eq!(parse(":foo+"), Ok(foo_symbol.children().ancestors()));
}
#[test]

View File

@ -615,14 +615,14 @@ fn test_evaluate_expression_ancestors(use_git: bool) {
// The ancestors of the root commit is just the root commit itself
assert_eq!(
resolve_commit_ids(mut_repo.as_repo_ref(), ",,root"),
resolve_commit_ids(mut_repo.as_repo_ref(), ":root"),
vec![root_commit.id().clone()]
);
// Can find ancestors of a specific commit. Commits reachable via multiple paths
// are not repeated.
assert_eq!(
resolve_commit_ids(mut_repo.as_repo_ref(), &format!(",,{}", commit4.id().hex())),
resolve_commit_ids(mut_repo.as_repo_ref(), &format!(":{}", commit4.id().hex())),
vec![
commit4.id().clone(),
commit3.id().clone(),
@ -715,7 +715,7 @@ fn test_evaluate_expression_dag_range(use_git: bool) {
// Can get DAG range of just the root commit
assert_eq!(
resolve_commit_ids(mut_repo.as_repo_ref(), "root,,root"),
resolve_commit_ids(mut_repo.as_repo_ref(), "root:root"),
vec![root_commit_id.clone()]
);
@ -723,7 +723,7 @@ fn test_evaluate_expression_dag_range(use_git: bool) {
assert_eq!(
resolve_commit_ids(
mut_repo.as_repo_ref(),
&format!("{},,{}", root_commit_id.hex(), commit2.id().hex())
&format!("{}:{}", root_commit_id.hex(), commit2.id().hex())
),
vec![commit2.id().clone(), commit1.id().clone(), root_commit_id,]
);
@ -732,7 +732,7 @@ fn test_evaluate_expression_dag_range(use_git: bool) {
assert_eq!(
resolve_commit_ids(
mut_repo.as_repo_ref(),
&format!("{},,{}", commit2.id().hex(), commit4.id().hex())
&format!("{}:{}", commit2.id().hex(), commit4.id().hex())
),
vec![]
);
@ -741,7 +741,7 @@ fn test_evaluate_expression_dag_range(use_git: bool) {
assert_eq!(
resolve_commit_ids(
mut_repo.as_repo_ref(),
&format!("{},,{}", commit1.id().hex(), commit5.id().hex())
&format!("{}:{}", commit1.id().hex(), commit5.id().hex())
),
vec![
commit5.id().clone(),
@ -756,7 +756,7 @@ fn test_evaluate_expression_dag_range(use_git: bool) {
assert_eq!(
resolve_commit_ids(
mut_repo.as_repo_ref(),
&format!("{},,{}", commit2.id().hex(), commit5.id().hex())
&format!("{}:{}", commit2.id().hex(), commit5.id().hex())
),
vec![
commit5.id().clone(),
@ -794,7 +794,7 @@ fn test_evaluate_expression_descendants(use_git: bool) {
// The descendants of the root commit are all the commits in the repo
assert_eq!(
resolve_commit_ids(mut_repo.as_repo_ref(), "root,,"),
resolve_commit_ids(mut_repo.as_repo_ref(), "root:"),
vec![
commit5.id().clone(),
commit4.id().clone(),
@ -808,7 +808,7 @@ fn test_evaluate_expression_descendants(use_git: bool) {
// Can find descendants of a specific commit
assert_eq!(
resolve_commit_ids(mut_repo.as_repo_ref(), &format!("{},,", commit2.id().hex())),
resolve_commit_ids(mut_repo.as_repo_ref(), &format!("{}:", commit2.id().hex())),
vec![
commit5.id().clone(),
commit3.id().clone(),
@ -1178,7 +1178,7 @@ fn test_evaluate_expression_merges(use_git: bool) {
assert_eq!(
resolve_commit_ids(
mut_repo.as_repo_ref(),
&format!("merges(,,{})", commit5.id().hex())
&format!("merges(:{})", commit5.id().hex())
),
vec![commit5.id().clone()]
);
@ -1248,7 +1248,7 @@ fn test_evaluate_expression_union(use_git: bool) {
assert_eq!(
resolve_commit_ids(
mut_repo.as_repo_ref(),
&format!(",,{} | ,,{}", commit4.id().hex(), commit5.id().hex())
&format!(":{} | :{}", commit4.id().hex(), commit5.id().hex())
),
vec![
commit5.id().clone(),
@ -1265,7 +1265,7 @@ fn test_evaluate_expression_union(use_git: bool) {
resolve_commit_ids(
mut_repo.as_repo_ref(),
&format!(
"(,,{} - ,,{}) | ,,{}",
"(:{} - :{}) | :{}",
commit4.id().hex(),
commit2.id().hex(),
commit5.id().hex()
@ -1286,7 +1286,7 @@ fn test_evaluate_expression_union(use_git: bool) {
resolve_commit_ids(
mut_repo.as_repo_ref(),
&format!(
"(,,{} - ,,{}) | {}",
"(:{} - :{}) | {}",
commit4.id().hex(),
commit2.id().hex(),
commit5.id().hex(),
@ -1321,7 +1321,7 @@ fn test_evaluate_expression_intersection(use_git: bool) {
assert_eq!(
resolve_commit_ids(
mut_repo.as_repo_ref(),
&format!(",,{} & ,,{}", commit4.id().hex(), commit5.id().hex())
&format!(":{} & :{}", commit4.id().hex(), commit5.id().hex())
),
vec![
commit2.id().clone(),
@ -1361,21 +1361,21 @@ fn test_evaluate_expression_difference(use_git: bool) {
assert_eq!(
resolve_commit_ids(
mut_repo.as_repo_ref(),
&format!(",,{} - ,,{}", commit4.id().hex(), commit5.id().hex())
&format!(":{} - :{}", commit4.id().hex(), commit5.id().hex())
),
vec![commit4.id().clone(), commit3.id().clone()]
);
assert_eq!(
resolve_commit_ids(
mut_repo.as_repo_ref(),
&format!(",,{} - ,,{}", commit5.id().hex(), commit4.id().hex())
&format!(":{} - :{}", commit5.id().hex(), commit4.id().hex())
),
vec![commit5.id().clone()]
);
assert_eq!(
resolve_commit_ids(
mut_repo.as_repo_ref(),
&format!(",,{} - ,,{}", commit4.id().hex(), commit2.id().hex())
&format!(":{} - :{}", commit4.id().hex(), commit2.id().hex())
),
vec![commit4.id().clone(), commit3.id().clone()]
);
@ -1385,7 +1385,7 @@ fn test_evaluate_expression_difference(use_git: bool) {
resolve_commit_ids(
mut_repo.as_repo_ref(),
&format!(
",,{} - {} - {}",
":{} - {} - {}",
commit4.id().hex(),
commit2.id().hex(),
commit3.id().hex()
@ -1403,7 +1403,7 @@ fn test_evaluate_expression_difference(use_git: bool) {
resolve_commit_ids(
mut_repo.as_repo_ref(),
&format!(
"(,,{} - ,,{}) - (,,{} - ,,{})",
"(:{} - :{}) - (:{} - :{})",
commit4.id().hex(),
commit1.id().hex(),
commit3.id().hex(),

View File

@ -841,7 +841,7 @@ With the `--from` and/or `--to` options, shows the difference from/to the given
.long("revisions")
.short("r")
.takes_value(true)
.default_value(",,heads()")
.default_value(":heads()")
.help("Which revisions to show"),
)
.arg(