Unified · Split
| @@ -5,9 +5,6 @@ pub struct Options { · 4 unmodified lines | |||
| 5 | pub format: crate::OutputFormat, | 5 | pub format: crate::OutputFormat, |
| 6 | } | 6 | } |
| 7 | 7 | ||
| 8 | mod entries; | ||
| 9 | pub use entries::entries; | ||
| 10 | |||
| 11 | pub mod information; | 8 | pub mod information; |
| 12 | 9 | ||
| 13 | fn parse_file(index_path: impl AsRef<Path>, object_hash: gix::hash::Kind) -> anyhow::Result<gix::index::File> { | 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; | 1 | pub fn entries(repo: gix::Repository, mut out: impl std::io::Write, format: crate::OutputFormat) -> anyhow::Result<()> { |
| 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<()> { | ||
| 10 | use crate::OutputFormat::*; | 2 | use crate::OutputFormat::*; |
| 11 | let file = parse_file(index_path, object_hash)?; | 3 | let index = repo.index()?; |
| 12 | 4 | ||
| 13 | #[cfg(feature = "serde")] | 5 | #[cfg(feature = "serde")] |
| 14 | if let Json = format { | 6 | if let Json = format { |
| 15 | out.write_all(b"[\n")?; | 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 | while let Some(entry) = entries.next() { | 11 | while let Some(entry) = entries.next() { |
| 20 | match format { | 12 | match format { |
| 21 | Human => to_human(&mut out, &file, entry)?, | 13 | Human => to_human(&mut out, &index, entry)?, |
| 22 | #[cfg(feature = "serde")] | 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 | #[cfg(feature = "serde")] | 26 | #[cfg(feature = "serde")] |
| 35 | pub(crate) fn to_json( | 27 | pub(crate) fn to_json( |
| 36 | mut out: &mut impl std::io::Write, | 28 | mut out: &mut impl std::io::Write, |
| 37 | file: &gix::index::File, | 29 | index: &gix::index::File, |
| 38 | entry: &gix::index::Entry, | 30 | entry: &gix::index::Entry, |
| 39 | is_last: bool, | 31 | is_last: bool, |
| 40 | ) -> anyhow::Result<()> { | 32 | ) -> anyhow::Result<()> { |
| @@ -56,7 +48,7 @@ pub(crate) fn to_json( · 15 unmodified lines | |||
| 56 | hex_id: entry.id.to_hex().to_string(), | 48 | hex_id: entry.id.to_hex().to_string(), |
| 57 | flags: entry.flags.bits(), | 49 | flags: entry.flags.bits(), |
| 58 | mode: entry.mode.bits(), | 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 | Ok(()) | 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 | free::index::Subcommands::Verify => prepare_and_run( | 342 | free::index::Subcommands::Verify => prepare_and_run( |
| 353 | "index-verify", | 343 | "index-verify", |
| 354 | auto_verbose, | 344 | auto_verbose, |
| @@ -865,6 +855,16 @@ pub fn main() -> Result<()> { · 510 unmodified lines | |||
| 865 | ), | 855 | ), |
| 866 | }, | 856 | }, |
| 867 | Subcommands::Index(cmd) => match cmd { | 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 | index::Subcommands::FromTree { | 868 | index::Subcommands::FromTree { |
| 869 | force, | 869 | force, |
| 870 | index_output_path, | 870 | index_output_path, |
| @@ -55,8 +55,6 @@ pub mod index { · 54 unmodified lines | |||
| 55 | pub enum Subcommands { | 55 | pub enum Subcommands { |
| 56 | /// Validate constraints and assumptions of an index along with its integrity. | 56 | /// Validate constraints and assumptions of an index along with its integrity. |
| 57 | Verify, | 57 | Verify, |
| 58 | /// Print all entries to standard output | ||
| 59 | Entries, | ||
| 60 | /// Print information about the index structure | 58 | /// Print information about the index structure |
| 61 | Info { | 59 | Info { |
| 62 | /// Do not extract specific extension information to gain only a superficial idea of the index's composition. | 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 | #[derive(Debug, clap::Subcommand)] | 472 | #[derive(Debug, clap::Subcommand)] |
| 473 | pub enum Subcommands { | 473 | pub enum Subcommands { |
| 474 | /// Print all entries to standard output | ||
| 475 | Entries, | ||
| 474 | /// Create an index from a tree-ish. | 476 | /// Create an index from a tree-ish. |
| 475 | #[clap(visible_alias = "read-tree")] | 477 | #[clap(visible_alias = "read-tree")] |
| 476 | FromTree { | 478 | FromTree { |