Skip to content

Commit 626e5b2

Browse files
committed
revset: parameterize special "git" remote that is ignored by default
The default remote parameter of remote_bookmarks() will be derived from this parameter. It doesn't make sense to exclude @git bookmarks if the backend isn't Git. It's also nice that parsing tests don't depend on the feature flag.
1 parent e96af18 commit 626e5b2

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

cli/src/cli_util.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ use jj_lib::op_walk::OpsetEvaluationError;
8383
use jj_lib::operation::Operation;
8484
use jj_lib::ref_name::RefName;
8585
use jj_lib::ref_name::RefNameBuf;
86+
use jj_lib::ref_name::RemoteName;
8687
use jj_lib::ref_name::WorkspaceName;
8788
use jj_lib::ref_name::WorkspaceNameBuf;
8889
use jj_lib::repo::CheckOutCommitError;
@@ -115,6 +116,7 @@ use jj_lib::revset::UserRevsetExpression;
115116
use jj_lib::rewrite::restore_tree;
116117
use jj_lib::settings::HumanByteSize;
117118
use jj_lib::settings::UserSettings;
119+
use jj_lib::store::Store;
118120
use jj_lib::str_util::StringMatcher;
119121
use jj_lib::str_util::StringPattern;
120122
use jj_lib::transaction::Transaction;
@@ -782,6 +784,7 @@ pub struct WorkspaceCommandEnvironment {
782784
settings: UserSettings,
783785
revset_aliases_map: RevsetAliasesMap,
784786
template_aliases_map: TemplateAliasesMap,
787+
default_ignored_remote: Option<&'static RemoteName>,
785788
path_converter: RepoPathUiConverter,
786789
workspace_name: WorkspaceNameBuf,
787790
immutable_heads_expression: Arc<UserRevsetExpression>,
@@ -795,6 +798,7 @@ impl WorkspaceCommandEnvironment {
795798
let settings = workspace.settings();
796799
let revset_aliases_map = revset_util::load_revset_aliases(ui, settings.config())?;
797800
let template_aliases_map = load_template_aliases(ui, settings.config())?;
801+
let default_ignored_remote = default_ignored_remote_name(workspace.repo_loader().store());
798802
let path_converter = RepoPathUiConverter::Fs {
799803
cwd: command.cwd().to_owned(),
800804
base: workspace.workspace_root().to_owned(),
@@ -804,6 +808,7 @@ impl WorkspaceCommandEnvironment {
804808
settings: settings.clone(),
805809
revset_aliases_map,
806810
template_aliases_map,
811+
default_ignored_remote,
807812
path_converter,
808813
workspace_name: workspace.workspace_name().to_owned(),
809814
immutable_heads_expression: RevsetExpression::root(),
@@ -840,6 +845,7 @@ impl WorkspaceCommandEnvironment {
840845
local_variables: HashMap::new(),
841846
user_email: self.settings.user_email(),
842847
date_pattern_context: now.into(),
848+
default_ignored_remote: self.default_ignored_remote,
843849
extensions: self.command.revset_extensions(),
844850
workspace: Some(workspace_context),
845851
}
@@ -2867,6 +2873,19 @@ pub fn update_working_copy(
28672873
Ok(stats)
28682874
}
28692875

2876+
/// Returns the special remote name that should be ignored by default.
2877+
pub fn default_ignored_remote_name(store: &Store) -> Option<&'static RemoteName> {
2878+
#[cfg(feature = "git")]
2879+
{
2880+
use jj_lib::git;
2881+
if git::get_git_backend(store).is_ok() {
2882+
return Some(git::REMOTE_NAME_FOR_LOCAL_GIT_REPO);
2883+
}
2884+
}
2885+
let _ = store;
2886+
None
2887+
}
2888+
28702889
/// Whether or not the `bookmark` has any tracked remotes (i.e. is a tracking
28712890
/// local bookmark.)
28722891
pub fn has_tracked_remote_bookmarks(view: &View, bookmark: &RefName) -> bool {

cli/src/commit_templater.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,6 +2768,7 @@ mod tests {
27682768
local_variables: HashMap::new(),
27692769
user_email: "[email protected]",
27702770
date_pattern_context: chrono::DateTime::UNIX_EPOCH.fixed_offset().into(),
2771+
default_ignored_remote: None,
27712772
extensions: &self.revset_extensions,
27722773
workspace: Some(RevsetWorkspaceContext {
27732774
path_converter: &self.path_converter,

lib/src/revset.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use crate::object_id::PrefixResolution;
4444
use crate::op_store::RefTarget;
4545
use crate::op_store::RemoteRefState;
4646
use crate::op_walk;
47+
use crate::ref_name::RemoteName;
4748
use crate::ref_name::RemoteRefSymbol;
4849
use crate::ref_name::RemoteRefSymbolBuf;
4950
use crate::ref_name::WorkspaceName;
@@ -3381,6 +3382,8 @@ pub struct RevsetParseContext<'a> {
33813382
pub local_variables: HashMap<&'a str, ExpressionNode<'a>>,
33823383
pub user_email: &'a str,
33833384
pub date_pattern_context: DatePatternContext,
3385+
/// Special remote that should be ignored by default. (e.g. "git")
3386+
pub default_ignored_remote: Option<&'a RemoteName>,
33843387
pub extensions: &'a RevsetExtensions,
33853388
pub workspace: Option<RevsetWorkspaceContext<'a>>,
33863389
}
@@ -3392,6 +3395,7 @@ impl<'a> RevsetParseContext<'a> {
33923395
local_variables: _,
33933396
user_email,
33943397
date_pattern_context,
3398+
default_ignored_remote: _,
33953399
extensions,
33963400
workspace,
33973401
} = *self;
@@ -3495,6 +3499,7 @@ mod tests {
34953499
local_variables: HashMap::new(),
34963500
user_email: "[email protected]",
34973501
date_pattern_context: chrono::Utc::now().fixed_offset().into(),
3502+
default_ignored_remote: Some("ignored".as_ref()),
34983503
extensions: &RevsetExtensions::default(),
34993504
workspace: None,
35003505
};
@@ -3524,6 +3529,7 @@ mod tests {
35243529
local_variables: HashMap::new(),
35253530
user_email: "[email protected]",
35263531
date_pattern_context: chrono::Utc::now().fixed_offset().into(),
3532+
default_ignored_remote: Some("ignored".as_ref()),
35273533
extensions: &RevsetExtensions::default(),
35283534
workspace: Some(workspace_ctx),
35293535
};
@@ -3549,6 +3555,7 @@ mod tests {
35493555
local_variables: HashMap::new(),
35503556
user_email: "[email protected]",
35513557
date_pattern_context: chrono::Utc::now().fixed_offset().into(),
3558+
default_ignored_remote: Some("ignored".as_ref()),
35523559
extensions: &RevsetExtensions::default(),
35533560
workspace: None,
35543561
};

lib/tests/test_revset.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ fn resolve_symbol(repo: &dyn Repo, symbol: &str) -> Result<Vec<CommitId>, Revset
9696
local_variables: HashMap::new(),
9797
user_email: "",
9898
date_pattern_context: chrono::Local::now().into(),
99+
default_ignored_remote: Some(git::REMOTE_NAME_FOR_LOCAL_GIT_REPO),
99100
extensions: &RevsetExtensions::default(),
100101
workspace: None,
101102
};
@@ -228,6 +229,7 @@ fn test_resolve_symbol_commit_id() {
228229
local_variables: HashMap::new(),
229230
user_email: settings.user_email(),
230231
date_pattern_context: chrono::Utc::now().fixed_offset().into(),
232+
default_ignored_remote: Some(git::REMOTE_NAME_FOR_LOCAL_GIT_REPO),
231233
extensions: &RevsetExtensions::default(),
232234
workspace: None,
233235
};
@@ -1017,6 +1019,7 @@ fn try_resolve_expression(
10171019
local_variables: HashMap::new(),
10181020
user_email: settings.user_email(),
10191021
date_pattern_context: chrono::Utc::now().fixed_offset().into(),
1022+
default_ignored_remote: Some(git::REMOTE_NAME_FOR_LOCAL_GIT_REPO),
10201023
extensions: &RevsetExtensions::default(),
10211024
workspace: None,
10221025
};
@@ -1066,6 +1069,7 @@ fn resolve_commit_ids_in_workspace(
10661069
local_variables: HashMap::new(),
10671070
user_email: settings.user_email(),
10681071
date_pattern_context: chrono::Utc::now().fixed_offset().into(),
1072+
default_ignored_remote: Some(git::REMOTE_NAME_FOR_LOCAL_GIT_REPO),
10691073
extensions: &RevsetExtensions::default(),
10701074
workspace: Some(workspace_ctx),
10711075
};

0 commit comments

Comments
 (0)