From 993de96fc7e4c6c1912e89ff85f6c08844f95a53 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 12 Feb 2022 17:16:19 -0800 Subject: [PATCH] working_copy: stop keeping track of commit ID --- lib/protos/working_copy.proto | 3 ++- lib/src/working_copy.rs | 29 ++++------------------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/lib/protos/working_copy.proto b/lib/protos/working_copy.proto index b47823713..7104208c5 100644 --- a/lib/protos/working_copy.proto +++ b/lib/protos/working_copy.proto @@ -43,6 +43,7 @@ message Checkout { // config? That way users can rename a workspace. string workspace_id = 3; // The checked-out commit, which can be viewed as a cache of the checkout - // recorded in `operation_id`'s operation. + // recorded in `operation_id`'s operation. No longer used. + // TODO: Delete this mid 2022 or so bytes commit_id = 1; } diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index f8f703418..816748872 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -719,28 +719,24 @@ pub struct WorkingCopy { state_path: PathBuf, operation_id: RefCell>, workspace_id: RefCell>, - commit_id: RefCell>, tree_state: RefCell>, } impl WorkingCopy { /// Initializes a new working copy at `working_copy_path`. The working - /// copy's state will be stored in the `state_path` directory. The - /// working copy will be recorded as being already checked out at commit - /// pointed to by `commit_id`; this function doesn't update the working - /// copy file to that commit. + /// copy's state will be stored in the `state_path` directory. The working + /// copy will have the empty tree checked out. pub fn init( store: Arc, working_copy_path: PathBuf, state_path: PathBuf, operation_id: OperationId, workspace_id: WorkspaceId, - commit_id: CommitId, + _commit_id: CommitId, ) -> WorkingCopy { let mut proto = crate::protos::working_copy::Checkout::new(); proto.operation_id = operation_id.to_bytes(); proto.workspace_id = workspace_id.as_str().to_string(); - proto.commit_id = commit_id.to_bytes(); let mut file = OpenOptions::new() .create_new(true) .write(true) @@ -753,7 +749,6 @@ impl WorkingCopy { state_path, operation_id: RefCell::new(Some(operation_id)), workspace_id: RefCell::new(Some(workspace_id)), - commit_id: RefCell::new(Some(commit_id)), tree_state: RefCell::new(None), } } @@ -765,7 +760,6 @@ impl WorkingCopy { state_path, operation_id: RefCell::new(None), workspace_id: RefCell::new(None), - commit_id: RefCell::new(None), tree_state: RefCell::new(None), } } @@ -796,7 +790,6 @@ impl WorkingCopy { WorkspaceId::new(proto.workspace_id) }; self.workspace_id.replace(Some(workspace_id)); - self.commit_id.replace(Some(CommitId::new(proto.commit_id))); } pub fn operation_id(&self) -> OperationId { @@ -815,18 +808,6 @@ impl WorkingCopy { self.workspace_id.borrow().as_ref().unwrap().clone() } - /// The id of the commit that's currently checked out in the working copy. - /// Note that the View is the source of truth for which commit *should* - /// be checked out. That should be kept up to date within a Transaction. - /// The WorkingCopy is only updated at the end. - pub fn current_commit_id(&self) -> CommitId { - if self.commit_id.borrow().is_none() { - self.load_proto(); - } - - self.commit_id.borrow().as_ref().unwrap().clone() - } - fn tree_state(&self) -> RefMut> { if self.tree_state.borrow().is_none() { self.tree_state.replace(Some(TreeState::load( @@ -854,7 +835,6 @@ impl WorkingCopy { let mut proto = crate::protos::working_copy::Checkout::new(); proto.operation_id = self.operation_id().to_bytes(); proto.workspace_id = self.workspace_id().as_str().to_string(); - proto.commit_id = self.current_commit_id().to_bytes(); self.write_proto(proto); } @@ -944,10 +924,9 @@ impl LockedWorkingCopy<'_> { self.wc.tree_state().as_mut().unwrap().reset(new_tree) } - pub fn finish(mut self, operation_id: OperationId, commit_id: CommitId) { + pub fn finish(mut self, operation_id: OperationId, _commit_id: CommitId) { self.wc.tree_state().as_mut().unwrap().save(); self.wc.operation_id.replace(Some(operation_id)); - self.wc.commit_id.replace(Some(commit_id)); self.wc.save(); // TODO: Clear the "pending_checkout" file here. self.closed = true;