1322 lines · 49.8 KB · Rust
RawDownload
use std::path::PathBuf; use clap_complete::Shell;use gitoxide_core as core;use gix::bstr::BString; use crate::shared::{AsRange, AsTime}; #[derive(Debug, clap::Parser)]#[clap(name = "gix", about = "The git underworld", version = option_env!("GIX_VERSION"))]#[clap(subcommand_required = true)]#[clap(arg_required_else_help = true)]pub struct Args {    /// The repository to access.    #[clap(short = 'r', long, default_value = ".")]    pub repository: PathBuf,     /// Add these values to the configuration in the form of `key=value` or `key`.    ///    /// For example, if `key` is `core.abbrev`, set configuration like `[core] abbrev = key`,    /// or `remote.origin.url = foo` to set `[remote "origin"] url = foo`.    #[clap(long, short = 'c', value_parser = crate::shared::AsBString)]    pub config: Vec<BString>,     /// The amount of threads to use for some operations.    ///    /// If unset, or the value is 0, there is no limit and all logical cores can be used.    #[clap(long, short = 't')]    pub threads: Option<usize>,     /// Display verbose messages and progress information    #[clap(long, short = 'v')]    pub verbose: bool,     /// Display structured `tracing` output in a tree-like structure.    #[clap(long)]    #[cfg(feature = "tracing")]    pub trace: bool,     /// Turn off verbose message display for commands where these are shown by default.    #[clap(long, conflicts_with("verbose"))]    pub no_verbose: bool,     /// Bring up a terminal user interface displaying progress visually.    #[cfg(feature = "prodash-render-tui")]    #[clap(long, conflicts_with("verbose"))]    pub progress: bool,     /// Don't default malformed configuration flags, but show an error instead. Ignore IO errors as well.    ///    /// Note that some subcommands use strict mode by default.    // TODO: needs a 'lenient' mutually exclusive counterpart. Opens the gate to auto-verbose some commands, and add --no-verbose    //       for these.    #[clap(long, short = 's')]    pub strict: bool,     /// The progress TUI will stay up even though the work is already completed.    ///    /// Use this to be able to read progress messages or additional information visible in the TUI log pane.    #[cfg(feature = "prodash-render-tui")]    #[clap(long, conflicts_with("verbose"), requires("progress"))]    pub progress_keep_open: bool,     /// Determine the format to use when outputting statistics.    #[clap(        long,        short = 'f',        default_value = "human",        value_parser = crate::shared::AsOutputFormat    )]    pub format: core::OutputFormat,     /// The object format to assume when reading files that don't inherently know about it, or when writing files.    #[clap(long, default_value_t = gix::hash::Kind::default(), value_parser = crate::shared::AsHashKind)]    pub object_hash: gix::hash::Kind,     #[clap(subcommand)]    pub cmd: Subcommands,} #[derive(Debug, clap::Subcommand)]pub enum Subcommands {    /// Subcommands for creating worktree archives.    #[cfg(feature = "gitoxide-core-tools-archive")]    Archive(archive::Platform),    /// Interact with branches.    #[clap(visible_alias = "branches")]    Branch(branch::Platform),    /// Remove untracked files from the working tree.    #[cfg(feature = "gitoxide-core-tools-clean")]    Clean(clean::Command),    /// Subcommands for interacting with commit-graph files.    #[clap(subcommand)]    CommitGraph(commitgraph::Subcommands),    /// Interact with the object database.    #[clap(subcommand)]    Odb(odb::Subcommands),    /// Check for missing objects.    Fsck(fsck::Platform),    /// Interact with tree objects.    #[clap(subcommand)]    Tree(tree::Subcommands),    /// Interact with commit objects.    #[clap(subcommand)]    Commit(commit::Subcommands),    /// Interact with tag objects.    #[clap(visible_alias = "tags")]    Tag(tag::Platform),    /// Verify the integrity of the entire repository    Verify {        #[clap(flatten)]        args: free::pack::VerifyOptions,    },    /// Query and obtain information about revisions.    #[clap(subcommand)]    Revision(revision::Subcommands),    /// A program just like `git credential`.    #[clap(subcommand)]    Credential(credential::Subcommands),    /// Fetch data from remotes and store it in the repository.    #[cfg(feature = "gitoxide-core-blocking-client")]    Fetch(fetch::Platform),    /// Clone a repository into a new directory.    #[cfg(feature = "gitoxide-core-blocking-client")]    Clone(clone::Platform),    /// Interact with the mailmap.    #[clap(subcommand)]    Mailmap(mailmap::Subcommands),    /// Interact with the remote hosts.    #[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]    Remote(remote::Platform),    /// Interact with the attribute files like .gitattributes.    #[clap(subcommand, visible_alias = "attrs")]    Attributes(attributes::Subcommands),    /// Interact with the exclude files like .gitignore.    #[clap(subcommand)]    Exclude(exclude::Subcommands),    /// Interact with a worktree index like .git/index.    #[clap(subcommand)]    Index(index::Subcommands),    /// Interact with submodules.    #[clap(alias = "submodules")]    Submodule(submodule::Platform),    /// Show whatever object is at the given spec.    Cat {        /// The object to print to stdout.        revspec: String,    },    /// Check for changes in the repository, treating this as an error.    IsClean,    /// Check for changes in the repository, treating their absence as an error.    IsChanged,    /// Show which git configuration values are used or planned.    ConfigTree,    Status(status::Platform),    Dirwalk(dirwalk::Platform),    Config(config::Platform),    #[cfg(feature = "gitoxide-core-tools-corpus")]    Corpus(corpus::Platform),    MergeBase(merge_base::Command),    Merge(merge::Platform),    /// Print paths relevant to the Git installation.    Env,    Diff(diff::Platform),    Log(log::Platform),    Worktree(worktree::Platform),    /// Subcommands that need no Git repository to run.    #[clap(subcommand)]    Free(free::Subcommands),    /// Blame lines in a file.    Blame {        /// Print additional statistics to help understanding performance.        #[clap(long, short = 's')]        statistics: bool,        /// The file to create the blame information for.        file: std::ffi::OsString,        /// Only blame lines in the given 1-based inclusive range '<start>,<end>', e.g. '20,40'.        #[clap(short='L', value_parser=AsRange, action=clap::ArgAction::Append)]        ranges: Vec<std::ops::RangeInclusive<u32>>,        /// Don't consider commits before the given date.        #[clap(long,  value_parser=AsTime, value_name = "DATE")]        since: Option<gix::date::Time>,    },    /// Generate shell completions to stdout or a directory.    #[clap(visible_alias = "generate-completions", visible_alias = "shell-completions")]    Completions {        /// The shell to generate completions for. Otherwise it's derived from the environment.        #[clap(long, short)]        shell: Option<Shell>,        /// The output directory in case multiple files are generated. If not provided, will write to stdout.        out_dir: Option<String>,    },} #[cfg(feature = "gitoxide-core-tools-archive")]pub mod archive {    use std::path::PathBuf;     #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]    pub enum Format {        /// An internal format that is for debugging, it should not be persisted and cannot be read back.        ///        /// However, it represents that bare data stream without with minimal overhead, and is a good        /// metric for throughput.        Internal,        /// Use the `.tar` file format, uncompressed.        Tar,        /// Use the `.tar.gz` file format, compressed with `gzip`.        TarGz,        /// Use the `.zip` container format.        Zip,    }     #[derive(Debug, clap::Parser)]    pub struct Platform {        /// Explicitly set the format. Otherwise derived from the suffix of the output file.        #[clap(long, short = 'f', value_enum)]        pub format: Option<Format>,        /// Apply the prefix verbatim to any path we add to the archive. Use a trailing `/` if prefix is a directory.        #[clap(long)]        pub prefix: Option<String>,        /// The compression strength to use for `.zip` and `.tar.gz` archives, valid from 0-9.        #[clap(long, short = 'l', requires = "format")]        pub compression_level: Option<u8>,        /// Add the given path to the archive. Directories will always be empty.        #[clap(long, short = 'p')]        pub add_path: Vec<PathBuf>,        /// Add the new file from a slash-separated path, which must happen in pairs of two, first the path, then the content.        #[clap(long, short = 'v')]        pub add_virtual_file: Vec<String>,        /// The file to write the archive to.        ///        /// It's extension determines the archive format, unless `--format` is set.        pub output_file: PathBuf,         /// The revspec of the commit or tree to traverse, or the tree at `HEAD` if unspecified.        ///        /// If commit, the commit timestamp will be used as timestamp for each file in the archive.        pub treeish: Option<String>,    }} pub mod branch {    #[derive(Debug, clap::Parser)]    pub struct Platform {        #[clap(subcommand)]        pub cmd: Subcommands,    }     #[derive(Debug, clap::Subcommand)]    pub enum Subcommands {        /// List branches.        List {            /// List remote-tracking as well as local branches.            #[clap(long, short = 'a')]            all: bool,        },    }} pub mod status {    use gix::bstr::BString;     use crate::shared::{CheckPathSpec, ParseRenameFraction};     #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]    pub enum Submodules {        /// display all information about submodules, including ref changes, modifications and untracked files.        #[default]        All,        /// Compare only the configuration of the superprojects commit with the actually checked out `HEAD` commit.        RefChange,        /// See if there are worktree modifications compared to the index, but do not check for untracked files.        Modifications,        /// Ignore all submodule changes.        None,    }     #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]    pub enum Ignored {        /// display all ignored files and directories, but collapse them if possible to simplify.        #[default]        Collapsed,        /// Show exact matches. Note that this may show directories if these are a match as well.        ///        /// Simplification will not happen in this mode.        Matching,        // TODO: figure out how to implement traditional, which right now can't be done as it requires ignored folders        //       to be fully expanded. This should probably be implemented in `gix_dir` which then simply works by not        //       allowing to ignore directories, naturally traversing the entire content.    }     #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]    pub enum Untracked {        /// Do not show untracked files.        No,        /// Collapse untracked directories when possible.        Normal,        /// Show individual untracked files.        #[default]        All,    }     #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]    pub enum Format {        /// A basic format that is easy to read, and useful for a first glimpse as flat list.        #[default]        Simplified,        /// Output very similar to `git status --porcelain=2`.        PorcelainV2,    }     #[derive(Debug, clap::Parser)]    #[command(about = "Compute repository status similar to `git status`")]    pub struct Platform {        /// The way status data is displayed.        #[clap(long, short = 'f')]        pub format: Option<Format>,        /// If enabled, show ignored files and directories.        #[clap(long)]        pub ignored: Option<Option<Ignored>>,        /// Define how to show untracked files. If set without a value, show all individual untracked files.        #[clap(long, short = 'u', require_equals = true)]        pub untracked: Option<Option<Untracked>>,        /// Define how to display the submodule status. Defaults to git configuration if unset.        #[clap(long)]        pub submodules: Option<Submodules>,        /// Print additional statistics to help understanding performance.        #[clap(long, short = 's')]        pub statistics: bool,        /// Don't write back a changed index, which forces this operation to always be idempotent.        #[clap(long)]        pub no_write: bool,        /// Enable rename tracking between the index and the working tree, preventing the collapse of folders as well.        #[clap(long, value_parser = ParseRenameFraction)]        pub index_worktree_renames: Option<Option<f32>>,        /// The git path specifications to list attributes for, or unset to read from stdin one per line.        #[clap(value_parser = CheckPathSpec)]        pub pathspec: Vec<BString>,    }} pub mod dirwalk {    use gix::bstr::BString;     use crate::shared::CheckPathSpec;     #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]    pub enum Untracked {        /// Collapse untracked directories when possible.        #[default]        Collapsed,        /// Emit matching untracked files and directories.        Matching,    }     #[derive(Debug, clap::Parser)]    #[command(about = "Run only the repository directory walk")]    pub struct Platform {        /// Print additional statistics to help understanding performance.        #[clap(long, short = 's')]        pub statistics: bool,        /// How untracked files should be emitted.        #[clap(long, default_value = "collapsed")]        pub untracked: Untracked,        /// The git path specifications to walk.        #[clap(value_parser = CheckPathSpec)]        pub pathspec: Vec<BString>,    }} pub mod merge_base {    #[derive(Debug, clap::Parser)]    #[command(about = "A command for calculating all merge-bases")]    pub struct Command {        /// A revspec for the first commit.        pub first: String,        /// Revspecs for the other commits to compute the merge-base with.        pub others: Vec<String>,    }} pub mod worktree {    #[derive(Debug, clap::Parser)]    #[command(about = "Commands for handling worktrees")]    pub struct Platform {        #[clap(subcommand)]        pub cmd: SubCommands,    }     #[derive(Debug, clap::Subcommand)]    pub enum SubCommands {        /// List all worktrees, along with some accompanying information.        List,    }} #[cfg(feature = "gitoxide-core-tools-corpus")]pub mod corpus {    use std::path::PathBuf;     #[derive(Debug, clap::Parser)]    #[command(about = "Run algorithms on a corpus of git repositories and store their results for later analysis")]    pub struct Platform {        /// The path to the database to read and write depending on the sub-command.        #[arg(long, default_value = "corpus.db")]        pub db: PathBuf,        /// The path to the root of the corpus to search repositories in.        #[arg(long, short = 'p', default_value = ".")]        pub path: PathBuf,        #[clap(subcommand)]        pub cmd: SubCommands,    }     #[derive(Debug, clap::Subcommand)]    pub enum SubCommands {        /// Perform a corpus run on all registered repositories.        Run {            /// Don't run any task, but print all repos that would be traversed once.            ///            /// Note that this will refresh repositories if necessary and store them in the database, it just won't run tasks.            #[clap(long, short = 'n')]            dry_run: bool,             /// The SQL that will be appended to the actual select statement for repositories to apply additional filtering, like `LIMIT 10`.            ///            /// The string must be trusted even though the engine will only execute a single statement.            #[clap(long, short = 'r')]            repo_sql_suffix: Option<String>,             /// The short_names of the tasks to include when running.            #[clap(long, short = 't')]            include_task: Vec<String>,        },        /// Re-read all repositories under the corpus directory, and add or update them.        Refresh,    }} pub mod merge {    use gix::bstr::BString;     #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]    pub enum ResolveWith {        /// Use ours then theirs in case of conflict.        Union,        /// Use only ours in case of conflict.        Ours,        /// Use only theirs in case of conflict.        Theirs,    }     impl From<ResolveWith> for gix::merge::blob::builtin_driver::text::Conflict {        fn from(value: ResolveWith) -> Self {            match value {                ResolveWith::Union => gix::merge::blob::builtin_driver::text::Conflict::ResolveWithUnion,                ResolveWith::Ours => gix::merge::blob::builtin_driver::text::Conflict::ResolveWithOurs,                ResolveWith::Theirs => gix::merge::blob::builtin_driver::text::Conflict::ResolveWithTheirs,            }        }    }     #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]    pub enum FileFavor {        /// Use only ours in case of conflict.        Ours,        /// Use only theirs in case of conflict.        Theirs,    }     #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]    pub enum TreeFavor {        /// Use only the previous tree entry in case of conflict.        Ancestor,        /// Use only ours tree entry in case of conflict.        Ours,    }     impl From<FileFavor> for gix::merge::tree::FileFavor {        fn from(value: FileFavor) -> Self {            match value {                FileFavor::Ours => gix::merge::tree::FileFavor::Ours,                FileFavor::Theirs => gix::merge::tree::FileFavor::Theirs,            }        }    }     impl From<TreeFavor> for gix::merge::tree::TreeFavor {        fn from(value: TreeFavor) -> Self {            match value {                TreeFavor::Ancestor => gix::merge::tree::TreeFavor::Ancestor,                TreeFavor::Ours => gix::merge::tree::TreeFavor::Ours,            }        }    }     #[derive(Debug, clap::Parser)]    pub struct SharedOptions {        /// Keep all objects to be written in memory to avoid any disk IO.        ///

Lines 1–500 of 1322.