Skip to content

Commit

Permalink
feat!: turn gix free index entries into gix index entries.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Apr 25, 2023
1 parent f722d6b commit ca8ebdf
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 30 deletions.
3 changes: 0 additions & 3 deletions gitoxide-core/src/index/mod.rs
Expand Up @@ -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<Path>, object_hash: gix::hash::Kind) -> anyhow::Result<gix::index::File> {
Expand Down
@@ -1,26 +1,18 @@
use std::path::Path;

use crate::index::{parse_file, Options};

pub fn entries(
index_path: impl AsRef<Path>,
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())?,
}
}

Expand All @@ -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<()> {
Expand All @@ -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(),
},
)?;

Expand Down
Expand Up @@ -34,3 +34,6 @@ pub fn from_tree(

Ok(())
}

mod entries;
pub use entries::entries;
20 changes: 10 additions & 10 deletions src/plumbing/main.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/plumbing/options/free.rs
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/plumbing/options/mod.rs
Expand Up @@ -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 {
Expand Down

0 comments on commit ca8ebdf

Please sign in to comment.