Skip to content

Commit 6287424

Browse files
committed
style: apply formatting to bookmark bump implementation
1 parent 85451e1 commit 6287424

File tree

2 files changed

+48
-49
lines changed

2 files changed

+48
-49
lines changed

cli/src/commands/bookmark/bump.rs

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,26 @@ use crate::ui::Ui;
3030

3131
/// Move a bookmark to the latest non-empty descendant
3232
///
33-
/// Finds the closest bookmark on the specified revision or any of its ancestors,
34-
/// then moves that bookmark forward to the topologically latest non-empty descendant.
33+
/// Finds the closest bookmark on the specified revision or any of its
34+
/// ancestors, then moves that bookmark forward to the topologically latest
35+
/// non-empty descendant.
3536
///
36-
/// This is useful for advancing a bookmark after making several commits, without
37-
/// having to manually specify the bookmark name or target revision.
37+
/// This is useful for advancing a bookmark after making several commits,
38+
/// without having to manually specify the bookmark name or target revision.
3839
///
3940
/// If multiple bookmarks exist on the same commit, the alphabetically first one
4041
/// is selected.
4142
///
42-
/// Example: After creating commits on top of a bookmarked commit, move the bookmark
43-
/// forward to the latest non-empty commit:
43+
/// Example: After creating commits on top of a bookmarked commit, move the
44+
/// bookmark forward to the latest non-empty commit:
4445
///
4546
/// ```shell
4647
/// $ jj bookmark bump
4748
/// ```
4849
#[derive(clap::Args, Clone, Debug)]
4950
pub struct BookmarkBumpArgs {
5051
/// Revision to start searching for bookmarks from (searches ancestors too)
51-
#[arg(
52-
long, short,
53-
value_name = "REVSET",
54-
default_value = "@"
55-
)]
52+
#[arg(long, short, value_name = "REVSET", default_value = "@")]
5653
from: RevisionArg,
5754

