cli: migrate cat, files & git submodule print to MergedTree API

This commit is contained in:
Martin von Zweigbergk 2023-08-27 06:51:34 -07:00 committed by Martin von Zweigbergk
parent d753c85e01
commit a0291e99d7
2 changed files with 11 additions and 9 deletions

View file

@ -1049,13 +1049,14 @@ fn cmd_git_submodule_print_gitmodules(
let workspace_command = command.workspace_helper(ui)?;
let repo = workspace_command.repo();
let commit = workspace_command.resolve_single_rev(&args.revisions, ui)?;
let tree = commit.merged_tree()?;
let gitmodules_path = RepoPath::from_internal_string(".gitmodules");
let mut gitmodules_file = match commit.tree().path_value(&gitmodules_path) {
None => {
let mut gitmodules_file = match tree.path_value(&gitmodules_path).into_resolved() {
Ok(None) => {
writeln!(ui, "No submodules!")?;
return Ok(());
}
Some(TreeValue::File { id, .. }) => repo.store().read_file(&gitmodules_path, &id)?,
Ok(Some(TreeValue::File { id, .. })) => repo.store().read_file(&gitmodules_path, &id)?,
_ => {
return Err(user_error(".gitmodules is not a file."));
}

View file

@ -1386,9 +1386,10 @@ Make sure they're ignored, then try again.",
fn cmd_files(ui: &mut Ui, command: &CommandHelper, args: &FilesArgs) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;
let commit = workspace_command.resolve_single_rev(&args.revision, ui)?;
let tree = commit.merged_tree()?;
let matcher = workspace_command.matcher_from_values(&args.paths)?;
ui.request_pager();
for (name, _value) in commit.tree().entries_matching(matcher.as_ref()) {
for (name, _value) in tree.entries_matching(matcher.as_ref()) {
writeln!(ui, "{}", &workspace_command.format_file_path(&name))?;
}
Ok(())
@ -1398,19 +1399,19 @@ fn cmd_files(ui: &mut Ui, command: &CommandHelper, args: &FilesArgs) -> Result<(
fn cmd_cat(ui: &mut Ui, command: &CommandHelper, args: &CatArgs) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;
let commit = workspace_command.resolve_single_rev(&args.revision, ui)?;
let tree = commit.merged_tree()?;
let path = workspace_command.parse_file_path(&args.path)?;
let repo = workspace_command.repo();
match commit.tree().path_value(&path) {
None => {
match tree.path_value(&path).into_resolved() {
Ok(None) => {
return Err(user_error("No such path"));
}
Some(TreeValue::File { id, .. }) => {
Ok(Some(TreeValue::File { id, .. })) => {
let mut contents = repo.store().read_file(&path, &id)?;
ui.request_pager();
std::io::copy(&mut contents, &mut ui.stdout_formatter().as_mut())?;
}
Some(TreeValue::Conflict(id)) => {
let conflict = repo.store().read_conflict(&path, &id)?;
Err(conflict) => {
let mut contents = vec![];
conflicts::materialize(&conflict, repo.store(), &path, &mut contents).unwrap();
ui.request_pager();