Skip to content

Commit

Permalink
repo: remove &UserSettings argument from start_transaction(), use sel…
Browse files Browse the repository at this point in the history
…f.settings
  • Loading branch information
yuja committed Dec 31, 2024
1 parent 57806ee commit 14b5220
Show file tree
Hide file tree
Showing 28 changed files with 364 additions and 382 deletions.
24 changes: 6 additions & 18 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,7 @@ impl CommandHelper {
)?;
let base_repo = repo_loader.load_at(&op_heads[0])?;
// TODO: It may be helpful to print each operation we're merging here
let mut tx = start_repo_transaction(
&base_repo,
&self.data.settings,
&self.data.string_args,
);
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)?;
Expand Down Expand Up @@ -1841,11 +1837,8 @@ See https://jj-vcs.github.io/jj/latest/working-copy/#stale-working-copy \
.map_err(snapshot_command_error)?
};
if new_tree_id != *wc_commit.tree_id() {
let mut tx = start_repo_transaction(
&self.user_repo.repo,
self.env.settings(),
self.env.command.string_args(),
);
let mut tx =
start_repo_transaction(&self.user_repo.repo, self.env.command.string_args());
tx.set_is_snapshot(true);
let mut_repo = tx.repo_mut();
let commit = mut_repo
Expand Down Expand Up @@ -1933,8 +1926,7 @@ See https://jj-vcs.github.io/jj/latest/working-copy/#stale-working-copy \
}

pub fn start_transaction(&mut self) -> WorkspaceCommandTransaction {
let tx =
start_repo_transaction(self.repo(), self.settings(), self.env.command.string_args());
let tx = start_repo_transaction(self.repo(), self.env.command.string_args());
let id_prefix_context = mem::take(&mut self.user_repo.id_prefix_context);
WorkspaceCommandTransaction {
helper: self,
Expand Down Expand Up @@ -2424,12 +2416,8 @@ jj git init --colocate",
}
}