5855
/// Allow moving the bookmark backwards or sideways
@@ -70,35 +67,28 @@ pub fn cmd_bookmark_bump(
7067
let from_commit = workspace_command.resolve_single_rev(ui, &args.from)?;
7168

7269
let (bookmark_name, bookmark_commit) = {
73-
let ancestors_expression = workspace_command
74-
.parse_revset(ui, &RevisionArg::from(format!("::{}", from_commit.id().hex())))?;
70+
let ancestors_expression = workspace_command.parse_revset(
71+
ui,
72+
&RevisionArg::from(format!("::{}", from_commit.id().hex())),
73+
)?;
7574
let store = repo.store();
7675
let ancestors = ancestors_expression.evaluate()?;
77-
78-
let ancestor_ids: Vec<_> = ancestors
79-
.iter()
80-
.try_collect()?;
81-
76+
77+
let ancestor_ids: Vec<_> = ancestors.iter().try_collect()?;
78+
8279
let pattern = StringPattern::everything();
83-
let all_bookmarks: Vec<_> = repo
84-
.view()
85-
.local_bookmarks_matching(&pattern)
86-
.collect();
87-
80+
let all_bookmarks: Vec<_> = repo.view().local_bookmarks_matching(&pattern).collect();
81+
8882
let mut bookmark_on_ancestor = None;
8983
for ancestor_id in &ancestor_ids {
9084
let mut bookmarks_here: Vec<_> = all_bookmarks
9185
.iter()
92-
.filter(|(_, target)| {
93-
target
94-
.added_ids()
95-
.any(|id| id == ancestor_id)
96-
})
86+
.filter(|(_, target)| target.added_ids().any(|id| id == ancestor_id))
9787
.collect();
98-
88+
9989
if !bookmarks_here.is_empty() {
10090
bookmarks_here.sort_by_key(|(name, _)| *name);
101-
91+
10292
if bookmarks_here.len() > 1 {
10393
writeln!(
10494
ui.warning_default(),
@@ -115,14 +105,14 @@ pub fn cmd_bookmark_bump(
115105
bookmarks_here[0].0.as_symbol()
116106
)?;
117107
}
118-
108+
119109
let (name, _) = bookmarks_here[0];
120110
let name_string = name.as_symbol().to_string();
121111
bookmark_on_ancestor = Some((name_string, store.get_commit(ancestor_id)?));
122112
break;
123113
}
124114
}
125-
115+
126116
bookmark_on_ancestor.ok_or_else(|| {
127117
user_error(format!(
128118
"No bookmarks found on {} or its ancestors",
@@ -132,15 +122,15 @@ pub fn cmd_bookmark_bump(
132122
};
133123

134124
let target_commit = {
135-
let revset_expression = workspace_command
136-
.parse_revset(ui, &RevisionArg::from(format!("heads({}+ & ~empty())", bookmark_commit.id().hex())))?;
125+
let revset_expression = workspace_command.parse_revset(
126+
ui,
127+
&RevisionArg::from(format!("heads({}+ & ~empty())", bookmark_commit.id().hex())),
128+
)?;
137129
let store = repo.store();
138130
let descendants = revset_expression.evaluate()?;
139-
140-
let commit_ids: Vec<_> = descendants
141-
.iter()
142-
.try_collect()?;
143-
131+
132+
let commit_ids: Vec<_> = descendants.iter().try_collect()?;
133+
144134
commit_ids
145135
.into_iter()
146136
.map(|id| store.get_commit(&id))
@@ -156,12 +146,11 @@ pub fn cmd_bookmark_bump(
156146
};
157147

158148
if !args.allow_backwards {
159-
let matches = find_local_bookmarks(repo.view(), &[StringPattern::exact(bookmark_name.clone())])?;
149+
let matches =
150+
find_local_bookmarks(repo.view(), &[StringPattern::exact(bookmark_name.clone())])?;
160151
if let Some((name, _old_target)) = matches
161152
.into_iter()
162-
.find(|(_, old_target)| {
163-
!is_fast_forward(repo.as_ref(), old_target, target_commit.id())
164-
})
153+
.find(|(_, old_target)| !is_fast_forward(repo.as_ref(), old_target, target_commit.id()))
165154
{
166155
return Err(user_error_with_hint(
167156
format!(
@@ -173,15 +162,20 @@ pub fn cmd_bookmark_bump(
173162
}
174163
}
175164

176-
let bookmark_ref_name = revset_util::parse_bookmark_name(&bookmark_name)
177-
.map_err(|e| user_error(format!("Failed to parse bookmark name '{}': {}", bookmark_name, e)))?;
165+
let bookmark_ref_name = revset_util::parse_bookmark_name(&bookmark_name).map_err(|e| {
166+
user_error(format!(
167+
"Failed to parse bookmark name '{bookmark_name}': {e}"
168+
))
169+
})?;
178170

179171
let mut tx = workspace_command.start_transaction();
180-
tx.repo_mut()
181-
.set_local_bookmark_target(&bookmark_ref_name, RefTarget::normal(target_commit.id().clone()));
172+
tx.repo_mut().set_local_bookmark_target(
173+
&bookmark_ref_name,
174+
RefTarget::normal(target_commit.id().clone()),
175+
);
182176

183177
if let Some(mut formatter) = ui.status_formatter() {
184-
write!(formatter, "Moved bookmark {} to ", bookmark_name)?;
178+
write!(formatter, "Moved bookmark {bookmark_name} to ")?;
185179
tx.write_commit_summary(formatter.as_mut(), &target_commit)?;
186180
writeln!(formatter)?;
187181
}

cli/tests/test_bookmark_command.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,12 @@ fn test_bookmark_bump_backwards() {
24622462
[exit status: 1]
24632463
"###);
24642464

2465-
let output = work_dir.run_jj(["bookmark", "bump", "--from=description(second)", "--allow-backwards"]);
2465+
let output = work_dir.run_jj([
2466+
"bookmark",
2467+
"bump",
2468+
"--from=description(second)",
2469+
"--allow-backwards",
2470+
]);
24662471
insta::assert_snapshot!(output, @r###"
24672472
------- stderr -------
24682473
Error: No non-empty descendants found for revision 63351e1b9362cbf9d47547d2e87a5e3bb8bcab3c

0 commit comments

Comments
 (0)