Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ fn main() {
println!("cargo:rerun-if-env-changed=NIX_JJ_GIT_HASH");
let git_hash = get_git_hash_from_nix().or_else(|| {
if Path::new(GIT_HEAD_PATH).exists() {
// In colocated workspace, .git/HEAD should reflect the working-copy parent.
// In colocated workspace, .git/HEAD should reflect the working-copy
// parent.
println!("cargo:rerun-if-changed={GIT_HEAD_PATH}");
} else if Path::new(JJ_OP_HEADS_PATH).exists() {
// op_heads changes when working-copy files are mutated, which is way more
// frequent than .git/HEAD.
// op_heads changes when working-copy files are mutated, which is
// way more frequent than .git/HEAD.
println!("cargo:rerun-if-changed={JJ_OP_HEADS_PATH}");
}
get_git_hash_from_jj().or_else(get_git_hash_from_git)
Expand Down Expand Up @@ -70,8 +71,9 @@ fn get_git_hash_from_jj() -> Option<String> {
.filter(|output| output.status.success())
.map(|output| {
let mut parent_commits = String::from_utf8(output.stdout).unwrap();
// If a development version of `jj` is compiled at a merge commit, this will
// result in several commit ids separated by `-`s.
// If a development version of `jj` is compiled at a merge commit,
// this will result in several commit ids separated by
// `-`s.
parent_commits.truncate(parent_commits.trim_end_matches('-').len());
parent_commits
})
Expand Down
4 changes: 2 additions & 2 deletions cli/examples/custom-backend/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ enum CustomCommand {

fn create_store_factories() -> StoreFactories {
let mut store_factories = StoreFactories::empty();
// Register the backend so it can be loaded when the repo is loaded. The name
// must match `Backend::name()`.
// Register the backend so it can be loaded when the repo is loaded. The
// name must match `Backend::name()`.
store_factories.add_backend(
"jit",
Box::new(|settings, store_path| Ok(Box::new(JitBackend::load(settings, store_path)?))),
Expand Down
5 changes: 3 additions & 2 deletions cli/src/cleanup_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ type GuardTable = Slab<Box<dyn FnOnce() + Send>>;
/// Prepare to run [`CleanupGuard`]s on `SIGINT`/`SIGTERM`/`SIGHUP`
pub fn init() {
if let Err(e) = ctrlc::set_handler(|| {
// We must hold the lock for the remainder of the process's lifetime to avoid a
// race where a guard is created after we unlock but before we exit.
// We must hold the lock for the remainder of the process's lifetime to
// avoid a race where a guard is created after we unlock but before we
// exit.
let guards = &mut *LIVE_GUARDS.lock().unwrap();
if let Err(e) = std::panic::catch_unwind(AssertUnwindSafe(|| {
for guard in guards.drain() {
Expand Down
149 changes: 84 additions & 65 deletions cli/src/cli_util.rs

Large diffs are not rendered by default.

43 changes: 23 additions & 20 deletions cli/src/commands/arrange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ impl State {
/// viewport.
fn clamp_scroll(&mut self, viewport_rows: u16) {
// `render()` configures the graph renderer with a minimum row height of
// two, so this estimates how many commits fit in the common case. Custom
// templates and graph topology can make a commit taller, so this is not
// a strict bound.
// two, so this estimates how many commits fit in the common case.
// Custom templates and graph topology can make a commit taller,
// so this is not a strict bound.
let max_visible = (viewport_rows / 2).max(1) as usize;
let total_commits =
self.external_children.len() + self.current_order.len() + self.external_parents.len();
Expand Down Expand Up @@ -528,8 +528,8 @@ fn run_tui<B: ratatui::backend::Backend>(
if let Event::Key(event) =
event::read().map_err(|e| internal_error(format!("Failed to read TUI events: {e}")))?
{
// On Windows, we get Press and Release (and maybe Repeat) events, but on Linux
// we only get Press.
// On Windows, we get Press and Release (and maybe Repeat) events,
// but on Linux we only get Press.
if event.is_release() {
continue;
}
Expand Down Expand Up @@ -600,8 +600,8 @@ fn render(
.chain(state.external_parents.iter())
.skip(state.scroll_top);
for id in commits_to_render {
// TODO: Make the graph column width depend on what's needed to render the
// graph.
// TODO: Make the graph column width depend on what's needed to render
// the graph.
let row_layout = Layout::horizontal([
Constraint::Min(2),
Constraint::Min(10),
Expand All @@ -621,9 +621,9 @@ fn render(
let commit_state = state.commits.get(id).unwrap();
let action = &commit_state.action;

// TODO: The graph can be misaligned with the text because sometimes `renderdag`
// inserts a line of edges before the line with the node and we assume the node
// is the first line emitted.
// TODO: The graph can be misaligned with the text because sometimes
// `renderdag` inserts a line of edges before the line with the
// node and we assume the node is the first line emitted.
let edges = commit_state
.parents
.iter()
Expand Down Expand Up @@ -756,7 +756,8 @@ mod tests {
]
);

// Update parents and head order and check that the commit order changes.
// Update parents and head order and check that the commit order
// changes.
state.commits.get_mut(commit_a.id()).unwrap().parents = vec![commit_c.id().clone()];
state.commits.get_mut(commit_b.id()).unwrap().parents =
vec![store.root_commit_id().clone()];
Expand Down Expand Up @@ -1013,7 +1014,8 @@ mod tests {
]
);

// Attempting to swap D down should have no effect because it has two parents
// Attempting to swap D down should have no effect because it has two
// parents
state.current_selection = 0;
assert_eq!(state.current_id(), commit_d.id());
let state_before = state.clone();
Expand Down Expand Up @@ -1070,8 +1072,8 @@ mod tests {
);
assert_eq!(state.current_selection, 3);

// Attempting to swap C down should have no effect because it would move outside
// of range
// Attempting to swap C down should have no effect because it would move
// outside of range
state.current_selection = 3;
assert_eq!(state.current_id(), commit_c.id());
let state_before = state.clone();
Expand Down Expand Up @@ -1132,16 +1134,17 @@ mod tests {
]
);

// Attempting to swap A up should have no effect because it has two children
// Attempting to swap A up should have no effect because it has two
// children
state.current_selection = 3;
assert_eq!(state.current_id(), commit_a.id());
let state_before = state.clone();
state.swap_selection_up();
assert_eq!(state, state_before);

// Attempting to swap C up should have no effect because it has two children
// even though one is external. We could change this to ignore the external
// child.
// Attempting to swap C up should have no effect because it has two
// children even though one is external. We could change this to
// ignore the external child.
state.current_selection = 2;
assert_eq!(state.current_id(), commit_c.id());
let state_before = state.clone();
Expand Down Expand Up @@ -1173,8 +1176,8 @@ mod tests {
);
assert_eq!(state.current_selection, 0);

// Attempting to swap B up should have no effect because it would move outside
// of range
// Attempting to swap B up should have no effect because it would move
// outside of range
state.current_selection = 0;
assert_eq!(state.current_id(), commit_b.id());
let state_before = state.clone();
Expand Down
3 changes: 2 additions & 1 deletion cli/src/commands/bisect/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ pub(crate) async fn cmd_bisect_run(
bisector.mark(commit.id().clone(), evaluation);
}

// Reload the workspace because the evaluation command may run `jj` commands.
// Reload the workspace because the evaluation command may run
// `jj` commands.
workspace_command = command.workspace_helper(ui).await?;
}
jj_lib::bisect::NextStep::Done(bisection_result) => {
Expand Down
7 changes: 4 additions & 3 deletions cli/src/commands/bookmark/forget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ pub async fn cmd_bookmark_forget(
.set_local_bookmark_target(name, RefTarget::absent());
for (remote, _) in &bookmark_target.remote_refs {
let symbol = name.to_remote_symbol(remote);
// If `--include-remotes` is specified, we forget the corresponding remote
// bookmarks instead of untracking them
// If `--include-remotes` is specified, we forget the corresponding
// remote bookmarks instead of untracking them
if args.include_remotes {
tx.repo_mut()
.set_remote_bookmark(symbol, RemoteRef::absent());
forgotten_remote += 1;
continue;
}
// Git-tracking remote bookmarks cannot be untracked currently, so skip them
// Git-tracking remote bookmarks cannot be untracked currently, so
// skip them
if ignored_remote.is_some_and(|ignored| symbol.remote == ignored) {
continue;
}
Expand Down
12 changes: 7 additions & 5 deletions cli/src/commands/bookmark/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,11 @@ pub async fn cmd_bookmark_list(
(None, None) => StringExpression::all(),
};
let matched_local_targets: HashSet<_> = if let Some(revisions) = &args.revisions {
// Match against local targets only, which is consistent with "jj git push".
// Match against local targets only, which is consistent with "jj git
// push".
let mut expression = workspace_command.parse_union_revsets(ui, revisions)?;
// Intersects with the set of local bookmark targets to minimize the lookup
// space.
// Intersects with the set of local bookmark targets to minimize the
// lookup space.
expression.intersect_with(&RevsetExpression::bookmarks(StringExpression::all()));
expression.evaluate_to_commit_ids()?.try_collect().await?
} else {
Expand Down Expand Up @@ -216,8 +217,9 @@ pub async fn cmd_bookmark_list(

#[cfg(feature = "git")]
if jj_lib::git::get_git_backend(repo.store()).is_ok() {
// Print only one of these hints. It's not important to mention unexported
// bookmarks, but user might wonder why deleted bookmarks are still listed.
// Print only one of these hints. It's not important to mention
// unexported bookmarks, but user might wonder why deleted
// bookmarks are still listed.
let deleted_tracking = bookmark_list_items
.iter()
.filter(|item| item.primary.is_local() && item.primary.is_absent())
Expand Down
6 changes: 3 additions & 3 deletions cli/src/commands/bookmark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ async fn is_fast_forward(
new_target_id: &CommitId,
) -> Result<bool, CommandError> {
if old_target.is_present() {
// Strictly speaking, "all" old targets should be ancestors, but we allow
// conflict resolution by setting bookmark to "any" of the old target
// descendants.
// Strictly speaking, "all" old targets should be ancestors, but we
// allow conflict resolution by setting bookmark to "any" of the
// old target descendants.
let found = fallible_any(old_target.added_ids(), async |old| {
repo.index().is_ancestor(old, new_target_id).await
})
Expand Down
5 changes: 3 additions & 2 deletions cli/src/commands/bookmark/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ pub async fn cmd_bookmark_set(
let mut moved_bookmark_count = 0;
for name in bookmark_names {
let old_target = repo.view().get_local_bookmark(name);
// If a bookmark is absent locally but is still tracking remote bookmarks,
// we are resurrecting the local bookmark, not "creating" a new bookmark.
// If a bookmark is absent locally but is still tracking remote
// bookmarks, we are resurrecting the local bookmark, not
// "creating" a new bookmark.
if old_target.is_absent() && !has_tracked_remote_bookmarks(repo, name) {
new_bookmarks.insert(name);
} else if old_target.as_normal() != Some(target_commit.id()) {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/bookmark/untrack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ pub async fn cmd_bookmark_untrack(
let mut symbols = Vec::new();
for (symbol, remote_ref) in matched_refs {
if ignored_remote.is_some_and(|ignored| symbol.remote == ignored) {
// This restriction can be lifted if we want to support untracked @git
// bookmarks.
// This restriction can be lifted if we want to support untracked
// @git bookmarks.
writeln!(
ui.warning_default(),
"Git-tracking bookmark cannot be untracked: {symbol}"
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/config/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pub async fn cmd_config_set(
) -> Result<(), CommandError> {
let mut file = args.level.edit_config_file(ui, command)?;

// If the user is trying to change the author config, we should warn them that
// it won't affect the working copy author
// If the user is trying to change the author config, we should warn them
// that it won't affect the working copy author
if args.name == ConfigNamePathBuf::from_iter(vec!["user", "name"]) {
check_wc_author(ui, command, &args.value, AuthorChange::Name).await?;
} else if args.name == ConfigNamePathBuf::from_iter(vec!["user", "email"]) {
Expand Down
36 changes: 20 additions & 16 deletions cli/src/commands/converge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ impl<'a> Converge<'a> {
short_change_hash(&self.change_id)
)?;

// Call the library function to attempt to converge the change automatically.
// Call the library function to attempt to converge the change
// automatically.
let automatic_converge_result = {
// Initially we start with zero knowledge about what the solution should look
// like.
// Initially we start with zero knowledge about what the solution
// should look like.
let author = None;
let description = None;
let parents = None;
Expand All @@ -234,8 +235,8 @@ impl<'a> Converge<'a> {
.await?
};

// Now solve the author, description and parents, prompting the user for input
// if necessary.
// Now solve the author, description and parents, prompting the user for
// input if necessary.
let author = self.generic_solver(automatic_converge_result.author, Self::choose_author)?;
let description = self.generic_solver(
automatic_converge_result.description,
Expand Down Expand Up @@ -264,8 +265,9 @@ impl<'a> Converge<'a> {
return Err(user_error("Could not converge change"));
};

// If we do not have a tree yet, call the converge_change library function
// again, now that we have the author, description and parents.
// If we do not have a tree yet, call the converge_change library
// function again, now that we have the author, description and
// parents.
let tree = match automatic_converge_result.tree {
Some(tree) => Ok(tree),
None => {
Expand Down Expand Up @@ -391,8 +393,9 @@ impl<'a> Converge<'a> {

let value_fn = |commit: &Commit| commit.parent_ids().to_vec();

// A function that takes one of the divergent commits and returns a string that
// displays that commit's id and then its parents (one parent per line)
// A function that takes one of the divergent commits and returns a
// string that displays that commit's id and then its parents
// (one parent per line)
let display_fn = |commit: &Commit, _formatter: &mut dyn Formatter| {
let mut display_string = String::new();
writeln!(display_string, "{}:", short_commit_hash(commit.id()))
Expand Down Expand Up @@ -425,8 +428,8 @@ impl<'a> Converge<'a> {
_excluded_divergent_commits: HashSet<CommitId>,
) -> Result<String, CommandError> {
let distinct_values = {
// Add the values of the divergent commits to the map, deduplicating them as we
// go.
// Add the values of the divergent commits to the map, deduplicating
// them as we go.
let mut distinct_values = IndexMap::new();
for commit in self.truncated_evolution_graph.divergent_commits() {
distinct_values
Expand Down Expand Up @@ -483,9 +486,10 @@ fn choose_change<'a>(
if divergent_changes.len() == 1 {
return Ok(Some(divergent_changes.keys().next().unwrap()));
}
// TODO: consider using heuristics to automatically choose a "good" change-id to
// converge, falling back to prompting the user only if the heuristics are
// inconclusive. This is specially important in non-interactive mode.
// TODO: consider using heuristics to automatically choose a "good"
// change-id to converge, falling back to prompting the user only if the
// heuristics are inconclusive. This is specially important in
// non-interactive mode.
if !interactive {
return Err(
user_error("Cannot automatically choose which change to converge").hinted(
Expand Down Expand Up @@ -535,8 +539,8 @@ where
{
assert!(!divergent_commits.is_empty());
let distinct_values = {
// Add the values of the divergent commits to the map, deduplicating them as we
// go.
// Add the values of the divergent commits to the map, deduplicating
// them as we go.
let mut distinct_values = IndexMap::new();
for commit in divergent_commits {
distinct_values.entry(value_fn(commit)).or_insert(commit);
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/debug/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ pub async fn cmd_debug_object(
command: &CommandHelper,
args: &DebugObjectArgs,
) -> Result<(), CommandError> {
// Resolve the operation without loading the repo, so this command can be used
// even if e.g. the view object is broken.
// Resolve the operation without loading the repo, so this command can be
// used even if e.g. the view object is broken.
let workspace = command.load_workspace()?;
let repo_loader = workspace.repo_loader();

Expand Down
5 changes: 3 additions & 2 deletions cli/src/commands/debug/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ pub async fn cmd_debug_tree(
};
let store = workspace_command.repo().store();
let tree = store.get_tree(dir, &tree_id).await?;
// We can't use `MergedTree` here, since it only supports iterating from the
// root, but we support a `--dir` option to read trees at any path.
// We can't use `MergedTree` here, since it only supports iterating
// from the root, but we support a `--dir` option to read trees at
// any path.
Box::new(
tree.entries_matching(matcher.as_ref())
.map(|(path, value)| (path, Ok(Merge::normal(value)))),
Expand Down
7 changes: 4 additions & 3 deletions cli/src/commands/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ pub(crate) async fn cmd_describe(
if let Some(trailer_template) = parse_trailers_template(ui, &tx)? {
for commit_builder in &mut commit_builders {
// The first trailer would become the first line of the description.
// Also, a commit with no description is treated in a special way in jujutsu: it
// can be discarded as soon as it's no longer the working copy. Adding a
// trailer to an empty description would break that logic.
// Also, a commit with no description is treated in a special way in
// jujutsu: it can be discarded as soon as it's no longer the
// working copy. Adding a trailer to an empty description would
// break that logic.
if use_editor || !commit_builder.description().is_empty() {
let temp_commit = commit_builder.write_hidden().await?;
let new_description = add_trailers_with_template(&trailer_template, &temp_commit)?;
Expand Down
Loading