Unified · Split
| @@ -5,9 +5,6 @@ pub struct Options { · 4 unmodified lines | ||
| 5 | 5 | pub format: crate::OutputFormat, |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | −mod entries; | |
| 9 | −pub use entries::entries; | |
| 10 | − | |
| 11 | 8 | pub mod information; |
| 12 | 9 | |
| 13 | 10 | fn parse_file(index_path: impl AsRef<Path>, object_hash: gix::hash::Kind) -> anyhow::Result<gix::index::File> { |
| @@ -1,26 +1,18 @@ | ||
| 1 | −use std::path::Path; | |
| 2 | − | |
| 3 | −use crate::index::{parse_file, Options}; | |
| 4 | − | |
| 5 | −pub fn entries( | |
| 6 | − index_path: impl AsRef<Path>, | |
| 7 | − mut out: impl std::io::Write, | |
| 8 | − Options { object_hash, format }: Options, | |
| 9 | −) -> anyhow::Result<()> { | |
| 1 | +pub fn entries(repo: gix::Repository, mut out: impl std::io::Write, format: crate::OutputFormat) -> anyhow::Result<()> { | |
| 10 | 2 | use crate::OutputFormat::*; |
| 11 | − let file = parse_file(index_path, object_hash)?; | |
| 3 | + let index = repo.index()?; | |
| 12 | 4 | |
| 13 | 5 | #[cfg(feature = "serde")] |
| 14 | 6 | if let Json = format { |
| 15 | 7 | out.write_all(b"[\n")?; |
| 16 | 8 | } |
| 17 | 9 | |
| 18 | − let mut entries = file.entries().iter().peekable(); | |
| 10 | + let mut entries = index.entries().iter().peekable(); | |
| 19 | 11 | while let Some(entry) = entries.next() { |
| 20 | 12 | match format { |
| 21 | − Human => to_human(&mut out, &file, entry)?, | |
| 13 | + Human => to_human(&mut out, &index, entry)?, | |
| 22 | 14 | #[cfg(feature = "serde")] |
| 23 | − Json => to_json(&mut out, &file, entry, entries.peek().is_none())?, | |
| 15 | + Json => to_json(&mut out, &index, entry, entries.peek().is_none())?, | |
| 24 | 16 | } |
| 25 | 17 | } |
| 26 | 18 | |
| @@ -34,7 +26,7 @@ pub fn entries( · 7 unmodified lines | ||
| 34 | 26 | #[cfg(feature = "serde")] |
| 35 | 27 | pub(crate) fn to_json( |
| 36 | 28 | mut out: &mut impl std::io::Write, |
| 37 | − file: &gix::index::File, | |
| 29 | + index: &gix::index::File, | |
| 38 | 30 | entry: &gix::index::Entry, |
| 39 | 31 | is_last: bool, |
| 40 | 32 | ) -> anyhow::Result<()> { |
| @@ -56,7 +48,7 @@ pub(crate) fn to_json( · 15 unmodified lines | ||
| 56 | 48 | hex_id: entry.id.to_hex().to_string(), |
| 57 | 49 | flags: entry.flags.bits(), |
| 58 | 50 | mode: entry.mode.bits(), |
| 59 | − path: entry.path(file).to_str_lossy(), | |
| 51 | + path: entry.path(index).to_str_lossy(), | |
| 60 | 52 | }, |
| 61 | 53 | )?; |
| 62 | 54 | |
| @@ -34,3 +34,6 @@ pub fn from_tree( · 33 unmodified lines | ||
| 34 | 34 | |
| 35 | 35 | Ok(()) |
| 36 | 36 | } |
| 37 | + | |
| 38 | +mod entries; | |
| 39 | +pub use entries::entries; | |
| @@ -339,16 +339,6 @@ pub fn main() -> Result<()> { · 338 unmodified lines | ||
| 339 | 339 | ) |
| 340 | 340 | }, |
| 341 | 341 | ), |
| 342 | − free::index::Subcommands::Entries => prepare_and_run( | |
| 343 | − "index-entries", | |
| 344 | − verbose, | |
| 345 | − progress, | |
| 346 | − progress_keep_open, | |
| 347 | − None, | |
| 348 | − move |_progress, out, _err| { | |
| 349 | − core::index::entries(index_path, out, core::index::Options { object_hash, format }) | |
| 350 | − }, | |
| 351 | − ), | |
| 352 | 342 | free::index::Subcommands::Verify => prepare_and_run( |
| 353 | 343 | "index-verify", |
| 354 | 344 | auto_verbose, |
| @@ -865,6 +855,16 @@ pub fn main() -> Result<()> { · 510 unmodified lines | ||
| 865 | 855 | ), |
| 866 | 856 | }, |
| 867 | 857 | Subcommands::Index(cmd) => match cmd { |
| 858 | + index::Subcommands::Entries => prepare_and_run( | |
| 859 | + "index-entries", | |
| 860 | + verbose, | |
| 861 | + progress, | |
| 862 | + progress_keep_open, | |
| 863 | + None, | |
| 864 | + move |_progress, out, _err| { | |
| 865 | + core::repository::index::entries(repository(Mode::LenientWithGitInstallConfig)?, out, format) | |
| 866 | + }, | |
| 867 | + ), | |
| 868 | 868 | index::Subcommands::FromTree { |
| 869 | 869 | force, |
| 870 | 870 | index_output_path, |
| @@ -55,8 +55,6 @@ pub mod index { · 54 unmodified lines | ||
| 55 | 55 | pub enum Subcommands { |
| 56 | 56 | /// Validate constraints and assumptions of an index along with its integrity. |
| 57 | 57 | Verify, |
| 58 | − /// Print all entries to standard output | |
| 59 | − Entries, | |
| 60 | 58 | /// Print information about the index structure |
| 61 | 59 | Info { |
| 62 | 60 | /// Do not extract specific extension information to gain only a superficial idea of the index's composition. |
| @@ -471,6 +471,8 @@ pub mod index { · 470 unmodified lines | ||
| 471 | 471 | |
| 472 | 472 | #[derive(Debug, clap::Subcommand)] |
| 473 | 473 | pub enum Subcommands { |
| 474 | + /// Print all entries to standard output | |
| 475 | + Entries, | |
| 474 | 476 | /// Create an index from a tree-ish. |
| 475 | 477 | #[clap(visible_alias = "read-tree")] |
| 476 | 478 | FromTree { |