From ca8ebdfb9647ff15b0293823bb3bb3c6779c8dd2 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 25 Apr 2023 08:57:53 +0200 Subject: [PATCH] feat!: turn `gix free index entries` into `gix index entries`. --- gitoxide-core/src/index/mod.rs | 3 --- .../src/{ => repository}/index/entries.rs | 22 ++++++------------- .../src/repository/{index.rs => index/mod.rs} | 3 +++ src/plumbing/main.rs | 20 ++++++++--------- src/plumbing/options/free.rs | 2 -- src/plumbing/options/mod.rs | 2 ++ 6 files changed, 22 insertions(+), 30 deletions(-) rename gitoxide-core/src/{ => repository}/index/entries.rs (75%) rename gitoxide-core/src/repository/{index.rs => index/mod.rs} (96%) diff --git a/gitoxide-core/src/index/mod.rs b/gitoxide-core/src/index/mod.rs index 12b23f74332..df75cf541b6 100644 --- a/gitoxide-core/src/index/mod.rs +++ b/gitoxide-core/src/index/mod.rs @@ -5,9 +5,6 @@ pub struct Options { pub format: crate::OutputFormat, } -mod entries; -pub use entries::entries; - pub mod information; fn parse_file(index_path: impl AsRef, object_hash: gix::hash::Kind) -> anyhow::Result { diff --git a/gitoxide-core/src/index/entries.rs b/gitoxide-core/src/repository/index/entries.rs similarity index 75% rename from gitoxide-core/src/index/entries.rs rename to gitoxide-core/src/repository/index/entries.rs index 07a1481209c..05227dd88d2 100644 --- a/gitoxide-core/src/index/entries.rs +++ b/gitoxide-core/src/repository/index/entries.rs @@ -1,26 +1,18 @@ -use std::path::Path; - -use crate::index::{parse_file, Options}; - -pub fn entries( - index_path: impl AsRef, - mut out: impl std::io::Write, - Options { object_hash, format }: Options, -) -> anyhow::Result<()> { +pub fn entries(repo: gix::Repository, mut out: impl std::io::Write, format: crate::OutputFormat) -> anyhow::Result<()> { use crate::OutputFormat::*; - let file = parse_file(index_path, object_hash)?; + let index = repo.index()?; #[cfg(feature = "serde")] if let Json = format { out.write_all(b"[\n")?; } - let mut entries = file.entries().iter().peekable(); + let mut entries = index.entries().iter().peekable(); while let Some(entry) = entries.next() { match format { - Human => to_human(&mut out, &file, entry)?, + Human => to_human(&mut out, &index, entry)?, #[cfg(feature = "serde")] - Json => to_json(&mut out, &file, entry, entries.peek().is_none())?, + Json => to_json(&mut out, &index, entry, entries.peek().is_none())?, } } @@ -34,7 +26,7 @@ pub fn entries( #[cfg(feature = "serde")] pub(crate) fn to_json( mut out: &mut impl std::io::Write, - file: &gix::index::File, + index: &gix::index::File, entry: &gix::index::Entry, is_last: bool, ) -> anyhow::Result<()> { @@ -56,7 +48,7 @@ pub(crate) fn to_json( hex_id: entry.id.to_hex().to_string(), flags: entry.flags.bits(), mode: entry.mode.bits(), - path: entry.path(file).to_str_lossy(), + path: entry.path(index).to_str_lossy(), }, )?; diff --git a/gitoxide-core/src/repository/index.rs b/gitoxide-core/src/repository/index/mod.rs similarity index 96% rename from gitoxide-core/src/repository/index.rs rename to gitoxide-core/src/repository/index/mod.rs index d14fca2227e..7e1b3c274da 100644 --- a/gitoxide-core/src/repository/index.rs +++ b/gitoxide-core/src/repository/index/mod.rs @@ -34,3 +34,6 @@ pub fn from_tree( Ok(()) } + +mod entries; +pub use entries::entries; diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index 3f35d5b2a0d..ac05d3964fc 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -339,16 +339,6 @@ pub fn main() -> Result<()> { ) }, ), - free::index::Subcommands::Entries => prepare_and_run( - "index-entries", - verbose, - progress, - progress_keep_open, - None, - move |_progress, out, _err| { - core::index::entries(index_path, out, core::index::Options { object_hash, format }) - }, - ), free::index::Subcommands::Verify => prepare_and_run( "index-verify", auto_verbose, @@ -865,6 +855,16 @@ pub fn main() -> Result<()> { ), }, Subcommands::Index(cmd) => match cmd { + index::Subcommands::Entries => prepare_and_run( + "index-entries", + verbose, + progress, + progress_keep_open, + None, + move |_progress, out, _err| { + core::repository::index::entries(repository(Mode::LenientWithGitInstallConfig)?, out, format) + }, + ), index::Subcommands::FromTree { force, index_output_path, diff --git a/src/plumbing/options/free.rs b/src/plumbing/options/free.rs index 8bff740a3ef..00641f33b28 100644 --- a/src/plumbing/options/free.rs +++ b/src/plumbing/options/free.rs @@ -55,8 +55,6 @@ pub mod index { pub enum Subcommands { /// Validate constraints and assumptions of an index along with its integrity. Verify, - /// Print all entries to standard output - Entries, /// Print information about the index structure Info { /// Do not extract specific extension information to gain only a superficial idea of the index's composition. diff --git a/src/plumbing/options/mod.rs b/src/plumbing/options/mod.rs index 03adad04590..d2b8d7805d2 100644 --- a/src/plumbing/options/mod.rs +++ b/src/plumbing/options/mod.rs @@ -471,6 +471,8 @@ pub mod index { #[derive(Debug, clap::Subcommand)] pub enum Subcommands { + /// Print all entries to standard output + Entries, /// Create an index from a tree-ish. #[clap(visible_alias = "read-tree")] FromTree {