mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-05 23:42:50 +00:00
view: replace WorkspaceId by string-like newtypes
I think this makes more sense because WorkspaceId is currently a human-readable name. In error/status messages, workspace names are now printed in revset syntax. New WorkspaceId types do not implement Default. It would be weird if string-like type had non-empty Default::default(). The DEFAULT constant is provided instead.
This commit is contained in:
parent
a08d53bef8
commit
e66c545438
@ -28,7 +28,8 @@ use jj_lib::commit::Commit;
|
||||
use jj_lib::git_backend::GitBackend;
|
||||
use jj_lib::local_working_copy::LocalWorkingCopy;
|
||||
use jj_lib::op_store::OperationId;
|
||||
use jj_lib::op_store::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::repo::ReadonlyRepo;
|
||||
use jj_lib::repo_path::RepoPathBuf;
|
||||
use jj_lib::settings::UserSettings;
|
||||
@ -79,7 +80,7 @@ fn run_custom_command(
|
||||
&ReadonlyRepo::default_index_store_initializer(),
|
||||
&ReadonlyRepo::default_submodule_store_initializer(),
|
||||
&ConflictsWorkingCopyFactory {},
|
||||
WorkspaceId::default(),
|
||||
WorkspaceId::DEFAULT.to_owned(),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
@ -120,7 +121,7 @@ impl ConflictsWorkingCopy {
|
||||
working_copy_path: PathBuf,
|
||||
state_path: PathBuf,
|
||||
operation_id: OperationId,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
) -> Result<Self, WorkingCopyStateError> {
|
||||
let inner = LocalWorkingCopy::init(
|
||||
store,
|
||||
@ -187,7 +188,7 @@ impl WorkingCopyFactory for ConflictsWorkingCopyFactory {
|
||||
working_copy_path: PathBuf,
|
||||
state_path: PathBuf,
|
||||
operation_id: OperationId,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
) -> Result<Box<dyn WorkingCopy>, WorkingCopyStateError> {
|
||||
Ok(Box::new(ConflictsWorkingCopy::init(
|
||||
store,
|
||||
@ -263,7 +264,7 @@ impl LockedWorkingCopy for LockedConflictsWorkingCopy {
|
||||
self.inner.check_out(commit, options)
|
||||
}
|
||||
|
||||
fn rename_workspace(&mut self, new_workspace_id: WorkspaceId) {
|
||||
fn rename_workspace(&mut self, new_workspace_id: WorkspaceIdBuf) {
|
||||
self.inner.rename_workspace(new_workspace_id);
|
||||
}
|
||||
|
||||
|
@ -79,12 +79,13 @@ use jj_lib::op_heads_store;
|
||||
use jj_lib::op_store::OpStoreError;
|
||||
use jj_lib::op_store::OperationId;
|
||||
use jj_lib::op_store::RefTarget;
|
||||
use jj_lib::op_store::WorkspaceId;
|
||||
use jj_lib::op_walk;
|
||||
use jj_lib::op_walk::OpsetEvaluationError;
|
||||
use jj_lib::operation::Operation;
|
||||
use jj_lib::ref_name::RefName;
|
||||
use jj_lib::ref_name::RefNameBuf;
|
||||
use jj_lib::ref_name::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::repo::merge_factories_map;
|
||||
use jj_lib::repo::CheckOutCommitError;
|
||||
use jj_lib::repo::EditCommitError;
|
||||
@ -783,7 +784,7 @@ pub struct WorkspaceCommandEnvironment {
|
||||
revset_aliases_map: RevsetAliasesMap,
|
||||
template_aliases_map: TemplateAliasesMap,
|
||||
path_converter: RepoPathUiConverter,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
immutable_heads_expression: Rc<UserRevsetExpression>,
|
||||
short_prefixes_expression: Option<Rc<UserRevsetExpression>>,
|
||||
conflict_marker_style: ConflictMarkerStyle,
|
||||
@ -1288,7 +1289,7 @@ impl WorkspaceCommandHelper {
|
||||
) -> Result<SnapshotStats, CommandError> {
|
||||
self.check_working_copy_writable()?;
|
||||
|
||||
let workspace_id = self.workspace_id().clone();
|
||||
let workspace_id = self.workspace_id().to_owned();
|
||||
let mut locked_ws = self.workspace.start_working_copy_mutation()?;
|
||||
let (repo, new_commit) = working_copy::create_and_check_out_recovery_commit(
|
||||
locked_ws.locked_wc(),
|
||||
@ -2103,7 +2104,7 @@ See https://jj-vcs.github.io/jj/latest/working-copy/#stale-working-copy \
|
||||
ui.warning_default(),
|
||||
"The working-copy commit in workspace '{}' became immutable, so a new commit \
|
||||
has been created on top of it.",
|
||||
workspace_id.as_str()
|
||||
workspace_id.as_symbol()
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
@ -832,7 +832,7 @@ fn find_bookmarks_targeted_by_revisions<'a>(
|
||||
StringPattern::exact(remote),
|
||||
None,
|
||||
)
|
||||
.range(&RevsetExpression::working_copy(workspace_id.clone()))
|
||||
.range(&RevsetExpression::working_copy(workspace_id.to_owned()))
|
||||
.intersection(&RevsetExpression::bookmarks(StringPattern::everything()));
|
||||
let mut commit_ids = workspace_command
|
||||
.attach_revset_evaluator(expression)
|
||||
|
@ -290,7 +290,7 @@ pub fn show_op_diff(
|
||||
// Usually, there is at most one working copy changed per operation, so we put
|
||||
// the working copy name in the heading.
|
||||
write!(formatter, "Changed working copy ")?;
|
||||
write!(formatter.labeled("working_copies"), "{}@", name.as_str())?;
|
||||
write!(formatter.labeled("working_copies"), "{}@", name.as_symbol())?;
|
||||
writeln!(formatter, ":")?;
|
||||
write_ref_target_summary(
|
||||
formatter,
|
||||
|
@ -18,7 +18,7 @@ use itertools::Itertools as _;
|
||||
use jj_lib::commit::CommitIteratorExt as _;
|
||||
use jj_lib::file_util;
|
||||
use jj_lib::file_util::IoResultExt as _;
|
||||
use jj_lib::op_store::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::repo::Repo as _;
|
||||
use jj_lib::rewrite::merge_commit_trees;
|
||||
use jj_lib::workspace::Workspace;
|
||||
@ -55,7 +55,7 @@ pub struct WorkspaceAddArgs {
|
||||
/// To override the default, which is the basename of the destination
|
||||
/// directory.
|
||||
#[arg(long)]
|
||||
name: Option<String>,
|
||||
name: Option<WorkspaceIdBuf>,
|
||||
/// A list of parent revisions for the working-copy commit of the newly
|
||||
/// created workspace. You may specify nothing, or any number of parents.
|
||||
///
|
||||
@ -88,20 +88,20 @@ pub fn cmd_workspace_add(
|
||||
} else {
|
||||
fs::create_dir(&destination_path).context(&destination_path)?;
|
||||
}
|
||||
let name = if let Some(name) = &args.name {
|
||||
name.to_string()
|
||||
let workspace_id = if let Some(name) = &args.name {
|
||||
name.to_owned()
|
||||
} else {
|
||||
let file_name = destination_path.file_name().unwrap();
|
||||
file_name
|
||||
.to_str()
|
||||
.ok_or_else(|| user_error("Destination path is not valid UTF-8"))?
|
||||
.to_string()
|
||||
.into()
|
||||
};
|
||||
let workspace_id = WorkspaceId::new(name.clone());
|
||||
let repo = old_workspace_command.repo();
|
||||
if repo.view().get_wc_commit_id(&workspace_id).is_some() {
|
||||
return Err(user_error(format!(
|
||||
"Workspace named '{name}' already exists"
|
||||
"Workspace named '{name}' already exists",
|
||||
name = workspace_id.as_symbol()
|
||||
)));
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ pub fn cmd_workspace_add(
|
||||
repo_path,
|
||||
repo,
|
||||
working_copy_factory,
|
||||
workspace_id,
|
||||
workspace_id.clone(),
|
||||
)?;
|
||||
writeln!(
|
||||
ui.status(),
|
||||
@ -127,7 +127,8 @@ pub fn cmd_workspace_add(
|
||||
writeln!(
|
||||
ui.warning_default(),
|
||||
r#"Workspace created inside current directory. If this was unintentional, delete the "{}" directory and run `jj workspace forget {name}` to remove it."#,
|
||||
args.destination
|
||||
args.destination,
|
||||
name = workspace_id.as_symbol()
|
||||
)?;
|
||||
}
|
||||
|
||||
@ -191,7 +192,10 @@ pub fn cmd_workspace_add(
|
||||
tx.edit(&new_wc_commit)?;
|
||||
tx.finish(
|
||||
ui,
|
||||
format!("create initial working-copy commit in workspace {name}"),
|
||||
format!(
|
||||
"create initial working-copy commit in workspace {name}",
|
||||
name = workspace_id.as_symbol()
|
||||
),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
use clap_complete::ArgValueCandidates;
|
||||
use itertools::Itertools as _;
|
||||
use jj_lib::op_store::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use tracing::instrument;
|
||||
|
||||
use crate::cli_util::CommandHelper;
|
||||
@ -32,7 +32,7 @@ pub struct WorkspaceForgetArgs {
|
||||
/// Names of the workspaces to forget. By default, forgets only the current
|
||||
/// workspace.
|
||||
#[arg(add = ArgValueCandidates::new(complete::workspaces))]
|
||||
workspaces: Vec<String>,
|
||||
workspaces: Vec<WorkspaceIdBuf>,
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
@ -43,13 +43,10 @@ pub fn cmd_workspace_forget(
|
||||
) -> Result<(), CommandError> {
|
||||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
|
||||
let wss: Vec<WorkspaceId> = if args.workspaces.is_empty() {
|
||||
vec![workspace_command.workspace_id().clone()]
|
||||
let wss = if args.workspaces.is_empty() {
|
||||
vec![workspace_command.workspace_id().to_owned()]
|
||||
} else {
|
||||
args.workspaces
|
||||
.iter()
|
||||
.map(|ws| WorkspaceId::new(ws.to_string()))
|
||||
.collect()
|
||||
args.workspaces.clone()
|
||||
};
|
||||
|
||||
for ws in &wss {
|
||||
@ -59,7 +56,7 @@ pub fn cmd_workspace_forget(
|
||||
.get_wc_commit_id(ws)
|
||||
.is_none()
|
||||
{
|
||||
return Err(user_error(format!("No such workspace: {}", ws.as_str())));
|
||||
return Err(user_error(format!("No such workspace: {}", ws.as_symbol())));
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,11 +66,11 @@ pub fn cmd_workspace_forget(
|
||||
wss.iter()
|
||||
.try_for_each(|ws| tx.repo_mut().remove_wc_commit(ws))?;
|
||||
let description = if let [ws] = wss.as_slice() {
|
||||
format!("forget workspace {}", ws.as_str())
|
||||
format!("forget workspace {}", ws.as_symbol())
|
||||
} else {
|
||||
format!(
|
||||
"forget workspaces {}",
|
||||
wss.iter().map(|ws| ws.as_str()).join(", ")
|
||||
wss.iter().map(|ws| ws.as_symbol()).join(", ")
|
||||
)
|
||||
};
|
||||
|
||||
|
@ -34,7 +34,7 @@ pub fn cmd_workspace_list(
|
||||
let mut formatter = ui.stdout_formatter();
|
||||
let template = workspace_command.commit_summary_template();
|
||||
for (workspace_id, wc_commit_id) in repo.view().wc_commit_ids() {
|
||||
write!(formatter, "{}: ", workspace_id.as_str())?;
|
||||
write!(formatter, "{}: ", workspace_id.as_symbol())?;
|
||||
let commit = repo.store().get_commit(wc_commit_id)?;
|
||||
template.format(&commit, formatter.as_mut())?;
|
||||
writeln!(formatter)?;
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use jj_lib::op_store::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use tracing::instrument;
|
||||
|
||||
use crate::cli_util::CommandHelper;
|
||||
@ -24,7 +24,7 @@ use crate::ui::Ui;
|
||||
#[derive(clap::Args, Clone, Debug)]
|
||||
pub struct WorkspaceRenameArgs {
|
||||
/// The name of the workspace to update to.
|
||||
new_workspace_name: String,
|
||||
new_workspace_name: WorkspaceIdBuf,
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
@ -33,14 +33,14 @@ pub fn cmd_workspace_rename(
|
||||
command: &CommandHelper,
|
||||
args: &WorkspaceRenameArgs,
|
||||
) -> Result<(), CommandError> {
|
||||
if args.new_workspace_name.is_empty() {
|
||||
if args.new_workspace_name.as_str().is_empty() {
|
||||
return Err(user_error("New workspace name cannot be empty"));
|
||||
}
|
||||
|
||||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
|
||||
let old_workspace_id = workspace_command.working_copy().workspace_id().clone();
|
||||
let new_workspace_id = WorkspaceId::new(args.new_workspace_name.clone());
|
||||
let old_workspace_id = workspace_command.working_copy().workspace_id().to_owned();
|
||||
let new_workspace_id = &*args.new_workspace_name;
|
||||
if new_workspace_id == old_workspace_id {
|
||||
writeln!(ui.status(), "Nothing changed.")?;
|
||||
return Ok(());
|
||||
@ -54,7 +54,7 @@ pub fn cmd_workspace_rename(
|
||||
{
|
||||
return Err(user_error(format!(
|
||||
"The current workspace '{}' is not tracked in the repo.",
|
||||
old_workspace_id.as_str()
|
||||
old_workspace_id.as_symbol()
|
||||
)));
|
||||
}
|
||||
|
||||
@ -63,14 +63,14 @@ pub fn cmd_workspace_rename(
|
||||
|
||||
locked_ws
|
||||
.locked_wc()
|
||||
.rename_workspace(new_workspace_id.clone());
|
||||
.rename_workspace(new_workspace_id.to_owned());
|
||||
|
||||
tx.repo_mut()
|
||||
.rename_workspace(&old_workspace_id, new_workspace_id)?;
|
||||
.rename_workspace(&old_workspace_id, new_workspace_id.to_owned())?;
|
||||
let repo = tx.commit(format!(
|
||||
"Renamed workspace '{}' to '{}'",
|
||||
old_workspace_id.as_str(),
|
||||
args.new_workspace_name
|
||||
"Renamed workspace '{old}' to '{new}'",
|
||||
old = old_workspace_id.as_symbol(),
|
||||
new = new_workspace_id.as_symbol()
|
||||
))?;
|
||||
locked_ws.finish(repo.op_id().clone())?;
|
||||
|
||||
|
@ -45,7 +45,8 @@ use jj_lib::merged_tree::MergedTree;
|
||||
use jj_lib::object_id::ObjectId as _;
|
||||
use jj_lib::op_store::RefTarget;
|
||||
use jj_lib::op_store::RemoteRef;
|
||||
use jj_lib::op_store::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::repo::Repo;
|
||||
use jj_lib::repo_path::RepoPathBuf;
|
||||
use jj_lib::repo_path::RepoPathUiConverter;
|
||||
@ -102,7 +103,7 @@ pub trait CommitTemplateLanguageExtension {
|
||||
pub struct CommitTemplateLanguage<'repo> {
|
||||
repo: &'repo dyn Repo,
|
||||
path_converter: &'repo RepoPathUiConverter,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
// RevsetParseContext doesn't borrow a repo, but we'll need 'repo lifetime
|
||||
// anyway to capture it to evaluate dynamically-constructed user expression
|
||||
// such as `revset("ancestors(" ++ commit_id ++ ")")`.
|
||||
@ -144,7 +145,7 @@ impl<'repo> CommitTemplateLanguage<'repo> {
|
||||
CommitTemplateLanguage {
|
||||
repo,
|
||||
path_converter,
|
||||
workspace_id: workspace_id.clone(),
|
||||
workspace_id: workspace_id.to_owned(),
|
||||
revset_parse_context,
|
||||
id_prefix_context,
|
||||
immutable_expression,
|
||||
@ -1069,7 +1070,7 @@ fn extract_working_copies(repo: &dyn Repo, commit: &Commit) -> String {
|
||||
let mut names = vec![];
|
||||
for (workspace_id, wc_commit_id) in wc_commit_ids {
|
||||
if wc_commit_id == commit.id() {
|
||||
names.push(format!("{}@", workspace_id.as_str()));
|
||||
names.push(format!("{}@", workspace_id.as_symbol()));
|
||||
}
|
||||
}
|
||||
names.join(" ")
|
||||
|
@ -269,7 +269,7 @@ change very frequently.
|
||||
|
||||
```rust
|
||||
// Before:
|
||||
pub wc_commit_ids: HashMap<WorkspaceId, CommitId>,
|
||||
pub wc_commit_ids: HashMap<WorkspaceIdBuf, CommitId>,
|
||||
|
||||
// After:
|
||||
pub struct WorkingCopyInfo {
|
||||
@ -277,7 +277,7 @@ pub struct WorkingCopyInfo {
|
||||
pub wc_patterns_id: WorkingCopyPatternsId,
|
||||
}
|
||||
...
|
||||
pub wc_info: HashMap<WorkspaceId, WorkingCopyInfo>,
|
||||
pub wc_info: HashMap<WorkspaceIdBuf, WorkingCopyInfo>,
|
||||
```
|
||||
|
||||
A View object with no stored working copy patterns will be modified at read
|
||||
|
@ -95,7 +95,8 @@ use crate::merged_tree::MergedTreeBuilder;
|
||||
use crate::merged_tree::TreeDiffEntry;
|
||||
use crate::object_id::ObjectId as _;
|
||||
use crate::op_store::OperationId;
|
||||
use crate::op_store::WorkspaceId;
|
||||
use crate::ref_name::WorkspaceId;
|
||||
use crate::ref_name::WorkspaceIdBuf;
|
||||
use crate::repo_path::RepoPath;
|
||||
use crate::repo_path::RepoPathBuf;
|
||||
use crate::repo_path::RepoPathComponent;
|
||||
@ -1959,7 +1960,7 @@ fn checkout_error_for_stat_error(err: io::Error, path: &Path) -> CheckoutError {
|
||||
#[derive(Clone, Debug)]
|
||||
struct CheckoutState {
|
||||
operation_id: OperationId,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
}
|
||||
|
||||
pub struct LocalWorkingCopy {
|
||||
@ -2038,11 +2039,11 @@ impl LocalWorkingCopy {
|
||||
working_copy_path: PathBuf,
|
||||
state_path: PathBuf,
|
||||
operation_id: OperationId,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
) -> Result<LocalWorkingCopy, WorkingCopyStateError> {
|
||||
let proto = crate::protos::working_copy::Checkout {
|
||||
operation_id: operation_id.to_bytes(),
|
||||
workspace_id: workspace_id.as_str().to_string(),
|
||||
workspace_id: workspace_id.into(),
|
||||
};
|
||||
let mut file = OpenOptions::new()
|
||||
.create_new(true)
|
||||
@ -2104,9 +2105,9 @@ impl LocalWorkingCopy {
|
||||
workspace_id: if proto.workspace_id.is_empty() {
|
||||
// For compatibility with old working copies.
|
||||
// TODO: Delete in mid 2022 or so
|
||||
WorkspaceId::default()
|
||||
WorkspaceId::DEFAULT.to_owned()
|
||||
} else {
|
||||
WorkspaceId::new(proto.workspace_id)
|
||||
proto.workspace_id.into()
|
||||
},
|
||||
}
|
||||
})
|
||||
@ -2146,7 +2147,7 @@ impl LocalWorkingCopy {
|
||||
fn save(&mut self) {
|
||||
self.write_proto(crate::protos::working_copy::Checkout {
|
||||
operation_id: self.operation_id().to_bytes(),
|
||||
workspace_id: self.workspace_id().as_str().to_string(),
|
||||
workspace_id: self.workspace_id().into(),
|
||||
});
|
||||
}
|
||||
|
||||
@ -2186,7 +2187,7 @@ impl WorkingCopyFactory for LocalWorkingCopyFactory {
|
||||
working_copy_path: PathBuf,
|
||||
state_path: PathBuf,
|
||||
operation_id: OperationId,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
) -> Result<Box<dyn WorkingCopy>, WorkingCopyStateError> {
|
||||
Ok(Box::new(LocalWorkingCopy::init(
|
||||
store,
|
||||
@ -2220,7 +2221,7 @@ pub struct LockedLocalWorkingCopy {
|
||||
old_operation_id: OperationId,
|
||||
old_tree_id: MergedTreeId,
|
||||
tree_state_dirty: bool,
|
||||
new_workspace_id: Option<WorkspaceId>,
|
||||
new_workspace_id: Option<WorkspaceIdBuf>,
|
||||
}
|
||||
|
||||
impl LockedWorkingCopy for LockedLocalWorkingCopy {
|
||||
@ -2280,7 +2281,7 @@ impl LockedWorkingCopy for LockedLocalWorkingCopy {
|
||||
}
|
||||
}
|
||||
|
||||
fn rename_workspace(&mut self, new_workspace_id: WorkspaceId) {
|
||||
fn rename_workspace(&mut self, new_workspace_id: WorkspaceIdBuf) {
|
||||
self.new_workspace_id = Some(new_workspace_id);
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,6 @@ use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt::Debug;
|
||||
use std::fmt::Error;
|
||||
use std::fmt::Formatter;
|
||||
use std::iter;
|
||||
use std::time::SystemTime;
|
||||
|
||||
@ -43,31 +41,7 @@ use crate::ref_name::RefNameBuf;
|
||||
use crate::ref_name::RemoteName;
|
||||
use crate::ref_name::RemoteNameBuf;
|
||||
use crate::ref_name::RemoteRefSymbol;
|
||||
|
||||
#[derive(ContentHash, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
|
||||
pub struct WorkspaceId(String);
|
||||
|
||||
impl Debug for WorkspaceId {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
|
||||
f.debug_tuple("WorkspaceId").field(&self.0).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for WorkspaceId {
|
||||
fn default() -> Self {
|
||||
Self("default".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl WorkspaceId {
|
||||
pub fn new(value: String) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
use crate::ref_name::WorkspaceIdBuf;
|
||||
|
||||
id_type!(pub ViewId { hex() });
|
||||
id_type!(pub OperationId { hex() });
|
||||
@ -285,7 +259,7 @@ pub struct View {
|
||||
// The commit that *should be* checked out in the workspace. Note that the working copy
|
||||
// (.jj/working_copy/) has the source of truth about which commit *is* checked out (to be
|
||||
// precise: the commit to which we most recently completed an update to).
|
||||
pub wc_commit_ids: BTreeMap<WorkspaceId, CommitId>,
|
||||
pub wc_commit_ids: BTreeMap<WorkspaceIdBuf, CommitId>,
|
||||
}
|
||||
|
||||
impl View {
|
||||
|
@ -90,6 +90,22 @@ pub struct RemoteNameBuf(String);
|
||||
#[repr(transparent)]
|
||||
pub struct RemoteName(str);
|
||||
|
||||
/// Owned workspace name.
|
||||
///
|
||||
/// Use `.as_str()` or `.as_symbol()` for displaying. Other than that, this can
|
||||
/// be considered an immutable `String`.
|
||||
// Eq, Hash, and Ord must be compatible with WorkspaceId.
|
||||
#[derive(Clone, ContentHash, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
pub struct WorkspaceIdBuf(String); // TODO: rename to WorkspaceNameBuf
|
||||
|
||||
/// Borrowed workspace name.
|
||||
///
|
||||
/// Use `.as_str()` or `.as_symbol()` for displaying. Other than that, this can
|
||||
/// be considered an immutable `str`.
|
||||
#[derive(ContentHash, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, RefCastCustom)]
|
||||
#[repr(transparent)]
|
||||
pub struct WorkspaceId(str); // TODO: rename to WorkspaceName
|
||||
|
||||
macro_rules! impl_partial_eq {
|
||||
($borrowed_ty:ty, $lhs:ty, $rhs:ty) => {
|
||||
impl PartialEq<$rhs> for $lhs {
|
||||
@ -284,6 +300,7 @@ impl_name_type!(GitRefNameBuf, GitRefName);
|
||||
// repo/view API surface, but we'll need generic RemoteRefSymbol type, etc.
|
||||
impl_name_type!(RefNameBuf, RefName);
|
||||
impl_name_type!(RemoteNameBuf, RemoteName);
|
||||
impl_name_type!(WorkspaceIdBuf, WorkspaceId);
|
||||
|
||||
impl RefName {
|
||||
/// Constructs a remote symbol with this local name.
|
||||
@ -292,6 +309,11 @@ impl RefName {
|
||||
}
|
||||
}
|
||||
|
||||
impl WorkspaceId {
|
||||
/// Default workspace name.
|
||||
pub const DEFAULT: &WorkspaceId = WorkspaceId::new("default");
|
||||
}
|
||||
|
||||
/// Symbol for displaying.
|
||||
///
|
||||
/// This type can be displayed with quoting and escaping if necessary.
|
||||
|
@ -71,12 +71,13 @@ use crate::op_store::RefTarget;
|
||||
use crate::op_store::RemoteRef;
|
||||
use crate::op_store::RemoteRefState;
|
||||
use crate::op_store::RootOperationData;
|
||||
use crate::op_store::WorkspaceId;
|
||||
use crate::operation::Operation;
|
||||
use crate::ref_name::GitRefName;
|
||||
use crate::ref_name::RefName;
|
||||
use crate::ref_name::RemoteName;
|
||||
use crate::ref_name::RemoteRefSymbol;
|
||||
use crate::ref_name::WorkspaceId;
|
||||
use crate::ref_name::WorkspaceIdBuf;
|
||||
use crate::refs::diff_named_ref_targets;
|
||||
use crate::refs::diff_named_remote_refs;
|
||||
use crate::refs::merge_ref_targets;
|
||||
@ -1352,7 +1353,7 @@ impl MutableRepo {
|
||||
|
||||
pub fn set_wc_commit(
|
||||
&mut self,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
commit_id: CommitId,
|
||||
) -> Result<(), RewriteRootCommit> {
|
||||
if &commit_id == self.store().root_commit_id() {
|
||||
@ -1371,7 +1372,7 @@ impl MutableRepo {
|
||||
pub fn rename_workspace(
|
||||
&mut self,
|
||||
old_workspace_id: &WorkspaceId,
|
||||
new_workspace_id: WorkspaceId,
|
||||
new_workspace_id: WorkspaceIdBuf,
|
||||
) -> Result<(), RenameWorkspaceError> {
|
||||
self.view_mut()
|
||||
.rename_workspace(old_workspace_id, new_workspace_id)
|
||||
@ -1379,7 +1380,7 @@ impl MutableRepo {
|
||||
|
||||
pub fn check_out(
|
||||
&mut self,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
commit: &Commit,
|
||||
) -> Result<Commit, CheckOutCommitError> {
|
||||
let wc_commit = self
|
||||
@ -1391,7 +1392,7 @@ impl MutableRepo {
|
||||
|
||||
pub fn edit(
|
||||
&mut self,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
commit: &Commit,
|
||||
) -> Result<(), EditCommitError> {
|
||||
self.maybe_abandon_wc_commit(&workspace_id)?;
|
||||
|
@ -44,10 +44,11 @@ use crate::id_prefix::IdPrefixIndex;
|
||||
use crate::object_id::HexPrefix;
|
||||
use crate::object_id::PrefixResolution;
|
||||
use crate::op_store::RemoteRefState;
|
||||
use crate::op_store::WorkspaceId;
|
||||
use crate::op_walk;
|
||||
use crate::ref_name::RemoteRefSymbol;
|
||||
use crate::ref_name::RemoteRefSymbolBuf;
|
||||
use crate::ref_name::WorkspaceId;
|
||||
use crate::ref_name::WorkspaceIdBuf;
|
||||
use crate::repo::ReadonlyRepo;
|
||||
use crate::repo::Repo;
|
||||
use crate::repo::RepoLoaderError;
|
||||
@ -78,8 +79,8 @@ pub enum RevsetResolutionError {
|
||||
name: String,
|
||||
candidates: Vec<String>,
|
||||
},
|
||||
#[error("Workspace `{name}` doesn't have a working-copy commit")]
|
||||
WorkspaceMissingWorkingCopy { name: String },
|
||||
#[error("Workspace `{}` doesn't have a working-copy commit", name.as_symbol())]
|
||||
WorkspaceMissingWorkingCopy { name: WorkspaceIdBuf },
|
||||
#[error("An empty string is not a valid revision")]
|
||||
EmptyString,
|
||||
#[error("Commit ID prefix `{0}` is ambiguous")]
|
||||
@ -128,7 +129,7 @@ pub enum RevsetModifier {
|
||||
/// Symbol or function to be resolved to `CommitId`s.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum RevsetCommitRef {
|
||||
WorkingCopy(WorkspaceId),
|
||||
WorkingCopy(WorkspaceIdBuf),
|
||||
WorkingCopies,
|
||||
Symbol(String),
|
||||
RemoteSymbol(RemoteRefSymbolBuf),
|
||||
@ -322,7 +323,7 @@ impl<St: ExpressionState> RevsetExpression<St> {
|
||||
|
||||
// Leaf expression that represents unresolved commit refs
|
||||
impl<St: ExpressionState<CommitRef = RevsetCommitRef>> RevsetExpression<St> {
|
||||
pub fn working_copy(workspace_id: WorkspaceId) -> Rc<Self> {
|
||||
pub fn working_copy(workspace_id: WorkspaceIdBuf) -> Rc<Self> {
|
||||
Rc::new(Self::CommitRef(RevsetCommitRef::WorkingCopy(workspace_id)))
|
||||
}
|
||||
|
||||
@ -1052,9 +1053,7 @@ pub fn lower_expression(
|
||||
node.span,
|
||||
)),
|
||||
ExpressionKind::RemoteSymbol(symbol) => Ok(RevsetExpression::remote_symbol(symbol.clone())),
|
||||
ExpressionKind::AtWorkspace(name) => Ok(RevsetExpression::working_copy(WorkspaceId::new(
|
||||
name.to_owned(),
|
||||
))),
|
||||
ExpressionKind::AtWorkspace(name) => Ok(RevsetExpression::working_copy(name.into())),
|
||||
ExpressionKind::AtCurrentWorkspace => {
|
||||
let ctx = context.workspace.as_ref().ok_or_else(|| {
|
||||
RevsetParseError::with_span(
|
||||
@ -1062,7 +1061,7 @@ pub fn lower_expression(
|
||||
node.span,
|
||||
)
|
||||
})?;
|
||||
Ok(RevsetExpression::working_copy(ctx.workspace_id.clone()))
|
||||
Ok(RevsetExpression::working_copy(ctx.workspace_id.to_owned()))
|
||||
}
|
||||
ExpressionKind::DagRangeAll => Ok(RevsetExpression::all()),
|
||||
ExpressionKind::RangeAll => {
|
||||
@ -2100,7 +2099,7 @@ fn resolve_commit_ref(
|
||||
Ok(vec![commit_id.clone()])
|
||||
} else {
|
||||
Err(RevsetResolutionError::WorkspaceMissingWorkingCopy {
|
||||
name: workspace_id.as_str().to_string(),
|
||||
name: workspace_id.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -2763,31 +2762,31 @@ mod tests {
|
||||
fn test_revset_expression_building() {
|
||||
let settings = insta_settings();
|
||||
let _guard = settings.bind_to_scope();
|
||||
let current_wc = UserRevsetExpression::working_copy(WorkspaceId::default());
|
||||
let current_wc = UserRevsetExpression::working_copy(WorkspaceId::DEFAULT.to_owned());
|
||||
let foo_symbol = UserRevsetExpression::symbol("foo".to_string());
|
||||
let bar_symbol = UserRevsetExpression::symbol("bar".to_string());
|
||||
let baz_symbol = UserRevsetExpression::symbol("baz".to_string());
|
||||
|
||||
insta::assert_debug_snapshot!(
|
||||
current_wc,
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceId("default")))"#);
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceIdBuf("default")))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
current_wc.heads(),
|
||||
@r#"Heads(CommitRef(WorkingCopy(WorkspaceId("default"))))"#);
|
||||
@r#"Heads(CommitRef(WorkingCopy(WorkspaceIdBuf("default"))))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
current_wc.roots(),
|
||||
@r#"Roots(CommitRef(WorkingCopy(WorkspaceId("default"))))"#);
|
||||
@r#"Roots(CommitRef(WorkingCopy(WorkspaceIdBuf("default"))))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
current_wc.parents(), @r#"
|
||||
Ancestors {
|
||||
heads: CommitRef(WorkingCopy(WorkspaceId("default"))),
|
||||
heads: CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
generation: 1..2,
|
||||
}
|
||||
"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
current_wc.ancestors(), @r#"
|
||||
Ancestors {
|
||||
heads: CommitRef(WorkingCopy(WorkspaceId("default"))),
|
||||
heads: CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
generation: 0..18446744073709551615,
|
||||
}
|
||||
"#);
|
||||
@ -2809,7 +2808,7 @@ mod tests {
|
||||
foo_symbol.dag_range_to(¤t_wc), @r#"
|
||||
DagRange {
|
||||
roots: CommitRef(Symbol("foo")),
|
||||
heads: CommitRef(WorkingCopy(WorkspaceId("default"))),
|
||||
heads: CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
}
|
||||
"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
@ -2823,7 +2822,7 @@ mod tests {
|
||||
foo_symbol.range(¤t_wc), @r#"
|
||||
Range {
|
||||
roots: CommitRef(Symbol("foo")),
|
||||
heads: CommitRef(WorkingCopy(WorkspaceId("default"))),
|
||||
heads: CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
generation: 0..18446744073709551615,
|
||||
}
|
||||
"#);
|
||||
@ -2834,7 +2833,7 @@ mod tests {
|
||||
foo_symbol.union(¤t_wc), @r#"
|
||||
Union(
|
||||
CommitRef(Symbol("foo")),
|
||||
CommitRef(WorkingCopy(WorkspaceId("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
)
|
||||
"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
@ -2842,12 +2841,12 @@ mod tests {
|
||||
@"None");
|
||||
insta::assert_debug_snapshot!(
|
||||
RevsetExpression::union_all(&[current_wc.clone()]),
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceId("default")))"#);
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceIdBuf("default")))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
RevsetExpression::union_all(&[current_wc.clone(), foo_symbol.clone()]),
|
||||
@r#"
|
||||
Union(
|
||||
CommitRef(WorkingCopy(WorkspaceId("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
CommitRef(Symbol("foo")),
|
||||
)
|
||||
"#);
|
||||
@ -2859,7 +2858,7 @@ mod tests {
|
||||
]),
|
||||
@r#"
|
||||
Union(
|
||||
CommitRef(WorkingCopy(WorkspaceId("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
Union(
|
||||
CommitRef(Symbol("foo")),
|
||||
CommitRef(Symbol("bar")),
|
||||
@ -2876,7 +2875,7 @@ mod tests {
|
||||
@r#"
|
||||
Union(
|
||||
Union(
|
||||
CommitRef(WorkingCopy(WorkspaceId("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
CommitRef(Symbol("foo")),
|
||||
),
|
||||
Union(
|
||||
@ -2889,14 +2888,14 @@ mod tests {
|
||||
foo_symbol.intersection(¤t_wc), @r#"
|
||||
Intersection(
|
||||
CommitRef(Symbol("foo")),
|
||||
CommitRef(WorkingCopy(WorkspaceId("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
)
|
||||
"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
foo_symbol.minus(¤t_wc), @r#"
|
||||
Difference(
|
||||
CommitRef(Symbol("foo")),
|
||||
CommitRef(WorkingCopy(WorkspaceId("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
)
|
||||
"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
@ -2904,12 +2903,12 @@ mod tests {
|
||||
@"None");
|
||||
insta::assert_debug_snapshot!(
|
||||
RevsetExpression::coalesce(&[current_wc.clone()]),
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceId("default")))"#);
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceIdBuf("default")))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
RevsetExpression::coalesce(&[current_wc.clone(), foo_symbol.clone()]),
|
||||
@r#"
|
||||
Coalesce(
|
||||
CommitRef(WorkingCopy(WorkspaceId("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
CommitRef(Symbol("foo")),
|
||||
)
|
||||
"#);
|
||||
@ -2921,7 +2920,7 @@ mod tests {
|
||||
]),
|
||||
@r#"
|
||||
Coalesce(
|
||||
CommitRef(WorkingCopy(WorkspaceId("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
Coalesce(
|
||||
CommitRef(Symbol("foo")),
|
||||
CommitRef(Symbol("bar")),
|
||||
@ -2934,8 +2933,8 @@ mod tests {
|
||||
fn test_parse_revset() {
|
||||
let settings = insta_settings();
|
||||
let _guard = settings.bind_to_scope();
|
||||
let main_workspace_id = WorkspaceId::new("main".to_string());
|
||||
let other_workspace_id = WorkspaceId::new("other".to_string());
|
||||
let main_workspace_id = WorkspaceIdBuf::from("main");
|
||||
let other_workspace_id = WorkspaceIdBuf::from("other");
|
||||
|
||||
// Parse "@" (the current working copy)
|
||||
insta::assert_debug_snapshot!(
|
||||
@ -2943,13 +2942,13 @@ mod tests {
|
||||
@"WorkingCopyWithoutWorkspace");
|
||||
insta::assert_debug_snapshot!(
|
||||
parse("main@").unwrap(),
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceId("main")))"#);
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceIdBuf("main")))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
parse_with_workspace("@", &main_workspace_id).unwrap(),
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceId("main")))"#);
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceIdBuf("main")))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
parse_with_workspace("main@", &other_workspace_id).unwrap(),
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceId("main")))"#);
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceIdBuf("main")))"#);
|
||||
// "@" in function argument must be quoted
|
||||
insta::assert_debug_snapshot!(
|
||||
parse("author_name(foo@)").unwrap_err().kind(),
|
||||
@ -3217,21 +3216,21 @@ mod tests {
|
||||
@r#"Filter(Description(Substring("(foo)")))"#);
|
||||
assert!(parse("mine(foo)").is_err());
|
||||
insta::assert_debug_snapshot!(
|
||||
parse_with_workspace("empty()", &WorkspaceId::default()).unwrap(),
|
||||
parse_with_workspace("empty()", WorkspaceId::DEFAULT).unwrap(),
|
||||
@"NotIn(Filter(File(All)))");
|
||||
assert!(parse_with_workspace("empty(foo)", &WorkspaceId::default()).is_err());
|
||||
assert!(parse_with_workspace("file()", &WorkspaceId::default()).is_err());
|
||||
assert!(parse_with_workspace("empty(foo)", WorkspaceId::DEFAULT).is_err());
|
||||
assert!(parse_with_workspace("file()", WorkspaceId::DEFAULT).is_err());
|
||||
insta::assert_debug_snapshot!(
|
||||
parse_with_workspace("files(foo)", &WorkspaceId::default()).unwrap(),
|
||||
parse_with_workspace("files(foo)", WorkspaceId::DEFAULT).unwrap(),
|
||||
@r#"Filter(File(Pattern(PrefixPath("foo"))))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
parse_with_workspace("files(all())", &WorkspaceId::default()).unwrap(),
|
||||
parse_with_workspace("files(all())", WorkspaceId::DEFAULT).unwrap(),
|
||||
@"Filter(File(All))");
|
||||
insta::assert_debug_snapshot!(
|
||||
parse_with_workspace(r#"files(file:"foo")"#, &WorkspaceId::default()).unwrap(),
|
||||
parse_with_workspace(r#"files(file:"foo")"#, WorkspaceId::DEFAULT).unwrap(),
|
||||
@r#"Filter(File(Pattern(FilePath("foo"))))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
parse_with_workspace("files(foo|bar&baz)", &WorkspaceId::default()).unwrap(), @r#"
|
||||
parse_with_workspace("files(foo|bar&baz)", WorkspaceId::DEFAULT).unwrap(), @r#"
|
||||
Filter(
|
||||
File(
|
||||
UnionAll(
|
||||
@ -3383,7 +3382,7 @@ mod tests {
|
||||
|
||||
// Alias can be substituted to string literal.
|
||||
insta::assert_debug_snapshot!(
|
||||
parse_with_aliases_and_workspace("files(A)", [("A", "a")], &WorkspaceId::default())
|
||||
parse_with_aliases_and_workspace("files(A)", [("A", "a")], WorkspaceId::DEFAULT)
|
||||
.unwrap(),
|
||||
@r#"Filter(File(Pattern(PrefixPath("a"))))"#);
|
||||
|
||||
@ -3862,7 +3861,7 @@ mod tests {
|
||||
insta::assert_debug_snapshot!(
|
||||
optimize(parse_with_workspace(
|
||||
"committer_name(foo) & files(bar) & baz",
|
||||
&WorkspaceId::default()).unwrap(),
|
||||
WorkspaceId::DEFAULT).unwrap(),
|
||||
), @r#"
|
||||
Intersection(
|
||||
Intersection(
|
||||
@ -3875,7 +3874,7 @@ mod tests {
|
||||
insta::assert_debug_snapshot!(
|
||||
optimize(parse_with_workspace(
|
||||
"committer_name(foo) & files(bar) & author_name(baz)",
|
||||
&WorkspaceId::default()).unwrap(),
|
||||
WorkspaceId::DEFAULT).unwrap(),
|
||||
), @r#"
|
||||
Intersection(
|
||||
Intersection(
|
||||
@ -3888,7 +3887,7 @@ mod tests {
|
||||
insta::assert_debug_snapshot!(
|
||||
optimize(parse_with_workspace(
|
||||
"foo & files(bar) & baz",
|
||||
&WorkspaceId::default()).unwrap(),
|
||||
WorkspaceId::DEFAULT).unwrap(),
|
||||
), @r#"
|
||||
Intersection(
|
||||
Intersection(
|
||||
|
@ -59,10 +59,11 @@ use crate::op_store::RemoteView;
|
||||
use crate::op_store::RootOperationData;
|
||||
use crate::op_store::View;
|
||||
use crate::op_store::ViewId;
|
||||
use crate::op_store::WorkspaceId;
|
||||
use crate::ref_name::GitRefNameBuf;
|
||||
use crate::ref_name::RefNameBuf;
|
||||
use crate::ref_name::RemoteNameBuf;
|
||||
use crate::ref_name::WorkspaceId;
|
||||
use crate::ref_name::WorkspaceIdBuf;
|
||||
|
||||
// BLAKE2b-512 hash length in bytes
|
||||
const OPERATION_ID_LENGTH: usize = 64;
|
||||
@ -482,7 +483,7 @@ fn view_to_proto(view: &View) -> crate::protos::op_store::View {
|
||||
for (workspace_id, commit_id) in &view.wc_commit_ids {
|
||||
proto
|
||||
.wc_commit_ids
|
||||
.insert(workspace_id.as_str().to_string(), commit_id.to_bytes());
|
||||
.insert(workspace_id.into(), commit_id.to_bytes());
|
||||
}
|
||||
for head_id in &view.head_ids {
|
||||
proto.head_ids.push(head_id.to_bytes());
|
||||
@ -517,12 +518,14 @@ fn view_from_proto(proto: crate::protos::op_store::View) -> View {
|
||||
// copies
|
||||
#[expect(deprecated)]
|
||||
if !proto.wc_commit_id.is_empty() {
|
||||
view.wc_commit_ids
|
||||
.insert(WorkspaceId::default(), CommitId::new(proto.wc_commit_id));
|
||||
view.wc_commit_ids.insert(
|
||||
WorkspaceId::DEFAULT.to_owned(),
|
||||
CommitId::new(proto.wc_commit_id),
|
||||
);
|
||||
}
|
||||
for (workspace_id, commit_id) in proto.wc_commit_ids {
|
||||
view.wc_commit_ids
|
||||
.insert(WorkspaceId::new(workspace_id), CommitId::new(commit_id));
|
||||
.insert(WorkspaceIdBuf::from(workspace_id), CommitId::new(commit_id));
|
||||
}
|
||||
for head_id_bytes in proto.head_ids {
|
||||
view.head_ids.insert(CommitId::new(head_id_bytes));
|
||||
@ -781,8 +784,8 @@ mod tests {
|
||||
},
|
||||
git_head: RefTarget::normal(CommitId::from_hex("fff111")),
|
||||
wc_commit_ids: btreemap! {
|
||||
WorkspaceId::default() => default_wc_commit_id,
|
||||
WorkspaceId::new("test".to_string()) => test_wc_commit_id,
|
||||
WorkspaceId::DEFAULT.to_owned() => default_wc_commit_id,
|
||||
"test".into() => test_wc_commit_id,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -26,13 +26,14 @@ use crate::op_store::BookmarkTarget;
|
||||
use crate::op_store::RefTarget;
|
||||
use crate::op_store::RefTargetOptionExt as _;
|
||||
use crate::op_store::RemoteRef;
|
||||
use crate::op_store::WorkspaceId;
|
||||
use crate::ref_name::GitRefName;
|
||||
use crate::ref_name::GitRefNameBuf;
|
||||
use crate::ref_name::RefName;
|
||||
use crate::ref_name::RefNameBuf;
|
||||
use crate::ref_name::RemoteName;
|
||||
use crate::ref_name::RemoteRefSymbol;
|
||||
use crate::ref_name::WorkspaceId;
|
||||
use crate::ref_name::WorkspaceIdBuf;
|
||||
use crate::refs;
|
||||
use crate::refs::LocalAndRemoteRef;
|
||||
use crate::str_util::StringPattern;
|
||||
@ -50,7 +51,7 @@ impl View {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn wc_commit_ids(&self) -> &BTreeMap<WorkspaceId, CommitId> {
|
||||
pub fn wc_commit_ids(&self) -> &BTreeMap<WorkspaceIdBuf, CommitId> {
|
||||
&self.data.wc_commit_ids
|
||||
}
|
||||
|
||||
@ -58,7 +59,7 @@ impl View {
|
||||
self.data.wc_commit_ids.get(workspace_id)
|
||||
}
|
||||
|
||||
pub fn workspaces_for_wc_commit_id(&self, commit_id: &CommitId) -> Vec<WorkspaceId> {
|
||||
pub fn workspaces_for_wc_commit_id(&self, commit_id: &CommitId) -> Vec<WorkspaceIdBuf> {
|
||||
let mut workspaces_ids = vec![];
|
||||
for (workspace_id, wc_commit_id) in &self.data.wc_commit_ids {
|
||||
if wc_commit_id == commit_id {
|
||||
@ -93,7 +94,7 @@ impl View {
|
||||
&self.data.git_head
|
||||
}
|
||||
|
||||
pub fn set_wc_commit(&mut self, workspace_id: WorkspaceId, commit_id: CommitId) {
|
||||
pub fn set_wc_commit(&mut self, workspace_id: WorkspaceIdBuf, commit_id: CommitId) {
|
||||
self.data.wc_commit_ids.insert(workspace_id, commit_id);
|
||||
}
|
||||
|
||||
@ -104,11 +105,11 @@ impl View {
|
||||
pub fn rename_workspace(
|
||||
&mut self,
|
||||
old_workspace_id: &WorkspaceId,
|
||||
new_workspace_id: WorkspaceId,
|
||||
new_workspace_id: WorkspaceIdBuf,
|
||||
) -> Result<(), RenameWorkspaceError> {
|
||||
if self.data.wc_commit_ids.contains_key(&new_workspace_id) {
|
||||
return Err(RenameWorkspaceError::WorkspaceAlreadyExists {
|
||||
workspace_id: new_workspace_id.as_str().to_owned(),
|
||||
workspace_id: new_workspace_id.clone(),
|
||||
});
|
||||
}
|
||||
let wc_commit_id = self
|
||||
@ -116,7 +117,7 @@ impl View {
|
||||
.wc_commit_ids
|
||||
.remove(old_workspace_id)
|
||||
.ok_or_else(|| RenameWorkspaceError::WorkspaceDoesNotExist {
|
||||
workspace_id: old_workspace_id.as_str().to_owned(),
|
||||
workspace_id: old_workspace_id.to_owned(),
|
||||
})?;
|
||||
self.data
|
||||
.wc_commit_ids
|
||||
@ -417,9 +418,9 @@ impl View {
|
||||
/// Error from attempts to rename a workspace
|
||||
#[derive(Debug, Error)]
|
||||
pub enum RenameWorkspaceError {
|
||||
#[error("Workspace {workspace_id} not found")]
|
||||
WorkspaceDoesNotExist { workspace_id: String },
|
||||
#[error("Workspace {} not found", workspace_id.as_symbol())]
|
||||
WorkspaceDoesNotExist { workspace_id: WorkspaceIdBuf },
|
||||
|
||||
#[error("Workspace {workspace_id} already exists")]
|
||||
WorkspaceAlreadyExists { workspace_id: String },
|
||||
#[error("Workspace {} already exists", workspace_id.as_symbol())]
|
||||
WorkspaceAlreadyExists { workspace_id: WorkspaceIdBuf },
|
||||
}
|
||||
|
@ -38,8 +38,9 @@ use crate::matchers::Matcher;
|
||||
use crate::op_heads_store::OpHeadsStoreError;
|
||||
use crate::op_store::OpStoreError;
|
||||
use crate::op_store::OperationId;
|
||||
use crate::op_store::WorkspaceId;
|
||||
use crate::operation::Operation;
|
||||
use crate::ref_name::WorkspaceId;
|
||||
use crate::ref_name::WorkspaceIdBuf;
|
||||
use crate::repo::ReadonlyRepo;
|
||||
use crate::repo::Repo as _;
|
||||
use crate::repo::RewriteRootCommit;
|
||||
@ -86,7 +87,7 @@ pub trait WorkingCopyFactory {
|
||||
working_copy_path: PathBuf,
|
||||
state_path: PathBuf,
|
||||
operation_id: OperationId,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
) -> Result<Box<dyn WorkingCopy>, WorkingCopyStateError>;
|
||||
|
||||
/// Load an existing working copy.
|
||||
@ -126,7 +127,7 @@ pub trait LockedWorkingCopy {
|
||||
) -> Result<CheckoutStats, CheckoutError>;
|
||||
|
||||
/// Update the workspace name.
|
||||
fn rename_workspace(&mut self, new_workspace_name: WorkspaceId);
|
||||
fn rename_workspace(&mut self, new_workspace_name: WorkspaceIdBuf);
|
||||
|
||||
/// Update to another commit without touching the files in the working copy.
|
||||
fn reset(&mut self, commit: &Commit) -> Result<(), ResetError>;
|
||||
@ -426,15 +427,15 @@ pub enum RecoverWorkspaceError {
|
||||
#[error(transparent)]
|
||||
RewriteRootCommit(#[from] RewriteRootCommit),
|
||||
/// Working copy commit is missing.
|
||||
#[error("\"{0:?}\" doesn't have a working-copy commit")]
|
||||
WorkspaceMissingWorkingCopy(WorkspaceId),
|
||||
#[error(r#""{}" doesn't have a working-copy commit"#, .0.as_symbol())]
|
||||
WorkspaceMissingWorkingCopy(WorkspaceIdBuf),
|
||||
}
|
||||
|
||||
/// Recover this workspace to its last known checkout.
|
||||
pub fn create_and_check_out_recovery_commit(
|
||||
locked_wc: &mut dyn LockedWorkingCopy,
|
||||
repo: &Arc<ReadonlyRepo>,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
description: &str,
|
||||
) -> Result<(Arc<ReadonlyRepo>, Commit), RecoverWorkspaceError> {
|
||||
let mut tx = repo.start_transaction();
|
||||
|
@ -34,7 +34,8 @@ use crate::local_working_copy::LocalWorkingCopy;
|
||||
use crate::local_working_copy::LocalWorkingCopyFactory;
|
||||
use crate::op_heads_store::OpHeadsStoreError;
|
||||
use crate::op_store::OperationId;
|
||||
use crate::op_store::WorkspaceId;
|
||||
use crate::ref_name::WorkspaceId;
|
||||
use crate::ref_name::WorkspaceIdBuf;
|
||||
use crate::repo::read_store_type;
|
||||
use crate::repo::BackendInitializer;
|
||||
use crate::repo::CheckOutCommitError;
|
||||
@ -128,7 +129,7 @@ fn init_working_copy(
|
||||
workspace_root: &Path,
|
||||
jj_dir: &Path,
|
||||
working_copy_factory: &dyn WorkingCopyFactory,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
) -> Result<(Box<dyn WorkingCopy>, Arc<ReadonlyRepo>), WorkspaceInitError> {
|
||||
let working_copy_state_path = jj_dir.join("working_copy");
|
||||
std::fs::create_dir(&working_copy_state_path).context(&working_copy_state_path)?;
|
||||
@ -136,7 +137,7 @@ fn init_working_copy(
|
||||
let mut tx = repo.start_transaction();
|
||||
tx.repo_mut()
|
||||
.check_out(workspace_id.clone(), &repo.store().root_commit())?;
|
||||
let repo = tx.commit(format!("add workspace '{}'", workspace_id.as_str()))?;
|
||||
let repo = tx.commit(format!("add workspace '{}'", workspace_id.as_symbol()))?;
|
||||
|
||||
let working_copy = working_copy_factory.init_working_copy(
|
||||
repo.store().clone(),
|
||||
@ -287,7 +288,7 @@ impl Workspace {
|
||||
index_store_initializer: &IndexStoreInitializer,
|
||||
submodule_store_initializer: &SubmoduleStoreInitializer,
|
||||
working_copy_factory: &dyn WorkingCopyFactory,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
) -> Result<(Self, Arc<ReadonlyRepo>), WorkspaceInitError> {
|
||||
let jj_dir = create_jj_dir(workspace_root)?;
|
||||
(|| {
|
||||
@ -340,7 +341,7 @@ impl Workspace {
|
||||
ReadonlyRepo::default_index_store_initializer(),
|
||||
ReadonlyRepo::default_submodule_store_initializer(),
|
||||
&*default_working_copy_factory(),
|
||||
WorkspaceId::default(),
|
||||
WorkspaceId::DEFAULT.to_owned(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -349,7 +350,7 @@ impl Workspace {
|
||||
repo_path: &Path,
|
||||
repo: &Arc<ReadonlyRepo>,
|
||||
working_copy_factory: &dyn WorkingCopyFactory,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
) -> Result<(Self, Arc<ReadonlyRepo>), WorkspaceInitError> {
|
||||
let jj_dir = create_jj_dir(workspace_root)?;
|
||||
|
||||
|
@ -17,7 +17,7 @@ use std::path::PathBuf;
|
||||
|
||||
use jj_lib::config::StackedConfig;
|
||||
use jj_lib::git_backend::GitBackend;
|
||||
use jj_lib::op_store::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceId;
|
||||
use jj_lib::repo::Repo as _;
|
||||
use jj_lib::settings::UserSettings;
|
||||
use jj_lib::workspace::Workspace;
|
||||
@ -145,10 +145,7 @@ fn test_init_with_default_config(backend: TestRepoBackend) {
|
||||
let settings = UserSettings::from_config(StackedConfig::with_defaults()).unwrap();
|
||||
let test_workspace = TestWorkspace::init_with_backend_and_settings(backend, &settings);
|
||||
let repo = &test_workspace.repo;
|
||||
let wc_commit_id = repo
|
||||
.view()
|
||||
.get_wc_commit_id(&WorkspaceId::default())
|
||||
.unwrap();
|
||||
let wc_commit_id = repo.view().get_wc_commit_id(WorkspaceId::DEFAULT).unwrap();
|
||||
let wc_commit = repo.store().get_commit(wc_commit_id).unwrap();
|
||||
assert_eq!(wc_commit.author().name, "".to_string());
|
||||
assert_eq!(wc_commit.author().email, "".to_string());
|
||||
@ -163,10 +160,7 @@ fn test_init_checkout(backend: TestRepoBackend) {
|
||||
let settings = testutils::user_settings();
|
||||
let test_workspace = TestWorkspace::init_with_backend_and_settings(backend, &settings);
|
||||
let repo = &test_workspace.repo;
|
||||
let wc_commit_id = repo
|
||||
.view()
|
||||
.get_wc_commit_id(&WorkspaceId::default())
|
||||
.unwrap();
|
||||
let wc_commit_id = repo.view().get_wc_commit_id(WorkspaceId::DEFAULT).unwrap();
|
||||
let wc_commit = repo.store().get_commit(wc_commit_id).unwrap();
|
||||
assert_eq!(*wc_commit.tree_id(), repo.store().empty_merged_tree_id());
|
||||
assert_eq!(
|
||||
|
@ -36,7 +36,7 @@ use jj_lib::merge::MergedTreeValue;
|
||||
use jj_lib::merged_tree::MergedTree;
|
||||
use jj_lib::merged_tree::MergedTreeBuilder;
|
||||
use jj_lib::op_store::OperationId;
|
||||
use jj_lib::op_store::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceId;
|
||||
use jj_lib::repo::ReadonlyRepo;
|
||||
use jj_lib::repo::Repo as _;
|
||||
use jj_lib::repo_path::RepoPath;
|
||||
@ -113,10 +113,7 @@ fn test_root() {
|
||||
assert_eq!(wc.sparse_patterns().unwrap(), vec![RepoPathBuf::root()]);
|
||||
let new_tree = test_workspace.snapshot().unwrap();
|
||||
let repo = &test_workspace.repo;
|
||||
let wc_commit_id = repo
|
||||
.view()
|
||||
.get_wc_commit_id(&WorkspaceId::default())
|
||||
.unwrap();
|
||||
let wc_commit_id = repo.view().get_wc_commit_id(WorkspaceId::DEFAULT).unwrap();
|
||||
let wc_commit = repo.store().get_commit(wc_commit_id).unwrap();
|
||||
assert_eq!(new_tree.id(), *wc_commit.tree_id());
|
||||
assert_eq!(new_tree.id(), repo.store().empty_merged_tree_id());
|
||||
|
@ -16,10 +16,11 @@ use jj_lib::backend::CommitId;
|
||||
use jj_lib::op_store::RefTarget;
|
||||
use jj_lib::op_store::RemoteRef;
|
||||
use jj_lib::op_store::RemoteRefState;
|
||||
use jj_lib::op_store::WorkspaceId;
|
||||
use jj_lib::ref_name::RefName;
|
||||
use jj_lib::ref_name::RemoteName;
|
||||
use jj_lib::ref_name::RemoteRefSymbol;
|
||||
use jj_lib::ref_name::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::repo::Repo as _;
|
||||
use jj_lib::rewrite::RebaseOptions;
|
||||
use maplit::hashset;
|
||||
@ -53,7 +54,7 @@ fn test_edit() {
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let ws_id = WorkspaceId::default();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
tx.repo_mut().edit(ws_id.clone(), &wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws_id), Some(wc_commit.id()));
|
||||
@ -70,7 +71,7 @@ fn test_checkout() {
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let ws_id = WorkspaceId::default();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
let wc_commit = tx
|
||||
.repo_mut()
|
||||
.check_out(ws_id.clone(), &wc_commit_parent)
|
||||
@ -92,7 +93,7 @@ fn test_edit_previous_not_empty() {
|
||||
let mut tx = repo.start_transaction();
|
||||
let mut_repo = tx.repo_mut();
|
||||
let old_wc_commit = write_random_commit(mut_repo);
|
||||
let ws_id = WorkspaceId::default();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
@ -120,7 +121,7 @@ fn test_edit_previous_empty() {
|
||||
)
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws_id = WorkspaceId::default();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
@ -157,7 +158,7 @@ fn test_edit_previous_empty_merge() {
|
||||
.set_tree_id(old_parent_tree.id())
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws_id = WorkspaceId::default();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
@ -186,7 +187,7 @@ fn test_edit_previous_empty_with_description() {
|
||||
.set_description("not empty")
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws_id = WorkspaceId::default();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
@ -215,7 +216,7 @@ fn test_edit_previous_empty_with_local_bookmark() {
|
||||
.write()
|
||||
.unwrap();
|
||||
mut_repo.set_local_bookmark_target("b".as_ref(), RefTarget::normal(old_wc_commit.id().clone()));
|
||||
let ws_id = WorkspaceId::default();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
@ -243,9 +244,9 @@ fn test_edit_previous_empty_with_other_workspace() {
|
||||
)
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws_id = WorkspaceId::default();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let other_ws_id = WorkspaceId::new("other".to_string());
|
||||
let other_ws_id = WorkspaceIdBuf::from("other");
|
||||
mut_repo.edit(other_ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
@ -280,7 +281,7 @@ fn test_edit_previous_empty_non_head() {
|
||||
)
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws_id = WorkspaceId::default();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
@ -307,7 +308,7 @@ fn test_edit_initial() {
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let workspace_id = WorkspaceId::new("new-workspace".to_string());
|
||||
let workspace_id = WorkspaceIdBuf::from("new-workspace");
|
||||
tx.repo_mut()
|
||||
.edit(workspace_id.clone(), &wc_commit)
|
||||
.unwrap();
|
||||
@ -332,7 +333,7 @@ fn test_edit_hidden_commit() {
|
||||
// in the view head ids.
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let ws_id = WorkspaceId::default();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
tx.repo_mut().edit(ws_id.clone(), &wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws_id), Some(wc_commit.id()));
|
||||
@ -476,7 +477,7 @@ fn test_has_changed() {
|
||||
let commit1 = write_random_commit(mut_repo);
|
||||
let commit2 = write_random_commit(mut_repo);
|
||||
mut_repo.remove_head(commit2.id());
|
||||
let ws_id = WorkspaceId::default();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo
|
||||
.set_wc_commit(ws_id.clone(), commit1.id().clone())
|
||||
.unwrap();
|
||||
@ -637,7 +638,7 @@ fn test_remove_wc_commit_previous_not_discardable() {
|
||||
let mut tx = repo.start_transaction();
|
||||
let mut_repo = tx.repo_mut();
|
||||
let old_wc_commit = write_random_commit(mut_repo);
|
||||
let ws_id = WorkspaceId::default();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
@ -664,7 +665,7 @@ fn test_remove_wc_commit_previous_discardable() {
|
||||
)
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws_id = WorkspaceId::default();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
|
@ -34,10 +34,11 @@ use jj_lib::object_id::ObjectId as _;
|
||||
use jj_lib::op_store::RefTarget;
|
||||
use jj_lib::op_store::RemoteRef;
|
||||
use jj_lib::op_store::RemoteRefState;
|
||||
use jj_lib::op_store::WorkspaceId;
|
||||
use jj_lib::ref_name::RefName;
|
||||
use jj_lib::ref_name::RemoteName;
|
||||
use jj_lib::ref_name::RemoteRefSymbol;
|
||||
use jj_lib::ref_name::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::repo::Repo;
|
||||
use jj_lib::repo_path::RepoPath;
|
||||
use jj_lib::repo_path::RepoPathUiConverter;
|
||||
@ -431,8 +432,8 @@ fn test_resolve_working_copy() {
|
||||
let commit1 = write_random_commit(mut_repo);
|
||||
let commit2 = write_random_commit(mut_repo);
|
||||
|
||||
let ws1 = WorkspaceId::new("ws1".to_string());
|
||||
let ws2 = WorkspaceId::new("ws2".to_string());
|
||||
let ws1 = WorkspaceIdBuf::from("ws1");
|
||||
let ws2 = WorkspaceIdBuf::from("ws2");
|
||||
|
||||
// Cannot resolve a working-copy commit for an unknown workspace
|
||||
assert_matches!(
|
||||
@ -462,7 +463,7 @@ fn test_resolve_working_copy() {
|
||||
mut_repo
|
||||
.set_wc_commit(ws2.clone(), commit2.id().clone())
|
||||
.unwrap();
|
||||
let resolve = |ws_id: WorkspaceId| -> Vec<CommitId> {
|
||||
let resolve = |ws_id: WorkspaceIdBuf| -> Vec<CommitId> {
|
||||
RevsetExpression::working_copy(ws_id)
|
||||
.resolve_user_expression(mut_repo, &FailingSymbolResolver)
|
||||
.unwrap()
|
||||
@ -491,8 +492,8 @@ fn test_resolve_working_copies() {
|
||||
let commit2 = write_random_commit(mut_repo);
|
||||
|
||||
// Add some workspaces
|
||||
let ws1 = WorkspaceId::new("ws1".to_string());
|
||||
let ws2 = WorkspaceId::new("ws2".to_string());
|
||||
let ws1 = WorkspaceIdBuf::from("ws1");
|
||||
let ws2 = WorkspaceIdBuf::from("ws2");
|
||||
|
||||
// add one commit to each working copy
|
||||
mut_repo
|
||||
@ -792,7 +793,7 @@ fn test_resolve_symbol_tags() {
|
||||
);
|
||||
|
||||
// "@" (quoted) can be resolved, and root is a normal symbol.
|
||||
let ws_id = WorkspaceId::default();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo
|
||||
.set_wc_commit(ws_id.clone(), commit1.id().clone())
|
||||
.unwrap();
|
||||
@ -1006,7 +1007,7 @@ fn test_evaluate_expression_root_and_checkout() {
|
||||
|
||||
// Can find the current working-copy commit
|
||||
mut_repo
|
||||
.set_wc_commit(WorkspaceId::default(), commit1.id().clone())
|
||||
.set_wc_commit(WorkspaceId::DEFAULT.to_owned(), commit1.id().clone())
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
resolve_commit_ids_in_workspace(mut_repo, "@", &test_workspace.workspace, None),
|
||||
@ -1158,7 +1159,7 @@ fn test_evaluate_expression_parents() {
|
||||
|
||||
// Can find parents of the current working-copy commit
|
||||
mut_repo
|
||||
.set_wc_commit(WorkspaceId::default(), commit2.id().clone())
|
||||
.set_wc_commit(WorkspaceId::DEFAULT.to_owned(), commit2.id().clone())
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
resolve_commit_ids_in_workspace(mut_repo, "@-", &test_workspace.workspace, None,),
|
||||
|
@ -21,10 +21,11 @@ use jj_lib::merged_tree::MergedTree;
|
||||
use jj_lib::op_store::RefTarget;
|
||||
use jj_lib::op_store::RemoteRef;
|
||||
use jj_lib::op_store::RemoteRefState;
|
||||
use jj_lib::op_store::WorkspaceId;
|
||||
use jj_lib::ref_name::RefName;
|
||||
use jj_lib::ref_name::RemoteName;
|
||||
use jj_lib::ref_name::RemoteRefSymbol;
|
||||
use jj_lib::ref_name::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::repo::Repo as _;
|
||||
use jj_lib::repo_path::RepoPath;
|
||||
use jj_lib::rewrite::rebase_commit_with_options;
|
||||
@ -1506,9 +1507,9 @@ fn test_rebase_descendants_update_checkout() {
|
||||
.set_parents(vec![commit_a.id().clone()])
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws1_id = WorkspaceId::new("ws1".to_string());
|
||||
let ws2_id = WorkspaceId::new("ws2".to_string());
|
||||
let ws3_id = WorkspaceId::new("ws3".to_string());
|
||||
let ws1_id = WorkspaceIdBuf::from("ws1");
|
||||
let ws2_id = WorkspaceIdBuf::from("ws2");
|
||||
let ws3_id = WorkspaceIdBuf::from("ws3");
|
||||
tx.repo_mut()
|
||||
.set_wc_commit(ws1_id.clone(), commit_b.id().clone())
|
||||
.unwrap();
|
||||
@ -1554,9 +1555,9 @@ fn test_rebase_descendants_update_checkout_abandoned() {
|
||||
.set_parents(vec![commit_a.id().clone()])
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws1_id = WorkspaceId::new("ws1".to_string());
|
||||
let ws2_id = WorkspaceId::new("ws2".to_string());
|
||||
let ws3_id = WorkspaceId::new("ws3".to_string());
|
||||
let ws1_id = WorkspaceIdBuf::from("ws1");
|
||||
let ws2_id = WorkspaceIdBuf::from("ws2");
|
||||
let ws3_id = WorkspaceIdBuf::from("ws3");
|
||||
tx.repo_mut()
|
||||
.set_wc_commit(ws1_id.clone(), commit_b.id().clone())
|
||||
.unwrap();
|
||||
@ -1614,7 +1615,7 @@ fn test_rebase_descendants_update_checkout_abandoned_merge() {
|
||||
.set_parents(vec![commit_b.id().clone(), commit_c.id().clone()])
|
||||
.write()
|
||||
.unwrap();
|
||||
let workspace_id = WorkspaceId::default();
|
||||
let workspace_id = WorkspaceId::DEFAULT.to_owned();
|
||||
tx.repo_mut()
|
||||
.set_wc_commit(workspace_id.clone(), commit_d.id().clone())
|
||||
.unwrap();
|
||||
@ -1829,7 +1830,7 @@ fn test_rebase_abandoning_empty() {
|
||||
.write()
|
||||
.unwrap();
|
||||
|
||||
let workspace = WorkspaceId::new("ws".to_string());
|
||||
let workspace = WorkspaceIdBuf::from("ws");
|
||||
tx.repo_mut()
|
||||
.set_wc_commit(workspace.clone(), commit_e.id().clone())
|
||||
.unwrap();
|
||||
|
@ -18,10 +18,10 @@ use jj_lib::op_store::BookmarkTarget;
|
||||
use jj_lib::op_store::RefTarget;
|
||||
use jj_lib::op_store::RemoteRef;
|
||||
use jj_lib::op_store::RemoteRefState;
|
||||
use jj_lib::op_store::WorkspaceId;
|
||||
use jj_lib::ref_name::RefName;
|
||||
use jj_lib::ref_name::RemoteName;
|
||||
use jj_lib::ref_name::RemoteRefSymbol;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::repo::Repo as _;
|
||||
use maplit::btreemap;
|
||||
use maplit::hashset;
|
||||
@ -139,13 +139,13 @@ fn test_merge_views_checkout() {
|
||||
let commit1 = write_random_commit(initial_tx.repo_mut());
|
||||
let commit2 = write_random_commit(initial_tx.repo_mut());
|
||||
let commit3 = write_random_commit(initial_tx.repo_mut());
|
||||
let ws1_id = WorkspaceId::new("ws1".to_string());
|
||||
let ws2_id = WorkspaceId::new("ws2".to_string());
|
||||
let ws3_id = WorkspaceId::new("ws3".to_string());
|
||||
let ws4_id = WorkspaceId::new("ws4".to_string());
|
||||
let ws5_id = WorkspaceId::new("ws5".to_string());
|
||||
let ws6_id = WorkspaceId::new("ws6".to_string());
|
||||
let ws7_id = WorkspaceId::new("ws7".to_string());
|
||||
let ws1_id = WorkspaceIdBuf::from("ws1");
|
||||
let ws2_id = WorkspaceIdBuf::from("ws2");
|
||||
let ws3_id = WorkspaceIdBuf::from("ws3");
|
||||
let ws4_id = WorkspaceIdBuf::from("ws4");
|
||||
let ws5_id = WorkspaceIdBuf::from("ws5");
|
||||
let ws6_id = WorkspaceIdBuf::from("ws6");
|
||||
let ws7_id = WorkspaceIdBuf::from("ws7");
|
||||
initial_tx
|
||||
.repo_mut()
|
||||
.set_wc_commit(ws1_id.clone(), commit1.id().clone())
|
||||
|
@ -15,7 +15,7 @@
|
||||
use std::thread;
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use jj_lib::op_store::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::repo::Repo as _;
|
||||
use jj_lib::workspace::default_working_copy_factories;
|
||||
use jj_lib::workspace::default_working_copy_factory;
|
||||
@ -48,7 +48,7 @@ fn test_init_additional_workspace() {
|
||||
let test_workspace = TestWorkspace::init_with_settings(&settings);
|
||||
let workspace = &test_workspace.workspace;
|
||||
|
||||
let ws2_id = WorkspaceId::new("ws2".to_string());
|
||||
let ws2_id = WorkspaceIdBuf::from("ws2");
|
||||
let ws2_root = test_workspace.root_dir().join("ws2_root");
|
||||
std::fs::create_dir(&ws2_root).unwrap();
|
||||
let (ws2, repo) = Workspace::init_workspace_with_existing_repo(
|
||||
|
Loading…
x
Reference in New Issue
Block a user