mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 10:07:28 +00:00
cleanup: rename some more variables from checkout_*
to ~wc_
This commit is contained in:
parent
5b5a85fe33
commit
3fc7b549ec
6 changed files with 72 additions and 77 deletions
|
@ -1400,27 +1400,27 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_revset_expression_building() {
|
||||
let checkout_symbol = RevsetExpression::symbol("@".to_string());
|
||||
let wc_symbol = RevsetExpression::symbol("@".to_string());
|
||||
let foo_symbol = RevsetExpression::symbol("foo".to_string());
|
||||
assert_eq!(
|
||||
checkout_symbol,
|
||||
wc_symbol,
|
||||
Rc::new(RevsetExpression::Symbol("@".to_string()))
|
||||
);
|
||||
assert_eq!(
|
||||
checkout_symbol.heads(),
|
||||
Rc::new(RevsetExpression::Heads(checkout_symbol.clone()))
|
||||
wc_symbol.heads(),
|
||||
Rc::new(RevsetExpression::Heads(wc_symbol.clone()))
|
||||
);
|
||||
assert_eq!(
|
||||
checkout_symbol.roots(),
|
||||
Rc::new(RevsetExpression::Roots(checkout_symbol.clone()))
|
||||
wc_symbol.roots(),
|
||||
Rc::new(RevsetExpression::Roots(wc_symbol.clone()))
|
||||
);
|
||||
assert_eq!(
|
||||
checkout_symbol.parents(),
|
||||
Rc::new(RevsetExpression::Parents(checkout_symbol.clone()))
|
||||
wc_symbol.parents(),
|
||||
Rc::new(RevsetExpression::Parents(wc_symbol.clone()))
|
||||
);
|
||||
assert_eq!(
|
||||
checkout_symbol.ancestors(),
|
||||
Rc::new(RevsetExpression::Ancestors(checkout_symbol.clone()))
|
||||
wc_symbol.ancestors(),
|
||||
Rc::new(RevsetExpression::Ancestors(wc_symbol.clone()))
|
||||
);
|
||||
assert_eq!(
|
||||
foo_symbol.children(),
|
||||
|
@ -1434,10 +1434,10 @@ mod tests {
|
|||
})
|
||||
);
|
||||
assert_eq!(
|
||||
foo_symbol.dag_range_to(&checkout_symbol),
|
||||
foo_symbol.dag_range_to(&wc_symbol),
|
||||
Rc::new(RevsetExpression::DagRange {
|
||||
roots: foo_symbol.clone(),
|
||||
heads: checkout_symbol.clone(),
|
||||
heads: wc_symbol.clone(),
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
|
@ -1448,10 +1448,10 @@ mod tests {
|
|||
})
|
||||
);
|
||||
assert_eq!(
|
||||
foo_symbol.range(&checkout_symbol),
|
||||
foo_symbol.range(&wc_symbol),
|
||||
Rc::new(RevsetExpression::Range {
|
||||
roots: foo_symbol.clone(),
|
||||
heads: checkout_symbol.clone()
|
||||
heads: wc_symbol.clone()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
|
@ -1483,35 +1483,32 @@ mod tests {
|
|||
})
|
||||
);
|
||||
assert_eq!(
|
||||
foo_symbol.union(&checkout_symbol),
|
||||
foo_symbol.union(&wc_symbol),
|
||||
Rc::new(RevsetExpression::Union(
|
||||
foo_symbol.clone(),
|
||||
checkout_symbol.clone()
|
||||
wc_symbol.clone()
|
||||
))
|
||||
);
|
||||
assert_eq!(
|
||||
foo_symbol.intersection(&checkout_symbol),
|
||||
foo_symbol.intersection(&wc_symbol),
|
||||
Rc::new(RevsetExpression::Intersection(
|
||||
foo_symbol.clone(),
|
||||
checkout_symbol.clone()
|
||||
wc_symbol.clone()
|
||||
))
|
||||
);
|
||||
assert_eq!(
|
||||
foo_symbol.minus(&checkout_symbol),
|
||||
Rc::new(RevsetExpression::Difference(
|
||||
foo_symbol,
|
||||
checkout_symbol.clone()
|
||||
))
|
||||
foo_symbol.minus(&wc_symbol),
|
||||
Rc::new(RevsetExpression::Difference(foo_symbol, wc_symbol.clone()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_revset() {
|
||||
let checkout_symbol = RevsetExpression::symbol("@".to_string());
|
||||
let wc_symbol = RevsetExpression::symbol("@".to_string());
|
||||
let foo_symbol = RevsetExpression::symbol("foo".to_string());
|
||||
let bar_symbol = RevsetExpression::symbol("bar".to_string());
|
||||
// Parse a single symbol (specifically the "checkout" symbol)
|
||||
assert_eq!(parse("@"), Ok(checkout_symbol.clone()));
|
||||
assert_eq!(parse("@"), Ok(wc_symbol.clone()));
|
||||
// Parse a single symbol
|
||||
assert_eq!(parse("foo"), Ok(foo_symbol.clone()));
|
||||
// Internal '.', '-', and '+' are allowed
|
||||
|
@ -1531,20 +1528,20 @@ mod tests {
|
|||
// Parse a quoted symbol
|
||||
assert_eq!(parse("\"foo\""), Ok(foo_symbol.clone()));
|
||||
// Parse the "parents" operator
|
||||
assert_eq!(parse("@-"), Ok(checkout_symbol.parents()));
|
||||
assert_eq!(parse("@-"), Ok(wc_symbol.parents()));
|
||||
// Parse the "children" operator
|
||||
assert_eq!(parse("@+"), Ok(checkout_symbol.children()));
|
||||
assert_eq!(parse("@+"), Ok(wc_symbol.children()));
|
||||
// Parse the "ancestors" operator
|
||||
assert_eq!(parse(":@"), Ok(checkout_symbol.ancestors()));
|
||||
assert_eq!(parse(":@"), Ok(wc_symbol.ancestors()));
|
||||
// Parse the "descendants" operator
|
||||
assert_eq!(parse("@:"), Ok(checkout_symbol.descendants()));
|
||||
assert_eq!(parse("@:"), Ok(wc_symbol.descendants()));
|
||||
// Parse the "dag range" operator
|
||||
assert_eq!(parse("foo:bar"), Ok(foo_symbol.dag_range_to(&bar_symbol)));
|
||||
// Parse the "range" prefix operator
|
||||
assert_eq!(parse("..@"), Ok(checkout_symbol.ancestors()));
|
||||
assert_eq!(parse("..@"), Ok(wc_symbol.ancestors()));
|
||||
assert_eq!(
|
||||
parse("@.."),
|
||||
Ok(checkout_symbol.range(&RevsetExpression::visible_heads()))
|
||||
Ok(wc_symbol.range(&RevsetExpression::visible_heads()))
|
||||
);
|
||||
assert_eq!(parse("foo..bar"), Ok(foo_symbol.range(&bar_symbol)));
|
||||
// Parse the "intersection" operator
|
||||
|
@ -1554,9 +1551,9 @@ mod tests {
|
|||
// Parse the "difference" operator
|
||||
assert_eq!(parse("foo ~ bar"), Ok(foo_symbol.minus(&bar_symbol)));
|
||||
// Parentheses are allowed before suffix operators
|
||||
assert_eq!(parse("(@)-"), Ok(checkout_symbol.parents()));
|
||||
assert_eq!(parse("(@)-"), Ok(wc_symbol.parents()));
|
||||
// Space is allowed around expressions
|
||||
assert_eq!(parse(" :@ "), Ok(checkout_symbol.ancestors()));
|
||||
assert_eq!(parse(" :@ "), Ok(wc_symbol.ancestors()));
|
||||
// Space is not allowed around prefix operators
|
||||
assert_matches!(parse(" : @ "), Err(RevsetParseError::SyntaxError(_)));
|
||||
// Incomplete parse
|
||||
|
@ -1605,13 +1602,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_parse_revset_function() {
|
||||
let checkout_symbol = RevsetExpression::symbol("@".to_string());
|
||||
assert_eq!(parse("parents(@)"), Ok(checkout_symbol.parents()));
|
||||
assert_eq!(parse("parents((@))"), Ok(checkout_symbol.parents()));
|
||||
assert_eq!(parse("parents(\"@\")"), Ok(checkout_symbol.parents()));
|
||||
let wc_symbol = RevsetExpression::symbol("@".to_string());
|
||||
assert_eq!(parse("parents(@)"), Ok(wc_symbol.parents()));
|
||||
assert_eq!(parse("parents((@))"), Ok(wc_symbol.parents()));
|
||||
assert_eq!(parse("parents(\"@\")"), Ok(wc_symbol.parents()));
|
||||
assert_eq!(
|
||||
parse("ancestors(parents(@))"),
|
||||
Ok(checkout_symbol.parents().ancestors())
|
||||
Ok(wc_symbol.parents().ancestors())
|
||||
);
|
||||
assert_matches!(parse("parents(@"), Err(RevsetParseError::SyntaxError(_)));
|
||||
assert_eq!(
|
||||
|
|
|
@ -345,7 +345,7 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
|
|||
}
|
||||
|
||||
let new_commit = self.mut_repo.store().get_commit(new_commit_id)?;
|
||||
let new_checkout_commit = if edit {
|
||||
let new_wc_commit = if edit {
|
||||
new_commit
|
||||
} else {
|
||||
CommitBuilder::for_open_commit(
|
||||
|
@ -356,7 +356,7 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
|
|||
.write_to_repo(self.mut_repo)
|
||||
};
|
||||
for workspace_id in workspaces_to_update.into_iter() {
|
||||
self.mut_repo.edit(workspace_id, &new_checkout_commit);
|
||||
self.mut_repo.edit(workspace_id, &new_wc_commit);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -387,8 +387,8 @@ mod tests {
|
|||
removes: vec![CommitId::from_hex("fff111")],
|
||||
adds: vec![CommitId::from_hex("fff222"), CommitId::from_hex("fff333")],
|
||||
};
|
||||
let default_checkout_id = CommitId::from_hex("abc111");
|
||||
let test_checkout_id = CommitId::from_hex("abc222");
|
||||
let default_wc_commit_id = CommitId::from_hex("abc111");
|
||||
let test_wc_commit_id = CommitId::from_hex("abc222");
|
||||
let view = View {
|
||||
head_ids: hashset! {head_id1, head_id2},
|
||||
public_head_ids: hashset! {public_head_id1, public_head_id2},
|
||||
|
@ -415,8 +415,8 @@ mod tests {
|
|||
},
|
||||
git_head: Some(CommitId::from_hex("fff111")),
|
||||
wc_commit_ids: hashmap! {
|
||||
WorkspaceId::default() => default_checkout_id,
|
||||
WorkspaceId::new("test".to_string()) => test_checkout_id,
|
||||
WorkspaceId::default() => default_wc_commit_id,
|
||||
WorkspaceId::new("test".to_string()) => test_wc_commit_id,
|
||||
},
|
||||
};
|
||||
let view_id = store.write_view(&view).unwrap();
|
||||
|
|
|
@ -48,12 +48,12 @@ fn test_root(use_git: bool) {
|
|||
let mut locked_wc = wc.start_mutation();
|
||||
let new_tree_id = locked_wc.snapshot(GitIgnoreFile::empty()).unwrap();
|
||||
locked_wc.discard();
|
||||
let checkout_id = repo
|
||||
let wc_commit_id = repo
|
||||
.view()
|
||||
.get_wc_commit_id(&WorkspaceId::default())
|
||||
.unwrap();
|
||||
let checkout_commit = repo.store().get_commit(checkout_id).unwrap();
|
||||
assert_eq!(&new_tree_id, checkout_commit.tree_id());
|
||||
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_tree_id());
|
||||
}
|
||||
|
||||
|
|
|
@ -405,9 +405,13 @@ impl WorkspaceCommandHelper {
|
|||
.peel_to_commit()
|
||||
.ok()
|
||||
.map(|commit| commit.id());
|
||||
if let Some(checkout_id) = mut_repo.view().get_wc_commit_id(&self.workspace_id()) {
|
||||
let first_parent_id =
|
||||
mut_repo.index().entry_by_id(checkout_id).unwrap().parents()[0].commit_id();
|
||||
if let Some(wc_commit_id) = mut_repo.view().get_wc_commit_id(&self.workspace_id()) {
|
||||
let first_parent_id = mut_repo
|
||||
.index()
|
||||
.entry_by_id(wc_commit_id)
|
||||
.unwrap()
|
||||
.parents()[0]
|
||||
.commit_id();
|
||||
if first_parent_id != *mut_repo.store().root_commit_id() {
|
||||
if let Some(current_git_commit_id) = current_git_commit_id {
|
||||
git_repo.set_head_detached(current_git_commit_id)?;
|
||||
|
@ -568,8 +572,8 @@ impl WorkspaceCommandHelper {
|
|||
pub fn commit_working_copy(&mut self, ui: &mut Ui) -> Result<(), CommandError> {
|
||||
let repo = self.repo.clone();
|
||||
let workspace_id = self.workspace_id();
|
||||
let checkout_id = match repo.view().get_wc_commit_id(&self.workspace_id()) {
|
||||
Some(checkout_id) => checkout_id.clone(),
|
||||
let wc_commit_id = match repo.view().get_wc_commit_id(&self.workspace_id()) {
|
||||
Some(wc_commit_id) => wc_commit_id.clone(),
|
||||
None => {
|
||||
// If the workspace has been deleted, it's unclear what to do, so we just skip
|
||||
// committing the working copy.
|
||||
|
@ -582,10 +586,10 @@ impl WorkspaceCommandHelper {
|
|||
// doesn't, but we'll need to reload the repo so the new commit is
|
||||
// in the index and view, and so we don't cause unnecessary
|
||||
// divergence.
|
||||
let checkout_commit = repo.store().get_commit(&checkout_id)?;
|
||||
let wc_commit = repo.store().get_commit(&wc_commit_id)?;
|
||||
let wc_tree_id = locked_wc.old_tree_id().clone();
|
||||
let mut wc_was_stale = false;
|
||||
if *checkout_commit.tree_id() != wc_tree_id {
|
||||
if *wc_commit.tree_id() != wc_tree_id {
|
||||
let wc_operation_data = self
|
||||
.repo
|
||||
.op_store()
|
||||
|
@ -619,15 +623,13 @@ impl WorkspaceCommandHelper {
|
|||
short_operation_hash(wc_operation.id()),
|
||||
short_operation_hash(repo_operation.id()),
|
||||
)?;
|
||||
locked_wc
|
||||
.check_out(&checkout_commit.tree())
|
||||
.map_err(|err| {
|
||||
CommandError::InternalError(format!(
|
||||
"Failed to check out commit {}: {}",
|
||||
checkout_commit.id().hex(),
|
||||
err
|
||||
))
|
||||
})?;
|
||||
locked_wc.check_out(&wc_commit.tree()).map_err(|err| {
|
||||
CommandError::InternalError(format!(
|
||||
"Failed to check out commit {}: {}",
|
||||
wc_commit.id().hex(),
|
||||
err
|
||||
))
|
||||
})?;
|
||||
wc_was_stale = true;
|
||||
} else {
|
||||
return Err(CommandError::InternalError(format!(
|
||||
|
@ -647,10 +649,10 @@ impl WorkspaceCommandHelper {
|
|||
}
|
||||
}
|
||||
let new_tree_id = locked_wc.snapshot(base_ignores)?;
|
||||
if new_tree_id != *checkout_commit.tree_id() {
|
||||
if new_tree_id != *wc_commit.tree_id() {
|
||||
let mut tx = self.repo.start_transaction("commit working copy");
|
||||
let mut_repo = tx.mut_repo();
|
||||
let commit = CommitBuilder::for_rewrite_from(&self.settings, &checkout_commit)
|
||||
let commit = CommitBuilder::for_rewrite_from(&self.settings, &wc_commit)
|
||||
.set_tree(new_tree_id)
|
||||
.write_to_repo(mut_repo);
|
||||
mut_repo.set_wc_commit(workspace_id, commit.id().clone());
|
||||
|
|
|
@ -1960,17 +1960,13 @@ fn cmd_status(
|
|||
let maybe_checkout = maybe_checkout_id
|
||||
.map(|id| repo.store().get_commit(id))
|
||||
.transpose()?;
|
||||
if let Some(checkout_commit) = &maybe_checkout {
|
||||
if let Some(wc_commit) = &maybe_checkout {
|
||||
ui.write("Parent commit: ")?;
|
||||
let workspace_id = workspace_command.workspace_id();
|
||||
ui.write_commit_summary(
|
||||
repo.as_repo_ref(),
|
||||
&workspace_id,
|
||||
&checkout_commit.parents()[0],
|
||||
)?;
|
||||
ui.write_commit_summary(repo.as_repo_ref(), &workspace_id, &wc_commit.parents()[0])?;
|
||||
ui.write("\n")?;
|
||||
ui.write("Working copy : ")?;
|
||||
ui.write_commit_summary(repo.as_repo_ref(), &workspace_id, checkout_commit)?;
|
||||
ui.write_commit_summary(repo.as_repo_ref(), &workspace_id, wc_commit)?;
|
||||
ui.write("\n")?;
|
||||
} else {
|
||||
ui.write("No working copy\n")?;
|
||||
|
@ -2024,9 +2020,9 @@ fn cmd_status(
|
|||
)?;
|
||||
}
|
||||
|
||||
if let Some(checkout_commit) = &maybe_checkout {
|
||||
let parent_tree = checkout_commit.parents()[0].tree();
|
||||
let tree = checkout_commit.tree();
|
||||
if let Some(wc_commit) = &maybe_checkout {
|
||||
let parent_tree = wc_commit.parents()[0].tree();
|
||||
let tree = wc_commit.tree();
|
||||
if tree.id() == parent_tree.id() {
|
||||
ui.write("The working copy is clean\n")?;
|
||||
} else {
|
||||
|
@ -3904,7 +3900,7 @@ fn cmd_workspace_add(
|
|||
.start_transaction(&format!("Initial checkout in workspace {}", &name));
|
||||
// Check out a parent of the checkout of the current workspace, or the root if
|
||||
// there is no checkout in the current workspace.
|
||||
let new_checkout_commit = if let Some(old_checkout_id) = new_workspace_command
|
||||
let new_wc_commit = if let Some(old_checkout_id) = new_workspace_command
|
||||
.repo()
|
||||
.view()
|
||||
.get_wc_commit_id(&old_workspace_command.workspace_id())
|
||||
|
@ -3921,7 +3917,7 @@ fn cmd_workspace_add(
|
|||
tx.mut_repo().check_out(
|
||||
new_workspace_command.workspace_id(),
|
||||
ui.settings(),
|
||||
&new_checkout_commit,
|
||||
&new_wc_commit,
|
||||
);
|
||||
new_workspace_command.finish_transaction(ui, tx)?;
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue