Skip to content

Commit 53f18f3

Browse files
committed
git: replace remaining users of is_special_git_remote()
We no longer need jj-lib functions.
1 parent d6b5530 commit 53f18f3

File tree

12 files changed

+38
-44
lines changed

12 files changed

+38
-44
lines changed

cli/src/cli_util.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ use jj_lib::rewrite::restore_tree;
117117
use jj_lib::settings::HumanByteSize;
118118
use jj_lib::settings::UserSettings;
119119
use jj_lib::store::Store;
120+
use jj_lib::str_util::StringExpression;
120121
use jj_lib::str_util::StringMatcher;
121122
use jj_lib::str_util::StringPattern;
122123
use jj_lib::transaction::Transaction;
123-
use jj_lib::view::View;
124124
use jj_lib::working_copy;
125125
use jj_lib::working_copy::CheckoutStats;
126126
use jj_lib::working_copy::SnapshotOptions;
@@ -2888,9 +2888,13 @@ pub fn default_ignored_remote_name(store: &Store) -> Option<&'static RemoteName>
28882888

28892889
/// Whether or not the `bookmark` has any tracked remotes (i.e. is a tracking
28902890
/// local bookmark.)
2891-
pub fn has_tracked_remote_bookmarks(view: &View, bookmark: &RefName) -> bool {
2892-
view.remote_bookmarks_matching(&StringMatcher::exact(bookmark), &StringMatcher::all())
2893-
.filter(|&(symbol, _)| !jj_lib::git::is_special_git_remote(symbol.remote))
2891+
pub fn has_tracked_remote_bookmarks(repo: &dyn Repo, bookmark: &RefName) -> bool {
2892+
let remote_matcher = match default_ignored_remote_name(repo.store()) {
2893+
Some(remote) => StringExpression::exact(remote).negated().to_matcher(),
2894+
None => StringMatcher::all(),
2895+
};
2896+
repo.view()
2897+
.remote_bookmarks_matching(&StringMatcher::exact(bookmark), &remote_matcher)
28942898
.any(|(_, remote_ref)| remote_ref.is_tracked())
28952899
}
28962900

cli/src/commands/abandon.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ pub(crate) fn cmd_abandon(
184184

185185
#[cfg(feature = "git")]
186186
if jj_lib::git::get_git_backend(workspace_command.repo().store()).is_ok() {
187-
let view = workspace_command.repo().view();
187+
let repo = workspace_command.repo().as_ref();
188188
if deleted_bookmarks
189189
.iter()
190-
.any(|name| has_tracked_remote_bookmarks(view, name))
190+
.any(|name| has_tracked_remote_bookmarks(repo, name))
191191
{
192192
writeln!(
193193
ui.hint_default(),

cli/src/commands/bookmark/create.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn cmd_bookmark_create(
6262
"Use `jj bookmark set` to update it.",
6363
));
6464
}
65-
if has_tracked_remote_bookmarks(view, name) {
65+
if has_tracked_remote_bookmarks(repo, name) {
6666
return Err(user_error_with_hint(
6767
format!(
6868
"Tracked remote bookmarks exist for deleted bookmark: {name}",

cli/src/commands/bookmark/forget.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ use jj_lib::op_store::LocalRemoteRefTarget;
1818
use jj_lib::op_store::RefTarget;
1919
use jj_lib::op_store::RemoteRef;
2020
use jj_lib::ref_name::RefName;
21+
use jj_lib::repo::Repo as _;
2122
use jj_lib::str_util::StringPattern;
2223
use jj_lib::view::View;
2324

2425
use super::find_bookmarks_with;
2526
use crate::cli_util::CommandHelper;
27+
use crate::cli_util::default_ignored_remote_name;
2628
use crate::command_error::CommandError;
2729
use crate::complete;
2830
use crate::ui::Ui;
@@ -65,6 +67,7 @@ pub fn cmd_bookmark_forget(
6567
) -> Result<(), CommandError> {
6668
let mut workspace_command = command.workspace_helper(ui)?;
6769
let repo = workspace_command.repo().clone();
70+
let ignored_remote = default_ignored_remote_name(repo.store());
6871
let matched_bookmarks = find_forgettable_bookmarks(repo.view(), &args.names)?;
6972
let mut tx = workspace_command.start_transaction();
7073
let mut forgotten_remote: usize = 0;
@@ -82,7 +85,7 @@ pub fn cmd_bookmark_forget(
8285
continue;
8386
}
8487
// Git-tracking remote bookmarks cannot be untracked currently, so skip them
85-
if jj_lib::git::is_special_git_remote(symbol.remote) {
88+
if ignored_remote.is_some_and(|ignored| symbol.remote == ignored) {
8689
continue;
8790
}
8891
tx.repo_mut().untrack_remote_bookmark(symbol);

cli/src/commands/bookmark/list.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use jj_lib::str_util::StringPattern;
3232

3333
use crate::cli_util::CommandHelper;
3434
use crate::cli_util::RevisionArg;
35+
use crate::cli_util::default_ignored_remote_name;
3536
use crate::command_error::CommandError;
3637
use crate::commit_templater::CommitRef;
3738
use crate::complete;
@@ -185,6 +186,7 @@ pub fn cmd_bookmark_list(
185186
.labeled(["bookmark_list"])
186187
};
187188

189+
let ignored_tracked_remote = default_ignored_remote_name(repo.store());
188190
let mut bookmark_list_items: Vec<RefListItem> = Vec::new();
189191
let bookmarks_to_list = view.bookmarks().filter(|(name, target)| {
190192
bookmark_names_to_list
@@ -208,7 +210,9 @@ pub fn cmd_bookmark_list(
208210
.partition::<Vec<_>, _>(|&(_, remote_ref)| remote_ref.is_tracked());
209211

210212
if args.tracked {
211-
tracked_remote_refs.retain(|&(remote, _)| !jj_lib::git::is_special_git_remote(remote));
213+
tracked_remote_refs.retain(|&(remote, _)| {
214+
ignored_tracked_remote.is_none_or(|ignored| remote != ignored)
215+
});
212216
} else if !args.all_remotes && args.remotes.is_none() {
213217
tracked_remote_refs.retain(|&(_, remote_ref)| remote_ref.target != *local_target);
214218
}
@@ -279,7 +283,7 @@ pub fn cmd_bookmark_list(
279283
.map(|item| {
280284
item.tracked.iter().any(|r| {
281285
let remote = r.remote_name().expect("tracked ref should be remote");
282-
!jj_lib::git::is_special_git_remote(remote.as_ref())
286+
ignored_tracked_remote.is_none_or(|ignored| remote != ignored)
283287
})
284288
})
285289
.max();

cli/src/commands/bookmark/rename.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ pub fn cmd_bookmark_rename(
7979
),
8080
)?;
8181

82-
let view = workspace_command.repo().view();
83-
if has_tracked_remote_bookmarks(view, old_bookmark) {
82+
let repo = workspace_command.repo().as_ref();
83+
if has_tracked_remote_bookmarks(repo, old_bookmark) {
8484
writeln!(
8585
ui.warning_default(),
8686
"Tracked remote bookmarks for bookmark {old_bookmark} were not renamed.",
@@ -95,7 +95,7 @@ pub fn cmd_bookmark_rename(
9595
new_bookmark = new_bookmark.as_symbol()
9696
)?;
9797
}
98-
if has_tracked_remote_bookmarks(view, new_bookmark) {
98+
if has_tracked_remote_bookmarks(repo, new_bookmark) {
9999
// This isn't an error because bookmark renaming can't be propagated to
100100
// the remote immediately. "rename old new && rename new old" should be
101101
// allowed even if the original old bookmark had tracked remotes.

cli/src/commands/bookmark/set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub fn cmd_bookmark_set(
7070
let old_target = repo.view().get_local_bookmark(name);
7171
// If a bookmark is absent locally but is still tracking remote bookmarks,
7272
// we are resurrecting the local bookmark, not "creating" a new bookmark.
73-
if old_target.is_absent() && !has_tracked_remote_bookmarks(repo.view(), name) {
73+
if old_target.is_absent() && !has_tracked_remote_bookmarks(repo, name) {
7474
new_bookmark_count += 1;
7575
} else if old_target.as_normal() != Some(target_commit.id()) {
7676
moved_bookmark_count += 1;

cli/src/commands/bookmark/untrack.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414

1515
use clap_complete::ArgValueCandidates;
1616
use itertools::Itertools as _;
17+
use jj_lib::repo::Repo as _;
1718

1819
use super::find_trackable_remote_bookmarks;
1920
use crate::cli_util::CommandHelper;
2021
use crate::cli_util::RemoteBookmarkNamePattern;
22+
use crate::cli_util::default_ignored_remote_name;
2123
use crate::command_error::CommandError;
2224
use crate::complete;
2325
use crate::ui::Ui;
@@ -55,9 +57,10 @@ pub fn cmd_bookmark_untrack(
5557
) -> Result<(), CommandError> {
5658
let mut workspace_command = command.workspace_helper(ui)?;
5759
let repo = workspace_command.repo().clone();
60+
let ignored_remote = default_ignored_remote_name(repo.store());
5861
let mut symbols = Vec::new();
5962
for (symbol, remote_ref) in find_trackable_remote_bookmarks(repo.view(), &args.names)? {
60-
if jj_lib::git::is_special_git_remote(symbol.remote) {
63+
if ignored_remote.is_some_and(|ignored| symbol.remote == ignored) {
6164
// This restriction can be lifted if we want to support untracked @git
6265
// bookmarks.
6366
writeln!(

cli/src/commands/git/push.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -815,9 +815,9 @@ fn classify_bookmark_update(
815815
}
816816
}
817817

818-
fn ensure_new_bookmark_name(view: &View, name: &RefName) -> Result<(), CommandError> {
818+
fn ensure_new_bookmark_name(repo: &dyn Repo, name: &RefName) -> Result<(), CommandError> {
819819
let symbol = name.as_symbol();
820-
if view.get_local_bookmark(name).is_present() {
820+
if repo.view().get_local_bookmark(name).is_present() {
821821
return Err(user_error_with_hint(
822822
format!("Bookmark already exists: {symbol}"),
823823
format!(
@@ -826,7 +826,7 @@ fn ensure_new_bookmark_name(view: &View, name: &RefName) -> Result<(), CommandEr
826826
),
827827
));
828828
}
829-
if has_tracked_remote_bookmarks(view, name) {
829+
if has_tracked_remote_bookmarks(repo, name) {
830830
return Err(user_error_with_hint(
831831
format!("Tracked remote bookmarks exist for deleted bookmark: {symbol}"),
832832
format!(
@@ -868,7 +868,7 @@ fn create_explicitly_named_bookmarks(
868868
)
869869
.hinted(hint)
870870
})?;
871-
ensure_new_bookmark_name(tx.repo().view(), &name)?;
871+
ensure_new_bookmark_name(tx.repo(), &name)?;
872872
let revision = tx
873873
.base_workspace_helper()
874874
.resolve_single_rev(ui, &revision_str.to_string().into())?;
@@ -915,12 +915,11 @@ fn create_change_bookmarks(
915915

916916
for (commit, name) in iter::zip(&all_commits, &bookmark_names) {
917917
let target = RefTarget::normal(commit.id().clone());
918-
let view = tx.base_repo().view();
919-
if view.get_local_bookmark(name) == &target {
918+
if tx.base_repo().view().get_local_bookmark(name) == &target {
920919
// Existing bookmark pointing to the commit, which is allowed
921920
continue;
922921
}
923-
ensure_new_bookmark_name(view, name)?;
922+
ensure_new_bookmark_name(tx.base_repo().as_ref(), name)?;
924923
writeln!(
925924
ui.status(),
926925
"Creating bookmark {name} for revision {change_id:.12}",

cli/src/commands/operation/diff.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use pollster::FutureExt as _;
3838

3939
use crate::cli_util::CommandHelper;
4040
use crate::cli_util::LogContentFormat;
41+
use crate::cli_util::default_ignored_remote_name;
4142
use crate::command_error::CommandError;
4243
use crate::complete;
4344
use crate::diff_util::DiffFormatArgs;
@@ -348,13 +349,14 @@ pub fn show_op_diff(
348349
writeln!(formatter)?;
349350
}
350351

352+
let ignored_remote = default_ignored_remote_name(current_repo.store());
351353
let changed_remote_bookmarks = diff_named_remote_refs(
352354
from_repo.view().all_remote_bookmarks(),
353355
to_repo.view().all_remote_bookmarks(),
354356
)
355357
// Skip updates to the local git repo, since they should typically be covered in
356358
// local branches.
357-
.filter(|(symbol, _)| !jj_lib::git::is_special_git_remote(symbol.remote))
359+
.filter(|(symbol, _)| ignored_remote.is_none_or(|ignored| symbol.remote != ignored))
358360
.collect_vec();
359361
if !changed_remote_bookmarks.is_empty() {
360362
writeln!(formatter)?;

0 commit comments

Comments
 (0)