Skip to content

Commit d6b5530

Browse files
committed
revset: do not ignore "git" remote if user pattern is specified
Since we can now express the default pattern as `remote=~exact:"git"`, we can unblock queries matching the "git" remote.
1 parent 626e5b2 commit d6b5530

File tree

5 files changed

+54
-17
lines changed

5 files changed

+54
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1919
- `core.watchman.register_snapshot_trigger`
2020
- `diff.format`
2121

22+
* The `remote_bookmarks(remote=pattern)` revset now includes Git-tracking
23+
bookmarks if the specified `pattern` matches `git`. The default is
24+
`remote=~exact:"git"` as before.
25+
2226
### Deprecations
2327

2428
* `jj bisect run --command <cmd>` is deprecated in favor of

cli/tests/test_git_import_export.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ fn test_resolution_of_git_tracking_bookmarks() {
5858
a7f9930bb6d54ba39e6c254135b9bfe32041fea4 old_message
5959
[EOF]
6060
");
61-
// Can't be selected by remote_bookmarks()
62-
insta::assert_snapshot!(query(r#"remote_bookmarks(exact:"main", exact:"git")"#), @"");
61+
insta::assert_snapshot!(query(r#"remote_bookmarks(exact:"main", exact:"git")"#), @r"
62+
a7f9930bb6d54ba39e6c254135b9bfe32041fea4 old_message
63+
[EOF]
64+
");
6365
}
6466

6567
#[test]

docs/revsets.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ revsets (expressions) as arguments.
268268
`main@origin` or `main@upstream`. If a bookmark is in a conflicted state, all
269269
its possible targets are included.
270270

271-
While Git-tracking bookmarks can be selected by `<name>@git`, these bookmarks
272-
aren't included in `remote_bookmarks()`.
271+
Git-tracking bookmarks are excluded by default. Use `remote=exact:"git"` or
272+
`remote=glob:"*"` to select bookmarks including `@git` ones.
273273

274274
* `tracked_remote_bookmarks([bookmark_pattern], [[remote=]remote_pattern])`: All
275275
targets of tracked remote bookmarks. Supports the same optional arguments as

lib/src/revset.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -897,19 +897,34 @@ static BUILTIN_FUNCTION_MAP: LazyLock<HashMap<&str, RevsetFunction>> = LazyLock:
897897
};
898898
Ok(RevsetExpression::bookmarks(expr))
899899
});
900-
map.insert("remote_bookmarks", |diagnostics, function, _context| {
901-
parse_remote_bookmarks_arguments(diagnostics, function, None)
900+
map.insert("remote_bookmarks", |diagnostics, function, context| {
901+
parse_remote_bookmarks_arguments(
902+
diagnostics,
903+
function,
904+
None,
905+
context.default_ignored_remote,
906+
)
902907
});
903908
map.insert(
904909
"tracked_remote_bookmarks",
905-
|diagnostics, function, _context| {
906-
parse_remote_bookmarks_arguments(diagnostics, function, Some(RemoteRefState::Tracked))
910+
|diagnostics, function, context| {
911+
parse_remote_bookmarks_arguments(
912+
diagnostics,
913+
function,
914+
Some(RemoteRefState::Tracked),
915+
context.default_ignored_remote,
916+
)
907917
},
908918
);
909919
map.insert(
910920
"untracked_remote_bookmarks",
911-
|diagnostics, function, _context| {
912-
parse_remote_bookmarks_arguments(diagnostics, function, Some(RemoteRefState::New))
921+
|diagnostics, function, context| {
922+
parse_remote_bookmarks_arguments(
923+
diagnostics,
924+
function,
925+
Some(RemoteRefState::New),
926+
context.default_ignored_remote,
927+
)
913928
},
914929
);
915930
map.insert("tags", |diagnostics, function, _context| {
@@ -1205,6 +1220,7 @@ fn parse_remote_bookmarks_arguments(
12051220
diagnostics: &mut RevsetDiagnostics,
12061221
function: &FunctionCallNode,
12071222
remote_ref_state: Option<RemoteRefState>,
1223+
default_ignored_remote: Option<&RemoteName>,
12081224
) -> Result<Arc<UserRevsetExpression>, RevsetParseError> {
12091225
let ([], [bookmark_opt_arg, remote_opt_arg]) =
12101226
function.expect_named_arguments(&["", "remote"])?;
@@ -1215,6 +1231,8 @@ fn parse_remote_bookmarks_arguments(
12151231
};
12161232
let remote_expr = if let Some(remote_arg) = remote_opt_arg {
12171233
expect_string_expression(diagnostics, remote_arg)?
1234+
} else if let Some(remote) = default_ignored_remote {
1235+
StringExpression::exact(remote).negated()
12181236
} else {
12191237
StringExpression::all()
12201238
};
@@ -2869,7 +2887,6 @@ fn resolve_commit_ref(
28692887
remote,
28702888
remote_ref_state,
28712889
} => {
2872-
// TODO: should we allow to select @git bookmarks explicitly?
28732890
let bookmark_matcher = bookmark.to_matcher();
28742891
let remote_matcher = remote.to_matcher();
28752892
let commit_ids = repo
@@ -2878,7 +2895,6 @@ fn resolve_commit_ref(
28782895
.filter(|(_, remote_ref)| {
28792896
remote_ref_state.is_none_or(|state| remote_ref.state == state)
28802897
})
2881-
.filter(|&(symbol, _)| !crate::git::is_special_git_remote(symbol.remote))
28822898
.flat_map(|(_, remote_ref)| remote_ref.target.added_ids())
28832899
.cloned()
28842900
.collect();
@@ -3395,13 +3411,14 @@ impl<'a> RevsetParseContext<'a> {
33953411
local_variables: _,
33963412
user_email,
33973413
date_pattern_context,
3398-
default_ignored_remote: _,
3414+
default_ignored_remote,
33993415
extensions,
34003416
workspace,
34013417
} = *self;
34023418
LoweringContext {
34033419
user_email,
34043420
date_pattern_context,
3421+
default_ignored_remote,
34053422
extensions,
34063423
workspace,
34073424
}
@@ -3413,6 +3430,7 @@ impl<'a> RevsetParseContext<'a> {
34133430
pub struct LoweringContext<'a> {
34143431
user_email: &'a str,
34153432
date_pattern_context: DatePatternContext,
3433+
default_ignored_remote: Option<&'a RemoteName>,
34163434
extensions: &'a RevsetExtensions,
34173435
workspace: Option<RevsetWorkspaceContext<'a>>,
34183436
}
@@ -3796,7 +3814,7 @@ mod tests {
37963814
CommitRef(
37973815
RemoteBookmarks {
37983816
bookmark: Pattern(Substring("")),
3799-
remote: Pattern(Substring("")),
3817+
remote: NotIn(Pattern(Exact("ignored"))),
38003818
remote_ref_state: None,
38013819
},
38023820
)
@@ -3805,7 +3823,7 @@ mod tests {
38053823
CommitRef(
38063824
RemoteBookmarks {
38073825
bookmark: Pattern(Substring("")),
3808-
remote: Pattern(Substring("")),
3826+
remote: NotIn(Pattern(Exact("ignored"))),
38093827
remote_ref_state: Some(Tracked),
38103828
},
38113829
)
@@ -3814,7 +3832,7 @@ mod tests {
38143832
CommitRef(
38153833
RemoteBookmarks {
38163834
bookmark: Pattern(Substring("")),
3817-
remote: Pattern(Substring("")),
3835+
remote: NotIn(Pattern(Exact("ignored"))),
38183836
remote_ref_state: Some(New),
38193837
},
38203838
)

lib/tests/test_revset.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2579,7 +2579,7 @@ fn test_evaluate_expression_remote_bookmarks() {
25792579
remote_symbol("bookmark2", "private"),
25802580
normal_tracked_remote_ref(commit2.id()),
25812581
);
2582-
// Git-tracking bookmarks aren't included
2582+
// Git-tracking bookmarks aren't included by default
25832583
mut_repo.set_remote_bookmark(
25842584
remote_symbol("bookmark", git::REMOTE_NAME_FOR_LOCAL_GIT_REPO),
25852585
normal_tracked_remote_ref(commit_git_remote.id()),
@@ -2631,6 +2631,19 @@ fn test_evaluate_expression_remote_bookmarks() {
26312631
),
26322632
vec![commit1.id().clone()]
26332633
);
2634+
// Can get Git-tracking bookmarks by specifying the remote
2635+
assert_eq!(
2636+
resolve_commit_ids(mut_repo, "remote_bookmarks(remote=exact:'git')"),
2637+
vec![commit_git_remote.id().clone()]
2638+
);
2639+
assert_eq!(
2640+
resolve_commit_ids(mut_repo, "remote_bookmarks(remote=glob:'*')"),
2641+
vec![
2642+
commit_git_remote.id().clone(),
2643+
commit2.id().clone(),
2644+
commit1.id().clone(),
2645+
]
2646+
);
26342647
// Can filter bookmarks by tracked and untracked
26352648
assert_eq!(
26362649
resolve_commit_ids(mut_repo, "tracked_remote_bookmarks()"),

0 commit comments

Comments
 (0)