cleanup: update more "checkout" to "working-copy commit" and similar

I've preferred "working-copy commit" over "checkout" for a while
because I think it's clearer, but there were lots of places still
using "checkout". I've left "checkout" in places where it refers to
the action of updating the working copy or the working-copy commit.
This commit is contained in:
Martin von Zweigbergk 2023-01-25 08:29:15 -08:00 committed by Waleed Khan
parent 37ba17589d
commit 10725c095f
13 changed files with 91 additions and 89 deletions

View file

@ -46,7 +46,7 @@ message Checkout {
// The operation at which the working copy was updated.
bytes operation_id = 2;
// An identifier for this workspace. It is used for looking up the current
// checkout in the repo view. Currently a human-readable name.
// 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;

View file

@ -37,7 +37,7 @@ pub struct Checkout {
#[prost(bytes = "vec", tag = "2")]
pub operation_id: ::prost::alloc::vec::Vec<u8>,
/// An identifier for this workspace. It is used for looking up the current
/// checkout in the repo view. Currently a human-readable name.
/// 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.
#[prost(string, tag = "3")]

View file

@ -783,7 +783,7 @@ impl MutableRepo {
&& wc_commit.description().is_empty()
&& self.view().heads().contains(wc_commit.id())
{
// Abandon the checkout we're leaving if it's empty and a head commit
// Abandon the working-copy commit we're leaving if it's empty and a head commit
self.record_abandoned_commit(wc_commit_id);
}
}
@ -950,31 +950,31 @@ impl MutableRepo {
}
fn merge_view(&mut self, base: &View, other: &View) {
// Merge checkouts. If there's a conflict, we keep the self side.
for (workspace_id, base_checkout) in base.wc_commit_ids() {
let self_checkout = self.view().get_wc_commit_id(workspace_id);
let other_checkout = other.get_wc_commit_id(workspace_id);
if other_checkout == Some(base_checkout) || other_checkout == self_checkout {
// 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);
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_checkout) = other_checkout {
if self_checkout == Some(base_checkout) {
} 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_checkout.clone());
.set_wc_commit(workspace_id.clone(), other_wc_commit.clone());
}
} else {
// The other side removed the workspace. We want to remove it even if the self
// side changed the checkout.
// side changed the working-copy commit.
self.view_mut().remove_wc_commit(workspace_id);
}
}
for (workspace_id, other_checkout) in other.wc_commit_ids() {
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()
{
// The other side added the workspace.
self.view_mut()
.set_wc_commit(workspace_id.clone(), other_checkout.clone());
.set_wc_commit(workspace_id.clone(), other_wc_commit.clone());
}
}

View file

@ -297,7 +297,7 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
new_commit_ids: Vec<CommitId>,
edit: bool,
) -> Result<(), BackendError> {
// We arbitrarily pick a new checkout among the candidates.
// We arbitrarily pick a new working-copy commit among the candidates.
self.update_wc_commits(&old_commit_id, &new_commit_ids[0], edit)?;
if let Some(branch_names) = self.branches.get(&old_commit_id).cloned() {

View file

@ -293,9 +293,9 @@ pub enum SnapshotError {
#[derive(Debug, Error)]
pub enum CheckoutError {
// The current checkout was deleted, maybe by an overly aggressive GC that happened while
// the current process was running.
#[error("Current checkout not found: {source}")]
// The current working-copy commit was deleted, maybe by an overly aggressive GC that happened
// while the current process was running.
#[error("Current working-copy commit not found: {source}")]
SourceNotFound {
source: Box<dyn std::error::Error + Send + Sync>,
},
@ -333,9 +333,9 @@ fn suppress_file_exists_error(orig_err: CheckoutError) -> Result<(), CheckoutErr
#[derive(Debug, Error)]
pub enum ResetError {
// The current checkout was deleted, maybe by an overly aggressive GC that happened while
// the current process was running.
#[error("Current checkout not found: {source}")]
// The current working-copy commit was deleted, maybe by an overly aggressive GC that happened
// while the current process was running.
#[error("Current working-copy commit not found: {source}")]
SourceNotFound {
source: Box<dyn std::error::Error + Send + Sync>,
},
@ -1167,9 +1167,10 @@ impl WorkingCopy {
new_tree: &Tree,
) -> Result<CheckoutStats, CheckoutError> {
let mut locked_wc = self.start_mutation();
// Check if the current checkout has changed on disk compared to what the caller
// expected. It's safe to check out another commit regardless, but it's
// probably not what the caller wanted, so we let them know.
// Check if the current working-copy commit has changed on disk compared to what
// the caller expected. It's safe to check out another commit
// regardless, but it's probably not what the caller wanted, so we let
// them know.
if let Some(old_tree_id) = old_tree_id {
if *old_tree_id != locked_wc.old_tree_id {
locked_wc.discard();

View file

@ -63,11 +63,11 @@ fn test_commit_parallel(use_git: bool) {
thread.join().ok().unwrap();
}
let repo = repo.reload_at_head(&settings).unwrap();
// One commit per thread plus the commit from the initial checkout on top of the
// root commit
// One commit per thread plus the commit from the initial working-copy on top of
// the root commit
assert_eq!(repo.view().heads().len(), num_threads + 1);
// One addition operation for initializing the repo, one for checking out the
// One additional operation for initializing the repo, one for checking out the
// initial commit.
assert_eq!(count_non_merge_operations(&repo), num_threads + 2);
}
@ -98,8 +98,8 @@ fn test_commit_parallel_instances(use_git: bool) {
for thread in threads {
thread.join().ok().unwrap();
}
// One commit per thread plus the commit from the initial checkout on top of the
// root commit
// One commit per thread plus the commit from the initial working-copy commit on
// top of the root commit
let repo = ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &StoreFactories::default())
.unwrap();
assert_eq!(repo.view().heads().len(), num_threads + 1);

View file

@ -108,7 +108,7 @@ fn test_init_no_config_set(use_git: bool) {
#[test_case(false ; "local backend")]
#[test_case(true ; "git backend")]
fn test_init_checkout(use_git: bool) {
// Test the contents of the checkout after init
// Test the contents of the working-copy commit after init
let settings = testutils::user_settings();
let test_workspace = TestWorkspace::init(&settings, use_git);
let repo = &test_workspace.repo;

View file

@ -47,23 +47,20 @@ fn test_checkout(use_git: bool) {
let repo = &test_repo.repo;
let mut tx = repo.start_transaction(&settings, "test");
let requested_checkout = write_random_commit(tx.mut_repo(), &settings);
let wc_commit_parent = write_random_commit(tx.mut_repo(), &settings);
let repo = tx.commit();
let mut tx = repo.start_transaction(&settings, "test");
let ws_id = WorkspaceId::default();
let actual_checkout = tx
let wc_commit = tx
.mut_repo()
.check_out(ws_id.clone(), &settings, &requested_checkout)
.check_out(ws_id.clone(), &settings, &wc_commit_parent)
.unwrap();
assert_eq!(actual_checkout.tree_id(), requested_checkout.tree_id());
assert_eq!(actual_checkout.parents().len(), 1);
assert_eq!(actual_checkout.parents()[0].id(), requested_checkout.id());
assert_eq!(wc_commit.tree_id(), wc_commit_parent.tree_id());
assert_eq!(wc_commit.parents().len(), 1);
assert_eq!(wc_commit.parents()[0].id(), wc_commit_parent.id());
let repo = tx.commit();
assert_eq!(
repo.view().get_wc_commit_id(&ws_id),
Some(actual_checkout.id())
);
assert_eq!(repo.view().get_wc_commit_id(&ws_id), Some(wc_commit.id()));
}
#[test_case(false ; "local backend")]
@ -77,17 +74,17 @@ fn test_checkout_previous_not_empty(use_git: bool) {
let mut tx = repo.start_transaction(&settings, "test");
let mut_repo = tx.mut_repo();
let old_checkout = write_random_commit(mut_repo, &settings);
let old_wc_commit = write_random_commit(mut_repo, &settings);
let ws_id = WorkspaceId::default();
mut_repo.edit(ws_id.clone(), &old_checkout).unwrap();
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
let repo = tx.commit();
let mut tx = repo.start_transaction(&settings, "test");
let mut_repo = tx.mut_repo();
let new_checkout = write_random_commit(mut_repo, &settings);
mut_repo.edit(ws_id, &new_checkout).unwrap();
let new_wc_commit = write_random_commit(mut_repo, &settings);
mut_repo.edit(ws_id, &new_wc_commit).unwrap();
mut_repo.rebase_descendants(&settings).unwrap();
assert!(mut_repo.view().heads().contains(old_checkout.id()));
assert!(mut_repo.view().heads().contains(old_wc_commit.id()));
}
#[test_case(false ; "local backend")]
@ -101,7 +98,7 @@ fn test_checkout_previous_empty(use_git: bool) {
let mut tx = repo.start_transaction(&settings, "test");
let mut_repo = tx.mut_repo();
let old_checkout = mut_repo
let old_wc_commit = mut_repo
.new_commit(
&settings,
vec![repo.store().root_commit_id().clone()],
@ -110,7 +107,7 @@ fn test_checkout_previous_empty(use_git: bool) {
.write()
.unwrap();
let ws_id = WorkspaceId::default();
mut_repo.edit(ws_id.clone(), &old_checkout).unwrap();
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
let repo = tx.commit();
let mut tx = repo.start_transaction(&settings, "test");
@ -118,7 +115,7 @@ fn test_checkout_previous_empty(use_git: bool) {
let new_wc_commit = write_random_commit(mut_repo, &settings);
mut_repo.edit(ws_id, &new_wc_commit).unwrap();
mut_repo.rebase_descendants(&settings).unwrap();
assert!(!mut_repo.view().heads().contains(old_checkout.id()));
assert!(!mut_repo.view().heads().contains(old_wc_commit.id()));
}
#[test_case(false ; "local backend")]
@ -132,7 +129,7 @@ fn test_checkout_previous_empty_with_description(use_git: bool) {
let mut tx = repo.start_transaction(&settings, "test");
let mut_repo = tx.mut_repo();
let old_checkout = mut_repo
let old_wc_commit = mut_repo
.new_commit(
&settings,
vec![repo.store().root_commit_id().clone()],
@ -142,15 +139,15 @@ fn test_checkout_previous_empty_with_description(use_git: bool) {
.write()
.unwrap();
let ws_id = WorkspaceId::default();
mut_repo.edit(ws_id.clone(), &old_checkout).unwrap();
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
let repo = tx.commit();
let mut tx = repo.start_transaction(&settings, "test");
let mut_repo = tx.mut_repo();
let new_checkout = write_random_commit(mut_repo, &settings);
mut_repo.edit(ws_id, &new_checkout).unwrap();
let new_wc_commit = write_random_commit(mut_repo, &settings);
mut_repo.edit(ws_id, &new_wc_commit).unwrap();
mut_repo.rebase_descendants(&settings).unwrap();
assert!(mut_repo.view().heads().contains(old_checkout.id()));
assert!(mut_repo.view().heads().contains(old_wc_commit.id()));
}
#[test_case(false ; "local backend")]
@ -164,7 +161,7 @@ fn test_checkout_previous_empty_non_head(use_git: bool) {
let mut tx = repo.start_transaction(&settings, "test");
let mut_repo = tx.mut_repo();
let old_checkout = mut_repo
let old_wc_commit = mut_repo
.new_commit(
&settings,
vec![repo.store().root_commit_id().clone()],
@ -175,46 +172,48 @@ fn test_checkout_previous_empty_non_head(use_git: bool) {
let old_child = mut_repo
.new_commit(
&settings,
vec![old_checkout.id().clone()],
old_checkout.tree_id().clone(),
vec![old_wc_commit.id().clone()],
old_wc_commit.tree_id().clone(),
)
.write()
.unwrap();
let ws_id = WorkspaceId::default();
mut_repo.edit(ws_id.clone(), &old_checkout).unwrap();
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
let repo = tx.commit();
let mut tx = repo.start_transaction(&settings, "test");
let mut_repo = tx.mut_repo();
let new_checkout = write_random_commit(mut_repo, &settings);
mut_repo.edit(ws_id, &new_checkout).unwrap();
let new_wc_commit = write_random_commit(mut_repo, &settings);
mut_repo.edit(ws_id, &new_wc_commit).unwrap();
mut_repo.rebase_descendants(&settings).unwrap();
assert_eq!(
*mut_repo.view().heads(),
hashset! {old_child.id().clone(), new_checkout.id().clone()}
hashset! {old_child.id().clone(), new_wc_commit.id().clone()}
);
}
#[test_case(false ; "local backend")]
#[test_case(true ; "git backend")]
fn test_edit_initial(use_git: bool) {
// Test that MutableRepo::edit() can be used on the initial checkout in a
// workspace
// Test that MutableRepo::edit() can be used on the initial working-copy commit
// in a workspace
let settings = testutils::user_settings();
let test_repo = TestRepo::init(use_git);
let repo = &test_repo.repo;
let mut tx = repo.start_transaction(&settings, "test");
let checkout = write_random_commit(tx.mut_repo(), &settings);
let wc_commit = write_random_commit(tx.mut_repo(), &settings);
let repo = tx.commit();
let mut tx = repo.start_transaction(&settings, "test");
let workspace_id = WorkspaceId::new("new-workspace".to_string());
tx.mut_repo().edit(workspace_id.clone(), &checkout).unwrap();
tx.mut_repo()
.edit(workspace_id.clone(), &wc_commit)
.unwrap();
let repo = tx.commit();
assert_eq!(
repo.view().get_wc_commit_id(&workspace_id),
Some(checkout.id())
Some(wc_commit.id())
);
}

View file

@ -514,7 +514,7 @@ fn test_evaluate_expression_root_and_checkout(use_git: bool) {
vec![root_commit.id().clone()]
);
// Can find the current checkout
// Can find the current working-copy commit
mut_repo
.set_wc_commit(WorkspaceId::default(), commit1.id().clone())
.unwrap();
@ -673,7 +673,7 @@ fn test_evaluate_expression_parents(use_git: bool) {
// The root commit has no parents
assert_eq!(resolve_commit_ids(mut_repo.as_repo_ref(), "root-"), vec![]);
// Can find parents of the current checkout
// Can find parents of the current working-copy commit
mut_repo
.set_wc_commit(WorkspaceId::default(), commit2.id().clone())
.unwrap();

View file

@ -223,8 +223,8 @@ fn test_merge_views_checkout() {
let repo = repo.reload_at_head(&settings).unwrap();
// We currently arbitrarily pick the first transaction's checkout (first by
// transaction end time).
// 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()));

View file

@ -617,7 +617,7 @@ fn cmd_git_push(
None => {
return Err(user_error("Nothing checked out in this workspace"));
}
Some(checkout) => {
Some(wc_commit) => {
fn find_branches_targeting<'a>(
view: &'a View,
target: &RefTarget,
@ -633,11 +633,11 @@ fn cmd_git_push(
// Search for branches targeting @
let mut branches = find_branches_targeting(
workspace_command.repo().view(),
&RefTarget::Normal(checkout.clone()),
&RefTarget::Normal(wc_commit.clone()),
);
if branches.is_empty() {
// Try @- instead if it has exactly one parent, such as after `jj squash`
let commit = workspace_command.repo().store().get_commit(checkout)?;
let commit = workspace_command.repo().store().get_commit(wc_commit)?;
if let [parent] = commit.parent_ids() {
branches = find_branches_targeting(
workspace_command.repo().view(),

View file

@ -1267,16 +1267,16 @@ fn cmd_status(
) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;
let repo = workspace_command.repo();
let maybe_checkout_id = repo
let maybe_wc_commit_id = repo
.view()
.get_wc_commit_id(workspace_command.workspace_id());
let maybe_checkout = maybe_checkout_id
let maybe_wc_commit = maybe_wc_commit_id
.map(|id| repo.store().get_commit(id))
.transpose()?;
ui.request_pager();
let mut formatter = ui.stdout_formatter();
let formatter = formatter.as_mut();
if let Some(wc_commit) = &maybe_checkout {
if let Some(wc_commit) = &maybe_wc_commit {
for parent in wc_commit.parents() {
formatter.write_str("Parent commit: ")?;
workspace_command.write_commit_summary(formatter, &parent)?;
@ -1335,7 +1335,7 @@ fn cmd_status(
)?;
}
if let Some(wc_commit) = &maybe_checkout {
if let Some(wc_commit) = &maybe_wc_commit {
let parent_tree = merge_commit_trees(repo.as_repo_ref(), &wc_commit.parents());
let tree = wc_commit.tree();
if tree.id() == parent_tree.id() {
@ -1409,7 +1409,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
workspace_command.parse_revset(args.revisions.as_deref().unwrap_or(&default_revset))?;
let repo = workspace_command.repo();
let workspace_id = workspace_command.workspace_id();
let checkout_id = repo.view().get_wc_commit_id(workspace_id);
let wc_commit_id = repo.view().get_wc_commit_id(workspace_id);
let matcher = workspace_command.matcher_from_values(&args.paths)?;
let revset = workspace_command.evaluate_revset(&revset_expression)?;
let revset = if !args.paths.is_empty() {
@ -1432,8 +1432,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
&template_string,
);
let format_commit_template = |commit: &Commit, formatter: &mut dyn Formatter| {
let is_checkout = Some(commit.id()) == checkout_id;
if is_checkout {
if Some(commit.id()) == wc_commit_id {
formatter.with_label("working_copy", |formatter| {
template.format(commit, formatter)
})
@ -1482,7 +1481,6 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
let mut buffer = vec![];
let commit_id = index_entry.commit_id();
let commit = store.get_commit(&commit_id)?;
let is_checkout = Some(&commit_id) == checkout_id;
format_commit_template(&commit, ui.new_formatter(&mut buffer).as_mut())?;
if !buffer.ends_with(b"\n") {
buffer.push(b'\n');
@ -1497,7 +1495,11 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
&diff_formats,
)?;
}
let node_symbol = if is_checkout { "@" } else { "o" };
let node_symbol = if Some(&commit_id) == wc_commit_id {
"@"
} else {
"o"
};
graph.add_node(
&index_entry.position(),
@ -1807,7 +1809,7 @@ fn cmd_commit(ui: &mut Ui, command: &CommandHelper, args: &CommitArgs) -> Result
.view()
.workspaces_for_wc_commit_id(commit.id());
if !workspace_ids.is_empty() {
let new_checkout = tx
let new_wc_commit = tx
.mut_repo()
.new_commit(
command.settings(),
@ -1816,7 +1818,7 @@ fn cmd_commit(ui: &mut Ui, command: &CommandHelper, args: &CommitArgs) -> Result
)
.write()?;
for workspace_id in workspace_ids {
tx.mut_repo().edit(workspace_id, &new_checkout).unwrap();
tx.mut_repo().edit(workspace_id, &new_wc_commit).unwrap();
}
}
tx.finish(ui)?;
@ -3032,14 +3034,14 @@ fn cmd_workspace_add(
));
// Check out a parent of the current workspace's working-copy commit, or the
// root if there is no working-copy commit in the current workspace.
let new_wc_commit = if let Some(old_checkout_id) = tx
let new_wc_commit = if let Some(old_wc_commit_id) = tx
.base_repo()
.view()
.get_wc_commit_id(old_workspace_command.workspace_id())
{
tx.base_repo()
.store()
.get_commit(old_checkout_id)?
.get_commit(old_wc_commit_id)?
.parents()[0]
.clone()
} else {
@ -3085,9 +3087,9 @@ fn cmd_workspace_list(
) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;
let repo = workspace_command.repo();
for (workspace_id, checkout_id) in repo.view().wc_commit_ids().iter().sorted() {
for (workspace_id, wc_commit_id) in repo.view().wc_commit_ids().iter().sorted() {
write!(ui, "{}: ", workspace_id.as_str())?;
let commit = repo.store().get_commit(checkout_id)?;
let commit = repo.store().get_commit(wc_commit_id)?;
workspace_command.write_commit_summary(ui.stdout_formatter().as_mut(), &commit)?;
writeln!(ui)?;
}

View file

@ -44,8 +44,8 @@ fn test_workspaces_add_second_workspace() {
Added 1 files, modified 0 files, removed 0 files
"###);
// Can see the checkout in each workspace in the log output. The "@" node in the
// graph indicates the current workspace's checkout.
// Can see the working-copy commit in each workspace in the log output. The "@"
// node in the graph indicates the current workspace's working-copy commit.
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###"
o 397eac932ad3c349b2659fd2eb035a4dd3da4193 second@
| @ e0e6d5672858dc9a57ec5b772b7c4f3270ed0223 default@