working_copy: Add LockedWorkingCopy::set_workspace_annotations hook - #9923
working_copy: Add LockedWorkingCopy::set_workspace_annotations hook#9923rayaq-siddiqui wants to merge 1 commit into
LockedWorkingCopy::set_workspace_annotations hook#9923Conversation
|
I guess this is the thing @hooper asked some questions about in the Discord. Anyway to adhere to our commit style guidelines drop the conventional commit |
b6668a6 to
44fc947
Compare
LockedWorkingCopy::set_workspace_annotations hookLockedWorkingCopy::set_workspace_annotations hook
Custom working-copy backends (such as those used at Google) often maintain separate metadata stores alongside the repository. These backends need to record the checked-out commit ID (`@`) in synchronization with the working copy's operation ID. Maintaining this explicit mapping allows external tools, including developer environments and build systems, to accurately determine workspace state and verify code provenance. Currently, when commands trigger automatic snapshotting of dirty working-copy files (e.g., during `jj status`), a new working-copy commit is created, but `LockedWorkingCopy` is not informed of the updated commit ID. To address this, introduce a hook on `LockedWorkingCopy` that allows backends to be notified when checkout annotations or metadata are updated: - Add `WorkspaceAnnotations` to encapsulate working-copy checkout metadata (currently holding the associated `CommitId`). - Add `LockedWorkingCopy::set_workspace_annotations` with a default no-op implementation for backends that do not track this state (such as `LocalWorkingCopy`). - Invoke `set_workspace_annotations` in `cli_util::snapshot_working_copy()` after updating the snapshot working-copy commit.
44fc947 to
8f6cd16
Compare
|
This is actually different from the problem I mentioned on Discord a few weeks ago, but it has a very similar shape. That older one (passing operation attributes from the working copy implementation) seemed less controversial, but I wanted to get some early feedback on this new one in case we missed a nicer way to do it. I haven't checked if this one is as tricky to test, but that's a consideration in addition to performance. |
I agree.
While I currently don't really have an idea on how to do it in a nicer way, the first thing which is surely a trade-off to make is that the And if this is a static schema for all of Google I don't really think it should live upstream (that's a personal opinion). |
| }; | ||
| locked_ws | ||
| .locked_wc() | ||
| .set_workspace_annotations(annotations) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
This introduces a mechanism to pass metadata and annotations to a working-copy backend when its checkout is updated.
Specifically:
WorkspaceAnnotationsstruct to hold the checkout metadata (currently the associatedCommitId).set_workspace_annotationsmethod to theLockedWorkingCopytrait, allowing backends to be notified of these updates. It defaults to a no-op for backends that do not track this state (likeLocalWorkingCopy).snapshot_working_copyin the CLI after the working-copy commit is updated.Checklist
If applicable:
CHANGELOG.mdREADME.md,docs/,demos/)cli/src/config-schema.json)how it works, how it's organized), including any code drafted by an LLM.
an eye towards deleting anything that is irrelevant, clarifying anything
that is confusing, and adding details that are relevant. This includes,
for example, commit descriptions, PR descriptions, and code comments.