pub fn start_repo_transaction(
repo: &Arc<ReadonlyRepo>,
settings: &UserSettings,
string_args: &[String],
) -> Transaction {
let mut tx = repo.start_transaction(settings);
pub fn start_repo_transaction(repo: &Arc<ReadonlyRepo>, string_args: &[String]) -> Transaction {
let mut tx = repo.start_transaction();
// TODO: Either do better shell-escaping here or store the values in some list
// type (which we currently don't have).
let shell_escape = |arg: &String| {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/git/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn init_git_refs(
repo: Arc<ReadonlyRepo>,
colocated: bool,
) -> Result<Arc<ReadonlyRepo>, CommandError> {
let mut tx = start_repo_transaction(&repo, command.settings(), command.string_args());
let mut tx = start_repo_transaction(&repo, command.string_args());
// There should be no old refs to abandon, but enforce it.
let mut git_settings = command.settings().git_settings()?;
git_settings.abandon_unreachable_commits = false;
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 @@ -116,7 +116,7 @@ pub fn cmd_op_diff(
let to_repo = repo_loader.load_at(&to_op)?;

// Create a new transaction starting from `to_repo`.
let mut tx = to_repo.start_transaction(command.settings());
let mut tx = to_repo.start_transaction();
// Merge index from `from_repo` to `to_repo`, so commits in `from_repo` are
// accessible.
tx.repo_mut().merge_index(&from_repo);
Expand Down
9 changes: 3 additions & 6 deletions lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,9 @@ impl ReadonlyRepo {
self.loader.settings()
}

pub fn start_transaction(
self: &Arc<ReadonlyRepo>,
user_settings: &UserSettings,
) -> Transaction {
pub fn start_transaction(self: &Arc<ReadonlyRepo>) -> Transaction {
let mut_repo = MutableRepo::new(self.clone(), self.readonly_index(), &self.view);
Transaction::new(mut_repo, user_settings)
Transaction::new(mut_repo, self.settings())
}

pub fn reload_at_head(
Expand Down Expand Up @@ -779,7 +776,7 @@ impl RepoLoader {
};
let final_op = if num_operations > 1 {
let base_repo = self.load_at(&base_op)?;
let mut tx = base_repo.start_transaction(settings);
let mut tx = base_repo.start_transaction();
for other_op in operations {
tx.merge_operation(other_op)?;
tx.repo_mut().rebase_descendants(settings)?;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ pub fn create_and_check_out_recovery_commit(
user_settings: &UserSettings,
description: &str,
) -> Result<(Arc<ReadonlyRepo>, Commit), RecoverWorkspaceError> {
let mut tx = repo.start_transaction(user_settings);
let mut tx = repo.start_transaction();
let repo_mut = tx.repo_mut();

let commit_id = repo
Expand Down
2 changes: 1 addition & 1 deletion lib/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn init_working_copy(
let working_copy_state_path = jj_dir.join("working_copy");
std::fs::create_dir(&working_copy_state_path).context(&working_copy_state_path)?;

let mut tx = repo.start_transaction(user_settings);
let mut tx = repo.start_transaction();
tx.repo_mut().check_out(
workspace_id.clone(),
user_settings,
Expand Down
12 changes: 6 additions & 6 deletions lib/tests/test_annotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn test_annotate_linear() {
let root_commit_id = repo.store().root_commit_id();
let file_path = RepoPath::from_internal_string("file");

let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let mut create_commit = create_commit_fn(tx.repo_mut(), &settings);
let content1 = "";
let content2 = "2a\n2b\n";
Expand Down Expand Up @@ -157,7 +157,7 @@ fn test_annotate_merge_simple() {
// 2 | "2 1"
// |/
// 1 "1"
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let mut create_commit = create_commit_fn(tx.repo_mut(), &settings);
let content1 = "1\n";
let content2 = "2\n1\n";
Expand Down Expand Up @@ -232,7 +232,7 @@ fn test_annotate_merge_split() {
// 2 | "2 1a"
// |/
// 1 "1a 1b"
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let mut create_commit = create_commit_fn(tx.repo_mut(), &settings);
let content1 = "1a\n1b\n";
let content2 = "2\n1a\n";
Expand Down Expand Up @@ -277,7 +277,7 @@ fn test_annotate_merge_split_interleaved() {
// | 2 "2a 2b"
// |
// 1 "1a 1b"
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let mut create_commit = create_commit_fn(tx.repo_mut(), &settings);
let content1 = "1a\n1b\n";
let content2 = "2a\n2b\n";
Expand Down Expand Up @@ -326,7 +326,7 @@ fn test_annotate_merge_dup() {
// 2 | "2 1"
// |/
// 1 "1"
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let mut create_commit = create_commit_fn(tx.repo_mut(), &settings);
let content1 = "1\n";
let content2 = "2\n1\n";
Expand Down Expand Up @@ -373,7 +373,7 @@ fn test_annotate_file_directory_transition() {
let file_path1 = RepoPath::from_internal_string("file/was_dir");
let file_path2 = RepoPath::from_internal_string("file");

let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let mut create_commit = create_commit_fn(tx.repo_mut(), &settings);
let tree1 = create_tree(repo, &[(file_path1, "1\n")]);
let tree2 = create_tree(repo, &[(file_path2, "2\n")]);
Expand Down
10 changes: 5 additions & 5 deletions lib/tests/test_bad_locking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn test_bad_locking_children(backend: TestRepoBackend) {
let repo = &test_workspace.repo;
let workspace_root = test_workspace.workspace.workspace_root();

let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let initial = create_random_commit(tx.repo_mut(), &settings)
.set_parents(vec![repo.store().root_commit_id().clone()])
.write()
Expand All @@ -130,7 +130,7 @@ fn test_bad_locking_children(backend: TestRepoBackend) {
.repo_loader()
.load_at_head(&settings)
.unwrap();
let mut machine1_tx = machine1_repo.start_transaction(&settings);
let mut machine1_tx = machine1_repo.start_transaction();
let child1 = create_random_commit(machine1_tx.repo_mut(), &settings)
.set_parents(vec![initial.id().clone()])
.write()
Expand All @@ -151,7 +151,7 @@ fn test_bad_locking_children(backend: TestRepoBackend) {
.repo_loader()
.load_at_head(&settings)
.unwrap();
let mut machine2_tx = machine2_repo.start_transaction(&settings);
let mut machine2_tx = machine2_repo.start_transaction();
let child2 = create_random_commit(machine2_tx.repo_mut(), &settings)
.set_parents(vec![initial.id().clone()])
.write()
Expand Down Expand Up @@ -191,7 +191,7 @@ fn test_bad_locking_interrupted(backend: TestRepoBackend) {
let test_env = &test_workspace.env;
let repo = &test_workspace.repo;

let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let initial = create_random_commit(tx.repo_mut(), &settings)
.set_parents(vec![repo.store().root_commit_id().clone()])
.write()
Expand All @@ -205,7 +205,7 @@ fn test_bad_locking_interrupted(backend: TestRepoBackend) {
let op_heads_dir = test_workspace.repo_path().join("op_heads");
let backup_path = test_workspace.root_dir().join("backup");
copy_directory(&op_heads_dir, &backup_path);
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
create_random_commit(tx.repo_mut(), &settings)
.set_parents(vec![initial.id().clone()])
.write()
Expand Down
24 changes: 12 additions & 12 deletions lib/tests/test_commit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn test_initial(backend: TestRepoBackend) {
],
);

let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let author_signature = Signature {
name: "author name".to_string(),
email: "author email".to_string(),
Expand Down Expand Up @@ -147,7 +147,7 @@ fn test_rewrite(backend: TestRepoBackend) {
],
);

let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let initial_commit = tx
.repo_mut()
.new_commit(
Expand Down Expand Up @@ -182,7 +182,7 @@ fn test_rewrite(backend: TestRepoBackend) {
let repo = test_env.load_repo_at_head(&rewrite_settings, test_repo.repo_path());
let store = repo.store();
let initial_commit = store.get_commit(initial_commit.id()).unwrap();
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let rewritten_commit = tx
.repo_mut()
.rewrite_commit(&rewrite_settings, &initial_commit)
Expand Down Expand Up @@ -230,7 +230,7 @@ fn test_rewrite_update_missing_user(backend: TestRepoBackend) {
let test_env = &test_repo.env;
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&missing_user_settings);
let mut tx = repo.start_transaction();
let initial_commit = tx
.repo_mut()
.new_commit(
Expand Down Expand Up @@ -260,7 +260,7 @@ fn test_rewrite_update_missing_user(backend: TestRepoBackend) {
let settings = UserSettings::from_config(config).unwrap();
let repo = test_env.load_repo_at_head(&settings, test_repo.repo_path());
let initial_commit = repo.store().get_commit(initial_commit.id()).unwrap();
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let rewritten_commit = tx
.repo_mut()
.rewrite_commit(&settings, &initial_commit)
Expand Down Expand Up @@ -290,7 +290,7 @@ fn test_rewrite_resets_author_timestamp(backend: TestRepoBackend) {
let settings =
UserSettings::from_config(config_with_commit_timestamp(initial_timestamp)).unwrap();
let repo = test_env.load_repo_at_head(&settings, test_repo.repo_path());
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let initial_commit = tx
.repo_mut()
.new_commit(
Expand All @@ -313,7 +313,7 @@ fn test_rewrite_resets_author_timestamp(backend: TestRepoBackend) {
UserSettings::from_config(config_with_commit_timestamp(new_timestamp_1)).unwrap();
let repo = test_env.load_repo_at_head(&settings, test_repo.repo_path());
let initial_commit = repo.store().get_commit(initial_commit.id()).unwrap();
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let rewritten_commit_1 = tx
.repo_mut()
.rewrite_commit(&settings, &initial_commit)
Expand All @@ -337,7 +337,7 @@ fn test_rewrite_resets_author_timestamp(backend: TestRepoBackend) {
UserSettings::from_config(config_with_commit_timestamp(new_timestamp_2)).unwrap();
let repo = test_env.load_repo_at_head(&settings, test_repo.repo_path());
let rewritten_commit_1 = repo.store().get_commit(rewritten_commit_1.id()).unwrap();
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let rewritten_commit_2 = tx
.repo_mut()
.rewrite_commit(&settings, &rewritten_commit_1)
Expand All @@ -363,15 +363,15 @@ fn test_commit_builder_descendants(backend: TestRepoBackend) {
let repo = &test_repo.repo;
let store = repo.store().clone();

let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let mut graph_builder = CommitGraphBuilder::new(&settings, tx.repo_mut());
let commit1 = graph_builder.initial_commit();
let commit2 = graph_builder.commit_with_parents(&[&commit1]);
let commit3 = graph_builder.commit_with_parents(&[&commit2]);
let repo = tx.commit("test").unwrap();

// Test with for_new_commit()
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
tx.repo_mut()
.new_commit(
&settings,
Expand All @@ -387,7 +387,7 @@ fn test_commit_builder_descendants(backend: TestRepoBackend) {
assert_eq!(rebase_map.len(), 0);

// Test with for_rewrite_from()
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let commit4 = tx
.repo_mut()
.rewrite_commit(&settings, &commit2)
Expand All @@ -401,7 +401,7 @@ fn test_commit_builder_descendants(backend: TestRepoBackend) {
assert_eq!(rebase_map.len(), 1);

// Test with for_rewrite_from() but new change id
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
tx.repo_mut()
.rewrite_commit(&settings, &commit2)
.generate_new_change_id()
Expand Down
4 changes: 2 additions & 2 deletions lib/tests/test_commit_concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn test_commit_parallel(backend: TestRepoBackend) {
let settings = settings.clone();
let repo = repo.clone();
s.spawn(move || {
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
write_random_commit(tx.repo_mut(), &settings);
tx.commit("test").unwrap();
});
Expand Down Expand Up @@ -88,7 +88,7 @@ fn test_commit_parallel_instances(backend: TestRepoBackend) {
let settings = settings.clone();
let repo = test_env.load_repo_at_head(&settings, test_workspace.repo_path());
s.spawn(move || {
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
write_random_commit(tx.repo_mut(), &settings);
tx.commit("test").unwrap();
});
Expand Down
12 changes: 6 additions & 6 deletions lib/tests/test_default_revset_graph_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn test_graph_iterator_linearized(skip_transitive_edges: bool) {
// A ~
// |
// root
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let mut graph_builder = CommitGraphBuilder::new(&settings, tx.repo_mut());
let commit_a = graph_builder.initial_commit();
let commit_b = graph_builder.commit_with_parents(&[&commit_a]);
Expand Down Expand Up @@ -105,7 +105,7 @@ fn test_graph_iterator_virtual_octopus(skip_transitive_edges: bool) {
// A B C A B C
// \|/ ~ ~ ~
// root
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let mut graph_builder = CommitGraphBuilder::new(&settings, tx.repo_mut());
let commit_a = graph_builder.initial_commit();
let commit_b = graph_builder.initial_commit();
Expand Down Expand Up @@ -157,7 +157,7 @@ fn test_graph_iterator_simple_fork(skip_transitive_edges: bool) {
// A
// |
// root
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let mut graph_builder = CommitGraphBuilder::new(&settings, tx.repo_mut());
let commit_a = graph_builder.initial_commit();
let commit_b = graph_builder.commit_with_parents(&[&commit_a]);
Expand Down Expand Up @@ -197,7 +197,7 @@ fn test_graph_iterator_multiple_missing(skip_transitive_edges: bool) {
// a B c ~
// \|/
// root
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let mut graph_builder = CommitGraphBuilder::new(&settings, tx.repo_mut());
let commit_a = graph_builder.initial_commit();
let commit_b = graph_builder.initial_commit();
Expand Down Expand Up @@ -242,7 +242,7 @@ fn test_graph_iterator_edge_to_ancestor(skip_transitive_edges: bool) {
// a
// |
// root
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let mut graph_builder = CommitGraphBuilder::new(&settings, tx.repo_mut());
let commit_a = graph_builder.initial_commit();
let commit_b = graph_builder.initial_commit();
Expand Down Expand Up @@ -293,7 +293,7 @@ fn test_graph_iterator_edge_escapes_from_(skip_transitive_edges: bool) {
// A
// |
// root
let mut tx = repo.start_transaction(&settings);
let mut tx = repo.start_transaction();
let mut graph_builder = CommitGraphBuilder::new(&settings, tx.repo_mut());
let commit_a = graph_builder.initial_commit();
let commit_b = graph_builder.commit_with_parents(&[&commit_a]);
Expand Down
Loading

0 comments on commit 14b5220

Please sign in to comment.