forked from mirrors/jj
working_copy: keep track of workspace ID (#13)
This patch makes it so the workspace ID can be stored in `.jj/working_copy/checkout`. The workspace ID is still always "default".
This commit is contained in:
parent
0098edd3d2
commit
fb8fbdc4b3
3 changed files with 35 additions and 2 deletions
|
@ -37,6 +37,11 @@ message TreeState {
|
|||
message Checkout {
|
||||
// The operation at which the working copy was updated.
|
||||
bytes operation_id = 2;
|
||||
// An identifier for this workspace. It is used for looking up the current
|
||||
// checkout in the repo view. Currently a human-readable name.
|
||||
// TODO: Is it better to make this a UUID and a have map that to a name in
|
||||
// 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.
|
||||
bytes commit_id = 1;
|
||||
|
|
|
@ -39,7 +39,7 @@ use crate::conflicts::{materialize_conflict, update_conflict_from_content};
|
|||
use crate::gitignore::GitIgnoreFile;
|
||||
use crate::lock::FileLock;
|
||||
use crate::matchers::EverythingMatcher;
|
||||
use crate::op_store::OperationId;
|
||||
use crate::op_store::{OperationId, WorkspaceId};
|
||||
use crate::repo_path::{RepoPath, RepoPathComponent, RepoPathJoin};
|
||||
use crate::store::Store;
|
||||
use crate::tree::{Diff, Tree};
|
||||
|
@ -719,6 +719,7 @@ pub struct WorkingCopy {
|
|||
working_copy_path: PathBuf,
|
||||
state_path: PathBuf,
|
||||
operation_id: RefCell<Option<OperationId>>,
|
||||
workspace_id: RefCell<Option<WorkspaceId>>,
|
||||
commit_id: RefCell<Option<CommitId>>,
|
||||
tree_state: RefCell<Option<TreeState>>,
|
||||
}
|
||||
|
@ -734,6 +735,7 @@ impl WorkingCopy {
|
|||
working_copy_path: PathBuf,
|
||||
state_path: PathBuf,
|
||||
operation_id: OperationId,
|
||||
workspace_id: WorkspaceId,
|
||||
commit_id: CommitId,
|
||||
) -> WorkingCopy {
|
||||
let mut proto = crate::protos::working_copy::Checkout::new();
|
||||
|
@ -748,8 +750,9 @@ impl WorkingCopy {
|
|||
store,
|
||||
working_copy_path,
|
||||
state_path,
|
||||
commit_id: RefCell::new(Some(commit_id)),
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
@ -760,6 +763,7 @@ impl WorkingCopy {
|
|||
working_copy_path,
|
||||
state_path,
|
||||
operation_id: RefCell::new(None),
|
||||
workspace_id: RefCell::new(None),
|
||||
commit_id: RefCell::new(None),
|
||||
tree_state: RefCell::new(None),
|
||||
}
|
||||
|
@ -779,6 +783,14 @@ impl WorkingCopy {
|
|||
Message::parse_from_reader(&mut file).unwrap();
|
||||
self.operation_id
|
||||
.replace(Some(OperationId::new(proto.operation_id)));
|
||||
let workspace_id = if proto.workspace_id.is_empty() {
|
||||
// For compatibility with old working copies.
|
||||
// TODO: Delete in mid 2022 or so
|
||||
WorkspaceId::default()
|
||||
} else {
|
||||
WorkspaceId::new(proto.workspace_id)
|
||||
};
|
||||
self.workspace_id.replace(Some(workspace_id));
|
||||
self.commit_id.replace(Some(CommitId::new(proto.commit_id)));
|
||||
}
|
||||
|
||||
|
@ -790,6 +802,14 @@ impl WorkingCopy {
|
|||
self.operation_id.borrow().as_ref().unwrap().clone()
|
||||
}
|
||||
|
||||
pub fn workspace_id(&self) -> WorkspaceId {
|
||||
if self.workspace_id.borrow().is_none() {
|
||||
self.load_proto();
|
||||
}
|
||||
|
||||
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.
|
||||
|
@ -828,6 +848,7 @@ impl WorkingCopy {
|
|||
fn save(&mut self) {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ use std::sync::Arc;
|
|||
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::op_store::WorkspaceId;
|
||||
use crate::repo::{ReadonlyRepo, RepoLoader};
|
||||
use crate::settings::UserSettings;
|
||||
use crate::working_copy::WorkingCopy;
|
||||
|
@ -60,11 +61,13 @@ fn init_working_copy(
|
|||
) -> WorkingCopy {
|
||||
let working_copy_state_path = jj_dir.join("working_copy");
|
||||
std::fs::create_dir(&working_copy_state_path).unwrap();
|
||||
let workspace_id = WorkspaceId::default();
|
||||
WorkingCopy::init(
|
||||
repo.store().clone(),
|
||||
workspace_root.to_path_buf(),
|
||||
working_copy_state_path,
|
||||
repo.op_id().clone(),
|
||||
workspace_id,
|
||||
repo.view().checkout().clone(),
|
||||
)
|
||||
}
|
||||
|
@ -159,6 +162,10 @@ impl Workspace {
|
|||
&self.workspace_root
|
||||
}
|
||||
|
||||
pub fn workspace_id(&self) -> WorkspaceId {
|
||||
self.working_copy.workspace_id()
|
||||
}
|
||||
|
||||
pub fn repo_path(&self) -> &PathBuf {
|
||||
self.repo_loader.repo_path()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue