forked from mirrors/jj
op show: accept root operation by mapping empty parents to root
I'm thinking of adding an option to embed operation diffs in "op log", and "op log" shouldn't fail at the root operation. Let's make "op diff"/"show" also work for consistency.
This commit is contained in:
parent
e385653064
commit
ea8f543d5a
4 changed files with 11 additions and 14 deletions
|
@ -40,7 +40,6 @@ use crate::cli_util::short_change_hash;
|
||||||
use crate::cli_util::short_operation_hash;
|
use crate::cli_util::short_operation_hash;
|
||||||
use crate::cli_util::CommandHelper;
|
use crate::cli_util::CommandHelper;
|
||||||
use crate::cli_util::LogContentFormat;
|
use crate::cli_util::LogContentFormat;
|
||||||
use crate::command_error::user_error;
|
|
||||||
use crate::command_error::CommandError;
|
use crate::command_error::CommandError;
|
||||||
use crate::diff_util::DiffFormatArgs;
|
use crate::diff_util::DiffFormatArgs;
|
||||||
use crate::diff_util::DiffRenderer;
|
use crate::diff_util::DiffRenderer;
|
||||||
|
@ -93,9 +92,6 @@ pub fn cmd_op_diff(
|
||||||
} else {
|
} else {
|
||||||
to_op = workspace_command.resolve_single_op(args.operation.as_deref().unwrap_or("@"))?;
|
to_op = workspace_command.resolve_single_op(args.operation.as_deref().unwrap_or("@"))?;
|
||||||
let to_op_parents: Vec<_> = to_op.parents().try_collect()?;
|
let to_op_parents: Vec<_> = to_op.parents().try_collect()?;
|
||||||
if to_op_parents.is_empty() {
|
|
||||||
return Err(user_error("Cannot diff operation with no parents"));
|
|
||||||
}
|
|
||||||
from_op = repo_loader.merge_operations(command.settings(), to_op_parents, None)?;
|
from_op = repo_loader.merge_operations(command.settings(), to_op_parents, None)?;
|
||||||
}
|
}
|
||||||
let graph_style = GraphStyle::from_settings(command.settings())?;
|
let graph_style = GraphStyle::from_settings(command.settings())?;
|
||||||
|
|
|
@ -17,7 +17,6 @@ use itertools::Itertools;
|
||||||
use super::diff::show_op_diff;
|
use super::diff::show_op_diff;
|
||||||
use crate::cli_util::CommandHelper;
|
use crate::cli_util::CommandHelper;
|
||||||
use crate::cli_util::LogContentFormat;
|
use crate::cli_util::LogContentFormat;
|
||||||
use crate::command_error::user_error;
|
|
||||||
use crate::command_error::CommandError;
|
use crate::command_error::CommandError;
|
||||||
use crate::diff_util::DiffFormatArgs;
|
use crate::diff_util::DiffFormatArgs;
|
||||||
use crate::graphlog::GraphStyle;
|
use crate::graphlog::GraphStyle;
|
||||||
|
@ -55,9 +54,6 @@ pub fn cmd_op_show(
|
||||||
let repo_loader = &repo.loader();
|
let repo_loader = &repo.loader();
|
||||||
let op = workspace_command.resolve_single_op(&args.operation)?;
|
let op = workspace_command.resolve_single_op(&args.operation)?;
|
||||||
let parents: Vec<_> = op.parents().try_collect()?;
|
let parents: Vec<_> = op.parents().try_collect()?;
|
||||||
if parents.is_empty() {
|
|
||||||
return Err(user_error("Cannot show the root operation"));
|
|
||||||
}
|
|
||||||
let parent_op = repo_loader.merge_operations(command.settings(), parents, None)?;
|
let parent_op = repo_loader.merge_operations(command.settings(), parents, None)?;
|
||||||
let parent_repo = repo_loader.load_at(&parent_op)?;
|
let parent_repo = repo_loader.load_at(&parent_op)?;
|
||||||
let repo = repo_loader.load_at(&op)?;
|
let repo = repo_loader.load_at(&op)?;
|
||||||
|
|
|
@ -1211,9 +1211,9 @@ fn test_op_show() {
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
// The root operation is empty.
|
// The root operation is empty.
|
||||||
let stderr = test_env.jj_cmd_failure(&repo_path, &["op", "show", "0000000"]);
|
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "show", "0000000"]);
|
||||||
insta::assert_snapshot!(&stderr, @r###"
|
insta::assert_snapshot!(&stdout, @r###"
|
||||||
Error: Cannot show the root operation
|
000000000000 root()
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
// Showing the latest operation.
|
// Showing the latest operation.
|
||||||
|
|
|
@ -753,8 +753,8 @@ impl RepoLoader {
|
||||||
Arc::new(repo)
|
Arc::new(repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Merges the given `operations` into a single operation.
|
/// Merges the given `operations` into a single operation. Returns the root
|
||||||
/// Assumes that there is at least one operation.
|
/// operation if the `operations` is empty.
|
||||||
pub fn merge_operations(
|
pub fn merge_operations(
|
||||||
&self,
|
&self,
|
||||||
settings: &UserSettings,
|
settings: &UserSettings,
|
||||||
|
@ -763,7 +763,11 @@ impl RepoLoader {
|
||||||
) -> Result<Operation, RepoLoaderError> {
|
) -> Result<Operation, RepoLoaderError> {
|
||||||
let num_operations = operations.len();
|
let num_operations = operations.len();
|
||||||
let mut operations = operations.into_iter();
|
let mut operations = operations.into_iter();
|
||||||
let base_op = operations.next().unwrap();
|
let Some(base_op) = operations.next() else {
|
||||||
|
let id = self.op_store.root_operation_id();
|
||||||
|
let data = self.op_store.read_operation(id)?;
|
||||||
|
return Ok(Operation::new(self.op_store.clone(), id.clone(), data));
|
||||||
|
};
|
||||||
let final_op = if num_operations > 1 {
|
let final_op = if num_operations > 1 {
|
||||||
let base_repo = self.load_at(&base_op)?;
|
let base_repo = self.load_at(&base_op)?;
|
||||||
let mut tx = base_repo.start_transaction(settings);
|
let mut tx = base_repo.start_transaction(settings);
|
||||||
|
@ -789,6 +793,7 @@ impl RepoLoader {
|
||||||
op_heads: Vec<Operation>,
|
op_heads: Vec<Operation>,
|
||||||
user_settings: &UserSettings,
|
user_settings: &UserSettings,
|
||||||
) -> Result<Operation, RepoLoaderError> {
|
) -> Result<Operation, RepoLoaderError> {
|
||||||
|
assert!(!op_heads.is_empty());
|
||||||
self.merge_operations(
|
self.merge_operations(
|
||||||
user_settings,
|
user_settings,
|
||||||
op_heads,
|
op_heads,
|
||||||
|
|
Loading…
Reference in a new issue