Skip to content

Commit 1291cc3

Browse files
committed
Add a dry_run flag to SnapshotOptions.
This commit only adds the flag to the list of options, and does not provide an implementation. When set, it simply returns an error. At Google, we are implementing a tool that needs to know the state of the jj repo constantly. Always snapshotting and updating .jj/working_copy/checkout increases the likelihood of write races. To fix this, I'd like to add a --dry-run flag to SnapshotOptions to make it not update the working copy. This is similar to the request in jj-vcs#2562
1 parent fae66ac commit 1291cc3

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

cli/src/cli_util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,7 @@ to the current parents may contain changes from multiple commits.
14091409
start_tracking_matcher,
14101410
max_new_file_size,
14111411
conflict_marker_style,
1412+
dry_run: false,
14121413
})
14131414
}
14141415

cli/src/merge_tools/diff_working_copies.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ diff editing in mind and be a little inaccurate.
299299
start_tracking_matcher: &EverythingMatcher,
300300
max_new_file_size: u64::MAX,
301301
conflict_marker_style,
302+
dry_run: false,
302303
})?;
303304
Ok(output_tree_state.current_tree_id().clone())
304305
}

lib/src/local_working_copy.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,8 +966,16 @@ impl TreeState {
966966
start_tracking_matcher,
967967
max_new_file_size,
968968
conflict_marker_style,
969+
dry_run,
969970
} = options;
970971

972+
if dry_run {
973+
return Err(SnapshotError::Other {
974+
message: "dry_run is not supported yet".to_string(),
975+
err: "dry_run is not supported yet".into(),
976+
});
977+
}
978+
971979
let sparse_matcher = self.sparse_matcher();
972980

973981
let fsmonitor_clock_needs_save = *fsmonitor_settings != FsmonitorSettings::None;

lib/src/working_copy.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ pub struct SnapshotOptions<'a> {
222222
pub max_new_file_size: u64,
223223
/// Expected conflict marker style for checking for changed files.
224224
pub conflict_marker_style: ConflictMarkerStyle,
225+
/// If true, skip any updates to the working copy metadata files when
226+
/// snapshotting.
227+
pub dry_run: bool,
225228
}
226229

227230
impl SnapshotOptions<'_> {
@@ -234,6 +237,7 @@ impl SnapshotOptions<'_> {
234237
start_tracking_matcher: &EverythingMatcher,
235238
max_new_file_size: u64::MAX,
236239
conflict_marker_style: ConflictMarkerStyle::default(),
240+
dry_run: false,
237241
}
238242
}
239243
}

lib/tests/test_local_working_copy.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,3 +2222,15 @@ fn test_snapshot_max_new_file_size() {
22222222
UntrackedReason::FileTooLarge { .. }
22232223
);
22242224
}
2225+
2226+
#[test]
2227+
fn test_dry_run() {
2228+
let mut test_workspace = TestWorkspace::init();
2229+
let options = SnapshotOptions {
2230+
dry_run: true,
2231+
..SnapshotOptions::empty_for_test()
2232+
};
2233+
test_workspace
2234+
.snapshot_with_options(&options)
2235+
.expect_err("dry_run is not implemented yet");
2236+
}

0 commit comments

Comments
 (0)