mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-05 15:32:49 +00:00
view: rename workspace "id" to "name"
This matches the current implementation.
This commit is contained in:
parent
e66c545438
commit
3f5f872204
@ -28,8 +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::ref_name::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::ref_name::WorkspaceName;
|
||||
use jj_lib::ref_name::WorkspaceNameBuf;
|
||||
use jj_lib::repo::ReadonlyRepo;
|
||||
use jj_lib::repo_path::RepoPathBuf;
|
||||
use jj_lib::settings::UserSettings;
|
||||
@ -80,7 +80,7 @@ fn run_custom_command(
|
||||
&ReadonlyRepo::default_index_store_initializer(),
|
||||
&ReadonlyRepo::default_submodule_store_initializer(),
|
||||
&ConflictsWorkingCopyFactory {},
|
||||
WorkspaceId::DEFAULT.to_owned(),
|
||||
WorkspaceName::DEFAULT.to_owned(),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
@ -121,14 +121,14 @@ impl ConflictsWorkingCopy {
|
||||
working_copy_path: PathBuf,
|
||||
state_path: PathBuf,
|
||||
operation_id: OperationId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
workspace_name: WorkspaceNameBuf,
|
||||
) -> Result<Self, WorkingCopyStateError> {
|
||||
let inner = LocalWorkingCopy::init(
|
||||
store,
|
||||
working_copy_path.clone(),
|
||||
state_path,
|
||||
operation_id,
|
||||
workspace_id,
|
||||
workspace_name,
|
||||
)?;
|
||||
Ok(ConflictsWorkingCopy {
|
||||
inner: Box::new(inner),
|
||||
@ -154,8 +154,8 @@ impl WorkingCopy for ConflictsWorkingCopy {
|
||||
Self::name()
|
||||
}
|
||||
|
||||
fn workspace_id(&self) -> &WorkspaceId {
|
||||
self.inner.workspace_id()
|
||||
fn workspace_name(&self) -> &WorkspaceName {
|
||||
self.inner.workspace_name()
|
||||
}
|
||||
|
||||
fn operation_id(&self) -> &OperationId {
|
||||
@ -188,14 +188,14 @@ impl WorkingCopyFactory for ConflictsWorkingCopyFactory {
|
||||
working_copy_path: PathBuf,
|
||||
state_path: PathBuf,
|
||||
operation_id: OperationId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
workspace_name: WorkspaceNameBuf,
|
||||
) -> Result<Box<dyn WorkingCopy>, WorkingCopyStateError> {
|
||||
Ok(Box::new(ConflictsWorkingCopy::init(
|
||||
store,
|
||||
working_copy_path,
|
||||
state_path,
|
||||
operation_id,
|
||||
workspace_id,
|
||||
workspace_name,
|
||||
)?))
|
||||
}
|
||||
|
||||
@ -264,8 +264,8 @@ impl LockedWorkingCopy for LockedConflictsWorkingCopy {
|
||||
self.inner.check_out(commit, options)
|
||||
}
|
||||
|
||||
fn rename_workspace(&mut self, new_workspace_id: WorkspaceIdBuf) {
|
||||
self.inner.rename_workspace(new_workspace_id);
|
||||
fn rename_workspace(&mut self, new_name: WorkspaceNameBuf) {
|
||||
self.inner.rename_workspace(new_name);
|
||||
}
|
||||
|
||||
fn reset(&mut self, commit: &Commit) -> Result<(), ResetError> {
|
||||
|
@ -84,8 +84,8 @@ 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::ref_name::WorkspaceName;
|
||||
use jj_lib::ref_name::WorkspaceNameBuf;
|
||||
use jj_lib::repo::merge_factories_map;
|
||||
use jj_lib::repo::CheckOutCommitError;
|
||||
use jj_lib::repo::EditCommitError;
|
||||
@ -784,7 +784,7 @@ pub struct WorkspaceCommandEnvironment {
|
||||
revset_aliases_map: RevsetAliasesMap,
|
||||
template_aliases_map: TemplateAliasesMap,
|
||||
path_converter: RepoPathUiConverter,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
workspace_name: WorkspaceNameBuf,
|
||||
immutable_heads_expression: Rc<UserRevsetExpression>,
|
||||
short_prefixes_expression: Option<Rc<UserRevsetExpression>>,
|
||||
conflict_marker_style: ConflictMarkerStyle,
|
||||
@ -806,7 +806,7 @@ impl WorkspaceCommandEnvironment {
|
||||
revset_aliases_map,
|
||||
template_aliases_map,
|
||||
path_converter,
|
||||
workspace_id: workspace.workspace_id().to_owned(),
|
||||
workspace_name: workspace.workspace_name().to_owned(),
|
||||
immutable_heads_expression: RevsetExpression::root(),
|
||||
short_prefixes_expression: None,
|
||||
conflict_marker_style: settings.get("ui.conflict-marker-style")?,
|
||||
@ -820,14 +820,14 @@ impl WorkspaceCommandEnvironment {
|
||||
&self.path_converter
|
||||
}
|
||||
|
||||
pub fn workspace_id(&self) -> &WorkspaceId {
|
||||
&self.workspace_id
|
||||
pub fn workspace_name(&self) -> &WorkspaceName {
|
||||
&self.workspace_name
|
||||
}
|
||||
|
||||
pub(crate) fn revset_parse_context(&self) -> RevsetParseContext {
|
||||
let workspace_context = RevsetWorkspaceContext {
|
||||
path_converter: &self.path_converter,
|
||||
workspace_id: &self.workspace_id,
|
||||
workspace_name: &self.workspace_name,
|
||||
};
|
||||
let now = if let Some(timestamp) = self.settings.commit_timestamp() {
|
||||
chrono::Local
|
||||
@ -998,7 +998,7 @@ impl WorkspaceCommandEnvironment {
|
||||
CommitTemplateLanguage::new(
|
||||
repo,
|
||||
&self.path_converter,
|
||||
&self.workspace_id,
|
||||
&self.workspace_name,
|
||||
self.revset_parse_context(),
|
||||
id_prefix_context,
|
||||
self.immutable_expression(),
|
||||
@ -1169,10 +1169,10 @@ impl WorkspaceCommandHelper {
|
||||
let old_git_head = self.repo().view().git_head().clone();
|
||||
let new_git_head = tx.repo().view().git_head().clone();
|
||||
if let Some(new_git_head_id) = new_git_head.as_normal() {
|
||||
let workspace_id = self.workspace_id().to_owned();
|
||||
let workspace_name = self.workspace_name().to_owned();
|
||||
let new_git_head_commit = tx.repo().store().get_commit(new_git_head_id)?;
|
||||
tx.repo_mut()
|
||||
.check_out(workspace_id, &new_git_head_commit)?;
|
||||
.check_out(workspace_name, &new_git_head_commit)?;
|
||||
let mut locked_ws = self.workspace.start_working_copy_mutation()?;
|
||||
// The working copy was presumably updated by the git command that updated
|
||||
// HEAD, so we just need to reset our working copy
|
||||
@ -1289,12 +1289,12 @@ impl WorkspaceCommandHelper {
|
||||
) -> Result<SnapshotStats, CommandError> {
|
||||
self.check_working_copy_writable()?;
|
||||
|
||||
let workspace_id = self.workspace_id().to_owned();
|
||||
let workspace_name = self.workspace_name().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(),
|
||||
&self.user_repo.repo,
|
||||
workspace_id,
|
||||
workspace_name,
|
||||
"RECOVERY COMMIT FROM `jj workspace update-stale`
|
||||
|
||||
This commit contains changes that were written to the working copy by an
|
||||
@ -1321,12 +1321,12 @@ to the current parents may contain changes from multiple commits.
|
||||
self.workspace.workspace_root()
|
||||
}
|
||||
|
||||
pub fn workspace_id(&self) -> &WorkspaceId {
|
||||
self.workspace.workspace_id()
|
||||
pub fn workspace_name(&self) -> &WorkspaceName {
|
||||
self.workspace.workspace_name()
|
||||
}
|
||||
|
||||
pub fn get_wc_commit_id(&self) -> Option<&CommitId> {
|
||||
self.repo().view().get_wc_commit_id(self.workspace_id())
|
||||
self.repo().view().get_wc_commit_id(self.workspace_name())
|
||||
}
|
||||
|
||||
pub fn working_copy_shared_with_git(&self) -> bool {
|
||||
@ -1870,10 +1870,10 @@ to the current parents may contain changes from multiple commits.
|
||||
&mut self,
|
||||
ui: &Ui,
|
||||
) -> Result<SnapshotStats, SnapshotWorkingCopyError> {
|
||||
let workspace_id = self.workspace_id().to_owned();
|
||||
let workspace_name = self.workspace_name().to_owned();
|
||||
let get_wc_commit = |repo: &ReadonlyRepo| -> Result<Option<_>, _> {
|
||||
repo.view()
|
||||
.get_wc_commit_id(&workspace_id)
|
||||
.get_wc_commit_id(&workspace_name)
|
||||
.map(|id| repo.store().get_commit(id))
|
||||
.transpose()
|
||||
.map_err(snapshot_command_error)
|
||||
@ -1969,7 +1969,7 @@ See https://jj-vcs.github.io/jj/latest/working-copy/#stale-working-copy \
|
||||
.write()
|
||||
.map_err(snapshot_command_error)?;
|
||||
mut_repo
|
||||
.set_wc_commit(workspace_id, commit.id().clone())
|
||||
.set_wc_commit(workspace_name, commit.id().clone())
|
||||
.map_err(snapshot_command_error)?;
|
||||
|
||||
// Rebase descendants
|
||||
@ -2092,19 +2092,19 @@ See https://jj-vcs.github.io/jj/latest/working-copy/#stale-working-copy \
|
||||
writeln!(ui.status(), "Rebased {num_rebased} descendant commits")?;
|
||||
}
|
||||
|
||||
for (workspace_id, wc_commit_id) in &tx.repo().view().wc_commit_ids().clone() {
|
||||
for (name, wc_commit_id) in &tx.repo().view().wc_commit_ids().clone() {
|
||||
if self
|
||||
.env
|
||||
.find_immutable_commit(tx.repo(), [wc_commit_id])?
|
||||
.is_some()
|
||||
{
|
||||
let wc_commit = tx.repo().store().get_commit(wc_commit_id)?;
|
||||
tx.repo_mut().check_out(workspace_id.clone(), &wc_commit)?;
|
||||
tx.repo_mut().check_out(name.clone(), &wc_commit)?;
|
||||
writeln!(
|
||||
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_symbol()
|
||||
"The working-copy commit in workspace '{name}' became immutable, so a new \
|
||||
commit has been created on top of it.",
|
||||
name = name.as_symbol()
|
||||
)?;
|
||||
}
|
||||
}
|
||||
@ -2113,13 +2113,13 @@ See https://jj-vcs.github.io/jj/latest/working-copy/#stale-working-copy \
|
||||
|
||||
let maybe_old_wc_commit = old_repo
|
||||
.view()
|
||||
.get_wc_commit_id(self.workspace_id())
|
||||
.get_wc_commit_id(self.workspace_name())
|
||||
.map(|commit_id| tx.base_repo().store().get_commit(commit_id))
|
||||
.transpose()?;
|
||||
let maybe_new_wc_commit = tx
|
||||
.repo()
|
||||
.view()
|
||||
.get_wc_commit_id(self.workspace_id())
|
||||
.get_wc_commit_id(self.workspace_name())
|
||||
.map(|commit_id| tx.repo().store().get_commit(commit_id))
|
||||
.transpose()?;
|
||||
|
||||
@ -2429,15 +2429,15 @@ impl WorkspaceCommandTransaction<'_> {
|
||||
}
|
||||
|
||||
pub fn check_out(&mut self, commit: &Commit) -> Result<Commit, CheckOutCommitError> {
|
||||
let workspace_id = self.helper.workspace_id().to_owned();
|
||||
let name = self.helper.workspace_name().to_owned();
|
||||
self.id_prefix_context.take(); // invalidate
|
||||
self.tx.repo_mut().check_out(workspace_id, commit)
|
||||
self.tx.repo_mut().check_out(name, commit)
|
||||
}
|
||||
|
||||
pub fn edit(&mut self, commit: &Commit) -> Result<(), EditCommitError> {
|
||||
let workspace_id = self.helper.workspace_id().to_owned();
|
||||
let name = self.helper.workspace_name().to_owned();
|
||||
self.id_prefix_context.take(); // invalidate
|
||||
self.tx.repo_mut().edit(workspace_id, commit)
|
||||
self.tx.repo_mut().edit(name, commit)
|
||||
}
|
||||
|
||||
pub fn format_commit_summary(&self, commit: &Commit) -> String {
|
||||
|
@ -143,8 +143,8 @@ new working-copy commit.
|
||||
commit_builder.set_description(description);
|
||||
let new_commit = commit_builder.write(tx.repo_mut())?;
|
||||
|
||||
let workspace_ids = tx.repo().view().workspaces_for_wc_commit_id(commit.id());
|
||||
if !workspace_ids.is_empty() {
|
||||
let workspace_names = tx.repo().view().workspaces_for_wc_commit_id(commit.id());
|
||||
if !workspace_names.is_empty() {
|
||||
let new_wc_commit = tx
|
||||
.repo_mut()
|
||||
.new_commit(vec![new_commit.id().clone()], commit.tree_id().clone())
|
||||
@ -153,8 +153,8 @@ new working-copy commit.
|
||||
// Does nothing if there's no bookmarks to advance.
|
||||
tx.advance_bookmarks(advanceable_bookmarks, new_commit.id());
|
||||
|
||||
for workspace_id in workspace_ids {
|
||||
tx.repo_mut().edit(workspace_id, &new_wc_commit).unwrap();
|
||||
for name in workspace_names {
|
||||
tx.repo_mut().edit(name, &new_wc_commit).unwrap();
|
||||
}
|
||||
}
|
||||
tx.finish(ui, format!("commit {}", commit.id().hex()))?;
|
||||
|
@ -826,13 +826,13 @@ fn find_bookmarks_targeted_by_revisions<'a>(
|
||||
let mut revision_commit_ids = HashSet::new();
|
||||
if use_default_revset {
|
||||
// remote_bookmarks(remote=<remote>)..@
|
||||
let workspace_id = workspace_command.workspace_id();
|
||||
let workspace_name = workspace_command.workspace_name();
|
||||
let expression = RevsetExpression::remote_bookmarks(
|
||||
StringPattern::everything(),
|
||||
StringPattern::exact(remote),
|
||||
None,
|
||||
)
|
||||
.range(&RevsetExpression::working_copy(workspace_id.to_owned()))
|
||||
.range(&RevsetExpression::working_copy(workspace_name.to_owned()))
|
||||
.intersection(&RevsetExpression::bookmarks(StringPattern::everything()));
|
||||
let mut commit_ids = workspace_command
|
||||
.attach_revset_evaluator(expression)
|
||||
|
@ -231,9 +231,9 @@ pub(crate) fn cmd_split(
|
||||
})?;
|
||||
// Move the working copy commit (@) to the second commit for any workspaces
|
||||
// where the target commit is the working copy commit.
|
||||
for (workspace_id, working_copy_commit) in tx.base_repo().clone().view().wc_commit_ids() {
|
||||
for (name, working_copy_commit) in tx.base_repo().clone().view().wc_commit_ids() {
|
||||
if working_copy_commit == target.commit.id() {
|
||||
tx.repo_mut().edit(workspace_id.clone(), &second_commit)?;
|
||||
tx.repo_mut().edit(name.clone(), &second_commit)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::ref_name::WorkspaceNameBuf;
|
||||
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<WorkspaceIdBuf>,
|
||||
name: Option<WorkspaceNameBuf>,
|
||||
/// 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,7 +88,7 @@ pub fn cmd_workspace_add(
|
||||
} else {
|
||||
fs::create_dir(&destination_path).context(&destination_path)?;
|
||||
}
|
||||
let workspace_id = if let Some(name) = &args.name {
|
||||
let workspace_name = if let Some(name) = &args.name {
|
||||
name.to_owned()
|
||||
} else {
|
||||
let file_name = destination_path.file_name().unwrap();
|
||||
@ -98,10 +98,10 @@ pub fn cmd_workspace_add(
|
||||
.into()
|
||||
};
|
||||
let repo = old_workspace_command.repo();
|
||||
if repo.view().get_wc_commit_id(&workspace_id).is_some() {
|
||||
if repo.view().get_wc_commit_id(&workspace_name).is_some() {
|
||||
return Err(user_error(format!(
|
||||
"Workspace named '{name}' already exists",
|
||||
name = workspace_id.as_symbol()
|
||||
name = workspace_name.as_symbol()
|
||||
)));
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ pub fn cmd_workspace_add(
|
||||
repo_path,
|
||||
repo,
|
||||
working_copy_factory,
|
||||
workspace_id.clone(),
|
||||
workspace_name.clone(),
|
||||
)?;
|
||||
writeln!(
|
||||
ui.status(),
|
||||
@ -128,7 +128,7 @@ pub fn cmd_workspace_add(
|
||||
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,
|
||||
name = workspace_id.as_symbol()
|
||||
name = workspace_name.as_symbol()
|
||||
)?;
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ pub fn cmd_workspace_add(
|
||||
if let Some(old_wc_commit_id) = tx
|
||||
.base_repo()
|
||||
.view()
|
||||
.get_wc_commit_id(old_workspace_command.workspace_id())
|
||||
.get_wc_commit_id(old_workspace_command.workspace_name())
|
||||
{
|
||||
tx.repo()
|
||||
.store()
|
||||
@ -194,7 +194,7 @@ pub fn cmd_workspace_add(
|
||||
ui,
|
||||
format!(
|
||||
"create initial working-copy commit in workspace {name}",
|
||||
name = workspace_id.as_symbol()
|
||||
name = workspace_name.as_symbol()
|
||||
),
|
||||
)?;
|
||||
Ok(())
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
use clap_complete::ArgValueCandidates;
|
||||
use itertools::Itertools as _;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::ref_name::WorkspaceNameBuf;
|
||||
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<WorkspaceIdBuf>,
|
||||
workspaces: Vec<WorkspaceNameBuf>,
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
@ -44,7 +44,7 @@ pub fn cmd_workspace_forget(
|
||||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
|
||||
let wss = if args.workspaces.is_empty() {
|
||||
vec![workspace_command.workspace_id().to_owned()]
|
||||
vec![workspace_command.workspace_name().to_owned()]
|
||||
} else {
|
||||
args.workspaces.clone()
|
||||
};
|
||||
|
@ -33,8 +33,8 @@ pub fn cmd_workspace_list(
|
||||
let repo = workspace_command.repo();
|
||||
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_symbol())?;
|
||||
for (name, wc_commit_id) in repo.view().wc_commit_ids() {
|
||||
write!(formatter, "{}: ", name.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::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::ref_name::WorkspaceNameBuf;
|
||||
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: WorkspaceIdBuf,
|
||||
new_workspace_name: WorkspaceNameBuf,
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
@ -39,9 +39,9 @@ pub fn cmd_workspace_rename(
|
||||
|
||||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
|
||||
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 {
|
||||
let old_name = workspace_command.working_copy().workspace_name().to_owned();
|
||||
let new_name = &*args.new_workspace_name;
|
||||
if new_name == old_name {
|
||||
writeln!(ui.status(), "Nothing changed.")?;
|
||||
return Ok(());
|
||||
}
|
||||
@ -49,28 +49,26 @@ pub fn cmd_workspace_rename(
|
||||
if workspace_command
|
||||
.repo()
|
||||
.view()
|
||||
.get_wc_commit_id(&old_workspace_id)
|
||||
.get_wc_commit_id(&old_name)
|
||||
.is_none()
|
||||
{
|
||||
return Err(user_error(format!(
|
||||
"The current workspace '{}' is not tracked in the repo.",
|
||||
old_workspace_id.as_symbol()
|
||||
old_name.as_symbol()
|
||||
)));
|
||||
}
|
||||
|
||||
let mut tx = workspace_command.start_transaction().into_inner();
|
||||
let (mut locked_ws, _wc_commit) = workspace_command.start_working_copy_mutation()?;
|
||||
|
||||
locked_ws
|
||||
.locked_wc()
|
||||
.rename_workspace(new_workspace_id.to_owned());
|
||||
locked_ws.locked_wc().rename_workspace(new_name.to_owned());
|
||||
|
||||
tx.repo_mut()
|
||||
.rename_workspace(&old_workspace_id, new_workspace_id.to_owned())?;
|
||||
.rename_workspace(&old_name, new_name.to_owned())?;
|
||||
let repo = tx.commit(format!(
|
||||
"Renamed workspace '{old}' to '{new}'",
|
||||
old = old_workspace_id.as_symbol(),
|
||||
new = new_workspace_id.as_symbol()
|
||||
old = old_name.as_symbol(),
|
||||
new = new_name.as_symbol()
|
||||
))?;
|
||||
locked_ws.finish(repo.op_id().clone())?;
|
||||
|
||||
|
@ -45,8 +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::ref_name::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::ref_name::WorkspaceName;
|
||||
use jj_lib::ref_name::WorkspaceNameBuf;
|
||||
use jj_lib::repo::Repo;
|
||||
use jj_lib::repo_path::RepoPathBuf;
|
||||
use jj_lib::repo_path::RepoPathUiConverter;
|
||||
@ -103,12 +103,12 @@ pub trait CommitTemplateLanguageExtension {
|
||||
pub struct CommitTemplateLanguage<'repo> {
|
||||
repo: &'repo dyn Repo,
|
||||
path_converter: &'repo RepoPathUiConverter,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
workspace_name: WorkspaceNameBuf,
|
||||
// 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 ++ ")")`.
|
||||
// TODO: Maybe refactor context structs? RepoPathUiConverter and WorkspaceId
|
||||
// are contained in RevsetParseContext for example.
|
||||
// TODO: Maybe refactor context structs? RepoPathUiConverter and
|
||||
// WorkspaceName are contained in RevsetParseContext for example.
|
||||
revset_parse_context: RevsetParseContext<'repo>,
|
||||
id_prefix_context: &'repo IdPrefixContext,
|
||||
immutable_expression: Rc<UserRevsetExpression>,
|
||||
@ -125,7 +125,7 @@ impl<'repo> CommitTemplateLanguage<'repo> {
|
||||
pub fn new(
|
||||
repo: &'repo dyn Repo,
|
||||
path_converter: &'repo RepoPathUiConverter,
|
||||
workspace_id: &WorkspaceId,
|
||||
workspace_name: &WorkspaceName,
|
||||
revset_parse_context: RevsetParseContext<'repo>,
|
||||
id_prefix_context: &'repo IdPrefixContext,
|
||||
immutable_expression: Rc<UserRevsetExpression>,
|
||||
@ -145,7 +145,7 @@ impl<'repo> CommitTemplateLanguage<'repo> {
|
||||
CommitTemplateLanguage {
|
||||
repo,
|
||||
path_converter,
|
||||
workspace_id: workspace_id.to_owned(),
|
||||
workspace_name: workspace_name.to_owned(),
|
||||
revset_parse_context,
|
||||
id_prefix_context,
|
||||
immutable_expression,
|
||||
@ -342,8 +342,8 @@ impl<'repo> CommitTemplateLanguage<'repo> {
|
||||
self.repo
|
||||
}
|
||||
|
||||
pub fn workspace_id(&self) -> &WorkspaceId {
|
||||
&self.workspace_id
|
||||
pub fn workspace_name(&self) -> &WorkspaceName {
|
||||
&self.workspace_name
|
||||
}
|
||||
|
||||
pub fn keyword_cache(&self) -> &CommitKeywordCache<'repo> {
|
||||
@ -871,10 +871,9 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm
|
||||
|language, _diagnostics, _build_ctx, self_property, function| {
|
||||
function.expect_no_arguments()?;
|
||||
let repo = language.repo;
|
||||
let workspace_id = language.workspace_id.clone();
|
||||
let out_property = self_property.map(move |commit| {
|
||||
Some(commit.id()) == repo.view().get_wc_commit_id(&workspace_id)
|
||||
});
|
||||
let name = language.workspace_name.clone();
|
||||
let out_property = self_property
|
||||
.map(move |commit| Some(commit.id()) == repo.view().get_wc_commit_id(&name));
|
||||
Ok(L::wrap_boolean(out_property))
|
||||
},
|
||||
);
|
||||
@ -1068,9 +1067,9 @@ fn extract_working_copies(repo: &dyn Repo, commit: &Commit) -> String {
|
||||
return "".to_string();
|
||||
}
|
||||
let mut names = vec![];
|
||||
for (workspace_id, wc_commit_id) in wc_commit_ids {
|
||||
for (name, wc_commit_id) in wc_commit_ids {
|
||||
if wc_commit_id == commit.id() {
|
||||
names.push(format!("{}@", workspace_id.as_symbol()));
|
||||
names.push(format!("{}@", name.as_symbol()));
|
||||
}
|
||||
}
|
||||
names.join(" ")
|
||||
|
@ -269,7 +269,7 @@ change very frequently.
|
||||
|
||||
```rust
|
||||
// Before:
|
||||
pub wc_commit_ids: HashMap<WorkspaceIdBuf, CommitId>,
|
||||
pub wc_commit_ids: HashMap<WorkspaceNameBuf, CommitId>,
|
||||
|
||||
// After:
|
||||
pub struct WorkingCopyInfo {
|
||||
@ -277,7 +277,7 @@ pub struct WorkingCopyInfo {
|
||||
pub wc_patterns_id: WorkingCopyPatternsId,
|
||||
}
|
||||
...
|
||||
pub wc_info: HashMap<WorkspaceIdBuf, WorkingCopyInfo>,
|
||||
pub wc_info: HashMap<WorkspaceNameBuf, WorkingCopyInfo>,
|
||||
```
|
||||
|
||||
A View object with no stored working copy patterns will be modified at read
|
||||
|
@ -145,7 +145,7 @@ sparse; they simply track the full repo in most cases.
|
||||
|
||||
### WorkingCopy
|
||||
|
||||
The `WorkingCopy` type has a `TreeState` but also knows which `WorkspaceId` it
|
||||
The `WorkingCopy` type has a `TreeState` but also knows which `WorkspaceName` it
|
||||
has and at which operation it was most recently updated.
|
||||
|
||||
### Workspace
|
||||
|
@ -95,8 +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::ref_name::WorkspaceId;
|
||||
use crate::ref_name::WorkspaceIdBuf;
|
||||
use crate::ref_name::WorkspaceName;
|
||||
use crate::ref_name::WorkspaceNameBuf;
|
||||
use crate::repo_path::RepoPath;
|
||||
use crate::repo_path::RepoPathBuf;
|
||||
use crate::repo_path::RepoPathComponent;
|
||||
@ -1960,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: WorkspaceIdBuf,
|
||||
workspace_name: WorkspaceNameBuf,
|
||||
}
|
||||
|
||||
pub struct LocalWorkingCopy {
|
||||
@ -1980,8 +1980,8 @@ impl WorkingCopy for LocalWorkingCopy {
|
||||
Self::name()
|
||||
}
|
||||
|
||||
fn workspace_id(&self) -> &WorkspaceId {
|
||||
&self.checkout_state().workspace_id
|
||||
fn workspace_name(&self) -> &WorkspaceName {
|
||||
&self.checkout_state().workspace_name
|
||||
}
|
||||
|
||||
fn operation_id(&self) -> &OperationId {
|
||||
@ -2021,7 +2021,7 @@ impl WorkingCopy for LocalWorkingCopy {
|
||||
old_operation_id,
|
||||
old_tree_id,
|
||||
tree_state_dirty: false,
|
||||
new_workspace_id: None,
|
||||
new_workspace_name: None,
|
||||
}))
|
||||
}
|
||||
}
|
||||
@ -2039,11 +2039,11 @@ impl LocalWorkingCopy {
|
||||
working_copy_path: PathBuf,
|
||||
state_path: PathBuf,
|
||||
operation_id: OperationId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
workspace_name: WorkspaceNameBuf,
|
||||
) -> Result<LocalWorkingCopy, WorkingCopyStateError> {
|
||||
let proto = crate::protos::working_copy::Checkout {
|
||||
operation_id: operation_id.to_bytes(),
|
||||
workspace_id: workspace_id.into(),
|
||||
workspace_name: workspace_name.into(),
|
||||
};
|
||||
let mut file = OpenOptions::new()
|
||||
.create_new(true)
|
||||
@ -2102,12 +2102,12 @@ impl LocalWorkingCopy {
|
||||
let proto = crate::protos::working_copy::Checkout::decode(&*buf).unwrap();
|
||||
CheckoutState {
|
||||
operation_id: OperationId::new(proto.operation_id),
|
||||
workspace_id: if proto.workspace_id.is_empty() {
|
||||
workspace_name: if proto.workspace_name.is_empty() {
|
||||
// For compatibility with old working copies.
|
||||
// TODO: Delete in mid 2022 or so
|
||||
WorkspaceId::DEFAULT.to_owned()
|
||||
WorkspaceName::DEFAULT.to_owned()
|
||||
} else {
|
||||
proto.workspace_id.into()
|
||||
proto.workspace_name.into()
|
||||
},
|
||||
}
|
||||
})
|
||||
@ -2147,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().into(),
|
||||
workspace_name: self.workspace_name().into(),
|
||||
});
|
||||
}
|
||||
|
||||
@ -2187,14 +2187,14 @@ impl WorkingCopyFactory for LocalWorkingCopyFactory {
|
||||
working_copy_path: PathBuf,
|
||||
state_path: PathBuf,
|
||||
operation_id: OperationId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
workspace_name: WorkspaceNameBuf,
|
||||
) -> Result<Box<dyn WorkingCopy>, WorkingCopyStateError> {
|
||||
Ok(Box::new(LocalWorkingCopy::init(
|
||||
store,
|
||||
working_copy_path,
|
||||
state_path,
|
||||
operation_id,
|
||||
workspace_id,
|
||||
workspace_name,
|
||||
)?))
|
||||
}
|
||||
|
||||
@ -2221,7 +2221,7 @@ pub struct LockedLocalWorkingCopy {
|
||||
old_operation_id: OperationId,
|
||||
old_tree_id: MergedTreeId,
|
||||
tree_state_dirty: bool,
|
||||
new_workspace_id: Option<WorkspaceIdBuf>,
|
||||
new_workspace_name: Option<WorkspaceNameBuf>,
|
||||
}
|
||||
|
||||
impl LockedWorkingCopy for LockedLocalWorkingCopy {
|
||||
@ -2281,8 +2281,8 @@ impl LockedWorkingCopy for LockedLocalWorkingCopy {
|
||||
}
|
||||
}
|
||||
|
||||
fn rename_workspace(&mut self, new_workspace_id: WorkspaceIdBuf) {
|
||||
self.new_workspace_id = Some(new_workspace_id);
|
||||
fn rename_workspace(&mut self, new_name: WorkspaceNameBuf) {
|
||||
self.new_workspace_name = Some(new_name);
|
||||
}
|
||||
|
||||
fn reset(&mut self, commit: &Commit) -> Result<(), ResetError> {
|
||||
@ -2351,9 +2351,9 @@ impl LockedWorkingCopy for LockedLocalWorkingCopy {
|
||||
err: Box::new(err),
|
||||
})?;
|
||||
}
|
||||
if self.old_operation_id != operation_id || self.new_workspace_id.is_some() {
|
||||
if let Some(new_workspace_id) = self.new_workspace_id {
|
||||
self.wc.checkout_state_mut().workspace_id = new_workspace_id;
|
||||
if self.old_operation_id != operation_id || self.new_workspace_name.is_some() {
|
||||
if let Some(new_name) = self.new_workspace_name {
|
||||
self.wc.checkout_state_mut().workspace_name = new_name;
|
||||
}
|
||||
self.wc.checkout_state_mut().operation_id = operation_id;
|
||||
self.wc.save();
|
||||
|
@ -41,7 +41,7 @@ use crate::ref_name::RefNameBuf;
|
||||
use crate::ref_name::RemoteName;
|
||||
use crate::ref_name::RemoteNameBuf;
|
||||
use crate::ref_name::RemoteRefSymbol;
|
||||
use crate::ref_name::WorkspaceIdBuf;
|
||||
use crate::ref_name::WorkspaceNameBuf;
|
||||
|
||||
id_type!(pub ViewId { hex() });
|
||||
id_type!(pub OperationId { hex() });
|
||||
@ -259,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<WorkspaceIdBuf, CommitId>,
|
||||
pub wc_commit_ids: BTreeMap<WorkspaceNameBuf, CommitId>,
|
||||
}
|
||||
|
||||
impl View {
|
||||
|
@ -72,6 +72,6 @@ message Checkout {
|
||||
// working-copy commit 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;
|
||||
string workspace_name = 3;
|
||||
reserved 1;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ pub struct Checkout {
|
||||
/// 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.
|
||||
#[prost(string, tag = "3")]
|
||||
pub workspace_id: ::prost::alloc::string::String,
|
||||
pub workspace_name: ::prost::alloc::string::String,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
|
||||
#[repr(i32)]
|
||||
|
@ -94,9 +94,9 @@ pub struct RemoteName(str);
|
||||
///
|
||||
/// 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.
|
||||
// Eq, Hash, and Ord must be compatible with WorkspaceName.
|
||||
#[derive(Clone, ContentHash, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
pub struct WorkspaceIdBuf(String); // TODO: rename to WorkspaceNameBuf
|
||||
pub struct WorkspaceNameBuf(String);
|
||||
|
||||
/// Borrowed workspace name.
|
||||
///
|
||||
@ -104,7 +104,7 @@ pub struct WorkspaceIdBuf(String); // TODO: rename to WorkspaceNameBuf
|
||||
/// be considered an immutable `str`.
|
||||
#[derive(ContentHash, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, RefCastCustom)]
|
||||
#[repr(transparent)]
|
||||
pub struct WorkspaceId(str); // TODO: rename to WorkspaceName
|
||||
pub struct WorkspaceName(str);
|
||||
|
||||
macro_rules! impl_partial_eq {
|
||||
($borrowed_ty:ty, $lhs:ty, $rhs:ty) => {
|
||||
@ -300,7 +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_name_type!(WorkspaceNameBuf, WorkspaceName);
|
||||
|
||||
impl RefName {
|
||||
/// Constructs a remote symbol with this local name.
|
||||
@ -309,9 +309,9 @@ impl RefName {
|
||||
}
|
||||
}
|
||||
|
||||
impl WorkspaceId {
|
||||
impl WorkspaceName {
|
||||
/// Default workspace name.
|
||||
pub const DEFAULT: &WorkspaceId = WorkspaceId::new("default");
|
||||
pub const DEFAULT: &WorkspaceName = WorkspaceName::new("default");
|
||||
}
|
||||
|
||||
/// Symbol for displaying.
|
||||
|
@ -76,8 +76,8 @@ 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::ref_name::WorkspaceName;
|
||||
use crate::ref_name::WorkspaceNameBuf;
|
||||
use crate::refs::diff_named_ref_targets;
|
||||
use crate::refs::diff_named_remote_refs;
|
||||
use crate::refs::merge_ref_targets;
|
||||
@ -1124,13 +1124,13 @@ impl MutableRepo {
|
||||
.view()
|
||||
.wc_commit_ids()
|
||||
.iter()
|
||||
.filter_map(|(workspace_id, commit_id)| {
|
||||
.filter_map(|(name, commit_id)| {
|
||||
let change = rewrite_mapping.get_key_value(commit_id)?;
|
||||
Some((workspace_id.to_owned(), change))
|
||||
Some((name.to_owned(), change))
|
||||
})
|
||||
.collect_vec();
|
||||
let mut recreated_wc_commits: HashMap<&CommitId, Commit> = HashMap::new();
|
||||
for (workspace_id, (old_commit_id, new_commit_ids)) in changed_wc_commits {
|
||||
for (name, (old_commit_id, new_commit_ids)) in changed_wc_commits {
|
||||
let abandoned_old_commit = matches!(
|
||||
self.parent_mapping.get(old_commit_id),
|
||||
Some(Rewrite::Abandoned(_))
|
||||
@ -1152,7 +1152,7 @@ impl MutableRepo {
|
||||
recreated_wc_commits.insert(old_commit_id, commit.clone());
|
||||
commit
|
||||
};
|
||||
self.edit(workspace_id, &new_wc_commit).unwrap();
|
||||
self.edit(name, &new_wc_commit).unwrap();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -1353,61 +1353,56 @@ impl MutableRepo {
|
||||
|
||||
pub fn set_wc_commit(
|
||||
&mut self,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
name: WorkspaceNameBuf,
|
||||
commit_id: CommitId,
|
||||
) -> Result<(), RewriteRootCommit> {
|
||||
if &commit_id == self.store().root_commit_id() {
|
||||
return Err(RewriteRootCommit);
|
||||
}
|
||||
self.view_mut().set_wc_commit(workspace_id, commit_id);
|
||||
self.view_mut().set_wc_commit(name, commit_id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn remove_wc_commit(&mut self, workspace_id: &WorkspaceId) -> Result<(), EditCommitError> {
|
||||
self.maybe_abandon_wc_commit(workspace_id)?;
|
||||
self.view_mut().remove_wc_commit(workspace_id);
|
||||
pub fn remove_wc_commit(&mut self, name: &WorkspaceName) -> Result<(), EditCommitError> {
|
||||
self.maybe_abandon_wc_commit(name)?;
|
||||
self.view_mut().remove_wc_commit(name);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn rename_workspace(
|
||||
&mut self,
|
||||
old_workspace_id: &WorkspaceId,
|
||||
new_workspace_id: WorkspaceIdBuf,
|
||||
old_name: &WorkspaceName,
|
||||
new_name: WorkspaceNameBuf,
|
||||
) -> Result<(), RenameWorkspaceError> {
|
||||
self.view_mut()
|
||||
.rename_workspace(old_workspace_id, new_workspace_id)
|
||||
self.view_mut().rename_workspace(old_name, new_name)
|
||||
}
|
||||
|
||||
pub fn check_out(
|
||||
&mut self,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
name: WorkspaceNameBuf,
|
||||
commit: &Commit,
|
||||
) -> Result<Commit, CheckOutCommitError> {
|
||||
let wc_commit = self
|
||||
.new_commit(vec![commit.id().clone()], commit.tree_id().clone())
|
||||
.write()?;
|
||||
self.edit(workspace_id, &wc_commit)?;
|
||||
self.edit(name, &wc_commit)?;
|
||||
Ok(wc_commit)
|
||||
}
|
||||
|
||||
pub fn edit(
|
||||
&mut self,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
commit: &Commit,
|
||||
) -> Result<(), EditCommitError> {
|
||||
self.maybe_abandon_wc_commit(&workspace_id)?;
|
||||
pub fn edit(&mut self, name: WorkspaceNameBuf, commit: &Commit) -> Result<(), EditCommitError> {
|
||||
self.maybe_abandon_wc_commit(&name)?;
|
||||
self.add_head(commit)?;
|
||||
Ok(self.set_wc_commit(workspace_id, commit.id().clone())?)
|
||||
Ok(self.set_wc_commit(name, commit.id().clone())?)
|
||||
}
|
||||
|
||||
fn maybe_abandon_wc_commit(
|
||||
&mut self,
|
||||
workspace_id: &WorkspaceId,
|
||||
workspace_name: &WorkspaceName,
|
||||
) -> Result<(), EditCommitError> {
|
||||
let is_commit_referenced = |view: &View, commit_id: &CommitId| -> bool {
|
||||
view.wc_commit_ids()
|
||||
.iter()
|
||||
.filter(|&(ws_id, _)| ws_id != workspace_id)
|
||||
.filter(|&(name, _)| name != workspace_name)
|
||||
.map(|(_, wc_id)| wc_id)
|
||||
.chain(
|
||||
view.local_bookmarks()
|
||||
@ -1418,7 +1413,7 @@ impl MutableRepo {
|
||||
|
||||
let maybe_wc_commit_id = self
|
||||
.view
|
||||
.with_ref(|v| v.get_wc_commit_id(workspace_id).cloned());
|
||||
.with_ref(|v| v.get_wc_commit_id(workspace_name).cloned());
|
||||
if let Some(wc_commit_id) = maybe_wc_commit_id {
|
||||
let wc_commit = self
|
||||
.store()
|
||||
@ -1675,30 +1670,29 @@ impl MutableRepo {
|
||||
fn merge_view(&mut self, base: &View, other: &View) -> BackendResult<()> {
|
||||
// TODO: Use `diff_named_commit_ids` to simplify this.
|
||||
// Merge working-copy commits. If there's a conflict, we keep the self side.
|
||||
for (workspace_id, base_wc_commit) in base.wc_commit_ids() {
|
||||
let self_wc_commit = self.view().get_wc_commit_id(workspace_id);
|
||||
let other_wc_commit = other.get_wc_commit_id(workspace_id);
|
||||
for (name, base_wc_commit) in base.wc_commit_ids() {
|
||||
let self_wc_commit = self.view().get_wc_commit_id(name);
|
||||
let other_wc_commit = other.get_wc_commit_id(name);
|
||||
if other_wc_commit == Some(base_wc_commit) || other_wc_commit == self_wc_commit {
|
||||
// The other side didn't change or both sides changed in the
|
||||
// same way.
|
||||
} else if let Some(other_wc_commit) = other_wc_commit {
|
||||
if self_wc_commit == Some(base_wc_commit) {
|
||||
self.view_mut()
|
||||
.set_wc_commit(workspace_id.clone(), other_wc_commit.clone());
|
||||
.set_wc_commit(name.clone(), other_wc_commit.clone());
|
||||
}
|
||||
} else {
|
||||
// The other side removed the workspace. We want to remove it even if the self
|
||||
// side changed the working-copy commit.
|
||||
self.view_mut().remove_wc_commit(workspace_id);
|
||||
self.view_mut().remove_wc_commit(name);
|
||||
}
|
||||
}
|
||||
for (workspace_id, other_wc_commit) in other.wc_commit_ids() {
|
||||
if self.view().get_wc_commit_id(workspace_id).is_none()
|
||||
&& base.get_wc_commit_id(workspace_id).is_none()
|
||||
for (name, other_wc_commit) in other.wc_commit_ids() {
|
||||
if self.view().get_wc_commit_id(name).is_none() && base.get_wc_commit_id(name).is_none()
|
||||
{
|
||||
// The other side added the workspace.
|
||||
self.view_mut()
|
||||
.set_wc_commit(workspace_id.clone(), other_wc_commit.clone());
|
||||
.set_wc_commit(name.clone(), other_wc_commit.clone());
|
||||
}
|
||||
}
|
||||
let base_heads = base.heads().iter().cloned().collect_vec();
|
||||
|
@ -47,8 +47,8 @@ use crate::op_store::RemoteRefState;
|
||||
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::ref_name::WorkspaceName;
|
||||
use crate::ref_name::WorkspaceNameBuf;
|
||||
use crate::repo::ReadonlyRepo;
|
||||
use crate::repo::Repo;
|
||||
use crate::repo::RepoLoaderError;
|
||||
@ -80,7 +80,7 @@ pub enum RevsetResolutionError {
|
||||
candidates: Vec<String>,
|
||||
},
|
||||
#[error("Workspace `{}` doesn't have a working-copy commit", name.as_symbol())]
|
||||
WorkspaceMissingWorkingCopy { name: WorkspaceIdBuf },
|
||||
WorkspaceMissingWorkingCopy { name: WorkspaceNameBuf },
|
||||
#[error("An empty string is not a valid revision")]
|
||||
EmptyString,
|
||||
#[error("Commit ID prefix `{0}` is ambiguous")]
|
||||
@ -129,7 +129,7 @@ pub enum RevsetModifier {
|
||||
/// Symbol or function to be resolved to `CommitId`s.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum RevsetCommitRef {
|
||||
WorkingCopy(WorkspaceIdBuf),
|
||||
WorkingCopy(WorkspaceNameBuf),
|
||||
WorkingCopies,
|
||||
Symbol(String),
|
||||
RemoteSymbol(RemoteRefSymbolBuf),
|
||||
@ -323,8 +323,8 @@ 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: WorkspaceIdBuf) -> Rc<Self> {
|
||||
Rc::new(Self::CommitRef(RevsetCommitRef::WorkingCopy(workspace_id)))
|
||||
pub fn working_copy(name: WorkspaceNameBuf) -> Rc<Self> {
|
||||
Rc::new(Self::CommitRef(RevsetCommitRef::WorkingCopy(name)))
|
||||
}
|
||||
|
||||
pub fn working_copies() -> Rc<Self> {
|
||||
@ -1061,7 +1061,9 @@ pub fn lower_expression(
|
||||
node.span,
|
||||
)
|
||||
})?;
|
||||
Ok(RevsetExpression::working_copy(ctx.workspace_id.to_owned()))
|
||||
Ok(RevsetExpression::working_copy(
|
||||
ctx.workspace_name.to_owned(),
|
||||
))
|
||||
}
|
||||
ExpressionKind::DagRangeAll => Ok(RevsetExpression::all()),
|
||||
ExpressionKind::RangeAll => {
|
||||
@ -2094,13 +2096,11 @@ fn resolve_commit_ref(
|
||||
RevsetCommitRef::Symbol(symbol) => symbol_resolver.resolve_symbol(repo, symbol),
|
||||
RevsetCommitRef::RemoteSymbol(symbol) => resolve_remote_bookmark(repo, symbol.as_ref())
|
||||
.ok_or_else(|| make_no_such_symbol_error(repo, symbol.to_string())),
|
||||
RevsetCommitRef::WorkingCopy(workspace_id) => {
|
||||
if let Some(commit_id) = repo.view().get_wc_commit_id(workspace_id) {
|
||||
RevsetCommitRef::WorkingCopy(name) => {
|
||||
if let Some(commit_id) = repo.view().get_wc_commit_id(name) {
|
||||
Ok(vec![commit_id.clone()])
|
||||
} else {
|
||||
Err(RevsetResolutionError::WorkspaceMissingWorkingCopy {
|
||||
name: workspace_id.clone(),
|
||||
})
|
||||
Err(RevsetResolutionError::WorkspaceMissingWorkingCopy { name: name.clone() })
|
||||
}
|
||||
}
|
||||
RevsetCommitRef::WorkingCopies => {
|
||||
@ -2621,7 +2621,7 @@ impl<'a> LoweringContext<'a> {
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct RevsetWorkspaceContext<'a> {
|
||||
pub path_converter: &'a RepoPathUiConverter,
|
||||
pub workspace_id: &'a WorkspaceId,
|
||||
pub workspace_name: &'a WorkspaceName,
|
||||
}
|
||||
|
||||
/// Formats a string as symbol by quoting and escaping it if necessary.
|
||||
@ -2663,9 +2663,9 @@ mod tests {
|
||||
|
||||
fn parse_with_workspace(
|
||||
revset_str: &str,
|
||||
workspace_id: &WorkspaceId,
|
||||
workspace_name: &WorkspaceName,
|
||||
) -> Result<Rc<UserRevsetExpression>, RevsetParseError> {
|
||||
parse_with_aliases_and_workspace(revset_str, [] as [(&str, &str); 0], workspace_id)
|
||||
parse_with_aliases_and_workspace(revset_str, [] as [(&str, &str); 0], workspace_name)
|
||||
}
|
||||
|
||||
fn parse_with_aliases(
|
||||
@ -2690,16 +2690,16 @@ mod tests {
|
||||
fn parse_with_aliases_and_workspace(
|
||||
revset_str: &str,
|
||||
aliases: impl IntoIterator<Item = (impl AsRef<str>, impl Into<String>)>,
|
||||
workspace_id: &WorkspaceId,
|
||||
workspace_name: &WorkspaceName,
|
||||
) -> Result<Rc<UserRevsetExpression>, RevsetParseError> {
|
||||
// Set up pseudo context to resolve `workspace_id@` and `file(path)`
|
||||
// Set up pseudo context to resolve `workspace_name@` and `file(path)`
|
||||
let path_converter = RepoPathUiConverter::Fs {
|
||||
cwd: PathBuf::from("/"),
|
||||
base: PathBuf::from("/"),
|
||||
};
|
||||
let workspace_ctx = RevsetWorkspaceContext {
|
||||
path_converter: &path_converter,
|
||||
workspace_id,
|
||||
workspace_name,
|
||||
};
|
||||
let mut aliases_map = RevsetAliasesMap::new();
|
||||
for (decl, defn) in aliases {
|
||||
@ -2762,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.to_owned());
|
||||
let current_wc = UserRevsetExpression::working_copy(WorkspaceName::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(WorkspaceIdBuf("default")))"#);
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceNameBuf("default")))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
current_wc.heads(),
|
||||
@r#"Heads(CommitRef(WorkingCopy(WorkspaceIdBuf("default"))))"#);
|
||||
@r#"Heads(CommitRef(WorkingCopy(WorkspaceNameBuf("default"))))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
current_wc.roots(),
|
||||
@r#"Roots(CommitRef(WorkingCopy(WorkspaceIdBuf("default"))))"#);
|
||||
@r#"Roots(CommitRef(WorkingCopy(WorkspaceNameBuf("default"))))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
current_wc.parents(), @r#"
|
||||
Ancestors {
|
||||
heads: CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
heads: CommitRef(WorkingCopy(WorkspaceNameBuf("default"))),
|
||||
generation: 1..2,
|
||||
}
|
||||
"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
current_wc.ancestors(), @r#"
|
||||
Ancestors {
|
||||
heads: CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
heads: CommitRef(WorkingCopy(WorkspaceNameBuf("default"))),
|
||||
generation: 0..18446744073709551615,
|
||||
}
|
||||
"#);
|
||||
@ -2808,7 +2808,7 @@ mod tests {
|
||||
foo_symbol.dag_range_to(¤t_wc), @r#"
|
||||
DagRange {
|
||||
roots: CommitRef(Symbol("foo")),
|
||||
heads: CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
heads: CommitRef(WorkingCopy(WorkspaceNameBuf("default"))),
|
||||
}
|
||||
"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
@ -2822,7 +2822,7 @@ mod tests {
|
||||
foo_symbol.range(¤t_wc), @r#"
|
||||
Range {
|
||||
roots: CommitRef(Symbol("foo")),
|
||||
heads: CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
heads: CommitRef(WorkingCopy(WorkspaceNameBuf("default"))),
|
||||
generation: 0..18446744073709551615,
|
||||
}
|
||||
"#);
|
||||
@ -2833,7 +2833,7 @@ mod tests {
|
||||
foo_symbol.union(¤t_wc), @r#"
|
||||
Union(
|
||||
CommitRef(Symbol("foo")),
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceNameBuf("default"))),
|
||||
)
|
||||
"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
@ -2841,12 +2841,12 @@ mod tests {
|
||||
@"None");
|
||||
insta::assert_debug_snapshot!(
|
||||
RevsetExpression::union_all(&[current_wc.clone()]),
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceIdBuf("default")))"#);
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceNameBuf("default")))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
RevsetExpression::union_all(&[current_wc.clone(), foo_symbol.clone()]),
|
||||
@r#"
|
||||
Union(
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceNameBuf("default"))),
|
||||
CommitRef(Symbol("foo")),
|
||||
)
|
||||
"#);
|
||||
@ -2858,7 +2858,7 @@ mod tests {
|
||||
]),
|
||||
@r#"
|
||||
Union(
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceNameBuf("default"))),
|
||||
Union(
|
||||
CommitRef(Symbol("foo")),
|
||||
CommitRef(Symbol("bar")),
|
||||
@ -2875,7 +2875,7 @@ mod tests {
|
||||
@r#"
|
||||
Union(
|
||||
Union(
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceNameBuf("default"))),
|
||||
CommitRef(Symbol("foo")),
|
||||
),
|
||||
Union(
|
||||
@ -2888,14 +2888,14 @@ mod tests {
|
||||
foo_symbol.intersection(¤t_wc), @r#"
|
||||
Intersection(
|
||||
CommitRef(Symbol("foo")),
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceNameBuf("default"))),
|
||||
)
|
||||
"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
foo_symbol.minus(¤t_wc), @r#"
|
||||
Difference(
|
||||
CommitRef(Symbol("foo")),
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceNameBuf("default"))),
|
||||
)
|
||||
"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
@ -2903,12 +2903,12 @@ mod tests {
|
||||
@"None");
|
||||
insta::assert_debug_snapshot!(
|
||||
RevsetExpression::coalesce(&[current_wc.clone()]),
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceIdBuf("default")))"#);
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceNameBuf("default")))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
RevsetExpression::coalesce(&[current_wc.clone(), foo_symbol.clone()]),
|
||||
@r#"
|
||||
Coalesce(
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceNameBuf("default"))),
|
||||
CommitRef(Symbol("foo")),
|
||||
)
|
||||
"#);
|
||||
@ -2920,7 +2920,7 @@ mod tests {
|
||||
]),
|
||||
@r#"
|
||||
Coalesce(
|
||||
CommitRef(WorkingCopy(WorkspaceIdBuf("default"))),
|
||||
CommitRef(WorkingCopy(WorkspaceNameBuf("default"))),
|
||||
Coalesce(
|
||||
CommitRef(Symbol("foo")),
|
||||
CommitRef(Symbol("bar")),
|
||||
@ -2933,8 +2933,8 @@ mod tests {
|
||||
fn test_parse_revset() {
|
||||
let settings = insta_settings();
|
||||
let _guard = settings.bind_to_scope();
|
||||
let main_workspace_id = WorkspaceIdBuf::from("main");
|
||||
let other_workspace_id = WorkspaceIdBuf::from("other");
|
||||
let main_workspace_name = WorkspaceNameBuf::from("main");
|
||||
let other_workspace_name = WorkspaceNameBuf::from("other");
|
||||
|
||||
// Parse "@" (the current working copy)
|
||||
insta::assert_debug_snapshot!(
|
||||
@ -2942,13 +2942,13 @@ mod tests {
|
||||
@"WorkingCopyWithoutWorkspace");
|
||||
insta::assert_debug_snapshot!(
|
||||
parse("main@").unwrap(),
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceIdBuf("main")))"#);
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceNameBuf("main")))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
parse_with_workspace("@", &main_workspace_id).unwrap(),
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceIdBuf("main")))"#);
|
||||
parse_with_workspace("@", &main_workspace_name).unwrap(),
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceNameBuf("main")))"#);
|
||||
insta::assert_debug_snapshot!(
|
||||
parse_with_workspace("main@", &other_workspace_id).unwrap(),
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceIdBuf("main")))"#);
|
||||
parse_with_workspace("main@", &other_workspace_name).unwrap(),
|
||||
@r#"CommitRef(WorkingCopy(WorkspaceNameBuf("main")))"#);
|
||||
// "@" in function argument must be quoted
|
||||
insta::assert_debug_snapshot!(
|
||||
parse("author_name(foo@)").unwrap_err().kind(),
|
||||
@ -3216,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()", WorkspaceName::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)", WorkspaceName::DEFAULT).is_err());
|
||||
assert!(parse_with_workspace("file()", WorkspaceName::DEFAULT).is_err());
|
||||
insta::assert_debug_snapshot!(
|
||||
parse_with_workspace("files(foo)", WorkspaceId::DEFAULT).unwrap(),
|
||||
parse_with_workspace("files(foo)", WorkspaceName::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())", WorkspaceName::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")"#, WorkspaceName::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)", WorkspaceName::DEFAULT).unwrap(), @r#"
|
||||
Filter(
|
||||
File(
|
||||
UnionAll(
|
||||
@ -3382,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")], WorkspaceName::DEFAULT)
|
||||
.unwrap(),
|
||||
@r#"Filter(File(Pattern(PrefixPath("a"))))"#);
|
||||
|
||||
@ -3861,7 +3861,7 @@ mod tests {
|
||||
insta::assert_debug_snapshot!(
|
||||
optimize(parse_with_workspace(
|
||||
"committer_name(foo) & files(bar) & baz",
|
||||
WorkspaceId::DEFAULT).unwrap(),
|
||||
WorkspaceName::DEFAULT).unwrap(),
|
||||
), @r#"
|
||||
Intersection(
|
||||
Intersection(
|
||||
@ -3874,7 +3874,7 @@ mod tests {
|
||||
insta::assert_debug_snapshot!(
|
||||
optimize(parse_with_workspace(
|
||||
"committer_name(foo) & files(bar) & author_name(baz)",
|
||||
WorkspaceId::DEFAULT).unwrap(),
|
||||
WorkspaceName::DEFAULT).unwrap(),
|
||||
), @r#"
|
||||
Intersection(
|
||||
Intersection(
|
||||
@ -3887,7 +3887,7 @@ mod tests {
|
||||
insta::assert_debug_snapshot!(
|
||||
optimize(parse_with_workspace(
|
||||
"foo & files(bar) & baz",
|
||||
WorkspaceId::DEFAULT).unwrap(),
|
||||
WorkspaceName::DEFAULT).unwrap(),
|
||||
), @r#"
|
||||
Intersection(
|
||||
Intersection(
|
||||
|
@ -329,7 +329,7 @@ pub enum ExpressionKind<'i> {
|
||||
},
|
||||
/// `<name>@<remote>`
|
||||
RemoteSymbol(RemoteRefSymbolBuf),
|
||||
/// `<workspace_id>@`
|
||||
/// `<name>@`
|
||||
AtWorkspace(String),
|
||||
/// `@`
|
||||
AtCurrentWorkspace,
|
||||
@ -649,7 +649,7 @@ fn parse_primary_node(pair: Pair<Rule>) -> Result<ExpressionNode, RevsetParseErr
|
||||
Some(op) => {
|
||||
assert_eq!(op.as_rule(), Rule::at_op);
|
||||
match pairs.next() {
|
||||
// postfix "<workspace_id>@"
|
||||
// postfix "<name>@"
|
||||
None => ExpressionKind::AtWorkspace(name),
|
||||
// infix "<name>@<remote>"
|
||||
Some(second) => {
|
||||
|
@ -62,8 +62,8 @@ use crate::op_store::ViewId;
|
||||
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;
|
||||
use crate::ref_name::WorkspaceName;
|
||||
use crate::ref_name::WorkspaceNameBuf;
|
||||
|
||||
// BLAKE2b-512 hash length in bytes
|
||||
const OPERATION_ID_LENGTH: usize = 64;
|
||||
@ -480,10 +480,10 @@ fn view_to_proto(view: &View) -> crate::protos::op_store::View {
|
||||
let mut proto = crate::protos::op_store::View {
|
||||
..Default::default()
|
||||
};
|
||||
for (workspace_id, commit_id) in &view.wc_commit_ids {
|
||||
for (name, commit_id) in &view.wc_commit_ids {
|
||||
proto
|
||||
.wc_commit_ids
|
||||
.insert(workspace_id.into(), commit_id.to_bytes());
|
||||
.insert(name.into(), commit_id.to_bytes());
|
||||
}
|
||||
for head_id in &view.head_ids {
|
||||
proto.head_ids.push(head_id.to_bytes());
|
||||
@ -519,13 +519,13 @@ fn view_from_proto(proto: crate::protos::op_store::View) -> View {
|
||||
#[expect(deprecated)]
|
||||
if !proto.wc_commit_id.is_empty() {
|
||||
view.wc_commit_ids.insert(
|
||||
WorkspaceId::DEFAULT.to_owned(),
|
||||
WorkspaceName::DEFAULT.to_owned(),
|
||||
CommitId::new(proto.wc_commit_id),
|
||||
);
|
||||
}
|
||||
for (workspace_id, commit_id) in proto.wc_commit_ids {
|
||||
for (name, commit_id) in proto.wc_commit_ids {
|
||||
view.wc_commit_ids
|
||||
.insert(WorkspaceIdBuf::from(workspace_id), CommitId::new(commit_id));
|
||||
.insert(WorkspaceNameBuf::from(name), CommitId::new(commit_id));
|
||||
}
|
||||
for head_id_bytes in proto.head_ids {
|
||||
view.head_ids.insert(CommitId::new(head_id_bytes));
|
||||
@ -784,7 +784,7 @@ mod tests {
|
||||
},
|
||||
git_head: RefTarget::normal(CommitId::from_hex("fff111")),
|
||||
wc_commit_ids: btreemap! {
|
||||
WorkspaceId::DEFAULT.to_owned() => default_wc_commit_id,
|
||||
WorkspaceName::DEFAULT.to_owned() => default_wc_commit_id,
|
||||
"test".into() => test_wc_commit_id,
|
||||
},
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ 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::ref_name::WorkspaceName;
|
||||
use crate::ref_name::WorkspaceNameBuf;
|
||||
use crate::refs;
|
||||
use crate::refs::LocalAndRemoteRef;
|
||||
use crate::str_util::StringPattern;
|
||||
@ -51,22 +51,22 @@ impl View {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn wc_commit_ids(&self) -> &BTreeMap<WorkspaceIdBuf, CommitId> {
|
||||
pub fn wc_commit_ids(&self) -> &BTreeMap<WorkspaceNameBuf, CommitId> {
|
||||
&self.data.wc_commit_ids
|
||||
}
|
||||
|
||||
pub fn get_wc_commit_id(&self, workspace_id: &WorkspaceId) -> Option<&CommitId> {
|
||||
self.data.wc_commit_ids.get(workspace_id)
|
||||
pub fn get_wc_commit_id(&self, name: &WorkspaceName) -> Option<&CommitId> {
|
||||
self.data.wc_commit_ids.get(name)
|
||||
}
|
||||
|
||||
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 {
|
||||
pub fn workspaces_for_wc_commit_id(&self, commit_id: &CommitId) -> Vec<WorkspaceNameBuf> {
|
||||
let mut workspace_names = vec![];
|
||||
for (name, wc_commit_id) in &self.data.wc_commit_ids {
|
||||
if wc_commit_id == commit_id {
|
||||
workspaces_ids.push(workspace_id.clone());
|
||||
workspace_names.push(name.clone());
|
||||
}
|
||||
}
|
||||
workspaces_ids
|
||||
workspace_names
|
||||
}
|
||||
|
||||
pub fn is_wc_commit_id(&self, commit_id: &CommitId) -> bool {
|
||||
@ -94,34 +94,30 @@ impl View {
|
||||
&self.data.git_head
|
||||
}
|
||||
|
||||
pub fn set_wc_commit(&mut self, workspace_id: WorkspaceIdBuf, commit_id: CommitId) {
|
||||
self.data.wc_commit_ids.insert(workspace_id, commit_id);
|
||||
pub fn set_wc_commit(&mut self, name: WorkspaceNameBuf, commit_id: CommitId) {
|
||||
self.data.wc_commit_ids.insert(name, commit_id);
|
||||
}
|
||||
|
||||
pub fn remove_wc_commit(&mut self, workspace_id: &WorkspaceId) {
|
||||
self.data.wc_commit_ids.remove(workspace_id);
|
||||
pub fn remove_wc_commit(&mut self, name: &WorkspaceName) {
|
||||
self.data.wc_commit_ids.remove(name);
|
||||
}
|
||||
|
||||
pub fn rename_workspace(
|
||||
&mut self,
|
||||
old_workspace_id: &WorkspaceId,
|
||||
new_workspace_id: WorkspaceIdBuf,
|
||||
old_name: &WorkspaceName,
|
||||
new_name: WorkspaceNameBuf,
|
||||
) -> Result<(), RenameWorkspaceError> {
|
||||
if self.data.wc_commit_ids.contains_key(&new_workspace_id) {
|
||||
if self.data.wc_commit_ids.contains_key(&new_name) {
|
||||
return Err(RenameWorkspaceError::WorkspaceAlreadyExists {
|
||||
workspace_id: new_workspace_id.clone(),
|
||||
name: new_name.clone(),
|
||||
});
|
||||
}
|
||||
let wc_commit_id = self
|
||||
.data
|
||||
.wc_commit_ids
|
||||
.remove(old_workspace_id)
|
||||
.ok_or_else(|| RenameWorkspaceError::WorkspaceDoesNotExist {
|
||||
workspace_id: old_workspace_id.to_owned(),
|
||||
})?;
|
||||
self.data
|
||||
.wc_commit_ids
|
||||
.insert(new_workspace_id, wc_commit_id);
|
||||
let wc_commit_id = self.data.wc_commit_ids.remove(old_name).ok_or_else(|| {
|
||||
RenameWorkspaceError::WorkspaceDoesNotExist {
|
||||
name: old_name.to_owned(),
|
||||
}
|
||||
})?;
|
||||
self.data.wc_commit_ids.insert(new_name, wc_commit_id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -418,9 +414,9 @@ impl View {
|
||||
/// Error from attempts to rename a workspace
|
||||
#[derive(Debug, Error)]
|
||||
pub enum RenameWorkspaceError {
|
||||
#[error("Workspace {} not found", workspace_id.as_symbol())]
|
||||
WorkspaceDoesNotExist { workspace_id: WorkspaceIdBuf },
|
||||
#[error("Workspace {} not found", name.as_symbol())]
|
||||
WorkspaceDoesNotExist { name: WorkspaceNameBuf },
|
||||
|
||||
#[error("Workspace {} already exists", workspace_id.as_symbol())]
|
||||
WorkspaceAlreadyExists { workspace_id: WorkspaceIdBuf },
|
||||
#[error("Workspace {} already exists", name.as_symbol())]
|
||||
WorkspaceAlreadyExists { name: WorkspaceNameBuf },
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ use crate::op_heads_store::OpHeadsStoreError;
|
||||
use crate::op_store::OpStoreError;
|
||||
use crate::op_store::OperationId;
|
||||
use crate::operation::Operation;
|
||||
use crate::ref_name::WorkspaceId;
|
||||
use crate::ref_name::WorkspaceIdBuf;
|
||||
use crate::ref_name::WorkspaceName;
|
||||
use crate::ref_name::WorkspaceNameBuf;
|
||||
use crate::repo::ReadonlyRepo;
|
||||
use crate::repo::Repo as _;
|
||||
use crate::repo::RewriteRootCommit;
|
||||
@ -58,8 +58,8 @@ pub trait WorkingCopy: Send {
|
||||
/// implementation when loading a working copy.
|
||||
fn name(&self) -> &str;
|
||||
|
||||
/// The working copy's workspace ID.
|
||||
fn workspace_id(&self) -> &WorkspaceId;
|
||||
/// The working copy's workspace name (or identifier.)
|
||||
fn workspace_name(&self) -> &WorkspaceName;
|
||||
|
||||
/// The operation this working copy was most recently updated to.
|
||||
fn operation_id(&self) -> &OperationId;
|
||||
@ -87,7 +87,7 @@ pub trait WorkingCopyFactory {
|
||||
working_copy_path: PathBuf,
|
||||
state_path: PathBuf,
|
||||
operation_id: OperationId,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
workspace_name: WorkspaceNameBuf,
|
||||
) -> Result<Box<dyn WorkingCopy>, WorkingCopyStateError>;
|
||||
|
||||
/// Load an existing working copy.
|
||||
@ -127,7 +127,7 @@ pub trait LockedWorkingCopy {
|
||||
) -> Result<CheckoutStats, CheckoutError>;
|
||||
|
||||
/// Update the workspace name.
|
||||
fn rename_workspace(&mut self, new_workspace_name: WorkspaceIdBuf);
|
||||
fn rename_workspace(&mut self, new_workspace_name: WorkspaceNameBuf);
|
||||
|
||||
/// Update to another commit without touching the files in the working copy.
|
||||
fn reset(&mut self, commit: &Commit) -> Result<(), ResetError>;
|
||||
@ -428,14 +428,14 @@ pub enum RecoverWorkspaceError {
|
||||
RewriteRootCommit(#[from] RewriteRootCommit),
|
||||
/// Working copy commit is missing.
|
||||
#[error(r#""{}" doesn't have a working-copy commit"#, .0.as_symbol())]
|
||||
WorkspaceMissingWorkingCopy(WorkspaceIdBuf),
|
||||
WorkspaceMissingWorkingCopy(WorkspaceNameBuf),
|
||||
}
|
||||
|
||||
/// 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: WorkspaceIdBuf,
|
||||
workspace_name: WorkspaceNameBuf,
|
||||
description: &str,
|
||||
) -> Result<(Arc<ReadonlyRepo>, Commit), RecoverWorkspaceError> {
|
||||
let mut tx = repo.start_transaction();
|
||||
@ -443,14 +443,16 @@ pub fn create_and_check_out_recovery_commit(
|
||||
|
||||
let commit_id = repo
|
||||
.view()
|
||||
.get_wc_commit_id(&workspace_id)
|
||||
.ok_or_else(|| RecoverWorkspaceError::WorkspaceMissingWorkingCopy(workspace_id.clone()))?;
|
||||
.get_wc_commit_id(&workspace_name)
|
||||
.ok_or_else(|| {
|
||||
RecoverWorkspaceError::WorkspaceMissingWorkingCopy(workspace_name.clone())
|
||||
})?;
|
||||
let commit = repo.store().get_commit(commit_id)?;
|
||||
let new_commit = repo_mut
|
||||
.new_commit(vec![commit_id.clone()], commit.tree_id().clone())
|
||||
.set_description(description)
|
||||
.write()?;
|
||||
repo_mut.set_wc_commit(workspace_id, new_commit.id().clone())?;
|
||||
repo_mut.set_wc_commit(workspace_name, new_commit.id().clone())?;
|
||||
|
||||
let repo = tx.commit("recovery commit")?;
|
||||
locked_wc.recover(&new_commit)?;
|
||||
|
@ -34,8 +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::ref_name::WorkspaceId;
|
||||
use crate::ref_name::WorkspaceIdBuf;
|
||||
use crate::ref_name::WorkspaceName;
|
||||
use crate::ref_name::WorkspaceNameBuf;
|
||||
use crate::repo::read_store_type;
|
||||
use crate::repo::BackendInitializer;
|
||||
use crate::repo::CheckOutCommitError;
|
||||
@ -129,22 +129,22 @@ fn init_working_copy(
|
||||
workspace_root: &Path,
|
||||
jj_dir: &Path,
|
||||
working_copy_factory: &dyn WorkingCopyFactory,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
workspace_name: WorkspaceNameBuf,
|
||||
) -> 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)?;
|
||||
|
||||
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_symbol()))?;
|
||||
.check_out(workspace_name.clone(), &repo.store().root_commit())?;
|
||||
let repo = tx.commit(format!("add workspace '{}'", workspace_name.as_symbol()))?;
|
||||
|
||||
let working_copy = working_copy_factory.init_working_copy(
|
||||
repo.store().clone(),
|
||||
workspace_root.to_path_buf(),
|
||||
working_copy_state_path.clone(),
|
||||
repo.op_id().clone(),
|
||||
workspace_id,
|
||||
workspace_name,
|
||||
)?;
|
||||
let working_copy_type_path = working_copy_state_path.join("type");
|
||||
fs::write(&working_copy_type_path, working_copy.name()).context(&working_copy_type_path)?;
|
||||
@ -288,7 +288,7 @@ impl Workspace {
|
||||
index_store_initializer: &IndexStoreInitializer,
|
||||
submodule_store_initializer: &SubmoduleStoreInitializer,
|
||||
working_copy_factory: &dyn WorkingCopyFactory,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
workspace_name: WorkspaceNameBuf,
|
||||
) -> Result<(Self, Arc<ReadonlyRepo>), WorkspaceInitError> {
|
||||
let jj_dir = create_jj_dir(workspace_root)?;
|
||||
(|| {
|
||||
@ -314,7 +314,7 @@ impl Workspace {
|
||||
workspace_root,
|
||||
&jj_dir,
|
||||
working_copy_factory,
|
||||
workspace_id,
|
||||
workspace_name,
|
||||
)?;
|
||||
let repo_loader = repo.loader().clone();
|
||||
let workspace = Workspace::new(workspace_root, repo_dir, working_copy, repo_loader)?;
|
||||
@ -341,7 +341,7 @@ impl Workspace {
|
||||
ReadonlyRepo::default_index_store_initializer(),
|
||||
ReadonlyRepo::default_submodule_store_initializer(),
|
||||
&*default_working_copy_factory(),
|
||||
WorkspaceId::DEFAULT.to_owned(),
|
||||
WorkspaceName::DEFAULT.to_owned(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -350,7 +350,7 @@ impl Workspace {
|
||||
repo_path: &Path,
|
||||
repo: &Arc<ReadonlyRepo>,
|
||||
working_copy_factory: &dyn WorkingCopyFactory,
|
||||
workspace_id: WorkspaceIdBuf,
|
||||
workspace_name: WorkspaceNameBuf,
|
||||
) -> Result<(Self, Arc<ReadonlyRepo>), WorkspaceInitError> {
|
||||
let jj_dir = create_jj_dir(workspace_root)?;
|
||||
|
||||
@ -371,7 +371,7 @@ impl Workspace {
|
||||
workspace_root,
|
||||
&jj_dir,
|
||||
working_copy_factory,
|
||||
workspace_id,
|
||||
workspace_name,
|
||||
)?;
|
||||
let workspace = Workspace::new(
|
||||
workspace_root,
|
||||
@ -397,8 +397,8 @@ impl Workspace {
|
||||
&self.workspace_root
|
||||
}
|
||||
|
||||
pub fn workspace_id(&self) -> &WorkspaceId {
|
||||
self.working_copy.workspace_id()
|
||||
pub fn workspace_name(&self) -> &WorkspaceName {
|
||||
self.working_copy.workspace_name()
|
||||
}
|
||||
|
||||
pub fn repo_path(&self) -> &Path {
|
||||
|
@ -17,7 +17,7 @@ use std::path::PathBuf;
|
||||
|
||||
use jj_lib::config::StackedConfig;
|
||||
use jj_lib::git_backend::GitBackend;
|
||||
use jj_lib::ref_name::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceName;
|
||||
use jj_lib::repo::Repo as _;
|
||||
use jj_lib::settings::UserSettings;
|
||||
use jj_lib::workspace::Workspace;
|
||||
@ -145,7 +145,10 @@ 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(WorkspaceName::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());
|
||||
@ -160,7 +163,10 @@ 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(WorkspaceName::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::ref_name::WorkspaceId;
|
||||
use jj_lib::ref_name::WorkspaceName;
|
||||
use jj_lib::repo::ReadonlyRepo;
|
||||
use jj_lib::repo::Repo as _;
|
||||
use jj_lib::repo_path::RepoPath;
|
||||
@ -113,7 +113,10 @@ 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(WorkspaceName::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());
|
||||
|
@ -19,8 +19,8 @@ use jj_lib::op_store::RemoteRefState;
|
||||
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::ref_name::WorkspaceName;
|
||||
use jj_lib::ref_name::WorkspaceNameBuf;
|
||||
use jj_lib::repo::Repo as _;
|
||||
use jj_lib::rewrite::RebaseOptions;
|
||||
use maplit::hashset;
|
||||
@ -54,10 +54,10 @@ fn test_edit() {
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
tx.repo_mut().edit(ws_id.clone(), &wc_commit).unwrap();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
tx.repo_mut().edit(ws_name.clone(), &wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws_id), Some(wc_commit.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws_name), Some(wc_commit.id()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -71,16 +71,16 @@ fn test_checkout() {
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
let wc_commit = tx
|
||||
.repo_mut()
|
||||
.check_out(ws_id.clone(), &wc_commit_parent)
|
||||
.check_out(ws_name.clone(), &wc_commit_parent)
|
||||
.unwrap();
|
||||
assert_eq!(wc_commit.tree_id(), wc_commit_parent.tree_id());
|
||||
assert_eq!(wc_commit.parent_ids().len(), 1);
|
||||
assert_eq!(&wc_commit.parent_ids()[0], wc_commit_parent.id());
|
||||
let repo = tx.commit("test").unwrap();
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws_id), Some(wc_commit.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws_name), Some(wc_commit.id()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -93,14 +93,14 @@ 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.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_name.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let mut_repo = tx.repo_mut();
|
||||
let new_wc_commit = write_random_commit(mut_repo);
|
||||
mut_repo.edit(ws_id, &new_wc_commit).unwrap();
|
||||
mut_repo.edit(ws_name, &new_wc_commit).unwrap();
|
||||
mut_repo.rebase_descendants().unwrap();
|
||||
assert!(mut_repo.view().heads().contains(old_wc_commit.id()));
|
||||
}
|
||||
@ -121,14 +121,14 @@ fn test_edit_previous_empty() {
|
||||
)
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_name.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let mut_repo = tx.repo_mut();
|
||||
let new_wc_commit = write_random_commit(mut_repo);
|
||||
mut_repo.edit(ws_id, &new_wc_commit).unwrap();
|
||||
mut_repo.edit(ws_name, &new_wc_commit).unwrap();
|
||||
mut_repo.rebase_descendants().unwrap();
|
||||
assert!(!mut_repo.view().heads().contains(old_wc_commit.id()));
|
||||
}
|
||||
@ -158,14 +158,14 @@ fn test_edit_previous_empty_merge() {
|
||||
.set_tree_id(old_parent_tree.id())
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_name.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let mut_repo = tx.repo_mut();
|
||||
let new_wc_commit = write_random_commit(mut_repo);
|
||||
mut_repo.edit(ws_id, &new_wc_commit).unwrap();
|
||||
mut_repo.edit(ws_name, &new_wc_commit).unwrap();
|
||||
mut_repo.rebase_descendants().unwrap();
|
||||
assert!(!mut_repo.view().heads().contains(old_wc_commit.id()));
|
||||
}
|
||||
@ -187,14 +187,14 @@ fn test_edit_previous_empty_with_description() {
|
||||
.set_description("not empty")
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_name.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let mut_repo = tx.repo_mut();
|
||||
let new_wc_commit = write_random_commit(mut_repo);
|
||||
mut_repo.edit(ws_id, &new_wc_commit).unwrap();
|
||||
mut_repo.edit(ws_name, &new_wc_commit).unwrap();
|
||||
mut_repo.rebase_descendants().unwrap();
|
||||
assert!(mut_repo.view().heads().contains(old_wc_commit.id()));
|
||||
}
|
||||
@ -216,14 +216,14 @@ 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.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_name.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let mut_repo = tx.repo_mut();
|
||||
let new_wc_commit = write_random_commit(mut_repo);
|
||||
mut_repo.edit(ws_id, &new_wc_commit).unwrap();
|
||||
mut_repo.edit(ws_name, &new_wc_commit).unwrap();
|
||||
mut_repo.rebase_descendants().unwrap();
|
||||
assert!(mut_repo.view().heads().contains(old_wc_commit.id()));
|
||||
}
|
||||
@ -244,16 +244,18 @@ fn test_edit_previous_empty_with_other_workspace() {
|
||||
)
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let other_ws_id = WorkspaceIdBuf::from("other");
|
||||
mut_repo.edit(other_ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_name.clone(), &old_wc_commit).unwrap();
|
||||
let other_ws_name = WorkspaceNameBuf::from("other");
|
||||
mut_repo
|
||||
.edit(other_ws_name.clone(), &old_wc_commit)
|
||||
.unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let mut_repo = tx.repo_mut();
|
||||
let new_wc_commit = write_random_commit(mut_repo);
|
||||
mut_repo.edit(ws_id, &new_wc_commit).unwrap();
|
||||
mut_repo.edit(ws_name, &new_wc_commit).unwrap();
|
||||
mut_repo.rebase_descendants().unwrap();
|
||||
assert!(mut_repo.view().heads().contains(old_wc_commit.id()));
|
||||
}
|
||||
@ -281,14 +283,14 @@ fn test_edit_previous_empty_non_head() {
|
||||
)
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_name.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let mut_repo = tx.repo_mut();
|
||||
let new_wc_commit = write_random_commit(mut_repo);
|
||||
mut_repo.edit(ws_id, &new_wc_commit).unwrap();
|
||||
mut_repo.edit(ws_name, &new_wc_commit).unwrap();
|
||||
mut_repo.rebase_descendants().unwrap();
|
||||
assert_eq!(
|
||||
*mut_repo.view().heads(),
|
||||
@ -308,15 +310,10 @@ fn test_edit_initial() {
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let workspace_id = WorkspaceIdBuf::from("new-workspace");
|
||||
tx.repo_mut()
|
||||
.edit(workspace_id.clone(), &wc_commit)
|
||||
.unwrap();
|
||||
let ws_name = WorkspaceNameBuf::from("new-workspace");
|
||||
tx.repo_mut().edit(ws_name.clone(), &wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
assert_eq!(
|
||||
repo.view().get_wc_commit_id(&workspace_id),
|
||||
Some(wc_commit.id())
|
||||
);
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws_name), Some(wc_commit.id()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -333,10 +330,10 @@ fn test_edit_hidden_commit() {
|
||||
// in the view head ids.
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
tx.repo_mut().edit(ws_id.clone(), &wc_commit).unwrap();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
tx.repo_mut().edit(ws_name.clone(), &wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws_id), Some(wc_commit.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws_name), Some(wc_commit.id()));
|
||||
assert_eq!(*repo.view().heads(), hashset! {wc_commit.id().clone()});
|
||||
}
|
||||
|
||||
@ -477,9 +474,9 @@ 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.to_owned();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
mut_repo
|
||||
.set_wc_commit(ws_id.clone(), commit1.id().clone())
|
||||
.set_wc_commit(ws_name.clone(), commit1.id().clone())
|
||||
.unwrap();
|
||||
mut_repo.set_local_bookmark_target("main".as_ref(), RefTarget::normal(commit1.id().clone()));
|
||||
mut_repo.set_remote_bookmark(
|
||||
@ -495,7 +492,7 @@ fn test_has_changed() {
|
||||
|
||||
mut_repo.add_head(&commit1).unwrap();
|
||||
mut_repo
|
||||
.set_wc_commit(ws_id.clone(), commit1.id().clone())
|
||||
.set_wc_commit(ws_name.clone(), commit1.id().clone())
|
||||
.unwrap();
|
||||
mut_repo.set_local_bookmark_target("main".as_ref(), RefTarget::normal(commit1.id().clone()));
|
||||
mut_repo.set_remote_bookmark(
|
||||
@ -515,10 +512,12 @@ fn test_has_changed() {
|
||||
assert!(!mut_repo.has_changes());
|
||||
|
||||
mut_repo
|
||||
.set_wc_commit(ws_id.clone(), commit2.id().clone())
|
||||
.set_wc_commit(ws_name.clone(), commit2.id().clone())
|
||||
.unwrap();
|
||||
assert!(mut_repo.has_changes());
|
||||
mut_repo.set_wc_commit(ws_id, commit1.id().clone()).unwrap();
|
||||
mut_repo
|
||||
.set_wc_commit(ws_name, commit1.id().clone())
|
||||
.unwrap();
|
||||
assert!(!mut_repo.has_changes());
|
||||
|
||||
mut_repo.set_local_bookmark_target("main".as_ref(), RefTarget::normal(commit2.id().clone()));
|
||||
@ -638,13 +637,13 @@ 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.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_name.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let mut_repo = tx.repo_mut();
|
||||
mut_repo.remove_wc_commit(&ws_id).unwrap();
|
||||
mut_repo.remove_wc_commit(&ws_name).unwrap();
|
||||
mut_repo.rebase_descendants().unwrap();
|
||||
assert!(mut_repo.view().heads().contains(old_wc_commit.id()));
|
||||
}
|
||||
@ -665,13 +664,13 @@ fn test_remove_wc_commit_previous_discardable() {
|
||||
)
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
mut_repo.edit(ws_name.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let mut tx = repo.start_transaction();
|
||||
let mut_repo = tx.repo_mut();
|
||||
mut_repo.remove_wc_commit(&ws_id).unwrap();
|
||||
mut_repo.remove_wc_commit(&ws_name).unwrap();
|
||||
mut_repo.rebase_descendants().unwrap();
|
||||
assert!(!mut_repo.view().heads().contains(old_wc_commit.id()));
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ use jj_lib::op_store::RemoteRefState;
|
||||
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::ref_name::WorkspaceName;
|
||||
use jj_lib::ref_name::WorkspaceNameBuf;
|
||||
use jj_lib::repo::Repo;
|
||||
use jj_lib::repo_path::RepoPath;
|
||||
use jj_lib::repo_path::RepoPathUiConverter;
|
||||
@ -432,8 +432,8 @@ fn test_resolve_working_copy() {
|
||||
let commit1 = write_random_commit(mut_repo);
|
||||
let commit2 = write_random_commit(mut_repo);
|
||||
|
||||
let ws1 = WorkspaceIdBuf::from("ws1");
|
||||
let ws2 = WorkspaceIdBuf::from("ws2");
|
||||
let ws1 = WorkspaceNameBuf::from("ws1");
|
||||
let ws2 = WorkspaceNameBuf::from("ws2");
|
||||
|
||||
// Cannot resolve a working-copy commit for an unknown workspace
|
||||
assert_matches!(
|
||||
@ -463,8 +463,8 @@ fn test_resolve_working_copy() {
|
||||
mut_repo
|
||||
.set_wc_commit(ws2.clone(), commit2.id().clone())
|
||||
.unwrap();
|
||||
let resolve = |ws_id: WorkspaceIdBuf| -> Vec<CommitId> {
|
||||
RevsetExpression::working_copy(ws_id)
|
||||
let resolve = |name: WorkspaceNameBuf| -> Vec<CommitId> {
|
||||
RevsetExpression::working_copy(name)
|
||||
.resolve_user_expression(mut_repo, &FailingSymbolResolver)
|
||||
.unwrap()
|
||||
.evaluate(mut_repo)
|
||||
@ -474,7 +474,7 @@ fn test_resolve_working_copy() {
|
||||
.collect()
|
||||
};
|
||||
|
||||
// Can resolve "@" shorthand with a default workspace ID
|
||||
// Can resolve "@" shorthand with a default workspace name
|
||||
assert_eq!(resolve(ws1), vec![commit1.id().clone()]);
|
||||
// Can resolve an explicit checkout
|
||||
assert_eq!(resolve(ws2), vec![commit2.id().clone()]);
|
||||
@ -492,8 +492,8 @@ fn test_resolve_working_copies() {
|
||||
let commit2 = write_random_commit(mut_repo);
|
||||
|
||||
// Add some workspaces
|
||||
let ws1 = WorkspaceIdBuf::from("ws1");
|
||||
let ws2 = WorkspaceIdBuf::from("ws2");
|
||||
let ws1 = WorkspaceNameBuf::from("ws1");
|
||||
let ws2 = WorkspaceNameBuf::from("ws2");
|
||||
|
||||
// add one commit to each working copy
|
||||
mut_repo
|
||||
@ -793,9 +793,9 @@ fn test_resolve_symbol_tags() {
|
||||
);
|
||||
|
||||
// "@" (quoted) can be resolved, and root is a normal symbol.
|
||||
let ws_id = WorkspaceId::DEFAULT.to_owned();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
mut_repo
|
||||
.set_wc_commit(ws_id.clone(), commit1.id().clone())
|
||||
.set_wc_commit(ws_name.clone(), commit1.id().clone())
|
||||
.unwrap();
|
||||
mut_repo.set_tag_target("@".as_ref(), RefTarget::normal(commit2.id().clone()));
|
||||
mut_repo.set_tag_target("root".as_ref(), RefTarget::normal(commit3.id().clone()));
|
||||
@ -955,7 +955,7 @@ fn resolve_commit_ids_in_workspace(
|
||||
};
|
||||
let workspace_ctx = RevsetWorkspaceContext {
|
||||
path_converter: &path_converter,
|
||||
workspace_id: workspace.workspace_id(),
|
||||
workspace_name: workspace.workspace_name(),
|
||||
};
|
||||
let context = RevsetParseContext {
|
||||
aliases_map: &RevsetAliasesMap::default(),
|
||||
@ -1007,7 +1007,7 @@ fn test_evaluate_expression_root_and_checkout() {
|
||||
|
||||
// Can find the current working-copy commit
|
||||
mut_repo
|
||||
.set_wc_commit(WorkspaceId::DEFAULT.to_owned(), commit1.id().clone())
|
||||
.set_wc_commit(WorkspaceName::DEFAULT.to_owned(), commit1.id().clone())
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
resolve_commit_ids_in_workspace(mut_repo, "@", &test_workspace.workspace, None),
|
||||
@ -1159,7 +1159,7 @@ fn test_evaluate_expression_parents() {
|
||||
|
||||
// Can find parents of the current working-copy commit
|
||||
mut_repo
|
||||
.set_wc_commit(WorkspaceId::DEFAULT.to_owned(), commit2.id().clone())
|
||||
.set_wc_commit(WorkspaceName::DEFAULT.to_owned(), commit2.id().clone())
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
resolve_commit_ids_in_workspace(mut_repo, "@-", &test_workspace.workspace, None,),
|
||||
|
@ -24,8 +24,8 @@ use jj_lib::op_store::RemoteRefState;
|
||||
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::ref_name::WorkspaceName;
|
||||
use jj_lib::ref_name::WorkspaceNameBuf;
|
||||
use jj_lib::repo::Repo as _;
|
||||
use jj_lib::repo_path::RepoPath;
|
||||
use jj_lib::rewrite::rebase_commit_with_options;
|
||||
@ -1507,17 +1507,17 @@ fn test_rebase_descendants_update_checkout() {
|
||||
.set_parents(vec![commit_a.id().clone()])
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws1_id = WorkspaceIdBuf::from("ws1");
|
||||
let ws2_id = WorkspaceIdBuf::from("ws2");
|
||||
let ws3_id = WorkspaceIdBuf::from("ws3");
|
||||
let ws1_name = WorkspaceNameBuf::from("ws1");
|
||||
let ws2_name = WorkspaceNameBuf::from("ws2");
|
||||
let ws3_name = WorkspaceNameBuf::from("ws3");
|
||||
tx.repo_mut()
|
||||
.set_wc_commit(ws1_id.clone(), commit_b.id().clone())
|
||||
.set_wc_commit(ws1_name.clone(), commit_b.id().clone())
|
||||
.unwrap();
|
||||
tx.repo_mut()
|
||||
.set_wc_commit(ws2_id.clone(), commit_b.id().clone())
|
||||
.set_wc_commit(ws2_name.clone(), commit_b.id().clone())
|
||||
.unwrap();
|
||||
tx.repo_mut()
|
||||
.set_wc_commit(ws3_id.clone(), commit_a.id().clone())
|
||||
.set_wc_commit(ws3_name.clone(), commit_a.id().clone())
|
||||
.unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
@ -1533,9 +1533,9 @@ fn test_rebase_descendants_update_checkout() {
|
||||
|
||||
// Workspaces 1 and 2 had B checked out, so they get updated to C. Workspace 3
|
||||
// had A checked out, so it doesn't get updated.
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws1_id), Some(commit_c.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws2_id), Some(commit_c.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws3_id), Some(commit_a.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws1_name), Some(commit_c.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws2_name), Some(commit_c.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws3_name), Some(commit_a.id()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1555,17 +1555,17 @@ fn test_rebase_descendants_update_checkout_abandoned() {
|
||||
.set_parents(vec![commit_a.id().clone()])
|
||||
.write()
|
||||
.unwrap();
|
||||
let ws1_id = WorkspaceIdBuf::from("ws1");
|
||||
let ws2_id = WorkspaceIdBuf::from("ws2");
|
||||
let ws3_id = WorkspaceIdBuf::from("ws3");
|
||||
let ws1_name = WorkspaceNameBuf::from("ws1");
|
||||
let ws2_name = WorkspaceNameBuf::from("ws2");
|
||||
let ws3_name = WorkspaceNameBuf::from("ws3");
|
||||
tx.repo_mut()
|
||||
.set_wc_commit(ws1_id.clone(), commit_b.id().clone())
|
||||
.set_wc_commit(ws1_name.clone(), commit_b.id().clone())
|
||||
.unwrap();
|
||||
tx.repo_mut()
|
||||
.set_wc_commit(ws2_id.clone(), commit_b.id().clone())
|
||||
.set_wc_commit(ws2_name.clone(), commit_b.id().clone())
|
||||
.unwrap();
|
||||
tx.repo_mut()
|
||||
.set_wc_commit(ws3_id.clone(), commit_a.id().clone())
|
||||
.set_wc_commit(ws3_name.clone(), commit_a.id().clone())
|
||||
.unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
@ -1577,15 +1577,15 @@ fn test_rebase_descendants_update_checkout_abandoned() {
|
||||
// Workspaces 1 and 2 had B checked out, so they get updated to the same new
|
||||
// commit on top of C. Workspace 3 had A checked out, so it doesn't get updated.
|
||||
assert_eq!(
|
||||
repo.view().get_wc_commit_id(&ws1_id),
|
||||
repo.view().get_wc_commit_id(&ws2_id)
|
||||
repo.view().get_wc_commit_id(&ws1_name),
|
||||
repo.view().get_wc_commit_id(&ws2_name)
|
||||
);
|
||||
let checkout = repo
|
||||
.store()
|
||||
.get_commit(repo.view().get_wc_commit_id(&ws1_id).unwrap())
|
||||
.get_commit(repo.view().get_wc_commit_id(&ws1_name).unwrap())
|
||||
.unwrap();
|
||||
assert_eq!(checkout.parent_ids(), vec![commit_a.id().clone()]);
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws3_id), Some(commit_a.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws3_name), Some(commit_a.id()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1615,9 +1615,9 @@ 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.to_owned();
|
||||
let ws_name = WorkspaceName::DEFAULT.to_owned();
|
||||
tx.repo_mut()
|
||||
.set_wc_commit(workspace_id.clone(), commit_d.id().clone())
|
||||
.set_wc_commit(ws_name.clone(), commit_d.id().clone())
|
||||
.unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
@ -1626,7 +1626,7 @@ fn test_rebase_descendants_update_checkout_abandoned_merge() {
|
||||
tx.repo_mut().rebase_descendants().unwrap();
|
||||
let repo = tx.commit("test").unwrap();
|
||||
|
||||
let new_checkout_id = repo.view().get_wc_commit_id(&workspace_id).unwrap();
|
||||
let new_checkout_id = repo.view().get_wc_commit_id(&ws_name).unwrap();
|
||||
let checkout = repo.store().get_commit(new_checkout_id).unwrap();
|
||||
assert_eq!(
|
||||
checkout.parent_ids(),
|
||||
@ -1830,7 +1830,7 @@ fn test_rebase_abandoning_empty() {
|
||||
.write()
|
||||
.unwrap();
|
||||
|
||||
let workspace = WorkspaceIdBuf::from("ws");
|
||||
let workspace = WorkspaceNameBuf::from("ws");
|
||||
tx.repo_mut()
|
||||
.set_wc_commit(workspace.clone(), commit_e.id().clone())
|
||||
.unwrap();
|
||||
|
@ -21,7 +21,7 @@ use jj_lib::op_store::RemoteRefState;
|
||||
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::ref_name::WorkspaceNameBuf;
|
||||
use jj_lib::repo::Repo as _;
|
||||
use maplit::btreemap;
|
||||
use maplit::hashset;
|
||||
@ -139,76 +139,76 @@ 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 = 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");
|
||||
let ws1_name = WorkspaceNameBuf::from("ws1");
|
||||
let ws2_name = WorkspaceNameBuf::from("ws2");
|
||||
let ws3_name = WorkspaceNameBuf::from("ws3");
|
||||
let ws4_name = WorkspaceNameBuf::from("ws4");
|
||||
let ws5_name = WorkspaceNameBuf::from("ws5");
|
||||
let ws6_name = WorkspaceNameBuf::from("ws6");
|
||||
let ws7_name = WorkspaceNameBuf::from("ws7");
|
||||
initial_tx
|
||||
.repo_mut()
|
||||
.set_wc_commit(ws1_id.clone(), commit1.id().clone())
|
||||
.set_wc_commit(ws1_name.clone(), commit1.id().clone())
|
||||
.unwrap();
|
||||
initial_tx
|
||||
.repo_mut()
|
||||
.set_wc_commit(ws2_id.clone(), commit1.id().clone())
|
||||
.set_wc_commit(ws2_name.clone(), commit1.id().clone())
|
||||
.unwrap();
|
||||
initial_tx
|
||||
.repo_mut()
|
||||
.set_wc_commit(ws3_id.clone(), commit1.id().clone())
|
||||
.set_wc_commit(ws3_name.clone(), commit1.id().clone())
|
||||
.unwrap();
|
||||
initial_tx
|
||||
.repo_mut()
|
||||
.set_wc_commit(ws4_id.clone(), commit1.id().clone())
|
||||
.set_wc_commit(ws4_name.clone(), commit1.id().clone())
|
||||
.unwrap();
|
||||
initial_tx
|
||||
.repo_mut()
|
||||
.set_wc_commit(ws5_id.clone(), commit1.id().clone())
|
||||
.set_wc_commit(ws5_name.clone(), commit1.id().clone())
|
||||
.unwrap();
|
||||
let repo = initial_tx.commit("test").unwrap();
|
||||
|
||||
let mut tx1 = repo.start_transaction();
|
||||
tx1.repo_mut()
|
||||
.set_wc_commit(ws1_id.clone(), commit2.id().clone())
|
||||
.set_wc_commit(ws1_name.clone(), commit2.id().clone())
|
||||
.unwrap();
|
||||
tx1.repo_mut()
|
||||
.set_wc_commit(ws2_id.clone(), commit2.id().clone())
|
||||
.set_wc_commit(ws2_name.clone(), commit2.id().clone())
|
||||
.unwrap();
|
||||
tx1.repo_mut().remove_wc_commit(&ws4_id).unwrap();
|
||||
tx1.repo_mut().remove_wc_commit(&ws4_name).unwrap();
|
||||
tx1.repo_mut()
|
||||
.set_wc_commit(ws5_id.clone(), commit2.id().clone())
|
||||
.set_wc_commit(ws5_name.clone(), commit2.id().clone())
|
||||
.unwrap();
|
||||
tx1.repo_mut()
|
||||
.set_wc_commit(ws6_id.clone(), commit2.id().clone())
|
||||
.set_wc_commit(ws6_name.clone(), commit2.id().clone())
|
||||
.unwrap();
|
||||
|
||||
let mut tx2 = repo.start_transaction();
|
||||
tx2.repo_mut()
|
||||
.set_wc_commit(ws1_id.clone(), commit3.id().clone())
|
||||
.set_wc_commit(ws1_name.clone(), commit3.id().clone())
|
||||
.unwrap();
|
||||
tx2.repo_mut()
|
||||
.set_wc_commit(ws3_id.clone(), commit3.id().clone())
|
||||
.set_wc_commit(ws3_name.clone(), commit3.id().clone())
|
||||
.unwrap();
|
||||
tx2.repo_mut()
|
||||
.set_wc_commit(ws4_id.clone(), commit3.id().clone())
|
||||
.set_wc_commit(ws4_name.clone(), commit3.id().clone())
|
||||
.unwrap();
|
||||
tx2.repo_mut().remove_wc_commit(&ws5_id).unwrap();
|
||||
tx2.repo_mut().remove_wc_commit(&ws5_name).unwrap();
|
||||
tx2.repo_mut()
|
||||
.set_wc_commit(ws7_id.clone(), commit3.id().clone())
|
||||
.set_wc_commit(ws7_name.clone(), commit3.id().clone())
|
||||
.unwrap();
|
||||
|
||||
let repo = commit_transactions(vec![tx1, tx2]);
|
||||
|
||||
// We currently arbitrarily pick the first transaction's working-copy commit
|
||||
// (first by transaction end time).
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws1_id), Some(commit2.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws2_id), Some(commit2.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws3_id), Some(commit3.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws4_id), None);
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws5_id), None);
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws6_id), Some(commit2.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws7_id), Some(commit3.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws1_name), Some(commit2.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws2_name), Some(commit2.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws3_name), Some(commit3.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws4_name), None);
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws5_name), None);
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws6_name), Some(commit2.id()));
|
||||
assert_eq!(repo.view().get_wc_commit_id(&ws7_name), Some(commit3.id()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -15,7 +15,7 @@
|
||||
use std::thread;
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use jj_lib::ref_name::WorkspaceIdBuf;
|
||||
use jj_lib::ref_name::WorkspaceNameBuf;
|
||||
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 = WorkspaceIdBuf::from("ws2");
|
||||
let ws2_name = WorkspaceNameBuf::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(
|
||||
@ -56,10 +56,10 @@ fn test_init_additional_workspace() {
|
||||
test_workspace.repo_path(),
|
||||
&test_workspace.repo,
|
||||
&*default_working_copy_factory(),
|
||||
ws2_id.clone(),
|
||||
ws2_name.clone(),
|
||||
)
|
||||
.unwrap();
|
||||
let wc_commit_id = repo.view().get_wc_commit_id(&ws2_id);
|
||||
let wc_commit_id = repo.view().get_wc_commit_id(&ws2_name);
|
||||
assert_ne!(wc_commit_id, None);
|
||||
let wc_commit_id = wc_commit_id.unwrap();
|
||||
let wc_commit = repo.store().get_commit(wc_commit_id).unwrap();
|
||||
@ -67,7 +67,7 @@ fn test_init_additional_workspace() {
|
||||
wc_commit.parent_ids(),
|
||||
vec![repo.store().root_commit_id().clone()]
|
||||
);
|
||||
assert_eq!(ws2.workspace_id(), &ws2_id);
|
||||
assert_eq!(ws2.workspace_name(), &ws2_name);
|
||||
assert_eq!(
|
||||
*ws2.repo_path(),
|
||||
dunce::canonicalize(workspace.repo_path()).unwrap()
|
||||
@ -84,7 +84,7 @@ fn test_init_additional_workspace() {
|
||||
);
|
||||
assert!(same_workspace.is_ok());
|
||||
let same_workspace = same_workspace.unwrap();
|
||||
assert_eq!(same_workspace.workspace_id(), &ws2_id);
|
||||
assert_eq!(same_workspace.workspace_name(), &ws2_name);
|
||||
assert_eq!(
|
||||
*same_workspace.repo_path(),
|
||||
dunce::canonicalize(workspace.repo_path()).unwrap()
|
||||
|
Loading…
x
Reference in New Issue
Block a user