History

feat!: turn `gix free index entries` into `gix index entries`.

Sebastian Thiel committed 3 years ago

Commit ca8ebdf1 parent f722d6b6 files · +22 −30Browse files

Unified · Split

6 files
  1. gitoxide-core/src/index/mod.rs +0 −3
  2. gitoxide-core/src/repository/index/entries.rs +7 −15
  3. gitoxide-core/src/repository/index/mod.rs +3 −0
  4. src/plumbing/main.rs +10 −10
  5. src/plumbing/options/free.rs +0 −2
  6. src/plumbing/options/mod.rs +2 −0
gitoxide-core/src/index/mod.rs+0−3
@@ -5,9 +5,6 @@ pub struct Options { · 4 unmodified lines
55 pub format: crate::OutputFormat,
66 }
77
8−mod entries;
9−pub use entries::entries;
10−
118 pub mod information;
129
1310 fn parse_file(index_path: impl AsRef<Path>, object_hash: gix::hash::Kind) -> anyhow::Result<gix::index::File> {
gitoxide-core/src/repository/index/entries.rsrenamed from gitoxide-core/src/index/entries.rs+7−15
@@ -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<()> {
102 use crate::OutputFormat::*;
11− let file = parse_file(index_path, object_hash)?;
3+ let index = repo.index()?;
124
135 #[cfg(feature = "serde")]
146 if let Json = format {
157 out.write_all(b"[\n")?;
168 }
179
18− let mut entries = file.entries().iter().peekable();
10+ let mut entries = index.entries().iter().peekable();
1911 while let Some(entry) = entries.next() {
2012 match format {
21− Human => to_human(&mut out, &file, entry)?,
13+ Human => to_human(&mut out, &index, entry)?,
2214 #[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())?,
2416 }
2517 }
2618
@@ -34,7 +26,7 @@ pub fn entries( · 7 unmodified lines
3426 #[cfg(feature = "serde")]
3527 pub(crate) fn to_json(
3628 mut out: &mut impl std::io::Write,
37− file: &gix::index::File,
29+ index: &gix::index::File,
3830 entry: &gix::index::Entry,
3931 is_last: bool,
4032 ) -> anyhow::Result<()> {
@@ -56,7 +48,7 @@ pub(crate) fn to_json( · 15 unmodified lines
5648 hex_id: entry.id.to_hex().to_string(),
5749 flags: entry.flags.bits(),
5850 mode: entry.mode.bits(),
59− path: entry.path(file).to_str_lossy(),
51+ path: entry.path(index).to_str_lossy(),
6052 },
6153 )?;
6254
gitoxide-core/src/repository/index/mod.rsrenamed from gitoxide-core/src/repository/index.rs+3−0
@@ -34,3 +34,6 @@ pub fn from_tree( · 33 unmodified lines
3434
3535 Ok(())
3636 }
37+
38+mod entries;
39+pub use entries::entries;
src/plumbing/main.rs+10−10
@@ -339,16 +339,6 @@ pub fn main() -> Result<()> { · 338 unmodified lines
339339 )
340340 },
341341 ),
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− ),
352342 free::index::Subcommands::Verify => prepare_and_run(
353343 "index-verify",
354344 auto_verbose,
@@ -865,6 +855,16 @@ pub fn main() -> Result<()> { · 510 unmodified lines
865855 ),
866856 },
867857 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+ ),
868868 index::Subcommands::FromTree {
869869 force,
870870 index_output_path,
src/plumbing/options/free.rs+0−2
@@ -55,8 +55,6 @@ pub mod index { · 54 unmodified lines
5555 pub enum Subcommands {
5656 /// Validate constraints and assumptions of an index along with its integrity.
5757 Verify,
58− /// Print all entries to standard output
59− Entries,
6058 /// Print information about the index structure
6159 Info {
6260 /// Do not extract specific extension information to gain only a superficial idea of the index's composition.
src/plumbing/options/mod.rs+2−0
@@ -471,6 +471,8 @@ pub mod index { · 470 unmodified lines
471471
472472 #[derive(Debug, clap::Subcommand)]
473473 pub enum Subcommands {
474+ /// Print all entries to standard output
475+ Entries,
474476 /// Create an index from a tree-ish.
475477 #[clap(visible_alias = "read-tree")]
476478 FromTree {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t