ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: rename snapshot() to maybe_snapshot(), make inner function private

This function respects --ignore-working-copy and --at-op arguments, but the
name snapshot() sounds like it could forcibly trigger the snapshotting. Let's
clarify the actual behavior.

import_git_refs_and_head() and snapshot_working_copy() are unchecked functions,
and there are no external callers.
This commit is contained in:
Yuya Nishihara 2024-01-11 19:57:13 +09:00
parent 650c1f6521
commit 7e62d5ef36
3 changed files with 5 additions and 5 deletions

View file

@ -595,7 +595,7 @@ impl CommandHelper {
#[instrument(skip(self, ui))]
pub fn workspace_helper(&self, ui: &mut Ui) -> Result<WorkspaceCommandHelper, CommandError> {
let mut workspace_command = self.workspace_helper_no_snapshot(ui)?;
workspace_command.snapshot(ui)?;
workspace_command.maybe_snapshot(ui)?;
Ok(workspace_command)
}
@ -795,7 +795,7 @@ impl WorkspaceCommandHelper {
/// Snapshot the working copy if allowed, and import Git refs if the working
/// copy is collocated with Git.
#[instrument(skip_all)]
pub fn snapshot(&mut self, ui: &mut Ui) -> Result<(), CommandError> {
pub fn maybe_snapshot(&mut self, ui: &mut Ui) -> Result<(), CommandError> {
if self.may_update_working_copy {
if self.working_copy_shared_with_git {
self.import_git_refs_and_head(ui)?;
@ -1297,7 +1297,7 @@ Set which revision the branch points to with `jj branch set {branch_name} -r <RE
}
#[instrument(skip_all)]
pub fn snapshot_working_copy(&mut self, ui: &mut Ui) -> Result<(), CommandError> {
fn snapshot_working_copy(&mut self, ui: &mut Ui) -> Result<(), CommandError> {
let workspace_id = self.workspace_id().to_owned();
let get_wc_commit = |repo: &ReadonlyRepo| -> Result<Option<_>, _> {
repo.view()

View file

@ -81,7 +81,7 @@ pub(crate) fn cmd_init(
Workspace::init_external_git(command.settings(), &wc_path, &git_store_path)?;
let mut workspace_command = command.for_loaded_repo(ui, workspace, repo)?;
git::maybe_add_gitignore(&workspace_command)?;
workspace_command.snapshot(ui)?;
workspace_command.maybe_snapshot(ui)?;
if !workspace_command.working_copy_shared_with_git() {
let mut tx = workspace_command.start_transaction();
let stats = jj_lib::git::import_some_refs(

View file

@ -290,7 +290,7 @@ fn cmd_workspace_update_stale(
// fine if we picked the new wc_commit_id.
let known_wc_commit = {
let mut workspace_command = command.for_stale_working_copy(ui)?;
workspace_command.snapshot(ui)?;
workspace_command.maybe_snapshot(ui)?;
let wc_commit_id = workspace_command.get_wc_commit_id().unwrap();
workspace_command.repo().store().get_commit(wc_commit_id)?
};