Skip to content

Commit

Permalink
sub-command to print multi-index entries (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Mar 6, 2022
1 parent 21c2dd5 commit 6c10e09
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
* [x] **info** - print information about the file
* [x] **create** - create a multi-index from pack indices
* [x] **verify** - check the file for consistency
* [x] **entries** - list all entries of the file
- **index**
* [x] [create](https://asciinema.org/a/352941) - create an index file by streaming a pack file as done during clone
* [x] support for thin packs (as needed for fetch/pull)
Expand Down
1 change: 0 additions & 1 deletion git-worktree/src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ where
}
Err(err) => {
if options.keep_going {
files.fail(format!("{}: {}", entry_path, err));
errors.push(ErrorRecord {
path: entry_path.into(),
error: Box::new(err),
Expand Down
12 changes: 12 additions & 0 deletions gitoxide-core/src/pack/multi_index.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::bail;
use std::{io::BufWriter, path::PathBuf, sync::atomic::AtomicBool};

use crate::OutputFormat;
Expand Down Expand Up @@ -68,3 +69,14 @@ pub fn info(
)?;
Ok(())
}

pub fn entries(multi_index_path: PathBuf, format: OutputFormat, mut out: impl std::io::Write) -> anyhow::Result<()> {
if format != OutputFormat::Human {
bail!("Only human format is supported right now");
}
let file = git::odb::pack::multi_index::File::at(&multi_index_path)?;
for entry in file.iter() {
writeln!(out, "{} {} {}", entry.oid, entry.pack_index, entry.pack_offset)?;
}
Ok(())
}
8 changes: 8 additions & 0 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@ pub fn main() -> Result<()> {
)
.map(|_| ()),
pack::Subcommands::MultiIndex(multi_index::Platform { multi_index_path, cmd }) => match cmd {
pack::multi_index::Subcommands::Entries => prepare_and_run(
"pack-multi-index-entries",
verbose,
progress,
progress_keep_open,
core::pack::multi_index::PROGRESS_RANGE,
move |_progress, out, _err| core::pack::multi_index::entries(multi_index_path, format, out),
),
pack::multi_index::Subcommands::Info => prepare_and_run(
"pack-multi-index-info",
verbose,
Expand Down
2 changes: 2 additions & 0 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ pub mod pack {

#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Display all entries of a multi-index: <oid> <pack-id> <pack-offset>
Entries,
/// Print general information about a multi-index file
Info,
/// Verify a multi-index quickly without inspecting objects themselves
Expand Down

0 comments on commit 6c10e09

Please sign in to comment.