Skip to content
Draft
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
9 changes: 9 additions & 0 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ use jj_lib::working_copy::SnapshotStats;
use jj_lib::working_copy::UntrackedReason;
use jj_lib::working_copy::WorkingCopy;
use jj_lib::working_copy::WorkingCopyFactory;
use jj_lib::working_copy::WorkspaceAnnotations;
use jj_lib::working_copy::WorkingCopyFreshness;
use jj_lib::workspace::DefaultWorkspaceLoaderFactory;
use jj_lib::workspace::LockedWorkspace;
Expand Down Expand Up @@ -2137,6 +2138,14 @@ to the current parents may contain changes from multiple commits.
mut_repo
.set_wc_commit(workspace_name, new_wc_commit.id().clone())
.map_err(snapshot_command_error)?;
let annotations = WorkspaceAnnotations {
commit_id: Some(new_wc_commit.id()),
};
locked_ws
.locked_wc()
.set_workspace_annotations(annotations)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have guessed that we could pass the commit id to LockedWorkingCopy::finish() instead of adding a new set_workspace_annotations() method. Why does that not work? I didn't quite follow the explanation in the commit description.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting to pass WorkspaceAnnotations into finish()? For example:

    async fn finish(
        self: Box<Self>,
        operation_id: OperationId,
        annotations: WorkspaceAnnotations<'_>,
    ) -> Result<Box<dyn WorkingCopy>, WorkingCopyStateError>;

I believe this would work. I have not tested it yet.

The initial motivation for set_workspace_annotations() was to keep finish() focused strictly on operation finalization. That said, bundling checkout metadata into finish() makes sense if we'd prefer to avoid adding a separate method to LockedWorkingCopy. Thoughts?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even:

    async fn finish(
        self: Box<Self>,
        operation_id: OperationId,
        wc_commit_id: CommitId,
    ) -> Result<Box<dyn WorkingCopy>, WorkingCopyStateError>;

And removing the WorkspaceAnnotations struct?

.await
.map_err(snapshot_command_error)?;

// Rebase descendants
let num_rebased = mut_repo
Expand Down
19 changes: 19 additions & 0 deletions lib/src/working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use thiserror::Error;
use tracing::instrument;

use crate::backend::BackendError;
use crate::backend::CommitId;
use crate::commit::Commit;
use crate::gitignore::GitIgnoreError;
use crate::gitignore::GitIgnoreFile;
Expand Down Expand Up @@ -105,6 +106,14 @@ pub trait WorkingCopyFactory {
) -> Result<Box<dyn WorkingCopy>, WorkingCopyStateError>;
}

/// Annotations and metadata associated with a working-copy checkout.
#[derive(Debug, Clone, Default)]
pub struct WorkspaceAnnotations<'a> {
/// The working-copy commit ID associated with this checkout, if one was
/// created or updated.
pub commit_id: Option<&'a CommitId>,
}

/// A working copy that's being modified.
#[async_trait]
pub trait LockedWorkingCopy: Any + Send {
Expand All @@ -129,6 +138,16 @@ pub trait LockedWorkingCopy: Any + Send {
/// Update to another commit without touching the files in the working copy.
async fn reset(&mut self, commit: &Commit) -> Result<(), ResetError>;

/// Notify the locked working copy of updated workspace annotations.
async fn set_workspace_annotations(
&mut self,
_annotations: WorkspaceAnnotations<'_>,
) -> Result<(), ResetError> {
// Default no-op for backends that don't track annotations in their checkout
// state.
Ok(())
}

/// Update to another commit without touching the files in the working copy,
/// without assuming that the previous tree exists.
async fn recover(&mut self, commit: &Commit) -> Result<(), ResetError>;
Expand Down
Loading