forked from mirrors/jj
commands: move files code to files.rs
This commit is contained in:
parent
4257341dbe
commit
42795898de
2 changed files with 55 additions and 30 deletions
52
cli/src/commands/files.rs
Normal file
52
cli/src/commands/files.rs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
// Copyright 2020 The Jujutsu Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
|
use crate::cli_util::{CommandError, CommandHelper, RevisionArg};
|
||||||
|
use crate::ui::Ui;
|
||||||
|
|
||||||
|
/// List files in a revision
|
||||||
|
#[derive(clap::Args, Clone, Debug)]
|
||||||
|
pub(crate) struct FilesArgs {
|
||||||
|
/// The revision to list files in
|
||||||
|
#[arg(long, short, default_value = "@")]
|
||||||
|
revision: RevisionArg,
|
||||||
|
/// Only list files matching these prefixes (instead of all files)
|
||||||
|
#[arg(value_hint = clap::ValueHint::AnyPath)]
|
||||||
|
paths: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[instrument(skip_all)]
|
||||||
|
pub(crate) 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.tree()?;
|
||||||
|
let matcher = workspace_command.matcher_from_values(&args.paths)?;
|
||||||
|
ui.request_pager();
|
||||||
|
for (name, _value) in tree.entries_matching(matcher.as_ref()) {
|
||||||
|
writeln!(
|
||||||
|
ui.stdout(),
|
||||||
|
"{}",
|
||||||
|
&workspace_command.format_file_path(&name)
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ mod diff;
|
||||||
mod diffedit;
|
mod diffedit;
|
||||||
mod duplicate;
|
mod duplicate;
|
||||||
mod edit;
|
mod edit;
|
||||||
|
mod files;
|
||||||
mod git;
|
mod git;
|
||||||
mod operation;
|
mod operation;
|
||||||
|
|
||||||
|
@ -99,7 +100,7 @@ enum Commands {
|
||||||
Diffedit(diffedit::DiffeditArgs),
|
Diffedit(diffedit::DiffeditArgs),
|
||||||
Duplicate(duplicate::DuplicateArgs),
|
Duplicate(duplicate::DuplicateArgs),
|
||||||
Edit(edit::EditArgs),
|
Edit(edit::EditArgs),
|
||||||
Files(FilesArgs),
|
Files(files::FilesArgs),
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
Git(git::GitCommands),
|
Git(git::GitCommands),
|
||||||
Init(InitArgs),
|
Init(InitArgs),
|
||||||
|
@ -176,17 +177,6 @@ struct UntrackArgs {
|
||||||
paths: Vec<String>,
|
paths: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List files in a revision
|
|
||||||
#[derive(clap::Args, Clone, Debug)]
|
|
||||||
struct FilesArgs {
|
|
||||||
/// The revision to list files in
|
|
||||||
#[arg(long, short, default_value = "@")]
|
|
||||||
revision: RevisionArg,
|
|
||||||
/// Only list files matching these prefixes (instead of all files)
|
|
||||||
#[arg(value_hint = clap::ValueHint::AnyPath)]
|
|
||||||
paths: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Show commit description and changes in a revision
|
/// Show commit description and changes in a revision
|
||||||
#[derive(clap::Args, Clone, Debug)]
|
#[derive(clap::Args, Clone, Debug)]
|
||||||
struct ShowArgs {
|
struct ShowArgs {
|
||||||
|
@ -1040,23 +1030,6 @@ Make sure they're ignored, then try again.",
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip_all)]
|
|
||||||
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.tree()?;
|
|
||||||
let matcher = workspace_command.matcher_from_values(&args.paths)?;
|
|
||||||
ui.request_pager();
|
|
||||||
for (name, _value) in tree.entries_matching(matcher.as_ref()) {
|
|
||||||
writeln!(
|
|
||||||
ui.stdout(),
|
|
||||||
"{}",
|
|
||||||
&workspace_command.format_file_path(&name)
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[instrument(skip_all)]
|
#[instrument(skip_all)]
|
||||||
fn cmd_show(ui: &mut Ui, command: &CommandHelper, args: &ShowArgs) -> Result<(), CommandError> {
|
fn cmd_show(ui: &mut Ui, command: &CommandHelper, args: &ShowArgs) -> Result<(), CommandError> {
|
||||||
let workspace_command = command.workspace_helper(ui)?;
|
let workspace_command = command.workspace_helper(ui)?;
|
||||||
|
@ -3131,7 +3104,7 @@ pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), Co
|
||||||
Commands::Config(sub_args) => config::cmd_config(ui, command_helper, sub_args),
|
Commands::Config(sub_args) => config::cmd_config(ui, command_helper, sub_args),
|
||||||
Commands::Checkout(sub_args) => checkout::cmd_checkout(ui, command_helper, sub_args),
|
Commands::Checkout(sub_args) => checkout::cmd_checkout(ui, command_helper, sub_args),
|
||||||
Commands::Untrack(sub_args) => cmd_untrack(ui, command_helper, sub_args),
|
Commands::Untrack(sub_args) => cmd_untrack(ui, command_helper, sub_args),
|
||||||
Commands::Files(sub_args) => cmd_files(ui, command_helper, sub_args),
|
Commands::Files(sub_args) => files::cmd_files(ui, command_helper, sub_args),
|
||||||
Commands::Cat(sub_args) => cat::cmd_cat(ui, command_helper, sub_args),
|
Commands::Cat(sub_args) => cat::cmd_cat(ui, command_helper, sub_args),
|
||||||
Commands::Diff(sub_args) => diff::cmd_diff(ui, command_helper, sub_args),
|
Commands::Diff(sub_args) => diff::cmd_diff(ui, command_helper, sub_args),
|
||||||
Commands::Show(sub_args) => cmd_show(ui, command_helper, sub_args),
|
Commands::Show(sub_args) => cmd_show(ui, command_helper, sub_args),
|
||||||
|
|
Loading…
Reference in a new issue