Skip to content

Commit

Permalink
Get all pieces ready for action
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 27, 2020
1 parent 0bcb790 commit 1805d64
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gitoxide-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ git-object = { version = "^0.2.0", path = "../git-object" }
git-odb = { version = "0.1.0", path = "../git-odb" }
git-features = { version = "^0.2.0", path = "../git-features" }
anyhow = "1.0.31"
quick-error = { version = "1.2.3", git = "https://github.com/tailhook/quick-error", rev = "aad5701556438218339fba452451ae63a47c31c2" }
bytesize = "1.0.1"
serde_json = { version = "1.0.56", optional = true }
52 changes: 49 additions & 3 deletions gitoxide-core/src/pack/explode.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use anyhow::{Context, Result};
use git_features::progress::Progress;
use git_odb::pack;
use git_object::{owned, HashKind};
use git_odb::{loose, pack};
use std::io::Read;
use std::path::Path;

#[derive(PartialEq, Debug)]
Expand Down Expand Up @@ -52,21 +54,65 @@ impl From<SafetyCheck> for pack::index::traverse::SafetyCheck {
}
}

use quick_error::quick_error;

quick_error! {
#[derive(Debug)]
enum Error {
Io(err: std::io::Error) {
source(err)
from()
}
Odb(err: loose::db::write::Error) {
source(err)
from()
}
}
}

struct OutputWriter(Option<loose::Db>);

impl git_odb::Write for OutputWriter {
type Error = Error;

fn write_stream(
&self,
kind: git_object::Kind,
size: u64,
from: impl Read,
hash: HashKind,
) -> Result<owned::Id, Self::Error> {
match self.0.as_ref() {
Some(db) => db.write_stream(kind, size, from, hash).map_err(Into::into),
None => git_odb::sink().write_stream(kind, size, from, hash).map_err(Into::into),
}
}
fn write_buf(&self, kind: git_object::Kind, from: &[u8], hash: HashKind) -> Result<owned::Id, Self::Error> {
match self.0.as_ref() {
Some(db) => db.write_buf(kind, from, hash).map_err(Into::into),
None => git_odb::sink().write_buf(kind, from, hash).map_err(Into::into),
}
}
}

pub fn pack_or_pack_index<P>(
path: impl AsRef<Path>,
pack_path: impl AsRef<Path>,
object_path: Option<impl AsRef<Path>>,
_check: SafetyCheck,
_progress: Option<P>,
_delete_pack: bool,
) -> Result<()>
where
P: Progress,
{
let path = path.as_ref();
let path = pack_path.as_ref();
let _bundle = pack::Bundle::at(path).with_context(|| {
format!(
"Could not find .idx or .pack file from given file at '{}'",
path.display()
)
})?;

let _out = OutputWriter(object_path.map(|path| loose::Db::at(path.as_ref())));
Ok(())
}
12 changes: 9 additions & 3 deletions src/plumbing/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ mod options {

/// the '.pack' or '.idx' file to explode into loose objects
#[argh(positional)]
pub path: PathBuf,
pub pack_path: PathBuf,

/// the path into which all objects should be written. Commonly '.git/objects'
#[argh(positional)]
pub object_path: Option<PathBuf>,
}

/// Verify a pack
Expand Down Expand Up @@ -131,14 +135,16 @@ pub fn main() -> Result<()> {
let thread_limit = cli.threads;
match cli.subcommand {
SubCommands::PackExplode(PackExplode {
path,
pack_path,
object_path,
verbose,
check,
delete_pack,
}) => {
let (_handle, progress) = prepare(verbose, "pack-explode");
core::pack::explode::pack_or_pack_index(
path,
pack_path,
object_path,
check.unwrap_or(core::pack::explode::SafetyCheck::All),
progress,
delete_pack,
Expand Down
13 changes: 10 additions & 3 deletions src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ mod options {

/// The '.pack' or '.idx' file to explode into loose objects
#[structopt(parse(from_os_str))]
path: PathBuf,
pack_path: PathBuf,

/// The path into which all objects should be written. Commonly '.git/objects'
#[structopt(parse(from_os_str))]
object_path: Option<PathBuf>,
},
/// Verify the integrity of a pack or index file
#[structopt(setting = AppSettings::ColoredHelp)]
Expand Down Expand Up @@ -221,13 +225,16 @@ pub fn main() -> Result<()> {
progress,
progress_keep_open,
delete_pack,
path,
pack_path,
object_path,
} => prepare_and_run(
"pack-explode",
verbose,
progress,
progress_keep_open,
move |progress, _out, _err| core::pack::explode::pack_or_pack_index(path, check, progress, delete_pack),
move |progress, _out, _err| {
core::pack::explode::pack_or_pack_index(pack_path, object_path, check, progress, delete_pack)
},
),
Subcommands::PackVerify {
path,
Expand Down

0 comments on commit 1805d64

Please sign in to comment.