Skip to content

Commit

Permalink
repo: remove &UserSettings argument from new/rewrite_commit(), use se…
Browse files Browse the repository at this point in the history
…lf.settings
  • Loading branch information
yuja committed Dec 31, 2024
1 parent 14b5220 commit cff7384
Show file tree
Hide file tree
Showing 55 changed files with 720 additions and 1,186 deletions.
2 changes: 1 addition & 1 deletion cli/examples/custom-command/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn run_custom_command(
let mut tx = workspace_command.start_transaction();
let new_commit = tx
.repo_mut()
.rewrite_commit(command_helper.settings(), &commit)
.rewrite_commit(&commit)
.set_description("Frobnicated!")
.write()?;
tx.finish(ui, "frobnicate")?;
Expand Down
21 changes: 9 additions & 12 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ impl CommandHelper {
let mut tx = start_repo_transaction(&base_repo, &self.data.string_args);
for other_op_head in op_heads.into_iter().skip(1) {
tx.merge_operation(other_op_head)?;
let num_rebased = tx.repo_mut().rebase_descendants(&self.data.settings)?;
let num_rebased = tx.repo_mut().rebase_descendants()?;
if num_rebased > 0 {
writeln!(
ui.status(),
Expand Down Expand Up @@ -1070,13 +1070,13 @@ impl WorkspaceCommandHelper {
let workspace_id = self.workspace_id().to_owned();
let new_git_head_commit = tx.repo().store().get_commit(new_git_head_id)?;
tx.repo_mut()
.check_out(workspace_id, self.env.settings(), &new_git_head_commit)?;
.check_out(workspace_id, &new_git_head_commit)?;
let mut locked_ws = self.workspace.start_working_copy_mutation()?;
// The working copy was presumably updated by the git command that updated
// HEAD, so we just need to reset our working copy
// state to it without updating working copy files.
locked_ws.locked_wc().reset(&new_git_head_commit)?;
tx.repo_mut().rebase_descendants(self.env.settings())?;
tx.repo_mut().rebase_descendants()?;
self.user_repo = ReadonlyUserRepo::new(tx.commit("import git head")?);
locked_ws.finish(self.user_repo.repo.op_id().clone())?;
if old_git_head.is_present() {
Expand Down Expand Up @@ -1117,7 +1117,7 @@ impl WorkspaceCommandHelper {
print_git_import_stats(ui, tx.repo(), &stats, false)?;
let mut tx = tx.into_inner();
// Rebase here to show slightly different status message.
let num_rebased = tx.repo_mut().rebase_descendants(self.settings())?;
let num_rebased = tx.repo_mut().rebase_descendants()?;
if num_rebased > 0 {
writeln!(
ui.status(),
Expand Down Expand Up @@ -1192,7 +1192,6 @@ impl WorkspaceCommandHelper {
locked_ws.locked_wc(),
&self.user_repo.repo,
workspace_id,
self.env.settings(),
"RECOVERY COMMIT FROM `jj workspace update-stale`
This commit contains changes that were written to the working copy by an
Expand Down Expand Up @@ -1842,7 +1841,7 @@ See https://jj-vcs.github.io/jj/latest/working-copy/#stale-working-copy \
tx.set_is_snapshot(true);
let mut_repo = tx.repo_mut();
let commit = mut_repo
.rewrite_commit(self.env.settings(), &wc_commit)
.rewrite_commit(&wc_commit)
.set_tree_id(new_tree_id)
.write()
.map_err(snapshot_command_error)?;
Expand All @@ -1852,7 +1851,7 @@ See https://jj-vcs.github.io/jj/latest/working-copy/#stale-working-copy \

// Rebase descendants
let num_rebased = mut_repo
.rebase_descendants(self.env.settings())
.rebase_descendants()
.map_err(snapshot_command_error)?;
if num_rebased > 0 {
writeln!(
Expand Down Expand Up @@ -1945,7 +1944,7 @@ See https://jj-vcs.github.io/jj/latest/working-copy/#stale-working-copy \
writeln!(ui.status(), "Nothing changed.")?;
return Ok(());
}
let num_rebased = tx.repo_mut().rebase_descendants(self.settings())?;
let num_rebased = tx.repo_mut().rebase_descendants()?;
if num_rebased > 0 {
writeln!(ui.status(), "Rebased {num_rebased} descendant commits")?;
}
Expand All @@ -1959,8 +1958,7 @@ See https://jj-vcs.github.io/jj/latest/working-copy/#stale-working-copy \
.is_some()
{
let wc_commit = tx.repo().store().get_commit(wc_commit_id)?;
tx.repo_mut()
.check_out(workspace_id.clone(), self.settings(), &wc_commit)?;
tx.repo_mut().check_out(workspace_id.clone(), &wc_commit)?;
writeln!(
ui.warning_default(),
"The working-copy commit in workspace '{}' became immutable, so a new commit \
Expand Down Expand Up @@ -2280,9 +2278,8 @@ impl WorkspaceCommandTransaction<'_> {

pub fn check_out(&mut self, commit: &Commit) -> Result<Commit, CheckOutCommitError> {
let workspace_id = self.helper.workspace_id().to_owned();
let settings = self.helper.settings();
self.id_prefix_context.take(); // invalidate
self.tx.repo_mut().check_out(workspace_id, settings, commit)
self.tx.repo_mut().check_out(workspace_id, commit)
}

pub fn edit(&mut self, commit: &Commit) -> Result<(), EditCommitError> {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/abandon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ pub(crate) fn cmd_abandon(
}
let (num_rebased, extra_msg) = if args.restore_descendants {
(
tx.repo_mut().reparent_descendants(command.settings())?,
tx.repo_mut().reparent_descendants()?,
" (while preserving their content)",
)
} else {
(tx.repo_mut().rebase_descendants(command.settings())?, "")
(tx.repo_mut().rebase_descendants()?, "")
};

if let Some(mut formatter) = ui.status_formatter() {
Expand Down
8 changes: 2 additions & 6 deletions cli/src/commands/absorb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,8 @@ pub(crate) fn cmd_absorb(
workspace_command.check_rewritable(selected_trees.target_commits.keys())?;

let mut tx = workspace_command.start_transaction();
let (rewritten_commits, num_rebased) = absorb_hunks(
tx.repo_mut(),
&source,
selected_trees.target_commits,
command.settings(),
)?;
let (rewritten_commits, num_rebased) =
absorb_hunks(tx.repo_mut(), &source, selected_trees.target_commits)?;

if let Some(mut formatter) = ui.status_formatter() {
if !rewritten_commits.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/backout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub(crate) fn cmd_backout(
let new_parent_ids = parents.iter().map(|commit| commit.id().clone()).collect();
let new_commit = tx
.repo_mut()
.new_commit(command.settings(), new_parent_ids, new_tree.id())
.new_commit(new_parent_ids, new_tree.id())
.set_description(new_commit_description)
.write()?;
parents = vec![new_commit];
Expand Down
11 changes: 2 additions & 9 deletions cli/src/commands/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ new working-copy commit.
)?;
}

let mut commit_builder = tx
.repo_mut()
.rewrite_commit(command.settings(), &commit)
.detach();
let mut commit_builder = tx.repo_mut().rewrite_commit(&commit).detach();
commit_builder.set_tree_id(tree_id);
if args.reset_author {
commit_builder.set_author(commit_builder.committer().clone());
Expand Down Expand Up @@ -154,11 +151,7 @@ new working-copy commit.
if !workspace_ids.is_empty() {
let new_wc_commit = tx
.repo_mut()
.new_commit(
command.settings(),
vec![new_commit.id().clone()],
commit.tree_id().clone(),
)
.new_commit(vec![new_commit.id().clone()], commit.tree_id().clone())
.write()?;

// Does nothing if there's no bookmarks to advance.
Expand Down
8 changes: 2 additions & 6 deletions cli/src/commands/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ pub(crate) fn cmd_describe(
// Edit descriptions in topological order
.rev()
.map(|commit| -> Result<_, CommandError> {
let mut commit_builder = tx
.repo_mut()
.rewrite_commit(command.settings(), commit)
.detach();
let mut commit_builder = tx.repo_mut().rewrite_commit(commit).detach();
if commit_builder.description().is_empty() {
commit_builder
.set_description(command.settings().get_string("ui.default-description")?);
Expand Down Expand Up @@ -244,14 +241,13 @@ pub(crate) fn cmd_describe(
// rewriting the same commit multiple times, and adding additional entries
// in the predecessor chain.
tx.repo_mut().transform_descendants(
command.settings(),
commit_descriptions
.keys()
.map(|&id| id.clone())
.collect_vec(),
|rewriter| {
let old_commit_id = rewriter.old_commit().id().clone();
let mut commit_builder = rewriter.rebase(command.settings())?;
let mut commit_builder = rewriter.rebase()?;
if let Some(description) = commit_descriptions.get(&old_commit_id) {
commit_builder = commit_builder.set_description(description);
if args.reset_author {
Expand Down
6 changes: 3 additions & 3 deletions cli/src/commands/diffedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,18 @@ don't make any changes, then the operation will be aborted.",
} else {
let new_commit = tx
.repo_mut()
.rewrite_commit(command.settings(), &target_commit)
.rewrite_commit(&target_commit)
.set_tree_id(tree_id)
.write()?;
// rebase_descendants early; otherwise `new_commit` would always have
// a conflicted change id at this point.
let (num_rebased, extra_msg) = if args.restore_descendants {
(
tx.repo_mut().reparent_descendants(command.settings())?,
tx.repo_mut().reparent_descendants()?,
" (while preserving their content)",
)
} else {
(tx.repo_mut().rebase_descendants(command.settings())?, "")
(tx.repo_mut().rebase_descendants()?, "")
};
if let Some(mut formatter) = ui.status_formatter() {
write!(formatter, "Created ")?;
Expand Down
3 changes: 1 addition & 2 deletions cli/src/commands/duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,9 @@ pub(crate) fn cmd_duplicate(
&& args.insert_after.is_empty()
&& args.insert_before.is_empty()
{
duplicate_commits_onto_parents(command.settings(), tx.repo_mut(), &to_duplicate)?
duplicate_commits_onto_parents(tx.repo_mut(), &to_duplicate)?
} else {
duplicate_commits(
command.settings(),
tx.repo_mut(),
&to_duplicate,
&parent_commit_ids,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/file/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub(crate) fn cmd_file_chmod(

let new_tree_id = tree_builder.write_tree(store)?;
tx.repo_mut()
.rewrite_commit(command.settings(), &commit)
.rewrite_commit(&commit)
.set_tree_id(new_tree_id)
.write()?;
tx.finish(
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/file/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub(crate) fn cmd_file_track(
let mut tx = workspace_command.start_transaction().into_inner();
let (mut locked_ws, _wc_commit) = workspace_command.start_working_copy_mutation()?;
let (_tree_id, stats) = locked_ws.locked_wc().snapshot(&options)?;
let num_rebased = tx.repo_mut().rebase_descendants(command.settings())?;
let num_rebased = tx.repo_mut().rebase_descendants()?;
if num_rebased > 0 {
writeln!(ui.status(), "Rebased {num_rebased} descendant commits")?;
}
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/file/untrack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(crate) fn cmd_file_untrack(
let new_tree_id = tree_builder.write_tree(&store)?;
let new_commit = tx
.repo_mut()
.rewrite_commit(command.settings(), &wc_commit)
.rewrite_commit(&wc_commit)
.set_tree_id(new_tree_id)
.write()?;
// Reset the working copy to the new commit
Expand Down Expand Up @@ -105,7 +105,7 @@ Make sure they're ignored, then try again.",
locked_ws.locked_wc().reset(&new_commit)?;
}
}
let num_rebased = tx.repo_mut().rebase_descendants(command.settings())?;
let num_rebased = tx.repo_mut().rebase_descendants()?;
if num_rebased > 0 {
writeln!(ui.status(), "Rebased {num_rebased} descendant commits")?;
}
Expand Down
3 changes: 1 addition & 2 deletions cli/src/commands/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ pub(crate) fn cmd_fix(
let mut num_checked_commits = 0;
let mut num_fixed_commits = 0;
tx.repo_mut().transform_descendants(
command.settings(),
root_commits.iter().cloned().collect_vec(),
|mut rewriter| {
// TODO: Build the trees in parallel before `transform_descendants()` and only
Expand Down Expand Up @@ -287,7 +286,7 @@ pub(crate) fn cmd_fix(
if changes > 0 {
num_fixed_commits += 1;
let new_tree = tree_builder.write_tree(rewriter.mut_repo().store())?;
let builder = rewriter.reparent(command.settings());
let builder = rewriter.reparent();
builder.set_tree_id(new_tree).write()?;
}
Ok(())
Expand Down
11 changes: 3 additions & 8 deletions cli/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub(crate) fn cmd_new(
let merged_tree = merge_commit_trees(tx.repo(), &parent_commits)?;
let new_commit = tx
.repo_mut()
.new_commit(command.settings(), parent_commit_ids, merged_tree.id())
.new_commit(parent_commit_ids, merged_tree.id())
.set_description(join_message_paragraphs(&args.message_paragraphs))
.write()?;

Expand All @@ -208,15 +208,10 @@ pub(crate) fn cmd_new(
.cloned()
.chain(std::iter::once(new_commit.id().clone()))
.collect_vec();
rebase_commit(
command.settings(),
tx.repo_mut(),
child_commit,
new_parent_ids,
)?;
rebase_commit(tx.repo_mut(), child_commit, new_parent_ids)?;
num_rebased += 1;
}
num_rebased += tx.repo_mut().rebase_descendants(command.settings())?;
num_rebased += tx.repo_mut().rebase_descendants()?;

if args.no_edit {
if let Some(mut formatter) = ui.status_formatter() {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/operation/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn cmd_op_diff(
} else {
to_op = workspace_command.resolve_single_op(args.operation.as_deref().unwrap_or("@"))?;
let to_op_parents: Vec<_> = to_op.parents().try_collect()?;
from_op = repo_loader.merge_operations(command.settings(), to_op_parents, None)?;
from_op = repo_loader.merge_operations(to_op_parents, None)?;
}
let graph_style = GraphStyle::from_settings(command.settings())?;
let with_content_format = LogContentFormat::new(ui, command.settings())?;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/operation/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn do_op_log(
op: &Operation,
with_content_format: &LogContentFormat| {
let parents: Vec<_> = op.parents().try_collect()?;
let parent_op = repo_loader.merge_operations(settings, parents, None)?;
let parent_op = repo_loader.merge_operations(parents, None)?;
let parent_repo = repo_loader.load_at(&parent_op)?;
let repo = repo_loader.load_at(op)?;

Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/operation/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn cmd_op_show(
let repo_loader = workspace_command.workspace().repo_loader();
let op = workspace_command.resolve_single_op(&args.operation)?;
let parents: Vec<_> = op.parents().try_collect()?;
let parent_op = repo_loader.merge_operations(command.settings(), parents, None)?;
let parent_op = repo_loader.merge_operations(parents, None)?;
let parent_repo = repo_loader.load_at(&parent_op)?;
let repo = repo_loader.load_at(&op)?;

Expand Down
3 changes: 1 addition & 2 deletions cli/src/commands/parallelize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ pub(crate) fn cmd_parallelize(
}

tx.repo_mut().transform_descendants(
command.settings(),
target_commits.iter().ids().cloned().collect_vec(),
|mut rewriter| {
// Commits in the target set do not depend on each other but they still depend
Expand All @@ -137,7 +136,7 @@ pub(crate) fn cmd_parallelize(
rewriter.set_new_rewritten_parents(&new_parents);
}
if rewriter.parents_changed() {
let builder = rewriter.rebase(command.settings())?;
let builder = rewriter.rebase()?;
builder.write()?;
}
Ok(())
Expand Down
Loading

0 comments on commit cff7384

Please sign in to comment.